Skip to content

Commit 164da0a

Browse files
committed
feat(tui): show running tools and LLM status in sidebar
Adds a Running section to the sidebar showing LLM status (Pondering, Streaming, etc.) and active tools/agents with elapsed time. Closes anomalyco#9655 Related: anomalyco#8322, anomalyco#7093, anomalyco#5872
1 parent 4175a2b commit 164da0a

4 files changed

Lines changed: 126 additions & 174 deletions

File tree

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

Lines changed: 8 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,16 @@ import { useSync } from "@tui/context/sync"
22
import { createMemo, For, Show, Switch, Match } from "solid-js"
33
import { createStore } from "solid-js/store"
44
import { useTheme } from "../../context/theme"
5-
import { formatDuration } from "@/util/format"
5+
import { Locale } from "@/util/locale"
6+
import path from "path"
67
import type { AssistantMessage } from "@opencode-ai/sdk/v2"
8+
import { Global } from "@/global"
79
import { Installation } from "@/installation"
10+
import { useKeybind } from "../../context/keybind"
811
import { useDirectory } from "../../context/directory"
912
import { useKV } from "../../context/kv"
1013
import { TodoItem } from "../../component/todo-item"
11-
import { createRunningState } from "../../util/running"
12-
13-
function RunningToolItem(props: { command: string; startTime: number; now: number }) {
14-
const { theme } = useTheme()
15-
16-
return (
17-
<box flexDirection="row" gap={1}>
18-
<text flexShrink={0} fg={theme.warning}>
19-
●
20-
</text>
21-
<text fg={theme.text} wrapMode="none">
22-
{props.command}
23-
<span style={{ fg: theme.textMuted }}> {formatDuration(Math.floor((props.now - props.startTime) / 1000))}</span>
24-
</text>
25-
</box>
26-
)
27-
}
14+
import { createRunningState, RunningItemView } from "../../util/running.tsx"
2815

2916
export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
3017
const sync = useSync()
@@ -34,7 +21,7 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
3421
const todo = createMemo(() => sync.data.todo[props.sessionID] ?? [])
3522
const messages = createMemo(() => sync.data.message[props.sessionID] ?? [])
3623

37-
const { tick, runningTools, inferenceStatus } = createRunningState(() => props.sessionID, sync.data)
24+
const { tick, runningItems } = createRunningState(() => props.sessionID, sync.data)
3825

3926
const [expanded, setExpanded] = createStore({
4027
mcp: true,
@@ -113,88 +100,12 @@ export function Sidebar(props: { sessionID: string; overlay?: boolean }) {
113100
<text fg={theme.textMuted}>{context()?.percentage ?? 0}% used</text>
114101
<text fg={theme.textMuted}>{cost()} spent</text>
115102
</box>
116-
<Show when={runningTools().length > 0 || inferenceStatus()}>
103+
<Show when={runningItems().length > 0}>
117104
<box>
118105
<text fg={theme.text}>
119106
<b>Running</b>
120107
</text>
121-
<Show when={inferenceStatus()}>
122-
{(status) => (
123-
<Switch>
124-
<Match when={status().type === "sending"}>
125-
<box flexDirection="row" gap={1}>
126-
<text flexShrink={0} fg={theme.warning}>
127-
●
128-
</text>
129-
<text fg={theme.text} wrapMode="none">
130-
Sending...
131-
<span style={{ fg: theme.textMuted }}>
132-
{" "}
133-
{formatDuration(
134-
Math.floor(
135-
(tick() - (status() as { type: "sending"; startTime: number }).startTime) / 1000,
136-
),
137-
)}
138-
</span>
139-
</text>
140-
</box>
141-
</Match>
142-
<Match when={status().type === "pondering"}>
143-
<box flexDirection="row" gap={1}>
144-
<text flexShrink={0} fg={theme.warning}>
145-
●
146-
</text>
147-
<text fg={theme.text} wrapMode="none">
148-
Pondering...
149-
<span style={{ fg: theme.textMuted }}>
150-
{" "}
151-
{formatDuration(
152-
Math.floor(
153-
(tick() - (status() as { type: "pondering"; startTime: number }).startTime) / 1000,
154-
),
155-
)}
156-
</span>
157-
</text>
158-
</box>
159-
</Match>
160-
<Match when={status().type === "streaming"}>
161-
<box flexDirection="row" gap={1}>
162-
<text flexShrink={0} fg={theme.warning}>
163-
●
164-
</text>
165-
<text fg={theme.text} wrapMode="none">
166-
Streaming...
167-
<span style={{ fg: theme.textMuted }}>
168-
{" "}
169-
{formatDuration(
170-
Math.floor(
171-
(tick() - (status() as { type: "streaming"; startTime: number }).startTime) / 1000,
172-
),
173-
)}
174-
</span>
175-
</text>
176-
</box>
177-
</Match>
178-
<Match when={status().type === "retry"}>
179-
<box flexDirection="row" gap={1}>
180-
<text flexShrink={0} fg={theme.warning}>
181-
●
182-
</text>
183-
<text fg={theme.text} wrapMode="none">
184-
Retrying in {(status() as { type: "retry"; message: string; remaining: number }).remaining}s
185-
<span style={{ fg: theme.textMuted }}>
186-
{" "}
187-
({(status() as { type: "retry"; message: string; remaining: number }).message})
188-
</span>
189-
</text>
190-
</box>
191-
</Match>
192-
</Switch>
193-
)}
194-
</Show>
195-
<For each={runningTools()}>
196-
{(item) => <RunningToolItem command={item.command} startTime={item.startTime} now={tick()} />}
197-
</For>
108+
<For each={runningItems()}>{(item) => <RunningItemView item={item} now={tick()} />}</For>
198109
</box>
199110
</Show>
200111
<Show when={mcpEntries().length > 0}>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const MAX_LEN = 40
2+
export const RUNNING_THRESHOLD_MS = 2000
3+
4+
export type RunningItem = {
5+
id: string
6+
label: string
7+
startTime: number
8+
suffix?: string
9+
}
10+
11+
export function extractToolCommand(tool: string, input: Record<string, unknown>): string {
12+
let cmd = ""
13+
14+
switch (tool) {
15+
case "bash":
16+
cmd = (input.command as string) || "bash"
17+
break
18+
case "grep":
19+
cmd = `rg "${input.pattern}"${input.path ? ` ${input.path}` : ""}`
20+
break
21+
case "glob":
22+
cmd = `glob ${input.pattern}`
23+
break
24+
case "read":
25+
cmd = `read ${(input.filePath as string)?.split("/").pop() || input.filePath}`
26+
break
27+
case "write":
28+
cmd = `write ${(input.filePath as string)?.split("/").pop() || input.filePath}`
29+
break
30+
case "edit":
31+
cmd = `edit ${(input.filePath as string)?.split("/").pop() || input.filePath}`
32+
break
33+
case "task":
34+
cmd = `agent: ${(input.description as string) || "..."}`
35+
break
36+
case "webfetch":
37+
cmd = `fetch ${input.url}`
38+
break
39+
default:
40+
cmd = (input.title as string) || tool
41+
}
42+
43+
return cmd.length > MAX_LEN ? cmd.slice(0, MAX_LEN - 3) + "..." : cmd
44+
}

0 commit comments

Comments
 (0)