@duckmind/dm-windows-x64 0.60.2 → 0.60.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dm.exe CHANGED
Binary file
@@ -222,8 +222,8 @@
222
222
  "src/tui/render.js"
223
223
  ],
224
224
  "file_count": 93,
225
- "before_bytes": 1544913,
226
- "after_bytes": 3104479,
225
+ "before_bytes": 1545179,
226
+ "after_bytes": 3104611,
227
227
  "externals": [
228
228
  "@duckmind/dm-agent-core",
229
229
  "@duckmind/dm-ai",
@@ -72,7 +72,9 @@ ${q$}`:q$:S?.error;if(G&&j.artifactConfig?.enabled!==!1){if(j.artifactConfig?.in
72
72
  ${U}`}function a5($,j){let J=r.join($,"progress.md");if(!j.parallel.some((Z)=>Z.task.includes(`Update progress at: ${J}`)))return;ej($)}function fj($){if(!$.artifactsDir||$.artifactConfig?.enabled===!1||$.artifactConfig?.includeTranscript===!1)return;return c1($.artifactsDir,$.runId,$.agent,$.flatStepCount>1?$.flatIndex:void 0).transcriptPath}async function r8($){let{id:j,steps:J,resultPath:Z,cwd:Q,placeholder:X,taskIndex:W,totalTasks:U,maxOutput:G,artifactsDir:B,artifactConfig:q}=$,O=new y1($.globalConcurrencyLimit??tj),T="",y={},h=[],S=Date.now(),v$=$.share===!0,k=$.asyncDir,f=r.join(k,"status.json"),n=r.join(k,"events.jsonl"),d$=r.join(k,`subagent-log-${j}.md`),W$=$.controlConfig??LJ,y$=new Map,K$=new Map,g$=new Map,A$=[],s=!1,E$,X$,_$,E=!1,t=!1,p=$.timeoutMs!==void 0?`Subagent timed out after ${$.timeoutMs}ms.`:void 0,q$=new AbortController,Y$={input:0,output:0,total:0},o$,u$=aj(J),j$=u$.length,c=[],H$=[],k$=0;for(let H=0;H<J.length;H++){let V=J[H];if($0(V)){c.push({start:k$,count:V.parallel.length,stepIndex:H});for(let K of V.parallel){let _=k$,z=fj({artifactsDir:B,artifactConfig:q,runId:j,agent:K.agent,flatIndex:_,flatStepCount:j$});H$.push({agent:K.agent,phase:K.phase,label:K.label,outputName:K.outputName,structured:K.structured,status:"pending",...K.toolBudget?{toolBudget:C0(K.toolBudget)}:{},...K.sessionFile?{sessionFile:K.sessionFile}:{},...z?{transcriptPath:z}:{},skills:K.skills,model:K.model,thinking:K.thinking,attemptedModels:K.modelCandidates&&K.modelCandidates.length>0?K.modelCandidates:K.model?[K.model]:void 0,recentTools:[],recentOutput:[]}),k$++}}else if(j0(V))c.push({start:k$,count:1,stepIndex:H}),H$.push({agent:`expand:${V.parallel.agent}`,phase:V.phase??V.parallel.phase,label:V.label??V.parallel.label??`Dynamic fanout (${V.collect.as})`,outputName:V.collect.as,structured:Boolean(V.collect.outputSchema),status:"pending",...V.parallel.toolBudget?{toolBudget:C0(V.parallel.toolBudget)}:{},recentTools:[],recentOutput:[]}),k$++;else{let K=k$,_=fj({artifactsDir:B,artifactConfig:q,runId:j,agent:V.agent,flatIndex:K,flatStepCount:j$});H$.push({agent:V.agent,phase:V.phase,label:V.label,outputName:V.outputName,structured:V.structured,status:"pending",...V.toolBudget?{toolBudget:C0(V.toolBudget)}:{},...V.sessionFile?{sessionFile:V.sessionFile}:{},..._?{transcriptPath:_}:{},skills:V.skills,model:V.model,thinking:V.thinking,attemptedModels:V.modelCandidates&&V.modelCandidates.length>0?V.modelCandidates:V.model?[V.model]:void 0,recentTools:[],recentOutput:[]}),k$++}}let W0=Boolean($.sessionDir)||v$||u$.some((H)=>Boolean(H.sessionFile)),Y={lifecycleArtifactVersion:S0,runId:j,...$.sessionId?{sessionId:$.sessionId}:{},mode:$.resultMode??(u$.length>1?"chain":"single"),state:"running",lastActivityAt:S,startedAt:S,lastUpdate:S,...$.timeoutMs!==void 0?{timeoutMs:$.timeoutMs}:{},...$.deadlineAt!==void 0?{deadlineAt:$.deadlineAt}:{},...$.turnBudget?{turnBudget:Rj($.turnBudget)}:{},...$.toolBudget?{toolBudget:C0($.toolBudget)}:{},pid:process.pid,cwd:Q,currentStep:0,chainStepCount:J.length,parallelGroups:c,workflowGraph:$.workflowGraph,steps:H$,artifactsDir:B,sessionDir:$.sessionDir,outputFile:r.join(k,"output-0.log")};e.mkdirSync(k,{recursive:!0}),D$(f,Y);let u=(H)=>{if(!$.nestedRoute||!$.nestedSelf)return;try{Y8($.nestedRoute,{type:H,ts:Date.now(),parentRunId:$.nestedSelf.parentRunId,parentStepIndex:$.nestedSelf.parentStepIndex,child:W8(Y,k,{id:j,parentRunId:$.nestedSelf.parentRunId,parentStepIndex:$.nestedSelf.parentStepIndex,depth:$.nestedSelf.depth,path:$.nestedSelf.path,mode:Y.mode,ts:Date.now()})})}catch(V){console.error("Failed to emit nested async status event:",V)}},U$=()=>{if(!$.workflowGraph)return;let H=structuredClone(Y.workflowGraph??$.workflowGraph),V=(_)=>{if(_==="complete"||_==="completed")return"completed";if(_==="running"||_==="failed"||_==="paused"||_==="pending")return _;return"pending"},K=(_)=>{if(_.flatIndex!==void 0){let z=Y.steps[_.flatIndex];if(z)_.status=V(z.status),_.error=z.error,_.acceptanceStatus=z.acceptance?.status;if(Y.currentStep===_.flatIndex)H.currentNodeId=_.id}for(let z of _.children??[])K(z);if(_.children?.length){if(_.children.every((z)=>z.status==="completed"))_.status="completed";else if(_.children.some((z)=>z.status==="running"))_.status="running";else if(_.children.some((z)=>z.status==="failed"))_.status="failed";else if(_.children.some((z)=>z.status==="paused"))_.status="paused"}if(_.error)_.status="failed"};for(let _ of H.nodes)K(_);Y.workflowGraph=H},a=()=>{U$(),D$(f,Y),u(Y.state==="running"||Y.state==="queued"?"subagent.nested.updated":"subagent.nested.completed")},N$=(H,V)=>{if(!V){y$.delete(H);return}if(y$.set(H,V),s)V()},f$=(H,V)=>{if(!V){K$.delete(H);return}if(K$.set(H,V),E)V()},S$=(H,V)=>{if(!V){g$.delete(H);return}g$.set(H,V)},t$=()=>{for(let H of[...y$.values()])H()},P$=()=>{for(let H of[...K$.values()])H()},V$=function*(H){for(let V of H??[])yield V,yield*V$(V.children),yield*V$(V.steps?.flatMap((K)=>K.children??[]))},l$=()=>{if(!$.nestedRoute)return;let H;try{H=Mj($.nestedRoute)}catch(V){$$(n,JSON.stringify({type:"subagent.nested.interrupt_failed",ts:Date.now(),runId:j,message:V instanceof Error?V.message:String(V)}));return}for(let V of V$(H.children)){if(V.state!=="running"&&V.state!=="queued")continue;let K=V.asyncDir??_j($.nestedRoute.rootRunId,V);if(!K)continue;try{KJ({asyncDir:K,pid:V.pid,source:"ancestor-interrupt"})}catch(_){$$(n,JSON.stringify({type:"subagent.nested.interrupt_failed",ts:Date.now(),runId:j,targetRunId:V.id,message:_ instanceof Error?_.message:String(_)}))}}},p$=()=>{if(!$.nestedRoute)return;let H;try{H=Mj($.nestedRoute)}catch(V){$$(n,JSON.stringify({type:"subagent.nested.timeout_failed",ts:Date.now(),runId:j,message:V instanceof Error?V.message:String(V)}));return}for(let V of V$(H.children)){if(V.state!=="running"&&V.state!=="queued")continue;let K=V.asyncDir??_j($.nestedRoute.rootRunId,V);if(!K)continue;try{m1({asyncDir:K,pid:V.pid,source:"ancestor-timeout"})}catch(_){$$(n,JSON.stringify({type:"subagent.nested.timeout_failed",ts:Date.now(),runId:j,targetRunId:V.id,message:_ instanceof Error?_.message:String(_)}))}}},e$=(H)=>({agent:H,output:"Paused after interrupt. Waiting for explicit next action.",exitCode:0,interrupted:!0}),P=(H)=>({agent:H,output:p??"Subagent timed out.",error:p??"Subagent timed out.",exitCode:1,timedOut:!0}),D=()=>{if(Y.mode!=="chain"||Y.state!=="running")return;let H=g8(k);if(H.length===0){let N=Dj(k);if((Y.pendingAppends??0)!==N)Y.pendingAppends=N,Y.lastUpdate=Date.now(),a();return}let V=H.flatMap((N)=>N.steps);J.push(...V);let K=Date.now(),_=Dj(k),z=c8({status:Y,steps:V,now:K,pendingAppends:_});if(p0.push(...Array.from({length:z.addedFlatSteps},()=>G1())),T0.push(...Array.from({length:z.addedFlatSteps},()=>{return})),$.childIntercomTargets)$.childIntercomTargets=Y.steps.map((N,w)=>Aj(j,N.agent,w));a();for(let N of H)$$(n,JSON.stringify({type:"subagent.chain.append.accepted",ts:K,runId:j,requestId:N.id,stepCount:N.steps.length,pendingAppends:_}))},i=(H,V,K,_)=>{let z=Y.workflowGraph?.nodes.find((N)=>N.id===`step-${H}`);if(!z)return;z.status=V,z.error=K,z.acceptanceStatus=_?.status??z.acceptanceStatus},M$=(H)=>{let V=Y.steps[H],K=V?.lastActivityAt??V?.startedAt??S,_=r.join(k,`output-${H}.log`);try{K=Math.max(K,e.statSync(_).mtimeMs)}catch(z){if(z.code!=="ENOENT")console.error(`Failed to inspect async output file '${_}':`,z)}return K},l0=new Set,vj=new Set,p0=H$.map(()=>G1()),T0=H$.map(()=>{return}),s8=300000,E0=(H)=>{if(!W$.enabled)return;let V=$.childIntercomTargets?.[H.index??Y.currentStep],K=H.type==="active_long_running"?W$.notifyChannels.filter((_)=>_!=="intercom"):W$.notifyChannels;if(K.length===0||!FJ(W$,H,l0,V))return;$$(n,JSON.stringify({type:"subagent.control",event:H,channels:K,childIntercomTarget:V,noticeText:p1(H,V),...$.controlIntercomTarget&&K.includes("intercom")?{intercom:{to:$.controlIntercomTarget,message:OJ(H,V)}}:{}}))},A1=()=>{let H=Y.steps.filter((V)=>V.status==="running"&&typeof V.currentTool==="string"&&V.currentTool.length>0).sort((V,K)=>(K.currentToolStartedAt??0)-(V.currentToolStartedAt??0))[0];Y.currentTool=H?.currentTool,Y.currentToolStartedAt=H?.currentToolStartedAt,Y.currentPath=H?.currentPath},gj=(H,V)=>{if(!W$.enabled||vj.has(H))return!1;let K=Y.steps[H];if(!K||K.status!=="running"||K.activityState==="needs_attention")return!1;let _=G8(W$,{startedAt:K.startedAt??S,now:V,turns:K.turnCount??0,tokens:K.tokens?.total??0});if(!_)return!1;vj.add(H);let z=K.activityState;K.activityState="active_long_running",Y.activityState=Y.activityState==="needs_attention"?"needs_attention":"active_long_running";let N=A0({type:"active_long_running",from:z,to:"active_long_running",runId:j,agent:K.agent,index:H,ts:V,message:`${K.agent} is still active but long-running`,reason:_,turns:K.turnCount,tokens:K.tokens?.total,toolCount:K.toolCount,currentTool:K.currentTool,currentToolDurationMs:K.currentToolStartedAt?Math.max(0,V-K.currentToolStartedAt):void 0,currentPath:K.currentPath,elapsedMs:V-(K.startedAt??S)});return E0(N),!0},N1=(H)=>{if(Y.state!=="running")return;let V=Y.steps.map((w,d)=>({step:w,index:d})).filter(({step:w})=>w.status==="running").map(({index:w})=>w),K=H.targetIndex!==void 0?[H.targetIndex]:V,_=Date.now(),z=[],N=[];for(let w of K){let d=Y.steps[w];if(!d){N.push({index:w,reason:"child index out of range"});continue}if(d.status!=="running"){N.push({index:w,reason:`child is ${d.status}`});continue}VJ(k,w,H),d.steerCount=(d.steerCount??0)+1,d.lastSteerAt=_,z.push(w)}if(z.length>0)Y.steerCount=(Y.steerCount??0)+z.length,Y.lastSteerAt=_,Y.lastUpdate=_,a();$$(n,JSON.stringify({type:"subagent.steer.requested",ts:_,runId:j,requestId:H.id,message:H.message,...H.source?{source:H.source}:{},...H.targetIndex!==void 0?{targetIndex:H.targetIndex}:{},acceptedIndexes:z,...N.length?{rejected:N}:{}}))},C1=(H)=>{let V=[];for(let K of A$.splice(0))if(K.targetIndex===void 0)N1({...K,targetIndex:H});else if(K.targetIndex===H)N1(K);else V.push(K);A$.push(...V)},T1=(H,V,K,_=Date.now())=>{let z=Y.steps[H];if(!z)return;z.model=V,z.thinking=K,Y.lastUpdate=_,a()},a8=(H,V,K,_)=>{let z=$.turnBudget,N=Y.steps[H];if(!z||!N||E||t||N.turnBudgetExceeded)return;if(V<z.maxTurns){let v={...z,outcome:"within-budget",turnCount:V};N.turnBudget=v,Y.turnBudget=v;return}let w=O1(z,V,!1);if(N.turnBudget=w,Y.turnBudget=w,!N.wrapUpRequested)N.wrapUpRequested=!0,Y.wrapUpRequested=!0,Ij(N,[bj(z,V)]);if(!wj(z,V,_))return;let d=O1(z,V,!0),Z$=u0(z,V);N.turnBudget=d,N.turnBudgetExceeded=!0,N.wrapUpRequested=!0,N.error=Z$,t=!0,Y.turnBudget=d,Y.turnBudgetExceeded=!0,Y.wrapUpRequested=!0,Y.error=Z$,Y.lastUpdate=K,$$(n,JSON.stringify({type:"subagent.step.turn_budget_exceeded",ts:K,runId:j,stepIndex:H,agent:N.agent,turnCount:V,maxTurns:z.maxTurns,graceTurns:z.graceTurns,message:Z$})),g$.get(H)?.(Z$,d)},E1=(H,V)=>{let K=Y.steps[H];if(!K)return;let _=Date.now();if(Y.currentStep=H,V.type==="tool_execution_start"&&V.toolName){let z=qj(V.toolName,V.args),N=U8(V.toolName,V.args);K.toolCount=(K.toolCount??0)+1;let w=u$[H]?.toolBudget;if(w)K.toolBudget=Z1(w,K.toolCount),Y.toolBudget=K.toolBudget;K.currentTool=V.toolName,K.currentToolArgs=w0(V.args??{}),K.currentToolStartedAt=_,K.currentPath=N,T0[H]={tool:V.toolName,path:N,mutates:z,startedAt:_},Y.toolCount=(Y.toolCount??0)+1,A1()}else if(V.type==="tool_execution_end"){if(K.currentTool)K.recentTools??=[],K.recentTools.push({tool:K.currentTool,args:K.currentToolArgs||"",endMs:_});K.currentTool=void 0,K.currentToolArgs=void 0,K.currentToolStartedAt=void 0,K.currentPath=void 0,A1()}else if(V.type==="tool_result_end"&&V.message){let z=T0[H];T0[H]=void 0;let N=s$(V.message.content);if(z&&N.includes("Tool budget hard limit reached")){let w=u$[H]?.toolBudget;if(w)K.toolBudget=Z1(w,K.toolCount??0,z.tool),K.toolBudgetBlocked=!0,Y.toolBudget=K.toolBudget,Y.toolBudgetBlocked=!0}if(Ij(K,N.split(`
73
73
  `).slice(-10)),z?.mutates&&z8(N)){let w=p0[H];if(_8(w,{tool:z.tool,path:z.path,error:N.split(`
74
74
  `).find((d)=>d.trim())?.trim().slice(0,180)??"mutating tool failed",ts:_},s8),W$.enabled&&M8(w,W$.failedToolAttemptsBeforeAttention)&&K.activityState!=="needs_attention"){let d=K.activityState;K.activityState="needs_attention",Y.activityState="needs_attention",E0(A0({type:"needs_attention",from:d,to:"needs_attention",runId:j,agent:K.agent,index:H,ts:_,message:`${K.agent} needs attention after repeated mutating tool failures`,reason:"tool_failures",turns:K.turnCount,tokens:K.tokens?.total,toolCount:K.toolCount,currentTool:z.tool,currentToolDurationMs:z.startedAt?Math.max(0,_-z.startedAt):void 0,currentPath:z.path,recentFailureSummary:L8(w)}))}}else if(z?.mutates)B8(p0[H])}else if(V.type==="message_end"&&V.message?.role==="assistant"){Ij(K,Cj(s$(V.message.content)).split(`
75
- `).slice(-10)),K.turnCount=(K.turnCount??0)+1;let z=V.message.usage;if(z){let N=z.input??z.inputTokens??0,w=z.output??z.outputTokens??0,d=K.tokens?.input??0,Z$=K.tokens?.output??0;K.tokens={input:d+N,output:Z$+w,total:d+Z$+N+w};let v=Y.totalTokens?.input??0,F=Y.totalTokens?.output??0;Y.totalTokens={input:v+N,output:F+w,total:v+F+N+w}}Y.turnCount=Math.max(Y.turnCount??0,K.turnCount),a8(H,K.turnCount,_,hj(V.message))}A1(),K.lastActivityAt=_,Y.lastActivityAt=_,Y.lastUpdate=_,gj(H,_),a()},t8=(H)=>{if(!W$.enabled)return!1;let V=!1,K=Y.lastActivityAt??S;for(let z=0;z<Y.steps.length;z++){let N=Y.steps[z];if(N.status!=="running")continue;let w=M$(z);if(K=Math.max(K,w),N.lastActivityAt!==w)N.lastActivityAt=w,V=!0;if(qJ({config:W$,startedAt:N.startedAt??S,lastActivityAt:w,now:H})==="needs_attention"){let Z$=N.activityState;if(N.activityState="needs_attention",Z$!=="needs_attention")E0(A0({from:Z$,to:"needs_attention",runId:j,agent:N.agent,index:z,ts:H,lastActivityAt:w})),V=!0}else if(gj(z,H))V=!0}if(Y.lastActivityAt!==K)Y.lastActivityAt=K,V=!0;let _=Y.steps.some((z)=>z.activityState==="needs_attention")?"needs_attention":Y.steps.some((z)=>z.activityState==="active_long_running")?"active_long_running":void 0;if(_!==E$)E$=_,Y.activityState=_,V=!0;if(Y.lastUpdate=H,V)a();return V};if(W$.enabled)X$=setInterval(()=>{if(Y.state!=="running")return;let H=Date.now();t8(H)},1000),X$.unref?.();let mj=()=>{if(g1(k),s||Y.state!=="running")return;s=!0;let H=Date.now();Y.state="paused",E$=void 0,Y.activityState=void 0,Y.lastUpdate=H;for(let V of Y.steps)if(V.status==="running")V.status="paused",V.activityState=void 0,V.endedAt=H,V.durationMs=V.startedAt?H-V.startedAt:void 0,V.lastActivityAt=H;a(),$$(n,JSON.stringify({type:"subagent.run.paused",ts:H,runId:j})),l$(),t$()},cj=()=>{if(E||s||Y.state!=="running")return;E=!0;let H=Date.now(),V=p??"Subagent timed out.";Y.state="failed",Y.timedOut=!0,Y.error=V,E$=void 0,Y.activityState=void 0,Y.lastUpdate=H;for(let K of Y.steps){if(K.status!=="running"&&K.status!=="pending")continue;K.status="failed",K.error=V,K.exitCode=1,K.timedOut=!0,K.activityState=void 0,K.endedAt=H,K.durationMs=K.startedAt?H-K.startedAt:0,K.lastActivityAt=H}a(),$$(n,JSON.stringify({type:"subagent.run.timed_out",ts:H,runId:j,timeoutMs:$.timeoutMs,deadlineAt:$.deadlineAt,message:V})),q$.abort(),p$(),P$()};process.on(y5,mj);let e8=UJ(k,{onInterrupt:mj,onTimeout:cj,onSteer:(H)=>{if((H.targetIndex!==void 0?Y.steps[H.targetIndex]:void 0)?.status==="pending")A$.push(H);else if(H.targetIndex!==void 0||Y.steps.some((K)=>K.status==="running"))N1(H);else A$.push(H)}});if($.deadlineAt!==void 0){let H=Math.max(0,$.deadlineAt-Date.now());_$=setTimeout(cj,H),_$.unref?.()}$$(n,JSON.stringify({type:"subagent.run.started",lifecycleArtifactVersion:S0,ts:S,runId:j,mode:Y.mode,cwd:Q,pid:process.pid}));let R=0,dj=0;while(!0){if(s||E||t)break;if(D(),dj>=J.length)break;let H=dj++,V=J[H];if(j0(V)){let K=R,_;try{if(_=tJ(V,y,H,{maxItems:$.dynamicFanoutMaxItems,allowRunnerFields:!0}),_.collectedOnEmpty)Yj(V.collect.outputSchema,_.collectedOnEmpty)}catch(M){let o=Date.now(),L=M instanceof x?M.message:M instanceof Error?M.message:String(M);Y.state="failed",Y.error=L,Y.currentStep=R;let A=Y.steps[K];if(A)A.status="failed",A.error=L,A.startedAt=o,A.endedAt=o,A.durationMs=0,A.exitCode=1;Y.lastUpdate=o,i(H,"failed",L),a(),h.push({agent:V.parallel.agent,output:L,error:L,success:!1,exitCode:1});break}if(_.parallel.length===0){let M=Date.now(),o=_.collectedOnEmpty??[];y[V.collect.as]={text:JSON.stringify(o),structured:o,agent:V.parallel.agent,stepIndex:H},Y.outputs=y;let L=Y.steps[K];if(L)L.status="complete",L.startedAt=M,L.endedAt=M,L.durationMs=0;T="Dynamic fanout produced 0 results.";let A=V.effectiveAcceptance?.explicit&&!E?await M1({acceptance:V.effectiveAcceptance,output:"",report:Ej({results:[],notes:"Dynamic fanout produced 0 results."}),cwd:Q,signal:q$.signal,abortMessage:p??"Subagent timed out."}):void 0,I=E||q$.signal.aborted,G$=I?void 0:A;if(L&&G$)L.acceptance=G$;let x$=G$?L1(G$):void 0;if(I||x$){let g=I?p??"Subagent timed out.":x$;if(Y.state="failed",Y.error=g,L)L.status="failed",L.error=g,L.exitCode=1,L.timedOut=I?!0:void 0;i(H,"failed",g,G$),Y.lastUpdate=Date.now(),a(),h.push({agent:V.parallel.agent,output:g,error:g,success:!1,exitCode:1,timedOut:I?!0:void 0,acceptance:G$});break}R++,Y.lastUpdate=M,i(H,"completed",void 0,G$),a();continue}let z=_.parallel.map((M,o)=>{let L=V.thinkingOverrides?.[o],A=L?W1(V.parallel.model,L,!0):V.parallel.model,I=L?O0(A,L):void 0;return{...V.parallel,task:M.task??V.parallel.task,label:M.label??V.parallel.label,...V.sessionFiles?.[o]?{sessionFile:V.sessionFiles[o]}:{},...L?{...A?{model:A}:{},...I?{thinking:I}:{},...V.parallel.modelCandidates?{modelCandidates:V.parallel.modelCandidates.map((G$)=>W1(G$,L,!0))}:{}}:{},structuredOutput:void 0,structuredOutputSchema:V.parallel.structuredOutputSchema??V.parallel.structuredOutput?.schema}}),N=Math.max(Y.steps.length-1+z.length,1),w=z.map((M,o)=>{let L=fj({artifactsDir:B,artifactConfig:q,runId:j,agent:M.agent,flatIndex:K+o,flatStepCount:N});return{agent:M.agent,phase:M.phase??V.phase,label:M.label,outputName:void 0,structured:Boolean(M.structuredOutputSchema),status:"pending",...M.sessionFile?{sessionFile:M.sessionFile}:{},...L?{transcriptPath:L}:{},skills:M.skills,model:M.model,thinking:M.thinking,attemptedModels:M.modelCandidates&&M.modelCandidates.length>0?M.modelCandidates:M.model?[M.model]:void 0,recentTools:[],recentOutput:[]}});if(Y.steps.splice(K,1,...w),$.childIntercomTargets)$.childIntercomTargets=Y.steps.map((M,o)=>Aj(j,M.agent,o));p0.splice(K,1,...w.map(()=>G1())),T0.splice(K,1,...w.map(()=>{return}));let d=w.length-1;for(let M of Y.parallelGroups)if(M.stepIndex===H)M.start=K,M.count=w.length;else if(M.start>K)M.start+=d;if(Y.workflowGraph){let M=(L)=>{for(let A of L){if(A.stepIndex!==void 0&&A.stepIndex>H&&A.flatIndex!==void 0&&A.flatIndex>=K)A.flatIndex+=w.length;if(A.children)M(A.children)}};M(Y.workflowGraph.nodes);let o=Y.workflowGraph.nodes.find((L)=>L.id===`step-${H}`);if(o)o.children=_.items.map((L,A)=>({id:`step-${H}-item-${L.idKey}`,kind:"agent",agent:V.parallel.agent,phase:z[A]?.phase??V.phase,label:z[A]?.label?.trim()||`${V.parallel.agent} ${L.key}`,status:"pending",flatIndex:K+A,stepIndex:H,itemKey:L.key,structured:Boolean(z[A]?.structuredOutputSchema)}))}a();let Z$=V.concurrency??k1,v=V.failFast??!1,F=!1,F$=await t0(z,Z$,async(M,o)=>{let L=K+o;if(E)return P(M.agent);if(s)return e$(M.agent);if(F&&v){let g=Date.now();return Y.steps[L].status="failed",Y.steps[L].error="Skipped due to fail-fast",Y.steps[L].startedAt=g,Y.steps[L].endedAt=g,Y.steps[L].durationMs=0,Y.steps[L].exitCode=-1,Y.lastUpdate=g,a(),{agent:M.agent,output:"(skipped — fail-fast)",exitCode:-1,skipped:!0}}let A=Date.now();Y.currentStep=L,Y.steps[L].status="running",Y.steps[L].error=void 0,Y.steps[L].activityState=void 0,yj(Y.steps[L]),Y.steps[L].startedAt=A,Y.steps[L].lastActivityAt=A,Y.outputFile=r.join(k,`output-${L}.log`),Y.lastActivityAt=A,Y.lastUpdate=A,a(),$$(n,JSON.stringify({type:"subagent.step.started",ts:A,runId:j,stepIndex:L,agent:M.agent})),C1(L);let I=await kj(M,{previousOutput:T,placeholder:X,cwd:Q,sessionEnabled:W0,outputs:y,sessionDir:$.sessionDir?r.join($.sessionDir,`dynamic-${H}-${o}`):void 0,artifactsDir:B,artifactConfig:q,id:j,flatIndex:L,flatStepCount:Math.max(Y.steps.length,1),outputFile:r.join(k,`output-${L}.log`),steerInboxDir:y0(k,L),piPackageRoot:$.piPackageRoot,piArgv1:$.piArgv1,childIntercomTarget:$.childIntercomTargets?.[L],orchestratorIntercomTarget:$.controlIntercomTarget,nestedRoute:$.nestedRoute,registerInterrupt:(g)=>N$(L,g),registerTimeout:(g)=>f$(L,g),registerTurnBudgetAbort:(g)=>S$(L,g),timeoutSignal:q$.signal,timeoutMessage:p,turnBudget:$.turnBudget,onAttemptStart:(g)=>T1(L,g.model,g.thinking),onChildEvent:(g)=>E1(L,g),skipAcceptance:()=>E}),G$=Date.now(),x$=I.interrupted===!0;if(Y.steps[L].status=E?"failed":x$?"paused":I.exitCode===0?"complete":"failed",Y.steps[L].endedAt=G$,Y.steps[L].durationMs=G$-A,Y.steps[L].exitCode=E?1:x$?0:I.exitCode,Y.steps[L].timedOut=E||I.timedOut?!0:void 0,Y.steps[L].turnBudget=I.turnBudget,Y.steps[L].turnBudgetExceeded=I.turnBudgetExceeded,Y.steps[L].wrapUpRequested=I.wrapUpRequested,Y.steps[L].toolBudget=I.toolBudget,Y.steps[L].toolBudgetBlocked=I.toolBudgetBlocked,I.toolBudget)Y.toolBudget=I.toolBudget;if(I.toolBudgetBlocked)Y.toolBudgetBlocked=!0;if(I.turnBudget)Y.turnBudget=I.turnBudget;if(I.turnBudgetExceeded)Y.turnBudgetExceeded=!0;if(I.wrapUpRequested)Y.wrapUpRequested=!0;if(Y.steps[L].model=I.model,Y.steps[L].thinking=O0(I.model,Y.steps[L].thinking),Y.steps[L].attemptedModels=I.attemptedModels,Y.steps[L].modelAttempts=I.modelAttempts,Y.steps[L].totalCost=I.totalCost,Y.steps[L].error=E?p??"Subagent timed out.":I.error,Y.steps[L].transcriptPath=I.transcriptPath??Y.steps[L].transcriptPath,Y.steps[L].transcriptError=I.transcriptError,Y.steps[L].structuredOutput=I.structuredOutput,Y.steps[L].structuredOutputPath=I.structuredOutputPath,Y.steps[L].structuredOutputSchemaPath=I.structuredOutputSchemaPath,Y.steps[L].acceptance=I.acceptance,Y.lastUpdate=G$,a(),$$(n,JSON.stringify({type:E?"subagent.step.failed":x$?"subagent.step.paused":I.exitCode===0?"subagent.step.completed":"subagent.step.failed",ts:G$,runId:j,stepIndex:L,agent:M.agent,exitCode:E?1:x$?0:I.exitCode,durationMs:G$-A})),I.exitCode!==0&&v)F=!0;return E?{...I,output:p??"Subagent timed out.",error:p??"Subagent timed out.",exitCode:1,interrupted:!1,timedOut:!0,skipped:!1}:{...I,skipped:!1}},O);R+=z.length;for(let M of F$)h.push({agent:M.agent,output:M.output,error:M.error,success:M.interrupted!==!0&&M.exitCode===0,exitCode:M.interrupted===!0?0:M.exitCode,skipped:M.skipped,interrupted:M.interrupted,timedOut:M.timedOut,turnBudget:M.turnBudget,turnBudgetExceeded:M.turnBudgetExceeded,wrapUpRequested:M.wrapUpRequested,toolBudget:M.toolBudget,toolBudgetBlocked:M.toolBudgetBlocked,sessionFile:M.sessionFile,intercomTarget:M.intercomTarget,model:M.model,attemptedModels:M.attemptedModels,modelAttempts:M.modelAttempts,totalCost:M.totalCost,artifactPaths:M.artifactPaths,transcriptPath:M.transcriptPath,transcriptError:M.transcriptError,structuredOutput:M.structuredOutput,structuredOutputPath:M.structuredOutputPath,structuredOutputSchemaPath:M.structuredOutputSchemaPath,acceptance:M.acceptance});let C=eJ(V,_.items,F$),z$=F$.filter((M)=>M.exitCode!==0&&M.exitCode!==-1);if(z$.length===0)try{Yj(V.collect.outputSchema,C),y[V.collect.as]={text:JSON.stringify(C),structured:C,agent:V.parallel.agent,stepIndex:H},Y.outputs=y;let M=V.effectiveAcceptance&&!E?await M1({acceptance:V.effectiveAcceptance,output:"",report:Ej({results:F$,notes:`Dynamic fanout collected ${C.length} result(s) into ${V.collect.as}.`}),cwd:Q,signal:q$.signal,abortMessage:p??"Subagent timed out."}):void 0,o=E||q$.signal.aborted,L=o?void 0:M,A=L?L1(L):void 0,I=o?p??"Subagent timed out.":A;if(i(H,I?"failed":"completed",I,L),I)h.push({agent:V.parallel.agent,output:I,error:I,success:!1,exitCode:1,timedOut:o?!0:void 0,structuredOutput:C,acceptance:L}),Y.error=I}catch(M){let o=M instanceof x?M.message:M instanceof Error?M.message:String(M);h.push({agent:V.parallel.agent,output:o,error:o,success:!1,exitCode:1,structuredOutput:C}),Y.error=o,i(H,"failed",o)}if(T=e0(F$.map((M,o)=>({agent:M.agent,taskIndex:o,output:M.output,exitCode:M.exitCode,error:M.error})),(M,o)=>`=== Dynamic Item ${M+1} (${o}, key ${_.items[M]?.key??M}) ===`),$$(n,JSON.stringify({type:"subagent.dynamic.completed",ts:Date.now(),runId:j,stepIndex:H,success:z$.length===0})),z$.length>0)i(H,"failed",z$[0]?.error??"Dynamic fanout child failed.");if(Y.lastUpdate=Date.now(),a(),z$.length>0||Y.error)break;continue}if($0(V)){let K=V,_=K.concurrency??k1,z=K.failFast??!1,N=R,w=!1,d;if(K.worktree){let Z$=N8(K.parallel,Q);if(Z$){let v=Date.now();i8({statusPayload:Y,results:h,group:K,groupStartFlatIndex:N,setupError:C8(Z$,Q),failedAt:v,statusPath:f,eventsPath:n,asyncDir:k,runId:j,stepIndex:H}),R+=K.parallel.length;break}try{d=E8(Q,`${j}-s${H}`,K.parallel.length,{agents:K.parallel.map((v)=>v.agent),setupHook:$.worktreeSetupHook?{hookPath:$.worktreeSetupHook,timeoutMs:$.worktreeSetupHookTimeoutMs}:void 0,baseDir:$.worktreeBaseDir})}catch(v){let F=v instanceof Error?v.message:String(v),F$=Date.now();i8({statusPayload:Y,results:h,group:K,groupStartFlatIndex:N,setupError:F,failedAt:F$,statusPath:f,eventsPath:n,asyncDir:k,runId:j,stepIndex:H}),R+=K.parallel.length;break}}try{if(K.worktree)a5(Q,K);let Z$=Date.now();i5({statusPayload:Y,group:K,groupStartFlatIndex:N,groupStartTime:Z$,statusPath:f,eventsPath:n,asyncDir:k,runId:j,stepIndex:H});let v=await t0(K.parallel,_,async(F,F$)=>{let C=N+F$;if(E)return P(F.agent);if(s)return e$(F.agent);if(w&&z){let g=Date.now();return Y.steps[C].status="failed",Y.steps[C].error="Skipped due to fail-fast",Y.steps[C].startedAt=g,Y.steps[C].endedAt=g,Y.steps[C].durationMs=0,Y.steps[C].exitCode=-1,Y.steps[C].activityState=void 0,Y.lastUpdate=g,a(),$$(n,JSON.stringify({type:"subagent.step.failed",ts:g,runId:j,stepIndex:C,agent:F.agent,exitCode:-1,durationMs:0})),{agent:F.agent,output:"(skipped — fail-fast)",exitCode:-1,skipped:!0}}let z$=Date.now();Y.currentStep=C,Y.steps[C].status="running",Y.steps[C].error=void 0,Y.steps[C].activityState=void 0,yj(Y.steps[C]),Y.steps[C].startedAt=z$,Y.steps[C].endedAt=void 0,Y.steps[C].durationMs=void 0,Y.steps[C].lastActivityAt=z$,Y.outputFile=r.join(k,`output-${C}.log`),Y.lastActivityAt=z$,Y.lastUpdate=z$,a(),$$(n,JSON.stringify({type:"subagent.step.started",ts:z$,runId:j,stepIndex:C,agent:F.agent}));let M=$.sessionDir?r.join($.sessionDir,`parallel-${F$}`):void 0,{taskForRun:o,taskCwd:L}=r5(F,Q,d,F$);C1(C);let A=await kj(o,{previousOutput:T,placeholder:X,cwd:L,sessionEnabled:W0,outputs:y,sessionDir:M,artifactsDir:B,artifactConfig:q,id:j,flatIndex:C,flatStepCount:Math.max(Y.steps.length,1),outputFile:r.join(k,`output-${C}.log`),steerInboxDir:y0(k,C),piPackageRoot:$.piPackageRoot,piArgv1:$.piArgv1,childIntercomTarget:$.childIntercomTargets?.[C],orchestratorIntercomTarget:$.controlIntercomTarget,nestedRoute:$.nestedRoute,registerInterrupt:(g)=>N$(C,g),registerTimeout:(g)=>f$(C,g),registerTurnBudgetAbort:(g)=>S$(C,g),timeoutSignal:q$.signal,timeoutMessage:p,turnBudget:$.turnBudget,onAttemptStart:(g)=>T1(C,g.model,g.thinking),onChildEvent:(g)=>E1(C,g),skipAcceptance:()=>E});if(F.sessionFile)o$=F.sessionFile;let I=Date.now(),G$=I-z$,x$=A.interrupted===!0;if(Y.steps[C].status=E?"failed":x$?"paused":A.exitCode===0?"complete":"failed",Y.steps[C].endedAt=I,Y.steps[C].durationMs=G$,Y.steps[C].exitCode=E?1:x$?0:A.exitCode,Y.steps[C].timedOut=E||A.timedOut?!0:void 0,Y.steps[C].turnBudget=A.turnBudget,Y.steps[C].turnBudgetExceeded=A.turnBudgetExceeded,Y.steps[C].wrapUpRequested=A.wrapUpRequested,Y.steps[C].toolBudget=A.toolBudget,Y.steps[C].toolBudgetBlocked=A.toolBudgetBlocked,A.toolBudget)Y.toolBudget=A.toolBudget;if(A.toolBudgetBlocked)Y.toolBudgetBlocked=!0;if(A.turnBudget)Y.turnBudget=A.turnBudget;if(A.turnBudgetExceeded)Y.turnBudgetExceeded=!0;if(A.wrapUpRequested)Y.wrapUpRequested=!0;if(Y.steps[C].model=A.model,Y.steps[C].thinking=O0(A.model,Y.steps[C].thinking),Y.steps[C].attemptedModels=A.attemptedModels,Y.steps[C].modelAttempts=A.modelAttempts,Y.steps[C].totalCost=A.totalCost,Y.steps[C].error=E?p??"Subagent timed out.":A.error,Y.steps[C].transcriptPath=A.transcriptPath??Y.steps[C].transcriptPath,Y.steps[C].transcriptError=A.transcriptError,Y.steps[C].structuredOutput=A.structuredOutput,Y.steps[C].structuredOutputPath=A.structuredOutputPath,Y.steps[C].structuredOutputSchemaPath=A.structuredOutputSchemaPath,Y.steps[C].acceptance=A.acceptance,Y.lastUpdate=I,a(),$$(n,JSON.stringify({type:E?"subagent.step.failed":x$?"subagent.step.paused":A.exitCode===0?"subagent.step.completed":"subagent.step.failed",ts:I,runId:j,stepIndex:C,agent:F.agent,exitCode:E?1:x$?0:A.exitCode,durationMs:G$})),A.completionGuardTriggered){let g=A0({from:Y.steps[C].activityState,to:"needs_attention",runId:j,agent:F.agent,index:C,ts:I,message:`${F.agent} completed without making edits for an implementation task`,reason:"completion_guard"});E0(g)}if(A.exitCode!==0&&z)w=!0;return E?{...A,output:p??"Subagent timed out.",error:p??"Subagent timed out.",exitCode:1,interrupted:!1,timedOut:!0,skipped:!1}:{...A,skipped:!1}},O);R+=K.parallel.length;for(let F=0;F<K.parallel.length;F++){let F$=N+F,z$=($.sessionDir?Fj(r.join($.sessionDir,`parallel-${F}`)):null)??p8(v[F]?.modelAttempts);if(!z$)continue;Y.steps[F$].tokens=z$,Y$={input:Y$.input+z$.input,output:Y$.output+z$.output,total:Y$.total+z$.total}}Y.totalTokens={...Y$},Y.lastUpdate=Date.now(),a();for(let F of v)h.push({agent:F.agent,output:F.output,error:F.error,success:F.interrupted!==!0&&F.exitCode===0,exitCode:F.interrupted===!0?0:F.exitCode,skipped:F.skipped,interrupted:F.interrupted,timedOut:F.timedOut,turnBudget:F.turnBudget,turnBudgetExceeded:F.turnBudgetExceeded,wrapUpRequested:F.wrapUpRequested,toolBudget:F.toolBudget,toolBudgetBlocked:F.toolBudgetBlocked,sessionFile:F.sessionFile,intercomTarget:F.intercomTarget,model:F.model,attemptedModels:F.attemptedModels,modelAttempts:F.modelAttempts,totalCost:F.totalCost,artifactPaths:F.artifactPaths,transcriptPath:F.transcriptPath,transcriptError:F.transcriptError,structuredOutput:F.structuredOutput,structuredOutputPath:F.structuredOutputPath,structuredOutputSchemaPath:F.structuredOutputSchemaPath,acceptance:F.acceptance});for(let F=0;F<K.parallel.length;F++){let F$=K.parallel[F]?.outputName;if(F$)y[F$]=Hj({agent:v[F].agent,output:v[F].output,structuredOutput:v[F].structuredOutput},H)}if(Y.outputs=y,T=e0(v.map((F)=>({agent:F.agent,output:F.output,exitCode:F.exitCode,error:F.error,model:F.model,attemptedModels:F.attemptedModels}))),T=s5(T,d,k,H,K),$$(n,JSON.stringify({type:"subagent.parallel.completed",ts:Date.now(),runId:j,stepIndex:H,success:v.every((F)=>F.exitCode===0||F.exitCode===-1)})),v.some((F)=>F.exitCode!==0&&F.exitCode!==-1))break}finally{if(d)Oj(d)}}else{let K=V,_=Date.now();Y.currentStep=R,Y.steps[R].status="running",Y.steps[R].activityState=void 0,Y.activityState=void 0,yj(Y.steps[R]),Y.steps[R].skills=K.skills,Y.steps[R].startedAt=_,Y.steps[R].lastActivityAt=_,Y.lastActivityAt=_,Y.lastUpdate=_,Y.outputFile=r.join(k,`output-${R}.log`),a(),$$(n,JSON.stringify({type:"subagent.step.started",ts:_,runId:j,stepIndex:R,agent:K.agent})),C1(R);let z=await kj(K,{previousOutput:T,placeholder:X,cwd:Q,sessionEnabled:W0,outputs:y,sessionDir:$.sessionDir,artifactsDir:B,artifactConfig:q,id:j,flatIndex:R,flatStepCount:Math.max(Y.steps.length,1),outputFile:r.join(k,`output-${R}.log`),steerInboxDir:y0(k,R),piPackageRoot:$.piPackageRoot,piArgv1:$.piArgv1,childIntercomTarget:$.childIntercomTargets?.[R],orchestratorIntercomTarget:$.controlIntercomTarget,nestedRoute:$.nestedRoute,registerInterrupt:(v)=>N$(R,v),registerTimeout:(v)=>f$(R,v),registerTurnBudgetAbort:(v)=>S$(R,v),timeoutSignal:q$.signal,timeoutMessage:p,turnBudget:$.turnBudget,onAttemptStart:(v)=>T1(R,v.model,v.thinking),onChildEvent:(v)=>E1(R,v),skipAcceptance:()=>E});if(K.sessionFile)o$=K.sessionFile;if(T=z.output,h.push({agent:z.agent,output:E?p??"Subagent timed out.":z.output,error:E?p??"Subagent timed out.":z.error,success:!E&&z.interrupted!==!0&&z.exitCode===0,exitCode:E?1:z.interrupted===!0?0:z.exitCode,sessionFile:z.sessionFile,intercomTarget:z.intercomTarget,model:z.model,attemptedModels:z.attemptedModels,modelAttempts:z.modelAttempts,totalCost:z.totalCost,artifactPaths:z.artifactPaths,transcriptPath:z.transcriptPath,transcriptError:z.transcriptError,structuredOutput:z.structuredOutput,structuredOutputPath:z.structuredOutputPath,structuredOutputSchemaPath:z.structuredOutputSchemaPath,acceptance:z.acceptance,interrupted:z.interrupted,timedOut:E||z.timedOut?!0:void 0,turnBudget:z.turnBudget,turnBudgetExceeded:z.turnBudgetExceeded,wrapUpRequested:z.wrapUpRequested,toolBudget:z.toolBudget,toolBudgetBlocked:z.toolBudgetBlocked}),K.outputName)y[K.outputName]=Hj({agent:z.agent,output:z.output,structuredOutput:z.structuredOutput},H);Y.outputs=y;let N=$.sessionDir?Fj($.sessionDir):null,w=N?{input:N.input-Y$.input,output:N.output-Y$.output,total:N.total-Y$.total}:null;if(N)Y$=N;else if(w=p8(z.modelAttempts),w)Y$={input:Y$.input+w.input,output:Y$.output+w.output,total:Y$.total+w.total};let d=Date.now(),Z$=z.interrupted===!0;if(Y.steps[R].status=E?"failed":Z$?"paused":z.exitCode===0?"complete":"failed",Y.steps[R].endedAt=d,Y.steps[R].durationMs=d-_,Y.steps[R].exitCode=E?1:Z$?0:z.exitCode,Y.steps[R].timedOut=E||z.timedOut?!0:void 0,Y.steps[R].turnBudget=z.turnBudget,Y.steps[R].turnBudgetExceeded=z.turnBudgetExceeded,Y.steps[R].wrapUpRequested=z.wrapUpRequested,Y.steps[R].toolBudget=z.toolBudget,Y.steps[R].toolBudgetBlocked=z.toolBudgetBlocked,z.toolBudget)Y.toolBudget=z.toolBudget;if(z.toolBudgetBlocked)Y.toolBudgetBlocked=!0;if(z.turnBudget)Y.turnBudget=z.turnBudget;if(z.turnBudgetExceeded)Y.turnBudgetExceeded=!0;if(z.wrapUpRequested)Y.wrapUpRequested=!0;if(Y.steps[R].model=z.model,Y.steps[R].thinking=O0(z.model,Y.steps[R].thinking),Y.steps[R].attemptedModels=z.attemptedModels,Y.steps[R].modelAttempts=z.modelAttempts,Y.steps[R].totalCost=z.totalCost,Y.steps[R].error=E?p??"Subagent timed out.":z.error,Y.steps[R].transcriptPath=z.transcriptPath??Y.steps[R].transcriptPath,Y.steps[R].transcriptError=z.transcriptError,Y.steps[R].structuredOutput=z.structuredOutput,Y.steps[R].structuredOutputPath=z.structuredOutputPath,Y.steps[R].structuredOutputSchemaPath=z.structuredOutputSchemaPath,Y.steps[R].acceptance=z.acceptance,w)Y.steps[R].tokens=w,Y.totalTokens={...Y$};if(Y.lastUpdate=d,a(),$$(n,JSON.stringify({type:E?"subagent.step.failed":Z$?"subagent.step.paused":z.exitCode===0?"subagent.step.completed":"subagent.step.failed",ts:d,runId:j,stepIndex:R,agent:K.agent,exitCode:E?1:Z$?0:z.exitCode,durationMs:d-_,tokens:w})),z.completionGuardTriggered){let v=A0({from:Y.steps[R].activityState,to:"needs_attention",runId:j,agent:K.agent,index:R,ts:d,message:`${K.agent} completed without making edits for an implementation task`,reason:"completion_guard"});E0(v)}if(R++,z.exitCode!==0)break}}let n0=h.map((H)=>`${H.agent}:
76
- ${H.output}`).join(`
75
+ `).slice(-10)),K.turnCount=(K.turnCount??0)+1;let z=V.message.usage;if(z){let N=z.input??z.inputTokens??0,w=z.output??z.outputTokens??0,d=K.tokens?.input??0,Z$=K.tokens?.output??0;K.tokens={input:d+N,output:Z$+w,total:d+Z$+N+w};let v=Y.totalTokens?.input??0,F=Y.totalTokens?.output??0;Y.totalTokens={input:v+N,output:F+w,total:v+F+N+w}}Y.turnCount=Math.max(Y.turnCount??0,K.turnCount),a8(H,K.turnCount,_,hj(V.message))}A1(),K.lastActivityAt=_,Y.lastActivityAt=_,Y.lastUpdate=_,gj(H,_),a()},t8=(H)=>{if(!W$.enabled)return!1;let V=!1,K=Y.lastActivityAt??S;for(let z=0;z<Y.steps.length;z++){let N=Y.steps[z];if(N.status!=="running")continue;let w=M$(z);if(K=Math.max(K,w),N.lastActivityAt!==w)N.lastActivityAt=w,V=!0;if(qJ({config:W$,startedAt:N.startedAt??S,lastActivityAt:w,now:H})==="needs_attention"){let Z$=N.activityState;if(N.activityState="needs_attention",Z$!=="needs_attention")E0(A0({from:Z$,to:"needs_attention",runId:j,agent:N.agent,index:z,ts:H,lastActivityAt:w})),V=!0}else if(gj(z,H))V=!0}if(Y.lastActivityAt!==K)Y.lastActivityAt=K,V=!0;let _=Y.steps.some((z)=>z.activityState==="needs_attention")?"needs_attention":Y.steps.some((z)=>z.activityState==="active_long_running")?"active_long_running":void 0;if(_!==E$)E$=_,Y.activityState=_,V=!0;if(Y.lastUpdate=H,V)a();return V};if(W$.enabled)X$=setInterval(()=>{if(Y.state!=="running")return;let H=Date.now();t8(H)},1000),X$.unref?.();let mj=()=>{if(g1(k),s||Y.state!=="running")return;s=!0;let H=Date.now();Y.state="paused",E$=void 0,Y.activityState=void 0,Y.lastUpdate=H;for(let V of Y.steps)if(V.status==="running")V.status="paused",V.activityState=void 0,V.endedAt=H,V.durationMs=V.startedAt?H-V.startedAt:void 0,V.lastActivityAt=H;a(),$$(n,JSON.stringify({type:"subagent.run.paused",ts:H,runId:j})),l$(),t$()},cj=()=>{if(E||s||Y.state!=="running")return;E=!0;let H=Date.now(),V=p??"Subagent timed out.";Y.state="failed",Y.timedOut=!0,Y.error=V,E$=void 0,Y.activityState=void 0,Y.lastUpdate=H;for(let K of Y.steps){if(K.status!=="running"&&K.status!=="pending")continue;K.status="failed",K.error=V,K.exitCode=1,K.timedOut=!0,K.activityState=void 0,K.endedAt=H,K.durationMs=K.startedAt?H-K.startedAt:0,K.lastActivityAt=H}a(),$$(n,JSON.stringify({type:"subagent.run.timed_out",ts:H,runId:j,timeoutMs:$.timeoutMs,deadlineAt:$.deadlineAt,message:V})),q$.abort(),p$(),P$()};process.on(y5,mj);let e8=UJ(k,{onInterrupt:mj,onTimeout:cj,onSteer:(H)=>{if((H.targetIndex!==void 0?Y.steps[H.targetIndex]:void 0)?.status==="pending")A$.push(H);else if(H.targetIndex!==void 0||Y.steps.some((K)=>K.status==="running"))N1(H);else A$.push(H)}});if($.deadlineAt!==void 0){let H=Math.max(0,$.deadlineAt-Date.now());_$=setTimeout(cj,H),_$.unref?.()}$$(n,JSON.stringify({type:"subagent.run.started",lifecycleArtifactVersion:S0,ts:S,runId:j,mode:Y.mode,cwd:Q,pid:process.pid}));let R=0,dj=0;while(!0){if(s||E||t)break;if(D(),dj>=J.length)break;let H=dj++,V=J[H];if(j0(V)){let K=R,_;try{if(_=tJ(V,y,H,{maxItems:$.dynamicFanoutMaxItems,allowRunnerFields:!0}),_.collectedOnEmpty)Yj(V.collect.outputSchema,_.collectedOnEmpty)}catch(M){let o=Date.now(),L=M instanceof x?M.message:M instanceof Error?M.message:String(M);Y.state="failed",Y.error=L,Y.currentStep=R;let A=Y.steps[K];if(A)A.status="failed",A.error=L,A.startedAt=o,A.endedAt=o,A.durationMs=0,A.exitCode=1;Y.lastUpdate=o,i(H,"failed",L),a(),h.push({agent:V.parallel.agent,output:L,error:L,success:!1,exitCode:1});break}if(_.parallel.length===0){let M=Date.now(),o=_.collectedOnEmpty??[];y[V.collect.as]={text:JSON.stringify(o),structured:o,agent:V.parallel.agent,stepIndex:H},Y.outputs=y;let L=Y.steps[K];if(L)L.status="complete",L.startedAt=M,L.endedAt=M,L.durationMs=0;T="Dynamic fanout produced 0 results.";let A=V.effectiveAcceptance?.explicit&&!E?await M1({acceptance:V.effectiveAcceptance,output:"",report:Ej({results:[],notes:"Dynamic fanout produced 0 results."}),cwd:Q,signal:q$.signal,abortMessage:p??"Subagent timed out."}):void 0,I=E||q$.signal.aborted,G$=I?void 0:A;if(L&&G$)L.acceptance=G$;let x$=G$?L1(G$):void 0;if(I||x$){let g=I?p??"Subagent timed out.":x$;if(Y.state="failed",Y.error=g,L)L.status="failed",L.error=g,L.exitCode=1,L.timedOut=I?!0:void 0;i(H,"failed",g,G$),Y.lastUpdate=Date.now(),a(),h.push({agent:V.parallel.agent,output:g,error:g,success:!1,exitCode:1,timedOut:I?!0:void 0,acceptance:G$});break}R++,Y.lastUpdate=M,i(H,"completed",void 0,G$),a();continue}let z=_.parallel.map((M,o)=>{let L=V.thinkingOverrides?.[o],A=L?W1(V.parallel.model,L,!0):V.parallel.model,I=L?O0(A,L):void 0;return{...V.parallel,task:M.task??V.parallel.task,label:M.label??V.parallel.label,...V.sessionFiles?.[o]?{sessionFile:V.sessionFiles[o]}:{},...L?{...A?{model:A}:{},...I?{thinking:I}:{},...V.parallel.modelCandidates?{modelCandidates:V.parallel.modelCandidates.map((G$)=>W1(G$,L,!0))}:{}}:{},structuredOutput:void 0,structuredOutputSchema:V.parallel.structuredOutputSchema??V.parallel.structuredOutput?.schema}}),N=Math.max(Y.steps.length-1+z.length,1),w=z.map((M,o)=>{let L=fj({artifactsDir:B,artifactConfig:q,runId:j,agent:M.agent,flatIndex:K+o,flatStepCount:N});return{agent:M.agent,phase:M.phase??V.phase,label:M.label,outputName:void 0,structured:Boolean(M.structuredOutputSchema),status:"pending",...M.sessionFile?{sessionFile:M.sessionFile}:{},...L?{transcriptPath:L}:{},skills:M.skills,model:M.model,thinking:M.thinking,attemptedModels:M.modelCandidates&&M.modelCandidates.length>0?M.modelCandidates:M.model?[M.model]:void 0,recentTools:[],recentOutput:[]}});if(Y.steps.splice(K,1,...w),$.childIntercomTargets)$.childIntercomTargets=Y.steps.map((M,o)=>Aj(j,M.agent,o));p0.splice(K,1,...w.map(()=>G1())),T0.splice(K,1,...w.map(()=>{return}));let d=w.length-1;for(let M of Y.parallelGroups)if(M.stepIndex===H)M.start=K,M.count=w.length;else if(M.start>K)M.start+=d;if(Y.workflowGraph){let M=(L)=>{for(let A of L){if(A.stepIndex!==void 0&&A.stepIndex>H&&A.flatIndex!==void 0&&A.flatIndex>=K)A.flatIndex+=w.length;if(A.children)M(A.children)}};M(Y.workflowGraph.nodes);let o=Y.workflowGraph.nodes.find((L)=>L.id===`step-${H}`);if(o)o.children=_.items.map((L,A)=>({id:`step-${H}-item-${L.idKey}`,kind:"agent",agent:V.parallel.agent,phase:z[A]?.phase??V.phase,label:z[A]?.label?.trim()||`${V.parallel.agent} ${L.key}`,status:"pending",flatIndex:K+A,stepIndex:H,itemKey:L.key,structured:Boolean(z[A]?.structuredOutputSchema)}))}a();let Z$=V.concurrency??k1,v=V.failFast??!1,F=!1,F$=await t0(z,Z$,async(M,o)=>{let L=K+o;if(E)return P(M.agent);if(s)return e$(M.agent);if(F&&v){let g=Date.now();return Y.steps[L].status="failed",Y.steps[L].error="Skipped due to fail-fast",Y.steps[L].startedAt=g,Y.steps[L].endedAt=g,Y.steps[L].durationMs=0,Y.steps[L].exitCode=-1,Y.lastUpdate=g,a(),{agent:M.agent,output:"(skipped — fail-fast)",exitCode:-1,skipped:!0}}let A=Date.now();Y.currentStep=L,Y.steps[L].status="running",Y.steps[L].error=void 0,Y.steps[L].activityState=void 0,yj(Y.steps[L]),Y.steps[L].startedAt=A,Y.steps[L].lastActivityAt=A,Y.outputFile=r.join(k,`output-${L}.log`),Y.lastActivityAt=A,Y.lastUpdate=A,a(),$$(n,JSON.stringify({type:"subagent.step.started",ts:A,runId:j,stepIndex:L,agent:M.agent})),C1(L);let I=await kj(M,{previousOutput:T,placeholder:X,cwd:Q,sessionEnabled:W0,outputs:y,sessionDir:$.sessionDir?r.join($.sessionDir,`dynamic-${H}-${o}`):void 0,artifactsDir:B,artifactConfig:q,id:j,flatIndex:L,flatStepCount:Math.max(Y.steps.length,1),outputFile:r.join(k,`output-${L}.log`),steerInboxDir:y0(k,L),piPackageRoot:$.piPackageRoot,piArgv1:$.piArgv1,childIntercomTarget:$.childIntercomTargets?.[L],orchestratorIntercomTarget:$.controlIntercomTarget,nestedRoute:$.nestedRoute,registerInterrupt:(g)=>N$(L,g),registerTimeout:(g)=>f$(L,g),registerTurnBudgetAbort:(g)=>S$(L,g),timeoutSignal:q$.signal,timeoutMessage:p,turnBudget:$.turnBudget,onAttemptStart:(g)=>T1(L,g.model,g.thinking),onChildEvent:(g)=>E1(L,g),skipAcceptance:()=>E}),G$=Date.now(),x$=I.interrupted===!0;if(Y.steps[L].status=E?"failed":x$?"paused":I.exitCode===0?"complete":"failed",Y.steps[L].endedAt=G$,Y.steps[L].durationMs=G$-A,Y.steps[L].exitCode=E?1:x$?0:I.exitCode,Y.steps[L].timedOut=E||I.timedOut?!0:void 0,Y.steps[L].turnBudget=I.turnBudget,Y.steps[L].turnBudgetExceeded=I.turnBudgetExceeded,Y.steps[L].wrapUpRequested=I.wrapUpRequested,Y.steps[L].toolBudget=I.toolBudget,Y.steps[L].toolBudgetBlocked=I.toolBudgetBlocked,I.toolBudget)Y.toolBudget=I.toolBudget;if(I.toolBudgetBlocked)Y.toolBudgetBlocked=!0;if(I.turnBudget)Y.turnBudget=I.turnBudget;if(I.turnBudgetExceeded)Y.turnBudgetExceeded=!0;if(I.wrapUpRequested)Y.wrapUpRequested=!0;if(Y.steps[L].model=I.model,Y.steps[L].thinking=O0(I.model,Y.steps[L].thinking),Y.steps[L].attemptedModels=I.attemptedModels,Y.steps[L].modelAttempts=I.modelAttempts,Y.steps[L].totalCost=I.totalCost,Y.steps[L].error=E?p??"Subagent timed out.":I.error,Y.steps[L].transcriptPath=I.transcriptPath??Y.steps[L].transcriptPath,Y.steps[L].transcriptError=I.transcriptError,Y.steps[L].structuredOutput=I.structuredOutput,Y.steps[L].structuredOutputPath=I.structuredOutputPath,Y.steps[L].structuredOutputSchemaPath=I.structuredOutputSchemaPath,Y.steps[L].acceptance=I.acceptance,Y.lastUpdate=G$,a(),$$(n,JSON.stringify({type:E?"subagent.step.failed":x$?"subagent.step.paused":I.exitCode===0?"subagent.step.completed":"subagent.step.failed",ts:G$,runId:j,stepIndex:L,agent:M.agent,exitCode:E?1:x$?0:I.exitCode,durationMs:G$-A})),I.exitCode!==0&&v)F=!0;return E?{...I,output:p??"Subagent timed out.",error:p??"Subagent timed out.",exitCode:1,interrupted:!1,timedOut:!0,skipped:!1}:{...I,skipped:!1}},O);R+=z.length;for(let M of F$)h.push({agent:M.agent,output:M.output,error:M.error,success:M.interrupted!==!0&&M.exitCode===0,exitCode:M.interrupted===!0?0:M.exitCode,skipped:M.skipped,interrupted:M.interrupted,timedOut:M.timedOut,turnBudget:M.turnBudget,turnBudgetExceeded:M.turnBudgetExceeded,wrapUpRequested:M.wrapUpRequested,toolBudget:M.toolBudget,toolBudgetBlocked:M.toolBudgetBlocked,sessionFile:M.sessionFile,intercomTarget:M.intercomTarget,model:M.model,attemptedModels:M.attemptedModels,modelAttempts:M.modelAttempts,totalCost:M.totalCost,artifactPaths:M.artifactPaths,transcriptPath:M.transcriptPath,transcriptError:M.transcriptError,structuredOutput:M.structuredOutput,structuredOutputPath:M.structuredOutputPath,structuredOutputSchemaPath:M.structuredOutputSchemaPath,acceptance:M.acceptance});let C=eJ(V,_.items,F$),z$=F$.filter((M)=>M.exitCode!==0&&M.exitCode!==-1);if(z$.length===0)try{Yj(V.collect.outputSchema,C),y[V.collect.as]={text:JSON.stringify(C),structured:C,agent:V.parallel.agent,stepIndex:H},Y.outputs=y;let M=V.effectiveAcceptance&&!E?await M1({acceptance:V.effectiveAcceptance,output:"",report:Ej({results:F$,notes:`Dynamic fanout collected ${C.length} result(s) into ${V.collect.as}.`}),cwd:Q,signal:q$.signal,abortMessage:p??"Subagent timed out."}):void 0,o=E||q$.signal.aborted,L=o?void 0:M,A=L?L1(L):void 0,I=o?p??"Subagent timed out.":A;if(i(H,I?"failed":"completed",I,L),I)h.push({agent:V.parallel.agent,output:I,error:I,success:!1,exitCode:1,timedOut:o?!0:void 0,structuredOutput:C,acceptance:L}),Y.error=I}catch(M){let o=M instanceof x?M.message:M instanceof Error?M.message:String(M);h.push({agent:V.parallel.agent,output:o,error:o,success:!1,exitCode:1,structuredOutput:C}),Y.error=o,i(H,"failed",o)}if(T=e0(F$.map((M,o)=>({agent:M.agent,taskIndex:o,output:M.output,exitCode:M.exitCode,error:M.error})),(M,o)=>`=== Dynamic Item ${M+1} (${o}, key ${_.items[M]?.key??M}) ===`),$$(n,JSON.stringify({type:"subagent.dynamic.completed",ts:Date.now(),runId:j,stepIndex:H,success:z$.length===0})),z$.length>0)i(H,"failed",z$[0]?.error??"Dynamic fanout child failed.");if(Y.lastUpdate=Date.now(),a(),z$.length>0||Y.error)break;continue}if($0(V)){let K=V,_=K.concurrency??k1,z=K.failFast??!1,N=R,w=!1,d;if(K.worktree){let Z$=N8(K.parallel,Q);if(Z$){let v=Date.now();i8({statusPayload:Y,results:h,group:K,groupStartFlatIndex:N,setupError:C8(Z$,Q),failedAt:v,statusPath:f,eventsPath:n,asyncDir:k,runId:j,stepIndex:H}),R+=K.parallel.length;break}try{d=E8(Q,`${j}-s${H}`,K.parallel.length,{agents:K.parallel.map((v)=>v.agent),setupHook:$.worktreeSetupHook?{hookPath:$.worktreeSetupHook,timeoutMs:$.worktreeSetupHookTimeoutMs}:void 0,baseDir:$.worktreeBaseDir})}catch(v){let F=v instanceof Error?v.message:String(v),F$=Date.now();i8({statusPayload:Y,results:h,group:K,groupStartFlatIndex:N,setupError:F,failedAt:F$,statusPath:f,eventsPath:n,asyncDir:k,runId:j,stepIndex:H}),R+=K.parallel.length;break}}try{if(K.worktree)a5(Q,K);let Z$=Date.now();i5({statusPayload:Y,group:K,groupStartFlatIndex:N,groupStartTime:Z$,statusPath:f,eventsPath:n,asyncDir:k,runId:j,stepIndex:H});let v=await t0(K.parallel,_,async(F,F$)=>{let C=N+F$;if(E)return P(F.agent);if(s)return e$(F.agent);if(w&&z){let g=Date.now();return Y.steps[C].status="failed",Y.steps[C].error="Skipped due to fail-fast",Y.steps[C].startedAt=g,Y.steps[C].endedAt=g,Y.steps[C].durationMs=0,Y.steps[C].exitCode=-1,Y.steps[C].activityState=void 0,Y.lastUpdate=g,a(),$$(n,JSON.stringify({type:"subagent.step.failed",ts:g,runId:j,stepIndex:C,agent:F.agent,exitCode:-1,durationMs:0})),{agent:F.agent,output:"(skipped — fail-fast)",exitCode:-1,skipped:!0}}let z$=Date.now();Y.currentStep=C,Y.steps[C].status="running",Y.steps[C].error=void 0,Y.steps[C].activityState=void 0,yj(Y.steps[C]),Y.steps[C].startedAt=z$,Y.steps[C].endedAt=void 0,Y.steps[C].durationMs=void 0,Y.steps[C].lastActivityAt=z$,Y.outputFile=r.join(k,`output-${C}.log`),Y.lastActivityAt=z$,Y.lastUpdate=z$,a(),$$(n,JSON.stringify({type:"subagent.step.started",ts:z$,runId:j,stepIndex:C,agent:F.agent}));let M=$.sessionDir?r.join($.sessionDir,`parallel-${F$}`):void 0,{taskForRun:o,taskCwd:L}=r5(F,Q,d,F$);C1(C);let A=await kj(o,{previousOutput:T,placeholder:X,cwd:L,sessionEnabled:W0,outputs:y,sessionDir:M,artifactsDir:B,artifactConfig:q,id:j,flatIndex:C,flatStepCount:Math.max(Y.steps.length,1),outputFile:r.join(k,`output-${C}.log`),steerInboxDir:y0(k,C),piPackageRoot:$.piPackageRoot,piArgv1:$.piArgv1,childIntercomTarget:$.childIntercomTargets?.[C],orchestratorIntercomTarget:$.controlIntercomTarget,nestedRoute:$.nestedRoute,registerInterrupt:(g)=>N$(C,g),registerTimeout:(g)=>f$(C,g),registerTurnBudgetAbort:(g)=>S$(C,g),timeoutSignal:q$.signal,timeoutMessage:p,turnBudget:$.turnBudget,onAttemptStart:(g)=>T1(C,g.model,g.thinking),onChildEvent:(g)=>E1(C,g),skipAcceptance:()=>E});if(F.sessionFile)o$=F.sessionFile;let I=Date.now(),G$=I-z$,x$=A.interrupted===!0;if(Y.steps[C].status=E?"failed":x$?"paused":A.exitCode===0?"complete":"failed",Y.steps[C].endedAt=I,Y.steps[C].durationMs=G$,Y.steps[C].exitCode=E?1:x$?0:A.exitCode,Y.steps[C].timedOut=E||A.timedOut?!0:void 0,Y.steps[C].turnBudget=A.turnBudget,Y.steps[C].turnBudgetExceeded=A.turnBudgetExceeded,Y.steps[C].wrapUpRequested=A.wrapUpRequested,Y.steps[C].toolBudget=A.toolBudget,Y.steps[C].toolBudgetBlocked=A.toolBudgetBlocked,A.toolBudget)Y.toolBudget=A.toolBudget;if(A.toolBudgetBlocked)Y.toolBudgetBlocked=!0;if(A.turnBudget)Y.turnBudget=A.turnBudget;if(A.turnBudgetExceeded)Y.turnBudgetExceeded=!0;if(A.wrapUpRequested)Y.wrapUpRequested=!0;if(Y.steps[C].model=A.model,Y.steps[C].thinking=O0(A.model,Y.steps[C].thinking),Y.steps[C].attemptedModels=A.attemptedModels,Y.steps[C].modelAttempts=A.modelAttempts,Y.steps[C].totalCost=A.totalCost,Y.steps[C].error=E?p??"Subagent timed out.":A.error,Y.steps[C].transcriptPath=A.transcriptPath??Y.steps[C].transcriptPath,Y.steps[C].transcriptError=A.transcriptError,Y.steps[C].structuredOutput=A.structuredOutput,Y.steps[C].structuredOutputPath=A.structuredOutputPath,Y.steps[C].structuredOutputSchemaPath=A.structuredOutputSchemaPath,Y.steps[C].acceptance=A.acceptance,Y.lastUpdate=I,a(),$$(n,JSON.stringify({type:E?"subagent.step.failed":x$?"subagent.step.paused":A.exitCode===0?"subagent.step.completed":"subagent.step.failed",ts:I,runId:j,stepIndex:C,agent:F.agent,exitCode:E?1:x$?0:A.exitCode,durationMs:G$})),A.completionGuardTriggered){let g=A0({from:Y.steps[C].activityState,to:"needs_attention",runId:j,agent:F.agent,index:C,ts:I,message:`${F.agent} completed without making edits for an implementation task`,reason:"completion_guard"});E0(g)}if(A.exitCode!==0&&z)w=!0;return E?{...A,output:p??"Subagent timed out.",error:p??"Subagent timed out.",exitCode:1,interrupted:!1,timedOut:!0,skipped:!1}:{...A,skipped:!1}},O);R+=K.parallel.length;for(let F=0;F<K.parallel.length;F++){let F$=N+F,z$=($.sessionDir?Fj(r.join($.sessionDir,`parallel-${F}`)):null)??p8(v[F]?.modelAttempts);if(!z$)continue;Y.steps[F$].tokens=z$,Y$={input:Y$.input+z$.input,output:Y$.output+z$.output,total:Y$.total+z$.total}}Y.totalTokens={...Y$},Y.lastUpdate=Date.now(),a();for(let F of v)h.push({agent:F.agent,output:F.output,error:F.error,success:F.interrupted!==!0&&F.exitCode===0,exitCode:F.interrupted===!0?0:F.exitCode,skipped:F.skipped,interrupted:F.interrupted,timedOut:F.timedOut,turnBudget:F.turnBudget,turnBudgetExceeded:F.turnBudgetExceeded,wrapUpRequested:F.wrapUpRequested,toolBudget:F.toolBudget,toolBudgetBlocked:F.toolBudgetBlocked,sessionFile:F.sessionFile,intercomTarget:F.intercomTarget,model:F.model,attemptedModels:F.attemptedModels,modelAttempts:F.modelAttempts,totalCost:F.totalCost,artifactPaths:F.artifactPaths,transcriptPath:F.transcriptPath,transcriptError:F.transcriptError,structuredOutput:F.structuredOutput,structuredOutputPath:F.structuredOutputPath,structuredOutputSchemaPath:F.structuredOutputSchemaPath,acceptance:F.acceptance});for(let F=0;F<K.parallel.length;F++){let F$=K.parallel[F]?.outputName;if(F$)y[F$]=Hj({agent:v[F].agent,output:v[F].output,structuredOutput:v[F].structuredOutput},H)}if(Y.outputs=y,T=e0(v.map((F)=>({agent:F.agent,output:F.output,exitCode:F.exitCode,error:F.error,model:F.model,attemptedModels:F.attemptedModels}))),T=s5(T,d,k,H,K),$$(n,JSON.stringify({type:"subagent.parallel.completed",ts:Date.now(),runId:j,stepIndex:H,success:v.every((F)=>F.exitCode===0||F.exitCode===-1)})),v.some((F)=>F.exitCode!==0&&F.exitCode!==-1))break}finally{if(d)Oj(d)}}else{let K=V,_=Date.now();Y.currentStep=R,Y.steps[R].status="running",Y.steps[R].activityState=void 0,Y.activityState=void 0,yj(Y.steps[R]),Y.steps[R].skills=K.skills,Y.steps[R].startedAt=_,Y.steps[R].lastActivityAt=_,Y.lastActivityAt=_,Y.lastUpdate=_,Y.outputFile=r.join(k,`output-${R}.log`),a(),$$(n,JSON.stringify({type:"subagent.step.started",ts:_,runId:j,stepIndex:R,agent:K.agent})),C1(R);let z=await kj(K,{previousOutput:T,placeholder:X,cwd:Q,sessionEnabled:W0,outputs:y,sessionDir:$.sessionDir,artifactsDir:B,artifactConfig:q,id:j,flatIndex:R,flatStepCount:Math.max(Y.steps.length,1),outputFile:r.join(k,`output-${R}.log`),steerInboxDir:y0(k,R),piPackageRoot:$.piPackageRoot,piArgv1:$.piArgv1,childIntercomTarget:$.childIntercomTargets?.[R],orchestratorIntercomTarget:$.controlIntercomTarget,nestedRoute:$.nestedRoute,registerInterrupt:(v)=>N$(R,v),registerTimeout:(v)=>f$(R,v),registerTurnBudgetAbort:(v)=>S$(R,v),timeoutSignal:q$.signal,timeoutMessage:p,turnBudget:$.turnBudget,onAttemptStart:(v)=>T1(R,v.model,v.thinking),onChildEvent:(v)=>E1(R,v),skipAcceptance:()=>E});if(K.sessionFile)o$=K.sessionFile;if(T=z.output,h.push({agent:z.agent,output:E?p??"Subagent timed out.":z.output,error:E?p??"Subagent timed out.":z.error,success:!E&&z.interrupted!==!0&&z.exitCode===0,exitCode:E?1:z.interrupted===!0?0:z.exitCode,sessionFile:z.sessionFile,intercomTarget:z.intercomTarget,model:z.model,attemptedModels:z.attemptedModels,modelAttempts:z.modelAttempts,totalCost:z.totalCost,artifactPaths:z.artifactPaths,transcriptPath:z.transcriptPath,transcriptError:z.transcriptError,structuredOutput:z.structuredOutput,structuredOutputPath:z.structuredOutputPath,structuredOutputSchemaPath:z.structuredOutputSchemaPath,acceptance:z.acceptance,interrupted:z.interrupted,timedOut:E||z.timedOut?!0:void 0,turnBudget:z.turnBudget,turnBudgetExceeded:z.turnBudgetExceeded,wrapUpRequested:z.wrapUpRequested,toolBudget:z.toolBudget,toolBudgetBlocked:z.toolBudgetBlocked}),K.outputName)y[K.outputName]=Hj({agent:z.agent,output:z.output,structuredOutput:z.structuredOutput},H);Y.outputs=y;let N=$.sessionDir?Fj($.sessionDir):null,w=N?{input:N.input-Y$.input,output:N.output-Y$.output,total:N.total-Y$.total}:null;if(N)Y$=N;else if(w=p8(z.modelAttempts),w)Y$={input:Y$.input+w.input,output:Y$.output+w.output,total:Y$.total+w.total};let d=Date.now(),Z$=z.interrupted===!0;if(Y.steps[R].status=E?"failed":Z$?"paused":z.exitCode===0?"complete":"failed",Y.steps[R].endedAt=d,Y.steps[R].durationMs=d-_,Y.steps[R].exitCode=E?1:Z$?0:z.exitCode,Y.steps[R].timedOut=E||z.timedOut?!0:void 0,Y.steps[R].turnBudget=z.turnBudget,Y.steps[R].turnBudgetExceeded=z.turnBudgetExceeded,Y.steps[R].wrapUpRequested=z.wrapUpRequested,Y.steps[R].toolBudget=z.toolBudget,Y.steps[R].toolBudgetBlocked=z.toolBudgetBlocked,z.toolBudget)Y.toolBudget=z.toolBudget;if(z.toolBudgetBlocked)Y.toolBudgetBlocked=!0;if(z.turnBudget)Y.turnBudget=z.turnBudget;if(z.turnBudgetExceeded)Y.turnBudgetExceeded=!0;if(z.wrapUpRequested)Y.wrapUpRequested=!0;if(Y.steps[R].model=z.model,Y.steps[R].thinking=O0(z.model,Y.steps[R].thinking),Y.steps[R].attemptedModels=z.attemptedModels,Y.steps[R].modelAttempts=z.modelAttempts,Y.steps[R].totalCost=z.totalCost,Y.steps[R].error=E?p??"Subagent timed out.":z.error,Y.steps[R].transcriptPath=z.transcriptPath??Y.steps[R].transcriptPath,Y.steps[R].transcriptError=z.transcriptError,Y.steps[R].structuredOutput=z.structuredOutput,Y.steps[R].structuredOutputPath=z.structuredOutputPath,Y.steps[R].structuredOutputSchemaPath=z.structuredOutputSchemaPath,Y.steps[R].acceptance=z.acceptance,w)Y.steps[R].tokens=w,Y.totalTokens={...Y$};if(Y.lastUpdate=d,a(),$$(n,JSON.stringify({type:E?"subagent.step.failed":Z$?"subagent.step.paused":z.exitCode===0?"subagent.step.completed":"subagent.step.failed",ts:d,runId:j,stepIndex:R,agent:K.agent,exitCode:E?1:Z$?0:z.exitCode,durationMs:d-_,tokens:w})),z.completionGuardTriggered){let v=A0({from:Y.steps[R].activityState,to:"needs_attention",runId:j,agent:K.agent,index:R,ts:d,message:`${K.agent} completed without making edits for an implementation task`,reason:"completion_guard"});E0(v)}if(R++,z.exitCode!==0)break}}let n0=h.map((H)=>{let V=H.output.trim(),K=V?H.error?`${V}
77
76
 
78
- `),S1=!1;if(G){let H={...nj,...G},V=h[h.length-1]?.artifactPaths?.outputPath,K=sj(n0,H,V);if(K.truncated)n0=K.text,S1=!0}let oj=$.resultMode??Y.mode,i0=h.reduce((H,V)=>({inputTokens:H.inputTokens+(V.totalCost?.inputTokens??0),outputTokens:H.outputTokens+(V.totalCost?.outputTokens??0),costUsd:H.costUsd+(V.totalCost?.costUsd??0)}),{inputTokens:0,outputTokens:0,costUsd:0}),D1=i0.inputTokens>0||i0.outputTokens>0||i0.costUsd>0?i0:void 0,r0=Y.steps.map((H)=>H.agent),$2=r0.length===1?r0[0]:oj==="parallel"?`parallel:${r0.join("+")}`:`chain:${r0.join("->")}`,H0,s0,b1,M0;if(v$){if(H0=$.sessionDir?m5($.sessionDir)??void 0:void 0,!H0&&o$)H0=o$;if(H0)try{let H=$.sessionDir??r.dirname(H0),V=await l5(H0,H,$.piPackageRoot),K=p5(V);if("error"in K)M0=K.error;else s0=K.shareUrl,b1=K.gistUrl}catch(H){M0=String(H)}else M0="Session file not found."}if(X$)clearInterval(X$),X$=void 0;if(_$)clearTimeout(_$),_$=void 0;e8();let R1=H0??o$,V0=Date.now();if(Y.state=E||t?"failed":s?"paused":h.every((H)=>H.success)?"complete":"failed",Y.activityState=void 0,E)Y.timedOut=!0,Y.error=p??"Subagent timed out.";if(t&&!Y.error){let H=Y.turnBudget;Y.error=H?u0(H,H.turnCount):"Subagent exceeded turn budget."}if(Y.endedAt=V0,Y.lastUpdate=V0,Y.sessionFile=R1,Y.totalCost=D1,Y.shareUrl=s0,Y.gistUrl=b1,Y.shareError=M0,Y.state==="failed"&&!Y.error){let H=Y.steps.find((V)=>V.status==="failed");if(H?.agent)Y.error=`Step failed: ${H.agent}`}a(),$$(n,JSON.stringify({type:"subagent.run.completed",lifecycleArtifactVersion:S0,ts:V0,runId:j,status:Y.state,durationMs:V0-S,totalTokens:Y.totalTokens,totalCost:D1})),n5(d$,{id:j,mode:Y.mode,cwd:Q,startedAt:S,endedAt:V0,steps:Y.steps.map((H)=>({agent:H.agent,status:H.status,durationMs:H.durationMs})),summary:n0,truncated:S1,artifactsDir:B,sessionFile:R1,shareUrl:s0,shareError:M0});try{D$(Z,{lifecycleArtifactVersion:S0,id:j,agent:$2,mode:oj,success:!E&&!t&&!s&&h.every((H)=>H.success),state:E||t?"failed":s?"paused":h.every((H)=>H.success)?"complete":"failed",summary:E?p??"Subagent timed out.":t?Y.error??"Subagent exceeded turn budget.":s?"Paused after interrupt. Waiting for explicit next action.":n0,...$.timeoutMs!==void 0?{timeoutMs:$.timeoutMs}:{},...$.deadlineAt!==void 0?{deadlineAt:$.deadlineAt}:{},...Y.turnBudget?{turnBudget:Y.turnBudget}:{},...Y.turnBudgetExceeded?{turnBudgetExceeded:!0}:{},...Y.wrapUpRequested?{wrapUpRequested:!0}:{},...Y.toolBudget?{toolBudget:Y.toolBudget}:{},...Y.toolBudgetBlocked?{toolBudgetBlocked:!0}:{},...E?{timedOut:!0,error:p??"Subagent timed out."}:t?{error:Y.error??"Subagent exceeded turn budget."}:{},results:h.map((H)=>({agent:H.agent,output:H.output,error:H.error,success:H.success,skipped:H.skipped||void 0,interrupted:H.interrupted||void 0,timedOut:H.timedOut||void 0,turnBudget:H.turnBudget,turnBudgetExceeded:H.turnBudgetExceeded||void 0,wrapUpRequested:H.wrapUpRequested||void 0,toolBudget:H.toolBudget,toolBudgetBlocked:H.toolBudgetBlocked||void 0,sessionFile:H.sessionFile,intercomTarget:H.intercomTarget,model:H.model,attemptedModels:H.attemptedModels,modelAttempts:H.modelAttempts,totalCost:H.totalCost,artifactPaths:H.artifactPaths,truncated:H.truncated,transcriptPath:H.transcriptPath,transcriptError:H.transcriptError,structuredOutput:H.structuredOutput,structuredOutputPath:H.structuredOutputPath,structuredOutputSchemaPath:H.structuredOutputSchemaPath,acceptance:H.acceptance})),outputs:y,workflowGraph:Y.workflowGraph,exitCode:E||t?1:s||h.every((H)=>H.success)?0:1,timestamp:V0,durationMs:V0-S,totalTokens:Y.totalTokens,totalCost:D1,truncated:S1,artifactsDir:B,cwd:Q,asyncDir:k,sessionId:$.sessionId,sessionFile:R1,intercomTarget:$.controlIntercomTarget,shareUrl:s0,gistUrl:b1,shareError:M0,...W!==void 0&&{taskIndex:W},...U!==void 0&&{totalTasks:U}})}catch(H){console.error(`Failed to write result file ${Z}:`,H)}}var Pj=process.argv[2];if(Pj)try{let $=e.readFileSync(Pj,"utf-8"),j=JSON.parse($);try{e.unlinkSync(Pj)}catch{}r8(j).catch((J)=>{console.error("Subagent runner error:",J),process.exit(1)})}catch($){console.error("Subagent runner error:",$),process.exit(1)}else{let $="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",(j)=>{$+=j}),process.stdin.on("end",()=>{try{let j=JSON.parse($);r8(j).catch((J)=>{console.error("Subagent runner error:",J),process.exit(1)})}catch(j){console.error("Subagent runner error:",j),process.exit(1)}})}
77
+ Error: ${H.error}`:V:H.error??"(no output)";return`${H.agent}:
78
+ ${K}`}).join(`
79
+
80
+ `),S1=!1;if(G){let H={...nj,...G},V=h[h.length-1]?.artifactPaths?.outputPath,K=sj(n0,H,V);if(K.truncated)n0=K.text,S1=!0}let oj=$.resultMode??Y.mode,i0=h.reduce((H,V)=>({inputTokens:H.inputTokens+(V.totalCost?.inputTokens??0),outputTokens:H.outputTokens+(V.totalCost?.outputTokens??0),costUsd:H.costUsd+(V.totalCost?.costUsd??0)}),{inputTokens:0,outputTokens:0,costUsd:0}),D1=i0.inputTokens>0||i0.outputTokens>0||i0.costUsd>0?i0:void 0,r0=Y.steps.map((H)=>H.agent),$2=r0.length===1?r0[0]:oj==="parallel"?`parallel:${r0.join("+")}`:`chain:${r0.join("->")}`,H0,s0,b1,M0;if(v$){if(H0=$.sessionDir?m5($.sessionDir)??void 0:void 0,!H0&&o$)H0=o$;if(H0)try{let H=$.sessionDir??r.dirname(H0),V=await l5(H0,H,$.piPackageRoot),K=p5(V);if("error"in K)M0=K.error;else s0=K.shareUrl,b1=K.gistUrl}catch(H){M0=String(H)}else M0="Session file not found."}if(X$)clearInterval(X$),X$=void 0;if(_$)clearTimeout(_$),_$=void 0;e8();let R1=H0??o$,V0=Date.now();if(Y.state=E||t?"failed":s?"paused":h.every((H)=>H.success)?"complete":"failed",Y.activityState=void 0,E)Y.timedOut=!0,Y.error=p??"Subagent timed out.";if(t&&!Y.error){let H=Y.turnBudget;Y.error=H?u0(H,H.turnCount):"Subagent exceeded turn budget."}if(Y.endedAt=V0,Y.lastUpdate=V0,Y.sessionFile=R1,Y.totalCost=D1,Y.shareUrl=s0,Y.gistUrl=b1,Y.shareError=M0,Y.state==="failed"&&!Y.error){let H=Y.steps.find((V)=>V.status==="failed");if(H?.agent)Y.error=H.error?`Step failed: ${H.agent}: ${H.error}`:`Step failed: ${H.agent}`}a(),$$(n,JSON.stringify({type:"subagent.run.completed",lifecycleArtifactVersion:S0,ts:V0,runId:j,status:Y.state,durationMs:V0-S,totalTokens:Y.totalTokens,totalCost:D1})),n5(d$,{id:j,mode:Y.mode,cwd:Q,startedAt:S,endedAt:V0,steps:Y.steps.map((H)=>({agent:H.agent,status:H.status,durationMs:H.durationMs})),summary:n0,truncated:S1,artifactsDir:B,sessionFile:R1,shareUrl:s0,shareError:M0});try{D$(Z,{lifecycleArtifactVersion:S0,id:j,agent:$2,mode:oj,success:!E&&!t&&!s&&h.every((H)=>H.success),state:E||t?"failed":s?"paused":h.every((H)=>H.success)?"complete":"failed",summary:E?p??"Subagent timed out.":t?Y.error??"Subagent exceeded turn budget.":s?"Paused after interrupt. Waiting for explicit next action.":n0,...$.timeoutMs!==void 0?{timeoutMs:$.timeoutMs}:{},...$.deadlineAt!==void 0?{deadlineAt:$.deadlineAt}:{},...Y.turnBudget?{turnBudget:Y.turnBudget}:{},...Y.turnBudgetExceeded?{turnBudgetExceeded:!0}:{},...Y.wrapUpRequested?{wrapUpRequested:!0}:{},...Y.toolBudget?{toolBudget:Y.toolBudget}:{},...Y.toolBudgetBlocked?{toolBudgetBlocked:!0}:{},...E?{timedOut:!0,error:p??"Subagent timed out."}:t?{error:Y.error??"Subagent exceeded turn budget."}:{},results:h.map((H)=>({agent:H.agent,output:H.output,error:H.error,success:H.success,skipped:H.skipped||void 0,interrupted:H.interrupted||void 0,timedOut:H.timedOut||void 0,turnBudget:H.turnBudget,turnBudgetExceeded:H.turnBudgetExceeded||void 0,wrapUpRequested:H.wrapUpRequested||void 0,toolBudget:H.toolBudget,toolBudgetBlocked:H.toolBudgetBlocked||void 0,sessionFile:H.sessionFile,intercomTarget:H.intercomTarget,model:H.model,attemptedModels:H.attemptedModels,modelAttempts:H.modelAttempts,totalCost:H.totalCost,artifactPaths:H.artifactPaths,truncated:H.truncated,transcriptPath:H.transcriptPath,transcriptError:H.transcriptError,structuredOutput:H.structuredOutput,structuredOutputPath:H.structuredOutputPath,structuredOutputSchemaPath:H.structuredOutputSchemaPath,acceptance:H.acceptance})),outputs:y,workflowGraph:Y.workflowGraph,exitCode:E||t?1:s||h.every((H)=>H.success)?0:1,timestamp:V0,durationMs:V0-S,totalTokens:Y.totalTokens,totalCost:D1,truncated:S1,artifactsDir:B,cwd:Q,asyncDir:k,sessionId:$.sessionId,sessionFile:R1,intercomTarget:$.controlIntercomTarget,shareUrl:s0,gistUrl:b1,shareError:M0,...W!==void 0&&{taskIndex:W},...U!==void 0&&{totalTasks:U}})}catch(H){console.error(`Failed to write result file ${Z}:`,H)}}var Pj=process.argv[2];if(Pj)try{let $=e.readFileSync(Pj,"utf-8"),j=JSON.parse($);try{e.unlinkSync(Pj)}catch{}r8(j).catch((J)=>{console.error("Subagent runner error:",J),process.exit(1)})}catch($){console.error("Subagent runner error:",$),process.exit(1)}else{let $="";process.stdin.setEncoding("utf-8"),process.stdin.on("data",(j)=>{$+=j}),process.stdin.on("end",()=>{try{let j=JSON.parse($);r8(j).catch((J)=>{console.error("Subagent runner error:",J),process.exit(1)})}catch(j){console.error("Subagent runner error:",j),process.exit(1)}})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duckmind/dm-windows-x64",
3
- "version": "0.60.2",
3
+ "version": "0.60.6",
4
4
  "description": "DuckMind (dm) binary payload for windows x64",
5
5
  "license": "MIT",
6
6
  "os": [