xonecas.io
64875
Mc

mini-coder / commit a382e5f

feat: add terminal title updates and cleanup guidance

xonecas2026-04-16 a382e5f045d1ab3d1200776e91cd1dd44ad3f9dd parent 434a7cb

8 files changed

TODO.md+0−1
@@ -33,6 +33,5 @@ The spec.md and code are the sources of truth, not this file, don't assume anyth
3333
3434 ## Future ideas
3535
36-- [ ] Terminal title should show activity/session info and stay in sync with the divider animation
3736 - [ ] Divider theme plugin — customizable divider animations (scanning pulse, breathing, flowing dots, wave)
3837 - [ ] Backward-compatibility and migration policy for 1.0 (session/app data versioning, explicit migration strategy)
spec.md+5−1
@@ -61,13 +61,14 @@ Four built-in tools, plus a read-only image tool. Plugins may add more (see [Plu
6161
6262 ### `shell`
6363
64-Runs a command in the user's shell. Returns stdout, stderr, and exit code. Use it to explore the codebase, read tests/verifiers/examples, inspect required outputs, and run targeted checks, builds, or git commands.
64+Runs a command in the user's shell. Returns stdout, stderr, and exit code. Use it to explore the codebase, read tests/verifiers/examples, inspect required outputs, and run targeted checks, builds, or git commands. Commands mutate the real working directory, so verification outputs should go to temporary paths or be cleaned up before finishing.
6565
6666 Implementation details:
6767
6868 - Large outputs are truncated as a safety guard against context explosion from bad or overly broad commands (for example, accidentally reading a huge file, binary, or unbounded command output). This guard applies to both very tall output (many lines) and very wide output (a few extremely long lines), and is not related to the user-configured verbose setting.
6969 - The truncation threshold is configurable, tuned to keep useful output while staying well within context limits. This tool-level truncation is intentionally narrow in scope: it protects the model context from pathological output, not as a general-purpose presentation layer for every output-shaping concern.
7070 - Commands run via `$SHELL -c "<command>"` (falling back to `/bin/sh` if `$SHELL` is unset) with the CWD set to the session's working directory.
71+- Verification commands that produce build artifacts should prefer temporary output paths or clean up generated files before the agent finishes.
7172 - Before execution, the harness may apply a small set of silent, lossless compatibility normalizations for common model-authored shell mistakes when the intended command is unambiguous (for example, moving a heredoc trailer's `|`, `&&`, or `>` continuation back onto the heredoc start line, or rewriting `printf '--- ...'` to `printf -- '--- ...'` when the format string begins with `-`).
7273 - Compatibility normalization is best-effort and intentionally narrow. If a rewrite is ambiguous or the normalization step itself fails, the raw command is executed unchanged.
7374 - Timeout: no default timeout. The user can interrupt via `Escape`.
@@ -331,6 +332,7 @@ The current environment is:
331332 - Check requirements, and plan your changes before editting code.
332333 - Implement the necessary changes, following good practices and propper error handling.
333334 - Always verify your changes using compilation, testing, and manual verification when possible.
335+- When verifying with build or test commands, avoid leaving generated binaries or scratch artifacts in the requested output location; use temporary paths or remove them before finishing.
334336 - Do not leave helpers, test, or any other form of temporary files, cleanup after yourself and leave no trace.
335337
336338 ### Task management
@@ -695,6 +697,8 @@ Representative entry shapes:
695697
696698 While the agent is working, the top divider (above the input area) animates with a scanning pulse — a bright and colored (be creative) segment sweeping across the dimmed divider line. The animation starts when a turn begins and stops when the turn ends (done, error, or aborted). No per-activity state tracking.
697699
700+mini-coder also updates the terminal title. While idle, the title is `mc` when there is no conversational text yet; otherwise it is `mc - <tail preview>`, where `<tail preview>` is the last five words of the most recent non-UI user or assistant text message, with whitespace collapsed to a single line and `...` prefixed when the preview was truncated. While a turn is active, the title switches to a stable-width glow-scanner animation (for example `mc - [=o---]`, `mc - [-=o--]`, `mc - [--=o-]`) so …
701+
698702 #### Divider sketches
699703
700704 ```text
src/prompt.test.ts+3−0
@@ -361,6 +361,9 @@ describe("buildSystemPrompt", () => {
361361 expect(prompt).toContain(
362362 "Use `todoRead` when you need to inspect the current list before updating it",
363363 );
364+ expect(prompt).toContain(
365+ "When verifying with build or test commands, avoid leaving generated binaries or scratch artifacts in the requested output location; use temporary paths or remove them before finishing.",
366+ );
364367 });
365368
366369 test("appends AGENTS.md content, skills, and plugin suffixes after the core prompt in order", () => {
src/prompt.ts+1−0
@@ -246,6 +246,7 @@ function buildCorePrompt(opts: BuildSystemPromptOpts): string {
246246 "- Check requirements, and plan your changes before editing code.",
247247 "- Implement the necessary changes, following good practices and proper error handling.",
248248 "- Always verify your changes using compilation, testing, and manual verification when possible.",
249+ "- When verifying with build or test commands, avoid leaving generated binaries or scratch artifacts in the requested output location; use temporary paths or remove them before finishing.",
249250 "- Do not leave helpers, tests, or any other form of temporary files; clean up after yourself and leave no trace.",
250251 "- Ensure you match the requested output exactly. This applies to file names, directory structure, number of files, output formats, and all other details.",
251252 '- "Polish" is not optional; it counts just as much as solving the task.',
src/tools.test.ts+3−0
@@ -888,6 +888,9 @@ describe("tool definitions", () => {
888888 expect(shellTool.description).toContain("read tests/verifiers/examples");
889889 expect(shellTool.description).toContain("inspect required outputs");
890890 expect(shellTool.description).toContain("targeted checks");
891+ expect(shellTool.description).toContain(
892+ "direct verification outputs to temporary paths or clean them up before finishing",
893+ );
891894 });
892895
893896 test("edit description emphasizes exact required file content", () => {
src/tools.ts+2−1
@@ -1574,7 +1574,8 @@ export const shellTool: Tool = {
15741574 name: "shell",
15751575 description:
15761576 "Run a command in the user's shell. Returns stdout, stderr, and exit code. " +
1577- "Use this to explore the codebase, read tests/verifiers/examples, inspect required outputs, and run targeted checks, builds, or git commands.",
1577+ "Use this to explore the codebase, read tests/verifiers/examples, inspect required outputs, and run targeted checks, builds, or git commands. " +
1578+ "Commands mutate the real working directory, so direct verification outputs to temporary paths or clean them up before finishing.",
15781579 parameters: Type.Object({
15791580 command: Type.String({ description: "The shell command to execute" }),
15801581 }),
src/ui.test.ts+251−0
@@ -39,6 +39,7 @@ import {
3939 } from "./ui/conversation.ts";
4040 import {
4141 buildConversationLog,
42+ buildTerminalTitle,
4243 createInputController,
4344 handleInput,
4445 type InputController,
@@ -157,6 +158,32 @@ function createDeferred<T = void>() {
157158 return { promise, resolve, reject };
158159 }
159160
161+// biome-ignore lint/complexity/useRegexLiterals: using RegExp here avoids control-character regex diagnostics.
162+const TITLE_SEQUENCE_RE = new RegExp(
163+ String.raw`\x1b\][02];([^\x07\x1b]*)(?:\x07|\x1b\\)`,
164+ "g",
165+);
166+
167+function extractTitlePayloads(output: string): string[] {
168+ return Array.from(output.matchAll(TITLE_SEQUENCE_RE), (match) => {
169+ const payload = match[1];
170+ if (payload === undefined) {
171+ throw new Error("Missing terminal title payload");
172+ }
173+ return payload;
174+ });
175+}
176+
177+const ACTIVE_TITLE_FRAMES = [
178+ "mc - [=o---]",
179+ "mc - [-=o--]",
180+ "mc - [--=o-]",
181+ "mc - [---=o]",
182+ "mc - [--o=-]",
183+ "mc - [-o=--]",
184+ "mc - [o=---]",
185+] as const;
186+
160187 async function waitForCelRender(): Promise<void> {
161188 await new Promise((resolve) => setTimeout(resolve, 10));
162189 }
@@ -365,6 +392,178 @@ describe("ui rendering", () => {
365392 expect(unrefCalled).toBe(true);
366393 });
367394
395+ test("buildTerminalTitle falls back to mc when idle and no conversational text exists", () => {
396+ const state = createTestState();
397+
398+ try {
399+ state.messages = [createUiMessage("Status only")];
400+
401+ expect(buildTerminalTitle(state)).toBe("mc");
402+ } finally {
403+ state.db.close();
404+ }
405+ });
406+
407+ test("buildTerminalTitle ignores UI and tool results and uses the latest conversational text tail", () => {
408+ const state = createTestState();
409+
410+ try {
411+ state.messages = [
412+ createUiMessage("Ignored status"),
413+ {
414+ role: "user",
415+ content: "alpha\nbeta gamma delta epsilon zeta",
416+ timestamp: 1,
417+ },
418+ {
419+ role: "toolResult",
420+ toolCallId: "tool-1",
421+ toolName: "shell",
422+ isError: false,
423+ content: [{ type: "text", text: "tool output should be ignored" }],
424+ timestamp: 2,
425+ },
426+ ];
427+
428+ expect(buildTerminalTitle(state)).toBe(
429+ "mc - ...beta gamma delta epsilon zeta",
430+ );
431+ } finally {
432+ state.db.close();
433+ }
434+ });
435+
436+ test("buildTerminalTitle shows a stable-width glow scanner while a turn is running", () => {
437+ const state = createTestState();
438+ state.running = true;
439+
440+ try {
441+ expect(buildTerminalTitle(state, 0)).toBe(ACTIVE_TITLE_FRAMES[0]);
442+ expect(buildTerminalTitle(state, 4)).toBe(ACTIVE_TITLE_FRAMES[1]);
443+ expect(buildTerminalTitle(state, 8)).toBe(ACTIVE_TITLE_FRAMES[2]);
444+ expect(buildTerminalTitle(state, 12)).toBe(ACTIVE_TITLE_FRAMES[3]);
445+ expect(buildTerminalTitle(state, 16)).toBe(ACTIVE_TITLE_FRAMES[4]);
446+ expect(buildTerminalTitle(state, 20)).toBe(ACTIVE_TITLE_FRAMES[5]);
447+ expect(buildTerminalTitle(state, 24)).toBe(ACTIVE_TITLE_FRAMES[6]);
448+ expect(buildTerminalTitle(state, 28)).toBe(ACTIVE_TITLE_FRAMES[0]);
449+ } finally {
450+ state.db.close();
451+ }
452+ });
453+
454+ test("terminal title animates during a turn and restores the latest assistant tail when done", async () => {
455+ const api = "ui-terminal-title-test";
456+ const sourceId = "ui-terminal-title-test-source";
457+ const model: Model<string> = {
458+ id: "ui-terminal-title-model",
459+ name: "UI Terminal Title Model",
460+ api,
461+ provider: "test",
462+ baseUrl: "http://localhost:0",
463+ reasoning: false,
464+ input: ["text"],
465+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
466+ contextWindow: 128000,
467+ maxTokens: 4096,
468+ };
469+ const finishStream = createDeferred<void>();
470+
471+ const buildProviderStream = () => {
472+ const stream = createAssistantMessageEventStream();
473+ const partial: AssistantMessage = {
474+ role: "assistant",
475+ content: [fauxText("one two three four five six")],
476+ api,
477+ provider: model.provider,
478+ model: model.id,
479+ usage: {
480+ input: 0,
481+ output: 0,
482+ cacheRead: 0,
483+ cacheWrite: 0,
484+ totalTokens: 0,
485+ cost: {
486+ input: 0,
487+ output: 0,
488+ cacheRead: 0,
489+ cacheWrite: 0,
490+ total: 0,
491+ },
492+ },
493+ stopReason: "stop",
494+ timestamp: Date.now(),
495+ };
496+ const finalMessage: AssistantMessage = { ...partial };
497+
498+ queueMicrotask(() => {
499+ stream.push({
500+ type: "text_delta",
501+ contentIndex: 0,
502+ delta: "one two three four five six",
503+ partial,
504+ });
505+ void finishStream.promise.then(() => {
506+ stream.push({
507+ type: "done",
508+ reason: "stop",
509+ message: finalMessage,
510+ });
511+ stream.end(finalMessage);
512+ });
513+ });
514+
515+ return stream;
516+ };
517+
518+ registerApiProvider(
519+ {
520+ api,
521+ stream: (_model, _context, _options) => buildProviderStream(),
522+ streamSimple: (_model, _context, _options) => buildProviderStream(),
523+ },
524+ sourceId,
525+ );
526+
527+ const state = createTestState();
528+ const terminal = new MockTerminal(80, 20);
529+ state.cwd = process.cwd();
530+ state.canonicalCwd = process.cwd();
531+ state.model = model;
532+
533+ try {
534+ const controller = createInputController(state);
535+ startUiViewport(state, terminal, controller);
536+ await waitForCelRender();
537+ terminal.clearOutput();
538+
539+ handleInput("show me the title", state);
540+
541+ await waitFor(() => {
542+ const titles = extractTitlePayloads(terminal.output);
543+ return (
544+ state.running &&
545+ titles.some((title) =>
546+ ACTIVE_TITLE_FRAMES.some((frame) => frame === title),
547+ )
548+ );
549+ });
550+
551+ finishStream.resolve();
552+
553+ await waitFor(
554+ () =>
555+ extractTitlePayloads(terminal.output).at(-1) ===
556+ "mc - ...two three four five six",
557+ );
558+ } finally {
559+ finishStream.resolve();
560+ await stopRunningTurn(state);
561+ cel.stop();
562+ unregisterApiProviders(sourceId);
563+ state.db.close();
564+ }
565+ });
566+
368567 test("committing a streamed response preserves hidden reasoning placeholder order", async () => {
369568 const api = "ui-hidden-reasoning-order-test";
370569 const sourceId = "ui-hidden-reasoning-order-test-source";
@@ -2403,4 +2602,56 @@ describe("ui rendering", () => {
24032602 resumeHandler();
24042603 expect(calls).toEqual(["stop", "onResume", "suspend", "resume"]);
24052604 });
2605+
2606+ test("suspendToBackground invalidates the title cache so the title is re-sent after resume", async () => {
2607+ const state = createTestState();
2608+ const terminal = new MockTerminal(80, 20);
2609+ let resumeHandler = (): void => {
2610+ throw new Error(
2611+ "Expected suspendToBackground to register a resume handler",
2612+ );
2613+ };
2614+ state.messages = [
2615+ {
2616+ role: "user",
2617+ content: "resume keeps the mini coder title",
2618+ timestamp: 1,
2619+ },
2620+ ];
2621+
2622+ try {
2623+ const controller = createInputController(state);
2624+ startUiViewport(state, terminal, controller);
2625+ await waitForCelRender();
2626+
2627+ expect(extractTitlePayloads(terminal.output)).toContain(
2628+ "mc - ...keeps the mini coder title",
2629+ );
2630+
2631+ terminal.clearOutput();
2632+
2633+ suspendToBackground(
2634+ () => {
2635+ controller.onBlur();
2636+ },
2637+ {
2638+ stop: () => {},
2639+ onResume: (handler: () => void) => {
2640+ resumeHandler = handler;
2641+ },
2642+ suspend: () => {},
2643+ },
2644+ );
2645+
2646+ resumeHandler();
2647+ await waitForCelRender();
2648+
2649+ expect(extractTitlePayloads(terminal.output)).toContain(
2650+ "mc - ...keeps the mini coder title",
2651+ );
2652+ } finally {
2653+ cel.stop();
2654+ state.db.close();
2655+ }
2656+ });
24062657 });
src/ui.ts+194−18
@@ -64,6 +64,23 @@ const DIVIDER_FRAME_MS = 60;
6464 /** Width of the bright pulse segment in the animated divider. */
6565 const PULSE_WIDTH = 5;
6666
67+/** Number of trailing words shown in the idle terminal-title preview. */
68+const TERMINAL_TITLE_WORD_COUNT = 5;
69+
70+/** Divider ticks spent on each animated terminal-title scanner frame. */
71+const TERMINAL_TITLE_TICKS_PER_FRAME = 4;
72+
73+/** Frames used for the active terminal-title glow-scanner animation. */
74+const TERMINAL_TITLE_FRAMES = [
75+ "[=o---]",
76+ "[-=o--]",
77+ "[--=o-]",
78+ "[---=o]",
79+ "[--o=-]",
80+ "[-o=--]",
81+ "[o=---]",
82+] as const;
83+
6784 /** Maximum number of committed messages rendered before older history is chunked. */
6885 const CONVERSATION_CHUNK_MESSAGES = 50;
6986
@@ -109,6 +126,15 @@ let dividerTimer: ReturnType<typeof setInterval> | null = null;
109126 /** Whether stdin was already in raw mode before the TUI initialized. */
110127 let stdinWasRaw = false;
111128
129+/** Latest application state associated with the active terminal UI. */
130+let titleState: AppState | null = null;
131+
132+/** Whether a cel viewport has rendered for the current UI session. */
133+let titleViewportActive = false;
134+
135+/** Last terminal title written during the current UI session. */
136+let lastTerminalTitle: string | null = null;
137+
112138 // ---------------------------------------------------------------------------
113139 // Overlay state
114140 // ---------------------------------------------------------------------------
@@ -150,6 +176,148 @@ export function resetUiState(): void {
150176 resetConversationRenderCache();
151177 activeOverlay = null;
152178 stdinWasRaw = false;
179+ titleState = null;
180+ titleViewportActive = false;
181+ lastTerminalTitle = null;
182+}
183+
184+// ---------------------------------------------------------------------------
185+// Terminal title
186+// ---------------------------------------------------------------------------
187+
188+function collapseTerminalTitleText(text: string): string | null {
189+ const collapsed = text.replace(/\s+/g, " ").trim();
190+ return collapsed.length > 0 ? collapsed : null;
191+}
192+
193+function getUserTerminalTitleText(
194+ content: Extract<AppState["messages"][number], { role: "user" }>["content"],
195+): string | null {
196+ if (typeof content === "string") {
197+ return collapseTerminalTitleText(content);
198+ }
199+
200+ const text = content
201+ .filter(
202+ (block): block is Extract<(typeof content)[number], { type: "text" }> => {
203+ return block.type === "text";
204+ },
205+ )
206+ .map((block) => block.text)
207+ .join(" ");
208+
209+ return collapseTerminalTitleText(text);
210+}
211+
212+function getAssistantTerminalTitleText(
213+ content: Extract<
214+ AppState["messages"][number],
215+ { role: "assistant" }
216+ >["content"],
217+): string | null {
218+ const text = content
219+ .filter(
220+ (
221+ block,
222+ ): block is Extract<
223+ Extract<
224+ AppState["messages"][number],
225+ { role: "assistant" }
226+ >["content"][number],
227+ { type: "text" }
228+ > => {
229+ return block.type === "text";
230+ },
231+ )
232+ .map((block) => block.text)
233+ .join(" ");
234+
235+ return collapseTerminalTitleText(text);
236+}
237+
238+function truncateTerminalTitleTail(text: string): string {
239+ const words = text.split(" ");
240+ if (words.length <= TERMINAL_TITLE_WORD_COUNT) {
241+ return text;
242+ }
243+ return `...${words.slice(-TERMINAL_TITLE_WORD_COUNT).join(" ")}`;
244+}
245+
246+function buildIdleTerminalTitle(state: Pick<AppState, "messages">): string {
247+ for (let index = state.messages.length - 1; index >= 0; index -= 1) {
248+ const message = state.messages[index];
249+ if (!message) {
250+ continue;
251+ }
252+
253+ let text: string | null = null;
254+ switch (message.role) {
255+ case "user":
256+ text = getUserTerminalTitleText(message.content);
257+ break;
258+ case "assistant":
259+ text = getAssistantTerminalTitleText(message.content);
260+ break;
261+ case "toolResult":
262+ case "ui":
263+ break;
264+ }
265+
266+ if (text) {
267+ return `mc - ${truncateTerminalTitleTail(text)}`;
268+ }
269+ }
270+
271+ return "mc";
272+}
273+
274+/**
275+ * Build the current terminal title from UI state.
276+ *
277+ * Idle titles show a short tail preview from the latest conversational text
278+ * message. Active turns show a stable-width glow scanner.
279+ *
280+ * @param state - Application state needed to derive the title.
281+ * @param animationTick - Divider animation tick used to pick the scanner frame.
282+ * @returns The terminal title text to write via cel-tui.
283+ */
284+export function buildTerminalTitle(
285+ state: Pick<AppState, "messages" | "running">,
286+ animationTick = dividerTick,
287+): string {
288+ if (!state.running) {
289+ return buildIdleTerminalTitle(state);
290+ }
291+
292+ const frameIndex =
293+ Math.floor(animationTick / TERMINAL_TITLE_TICKS_PER_FRAME) %
294+ TERMINAL_TITLE_FRAMES.length;
295+ return `mc - ${TERMINAL_TITLE_FRAMES[frameIndex]}`;
296+}
297+
298+function syncTerminalTitle(
299+ state: Pick<AppState, "messages" | "running"> | null,
300+): void {
301+ if (!state || !titleViewportActive) {
302+ return;
303+ }
304+
305+ const title = buildTerminalTitle(state);
306+ if (title === lastTerminalTitle) {
307+ return;
308+ }
309+
310+ cel.setTitle(title);
311+ lastTerminalTitle = title;
312+}
313+
314+function invalidateTerminalTitleCache(): void {
315+ lastTerminalTitle = null;
316+}
317+
318+function requestRender(): void {
319+ syncTerminalTitle(titleState);
320+ cel.render();
153321 }
154322
155323 // ---------------------------------------------------------------------------
@@ -162,7 +330,7 @@ function startDividerAnimation(): void {
162330 dividerTick = 0;
163331 dividerTimer = setInterval(() => {
164332 dividerTick++;
165- cel.render();
333+ requestRender();
166334 }, DIVIDER_FRAME_MS);
167335 }
168336
@@ -286,14 +454,14 @@ function prependConversationChunk(state: AppState, width: number): void {
286454 function openOverlay(overlay: ActiveOverlay): void {
287455 activeOverlay = overlay;
288456 inputFocused = false;
289- cel.render();
457+ requestRender();
290458 }
291459
292460 /** Dismiss the active overlay and return focus to the input. */
293461 function dismissOverlay(): void {
294462 activeOverlay = null;
295463 inputFocused = true;
296- cel.render();
464+ requestRender();
297465 }
298466
299467 function openPathAutocompleteOverlay(state: AppState): void {
@@ -331,7 +499,7 @@ function handleTabKeyPress(state: AppState): void {
331499 const completedInput = autocompleteInputPath(inputValue, state.cwd);
332500 if (completedInput) {
333501 inputValue = completedInput;
334- cel.render();
502+ requestRender();
335503 return;
336504 }
337505
@@ -366,18 +534,20 @@ export function renderActiveOverlay(state: AppState): Node | null {
366534 * @returns Stable callbacks for the controlled TextInput.
367535 */
368536 export function createInputController(state: AppState): InputController {
537+ titleState = state;
538+
369539 return {
370540 onChange: (value) => {
371541 inputValue = value;
372- cel.render();
542+ requestRender();
373543 },
374544 onFocus: () => {
375545 inputFocused = true;
376- cel.render();
546+ requestRender();
377547 },
378548 onBlur: () => {
379549 inputFocused = false;
380- cel.render();
550+ requestRender();
381551 },
382552 onKeyPress: (key) => {
383553 if (key === "enter") {
@@ -385,13 +555,13 @@ export function createInputController(state: AppState): InputController {
385555
386556 if (isQuitInput(raw)) {
387557 inputValue = "";
388- cel.render();
558+ requestRender();
389559 requestGracefulExit(state);
390560 return false;
391561 }
392562
393563 inputValue = "";
394- cel.render();
564+ requestRender();
395565 handleInput(raw, state);
396566 return false;
397567 }
@@ -479,7 +649,7 @@ function appendUiMessage(
479649 }
480650 state.messages.push(message);
481651 scrollConversationToBottom();
482- cel.render();
652+ requestRender();
483653 }
484654
485655 /**
@@ -521,9 +691,7 @@ const commandController = createCommandController({
521691 appendInfoMessage,
522692 appendTodoMessage,
523693 scrollConversationToBottom,
524- render: () => {
525- cel.render();
526- },
694+ render: requestRender,
527695 reloadPromptContext,
528696 openInBrowser,
529697 });
@@ -537,9 +705,7 @@ const agentController = createUiAgentController({
537705 appendInfoMessage,
538706 handleCommand: (command, state) =>
539707 commandController.handleCommand(command, state),
540- render: () => {
541- cel.render();
542- },
708+ render: requestRender,
543709 scrollConversationToBottom,
544710 startDividerAnimation,
545711 stopDividerAnimation,
@@ -547,6 +713,7 @@ const agentController = createUiAgentController({
547713
548714 /** Route raw user input through parseInput and dispatch accordingly. */
549715 export function handleInput(raw: string, state: AppState): void {
716+ titleState = state;
550717 agentController.handleInput(raw, state);
551718 }
552719
@@ -618,6 +785,7 @@ export function suspendToBackground(
618785 stop();
619786 onResume(() => {
620787 clearInterval(keepAlive);
788+ invalidateTerminalTitleCache();
621789 resumeUi();
622790 });
623791
@@ -657,7 +825,7 @@ function renderConversationLog(state: AppState, width: number): Node {
657825 prependConversationChunk(state, width);
658826 }
659827
660- cel.render();
828+ requestRender();
661829 },
662830 },
663831 buildConversationLog(state, width),
@@ -681,6 +849,12 @@ export function renderBaseLayout(
681849 inputController: InputController,
682850 onSuspend?: () => void,
683851 ): Node {
852+ titleState = state;
853+ titleViewportActive = true;
854+ if (lastTerminalTitle === null) {
855+ syncTerminalTitle(state);
856+ }
857+
684858 return VStack(
685859 {
686860 height: "100%",
@@ -736,6 +910,7 @@ export function renderBaseLayout(
736910 export function startUI(state: AppState): void {
737911 resetUiState();
738912 stdinWasRaw = process.stdin.isRaw || false;
913+ titleState = state;
739914 const terminal = new ProcessTerminal();
740915 const inputController = createInputController(state);
741916 cel.init(terminal);
@@ -749,7 +924,7 @@ export function startUI(state: AppState): void {
749924 if (state.running) {
750925 startDividerAnimation();
751926 }
752- cel.render();
927+ requestRender();
753928 });
754929 });
755930 const overlay = renderActiveOverlay(state);
@@ -759,6 +934,7 @@ export function startUI(state: AppState): void {
759934 }
760935 return base;
761936 });
937+ syncTerminalTitle(state);
762938
763939 if (state.running) {
764940 startDividerAnimation();