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

Modern-Apps.git / notes / AGENTS.md

AGENTS.md9.1 KiBRenderedCodeRaw

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: 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/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.
  • Push triggers: the publish also runs on the phone Watch app's scheduled sync-trigger intent (sync/ConduitSyncTriggerReceiver, exported only under the CONDUIT signature permission, invoking WearNotesSync.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 (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 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 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
  • 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 — 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