Update CLAUDE.md with ChatScreenViewModel architecture

This commit is contained in:
Bruno Deanoz 2026-06-24 10:10:43 +02:00
parent 40db869717
commit 06757d6f69

View file

@ -60,8 +60,9 @@ ui/
- **KaizenApi** (`net/KaizenApi.kt`) — singleton `object`, all HTTP calls via OkHttp. Three clients sharing one connection pool: `baseClient` (30s timeout, also used by LiveClient), `streamClient` (infinite timeout, chat only), `imageClient` (same as baseClient). Streaming chat returns `Flow<StreamState>` via `streamClient`. `uploadStream()` accepts InputStream for zero-copy file uploads.
- **StreamConsumer** (`net/StreamConsumer.kt`) — O(chunk-size) incremental parser, each character visited exactly once across the entire stream.
- **SessionViewModel** (`net/SessionViewModel.kt`) — Compose snapshot state for auth session. Holds `ServerConfig` (baseUrl, token, model, email, speed). Persisted in `EncryptedSharedPreferences` via `SecureStore`.
- **ChatViewModel** (`chat/ChatViewModel.kt`) — owns Room database instance + repositories. Created in `MainActivity`, passed to `ChatScreen`.
- **ChatScreen** (`chat/ChatScreen.kt`) — main composable, orchestrates sidebar, messages, streaming, file uploads.
- **ChatViewModel** (`chat/ChatViewModel.kt`) — owns Room database instance + repositories. Created in `MainActivity`, passed to `ChatScreenViewModel`.
- **ChatScreenViewModel** (`chat/ChatScreenViewModel.kt`) — owns all chat state and business logic: messages, streaming, conversation management, sidebar actions, file upload, voice recording, TTS, live call, biometric unlock. Extends `ViewModel` with `viewModelScope`. Dependencies: `Application?`, `SessionViewModel`, `ChatViewModel?`, `SettingsViewModel`. Nullable deps for JVM test construction.
- **ChatScreen** (`chat/ChatScreen.kt`) — thin rendering layer (~430 lines). Reads state from `ChatScreenViewModel`, wires UI events to VM methods. Owns Android-framework-only concerns: `ActivityResultLauncher` (camera/gallery/file), `DrawerState`, `LazyListState`, keyboard insets, `LifecycleResumeEffect`.
### Design System v2 (`ui/`) — added 2026-06-21
@ -294,6 +295,7 @@ All committed on `main`. Compile-verified on Mac (`./gradlew :app:compileDebugKo
| `430d5b6` | **Flat sidebar user row** — removed heavy card (background, border, shadow), replaced with flat row + thin separator |
| — | **Branch navigation (tree support)**`ChatTree` data structure mirrors web frontend's tree. Edit creates a branch (sibling node with same parentId) instead of deleting messages. Regenerate creates a new assistant branch. `BranchNavigator` UI (chevron arrows + "1/3" counter) on messages with siblings. `activeRootId`/`activeChild` synced to server via PATCH. `StoredMessage.parentId` parsed from API. `patchConversation` handles JSON object values for `activeChild` |
| `3b73e15` | **Security hardening + performance pass** — JSON injection fix (deleteMessage), separate stream OkHttpClient (30s timeout on normal requests), disable backup, block cleartext, strip URLs from logs. Shared connection pool (LiveClient reuses KaizenApi.baseClient), eliminate duplicate fetchMe, parallel prefetchMissing, streaming file uploads (no readBytes), O(1) message index during streaming, send() race condition fix, voice recording file read on IO thread |
| `40db869` | **ChatScreenViewModel extraction** — moved ~35 state variables + ~15 business-logic functions from the 1540-line God Composable into `ChatScreenViewModel`. ChatScreen is now ~430 lines (pure UI). `createHaptics()` factory for non-Composable use. `SessionViewModel.store` nullable for JVM test construction. 12 new unit tests |
**Earlier UI/feel work (Phase 0 prototype → feel-first):**
- Liquid glass styling, floating panels, glassmorphic sidebar
@ -487,6 +489,7 @@ composeIcons = "1.0.0" # com.composables:icons-lucide-android (Lucide
**Unit tests** (`app/src/test/`): JVM-only, no emulator needed.
- `ChatScreenViewModelTest` — 12 tests: initial state, newChat reset, send guards (no config, empty input, while streaming), input binding, mode/reasoning/sampling toggles, screen navigation, password dialog lifecycle, edit message, delete message, file removal, attach menu, TTS voice
- `SettingsViewModelTest` — state transitions, all 4 themes, appearance modes, name updates with store-less default
- `StreamConsumerTest` — batch + incremental parser, sentinel stripping, reasoning/sources/tools/usage parsing, char-by-char edge cases
- `OklabTest` — round-trip conversion, interpolation midpoint, gradient generation (all green since Double-precision fix)