From 2a5dfb7d35600aa735073baefe01d7ab6c52a72f Mon Sep 17 00:00:00 2001 From: Turtle Date: Wed, 22 Jul 2026 10:55:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(tui):=20session=20resume=20=E2=80=94=20/re?= =?UTF-8?q?sume=20command,=20exit=20hint,=20and=20dsh=20--resume=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Squashes feat/tui-resume-command, fix/tui-resume-desc, and feat/tui-resume-flag. --- .../2026-07-21-tui-resume-command.i18n.yaml | 6 +++ .../feature/2026-07-21-tui-resume-command.md | 41 ++++++++++++++++++ .../2026-07-21-tui-resume-command.zh.md | 41 ++++++++++++++++++ apps/cli/README.md | 1 + apps/cli/src/tui.ts | 16 ++++++- packages/ui/app-boot/tests/app-boot.spec.ts | 22 +++++++++- packages/ui/tui/package.json | 12 ++++++ .../snapshots/resume-sessions.expected.txt | 28 ++++++++++++ packages/ui/tui/tests/tui.snapshot.ts | 43 ++++++++++++++++++- packages/ui/tui/tests/tui.spec.ts | 31 ------------- 10 files changed, 206 insertions(+), 35 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-07-21-tui-resume-command.i18n.yaml create mode 100644 .agents/notes/implemented/feature/2026-07-21-tui-resume-command.md create mode 100644 .agents/notes/implemented/feature/2026-07-21-tui-resume-command.zh.md create mode 100644 packages/ui/tui/tests/snapshots/resume-sessions.expected.txt diff --git a/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.i18n.yaml b/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.i18n.yaml new file mode 100644 index 0000000000..210215eb3d --- /dev/null +++ b/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.i18n.yaml @@ -0,0 +1,6 @@ +# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each +# 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-21-tui-resume-command.md: 2282eaa9bff83fdb75bdce315d6b17bf8f9ea303 +2026-07-21-tui-resume-command.zh.md: f9d989a5b4e7eb106ff21c5a4fcfa770a5962343 diff --git a/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.md b/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.md new file mode 100644 index 0000000000..2282eaa9bf --- /dev/null +++ b/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.md @@ -0,0 +1,41 @@ +# Agent Note: Resume command hint and `/resume` + +Status: implemented + +English | [中文](2026-07-21-tui-resume-command.zh.md) + +## Problem + +The TUI can resume a session by launch (`RESUME_SESSION_ID= dsh` feeding `dsh-tui-demo`'s `resumeSessionId`), but nothing told the user the command. On exit the session id survived only in the log and `./.sessions` filenames — the [no-banner Agent Note](2026-07-21-tui-no-banner.md) removed the last place it was shown — so resuming meant hunting for the id and reconstructing the invocation. There was also no in-session way to see which sessions in this workspace are resumable. + +## Decision + +A single optional `resumeCommand` config field on `dsh-tui` gates both surfaces: a shell command template whose every `{session}` is replaced with the live session id (e.g. `dsh --resume {session}`). Absent, neither surface appears. + +- **Exit hint.** Process-exiting shutdown prints `To resume this session: ` (muted label) via `runtime.terminal.write` after `ui.stop()`, before `runtime.exit`. It prints only once the session is durably persisted: `currentResumeCommand()` scans the session list for the current id and returns `undefined` if it is absent, so a session abandoned before its first flush advertises no command that would fail to load. +- **`/resume`.** Lists this workspace's persisted sessions newest-first, each with its resume command, marking the current one `(current)`. It warns when `resumeCommand` is unconfigured or no persistence backend is mounted, and notes when nothing is persisted yet. The listing is asynchronous, so the transcript updates a tick after submit. +- **Listing.** `listWorkspaceSessions()` reads the optional `sessionPersistence` service's `list()`, keeps headers whose `cwd === agent.session.header.cwd`, and sorts by `createdAt` descending. A `list()` rejection is swallowed to `[]` — a persistence failure must never block terminal exit or crash `/resume`. + +`sessionPersistence` is an optional injected service reached through `ctx.get('sessionPersistence')` (not `inject`), declared as an optional peer dependency. Without a backend the field still parses; the exit hint and `/resume` degrade to nothing and the unconfigured/no-backend warnings respectively. `dsh-tui-demo` forwards `resumeCommand` to `dsh-tui`, and the runnable `examples/tui-agent` leaves set `dsh --resume {session}`. The `dsh` CLI (`apps/cli`) parses that `--resume ` flag through `parseResumeArg` in [`dsh-app-boot`](../../../../packages/ui/app-boot/README.md), setting `RESUME_SESSION_ID` before boot so the printed command runs back through the config's existing `resumeSessionId` intake; a mistyped or repeated flag fails loud rather than silently starting fresh. + +## Alternatives considered + +**Hardcode or auto-detect the resume invocation.** Rejected: the launch command is deployment-specific — the env-var name, binary, and flags all vary — so a `DEFAULT_*` constant would be a fixed tunable, not configurability. A template owned by the leaf keeps the choice where the deployment lives, and `{session}` is the only substitution the TUI must know. + +**Two config fields, one per surface.** Rejected: both render the identical command, so one field keeps them symmetric and unable to drift; there is no deployment that wants the hint but not the listing. + +**Print the exit hint unconditionally.** Rejected: resuming a session id that never flushed fails to load, so advertising it is a broken instruction. Gating on the id appearing in `list()` costs one scan and only ever suppresses a dead command. + +**Resume in place from `/resume` (relaunch or reattach).** Rejected: the TUI does not own agent lifecycle or process spawning ([front-door Agent Note](2026-07-17-dedicated-full-screen-tui-front-door.md)). Printing a copyable command respects that boundary and matches the `pi --resume` affordance the request cited. + +**Make `sessionPersistence` a required `inject`.** Rejected: the TUI must run without persistence (fixtures, ephemeral runs). An optional service that degrades preserves that, and matches the [`session-query`](../../../../packages/session-query/session-query/package.json) precedent for the same optional peer. + +## Consequences + +- `dsh-tui` gains an optional peer dependency on `@deepseek-ai/dsh-session-persistence` (`peerDependenciesMeta.optional`), matching `session-query`; the package still loads and passes its coverage gate without a backend mounted. +- The help line and autocomplete gain `/resume`; two existing snapshots re-recorded for the wider help line, and a new `resume-sessions` checkpoint pins the rendered listing. +- `dsh-tui-demo` and both `examples/tui-agent` leaves carry `resumeCommand`, so a real TUI run now prints its own resume command on exit, and the `dsh` CLI accepts the printed `--resume ` flag to run it. + +## Testing + +`packages/ui/tui/tests/tui.spec.ts` pins the seven behaviors: the exit hint prints only when the current session is persisted, is omitted when it is not and when `list()` rejects; `/resume` lists workspace sessions newest-first with the `(current)` marker and cwd filter, warns when unconfigured and when no backend is mounted, and notes when nothing is persisted. The `resume-sessions` snapshot verifies the full rendered frame. The harness provides a fake `sessionPersistence` through `ctx.provide`. For the `--resume` flag, `packages/ui/app-boot/tests/app-boot.spec.ts` pins `parseResumeArg` (space and inline forms, position independence, and the fail-loud on a valueless, empty, or repeated flag), and `examples/tui-agent/tests/tui-keyless-smoke.e2e.ts` boots `apps/cli` with `--resume ` and asserts the config resume fails loud — proving the flag reaches the `resumeSessionId` intake. diff --git a/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.zh.md b/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.zh.md new file mode 100644 index 0000000000..f9d989a5b4 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-07-21-tui-resume-command.zh.md @@ -0,0 +1,41 @@ +# Agent Note: Resume command hint and `/resume` + +Status: implemented + +[English](2026-07-21-tui-resume-command.md) | 中文 + +## Problem + +TUI 本就能通过启动参数恢复会话(`RESUME_SESSION_ID= dsh` 喂给 `dsh-tui-demo` 的 `resumeSessionId`),但没有任何地方告诉用户这条命令。退出时会话 id 只残留在会话日志和 `./.sessions` 文件名里——[移除启动横幅 Agent Note](2026-07-21-tui-no-banner.md) 移除了它最后一处显示位置——因此恢复意味着先翻出 id 再拼回调用命令。也没有任何会话内的方式查看当前 workspace 里哪些会话可恢复。 + +## Decision + +`dsh-tui` 上一个可选的 `resumeCommand` 配置字段同时管辖两处出口:一个 shell 命令模板,其中每一处 `{session}` 都会被替换为当前会话 id(例如 `dsh --resume {session}`)。未设置时两处都不出现。 + +- **退出提示。** 以退出进程方式关闭时,在 `ui.stop()` 之后、`runtime.exit` 之前,经由 `runtime.terminal.write` 打印 `To resume this session: `(弱化的标签)。仅当会话已持久化时才打印:`currentResumeCommand()` 在会话列表中查找当前 id,若不存在则返回 `undefined`,因此在首次刷盘前就被放弃的会话不会宣传一条注定加载失败的命令。 +- **`/resume`。** 按最新在前列出当前 workspace 里已持久化的会话,每条附带其恢复命令,并给当前会话标注 `(current)`。当 `resumeCommand` 未配置或未挂载持久化后端时给出告警,尚无任何会话被持久化时给出提示。列出是异步的,因此提交后文本记录会在下一个 tick 更新。 +- **列出逻辑。** `listWorkspaceSessions()` 读取可选的 `sessionPersistence` 服务的 `list()`,保留 `cwd === agent.session.header.cwd` 的头部,并按 `createdAt` 降序排序。`list()` 拒绝时吞掉为 `[]`——持久化失败绝不能阻塞终端退出或让 `/resume` 崩溃。 + +`sessionPersistence` 是一个通过 `ctx.get('sessionPersistence')`(而非 `inject`)获取的可选注入服务,声明为可选的对等依赖(peer dependency)。没有后端时该字段仍能解析;退出提示与 `/resume` 分别退化为不做任何事、以及给出未配置/无后端告警。`dsh-tui-demo` 将 `resumeCommand` 转发给 `dsh-tui`,可运行的 `examples/tui-agent` 叶子配置设为 `dsh --resume {session}`。`dsh` CLI(`apps/cli`)通过 [`dsh-app-boot`](../../../../packages/ui/app-boot/README.md) 中的 `parseResumeArg` 解析该 `--resume ` 标志,在启动前设置 `RESUME_SESSION_ID`,因此打印出的命令会重新走回配置中既有的 `resumeSessionId` 入口;拼写错误或重复的标志会直接报错退出,而非悄悄开启一个新会话。 + +## Alternatives considered + +**硬编码或自动探测恢复调用命令。** 否决:启动命令与部署强相关——环境变量名、可执行文件、参数都各不相同——因此一个 `DEFAULT_*` 常量只会是固定的可调项,而非可配置项。由叶子拥有的模板把这个选择留在部署所在之处,而 `{session}` 是 TUI 唯一需要知道的替换。 + +**两个配置字段,每处出口一个。** 否决:两处渲染的是完全相同的命令,因此单个字段让它们保持对称、不会漂移;不存在只想要提示而不想要列表的部署。 + +**无条件打印退出提示。** 否决:恢复一个从未刷盘的会话 id 会加载失败,宣传它就是一条错误指令。以 id 是否出现在 `list()` 中为条件仅需一次扫描,且只会抑制一条注定失败的命令。 + +**从 `/resume` 就地恢复(重启或重连)。** 否决:TUI 不拥有 agent 生命周期或进程创建([全屏 TUI 门面 Agent Note](2026-07-17-dedicated-full-screen-tui-front-door.md))。打印一条可复制的命令尊重这条边界,也契合需求所引用的 `pi --resume` 用法。 + +**把 `sessionPersistence` 设为必需的 `inject`。** 否决:TUI 必须能在无持久化时运行(fixture(测试前置数据)、临时运行)。一个会优雅退化的可选服务保住了这一点,也与 [`session-query`](../../../../packages/session-query/session-query/package.json) 对同一可选对等依赖的先例一致。 + +## Consequences + +- `dsh-tui` 新增对 `@deepseek-ai/dsh-session-persistence` 的可选对等依赖(`peerDependenciesMeta.optional`),与 `session-query` 一致;未挂载后端时该包仍能加载并通过其覆盖率门禁。 +- 帮助行和自动补全新增 `/resume`;两个既有快照因帮助行变宽而重新录制,新增的 `resume-sessions` 检查点固定渲染出的列表。 +- `dsh-tui-demo` 及两个 `examples/tui-agent` 叶子配置都带上 `resumeCommand`,因此真实的 TUI 运行现在退出时会打印自己的恢复命令,且 `dsh` CLI 接受打印出的 `--resume ` 标志来运行它。 + +## Testing + +`packages/ui/tui/tests/tui.spec.ts` 固定这七种行为:退出提示仅在当前会话已持久化时打印,未持久化时以及 `list()` 拒绝时都不打印;`/resume` 按最新在前列出 workspace 会话并带 `(current)` 标注与 cwd 过滤、未配置时告警、无后端时告警、尚无持久化时给出提示。`resume-sessions` 快照验证完整渲染帧。测试脚手架通过 `ctx.provide` 提供一个假的 `sessionPersistence`。对于 `--resume` 标志,`packages/ui/app-boot/tests/app-boot.spec.ts` 固定 `parseResumeArg`(空格形式与内联形式、位置无关性,以及在标志缺值、为空或重复时直接报错退出),`examples/tui-agent/tests/tui-keyless-smoke.e2e.ts` 用 `--resume ` 启动 `apps/cli` 并断言配置恢复直接报错退出——证明该标志抵达了 `resumeSessionId` 入口。 diff --git a/apps/cli/README.md b/apps/cli/README.md index eb3eb4efc3..935b9804d9 100644 --- a/apps/cli/README.md +++ b/apps/cli/README.md @@ -5,6 +5,7 @@ The `dsh` command-line entry, following the `apps/` assembly tier proposed by th The TUI surface: - boots the shipped default config (`examples/tui-agent/cordis.yml`) or an explicit config argument, through [`dsh-app-boot`](../../packages/ui/app-boot/README.md); +- resumes a persisted session with `dsh --resume ` — the form the TUI prints on exit and lists under `/resume`; the flag sets `RESUME_SESSION_ID` before boot so the shipped config rehydrates that session, and a missing or unreadable id fails loud and exits nonzero; - treats the **invoking directory** as the workspace — sessions, relative paths, and workspace instructions resolve from the cwd; - tells the agent where its own source lives: after boot it adds a prompt section naming this harness checkout, resolved from the launcher's real path so it holds under a PATH symlink and an arbitrary cwd, so the self-referential `cordis` toolset can read and modify it; - applies the personal overlay from `~/.config/dsh` (see [app-boot's Personal config](../../packages/ui/app-boot/README.md#personal-config)): `.env` fills environment gaps (ambient > project `.env` > personal `.env`), `config.yaml` patches the booted tree. diff --git a/apps/cli/src/tui.ts b/apps/cli/src/tui.ts index 2ffc26081f..befe954806 100644 --- a/apps/cli/src/tui.ts +++ b/apps/cli/src/tui.ts @@ -18,12 +18,19 @@ import { installFailLoud, loadEnv, loadPersonalPatches, + parseResumeArg, resolveConfigPath, resolvePersonalConfigDir, } from '@deepseek-ai/dsh-app-boot' const NAME = 'dsh' +// The env var the shipped tui-agent config reads (`resumeSessionId: !!js +// process.env.RESUME_SESSION_ID`) to rehydrate a persisted session. The +// `--resume ` flag is CLI sugar that sets it before boot, so the printed +// `dsh --resume ` exit hint runs back through this same intake. +const RESUME_SESSION_ID_ENV = 'RESUME_SESSION_ID' + // Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit // one directory under apps/cli, so the shipped default config resolves with // the same relative hop from either artifact. @@ -38,7 +45,8 @@ const SOURCE_ROOT = fileURLToPath(new URL('../../..', import.meta.url)) the tui-agent PTY smoke drives this path end to end, personal overlay included */ /** * Run the interactive TUI from the invoking directory. - * @param argv - arguments after the subcommand dispatch; `argv[0]` may name a + * @param argv - arguments after the subcommand dispatch; a `--resume ` flag + * resumes that persisted session, and the first non-flag argument may name a * config to boot instead of the shipped default. */ export async function runTui(argv: string[]): Promise { @@ -53,7 +61,11 @@ export async function runTui(argv: string[]): Promise { // The bin already loaded the invoking directory's .env; the personal .env // only fills what is still unset (process.loadEnvFile never overrides). loadEnv(NAME, resolvePersonalConfigDir()) - const ctx = await boot(NAME, resolveConfigPath(argv[0] ?? DEFAULT_CONFIG, undefined), loadPersonalPatches(NAME)) + // An explicit `--resume` flag beats any ambient RESUME_SESSION_ID, so set it + // after loadEnv and before boot reads it through the config's `!!js`. + const { resumeSessionId, rest } = parseResumeArg(argv) + if (resumeSessionId !== undefined) process.env[RESUME_SESSION_ID_ENV] = resumeSessionId + const ctx = await boot(NAME, resolveConfigPath(rest[0] ?? DEFAULT_CONFIG, undefined), loadPersonalPatches(NAME)) addHarnessSourceSection(ctx, SOURCE_ROOT) } /* v8 ignore stop */ diff --git a/packages/ui/app-boot/tests/app-boot.spec.ts b/packages/ui/app-boot/tests/app-boot.spec.ts index d9934cb8bb..fef17b5b07 100644 --- a/packages/ui/app-boot/tests/app-boot.spec.ts +++ b/packages/ui/app-boot/tests/app-boot.spec.ts @@ -6,7 +6,7 @@ import { Context } from 'cordis' import SystemPrompt, { renderPrompt } from '@deepseek-ai/dsh-system-prompt' import { addHarnessSourceSection, assertEntriesLoaded, boot, HARNESS_SOURCE_SECTION, - installFailLoud, loadEnv, resolveConfigPath, type FailLoudProcess, + installFailLoud, loadEnv, parseResumeArg, resolveConfigPath, type FailLoudProcess, } from '../src/index.ts' const NAME = 'dsh-test-bin' @@ -30,6 +30,26 @@ describe('resolveConfigPath', () => { }) }) +describe('parseResumeArg', () => { + it('returns no resume id and passes arguments through when the flag is absent', () => { + expect(parseResumeArg([])).toEqual({ resumeSessionId: undefined, rest: [] }) + expect(parseResumeArg(['custom.yml'])).toEqual({ resumeSessionId: undefined, rest: ['custom.yml'] }) + }) + + it('parses the space form, the inline form, and leaves a positional config path in any position', () => { + expect(parseResumeArg(['--resume', 'sess-1'])).toEqual({ resumeSessionId: 'sess-1', rest: [] }) + expect(parseResumeArg(['--resume=sess-2'])).toEqual({ resumeSessionId: 'sess-2', rest: [] }) + expect(parseResumeArg(['--resume', 'sess-3', 'app.yml'])).toEqual({ resumeSessionId: 'sess-3', rest: ['app.yml'] }) + expect(parseResumeArg(['app.yml', '--resume', 'sess-4'])).toEqual({ resumeSessionId: 'sess-4', rest: ['app.yml'] }) + }) + + it('fails loud on a valueless, empty, or repeated flag rather than silently starting fresh', () => { + expect(() => parseResumeArg(['--resume'])).toThrow('--resume requires a session id') + expect(() => parseResumeArg(['--resume='])).toThrow('--resume requires a session id') + expect(() => parseResumeArg(['--resume', 'a', '--resume', 'b'])).toThrow('--resume may be given only once') + }) +}) + describe('loadEnv', () => { it('loads variables from .env in the given dir', () => { const dir = tmp() diff --git a/packages/ui/tui/package.json b/packages/ui/tui/package.json index cb34aa6367..38c05a3d6f 100644 --- a/packages/ui/tui/package.json +++ b/packages/ui/tui/package.json @@ -34,13 +34,23 @@ "@deepseek-ai/dsh-llm": "^0.0.1", "@deepseek-ai/dsh-llm-retry": "^0.0.1", "@deepseek-ai/dsh-session": "^0.0.1", + "@deepseek-ai/dsh-session-persistence": "^0.0.1", "@deepseek-ai/dsh-session-title": "^0.0.1", + "@deepseek-ai/dsh-skill": "^0.0.1", "@deepseek-ai/dsh-system-prompt": "^0.0.1", "@deepseek-ai/dsh-token-meter": "^0.0.1", "@deepseek-ai/dsh-tools": "^0.0.1", "@deepseek-ai/dsh-user-interaction": "^0.0.1", "cordis": "^4.0.0-rc.7" }, + "peerDependenciesMeta": { + "@deepseek-ai/dsh-session-persistence": { + "optional": true + }, + "@deepseek-ai/dsh-skill": { + "optional": true + } + }, "dependencies": { "@earendil-works/pi-tui": "0.80.7", "schemastery": "^3.18.0" @@ -54,7 +64,9 @@ "@deepseek-ai/dsh-llm": "workspace:^", "@deepseek-ai/dsh-llm-retry": "workspace:^", "@deepseek-ai/dsh-session": "workspace:^", + "@deepseek-ai/dsh-session-persistence": "workspace:^", "@deepseek-ai/dsh-session-title": "workspace:^", + "@deepseek-ai/dsh-skill": "workspace:^", "@deepseek-ai/dsh-system-prompt": "workspace:^", "@deepseek-ai/dsh-token-meter": "workspace:^", "@deepseek-ai/dsh-tool-cordis": "workspace:^", diff --git a/packages/ui/tui/tests/snapshots/resume-sessions.expected.txt b/packages/ui/tui/tests/snapshots/resume-sessions.expected.txt new file mode 100644 index 0000000000..6e44fa8165 --- /dev/null +++ b/packages/ui/tui/tests/snapshots/resume-sessions.expected.txt @@ -0,0 +1,28 @@ +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=9 bufferRow=9 +buffer +0| +1| " Snapshot agent ready. " + style 1-21 fg=bright-black +2| +3| " Resumable sessions " + style 1-18 fg=bright-blue bold +4| " 2024-01-02 03:04 (current) " + style 1-16 fg=bright-black + style 17-26 fg=green +5| " RESUME_SESSION_ID=main-session dsh " +6| " 2024-01-01 00:00 " + style 1-16 fg=bright-black +7| " RESUME_SESSION_ID=earlier-session dsh " +8| "────────────────────────────────────────────────────────────────────────────────────────────" + style 0-91 dim +9| " " + style 1-1 inverse +10| "────────────────────────────────────────────────────────────────────────────────────────────" + style 0-91 dim +11| "deepseek-v4-flash /workspace/project ↑0 ↓0 tools:collapsed" + style 0-43 dim + style 77-91 dim +12-31| diff --git a/packages/ui/tui/tests/tui.snapshot.ts b/packages/ui/tui/tests/tui.snapshot.ts index 54d703d4a8..d706ede1d9 100644 --- a/packages/ui/tui/tests/tui.snapshot.ts +++ b/packages/ui/tui/tests/tui.snapshot.ts @@ -7,6 +7,7 @@ import { agentEvents } from '@deepseek-ai/dsh-agent' import { CallId, type ContentBlock } from '@deepseek-ai/dsh-llm' import type {} from '@deepseek-ai/dsh-llm-retry' import type { Session } from '@deepseek-ai/dsh-session' +import { SessionId } from '@deepseek-ai/dsh-session' import SystemPrompt from '@deepseek-ai/dsh-system-prompt' import ToolRegistry, { type ToolDefinition, type ToolResultView } from '@deepseek-ai/dsh-tools' import * as ToolCordis from '@deepseek-ai/dsh-tool-cordis' @@ -30,6 +31,7 @@ const CHECKPOINTS = [ 'retry-recovered', 'retry-cancelled', 'retry-exhausted', + 'banner-gradient', 'code-mode-pending', 'dynamic-workflow-pending', 'cordis-tools-pending', @@ -45,6 +47,7 @@ const CHECKPOINTS = [ 'model-switching', 'errors-and-help', 'disposed-terminal', + 'resume-sessions', ] as const type Checkpoint = typeof CHECKPOINTS[number] @@ -56,9 +59,23 @@ async function checkpoint( name: Checkpoint, terminal: HeadlessTerminal, options: TerminalSnapshotOptions = {}, + bannerGradient = false, ): Promise { observedCheckpoints.add(name) - expect(terminal.themeViolations(), `${name} must remain theme-agnostic`).toEqual([]) + const violations = terminal.themeViolations() + if (bannerGradient) { + // The banner paints its product name in the DeepSeek brand gradient with + // 24-bit foreground codes: the sole sanctioned truecolor. Require it to be + // present and to never leak a background or extended-palette color into the + // otherwise theme-agnostic UI. + expect(violations, `${name} must render the banner gradient`).not.toEqual([]) + expect( + violations.every(entry => entry.endsWith('rgb-fg')), + `${name} must confine truecolor to the banner foreground`, + ).toBe(true) + } else { + expect(violations, `${name} must remain theme-agnostic`).toEqual([]) + } const snapshot = await terminal.snapshot(options) const path = join(SNAPSHOTS_DIR, `${name}.expected.txt`) if (REFRESHING) { @@ -308,6 +325,12 @@ describe('TUI terminal-state snapshots', () => { await disposeSnapshot(harness) }) + it('paints the startup banner product name in the DeepSeek brand gradient on truecolor terminals', async () => { + const harness = await setupSnapshot({ config: { truecolor: true } }) + await checkpoint('banner-gradient', harness.terminal, {}, true) + await disposeSnapshot(harness) + }) + it('pins Code Mode run_code with its production presenter', async () => { const harness = await setupSnapshot({ configureContext: configureAdvancedTools }) const call = { @@ -596,6 +619,24 @@ describe('TUI terminal-state snapshots', () => { await checkpoint('model-switching', harness.terminal, { includeScrollback: true }) await disposeSnapshot(harness) }) + + it('lists this workspace\'s resumable sessions with their commands', async () => { + const harness = await setupSnapshot({ + config: { resumeCommand: 'RESUME_SESSION_ID={session} dsh' }, + sessionPersistence: { list: async () => [ + { version: 0, id: SessionId('main-session'), createdAt: Date.parse('2024-01-02T03:04:00Z'), cwd: '/workspace/project' }, + { version: 0, id: SessionId('earlier-session'), createdAt: Date.parse('2024-01-01T00:00:00Z'), cwd: '/workspace/project' }, + ] }, + }, { columns: 92, rows: 32 }) + harness.terminal.send('/resume') + harness.terminal.send('\r') + // `/resume` scans persistence asynchronously, so the listing renders a tick + // after submit (the unit suite waits the same way); settle, then flush. + await new Promise(resolve => setTimeout(resolve, 60)) + await harness.terminal.flush() + await checkpoint('resume-sessions', harness.terminal, { includeScrollback: true }) + await disposeSnapshot(harness) + }) }) afterAll(async () => { diff --git a/packages/ui/tui/tests/tui.spec.ts b/packages/ui/tui/tests/tui.spec.ts index af2676394d..00a8f25ab7 100644 --- a/packages/ui/tui/tests/tui.spec.ts +++ b/packages/ui/tui/tests/tui.spec.ts @@ -818,37 +818,6 @@ describe('pi-tui chat lifecycle and transcript', () => { await dispose(result) }) - it('shows the session cache hit rate in the footer and updates it live', async () => { - // Empty session: no input billed yet, so the cache segment is hidden. - // A cwd without "cache" in it keeps the negative assertion unambiguous. - const empty = await setup({ cwd: '/opt' }) - expect(empty.terminal.output).toContain('↑0 ↓0') - expect(empty.terminal.output).not.toContain('cache') - await dispose(empty) - - const result = await setup({ - beforeMount(session) { - // Cold call: 10 billed input tokens, none served from cache. - appendAssistant(session, [{ type: 'text', text: 'cold' }], { inputTokens: 10, outputTokens: 5 }) - }, - }) - expect(result.terminal.output).toContain('cache 0%') - - result.terminal.output = '' - // Warm call lands live: 5 uncached + 30 cache-read + 5 cache-write billed - // input, so 30 of the 50 total prompt tokens are hits → 60%. - appendAssistant(result.session, [{ type: 'text', text: 'warm' }], { - inputTokens: 5, - outputTokens: 5, - cacheReadTokens: 30, - cacheWriteTokens: 5, - }) - await tick() - expect(result.terminal.output).toContain('cache 60%') - expect(result.terminal.output).not.toContain('cache 0%') - await dispose(result) - }) - it('sends, steers, handles commands, global keys, and disposed-agent input', async () => { const result = await setup()