@@ -34,6 +34,34 @@ function firstSentenceFallback(prompt: string): string | undefined {
3434 return cleaned . length > 0 ? truncate ( cleaned ) : undefined ;
3535}
3636
37+ interface SubagentMeta {
38+ description ?: string ;
39+ agentType ?: string ;
40+ }
41+
42+ /**
43+ * Read the sibling `agent-*.meta.json` the CLI writes next to each subagent
44+ * transcript. Classic Task subagents carry `description` + `agentType`;
45+ * workflow agents usually only `agentType` (the generic `workflow-subagent`
46+ * value carries no information and is dropped).
47+ */
48+ async function readSubagentMeta ( filePath : string ) : Promise < SubagentMeta > {
49+ const metaFile = Bun . file ( filePath . replace ( / \. j s o n l $ / , '.meta.json' ) ) ;
50+ try {
51+ if ( ! ( await metaFile . exists ( ) ) ) return { } ;
52+ const meta = ( await metaFile . json ( ) ) as { description ?: unknown ; agentType ?: unknown } ;
53+ const description = typeof meta . description === 'string' && meta . description . length > 0
54+ ? meta . description
55+ : undefined ;
56+ const agentType = typeof meta . agentType === 'string' && meta . agentType . length > 0 && meta . agentType !== 'workflow-subagent'
57+ ? meta . agentType
58+ : undefined ;
59+ return { description, agentType } ;
60+ } catch {
61+ return { } ;
62+ }
63+ }
64+
3765function readFirstLineContent ( text : string ) : string | undefined {
3866 const [ firstLine ] = text . split ( '\n' , 1 ) ;
3967 if ( firstLine === undefined || firstLine . trim ( ) === '' ) return undefined ;
@@ -74,11 +102,14 @@ function matchAgentLabel(parentText: string, targetPrompt: string): string | und
74102/**
75103 * Given a subagent JSONL path (`.../<parentSessionId>/subagents/agent-*.jsonl`,
76104 * or the ultra-mode variant `.../<parentSessionId>/subagents/workflows/wf_<runId>/agent-*.jsonl`),
77- * return a human-readable label by correlating the child's first user prompt
78- * against the parent's `Agent` tool_use invocations. Falls back to the first
79- * sentence of the subagent prompt when the parent can't be found or doesn't
80- * carry an exact prompt match — always the case for workflow agents, whose
81- * prompts live in the Workflow script rather than in the parent transcript.
105+ * return a human-readable label. Tiers, best first:
106+ *
107+ * 1. `description` from the sibling `agent-*.meta.json`
108+ * 2. the parent's matching `Agent` tool_use (description / subagent_type)
109+ * 3. `agentType` from meta.json combined with the prompt's first sentence —
110+ * the only informative pair for workflow agents, whose prompts live in
111+ * the Workflow script rather than in the parent transcript
112+ * 4. the first sentence of the subagent prompt
82113 *
83114 * Returns `undefined` for non-subagent paths or when nothing usable is available.
84115 */
@@ -90,6 +121,9 @@ export async function resolveSubagentLabel(filePath: string): Promise<string | u
90121 }
91122 if ( basename ( subagentsDir ) !== 'subagents' ) return undefined ;
92123
124+ const meta = await readSubagentMeta ( filePath ) ;
125+ if ( meta . description !== undefined ) return truncate ( meta . description ) ;
126+
93127 const parentSessionDir = dirname ( subagentsDir ) ;
94128 const projectDir = dirname ( parentSessionDir ) ;
95129 const parentSessionId = basename ( parentSessionDir ) ;
@@ -99,14 +133,19 @@ export async function resolveSubagentLabel(filePath: string): Promise<string | u
99133 if ( ! ( await childFile . exists ( ) ) ) return undefined ;
100134 const childText = await childFile . text ( ) ;
101135 const prompt = readFirstLineContent ( childText ) ;
102- if ( prompt === undefined ) return undefined ;
103136
104- const parentFile = Bun . file ( parentPath ) ;
105- if ( await parentFile . exists ( ) ) {
106- const parentText = await parentFile . text ( ) ;
107- const matched = matchAgentLabel ( parentText , prompt ) ;
108- if ( matched !== undefined ) return matched ;
137+ if ( prompt !== undefined ) {
138+ const parentFile = Bun . file ( parentPath ) ;
139+ if ( await parentFile . exists ( ) ) {
140+ const parentText = await parentFile . text ( ) ;
141+ const matched = matchAgentLabel ( parentText , prompt ) ;
142+ if ( matched !== undefined ) return matched ;
143+ }
109144 }
110145
111- return firstSentenceFallback ( prompt ) ;
146+ const sentence = prompt !== undefined ? firstSentenceFallback ( prompt ) : undefined ;
147+ if ( meta . agentType !== undefined ) {
148+ return truncate ( sentence !== undefined ? `${ meta . agentType } : ${ sentence } ` : meta . agentType ) ;
149+ }
150+ return sentence ;
112151}
0 commit comments