diff --git a/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.i18n.yaml b/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.i18n.yaml index 810f8863e5..8d6c7be831 100644 --- a/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.i18n.yaml @@ -2,5 +2,5 @@ # side as of the last confirmed-consistent state. Both languages carry equal authority; # after editing either side, bring the other along and re-record with: # pnpm run verify-translation-pairing --write -2026-07-17-dedicated-full-screen-tui-front-door.md: 3e2b1e751001020eccc9193438daff23dd42518a -2026-07-17-dedicated-full-screen-tui-front-door.zh.md: 5f3632f43702e16ca9dec07c0bb8e42bf50499b7 +2026-07-17-dedicated-full-screen-tui-front-door.md: ecfda138593fc2b98ac42929acc586b11e437ee2 +2026-07-17-dedicated-full-screen-tui-front-door.zh.md: 6b8cc63f7657672a6da542e2033d765b54bd4f07 diff --git a/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.md b/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.md index 3e2b1e7510..ecfda13859 100644 --- a/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.md +++ b/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.md @@ -22,7 +22,7 @@ The selected front door receives the exact generated or resumed `SessionId` used The TUI rebuilds the transcript from the active `session.surface` and reprojects it whenever an event carries a `surfaceOp`, so resumed and compacted history matches the model-visible conversation. It renders Markdown text and reasoning, token totals, the latest `todo/write` plan, and tool cards produced through each tool definition's `presentCall` and `presentResult` methods. Long card bodies retain a configurable head/tail preview with the hidden-line count; one terminal control expands or collapses every card. Pending chunks and tool calls update the same components that completed events settle. -Editor input calls `agent.send()` while idle and `agent.steer()` while a turn is running. Cancellation, reasoning visibility, tool-card expansion, redraw, transcript clearing, and exit are terminal-only controls. The idle footer derives context occupancy from `tokenMeter` and pairs the selected model with its reasoning state; during a run, elapsed activity and the Escape interrupt hint replace that summary. The plugin registers the shared `userInteraction` provider and presents queued questions in a wide bottom-left keyboard panel with batch progress, numbered options, and aligned descriptions; agent behavior and answer logging remain owned by their existing services. +Editor input calls `agent.send()` while idle and `agent.steer()` while a turn is running. Cancellation, reasoning visibility, tool-card expansion, redraw, transcript clearing, and exit are terminal-only controls. The idle footer derives context occupancy from `tokenMeter` and shows the selected model; during a run, elapsed activity and the Escape interrupt hint replace that summary. `/status` remains available in either state and appends a detailed terminal-only snapshot: session identity and timestamps, selected model and reasoning visibility, lifecycle counts folded from the event log, the same deduplicated usage buckets and KV-cache rate as the footer, and context use from `tokenMeter` plus the selected model's advertised capacity. The plugin registers the shared `userInteraction` provider and presents queued questions in a wide bottom-left keyboard panel with batch progress, numbered options, and aligned descriptions; agent behavior and answer logging remain owned by their existing services. The `/model` command presents the advisory `ctx.llm` catalog as a keyboard selector and changes only this TUI session's target; argument forms remain available for direct selection. Agent-scoped prompt-assembly and request waterfalls snapshot one provider/model pair per step, so `{{provider}}` / `{{model}}` interpolation and request routing cannot split when a command arrives during assembly. The latest logged request header restores a used target; a selection that never reaches a request remains process-local. diff --git a/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.zh.md b/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.zh.md index 5f3632f437..6b8cc63f76 100644 --- a/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.zh.md +++ b/.agents/notes/implemented/feature/2026-07-17-dedicated-full-screen-tui-front-door.zh.md @@ -22,7 +22,7 @@ DeepSeek Harness 将 [`@deepseek-ai/dsh-tui`](../../../../packages/ui/tui/README TUI 从活跃的 `session.surface` 重建 transcript(文本记录),并在事件携带 `surfaceOp` 时重新投影,因此恢复或压缩后的历史与模型可见会话保持一致。TUI 渲染 Markdown 文本与推理、token 用量、最新 `todo/write` 计划,以及各工具定义通过 `presentCall` 和 `presentResult` 方法生成的工具卡片。较长的工具卡片正文会保留可配置的头尾预览,并显示隐藏行数;一个终端控制可以展开或收起全部卡片。进行中的分片与工具调用会更新同一组组件,随后由完成事件收束状态。 -agent 空闲时,编辑器输入调用 `agent.send()`;轮次运行中则调用 `agent.steer()`。取消、推理显隐、工具卡片展开、重绘、清空 transcript 和退出都只是终端控制。空闲态页脚根据 `tokenMeter` 得出上下文占用率,并将选中模型及其推理状态组合显示;agent 运行期间,该摘要会替换为带已用时长的活动指示和 Escape 中断提示。插件注册共享的 `userInteraction` 提供方,在左下角宽幅键盘操作面板中呈现排队的问题,面板显示批次进度、带编号的选项和对齐的描述;agent 行为和答案日志仍由既有服务负责。 +agent 空闲时,编辑器输入调用 `agent.send()`;轮次运行中则调用 `agent.steer()`。取消、推理显隐、工具卡片展开、重绘、清空 transcript 和退出都只是终端控制。空闲态页脚根据 `tokenMeter` 得出上下文占用率,并显示所选模型;agent 运行期间,该摘要会替换为带已用时长的活动指示和 Escape 中断提示。`/status` 在这两种状态下均可用,并会追加一份仅在终端显示的详细快照,其中包括会话标识与时间戳、所选模型及推理显隐状态、从事件日志归并得出的生命周期计数、与页脚一致的去重用量分项和 KV 缓存命中率,以及 `tokenMeter` 给出的上下文用量和所选模型公布的容量。插件注册共享的 `userInteraction` 提供方,在左下角宽幅键盘操作面板中呈现排队的问题,面板显示批次进度、带编号的选项和对齐的描述;agent 行为和答案日志仍由既有服务负责。 `/model` 命令将建议性的 `ctx.llm` 目录呈现为键盘选择器,并且只更改当前 TUI 会话的目标;带参数的形式仍可直接选择目标。agent 作用域内的 prompt 组装和请求两条 waterfall(瀑布式事件)会为每个 step 快照一次同一个提供方/模型字段组合,因此即使命令在组装期间到达,`{{provider}}` / `{{model}}` 插值与请求路由也不会分裂。系统通过日志中最新的请求头恢复已经使用过的目标;未被请求使用的选择只保留在当前进程中。 diff --git a/examples/tui-agent/README.md b/examples/tui-agent/README.md index e4197b22c4..ecae86750b 100644 --- a/examples/tui-agent/README.md +++ b/examples/tui-agent/README.md @@ -17,7 +17,7 @@ Type a coding task. The agent works through the `read`/`write`/`edit` filesystem The `todo_write` task tracker is opt-in and not in the shipped config: add `@deepseek-ai/dsh-tool-todo` to `cordis.yml` (or a personal-config overlay under `~/.dsh`) to expose it. Once loaded, the model records a whole-list plan to the session log and the TUI renders it. -The TUI renders Markdown history, reasoning, tool-owned terminal/diff/generic cards, token totals, and — when `todo_write` is loaded — the latest plan. Long tool bodies keep a head/tail preview; Ctrl+O expands or collapses every card. Enter submits or steers while the agent runs, Ctrl+R toggles reasoning, Escape cancels, and `/help` lists commands. `/model` opens a keyboard selector for the current provider catalog; use Up/Down and Enter, or `/model ` and `/model /` for direct selection. `ask_user_question` opens a wide bottom-left keyboard panel with batch progress and numbered options. +The TUI renders Markdown history, reasoning, tool-owned terminal/diff/generic cards, token totals, and — when `todo_write` is loaded — the latest plan. Long tool bodies keep a head/tail preview; Ctrl+O expands or collapses every card. Enter submits or steers while the agent runs, Ctrl+R toggles reasoning, Escape cancels, and `/help` lists commands. `/status` expands the current session's identity, activity counts, exact token/cache buckets, context use, and timestamps without interrupting a running turn. `/model` opens a keyboard selector for the current provider catalog; use Up/Down and Enter, or `/model ` and `/model /` for direct selection. `ask_user_question` opens a wide bottom-left keyboard panel with batch progress and numbered options. ### Resuming a prior session diff --git a/examples/tui-agent/tests/tui-keyless-smoke.e2e.ts b/examples/tui-agent/tests/tui-keyless-smoke.e2e.ts index 2fd1dd1467..e9991b1404 100644 --- a/examples/tui-agent/tests/tui-keyless-smoke.e2e.ts +++ b/examples/tui-agent/tests/tui-keyless-smoke.e2e.ts @@ -101,8 +101,10 @@ describe('tui-agent keyless smoke (real Loader tree in a PTY)', () => { // provider's tool-less title call; the scripted adapter answers it, the // accepted title lands in the log, and the TUI renders the terminal // window title as `` via OSC 0. - // Gating /exit on it keeps the assertion race-free. - { waitFor: 'scripted session title — DeepSeek Harness', send: '/exit\r' }, + // Gating /status on it keeps the assertion race-free; the diagnostics + // card is then exercised through the same real Loader/PTY composition. + { waitFor: 'scripted session title — DeepSeek Harness', send: '/status\r' }, + { waitFor: 'Session status', send: '/exit\r' }, ], }) expect(output).toContain('I need one decision before I continue.') @@ -114,6 +116,14 @@ describe('tui-agent keyless smoke (real Loader tree in a PTY)', () => { expect(output).not.toContain('\u009B31mMODEL_C1') expect(output).toContain('Safe') expect(output).toContain('\u001B]0;scripted session title — DeepSeek Harness\u0007') + expect(output).toContain('Session status') + expect(output).toContain('Title') + expect(output).toContain('scripted session title') + expect(output).toContain('Model') + expect(output).toContain('tui-scripted/tui-scripted-model-pro') + expect(output).toContain('KV cache') + expect(output).toContain('Context') + expect(output).toContain('128,000') expect(output).toContain('\u001B[?2004l') }, LOADER_SMOKE_TEST_TIMEOUT_MS) diff --git a/packages/ui/tui/README.md b/packages/ui/tui/README.md index bc6521d058..119803fd9c 100644 --- a/packages/ui/tui/README.md +++ b/packages/ui/tui/README.md @@ -14,7 +14,7 @@ An embedding may provide `TuiRuntime.formatCwd` when its logical workspace label Before model output, session events, tool presenters, questions, configuration, or diagnostics reach pi-tui's ANSI-aware renderers or the terminal title, the TUI renders C0 and C1 controls other than line feeds as visible `\xNN` text. Those sources cannot add terminal control sequences; the TUI and pi-tui retain ownership of terminal rendering and styling. -While the agent is running, ordinary editor submissions call `agent.steer()`; otherwise they call `agent.send()`. A slash at the start of the submitted line enters `ctx.commands` instead: known commands execute directly, unknown commands produce a warning, and neither path reaches the model. The TUI registers `/help`, `/model`, `/clear`, `/reasoning`, `/tools`, `/redraw`, `/reload`, `/resume`, and `/exit` as agent-scoped definitions; every other effective command joins autocomplete and `/help` dynamically, as do `/skill:` completions. A status line above the editor reports the turn phase the TUI derives from session events — waiting for the first token, thinking, responding, or executing tools — with the elapsed time in that phase and the running step total, refreshed each second, and ends with the `Enter sends steering, Esc cancels` hint; while steering messages wait to reach the model it inserts a `N queued ·` badge before the hint that clears as each drains. Ctrl+C or Escape cancels a running turn. Tool cards collapse long bodies into a configurable head/tail preview; Ctrl+O toggles every card between its preview and full output. Ctrl+R toggles reasoning, Ctrl+L redraws, and Ctrl+D exits while idle. +While the agent is running, ordinary editor submissions call `agent.steer()`; otherwise they call `agent.send()`. A slash at the start of the submitted line enters `ctx.commands` instead: known commands execute directly, unknown commands produce a warning, and neither path reaches the model. The TUI registers `/help`, `/model`, `/clear`, `/reasoning`, `/tools`, `/redraw`, `/reload`, `/resume`, `/status`, and `/exit` as agent-scoped definitions; every other effective command joins autocomplete and `/help` dynamically, as do `/skill:` completions. A status line above the editor reports the turn phase the TUI derives from session events — waiting for the first token, thinking, responding, or executing tools — with the elapsed time in that phase and the running step total, refreshed each second, and ends with the `Enter sends steering, Esc cancels` hint; while steering messages wait to reach the model it inserts a `N queued ·` badge before the hint that clears as each drains. Ctrl+C or Escape cancels a running turn. Tool cards collapse long bodies into a configurable head/tail preview; Ctrl+O toggles every card between its preview and full output. Ctrl+R toggles reasoning, Ctrl+L redraws, and Ctrl+D exits while idle. `/model` opens the advisory `ctx.llm` catalog as a keyboard selector: Up/Down moves, Enter selects, and Escape closes it. `/model ` still selects an unambiguous model id directly, while `/model /` selects an exact target. The configured target or latest logged request header initializes the selector, and an unlisted current model remains visible because catalogs are advisory. Selection is local to this TUI session. Prompt assembly snapshots the target for one step, replaces `{{provider}}` and `{{model}}`, and applies the same pair through `agent/request`; a switch during assembly therefore starts with a later step. The request header durably records targets that reach the model, while an unused selection remains process-local. @@ -22,6 +22,8 @@ While the agent is running, ordinary editor submissions call `agent.steer()`; ot The footer sums the session's reported usage as `↑`, followed by `cache %` once any input has been billed — the share of billed prompt tokens (uncached input plus cache reads and writes) served from the provider cache, rounded to a percent. It also compares token-meter pressure with `ctx.llm.resolveModelContext()` for the current route (omitting the context share when the adapter has no capacity metadata) and shows the current model and tool-card mode; the right side clips first when the footer is narrow. +`/status` adds a point-in-time diagnostics card to the transcript and remains available while the agent runs. It reports the session id, title, working directory, selected provider/model, reasoning-block visibility, agent state, event/turn/step/tool-call counts, exact input/output/cache token buckets, KV-cache hit rate, token-meter context use and capacity, creation time, and latest event time. Missing titles, models, cache input, or context capacity are labeled instead of inferred. The card is terminal-only and does not duplicate the compact footer. + When `resumeCommand` is set and a `sessionPersistence` backend is mounted, exiting prints the resume command for the current session (once it has been persisted, so an abandoned session yields no hint), and `/resume` lists this workspace's persisted sessions newest-first, each with its resume command and a marker on the current one. `{session}` in the template expands to the session id; the TUI only prints commands to copy and never resumes in place. ## Config diff --git a/packages/ui/tui/src/index.ts b/packages/ui/tui/src/index.ts index 99e0ec2727..cd6ab99f2b 100644 --- a/packages/ui/tui/src/index.ts +++ b/packages/ui/tui/src/index.ts @@ -940,6 +940,77 @@ function sessionTokens(session: Session): SessionTokenTotals { return totals } +function formatDiagnosticNumber(value: number): string { + return value.toLocaleString('en-US') +} + +function formatDiagnosticTime(value: number): string { + return new Date(value).toISOString().replace('T', ' ').replace(/\.\d{3}Z$/u, ' UTC') +} + +function formatDiagnosticCount(value: number, singular: string): string { + return `${String(value)} ${singular}${value === 1 ? '' : 's'}` +} + +function diagnosticMeter(percent: number, palette: Palette): string { + const width = 16 + const filled = Math.round(Math.min(100, Math.max(0, percent)) / 100 * width) + return `${palette.dim('[')}${palette.accent('█'.repeat(filled))}${palette.dim(`${'░'.repeat(width - filled)}]`)}` +} + +type StatusCardRow = readonly [label: string, value: string] + +/** Bordered, grouped field card for one point-in-time status snapshot. */ +class StatusCardComponent implements Component { + constructor( + private readonly groups: readonly (readonly StatusCardRow[])[], + private readonly palette: Palette, + ) {} + + invalidate(): void {} + + render(width: number): string[] { + const labels = this.groups.flatMap(group => group.map(([label]) => `${label}:`)) + const naturalLabelWidth = Math.max(...labels.map(label => label.length)) + const naturalBodyWidth = Math.max(...this.groups.flatMap(group => group.map(([, value]) => + 1 + naturalLabelWidth + 2 + visibleWidth(value)))) + const cardWidth = Math.min( + Math.max(8, width), + Math.max('Session status'.length + 5, naturalBodyWidth + 4), + ) + const innerWidth = Math.max(1, cardWidth - 4) + const labelWidth = Math.min( + naturalLabelWidth, + Math.max(1, Math.floor(innerWidth / 3)), + ) + const body: string[] = [] + for (const [groupIndex, group] of this.groups.entries()) { + if (groupIndex > 0) body.push('') + for (const [label, value] of group) { + const plainLabel = truncateToWidth(`${label}:`, labelWidth, '') + const prefix = ` ${this.palette.muted(plainLabel.padEnd(labelWidth))} ` + const continuation = ' '.repeat(1 + labelWidth + 2) + const valueWidth = Math.max(1, innerWidth - visibleWidth(prefix)) + const wrapped = wrapTextWithAnsi(value, valueWidth) + for (const [lineIndex, line] of wrapped.entries()) { + body.push(`${lineIndex === 0 ? prefix : continuation}${line}`) + } + } + } + + const title = truncateToWidth('Session status', Math.max(1, cardWidth - 5), '') + const topTail = '─'.repeat(Math.max(0, cardWidth - visibleWidth(title) - 5)) + const top = `${this.palette.dim('╭─ ')}${this.palette.bold(this.palette.accent(title))}${this.palette.dim(` ${topTail}╮`)}` + const lines = [top] + for (const line of body) { + const clipped = truncateToWidth(line, innerWidth, '') + lines.push(`${this.palette.dim('│')} ${clipped}${' '.repeat(Math.max(0, innerWidth - visibleWidth(clipped)))} ${this.palette.dim('│')}`) + } + lines.push(this.palette.dim(`╰${'─'.repeat(Math.max(0, cardWidth - 2))}╯`)) + return lines + } +} + class FooterComponent implements Component { constructor( private readonly agent: Agent, @@ -1953,6 +2024,54 @@ export function createTuiChat( requestRender() } + const showStatus = (): void => { + const events = agent.session.events + const latestActivity = events.at(-1)?.time ?? agent.session.header.createdAt + const usedContext = Math.max(0, Math.round(ctx.tokenMeter.measure(agent.session).totalTokens)) + let context = `${formatDiagnosticNumber(usedContext)} used · capacity unknown` + if (contextWindow !== undefined) { + const contextPercent = Math.round(usedContext / contextWindow * 100) + context = `${diagnosticMeter(contextPercent, palette)} ${String(contextPercent)}% used (${formatDiagnosticNumber(usedContext)} / ${formatDiagnosticNumber(contextWindow)})` + } + const rate = cacheHitRate(tokens) + const turns = events.filter(event => event.type === 'turn/start').length + const steps = events.filter(event => event.type === 'step/start').length + const toolCalls = events.filter(event => event.type === 'tool/call').length + const model = target.current === undefined ? 'unset' : displayText(targetLabel(target.current)) + const groups: readonly (readonly StatusCardRow[])[] = [ + [ + ['Session', displayText(agent.session.id)], + ['Title', displayText(sessionTitle ?? 'untitled')], + ['Directory', displayText(cwd)], + ['Model', `${model} ${palette.dim(`(reasoning ${showReasoning ? 'shown' : 'hidden'})`)}`], + ], + [ + ['Agent', [ + agent.status, + formatDiagnosticCount(events.length, 'event'), + formatDiagnosticCount(turns, 'turn'), + formatDiagnosticCount(steps, 'step'), + formatDiagnosticCount(toolCalls, 'tool call'), + ].join(' · ')], + ], + [ + ['Tokens', `${formatDiagnosticNumber(tokens.input)} input + ${formatDiagnosticNumber(tokens.output)} output`], + ['KV cache', rate === undefined + ? `n/a (${formatDiagnosticNumber(tokens.cacheRead)} read + ${formatDiagnosticNumber(tokens.cacheWrite)} write)` + : `${diagnosticMeter(rate, palette)} ${String(rate)}% hit (${formatDiagnosticNumber(tokens.cacheRead)} read + ${formatDiagnosticNumber(tokens.cacheWrite)} write)`], + ['Context', context], + ], + [ + ['Created', formatDiagnosticTime(agent.session.header.createdAt)], + ['Active', formatDiagnosticTime(latestActivity)], + ], + ] + const card = new StatusCardComponent(groups, palette) + chat.addChild(new Spacer(1)) + chat.addChild(card) + requestRender() + } + // Skill listing is async while `createTuiChat` is synchronous, so the // completions rebuild once the catalog resolves. Disabled-for-model skills // are absent from `list()`, so they never appear as completions; a user can @@ -2041,6 +2160,11 @@ export function createTuiChat( description: 'List this workspace\'s resumable sessions', handler: () => { showResume(); return { kind: 'success' } }, }) + commandCtx.commands.register({ + name: 'status', + description: 'Show detailed session diagnostics', + handler: () => { showStatus(); return { kind: 'success' } }, + }) commandCtx.commands.register({ name: 'exit', description: 'Exit after the active turn reaches idle', diff --git a/packages/ui/tui/tests/harness.ts b/packages/ui/tui/tests/harness.ts index 8210a3a423..97db25b7ae 100644 --- a/packages/ui/tui/tests/harness.ts +++ b/packages/ui/tui/tests/harness.ts @@ -24,6 +24,8 @@ interface FakeAgent extends Agent { export interface TuiHarnessOptions { status?: AgentStatus config?: Config + /** Leave the session event log empty instead of seeding one turn and step. */ + omitInitialLifecycle?: boolean /** Omit the harness's default `welcome`, exercising the banner sweep-reveal path. */ omitWelcome?: boolean tools?: Record @@ -120,11 +122,13 @@ export async function createTuiTestHarness [instructions] — load a skill into the conversation " +19| " /skill: [instructions] — load a skill into the conversation " style 1-65 fg=bright-black -19| -20| " provider stream failed after partial output " +20| +21| " provider stream failed after partial output " style 1-43 fg=red -21| -22| " The previous process ended during this turn. " +22| +23| " The previous process ended during this turn. " style 1-44 fg=yellow -23| -24| " Unknown command: /unknown-advanced-command " +24| +25| " Unknown command: /unknown-advanced-command " style 1-42 fg=yellow -25| "────────────────────────────────────────────────────────────────────────────────────────────" +26| "────────────────────────────────────────────────────────────────────────────────────────────" style 0-91 dim -26| " " +27| " " style 1-1 inverse -27| "────────────────────────────────────────────────────────────────────────────────────────────" +28| "────────────────────────────────────────────────────────────────────────────────────────────" style 0-91 dim -28| "deepseek-v4-flash /workspace/project ↑0 ↓0 0% context tools:collapsed" +29| "deepseek-v4-flash /workspace/project ↑0 ↓0 0% context tools:collapsed" style 0-43 dim style 65-91 dim -29-31| +30-31| diff --git a/packages/ui/tui/tests/snapshots/errors-and-help.expected.txt b/packages/ui/tui/tests/snapshots/errors-and-help.expected.txt index b6bb78ce3a..05c35e32e1 100644 --- a/packages/ui/tui/tests/snapshots/errors-and-help.expected.txt +++ b/packages/ui/tui/tests/snapshots/errors-and-help.expected.txt @@ -1,7 +1,7 @@ terminal 92x32 buffer=normal length=32 base=0 viewport=0 lifecycle started=1 stopped=0 progress=inactive title "DSH snapshot" -cursor hidden column=1 viewportRow=26 bufferRow=26 +cursor hidden column=1 viewportRow=27 bufferRow=27 buffer 0| " DEEPSEEK HARNESS" style 1-8 fg=bright-blue bold @@ -36,26 +36,28 @@ buffer style 1-88 fg=bright-black 16| " /resume — List this workspace's resumable sessions " style 1-50 fg=bright-black -17| " /tools — Expand or collapse all tool cards " +17| " /status — Show detailed session diagnostics " + style 1-43 fg=bright-black +18| " /tools — Expand or collapse all tool cards " style 1-42 fg=bright-black -18| " /skill: [instructions] — load a skill into the conversation " +19| " /skill: [instructions] — load a skill into the conversation " style 1-65 fg=bright-black -19| -20| " provider stream failed after partial output " +20| +21| " provider stream failed after partial output " style 1-43 fg=red -21| -22| " The previous process ended during this turn. " +22| +23| " The previous process ended during this turn. " style 1-44 fg=yellow -23| -24| " Unknown command: /unknown-advanced-command " +24| +25| " Unknown command: /unknown-advanced-command " style 1-42 fg=yellow -25| "────────────────────────────────────────────────────────────────────────────────────────────" +26| "────────────────────────────────────────────────────────────────────────────────────────────" style 0-91 dim -26| " " +27| " " style 1-1 inverse -27| "────────────────────────────────────────────────────────────────────────────────────────────" +28| "────────────────────────────────────────────────────────────────────────────────────────────" style 0-91 dim -28| "deepseek-v4-flash /workspace/project ↑0 ↓0 0% context tools:collapsed" +29| "deepseek-v4-flash /workspace/project ↑0 ↓0 0% context tools:collapsed" style 0-43 dim style 65-91 dim -29-31| +30-31| diff --git a/packages/ui/tui/tests/snapshots/status-diagnostics-narrow.expected.txt b/packages/ui/tui/tests/snapshots/status-diagnostics-narrow.expected.txt new file mode 100644 index 0000000000..de46d59543 --- /dev/null +++ b/packages/ui/tui/tests/snapshots/status-diagnostics-narrow.expected.txt @@ -0,0 +1,110 @@ +terminal 56x36 buffer=normal length=36 base=0 viewport=0 +lifecycle started=1 stopped=0 progress=inactive +title "Inspect session diagnostics — DSH snapshot" +cursor hidden column=1 viewportRow=32 bufferRow=32 +buffer +0| " DEEPSEEK HARNESS" + style 1-8 fg=bright-blue bold + style 10-16 bold +1| " Inspect session diagnostics" + style 1-27 fg=bright-black +2| " deepseek-v4-pro • main-session" + style 1-32 dim +3| +4| "▌ " + style 0-0 fg=bright-blue +5| "▌ You " + style 0-0 fg=bright-blue + style 2-4 fg=bright-blue bold +6| "▌ inspect this session " + style 0-0 fg=bright-blue +7| "▌ " + style 0-0 fg=bright-blue +8| +9| " Assistant " + style 1-9 fg=bright-magenta bold +10| " Session inspected. " +11| +12| "╭─ Session status ─────────────────────────────────────╮" + style 0-2 dim + style 3-16 fg=bright-blue bold + style 17-55 dim +13| "│ Session: main-session │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +14| "│ Title: Inspect session diagnostics │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +15| "│ Directory: /workspace/project │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +16| "│ Model: deepseek/deepseek-v4-pro (reasoning │" + style 0-0 dim + style 3-12 fg=bright-black + style 40-55 dim +17| "│ shown) │" + style 0-0 dim + style 15-20 dim + style 55-55 dim +18| "│ │" + style 0-0 dim + style 55-55 dim +19| "│ Agent: idle · 6 events · 1 turn · 1 step · 1 │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +20| "│ tool call │" + style 0-0 dim + style 55-55 dim +21| "│ │" + style 0-0 dim + style 55-55 dim +22| "│ Tokens: 1,250 input + 340 output │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +23| "│ KV cache: [███████████░░░░░] 67% hit (3,000 read │" + style 0-0 dim + style 3-12 fg=bright-black + style 15-15 dim + style 16-26 fg=bright-blue + style 27-32 dim + style 55-55 dim +24| "│ + 250 write) │" + style 0-0 dim + style 55-55 dim +25| "│ Context: [█████░░░░░░░░░░░] 33% used (42,000 / │" + style 0-0 dim + style 3-12 fg=bright-black + style 15-15 dim + style 16-20 fg=bright-blue + style 21-32 dim + style 55-55 dim +26| "│ 128,000) │" + style 0-0 dim + style 55-55 dim +27| "│ │" + style 0-0 dim + style 55-55 dim +28| "│ Created: 2026-07-22 09:10:11 UTC │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +29| "│ Active: 2026-07-22 09:10:11 UTC │" + style 0-0 dim + style 3-12 fg=bright-black + style 55-55 dim +30| "╰──────────────────────────────────────────────────────╯" + style 0-55 dim +31| "────────────────────────────────────────────────────────" + style 0-55 dim +32| " " + style 1-1 inverse +33| "────────────────────────────────────────────────────────" + style 0-55 dim +34| "deepseek-v4-pro /workspace/project ↑1.3k ↓340 cache 6" + style 0-55 dim +35| diff --git a/packages/ui/tui/tests/snapshots/status-diagnostics.expected.txt b/packages/ui/tui/tests/snapshots/status-diagnostics.expected.txt new file mode 100644 index 0000000000..73d98953f6 --- /dev/null +++ b/packages/ui/tui/tests/snapshots/status-diagnostics.expected.txt @@ -0,0 +1,99 @@ +terminal 92x32 buffer=normal length=32 base=0 viewport=0 +lifecycle started=1 stopped=0 progress=inactive +title "Inspect session diagnostics — DSH snapshot" +cursor hidden column=1 viewportRow=28 bufferRow=28 +buffer +0| " DEEPSEEK HARNESS" + style 1-8 fg=bright-blue bold + style 10-16 bold +1| " Inspect session diagnostics" + style 1-27 fg=bright-black +2| " deepseek-v4-pro • main-session" + style 1-32 dim +3| +4| "▌ " + style 0-0 fg=bright-blue +5| "▌ You " + style 0-0 fg=bright-blue + style 2-4 fg=bright-blue bold +6| "▌ inspect this session " + style 0-0 fg=bright-blue +7| "▌ " + style 0-0 fg=bright-blue +8| +9| " Assistant " + style 1-9 fg=bright-magenta bold +10| " Session inspected. " +11| +12| "╭─ Session status ─────────────────────────────────────────────────╮" + style 0-2 dim + style 3-16 fg=bright-blue bold + style 17-67 dim +13| "│ Session: main-session │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +14| "│ Title: Inspect session diagnostics │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +15| "│ Directory: /workspace/project │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +16| "│ Model: deepseek/deepseek-v4-pro (reasoning shown) │" + style 0-0 dim + style 3-12 fg=bright-black + style 40-56 dim + style 67-67 dim +17| "│ │" + style 0-0 dim + style 67-67 dim +18| "│ Agent: idle · 6 events · 1 turn · 1 step · 1 tool call │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +19| "│ │" + style 0-0 dim + style 67-67 dim +20| "│ Tokens: 1,250 input + 340 output │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +21| "│ KV cache: [███████████░░░░░] 67% hit (3,000 read + 250 write) │" + style 0-0 dim + style 3-12 fg=bright-black + style 15-15 dim + style 16-26 fg=bright-blue + style 27-32 dim + style 67-67 dim +22| "│ Context: [█████░░░░░░░░░░░] 33% used (42,000 / 128,000) │" + style 0-0 dim + style 3-12 fg=bright-black + style 15-15 dim + style 16-20 fg=bright-blue + style 21-32 dim + style 67-67 dim +23| "│ │" + style 0-0 dim + style 67-67 dim +24| "│ Created: 2026-07-22 09:10:11 UTC │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +25| "│ Active: 2026-07-22 09:10:11 UTC │" + style 0-0 dim + style 3-12 fg=bright-black + style 67-67 dim +26| "╰──────────────────────────────────────────────────────────────────╯" + style 0-67 dim +27| "────────────────────────────────────────────────────────────────────────────────────────────" + style 0-91 dim +28| " " + style 1-1 inverse +29| "────────────────────────────────────────────────────────────────────────────────────────────" + style 0-91 dim +30| "deepseek-v4-pro /workspace/project ↑1.3k ↓340 cache 67% 33% context tools:collapsed" + style 0-57 dim + style 64-91 dim +31| diff --git a/packages/ui/tui/tests/tui.snapshot.ts b/packages/ui/tui/tests/tui.snapshot.ts index d706ede1d9..97617508ec 100644 --- a/packages/ui/tui/tests/tui.snapshot.ts +++ b/packages/ui/tui/tests/tui.snapshot.ts @@ -1,7 +1,7 @@ import { mkdir, readdir, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' -import { afterAll, describe, expect, it } from 'vitest' +import { afterAll, describe, expect, it, vi } from 'vitest' import type { Context } from 'cordis' import { agentEvents } from '@deepseek-ai/dsh-agent' import { CallId, type ContentBlock } from '@deepseek-ai/dsh-llm' @@ -48,6 +48,8 @@ const CHECKPOINTS = [ 'errors-and-help', 'disposed-terminal', 'resume-sessions', + 'status-diagnostics', + 'status-diagnostics-narrow', ] as const type Checkpoint = typeof CHECKPOINTS[number] @@ -637,6 +639,45 @@ describe('TUI terminal-state snapshots', () => { await checkpoint('resume-sessions', harness.terminal, { includeScrollback: true }) await disposeSnapshot(harness) }) + + it('pins the detailed session diagnostics card', async () => { + const dateNow = vi.spyOn(Date, 'now').mockReturnValue(Date.parse('2026-07-22T09:10:11.000Z')) + const harness = await setupSnapshot({ + contextWindow: 128_000, + contextTokens: 42_000, + agentOptions: { provider: 'deepseek', model: 'deepseek-v4-pro' }, + beforeMount(session) { + appendUser(session, 'inspect this session') + appendAssistant(session, [{ type: 'text', text: 'Session inspected.' }], { + inputTokens: 1_250, + outputTokens: 340, + cacheReadTokens: 3_000, + cacheWriteTokens: 250, + }) + session.append('tool/call', { + turn: 1, + step: 1, + callId: CallId('status-call'), + name: 'read', + arguments: '{"path":"README.md"}', + }) + session.append('session/title', { + title: 'Inspect session diagnostics', + messageSeqs: [1], + source: { kind: 'fallback' }, + }) + }, + }, { columns: 92, rows: 32 }) + await renderAfter(harness, () => { + harness.terminal.send('/status') + harness.terminal.send('\r') + }) + await checkpoint('status-diagnostics', harness.terminal, { includeScrollback: true }) + await renderAfter(harness, () => { harness.terminal.resize(56, 36) }) + await checkpoint('status-diagnostics-narrow', harness.terminal, { includeScrollback: true }) + await disposeSnapshot(harness) + dateNow.mockRestore() + }) }) afterAll(async () => { diff --git a/packages/ui/tui/tests/tui.spec.ts b/packages/ui/tui/tests/tui.spec.ts index a26ae0e3fa..d48289f46d 100644 --- a/packages/ui/tui/tests/tui.spec.ts +++ b/packages/ui/tui/tests/tui.spec.ts @@ -845,6 +845,90 @@ describe('pi-tui chat lifecycle and transcript', () => { await dispose(result) }) + it('shows detailed session diagnostics while the agent is running', async () => { + const timestamp = Date.parse('2026-07-22T09:10:11.000Z') + const dateNow = vi.spyOn(Date, 'now').mockReturnValue(timestamp) + const result = await setup({ + cwd: '/workspace/status', + contextWindow: 128_000, + contextTokens: 42_000, + config: { showReasoning: false }, + agentOptions: { provider: 'deepseek', model: 'deepseek-v4-pro' }, + beforeMount(session) { + session.append('session/title', { + title: 'Inspect status \u001B]2;unsafe\u0007', + messageSeqs: [1], + source: { kind: 'fallback' }, + }) + appendAssistant(session, [{ type: 'text', text: 'measured' }], { + inputTokens: 1_250, + outputTokens: 340, + cacheReadTokens: 3_000, + cacheWriteTokens: 250, + }) + session.append('tool/call', { + turn: 1, step: 1, callId: 'status-call-1' as never, name: 'read', arguments: '{}', + }) + session.append('tool/call', { + turn: 1, step: 1, callId: 'status-call-2' as never, name: 'write', arguments: '{}', + }) + }, + }) + result.agent.status = 'running' + agentEvents(result.ctx, result.agent).emit('agent/status', 'running') + result.terminal.send('/status') + result.terminal.send('\r') + await tick() + + expect(result.terminal.output).toContain('Session status') + expect(result.terminal.output).toContain('main-session') + expect(result.terminal.output).toContain('Inspect status \\x1b]2;unsafe\\x07') + expect(result.terminal.output).toContain('/workspace/status') + expect(result.terminal.output).toContain('deepseek/deepseek-v4-pro (reasoning hidden)') + expect(result.terminal.output).toContain('running · 6 events · 1 turn · 1 step · 2 tool calls') + expect(result.terminal.output).toContain('1,250 input + 340 output') + expect(result.terminal.output).toContain('[███████████░░░░░] 67% hit (3,000 read + 250 write)') + expect(result.terminal.output).toContain('[█████░░░░░░░░░░░] 33% used (42,000 / 128,000)') + expect(result.terminal.output).toContain('2026-07-22 09:10:11 UTC') + expect(result.terminal.output).not.toContain('\u001B]2;unsafe\u0007') + + result.terminal.resize(56) + result.terminal.send('/redraw') + result.terminal.send('\r') + await tick() + + await dispose(result) + dateNow.mockRestore() + }) + + it('labels unavailable status diagnostics without inventing values', async () => { + const timestamp = Date.parse('2026-07-22T10:11:12.000Z') + const dateNow = vi.spyOn(Date, 'now').mockReturnValue(timestamp) + const result = await setup({ + cwd: null, + omitInitialLifecycle: true, + contextTokens: 7, + agentOptions: {}, + catalog: { + providers: [], + models: [], + resolveModelContext: () => Promise.resolve(undefined), + }, + }) + result.terminal.send('/status') + result.terminal.send('\r') + await tick() + + expect(result.terminal.output).toContain('untitled') + expect(result.terminal.output).toContain('unset (reasoning shown)') + expect(result.terminal.output).toContain('idle · 0 events · 0 turns · 0 steps · 0 tool calls') + expect(result.terminal.output).toContain('n/a (0 read + 0 write)') + expect(result.terminal.output).toContain('7 used · capacity unknown') + expect(result.terminal.output).toContain('2026-07-22 10:11:12 UTC') + await dispose(result) + dateNow.mockRestore() + }) + it('sends, steers, handles commands, global keys, and disposed-agent input', async () => { const result = await setup()