From 6ec5a6136b05f308145104f404c6ff13cca22a2c Mon Sep 17 00:00:00 2001
From: Yif <877193178@qq.com>
Date: Mon, 3 Aug 2026 19:58:58 +0800
Subject: [PATCH 1/4] feat(web): show turn run time with hover-revealed time
chrome
Derive turn wall time from adjacent logged timestamps (no new session
events): the actions-owning assistant footer gains a localized
"Ran for {duration}" label, and the running TurnStatus label gains a
live elapsed clock anchored to the same logged trigger so a mid-turn
reload keeps the real elapsed time. Message time chrome is now
hover-revealed on hover-capable devices, keeping icons visible and
layout stable.
---
.../2026-08-03-web-turn-run-time.i18n.yaml | 6 ++
.../feature/2026-08-03-web-turn-run-time.md | 27 +++++++
.../2026-08-03-web-turn-run-time.zh.md | 27 +++++++
.../src/client/chat/AssistantMarkdown.tsx | 8 +-
.../src/client/chat/ChatView.module.css | 9 +++
.../src/client/chat/ChatView.tsx | 34 ++++++++-
.../client/chat/MessageIconActions.module.css | 23 +++++-
.../src/client/chat/MessageIconActions.tsx | 12 ++-
.../src/client/chat/MessageItem.tsx | 2 +-
.../src/client/chat/chat-flow.ts | 37 ++++++++++
.../src/client/chat/message-chrome.ts | 13 ++++
.../ui-conversation/src/client/locales.ts | 2 +
.../ui-conversation/tests/chat-view.spec.tsx | 73 ++++++++++++++++++-
13 files changed, 263 insertions(+), 10 deletions(-)
create mode 100644 .agents/notes/implemented/feature/2026-08-03-web-turn-run-time.i18n.yaml
create mode 100644 .agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md
create mode 100644 .agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md
diff --git a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.i18n.yaml b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.i18n.yaml
new file mode 100644
index 0000000000..c404d7797c
--- /dev/null
+++ b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.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-03-web-turn-run-time.md
+2026-08-03-web-turn-run-time.md: 456cc75279bdeeadb67f0d8a1fe7f281e3e87d30
+2026-08-03-web-turn-run-time.zh.md: a9c78997e79530047b9d5edba2cc3a1018b90f15
diff --git a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md
new file mode 100644
index 0000000000..456cc75279
--- /dev/null
+++ b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md
@@ -0,0 +1,27 @@
+# Agent Note: Web turn run time and hover-revealed time chrome
+
+Status: implemented
+
+English | [中文](2026-08-03-web-turn-run-time.zh.md)
+
+## Problem
+
+The Web chat shows when a message arrived but not how long the agent worked on it. Long turns give no live progress signal beyond the static activity label, and after the turn settles the wall time is not recoverable from the UI. Meanwhile the always-visible clock row adds visual noise to every message.
+
+## Decision
+
+Turn wall time derives from adjacent logged timestamps, with no new session events: `turnStartTimes` maps each turn to the nearest preceding user/steering node's time, and the actions-owning assistant footer renders `time - turnStart` as a `Ran for {duration}` label next to the clock. The running `TurnStatus` label gains a live elapsed clock anchored to `lastInputTime` — the same logged instant the footer measures from — so a mid-turn reload keeps the real elapsed time and the final label matches the live clock. The clock appears only after 15 seconds so short turns keep the plain label.
+
+Time chrome (clock and run time) is hover-revealed: message containers opt in with a `data-time-hover-root` attribute, and `MessageIconActions.module.css` fades the time label in on container `:hover`/`:focus-within`. The rule is scoped to `@media (hover: hover)`, so touch devices keep the always-visible label; opacity (not display) keeps the layout stable. Copy/branch icons stay always visible.
+
+## Alternatives considered
+
+**A dedicated turn-start session event.** Precise, but adds a model-invisible event type solely for UI display; the adjacent-timestamp fold matches the trajectory table's existing derivation family and needs no log change. A turn whose trigger is outside the loaded window simply omits the label.
+
+**Anchoring the live clock to component mount.** Simpler, but a mid-turn reload would restart the clock at zero and disagree with the eventual footer label. Mount time remains only the fallback when no input node is in-window.
+
+**Hiding the whole actions row until hover.** Rejected in review: copy/branch are affordances worth discovering, and row-level show/hide risks layout shift. Only the passive time text is hover-gated.
+
+## Consequences
+
+Turn duration is visible live and after settlement without new session state, and the two readings agree by construction. The run-time label is absent for turns whose triggering input fell outside the loaded window. Time chrome no longer competes with message content at rest; ARIA-tree snapshots are unaffected because the label stays in the DOM.
diff --git a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md
new file mode 100644
index 0000000000..a9c78997e7
--- /dev/null
+++ b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md
@@ -0,0 +1,27 @@
+# Agent Note: Web 轮次运行时长与悬停显示的时间附属元素
+
+Status: implemented
+
+[English](2026-08-03-web-turn-run-time.md) | 中文
+
+## 问题
+
+Web 聊天界面会显示消息的到达时间,却不显示 agent(智能体)处理这条消息花了多久。长轮次除静态活动标签外没有任何实时进度信号,轮次结束后也无法从 UI 中还原实际耗时。与此同时,始终可见的时钟行给每条消息都增加了视觉噪音。
+
+## 决策
+
+轮次实际耗时(wall time)由相邻的已记录时间戳推导,不新增任何会话事件:`turnStartTimes` 把每个轮次映射到其前方最近的用户或 steering(中途引导)节点的时间,承载操作图标的 assistant 页脚在时钟旁把 `time - turnStart` 渲染为 `Ran for {duration}` 标签。运行中的 `TurnStatus` 标签新增一个实时已用时长时钟,锚定在 `lastInputTime` 上(即页脚计时所依据的同一已记录时刻),因此轮次进行中重新加载页面仍能保留真实的已用时长,最终标签也与实时时钟一致。该时钟在 15 秒后才出现,短轮次因此仍显示不带时钟的普通标签。
+
+时钟与运行时长这类时间附属元素(time chrome)在悬停时才显示:消息容器通过 `data-time-hover-root` 属性显式启用该行为,`MessageIconActions.module.css` 在容器处于 `:hover`/`:focus-within` 时以淡入方式显示时间标签。该规则限定在 `@media (hover: hover)` 之内,触屏设备因此保持标签始终可见;显隐通过 opacity(而非 display)实现,布局保持稳定。复制与分支图标始终可见。
+
+## 考虑过的替代方案
+
+**专门的轮次开始会话事件。** 精确,但会仅为 UI 展示就新增一种模型不可见的事件类型;基于相邻时间戳的推导与轨迹表既有的推导方式属于同一族,且无需改动日志。若轮次的触发节点位于已加载窗口之外,则直接省略该标签。
+
+**将实时时钟锚定到组件挂载时刻。** 更简单,但轮次进行中重新加载会让时钟从零重新计时,并与最终的页脚标签不一致。挂载时刻仅作为窗口内没有输入节点时的回退。
+
+**将整个操作行隐藏至悬停时才显示。** 在评审中被否决:复制与分支是值得让用户发现的操作入口,而整行级别的显隐切换有布局偏移的风险。只有被动的时间文本由悬停控制显隐。
+
+## 后果
+
+轮次时长在运行中和结束后都可见,且不需要新的会话状态,两处读数在机制上必然一致。触发输入落在已加载窗口之外的轮次没有运行时长标签。未交互时,时间附属元素不再与消息内容争夺注意力;标签始终保留在 DOM 中,因此 ARIA 树快照不受影响。
diff --git a/packages/client/ui-conversation/src/client/chat/AssistantMarkdown.tsx b/packages/client/ui-conversation/src/client/chat/AssistantMarkdown.tsx
index 3f87e40e8b..de882e8bb2 100644
--- a/packages/client/ui-conversation/src/client/chat/AssistantMarkdown.tsx
+++ b/packages/client/ui-conversation/src/client/chat/AssistantMarkdown.tsx
@@ -27,6 +27,9 @@ export interface AssistantMarkdownProps {
/** Unix epoch ms for the IconActions clock; omitted while streaming or when
* the parent withholds chrome (mid-turn content assistants). */
time?: number | undefined
+ /** Turn wall time in ms for the IconActions run-time label; omitted when the
+ * turn's triggering input is outside the loaded window. */
+ runMs?: number | undefined
/** Event sequence used as the fork boundary; omitted while streaming. */
seq?: number | undefined
/** Fork the session through this finalized message's completed turn when eligible. */
@@ -79,7 +82,7 @@ function ThinkRow({ text, running, t }: { text: string; running: boolean; t: Ass
}
export const AssistantMarkdown = memo(function AssistantMarkdown({
- blocks, streaming, interrupted, time, seq, onFork, forkUnavailable, t,
+ blocks, streaming, interrupted, time, runMs, seq, onFork, forkUnavailable, t,
}: AssistantMarkdownProps) {
// Stable per locale revision (t identity changes on switch): a fresh object
// per render would rebuild MarkdownText's component table every chunk.
@@ -95,7 +98,7 @@ export const AssistantMarkdown = memo(function AssistantMarkdown({
// Footer only under settled content text; Think-only / streaming omit it.
const showActions = !streaming && time !== undefined && hasContentText(blocks)
return (
-
+
{blocks.map((block, i) => {
switch (block.kind) {
@@ -121,6 +124,7 @@ export const AssistantMarkdown = memo(function AssistantMarkdown({
{ onFork(seq) }}
branchUnavailable={forkUnavailable}
diff --git a/packages/client/ui-conversation/src/client/chat/ChatView.module.css b/packages/client/ui-conversation/src/client/chat/ChatView.module.css
index 55270946ba..3f1dd2d379 100644
--- a/packages/client/ui-conversation/src/client/chat/ChatView.module.css
+++ b/packages/client/ui-conversation/src/client/chat/ChatView.module.css
@@ -93,6 +93,15 @@
animation: dsh-turn-status-shimmer 1.8s linear infinite;
}
+.turnStatusClock {
+ margin-left: 8px;
+ font: var(--dsw-font-xs-13);
+ font-weight: 400;
+ font-variant-numeric: tabular-nums;
+ color: var(--dsw-alias-label-caption);
+ -webkit-text-fill-color: var(--dsw-alias-label-caption);
+}
+
@keyframes dsh-turn-status-shimmer {
to {
background-position: 0 0;
diff --git a/packages/client/ui-conversation/src/client/chat/ChatView.tsx b/packages/client/ui-conversation/src/client/chat/ChatView.tsx
index 076da6c6ab..bf2dc6592d 100644
--- a/packages/client/ui-conversation/src/client/chat/ChatView.tsx
+++ b/packages/client/ui-conversation/src/client/chat/ChatView.tsx
@@ -30,7 +30,7 @@ import type {
import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots'
import { IconChevronDownOutline14 } from '@deepseek-ai/dsh-client-ui-primitives'
import type { ChatViewSlotProps } from '../contract/slots.ts'
-import { assistantActionsSeqs, deriveChatFlow, messageBranchSeqs, type ChatFlowItem } from './chat-flow.ts'
+import { assistantActionsSeqs, deriveChatFlow, lastInputTime, messageBranchSeqs, turnStartTimes, type ChatFlowItem } from './chat-flow.ts'
import { AssistantMarkdown } from './AssistantMarkdown.tsx'
import { GenericCommandCard } from './GenericCommandCard.tsx'
import { GenericToolCard } from './GenericToolCard.tsx'
@@ -205,10 +205,34 @@ const CommandRow = memo(function CommandRow({ renderSlot, node, t }: {
})
/** Turn-level model activity label retained across first-token, tool, and streaming phases. */
-function TurnStatus() {
+function TurnStatus({ startTime }: {
+ /** The running turn's logged trigger time; null falls back to mount time
+ * (input node outside the window), which restarts the clock on reload. */
+ startTime: number | null
+}) {
+ const [mountedAt] = useState(() => Date.now())
+ // Anchored to the logged trigger so a mid-turn reload keeps the real
+ // elapsed time and the final footer's Ran-for label matches this clock.
+ const anchor = startTime ?? mountedAt
+ const [elapsedSeconds, setElapsedSeconds] = useState(() => Math.max(0, Math.floor((Date.now() - anchor) / 1000)))
+ useEffect(() => {
+ const tick = (): void => {
+ setElapsedSeconds(Math.max(0, Math.floor((Date.now() - anchor) / 1000)))
+ }
+ tick()
+ const id = setInterval(tick, 1000)
+ return () => { clearInterval(id) }
+ }, [anchor])
+ const minutes = Math.floor(elapsedSeconds / 60)
+ const seconds = elapsedSeconds % 60
+ const clock = minutes > 0 ? `${minutes}m ${String(seconds).padStart(2, '0')}s` : `${seconds}s`
+ // Short turns keep the plain label; the clock only appears once the turn
+ // has clearly been running for a while.
+ const showClock = elapsedSeconds >= 15
return (
Deep diving...
+ {showClock && {clock}}
)
}
@@ -259,6 +283,8 @@ export function ChatView({
// text (before tools) omits `time` so AssistantMarkdown stays chrome-free.
const actionSeqs = useMemo(() => assistantActionsSeqs(nodes), [nodes])
const branchSeqs = useMemo(() => messageBranchSeqs(nodes, turnEnds), [nodes, turnEnds])
+ const turnStarts = useMemo(() => turnStartTimes(nodes), [nodes])
+ const runningTurnStart = useMemo(() => lastInputTime(nodes), [nodes])
const listRef = useRef(null)
const atBottomRef = useRef(true)
@@ -406,6 +432,7 @@ export function ChatView({
}
const node: ConversationNode = item.node
if (node.kind === 'assistant') {
+ const turnStart = actionSeqs.has(node.seq) ? turnStarts.get(node.turn) : undefined
return (
}
+ {running && }
{pendingSteering.map(item => (
))}
diff --git a/packages/client/ui-conversation/src/client/chat/MessageIconActions.module.css b/packages/client/ui-conversation/src/client/chat/MessageIconActions.module.css
index 8a43b42f83..0e80c5ee44 100644
--- a/packages/client/ui-conversation/src/client/chat/MessageIconActions.module.css
+++ b/packages/client/ui-conversation/src/client/chat/MessageIconActions.module.css
@@ -1,5 +1,6 @@
/* Shared message IconActions row (user + assistant). Parent modules own
- layout offsets via the composed className. Always visible when mounted. */
+ layout offsets via the composed className. Icons stay visible when mounted;
+ the time label is hover-revealed inside a data-time-hover-root scope. */
.actions {
display: flex;
@@ -25,6 +26,26 @@
white-space: nowrap;
}
+/* Separator between the clock and the run-time label (time · Ran for 15s). */
+.runTimeDot {
+ margin: 0 10px;
+}
+
+/* Message containers opt in with data-time-hover-root: the time label fades
+ in on message hover (or keyboard focus within). Opacity keeps the layout
+ stable, and devices without hover keep the label always visible. */
+@media (hover: hover) {
+ [data-time-hover-root] :is(.timeStart, .timeEnd) {
+ opacity: 0;
+ transition: opacity 80ms ease;
+ }
+
+ [data-time-hover-root]:hover :is(.timeStart, .timeEnd),
+ [data-time-hover-root]:focus-within :is(.timeStart, .timeEnd) {
+ opacity: 1;
+ }
+}
+
.action {
display: inline-flex;
align-items: center;
diff --git a/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx b/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx
index 6d77d4db68..e5f80cf284 100644
--- a/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx
+++ b/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx
@@ -6,7 +6,7 @@ import {
IconBranchOutline16, IconCopyOutline16, Tooltip,
} from '@deepseek-ai/dsh-client-ui-primitives'
import type { ChatViewSlotProps } from '../contract/slots.ts'
-import { formatMessageClock, writeClipboard } from './message-chrome.ts'
+import { formatMessageClock, formatRunDuration, writeClipboard } from './message-chrome.ts'
import { useCalendarDay } from './use-calendar-day.ts'
import css from './MessageIconActions.module.css'
@@ -15,6 +15,8 @@ export interface MessageIconActionsProps {
text: string
/** Unix epoch ms for the clock label; omitted for transient messages. */
time?: number | undefined
+ /** Turn wall time in ms, appended to the clock as `· Ran for 15s`; omitted when the turn's start is unknown. */
+ runMs?: number | undefined
/** Clock before icons (user) or after (assistant). */
clock: 'start' | 'end'
/** Fork the session at this message; omission hides the branch action. */
@@ -35,7 +37,7 @@ export interface MessageIconActionsProps {
* @returns The actions row element.
*/
export function MessageIconActions({
- text, time, clock, onBranch, branchUnavailable = false, showBranch = true, className, t,
+ text, time, runMs, clock, onBranch, branchUnavailable = false, showBranch = true, className, t,
}: MessageIconActionsProps) {
const day = useCalendarDay()
const reasonId = useId()
@@ -45,6 +47,12 @@ export function MessageIconActions({
const clockEl = time === undefined ? null : (
{formatMessageClock(time, t, day)}
+ {runMs !== undefined && (
+ <>
+ ·
+ {t('message.ranFor', { duration: formatRunDuration(runMs) })}
+ >
+ )}
)
return (
diff --git a/packages/client/ui-conversation/src/client/chat/MessageItem.tsx b/packages/client/ui-conversation/src/client/chat/MessageItem.tsx
index df04ac19c2..a0bed9a38e 100644
--- a/packages/client/ui-conversation/src/client/chat/MessageItem.tsx
+++ b/packages/client/ui-conversation/src/client/chat/MessageItem.tsx
@@ -183,7 +183,7 @@ function UserStyleBubble({
const { text, rest } = contentText(content)
const truncated = (total: number): string => t('json.truncated', { total })
return (
-
+
{projectUserText(text)}
{rest.map((block, i) =>
)}
diff --git a/packages/client/ui-conversation/src/client/chat/chat-flow.ts b/packages/client/ui-conversation/src/client/chat/chat-flow.ts
index 9de9876d89..22504785ad 100644
--- a/packages/client/ui-conversation/src/client/chat/chat-flow.ts
+++ b/packages/client/ui-conversation/src/client/chat/chat-flow.ts
@@ -47,6 +47,43 @@ export function assistantActionsSeqs(nodes: readonly ConversationNode[]): Readon
return new Set(lastByTurn.values())
}
+/**
+ * Approximate turn start times: turn number -> the time of the nearest
+ * user/steering node preceding the turn's first assistant node. Same
+ * derivation family as the trajectory fold (adjacent logged timestamps, no
+ * dedicated turn/start state); a turn whose triggering input is outside the
+ * loaded window is simply absent.
+ * @param nodes - snapshot nodes in event order.
+ * @returns Unix epoch ms per in-window turn with a visible trigger.
+ */
+export function turnStartTimes(nodes: readonly ConversationNode[]): ReadonlyMap
{
+ const starts = new Map()
+ let lastInputTime: number | null = null
+ for (const node of nodes) {
+ if (node.kind === 'user' || node.kind === 'steering') {
+ lastInputTime = node.time
+ } else if (node.kind === 'assistant' && lastInputTime !== null && !starts.has(node.turn)) {
+ starts.set(node.turn, lastInputTime)
+ }
+ }
+ return starts
+}
+
+/**
+ * Time of the last user/steering node in the window: the running turn's
+ * trigger, anchoring the live TurnStatus clock to the same logged instant the
+ * finalized footer's run time is measured from.
+ * @param nodes - snapshot nodes in event order.
+ * @returns Unix epoch ms, or null when no input node is in-window.
+ */
+export function lastInputTime(nodes: readonly ConversationNode[]): number | null {
+ for (let i = nodes.length - 1; i >= 0; i--) {
+ const node = nodes[i]
+ if (node?.kind === 'user' || node?.kind === 'steering') return node.time
+ }
+ return null
+}
+
/**
* Seq set of message rows that may fork: the last transcript node of a
* completed turn, when that node owns message chrome. A later tool, reasoning,
diff --git a/packages/client/ui-conversation/src/client/chat/message-chrome.ts b/packages/client/ui-conversation/src/client/chat/message-chrome.ts
index 67b625e71d..883b371b48 100644
--- a/packages/client/ui-conversation/src/client/chat/message-chrome.ts
+++ b/packages/client/ui-conversation/src/client/chat/message-chrome.ts
@@ -71,6 +71,19 @@ export function msUntilNextLocalMidnight(ms: number): number {
return Math.max(next.getTime() - ms, 1)
}
+/**
+ * Compact elapsed-time label for the turn run-time chrome, matching the
+ * running TurnStatus clock format: `15s` under a minute, `2m 05s` from there.
+ * @param ms - Elapsed duration in milliseconds (negatives clamp to zero).
+ * @returns Display string in whole seconds.
+ */
+export function formatRunDuration(ms: number): string {
+ const total = Math.max(0, Math.round(ms / 1000))
+ const minutes = Math.floor(total / 60)
+ const seconds = total % 60
+ return minutes > 0 ? `${minutes}m ${String(seconds).padStart(2, '0')}s` : `${seconds}s`
+}
+
/**
* Compact local timestamp for message IconActions. Same calendar day →
* `HH:mm`; earlier this year → the `clock.md` date template + clock; other
diff --git a/packages/client/ui-conversation/src/client/locales.ts b/packages/client/ui-conversation/src/client/locales.ts
index 7bc01b4d95..514b11c8cb 100644
--- a/packages/client/ui-conversation/src/client/locales.ts
+++ b/packages/client/ui-conversation/src/client/locales.ts
@@ -68,6 +68,7 @@ export const zh = {
'message.retry.delay': '重试延迟:',
'message.retry.failure': '失败原因:',
'message.turnError': '本轮运行失败',
+ 'message.ranFor': '用时 {duration}',
'command.running': '执行中…',
'command.failed': '命令失败',
'command.done': '已完成',
@@ -176,6 +177,7 @@ export const en = {
'message.retry.delay': 'Retry delay: ',
'message.retry.failure': 'Failure reason: ',
'message.turnError': 'This turn failed',
+ 'message.ranFor': 'Ran for {duration}',
'command.running': 'Running…',
'command.failed': 'Command failed',
'command.done': 'Completed',
diff --git a/packages/client/ui-conversation/tests/chat-view.spec.tsx b/packages/client/ui-conversation/tests/chat-view.spec.tsx
index a041aca214..3ba0471ddb 100644
--- a/packages/client/ui-conversation/tests/chat-view.spec.tsx
+++ b/packages/client/ui-conversation/tests/chat-view.spec.tsx
@@ -20,7 +20,8 @@ import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts
import { createChatStore } from '../src/client/stores.ts'
import { ChatView } from '../src/client/chat/ChatView.tsx'
import { zh } from '../src/client/locales.ts'
-import { assistantActionsSeqs, deriveChatFlow, flowKeys, messageBranchSeqs } from '../src/client/chat/chat-flow.ts'
+import { assistantActionsSeqs, deriveChatFlow, flowKeys, lastInputTime, messageBranchSeqs, turnStartTimes } from '../src/client/chat/chat-flow.ts'
+import { formatRunDuration } from '../src/client/chat/message-chrome.ts'
afterEach(cleanup)
// Keyless create() persists under the bare declared key; clear between cases
@@ -212,6 +213,35 @@ describe('chat-flow derivation', () => {
expect([...seqs].sort((a, b) => a - b)).toEqual([5, 7])
})
+ it('turnStartTimes anchors each turn to the nearest preceding input node', () => {
+ const starts = turnStartTimes([
+ user(1, 'hi'),
+ assistant(2, 'mid', 1),
+ assistant(5, 'done', 1),
+ {
+ kind: 'steering', messageId: 'st' as never,
+ seq: 6, time: 6_000, turn: 1,
+ content: [{ type: 'text', text: 'also' }], source: null,
+ },
+ assistant(7, 'second turn', 2),
+ ])
+ expect([...starts]).toEqual([[1, 1_000], [2, 6_000]])
+ // No input in-window before the turn's first assistant: the turn is absent.
+ expect(turnStartTimes([assistant(2, 'orphan', 1)]).size).toBe(0)
+ })
+
+ it('formatRunDuration matches the running clock format', () => {
+ expect(formatRunDuration(0)).toBe('0s')
+ expect(formatRunDuration(-500)).toBe('0s')
+ expect(formatRunDuration(15_400)).toBe('15s')
+ expect(formatRunDuration(125_000)).toBe('2m 05s')
+ })
+
+ it('lastInputTime returns the trailing input node time', () => {
+ expect(lastInputTime([user(1, 'hi'), assistant(2, 'mid', 1)])).toBe(1_000)
+ expect(lastInputTime([assistant(2, 'orphan', 1)])).toBeNull()
+ })
+
it('messageBranchSeqs keeps only message rows at completed transcript tails', () => {
const interruptedThink: AssistantMessageNode = {
kind: 'assistant', seq: 4.1, time: 4_100, turn: 1, step: 2,
@@ -447,6 +477,39 @@ describe('ChatView', () => {
expect(branchButtons.map(button => button.getAttribute('aria-disabled'))).toEqual(['true', null, 'true', null])
})
+ it('the actions-owning assistant footer shows the turn run time', () => {
+ const h = makeHarness({
+ nodes: [
+ user(1, 'hi'), // time 1_000
+ assistant(2, 'mid-turn text'),
+ assistant(16, 'final answer'), // time 16_000 → 15s
+ ],
+ turnEnds: new Map([[1, 16]]),
+ })
+ const view = render()
+ // Only the turn-tail footer carries the label; mid-turn chrome stays bare.
+ expect(view.getAllByText(/用时 15s/)).toHaveLength(1)
+ })
+
+ it('user and assistant message containers scope the hover-revealed time chrome', () => {
+ const h = makeHarness({
+ nodes: [user(1, 'hi'), assistant(2, 'answer')],
+ turnEnds: new Map([[1, 2]]),
+ })
+ const view = render()
+ // One scope per message row; the CSS reveal keys off this attribute.
+ expect(view.container.querySelectorAll('[data-time-hover-root]')).toHaveLength(2)
+ })
+
+ it('the run-time label is withheld when the turn start is outside the window', () => {
+ const h = makeHarness({
+ nodes: [assistant(16, 'tail without trigger')],
+ turnEnds: new Map([[1, 16]]),
+ })
+ const view = render()
+ expect(view.queryByText(/用时/)).toBeNull()
+ })
+
it('enables fork only on the finalized assistant at the completed transcript tail', () => {
const h = makeHarness({
nodes: [user(1, 'question'), assistant(2, 'answer')],
@@ -607,6 +670,14 @@ describe('ChatView', () => {
expect(view.getByRole('status').textContent).toBe('Deep diving...')
})
+ it('the running TurnStatus clock anchors to the logged trigger time, surviving reload', () => {
+ const trigger: UserMessageNode = { ...user(1, 'go'), time: Date.now() - 125_000 }
+ const h = makeHarness({ nodes: [trigger], running: true })
+ const view = render()
+ // Freshly mounted (as after a reload) yet already past the 15s gate.
+ expect(view.getByRole('status').textContent).toMatch(/^Deep diving\.\.\.2m 0\ds$/)
+ })
+
it('dispatches each tool row through the keyed slot with the tool name as entryKey', () => {
const h = makeHarness({ nodes: [toolResult(3, 'a')] })
const calls: { key: string; entryKey?: string }[] = []
From 981315997382d8a818a47b69d308d90e880b9906 Mon Sep 17 00:00:00 2001
From: Yif <877193178@qq.com>
Date: Mon, 3 Aug 2026 19:59:00 +0800
Subject: [PATCH 2/4] test(web): refresh aria goldens for the run-time footer
label
---
apps/web/tests/snapshots/code-mode-round/ui.expected.md | 2 +-
apps/web/tests/snapshots/cordis-tool-round/ui.expected.md | 2 +-
apps/web/tests/snapshots/fresh-round-trip/ui.expected.md | 2 +-
.../web/tests/snapshots/lifecycle-chrome/reloaded.expected.md | 2 +-
apps/web/tests/snapshots/live-interactions/cancel.expected.md | 2 +-
apps/web/tests/snapshots/live-interactions/retry.expected.md | 2 +-
apps/web/tests/snapshots/markdown-images/ui.expected.md | 2 +-
apps/web/tests/snapshots/message-actions/ui.expected.md | 4 ++--
apps/web/tests/snapshots/plan-review/approved.expected.md | 2 +-
.../tests/snapshots/question-composer/answered.expected.md | 2 +-
apps/web/tests/snapshots/queue-actions/preserved.expected.md | 2 +-
.../tests/snapshots/seeded-history/command-row.expected.md | 2 +-
apps/web/tests/snapshots/seeded-history/ui.expected.md | 2 +-
apps/web/tests/snapshots/steering/settled.expected.md | 2 +-
apps/web/tests/snapshots/subagent-conversation/ui.expected.md | 4 ++--
apps/web/tests/snapshots/web-search-round/ui.expected.md | 2 +-
16 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/apps/web/tests/snapshots/code-mode-round/ui.expected.md b/apps/web/tests/snapshots/code-mode-round/ui.expected.md
index c6799a2247..42758237bb 100644
--- a/apps/web/tests/snapshots/code-mode-round/ui.expected.md
+++ b/apps/web/tests/snapshots/code-mode-round/ui.expected.md
@@ -36,7 +36,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/cordis-tool-round/ui.expected.md b/apps/web/tests/snapshots/cordis-tool-round/ui.expected.md
index fc6d312821..85ef8932b2 100644
--- a/apps/web/tests/snapshots/cordis-tool-round/ui.expected.md
+++ b/apps/web/tests/snapshots/cordis-tool-round/ui.expected.md
@@ -51,7 +51,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/fresh-round-trip/ui.expected.md b/apps/web/tests/snapshots/fresh-round-trip/ui.expected.md
index 17df480cd9..159e77d5bc 100644
--- a/apps/web/tests/snapshots/fresh-round-trip/ui.expected.md
+++ b/apps/web/tests/snapshots/fresh-round-trip/ui.expected.md
@@ -31,7 +31,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/lifecycle-chrome/reloaded.expected.md b/apps/web/tests/snapshots/lifecycle-chrome/reloaded.expected.md
index 5e0b4f73bb..f6f965337e 100644
--- a/apps/web/tests/snapshots/lifecycle-chrome/reloaded.expected.md
+++ b/apps/web/tests/snapshots/lifecycle-chrome/reloaded.expected.md
@@ -23,7 +23,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/live-interactions/cancel.expected.md b/apps/web/tests/snapshots/live-interactions/cancel.expected.md
index d18e061a1a..cd06310db0 100644
--- a/apps/web/tests/snapshots/live-interactions/cancel.expected.md
+++ b/apps/web/tests/snapshots/live-interactions/cancel.expected.md
@@ -20,7 +20,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/live-interactions/retry.expected.md b/apps/web/tests/snapshots/live-interactions/retry.expected.md
index d5df08c05e..5f834e15f0 100644
--- a/apps/web/tests/snapshots/live-interactions/retry.expected.md
+++ b/apps/web/tests/snapshots/live-interactions/retry.expected.md
@@ -25,7 +25,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/markdown-images/ui.expected.md b/apps/web/tests/snapshots/markdown-images/ui.expected.md
index 58b72e0d65..0f261e5474 100644
--- a/apps/web/tests/snapshots/markdown-images/ui.expected.md
+++ b/apps/web/tests/snapshots/markdown-images/ui.expected.md
@@ -19,7 +19,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/message-actions/ui.expected.md b/apps/web/tests/snapshots/message-actions/ui.expected.md
index 3d085b0931..0554b95404 100644
--- a/apps/web/tests/snapshots/message-actions/ui.expected.md
+++ b/apps/web/tests/snapshots/message-actions/ui.expected.md
@@ -20,7 +20,7 @@
- img
- button "Branch into a new conversation" [disabled]:
- img
-- text: Available only on the last message of a completed turn 7/25 {{clock}}
+- text: Available only on the last message of a completed turn 7/25 {{clock}}Ran for {{duration}}
- button "Read a.txt":
- img
- img
@@ -46,7 +46,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: 7/25 {{clock}}
+- text: 7/25 {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/plan-review/approved.expected.md b/apps/web/tests/snapshots/plan-review/approved.expected.md
index 108ca47986..2120c32408 100644
--- a/apps/web/tests/snapshots/plan-review/approved.expected.md
+++ b/apps/web/tests/snapshots/plan-review/approved.expected.md
@@ -36,7 +36,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/question-composer/answered.expected.md b/apps/web/tests/snapshots/question-composer/answered.expected.md
index 7fdddfa8a8..a54b7dcd75 100644
--- a/apps/web/tests/snapshots/question-composer/answered.expected.md
+++ b/apps/web/tests/snapshots/question-composer/answered.expected.md
@@ -31,7 +31,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/queue-actions/preserved.expected.md b/apps/web/tests/snapshots/queue-actions/preserved.expected.md
index 74de289ee9..2ce0077a2e 100644
--- a/apps/web/tests/snapshots/queue-actions/preserved.expected.md
+++ b/apps/web/tests/snapshots/queue-actions/preserved.expected.md
@@ -20,7 +20,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}} Edited queue item {{clock}}
+- text: {{clock}}Ran for {{duration}} Edited queue item {{clock}}
- button "Copy":
- img
- button "Branch into a new conversation" [disabled]:
diff --git a/apps/web/tests/snapshots/seeded-history/command-row.expected.md b/apps/web/tests/snapshots/seeded-history/command-row.expected.md
index b4eddfc24e..d638821c45 100644
--- a/apps/web/tests/snapshots/seeded-history/command-row.expected.md
+++ b/apps/web/tests/snapshots/seeded-history/command-row.expected.md
@@ -33,7 +33,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: 7/25 {{clock}}
+- text: 7/25 {{clock}}Ran for {{duration}}
- button "Context compacted View compaction summary":
- img
- text: Context compacted View compaction summary
diff --git a/apps/web/tests/snapshots/seeded-history/ui.expected.md b/apps/web/tests/snapshots/seeded-history/ui.expected.md
index 4643c60f3b..9e78cca0f8 100644
--- a/apps/web/tests/snapshots/seeded-history/ui.expected.md
+++ b/apps/web/tests/snapshots/seeded-history/ui.expected.md
@@ -33,7 +33,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: 7/25 {{clock}}
+- text: 7/25 {{clock}}Ran for {{duration}}
- button "Context compacted View compaction summary":
- img
- text: Context compacted View compaction summary
diff --git a/apps/web/tests/snapshots/steering/settled.expected.md b/apps/web/tests/snapshots/steering/settled.expected.md
index 4d8d35a085..00f1b33206 100644
--- a/apps/web/tests/snapshots/steering/settled.expected.md
+++ b/apps/web/tests/snapshots/steering/settled.expected.md
@@ -37,7 +37,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/subagent-conversation/ui.expected.md b/apps/web/tests/snapshots/subagent-conversation/ui.expected.md
index 9497cc36d3..561277b8ee 100644
--- a/apps/web/tests/snapshots/subagent-conversation/ui.expected.md
+++ b/apps/web/tests/snapshots/subagent-conversation/ui.expected.md
@@ -28,7 +28,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}} Now give the same explanation to a human reader. {{clock}}
+- text: {{clock}}Ran for {{duration}} Now give the same explanation to a human reader. {{clock}}
- button "Copy":
- img
- button "Branch into a new conversation" [disabled]:
@@ -43,7 +43,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
diff --git a/apps/web/tests/snapshots/web-search-round/ui.expected.md b/apps/web/tests/snapshots/web-search-round/ui.expected.md
index 97ca405141..45098769f7 100644
--- a/apps/web/tests/snapshots/web-search-round/ui.expected.md
+++ b/apps/web/tests/snapshots/web-search-round/ui.expected.md
@@ -23,7 +23,7 @@
- img
- button "Branch into a new conversation":
- img
-- text: {{clock}}
+- text: {{clock}}Ran for {{duration}}
- textbox "Message the agent"
- button "Commands":
- img
From cc435a9c0c5b0f6124a26827977fb4adb4c5795b Mon Sep 17 00:00:00 2001
From: imccyu
Date: Tue, 4 Aug 2026 15:55:07 +0800
Subject: [PATCH 3/4] fix(web): use exact turn boundaries for run time
---
.../2026-08-03-web-turn-run-time.i18n.yaml | 4 +-
.../feature/2026-08-03-web-turn-run-time.md | 10 +--
.../2026-08-03-web-turn-run-time.zh.md | 10 +--
.../src/client/sessions/conversation.ts | 2 +
.../runtime/src/client/sessions/session.ts | 18 +++++
packages/client/runtime/tests/session.spec.ts | 11 +++
packages/client/test-runtime/src/fixtures.ts | 1 +
.../src/client/chat/ChatView.tsx | 40 +++++-----
.../src/client/chat/MessageIconActions.tsx | 2 +-
.../src/client/chat/chat-flow.ts | 44 +++--------
.../src/client/chat/message-chrome.ts | 15 ++--
.../ui-conversation/src/client/locales.ts | 4 +
.../tests/chat-code-subcalls.spec.tsx | 2 +-
.../tests/chat-stats-bash-sample.spec.tsx | 2 +-
.../ui-conversation/tests/chat-view.spec.tsx | 75 ++++++++++---------
.../ui-conversation/tests/diff-card.spec.tsx | 2 +-
.../tests/gate-branch-tails.spec.tsx | 2 +-
.../ui-conversation/tests/input-bar.spec.tsx | 2 +-
.../tests/input-matrix.spec.tsx | 2 +-
.../tests/input-scenarios.spec.tsx | 2 +-
.../ui-conversation/tests/queue-dock.spec.tsx | 2 +-
.../ui-conversation/tests/read-card.spec.tsx | 2 +-
.../tests/search-card.spec.tsx | 2 +-
.../ui-conversation/tests/skeleton.spec.tsx | 2 +-
.../tests/terminal-card.spec.tsx | 2 +-
.../ui-conversation/tests/web-card.spec.tsx | 2 +-
26 files changed, 146 insertions(+), 116 deletions(-)
diff --git a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.i18n.yaml b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.i18n.yaml
index c404d7797c..ea99a814e6 100644
--- a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.i18n.yaml
+++ b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.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-03-web-turn-run-time.md
-2026-08-03-web-turn-run-time.md: 456cc75279bdeeadb67f0d8a1fe7f281e3e87d30
-2026-08-03-web-turn-run-time.zh.md: a9c78997e79530047b9d5edba2cc3a1018b90f15
+2026-08-03-web-turn-run-time.md: b6e79b34f45ebe46d9ce752b6333cdfce6fc4dd6
+2026-08-03-web-turn-run-time.zh.md: 73d9be4d2119278f8a78c6858bae353a4ef5d62f
diff --git a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md
index 456cc75279..b6e79b34f4 100644
--- a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md
+++ b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.md
@@ -10,18 +10,18 @@ The Web chat shows when a message arrived but not how long the agent worked on i
## Decision
-Turn wall time derives from adjacent logged timestamps, with no new session events: `turnStartTimes` maps each turn to the nearest preceding user/steering node's time, and the actions-owning assistant footer renders `time - turnStart` as a `Ran for {duration}` label next to the clock. The running `TurnStatus` label gains a live elapsed clock anchored to `lastInputTime` — the same logged instant the footer measures from — so a mid-turn reload keeps the real elapsed time and the final label matches the live clock. The clock appears only after 15 seconds so short turns keep the plain label.
+Turn wall time uses the existing logged `turn/start` and `turn/end` timestamps, with no new session events. The client Session folds each in-window pair into `turnTimings`; the actions-owning assistant footer renders `endTime - startTime` as a localized `Ran for {duration}` label after the turn ends. The running `TurnStatus` clock uses the latest timing without an end, so reload preserves elapsed time, steering does not reset it, and a retry starts from its own logged boundary. Both readings use the same localized formatter and whole-second floor. The clock appears only after 15 seconds and is hidden from the live region so screen readers announce the activity status without replaying every tick.
Time chrome (clock and run time) is hover-revealed: message containers opt in with a `data-time-hover-root` attribute, and `MessageIconActions.module.css` fades the time label in on container `:hover`/`:focus-within`. The rule is scoped to `@media (hover: hover)`, so touch devices keep the always-visible label; opacity (not display) keeps the layout stable. Copy/branch icons stay always visible.
## Alternatives considered
-**A dedicated turn-start session event.** Precise, but adds a model-invisible event type solely for UI display; the adjacent-timestamp fold matches the trajectory table's existing derivation family and needs no log change. A turn whose trigger is outside the loaded window simply omits the label.
+**Deriving timing from message nodes.** The nearest user or steering timestamp is available in the rendered transcript, but it mismeasures retry turns and lets mid-turn steering reset the live clock. Existing turn boundary events provide the authoritative timestamps without changing the log format.
-**Anchoring the live clock to component mount.** Simpler, but a mid-turn reload would restart the clock at zero and disagree with the eventual footer label. Mount time remains only the fallback when no input node is in-window.
+**Anchoring the live clock to component mount.** Simpler, but a mid-turn reload would restart the clock at zero and disagree with the eventual footer label. Mount time remains only the fallback when `turn/start` is outside the loaded window.
-**Hiding the whole actions row until hover.** Rejected in review: copy/branch are affordances worth discovering, and row-level show/hide risks layout shift. Only the passive time text is hover-gated.
+**Hiding the whole actions row until hover.** Copy and branch are affordances worth discovering, and row-level show/hide risks layout shift. Only the passive time text is hover-gated.
## Consequences
-Turn duration is visible live and after settlement without new session state, and the two readings agree by construction. The run-time label is absent for turns whose triggering input fell outside the loaded window. Time chrome no longer competes with message content at rest; ARIA-tree snapshots are unaffected because the label stays in the DOM.
+Turn duration is visible live and after settlement without new session events, and both readings share exact log boundaries and formatting. The settled duration includes activity after the last assistant text up to `turn/end`; the label is absent when `turn/start` is outside the loaded window. Time chrome no longer competes with message content at rest, and the ticking clock remains visual rather than repeatedly announced.
diff --git a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md
index a9c78997e7..73d9be4d21 100644
--- a/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md
+++ b/.agents/notes/implemented/feature/2026-08-03-web-turn-run-time.zh.md
@@ -10,18 +10,18 @@ Web 聊天界面会显示消息的到达时间,却不显示 agent(智能体
## 决策
-轮次实际耗时(wall time)由相邻的已记录时间戳推导,不新增任何会话事件:`turnStartTimes` 把每个轮次映射到其前方最近的用户或 steering(中途引导)节点的时间,承载操作图标的 assistant 页脚在时钟旁把 `time - turnStart` 渲染为 `Ran for {duration}` 标签。运行中的 `TurnStatus` 标签新增一个实时已用时长时钟,锚定在 `lastInputTime` 上(即页脚计时所依据的同一已记录时刻),因此轮次进行中重新加载页面仍能保留真实的已用时长,最终标签也与实时时钟一致。该时钟在 15 秒后才出现,短轮次因此仍显示不带时钟的普通标签。
+轮次实际耗时(wall time)采用日志中已有的 `turn/start` 和 `turn/end` 时间戳,不新增任何会话事件。客户端 Session 将加载窗口内的每对边界归并到 `turnTimings` 中;轮次结束后,承载操作图标的 assistant 页脚把 `endTime - startTime` 渲染为本地化的 `Ran for {duration}` 标签。运行中的 `TurnStatus` 时钟采用最新一条没有结束时间的计时记录,因此重新加载会保留已用时长,steering(中途引导)不会重置计时,重试也从自身的日志边界开始。两处读数共用同一个本地化格式化器,并向下取整到整秒。该时钟在 15 秒后才出现,并从实时区域中隐藏,因此屏幕阅读器会播报活动状态而不会重复播报每次时钟跳动。
时钟与运行时长这类时间附属元素(time chrome)在悬停时才显示:消息容器通过 `data-time-hover-root` 属性显式启用该行为,`MessageIconActions.module.css` 在容器处于 `:hover`/`:focus-within` 时以淡入方式显示时间标签。该规则限定在 `@media (hover: hover)` 之内,触屏设备因此保持标签始终可见;显隐通过 opacity(而非 display)实现,布局保持稳定。复制与分支图标始终可见。
## 考虑过的替代方案
-**专门的轮次开始会话事件。** 精确,但会仅为 UI 展示就新增一种模型不可见的事件类型;基于相邻时间戳的推导与轨迹表既有的推导方式属于同一族,且无需改动日志。若轮次的触发节点位于已加载窗口之外,则直接省略该标签。
+**从消息节点推导计时。** 渲染后的 transcript(文本记录)中可以取得最近的用户或 steering 时间戳,但这会错误计算重试轮次,并让轮次中途的 steering 重置实时时钟。已有的轮次边界事件无需改变日志格式即可提供权威时间戳。
-**将实时时钟锚定到组件挂载时刻。** 更简单,但轮次进行中重新加载会让时钟从零重新计时,并与最终的页脚标签不一致。挂载时刻仅作为窗口内没有输入节点时的回退。
+**将实时时钟锚定到组件挂载时刻。** 更简单,但轮次进行中重新加载会让时钟从零重新计时,并与最终的页脚标签不一致。仅当 `turn/start` 位于已加载窗口之外时,才回退到挂载时刻。
-**将整个操作行隐藏至悬停时才显示。** 在评审中被否决:复制与分支是值得让用户发现的操作入口,而整行级别的显隐切换有布局偏移的风险。只有被动的时间文本由悬停控制显隐。
+**将整个操作行隐藏至悬停时才显示。** 复制与分支是值得让用户发现的操作入口,而整行级别的显隐切换有布局偏移的风险。只有被动的时间文本由悬停控制显隐。
## 后果
-轮次时长在运行中和结束后都可见,且不需要新的会话状态,两处读数在机制上必然一致。触发输入落在已加载窗口之外的轮次没有运行时长标签。未交互时,时间附属元素不再与消息内容争夺注意力;标签始终保留在 DOM 中,因此 ARIA 树快照不受影响。
+轮次时长在运行中和结束后都可见,且不需要新的会话事件;两处读数共用精确的日志边界和格式化方式。结束后的时长包括最后一条 assistant 文本之后、直至 `turn/end` 的活动;若 `turn/start` 位于已加载窗口之外,则不显示标签。未交互时,时间附属元素不再与消息内容争夺注意力,持续跳动的时钟也只保留视觉呈现,不会被重复播报。
diff --git a/packages/client/runtime/src/client/sessions/conversation.ts b/packages/client/runtime/src/client/sessions/conversation.ts
index 46cc5b0391..c4e195bc88 100644
--- a/packages/client/runtime/src/client/sessions/conversation.ts
+++ b/packages/client/runtime/src/client/sessions/conversation.ts
@@ -331,6 +331,8 @@ export interface ConversationSnapshot {
sessionId: SessionId
/** Human transcript plus retry notices and interrupted-turn terminal nodes in event order. */
nodes: readonly ConversationNode[]
+ /** Exact in-window `turn/start` time and optional matching `turn/end` time. */
+ turnTimings: ReadonlyMap
/** In-window completed turn number -> its `turn/end` event seq. */
turnEnds: ReadonlyMap
partial: PartialAssistant | null
diff --git a/packages/client/runtime/src/client/sessions/session.ts b/packages/client/runtime/src/client/sessions/session.ts
index c4cc1d2b5b..65e10a9026 100644
--- a/packages/client/runtime/src/client/sessions/session.ts
+++ b/packages/client/runtime/src/client/sessions/session.ts
@@ -113,6 +113,11 @@ export class Session implements SessionFace {
private pendingCache: { rev: number; value: PendingInteraction[] } | null = null
private derivedRev = 0
private nodesCache: { projected: readonly ConversationNode[]; derivedRev: number; value: readonly ConversationNode[] } | null = null
+ /** Exact turn timing retained from the raw window so presentation never
+ * infers elapsed time from transcript content. */
+ private turnTimings = new Map()
+ private turnTimingsRev = 0
+ private turnTimingsCache: { rev: number; value: ConversationSnapshot['turnTimings'] } | null = null
/** Completed turn boundaries retained from the raw window so presentation
* actions never infer a safe fork point from transcript content alone. */
private turnEnds = new Map()
@@ -799,6 +804,8 @@ export class Session implements SessionFace {
}
switch (event.type) {
case 'turn/start': {
+ this.turnTimings.set(event.data.turn, { startTime: event.time })
+ this.turnTimingsRev++
if (event.data.trigger.kind === 'retry') this.settleScheduledRetry('started')
return
}
@@ -830,6 +837,11 @@ export class Session implements SessionFace {
return
}
case 'turn/end': {
+ const timing = this.turnTimings.get(event.data.turn)
+ if (timing !== undefined) {
+ this.turnTimings.set(event.data.turn, { ...timing, endTime: event.time })
+ this.turnTimingsRev++
+ }
this.turnEnds.set(event.data.turn, event.seq)
this.turnEndsRev++
if (event.data.reason.kind === 'aborted' || event.data.reason.kind === 'disposed') {
@@ -922,6 +934,8 @@ export class Session implements SessionFace {
this.callsRev++
this.derivedNodes = []
this.derivedRev++
+ this.turnTimings = new Map()
+ this.turnTimingsRev++
this.turnEnds = new Map()
this.turnEndsRev++
this.codeDispatches = new Map()
@@ -955,6 +969,9 @@ export class Session implements SessionFace {
if (this.callsCache === null || this.callsCache.rev !== this.callsRev) {
this.callsCache = { rev: this.callsRev, value: [...this.openCalls.values()] }
}
+ if (this.turnTimingsCache === null || this.turnTimingsCache.rev !== this.turnTimingsRev) {
+ this.turnTimingsCache = { rev: this.turnTimingsRev, value: new Map(this.turnTimings) }
+ }
if (this.turnEndsCache === null || this.turnEndsCache.rev !== this.turnEndsRev) {
this.turnEndsCache = { rev: this.turnEndsRev, value: new Map(this.turnEnds) }
}
@@ -971,6 +988,7 @@ export class Session implements SessionFace {
return {
sessionId: this.sessionId,
nodes,
+ turnTimings: this.turnTimingsCache.value,
turnEnds: this.turnEndsCache.value,
partial,
runningCalls: this.callsCache.value,
diff --git a/packages/client/runtime/tests/session.spec.ts b/packages/client/runtime/tests/session.spec.ts
index 26743e23ab..b47a70edec 100644
--- a/packages/client/runtime/tests/session.spec.ts
+++ b/packages/client/runtime/tests/session.spec.ts
@@ -46,6 +46,11 @@ describe('open', () => {
expect(snapshot.openState).toBe('open')
expect(snapshot.hasMore).toBe(true)
expect(snapshot.nodes.map(n => n.kind)).toEqual(['user', 'assistant'])
+ expect(snapshot.turnTimings.get(3)).toEqual({
+ startTime: 1_700_000_000_010,
+ endTime: 1_700_000_000_015,
+ })
+ expect(snapshot.turnEnds.get(3)).toBe(15)
})
it('is idempotent: concurrent opens share one history call, reopening when open is a no-op', async () => {
@@ -253,11 +258,16 @@ describe('live event path', () => {
expect(snapshot.nodes.some(node => node.kind === 'turn-error')).toBe(false)
expect(snapshot.nodes.at(-2)).toMatchObject({ kind: 'model-retry', retryState: 'started' })
expect(snapshot.nodes.at(-1)).toMatchObject({ kind: 'assistant', blocks: [{ kind: 'text', text: '完整回复' }] })
+ expect([...snapshot.turnTimings]).toEqual([
+ [1, { startTime: 1_700_000_000_006, endTime: 1_700_000_000_013 }],
+ [2, { startTime: 1_700_000_000_014, endTime: 1_700_000_000_018 }],
+ ])
const replay = makeSession()
replay.api.onHistory = () => histResponse([...plainTurn(0, 0, 'a', 'b'), ...retryTurn])
await replay.session.open()
expect(replay.session.getSnapshot().nodes).toEqual(snapshot.nodes)
+ expect(replay.session.getSnapshot().turnTimings).toEqual(snapshot.turnTimings)
expect(replay.session.getSnapshot().partial).toBeNull()
})
@@ -1254,6 +1264,7 @@ describe('reference stability (the memo contract)', () => {
expect(after).not.toBe(before)
expect(after.runningCalls).toBe(before.runningCalls)
expect(after.pending).toBe(before.pending)
+ expect(after.turnTimings).toBe(before.turnTimings)
expect(after.turnEnds).toBe(before.turnEnds)
// And a mutation on the tracked domain swaps that array.
feed(ev.toolResult(11, 1, 'c1', 'ECHO'))
diff --git a/packages/client/test-runtime/src/fixtures.ts b/packages/client/test-runtime/src/fixtures.ts
index d033669215..9cf025192c 100644
--- a/packages/client/test-runtime/src/fixtures.ts
+++ b/packages/client/test-runtime/src/fixtures.ts
@@ -46,6 +46,7 @@ export function conversationSnapshot(sessionId: SessionId): ConversationSnapshot
return {
sessionId,
nodes: [],
+ turnTimings: new Map(),
turnEnds: new Map(),
partial: null,
runningCalls: [],
diff --git a/packages/client/ui-conversation/src/client/chat/ChatView.tsx b/packages/client/ui-conversation/src/client/chat/ChatView.tsx
index 702d40857c..3320eb0f69 100644
--- a/packages/client/ui-conversation/src/client/chat/ChatView.tsx
+++ b/packages/client/ui-conversation/src/client/chat/ChatView.tsx
@@ -30,11 +30,12 @@ import type {
import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots'
import { IconChevronDownOutline14 } from '@deepseek-ai/dsh-client-ui-primitives'
import type { ChatViewSlotProps } from '../contract/slots.ts'
-import { assistantActionsSeqs, deriveChatFlow, lastInputTime, messageBranchSeqs, turnStartTimes, type ChatFlowItem } from './chat-flow.ts'
+import { assistantActionsSeqs, deriveChatFlow, messageBranchSeqs, runningTurnStartTime, type ChatFlowItem } from './chat-flow.ts'
import { AssistantMarkdown } from './AssistantMarkdown.tsx'
import { GenericCommandCard } from './GenericCommandCard.tsx'
import { GenericToolCard } from './GenericToolCard.tsx'
import { MessageItem, PendingSteeringBubble } from './MessageItem.tsx'
+import { formatRunDuration } from './message-chrome.ts'
import css from './ChatView.module.css'
const FOLLOW_THRESHOLD = 24
@@ -282,34 +283,37 @@ const CommandRow = memo(function CommandRow({ renderSlot, node, t }: {
})
/** Turn-level model activity label retained across first-token, tool, and streaming phases. */
-function TurnStatus({ startTime }: {
- /** The running turn's logged trigger time; null falls back to mount time
- * (input node outside the window), which restarts the clock on reload. */
+function TurnStatus({ startTime, t }: {
+ /** The running turn's logged `turn/start` time; null falls back to mount
+ * time when that boundary is outside the window. */
startTime: number | null
+ /** The owning view's locale seat. */
+ t: ChatViewSlotProps['t']
}) {
const [mountedAt] = useState(() => Date.now())
- // Anchored to the logged trigger so a mid-turn reload keeps the real
+ // Anchored to turn/start so a mid-turn reload keeps the real
// elapsed time and the final footer's Ran-for label matches this clock.
const anchor = startTime ?? mountedAt
- const [elapsedSeconds, setElapsedSeconds] = useState(() => Math.max(0, Math.floor((Date.now() - anchor) / 1000)))
+ const [elapsedMs, setElapsedMs] = useState(() => Math.max(0, Date.now() - anchor))
useEffect(() => {
const tick = (): void => {
- setElapsedSeconds(Math.max(0, Math.floor((Date.now() - anchor) / 1000)))
+ setElapsedMs(Math.max(0, Date.now() - anchor))
}
tick()
const id = setInterval(tick, 1000)
return () => { clearInterval(id) }
}, [anchor])
- const minutes = Math.floor(elapsedSeconds / 60)
- const seconds = elapsedSeconds % 60
- const clock = minutes > 0 ? `${minutes}m ${String(seconds).padStart(2, '0')}s` : `${seconds}s`
// Short turns keep the plain label; the clock only appears once the turn
// has clearly been running for a while.
- const showClock = elapsedSeconds >= 15
+ const showClock = elapsedMs >= 15_000
return (
Deep diving...
- {showClock && {clock}}
+ {showClock && (
+
+ {formatRunDuration(elapsedMs, t)}
+
+ )}
)
}
@@ -333,6 +337,7 @@ export function ChatView({
useSession, useSessions, useStore, renderSlot, sessionId, openFile, loadOlder, inspectCall, chatScroll, forkAt, t,
}: ChatViewSlotProps) {
const nodes = useSession(s => s.nodes)
+ const turnTimings = useSession(s => s.turnTimings)
const turnEnds = useSession(s => s.turnEnds)
const inbox = useSession(s => s.queue)
// Workspace root off the session list row: path summaries display relative to it.
@@ -356,8 +361,7 @@ export function ChatView({
// text (before tools) omits `time` so AssistantMarkdown stays chrome-free.
const actionSeqs = useMemo(() => assistantActionsSeqs(nodes), [nodes])
const branchSeqs = useMemo(() => messageBranchSeqs(nodes, turnEnds), [nodes, turnEnds])
- const turnStarts = useMemo(() => turnStartTimes(nodes), [nodes])
- const runningTurnStart = useMemo(() => lastInputTime(nodes), [nodes])
+ const runningTurnStart = useMemo(() => runningTurnStartTime(turnTimings), [turnTimings])
const listRef = useRef(null)
const columnRef = useRef(null)
@@ -594,14 +598,16 @@ export function ChatView({
}
const node: ConversationNode = item.node
if (node.kind === 'assistant') {
- const turnStart = actionSeqs.has(node.seq) ? turnStarts.get(node.turn) : undefined
+ const timing = actionSeqs.has(node.seq) ? turnTimings.get(node.turn) : undefined
return (
}
+ {running && }
{pendingSteering.map(item => (
))}
diff --git a/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx b/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx
index e5f80cf284..a2c1459875 100644
--- a/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx
+++ b/packages/client/ui-conversation/src/client/chat/MessageIconActions.tsx
@@ -50,7 +50,7 @@ export function MessageIconActions({
{runMs !== undefined && (
<>
·
- {t('message.ranFor', { duration: formatRunDuration(runMs) })}
+ {t('message.ranFor', { duration: formatRunDuration(runMs, t) })}
>
)}
diff --git a/packages/client/ui-conversation/src/client/chat/chat-flow.ts b/packages/client/ui-conversation/src/client/chat/chat-flow.ts
index 22504785ad..2fc2a82a69 100644
--- a/packages/client/ui-conversation/src/client/chat/chat-flow.ts
+++ b/packages/client/ui-conversation/src/client/chat/chat-flow.ts
@@ -9,7 +9,7 @@
* flow share their gates.
*/
import type {
- AssistantBlock, ConversationNode, ToolResultNode,
+ AssistantBlock, ConversationNode, ConversationSnapshot, ToolResultNode,
} from '@deepseek-ai/dsh-client-runtime/client'
/** One renderable flow item; key is the React key and the parent's identity unit. */
@@ -48,40 +48,18 @@ export function assistantActionsSeqs(nodes: readonly ConversationNode[]): Readon
}
/**
- * Approximate turn start times: turn number -> the time of the nearest
- * user/steering node preceding the turn's first assistant node. Same
- * derivation family as the trajectory fold (adjacent logged timestamps, no
- * dedicated turn/start state); a turn whose triggering input is outside the
- * loaded window is simply absent.
- * @param nodes - snapshot nodes in event order.
- * @returns Unix epoch ms per in-window turn with a visible trigger.
+ * Exact start time of the latest in-window turn without a matching end time.
+ * @param turnTimings - In-window turn timings in event order.
+ * @returns Unix epoch ms, or null when the running turn started outside the window.
*/
-export function turnStartTimes(nodes: readonly ConversationNode[]): ReadonlyMap {
- const starts = new Map()
- let lastInputTime: number | null = null
- for (const node of nodes) {
- if (node.kind === 'user' || node.kind === 'steering') {
- lastInputTime = node.time
- } else if (node.kind === 'assistant' && lastInputTime !== null && !starts.has(node.turn)) {
- starts.set(node.turn, lastInputTime)
- }
+export function runningTurnStartTime(
+ turnTimings: ConversationSnapshot['turnTimings'],
+): number | null {
+ let latest: number | null = null
+ for (const timing of turnTimings.values()) {
+ if (timing.endTime === undefined) latest = timing.startTime
}
- return starts
-}
-
-/**
- * Time of the last user/steering node in the window: the running turn's
- * trigger, anchoring the live TurnStatus clock to the same logged instant the
- * finalized footer's run time is measured from.
- * @param nodes - snapshot nodes in event order.
- * @returns Unix epoch ms, or null when no input node is in-window.
- */
-export function lastInputTime(nodes: readonly ConversationNode[]): number | null {
- for (let i = nodes.length - 1; i >= 0; i--) {
- const node = nodes[i]
- if (node?.kind === 'user' || node?.kind === 'steering') return node.time
- }
- return null
+ return latest
}
/**
diff --git a/packages/client/ui-conversation/src/client/chat/message-chrome.ts b/packages/client/ui-conversation/src/client/chat/message-chrome.ts
index 883b371b48..a125355a27 100644
--- a/packages/client/ui-conversation/src/client/chat/message-chrome.ts
+++ b/packages/client/ui-conversation/src/client/chat/message-chrome.ts
@@ -6,6 +6,9 @@ import type { Translate } from '@deepseek-ai/dsh-client-ui-slots'
/** The date-template share of the conversation dictionary the clock consumes. */
export type ClockTranslate = Translate<'clock.md' | 'clock.ymd'>
+/** The elapsed-duration share of the conversation dictionary. */
+export type RunDurationTranslate = Translate<'duration.seconds' | 'duration.minutes'>
+
/**
* Best-effort clipboard write; rejections stay swallowed (no success chrome).
* @param text - Plain text to place on the clipboard.
@@ -72,16 +75,18 @@ export function msUntilNextLocalMidnight(ms: number): number {
}
/**
- * Compact elapsed-time label for the turn run-time chrome, matching the
- * running TurnStatus clock format: `15s` under a minute, `2m 05s` from there.
+ * Localized elapsed-time label shared by running and settled turn chrome.
* @param ms - Elapsed duration in milliseconds (negatives clamp to zero).
+ * @param t - Translate seat supplying the duration templates.
* @returns Display string in whole seconds.
*/
-export function formatRunDuration(ms: number): string {
- const total = Math.max(0, Math.round(ms / 1000))
+export function formatRunDuration(ms: number, t: RunDurationTranslate): string {
+ const total = Math.max(0, Math.floor(ms / 1000))
const minutes = Math.floor(total / 60)
const seconds = total % 60
- return minutes > 0 ? `${minutes}m ${String(seconds).padStart(2, '0')}s` : `${seconds}s`
+ return minutes > 0
+ ? t('duration.minutes', { minutes, seconds: String(seconds).padStart(2, '0') })
+ : t('duration.seconds', { seconds })
}
/**
diff --git a/packages/client/ui-conversation/src/client/locales.ts b/packages/client/ui-conversation/src/client/locales.ts
index 514b11c8cb..7a38aaa0f8 100644
--- a/packages/client/ui-conversation/src/client/locales.ts
+++ b/packages/client/ui-conversation/src/client/locales.ts
@@ -69,6 +69,8 @@ export const zh = {
'message.retry.failure': '失败原因:',
'message.turnError': '本轮运行失败',
'message.ranFor': '用时 {duration}',
+ 'duration.seconds': '{seconds}秒',
+ 'duration.minutes': '{minutes}分{seconds}秒',
'command.running': '执行中…',
'command.failed': '命令失败',
'command.done': '已完成',
@@ -178,6 +180,8 @@ export const en = {
'message.retry.failure': 'Failure reason: ',
'message.turnError': 'This turn failed',
'message.ranFor': 'Ran for {duration}',
+ 'duration.seconds': '{seconds}s',
+ 'duration.minutes': '{minutes}m {seconds}s',
'command.running': 'Running…',
'command.failed': 'Command failed',
'command.done': 'Completed',
diff --git a/packages/client/ui-conversation/tests/chat-code-subcalls.spec.tsx b/packages/client/ui-conversation/tests/chat-code-subcalls.spec.tsx
index 6708cdb759..f07104ba7b 100644
--- a/packages/client/ui-conversation/tests/chat-code-subcalls.spec.tsx
+++ b/packages/client/ui-conversation/tests/chat-code-subcalls.spec.tsx
@@ -67,7 +67,7 @@ function snapshotWith(
runningCalls: RunningToolCall[] = [],
): ConversationSnapshot {
return {
- sessionId: SID, nodes, turnEnds: new Map(), partial: null, runningCalls, codeDispatches,
+ sessionId: SID, nodes, turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls, codeDispatches,
pending: [], queue: [], running: runningCalls.length > 0, composerPhase: 'active', removed: false,
openState: 'open', openError: null,
hasMore: false, loadingOlder: false, promptError: null, blank: false, subagent: null, lastAgentError: null,
diff --git a/packages/client/ui-conversation/tests/chat-stats-bash-sample.spec.tsx b/packages/client/ui-conversation/tests/chat-stats-bash-sample.spec.tsx
index 95da35f267..8368c7cca1 100644
--- a/packages/client/ui-conversation/tests/chat-stats-bash-sample.spec.tsx
+++ b/packages/client/ui-conversation/tests/chat-stats-bash-sample.spec.tsx
@@ -32,7 +32,7 @@ const assistant = (seq: number, turn: number, usage?: unknown): AssistantMessage
function snapshotBase(): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false, openState: 'open', openError: null,
hasMore: false, loadingOlder: false, promptError: null, blank: false, subagent: null, lastAgentError: null,
}
diff --git a/packages/client/ui-conversation/tests/chat-view.spec.tsx b/packages/client/ui-conversation/tests/chat-view.spec.tsx
index d47ab7de80..3a0ca4f7b0 100644
--- a/packages/client/ui-conversation/tests/chat-view.spec.tsx
+++ b/packages/client/ui-conversation/tests/chat-view.spec.tsx
@@ -20,7 +20,7 @@ import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts
import { createChatStore } from '../src/client/stores.ts'
import { ChatView } from '../src/client/chat/ChatView.tsx'
import { zh } from '../src/client/locales.ts'
-import { assistantActionsSeqs, deriveChatFlow, flowKeys, lastInputTime, messageBranchSeqs, turnStartTimes } from '../src/client/chat/chat-flow.ts'
+import { assistantActionsSeqs, deriveChatFlow, flowKeys, messageBranchSeqs, runningTurnStartTime } from '../src/client/chat/chat-flow.ts'
import { formatRunDuration } from '../src/client/chat/message-chrome.ts'
afterEach(() => {
@@ -37,7 +37,7 @@ const SID = 's1' as SessionId
function snapshotBase(): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false, openState: 'open', openError: null,
hasMore: false, loadingOlder: false, promptError: null, blank: false, subagent: null, lastAgentError: null,
}
@@ -242,33 +242,23 @@ describe('chat-flow derivation', () => {
expect([...seqs].sort((a, b) => a - b)).toEqual([5, 7])
})
- it('turnStartTimes anchors each turn to the nearest preceding input node', () => {
- const starts = turnStartTimes([
- user(1, 'hi'),
- assistant(2, 'mid', 1),
- assistant(5, 'done', 1),
- {
- kind: 'steering', messageId: 'st' as never,
- seq: 6, time: 6_000, turn: 1,
- content: [{ type: 'text', text: 'also' }], source: null,
- },
- assistant(7, 'second turn', 2),
- ])
- expect([...starts]).toEqual([[1, 1_000], [2, 6_000]])
- // No input in-window before the turn's first assistant: the turn is absent.
- expect(turnStartTimes([assistant(2, 'orphan', 1)]).size).toBe(0)
+ it('runningTurnStartTime selects the latest turn/start without a turn/end', () => {
+ expect(runningTurnStartTime(new Map([
+ [1, { startTime: 1_000, endTime: 5_000 }],
+ [2, { startTime: 6_000 }],
+ ]))).toBe(6_000)
+ expect(runningTurnStartTime(new Map([
+ [1, { startTime: 1_000, endTime: 5_000 }],
+ [2, { startTime: 6_000, endTime: 9_000 }],
+ ]))).toBeNull()
})
- it('formatRunDuration matches the running clock format', () => {
- expect(formatRunDuration(0)).toBe('0s')
- expect(formatRunDuration(-500)).toBe('0s')
- expect(formatRunDuration(15_400)).toBe('15s')
- expect(formatRunDuration(125_000)).toBe('2m 05s')
- })
-
- it('lastInputTime returns the trailing input node time', () => {
- expect(lastInputTime([user(1, 'hi'), assistant(2, 'mid', 1)])).toBe(1_000)
- expect(lastInputTime([assistant(2, 'orphan', 1)])).toBeNull()
+ it('formatRunDuration localizes units and floors partial seconds', () => {
+ const t = makeTranslate(zh, commonZh)
+ expect(formatRunDuration(0, t)).toBe('0秒')
+ expect(formatRunDuration(-500, t)).toBe('0秒')
+ expect(formatRunDuration(15_999, t)).toBe('15秒')
+ expect(formatRunDuration(125_000, t)).toBe('2分05秒')
})
it('messageBranchSeqs keeps only message rows at completed transcript tails', () => {
@@ -539,18 +529,21 @@ describe('ChatView', () => {
nodes: [
user(1, 'hi'), // time 1_000
assistant(2, 'mid-turn text'),
- assistant(16, 'final answer'), // time 16_000 → 15s
+ assistant(16, 'final answer'),
+ toolResult(18, 'trailing'),
],
- turnEnds: new Map([[1, 16]]),
+ turnTimings: new Map([[1, { startTime: 1_000, endTime: 20_000 }]]),
+ turnEnds: new Map([[1, 20]]),
})
const view = render()
- // Only the turn-tail footer carries the label; mid-turn chrome stays bare.
- expect(view.getAllByText(/用时 15s/)).toHaveLength(1)
+ // The exact turn/end includes trailing tool activity after the final text.
+ expect(view.getAllByText(/用时 19秒/)).toHaveLength(1)
})
it('user and assistant message containers scope the hover-revealed time chrome', () => {
const h = makeHarness({
nodes: [user(1, 'hi'), assistant(2, 'answer')],
+ turnTimings: new Map([[1, { startTime: 1_000, endTime: 2_000 }]]),
turnEnds: new Map([[1, 2]]),
})
const view = render()
@@ -727,12 +720,24 @@ describe('ChatView', () => {
expect(view.getByRole('status').textContent).toBe('Deep diving...')
})
- it('the running TurnStatus clock anchors to the logged trigger time, surviving reload', () => {
- const trigger: UserMessageNode = { ...user(1, 'go'), time: Date.now() - 125_000 }
- const h = makeHarness({ nodes: [trigger], running: true })
+ it('the running clock uses turn/start, ignores steering, and stays out of the live region', () => {
+ const startTime = Date.now() - 125_000
+ const trigger: UserMessageNode = { ...user(1, 'go'), time: startTime + 1 }
+ const h = makeHarness({
+ nodes: [trigger], turnTimings: new Map([[1, { startTime }]]), running: true,
+ })
const view = render()
// Freshly mounted (as after a reload) yet already past the 15s gate.
- expect(view.getByRole('status').textContent).toMatch(/^Deep diving\.\.\.2m 0\ds$/)
+ const status = view.getByRole('status')
+ expect(status.textContent).toMatch(/^Deep diving\.\.\.2分0\d秒$/)
+ expect(status.querySelector('[aria-hidden="true"]')).not.toBeNull()
+ act(() => {
+ h.set({ nodes: [trigger, {
+ kind: 'steering', messageId: 'st' as never, seq: 2, time: Date.now(), turn: 1,
+ content: [{ type: 'text', text: 'also' }], source: null,
+ }] })
+ })
+ expect(status.textContent).toMatch(/^Deep diving\.\.\.2分0\d秒$/)
})
it('dispatches each tool row through the keyed slot with the tool name as entryKey', () => {
diff --git a/packages/client/ui-conversation/tests/diff-card.spec.tsx b/packages/client/ui-conversation/tests/diff-card.spec.tsx
index f7de4e45f9..0d0fd46407 100644
--- a/packages/client/ui-conversation/tests/diff-card.spec.tsx
+++ b/packages/client/ui-conversation/tests/diff-card.spec.tsx
@@ -335,7 +335,7 @@ describe('DetailsPanel diff Output section', () => {
function snapshot(over: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null, ...over,
diff --git a/packages/client/ui-conversation/tests/gate-branch-tails.spec.tsx b/packages/client/ui-conversation/tests/gate-branch-tails.spec.tsx
index 8350b318e9..85854c6e97 100644
--- a/packages/client/ui-conversation/tests/gate-branch-tails.spec.tsx
+++ b/packages/client/ui-conversation/tests/gate-branch-tails.spec.tsx
@@ -24,7 +24,7 @@ const SID = 's1' as SessionId
function snapshotBase(): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false, openState: 'open', openError: null,
hasMore: false, loadingOlder: false, promptError: null, blank: false, subagent: null, lastAgentError: null,
}
diff --git a/packages/client/ui-conversation/tests/input-bar.spec.tsx b/packages/client/ui-conversation/tests/input-bar.spec.tsx
index 002704ce4c..9aa503dcac 100644
--- a/packages/client/ui-conversation/tests/input-bar.spec.tsx
+++ b/packages/client/ui-conversation/tests/input-bar.spec.tsx
@@ -23,7 +23,7 @@ const SID = 's1' as SessionId
function snapshotOf(overrides: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null,
diff --git a/packages/client/ui-conversation/tests/input-matrix.spec.tsx b/packages/client/ui-conversation/tests/input-matrix.spec.tsx
index 13c519e10d..be385d41d5 100644
--- a/packages/client/ui-conversation/tests/input-matrix.spec.tsx
+++ b/packages/client/ui-conversation/tests/input-matrix.spec.tsx
@@ -26,7 +26,7 @@ const SID = 's1' as SessionId
/** Standard-props InputBar mount over a real shell (the composer-bar entry shape). */
function mountBar(shell: SessionInputShell, over?: { running?: boolean; disabled?: boolean }) {
const session = createSnapshotStore({
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: over?.running ?? false, composerPhase: 'active',
removed: over?.disabled ?? false, openState: 'open', openError: null, hasMore: false,
loadingOlder: false, promptError: null, blank: false, subagent: null, lastAgentError: null,
diff --git a/packages/client/ui-conversation/tests/input-scenarios.spec.tsx b/packages/client/ui-conversation/tests/input-scenarios.spec.tsx
index 180318a846..58acf3a863 100644
--- a/packages/client/ui-conversation/tests/input-scenarios.spec.tsx
+++ b/packages/client/ui-conversation/tests/input-scenarios.spec.tsx
@@ -112,7 +112,7 @@ async function scopedBench(register?: (slash: SlashService) => void) {
actx.on('slash/input-consume-token', req => shell.consumeToken(req.guard) ? true : undefined)
const wiring = shell
const sessionStore = createSnapshotStore({
- sessionId, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null,
diff --git a/packages/client/ui-conversation/tests/queue-dock.spec.tsx b/packages/client/ui-conversation/tests/queue-dock.spec.tsx
index 52387ae397..9a37922668 100644
--- a/packages/client/ui-conversation/tests/queue-dock.spec.tsx
+++ b/packages/client/ui-conversation/tests/queue-dock.spec.tsx
@@ -32,7 +32,7 @@ function row(id: string, text: string | null, preview = text ?? '[image]'): Queu
function snapshotWith(queue: QueuedMessage[]): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue, running: true, composerPhase: 'active', removed: false, openState: 'open', openError: null,
hasMore: false, loadingOlder: false, promptError: null, blank: false, subagent: null, lastAgentError: null,
}
diff --git a/packages/client/ui-conversation/tests/read-card.spec.tsx b/packages/client/ui-conversation/tests/read-card.spec.tsx
index bf9898cff9..f8ecb8b73c 100644
--- a/packages/client/ui-conversation/tests/read-card.spec.tsx
+++ b/packages/client/ui-conversation/tests/read-card.spec.tsx
@@ -283,7 +283,7 @@ describe('DetailsPanel Output section (read)', () => {
function snapshot(over: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null, ...over,
diff --git a/packages/client/ui-conversation/tests/search-card.spec.tsx b/packages/client/ui-conversation/tests/search-card.spec.tsx
index c50c308edf..cd572cc350 100644
--- a/packages/client/ui-conversation/tests/search-card.spec.tsx
+++ b/packages/client/ui-conversation/tests/search-card.spec.tsx
@@ -397,7 +397,7 @@ describe('DetailsPanel Output section (search)', () => {
function snapshot(over: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null, ...over,
diff --git a/packages/client/ui-conversation/tests/skeleton.spec.tsx b/packages/client/ui-conversation/tests/skeleton.spec.tsx
index 5fc6f106b5..312ec88642 100644
--- a/packages/client/ui-conversation/tests/skeleton.spec.tsx
+++ b/packages/client/ui-conversation/tests/skeleton.spec.tsx
@@ -68,7 +68,7 @@ const workspaceState = (items: readonly WorkspaceView[]): WorkspaceListState =>
function conversationSnapshot(overrides: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null,
diff --git a/packages/client/ui-conversation/tests/terminal-card.spec.tsx b/packages/client/ui-conversation/tests/terminal-card.spec.tsx
index 6250fd0764..d4be802a34 100644
--- a/packages/client/ui-conversation/tests/terminal-card.spec.tsx
+++ b/packages/client/ui-conversation/tests/terminal-card.spec.tsx
@@ -477,7 +477,7 @@ describe('DetailsPanel Output section', () => {
function snapshot(over: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null, ...over,
diff --git a/packages/client/ui-conversation/tests/web-card.spec.tsx b/packages/client/ui-conversation/tests/web-card.spec.tsx
index bf4228f346..8940f5dd24 100644
--- a/packages/client/ui-conversation/tests/web-card.spec.tsx
+++ b/packages/client/ui-conversation/tests/web-card.spec.tsx
@@ -231,7 +231,7 @@ describe('DetailsPanel web Output section', () => {
function snapshot(over: Partial = {}): ConversationSnapshot {
return {
- sessionId: SID, nodes: [], turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
+ sessionId: SID, nodes: [], turnTimings: new Map(), turnEnds: new Map(), partial: null, runningCalls: [], codeDispatches: new Map(),
pending: [], queue: [], running: false, composerPhase: 'active', removed: false,
openState: 'open', openError: null, hasMore: false, loadingOlder: false,
promptError: null, blank: false, subagent: null, lastAgentError: null, ...over,
From b4a4f337e47e3e0019c758fcfb4758120ee7a1a0 Mon Sep 17 00:00:00 2001
From: imccyu
Date: Tue, 4 Aug 2026 16:02:19 +0800
Subject: [PATCH 4/4] test(client): derive retry timing expectation
---
packages/client/runtime/tests/session.spec.ts | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/packages/client/runtime/tests/session.spec.ts b/packages/client/runtime/tests/session.spec.ts
index b47a70edec..e1c9bbeae7 100644
--- a/packages/client/runtime/tests/session.spec.ts
+++ b/packages/client/runtime/tests/session.spec.ts
@@ -258,10 +258,16 @@ describe('live event path', () => {
expect(snapshot.nodes.some(node => node.kind === 'turn-error')).toBe(false)
expect(snapshot.nodes.at(-2)).toMatchObject({ kind: 'model-retry', retryState: 'started' })
expect(snapshot.nodes.at(-1)).toMatchObject({ kind: 'assistant', blocks: [{ kind: 'text', text: '完整回复' }] })
- expect([...snapshot.turnTimings]).toEqual([
- [1, { startTime: 1_700_000_000_006, endTime: 1_700_000_000_013 }],
- [2, { startTime: 1_700_000_000_014, endTime: 1_700_000_000_018 }],
- ])
+ const retryStart = retryTurn.find(event =>
+ event.type === 'turn/start' && event.data.trigger.kind === 'retry')
+ if (retryStart?.type !== 'turn/start') throw new Error('test fixture must include a retry turn/start')
+ const retryEnd = retryTurn.find(event =>
+ event.type === 'turn/end' && event.data.turn === retryStart.data.turn)
+ if (retryEnd?.type !== 'turn/end') throw new Error('test fixture must complete the retry turn')
+ expect(snapshot.turnTimings.get(retryStart.data.turn)).toEqual({
+ startTime: retryStart.time,
+ endTime: retryEnd.time,
+ })
const replay = makeSession()
replay.api.onHistory = () => histResponse([...plainTurn(0, 0, 'a', 'b'), ...retryTurn])