refactor(graph-layout): update subagent session filtering logic

- Revised the filtering logic for subagent sessions in the layoutGraph function to exclude empty sessions that lack associated actions or execs. This change enhances the accuracy of session representation in the graph layout by ensuring only relevant sessions are displayed.
This commit is contained in:
Luciano Castillo
2026-01-29 15:49:09 -05:00
parent aded6fa1e5
commit 8d417e2d18
+11 -11
View File
@@ -67,17 +67,6 @@ export function layoutGraph(
.filter((n) => n.type === 'session')
.map((n) => n.data as unknown as MonitorSession)
// Filter out orphan subagents:
// - Subagent sessions (by key) must have a valid parent in the list
// - Non-subagents are shown if they have no parent or a valid parent
const sessions = allSessions.filter(s => {
const isSubagent = s.key.includes('subagent')
if (isSubagent) {
return s.spawnedBy && allSessions.some(p => p.key === s.spawnedBy)
}
return !s.spawnedBy || allSessions.some(p => p.key === s.spawnedBy)
})
const actions = nodes
.filter((n) => n.type === 'action')
.map((n) => ({ id: n.id.replace('action-', ''), data: n.data as unknown as MonitorAction }))
@@ -86,6 +75,17 @@ export function layoutGraph(
.filter((n) => n.type === 'exec')
.map((n) => ({ id: n.id.replace('exec-', ''), data: n.data as unknown as MonitorExecProcess }))
// Filter out empty subagent sessions (no actions or execs attached)
const sessions = allSessions.filter(s => {
const isSubagent = s.key.includes('subagent')
if (isSubagent) {
const hasActions = actions.some(a => a.data.sessionKey === s.key)
const hasExecs = execs.some(e => e.data.sessionKey === s.key)
return hasActions || hasExecs
}
return true
})
const crabNode = nodes.find((n) => n.type === 'crab')
// Build session column map - which column is each session in?