Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / openassistant / AGENTS.md
| 1 | # AGENTS.md — openassistant/ (':openassistant') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `openassistant/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install openassistant (dev by default)._ |
| 6 | <!-- last-reviewed: 2026-10-16 --> |
| 7 | - Gradle: :openassistant / dir: openassistant/ |
| 8 | - Package roots present: ui, data, domain, platform |
| 9 | - Entry files: MainActivity.kt (no Route.kt — `Route` + `Navigation` are inline) |
| 10 | - Deps: :library:room, :library:image, :library:ml, :library:downloadservice, androidx.a2ui (model + engine) |
| 11 | - Metadata: metadata_data/openassistant.md (present) |
| 12 | - Rust: no / screenshotTest: yes |
| 13 | |
| 14 | ## Overview |
| 15 | **Purpose:** A simple open-source local AI app — Gemma 4 E2B runs fully on device (~3.5GB RAM when active). Internet only for initial asset downloads. |
| 16 | **Key features:** |
| 17 | - Multiple chats with streaming responses and markdown rendering, persisted in Room |
| 18 | - Multimodal input: photo upload and audio recording, read by Gemma 4's vision and audio towers |
| 19 | - Tool calling into other Modern Apps over local IPC, with JSON-schema validation |
| 20 | - A model-managed memory plus an editable system prompt; can be set as the device's default digital assistant (Assist API + voice interaction service) |
| 21 | - Generative UI: replies can carry an A2UI block (cards, forms, buttons) rendered natively; button events come back to the model as user turns |
| 22 | **Architecture / data-flow:** `ui/LiteRTChatUi` → `util/AssistantViewModel` → `data/OpenAssistantRepository` (Room) + `util/InferenceService` → `platform/MamlChatEngine` (Gemma 4 on `:library:ml`'s `Gemma4Handle`; own tool loop, max 6 rounds) with `platform/AssistantTools` (explicit registry over `domain/AssistantToolSpecs`) dispatching IPC tool calls. Pure logic (tool-call parsing/markup stripping, tool loop, WAV decode, history fitting) lives in `domain/` with unit tests. `onCreateBeforeContent` only wires the `IntentLauncher` and picks up Assist-API screen context; `Content()` gates on the initial model download before the chat renders. |
| 23 | **Entry points + reading order:** `Route` (`ConversationPage(id)` / `SettingsPage`, inline) → `MainActivity.kt` → `ui/LiteRTChatUi.kt` → `util/AssistantViewModel.kt` → `util/InferenceService.kt` → `platform/MamlChatEngine.kt` → `data/OpenAssistantRepository.kt`. |
| 24 | **Gotchas:** |
| 25 | - Card drift fixed: `ui/` files were renamed `Assistant*` → `LiteRT*` and `util/` gained `AssistantDeviceTools`, `AssistantToolIntents`, `JsonSchemaValidator`; `Gemma4Engine`/`Gemma4EtEngine` no longer exist |
| 26 | - `MainActivity.intentLauncher` is a shared static other apps mirror (maps/taxi pattern) — keep it initialized in `onCreateBeforeContent` |
| 27 | - `StubRecognitionService` is a placeholder voice-recognition hook, not a real recognizer |
| 28 | - Tool names are snake_case (`get_notes`, `add_to_memory`), matching what LiteRT-LM exposed; the system prompt references them. Add a tool in `domain/AssistantToolSpecs.kt` AND `platform/AssistantTools.kt` (an init check fails if they disagree) |
| 29 | - Model files live in `getExternalFilesDir(null)/gemma4/` (text, embed, head, vision, audio, tokenizer); the vision/audio towers load lazily and unload after 3 idle minutes |
| 30 | - Extra non-conforming dirs (`assist/`, `util/`) hold real code — closed-roots migration pending |
| 31 | - A2UI: the model writes only ```` ```a2ui {"components":[...],"data":{...}} ```` and `domain/A2uiEnvelope` adds the protocol envelope. Surface id is `m<messageId>`; the block is stored in `Message.a2ui` (DB v4) and replayed by `platform/A2uiController.sync`. androidx.a2ui ships no renderer — `ui/A2uiSurfaceView` is ours. Add a component in `platform/AssistantCatalog` (schema + prompt line together) AND the `when` in `A2uiSurfaceView` |
| 32 | - `AssistantCatalog.PROMPT_SECTION` is appended to every system prompt, so changing it (or the catalog) invalidates the baked `gemma4_prefix.kv`: still correct, but first turns prefill until it is rebaked with `bake_gemma4_prefix` |
| 33 | |
| 34 | ## Key files |
| 35 | ### Root — entry + inline navigation |
| 36 | - com/vayunmathur/openassistant/MainActivity.kt — Route, Navigation, assist screen-context |
| 37 | ### assist/ — system assistant surfaces |
| 38 | - com/vayunmathur/openassistant/assist/OpenAssistantSession.kt — Assist API screen-text capture |
| 39 | - com/vayunmathur/openassistant/assist/OpenAssistantSessionService.kt |
| 40 | - com/vayunmathur/openassistant/assist/OpenAssistantVoiceInteractionService.kt |
| 41 | - com/vayunmathur/openassistant/assist/StubRecognitionService.kt — placeholder recognizer hook |
| 42 | ### data/ — chats + repository |
| 43 | - com/vayunmathur/openassistant/data/Database.kt |
| 44 | - com/vayunmathur/openassistant/data/OpenAssistantRepository.kt |
| 45 | ### ui/ — chat + settings |
| 46 | - com/vayunmathur/openassistant/ui/LiteRTChatUi.kt |
| 47 | - com/vayunmathur/openassistant/ui/LiteRTChatScreen.kt |
| 48 | - com/vayunmathur/openassistant/ui/LiteRTChatBubble.kt |
| 49 | - com/vayunmathur/openassistant/ui/LiteRTChatInput.kt |
| 50 | - com/vayunmathur/openassistant/ui/SettingsPage.kt |
| 51 | - com/vayunmathur/openassistant/ui/A2uiSurfaceView.kt — Compose renderer for A2UI surfaces |
| 52 | ### domain/ — pure, unit-tested |
| 53 | - com/vayunmathur/openassistant/domain/AssistantToolSpecs.kt — tool names/descriptions/params |
| 54 | - com/vayunmathur/openassistant/domain/ToolCalls.kt — call parsing, markup stripping, arg coercion |
| 55 | - com/vayunmathur/openassistant/domain/ToolLoop.kt — generate/call/respond loop |
| 56 | - com/vayunmathur/openassistant/domain/WavDecoder.kt |
| 57 | - com/vayunmathur/openassistant/domain/HistoryFit.kt |
| 58 | - com/vayunmathur/openassistant/domain/A2uiBlocks.kt — split/restore ```a2ui blocks, streaming-safe |
| 59 | - com/vayunmathur/openassistant/domain/A2uiEnvelope.kt — block → A2UI protocol messages, action → user turn |
| 60 | ### platform/ — engine + tool registry |
| 61 | - com/vayunmathur/openassistant/platform/MamlChatEngine.kt |
| 62 | - com/vayunmathur/openassistant/platform/AssistantTools.kt |
| 63 | - com/vayunmathur/openassistant/platform/AssistantCatalog.kt — A2UI component catalog + its prompt section |
| 64 | - com/vayunmathur/openassistant/platform/A2uiController.kt — owns the A2UI engine; events → user turns |
| 65 | - com/vayunmathur/openassistant/platform/A2uiComposeState.kt — snapshot-state registry + data model |
| 66 | ### util/ — ViewModel, inference, tools, audio (migration pending) |
| 67 | - com/vayunmathur/openassistant/util/AssistantViewModel.kt |
| 68 | - com/vayunmathur/openassistant/util/AssistantUiContract.kt |
| 69 | - com/vayunmathur/openassistant/util/InferenceService.kt |
| 70 | - com/vayunmathur/openassistant/util/AssistantToolIntents.kt |
| 71 | - com/vayunmathur/openassistant/util/AssistantDeviceTools.kt |
| 72 | - com/vayunmathur/openassistant/util/JsonSchemaValidator.kt |
| 73 | - com/vayunmathur/openassistant/util/AudioRecorder.kt |
| 74 | - com/vayunmathur/openassistant/util/AppBackupAgent.kt |
| 75 | |
| 76 | ## Verify (this module only) |
| 77 | ``` |
| 78 | ./gradlew :openassistant:compileDevKotlin |
| 79 | ./gradlew :openassistant:testDevUnitTest |
| 80 | ./gradlew :openassistant:lint |
| 81 | ./gradlew :openassistant:checkMetadata |
| 82 | ``` |