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

Modern-Apps.git / notes / AGENTS.md

AGENTS.md8.2 KiBRenderedCodeRaw
1# AGENTS.md — notes/ (':notes')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `notes/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install notes (dev by default)._
6- Gradle: :notes / dir: notes/
7- Package roots present: ui, data, domain, platform, intents, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:room, :library:ink, :library:image, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/notes.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**Purpose:** Offline markdown+ note-taking app (100% offline). Close-second reference impl after `backup/`, and the canonical `intents/` IPC demo.
15**Key features:**
16- Block-based editor (`Note`/`NoteBlock`) with stylus ink (`:library:ink`) and images (`:library:image`, content-addressed `sha256.jpg`)
17- `.md` import/export — opens files shared from other apps, desktop file-drop, shares notes back out
18- OpenAssistant read/add via `intents/`; local backup/restore via the in-app backup buttons (`BackupButtons`); platform backup via `platform/AppBackupAgent` (key/value `BaseBackupAgent` + `SqlCipherDbCodec`: the DB is exported to plaintext in the backup payload and re-encrypted under the new device's passphrase on restore; `data_extraction_rules.xml` excludes the raw `notes-db`/`passwords-db` files and `secure_prefs` from file copy on both channels, and carries `note_images`/settings/watch store by device transfer)
19**Architecture / data-flow:** `ui/` Compose list/detail → `platform/NotesViewModel` (+ `NotesUiContract`) → `data/NotesRepository` singleton over Room (`Note`/`NoteBlock`/`NoteDatabase`). `MainActivity.onCreateBeforeContent`: repo init → one-time legacy-notes clear + image `img_<uuid>.jpg → sha256.jpg` migration with block-reference rewrite → `ready` gate before `Navigation`.
20**Entry points + reading order:** `Route` (`NotesList` / `Note(id)` / `ExternalNote(uri)`) → `MainActivity.kt` → `Navigation.kt` → `platform/NotesViewModel.kt` → `data/NotesRepository.kt`.
21
22## One APK, two form factors (phone + watch)
23This module is the single Notes APK for phones and watches: same
24`applicationId = "com.vayunmathur.notes"` and signing on both, as the
25WearLink handshake requires. The manifest deliberately declares no
26`android.hardware.type.watch` feature (required=true would block
27phones; required=false is disallowed for this feature), plus
28touchscreen not-required and
29`com.google.android.wearable.standalone=false`; distribution is
30sideload/F-Droid, not Play's watch channel, so the APK installs on
31phones and watches alike. `platform/FormFactor.kt`
32reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the
33sole launcher entry) forwards watches to `ui/WearMainActivity` before
34any phone state loads; phones get the list/detail UI. This module
35declares no broadcast receivers; the watch activity carries no
36launcher filter (`exported=false`) and is reachable only through that
37routing, so every entry point is inert on the wrong form factor.
38
39## Wear sync (Watch conduit client)
40**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.notes.WearNotesProtocol`; the golden-JSON tests in this module pin the shared code's wire format.
41- Snapshot + watch-state sync: conduit data items (`/notes/snapshot` phone -> watch, `/notes/watch-state` watch -> phone)
42- Watch-originated ops: conduit message (`/notes/op`, create/edit/delete)
43- Sync request: conduit message (`/notes/request-sync`), watch -> phone only
44- **Transport: Watch conduit client** — phone side `sync/WearNotesSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `notes`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; snapshots republish on conduit `Connected` and on note changes.
45- **Sync semantics:** phone -> watch is a bounded snapshot — 50 most recent notes, title ≤120 chars, body ≤4000 chars, ≤90_000 JSON bytes (`truncated` flags loss); the watch persists it and reads fully offline. Watch -> phone create/edit/delete ops apply on the phone only, last-writer-wins per note by `updatedAt` (ties: tombstone, then larger title/body), no text merge. Notes with image/ink blocks (`textOnly = false`) are read-only on the watch except delete; watch creates/edits become single-text-block notes on the phone. An op stays pending on the watch (persisted, resent on reconnect) until a phone snapshot reflects it, so the watch UI never claims "synced" before that.
46
47## Watch experience (in this module)
48- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over the recent-notes list / note view / quick-note editor, rendered only from `data/WearNotesStore` (`wear-notes-snapshot.json` + `wear-notes-pending.json`) so it works with the phone absent.
49- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:notes:metadata` into `metadata_data/photos/notes/wear/`; phone shots use the `phone` bucket.
50**Gotchas:**
51- Migrations must finish before `ready = true` — image references break if skipped
52- External/shared URIs enter via the `ExternalNote` route, not the list
53- `intents/` DTOs are the copy-pattern for cross-app IPC; keep them thin
54
55## Key files
56### Root — entry + navigation
57- com/vayunmathur/notes/MainActivity.kt
58- com/vayunmathur/notes/Navigation.kt
59- com/vayunmathur/notes/Route.kt
60### data/ — Room entities + repository
61- com/vayunmathur/notes/data/Note.kt
62- com/vayunmathur/notes/data/NoteBlock.kt
63- com/vayunmathur/notes/data/NoteDatabase.kt
64- com/vayunmathur/notes/data/NotesRepository.kt
65- com/vayunmathur/notes/data/NoteConverters.kt — `tags` JSON-array column
66### domain/ — pure rules (no Android)
67- com/vayunmathur/notes/domain/NoteTags.kt — tag normalisation, rename/merge, counts, suggestions
68- com/vayunmathur/notes/domain/NoteOrder.kt — strict reorder positions (respaces tied positions so a drag persists)
69### platform/ — ViewModel, contract, stores, export
70- com/vayunmathur/notes/platform/AppBackupAgent.kt — platform backup agent (DB via `SqlCipherDbCodec`, `datastore_default`, `note_images`)
71- com/vayunmathur/notes/platform/NotesViewModel.kt
72- com/vayunmathur/notes/platform/NotesUiContract.kt
73- com/vayunmathur/notes/platform/NoteImageStore.kt — content-addressed image copy + migration
74- com/vayunmathur/notes/platform/NoteMarkdownExporter.kt
75### ui/ — list/detail/ink/external screens
76- com/vayunmathur/notes/ui/NotesListScreen.kt
77- com/vayunmathur/notes/ui/NotesListPage.kt
78- com/vayunmathur/notes/ui/NoteScreen.kt
79- com/vayunmathur/notes/ui/NotePage.kt
80- com/vayunmathur/notes/ui/InkEditorPage.kt
81- com/vayunmathur/notes/ui/ExternalNoteScreen.kt
82- com/vayunmathur/notes/ui/components/NoteEditorComponents.kt
83- com/vayunmathur/notes/ui/dialogs/RenameTagDialog.kt
84- com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.kt
85### sync/ — wear sync (both sides)
86- com/vayunmathur/notes/sync/WearNotesSync.kt — phone conduit client node; snapshot publish, watch-state receive, watch-op apply under LWW
87- com/vayunmathur/notes/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store, pending-op flush, watch-state publish
88- com/vayunmathur/notes/sync/RelayNoteProvider.kt
89### Watch experience (ui/ + data/ + platform/)
90- com/vayunmathur/notes/ui/WearMainActivity.kt — watch entry (WearShellActivity)
91- com/vayunmathur/notes/ui/WearRoute.kt, WearNotesListScreen.kt, WearNoteScreen.kt, WearNoteEditorScreen.kt
92- com/vayunmathur/notes/data/WearNotesStore.kt — watch local truth: persisted snapshot merged with pending ops
93- com/vayunmathur/notes/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
94### intents/ — assistant IPC demo (copy this pattern)
95- com/vayunmathur/notes/intents/GetIntent.kt
96- com/vayunmathur/notes/intents/InsertIntent.kt
97
98## Verify (this module only)
99```
100./gradlew :notes:compileDevKotlin
101./gradlew :notes:lint :notes:lintVitalRelease :notes:testDevUnitTest
102./gradlew :notes:checkMetadata
103```