Skip to content

Commit 17dca85

Browse files
committed
feat(tui): show per-turn completion time and duration
The assistant footer only appears on the final message of a prompt and shows one number: the time since that prompt. Intermediate tool-call turns show no footer, so there is no way to see when a turn finished or which step of a long run took the time. Add a `turn_timing` option to tui.json with two independent booleans: - `time`: when each assistant turn finished, as the time of day if today and the date and time otherwise (Locale.todayTimeOrDateTime, the same format /timestamps uses for user messages). - `duration`: how long each turn took (created -> completed). The final turn keeps the existing total since the prompt and labels it `total`, so both numbers are visible. Either option gives every completed assistant turn a footer. Both default to false, so the footer is unchanged unless enabled. /turn-times and /turn-durations (also in the command palette and bindable via session_toggle_turn_time / session_toggle_turn_duration) toggle them at runtime. Like /timestamps, a toggled value persists in kv.json and takes precedence over tui.json, which supplies the default. AI-Tool: opencode 1.18.33-vt-60-2fa3363c92 AI-Model: anthropic/claude-opus-5-5 AI-Variant: high AI-Platform: linux AI-Harness: Vibeterm fcfb2f9 AI-Session-ID: ses_ef81c1485ffeC5Sb59U9mVI77g
1 parent 35bba91 commit 17dca85

5 files changed

Lines changed: 93 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ it.instance("loads tui config with the same precedence order as server config pa
141141
),
142142
)
143143

144+
it.instance("loads turn timing config", () =>
145+
withCleanState(
146+
Effect.gen(function* () {
147+
const fs = yield* FSUtil.Service
148+
const test = yield* TestInstance
149+
yield* fs.writeJson(path.join(test.directory, "tui.json"), { turn_timing: { time: true } })
150+
151+
const config = yield* getTuiConfig(test.directory)
152+
expect(config.turn_timing).toEqual({ time: true })
153+
}),
154+
),
155+
)
156+
144157
it.instance("resolves attention config defaults and overrides", () =>
145158
withCleanState(
146159
Effect.gen(function* () {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export const Cursor = Schema.Struct({
3838
description: "Whether the cursor blinks. Has no effect when style is 'default'",
3939
}),
4040
}).annotate({ description: "Terminal cursor settings" })
41+
export const TurnTiming = Schema.Struct({
42+
time: Schema.optional(Schema.Boolean).annotate({
43+
description:
44+
"Show when each assistant turn finished: the time of day if today, the date and time otherwise (default: false)",
45+
}),
46+
duration: Schema.optional(Schema.Boolean).annotate({
47+
description:
48+
"Show how long each assistant turn took; the final turn also keeps the total since the prompt (default: false)",
49+
}),
50+
}).annotate({
51+
description: "Default per-turn timing in assistant message footers; toggle at runtime from the command palette",
52+
})
4153

4254
export const Sidebar = Schema.Struct({
4355
pin_title: Schema.optional(Schema.Boolean).annotate({
@@ -80,6 +92,7 @@ export const Info = Schema.Struct({
8092
description:
8193
"Keep the session scroll position when a prompt is submitted instead of jumping to the bottom (default: false)",
8294
}),
95+
turn_timing: Schema.optional(TurnTiming),
8396
cursor: Schema.optional(Cursor),
8497
sidebar: Schema.optional(Sidebar),
8598
mouse: Schema.optional(Schema.Boolean).annotate({ description: "Enable or disable mouse capture (default: true)" }),

‎packages/tui/src/config/keybind.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export const Definitions = {
9999
session_background: keybind("ctrl+b", "Background synchronous subagents"),
100100
session_compact: keybind("<leader>c", "Compact the session"),
101101
session_toggle_timestamps: keybind("none", "Toggle message timestamps"),
102+
session_toggle_turn_time: keybind("none", "Toggle assistant turn completion times"),
103+
session_toggle_turn_duration: keybind("none", "Toggle assistant turn durations"),
102104
session_toggle_generic_tool_output: keybind("none", "Toggle generic tool output"),
103105
session_queued_prompts: keybind("<leader>q", "Manage queued prompts"),
104106
session_child_first: keybind("<leader>down", "Go to first child session"),
@@ -307,6 +309,8 @@ export const CommandMap = {
307309
session_background: "session.background",
308310
session_compact: "session.compact",
309311
session_toggle_timestamps: "session.toggle.timestamps",
312+
session_toggle_turn_time: "session.toggle.turn_time",
313+
session_toggle_turn_duration: "session.toggle.turn_duration",
310314
session_toggle_generic_tool_output: "session.toggle.generic_tool_output",
311315
session_queued_prompts: "session.queued_prompts",
312316
session_child_first: "session.child.first",

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

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ const sessionBindingCommands = [
125125
"session.sidebar.pin_title",
126126
"session.toggle.conceal",
127127
"session.toggle.timestamps",
128+
"session.toggle.turn_time",
129+
"session.toggle.turn_duration",
128130
"session.toggle.thinking",
129131
"session.toggle.actions",
130132
"session.toggle.scrollbar",
@@ -161,6 +163,8 @@ const context = createContext<{
161163
thinkingMode: () => ThinkingMode
162164
showThinking: () => boolean
163165
showTimestamps: () => boolean
166+
showTurnTime: () => boolean
167+
showTurnDuration: () => boolean
164168
showDetails: () => boolean
165169
showGenericToolOutput: () => boolean
166170
diffWrapMode: () => "word" | "none"
@@ -282,6 +286,11 @@ export function Session() {
282286
const keepScrollOnSubmit = createMemo<boolean>(() =>
283287
kv.get("keep_scroll_on_submit", tuiConfig.keep_scroll_on_submit ?? false),
284288
)
289+
// tui.json supplies the default; a palette toggle persists its own choice in kv.
290+
const showTurnTime = createMemo(() => kv.get("turn_timing_time", tuiConfig.turn_timing?.time ?? false) === true)
291+
const showTurnDuration = createMemo(
292+
() => kv.get("turn_timing_duration", tuiConfig.turn_timing?.duration ?? false) === true,
293+
)
285294
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
286295
const providers = createMemo(() => Model.index(sync.data.provider))
287296

@@ -740,6 +749,30 @@ export function Session() {
740749
dialog.clear()
741750
},
742751
},
752+
{
753+
title: showTurnTime() ? "Hide turn times" : "Show turn times",
754+
value: "session.toggle.turn_time",
755+
category: "Session",
756+
slash: {
757+
name: "turn-times",
758+
},
759+
run: () => {
760+
kv.set("turn_timing_time", !showTurnTime())
761+
dialog.clear()
762+
},
763+
},
764+
{
765+
title: showTurnDuration() ? "Hide turn durations" : "Show turn durations",
766+
value: "session.toggle.turn_duration",
767+
category: "Session",
768+
slash: {
769+
name: "turn-durations",
770+
},
771+
run: () => {
772+
kv.set("turn_timing_duration", !showTurnDuration())
773+
dialog.clear()
774+
},
775+
},
743776
{
744777
title: (() => {
745778
const next = nextThinkingMode(thinkingMode())
@@ -1202,6 +1235,8 @@ export function Session() {
12021235
thinkingMode,
12031236
showThinking,
12041237
showTimestamps,
1238+
showTurnTime,
1239+
showTurnDuration,
12051240
showDetails,
12061241
showGenericToolOutput,
12071242
diffWrapMode,
@@ -1520,6 +1555,12 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
15201555
return props.message.time.completed - user.time.created
15211556
})
15221557

1558+
const completed = createMemo(() =>
1559+
(ctx.showTurnTime() || ctx.showTurnDuration()) && props.message.time.completed
1560+
? props.message.time.completed
1561+
: undefined,
1562+
)
1563+
15231564
const childShortcut = useCommandShortcut("session.child.first")
15241565
const backgroundShortcut = useCommandShortcut("session.background")
15251566

@@ -1580,7 +1621,7 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
15801621
</box>
15811622
</Show>
15821623
<Switch>
1583-
<Match when={props.last || final() || props.message.error?.name === "MessageAbortedError"}>
1624+
<Match when={props.last || final() || props.message.error?.name === "MessageAbortedError" || completed()}>
15841625
<box ref={(el: BoxRenderable) => alwaysSeparate.add(el)} paddingLeft={3}>
15851626
<text marginTop={1}>
15861627
<span
@@ -1595,8 +1636,23 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
15951636
</span>{" "}
15961637
<span style={{ fg: theme.text }}>{Locale.titlecase(props.message.mode)}</span>
15971638
<span style={{ fg: theme.textMuted }}> · {model()}</span>
1639+
<Show when={ctx.showTurnTime() && completed()}>
1640+
{(time) => <span style={{ fg: theme.textMuted }}> · {Locale.todayTimeOrDateTime(time())}</span>}
1641+
</Show>
1642+
<Show when={ctx.showTurnDuration() && completed()}>
1643+
{(time) => (
1644+
<span style={{ fg: theme.textMuted }}>
1645+
{" "}
1646+
· {Locale.duration(Math.max(0, time() - props.message.time.created))}
1647+
</span>
1648+
)}
1649+
</Show>
15981650
<Show when={duration()}>
1599-
<span style={{ fg: theme.textMuted }}> · {Locale.duration(duration())}</span>
1651+
<span style={{ fg: theme.textMuted }}>
1652+
{" "}
1653+
· {Locale.duration(duration())}
1654+
{ctx.showTurnDuration() ? " total" : ""}
1655+
</span>
16001656
</Show>
16011657
<Show when={props.message.error?.name === "MessageAbortedError"}>
16021658
<span style={{ fg: theme.textMuted }}> · interrupted</span>

‎packages/web/src/content/docs/tui.mdx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ You can customize TUI behavior through `tui.json` (or `tui.jsonc`).
369369
"enabled": false
370370
},
371371
"diff_style": "auto",
372+
"turn_timing": {
373+
"time": false,
374+
"duration": false
375+
},
372376
"cursor": {
373377
"style": "block",
374378
"blinking": true
@@ -399,6 +403,7 @@ This is separate from `opencode.json`, which configures server/runtime behavior.
399403
- `scroll_acceleration.enabled` - Enable macOS-style scroll acceleration for smooth, natural scrolling. When enabled, scroll speed increases with rapid scrolling gestures and stays precise for slower movements. **This setting takes precedence over `scroll_speed` and overrides it when enabled.**
400404
- `scroll_speed` - Controls how fast the TUI scrolls when using scroll commands (minimum: `0.001`, supports decimal values). Defaults to `3`. **Note: This is ignored if `scroll_acceleration.enabled` is set to `true`.**
401405
- `diff_style` - Controls diff rendering. `"auto"` adapts to terminal width, `"stacked"` always shows a single-column layout.
406+
- `turn_timing` - Adds timing to the footer of every assistant turn, including the intermediate tool-call turns. `time` shows when the turn finished: the time of day if today, the date and time otherwise. `duration` shows how long the turn took; the final turn keeps the total since your prompt, labelled `total`. Both default to `false`. Toggle them at runtime with `/turn-times` and `/turn-durations`; the toggled value persists and takes precedence over `tui.json`.
402407
- `cursor` - Controls the terminal cursor in TUI input fields. `style` defaults to `"block"`, can be `"underline"`, `"line"`, or `"default"`; `blinking` defaults to `true`. When `style` is `"default"`, the terminal default cursor is restored, so `blinking` has no effect.
403408
- `mouse` - Enable or disable mouse capture in the TUI (default: `true`). When disabled, the terminal's native mouse selection/scrolling behavior is preserved.
404409
- `keep_scroll_on_submit` - Keep the session scroll position when a prompt is submitted instead of jumping to the bottom (default: `false`). Toggle it at runtime with `/keep-scroll`; the toggle is remembered and takes precedence over this option.

0 commit comments

Comments
 (0)