@@ -76,6 +76,15 @@ export class CodexNativeSubagentTaskMirror {
7676 return ;
7777 }
7878 if ( notification . method === "item/started" || notification . method === "item/completed" ) {
79+ const item = isJsonObject ( params . item ) ? params . item : undefined ;
80+ if (
81+ notification . method === "item/completed" &&
82+ item &&
83+ readString ( item , "type" ) === "subAgentActivity"
84+ ) {
85+ this . handleSubagentActivityItem ( params ) ;
86+ return ;
87+ }
7988 this . handleCollabAgentItem ( params ) ;
8089 }
8190 }
@@ -91,11 +100,6 @@ export class CodexNativeSubagentTaskMirror {
91100 return ;
92101 }
93102 const threadId = thread . id . trim ( ) ;
94- if ( ! threadId || this . mirrorStateByThreadId . get ( threadId ) === "mirrored" ) {
95- return ;
96- }
97- this . mirrorStateByThreadId . set ( threadId , "mirrored" ) ;
98- const runId = codexNativeSubagentRunId ( threadId ) ;
99103 const label =
100104 trimOptional ( spawn . agent_nickname ) ??
101105 trimOptional ( thread . agentNickname ) ??
@@ -106,25 +110,17 @@ export class CodexNativeSubagentTaskMirror {
106110 trimOptional ( thread . preview ) ??
107111 `Codex native subagent${ label === "Codex subagent" ? "" : ` ${ label } ` } ` ;
108112 const createdAt = secondsToMillis ( thread . createdAt ) ?? this . now ( ) ;
109- const taskRecord = this . runtime . tryCreateRunningTaskRun ( {
110- sourceId : runId ,
111- agentId : this . params . agentId ,
112- runId,
113- label,
114- task,
115- notifyPolicy : "silent" ,
116- deliveryStatus : "not_applicable" ,
117- preferMetadata : true ,
118- startedAt : createdAt ,
119- lastEventAt : this . now ( ) ,
120- progressSummary : "Codex native subagent started." ,
121- } ) ;
122- if ( ! taskRecord ) {
123- this . mirrorStateByThreadId . set ( threadId , "failed" ) ;
113+ if (
114+ ! this . createRunningTask ( {
115+ threadId,
116+ label,
117+ task,
118+ startedAt : createdAt ,
119+ progressSummary : "Codex native subagent started." ,
120+ } )
121+ ) {
124122 return ;
125123 }
126- this . terminalRunIds . delete ( runId ) ;
127- this . authoritativeRunIds . delete ( runId ) ;
128124 this . applyStatus ( threadId , thread . status ) ;
129125 }
130126
@@ -244,34 +240,94 @@ export class CodexNativeSubagentTaskMirror {
244240 }
245241 }
246242
247- private createTaskFromCollabSpawnItem ( threadId : string , item : JsonObject ) : void {
248- const normalizedThreadId = threadId . trim ( ) ;
249- if ( ! normalizedThreadId || this . mirrorStateByThreadId . get ( normalizedThreadId ) === "mirrored" ) {
243+ private handleSubagentActivityItem ( params : JsonObject ) : void {
244+ const item = isJsonObject ( params . item ) ? params . item : undefined ;
245+ if (
246+ ! item ||
247+ readString ( item , "type" ) !== "subAgentActivity" ||
248+ readString ( params , "threadId" ) !== this . params . parentThreadId
249+ ) {
250+ return ;
251+ }
252+ const threadId = trimOptional ( readString ( item , "agentThreadId" ) ) ;
253+ const kind = normalizeSubagentActivityKind ( readString ( item , "kind" ) ) ;
254+ if ( ! threadId || ! kind ) {
255+ return ;
256+ }
257+ if ( kind === "started" ) {
258+ this . createTaskFromSubagentActivity ( threadId , trimOptional ( readString ( item , "agentPath" ) ) ) ;
259+ return ;
260+ }
261+ if ( this . mirrorStateByThreadId . get ( threadId ) !== "mirrored" ) {
250262 return ;
251263 }
252- this . mirrorStateByThreadId . set ( normalizedThreadId , "mirrored" ) ;
264+ const message =
265+ kind === "interacted"
266+ ? "Codex native subagent received more input."
267+ : "Codex native subagent was interrupted." ;
268+ this . applyCollabAgentStatus (
269+ threadId ,
270+ kind === "interacted" ? "running" : "interrupted" ,
271+ message ,
272+ ) ;
273+ }
274+
275+ private createTaskFromSubagentActivity ( threadId : string , agentPath : string | undefined ) : void {
276+ const eventAt = this . now ( ) ;
277+ this . createRunningTask ( {
278+ threadId,
279+ label : "Codex subagent" ,
280+ task : agentPath ? `Codex native subagent ${ agentPath } ` : "Codex native subagent" ,
281+ startedAt : eventAt ,
282+ progressSummary : "Codex native subagent started." ,
283+ } ) ;
284+ }
285+
286+ private createTaskFromCollabSpawnItem ( threadId : string , item : JsonObject ) : void {
253287 const prompt = trimOptional ( readString ( item , "prompt" ) ) ;
254- const runId = codexNativeSubagentRunId ( normalizedThreadId ) ;
255288 const createdAt = this . now ( ) ;
289+ this . createRunningTask ( {
290+ threadId,
291+ label : "Codex subagent" ,
292+ task : prompt ?? "Codex native subagent" ,
293+ startedAt : createdAt ,
294+ progressSummary : "Codex native subagent spawned." ,
295+ } ) ;
296+ }
297+
298+ private createRunningTask ( params : {
299+ threadId : string ;
300+ label : string ;
301+ task : string ;
302+ startedAt : number ;
303+ progressSummary : string ;
304+ } ) : boolean {
305+ const threadId = params . threadId . trim ( ) ;
306+ if ( ! threadId || this . mirrorStateByThreadId . get ( threadId ) === "mirrored" ) {
307+ return false ;
308+ }
309+ this . mirrorStateByThreadId . set ( threadId , "mirrored" ) ;
310+ const runId = codexNativeSubagentRunId ( threadId ) ;
256311 const taskRecord = this . runtime . tryCreateRunningTaskRun ( {
257312 sourceId : runId ,
258313 agentId : this . params . agentId ,
259314 runId,
260- label : "Codex subagent" ,
261- task : prompt ?? "Codex native subagent" ,
315+ label : params . label ,
316+ task : params . task ,
262317 notifyPolicy : "silent" ,
263318 deliveryStatus : "not_applicable" ,
264319 preferMetadata : true ,
265- startedAt : createdAt ,
266- lastEventAt : createdAt ,
267- progressSummary : "Codex native subagent spawned." ,
320+ startedAt : params . startedAt ,
321+ lastEventAt : this . now ( ) ,
322+ progressSummary : params . progressSummary ,
268323 } ) ;
269324 if ( ! taskRecord ) {
270- this . mirrorStateByThreadId . set ( normalizedThreadId , "failed" ) ;
271- return ;
325+ this . mirrorStateByThreadId . set ( threadId , "failed" ) ;
326+ return false ;
272327 }
273328 this . terminalRunIds . delete ( runId ) ;
274329 this . authoritativeRunIds . delete ( runId ) ;
330+ return true ;
275331 }
276332
277333 private applyCollabAgentStatus (
@@ -451,6 +507,13 @@ function normalizeToolName(value: string | undefined): string | undefined {
451507 return value ?. replace ( / [ ^ a - z 0 - 9 ] / giu, "" ) . toLowerCase ( ) ;
452508}
453509
510+ function normalizeSubagentActivityKind (
511+ value : string | undefined ,
512+ ) : "started" | "interacted" | "interrupted" | undefined {
513+ const key = value ?. replace ( / [ ^ a - z ] / giu, "" ) . toLowerCase ( ) ;
514+ return key === "started" || key === "interacted" || key === "interrupted" ? key : undefined ;
515+ }
516+
454517function normalizeCollabToolCallStatus ( value : string | undefined ) : string | undefined {
455518 const key = value ?. replace ( / [ ^ a - z 0 - 9 ] / giu, "" ) . toLowerCase ( ) ;
456519 if ( key === "completed" || key === "succeeded" || key === "success" ) {
0 commit comments