Skip to content

Commit 42ce394

Browse files
committed
feat(tui): add datetime_format and show each footer detail once
Times and dates were always written by toLocale*String with the runtime locale, which Bun resolves to en-US whatever LANG and LC_TIME say, so there was no way to get 24-hour or ISO dates. datetime_format in tui.json takes a date and a time pattern in Day.js tokens (YYYY, MM, DD; HH, mm, ss, A ...); entries from today still show only the time, and an unset part keeps the locale output. Each part accepts only its own tokens and other letters must be bracketed, so "HH:MM:SS" (month in place of minute) is rejected instead of misprinted. It applies to every caller of the Locale time helpers: footers, entry timestamps, the compaction divider and the timeline, fork and stash dialogs. With footer.message_id on both, a tool call repeated its assistant message's ID right above the message footer. A tool call now shows the ID only when the message's own footer does not (toolFooterShowsMessageID): message_id "tool" without "assistant", or "important" leaving a plain step's footer out. A collapsed or expanded block tool drew its "Click to expand" hint and its footer on two lines. BlockTool now takes the hint and joins the footer to it with " · "; clicking the hint still toggles the block and a msg_ ID on that line still copies. AI-Tool: opencode 1.18.34-vt-163-907b3bc518 AI-Model: anthropic/claude-opus-5-5 AI-Variant: high AI-Platform: linux AI-Harness: Vibeterm fcbe738 AI-Session-ID: ses_ee68aab01ffei41gwUGJ5ESj6W
1 parent e23cc19 commit 42ce394

9 files changed

Lines changed: 213 additions & 35 deletions

File tree

‎packages/tui/src/component/dialog-stash.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { Locale } from "../util/locale"
55
import { useTheme } from "../context/theme"
66
import { usePromptStash, type StashEntry } from "./prompt/stash"
77
import { useCommandShortcut } from "../keymap"
8+
import { useTuiConfig } from "../config"
89

9-
function getRelativeTime(timestamp: number): string {
10+
function getRelativeTime(timestamp: number, format?: Locale.DateTimeFormat): string {
1011
const now = Date.now()
1112
const diff = now - timestamp
1213
const seconds = Math.floor(diff / 1000)
@@ -18,7 +19,7 @@ function getRelativeTime(timestamp: number): string {
1819
if (minutes < 60) return `${minutes}m ago`
1920
if (hours < 24) return `${hours}h ago`
2021
if (days < 7) return `${days}d ago`
21-
return Locale.datetime(timestamp)
22+
return Locale.datetime(timestamp, format)
2223
}
2324

2425
function getStashPreview(input: string, maxLength: number = 50): string {
@@ -30,6 +31,7 @@ export function DialogStash(props: { onSelect: (entry: StashEntry) => void }) {
3031
const dialog = useDialog()
3132
const stash = usePromptStash()
3233
const { theme } = useTheme()
34+
const tuiConfig = useTuiConfig()
3335

3436
const [toDelete, setToDelete] = createSignal<number>()
3537
const deleteHint = useCommandShortcut("stash.delete")
@@ -45,7 +47,7 @@ export function DialogStash(props: { onSelect: (entry: StashEntry) => void }) {
4547
title: isDeleting ? `Press ${deleteHint()} again to confirm` : getStashPreview(entry.input),
4648
bg: isDeleting ? theme.error : undefined,
4749
value: index,
48-
description: getRelativeTime(entry.timestamp),
50+
description: getRelativeTime(entry.timestamp, tuiConfig.datetime_format),
4951
footer: lineCount > 1 ? `~${lineCount} lines` : undefined,
5052
}
5153
})

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export const Footer = Schema.Struct({
214214
"Time from the prompt to the end of the turn. Applies to: assistant, and only on a turn's final message, so 'important' and 'assistant' select the same footers as 'all'. Default: all.",
215215
),
216216
message_id: footerElement(
217-
"The message ID (msg_...), selectable for drag-to-copy, at the end of the footer. Applies to: user, assistant, tool (the message the call belongs to). Default: none.",
217+
"The message ID (msg_...), selectable for drag-to-copy, at the end of the footer. Applies to: user, assistant, tool. A tool call shows the ID of the message it belongs to only when that message's own footer does not show it, so each ID appears once. Default: none.",
218218
),
219219
}).annotate({
220220
description: [
@@ -256,6 +256,12 @@ export function footerShows(selection: FooterSelection, type: TimestampType, lan
256256
return selection.important && landmark()
257257
}
258258

259+
// A tool call belongs to its assistant message, so its footer repeats the message ID only when the
260+
// message's own footer does not show it: each ID appears once.
261+
export function toolFooterShowsMessageID(shows: (type: "tool" | "assistant") => boolean) {
262+
return shows("tool") && !shows("assistant")
263+
}
264+
259265
// Whether the runtime toggles for an element are session-only because tui.json decides it.
260266
export function footerConfigured(config: Pick<Info, "footer" | "timestamps">, element: FooterElement) {
261267
if (config.footer?.[element] !== undefined) return true
@@ -304,6 +310,24 @@ export function footerSelections(
304310
}
305311
}
306312

313+
// Literal text is anything that is not a letter, or text in [brackets]. Letters outside the
314+
// part's own tokens are rejected, so "HH:MM:SS" (month, not minute) fails instead of misprinting.
315+
const formatLiteral = "\\[[^\\]]*\\]|[^A-Za-z\\[\\]]"
316+
const formatPattern = (tokens: string) => new RegExp(`^(?:${tokens}|${formatLiteral})+$`)
317+
export const DateTimeFormat = Schema.Struct({
318+
date: Schema.optional(Schema.String.check(Schema.isPattern(formatPattern("YYYY|YY|MM|M|DD|D")))).annotate({
319+
description:
320+
"Date pattern, shown before the time on entries from another day: YYYY year, YY two-digit year, MM month (01-12), M month (1-12), DD day (01-31), D day (1-31); other letters must be in [brackets]. Example: 'YYYY-MM-DD'. Unset: the locale's date, e.g. 10/7/2026",
321+
}),
322+
time: Schema.optional(Schema.String.check(Schema.isPattern(formatPattern("HH|H|hh|h|mm|m|ss|s|A|a")))).annotate({
323+
description:
324+
"Time pattern: HH hour 00-23, H 0-23, hh hour 01-12, h 1-12, mm minute (lowercase; MM is the month and is rejected here), m minute, ss second, s second, A AM/PM, a am/pm; other letters must be in [brackets]. Example: 'HH:mm:ss'. Unset: the locale's short time, e.g. 2:20 PM",
325+
}),
326+
}).annotate({
327+
description:
328+
"How times and dates are written in message footers, entry timestamps, the compaction divider and the timeline and stash dialogs. Entries from today show only the time",
329+
})
330+
307331
export const TranscriptMaxMessagesDefault = 100
308332
export const Transcript = Schema.Struct({
309333
max_messages: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))).annotate({
@@ -370,6 +394,7 @@ export const Info = Schema.Struct({
370394
"Legacy alias of footer.variant: true shows the variant a turn ran with, such as its reasoning effort ('high'), after the model in assistant message footers (default: false). footer.variant wins when set",
371395
}),
372396
footer: Schema.optional(Footer),
397+
datetime_format: Schema.optional(DateTimeFormat),
373398
cursor: Schema.optional(Cursor),
374399
sidebar: Schema.optional(Sidebar),
375400
usage: Schema.optional(Usage),

‎packages/tui/src/routes/session/dialog-fork-from-timeline.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSync } from "../../context/sync"
33
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
44
import type { TextPart } from "@opencode-ai/sdk/v2"
55
import { Locale } from "../../util/locale"
6+
import { useTuiConfig } from "../../config"
67
import { useSDK } from "../../context/sdk"
78
import { useRoute } from "../../context/route"
89
import { useDialog, type DialogContext } from "../../ui/dialog"
@@ -12,6 +13,7 @@ import { stripPromptPartIDs as strip } from "../../prompt/part"
1213
export function DialogForkFromTimeline(props: { sessionID: string; onMove: (messageID?: string) => void }) {
1314
const sync = useSync()
1415
const dialog = useDialog()
16+
const tuiConfig = useTuiConfig()
1517
const sdk = useSDK()
1618
const route = useRoute()
1719

@@ -43,7 +45,7 @@ export function DialogForkFromTimeline(props: { sessionID: string; onMove: (mess
4345
result.push({
4446
title: part.text.replace(/\n/g, " "),
4547
value: message.id,
46-
footer: Locale.time(message.time.created),
48+
footer: Locale.time(message.time.created, tuiConfig.datetime_format),
4749
onSelect: async (dialog) => {
4850
const forked = await sdk.client.session.fork({
4951
sessionID: props.sessionID,

‎packages/tui/src/routes/session/dialog-timeline.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSync } from "../../context/sync"
33
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
44
import type { TextPart } from "@opencode-ai/sdk/v2"
55
import { Locale } from "../../util/locale"
6+
import { useTuiConfig } from "../../config"
67
import { DialogMessage } from "./dialog-message"
78
import { useDialog } from "../../ui/dialog"
89
import type { PromptInfo } from "../../component/prompt/history"
@@ -14,6 +15,7 @@ export function DialogTimeline(props: {
1415
}) {
1516
const sync = useSync()
1617
const dialog = useDialog()
18+
const tuiConfig = useTuiConfig()
1719

1820
onMount(() => {
1921
dialog.setSize("large")
@@ -31,7 +33,7 @@ export function DialogTimeline(props: {
3133
result.push({
3234
title: part.text.replace(/\n/g, " "),
3335
value: message.id,
34-
footer: Locale.time(message.time.created),
36+
footer: Locale.time(message.time.created, tuiConfig.datetime_format),
3537
onSelect: (dialog) => {
3638
dialog.replace(() => (
3739
<DialogMessage messageID={message.id} sessionID={props.sessionID} setPrompt={props.setPrompt} />

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

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ function UserMessage(props: {
17461746
fallback={
17471747
<Show when={time()}>
17481748
<span style={{ fg: theme.textMuted }}>
1749-
{Locale.todayTimeOrDateTime(props.message.time.created)}
1749+
{Locale.todayTimeOrDateTime(props.message.time.created, ctx.tui.datetime_format)}
17501750
</span>
17511751
</Show>
17521752
}
@@ -1770,7 +1770,7 @@ function UserMessage(props: {
17701770
border={["top"]}
17711771
title={
17721772
ctx.footer("time", "compaction", props.message.id)
1773-
? ` Compaction · ${Locale.todayTimeOrDateFirst(props.message.time.created)} `
1773+
? ` Compaction · ${Locale.todayTimeOrDateFirst(props.message.time.created, ctx.tui.datetime_format)} `
17741774
: " Compaction "
17751775
}
17761776
titleAlignment="center"
@@ -1819,7 +1819,7 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
18191819
shows("agent") && { text: Locale.titlecase(props.message.mode), fg: theme.text },
18201820
shows("model") && { text: model(), fg: theme.textMuted },
18211821
shows("variant") && props.message.variant && { text: props.message.variant, fg: theme.textMuted },
1822-
shows("time") && end && { text: Locale.todayTimeOrDateFirst(end), fg: theme.textMuted },
1822+
shows("time") && end && { text: Locale.todayTimeOrDateFirst(end, ctx.tui.datetime_format), fg: theme.textMuted },
18231823
shows("duration") &&
18241824
end && { text: Locale.duration(Math.max(0, end - props.message.time.created)), fg: theme.textMuted },
18251825
shows("total") &&
@@ -1906,7 +1906,7 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
19061906
<text fg={theme.textMuted}>{errorMessage(props.message.error)}</text>
19071907
<Show when={ctx.footer("time", "error", props.message.id)}>
19081908
<text fg={theme.textMuted}>
1909-
{Locale.todayTimeOrDateFirst(props.message.time.completed ?? props.message.time.created)}
1909+
{Locale.todayTimeOrDateFirst(props.message.time.completed ?? props.message.time.created, ctx.tui.datetime_format)}
19101910
</text>
19111911
</Show>
19121912
</box>
@@ -1997,7 +1997,7 @@ function ReasoningPart(props: { last: boolean; part: ReasoningPart; message: Ass
19971997
title={summary().title}
19981998
time={
19991999
ctx.footer("time", "reasoning", props.message.id, props.part.id) && props.part.time.end !== undefined
2000-
? Locale.todayTimeOrDateFirst(props.part.time.end)
2000+
? Locale.todayTimeOrDateFirst(props.part.time.end, ctx.tui.datetime_format)
20012001
: undefined
20022002
}
20032003
duration={
@@ -2086,7 +2086,7 @@ function TextPart(props: { last: boolean; part: TextPart; message: AssistantMess
20862086
bg={theme.background}
20872087
/>
20882088
<Show when={ctx.footer("time", "text", props.message.id, props.part.id) && props.part.time?.end}>
2089-
{(end) => <text fg={theme.textMuted}>{Locale.todayTimeOrDateFirst(end())}</text>}
2089+
{(end) => <text fg={theme.textMuted}>{Locale.todayTimeOrDateFirst(end(), ctx.tui.datetime_format)}</text>}
20902090
</Show>
20912091
</box>
20922092
</Show>
@@ -2215,13 +2215,11 @@ function GenericTool(props: ToolProps) {
22152215
<BlockTool
22162216
title={`# ${props.tool} ${input(props.input)}`}
22172217
part={props.part}
2218+
hint={expandHint(collapsed().overflow, expanded())}
22182219
onClick={collapsed().overflow ? () => setExpanded((prev) => !prev) : undefined}
22192220
>
22202221
<box gap={1}>
22212222
<text fg={theme.text}>{limited()}</text>
2222-
<Show when={collapsed().overflow}>
2223-
<text fg={theme.textMuted}>{expanded() ? "Click to collapse" : "Click to expand"}</text>
2224-
</Show>
22252223
</box>
22262224
</BlockTool>
22272225
</Show>
@@ -2414,6 +2412,7 @@ export function InlineToolRow(props: {
24142412
function BlockTool(props: {
24152413
title?: string
24162414
children: JSX.Element
2415+
hint?: string
24172416
onClick?: () => void
24182417
part?: ToolPart
24192418
spinner?: boolean
@@ -2462,10 +2461,17 @@ function BlockTool(props: {
24622461
)}
24632462
</Show>
24642463
{props.children}
2464+
<Show when={props.hint}>
2465+
{(hint) => (
2466+
<text ref={markOwnIds} fg={theme.textMuted}>
2467+
{timestamp() ? `${hint()} · ${timestamp()}` : hint()}
2468+
</text>
2469+
)}
2470+
</Show>
24652471
<Show when={error()}>
24662472
<text fg={theme.error}>{error()}</text>
24672473
</Show>
2468-
<Show when={timestamp()}>
2474+
<Show when={!props.hint && timestamp()}>
24692475
<text ref={markOwnIds} paddingLeft={props.title ? 3 : 0} fg={theme.textMuted}>
24702476
{timestamp()}
24712477
</text>
@@ -2509,6 +2515,7 @@ function Shell(props: ToolProps) {
25092515
<BlockTool
25102516
title={title()}
25112517
part={props.part}
2518+
hint={expandHint(collapsed().overflow, expanded())}
25122519
onClick={collapsed().overflow ? () => setExpanded((prev) => !prev) : undefined}
25132520
>
25142521
<box gap={1}>
@@ -2518,9 +2525,6 @@ function Shell(props: ToolProps) {
25182525
<Show when={output()}>
25192526
<text fg={theme.text}>{limited()}</text>
25202527
</Show>
2521-
<Show when={collapsed().overflow}>
2522-
<text fg={theme.textMuted}>{expanded() ? "Click to collapse" : "Click to expand"}</text>
2523-
</Show>
25242528
</box>
25252529
</BlockTool>
25262530
</Match>
@@ -2744,20 +2748,32 @@ function Task(props: ToolProps) {
27442748
// The footer elements every tool call takes, whichever renderer draws it.
27452749
function toolFooter(ctx: ReturnType<typeof use>, part: ToolPart) {
27462750
const shows = (element: TuiConfig.FooterElement) => ctx.footer(element, "tool", part.messageID, part.id)
2751+
const messageID = TuiConfig.toolFooterShowsMessageID((type) =>
2752+
type === "tool" ? shows("message_id") : ctx.footer("message_id", "assistant", part.messageID),
2753+
)
27472754
return {
27482755
time: shows("time"),
27492756
duration: shows("duration"),
2750-
messageID: shows("message_id") ? part.messageID : undefined,
2757+
messageID: messageID ? part.messageID : undefined,
2758+
format: ctx.tui.datetime_format,
27512759
}
27522760
}
27532761

2762+
function expandHint(overflow: boolean, expanded: boolean) {
2763+
if (!overflow) return
2764+
return expanded ? "Click to collapse" : "Click to expand"
2765+
}
2766+
27542767
export function formatToolTimestamp(
27552768
state: ToolPart["state"],
2756-
show: { time: boolean; duration: boolean; messageID?: string } = { time: true, duration: true },
2769+
show: { time: boolean; duration: boolean; messageID?: string; format?: Locale.DateTimeFormat } = {
2770+
time: true,
2771+
duration: true,
2772+
},
27572773
) {
27582774
if (state.status !== "completed" && state.status !== "error") return
27592775
const details = [
2760-
show.time && Locale.todayTimeOrDateFirst(state.time.end),
2776+
show.time && Locale.todayTimeOrDateFirst(state.time.end, show.format),
27612777
show.duration && Locale.duration(Math.max(0, state.time.end - state.time.start)),
27622778
show.messageID,
27632779
].flatMap((detail) => (detail ? [detail] : []))

‎packages/tui/src/util/locale.ts‎

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,64 @@ export function titlecase(str: string) {
22
return str.replace(/\b\w/g, (c) => c.toUpperCase())
33
}
44

5-
export function time(input: number): string {
5+
// Patterns from tui.json `datetime_format`. Unset parts keep the runtime locale's output.
6+
export type DateTimeFormat = { date?: string; time?: string }
7+
8+
export function time(input: number, format?: DateTimeFormat): string {
9+
if (format?.time) return pattern(input, format.time)
610
const date = new Date(input)
711
return date.toLocaleTimeString(undefined, { timeStyle: "short" })
812
}
913

10-
export function datetime(input: number): string {
11-
const date = new Date(input)
12-
const localTime = time(input)
13-
const localDate = date.toLocaleDateString()
14-
return `${localTime} · ${localDate}`
14+
export function date(input: number, format?: DateTimeFormat): string {
15+
if (format?.date) return pattern(input, format.date)
16+
return new Date(input).toLocaleDateString()
1517
}
1618

17-
export function todayTimeOrDateTime(input: number): string {
19+
export function datetime(input: number, format?: DateTimeFormat): string {
20+
return `${time(input, format)} · ${date(input, format)}`
21+
}
22+
23+
export function todayTimeOrDateTime(input: number, format?: DateTimeFormat): string {
1824
if (isToday(input)) {
19-
return time(input)
25+
return time(input, format)
2026
} else {
21-
return datetime(input)
27+
return datetime(input, format)
2228
}
2329
}
2430

25-
export function todayTimeOrDateFirst(input: number): string {
26-
if (isToday(input)) return time(input)
27-
return `${new Date(input).toLocaleDateString()} ${time(input)}`
31+
export function todayTimeOrDateFirst(input: number, format?: DateTimeFormat): string {
32+
if (isToday(input)) return time(input, format)
33+
return `${date(input, format)} ${time(input, format)}`
34+
}
35+
36+
// Day.js tokens: MM is the month and mm the minute; text in [brackets] is printed as is.
37+
const PATTERN_TOKENS = /\[([^\]]*)\]|YYYY|YY|MM|M|DD|D|HH|H|hh|h|mm|m|ss|s|A|a/g
38+
39+
function pattern(input: number, format: string) {
40+
const date = new Date(input)
41+
const pad = (value: number) => String(value).padStart(2, "0")
42+
const hour12 = date.getHours() % 12 || 12
43+
const meridiem = date.getHours() < 12 ? "AM" : "PM"
44+
const values: Record<string, string> = {
45+
YYYY: String(date.getFullYear()),
46+
YY: pad(date.getFullYear() % 100),
47+
MM: pad(date.getMonth() + 1),
48+
M: String(date.getMonth() + 1),
49+
DD: pad(date.getDate()),
50+
D: String(date.getDate()),
51+
HH: pad(date.getHours()),
52+
H: String(date.getHours()),
53+
hh: pad(hour12),
54+
h: String(hour12),
55+
mm: pad(date.getMinutes()),
56+
m: String(date.getMinutes()),
57+
ss: pad(date.getSeconds()),
58+
s: String(date.getSeconds()),
59+
A: meridiem,
60+
a: meridiem.toLowerCase(),
61+
}
62+
return format.replace(PATTERN_TOKENS, (token, literal: string | undefined) => literal ?? values[token])
2863
}
2964

3065
function isToday(input: number) {

0 commit comments

Comments
 (0)