Skip to content

Commit b4cf0bc

Browse files
authored
Merge pull request anomalyco#66 from kcrommett/add-subagent-sidebar
Merge PR anomalyco#4865: Subagents sidebar with clickable navigation
2 parents cb4ded1 + ba0dcce commit b4cf0bc

8 files changed

Lines changed: 144 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ This fork serves as an integration testing ground for upstream PRs before they a
1010

1111
The following PRs have been merged into this fork and are awaiting merge into upstream:
1212

13-
| PR | Title | Status | Description |
14-
| -------------------------------------------------- | --------------------------------- | ------ | ------------------------------------------------------------------ |
15-
| [#4898](https://github.com/sst/opencode/pull/4898) | Search in messages | Open | Ctrl+F to search through session messages with highlighting |
16-
| [#4791](https://github.com/sst/opencode/pull/4791) | Bash output with ANSI | Open | Full terminal emulation for bash output with color support |
17-
| [#4900](https://github.com/sst/opencode/pull/4900) | Double Ctrl+C to exit | Open | Require double Ctrl+C within 2 seconds to prevent accidental exits |
18-
| [#4709](https://github.com/sst/opencode/pull/4709) | Live token usage during streaming | Open | Real-time token tracking and display during model responses |
19-
| [#4773](https://github.com/sst/opencode/pull/4773) | Configurable subagent visibility | Open | Allow agents to restrict which subagents they can invoke |
20-
21-
_Last updated: 2025-11-29_
13+
| PR | Title | Status | Description |
14+
| -------------------------------------------------- | ------------------------------------------- | ------ | ------------------------------------------------------------------- |
15+
| [#4898](https://github.com/sst/opencode/pull/4898) | Search in messages | Open | Ctrl+F to search through session messages with highlighting |
16+
| [#4791](https://github.com/sst/opencode/pull/4791) | Bash output with ANSI | Open | Full terminal emulation for bash output with color support |
17+
| [#4900](https://github.com/sst/opencode/pull/4900) | Double Ctrl+C to exit | Open | Require double Ctrl+C within 2 seconds to prevent accidental exits |
18+
| [#4709](https://github.com/sst/opencode/pull/4709) | Live token usage during streaming | Open | Real-time token tracking and display during model responses |
19+
| [#4773](https://github.com/sst/opencode/pull/4773) | Configurable subagent visibility | Open | Allow agents to restrict which subagents they can invoke |
20+
| [#4865](https://github.com/sst/opencode/pull/4865) | Subagents sidebar with clickable navigation | Open | Show subagents in sidebar with click-to-navigate and parent keybind |
21+
22+
_Last updated: 2025-11-30_
2223

2324
---
2425

‎flake.lock‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export function Header() {
8181
<text fg={theme.text}>
8282
<b>Subagent session</b>
8383
</text>
84+
<text fg={theme.text}>
85+
Parent <span style={{ fg: theme.textMuted }}>{keybind.print("session_parent" as any)}</span>
86+
</text>
8487
<text fg={theme.text}>
8588
Prev <span style={{ fg: theme.textMuted }}>{keybind.print("session_child_cycle_reverse")}</span>
8689
</text>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ export function Session() {
379379
}
380380
}
381381

382+
function goToParent() {
383+
const parentID = session()?.parentID
384+
if (parentID) {
385+
navigate({ type: "session", sessionID: parentID })
386+
}
387+
}
388+
382389
const command = useCommandDialog()
383390
command.register(() => [
384391
{
@@ -849,6 +856,17 @@ export function Session() {
849856
dialog.clear()
850857
},
851858
},
859+
{
860+
title: "Go to parent session",
861+
value: "session.parent",
862+
keybind: "session_parent" as any,
863+
category: "Session",
864+
disabled: !session()?.parentID,
865+
onSelect: (dialog) => {
866+
goToParent()
867+
dialog.clear()
868+
},
869+
},
852870
])
853871

854872
const revertInfo = createMemo(() => session()?.revert)

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

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { useSync } from "@tui/context/sync"
2-
import { createMemo, For, Show, Switch, Match } from "solid-js"
2+
import { createMemo, For, Show, Switch, Match, createSignal, onCleanup } from "solid-js"
33
import { createStore } from "solid-js/store"
44
import { useTheme } from "../../context/theme"
5+
import { useRoute } from "../../context/route"
56
import { Locale } from "@/util/locale"
67
import path from "path"
7-
import type { AssistantMessage } from "@opencode-ai/sdk"
8-
import { Global } from "@/global"
8+
import type { AssistantMessage, ToolPart } from "@opencode-ai/sdk"
99
import { Installation } from "@/installation"
10-
import { useKeybind } from "../../context/keybind"
1110
import { useDirectory } from "../../context/directory"
1211

1312
export function Sidebar(props: { sessionID: string }) {
1413
const sync = useSync()
14+
const route = useRoute()
1515
const { theme } = useTheme()
1616
const session = createMemo(() => sync.session.get(props.sessionID)!)
1717
const diff = createMemo(() => sync.data.session_diff[props.sessionID] ?? [])
@@ -23,11 +23,43 @@ export function Sidebar(props: { sessionID: string }) {
2323
diff: true,
2424
todo: true,
2525
lsp: true,
26+
subagents: true,
2627
})
2728

29+
// Animated spinner
30+
const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
31+
const [spinnerIndex, setSpinnerIndex] = createSignal(0)
32+
33+
const intervalId = setInterval(() => {
34+
setSpinnerIndex((prev) => (prev + 1) % spinnerFrames.length)
35+
}, 100)
36+
onCleanup(() => clearInterval(intervalId))
37+
2838
// Sort MCP servers alphabetically for consistent display order
2939
const mcpEntries = createMemo(() => Object.entries(sync.data.mcp).sort(([a], [b]) => a.localeCompare(b)))
3040

41+
const taskToolParts = createMemo(() => {
42+
const parts: ToolPart[] = []
43+
for (const message of messages()) {
44+
for (const part of sync.data.part[message.id] ?? []) {
45+
if (part.type === "tool" && part.tool === "task") parts.push(part)
46+
}
47+
}
48+
return parts
49+
})
50+
51+
const subagentGroups = createMemo(() => {
52+
const groups = new Map<string, ToolPart[]>()
53+
for (const part of taskToolParts()) {
54+
const input = part.state.input as Record<string, unknown>
55+
const agentName = input?.subagent_type as string
56+
if (!agentName) continue
57+
if (!groups.has(agentName)) groups.set(agentName, [])
58+
groups.get(agentName)!.push(part)
59+
}
60+
return Array.from(groups.entries())
61+
})
62+
3163
const cost = createMemo(() => {
3264
const total = messages().reduce((sum, x) => sum + (x.role === "assistant" ? x.cost : 0), 0)
3365
return new Intl.NumberFormat("en-US", {
@@ -48,7 +80,6 @@ export function Sidebar(props: { sessionID: string }) {
4880
}
4981
})
5082

51-
const keybind = useKeybind()
5283
const directory = useDirectory()
5384

5485
const hasProviders = createMemo(() =>
@@ -129,6 +160,73 @@ export function Sidebar(props: { sessionID: string }) {
129160
</Show>
130161
</box>
131162
</Show>
163+
<Show when={subagentGroups().length > 0}>
164+
<box>
165+
<box
166+
flexDirection="row"
167+
gap={1}
168+
onMouseDown={() => subagentGroups().length > 2 && setExpanded("subagents", !expanded.subagents)}
169+
>
170+
<Show when={subagentGroups().length > 2}>
171+
<text fg={theme.text}>{expanded.subagents ? "▼" : "▶"}</text>
172+
</Show>
173+
<text fg={theme.text}>
174+
<b>Subagents</b>
175+
</text>
176+
</box>
177+
<Show when={subagentGroups().length <= 2 || expanded.subagents}>
178+
<For each={subagentGroups()}>
179+
{([agentName, parts]) => {
180+
const hasActive = () =>
181+
parts.some((p) => p.state.status === "running" || p.state.status === "pending")
182+
return (
183+
<box>
184+
<box flexDirection="row" gap={1}>
185+
<text flexShrink={0} style={{ fg: hasActive() ? theme.success : theme.text }}>
186+
•
187+
</text>
188+
<text fg={theme.text} wrapMode="word">
189+
{agentName}
190+
</text>
191+
</box>
192+
<For each={parts}>
193+
{(part) => {
194+
const isActive = () => part.state.status === "running" || part.state.status === "pending"
195+
const isError = () => part.state.status === "error"
196+
const input = part.state.input as Record<string, unknown>
197+
const description = (input?.description as string) ?? ""
198+
const stateMetadata = (part.state as { metadata?: Record<string, unknown> }).metadata
199+
const sessionId = (part.metadata?.sessionId ?? stateMetadata?.sessionId) as
200+
| string
201+
| undefined
202+
return (
203+
<box
204+
flexDirection="row"
205+
gap={1}
206+
paddingLeft={2}
207+
onMouseUp={(e) => {
208+
if (e.button === 0 && sessionId) {
209+
route.navigate({ type: "session", sessionID: sessionId })
210+
}
211+
}}
212+
>
213+
<text flexShrink={0} fg={isActive() ? theme.success : theme.textMuted}>
214+
{isActive() ? spinnerFrames[spinnerIndex()] : isError() ? "✗" : "✓"}
215+
</text>
216+
<text fg={isActive() ? theme.text : theme.textMuted} wrapMode="word">
217+
{description}
218+
</text>
219+
</box>
220+
)
221+
}}
222+
</For>
223+
</box>
224+
)
225+
}}
226+
</For>
227+
</Show>
228+
</box>
229+
</Show>
132230
<box>
133231
<box
134232
flexDirection="row"

‎packages/opencode/src/config/config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ export namespace Config {
442442
history_next: z.string().optional().default("down").describe("Next history item"),
443443
session_child_cycle: z.string().optional().default("<leader>right").describe("Next child session"),
444444
session_child_cycle_reverse: z.string().optional().default("<leader>left").describe("Previous child session"),
445+
session_parent: z.string().optional().default("<leader>up").describe("Go to parent session"),
445446
terminal_suspend: z.string().optional().default("ctrl+z").describe("Suspend terminal"),
446447
})
447448
.strict()

‎packages/sdk/js/src/gen/types.gen.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ export type KeybindsConfig = {
870870
* Previous child session
871871
*/
872872
session_child_cycle_reverse?: string
873+
/**
874+
* Go to parent session
875+
*/
876+
session_parent?: string
873877
/**
874878
* Suspend terminal
875879
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ A general-purpose agent for researching complex questions, searching for code, a
8989
```
9090

9191
3. **Navigation between sessions**: When subagents create their own child sessions, you can navigate between the parent session and all child sessions using:
92+
- **\<Leader>+Up** (or your configured `session_parent` keybind) to go directly to the parent session
9293
- **\<Leader>+Right** (or your configured `session_child_cycle` keybind) to cycle forward through parent → child1 → child2 → ... → parent
9394
- **\<Leader>+Left** (or your configured `session_child_cycle_reverse` keybind) to cycle backward through parent ← child1 ← child2 ← ... ← parent
9495

95-
This allows you to seamlessly switch between the main conversation and specialized subagent work.
96+
You can also click on any subagent task in the sidebar to navigate directly to that subagent's session.
9697

9798
---
9899

0 commit comments

Comments
 (0)