RuleStack

Configs

Stacks

Compare

Diff

RuleStack

Configs

Stacks

Compare

Diff

Read API

RuleStack

Configs

Stacks

Compare

Diff

Read API

Diff/topjohnwu-magisk-app-agents ↔ topjohnwu-magisk-native-agents

Comparison

A · AGENTS.md · topjohnwu/MagiskB · AGENTS.md · topjohnwu/Magisk
What each file covers, counted
DimensionSharedOnly in AOnly in BOverlap
Sections0590%
Commands0100%
Section tags20529%

What each file covers

Sections

0 shared · 5 only in A · 9 only in B
  • − AGENTS.md (app subproject)
  • − 1. Environment & Gradle Setup
  • − 2. Architecture & Submodules
  • − 3. Development Guidelines
  • − 4. Workflows & Verification (from `app/`)
  • + AGENTS.md (native subproject)
  • + 1. Environment & Build Requirements
  • + 2. Component Architecture
  • + Key Native Binary Output Targets
  • + 3. Build System Orchestration
  • + 4. FFI Architecture & Mechanics
  • + 5. Build Targets & Commands (from Root)
  • + 6. Rust & C++ Conventions
  • + 7. Magisk Rust Patterns & Non-Standard Idioms

Commands

0 shared · 1 only in A · 0 only in B
  • − ./gradlew

Section tags

2 shared · 0 only in A · 5 only in B
  • + build
  • + test
  • + lint-format
  • + ui
  • + do-not
  •   setup
  •   code-style

Line diff

+83 added−28 removed10 unchanged10.8% identical
topjohnwu/Magisk · app/AGENTS.md
@@ −1 @@
1# AGENTS.md (app subproject)
2 
3Guidelines for AI models operating inside the `app/` subproject.
4 
5## 1. Environment & Gradle Setup
6 
7- **Working Directory:** Set working directory to `app/` when working on app code.
8- **Environment Wrapper:** Standalone `./gradlew` commands MUST be prefixed with `../scripts/env.py` (e.g., `../scripts/env.py ./gradlew assembleDebug`), or run `./build.py app` from root.
9 
10## 2. Architecture & Submodules
11 
12Multi-module Gradle project structure:
13- **`:apk`** (`apk/`): Legacy app APK. **Maintenance mode:** No new features should be added here.
14- **`:apk-ng`** (`apk-ng/`): Next-gen app variant. Primary target for new UI/app features.
15- **`:core`** (`core/`): Core domain logic, resources, Room DB, services. Primary target for core feature development.
16- **`:shared`** (`shared/`): Shared utilities and common data structures.
17- **`:stub`** (`stub/`): Lightweight stub app loader for hidden installs.
18- **`:stub-res`** (`stub-res/`): Stub-specific Android resources.
19- **`:test`** (`test/`): Application testing target.
20- **`:build-logic`** (`build-logic/`): Custom Gradle plugins and build logic.
21 
22## 3. Development Guidelines
 
 
 
 
 
23 
24- **Feature Development:** `:apk` is in maintenance mode. All new development MUST occur in `:core` and `:apk-ng`.
25- **Language & UI:** Written in Kotlin/Java. **Prefer Kotlin for all new code.** Uses Jetpack Compose for UI (prefer over View XML).
26- **String Resources:** Default strings in `core/src/main/res/values/strings.xml` and `stub-res/src/main/res/values/strings.xml`. Translations go in `values-[lang]/strings.xml`.
27- **Data Stack:** Room, KSP, Wire (Protocol Buffers), Moshi.
28 
29## 4. Workflows & Verification (from `app/`)
30 
31Prefix commands with `../scripts/env.py`:
32- **Build Main APK (Debug):** `../scripts/env.py ./gradlew :apk:assembleDebug`
33- **Build All Variants:** `../scripts/env.py ./gradlew assembleDebug`
34- **Build Stub APK:** `../scripts/env.py ./gradlew :stub:assembleDebug`
35- **Run Lint:** `../scripts/env.py ./gradlew lint`
36- **Run Unit Tests:** `../scripts/env.py ./gradlew test`
37- **Clean Artifacts:** `../scripts/env.py ./gradlew clean`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38 
topjohnwu/Magisk · native/AGENTS.md
@@ +1 @@
1# AGENTS.md (native subproject)
2 
3Guidelines for AI models operating inside the `native/` subproject.
4 
5## 1. Environment & Build Requirements
6 
7- **Working Directory:** Execute commands from repo root via `./build.py`.
8- **Pre-build Requirement:** ALWAYS run `./build.py native` at least once before editing native sources to generate FFI bindings, headers, and flags (`flags.h`, `flags.rs`, `*-rs.hpp`, `*-rs.cpp`, protobuf generated modules).
9 
10## 2. Component Architecture
11 
12Native C, C++, and Rust source modules under `native/src/`:
13- **`base/`**: System wrappers, logging, custom string abstractions (`Utf8CStr`), mount helpers, and common utilities (C++/Rust).
14- **`boot/`**: Boot image parsing, unpacking, repacking, and ramdisk patching logic (`magiskboot`) (Rust/C++).
15- **`core/`**: Magisk daemon (`magiskd`), Zygisk engine, `su` implementation, applets, and system properties (`resetprop`) (C++/Rust).
16- **`init/`**: Early boot `magiskinit`, ramdisk patching, SELinux pre-init (C/C++/Rust).
17- **`sepolicy/`**: SELinux policy engine (`libpolicy`) and `magiskpolicy` CLI (C++/Rust).
18- **`external/`**: Embedded dependencies (`cxx-rs`, `selinux`, `crt0`, `system_properties`, `lsplt`, `lz4-sys`, `xz-embedded`).
 
 
19 
20### Key Native Binary Output Targets
21- `magisk`: Core daemon, Zygisk, `su`, and applets executable.
22- `magiskinit`: Early init replacement executable (static).
23- `magiskboot`: Boot image patcher executable (static).
24- `magiskpolicy`: SELinux policy tool executable.
25- `resetprop`: System property reader/writer executable.
26 
27## 3. Build System Orchestration
 
 
 
28 
29The build process follows a two-stage hybrid pipeline orchestrated by `build.py`:
30 
31```
321. dump_flags_native() --> Outputs flags.h & flags.rs to native/out/generated/
332. build_rust_src() --> Cargo build outputs lib<tgt>.a for each target ABI
34 Cargo build.rs runs cxx_gen to produce *-rs.hpp / *-rs.cpp
35 Cargo build.rs runs pb-rs to generate Protobuf bindings
36 Static libraries moved to native/out/<arch>/lib<tgt>-rs.a
373. build_cpp_src() --> ndk-build runs using Android.mk & Application.mk
38 Android-rs.mk imports lib<tgt>-rs.a as PREBUILT_STATIC_LIBRARY
39 Compiles C/C++ sources + *-rs.cpp bridge files + cxx.cc
404. clean_elf() --> tools/elf-cleaner strips incompatible ELF dynamic tags
41```
42 
43## 4. FFI Architecture & Mechanics
44 
45- **Bridge Engine:** C++/Rust FFI uses `cxx` (`cxx-rs`) via `#[cxx::bridge]` modules declared in crate `lib.rs` files.
46- **Header & Source Generation:**
47 - `codegen.rs` (`gen_cxx_binding()`) invokes `cxx_gen` in crate `build.rs` scripts.
48 - Automatically generates C++ bridge headers (`*-rs.hpp`) and source wrappers (`*-rs.cpp`) directly in each crate directory.
49 - Generates bindings for `base-rs`, `core-rs`, `init-rs`, `boot-rs`, and `policy-rs`.
50- **Linking:** Generated `*-rs.cpp` bridge code and `cxx.cc` are compiled directly by `ndk-build` alongside native C++ source files, linking against the compiled Rust static library (`lib<tgt>-rs.a`).
51 
52## 5. Build Targets & Commands (from Root)
53 
54- **Build All Native Binaries:** `./build.py native`
55- **Build Specific Target(s):** `./build.py native [magisk|magiskinit|magiskboot|magiskpolicy|resetprop]`
56- **Rust Clippy Lint:** `./build.py clippy`
57- **Cargo Commands:** `./build.py cargo check`, `./build.py cargo test`
58- **Generate IDE Database:** `./build.py gen`
59- **Clean Native Artifacts:** `./build.py clean native`
60 
61## 6. Rust & C++ Conventions
62 
63- **Rust Edition & Profile:** Rust Edition 2024. Profile configured with `panic = "immediate-abort"` across dev and release profiles.
64- **C++ Standard:** C++20 with `libc++` static linking.
65- **Clippy Rules:** `unwrap_used = "deny"` in workspace configuration. **Do NOT use `.unwrap()` in Rust code.** Use `?`, `unwrap_or`, `unwrap_or_else`, or pattern matching.
66- **Incremental Build Protection:** File writers (`write_if_diff`) skip rewriting identical generated files to preserve compilation timestamps and avoid unnecessary rebuilds.
67 
68## 7. Magisk Rust Patterns & Non-Standard Idioms
69 
70AI models modifying or writing Rust code in `native/src/` MUST follow these Magisk-specific idioms:
71 
721. **Custom String Handling (`Utf8CStr` & `cstr!`):**
73 - Standard C/C++ APIs require null-terminated UTF-8 strings. Do NOT create intermediate `CString` allocations.
74 - Use `&Utf8CStr` for string references, `Utf8CString` for heap buffers, and `Utf8CStrBufArr<N>` for stack buffers (`base/cstr.rs`).
75 - Use `cstr!("literal")` for compile-time null-terminated static strings.
76 - Use `StringExt::nul_terminate` for in-place null byte termination using reserved string capacity.
77 
782. **Instant Logging Error Model (`LoggedError`):**
79 - Application logic does NOT use standard error enums or `anyhow`.
80 - Errors are logged immediately at the failure point via `log_err!`, `.log()`, or `.log_with_msg()` and converted into zero-sized `LoggedError` / `LoggedResult<T>`.
81 - In debug builds, `#[track_caller]` logs the file and line number of error sites automatically. Use `.silent()` to silence expected failures.
82 
833. **Libc System Call Conversions (`LibcReturn`):**
84 - When calling raw libc or C system APIs in Rust or `xwrap.rs`, use `LibcReturn::into_os_result` or `check_err` to automatically map negative integer returns or null pointers into `OsResult` or `LoggedResult`.
85 
864. **Zero Allocation & Binary Size Rules:**
87 - Prefer custom `argh` derivation (`base/argh.rs`) for command-line parsing instead of adding standard argument dependencies.
88 - Avoid `serde` overhead; use procedural `Encodable`/`Decodable` binary traits over UNIX domain sockets for IPC.
89 
905. **Nightly Synchronization & IPC:**
91 - Magisk uses nightly features (`unix_socket_ancillary_data`, `nonpoison_mutex`).
92 - Use non-poisoning mutexes/condvars for daemon threading and `send_fd`/`recv_fd` for raw file descriptor passing.
93 
@@ −1 +1 @@
1−# AGENTS.md (app subproject)
1+# AGENTS.md (native subproject)
22  
3−Guidelines for AI models operating inside the `app/` subproject.
3+Guidelines for AI models operating inside the `native/` subproject.
44  
5−## 1. Environment & Gradle Setup
5+## 1. Environment & Build Requirements
66  
7−- **Working Directory:** Set working directory to `app/` when working on app code.
8−- **Environment Wrapper:** Standalone `./gradlew` commands MUST be prefixed with `../scripts/env.py` (e.g., `../scripts/env.py ./gradlew assembleDebug`), or run `./build.py app` from root.
7+- **Working Directory:** Execute commands from repo root via `./build.py`.
8+- **Pre-build Requirement:** ALWAYS run `./build.py native` at least once before editing native sources to generate FFI bindings, headers, and flags (`flags.h`, `flags.rs`, `*-rs.hpp`, `*-rs.cpp`, protobuf generated modules).
99  
10−## 2. Architecture & Submodules
10+## 2. Component Architecture
1111  
12−Multi-module Gradle project structure:
13−- **`:apk`** (`apk/`): Legacy app APK. **Maintenance mode:** No new features should be added here.
14−- **`:apk-ng`** (`apk-ng/`): Next-gen app variant. Primary target for new UI/app features.
15−- **`:core`** (`core/`): Core domain logic, resources, Room DB, services. Primary target for core feature development.
16−- **`:shared`** (`shared/`): Shared utilities and common data structures.
17−- **`:stub`** (`stub/`): Lightweight stub app loader for hidden installs.
18−- **`:stub-res`** (`stub-res/`): Stub-specific Android resources.
19−- **`:test`** (`test/`): Application testing target.
20−- **`:build-logic`** (`build-logic/`): Custom Gradle plugins and build logic.
12+Native C, C++, and Rust source modules under `native/src/`:
13+- **`base/`**: System wrappers, logging, custom string abstractions (`Utf8CStr`), mount helpers, and common utilities (C++/Rust).
14+- **`boot/`**: Boot image parsing, unpacking, repacking, and ramdisk patching logic (`magiskboot`) (Rust/C++).
15+- **`core/`**: Magisk daemon (`magiskd`), Zygisk engine, `su` implementation, applets, and system properties (`resetprop`) (C++/Rust).
16+- **`init/`**: Early boot `magiskinit`, ramdisk patching, SELinux pre-init (C/C++/Rust).
17+- **`sepolicy/`**: SELinux policy engine (`libpolicy`) and `magiskpolicy` CLI (C++/Rust).
18+- **`external/`**: Embedded dependencies (`cxx-rs`, `selinux`, `crt0`, `system_properties`, `lsplt`, `lz4-sys`, `xz-embedded`).
2119  
22−## 3. Development Guidelines
20+### Key Native Binary Output Targets
21+- `magisk`: Core daemon, Zygisk, `su`, and applets executable.
22+- `magiskinit`: Early init replacement executable (static).
23+- `magiskboot`: Boot image patcher executable (static).
24+- `magiskpolicy`: SELinux policy tool executable.
25+- `resetprop`: System property reader/writer executable.
2326  
24−- **Feature Development:** `:apk` is in maintenance mode. All new development MUST occur in `:core` and `:apk-ng`.
25−- **Language & UI:** Written in Kotlin/Java. **Prefer Kotlin for all new code.** Uses Jetpack Compose for UI (prefer over View XML).
26−- **String Resources:** Default strings in `core/src/main/res/values/strings.xml` and `stub-res/src/main/res/values/strings.xml`. Translations go in `values-[lang]/strings.xml`.
27−- **Data Stack:** Room, KSP, Wire (Protocol Buffers), Moshi.
27+## 3. Build System Orchestration
2828  
29−## 4. Workflows & Verification (from `app/`)
29+The build process follows a two-stage hybrid pipeline orchestrated by `build.py`:
3030  
31−Prefix commands with `../scripts/env.py`:
32−- **Build Main APK (Debug):** `../scripts/env.py ./gradlew :apk:assembleDebug`
33−- **Build All Variants:** `../scripts/env.py ./gradlew assembleDebug`
34−- **Build Stub APK:** `../scripts/env.py ./gradlew :stub:assembleDebug`
35−- **Run Lint:** `../scripts/env.py ./gradlew lint`
36−- **Run Unit Tests:** `../scripts/env.py ./gradlew test`
37−- **Clean Artifacts:** `../scripts/env.py ./gradlew clean`
31+```
32+1. dump_flags_native() --> Outputs flags.h & flags.rs to native/out/generated/
33+2. build_rust_src() --> Cargo build outputs lib<tgt>.a for each target ABI
34+ Cargo build.rs runs cxx_gen to produce *-rs.hpp / *-rs.cpp
35+ Cargo build.rs runs pb-rs to generate Protobuf bindings
36+ Static libraries moved to native/out/<arch>/lib<tgt>-rs.a
37+3. build_cpp_src() --> ndk-build runs using Android.mk & Application.mk
38+ Android-rs.mk imports lib<tgt>-rs.a as PREBUILT_STATIC_LIBRARY
39+ Compiles C/C++ sources + *-rs.cpp bridge files + cxx.cc
40+4. clean_elf() --> tools/elf-cleaner strips incompatible ELF dynamic tags
41+```
42+ 
43+## 4. FFI Architecture & Mechanics
44+ 
45+- **Bridge Engine:** C++/Rust FFI uses `cxx` (`cxx-rs`) via `#[cxx::bridge]` modules declared in crate `lib.rs` files.
46+- **Header & Source Generation:**
47+ - `codegen.rs` (`gen_cxx_binding()`) invokes `cxx_gen` in crate `build.rs` scripts.
48+ - Automatically generates C++ bridge headers (`*-rs.hpp`) and source wrappers (`*-rs.cpp`) directly in each crate directory.
49+ - Generates bindings for `base-rs`, `core-rs`, `init-rs`, `boot-rs`, and `policy-rs`.
50+- **Linking:** Generated `*-rs.cpp` bridge code and `cxx.cc` are compiled directly by `ndk-build` alongside native C++ source files, linking against the compiled Rust static library (`lib<tgt>-rs.a`).
51+ 
52+## 5. Build Targets & Commands (from Root)
53+ 
54+- **Build All Native Binaries:** `./build.py native`
55+- **Build Specific Target(s):** `./build.py native [magisk|magiskinit|magiskboot|magiskpolicy|resetprop]`
56+- **Rust Clippy Lint:** `./build.py clippy`
57+- **Cargo Commands:** `./build.py cargo check`, `./build.py cargo test`
58+- **Generate IDE Database:** `./build.py gen`
59+- **Clean Native Artifacts:** `./build.py clean native`
60+ 
61+## 6. Rust & C++ Conventions
62+ 
63+- **Rust Edition & Profile:** Rust Edition 2024. Profile configured with `panic = "immediate-abort"` across dev and release profiles.
64+- **C++ Standard:** C++20 with `libc++` static linking.
65+- **Clippy Rules:** `unwrap_used = "deny"` in workspace configuration. **Do NOT use `.unwrap()` in Rust code.** Use `?`, `unwrap_or`, `unwrap_or_else`, or pattern matching.
66+- **Incremental Build Protection:** File writers (`write_if_diff`) skip rewriting identical generated files to preserve compilation timestamps and avoid unnecessary rebuilds.
67+ 
68+## 7. Magisk Rust Patterns & Non-Standard Idioms
69+ 
70+AI models modifying or writing Rust code in `native/src/` MUST follow these Magisk-specific idioms:
71+ 
72+1. **Custom String Handling (`Utf8CStr` & `cstr!`):**
73+ - Standard C/C++ APIs require null-terminated UTF-8 strings. Do NOT create intermediate `CString` allocations.
74+ - Use `&Utf8CStr` for string references, `Utf8CString` for heap buffers, and `Utf8CStrBufArr<N>` for stack buffers (`base/cstr.rs`).
75+ - Use `cstr!("literal")` for compile-time null-terminated static strings.
76+ - Use `StringExt::nul_terminate` for in-place null byte termination using reserved string capacity.
77+ 
78+2. **Instant Logging Error Model (`LoggedError`):**
79+ - Application logic does NOT use standard error enums or `anyhow`.
80+ - Errors are logged immediately at the failure point via `log_err!`, `.log()`, or `.log_with_msg()` and converted into zero-sized `LoggedError` / `LoggedResult<T>`.
81+ - In debug builds, `#[track_caller]` logs the file and line number of error sites automatically. Use `.silent()` to silence expected failures.
82+ 
83+3. **Libc System Call Conversions (`LibcReturn`):**
84+ - When calling raw libc or C system APIs in Rust or `xwrap.rs`, use `LibcReturn::into_os_result` or `check_err` to automatically map negative integer returns or null pointers into `OsResult` or `LoggedResult`.
85+ 
86+4. **Zero Allocation & Binary Size Rules:**
87+ - Prefer custom `argh` derivation (`base/argh.rs`) for command-line parsing instead of adding standard argument dependencies.
88+ - Avoid `serde` overhead; use procedural `Encodable`/`Decodable` binary traits over UNIX domain sockets for IPC.
89+ 
90+5. **Nightly Synchronization & IPC:**
91+ - Magisk uses nightly features (`unix_socket_ancillary_data`, `nonpoison_mutex`).
92+ - Use non-poisoning mutexes/condvars for daemon threading and `send_fd`/`recv_fd` for raw file descriptor passing.
3893  
RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack

RuleStack

Built by

Kynth Studio

Directory

Configs
Stacks
Compare formats
Diff two configs
Best AGENTS.md examples

Formats

AGENTS.md
CLAUDE.md
Cursor rules
Copilot instructions

Reference

Read API
Corpus health
Privacy Policy
Terms

RuleStack