@ashx-j/lunr 0.2.21 → 0.2.23
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 +4 -2
- package/README.md +23 -5
- package/dist/builtin-extensions/index.d.ts.map +1 -1
- package/dist/builtin-extensions/index.js +1 -0
- package/dist/builtin-extensions/index.js.map +1 -1
- package/dist/builtin-extensions/lunr-browser.d.ts +9 -0
- package/dist/builtin-extensions/lunr-browser.d.ts.map +1 -0
- package/dist/builtin-extensions/lunr-browser.js +169 -0
- package/dist/builtin-extensions/lunr-browser.js.map +1 -0
- package/dist/builtin-extensions/lunr-todos.d.ts.map +1 -1
- package/dist/builtin-extensions/lunr-todos.js +15 -0
- package/dist/builtin-extensions/lunr-todos.js.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-intercom/index.js +3 -0
- package/dist/builtin-extensions/pi-intercom/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.d.ts +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.js +5 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/control-notices.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +2 -2
- package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js +18 -5
- package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +4 -3
- 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 +3 -0
- package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.d.ts +17 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.js +45 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/communication.js.map +1 -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 +4 -11
- 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 +4 -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 +160 -51
- package/dist/builtin-extensions/pi-subagents/src/intercom/native-supervisor-channel.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.js +5 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-ask.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.d.ts +2 -0
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.js +3 -2
- package/dist/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.js +2 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/auto-drain.js.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-wait.d.ts +3 -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 +11 -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/subagent-executor.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +4 -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/pi-args.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js +3 -0
- 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-control.d.ts +1 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.js +3 -0
- package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-control.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 +1 -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/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 +18 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.d.ts.map +1 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js +48 -0
- package/dist/builtin-extensions/pi-subagents/src/tui/communication.js.map +1 -0
- package/dist/builtin-extensions/pi-web-access/index.d.ts.map +1 -1
- package/dist/builtin-extensions/pi-web-access/index.js +11 -7
- package/dist/builtin-extensions/pi-web-access/index.js.map +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +2 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/install-cli.d.ts.map +1 -1
- package/dist/cli/install-cli.js +15 -45
- package/dist/cli/install-cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +9 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +126 -29
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +22 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +250 -105
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/browser/network.d.ts +9 -0
- package/dist/core/browser/network.d.ts.map +1 -0
- package/dist/core/browser/network.js +146 -0
- package/dist/core/browser/network.js.map +1 -0
- package/dist/core/browser/runtime.d.ts +24 -0
- package/dist/core/browser/runtime.d.ts.map +1 -0
- package/dist/core/browser/runtime.js +289 -0
- package/dist/core/browser/runtime.js.map +1 -0
- package/dist/core/browser/schema.d.ts +16 -0
- package/dist/core/browser/schema.d.ts.map +1 -0
- package/dist/core/browser/schema.js +36 -0
- package/dist/core/browser/schema.js.map +1 -0
- package/dist/core/browser/settings.d.ts +8 -0
- package/dist/core/browser/settings.d.ts.map +1 -0
- package/dist/core/browser/settings.js +30 -0
- package/dist/core/browser/settings.js.map +1 -0
- package/dist/core/browser/setup.d.ts +2 -0
- package/dist/core/browser/setup.d.ts.map +1 -0
- package/dist/core/browser/setup.js +16 -0
- package/dist/core/browser/setup.js.map +1 -0
- package/dist/core/customize.d.ts.map +1 -1
- package/dist/core/customize.js +15 -14
- package/dist/core/customize.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +1 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/install-features.d.ts.map +1 -1
- package/dist/core/install-features.js +10 -8
- package/dist/core/install-features.js.map +1 -1
- package/dist/core/memory-cap.d.ts.map +1 -1
- package/dist/core/memory-cap.js +5 -3
- package/dist/core/memory-cap.js.map +1 -1
- package/dist/core/model-tiers.d.ts.map +1 -1
- package/dist/core/model-tiers.js +9 -6
- package/dist/core/model-tiers.js.map +1 -1
- package/dist/core/permissions.d.ts.map +1 -1
- package/dist/core/permissions.js +9 -0
- package/dist/core/permissions.js.map +1 -1
- package/dist/core/plan-mode.d.ts.map +1 -1
- package/dist/core/plan-mode.js +3 -0
- package/dist/core/plan-mode.js.map +1 -1
- package/dist/core/process-registry.d.ts.map +1 -1
- package/dist/core/process-registry.js +6 -4
- package/dist/core/process-registry.js.map +1 -1
- package/dist/core/runtime-scope.d.ts +11 -0
- package/dist/core/runtime-scope.d.ts.map +1 -0
- package/dist/core/runtime-scope.js +3 -0
- package/dist/core/runtime-scope.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +13 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-handoff.d.ts +35 -0
- package/dist/core/session-handoff.d.ts.map +1 -0
- package/dist/core/session-handoff.js +214 -0
- package/dist/core/session-handoff.js.map +1 -0
- package/dist/core/session-manager.d.ts +20 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +184 -22
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-ownership.d.ts +28 -0
- package/dist/core/session-ownership.d.ts.map +1 -0
- package/dist/core/session-ownership.js +138 -0
- package/dist/core/session-ownership.js.map +1 -0
- package/dist/core/session-retention.d.ts.map +1 -1
- package/dist/core/session-retention.js +11 -2
- package/dist/core/session-retention.js.map +1 -1
- package/dist/core/settings-manager.d.ts +11 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +27 -0
- 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 +2 -0
- package/dist/core/slash-commands.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.map +1 -1
- package/dist/core/system-prompt.js +7 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/todo-settings.d.ts +5 -0
- package/dist/core/todo-settings.d.ts.map +1 -0
- package/dist/core/todo-settings.js +7 -0
- package/dist/core/todo-settings.js.map +1 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +4 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +5 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +4 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +4 -4
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +4 -4
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +4 -4
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +14 -5
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +34 -7
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +4 -4
- package/dist/core/tools/write.js.map +1 -1
- package/dist/core/usage-service.d.ts.map +1 -1
- package/dist/core/usage-service.js +5 -3
- package/dist/core/usage-service.js.map +1 -1
- package/dist/gateway/adapters/discord.d.ts +12 -1
- package/dist/gateway/adapters/discord.d.ts.map +1 -1
- package/dist/gateway/adapters/discord.js +112 -17
- package/dist/gateway/adapters/discord.js.map +1 -1
- package/dist/gateway/adapters/telegram.d.ts +4 -2
- package/dist/gateway/adapters/telegram.d.ts.map +1 -1
- package/dist/gateway/adapters/telegram.js +34 -11
- package/dist/gateway/adapters/telegram.js.map +1 -1
- package/dist/gateway/agent-bridge.d.ts +14 -3
- package/dist/gateway/agent-bridge.d.ts.map +1 -1
- package/dist/gateway/agent-bridge.js +252 -60
- package/dist/gateway/agent-bridge.js.map +1 -1
- package/dist/gateway/approval.d.ts +1 -0
- package/dist/gateway/approval.d.ts.map +1 -1
- package/dist/gateway/approval.js +60 -18
- package/dist/gateway/approval.js.map +1 -1
- package/dist/gateway/authz.d.ts +2 -0
- package/dist/gateway/authz.d.ts.map +1 -1
- package/dist/gateway/authz.js +13 -0
- package/dist/gateway/authz.js.map +1 -1
- package/dist/gateway/buttons.d.ts +3 -1
- package/dist/gateway/buttons.d.ts.map +1 -1
- package/dist/gateway/buttons.js +18 -3
- package/dist/gateway/buttons.js.map +1 -1
- package/dist/gateway/command.d.ts.map +1 -1
- package/dist/gateway/command.js +49 -4
- package/dist/gateway/command.js.map +1 -1
- package/dist/gateway/commands.d.ts.map +1 -1
- package/dist/gateway/commands.js +18 -3
- package/dist/gateway/commands.js.map +1 -1
- package/dist/gateway/config.d.ts +5 -0
- package/dist/gateway/config.d.ts.map +1 -1
- package/dist/gateway/config.js +5 -0
- package/dist/gateway/config.js.map +1 -1
- package/dist/gateway/conversations.d.ts +14 -0
- package/dist/gateway/conversations.d.ts.map +1 -0
- package/dist/gateway/conversations.js +30 -0
- package/dist/gateway/conversations.js.map +1 -0
- package/dist/gateway/download.d.ts +2 -0
- package/dist/gateway/download.d.ts.map +1 -0
- package/dist/gateway/download.js +36 -0
- package/dist/gateway/download.js.map +1 -0
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js +85 -26
- package/dist/gateway/index.js.map +1 -1
- package/dist/gateway/mobile-commands.d.ts +24 -0
- package/dist/gateway/mobile-commands.d.ts.map +1 -0
- package/dist/gateway/mobile-commands.js +422 -0
- package/dist/gateway/mobile-commands.js.map +1 -0
- package/dist/gateway/presenter.d.ts +16 -0
- package/dist/gateway/presenter.d.ts.map +1 -0
- package/dist/gateway/presenter.js +210 -0
- package/dist/gateway/presenter.js.map +1 -0
- package/dist/gateway/router.d.ts +1 -0
- package/dist/gateway/router.d.ts.map +1 -1
- package/dist/gateway/router.js +32 -3
- package/dist/gateway/router.js.map +1 -1
- package/dist/gateway/service.d.ts +46 -0
- package/dist/gateway/service.d.ts.map +1 -0
- package/dist/gateway/service.js +395 -0
- package/dist/gateway/service.js.map +1 -0
- package/dist/gateway/setup.d.ts +4 -0
- package/dist/gateway/setup.d.ts.map +1 -0
- package/dist/gateway/setup.js +146 -0
- package/dist/gateway/setup.js.map +1 -0
- package/dist/gateway/types.d.ts +4 -2
- package/dist/gateway/types.d.ts.map +1 -1
- package/dist/gateway/types.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +78 -17
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/copyable-text.d.ts +27 -0
- package/dist/modes/interactive/components/copyable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/copyable-text.js +156 -0
- package/dist/modes/interactive/components/copyable-text.js.map +1 -0
- package/dist/modes/interactive/components/custom-entry.d.ts +1 -0
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +8 -0
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +8 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +16 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +8 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +51 -0
- 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 +4 -3
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +34 -45
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +9 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +267 -44
- 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-GZVSOGYR.js +49 -0
- package/dist/node-runtime/{builtin-extensions-JCOPAAB5.js → builtin-extensions-QVCXNQT4.js} +6 -5
- package/dist/node-runtime/{chunk-LTYWTR3V.js → chunk-2MI5OPMN.js} +17 -2
- package/dist/node-runtime/{chunk-W3CVH5RX.js → chunk-2TKODGBZ.js} +11 -6
- package/dist/node-runtime/chunk-4EULYYR4.js +62 -0
- package/dist/node-runtime/{chunk-6N22HULO.js → chunk-5D7LC2ZQ.js} +7 -2
- package/dist/node-runtime/{chunk-KBKMCJDU.js → chunk-5ZQXRPMC.js} +19 -4
- package/dist/node-runtime/{chunk-BOHIDQT4.js → chunk-6VYZ5UFP.js} +1 -1
- package/dist/node-runtime/chunk-AZJHNQKQ.js +205 -0
- package/dist/node-runtime/{chunk-A3KMVBZV.js → chunk-BBUVIEZB.js} +1 -10
- package/dist/node-runtime/{chunk-IRPJXI6U.js → chunk-BX2RB477.js} +1 -1
- package/dist/node-runtime/chunk-CCCN2UCX.js +14 -0
- package/dist/node-runtime/{chunk-25I2BHAA.js → chunk-CSUZVNYE.js} +1 -1
- package/dist/node-runtime/chunk-DD5YWFSJ.js +708 -0
- package/dist/node-runtime/chunk-DQMGU675.js +3409 -0
- package/dist/node-runtime/{chunk-QZMODZQ2.js → chunk-E24EO34J.js} +2 -1
- package/dist/node-runtime/chunk-EKVFP6YF.js +355 -0
- package/dist/node-runtime/chunk-GJ2RDBRL.js +672 -0
- package/dist/node-runtime/{chunk-W3SILANP.js → chunk-GMHJCCEN.js} +8 -8
- package/dist/node-runtime/{chunk-DDWHZ633.js → chunk-GS42T6MX.js} +1 -1
- package/dist/node-runtime/chunk-GS66LV4M.js +2830 -0
- package/dist/node-runtime/chunk-H4K3JDRB.js +47 -0
- package/dist/node-runtime/{chunk-2SJB2AWP.js → chunk-HMBGROQK.js} +3 -3
- package/dist/node-runtime/{chunk-GB2MGFLI.js → chunk-HPUP7E4T.js} +216 -201
- package/dist/node-runtime/{chunk-YMEAYRBE.js → chunk-HTFRRDSF.js} +2 -7
- package/dist/node-runtime/{chunk-OPEK5RRY.js → chunk-IF24A3FH.js} +1 -1
- package/dist/node-runtime/chunk-IMLCWLPI.js +9 -0
- package/dist/node-runtime/chunk-KKUTQQV7.js +144 -0
- package/dist/node-runtime/chunk-LFZDVKSP.js +521 -0
- package/dist/node-runtime/{chunk-2BUAYZ7K.js → chunk-LLUIPGDR.js} +581 -197
- package/dist/node-runtime/{chunk-7NBZ5P7I.js → chunk-NAY6UUQZ.js} +1 -1
- package/dist/node-runtime/chunk-OAR4TYZE.js +146 -0
- package/dist/node-runtime/{chunk-STERBGUB.js → chunk-OFKSVRV7.js} +2 -2
- package/dist/node-runtime/{chunk-JZQ7F36T.js → chunk-PCEW76PM.js} +19 -3
- package/dist/node-runtime/{chunk-WLLDXJRT.js → chunk-QAZOULTU.js} +29 -1014
- package/dist/node-runtime/{chunk-6KDIOJL3.js → chunk-QH6YL7VK.js} +3 -3
- package/dist/node-runtime/chunk-R3K2F5GI.js +122 -0
- package/dist/node-runtime/{chunk-RNBHABBA.js → chunk-RDDAZOMU.js} +23 -0
- package/dist/node-runtime/{chunk-SY2TFMLO.js → chunk-RIR5EDDJ.js} +46 -151
- package/dist/node-runtime/chunk-RMQZU2YU.js +117 -0
- package/dist/node-runtime/{chunk-6BEIBLQ3.js → chunk-RWTKOC3B.js} +1 -1
- package/dist/node-runtime/{chunk-G6LRAP36.js → chunk-TQGPP4SC.js} +1 -1
- package/dist/node-runtime/{chunk-Y5KOEMBH.js → chunk-TVJUOJZJ.js} +9 -674
- package/dist/node-runtime/chunk-UAEOTO52.js +119 -0
- package/dist/node-runtime/{chunk-AY6CAJSL.js → chunk-UJOCPOMX.js} +6 -3
- package/dist/node-runtime/chunk-UP2XBVH5.js +40 -0
- package/dist/node-runtime/{chunk-WJVFOIB5.js → chunk-UQUCFAJ3.js} +1 -1
- package/dist/node-runtime/chunk-URD2SLIT.js +1019 -0
- package/dist/node-runtime/chunk-US544NN6.js +13 -0
- package/dist/node-runtime/chunk-UWPJL22I.js +341 -0
- package/dist/node-runtime/{chunk-4I23VTC4.js → chunk-VWCE2HSZ.js} +21 -124
- package/dist/node-runtime/{chunk-VZR3NCM7.js → chunk-W64JC4E7.js} +18 -14
- package/dist/node-runtime/{chunk-AWVD5IEY.js → chunk-X3URCYCU.js} +23 -12
- package/dist/node-runtime/{chunk-GKLEQ3I4.js → chunk-XLTL257W.js} +126 -27
- package/dist/node-runtime/{chunk-WKDK4C5P.js → chunk-YDO2F2IA.js} +38 -164
- package/dist/node-runtime/{chunk-PDNXVXMD.js → chunk-YHQ3NBB3.js} +58 -48
- package/dist/node-runtime/chunk-YPHAIRZT.js +10 -0
- package/dist/node-runtime/cli-runtime.js +2 -2
- package/dist/node-runtime/command-PDVTBRWA.js +45 -0
- package/dist/node-runtime/{commands-MV5KOZ64.js → commands-KAMO2T6P.js} +10 -10
- package/dist/node-runtime/commands-XDCFGIGW.js +36 -0
- package/dist/node-runtime/config-RORQUQFG.js +20 -0
- package/dist/node-runtime/{customize-LF5VST47.js → customize-VFJV3U6A.js} +2 -1
- package/dist/node-runtime/{direct-tool-executor-BK7CLEBX.js → direct-tool-executor-YAVOLDFY.js} +8 -8
- package/dist/node-runtime/{export-html-TEXVV5RP.js → export-html-KSOIMVPI.js} +4 -3
- package/dist/node-runtime/{extension-input-O4HSAEM4.js → extension-input-E7BJZ35H.js} +4 -4
- package/dist/node-runtime/{extension-selector-X5FCX43D.js → extension-selector-WU42XDTU.js} +4 -4
- package/dist/node-runtime/{extract-XLQSJN4V.js → extract-EQJE7FZZ.js} +2 -2
- package/dist/node-runtime/{gateway-BM6NLOH4.js → gateway-AYWM5DIO.js} +275 -994
- package/dist/node-runtime/{gemini-search-U7SUMPQA.js → gemini-search-35OCRFLN.js} +1 -1
- package/dist/node-runtime/{gemini-url-context-PXWCBQHK.js → gemini-url-context-UQY3PHHW.js} +2 -2
- package/dist/node-runtime/index.js +104 -65
- package/dist/node-runtime/{init-3C7Z24OI.js → init-X2LIUB2H.js} +3 -3
- package/dist/node-runtime/{install-cli-EXMJQESX.js → install-cli-3BO4MMQ6.js} +21 -82
- package/dist/node-runtime/interactive-mode-4MFRKAHG.js +72 -0
- package/dist/node-runtime/{interactive-view-ILS6TAN5.js → interactive-view-TUZHCQM3.js} +8 -8
- package/dist/node-runtime/lunr-browser-RYFIIVJN.js +174 -0
- package/dist/node-runtime/{lunr-cron-4VHP4E4B.js → lunr-cron-YWXEPZMQ.js} +19 -5
- package/dist/node-runtime/main.js +44 -31
- package/dist/node-runtime/{memory-cap-3S4XRLNP.js → memory-cap-EL3KL4JJ.js} +2 -1
- package/dist/node-runtime/mobile-commands-LVHDAUDP.js +32 -0
- package/dist/node-runtime/model-runtime-PLQKAG4B.js +16 -0
- package/dist/node-runtime/{model-tiers-NJLHUEGK.js → model-tiers-OU3U5CZG.js} +2 -1
- package/dist/node-runtime/{package-manager-cli-N37546V5.js → package-manager-cli-6GT3Z3CK.js} +22 -15
- package/dist/node-runtime/{pi-intercom-NV2LW6X7.js → pi-intercom-HBPK5HSJ.js} +4 -1
- package/dist/node-runtime/{pi-mcp-adapter-GUFZWW54.js → pi-mcp-adapter-E6WULBKF.js} +4 -4
- package/dist/node-runtime/{pi-subagents-6MUIFNDM.js → pi-subagents-CDWK2AKY.js} +236 -79
- package/dist/node-runtime/{pi-web-access-2CQGFLT2.js → pi-web-access-WTGMNZ32.js} +15 -15
- package/dist/node-runtime/process-registry-4FAKZQOL.js +31 -0
- package/dist/node-runtime/{proxy-modes-V6YVFH3C.js → proxy-modes-OSQCWRBI.js} +9 -9
- package/dist/node-runtime/rpc-entry.js +44 -31
- package/dist/node-runtime/{rpc-mode-W5ZTLTMZ.js → rpc-mode-O3XV4SID.js} +2 -2
- package/dist/node-runtime/runtime-4VA6JKNF.js +373 -0
- package/dist/node-runtime/{runtime-bridges-2VQTLPOZ.js → runtime-bridges-3XUQ46XW.js} +6 -5
- package/dist/node-runtime/service-ISSP6VHE.js +36 -0
- package/dist/node-runtime/session-handoff-HC7R5E24.js +33 -0
- package/dist/node-runtime/{session-manager-E7AREDTV.js → session-manager-CFN4UFM2.js} +2 -1
- package/dist/node-runtime/{session-selector-FJ7M2AIX.js → session-selector-GIM4DHQ2.js} +5 -4
- package/dist/node-runtime/{settings-manager-CUGAZWAB.js → settings-manager-6VEMXRDL.js} +7 -2
- package/dist/node-runtime/setup-5SR2J35A.js +155 -0
- package/dist/node-runtime/setup-JBKOLJ6F.js +18 -0
- package/dist/node-runtime/{subagent-executor-MH4A7CCF.js → subagent-executor-M5VWB3D3.js} +26 -18
- package/dist/node-runtime/theme-UOO5RVFN.js +68 -0
- package/dist/node-runtime/trust-manager-MMISNCYO.js +17 -0
- package/dist/node-runtime/{update-cli-XTZMZGOL.js → update-cli-UVKJWRRJ.js} +7 -2
- package/dist/node-runtime/usage-service-LFB2SWYV.js +37 -0
- package/dist/node-runtime/{video-extract-OYT5WKS5.js → video-extract-OOZHR7SU.js} +2 -2
- package/dist/node-runtime/{youtube-extract-TQYKGFGS.js → youtube-extract-FNPAUNHU.js} +6 -6
- package/docs/browser.md +86 -0
- package/docs/extensions.md +2 -0
- package/docs/features.md +96 -16
- package/docs/interactive-startup.md +2 -1
- package/docs/sessions.md +10 -0
- package/docs/settings.md +2 -0
- package/docs/tui.md +2 -0
- package/docs/usage.md +16 -0
- 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/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 +7 -4
- package/scripts/install-browser.mjs +20 -0
- package/dist/node-runtime/agent-session-services-C743TYQE.js +0 -37
- package/dist/node-runtime/chunk-VGYZ3APQ.js +0 -59
- package/dist/node-runtime/chunk-XI77KVKA.js +0 -6009
- package/dist/node-runtime/command-P4NYCJ2M.js +0 -13
- package/dist/node-runtime/interactive-mode-EVVBA64D.js +0 -59
- package/dist/node-runtime/{chunk-UWQYRSYQ.js → chunk-YJMMG7C6.js} +25 -25
- package/dist/node-runtime/{mcp-panel-IIGMXQGP.js → mcp-panel-KTTFXJZ4.js} +3 -3
- package/dist/node-runtime/{src-BPQFJR76.js → src-IVPNZ2BX.js} +9 -9
|
@@ -9,6 +9,7 @@ export interface SupervisorChildIncarnation {
|
|
|
9
9
|
}
|
|
10
10
|
export interface SupervisorQuestion {
|
|
11
11
|
type: "subagent.supervisor.question";
|
|
12
|
+
childDescription?: string;
|
|
12
13
|
id: string;
|
|
13
14
|
createdAt: number;
|
|
14
15
|
expiresAt: number;
|
|
@@ -45,6 +46,7 @@ export declare function readSupervisorQuestion(channelDir: string, questionId: s
|
|
|
45
46
|
export declare function listSupervisorQuestions(channelDir: string): SupervisorQuestion[];
|
|
46
47
|
export declare function createSupervisorQuestion(input: {
|
|
47
48
|
channelDir: string;
|
|
49
|
+
childDescription?: string;
|
|
48
50
|
reason: string;
|
|
49
51
|
message: string;
|
|
50
52
|
runId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor-questions.d.ts","sourceRoot":"","sources":["../../../../../src/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,uBAAuB,QAAkD,CAAC;AACvF,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAC5E,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;AAE7F,MAAM,WAAW,0BAA0B;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,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M,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,kBAAkB,CAAA;CAAE,GAAG,SAAS,CAQ3H;AAED,wBAAgB,wCAAwC,CAAC,KAAK,EAAE;IAC/D,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,kBAAkB,EAAE,CAevB;AAED,wBAAgB,qCAAqC,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,uBAAuB,EAAE,GAAG,SAAa,GAAG,kBAAkB,EAAE,CAShJ","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { TEMP_ROOT_DIR } from \"../shared/types.ts\";\n\nexport const QUESTIONS_DIR = \"questions\";\nexport const SUPERVISOR_CHANNEL_ROOT = path.join(TEMP_ROOT_DIR, \"supervisor-channels\");\nexport const SUBAGENT_SUPERVISOR_ANSWER_TYPE = \"subagent_supervisor_answer\";\nexport const SUBAGENT_QUESTION_EVENT = \"subagent:supervisor-question\";\n\nexport type SupervisorQuestionPublicState = \"pending\" | \"answered\" | \"expired\" | \"cancelled\";\n\nexport interface SupervisorChildIncarnation {\n\tpid: number;\n\treadyAt: number;\n}\n\nexport interface SupervisorQuestion {\n\ttype: \"subagent.supervisor.question\";\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tdeliveredAt?: number;\n\tansweredAt?: number;\n\texpiredAt?: number;\n\tcancelledAt?: number;\n\tcancelReason?: string;\n\tnotifiedAt?: number;\n\tlateAnswerAt?: number;\n\tanswer?: string;\n}\n\nexport interface SupervisorQuestionOwner {\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tpid: number;\n\treadyAt: number;\n}\n\ninterface QuestionRecord {\n\ttype: \"subagent.supervisor.question\";\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n}\n\ninterface DeliveredRecord {\n\ttype: \"subagent.supervisor.delivered\";\n\tid: string;\n\tat: number;\n\tpid: number;\n\treadyAt: number;\n}\n\ntype TerminalRecord =\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"answered\"; at: number; message: string }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"expired\"; at: number }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"cancelled\"; at: number; reason: string };\n\ninterface NotifiedRecord {\n\ttype: \"subagent.supervisor.notified\";\n\tid: string;\n\tat: number;\n}\n\ninterface LateAnswerRecord {\n\ttype: \"subagent.supervisor.late-answer\";\n\tid: string;\n\tat: number;\n\tmessage: string;\n}\n\nconst MAX_MESSAGE_BYTES = 64 * 1024;\nconst DEFAULT_ASK_TIMEOUT_MS = 10 * 60 * 1000;\nconst activeQuestionWaits = new Set<string>();\n\nfunction askTimeoutMs(): number {\n\tconst parsed = Number(process.env.PI_INTERCOM_ASK_TIMEOUT_MS);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_ASK_TIMEOUT_MS;\n}\n\nfunction safeSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nexport function resolveSupervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(SUPERVISOR_CHANNEL_ROOT, `${safeSegment(runId)}-${safeSegment(agent)}-${childIndex}`);\n}\n\nexport function questionsDir(channelDir: string): string {\n\treturn path.join(channelDir, QUESTIONS_DIR);\n}\n\nfunction questionFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.json`);\n}\n\nfunction deliveredFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.delivered.json`);\n}\n\nfunction terminalFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.terminal.json`);\n}\n\nfunction notifiedFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.notified.json`);\n}\n\nfunction lateFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.late.json`);\n}\n\nfunction writeExclusiveJson(filePath: string, payload: object): boolean {\n\tfs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });\n\tconst temporary = `${filePath}.${randomUUID()}.tmp`;\n\ttry {\n\t\tfs.writeFileSync(temporary, JSON.stringify(payload), { encoding: \"utf-8\", flag: \"wx\", mode: 0o600 });\n\t\t// Publish a complete record without overwriting a competing terminal outcome.\n\t\tfs.linkSync(temporary, filePath);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n\t\tthrow error;\n\t} finally {\n\t\tfs.rmSync(temporary, { force: true });\n\t}\n}\n\nfunction readJsonFile(filePath: string): unknown {\n\treturn JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n}\n\nfunction tryReadJson(filePath: string): unknown | undefined {\n\ttry {\n\t\treturn readJsonFile(filePath);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\treturn undefined;\n\t}\n}\n\nfunction parseIncarnation(raw: unknown): SupervisorChildIncarnation | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<SupervisorChildIncarnation>;\n\tconst pid = input.pid;\n\tconst readyAt = input.readyAt;\n\tif (!Number.isInteger(pid) || pid === undefined || pid <= 0) return undefined;\n\tif (typeof readyAt !== \"number\" || !Number.isFinite(readyAt) || readyAt <= 0) return undefined;\n\treturn { pid, readyAt };\n}\n\nfunction parseQuestionRecord(raw: unknown): QuestionRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<QuestionRecord>;\n\tif (input.type !== \"subagent.supervisor.question\") return undefined;\n\tif (typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.createdAt !== \"number\" || !Number.isFinite(input.createdAt)) return undefined;\n\tif (typeof input.expiresAt !== \"number\" || !Number.isFinite(input.expiresAt)) return undefined;\n\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\tif (typeof input.runId !== \"string\" || !input.runId.trim()) return undefined;\n\tconst childIndex = input.childIndex;\n\tif (!Number.isInteger(childIndex) || childIndex === undefined || childIndex < 0) return undefined;\n\tif (typeof input.childId !== \"string\" || !input.childId.trim()) return undefined;\n\tif (typeof input.parentSessionId !== \"string\" || !input.parentSessionId.trim()) return undefined;\n\tconst parentGeneration = input.parentGeneration;\n\tif (!Number.isInteger(parentGeneration) || parentGeneration === undefined || parentGeneration < 0) return undefined;\n\tconst incarnation = parseIncarnation(input.childIncarnation);\n\treturn {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id.trim(),\n\t\tcreatedAt: input.createdAt,\n\t\texpiresAt: input.expiresAt,\n\t\treason: input.reason.trim(),\n\t\tmessage: input.message.trim(),\n\t\trunId: input.runId.trim(),\n\t\tchildIndex,\n\t\tchildId: input.childId.trim(),\n\t\tparentSessionId: input.parentSessionId.trim(),\n\t\tparentGeneration,\n\t\t...(incarnation ? { childIncarnation: incarnation } : {}),\n\t};\n}\n\nfunction parseDeliveredRecord(raw: unknown): DeliveredRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<DeliveredRecord>;\n\tif (input.type !== \"subagent.supervisor.delivered\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tconst incarnation = parseIncarnation(input);\n\tif (!incarnation) return undefined;\n\treturn { type: \"subagent.supervisor.delivered\", id: input.id.trim(), at: input.at, pid: incarnation.pid, readyAt: incarnation.readyAt };\n}\n\nfunction parseTerminalRecord(raw: unknown): TerminalRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<TerminalRecord> & { message?: unknown; reason?: unknown };\n\tif (input.type !== \"subagent.supervisor.terminal\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tif (input.state === \"answered\") {\n\t\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"answered\", at: input.at, message: input.message };\n\t}\n\tif (input.state === \"expired\") {\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"expired\", at: input.at };\n\t}\n\tif (input.state === \"cancelled\") {\n\t\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"cancelled\", at: input.at, reason: input.reason.trim() };\n\t}\n\treturn undefined;\n}\n\nfunction parseNotifiedRecord(raw: unknown): NotifiedRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<NotifiedRecord>;\n\tif (input.type !== \"subagent.supervisor.notified\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\treturn { type: \"subagent.supervisor.notified\", id: input.id.trim(), at: input.at };\n}\n\nfunction parseLateRecord(raw: unknown): LateAnswerRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<LateAnswerRecord>;\n\tif (input.type !== \"subagent.supervisor.late-answer\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at) || typeof input.message !== \"string\") return undefined;\n\treturn { type: \"subagent.supervisor.late-answer\", id: input.id.trim(), at: input.at, message: input.message };\n}\n\nfunction composeQuestion(record: QuestionRecord, channelDir: string): SupervisorQuestion {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, record.id)));\n\tconst terminal = parseTerminalRecord(tryReadJson(terminalFile(channelDir, record.id)));\n\tconst notified = parseNotifiedRecord(tryReadJson(notifiedFile(channelDir, record.id)));\n\tconst late = parseLateRecord(tryReadJson(lateFile(channelDir, record.id)));\n\treturn {\n\t\t...record,\n\t\t...(delivered ? { deliveredAt: delivered.at, childIncarnation: record.childIncarnation ?? { pid: delivered.pid, readyAt: delivered.readyAt } } : {}),\n\t\t...(terminal?.state === \"answered\" ? { answeredAt: terminal.at, answer: terminal.message } : {}),\n\t\t...(terminal?.state === \"expired\" ? { expiredAt: terminal.at } : {}),\n\t\t...(terminal?.state === \"cancelled\" ? { cancelledAt: terminal.at, cancelReason: terminal.reason } : {}),\n\t\t...(notified ? { notifiedAt: notified.at } : {}),\n\t\t...(late ? { lateAnswerAt: late.at, ...(terminal?.state === \"answered\" ? {} : { answer: late.message }) } : {}),\n\t};\n}\n\nfunction assertMessageSize(value: string, label: string): void {\n\tif (Buffer.byteLength(value, \"utf-8\") > MAX_MESSAGE_BYTES) throw new Error(`${label} is too large.`);\n}\n\nexport function ensureQuestionsDir(channelDir: string): void {\n\tfs.mkdirSync(questionsDir(channelDir), { recursive: true, mode: 0o700 });\n}\n\nexport function supervisorQuestionPublicState(question: SupervisorQuestion): SupervisorQuestionPublicState {\n\tif (question.answeredAt) return \"answered\";\n\tif (question.expiredAt) return \"expired\";\n\tif (question.cancelledAt) return \"cancelled\";\n\treturn \"pending\";\n}\n\nexport function supervisorQuestionIsTerminal(question: SupervisorQuestion): boolean {\n\treturn supervisorQuestionPublicState(question) !== \"pending\";\n}\n\nexport function readSupervisorQuestion(channelDir: string, questionId: string): SupervisorQuestion | undefined {\n\tconst record = parseQuestionRecord(tryReadJson(questionFile(channelDir, questionId)));\n\tif (!record || record.id !== questionId) return undefined;\n\treturn composeQuestion(record, channelDir);\n}\n\nexport function listSupervisorQuestions(channelDir: string): SupervisorQuestion[] {\n\tconst dir = questionsDir(channelDir);\n\tlet entries: string[];\n\ttry {\n\t\tentries = fs.readdirSync(dir).filter((name) => name.endsWith(\".json\") && !name.endsWith(\".delivered.json\") && !name.endsWith(\".terminal.json\") && !name.endsWith(\".notified.json\") && !name.endsWith(\".late.json\"));\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\tconst questions: SupervisorQuestion[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tconst record = parseQuestionRecord(tryReadJson(path.join(dir, entry)));\n\t\tif (record) questions.push(composeQuestion(record, channelDir));\n\t}\n\treturn questions;\n}\n\nfunction writeTerminal(channelDir: string, record: TerminalRecord): boolean {\n\treturn writeExclusiveJson(terminalFile(channelDir, record.id), record);\n}\n\nfunction readTerminal(channelDir: string, questionId: string): TerminalRecord | undefined {\n\treturn parseTerminalRecord(tryReadJson(terminalFile(channelDir, questionId)));\n}\n\nexport function createSupervisorQuestion(input: {\n\tchannelDir: string;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tnow?: number;\n\ttimeoutMs?: number;\n\tid?: string;\n}): SupervisorQuestion {\n\tconst reason = input.reason.trim();\n\tconst message = input.message.trim();\n\tif (!reason) throw new Error(\"reason is required and must name the concrete decision the child's answer will change.\");\n\tif (!message) throw new Error(\"message is required for supervisor questions.\");\n\tassertMessageSize(reason, \"reason\");\n\tassertMessageSize(message, \"message\");\n\tconst createdAt = input.now ?? Date.now();\n\tconst timeoutMs = input.timeoutMs && input.timeoutMs > 0 ? input.timeoutMs : askTimeoutMs();\n\tconst record: QuestionRecord = {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id ?? randomUUID(),\n\t\tcreatedAt,\n\t\texpiresAt: createdAt + timeoutMs,\n\t\treason,\n\t\tmessage,\n\t\trunId: input.runId,\n\t\tchildIndex: input.childIndex,\n\t\tchildId: input.childId,\n\t\tparentSessionId: input.parentSessionId,\n\t\tparentGeneration: input.parentGeneration,\n\t\t...(input.childIncarnation ? { childIncarnation: input.childIncarnation } : {}),\n\t};\n\tassertMessageSize(JSON.stringify(record), \"Supervisor question\");\n\tensureQuestionsDir(input.channelDir);\n\tif (!writeExclusiveJson(questionFile(input.channelDir, record.id), record)) {\n\t\tthrow new Error(`Supervisor question '${record.id}' already exists.`);\n\t}\n\treturn composeQuestion(record, input.channelDir);\n}\n\nexport function outstandingQuestionsForChild(channelDir: string, childIndex: number, childId?: string): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.childIndex !== childIndex) return false;\n\t\tif (childId && question.childId !== childId) return false;\n\t\treturn true;\n\t});\n}\n\nexport function hasBlockingSupervisorRequest(channelDir: string, runId: string, childIndex: number): boolean {\n\tconst directory = path.join(channelDir, \"requests\");\n\tif (!fs.existsSync(directory)) return false;\n\tfor (const name of fs.readdirSync(directory)) {\n\t\tif (!name.endsWith(\".json\")) continue;\n\t\tconst raw = tryReadJson(path.join(directory, name));\n\t\tif (!raw || typeof raw !== \"object\") continue;\n\t\tconst request = raw as { type?: unknown; id?: unknown; expectsReply?: unknown; runId?: unknown; childIndex?: unknown; expiresAt?: unknown };\n\t\tif (request.type !== \"subagent.supervisor.request\" || request.expectsReply !== true) continue;\n\t\tif (request.runId !== runId || request.childIndex !== childIndex || typeof request.id !== \"string\") continue;\n\t\tif (typeof request.expiresAt === \"number\" && request.expiresAt <= Date.now()) continue;\n\t\tif (!fs.existsSync(path.join(channelDir, \"replies\", `${safeSegment(request.id)}.json`))) return true;\n\t}\n\treturn false;\n}\n\nexport function hasOutstandingQuestionForChild(channelDir: string, childIndex: number, childId?: string): boolean {\n\treturn outstandingQuestionsForChild(channelDir, childIndex, childId).length > 0;\n}\n\nexport function incarnationMatches(expected: SupervisorChildIncarnation | undefined, actual: SupervisorChildIncarnation): boolean {\n\tif (!expected) return true;\n\treturn expected.pid === actual.pid && expected.readyAt === actual.readyAt;\n}\n\nfunction assertOwner(question: SupervisorQuestion, owner: SupervisorQuestionOwner): void {\n\tif (owner.runId !== question.runId || owner.childIndex !== question.childIndex || owner.childId !== question.childId) {\n\t\tthrow new Error(`Supervisor question '${question.id}' is not owned by this child.`);\n\t}\n\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) {\n\t\tthrow new Error(`Supervisor question '${question.id}' was bound to a different child incarnation.`);\n\t}\n}\n\nfunction ownerMatchesDelivered(channelDir: string, questionId: string, owner: SupervisorQuestionOwner): boolean {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, questionId)));\n\tif (!delivered) return true;\n\treturn delivered.pid === owner.pid && delivered.readyAt === owner.readyAt;\n}\n\nexport function markSupervisorQuestionDelivered(\n\tchannelDir: string,\n\tquestionId: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tassertOwner(current, owner);\n\twriteExclusiveJson(deliveredFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.delivered\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tpid: owner.pid,\n\t\treadyAt: owner.readyAt,\n\t} satisfies DeliveredRecord);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nfunction rejectLateOrDuplicate(channelDir: string, questionId: string, answer: string, now: number, terminal: TerminalRecord): never {\n\twriteExclusiveJson(lateFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.late-answer\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tmessage: answer,\n\t} satisfies LateAnswerRecord);\n\tif (terminal.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\tthrow new Error(`Supervisor question '${questionId}' is ${terminal.state} and no longer accepts an answer.`);\n}\n\nexport function answerSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\tanswer: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion {\n\tconst trimmed = answer.trim();\n\tif (!trimmed) throw new Error(\"message is required for supervisor question replies.\");\n\tassertMessageSize(trimmed, \"answer\");\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current) throw new Error(`No supervisor question found for replyTo '${questionId}'.`);\n\tassertOwner(current, owner);\n\tif (!ownerMatchesDelivered(channelDir, questionId, owner)) {\n\t\tthrow new Error(`Supervisor question '${questionId}' was bound to a different child incarnation.`);\n\t}\n\tif (now > current.expiresAt) {\n\t\twriteTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now });\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal && terminal.state !== \"answered\") {\n\t\t\trejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\t}\n\t\tif (terminal?.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\t}\n\tconst existing = readTerminal(channelDir, questionId);\n\tif (existing) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, existing);\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"answered\", at: now, message: trimmed })) {\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\tthrow new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\t}\n\tconst answered = readSupervisorQuestion(channelDir, questionId);\n\tif (!answered) throw new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\treturn answered;\n}\n\nexport function expireSupervisorQuestion(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current) || now <= current.expiresAt) return current && supervisorQuestionIsTerminal(current) ? current : undefined;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now })) return readSupervisorQuestion(channelDir, questionId);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function cancelSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\treason: string,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"cancelled\", at: now, reason: reason.trim() || \"cancelled\" })) {\n\t\treturn readSupervisorQuestion(channelDir, questionId);\n\t}\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function refreshSupervisorQuestionLifecycle(channelDir: string, now = Date.now()): SupervisorQuestion[] {\n\tconst changed: SupervisorQuestion[] = [];\n\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\tif (now > question.expiresAt) {\n\t\t\tconst expired = expireSupervisorQuestion(channelDir, question.id, now);\n\t\t\tif (expired && expired.expiredAt) changed.push(expired);\n\t\t}\n\t}\n\treturn changed;\n}\n\nexport function formatParentQuestionForChild(question: SupervisorQuestion): string {\n\treturn [\n\t\t`Parent question (${question.id})`,\n\t\t`Decision needed: ${question.reason}`,\n\t\t\"\",\n\t\tquestion.message,\n\t\t\"\",\n\t\t`Reply with: contact_supervisor({ action: \"reply\", replyTo: \"${question.id}\", message: \"...\" })`,\n\t\t\"Answer from current findings and uncertainty. Do not silently start extra investigation. Continue the assigned task after replying.\",\n\t].join(\"\\n\");\n}\n\nexport function formatSupervisorQuestionAnswer(question: SupervisorQuestion): string {\n\tconst state = supervisorQuestionPublicState(question);\n\tconst header = state === \"answered\"\n\t\t? `Subagent answer (${question.id})`\n\t\t: `Subagent question ${state} (${question.id})`;\n\tconst lines = [\n\t\theader,\n\t\t`Run: ${question.runId}`,\n\t\t`Child: ${question.childId} [#${question.childIndex}]`,\n\t\t`Decision: ${question.reason}`,\n\t];\n\tif (state === \"answered\" && question.answer?.trim()) {\n\t\tlines.push(\"\", question.answer.trim());\n\t} else if (question.cancelReason) {\n\t\tlines.push(\"\", question.cancelReason);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function registerQuestionWait(questionIds: Iterable<string>): () => void {\n\tconst ids = [...questionIds];\n\tfor (const id of ids) activeQuestionWaits.add(id);\n\treturn () => {\n\t\tfor (const id of ids) activeQuestionWaits.delete(id);\n\t};\n}\n\nexport function isQuestionWaitActive(questionId: string): boolean {\n\treturn activeQuestionWaits.has(questionId);\n}\n\nexport function claimQuestionNotification(channelDir: string, questionId: string, now = Date.now()): boolean {\n\treturn writeExclusiveJson(notifiedFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.notified\",\n\t\tid: questionId,\n\t\tat: now,\n\t} satisfies NotifiedRecord);\n}\n\nexport function markSupervisorQuestionNotified(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tclaimQuestionNotification(channelDir, questionId, now);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function resetSupervisorQuestionTestState(): void {\n\tactiveQuestionWaits.clear();\n}\n\nexport function listSupervisorChannelDirs(): string[] {\n\tlet entries: fs.Dirent[];\n\ttry {\n\t\tentries = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true });\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\treturn entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(SUPERVISOR_CHANNEL_ROOT, entry.name));\n}\n\nexport function findSupervisorQuestion(questionId: string): { channelDir: string; question: SupervisorQuestion } | undefined {\n\tconst id = questionId.trim();\n\tif (!id) return undefined;\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tconst question = readSupervisorQuestion(channelDir, id);\n\t\tif (question) return { channelDir, question };\n\t}\n\treturn undefined;\n}\n\nexport function cancelPendingSupervisorQuestionsForOwner(input: {\n\tparentSessionId: string;\n\tparentGeneration?: number;\n\trunId?: string;\n\treason: string;\n\tnow?: number;\n}): SupervisorQuestion[] {\n\tif (!input.parentSessionId?.trim()) return [];\n\tconst now = input.now ?? Date.now();\n\tconst cancelled: SupervisorQuestion[] = [];\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\t\tif (question.parentSessionId !== input.parentSessionId) continue;\n\t\t\tif (input.parentGeneration !== undefined && question.parentGeneration !== input.parentGeneration) continue;\n\t\t\tif (input.runId && question.runId !== input.runId) continue;\n\t\t\tconst next = cancelSupervisorQuestion(channelDir, question.id, input.reason, now);\n\t\t\tif (next?.cancelledAt) cancelled.push(next);\n\t\t}\n\t}\n\treturn cancelled;\n}\n\nexport function pendingSupervisorQuestionsForDelivery(channelDir: string, owner: SupervisorQuestionOwner, now = Date.now()): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir, now);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.deliveredAt) return false;\n\t\tif (question.runId !== owner.runId || question.childIndex !== owner.childIndex || question.childId !== owner.childId) return false;\n\t\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) return false;\n\t\treturn now <= question.expiresAt;\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"supervisor-questions.d.ts","sourceRoot":"","sources":["../../../../../src/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,uBAAuB,QAAkD,CAAC;AACvF,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAC5E,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,CAAC;AAE7F,MAAM,WAAW,0BAA0B;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,8BAA8B,CAAC;IACrC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,0BAA0B,CAAC;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU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kB,EAAE,CAU7G;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAUjF;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAgBnF;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAM9E;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,OAAO,CAM3G;AAED,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,kBAAkB,GAAG,SAAS,CAGvI;AAED,wBAAgB,gCAAgC,IAAI,IAAI,CAEvD;AAED,wBAAgB,yBAAyB,IAAI,MAAM,EAAE,CASpD;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,kBAAkB,CAAA;CAAE,GAAG,SAAS,CAQ3H;AAED,wBAAgB,wCAAwC,CAAC,KAAK,EAAE;IAC/D,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,kBAAkB,EAAE,CAevB;AAED,wBAAgB,qCAAqC,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,uBAAuB,EAAE,GAAG,SAAa,GAAG,kBAAkB,EAAE,CAShJ","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { TEMP_ROOT_DIR } from \"../shared/types.ts\";\n\nexport const QUESTIONS_DIR = \"questions\";\nexport const SUPERVISOR_CHANNEL_ROOT = path.join(TEMP_ROOT_DIR, \"supervisor-channels\");\nexport const SUBAGENT_SUPERVISOR_ANSWER_TYPE = \"subagent_supervisor_answer\";\nexport const SUBAGENT_QUESTION_EVENT = \"subagent:supervisor-question\";\n\nexport type SupervisorQuestionPublicState = \"pending\" | \"answered\" | \"expired\" | \"cancelled\";\n\nexport interface SupervisorChildIncarnation {\n\tpid: number;\n\treadyAt: number;\n}\n\nexport interface SupervisorQuestion {\n\ttype: \"subagent.supervisor.question\";\n\tchildDescription?: string;\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tdeliveredAt?: number;\n\tansweredAt?: number;\n\texpiredAt?: number;\n\tcancelledAt?: number;\n\tcancelReason?: string;\n\tnotifiedAt?: number;\n\tlateAnswerAt?: number;\n\tanswer?: string;\n}\n\nexport interface SupervisorQuestionOwner {\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tpid: number;\n\treadyAt: number;\n}\n\ninterface QuestionRecord {\n\ttype: \"subagent.supervisor.question\";\n\tchildDescription?: string;\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n}\n\ninterface DeliveredRecord {\n\ttype: \"subagent.supervisor.delivered\";\n\tid: string;\n\tat: number;\n\tpid: number;\n\treadyAt: number;\n}\n\ntype TerminalRecord =\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"answered\"; at: number; message: string }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"expired\"; at: number }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"cancelled\"; at: number; reason: string };\n\ninterface NotifiedRecord {\n\ttype: \"subagent.supervisor.notified\";\n\tid: string;\n\tat: number;\n}\n\ninterface LateAnswerRecord {\n\ttype: \"subagent.supervisor.late-answer\";\n\tid: string;\n\tat: number;\n\tmessage: string;\n}\n\nconst MAX_MESSAGE_BYTES = 64 * 1024;\nconst DEFAULT_ASK_TIMEOUT_MS = 10 * 60 * 1000;\nconst activeQuestionWaits = new Set<string>();\n\nfunction askTimeoutMs(): number {\n\tconst parsed = Number(process.env.PI_INTERCOM_ASK_TIMEOUT_MS);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_ASK_TIMEOUT_MS;\n}\n\nfunction safeSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nexport function resolveSupervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(SUPERVISOR_CHANNEL_ROOT, `${safeSegment(runId)}-${safeSegment(agent)}-${childIndex}`);\n}\n\nexport function questionsDir(channelDir: string): string {\n\treturn path.join(channelDir, QUESTIONS_DIR);\n}\n\nfunction questionFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.json`);\n}\n\nfunction deliveredFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.delivered.json`);\n}\n\nfunction terminalFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.terminal.json`);\n}\n\nfunction notifiedFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.notified.json`);\n}\n\nfunction lateFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.late.json`);\n}\n\nfunction writeExclusiveJson(filePath: string, payload: object): boolean {\n\tfs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });\n\tconst temporary = `${filePath}.${randomUUID()}.tmp`;\n\ttry {\n\t\tfs.writeFileSync(temporary, JSON.stringify(payload), { encoding: \"utf-8\", flag: \"wx\", mode: 0o600 });\n\t\t// Publish a complete record without overwriting a competing terminal outcome.\n\t\tfs.linkSync(temporary, filePath);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n\t\tthrow error;\n\t} finally {\n\t\tfs.rmSync(temporary, { force: true });\n\t}\n}\n\nfunction readJsonFile(filePath: string): unknown {\n\treturn JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n}\n\nfunction tryReadJson(filePath: string): unknown | undefined {\n\ttry {\n\t\treturn readJsonFile(filePath);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\treturn undefined;\n\t}\n}\n\nfunction parseIncarnation(raw: unknown): SupervisorChildIncarnation | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<SupervisorChildIncarnation>;\n\tconst pid = input.pid;\n\tconst readyAt = input.readyAt;\n\tif (!Number.isInteger(pid) || pid === undefined || pid <= 0) return undefined;\n\tif (typeof readyAt !== \"number\" || !Number.isFinite(readyAt) || readyAt <= 0) return undefined;\n\treturn { pid, readyAt };\n}\n\nfunction parseQuestionRecord(raw: unknown): QuestionRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<QuestionRecord>;\n\tif (input.type !== \"subagent.supervisor.question\") return undefined;\n\tif (typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.createdAt !== \"number\" || !Number.isFinite(input.createdAt)) return undefined;\n\tif (typeof input.expiresAt !== \"number\" || !Number.isFinite(input.expiresAt)) return undefined;\n\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\tif (typeof input.runId !== \"string\" || !input.runId.trim()) return undefined;\n\tconst childIndex = input.childIndex;\n\tif (!Number.isInteger(childIndex) || childIndex === undefined || childIndex < 0) return undefined;\n\tif (typeof input.childId !== \"string\" || !input.childId.trim()) return undefined;\n\tif (typeof input.parentSessionId !== \"string\" || !input.parentSessionId.trim()) return undefined;\n\tconst parentGeneration = input.parentGeneration;\n\tif (!Number.isInteger(parentGeneration) || parentGeneration === undefined || parentGeneration < 0) return undefined;\n\tconst incarnation = parseIncarnation(input.childIncarnation);\n\treturn {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id.trim(),\n\t\tcreatedAt: input.createdAt,\n\t\texpiresAt: input.expiresAt,\n\t\treason: input.reason.trim(),\n\t\tmessage: input.message.trim(),\n\t\trunId: input.runId.trim(),\n\t\tchildIndex,\n\t\tchildId: input.childId.trim(),\n\t\t...(typeof input.childDescription === \"string\" && input.childDescription.trim() ? { childDescription: input.childDescription.trim() } : {}),\n\t\tparentSessionId: input.parentSessionId.trim(),\n\t\tparentGeneration,\n\t\t...(incarnation ? { childIncarnation: incarnation } : {}),\n\t};\n}\n\nfunction parseDeliveredRecord(raw: unknown): DeliveredRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<DeliveredRecord>;\n\tif (input.type !== \"subagent.supervisor.delivered\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tconst incarnation = parseIncarnation(input);\n\tif (!incarnation) return undefined;\n\treturn { type: \"subagent.supervisor.delivered\", id: input.id.trim(), at: input.at, pid: incarnation.pid, readyAt: incarnation.readyAt };\n}\n\nfunction parseTerminalRecord(raw: unknown): TerminalRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<TerminalRecord> & { message?: unknown; reason?: unknown };\n\tif (input.type !== \"subagent.supervisor.terminal\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tif (input.state === \"answered\") {\n\t\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"answered\", at: input.at, message: input.message };\n\t}\n\tif (input.state === \"expired\") {\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"expired\", at: input.at };\n\t}\n\tif (input.state === \"cancelled\") {\n\t\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"cancelled\", at: input.at, reason: input.reason.trim() };\n\t}\n\treturn undefined;\n}\n\nfunction parseNotifiedRecord(raw: unknown): NotifiedRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<NotifiedRecord>;\n\tif (input.type !== \"subagent.supervisor.notified\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\treturn { type: \"subagent.supervisor.notified\", id: input.id.trim(), at: input.at };\n}\n\nfunction parseLateRecord(raw: unknown): LateAnswerRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<LateAnswerRecord>;\n\tif (input.type !== \"subagent.supervisor.late-answer\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at) || typeof input.message !== \"string\") return undefined;\n\treturn { type: \"subagent.supervisor.late-answer\", id: input.id.trim(), at: input.at, message: input.message };\n}\n\nfunction composeQuestion(record: QuestionRecord, channelDir: string): SupervisorQuestion {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, record.id)));\n\tconst terminal = parseTerminalRecord(tryReadJson(terminalFile(channelDir, record.id)));\n\tconst notified = parseNotifiedRecord(tryReadJson(notifiedFile(channelDir, record.id)));\n\tconst late = parseLateRecord(tryReadJson(lateFile(channelDir, record.id)));\n\treturn {\n\t\t...record,\n\t\t...(delivered ? { deliveredAt: delivered.at, childIncarnation: record.childIncarnation ?? { pid: delivered.pid, readyAt: delivered.readyAt } } : {}),\n\t\t...(terminal?.state === \"answered\" ? { answeredAt: terminal.at, answer: terminal.message } : {}),\n\t\t...(terminal?.state === \"expired\" ? { expiredAt: terminal.at } : {}),\n\t\t...(terminal?.state === \"cancelled\" ? { cancelledAt: terminal.at, cancelReason: terminal.reason } : {}),\n\t\t...(notified ? { notifiedAt: notified.at } : {}),\n\t\t...(late ? { lateAnswerAt: late.at, ...(terminal?.state === \"answered\" ? {} : { answer: late.message }) } : {}),\n\t};\n}\n\nfunction assertMessageSize(value: string, label: string): void {\n\tif (Buffer.byteLength(value, \"utf-8\") > MAX_MESSAGE_BYTES) throw new Error(`${label} is too large.`);\n}\n\nexport function ensureQuestionsDir(channelDir: string): void {\n\tfs.mkdirSync(questionsDir(channelDir), { recursive: true, mode: 0o700 });\n}\n\nexport function supervisorQuestionPublicState(question: SupervisorQuestion): SupervisorQuestionPublicState {\n\tif (question.answeredAt) return \"answered\";\n\tif (question.expiredAt) return \"expired\";\n\tif (question.cancelledAt) return \"cancelled\";\n\treturn \"pending\";\n}\n\nexport function supervisorQuestionIsTerminal(question: SupervisorQuestion): boolean {\n\treturn supervisorQuestionPublicState(question) !== \"pending\";\n}\n\nexport function readSupervisorQuestion(channelDir: string, questionId: string): SupervisorQuestion | undefined {\n\tconst record = parseQuestionRecord(tryReadJson(questionFile(channelDir, questionId)));\n\tif (!record || record.id !== questionId) return undefined;\n\treturn composeQuestion(record, channelDir);\n}\n\nexport function listSupervisorQuestions(channelDir: string): SupervisorQuestion[] {\n\tconst dir = questionsDir(channelDir);\n\tlet entries: string[];\n\ttry {\n\t\tentries = fs.readdirSync(dir).filter((name) => name.endsWith(\".json\") && !name.endsWith(\".delivered.json\") && !name.endsWith(\".terminal.json\") && !name.endsWith(\".notified.json\") && !name.endsWith(\".late.json\"));\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\tconst questions: SupervisorQuestion[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tconst record = parseQuestionRecord(tryReadJson(path.join(dir, entry)));\n\t\tif (record) questions.push(composeQuestion(record, channelDir));\n\t}\n\treturn questions;\n}\n\nfunction writeTerminal(channelDir: string, record: TerminalRecord): boolean {\n\treturn writeExclusiveJson(terminalFile(channelDir, record.id), record);\n}\n\nfunction readTerminal(channelDir: string, questionId: string): TerminalRecord | undefined {\n\treturn parseTerminalRecord(tryReadJson(terminalFile(channelDir, questionId)));\n}\n\nexport function createSupervisorQuestion(input: {\n\tchannelDir: string;\n\tchildDescription?: string;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tnow?: number;\n\ttimeoutMs?: number;\n\tid?: string;\n}): SupervisorQuestion {\n\tconst reason = input.reason.trim();\n\tconst message = input.message.trim();\n\tif (!reason) throw new Error(\"reason is required and must name the concrete decision the child's answer will change.\");\n\tif (!message) throw new Error(\"message is required for supervisor questions.\");\n\tassertMessageSize(reason, \"reason\");\n\tassertMessageSize(message, \"message\");\n\tconst createdAt = input.now ?? Date.now();\n\tconst timeoutMs = input.timeoutMs && input.timeoutMs > 0 ? input.timeoutMs : askTimeoutMs();\n\tconst record: QuestionRecord = {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id ?? randomUUID(),\n\t\tcreatedAt,\n\t\texpiresAt: createdAt + timeoutMs,\n\t\treason,\n\t\tmessage,\n\t\trunId: input.runId,\n\t\tchildIndex: input.childIndex,\n\t\tchildId: input.childId,\n\t\t...(input.childDescription ? { childDescription: input.childDescription } : {}),\n\t\tparentSessionId: input.parentSessionId,\n\t\tparentGeneration: input.parentGeneration,\n\t\t...(input.childIncarnation ? { childIncarnation: input.childIncarnation } : {}),\n\t};\n\tassertMessageSize(JSON.stringify(record), \"Supervisor question\");\n\tensureQuestionsDir(input.channelDir);\n\tif (!writeExclusiveJson(questionFile(input.channelDir, record.id), record)) {\n\t\tthrow new Error(`Supervisor question '${record.id}' already exists.`);\n\t}\n\treturn composeQuestion(record, input.channelDir);\n}\n\nexport function outstandingQuestionsForChild(channelDir: string, childIndex: number, childId?: string): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.childIndex !== childIndex) return false;\n\t\tif (childId && question.childId !== childId) return false;\n\t\treturn true;\n\t});\n}\n\nexport function hasBlockingSupervisorRequest(channelDir: string, runId: string, childIndex: number): boolean {\n\tconst directory = path.join(channelDir, \"requests\");\n\tif (!fs.existsSync(directory)) return false;\n\tfor (const name of fs.readdirSync(directory)) {\n\t\tif (!name.endsWith(\".json\")) continue;\n\t\tconst raw = tryReadJson(path.join(directory, name));\n\t\tif (!raw || typeof raw !== \"object\") continue;\n\t\tconst request = raw as { type?: unknown; id?: unknown; expectsReply?: unknown; runId?: unknown; childIndex?: unknown; expiresAt?: unknown };\n\t\tif (request.type !== \"subagent.supervisor.request\" || request.expectsReply !== true) continue;\n\t\tif (request.runId !== runId || request.childIndex !== childIndex || typeof request.id !== \"string\") continue;\n\t\tif (typeof request.expiresAt === \"number\" && request.expiresAt <= Date.now()) continue;\n\t\tif (!fs.existsSync(path.join(channelDir, \"replies\", `${safeSegment(request.id)}.json`))) return true;\n\t}\n\treturn false;\n}\n\nexport function hasOutstandingQuestionForChild(channelDir: string, childIndex: number, childId?: string): boolean {\n\treturn outstandingQuestionsForChild(channelDir, childIndex, childId).length > 0;\n}\n\nexport function incarnationMatches(expected: SupervisorChildIncarnation | undefined, actual: SupervisorChildIncarnation): boolean {\n\tif (!expected) return true;\n\treturn expected.pid === actual.pid && expected.readyAt === actual.readyAt;\n}\n\nfunction assertOwner(question: SupervisorQuestion, owner: SupervisorQuestionOwner): void {\n\tif (owner.runId !== question.runId || owner.childIndex !== question.childIndex || owner.childId !== question.childId) {\n\t\tthrow new Error(`Supervisor question '${question.id}' is not owned by this child.`);\n\t}\n\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) {\n\t\tthrow new Error(`Supervisor question '${question.id}' was bound to a different child incarnation.`);\n\t}\n}\n\nfunction ownerMatchesDelivered(channelDir: string, questionId: string, owner: SupervisorQuestionOwner): boolean {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, questionId)));\n\tif (!delivered) return true;\n\treturn delivered.pid === owner.pid && delivered.readyAt === owner.readyAt;\n}\n\nexport function markSupervisorQuestionDelivered(\n\tchannelDir: string,\n\tquestionId: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tassertOwner(current, owner);\n\twriteExclusiveJson(deliveredFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.delivered\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tpid: owner.pid,\n\t\treadyAt: owner.readyAt,\n\t} satisfies DeliveredRecord);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nfunction rejectLateOrDuplicate(channelDir: string, questionId: string, answer: string, now: number, terminal: TerminalRecord): never {\n\twriteExclusiveJson(lateFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.late-answer\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tmessage: answer,\n\t} satisfies LateAnswerRecord);\n\tif (terminal.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\tthrow new Error(`Supervisor question '${questionId}' is ${terminal.state} and no longer accepts an answer.`);\n}\n\nexport function answerSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\tanswer: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion {\n\tconst trimmed = answer.trim();\n\tif (!trimmed) throw new Error(\"message is required for supervisor question replies.\");\n\tassertMessageSize(trimmed, \"answer\");\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current) throw new Error(`No supervisor question found for replyTo '${questionId}'.`);\n\tassertOwner(current, owner);\n\tif (!ownerMatchesDelivered(channelDir, questionId, owner)) {\n\t\tthrow new Error(`Supervisor question '${questionId}' was bound to a different child incarnation.`);\n\t}\n\tif (now > current.expiresAt) {\n\t\twriteTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now });\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal && terminal.state !== \"answered\") {\n\t\t\trejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\t}\n\t\tif (terminal?.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\t}\n\tconst existing = readTerminal(channelDir, questionId);\n\tif (existing) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, existing);\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"answered\", at: now, message: trimmed })) {\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\tthrow new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\t}\n\tconst answered = readSupervisorQuestion(channelDir, questionId);\n\tif (!answered) throw new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\treturn answered;\n}\n\nexport function expireSupervisorQuestion(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current) || now <= current.expiresAt) return current && supervisorQuestionIsTerminal(current) ? current : undefined;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now })) return readSupervisorQuestion(channelDir, questionId);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function cancelSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\treason: string,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"cancelled\", at: now, reason: reason.trim() || \"cancelled\" })) {\n\t\treturn readSupervisorQuestion(channelDir, questionId);\n\t}\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function refreshSupervisorQuestionLifecycle(channelDir: string, now = Date.now()): SupervisorQuestion[] {\n\tconst changed: SupervisorQuestion[] = [];\n\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\tif (now > question.expiresAt) {\n\t\t\tconst expired = expireSupervisorQuestion(channelDir, question.id, now);\n\t\t\tif (expired && expired.expiredAt) changed.push(expired);\n\t\t}\n\t}\n\treturn changed;\n}\n\nexport function formatParentQuestionForChild(question: SupervisorQuestion): string {\n\treturn [\n\t\t`Parent question (${question.id})`,\n\t\t`Decision needed: ${question.reason}`,\n\t\t\"\",\n\t\tquestion.message,\n\t\t\"\",\n\t\t`Reply with: contact_supervisor({ action: \"reply\", replyTo: \"${question.id}\", message: \"...\" })`,\n\t\t\"Answer from current findings and uncertainty. Do not silently start extra investigation. Continue the assigned task after replying.\",\n\t].join(\"\\n\");\n}\n\nexport function formatSupervisorQuestionAnswer(question: SupervisorQuestion): string {\n\tconst state = supervisorQuestionPublicState(question);\n\tconst header = state === \"answered\"\n\t\t? `Subagent answer (${question.id})`\n\t\t: `Subagent question ${state} (${question.id})`;\n\tconst lines = [\n\t\theader,\n\t\t`From: ${question.childDescription ?? `Subagent ${question.childIndex + 1}`}`,\n\t\t`Decision: ${question.reason}`,\n\t];\n\tif (state === \"answered\" && question.answer?.trim()) {\n\t\tlines.push(\"\", question.answer.trim());\n\t} else if (question.cancelReason) {\n\t\tlines.push(\"\", question.cancelReason);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function registerQuestionWait(questionIds: Iterable<string>): () => void {\n\tconst ids = [...questionIds];\n\tfor (const id of ids) activeQuestionWaits.add(id);\n\treturn () => {\n\t\tfor (const id of ids) activeQuestionWaits.delete(id);\n\t};\n}\n\nexport function isQuestionWaitActive(questionId: string): boolean {\n\treturn activeQuestionWaits.has(questionId);\n}\n\nexport function claimQuestionNotification(channelDir: string, questionId: string, now = Date.now()): boolean {\n\treturn writeExclusiveJson(notifiedFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.notified\",\n\t\tid: questionId,\n\t\tat: now,\n\t} satisfies NotifiedRecord);\n}\n\nexport function markSupervisorQuestionNotified(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tclaimQuestionNotification(channelDir, questionId, now);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function resetSupervisorQuestionTestState(): void {\n\tactiveQuestionWaits.clear();\n}\n\nexport function listSupervisorChannelDirs(): string[] {\n\tlet entries: fs.Dirent[];\n\ttry {\n\t\tentries = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true });\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\treturn entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(SUPERVISOR_CHANNEL_ROOT, entry.name));\n}\n\nexport function findSupervisorQuestion(questionId: string): { channelDir: string; question: SupervisorQuestion } | undefined {\n\tconst id = questionId.trim();\n\tif (!id) return undefined;\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tconst question = readSupervisorQuestion(channelDir, id);\n\t\tif (question) return { channelDir, question };\n\t}\n\treturn undefined;\n}\n\nexport function cancelPendingSupervisorQuestionsForOwner(input: {\n\tparentSessionId: string;\n\tparentGeneration?: number;\n\trunId?: string;\n\treason: string;\n\tnow?: number;\n}): SupervisorQuestion[] {\n\tif (!input.parentSessionId?.trim()) return [];\n\tconst now = input.now ?? Date.now();\n\tconst cancelled: SupervisorQuestion[] = [];\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\t\tif (question.parentSessionId !== input.parentSessionId) continue;\n\t\t\tif (input.parentGeneration !== undefined && question.parentGeneration !== input.parentGeneration) continue;\n\t\t\tif (input.runId && question.runId !== input.runId) continue;\n\t\t\tconst next = cancelSupervisorQuestion(channelDir, question.id, input.reason, now);\n\t\t\tif (next?.cancelledAt) cancelled.push(next);\n\t\t}\n\t}\n\treturn cancelled;\n}\n\nexport function pendingSupervisorQuestionsForDelivery(channelDir: string, owner: SupervisorQuestionOwner, now = Date.now()): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir, now);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.deliveredAt) return false;\n\t\tif (question.runId !== owner.runId || question.childIndex !== owner.childIndex || question.childId !== owner.childId) return false;\n\t\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) return false;\n\t\treturn now <= question.expiresAt;\n\t});\n}\n"]}
|
|
@@ -119,6 +119,7 @@ function parseQuestionRecord(raw) {
|
|
|
119
119
|
runId: input.runId.trim(),
|
|
120
120
|
childIndex,
|
|
121
121
|
childId: input.childId.trim(),
|
|
122
|
+
...(typeof input.childDescription === "string" && input.childDescription.trim() ? { childDescription: input.childDescription.trim() } : {}),
|
|
122
123
|
parentSessionId: input.parentSessionId.trim(),
|
|
123
124
|
parentGeneration,
|
|
124
125
|
...(incarnation ? { childIncarnation: incarnation } : {}),
|
|
@@ -266,6 +267,7 @@ export function createSupervisorQuestion(input) {
|
|
|
266
267
|
runId: input.runId,
|
|
267
268
|
childIndex: input.childIndex,
|
|
268
269
|
childId: input.childId,
|
|
270
|
+
...(input.childDescription ? { childDescription: input.childDescription } : {}),
|
|
269
271
|
parentSessionId: input.parentSessionId,
|
|
270
272
|
parentGeneration: input.parentGeneration,
|
|
271
273
|
...(input.childIncarnation ? { childIncarnation: input.childIncarnation } : {}),
|
|
@@ -441,8 +443,7 @@ export function formatSupervisorQuestionAnswer(question) {
|
|
|
441
443
|
: `Subagent question ${state} (${question.id})`;
|
|
442
444
|
const lines = [
|
|
443
445
|
header,
|
|
444
|
-
`
|
|
445
|
-
`Child: ${question.childId} [#${question.childIndex}]`,
|
|
446
|
+
`From: ${question.childDescription ?? `Subagent ${question.childIndex + 1}`}`,
|
|
446
447
|
`Decision: ${question.reason}`,
|
|
447
448
|
];
|
|
448
449
|
if (state === "answered" && question.answer?.trim()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor-questions.js","sourceRoot":"","sources":["../../../../../src/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AACzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,+BAA+B,GAAG,4BAA4B,CAAC;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAiFtE,MAAM,iBAAiB,GAAG,EAAE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,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAClF,IAAI,IAAI,EAAE,WAAW;gBAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CACjB;AAED,MAAM,UAAU,qCAAqC,CAAC,UAAkB,EAAE,KAA8B,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAAwB;IACjJ,kCAAkC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO,uBAAuB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC/D,IAAI,4BAA4B,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;QACzD,IAAI,QAAQ,CAAC,WAAW;YAAE,OAAO,KAAK,CAAC;QACvC,IAAI,QAAQ,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;YAAE,OAAO,KAAK,CAAC;QACnI,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7G,OAAO,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC;IAAA,CACjC,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { TEMP_ROOT_DIR } from \"../shared/types.ts\";\n\nexport const QUESTIONS_DIR = \"questions\";\nexport const SUPERVISOR_CHANNEL_ROOT = path.join(TEMP_ROOT_DIR, \"supervisor-channels\");\nexport const SUBAGENT_SUPERVISOR_ANSWER_TYPE = \"subagent_supervisor_answer\";\nexport const SUBAGENT_QUESTION_EVENT = \"subagent:supervisor-question\";\n\nexport type SupervisorQuestionPublicState = \"pending\" | \"answered\" | \"expired\" | \"cancelled\";\n\nexport interface SupervisorChildIncarnation {\n\tpid: number;\n\treadyAt: number;\n}\n\nexport interface SupervisorQuestion {\n\ttype: \"subagent.supervisor.question\";\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tdeliveredAt?: number;\n\tansweredAt?: number;\n\texpiredAt?: number;\n\tcancelledAt?: number;\n\tcancelReason?: string;\n\tnotifiedAt?: number;\n\tlateAnswerAt?: number;\n\tanswer?: string;\n}\n\nexport interface SupervisorQuestionOwner {\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tpid: number;\n\treadyAt: number;\n}\n\ninterface QuestionRecord {\n\ttype: \"subagent.supervisor.question\";\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n}\n\ninterface DeliveredRecord {\n\ttype: \"subagent.supervisor.delivered\";\n\tid: string;\n\tat: number;\n\tpid: number;\n\treadyAt: number;\n}\n\ntype TerminalRecord =\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"answered\"; at: number; message: string }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"expired\"; at: number }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"cancelled\"; at: number; reason: string };\n\ninterface NotifiedRecord {\n\ttype: \"subagent.supervisor.notified\";\n\tid: string;\n\tat: number;\n}\n\ninterface LateAnswerRecord {\n\ttype: \"subagent.supervisor.late-answer\";\n\tid: string;\n\tat: number;\n\tmessage: string;\n}\n\nconst MAX_MESSAGE_BYTES = 64 * 1024;\nconst DEFAULT_ASK_TIMEOUT_MS = 10 * 60 * 1000;\nconst activeQuestionWaits = new Set<string>();\n\nfunction askTimeoutMs(): number {\n\tconst parsed = Number(process.env.PI_INTERCOM_ASK_TIMEOUT_MS);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_ASK_TIMEOUT_MS;\n}\n\nfunction safeSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nexport function resolveSupervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(SUPERVISOR_CHANNEL_ROOT, `${safeSegment(runId)}-${safeSegment(agent)}-${childIndex}`);\n}\n\nexport function questionsDir(channelDir: string): string {\n\treturn path.join(channelDir, QUESTIONS_DIR);\n}\n\nfunction questionFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.json`);\n}\n\nfunction deliveredFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.delivered.json`);\n}\n\nfunction terminalFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.terminal.json`);\n}\n\nfunction notifiedFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.notified.json`);\n}\n\nfunction lateFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.late.json`);\n}\n\nfunction writeExclusiveJson(filePath: string, payload: object): boolean {\n\tfs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });\n\tconst temporary = `${filePath}.${randomUUID()}.tmp`;\n\ttry {\n\t\tfs.writeFileSync(temporary, JSON.stringify(payload), { encoding: \"utf-8\", flag: \"wx\", mode: 0o600 });\n\t\t// Publish a complete record without overwriting a competing terminal outcome.\n\t\tfs.linkSync(temporary, filePath);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n\t\tthrow error;\n\t} finally {\n\t\tfs.rmSync(temporary, { force: true });\n\t}\n}\n\nfunction readJsonFile(filePath: string): unknown {\n\treturn JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n}\n\nfunction tryReadJson(filePath: string): unknown | undefined {\n\ttry {\n\t\treturn readJsonFile(filePath);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\treturn undefined;\n\t}\n}\n\nfunction parseIncarnation(raw: unknown): SupervisorChildIncarnation | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<SupervisorChildIncarnation>;\n\tconst pid = input.pid;\n\tconst readyAt = input.readyAt;\n\tif (!Number.isInteger(pid) || pid === undefined || pid <= 0) return undefined;\n\tif (typeof readyAt !== \"number\" || !Number.isFinite(readyAt) || readyAt <= 0) return undefined;\n\treturn { pid, readyAt };\n}\n\nfunction parseQuestionRecord(raw: unknown): QuestionRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<QuestionRecord>;\n\tif (input.type !== \"subagent.supervisor.question\") return undefined;\n\tif (typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.createdAt !== \"number\" || !Number.isFinite(input.createdAt)) return undefined;\n\tif (typeof input.expiresAt !== \"number\" || !Number.isFinite(input.expiresAt)) return undefined;\n\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\tif (typeof input.runId !== \"string\" || !input.runId.trim()) return undefined;\n\tconst childIndex = input.childIndex;\n\tif (!Number.isInteger(childIndex) || childIndex === undefined || childIndex < 0) return undefined;\n\tif (typeof input.childId !== \"string\" || !input.childId.trim()) return undefined;\n\tif (typeof input.parentSessionId !== \"string\" || !input.parentSessionId.trim()) return undefined;\n\tconst parentGeneration = input.parentGeneration;\n\tif (!Number.isInteger(parentGeneration) || parentGeneration === undefined || parentGeneration < 0) return undefined;\n\tconst incarnation = parseIncarnation(input.childIncarnation);\n\treturn {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id.trim(),\n\t\tcreatedAt: input.createdAt,\n\t\texpiresAt: input.expiresAt,\n\t\treason: input.reason.trim(),\n\t\tmessage: input.message.trim(),\n\t\trunId: input.runId.trim(),\n\t\tchildIndex,\n\t\tchildId: input.childId.trim(),\n\t\tparentSessionId: input.parentSessionId.trim(),\n\t\tparentGeneration,\n\t\t...(incarnation ? { childIncarnation: incarnation } : {}),\n\t};\n}\n\nfunction parseDeliveredRecord(raw: unknown): DeliveredRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<DeliveredRecord>;\n\tif (input.type !== \"subagent.supervisor.delivered\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tconst incarnation = parseIncarnation(input);\n\tif (!incarnation) return undefined;\n\treturn { type: \"subagent.supervisor.delivered\", id: input.id.trim(), at: input.at, pid: incarnation.pid, readyAt: incarnation.readyAt };\n}\n\nfunction parseTerminalRecord(raw: unknown): TerminalRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<TerminalRecord> & { message?: unknown; reason?: unknown };\n\tif (input.type !== \"subagent.supervisor.terminal\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tif (input.state === \"answered\") {\n\t\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"answered\", at: input.at, message: input.message };\n\t}\n\tif (input.state === \"expired\") {\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"expired\", at: input.at };\n\t}\n\tif (input.state === \"cancelled\") {\n\t\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"cancelled\", at: input.at, reason: input.reason.trim() };\n\t}\n\treturn undefined;\n}\n\nfunction parseNotifiedRecord(raw: unknown): NotifiedRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<NotifiedRecord>;\n\tif (input.type !== \"subagent.supervisor.notified\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\treturn { type: \"subagent.supervisor.notified\", id: input.id.trim(), at: input.at };\n}\n\nfunction parseLateRecord(raw: unknown): LateAnswerRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<LateAnswerRecord>;\n\tif (input.type !== \"subagent.supervisor.late-answer\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at) || typeof input.message !== \"string\") return undefined;\n\treturn { type: \"subagent.supervisor.late-answer\", id: input.id.trim(), at: input.at, message: input.message };\n}\n\nfunction composeQuestion(record: QuestionRecord, channelDir: string): SupervisorQuestion {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, record.id)));\n\tconst terminal = parseTerminalRecord(tryReadJson(terminalFile(channelDir, record.id)));\n\tconst notified = parseNotifiedRecord(tryReadJson(notifiedFile(channelDir, record.id)));\n\tconst late = parseLateRecord(tryReadJson(lateFile(channelDir, record.id)));\n\treturn {\n\t\t...record,\n\t\t...(delivered ? { deliveredAt: delivered.at, childIncarnation: record.childIncarnation ?? { pid: delivered.pid, readyAt: delivered.readyAt } } : {}),\n\t\t...(terminal?.state === \"answered\" ? { answeredAt: terminal.at, answer: terminal.message } : {}),\n\t\t...(terminal?.state === \"expired\" ? { expiredAt: terminal.at } : {}),\n\t\t...(terminal?.state === \"cancelled\" ? { cancelledAt: terminal.at, cancelReason: terminal.reason } : {}),\n\t\t...(notified ? { notifiedAt: notified.at } : {}),\n\t\t...(late ? { lateAnswerAt: late.at, ...(terminal?.state === \"answered\" ? {} : { answer: late.message }) } : {}),\n\t};\n}\n\nfunction assertMessageSize(value: string, label: string): void {\n\tif (Buffer.byteLength(value, \"utf-8\") > MAX_MESSAGE_BYTES) throw new Error(`${label} is too large.`);\n}\n\nexport function ensureQuestionsDir(channelDir: string): void {\n\tfs.mkdirSync(questionsDir(channelDir), { recursive: true, mode: 0o700 });\n}\n\nexport function supervisorQuestionPublicState(question: SupervisorQuestion): SupervisorQuestionPublicState {\n\tif (question.answeredAt) return \"answered\";\n\tif (question.expiredAt) return \"expired\";\n\tif (question.cancelledAt) return \"cancelled\";\n\treturn \"pending\";\n}\n\nexport function supervisorQuestionIsTerminal(question: SupervisorQuestion): boolean {\n\treturn supervisorQuestionPublicState(question) !== \"pending\";\n}\n\nexport function readSupervisorQuestion(channelDir: string, questionId: string): SupervisorQuestion | undefined {\n\tconst record = parseQuestionRecord(tryReadJson(questionFile(channelDir, questionId)));\n\tif (!record || record.id !== questionId) return undefined;\n\treturn composeQuestion(record, channelDir);\n}\n\nexport function listSupervisorQuestions(channelDir: string): SupervisorQuestion[] {\n\tconst dir = questionsDir(channelDir);\n\tlet entries: string[];\n\ttry {\n\t\tentries = fs.readdirSync(dir).filter((name) => name.endsWith(\".json\") && !name.endsWith(\".delivered.json\") && !name.endsWith(\".terminal.json\") && !name.endsWith(\".notified.json\") && !name.endsWith(\".late.json\"));\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\tconst questions: SupervisorQuestion[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tconst record = parseQuestionRecord(tryReadJson(path.join(dir, entry)));\n\t\tif (record) questions.push(composeQuestion(record, channelDir));\n\t}\n\treturn questions;\n}\n\nfunction writeTerminal(channelDir: string, record: TerminalRecord): boolean {\n\treturn writeExclusiveJson(terminalFile(channelDir, record.id), record);\n}\n\nfunction readTerminal(channelDir: string, questionId: string): TerminalRecord | undefined {\n\treturn parseTerminalRecord(tryReadJson(terminalFile(channelDir, questionId)));\n}\n\nexport function createSupervisorQuestion(input: {\n\tchannelDir: string;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tnow?: number;\n\ttimeoutMs?: number;\n\tid?: string;\n}): SupervisorQuestion {\n\tconst reason = input.reason.trim();\n\tconst message = input.message.trim();\n\tif (!reason) throw new Error(\"reason is required and must name the concrete decision the child's answer will change.\");\n\tif (!message) throw new Error(\"message is required for supervisor questions.\");\n\tassertMessageSize(reason, \"reason\");\n\tassertMessageSize(message, \"message\");\n\tconst createdAt = input.now ?? Date.now();\n\tconst timeoutMs = input.timeoutMs && input.timeoutMs > 0 ? input.timeoutMs : askTimeoutMs();\n\tconst record: QuestionRecord = {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id ?? randomUUID(),\n\t\tcreatedAt,\n\t\texpiresAt: createdAt + timeoutMs,\n\t\treason,\n\t\tmessage,\n\t\trunId: input.runId,\n\t\tchildIndex: input.childIndex,\n\t\tchildId: input.childId,\n\t\tparentSessionId: input.parentSessionId,\n\t\tparentGeneration: input.parentGeneration,\n\t\t...(input.childIncarnation ? { childIncarnation: input.childIncarnation } : {}),\n\t};\n\tassertMessageSize(JSON.stringify(record), \"Supervisor question\");\n\tensureQuestionsDir(input.channelDir);\n\tif (!writeExclusiveJson(questionFile(input.channelDir, record.id), record)) {\n\t\tthrow new Error(`Supervisor question '${record.id}' already exists.`);\n\t}\n\treturn composeQuestion(record, input.channelDir);\n}\n\nexport function outstandingQuestionsForChild(channelDir: string, childIndex: number, childId?: string): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.childIndex !== childIndex) return false;\n\t\tif (childId && question.childId !== childId) return false;\n\t\treturn true;\n\t});\n}\n\nexport function hasBlockingSupervisorRequest(channelDir: string, runId: string, childIndex: number): boolean {\n\tconst directory = path.join(channelDir, \"requests\");\n\tif (!fs.existsSync(directory)) return false;\n\tfor (const name of fs.readdirSync(directory)) {\n\t\tif (!name.endsWith(\".json\")) continue;\n\t\tconst raw = tryReadJson(path.join(directory, name));\n\t\tif (!raw || typeof raw !== \"object\") continue;\n\t\tconst request = raw as { type?: unknown; id?: unknown; expectsReply?: unknown; runId?: unknown; childIndex?: unknown; expiresAt?: unknown };\n\t\tif (request.type !== \"subagent.supervisor.request\" || request.expectsReply !== true) continue;\n\t\tif (request.runId !== runId || request.childIndex !== childIndex || typeof request.id !== \"string\") continue;\n\t\tif (typeof request.expiresAt === \"number\" && request.expiresAt <= Date.now()) continue;\n\t\tif (!fs.existsSync(path.join(channelDir, \"replies\", `${safeSegment(request.id)}.json`))) return true;\n\t}\n\treturn false;\n}\n\nexport function hasOutstandingQuestionForChild(channelDir: string, childIndex: number, childId?: string): boolean {\n\treturn outstandingQuestionsForChild(channelDir, childIndex, childId).length > 0;\n}\n\nexport function incarnationMatches(expected: SupervisorChildIncarnation | undefined, actual: SupervisorChildIncarnation): boolean {\n\tif (!expected) return true;\n\treturn expected.pid === actual.pid && expected.readyAt === actual.readyAt;\n}\n\nfunction assertOwner(question: SupervisorQuestion, owner: SupervisorQuestionOwner): void {\n\tif (owner.runId !== question.runId || owner.childIndex !== question.childIndex || owner.childId !== question.childId) {\n\t\tthrow new Error(`Supervisor question '${question.id}' is not owned by this child.`);\n\t}\n\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) {\n\t\tthrow new Error(`Supervisor question '${question.id}' was bound to a different child incarnation.`);\n\t}\n}\n\nfunction ownerMatchesDelivered(channelDir: string, questionId: string, owner: SupervisorQuestionOwner): boolean {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, questionId)));\n\tif (!delivered) return true;\n\treturn delivered.pid === owner.pid && delivered.readyAt === owner.readyAt;\n}\n\nexport function markSupervisorQuestionDelivered(\n\tchannelDir: string,\n\tquestionId: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tassertOwner(current, owner);\n\twriteExclusiveJson(deliveredFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.delivered\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tpid: owner.pid,\n\t\treadyAt: owner.readyAt,\n\t} satisfies DeliveredRecord);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nfunction rejectLateOrDuplicate(channelDir: string, questionId: string, answer: string, now: number, terminal: TerminalRecord): never {\n\twriteExclusiveJson(lateFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.late-answer\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tmessage: answer,\n\t} satisfies LateAnswerRecord);\n\tif (terminal.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\tthrow new Error(`Supervisor question '${questionId}' is ${terminal.state} and no longer accepts an answer.`);\n}\n\nexport function answerSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\tanswer: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion {\n\tconst trimmed = answer.trim();\n\tif (!trimmed) throw new Error(\"message is required for supervisor question replies.\");\n\tassertMessageSize(trimmed, \"answer\");\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current) throw new Error(`No supervisor question found for replyTo '${questionId}'.`);\n\tassertOwner(current, owner);\n\tif (!ownerMatchesDelivered(channelDir, questionId, owner)) {\n\t\tthrow new Error(`Supervisor question '${questionId}' was bound to a different child incarnation.`);\n\t}\n\tif (now > current.expiresAt) {\n\t\twriteTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now });\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal && terminal.state !== \"answered\") {\n\t\t\trejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\t}\n\t\tif (terminal?.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\t}\n\tconst existing = readTerminal(channelDir, questionId);\n\tif (existing) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, existing);\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"answered\", at: now, message: trimmed })) {\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\tthrow new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\t}\n\tconst answered = readSupervisorQuestion(channelDir, questionId);\n\tif (!answered) throw new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\treturn answered;\n}\n\nexport function expireSupervisorQuestion(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current) || now <= current.expiresAt) return current && supervisorQuestionIsTerminal(current) ? current : undefined;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now })) return readSupervisorQuestion(channelDir, questionId);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function cancelSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\treason: string,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"cancelled\", at: now, reason: reason.trim() || \"cancelled\" })) {\n\t\treturn readSupervisorQuestion(channelDir, questionId);\n\t}\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function refreshSupervisorQuestionLifecycle(channelDir: string, now = Date.now()): SupervisorQuestion[] {\n\tconst changed: SupervisorQuestion[] = [];\n\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\tif (now > question.expiresAt) {\n\t\t\tconst expired = expireSupervisorQuestion(channelDir, question.id, now);\n\t\t\tif (expired && expired.expiredAt) changed.push(expired);\n\t\t}\n\t}\n\treturn changed;\n}\n\nexport function formatParentQuestionForChild(question: SupervisorQuestion): string {\n\treturn [\n\t\t`Parent question (${question.id})`,\n\t\t`Decision needed: ${question.reason}`,\n\t\t\"\",\n\t\tquestion.message,\n\t\t\"\",\n\t\t`Reply with: contact_supervisor({ action: \"reply\", replyTo: \"${question.id}\", message: \"...\" })`,\n\t\t\"Answer from current findings and uncertainty. Do not silently start extra investigation. Continue the assigned task after replying.\",\n\t].join(\"\\n\");\n}\n\nexport function formatSupervisorQuestionAnswer(question: SupervisorQuestion): string {\n\tconst state = supervisorQuestionPublicState(question);\n\tconst header = state === \"answered\"\n\t\t? `Subagent answer (${question.id})`\n\t\t: `Subagent question ${state} (${question.id})`;\n\tconst lines = [\n\t\theader,\n\t\t`Run: ${question.runId}`,\n\t\t`Child: ${question.childId} [#${question.childIndex}]`,\n\t\t`Decision: ${question.reason}`,\n\t];\n\tif (state === \"answered\" && question.answer?.trim()) {\n\t\tlines.push(\"\", question.answer.trim());\n\t} else if (question.cancelReason) {\n\t\tlines.push(\"\", question.cancelReason);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function registerQuestionWait(questionIds: Iterable<string>): () => void {\n\tconst ids = [...questionIds];\n\tfor (const id of ids) activeQuestionWaits.add(id);\n\treturn () => {\n\t\tfor (const id of ids) activeQuestionWaits.delete(id);\n\t};\n}\n\nexport function isQuestionWaitActive(questionId: string): boolean {\n\treturn activeQuestionWaits.has(questionId);\n}\n\nexport function claimQuestionNotification(channelDir: string, questionId: string, now = Date.now()): boolean {\n\treturn writeExclusiveJson(notifiedFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.notified\",\n\t\tid: questionId,\n\t\tat: now,\n\t} satisfies NotifiedRecord);\n}\n\nexport function markSupervisorQuestionNotified(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tclaimQuestionNotification(channelDir, questionId, now);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function resetSupervisorQuestionTestState(): void {\n\tactiveQuestionWaits.clear();\n}\n\nexport function listSupervisorChannelDirs(): string[] {\n\tlet entries: fs.Dirent[];\n\ttry {\n\t\tentries = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true });\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\treturn entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(SUPERVISOR_CHANNEL_ROOT, entry.name));\n}\n\nexport function findSupervisorQuestion(questionId: string): { channelDir: string; question: SupervisorQuestion } | undefined {\n\tconst id = questionId.trim();\n\tif (!id) return undefined;\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tconst question = readSupervisorQuestion(channelDir, id);\n\t\tif (question) return { channelDir, question };\n\t}\n\treturn undefined;\n}\n\nexport function cancelPendingSupervisorQuestionsForOwner(input: {\n\tparentSessionId: string;\n\tparentGeneration?: number;\n\trunId?: string;\n\treason: string;\n\tnow?: number;\n}): SupervisorQuestion[] {\n\tif (!input.parentSessionId?.trim()) return [];\n\tconst now = input.now ?? Date.now();\n\tconst cancelled: SupervisorQuestion[] = [];\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\t\tif (question.parentSessionId !== input.parentSessionId) continue;\n\t\t\tif (input.parentGeneration !== undefined && question.parentGeneration !== input.parentGeneration) continue;\n\t\t\tif (input.runId && question.runId !== input.runId) continue;\n\t\t\tconst next = cancelSupervisorQuestion(channelDir, question.id, input.reason, now);\n\t\t\tif (next?.cancelledAt) cancelled.push(next);\n\t\t}\n\t}\n\treturn cancelled;\n}\n\nexport function pendingSupervisorQuestionsForDelivery(channelDir: string, owner: SupervisorQuestionOwner, now = Date.now()): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir, now);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.deliveredAt) return false;\n\t\tif (question.runId !== owner.runId || question.childIndex !== owner.childIndex || question.childId !== owner.childId) return false;\n\t\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) return false;\n\t\treturn now <= question.expiresAt;\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"supervisor-questions.js","sourceRoot":"","sources":["../../../../../src/builtin-extensions/pi-subagents/src/intercom/supervisor-questions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AACzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,+BAA+B,GAAG,4BAA4B,CAAC;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;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,CAAC,OAAO,EAAE,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7G,OAAO,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC;IAAA,CACjC,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { TEMP_ROOT_DIR } from \"../shared/types.ts\";\n\nexport const QUESTIONS_DIR = \"questions\";\nexport const SUPERVISOR_CHANNEL_ROOT = path.join(TEMP_ROOT_DIR, \"supervisor-channels\");\nexport const SUBAGENT_SUPERVISOR_ANSWER_TYPE = \"subagent_supervisor_answer\";\nexport const SUBAGENT_QUESTION_EVENT = \"subagent:supervisor-question\";\n\nexport type SupervisorQuestionPublicState = \"pending\" | \"answered\" | \"expired\" | \"cancelled\";\n\nexport interface SupervisorChildIncarnation {\n\tpid: number;\n\treadyAt: number;\n}\n\nexport interface SupervisorQuestion {\n\ttype: \"subagent.supervisor.question\";\n\tchildDescription?: string;\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tdeliveredAt?: number;\n\tansweredAt?: number;\n\texpiredAt?: number;\n\tcancelledAt?: number;\n\tcancelReason?: string;\n\tnotifiedAt?: number;\n\tlateAnswerAt?: number;\n\tanswer?: string;\n}\n\nexport interface SupervisorQuestionOwner {\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tpid: number;\n\treadyAt: number;\n}\n\ninterface QuestionRecord {\n\ttype: \"subagent.supervisor.question\";\n\tchildDescription?: string;\n\tid: string;\n\tcreatedAt: number;\n\texpiresAt: number;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n}\n\ninterface DeliveredRecord {\n\ttype: \"subagent.supervisor.delivered\";\n\tid: string;\n\tat: number;\n\tpid: number;\n\treadyAt: number;\n}\n\ntype TerminalRecord =\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"answered\"; at: number; message: string }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"expired\"; at: number }\n\t| { type: \"subagent.supervisor.terminal\"; id: string; state: \"cancelled\"; at: number; reason: string };\n\ninterface NotifiedRecord {\n\ttype: \"subagent.supervisor.notified\";\n\tid: string;\n\tat: number;\n}\n\ninterface LateAnswerRecord {\n\ttype: \"subagent.supervisor.late-answer\";\n\tid: string;\n\tat: number;\n\tmessage: string;\n}\n\nconst MAX_MESSAGE_BYTES = 64 * 1024;\nconst DEFAULT_ASK_TIMEOUT_MS = 10 * 60 * 1000;\nconst activeQuestionWaits = new Set<string>();\n\nfunction askTimeoutMs(): number {\n\tconst parsed = Number(process.env.PI_INTERCOM_ASK_TIMEOUT_MS);\n\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_ASK_TIMEOUT_MS;\n}\n\nfunction safeSegment(value: string): string {\n\treturn value.trim().replace(/[^A-Za-z0-9._-]+/g, \"-\").replace(/^-+|-+$/g, \"\") || \"unknown\";\n}\n\nexport function resolveSupervisorChannelDir(runId: string, agent: string, childIndex: number): string {\n\treturn path.join(SUPERVISOR_CHANNEL_ROOT, `${safeSegment(runId)}-${safeSegment(agent)}-${childIndex}`);\n}\n\nexport function questionsDir(channelDir: string): string {\n\treturn path.join(channelDir, QUESTIONS_DIR);\n}\n\nfunction questionFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.json`);\n}\n\nfunction deliveredFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.delivered.json`);\n}\n\nfunction terminalFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.terminal.json`);\n}\n\nfunction notifiedFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.notified.json`);\n}\n\nfunction lateFile(channelDir: string, questionId: string): string {\n\treturn path.join(questionsDir(channelDir), `${safeSegment(questionId)}.late.json`);\n}\n\nfunction writeExclusiveJson(filePath: string, payload: object): boolean {\n\tfs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });\n\tconst temporary = `${filePath}.${randomUUID()}.tmp`;\n\ttry {\n\t\tfs.writeFileSync(temporary, JSON.stringify(payload), { encoding: \"utf-8\", flag: \"wx\", mode: 0o600 });\n\t\t// Publish a complete record without overwriting a competing terminal outcome.\n\t\tfs.linkSync(temporary, filePath);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n\t\tthrow error;\n\t} finally {\n\t\tfs.rmSync(temporary, { force: true });\n\t}\n}\n\nfunction readJsonFile(filePath: string): unknown {\n\treturn JSON.parse(fs.readFileSync(filePath, \"utf-8\"));\n}\n\nfunction tryReadJson(filePath: string): unknown | undefined {\n\ttry {\n\t\treturn readJsonFile(filePath);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\treturn undefined;\n\t}\n}\n\nfunction parseIncarnation(raw: unknown): SupervisorChildIncarnation | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<SupervisorChildIncarnation>;\n\tconst pid = input.pid;\n\tconst readyAt = input.readyAt;\n\tif (!Number.isInteger(pid) || pid === undefined || pid <= 0) return undefined;\n\tif (typeof readyAt !== \"number\" || !Number.isFinite(readyAt) || readyAt <= 0) return undefined;\n\treturn { pid, readyAt };\n}\n\nfunction parseQuestionRecord(raw: unknown): QuestionRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<QuestionRecord>;\n\tif (input.type !== \"subagent.supervisor.question\") return undefined;\n\tif (typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.createdAt !== \"number\" || !Number.isFinite(input.createdAt)) return undefined;\n\tif (typeof input.expiresAt !== \"number\" || !Number.isFinite(input.expiresAt)) return undefined;\n\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\tif (typeof input.runId !== \"string\" || !input.runId.trim()) return undefined;\n\tconst childIndex = input.childIndex;\n\tif (!Number.isInteger(childIndex) || childIndex === undefined || childIndex < 0) return undefined;\n\tif (typeof input.childId !== \"string\" || !input.childId.trim()) return undefined;\n\tif (typeof input.parentSessionId !== \"string\" || !input.parentSessionId.trim()) return undefined;\n\tconst parentGeneration = input.parentGeneration;\n\tif (!Number.isInteger(parentGeneration) || parentGeneration === undefined || parentGeneration < 0) return undefined;\n\tconst incarnation = parseIncarnation(input.childIncarnation);\n\treturn {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id.trim(),\n\t\tcreatedAt: input.createdAt,\n\t\texpiresAt: input.expiresAt,\n\t\treason: input.reason.trim(),\n\t\tmessage: input.message.trim(),\n\t\trunId: input.runId.trim(),\n\t\tchildIndex,\n\t\tchildId: input.childId.trim(),\n\t\t...(typeof input.childDescription === \"string\" && input.childDescription.trim() ? { childDescription: input.childDescription.trim() } : {}),\n\t\tparentSessionId: input.parentSessionId.trim(),\n\t\tparentGeneration,\n\t\t...(incarnation ? { childIncarnation: incarnation } : {}),\n\t};\n}\n\nfunction parseDeliveredRecord(raw: unknown): DeliveredRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<DeliveredRecord>;\n\tif (input.type !== \"subagent.supervisor.delivered\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tconst incarnation = parseIncarnation(input);\n\tif (!incarnation) return undefined;\n\treturn { type: \"subagent.supervisor.delivered\", id: input.id.trim(), at: input.at, pid: incarnation.pid, readyAt: incarnation.readyAt };\n}\n\nfunction parseTerminalRecord(raw: unknown): TerminalRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<TerminalRecord> & { message?: unknown; reason?: unknown };\n\tif (input.type !== \"subagent.supervisor.terminal\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\tif (input.state === \"answered\") {\n\t\tif (typeof input.message !== \"string\" || !input.message.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"answered\", at: input.at, message: input.message };\n\t}\n\tif (input.state === \"expired\") {\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"expired\", at: input.at };\n\t}\n\tif (input.state === \"cancelled\") {\n\t\tif (typeof input.reason !== \"string\" || !input.reason.trim()) return undefined;\n\t\treturn { type: \"subagent.supervisor.terminal\", id: input.id.trim(), state: \"cancelled\", at: input.at, reason: input.reason.trim() };\n\t}\n\treturn undefined;\n}\n\nfunction parseNotifiedRecord(raw: unknown): NotifiedRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<NotifiedRecord>;\n\tif (input.type !== \"subagent.supervisor.notified\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at)) return undefined;\n\treturn { type: \"subagent.supervisor.notified\", id: input.id.trim(), at: input.at };\n}\n\nfunction parseLateRecord(raw: unknown): LateAnswerRecord | undefined {\n\tif (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n\tconst input = raw as Partial<LateAnswerRecord>;\n\tif (input.type !== \"subagent.supervisor.late-answer\" || typeof input.id !== \"string\" || !input.id.trim()) return undefined;\n\tif (typeof input.at !== \"number\" || !Number.isFinite(input.at) || typeof input.message !== \"string\") return undefined;\n\treturn { type: \"subagent.supervisor.late-answer\", id: input.id.trim(), at: input.at, message: input.message };\n}\n\nfunction composeQuestion(record: QuestionRecord, channelDir: string): SupervisorQuestion {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, record.id)));\n\tconst terminal = parseTerminalRecord(tryReadJson(terminalFile(channelDir, record.id)));\n\tconst notified = parseNotifiedRecord(tryReadJson(notifiedFile(channelDir, record.id)));\n\tconst late = parseLateRecord(tryReadJson(lateFile(channelDir, record.id)));\n\treturn {\n\t\t...record,\n\t\t...(delivered ? { deliveredAt: delivered.at, childIncarnation: record.childIncarnation ?? { pid: delivered.pid, readyAt: delivered.readyAt } } : {}),\n\t\t...(terminal?.state === \"answered\" ? { answeredAt: terminal.at, answer: terminal.message } : {}),\n\t\t...(terminal?.state === \"expired\" ? { expiredAt: terminal.at } : {}),\n\t\t...(terminal?.state === \"cancelled\" ? { cancelledAt: terminal.at, cancelReason: terminal.reason } : {}),\n\t\t...(notified ? { notifiedAt: notified.at } : {}),\n\t\t...(late ? { lateAnswerAt: late.at, ...(terminal?.state === \"answered\" ? {} : { answer: late.message }) } : {}),\n\t};\n}\n\nfunction assertMessageSize(value: string, label: string): void {\n\tif (Buffer.byteLength(value, \"utf-8\") > MAX_MESSAGE_BYTES) throw new Error(`${label} is too large.`);\n}\n\nexport function ensureQuestionsDir(channelDir: string): void {\n\tfs.mkdirSync(questionsDir(channelDir), { recursive: true, mode: 0o700 });\n}\n\nexport function supervisorQuestionPublicState(question: SupervisorQuestion): SupervisorQuestionPublicState {\n\tif (question.answeredAt) return \"answered\";\n\tif (question.expiredAt) return \"expired\";\n\tif (question.cancelledAt) return \"cancelled\";\n\treturn \"pending\";\n}\n\nexport function supervisorQuestionIsTerminal(question: SupervisorQuestion): boolean {\n\treturn supervisorQuestionPublicState(question) !== \"pending\";\n}\n\nexport function readSupervisorQuestion(channelDir: string, questionId: string): SupervisorQuestion | undefined {\n\tconst record = parseQuestionRecord(tryReadJson(questionFile(channelDir, questionId)));\n\tif (!record || record.id !== questionId) return undefined;\n\treturn composeQuestion(record, channelDir);\n}\n\nexport function listSupervisorQuestions(channelDir: string): SupervisorQuestion[] {\n\tconst dir = questionsDir(channelDir);\n\tlet entries: string[];\n\ttry {\n\t\tentries = fs.readdirSync(dir).filter((name) => name.endsWith(\".json\") && !name.endsWith(\".delivered.json\") && !name.endsWith(\".terminal.json\") && !name.endsWith(\".notified.json\") && !name.endsWith(\".late.json\"));\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\tconst questions: SupervisorQuestion[] = [];\n\tfor (const entry of entries.sort()) {\n\t\tconst record = parseQuestionRecord(tryReadJson(path.join(dir, entry)));\n\t\tif (record) questions.push(composeQuestion(record, channelDir));\n\t}\n\treturn questions;\n}\n\nfunction writeTerminal(channelDir: string, record: TerminalRecord): boolean {\n\treturn writeExclusiveJson(terminalFile(channelDir, record.id), record);\n}\n\nfunction readTerminal(channelDir: string, questionId: string): TerminalRecord | undefined {\n\treturn parseTerminalRecord(tryReadJson(terminalFile(channelDir, questionId)));\n}\n\nexport function createSupervisorQuestion(input: {\n\tchannelDir: string;\n\tchildDescription?: string;\n\treason: string;\n\tmessage: string;\n\trunId: string;\n\tchildIndex: number;\n\tchildId: string;\n\tparentSessionId: string;\n\tparentGeneration: number;\n\tchildIncarnation?: SupervisorChildIncarnation;\n\tnow?: number;\n\ttimeoutMs?: number;\n\tid?: string;\n}): SupervisorQuestion {\n\tconst reason = input.reason.trim();\n\tconst message = input.message.trim();\n\tif (!reason) throw new Error(\"reason is required and must name the concrete decision the child's answer will change.\");\n\tif (!message) throw new Error(\"message is required for supervisor questions.\");\n\tassertMessageSize(reason, \"reason\");\n\tassertMessageSize(message, \"message\");\n\tconst createdAt = input.now ?? Date.now();\n\tconst timeoutMs = input.timeoutMs && input.timeoutMs > 0 ? input.timeoutMs : askTimeoutMs();\n\tconst record: QuestionRecord = {\n\t\ttype: \"subagent.supervisor.question\",\n\t\tid: input.id ?? randomUUID(),\n\t\tcreatedAt,\n\t\texpiresAt: createdAt + timeoutMs,\n\t\treason,\n\t\tmessage,\n\t\trunId: input.runId,\n\t\tchildIndex: input.childIndex,\n\t\tchildId: input.childId,\n\t\t...(input.childDescription ? { childDescription: input.childDescription } : {}),\n\t\tparentSessionId: input.parentSessionId,\n\t\tparentGeneration: input.parentGeneration,\n\t\t...(input.childIncarnation ? { childIncarnation: input.childIncarnation } : {}),\n\t};\n\tassertMessageSize(JSON.stringify(record), \"Supervisor question\");\n\tensureQuestionsDir(input.channelDir);\n\tif (!writeExclusiveJson(questionFile(input.channelDir, record.id), record)) {\n\t\tthrow new Error(`Supervisor question '${record.id}' already exists.`);\n\t}\n\treturn composeQuestion(record, input.channelDir);\n}\n\nexport function outstandingQuestionsForChild(channelDir: string, childIndex: number, childId?: string): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.childIndex !== childIndex) return false;\n\t\tif (childId && question.childId !== childId) return false;\n\t\treturn true;\n\t});\n}\n\nexport function hasBlockingSupervisorRequest(channelDir: string, runId: string, childIndex: number): boolean {\n\tconst directory = path.join(channelDir, \"requests\");\n\tif (!fs.existsSync(directory)) return false;\n\tfor (const name of fs.readdirSync(directory)) {\n\t\tif (!name.endsWith(\".json\")) continue;\n\t\tconst raw = tryReadJson(path.join(directory, name));\n\t\tif (!raw || typeof raw !== \"object\") continue;\n\t\tconst request = raw as { type?: unknown; id?: unknown; expectsReply?: unknown; runId?: unknown; childIndex?: unknown; expiresAt?: unknown };\n\t\tif (request.type !== \"subagent.supervisor.request\" || request.expectsReply !== true) continue;\n\t\tif (request.runId !== runId || request.childIndex !== childIndex || typeof request.id !== \"string\") continue;\n\t\tif (typeof request.expiresAt === \"number\" && request.expiresAt <= Date.now()) continue;\n\t\tif (!fs.existsSync(path.join(channelDir, \"replies\", `${safeSegment(request.id)}.json`))) return true;\n\t}\n\treturn false;\n}\n\nexport function hasOutstandingQuestionForChild(channelDir: string, childIndex: number, childId?: string): boolean {\n\treturn outstandingQuestionsForChild(channelDir, childIndex, childId).length > 0;\n}\n\nexport function incarnationMatches(expected: SupervisorChildIncarnation | undefined, actual: SupervisorChildIncarnation): boolean {\n\tif (!expected) return true;\n\treturn expected.pid === actual.pid && expected.readyAt === actual.readyAt;\n}\n\nfunction assertOwner(question: SupervisorQuestion, owner: SupervisorQuestionOwner): void {\n\tif (owner.runId !== question.runId || owner.childIndex !== question.childIndex || owner.childId !== question.childId) {\n\t\tthrow new Error(`Supervisor question '${question.id}' is not owned by this child.`);\n\t}\n\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) {\n\t\tthrow new Error(`Supervisor question '${question.id}' was bound to a different child incarnation.`);\n\t}\n}\n\nfunction ownerMatchesDelivered(channelDir: string, questionId: string, owner: SupervisorQuestionOwner): boolean {\n\tconst delivered = parseDeliveredRecord(tryReadJson(deliveredFile(channelDir, questionId)));\n\tif (!delivered) return true;\n\treturn delivered.pid === owner.pid && delivered.readyAt === owner.readyAt;\n}\n\nexport function markSupervisorQuestionDelivered(\n\tchannelDir: string,\n\tquestionId: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tassertOwner(current, owner);\n\twriteExclusiveJson(deliveredFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.delivered\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tpid: owner.pid,\n\t\treadyAt: owner.readyAt,\n\t} satisfies DeliveredRecord);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nfunction rejectLateOrDuplicate(channelDir: string, questionId: string, answer: string, now: number, terminal: TerminalRecord): never {\n\twriteExclusiveJson(lateFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.late-answer\",\n\t\tid: questionId,\n\t\tat: now,\n\t\tmessage: answer,\n\t} satisfies LateAnswerRecord);\n\tif (terminal.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\tthrow new Error(`Supervisor question '${questionId}' is ${terminal.state} and no longer accepts an answer.`);\n}\n\nexport function answerSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\tanswer: string,\n\towner: SupervisorQuestionOwner,\n\tnow = Date.now(),\n): SupervisorQuestion {\n\tconst trimmed = answer.trim();\n\tif (!trimmed) throw new Error(\"message is required for supervisor question replies.\");\n\tassertMessageSize(trimmed, \"answer\");\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current) throw new Error(`No supervisor question found for replyTo '${questionId}'.`);\n\tassertOwner(current, owner);\n\tif (!ownerMatchesDelivered(channelDir, questionId, owner)) {\n\t\tthrow new Error(`Supervisor question '${questionId}' was bound to a different child incarnation.`);\n\t}\n\tif (now > current.expiresAt) {\n\t\twriteTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now });\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal && terminal.state !== \"answered\") {\n\t\t\trejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\t}\n\t\tif (terminal?.state === \"answered\") throw new Error(`Supervisor question '${questionId}' was already answered.`);\n\t}\n\tconst existing = readTerminal(channelDir, questionId);\n\tif (existing) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, existing);\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"answered\", at: now, message: trimmed })) {\n\t\tconst terminal = readTerminal(channelDir, questionId);\n\t\tif (terminal) rejectLateOrDuplicate(channelDir, questionId, trimmed, now, terminal);\n\t\tthrow new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\t}\n\tconst answered = readSupervisorQuestion(channelDir, questionId);\n\tif (!answered) throw new Error(`Supervisor question '${questionId}' is no longer pending.`);\n\treturn answered;\n}\n\nexport function expireSupervisorQuestion(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current) || now <= current.expiresAt) return current && supervisorQuestionIsTerminal(current) ? current : undefined;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"expired\", at: now })) return readSupervisorQuestion(channelDir, questionId);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function cancelSupervisorQuestion(\n\tchannelDir: string,\n\tquestionId: string,\n\treason: string,\n\tnow = Date.now(),\n): SupervisorQuestion | undefined {\n\tconst current = readSupervisorQuestion(channelDir, questionId);\n\tif (!current || supervisorQuestionIsTerminal(current)) return current;\n\tif (!writeTerminal(channelDir, { type: \"subagent.supervisor.terminal\", id: questionId, state: \"cancelled\", at: now, reason: reason.trim() || \"cancelled\" })) {\n\t\treturn readSupervisorQuestion(channelDir, questionId);\n\t}\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function refreshSupervisorQuestionLifecycle(channelDir: string, now = Date.now()): SupervisorQuestion[] {\n\tconst changed: SupervisorQuestion[] = [];\n\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\tif (now > question.expiresAt) {\n\t\t\tconst expired = expireSupervisorQuestion(channelDir, question.id, now);\n\t\t\tif (expired && expired.expiredAt) changed.push(expired);\n\t\t}\n\t}\n\treturn changed;\n}\n\nexport function formatParentQuestionForChild(question: SupervisorQuestion): string {\n\treturn [\n\t\t`Parent question (${question.id})`,\n\t\t`Decision needed: ${question.reason}`,\n\t\t\"\",\n\t\tquestion.message,\n\t\t\"\",\n\t\t`Reply with: contact_supervisor({ action: \"reply\", replyTo: \"${question.id}\", message: \"...\" })`,\n\t\t\"Answer from current findings and uncertainty. Do not silently start extra investigation. Continue the assigned task after replying.\",\n\t].join(\"\\n\");\n}\n\nexport function formatSupervisorQuestionAnswer(question: SupervisorQuestion): string {\n\tconst state = supervisorQuestionPublicState(question);\n\tconst header = state === \"answered\"\n\t\t? `Subagent answer (${question.id})`\n\t\t: `Subagent question ${state} (${question.id})`;\n\tconst lines = [\n\t\theader,\n\t\t`From: ${question.childDescription ?? `Subagent ${question.childIndex + 1}`}`,\n\t\t`Decision: ${question.reason}`,\n\t];\n\tif (state === \"answered\" && question.answer?.trim()) {\n\t\tlines.push(\"\", question.answer.trim());\n\t} else if (question.cancelReason) {\n\t\tlines.push(\"\", question.cancelReason);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function registerQuestionWait(questionIds: Iterable<string>): () => void {\n\tconst ids = [...questionIds];\n\tfor (const id of ids) activeQuestionWaits.add(id);\n\treturn () => {\n\t\tfor (const id of ids) activeQuestionWaits.delete(id);\n\t};\n}\n\nexport function isQuestionWaitActive(questionId: string): boolean {\n\treturn activeQuestionWaits.has(questionId);\n}\n\nexport function claimQuestionNotification(channelDir: string, questionId: string, now = Date.now()): boolean {\n\treturn writeExclusiveJson(notifiedFile(channelDir, questionId), {\n\t\ttype: \"subagent.supervisor.notified\",\n\t\tid: questionId,\n\t\tat: now,\n\t} satisfies NotifiedRecord);\n}\n\nexport function markSupervisorQuestionNotified(channelDir: string, questionId: string, now = Date.now()): SupervisorQuestion | undefined {\n\tclaimQuestionNotification(channelDir, questionId, now);\n\treturn readSupervisorQuestion(channelDir, questionId);\n}\n\nexport function resetSupervisorQuestionTestState(): void {\n\tactiveQuestionWaits.clear();\n}\n\nexport function listSupervisorChannelDirs(): string[] {\n\tlet entries: fs.Dirent[];\n\ttry {\n\t\tentries = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true });\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow error;\n\t}\n\treturn entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(SUPERVISOR_CHANNEL_ROOT, entry.name));\n}\n\nexport function findSupervisorQuestion(questionId: string): { channelDir: string; question: SupervisorQuestion } | undefined {\n\tconst id = questionId.trim();\n\tif (!id) return undefined;\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tconst question = readSupervisorQuestion(channelDir, id);\n\t\tif (question) return { channelDir, question };\n\t}\n\treturn undefined;\n}\n\nexport function cancelPendingSupervisorQuestionsForOwner(input: {\n\tparentSessionId: string;\n\tparentGeneration?: number;\n\trunId?: string;\n\treason: string;\n\tnow?: number;\n}): SupervisorQuestion[] {\n\tif (!input.parentSessionId?.trim()) return [];\n\tconst now = input.now ?? Date.now();\n\tconst cancelled: SupervisorQuestion[] = [];\n\tfor (const channelDir of listSupervisorChannelDirs()) {\n\t\tfor (const question of listSupervisorQuestions(channelDir)) {\n\t\t\tif (supervisorQuestionIsTerminal(question)) continue;\n\t\t\tif (question.parentSessionId !== input.parentSessionId) continue;\n\t\t\tif (input.parentGeneration !== undefined && question.parentGeneration !== input.parentGeneration) continue;\n\t\t\tif (input.runId && question.runId !== input.runId) continue;\n\t\t\tconst next = cancelSupervisorQuestion(channelDir, question.id, input.reason, now);\n\t\t\tif (next?.cancelledAt) cancelled.push(next);\n\t\t}\n\t}\n\treturn cancelled;\n}\n\nexport function pendingSupervisorQuestionsForDelivery(channelDir: string, owner: SupervisorQuestionOwner, now = Date.now()): SupervisorQuestion[] {\n\trefreshSupervisorQuestionLifecycle(channelDir, now);\n\treturn listSupervisorQuestions(channelDir).filter((question) => {\n\t\tif (supervisorQuestionIsTerminal(question)) return false;\n\t\tif (question.deliveredAt) return false;\n\t\tif (question.runId !== owner.runId || question.childIndex !== owner.childIndex || question.childId !== owner.childId) return false;\n\t\tif (!incarnationMatches(question.childIncarnation, { pid: owner.pid, readyAt: owner.readyAt })) return false;\n\t\treturn now <= question.expiresAt;\n\t});\n}\n"]}
|
|
@@ -9,6 +9,7 @@ export interface AutoDrainDeps {
|
|
|
9
9
|
now?: () => number;
|
|
10
10
|
wait?: (params: SubagentWaitParams, signal: AbortSignal | undefined, deps: SubagentWaitDeps) => Promise<AgentToolResult<Details>>;
|
|
11
11
|
hasWork?: (sessionId: string, nowMs: number) => boolean;
|
|
12
|
+
hasPendingMessages?: () => boolean;
|
|
12
13
|
}
|
|
13
14
|
/** Drain all work owned by the current headless session, including work added while draining. */
|
|
14
15
|
export declare function drainOutstandingWork(deps: AutoDrainDeps): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-drain.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/background/auto-drain.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAA0B,KAAK,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEjG,OAAO,EAAoB,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzH,eAAO,MAAM,6BAA6B,QAAiB,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,CACN,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,gBAAgB,KAClB,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"auto-drain.d.ts","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/background/auto-drain.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAA0B,KAAK,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEjG,OAAO,EAAoB,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzH,eAAO,MAAM,6BAA6B,QAAiB,CAAC;AAE5D,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,CACN,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,gBAAgB,KAClB,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACxD,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC;CACnC;AAgBD,iGAAiG;AACjG,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CA+B7E","sourcesContent":["// @ts-nocheck\nimport type { AgentToolResult } from \"@ashx-j/lunr-agent\";\nimport { snapshotBackgroundWork } from \"../../api/background-work.ts\";\nimport { ASYNC_DIR, RESULTS_DIR, type Details, type SubagentState } from \"../../shared/types.ts\";\nimport { listAsyncRuns } from \"./async-status.ts\";\nimport { waitForSubagents, type SubagentWaitDeps, type SubagentWaitParams, type WaitEventBus } from \"./subagent-wait.ts\";\n\nexport const DEFAULT_AUTO_DRAIN_TIMEOUT_MS = 30 * 60 * 1000;\n\nexport interface AutoDrainDeps {\n\tstate: SubagentState;\n\tevents?: WaitEventBus;\n\ttimeoutMs?: number;\n\tnow?: () => number;\n\twait?: (\n\t\tparams: SubagentWaitParams,\n\t\tsignal: AbortSignal | undefined,\n\t\tdeps: SubagentWaitDeps,\n\t) => Promise<AgentToolResult<Details>>;\n\thasWork?: (sessionId: string, nowMs: number) => boolean;\n\thasPendingMessages?: () => boolean;\n}\n\nfunction resultText(value: AgentToolResult<Details>): string {\n\treturn value.content.map((part) => part.type === \"text\" ? part.text : \"\").join(\" \").trim();\n}\n\nfunction hasOutstandingWork(sessionId: string, nowMs: number): boolean {\n\tconst asyncRuns = listAsyncRuns(ASYNC_DIR, {\n\t\tstates: [\"queued\", \"running\"],\n\t\tsessionId,\n\t\tresultsDir: RESULTS_DIR,\n\t\tnow: () => nowMs,\n\t});\n\treturn asyncRuns.length > 0 || snapshotBackgroundWork(sessionId, nowMs).items.length > 0;\n}\n\n/** Drain all work owned by the current headless session, including work added while draining. */\nexport async function drainOutstandingWork(deps: AutoDrainDeps): Promise<void> {\n\tconst sessionId = deps.state.currentSessionId;\n\tif (!sessionId) throw new Error(\"Cannot auto-drain background work without an active session identity.\");\n\tconst now = deps.now ?? Date.now;\n\tconst timeoutMs = deps.timeoutMs ?? DEFAULT_AUTO_DRAIN_TIMEOUT_MS;\n\tif (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new Error(\"Auto-drain timeoutMs must be a positive finite number.\");\n\tconst deadlineAt = now() + timeoutMs;\n\tconst hasWork = deps.hasWork ?? hasOutstandingWork;\n\tconst wait = deps.wait ?? waitForSubagents;\n\n\twhile (!deps.hasPendingMessages?.() && hasWork(sessionId, now())) {\n\t\tconst remainingMs = deadlineAt - now();\n\t\tif (remainingMs <= 0) {\n\t\t\tthrow new Error(`Auto-drain timed out after ${timeoutMs}ms with background work still active in session '${sessionId}'.`);\n\t\t}\n\t\tconst waitResult = await wait(\n\t\t\t{ all: true, timeoutMs: remainingMs },\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\tstate: deps.state,\n\t\t\t\tevents: deps.events,\n\t\t\t\tnow,\n\t\t\t\tstopOnAttention: false,\n\t\t\t\tshouldYield: deps.hasPendingMessages,\n\t\t\t\tfailOnFailedRuns: true,\n\t\t\t},\n\t\t);\n\t\tif (waitResult.isError) {\n\t\t\tthrow new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || \"subagent_wait returned an error without details\"}.`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -27,7 +27,7 @@ export async function drainOutstandingWork(deps) {
|
|
|
27
27
|
const deadlineAt = now() + timeoutMs;
|
|
28
28
|
const hasWork = deps.hasWork ?? hasOutstandingWork;
|
|
29
29
|
const wait = deps.wait ?? waitForSubagents;
|
|
30
|
-
while (hasWork(sessionId, now())) {
|
|
30
|
+
while (!deps.hasPendingMessages?.() && hasWork(sessionId, now())) {
|
|
31
31
|
const remainingMs = deadlineAt - now();
|
|
32
32
|
if (remainingMs <= 0) {
|
|
33
33
|
throw new Error(`Auto-drain timed out after ${timeoutMs}ms with background work still active in session '${sessionId}'.`);
|
|
@@ -37,6 +37,7 @@ export async function drainOutstandingWork(deps) {
|
|
|
37
37
|
events: deps.events,
|
|
38
38
|
now,
|
|
39
39
|
stopOnAttention: false,
|
|
40
|
+
shouldYield: deps.hasPendingMessages,
|
|
40
41
|
failOnFailedRuns: true,
|
|
41
42
|
});
|
|
42
43
|
if (waitResult.isError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-drain.js","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/background/auto-drain.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAoC,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAqE,MAAM,oBAAoB,CAAC;AAEzH,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"auto-drain.js","sourceRoot":"","sources":["../../../../../../src/builtin-extensions/pi-subagents/src/runs/background/auto-drain.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAoC,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAqE,MAAM,oBAAoB,CAAC;AAEzH,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAgB5D,SAAS,UAAU,CAAC,KAA+B,EAAU;IAC5D,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAAA,CAC3F;AAED,SAAS,kBAAkB,CAAC,SAAiB,EAAE,KAAa,EAAW;IACtE,MAAM,SAAS,GAAG,aAAa,CAAC,SAAS,EAAE;QAC1C,MAAM,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;QAC7B,SAAS;QACT,UAAU,EAAE,WAAW;QACvB,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK;KAChB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,sBAAsB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAAA,CACzF;AAED,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,IAAmB,EAAiB;IAC9E,MAAM,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AK,CAAC,kCAAkC,SAAS,MAAM,UAAU,CAAC,UAAU,CAAC,IAAI,iDAAiD,GAAG,CAAC,CAAC;QAClJ,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["// @ts-nocheck\nimport type { AgentToolResult } from \"@ashx-j/lunr-agent\";\nimport { snapshotBackgroundWork } from \"../../api/background-work.ts\";\nimport { ASYNC_DIR, RESULTS_DIR, type Details, type SubagentState } from \"../../shared/types.ts\";\nimport { listAsyncRuns } from \"./async-status.ts\";\nimport { waitForSubagents, type SubagentWaitDeps, type SubagentWaitParams, type WaitEventBus } from \"./subagent-wait.ts\";\n\nexport const DEFAULT_AUTO_DRAIN_TIMEOUT_MS = 30 * 60 * 1000;\n\nexport interface AutoDrainDeps {\n\tstate: SubagentState;\n\tevents?: WaitEventBus;\n\ttimeoutMs?: number;\n\tnow?: () => number;\n\twait?: (\n\t\tparams: SubagentWaitParams,\n\t\tsignal: AbortSignal | undefined,\n\t\tdeps: SubagentWaitDeps,\n\t) => Promise<AgentToolResult<Details>>;\n\thasWork?: (sessionId: string, nowMs: number) => boolean;\n\thasPendingMessages?: () => boolean;\n}\n\nfunction resultText(value: AgentToolResult<Details>): string {\n\treturn value.content.map((part) => part.type === \"text\" ? part.text : \"\").join(\" \").trim();\n}\n\nfunction hasOutstandingWork(sessionId: string, nowMs: number): boolean {\n\tconst asyncRuns = listAsyncRuns(ASYNC_DIR, {\n\t\tstates: [\"queued\", \"running\"],\n\t\tsessionId,\n\t\tresultsDir: RESULTS_DIR,\n\t\tnow: () => nowMs,\n\t});\n\treturn asyncRuns.length > 0 || snapshotBackgroundWork(sessionId, nowMs).items.length > 0;\n}\n\n/** Drain all work owned by the current headless session, including work added while draining. */\nexport async function drainOutstandingWork(deps: AutoDrainDeps): Promise<void> {\n\tconst sessionId = deps.state.currentSessionId;\n\tif (!sessionId) throw new Error(\"Cannot auto-drain background work without an active session identity.\");\n\tconst now = deps.now ?? Date.now;\n\tconst timeoutMs = deps.timeoutMs ?? DEFAULT_AUTO_DRAIN_TIMEOUT_MS;\n\tif (!Number.isFinite(timeoutMs) || timeoutMs <= 0) throw new Error(\"Auto-drain timeoutMs must be a positive finite number.\");\n\tconst deadlineAt = now() + timeoutMs;\n\tconst hasWork = deps.hasWork ?? hasOutstandingWork;\n\tconst wait = deps.wait ?? waitForSubagents;\n\n\twhile (!deps.hasPendingMessages?.() && hasWork(sessionId, now())) {\n\t\tconst remainingMs = deadlineAt - now();\n\t\tif (remainingMs <= 0) {\n\t\t\tthrow new Error(`Auto-drain timed out after ${timeoutMs}ms with background work still active in session '${sessionId}'.`);\n\t\t}\n\t\tconst waitResult = await wait(\n\t\t\t{ all: true, timeoutMs: remainingMs },\n\t\t\tundefined,\n\t\t\t{\n\t\t\t\tstate: deps.state,\n\t\t\t\tevents: deps.events,\n\t\t\t\tnow,\n\t\t\t\tstopOnAttention: false,\n\t\t\t\tshouldYield: deps.hasPendingMessages,\n\t\t\t\tfailOnFailedRuns: true,\n\t\t\t},\n\t\t);\n\t\tif (waitResult.isError) {\n\t\t\tthrow new Error(`Auto-drain failed for session '${sessionId}': ${resultText(waitResult) || \"subagent_wait returned an error without details\"}.`);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -73,6 +73,9 @@ export interface SubagentWaitDeps {
|
|
|
73
73
|
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
74
74
|
/** Internal auto-drain mode waits through needs-attention states. */
|
|
75
75
|
stopOnAttention?: boolean;
|
|
76
|
+
shouldYield?: () => boolean;
|
|
77
|
+
/** True when interactive input released only this local wait. */
|
|
78
|
+
wasInterrupted?: () => boolean;
|
|
76
79
|
/** Internal auto-drain mode surfaces failed terminal subagent runs as errors. */
|
|
77
80
|
failOnFailedRuns?: boolean;
|
|
78
81
|
/** Injectable provider protocol surfaces for deterministic tests. */
|