@ashx-j/lunr 0.2.22 → 0.2.24
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/CHANGELOG.md +16 -1
- package/README.md +15 -13
- package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
- package/dist/builtin-extensions/ashxj-tui.js +2 -2
- package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
- package/dist/builtin-extensions/lunr-browser.d.ts +7 -1
- package/dist/builtin-extensions/lunr-browser.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-browser.js +116 -3
- package/dist/builtin-extensions/lunr-browser.js.map +1 -1
- package/dist/builtin-extensions/lunr-plan-tools.d.ts +7 -7
- package/dist/builtin-extensions/lunr-plan-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-plan-tools.js +12 -12
- package/dist/builtin-extensions/lunr-plan-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.js +2 -0
- package/dist/builtin-extensions/pi-intercom/index.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js +1 -0
- package/dist/builtin-extensions/pi-mcp-adapter/direct-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.js +1 -1
- package/dist/builtin-extensions/pi-mcp-adapter/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +4 -4
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +6 -4
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.js +6 -3
- package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js +7 -2
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js +4 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js +9 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js +41 -3
- package/dist/builtin-extensions/pi-subagents/src/runs/background/wait-tool.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +5 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +3 -2
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +23 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js +17 -15
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js +3 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js +2 -2
- package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js +3 -2
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js.map +1 -1
- package/dist/core/agent-session.d.ts +20 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +235 -107
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/browser/schema.d.ts +1 -1
- package/dist/core/browser/schema.d.ts.map +1 -1
- package/dist/core/browser/schema.js +1 -1
- package/dist/core/browser/schema.js.map +1 -1
- package/dist/core/catalog-cache-scope.d.ts.map +1 -1
- package/dist/core/catalog-cache-scope.js +3 -1
- package/dist/core/catalog-cache-scope.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +3 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/permissions.d.ts +16 -23
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +66 -141
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/plan-mode.d.ts +10 -12
- package/dist/core/plan-mode.d.ts.map +1 -1
- package/dist/core/plan-mode.js +16 -18
- package/dist/core/plan-mode.js.map +1 -1
- package/dist/core/runtime-bridges.d.ts.map +1 -1
- package/dist/core/runtime-bridges.js +2 -0
- package/dist/core/runtime-bridges.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +13 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +9 -2
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +13 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +49 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -4
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/subagent-permission-inherit.d.ts +6 -10
- package/dist/core/subagent-permission-inherit.d.ts.map +1 -1
- package/dist/core/subagent-permission-inherit.js +14 -14
- package/dist/core/subagent-permission-inherit.js.map +1 -1
- package/dist/core/subagent-wait-interruption.d.ts +11 -0
- package/dist/core/subagent-wait-interruption.d.ts.map +1 -0
- package/dist/core/subagent-wait-interruption.js +19 -0
- package/dist/core/subagent-wait-interruption.js.map +1 -0
- package/dist/core/system-prompt.d.ts +2 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +11 -4
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +3 -3
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +3 -3
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/gateway/adapters/discord.d.ts.map +1 -1
- package/dist/gateway/adapters/discord.js +1 -1
- package/dist/gateway/adapters/discord.js.map +1 -1
- package/dist/gateway/approval.d.ts +2 -6
- package/dist/gateway/approval.d.ts.map +1 -1
- package/dist/gateway/approval.js +3 -7
- package/dist/gateway/approval.js.map +1 -1
- package/dist/gateway/mobile-commands.d.ts.map +1 -1
- package/dist/gateway/mobile-commands.js +12 -11
- package/dist/gateway/mobile-commands.js.map +1 -1
- package/dist/gateway/router.d.ts.map +1 -1
- package/dist/gateway/router.js +1 -1
- package/dist/gateway/router.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +10 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +29 -5
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/copyable-text.d.ts +2 -6
- package/dist/modes/interactive/components/copyable-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/copyable-text.js +26 -35
- package/dist/modes/interactive/components/copyable-text.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +7 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +36 -3
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-tail.d.ts +9 -2
- package/dist/modes/interactive/components/thinking-tail.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-tail.js +43 -1
- package/dist/modes/interactive/components/thinking-tail.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +5 -3
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +44 -45
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +7 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +194 -129
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +1 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +23 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/node-runtime/{agent-session-services-NQ6GKOIK.js → agent-session-services-IEF7LQWD.js} +12 -13
- package/dist/node-runtime/{builtin-extensions-GVC6IFDU.js → builtin-extensions-EBAWTH4M.js} +5 -5
- package/dist/node-runtime/{chunk-XLTL257W.js → chunk-2KIPT4HJ.js} +5 -1
- package/dist/node-runtime/{chunk-IWOWXRWU.js → chunk-5Q3EHOHI.js} +21 -21
- package/dist/node-runtime/{chunk-6B2POMK7.js → chunk-6VYZ5UFP.js} +1 -1
- package/dist/node-runtime/{chunk-TQGPP4SC.js → chunk-CDVHZOOK.js} +1 -1
- package/dist/node-runtime/{chunk-TDL7UWJ7.js → chunk-DE2JB6J5.js} +189 -70
- package/dist/node-runtime/{chunk-YJMMG7C6.js → chunk-DSIKTUPW.js} +1 -1
- package/dist/node-runtime/{chunk-IQIEU7SB.js → chunk-F4FLTQKV.js} +2 -2
- package/dist/node-runtime/{chunk-GMHJCCEN.js → chunk-FU6OODRZ.js} +4 -1
- package/dist/node-runtime/{chunk-5BNJ4JUH.js → chunk-GJ2RDBRL.js} +1 -1
- package/dist/node-runtime/{chunk-GNN7H3B7.js → chunk-GS42T6MX.js} +1 -1
- package/dist/node-runtime/{chunk-OFKSVRV7.js → chunk-GYIXXQAO.js} +1 -1
- package/dist/node-runtime/{chunk-BX2RB477.js → chunk-HFVZUPFJ.js} +1 -1
- package/dist/node-runtime/{chunk-PC2Z5TKZ.js → chunk-HMBGROQK.js} +3 -3
- package/dist/node-runtime/{chunk-AZJHNQKQ.js → chunk-I54LGHWM.js} +1 -1
- package/dist/node-runtime/{chunk-IVXYUAJE.js → chunk-IF24A3FH.js} +1 -1
- package/dist/node-runtime/{chunk-VJPTNWAP.js → chunk-IGV54Q5V.js} +3 -3
- package/dist/node-runtime/{chunk-QDGKKKUM.js → chunk-K5AGHH57.js} +18 -13
- package/dist/node-runtime/{chunk-GS66LV4M.js → chunk-KJ6DWS3K.js} +4 -4
- package/dist/node-runtime/{chunk-EQ63ANHL.js → chunk-L3LX4SNR.js} +310 -192
- package/dist/node-runtime/{chunk-VSELYKWU.js → chunk-LWYIVUGV.js} +2 -1
- package/dist/node-runtime/{chunk-JHYKXIMM.js → chunk-MPKSOJBT.js} +1 -1
- package/dist/node-runtime/{chunk-UAFLNHSH.js → chunk-OF7PWMG4.js} +8 -8
- package/dist/node-runtime/{chunk-CSUZVNYE.js → chunk-OVX6X377.js} +10 -6
- package/dist/node-runtime/{chunk-ORH324EP.js → chunk-PCEW76PM.js} +3 -3
- package/dist/node-runtime/{chunk-6427XAWG.js → chunk-QH6YL7VK.js} +3 -3
- package/dist/node-runtime/{chunk-LMBNLFXQ.js → chunk-QM43FEAE.js} +15 -15
- package/dist/node-runtime/{chunk-7QWNYZDI.js → chunk-RDDAZOMU.js} +16 -0
- package/dist/node-runtime/{chunk-WADV2VDS.js → chunk-RORY2HMJ.js} +46 -5
- package/dist/node-runtime/{chunk-H3XF4UVQ.js → chunk-RWTKOC3B.js} +1 -1
- package/dist/node-runtime/{chunk-V2A7CEXK.js → chunk-WHLRAGUQ.js} +13 -12
- package/dist/node-runtime/{chunk-GJSAD4AB.js → chunk-Y73WPE6S.js} +17 -17
- package/dist/node-runtime/{chunk-VSSXXL36.js → chunk-YDO2F2IA.js} +2 -2
- package/dist/node-runtime/{chunk-BFNXONG3.js → chunk-YVI6L6LU.js} +5 -5
- package/dist/node-runtime/{chunk-5D7LC2ZQ.js → chunk-ZXSGTGJ6.js} +54 -85
- package/dist/node-runtime/cli-runtime.js +1 -1
- package/dist/node-runtime/{command-3JHHXOPX.js → command-7BG7VVTS.js} +3 -3
- package/dist/node-runtime/{commands-KAMO2T6P.js → commands-NZLSOHPE.js} +2 -2
- package/dist/node-runtime/{commands-2JVNFGMQ.js → commands-QFDKNQTL.js} +9 -9
- package/dist/node-runtime/{direct-tool-executor-YAVOLDFY.js → direct-tool-executor-77GW4F5P.js} +3 -3
- package/dist/node-runtime/{export-html-KBFVV63J.js → export-html-VM4J2MNR.js} +2 -2
- package/dist/node-runtime/{extension-input-K24TVKVW.js → extension-input-E7BJZ35H.js} +4 -4
- package/dist/node-runtime/{extension-selector-SPNF7EDR.js → extension-selector-WU42XDTU.js} +4 -4
- package/dist/node-runtime/{gateway-VFO6SFKK.js → gateway-TWR3N65G.js} +14 -14
- package/dist/node-runtime/index.js +26 -27
- package/dist/node-runtime/{init-X2LIUB2H.js → init-HS6NQXSK.js} +2 -2
- package/dist/node-runtime/{install-cli-C3CF7O7N.js → install-cli-VAP6KBFN.js} +1 -1
- package/dist/node-runtime/{interactive-mode-LOM6AIF6.js → interactive-mode-6J5VZ2TT.js} +19 -20
- package/dist/node-runtime/{interactive-view-IDSCPPK7.js → interactive-view-NGFAMHPW.js} +7 -7
- package/dist/node-runtime/lunr-browser-J5ZZYVGM.js +174 -0
- package/dist/node-runtime/{lunr-cron-BKHGNBKT.js → lunr-cron-CXOL37AL.js} +7 -7
- package/dist/node-runtime/main.js +22 -23
- package/dist/node-runtime/{mobile-commands-HMP25WBC.js → mobile-commands-VTBM5DSZ.js} +6 -6
- package/dist/node-runtime/{model-runtime-PLQKAG4B.js → model-runtime-OO5HFLWE.js} +1 -1
- package/dist/node-runtime/{package-manager-cli-VCK4E2RC.js → package-manager-cli-ZLW5DZXF.js} +9 -10
- package/dist/node-runtime/{pi-intercom-HBPK5HSJ.js → pi-intercom-QM53RLTS.js} +2 -0
- package/dist/node-runtime/{pi-mcp-adapter-E6WULBKF.js → pi-mcp-adapter-5UKBZP44.js} +7 -6
- package/dist/node-runtime/{pi-subagents-FEUDLJOE.js → pi-subagents-XPCLLKIM.js} +65 -21
- package/dist/node-runtime/{proxy-modes-OSQCWRBI.js → proxy-modes-LGEUYD7R.js} +3 -3
- package/dist/node-runtime/rpc-entry.js +22 -23
- package/dist/node-runtime/{rpc-mode-P5ODXPEG.js → rpc-mode-O3XV4SID.js} +2 -2
- package/dist/node-runtime/{runtime-bridges-3XUQ46XW.js → runtime-bridges-QYXUX2TG.js} +8 -1
- package/dist/node-runtime/{session-handoff-HC7R5E24.js → session-handoff-GWARVEWT.js} +2 -2
- package/dist/node-runtime/{session-manager-CFN4UFM2.js → session-manager-JB5J6XBN.js} +1 -1
- package/dist/node-runtime/{session-selector-LHRMJOKT.js → session-selector-GIM4DHQ2.js} +4 -4
- package/dist/node-runtime/{settings-manager-UUZ6NUXI.js → settings-manager-WCQDUVQB.js} +7 -4
- package/dist/node-runtime/{setup-NRXVZBLJ.js → setup-YRBKH2LD.js} +2 -2
- package/dist/node-runtime/{subagent-executor-MLUMBWCP.js → subagent-executor-OTNISDQU.js} +47 -10
- package/dist/node-runtime/{theme-U7IGOA7O.js → theme-UOO5RVFN.js} +1 -1
- package/dist/node-runtime/{update-cli-4TP25CNW.js → update-cli-VBR2777K.js} +1 -2
- package/dist/startup/interactive-view.d.ts.map +1 -1
- package/dist/startup/interactive-view.js +5 -1
- package/dist/startup/interactive-view.js.map +1 -1
- package/docs/browser.md +1 -1
- package/docs/features.md +17 -14
- package/docs/index.md +1 -1
- package/docs/keybindings.md +1 -1
- package/docs/providers.md +6 -2
- package/docs/quickstart.md +2 -2
- package/docs/settings.md +2 -1
- package/docs/usage.md +6 -6
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/plan-mode/README.md +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/package.json +4 -4
- package/dist/node-runtime/chunk-LISUTZS3.js +0 -19
- package/dist/node-runtime/lunr-browser-YNW7FTYX.js +0 -87
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* persistent/user-config tools stay excluded.
|
|
8
8
|
*
|
|
9
9
|
* Read-only drops mutating coding tools from the registry and still runs under
|
|
10
|
-
*
|
|
10
|
+
* Read-only mode as defense in depth.
|
|
11
11
|
*/
|
|
12
12
|
import type { ChildPermission } from "../../../../../core/subagent-permission-inherit.ts";
|
|
13
13
|
/** Parent-owned / persistent tools excluded even from full children. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child-tools.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/child-tools.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAE1F,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,+IAU3B,CAAC;AAEX,uEAAuE;AACvE,eAAO,MAAM,8BAA8B,0DAKjC,CAAC;AAKX,MAAM,WAAW,6BAA6B;IAC7C,WAAW,EAAE,eAAe,CAAC;IAC7B,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,GAAG,MAAM,EAAE,CASvF;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjE","sourcesContent":["// @ts-nocheck\n/**\n * Central permission-to-tool resolver for prompt-driven children.\n *\n * Full access is the coding-tool set (read/search/shell/edit/write/web/LSP/MCP\n * plus output and supervisor coordination). It is not parent-equivalent: cron,\n * memory, goals, plan approval, nested subagent management, and other\n * persistent/user-config tools stay excluded.\n *\n * Read-only drops mutating coding tools from the registry and still runs under\n *
|
|
1
|
+
{"version":3,"file":"child-tools.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/child-tools.ts"],"names":[],"mappings":"AACA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAE1F,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,+IAU3B,CAAC;AAEX,uEAAuE;AACvE,eAAO,MAAM,8BAA8B,0DAKjC,CAAC;AAKX,MAAM,WAAW,6BAA6B;IAC7C,WAAW,EAAE,eAAe,CAAC;IAC7B,qEAAqE;IACrE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,GAAG,MAAM,EAAE,CASvF;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjE","sourcesContent":["// @ts-nocheck\n/**\n * Central permission-to-tool resolver for prompt-driven children.\n *\n * Full access is the coding-tool set (read/search/shell/edit/write/web/LSP/MCP\n * plus output and supervisor coordination). It is not parent-equivalent: cron,\n * memory, goals, plan approval, nested subagent management, and other\n * persistent/user-config tools stay excluded.\n *\n * Read-only drops mutating coding tools from the registry and still runs under\n * Read-only mode as defense in depth.\n */\n\nimport type { ChildPermission } from \"../../../../../core/subagent-permission-inherit.ts\";\n\n/** Parent-owned / persistent tools excluded even from full children. */\nexport const PARENT_OWNED_CHILD_TOOLS = [\n\t\"cron\",\n\t\"memory_add\",\n\t\"memory_remove\",\n\t\"memory_load\",\n\t\"present_plan\",\n\t\"goal_complete\",\n\t\"goal_blocked\",\n\t\"subagent\",\n\t\"subagent_wait\",\n] as const;\n\n/** Mutating coding tools omitted from the read-only child registry. */\nexport const READ_ONLY_EXCLUDED_CHILD_TOOLS = [\n\t\"edit\",\n\t\"write\",\n\t\"code_rewrite\",\n\t\"lsp_rename\",\n] as const;\n\nconst PARENT_OWNED_SET = new Set<string>(PARENT_OWNED_CHILD_TOOLS);\nconst READ_ONLY_SET = new Set<string>(READ_ONLY_EXCLUDED_CHILD_TOOLS);\n\nexport interface ResolveChildExcludeToolsInput {\n\tpermissions: ChildPermission;\n\t/** Dynamic fanout children may keep the child-safe subagent tool. */\n\tfanoutAuthorized?: boolean;\n}\n\nexport function resolveChildExcludeTools(input: ResolveChildExcludeToolsInput): string[] {\n\tconst excluded = new Set<string>(PARENT_OWNED_SET);\n\tif (input.fanoutAuthorized) {\n\t\texcluded.delete(\"subagent\");\n\t}\n\tif (input.permissions === \"read-only\") {\n\t\tfor (const tool of READ_ONLY_SET) excluded.add(tool);\n\t}\n\treturn [...excluded];\n}\n\nexport function isParentOwnedChildTool(name: string): boolean {\n\treturn PARENT_OWNED_SET.has(name);\n}\n\nexport function isReadOnlyExcludedChildTool(name: string): boolean {\n\treturn READ_ONLY_SET.has(name);\n}\n"]}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* persistent/user-config tools stay excluded.
|
|
9
9
|
*
|
|
10
10
|
* Read-only drops mutating coding tools from the registry and still runs under
|
|
11
|
-
*
|
|
11
|
+
* Read-only mode as defense in depth.
|
|
12
12
|
*/
|
|
13
13
|
/** Parent-owned / persistent tools excluded even from full children. */
|
|
14
14
|
export const PARENT_OWNED_CHILD_TOOLS = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"child-tools.js","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/child-tools.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;;;;GAUG;AAIH,wEAAwE;AACxE,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,MAAM;IACN,YAAY;IACZ,eAAe;IACf,aAAa;IACb,cAAc;IACd,eAAe;IACf,cAAc;IACd,UAAU;IACV,eAAe;CACN,CAAC;AAEX,uEAAuE;AACvE,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C,MAAM;IACN,OAAO;IACP,cAAc;IACd,YAAY;CACH,CAAC;AAEX,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS,wBAAwB,CAAC,CAAC;AACnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAS,8BAA8B,CAAC,CAAC;AAQtE,MAAM,UAAU,wBAAwB,CAAC,KAAoC,EAAY;IACxF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAS,gBAAgB,CAAC,CAAC;IACnD,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC5B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;QACvC,KAAK,MAAM,IAAI,IAAI,aAAa;YAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,CACrB;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAW;IAC7D,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAAA,CAClC;AAED,MAAM,UAAU,2BAA2B,CAAC,IAAY,EAAW;IAClE,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAAA,CAC/B","sourcesContent":["// @ts-nocheck\n/**\n * Central permission-to-tool resolver for prompt-driven children.\n *\n * Full access is the coding-tool set (read/search/shell/edit/write/web/LSP/MCP\n * plus output and supervisor coordination). It is not parent-equivalent: cron,\n * memory, goals, plan approval, nested subagent management, and other\n * persistent/user-config tools stay excluded.\n *\n * Read-only drops mutating coding tools from the registry and still runs under\n *
|
|
1
|
+
{"version":3,"file":"child-tools.js","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/child-tools.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;;;;GAUG;AAIH,wEAAwE;AACxE,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,MAAM;IACN,YAAY;IACZ,eAAe;IACf,aAAa;IACb,cAAc;IACd,eAAe;IACf,cAAc;IACd,UAAU;IACV,eAAe;CACN,CAAC;AAEX,uEAAuE;AACvE,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC7C,MAAM;IACN,OAAO;IACP,cAAc;IACd,YAAY;CACH,CAAC;AAEX,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS,wBAAwB,CAAC,CAAC;AACnE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAS,8BAA8B,CAAC,CAAC;AAQtE,MAAM,UAAU,wBAAwB,CAAC,KAAoC,EAAY;IACxF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAS,gBAAgB,CAAC,CAAC;IACnD,IAAI,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAC5B,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,KAAK,CAAC,WAAW,KAAK,WAAW,EAAE,CAAC;QACvC,KAAK,MAAM,IAAI,IAAI,aAAa;YAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,CACrB;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY,EAAW;IAC7D,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAAA,CAClC;AAED,MAAM,UAAU,2BAA2B,CAAC,IAAY,EAAW;IAClE,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAAA,CAC/B","sourcesContent":["// @ts-nocheck\n/**\n * Central permission-to-tool resolver for prompt-driven children.\n *\n * Full access is the coding-tool set (read/search/shell/edit/write/web/LSP/MCP\n * plus output and supervisor coordination). It is not parent-equivalent: cron,\n * memory, goals, plan approval, nested subagent management, and other\n * persistent/user-config tools stay excluded.\n *\n * Read-only drops mutating coding tools from the registry and still runs under\n * Read-only mode as defense in depth.\n */\n\nimport type { ChildPermission } from \"../../../../../core/subagent-permission-inherit.ts\";\n\n/** Parent-owned / persistent tools excluded even from full children. */\nexport const PARENT_OWNED_CHILD_TOOLS = [\n\t\"cron\",\n\t\"memory_add\",\n\t\"memory_remove\",\n\t\"memory_load\",\n\t\"present_plan\",\n\t\"goal_complete\",\n\t\"goal_blocked\",\n\t\"subagent\",\n\t\"subagent_wait\",\n] as const;\n\n/** Mutating coding tools omitted from the read-only child registry. */\nexport const READ_ONLY_EXCLUDED_CHILD_TOOLS = [\n\t\"edit\",\n\t\"write\",\n\t\"code_rewrite\",\n\t\"lsp_rename\",\n] as const;\n\nconst PARENT_OWNED_SET = new Set<string>(PARENT_OWNED_CHILD_TOOLS);\nconst READ_ONLY_SET = new Set<string>(READ_ONLY_EXCLUDED_CHILD_TOOLS);\n\nexport interface ResolveChildExcludeToolsInput {\n\tpermissions: ChildPermission;\n\t/** Dynamic fanout children may keep the child-safe subagent tool. */\n\tfanoutAuthorized?: boolean;\n}\n\nexport function resolveChildExcludeTools(input: ResolveChildExcludeToolsInput): string[] {\n\tconst excluded = new Set<string>(PARENT_OWNED_SET);\n\tif (input.fanoutAuthorized) {\n\t\texcluded.delete(\"subagent\");\n\t}\n\tif (input.permissions === \"read-only\") {\n\t\tfor (const tool of READ_ONLY_SET) excluded.add(tool);\n\t}\n\treturn [...excluded];\n}\n\nexport function isParentOwnedChildTool(name: string): boolean {\n\treturn PARENT_OWNED_SET.has(name);\n}\n\nexport function isReadOnlyExcludedChildTool(name: string): boolean {\n\treturn READ_ONLY_SET.has(name);\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parseNestedPathEnv, type NestedPathEntry } from "./nested-path.ts";
|
|
2
2
|
import { type JsonSchemaObject, type ResolvedToolBudget } from "../../shared/types.ts";
|
|
3
3
|
import { type ChildWatchdogConfig } from "../../watchdog/child-status.ts";
|
|
4
|
+
export declare const SUBAGENT_COMMUNICATION_ENV = "PI_SUBAGENT_COMMUNICATION_ENABLED";
|
|
4
5
|
export declare const SUBAGENT_CHILD_ENV = "PI_SUBAGENT_CHILD";
|
|
5
6
|
export declare const SUBAGENT_ORCHESTRATOR_TARGET_ENV = "PI_SUBAGENT_ORCHESTRATOR_TARGET";
|
|
6
7
|
export declare const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = "PI_SUBAGENT_ORCHESTRATOR_SESSION_ID";
|
|
@@ -75,6 +76,7 @@ interface BuildPiArgsInput {
|
|
|
75
76
|
excludeTools?: string[];
|
|
76
77
|
childId?: string;
|
|
77
78
|
childDescription?: string;
|
|
79
|
+
communicationEnabled?: boolean;
|
|
78
80
|
}
|
|
79
81
|
interface BuildPiArgsResult {
|
|
80
82
|
args: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-args.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/pi-args.ts"],"names":[],"mappings":"AAKA,OAAO,EAAuB,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGjG,OAAO,EAAiB,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAItG,OAAO,EAAwD,KAAK,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAehI,eAAO,MAAM,kBAAkB,sBAAsB,CAAC;AACtD,eAAO,MAAM,gCAAgC,oCAAoC,CAAC;AAClF,eAAO,MAAM,oCAAoC,wCAAwC,CAAC;AAC1F,eAAO,MAAM,kCAAkC,sCAAsC,CAAC;AACtF,eAAO,MAAM,mCAAmC,uCAAuC,CAAC;AACxF,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AACxD,eAAO,MAAM,wBAAwB,4BAA4B,CAAC;AAClE,eAAO,MAAM,wBAAwB,4BAA4B,CAAC;AAClE,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AACpE,eAAO,MAAM,8BAA8B,kCAAkC,CAAC;AAC9E,eAAO,MAAM,iCAAiC,qCAAqC,CAAC;AACpF,eAAO,MAAM,+BAA+B,mCAAmC,CAAC;AAChF,eAAO,MAAM,0BAA0B,8BAA8B,CAAC;AACtE,eAAO,MAAM,+BAA+B,mCAAmC,CAAC;AAChF,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AACpE,eAAO,MAAM,wBAAwB,4BAA4B,CAAC;AAClE,eAAO,MAAM,oCAAoC,wCAAwC,CAAC;AAC1F,eAAO,MAAM,2BAA2B,+BAA+B,CAAC;AACxE,eAAO,MAAM,mCAAmC,uCA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AAG,iBAAiB,CA8LtE;AAED,eAAO,MAAM,kBAAkB,2BAAqB,CAAC;AAErD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAOvE","sourcesContent":["// @ts-nocheck\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { encodeNestedPathEnv, parseNestedPathEnv, type NestedPathEntry } from \"./nested-path.ts\";\nimport { resolveMcpDirectToolNames } from \"./mcp-direct-tool-allowlist.ts\";\nimport { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV } from \"./structured-output.ts\";\nimport { TEMP_ROOT_DIR, type JsonSchemaObject, type ResolvedToolBudget } from \"../../shared/types.ts\";\nimport { THINKING_LEVELS } from \"../../shared/model-info.ts\";\nimport { TOOL_BUDGET_ENV, encodeToolBudgetEnv } from \"./tool-budget.ts\";\nimport { CHILD_TOOL_DIAGNOSTIC_PATH_ENV, REQUIRED_CHILD_TOOLS_ENV } from \"./tool-availability.ts\";\nimport { CHILD_WATCHDOG_CONFIG_ENV, encodeChildWatchdogConfig, type ChildWatchdogConfig } from \"../../watchdog/child-status.ts\";\nimport { WAIT_TOOL_ENABLED_ENV } from \"../background/wait-config.ts\";\nimport { CHILD_DESCRIPTION_ENV, SUPERVISOR_PROTOCOL_ENV, SUPERVISOR_PROTOCOL_VERSION } from \"../../intercom/communication.ts\";\n\nconst TASK_ARG_LIMIT = 8000;\n// lunr: the bake-in compiles extensions to dist/*.js only; upstream dev mode ships .ts.\n// Resolve the .ts sibling when present, else fall back to the compiled .js so child\n// processes always get a path that exists (the extension loader accepts both).\nfunction resolveRuntimeScriptPath(basePathWithoutExt: string): string {\n\tconst tsPath = `${basePathWithoutExt}.ts`;\n\tif (fs.existsSync(tsPath)) return tsPath;\n\treturn `${basePathWithoutExt}.js`;\n}\nconst PROMPT_RUNTIME_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"subagent-prompt-runtime\"));\nconst FANOUT_CHILD_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"..\", \"..\", \"extension\", \"fanout-child\"));\nexport const SUBAGENT_CHILD_ENV = \"PI_SUBAGENT_CHILD\";\nexport const SUBAGENT_ORCHESTRATOR_TARGET_ENV = \"PI_SUBAGENT_ORCHESTRATOR_TARGET\";\nexport const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = \"PI_SUBAGENT_ORCHESTRATOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_SESSION_ID_ENV = \"PI_SUBAGENT_SUPERVISOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV = \"PI_SUBAGENT_SUPERVISOR_CHANNEL_DIR\";\nexport const SUBAGENT_RUN_ID_ENV = \"PI_SUBAGENT_RUN_ID\";\nexport const SUBAGENT_CHILD_AGENT_ENV = \"PI_SUBAGENT_CHILD_AGENT\";\nexport const SUBAGENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_CHILD_INDEX\";\nexport const SUBAGENT_FANOUT_CHILD_ENV = \"PI_SUBAGENT_FANOUT_CHILD\";\nexport const SUBAGENT_PARENT_EVENT_SINK_ENV = \"PI_SUBAGENT_PARENT_EVENT_SINK\";\nexport const SUBAGENT_PARENT_CONTROL_INBOX_ENV = \"PI_SUBAGENT_PARENT_CONTROL_INBOX\";\nexport const SUBAGENT_PARENT_ROOT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_ROOT_RUN_ID\";\nexport const SUBAGENT_PARENT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_RUN_ID\";\nexport const SUBAGENT_PARENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_PARENT_CHILD_INDEX\";\nexport const SUBAGENT_PARENT_DEPTH_ENV = \"PI_SUBAGENT_PARENT_DEPTH\";\nexport const SUBAGENT_PARENT_PATH_ENV = \"PI_SUBAGENT_PARENT_PATH\";\nexport const SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV = \"PI_SUBAGENT_PARENT_CAPABILITY_TOKEN\";\nexport const SUBAGENT_PARENT_SESSION_ENV = \"PI_SUBAGENT_PARENT_SESSION\";\nexport const SUBAGENT_PARENT_PERMISSION_MODE_ENV = \"PI_SUBAGENT_PARENT_PERMISSION_MODE\";\nexport const SUBAGENT_CHILD_PERMISSION_ENV = \"PI_SUBAGENT_CHILD_PERMISSION\";\nexport const SUBAGENT_STEER_INBOX_ENV = \"PI_SUBAGENT_STEER_INBOX\";\nexport const SUBAGENT_STEER_CAPABILITY_ENV = \"PI_SUBAGENT_STEER_CAPABILITY\";\nexport const SUBAGENT_STEER_ACK_DIR_ENV = \"PI_SUBAGENT_STEER_ACK_DIR\";\n\ninterface BuildPiArgsInput {\n\tparentSessionId?: string;\n\t/** Run ownership is a session file or in-memory UUID; parentSessionId remains the routing UUID. */\n\tsupervisorSessionId?: string;\n\tbaseArgs: string[];\n\ttask: string;\n\tsessionEnabled: boolean;\n\tsessionDir?: string;\n\tsessionFile?: string;\n\tmodel?: string;\n\tthinking?: string | false;\n\tsystemPromptMode?: \"append\" | \"replace\";\n\tinheritProjectContext: boolean;\n\tinheritSkills: boolean;\n\trequireReadTool?: boolean;\n\ttools?: string[];\n\textensions?: string[];\n\tsubagentOnlyExtensions?: string[];\n\tsystemPrompt?: string | null;\n\tmcpDirectTools?: string[];\n\tcwd?: string;\n\tpromptFileStem?: string;\n\tintercomSessionName?: string;\n\torchestratorIntercomTarget?: string;\n\trunId?: string;\n\tchildAgentName?: string;\n\tchildIndex?: number;\n\tparentEventSink?: string;\n\tparentControlInbox?: string;\n\tparentRootRunId?: string;\n\tparentRunId?: string;\n\tparentChildIndex?: number;\n\tparentDepth?: number;\n\tparentPath?: NestedPathEntry[];\n\tparentCapabilityToken?: string;\n\tsteerInboxDir?: string;\n\tsteerCapabilityPath?: string;\n\tsteerAckDir?: string;\n\tstructuredOutput?: {\n\t\tschema: JsonSchemaObject;\n\t\tschemaPath: string;\n\t\toutputPath: string;\n\t};\n\ttoolBudget?: ResolvedToolBudget;\n\tchildWatchdog?: ChildWatchdogConfig;\n\twaitToolEnabled?: boolean;\n\tparentPermissionMode?: string;\n\tchildPermission?: \"full\" | \"read-only\";\n\texcludeTools?: string[];\n\tchildId?: string;\n\tchildDescription?: string;\n}\n\ninterface BuildPiArgsResult {\n\targs: string[];\n\tenv: Record<string, string | undefined>;\n\ttempDir?: string;\n\ttoolDiagnosticPath?: string;\n}\n\nfunction sanitizeSupervisorChannelSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nfunction supervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(TEMP_ROOT_DIR, \"supervisor-channels\", `${sanitizeSupervisorChannelSegment(runId)}-${sanitizeSupervisorChannelSegment(agent)}-${childIndex}`);\n}\n\nexport function applyThinkingSuffix(model: string | undefined, thinking: string | false | undefined, replaceExisting = false): string | undefined {\n\tif (!model || !thinking) return model;\n\tconst colonIdx = model.lastIndexOf(\":\");\n\tif (colonIdx !== -1 && THINKING_LEVELS.some((level) => level === model.substring(colonIdx + 1))) {\n\t\treturn replaceExisting ? `${model.slice(0, colonIdx)}:${thinking}` : model;\n\t}\n\treturn `${model}:${thinking}`;\n}\n\nexport function buildPiArgs(input: BuildPiArgsInput): BuildPiArgsResult {\n\tconst args = [...input.baseArgs];\n\n\tif (input.sessionFile) {\n\t\tfs.mkdirSync(path.dirname(input.sessionFile), { recursive: true });\n\t\targs.push(\"--session\", input.sessionFile);\n\t} else {\n\t\tif (!input.sessionEnabled) {\n\t\t\targs.push(\"--no-session\");\n\t\t}\n\t\tif (input.sessionDir) {\n\t\t\tfs.mkdirSync(input.sessionDir, { recursive: true });\n\t\t\targs.push(\"--session-dir\", input.sessionDir);\n\t\t}\n\t}\n\n\tconst modelArg = applyThinkingSuffix(input.model, input.thinking);\n\tif (modelArg) {\n\t\targs.push(\"--model\", modelArg);\n\t}\n\n\tconst declaredBuiltinToolsBase = input.tools?.filter((tool) => !(tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))) ?? [];\n\tconst declaredBuiltinTools = input.requireReadTool && input.tools?.length && !declaredBuiltinToolsBase.includes(\"read\")\n\t\t? [\"read\", ...declaredBuiltinToolsBase]\n\t\t: declaredBuiltinToolsBase;\n\tconst fanoutAuthorized = declaredBuiltinTools.includes(\"subagent\");\n\tconst toolExtensionPaths: string[] = [];\n\tlet requiredChildTools: string[] = [];\n\tif (input.tools?.length) {\n\t\tconst allowedTools = [...declaredBuiltinTools];\n\t\tfor (const tool of input.tools) {\n\t\t\tif (!declaredBuiltinTools.includes(tool) && (tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))) {\n\t\t\t\ttoolExtensionPaths.push(tool);\n\t\t\t}\n\t\t}\n\t\tif (allowedTools.length > 0) {\n\t\t\tif (input.mcpDirectTools?.length) {\n\t\t\t\tallowedTools.push(...resolveMcpDirectToolNames(input.mcpDirectTools, input.cwd));\n\t\t\t}\n\t\t\tif (input.structuredOutput) allowedTools.push(\"structured_output\");\n\t\t\trequiredChildTools = [...new Set(allowedTools)];\n\t\t\targs.push(\"--tools\", requiredChildTools.join(\",\"));\n\t\t}\n\t}\n\tif (input.excludeTools?.length) {\n\t\targs.push(\"--exclude-tools\", [...new Set(input.excludeTools)].join(\",\"));\n\t}\n\n\tconst runtimeExtensions = fanoutAuthorized\n\t\t? [PROMPT_RUNTIME_EXTENSION_PATH, FANOUT_CHILD_EXTENSION_PATH]\n\t\t: [PROMPT_RUNTIME_EXTENSION_PATH];\n\tif (input.extensions !== undefined) {\n\t\targs.push(\"--no-extensions\");\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...input.extensions, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t} else {\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t}\n\n\tif (!input.inheritSkills) {\n\t\targs.push(\"--no-skills\");\n\t}\n\n\tlet tempDir: string | undefined;\n\tif (input.systemPrompt !== undefined && input.systemPrompt !== null) {\n\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\tconst stem = (input.promptFileStem ?? \"prompt\").replace(/[^\\w.-]/g, \"_\");\n\t\tconst promptPath = path.join(tempDir, `${stem}.md`);\n\t\tfs.writeFileSync(promptPath, input.systemPrompt, { mode: 0o600 });\n\t\targs.push(input.systemPromptMode === \"replace\" ? \"--system-prompt\" : \"--append-system-prompt\", promptPath);\n\t}\n\n\tif (input.task.length > TASK_ARG_LIMIT) {\n\t\tif (!tempDir) {\n\t\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\t}\n\t\tconst taskFilePath = path.join(tempDir, \"task.md\");\n\t\tfs.writeFileSync(taskFilePath, `Task: ${input.task}`, { mode: 0o600 });\n\t\targs.push(`@${taskFilePath}`);\n\t} else {\n\t\targs.push(`Task: ${input.task}`);\n\t}\n\n\tconst env: Record<string, string | undefined> = {};\n\tlet toolDiagnosticPath: string | undefined;\n\tif (requiredChildTools.length > 0) {\n\t\tif (!tempDir) tempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\ttoolDiagnosticPath = path.join(tempDir, \"tool-diagnostic.json\");\n\t\tenv[REQUIRED_CHILD_TOOLS_ENV] = JSON.stringify(requiredChildTools);\n\t\tenv[CHILD_TOOL_DIAGNOSTIC_PATH_ENV] = toolDiagnosticPath;\n\t}\n\tenv[SUBAGENT_CHILD_ENV] = \"1\";\n\tenv[SUBAGENT_CHILD_PERMISSION_ENV] = input.childPermission\n\t\t?? (input.parentPermissionMode === \"plan\" ? \"read-only\" : \"full\");\n\tenv[SUBAGENT_PARENT_PERMISSION_MODE_ENV] = \"\";\n\tenv[SUBAGENT_FANOUT_CHILD_ENV] = fanoutAuthorized ? \"1\" : \"0\";\n\tif (input.waitToolEnabled !== undefined) {\n\t\tenv[WAIT_TOOL_ENABLED_ENV] = input.waitToolEnabled ? \"true\" : \"false\";\n\t}\n\tconst inheritedNestedRoute = Boolean(process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] && process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] && process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV]);\n\tconst parentRunId = input.parentRunId ?? input.runId ?? (inheritedNestedRoute ? process.env[SUBAGENT_RUN_ID_ENV] : undefined) ?? process.env[SUBAGENT_PARENT_RUN_ID_ENV] ?? \"\";\n\tconst parentChildIndex = input.parentChildIndex !== undefined\n\t\t? String(input.parentChildIndex)\n\t\t: input.childIndex !== undefined\n\t\t\t? String(input.childIndex)\n\t\t\t: process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] ?? \"\";\n\tconst inheritedDepth = Number(process.env[SUBAGENT_PARENT_DEPTH_ENV]);\n\tconst parentDepth = input.parentDepth ?? (inheritedNestedRoute && Number.isFinite(inheritedDepth) ? inheritedDepth + 1 : 1);\n\tconst parentPath = input.parentPath ?? [\n\t\t...parseNestedPathEnv(process.env[SUBAGENT_PARENT_PATH_ENV]),\n\t\t...(parentRunId ? [{\n\t\t\trunId: parentRunId,\n\t\t\t...(parentChildIndex && /^\\d+$/.test(parentChildIndex) ? { stepIndex: Number(parentChildIndex) } : {}),\n\t\t\t...(input.childAgentName ? { agent: input.childAgentName } : {}),\n\t\t}] : []),\n\t];\n\tenv[SUBAGENT_PARENT_EVENT_SINK_ENV] = fanoutAuthorized\n\t\t? input.parentEventSink ?? process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_CONTROL_INBOX_ENV] = fanoutAuthorized\n\t\t? input.parentControlInbox ?? process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] = fanoutAuthorized\n\t\t? input.parentRootRunId ?? process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] ?? input.runId ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_RUN_ID_ENV] = fanoutAuthorized ? parentRunId : \"\";\n\tenv[SUBAGENT_PARENT_CHILD_INDEX_ENV] = fanoutAuthorized ? parentChildIndex : \"\";\n\tenv[SUBAGENT_PARENT_DEPTH_ENV] = fanoutAuthorized ? String(parentDepth) : \"\";\n\tenv[SUBAGENT_PARENT_PATH_ENV] = fanoutAuthorized ? encodeNestedPathEnv(parentPath) : \"\";\n\tenv[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = fanoutAuthorized\n\t\t? input.parentCapabilityToken ?? process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] ?? \"\"\n\t\t: \"\";\n\tenv.PI_SUBAGENT_INHERIT_PROJECT_CONTEXT = input.inheritProjectContext ? \"1\" : \"0\";\n\tenv.PI_SUBAGENT_INHERIT_SKILLS = input.inheritSkills ? \"1\" : \"0\";\n\tif (input.intercomSessionName) {\n\t\tenv.PI_SUBAGENT_INTERCOM_SESSION_NAME = input.intercomSessionName;\n\t}\n\tif (input.orchestratorIntercomTarget) {\n\t\tenv[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = input.orchestratorIntercomTarget;\n\t}\n\tif (input.parentSessionId) {\n\t\tenv[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = input.parentSessionId;\n\t}\n\tenv[SUBAGENT_SUPERVISOR_SESSION_ID_ENV] = input.supervisorSessionId ?? \"\";\n\tenv[SUPERVISOR_PROTOCOL_ENV] = String(SUPERVISOR_PROTOCOL_VERSION);\n\tenv[CHILD_DESCRIPTION_ENV] = input.childDescription ?? input.childAgentName ?? \"\";\n\tif (input.parentSessionId && input.runId && (input.childId || input.childAgentName)) {\n\t\tconst childIndex = input.childIndex ?? 0;\n\t\tconst channelAgent = input.childId ?? input.childAgentName!;\n\t\tconst channelDir = supervisorChannelDir(input.runId, channelAgent, childIndex);\n\t\tfs.mkdirSync(path.join(channelDir, \"requests\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"replies\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"questions\"), { recursive: true });\n\t\tenv[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = channelDir;\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(childIndex);\n\t}\n\tif (input.runId) {\n\t\tenv[SUBAGENT_RUN_ID_ENV] = input.runId;\n\t}\n\tif (input.childId || input.childAgentName) {\n\t\tenv[SUBAGENT_CHILD_AGENT_ENV] = input.childId ?? input.childAgentName;\n\t}\n\tif (input.childIndex !== undefined) {\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(input.childIndex);\n\t}\n\tif (input.mcpDirectTools?.length) {\n\t\tenv.MCP_DIRECT_TOOLS = input.mcpDirectTools.join(\",\");\n\t} else {\n\t\tenv.MCP_DIRECT_TOOLS = \"__none__\";\n\t}\n\tif (input.structuredOutput) {\n\t\tenv[STRUCTURED_OUTPUT_CAPTURE_ENV] = input.structuredOutput.outputPath;\n\t\tenv[STRUCTURED_OUTPUT_SCHEMA_ENV] = input.structuredOutput.schemaPath;\n\t}\n\tif (input.steerInboxDir) {\n\t\tenv[SUBAGENT_STEER_INBOX_ENV] = input.steerInboxDir;\n\t}\n\tif (input.steerCapabilityPath) env[SUBAGENT_STEER_CAPABILITY_ENV] = input.steerCapabilityPath;\n\tif (input.steerAckDir) env[SUBAGENT_STEER_ACK_DIR_ENV] = input.steerAckDir;\n\tconst encodedToolBudget = encodeToolBudgetEnv(input.toolBudget);\n\tif (encodedToolBudget) env[TOOL_BUDGET_ENV] = encodedToolBudget;\n\tconst encodedChildWatchdog = encodeChildWatchdogConfig(input.childWatchdog);\n\tif (encodedChildWatchdog) env[CHILD_WATCHDOG_CONFIG_ENV] = encodedChildWatchdog;\n\n\tenv[SUBAGENT_PARENT_SESSION_ENV] = input.parentSessionId ?? process.env[SUBAGENT_PARENT_SESSION_ENV] ?? \"\";\n\n\treturn { args, env, tempDir, toolDiagnosticPath };\n}\n\nexport const parseParentPathEnv = parseNestedPathEnv;\n\nexport function cleanupTempDir(tempDir: string | null | undefined): void {\n\tif (!tempDir) return;\n\ttry {\n\t\tfs.rmSync(tempDir, { recursive: true, force: true });\n\t} catch {\n\t\t// Temp cleanup is best effort.\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pi-args.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/pi-args.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGjG,OAAO,EAAiB,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAItG,OAAO,EAAwD,KAAK,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAehI,eAAO,MAAM,0BAA0B,sCAAsC,CAAC;AAC9E,eAAO,MAAM,kBAAkB,sBAAsB,CAAC;AACtD,eAAO,MAAM,gCAAgC,oCAAoC,CAAC;AAClF,eAAO,MAAM,oCAAoC,wCAAwC,CAAC;AAC1F,eAAO,MAAM,kCAAkC,sCAAsC,CAAC;AACtF,eAAO,MAAM,mCAAmC,uCAAuC,CAAC;AACxF,eAAO,MAAM,mBAAmB,uBAAuB,CAAC;AACxD,eAAO,MAAM,wBAAwB,4BAA4B,CAAC;AAClE,eAAO,MAAM,wBAAwB,4BAA4B,CAAC;AAClE,eAAO,MAAM,yBAAyB,6BAA6B,CAAC;AACpE,eAAO,MAAM,8BAA8B,kCAAkC,CAAC;AAC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AC1B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAUD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,EAAE,eAAe,UAAQ,GAAG,MAAM,GAAG,SAAS,CAOhJ;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CA8LtE;AAED,eAAO,MAAM,kBAAkB,2BAAqB,CAAC;AAErD,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAOvE","sourcesContent":["// @ts-nocheck\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { subagentCommunicationEnabled } from \"../../../../../core/settings-manager.ts\";\nimport { getAgentDir } from \"../../shared/utils.ts\";\nimport { encodeNestedPathEnv, parseNestedPathEnv, type NestedPathEntry } from \"./nested-path.ts\";\nimport { resolveMcpDirectToolNames } from \"./mcp-direct-tool-allowlist.ts\";\nimport { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV } from \"./structured-output.ts\";\nimport { TEMP_ROOT_DIR, type JsonSchemaObject, type ResolvedToolBudget } from \"../../shared/types.ts\";\nimport { THINKING_LEVELS } from \"../../shared/model-info.ts\";\nimport { TOOL_BUDGET_ENV, encodeToolBudgetEnv } from \"./tool-budget.ts\";\nimport { CHILD_TOOL_DIAGNOSTIC_PATH_ENV, REQUIRED_CHILD_TOOLS_ENV } from \"./tool-availability.ts\";\nimport { CHILD_WATCHDOG_CONFIG_ENV, encodeChildWatchdogConfig, type ChildWatchdogConfig } from \"../../watchdog/child-status.ts\";\nimport { WAIT_TOOL_ENABLED_ENV } from \"../background/wait-config.ts\";\nimport { CHILD_DESCRIPTION_ENV, SUPERVISOR_PROTOCOL_ENV, SUPERVISOR_PROTOCOL_VERSION } from \"../../intercom/communication.ts\";\n\nconst TASK_ARG_LIMIT = 8000;\n// lunr: the bake-in compiles extensions to dist/*.js only; upstream dev mode ships .ts.\n// Resolve the .ts sibling when present, else fall back to the compiled .js so child\n// processes always get a path that exists (the extension loader accepts both).\nfunction resolveRuntimeScriptPath(basePathWithoutExt: string): string {\n\tconst tsPath = `${basePathWithoutExt}.ts`;\n\tif (fs.existsSync(tsPath)) return tsPath;\n\treturn `${basePathWithoutExt}.js`;\n}\nconst PROMPT_RUNTIME_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"subagent-prompt-runtime\"));\nconst FANOUT_CHILD_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"..\", \"..\", \"extension\", \"fanout-child\"));\nexport const SUBAGENT_COMMUNICATION_ENV = \"PI_SUBAGENT_COMMUNICATION_ENABLED\";\nexport const SUBAGENT_CHILD_ENV = \"PI_SUBAGENT_CHILD\";\nexport const SUBAGENT_ORCHESTRATOR_TARGET_ENV = \"PI_SUBAGENT_ORCHESTRATOR_TARGET\";\nexport const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = \"PI_SUBAGENT_ORCHESTRATOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_SESSION_ID_ENV = \"PI_SUBAGENT_SUPERVISOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV = \"PI_SUBAGENT_SUPERVISOR_CHANNEL_DIR\";\nexport const SUBAGENT_RUN_ID_ENV = \"PI_SUBAGENT_RUN_ID\";\nexport const SUBAGENT_CHILD_AGENT_ENV = \"PI_SUBAGENT_CHILD_AGENT\";\nexport const SUBAGENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_CHILD_INDEX\";\nexport const SUBAGENT_FANOUT_CHILD_ENV = \"PI_SUBAGENT_FANOUT_CHILD\";\nexport const SUBAGENT_PARENT_EVENT_SINK_ENV = \"PI_SUBAGENT_PARENT_EVENT_SINK\";\nexport const SUBAGENT_PARENT_CONTROL_INBOX_ENV = \"PI_SUBAGENT_PARENT_CONTROL_INBOX\";\nexport const SUBAGENT_PARENT_ROOT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_ROOT_RUN_ID\";\nexport const SUBAGENT_PARENT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_RUN_ID\";\nexport const SUBAGENT_PARENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_PARENT_CHILD_INDEX\";\nexport const SUBAGENT_PARENT_DEPTH_ENV = \"PI_SUBAGENT_PARENT_DEPTH\";\nexport const SUBAGENT_PARENT_PATH_ENV = \"PI_SUBAGENT_PARENT_PATH\";\nexport const SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV = \"PI_SUBAGENT_PARENT_CAPABILITY_TOKEN\";\nexport const SUBAGENT_PARENT_SESSION_ENV = \"PI_SUBAGENT_PARENT_SESSION\";\nexport const SUBAGENT_PARENT_PERMISSION_MODE_ENV = \"PI_SUBAGENT_PARENT_PERMISSION_MODE\";\nexport const SUBAGENT_CHILD_PERMISSION_ENV = \"PI_SUBAGENT_CHILD_PERMISSION\";\nexport const SUBAGENT_STEER_INBOX_ENV = \"PI_SUBAGENT_STEER_INBOX\";\nexport const SUBAGENT_STEER_CAPABILITY_ENV = \"PI_SUBAGENT_STEER_CAPABILITY\";\nexport const SUBAGENT_STEER_ACK_DIR_ENV = \"PI_SUBAGENT_STEER_ACK_DIR\";\n\ninterface BuildPiArgsInput {\n\tparentSessionId?: string;\n\t/** Run ownership is a session file or in-memory UUID; parentSessionId remains the routing UUID. */\n\tsupervisorSessionId?: string;\n\tbaseArgs: string[];\n\ttask: string;\n\tsessionEnabled: boolean;\n\tsessionDir?: string;\n\tsessionFile?: string;\n\tmodel?: string;\n\tthinking?: string | false;\n\tsystemPromptMode?: \"append\" | \"replace\";\n\tinheritProjectContext: boolean;\n\tinheritSkills: boolean;\n\trequireReadTool?: boolean;\n\ttools?: string[];\n\textensions?: string[];\n\tsubagentOnlyExtensions?: string[];\n\tsystemPrompt?: string | null;\n\tmcpDirectTools?: string[];\n\tcwd?: string;\n\tpromptFileStem?: string;\n\tintercomSessionName?: string;\n\torchestratorIntercomTarget?: string;\n\trunId?: string;\n\tchildAgentName?: string;\n\tchildIndex?: number;\n\tparentEventSink?: string;\n\tparentControlInbox?: string;\n\tparentRootRunId?: string;\n\tparentRunId?: string;\n\tparentChildIndex?: number;\n\tparentDepth?: number;\n\tparentPath?: NestedPathEntry[];\n\tparentCapabilityToken?: string;\n\tsteerInboxDir?: string;\n\tsteerCapabilityPath?: string;\n\tsteerAckDir?: string;\n\tstructuredOutput?: {\n\t\tschema: JsonSchemaObject;\n\t\tschemaPath: string;\n\t\toutputPath: string;\n\t};\n\ttoolBudget?: ResolvedToolBudget;\n\tchildWatchdog?: ChildWatchdogConfig;\n\twaitToolEnabled?: boolean;\n\tparentPermissionMode?: string;\n\tchildPermission?: \"full\" | \"read-only\";\n\texcludeTools?: string[];\n\tchildId?: string;\n\tchildDescription?: string;\n\tcommunicationEnabled?: boolean;\n}\n\ninterface BuildPiArgsResult {\n\targs: string[];\n\tenv: Record<string, string | undefined>;\n\ttempDir?: string;\n\ttoolDiagnosticPath?: string;\n}\n\nfunction sanitizeSupervisorChannelSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nfunction supervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(TEMP_ROOT_DIR, \"supervisor-channels\", `${sanitizeSupervisorChannelSegment(runId)}-${sanitizeSupervisorChannelSegment(agent)}-${childIndex}`);\n}\n\nexport function applyThinkingSuffix(model: string | undefined, thinking: string | false | undefined, replaceExisting = false): string | undefined {\n\tif (!model || !thinking) return model;\n\tconst colonIdx = model.lastIndexOf(\":\");\n\tif (colonIdx !== -1 && THINKING_LEVELS.some((level) => level === model.substring(colonIdx + 1))) {\n\t\treturn replaceExisting ? `${model.slice(0, colonIdx)}:${thinking}` : model;\n\t}\n\treturn `${model}:${thinking}`;\n}\n\nexport function buildPiArgs(input: BuildPiArgsInput): BuildPiArgsResult {\n\tconst communicationEnabled = input.communicationEnabled ?? subagentCommunicationEnabled(input.cwd ?? process.cwd(), getAgentDir());\n\tconst args = [...input.baseArgs];\n\n\tif (input.sessionFile) {\n\t\tfs.mkdirSync(path.dirname(input.sessionFile), { recursive: true });\n\t\targs.push(\"--session\", input.sessionFile);\n\t} else {\n\t\tif (!input.sessionEnabled) {\n\t\t\targs.push(\"--no-session\");\n\t\t}\n\t\tif (input.sessionDir) {\n\t\t\tfs.mkdirSync(input.sessionDir, { recursive: true });\n\t\t\targs.push(\"--session-dir\", input.sessionDir);\n\t\t}\n\t}\n\n\tconst modelArg = applyThinkingSuffix(input.model, input.thinking);\n\tif (modelArg) {\n\t\targs.push(\"--model\", modelArg);\n\t}\n\n\tconst declaredBuiltinToolsBase = input.tools?.filter((tool) =>\n\t\t!(tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))\n\t\t&& (communicationEnabled || (tool !== \"contact_supervisor\" && tool !== \"intercom\"))) ?? [];\n\tconst declaredBuiltinTools = input.requireReadTool && input.tools?.length && !declaredBuiltinToolsBase.includes(\"read\")\n\t\t? [\"read\", ...declaredBuiltinToolsBase]\n\t\t: declaredBuiltinToolsBase;\n\tconst fanoutAuthorized = declaredBuiltinTools.includes(\"subagent\");\n\tconst toolExtensionPaths: string[] = [];\n\tlet requiredChildTools: string[] = [];\n\tif (input.tools?.length) {\n\t\tconst allowedTools = [...declaredBuiltinTools];\n\t\tfor (const tool of input.tools) {\n\t\t\tif (!declaredBuiltinTools.includes(tool) && (tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))) {\n\t\t\t\ttoolExtensionPaths.push(tool);\n\t\t\t}\n\t\t}\n\t\tif (allowedTools.length > 0) {\n\t\t\tif (input.mcpDirectTools?.length) {\n\t\t\t\tallowedTools.push(...resolveMcpDirectToolNames(input.mcpDirectTools, input.cwd));\n\t\t\t}\n\t\t\tif (input.structuredOutput) allowedTools.push(\"structured_output\");\n\t\t\trequiredChildTools = [...new Set(allowedTools)];\n\t\t\targs.push(\"--tools\", requiredChildTools.join(\",\"));\n\t\t}\n\t}\n\tconst excludedTools = [...(input.excludeTools ?? []), ...(communicationEnabled ? [] : [\"contact_supervisor\", \"intercom\"])];\n\tif (excludedTools.length) {\n\t\targs.push(\"--exclude-tools\", [...new Set(excludedTools)].join(\",\"));\n\t}\n\n\tconst runtimeExtensions = fanoutAuthorized\n\t\t? [PROMPT_RUNTIME_EXTENSION_PATH, FANOUT_CHILD_EXTENSION_PATH]\n\t\t: [PROMPT_RUNTIME_EXTENSION_PATH];\n\tif (input.extensions !== undefined) {\n\t\targs.push(\"--no-extensions\");\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...input.extensions, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t} else {\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t}\n\n\tif (!input.inheritSkills) {\n\t\targs.push(\"--no-skills\");\n\t}\n\n\tlet tempDir: string | undefined;\n\tif (input.systemPrompt !== undefined && input.systemPrompt !== null) {\n\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\tconst stem = (input.promptFileStem ?? \"prompt\").replace(/[^\\w.-]/g, \"_\");\n\t\tconst promptPath = path.join(tempDir, `${stem}.md`);\n\t\tfs.writeFileSync(promptPath, input.systemPrompt, { mode: 0o600 });\n\t\targs.push(input.systemPromptMode === \"replace\" ? \"--system-prompt\" : \"--append-system-prompt\", promptPath);\n\t}\n\n\tif (input.task.length > TASK_ARG_LIMIT) {\n\t\tif (!tempDir) {\n\t\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\t}\n\t\tconst taskFilePath = path.join(tempDir, \"task.md\");\n\t\tfs.writeFileSync(taskFilePath, `Task: ${input.task}`, { mode: 0o600 });\n\t\targs.push(`@${taskFilePath}`);\n\t} else {\n\t\targs.push(`Task: ${input.task}`);\n\t}\n\n\tconst env: Record<string, string | undefined> = {};\n\tlet toolDiagnosticPath: string | undefined;\n\tif (requiredChildTools.length > 0) {\n\t\tif (!tempDir) tempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\ttoolDiagnosticPath = path.join(tempDir, \"tool-diagnostic.json\");\n\t\tenv[REQUIRED_CHILD_TOOLS_ENV] = JSON.stringify(requiredChildTools);\n\t\tenv[CHILD_TOOL_DIAGNOSTIC_PATH_ENV] = toolDiagnosticPath;\n\t}\n\tenv[SUBAGENT_CHILD_ENV] = \"1\";\n\tenv[SUBAGENT_COMMUNICATION_ENV] = communicationEnabled ? \"1\" : \"0\";\n\tenv[SUBAGENT_CHILD_PERMISSION_ENV] = input.childPermission\n\t\t?? (input.parentPermissionMode === \"read-only\" ? \"read-only\" : \"full\");\n\tenv[SUBAGENT_PARENT_PERMISSION_MODE_ENV] = \"\";\n\tenv[SUBAGENT_FANOUT_CHILD_ENV] = fanoutAuthorized ? \"1\" : \"0\";\n\tif (input.waitToolEnabled !== undefined) {\n\t\tenv[WAIT_TOOL_ENABLED_ENV] = input.waitToolEnabled ? \"true\" : \"false\";\n\t}\n\tconst inheritedNestedRoute = Boolean(process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] && process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] && process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV]);\n\tconst parentRunId = input.parentRunId ?? input.runId ?? (inheritedNestedRoute ? process.env[SUBAGENT_RUN_ID_ENV] : undefined) ?? process.env[SUBAGENT_PARENT_RUN_ID_ENV] ?? \"\";\n\tconst parentChildIndex = input.parentChildIndex !== undefined\n\t\t? String(input.parentChildIndex)\n\t\t: input.childIndex !== undefined\n\t\t\t? String(input.childIndex)\n\t\t\t: process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] ?? \"\";\n\tconst inheritedDepth = Number(process.env[SUBAGENT_PARENT_DEPTH_ENV]);\n\tconst parentDepth = input.parentDepth ?? (inheritedNestedRoute && Number.isFinite(inheritedDepth) ? inheritedDepth + 1 : 1);\n\tconst parentPath = input.parentPath ?? [\n\t\t...parseNestedPathEnv(process.env[SUBAGENT_PARENT_PATH_ENV]),\n\t\t...(parentRunId ? [{\n\t\t\trunId: parentRunId,\n\t\t\t...(parentChildIndex && /^\\d+$/.test(parentChildIndex) ? { stepIndex: Number(parentChildIndex) } : {}),\n\t\t\t...(input.childAgentName ? { agent: input.childAgentName } : {}),\n\t\t}] : []),\n\t];\n\tenv[SUBAGENT_PARENT_EVENT_SINK_ENV] = fanoutAuthorized\n\t\t? input.parentEventSink ?? process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_CONTROL_INBOX_ENV] = fanoutAuthorized\n\t\t? input.parentControlInbox ?? process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] = fanoutAuthorized\n\t\t? input.parentRootRunId ?? process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] ?? input.runId ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_RUN_ID_ENV] = fanoutAuthorized ? parentRunId : \"\";\n\tenv[SUBAGENT_PARENT_CHILD_INDEX_ENV] = fanoutAuthorized ? parentChildIndex : \"\";\n\tenv[SUBAGENT_PARENT_DEPTH_ENV] = fanoutAuthorized ? String(parentDepth) : \"\";\n\tenv[SUBAGENT_PARENT_PATH_ENV] = fanoutAuthorized ? encodeNestedPathEnv(parentPath) : \"\";\n\tenv[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = fanoutAuthorized\n\t\t? input.parentCapabilityToken ?? process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] ?? \"\"\n\t\t: \"\";\n\tenv.PI_SUBAGENT_INHERIT_PROJECT_CONTEXT = input.inheritProjectContext ? \"1\" : \"0\";\n\tenv.PI_SUBAGENT_INHERIT_SKILLS = input.inheritSkills ? \"1\" : \"0\";\n\tenv.PI_SUBAGENT_INTERCOM_SESSION_NAME = communicationEnabled ? input.intercomSessionName ?? \"\" : \"\";\n\tenv[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = communicationEnabled ? input.orchestratorIntercomTarget ?? \"\" : \"\";\n\tenv[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = communicationEnabled ? input.parentSessionId ?? \"\" : \"\";\n\tenv[SUBAGENT_SUPERVISOR_SESSION_ID_ENV] = communicationEnabled ? input.supervisorSessionId ?? \"\" : \"\";\n\tenv[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = \"\";\n\tenv[SUPERVISOR_PROTOCOL_ENV] = String(SUPERVISOR_PROTOCOL_VERSION);\n\tenv[CHILD_DESCRIPTION_ENV] = input.childDescription ?? input.childAgentName ?? \"\";\n\tif (communicationEnabled && input.parentSessionId && input.runId && (input.childId || input.childAgentName)) {\n\t\tconst childIndex = input.childIndex ?? 0;\n\t\tconst channelAgent = input.childId ?? input.childAgentName!;\n\t\tconst channelDir = supervisorChannelDir(input.runId, channelAgent, childIndex);\n\t\tfs.mkdirSync(path.join(channelDir, \"requests\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"replies\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"questions\"), { recursive: true });\n\t\tenv[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = channelDir;\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(childIndex);\n\t}\n\tif (input.runId) {\n\t\tenv[SUBAGENT_RUN_ID_ENV] = input.runId;\n\t}\n\tif (input.childId || input.childAgentName) {\n\t\tenv[SUBAGENT_CHILD_AGENT_ENV] = input.childId ?? input.childAgentName;\n\t}\n\tif (input.childIndex !== undefined) {\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(input.childIndex);\n\t}\n\tif (input.mcpDirectTools?.length) {\n\t\tenv.MCP_DIRECT_TOOLS = input.mcpDirectTools.join(\",\");\n\t} else {\n\t\tenv.MCP_DIRECT_TOOLS = \"__none__\";\n\t}\n\tif (input.structuredOutput) {\n\t\tenv[STRUCTURED_OUTPUT_CAPTURE_ENV] = input.structuredOutput.outputPath;\n\t\tenv[STRUCTURED_OUTPUT_SCHEMA_ENV] = input.structuredOutput.schemaPath;\n\t}\n\tif (input.steerInboxDir) {\n\t\tenv[SUBAGENT_STEER_INBOX_ENV] = input.steerInboxDir;\n\t}\n\tif (input.steerCapabilityPath) env[SUBAGENT_STEER_CAPABILITY_ENV] = input.steerCapabilityPath;\n\tif (input.steerAckDir) env[SUBAGENT_STEER_ACK_DIR_ENV] = input.steerAckDir;\n\tconst encodedToolBudget = encodeToolBudgetEnv(input.toolBudget);\n\tif (encodedToolBudget) env[TOOL_BUDGET_ENV] = encodedToolBudget;\n\tconst encodedChildWatchdog = encodeChildWatchdogConfig(input.childWatchdog);\n\tif (encodedChildWatchdog) env[CHILD_WATCHDOG_CONFIG_ENV] = encodedChildWatchdog;\n\n\tenv[SUBAGENT_PARENT_SESSION_ENV] = input.parentSessionId ?? process.env[SUBAGENT_PARENT_SESSION_ENV] ?? \"\";\n\n\treturn { args, env, tempDir, toolDiagnosticPath };\n}\n\nexport const parseParentPathEnv = parseNestedPathEnv;\n\nexport function cleanupTempDir(tempDir: string | null | undefined): void {\n\tif (!tempDir) return;\n\ttry {\n\t\tfs.rmSync(tempDir, { recursive: true, force: true });\n\t} catch {\n\t\t// Temp cleanup is best effort.\n\t}\n}\n"]}
|
|
@@ -3,6 +3,8 @@ import * as fs from "node:fs";
|
|
|
3
3
|
import * as os from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { subagentCommunicationEnabled } from "../../../../../core/settings-manager.js";
|
|
7
|
+
import { getAgentDir } from "../../shared/utils.js";
|
|
6
8
|
import { encodeNestedPathEnv, parseNestedPathEnv } from "./nested-path.js";
|
|
7
9
|
import { resolveMcpDirectToolNames } from "./mcp-direct-tool-allowlist.js";
|
|
8
10
|
import { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV } from "./structured-output.js";
|
|
@@ -25,6 +27,7 @@ function resolveRuntimeScriptPath(basePathWithoutExt) {
|
|
|
25
27
|
}
|
|
26
28
|
const PROMPT_RUNTIME_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), "subagent-prompt-runtime"));
|
|
27
29
|
const FANOUT_CHILD_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "extension", "fanout-child"));
|
|
30
|
+
export const SUBAGENT_COMMUNICATION_ENV = "PI_SUBAGENT_COMMUNICATION_ENABLED";
|
|
28
31
|
export const SUBAGENT_CHILD_ENV = "PI_SUBAGENT_CHILD";
|
|
29
32
|
export const SUBAGENT_ORCHESTRATOR_TARGET_ENV = "PI_SUBAGENT_ORCHESTRATOR_TARGET";
|
|
30
33
|
export const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = "PI_SUBAGENT_ORCHESTRATOR_SESSION_ID";
|
|
@@ -64,6 +67,7 @@ export function applyThinkingSuffix(model, thinking, replaceExisting = false) {
|
|
|
64
67
|
return `${model}:${thinking}`;
|
|
65
68
|
}
|
|
66
69
|
export function buildPiArgs(input) {
|
|
70
|
+
const communicationEnabled = input.communicationEnabled ?? subagentCommunicationEnabled(input.cwd ?? process.cwd(), getAgentDir());
|
|
67
71
|
const args = [...input.baseArgs];
|
|
68
72
|
if (input.sessionFile) {
|
|
69
73
|
fs.mkdirSync(path.dirname(input.sessionFile), { recursive: true });
|
|
@@ -82,7 +86,8 @@ export function buildPiArgs(input) {
|
|
|
82
86
|
if (modelArg) {
|
|
83
87
|
args.push("--model", modelArg);
|
|
84
88
|
}
|
|
85
|
-
const declaredBuiltinToolsBase = input.tools?.filter((tool) => !(tool.includes("/") || tool.endsWith(".ts") || tool.endsWith(".js"))
|
|
89
|
+
const declaredBuiltinToolsBase = input.tools?.filter((tool) => !(tool.includes("/") || tool.endsWith(".ts") || tool.endsWith(".js"))
|
|
90
|
+
&& (communicationEnabled || (tool !== "contact_supervisor" && tool !== "intercom"))) ?? [];
|
|
86
91
|
const declaredBuiltinTools = input.requireReadTool && input.tools?.length && !declaredBuiltinToolsBase.includes("read")
|
|
87
92
|
? ["read", ...declaredBuiltinToolsBase]
|
|
88
93
|
: declaredBuiltinToolsBase;
|
|
@@ -106,8 +111,9 @@ export function buildPiArgs(input) {
|
|
|
106
111
|
args.push("--tools", requiredChildTools.join(","));
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
const excludedTools = [...(input.excludeTools ?? []), ...(communicationEnabled ? [] : ["contact_supervisor", "intercom"])];
|
|
115
|
+
if (excludedTools.length) {
|
|
116
|
+
args.push("--exclude-tools", [...new Set(excludedTools)].join(","));
|
|
111
117
|
}
|
|
112
118
|
const runtimeExtensions = fanoutAuthorized
|
|
113
119
|
? [PROMPT_RUNTIME_EXTENSION_PATH, FANOUT_CHILD_EXTENSION_PATH]
|
|
@@ -155,8 +161,9 @@ export function buildPiArgs(input) {
|
|
|
155
161
|
env[CHILD_TOOL_DIAGNOSTIC_PATH_ENV] = toolDiagnosticPath;
|
|
156
162
|
}
|
|
157
163
|
env[SUBAGENT_CHILD_ENV] = "1";
|
|
164
|
+
env[SUBAGENT_COMMUNICATION_ENV] = communicationEnabled ? "1" : "0";
|
|
158
165
|
env[SUBAGENT_CHILD_PERMISSION_ENV] = input.childPermission
|
|
159
|
-
?? (input.parentPermissionMode === "
|
|
166
|
+
?? (input.parentPermissionMode === "read-only" ? "read-only" : "full");
|
|
160
167
|
env[SUBAGENT_PARENT_PERMISSION_MODE_ENV] = "";
|
|
161
168
|
env[SUBAGENT_FANOUT_CHILD_ENV] = fanoutAuthorized ? "1" : "0";
|
|
162
169
|
if (input.waitToolEnabled !== undefined) {
|
|
@@ -197,19 +204,14 @@ export function buildPiArgs(input) {
|
|
|
197
204
|
: "";
|
|
198
205
|
env.PI_SUBAGENT_INHERIT_PROJECT_CONTEXT = input.inheritProjectContext ? "1" : "0";
|
|
199
206
|
env.PI_SUBAGENT_INHERIT_SKILLS = input.inheritSkills ? "1" : "0";
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
if (input.parentSessionId) {
|
|
207
|
-
env[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = input.parentSessionId;
|
|
208
|
-
}
|
|
209
|
-
env[SUBAGENT_SUPERVISOR_SESSION_ID_ENV] = input.supervisorSessionId ?? "";
|
|
207
|
+
env.PI_SUBAGENT_INTERCOM_SESSION_NAME = communicationEnabled ? input.intercomSessionName ?? "" : "";
|
|
208
|
+
env[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = communicationEnabled ? input.orchestratorIntercomTarget ?? "" : "";
|
|
209
|
+
env[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = communicationEnabled ? input.parentSessionId ?? "" : "";
|
|
210
|
+
env[SUBAGENT_SUPERVISOR_SESSION_ID_ENV] = communicationEnabled ? input.supervisorSessionId ?? "" : "";
|
|
211
|
+
env[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = "";
|
|
210
212
|
env[SUPERVISOR_PROTOCOL_ENV] = String(SUPERVISOR_PROTOCOL_VERSION);
|
|
211
213
|
env[CHILD_DESCRIPTION_ENV] = input.childDescription ?? input.childAgentName ?? "";
|
|
212
|
-
if (input.parentSessionId && input.runId && (input.childId || input.childAgentName)) {
|
|
214
|
+
if (communicationEnabled && input.parentSessionId && input.runId && (input.childId || input.childAgentName)) {
|
|
213
215
|
const childIndex = input.childIndex ?? 0;
|
|
214
216
|
const channelAgent = input.childId ?? input.childAgentName;
|
|
215
217
|
const channelDir = supervisorChannelDir(input.runId, channelAgent, childIndex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-args.js","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/pi-args.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAwB,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,aAAa,EAAkD,MAAM,uBAAuB,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,8BAA8B,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAA4B,MAAM,gCAAgC,CAAC;AAChI,OAAO,EAAE,qBAAqB,EAAE,MAAM,8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,CAAC,yBAAyB,CAAC,GAAG,oBAAoB,CAAC;IAEhF,GAAG,CAAC,2BAA2B,CAAC,GAAG,KAAK,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,IAAI,EAAE,CAAC;IAE3G,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAAA,CAClD;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAErD,MAAM,UAAU,cAAc,CAAC,OAAkC,EAAQ;IACxE,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,IAAI,CAAC;QACJ,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACR,+BAA+B;IAChC,CAAC;AAAA,CACD","sourcesContent":["// @ts-nocheck\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { encodeNestedPathEnv, parseNestedPathEnv, type NestedPathEntry } from \"./nested-path.ts\";\nimport { resolveMcpDirectToolNames } from \"./mcp-direct-tool-allowlist.ts\";\nimport { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV } from \"./structured-output.ts\";\nimport { TEMP_ROOT_DIR, type JsonSchemaObject, type ResolvedToolBudget } from \"../../shared/types.ts\";\nimport { THINKING_LEVELS } from \"../../shared/model-info.ts\";\nimport { TOOL_BUDGET_ENV, encodeToolBudgetEnv } from \"./tool-budget.ts\";\nimport { CHILD_TOOL_DIAGNOSTIC_PATH_ENV, REQUIRED_CHILD_TOOLS_ENV } from \"./tool-availability.ts\";\nimport { CHILD_WATCHDOG_CONFIG_ENV, encodeChildWatchdogConfig, type ChildWatchdogConfig } from \"../../watchdog/child-status.ts\";\nimport { WAIT_TOOL_ENABLED_ENV } from \"../background/wait-config.ts\";\nimport { CHILD_DESCRIPTION_ENV, SUPERVISOR_PROTOCOL_ENV, SUPERVISOR_PROTOCOL_VERSION } from \"../../intercom/communication.ts\";\n\nconst TASK_ARG_LIMIT = 8000;\n// lunr: the bake-in compiles extensions to dist/*.js only; upstream dev mode ships .ts.\n// Resolve the .ts sibling when present, else fall back to the compiled .js so child\n// processes always get a path that exists (the extension loader accepts both).\nfunction resolveRuntimeScriptPath(basePathWithoutExt: string): string {\n\tconst tsPath = `${basePathWithoutExt}.ts`;\n\tif (fs.existsSync(tsPath)) return tsPath;\n\treturn `${basePathWithoutExt}.js`;\n}\nconst PROMPT_RUNTIME_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"subagent-prompt-runtime\"));\nconst FANOUT_CHILD_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"..\", \"..\", \"extension\", \"fanout-child\"));\nexport const SUBAGENT_CHILD_ENV = \"PI_SUBAGENT_CHILD\";\nexport const SUBAGENT_ORCHESTRATOR_TARGET_ENV = \"PI_SUBAGENT_ORCHESTRATOR_TARGET\";\nexport const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = \"PI_SUBAGENT_ORCHESTRATOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_SESSION_ID_ENV = \"PI_SUBAGENT_SUPERVISOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV = \"PI_SUBAGENT_SUPERVISOR_CHANNEL_DIR\";\nexport const SUBAGENT_RUN_ID_ENV = \"PI_SUBAGENT_RUN_ID\";\nexport const SUBAGENT_CHILD_AGENT_ENV = \"PI_SUBAGENT_CHILD_AGENT\";\nexport const SUBAGENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_CHILD_INDEX\";\nexport const SUBAGENT_FANOUT_CHILD_ENV = \"PI_SUBAGENT_FANOUT_CHILD\";\nexport const SUBAGENT_PARENT_EVENT_SINK_ENV = \"PI_SUBAGENT_PARENT_EVENT_SINK\";\nexport const SUBAGENT_PARENT_CONTROL_INBOX_ENV = \"PI_SUBAGENT_PARENT_CONTROL_INBOX\";\nexport const SUBAGENT_PARENT_ROOT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_ROOT_RUN_ID\";\nexport const SUBAGENT_PARENT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_RUN_ID\";\nexport const SUBAGENT_PARENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_PARENT_CHILD_INDEX\";\nexport const SUBAGENT_PARENT_DEPTH_ENV = \"PI_SUBAGENT_PARENT_DEPTH\";\nexport const SUBAGENT_PARENT_PATH_ENV = \"PI_SUBAGENT_PARENT_PATH\";\nexport const SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV = \"PI_SUBAGENT_PARENT_CAPABILITY_TOKEN\";\nexport const SUBAGENT_PARENT_SESSION_ENV = \"PI_SUBAGENT_PARENT_SESSION\";\nexport const SUBAGENT_PARENT_PERMISSION_MODE_ENV = \"PI_SUBAGENT_PARENT_PERMISSION_MODE\";\nexport const SUBAGENT_CHILD_PERMISSION_ENV = \"PI_SUBAGENT_CHILD_PERMISSION\";\nexport const SUBAGENT_STEER_INBOX_ENV = \"PI_SUBAGENT_STEER_INBOX\";\nexport const SUBAGENT_STEER_CAPABILITY_ENV = \"PI_SUBAGENT_STEER_CAPABILITY\";\nexport const SUBAGENT_STEER_ACK_DIR_ENV = \"PI_SUBAGENT_STEER_ACK_DIR\";\n\ninterface BuildPiArgsInput {\n\tparentSessionId?: string;\n\t/** Run ownership is a session file or in-memory UUID; parentSessionId remains the routing UUID. */\n\tsupervisorSessionId?: string;\n\tbaseArgs: string[];\n\ttask: string;\n\tsessionEnabled: boolean;\n\tsessionDir?: string;\n\tsessionFile?: string;\n\tmodel?: string;\n\tthinking?: string | false;\n\tsystemPromptMode?: \"append\" | \"replace\";\n\tinheritProjectContext: boolean;\n\tinheritSkills: boolean;\n\trequireReadTool?: boolean;\n\ttools?: string[];\n\textensions?: string[];\n\tsubagentOnlyExtensions?: string[];\n\tsystemPrompt?: string | null;\n\tmcpDirectTools?: string[];\n\tcwd?: string;\n\tpromptFileStem?: string;\n\tintercomSessionName?: string;\n\torchestratorIntercomTarget?: string;\n\trunId?: string;\n\tchildAgentName?: string;\n\tchildIndex?: number;\n\tparentEventSink?: string;\n\tparentControlInbox?: string;\n\tparentRootRunId?: string;\n\tparentRunId?: string;\n\tparentChildIndex?: number;\n\tparentDepth?: number;\n\tparentPath?: NestedPathEntry[];\n\tparentCapabilityToken?: string;\n\tsteerInboxDir?: string;\n\tsteerCapabilityPath?: string;\n\tsteerAckDir?: string;\n\tstructuredOutput?: {\n\t\tschema: JsonSchemaObject;\n\t\tschemaPath: string;\n\t\toutputPath: string;\n\t};\n\ttoolBudget?: ResolvedToolBudget;\n\tchildWatchdog?: ChildWatchdogConfig;\n\twaitToolEnabled?: boolean;\n\tparentPermissionMode?: string;\n\tchildPermission?: \"full\" | \"read-only\";\n\texcludeTools?: string[];\n\tchildId?: string;\n\tchildDescription?: string;\n}\n\ninterface BuildPiArgsResult {\n\targs: string[];\n\tenv: Record<string, string | undefined>;\n\ttempDir?: string;\n\ttoolDiagnosticPath?: string;\n}\n\nfunction sanitizeSupervisorChannelSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nfunction supervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(TEMP_ROOT_DIR, \"supervisor-channels\", `${sanitizeSupervisorChannelSegment(runId)}-${sanitizeSupervisorChannelSegment(agent)}-${childIndex}`);\n}\n\nexport function applyThinkingSuffix(model: string | undefined, thinking: string | false | undefined, replaceExisting = false): string | undefined {\n\tif (!model || !thinking) return model;\n\tconst colonIdx = model.lastIndexOf(\":\");\n\tif (colonIdx !== -1 && THINKING_LEVELS.some((level) => level === model.substring(colonIdx + 1))) {\n\t\treturn replaceExisting ? `${model.slice(0, colonIdx)}:${thinking}` : model;\n\t}\n\treturn `${model}:${thinking}`;\n}\n\nexport function buildPiArgs(input: BuildPiArgsInput): BuildPiArgsResult {\n\tconst args = [...input.baseArgs];\n\n\tif (input.sessionFile) {\n\t\tfs.mkdirSync(path.dirname(input.sessionFile), { recursive: true });\n\t\targs.push(\"--session\", input.sessionFile);\n\t} else {\n\t\tif (!input.sessionEnabled) {\n\t\t\targs.push(\"--no-session\");\n\t\t}\n\t\tif (input.sessionDir) {\n\t\t\tfs.mkdirSync(input.sessionDir, { recursive: true });\n\t\t\targs.push(\"--session-dir\", input.sessionDir);\n\t\t}\n\t}\n\n\tconst modelArg = applyThinkingSuffix(input.model, input.thinking);\n\tif (modelArg) {\n\t\targs.push(\"--model\", modelArg);\n\t}\n\n\tconst declaredBuiltinToolsBase = input.tools?.filter((tool) => !(tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))) ?? [];\n\tconst declaredBuiltinTools = input.requireReadTool && input.tools?.length && !declaredBuiltinToolsBase.includes(\"read\")\n\t\t? [\"read\", ...declaredBuiltinToolsBase]\n\t\t: declaredBuiltinToolsBase;\n\tconst fanoutAuthorized = declaredBuiltinTools.includes(\"subagent\");\n\tconst toolExtensionPaths: string[] = [];\n\tlet requiredChildTools: string[] = [];\n\tif (input.tools?.length) {\n\t\tconst allowedTools = [...declaredBuiltinTools];\n\t\tfor (const tool of input.tools) {\n\t\t\tif (!declaredBuiltinTools.includes(tool) && (tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))) {\n\t\t\t\ttoolExtensionPaths.push(tool);\n\t\t\t}\n\t\t}\n\t\tif (allowedTools.length > 0) {\n\t\t\tif (input.mcpDirectTools?.length) {\n\t\t\t\tallowedTools.push(...resolveMcpDirectToolNames(input.mcpDirectTools, input.cwd));\n\t\t\t}\n\t\t\tif (input.structuredOutput) allowedTools.push(\"structured_output\");\n\t\t\trequiredChildTools = [...new Set(allowedTools)];\n\t\t\targs.push(\"--tools\", requiredChildTools.join(\",\"));\n\t\t}\n\t}\n\tif (input.excludeTools?.length) {\n\t\targs.push(\"--exclude-tools\", [...new Set(input.excludeTools)].join(\",\"));\n\t}\n\n\tconst runtimeExtensions = fanoutAuthorized\n\t\t? [PROMPT_RUNTIME_EXTENSION_PATH, FANOUT_CHILD_EXTENSION_PATH]\n\t\t: [PROMPT_RUNTIME_EXTENSION_PATH];\n\tif (input.extensions !== undefined) {\n\t\targs.push(\"--no-extensions\");\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...input.extensions, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t} else {\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t}\n\n\tif (!input.inheritSkills) {\n\t\targs.push(\"--no-skills\");\n\t}\n\n\tlet tempDir: string | undefined;\n\tif (input.systemPrompt !== undefined && input.systemPrompt !== null) {\n\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\tconst stem = (input.promptFileStem ?? \"prompt\").replace(/[^\\w.-]/g, \"_\");\n\t\tconst promptPath = path.join(tempDir, `${stem}.md`);\n\t\tfs.writeFileSync(promptPath, input.systemPrompt, { mode: 0o600 });\n\t\targs.push(input.systemPromptMode === \"replace\" ? \"--system-prompt\" : \"--append-system-prompt\", promptPath);\n\t}\n\n\tif (input.task.length > TASK_ARG_LIMIT) {\n\t\tif (!tempDir) {\n\t\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\t}\n\t\tconst taskFilePath = path.join(tempDir, \"task.md\");\n\t\tfs.writeFileSync(taskFilePath, `Task: ${input.task}`, { mode: 0o600 });\n\t\targs.push(`@${taskFilePath}`);\n\t} else {\n\t\targs.push(`Task: ${input.task}`);\n\t}\n\n\tconst env: Record<string, string | undefined> = {};\n\tlet toolDiagnosticPath: string | undefined;\n\tif (requiredChildTools.length > 0) {\n\t\tif (!tempDir) tempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\ttoolDiagnosticPath = path.join(tempDir, \"tool-diagnostic.json\");\n\t\tenv[REQUIRED_CHILD_TOOLS_ENV] = JSON.stringify(requiredChildTools);\n\t\tenv[CHILD_TOOL_DIAGNOSTIC_PATH_ENV] = toolDiagnosticPath;\n\t}\n\tenv[SUBAGENT_CHILD_ENV] = \"1\";\n\tenv[SUBAGENT_CHILD_PERMISSION_ENV] = input.childPermission\n\t\t?? (input.parentPermissionMode === \"plan\" ? \"read-only\" : \"full\");\n\tenv[SUBAGENT_PARENT_PERMISSION_MODE_ENV] = \"\";\n\tenv[SUBAGENT_FANOUT_CHILD_ENV] = fanoutAuthorized ? \"1\" : \"0\";\n\tif (input.waitToolEnabled !== undefined) {\n\t\tenv[WAIT_TOOL_ENABLED_ENV] = input.waitToolEnabled ? \"true\" : \"false\";\n\t}\n\tconst inheritedNestedRoute = Boolean(process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] && process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] && process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV]);\n\tconst parentRunId = input.parentRunId ?? input.runId ?? (inheritedNestedRoute ? process.env[SUBAGENT_RUN_ID_ENV] : undefined) ?? process.env[SUBAGENT_PARENT_RUN_ID_ENV] ?? \"\";\n\tconst parentChildIndex = input.parentChildIndex !== undefined\n\t\t? String(input.parentChildIndex)\n\t\t: input.childIndex !== undefined\n\t\t\t? String(input.childIndex)\n\t\t\t: process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] ?? \"\";\n\tconst inheritedDepth = Number(process.env[SUBAGENT_PARENT_DEPTH_ENV]);\n\tconst parentDepth = input.parentDepth ?? (inheritedNestedRoute && Number.isFinite(inheritedDepth) ? inheritedDepth + 1 : 1);\n\tconst parentPath = input.parentPath ?? [\n\t\t...parseNestedPathEnv(process.env[SUBAGENT_PARENT_PATH_ENV]),\n\t\t...(parentRunId ? [{\n\t\t\trunId: parentRunId,\n\t\t\t...(parentChildIndex && /^\\d+$/.test(parentChildIndex) ? { stepIndex: Number(parentChildIndex) } : {}),\n\t\t\t...(input.childAgentName ? { agent: input.childAgentName } : {}),\n\t\t}] : []),\n\t];\n\tenv[SUBAGENT_PARENT_EVENT_SINK_ENV] = fanoutAuthorized\n\t\t? input.parentEventSink ?? process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_CONTROL_INBOX_ENV] = fanoutAuthorized\n\t\t? input.parentControlInbox ?? process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] = fanoutAuthorized\n\t\t? input.parentRootRunId ?? process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] ?? input.runId ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_RUN_ID_ENV] = fanoutAuthorized ? parentRunId : \"\";\n\tenv[SUBAGENT_PARENT_CHILD_INDEX_ENV] = fanoutAuthorized ? parentChildIndex : \"\";\n\tenv[SUBAGENT_PARENT_DEPTH_ENV] = fanoutAuthorized ? String(parentDepth) : \"\";\n\tenv[SUBAGENT_PARENT_PATH_ENV] = fanoutAuthorized ? encodeNestedPathEnv(parentPath) : \"\";\n\tenv[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = fanoutAuthorized\n\t\t? input.parentCapabilityToken ?? process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] ?? \"\"\n\t\t: \"\";\n\tenv.PI_SUBAGENT_INHERIT_PROJECT_CONTEXT = input.inheritProjectContext ? \"1\" : \"0\";\n\tenv.PI_SUBAGENT_INHERIT_SKILLS = input.inheritSkills ? \"1\" : \"0\";\n\tif (input.intercomSessionName) {\n\t\tenv.PI_SUBAGENT_INTERCOM_SESSION_NAME = input.intercomSessionName;\n\t}\n\tif (input.orchestratorIntercomTarget) {\n\t\tenv[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = input.orchestratorIntercomTarget;\n\t}\n\tif (input.parentSessionId) {\n\t\tenv[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = input.parentSessionId;\n\t}\n\tenv[SUBAGENT_SUPERVISOR_SESSION_ID_ENV] = input.supervisorSessionId ?? \"\";\n\tenv[SUPERVISOR_PROTOCOL_ENV] = String(SUPERVISOR_PROTOCOL_VERSION);\n\tenv[CHILD_DESCRIPTION_ENV] = input.childDescription ?? input.childAgentName ?? \"\";\n\tif (input.parentSessionId && input.runId && (input.childId || input.childAgentName)) {\n\t\tconst childIndex = input.childIndex ?? 0;\n\t\tconst channelAgent = input.childId ?? input.childAgentName!;\n\t\tconst channelDir = supervisorChannelDir(input.runId, channelAgent, childIndex);\n\t\tfs.mkdirSync(path.join(channelDir, \"requests\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"replies\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"questions\"), { recursive: true });\n\t\tenv[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = channelDir;\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(childIndex);\n\t}\n\tif (input.runId) {\n\t\tenv[SUBAGENT_RUN_ID_ENV] = input.runId;\n\t}\n\tif (input.childId || input.childAgentName) {\n\t\tenv[SUBAGENT_CHILD_AGENT_ENV] = input.childId ?? input.childAgentName;\n\t}\n\tif (input.childIndex !== undefined) {\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(input.childIndex);\n\t}\n\tif (input.mcpDirectTools?.length) {\n\t\tenv.MCP_DIRECT_TOOLS = input.mcpDirectTools.join(\",\");\n\t} else {\n\t\tenv.MCP_DIRECT_TOOLS = \"__none__\";\n\t}\n\tif (input.structuredOutput) {\n\t\tenv[STRUCTURED_OUTPUT_CAPTURE_ENV] = input.structuredOutput.outputPath;\n\t\tenv[STRUCTURED_OUTPUT_SCHEMA_ENV] = input.structuredOutput.schemaPath;\n\t}\n\tif (input.steerInboxDir) {\n\t\tenv[SUBAGENT_STEER_INBOX_ENV] = input.steerInboxDir;\n\t}\n\tif (input.steerCapabilityPath) env[SUBAGENT_STEER_CAPABILITY_ENV] = input.steerCapabilityPath;\n\tif (input.steerAckDir) env[SUBAGENT_STEER_ACK_DIR_ENV] = input.steerAckDir;\n\tconst encodedToolBudget = encodeToolBudgetEnv(input.toolBudget);\n\tif (encodedToolBudget) env[TOOL_BUDGET_ENV] = encodedToolBudget;\n\tconst encodedChildWatchdog = encodeChildWatchdogConfig(input.childWatchdog);\n\tif (encodedChildWatchdog) env[CHILD_WATCHDOG_CONFIG_ENV] = encodedChildWatchdog;\n\n\tenv[SUBAGENT_PARENT_SESSION_ENV] = input.parentSessionId ?? process.env[SUBAGENT_PARENT_SESSION_ENV] ?? \"\";\n\n\treturn { args, env, tempDir, toolDiagnosticPath };\n}\n\nexport const parseParentPathEnv = parseNestedPathEnv;\n\nexport function cleanupTempDir(tempDir: string | null | undefined): void {\n\tif (!tempDir) return;\n\ttry {\n\t\tfs.rmSync(tempDir, { recursive: true, force: true });\n\t} catch {\n\t\t// Temp cleanup is best effort.\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pi-args.js","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/pi-args.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AACvF,O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AAa,CAAC,CAAC;IAC5E,IAAI,oBAAoB;QAAE,GAAG,CAAC,yBAAyB,CAAC,GAAG,oBAAoB,CAAC;IAEhF,GAAG,CAAC,2BAA2B,CAAC,GAAG,KAAK,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,IAAI,EAAE,CAAC;IAE3G,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAAA,CAClD;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAErD,MAAM,UAAU,cAAc,CAAC,OAAkC,EAAQ;IACxE,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,IAAI,CAAC;QACJ,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACR,+BAA+B;IAChC,CAAC;AAAA,CACD","sourcesContent":["// @ts-nocheck\nimport * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { subagentCommunicationEnabled } from \"../../../../../core/settings-manager.ts\";\nimport { getAgentDir } from \"../../shared/utils.ts\";\nimport { encodeNestedPathEnv, parseNestedPathEnv, type NestedPathEntry } from \"./nested-path.ts\";\nimport { resolveMcpDirectToolNames } from \"./mcp-direct-tool-allowlist.ts\";\nimport { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV } from \"./structured-output.ts\";\nimport { TEMP_ROOT_DIR, type JsonSchemaObject, type ResolvedToolBudget } from \"../../shared/types.ts\";\nimport { THINKING_LEVELS } from \"../../shared/model-info.ts\";\nimport { TOOL_BUDGET_ENV, encodeToolBudgetEnv } from \"./tool-budget.ts\";\nimport { CHILD_TOOL_DIAGNOSTIC_PATH_ENV, REQUIRED_CHILD_TOOLS_ENV } from \"./tool-availability.ts\";\nimport { CHILD_WATCHDOG_CONFIG_ENV, encodeChildWatchdogConfig, type ChildWatchdogConfig } from \"../../watchdog/child-status.ts\";\nimport { WAIT_TOOL_ENABLED_ENV } from \"../background/wait-config.ts\";\nimport { CHILD_DESCRIPTION_ENV, SUPERVISOR_PROTOCOL_ENV, SUPERVISOR_PROTOCOL_VERSION } from \"../../intercom/communication.ts\";\n\nconst TASK_ARG_LIMIT = 8000;\n// lunr: the bake-in compiles extensions to dist/*.js only; upstream dev mode ships .ts.\n// Resolve the .ts sibling when present, else fall back to the compiled .js so child\n// processes always get a path that exists (the extension loader accepts both).\nfunction resolveRuntimeScriptPath(basePathWithoutExt: string): string {\n\tconst tsPath = `${basePathWithoutExt}.ts`;\n\tif (fs.existsSync(tsPath)) return tsPath;\n\treturn `${basePathWithoutExt}.js`;\n}\nconst PROMPT_RUNTIME_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"subagent-prompt-runtime\"));\nconst FANOUT_CHILD_EXTENSION_PATH = resolveRuntimeScriptPath(path.join(path.dirname(fileURLToPath(import.meta.url)), \"..\", \"..\", \"extension\", \"fanout-child\"));\nexport const SUBAGENT_COMMUNICATION_ENV = \"PI_SUBAGENT_COMMUNICATION_ENABLED\";\nexport const SUBAGENT_CHILD_ENV = \"PI_SUBAGENT_CHILD\";\nexport const SUBAGENT_ORCHESTRATOR_TARGET_ENV = \"PI_SUBAGENT_ORCHESTRATOR_TARGET\";\nexport const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = \"PI_SUBAGENT_ORCHESTRATOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_SESSION_ID_ENV = \"PI_SUBAGENT_SUPERVISOR_SESSION_ID\";\nexport const SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV = \"PI_SUBAGENT_SUPERVISOR_CHANNEL_DIR\";\nexport const SUBAGENT_RUN_ID_ENV = \"PI_SUBAGENT_RUN_ID\";\nexport const SUBAGENT_CHILD_AGENT_ENV = \"PI_SUBAGENT_CHILD_AGENT\";\nexport const SUBAGENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_CHILD_INDEX\";\nexport const SUBAGENT_FANOUT_CHILD_ENV = \"PI_SUBAGENT_FANOUT_CHILD\";\nexport const SUBAGENT_PARENT_EVENT_SINK_ENV = \"PI_SUBAGENT_PARENT_EVENT_SINK\";\nexport const SUBAGENT_PARENT_CONTROL_INBOX_ENV = \"PI_SUBAGENT_PARENT_CONTROL_INBOX\";\nexport const SUBAGENT_PARENT_ROOT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_ROOT_RUN_ID\";\nexport const SUBAGENT_PARENT_RUN_ID_ENV = \"PI_SUBAGENT_PARENT_RUN_ID\";\nexport const SUBAGENT_PARENT_CHILD_INDEX_ENV = \"PI_SUBAGENT_PARENT_CHILD_INDEX\";\nexport const SUBAGENT_PARENT_DEPTH_ENV = \"PI_SUBAGENT_PARENT_DEPTH\";\nexport const SUBAGENT_PARENT_PATH_ENV = \"PI_SUBAGENT_PARENT_PATH\";\nexport const SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV = \"PI_SUBAGENT_PARENT_CAPABILITY_TOKEN\";\nexport const SUBAGENT_PARENT_SESSION_ENV = \"PI_SUBAGENT_PARENT_SESSION\";\nexport const SUBAGENT_PARENT_PERMISSION_MODE_ENV = \"PI_SUBAGENT_PARENT_PERMISSION_MODE\";\nexport const SUBAGENT_CHILD_PERMISSION_ENV = \"PI_SUBAGENT_CHILD_PERMISSION\";\nexport const SUBAGENT_STEER_INBOX_ENV = \"PI_SUBAGENT_STEER_INBOX\";\nexport const SUBAGENT_STEER_CAPABILITY_ENV = \"PI_SUBAGENT_STEER_CAPABILITY\";\nexport const SUBAGENT_STEER_ACK_DIR_ENV = \"PI_SUBAGENT_STEER_ACK_DIR\";\n\ninterface BuildPiArgsInput {\n\tparentSessionId?: string;\n\t/** Run ownership is a session file or in-memory UUID; parentSessionId remains the routing UUID. */\n\tsupervisorSessionId?: string;\n\tbaseArgs: string[];\n\ttask: string;\n\tsessionEnabled: boolean;\n\tsessionDir?: string;\n\tsessionFile?: string;\n\tmodel?: string;\n\tthinking?: string | false;\n\tsystemPromptMode?: \"append\" | \"replace\";\n\tinheritProjectContext: boolean;\n\tinheritSkills: boolean;\n\trequireReadTool?: boolean;\n\ttools?: string[];\n\textensions?: string[];\n\tsubagentOnlyExtensions?: string[];\n\tsystemPrompt?: string | null;\n\tmcpDirectTools?: string[];\n\tcwd?: string;\n\tpromptFileStem?: string;\n\tintercomSessionName?: string;\n\torchestratorIntercomTarget?: string;\n\trunId?: string;\n\tchildAgentName?: string;\n\tchildIndex?: number;\n\tparentEventSink?: string;\n\tparentControlInbox?: string;\n\tparentRootRunId?: string;\n\tparentRunId?: string;\n\tparentChildIndex?: number;\n\tparentDepth?: number;\n\tparentPath?: NestedPathEntry[];\n\tparentCapabilityToken?: string;\n\tsteerInboxDir?: string;\n\tsteerCapabilityPath?: string;\n\tsteerAckDir?: string;\n\tstructuredOutput?: {\n\t\tschema: JsonSchemaObject;\n\t\tschemaPath: string;\n\t\toutputPath: string;\n\t};\n\ttoolBudget?: ResolvedToolBudget;\n\tchildWatchdog?: ChildWatchdogConfig;\n\twaitToolEnabled?: boolean;\n\tparentPermissionMode?: string;\n\tchildPermission?: \"full\" | \"read-only\";\n\texcludeTools?: string[];\n\tchildId?: string;\n\tchildDescription?: string;\n\tcommunicationEnabled?: boolean;\n}\n\ninterface BuildPiArgsResult {\n\targs: string[];\n\tenv: Record<string, string | undefined>;\n\ttempDir?: string;\n\ttoolDiagnosticPath?: string;\n}\n\nfunction sanitizeSupervisorChannelSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nfunction supervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(TEMP_ROOT_DIR, \"supervisor-channels\", `${sanitizeSupervisorChannelSegment(runId)}-${sanitizeSupervisorChannelSegment(agent)}-${childIndex}`);\n}\n\nexport function applyThinkingSuffix(model: string | undefined, thinking: string | false | undefined, replaceExisting = false): string | undefined {\n\tif (!model || !thinking) return model;\n\tconst colonIdx = model.lastIndexOf(\":\");\n\tif (colonIdx !== -1 && THINKING_LEVELS.some((level) => level === model.substring(colonIdx + 1))) {\n\t\treturn replaceExisting ? `${model.slice(0, colonIdx)}:${thinking}` : model;\n\t}\n\treturn `${model}:${thinking}`;\n}\n\nexport function buildPiArgs(input: BuildPiArgsInput): BuildPiArgsResult {\n\tconst communicationEnabled = input.communicationEnabled ?? subagentCommunicationEnabled(input.cwd ?? process.cwd(), getAgentDir());\n\tconst args = [...input.baseArgs];\n\n\tif (input.sessionFile) {\n\t\tfs.mkdirSync(path.dirname(input.sessionFile), { recursive: true });\n\t\targs.push(\"--session\", input.sessionFile);\n\t} else {\n\t\tif (!input.sessionEnabled) {\n\t\t\targs.push(\"--no-session\");\n\t\t}\n\t\tif (input.sessionDir) {\n\t\t\tfs.mkdirSync(input.sessionDir, { recursive: true });\n\t\t\targs.push(\"--session-dir\", input.sessionDir);\n\t\t}\n\t}\n\n\tconst modelArg = applyThinkingSuffix(input.model, input.thinking);\n\tif (modelArg) {\n\t\targs.push(\"--model\", modelArg);\n\t}\n\n\tconst declaredBuiltinToolsBase = input.tools?.filter((tool) =>\n\t\t!(tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))\n\t\t&& (communicationEnabled || (tool !== \"contact_supervisor\" && tool !== \"intercom\"))) ?? [];\n\tconst declaredBuiltinTools = input.requireReadTool && input.tools?.length && !declaredBuiltinToolsBase.includes(\"read\")\n\t\t? [\"read\", ...declaredBuiltinToolsBase]\n\t\t: declaredBuiltinToolsBase;\n\tconst fanoutAuthorized = declaredBuiltinTools.includes(\"subagent\");\n\tconst toolExtensionPaths: string[] = [];\n\tlet requiredChildTools: string[] = [];\n\tif (input.tools?.length) {\n\t\tconst allowedTools = [...declaredBuiltinTools];\n\t\tfor (const tool of input.tools) {\n\t\t\tif (!declaredBuiltinTools.includes(tool) && (tool.includes(\"/\") || tool.endsWith(\".ts\") || tool.endsWith(\".js\"))) {\n\t\t\t\ttoolExtensionPaths.push(tool);\n\t\t\t}\n\t\t}\n\t\tif (allowedTools.length > 0) {\n\t\t\tif (input.mcpDirectTools?.length) {\n\t\t\t\tallowedTools.push(...resolveMcpDirectToolNames(input.mcpDirectTools, input.cwd));\n\t\t\t}\n\t\t\tif (input.structuredOutput) allowedTools.push(\"structured_output\");\n\t\t\trequiredChildTools = [...new Set(allowedTools)];\n\t\t\targs.push(\"--tools\", requiredChildTools.join(\",\"));\n\t\t}\n\t}\n\tconst excludedTools = [...(input.excludeTools ?? []), ...(communicationEnabled ? [] : [\"contact_supervisor\", \"intercom\"])];\n\tif (excludedTools.length) {\n\t\targs.push(\"--exclude-tools\", [...new Set(excludedTools)].join(\",\"));\n\t}\n\n\tconst runtimeExtensions = fanoutAuthorized\n\t\t? [PROMPT_RUNTIME_EXTENSION_PATH, FANOUT_CHILD_EXTENSION_PATH]\n\t\t: [PROMPT_RUNTIME_EXTENSION_PATH];\n\tif (input.extensions !== undefined) {\n\t\targs.push(\"--no-extensions\");\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...input.extensions, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t} else {\n\t\tfor (const extPath of [...new Set([...runtimeExtensions, ...toolExtensionPaths, ...(input.subagentOnlyExtensions ?? [])])]) {\n\t\t\targs.push(\"--extension\", extPath);\n\t\t}\n\t}\n\n\tif (!input.inheritSkills) {\n\t\targs.push(\"--no-skills\");\n\t}\n\n\tlet tempDir: string | undefined;\n\tif (input.systemPrompt !== undefined && input.systemPrompt !== null) {\n\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\tconst stem = (input.promptFileStem ?? \"prompt\").replace(/[^\\w.-]/g, \"_\");\n\t\tconst promptPath = path.join(tempDir, `${stem}.md`);\n\t\tfs.writeFileSync(promptPath, input.systemPrompt, { mode: 0o600 });\n\t\targs.push(input.systemPromptMode === \"replace\" ? \"--system-prompt\" : \"--append-system-prompt\", promptPath);\n\t}\n\n\tif (input.task.length > TASK_ARG_LIMIT) {\n\t\tif (!tempDir) {\n\t\t\ttempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\t}\n\t\tconst taskFilePath = path.join(tempDir, \"task.md\");\n\t\tfs.writeFileSync(taskFilePath, `Task: ${input.task}`, { mode: 0o600 });\n\t\targs.push(`@${taskFilePath}`);\n\t} else {\n\t\targs.push(`Task: ${input.task}`);\n\t}\n\n\tconst env: Record<string, string | undefined> = {};\n\tlet toolDiagnosticPath: string | undefined;\n\tif (requiredChildTools.length > 0) {\n\t\tif (!tempDir) tempDir = fs.mkdtempSync(path.join(os.tmpdir(), \"pi-subagent-\"));\n\t\ttoolDiagnosticPath = path.join(tempDir, \"tool-diagnostic.json\");\n\t\tenv[REQUIRED_CHILD_TOOLS_ENV] = JSON.stringify(requiredChildTools);\n\t\tenv[CHILD_TOOL_DIAGNOSTIC_PATH_ENV] = toolDiagnosticPath;\n\t}\n\tenv[SUBAGENT_CHILD_ENV] = \"1\";\n\tenv[SUBAGENT_COMMUNICATION_ENV] = communicationEnabled ? \"1\" : \"0\";\n\tenv[SUBAGENT_CHILD_PERMISSION_ENV] = input.childPermission\n\t\t?? (input.parentPermissionMode === \"read-only\" ? \"read-only\" : \"full\");\n\tenv[SUBAGENT_PARENT_PERMISSION_MODE_ENV] = \"\";\n\tenv[SUBAGENT_FANOUT_CHILD_ENV] = fanoutAuthorized ? \"1\" : \"0\";\n\tif (input.waitToolEnabled !== undefined) {\n\t\tenv[WAIT_TOOL_ENABLED_ENV] = input.waitToolEnabled ? \"true\" : \"false\";\n\t}\n\tconst inheritedNestedRoute = Boolean(process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] && process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] && process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV]);\n\tconst parentRunId = input.parentRunId ?? input.runId ?? (inheritedNestedRoute ? process.env[SUBAGENT_RUN_ID_ENV] : undefined) ?? process.env[SUBAGENT_PARENT_RUN_ID_ENV] ?? \"\";\n\tconst parentChildIndex = input.parentChildIndex !== undefined\n\t\t? String(input.parentChildIndex)\n\t\t: input.childIndex !== undefined\n\t\t\t? String(input.childIndex)\n\t\t\t: process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] ?? \"\";\n\tconst inheritedDepth = Number(process.env[SUBAGENT_PARENT_DEPTH_ENV]);\n\tconst parentDepth = input.parentDepth ?? (inheritedNestedRoute && Number.isFinite(inheritedDepth) ? inheritedDepth + 1 : 1);\n\tconst parentPath = input.parentPath ?? [\n\t\t...parseNestedPathEnv(process.env[SUBAGENT_PARENT_PATH_ENV]),\n\t\t...(parentRunId ? [{\n\t\t\trunId: parentRunId,\n\t\t\t...(parentChildIndex && /^\\d+$/.test(parentChildIndex) ? { stepIndex: Number(parentChildIndex) } : {}),\n\t\t\t...(input.childAgentName ? { agent: input.childAgentName } : {}),\n\t\t}] : []),\n\t];\n\tenv[SUBAGENT_PARENT_EVENT_SINK_ENV] = fanoutAuthorized\n\t\t? input.parentEventSink ?? process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_CONTROL_INBOX_ENV] = fanoutAuthorized\n\t\t? input.parentControlInbox ?? process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV] ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] = fanoutAuthorized\n\t\t? input.parentRootRunId ?? process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] ?? input.runId ?? \"\"\n\t\t: \"\";\n\tenv[SUBAGENT_PARENT_RUN_ID_ENV] = fanoutAuthorized ? parentRunId : \"\";\n\tenv[SUBAGENT_PARENT_CHILD_INDEX_ENV] = fanoutAuthorized ? parentChildIndex : \"\";\n\tenv[SUBAGENT_PARENT_DEPTH_ENV] = fanoutAuthorized ? String(parentDepth) : \"\";\n\tenv[SUBAGENT_PARENT_PATH_ENV] = fanoutAuthorized ? encodeNestedPathEnv(parentPath) : \"\";\n\tenv[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = fanoutAuthorized\n\t\t? input.parentCapabilityToken ?? process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] ?? \"\"\n\t\t: \"\";\n\tenv.PI_SUBAGENT_INHERIT_PROJECT_CONTEXT = input.inheritProjectContext ? \"1\" : \"0\";\n\tenv.PI_SUBAGENT_INHERIT_SKILLS = input.inheritSkills ? \"1\" : \"0\";\n\tenv.PI_SUBAGENT_INTERCOM_SESSION_NAME = communicationEnabled ? input.intercomSessionName ?? \"\" : \"\";\n\tenv[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = communicationEnabled ? input.orchestratorIntercomTarget ?? \"\" : \"\";\n\tenv[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = communicationEnabled ? input.parentSessionId ?? \"\" : \"\";\n\tenv[SUBAGENT_SUPERVISOR_SESSION_ID_ENV] = communicationEnabled ? input.supervisorSessionId ?? \"\" : \"\";\n\tenv[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = \"\";\n\tenv[SUPERVISOR_PROTOCOL_ENV] = String(SUPERVISOR_PROTOCOL_VERSION);\n\tenv[CHILD_DESCRIPTION_ENV] = input.childDescription ?? input.childAgentName ?? \"\";\n\tif (communicationEnabled && input.parentSessionId && input.runId && (input.childId || input.childAgentName)) {\n\t\tconst childIndex = input.childIndex ?? 0;\n\t\tconst channelAgent = input.childId ?? input.childAgentName!;\n\t\tconst channelDir = supervisorChannelDir(input.runId, channelAgent, childIndex);\n\t\tfs.mkdirSync(path.join(channelDir, \"requests\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"replies\"), { recursive: true });\n\t\tfs.mkdirSync(path.join(channelDir, \"questions\"), { recursive: true });\n\t\tenv[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = channelDir;\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(childIndex);\n\t}\n\tif (input.runId) {\n\t\tenv[SUBAGENT_RUN_ID_ENV] = input.runId;\n\t}\n\tif (input.childId || input.childAgentName) {\n\t\tenv[SUBAGENT_CHILD_AGENT_ENV] = input.childId ?? input.childAgentName;\n\t}\n\tif (input.childIndex !== undefined) {\n\t\tenv[SUBAGENT_CHILD_INDEX_ENV] = String(input.childIndex);\n\t}\n\tif (input.mcpDirectTools?.length) {\n\t\tenv.MCP_DIRECT_TOOLS = input.mcpDirectTools.join(\",\");\n\t} else {\n\t\tenv.MCP_DIRECT_TOOLS = \"__none__\";\n\t}\n\tif (input.structuredOutput) {\n\t\tenv[STRUCTURED_OUTPUT_CAPTURE_ENV] = input.structuredOutput.outputPath;\n\t\tenv[STRUCTURED_OUTPUT_SCHEMA_ENV] = input.structuredOutput.schemaPath;\n\t}\n\tif (input.steerInboxDir) {\n\t\tenv[SUBAGENT_STEER_INBOX_ENV] = input.steerInboxDir;\n\t}\n\tif (input.steerCapabilityPath) env[SUBAGENT_STEER_CAPABILITY_ENV] = input.steerCapabilityPath;\n\tif (input.steerAckDir) env[SUBAGENT_STEER_ACK_DIR_ENV] = input.steerAckDir;\n\tconst encodedToolBudget = encodeToolBudgetEnv(input.toolBudget);\n\tif (encodedToolBudget) env[TOOL_BUDGET_ENV] = encodedToolBudget;\n\tconst encodedChildWatchdog = encodeChildWatchdogConfig(input.childWatchdog);\n\tif (encodedChildWatchdog) env[CHILD_WATCHDOG_CONFIG_ENV] = encodedChildWatchdog;\n\n\tenv[SUBAGENT_PARENT_SESSION_ENV] = input.parentSessionId ?? process.env[SUBAGENT_PARENT_SESSION_ENV] ?? \"\";\n\n\treturn { args, env, tempDir, toolDiagnosticPath };\n}\n\nexport const parseParentPathEnv = parseNestedPathEnv;\n\nexport function cleanupTempDir(tempDir: string | null | undefined): void {\n\tif (!tempDir) return;\n\ttry {\n\t\tfs.rmSync(tempDir, { recursive: true, force: true });\n\t} catch {\n\t\t// Temp cleanup is best effort.\n\t}\n}\n"]}
|
package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-prompt-runtime.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAqH,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAsBxL,eAAO,MAAM,kCAAkC,sCAAsC,CAAC;AAQtF,eAAO,MAAM,oCAAoC,QAMrC,CAAC;AAEb,eAAO,MAAM,kCAAkC,QAOnC,CAAC;AA6Cb,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAItE;AAUD,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,qBAAqB,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GACxF,MAAM,CAaR;AA4BD,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAkB9E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAQhE;AAwBD,wBAAgB,qBAAqB,CACpC,EAAE,EAAE,YAAY,EAChB,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC;IAAC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;CAAO,GACnF,IAAI,CAoHN;AAED,MAAM,CAAC,OAAO,UAAU,6BAA6B,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAiH5E","sourcesContent":["// @ts-nocheck\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { ExtensionAPI } from \"@ashx-j/lunr\";\nimport { isPendingQuestionForCurrentChild, markDeliveredSupervisorQuestionFromChild, registerNativeSupervisorClient } from \"../../intercom/native-supervisor-channel.ts\";\nimport { consumeSteerRequestsFromDir, steerAckPathFromDir, writeSteerAckAt, writeSteerCapabilityAt, writeSteerRequestToDir, type SteerRequest } from \"../background/control-channel.ts\";\nimport { SUBAGENT_CHILD_AGENT_ENV, SUBAGENT_CHILD_INDEX_ENV, SUBAGENT_FANOUT_CHILD_ENV, SUBAGENT_STEER_ACK_DIR_ENV, SUBAGENT_STEER_CAPABILITY_ENV, SUBAGENT_STEER_INBOX_ENV } from \"./pi-args.ts\";\nimport { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV, validateStructuredOutputValue } from \"./structured-output.ts\";\nimport {\n\tCHILD_TOOL_DIAGNOSTIC_PATH_ENV,\n\tformatChildToolDiagnostic,\n\tREQUIRED_CHILD_TOOLS_ENV,\n\twriteChildToolDiagnostic,\n\ttype ChildToolDiagnostic,\n} from \"./tool-availability.ts\";\nimport { TOOL_BUDGET_ENV, decodeToolBudgetEnv, shouldBlockToolForBudget, toolBudgetBlockedMessage, toolBudgetSoftNudge } from \"./tool-budget.ts\";\nimport type { JsonSchemaObject, ResolvedToolBudget, SubagentState } from \"../../shared/types.ts\";\nimport { resolveCurrentSessionId } from \"../../shared/session-identity.ts\";\nimport { resolveWatchPath } from \"../../shared/utils.ts\";\nimport { registerChildWatchdog } from \"../../watchdog/register-child.ts\";\nimport { SUBAGENT_WATCHDOG_WARNING_TYPE } from \"../../watchdog/types.ts\";\nimport { resolveWaitToolConfig } from \"../background/wait-config.ts\";\nimport { registerWaitTool } from \"../background/wait-tool.ts\";\nimport { drainOutstandingWork } from \"../background/auto-drain.ts\";\n\nconst SUBAGENT_INHERIT_PROJECT_CONTEXT_ENV = \"PI_SUBAGENT_INHERIT_PROJECT_CONTEXT\";\nconst SUBAGENT_INHERIT_SKILLS_ENV = \"PI_SUBAGENT_INHERIT_SKILLS\";\nexport const SUBAGENT_INTERCOM_SESSION_NAME_ENV = \"PI_SUBAGENT_INTERCOM_SESSION_NAME\";\n\nconst STRUCTURED_OUTPUT_INSTRUCTIONS = [\n\t\"This subagent step has a strict structured output contract.\",\n\t\"Your final action must be to call the `structured_output` tool with JSON matching the provided schema.\",\n\t\"Do not rely on prose-only completion; if you do not call `structured_output`, the parent will fail this step.\",\n].join(\"\\n\");\n\nexport const CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS = [\n\t\"You are a child subagent, not the parent orchestrator.\",\n\t\"The parent session owns delegation, orchestration, review fanout, and follow-up launches.\",\n\t\"Ignore prior parent-only orchestration instructions in inherited conversation history.\",\n\t\"Do not propose or run subagents. Complete only your assigned task with the tools available to you.\",\n\t\"If you need to edit files, use the available editing tools. Do not print tool-call syntax, patches, or pseudo-tool calls as text.\",\n].join(\"\\n\");\n\nexport const CHILD_FANOUT_BOUNDARY_INSTRUCTIONS = [\n\t\"You are a child subagent with explicit fanout responsibility for this assigned task.\",\n\t\"The parent session owns final orchestration, acceptance, and follow-up implementation launches.\",\n\t\"You may use the `subagent` tool only for the fanout work explicitly requested in this task.\",\n\t\"Do not broaden yourself into general parent orchestration. Do not launch follow-up workers unless the task explicitly asks for that.\",\n\t\"The maxSubagentDepth cap still applies and may block further fanout.\",\n\t\"If you need to edit files, use the available editing tools. Do not print tool-call syntax, patches, or pseudo-tool calls as text.\",\n].join(\"\\n\");\n\nconst PARENT_ONLY_CUSTOM_MESSAGE_TYPES = new Set([\n\t\"subagent-orchestration-instructions\",\n\t\"subagent-slash-result\",\n\t\"subagent-slash-text-result\",\n\t\"subagent-notify\",\n\t\"subagent_control_notice\",\n\t\"subagent-control\",\n\t\"subagent-control-notice\",\n]);\nconst SUBAGENT_ORCHESTRATION_SKILL_NAME_PATTERN = /<name>\\s*pi-subagents\\s*<\\/name>/;\nconst PROJECT_CONTEXT_HEADER = \"\\n\\n# Project Context\\n\\nProject-specific instructions and guidelines:\\n\\n\";\nconst SKILLS_HEADER = \"\\n\\nThe following skills provide specialized instructions for specific tasks.\";\nconst DATE_HEADER = \"\\nCurrent date:\";\n\nfunction readBooleanEnv(name: string): boolean | undefined {\n\tconst value = process.env[name];\n\tif (value === undefined) return undefined;\n\treturn value !== \"0\";\n}\n\nfunction refreshChildToolDiagnostic(pi: ExtensionAPI): ChildToolDiagnostic | undefined {\n\tconst filePath = process.env[CHILD_TOOL_DIAGNOSTIC_PATH_ENV]?.trim();\n\tconst encoded = process.env[REQUIRED_CHILD_TOOLS_ENV]?.trim();\n\tif (!filePath || !encoded) return undefined;\n\tconst required = JSON.parse(encoded) as unknown;\n\tif (!Array.isArray(required) || required.some((name) => typeof name !== \"string\" || !name)) {\n\t\tthrow new Error(`Invalid ${REQUIRED_CHILD_TOOLS_ENV} payload.`);\n\t}\n\tconst available = pi.getAllTools().map((tool) => tool.name);\n\treturn writeChildToolDiagnostic(filePath, required, available, process.env[SUBAGENT_CHILD_AGENT_ENV]?.trim());\n}\n\nfunction findSectionEnd(prompt: string, startIndex: number, nextHeaders: string[]): number {\n\tlet endIndex = prompt.length;\n\tfor (const header of nextHeaders) {\n\t\tconst index = prompt.indexOf(header, startIndex);\n\t\tif (index !== -1 && index < endIndex) {\n\t\t\tendIndex = index;\n\t\t}\n\t}\n\treturn endIndex;\n}\n\nexport function stripProjectContext(prompt: string): string {\n\tconst startIndex = prompt.indexOf(PROJECT_CONTEXT_HEADER);\n\tif (startIndex === -1) return prompt;\n\tconst endIndex = findSectionEnd(prompt, startIndex + PROJECT_CONTEXT_HEADER.length, [SKILLS_HEADER, DATE_HEADER]);\n\treturn `${prompt.slice(0, startIndex)}${prompt.slice(endIndex)}`;\n}\n\nexport function stripInheritedSkills(prompt: string): string {\n\tconst startIndex = prompt.indexOf(SKILLS_HEADER);\n\tif (startIndex === -1) return prompt;\n\tconst endIndex = findSectionEnd(prompt, startIndex + SKILLS_HEADER.length, [DATE_HEADER]);\n\treturn `${prompt.slice(0, startIndex)}${prompt.slice(endIndex)}`;\n}\n\nexport function stripSubagentOrchestrationSkill(prompt: string): string {\n\treturn prompt\n\t\t.replace(/\\n{0,2}<skill\\s+name=[\"']pi-subagents[\"'][^>]*>[\\s\\S]*?<\\/skill>\\n{0,2}/g, \"\\n\\n\")\n\t\t.replace(/[ \\t]*<skill>\\s*[\\s\\S]*?<\\/skill>\\s*/g, (block) => SUBAGENT_ORCHESTRATION_SKILL_NAME_PATTERN.test(block) ? \"\" : block);\n}\n\nfunction stripChildBoundaryInstructions(prompt: string): string {\n\tlet rewritten = prompt;\n\tfor (const boundary of [CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS, CHILD_FANOUT_BOUNDARY_INSTRUCTIONS]) {\n\t\trewritten = rewritten.split(boundary).join(\"\");\n\t}\n\treturn rewritten.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\");\n}\n\nexport function rewriteSubagentPrompt(\n\tprompt: string,\n\toptions: { inheritProjectContext: boolean; inheritSkills: boolean; fanoutChild?: boolean },\n): string {\n\tlet rewritten = prompt;\n\tif (!options.inheritProjectContext) {\n\t\trewritten = stripProjectContext(rewritten);\n\t}\n\tif (!options.inheritSkills) {\n\t\trewritten = stripInheritedSkills(rewritten);\n\t}\n\trewritten = stripSubagentOrchestrationSkill(rewritten);\n\trewritten = stripChildBoundaryInstructions(rewritten);\n\tconst boundary = options.fanoutChild ? CHILD_FANOUT_BOUNDARY_INSTRUCTIONS : CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS;\n\tconst structured = process.env[STRUCTURED_OUTPUT_CAPTURE_ENV] ? `\\n\\n${STRUCTURED_OUTPUT_INSTRUCTIONS}` : \"\";\n\treturn `${boundary}${structured}\\n\\n${rewritten}`;\n}\n\nfunction isParentOnlySubagentMessage(message: unknown): boolean {\n\tconst m = message as { role?: string; customType?: string };\n\tif (m?.role !== \"custom\" || typeof m.customType !== \"string\") return false;\n\tif (m.customType === SUBAGENT_WATCHDOG_WARNING_TYPE) return true;\n\treturn PARENT_ONLY_CUSTOM_MESSAGE_TYPES.has(m.customType);\n}\n\nfunction isSubagentToolResultMessage(message: unknown): boolean {\n\tconst m = message as { role?: string; toolName?: string };\n\treturn m?.role === \"toolResult\" && m.toolName === \"subagent\";\n}\n\nfunction isSubagentToolCallBlock(block: unknown): boolean {\n\tconst b = block as { type?: string; name?: string };\n\treturn b?.type === \"toolCall\" && b.name === \"subagent\";\n}\n\nfunction stripAssistantSubagentToolCallBlocks(message: unknown): unknown | undefined {\n\tconst m = message as { role?: string; content?: unknown };\n\tif (m?.role !== \"assistant\" || !Array.isArray(m.content)) return message;\n\tconst filteredContent = m.content.filter((block) => !isSubagentToolCallBlock(block));\n\tif (filteredContent.length === m.content.length) return message;\n\tif (filteredContent.length === 0) return undefined;\n\treturn { ...m, content: filteredContent };\n}\n\nexport function stripParentOnlySubagentMessages(messages: unknown[]): unknown[] {\n\tconst preserveCurrentFanoutToolHistory = process.env[SUBAGENT_FANOUT_CHILD_ENV] === \"1\";\n\tlet changed = false;\n\tconst filtered: unknown[] = [];\n\tfor (const message of messages) {\n\t\tif (isParentOnlySubagentMessage(message) || (!preserveCurrentFanoutToolHistory && isSubagentToolResultMessage(message))) {\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst stripped = preserveCurrentFanoutToolHistory ? message : stripAssistantSubagentToolCallBlocks(message);\n\t\tif (stripped === undefined) {\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (stripped !== message) changed = true;\n\t\tfiltered.push(stripped);\n\t}\n\treturn changed ? filtered : messages;\n}\n\nexport function formatSteerMessage(request: SteerRequest): string {\n\treturn [\n\t\t\"Mid-run steering from the parent orchestrator:\",\n\t\t\"\",\n\t\trequest.message,\n\t\t\"\",\n\t\t\"Incorporate this guidance at the next safe point. Do not restart the task unless the guidance explicitly asks you to.\",\n\t].join(\"\\n\");\n}\n\nfunction registerToolBudget(pi: ExtensionAPI, budget: ResolvedToolBudget | undefined): void {\n\tif (!budget) return;\n\tlet toolCount = 0;\n\tlet softNudged = false;\n\tconst sendUserMessage = (pi as { sendUserMessage?: (content: string, options: { deliverAs: \"steer\" }) => unknown }).sendUserMessage;\n\tconst onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: { toolName?: string }) => unknown) => void;\n\tonRuntimeEvent(\"tool_call\", (event) => {\n\t\tconst toolName = typeof event.toolName === \"string\" ? event.toolName : \"tool\";\n\t\ttoolCount++;\n\t\tif (budget.soft !== undefined && toolCount >= budget.soft && !softNudged) {\n\t\t\tsoftNudged = true;\n\t\t\ttry {\n\t\t\t\tsendUserMessage?.(toolBudgetSoftNudge(budget, toolCount), { deliverAs: \"steer\" });\n\t\t\t} catch {\n\t\t\t\t// Budget nudges are advisory; blocking below remains authoritative.\n\t\t\t}\n\t\t}\n\t\tif (!shouldBlockToolForBudget(budget, toolName, toolCount)) return undefined;\n\t\treturn { block: true, reason: toolBudgetBlockedMessage(budget, toolName, toolCount) };\n\t});\n}\n\nexport function registerSteeringInbox(\n\tpi: ExtensionAPI,\n\tdeps: { watch?: typeof fs.watch; nativeRealpath?: (filePath: string) => string } = {},\n): void {\n\tconst steerInbox = process.env[SUBAGENT_STEER_INBOX_ENV]?.trim();\n\tif (!steerInbox) return;\n\tconst capabilityPath = process.env[SUBAGENT_STEER_CAPABILITY_ENV]?.trim();\n\tconst ackDir = process.env[SUBAGENT_STEER_ACK_DIR_ENV]?.trim();\n\tconst sendUserMessage = (pi as { sendUserMessage?: (content: string, options: { deliverAs: \"steer\" }) => unknown }).sendUserMessage;\n\tconst childIndex = Number(process.env[SUBAGENT_CHILD_INDEX_ENV]);\n\tconst pending = new Map<string, string[]>();\n\tlet disposed = false;\n\tlet flushing = false;\n\tlet started = false;\n\tlet canSteer = typeof sendUserMessage === \"function\";\n\tlet watcher: fs.FSWatcher | undefined;\n\tlet interval: NodeJS.Timeout | undefined;\n\tconst acknowledge = (request: SteerRequest, state: \"delivered\" | \"failed\", message: string): void => {\n\t\tif (!ackDir || !Number.isInteger(childIndex) || childIndex < 0) return;\n\t\twriteSteerAckAt(steerAckPathFromDir(ackDir, request.id), {\n\t\t\trequestId: request.id,\n\t\t\tindex: childIndex,\n\t\t\tts: Date.now(),\n\t\t\tstate,\n\t\t\tmessage,\n\t\t});\n\t};\n\tlet readyAt = Number(process.env.PI_SUBAGENT_STEER_READY_AT);\n\tif (!Number.isFinite(readyAt) || readyAt <= 0) {\n\t\treadyAt = Date.now();\n\t\tprocess.env.PI_SUBAGENT_STEER_READY_AT = String(readyAt);\n\t}\n\tconst publishCapability = (): void => {\n\t\tif (!capabilityPath || !Number.isInteger(childIndex) || childIndex < 0) return;\n\t\twriteSteerCapabilityAt(capabilityPath, { index: childIndex, pid: process.pid, readyAt, supported: canSteer });\n\t};\n\tconst flush = (): void => {\n\t\tif (disposed || flushing) return;\n\t\tflushing = true;\n\t\ttry {\n\t\t\tconst requests = consumeSteerRequestsFromDir(steerInbox);\n\t\t\tfor (let index = 0; index < requests.length; index++) {\n\t\t\t\tconst request = requests[index]!;\n\t\t\t\tif (!canSteer || typeof sendUserMessage !== \"function\") {\n\t\t\t\t\tacknowledge(request, \"failed\", \"Child Pi session does not support sendUserMessage steering.\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (request.source === \"supervisor-question\" && !isPendingQuestionForCurrentChild(request.id)) {\n\t\t\t\t\tacknowledge(request, \"failed\", \"Question is no longer pending for this child.\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst formatted = request.source === \"supervisor-question\" ? request.message : formatSteerMessage(request);\n\t\t\t\tconst ids = pending.get(formatted) ?? [];\n\t\t\t\tids.push(request.id);\n\t\t\t\tpending.set(formatted, ids);\n\t\t\t\ttry {\n\t\t\t\t\tsendUserMessage(formatted, { deliverAs: \"steer\" });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tids.pop();\n\t\t\t\t\tif (ids.length === 0) pending.delete(formatted);\n\t\t\t\t\tacknowledge(request, \"failed\", error instanceof Error ? error.message : String(error));\n\t\t\t\t\tfor (const retry of requests.slice(index + 1)) writeSteerRequestToDir(steerInbox, retry);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tflushing = false;\n\t\t}\n\t};\n\tconst onInput = (event: unknown): undefined => {\n\t\tif (disposed || !event || typeof event !== \"object\") return undefined;\n\t\tconst input = event as { source?: unknown; streamingBehavior?: unknown; text?: unknown; content?: unknown };\n\t\tif (input.source !== \"extension\" || input.streamingBehavior !== \"steer\") return undefined;\n\t\tconst text = typeof input.text === \"string\" ? input.text : typeof input.content === \"string\" ? input.content : undefined;\n\t\tif (!text) return undefined;\n\t\tconst ids = pending.get(text);\n\t\tconst requestId = ids?.shift();\n\t\tif (!requestId) return undefined;\n\t\tif (ids?.length === 0) pending.delete(text);\n\t\tacknowledge({ type: \"steer\", id: requestId, ts: Date.now(), message: text }, \"delivered\", \"Pi accepted the correlated steering input.\");\n\t\tmarkDeliveredSupervisorQuestionFromChild(text);\n\t\treturn undefined;\n\t};\n\tconst start = (): void => {\n\t\tif (started || disposed) return;\n\t\ttry {\n\t\t\tfs.mkdirSync(steerInbox, { recursive: true });\n\t\t\tpublishCapability();\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tstarted = true;\n\t\ttry {\n\t\t\twatcher = (deps.watch ?? fs.watch)(resolveWatchPath(steerInbox, deps.nativeRealpath), () => flush());\n\t\t\twatcher.on(\"error\", () => {});\n\t\t} catch {\n\t\t\twatcher = undefined;\n\t\t}\n\t\tinterval = setInterval(flush, 250);\n\t\tinterval.unref?.();\n\t};\n\tconst activate = (): undefined => {\n\t\tstart();\n\t\tflush();\n\t\treturn undefined;\n\t};\n\n\tconst onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;\n\t// Register input before the watcher so an accepted extension input cannot race request dispatch.\n\tonRuntimeEvent(\"input\", onInput);\n\tonRuntimeEvent(\"session_start\", () => start());\n\tfor (const eventName of [\"message_start\", \"message_update\", \"message_end\", \"tool_execution_start\", \"tool_execution_end\", \"turn_end\"] as const) {\n\t\tonRuntimeEvent(eventName, activate);\n\t}\n\tonRuntimeEvent(\"session_shutdown\", () => {\n\t\tdisposed = true;\n\t\ttry { watcher?.close(); } catch {}\n\t\tif (interval) clearInterval(interval);\n\t});\n}\n\nexport default function registerSubagentPromptRuntime(pi: ExtensionAPI): void {\n\tregisterSteeringInbox(pi);\n\tregisterToolBudget(pi, decodeToolBudgetEnv(process.env[TOOL_BUDGET_ENV]));\n\tregisterChildWatchdog(pi);\n\tconst waitToolEnabled = resolveWaitToolConfig().enabled;\n\tconst waitState = {\n\t\tbaseCwd: \"\",\n\t\tcurrentSessionId: null,\n\t\tasyncJobs: new Map(),\n\t\tforegroundControls: new Map(),\n\t\tlastForegroundControlId: null,\n\t\tcleanupTimers: new Map(),\n\t\tlastUiContext: null,\n\t\tpoller: null,\n\t\tcompletionSeen: new Map(),\n\t\twatcher: null,\n\t\twatcherRestartTimer: null,\n\t\tresultFileCoalescer: { schedule: () => false, clear: () => {} },\n\t} as unknown as SubagentState;\n\tif (typeof pi.registerTool === \"function\") registerWaitTool(pi, waitState, waitToolEnabled);\n\tlet nativeSupervisorClientRegistered = false;\n\tlet nativeSupervisorFallbackRegistered = false;\n\tconst registerNativeSupervisorClientOnce = (): void => {\n\t\tif (nativeSupervisorClientRegistered) return;\n\t\tnativeSupervisorClientRegistered = true;\n\t\tregisterNativeSupervisorClient(pi, { includeIntercomFallback: false });\n\t};\n\tconst registerNativeSupervisorFallbackOnce = (): void => {\n\t\tregisterNativeSupervisorClientOnce();\n\t\tif (nativeSupervisorFallbackRegistered) return;\n\t\tnativeSupervisorFallbackRegistered = true;\n\t\tregisterNativeSupervisorClient(pi);\n\t};\n\tconst onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;\n\tonRuntimeEvent(\"session_start\", (_event: unknown, ctx: unknown) => {\n\t\tconst sessionManager = (ctx as { sessionManager?: Parameters<typeof resolveCurrentSessionId>[0] } | undefined)?.sessionManager;\n\t\twaitState.currentSessionId = sessionManager ? resolveCurrentSessionId(sessionManager) : null;\n\t\tregisterNativeSupervisorClientOnce();\n\t\trefreshChildToolDiagnostic(pi);\n\t});\n\tonRuntimeEvent(\"agent_end\", async (_event: unknown, ctx: unknown) => {\n\t\tif ((ctx as { hasUI?: boolean } | undefined)?.hasUI === true) return;\n\t\tawait drainOutstandingWork({ state: waitState, events: pi.events, hasPendingMessages: () => ctx.hasPendingMessages() });\n\t});\n\tconst structuredOutputPath = process.env[STRUCTURED_OUTPUT_CAPTURE_ENV];\n\tconst structuredSchemaPath = process.env[STRUCTURED_OUTPUT_SCHEMA_ENV];\n\tif (structuredOutputPath && structuredSchemaPath) {\n\t\tconst schema = JSON.parse(fs.readFileSync(structuredSchemaPath, \"utf-8\")) as JsonSchemaObject;\n\t\tconst parameters = {\n\t\t\ttype: \"object\",\n\t\t\tproperties: { value: schema },\n\t\t\trequired: [\"value\"],\n\t\t\tadditionalProperties: false,\n\t\t};\n\t\tconst registerTool = pi.registerTool as unknown as (tool: {\n\t\t\tname: string;\n\t\t\tlabel: string;\n\t\t\tdescription: string;\n\t\t\tparameters: unknown;\n\t\t\texecute: (_id: string, params: { value: unknown }) => Promise<unknown>;\n\t\t}) => void;\n\t\tregisterTool({\n\t\t\tname: \"structured_output\",\n\t\t\tlabel: \"Structured Output\",\n\t\t\tdescription: \"Submit the required final structured output for this subagent step. This terminates the step.\",\n\t\t\tparameters: parameters as never,\n\t\t\tasync execute(_id: string, params: { value: unknown }) {\n\t\t\t\tconst validation = validateStructuredOutputValue(schema, params.value);\n\t\t\t\tif (validation.status === \"invalid\") {\n\t\t\t\t\tthrow new Error(`Structured output validation failed: ${validation.message}`);\n\t\t\t\t}\n\t\t\t\tfs.mkdirSync(path.dirname(structuredOutputPath), { recursive: true });\n\t\t\t\tfs.writeFileSync(structuredOutputPath, JSON.stringify(params.value), { mode: 0o600 });\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Structured output captured.\" }],\n\t\t\t\t\tdetails: { path: structuredOutputPath },\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t}\n\n\tonRuntimeEvent(\"context\", (event: { messages: unknown[] }) => {\n\t\tconst messages = stripParentOnlySubagentMessages(event.messages);\n\t\tif (messages === event.messages) return undefined;\n\t\treturn { messages };\n\t});\n\n\tonRuntimeEvent(\"before_agent_start\", async (event: { systemPrompt: string }) => {\n\t\tregisterNativeSupervisorFallbackOnce();\n\t\tconst toolDiagnostic = refreshChildToolDiagnostic(pi);\n\t\tconst intercomSessionName = process.env[SUBAGENT_INTERCOM_SESSION_NAME_ENV]?.trim();\n\t\tif (intercomSessionName && typeof pi.setSessionName === \"function\") {\n\t\t\tpi.setSessionName(intercomSessionName);\n\t\t}\n\n\t\tconst inheritProjectContext = readBooleanEnv(SUBAGENT_INHERIT_PROJECT_CONTEXT_ENV);\n\t\tconst inheritSkills = readBooleanEnv(SUBAGENT_INHERIT_SKILLS_ENV);\n\t\tconst fanoutChild = readBooleanEnv(SUBAGENT_FANOUT_CHILD_ENV);\n\t\tlet rewritten = event.systemPrompt;\n\t\tif (inheritProjectContext !== undefined || inheritSkills !== undefined || fanoutChild !== undefined) {\n\t\t\trewritten = rewriteSubagentPrompt(event.systemPrompt, {\n\t\t\t\tinheritProjectContext: inheritProjectContext ?? true,\n\t\t\t\tinheritSkills: inheritSkills ?? true,\n\t\t\t\tfanoutChild: fanoutChild === true,\n\t\t\t});\n\t\t}\n\t\tif (toolDiagnostic) {\n\t\t\trewritten = `${formatChildToolDiagnostic(toolDiagnostic)}\\nDo not claim tool-dependent work succeeded; report this configuration error to the parent.\\n\\n${rewritten}`;\n\t\t}\n\t\tif (rewritten === event.systemPrompt) return;\n\t\treturn { systemPrompt: rewritten };\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subagent-prompt-runtime.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAqH,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAsBxL,eAAO,MAAM,kCAAkC,sCAAsC,CAAC;AAQtF,eAAO,MAAM,oCAAoC,QAMrC,CAAC;AAEb,eAAO,MAAM,kCAAkC,QAOnC,CAAC;AA6Cb,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK1D;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAItE;AAUD,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,qBAAqB,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GACxF,MAAM,CAaR;AA4BD,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAkB9E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAQhE;AAwBD,wBAAgB,qBAAqB,CACpC,EAAE,EAAE,YAAY,EAChB,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC;IAAC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;CAAO,GACnF,IAAI,CAoHN;AAED,MAAM,CAAC,OAAO,UAAU,6BAA6B,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAkH5E","sourcesContent":["// @ts-nocheck\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { ExtensionAPI } from \"@ashx-j/lunr\";\nimport { isPendingQuestionForCurrentChild, markDeliveredSupervisorQuestionFromChild, registerNativeSupervisorClient } from \"../../intercom/native-supervisor-channel.ts\";\nimport { consumeSteerRequestsFromDir, steerAckPathFromDir, writeSteerAckAt, writeSteerCapabilityAt, writeSteerRequestToDir, type SteerRequest } from \"../background/control-channel.ts\";\nimport { SUBAGENT_CHILD_AGENT_ENV, SUBAGENT_CHILD_INDEX_ENV, SUBAGENT_FANOUT_CHILD_ENV, SUBAGENT_STEER_ACK_DIR_ENV, SUBAGENT_STEER_CAPABILITY_ENV, SUBAGENT_STEER_INBOX_ENV } from \"./pi-args.ts\";\nimport { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV, validateStructuredOutputValue } from \"./structured-output.ts\";\nimport {\n\tCHILD_TOOL_DIAGNOSTIC_PATH_ENV,\n\tformatChildToolDiagnostic,\n\tREQUIRED_CHILD_TOOLS_ENV,\n\twriteChildToolDiagnostic,\n\ttype ChildToolDiagnostic,\n} from \"./tool-availability.ts\";\nimport { TOOL_BUDGET_ENV, decodeToolBudgetEnv, shouldBlockToolForBudget, toolBudgetBlockedMessage, toolBudgetSoftNudge } from \"./tool-budget.ts\";\nimport type { JsonSchemaObject, ResolvedToolBudget, SubagentState } from \"../../shared/types.ts\";\nimport { resolveCurrentSessionId } from \"../../shared/session-identity.ts\";\nimport { resolveWatchPath } from \"../../shared/utils.ts\";\nimport { registerChildWatchdog } from \"../../watchdog/register-child.ts\";\nimport { SUBAGENT_WATCHDOG_WARNING_TYPE } from \"../../watchdog/types.ts\";\nimport { resolveWaitToolConfig } from \"../background/wait-config.ts\";\nimport { registerWaitTool } from \"../background/wait-tool.ts\";\nimport { drainOutstandingWork } from \"../background/auto-drain.ts\";\n\nconst SUBAGENT_INHERIT_PROJECT_CONTEXT_ENV = \"PI_SUBAGENT_INHERIT_PROJECT_CONTEXT\";\nconst SUBAGENT_INHERIT_SKILLS_ENV = \"PI_SUBAGENT_INHERIT_SKILLS\";\nexport const SUBAGENT_INTERCOM_SESSION_NAME_ENV = \"PI_SUBAGENT_INTERCOM_SESSION_NAME\";\n\nconst STRUCTURED_OUTPUT_INSTRUCTIONS = [\n\t\"This subagent step has a strict structured output contract.\",\n\t\"Your final action must be to call the `structured_output` tool with JSON matching the provided schema.\",\n\t\"Do not rely on prose-only completion; if you do not call `structured_output`, the parent will fail this step.\",\n].join(\"\\n\");\n\nexport const CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS = [\n\t\"You are a child subagent, not the parent orchestrator.\",\n\t\"The parent session owns delegation, orchestration, review fanout, and follow-up launches.\",\n\t\"Ignore prior parent-only orchestration instructions in inherited conversation history.\",\n\t\"Do not propose or run subagents. Complete only your assigned task with the tools available to you.\",\n\t\"If you need to edit files, use the available editing tools. Do not print tool-call syntax, patches, or pseudo-tool calls as text.\",\n].join(\"\\n\");\n\nexport const CHILD_FANOUT_BOUNDARY_INSTRUCTIONS = [\n\t\"You are a child subagent with explicit fanout responsibility for this assigned task.\",\n\t\"The parent session owns final orchestration, acceptance, and follow-up implementation launches.\",\n\t\"You may use the `subagent` tool only for the fanout work explicitly requested in this task.\",\n\t\"Do not broaden yourself into general parent orchestration. Do not launch follow-up workers unless the task explicitly asks for that.\",\n\t\"The maxSubagentDepth cap still applies and may block further fanout.\",\n\t\"If you need to edit files, use the available editing tools. Do not print tool-call syntax, patches, or pseudo-tool calls as text.\",\n].join(\"\\n\");\n\nconst PARENT_ONLY_CUSTOM_MESSAGE_TYPES = new Set([\n\t\"subagent-orchestration-instructions\",\n\t\"subagent-slash-result\",\n\t\"subagent-slash-text-result\",\n\t\"subagent-notify\",\n\t\"subagent_control_notice\",\n\t\"subagent-control\",\n\t\"subagent-control-notice\",\n]);\nconst SUBAGENT_ORCHESTRATION_SKILL_NAME_PATTERN = /<name>\\s*pi-subagents\\s*<\\/name>/;\nconst PROJECT_CONTEXT_HEADER = \"\\n\\n# Project Context\\n\\nProject-specific instructions and guidelines:\\n\\n\";\nconst SKILLS_HEADER = \"\\n\\nThe following skills provide specialized instructions for specific tasks.\";\nconst DATE_HEADER = \"\\nCurrent date:\";\n\nfunction readBooleanEnv(name: string): boolean | undefined {\n\tconst value = process.env[name];\n\tif (value === undefined) return undefined;\n\treturn value !== \"0\";\n}\n\nfunction refreshChildToolDiagnostic(pi: ExtensionAPI): ChildToolDiagnostic | undefined {\n\tconst filePath = process.env[CHILD_TOOL_DIAGNOSTIC_PATH_ENV]?.trim();\n\tconst encoded = process.env[REQUIRED_CHILD_TOOLS_ENV]?.trim();\n\tif (!filePath || !encoded) return undefined;\n\tconst required = JSON.parse(encoded) as unknown;\n\tif (!Array.isArray(required) || required.some((name) => typeof name !== \"string\" || !name)) {\n\t\tthrow new Error(`Invalid ${REQUIRED_CHILD_TOOLS_ENV} payload.`);\n\t}\n\tconst available = pi.getAllTools().map((tool) => tool.name);\n\treturn writeChildToolDiagnostic(filePath, required, available, process.env[SUBAGENT_CHILD_AGENT_ENV]?.trim());\n}\n\nfunction findSectionEnd(prompt: string, startIndex: number, nextHeaders: string[]): number {\n\tlet endIndex = prompt.length;\n\tfor (const header of nextHeaders) {\n\t\tconst index = prompt.indexOf(header, startIndex);\n\t\tif (index !== -1 && index < endIndex) {\n\t\t\tendIndex = index;\n\t\t}\n\t}\n\treturn endIndex;\n}\n\nexport function stripProjectContext(prompt: string): string {\n\tconst startIndex = prompt.indexOf(PROJECT_CONTEXT_HEADER);\n\tif (startIndex === -1) return prompt;\n\tconst endIndex = findSectionEnd(prompt, startIndex + PROJECT_CONTEXT_HEADER.length, [SKILLS_HEADER, DATE_HEADER]);\n\treturn `${prompt.slice(0, startIndex)}${prompt.slice(endIndex)}`;\n}\n\nexport function stripInheritedSkills(prompt: string): string {\n\tconst startIndex = prompt.indexOf(SKILLS_HEADER);\n\tif (startIndex === -1) return prompt;\n\tconst endIndex = findSectionEnd(prompt, startIndex + SKILLS_HEADER.length, [DATE_HEADER]);\n\treturn `${prompt.slice(0, startIndex)}${prompt.slice(endIndex)}`;\n}\n\nexport function stripSubagentOrchestrationSkill(prompt: string): string {\n\treturn prompt\n\t\t.replace(/\\n{0,2}<skill\\s+name=[\"']pi-subagents[\"'][^>]*>[\\s\\S]*?<\\/skill>\\n{0,2}/g, \"\\n\\n\")\n\t\t.replace(/[ \\t]*<skill>\\s*[\\s\\S]*?<\\/skill>\\s*/g, (block) => SUBAGENT_ORCHESTRATION_SKILL_NAME_PATTERN.test(block) ? \"\" : block);\n}\n\nfunction stripChildBoundaryInstructions(prompt: string): string {\n\tlet rewritten = prompt;\n\tfor (const boundary of [CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS, CHILD_FANOUT_BOUNDARY_INSTRUCTIONS]) {\n\t\trewritten = rewritten.split(boundary).join(\"\");\n\t}\n\treturn rewritten.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\");\n}\n\nexport function rewriteSubagentPrompt(\n\tprompt: string,\n\toptions: { inheritProjectContext: boolean; inheritSkills: boolean; fanoutChild?: boolean },\n): string {\n\tlet rewritten = prompt;\n\tif (!options.inheritProjectContext) {\n\t\trewritten = stripProjectContext(rewritten);\n\t}\n\tif (!options.inheritSkills) {\n\t\trewritten = stripInheritedSkills(rewritten);\n\t}\n\trewritten = stripSubagentOrchestrationSkill(rewritten);\n\trewritten = stripChildBoundaryInstructions(rewritten);\n\tconst boundary = options.fanoutChild ? CHILD_FANOUT_BOUNDARY_INSTRUCTIONS : CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS;\n\tconst structured = process.env[STRUCTURED_OUTPUT_CAPTURE_ENV] ? `\\n\\n${STRUCTURED_OUTPUT_INSTRUCTIONS}` : \"\";\n\treturn `${boundary}${structured}\\n\\n${rewritten}`;\n}\n\nfunction isParentOnlySubagentMessage(message: unknown): boolean {\n\tconst m = message as { role?: string; customType?: string };\n\tif (m?.role !== \"custom\" || typeof m.customType !== \"string\") return false;\n\tif (m.customType === SUBAGENT_WATCHDOG_WARNING_TYPE) return true;\n\treturn PARENT_ONLY_CUSTOM_MESSAGE_TYPES.has(m.customType);\n}\n\nfunction isSubagentToolResultMessage(message: unknown): boolean {\n\tconst m = message as { role?: string; toolName?: string };\n\treturn m?.role === \"toolResult\" && m.toolName === \"subagent\";\n}\n\nfunction isSubagentToolCallBlock(block: unknown): boolean {\n\tconst b = block as { type?: string; name?: string };\n\treturn b?.type === \"toolCall\" && b.name === \"subagent\";\n}\n\nfunction stripAssistantSubagentToolCallBlocks(message: unknown): unknown | undefined {\n\tconst m = message as { role?: string; content?: unknown };\n\tif (m?.role !== \"assistant\" || !Array.isArray(m.content)) return message;\n\tconst filteredContent = m.content.filter((block) => !isSubagentToolCallBlock(block));\n\tif (filteredContent.length === m.content.length) return message;\n\tif (filteredContent.length === 0) return undefined;\n\treturn { ...m, content: filteredContent };\n}\n\nexport function stripParentOnlySubagentMessages(messages: unknown[]): unknown[] {\n\tconst preserveCurrentFanoutToolHistory = process.env[SUBAGENT_FANOUT_CHILD_ENV] === \"1\";\n\tlet changed = false;\n\tconst filtered: unknown[] = [];\n\tfor (const message of messages) {\n\t\tif (isParentOnlySubagentMessage(message) || (!preserveCurrentFanoutToolHistory && isSubagentToolResultMessage(message))) {\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst stripped = preserveCurrentFanoutToolHistory ? message : stripAssistantSubagentToolCallBlocks(message);\n\t\tif (stripped === undefined) {\n\t\t\tchanged = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (stripped !== message) changed = true;\n\t\tfiltered.push(stripped);\n\t}\n\treturn changed ? filtered : messages;\n}\n\nexport function formatSteerMessage(request: SteerRequest): string {\n\treturn [\n\t\t\"Mid-run steering from the parent orchestrator:\",\n\t\t\"\",\n\t\trequest.message,\n\t\t\"\",\n\t\t\"Incorporate this guidance at the next safe point. Do not restart the task unless the guidance explicitly asks you to.\",\n\t].join(\"\\n\");\n}\n\nfunction registerToolBudget(pi: ExtensionAPI, budget: ResolvedToolBudget | undefined): void {\n\tif (!budget) return;\n\tlet toolCount = 0;\n\tlet softNudged = false;\n\tconst sendUserMessage = (pi as { sendUserMessage?: (content: string, options: { deliverAs: \"steer\" }) => unknown }).sendUserMessage;\n\tconst onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: { toolName?: string }) => unknown) => void;\n\tonRuntimeEvent(\"tool_call\", (event) => {\n\t\tconst toolName = typeof event.toolName === \"string\" ? event.toolName : \"tool\";\n\t\ttoolCount++;\n\t\tif (budget.soft !== undefined && toolCount >= budget.soft && !softNudged) {\n\t\t\tsoftNudged = true;\n\t\t\ttry {\n\t\t\t\tsendUserMessage?.(toolBudgetSoftNudge(budget, toolCount), { deliverAs: \"steer\" });\n\t\t\t} catch {\n\t\t\t\t// Budget nudges are advisory; blocking below remains authoritative.\n\t\t\t}\n\t\t}\n\t\tif (!shouldBlockToolForBudget(budget, toolName, toolCount)) return undefined;\n\t\treturn { block: true, reason: toolBudgetBlockedMessage(budget, toolName, toolCount) };\n\t});\n}\n\nexport function registerSteeringInbox(\n\tpi: ExtensionAPI,\n\tdeps: { watch?: typeof fs.watch; nativeRealpath?: (filePath: string) => string } = {},\n): void {\n\tconst steerInbox = process.env[SUBAGENT_STEER_INBOX_ENV]?.trim();\n\tif (!steerInbox) return;\n\tconst capabilityPath = process.env[SUBAGENT_STEER_CAPABILITY_ENV]?.trim();\n\tconst ackDir = process.env[SUBAGENT_STEER_ACK_DIR_ENV]?.trim();\n\tconst sendUserMessage = (pi as { sendUserMessage?: (content: string, options: { deliverAs: \"steer\" }) => unknown }).sendUserMessage;\n\tconst childIndex = Number(process.env[SUBAGENT_CHILD_INDEX_ENV]);\n\tconst pending = new Map<string, string[]>();\n\tlet disposed = false;\n\tlet flushing = false;\n\tlet started = false;\n\tlet canSteer = typeof sendUserMessage === \"function\";\n\tlet watcher: fs.FSWatcher | undefined;\n\tlet interval: NodeJS.Timeout | undefined;\n\tconst acknowledge = (request: SteerRequest, state: \"delivered\" | \"failed\", message: string): void => {\n\t\tif (!ackDir || !Number.isInteger(childIndex) || childIndex < 0) return;\n\t\twriteSteerAckAt(steerAckPathFromDir(ackDir, request.id), {\n\t\t\trequestId: request.id,\n\t\t\tindex: childIndex,\n\t\t\tts: Date.now(),\n\t\t\tstate,\n\t\t\tmessage,\n\t\t});\n\t};\n\tlet readyAt = Number(process.env.PI_SUBAGENT_STEER_READY_AT);\n\tif (!Number.isFinite(readyAt) || readyAt <= 0) {\n\t\treadyAt = Date.now();\n\t\tprocess.env.PI_SUBAGENT_STEER_READY_AT = String(readyAt);\n\t}\n\tconst publishCapability = (): void => {\n\t\tif (!capabilityPath || !Number.isInteger(childIndex) || childIndex < 0) return;\n\t\twriteSteerCapabilityAt(capabilityPath, { index: childIndex, pid: process.pid, readyAt, supported: canSteer });\n\t};\n\tconst flush = (): void => {\n\t\tif (disposed || flushing) return;\n\t\tflushing = true;\n\t\ttry {\n\t\t\tconst requests = consumeSteerRequestsFromDir(steerInbox);\n\t\t\tfor (let index = 0; index < requests.length; index++) {\n\t\t\t\tconst request = requests[index]!;\n\t\t\t\tif (!canSteer || typeof sendUserMessage !== \"function\") {\n\t\t\t\t\tacknowledge(request, \"failed\", \"Child Pi session does not support sendUserMessage steering.\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (request.source === \"supervisor-question\" && !isPendingQuestionForCurrentChild(request.id)) {\n\t\t\t\t\tacknowledge(request, \"failed\", \"Question is no longer pending for this child.\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst formatted = request.source === \"supervisor-question\" ? request.message : formatSteerMessage(request);\n\t\t\t\tconst ids = pending.get(formatted) ?? [];\n\t\t\t\tids.push(request.id);\n\t\t\t\tpending.set(formatted, ids);\n\t\t\t\ttry {\n\t\t\t\t\tsendUserMessage(formatted, { deliverAs: \"steer\" });\n\t\t\t\t} catch (error) {\n\t\t\t\t\tids.pop();\n\t\t\t\t\tif (ids.length === 0) pending.delete(formatted);\n\t\t\t\t\tacknowledge(request, \"failed\", error instanceof Error ? error.message : String(error));\n\t\t\t\t\tfor (const retry of requests.slice(index + 1)) writeSteerRequestToDir(steerInbox, retry);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tflushing = false;\n\t\t}\n\t};\n\tconst onInput = (event: unknown): undefined => {\n\t\tif (disposed || !event || typeof event !== \"object\") return undefined;\n\t\tconst input = event as { source?: unknown; streamingBehavior?: unknown; text?: unknown; content?: unknown };\n\t\tif (input.source !== \"extension\" || input.streamingBehavior !== \"steer\") return undefined;\n\t\tconst text = typeof input.text === \"string\" ? input.text : typeof input.content === \"string\" ? input.content : undefined;\n\t\tif (!text) return undefined;\n\t\tconst ids = pending.get(text);\n\t\tconst requestId = ids?.shift();\n\t\tif (!requestId) return undefined;\n\t\tif (ids?.length === 0) pending.delete(text);\n\t\tacknowledge({ type: \"steer\", id: requestId, ts: Date.now(), message: text }, \"delivered\", \"Pi accepted the correlated steering input.\");\n\t\tmarkDeliveredSupervisorQuestionFromChild(text);\n\t\treturn undefined;\n\t};\n\tconst start = (): void => {\n\t\tif (started || disposed) return;\n\t\ttry {\n\t\t\tfs.mkdirSync(steerInbox, { recursive: true });\n\t\t\tpublishCapability();\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tstarted = true;\n\t\ttry {\n\t\t\twatcher = (deps.watch ?? fs.watch)(resolveWatchPath(steerInbox, deps.nativeRealpath), () => flush());\n\t\t\twatcher.on(\"error\", () => {});\n\t\t} catch {\n\t\t\twatcher = undefined;\n\t\t}\n\t\tinterval = setInterval(flush, 250);\n\t\tinterval.unref?.();\n\t};\n\tconst activate = (): undefined => {\n\t\tstart();\n\t\tflush();\n\t\treturn undefined;\n\t};\n\n\tconst onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;\n\t// Register input before the watcher so an accepted extension input cannot race request dispatch.\n\tonRuntimeEvent(\"input\", onInput);\n\tonRuntimeEvent(\"session_start\", () => start());\n\tfor (const eventName of [\"message_start\", \"message_update\", \"message_end\", \"tool_execution_start\", \"tool_execution_end\", \"turn_end\"] as const) {\n\t\tonRuntimeEvent(eventName, activate);\n\t}\n\tonRuntimeEvent(\"session_shutdown\", () => {\n\t\tdisposed = true;\n\t\ttry { watcher?.close(); } catch {}\n\t\tif (interval) clearInterval(interval);\n\t});\n}\n\nexport default function registerSubagentPromptRuntime(pi: ExtensionAPI): void {\n\tregisterSteeringInbox(pi);\n\tregisterToolBudget(pi, decodeToolBudgetEnv(process.env[TOOL_BUDGET_ENV]));\n\tregisterChildWatchdog(pi);\n\tconst waitToolEnabled = resolveWaitToolConfig().enabled;\n\tconst waitState = {\n\t\tbaseCwd: \"\",\n\t\tcurrentSessionId: null,\n\t\tasyncJobs: new Map(),\n\t\tforegroundControls: new Map(),\n\t\tlastForegroundControlId: null,\n\t\tcleanupTimers: new Map(),\n\t\tlastUiContext: null,\n\t\tpoller: null,\n\t\tcompletionSeen: new Map(),\n\t\twatcher: null,\n\t\twatcherRestartTimer: null,\n\t\tresultFileCoalescer: { schedule: () => false, clear: () => {} },\n\t} as unknown as SubagentState;\n\tif (typeof pi.registerTool === \"function\") registerWaitTool(pi, waitState, waitToolEnabled);\n\tlet nativeSupervisorClientRegistered = false;\n\tlet nativeSupervisorFallbackRegistered = false;\n\tconst registerNativeSupervisorClientOnce = (): void => {\n\t\tif (process.env.PI_SUBAGENT_COMMUNICATION_ENABLED === \"0\" || nativeSupervisorClientRegistered) return;\n\t\tnativeSupervisorClientRegistered = true;\n\t\tregisterNativeSupervisorClient(pi, { includeIntercomFallback: false });\n\t};\n\tconst registerNativeSupervisorFallbackOnce = (): void => {\n\t\tif (process.env.PI_SUBAGENT_COMMUNICATION_ENABLED === \"0\") return;\n\t\tregisterNativeSupervisorClientOnce();\n\t\tif (nativeSupervisorFallbackRegistered) return;\n\t\tnativeSupervisorFallbackRegistered = true;\n\t\tregisterNativeSupervisorClient(pi);\n\t};\n\tconst onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;\n\tonRuntimeEvent(\"session_start\", (_event: unknown, ctx: unknown) => {\n\t\tconst sessionManager = (ctx as { sessionManager?: Parameters<typeof resolveCurrentSessionId>[0] } | undefined)?.sessionManager;\n\t\twaitState.currentSessionId = sessionManager ? resolveCurrentSessionId(sessionManager) : null;\n\t\tregisterNativeSupervisorClientOnce();\n\t\trefreshChildToolDiagnostic(pi);\n\t});\n\tonRuntimeEvent(\"agent_end\", async (_event: unknown, ctx: unknown) => {\n\t\tif ((ctx as { hasUI?: boolean } | undefined)?.hasUI === true) return;\n\t\tawait drainOutstandingWork({ state: waitState, events: pi.events, hasPendingMessages: () => ctx.hasPendingMessages() });\n\t});\n\tconst structuredOutputPath = process.env[STRUCTURED_OUTPUT_CAPTURE_ENV];\n\tconst structuredSchemaPath = process.env[STRUCTURED_OUTPUT_SCHEMA_ENV];\n\tif (structuredOutputPath && structuredSchemaPath) {\n\t\tconst schema = JSON.parse(fs.readFileSync(structuredSchemaPath, \"utf-8\")) as JsonSchemaObject;\n\t\tconst parameters = {\n\t\t\ttype: \"object\",\n\t\t\tproperties: { value: schema },\n\t\t\trequired: [\"value\"],\n\t\t\tadditionalProperties: false,\n\t\t};\n\t\tconst registerTool = pi.registerTool as unknown as (tool: {\n\t\t\tname: string;\n\t\t\tlabel: string;\n\t\t\tdescription: string;\n\t\t\tparameters: unknown;\n\t\t\texecute: (_id: string, params: { value: unknown }) => Promise<unknown>;\n\t\t}) => void;\n\t\tregisterTool({\n\t\t\tname: \"structured_output\",\n\t\t\tlabel: \"Structured Output\",\n\t\t\tdescription: \"Submit the required final structured output for this subagent step. This terminates the step.\",\n\t\t\tparameters: parameters as never,\n\t\t\tasync execute(_id: string, params: { value: unknown }) {\n\t\t\t\tconst validation = validateStructuredOutputValue(schema, params.value);\n\t\t\t\tif (validation.status === \"invalid\") {\n\t\t\t\t\tthrow new Error(`Structured output validation failed: ${validation.message}`);\n\t\t\t\t}\n\t\t\t\tfs.mkdirSync(path.dirname(structuredOutputPath), { recursive: true });\n\t\t\t\tfs.writeFileSync(structuredOutputPath, JSON.stringify(params.value), { mode: 0o600 });\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: \"Structured output captured.\" }],\n\t\t\t\t\tdetails: { path: structuredOutputPath },\n\t\t\t\t\tterminate: true,\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t}\n\n\tonRuntimeEvent(\"context\", (event: { messages: unknown[] }) => {\n\t\tconst messages = stripParentOnlySubagentMessages(event.messages);\n\t\tif (messages === event.messages) return undefined;\n\t\treturn { messages };\n\t});\n\n\tonRuntimeEvent(\"before_agent_start\", async (event: { systemPrompt: string }) => {\n\t\tregisterNativeSupervisorFallbackOnce();\n\t\tconst toolDiagnostic = refreshChildToolDiagnostic(pi);\n\t\tconst intercomSessionName = process.env[SUBAGENT_INTERCOM_SESSION_NAME_ENV]?.trim();\n\t\tif (intercomSessionName && typeof pi.setSessionName === \"function\") {\n\t\t\tpi.setSessionName(intercomSessionName);\n\t\t}\n\n\t\tconst inheritProjectContext = readBooleanEnv(SUBAGENT_INHERIT_PROJECT_CONTEXT_ENV);\n\t\tconst inheritSkills = readBooleanEnv(SUBAGENT_INHERIT_SKILLS_ENV);\n\t\tconst fanoutChild = readBooleanEnv(SUBAGENT_FANOUT_CHILD_ENV);\n\t\tlet rewritten = event.systemPrompt;\n\t\tif (inheritProjectContext !== undefined || inheritSkills !== undefined || fanoutChild !== undefined) {\n\t\t\trewritten = rewriteSubagentPrompt(event.systemPrompt, {\n\t\t\t\tinheritProjectContext: inheritProjectContext ?? true,\n\t\t\t\tinheritSkills: inheritSkills ?? true,\n\t\t\t\tfanoutChild: fanoutChild === true,\n\t\t\t});\n\t\t}\n\t\tif (toolDiagnostic) {\n\t\t\trewritten = `${formatChildToolDiagnostic(toolDiagnostic)}\\nDo not claim tool-dependent work succeeded; report this configuration error to the parent.\\n\\n${rewritten}`;\n\t\t}\n\t\tif (rewritten === event.systemPrompt) return;\n\t\treturn { systemPrompt: rewritten };\n\t});\n}\n"]}
|
|
@@ -358,12 +358,14 @@ export default function registerSubagentPromptRuntime(pi) {
|
|
|
358
358
|
let nativeSupervisorClientRegistered = false;
|
|
359
359
|
let nativeSupervisorFallbackRegistered = false;
|
|
360
360
|
const registerNativeSupervisorClientOnce = () => {
|
|
361
|
-
if (nativeSupervisorClientRegistered)
|
|
361
|
+
if (process.env.PI_SUBAGENT_COMMUNICATION_ENABLED === "0" || nativeSupervisorClientRegistered)
|
|
362
362
|
return;
|
|
363
363
|
nativeSupervisorClientRegistered = true;
|
|
364
364
|
registerNativeSupervisorClient(pi, { includeIntercomFallback: false });
|
|
365
365
|
};
|
|
366
366
|
const registerNativeSupervisorFallbackOnce = () => {
|
|
367
|
+
if (process.env.PI_SUBAGENT_COMMUNICATION_ENABLED === "0")
|
|
368
|
+
return;
|
|
367
369
|
registerNativeSupervisorClientOnce();
|
|
368
370
|
if (nativeSupervisorFallbackRegistered)
|
|
369
371
|
return;
|