From d38ff541504ae1bac53bf12dfa260e83b52076ef Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Tue, 25 Aug 2026 14:02:57 +0800 Subject: [PATCH 01/13] feat(web): navigate loaded Chat Turns from a compact rail ChatView derives one navigation mark per currently loaded Turn, keyed by Turn number and anchored on that Turn's first loaded user node. The rail sits against the scrollport's right edge, centered in the band the sticky composer leaves visible; hover and keyboard focus preview the Turn's prompt and response, and activating a mark moves the shared scrollport and records the resulting restoration anchor. ConversationRoot publishes --dsh-conversation-viewport-height beside the composer height it already measures on the scrollport, so floating View chrome can center in that band without assuming a Session header height. --- ...8-25-loaded-turn-chat-navigation.i18n.yaml | 6 + .../2026-08-25-loaded-turn-chat-navigation.md | 41 ++++ ...26-08-25-loaded-turn-chat-navigation.zh.md | 41 ++++ apps/web/tests/chat-long-interactions.e2e.ts | 44 ++++- packages/client/ui-chat/README.i18n.yaml | 4 +- packages/client/ui-chat/README.md | 2 +- packages/client/ui-chat/README.zh.md | 2 +- .../ui-chat/src/client/chat/ChatNodeSeat.tsx | 5 + .../ui-chat/src/client/chat/ChatView.tsx | 81 ++++++++ .../src/client/chat/TurnNavigator.module.css | 176 ++++++++++++++++++ .../ui-chat/src/client/chat/TurnNavigator.tsx | 118 ++++++++++++ .../src/client/chat/turn-navigation.ts | 49 +++++ packages/client/ui-chat/src/client/locale.ts | 6 + .../ui-chat/tests/chat-view.client.spec.tsx | 69 +++++++ .../src/client/skeleton/ConversationRoot.tsx | 16 +- .../goal-multi-turn-actions/ui.expected.md | 3 + 16 files changed, 654 insertions(+), 9 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.i18n.yaml create mode 100644 .agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md create mode 100644 .agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md create mode 100644 packages/client/ui-chat/src/client/chat/TurnNavigator.module.css create mode 100644 packages/client/ui-chat/src/client/chat/TurnNavigator.tsx create mode 100644 packages/client/ui-chat/src/client/chat/turn-navigation.ts diff --git a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.i18n.yaml b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.i18n.yaml new file mode 100644 index 0000000000..bcc02e9b68 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.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-08-25-loaded-turn-chat-navigation.md +2026-08-25-loaded-turn-chat-navigation.md: 92e92323115c5da51ced09092d9ecd4e376f874f +2026-08-25-loaded-turn-chat-navigation.zh.md: b0cba5e78fad8b2ff3559d6cbfc12fb2160a2dc8 diff --git a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md new file mode 100644 index 0000000000..92e9232311 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md @@ -0,0 +1,41 @@ +# Agent Note: Loaded-Turn chat navigation + +Status: implemented + +English | [中文](2026-08-25-loaded-turn-chat-navigation.zh.md) + +## Problem + +Long Chat transcripts require repeated scrolling to revisit an earlier Turn. Session history is paged, so the browser may hold only a suffix of the conversation and the first loaded Turn may begin after its user message. A navigator that implies knowledge of unloaded Turns, or keys marks by their current array position, becomes misleading or unstable when Session Controller prepends the preceding event page. + +## Decision + +ChatView derives one navigation item for every currently loaded Turn that has a visible transcript node. Each item uses the Turn number as its stable React key and the first loaded user node, falling back to the Turn's first loaded node, as its scroll anchor. This is a pure projection of the Chat snapshot: the feature adds no Session event, persisted index, or pagination request. + +The rail renders the complete loaded Turn set with a 10px natural interval and never renders an ellipsis or unloaded-history placeholder. Its height shrink-wraps small sets; when the loaded set exceeds the available height, percentage positions compress every mark into the capped rail. When an earlier page arrives, existing Turn keys and DOM elements remain stable while their resolved positions change; CSS transitions animate that redistribution. A Turn split by the page boundary initially previews its Turn number and loaded assistant response, then gains the user prompt when the preceding page supplies it. + +The rail sits against the scrollport's right edge and centers on the band the sticky composer leaves visible. That band is the scrollport's own height minus the seat's, so ConversationRoot publishes `--dsh-conversation-viewport-height` beside the `--dsh-composer-height` it already measures on the same element, and the rail centers on their difference instead of a viewport height that ignores the Session header. + +The active mark follows a reading line near the top of the shared Chat scrollport. Scroll updates are coalesced with `requestAnimationFrame`; reaching the bottom selects the final loaded Turn. Activating a mark computes the target node's position in the existing scroll coordinate system, moves that same scrollport, and records the resulting Chat scroll-restoration anchor. + +Every Turn remains an accessible button even when dense marks visually overlap. The rail maps pointer height to the nearest loaded Turn, while keyboard focus and activation operate the individual buttons. Hover and focus show a compact prompt-and-response preview, the active mark is longer and darker, the rail is hidden when the Chat container is at most 900px wide, and reduced-motion preferences disable redistribution and mark-entry animation. + +## Alternatives considered + +**Persist a complete Turn index separately from the loaded Session page.** Rejected: the current client cannot navigate to an unloaded transcript anchor without first materializing that history, and a second index would duplicate Session projection state. + +**Show an ellipsis for unloaded history.** Rejected: pagination exposes only `hasMore`, not the number or distribution of earlier Turns, so an ellipsis would add no actionable destination. Loading a page and redistributing the actual loaded set communicates the available navigation precisely. + +**Always spread marks across the available height.** Rejected: a small loaded set produces visually unrelated marks separated by large empty regions. A fixed natural interval preserves a compact index while percentage compression still admits dense histories. + +**Key marks by loaded-array position.** Rejected: prepending a page would reuse each DOM element for a different Turn, lose focus and preview identity, and prevent the existing marks from animating to their new positions. + +**Call `scrollIntoView` on the Turn row.** Rejected: Chat owns a shared scroller, bottom-follow state, paging anchors, and persisted restoration coordinates. An opaque browser scroll would bypass those state updates. + +## Consequences + +Desktop-width Chat views can jump among all currently loaded Turns and inspect a short preview without expanding transcript content. Pagination prepends new destinations without presenting fabricated coverage or remounting existing marks. The first loaded mark can temporarily lack a prompt when the page boundary cuts through its Turn; its Turn label remains usable until the earlier page fills that data. If a future transcript virtualizer unmounts loaded anchors, navigation will need an explicit materialization operation before scrolling rather than changing this loaded-Turn projection. + +## Testing + +Component tests pin Turn derivation, accessible previews, scroll-coordinate jumps, DOM identity, and percentage redistribution after prepend. The long-interaction Chromium scenario pins the real paginated boundary, prompt completion after `Load earlier`, stable-mark movement, keyboard activation, and active-state update. The multi-Turn recorded Web snapshot includes the navigation landmark and buttons. diff --git a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md new file mode 100644 index 0000000000..b0cba5e78f --- /dev/null +++ b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md @@ -0,0 +1,41 @@ +# Agent Note:已加载 Turn 的聊天导航 + +Status: implemented + +[English](2026-08-25-loaded-turn-chat-navigation.md) | 中文 + +## 问题 + +较长的 Chat transcript 需要反复滚动才能回看更早的 Turn。Session 历史采用分页加载,因此浏览器可能只持有会话后缀,首个已加载 Turn 也可能从用户消息之后开始。如果导航暗示自己知道未加载的 Turn,或者按当前数组位置给刻度设置 key,Session Controller 前插上一页 event 后,导航就会产生误导或变得不稳定。 + +## 决定 + +ChatView 为当前已加载且含可见 transcript node 的每个 Turn 派生一项导航。每项使用 Turn 编号作为稳定的 React key,并以首个已加载用户 node 为滚动锚点;没有用户 node 时回退到该 Turn 的首个已加载 node。这只是 Chat snapshot 的纯投影:本功能不新增 Session event、持久化索引或分页请求。 + +导航轨道以 10px 自然间距渲染完整的已加载 Turn 集合,永不显示省略号或未加载历史占位。集合较小时轨道随内容收缩;已加载集合超过可用高度后,百分比位置会把所有刻度压缩到设定上限内。更早一页到达后,已有 Turn 的 key 和 DOM 元素保持不变,最终位置随之变化;CSS transition 为这次重排添加动画。如果一个 Turn 被分页边界截断,预览最初显示其 Turn 编号与已加载的助手回复,上一页补齐后再显示用户问题。 + +轨道紧贴滚动视口右缘,并在粘性输入区之外的可见区间内垂直居中。该区间等于滚动视口自身高度减去输入区高度,因此 ConversationRoot 在同一元素上除已有的 `--dsh-composer-height` 外再发布 `--dsh-conversation-viewport-height`,轨道按两者之差居中,而不是按忽略 Session 头部的视口高度居中。 + +活跃刻度跟随共享 Chat 滚动区顶部附近的阅读线。滚动更新由 `requestAnimationFrame` 合并;到达底部时选择最后一个已加载 Turn。激活刻度会在现有滚动坐标系中计算目标 node 的位置,移动同一个滚动区,并记录由此产生的 Chat 滚动恢复锚点。 + +即使密集刻度在视觉上重叠,每个 Turn 仍是可访问的按钮。轨道把指针高度映射到最近的已加载 Turn,键盘聚焦和激活则作用于各个按钮。悬停或聚焦显示紧凑的问题与回复预览,活跃刻度更长、更深;Chat 容器宽度不超过 900px 时隐藏轨道,用户偏好减少动态效果时关闭重排和刻度入场动画。 + +## 曾考虑的替代方案 + +**在已加载 Session 页之外持久化完整 Turn 索引。**否决:当前客户端必须先物化历史记录,才能导航到未加载的 transcript 锚点;第二套索引还会重复 Session 投影状态。 + +**为未加载历史显示省略号。**否决:分页只暴露 `hasMore`,不提供更早 Turn 的数量或分布,因此省略号不是可操作的目的地。加载一页并重排真实的已加载集合,才能精确表达当前可导航范围。 + +**始终把刻度铺满可用高度。**否决:已加载集合较小时,各刻度会被大片空白隔开,在视觉上失去关联。固定自然间距保持紧凑索引,百分比压缩仍能容纳密集历史。 + +**按已加载数组位置给刻度设置 key。**否决:前插一页会让每个 DOM 元素改为代表另一个 Turn,丢失焦点与预览身份,也无法让已有刻度移动到新位置。 + +**对 Turn 行调用 `scrollIntoView`。**否决:Chat 拥有共享滚动区、底部跟随状态、分页锚点与持久化恢复坐标。浏览器的黑盒滚动会绕过这些状态更新。 + +## 后果 + +桌面宽度的 Chat 视图可以在当前所有已加载 Turn 之间跳转,并在不展开 transcript 内容的情况下查看短预览。分页会前插新目的地,但不会虚构覆盖范围或重新挂载已有刻度。分页边界截断 Turn 时,首个已加载刻度可能暂时缺少问题;在上一页补齐数据前,Turn 标签仍可用于导航。如果未来 transcript 虚拟列表会卸载已加载锚点,导航需要在滚动前执行显式物化操作,而不应改变这里的已加载 Turn 投影。 + +## 测试 + +组件测试固定 Turn 派生、可访问预览、滚动坐标跳转、DOM 身份以及前插后的百分比重排。长交互 Chromium 场景固定真实分页边界、`加载更早` 后补齐问题、稳定刻度移动、键盘激活与活跃状态更新。多 Turn 的 Web 录制快照包含导航 landmark 和按钮。 diff --git a/apps/web/tests/chat-long-interactions.e2e.ts b/apps/web/tests/chat-long-interactions.e2e.ts index 03198a23a8..4525cf8390 100644 --- a/apps/web/tests/chat-long-interactions.e2e.ts +++ b/apps/web/tests/chat-long-interactions.e2e.ts @@ -153,7 +153,7 @@ describe('web e2e: long Chat interaction contract', () => { }) await seedSession(scaffold, FIXTURE.log, SESSION_ID) browser = await chromium.launch() - page = await newEnglishPage(browser, 900) + page = await newEnglishPage(browser, 1_280) tripwire = watchConsole(page) await page.goto(scaffold.baseUrl, { waitUntil: 'load' }) await page.waitForSelector('[class*="frame"]', { timeout: 30_000 }) @@ -193,6 +193,48 @@ describe('web e2e: long Chat interaction contract', () => { if (boundary === undefined) throw new Error(`turn ${String(BRANCH_TURN)} has no turn/end event`) const expectedUserText = textContent(branchUserEvent.data.content) + const turnNavigation = page.getByRole('navigation', { name: 'Turn navigation' }) + await turnNavigation.waitFor({ state: 'visible', timeout: 15_000 }) + const initialTurnButtons = turnNavigation.getByRole('button') + const initialTurnCount = await initialTurnButtons.count() + expect(initialTurnCount).toBeGreaterThan(1) + expect(await initialTurnButtons.last().getAttribute('aria-current')).toBe('true') + const firstTurnButton = initialTurnButtons.first() + const firstTurnLabel = await firstTurnButton.getAttribute('aria-label') + if (firstTurnLabel === null) throw new Error('first Turn navigation mark has no accessible label') + const firstTurn = Number(firstTurnLabel.match(/^Jump to turn (\d+)$/)?.[1]) + expect(Number.isSafeInteger(firstTurn)).toBe(true) + await firstTurnButton.focus() + const preview = page.getByRole('tooltip') + await preview.waitFor({ state: 'visible', timeout: 5_000 }) + // The first loaded Turn may begin mid-Turn at a page boundary. Its mark is + // still useful with the loaded response and gains the prompt after prepend. + expect(await preview.textContent()).toContain(`Turn ${String(firstTurn)}`) + expect(await preview.textContent()).toContain(FIXTURE.markers.assistant(firstTurn)) + const firstTurnPosition = await firstTurnButton.evaluate(button => ( + button.parentElement?.style.getPropertyValue('--turn-position') ?? '' + )) + expect(firstTurnPosition).toBe('0%') + + const loadEarlier = page.getByRole('button', { name: 'Load earlier', exact: true }) + await loadEarlier.click() + await expect.poll(() => turnNavigation.getByRole('button').count(), { timeout: 15_000 }) + .toBeGreaterThan(initialTurnCount) + const stableFirstTurnButton = turnNavigation.getByRole('button', { name: firstTurnLabel }) + expect(await stableFirstTurnButton.evaluate(button => ( + button.parentElement?.style.getPropertyValue('--turn-position') ?? '' + ))).not.toBe(firstTurnPosition) + await stableFirstTurnButton.focus() + await expect.poll(() => preview.textContent(), { timeout: 5_000 }) + .toContain(FIXTURE.markers.user(firstTurn)) + expect(await preview.textContent()).toContain(FIXTURE.markers.assistant(firstTurn)) + await stableFirstTurnButton.press('Enter') + await expect.poll(() => stableFirstTurnButton.getAttribute('aria-current'), { timeout: 5_000 }).toBe('true') + await expect.poll( + () => page.locator(`[data-chat-turn="${String(firstTurn)}"][data-chat-flow-kind="user"]`).count(), + { timeout: 5_000 }, + ).toBe(1) + await wheelUntilMounted(page, `[data-chat-call-id="${TARGET_CALL_2}"]`, -1_100) const toolUserKey = messageKey(toolUserEvent) const toolAssistantKey = assistantKey(toolAssistantEvent) diff --git a/packages/client/ui-chat/README.i18n.yaml b/packages/client/ui-chat/README.i18n.yaml index 4859153e08..c63e44730a 100644 --- a/packages/client/ui-chat/README.i18n.yaml +++ b/packages/client/ui-chat/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-chat/README.md -README.md: 5253cb95b0e5c0b89c32646e2ae2915936d35288 -README.zh.md: 8cd2d0d581a0493892aed23f42ebc0c229a0bc17 +README.md: eca746a7598d57325a0972b25b684e7fbc7c1632 +README.zh.md: df690ec2d03c27edbdf5802bbe02380960527d4c diff --git a/packages/client/ui-chat/README.md b/packages/client/ui-chat/README.md index 5253cb95b0..eca746a759 100644 --- a/packages/client/ui-chat/README.md +++ b/packages/client/ui-chat/README.md @@ -14,4 +14,4 @@ None; Chat presentation does not assemble or mutate provider requests. ## Known Limitations and Deferred Work -- **The view reflects the loaded Session window** — older transcript nodes become available only after Session Controller loads the preceding event page. +- **The view reflects the loaded Session window** — older transcript nodes become available only after Session Controller loads the preceding event page. Turn navigation likewise represents only loaded Turns; loading an earlier page preserves existing Turn marks and redistributes the complete loaded set in a compact rail without an unloaded-history placeholder. Marks stay 10px apart until the loaded set exceeds the available height, then compress to fit. diff --git a/packages/client/ui-chat/README.zh.md b/packages/client/ui-chat/README.zh.md index 8cd2d0d581..df690ec2d0 100644 --- a/packages/client/ui-chat/README.zh.md +++ b/packages/client/ui-chat/README.zh.md @@ -14,4 +14,4 @@ Conversation 组装的浏览器 Chat target。本包注册 Chat event definition ## 已知限制与暂缓事项 -- **视图只反映已加载的 Session 窗口**——只有 Session Controller 加载前一页 event 后,更早的 transcript node 才会出现。 +- **视图只反映已加载的 Session 窗口**——只有 Session Controller 加载前一页 event 后,更早的 transcript node 才会出现。轮次导航同样只表示已加载的 Turn;加载更早一页时,已有 Turn 刻度保持身份不变,完整的已加载集合在紧凑轨道中重新排布,不显示未加载历史占位。刻度默认相隔 10px,仅在已加载集合超过可用高度时压缩间距。 diff --git a/packages/client/ui-chat/src/client/chat/ChatNodeSeat.tsx b/packages/client/ui-chat/src/client/chat/ChatNodeSeat.tsx index 22a6d0dc35..7568f767ff 100644 --- a/packages/client/ui-chat/src/client/chat/ChatNodeSeat.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatNodeSeat.tsx @@ -36,6 +36,10 @@ export const ChatNodeSeat = memo(function ChatNodeSeat({ node, selectedCallId, cwd, openFile, inspectCall, forkAt, renderMessageImages, fileMentions, ]) if (routedNode === undefined || owner === null) return null + const location = routedNode.location + const turn = location.kind === 'turn' || location.kind === 'step' + ? location.turn.turn + : undefined // Runtime dispatch owns the correlation: every Node's discriminant is the // keyed-slot entry passed alongside that same Node. TypeScript does not // distribute an object containing a union into a union of objects itself. @@ -46,6 +50,7 @@ export const ChatNodeSeat = memo(function ChatNodeSeat({ data-chat-anchor-key={routedNode.key} data-chat-flow-key={routedNode.key} data-chat-flow-kind={routedNode.kind} + data-chat-turn={turn} > {renderSlot('conversation.chat.node', routedOwner, { entryKey: routedNode.kind, diff --git a/packages/client/ui-chat/src/client/chat/ChatView.tsx b/packages/client/ui-chat/src/client/chat/ChatView.tsx index a647ad5c18..a82841bf53 100644 --- a/packages/client/ui-chat/src/client/chat/ChatView.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatView.tsx @@ -9,6 +9,8 @@ import { Button, IconChevronDownOutline14, Modal } from '@deepseek-ai/dsh-client import type { ChatViewSlotProps } from '../contract/slots.ts' import { PendingSteeringBubble } from './MessageItem.tsx' import { ChatNodeSeat } from './ChatNodeSeat.tsx' +import { TurnNavigator } from './TurnNavigator.tsx' +import { deriveTurnNavigationItems, type TurnNavigationItem } from './turn-navigation.ts' import { formatRunDuration } from './message-chrome.ts' import css from './ChatView.module.css' @@ -151,6 +153,7 @@ export function ChatView({ }: ChatViewSlotProps) { const order = useChat(s => s.order) const nodeStore = useChat(s => s.nodes) + const locations = useChat(s => s.locations) const timeline = useChat(s => s.timeline) const inbox = useSession(s => s.queue) // Workspace root off the session list row: path summaries display relative to it. @@ -208,11 +211,18 @@ export function ChatView({ [loadImage, renderSlot], ) const runningTurnStart = useMemo(() => runningTurnStartTime(timeline), [timeline]) + const turnNavigationItems = useMemo( + () => deriveTurnNavigationItems({ timeline, locations, nodes: nodeStore }), + [locations, nodeStore, order, timeline], + ) const listRef = useRef(null) const columnRef = useRef(null) const atBottomRef = useRef(true) const [atBottom, setAtBottom] = useState(true) + const [activeTurn, setActiveTurn] = useState( + () => turnNavigationItems.at(-1)?.turn ?? null, + ) /** Last position delivered or written on the main thread. */ const observedTopRef = useRef(0) /** Paging anchor: semantic row/position at click, updated by reader scrolls @@ -234,6 +244,51 @@ export function ChatView({ const lastSteeringId = pendingSteering[pendingSteering.length - 1]?.id ?? null const followSig = `${openState}:${firstSeq}:${lastKey}:${order.length}:${running ? 1 : 0}:${lastSteeringId ?? ''}` + const syncActiveTurn = useCallback((): void => { + const local = listRef.current + const first = turnNavigationItems[0] + if (local === null || first === undefined) { + setActiveTurn(null) + return + } + const el = scrollerOf(local) + const scrollport = el.getBoundingClientRect() + const readingLine = scrollport.top + Math.min(96, el.clientHeight * 0.2) + let next = first.turn + for (const item of turnNavigationItems) { + const row = anchorElement(local, item.anchorKey) + if (row === null || row.getBoundingClientRect().top > readingLine) break + next = item.turn + } + if (el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_THRESHOLD + 1) { + next = turnNavigationItems.at(-1)?.turn ?? next + } + setActiveTurn(current => current === next ? current : next) + }, [turnNavigationItems]) + + const activeFrameRef = useRef(null) + const scheduleActiveTurn = useCallback((): void => { + if (activeFrameRef.current !== null) return + if (typeof requestAnimationFrame === 'undefined') { + syncActiveTurn() + return + } + activeFrameRef.current = requestAnimationFrame(() => { + activeFrameRef.current = null + syncActiveTurn() + }) + }, [syncActiveTurn]) + + useEffect(() => () => { + if (activeFrameRef.current !== null && typeof cancelAnimationFrame !== 'undefined') { + cancelAnimationFrame(activeFrameRef.current) + } + }, []) + + useLayoutEffect(() => { + scheduleActiveTurn() + }, [scheduleActiveTurn]) + const toBottom = (el: HTMLElement): void => { anchorRef.current = null el.scrollTop = el.scrollHeight @@ -241,6 +296,7 @@ export function ChatView({ atBottomRef.current = true setAtBottom(true) chatScroll.save(null) + setActiveTurn(turnNavigationItems.at(-1)?.turn ?? null) } useLayoutEffect(() => { @@ -339,6 +395,7 @@ export function ChatView({ if (isAtBottom) chatScroll.save(null) else if (position !== null) chatScroll.save(position) observedTopRef.current = el.scrollTop + scheduleActiveTurn() } // Bind the scroll listener on the resolved scrollport once per mount; @@ -405,9 +462,33 @@ export function ChatView({ loadOlder() } + const navigateToTurn = (item: TurnNavigationItem): void => { + const local = listRef.current + if (local === null) return + const row = anchorElement(local, item.anchorKey) + if (row === null) return + anchorRef.current = null + const el = scrollerOf(local) + el.scrollTop += flowTop(row, el) - 24 + observedTopRef.current = el.scrollTop + const isAtBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_THRESHOLD + 1 + atBottomRef.current = isAtBottom + setAtBottom(isAtBottom) + setActiveTurn(item.turn) + const position = isAtBottom ? null : scrollPosition(local, el) + if (isAtBottom) chatScroll.save(null) + else if (position !== null) chatScroll.save(position) + } + return (
+
{openState === 'loading' &&
{t('chat.loadingHistory')}
} {openState === 'error' && openError !== null && ( diff --git a/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css b/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css new file mode 100644 index 0000000000..8a874897de --- /dev/null +++ b/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css @@ -0,0 +1,176 @@ +/* Zero-height sticky slot, like the back-to-bottom control: the rail floats + over the transcript's right gutter without extending scrollHeight. */ +.slot { + position: sticky; + top: 0; + z-index: 6; + height: 0; + pointer-events: none; +} + +.rail { + /* The band a reader actually sees: the scrollport minus the sticky composer + stack covering its floor. ConversationRoot publishes both measurements on + the scrollport; the fallbacks carry the first paint before its observer + fires. */ + --turn-rail-band: calc( + var(--dsh-conversation-viewport-height, 100dvh) - var(--dsh-composer-height, 152px) + ); + --turn-preview-height: 100px; + + position: absolute; + top: calc(var(--turn-rail-band) / 2); + /* Flush with the scrollport edge: the slot sits inside the transcript's side + padding, so the rail gives that inset back and keeps 12px of its own. */ + right: calc(12px - (var(--dsh-composer-side-clearance) + 16px)); + width: 28px; + height: min( + var(--turn-natural-height), + clamp(120px, calc(var(--turn-rail-band) - 64px), 420px) + ); + cursor: pointer; + pointer-events: auto; + transform: translateY(-50%); + transition: height 220ms cubic-bezier(0.2, 0.8, 0.2, 1); +} + +.marks { + position: absolute; + inset: var(--turn-rail-inset) 0; +} + +.markPosition { + position: absolute; + top: min(var(--turn-natural-position), var(--turn-position)); + right: 0; + left: 0; + height: 10px; + transform: translateY(-50%); + transition: top 220ms cubic-bezier(0.2, 0.8, 0.2, 1); + animation: dsh-turn-mark-enter 150ms ease-out; +} + +/* The rail owns pointer input for the whole column, so a mark is a keyboard + destination that paints one tick — never a mouse target of its own. */ +.mark { + position: absolute; + /* As wide as the longest tick, right-aligned with it: the focus ring below + then wraps the tick instead of the rail's full pointer column. */ + inset: 0 0 0 auto; + width: 20px; + padding: 0; + border: 0; + border-radius: 8px; + background: transparent; + cursor: pointer; + pointer-events: none; +} + +.mark::before { + position: absolute; + top: 50%; + right: 0; + width: 12px; + height: 2px; + border-radius: 2px; + background: var(--dsw-alias-border-l4); + content: ''; + transform: translateY(-50%); + transition: width 140ms ease, background-color 140ms ease; +} + +.markPreview::before { + width: 18px; + background: var(--dsw-alias-label-tertiary); +} + +.markActive::before { + width: 20px; + background: var(--dsw-alias-label-primary); +} + +/* Keyboard focus outranks both resting states: the tick takes the brand color + the rest of the rail never uses, and a hairline ring keeps it legible + against a busy transcript. */ +.mark:focus-visible::before { + width: 20px; + background: var(--dsw-alias-state-business-primary); +} + +.mark:focus-visible { + outline: 1px solid var(--dsw-alias-state-business-primary); + outline-offset: 2px; +} + +.preview { + position: absolute; + /* Centered on its mark (mark positions are measured inside the rail inset), + then held clear of both rail ends. */ + top: clamp( + 0px, + calc( + min(var(--turn-natural-position), var(--turn-position)) + + var(--turn-rail-inset) - var(--turn-preview-height) / 2 + ), + calc(100% - var(--turn-preview-height)) + ); + right: calc(100% + 10px); + box-sizing: border-box; + width: min(300px, calc(100cqw - 120px)); + max-height: var(--turn-preview-height); + overflow: hidden; + padding: 10px 12px; + border: 1px solid var(--dsw-alias-border-l2); + border-radius: 10px; + color: var(--dsw-alias-label-primary); + background: var(--dsw-alias-bg-layer-1); + box-shadow: var(--dsw-shadow-lv2); + pointer-events: none; + animation: dsh-turn-preview-enter 120ms ease-out; + transition: top 140ms cubic-bezier(0.2, 0.8, 0.2, 1); +} + +.previewPrompt, +.previewResponse { + display: -webkit-box; + overflow: hidden; + -webkit-box-orient: vertical; +} + +.previewPrompt { + font: var(--dsw-font-xs-strong-13); + -webkit-line-clamp: 2; +} + +.previewResponse { + margin-top: 4px; + color: var(--dsw-alias-label-caption); + font: var(--dsw-font-xxs-12); + -webkit-line-clamp: 2; +} + +@keyframes dsh-turn-mark-enter { + from { opacity: 0; } + to { opacity: 1; } +} + +@keyframes dsh-turn-preview-enter { + from { opacity: 0; transform: translateX(4px); } + to { opacity: 1; transform: translateX(0); } +} + +@container (max-width: 900px) { + .slot { + display: none; + } +} + +@media (prefers-reduced-motion: reduce) { + .rail, + .markPosition, + .mark::before, + .preview { + transition: none; + animation: none; + } +} diff --git a/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx b/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx new file mode 100644 index 0000000000..79029a3e52 --- /dev/null +++ b/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx @@ -0,0 +1,118 @@ +import { + useId, useState, type CSSProperties, type MouseEvent, type PointerEvent, +} from 'react' +import type { ChatViewSlotProps } from '../contract/slots.ts' +import type { TurnNavigationItem } from './turn-navigation.ts' +import css from './TurnNavigator.module.css' + +interface TurnNavigatorProps { + readonly items: readonly TurnNavigationItem[] + readonly activeTurn: number | null + readonly onNavigate: (item: TurnNavigationItem) => void + readonly t: ChatViewSlotProps['t'] +} + +/** Resting gap between neighbouring marks before the rail compresses to fit. */ +const TURN_SPACING_PX = 10 +/** Rail padding above the first mark and below the last one, per end. */ +const RAIL_INSET_PX = 6 + +type TurnPositionStyle = CSSProperties & { + readonly '--turn-natural-position': string + readonly '--turn-position': string +} + +type TurnRailStyle = CSSProperties & { + readonly '--turn-natural-height': string + readonly '--turn-rail-inset': string +} + +function itemPosition(index: number, count: number): TurnPositionStyle { + const ratio = count <= 1 ? 0 : index / (count - 1) + return { + '--turn-natural-position': `${String(index * TURN_SPACING_PX)}px`, + '--turn-position': `${String(ratio * 100)}%`, + } +} + +function railSize(count: number): TurnRailStyle { + return { + '--turn-natural-height': `${String((count - 1) * TURN_SPACING_PX + 2 * RAIL_INSET_PX)}px`, + '--turn-rail-inset': `${String(RAIL_INSET_PX)}px`, + } +} + +function itemAtPointer( + items: readonly TurnNavigationItem[], + rail: HTMLElement, + clientY: number, +): TurnNavigationItem | undefined { + const rect = rail.getBoundingClientRect() + const usableHeight = Math.max(1, rect.height - 2 * RAIL_INSET_PX) + const ratio = Math.max(0, Math.min(1, (clientY - rect.top - RAIL_INSET_PX) / usableHeight)) + return items[Math.round(ratio * (items.length - 1))] +} + +/** Compact rail of the currently loaded Turns with hover and focus previews. */ +export function TurnNavigator({ items, activeTurn, onNavigate, t }: TurnNavigatorProps) { + const [previewTurn, setPreviewTurn] = useState(null) + const previewId = useId() + if (items.length < 2) return null + const previewIndex = items.findIndex(item => item.turn === previewTurn) + const preview = previewIndex < 0 ? undefined : items[previewIndex] + const previewPosition = previewIndex < 0 ? undefined : itemPosition(previewIndex, items.length) + const previewAtPointer = (event: PointerEvent): void => { + setPreviewTurn(itemAtPointer(items, event.currentTarget, event.clientY)?.turn ?? null) + } + const navigateAtPointer = (event: MouseEvent): void => { + const item = itemAtPointer(items, event.currentTarget, event.clientY) + if (item !== undefined) onNavigate(item) + } + return ( +
+ +
+ ) +} diff --git a/packages/client/ui-chat/src/client/chat/turn-navigation.ts b/packages/client/ui-chat/src/client/chat/turn-navigation.ts new file mode 100644 index 0000000000..5ce5305dfd --- /dev/null +++ b/packages/client/ui-chat/src/client/chat/turn-navigation.ts @@ -0,0 +1,49 @@ +import type { ChatNode } from '../contract/chat-nodes.ts' +import type { ChatSnapshot } from '../contract/snapshot.ts' + +/** One loaded Turn projected into the compact Chat navigation rail. */ +export interface TurnNavigationItem { + readonly turn: number + readonly anchorKey: string + readonly prompt: string + readonly response: string +} + +function compactText(parts: readonly string[]): string { + return parts.join(' ').replace(/\s+/g, ' ').trim() +} + +function promptText(node: ChatNode): string { + if (node.kind !== 'user') return '' + return compactText(node.data.content.flatMap(block => block.type === 'text' ? [block.text] : [])) +} + +function responseText(node: ChatNode): string { + if (node.kind !== 'assistant-step') return '' + return compactText(node.data.blocks.flatMap(block => block.kind === 'text' ? [block.text] : [])) +} + +/** + * Project the currently loaded Chat window into stable Turn navigation items. + * @param snapshot - current incremental Chat snapshot. + * @returns loaded Turns that have at least one visible rendered anchor. + */ +export function deriveTurnNavigationItems( + snapshot: Pick, +): readonly TurnNavigationItem[] { + return snapshot.timeline.turnOrder.flatMap((turn): TurnNavigationItem[] => { + const nodes = snapshot.locations.getTurn(turn) + .map(key => snapshot.nodes.get(key)) + .filter((node): node is ChatNode => node !== undefined && node.visibility === 'visible') + const user = nodes.find(node => node.kind === 'user') + const anchor = user ?? nodes[0] + if (anchor === undefined) return [] + const response = nodes.findLast(node => responseText(node) !== '') + return [{ + turn, + anchorKey: anchor.key, + prompt: user === undefined ? '' : promptText(user), + response: response === undefined ? '' : responseText(response), + }] + }) +} diff --git a/packages/client/ui-chat/src/client/locale.ts b/packages/client/ui-chat/src/client/locale.ts index be8a3521ac..6ffbb125d4 100644 --- a/packages/client/ui-chat/src/client/locale.ts +++ b/packages/client/ui-chat/src/client/locale.ts @@ -28,6 +28,9 @@ export const zh = { 'chat.loadOlder': '加载更早', 'chat.toBottom': '回到底部', 'chat.deepDiving': '深度求索中...', + 'chat.turnNavigation.label': '轮次导航', + 'chat.turnNavigation.jump': '跳转到第 {turn} 轮', + 'chat.turnNavigation.turn': '第 {turn} 轮', 'fileOpen.title': '无法打开文件', 'fileOpen.unknown': '无法打开此文件', 'fileOpen.folderTitle': '无法打开文件夹', @@ -114,6 +117,9 @@ export const en = { 'chat.loadOlder': 'Load earlier', 'chat.toBottom': 'Back to bottom', 'chat.deepDiving': 'Deep diving...', + 'chat.turnNavigation.label': 'Turn navigation', + 'chat.turnNavigation.jump': 'Jump to turn {turn}', + 'chat.turnNavigation.turn': 'Turn {turn}', 'fileOpen.title': 'Couldn’t open file', 'fileOpen.unknown': 'Couldn’t open this file', 'fileOpen.folderTitle': 'Couldn’t open folder', diff --git a/packages/client/ui-chat/tests/chat-view.client.spec.tsx b/packages/client/ui-chat/tests/chat-view.client.spec.tsx index d112bd779c..de703920fc 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -32,6 +32,7 @@ import { } from '../src/client/chat/MessageItem.tsx' import { TurnTailNodeView } from '../src/client/chat/TurnTailNodeView.tsx' import { formatRunDuration } from '../src/client/chat/message-chrome.ts' +import { deriveTurnNavigationItems } from '../src/client/chat/turn-navigation.ts' import { chatSnapshotFixture } from './chat-snapshot-fixture.client.ts' afterEach(() => { @@ -114,6 +115,12 @@ const user = (seq: number, text: string): UserMessageNode => ({ content: [{ type: 'text', text }] as never, source: null, }) +const userInTurn = (seq: number, text: string, turn: number): ConversationNode => ({ + ...user(seq, text), + // The production Location index owns this association. The legacy fixture + // accepts the extra coordinate so component tests can build the same view. + turn, +} as unknown as ConversationNode) const assistant = (seq: number, text: string, turn = 1): AssistantMessageNode => ({ kind: 'assistant', seq, time: seq * 1_000, turn, step: 1, blocks: [{ kind: 'text', text }], }) @@ -406,6 +413,68 @@ describe('Chat node rendering', () => { }) describe('ChatView', () => { + it('projects loaded turns into prompt and response navigation previews', () => { + const snapshot = chatSnapshotFixture({ + nodes: [ + userInTurn(1, 'first prompt', 1), + assistant(2, 'first response', 1), + userInTurn(4, 'second prompt', 2), + assistant(5, 'second response', 2), + ], + turnEnds: new Map([[1, 3], [2, 6]]), + }) + expect(deriveTurnNavigationItems(snapshot)).toEqual([ + { turn: 1, anchorKey: 'fixture:user:1', prompt: 'first prompt', response: 'first response' }, + { turn: 2, anchorKey: 'fixture:user:4', prompt: 'second prompt', response: 'second response' }, + ]) + const h = makeHarness({}, {}, snapshot) + const view = render() + const navigation = view.getByRole('navigation', { name: '轮次导航' }) + expect(navigation.style.getPropertyValue('--turn-natural-height')).toBe('22px') + const first = view.getByRole('button', { name: '跳转到第 1 轮' }) + const second = view.getByRole('button', { name: '跳转到第 2 轮' }) + expect(first.parentElement?.style.getPropertyValue('--turn-natural-position')).toBe('0px') + expect(second.parentElement?.style.getPropertyValue('--turn-natural-position')).toBe('10px') + expect(second.getAttribute('aria-current')).toBe('true') + fireEvent.focus(first) + const preview = view.getByRole('tooltip') + expect(preview.textContent).toContain('first prompt') + expect(preview.textContent).toContain('first response') + }) + + it('jumps to a turn anchor and reflows stable marks after an older page arrives', () => { + const later = [ + userInTurn(4, 'second prompt', 2), assistant(5, 'second response', 2), + userInTurn(7, 'third prompt', 3), assistant(8, 'third response', 3), + ] + const h = makeHarness({ nodes: later }, { hasMore: true }) + const view = render() + const second = view.getByRole('button', { name: '跳转到第 2 轮' }) + const secondPosition = second.parentElement as HTMLElement + expect(secondPosition.style.getPropertyValue('--turn-position')).toBe('0%') + + const scroller = view.container.querySelector('[class*="scroll"]') as HTMLDivElement + const metrics = installScrollMetrics(scroller, 1_000, 300) + metrics.setLayout(1_000, 700) + vi.spyOn(scroller, 'getBoundingClientRect').mockReturnValue({ top: 0, bottom: 300 } as DOMRect) + const secondRow = view.container.querySelector('[data-chat-flow-key="fixture:user:4"]') as HTMLElement + vi.spyOn(secondRow, 'getBoundingClientRect').mockReturnValue({ top: -500, bottom: -440 } as DOMRect) + fireEvent.click(second) + expect(scroller.scrollTop).toBe(176) + expect(second.getAttribute('aria-current')).toBe('true') + + act(() => { + h.setChat({ + nodes: [userInTurn(1, 'first prompt', 1), assistant(2, 'first response', 1), ...later], + turnTimings: new Map([[1, { startTime: 1_000 }], [2, { startTime: 4_000 }], [3, { startTime: 7_000 }]]), + }) + }) + const movedSecond = view.getByRole('button', { name: '跳转到第 2 轮' }) + expect(movedSecond.parentElement).toBe(secondPosition) + expect(secondPosition.style.getPropertyValue('--turn-natural-position')).toBe('10px') + expect(secondPosition.style.getPropertyValue('--turn-position')).toBe('50%') + }) + it('hands a windowless tool result to the Tool seat with an empty tool name', () => { const h = makeHarness({ nodes: [{ ...toolResult(3, 'w1'), call: null }], diff --git a/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.tsx b/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.tsx index a3a5942da7..d172b261cb 100644 --- a/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.tsx +++ b/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.tsx @@ -38,10 +38,13 @@ export function ConversationRoot({ const [pendingWorkspaceId, setPendingWorkspaceId] = useState() const pickerAnchor = useRef(null) - // Publishes the seat's live height as --dsh-composer-height on the scroll - // body so floating View controls clear the composer as - // it grows. Callback ref, not an effect; stable identity prevents observer - // churn while the first blank session fills the resident body outlet. + // Publishes the two live measurements floating View chrome reads off the + // scroll body: the seat's height as --dsh-composer-height, so controls clear + // the composer as it grows, and the scrollport's own height as + // --dsh-conversation-viewport-height, so a control can sit in the band the + // seat leaves visible. Callback ref, not an effect; stable identity prevents + // observer churn while the first blank session fills the resident body + // outlet. const seatObserver = useRef(null) const seatResizeRef = useCallback((seat: HTMLDivElement | null): void => { seatObserver.current?.disconnect() @@ -50,8 +53,13 @@ export function ConversationRoot({ if (seat === null || scroller === null) return seatObserver.current = new ResizeObserver(() => { scroller.style.setProperty('--dsh-composer-height', `${seat.offsetHeight}px`) + scroller.style.setProperty( + '--dsh-conversation-viewport-height', + `${scroller.clientHeight}px`, + ) }) seatObserver.current.observe(seat) + seatObserver.current.observe(scroller) }, []) const sessionWorkspace = sessionId === undefined diff --git a/snapshots/web/goal-multi-turn-actions/ui.expected.md b/snapshots/web/goal-multi-turn-actions/ui.expected.md index 80733e2719..a835b3352e 100644 --- a/snapshots/web/goal-multi-turn-actions/ui.expected.md +++ b/snapshots/web/goal-multi-turn-actions/ui.expected.md @@ -9,6 +9,9 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" - group "Command input": /goal 做两个turn,每个turn输出随机一个包的文件结构。注意你做完一个turn之后,直接输出内容,停止,我们的系统会帮你再开一个turn,你看着做一个类似的 - 'button "goal Goal created Status: active Objective: 做两个turn,每个turn输出随机一个包的文件结构。注意你做完一个turn之后,直接输出内容,停止,我们的系统会帮你再开一个turn,你看着做一个类似的 Rounds: 0/256 Activation: armed Commands: /goal edit , /goal pause, /goal clear"': - img From ba84299c989a2f00a7966b7c8bf8eea119841e7f Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Tue, 25 Aug 2026 14:26:10 +0800 Subject: [PATCH 02/13] test(web): record the Turn rail in every affected aria golden The rail is a landmark on every Chat wide enough to show it, so each recorded conversation with at least two loaded Turns now carries the navigation node and its marks. --- .../stats-paged-history/ui.expected.md | 29 +++++++++++++++++++ .../web/cordis-tool-round/ui.expected.md | 4 +++ snapshots/web/message-actions/ui.expected.md | 3 ++ .../seeded-history/command-row.expected.md | 3 ++ .../seeded-history/feedback-row.expected.md | 3 ++ snapshots/web/seeded-history/ui.expected.md | 3 ++ .../web/subagent-conversation/ui.expected.md | 3 ++ 7 files changed, 48 insertions(+) diff --git a/apps/web/tests/expected/stats-paged-history/ui.expected.md b/apps/web/tests/expected/stats-paged-history/ui.expected.md index 78d175af5d..1722b90b13 100644 --- a/apps/web/tests/expected/stats-paged-history/ui.expected.md +++ b/apps/web/tests/expected/stats-paged-history/ui.expected.md @@ -7,6 +7,35 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" + - button "Jump to turn 3" + - button "Jump to turn 4" + - button "Jump to turn 5" + - button "Jump to turn 6" + - button "Jump to turn 7" + - button "Jump to turn 8" + - button "Jump to turn 9" + - button "Jump to turn 10" + - button "Jump to turn 11" + - button "Jump to turn 12" + - button "Jump to turn 13" + - button "Jump to turn 14" + - button "Jump to turn 15" + - button "Jump to turn 16" + - button "Jump to turn 17" + - button "Jump to turn 18" + - button "Jump to turn 19" + - button "Jump to turn 20" + - button "Jump to turn 21" + - button "Jump to turn 22" + - button "Jump to turn 23" + - button "Jump to turn 24" + - button "Jump to turn 25" + - button "Jump to turn 26" + - button "Jump to turn 27" + - button "Jump to turn 28" - text: m1 7/25 {{clock}} - button "Copy": - img diff --git a/snapshots/web/cordis-tool-round/ui.expected.md b/snapshots/web/cordis-tool-round/ui.expected.md index cc05c3aed9..2ec7d45c4a 100644 --- a/snapshots/web/cordis-tool-round/ui.expected.md +++ b/snapshots/web/cordis-tool-round/ui.expected.md @@ -9,6 +9,10 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" + - button "Jump to turn 3" - text: "Use only Cordis tools. First call cordis_inspect_self with no arguments. Then call cordis_define with plugin kind \"new\", idPrefix \"snap\", name \"snapshot noop\", purpose \"does nothing, for the snapshot\", code.host exactly \"return { name: \\\"snapshot-noop\\\", apply(ctx) {} }\" and code.client exactly \"return { inject: [\\\"slots\\\"], apply(ctx) { ctx.slots.register({ name: \\\"shell.overlay\\\", id: \\\"snapshot-probe\\\" }, () => React.createElement(\\\"div\\\", { \\\"data-snapshot-probe\\\": \\\"loaded\\\" })) } }\". Read its returned pluginId and packageId, then call cordis_run with those exact IDs and mode \"run\". After the run request returns, reply exactly CORDIS_UI_READY and stop. {{clock}}" - button "Copy": - img diff --git a/snapshots/web/message-actions/ui.expected.md b/snapshots/web/message-actions/ui.expected.md index 0419f0f1b1..794bd71758 100644 --- a/snapshots/web/message-actions/ui.expected.md +++ b/snapshots/web/message-actions/ui.expected.md @@ -7,6 +7,9 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" - text: "Use the read tool twice in one assistant message: read a.txt and b.txt. Then reply with the single word DONE and stop. 7/25 {{clock}}" - button "Copy": - img diff --git a/snapshots/web/seeded-history/command-row.expected.md b/snapshots/web/seeded-history/command-row.expected.md index 4402a0c69b..01234b74da 100644 --- a/snapshots/web/seeded-history/command-row.expected.md +++ b/snapshots/web/seeded-history/command-row.expected.md @@ -7,6 +7,9 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" - text: "Use the read tool twice in one assistant message: read a.txt and b.txt. Then reply with the single word DONE and stop. 7/25 {{clock}}" - button "Copy": - img diff --git a/snapshots/web/seeded-history/feedback-row.expected.md b/snapshots/web/seeded-history/feedback-row.expected.md index 3f7148828e..3b362a9252 100644 --- a/snapshots/web/seeded-history/feedback-row.expected.md +++ b/snapshots/web/seeded-history/feedback-row.expected.md @@ -7,6 +7,9 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" - text: "Use the read tool twice in one assistant message: read a.txt and b.txt. Then reply with the single word DONE and stop. 7/25 {{clock}}" - button "Copy": - img diff --git a/snapshots/web/seeded-history/ui.expected.md b/snapshots/web/seeded-history/ui.expected.md index 3ca7fba7ca..1f72791a3c 100644 --- a/snapshots/web/seeded-history/ui.expected.md +++ b/snapshots/web/seeded-history/ui.expected.md @@ -7,6 +7,9 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" - text: "Use the read tool twice in one assistant message: read a.txt and b.txt. Then reply with the single word DONE and stop. 7/25 {{clock}}" - button "Copy": - img diff --git a/snapshots/web/subagent-conversation/ui.expected.md b/snapshots/web/subagent-conversation/ui.expected.md index dc26ca3e97..68eb4d1082 100644 --- a/snapshots/web/subagent-conversation/ui.expected.md +++ b/snapshots/web/subagent-conversation/ui.expected.md @@ -14,6 +14,9 @@ - tablist: - tab "Chat" [selected] - tab "Trajectory" +- navigation "Turn navigation": + - button "Jump to turn 1" + - button "Jump to turn 2" - text: Explain event sourcing in one sentence. {{clock}} - button "Copy": - img From 1272c7d0dfcafc533c2a4e1a2258efbc9c63822d Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Tue, 25 Aug 2026 14:46:38 +0800 Subject: [PATCH 03/13] perf(web): accumulate the Turn rail instead of scanning the loaded window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rail's items now ride the Chat snapshot: a structural upsert re-derives the loaded Turn set, a content-only upsert re-derives only the Turns whose nodes changed, and each preview is capped so navigation state never holds a copy of the transcript. The published array keeps its identity until an item changes, so ChatView selects it as both data and change signal — and a streaming reply's preview follows the in-place node update instead of the last structural publication. A scroll frame resolves the active mark with one hit test at the reading line, falling back to a single row scan, rather than a DOM query per mark. Flow-height changes resync through the existing column observer, navigating during a pending page keeps the paging anchor, and the rail height no longer holds a floor taller than the band it centers in. --- ...8-25-loaded-turn-chat-navigation.i18n.yaml | 4 +- .../2026-08-25-loaded-turn-chat-navigation.md | 10 ++- ...26-08-25-loaded-turn-chat-navigation.zh.md | 10 ++- apps/web/tests/chat-long-interactions.e2e.ts | 8 +- .../ui-chat/src/client/chat/ChatView.tsx | 70 ++++++++++++---- .../src/client/chat/TurnNavigator.module.css | 6 +- .../ui-chat/src/client/chat/TurnNavigator.tsx | 2 +- .../src/client/chat/turn-navigation.ts | 49 ----------- .../ui-chat/src/client/contract/snapshot.ts | 26 ++++++ .../chat-snapshot-builder.ts | 83 ++++++++++++++++++- .../conversation-nodes/turn-navigation.ts | 71 ++++++++++++++++ packages/client/ui-chat/src/client/index.ts | 9 +- .../tests/chat-snapshot-fixture.client.ts | 14 +++- .../ui-chat/tests/chat-view.client.spec.tsx | 3 +- ...nversation-node-definitions.client.spec.ts | 40 +++++++++ .../tests/tool-details-render.client.tsx | 1 + .../tests/plan-review-panel.client.spec.tsx | 1 + .../user-questions-composer.client.spec.tsx | 1 + 18 files changed, 325 insertions(+), 83 deletions(-) delete mode 100644 packages/client/ui-chat/src/client/chat/turn-navigation.ts create mode 100644 packages/client/ui-chat/src/client/conversation-nodes/turn-navigation.ts diff --git a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.i18n.yaml b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.i18n.yaml index bcc02e9b68..0ba01f1eeb 100644 --- a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.i18n.yaml +++ b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.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-08-25-loaded-turn-chat-navigation.md -2026-08-25-loaded-turn-chat-navigation.md: 92e92323115c5da51ced09092d9ecd4e376f874f -2026-08-25-loaded-turn-chat-navigation.zh.md: b0cba5e78fad8b2ff3559d6cbfc12fb2160a2dc8 +2026-08-25-loaded-turn-chat-navigation.md: 5d9d93b07f7a8c527bf7376bf111c6a709afa4d1 +2026-08-25-loaded-turn-chat-navigation.zh.md: 21dba024710b306848fee9bc4fe1f16913c475b3 diff --git a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md index 92e9232311..5d9d93b07f 100644 --- a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md +++ b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.md @@ -10,13 +10,15 @@ Long Chat transcripts require repeated scrolling to revisit an earlier Turn. Ses ## Decision -ChatView derives one navigation item for every currently loaded Turn that has a visible transcript node. Each item uses the Turn number as its stable React key and the first loaded user node, falling back to the Turn's first loaded node, as its scroll anchor. This is a pure projection of the Chat snapshot: the feature adds no Session event, persisted index, or pagination request. +The Chat snapshot builder accumulates one navigation item for every currently loaded Turn that has a visible transcript node. Each item uses the Turn number as its stable React key and the first loaded user node, falling back to the Turn's first loaded node, as its scroll anchor. This is a pure projection of loaded Chat state: the feature adds no Session event, persisted index, or pagination request. + +Accumulation, not a render-time scan: a structural upsert re-derives the loaded Turn set, a content-only upsert re-derives only the Turns whose nodes changed, and each preview is capped at 160 characters so navigation state never holds a copy of the transcript. The published array keeps its identity until an item changes, so ChatView selects it as both the rail's data and its change signal — the renderer never walks the loaded window, and a streaming reply's preview follows the in-place node update instead of the last structural publication. The rail renders the complete loaded Turn set with a 10px natural interval and never renders an ellipsis or unloaded-history placeholder. Its height shrink-wraps small sets; when the loaded set exceeds the available height, percentage positions compress every mark into the capped rail. When an earlier page arrives, existing Turn keys and DOM elements remain stable while their resolved positions change; CSS transitions animate that redistribution. A Turn split by the page boundary initially previews its Turn number and loaded assistant response, then gains the user prompt when the preceding page supplies it. The rail sits against the scrollport's right edge and centers on the band the sticky composer leaves visible. That band is the scrollport's own height minus the seat's, so ConversationRoot publishes `--dsh-conversation-viewport-height` beside the `--dsh-composer-height` it already measures on the same element, and the rail centers on their difference instead of a viewport height that ignores the Session header. -The active mark follows a reading line near the top of the shared Chat scrollport. Scroll updates are coalesced with `requestAnimationFrame`; reaching the bottom selects the final loaded Turn. Activating a mark computes the target node's position in the existing scroll coordinate system, moves that same scrollport, and records the resulting Chat scroll-restoration anchor. +The active mark follows a reading line near the top of the shared Chat scrollport. A scroll frame resolves the owning Turn with one hit test at that line, falling back to a single row scan where layout cannot answer, so cost does not grow with the number of marks. Flow-height changes that move rows across the line without a scroll event resync through the existing column observer. Scroll updates are coalesced with `requestAnimationFrame`; reaching the bottom selects the final loaded Turn. Activating a mark computes the target node's position in the existing scroll coordinate system, moves that same scrollport, and records the resulting Chat scroll-restoration anchor. Every Turn remains an accessible button even when dense marks visually overlap. The rail maps pointer height to the nearest loaded Turn, while keyboard focus and activation operate the individual buttons. Hover and focus show a compact prompt-and-response preview, the active mark is longer and darker, the rail is hidden when the Chat container is at most 900px wide, and reduced-motion preferences disable redistribution and mark-entry animation. @@ -28,6 +30,8 @@ Every Turn remains an accessible button even when dense marks visually overlap. **Always spread marks across the available height.** Rejected: a small loaded set produces visually unrelated marks separated by large empty regions. A fixed natural interval preserves a compact index while percentage compression still admits dense histories. +**Derive the rail in the renderer from the Chat snapshot.** Rejected: renderers do not scan the loaded Chat Nodes ([client discipline](../../../../packages/client/AGENTS.md)). A render-time projection also re-copied every Turn's prompt and reply text on each structural publication, and could not see the in-place node updates a streaming reply produces, so previews froze at the first chunk. + **Key marks by loaded-array position.** Rejected: prepending a page would reuse each DOM element for a different Turn, lose focus and preview identity, and prevent the existing marks from animating to their new positions. **Call `scrollIntoView` on the Turn row.** Rejected: Chat owns a shared scroller, bottom-follow state, paging anchors, and persisted restoration coordinates. An opaque browser scroll would bypass those state updates. @@ -38,4 +42,4 @@ Desktop-width Chat views can jump among all currently loaded Turns and inspect a ## Testing -Component tests pin Turn derivation, accessible previews, scroll-coordinate jumps, DOM identity, and percentage redistribution after prepend. The long-interaction Chromium scenario pins the real paginated boundary, prompt completion after `Load earlier`, stable-mark movement, keyboard activation, and active-state update. The multi-Turn recorded Web snapshot includes the navigation landmark and buttons. +Builder tests pin the accumulated projection, the bounded preview, and preview freshness under an in-place chunk update. Component tests pin the published items, accessible previews, scroll-coordinate jumps, DOM identity, and percentage redistribution after prepend. The long-interaction Chromium scenario pins the real paginated boundary, prompt completion after `Load earlier`, stable-mark movement, keyboard activation, active-state update, and the narrow-container hide. The multi-Turn recorded Web snapshot includes the navigation landmark and buttons. diff --git a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md index b0cba5e78f..21dba02471 100644 --- a/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md +++ b/.agents/notes/implemented/feature/2026-08-25-loaded-turn-chat-navigation.zh.md @@ -10,13 +10,15 @@ Status: implemented ## 决定 -ChatView 为当前已加载且含可见 transcript node 的每个 Turn 派生一项导航。每项使用 Turn 编号作为稳定的 React key,并以首个已加载用户 node 为滚动锚点;没有用户 node 时回退到该 Turn 的首个已加载 node。这只是 Chat snapshot 的纯投影:本功能不新增 Session event、持久化索引或分页请求。 +Chat snapshot 构建层为当前已加载且含可见 transcript node 的每个 Turn 累积一项导航。每项使用 Turn 编号作为稳定的 React key,并以首个已加载用户 node 为滚动锚点;没有用户 node 时回退到该 Turn 的首个已加载 node。这只是已加载 Chat 状态的纯投影:本功能不新增 Session event、持久化索引或分页请求。 + +累积而非渲染期扫描:结构性 upsert 重算已加载 Turn 集合,仅内容变化的 upsert 只重算受影响 Turn,每条预览截断到 160 字符,导航状态因此不会持有 transcript 副本。发布的数组在条目未变时保持引用不变,ChatView 直接选取它,既作为轨道数据也作为变化信号——渲染层不遍历已加载窗口,流式回复的预览也跟随节点原地更新,而不是停在上一次结构性发布。 导航轨道以 10px 自然间距渲染完整的已加载 Turn 集合,永不显示省略号或未加载历史占位。集合较小时轨道随内容收缩;已加载集合超过可用高度后,百分比位置会把所有刻度压缩到设定上限内。更早一页到达后,已有 Turn 的 key 和 DOM 元素保持不变,最终位置随之变化;CSS transition 为这次重排添加动画。如果一个 Turn 被分页边界截断,预览最初显示其 Turn 编号与已加载的助手回复,上一页补齐后再显示用户问题。 轨道紧贴滚动视口右缘,并在粘性输入区之外的可见区间内垂直居中。该区间等于滚动视口自身高度减去输入区高度,因此 ConversationRoot 在同一元素上除已有的 `--dsh-composer-height` 外再发布 `--dsh-conversation-viewport-height`,轨道按两者之差居中,而不是按忽略 Session 头部的视口高度居中。 -活跃刻度跟随共享 Chat 滚动区顶部附近的阅读线。滚动更新由 `requestAnimationFrame` 合并;到达底部时选择最后一个已加载 Turn。激活刻度会在现有滚动坐标系中计算目标 node 的位置,移动同一个滚动区,并记录由此产生的 Chat 滚动恢复锚点。 +活跃刻度跟随共享 Chat 滚动区顶部附近的阅读线。每个滚动帧用一次命中测试解析该行所属 Turn,布局无法作答时退化为一次行扫描,成本不随刻度数量增长。图片加载、工具卡展开等不产生滚动事件的高度变化,通过既有的 column observer 重新同步。滚动更新由 `requestAnimationFrame` 合并;到达底部时选择最后一个已加载 Turn。激活刻度会在现有滚动坐标系中计算目标 node 的位置,移动同一个滚动区,并记录由此产生的 Chat 滚动恢复锚点。 即使密集刻度在视觉上重叠,每个 Turn 仍是可访问的按钮。轨道把指针高度映射到最近的已加载 Turn,键盘聚焦和激活则作用于各个按钮。悬停或聚焦显示紧凑的问题与回复预览,活跃刻度更长、更深;Chat 容器宽度不超过 900px 时隐藏轨道,用户偏好减少动态效果时关闭重排和刻度入场动画。 @@ -28,6 +30,8 @@ ChatView 为当前已加载且含可见 transcript node 的每个 Turn 派生一 **始终把刻度铺满可用高度。**否决:已加载集合较小时,各刻度会被大片空白隔开,在视觉上失去关联。固定自然间距保持紧凑索引,百分比压缩仍能容纳密集历史。 +**在渲染层从 Chat snapshot 派生轨道。**否决:渲染层不扫描已加载的 Chat Nodes(见 [client 纪律](../../../../packages/client/AGENTS.md))。渲染期投影还会在每次结构性发布时重新复制每个 Turn 的问题与回复文本,且看不到流式回复的节点原地更新,预览会停在首个 chunk。 + **按已加载数组位置给刻度设置 key。**否决:前插一页会让每个 DOM 元素改为代表另一个 Turn,丢失焦点与预览身份,也无法让已有刻度移动到新位置。 **对 Turn 行调用 `scrollIntoView`。**否决:Chat 拥有共享滚动区、底部跟随状态、分页锚点与持久化恢复坐标。浏览器的黑盒滚动会绕过这些状态更新。 @@ -38,4 +42,4 @@ ChatView 为当前已加载且含可见 transcript node 的每个 Turn 派生一 ## 测试 -组件测试固定 Turn 派生、可访问预览、滚动坐标跳转、DOM 身份以及前插后的百分比重排。长交互 Chromium 场景固定真实分页边界、`加载更早` 后补齐问题、稳定刻度移动、键盘激活与活跃状态更新。多 Turn 的 Web 录制快照包含导航 landmark 和按钮。 +构建层测试固定累积投影、预览截断,以及原地 chunk 更新后的预览新鲜度。组件测试固定已发布条目、可访问预览、滚动坐标跳转、DOM 身份以及前插后的百分比重排。长交互 Chromium 场景固定真实分页边界、`加载更早` 后补齐问题、稳定刻度移动、键盘激活、活跃状态更新与窄容器隐藏。多 Turn 的 Web 录制快照包含导航 landmark 和按钮。 diff --git a/apps/web/tests/chat-long-interactions.e2e.ts b/apps/web/tests/chat-long-interactions.e2e.ts index 4525cf8390..da9243a7cd 100644 --- a/apps/web/tests/chat-long-interactions.e2e.ts +++ b/apps/web/tests/chat-long-interactions.e2e.ts @@ -153,7 +153,7 @@ describe('web e2e: long Chat interaction contract', () => { }) await seedSession(scaffold, FIXTURE.log, SESSION_ID) browser = await chromium.launch() - page = await newEnglishPage(browser, 1_280) + page = await newEnglishPage(browser, 900) tripwire = watchConsole(page) await page.goto(scaffold.baseUrl, { waitUntil: 'load' }) await page.waitForSelector('[class*="frame"]', { timeout: 30_000 }) @@ -235,6 +235,12 @@ describe('web e2e: long Chat interaction contract', () => { { timeout: 5_000 }, ).toBe(1) + // Desktop-only affordance: a narrow Chat container hides the rail outright. + await page.setViewportSize({ width: 800, height: 900 }) + await turnNavigation.waitFor({ state: 'hidden', timeout: 5_000 }) + await page.setViewportSize({ width: 1_680, height: 900 }) + await turnNavigation.waitFor({ state: 'visible', timeout: 5_000 }) + await wheelUntilMounted(page, `[data-chat-call-id="${TARGET_CALL_2}"]`, -1_100) const toolUserKey = messageKey(toolUserEvent) const toolAssistantKey = assistantKey(toolAssistantEvent) diff --git a/packages/client/ui-chat/src/client/chat/ChatView.tsx b/packages/client/ui-chat/src/client/chat/ChatView.tsx index a82841bf53..298d417d75 100644 --- a/packages/client/ui-chat/src/client/chat/ChatView.tsx +++ b/packages/client/ui-chat/src/client/chat/ChatView.tsx @@ -7,10 +7,10 @@ import type { } from '@deepseek-ai/dsh-client-ui-conversation/client' import { Button, IconChevronDownOutline14, Modal } from '@deepseek-ai/dsh-client-ui-primitives' import type { ChatViewSlotProps } from '../contract/slots.ts' +import type { TurnNavigationItem } from '../contract/snapshot.ts' import { PendingSteeringBubble } from './MessageItem.tsx' import { ChatNodeSeat } from './ChatNodeSeat.tsx' import { TurnNavigator } from './TurnNavigator.tsx' -import { deriveTurnNavigationItems, type TurnNavigationItem } from './turn-navigation.ts' import { formatRunDuration } from './message-chrome.ts' import css from './ChatView.module.css' @@ -36,6 +36,32 @@ function anchorElement(list: HTMLElement, key: string): HTMLElement | null { return null } +/** + * Turn owning the row at a scrollport line. Scroll frames are hot, so this + * hit-tests the line first and falls back to one row scan when layout cannot + * answer (jsdom, pre-paint); neither path queries per navigation item. + * @param list - the ChatView list element. + * @param line - viewport y of the reading line. + * @returns the Turn number, or null when no loaded row covers the line. + */ +function turnAtLine(list: HTMLElement, line: number): number | null { + const content = list.getBoundingClientRect() + if (typeof document.elementsFromPoint === 'function' && content.width > 0) { + for (const element of document.elementsFromPoint(content.left + content.width / 2, line)) { + const row = element instanceof HTMLElement ? element.closest('[data-chat-turn]') : null + const turn = Number(row?.dataset.chatTurn) + if (row !== null && list.contains(row) && Number.isSafeInteger(turn)) return turn + } + } + let found: number | null = null + for (const row of list.querySelectorAll('[data-chat-turn]')) { + if (row.getBoundingClientRect().top > line) break + const turn = Number(row.dataset.chatTurn) + if (Number.isSafeInteger(turn)) found = turn + } + return found +} + /** Row position in scrollport coordinates (viewport-independent). */ function flowTop(row: HTMLElement, scrollport: HTMLElement): number { return row.getBoundingClientRect().top - scrollport.getBoundingClientRect().top @@ -153,7 +179,10 @@ export function ChatView({ }: ChatViewSlotProps) { const order = useChat(s => s.order) const nodeStore = useChat(s => s.nodes) - const locations = useChat(s => s.locations) + // The rail's items are accumulated in the Chat snapshot, so this selector is + // both the data and its change signal: the array identity moves only when a + // Turn enters, leaves, or changes its preview. + const turnNavigationItems = useChat(s => s.navigation.items()) const timeline = useChat(s => s.timeline) const inbox = useSession(s => s.queue) // Workspace root off the session list row: path summaries display relative to it. @@ -211,10 +240,6 @@ export function ChatView({ [loadImage, renderSlot], ) const runningTurnStart = useMemo(() => runningTurnStartTime(timeline), [timeline]) - const turnNavigationItems = useMemo( - () => deriveTurnNavigationItems({ timeline, locations, nodes: nodeStore }), - [locations, nodeStore, order, timeline], - ) const listRef = useRef(null) const columnRef = useRef(null) @@ -252,13 +277,17 @@ export function ChatView({ return } const el = scrollerOf(local) - const scrollport = el.getBoundingClientRect() - const readingLine = scrollport.top + Math.min(96, el.clientHeight * 0.2) + const readingLine = el.getBoundingClientRect().top + Math.min(96, el.clientHeight * 0.2) + const reading = turnAtLine(local, readingLine) + // No row reaches the line yet: the flow head still owns the mark. Otherwise + // the row's Turn may be one the rail does not offer (all its nodes hidden), + // so the newest offered Turn at or above it owns the mark. let next = first.turn - for (const item of turnNavigationItems) { - const row = anchorElement(local, item.anchorKey) - if (row === null || row.getBoundingClientRect().top > readingLine) break - next = item.turn + if (reading !== null) { + for (const item of turnNavigationItems) { + if (item.turn > reading) break + next = item.turn + } } if (el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_THRESHOLD + 1) { next = turnNavigationItems.at(-1)?.turn ?? next @@ -266,6 +295,7 @@ export function ChatView({ setActiveTurn(current => current === next ? current : next) }, [turnNavigationItems]) + const activeTurnRef = useRef<(() => void) | null>(null) const activeFrameRef = useRef(null) const scheduleActiveTurn = useCallback((): void => { if (activeFrameRef.current !== null) return @@ -285,6 +315,8 @@ export function ChatView({ } }, []) + activeTurnRef.current = scheduleActiveTurn + useLayoutEffect(() => { scheduleActiveTurn() }, [scheduleActiveTurn]) @@ -434,7 +466,12 @@ export function ChatView({ if (column === null || local === null || typeof ResizeObserver === 'undefined') return const scrollport = scrollerOf(local) const composer = scrollport.querySelector('[data-composer-seat]') - const observer = new ResizeObserver(() => { followRef.current?.() }) + // Flow-height changes (image loads, tool disclosures) move rows across the + // reading line without a scroll event, so the active mark resyncs here too. + const observer = new ResizeObserver(() => { + followRef.current?.() + activeTurnRef.current?.() + }) observer.observe(column) if (composer !== null) observer.observe(composer) return () => { observer.disconnect() } @@ -467,10 +504,15 @@ export function ChatView({ if (local === null) return const row = anchorElement(local, item.anchorKey) if (row === null) return - anchorRef.current = null const el = scrollerOf(local) el.scrollTop += flowTop(row, el) - 24 observedTopRef.current = el.scrollTop + // A pending older page still has to compensate the prepended height, so + // navigation moves that anchor to the new position instead of dropping it. + const landed = loadingOlder ? pagingAnchor(local, el) : null + anchorRef.current = landed === null || landed.dataset.chatAnchorKey === undefined + ? null + : { key: landed.dataset.chatAnchorKey, top: flowTop(landed, el) } const isAtBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_THRESHOLD + 1 atBottomRef.current = isAtBottom setAtBottom(isAtBottom) diff --git a/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css b/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css index 8a874897de..76a7b73e9c 100644 --- a/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css +++ b/packages/client/ui-chat/src/client/chat/TurnNavigator.module.css @@ -24,9 +24,13 @@ padding, so the rail gives that inset back and keeps 12px of its own. */ right: calc(12px - (var(--dsh-composer-side-clearance) + 16px)); width: 28px; + /* Never taller than the band it centers in: a short window (a tall composer, + a low viewport) shrinks the rail instead of pushing marks under the + composer or above the scrollport. */ height: min( var(--turn-natural-height), - clamp(120px, calc(var(--turn-rail-band) - 64px), 420px) + max(0px, calc(var(--turn-rail-band) - 64px)), + 420px ); cursor: pointer; pointer-events: auto; diff --git a/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx b/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx index 79029a3e52..b2533e533c 100644 --- a/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx +++ b/packages/client/ui-chat/src/client/chat/TurnNavigator.tsx @@ -2,7 +2,7 @@ import { useId, useState, type CSSProperties, type MouseEvent, type PointerEvent, } from 'react' import type { ChatViewSlotProps } from '../contract/slots.ts' -import type { TurnNavigationItem } from './turn-navigation.ts' +import type { TurnNavigationItem } from '../contract/snapshot.ts' import css from './TurnNavigator.module.css' interface TurnNavigatorProps { diff --git a/packages/client/ui-chat/src/client/chat/turn-navigation.ts b/packages/client/ui-chat/src/client/chat/turn-navigation.ts deleted file mode 100644 index 5ce5305dfd..0000000000 --- a/packages/client/ui-chat/src/client/chat/turn-navigation.ts +++ /dev/null @@ -1,49 +0,0 @@ -import type { ChatNode } from '../contract/chat-nodes.ts' -import type { ChatSnapshot } from '../contract/snapshot.ts' - -/** One loaded Turn projected into the compact Chat navigation rail. */ -export interface TurnNavigationItem { - readonly turn: number - readonly anchorKey: string - readonly prompt: string - readonly response: string -} - -function compactText(parts: readonly string[]): string { - return parts.join(' ').replace(/\s+/g, ' ').trim() -} - -function promptText(node: ChatNode): string { - if (node.kind !== 'user') return '' - return compactText(node.data.content.flatMap(block => block.type === 'text' ? [block.text] : [])) -} - -function responseText(node: ChatNode): string { - if (node.kind !== 'assistant-step') return '' - return compactText(node.data.blocks.flatMap(block => block.kind === 'text' ? [block.text] : [])) -} - -/** - * Project the currently loaded Chat window into stable Turn navigation items. - * @param snapshot - current incremental Chat snapshot. - * @returns loaded Turns that have at least one visible rendered anchor. - */ -export function deriveTurnNavigationItems( - snapshot: Pick, -): readonly TurnNavigationItem[] { - return snapshot.timeline.turnOrder.flatMap((turn): TurnNavigationItem[] => { - const nodes = snapshot.locations.getTurn(turn) - .map(key => snapshot.nodes.get(key)) - .filter((node): node is ChatNode => node !== undefined && node.visibility === 'visible') - const user = nodes.find(node => node.kind === 'user') - const anchor = user ?? nodes[0] - if (anchor === undefined) return [] - const response = nodes.findLast(node => responseText(node) !== '') - return [{ - turn, - anchorKey: anchor.key, - prompt: user === undefined ? '' : promptText(user), - response: response === undefined ? '' : responseText(response), - }] - }) -} diff --git a/packages/client/ui-chat/src/client/contract/snapshot.ts b/packages/client/ui-chat/src/client/contract/snapshot.ts index 35b1562c5b..4a3deb7410 100644 --- a/packages/client/ui-chat/src/client/contract/snapshot.ts +++ b/packages/client/ui-chat/src/client/contract/snapshot.ts @@ -18,6 +18,28 @@ export interface ChatNodeStore { values(): readonly ChatConversationViewNode[] } +/** One loaded Turn projected into the compact Chat navigation rail. */ +export interface TurnNavigationItem { + readonly turn: number + /** Stable Conversation Context key the rail scrolls to. */ + readonly anchorKey: string + /** Bounded prompt preview; empty when the loaded window starts mid-Turn. */ + readonly prompt: string + /** Bounded assistant-response preview; empty until the Turn answers. */ + readonly response: string +} + +/** Stable live navigation projection of the loaded Turns. */ +export interface ChatTurnNavigationIndex { + /** + * Loaded Turns that have a visible anchor, in timeline order. The array + * identity changes exactly when a Turn enters, leaves, or changes preview, + * so a renderer can select it directly as its change signal. + * @returns current navigation items. + */ + items(): readonly TurnNavigationItem[] +} + /** Stable live Location index for Chat nodes. */ export interface ChatLocationNodeIndex { /** @param turn - owning turn. @returns ordered Chat Node keys in the turn. */ @@ -40,6 +62,7 @@ export interface ChatSnapshot { readonly order: readonly string[] readonly nodes: ChatNodeStore readonly locations: ChatLocationNodeIndex + readonly navigation: ChatTurnNavigationIndex readonly timeline: ConversationTimelineSnapshot readonly legacy: LegacyConversationSlice } @@ -64,6 +87,9 @@ export const EMPTY_CHAT_SNAPSHOT: ChatSnapshot = { getTurn: () => EMPTY_LIST, getStep: () => EMPTY_LIST, }, + navigation: { + items: () => EMPTY_LIST, + }, timeline: EMPTY_TIMELINE, legacy: { nodes: EMPTY_LIST, diff --git a/packages/client/ui-chat/src/client/conversation-nodes/chat-snapshot-builder.ts b/packages/client/ui-chat/src/client/conversation-nodes/chat-snapshot-builder.ts index f70e657014..0f8c37d1a1 100644 --- a/packages/client/ui-chat/src/client/conversation-nodes/chat-snapshot-builder.ts +++ b/packages/client/ui-chat/src/client/conversation-nodes/chat-snapshot-builder.ts @@ -6,13 +6,15 @@ import type { import type { ChatConversationViewNode, ChatNode } from '../contract/chat-nodes.ts' import { isRunningTool } from '../contract/chat-nodes.ts' import type { - ChatLocationNodeIndex, ChatNodeStore, ChatSnapshot, ConversationNode, - LegacyConversationSlice, PartialAssistant, RunningToolCall, + ChatLocationNodeIndex, ChatNodeStore, ChatSnapshot, ChatTurnNavigationIndex, ConversationNode, + LegacyConversationSlice, PartialAssistant, RunningToolCall, TurnNavigationItem, } from '../contract/snapshot.ts' import { sessionRecallLabels } from './event-projection.ts' +import { sameTurnNavigationItem, turnNavigationItem } from './turn-navigation.ts' const EMPTY_KEYS: readonly string[] = [] const EMPTY_TURNS: readonly number[] = [] +const EMPTY_ITEMS: readonly TurnNavigationItem[] = [] const EMPTY_LIST: readonly never[] = [] function sameReferences(left: readonly T[], right: readonly T[]): boolean { @@ -125,6 +127,61 @@ function updateIndex( return next } +/** + * Loaded-Turn rail projection accumulated alongside the node store: a + * structural change re-derives the Turn set, a content-only upsert re-derives + * only the Turns whose nodes moved, and the published array keeps its identity + * until an item actually changes. Renderers therefore consume final Turn data + * instead of scanning the loaded window per frame. + */ +class MutableTurnNavigationIndex implements ChatTurnNavigationIndex { + private current: readonly TurnNavigationItem[] = EMPTY_ITEMS + private byTurn = new Map() + + items(): readonly TurnNavigationItem[] { + return this.current + } + + /** Re-derive the whole Turn set; runs only when the loaded structure moves. */ + rebuild( + timeline: ConversationTimelineSnapshot, + locations: ChatLocationNodeIndex, + nodes: ChatNodeStore, + ): void { + const next: TurnNavigationItem[] = [] + const byTurn = new Map() + for (const turn of timeline.turnOrder) { + const derived = turnNavigationItem(turn, locations, nodes) + if (derived === undefined) continue + const previous = this.byTurn.get(turn) + const item = previous !== undefined && sameTurnNavigationItem(previous, derived) ? previous : derived + next.push(item) + byTurn.set(turn, item) + } + this.byTurn = byTurn + const unchanged = next.length === this.current.length + && next.every((item, index) => item === this.current[index]) + if (!unchanged) this.current = next + } + + /** Re-derive only the Turns a content-only upsert touched. */ + touch( + turns: ReadonlySet, + locations: ChatLocationNodeIndex, + nodes: ChatNodeStore, + ): void { + if (turns.size === 0) return + const next = this.current.map((item) => { + if (!turns.has(item.turn)) return item + const derived = turnNavigationItem(item.turn, locations, nodes) + if (derived === undefined || sameTurnNavigationItem(item, derived)) return item + this.byTurn.set(item.turn, derived) + return derived + }) + if (next.some((item, index) => item !== this.current[index])) this.current = next + } +} + function stepKey(turn: number, step: number): string { return `${turn}:${step}` } @@ -479,9 +536,12 @@ function partialContributionChanged( export class ChatSnapshotBuilder implements ConversationViewBuilder { private readonly store = new MutableChatNodeStore() private readonly locations = new MutableChatLocationIndex() + private readonly navigation = new MutableTurnNavigationIndex() private readonly legacy = new LegacySliceBuilder() private readonly referenceLabels = new ReferenceLabelProjector() private order: readonly string[] = EMPTY_KEYS + /** Last published timeline: a Turn boundary can land without a new node. */ + private timeline: ConversationTimelineSnapshot | null = null readonly empty: ChatSnapshot constructor() { @@ -496,6 +556,8 @@ export class ChatSnapshotBuilder implements ConversationViewBuilder node.key) this.locations.rebuild(this.order, this.store) + this.navigation.rebuild(input.timeline, this.locations, this.store) + this.timeline = input.timeline return this.snapshot(input.timeline, this.legacy.replace(nodes, input.timeline)) } @@ -522,6 +584,12 @@ export class ChatSnapshotBuilder implements ConversationViewBuilder { + const turns = new Set() + for (const node of nodes) { + const turn = locationCoordinates(node.location).turn + if (turn !== undefined) turns.add(turn) + } + return turns +} + function locationIdentity(location: ConversationLocation): string { const coordinates = locationCoordinates(location) return `${location.kind}:${coordinates.turn ?? ''}:${coordinates.step ?? ''}` diff --git a/packages/client/ui-chat/src/client/conversation-nodes/turn-navigation.ts b/packages/client/ui-chat/src/client/conversation-nodes/turn-navigation.ts new file mode 100644 index 0000000000..9d54e058c1 --- /dev/null +++ b/packages/client/ui-chat/src/client/conversation-nodes/turn-navigation.ts @@ -0,0 +1,71 @@ +import type { ChatNode } from '../contract/chat-nodes.ts' +import type { ChatLocationNodeIndex, ChatNodeStore, TurnNavigationItem } from '../contract/snapshot.ts' + +/** + * Preview budget per field. The rail clamps two short lines, so anything past + * this is invisible; copying whole transcripts into navigation state would + * otherwise grow with the loaded window on every structural update. + */ +const PREVIEW_LIMIT = 160 + +/** Join rendered text until the preview budget is met, then stop reading. */ +function preview(parts: Iterable): string { + let text = '' + for (const part of parts) { + text += text === '' ? part : ` ${part}` + if (text.length >= PREVIEW_LIMIT) break + } + return text.replace(/\s+/g, ' ').trim().slice(0, PREVIEW_LIMIT) +} + +function promptText(node: ChatNode): string { + if (node.kind !== 'user') return '' + return preview(node.data.content.flatMap(block => block.type === 'text' ? [block.text] : [])) +} + +function responseText(node: ChatNode): string { + if (node.kind !== 'assistant-step') return '' + return preview(node.data.blocks.flatMap(block => block.kind === 'text' ? [block.text] : [])) +} + +/** + * Whether two items carry the same rail state, so the reader can keep its array. + * @param left - previously published item, when the Turn had one. + * @param right - freshly derived item, when the Turn still has one. + * @returns whether both sides describe the same mark. + */ +export function sameTurnNavigationItem( + left: TurnNavigationItem | undefined, + right: TurnNavigationItem | undefined, +): boolean { + if (left === undefined || right === undefined) return left === right + return left.turn === right.turn && left.anchorKey === right.anchorKey + && left.prompt === right.prompt && left.response === right.response +} + +/** + * Project one loaded Turn into its rail item. + * @param turn - Turn number the item addresses. + * @param locations - live Location index supplying the Turn's node keys. + * @param nodes - live Chat node store. + * @returns the item, or undefined when the Turn has no visible loaded node. + */ +export function turnNavigationItem( + turn: number, + locations: ChatLocationNodeIndex, + nodes: ChatNodeStore, +): TurnNavigationItem | undefined { + const loaded = locations.getTurn(turn) + .map(key => nodes.get(key)) + .filter((node): node is ChatNode => node !== undefined && node.visibility === 'visible') + const user = loaded.find(node => node.kind === 'user') + const anchor = user ?? loaded[0] + if (anchor === undefined) return undefined + const response = loaded.findLast(node => responseText(node) !== '') + return { + turn, + anchorKey: anchor.key, + prompt: user === undefined ? '' : promptText(user), + response: response === undefined ? '' : responseText(response), + } +} diff --git a/packages/client/ui-chat/src/client/index.ts b/packages/client/ui-chat/src/client/index.ts index c04c2c588e..60165ddd39 100644 --- a/packages/client/ui-chat/src/client/index.ts +++ b/packages/client/ui-chat/src/client/index.ts @@ -13,10 +13,11 @@ export type {} from './conversation-nodes/turn-tail.ts' export type { AssistantBlock, AssistantMessageNode, AssistantProvenanceView, AssistantRequestConfig, - AssistantTiming, ChatLocationNodeIndex, ChatNodeStore, ChatSnapshot, CommandNode, - CompactionSummaryNode, ContextMessageNode, ConversationNode, LegacyConversationSlice, - ModelRetryNode, PartialAssistant, RunningToolCall, SteeringMessageNode, ToolCallBlock, - ToolResultNode, TurnErrorNode, TurnMaxTokensNode, UnknownSurfaceNode, UserMessageNode, + AssistantTiming, ChatLocationNodeIndex, ChatNodeStore, ChatSnapshot, ChatTurnNavigationIndex, + CommandNode, CompactionSummaryNode, ContextMessageNode, ConversationNode, + LegacyConversationSlice, ModelRetryNode, PartialAssistant, RunningToolCall, + SteeringMessageNode, ToolCallBlock, ToolResultNode, TurnErrorNode, TurnMaxTokensNode, + TurnNavigationItem, UnknownSurfaceNode, UserMessageNode, } from './contract/snapshot.ts' export type { AssistantChatData, ChatConversationViewNode, ChatNode, ChatNodeKind, diff --git a/packages/client/ui-chat/tests/chat-snapshot-fixture.client.ts b/packages/client/ui-chat/tests/chat-snapshot-fixture.client.ts index a6033c4c8c..dce67d27ec 100644 --- a/packages/client/ui-chat/tests/chat-snapshot-fixture.client.ts +++ b/packages/client/ui-chat/tests/chat-snapshot-fixture.client.ts @@ -1,12 +1,15 @@ import type { AssistantMessageNode, ChatConversationViewNode, ChatSnapshot, ConversationNode, ChatLocationNodeIndex, ChatNodeStore, CompactionSummaryNode, LegacyConversationSlice, - PartialAssistant, RunningToolCall, ToolCallBlock, + PartialAssistant, RunningToolCall, ToolCallBlock, TurnNavigationItem, } from '@deepseek-ai/dsh-client-ui-chat/client' import type { ConversationLocationDataStore, ConversationTurnDataMap, TurnLocation, } from '@deepseek-ai/dsh-client-ui-conversation/client' import { deriveTurnMetrics } from '../src/client/contract/turn-metrics.ts' +import { + sameTurnNavigationItem, turnNavigationItem, +} from '../src/client/conversation-nodes/turn-navigation.ts' const EMPTY: readonly never[] = [] @@ -290,10 +293,19 @@ export function chatSnapshotFixture(input: { && previous.legacy.turnEnds === legacy.turnEnds ? previous.timeline : { turnOrder: [...turns.keys()], turns } + const derived = timeline.turnOrder + .map(turn => turnNavigationItem(turn, locations, store)) + .filter((item): item is TurnNavigationItem => item !== undefined) + const kept = previous?.navigation.items() ?? [] + const items = kept.length === derived.length + && derived.every((item, index) => sameTurnNavigationItem(kept[index], item)) + ? kept + : derived return { order, nodes: store, locations, + navigation: { items: () => items }, timeline, legacy, } diff --git a/packages/client/ui-chat/tests/chat-view.client.spec.tsx b/packages/client/ui-chat/tests/chat-view.client.spec.tsx index de703920fc..1f04ad37f5 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -32,7 +32,6 @@ import { } from '../src/client/chat/MessageItem.tsx' import { TurnTailNodeView } from '../src/client/chat/TurnTailNodeView.tsx' import { formatRunDuration } from '../src/client/chat/message-chrome.ts' -import { deriveTurnNavigationItems } from '../src/client/chat/turn-navigation.ts' import { chatSnapshotFixture } from './chat-snapshot-fixture.client.ts' afterEach(() => { @@ -423,7 +422,7 @@ describe('ChatView', () => { ], turnEnds: new Map([[1, 3], [2, 6]]), }) - expect(deriveTurnNavigationItems(snapshot)).toEqual([ + expect(snapshot.navigation.items()).toEqual([ { turn: 1, anchorKey: 'fixture:user:1', prompt: 'first prompt', response: 'first response' }, { turn: 2, anchorKey: 'fixture:user:4', prompt: 'second prompt', response: 'second response' }, ]) diff --git a/packages/client/ui-chat/tests/conversation-node-definitions.client.spec.ts b/packages/client/ui-chat/tests/conversation-node-definitions.client.spec.ts index 88b103ae66..f720f4a8bc 100644 --- a/packages/client/ui-chat/tests/conversation-node-definitions.client.spec.ts +++ b/packages/client/ui-chat/tests/conversation-node-definitions.client.spec.ts @@ -140,6 +140,46 @@ describe('built-in conversation node Definitions', () => { expect(chatViewDefinition.isActive?.(current)).toBe(false) }) + it('keeps the Turn rail projection current when a chunk updates one node in place', () => { + const value = assembler([ + at(1, 'turn/start', { turn: 1 }), + at(2, 'user/message', textMessage('user-1', 'navigate here'), { surfaceOp: 'append' }), + at(3, 'step/start', { turn: 1, step: 1 }), + at(4, 'assistant/chunk', { + turn: 1, + step: 1, + chunk: { type: 'text-delta', index: 0, text: 'first' }, + }), + ]) + const opening = snapshot(value).navigation.items() + expect(opening).toHaveLength(1) + expect(opening[0]?.turn).toBe(1) + expect(opening[0]?.prompt).toBe('navigate here') + expect(opening[0]?.response).toBe('first') + + // Content-only upsert: the node keeps its key, so the rail's preview has to + // follow the in-place update rather than the last structural publication. + value.append(at(5, 'assistant/chunk', { + turn: 1, + step: 1, + chunk: { type: 'text-delta', index: 0, text: ' and more' }, + })) + value.flush() + const streamed = snapshot(value).navigation.items() + expect(streamed[0]?.response).toBe('first and more') + expect(streamed).not.toBe(opening) + }) + + it('bounds each rail preview instead of copying the whole transcript', () => { + const long = 'x'.repeat(400) + const value = assembler([ + at(1, 'turn/start', { turn: 1 }), + at(2, 'user/message', textMessage('user-1', long), { surfaceOp: 'append' }), + ]) + const items = snapshot(value).navigation.items() + expect(items[0]?.prompt.length).toBe(160) + }) + it('keeps one keyed Assistant node while streaming settles and materializes interruption from Location', () => { const value = assembler([ at(1, 'turn/start', { turn: 1 }), diff --git a/packages/client/ui-tool/tests/tool-details-render.client.tsx b/packages/client/ui-tool/tests/tool-details-render.client.tsx index b915b39de9..7021928ee3 100644 --- a/packages/client/ui-tool/tests/tool-details-render.client.tsx +++ b/packages/client/ui-tool/tests/tool-details-render.client.tsx @@ -56,6 +56,7 @@ export function toolChatSnapshot( getTurn: () => empty, getStep: () => empty, }, + navigation: { items: () => [] }, timeline: { turnOrder: [], turns: new Map() }, legacy: { nodes: settled, diff --git a/packages/client/ui-user-questions/tests/plan-review-panel.client.spec.tsx b/packages/client/ui-user-questions/tests/plan-review-panel.client.spec.tsx index 4faba04c00..faff18b4da 100644 --- a/packages/client/ui-user-questions/tests/plan-review-panel.client.spec.tsx +++ b/packages/client/ui-user-questions/tests/plan-review-panel.client.spec.tsx @@ -66,6 +66,7 @@ const chatState: ChatState = { order: emptyKeys, nodes: { get: () => undefined, values: () => [] }, locations: { getTurn: () => emptyKeys, getStep: () => emptyKeys }, + navigation: { items: () => [] }, timeline: { turnOrder: [], turns: new Map() }, legacy: { nodes: [], diff --git a/packages/client/ui-user-questions/tests/user-questions-composer.client.spec.tsx b/packages/client/ui-user-questions/tests/user-questions-composer.client.spec.tsx index a650dd6a5b..e6cf481fcc 100644 --- a/packages/client/ui-user-questions/tests/user-questions-composer.client.spec.tsx +++ b/packages/client/ui-user-questions/tests/user-questions-composer.client.spec.tsx @@ -64,6 +64,7 @@ const chatState: ChatState = { order: emptyKeys, nodes: { get: () => undefined, values: () => [] }, locations: { getTurn: () => emptyKeys, getStep: () => emptyKeys }, + navigation: { items: () => [] }, timeline: { turnOrder: [], turns: new Map() }, legacy: { nodes: [], From 87ac9f5beae1ee596310b9646cca996bbcecd7d6 Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Wed, 26 Aug 2026 10:21:49 +0800 Subject: [PATCH 04/13] fix(notices): restore the SDK version the lockfile installs The generator names the first matching virtual-store directory, so a local store still holding an older SDK payload alongside the locked one renders that older version into the notices. --- THIRD_PARTY_NOTICES.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index e079fa8c57..03c01e88af 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -113,18 +113,18 @@ pnpm applies local patches to the following packages at install time, so shipped The project owner authorizes distribution of every version of the official `@anthropic-ai/claude-agent-sdk` package and the official Claude Code CLI/platform payloads that each version declares through `optionalDependencies`. This identity-scoped authorization does not classify their declared terms as permissive and does not cover any unrelated runtime package; version, declared-license, and payload-set changes still require the ordinary dependency, lockfile, compatibility, terms, and notices review. -The installed SDK 0.3.220 declares the following optional platform packages. Each carries the official Claude Code 2.1.220 executable; the package identities and versions come from the SDK manifest, while the declared license field is verified against the platform payload installed for the current host. +The installed SDK 0.3.241 declares the following optional platform packages. Each carries the official Claude Code 2.1.241 executable; the package identities and versions come from the SDK manifest, while the declared license field is verified against the platform payload installed for the current host. | Optional platform package | Version | Declared license | | --- | --- | --- | -| [`@anthropic-ai/claude-agent-sdk-darwin-arm64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-darwin-arm64) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-darwin-x64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-darwin-x64) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-linux-arm64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-arm64) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-linux-arm64-musl`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-arm64-musl) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-linux-x64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-x64) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-linux-x64-musl`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-x64-musl) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-win32-arm64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-win32-arm64) | 0.3.220 | SEE LICENSE IN LICENSE.md | -| [`@anthropic-ai/claude-agent-sdk-win32-x64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-win32-x64) | 0.3.220 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-darwin-arm64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-darwin-arm64) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-darwin-x64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-darwin-x64) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-linux-arm64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-arm64) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-linux-arm64-musl`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-arm64-musl) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-linux-x64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-x64) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-linux-x64-musl`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-linux-x64-musl) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-win32-arm64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-win32-arm64) | 0.3.241 | SEE LICENSE IN LICENSE.md | +| [`@anthropic-ai/claude-agent-sdk-win32-x64`](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk-win32-x64) | 0.3.241 | SEE LICENSE IN LICENSE.md | ## Development-only npm dependencies From 806642b064251640e14bb8aebd47ce49e9e736a2 Mon Sep 17 00:00:00 2001 From: Dudu-0223 Date: Fri, 14 Aug 2026 13:10:19 +0800 Subject: [PATCH 05/13] feat(team): add experimental Agent Teams Web profile --- ...08-18-experimental-agent-teams-packages.md | 4 +- ...18-experimental-agent-teams-packages.zh.md | 4 +- .../2026-08-06-agent-teams-web.i18n.yaml | 6 + .../feature/2026-08-06-agent-teams-web.md | 39 ++ .../feature/2026-08-06-agent-teams-web.zh.md | 39 ++ apps/web/tests/agent-team-panel.e2e.ts | 89 +++ apps/web/tests/agent-team-panel.overlay.yml | 44 ++ apps/web/tests/scaffold.ts | 38 +- .../agent-team-panel/task.expected.md | 29 + apps/web/tsconfig.json | 1 + docs/subsystems/agent-team.md | 23 + docs/subsystems/agent-team.zh.md | 23 + knip.json | 11 + packages/experimental/README.md | 3 + packages/experimental/README.zh.md | 3 + .../agent-team-remotes/README.i18n.yaml | 6 + .../experimental/agent-team-remotes/README.md | 22 + .../agent-team-remotes/README.zh.md | 22 + .../agent-team-remotes/package.json | 62 ++ .../agent-team-remotes/src/client/index.ts | 19 + .../agent-team-remotes/src/index.ts | 4 + .../agent-team-remotes/src/invariant.ts | 23 + .../agent-team-remotes/tests/built-lib.e2e.ts | 95 +++ .../tests/invariant.spec.ts | 16 + .../agent-team-remotes/tsconfig.client.json | 20 + .../agent-team-remotes/tsconfig.host.json | 17 + .../agent-team-remotes/tsconfig.json | 11 + .../agent-team-remotes/tsdown.config.ts | 3 + .../agent-team-web-profile/README.i18n.yaml | 6 + .../agent-team-web-profile/README.md | 27 + .../agent-team-web-profile/README.zh.md | 27 + .../agent-team-web-profile/cordis.patch.yml | 9 + .../agent-team-web-profile/package.json | 53 ++ .../agent-team-web-profile/src/index.ts | 3 + .../agent-team-web-profile/src/invariant.ts | 23 + .../tests/profile.spec.ts | 36 ++ .../agent-team-web-profile/tsconfig.json | 12 + packages/experimental/agent-team/README.md | 5 + packages/experimental/agent-team/README.zh.md | 5 + packages/experimental/agent-team/package.json | 21 +- .../experimental/agent-team/src/client.ts | 3 + packages/experimental/agent-team/src/index.ts | 53 +- packages/experimental/agent-team/src/types.ts | 17 + .../agent-team/tests/team.spec.ts | 35 ++ .../experimental/agent-team/tsconfig.json | 1 + .../client-ui-agent-team/README.i18n.yaml | 6 + .../client-ui-agent-team/README.md | 25 + .../client-ui-agent-team/README.zh.md | 25 + .../client-ui-agent-team/package.json | 86 +++ .../src/client/TeamAction.module.css | 239 ++++++++ .../src/client/TeamAction.tsx | 433 ++++++++++++++ .../client-ui-agent-team/src/client/index.ts | 96 +++ .../src/client/locales.ts | 72 +++ .../client-ui-agent-team/src/css-modules.d.ts | 6 + .../client-ui-agent-team/src/index.ts | 4 + .../client-ui-agent-team/src/invariant.ts | 18 + .../tests/browser-plugin.client.spec.ts | 264 +++++++++ .../tests/team-action.client.spec.tsx | 549 ++++++++++++++++++ .../client-ui-agent-team/tsconfig.json | 21 + .../client-ui-agent-team/tsdown.config.ts | 3 + scripts/gen-cordis-catalog.ts | 2 + scripts/run-gates.spec.ts | 1 + scripts/run-gates.ts | 1 + .../verify-package-readme-model-experience.ts | 3 + tsconfig.base.json | 2 + tsconfig.client.json | 2 + tsconfig.host.json | 3 + vitest.config.ts | 2 + 68 files changed, 2864 insertions(+), 11 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-08-06-agent-teams-web.i18n.yaml create mode 100644 .agents/notes/implemented/feature/2026-08-06-agent-teams-web.md create mode 100644 .agents/notes/implemented/feature/2026-08-06-agent-teams-web.zh.md create mode 100644 apps/web/tests/agent-team-panel.e2e.ts create mode 100644 apps/web/tests/agent-team-panel.overlay.yml create mode 100644 apps/web/tests/snapshots/agent-team-panel/task.expected.md create mode 100644 packages/experimental/agent-team-remotes/README.i18n.yaml create mode 100644 packages/experimental/agent-team-remotes/README.md create mode 100644 packages/experimental/agent-team-remotes/README.zh.md create mode 100644 packages/experimental/agent-team-remotes/package.json create mode 100644 packages/experimental/agent-team-remotes/src/client/index.ts create mode 100644 packages/experimental/agent-team-remotes/src/index.ts create mode 100644 packages/experimental/agent-team-remotes/src/invariant.ts create mode 100644 packages/experimental/agent-team-remotes/tests/built-lib.e2e.ts create mode 100644 packages/experimental/agent-team-remotes/tests/invariant.spec.ts create mode 100644 packages/experimental/agent-team-remotes/tsconfig.client.json create mode 100644 packages/experimental/agent-team-remotes/tsconfig.host.json create mode 100644 packages/experimental/agent-team-remotes/tsconfig.json create mode 100644 packages/experimental/agent-team-remotes/tsdown.config.ts create mode 100644 packages/experimental/agent-team-web-profile/README.i18n.yaml create mode 100644 packages/experimental/agent-team-web-profile/README.md create mode 100644 packages/experimental/agent-team-web-profile/README.zh.md create mode 100644 packages/experimental/agent-team-web-profile/cordis.patch.yml create mode 100644 packages/experimental/agent-team-web-profile/package.json create mode 100644 packages/experimental/agent-team-web-profile/src/index.ts create mode 100644 packages/experimental/agent-team-web-profile/src/invariant.ts create mode 100644 packages/experimental/agent-team-web-profile/tests/profile.spec.ts create mode 100644 packages/experimental/agent-team-web-profile/tsconfig.json create mode 100644 packages/experimental/agent-team/src/client.ts create mode 100644 packages/experimental/client-ui-agent-team/README.i18n.yaml create mode 100644 packages/experimental/client-ui-agent-team/README.md create mode 100644 packages/experimental/client-ui-agent-team/README.zh.md create mode 100644 packages/experimental/client-ui-agent-team/package.json create mode 100644 packages/experimental/client-ui-agent-team/src/client/TeamAction.module.css create mode 100644 packages/experimental/client-ui-agent-team/src/client/TeamAction.tsx create mode 100644 packages/experimental/client-ui-agent-team/src/client/index.ts create mode 100644 packages/experimental/client-ui-agent-team/src/client/locales.ts create mode 100644 packages/experimental/client-ui-agent-team/src/css-modules.d.ts create mode 100644 packages/experimental/client-ui-agent-team/src/index.ts create mode 100644 packages/experimental/client-ui-agent-team/src/invariant.ts create mode 100644 packages/experimental/client-ui-agent-team/tests/browser-plugin.client.spec.ts create mode 100644 packages/experimental/client-ui-agent-team/tests/team-action.client.spec.tsx create mode 100644 packages/experimental/client-ui-agent-team/tsconfig.json create mode 100644 packages/experimental/client-ui-agent-team/tsdown.config.ts diff --git a/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.md b/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.md index 495922d57b..144484deee 100644 --- a/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.md +++ b/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.md @@ -12,13 +12,13 @@ An experimental directory without a current package previously imposed placement ## Decision -`packages/experimental/agent-team`, `packages/experimental/tool-agent-team`, and `packages/experimental/agent-team-profile` are private workspace packages. The [experimental package naming decision](2026-08-19-experimental-package-name-prefix.md) owns their npm names and promotion rename; this note owns their placement, release exclusion, and dependency isolation. +`packages/experimental/agent-team`, `packages/experimental/tool-agent-team`, `packages/experimental/agent-team-profile`, `packages/experimental/agent-team-remotes`, `packages/experimental/client-ui-agent-team`, and `packages/experimental/agent-team-web-profile` are private workspace packages. The [experimental package naming decision](2026-08-19-experimental-package-name-prefix.md) owns their npm names and promotion rename; this note owns their placement, release exclusion, and dependency isolation. The dsh pack and publish set and the local baseline publisher exclude every manifest below `packages/experimental/`. `release:dsh` still advances their manifest versions with the shared dsh version without creating release tags. Workspace constraints require each experimental package to set `private: true` and omit `publishConfig`. The same top-level check rejects `dependencies`, `optionalDependencies`, and `peerDependencies` from release packages, release apps, or the Python runtime to an experimental package. Experimental packages may depend on release packages and each other; tests may use them through `devDependencies`, and examples may load them explicitly. The generic caller-reserved continuable child identity and selective direct-child drain remain in the stable Subagent service. They own Subagent identity and Activation lifecycle without importing or naming Agent Teams; the experimental Team service consumes them in the permitted direction. -The private Agent Teams profile bundle depends on the Team packages and applies after `dsh-base`. It inserts the Team rows, disables the global continuable-child controls whose model-visible names overlap the Team tools, and leaves the shipped base, CLI, Web, and Python runtime dependency graphs unchanged. +The private Host-side Agent Teams profile bundle depends on the Team packages and applies after `dsh-base`. It inserts the Team rows and disables the global continuable-child controls whose model-visible names overlap the Team tools. The separate private Web profile applies after `dsh-web-app` and the Host profile; it inserts a Team-only Client Remote assembly and the Team UI. Both layers leave the shipped base, CLI, Web, and Python runtime dependency graphs unchanged. Profile startup resolves selected bundles before healing module fallbacks. The shared fallback retains the dsh installation's carrier-specific entries: symlinks under plain Node and ESM proxies in a packaged executable. Missing packages from selected bundle closures are linked under the current profile's own `node_modules`, while pnpm-managed profile entries remain authoritative. Closure discovery starts from each explicit external bundle's real package directory and traverses every listed root even when an earlier dependency has the same package name. It excludes dsh-owned profile projections from later discovery, so a projected dependency cannot feed back into its own closure. Link ownership compares canonical parent paths so junction-normalized targets remain removable. A private profile layer can therefore carry experimental plugin rows without adding those plugins to a release app, requiring profile users to install transitive packages directly, weakening packaged-runtime module identity, or changing another profile's resolution. diff --git a/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.zh.md b/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.zh.md index 65aed57e22..01e9e94319 100644 --- a/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.zh.md +++ b/.agents/notes/implemented/architecture/2026-08-18-experimental-agent-teams-packages.zh.md @@ -12,13 +12,13 @@ Agent Teams 的服务与工具约定仍在变化,但它需要使用真实 Sess ## 决策 -`packages/experimental/agent-team`、`packages/experimental/tool-agent-team` 与 `packages/experimental/agent-team-profile` 是私有 workspace 包。[实验性包命名决策](2026-08-19-experimental-package-name-prefix.zh.md)负责其 npm 名和 promotion 重命名;本记录负责其目录归属、发布排除与依赖隔离。 +`packages/experimental/agent-team`、`packages/experimental/tool-agent-team`、`packages/experimental/agent-team-profile`、`packages/experimental/agent-team-remotes`、`packages/experimental/client-ui-agent-team` 与 `packages/experimental/agent-team-web-profile` 是私有 workspace 包。[实验性包命名决策](2026-08-19-experimental-package-name-prefix.zh.md)负责其 npm 名和 promotion 重命名;本记录负责其目录归属、发布排除与依赖隔离。 dsh pack 与 publish 集合以及本地 baseline 发布器均排除 `packages/experimental/` 下的所有 manifest。`release:dsh` 仍会让这些 manifest 跟随 dsh 共享版本递增,但不会创建发布 tag。workspace 约束要求每个实验性包设置 `private: true` 并省略 `publishConfig`。同一个顶层检查会拒绝发布包、发布 app 或 Python runtime 通过 `dependencies`、`optionalDependencies` 或 `peerDependencies` 依赖实验性包。实验性包可以依赖发布包和其他实验性包;测试可以通过 `devDependencies` 使用它们,示例可以显式加载它们。 通用的调用方预留 continuable child 身份和精确 direct-child drain 仍属于稳定 Subagent 服务。它们负责 Subagent 身份与 Activation 生命周期,不 import 或命名 Agent Teams;实验性 Team 服务沿允许的方向消费这些能力。 -私有 Agent Teams profile bundle 依赖 Team 包,并应用在 `dsh-base` 之后。它插入 Team 配置行,禁用模型可见名称与 Team 工具重叠的全局 continuable-child control,并保持已发布 base、CLI、Web 与 Python runtime 的依赖图不变。 +私有 Host 侧 Agent Teams profile bundle 依赖 Team 包,并在 `dsh-base` 之后应用。它会插入 Team 配置行,并禁用模型可见名称与 Team 工具重叠的全局 continuable-child control。独立的私有 Web profile 在 `dsh-web-app` 与 Host profile 之后应用;它会插入 Team 专用 Client Remote assembly 与 Team UI。两个层都保持已发布 base、CLI、Web 与 Python runtime 的依赖图不变。 profile 启动会先解析所选 bundle,再修复模块 fallback。共享 fallback 保留 dsh 安装的载体专用条目:普通 Node 下使用 symlink,打包 executable 中使用 ESM proxy。仅由所选 bundle 闭包携带的缺失包会链接到当前 profile 自己的 `node_modules` 下,而 pnpm 管理的 profile 条目仍具有优先权。闭包发现从每个显式外部 bundle 的真实包目录开始;即使前一个依赖具有相同包名,也会遍历所有列出的根。后续发现会排除 dsh 所有的 profile projection,避免投影后的依赖重新进入自己的闭包。link ownership 通过规范化父路径比较,使 junction 规范化后的 target 仍可删除。因此,私有 profile 层可以携带实验性 plugin 配置行,而无需把这些 plugin 加入发布 app、要求 profile 用户直接安装传递依赖、破坏 packaged-runtime 的模块身份,或改变其他 profile 的解析结果。 diff --git a/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.i18n.yaml b/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.i18n.yaml new file mode 100644 index 0000000000..8a70534909 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.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-08-06-agent-teams-web.md +2026-08-06-agent-teams-web.md: a8842bb647ca469fffcffe7f1d91eff42b6a403c +2026-08-06-agent-teams-web.zh.md: 55e8a65711fefe1ae2b9fcca6e0adb4d0358ecf6 diff --git a/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.md b/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.md new file mode 100644 index 0000000000..a8842bb647 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.md @@ -0,0 +1,39 @@ +# Agent Note: Experimental Agent Teams Web controls + +Status: implemented + +English | [中文](2026-08-06-agent-teams-web.zh.md) + +## Problem + +The durable Agent Teams runtime owns roster, mailbox, and task state but exposes only model tools and Host service methods. Web users need to inspect teammate activity, manage shared tasks with the same compare-and-set rules, and open a teammate conversation. Agent Teams is still experimental, so these capabilities must not add Team-specific contracts or dependencies to the stable API Proxy, Client runtime, Subagent UI, or Web bundle. + +## Decision + +`TeamService` directly contributes three Typert Remote methods: `teams/view`, `teams/createTask`, and `teams/updateTask`. The generated codecs use a browser-safe `@deepseek-ai/dsh-team/client` vocabulary. Views contain roster and current task state but omit pending mailbox content and deleted task tombstones. Task conflicts cross Remote as a closed business result so the browser can preserve `team-task-conflict`; transport and lookup failures remain ordinary `RemoteResult` failures. + +`@deepseek-ai/dsh-agent-team-remotes` is a private Client assembly that mounts the generated Team contribution through the stable `ctx.remote` service. `@deepseek-ai/dsh-client-ui-agent-team` consumes only `ctx.remote.teams`, Client Session navigation, locale, and slots. It displays roster status, model and diagnostics and supports task create, edit, dependency update, assignment, completion, reopen, and deletion. Every mutation sends the displayed revision. A conflict reloads the complete Team view and asks the user to review instead of retrying or overwriting automatically. Overlapping refreshes publish only the latest request for the selected Session, and a successful mutation invalidates older refresh snapshots. + +Teammate navigation uses the existing `{ parentSessionId, childSessionId, mode: 'continuable' }` Subagent address without a Team tag. The UI refreshes the direct-child catalog, rechecks the selected Session, and opens the addressed conversation. History and later human prompts follow the stable Subagent path; the Team mailbox remains reserved for Team peer delivery from Team tools. + +`@deepseek-ai/dsh-agent-team-web-profile` inserts the private Remote assembly and UI after the stable Web bundle. It is applied alongside the Host-side `@deepseek-ai/dsh-agent-team-profile`. Neither stable bundle contains disabled Team rows or dependencies. + +## Boundaries + +The Web UI has no mailbox timeline, worktree or Git controls, teammate creation, rename, deletion, interruption, or automatic merge behavior. It does not infer filesystem authority from task ownership or write scopes. A human continuation after teammate navigation is an ordinary addressed-child prompt, not a Team mailbox message. + +## Alternatives considered + +**Extend the legacy API Proxy Team RPC map.** Rejected because it would put an experimental domain in a stable wire package and duplicate the generated Remote vocabulary and validation. + +**Add Team metadata to the stable Subagent address and prompt routing.** Rejected because ordinary child navigation already identifies the conversation. A Team tag would couple stable Client and Subagent contracts to experimental mailbox policy. + +**Put disabled Team rows in the stable Web bundle.** Rejected because a disabled row still creates release dependencies and makes the experimental package part of shipped composition. + +## Testing + +Team Remote generation and Host build verify the typed methods. Client typechecking and browser component tests cover the mounted namespace, Lead routing, every task action, conflict reload, stale async results, navigation, disposal, and status or error presentation. A Web end-to-end test composes both experimental profile layers over the real Host Remote flow. + +## Consequences + +The Team service remains the only state machine, while Web is a typed projection and command adapter. The stable API Proxy, Client runtime, Subagent UI, and Web bundle remain Team-agnostic. Source-checkout users must add two ordered experimental profile layers to a Web profile, and promotion can move those packages without changing their npm names or generated namespace. diff --git a/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.zh.md b/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.zh.md new file mode 100644 index 0000000000..55e8a65711 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-08-06-agent-teams-web.zh.md @@ -0,0 +1,39 @@ +# Agent Note:实验性 Agent Teams Web 控件 + +状态:已实现 + +[English](2026-08-06-agent-teams-web.md) | 中文 + +## 问题 + +持久 Agent Teams runtime 负责 roster、mailbox 与 task 状态,但只提供模型工具和 Host service method。Web 用户需要查看 teammate 活动、按同样的 compare-and-set 规则管理共享任务,并打开 teammate 会话。Agent Teams 仍处于实验阶段,因此这些能力不能向稳定 API Proxy、Client runtime、Subagent UI 或 Web bundle 增加 Team 专用 contract 或依赖。 + +## 决策 + +`TeamService` 直接提供三个 Typert Remote method:`teams/view`、`teams/createTask` 与 `teams/updateTask`。生成式 codec 使用浏览器安全的 `@deepseek-ai/dsh-team/client` vocabulary。View 包含 roster 与当前 task 状态,但不包含 pending mailbox 内容或已删除 task tombstone。Task conflict 通过封闭 business result 跨越 Remote,使浏览器保留 `team-task-conflict`;transport 与 lookup failure 仍是普通 `RemoteResult` failure。 + +`@deepseek-ai/dsh-agent-team-remotes` 是私有 Client assembly,通过稳定 `ctx.remote` service 挂载生成式 Team contribution。`@deepseek-ai/dsh-client-ui-agent-team` 只消费 `ctx.remote.teams`、Client Session navigation、locale 与 slot。它展示 roster status、model 与 diagnostics,并支持 task create、edit、dependency update、assignment、completion、reopen 与 deletion。每次 mutation 都发送当前显示的 revision。Conflict 会重新读取完整 Team view 并要求用户检查,不会自动重试或覆盖。重叠 refresh 只发布所选 Session 的最新请求,成功 mutation 会让更早的 refresh snapshot 失效。 + +Teammate navigation 使用既有 `{ parentSessionId, childSessionId, mode: 'continuable' }` Subagent address,不带 Team tag。UI 刷新直接 child catalog、再次检查所选 Session,然后打开 addressed conversation。History 与后续人类 prompt 使用稳定 Subagent 路径;Team mailbox 只用于 Team 工具发起的 Team peer delivery。 + +`@deepseek-ai/dsh-agent-team-web-profile` 在稳定 Web bundle 之后插入私有 Remote assembly 与 UI。它与 Host 侧 `@deepseek-ai/dsh-agent-team-profile` 一起应用。两个稳定 bundle 都不包含禁用的 Team row 或依赖。 + +## 边界 + +Web UI 不提供 mailbox timeline、worktree 或 Git control、teammate creation、rename、deletion、interrupt 或自动 merge。它不会从 task ownership 或 write scope 推断文件系统权限。导航到 teammate 后的人类 continuation 是普通 addressed-child prompt,不是 Team mailbox message。 + +## 考虑过的替代方案 + +**扩展 legacy API Proxy Team RPC map。** 拒绝,因为这会把实验性 domain 放入稳定 wire package,并重复生成式 Remote vocabulary 与 validation。 + +**向稳定 Subagent address 与 prompt routing 添加 Team metadata。** 拒绝,因为普通 child navigation 已经标识会话;Team tag 会让稳定 Client 与 Subagent contract 耦合实验性 mailbox policy。 + +**在稳定 Web bundle 中加入禁用 Team row。** 拒绝,因为禁用 row 仍会产生 release 依赖,并让实验性 package 成为随附 composition 的一部分。 + +## 测试 + +Team Remote 生成与 Host build 校验 typed method。Client typecheck 与浏览器 component test 覆盖挂载 namespace、Lead routing、所有 task action、conflict reload、陈旧 async result、navigation、dispose 与状态或错误呈现。Web 端到端测试在真实 Host Remote flow 上组合两个实验性 profile 层。 + +## 后果 + +Team service 仍是唯一状态机,Web 是 typed projection 与 command adapter。稳定 API Proxy、Client runtime、Subagent UI 和 Web bundle 保持 Team 无关。源码 checkout 用户必须向 Web profile 添加两个有序 experimental profile 层;promotion 可以移动这些 package,而无需修改 npm name 或生成式 namespace。 diff --git a/apps/web/tests/agent-team-panel.e2e.ts b/apps/web/tests/agent-team-panel.e2e.ts new file mode 100644 index 0000000000..e36e921021 --- /dev/null +++ b/apps/web/tests/agent-team-panel.e2e.ts @@ -0,0 +1,89 @@ +// Keyless assembled-browser coverage for the private Agent Teams Web profiles +// over the real Host Typert Remote flow. +import { fileURLToPath } from 'node:url' +import { join } from 'node:path' +import type { Browser, Page } from 'playwright' +import { chromium } from 'playwright' +import { afterAll, beforeAll, describe, expect, it, onTestFailed } from 'vitest' +import { createMessage, createUserMessage } from '@deepseek-ai/dsh-llm' +import { + assertFixtureInventory, captureStableAria, compareOrRefreshGolden, + launchWebScaffold, watchConsole, webSnapshotMode, type WebScaffold, +} from './scaffold.ts' +import { connectFreshWorkspace, newEnglishPage, saveFailureShot } from './support.ts' + +const SNAPSHOT_DIR = fileURLToPath(new URL('./snapshots/agent-team-panel', import.meta.url)) +const PANEL_EXPECTED = join(SNAPSHOT_DIR, 'task.expected.md') +const OVERLAY = fileURLToPath(new URL('./agent-team-panel.overlay.yml', import.meta.url)) +const INSTALL_ANCHORS = [ + fileURLToPath(new URL('../../../packages/experimental/agent-team-profile/package.json', import.meta.url)), + fileURLToPath(new URL('../../../packages/experimental/agent-team-web-profile/package.json', import.meta.url)), +] +const MODE = webSnapshotMode() + +describe('web e2e: Agent Teams panel', () => { + let scaffold: WebScaffold + let browser: Browser + let page: Page + let tripwire: ReturnType + + beforeAll(async () => { + scaffold = await launchWebScaffold({ extraOverlayPath: OVERLAY, extraInstallAnchors: INSTALL_ANCHORS }) + browser = await chromium.launch() + page = await newEnglishPage(browser) + tripwire = watchConsole(page) + await page.goto(scaffold.baseUrl, { waitUntil: 'load' }) + await page.waitForSelector('[class*="frame"]', { timeout: 30_000 }) + await connectFreshWorkspace(page, scaffold.workspaceCwd) + const agent = scaffold.ctx.agents.list()[0] + if (agent === undefined) throw new Error('connected Team workspace did not create an Agent') + agent.session.append('turn/start', { turn: 1 }) + agent.session.append('user/message', createUserMessage({ + content: [{ type: 'text', text: 'Open the Agent Team controls.' }], + source: { kind: 'user' }, + }), { surfaceOp: 'append' }) + agent.session.append('step/start', { turn: 1, step: 1 }) + agent.session.append('assistant/message', { + turn: 1, + step: 1, + message: createMessage({ + role: 'assistant', + content: [{ type: 'text', text: 'Ready.' }], + source: { kind: 'model', provider: 'fixture', model: 'fixture' }, + }), + }, { surfaceOp: 'append' }) + agent.session.append('step/end', { turn: 1, step: 1 }) + agent.session.append('turn/end', { turn: 1, reason: { kind: 'completed' } }) + await scaffold.ctx.sessions.flush(agent.session) + await page.getByText('Ready.').waitFor({ timeout: 10_000 }) + }, 120_000) + + afterAll(async () => { + await browser?.close() + await scaffold?.close() + }) + + it('loads the roster and creates one shared task through generated Remote', async () => { + onTestFailed(() => saveFailureShot(page, 'web-e2e-agent-team-panel')) + const action = page.locator('[data-team-action]') + await action.getByRole('button', { name: /Agent Team/iu }).click() + await action.getByText('No shared tasks yet').waitFor() + await action.getByText('lead').waitFor() + + await action.getByRole('button', { name: 'New task' }).click() + await action.getByPlaceholder('Task subject').fill('Browser task') + await action.getByPlaceholder('Task description').fill('Created through the assembled browser') + await action.getByPlaceholder(/Write scopes/iu).fill('src/web') + await action.getByRole('button', { name: 'Save' }).click() + await action.getByText('Browser task').waitFor() + + const snapshot = await captureStableAria(page, '[data-team-action]', scaffold.workspaceCwd) + await compareOrRefreshGolden(PANEL_EXPECTED, snapshot, MODE) + expect(tripwire.pageErrors).toEqual([]) + expect(tripwire.warnings).toEqual([]) + }, 60_000) + + it.skipIf(MODE === 'record')('keeps the fixture inventory closed', async () => { + await assertFixtureInventory(SNAPSHOT_DIR, ['task.expected.md']) + }) +}) diff --git a/apps/web/tests/agent-team-panel.overlay.yml b/apps/web/tests/agent-team-panel.overlay.yml new file mode 100644 index 0000000000..73c7b949c5 --- /dev/null +++ b/apps/web/tests/agent-team-panel.overlay.yml @@ -0,0 +1,44 @@ +# Equivalent to the two explicit Agent Teams profile layers over the scaffold's +# stable base and Web bundles. +- id: tool-subagent-control + disabled: true + +- id: tool-subagent-list-agents + disabled: true + +- id: tool-subagent-report + disabled: true + +- id: tool-subagent + config: + provider: spawn + toolName: subagent + backgroundMode: one-shot + +- id: tool-subagent-fork + config: + provider: fork + toolName: subagent_fork + backgroundMode: one-shot + +- insert: + - id: team + name: '@deepseek-ai/dsh-team' + config: + maxMembers: 8 + maxTasks: 256 + maxPendingMessagesPerMember: 64 + maxMessageBytes: 65536 + disposalTimeoutMs: 5000 + + - id: tool-team + name: '@deepseek-ai/dsh-tool-team' + config: + freshProvider: spawn + forkProvider: fork + + - id: agent-team-remotes + name: '@deepseek-ai/dsh-agent-team-remotes' + + - id: ui-agent-team + name: '@deepseek-ai/dsh-client-ui-agent-team' diff --git a/apps/web/tests/scaffold.ts b/apps/web/tests/scaffold.ts index 58e4e249b7..6e89812da7 100644 --- a/apps/web/tests/scaffold.ts +++ b/apps/web/tests/scaffold.ts @@ -54,6 +54,7 @@ import { composeEntries, healProfilesModuleFallback, loadOverlayPatches, + type Profile, } from '@deepseek-ai/dsh-app-boot' import { dshHomePath } from '@deepseek-ai/dsh-home-paths' import { settingsNamespace } from '@deepseek-ai/dsh-settings' @@ -237,6 +238,11 @@ export interface LaunchOptions { * ordering. */ extraOverlayPath?: string + /** + * Additional source-checkout package manifests whose dependency closures + * supply private profile layers named by {@link extraOverlayPath}. + */ + extraInstallAnchors?: string[] /** * Replay fixture (session.jsonl) served by the inserted dsh-llm-replay row * in replay/refresh modes; ignored in record mode (the real adapter @@ -569,11 +575,35 @@ export async function launchWebScaffold(options: LaunchOptions = {}): Promise/profiles. - await healProfilesModuleFallback({ installAnchor: INSTALL_ANCHOR, home: harnessHome }) const profileDir = join(harnessHome, 'profiles', 'scaffold') + const extraLayers: Profile['layers'] = await Promise.all((options.extraInstallAnchors ?? []).map(async (anchor) => { + const manifest = JSON.parse(await readFile(anchor, 'utf8')) as { name?: unknown } + if (typeof manifest.name !== 'string' || manifest.name === '') { + throw new Error(`web scaffold extra install anchor has no package name: ${anchor}`) + } + const packageDir = dirname(anchor) + return { + packageName: manifest.name, + packageDir, + patchPath: join(packageDir, 'cordis.patch.yml'), + patches: [], + } + })) + // Mirror the production launcher: the shared installation closure keeps + // its carrier-specific fallback, while private bundle dependencies stay + // isolated to this synthetic scaffold profile. + await healProfilesModuleFallback({ + installAnchor: INSTALL_ANCHOR, + home: harnessHome, + profile: { + name: 'scaffold', + dir: profileDir, + layers: extraLayers, + patchPath: join(profileDir, 'cordis.patch.yml'), + patches: [], + patchReload: 'startup', + }, + }) await mkdir(profileDir, { recursive: true }) const rootConfig = join(profileDir, 'cordis.yml') await writeFile(rootConfig, '[]\n') diff --git a/apps/web/tests/snapshots/agent-team-panel/task.expected.md b/apps/web/tests/snapshots/agent-team-panel/task.expected.md new file mode 100644 index 0000000000..42543b8027 --- /dev/null +++ b/apps/web/tests/snapshots/agent-team-panel/task.expected.md @@ -0,0 +1,29 @@ +- button "Agent Team" [expanded]: + - img + - text: Agent Team +- dialog "Agent Team": + - strong: Agent Team + - button "Refresh Team": + - img + - button "Close": + - img + - heading "Members" [level=3] + - 'button "lead idle · Model: deepseek-v4-flash" [disabled]' + - heading "Shared tasks" [level=3] + - button "New task": + - img + - text: New task + - article: + - strong: Browser task + - text: Pending + - paragraph: Created through the assembled browser + - text: "task-1 Ready Write scopes: src/web Owner" + - combobox "Owner": + - option "Unowned" [selected] + - option "lead" + - button "Edit": + - img + - text: Edit + - button "Delete": + - img + - text: Delete diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index a104388946..0388704e61 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -82,6 +82,7 @@ "tests/shipped-composition.e2e.ts", "tests/schedule-after.e2e.ts", "tests/feedback-command.e2e.ts", + "tests/agent-team-panel.e2e.ts", "tests/startup-auto-selection.e2e.ts", "tests/produced-files.e2e.ts", "tests/produced-file-mentions.e2e.ts", diff --git a/docs/subsystems/agent-team.md b/docs/subsystems/agent-team.md index 8704bff307..84becd182c 100644 --- a/docs/subsystems/agent-team.md +++ b/docs/subsystems/agent-team.md @@ -105,6 +105,13 @@ membership(agent: Agent): TeamMembership */ listMembers(agent: Agent): TeamMemberView[] +/** + * Read the current roster and non-deleted task board for a browser client. + * @param agent - exact live Team member used as the authority credential. + * @returns detached current roster and task views. + */ +@Remote('view') view(agent: Agent): TeamView + /** * Create one named, continuable direct child of the Team Lead. * @param caller - exact live Lead Agent. @@ -129,6 +136,14 @@ async sendMessage(caller: Agent, request: SendTeamMessageRequest): Promise +/** + * Create one shared task for a browser client. + * @param agent - exact live Team member creating the task. + * @param request - task text, blockers, and advisory write scopes. + * @returns the revision-one task view. + */ +@Remote('createTask') createTaskForClient(agent: Agent, request: CreateTeamTaskRequest): Promise + /** * Return one task, including a deleted tombstone. * @param caller - exact live Team member reading the task. @@ -152,6 +167,14 @@ listTasks(caller: Agent): TeamTaskView[] */ async updateTask(caller: Agent, request: UpdateTeamTaskRequest): Promise +/** + * Apply one task mutation for a browser client while preserving CAS conflicts. + * @param agent - exact live Team member authorizing the mutation. + * @param request - task identity, expected revision, action, and action fields. + * @returns the committed task or a browser-safe Team rejection. + */ +@Remote('updateTask') async updateTaskForClient(agent: Agent, request: UpdateTeamTaskRequest): Promise + /** * Wait for the next Team-domain or member-status change. * @param caller - exact live Team member waiting for activity. diff --git a/docs/subsystems/agent-team.zh.md b/docs/subsystems/agent-team.zh.md index dfa55743e5..4fb5e4fb7b 100644 --- a/docs/subsystems/agent-team.zh.md +++ b/docs/subsystems/agent-team.zh.md @@ -105,6 +105,13 @@ membership(agent: Agent): TeamMembership */ listMembers(agent: Agent): TeamMemberView[] +/** + * Read the current roster and non-deleted task board for a browser client. + * @param agent - exact live Team member used as the authority credential. + * @returns detached current roster and task views. + */ +@Remote('view') view(agent: Agent): TeamView + /** * Create one named, continuable direct child of the Team Lead. * @param caller - exact live Lead Agent. @@ -129,6 +136,14 @@ async sendMessage(caller: Agent, request: SendTeamMessageRequest): Promise +/** + * Create one shared task for a browser client. + * @param agent - exact live Team member creating the task. + * @param request - task text, blockers, and advisory write scopes. + * @returns the revision-one task view. + */ +@Remote('createTask') createTaskForClient(agent: Agent, request: CreateTeamTaskRequest): Promise + /** * Return one task, including a deleted tombstone. * @param caller - exact live Team member reading the task. @@ -152,6 +167,14 @@ listTasks(caller: Agent): TeamTaskView[] */ async updateTask(caller: Agent, request: UpdateTeamTaskRequest): Promise +/** + * Apply one task mutation for a browser client while preserving CAS conflicts. + * @param agent - exact live Team member authorizing the mutation. + * @param request - task identity, expected revision, action, and action fields. + * @returns the committed task or a browser-safe Team rejection. + */ +@Remote('updateTask') async updateTaskForClient(agent: Agent, request: UpdateTeamTaskRequest): Promise + /** * Wait for the next Team-domain or member-status change. * @param caller - exact live Team member waiting for activity. diff --git a/knip.json b/knip.json index 09e6327745..a989ed37c2 100644 --- a/knip.json +++ b/knip.json @@ -756,6 +756,17 @@ "@deepseek-ai/.+" ] }, + "packages/experimental/agent-team-remotes": { + "entry": [ + "tests/**/*.e2e.ts" + ] + }, + "packages/experimental/agent-team-web-profile": { + "ignoreDependencies": [ + "@deepseek-ai/dsh-agent-team-remotes", + "@deepseek-ai/dsh-client-ui-agent-team" + ] + }, "packages/bundle/web-app": { "ignoreDependencies": [ "@deepseek-ai/.+" diff --git a/packages/experimental/README.md b/packages/experimental/README.md index ad658da843..10a5017567 100644 --- a/packages/experimental/README.md +++ b/packages/experimental/README.md @@ -26,6 +26,9 @@ The experimental group contains prototype capabilities that are not part of any |---|---|---| | [`agent-team-profile`](agent-team-profile/README.md) | Explicit source-checkout profile layer for Agent Teams | — | | [`agent-team`](agent-team/README.md) | Named teammates with durable messages and a shared task board | `ctx.agentTeams` | +| [`agent-team-remotes`](agent-team-remotes/README.md) | Client assembly for the generated Agent Teams Remote contribution | `ctx.remote.agentTeams` | +| [`agent-team-web-profile`](agent-team-web-profile/README.md) | Explicit source-checkout Web layer for Agent Teams | — | +| [`client-ui-agent-team`](client-ui-agent-team/README.md) | Team roster, task board, and teammate navigation for Web | — | | [`tool-agent-team`](tool-agent-team/README.md) | Ten tools that let the model create, message, and coordinate teammates | registers scoped tools on `ctx.tools` | | [`webworker-packer`](webworker-packer/README.md) | Builds the gzip-compressed VFS image consumed by the browser worker preview | library and CLI — no ctx key | | [`webworker-runtime`](webworker-runtime/README.md) | Runs the harness plugin tree inside a dedicated browser worker | library and worker entry — no ctx key | diff --git a/packages/experimental/README.zh.md b/packages/experimental/README.zh.md index a8b777b40e..dbd1605996 100644 --- a/packages/experimental/README.zh.md +++ b/packages/experimental/README.zh.md @@ -26,6 +26,9 @@ kind: "package-group" |---|---|---| | [`agent-team-profile`](agent-team-profile/README.zh.md) | Agent Teams 的显式源码 checkout profile 层 | — | | [`agent-team`](agent-team/README.zh.md) | 具名 teammate,成员之间持久消息与共享任务板 | `ctx.agentTeams` | +| [`agent-team-remotes`](agent-team-remotes/README.zh.md) | 生成式 Agent Teams Remote contribution 的 Client assembly | `ctx.remote.agentTeams` | +| [`agent-team-web-profile`](agent-team-web-profile/README.zh.md) | Agent Teams 的显式源码 checkout Web 层 | — | +| [`client-ui-agent-team`](client-ui-agent-team/README.zh.md) | Web Team roster、任务板与 teammate 导航 | — | | [`tool-agent-team`](tool-agent-team/README.zh.md) | 让模型创建、发消息与协调 teammate 的十个工具 | 按作用域注册工具到 `ctx.tools` | | [`webworker-packer`](webworker-packer/README.zh.md) | 构建浏览器 worker 预览所消费的 gzip 压缩 VFS 镜像 | 库与 CLI,不使用 ctx key | | [`webworker-runtime`](webworker-runtime/README.zh.md) | 在专用浏览器 worker 中运行 harness 插件树 | 库与 worker 入口,不使用 ctx key | diff --git a/packages/experimental/agent-team-remotes/README.i18n.yaml b/packages/experimental/agent-team-remotes/README.i18n.yaml new file mode 100644 index 0000000000..42db67354d --- /dev/null +++ b/packages/experimental/agent-team-remotes/README.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 packages/experimental/agent-team-remotes/README.md +README.md: be1d28c5ef53b932a9553a716488e465fd2ad8ce +README.zh.md: ee4e0734e1296424b428b8ecb184a5e8b06b194a diff --git a/packages/experimental/agent-team-remotes/README.md b/packages/experimental/agent-team-remotes/README.md new file mode 100644 index 0000000000..be1d28c5ef --- /dev/null +++ b/packages/experimental/agent-team-remotes/README.md @@ -0,0 +1,22 @@ +# @deepseek-ai/dsh-agent-team-remotes + +English | [中文](README.zh.md) + +Private Client assembly for the Agent Teams Typert Remote contribution. Its Client entry imports the generated `@deepseek-ai/dsh-team/remote` runtime value, mounts it through the stable `ctx.remote.$mount()` service, and re-exports the declaration merge that adds `ctx.remote.teams`. + +The contribution exposes `teams/view`, `teams/createTask`, and `teams/updateTask`. The generated codecs validate arguments and results, while the Team service remains the only owner of roster and task state. This package contains no Host resolver or transport logic; `@deepseek-ai/dsh-api-remotes` supplies the stable Remote service and Agent identity policy. + +The root export is inert because this package mounts only in a Client environment. [`@deepseek-ai/dsh-agent-team-web-profile`](../agent-team-web-profile/README.md) inserts it before the Team UI so the namespace exists when the UI activates. + +## Model Experience + +None, as this Client assembly only mounts typed Remote methods and registers no model-facing input. + +#### KV Cache effect + +No direct effect; invoked Team methods and their model-facing consumers own any later effect. + +## Known Limitations and Deferred Work + +- **Fixed contribution set** — adding a Team Remote method requires regenerating the Team artifacts and rebuilding this explicit assembly. +- **Source-checkout only** — this private package is excluded from official releases. diff --git a/packages/experimental/agent-team-remotes/README.zh.md b/packages/experimental/agent-team-remotes/README.zh.md new file mode 100644 index 0000000000..ee4e0734e1 --- /dev/null +++ b/packages/experimental/agent-team-remotes/README.zh.md @@ -0,0 +1,22 @@ +# @deepseek-ai/dsh-agent-team-remotes + +[English](README.md) | 中文 + +Agent Teams Typert Remote contribution 的私有 Client assembly。它的 Client entry 导入生成式 `@deepseek-ai/dsh-team/remote` runtime value,通过稳定 `ctx.remote.$mount()` service 挂载,并重新导出为 `ctx.remote.teams` 增加类型的 declaration merge。 + +该 contribution 提供 `teams/view`、`teams/createTask` 与 `teams/updateTask`。生成式 codec 校验参数和结果,Team service 仍是 roster 与 task 状态的唯一 owner。本包不包含 Host resolver 或 transport 逻辑;`@deepseek-ai/dsh-api-remotes` 提供稳定 Remote service 与 Agent identity policy。 + +Root export 不执行行为,因为本包只在 Client 环境挂载。[`@deepseek-ai/dsh-agent-team-web-profile`](../agent-team-web-profile/README.md) 会先于 Team UI 插入本包,确保 UI 激活时 namespace 已存在。 + +## 模型体验 + +无直接影响,因为该 Client assembly 只挂载 typed Remote method,不注册面向模型的输入。 + +#### KV Cache 影响 + +无直接影响;被调用的 Team method 及其面向模型的 consumer 负责后续任何影响。 + +## 已知限制与暂缓事项 + +- **固定 contribution 集合**:增加 Team Remote method 时,需要重新生成 Team artifact 并重建这个显式 assembly。 +- **仅限源码 checkout**:正式发布会排除这个私有包。 diff --git a/packages/experimental/agent-team-remotes/package.json b/packages/experimental/agent-team-remotes/package.json new file mode 100644 index 0000000000..13979d5780 --- /dev/null +++ b/packages/experimental/agent-team-remotes/package.json @@ -0,0 +1,62 @@ +{ + "name": "@deepseek-ai/dsh-agent-team-remotes", + "description": "Private Client assembly for the Agent Teams Typert Remote contribution", + "version": "0.1.0-rc.7", + "private": true, + "repository": { + "type": "git", + "url": "git+https://github.com/deepseek-ai/deepseek-harness.git", + "directory": "packages/experimental/agent-team-remotes" + }, + "type": "module", + "main": "lib/index.js", + "types": "lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + }, + "./invariant": { + "types": "./lib/types/invariant.d.ts", + "default": "./lib/invariant.js" + }, + "./client": { + "types": "./lib/types/client/index.d.ts", + "default": "./lib/client.js" + }, + "./src/*": "./src/*", + "./package.json": "./package.json" + }, + "dsh": { + "client": { + "inject": [ + "@deepseek-ai/dsh-api-remotes" + ], + "platform": "web", + "immediately": true + } + }, + "scripts": { + "bundle": "tsdown", + "watch": "tsdown --watch" + }, + "license": "MIT", + "peerDependencies": { + "@deepseek-ai/dsh-api-remotes": "workspace:^", + "@deepseek-ai/dsh-invariants": "workspace:^", + "@deepseek-ai/dsh-team": "workspace:^", + "@deepseek-ai/cordis": "workspace:^" + }, + "devDependencies": { + "@deepseek-ai/dsh-api-remotes": "workspace:^", + "@deepseek-ai/dsh-invariants": "workspace:^", + "@deepseek-ai/dsh-team": "workspace:^", + "@deepseek-ai/cordis": "workspace:^" + }, + "files": [ + "lib/index.js", + "lib/invariant.js", + "lib/client.js", + "lib/types/**/*.d.ts" + ] +} diff --git a/packages/experimental/agent-team-remotes/src/client/index.ts b/packages/experimental/agent-team-remotes/src/client/index.ts new file mode 100644 index 0000000000..9a8b5edf52 --- /dev/null +++ b/packages/experimental/agent-team-remotes/src/client/index.ts @@ -0,0 +1,19 @@ +/** Client assembly for the generated Agent Teams Remote contribution. */ + +import type { Context } from '@deepseek-ai/cordis' +import type {} from '@deepseek-ai/dsh-api-remotes/client' +import teamsRemote from '@deepseek-ai/dsh-team/remote' + +export type {} from '@deepseek-ai/dsh-team/remote' + +/** Required service: the typed Client Remote contribution mount. */ +export const inject = ['remote'] + +/** + * Mount the Agent Teams Remote namespace selected by the experimental Web profile. + * @param ctx - Client Cordis root carrying the Remote service. + * @returns disposer after the contribution is ready. + */ +export function apply(ctx: Context): Promise<() => Promise> { + return ctx.remote.$mount(teamsRemote) +} diff --git a/packages/experimental/agent-team-remotes/src/index.ts b/packages/experimental/agent-team-remotes/src/index.ts new file mode 100644 index 0000000000..5539b6adc3 --- /dev/null +++ b/packages/experimental/agent-team-remotes/src/index.ts @@ -0,0 +1,4 @@ +/** Pure Host half for the private Agent Teams Client Remote assembly. */ + +/** Host plugin body; the generated contribution mounts only in Client environments. */ +export function apply(): void {} diff --git a/packages/experimental/agent-team-remotes/src/invariant.ts b/packages/experimental/agent-team-remotes/src/invariant.ts new file mode 100644 index 0000000000..8522554074 --- /dev/null +++ b/packages/experimental/agent-team-remotes/src/invariant.ts @@ -0,0 +1,23 @@ +/** Package-owned invariant companion for the Agent Teams Client Remote assembly. */ + +import type { Context } from '@deepseek-ai/cordis' +import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants' + +const PACKAGE_NAME = '@deepseek-ai/dsh-agent-team-remotes' + +/** Cordis companion plugin name. */ +export const name = 'agent-team-remotes-invariant' +/** Service required before the companion can register. */ +export const inject = ['invariants'] + +// No runtime invariant: Client Remote validates each request and result with +// the generated Team codecs, while the Team service owns mutable state. +const install: InvariantInstaller = () => {} + +/** + * Register this package's invariant companion. + * @param ctx - Cordis context carrying the invariant service. + * @returns the installed registration's disposer after setup succeeds. + */ +export const apply = (ctx: Context): Promise<() => void> => + Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install)) diff --git a/packages/experimental/agent-team-remotes/tests/built-lib.e2e.ts b/packages/experimental/agent-team-remotes/tests/built-lib.e2e.ts new file mode 100644 index 0000000000..43b3877eda --- /dev/null +++ b/packages/experimental/agent-team-remotes/tests/built-lib.e2e.ts @@ -0,0 +1,95 @@ +/** Plain-Node smoke for the generated Agent Teams Client Remote assembly. */ + +import { execFile } from 'node:child_process' +import { existsSync } from 'node:fs' +import { join, resolve } from 'node:path' +import { fileURLToPath, pathToFileURL } from 'node:url' +import { describe, expect, it } from 'vitest' + +const packageDir = fileURLToPath(new URL('..', import.meta.url)) +const root = resolve(packageDir, '../../..') +const artifact = (path: string): string => join(root, path) +const artifactUrl = (path: string): string => pathToFileURL(artifact(path)).href + +const requiredArtifacts = [ + 'packages/experimental/agent-team-remotes/lib/client.js', + 'packages/experimental/agent-team-remotes/lib/index.js', + 'packages/experimental/team/lib/typert.remote-client.js', +].every(path => existsSync(artifact(path))) + +describe.skipIf(!requiredArtifacts)('Agent Teams Remote built LIB assembly', () => { + it('mounts exactly the generated Team contribution and keeps the Host half inert', async () => { + const urls = { + client: artifactUrl('packages/experimental/agent-team-remotes/lib/client.js'), + host: artifactUrl('packages/experimental/agent-team-remotes/lib/index.js'), + } + const script = ` + const handoffs = new Map() + globalThis.window = { + __ModuleLoader__: { + load(handoff) { handoffs.set(handoff.id, handoff) }, + }, + } + const host = await import(${JSON.stringify(urls.host)}) + host.apply() + await import(${JSON.stringify(urls.client)}) + const handoff = handoffs.get('@deepseek-ai/dsh-agent-team-remotes') + if (handoff === undefined) throw new Error('missing Agent Teams Remote Client handoff') + const plugin = handoff.factory(specifier => { + throw new Error('unexpected Client external ' + specifier) + }) + let mounted + const dispose = () => {} + const result = await plugin.apply({ + remote: { + $mount(contribution) { + mounted = contribution + return Promise.resolve(dispose) + }, + }, + }) + console.log(JSON.stringify({ + inject: plugin.inject, + sameDisposer: result === dispose, + methods: mounted?.descriptors.map(descriptor => descriptor.id), + })) + ` + + const result = await runPlainNode(script) + expect(result.exitCode, `stderr:\n${result.stderr}`).toBe(0) + const output = JSON.parse(result.stdout.trim().split('\n').at(-1) ?? '{}') as { + inject: string[] + sameDisposer: boolean + methods: string[] + } + expect(output).toEqual({ + inject: ['remote'], + sameDisposer: true, + methods: [ + '@deepseek-ai/dsh-team#teams/createTask', + '@deepseek-ai/dsh-team#teams/updateTask', + '@deepseek-ai/dsh-team#teams/view', + ], + }) + }) +}) + +function runPlainNode(script: string): Promise<{ + readonly exitCode: number | null + readonly stdout: string + readonly stderr: string +}> { + return new Promise((resolveRun) => { + execFile(process.execPath, ['--input-type=module', '-e', script], { + cwd: packageDir, + encoding: 'utf8', + timeout: 30_000, + }, (error, stdout, stderr) => { + resolveRun({ + exitCode: error === null ? 0 : typeof error.code === 'number' ? error.code : null, + stdout, + stderr, + }) + }) + }) +} diff --git a/packages/experimental/agent-team-remotes/tests/invariant.spec.ts b/packages/experimental/agent-team-remotes/tests/invariant.spec.ts new file mode 100644 index 0000000000..c8a8ea33ad --- /dev/null +++ b/packages/experimental/agent-team-remotes/tests/invariant.spec.ts @@ -0,0 +1,16 @@ +/** Package invariant registration for the Agent Teams Remote assembly. */ + +import { describe, expect, it, vi } from 'vitest' +import * as invariant from '../src/invariant.ts' + +describe('Agent Teams Remote invariant', () => { + it('reserves package ownership with an empty invariant installer', async () => { + const register = vi.fn().mockReturnValue(() => {}) + const ctx = { invariants: { register } } as never + + const dispose = await invariant.apply(ctx) + expect(register).toHaveBeenCalledWith('@deepseek-ai/dsh-agent-team-remotes', expect.any(Function)) + expect(() => { (register.mock.calls[0]![1] as () => void)() }).not.toThrow() + expect(dispose).toBeTypeOf('function') + }) +}) diff --git a/packages/experimental/agent-team-remotes/tsconfig.client.json b/packages/experimental/agent-team-remotes/tsconfig.client.json new file mode 100644 index 0000000000..34f7f86636 --- /dev/null +++ b/packages/experimental/agent-team-remotes/tsconfig.client.json @@ -0,0 +1,20 @@ +{ + "extends": "../../../tsconfig.base.client.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib/types", + "tsBuildInfoFile": "lib/tsconfig.client.tsbuildinfo" + }, + "files": ["src/client/index.ts"], + "references": [ + { + "path": "../../../vendor/cordis" + }, + { + "path": "../../api/remotes/tsconfig.client.json" + }, + { + "path": "../team" + } + ] +} diff --git a/packages/experimental/agent-team-remotes/tsconfig.host.json b/packages/experimental/agent-team-remotes/tsconfig.host.json new file mode 100644 index 0000000000..2f18caea89 --- /dev/null +++ b/packages/experimental/agent-team-remotes/tsconfig.host.json @@ -0,0 +1,17 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib/types", + "tsBuildInfoFile": "lib/tsconfig.host.tsbuildinfo" + }, + "files": ["src/index.ts", "src/invariant.ts"], + "references": [ + { + "path": "../../../vendor/cordis" + }, + { + "path": "../../runtime-diagnostics/invariants" + } + ] +} diff --git a/packages/experimental/agent-team-remotes/tsconfig.json b/packages/experimental/agent-team-remotes/tsconfig.json new file mode 100644 index 0000000000..2eca820546 --- /dev/null +++ b/packages/experimental/agent-team-remotes/tsconfig.json @@ -0,0 +1,11 @@ +{ + "files": [], + "references": [ + { + "path": "./tsconfig.host.json" + }, + { + "path": "./tsconfig.client.json" + } + ] +} diff --git a/packages/experimental/agent-team-remotes/tsdown.config.ts b/packages/experimental/agent-team-remotes/tsdown.config.ts new file mode 100644 index 0000000000..24d7f8d797 --- /dev/null +++ b/packages/experimental/agent-team-remotes/tsdown.config.ts @@ -0,0 +1,3 @@ +import { clientBundle } from '../../client/tsdown.client.ts' + +export default clientBundle('@deepseek-ai/dsh-agent-team-remotes', ['lib/types/index.js', 'lib/types/invariant.js']) diff --git a/packages/experimental/agent-team-web-profile/README.i18n.yaml b/packages/experimental/agent-team-web-profile/README.i18n.yaml new file mode 100644 index 0000000000..33f7358d3c --- /dev/null +++ b/packages/experimental/agent-team-web-profile/README.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 packages/experimental/agent-team-web-profile/README.md +README.md: cf893ce84f30ae07834b2ff1d4272b037547cb3e +README.zh.md: e4ecafb020a84b37f2babd731abc4d09f35e66e7 diff --git a/packages/experimental/agent-team-web-profile/README.md b/packages/experimental/agent-team-web-profile/README.md new file mode 100644 index 0000000000..cf893ce84f --- /dev/null +++ b/packages/experimental/agent-team-web-profile/README.md @@ -0,0 +1,27 @@ +# @deepseek-ai/dsh-agent-team-web-profile + +English | [中文](README.zh.md) + +Private Web profile layer for Agent Teams. Apply it after `@deepseek-ai/dsh-web-app` and [`@deepseek-ai/dsh-agent-team-profile`](../agent-team-profile/README.md). The patch inserts the experimental Client Remote assembly followed by the Team conversation-header UI; it does not modify the stable Web bundle. + +From a source checkout, add both Agent Teams layers to an initialized Web profile: + +```sh +pnpm dsh plugin --profile web add ./packages/experimental/agent-team-profile +pnpm dsh plugin --profile web add ./packages/experimental/agent-team-web-profile +``` + +The Host profile supplies the Team domain and model tools. This Web layer supplies only the generated Client Remote namespace and browser presentation. Removing either experimental bundle leaves the stable base and Web composition unchanged. + +## Model Experience + +Indirectly, through the Host-side Agent Teams profile selected alongside this Web layer. + +#### KV Cache effect + +No direct effect; the Host-side Team tools own prompt and schema changes. + +## Known Limitations and Deferred Work + +- **Ordered composition** — `dsh-base`, `dsh-web-app`, `dsh-agent-team-profile`, and this package must remain in that order. +- **Source-checkout only** — official CLI, Web, npm, and Python release payloads exclude this private package. diff --git a/packages/experimental/agent-team-web-profile/README.zh.md b/packages/experimental/agent-team-web-profile/README.zh.md new file mode 100644 index 0000000000..e4ecafb020 --- /dev/null +++ b/packages/experimental/agent-team-web-profile/README.zh.md @@ -0,0 +1,27 @@ +# @deepseek-ai/dsh-agent-team-web-profile + +[English](README.md) | 中文 + +Agent Teams 的私有 Web profile 层。应当在 `@deepseek-ai/dsh-web-app` 与 [`@deepseek-ai/dsh-agent-team-profile`](../agent-team-profile/README.md) 之后应用。本 patch 先插入实验性 Client Remote assembly,再插入 Team 会话页头 UI;它不修改稳定 Web bundle。 + +在源码 checkout 中,将两个 Agent Teams 层添加到已初始化的 Web profile: + +```sh +pnpm dsh plugin --profile web add ./packages/experimental/agent-team-profile +pnpm dsh plugin --profile web add ./packages/experimental/agent-team-web-profile +``` + +Host profile 提供 Team domain 与模型工具。本 Web 层只提供生成式 Client Remote namespace 与浏览器呈现。移除任一实验性 bundle 后,稳定 base 与 Web composition 保持不变。 + +## 模型体验 + +间接通过与该 Web 层同时选择的 Host 侧 Agent Teams profile 产生影响。 + +#### KV Cache 影响 + +无直接影响;Host 侧 Team 工具负责 prompt 与 schema 变化。 + +## 已知限制与暂缓事项 + +- **有序 composition**:`dsh-base`、`dsh-web-app`、`dsh-agent-team-profile` 与本包必须保持该顺序。 +- **仅限源码 checkout**:正式 CLI、Web、npm 与 Python 发布产物会排除这个私有包。 diff --git a/packages/experimental/agent-team-web-profile/cordis.patch.yml b/packages/experimental/agent-team-web-profile/cordis.patch.yml new file mode 100644 index 0000000000..14984af370 --- /dev/null +++ b/packages/experimental/agent-team-web-profile/cordis.patch.yml @@ -0,0 +1,9 @@ +# Private Agent Teams Web layer. Apply after dsh-web-app and the host-side +# dsh-agent-team-profile so the browser mounts only when both seams are present. + +- insert: + - id: agent-team-remotes + name: '@deepseek-ai/dsh-agent-team-remotes' + + - id: ui-agent-team + name: '@deepseek-ai/dsh-client-ui-agent-team' diff --git a/packages/experimental/agent-team-web-profile/package.json b/packages/experimental/agent-team-web-profile/package.json new file mode 100644 index 0000000000..0fec9d1577 --- /dev/null +++ b/packages/experimental/agent-team-web-profile/package.json @@ -0,0 +1,53 @@ +{ + "name": "@deepseek-ai/dsh-agent-team-web-profile", + "description": "Private Web profile layer for Agent Teams Remote and UI plugins", + "version": "0.1.0-rc.7", + "private": true, + "repository": { + "type": "git", + "url": "git+https://github.com/deepseek-ai/deepseek-harness.git", + "directory": "packages/experimental/agent-team-web-profile" + }, + "type": "module", + "main": "lib/index.js", + "types": "lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + }, + "./invariant": { + "types": "./lib/types/invariant.d.ts", + "default": "./lib/invariant.js" + }, + "./cordis.patch.yml": "./cordis.patch.yml", + "./src/*": "./src/*", + "./package.json": "./package.json" + }, + "files": [ + "lib/index.js", + "lib/invariant.js", + "cordis.patch.yml", + "lib/types/**/*.d.ts" + ], + "license": "MIT", + "dsh": { + "bundle": { + "patch": "./cordis.patch.yml" + } + }, + "dependencies": { + "@deepseek-ai/dsh-agent-team-remotes": "workspace:^", + "@deepseek-ai/dsh-client-ui-agent-team": "workspace:^" + }, + "peerDependencies": { + "@deepseek-ai/dsh-invariants": "workspace:^", + "@deepseek-ai/cordis": "workspace:^" + }, + "devDependencies": { + "@deepseek-ai/cordis-plugin-include": "workspace:^", + "@deepseek-ai/dsh-invariants": "workspace:^", + "@deepseek-ai/cordis": "workspace:^", + "js-yaml": "^4.2.0" + } +} diff --git a/packages/experimental/agent-team-web-profile/src/index.ts b/packages/experimental/agent-team-web-profile/src/index.ts new file mode 100644 index 0000000000..2ca6d6012f --- /dev/null +++ b/packages/experimental/agent-team-web-profile/src/index.ts @@ -0,0 +1,3 @@ +/** Private Web profile layer for the Agent Teams Client plugins. */ + +export {} diff --git a/packages/experimental/agent-team-web-profile/src/invariant.ts b/packages/experimental/agent-team-web-profile/src/invariant.ts new file mode 100644 index 0000000000..42531dd04d --- /dev/null +++ b/packages/experimental/agent-team-web-profile/src/invariant.ts @@ -0,0 +1,23 @@ +/** Package-owned invariant companion for the Agent Teams Web profile. */ + +import type { Context } from '@deepseek-ai/cordis' +import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants' + +const PACKAGE_NAME = '@deepseek-ai/dsh-agent-team-web-profile' + +/** Cordis companion plugin name. */ +export const name = 'agent-team-web-profile-invariant' +/** Service required before the companion can register. */ +export const inject = ['invariants'] + +// No runtime invariant: the package carries only a static profile patch. The +// Remote assembly and Team UI own their activation requirements. +const install: InvariantInstaller = () => {} + +/** + * Register this package's invariant companion. + * @param ctx - Cordis context carrying the invariant service. + * @returns the installed registration's disposer after setup succeeds. + */ +export const apply = (ctx: Context): Promise<() => void> => + Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install)) diff --git a/packages/experimental/agent-team-web-profile/tests/profile.spec.ts b/packages/experimental/agent-team-web-profile/tests/profile.spec.ts new file mode 100644 index 0000000000..f8efa92c14 --- /dev/null +++ b/packages/experimental/agent-team-web-profile/tests/profile.spec.ts @@ -0,0 +1,36 @@ +/** The experimental Web bundle must carry one parseable Team Client layer. */ + +import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' +import { resolve } from 'node:path' +import { describe, expect, it } from 'vitest' +import * as yaml from 'js-yaml' +import { entryListSchema } from '@deepseek-ai/cordis-plugin-include' + +describe('Agent Teams Web profile bundle', () => { + it('declares a private parseable layer with the Remote assembly before the UI', () => { + const root = fileURLToPath(new URL('..', import.meta.url)) + const manifest = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8')) as { + private?: boolean + publishConfig?: unknown + dependencies?: Record + dsh?: { bundle?: { patch?: string } } + } + expect(manifest.private).toBe(true) + expect(manifest.publishConfig).toBeUndefined() + expect(manifest.dsh?.bundle?.patch).toBe('./cordis.patch.yml') + expect(manifest.dependencies).toEqual({ + '@deepseek-ai/dsh-agent-team-remotes': 'workspace:^', + '@deepseek-ai/dsh-client-ui-agent-team': 'workspace:^', + }) + + const parsed = yaml.load( + readFileSync(resolve(root, manifest.dsh!.bundle!.patch!), 'utf8'), + { schema: entryListSchema }, + ) as { insert?: { id?: string; name?: string }[] }[] + expect(parsed.flatMap(patch => patch.insert ?? [])).toEqual([ + { id: 'agent-team-remotes', name: '@deepseek-ai/dsh-agent-team-remotes' }, + { id: 'ui-agent-team', name: '@deepseek-ai/dsh-client-ui-agent-team' }, + ]) + }) +}) diff --git a/packages/experimental/agent-team-web-profile/tsconfig.json b/packages/experimental/agent-team-web-profile/tsconfig.json new file mode 100644 index 0000000000..440bba72ae --- /dev/null +++ b/packages/experimental/agent-team-web-profile/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib/types" + }, + "include": ["src"], + "references": [ + { "path": "../../../vendor/cordis" }, + { "path": "../../runtime-diagnostics/invariants" } + ] +} diff --git a/packages/experimental/agent-team/README.md b/packages/experimental/agent-team/README.md index ca088a4cf3..7f5d99d2ef 100644 --- a/packages/experimental/agent-team/README.md +++ b/packages/experimental/agent-team/README.md @@ -164,6 +164,11 @@ Read these pages when the package-level contract is not enough. They move from t ----- + +### Client Remote surface + +`TeamService` contributes the generated `teams/view`, `teams/createTask`, and `teams/updateTask` Typert Remote methods. `./client` exports only browser-safe Team request and view types; `./typert` and `./remote` are generated Host and Client artifacts. The view omits mailbox contents and deleted task tombstones. Task conflicts cross Remote as an explicit business result so a Client can reload instead of losing the Team error code inside a generic carrier failure. + ## Model Experience ### Peer messages diff --git a/packages/experimental/agent-team/README.zh.md b/packages/experimental/agent-team/README.zh.md index ec5f7e1f46..0fc1c9f099 100644 --- a/packages/experimental/agent-team/README.zh.md +++ b/packages/experimental/agent-team/README.zh.md @@ -164,6 +164,11 @@ dispose 会关闭准入、中止并等待已获准的创建与 mailbox dispatch ----- + +### Client Remote 界面 + +`TeamService` 提供生成式 `teams/view`、`teams/createTask` 与 `teams/updateTask` Typert Remote method。`./client` 只导出浏览器安全的 Team request 与 view type;`./typert` 和 `./remote` 是生成的 Host 与 Client artifact。View 不包含 mailbox 内容或已删除 task tombstone。Task conflict 通过显式 business result 跨越 Remote,使 Client 能重新读取状态,而不会把 Team error code 丢失在通用 carrier failure 中。 + ## 模型体验 ### Peer 消息 diff --git a/packages/experimental/agent-team/package.json b/packages/experimental/agent-team/package.json index da61dd441e..e0410967ec 100644 --- a/packages/experimental/agent-team/package.json +++ b/packages/experimental/agent-team/package.json @@ -20,13 +20,30 @@ "types": "./lib/types/invariant.d.ts", "default": "./lib/invariant.js" }, + "./client": { + "types": "./lib/types/client.d.ts", + "default": "./lib/types/client.js" + }, + "./typert": { + "types": "./lib/typert.host.d.ts", + "default": "./lib/typert.host.js" + }, + "./remote": { + "types": "./lib/typert.remote-client.d.ts", + "default": "./lib/typert.remote-client.js" + }, "./src/*": "./src/*", "./package.json": "./package.json" }, "files": [ "lib/index.js", "lib/invariant.js", - "lib/types/**/*.d.ts" + "lib/types/**/*.js", + "lib/types/**/*.d.ts", + "lib/typert.host.js", + "lib/typert.host.d.ts", + "lib/typert.remote-client.js", + "lib/typert.remote-client.d.ts" ], "license": "MIT", "dependencies": { @@ -41,6 +58,7 @@ "@deepseek-ai/dsh-session": "workspace:^", "@deepseek-ai/dsh-session-persistence": "workspace:^", "@deepseek-ai/dsh-subagent": "workspace:^", + "@deepseek-ai/dsh-typert-protocol": "workspace:^", "@deepseek-ai/cordis": "workspace:^" }, "devDependencies": { @@ -58,6 +76,7 @@ "@deepseek-ai/dsh-subagent": "workspace:^", "@deepseek-ai/dsh-subagent-fork-in-process": "workspace:^", "@deepseek-ai/dsh-subagent-spawn-in-process": "workspace:^", + "@deepseek-ai/dsh-typert-protocol": "workspace:^", "@deepseek-ai/cordis": "workspace:^" } } diff --git a/packages/experimental/agent-team/src/client.ts b/packages/experimental/agent-team/src/client.ts new file mode 100644 index 0000000000..c76bab501d --- /dev/null +++ b/packages/experimental/agent-team/src/client.ts @@ -0,0 +1,3 @@ +/** Client-safe Agent Teams request, result, and view vocabulary. */ + +export type * from './types.ts' diff --git a/packages/experimental/agent-team/src/index.ts b/packages/experimental/agent-team/src/index.ts index c66e2ce3f6..981212eea3 100644 --- a/packages/experimental/agent-team/src/index.ts +++ b/packages/experimental/agent-team/src/index.ts @@ -1,9 +1,10 @@ /** Agent Teams service façade over roster, mailbox, task, and runtime lifecycle owners. */ -import { Context, Service } from '@deepseek-ai/cordis' +import { Context } from '@deepseek-ai/cordis' import z from '@deepseek-ai/schemastery' import type { Agent } from '@deepseek-ai/dsh-agent' import type {} from '@deepseek-ai/dsh-session-persistence' +import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol' import { TeamActivity } from './activity.ts' import { errorMessage, TeamError } from './error.ts' import { TeamJournal } from './journal.ts' @@ -22,6 +23,8 @@ import type { SpawnTeammateResult, TeamMemberView, TeamTaskView, + TeamTaskMutationResult, + TeamView, TeamWaitResult, UpdateTeamTaskRequest, } from './types.ts' @@ -53,7 +56,7 @@ function positiveLimit(name: string, value: number): number { } /** Agent Teams service backed by the exact live Lead Session log. */ -export class TeamService extends Service { +export class TeamService extends TypertRemoteService { static inject = ['agents', 'sessions', 'sessionPersistence', 'subagents'] static Config: z = z.object({ @@ -132,6 +135,19 @@ export class TeamService extends Service { return this.roster.list(this.roster.membership(agent)) } + /** + * Read the current roster and non-deleted task board for a browser client. + * @param agent - exact live Team member used as the authority credential. + * @returns detached current roster and task views. + */ + @Remote('view') + view(agent: Agent): TeamView { + return { + members: this.listMembers(agent), + tasks: this.listTasks(agent), + } + } + /** * Create one named, continuable direct child of the Team Lead. * @param caller - exact live Lead Agent. @@ -162,6 +178,17 @@ export class TeamService extends Service { return await this.tasks.create(this.roster.membership(caller), request) } + /** + * Create one shared task for a browser client. + * @param agent - exact live Team member creating the task. + * @param request - task text, blockers, and advisory write scopes. + * @returns the revision-one task view. + */ + @Remote('createTask') + createTaskForClient(agent: Agent, request: CreateTeamTaskRequest): Promise { + return this.createTask(agent, request) + } + /** * Return one task, including a deleted tombstone. * @param caller - exact live Team member reading the task. @@ -191,6 +218,28 @@ export class TeamService extends Service { return await this.tasks.update(caller, this.roster.membership(caller), request) } + /** + * Apply one task mutation for a browser client while preserving CAS conflicts. + * @param agent - exact live Team member authorizing the mutation. + * @param request - task identity, expected revision, action, and action fields. + * @returns the committed task or a browser-safe Team rejection. + */ + @Remote('updateTask') + async updateTaskForClient(agent: Agent, request: UpdateTeamTaskRequest): Promise { + try { + return { ok: true, value: await this.updateTask(agent, request) } + } catch (error) { + if (!(error instanceof TeamError)) throw error + return { + ok: false, + error: { + code: error.code === 'TEAM_TASK_STALE_REVISION' ? 'team-task-conflict' : 'team-rejected', + message: error.message, + }, + } + } + } + /** * Wait for the next Team-domain or member-status change. * @param caller - exact live Team member waiting for activity. diff --git a/packages/experimental/agent-team/src/types.ts b/packages/experimental/agent-team/src/types.ts index cee2b1064a..bca6c49d38 100644 --- a/packages/experimental/agent-team/src/types.ts +++ b/packages/experimental/agent-team/src/types.ts @@ -96,6 +96,23 @@ export interface TeamTaskView { readonly writeScopeWarnings: string[] } +/** Browser-safe point-in-time roster and task-board view. */ +export interface TeamView { + readonly members: TeamMemberView[] + readonly tasks: TeamTaskView[] +} + +/** Browser mutation result preserving stale-revision recovery across Remote. */ +export type TeamTaskMutationResult = + | { readonly ok: true; readonly value: TeamTaskView } + | { + readonly ok: false + readonly error: { + readonly code: 'team-task-conflict' | 'team-rejected' + readonly message: string + } + } + /** One peer message retained until its target Session records it. */ export interface TeamMessageSnapshot { readonly id: TeamMessageId diff --git a/packages/experimental/agent-team/tests/team.spec.ts b/packages/experimental/agent-team/tests/team.spec.ts index 9b606a3de3..ae594227b7 100644 --- a/packages/experimental/agent-team/tests/team.spec.ts +++ b/packages/experimental/agent-team/tests/team.spec.ts @@ -512,6 +512,41 @@ describe('Team identity and provisioning', () => { }) describe('Team shared task DAG', () => { + it('projects browser views and preserves task mutation failures across Remote', async () => { + const { ctx, lead } = await setup([]) + expect(ctx.teams.view(lead)).toEqual({ + members: [expect.objectContaining({ id: lead.id, name: 'lead', role: 'lead' })], + tasks: [], + }) + + const task = await ctx.teams.createTaskForClient(lead, { + subject: 'browser task', + description: 'created through the Remote face', + }) + await expect(ctx.teams.updateTaskForClient(lead, { + taskId: task.id, + expectedRevision: task.revision, + action: 'claim', + })).resolves.toMatchObject({ ok: true, value: { status: 'in_progress' } }) + await expect(ctx.teams.updateTaskForClient(lead, { + taskId: task.id, + expectedRevision: task.revision, + action: 'delete', + })).resolves.toMatchObject({ ok: false, error: { code: 'team-task-conflict' } }) + await expect(ctx.teams.updateTaskForClient(lead, { + taskId: TeamTaskId('task-999'), + expectedRevision: 1, + action: 'delete', + })).resolves.toMatchObject({ ok: false, error: { code: 'team-rejected' } }) + + vi.spyOn(ctx.teams, 'updateTask').mockRejectedValueOnce(new Error('unexpected mutation failure')) + await expect(ctx.teams.updateTaskForClient(lead, { + taskId: task.id, + expectedRevision: 2, + action: 'delete', + })).rejects.toThrow('unexpected mutation failure') + }) + it('fails loudly when the durable numeric task id space is exhausted', async () => { const { ctx, lead } = await setup([]) const id = TeamTaskId(`task-${Number.MAX_SAFE_INTEGER}`) diff --git a/packages/experimental/agent-team/tsconfig.json b/packages/experimental/agent-team/tsconfig.json index d0defa8242..ecfdf8e6e3 100644 --- a/packages/experimental/agent-team/tsconfig.json +++ b/packages/experimental/agent-team/tsconfig.json @@ -14,6 +14,7 @@ { "path": "../../core/session" }, { "path": "../../core/agent" }, { "path": "../../subagent/subagent" }, + { "path": "../../typert/protocol" }, { "path": "../../session/session-persistence" }, { "path": "../../runtime-diagnostics/invariants" } ] diff --git a/packages/experimental/client-ui-agent-team/README.i18n.yaml b/packages/experimental/client-ui-agent-team/README.i18n.yaml new file mode 100644 index 0000000000..d716c98671 --- /dev/null +++ b/packages/experimental/client-ui-agent-team/README.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 packages/experimental/client-ui-agent-team/README.md +README.md: 18352135f3883e8ecda94bc3c1d7c900cdf5d7ad +README.zh.md: abfbbf6a6238f16274db42b7e7295f21d5406edd diff --git a/packages/experimental/client-ui-agent-team/README.md b/packages/experimental/client-ui-agent-team/README.md new file mode 100644 index 0000000000..18352135f3 --- /dev/null +++ b/packages/experimental/client-ui-agent-team/README.md @@ -0,0 +1,25 @@ +# @deepseek-ai/dsh-client-ui-agent-team + +English | [中文](README.zh.md) + +Private Web Agent Teams presentation. It contributes one conversation-header action containing the current roster and shared task board. The browser calls the generated `ctx.remote.teams` namespace supplied by [`@deepseek-ai/dsh-agent-team-remotes`](../agent-team-remotes/README.md); it does not extend the stable API Proxy or store authoritative Team state. + +Opening the panel calls `teams/view`. Roster rows show durable names, runtime status, model, and diagnostics. Selecting a healthy teammate refreshes the existing direct-child catalog and opens the ordinary `{ parentSessionId, childSessionId, mode: 'continuable' }` address. History and later human prompts continue through the stable addressed-subagent conversation path; this package adds no Team-specific field to that address. + +The task board shows task identity, owner, blockers, readiness, advisory write scopes, and overlap warnings. Humans can create, edit, assign or unassign, complete, reopen, and delete tasks through `teams/createTask` and `teams/updateTask`. Every mutation sends the displayed revision. A `team-task-conflict` result reloads the Team view and displays a stale-state notice instead of retrying or overwriting. Editing task text or scopes and changing dependencies remain two sequential compare-and-set mutations because the Team service exposes them as separate actions. + +The root export is inert on the Host. The Client export owns locale and slot registrations, and Cordis disposes both with the plugin fiber. Install the package through [`@deepseek-ai/dsh-agent-team-web-profile`](../agent-team-web-profile/README.md) after the stable Web bundle and the Host-side Agent Teams profile. + +## Model Experience + +None, as this browser projection and task control surface registers no model-facing input. + +#### KV Cache effect + +No direct effect; the Team tools and ordinary conversation submission own any later model-visible use. + +## Known Limitations and Deferred Work + +- **Snapshot refresh** — the panel refreshes on open, explicit refresh, and mutations; it has no live event subscription or mailbox timeline. +- **Ordinary child continuation** — a human message sent after navigation uses the stable addressed-subagent prompt path, not the Team peer mailbox. +- **No lifecycle or workspace controls** — the panel cannot spawn, rename, delete, or interrupt teammates, and write scopes remain advisory metadata. diff --git a/packages/experimental/client-ui-agent-team/README.zh.md b/packages/experimental/client-ui-agent-team/README.zh.md new file mode 100644 index 0000000000..abfbbf6a62 --- /dev/null +++ b/packages/experimental/client-ui-agent-team/README.zh.md @@ -0,0 +1,25 @@ +# @deepseek-ai/dsh-client-ui-agent-team + +[English](README.md) | 中文 + +私有 Web Agent Teams 呈现包。它向会话页头提供一个包含当前 roster 与共享任务板的 action。浏览器调用由 [`@deepseek-ai/dsh-agent-team-remotes`](../agent-team-remotes/README.md) 提供的生成式 `ctx.remote.teams` namespace;它不扩展稳定 API Proxy,也不存储权威 Team 状态。 + +打开 panel 会调用 `teams/view`。Roster row 展示持久 name、运行时 status、model 与 diagnostics。选择健康 teammate 时,系统刷新既有直接 child catalog,并打开普通的 `{ parentSessionId, childSessionId, mode: 'continuable' }` address。History 与后续人类 prompt 继续使用稳定 addressed-subagent 会话路径;本包不会向该 address 添加 Team 专用字段。 + +任务板展示 task identity、owner、blocker、readiness、提示性 write scope 与重叠 warning。人类可以通过 `teams/createTask` 与 `teams/updateTask` 创建、编辑、分配或取消分配、完成、重开和删除任务。每次 mutation 都发送当前显示的 revision。收到 `team-task-conflict` 结果后,UI 会重新读取 Team view 并显示状态陈旧提示,不会自动重试或覆盖。Team service 将任务文本或 scope 编辑与 dependency 修改公开为两个独立 action,因此两者仍使用两个连续的 compare-and-set mutation。 + +Root export 在 Host 上不执行行为。Client export 负责 locale 与 slot 注册,Cordis 会随 plugin fiber dispose 两者。在稳定 Web bundle 与 Host 侧 Agent Teams profile 之后,通过 [`@deepseek-ai/dsh-agent-team-web-profile`](../agent-team-web-profile/README.md) 安装本包。 + +## 模型体验 + +无直接影响,因为该浏览器 projection 与任务控制界面不注册面向模型的输入。 + +#### KV Cache 影响 + +无直接影响;Team 工具与普通会话提交负责后续任何模型可见用途。 + +## 已知限制与暂缓事项 + +- **Snapshot refresh**:panel 会在打开、显式 refresh 与 mutation 后刷新;它没有实时 event subscription 或 mailbox timeline。 +- **普通 child continuation**:导航后发送的人类消息使用稳定 addressed-subagent prompt 路径,而不是 Team peer mailbox。 +- **没有 lifecycle 或 workspace control**:panel 不能 spawn、rename、delete 或 interrupt teammate,write scope 仍只是提示性 metadata。 diff --git a/packages/experimental/client-ui-agent-team/package.json b/packages/experimental/client-ui-agent-team/package.json new file mode 100644 index 0000000000..e514a9e6af --- /dev/null +++ b/packages/experimental/client-ui-agent-team/package.json @@ -0,0 +1,86 @@ +{ + "name": "@deepseek-ai/dsh-client-ui-agent-team", + "description": "Web Agent Teams roster, task board, and teammate navigation", + "version": "0.1.0-rc.7", + "private": true, + "repository": { + "type": "git", + "url": "git+https://github.com/deepseek-ai/deepseek-harness.git", + "directory": "packages/experimental/client-ui-agent-team" + }, + "type": "module", + "main": "lib/index.js", + "types": "lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + }, + "./invariant": { + "types": "./lib/types/invariant.d.ts", + "default": "./lib/invariant.js" + }, + "./client": { + "types": "./lib/types/client/index.d.ts", + "default": "./lib/client.js" + }, + "./src/*": "./src/*", + "./package.json": "./package.json" + }, + "dsh": { + "client": { + "inject": [ + "@deepseek-ai/dsh-agent-team-remotes", + "@deepseek-ai/dsh-client-locale", + "@deepseek-ai/dsh-client-runtime", + "@deepseek-ai/dsh-client-ui-conversation", + "@deepseek-ai/dsh-client-ui-primitives" + ], + "platform": "web" + } + }, + "scripts": { + "bundle": "tsdown", + "watch": "tsdown --watch" + }, + "license": "MIT", + "dependencies": { + "react": "^18.2.0" + }, + "peerDependencies": { + "@deepseek-ai/dsh-agent-team-remotes": "workspace:^", + "@deepseek-ai/dsh-api-remotes": "workspace:^", + "@deepseek-ai/dsh-client-locale": "workspace:^", + "@deepseek-ai/dsh-client-runtime": "workspace:^", + "@deepseek-ai/dsh-client-ui-conversation": "workspace:^", + "@deepseek-ai/dsh-client-ui-primitives": "workspace:^", + "@deepseek-ai/dsh-client-ui-slots": "workspace:^", + "@deepseek-ai/dsh-invariants": "workspace:^", + "@deepseek-ai/dsh-team": "workspace:^", + "@deepseek-ai/dsh-typert-protocol": "workspace:^", + "@deepseek-ai/cordis": "workspace:^" + }, + "devDependencies": { + "@deepseek-ai/dsh-agent-team-remotes": "workspace:^", + "@deepseek-ai/dsh-api-remotes": "workspace:^", + "@deepseek-ai/dsh-client-locale": "workspace:^", + "@deepseek-ai/dsh-client-runtime": "workspace:^", + "@deepseek-ai/dsh-client-test-runtime": "workspace:^", + "@deepseek-ai/dsh-client-ui-conversation": "workspace:^", + "@deepseek-ai/dsh-client-ui-primitives": "workspace:^", + "@deepseek-ai/dsh-client-ui-slots": "workspace:^", + "@deepseek-ai/dsh-invariants": "workspace:^", + "@deepseek-ai/dsh-team": "workspace:^", + "@deepseek-ai/dsh-typert-protocol": "workspace:^", + "@testing-library/react": "^16.1.0", + "@types/react": "~18.3.1", + "@deepseek-ai/cordis": "workspace:^", + "react-dom": "^18.2.0" + }, + "files": [ + "lib/index.js", + "lib/invariant.js", + "lib/client.js", + "lib/types/**/*.d.ts" + ] +} diff --git a/packages/experimental/client-ui-agent-team/src/client/TeamAction.module.css b/packages/experimental/client-ui-agent-team/src/client/TeamAction.module.css new file mode 100644 index 0000000000..8de88e2e33 --- /dev/null +++ b/packages/experimental/client-ui-agent-team/src/client/TeamAction.module.css @@ -0,0 +1,239 @@ +.root { + position: relative; +} + +.trigger, +.iconButton, +.smallButton, +.taskActions button, +.formActions button { + border: 0; + border-radius: 6px; + background: transparent; + color: var(--dsw-alias-label-secondary); + cursor: pointer; +} + +.trigger { + display: inline-flex; + align-items: center; + gap: 5px; + min-height: 28px; + padding: 3px 7px; + font-size: 12px; +} + +.trigger:hover, +.iconButton:hover, +.smallButton:hover, +.taskActions button:hover, +.formActions button:hover { + background: var(--dsw-alias-interactive-bg-hover); +} + +.count { + min-width: 16px; + border-radius: 8px; + background: var(--dsw-alias-fill-l2); + font-variant-numeric: tabular-nums; + text-align: center; +} + +.panel { + --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2); + --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2); + + position: absolute; + top: calc(100% + 5px); + left: 0; + z-index: 110; + box-sizing: border-box; + width: min(560px, calc(100vw - 32px)); + max-height: min(680px, calc(100vh - 120px)); + padding: 10px; + overflow: auto; + border: 1px solid var(--dsw-alias-border-l2); + border-radius: 12px; + background: var(--dsw-specific-menu); + box-shadow: var(--dsw-shadow-lv3); +} + +.toolbar, +.sectionTitle, +.taskTitle, +.taskActions, +.formActions { + display: flex; + align-items: center; + gap: 8px; +} + +.toolbar { + min-height: 28px; +} + +.spacer { + flex: 1; +} + +.iconButton { + display: inline-flex; + align-items: center; + justify-content: center; + width: 26px; + height: 26px; +} + +.panel h3 { + margin: 12px 0 6px; + color: var(--dsw-alias-label-secondary); + font-size: 12px; + font-weight: 500; +} + +.roster { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 6px; +} + +.member { + display: flex; + align-items: flex-start; + gap: 8px; + min-width: 0; + padding: 8px; + border: 1px solid var(--dsw-alias-border-l1); + border-radius: 8px; + background: transparent; + color: var(--dsw-alias-label-primary); + text-align: left; + cursor: pointer; +} + +.member:disabled { + cursor: default; +} + +.memberText { + display: flex; + flex-direction: column; + min-width: 0; +} + +.memberText small, +.meta { + color: var(--dsw-alias-label-tertiary); + font-size: 11px; +} + +.diagnostic, +.error, +.warning { + color: var(--dsw-alias-state-error-primary); +} + +.smallButton { + display: inline-flex; + align-items: center; + gap: 4px; + margin-left: auto; + padding: 4px 7px; + font-size: 11px; +} + +.tasks { + display: flex; + flex-direction: column; + gap: 7px; +} + +.task, +.form { + padding: 9px; + border: 1px solid var(--dsw-alias-border-l1); + border-radius: 9px; + background: var(--dsw-alias-bg-base); +} + +.taskTitle span { + margin-left: auto; + color: var(--dsw-alias-label-tertiary); + font-size: 11px; +} + +.task p { + margin: 5px 0; + color: var(--dsw-alias-label-secondary); + font-size: 12px; + white-space: pre-wrap; +} + +.meta { + display: flex; + flex-wrap: wrap; + gap: 4px 10px; +} + +.taskActions { + flex-wrap: wrap; + margin-top: 8px; +} + +.taskActions label { + display: inline-flex; + align-items: center; + gap: 4px; + color: var(--dsw-alias-label-tertiary); + font-size: 11px; +} + +.taskActions select, +.form input, +.form textarea { + box-sizing: border-box; + border: 1px solid var(--dsw-alias-border-l2); + border-radius: 6px; + background: var(--dsw-alias-bg-base); + color: var(--dsw-alias-label-primary); + font: inherit; +} + +.taskActions button, +.formActions button { + display: inline-flex; + align-items: center; + gap: 3px; + padding: 4px 6px; + font-size: 11px; +} + +.taskActions button:disabled, +.formActions button:disabled { + opacity: 0.45; + cursor: default; +} + +.form { + display: grid; + gap: 6px; + margin-bottom: 7px; +} + +.form input, +.form textarea { + width: 100%; + padding: 6px 8px; + font-size: 12px; +} + +.form textarea { + min-height: 58px; + resize: vertical; +} + +.notice, +.error { + padding: 9px; + font-size: 12px; +} diff --git a/packages/experimental/client-ui-agent-team/src/client/TeamAction.tsx b/packages/experimental/client-ui-agent-team/src/client/TeamAction.tsx new file mode 100644 index 0000000000..38e0ac6684 --- /dev/null +++ b/packages/experimental/client-ui-agent-team/src/client/TeamAction.tsx @@ -0,0 +1,433 @@ +import { useCallback, useEffect, useRef, useState, type ChangeEvent } from 'react' +import type { SessionId } from '@deepseek-ai/dsh-client-runtime/client' +import type { + TeamMemberView as TeamRosterMember, + TeamTaskAction, + TeamTaskId, + TeamTaskView as TeamTask, + TeamView, +} from '@deepseek-ai/dsh-team/client' +import { + IconCheckOutline14, IconCloseOutline16, IconEditOutline16, IconPlusOutline16, + IconRefreshOutline14, IconTrashOutline16, IconUserOutline16, StateDot, +} from '@deepseek-ai/dsh-client-ui-primitives' +import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots' +import type {} from '@deepseek-ai/dsh-client-ui-conversation/client' +import type { TeamKey } from './locales.ts' +import css from './TeamAction.module.css' + +/** Settled Team UI action result, including the stale-revision discriminator. */ +export type TeamActionResult = + | { ok: true; value: T } + | { ok: false; error: string; conflict: boolean } + +/** Business actions injected by the browser plugin. */ +export interface TeamActionInjected { + load: (sessionId: SessionId) => Promise> + createTask: (sessionId: SessionId, input: { + subject: string + description: string + blockedBy: TeamTaskId[] + writeScopes: string[] + }) => Promise> + updateTask: (sessionId: SessionId, input: { + taskId: TeamTaskId + expectedRevision: number + action: TeamTaskAction + subject?: string + description?: string + blockedBy?: TeamTaskId[] + writeScopes?: string[] + owner?: string + }) => Promise> + openTeammate: (sessionId: SessionId, member: TeamRosterMember) => Promise +} + +/** Full props of the Team conversation-header action. */ +export type TeamActionProps = + PropsRuntime<'conversation.session.header.actions'> & TeamActionInjected & PropsLocale<'team'> + +interface Draft { + subject: string + description: string + blockers: string + scopes: string +} + +const EMPTY_DRAFT: Draft = { subject: '', description: '', blockers: '', scopes: '' } + +function items(value: string): string[] { + return [...new Set(value.split(',').map(item => item.trim()).filter(Boolean))] +} + +function taskIds(value: string): TeamTaskId[] { + return items(value) as TeamTaskId[] +} + +function statusKey(status: TeamTask['status']): TeamKey { + switch (status) { + case 'pending': return 'status.pending' + case 'in_progress': return 'status.in_progress' + case 'completed': return 'status.completed' + /* v8 ignore next -- Team views omit deleted task tombstones. */ + case 'deleted': return 'status.completed' + } +} + +function loadedView(current: TeamView | null, update: (view: TeamView) => TeamView): TeamView | null { + /* v8 ignore next -- task controls and forms render only after a Team view exists. */ + if (current === null) return null + return update(current) +} + +function replaceTask(tasks: TeamTask[], task: TeamTask): TeamTask[] { + const index = tasks.findIndex(candidate => candidate.id === task.id) + /* v8 ignore next -- mutation responses preserve the requested task id. */ + if (index < 0) return tasks + return tasks.with(index, task) +} + +/** Render the live Team roster and compare-and-set task board. */ +export function TeamAction({ + sessionId, load, createTask, updateTask, openTeammate, t, +}: TeamActionProps) { + const [open, setOpen] = useState(false) + const [loading, setLoading] = useState(false) + const [view, setView] = useState(null) + const [error, setError] = useState(null) + const [creating, setCreating] = useState(false) + const [createDraft, setCreateDraft] = useState(EMPTY_DRAFT) + const [editing, setEditing] = useState(null) + const [editDraft, setEditDraft] = useState(EMPTY_DRAFT) + const [pendingTask, setPendingTask] = useState(null) + const sessionRef = useRef(sessionId) + const refreshGeneration = useRef(0) + sessionRef.current = sessionId + + useEffect(() => { + refreshGeneration.current += 1 + setOpen(false) + setLoading(false) + setView(null) + setError(null) + setCreating(false) + setCreateDraft(EMPTY_DRAFT) + setEditing(null) + setEditDraft(EMPTY_DRAFT) + setPendingTask(null) + }, [sessionId]) + + const refresh = useCallback(async (): Promise => { + const requestedSession = sessionId + const generation = ++refreshGeneration.current + setLoading(true) + const result = await load(requestedSession) + if (sessionRef.current !== requestedSession || refreshGeneration.current !== generation) return + setLoading(false) + if (result.ok) { + setView(result.value) + setError(null) + } else { + setError(result.error) + } + }, [load, sessionId]) + + const invalidateRefresh = useCallback((): void => { + refreshGeneration.current += 1 + setLoading(false) + }, []) + + const settleTask = useCallback(async ( + taskId: string, + operation: Promise>, + ): Promise => { + const requestedSession = sessionId + setPendingTask(taskId) + const result = await operation + if (sessionRef.current !== requestedSession) return undefined + setPendingTask(null) + if (!result.ok) { + if (result.conflict) { + await refresh() + if (sessionRef.current !== requestedSession) return undefined + setError(t('conflict')) + } else { + setError(result.error) + } + return undefined + } + invalidateRefresh() + setError(null) + setView(current => loadedView(current, loaded => ({ + ...loaded, + tasks: result.value.status === 'deleted' + ? loaded.tasks.filter(task => task.id !== result.value.id) + : replaceTask(loaded.tasks, result.value), + }))) + return result.value + }, [invalidateRefresh, refresh, sessionId, t]) + + const submitCreate = async (): Promise => { + const subject = createDraft.subject.trim() + const description = createDraft.description.trim() + /* v8 ignore next -- TaskForm disables Save while either normalized field is empty. */ + if (subject === '' || description === '') return + setPendingTask('create') + const requestedSession = sessionId + const result = await createTask(requestedSession, { + subject, + description, + blockedBy: taskIds(createDraft.blockers), + writeScopes: items(createDraft.scopes), + }) + if (sessionRef.current !== requestedSession) return + setPendingTask(null) + if (!result.ok) { + setError(result.error) + return + } + invalidateRefresh() + setView(current => loadedView(current, loaded => ({ + ...loaded, + tasks: [...loaded.tasks, result.value], + }))) + setCreateDraft(EMPTY_DRAFT) + setCreating(false) + setError(null) + } + + const startEdit = (task: TeamTask): void => { + setEditing(task.id) + setEditDraft({ + subject: task.subject, + description: task.description, + blockers: task.blockedBy.join(', '), + scopes: task.writeScopes.join(', '), + }) + } + + const submitEdit = async (task: TeamTask): Promise => { + const requestedSession = sessionId + const edited = await settleTask(task.id, updateTask(requestedSession, { + taskId: task.id, + expectedRevision: task.revision, + action: 'edit', + subject: editDraft.subject.trim(), + description: editDraft.description.trim(), + writeScopes: items(editDraft.scopes), + })) + if (edited === undefined) return + const blockedBy = taskIds(editDraft.blockers) + if (blockedBy.length === edited.blockedBy.length + && blockedBy.every((blocker, index) => blocker === edited.blockedBy[index])) { + setEditing(null) + return + } + setPendingTask(task.id) + const dependencyResult = await updateTask(requestedSession, { + taskId: task.id, + expectedRevision: edited.revision, + action: 'set_dependencies', + blockedBy, + }) + if (sessionRef.current !== requestedSession) return + setPendingTask(null) + if (!dependencyResult.ok) { + if (dependencyResult.conflict) { + await refresh() + if (sessionRef.current !== requestedSession) return + } + setError(dependencyResult.conflict ? t('conflict') : dependencyResult.error) + return + } + invalidateRefresh() + setView(current => loadedView(current, loaded => ({ + ...loaded, + tasks: replaceTask(loaded.tasks, dependencyResult.value), + }))) + setEditing(null) + } + + const teammates = view?.members.filter(member => member.role === 'teammate') ?? [] + const assignable = view?.members.filter(member => member.status !== 'failed' && member.status !== 'provisioning') ?? [] + + return ( +
+ + {open && ( +
+
+ {t('trigger')} + + + +
+ {error !== null &&
{error}
} + {loading && view === null &&
{t('loading')}
} + {view !== null && ( + <> +
+

{t('roster')}

+
+ {view.members.map(member => ( + + ))} +
+
+
+
+

{t('tasks')}

+ +
+ {creating && ( + { void submitCreate() }} + onCancel={() => { setCreating(false) }} + t={t} + /> + )} + {view.tasks.length === 0 && !creating &&
{t('empty')}
} +
+ {view.tasks.map(task => editing === task.id + ? ( + { void submitEdit(task) }} + onCancel={() => { setEditing(null) }} + t={t} + /> + ) + : ( +
+
+ {task.subject} + {t(statusKey(task.status))} +
+

{task.description}

+
+ {task.id} + {task.status === 'pending' && {task.ready ? t('ready') : t('blocked')}} + {task.blockedBy.length > 0 && {t('blockedBy')}: {task.blockedBy.join(', ')}} + {task.writeScopes.length > 0 && {t('writeScopes')}: {task.writeScopes.join(', ')}} + {task.writeScopeWarnings.map(warning => {warning})} +
+
+ + + {task.status === 'in_progress' && ( + + )} + {task.status === 'completed' && ( + + )} + +
+
+ ))} +
+
+ + )} +
+ )} +
+ ) +} + +interface TaskFormProps { + draft: Draft + setDraft: (draft: Draft) => void + pending: boolean + onSave: () => void + onCancel: () => void + t: TeamActionProps['t'] +} + +function TaskForm({ draft, setDraft, pending, onSave, onCancel, t }: TaskFormProps) { + const field = (key: keyof Draft, value: string): void => { setDraft({ ...draft, [key]: value }) } + return ( +
+ ) => { field('subject', event.target.value) }} /> +