# AGENTS.md — notes/ (':notes') > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `notes/` + allowed shared modules. Do not root-scan. _Install: ./install notes (dev by default)._ - Gradle: :notes / dir: notes/ - Package roots present: ui, data, domain, platform, intents, sync - Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt - Deps: :library:room, :library:ink, :library:image, :library:wearlink, :library:log, Wear Compose (material + foundation) - Metadata: metadata_data/notes.md (present) - Rust: no / screenshotTest: yes ## Overview **Purpose:** Offline markdown+ note-taking app (100% offline). Close-second reference impl after `backup/`, and the canonical `intents/` IPC demo. **Key features:** - Block-based editor (`Note`/`NoteBlock`) with stylus ink (`:library:ink`) and images (`:library:image`, content-addressed `sha256.jpg`) - `.md` import/export — opens files shared from other apps, desktop file-drop, shares notes back out - 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) **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_.jpg → sha256.jpg` migration with block-reference rewrite → `ready` gate before `Navigation`. **Entry points + reading order:** `Route` (`NotesList` / `Note(id)` / `ExternalNote(uri)`) → `MainActivity.kt` → `Navigation.kt` → `platform/NotesViewModel.kt` → `data/NotesRepository.kt`. ## One APK, two form factors (phone + watch) This module is the single Notes APK for phones and watches: same `applicationId = "com.vayunmathur.notes"` and signing on both, as the WearLink handshake requires. The manifest deliberately declares no `android.hardware.type.watch` feature (required=true would block phones; required=false is disallowed for this feature), plus touchscreen not-required and `com.google.android.wearable.standalone=false`; distribution is sideload/F-Droid, not Play's watch channel, so the APK installs on phones and watches alike. `platform/FormFactor.kt` reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the sole launcher entry) forwards watches to `ui/WearMainActivity` before any phone state loads; phones get the list/detail UI. This module declares no broadcast receivers; the watch activity carries no launcher filter (`exported=false`) and is reachable only through that routing, so every entry point is inert on the wrong form factor. ## Wear sync (Watch conduit client) **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. - Snapshot + watch-state sync: conduit data items (`/notes/snapshot` phone -> watch, `/notes/watch-state` watch -> phone) - Watch-originated ops: conduit message (`/notes/op`, create/edit/delete) - Sync request: conduit message (`/notes/request-sync`), watch -> phone only - **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. - **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. ## Watch experience (in this module) - `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. - 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. **Gotchas:** - Migrations must finish before `ready = true` — image references break if skipped - External/shared URIs enter via the `ExternalNote` route, not the list - `intents/` DTOs are the copy-pattern for cross-app IPC; keep them thin ## Key files ### Root — entry + navigation - com/vayunmathur/notes/MainActivity.kt - com/vayunmathur/notes/Navigation.kt - com/vayunmathur/notes/Route.kt ### data/ — Room entities + repository - com/vayunmathur/notes/data/Note.kt - com/vayunmathur/notes/data/NoteBlock.kt - com/vayunmathur/notes/data/NoteDatabase.kt - com/vayunmathur/notes/data/NotesRepository.kt - com/vayunmathur/notes/data/NoteConverters.kt — `tags` JSON-array column ### domain/ — pure rules (no Android) - com/vayunmathur/notes/domain/NoteTags.kt — tag normalisation, rename/merge, counts, suggestions - com/vayunmathur/notes/domain/NoteOrder.kt — strict reorder positions (respaces tied positions so a drag persists) ### platform/ — ViewModel, contract, stores, export - com/vayunmathur/notes/platform/AppBackupAgent.kt — platform backup agent (DB via `SqlCipherDbCodec`, `datastore_default`, `note_images`) - com/vayunmathur/notes/platform/NotesViewModel.kt - com/vayunmathur/notes/platform/NotesUiContract.kt - com/vayunmathur/notes/platform/NoteImageStore.kt — content-addressed image copy + migration - com/vayunmathur/notes/platform/NoteMarkdownExporter.kt ### ui/ — list/detail/ink/external screens - com/vayunmathur/notes/ui/NotesListScreen.kt - com/vayunmathur/notes/ui/NotesListPage.kt - com/vayunmathur/notes/ui/NoteScreen.kt - com/vayunmathur/notes/ui/NotePage.kt - com/vayunmathur/notes/ui/InkEditorPage.kt - com/vayunmathur/notes/ui/ExternalNoteScreen.kt - com/vayunmathur/notes/ui/components/NoteEditorComponents.kt - com/vayunmathur/notes/ui/dialogs/RenameTagDialog.kt - com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.kt ### sync/ — wear sync (both sides) - com/vayunmathur/notes/sync/WearNotesSync.kt — phone conduit client node; snapshot publish, watch-state receive, watch-op apply under LWW - com/vayunmathur/notes/sync/WearLinkBridge.kt — watch conduit client node; snapshot receive into the store, pending-op flush, watch-state publish - com/vayunmathur/notes/sync/RelayNoteProvider.kt ### Watch experience (ui/ + data/ + platform/) - com/vayunmathur/notes/ui/WearMainActivity.kt — watch entry (WearShellActivity) - com/vayunmathur/notes/ui/WearRoute.kt, WearNotesListScreen.kt, WearNoteScreen.kt, WearNoteEditorScreen.kt - com/vayunmathur/notes/data/WearNotesStore.kt — watch local truth: persisted snapshot merged with pending ops - com/vayunmathur/notes/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) ### intents/ — assistant IPC demo (copy this pattern) - com/vayunmathur/notes/intents/GetIntent.kt - com/vayunmathur/notes/intents/InsertIntent.kt ## Verify (this module only) ``` ./gradlew :notes:compileDevKotlin ./gradlew :notes:lint :notes:lintVitalRelease :notes:testDevUnitTest ./gradlew :notes:checkMetadata ```