{"version":3,"file":"agent-session-delegated-work.test.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-delegated-work.test.ts"],"names":[],"mappings":"","sourcesContent":["import { mkdtempSync, rmSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { Agent } from \"@apholdings/jensen-agent-core\";\nimport type { Model } from \"@apholdings/jensen-ai\";\nimport { describe, expect, it } from \"vitest\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\n\nfunction makeSession(): { rootDir: string; session: AgentSession } {\n\tconst rootDir = mkdtempSync(join(tmpdir(), \"jensen-delegated-work-\"));\n\tconst agentDir = join(rootDir, \"agent\");\n\tconst cwd = join(rootDir, \"repo\");\n\n\tconst authStorage = AuthStorage.create(join(agentDir, \"auth.json\"));\n\tconst modelRegistry = new ModelRegistry(authStorage, undefined);\n\tconst model: Model<any> = {\n\t\tid: \"test-model\",\n\t\tname: \"Test Model\",\n\t\tprovider: \"test-provider\",\n\t\tapi: \"openai-chat\",\n\t\tbaseUrl: \"https://example.invalid\",\n\t\treasoning: false,\n\t\tinput: [\"text\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 8000,\n\t\tmaxTokens: 4000,\n\t};\n\tmodelRegistry.registerProvider(\"test-provider\", {\n\t\tbaseUrl: \"https://example.invalid\",\n\t\tapiKey: \"test-key\",\n\t\tapi: \"openai-chat\",\n\t\tmodels: [model],\n\t});\n\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\tconst sessionManager = SessionManager.create(cwd);\n\tconst resourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });\n\tconst agent = new Agent({\n\t\tinitialState: {\n\t\t\tsystemPrompt: \"\",\n\t\t\tmodel,\n\t\t\tthinkingLevel: \"off\",\n\t\t\ttools: [],\n\t\t},\n\t});\n\n\tconst session = new AgentSession({\n\t\tagent,\n\t\tsessionManager,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tresourceLoader,\n\t\tmodelRegistry,\n\t});\n\n\treturn { rootDir, session };\n}\n\ndescribe(\"AgentSession delegated work state\", () => {\n\tit(\"tracks live subagent tool execution state from tool lifecycle events\", async () => {\n\t\tconst { rootDir, session } = makeSession();\n\n\t\ttry {\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\ttoolCallId: \"call_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\targs: { agent: \"worker\", task: \"Implement the panel\" },\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tlet summary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.total).toBe(1);\n\t\t\texpect(summary.active).toHaveLength(1);\n\t\t\texpect(summary.completed).toHaveLength(0);\n\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\ttoolCallId: \"call_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\tresult: {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Done\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: \"single\",\n\t\t\t\t\t\tagentScope: \"user\",\n\t\t\t\t\t\tprojectAgentsDir: null,\n\t\t\t\t\t\tdiscoveryErrors: [],\n\t\t\t\t\t\tresults: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"worker\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Implement the panel\",\n\t\t\t\t\t\t\t\texitCode: 0,\n\t\t\t\t\t\t\t\tmessages: [{ role: \"assistant\", content: [{ type: \"text\", text: \"Panel implemented.\" }] }],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tisError: false,\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tsummary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.active).toHaveLength(0);\n\t\t\texpect(summary.completed).toHaveLength(1);\n\t\t\texpect(summary.failed).toHaveLength(0);\n\t\t\texpect(session.getRecentDelegatedTasks(1)[0]?.outputPreview).toBe(\"Panel implemented.\");\n\t\t} finally {\n\t\t\trmSync(rootDir, { recursive: true, force: true });\n\t\t}\n\t});\n\n\tit(\"tracks parallel child tasks more granularly during the current swarm operation\", async () => {\n\t\tconst { rootDir, session } = makeSession();\n\n\t\ttry {\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\ttoolCallId: \"parallel_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\targs: {\n\t\t\t\t\ttasks: [\n\t\t\t\t\t\t{ agent: \"worker\", task: \"Implement the panel\" },\n\t\t\t\t\t\t{ agent: \"reviewer\", task: \"Review the panel\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tlet summary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.total).toBe(2);\n\t\t\texpect(summary.active).toHaveLength(2);\n\t\t\texpect(summary.completed).toHaveLength(0);\n\t\t\texpect(summary.active.map((task) => task.childIndex)).toEqual([1, 2]);\n\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\ttoolCallId: \"parallel_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\targs: {\n\t\t\t\t\ttasks: [\n\t\t\t\t\t\t{ agent: \"worker\", task: \"Implement the panel\" },\n\t\t\t\t\t\t{ agent: \"reviewer\", task: \"Review the panel\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tpartialResult: {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Parallel: 1/2 done, 1 running...\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: \"parallel\",\n\t\t\t\t\t\tagentScope: \"user\",\n\t\t\t\t\t\tprojectAgentsDir: null,\n\t\t\t\t\t\tdiscoveryErrors: [],\n\t\t\t\t\t\tresults: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"worker\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Implement the panel\",\n\t\t\t\t\t\t\t\texitCode: 0,\n\t\t\t\t\t\t\t\tmessages: [{ role: \"assistant\", content: [{ type: \"text\", text: \"Panel implemented.\" }] }],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"reviewer\",\n\t\t\t\t\t\t\t\tagentSource: \"unknown\",\n\t\t\t\t\t\t\t\ttask: \"Review the panel\",\n\t\t\t\t\t\t\t\texitCode: -1,\n\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 0,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tsummary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.active).toHaveLength(1);\n\t\t\texpect(summary.completed).toHaveLength(1);\n\t\t\texpect(summary.failed).toHaveLength(0);\n\t\t\texpect(summary.active[0]?.agent).toBe(\"reviewer\");\n\t\t\texpect(summary.completed[0]?.agent).toBe(\"worker\");\n\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\ttoolCallId: \"parallel_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\tresult: {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Parallel complete\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: \"parallel\",\n\t\t\t\t\t\tagentScope: \"user\",\n\t\t\t\t\t\tprojectAgentsDir: null,\n\t\t\t\t\t\tdiscoveryErrors: [],\n\t\t\t\t\t\tresults: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"worker\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Implement the panel\",\n\t\t\t\t\t\t\t\texitCode: 0,\n\t\t\t\t\t\t\t\tmessages: [{ role: \"assistant\", content: [{ type: \"text\", text: \"Panel implemented.\" }] }],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"reviewer\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Review the panel\",\n\t\t\t\t\t\t\t\texitCode: 1,\n\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\tstderr: \"Review failed\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tisError: false,\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tsummary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.total).toBe(2);\n\t\t\texpect(summary.active).toHaveLength(0);\n\t\t\texpect(summary.completed).toHaveLength(1);\n\t\t\texpect(summary.failed).toHaveLength(1);\n\t\t\texpect(session.getWorkingContext().delegatedWork).toMatchObject({\n\t\t\t\tactiveCount: 0,\n\t\t\t\tcompletedCount: 1,\n\t\t\t\tfailedCount: 1,\n\t\t\t\tisPersisted: false,\n\t\t\t\tscope: \"current_process_runtime_state\",\n\t\t\t\tfailurePreview: [\n\t\t\t\t\t{\n\t\t\t\t\t\tagent: \"reviewer\",\n\t\t\t\t\t\tmode: \"parallel\",\n\t\t\t\t\t\tstatus: \"error\",\n\t\t\t\t\t\tchildIndex: 2,\n\t\t\t\t\t\ttask: \"Review the panel\",\n\t\t\t\t\t\texitCode: 1,\n\t\t\t\t\t\terrorMessage: \"Review failed\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t} finally {\n\t\t\trmSync(rootDir, { recursive: true, force: true });\n\t\t}\n\t});\n\n\tit(\"tracks chain steps as separate runtime child entries across sequential progress\", async () => {\n\t\tconst { rootDir, session } = makeSession();\n\n\t\ttry {\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\ttoolCallId: \"chain_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\targs: {\n\t\t\t\t\tchain: [\n\t\t\t\t\t\t{ agent: \"planner\", task: \"Plan the feature\" },\n\t\t\t\t\t\t{ agent: \"worker\", task: \"Implement {previous}\" },\n\t\t\t\t\t\t{ agent: \"reviewer\", task: \"Review {previous}\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tlet summary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.total).toBe(1);\n\t\t\texpect(summary.active).toHaveLength(1);\n\t\t\texpect(summary.active[0]).toMatchObject({ step: 1, agent: \"planner\", status: \"active\" });\n\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\ttoolCallId: \"chain_1\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\targs: {\n\t\t\t\t\tchain: [\n\t\t\t\t\t\t{ agent: \"planner\", task: \"Plan the feature\" },\n\t\t\t\t\t\t{ agent: \"worker\", task: \"Implement {previous}\" },\n\t\t\t\t\t\t{ agent: \"reviewer\", task: \"Review {previous}\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t\tpartialResult: {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Chain: step 1 done, step 2 running...\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: \"chain\",\n\t\t\t\t\t\tagentScope: \"user\",\n\t\t\t\t\t\tprojectAgentsDir: null,\n\t\t\t\t\t\tdiscoveryErrors: [],\n\t\t\t\t\t\tresults: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"planner\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Plan the feature\",\n\t\t\t\t\t\t\t\texitCode: 0,\n\t\t\t\t\t\t\t\tstep: 1,\n\t\t\t\t\t\t\t\tmessages: [{ role: \"assistant\", content: [{ type: \"text\", text: \"Plan complete\" }] }],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"worker\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Implement Plan complete\",\n\t\t\t\t\t\t\t\texitCode: -1,\n\t\t\t\t\t\t\t\tstep: 2,\n\t\t\t\t\t\t\t\tmessages: [\n\t\t\t\t\t\t\t\t\t{ role: \"assistant\", content: [{ type: \"text\", text: \"Working on implementation\" }] },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tsummary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.total).toBe(2);\n\t\t\texpect(summary.completed).toHaveLength(1);\n\t\t\texpect(summary.active).toHaveLength(1);\n\t\t\texpect(summary.completed[0]).toMatchObject({ step: 1, agent: \"planner\", status: \"completed\" });\n\t\t\texpect(summary.active[0]).toMatchObject({ step: 2, agent: \"worker\", status: \"active\", exitCode: -1 });\n\t\t\texpect(session.getWorkingContext().delegatedWork).toMatchObject({\n\t\t\t\tactiveCount: 1,\n\t\t\t\tcompletedCount: 1,\n\t\t\t\tfailedCount: 0,\n\t\t\t\tisPersisted: false,\n\t\t\t\tscope: \"current_process_runtime_state\",\n\t\t\t});\n\t\t\texpect(session.getDelegatedTasks().some((task) => task.mode === \"chain\" && task.step === 3)).toBe(false);\n\t\t} finally {\n\t\t\trmSync(rootDir, { recursive: true, force: true });\n\t\t}\n\t});\n\n\tit(\"surfaces a blocked chain child distinctly from an earlier completed step\", async () => {\n\t\tconst { rootDir, session } = makeSession();\n\n\t\ttry {\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\ttoolCallId: \"chain_blocked\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\targs: {\n\t\t\t\t\tchain: [\n\t\t\t\t\t\t{ agent: \"planner\", task: \"Plan the rollout\" },\n\t\t\t\t\t\t{ agent: \"worker\", task: \"Write production config {previous}\" },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\ttoolCallId: \"chain_blocked\",\n\t\t\t\ttoolName: \"subagent\",\n\t\t\t\tresult: {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: \"Chain stopped at step 2 (worker): Approval required before writing production config.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: \"chain\",\n\t\t\t\t\t\tagentScope: \"user\",\n\t\t\t\t\t\tprojectAgentsDir: null,\n\t\t\t\t\t\tdiscoveryErrors: [],\n\t\t\t\t\t\tresults: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"planner\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Plan the rollout\",\n\t\t\t\t\t\t\t\texitCode: 0,\n\t\t\t\t\t\t\t\tstep: 1,\n\t\t\t\t\t\t\t\tmessages: [{ role: \"assistant\", content: [{ type: \"text\", text: \"Plan complete\" }] }],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tagent: \"worker\",\n\t\t\t\t\t\t\t\tagentSource: \"user\",\n\t\t\t\t\t\t\t\ttask: \"Write production config Plan complete\",\n\t\t\t\t\t\t\t\texitCode: 0,\n\t\t\t\t\t\t\t\tstep: 2,\n\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\tstderr: \"\",\n\t\t\t\t\t\t\t\tusage: {\n\t\t\t\t\t\t\t\t\tinput: 0,\n\t\t\t\t\t\t\t\t\toutput: 0,\n\t\t\t\t\t\t\t\t\tcacheRead: 0,\n\t\t\t\t\t\t\t\t\tcacheWrite: 0,\n\t\t\t\t\t\t\t\t\tcost: 0,\n\t\t\t\t\t\t\t\t\tcontextTokens: 0,\n\t\t\t\t\t\t\t\t\tturns: 1,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tstopReason: \"aborted\",\n\t\t\t\t\t\t\t\terrorMessage: \"Approval required before writing production config.\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tisError: true,\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tconst summary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.active).toHaveLength(0);\n\t\t\texpect(summary.completed).toMatchObject([{ step: 1, agent: \"planner\", status: \"completed\" }]);\n\t\t\texpect(summary.failed).toMatchObject([{ step: 2, agent: \"worker\", status: \"blocked\" }]);\n\t\t\texpect(session.getWorkingContext().delegatedWork).toMatchObject({\n\t\t\t\tactiveCount: 0,\n\t\t\t\tcompletedCount: 1,\n\t\t\t\tfailedCount: 1,\n\t\t\t\tisPersisted: false,\n\t\t\t\tscope: \"current_process_runtime_state\",\n\t\t\t\tfailurePreview: [\n\t\t\t\t\t{\n\t\t\t\t\t\tagent: \"worker\",\n\t\t\t\t\t\tmode: \"chain\",\n\t\t\t\t\t\tstatus: \"blocked\",\n\t\t\t\t\t\tstep: 2,\n\t\t\t\t\t\ttask: \"Write production config Plan complete\",\n\t\t\t\t\t\terrorMessage: \"Approval required before writing production config.\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\t\t} finally {\n\t\t\trmSync(rootDir, { recursive: true, force: true });\n\t\t}\n\t});\n\n\tit(\"ignores non-subagent tools\", async () => {\n\t\tconst { rootDir, session } = makeSession();\n\n\t\ttry {\n\t\t\t(session as unknown as { _handleAgentEvent: (event: unknown) => void })._handleAgentEvent({\n\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\ttoolCallId: \"call_bash\",\n\t\t\t\ttoolName: \"bash\",\n\t\t\t\targs: { command: \"echo hi\" },\n\t\t\t});\n\t\t\tawait (session as unknown as { _agentEventQueue: Promise<void> })._agentEventQueue;\n\n\t\t\tconst summary = session.getDelegatedWorkSummary();\n\t\t\texpect(summary.total).toBe(0);\n\t\t} finally {\n\t\t\trmSync(rootDir, { recursive: true, force: true });\n\t\t}\n\t});\n});\n"]}