Skip to content

Commit 407dbe8

Browse files
committed
[Stage 1/3] Add recursive descendant collection for nested sub-agent questions
Implement recursive session tree traversal to collect questions and permissions from all descendant sessions (grandchildren, great-grandchildren, etc.), not just direct children. This fixes issue anomalyco#7654 where questions from deeply nested sub-agents don't appear in the TUI. - Add descendants() memo with recursive collect function - Update permissions() and questions() memos to use descendants() - Add circular reference protection with visited Set - Preserve backward compatibility by keeping children() memo unchanged
1 parent a5c058e commit 407dbe8

1 file changed

Lines changed: 20 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: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,32 @@ export function Session() {
118118
.filter((x) => x.parentID === parentID || x.id === parentID)
119119
.toSorted((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
120120
})
121+
122+
// Recursively collect all descendant session IDs
123+
const descendants = createMemo(() => {
124+
const collect = (id: string, visited: Set<string>): string[] => {
125+
if (visited.has(id)) return []
126+
visited.add(id)
127+
128+
const directChildren = sync.data.session.filter((x) => x.parentID === id).map((x) => x.id)
129+
130+
return [id, ...directChildren.flatMap((childID) => collect(childID, visited))]
131+
}
132+
133+
const root = session()?.parentID ?? session()?.id
134+
return root ? collect(root, new Set()) : []
135+
})
136+
121137
const messages = createMemo(() => sync.data.message[route.sessionID] ?? [])
138+
122139
const permissions = createMemo(() => {
123140
if (session()?.parentID) return []
124-
return children().flatMap((x) => sync.data.permission[x.id] ?? [])
141+
return descendants().flatMap((x) => sync.data.permission[x] ?? [])
125142
})
143+
126144
const questions = createMemo(() => {
127145
if (session()?.parentID) return []
128-
return children().flatMap((x) => sync.data.question[x.id] ?? [])
146+
return descendants().flatMap((x) => sync.data.question[x] ?? [])
129147
})
130148

131149
const pending = createMemo(() => {

0 commit comments

Comments
 (0)