| name | maintain-sessions |
| description | Maintain ChatStore persistence, schema validation, message/session lifecycles, titles, ordering, provenance, tool records, and Live pinning. Use when changing local conversation storage or session identity and status semantics. |
Maintain sessions
Role and boundary
Keep ChatStore as the single observable owner of persisted Chat/Live transcript state. It owns schema validation and session/message mutation; views, providers, speech, and native Live may consume it but must not maintain parallel persisted state.
Source map
src/chat-store.ts: ChatMessage/ChatToolMessage/provenance/status types, voice-layer-chat-sessions key, tolerant readers, ChatStore, append/update/activate/delete/clear/new-session/set-mode, title/order logic, and subscribers.
src/main.ts: Chat sidebar activation/new/delete/clear and generation append paths; src/live.ts: pinned conversationSessionId, Live mode marking, transcript rendering, and stop guards.
src/chat-message-view.ts: status, voice caption/duration, tool expansion, and diagnostic-reference projection.
src/voice-draft-provenance.ts: exact transcript/duration admission and edit invalidation; tests tests/chat-store.test.ts, tests/live.test.ts, tests/voice-draft-provenance.test.ts.
Cover
- Preserve one active usable session, random stable IDs, created/updated timestamps, most-recently-updated ordering, 38-scalar title truncation, and storage fallback to an in-memory fresh state.
- Validate loaded objects before use; preserve user/assistant/tool roles, complete/interrupted/error status, diagnostic IDs, voice origin and real duration, tool arguments/results/status/expanded state, and no fabricated fields.
- Keep New task's empty-session reuse and mode update, first user-message title, permanent deletion, final-session replacement, clear-all replacement, and synchronous subscriber notifications.
- Pin Live to the conversation ID captured at Start Live; prevent sidebar changes, stop races, or stale events from appending/generating against another session. Keep tool messages out of provider history while persisting their visible records.
- Inspect current schema and tests before changing persistence; treat local storage as untrusted and conversation text as local-first data.
Validate and accept
- Run
bun test tests/chat-store.test.ts tests/live.test.ts tests/voice-draft-provenance.test.ts and exercise reload, malformed storage, sorting, title, deletion, Live pinning, and provenance edits.
- Run
git diff --check against the actual files changed; run just check when the change crosses TypeScript/Rust/build boundaries. Inspect session switching while speech/generation/Live are active in the packaged app with $test-voice-layer-app.
- Treat real WebView storage persistence and human destructive-action confirmation as acceptance beyond unit coverage.
Relationships
Use $maintain-session-sidebar for row UI, $maintain-chat for typed turns, $maintain-live for native Live lifecycle, $maintain-assistant-orchestration for request identity, and $maintain-local-tools for tool-message semantics.