Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / AGENTS.md

AGENTS.md21.8 KiBRenderedCodeRaw
1# AGENTS.md — Modern-Apps
2
3Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only.
4
5## 1. Scope first (law)
61. Each module has its own `AGENTS.md` (e.g. `notes/AGENTS.md`, `games/voxels/AGENTS.md`, `library/ui/AGENTS.md`) — auto-loaded on read. Read it instead of listing the dir.
72. State `Scope: <dir/> + <shared>` before any scan. Stay inside those prefixes.
83. Expand only with one-line justification. Never root-recurse.
94. Don't read `CONTRIBUTING.md` whole (26KB). Pull a section only on demand.
105. Prefer 1 targeted read over 10 searches.
116. **Keep `AGENTS.md` current (mandatory).** If your change adds, removes, renames, or alters anything a module's `AGENTS.md` documents — entry files, key files, architecture/data-flow, features, gotchas, verification commands, module purpose — update that module's `AGENTS.md` (and this root file, when the change is repo-wide: conventions, shared-module ownership, app index) **in the same change**. Facts that stopped being true (removed deps, renamed files, dead behavior) must be corrected or deleted, not left standing. A change that makes an `AGENTS.md` claim false is incomplete. Conversely, don't churn `AGENTS.md` prose for changes it doesn't document.
127. **`AGENTS.md` describes the current state only.** No history: no changelogs, "previously/formerly/used to" narratives, migration stories, commit references, or dated change notes. Write present-tense descriptions of how the module works now; when you touch an `AGENTS.md`, strip historical content you find (keep any present-tense lesson, drop its narrative).
13
14### How to pick scope
15| Task | Scope |
16| :--- | :--- |
17| UI bug in one app | that app + `library/ui` |
18| DB / Room | that app + `library/room` |
19| Network / TLS / certs | that app + `library/network` |
20| Icons, scaffold, theme, messenger | that app + `library/ui` |
21| Cross-app share / assistant tool | both apps + `library` (DTO in `library.intents.<app>`) |
22| New app module | `settings.gradle.kts` + `build-logic/` + reference app (`backup/`, else `notes/`) |
23| Store listing / screenshots | that app + `metadata_data/` |
24| Rust / JNI / native | that app's `src/main/rust/` + root `Cargo.toml` |
25| Build convention change | `build-logic/` only |
26| Lint rule change | `lint-rules/` only |
27| Games hub achievement | game + `sdk/games` |
28
29### Shared modules (only pull when row above says so)
30| Module | Path | What it owns |
31| :--- | :--- | :--- |
32| base | `library/` | nav keys, `AssistantIntent`, IPC DTOs (`library.intents.<app>`), `RoomRepository` base |
33| ui | `library/ui/` | `Icons.kt` + generated wrappers from `library/ui/icons.tsv` (ONLY `Icon()`/`painterResource()` allowed there and in the generated source), `AppScaffold` family, `DynamicTheme`, messenger/`AppMessages`, motion helpers |
34| network | `library/network/` | `NetworkClient`, pinned CAs in `assets/ca/`, `TrustBundle` (FIRST_PARTY/STANDARD/EXTENDED/SYSTEM/ESIM), `OfflineAware` banner |
35| room | `library/room/` | Room 3 + SQLCipher (`implementRoom(libs)`) |
36| map / ml / ocr | `library/map/`, `library/ml/`, `library/ocr/` | vector maps (INTERNET itself) / inference / OCR |
37| image/media | `library/image/`, `library/media/` | image loading (offline-local; network apps opt into HTTP via `Builder.remote()` with a `NetworkClient` fetch fn) / AV playback |
38| e2ee-p2p | `library/e2ee-p2p/` | E2EE, p2p, `Hkdf` |
39| widgets/work | `library/widgets/`, `library/work/` | Glance widgets / WorkManager |
40| biometric/ink | `library/biometric/`, `library/ink/` | biometric / stylus ink |
41| downloadservice | `library/downloadservice/` | foreground downloads (INTERNET itself) |
42| format | `library/format/` | relative-age bucketing + `"<amount>m ago"` wording (opt-in; calendar dates stay in `library/ui` `DateString`) |
43| locationprovider | `library/locationprovider/` | location abstraction |
44| aosp-stubs | `library/aosp-stubs/` | compile-only hidden-API stubs |
45| sdk:games/cast/openassistant | `sdk/games/`, `sdk/cast/`, `sdk/openassistant/` | achievements / casting / assistant tools |
46| build-logic | `build-logic/` | `common-conventions-app`, `common-conventions-library`, `launcherIcon`, `rustNativeLib` |
47| lint-rules | `lint-rules/` | ToastUsage + DirectComposeAnimation + FileLength + DirectAndroidLog + DialogAsRoute + RouteScreenshotCoverage + FixtureDeterminism + NoDeadClick (fatal) + others |
48
49### Apps (Gradle key → dir)
50Reference: `backup/` satisfies every rule; `notes/` second + `intents/` demo. `camera` + `games/voxels` hand-commit screenshots.
51Full canonical index (Gradle key → dir + group + notes): `.llms/repo-map.md`.
52`clock`, `notes`, `calendar`, `launcher`, `todo`, `maps`, `camera`, `findfamily`, `contacts`, `appstore`, `weather`, `communicate`, `music`, `email` and `securemail` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing).
53`appstore→appstore/` `astronomy→astronomy/` `auto→auto/,auto/protocol/` `backup→backup/` `calculator→calculator/` `calendar→calendar/` `camera→camera/` `cast→cast/,cast/protocol/,cast/tv/` `clock→clock/` `code→code/` `communicate→communicate/` `contacts→contacts/` `education→education/` `email→email/` `emergency→emergency/` `euicc→euicc/` `everysync→everysync/` `files→files/` `findfamily→findfamily/` `findfamily-ios→apple/FindFamily/` (SwiftPM/xtool, not Gradle) `flashcards→flashcards/` `fooddelivery→fooddelivery/` `health→health/` `keyboard→keyboard/` `launcher→launcher/` `logviewer→logviewer/` `maps→maps/` `measure→measure/` `music→music/` `networklocation→networklocation/` `news→news/` `notes→notes/` `office→office/` `openassistant→openassistant/` `passwords→passwords/` `pdf→pdf/` `photos→photos/` `parentalcontrols→parentalcontrols/` `screentime→screentime/` `setupwizard→setupwizard/` `share→share/` `speech→speech/` `taxi→taxi/` `things→things/` `todo→todo/` `translate→translate/` `travel→travel/` `tuner→tuner/` `updater→updater/` `vpn→vpn/` `weather→weather/` `watch→watch/,watch-wear/` `web→web/` `youpipe→youpipe/,youpipe/extractor/` `games-hub→games/hub/` `games-kart→games/kart/` `games-arrows→games/arrows/` `games-chess→games/chess/` `games-logicgate→games/logicgate/` `games-minesweeper→games/minesweeper/` `games-nonogram→games/nonogram/` `games-pipes→games/pipes/` `games-solitaire→games/solitaire/` `games-sudoku→games/sudoku/` `games-unblockjam→games/unblockjam/` `games-voxels→games/voxels/` `games-wordmaker→games/wordmaker/`
54Slash == colon for Gradle (`games/voxels` == `games:voxels`).
55
56### Never scan
57`target/`, `scripts/`, `build/`, `.gradle/`, `.kotlin/`, `*/build/`, `*/schemas/` (single file ok), `metadata_data/photos/`, `third_party/`, `firmware/`, `*.onnx`, `*.log`, `personal/`.
58
59### Backend server (outside this repo)
60The backend (relay server for findfamily/everysync/office/voxels) lives outside this repo:
61
62- Server checkout: `../location_share_server` (sibling of this repo root). On this dev machine: `C:\Users\Vayun\Documents\code\location_share_server`.
63- Live server SSH: `ssh [email protected]`
64- Server env template: `../location_share_server/.env.example` (copy to `../location_share_server/.env`, never commit secrets).
65- The server's canonical API host is `api.maproj.org` (same Cloudflare FIRST_PARTY pins). Legacy `findfamily.cc` / `api.findfamily.cc` still serve every API path identically so older app versions keep working.
66- Cloudflare R2: see `../location_share_server/src/handlers/os_admin.rs` for `R2::from_env()`; required vars `R2_ACCESS_KEY_ID`, `R2_SECRET_ACCESS_KEY`, plus `R2_ENDPOINT` or `R2_ACCOUNT_ID`.
67
68## 2. Conventions (check every time)
69- `Toast` banned (fatal lint). Use `rememberMessenger().show()` in composable, `AppMessages.show()` elsewhere.
70- Never `Icon()`/`painterResource()`/`androidx.compose.material.icons.*` in app. Icons are generated from `library/ui/icons.tsv` by `GenerateIconsTask` (build-logic) at build time: add an icon = one manifest line + rebuild; never hand-edit the generated file. A wrapper not in the manifest does not exist, so a missing icon is a compile error.
71- Never raw `Scaffold`. Use `AppScaffold` family. Refresh/loading indication goes through the scaffold's pull-to-refresh box (`isRefreshing`/`onRefresh`/`refreshEnabled` on `AppScaffold` family; TV: `TvAppFrame.isRefreshing`/`TvLoading` top indicator), never a standalone `LoadingState`/`LoadingIndicator`/`CircularProgressIndicator`/`ContainedLoadingIndicator` or hand-rolled pull-to-refresh in app UI (fatal `ScaffoldLoading` lint). Truly local progress is a non-icon affordance (disabled state, progress text); real determinate progress is a `LinearProgressIndicator(progress=...)` bar. Exception marker only for library-internal helpers and genuinely non-screen contexts. Never raw `androidx.compose.animation` at call site — use `library.ui` helpers. Never `imePadding()/navigationBarsPadding()/systemBarsPadding()` in `library.ui`.
72- Screen-level search goes through the scaffold's `search` parameter (`search = ScaffoldSearch(query, onQueryChange, placeholder)` on `AppScaffold`/`DetailScaffold`/`DetailLazyColumn`/`LazyListScaffold`; the field renders AS the top app bar in its title slot, title replaced, above the refresh box), never a standalone `CommonSearchBar`/`SearchBar`/`SearchBarInputField` or search-identified `TextField`/`OutlinedTextField` in app UI (fatal `ScaffoldSearch` lint). The `AppScaffold(topBar=...)` overload, `SetupScaffold`, and `TabbedPagerScaffold` (pages own their scaffolds) have no search slot by design; TV uses its own text field. Dialog/sheet/drawer-local filters and expandable overlay search with no scaffold host use the exception marker only.
73- Search hints say "Search" unless they convey valuable info such as the active search engine in web.
74- Room 3 only. Literal `androidx.room.` flagged even in comments. Never `buildDatabase()` at call site — subclass `library.room.RoomRepository`.
75- Network only via `library.network.NetworkClient` + `TrustBundle` narrowest (`FIRST_PARTY/STANDARD/EXTENDED/SYSTEM/ESIM`).
76- Package roots closed set: `ui data domain platform network intents service provider widget notifications sync telephony`. No `util/`. One public `@Composable` per file, named as file. `domain/` pure (no Android/Compose).
77- Package grammar is normative in `docs/package-structure.md`: package segments name responsibilities/features, never generic buckets (`util`, `common`, `helper`, `manager`, `api`, `viewmodel`, …) or UI toolkits. Widget code is flat in `widget/` — never `widgets/`, `widget/glance/`, `glance/`, or any `widget.<child>/`.
78- Every app with networking has exactly one public `network.Networking` entry point. It owns `NetworkClient`, the narrowest `TrustBundle`, URLs, endpoint paths, auth headers, retries, and status mapping. No package outside `network/` (and `library.network`) may construct raw API requests.
79- Every native library has exactly one guarded wrapper in `platform/` named `<Feature>Native`; it is the only `System.loadLibrary` caller for that library and exposes availability instead of letting initialization fail. JNI-frozen FQNs are the only package exceptions and must carry the verbatim JNI marker.
80- Every app has exactly one preferences owner in `data/` named `<App>Prefs`; only it opens the app’s DataStore/SharedPreferences, and it recovers from corruption with documented defaults. Persisted/external decoding goes through non-throwing helpers in `data/` or `domain/`; Room converters never throw.
81- Every exported entry point has one validated contract in `intents/`; entry points consume validated values only. Regexes must be Android-ICU-valid (escape literal braces outside quantifiers/character classes). Widgets render from one immutable snapshot and use fallbacks for missing keys/items. One widget, one file: every file in `widget/` declares a `MaWidget` subclass at top level together with its receiver; no helper-only files in `widget/` (helpers nest inside the widget; non-Glance app helpers belong to their own root).
82- Escape hatches verbatim: `// PACKAGE STRUCTURE EXCEPTION (JNI)`, `// RAW SCAFFOLD EXCEPTION: <reason>`, `// TOAST EXCEPTION: <reason>`, `// RAW ANIMATION EXCEPTION: <reason>`, `// SCAFFOLD LOADING EXCEPTION: <reason>`, `// SCAFFOLD SEARCH EXCEPTION: <reason>`, `// DIALOG LOCAL EXCEPTION: <reason>`, `// FIXTURE RELATIVE-TIME EXCEPTION: <reason>`, `// DEAD CLICK EXCEPTION: <reason>`.
83- Test/screenshot fixtures are deterministic (fatal `FixtureDeterminism` lint): no `Clock.System.now()`/`LocalDate.now()`/`LocalDateTime.now()`/`Instant.now()`/`System.currentTimeMillis()` or unseeded `Random()`/`UUID.randomUUID()` in `src/test`/`src/screenshotTest` — use named fixed constants or a seeded `Random(seed)`; deadline-polling/elapsed/freshness-assert idioms in unit tests are not fixtures. Code that must seed relative to the SUT's real clock uses `// FIXTURE RELATIVE-TIME EXCEPTION: <reason>`.
84- No dead clicks (fatal `NoDeadClick` lint): a Button/IconButton/FAB/MenuItem/ListItem-clickable in `src/main` with an empty/comment-only `onClick` and no `enabled = false` is an error — wire it, disable it honestly, or demote it to a non-button container. Display-only label chips are excluded by widget type; drag-handle grips use `// DEAD CLICK EXCEPTION: <reason>`.
85- detekt rules live in `detekt.yml` (ui/domain/odf/service scoping rationale inline). Fix code, not config, to green a module.
86
87## 3. Verify (slice touched, never whole repo)
88```
89./gradlew :<module>:compileDevKotlin
90./gradlew :<module>:lint
91./gradlew :<module>:checkMetadata
92```
93Gradle defaults to a small daemon heap (`-Xmx8g`) with wide task parallelism (`org.gradle.workers.max=128` in `gradle.properties`; `./install all` escalates the heap, not the worker count). New build logic must be configuration-cache compatible. New/changed UI previews: `./gradlew :<module>:metadata`.
94Rust builds use the fast cargo profile for dev tasks and the release profile for release/ambiguous tasks, overridable with `-Pmodernapps.rustProfile=release|fast`.
95Variants: apps and libraries both define only `dev` and `release` build types (the AGP `debug` type's variants are disabled in both convention plugins; neither `dev` variant is debuggable, and both initialise from `release`). App `dev` consumes library `dev` by exact build-type match — the `matchingFallbacks` lists in the conventions exist only for external AARs, which ship just debug/release. Library unit tests run as `:module:testDevUnitTest` (`testBuildType = "dev"` in both conventions), so one library variant serves assembleDev and tests.
96
97## 4. Tools — use these, not raw gradle/adb
98Work in repo dir. Experiments/logs go in `analysis/` (gitignored).
99
100`./install` — build + session-install (handles `.idsig`/fs-verity + `versionCodeOverride` automatically; skips apps whose built APK is byte-identical to the installed one, `INSTALL_SKIP_UNCHANGED=0` disables):
101```
102./install <device> <module> [...] # release by default; device (8|9|--device=watch) is required
103./install [dev|release] <device> <module> [...]
104./install voxels # shorthand → games:voxels; dooraccess → personal:dooraccess
105./install dev games/voxels # slash == colon
106./install 9 contacts calendar # multi-module, one gradlew invocation
107./install 9 maps # device required: 8 = Pixel 8, 9 = Pixel 9, --device=watch = Pixel Watch
108./install 9 all / ./install release 9 all # full repo (auto big-heap); release all caps R8 workers
109./install --dry-run 9 contacts
110```
111Rules: `release` default (dev is almost never the right install), `dev` only when asked, `debug` blocked. Never uninstall / clear data (emulator-only exception, never touch physical device). Never give placeholder commands — output copy-pasteable.
112
113`./dhu` — Desktop Head Unit loopback for `auto/` (Pixel 8 default):
114```
115./dhu # adb forward tcp:5277 + live logcat → analysis/dhu-<ts>.log + DHU window
116./dhu -NoLog # DHU only
117./dhu -DeviceId <serial> # non-default device
118```
119
120`./search` — scoped string search (bash only, `rg` when present, grep fallback). Pattern + optional `-m` (module) / `-p` (root package) filters, composable:
121```
122./search DB_NAME -m notes -p data # both: data/ package of notes/ only
123./search RoomRepository -m notes # module only
124./search TrustBundle -m web -p network # module + package combined
125./search "foo" -m voxels # shorthand → games:voxels; slash == colon; -m all = everything
126./search "bar" -m notes --files-only --max 20
127```
128Never grep repo-wide when a filter will do. Always excluded: `target/ build/ .gradle/ .kotlin/ .git/ .llms/ analysis/ *.log *.onnx metadata_data/photos/`.
129
130`./check` — static verification without building: `:<module>:detekt` (rules in `detekt.yml`) + `:<module>:lint` + `:<module>:ktlintCheck` + `cargo check/clippy/fmt/doc --locked` for Rust modules (workspace members via `-p`, standalone crates in-dir; `cargo fmt --check` is blocking — drift fails the script) + structure ratchets (`tools/structure_check.py`, manifests in `docs/structure/` — Wear protocol-pair drift, generated-source guard, exception-marker inventory, line-count ratchet against `line-budget.json`; runs on every invocation):
131```
132./check <module> [...] # e.g. ./check notes backup; ./check voxels
133./check all # every app + library module (pure-JVM modules excluded)
134./check structure # only the structure ratchets
135```
136Findings fail the task. Only `notes/`, `backup/`, `library/ui/`, `games/voxels/` are detekt-clean today; other modules carry incremental backlog — fixing a module means `./check <module>` goes green, not config relaxation.
137
138`./format` — auto-formatting (same module notation as `./check`):
139```
140./format <module> [...] # ktlintFormat + cargo fmt (writes changes)
141./format --check <module> # ktlintCheck + cargo fmt --check only
142./format all # every app + library module
143```
144Formatting (current state): Kotlin uses ktlint's standard rule set via the `org.jlleitschuh.gradle.ktlint` Gradle plugin (version pinned in `gradle/libs.versions.toml`; engine 1.5.0), applied by `common-conventions-app`/`common-conventions-library` so every app/library module has `ktlintFormat`/`ktlintCheck`. Style is the root `.editorconfig` (indent 4, max line 120, LF, final newline), which ktlint reads natively. Generated sources and `*.kts` build scripts are excluded (scope is `src/**`). `./check` enforces formatting per module (`:ktlintCheck` beside detekt/lint; `cargo fmt --check` blocking for Rust — style in the root `rustfmt.toml`, max_width 100; the rustfmt component is required: `rustup component add rustfmt`). `./check all` and `./format all` additionally run the workspace-wide `cargo fmt --all`, covering workspace crates with no Gradle module (`scripts/`, `third_party/`, `library/tilecodec`, `library/jni-http`, `library/vision`, `communicate-dev/src/main/rust-mls`), and check/format any standalone crate that is not a workspace member in its own dir. Rule exceptions: no ktlint rule is disabled. The one configured knob is `ktlint_function_naming_ignore_when_annotated_with = Composable` in `.editorconfig` — composables are PascalCase by repo convention (one public `@Composable` per file, named as the file), so the rule must not demand camelCase for them. Roll out module by module: `./format <module>` plus manual fixes for non-autocorrectable findings, then `./check <module>` green.
145
146### On-device file map (per-module `AGENTS.md` carries concrete names)
147- Room (`RoomRepository`, `DB_NAME` in `data/`): `/data/data/<pkg>/databases/<DB_NAME>` (+ `-wal`/`-shm` sidecars). SQLCipher-encrypted. `getDatabasePath`/`deleteDatabase`/`LEGACY_*` names are the same dir.
148- DataStore: `preferencesDataStore(name=X)` → `/data/data/<pkg>/files/datastore/X.preferences_pb`; shared `DataStoreUtils` → `/data/data/<pkg>/files/datastore_default.preferences_pb`.
149- Downloads (`InitialDownloadChecker`/`InitialModelDownloadChecker`, file lists in `platform/` or `data/`): each `fileName` → `/storage/emulated/0/Android/data/<pkg>/files/<fileName>` (`+.part` while downloading).
150- Assets (`src/main/assets/`): APK-bundled, read via `AssetManager` — no on-device path. Library assets (e.g. `library/network` CAs) ship inside each dependent APK.
151- Library modules have no `applicationId`: paths resolve under the hosting app's `<pkg>`.
152
153## 5. Git / safety
154- Other agents share the tree. Prohibited except reading state: `stash/revert/reset/checkout . /clean` etc. Only `add` + `commit` allowed, and only paths you changed — check `git status` first, never `add -A/.`, never stage without committing instantly.
155- Commit message: line 1 is ≤80 chars, always in the format `appname: short description (#iss)`. Then a blank line and a full body: what changed and why, the context (bug/symptom, root cause, constraints, alternatives rejected), notable implementation details, user-visible effect, and how it was verified. Write in plain prose/bullets, wrapped at ~72 chars. The body feeds AI-written release notes, so make it complete; never stop at one line.
156- LF only; never commit line-ending churn. `FAIL_ON_PROJECT_REPOS` — never add repos in modules. Read `SUPPLY_CHAIN_RISKS.md` before new third-party dep.
157- **Lint gate (mandatory).** No change merges into the local main branch without its modules' lint checks green: the agent verifies `./gradlew :<module>:lint :<module>:lintVitalRelease` (plus unit tests) in its worktree before committing, and the parent re-runs release lint for every module a cherry-picked commit touches before merging. The `.githooks/pre-commit` hook (enable once per clone with `git config core.hooksPath .githooks`) enforces this at the actual merge point — it runs release lint for every staged module whenever a commit is made on main and rejects the commit on failure; `.githooks/pre-push` is only a backstop for pushed ranges. Never bypass with `--no-verify`; fix the module instead.