xonecas.io
64875
Mc

mini-coder / commit 9ee5927

feat: add status bar tone scales

xonecas2026-04-09 9ee592703b4b237019b29f1a62a7de63d7f2f295 parent 6b1b19d

9 files changed

README.md+4−4
@@ -50,9 +50,9 @@ Plugins can add more tools, but the core stays intentionally small.
5050 ## Features
5151
5252 - **Multi-provider model support** — Anthropic, OpenAI, Google, Bedrock, Mistral, Groq, xAI, OpenRouter, Ollama, Copilot, and more via pi-ai.
53-- **Streaming TUI** — markdown conversation log, tool blocks with diffs, animated divider, multi-line input, and a one-line pill status bar.
53+- **Streaming TUI** — markdown conversation log, tool blocks with diffs, animated divider, multi-line input, and a one-line pill status bar with independent ANSI16 effort/context tones.
5454 - **Session persistence** — SQLite-backed sessions with undo, fork, resume, and cumulative usage stats. Sessions are scoped to the working directory.
55-- **Reasoning and verbosity controls** — toggle thinking visibility and full tool output on demand. Preferences persist across launches.
55+- **Reasoning and verbosity controls** — toggle thinking visibility and verbose tool rendering on demand. Preferences persist across launches.
5656 - **[AGENTS.md](https://agents.md) support** — project-specific instructions discovered root-to-leaf, with `~/.agents/` for global instructions.
5757 - **[Agent Skills](https://agentskills.io)** — skill catalogs exposed in the prompt. `/skill:name` injects a skill body into the next user message.
5858 - **Plugins** — optional tools, integrations, theme overrides, and prompt suffixes without bloating the core.
@@ -67,10 +67,10 @@ Plugins can add more tools, but the core stays intentionally small.
6767 | `/fork` | Copy the conversation into a new session and continue independently. |
6868 | `/undo` | Remove the last conversational turn (does not revert file changes). |
6969 | `/reasoning` | Toggle thinking visibility. Persisted and restored on launch. |
70-| `/verbose` | Toggle full shell output and edit diff display. |
70+| `/verbose` | Toggle verbose shell rendering plus edit previews/errors in the log. |
7171 | `/login` | Interactive OAuth login for supported providers. |
7272 | `/logout` | Clear saved OAuth credentials for a logged-in provider. |
73-| `/effort` | Set reasoning effort: low, med, high, or xhigh. |
73+| `/effort` | Set reasoning effort: low, medium, high, or xhigh. |
7474 | `/help` | List commands, loaded AGENTS.md files, discovered skills, and plugins. |
7575
7676 ## Key bindings
TODO.md+0−1
@@ -26,6 +26,5 @@ The spec.md and code are the sources of truth, not this file, don't assume anyth
2626 ## Future ideas
2727
2828 - [ ] Headless one-shot CLI mode for non-interactive runs and benchmark harnesses like Harbor/Terminal-Bench (https://www.tbench.ai/)
29-- [ ] Use dark/cold to warm/bright gradient for the statusbar backgrounds, the model info based on the thinking effort, and the session stats based on context percentage.
3029 - [ ] Divider theme plugin — customizable divider animations (scanning pulse, breathing, flowing dots, wave)
3130 - [ ] Backward-compatibility and migration policy for 1.0 (session/app data versioning, explicit migration strategy)
spec.md+31−15
@@ -422,11 +422,11 @@ VStack({ height: "100%" }, [
422422 TextInput({ minHeight: 2, maxHeight: 10, padding: { x: 1 } }),
423423 // Status pills — fixed 1 line, backgrounds only behind the text
424424 HStack({ height: 1, padding: { x: 1 } }, [
425- statusPill(modelInfo, theme.statusPrimaryBg),
426- statusPill(cwd, theme.statusSecondaryBg),
425+ statusPill(modelInfo, effortTone(theme, effort)),
426+ statusPill(cwd, theme.statusSecondary),
427427 Spacer(),
428- gitStatus && statusPill(gitStatus, theme.statusSecondaryBg),
429- statusPill(usage, theme.statusPrimaryBg),
428+ gitStatus && statusPill(gitStatus, theme.statusSecondary),
429+ statusPill(usage, contextTone(theme, contextPct)),
430430 ]),
431431 ]);
432432 ```
@@ -436,6 +436,13 @@ VStack({ height: "100%" }, [
436436 All UI colors are defined in a single `Theme` object. The UI never hardcodes colors — it reads from the active theme. Plugins can return a `Partial<Theme>` in their `PluginResult` to override any color. Multiple plugin overrides are merged left-to-right (last wins).
437437
438438 ```ts
439+interface StatusTone {
440+ /** Pill foreground. */
441+ fg: Color | undefined;
442+ /** Pill background. */
443+ bg: Color | undefined;
444+}
445+
439446 interface Theme {
440447 /** User message background. */
441448 userMsgBg: Color | undefined;
@@ -455,12 +462,18 @@ interface Theme {
455462 divider: Color | undefined;
456463 /** Divider scanning pulse highlight color (active state). */
457464 dividerPulse: Color | undefined;
458- /** Status pill foreground. */
459- statusText: Color | undefined;
460- /** Primary status pill background (outer pills: model/effort + usage/context/cost). */
461- statusPrimaryBg: Color | undefined;
462- /** Secondary status pill background (inner pills: CWD + git). */
463- statusSecondaryBg: Color | undefined;
465+ /** Neutral status pill tone for the inner CWD/git pills. */
466+ statusSecondary: StatusTone;
467+ /** Model/effort pill tones from low/cold to xhigh/warm. */
468+ statusEffortScale: [StatusTone, StatusTone, StatusTone, StatusTone];
469+ /** Usage/context pill tones from empty/cold to near-full/hot. */
470+ statusContextScale: [
471+ StatusTone,
472+ StatusTone,
473+ StatusTone,
474+ StatusTone,
475+ StatusTone,
476+ ];
464477 /** Error text. */
465478 error: Color | undefined;
466479 /** Overlay modal background. */
@@ -468,7 +481,7 @@ interface Theme {
468481 }
469482 ```
470483
471-The default theme uses the full ANSI 16-color terminal palette where semantic accents or pill styling benefit from it, including bright variants (`color08`-`color15`) rather than restricting itself to the base 8 colors. Semantic colors should still map sensibly (for example, greens for additions/success and reds for removals/errors), but status pill styling may draw from the wider ANSI 16 range to create restrained outer/inner separation. Status pill backgrounds are applied only behind the text …
484+The default theme uses the full ANSI 16-color terminal palette where semantic accents or pill styling benefit from it, including bright variants (`color08`-`color15`) rather than restricting itself to the base 8 colors. Semantic colors should still map sensibly (for example, greens for additions/success and reds for removals/errors), but the status bar now uses independent stepped tone scales rather than one shared outer-pill background. The inner CWD/git pills stay neutral, while the model pill …
472485
473486 ### Status bar
474487
@@ -479,20 +492,23 @@ One line, two-sided, rendered as compact padded pills rather than a full-width f
479492 ```
480493
481494 - Background is applied only behind each pill's text + padding; there is no bottom divider below the input and no full-width colored block.
482-- The outer pills (`model/effort` on the left, `usage/context/cost` on the right) use `statusPrimaryBg`.
483-- The inner pills (`cwd` on the left, `git` on the right) use `statusSecondaryBg`.
484-- All status pill text uses `statusText`, chosen to remain legible against both pill backgrounds on light and dark terminals.
495+- The inner pills (`cwd` on the left, `git` on the right) use the neutral `statusSecondary` tone.
496+- The outer-left `model/effort` pill chooses its tone from `statusEffortScale`, mapped to reasoning effort from low/cold to xhigh/warm.
497+- The outer-right `usage/context/cost` pill chooses its tone from `statusContextScale`, mapped to estimated context pressure from empty/cold to near-full/hot.
498+- The two outer pills are independent; high effort does not force a hot context pill, and high context usage does not force a hot effort pill.
485499 - The git pill is omitted outside a repo, preserving the current omission behavior.
486500
487501 **Left side:**
488502
489503 - Outer-left: `provider/model · effort`. Effort shown as `low`, `med`, `high`, `xhigh`.
504+- Effort tone mapping: `low` → scale 0, `medium` → scale 1, `high` → scale 2, `xhigh` → scale 3.
490505 - Inner-left: CWD, abbreviated with `~` for home. Truncated from the left (`…/mini-coder`) on narrow terminals.
491506
492507 **Right side:**
493508
494509 - Inner-right: git branch, working tree counts (+ staged, ~ modified, ? untracked), ahead of remote (▲ N). Omitted outside a repo.
495510 - 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.
511+- Context tone mapping: `<25%` → scale 0, `25-49.9%` → scale 1, `50-74.9%` → scale 2, `75-89.9%` → scale 3, `>=90%` → scale 4.
496512
497513 Token counts use human-friendly units (1.2k, 45k, 1.2M). Context usage is estimated from the current model-visible conversation, not just the last assistant message. Use the most recent valid assistant `usage` as an anchor (`totalTokens` when present, otherwise `input + output + cacheRead + cacheWrite`) and add heuristic estimates for any later messages. If no assistant `usage` exists yet, estimate the full current model-visible history heuristically. UI-only messages are excluded from this esti …
498514
@@ -563,7 +579,7 @@ Supports:
563579 | `/verbose` | Toggle [verbose tool rendering](#verbose-tool-rendering) for shell previews/results, edit previews, and edit errors. Successful edit diffs always render in full. |
564580 | `/login` | Interactive OAuth login. Shows a selector with available OAuth providers and their login status (logged in / not logged in). Selecting a provider starts the browser-based OAuth flow. Uses pi-ai's OAuth registry. Credentials are persisted to the app data directory and used for provider discovery on subsequent launches. |
565581 | `/logout` | Interactive OAuth logout. Shows a selector with logged-in OAuth providers. Selecting one clears its saved credentials. |
566-| `/effort` | Interactive effort selector. Shows the four reasoning levels (`low`, `med`, `high`, `xhigh`) with the current level highlighted. Updates the status bar immediately, and the selected effort is persisted immediately as the user's global default. The session record's `effort` field is not updated (it reflects the initial choice, like `/model`). |
582+| `/effort` | Interactive effort selector. Shows the four reasoning levels (`low`, `medium`, `high`, `xhigh`) with the current level highlighted. Updates the status bar immediately, and the selected effort is persisted immediately as the user's global default. The session record's `effort` field is not updated (it reflects the initial choice, like `/model`). |
567583 | `/help` | List available commands, including the current on/off state of `/reasoning` and `/verbose`, plus loaded AGENTS.md files, discovered skills, and active plugins. |
568584
569585 Commands are discoverable when the input starts with `/`: pressing `Tab` in that state switches from file-path autocomplete to interactive command select/filter.
src/theme.test.ts+21−7
@@ -12,9 +12,9 @@ const THEME_KEYS = [
1212 "diffRemoved",
1313 "divider",
1414 "dividerPulse",
15- "statusText",
16- "statusPrimaryBg",
17- "statusSecondaryBg",
15+ "statusSecondary",
16+ "statusEffortScale",
17+ "statusContextScale",
1818 "error",
1919 "overlayBg",
2020 ] as const;
@@ -24,10 +24,24 @@ describe("theme", () => {
2424 expect(Object.keys(DEFAULT_THEME).sort()).toEqual([...THEME_KEYS].sort());
2525 });
2626
27- test("DEFAULT_THEME uses explicit ANSI16 colors for status pills", () => {
28- expect(DEFAULT_THEME.statusText).toBe("color15");
29- expect(DEFAULT_THEME.statusPrimaryBg).toBe("color04");
30- expect(DEFAULT_THEME.statusSecondaryBg).toBe("color08");
27+ test("DEFAULT_THEME uses stepped ANSI16 tones for status pills", () => {
28+ expect(DEFAULT_THEME.statusSecondary).toEqual({
29+ fg: "color15",
30+ bg: "color08",
31+ });
32+ expect(DEFAULT_THEME.statusEffortScale).toEqual([
33+ { fg: "color00", bg: "color02" },
34+ { fg: "color00", bg: "color06" },
35+ { fg: "color15", bg: "color05" },
36+ { fg: "color00", bg: "color09" },
37+ ]);
38+ expect(DEFAULT_THEME.statusContextScale).toEqual([
39+ { fg: "color00", bg: "color02" },
40+ { fg: "color00", bg: "color06" },
41+ { fg: "color15", bg: "color05" },
42+ { fg: "color15", bg: "color01" },
43+ { fg: "color00", bg: "color09" },
44+ ]);
3145 });
3246
3347 test("mergeThemes with no overrides returns base unchanged", () => {
src/theme.ts+44−13
@@ -21,6 +21,14 @@ type ThemeColor = Color | undefined;
2121 // Types
2222 // ---------------------------------------------------------------------------
2323
24+/** Foreground/background pair for a single status pill tone. */
25+export interface StatusTone {
26+ /** Pill foreground color. */
27+ fg: ThemeColor;
28+ /** Pill background color. */
29+ bg: ThemeColor;
30+}
31+
2432 /**
2533 * Complete set of UI colors.
2634 *
@@ -48,12 +56,18 @@ export interface Theme {
4856 divider: ThemeColor;
4957 /** Divider scanning pulse highlight color (active state). */
5058 dividerPulse: ThemeColor;
51- /** Status pill foreground. */
52- statusText: ThemeColor;
53- /** Primary status pill background (outer pills: model/effort + usage/context/cost). */
54- statusPrimaryBg: ThemeColor;
55- /** Secondary status pill background (inner pills: CWD + git). */
56- statusSecondaryBg: ThemeColor;
59+ /** Neutral status pill tone for the inner CWD/git pills. */
60+ statusSecondary: StatusTone;
61+ /** Model/effort pill tones from low/cold to xhigh/warm. */
62+ statusEffortScale: readonly [StatusTone, StatusTone, StatusTone, StatusTone];
63+ /** Usage/context pill tones from empty/cold to near-full/hot. */
64+ statusContextScale: readonly [
65+ StatusTone,
66+ StatusTone,
67+ StatusTone,
68+ StatusTone,
69+ StatusTone,
70+ ];
5771 /** Error text. */
5872 error: ThemeColor;
5973 /** Overlay modal background. */
@@ -68,9 +82,10 @@ export interface Theme {
6882 * The default theme.
6983 *
7084 * Uses terminal palette colors so it looks reasonable across light and
71- * dark terminal themes without any configuration. The outer status pills
72- * use a blue primary background, the inner pills use a dim gray secondary
73- * background, and bright text keeps the badges readable.
85+ * dark terminal themes without any configuration. The inner status pills
86+ * stay neutral, while the outer pills use stepped ANSI16 tone scales so
87+ * reasoning effort and context pressure move through green, cyan, purple,
88+ * and red as they trend from cold/dark to warm/bright.
7489 */
7590 export const DEFAULT_THEME: Theme = {
7691 userMsgBg: "color08",
@@ -83,9 +98,23 @@ export const DEFAULT_THEME: Theme = {
8398 diffRemoved: "color01",
8499 divider: "color08",
85100 dividerPulse: "color04",
86- statusText: "color15",
87- statusPrimaryBg: "color04",
88- statusSecondaryBg: "color08",
101+ statusSecondary: {
102+ fg: "color15",
103+ bg: "color08",
104+ },
105+ statusEffortScale: [
106+ { fg: "color00", bg: "color02" },
107+ { fg: "color00", bg: "color06" },
108+ { fg: "color15", bg: "color05" },
109+ { fg: "color00", bg: "color09" },
110+ ],
111+ statusContextScale: [
112+ { fg: "color00", bg: "color02" },
113+ { fg: "color00", bg: "color06" },
114+ { fg: "color15", bg: "color05" },
115+ { fg: "color15", bg: "color01" },
116+ { fg: "color00", bg: "color09" },
117+ ],
89118 error: "color01",
90119 overlayBg: "color08",
91120 };
@@ -98,7 +127,9 @@ export const DEFAULT_THEME: Theme = {
98127 * Merge partial theme overrides on top of a base theme.
99128 *
100129 * Applies overrides left-to-right — later overrides win for the same key.
101- * Returns a new {@link Theme}; the base is not mutated.
130+ * This is a shallow merge, so nested status tones and tone scales are
131+ * replaced as whole values. Returns a new {@link Theme}; the base is not
132+ * mutated.
102133 *
103134 * @param base - The base theme to start from.
104135 * @param overrides - Partial theme objects to merge (from plugins).
src/ui/help.test.ts+3−1
@@ -19,6 +19,8 @@ describe("ui/help", () => {
1919 expect(text).toContain(
2020 `/reasoning Toggle thinking display (currently ${DEFAULT_SHOW_REASONING ? "on" : "off"})`,
2121 );
22- expect(text).toContain("/verbose Toggle full output (currently off)");
22+ expect(text).toContain(
23+ "/verbose Toggle verbose tool rendering (currently off)",
24+ );
2325 });
2426 });
src/ui/help.ts+2−2
@@ -22,7 +22,7 @@ export interface HelpRenderState {
2222 plugins: AppState["plugins"];
2323 /** Whether reasoning blocks are shown in the log. */
2424 showReasoning: AppState["showReasoning"];
25- /** Whether full tool output is shown in the log. */
25+ /** Whether verbose tool rendering is enabled in the log. */
2626 verbose: AppState["verbose"];
2727 }
2828
@@ -35,7 +35,7 @@ export const COMMAND_DESCRIPTIONS: Record<string, string> = {
3535 fork: "Fork session",
3636 undo: "Undo last turn",
3737 reasoning: "Toggle thinking display",
38- verbose: "Toggle full output",
38+ verbose: "Toggle verbose tool rendering",
3939 login: "OAuth login",
4040 logout: "OAuth logout",
4141 help: "Show help",
src/ui/status.test.ts+151−15
@@ -1,5 +1,4 @@
11 import { describe, expect, test } from "bun:test";
2-import type { Node } from "@cel-tui/types";
32 import {
43 fauxAssistantMessage,
54 registerFauxProvider,
@@ -10,31 +9,66 @@ import { DEFAULT_SHOW_REASONING, DEFAULT_VERBOSE } from "../settings.ts";
109 import { DEFAULT_THEME } from "../theme.ts";
1110 import { renderStatusBar } from "./status.ts";
1211
13-function collectText(node: Node | null): string[] {
14- if (!node) {
15- return [];
16- }
17- if (node.type === "text") {
18- return [node.content];
19- }
20- if (node.type === "textinput") {
21- return [];
12+interface RenderedStatusPill {
13+ text: string;
14+ bgColor: string | undefined;
15+ fgColor: string | undefined;
16+}
17+
18+function renderStatusPills(
19+ state: AppState,
20+ cols?: number,
21+): RenderedStatusPill[] {
22+ const bar = renderStatusBar(state, cols);
23+ if (bar.type !== "hstack") {
24+ throw new Error("Expected the status bar root to be an hstack");
2225 }
23- return node.children.flatMap((child) => collectText(child));
26+
27+ return bar.children.flatMap((child) => {
28+ if (child.type !== "hstack") {
29+ return [];
30+ }
31+ const [textNode] = child.children;
32+ if (!textNode || textNode.type !== "text") {
33+ return [];
34+ }
35+ return [
36+ {
37+ text: textNode.content,
38+ bgColor: child.props.bgColor,
39+ fgColor: textNode.props.fgColor,
40+ },
41+ ];
42+ });
2443 }
2544
2645 function renderStatusText(state: AppState, cols?: number): string[] {
27- return collectText(renderStatusBar(state, cols)).filter(Boolean);
46+ return renderStatusPills(state, cols)
47+ .map((pill) => pill.text)
48+ .filter(Boolean);
2849 }
2950
30-function getUsageSummary(state: AppState): string {
31- const usage = renderStatusText(state).at(-1);
51+function getModelPill(state: AppState): RenderedStatusPill {
52+ const [modelPill] = renderStatusPills(state);
53+ if (!modelPill) {
54+ throw new Error("Expected a model pill");
55+ }
56+ return modelPill;
57+}
58+
59+function getUsagePill(state: AppState): RenderedStatusPill {
60+ const pills = renderStatusPills(state);
61+ const usage = pills.at(-1);
3262 if (!usage) {
33- throw new Error("Expected a usage summary");
63+ throw new Error("Expected a usage pill");
3464 }
3565 return usage;
3666 }
3767
68+function getUsageSummary(state: AppState): string {
69+ return getUsagePill(state).text;
70+}
71+
3872 function getUsagePercent(state: AppState): number {
3973 const match = /· ([\d.]+)%\//.exec(getUsageSummary(state));
4074 if (!match) {
@@ -134,6 +168,108 @@ describe("ui/status", () => {
134168 }
135169 });
136170
171+ test("renderStatusBar maps reasoning effort levels to the model pill tone scale", () => {
172+ const faux = registerFauxProvider();
173+ const state = createTestState();
174+ state.model = faux.getModel();
175+
176+ try {
177+ const cases = [
178+ { effort: "low", bgColor: "color02", fgColor: "color00" },
179+ { effort: "medium", bgColor: "color06", fgColor: "color00" },
180+ { effort: "high", bgColor: "color05", fgColor: "color15" },
181+ { effort: "xhigh", bgColor: "color09", fgColor: "color00" },
182+ ] as const;
183+
184+ for (const testCase of cases) {
185+ state.effort = testCase.effort;
186+ expect(getModelPill(state)).toMatchObject({
187+ text: `${state.model.provider}/${state.model.id} · ${testCase.effort === "medium" ? "med" : testCase.effort}`,
188+ bgColor: testCase.bgColor,
189+ fgColor: testCase.fgColor,
190+ });
191+ }
192+ } finally {
193+ faux.unregister();
194+ state.db.close();
195+ }
196+ });
197+
198+ test("renderStatusBar maps context usage bands to the usage pill tone scale", () => {
199+ const faux = registerFauxProvider();
200+ const state = createTestState();
201+ state.model = {
202+ ...faux.getModel(),
203+ contextWindow: 100,
204+ };
205+
206+ try {
207+ const cases = [
208+ { totalTokens: 10, bgColor: "color02", fgColor: "color00" },
209+ { totalTokens: 30, bgColor: "color06", fgColor: "color00" },
210+ { totalTokens: 60, bgColor: "color05", fgColor: "color15" },
211+ { totalTokens: 80, bgColor: "color01", fgColor: "color15" },
212+ { totalTokens: 95, bgColor: "color09", fgColor: "color00" },
213+ ] as const;
214+
215+ for (const testCase of cases) {
216+ state.messages = [
217+ makeAssistantWithUsage("context anchor", {
218+ totalTokens: testCase.totalTokens,
219+ }),
220+ ];
221+ expect(getUsagePill(state)).toMatchObject({
222+ text: `in:0 out:0 · ${testCase.totalTokens.toFixed(1)}%/100 · $0.00`,
223+ bgColor: testCase.bgColor,
224+ fgColor: testCase.fgColor,
225+ });
226+ }
227+ } finally {
228+ faux.unregister();
229+ state.db.close();
230+ }
231+ });
232+
233+ test("renderStatusBar colors the model and usage pills independently", () => {
234+ const faux = registerFauxProvider();
235+ const state = createTestState();
236+ state.model = {
237+ ...faux.getModel(),
238+ contextWindow: 100,
239+ };
240+
241+ try {
242+ state.effort = "xhigh";
243+ state.messages = [
244+ makeAssistantWithUsage("cold context", { totalTokens: 10 }),
245+ ];
246+ expect(getModelPill(state)).toMatchObject({
247+ bgColor: "color09",
248+ fgColor: "color00",
249+ });
250+ expect(getUsagePill(state)).toMatchObject({
251+ bgColor: "color02",
252+ fgColor: "color00",
253+ });
254+
255+ state.effort = "low";
256+ state.messages = [
257+ makeAssistantWithUsage("hot context", { totalTokens: 95 }),
258+ ];
259+ expect(getModelPill(state)).toMatchObject({
260+ bgColor: "color02",
261+ fgColor: "color00",
262+ });
263+ expect(getUsagePill(state)).toMatchObject({
264+ bgColor: "color09",
265+ fgColor: "color00",
266+ });
267+ } finally {
268+ faux.unregister();
269+ state.db.close();
270+ }
271+ });
272+
137273 test("renderStatusBar uses the latest valid assistant usage as an anchor and ignores trailing UI-only messages", () => {
138274 const faux = registerFauxProvider();
139275 const state = createTestState();
src/ui/status.ts+55−23
@@ -15,7 +15,7 @@ import type { Node } from "@cel-tui/types";
1515 import type { AssistantMessage, Message } from "@mariozechner/pi-ai";
1616 import type { AppState } from "../index.ts";
1717 import { filterModelMessages, getAssistantUsage } from "../session.ts";
18-import type { Theme } from "../theme.ts";
18+import type { StatusTone, Theme } from "../theme.ts";
1919
2020 /** Conservative fixed estimate for an image block's token footprint. */
2121 const ESTIMATED_IMAGE_TOKENS = 1_200;
@@ -214,28 +214,59 @@ function estimateCurrentContextTokens(state: AppState): number {
214214 return total;
215215 }
216216
217+/** Estimate current context usage as a percentage of the active model window. */
218+function getContextPercentage(state: AppState): number {
219+ if (!state.model || state.model.contextWindow <= 0) {
220+ return 0;
221+ }
222+ const contextTokens = estimateCurrentContextTokens(state);
223+ return (contextTokens / state.model.contextWindow) * 100;
224+}
225+
217226 /** Format cumulative session totals plus estimated current context usage for the status bar. */
218-function formatUsage(state: AppState): string {
227+function formatUsage(state: AppState, contextPct: number): string {
219228 if (!state.model) return "";
220229 const input = formatTokens(state.stats.totalInput);
221230 const output = formatTokens(state.stats.totalOutput);
222- const contextTokens = estimateCurrentContextTokens(state);
223- const contextPct =
224- state.model.contextWindow > 0
225- ? (contextTokens / state.model.contextWindow) * 100
226- : 0;
227231 const contextWindow = formatTokenCapacity(state.model.contextWindow);
228232 return `in:${input} out:${output} · ${contextPct.toFixed(1)}%/${contextWindow} · ${formatCost(state.stats.totalCost)}`;
229233 }
230234
235+/** Select the model/effort pill tone for the current reasoning effort. */
236+function getEffortTone(theme: Theme, effort: string): StatusTone {
237+ switch (effort) {
238+ case "xhigh":
239+ return theme.statusEffortScale[3];
240+ case "high":
241+ return theme.statusEffortScale[2];
242+ case "medium":
243+ return theme.statusEffortScale[1];
244+ default:
245+ return theme.statusEffortScale[0];
246+ }
247+}
248+
249+/** Select the usage/context pill tone for the current context pressure. */
250+function getContextTone(theme: Theme, contextPct: number): StatusTone {
251+ if (contextPct >= 90) {
252+ return theme.statusContextScale[4];
253+ }
254+ if (contextPct >= 75) {
255+ return theme.statusContextScale[3];
256+ }
257+ if (contextPct >= 50) {
258+ return theme.statusContextScale[2];
259+ }
260+ if (contextPct >= 25) {
261+ return theme.statusContextScale[1];
262+ }
263+ return theme.statusContextScale[0];
264+}
265+
231266 /** Render a single compact status pill. */
232-function renderStatusPill(
233- text: string,
234- bgColor: Theme["statusPrimaryBg"] | Theme["statusSecondaryBg"],
235- theme: Theme,
236-): Node {
237- return HStack({ bgColor, padding: { x: 1 } }, [
238- Text(text, { fgColor: theme.statusText }),
267+function renderStatusPill(text: string, tone: StatusTone): Node {
268+ return HStack({ bgColor: tone.bg, padding: { x: 1 } }, [
269+ Text(text, { fgColor: tone.fg }),
239270 ]);
240271 }
241272
@@ -276,8 +307,9 @@ function leftTruncate(text: string, maxWidth: number): string {
276307 /**
277308 * Render the one-line status bar as compact padded pills.
278309 *
279- * Outer pills use the primary background and inner pills use the secondary
280- * background. The git pill is omitted outside repositories.
310+ * The inner pills use the neutral secondary tone. The model pill uses a
311+ * reasoning-effort tone scale, and the usage pill uses an independent
312+ * context-pressure tone scale. The git pill is omitted outside repositories.
281313 *
282314 * @param state - Application state.
283315 * @param cols - Current terminal width in columns.
@@ -290,7 +322,8 @@ export function renderStatusBar(
290322 const fullCwd = abbreviatePath(state.cwd);
291323 const gitStatus = formatGitStatus(state);
292324 const modelInfo = formatModelInfo(state);
293- const usage = formatUsage(state);
325+ const contextPct = getContextPercentage(state);
326+ const usage = formatUsage(state, contextPct);
294327 const reservedWidth =
295328 2 +
296329 measureStatusPill(modelInfo) +
@@ -301,18 +334,17 @@ export function renderStatusBar(
301334 ? leftTruncate(fullCwd, Math.max(Math.floor(cols) - reservedWidth, 1))
302335 : fullCwd;
303336
337+ const secondaryTone = state.theme.statusSecondary;
304338 const children: Node[] = [
305- renderStatusPill(modelInfo, state.theme.statusPrimaryBg, state.theme),
306- renderStatusPill(cwd, state.theme.statusSecondaryBg, state.theme),
339+ renderStatusPill(modelInfo, getEffortTone(state.theme, state.effort)),
340+ renderStatusPill(cwd, secondaryTone),
307341 Spacer(),
308342 ];
309343 if (gitStatus) {
310- children.push(
311- renderStatusPill(gitStatus, state.theme.statusSecondaryBg, state.theme),
312- );
344+ children.push(renderStatusPill(gitStatus, secondaryTone));
313345 }
314346 children.push(
315- renderStatusPill(usage, state.theme.statusPrimaryBg, state.theme),
347+ renderStatusPill(usage, getContextTone(state.theme, contextPct)),
316348 );
317349
318350 return HStack(