@@ -517,7 +517,7 @@ One line, two-sided, rendered as compact padded pills rather than a full-width f
517517
518518 **Right side:**
519519
520-- Inner-right: git branch, working tree counts (+ staged, ~ modified, ? untracked), ahead of remote (▲ N). Omitted outside a repo.
520+- Inner-right: git branch, working tree counts (+ staged, ~ modified, ? untracked), and remote divergence counts when present (▲ N ahead, ▼ N behind). Omitted outside a repo.
521521 - Outer-right: `in:input out:output · context%/window · $cost`. `in`, `out`, and `$cost` are **cumulative for the session**. `context%/window` shows the **estimated current context usage for the next model request** as a percentage of the active model's context window.
522522 - Context tone mapping: `<25%` → scale 0, `25-49.9%` → scale 1, `50-74.9%` → scale 2, `75-89.9%` → scale 3, `>=90%` → scale 4.
523523
@@ -528,7 +528,7 @@ Token counts use human-friendly units (1.2k, 45k, 1.2M). Context usage is estima
528528 ```text
529529 [ anthropic/sonnet-4 · med ] [ ~/src/mini-coder ] [ main +3 ~1 ▲ 2 ] [ in:1.2k out:0.8k · 42.0%/200k · $0.03 ]
530530 [ openai/gpt-5-mini · low ] [ ~/src/mini-coder ] [ in:220 out:90 · 8.0%/200k · $0.00 ]
531-[ openrouter/qwen3-coder · xhigh ] [ …/mini-coder ] [ feat/ui ~4 ?2 ▲ 7 ] [ in:180k out:24k · 93.0%/200k · $2.10 ]
531+[ openrouter/qwen3-coder · xhigh ] [ …/mini-coder ] [ feat/ui ~4 ?2 ▲ 7 ▼ 1 ] [ in:180k out:24k · 93.0%/200k · $2.10 ]
532532 ```
533533
534534 The outer-left pill tone changes with effort, the outer-right pill tone changes with context pressure, and the inner pills stay neutral.
@@ -544,10 +544,10 @@ Tool blocks share a common frame: a left border (`│`) plus a compact header pi
544544 - **User messages**: displayed as plain text with a subtle background color to distinguish them from agent responses. No prefix or role indicator.
545545 - **Assistant messages**: streamed raw markdown rendered via cel-tui's `SyntaxHighlight` component on the default background so the log stays copy-friendly and preserves markdown markers. Thinking/reasoning content is collapsible (shown or hidden according to the user's persisted `/reasoning` preference; defaults to shown when no setting exists).
546546 - **Tool calls — shell**: rendered in the shared tool frame. The assistant tool call streams the command as it arrives. The command preview and shell tool result body use [verbose tool rendering](#verbose-tool-rendering). Shell tool results render the tool output content below a `shell <-` header.
547-- **Tool calls — edit**: rendered in the shared tool frame. The in-progress tool-call preview shows the target path plus the streamed replacement content, preserving whitespace. The preview body uses [verbose tool rendering](#verbose-tool-rendering). Successful results render a compact confirmation block (`edit <-` plus the file path); errors render the returned error text.
547+- **Tool calls — edit**: rendered in the shared tool frame. The in-progress tool-call preview shows the target path followed by the streamed `oldText` and `newText` bodies. Old text is styled as removed and new text as added, but the preview does not render literal `-`/`+` diff prefixes. The preview body uses [verbose tool rendering](#verbose-tool-rendering). Successful results render a compact confirmation block (`edit <-` plus the file path); errors render the returned error text.
548548 - **Tool calls — readImage**: rendered in the shared tool frame. The assistant tool call streams the path as it arrives. Successful results render a compact result block (`read image <-` plus the file path) rather than rendering the image itself.
549549 - **Tool calls — plugin tools**: rendered in the shared tool frame, prefixed with plugin/tool name when available.
550-- **UI messages**: internal app messages such as `/help` output, OAuth progress, and other session-local notices. They are rendered in the conversation log, persisted with the session, excluded from model context, and do not participate in conversational turn numbering.
550+- **UI messages**: internal app messages such as `/help` output, OAuth progress, `/fork` notices, and other session-local notices. They are rendered in the conversation log, persisted with the session, excluded from model context, and do not participate in conversational turn numbering.
551551 - **Errors**: one-line summary, styled distinctly.
552552
553553 #### Verbose tool rendering
@@ -631,7 +631,7 @@ Representative entry shapes:
631631 │ edit ->
632632 │ src/session.ts
633633 │ const turn = getCurrentTurn(sessionId);
634- │ saveMessage(sessionId, turn, message);
634+ │ const turn = getNextTurn(sessionId);
635635 │ And 9 lines more
636636 ```
637637
@@ -640,6 +640,7 @@ Representative entry shapes:
640640 ```text
641641 │ edit ->
642642 │ src/session.ts
643+ │ const turn = getCurrentTurn(sessionId);
643644 │ const turn = getNextTurn(sessionId);
644645 │ saveMessage(sessionId, turn, message);
645646 │ return turn;
@@ -742,7 +743,7 @@ add tests for undo_
742743 | `/model` | Interactive model selector. The list includes built-in models plus any custom OpenAI-compatible models discovered from `settings.json`. Switching models mid-session is allowed — pi-ai's context is model-agnostic. The `readImage` tool is re-evaluated (added/removed based on the new model's capabilities). The status bar updates immediately, and the selected model is persisted immediately as the user's global default. The session record's `model` field is not updated (it reflects …
743744 | `/session` | Interactive session manager (list, resume). Sessions scoped to CWD. …
744745 | `/new` | Start a new session. Clears conversation, resets cost/token counters. …
745-| `/fork` | Fork the current conversation into a new session. Copies the full message history, continues from here independently. The original session is preserved. …
746+| `/fork` | Fork the current conversation into a new session. Copies the full message history, continues from here independently, and appends a UI-only `Forked session.` notice in the new session. The original session is preserved. …
746747 | `/undo` | Remove the last conversational turn from history: the most recent user message and all assistant/tool messages that followed in that turn. Persisted UI messages are not part of turns and are not removed by `/undo`. Context-only — does not revert filesystem changes. …
747748 | `/reasoning` | Toggle display of model thinking/reasoning content in the log. The new on/off state is persisted immediately and restored on launch. When no setting exists yet, reasoning defaults to shown. …
748749 | `/verbose` | Toggle [verbose tool rendering](#verbose-tool-rendering) for shell previews/results, edit previews, and edit errors. Successful edit results stay compact regardless of this setting. …
@@ -909,7 +910,7 @@ CREATE INDEX idx_prompt_history_created_at ON prompt_history(created_at, id);
909910
910911 **Messages as JSON blobs**: pi-ai's `Message` type (UserMessage, AssistantMessage, ToolResultMessage) is already serializable, and we also persist internal UI-only log entries in the same table. We store the full object as JSON in `data` rather than normalizing into columns. Session load returns the complete chronological log; model context construction filters out UI-only messages before replaying the remaining pi-ai messages into a pi-ai `Context`.
911912
912-**Turn grouping**: the `turn` column groups only conversational messages. A turn is: one user message + one or more assistant messages + any tool result messages from that agent loop. Persisted UI messages are stored alongside them but have `turn = NULL`, so they remain visible in session history without becoming part of `/undo`. `/fork` copies all persisted messages to a new session, preserving conversational turn numbers and UI messages as-is.
913+**Turn grouping**: the `turn` column groups only conversational messages. A turn is: one user message + one or more assistant messages + any tool result messages from that agent loop. Persisted UI messages are stored alongside them but have `turn = NULL`, so they remain visible in session history without becoming part of `/undo`. `/fork` copies all existing persisted messages to a new session, preserving conversational turn numbers and existing UI messages as-is, then appends a new UI-only notic …
913914
914915 **Cumulative stats are computed, not stored**: the status bar's cumulative `in`, `out`, and `$cost` values are computed by summing `usage` from assistant messages on session load (deserialize all messages, filter for `role: "assistant"`, sum their `usage` fields). The message count per session is small (hundreds), so this is fast. No separate counters to keep in sync. During an active session, a running in-memory accumulator is updated after each assistant message to avoid re-scanning. `context% …
915916
@@ -923,12 +924,12 @@ CREATE INDEX idx_prompt_history_created_at ON prompt_history(created_at, id);
923924
924925 ### Operations
925926
926-| Operation | SQL |
927-| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
928-| New session | `INSERT INTO sessions` |
929-| Append message | `INSERT INTO messages` with the current conversational turn number (or `NULL` for UI-only messages), `UPDATE sessions SET updated_at` |
930-| Undo | `DELETE FROM messages WHERE session_id = ? AND turn = (SELECT MAX(turn) FROM messages WHERE session_id = ?)` |
931-| Fork | `INSERT INTO sessions` (new id, `forked_from` set), then `INSERT INTO messages SELECT ... FROM messages WHERE session_id = ?` (copy all, new session_id) |
932-| List sessions | `SELECT * FROM sessions WHERE cwd = ? ORDER BY updated_at DESC` |
933-| Load session | `SELECT data FROM messages WHERE session_id = ? ORDER BY id` → parse JSON → persisted message log (`pi-ai Message[]` + internal UI messages) |
934-| Delete session | `DELETE FROM sessions WHERE id = ?` (cascade deletes messages) |
927+| Operation | SQL |
928+| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
929+| New session | `INSERT INTO sessions` |
930+| Append message | `INSERT INTO messages` with the current conversational turn number (or `NULL` for UI-only messages), `UPDATE sessions SET updated_at` |
931+| Undo | `DELETE FROM messages WHERE session_id = ? AND turn = (SELECT MAX(turn) FROM messages WHERE session_id = ?)` |
932+| Fork | `INSERT INTO sessions` (new id, `forked_from` set), then `INSERT INTO messages SELECT ... FROM messages WHERE session_id = ?` (copy all, new session_id), then append a UI-only fork notice with `turn = NULL` |
933+| List sessions | `SELECT * FROM sessions WHERE cwd = ? ORDER BY updated_at DESC` |
934+| Load session | `SELECT data FROM messages WHERE session_id = ? ORDER BY id` → parse JSON → persisted message log (`pi-ai Message[]` + internal UI messages) |
935+| Delete session | `DELETE FROM sessions WHERE id = ?` (cascade deletes messages) |