From 0a25c0d2371eb3ecc84545ae5241821e2f2961f1 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 30 Jul 2026 16:41:55 +0800 Subject: [PATCH 01/10] feat(web): add queue collapse control --- ...-29-addressable-queue-operations.i18n.yaml | 4 +- ...2026-07-29-addressable-queue-operations.md | 4 +- ...6-07-29-addressable-queue-operations.zh.md | 4 +- apps/web/tests/queue-actions.e2e.ts | 4 + .../queue-actions/editing.expected.md | 1 + .../client/ui-conversation/README.i18n.yaml | 4 +- packages/client/ui-conversation/README.md | 2 + packages/client/ui-conversation/README.zh.md | 2 + .../src/client/queue/QueueDock.module.css | 39 ++++ .../src/client/queue/QueueDock.tsx | 190 ++++++++++-------- .../ui-conversation/tests/queue-dock.spec.tsx | 33 ++- 11 files changed, 190 insertions(+), 97 deletions(-) diff --git a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.i18n.yaml b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.i18n.yaml index 85befa1383..3524737277 100644 --- a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.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-07-29-addressable-queue-operations.md -2026-07-29-addressable-queue-operations.md: 78a7d346163bb7e5e76c989c6e93576b4a6cee64 -2026-07-29-addressable-queue-operations.zh.md: 050b9755ad4ebe70e2bdcafb711ef279331e27af +2026-07-29-addressable-queue-operations.md: 28570be7a2a520fd8293a73526302122740823ca +2026-07-29-addressable-queue-operations.zh.md: eb62d45c6572cd993fedf982d6c86e2ff19787a6 diff --git a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md index 78a7d34616..28570be7a2 100644 --- a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md +++ b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md @@ -18,7 +18,7 @@ The Web queue rendered pending messages but could not edit or delete one row. `M **Queue addresses require a live Agent.** `session.updateQueue` queries only the mounted Agent registry and never resumes a cold session: an `InboxItemId` is process-local and cannot name work after restart or disposal. A missing Agent and a driver-claimed occurrence both return `queue-item-not-found`. -**Web actions address Queue only.** The Host excludes pending steering from `session/queue`; steering retains its existing durable transcript path after consumption. QueueDock exposes edit and delete, but no send-now control. The UI derives queue row and mutation types from the runtime `SessionFace` contract rather than importing the connection plugin, so plugin cooperation continues through services and snapshots. Edit is available only when all content blocks are text; the editor cannot silently drop non-text blocks. An editing row exposes only save and cancel, with Enter and Escape as their keyboard equivalents. Delete removes the exact occurrence. +**Web actions address Queue only.** The Host excludes pending steering from `session/queue`; steering retains its existing durable transcript path after consumption. QueueDock hides while empty, renders one pending occurrence directly, and defaults two or more occurrences to a collapsed `" Queued"` header that expands or collapses the complete list. The header exposes `aria-expanded`. Visible rows expose edit and delete, but no send-now control. The UI derives queue row and mutation types from the runtime `SessionFace` contract rather than importing the connection plugin, so plugin cooperation continues through services and snapshots. Edit is available only when all content blocks are text; the editor cannot silently drop non-text blocks. An editing row exposes only save and cancel, with Enter and Escape as their keyboard equivalents. Delete removes the exact occurrence. ## Alternatives considered @@ -34,7 +34,7 @@ The Web queue rendered pending messages but could not edit or delete one row. `M ## Verification -AgentLoop contract tests hold prompt admission while editing and removing exact queued occurrences, reject mutations of steering occurrences, and verify the resulting independent turn and terminal lifecycle events. Host schema and proxy tests cover queued-only authoritative snapshots, synchronous re-entrant mutation order, reconnect, cold-Agent rejection, typed not-found errors, and the RPC transport. Client runtime and QueueDock tests cover non-optimistic projection, text-only editing, save and cancel affordances, removal, retirement races, and disabled mixed-content editing. Keyless browser scenarios drive the exposed edit and delete actions through the built Web composition and real HTTP/SSE wire. +AgentLoop contract tests hold prompt admission while editing and removing exact queued occurrences, reject mutations of steering occurrences, and verify the resulting independent turn and terminal lifecycle events. Host schema and proxy tests cover queued-only authoritative snapshots, synchronous re-entrant mutation order, reconnect, cold-Agent rejection, typed not-found errors, and the RPC transport. Client runtime and QueueDock tests cover non-optimistic projection, single-row presentation, default multi-row collapse, expansion, text-only editing, save and cancel affordances, removal, retirement races, and disabled mixed-content editing. Keyless browser scenarios expand the queue and drive its exposed edit and delete actions through the built Web composition and real HTTP/SSE wire. ## Consequences diff --git a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md index 050b9755ad..eb62d45c65 100644 --- a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md +++ b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md @@ -18,7 +18,7 @@ Web 队列能够渲染待处理消息,但无法编辑或删除其中某一行 **Queue 寻址要求 Agent 存活。** `session.updateQueue` 只查询已挂载的 Agent 注册表,绝不恢复冷会话:`InboxItemId` 属于进程本地标识,无法在重启或资源释放后继续指向工作。Agent 缺失和单次入队项已被驱动器认领这两种情况都返回 `queue-item-not-found`。 -**Web 操作只面向 Queue。** Host 从 `session/queue` 中排除待处理 steering;steering 消费后仍沿用既有的持久 transcript(文本记录)路径。QueueDock 暴露编辑和删除,不提供立即发送控件。UI 从运行时 `SessionFace` 契约派生队列行与变更类型,而不是导入连接插件,因此插件仍通过服务和快照协作。仅当所有内容块都是文本时才提供编辑功能;编辑器不能静默丢弃非文本块。编辑中的行只展示保存和取消操作,对应的键盘操作分别是 Enter 和 Escape。删除会移除对应的精确入队项。 +**Web 操作只面向 Queue。** Host 从 `session/queue` 中排除待处理 steering;steering 消费后仍沿用既有的持久 transcript(文本记录)路径。QueueDock 在队列为空时隐藏,只有一个待处理项时直接渲染该行,存在两个或更多待处理项时则默认收起为可展开或收起完整列表的 `" Queued"` 表头。表头暴露 `aria-expanded`。可见行暴露编辑和删除操作,不提供立即发送控件。UI 从运行时 `SessionFace` 契约派生队列行与变更类型,而不是导入连接插件,因此插件仍通过服务和快照协作。仅当所有内容块都是文本时才提供编辑功能;编辑器不能静默丢弃非文本块。编辑中的行只展示保存和取消操作,对应的键盘操作分别是 Enter 和 Escape。删除会移除对应的精确入队项。 ## 考虑过的替代方案 @@ -34,7 +34,7 @@ Web 队列能够渲染待处理消息,但无法编辑或删除其中某一行 ## 验证 -AgentLoop 契约测试会在编辑和移除精确 queued 入队项时阻塞提示词接纳,拒绝对 steering 入队项的变更,并验证所得独立轮次及终态生命周期事件。Host schema 与代理测试覆盖仅含 queued 项的权威快照、同步可重入变更顺序、重连、拒绝冷 Agent、类型化 not-found 错误和 RPC 传输。客户端运行时和 QueueDock 测试覆盖非乐观投影、仅文本编辑、保存与取消入口、移除、退役竞态,以及禁用混合内容编辑。无密钥浏览器场景会通过构建后的 Web 组合和真实 HTTP/SSE 协议操作公开的编辑和删除。 +AgentLoop 契约测试会在编辑和移除精确 queued 入队项时阻塞提示词接纳,拒绝对 steering 入队项的变更,并验证所得独立轮次及终态生命周期事件。Host schema 与代理测试覆盖仅含 queued 项的权威快照、同步可重入变更顺序、重连、拒绝冷 Agent、类型化 not-found 错误和 RPC 传输。客户端运行时和 QueueDock 测试覆盖非乐观投影、单行呈现、多行默认收起、展开、仅文本编辑、保存与取消入口、移除、退役竞态,以及禁用混合内容编辑。无密钥浏览器场景会展开队列,并通过构建后的 Web 组合和真实 HTTP/SSE 协议操作其公开的编辑和删除。 ## 后果 diff --git a/apps/web/tests/queue-actions.e2e.ts b/apps/web/tests/queue-actions.e2e.ts index 1df3ffc247..025747c37d 100644 --- a/apps/web/tests/queue-actions.e2e.ts +++ b/apps/web/tests/queue-actions.e2e.ts @@ -80,6 +80,10 @@ describe('web e2e: queue row actions', () => { await input.fill(text) await input.press('Enter') } + const queueHeader = page.getByRole('button', { name: '2 Queued' }) + await expect.poll(() => queueHeader.getAttribute('aria-expanded'), { timeout: 10_000 }) + .toBe('false') + await queueHeader.click() await expect.poll( () => page.getByRole('button', { name: '删除排队消息' }).count(), { timeout: 10_000 }, diff --git a/apps/web/tests/snapshots/queue-actions/editing.expected.md b/apps/web/tests/snapshots/queue-actions/editing.expected.md index 311c961450..0bb20cde47 100644 --- a/apps/web/tests/snapshots/queue-actions/editing.expected.md +++ b/apps/web/tests/snapshots/queue-actions/editing.expected.md @@ -12,6 +12,7 @@ - button "编辑": - img - paragraph: partial +- button "2 Queued" [expanded] - list: - listitem: - text: Queue item to remove diff --git a/packages/client/ui-conversation/README.i18n.yaml b/packages/client/ui-conversation/README.i18n.yaml index 654722b589..5b9adf8b01 100644 --- a/packages/client/ui-conversation/README.i18n.yaml +++ b/packages/client/ui-conversation/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-conversation/README.md -README.md: 3973c14f2b8fe746549bb74af85a7a60a7d66aea -README.zh.md: a6bb15c4cdd53d05bf28147b97d9d64d1c59da2b +README.md: 6e48c127b18eb65008edd2debf9835e5beffdcca +README.zh.md: 632d2f9959ac496e6f4512ec30ca0f97c53a5abf diff --git a/packages/client/ui-conversation/README.md b/packages/client/ui-conversation/README.md index 3973c14f2b..6e48c127b1 100644 --- a/packages/client/ui-conversation/README.md +++ b/packages/client/ui-conversation/README.md @@ -18,6 +18,8 @@ Tool rows are slots too — the standalone tool ring (`ToolViewRegistry`/`ctx.to The todo surfaces are two registrations over that shape, both plain registrant plugins with `inject: ['slots', 'conversation']`. `TodoRow` takes the `'conversation.chat.toolview'` key `todo_write` and summarizes what the call attempted (`/ 已完成 · ` parsed from its args, falling back to the generic summary on malformed or wrongly-shaped model JSON, and keeping the generic dot for non-ok execution states so a cancelled call never reads as a completed update). `TodoDock` takes the `'conversation.input.dock'` list slot at `order: -1` — above the queue rows — and is the plan strip: it reads the host-computed `todos` projection via `useProjection` (standing plan: latest `todo/write` with no later `turn/start`) and renders `TodoPanel`, which takes the plain list, hides itself while the list is empty, and starts collapsed as a header of title plus `"/ tasks · in progress"` (status glyphs are the figma check / progress / dashed-pending set). The dock adapter owns the selection so the panel stays a pure function of its props; the standing list lives here rather than in the row so the row stays one line. Anything the input-zone composer chain hides (a `conversation.composer` takeover such as ui-question's) hides the whole dock, this strip included. +`QueueDock` takes the same input-dock list at `order: 0`. It hides while empty, renders one pending row directly, and defaults two or more rows to a collapsed `" Queued"` header whose button expands or collapses the complete list. The header exposes `aria-expanded`; each visible row remains a single-line preview with its exact-occurrence edit and delete actions. + Per-session UI state for selection and the active view lives in the declared chat store (`stores.ts` `createChatStore`); the InputHub owns the composer state machine and mirrors its draft into that store for persistence. Apply passes one store handle to the strict session subtree, chat view, and details registrations, so each session shares one instance and the framework owns its lifecycle. Components are pure: the framework standard kit supplies `useSession`/`sessionId`, global `useSessions`/`useWorkspaces`, and the input machine's `useInput`/`inputActions`; store faces and inject factories supply the remaining state and callbacks. The composer bar declares session-scoped single seats for `'conversation.input.plan'` (right of the local access-mode control) and `'conversation.input.model'` (immediately before the pending indicator and send/stop button), plus list slots for overlay, dock, left, and right input extensions. Feature packages own each control and its state; ui-conversation supplies placement, the `locked` owner prop, and the standard slot shares. While the `plan` projection's effective target is plan mode, InputBar swaps its textarea placeholder to the plan-task wording, localized through the `command.hint` locale namespace this package registers and shared verbatim with the claimed `/plan` command hint (a host-folded value read through the standard-kit `useProjection`; owner-supplied placeholders win). A pending composer takeover remains mounted when another conversation view is active so the blocked agent can still receive its answer; without a pending interaction, the active-session composer belongs to Chat. The resident no-session shell uses `DisabledInputBar` and therefore dispatches no session-scoped control seats. diff --git a/packages/client/ui-conversation/README.zh.md b/packages/client/ui-conversation/README.zh.md index a6bb15c4cd..632d2f9959 100644 --- a/packages/client/ui-conversation/README.zh.md +++ b/packages/client/ui-conversation/README.zh.md @@ -18,6 +18,8 @@ todo 两个面就是在该形状上的两个注册项,都是普通注册方插件,`inject: ['slots', 'conversation']`。`TodoRow` 占用 `'conversation.chat.toolview'` 的 `todo_write` key,摘要该次调用「试图写入」的内容(从其 args 解析出 `<已完成>/<总数> 已完成 · <进行中条目>`;模型 JSON 残缺或形状不对时回落到通用摘要;非 ok 执行状态保留通用状态点,使被取消的调用绝不读成一次已完成的更新)。`TodoDock` 以 `order: -1` 占用 `'conversation.input.dock'` 列表 slot(位于队列行之上),是计划条:它经 `useProjection` 读取 host 计算的 `todos` 投影(站立计划:其后没有更晚 `turn/start` 的最近一次 `todo/write`)并渲染 `TodoPanel`,后者接收纯列表,在列表为空时自我隐藏;列表非空时面板初始折叠,表头显示标题加 `"<已完成>/<总数> tasks · in progress"`(状态图标为 figma 的勾选/进行中/虚线未开始一组)。选取由 dock 适配器负责,因此面板保持为其 props 的纯函数;站立列表放在此处而非行内,行才能保持单行。输入区 composer 链隐藏的一切(例如 ui-question 对 `conversation.composer` 的接管)也会隐藏整个 dock,包括这条计划条。 +`QueueDock` 以 `order: 0` 占用同一个 input-dock 列表。队列为空时隐藏;只有一个待处理项时直接渲染该行;存在两个或更多待处理项时,默认收起为 `" Queued"` 表头,其按钮可展开或收起完整列表。表头暴露 `aria-expanded`;每条可见行仍是单行预览,并提供针对精确单次入队项的编辑和删除操作。 + 逐 Session UI 状态中的选择与活跃视图位于已声明的聊天 store(`stores.ts` `createChatStore`)中;InputHub 拥有输入区状态机,并将草稿镜像到该 store 以便持久化。apply 将同一个 store handle 传给严格限定于会话的子树、聊天视图和详情注册,因此每个会话内共享一个实例,框架拥有其生命周期。组件保持纯粹:框架标准工具包提供 `useSession`/`sessionId`、全局 `useSessions`/`useWorkspaces`,以及输入状态机的 `useInput`/`inputActions`;store 表层与 inject factory 提供其余状态和回调。 输入栏为 `'conversation.input.plan'`(位于本地 access 模式控件右侧)和 `'conversation.input.model'`(渲染在 pending 指示器与发送/停止按钮之前)声明会话作用域的单实例 seat,并为 overlay、dock、left 和 right 输入扩展声明列表 slot。各功能包拥有相应控件及其状态;ui-conversation 提供放置位置、`locked` owner prop 和标准 slot share。当 `plan` 投影的有效目标为 plan mode 时,InputBar 将文本框 placeholder 切换为 plan 任务措辞,经本包注册的 `command.hint` locale 命名空间本地化,并与已认领 `/plan` 命令的提示逐字共用同一份文案(经标准套件 `useProjection` 读取的 host 折叠值;owner 提供的 placeholder 优先)。另一个会话视图活跃时,待处理的 composer 接管仍保持挂载,使被阻塞的 agent(智能体)仍能收到回答;没有待处理交互时,活跃会话的 composer 归 Chat 所有。常驻无会话壳使用 `DisabledInputBar`,因此不会分发任何会话作用域的控件 seat。 diff --git a/packages/client/ui-conversation/src/client/queue/QueueDock.module.css b/packages/client/ui-conversation/src/client/queue/QueueDock.module.css index 4c05c2cbca..ce4455509b 100644 --- a/packages/client/ui-conversation/src/client/queue/QueueDock.module.css +++ b/packages/client/ui-conversation/src/client/queue/QueueDock.module.css @@ -30,6 +30,45 @@ pointer-events: none; } +.header { + box-sizing: border-box; + display: flex; + align-items: center; + gap: 10px; + width: 100%; + height: 36px; + padding: 4px 16px 4px 12px; + border: none; + border-radius: 8px; + background: transparent; + color: var(--dsw-alias-label-primary); + text-align: left; + cursor: pointer; +} + +.header:focus-visible { + outline: 2px solid var(--dsw-alias-label-tertiary); + outline-offset: -2px; +} + +.count { + flex: 1 1 auto; + min-width: 0; + font-family: Inter, var(--dsw-font-family); + font-size: 14px; + font-weight: 500; + line-height: 24px; +} + +.chevron { + display: grid; + flex: none; + place-items: center; + width: 14px; + height: 14px; + color: var(--dsw-alias-label-tertiary); +} + .list { margin: 0; padding: 0; diff --git a/packages/client/ui-conversation/src/client/queue/QueueDock.tsx b/packages/client/ui-conversation/src/client/queue/QueueDock.tsx index 99b91f301d..b4f7da1cc5 100644 --- a/packages/client/ui-conversation/src/client/queue/QueueDock.tsx +++ b/packages/client/ui-conversation/src/client/queue/QueueDock.tsx @@ -8,7 +8,8 @@ import { useEffect, useState } from 'react' import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' import type { SessionId } from '@deepseek-ai/dsh-client-runtime/client' import { - IconCheckOutline16, IconCloseOutline16, IconEditOutline16, IconTrashOutline16, + IconCheckOutline16, IconChevronDownOutline14, IconChevronUpOutline14, + IconCloseOutline16, IconEditOutline16, IconTrashOutline16, } from '@deepseek-ai/dsh-client-ui-primitives' import type { QueueAction, QueueItemId } from '../contract/queue.ts' import css from './QueueDock.module.css' @@ -22,11 +23,15 @@ export interface QueueDockInjected { /** Full props of a dock entry: InputZone owner share + session standard kit + global seat. */ export type QueueDockProps = PropsRuntime<'conversation.input.dock'> & QueueDockInjected -/** Queue strip: one preview line per queued message; renders null when the queue is empty. */ +/** + * Queue strip: one item renders directly; multiple items default to a + * collapsible count header; an empty queue renders nothing. + */ export function QueueDock({ useSession, updateQueue, notify }: QueueDockProps) { const queue = useSession(s => s.queue) const [editing, setEditing] = useState<{ id: QueueItemId; text: string } | null>(null) const [busy, setBusy] = useState(null) + const [collapsed, setCollapsed] = useState(true) useEffect(() => { if (editing !== null && !queue.some(row => row.id === editing.id)) setEditing(null) @@ -63,92 +68,107 @@ export function QueueDock({ useSession, updateQueue, notify }: QueueDockProps) { return (
-
    - {queue.map(row => ( -
  • - {editing?.id === row.id - ? ( - { setEditing({ id: row.id, text: event.currentTarget.value }) }} - onKeyDown={(event) => { - if (event.key === 'Escape') { - setEditing(null) - return - } - if (event.key === 'Enter' && !event.nativeEvent.isComposing) { - event.preventDefault() - void saveEdit() - } - }} - /> - ) - : {row.preview}} -
    + {queue.length > 1 && ( + + )} + {(queue.length === 1 || !collapsed) && ( +
      + {queue.map(row => ( +
    • {editing?.id === row.id ? ( - <> - - - + { setEditing({ id: row.id, text: event.currentTarget.value }) }} + onKeyDown={(event) => { + if (event.key === 'Escape') { + setEditing(null) + return + } + if (event.key === 'Enter' && !event.nativeEvent.isComposing) { + event.preventDefault() + void saveEdit() + } + }} + /> ) - : ( - <> - - - - )} -
    -
  • - ))} -
+ : {row.preview}} +
+ {editing?.id === row.id + ? ( + <> + + + + ) + : ( + <> + + + + )} +
+ + ))} + + )}
) diff --git a/packages/client/ui-conversation/tests/queue-dock.spec.tsx b/packages/client/ui-conversation/tests/queue-dock.spec.tsx index 8d0614d2e9..67c6ce7c45 100644 --- a/packages/client/ui-conversation/tests/queue-dock.spec.tsx +++ b/packages/client/ui-conversation/tests/queue-dock.spec.tsx @@ -1,7 +1,7 @@ // @vitest-environment jsdom /** * QueueDock rendering and operations: authoritative rows, inline editing, - * removal, failure notices, and live retirement. + * collapse state, removal, failure notices, and live retirement. */ import { afterEach, describe, expect, it, vi } from 'vitest' import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react' @@ -78,16 +78,40 @@ describe('QueueDock', () => { expect(container.innerHTML).toBe('') }) + it('renders one row directly and defaults multiple rows to a collapsible count header', () => { + const single = snapshotWith([row('i-1', 'one')]) + const source = liveSession(single) + const view = render() + expect(view.queryByRole('button', { name: '1 Queued' })).toBeNull() + expect(view.getByText('one')).toBeTruthy() + + act(() => { source.push(snapshotWith([row('i-1', 'one'), row('i-2', 'two')])) }) + const header = view.getByRole('button', { name: '2 Queued' }) + expect(header.getAttribute('aria-expanded')).toBe('false') + expect(view.queryByText('one')).toBeNull() + expect(view.queryByText('two')).toBeNull() + + fireEvent.click(header) + expect(header.getAttribute('aria-expanded')).toBe('true') + expect(view.getByText('one')).toBeTruthy() + expect(view.getByText('two')).toBeTruthy() + + fireEvent.click(header) + expect(header.getAttribute('aria-expanded')).toBe('false') + expect(view.queryByText('one')).toBeNull() + }) + it('renders active actions and disables editing for mixed-content rows', () => { const snap = snapshotWith([ row('i-1', '第一条排队消息'), row('i-2', null, 'image [image]'), ]) const source = liveSession(snap) - const { container } = render() + const { container, getByRole } = render() + fireEvent.click(getByRole('button', { name: '2 Queued' })) expect([...container.querySelectorAll('li')].map(item => item.textContent)) .toEqual(['第一条排队消息', 'image [image]']) - expect(container.querySelectorAll('button')).toHaveLength(4) + expect(container.querySelectorAll('button')).toHaveLength(5) expect(container.querySelectorAll('[aria-label="编辑排队消息"]')).toHaveLength(2) expect(container.querySelectorAll('[aria-label="删除排队消息"]')).toHaveLength(2) expect(container.querySelectorAll('[aria-label="立即发送排队消息"]')).toHaveLength(0) @@ -162,10 +186,11 @@ describe('QueueDock', () => { const snap = snapshotWith([row('i-1', 'one'), row('i-2', 'two')]) const source = liveSession(snap) const updateQueue = vi.fn(() => Promise.resolve()) - const { getAllByLabelText } = render( + const { getAllByLabelText, getByRole } = render( , ) + fireEvent.click(getByRole('button', { name: '2 Queued' })) fireEvent.click(getAllByLabelText('删除排队消息')[0]!) await waitFor(() => { expect(updateQueue).toHaveBeenCalledWith(iid('i-1'), { kind: 'remove' }) From 5f87c7a89c75de19e852302e1202f7ea8c72274c Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 30 Jul 2026 19:20:13 +0800 Subject: [PATCH 02/10] fix(web): close queue collapse review gaps --- ...-29-addressable-queue-operations.i18n.yaml | 4 +- ...2026-07-29-addressable-queue-operations.md | 4 +- ...6-07-29-addressable-queue-operations.zh.md | 4 +- apps/web/tests/queue-actions.e2e.ts | 14 +- .../queue-actions/collapsed.expected.md | 24 +++ .../queue-actions/editing.expected.md | 2 +- .../client/ui-conversation/README.i18n.yaml | 4 +- packages/client/ui-conversation/README.md | 2 +- packages/client/ui-conversation/README.zh.md | 2 +- .../src/client/queue/QueueDock.module.css | 8 + .../src/client/queue/QueueDock.tsx | 186 +++++++++--------- .../ui-conversation/tests/queue-dock.spec.tsx | 77 +++++++- 12 files changed, 224 insertions(+), 107 deletions(-) create mode 100644 apps/web/tests/snapshots/queue-actions/collapsed.expected.md diff --git a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.i18n.yaml b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.i18n.yaml index 3524737277..d9b4a04671 100644 --- a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.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-07-29-addressable-queue-operations.md -2026-07-29-addressable-queue-operations.md: 28570be7a2a520fd8293a73526302122740823ca -2026-07-29-addressable-queue-operations.zh.md: eb62d45c6572cd993fedf982d6c86e2ff19787a6 +2026-07-29-addressable-queue-operations.md: 7a08b889c958e583dc430d33a1855fe3725f3d48 +2026-07-29-addressable-queue-operations.zh.md: 701b028c7494fd7cb608d05a5d170c9075b155d7 diff --git a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md index 28570be7a2..7a08b889c9 100644 --- a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md +++ b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.md @@ -18,7 +18,7 @@ The Web queue rendered pending messages but could not edit or delete one row. `M **Queue addresses require a live Agent.** `session.updateQueue` queries only the mounted Agent registry and never resumes a cold session: an `InboxItemId` is process-local and cannot name work after restart or disposal. A missing Agent and a driver-claimed occurrence both return `queue-item-not-found`. -**Web actions address Queue only.** The Host excludes pending steering from `session/queue`; steering retains its existing durable transcript path after consumption. QueueDock hides while empty, renders one pending occurrence directly, and defaults two or more occurrences to a collapsed `" Queued"` header that expands or collapses the complete list. The header exposes `aria-expanded`. Visible rows expose edit and delete, but no send-now control. The UI derives queue row and mutation types from the runtime `SessionFace` contract rather than importing the connection plugin, so plugin cooperation continues through services and snapshots. Edit is available only when all content blocks are text; the editor cannot silently drop non-text blocks. An editing row exposes only save and cancel, with Enter and Escape as their keyboard equivalents. Delete removes the exact occurrence. +**Web actions address Queue only.** The Host excludes pending steering from `session/queue`; steering retains its existing durable transcript path after consumption. QueueDock hides while empty, renders one pending occurrence directly, and defaults two or more occurrences to a collapsed `" 条排队消息"` header that expands or collapses the complete list. The header exposes `aria-expanded` and `aria-controls`; the expanded list scrolls within a 180px height bound. An active edit or mutation keeps its rows visible, and emptying the queue restores the collapsed default for the next queue. Visible rows expose edit and delete, but no send-now control. The UI derives queue row and mutation types from the runtime `SessionFace` contract rather than importing the connection plugin, so plugin cooperation continues through services and snapshots. Edit is available only when all content blocks are text; the editor cannot silently drop non-text blocks. An editing row exposes only save and cancel, with Enter and Escape as their keyboard equivalents. Delete removes the exact occurrence. ## Alternatives considered @@ -34,7 +34,7 @@ The Web queue rendered pending messages but could not edit or delete one row. `M ## Verification -AgentLoop contract tests hold prompt admission while editing and removing exact queued occurrences, reject mutations of steering occurrences, and verify the resulting independent turn and terminal lifecycle events. Host schema and proxy tests cover queued-only authoritative snapshots, synchronous re-entrant mutation order, reconnect, cold-Agent rejection, typed not-found errors, and the RPC transport. Client runtime and QueueDock tests cover non-optimistic projection, single-row presentation, default multi-row collapse, expansion, text-only editing, save and cancel affordances, removal, retirement races, and disabled mixed-content editing. Keyless browser scenarios expand the queue and drive its exposed edit and delete actions through the built Web composition and real HTTP/SSE wire. +AgentLoop contract tests hold prompt admission while editing and removing exact queued occurrences, reject mutations of steering occurrences, and verify the resulting independent turn and terminal lifecycle events. Host schema and proxy tests cover queued-only authoritative snapshots, synchronous re-entrant mutation order, reconnect, cold-Agent rejection, typed not-found errors, and the RPC transport. Client runtime and QueueDock tests cover non-optimistic projection, single-row presentation, default multi-row collapse, interaction-forced visibility, reset after emptying, expansion, text-only editing, save and cancel affordances, removal, retirement races, and disabled mixed-content editing. Keyless browser scenarios capture the default collapsed header before expanding the queue and driving its exposed edit and delete actions through the built Web composition and real HTTP/SSE wire. ## Consequences diff --git a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md index eb62d45c65..701b028c74 100644 --- a/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md +++ b/.agents/notes/implemented/feature/2026-07-29-addressable-queue-operations.zh.md @@ -18,7 +18,7 @@ Web 队列能够渲染待处理消息,但无法编辑或删除其中某一行 **Queue 寻址要求 Agent 存活。** `session.updateQueue` 只查询已挂载的 Agent 注册表,绝不恢复冷会话:`InboxItemId` 属于进程本地标识,无法在重启或资源释放后继续指向工作。Agent 缺失和单次入队项已被驱动器认领这两种情况都返回 `queue-item-not-found`。 -**Web 操作只面向 Queue。** Host 从 `session/queue` 中排除待处理 steering;steering 消费后仍沿用既有的持久 transcript(文本记录)路径。QueueDock 在队列为空时隐藏,只有一个待处理项时直接渲染该行,存在两个或更多待处理项时则默认收起为可展开或收起完整列表的 `" Queued"` 表头。表头暴露 `aria-expanded`。可见行暴露编辑和删除操作,不提供立即发送控件。UI 从运行时 `SessionFace` 契约派生队列行与变更类型,而不是导入连接插件,因此插件仍通过服务和快照协作。仅当所有内容块都是文本时才提供编辑功能;编辑器不能静默丢弃非文本块。编辑中的行只展示保存和取消操作,对应的键盘操作分别是 Enter 和 Escape。删除会移除对应的精确入队项。 +**Web 操作只面向 Queue。** Host 从 `session/queue` 中排除待处理 steering;steering 消费后仍沿用既有的持久 transcript(文本记录)路径。QueueDock 在队列为空时隐藏,只有一个待处理项时直接渲染该行,存在两个或更多待处理项时则默认收起为可展开或收起完整列表的 `" 条排队消息"` 表头。表头暴露 `aria-expanded` 和 `aria-controls`;展开后的列表以 180px 为高度上限,并可滚动。存在进行中的编辑或变更时,列表行会保持可见;队列清空后,下一次出现队列时会恢复默认收起状态。可见行暴露编辑和删除操作,不提供立即发送控件。UI 从运行时 `SessionFace` 契约派生队列行与变更类型,而不是导入连接插件,因此插件仍通过服务和快照协作。仅当所有内容块都是文本时才提供编辑功能;编辑器不能静默丢弃非文本块。编辑中的行只展示保存和取消操作,对应的键盘操作分别是 Enter 和 Escape。删除会移除对应的精确入队项。 ## 考虑过的替代方案 @@ -34,7 +34,7 @@ Web 队列能够渲染待处理消息,但无法编辑或删除其中某一行 ## 验证 -AgentLoop 契约测试会在编辑和移除精确 queued 入队项时阻塞提示词接纳,拒绝对 steering 入队项的变更,并验证所得独立轮次及终态生命周期事件。Host schema 与代理测试覆盖仅含 queued 项的权威快照、同步可重入变更顺序、重连、拒绝冷 Agent、类型化 not-found 错误和 RPC 传输。客户端运行时和 QueueDock 测试覆盖非乐观投影、单行呈现、多行默认收起、展开、仅文本编辑、保存与取消入口、移除、退役竞态,以及禁用混合内容编辑。无密钥浏览器场景会展开队列,并通过构建后的 Web 组合和真实 HTTP/SSE 协议操作其公开的编辑和删除。 +AgentLoop 契约测试会在编辑和移除精确 queued 入队项时阻塞提示词接纳,拒绝对 steering 入队项的变更,并验证所得独立轮次及终态生命周期事件。Host schema 与代理测试覆盖仅含 queued 项的权威快照、同步可重入变更顺序、重连、拒绝冷 Agent、类型化 not-found 错误和 RPC 传输。客户端运行时和 QueueDock 测试覆盖非乐观投影、单行呈现、多行默认收起、交互期间强制保持可见、清空后重置、展开、仅文本编辑、保存与取消入口、移除、退役竞态,以及禁用混合内容编辑。无密钥浏览器场景会先捕获默认收起的表头,再展开队列,并通过构建后的 Web 组合和真实 HTTP/SSE 协议操作其公开的编辑和删除。 ## 后果 diff --git a/apps/web/tests/queue-actions.e2e.ts b/apps/web/tests/queue-actions.e2e.ts index 025747c37d..1c2ca271aa 100644 --- a/apps/web/tests/queue-actions.e2e.ts +++ b/apps/web/tests/queue-actions.e2e.ts @@ -20,6 +20,7 @@ import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './suppor const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/queue-actions', import.meta.url)) const FIXTURE = fileURLToPath(new URL('./snapshots/live-interactions/session.jsonl', import.meta.url)) +const COLLAPSED_EXPECTED = join(SNAPSHOT_DIR, 'collapsed.expected.md') const EDITING_EXPECTED = join(SNAPSHOT_DIR, 'editing.expected.md') const UI_EXPECTED = join(SNAPSHOT_DIR, 'ui.expected.md') const MODE = webSnapshotMode() @@ -80,9 +81,15 @@ describe('web e2e: queue row actions', () => { await input.fill(text) await input.press('Enter') } - const queueHeader = page.getByRole('button', { name: '2 Queued' }) + const queueHeader = page.getByRole('button', { name: '2 条排队消息' }) await expect.poll(() => queueHeader.getAttribute('aria-expanded'), { timeout: 10_000 }) .toBe('false') + const collapsedSnapshot = await captureStableAria( + page, + '[class*="centerCol"]', + scaffold.workspaceCwd, + ) + await compareOrRefreshGolden(COLLAPSED_EXPECTED, collapsedSnapshot, MODE) await queueHeader.click() await expect.poll( () => page.getByRole('button', { name: '删除排队消息' }).count(), @@ -116,6 +123,9 @@ describe('web e2e: queue row actions', () => { }, 120_000) it.skipIf(MODE === 'record')('keeps its snapshot inventory closed', async () => { - await assertFixtureInventory(SNAPSHOT_DIR, ['editing.expected.md', 'ui.expected.md']) + await assertFixtureInventory( + SNAPSHOT_DIR, + ['collapsed.expected.md', 'editing.expected.md', 'ui.expected.md'], + ) }) }) diff --git a/apps/web/tests/snapshots/queue-actions/collapsed.expected.md b/apps/web/tests/snapshots/queue-actions/collapsed.expected.md new file mode 100644 index 0000000000..cdbf6fc64b --- /dev/null +++ b/apps/web/tests/snapshots/queue-actions/collapsed.expected.md @@ -0,0 +1,24 @@ +- banner: + - navigation "Session hierarchy": + - button "Reply with a one-sentence description" [disabled] + - tablist: + - tab "Chat" [selected] + - tab "Trajectory" +- text: Reply with a one-sentence description of event sourcing, then stop. {{clock}} +- button "复制": + - img +- button "在新对话中分支": + - img +- button "编辑": + - img +- paragraph: partial +- button "2 条排队消息" +- textbox "Message the agent" +- button "Add attachment": + - img +- 'button "Access mode, current: Danger Full Access"': Danger Full Access +- button "Plan mode off, press to turn on": Plan off +- button "Select model, current DeepSeek-V4-Flash": + - text: DeepSeek-V4-Flash + - img +- button "Stop generating" diff --git a/apps/web/tests/snapshots/queue-actions/editing.expected.md b/apps/web/tests/snapshots/queue-actions/editing.expected.md index 0bd0f3f472..cf287b5006 100644 --- a/apps/web/tests/snapshots/queue-actions/editing.expected.md +++ b/apps/web/tests/snapshots/queue-actions/editing.expected.md @@ -12,7 +12,7 @@ - button "编辑": - img - paragraph: partial -- button "2 Queued" [expanded] +- button "2 条排队消息" [disabled] [expanded] - list: - listitem: - text: Queue item to remove diff --git a/packages/client/ui-conversation/README.i18n.yaml b/packages/client/ui-conversation/README.i18n.yaml index ff60af0eed..157999ceef 100644 --- a/packages/client/ui-conversation/README.i18n.yaml +++ b/packages/client/ui-conversation/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-conversation/README.md -README.md: 18c8d86cb8dc375815afab8cc5275691bfdd3d86 -README.zh.md: 5b69be13980ecc25302e28b9ecda32d57f11b782 +README.md: 602befcc7b0ff49701b4b447fd80da0237034fdc +README.zh.md: fa24deaa9638d4397ebce4cca072814257fa2bc3 diff --git a/packages/client/ui-conversation/README.md b/packages/client/ui-conversation/README.md index 18c8d86cb8..602befcc7b 100644 --- a/packages/client/ui-conversation/README.md +++ b/packages/client/ui-conversation/README.md @@ -18,7 +18,7 @@ Tool rows are slots too — the standalone tool ring (`ToolViewRegistry`/`ctx.to The todo surfaces are two registrations over that shape, both plain registrant plugins with `inject: ['slots', 'conversation']`. `TodoRow` takes the `'conversation.chat.toolview'` key `todo_write` and summarizes what the call attempted (`/ 已完成 · ` parsed from its args, falling back to the generic summary on malformed or wrongly-shaped model JSON, and keeping the generic dot for non-ok execution states so a cancelled call never reads as a completed update). `TodoDock` takes the `'conversation.input.dock'` list slot at `order: 10` — between Goal and Queue — and is the plan strip: it reads the host-computed `todos` projection via `useProjection` (standing plan: latest `todo/write` with no later `turn/start`) and renders `TodoPanel`, which takes the plain list, hides itself while the list is empty, and starts collapsed as a header of title plus `"/ tasks · in progress"` (status glyphs are the figma check / progress / dashed-pending set). The dock adapter owns the selection so the panel stays a pure function of its props; the standing list lives here rather than in the row so the row stays one line. Anything the input-zone composer chain hides (a `conversation.composer` takeover such as ui-question's) hides the whole dock, this strip included. -`QueueDock` is the terminal input-dock entry at `order: 20`. It hides while empty, renders one pending row directly, and defaults two or more rows to a collapsed `" Queued"` header whose button expands or collapses the complete list. The header exposes `aria-expanded`; each visible row remains a single-line preview with its exact-occurrence edit and delete actions. +`QueueDock` is the terminal input-dock entry at `order: 20`. It hides while empty, renders one pending row directly, and defaults two or more rows to a collapsed `" 条排队消息"` header whose button expands or collapses the complete list. The header exposes `aria-expanded` and `aria-controls`; the expanded list scrolls within a 180px height bound. An active edit or mutation keeps its rows visible, and emptying the queue restores the collapsed default for the next queue. Each visible row remains a single-line preview with its exact-occurrence edit and delete actions. Per-session UI state for selection and the active view lives in the declared chat store (`stores.ts` `createChatStore`); the InputHub owns the composer state machine and mirrors its draft into that store for persistence. Apply passes one store handle to the strict session subtree, chat view, and details registrations, so each session shares one instance and the framework owns its lifecycle. Components are pure: the framework standard kit supplies `useSession`/`sessionId`, global `useSessions`/`useWorkspaces`, and the input machine's `useInput`/`inputActions`; store faces and inject factories supply the remaining state and callbacks. diff --git a/packages/client/ui-conversation/README.zh.md b/packages/client/ui-conversation/README.zh.md index 5b69be1398..fa24deaa96 100644 --- a/packages/client/ui-conversation/README.zh.md +++ b/packages/client/ui-conversation/README.zh.md @@ -18,7 +18,7 @@ todo 两个面就是在该形状上的两个注册项,都是普通注册方插件,`inject: ['slots', 'conversation']`。`TodoRow` 占用 `'conversation.chat.toolview'` 的 `todo_write` key,摘要该次调用「试图写入」的内容(从其 args 解析出 `<已完成>/<总数> 已完成 · <进行中条目>`;模型 JSON 残缺或形状不对时回落到通用摘要;非 ok 执行状态保留通用状态点,使被取消的调用绝不读成一次已完成的更新)。`TodoDock` 以 `order: 10` 占用 `'conversation.input.dock'` 列表 slot(位于 Goal 和 Queue 之间),是计划条:它经 `useProjection` 读取 host 计算的 `todos` 投影(站立计划:其后没有更晚 `turn/start` 的最近一次 `todo/write`)并渲染 `TodoPanel`,后者接收纯列表,在列表为空时自我隐藏;列表非空时面板初始折叠,表头显示标题加 `"<已完成>/<总数> tasks · in progress"`(状态图标为 figma 的勾选/进行中/虚线未开始一组)。选取由 dock 适配器负责,因此面板保持为其 props 的纯函数;站立列表放在此处而非行内,行才能保持单行。输入区 composer 链隐藏的一切(例如 ui-question 对 `conversation.composer` 的接管)也会隐藏整个 dock,包括这条计划条。 -`QueueDock` 是 `order: 20` 的末端 input-dock 条目。队列为空时隐藏;只有一个待处理项时直接渲染该行;存在两个或更多待处理项时,默认收起为 `" Queued"` 表头,其按钮可展开或收起完整列表。表头暴露 `aria-expanded`;每条可见行仍是单行预览,并提供针对精确单次入队项的编辑和删除操作。 +`QueueDock` 是 `order: 20` 的末端 input-dock 条目。队列为空时隐藏;只有一个待处理项时直接渲染该行;存在两个或更多待处理项时,默认收起为 `" 条排队消息"` 表头,其按钮可展开或收起完整列表。表头暴露 `aria-expanded` 和 `aria-controls`;展开后的列表以 180px 为高度上限,并可滚动。存在进行中的编辑或变更时,列表行会保持可见;队列清空后,下一次出现队列时会恢复默认收起状态。每条可见行仍是单行预览,并提供针对精确单次入队项的编辑和删除操作。 逐 Session UI 状态中的选择与活跃视图位于已声明的聊天 store(`stores.ts` `createChatStore`)中;InputHub 拥有输入区状态机,并将草稿镜像到该 store 以便持久化。apply 将同一个 store handle 传给严格限定于会话的子树、聊天视图和详情注册,因此每个会话内共享一个实例,框架拥有其生命周期。组件保持纯粹:框架标准工具包提供 `useSession`/`sessionId`、全局 `useSessions`/`useWorkspaces`,以及输入状态机的 `useInput`/`inputActions`;store 表层与 inject factory 提供其余状态和回调。 diff --git a/packages/client/ui-conversation/src/client/queue/QueueDock.module.css b/packages/client/ui-conversation/src/client/queue/QueueDock.module.css index a45c8c02c2..46cc018179 100644 --- a/packages/client/ui-conversation/src/client/queue/QueueDock.module.css +++ b/packages/client/ui-conversation/src/client/queue/QueueDock.module.css @@ -20,6 +20,8 @@ padding-top: 2px; border-radius: 14px 14px 0 0; background: var(--dsw-specific-tip); + --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2); + --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2); } .panel::after { @@ -53,6 +55,10 @@ outline-offset: -2px; } +.header:disabled { + cursor: default; +} + .count { flex: 1 1 auto; min-width: 0; @@ -72,6 +78,8 @@ } .list { + max-height: 180px; + overflow-y: auto; margin: 0; padding: 0; list-style: none; diff --git a/packages/client/ui-conversation/src/client/queue/QueueDock.tsx b/packages/client/ui-conversation/src/client/queue/QueueDock.tsx index d20e25d8d2..67de5d0796 100644 --- a/packages/client/ui-conversation/src/client/queue/QueueDock.tsx +++ b/packages/client/ui-conversation/src/client/queue/QueueDock.tsx @@ -4,7 +4,7 @@ // The 'conversation.input.dock' SlotMap declaration lives in // ../contract/slots.ts beside the other input-region slots. import type { Context } from 'cordis' -import { useEffect, useState } from 'react' +import { useEffect, useId, useState } from 'react' import type { PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' import type { SessionId } from '@deepseek-ai/dsh-client-runtime/client' import { @@ -32,13 +32,19 @@ export function QueueDock({ useSession, updateQueue, notify }: QueueDockProps) { const [editing, setEditing] = useState<{ id: QueueItemId; text: string } | null>(null) const [busy, setBusy] = useState(null) const [collapsed, setCollapsed] = useState(true) + const listId = useId() useEffect(() => { + if (queue.length === 0 && !collapsed) setCollapsed(true) if (editing !== null && !queue.some(row => row.id === editing.id)) setEditing(null) - }, [editing, queue]) + }, [collapsed, editing, queue]) if (queue.length === 0) return null + const interactionActive = editing !== null || busy !== null + const expanded = !collapsed || interactionActive + const listVisible = queue.length === 1 || expanded + const applyAction = async ( itemId: QueueItemId, action: QueueAction, @@ -72,103 +78,103 @@ export function QueueDock({ useSession, updateQueue, notify }: QueueDockProps) { )} - {(queue.length === 1 || !collapsed) && ( -
    - {queue.map(row => ( -
  • + - )} + : ( + <> + + + + )} + +
  • + ))} +
) diff --git a/packages/client/ui-conversation/tests/queue-dock.spec.tsx b/packages/client/ui-conversation/tests/queue-dock.spec.tsx index 42749ec329..8a8e01cc91 100644 --- a/packages/client/ui-conversation/tests/queue-dock.spec.tsx +++ b/packages/client/ui-conversation/tests/queue-dock.spec.tsx @@ -82,12 +82,13 @@ describe('QueueDock', () => { const single = snapshotWith([row('i-1', 'one')]) const source = liveSession(single) const view = render() - expect(view.queryByRole('button', { name: '1 Queued' })).toBeNull() + expect(view.queryByRole('button', { name: '1 条排队消息' })).toBeNull() expect(view.getByText('one')).toBeTruthy() act(() => { source.push(snapshotWith([row('i-1', 'one'), row('i-2', 'two')])) }) - const header = view.getByRole('button', { name: '2 Queued' }) + const header = view.getByRole('button', { name: '2 条排队消息' }) expect(header.getAttribute('aria-expanded')).toBe('false') + expect(document.getElementById(header.getAttribute('aria-controls')!)).toBeTruthy() expect(view.queryByText('one')).toBeNull() expect(view.queryByText('two')).toBeNull() @@ -101,6 +102,74 @@ describe('QueueDock', () => { expect(view.queryByText('one')).toBeNull() }) + it('keeps an active single-row editor visible when another item arrives', () => { + const single = snapshotWith([row('i-edit', 'before')]) + const source = liveSession(single) + const view = render() + + fireEvent.click(view.getByLabelText('编辑排队消息')) + fireEvent.change(view.getByLabelText('编辑排队消息'), { target: { value: 'draft' } }) + act(() => { + source.push(snapshotWith([row('i-edit', 'before'), row('i-2', 'second')])) + }) + + const header = view.getByRole('button', { name: '2 条排队消息' }) + expect(header).toHaveProperty('disabled', true) + expect(header.getAttribute('aria-expanded')).toBe('true') + expect(view.getByRole('textbox', { name: '编辑排队消息' })).toHaveProperty('value', 'draft') + expect(view.getByText('second')).toBeTruthy() + + fireEvent.click(view.getByLabelText('取消编辑')) + expect(header).toHaveProperty('disabled', false) + expect(header.getAttribute('aria-expanded')).toBe('false') + expect(view.queryByText('second')).toBeNull() + }) + + it('keeps an in-flight row action visible when another item arrives', async () => { + const single = snapshotWith([row('i-remove', 'remove me')]) + const source = liveSession(single) + let finishUpdate: (() => void) | undefined + const updateQueue = vi.fn(() => new Promise((resolve) => { finishUpdate = resolve })) + const view = render( + , + ) + + fireEvent.click(view.getByLabelText('删除排队消息')) + act(() => { + source.push(snapshotWith([row('i-remove', 'remove me'), row('i-2', 'second')])) + }) + + const header = view.getByRole('button', { name: '2 条排队消息' }) + expect(header).toHaveProperty('disabled', true) + expect(header.getAttribute('aria-expanded')).toBe('true') + expect(view.getByText('remove me')).toBeTruthy() + expect(view.getByText('second')).toBeTruthy() + + act(() => { finishUpdate?.() }) + await waitFor(() => { + expect(header).toHaveProperty('disabled', false) + expect(header.getAttribute('aria-expanded')).toBe('false') + }) + }) + + it('defaults a new multi-row queue to collapsed after the prior queue empties', () => { + const first = snapshotWith([row('i-1', 'one'), row('i-2', 'two')]) + const source = liveSession(first) + const view = render() + fireEvent.click(view.getByRole('button', { name: '2 条排队消息' })) + expect(view.getByText('one')).toBeTruthy() + + act(() => { source.push(snapshotWith([])) }) + expect(view.container.innerHTML).toBe('') + act(() => { + source.push(snapshotWith([row('i-3', 'three'), row('i-4', 'four')])) + }) + + const header = view.getByRole('button', { name: '2 条排队消息' }) + expect(header.getAttribute('aria-expanded')).toBe('false') + expect(view.queryByText('three')).toBeNull() + }) + it('renders active actions and disables editing for mixed-content rows', () => { const snap = snapshotWith([ row('i-1', '第一条排队消息'), @@ -108,7 +177,7 @@ describe('QueueDock', () => { ]) const source = liveSession(snap) const { container, getByRole } = render() - fireEvent.click(getByRole('button', { name: '2 Queued' })) + fireEvent.click(getByRole('button', { name: '2 条排队消息' })) expect([...container.querySelectorAll('li')].map(item => item.textContent)) .toEqual(['第一条排队消息', 'image [image]']) expect(container.querySelectorAll('button')).toHaveLength(5) @@ -190,7 +259,7 @@ describe('QueueDock', () => { , ) - fireEvent.click(getByRole('button', { name: '2 Queued' })) + fireEvent.click(getByRole('button', { name: '2 条排队消息' })) fireEvent.click(getAllByLabelText('删除排队消息')[0]!) await waitFor(() => { expect(updateQueue).toHaveBeenCalledWith(iid('i-1'), { kind: 'remove' }) From 98f6552e219b32125e27b9c7683c049340693c69 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 20:24:58 +0800 Subject: [PATCH 03/10] Revert "ci: reduce coverage cocurrency" This reverts commit ab30aca5cb859aea4bd0fffc88414270d1761f7d. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6a94d11f..d1440bd88b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,8 +110,8 @@ jobs: # across six always-on runner instances, and the timing-sensitive # process suites have documented aggregate-contention failures. # 8 × 6 instances = 48 workers worst case on 64 cores. - DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }} - DSH_GATE_CONCURRENCY: '3' + DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '24' }} + DSH_GATE_CONCURRENCY: '8' NODE_OPTIONS: '--max-old-space-size=8192' steps: - uses: actions/checkout@v6 From e35e2a9f3ead2cc3b9e3aa2fcd1a15e8c668dad2 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:07:22 +0800 Subject: [PATCH 04/10] perf: tsc --- packages/typert/generator/src/analyzer.ts | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/typert/generator/src/analyzer.ts b/packages/typert/generator/src/analyzer.ts index 1f545d9673..e0e04a4fa1 100644 --- a/packages/typert/generator/src/analyzer.ts +++ b/packages/typert/generator/src/analyzer.ts @@ -131,6 +131,26 @@ interface FaceProgramHost { readonly files: Map } +/** + * Process-wide parse cache for the bundled TypeScript default libraries. + * `typescript/lib/lib.*.d.ts` content is immutable for the process lifetime, + * so parses are shared across every {@link WorkspaceCaches} instance; the key + * carries the parse-affecting settings, keeping reuse exact. + */ +const defaultLibraryParses = new Map() + +function defaultLibraryKey(fileName: string, languageVersionOrOptions: ts.ScriptTarget | ts.CreateSourceFileOptions): string { + const options = typeof languageVersionOrOptions === 'object' + ? languageVersionOrOptions + : { languageVersion: languageVersionOrOptions } + return [ + fileName, + String(options.languageVersion), + String(options.impliedNodeFormat ?? ''), + String(options.jsDocParsingMode ?? ''), + ].join('\0') +} + /** * Shared memo over one immutable workspace snapshot. Passing one instance to * several analyzers (the batched and write-mode children reuse their parent's @@ -185,6 +205,13 @@ export class WorkspaceCaches { // only fires under oldProgram reuse, which these fresh programs never // request, and invalidate() is the one supported re-read path. host.getSourceFile = (fileName, languageVersionOrOptions, onError) => { + if (isStandardLibraryFile(fileName)) { + const key = defaultLibraryKey(fileName, languageVersionOrOptions) + if (!defaultLibraryParses.has(key)) { + defaultLibraryParses.set(key, base(fileName, languageVersionOrOptions, onError)) + } + return defaultLibraryParses.get(key) + } if (!files.has(fileName)) files.set(fileName, base(fileName, languageVersionOrOptions, onError)) return files.get(fileName) } From be0216102a145729543b872e6da91c5bbfab7d69 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:17:11 +0800 Subject: [PATCH 05/10] Reapply "ci: reduce coverage cocurrency" This reverts commit a471ba79e30e6148e8c433b83fe0d7ee14a8312b. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1440bd88b..6d6a94d11f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,8 +110,8 @@ jobs: # across six always-on runner instances, and the timing-sensitive # process suites have documented aggregate-contention failures. # 8 × 6 instances = 48 workers worst case on 64 cores. - DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '24' }} - DSH_GATE_CONCURRENCY: '8' + DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }} + DSH_GATE_CONCURRENCY: '3' NODE_OPTIONS: '--max-old-space-size=8192' steps: - uses: actions/checkout@v6 From 56a8db2777ce002ead70f6f35d80cde9ccdbe60a Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:31:27 +0800 Subject: [PATCH 06/10] ci: use 16c 16c --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d6a94d11f..1e999becdc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,7 @@ jobs: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]') - || 'dsh-enterprise-ubuntu-latest-32core-test' }} + || 'dsh-ubuntu-24-04-16core' }} name: node 24 / static env: DSH_GATE_CONCURRENCY: '8' @@ -102,7 +102,7 @@ jobs: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]') - || 'dsh-enterprise-ubuntu-24-04-32core-test' }} + || 'dsh-ubuntu-24-04-16core' }} name: node 24 / coverage env: # Failover shrinks the worker bound: the hosted 32-core runner is @@ -167,7 +167,7 @@ jobs: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && fromJSON('["self-hosted", "linux", "x64", "vm-backup"]') - || 'dsh-enterprise-ubuntu-latest-32core-test' }} + || 'dsh-ubuntu-24-04-16core' }} name: node 24 / snapshots and artifacts env: DSH_GATE_CONCURRENCY: '8' From 9e2f6859f7c40b1be7014d7ae881e38d4d81fe9b Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:36:46 +0800 Subject: [PATCH 07/10] ci: reduce invariant import --- scripts/test-invariants.spec.ts | 3 +- scripts/test-invariants.ts | 66 ++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/scripts/test-invariants.spec.ts b/scripts/test-invariants.spec.ts index 7a4f678be8..0fb6aeb201 100644 --- a/scripts/test-invariants.spec.ts +++ b/scripts/test-invariants.spec.ts @@ -61,7 +61,8 @@ describe('global test invariant host', () => { return () => {} }) const fakeContext = { invariants: { register } } as unknown as Context - for (const [rawPath, companion] of Object.entries(testInvariantCompanions)) { + for (const [rawPath, load] of Object.entries(testInvariantCompanions)) { + const companion = await load() const path = rawPath.replace(/^\.\.\//, '') expect(companion.default, path).toBeUndefined() const unwrapped = loader.unwrapExports(companion) as typeof companion diff --git a/scripts/test-invariants.ts b/scripts/test-invariants.ts index ce9ede2dff..62c0102588 100644 --- a/scripts/test-invariants.ts +++ b/scripts/test-invariants.ts @@ -12,8 +12,8 @@ import InvariantService from '@deepseek-ai/dsh-invariants' declare global { interface ImportMeta { - /** Eager Vite module-glob expansion used by the Vitest setup file. */ - glob(pattern: string, options: { eager: true }): Record + /** Lazy Vite module-glob expansion used by the Vitest setup file. */ + glob(pattern: string): Record Promise> } } @@ -25,9 +25,15 @@ export interface TestInvariantCompanion { apply(ctx: Context): Promise<() => void> } -/** Every package companion, discovered eagerly so coverage observes each registration. */ -export const testInvariantCompanions: Readonly> = - import.meta.glob('../packages/*/*/src/invariant.ts', { eager: true }) +/** + * Every package companion as a lazy loader keyed by glob path. Ordinary tests + * load only their owner's module; the exhaustive topology test loads and + * executes all of them, so aggregated coverage still observes every + * registration while per-file setup stops importing 168 companions and their + * transitive package sources. + */ +export const testInvariantCompanions: Readonly Promise>> = + import.meta.glob('../packages/*/*/src/invariant.ts') /** Manual-topology suites whose names cannot follow the focused invariant convention. */ const MANUAL_INVARIANT_TEST_EXCEPTIONS = [ @@ -36,7 +42,6 @@ const MANUAL_INVARIANT_TEST_EXCEPTIONS = [ ] as const interface InvariantHost { - readonly fibers: readonly PluginFiber[] readonly byCallback: ReadonlyMap readonly ready: Promise } @@ -102,39 +107,40 @@ export function testInvariantCompanionPaths(testPath: string): string[] { } function startInvariantHost(root: Context): InvariantHost { - const fibers: PluginFiber[] = [] const byCallback = new Map() - const mount = (plugin: Plugin, config?: unknown): void => { + const mount = (plugin: Plugin, config?: unknown): PluginFiber => { const fiber = originalPlugin.call(root.registry, plugin, config) const callback = root.registry.resolve(plugin) if (callback === undefined) throw new Error('test invariants: companion is not a valid Cordis plugin') - fibers.push(fiber) byCallback.set(callback, fiber) + return fiber } - mount(InvariantService, { enabled: true }) + // The service mounts synchronously so the intercepted registration that + // started this host immediately finds its own fiber in byCallback. + // Companions load and mount inside the ready chain (after the service is + // active, so their startup is directly joinable); every joined root plugin + // awaits ready, so none starts ahead of its package checks. Tests plugging + // a companion directly must await an earlier root plugin first — the + // duplicate-mount failure otherwise is loud (owner name already reserved). + const serviceFiber = mount(InvariantService, { enabled: true }) const testPath = expect.getState().testPath ?? '' const companionPaths = testInvariantCompanionPaths(testPath) - for (const path of companionPaths) { - const companion = testInvariantCompanions[path] - if (companion === undefined) { - throw new Error(`test invariants: selected companion vanished at ${path}`) - } - if (!companion.inject.includes('invariants')) { - throw new Error(`test invariants: ${path} must inject the invariant service`) - } - mount(companion) - } - - const [serviceFiber, ...companionFibers] = fibers - if (serviceFiber === undefined) throw new Error('test invariants: service fiber was not mounted') - // A companion is initially PENDING on the invariant service, and Cordis - // Fiber.await() only joins work already in flight. Wait for the service to - // activate its dependants before joining their startup and failures. - const ready = serviceFiber.await() - .then(() => Promise.all(companionFibers.map(fiber => fiber.await()))) - .then(() => undefined) - const host = { fibers, byCallback, ready } + const ready = serviceFiber.await().then(async () => { + const companionFibers = await Promise.all(companionPaths.map(async (path) => { + const load = testInvariantCompanions[path] + if (load === undefined) { + throw new Error(`test invariants: selected companion vanished at ${path}`) + } + const companion = await load() + if (!companion.inject.includes('invariants')) { + throw new Error(`test invariants: ${path} must inject the invariant service`) + } + return mount(companion) + })) + await Promise.all(companionFibers.map(fiber => fiber.await())) + }) + const host = { byCallback, ready } hosts.set(root, host) return host } From 1a75d60174e474e613baf2fcb49715262518cf1f Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 21:59:07 +0800 Subject: [PATCH 08/10] ci: vitest forks --- vitest.config.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vitest.config.ts b/vitest.config.ts index 750bb6ddf2..a0d8b6d58a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -62,10 +62,12 @@ export default defineConfig({ plugins: [pathsPlugin()], test: { name: 'thread-safe', - // Node 24 has aborted in its CJS lexer from a macOS arm64 worker - // thread. A fork contains that external runtime failure to the test - // process; other hosts retain the lower-overhead thread pool. - pool: process.platform === 'darwin' ? 'forks' : 'threads', + // Node 24 has aborted in its CJS lexer (v8::ToLocalChecked Empty + // MaybeLocal in cjs_lexer::Parse) from worker threads on macOS + // arm64 and later on Linux. A fork contains that external runtime + // failure to the test process; Windows keeps the thread pool, where + // the abort has not reproduced and process spawn is costlier. + pool: process.platform === 'win32' ? 'threads' : 'forks', setupFiles: ['./scripts/test-invariants.ts'], include: testIncludes, exclude: [ From 8cc31127c4c7989e1954b33b7c7433e8fd717d62 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 22:10:43 +0800 Subject: [PATCH 09/10] ci: concurrency 3/6 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e999becdc..1f6ec52f0a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -110,9 +110,8 @@ jobs: # across six always-on runner instances, and the timing-sensitive # process suites have documented aggregate-contention failures. # 8 × 6 instances = 48 workers worst case on 64 cores. - DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '8' }} + DSH_COVERAGE_MAX_WORKERS: ${{ vars.DSH_CI_FAILOVER == 'selfhosted' && github.event.pull_request.user.login != 'dependabot[bot]' && '8' || '6' }} DSH_GATE_CONCURRENCY: '3' - NODE_OPTIONS: '--max-old-space-size=8192' steps: - uses: actions/checkout@v6 with: From 78adace0314528f16def3fd4346d89ecb364ded2 Mon Sep 17 00:00:00 2001 From: imccyu <276526105+imccyu@users.noreply.github.com> Date: Thu, 30 Jul 2026 22:34:37 +0800 Subject: [PATCH 10/10] ci: exclude typert generator from coverage thresholds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generator correctness stays pinned by its fixture suites and the byte-for-byte catalog reproduction test; per-file coverage put whole-workspace compiler analysis under v8 instrumentation — the coverage lane's longest tail. Widen the existing three-file exclude to the package's src. --- vitest.config.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vitest.config.ts b/vitest.config.ts index a0d8b6d58a..aa3e2b441b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -156,9 +156,11 @@ export default defineConfig({ 'packages/client/ui-sidebar/src/client/index.ts', 'packages/client/ui-skill/src/client/index.ts', 'packages/client/ui-workspace/src/client/index.ts', - 'packages/typert/generator/src/analyzer.ts', - 'packages/typert/generator/src/renderer.ts', - 'packages/typert/generator/src/cordis-catalog.ts', + // Typert generator: correctness is pinned by its fixture suites and + // the byte-for-byte catalog reproduction test; per-file coverage + // would put whole-workspace compiler analysis under v8 + // instrumentation — the coverage lane's longest tail. + 'packages/typert/generator/src/*.ts', 'packages/host/apiproxy/src/index.ts', 'packages/host/apiproxy/src/invariant.ts', 'packages/host/apiproxy/src/api-proxy.ts',