Skip to content

The agent that grows with you

feat(desktop): show per-turn wall-clock duration in the transcript

Tommy0074893a9b2318fd5
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
index ad9ac2c49cd..b7eeae2a17a 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts
@@ -595,6 +595,12 @@ export function useMessageStream({
const keepFailedPartialText = Boolean(failure?.partial && finalText)
const interimBoundaryPending = state.interimBoundaryPending
+ // Wall-clock seconds this turn actually ran (message.start stamped
+ // turnStartedAt). Read BEFORE the state return below nulls it.
+ const durationS = state.turnStartedAt
+ ? Math.max(1, Math.round((Date.now() - state.turnStartedAt) / 1000))
+ : undefined
+
const replaceTextPart = (parts: ChatMessagePart[]) => {
const visibleFinalText = stripGeneratedImageEchoes(finalText, generatedImageEchoSources(parts)).trim()
@@ -609,7 +615,8 @@ export function useMessageStream({
completedAt: occurredAt,
parts: completeOpenTimelineParts(message.parts, occurredAt),
pending: false,
- interim: false
+ interim: false,
+ ...(durationS !== undefined ? { durationS } : {})
}
if (completionError && !keepFailedPartialText) {
@@ -633,6 +640,7 @@ export function useMessageStream({
timestamp: occurredAt,
completedAt: occurredAt,
branchGroupId: state.pendingBranchGroup ?? undefined,
+ ...(durationS !== undefined ? { durationS } : {}),
...(completionError && { error: completionError })
})
@@ -779,6 +787,10 @@ export function useMessageStream({
const prev = state.messages
const error = errorMessage.trim() || 'Hermes reported an error'
+ const durationS = state.turnStartedAt
+ ? Math.max(1, Math.round((Date.now() - state.turnStartedAt) / 1000))
+ : undefined
+
const nextMessages = prev.some(m => m.id === streamId)
? prev.map(message =>
message.id === streamId
@@ -787,7 +799,8 @@ export function useMessageStream({
completedAt: occurredAt,
error,
parts: completeOpenTimelineParts(message.parts, occurredAt),
- pending: false
+ pending: false,
+ ...(durationS !== undefined ? { durationS } : {})
}
: message
)
@@ -801,7 +814,8 @@ export function useMessageStream({
completedAt: occurredAt,
error,
pending: false,
- branchGroupId: groupId
+ branchGroupId: groupId,
+ ...(durationS !== undefined ? { durationS } : {})
}
]
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts
index 4d46dc5fa53..533f0e9ca90 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts
@@ -149,7 +149,10 @@ const COMPARED_FIELDS = [
'interim',
'reactions',
'timestamp',
- 'completedAt'
+ 'completedAt',
+ // Turn wall-clock duration — stamps the visible "⏱ 38s" badge, so a change
+ // must re-render (set once at completion; stable afterwards).
+ 'durationS'
] as const
const IGNORED_FIELDS = ['attachmentRefs', 'parts', 'rowId'] as const
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
index a4ef0d5fbe7..1fcfabfbb3b 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
@@ -22,6 +22,7 @@ import { MessageTimelineTimestamp } from '@/components/assistant-ui/thread/timel
import { useMessageReactions, useTapbackDoubleClick } from '@/components/assistant-ui/thread/use-message-reactions'
import { AGENT_MESSAGE_RE } from '@/components/assistant-ui/thread/user-message'
import { TooltipIconButton } from '@/components/assistant-ui/tooltip-icon-button'
+import { formatElapsed } from '@/components/chat/activity-timer'
import { PreviewAttachment } from '@/components/chat/preview-attachment'
import { Codicon } from '@/components/ui/codicon'
import { CopyButton } from '@/components/ui/copy-button'
@@ -105,6 +106,10 @@ export const AssistantMessage: FC<{
// ChatMessage.interim).
const isInterim = useAuiState(s => s.message.metadata?.custom?.interim === true)
+ // Whole-turn wall-clock seconds (set once at completion — referentially
+ // stable across the 30 Hz delta stream, so this adds no per-token renders).
+ const turnDurationS = useAuiState(s => s.message.metadata?.custom?.durationS as number | undefined)
+
// The thinking/stall indicator belongs to the TAIL of the thread, period. A
// stale pending bubble mid-transcript (a turn that ended without its settle
// event, a steer race) must never show one — a spinner above a later user
@@ -223,7 +228,12 @@ export const AssistantMessage: FC<{
</div>
<MessageTimelineTimestamp className="px-(--message-text-indent) pt-0.5" suppressIfDuplicatePart />
{hasVisibleText && !isInterim && (
- <AssistantFooter getMessageText={getMessageText} messageId={messageId} onBranchInNewChat={onBranchInNewChat} />
+ <AssistantFooter
+ durationS={turnDurationS}
+ getMessageText={getMessageText}
+ messageId={messageId}
+ onBranchInNewChat={onBranchInNewChat}
+ />
)}
{/* Last thing in the turn — under the action bar, the way Cursor ends a
turn on its summary rather than burying it above the controls. */}
@@ -363,8 +373,20 @@ const ReadAloudButton: FC<{ getText: () => string; messageId: string }> = ({ get
)
}
-const AssistantFooter: FC<MessageActionProps> = props => (
+const AssistantFooter: FC<MessageActionProps & { durationS?: number }> = ({ durationS, ...props }) => {
+ const { t } = useI18n()
+
+ return (
<div className="flex min-h-6 flex-col items-end gap-1 pr-(--message-text-indent) pl-(--message-text-indent)">
+ {durationS !== undefined && (
+ <span
+ className="select-none px-0.5 text-[0.6875rem] leading-5 tabular-nums text-muted-foreground"
+ data-slot="aui_turn-duration"
+ title={t.assistant.thread.turnDuration(formatElapsed(durationS))}
+ >
+ ⏱ {formatElapsed(durationS)}
+ </span>
+ )}
<BranchPickerPrimitive.Root
className="inline-flex h-6 items-center gap-1 text-xs text-muted-foreground"
hideWhenSingleBranch
@@ -381,4 +403,5 @@ const AssistantFooter: FC<MessageActionProps> = props => (
</BranchPickerPrimitive.Root>
<AssistantActionBar {...props} />
</div>
-)
+ )
+}
diff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.ts
index 1ba11274e03..91d6c16314a 100644
--- a/apps/desktop/src/i18n/ar.ts
+++ b/apps/desktop/src/i18n/ar.ts
@@ -2310,6 +2310,7 @@ export const ar = defineLocale({
thought: 'فكّر',
thoughtBriefly: 'فكّر قليلاً',
thoughtFor: duration => `فكّر لمدة ${duration}`,
+ turnDuration: duration => `استغرقت هذه الجولة ${duration}`,
today: time => `اليوم ${time}`,
yesterday: time => `أمس ${time}`,
copy: 'نسخ',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 25d1cc34ee8..2aa80e8b689 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2878,6 +2878,7 @@ export const en: Translations = {
thought: 'Thought',
thoughtBriefly: 'Thought briefly',
thoughtFor: duration => `Thought for ${duration}`,
+ turnDuration: duration => `This turn took ${duration}`,
today: time => `Today, ${time}`,
yesterday: time => `Yesterday, ${time}`,
copy: 'Copy',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 671f60cb9b5..a3674007fda 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -2589,6 +2589,7 @@ export const ja = defineLocale({
thought: '思考済み',
thoughtBriefly: '少し思考',
thoughtFor: duration => `${duration} 思考`,
+ turnDuration: duration => `このターンの所要時間: ${duration}`,
today: time => `今日 ${time}`,
yesterday: time => `昨日 ${time}`,
copy: 'コピー',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 4cff6eee18a..86c28057f3c 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -2458,6 +2458,7 @@ export interface Translations {
thought: string
thoughtBriefly: string
thoughtFor: (duration: string) => string
+ turnDuration: (duration: string) => string
today: (time: string) => string
yesterday: (time: string) => string
copy: string
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index 2374a973938..5d5abe0e074 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -2507,6 +2507,7 @@ export const zhHant = defineLocale({
thought: '已思考',
thoughtBriefly: '思考了片刻',
thoughtFor: duration => `思考了 ${duration}`,
+ turnDuration: duration => `本輪耗時 ${duration}`,
today: time => `今天,${time}`,
yesterday: time => `昨天,${time}`,
copy: '複製',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 11f06c02c23..3f2641e62b6 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -3048,6 +3048,7 @@ export const zh: Translations = {
thought: '已思考',
thoughtBriefly: '思考了片刻',
thoughtFor: duration => `思考了 ${duration}`,
+ turnDuration: duration => `本轮耗时 ${duration}`,
today: time => `今天,${time}`,
yesterday: time => `昨天,${time}`,
copy: '复制',
diff --git a/apps/desktop/src/lib/chat-messages.ts b/apps/desktop/src/lib/chat-messages.ts
index 8f26f8c0006..02e028a623e 100644
--- a/apps/desktop/src/lib/chat-messages.ts
+++ b/apps/desktop/src/lib/chat-messages.ts
@@ -32,6 +32,10 @@ export type ChatMessage = {
* action footer so only the turn's final reply carries copy/refresh, and
* the live view matches rehydration (which merges the turn into one bubble). */
interim?: boolean
+ /** Whole-turn wall-clock seconds (message.start → message.complete),
+ * stamped by the desktop when it watched the turn run. Absent for
+ * messages hydrated from history — the backend doesn't persist it. */
+ durationS?: number
/** Composer attachment ref strings (`@file:...`, `@image:...`) sent with this user message. */
attachmentRefs?: string[]
/** Durable backend `messages.id`. Absent until the row is persisted. */
diff --git a/apps/desktop/src/lib/chat-runtime.ts b/apps/desktop/src/lib/chat-runtime.ts
index e921c873189..8bf133b674a 100644
--- a/apps/desktop/src/lib/chat-runtime.ts
+++ b/apps/desktop/src/lib/chat-runtime.ts
@@ -483,6 +483,7 @@ export function toRuntimeMessage(message: ChatMessage): ThreadMessage {
...(message.interim ? { interim: true } : {}),
...timelineMeta,
...(message.completedAt !== undefined ? { timelineCompletedAt: message.completedAt } : {}),
+ ...(message.durationS !== undefined ? { durationS: message.durationS } : {}),
...reactionMeta
}
}