Skip to content

Commit fbd4c26

Browse files
anandgupta42claude
andcommitted
fix: consolidate /trace command and improve trace list display
- Merge `/trace` and `/traces` into single `/trace` command that always shows the trace list with current session highlighted - Fix two-line entry rendering: extract first meaningful line from title, strip markdown headings and quotes - Prefer `prompt` over `title` in metadata (prompt has actual user request) - Simplify display to title + duration + time (no cramped inline stats) - Remove `/traces` sidebar hint (single command now) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 14358b5 commit fbd4c26

3 files changed

Lines changed: 34 additions & 55 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -662,34 +662,14 @@ function App() {
662662
onSelect: () => exit(),
663663
category: "System",
664664
},
665+
// altimate_change start - trace history command
665666
{
666-
title: "View session trace",
667+
title: "View traces",
667668
value: "trace.view",
668669
category: "Debug",
669670
slash: {
670671
name: "trace",
671672
},
672-
onSelect: (dialog) => {
673-
const sessionID = route.data.type === "session" ? route.data.sessionID : undefined
674-
if (!sessionID) {
675-
// No active session — show trace history instead
676-
dialog.replace(() => (
677-
<DialogTraceList onSelect={openTraceInBrowser} />
678-
))
679-
return
680-
}
681-
openTraceInBrowser(sessionID)
682-
dialog.clear()
683-
},
684-
},
685-
// altimate_change start - trace history command
686-
{
687-
title: "View trace history",
688-
value: "trace.list",
689-
category: "Debug",
690-
slash: {
691-
name: "traces",
692-
},
693673
onSelect: (dialog) => {
694674
const currentSessionID = route.data.type === "session" ? route.data.sessionID : undefined
695675
dialog.replace(() => (

‎packages/opencode/src/cli/cmd/tui/component/dialog-trace-list.tsx‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
// altimate_change start - trace history dialog
22
import { useDialog } from "@tui/ui/dialog"
33
import { DialogSelect } from "@tui/ui/dialog-select"
4-
import { createMemo, createResource, onMount, Show } from "solid-js"
4+
import { createMemo, createResource, onMount } from "solid-js"
55
import { Tracer } from "@/altimate/observability/tracing"
66
import { Locale } from "@/util/locale"
77

8+
function cleanTitle(raw: string): string {
9+
// Strip quotes, markdown headings, and take first non-empty line
10+
const stripped = raw.replace(/^["'`]+|["'`]+$/g, "").trim()
11+
const lines = stripped.split("\n").map((l) => l.replace(/^#+\s*/, "").trim()).filter(Boolean)
12+
return lines.find((l) => l.length > 5) || lines[0] || stripped
13+
}
14+
815
function formatDuration(ms: number): string {
916
if (ms < 1000) return `${ms}ms`
1017
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`
@@ -13,11 +20,6 @@ function formatDuration(ms: number): string {
1320
return `${mins}m${secs}s`
1421
}
1522

16-
function formatCost(cost: number): string {
17-
if (cost < 0.01) return `$${cost.toFixed(4)}`
18-
return `$${cost.toFixed(2)}`
19-
}
20-
2123
export function DialogTraceList(props: {
2224
currentSessionID?: string
2325
onSelect: (sessionID: string) => void
@@ -44,35 +46,33 @@ export function DialogTraceList(props: {
4446
const today = new Date().toDateString()
4547

4648
return items.slice(0, 50).map((item) => {
47-
const date = new Date(item.trace.startedAt)
48-
let category = date.toDateString()
49-
if (category === today) {
50-
category = "Today"
51-
}
49+
const date = new Date(item.trace.startedAt)
50+
let category = date.toDateString()
51+
if (category === today) {
52+
category = "Today"
53+
}
5254

53-
const title = item.trace.metadata?.title || item.trace.metadata?.prompt?.slice(0, 60) || item.sessionId
55+
const rawTitle = item.trace.metadata?.prompt || item.trace.metadata?.title || item.sessionId
56+
const title = cleanTitle(rawTitle).slice(0, 80)
5457

55-
const summary = item.trace.summary
56-
const status = summary?.status
57-
const statusLabel =
58-
status === "error" || status === "crashed"
59-
? `[${status}] `
60-
: status === "running"
61-
? "[running] "
62-
: ""
58+
const summary = item.trace.summary
59+
const status = summary?.status
60+
const statusLabel =
61+
status === "error" || status === "crashed"
62+
? `[${status}] `
63+
: status === "running"
64+
? "[running] "
65+
: ""
6366

64-
const duration = formatDuration(summary?.duration ?? 0)
65-
const cost = formatCost(summary?.totalCost ?? 0)
66-
const tokens = (summary?.totalTokens ?? 0).toLocaleString()
67-
const tools = summary?.totalToolCalls ?? 0
67+
const duration = formatDuration(summary?.duration ?? 0)
6868

69-
return {
70-
title: `${statusLabel}${title}`,
71-
value: item.sessionId,
72-
category,
73-
footer: `${Locale.time(date.getTime())} · ${duration} · ${tokens} tokens · ${cost} · ${tools} tools`,
74-
}
75-
})
69+
return {
70+
title: `${statusLabel}${title}`,
71+
value: item.sessionId,
72+
category,
73+
footer: `${duration} ${Locale.time(date.getTime())}`,
74+
}
75+
})
7676
})
7777

7878
onMount(() => {
@@ -81,7 +81,7 @@ export function DialogTraceList(props: {
8181

8282
return (
8383
<DialogSelect
84-
title={traces.state === "pending" ? "Trace History (loading...)" : "Trace History"}
84+
title={traces.state === "pending" ? "Traces (loading...)" : "Traces"}
8585
options={options()}
8686
current={props.currentSessionID}
8787
onSelect={(option) => {

‎packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
114114
<b>Trace</b>
115115
</text>
116116
<text fg={theme.textMuted}>type <span style={{ fg: theme.accent }}>/trace</span> to view</text>
117-
<text fg={theme.textMuted}>type <span style={{ fg: theme.accent }}>/traces</span> for history</text>
118117
</box>
119118
{/* altimate_change end */}
120119
<Show when={mcpEntries().length > 0}>

0 commit comments

Comments
 (0)