From 96a1749db6cc0c6912ce90204ac46cb01085e009 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 9 Sep 2026 16:52:42 +0800 Subject: [PATCH 01/14] fix(ptc): preserve literal braces in generated SDK prompts --- ...bles-and-tool-guidance-ownership.i18n.yaml | 4 +-- ...t-variables-and-tool-guidance-ownership.md | 8 ++--- ...ariables-and-tool-guidance-ownership.zh.md | 8 ++--- docs/config-catalog.i18n.yaml | 4 +-- docs/config-catalog.md | 2 +- docs/config-catalog.zh.md | 2 +- docs/subsystems/system-prompt.i18n.yaml | 4 +-- docs/subsystems/system-prompt.md | 4 ++- docs/subsystems/system-prompt.zh.md | 4 ++- packages/core/system-prompt/README.i18n.yaml | 4 +-- packages/core/system-prompt/README.md | 6 ++-- packages/core/system-prompt/README.zh.md | 6 ++-- packages/core/system-prompt/src/index.ts | 12 +++++-- .../system-prompt/tests/system-prompt.spec.ts | 14 ++++++++ packages/core/tools/README.i18n.yaml | 4 +-- packages/core/tools/README.md | 2 +- packages/core/tools/README.zh.md | 2 +- packages/core/tools/src/index.ts | 5 +-- .../core/tools/tests/fixtures/literal-sdk.ts | 20 ++++++++++++ packages/core/tools/tests/ptc.spec.ts | 32 ++++++++++++++++++- .../extensions/tool-cordis/src/api-catalog.ts | 4 +-- .../session/ptc-turn/cordis.snapshot.yml | 4 +++ snapshots/session/ptc-turn/cordis.yml | 4 +++ .../ptc-turn/system-prompt.expected.md | 5 +++ 24 files changed, 128 insertions(+), 36 deletions(-) create mode 100644 packages/core/tools/tests/fixtures/literal-sdk.ts diff --git a/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.i18n.yaml b/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.i18n.yaml index 611e38e8ba..57dba7f52b 100644 --- a/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.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 .agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.md -2026-07-05-prompt-variables-and-tool-guidance-ownership.md: 35bb7c6fabc85ae6f93bdbb67e13910eea627ca3 -2026-07-05-prompt-variables-and-tool-guidance-ownership.zh.md: 53d69cf45c02f6534334561b626d2c2ae6087c05 +2026-07-05-prompt-variables-and-tool-guidance-ownership.md: 8f5542cb09930e62fd1e26960166fbdd6d3f6745 +2026-07-05-prompt-variables-and-tool-guidance-ownership.zh.md: 348ae36cf6549d412adab1d3cdb5cc03f0badd01 diff --git a/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.md b/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.md index 35bb7c6fab..8f5542cb09 100644 --- a/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.md +++ b/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.md @@ -26,7 +26,7 @@ The assembled system prompt had four defects, all of one family: facts the harne ### Prompt variables -Plugins register `{{name}}` values through `ctx.systemPrompt.variable(name, provider)`. Assembly resolves them into the waterfall-visible variable map. Rendering rejects unknown own-property references, registered providers that return `undefined`, malformed complete references, and unbalanced references that still contain a closing `}}`; a lone unmatched `{{` remains prose, and substituted values are not rescanned. Registration rejects invalid or duplicate variable names, and section names are unique. +Plugins register `{{name}}` values through `ctx.systemPrompt.variable(name, provider)`. Assembly resolves them into the waterfall-visible variable map. Rendering rejects unknown own-property references, registered providers that return `undefined`, malformed complete references, and unbalanced references that still contain a closing `}}`; a lone unmatched `{{` remains prose, and substituted values are not rescanned. Registration rejects invalid or duplicate variable names, and section names are unique. Sections may set `interpolate: false` to preserve generated documents literally; `tools:sdk` does so because tool descriptions and schemas may document their own `{{…}}` syntax. `dsh-agent-loop` registers the two built-ins, both pure projections of the context agent: `model` (= `options.model`) and `cwd` (= `session.header.cwd`). The example personas write `powered by the {{model}} model` — the model name is stated once, in the `model:` config key. `{{cwd}}` is demonstrated in the ACP example only: every ACP session carries the client's cwd, while config-pre-created stdio agents have none (a persona claiming `{{cwd}}` there fails the turn — by design). The variables stay on the loop plugin (unlike the sections below): they are runtime facts of the agents THIS loop drives, and a replacement loop supplies its own. @@ -47,7 +47,7 @@ Per-tool semantics and selection guidance live in tool descriptions. Prompt sect - **The loop composes an identity line itself** — hardcodes model-facing prose in the one package that must stay thin ("plugins, not loop changes"), and outside the section pipeline it would be a second composition path. (The identity DOES ship as a code literal — but as an ordinary section registered by `dsh-system-prompt`, whose `system-prompt/assemble` waterfall remains the escape valve for a deployment that must drop it.) - **Inject the model name via the `agent/request` waterfall** — prompt text would be composed in two places and the earlier rendered persona could disagree with the final routed header. The request plugin that owns late routing must also own any earlier prompt claim about that model. - **Hand-write the model name in each persona** — duplicates the `model:` key one line above and silently lies after a config edit; the exact disease this decision cures. -- **Lenient interpolation (leave unknown refs verbatim, or substitute empty)** — a typo ships `{{modle}}` (or a hole) to the model and nobody notices until transcript review. +- **Lenient interpolation (leave unknown refs verbatim, or substitute empty)** — a typo ships `{{modle}}` (or a hole) to the model and nobody notices until transcript review. Leaving only unknown names unchanged would still substitute registered names inside tool documentation. - **Per-instance subagent wording in config** — returns model-facing prose to every deployment × instance, reviving the hand-written-guidance-in-leaf-YAML drift. **Keying wording off the provider NAME** — `providerName` is itself config, so a renamed provider silently gets the wrong words. - **Resolving the provider at `apply` time (a load-order requirement)** and **section-only subagent wording (lazily resolved at assemble)** — the alternatives to the provider-lifecycle events; both rejected in [the provider-lifecycle-events Agent Note](../../archived/architecture/2026-07-05-subagent-provider-lifecycle-events.md). @@ -60,7 +60,7 @@ Per-tool semantics and selection guidance live in tool descriptions. Prompt sect - The tui-agent prompt renders identity, persona with the interpolated model, then fs/shell/web guidance through one assembly path. - Fork and fresh subagent descriptions reflect whether the provider inherits completed conversation turns; the tool appears, disappears, and is reworded with provider lifecycle changes. -- Unknown, valueless, malformed, or unbalanced variable references name the section and throw; duplicate section, variable, and tool registrations also throw. +- In interpolated sections, unknown, valueless, malformed, or unbalanced variable references name the section and throw; duplicate section, variable, and tool registrations also throw. - Snapshot replay is prompt-independent: it keys recorded chunk streams by turn and step without comparing the outgoing request. ## Consequences @@ -69,4 +69,4 @@ Per-tool semantics and selection guidance live in tool descriptions. Prompt sect - `{{model}}` reflects `AgentOptions.model` at assembly time. A plugin that switches models in the `agent/request` waterfall makes the prompt's claim stale for that step, and one that SUPPLIES the model there (options.model unset — the loop's documented fallback) leaves the variable valueless at render, failing a `{{model}}` persona before the waterfall runs. Both have the same remedy, and it is the ownership rule itself: the plugin that owns the late-bound model fact states it early on the `system-prompt/assemble` waterfall (`assembly.variables['model'] = …`) — one owner, both statements; a loop test pins the supply path end-to-end. Accepted. - While a bound provider is absent (not yet activated, unloaded, mid-HMR-reload), the subagent tool does not exist and a model request in that window simply lacks it. That is the honest state — the alternative was a registered tool whose description or execution could not be trusted. - Strictness means a persona can fail a turn at render (e.g. `{{cwd}}` on a cwd-less session). The failure is contained — the turn ends `error`, the loop survives — and it is an authoring error we WANT loud. -- No escape syntax for a literal `{{name}}` in prompt prose yet; add one if a real prompt ever needs it. +- Inline escapes remain unsupported in interpolated text; literal sections need no escaping. PTC unit tests cover both modes and runtime languages, and the recorded `ptc-turn` scenario preserves tool-template examples in the model-visible prompt. diff --git a/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.zh.md b/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.zh.md index 53d69cf45c..348ae36cf6 100644 --- a/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.zh.md +++ b/.agents/notes/implemented/architecture/2026-07-05-prompt-variables-and-tool-guidance-ownership.zh.md @@ -26,7 +26,7 @@ Status: implemented ### 提示词变量 -插件通过 `ctx.systemPrompt.variable(name, provider)` 注册 `{{name}}` 值。组装过程将它们解析到 waterfall 可见的变量映射中。渲染阶段拒绝以下情况:引用未知的自有属性、已注册的提供方返回 `undefined`、格式错误的完整引用、以及仍包含闭合 `}}` 的不平衡引用;孤立的未匹配 `{{` 保留为行文,替换后的值不会被重新扫描。注册阶段拒绝无效或重复的变量名,section 名称也必须唯一。 +插件通过 `ctx.systemPrompt.variable(name, provider)` 注册 `{{name}}` 值。组装过程将它们解析到 waterfall 可见的变量映射中。渲染阶段拒绝以下情况:引用未知的自有属性、已注册的提供方返回 `undefined`、格式错误的完整引用、以及仍包含闭合 `}}` 的不平衡引用;孤立的未匹配 `{{` 保留为行文,替换后的值不会被重新扫描。注册阶段拒绝无效或重复的变量名,section 名称也必须唯一。段可设置 `interpolate: false` 来原样保留生成的文档;`tools:sdk` 使用此设置,因为工具描述和 schema 可能会介绍自身的 `{{…}}` 语法。 `dsh-agent-loop` 注册两个内置变量,均为上下文 agent 的纯投影:`model`(= `options.model`)和 `cwd`(= `session.header.cwd`)。示例 persona 写 `powered by the {{model}} model`——模型名称只在 `model:` 配置键中声明一次。`{{cwd}}` 仅在 ACP 示例中演示:每个 ACP 会话携带客户端的 cwd,而配置预创建的 stdio agent 没有 cwd(在那里声称 `{{cwd}}` 的 persona 会导致该轮次失败——这是有意为之)。变量留在 loop 插件上(不同于下面的 section):它们是本循环驱动的 agent 的运行时事实,替换循环自行提供自己的变量。 @@ -47,7 +47,7 @@ Status: implemented - **循环自行组合一行 identity 文本**:在必须保持精简的那个包(「用插件,不改循环」)中硬编码面向模型的行文,且在 section 流水线之外构成第二条组合路径。(identity 确实以代码字面量交付——但作为 `dsh-system-prompt` 注册的普通 section,其 `system-prompt/assemble` waterfall 仍是部署需要移除它时的逃生阀。) - **通过 `agent/request` waterfall 注入模型名称**:提示词文本会在两处组合,更早渲染的 persona 也可能与最终已路由 header 不一致。拥有延迟路由的请求插件还必须拥有该模型在提示词中更早出现的声明。 - **在每个 persona 中手写模型名称**:与上方一行的 `model:` 键重复,配置修改后静默失实;正是本决策要治愈的病症。 -- **宽松插值(未知引用保留原样或替换为空)**:一个拼写错误 `{{modle}}`(或一个空洞)会被发送给模型,直到 transcript(文本记录)审查时才会被发现。 +- **宽松插值(未知引用保留原样或替换为空)**:一个拼写错误 `{{modle}}`(或一个空洞)会被发送给模型,直到 transcript(文本记录)审查时才会被发现。仅保留未知名称仍会替换工具文档中的已注册名称。 - **在配置中为每个 subagent 实例编写措辞**:面向模型的行文回到每个部署 × 实例中,重蹈在 leaf YAML 中手写指导的漂移。**根据提供方名称选择措辞**:`providerName` 本身是配置,重命名提供方后会静默获得错误的措辞。 - **在 `apply` 时解析提供方(加载顺序要求)**与**仅用 section 承载 subagent 措辞(在 assemble 时惰性解析)**:提供方生命周期事件的替代方案;两者均在[提供方生命周期事件 Agent Note](../../archived/architecture/2026-07-05-subagent-provider-lifecycle-events.md)中被否决。 @@ -60,7 +60,7 @@ Status: implemented - tui-agent 的提示词通过一条组装路径依次渲染 identity、带插值模型名的 persona,然后是 fs/shell/web 指导。 - fork 和 fresh subagent 的描述反映提供方是否继承已完成的对话轮次;工具随提供方生命周期变化而出现、消失和重新措辞。 -- 未知、无值、格式错误或不平衡的变量引用会指明 section 名称并抛出异常;重复的 section、变量和工具注册同样抛出异常。 +- 在启用插值的段中,未知、无值、格式错误或不平衡的变量引用会指明 section 名称并抛出异常;重复的 section、变量和工具注册同样抛出异常。 - 快照回放与提示词无关:它按轮次和步骤索引已记录的分片流,不比较发出的请求。 ## 后果 @@ -69,4 +69,4 @@ Status: implemented - `{{model}}` 在组装时反映 `AgentOptions.model`。如果一个插件在 `agent/request` waterfall 中切换模型,提示词对该步骤的声明就会过时;如果一个插件在那里提供模型(options.model 未设置——循环文档中记载的回退路径),变量在渲染时无值,包含 `{{model}}` 的 persona 会在 waterfall 运行前失败。两者的补救方式相同,就是归属规则本身:拥有延迟绑定模型事实的插件在 `system-prompt/assemble` waterfall 上提前声明它(`assembly.variables['model'] = …`)——一个归属方,两处声明;一个循环测试端到端固定了 supply 路径。已接受。 - 当一个已绑定的提供方不存在时(尚未激活、已卸载、HMR(热模块替换)重载中),subagent 工具不存在,该窗口内的模型请求中不会包含它。这是诚实的状态——替代方案是注册一个 description 或执行都不可信的工具。 - 严格性意味着 persona 可能在渲染时导致轮次失败(例如在无 cwd 的会话上使用 `{{cwd}}`)。失败是受控的——该轮次以 `error` 结束,循环存活——且这是一个我们希望明确暴露的撰写错误。 -- 目前没有在提示词行文中转义字面 `{{name}}` 的语法;如果真实提示词确实需要,再行添加。 +- 插值文本仍不支持行内转义;字面文本段无需转义。PTC 单元测试覆盖两种模式和运行时语言,录制的 `ptc-turn` 场景在模型可见的提示词中保留工具模板示例。 diff --git a/docs/config-catalog.i18n.yaml b/docs/config-catalog.i18n.yaml index 2f4b0e6e79..ebb600e7d4 100644 --- a/docs/config-catalog.i18n.yaml +++ b/docs/config-catalog.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 docs/config-catalog.md -config-catalog.md: 4e92bbfcf4bcf190b9b17436eefc3255dda9132a -config-catalog.zh.md: df4b107f28040962f38802a77f8b91c47ad2931d +config-catalog.md: fd6f249775957f0c6ce74526ba98f5b461af548d +config-catalog.zh.md: 22aa87aa64eac626304a28227e172aa6952b087f diff --git a/docs/config-catalog.md b/docs/config-catalog.md index 4e92bbfcf4..fd6f249775 100644 --- a/docs/config-catalog.md +++ b/docs/config-catalog.md @@ -2607,7 +2607,7 @@ export interface Config { } ``` -Source: [`packages/core/system-prompt/src/index.ts:242`](../packages/core/system-prompt/src/index.ts) +Source: [`packages/core/system-prompt/src/index.ts:246`](../packages/core/system-prompt/src/index.ts) diff --git a/docs/config-catalog.zh.md b/docs/config-catalog.zh.md index df4b107f28..22aa87aa64 100644 --- a/docs/config-catalog.zh.md +++ b/docs/config-catalog.zh.md @@ -2609,7 +2609,7 @@ export interface Config { } ``` -来源:[`packages/core/system-prompt/src/index.ts:242`](../packages/core/system-prompt/src/index.ts) +来源:[`packages/core/system-prompt/src/index.ts:246`](../packages/core/system-prompt/src/index.ts) diff --git a/docs/subsystems/system-prompt.i18n.yaml b/docs/subsystems/system-prompt.i18n.yaml index 96577399bd..c4fb972a1d 100644 --- a/docs/subsystems/system-prompt.i18n.yaml +++ b/docs/subsystems/system-prompt.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 docs/subsystems/system-prompt.md -system-prompt.md: 516e3347c06882bfd3ff42638d77a2acb3aca753 -system-prompt.zh.md: 611ea0e9bdd81585efd7106012edd3d17e7bdd8e +system-prompt.md: 898520e8fc88a9fafd8429723fc48bad3b4ba210 +system-prompt.zh.md: 82e557a309a48f546d7c7fa5a8c1097152b4d145 diff --git a/docs/subsystems/system-prompt.md b/docs/subsystems/system-prompt.md index 516e3347c0..898520e8fc 100644 --- a/docs/subsystems/system-prompt.md +++ b/docs/subsystems/system-prompt.md @@ -56,9 +56,11 @@ interface PromptSection { /** * Static text or a provider evaluated at each assembly with that assembly's * {@link AssembleContext}. The text may reference `{{variable}}`s — they are - * interpolated later, by {@link renderPrompt}. + * interpolated later, by {@link renderPrompt}, unless `interpolate` is false. */ readonly text: string | ((context: AssembleContext) => string) + /** Whether to interpolate prompt variables. Defaults to true; false preserves literal text. */ + readonly interpolate?: boolean /** * Treat this contribution as the complete system prompt. Assembly still * runs the cooperative waterfall so tools, contexts, and variables can be diff --git a/docs/subsystems/system-prompt.zh.md b/docs/subsystems/system-prompt.zh.md index 611ea0e9bd..82e557a309 100644 --- a/docs/subsystems/system-prompt.zh.md +++ b/docs/subsystems/system-prompt.zh.md @@ -56,9 +56,11 @@ interface PromptSection { /** * Static text or a provider evaluated at each assembly with that assembly's * {@link AssembleContext}. The text may reference `{{variable}}`s — they are - * interpolated later, by {@link renderPrompt}. + * interpolated later, by {@link renderPrompt}, unless `interpolate` is false. */ readonly text: string | ((context: AssembleContext) => string) + /** Whether to interpolate prompt variables. Defaults to true; false preserves literal text. */ + readonly interpolate?: boolean /** * Treat this contribution as the complete system prompt. Assembly still * runs the cooperative waterfall so tools, contexts, and variables can be diff --git a/packages/core/system-prompt/README.i18n.yaml b/packages/core/system-prompt/README.i18n.yaml index afa3965820..0190a5a339 100644 --- a/packages/core/system-prompt/README.i18n.yaml +++ b/packages/core/system-prompt/README.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 packages/core/system-prompt/README.md -README.md: e98c1be171d7dbb16cabf1289a20be8922e5076b -README.zh.md: 2408ec1dbb730bd5f085f3467a5359f5900efebc +README.md: 9be48304c0ecdbcfa4b73a753d5565a60882038c +README.zh.md: 416eb6feb3d423c61e911b29c21ad8e0013c5e43 diff --git a/packages/core/system-prompt/README.md b/packages/core/system-prompt/README.md index e98c1be171..9be48304c0 100644 --- a/packages/core/system-prompt/README.md +++ b/packages/core/system-prompt/README.md @@ -63,6 +63,8 @@ ctx.systemPrompt.section({ }) ``` +Set `interpolate: false` on a section to preserve its text literally, including `{{…}}` groups in generated tool documentation. Other sections interpolate variables by default. + ### Contribute a prompt variable Variables are referenced from section text as `{{name}}` and resolved at each assembly; scoped variables shadow a same-named global for that agent. The loop supplies `model` and `cwd`; any plugin can register the facts it owns. @@ -102,7 +104,7 @@ The package is a registry plus a cooperative assembly pipeline. One `assemble()` ### Assembly and rendering -Assembly resolves and renders in two stages: `assemble()` returns sections with resolved-but-uninterpolated text, the ordered tool schemas, and every registered variable resolved against the context, while `renderPrompt()` interpolates `{{variable}}` references, drops empty sections, and joins with blank lines — strictly, an unknown reference, a registered-but-valueless reference, or a malformed complete group throws, because a malformed prompt is worse than a loud failure. `toolOrder` canonicalizes the collected tools before the waterfall (registration order is a plugin-load artifact); a waterfall listener that mutates the list owns the determinism of what it emits. +Assembly resolves and renders in two stages: `assemble()` returns sections with resolved-but-uninterpolated text, the ordered tool schemas, and every registered variable resolved against the context, while `renderPrompt()` interpolates `{{variable}}` references unless a section sets `interpolate: false`, drops empty sections, and joins with blank lines — strictly, an unknown reference, a registered-but-valueless reference, or a malformed complete group throws, because a malformed prompt is worse than a loud failure. `toolOrder` canonicalizes the collected tools before the waterfall (registration order is a plugin-load artifact); a waterfall listener that mutates the list owns the determinism of what it emits. ### Scoping @@ -170,7 +172,7 @@ Prefix-stable while the visible schema set, rendering, and order are unchanged. These limits define when prompt assembly needs special care. They are current package constraints, not a task backlog. - **Deployment-authored prompt text is config/composition only** — this plugin owns the global persona prefix and suffix defaults, creator plugins may register agent-scoped shadows, and other sections come from the plugin that owns the fact; there is no end-user prompt-editing API. -- **No escape syntax for literal `{{…}}` braces** — every complete group is interpolated against registered variables; an escape is deferred until a real prompt needs one. +- **No inline escape syntax in interpolated text** — use `interpolate: false` when a whole section must preserve literal braces. - **`toolOrder` misconfiguration surfaces at prompt assembly (the first turn), not at boot** — only shape violations throw at config load. diff --git a/packages/core/system-prompt/README.zh.md b/packages/core/system-prompt/README.zh.md index 2408ec1dbb..416eb6feb3 100644 --- a/packages/core/system-prompt/README.zh.md +++ b/packages/core/system-prompt/README.zh.md @@ -63,6 +63,8 @@ ctx.systemPrompt.section({ }) ``` +在段上设置 `interpolate: false` 可原样保留文本,包括生成的工具文档中的 `{{…}}` 组。其他段默认执行变量插值。 + ### 贡献提示词变量 变量在段文本中以 `{{name}}` 引用,并在每次组装时解析;带作用域变量会为该 agent 遮蔽同名全局变量。循环提供 `model` 与 `cwd`;任何插件都可以注册自己拥有的事实。 @@ -102,7 +104,7 @@ ctx.systemPrompt.variable('cwd', ({ agent }) => agent?.session.header.cwd) ### 组装与渲染 -组装分两阶段完成求值与渲染:`assemble()` 返回文本已求值但尚未插值的段、有序工具 schema,以及每个已注册变量按当前上下文求得的值;`renderPrompt()` 插值 `{{variable}}` 引用、删除空段并用空行连接——严格规则:未知引用、已注册但无值的引用或格式错误的完整组都会抛出,因为格式错误的提示词比明确失败更糟。`toolOrder` 在 waterfall(瀑布式事件)之前规范化收集到的工具(注册顺序只是插件加载产物);修改列表的 waterfall 监听器对其输出的确定性负责。 +组装分两阶段完成求值与渲染:`assemble()` 返回文本已求值但尚未插值的段、有序工具 schema,以及每个已注册变量按当前上下文求得的值;`renderPrompt()` 对未设置 `interpolate: false` 的段插值 `{{variable}}` 引用、删除空段并用空行连接——严格规则:未知引用、已注册但无值的引用或格式错误的完整组都会抛出,因为格式错误的提示词比明确失败更糟。`toolOrder` 在 waterfall(瀑布式事件)之前规范化收集到的工具(注册顺序只是插件加载产物);修改列表的 waterfall 监听器对其输出的确定性负责。 ### 作用域 @@ -170,7 +172,7 @@ schema token 在每次请求中重复。限制工具会为该 agent 移除其全 这些限制说明提示词组装何时需要特别留意。它们是当前包约束,不是任务积压。 - **部署方编写的提示词文本只来自配置/组合**:此插件拥有全局 persona 前缀与后缀默认值;创建方插件可以注册 agent 作用域的遮蔽项;其他段来自拥有相应事实的插件。不存在终端用户提示词编辑 API。 -- **没有表示字面量 `{{…}}` 花括号的转义语法**:每个完整组都会按已注册变量插值;只有实际提示词需要转义时才会实现。 +- **插值文本不支持行内转义语法**:整段需要保留字面花括号时,使用 `interpolate: false`。 - **`toolOrder` 配置错误在提示词组装(首轮)时出现,而不是启动时**:只有形状违规会在配置加载时抛出。 diff --git a/packages/core/system-prompt/src/index.ts b/packages/core/system-prompt/src/index.ts index d83cc4d216..0d056ec1fc 100644 --- a/packages/core/system-prompt/src/index.ts +++ b/packages/core/system-prompt/src/index.ts @@ -61,9 +61,11 @@ export interface PromptSection { /** * Static text or a provider evaluated at each assembly with that assembly's * {@link AssembleContext}. The text may reference `{{variable}}`s — they are - * interpolated later, by {@link renderPrompt}. + * interpolated later, by {@link renderPrompt}, unless `interpolate` is false. */ readonly text: string | ((context: AssembleContext) => string) + /** Whether to interpolate prompt variables. Defaults to true; false preserves literal text. */ + readonly interpolate?: boolean /** * Treat this contribution as the complete system prompt. Assembly still * runs the cooperative waterfall so tools, contexts, and variables can be @@ -89,6 +91,8 @@ export interface AssembledSection { name: string /** The resolved (but not yet interpolated) section text. */ text: string + /** Whether to interpolate prompt variables. Defaults to true; false preserves literal text. */ + interpolate?: boolean } /** One resolved dynamic context contribution. */ @@ -264,7 +268,8 @@ export interface Config { /** * Interpolate strict `{{variable}}` references, drop empty sections, and join - * the rest with blank lines. Malformed, unknown, or undefined references throw; + * the rest with blank lines. Sections with `interpolate: false` retain literal + * text. Malformed, unknown, or undefined references in other sections throw; * a lone `{{` without any later `}}` is literal prose, and substituted values * are not scanned again. * @param assembly - the assembly whose sections and variables to render. @@ -272,7 +277,7 @@ export interface Config { */ export function renderPrompt(assembly: PromptAssembly): string { return assembly.sections - .map(section => interpolate(section, assembly.variables, 'section')) + .map(section => section.interpolate === false ? section.text : interpolate(section, assembly.variables, 'section')) .filter(text => text.length > 0) .join('\n\n') } @@ -597,6 +602,7 @@ export class SystemPrompt extends Service { const assembled = { name: section.name, text: typeof section.text === 'function' ? section.text(context) : section.text, + ...section.interpolate !== undefined ? { interpolate: section.interpolate } : {}, } if (section.complete === true) completeSection = { ...assembled } return assembled diff --git a/packages/core/system-prompt/tests/system-prompt.spec.ts b/packages/core/system-prompt/tests/system-prompt.spec.ts index 8e60ea2bec..3294c3179d 100644 --- a/packages/core/system-prompt/tests/system-prompt.spec.ts +++ b/packages/core/system-prompt/tests/system-prompt.spec.ts @@ -579,6 +579,20 @@ describe('SystemPrompt', () => { expect(renderPrompt(await ctx.systemPrompt.assemble())).toBe(`${IDENTITY}\n\nYou run on deepseek-v4 in /work.`) }) + it.each([false, true])('preserves literal section text with complete=%s', async (complete) => { + const ctx = new Context() + try { + await ctx.plugin(SystemPrompt, { includeHarnessIdentity: false, personaPrefix: '{{model}}' }) + ctx.systemPrompt.variable('model', () => 'actual-model') + const text = '{{item}} {{model}} {{ model }} {{nested{{item}}}}' + ctx.systemPrompt.section({ name: 'literal', order: 1, text: () => text, interpolate: false, complete }) + expect(renderPrompt(await ctx.systemPrompt.assemble())) + .toBe(complete ? text : `actual-model\n\n${text}`) + } finally { + await ctx.fiber.dispose() + } + }) + it('lets a waterfall listener add or override variables before render', async () => { const ctx = new Context() await ctx.plugin(SystemPrompt) diff --git a/packages/core/tools/README.i18n.yaml b/packages/core/tools/README.i18n.yaml index ddeec40191..b6933fd01f 100644 --- a/packages/core/tools/README.i18n.yaml +++ b/packages/core/tools/README.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 packages/core/tools/README.md -README.md: 725e3e1a6a0a977e2e917561c61951a670a71ee4 -README.zh.md: 118849a2e58007cff694dcd07ab7b38b850d2a9e +README.md: 6c5d42bd7597d4f7715b50c71126bd645352dcff +README.zh.md: 6dff796455974f84b6a2facd6fb464976692be4b diff --git a/packages/core/tools/README.md b/packages/core/tools/README.md index 725e3e1a6a..6c5d42bd75 100644 --- a/packages/core/tools/README.md +++ b/packages/core/tools/README.md @@ -170,7 +170,7 @@ Prefix-stable while visible definitions and their order are unchanged. Registrat #### What the model sees -PTC mode exposes the generated [`run_code` schema](../../../docs/tool-catalog.md#deepseek-aidsh-tools), the SDK instructions below, and the generated exact SDK block for the loaded runtime's language. The TypeScript instructions identify generated declarations as program-only bindings. When the current `bash` parameter schema accepts the example arguments, they also show a complete `run_code` call around `tools.bash(...)`. The `tools:sdk` section uses first-party order 5000. `both` exposes normal schemas and this PTC mode API; under `ptc` the prompt also carries the `tools:ptc-only` rule earlier in the first-party order, so the model reads which tools it may call before it reads what each one is for. +PTC mode exposes the generated [`run_code` schema](../../../docs/tool-catalog.md#deepseek-aidsh-tools), the SDK instructions below, and the generated exact SDK block for the loaded runtime's language. The TypeScript instructions identify generated declarations as program-only bindings. When the current `bash` parameter schema accepts the example arguments, they also show a complete `run_code` call around `tools.bash(...)`. The `tools:sdk` section uses first-party order 5000 and disables prompt-variable interpolation, preserving literal `{{…}}` text in tool descriptions and schemas for both runtime languages. `both` exposes normal schemas and this PTC mode API; under `ptc` the prompt also carries the `tools:ptc-only` rule earlier in the first-party order, so the model reads which tools it may call before it reads what each one is for. ##### TypeScript PTC mode SDK instructions with bash diff --git a/packages/core/tools/README.zh.md b/packages/core/tools/README.zh.md index 118849a2e5..6dff796455 100644 --- a/packages/core/tools/README.zh.md +++ b/packages/core/tools/README.zh.md @@ -170,7 +170,7 @@ ctx.tools.register(defineTool({ #### 模型看到什么 -PTC mode 会公开生成的 [`run_code` schema](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tools)、下方 SDK 说明,以及按所加载运行时语言生成的精确 SDK 块。TypeScript 说明会把生成声明明确标为只能在程序内使用的绑定。当当前 `bash` 参数 schema 接受示例参数时,说明还会给出以 `run_code` 包住 `tools.bash(...)` 的完整调用。`tools:sdk` 段使用 first-party 顺序 5000。`both` 会同时公开普通 schema 与此 PTC mode API;在 `ptc` 下,提示词还会带上处于更早 first-party 顺序的 `tools:ptc-only` 规则,让模型先读到「可以调用哪些工具」再读「每个工具做什么」。 +PTC mode 会公开生成的 [`run_code` schema](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tools)、下方 SDK 说明,以及按所加载运行时语言生成的精确 SDK 块。TypeScript 说明会把生成声明明确标为只能在程序内使用的绑定。当当前 `bash` 参数 schema 接受示例参数时,说明还会给出以 `run_code` 包住 `tools.bash(...)` 的完整调用。`tools:sdk` 段使用 first-party 顺序 5000,并关闭提示词变量插值,使两种运行时语言都原样保留工具描述和 schema 中的 `{{…}}` 文本。`both` 会同时公开普通 schema 与此 PTC mode API;在 `ptc` 下,提示词还会带上处于更早 first-party 顺序的 `tools:ptc-only` 规则,让模型先读到「可以调用哪些工具」再读「每个工具做什么」。 ##### 带 bash 的 TypeScript PTC mode SDK 说明 diff --git a/packages/core/tools/src/index.ts b/packages/core/tools/src/index.ts index bef11baf26..b4d1a2a805 100644 --- a/packages/core/tools/src/index.ts +++ b/packages/core/tools/src/index.ts @@ -13,7 +13,7 @@ import { HarnessError } from '@deepseek-ai/dsh-llm' import type { Agent } from '@deepseek-ai/dsh-agent' import type { UserMessage } from '@deepseek-ai/dsh-session' import { assertNever, deepFreeze, snapshotJsonValue, type JsonValue } from '@deepseek-ai/dsh-util-values' -import type { ToolProviderResult } from '@deepseek-ai/dsh-system-prompt' +import type { PromptSection, ToolProviderResult } from '@deepseek-ai/dsh-system-prompt' import type { CodeRuntime } from '@deepseek-ai/dsh-code-runtime' // Type-only: makes `ctx.get('approval')` resolve to the ApprovalService // augmentation. The seam stays optional at runtime — see `serviceAsk`. @@ -864,10 +864,11 @@ export class ToolRuntime extends Service { * dropped from the rendered prompt. * @returns the section registration. */ - private sdkSection(): { name: string; order: number; text: (context: { scope?: ScopeKey }) => string } { + private sdkSection(): PromptSection { return { name: 'tools:sdk', order: this.ctx.systemPrompt.getSectionOrder('TOOLS_SDK'), + interpolate: false, // Regenerate from the calling scope's visible tools in stable order. text: (context) => { const mode = this.modeFor(context.scope) diff --git a/packages/core/tools/tests/fixtures/literal-sdk.ts b/packages/core/tools/tests/fixtures/literal-sdk.ts new file mode 100644 index 0000000000..4f0206456f --- /dev/null +++ b/packages/core/tools/tests/fixtures/literal-sdk.ts @@ -0,0 +1,20 @@ +/** Tool documentation containing literal template syntax for recorded PTC replay. */ + +import type { Context } from '@deepseek-ai/cordis' +import { defineTool } from '@deepseek-ai/dsh-tools' + +export const name = 'literal-sdk' +export const inject = ['tools'] + +export function apply(ctx: Context): void { + ctx.tools.register(defineTool({ + name: 'template_echo', + description: 'Echo template text such as {{item}}, {{model}}, or {{ item }} without substitution.', + parameters: { text: { type: 'string', required: true } }, + output: { + schema: { type: 'string' }, + render: (_args, value) => [{ type: 'text', text: value }], + }, + execute: args => Promise.resolve(args.text), + })) +} diff --git a/packages/core/tools/tests/ptc.spec.ts b/packages/core/tools/tests/ptc.spec.ts index 11bf14e01a..cfb651283e 100644 --- a/packages/core/tools/tests/ptc.spec.ts +++ b/packages/core/tools/tests/ptc.spec.ts @@ -3,7 +3,7 @@ import { Context } from '@deepseek-ai/cordis' import { createUserMessage, ToolCallId } from '@deepseek-ai/dsh-llm' import { createScope } from '@deepseek-ai/dsh-scope' import type { Scope } from '@deepseek-ai/dsh-scope' -import SystemPrompt from '@deepseek-ai/dsh-system-prompt' +import SystemPrompt, { renderPrompt } from '@deepseek-ai/dsh-system-prompt' import { CodeRuntime } from '@deepseek-ai/dsh-code-runtime' import type { CodeRunRequest, CodeRunResult } from '@deepseek-ai/dsh-code-runtime' import ToolRuntime, { CodeRunFailedError, RUN_CODE_NAME, TOOL_ABORTED_BEFORE_DISPATCH, defineContentToolFixture, defineTool } from '@deepseek-ai/dsh-tools' @@ -117,6 +117,36 @@ async function runCode( } describe('mode-aware wire contribution', () => { + it.each([ + { mode: 'ptc', language: 'typescript' }, + { mode: 'both', language: 'typescript' }, + { mode: 'ptc', language: 'python' }, + { mode: 'both', language: 'python' }, + ] as const)('preserves literal braces in the $language SDK under $mode', async ({ mode, language }) => { + const { ctx, systemPrompt } = await setup({ mode, runtime: { language } }) + try { + systemPrompt.variable('model', () => 'actual-model') + const description = 'Expand {{item}} with {{model}} or {{ model }}.' + ctx.tools.register(defineTool({ + name: 'template', + description, + parameters: { value: { type: 'string', description, enum: ['{{item}}', '{{model}}'], required: true } }, + output: { + schema: { type: 'string', enum: ['{{item}}', '{{model}}'] }, + render: (_args, value) => [{ type: 'text', text: value }], + }, + execute: args => Promise.resolve(args.value), + })) + const assembly = await systemPrompt.assemble() + const prompt = renderPrompt(assembly) + expect(prompt).toContain(description) + expect(prompt).toContain(assembly.sections.find(section => section.name === 'tools:sdk')?.text) + expect(prompt).not.toContain('actual-model') + } finally { + await ctx.fiber.dispose() + } + }) + it("mode 'native' contributes every schema, no run_code, no SDK section — and needs no runtime", async () => { const { ctx, systemPrompt } = await setup({ mode: 'native', runtime: false }) registerEcho(ctx) diff --git a/packages/extensions/tool-cordis/src/api-catalog.ts b/packages/extensions/tool-cordis/src/api-catalog.ts index 4606b99848..39cfe12a54 100644 --- a/packages/extensions/tool-cordis/src/api-catalog.ts +++ b/packages/extensions/tool-cordis/src/api-catalog.ts @@ -3698,7 +3698,7 @@ export const TYPE_API: readonly TypeApiEntry[] = [ }, { name: 'AssembledSection', - declaration: 'export interface AssembledSection {\n name: string;\n text: string;\n}', + declaration: 'export interface AssembledSection {\n name: string;\n text: string;\n interpolate?: boolean;\n}', }, { name: 'AssistantMessage', @@ -4830,7 +4830,7 @@ export const TYPE_API: readonly TypeApiEntry[] = [ }, { name: 'PromptSection', - declaration: 'export interface PromptSection {\n readonly name: string;\n readonly order: number;\n readonly text: string | ((context: AssembleContext) => string);\n readonly complete?: boolean;\n}', + declaration: 'export interface PromptSection {\n readonly name: string;\n readonly order: number;\n readonly text: string | ((context: AssembleContext) => string);\n readonly interpolate?: boolean;\n readonly complete?: boolean;\n}', }, { name: 'PromptSectionOrderName', diff --git a/snapshots/session/ptc-turn/cordis.snapshot.yml b/snapshots/session/ptc-turn/cordis.snapshot.yml index 5ef66b0f1e..72ac169e3c 100644 --- a/snapshots/session/ptc-turn/cordis.snapshot.yml +++ b/snapshots/session/ptc-turn/cordis.snapshot.yml @@ -1,5 +1,9 @@ # Keyless PTC mode combines the runtime/registry changes with the # DeepSeek-to-replay swap in one profile patch. +- insert: + - id: literal-sdk + name: '../../../packages/core/tools/tests/fixtures/literal-sdk.ts' + - id: llm-deepseek name: '@deepseek-ai/dsh-llm-deepseek' disabled: true diff --git a/snapshots/session/ptc-turn/cordis.yml b/snapshots/session/ptc-turn/cordis.yml index 1ff5387957..a9f85a8e1c 100644 --- a/snapshots/session/ptc-turn/cordis.yml +++ b/snapshots/session/ptc-turn/cordis.yml @@ -1,6 +1,10 @@ # PTC mode adds `ctx.codeRuntime` and changes the registry to one wire tool, # `run_code`, plus its generated TypeScript SDK prompt. The demo and snapshot # recorder apply this profile patch; replay applies its sibling patch. +- insert: + - id: literal-sdk + name: '../../../packages/core/tools/tests/fixtures/literal-sdk.ts' + - id: agent-default-model name: '@deepseek-ai/dsh-agent-default-model' config: diff --git a/snapshots/session/ptc-turn/system-prompt.expected.md b/snapshots/session/ptc-turn/system-prompt.expected.md index dd648445e1..589b935ac2 100644 --- a/snapshots/session/ptc-turn/system-prompt.expected.md +++ b/snapshots/session/ptc-turn/system-prompt.expected.md @@ -191,6 +191,10 @@ interface ToolArgsMap { /** The task for the subagent. It already sees this conversation's completed turns, so build on them freely and state only what is new. */ prompt: string; } & Record; + /** Echo template text such as {{item}}, {{model}}, or {{ item }} without substitution. */ + template_echo: { + text: string; + } & Record; /** Record and update a structured task list for the current work. Send the ENTIRE list every call — it REPLACES the previous list (there are no partial updates, no per-item edits). Use it to plan multi-step work and show progress: add one todo per concrete step before you start. Mark every todo being actively worked on `in_progress` — several at once when work genuinely runs in parallel (e.g. concurrent subagents or background commands), one for sequential work; while work remains, at least one task should be `in_progress`. Mark a todo `completed` the moment it is done (do not batch completions), and allow no `in_progress` item only once all work is complete. Skip the list for trivial single-step tasks. Statuses: `pending` (not started), `in_progress` (being worked on now), `completed` (finished). */ todo_write: { /** The COMPLETE task list, replacing any previous list. */ @@ -466,6 +470,7 @@ interface ToolOutputMap { runId: string; output: JsonValue[]; }; + template_echo: string; todo_write: { todos: ({ content: string; From e4be27d1d9f3929d470c9bbd0f97c36e736972fa Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 9 Sep 2026 17:13:08 +0800 Subject: [PATCH 02/14] test(ptc): align workspace snapshot with shared SDK prompt --- snapshots/session/ptc-workspace-context/cordis.snapshot.yml | 4 ++++ snapshots/session/ptc-workspace-context/cordis.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/snapshots/session/ptc-workspace-context/cordis.snapshot.yml b/snapshots/session/ptc-workspace-context/cordis.snapshot.yml index 63cd3c497f..f8e5fa3228 100644 --- a/snapshots/session/ptc-workspace-context/cordis.snapshot.yml +++ b/snapshots/session/ptc-workspace-context/cordis.snapshot.yml @@ -1,5 +1,9 @@ # Keyless replay counterpart of ptc-workspace-context.cordis.yml. It adds # PTC mode to the default filesystem suite and swaps in replay. +- insert: + - id: literal-sdk + name: '../../../packages/core/tools/tests/fixtures/literal-sdk.ts' + - id: llm-deepseek name: '@deepseek-ai/dsh-llm-deepseek' disabled: true diff --git a/snapshots/session/ptc-workspace-context/cordis.yml b/snapshots/session/ptc-workspace-context/cordis.yml index ac55e8c923..d8aa490ecc 100644 --- a/snapshots/session/ptc-workspace-context/cordis.yml +++ b/snapshots/session/ptc-workspace-context/cordis.yml @@ -1,5 +1,9 @@ # PTC mode agent-instructions snapshot recording overlay. The default filesystem # tools trigger nested instruction discovery after a read. +- insert: + - id: literal-sdk + name: '../../../packages/core/tools/tests/fixtures/literal-sdk.ts' + - id: agent-default-model name: '@deepseek-ai/dsh-agent-default-model' config: From 5a673b8a59b3b0eb7962587019f37998ec032133 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 9 Sep 2026 17:28:47 +0800 Subject: [PATCH 03/14] refactor(ptc): share the prompt section return type --- packages/core/tools/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/tools/src/index.ts b/packages/core/tools/src/index.ts index b4d1a2a805..ccfb594774 100644 --- a/packages/core/tools/src/index.ts +++ b/packages/core/tools/src/index.ts @@ -844,7 +844,7 @@ export class ToolRuntime extends Service { * `both` renders empty: native calls do execute there, so the rule is false. * @returns the section registration. */ - private collapseSection(): { name: string; order: number; text: (context: { scope?: ScopeKey }) => string } { + private collapseSection(): PromptSection { return { name: 'tools:ptc-only', order: this.ctx.systemPrompt.getSectionOrder('PTC_ONLY'), From e1f09116187d64cc1b800f838d4d3a8db53a6250 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 9 Sep 2026 17:29:01 +0800 Subject: [PATCH 04/14] test(ptc): strengthen literal prompt assertions --- packages/core/system-prompt/tests/system-prompt.spec.ts | 9 +++++++-- packages/core/tools/tests/ptc.spec.ts | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/system-prompt/tests/system-prompt.spec.ts b/packages/core/system-prompt/tests/system-prompt.spec.ts index 3294c3179d..1d73203062 100644 --- a/packages/core/system-prompt/tests/system-prompt.spec.ts +++ b/packages/core/system-prompt/tests/system-prompt.spec.ts @@ -579,13 +579,18 @@ describe('SystemPrompt', () => { expect(renderPrompt(await ctx.systemPrompt.assemble())).toBe(`${IDENTITY}\n\nYou run on deepseek-v4 in /work.`) }) - it.each([false, true])('preserves literal section text with complete=%s', async (complete) => { + it.each([ + [false, false], + [false, true], + [true, false], + [true, true], + ])('preserves literal section text with complete=%s and dynamic=%s', async (complete, dynamic) => { const ctx = new Context() try { await ctx.plugin(SystemPrompt, { includeHarnessIdentity: false, personaPrefix: '{{model}}' }) ctx.systemPrompt.variable('model', () => 'actual-model') const text = '{{item}} {{model}} {{ model }} {{nested{{item}}}}' - ctx.systemPrompt.section({ name: 'literal', order: 1, text: () => text, interpolate: false, complete }) + ctx.systemPrompt.section({ name: 'literal', order: 1, text: dynamic ? () => text : text, interpolate: false, complete }) expect(renderPrompt(await ctx.systemPrompt.assemble())) .toBe(complete ? text : `actual-model\n\n${text}`) } finally { diff --git a/packages/core/tools/tests/ptc.spec.ts b/packages/core/tools/tests/ptc.spec.ts index cfb651283e..2ebd121f0c 100644 --- a/packages/core/tools/tests/ptc.spec.ts +++ b/packages/core/tools/tests/ptc.spec.ts @@ -138,9 +138,11 @@ describe('mode-aware wire contribution', () => { execute: args => Promise.resolve(args.value), })) const assembly = await systemPrompt.assemble() + const sdk = assembly.sections.find(section => section.name === 'tools:sdk') + expect(sdk).toBeDefined() const prompt = renderPrompt(assembly) expect(prompt).toContain(description) - expect(prompt).toContain(assembly.sections.find(section => section.name === 'tools:sdk')?.text) + expect(prompt).toContain(sdk!.text) expect(prompt).not.toContain('actual-model') } finally { await ctx.fiber.dispose() From 626fa816a5be314f26b64b5399b61f1cbc5a1547 Mon Sep 17 00:00:00 2001 From: Yif <877193178@qq.com> Date: Thu, 10 Sep 2026 17:45:49 +0800 Subject: [PATCH 05/14] feat(sidebar): refine the connection indicator states and styling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The disconnected pill now names the retry action statically (refresh icon + "连接异常,刷新重试") instead of swapping text on hover; connecting shows a spinner, holds visible for at least 800ms, and distinguishes manual retry (重新连接中) from automatic backoff (自动重连中); state changes fade over 150ms. Pill chrome tightened to 28px height with a 20%-alpha label border. --- .../src/ConnectionIndicator.module.css | 68 +++++++++----- .../ui-primitives/src/ConnectionIndicator.tsx | 94 ++++++++++--------- .../ui-primitives/tests/atoms.client.spec.tsx | 6 +- .../src/client/SettingsRoot.tsx | 41 ++++++-- .../ui-settings-general/src/client/locales.ts | 6 +- 5 files changed, 133 insertions(+), 82 deletions(-) diff --git a/packages/client/ui-primitives/src/ConnectionIndicator.module.css b/packages/client/ui-primitives/src/ConnectionIndicator.module.css index bf0e653740..285edb6052 100644 --- a/packages/client/ui-primitives/src/ConnectionIndicator.module.css +++ b/packages/client/ui-primitives/src/ConnectionIndicator.module.css @@ -4,25 +4,49 @@ grid-template-columns: 14px max-content; align-items: center; column-gap: 4px; - height: 32px; - padding: 0 10px; + height: 28px; + padding: 0 8px; box-sizing: border-box; - border: none; - border-radius: 8px; + border: 1px solid transparent; + border-radius: 13px; font-family: inherit; font-size: 12px; font-weight: 500; line-height: 18px; white-space: nowrap; - transition: background-color 160ms ease-out, color 160ms ease-out; + transition: + background-color 160ms ease-out, + color 160ms ease-out, + border-color 160ms ease-out, + opacity 150ms ease-out; + animation: indicator-enter 150ms ease-out; +} + +.leaving { + opacity: 0; +} + +@keyframes indicator-enter { + from { + opacity: 0; + } } .warning { background: var(--dsw-alias-state-warn-tertiary); color: var(--dsw-alias-state-warn-label); + border-color: color-mix(in srgb, var(--dsw-alias-state-warn-label) 20%, transparent); cursor: pointer; } +.warning:hover { + background: color-mix( + in srgb, + var(--dsw-alias-state-warn-tertiary), + var(--dsw-alias-state-warn-primary) 6% + ); +} + .warning:active { background: color-mix( in srgb, @@ -39,6 +63,7 @@ .success { background: var(--dsw-alias-state-success-tertiary); color: var(--dsw-alias-state-success-primary); + border-color: color-mix(in srgb, var(--dsw-alias-state-success-primary) 20%, transparent); } .icon { @@ -49,35 +74,20 @@ } .label { - display: grid; text-align: left; } -.stateLabel, -.hoverLabel, -.sizeLabel { - grid-area: 1 / 1; +.spinner { + animation: spinner-rotate 0.9s linear infinite; } -.sizeLabel { - visibility: hidden; -} - -.warning:is(:hover, :focus-visible) .stateLabel { - visibility: hidden; -} - -.hoverLabel { - visibility: hidden; -} - -.warning:is(:hover, :focus-visible) .hoverLabel { - visibility: visible; +@keyframes spinner-rotate { + to { transform: rotate(360deg); } } .dots { display: inline-block; - width: 1.5em; + width: 1em; text-align: left; } @@ -100,8 +110,14 @@ } @media (prefers-reduced-motion: reduce) { + .indicator, .secondDot, - .thirdDot { + .thirdDot, + .spinner { animation: none; } + + .indicator { + transition: none; + } } diff --git a/packages/client/ui-primitives/src/ConnectionIndicator.tsx b/packages/client/ui-primitives/src/ConnectionIndicator.tsx index 2c549661df..552e778e3c 100644 --- a/packages/client/ui-primitives/src/ConnectionIndicator.tsx +++ b/packages/client/ui-primitives/src/ConnectionIndicator.tsx @@ -1,4 +1,5 @@ -import { IconCheckOutline16, IconWarningOutline16 } from './icons/index.tsx' +import { useEffect, useState } from 'react' +import { IconCheckOutline16, IconLoadingOutline16, IconRefreshOutline14 } from './icons/index.tsx' import css from './ConnectionIndicator.module.css' /** Visual state rendered by {@link ConnectionIndicator}. */ @@ -7,11 +8,16 @@ export type ConnectionIndicatorState = | 'connecting' | 'recovered' +/** Exit-transition length; keep equal to the `.leaving` transition duration in the stylesheet. */ +const EXIT_MS = 150 + /** - * Render an inline connection-recovery control. + * Render an inline connection-recovery control. The outage and retry-attempt + * states are one button whose static label already names the retry action; + * clicking it requests an immediate reconnect. The indicator animates in on + * appearance and fades out for {@link EXIT_MS} before unmounting. * @param props.state - visible outage, retry-attempt, or recovered state. - * @param props.disconnectedLabel - localized outage text. - * @param props.reconnectLabel - localized action text shown on hover or focus. + * @param props.disconnectedLabel - localized outage text naming the retry action. * @param props.connectingLabel - localized retry text followed by the attempt dots. * @param props.recoveredLabel - localized recovery confirmation. * @param props.reconnectActionLabel - accessible label for the outage action. @@ -22,7 +28,6 @@ export type ConnectionIndicatorState = export function ConnectionIndicator({ state, disconnectedLabel, - reconnectLabel, connectingLabel, recoveredLabel, reconnectActionLabel, @@ -31,63 +36,66 @@ export function ConnectionIndicator({ }: { state: ConnectionIndicatorState | undefined disconnectedLabel: string - reconnectLabel: string connectingLabel: string recoveredLabel: string reconnectActionLabel: string restartActionLabel: string onReconnect: () => void }) { - if (state === undefined) return null - const sizeLabels = ( - <> - - - - - - ) - if (state === 'recovered') { + const [rendered, setRendered] = useState(state) + const leaving = state === undefined && rendered !== undefined + useEffect(() => { + if (state !== undefined) { + setRendered(state) + return + } + if (rendered === undefined) return + const timeout = window.setTimeout(() => { setRendered(undefined) }, EXIT_MS) + return () => { window.clearTimeout(timeout) } + }, [state, rendered]) + + if (rendered === undefined) return null + const leavingClass = leaving ? ` ${css.leaving}` : '' + if (rendered === 'recovered') { return ( -
+
- - {sizeLabels} - {recoveredLabel} - + {recoveredLabel}
) } - const connecting = state === 'connecting' + const connecting = rendered === 'connecting' return ( ) diff --git a/packages/client/ui-primitives/tests/atoms.client.spec.tsx b/packages/client/ui-primitives/tests/atoms.client.spec.tsx index 70649d0874..c591546724 100644 --- a/packages/client/ui-primitives/tests/atoms.client.spec.tsx +++ b/packages/client/ui-primitives/tests/atoms.client.spec.tsx @@ -462,8 +462,7 @@ describe('ConnectionIndicator', () => { it('renders outage, attempt progress, and recovered states without a native tooltip', () => { const reconnect = vi.fn() const labels = { - disconnectedLabel: 'Disconnected', - reconnectLabel: 'Reconnect', + disconnectedLabel: 'Disconnected, retry', connectingLabel: 'Connecting', recoveredLabel: 'Connected', reconnectActionLabel: 'Disconnected, reconnect now', @@ -476,8 +475,7 @@ describe('ConnectionIndicator', () => { expect(container.firstChild).toBeNull() rerender() const indicator = screen.getByRole('button', { name: 'Disconnected, reconnect now' }) - expect(indicator.textContent).toContain('Disconnected') - expect(indicator.textContent).toContain('Reconnect') + expect(indicator.textContent).toContain('Disconnected, retry') expect(indicator.hasAttribute('title')).toBe(false) expect(indicator.querySelector('svg')).toBeTruthy() fireEvent.click(indicator) diff --git a/packages/client/ui-settings-general/src/client/SettingsRoot.tsx b/packages/client/ui-settings-general/src/client/SettingsRoot.tsx index e0b20dceed..c7d48b1746 100644 --- a/packages/client/ui-settings-general/src/client/SettingsRoot.tsx +++ b/packages/client/ui-settings-general/src/client/SettingsRoot.tsx @@ -23,6 +23,9 @@ import css from './SettingsRoot.module.css' const RECOVERY_CONFIRMATION_MS = 2_000 +/** Minimum visible time for the connecting pill; shorter attempts read as flicker. */ +const CONNECTING_MIN_VISIBLE_MS = 800 + /** Nav glyph by section id; unknown ids fall back to the settings gear. */ function navIcon(id: string) { if (id === 'models') return @@ -113,6 +116,9 @@ export function SettingsRoot(props: SettingsRootComponentProps) { const [activeId, setActiveId] = useState(undefined) const [completedOnboarding, setCompletedOnboarding] = useState>(() => new Set()) const [showRecovery, setShowRecovery] = useState(false) + const [holdConnecting, setHoldConnecting] = useState(false) + const [manualRetry, setManualRetry] = useState(false) + const connectingShownAt = useRef(undefined) const triggerButton = useRef(null) const wasOpen = useRef(open) const close = useCallback(() => { @@ -161,6 +167,30 @@ export function SettingsRoot(props: SettingsRootComponentProps) { return () => { window.clearTimeout(timeout) } }, [connectionState]) + useLayoutEffect(() => { + if (connectionState === 'connecting') { + connectingShownAt.current = Date.now() + return + } + setManualRetry(false) + const shownAt = connectingShownAt.current + if (shownAt === undefined) return + connectingShownAt.current = undefined + const remaining = CONNECTING_MIN_VISIBLE_MS - (Date.now() - shownAt) + if (remaining <= 0) return + setHoldConnecting(true) + const timeout = window.setTimeout(() => { setHoldConnecting(false) }, remaining) + return () => { + window.clearTimeout(timeout) + setHoldConnecting(false) + } + }, [connectionState]) + + const manualReconnect = useCallback(() => { + setManualRetry(true) + reconnect() + }, [reconnect]) + const completeOnboardingStep = useCallback((id: string) => { setCompletedOnboarding((previous) => { if (previous.has(id)) return previous @@ -169,10 +199,10 @@ export function SettingsRoot(props: SettingsRootComponentProps) { }, []) let connectionIndicator: ConnectionIndicatorState | undefined - if (connectionState === 'disconnected') { - connectionIndicator = 'disconnected' - } else if (connectionState === 'connecting') { + if (connectionState === 'connecting' || holdConnecting) { connectionIndicator = 'connecting' + } else if (connectionState === 'disconnected') { + connectionIndicator = 'disconnected' } else if (showRecovery) { connectionIndicator = 'recovered' } @@ -194,12 +224,11 @@ export function SettingsRoot(props: SettingsRootComponentProps) {
{open && ( diff --git a/packages/client/ui-settings-general/src/client/locales.ts b/packages/client/ui-settings-general/src/client/locales.ts index f03bee9680..f23b673325 100644 --- a/packages/client/ui-settings-general/src/client/locales.ts +++ b/packages/client/ui-settings-general/src/client/locales.ts @@ -8,9 +8,9 @@ export const zh = { 'openDocument': '打开配置文件', 'openDocument.error': '无法打开配置文件', 'general.nav': '通用设置', - 'connection.error': '连接异常', - 'connection.retry': '立即重连', + 'connection.error': '连接异常,刷新重试', 'connection.connecting': '自动重连中', + 'connection.reconnecting': '重新连接中', 'connection.connected': '连接成功', 'connection.reconnect': '连接异常,点击立即重连', 'connection.restart': '连接中断,正在自动重试,点击立即重连', @@ -28,8 +28,8 @@ export const en = { 'openDocument.error': 'Could not open configuration file', 'general.nav': 'General', 'connection.error': 'Disconnected', - 'connection.retry': 'Reconnect now', 'connection.connecting': 'Reconnecting', + 'connection.reconnecting': 'Reconnecting', 'connection.connected': 'Connected', 'connection.reconnect': 'Disconnected, reconnect now', 'connection.restart': 'Reconnecting automatically, reconnect now', From 464e1cce496617d98f6c3afed156517dee0ca00d Mon Sep 17 00:00:00 2001 From: turtle1999 <301751225+turtle1999@users.noreply.github.com> Date: Thu, 10 Sep 2026 19:01:00 +0800 Subject: [PATCH 06/14] fix(ci): canonicalize browser dependency scan roots --- scripts/browser-bundled-externals.spec.ts | 12 +++++++++--- scripts/browser-bundled-externals.ts | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/browser-bundled-externals.spec.ts b/scripts/browser-bundled-externals.spec.ts index b4d95cf96d..cadc8fb6ae 100644 --- a/scripts/browser-bundled-externals.spec.ts +++ b/scripts/browser-bundled-externals.spec.ts @@ -1,4 +1,4 @@ -import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs' +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join, resolve } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' @@ -78,7 +78,7 @@ describe('browser dependency discovery', () => { await expect(browserBundledExternals(root)).rejects.toThrow('has no browser build config') }) - it('follows shell workspace aliases, CSS assets and lazy imports without writing output', async () => { + it.each([false, true])('follows shell aliases, CSS and lazy imports without writing output (symlinked root: %s)', async (linked) => { const root = fixture() library(root, 'shell-lib') library(root, 'lazy-lib') @@ -104,7 +104,13 @@ describe('browser dependency discovery', () => { }`) write(root, 'apps/web/dist/sentinel.txt', 'untouched') - expect(await browserBundledExternals(root)).toEqual(new Set(['shell-lib', 'lazy-lib', 'asset-lib'])) + const scanRoot = linked ? join(fixture(), 'linked') : root + if (linked) symlinkSync(root, scanRoot, 'junction') + try { + expect(await browserBundledExternals(scanRoot)).toEqual(new Set(['shell-lib', 'lazy-lib', 'asset-lib'])) + } finally { + if (linked) unlinkSync(scanRoot) + } expect(readFileSync(join(app, 'dist/sentinel.txt'), 'utf8')).toBe('untouched') expect(existsSync(join(app, 'dist/index.html'))).toBe(false) expect(existsSync(join(root, 'packages/client/static/lib'))).toBe(false) diff --git a/scripts/browser-bundled-externals.ts b/scripts/browser-bundled-externals.ts index 85053be30f..9139f6b4c2 100644 --- a/scripts/browser-bundled-externals.ts +++ b/scripts/browser-bundled-externals.ts @@ -1,6 +1,6 @@ /** Resolve direct third-party browser inputs through the shipping build configurations, without emitting files. */ -import { globSync, readFileSync } from 'node:fs' +import { globSync, readFileSync, realpathSync } from 'node:fs' import { createRequire } from 'node:module' import { dirname, resolve } from 'node:path' import { pathToFileURL } from 'node:url' @@ -159,10 +159,12 @@ async function collectShell( /** * Direct third-party packages resolved by published browser builds. - * @param root - Repository root with installed build dependencies; lib/ is not required. + * @param root - Repository root, possibly symlinked, with installed build dependencies; lib/ is not required. * @returns Names of distributed browser inputs, excluding workspace packages and erased types. */ export async function browserBundledExternals(root: string): Promise> { + // Vite resolves HTML inputs to real paths, so its root must use the same spelling. + root = realpathSync(root) const manifests = new Map() for (const glob of ['packages/*/*/package.json', 'vendor/*/package.json']) { for (const path of globSync(glob, { cwd: root }).sort()) { From 16e986548e8f39061a8b1d1f9999aa147f7a4e67 Mon Sep 17 00:00:00 2001 From: Yif <877193178@qq.com> Date: Thu, 10 Sep 2026 19:29:48 +0800 Subject: [PATCH 07/14] test(sidebar): pin the refined connection indicator behavior and docs Update the behavior tests for the static retry label, the 800ms minimum connecting hold, manual-versus-automatic attempt naming, and the 150ms fade-out unmount; restate the interaction in both packages' bilingual READMEs and record the decision as an Agent Note. --- ...connection-indicator-refinements.i18n.yaml | 6 ++++ ...-09-10-connection-indicator-refinements.md | 27 ++++++++++++++++++ ...-10-connection-indicator-refinements.zh.md | 27 ++++++++++++++++++ .../client/ui-primitives/README.i18n.yaml | 4 +-- packages/client/ui-primitives/README.md | 2 +- packages/client/ui-primitives/README.zh.md | 2 +- .../ui-primitives/tests/atoms.client.spec.tsx | 23 +++++++++++++++ .../ui-settings-general/README.i18n.yaml | 4 +-- packages/client/ui-settings-general/README.md | 4 +-- .../client/ui-settings-general/README.zh.md | 4 +-- .../tests/apply.client.spec.ts | 2 +- .../tests/settings-root.client.spec.tsx | 28 ++++++++++++++++--- 12 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.i18n.yaml create mode 100644 .agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md create mode 100644 .agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md diff --git a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.i18n.yaml b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.i18n.yaml new file mode 100644 index 0000000000..e8f2b205d7 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.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 .agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md +2026-09-10-connection-indicator-refinements.md: 331aeec55b2eb038788125ce862bce0eebae9481 +2026-09-10-connection-indicator-refinements.zh.md: c5e5afebfc9f1238bc29edd7992a62fb5ea4ccfe diff --git a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md new file mode 100644 index 0000000000..331aeec55b --- /dev/null +++ b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md @@ -0,0 +1,27 @@ +# Agent Note: Connection indicator state and interaction refinements + +Status: implemented + +English | [中文](2026-09-10-connection-indicator-refinements.zh.md) + +## Problem + +The sidebar connection pill hid its affordance behind a hover swap: outage and retry-attempt states replaced their label with **Reconnect now** on hover or focus, so every state had to reserve the widest supplied label to keep the control from resizing. A retry that resolved in under a second flickered the connecting pill in and out, a manual click read identically to automatic backoff, and state changes and unmounts jumped with no transition. + +## Decision + +**The disconnected pill names its action statically.** [ConnectionIndicator.tsx](../../../../packages/client/ui-primitives/src/ConnectionIndicator.tsx) renders a retry glyph (`IconRefreshOutline14`) beside outage copy that itself names the retry action (`连接异常,刷新重试` / `Disconnected`); clicking the pill still reconnects immediately. The hover label swap and the hidden widest-label size-reservation spans are gone, so the pill sizes to its current label. The connecting state shows a rotating-arc spinner instead of the exclamation glyph. Appearance, state changes, and removal fade over 150ms: `EXIT_MS` delays unmount to match the stylesheet's `.leaving` transition, and `prefers-reduced-motion` disables every animation and transition. Chrome settles at 28px height, 8px horizontal padding, 4px icon gap, 13px radius, and a 1px border of the label color at 20% alpha. + +**The shell owns attempt pacing and attempt naming.** [SettingsRoot.tsx](../../../../packages/client/ui-settings-general/src/client/SettingsRoot.tsx) keeps the connecting pill visible for at least `CONNECTING_MIN_VISIBLE_MS` (800ms) so sub-second retries do not flicker, and tracks a `manualRetry` flag set by the pill click so a user-initiated attempt reads `重新连接中` (`connection.reconnecting`) while automatic backoff reads `自动重连中` (`connection.connecting`). Both timings are built-in presentation constants of their owners, like the recovery confirmation's existing two seconds, not configuration. + +## Alternatives considered + +**Animating width changes.** A FLIP-style measured pixel transition (remember the old width, pin it, transition to the new measurement) was implemented and then removed: the fade-only change reads calm enough, and the measurement replay added a layout effect and imperative style writes for marginal polish. + +**Swapping to the retry glyph on hover.** An 80ms cross-fade from the warning glyph to the retry glyph on hover was implemented and then simplified away: showing the retry glyph permanently states the affordance without requiring any pointer interaction, matching the static label decision. + +**Scaling on enter/exit.** A 0.98 scale accompanied the fades first; at 12px text the movement read as jitter, so only opacity remains. + +## Consequences + +`ConnectionIndicator`'s `reconnectLabel` prop and its size-reservation spans are removed from the pre-stable API; the sole consumer (`ui-settings-general`) is updated in the same change. `settings-root.client.spec.tsx` pins the 800ms hold, the manual-versus-automatic naming, and the fade-out delay; `atoms.client.spec.tsx` pins the exit-duration unmount. Both packages' READMEs restate the interaction. diff --git a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md new file mode 100644 index 0000000000..c5e5afebfc --- /dev/null +++ b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md @@ -0,0 +1,27 @@ +# Agent Note: 连接指示器状态与交互细化 + +Status: implemented + +[English](2026-09-10-connection-indicator-refinements.md) | 中文 + +## Problem + +侧边栏连接药丸把操作提示藏在悬停切换里:断连与重试状态在悬停或聚焦时把文案替换为**立即重连**,因此每个状态都要为最宽的 label 预留空间以避免控件变形。一次不到一秒就恢复的重试会让连接中药丸闪现闪没,手动点击与自动退避读起来毫无区别,状态切换和消失也没有任何过渡、十分突兀。 + +## Decision + +**断连药丸静态地指明其动作。** [ConnectionIndicator.tsx](../../../../packages/client/ui-primitives/src/ConnectionIndicator.tsx) 在断连文案旁渲染重试图形(`IconRefreshOutline14`),文案本身即指明重试动作(`连接异常,刷新重试` / `Disconnected`);点击药丸仍会立即重连。悬停换文案和隐藏的最宽 label 占位 span 全部移除,药丸宽度随当前 label 自适应。连接中状态改用旋转圆弧 spinner 取代感叹号图形。出现、状态切换与消失均以 150ms 淡入淡出:`EXIT_MS` 延迟卸载以匹配样式表的 `.leaving` 过渡,`prefers-reduced-motion` 会禁用全部动画与过渡。外观定为高 28px、水平内边距 8px、图标间距 4px、圆角 13px,以及 label 颜色 20% 透明度的 1px 边框。 + +**外壳拥有尝试节奏与尝试命名。** [SettingsRoot.tsx](../../../../packages/client/ui-settings-general/src/client/SettingsRoot.tsx) 让连接中药丸至少可见 `CONNECTING_MIN_VISIBLE_MS`(800ms),亚秒级重试不再闪动;并跟踪由药丸点击置位的 `manualRetry` 标志,用户主动发起的尝试显示`重新连接中`(`connection.reconnecting`),自动退避显示`自动重连中`(`connection.connecting`)。两个时长与恢复确认既有的 2 秒一样,是各自持有方的内置展示常量,不是配置。 + +## Alternatives considered + +**给宽度变化加动画。** FLIP 式的像素测量过渡(记住旧宽度、钉住、过渡到新测量值)实现后又被移除:纯淡入淡出已足够平静,而测量重放为边际的打磨引入了一个 layout effect 和命令式样式写入。 + +**悬停时切换为重试图形。** 悬停时从警告图形 80ms 交叉渐变到重试图形的方案实现后又被简化掉:常驻显示重试图形无需任何指针交互就说明了操作,与静态文案的决定一致。 + +**进出场缩放。** 淡入淡出最初伴随 0.98 的缩放;在 12px 文字上这点位移读起来像抖动,因此只保留透明度。 + +## Consequences + +`ConnectionIndicator` 的 `reconnectLabel` prop 及其占位 span 从 pre-stable API 中移除;唯一消费者(`ui-settings-general`)在同一变更中更新。`settings-root.client.spec.tsx` 固定 800ms 驻留、手动与自动命名以及淡出延迟;`atoms.client.spec.tsx` 固定退出时长后的卸载。两个包的 README 重述了该交互。 diff --git a/packages/client/ui-primitives/README.i18n.yaml b/packages/client/ui-primitives/README.i18n.yaml index 546a1ea347..3eb8ac2231 100644 --- a/packages/client/ui-primitives/README.i18n.yaml +++ b/packages/client/ui-primitives/README.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 packages/client/ui-primitives/README.md -README.md: c7536d946516e9626d1880244e879663d7565cd2 -README.zh.md: 0bba56e593662aed05394e918f570c83ad2d7ca3 +README.md: 6931f58db6e42f01f6835b7920b522795f74fa90 +README.zh.md: d18eec75ca5b7ddb5fd0260f97c0ad6b7ea97921 diff --git a/packages/client/ui-primitives/README.md b/packages/client/ui-primitives/README.md index c7536d9465..6931f58db6 100644 --- a/packages/client/ui-primitives/README.md +++ b/packages/client/ui-primitives/README.md @@ -67,7 +67,7 @@ Writing your own component in your own package is fine when the need is genuinel ### Controls and icons -The catalog above lists what each export is for; this section covers the behavior that props alone do not show. The `ic_ds_*` icon set and `FishLogo`/`BrandWordmark` marks fill brand and inline-icon slots. `FileTypeIcon` renders the traditional 28px Excel, folder, HTML, image, Markdown, generic, PDF, PPT, video, and Word glyphs, and uses the full-color square technology artwork for recognized code and configuration files. `classifyFileType` applies exact filename, prefix, suffix, optional project-context, and extension rules in that order; React names win over TypeScript/JavaScript, Angular suffixes win over their base extension, and a Dart file becomes Flutter only when the supplied project files contain a `pubspec.yaml` with `flutter:`. Markdown and SVG remain traditional Markdown and image files. Office mappings include XLSM/Numbers as Excel, KEY as slides, and RTF/ODT/Pages as documents. `fileExtension` exposes the same basename and final-dot parsing for adjacent metadata labels. Traditional glyphs use a solid category-colored sheet with a white mark and translucent white corner; the generic file uses a grey sheet and darker grey corner. Callers may override the sheet color through `--dsh-file-type-icon-color`. The full-color technology artwork is the deliberate exception and retains its embedded palette. All glyphs are decorative and carry no label. `LinkIcon` remains the smaller leading glyph for clickable artifact links — globe, folder, code, image, document, or plain paper — while `classifyLinkPath` folds the shared file types into that existing six-category vocabulary. `ConnectionIndicator` renders a warning-colored disconnected action, a connecting label whose one-to-three dots advance every 500ms independently of retry timing, or a success-colored recovered status. Hover or keyboard focus shows only the reconnect action label, including while the connecting dots animate. Every state reserves the widest supplied label and uses fixed icon and text columns, so copy changes do not move or resize the control. Its owner supplies visibility, the recovery hold, localized labels, and the immediate-reconnect callback; the primitive uses no native title tooltip. `useAnchoredPosition` and `useAnchoredMaxHeight` keep floating panels and bottom-anchored overlays clamped to the viewport and following their anchor. `HoverCard` keeps its portaled preview reachable across the anchor gap and can expose a copy button through the `copyText` prop. `Toast` holds for the window its owner names through `holdMs`, because how long a banner has to stay depends on how much there is to read; the same value drives its unmount timer and the stylesheet's fade delay, so the two cannot disagree. `rankByName` is the `/` menu's shared candidate ranker for the command and skill sources: the query must be a case-insensitive ordered subsequence of the name; prefix hits rank first, then alignment score, then source order. `Menu.autoFocus` focuses its first enabled item, supports Arrow Up/Down and Home/End navigation, and focuses the first button in the anchor on Escape; it is opt-in for action menus. +The catalog above lists what each export is for; this section covers the behavior that props alone do not show. The `ic_ds_*` icon set and `FishLogo`/`BrandWordmark` marks fill brand and inline-icon slots. `FileTypeIcon` renders the traditional 28px Excel, folder, HTML, image, Markdown, generic, PDF, PPT, video, and Word glyphs, and uses the full-color square technology artwork for recognized code and configuration files. `classifyFileType` applies exact filename, prefix, suffix, optional project-context, and extension rules in that order; React names win over TypeScript/JavaScript, Angular suffixes win over their base extension, and a Dart file becomes Flutter only when the supplied project files contain a `pubspec.yaml` with `flutter:`. Markdown and SVG remain traditional Markdown and image files. Office mappings include XLSM/Numbers as Excel, KEY as slides, and RTF/ODT/Pages as documents. `fileExtension` exposes the same basename and final-dot parsing for adjacent metadata labels. Traditional glyphs use a solid category-colored sheet with a white mark and translucent white corner; the generic file uses a grey sheet and darker grey corner. Callers may override the sheet color through `--dsh-file-type-icon-color`. The full-color technology artwork is the deliberate exception and retains its embedded palette. All glyphs are decorative and carry no label. `LinkIcon` remains the smaller leading glyph for clickable artifact links — globe, folder, code, image, document, or plain paper — while `classifyLinkPath` folds the shared file types into that existing six-category vocabulary. `ConnectionIndicator` renders a warning-colored disconnected action whose retry glyph and static label name the retry action, a connecting spinner beside a label whose one-to-three dots advance every 500ms independently of retry timing, or a success-colored recovered status. Clicking either warning state requests an immediate reconnect; no hover interaction changes the copy. The pill fades in on appearance, fades out for 150ms before unmounting, and sizes to its current label. Its owner supplies visibility, the recovery hold, localized labels, and the immediate-reconnect callback; the primitive uses no native title tooltip. `useAnchoredPosition` and `useAnchoredMaxHeight` keep floating panels and bottom-anchored overlays clamped to the viewport and following their anchor. `HoverCard` keeps its portaled preview reachable across the anchor gap and can expose a copy button through the `copyText` prop. `Toast` holds for the window its owner names through `holdMs`, because how long a banner has to stay depends on how much there is to read; the same value drives its unmount timer and the stylesheet's fade delay, so the two cannot disagree. `rankByName` is the `/` menu's shared candidate ranker for the command and skill sources: the query must be a case-insensitive ordered subsequence of the name; prefix hits rank first, then alignment score, then source order. `Menu.autoFocus` focuses its first enabled item, supports Arrow Up/Down and Home/End navigation, and focuses the first button in the anchor on Escape; it is opt-in for action menus. ### Rendering agent output diff --git a/packages/client/ui-primitives/README.zh.md b/packages/client/ui-primitives/README.zh.md index 0bba56e593..d18eec75ca 100644 --- a/packages/client/ui-primitives/README.zh.md +++ b/packages/client/ui-primitives/README.zh.md @@ -67,7 +67,7 @@ kind: "package-library" ### 控件与图标 -上面的目录说明每个导出的用途;本节讲 props 本身看不出来的行为。`ic_ds_*` 图标集与 `FishLogo`/`BrandWordmark` 标记填充品牌与行内图标 slot。`FileTypeIcon` 渲染传统的 28px Excel、folder、HTML、image、Markdown、generic、PDF、PPT、video 与 Word 图形,并为已识别的代码和配置文件使用全彩方形技术图形。`classifyFileType` 按完整文件名、前缀、后缀、可选项目上下文、扩展名的顺序匹配;React 文件名优先于 TypeScript/JavaScript,Angular 后缀优先于基础扩展名,只有传入的项目文件包含带 `flutter:` 的 `pubspec.yaml` 时 Dart 文件才使用 Flutter。Markdown 与 SVG 仍分别使用传统 Markdown 与图片图形。办公文件映射包含 XLSM/Numbers 的表格图标、KEY 的幻灯片图标,以及 RTF/ODT/Pages 的文档图标。`fileExtension` 为相邻元数据 label 暴露同一套 basename 与最终点号解析。传统图形使用实色分类底板、白色标记和半透明白色折角;通用文件使用灰色底板与较深灰色折角。调用方可通过 `--dsh-file-type-icon-color` 覆盖底板颜色。全彩技术图形是明确例外,会保留其内嵌调色板。所有图形都是装饰性的,不自带 label。`LinkIcon` 仍是可点击产物链接较小的前置分类图形——地球、文件夹、代码、图片、文档或纸张——`classifyLinkPath` 把共享文件类型折叠进原有六类词汇。`ConnectionIndicator` 可渲染警告色的断联操作、以独立于 retry 时序的 500ms 节奏推进一至三个点的连接中状态,或成功色的恢复状态。悬停或键盘聚焦时只显示重连操作文案,连接中的圆点动画也保持隐藏。所有状态都为最长的输入 label 预留空间,并使用固定的图标列和文字列,因此文案变化不会移动控件或改变其宽度。它的持有方提供可见性、恢复驻留时间、本地化 label 与立即重连回调;该原语不使用原生 title tooltip。`useAnchoredPosition` 与 `useAnchoredMaxHeight` 让浮动面板与底部锚定浮层始终钳制在视口内并跟随锚点。`HoverCard` 通过指针离开宽限期让采用 portal 的预览在跨过锚点间隙时仍可触及,并可通过 `copyText` prop 提供复制按钮。`Toast` 的停留时长由使用方通过 `holdMs` 指定,因为横幅该留多久取决于有多少内容要读;同一个值同时驱动它的卸载定时器与样式表的淡出延迟,两者不可能再错位。`rankByName` 是 `/` 菜单命令源与 skill(技能)源共享的候选排序器:查询必须是名字的不区分大小写的有序子序列;前缀命中排最前,其次按对齐分数,再按来源顺序。 `Menu.autoFocus` 聚焦首个启用项,支持上下方向键与 Home/End 导航,并在 Escape 时聚焦 anchor 内的第一个按钮;操作菜单可显式启用。 +上面的目录说明每个导出的用途;本节讲 props 本身看不出来的行为。`ic_ds_*` 图标集与 `FishLogo`/`BrandWordmark` 标记填充品牌与行内图标 slot。`FileTypeIcon` 渲染传统的 28px Excel、folder、HTML、image、Markdown、generic、PDF、PPT、video 与 Word 图形,并为已识别的代码和配置文件使用全彩方形技术图形。`classifyFileType` 按完整文件名、前缀、后缀、可选项目上下文、扩展名的顺序匹配;React 文件名优先于 TypeScript/JavaScript,Angular 后缀优先于基础扩展名,只有传入的项目文件包含带 `flutter:` 的 `pubspec.yaml` 时 Dart 文件才使用 Flutter。Markdown 与 SVG 仍分别使用传统 Markdown 与图片图形。办公文件映射包含 XLSM/Numbers 的表格图标、KEY 的幻灯片图标,以及 RTF/ODT/Pages 的文档图标。`fileExtension` 为相邻元数据 label 暴露同一套 basename 与最终点号解析。传统图形使用实色分类底板、白色标记和半透明白色折角;通用文件使用灰色底板与较深灰色折角。调用方可通过 `--dsh-file-type-icon-color` 覆盖底板颜色。全彩技术图形是明确例外,会保留其内嵌调色板。所有图形都是装饰性的,不自带 label。`LinkIcon` 仍是可点击产物链接较小的前置分类图形——地球、文件夹、代码、图片、文档或纸张——`classifyLinkPath` 把共享文件类型折叠进原有六类词汇。`ConnectionIndicator` 可渲染警告色的断联操作(重试图形与静态文案本身即指明重试动作)、spinner 加一至三个点以独立于 retry 时序的 500ms 节奏推进的连接中状态,或成功色的恢复状态。点击任一警告状态都会请求立即重连;没有任何悬停交互会改变文案。药丸出现时淡入、卸载前淡出 150ms,宽度随当前 label 自适应。它的持有方提供可见性、恢复驻留时间、本地化 label 与立即重连回调;该原语不使用原生 title tooltip。`useAnchoredPosition` 与 `useAnchoredMaxHeight` 让浮动面板与底部锚定浮层始终钳制在视口内并跟随锚点。`HoverCard` 通过指针离开宽限期让采用 portal 的预览在跨过锚点间隙时仍可触及,并可通过 `copyText` prop 提供复制按钮。`Toast` 的停留时长由使用方通过 `holdMs` 指定,因为横幅该留多久取决于有多少内容要读;同一个值同时驱动它的卸载定时器与样式表的淡出延迟,两者不可能再错位。`rankByName` 是 `/` 菜单命令源与 skill(技能)源共享的候选排序器:查询必须是名字的不区分大小写的有序子序列;前缀命中排最前,其次按对齐分数,再按来源顺序。 `Menu.autoFocus` 聚焦首个启用项,支持上下方向键与 Home/End 导航,并在 Escape 时聚焦 anchor 内的第一个按钮;操作菜单可显式启用。 ### 渲染 agent 输出 diff --git a/packages/client/ui-primitives/tests/atoms.client.spec.tsx b/packages/client/ui-primitives/tests/atoms.client.spec.tsx index c591546724..59178671a4 100644 --- a/packages/client/ui-primitives/tests/atoms.client.spec.tsx +++ b/packages/client/ui-primitives/tests/atoms.client.spec.tsx @@ -489,4 +489,27 @@ describe('ConnectionIndicator', () => { expect(screen.queryByRole('button')).toBeNull() expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() }) + + it('fades out for the exit duration before unmounting', () => { + vi.useFakeTimers() + try { + const labels = { + disconnectedLabel: 'Disconnected, retry', + connectingLabel: 'Connecting', + recoveredLabel: 'Connected', + reconnectActionLabel: 'Disconnected, reconnect now', + restartActionLabel: 'Connecting, restart now', + onReconnect: vi.fn(), + } + const { container, rerender } = render( + , + ) + rerender() + expect(screen.getByRole('button', { name: 'Disconnected, reconnect now' })).toBeTruthy() + act(() => { vi.advanceTimersByTime(150) }) + expect(container.firstChild).toBeNull() + } finally { + vi.useRealTimers() + } + }) }) diff --git a/packages/client/ui-settings-general/README.i18n.yaml b/packages/client/ui-settings-general/README.i18n.yaml index cb4566a437..bbd3b0ebb8 100644 --- a/packages/client/ui-settings-general/README.i18n.yaml +++ b/packages/client/ui-settings-general/README.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 packages/client/ui-settings-general/README.md -README.md: 845d9c48dce2264d478f0ac854ef85a480828a14 -README.zh.md: 814082f94156e44b45e015e67acb7a281ba2e7e9 +README.md: 5f4ba3c29943014860993b092274fd7479dfe7eb +README.zh.md: 8ae02f9c5bfe5af673a3d2f13861089c0cbee054 diff --git a/packages/client/ui-settings-general/README.md b/packages/client/ui-settings-general/README.md index 845d9c48dc..5f4ba3c299 100644 --- a/packages/client/ui-settings-general/README.md +++ b/packages/client/ui-settings-general/README.md @@ -25,7 +25,7 @@ Use this package to give the dsh web client a Settings panel, connection-recover ## Use this package -Users reach the shell through the sidebar's bottom Settings control; feature plugins contribute their pages and onboarding steps through the slot ledgers this shell projects. In both the expanded sidebar and collapsed rail, the control exposes the localized Settings label as its accessible name. A pale-yellow **Disconnected** action beside Settings indicates browser offline suspension. Automatic recovery shows **Reconnecting** with one to three dots advancing every 500ms. Hover or keyboard focus changes either yellow label to **Reconnect now** without changing its background; press feedback stays within the warning palette, and selecting it starts retry 1 immediately. Recovery changes the region to pale-green **Connected** for two seconds before it disappears. The icon, left-aligned text origin, height, and width remain fixed across every visible state. Initial startup and uninterrupted healthy operation remain silent. The shell renders the modal panel, the navigation built from `settings.section` entries, and exactly one mounted onboarding step at a time. +Users reach the shell through the sidebar's bottom Settings control; feature plugins contribute their pages and onboarding steps through the slot ledgers this shell projects. In both the expanded sidebar and collapsed rail, the control exposes the localized Settings label as its accessible name. A pale-yellow **Disconnected** action beside Settings indicates browser offline suspension; its retry glyph and static label name the retry action directly. Automatic recovery shows a spinner beside **Reconnecting** with one to three dots advancing every 500ms, and an attempt stays visible for at least 800ms so brief retries do not flicker. Selecting either yellow state starts an immediate retry, and the attempt label distinguishes that manual retry from automatic backoff; press feedback stays within the warning palette. Recovery changes the region to pale-green **Connected** for two seconds before it disappears. States fade in and out over 150ms, and the pill sizes to its current label. Initial startup and uninterrupted healthy operation remain silent. The shell renders the modal panel, the navigation built from `settings.section` entries, and exactly one mounted onboarding step at a time. ### The General section @@ -55,7 +55,7 @@ The navigation is a projection of the `settings.section` ledger; nav labels may ### Connection recovery -The shell is an explicit recovery consumer, so it injects Connection directly rather than adding lifecycle controls to `ctx.remote`. Its private hooks compartment binds `ctx.connection.state`, while the component receives only the selected state and an injected callback for `ctx.connection.reconnect()`. `ConnectionIndicator` owns the inline presentation and receives all visible and accessible copy from the `settings` locale namespace; the shell owns the two-second recovered-state timer. +The shell is an explicit recovery consumer, so it injects Connection directly rather than adding lifecycle controls to `ctx.remote`. Its private hooks compartment binds `ctx.connection.state`, while the component receives only the selected state and an injected callback for `ctx.connection.reconnect()`. `ConnectionIndicator` owns the inline presentation and receives all visible and accessible copy from the `settings` locale namespace; the shell owns the two-second recovered-state timer, the 800ms minimum-visible hold for the connecting state, and the manual-versus-automatic attempt label choice. ### Document availability diff --git a/packages/client/ui-settings-general/README.zh.md b/packages/client/ui-settings-general/README.zh.md index 814082f941..8ae02f9c5b 100644 --- a/packages/client/ui-settings-general/README.zh.md +++ b/packages/client/ui-settings-general/README.zh.md @@ -25,7 +25,7 @@ kind: "package-reference" ## 使用本包 -用户通过侧边栏底部的 Settings 控件进入外壳;功能插件通过本外壳所投影的 slot 账本贡献自己的页面与引导步骤。在展开侧边栏和收起轨道中,该控件都会把本地化的 Settings 文案作为其可访问名称。Settings 右侧浅黄色的**连接异常**操作表示浏览器离线暂停;自动恢复期间显示**自动重连中**,其后一至三个点每 500ms 前进一次。鼠标悬浮或键盘聚焦任一黄色状态时,只有文案变为**立即重连**,背景保持不变;按压反馈留在黄色色阶内,选中后立即从 retry 1 开始。恢复后该区域变为浅绿色的**连接成功**,驻留 2 秒再消失。所有可见状态的文字都左对齐,且图标、文字起点、高度和宽度保持固定。首次启动与未曾中断的健康连接保持静默。外壳渲染模态面板、由 `settings.section` 条目构建的导航,以及每次只挂载一个的引导步骤。 +用户通过侧边栏底部的 Settings 控件进入外壳;功能插件通过本外壳所投影的 slot 账本贡献自己的页面与引导步骤。在展开侧边栏和收起轨道中,该控件都会把本地化的 Settings 文案作为其可访问名称。Settings 右侧浅黄色的**连接异常**操作表示浏览器离线暂停;其重试图形与静态文案本身即指明重试动作。自动恢复期间显示 spinner 加**自动重连中**,其后一至三个点每 500ms 前进一次,且每次尝试至少可见 800ms,短暂重试不会闪动。选中任一黄色状态都会立即发起重试,尝试文案会把这次手动重试与自动退避区分开;按压反馈留在黄色色阶内。恢复后该区域变为浅绿色的**连接成功**,驻留 2 秒再消失。状态以 150ms 淡入淡出,药丸宽度随当前文案自适应。首次启动与未曾中断的健康连接保持静默。外壳渲染模态面板、由 `settings.section` 条目构建的导航,以及每次只挂载一个的引导步骤。 ### 「通用」分区 @@ -55,7 +55,7 @@ kind: "package-reference" ### 连接恢复 -外壳是明确的恢复功能消费方,因此直接注入 Connection,而不把生命周期控制放进 `ctx.remote`。它的私有 hooks compartment 绑定 `ctx.connection.state`,组件只接收选出的状态与调用 `ctx.connection.reconnect()` 的注入回调。`ConnectionIndicator` 拥有内联展示并从 `settings` locale namespace 接收全部可见与无障碍文案;2 秒恢复状态计时器归外壳所有。 +外壳是明确的恢复功能消费方,因此直接注入 Connection,而不把生命周期控制放进 `ctx.remote`。它的私有 hooks compartment 绑定 `ctx.connection.state`,组件只接收选出的状态与调用 `ctx.connection.reconnect()` 的注入回调。`ConnectionIndicator` 拥有内联展示并从 `settings` locale namespace 接收全部可见与无障碍文案;2 秒恢复状态计时器、连接中状态的 800ms 最短可见驻留,以及手动与自动尝试文案的选择都归外壳所有。 ### 文档可用性 diff --git a/packages/client/ui-settings-general/tests/apply.client.spec.ts b/packages/client/ui-settings-general/tests/apply.client.spec.ts index 10380d26d9..b9c2de2a9b 100644 --- a/packages/client/ui-settings-general/tests/apply.client.spec.ts +++ b/packages/client/ui-settings-general/tests/apply.client.spec.ts @@ -118,7 +118,7 @@ describe('ui-settings-general apply', () => { settings.mutate.mockResolvedValueOnce(ok(english)) const t = c.ctx.locale.bind(NS) expect(t('title')).toBe('设置') - expect(t('connection.error')).toBe('连接异常') + expect(t('connection.error')).toBe('连接异常,刷新重试') expect(t('connection.connecting')).toBe('自动重连中') expect(t('connection.connected')).toBe('连接成功') c.ctx.locale.setLocale('en') diff --git a/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx b/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx index a6a953aa34..01a15df743 100644 --- a/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx +++ b/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx @@ -165,12 +165,32 @@ describe('SettingsRoot trigger', () => { expect(screen.getByRole('button', { name: 'Reconnecting automatically, reconnect now' }).textContent) .toContain('Reconnecting...') + // An attempt that resolves instantly still shows the connecting pill for + // its 800ms minimum before the confirmation replaces it. mounted.setConnectionState('connected') - expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() - act(() => { vi.advanceTimersByTime(1_999) }) - expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() - act(() => { vi.advanceTimersByTime(1) }) expect(screen.queryByRole('status')).toBeNull() + act(() => { vi.advanceTimersByTime(800) }) + expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() + act(() => { vi.advanceTimersByTime(1_199) }) + expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() + // The confirmation window closes at 2s, then the pill fades for 150ms. + act(() => { vi.advanceTimersByTime(1) }) + act(() => { vi.advanceTimersByTime(150) }) + expect(screen.queryByRole('status')).toBeNull() + }) + + it('names automatic and manual retry attempts and confirms at once after a long attempt', () => { + vi.useFakeTimers() + const mounted = mount({ dictionary: zh }) + mounted.setConnectionState('connecting') + const attempt = screen.getByRole('button', { name: '连接中断,正在自动重试,点击立即重连' }) + expect(attempt.textContent).toContain('自动重连中') + fireEvent.click(attempt) + expect(mounted.reconnect).toHaveBeenCalledOnce() + expect(attempt.textContent).toContain('重新连接中') + act(() => { vi.advanceTimersByTime(800) }) + mounted.setConnectionState('connected') + expect(screen.getByRole('status', { name: '连接成功' })).toBeTruthy() }) it('keeps the reconnect indicator out of the collapsed rail', () => { From b044e45438a0bc9e8db44efbf2518363944d9cc1 Mon Sep 17 00:00:00 2001 From: Yif <877193178@qq.com> Date: Thu, 10 Sep 2026 19:52:38 +0800 Subject: [PATCH 08/14] test(web): pin the static connection pill in the lifecycle browser snapshot --- apps/web/tests/lifecycle-chrome.e2e.ts | 21 +++++++------------ .../connection-error.expected.md | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/apps/web/tests/lifecycle-chrome.e2e.ts b/apps/web/tests/lifecycle-chrome.e2e.ts index 1ebdb03002..b615b1235e 100644 --- a/apps/web/tests/lifecycle-chrome.e2e.ts +++ b/apps/web/tests/lifecycle-chrome.e2e.ts @@ -434,16 +434,9 @@ describe('web e2e: lifecycle & chrome (workspace flow / reload / dark mode)', () expect(await connecting.innerText()).toMatch(/^Reconnecting\.{1,3}$/) const connectingGeometry = await connectionIndicatorGeometry(connecting) expect(await connectionIndicatorTextAlignment(connecting)).toBe('left') - // Animated dots must remain hidden with their state label during hover. - await connecting.evaluate((element) => { - for (const animation of element.getAnimations({ subtree: true })) { - if (!(animation instanceof CSSAnimation)) continue - animation.pause() - animation.currentTime = 1_250 - } - }) + // Hover keeps the state label; the pill never swaps copy or resizes. await connecting.hover() - expect(await connecting.innerText()).toBe('Reconnect now') + expect(await connecting.innerText()).toMatch(/^Reconnecting\.{1,3}$/) expect(await connectionIndicatorGeometry(connecting)).toEqual(connectingGeometry) await recoveryPage.mouse.move(0, 0) @@ -461,7 +454,6 @@ describe('web e2e: lifecycle & chrome (workspace flow / reload / dark mode)', () const indicator = connecting expect(await connectionIndicatorGeometry(indicator)).toEqual(connectingGeometry) expect(await connectionIndicatorTextAlignment(indicator)).toBe('left') - await indicator.hover() const snapshot = await captureStableAria(recoveryPage, '[class*="footArea"]', scaffold.workspaceCwd) await compareOrRefreshGolden(CONNECTION_ERROR_EXPECTED, snapshot, MODE) const style = await indicator.evaluate((element) => { @@ -498,11 +490,9 @@ describe('web e2e: lifecycle & chrome (workspace flow / reload / dark mode)', () await connecting.waitFor() await recoveryPage.clock.fastForward(500) await expect.poll(() => sockets.length).toBe(11) - const idleBackground = await indicator.evaluate(element => getComputedStyle(element).backgroundColor) await indicator.hover() - expect(await indicator.innerText()).toBe('Reconnect now') + expect(await indicator.innerText()).toMatch(/^Reconnecting\.{1,3}$/) const hoverBackground = await indicator.evaluate(element => getComputedStyle(element).backgroundColor) - expect(hoverBackground).toBe(idleBackground) await recoveryPage.mouse.down() await expect.poll(() => indicator.evaluate(element => getComputedStyle(element).backgroundColor)) .not.toBe(hoverBackground) @@ -513,7 +503,10 @@ describe('web e2e: lifecycle & chrome (workspace flow / reload / dark mode)', () const recovered = recoveryPage.getByRole('status') await recovered.waitFor({ timeout: 10_000 }) expect(await recovered.innerText()).toBe('Connected') - expect(await connectionIndicatorGeometry(recovered)).toEqual(connectingGeometry) + // The pill sizes to its current label; chrome height and icon box stay fixed. + const recoveredGeometry = await connectionIndicatorGeometry(recovered) + expect(recoveredGeometry.outer[3]).toBe(connectingGeometry.outer[3]) + expect(recoveredGeometry.icon).toEqual(connectingGeometry.icon) expect(await connectionIndicatorTextAlignment(recovered)).toBe('left') await recoveryPage.clock.fastForward(2_000) await recovered.waitFor({ state: 'detached', timeout: 5_000 }) diff --git a/snapshots/web/lifecycle-chrome/connection-error.expected.md b/snapshots/web/lifecycle-chrome/connection-error.expected.md index 31046ddf7b..c14269d3ed 100644 --- a/snapshots/web/lifecycle-chrome/connection-error.expected.md +++ b/snapshots/web/lifecycle-chrome/connection-error.expected.md @@ -1,4 +1,4 @@ - button "Settings": - img - text: Settings -- button "Reconnecting automatically, reconnect now": Reconnect now +- button "Reconnecting automatically, reconnect now": Reconnecting From 11ca8020cdf3b367168536a1b343ac2348c08a95 Mon Sep 17 00:00:00 2001 From: Yif <877193178@qq.com> Date: Thu, 10 Sep 2026 20:12:09 +0800 Subject: [PATCH 09/14] fix(sidebar): keep one reconnect label and confirm recovery from visibility ConnectionController deduplicates repeated connecting states across backoff attempts, so the shell cannot tell manual retries from automatic ones; a shell-held flag either flipped the label mid-hold or stuck across later attempts. Every attempt now reads the single connecting label, and the two-second recovery confirmation starts when the recovered pill becomes visible rather than at the state transition, so the 800ms hold never shortens it. --- ...connection-indicator-refinements.i18n.yaml | 4 +-- ...-09-10-connection-indicator-refinements.md | 16 +++++---- ...-10-connection-indicator-refinements.zh.md | 16 +++++---- apps/web/tests/lifecycle-chrome.e2e.ts | 2 +- .../client/ui-primitives/README.i18n.yaml | 4 +-- packages/client/ui-primitives/README.md | 2 +- packages/client/ui-primitives/README.zh.md | 2 +- .../ui-settings-general/README.i18n.yaml | 4 +-- packages/client/ui-settings-general/README.md | 4 +-- .../client/ui-settings-general/README.zh.md | 4 +-- .../src/client/SettingsRoot.tsx | 19 +++++----- .../ui-settings-general/src/client/locales.ts | 8 ++--- .../tests/apply.client.spec.ts | 2 +- .../tests/settings-root.client.spec.tsx | 35 +++++++++++++++---- .../connection-error.expected.md | 2 +- 15 files changed, 74 insertions(+), 50 deletions(-) diff --git a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.i18n.yaml b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.i18n.yaml index e8f2b205d7..7d4eb35fa1 100644 --- a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.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 .agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md -2026-09-10-connection-indicator-refinements.md: 331aeec55b2eb038788125ce862bce0eebae9481 -2026-09-10-connection-indicator-refinements.zh.md: c5e5afebfc9f1238bc29edd7992a62fb5ea4ccfe +2026-09-10-connection-indicator-refinements.md: 3b6b4c7fd0962edbb87be17c2fa45eded46ee86b +2026-09-10-connection-indicator-refinements.zh.md: 0bd5dc3e0b5b69cf2d9491e2d3ce5711c96898f5 diff --git a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md index 331aeec55b..3b6b4c7fd0 100644 --- a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md +++ b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.md @@ -6,22 +6,24 @@ English | [中文](2026-09-10-connection-indicator-refinements.zh.md) ## Problem -The sidebar connection pill hid its affordance behind a hover swap: outage and retry-attempt states replaced their label with **Reconnect now** on hover or focus, so every state had to reserve the widest supplied label to keep the control from resizing. A retry that resolved in under a second flickered the connecting pill in and out, a manual click read identically to automatic backoff, and state changes and unmounts jumped with no transition. +The sidebar connection pill hid its affordance behind a hover swap: outage and retry-attempt states replaced their label with **Reconnect now** on hover or focus, so every state had to reserve the widest supplied label to keep the control from resizing. A retry that resolved in under a second flickered the connecting pill in and out, and state changes and unmounts jumped with no transition. ## Decision -**The disconnected pill names its action statically.** [ConnectionIndicator.tsx](../../../../packages/client/ui-primitives/src/ConnectionIndicator.tsx) renders a retry glyph (`IconRefreshOutline14`) beside outage copy that itself names the retry action (`连接异常,刷新重试` / `Disconnected`); clicking the pill still reconnects immediately. The hover label swap and the hidden widest-label size-reservation spans are gone, so the pill sizes to its current label. The connecting state shows a rotating-arc spinner instead of the exclamation glyph. Appearance, state changes, and removal fade over 150ms: `EXIT_MS` delays unmount to match the stylesheet's `.leaving` transition, and `prefers-reduced-motion` disables every animation and transition. Chrome settles at 28px height, 8px horizontal padding, 4px icon gap, 13px radius, and a 1px border of the label color at 20% alpha. +**The disconnected pill shows its action statically.** [ConnectionIndicator.tsx](../../../../packages/client/ui-primitives/src/ConnectionIndicator.tsx) renders a permanent retry glyph (`IconRefreshOutline14`) beside the outage copy (`连接异常,刷新重试` / `Disconnected`; the Chinese copy also names the retry action); clicking the pill still reconnects immediately. The hover label swap and the hidden widest-label size-reservation spans are gone, so the pill sizes to its current label. The connecting state shows a rotating-arc spinner instead of the exclamation glyph. Appearance and removal fade over 150ms — swaps between visible states replace content in place: `EXIT_MS` delays unmount to match the stylesheet's `.leaving` transition, and `prefers-reduced-motion` disables every animation and transition. Chrome settles at 28px height, 8px horizontal padding, 4px icon gap, 13px radius, and a 1px border of the label color at 20% alpha. -**The shell owns attempt pacing and attempt naming.** [SettingsRoot.tsx](../../../../packages/client/ui-settings-general/src/client/SettingsRoot.tsx) keeps the connecting pill visible for at least `CONNECTING_MIN_VISIBLE_MS` (800ms) so sub-second retries do not flicker, and tracks a `manualRetry` flag set by the pill click so a user-initiated attempt reads `重新连接中` (`connection.reconnecting`) while automatic backoff reads `自动重连中` (`connection.connecting`). Both timings are built-in presentation constants of their owners, like the recovery confirmation's existing two seconds, not configuration. +**The shell owns attempt pacing.** [SettingsRoot.tsx](../../../../packages/client/ui-settings-general/src/client/SettingsRoot.tsx) keeps the connecting pill visible for at least `CONNECTING_MIN_VISIBLE_MS` (800ms) so sub-second retries do not flicker; every attempt, manual or automatic, reads the one label `重新连接中` (`connection.connecting`). The two-second recovery confirmation (`RECOVERY_CONFIRMATION_MS`) starts when the recovered pill becomes visible, so a hold that delays its appearance never shortens the confirmation. Both timings are built-in presentation constants of their owners, not configuration. ## Alternatives considered -**Animating width changes.** A FLIP-style measured pixel transition (remember the old width, pin it, transition to the new measurement) was implemented and then removed: the fade-only change reads calm enough, and the measurement replay added a layout effect and imperative style writes for marginal polish. +**Animating width changes.** A FLIP-style measured pixel transition (remember the old width, pin it, transition to the new measurement) needs a layout effect and imperative style writes; the fade-only change reads calm enough without them. -**Swapping to the retry glyph on hover.** An 80ms cross-fade from the warning glyph to the retry glyph on hover was implemented and then simplified away: showing the retry glyph permanently states the affordance without requiring any pointer interaction, matching the static label decision. +**Swapping to the retry glyph only on hover.** Showing the retry glyph permanently states the affordance without requiring any pointer interaction, matching the static label; a hover cross-fade adds interaction-dependent state and conveys nothing extra. -**Scaling on enter/exit.** A 0.98 scale accompanied the fades first; at 12px text the movement read as jitter, so only opacity remains. +**Scaling on enter/exit.** A 0.98 scale beside the opacity fades reads as jitter at 12px text, so only opacity animates. + +**Naming manual and automatic attempts differently.** `ConnectionController.emitState` deduplicates repeated `connecting` states across backoff attempts, so the shell cannot observe attempt boundaries: a shell-held manual-retry flag either flips the label mid-hold or sticks across later automatic attempts. Distinguishing the copy correctly requires the connection layer to expose the attempt origin, which this change does not need — both attempt kinds read the same label. ## Consequences -`ConnectionIndicator`'s `reconnectLabel` prop and its size-reservation spans are removed from the pre-stable API; the sole consumer (`ui-settings-general`) is updated in the same change. `settings-root.client.spec.tsx` pins the 800ms hold, the manual-versus-automatic naming, and the fade-out delay; `atoms.client.spec.tsx` pins the exit-duration unmount. Both packages' READMEs restate the interaction. +`ConnectionIndicator`'s `reconnectLabel` prop and its size-reservation spans are removed from the pre-stable API; the sole consumer (`ui-settings-general`) is updated in the same change. `settings-root.client.spec.tsx` pins the 800ms hold, the single attempt label held steady through the hold, and the visibility-based confirmation window; `atoms.client.spec.tsx` pins the exit-duration unmount; `lifecycle-chrome.e2e.ts` and its ARIA golden replay the recovery flow in a real browser. Both packages' READMEs restate the interaction. diff --git a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md index c5e5afebfc..0bd5dc3e0b 100644 --- a/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md +++ b/.agents/notes/implemented/feature/2026-09-10-connection-indicator-refinements.zh.md @@ -6,22 +6,24 @@ Status: implemented ## Problem -侧边栏连接药丸把操作提示藏在悬停切换里:断连与重试状态在悬停或聚焦时把文案替换为**立即重连**,因此每个状态都要为最宽的 label 预留空间以避免控件变形。一次不到一秒就恢复的重试会让连接中药丸闪现闪没,手动点击与自动退避读起来毫无区别,状态切换和消失也没有任何过渡、十分突兀。 +侧边栏连接药丸把操作提示藏在悬停切换里:断连与重试状态在悬停或聚焦时把文案替换为**立即重连**,因此每个状态都要为最宽的 label 预留空间以避免控件变形。一次不到一秒就恢复的重试会让连接中药丸闪现闪没,状态切换和消失也没有任何过渡、十分突兀。 ## Decision -**断连药丸静态地指明其动作。** [ConnectionIndicator.tsx](../../../../packages/client/ui-primitives/src/ConnectionIndicator.tsx) 在断连文案旁渲染重试图形(`IconRefreshOutline14`),文案本身即指明重试动作(`连接异常,刷新重试` / `Disconnected`);点击药丸仍会立即重连。悬停换文案和隐藏的最宽 label 占位 span 全部移除,药丸宽度随当前 label 自适应。连接中状态改用旋转圆弧 spinner 取代感叹号图形。出现、状态切换与消失均以 150ms 淡入淡出:`EXIT_MS` 延迟卸载以匹配样式表的 `.leaving` 过渡,`prefers-reduced-motion` 会禁用全部动画与过渡。外观定为高 28px、水平内边距 8px、图标间距 4px、圆角 13px,以及 label 颜色 20% 透明度的 1px 边框。 +**断连药丸静态地展示其动作。** [ConnectionIndicator.tsx](../../../../packages/client/ui-primitives/src/ConnectionIndicator.tsx) 在断连文案旁常驻渲染重试图形(`IconRefreshOutline14`),文案为 `连接异常,刷新重试` / `Disconnected`(中文文案同时点明重试动作);点击药丸仍会立即重连。悬停换文案和隐藏的最宽 label 占位 span 全部移除,药丸宽度随当前 label 自适应。连接中状态改用旋转圆弧 spinner 取代感叹号图形。出现与移除以 150ms 淡入淡出——可见状态之间的切换则原地替换内容:`EXIT_MS` 延迟卸载以匹配样式表的 `.leaving` 过渡,`prefers-reduced-motion` 会禁用全部动画与过渡。外观定为高 28px、水平内边距 8px、图标间距 4px、圆角 13px,以及 label 颜色 20% 透明度的 1px 边框。 -**外壳拥有尝试节奏与尝试命名。** [SettingsRoot.tsx](../../../../packages/client/ui-settings-general/src/client/SettingsRoot.tsx) 让连接中药丸至少可见 `CONNECTING_MIN_VISIBLE_MS`(800ms),亚秒级重试不再闪动;并跟踪由药丸点击置位的 `manualRetry` 标志,用户主动发起的尝试显示`重新连接中`(`connection.reconnecting`),自动退避显示`自动重连中`(`connection.connecting`)。两个时长与恢复确认既有的 2 秒一样,是各自持有方的内置展示常量,不是配置。 +**外壳拥有尝试节奏。** [SettingsRoot.tsx](../../../../packages/client/ui-settings-general/src/client/SettingsRoot.tsx) 让连接中药丸至少可见 `CONNECTING_MIN_VISIBLE_MS`(800ms),亚秒级重试不再闪动;无论手动还是自动,每次尝试都显示同一个文案`重新连接中`(`connection.connecting`)。2 秒恢复确认(`RECOVERY_CONFIRMATION_MS`)从恢复药丸实际可见时起算,驻留推迟其出现也不会缩短确认时长。两个时长是各自持有方的内置展示常量,不是配置。 ## Alternatives considered -**给宽度变化加动画。** FLIP 式的像素测量过渡(记住旧宽度、钉住、过渡到新测量值)实现后又被移除:纯淡入淡出已足够平静,而测量重放为边际的打磨引入了一个 layout effect 和命令式样式写入。 +**给宽度变化加动画。** FLIP 式的像素测量过渡(记住旧宽度、钉住、过渡到新测量值)需要一个 layout effect 和命令式样式写入;纯淡入淡出已足够平静,无需这些。 -**悬停时切换为重试图形。** 悬停时从警告图形 80ms 交叉渐变到重试图形的方案实现后又被简化掉:常驻显示重试图形无需任何指针交互就说明了操作,与静态文案的决定一致。 +**仅在悬停时切换为重试图形。** 常驻显示重试图形无需任何指针交互就说明了操作,与静态文案一致;悬停交叉渐变引入依赖交互的状态却不传达更多信息。 -**进出场缩放。** 淡入淡出最初伴随 0.98 的缩放;在 12px 文字上这点位移读起来像抖动,因此只保留透明度。 +**进出场缩放。** 0.98 的缩放叠加在透明度淡入淡出上,在 12px 文字上读起来像抖动,因此只保留透明度。 + +**手动与自动尝试使用不同命名。** `ConnectionController.emitState` 会去重退避尝试之间重复的 `connecting` 状态,外壳观察不到尝试边界:外壳自持的手动重试标志要么在驻留中途翻转文案,要么在后续自动尝试中一直滞留。要正确区分文案需要连接层暴露尝试来源,而本次变更并不需要——两种尝试显示同一文案。 ## Consequences -`ConnectionIndicator` 的 `reconnectLabel` prop 及其占位 span 从 pre-stable API 中移除;唯一消费者(`ui-settings-general`)在同一变更中更新。`settings-root.client.spec.tsx` 固定 800ms 驻留、手动与自动命名以及淡出延迟;`atoms.client.spec.tsx` 固定退出时长后的卸载。两个包的 README 重述了该交互。 +`ConnectionIndicator` 的 `reconnectLabel` prop 及其占位 span 从 pre-stable API 中移除;唯一消费者(`ui-settings-general`)在同一变更中更新。`settings-root.client.spec.tsx` 固定 800ms 驻留、驻留期间保持不变的单一尝试文案,以及按可见时刻起算的确认窗口;`atoms.client.spec.tsx` 固定退出时长后的卸载;`lifecycle-chrome.e2e.ts` 及其 ARIA golden 在真实浏览器中回放恢复流程。两个包的 README 重述了该交互。 diff --git a/apps/web/tests/lifecycle-chrome.e2e.ts b/apps/web/tests/lifecycle-chrome.e2e.ts index b615b1235e..e01464786a 100644 --- a/apps/web/tests/lifecycle-chrome.e2e.ts +++ b/apps/web/tests/lifecycle-chrome.e2e.ts @@ -428,7 +428,7 @@ describe('web e2e: lifecycle & chrome (workspace flow / reload / dark mode)', () await recoveryPage.context().setOffline(false) await expect.poll(() => recoveryPage.evaluate(() => navigator.onLine)).toBe(true) const connecting = recoveryPage.getByRole('button', { - name: 'Reconnecting automatically, reconnect now', exact: true, + name: 'Reconnecting, reconnect now', exact: true, }) await connecting.waitFor({ timeout: 10_000 }) expect(await connecting.innerText()).toMatch(/^Reconnecting\.{1,3}$/) diff --git a/packages/client/ui-primitives/README.i18n.yaml b/packages/client/ui-primitives/README.i18n.yaml index 3eb8ac2231..6cdff9ec86 100644 --- a/packages/client/ui-primitives/README.i18n.yaml +++ b/packages/client/ui-primitives/README.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 packages/client/ui-primitives/README.md -README.md: 6931f58db6e42f01f6835b7920b522795f74fa90 -README.zh.md: d18eec75ca5b7ddb5fd0260f97c0ad6b7ea97921 +README.md: 01abef1fbd2d2558fa3b80b3632c15e9cfbf8cf1 +README.zh.md: bf49168900751e235cdbcc25c602c5499d9ce346 diff --git a/packages/client/ui-primitives/README.md b/packages/client/ui-primitives/README.md index 6931f58db6..01abef1fbd 100644 --- a/packages/client/ui-primitives/README.md +++ b/packages/client/ui-primitives/README.md @@ -67,7 +67,7 @@ Writing your own component in your own package is fine when the need is genuinel ### Controls and icons -The catalog above lists what each export is for; this section covers the behavior that props alone do not show. The `ic_ds_*` icon set and `FishLogo`/`BrandWordmark` marks fill brand and inline-icon slots. `FileTypeIcon` renders the traditional 28px Excel, folder, HTML, image, Markdown, generic, PDF, PPT, video, and Word glyphs, and uses the full-color square technology artwork for recognized code and configuration files. `classifyFileType` applies exact filename, prefix, suffix, optional project-context, and extension rules in that order; React names win over TypeScript/JavaScript, Angular suffixes win over their base extension, and a Dart file becomes Flutter only when the supplied project files contain a `pubspec.yaml` with `flutter:`. Markdown and SVG remain traditional Markdown and image files. Office mappings include XLSM/Numbers as Excel, KEY as slides, and RTF/ODT/Pages as documents. `fileExtension` exposes the same basename and final-dot parsing for adjacent metadata labels. Traditional glyphs use a solid category-colored sheet with a white mark and translucent white corner; the generic file uses a grey sheet and darker grey corner. Callers may override the sheet color through `--dsh-file-type-icon-color`. The full-color technology artwork is the deliberate exception and retains its embedded palette. All glyphs are decorative and carry no label. `LinkIcon` remains the smaller leading glyph for clickable artifact links — globe, folder, code, image, document, or plain paper — while `classifyLinkPath` folds the shared file types into that existing six-category vocabulary. `ConnectionIndicator` renders a warning-colored disconnected action whose retry glyph and static label name the retry action, a connecting spinner beside a label whose one-to-three dots advance every 500ms independently of retry timing, or a success-colored recovered status. Clicking either warning state requests an immediate reconnect; no hover interaction changes the copy. The pill fades in on appearance, fades out for 150ms before unmounting, and sizes to its current label. Its owner supplies visibility, the recovery hold, localized labels, and the immediate-reconnect callback; the primitive uses no native title tooltip. `useAnchoredPosition` and `useAnchoredMaxHeight` keep floating panels and bottom-anchored overlays clamped to the viewport and following their anchor. `HoverCard` keeps its portaled preview reachable across the anchor gap and can expose a copy button through the `copyText` prop. `Toast` holds for the window its owner names through `holdMs`, because how long a banner has to stay depends on how much there is to read; the same value drives its unmount timer and the stylesheet's fade delay, so the two cannot disagree. `rankByName` is the `/` menu's shared candidate ranker for the command and skill sources: the query must be a case-insensitive ordered subsequence of the name; prefix hits rank first, then alignment score, then source order. `Menu.autoFocus` focuses its first enabled item, supports Arrow Up/Down and Home/End navigation, and focuses the first button in the anchor on Escape; it is opt-in for action menus. +The catalog above lists what each export is for; this section covers the behavior that props alone do not show. The `ic_ds_*` icon set and `FishLogo`/`BrandWordmark` marks fill brand and inline-icon slots. `FileTypeIcon` renders the traditional 28px Excel, folder, HTML, image, Markdown, generic, PDF, PPT, video, and Word glyphs, and uses the full-color square technology artwork for recognized code and configuration files. `classifyFileType` applies exact filename, prefix, suffix, optional project-context, and extension rules in that order; React names win over TypeScript/JavaScript, Angular suffixes win over their base extension, and a Dart file becomes Flutter only when the supplied project files contain a `pubspec.yaml` with `flutter:`. Markdown and SVG remain traditional Markdown and image files. Office mappings include XLSM/Numbers as Excel, KEY as slides, and RTF/ODT/Pages as documents. `fileExtension` exposes the same basename and final-dot parsing for adjacent metadata labels. Traditional glyphs use a solid category-colored sheet with a white mark and translucent white corner; the generic file uses a grey sheet and darker grey corner. Callers may override the sheet color through `--dsh-file-type-icon-color`. The full-color technology artwork is the deliberate exception and retains its embedded palette. All glyphs are decorative and carry no label. `LinkIcon` remains the smaller leading glyph for clickable artifact links — globe, folder, code, image, document, or plain paper — while `classifyLinkPath` folds the shared file types into that existing six-category vocabulary. `ConnectionIndicator` renders a warning-colored disconnected action whose permanent retry glyph marks the retry action beside the owner-supplied outage label, a connecting spinner beside a label whose one-to-three dots advance every 500ms independently of retry timing, or a success-colored recovered status. Clicking either warning state requests an immediate reconnect; no hover interaction changes the copy. The pill fades in on appearance, fades out for 150ms before unmounting, and sizes to its current label. Its owner supplies visibility, the recovery hold, localized labels, and the immediate-reconnect callback; the primitive uses no native title tooltip. `useAnchoredPosition` and `useAnchoredMaxHeight` keep floating panels and bottom-anchored overlays clamped to the viewport and following their anchor. `HoverCard` keeps its portaled preview reachable across the anchor gap and can expose a copy button through the `copyText` prop. `Toast` holds for the window its owner names through `holdMs`, because how long a banner has to stay depends on how much there is to read; the same value drives its unmount timer and the stylesheet's fade delay, so the two cannot disagree. `rankByName` is the `/` menu's shared candidate ranker for the command and skill sources: the query must be a case-insensitive ordered subsequence of the name; prefix hits rank first, then alignment score, then source order. `Menu.autoFocus` focuses its first enabled item, supports Arrow Up/Down and Home/End navigation, and focuses the first button in the anchor on Escape; it is opt-in for action menus. ### Rendering agent output diff --git a/packages/client/ui-primitives/README.zh.md b/packages/client/ui-primitives/README.zh.md index d18eec75ca..bf49168900 100644 --- a/packages/client/ui-primitives/README.zh.md +++ b/packages/client/ui-primitives/README.zh.md @@ -67,7 +67,7 @@ kind: "package-library" ### 控件与图标 -上面的目录说明每个导出的用途;本节讲 props 本身看不出来的行为。`ic_ds_*` 图标集与 `FishLogo`/`BrandWordmark` 标记填充品牌与行内图标 slot。`FileTypeIcon` 渲染传统的 28px Excel、folder、HTML、image、Markdown、generic、PDF、PPT、video 与 Word 图形,并为已识别的代码和配置文件使用全彩方形技术图形。`classifyFileType` 按完整文件名、前缀、后缀、可选项目上下文、扩展名的顺序匹配;React 文件名优先于 TypeScript/JavaScript,Angular 后缀优先于基础扩展名,只有传入的项目文件包含带 `flutter:` 的 `pubspec.yaml` 时 Dart 文件才使用 Flutter。Markdown 与 SVG 仍分别使用传统 Markdown 与图片图形。办公文件映射包含 XLSM/Numbers 的表格图标、KEY 的幻灯片图标,以及 RTF/ODT/Pages 的文档图标。`fileExtension` 为相邻元数据 label 暴露同一套 basename 与最终点号解析。传统图形使用实色分类底板、白色标记和半透明白色折角;通用文件使用灰色底板与较深灰色折角。调用方可通过 `--dsh-file-type-icon-color` 覆盖底板颜色。全彩技术图形是明确例外,会保留其内嵌调色板。所有图形都是装饰性的,不自带 label。`LinkIcon` 仍是可点击产物链接较小的前置分类图形——地球、文件夹、代码、图片、文档或纸张——`classifyLinkPath` 把共享文件类型折叠进原有六类词汇。`ConnectionIndicator` 可渲染警告色的断联操作(重试图形与静态文案本身即指明重试动作)、spinner 加一至三个点以独立于 retry 时序的 500ms 节奏推进的连接中状态,或成功色的恢复状态。点击任一警告状态都会请求立即重连;没有任何悬停交互会改变文案。药丸出现时淡入、卸载前淡出 150ms,宽度随当前 label 自适应。它的持有方提供可见性、恢复驻留时间、本地化 label 与立即重连回调;该原语不使用原生 title tooltip。`useAnchoredPosition` 与 `useAnchoredMaxHeight` 让浮动面板与底部锚定浮层始终钳制在视口内并跟随锚点。`HoverCard` 通过指针离开宽限期让采用 portal 的预览在跨过锚点间隙时仍可触及,并可通过 `copyText` prop 提供复制按钮。`Toast` 的停留时长由使用方通过 `holdMs` 指定,因为横幅该留多久取决于有多少内容要读;同一个值同时驱动它的卸载定时器与样式表的淡出延迟,两者不可能再错位。`rankByName` 是 `/` 菜单命令源与 skill(技能)源共享的候选排序器:查询必须是名字的不区分大小写的有序子序列;前缀命中排最前,其次按对齐分数,再按来源顺序。 `Menu.autoFocus` 聚焦首个启用项,支持上下方向键与 Home/End 导航,并在 Escape 时聚焦 anchor 内的第一个按钮;操作菜单可显式启用。 +上面的目录说明每个导出的用途;本节讲 props 本身看不出来的行为。`ic_ds_*` 图标集与 `FishLogo`/`BrandWordmark` 标记填充品牌与行内图标 slot。`FileTypeIcon` 渲染传统的 28px Excel、folder、HTML、image、Markdown、generic、PDF、PPT、video 与 Word 图形,并为已识别的代码和配置文件使用全彩方形技术图形。`classifyFileType` 按完整文件名、前缀、后缀、可选项目上下文、扩展名的顺序匹配;React 文件名优先于 TypeScript/JavaScript,Angular 后缀优先于基础扩展名,只有传入的项目文件包含带 `flutter:` 的 `pubspec.yaml` 时 Dart 文件才使用 Flutter。Markdown 与 SVG 仍分别使用传统 Markdown 与图片图形。办公文件映射包含 XLSM/Numbers 的表格图标、KEY 的幻灯片图标,以及 RTF/ODT/Pages 的文档图标。`fileExtension` 为相邻元数据 label 暴露同一套 basename 与最终点号解析。传统图形使用实色分类底板、白色标记和半透明白色折角;通用文件使用灰色底板与较深灰色折角。调用方可通过 `--dsh-file-type-icon-color` 覆盖底板颜色。全彩技术图形是明确例外,会保留其内嵌调色板。所有图形都是装饰性的,不自带 label。`LinkIcon` 仍是可点击产物链接较小的前置分类图形——地球、文件夹、代码、图片、文档或纸张——`classifyLinkPath` 把共享文件类型折叠进原有六类词汇。`ConnectionIndicator` 可渲染警告色的断联操作(常驻重试图形指明重试动作,断联文案由持有方提供)、spinner 加一至三个点以独立于 retry 时序的 500ms 节奏推进的连接中状态,或成功色的恢复状态。点击任一警告状态都会请求立即重连;没有任何悬停交互会改变文案。药丸出现时淡入、卸载前淡出 150ms,宽度随当前 label 自适应。它的持有方提供可见性、恢复驻留时间、本地化 label 与立即重连回调;该原语不使用原生 title tooltip。`useAnchoredPosition` 与 `useAnchoredMaxHeight` 让浮动面板与底部锚定浮层始终钳制在视口内并跟随锚点。`HoverCard` 通过指针离开宽限期让采用 portal 的预览在跨过锚点间隙时仍可触及,并可通过 `copyText` prop 提供复制按钮。`Toast` 的停留时长由使用方通过 `holdMs` 指定,因为横幅该留多久取决于有多少内容要读;同一个值同时驱动它的卸载定时器与样式表的淡出延迟,两者不可能再错位。`rankByName` 是 `/` 菜单命令源与 skill(技能)源共享的候选排序器:查询必须是名字的不区分大小写的有序子序列;前缀命中排最前,其次按对齐分数,再按来源顺序。 `Menu.autoFocus` 聚焦首个启用项,支持上下方向键与 Home/End 导航,并在 Escape 时聚焦 anchor 内的第一个按钮;操作菜单可显式启用。 ### 渲染 agent 输出 diff --git a/packages/client/ui-settings-general/README.i18n.yaml b/packages/client/ui-settings-general/README.i18n.yaml index bbd3b0ebb8..dfe7e55738 100644 --- a/packages/client/ui-settings-general/README.i18n.yaml +++ b/packages/client/ui-settings-general/README.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 packages/client/ui-settings-general/README.md -README.md: 5f4ba3c29943014860993b092274fd7479dfe7eb -README.zh.md: 8ae02f9c5bfe5af673a3d2f13861089c0cbee054 +README.md: af68c42ad111f74e68037436e18a5be57195a64b +README.zh.md: f929df66a13cde7beb63721922f2a3f4aa90ba43 diff --git a/packages/client/ui-settings-general/README.md b/packages/client/ui-settings-general/README.md index 5f4ba3c299..af68c42ad1 100644 --- a/packages/client/ui-settings-general/README.md +++ b/packages/client/ui-settings-general/README.md @@ -25,7 +25,7 @@ Use this package to give the dsh web client a Settings panel, connection-recover ## Use this package -Users reach the shell through the sidebar's bottom Settings control; feature plugins contribute their pages and onboarding steps through the slot ledgers this shell projects. In both the expanded sidebar and collapsed rail, the control exposes the localized Settings label as its accessible name. A pale-yellow **Disconnected** action beside Settings indicates browser offline suspension; its retry glyph and static label name the retry action directly. Automatic recovery shows a spinner beside **Reconnecting** with one to three dots advancing every 500ms, and an attempt stays visible for at least 800ms so brief retries do not flicker. Selecting either yellow state starts an immediate retry, and the attempt label distinguishes that manual retry from automatic backoff; press feedback stays within the warning palette. Recovery changes the region to pale-green **Connected** for two seconds before it disappears. States fade in and out over 150ms, and the pill sizes to its current label. Initial startup and uninterrupted healthy operation remain silent. The shell renders the modal panel, the navigation built from `settings.section` entries, and exactly one mounted onboarding step at a time. +Users reach the shell through the sidebar's bottom Settings control; feature plugins contribute their pages and onboarding steps through the slot ledgers this shell projects. In both the expanded sidebar and collapsed rail, the control exposes the localized Settings label as its accessible name. A pale-yellow **Disconnected** action beside Settings indicates browser offline suspension; its permanent retry glyph marks the retry action, which the Chinese outage copy also names (连接异常,刷新重试). Every recovery attempt shows a spinner beside **Reconnecting** with one to three dots advancing every 500ms, and an attempt stays visible for at least 800ms so brief retries do not flicker. Selecting either yellow state starts an immediate retry; press feedback stays within the warning palette. Recovery changes the region to pale-green **Connected** for two seconds from the moment the green pill becomes visible. The pill fades in on appearance, fades out over 150ms on removal, and sizes to its current label. Initial startup and uninterrupted healthy operation remain silent. The shell renders the modal panel, the navigation built from `settings.section` entries, and exactly one mounted onboarding step at a time. ### The General section @@ -55,7 +55,7 @@ The navigation is a projection of the `settings.section` ledger; nav labels may ### Connection recovery -The shell is an explicit recovery consumer, so it injects Connection directly rather than adding lifecycle controls to `ctx.remote`. Its private hooks compartment binds `ctx.connection.state`, while the component receives only the selected state and an injected callback for `ctx.connection.reconnect()`. `ConnectionIndicator` owns the inline presentation and receives all visible and accessible copy from the `settings` locale namespace; the shell owns the two-second recovered-state timer, the 800ms minimum-visible hold for the connecting state, and the manual-versus-automatic attempt label choice. +The shell is an explicit recovery consumer, so it injects Connection directly rather than adding lifecycle controls to `ctx.remote`. Its private hooks compartment binds `ctx.connection.state`, while the component receives only the selected state and an injected callback for `ctx.connection.reconnect()`. `ConnectionIndicator` owns the inline presentation and receives all visible and accessible copy from the `settings` locale namespace; the shell owns the 800ms minimum-visible hold for the connecting state and the two-second recovered-state timer, which starts when the recovered pill becomes visible after the hold. ### Document availability diff --git a/packages/client/ui-settings-general/README.zh.md b/packages/client/ui-settings-general/README.zh.md index 8ae02f9c5b..f929df66a1 100644 --- a/packages/client/ui-settings-general/README.zh.md +++ b/packages/client/ui-settings-general/README.zh.md @@ -25,7 +25,7 @@ kind: "package-reference" ## 使用本包 -用户通过侧边栏底部的 Settings 控件进入外壳;功能插件通过本外壳所投影的 slot 账本贡献自己的页面与引导步骤。在展开侧边栏和收起轨道中,该控件都会把本地化的 Settings 文案作为其可访问名称。Settings 右侧浅黄色的**连接异常**操作表示浏览器离线暂停;其重试图形与静态文案本身即指明重试动作。自动恢复期间显示 spinner 加**自动重连中**,其后一至三个点每 500ms 前进一次,且每次尝试至少可见 800ms,短暂重试不会闪动。选中任一黄色状态都会立即发起重试,尝试文案会把这次手动重试与自动退避区分开;按压反馈留在黄色色阶内。恢复后该区域变为浅绿色的**连接成功**,驻留 2 秒再消失。状态以 150ms 淡入淡出,药丸宽度随当前文案自适应。首次启动与未曾中断的健康连接保持静默。外壳渲染模态面板、由 `settings.section` 条目构建的导航,以及每次只挂载一个的引导步骤。 +用户通过侧边栏底部的 Settings 控件进入外壳;功能插件通过本外壳所投影的 slot 账本贡献自己的页面与引导步骤。在展开侧边栏和收起轨道中,该控件都会把本地化的 Settings 文案作为其可访问名称。Settings 右侧浅黄色的**连接异常**操作表示浏览器离线暂停;其常驻重试图形与中文文案「连接异常,刷新重试」都指明重试动作。每次恢复尝试都显示 spinner 加**重新连接中**,其后一至三个点每 500ms 前进一次,且每次尝试至少可见 800ms,短暂重试不会闪动。选中任一黄色状态都会立即发起重试;按压反馈留在黄色色阶内。恢复后该区域变为浅绿色的**连接成功**,从绿色药丸可见起驻留 2 秒再消失。药丸出现时淡入、移除时以 150ms 淡出,宽度随当前文案自适应。首次启动与未曾中断的健康连接保持静默。外壳渲染模态面板、由 `settings.section` 条目构建的导航,以及每次只挂载一个的引导步骤。 ### 「通用」分区 @@ -55,7 +55,7 @@ kind: "package-reference" ### 连接恢复 -外壳是明确的恢复功能消费方,因此直接注入 Connection,而不把生命周期控制放进 `ctx.remote`。它的私有 hooks compartment 绑定 `ctx.connection.state`,组件只接收选出的状态与调用 `ctx.connection.reconnect()` 的注入回调。`ConnectionIndicator` 拥有内联展示并从 `settings` locale namespace 接收全部可见与无障碍文案;2 秒恢复状态计时器、连接中状态的 800ms 最短可见驻留,以及手动与自动尝试文案的选择都归外壳所有。 +外壳是明确的恢复功能消费方,因此直接注入 Connection,而不把生命周期控制放进 `ctx.remote`。它的私有 hooks compartment 绑定 `ctx.connection.state`,组件只接收选出的状态与调用 `ctx.connection.reconnect()` 的注入回调。`ConnectionIndicator` 拥有内联展示并从 `settings` locale namespace 接收全部可见与无障碍文案;连接中状态的 800ms 最短可见驻留与 2 秒恢复确认计时器归外壳所有;恢复计时从驻留结束、恢复药丸实际可见时开始。 ### 文档可用性 diff --git a/packages/client/ui-settings-general/src/client/SettingsRoot.tsx b/packages/client/ui-settings-general/src/client/SettingsRoot.tsx index c7d48b1746..14a93af9bc 100644 --- a/packages/client/ui-settings-general/src/client/SettingsRoot.tsx +++ b/packages/client/ui-settings-general/src/client/SettingsRoot.tsx @@ -117,7 +117,6 @@ export function SettingsRoot(props: SettingsRootComponentProps) { const [completedOnboarding, setCompletedOnboarding] = useState>(() => new Set()) const [showRecovery, setShowRecovery] = useState(false) const [holdConnecting, setHoldConnecting] = useState(false) - const [manualRetry, setManualRetry] = useState(false) const connectingShownAt = useRef(undefined) const triggerButton = useRef(null) const wasOpen = useRef(open) @@ -163,16 +162,21 @@ export function SettingsRoot(props: SettingsRootComponentProps) { } if (previous !== 'disconnected' && previous !== 'connecting') return setShowRecovery(true) + }, [connectionState]) + + // The confirmation window starts when the recovered pill becomes visible, + // which the connecting minimum-visible hold can delay past the transition. + useLayoutEffect(() => { + if (!showRecovery || holdConnecting) return const timeout = window.setTimeout(() => { setShowRecovery(false) }, RECOVERY_CONFIRMATION_MS) return () => { window.clearTimeout(timeout) } - }, [connectionState]) + }, [showRecovery, holdConnecting]) useLayoutEffect(() => { if (connectionState === 'connecting') { connectingShownAt.current = Date.now() return } - setManualRetry(false) const shownAt = connectingShownAt.current if (shownAt === undefined) return connectingShownAt.current = undefined @@ -186,11 +190,6 @@ export function SettingsRoot(props: SettingsRootComponentProps) { } }, [connectionState]) - const manualReconnect = useCallback(() => { - setManualRetry(true) - reconnect() - }, [reconnect]) - const completeOnboardingStep = useCallback((id: string) => { setCompletedOnboarding((previous) => { if (previous.has(id)) return previous @@ -224,11 +223,11 @@ export function SettingsRoot(props: SettingsRootComponentProps) { {open && ( diff --git a/packages/client/ui-settings-general/src/client/locales.ts b/packages/client/ui-settings-general/src/client/locales.ts index f23b673325..8f28b1710f 100644 --- a/packages/client/ui-settings-general/src/client/locales.ts +++ b/packages/client/ui-settings-general/src/client/locales.ts @@ -9,11 +9,10 @@ export const zh = { 'openDocument.error': '无法打开配置文件', 'general.nav': '通用设置', 'connection.error': '连接异常,刷新重试', - 'connection.connecting': '自动重连中', - 'connection.reconnecting': '重新连接中', + 'connection.connecting': '重新连接中', 'connection.connected': '连接成功', 'connection.reconnect': '连接异常,点击立即重连', - 'connection.restart': '连接中断,正在自动重试,点击立即重连', + 'connection.restart': '连接中断,正在重试,点击立即重连', } satisfies Record /** The settings namespace key union. */ @@ -29,8 +28,7 @@ export const en = { 'general.nav': 'General', 'connection.error': 'Disconnected', 'connection.connecting': 'Reconnecting', - 'connection.reconnecting': 'Reconnecting', 'connection.connected': 'Connected', 'connection.reconnect': 'Disconnected, reconnect now', - 'connection.restart': 'Reconnecting automatically, reconnect now', + 'connection.restart': 'Reconnecting, reconnect now', } satisfies Record diff --git a/packages/client/ui-settings-general/tests/apply.client.spec.ts b/packages/client/ui-settings-general/tests/apply.client.spec.ts index b9c2de2a9b..c1f5428a30 100644 --- a/packages/client/ui-settings-general/tests/apply.client.spec.ts +++ b/packages/client/ui-settings-general/tests/apply.client.spec.ts @@ -119,7 +119,7 @@ describe('ui-settings-general apply', () => { const t = c.ctx.locale.bind(NS) expect(t('title')).toBe('设置') expect(t('connection.error')).toBe('连接异常,刷新重试') - expect(t('connection.connecting')).toBe('自动重连中') + expect(t('connection.connecting')).toBe('重新连接中') expect(t('connection.connected')).toBe('连接成功') c.ctx.locale.setLocale('en') expect(t('close')).toBe('Close') diff --git a/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx b/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx index 01a15df743..01bc43a45b 100644 --- a/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx +++ b/packages/client/ui-settings-general/tests/settings-root.client.spec.tsx @@ -162,7 +162,7 @@ describe('SettingsRoot trigger', () => { expect(mounted.reconnect).toHaveBeenCalledOnce() mounted.setConnectionState('connecting') - expect(screen.getByRole('button', { name: 'Reconnecting automatically, reconnect now' }).textContent) + expect(screen.getByRole('button', { name: 'Reconnecting, reconnect now' }).textContent) .toContain('Reconnecting...') // An attempt that resolves instantly still shows the connecting pill for @@ -171,7 +171,8 @@ describe('SettingsRoot trigger', () => { expect(screen.queryByRole('status')).toBeNull() act(() => { vi.advanceTimersByTime(800) }) expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() - act(() => { vi.advanceTimersByTime(1_199) }) + // The confirmation window is measured from visibility, not the transition. + act(() => { vi.advanceTimersByTime(1_999) }) expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() // The confirmation window closes at 2s, then the pill fades for 150ms. act(() => { vi.advanceTimersByTime(1) }) @@ -179,18 +180,40 @@ describe('SettingsRoot trigger', () => { expect(screen.queryByRole('status')).toBeNull() }) - it('names automatic and manual retry attempts and confirms at once after a long attempt', () => { + it('keeps the attempt label steady through the hold and confirms for the full window', () => { vi.useFakeTimers() const mounted = mount({ dictionary: zh }) mounted.setConnectionState('connecting') - const attempt = screen.getByRole('button', { name: '连接中断,正在自动重试,点击立即重连' }) - expect(attempt.textContent).toContain('自动重连中') + const attempt = screen.getByRole('button', { name: '连接中断,正在重试,点击立即重连' }) + expect(attempt.textContent).toContain('重新连接中') fireEvent.click(attempt) expect(mounted.reconnect).toHaveBeenCalledOnce() expect(attempt.textContent).toContain('重新连接中') + // An attempt that resolves mid-hold keeps its label until the hold ends. + act(() => { vi.advanceTimersByTime(100) }) + mounted.setConnectionState('connected') + expect(screen.getByRole('button', { name: '连接中断,正在重试,点击立即重连' }).textContent) + .toContain('重新连接中') + act(() => { vi.advanceTimersByTime(700) }) + expect(screen.getByRole('status', { name: '连接成功' })).toBeTruthy() + // The full two-second confirmation follows the delayed appearance. + act(() => { vi.advanceTimersByTime(1_999) }) + expect(screen.getByRole('status', { name: '连接成功' })).toBeTruthy() + act(() => { vi.advanceTimersByTime(1) }) + act(() => { vi.advanceTimersByTime(150) }) + expect(screen.queryByRole('status')).toBeNull() + }) + + it('skips the hold when the attempt already stayed visible long enough', () => { + vi.useFakeTimers() + const mounted = mount() + mounted.setConnectionState('connecting') act(() => { vi.advanceTimersByTime(800) }) mounted.setConnectionState('connected') - expect(screen.getByRole('status', { name: '连接成功' })).toBeTruthy() + expect(screen.getByRole('status', { name: 'Connected' })).toBeTruthy() + act(() => { vi.advanceTimersByTime(2_000) }) + act(() => { vi.advanceTimersByTime(150) }) + expect(screen.queryByRole('status')).toBeNull() }) it('keeps the reconnect indicator out of the collapsed rail', () => { diff --git a/snapshots/web/lifecycle-chrome/connection-error.expected.md b/snapshots/web/lifecycle-chrome/connection-error.expected.md index c14269d3ed..d8526e9a57 100644 --- a/snapshots/web/lifecycle-chrome/connection-error.expected.md +++ b/snapshots/web/lifecycle-chrome/connection-error.expected.md @@ -1,4 +1,4 @@ - button "Settings": - img - text: Settings -- button "Reconnecting automatically, reconnect now": Reconnecting +- button "Reconnecting, reconnect now": Reconnecting From 96ee6e49f98997eb40c40946b7279949c48d26cc Mon Sep 17 00:00:00 2001 From: turtle1999 <301751225+turtle1999@users.noreply.github.com> Date: Fri, 11 Sep 2026 13:22:14 +0800 Subject: [PATCH 10/14] test(terminal): await PowerShell prompt delivery --- packages/terminal/terminal-bash/tests/local.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/terminal/terminal-bash/tests/local.spec.ts b/packages/terminal/terminal-bash/tests/local.spec.ts index 9800a79d54..2cf46dd9c2 100644 --- a/packages/terminal/terminal-bash/tests/local.spec.ts +++ b/packages/terminal/terminal-bash/tests/local.spec.ts @@ -330,7 +330,9 @@ describe.skipIf(!hasPwsh)('terminal-bash pwsh real shell', () => { timeoutMs: 8_000, }, 'pwsh') const created = await ctx.terminals.spawn(agent, { type: 'shell', name: 'main', cwd: root }) - expect(created.motd).toContain('dsh> ') + // stdin_read can precede delivery of the printable prompt to the PTY reader. + await expect.poll(() => ctx.terminals.read(agent, created.sessionId, { offset: 0, count: 100 }).text, + { timeout: 8_000 }).toContain('dsh> ') const releaseFile = join(root, 'release-command') // Hold the command across the silence settlement without relying on host load. From 40e39f467365c7aef02d55acbde3b8ac4a5c5049 Mon Sep 17 00:00:00 2001 From: turtle1999 <301751225+turtle1999@users.noreply.github.com> Date: Fri, 11 Sep 2026 13:31:22 +0800 Subject: [PATCH 11/14] test(ci): control Python stray UTF-8 fragment delivery --- .../code-runtime-python/tests/runtime.spec.ts | 100 ------------------ .../tests/stray-fragments.spec.ts | 31 ++++++ 2 files changed, 31 insertions(+), 100 deletions(-) diff --git a/packages/experimental/code-runtime-python/tests/runtime.spec.ts b/packages/experimental/code-runtime-python/tests/runtime.spec.ts index 1f3fd6cb1e..287cf8f785 100644 --- a/packages/experimental/code-runtime-python/tests/runtime.spec.ts +++ b/packages/experimental/code-runtime-python/tests/runtime.spec.ts @@ -1494,106 +1494,6 @@ describe('PythonCodeRuntime — programs and bindings', () => { await fiber.dispose() }) - it('bounds an illegal-UTF-8 native residual by its U+FFFD-decoded cost', async () => { - // Every 0xFF byte is illegal in any UTF-8 sequence, so `toString('utf8')` - // renders each as U+FFFD (3 serialized bytes). `accrueStrayCost` must charge - // that 3, not the raw 1: otherwise the newline-free residual grows to a full - // budget's worth of RAW bytes before flushing — a ~3x undercount that near a - // large maxLogBytes retains hundreds of MiB then expands toward a ~1 GiB peak - // in flushStray's concat + toString. Paced single-byte writes (each its own - // `data` chunk, like the sealing case) expose the sub-chunk accrual: charged - // at 3 the residual crosses a 3072-byte budget after ~1024 bytes and flushes; - // charged at 1 it would need ~3072 bytes, so the peak residual triples. The - // largest merged buffer is the discriminator. - const realConcat = Buffer.concat.bind(Buffer) - let maxConcat = 0 - Buffer.concat = (list: readonly Uint8Array[], total?: number): Buffer => { - const merged = realConcat(list, total) - if (merged.length > maxConcat) maxConcat = merged.length - return merged - } - let result: CodeRunResult - try { - const { runtime } = await setup({ maxLogBytes: 3072, maxWallMs: 30_000 }) - result = await runtime.run({ - program: [ - 'import os, time', - // One byte per chunk on every host: a plain yield lets a loaded - // reader coalesce, and the coalesced chunk is what the bound below - // measures. The payload stays above the 2048 discriminator, so a - // raw-byte undercount still flushes the whole residual at EOF. - 'for _ in range(3200):', - ' os.write(1, b"\\xff")', - ' time.sleep(0.001)', - 'return None', - ].join('\n'), - bindings: [], - }) - } finally { - Buffer.concat = realConcat - } - expect(result.error).toBeUndefined() - expect(result.logs.at(-1)).toBe(logTruncationMarker(3072)) - // Charged at 3, the residual flushes around 1024 raw bytes; the largest - // merged buffer stays well under 2048. A raw-byte undercount would let it - // reach ~3072 before flushing, so 2048 discriminates. - expect(maxConcat).toBeLessThan(2048) - // The paced payload costs ~3.2s deterministically, which is above the - // 5000ms default the local unit entry grants, so the case carries its own - // bound instead of relying on the lane to widen it. - }, 20_000) - - it('charges a structurally-valid but illegal UTF-8 sequence its U+FFFD-decoded cost', async () => { - // A CESU-8 lone surrogate `ED A0 80` is structurally well-formed (a 3-byte - // lead plus two 0x80–0xBF continuations) but ILLEGAL: `toString('utf8')` - // renders each of the three bytes as its own U+FFFD (serialized cost 9), not - // one width-3 character. The newline-free flush trigger weighs the residual - // through `accrueStrayCost`, which must validate each lead's - // first-continuation range (ED excludes A0–BF) and charge the true 9 — else a - // CESU flood undercounts 3x and the residual grows toward a full budget's raw - // bytes before flushing, the same peak-memory vector as the 0xFF case. The - // bytes are written one at a time (each its own `data` chunk, no pipe - // coalescing) and `Buffer.concat` is wrapped to measure the peak residual. - const realConcat = Buffer.concat.bind(Buffer) - let maxConcat = 0 - Buffer.concat = (list: readonly Uint8Array[], total?: number): Buffer => { - const merged = realConcat(list, total) - if (merged.length > maxConcat) maxConcat = merged.length - return merged - } - let result: CodeRunResult - try { - const { runtime } = await setup({ maxLogBytes: 3072, maxWallMs: 30_000 }) - result = await runtime.run({ - program: [ - 'import os, time', - 'seq = (0xed, 0xa0, 0x80)', - // 1100 sequences are 3300 raw bytes, past the 3072-byte budget a - // raw-byte undercount reaches, so the undercount flushes above the - // 2048 discriminator instead of only at EOF. - 'for _ in range(1100):', - ' for b in seq:', - ' os.write(1, bytes((b,)))', - ' time.sleep(0.001)', - 'return None', - ].join('\n'), - bindings: [], - }) - } finally { - Buffer.concat = realConcat - } - expect(result.error).toBeUndefined() - expect(result.logs.at(-1)).toBe(logTruncationMarker(3072)) - // Each 3-byte sequence costs 9 (three U+FFFD), so single-byte-paced the - // residual crosses the 3072 budget after ~342 raw bytes and flushes; the - // largest merged buffer stays well under 2048. Charging the structural width - // 3 would need ~1024 raw bytes, tripling the peak past 2048. - expect(maxConcat).toBeLessThan(2048) - // The paced payload costs ~3.3s deterministically, which is above the - // 5000ms default the local unit entry grants, so the case carries its own - // bound instead of relying on the lane to widen it. - }, 20_000) - it('charges a lone surrogate its full six escaped bytes, not three', async () => { // A forged `log` frame carrying `\ud800` escapes materializes lone // surrogates after JSON.parse. `Buffer.byteLength` of U+FFFD is 3, but diff --git a/packages/experimental/code-runtime-python/tests/stray-fragments.spec.ts b/packages/experimental/code-runtime-python/tests/stray-fragments.spec.ts index 9ed70c558b..500082b238 100644 --- a/packages/experimental/code-runtime-python/tests/stray-fragments.spec.ts +++ b/packages/experimental/code-runtime-python/tests/stray-fragments.spec.ts @@ -1,5 +1,6 @@ import { Context } from '@deepseek-ai/cordis' import { expect, it, vi } from 'vitest' +import { logTruncationMarker } from '../src/protocol.ts' // Keep the interpreter and pipe lifecycle real; only OS-dependent read sizes // change. Each byte reaches the runtime as its own data event. @@ -54,3 +55,33 @@ it('seals stray fragments without recopying the sealed prefix', async () => { await fiber.dispose() } }, 40_000) + +it.each([ + { name: 'illegal UTF-8 bytes', payload: 'b"\\xff" * 3200' }, + { name: 'CESU-8 lone surrogates', payload: 'b"\\xed\\xa0\\x80" * 1100' }, +])('bounds $name by their U+FFFD-decoded cost', async ({ payload }) => { + const ctx = new Context() + const fiber = await ctx.plugin(PythonCodeRuntime, { maxLogBytes: 3072, maxWallMs: 30_000 }) + const realConcat = Buffer.concat.bind(Buffer) + let maxConcat = 0 + const concat = vi.spyOn(Buffer, 'concat').mockImplementation((list, total) => { + const merged = realConcat(list, total) + maxConcat = Math.max(maxConcat, merged.length) + return merged + }) + try { + const result = await ctx.codeRuntime.run({ + program: `import os\nos.write(1, ${payload})\nreturn None`, + bindings: [], + }) + expect(result.error).toBeUndefined() + expect(result.logs.at(-1)).toBe(logTruncationMarker(3072)) + // Each raw byte decodes to U+FFFD (three UTF-8 bytes), so a 3072-byte + // budget flushes near 1024 raw bytes. Charging raw or structural widths + // instead retains over 2048 bytes before flushing these payloads. + expect(maxConcat).toBeLessThan(2048) + } finally { + concat.mockRestore() + await fiber.dispose() + } +}, 20_000) From eb9da8930e2752e4d4bc8927be03c9386da83fca Mon Sep 17 00:00:00 2001 From: turtle1999 Date: Fri, 11 Sep 2026 14:34:17 +0800 Subject: [PATCH 12/14] test(boot): cover Web failure recovery and inject module routes --- ...onsumer-owned-startup-strictness.i18n.yaml | 4 +- ...09-09-consumer-owned-startup-strictness.md | 4 + ...09-consumer-owned-startup-strictness.zh.md | 4 + apps/cli/README.i18n.yaml | 4 +- apps/cli/README.md | 2 + apps/cli/README.zh.md | 2 + .../tests/web-failure-matrix.expected.e2e.ts | 404 ++++++++++++++++++ packages/client/modules/README.i18n.yaml | 4 +- packages/client/modules/README.md | 2 + packages/client/modules/README.zh.md | 2 + packages/client/modules/src/index.ts | 4 +- .../modules/tests/node-half.client.spec.ts | 58 ++- 12 files changed, 477 insertions(+), 17 deletions(-) create mode 100644 apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts diff --git a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml index e3d96b6365..1b6639b303 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.i18n.yaml +++ b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.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 .agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md -2026-09-09-consumer-owned-startup-strictness.md: 8e3d5f0141245ba2fa2c85faba607ac1be952e37 -2026-09-09-consumer-owned-startup-strictness.zh.md: 3873b9ceeb6204939e817a53514f5e18767ececc +2026-09-09-consumer-owned-startup-strictness.md: e009e66ead25ef0a5e6001d33663e32bc04d19d2 +2026-09-09-consumer-owned-startup-strictness.zh.md: 58c364056f5b0dc41e018cd5488be983662401d4 diff --git a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md index 8e3d5f0141..e009e66ead 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md +++ b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.md @@ -33,3 +33,7 @@ Stable required entry ids are part of application assembly. Renaming one require ## Testing App-boot unit tests cover absent and disabled required ids, optional import failure, config evaluation failure, synchronous and asynchronous `apply()` failure, pending dependencies, and required failure teardown. The built Web-profile acceptance serves the full UI with optional failures and exits nonzero without readiness when the required HTTP port is occupied or `modules` or `connection` cannot activate. + +The [Web process matrix](../../../../apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts) independently exercises optional and required failures at startup and after native patch-file edits. Authenticated HTTP requests and plugin lifecycle files distinguish a usable application from a surviving process. These keyless process checks complement the [controlled-delivery unit tests](../testing/2026-09-09-user-patch-hmr-test-delivery.md): unit tests isolate reconciliation failures, while the process tests also require the shipped launcher, native watcher, and bounded shutdown to work together. + +The matrix enables Chokidar's `awaitWriteFinish` to acknowledge stable file contents before each reload; otherwise its short change-event suppression window can discard the next test edit. Native events remain required, and assertions wait for observed activation or failure rather than a fixed settling sleep. This is explicit test configuration, not evidence for the default watcher timing. diff --git a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md index 3873b9ceeb..58c364056f 100644 --- a/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md +++ b/.agents/notes/implemented/architecture/2026-09-09-consumer-owned-startup-strictness.zh.md @@ -33,3 +33,7 @@ Required id 为 `agent-loop`、`webserver`、`modules`、`connection`、`headles ## 测试 App-boot 单元测试覆盖缺失和禁用的 required id、optional import failure、config evaluation failure、同步和异步 `apply()` failure、pending dependency,以及 required failure teardown。构建后的 Web-profile acceptance 会在 optional failure 存在时继续提供完整 UI,并在 required HTTP port 被占用或 `modules`、`connection` 无法激活时以非零码退出,且不报告就绪。 + +[Web 进程矩阵](../../../../apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts)分别验证启动时和原生补丁文件修改后的 optional 与 required 失败。经过认证的 HTTP 请求和插件生命周期文件区分可用应用与仅存活的进程。这些无需密钥的进程检查与[受控事件投递单元测试](../testing/2026-09-09-user-patch-hmr-test-delivery.zh.md)互补:单元测试隔离配置协调失败,进程测试还要求随附启动器、原生监听器和有界关闭流程协同工作。 + +矩阵启用 Chokidar 的 `awaitWriteFinish`,在每次重载前确认文件内容已稳定;否则它的短暂 change 事件抑制窗口可能丢弃下一次测试编辑。测试仍然依赖原生事件,并等待观察到激活或失败,而不是固定时长的休眠。这是显式测试配置,不能证明默认监听器的时序行为。 diff --git a/apps/cli/README.i18n.yaml b/apps/cli/README.i18n.yaml index cfded686cf..0b46922994 100644 --- a/apps/cli/README.i18n.yaml +++ b/apps/cli/README.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 apps/cli/README.md -README.md: 2e74ef68cf0b8487083a2e2af0f5175c78ec5212 -README.zh.md: 553f28f3af78b18658701449678de80b086dbb15 +README.md: f5566281ab8164cf8e88c424ad5c41a22afe4444 +README.zh.md: b2cae164c639157dc4ea3fa8c83a2b52fce57707 diff --git a/apps/cli/README.md b/apps/cli/README.md index 2e74ef68cf..f5566281ab 100644 --- a/apps/cli/README.md +++ b/apps/cli/README.md @@ -54,3 +54,5 @@ The [CLI behavior reference](reference/README.md) owns exact layer precedence, f ## Development Production runs require built package and frontend artifacts. From the repository root, run `pnpm run build` separately, then use `pnpm dsh ` to run the TypeScript entry and forward every argument; the [source-execution reference](reference/README.md#source-execution) owns the module-resolution contract. + +The [Web failure matrix](tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts) runs the built CLI through startup failures and native configuration HMR with `awaitWriteFinish` enabled in `test:expected`. It verifies authenticated HTTP responses, diagnostics, recovery, process exits, and disposal without model API calls; the [startup acceptance](tests/profiles/web/tests/web-best-effort-startup.expected.e2e.ts) also covers the shipped required Web dependencies and port conflicts. diff --git a/apps/cli/README.zh.md b/apps/cli/README.zh.md index 553f28f3af..b2cae164c6 100644 --- a/apps/cli/README.zh.md +++ b/apps/cli/README.zh.md @@ -54,3 +54,5 @@ profile 目录包含一个 `package.json`,其中记录树外插件依赖,以 ## 开发 生产运行需要已构建的包与前端产物。请在仓库根目录单独运行 `pnpm run build`,然后使用 `pnpm dsh ` 运行 TypeScript 入口并转发所有参数;模块解析约定以[源码执行参考](reference/README.zh.md#source-execution)为准。 + +[Web 失败矩阵](tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts)在 `test:expected` 中通过构建后的 CLI 验证启动失败与启用 `awaitWriteFinish` 的原生配置 HMR。它不调用模型 API,而是检查经过认证的 HTTP 响应、诊断、恢复、进程退出与 dispose;[启动验收测试](tests/profiles/web/tests/web-best-effort-startup.expected.e2e.ts)还覆盖随附 Web 的必需依赖与端口冲突。 diff --git a/apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts b/apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts new file mode 100644 index 0000000000..d2d14a5ada --- /dev/null +++ b/apps/cli/tests/profiles/web/tests/web-failure-matrix.expected.e2e.ts @@ -0,0 +1,404 @@ +/** Failure policy through the built Web process and native configuration watcher. */ + +import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { createServer } from 'node:http' +import { join } from 'node:path' +import { fileURLToPath, pathToFileURL } from 'node:url' +import { execa } from 'execa' +import { describe, expect, it } from 'vitest' +import { FiberState } from '@deepseek-ai/cordis' + +const repoRoot = fileURLToPath(new URL('../../../../../../', import.meta.url)) +const bin = join(repoRoot, 'apps/cli/lib/bin.js') +const built = existsSync(bin) && existsSync(join(repoRoot, 'apps/web/dist/index.html')) +const failures = [ + ['import', 'missing.mjs'], + ['module evaluation', 'matrix module evaluation'], + ['schema', 'matrix schema failure'], + ['config expression', 'matrix config expression'], + ['disabled expression', 'matrix disabled expression'], + ['sync apply', 'matrix sync apply'], + ['async apply', 'matrix async apply'], + ['dependency', 'matrixMissingService'], +] as const +type Failure = typeof failures[number][0] + +function fixture() { + const root = mkdtempSync(join(tmpdir(), 'dsh-web-failure-matrix-')) + const home = join(root, 'home') + mkdirSync(home) + const events = join(root, 'events') + const diagnostics = join(root, 'diagnostics') + const serverUrl = join(root, 'server-url') + const states = join(root, 'states') + const stop = join(root, 'stop') + const patch = join(home, 'cordis.patch.yml') + const watcher = join(root, 'watcher.patch.yml') + // Native delivery remains real; completed writes bypass Chokidar's 50 ms change suppression. + writeFileSync(watcher, JSON.stringify([{ id: 'hmr', disabled: false, config: { + root: [], awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 20 }, + } }]) + '\n') + writeFileSync(events, '') + writeFileSync(diagnostics, '') + writeFileSync(states, '{}') + const observerPath = join(root, 'observer.mjs') + // HMR reports through Cordis logger exporters; WARN is above their default INFO threshold. + writeFileSync(observerPath, [ + "import { appendFileSync, writeFileSync, renameSync, rmSync } from 'node:fs'", + "import { inspect } from 'node:util'", + 'export function apply(ctx, config) {', + ' const report = message => appendFileSync(config.path, message.args.map(arg => inspect(arg)).join(" ") + "\\n")', + ' ctx.logger.buffer.forEach(report)', + ' ctx.logger.exporter({ levels: { default: 3 }, export: report })', + ' const timer = setInterval(() => {', + ' const loader = ctx.get("loader")', + ' if (!loader) return', + ' writeFileSync(config.states + ".tmp", JSON.stringify(Object.fromEntries([...loader.entries()].map(entry => [entry.options.id, entry.fiber?.state]))))', + ' renameSync(config.states + ".tmp", config.states)', + ' }, 20)', + ' ctx.effect(() => () => { clearInterval(timer) })', + ' ctx.inject(["webServer", "connection"], scope => {', + ' writeFileSync(config.url, scope.connection.authenticatedUrl(`http://127.0.0.1:${scope.webServer.port}`))', + ' scope.effect(() => () => { rmSync(config.url, { force: true }) })', + ' })', + '}', + '', + ].join('\n')) + const observer = { id: 'matrix-log-observer', name: pathToFileURL(observerPath).href, config: { path: diagnostics, url: serverUrl, states } } + const plugin = join(root, 'probe.mjs') + writeFileSync(plugin, [ + "import { appendFileSync, existsSync } from 'node:fs'", + 'export const Config = { "~standard": { version: 1, vendor: "matrix", validate(value) {', + ' return value.mode === "schema" ? { issues: [{ message: "matrix schema failure" }] } : { value }', + '} } }', + 'export const apply = (ctx, config) => {', + ' if (config.mode === "sync apply") throw new Error("matrix sync apply")', + ' return activate(ctx, config)', + '}', + 'async function activate(ctx, config) {', + ' if (config.mode === "async apply") { await Promise.resolve(); throw new Error("matrix async apply") }', + ' if (config.provider) ctx.provide(config.provider, true)', + ' if (config.mode === "detached") setImmediate(() => { void Promise.reject(new Error("matrix detached failure")) })', + ' appendFileSync(config.events, `${config.label} apply ${config.generation}\\n`)', + ' const timer = setInterval(() => { if (existsSync(config.stop)) process.emit("SIGTERM") }, 20)', + ' ctx.effect(() => () => { clearInterval(timer); appendFileSync(config.events, `${config.label} dispose ${config.generation}\\n`) })', + '}', + '', + ].join('\n')) + writeFileSync(join(root, 'evaluation.mjs'), 'throw new Error("matrix module evaluation")\n') + const url = pathToFileURL(plugin).href + const config = (label: string, generation: number, mode = '') => ({ label, generation, mode, events, stop }) + const witness = (generation: number) => ({ id: 'matrix-witness', name: url, config: config('witness', generation) }) + const target = (id: string, failure?: Failure, generation = 1) => ({ + id, + name: failure === 'import' ? pathToFileURL(join(root, 'missing.mjs')).href + : failure === 'module evaluation' ? pathToFileURL(join(root, 'evaluation.mjs')).href : url, + ...(failure === 'dependency' ? { inject: ['matrixMissingService'] } : {}), + config: config('target', generation, failure), + }) + const render = (id: string, failure?: Failure, generation = 1) => { + let text = `- insert: ${JSON.stringify([observer, witness(generation), target(id, failure, generation)])}` + if (failure === 'config expression') text += `\n- id: ${id}\n config: !!js "(() => { throw new Error('matrix config expression') })()"\n` + if (failure === 'disabled expression') text += `\n- id: ${id}\n disabled: !!js "(() => { throw new Error('matrix disabled expression') })()"\n` + return text + '\n' + } + writeFileSync(patch, JSON.stringify([{ insert: [observer, witness(0)] }]) + '\n') + return { root, home, events, diagnostics, serverUrl, states, observer, stop, patch, watcher, render, url, config, witness, target } +} + +function start(f: ReturnType, extra: string[] = []) { + const child = execa(process.execPath, [bin, '--profile', 'web', '--patch', f.watcher, ...extra, '--no-open', '--port', '0'], { + cwd: f.root, + env: { ...process.env, DSH_HOME: f.home, DSH_AGENTS_HOME: join(f.root, '.agents'), DSH_TELEMETRY_DISABLED: '1', DEEPSEEK_API_KEY: 'keyless-matrix-no-call', NODE_NO_WARNINGS: '1' }, + input: '', reject: false, timeout: 110_000, killSignal: 'SIGKILL', + }) + let stdout = '' + let stderr = '' + child.stdout?.setEncoding('utf8').on('data', (text: string) => { stdout += text }) + child.stderr?.setEncoding('utf8').on('data', (text: string) => { stderr += text }) + let exited = false + void child.then(() => { exited = true }) + async function wait(predicate: () => boolean) { + try { + await expect.poll(() => { + if (exited) throw new Error('Web process exited') + return predicate() + }, { timeout: 45_000 }).toBe(true) + } catch (cause) { throw new Error(`Web condition failed\n${stdout}\n${stderr}\n${readFileSync(f.diagnostics, 'utf8')}\n${readFileSync(f.events, 'utf8')}`, { cause }) } + } + async function serves(currentServer = false) { + await wait(() => /dsh web: http:\/\//u.test(stdout)) + const url = currentServer ? readFileSync(f.serverUrl, 'utf8') : /dsh web: (http:\/\/[^\s]+)/u.exec(stdout)?.[1] + if (!url) throw new Error('Missing Web URL') + const auth = await fetch(url, { redirect: 'manual', signal: AbortSignal.timeout(10_000) }) + const cookie = auth.headers.get('set-cookie')?.split(';', 1)[0] + if (!cookie) throw new Error('Missing Web authentication cookie') + const response = await fetch(new URL('/', url), { headers: { cookie }, signal: AbortSignal.timeout(10_000) }) + expect(response.status).toBe(200) + const html = await response.text() + expect(html).toContain('__DSH_BOOT__') + const bundlePath = /