@@ -8,6 +8,7 @@ import { loadConfig } from '../infra/config.js';
88import { SUBAGENT_RESULT_PREFIX } from '../contracts/session.js' ;
99import { MailboxService } from '../session/mailbox.js' ;
1010import { EventSinkService } from '../sink/port.js' ;
11+ import { HookService } from '../hooks/port.js' ;
1112import { SubagentRunnerService } from './port.js' ;
1213
1314export type SubagentRunStatus =
@@ -46,6 +47,7 @@ export class SubagentRunRegistryService extends Context.Tag('SubagentRunRegistry
4647interface SubagentRun {
4748 readonly sessionId : string ;
4849 readonly parentSessionId : string ;
50+ readonly parentCwd : string ;
4951 readonly agentName : string ;
5052 readonly status : SubscriptionRef . SubscriptionRef < SubagentRunStatus > ;
5153 readonly abort : AbortController ;
@@ -116,6 +118,7 @@ export const SubagentRunRegistryLayer = Layer.scoped(
116118 const mailbox = yield * MailboxService ;
117119 const runner = yield * SubagentRunnerService ;
118120 const sink = yield * EventSinkService ;
121+ const hooks = yield * HookService ;
119122 const runs = new Map < string , SubagentRun > ( ) ; // 键 = 子会话 sessionId;parentSessionId 只是条目上的字段
120123
121124 /** 帧直投父会话的出站队列:EventSink 的键就是收件人会话,不需要任何回调透传 */
@@ -159,6 +162,12 @@ export const SubagentRunRegistryLayer = Layer.scoped(
159162 run . parentSessionId , run . sessionId , run . agentName ,
160163 outcome . end . reason === 'done' ? 'completed' : 'failed' ,
161164 ) ;
165+ yield * hooks . emit ( 'agent.subagent.complete' , {
166+ projectPath : run . parentCwd ,
167+ childSessionId : run . sessionId ,
168+ agentName : run . agentName ,
169+ status : outcome . end . reason === 'done' ? 'completed' : 'failed' ,
170+ } ) ;
162171 } ) ;
163172
164173 const spawn = ( opts : SpawnOptions ) =>
@@ -183,8 +192,8 @@ export const SubagentRunRegistryLayer = Layer.scoped(
183192
184193 const status = yield * SubscriptionRef . make < SubagentRunStatus > ( { kind : 'running' } ) ;
185194 const run : SubagentRun = {
186- sessionId, parentSessionId : opts . parentSessionId , agentName : opts . agentName ,
187- status, abort,
195+ sessionId, parentSessionId : opts . parentSessionId , parentCwd : opts . parentCwd ,
196+ agentName : opts . agentName , status, abort,
188197 } ;
189198 runs . set ( sessionId , run ) ;
190199 yield * emitSubagent ( opts . parentSessionId , sessionId , opts . agentName , 'spawned' ) ;
0 commit comments