Skip to content

Commit 59742fb

Browse files
val-2actions-user
andauthored
Showed end time for agent loop and changed message time to show date if not current day (#4503)
Co-authored-by: GitHub Action <[email protected]>
1 parent 2938a25 commit 59742fb

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

nix/hashes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"nodeModules": "sha256-krj85tYW0P/YOnsXnO1cD5XkLtfWZzdXzj7CTNvsPPk="
2+
"nodeModules": "sha256-N33FQyKF6IgGIRZ8NFd9o1/sjHMwbQ6KQcnMFyN0WmI="
33
}

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const context = createContext<{
7979
width: number
8080
conceal: () => boolean
8181
showThinking: () => boolean
82+
showTimestamps: () => boolean
8283
}>()
8384

8485
function use() {
@@ -109,6 +110,7 @@ export function Session() {
109110
const [sidebar, setSidebar] = createSignal<"show" | "hide" | "auto">(kv.get("sidebar", "auto"))
110111
const [conceal, setConceal] = createSignal(true)
111112
const [showThinking, setShowThinking] = createSignal(true)
113+
const [showTimestamps, setShowTimestamps] = createSignal(kv.get("timestamps", "hide") === "show")
112114

113115
const wide = createMemo(() => dimensions().width > 120)
114116
const sidebarVisible = createMemo(() => sidebar() === "show" || (sidebar() === "auto" && wide()))
@@ -403,6 +405,19 @@ export function Session() {
403405
dialog.clear()
404406
},
405407
},
408+
{
409+
title: "Toggle timestamps",
410+
value: "session.toggle.timestamps",
411+
category: "Session",
412+
onSelect: (dialog) => {
413+
setShowTimestamps((prev) => {
414+
const next = !prev
415+
kv.set("timestamps", next ? "show" : "hide")
416+
return next
417+
})
418+
dialog.clear()
419+
},
420+
},
406421
{
407422
title: "Toggle thinking blocks",
408423
value: "session.toggle.thinking",
@@ -712,6 +727,7 @@ export function Session() {
712727
},
713728
conceal,
714729
showThinking,
730+
showTimestamps,
715731
}}
716732
>
717733
<box flexDirection="row" paddingBottom={1} paddingTop={1} paddingLeft={2} paddingRight={2} gap={2}>
@@ -891,6 +907,7 @@ function UserMessage(props: {
891907
index: number
892908
pending?: string
893909
}) {
910+
const ctx = use()
894911
const text = createMemo(() => props.parts.flatMap((x) => (x.type === "text" && !x.synthetic ? [x] : []))[0])
895912
const files = createMemo(() => props.parts.flatMap((x) => (x.type === "file" ? [x] : [])))
896913
const sync = useSync()
@@ -949,7 +966,13 @@ function UserMessage(props: {
949966
{sync.data.config.username ?? "You"}{" "}
950967
<Show
951968
when={queued()}
952-
fallback={<span style={{ fg: theme.textMuted }}>{Locale.time(props.message.time.created)}</span>}
969+
fallback={
970+
<span style={{ fg: theme.textMuted }}>
971+
{ctx.showTimestamps()
972+
? ${Locale.todayTimeOrDateTime(props.message.time.created)}`
973+
: ${Locale.time(props.message.time.created)}`}
974+
</span>
975+
}
953976
>
954977
<span style={{ bg: theme.accent, fg: theme.backgroundPanel, bold: true }}> QUEUED </span>
955978
</Show>
@@ -973,6 +996,7 @@ function UserMessage(props: {
973996
function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; last: boolean }) {
974997
const local = useLocal()
975998
const { theme } = useTheme()
999+
const ctx = use()
9761000
return (
9771001
<>
9781002
<For each={props.parts}>
@@ -1015,7 +1039,12 @@ function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; las
10151039
<box paddingLeft={3}>
10161040
<text marginTop={1}>
10171041
<span style={{ fg: local.agent.color(props.message.mode) }}>{Locale.titlecase(props.message.mode)}</span>{" "}
1018-
<span style={{ fg: theme.textMuted }}>{props.message.modelID}</span>
1042+
<span style={{ fg: theme.textMuted }}>
1043+
{props.message.modelID}
1044+
{ctx.showTimestamps() &&
1045+
props.message.time.completed &&
1046+
` · ${Locale.todayTimeOrDateTime(props.message.time.completed)}`}
1047+
</span>
10191048
</text>
10201049
</box>
10211050
</Match>

packages/opencode/src/util/locale.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@ export namespace Locale {
33
return str.replace(/\b\w/g, (c) => c.toUpperCase())
44
}
55

6-
export function time(input: number) {
6+
export function time(input: number): string {
77
const date = new Date(input)
8-
return date.toLocaleTimeString()
8+
return date.toLocaleTimeString(undefined, { timeStyle: "short" })
9+
}
10+
11+
export function datetime(input: number): string {
12+
const date = new Date(input)
13+
const localTime = time(input)
14+
const localDate = date.toLocaleDateString()
15+
return `${localTime} · ${localDate}`
16+
}
17+
18+
export function todayTimeOrDateTime(input: number): string {
19+
const date = new Date(input)
20+
const now = new Date()
21+
const isToday =
22+
date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()
23+
24+
if (isToday) {
25+
return time(input)
26+
} else {
27+
return datetime(input)
28+
}
929
}
1030

1131
export function number(num: number): string {

0 commit comments

Comments
 (0)