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-addressedsha256.jpg) .mdimport/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 viaplatform/AppBackupAgent(key/valueBaseBackupAgent+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.xmlexcludes the rawnotes-db/passwords-dbfiles andsecure_prefsfrom file copy on both channels, and carriesnote_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: cheap repo construction (Room opens lazily on first query) so Navigation composes on the first frame; the one-time legacy-notes clear + image img_<uuid>.jpg → sha256.jpg migration with block-reference rewrite + tombstone GC run on Dispatchers.IO in the background and land through the notes Flow. 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 one broadcast receiver, the conduit sync-trigger receiver (sync/ConduitSyncTriggerReceiver, phone-side snapshot publish only); 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/snapshotphone -> watch,/notes/watch-statewatch -> 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.ktand watch sidesync/WearLinkBridge.ktboth useWearLinkClientNode(Messenger to the Watch app'swatch_conduitservice, appIdnotes); 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 reportsNotInstalled/Unavailableand the sync stays idle; snapshots republish on conduitConnectedand on note changes. - Push triggers: the publish also runs on the phone Watch app's scheduled sync-trigger intent (
sync/ConduitSyncTriggerReceiver, exported only under theCONDUITsignature permission, invokingWearNotesSync.syncNow()— no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration. - Sync semantics: phone -> watch is a bounded snapshot — 50 most recent notes, title ≤120 chars, body ≤4000 chars, ≤90_000 JSON bytes (
truncatedflags 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 byupdatedAt(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(aWearShellActivity) routesui/WearRouteover the recent-notes list / note view / quick-note editor, rendered only fromdata/WearNotesStore(wear-notes-snapshot.json+wear-notes-pending.json) so it works with the phone absent.- Watch listing screenshots are the
group = "wear"previews insrc/screenshotTest/.../ui/WearMetadataPreviews.kt, collected by:notes:metadataintometadata_data/photos/notes/wear/; phone shots use thephonebucket.
Gotchas:
- Migrations run at every start until they are no-ops; a note opened before the image-reference rewrite lands may briefly miss an image, then updates when the rewrite re-emits the row
- External/shared URIs enter via the
ExternalNoteroute, 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
- src/main/baseline-prof.txt + src/main/startup-prof.txt — cold-start Baseline/Startup Profiles (HRF, hand-authored from the startup classpath; AGP compiles them into the release APK, ProfileInstaller ships via common-conventions-app)
- 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 —
tagsJSON-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