Skip to content

Commit 459e2b4

Browse files
Joeseph GreyJoeseph Grey
authored andcommitted
fix(opencode): collect nested subagent sessions in TUI sidebar
children() only looked one level deep — subagents spawning subagents were invisible because their parentID pointed to the intermediate session, not the root. Walk up to root and BFS-collect all descendants. Fixes anomalyco#4422
1 parent 48412f7 commit 459e2b4

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/routes/session

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,37 @@ export function Session() {
122122
const { theme } = useTheme()
123123
const promptRef = usePromptRef()
124124
const session = createMemo(() => sync.session.get(route.sessionID))
125+
const root = createMemo(() => {
126+
let current = session()
127+
while (current?.parentID) {
128+
const parent = sync.session.get(current.parentID)
129+
if (!parent) break
130+
current = parent
131+
}
132+
return current
133+
})
125134
const children = createMemo(() => {
126-
const parentID = session()?.parentID ?? session()?.id
135+
const r = root()
136+
if (!r) return []
137+
// Build parent->children index then collect all descendants
138+
const byParent = new Map<string, string[]>()
139+
for (const x of sync.data.session) {
140+
if (!x.parentID) continue
141+
const siblings = byParent.get(x.parentID)
142+
if (siblings) siblings.push(x.id)
143+
else byParent.set(x.parentID, [x.id])
144+
}
145+
const ids = new Set([r.id])
146+
const queue = [r.id]
147+
while (queue.length) {
148+
for (const child of byParent.get(queue.pop()!) ?? []) {
149+
if (ids.has(child)) continue
150+
ids.add(child)
151+
queue.push(child)
152+
}
153+
}
127154
return sync.data.session
128-
.filter((x) => x.parentID === parentID || x.id === parentID)
155+
.filter((x) => ids.has(x.id))
129156
.toSorted((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
130157
})
131158
const messages = createMemo(() => sync.data.message[route.sessionID] ?? [])

0 commit comments

Comments
 (0)