Skip to content

Commit 9163ac0

Browse files
committed
feat(tui): choose which transcript entries show timestamps
Only prompts (/timestamps) and assistant turn footers (/turn-times, turn_timing.time) can show when something happened. Tool calls, thinking blocks, text blocks, errors and compactions never do, so a long run gives no way to see when a step finished or how long a tool call ran. Add a `timestamps` option to tui.json naming the entry types that show a timestamp: "all", "none", a comma-separated list such as "user,tool", or an array. The types are user, assistant, text, reasoning, tool, error and compaction. Tool calls show when they finished and how long they ran; thinking blocks put the time before their existing duration; text blocks and errors get a muted time line; the compaction divider gets the time in its title. All use Locale.todayTimeOrDateFirst, like the turn footer. Unset, nothing changes: /timestamps, /turn-times and turn_timing.time work and persist exactly as before. Set, the list decides every type on each start and overrides turn_timing.time; /timestamps and /turn-times still flip prompt and turn times, until the TUI exits. A kv-wins rule would make the option dead for most existing installs: kv.json usually already holds "timestamps", because the kv store persists its in-memory defaults alongside any other write. The JSON schema description documents every value, since opencode ships no commented tui.jsonc template. AI-Model: anthropic/claude-opus-5-5 AI-Variant: high AI-Tool: opencode 1.18.34-vt-126-907b3bc518 AI-Platform: linux AI-Harness: Vibeterm a042c6b AI-Session-ID: ses_eec3e5569ffe2otGPxp4LBssZb
1 parent c602afc commit 9163ac0

6 files changed

Lines changed: 194 additions & 10 deletions

File tree

‎packages/opencode/test/config/tui.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ it.instance("loads turn timing config", () =>
154154
),
155155
)
156156

157+
it.instance("loads timestamps config", () =>
158+
withCleanState(
159+
Effect.gen(function* () {
160+
const fs = yield* FSUtil.Service
161+
const test = yield* TestInstance
162+
yield* fs.writeJson(path.join(test.directory, "tui.json"), { timestamps: "user,tool" })
163+
164+
const config = yield* getTuiConfig(test.directory)
165+
expect(config.timestamps).toBe("user,tool")
166+
}),
167+
),
168+
)
169+
157170
it.instance("resolves attention config defaults and overrides", () =>
158171
withCleanState(
159172
Effect.gen(function* () {

‎packages/tui/src/config/index.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@ export const Usage = Schema.Struct({
117117
}).annotate({ description: "Context usage and cost coloring in the sidebar Context block and the prompt footer" })
118118
export type Usage = Schema.Schema.Type<typeof Usage>
119119

120+
export const TimestampType = Schema.Literals(["user", "assistant", "text", "reasoning", "tool", "error", "compaction"])
121+
export type TimestampType = Schema.Schema.Type<typeof TimestampType>
122+
const timestampTypeNames = TimestampType.literals.join("|")
123+
export const Timestamps = Schema.Union([
124+
Schema.String.check(
125+
Schema.isPattern(new RegExp(`^\\s*(all|none|(${timestampTypeNames})(\\s*,\\s*(${timestampTypeNames}))*)\\s*$`)),
126+
),
127+
Schema.Array(TimestampType),
128+
]).annotate({
129+
description: [
130+
"Which session transcript entries show a timestamp: 'all', 'none', a comma-separated list such as 'user,tool',",
131+
'or an array such as ["user", "tool"].',
132+
"Types: 'user' - when a prompt was sent;",
133+
"'assistant' - when an assistant turn finished, in its footer;",
134+
"'text' - when an assistant text block finished, below it;",
135+
"'reasoning' - when a thinking block finished, before its duration;",
136+
"'tool' - when a tool call finished and how long it ran;",
137+
"'error' - when an assistant turn failed, in its error box;",
138+
"'compaction' - when compaction started, in its divider.",
139+
"Times from today show the time of day; older ones show the date, then the time.",
140+
"Unset (the default): only 'user' and 'assistant' can show times, through /timestamps, /turn-times and",
141+
"turn_timing.time, and those toggles persist.",
142+
"Set: this list decides every type on each start, overriding turn_timing.time,",
143+
"and /timestamps and /turn-times last until the TUI exits.",
144+
].join(" "),
145+
})
146+
147+
// Undefined when tui.json does not set `timestamps`, so callers can keep their unset behavior.
148+
export function timestampTypes(value: Info["timestamps"]): ReadonlySet<TimestampType> | undefined {
149+
if (value === undefined) return
150+
if (typeof value !== "string") return new Set(value)
151+
const names = value.split(",").map((name) => name.trim())
152+
if (names.includes("all")) return new Set(TimestampType.literals)
153+
return new Set(TimestampType.literals.filter((type) => names.includes(type)))
154+
}
155+
120156
export const AttentionSounds = Schema.Record(AttentionSoundName, Schema.optionalKey(Schema.String))
121157
export type AttentionSoundPaths = Schema.Schema.Type<typeof AttentionSounds>
122158
export const Attention = Schema.Struct({
@@ -154,6 +190,7 @@ export const Info = Schema.Struct({
154190
}),
155191
turn_timing: Schema.optional(TurnTiming),
156192
model_label: Schema.optional(ModelLabel),
193+
timestamps: Schema.optional(Timestamps),
157194
cursor: Schema.optional(Cursor),
158195
sidebar: Schema.optional(Sidebar),
159196
usage: Schema.optional(Usage),

‎packages/tui/src/routes/session/index.tsx‎

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import * as Model from "../../util/model"
7777
import { formatTranscript } from "../../util/transcript"
7878
import { sessionEpilogue } from "../../util/presentation"
7979
import { setPreLayoutSiblingMargin } from "../../util/layout"
80-
import { useTuiConfig } from "../../config"
80+
import { TuiConfig, useTuiConfig } from "../../config"
8181
import { useClipboard } from "../../context/clipboard"
8282
import { nextThinkingMode, reasoningSummary, useThinkingMode, type ThinkingMode } from "../../context/thinking"
8383
import { getScrollAcceleration, keepScrollAnchor } from "../../util/scroll"
@@ -185,6 +185,7 @@ const context = createContext<{
185185
showTimestamps: () => boolean
186186
showTurnTime: () => boolean
187187
showTurnDuration: () => boolean
188+
showPartTimestamp: (type: "text" | "reasoning" | "tool" | "error" | "compaction") => boolean
188189
showDetails: () => boolean
189190
showGenericToolOutput: () => boolean
190191
diffWrapMode: () => "word" | "none"
@@ -285,7 +286,6 @@ export function Session() {
285286
const thinking = useThinkingMode()
286287
const thinkingMode = thinking.mode
287288
const showThinking = createMemo(() => true)
288-
const [timestamps, setTimestamps] = kv.signal<"hide" | "show">("timestamps", "hide")
289289
const [showDetails, setShowDetails] = kv.signal("tool_details_visibility", true)
290290
const [showAssistantMetadata, _setShowAssistantMetadata] = kv.signal("assistant_metadata_visibility", true)
291291
const [showScrollbar, setShowScrollbar] = kv.signal("scrollbar_visible", false)
@@ -300,14 +300,21 @@ export function Session() {
300300
if (sidebar() === "auto" && wide()) return true
301301
return false
302302
})
303-
const showTimestamps = createMemo(() => timestamps() === "show")
304303
// Read without kv.signal: its in-memory default would be persisted by the next
305304
// unrelated kv.set and then shadow later tui.json edits.
306305
const keepScrollOnSubmit = createMemo<boolean>(() =>
307306
kv.get("keep_scroll_on_submit", tuiConfig.keep_scroll_on_submit ?? false),
308307
)
309-
// tui.json supplies the default; a palette toggle persists its own choice in kv.
310-
const showTurnTime = createMemo(() => kv.get("turn_timing_time", tuiConfig.turn_timing?.time ?? false) === true)
308+
// A tui.json `timestamps` list decides on every start and a toggle lasts until exit: kv.json usually
309+
// already holds a "timestamps" value, persisted alongside any other kv write, which would mask the config.
310+
// Without the list, the toggles persist in kv and turn_timing.time supplies the turn-time default.
311+
const timestampTypes = TuiConfig.timestampTypes(tuiConfig.timestamps)
312+
const [userTimestamps, setUserTimestamps] = createSignal(timestampTypes?.has("user"))
313+
const [turnTimes, setTurnTimes] = createSignal(timestampTypes?.has("assistant"))
314+
const showTimestamps = createMemo(() => userTimestamps() ?? kv.get("timestamps", "hide") === "show")
315+
const showTurnTime = createMemo(
316+
() => turnTimes() ?? kv.get("turn_timing_time", tuiConfig.turn_timing?.time ?? false) === true,
317+
)
311318
const showTurnDuration = createMemo(
312319
() => kv.get("turn_timing_duration", tuiConfig.turn_timing?.duration ?? false) === true,
313320
)
@@ -743,7 +750,8 @@ export function Session() {
743750
aliases: ["toggle-timestamps"],
744751
},
745752
run: () => {
746-
setTimestamps((prev) => (prev === "show" ? "hide" : "show"))
753+
if (timestampTypes) setUserTimestamps(!showTimestamps())
754+
else kv.set("timestamps", showTimestamps() ? "hide" : "show")
747755
dialog.clear()
748756
},
749757
},
@@ -767,7 +775,8 @@ export function Session() {
767775
name: "turn-times",
768776
},
769777
run: () => {
770-
kv.set("turn_timing_time", !showTurnTime())
778+
if (timestampTypes) setTurnTimes(!showTurnTime())
779+
else kv.set("turn_timing_time", !showTurnTime())
771780
dialog.clear()
772781
},
773782
},
@@ -1291,6 +1300,7 @@ export function Session() {
12911300
showTimestamps,
12921301
showTurnTime,
12931302
showTurnDuration,
1303+
showPartTimestamp: (type) => timestampTypes?.has(type) ?? false,
12941304
showDetails,
12951305
showGenericToolOutput,
12961306
diffWrapMode,
@@ -1584,7 +1594,11 @@ function UserMessage(props: {
15841594
<box
15851595
marginTop={1}
15861596
border={["top"]}
1587-
title=" Compaction "
1597+
title={
1598+
ctx.showPartTimestamp("compaction")
1599+
? ` Compaction · ${Locale.todayTimeOrDateFirst(props.message.time.created)} `
1600+
: " Compaction "
1601+
}
15881602
titleAlignment="center"
15891603
borderColor={theme.borderActive}
15901604
/>
@@ -1678,6 +1692,11 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
16781692
borderColor={theme.error}
16791693
>
16801694
<text fg={theme.textMuted}>{errorMessage(props.message.error)}</text>
1695+
<Show when={ctx.showPartTimestamp("error")}>
1696+
<text fg={theme.textMuted}>
1697+
{Locale.todayTimeOrDateFirst(props.message.time.completed ?? props.message.time.created)}
1698+
</text>
1699+
</Show>
16811700
</box>
16821701
</Show>
16831702
<Switch>
@@ -1777,6 +1796,11 @@ function ReasoningPart(props: { last: boolean; part: ReasoningPart; message: Ass
17771796
open={!inMinimal() || expanded()}
17781797
done={isDone()}
17791798
title={summary().title}
1799+
time={
1800+
ctx.showPartTimestamp("reasoning") && props.part.time.end !== undefined
1801+
? Locale.todayTimeOrDateFirst(props.part.time.end)
1802+
: undefined
1803+
}
17801804
duration={isDone() ? Locale.duration(duration()) : undefined}
17811805
encrypted={opaque()}
17821806
/>
@@ -1804,6 +1828,7 @@ function ReasoningHeader(props: {
18041828
open: boolean
18051829
done: boolean
18061830
title: string | null
1831+
time?: string
18071832
duration?: string
18081833
encrypted?: boolean
18091834
}) {
@@ -1813,8 +1838,9 @@ function ReasoningHeader(props: {
18131838
? RGBA.fromValues(theme.warning.r, theme.warning.g, theme.warning.b, theme.thinkingOpacity)
18141839
: theme.warning
18151840
const completed = () => {
1816-
if (props.encrypted) return `Thought${props.duration ? ` · ${props.duration}` : ""}`
1817-
const detail = [props.title, props.duration].filter(Boolean).join(" · ")
1841+
const timing = [props.time, props.duration].filter(Boolean).join(" · ")
1842+
if (props.encrypted) return `Thought${timing ? ` · ${timing}` : ""}`
1843+
const detail = [props.title, timing].filter(Boolean).join(" · ")
18181844
return `${props.toggleable ? (props.open ? "- " : "+ ") : ""}Thought${detail ? `: ${detail}` : ""}`
18191845
}
18201846

@@ -1856,6 +1882,9 @@ function TextPart(props: { last: boolean; part: TextPart; message: AssistantMess
18561882
fg={theme.markdownText}
18571883
bg={theme.background}
18581884
/>
1885+
<Show when={ctx.showPartTimestamp("text") && props.part.time?.end}>
1886+
{(end) => <text fg={theme.textMuted}>{Locale.todayTimeOrDateFirst(end())}</text>}
1887+
</Show>
18591888
</box>
18601889
</Show>
18611890
)
@@ -2027,6 +2056,9 @@ function InlineTool(props: {
20272056
)
20282057

20292058
const failed = createMemo(() => Boolean(error() && !denied()))
2059+
const timestamp = createMemo(() =>
2060+
ctx.showPartTimestamp("tool") ? formatToolTimestamp(props.part.state) : undefined,
2061+
)
20302062
const clickable = createMemo(() => Boolean(props.onClick || failed()))
20312063
const fg = createMemo(() => {
20322064
if (props.color) return props.color
@@ -2053,6 +2085,8 @@ function InlineTool(props: {
20532085
failure={props.failure}
20542086
spinner={props.spinner}
20552087
separate={props.separate}
2088+
timestamp={timestamp()}
2089+
timestampColor={theme.textMuted}
20562090
onMouseOver={() => clickable() && setHover(true)}
20572091
onMouseOut={() => setHover(false)}
20582092
onMouseUp={() => {
@@ -2084,6 +2118,8 @@ export function InlineToolRow(props: {
20842118
failure?: string
20852119
spinner?: boolean
20862120
separate?: boolean
2121+
timestamp?: string
2122+
timestampColor?: RGBA
20872123
children: JSX.Element
20882124
onMouseOver?: () => void
20892125
onMouseOut?: () => void
@@ -2137,6 +2173,9 @@ export function InlineToolRow(props: {
21372173
attributes={props.denied ? TextAttributes.STRIKETHROUGH : undefined}
21382174
>
21392175
{props.failed && !props.complete ? (props.failure ?? props.children) : props.children}
2176+
<Show when={props.timestamp}>
2177+
<span style={{ fg: props.timestampColor }}> · {props.timestamp}</span>
2178+
</Show>
21402179
</text>
21412180
</box>
21422181
</Show>
@@ -2159,9 +2198,13 @@ function BlockTool(props: {
21592198
spinner?: boolean
21602199
}) {
21612200
const { theme } = useTheme()
2201+
const ctx = use()
21622202
const renderer = useRenderer()
21632203
const [hover, setHover] = createSignal(false)
21642204
const error = createMemo(() => (props.part?.state.status === "error" ? props.part.state.error : undefined))
2205+
const timestamp = createMemo(() =>
2206+
props.part && ctx.showPartTimestamp("tool") ? formatToolTimestamp(props.part.state) : undefined,
2207+
)
21652208
return (
21662209
<box
21672210
id={props.part?.id}
@@ -2189,6 +2232,7 @@ function BlockTool(props: {
21892232
fallback={
21902233
<text paddingLeft={3} fg={theme.textMuted}>
21912234
{title()}
2235+
{timestamp() ? ` · ${timestamp()}` : ""}
21922236
</text>
21932237
}
21942238
>
@@ -2200,6 +2244,9 @@ function BlockTool(props: {
22002244
<Show when={error()}>
22012245
<text fg={theme.error}>{error()}</text>
22022246
</Show>
2247+
<Show when={!props.title && timestamp()}>
2248+
<text fg={theme.textMuted}>{timestamp()}</text>
2249+
</Show>
22032250
</box>
22042251
)
22052252
}
@@ -2471,6 +2518,11 @@ function Task(props: ToolProps) {
24712518
)
24722519
}
24732520

2521+
export function formatToolTimestamp(state: ToolPart["state"]) {
2522+
if (state.status !== "completed" && state.status !== "error") return
2523+
return `${Locale.todayTimeOrDateFirst(state.time.end)} · ${Locale.duration(Math.max(0, state.time.end - state.time.start))}`
2524+
}
2525+
24742526
export function formatSubagentToolcalls(count: number) {
24752527
return `${count} toolcall${count === 1 ? "" : "s"}`
24762528
}

‎packages/tui/test/cli/tui/inline-tool-wrap-snapshot.test.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
formatSubagentRetry,
88
formatSubagentTitle,
99
formatSubagentToolcalls,
10+
formatToolTimestamp,
1011
InlineToolRow,
1112
parseApplyPatchFiles,
1213
parseDiagnostics,
@@ -16,6 +17,7 @@ import {
1617
alwaysSeparate,
1718
toolDisplay,
1819
} from "../../../src/routes/session"
20+
import { Locale } from "../../../src/util/locale"
1921

2022
let testSetup: Awaited<ReturnType<typeof testRender>> | undefined
2123

@@ -240,6 +242,41 @@ describe("TUI inline tool wrapping", () => {
240242
expect(frame).not.toContain("Read failed")
241243
})
242244

245+
test("appends the tool timestamp after the row text", async () => {
246+
const frame = await renderFrame(
247+
() => (
248+
<InlineToolRow icon="→" complete={true} pending="" timestamp="1:07 PM · 1.2s">
249+
Read src/index.ts
250+
</InlineToolRow>
251+
),
252+
{ width: 72, height: 3 },
253+
)
254+
expect(frame).toContain("→ Read src/index.ts · 1:07 PM · 1.2s")
255+
})
256+
257+
test("formats a finished tool call's end time and duration", () => {
258+
const end = new Date()
259+
end.setHours(13, 7, 0, 0)
260+
const start = end.getTime() - 1234
261+
const input = {}
262+
const time = Locale.todayTimeOrDateFirst(end.getTime())
263+
expect(formatToolTimestamp({ status: "pending", input, raw: "" })).toBeUndefined()
264+
expect(formatToolTimestamp({ status: "running", input, time: { start } })).toBeUndefined()
265+
expect(
266+
formatToolTimestamp({
267+
status: "completed",
268+
input,
269+
output: "",
270+
title: "",
271+
metadata: {},
272+
time: { start, end: end.getTime() },
273+
}),
274+
).toBe(`${time} · 1.2s`)
275+
expect(formatToolTimestamp({ status: "error", input, error: "boom", time: { start, end: end.getTime() } })).toBe(
276+
`${time} · 1.2s`,
277+
)
278+
})
279+
243280
test("filters malformed nested tool wire data", () => {
244281
expect(
245282
parseApplyPatchFiles([

‎packages/tui/test/config.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
LeaderTimeoutDefault,
99
PluginSpec,
1010
resolve,
11+
timestampTypes,
1112
TuiConfigProvider,
1213
type Info as TuiConfigInfo,
1314
useTuiConfig,
@@ -82,6 +83,23 @@ test("validates config constraints", () => {
8283
expect(decodeInfo({ attention: { sounds: { unknown: "sound.wav" } } })).toEqual({ attention: { sounds: {} } })
8384
})
8485

86+
test("decodes timestamps as all, none, a comma-separated list, or an array", () => {
87+
const types = (value: unknown) => {
88+
const set = timestampTypes(decodeInfo({ timestamps: value }).timestamps)
89+
return set && [...set]
90+
}
91+
92+
expect(timestampTypes(decodeInfo({}).timestamps)).toBeUndefined()
93+
expect(types("all")).toEqual(["user", "assistant", "text", "reasoning", "tool", "error", "compaction"])
94+
expect(types("none")).toEqual([])
95+
expect(types(" user , tool")).toEqual(["user", "tool"])
96+
expect(types(["reasoning", "compaction"])).toEqual(["reasoning", "compaction"])
97+
expect(() => decodeInfo({ timestamps: "tools" })).toThrow()
98+
expect(() => decodeInfo({ timestamps: "all,user" })).toThrow()
99+
expect(() => decodeInfo({ timestamps: "user," })).toThrow()
100+
expect(() => decodeInfo({ timestamps: ["all"] })).toThrow()
101+
})
102+
85103
test("resolves host-neutral defaults", () => {
86104
const config = resolve({}, { terminalSuspend: true })
87105

0 commit comments

Comments
 (0)