@0xmaxma/claude-gateway 2.0.9 → 2.0.11
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/README.md +16 -1
- package/config.template.json +6 -4
- package/dist/agent/runner.d.ts +126 -11
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +102 -10
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/skill-learning/reviewer.d.ts.map +1 -1
- package/dist/agent/skill-learning/reviewer.js +1 -2
- package/dist/agent/skill-learning/reviewer.js.map +1 -1
- package/dist/api/browser-bindings-router.d.ts +6 -0
- package/dist/api/browser-bindings-router.d.ts.map +1 -0
- package/dist/api/browser-bindings-router.js +150 -0
- package/dist/api/browser-bindings-router.js.map +1 -0
- package/dist/api/capabilities.d.ts +53 -0
- package/dist/api/capabilities.d.ts.map +1 -0
- package/dist/api/capabilities.js +66 -0
- package/dist/api/capabilities.js.map +1 -0
- package/dist/api/connectors-router.js +1 -1
- package/dist/api/connectors-router.js.map +1 -1
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +38 -14
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/gateway-version.d.ts +9 -0
- package/dist/api/gateway-version.d.ts.map +1 -0
- package/dist/api/gateway-version.js +57 -0
- package/dist/api/gateway-version.js.map +1 -0
- package/dist/api/jev-router.d.ts +8 -0
- package/dist/api/jev-router.d.ts.map +1 -0
- package/dist/api/jev-router.js +128 -0
- package/dist/api/jev-router.js.map +1 -0
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +53 -6
- package/dist/api/router.js.map +1 -1
- package/dist/api/voice-router.d.ts.map +1 -1
- package/dist/api/voice-router.js +42 -3
- package/dist/api/voice-router.js.map +1 -1
- package/dist/automation/browser-command.d.ts +79 -0
- package/dist/automation/browser-command.d.ts.map +1 -0
- package/dist/automation/browser-command.js +118 -0
- package/dist/automation/browser-command.js.map +1 -0
- package/dist/automation/browser-outcome.d.ts +3 -0
- package/dist/automation/browser-outcome.d.ts.map +1 -0
- package/dist/automation/browser-outcome.js +78 -0
- package/dist/automation/browser-outcome.js.map +1 -0
- package/dist/automation/browser-steps.d.ts +33 -0
- package/dist/automation/browser-steps.d.ts.map +1 -0
- package/dist/automation/browser-steps.js +293 -0
- package/dist/automation/browser-steps.js.map +1 -0
- package/dist/automation/browser-trace.d.ts +60 -0
- package/dist/automation/browser-trace.d.ts.map +1 -0
- package/dist/automation/browser-trace.js +24 -0
- package/dist/automation/browser-trace.js.map +1 -0
- package/dist/automation/browser-use.d.ts +210 -0
- package/dist/automation/browser-use.d.ts.map +1 -0
- package/dist/automation/browser-use.js +1271 -0
- package/dist/automation/browser-use.js.map +1 -0
- package/dist/automation/command-speech.d.ts +33 -0
- package/dist/automation/command-speech.d.ts.map +1 -0
- package/dist/automation/command-speech.js +117 -0
- package/dist/automation/command-speech.js.map +1 -0
- package/dist/automation/command-steps.d.ts +35 -0
- package/dist/automation/command-steps.d.ts.map +1 -0
- package/dist/automation/command-steps.js +155 -0
- package/dist/automation/command-steps.js.map +1 -0
- package/dist/automation/computer-choice-ids.d.ts +7 -0
- package/dist/automation/computer-choice-ids.d.ts.map +1 -0
- package/dist/automation/computer-choice-ids.js +24 -0
- package/dist/automation/computer-choice-ids.js.map +1 -0
- package/dist/automation/computer-command.d.ts +126 -0
- package/dist/automation/computer-command.d.ts.map +1 -0
- package/dist/automation/computer-command.js +313 -0
- package/dist/automation/computer-command.js.map +1 -0
- package/dist/automation/computer-outcome.d.ts +8 -0
- package/dist/automation/computer-outcome.d.ts.map +1 -0
- package/dist/automation/computer-outcome.js +82 -0
- package/dist/automation/computer-outcome.js.map +1 -0
- package/dist/automation/computer-policy.d.ts +84 -0
- package/dist/automation/computer-policy.d.ts.map +1 -0
- package/dist/automation/computer-policy.js +56 -0
- package/dist/automation/computer-policy.js.map +1 -0
- package/dist/automation/computer-safety.d.ts +27 -0
- package/dist/automation/computer-safety.d.ts.map +1 -0
- package/dist/automation/computer-safety.js +47 -0
- package/dist/automation/computer-safety.js.map +1 -0
- package/dist/automation/computer-steps.d.ts +20 -0
- package/dist/automation/computer-steps.d.ts.map +1 -0
- package/dist/automation/computer-steps.js +251 -0
- package/dist/automation/computer-steps.js.map +1 -0
- package/dist/automation/computer-use.d.ts +315 -0
- package/dist/automation/computer-use.d.ts.map +1 -0
- package/dist/automation/computer-use.js +864 -0
- package/dist/automation/computer-use.js.map +1 -0
- package/dist/automation/direct-command.d.ts +51 -0
- package/dist/automation/direct-command.d.ts.map +1 -0
- package/dist/automation/direct-command.js +152 -0
- package/dist/automation/direct-command.js.map +1 -0
- package/dist/automation/interrupt.d.ts +4 -0
- package/dist/automation/interrupt.d.ts.map +1 -0
- package/dist/automation/interrupt.js +26 -0
- package/dist/automation/interrupt.js.map +1 -0
- package/dist/build-provenance.json +4 -4
- package/dist/child-env-exclusions.d.ts +4 -0
- package/dist/child-env-exclusions.d.ts.map +1 -0
- package/dist/child-env-exclusions.js +23 -0
- package/dist/child-env-exclusions.js.map +1 -0
- package/dist/cli/startup-diagnostics.d.ts.map +1 -1
- package/dist/cli/startup-diagnostics.js +19 -0
- package/dist/cli/startup-diagnostics.js.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +4 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/config/reload-policy.d.ts.map +1 -1
- package/dist/config/reload-policy.js +2 -1
- package/dist/config/reload-policy.js.map +1 -1
- package/dist/jev/automatic-browser-bindings.d.ts +15 -0
- package/dist/jev/automatic-browser-bindings.d.ts.map +1 -0
- package/dist/jev/automatic-browser-bindings.js +115 -0
- package/dist/jev/automatic-browser-bindings.js.map +1 -0
- package/dist/jev/browser-connector.d.ts +29 -0
- package/dist/jev/browser-connector.d.ts.map +1 -0
- package/dist/jev/browser-connector.js +347 -0
- package/dist/jev/browser-connector.js.map +1 -0
- package/dist/jev/browser-consent.d.ts +6 -0
- package/dist/jev/browser-consent.d.ts.map +1 -0
- package/dist/jev/browser-consent.js +50 -0
- package/dist/jev/browser-consent.js.map +1 -0
- package/dist/jev/browser-contract.d.ts +215 -0
- package/dist/jev/browser-contract.d.ts.map +1 -0
- package/dist/jev/browser-contract.js +10 -0
- package/dist/jev/browser-contract.js.map +1 -0
- package/dist/jev/browser-evidence-summary.d.ts +73 -0
- package/dist/jev/browser-evidence-summary.d.ts.map +1 -0
- package/dist/jev/browser-evidence-summary.js +22 -0
- package/dist/jev/browser-evidence-summary.js.map +1 -0
- package/dist/jev/browser-module-import.d.ts +3 -0
- package/dist/jev/browser-module-import.d.ts.map +1 -0
- package/dist/jev/browser-module-import.js +6 -0
- package/dist/jev/browser-module-import.js.map +1 -0
- package/dist/jev/child-env.d.ts +11 -0
- package/dist/jev/child-env.d.ts.map +1 -0
- package/dist/jev/child-env.js +60 -0
- package/dist/jev/child-env.js.map +1 -0
- package/dist/jev/computer-connector.d.ts +34 -0
- package/dist/jev/computer-connector.d.ts.map +1 -0
- package/dist/jev/computer-connector.js +82 -0
- package/dist/jev/computer-connector.js.map +1 -0
- package/dist/jev/computer-inputs.d.ts +41 -0
- package/dist/jev/computer-inputs.d.ts.map +1 -0
- package/dist/jev/computer-inputs.js +7 -0
- package/dist/jev/computer-inputs.js.map +1 -0
- package/dist/jev/index.d.ts +6 -0
- package/dist/jev/index.d.ts.map +1 -0
- package/dist/jev/index.js +25 -0
- package/dist/jev/index.js.map +1 -0
- package/dist/jev/relay-grants.d.ts +9 -0
- package/dist/jev/relay-grants.d.ts.map +1 -0
- package/dist/jev/relay-grants.js +49 -0
- package/dist/jev/relay-grants.js.map +1 -0
- package/dist/jev/service.d.ts +27 -0
- package/dist/jev/service.d.ts.map +1 -0
- package/dist/jev/service.js +264 -0
- package/dist/jev/service.js.map +1 -0
- package/dist/jev/thinking-provider.d.ts +7 -0
- package/dist/jev/thinking-provider.d.ts.map +1 -0
- package/dist/jev/thinking-provider.js +25 -0
- package/dist/jev/thinking-provider.js.map +1 -0
- package/dist/jev/types.d.ts +124 -0
- package/dist/jev/types.d.ts.map +1 -0
- package/dist/jev/types.js +13 -0
- package/dist/jev/types.js.map +1 -0
- package/dist/jev/validation.d.ts +45 -0
- package/dist/jev/validation.d.ts.map +1 -0
- package/dist/jev/validation.js +179 -0
- package/dist/jev/validation.js.map +1 -0
- package/dist/load-dotenv.d.ts.map +1 -1
- package/dist/load-dotenv.js +5 -1
- package/dist/load-dotenv.js.map +1 -1
- package/dist/orchestration/agent-tool-schemas.d.ts.map +1 -1
- package/dist/orchestration/agent-tool-schemas.js +12 -7
- package/dist/orchestration/agent-tool-schemas.js.map +1 -1
- package/dist/orchestration/background-work.d.ts +1 -0
- package/dist/orchestration/background-work.d.ts.map +1 -1
- package/dist/orchestration/background-work.js +1 -0
- package/dist/orchestration/background-work.js.map +1 -1
- package/dist/orchestration/bridge.d.ts +4 -0
- package/dist/orchestration/bridge.d.ts.map +1 -1
- package/dist/orchestration/bridge.js +227 -41
- package/dist/orchestration/bridge.js.map +1 -1
- package/dist/orchestration/browser-fields.d.ts +25 -0
- package/dist/orchestration/browser-fields.d.ts.map +1 -0
- package/dist/orchestration/browser-fields.js +23 -0
- package/dist/orchestration/browser-fields.js.map +1 -0
- package/dist/orchestration/browser-routing.d.ts +1 -1
- package/dist/orchestration/browser-routing.d.ts.map +1 -1
- package/dist/orchestration/browser-routing.js +7 -3
- package/dist/orchestration/browser-routing.js.map +1 -1
- package/dist/orchestration/capabilities.d.ts +5 -2
- package/dist/orchestration/capabilities.d.ts.map +1 -1
- package/dist/orchestration/capabilities.js +24 -24
- package/dist/orchestration/capabilities.js.map +1 -1
- package/dist/orchestration/channel-controls.js +1 -1
- package/dist/orchestration/channel-controls.js.map +1 -1
- package/dist/orchestration/cli-skills.d.ts +1 -1
- package/dist/orchestration/cli-skills.d.ts.map +1 -1
- package/dist/orchestration/cli-skills.js +16 -10
- package/dist/orchestration/cli-skills.js.map +1 -1
- package/dist/orchestration/computer-end-screenshot.d.ts +11 -0
- package/dist/orchestration/computer-end-screenshot.d.ts.map +1 -0
- package/dist/orchestration/computer-end-screenshot.js +37 -0
- package/dist/orchestration/computer-end-screenshot.js.map +1 -0
- package/dist/orchestration/computer-prompt.d.ts +6 -0
- package/dist/orchestration/computer-prompt.d.ts.map +1 -0
- package/dist/orchestration/computer-prompt.js +24 -0
- package/dist/orchestration/computer-prompt.js.map +1 -0
- package/dist/orchestration/config.d.ts +17 -0
- package/dist/orchestration/config.d.ts.map +1 -1
- package/dist/orchestration/config.js +10 -4
- package/dist/orchestration/config.js.map +1 -1
- package/dist/orchestration/container-tool-schemas.d.ts +47 -3
- package/dist/orchestration/container-tool-schemas.d.ts.map +1 -1
- package/dist/orchestration/container-tool-schemas.js +41 -6
- package/dist/orchestration/container-tool-schemas.js.map +1 -1
- package/dist/orchestration/container.d.ts +4 -1
- package/dist/orchestration/container.d.ts.map +1 -1
- package/dist/orchestration/container.js +48 -29
- package/dist/orchestration/container.js.map +1 -1
- package/dist/orchestration/context-footprint.d.ts +1 -1
- package/dist/orchestration/context-footprint.d.ts.map +1 -1
- package/dist/orchestration/context-footprint.js +5 -5
- package/dist/orchestration/context-footprint.js.map +1 -1
- package/dist/orchestration/control-notification.d.ts +6 -0
- package/dist/orchestration/control-notification.d.ts.map +1 -0
- package/dist/orchestration/control-notification.js +23 -0
- package/dist/orchestration/control-notification.js.map +1 -0
- package/dist/orchestration/dashboard-reader-worker.js +2 -2
- package/dist/orchestration/dashboard-reader-worker.js.map +1 -1
- package/dist/orchestration/execution-observation.d.ts +3 -0
- package/dist/orchestration/execution-observation.d.ts.map +1 -1
- package/dist/orchestration/execution-observation.js.map +1 -1
- package/dist/orchestration/gateway-tasks/browser.d.ts +59 -0
- package/dist/orchestration/gateway-tasks/browser.d.ts.map +1 -0
- package/dist/orchestration/gateway-tasks/browser.js +426 -0
- package/dist/orchestration/gateway-tasks/browser.js.map +1 -0
- package/dist/orchestration/gateway-tasks/computer-context.d.ts +6 -0
- package/dist/orchestration/gateway-tasks/computer-context.d.ts.map +1 -0
- package/dist/orchestration/gateway-tasks/computer-context.js +19 -0
- package/dist/orchestration/gateway-tasks/computer-context.js.map +1 -0
- package/dist/orchestration/gateway-tasks/computer.d.ts +123 -0
- package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -0
- package/dist/orchestration/gateway-tasks/computer.js +519 -0
- package/dist/orchestration/gateway-tasks/computer.js.map +1 -0
- package/dist/orchestration/gateway-tasks/controller.d.ts +40 -6
- package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/controller.js +118 -12
- package/dist/orchestration/gateway-tasks/controller.js.map +1 -1
- package/dist/orchestration/gateway-tasks/safemode.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/safemode.js +2 -1
- package/dist/orchestration/gateway-tasks/safemode.js.map +1 -1
- package/dist/orchestration/jev-gateway.d.ts +25 -0
- package/dist/orchestration/jev-gateway.d.ts.map +1 -0
- package/dist/orchestration/jev-gateway.js +103 -0
- package/dist/orchestration/jev-gateway.js.map +1 -0
- package/dist/orchestration/jev-tool.d.ts +45 -0
- package/dist/orchestration/jev-tool.d.ts.map +1 -0
- package/dist/orchestration/jev-tool.js +10 -0
- package/dist/orchestration/jev-tool.js.map +1 -0
- package/dist/orchestration/live-execution-input.d.ts +26 -0
- package/dist/orchestration/live-execution-input.d.ts.map +1 -0
- package/dist/orchestration/live-execution-input.js +70 -0
- package/dist/orchestration/live-execution-input.js.map +1 -0
- package/dist/orchestration/notification-mailbox.d.ts.map +1 -1
- package/dist/orchestration/notification-mailbox.js +5 -2
- package/dist/orchestration/notification-mailbox.js.map +1 -1
- package/dist/orchestration/process-activity.d.ts +4 -2
- package/dist/orchestration/process-activity.d.ts.map +1 -1
- package/dist/orchestration/process-activity.js +31 -42
- package/dist/orchestration/process-activity.js.map +1 -1
- package/dist/orchestration/process-platform.d.ts +72 -0
- package/dist/orchestration/process-platform.d.ts.map +1 -0
- package/dist/orchestration/process-platform.js +396 -0
- package/dist/orchestration/process-platform.js.map +1 -0
- package/dist/orchestration/process-supervisor.d.ts +31 -7
- package/dist/orchestration/process-supervisor.d.ts.map +1 -1
- package/dist/orchestration/process-supervisor.js +89 -61
- package/dist/orchestration/process-supervisor.js.map +1 -1
- package/dist/orchestration/process-turn.d.ts +8 -0
- package/dist/orchestration/process-turn.d.ts.map +1 -1
- package/dist/orchestration/process-turn.js +97 -13
- package/dist/orchestration/process-turn.js.map +1 -1
- package/dist/orchestration/progress-review.d.ts +1 -1
- package/dist/orchestration/progress-review.d.ts.map +1 -1
- package/dist/orchestration/progress-review.js +5 -1
- package/dist/orchestration/progress-review.js.map +1 -1
- package/dist/orchestration/report-fidelity.d.ts +31 -0
- package/dist/orchestration/report-fidelity.d.ts.map +1 -0
- package/dist/orchestration/report-fidelity.js +34 -0
- package/dist/orchestration/report-fidelity.js.map +1 -0
- package/dist/orchestration/response-errors.d.ts.map +1 -1
- package/dist/orchestration/response-errors.js +1 -0
- package/dist/orchestration/response-errors.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +51 -1
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +404 -33
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/skill-catalog-budget.d.ts +6 -0
- package/dist/orchestration/skill-catalog-budget.d.ts.map +1 -0
- package/dist/orchestration/skill-catalog-budget.js +9 -0
- package/dist/orchestration/skill-catalog-budget.js.map +1 -0
- package/dist/orchestration/skills.d.ts +4 -2
- package/dist/orchestration/skills.d.ts.map +1 -1
- package/dist/orchestration/skills.js +44 -3
- package/dist/orchestration/skills.js.map +1 -1
- package/dist/orchestration/speech.d.ts +1 -1
- package/dist/orchestration/speech.d.ts.map +1 -1
- package/dist/orchestration/speech.js +1 -1
- package/dist/orchestration/store.d.ts +1 -0
- package/dist/orchestration/store.d.ts.map +1 -1
- package/dist/orchestration/store.js +2 -0
- package/dist/orchestration/store.js.map +1 -1
- package/dist/orchestration/task-controls.d.ts +78 -8
- package/dist/orchestration/task-controls.d.ts.map +1 -1
- package/dist/orchestration/task-controls.js +6 -1
- package/dist/orchestration/task-controls.js.map +1 -1
- package/dist/orchestration/task-questions.js +2 -2
- package/dist/orchestration/task-questions.js.map +1 -1
- package/dist/orchestration/tasks/automation-session.d.ts +25 -0
- package/dist/orchestration/tasks/automation-session.d.ts.map +1 -0
- package/dist/orchestration/tasks/automation-session.js +68 -0
- package/dist/orchestration/tasks/automation-session.js.map +1 -0
- package/dist/orchestration/tasks/driver.d.ts.map +1 -1
- package/dist/orchestration/tasks/driver.js +7 -5
- package/dist/orchestration/tasks/driver.js.map +1 -1
- package/dist/orchestration/tasks/failure.d.ts +6 -0
- package/dist/orchestration/tasks/failure.d.ts.map +1 -1
- package/dist/orchestration/tasks/failure.js +26 -2
- package/dist/orchestration/tasks/failure.js.map +1 -1
- package/dist/orchestration/tasks/scheduler.d.ts +1 -1
- package/dist/orchestration/tasks/scheduler.d.ts.map +1 -1
- package/dist/orchestration/tasks/scheduler.js +3 -1
- package/dist/orchestration/tasks/scheduler.js.map +1 -1
- package/dist/orchestration/tasks/service.d.ts +68 -7
- package/dist/orchestration/tasks/service.d.ts.map +1 -1
- package/dist/orchestration/tasks/service.js +647 -45
- package/dist/orchestration/tasks/service.js.map +1 -1
- package/dist/orchestration/types.d.ts +90 -3
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/types.js.map +1 -1
- package/dist/safemode/native.d.ts.map +1 -1
- package/dist/safemode/native.js +8 -3
- package/dist/safemode/native.js.map +1 -1
- package/dist/session/claude-bin.d.ts +29 -0
- package/dist/session/claude-bin.d.ts.map +1 -1
- package/dist/session/claude-bin.js +63 -12
- package/dist/session/claude-bin.js.map +1 -1
- package/dist/session/codex-extension-discovery.d.ts.map +1 -1
- package/dist/session/codex-extension-discovery.js +4 -2
- package/dist/session/codex-extension-discovery.js.map +1 -1
- package/dist/session/codex-native-mcp-client.d.ts.map +1 -1
- package/dist/session/codex-native-mcp-client.js +2 -1
- package/dist/session/codex-native-mcp-client.js.map +1 -1
- package/dist/session/codex-process.d.ts +4 -0
- package/dist/session/codex-process.d.ts.map +1 -1
- package/dist/session/codex-process.js +16 -6
- package/dist/session/codex-process.js.map +1 -1
- package/dist/session/compactor.d.ts.map +1 -1
- package/dist/session/compactor.js +1 -2
- package/dist/session/compactor.js.map +1 -1
- package/dist/session/process.d.ts +18 -0
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +175 -67
- package/dist/session/process.js.map +1 -1
- package/dist/session/runtime-profile.d.ts +18 -0
- package/dist/session/runtime-profile.d.ts.map +1 -1
- package/dist/session/runtime-profile.js +23 -0
- package/dist/session/runtime-profile.js.map +1 -1
- package/dist/session/worker-extensions.d.ts.map +1 -1
- package/dist/session/worker-extensions.js +4 -3
- package/dist/session/worker-extensions.js.map +1 -1
- package/dist/shell/claude-pty-shell.js +5 -4
- package/dist/shell/claude-pty-shell.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/dashboard-client.d.ts.map +1 -1
- package/dist/ui/dashboard-client.js +33 -3
- package/dist/ui/dashboard-client.js.map +1 -1
- package/dist/ui/web-ui.js +1 -1
- package/dist/utils/paths.d.ts +8 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +11 -0
- package/dist/utils/paths.js.map +1 -1
- package/lib/automation/browser-thinking.cjs +9 -0
- package/lib/automation/browser-thinking.d.cts +2 -0
- package/lib/automation/computer-thinking.cjs +10 -0
- package/lib/automation/computer-thinking.d.cts +2 -0
- package/lib/automation/index.cjs +47 -0
- package/lib/automation/index.d.cts +3 -0
- package/lib/automation/reasoning-instructions.cjs +5 -0
- package/lib/automation/thinking.cjs +35 -0
- package/lib/automation/thinking.d.cts +2 -0
- package/mcp/capability-catalog.ts +2 -2
- package/mcp/server.ts +1 -1
- package/mcp/tools/tasks/module.ts +9 -0
- package/mcp/tools/telegram/receiver-server.ts +4 -2
- package/package.json +6 -4
package/dist/session/process.js
CHANGED
|
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.SessionProcess = exports.INTERRUPTED_NO_REPLY_TEXT = exports.MAX_HISTORY_MESSAGES = void 0;
|
|
40
40
|
exports.resolveMaxHistoryMessages = resolveMaxHistoryMessages;
|
|
41
|
+
const child_env_1 = require("../jev/child-env");
|
|
41
42
|
const worker_environment_1 = require("./worker-environment");
|
|
42
43
|
const process_diagnostics_1 = require("./process-diagnostics");
|
|
43
44
|
const managed_connectors_1 = require("./managed-connectors");
|
|
@@ -53,10 +54,11 @@ const runtime_profile_1 = require("./runtime-profile");
|
|
|
53
54
|
const string_decoder_1 = require("string_decoder");
|
|
54
55
|
const process_supervisor_1 = require("../orchestration/process-supervisor");
|
|
55
56
|
const capacity_1 = require("../orchestration/capacity");
|
|
57
|
+
const types_1 = require("../orchestration/types");
|
|
56
58
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
57
59
|
const knowledge_1 = require("../agent/knowledge");
|
|
58
60
|
const config_1 = require("../agent/dreaming/config");
|
|
59
|
-
const
|
|
61
|
+
const types_2 = require("../history/types");
|
|
60
62
|
const logger_1 = require("../logger");
|
|
61
63
|
const pty_stream_registry_1 = require("../shell/pty-stream-registry");
|
|
62
64
|
const screen_1 = require("../shell/screen");
|
|
@@ -252,6 +254,10 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
252
254
|
runtimeProfile) {
|
|
253
255
|
super();
|
|
254
256
|
this.runtimeProfile = runtimeProfile;
|
|
257
|
+
/** Bumped by stop(): a spawnProcess() that awaited across it abandons its spawn. */
|
|
258
|
+
this.spawnEpoch = 0;
|
|
259
|
+
// Bumped by every start(): a stop() still awaiting after one ran no longer owns the session's live state.
|
|
260
|
+
this.starts = 0;
|
|
255
261
|
this.managedGroupStopped = false;
|
|
256
262
|
this.lastActivityAt = Date.now(); // accessible by AgentRunner for eviction sort
|
|
257
263
|
// Wall-clock time of the most recent BACKGROUND_DISPATCH_TOOLS tool_use seen
|
|
@@ -369,7 +375,7 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
369
375
|
this.sessionId = sessionId;
|
|
370
376
|
this.source = source;
|
|
371
377
|
this.chatId = chatId ?? sessionId;
|
|
372
|
-
this.sessionChannel = (0,
|
|
378
|
+
this.sessionChannel = (0, types_2.toChatChannel)(source);
|
|
373
379
|
this.agentConfig = agentConfig;
|
|
374
380
|
this.gatewayConfig = gatewayConfig;
|
|
375
381
|
this.sessionStore = sessionStore;
|
|
@@ -421,6 +427,7 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
421
427
|
return this.agentConfig.claude.model;
|
|
422
428
|
}
|
|
423
429
|
async start() {
|
|
430
|
+
this.starts++;
|
|
424
431
|
this.stopping = false;
|
|
425
432
|
this.restartCount = 0;
|
|
426
433
|
this.setupRestartWatcher();
|
|
@@ -696,6 +703,25 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
696
703
|
return false;
|
|
697
704
|
return [...this.spawnedConnectors.keys()].some(id => name.startsWith(`mcp__${id}__`) && name.length > id.length + 7);
|
|
698
705
|
}
|
|
706
|
+
/** The appended system prompt never travels on the command line: Windows caps a
|
|
707
|
+
* whole command line at 32767 characters and Linux caps ONE argument at 128 KiB
|
|
708
|
+
* (MAX_ARG_STRLEN), so a large workspace context or skill catalog would fail
|
|
709
|
+
* every spawn (#559); argv is also world-readable through /proc/<pid>/cmdline.
|
|
710
|
+
* The host CLI reads a 0600 file beside the attempt's MCP config (a 0700
|
|
711
|
+
* directory), named per spawn so stopping one spawn never removes another's.
|
|
712
|
+
* A container CLI reads one that prepareContainerProfile writes in its attempt
|
|
713
|
+
* directory, in the same docker exec as the attempt's mcp.json and ticket. */
|
|
714
|
+
writeSystemPromptFile(args, mcpConfigPath) {
|
|
715
|
+
if (!this.runtimeProfile)
|
|
716
|
+
return args;
|
|
717
|
+
const file = path.join(path.dirname(mcpConfigPath ?? this.runtimeProfile.mcpConfigPath), `system-prompt-${this.sessionId.replace(/[^\w.-]/g, '_')}-${(0, crypto_1.randomUUID)()}.md`);
|
|
718
|
+
const moved = (0, runtime_profile_1.appendSystemPromptViaFile)(args, file);
|
|
719
|
+
if (moved.prompt === undefined)
|
|
720
|
+
return args;
|
|
721
|
+
fs.writeFileSync(file, moved.prompt, { mode: 0o600, flag: 'wx' });
|
|
722
|
+
this.systemPromptPath = file;
|
|
723
|
+
return moved.args;
|
|
724
|
+
}
|
|
699
725
|
writeMcpConfig() {
|
|
700
726
|
if (this.runtimeProfile) {
|
|
701
727
|
// Orchestrators dispatch execution; only eligible workers receive connectors.
|
|
@@ -707,7 +733,11 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
707
733
|
const { servers, connectors } = (0, managed_connectors_1.prepareManagedConnectors)(this.agentConfig, this.gatewayConfig, this.runtimeProfile, this.managedConnectorPaths);
|
|
708
734
|
this.spawnedConnectors = new Map(Object.entries(connectors).map(([id, server]) => [id, connectorFingerprint(server)]));
|
|
709
735
|
const configPath = path.join(path.dirname(this.runtimeProfile.mcpConfigPath), 'managed-connectors.json');
|
|
710
|
-
|
|
736
|
+
const mcpServers = { ...servers, ...ticket.mcpServers };
|
|
737
|
+
for (const server of Object.values(mcpServers))
|
|
738
|
+
if (server?.env)
|
|
739
|
+
server.env = (0, child_env_1.sanitizeJevChildEnv)(server.env, this.gatewayConfig.gateway.jev);
|
|
740
|
+
fs.writeFileSync(configPath, JSON.stringify({ mcpServers }), { mode: 0o600 });
|
|
711
741
|
fs.chmodSync(configPath, 0o600);
|
|
712
742
|
this.managedMcpConfigPath = configPath;
|
|
713
743
|
return configPath;
|
|
@@ -724,6 +754,7 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
724
754
|
throw new Error('invalid session id');
|
|
725
755
|
}
|
|
726
756
|
fs.mkdirSync(sessionDir, { recursive: true, mode: 0o700 });
|
|
757
|
+
this.sessionDirPath = sessionDir;
|
|
727
758
|
const mcpServerPath = path.resolve(__dirname, '..', '..', 'mcp', 'server.ts');
|
|
728
759
|
// Merge stdio servers from Claude Code user + project configs (project overrides user).
|
|
729
760
|
// Skip the gateway's own server names from both — gateway always generates its own
|
|
@@ -869,6 +900,9 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
869
900
|
},
|
|
870
901
|
};
|
|
871
902
|
const configPath = path.join(sessionDir, 'mcp-config.json');
|
|
903
|
+
for (const server of Object.values(mcpConfig.mcpServers))
|
|
904
|
+
if (server?.env)
|
|
905
|
+
server.env = (0, child_env_1.sanitizeJevChildEnv)(server.env, this.gatewayConfig.gateway.jev);
|
|
872
906
|
fs.writeFileSync(configPath, JSON.stringify(mcpConfig, null, 2), { mode: 0o600 });
|
|
873
907
|
const serverNames = Object.keys(mcpConfig.mcpServers);
|
|
874
908
|
this.logger.debug('MCP config written', { sessionId: this.sessionId, servers: serverNames });
|
|
@@ -900,7 +934,7 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
900
934
|
const shared = (0, knowledge_1.resolveSharedConfig)(this.agentConfig.knowledge?.shared, this.gatewayConfig.gateway.knowledge?.shared).staleness;
|
|
901
935
|
return (personal.enabled && personal.recordRetrievals) || (shared.enabled && shared.recordRetrievals) ? '1' : '';
|
|
902
936
|
}
|
|
903
|
-
buildArgs(mcpConfigPath, model) {
|
|
937
|
+
buildArgs(mcpConfigPath, model, containerAttempt = this.containerAttempt) {
|
|
904
938
|
const args = [
|
|
905
939
|
'--model', model,
|
|
906
940
|
'--input-format', 'stream-json',
|
|
@@ -926,7 +960,8 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
926
960
|
throw error;
|
|
927
961
|
}
|
|
928
962
|
}
|
|
929
|
-
|
|
963
|
+
const profileArgs = (0, runtime_profile_1.runtimeProfileArgs)({ ...this.runtimeProfile, context, checkpointCommand: containerAttempt && this.runtimeProfile.checkpointCommand ? `node ${containerAttempt.directory}/checkpoint.cjs ${containerAttempt.directory}/ticket.json` : this.runtimeProfile.checkpointCommand, containerExecution: this.agentConfig.type === 'app-agent', mcpConfigPath: containerAttempt?.config ?? mcpConfigPath ?? this.runtimeProfile.mcpConfigPath, skillPluginDir: containerAttempt && this.runtimeProfile.skillPluginDir ? containerAttempt.directory + '/skill-plugin' : this.runtimeProfile.skillPluginDir }, this.agentConfig.claude.extraFlags ?? []);
|
|
964
|
+
args.push(...profileArgs);
|
|
930
965
|
if (this.runtimeProfile.cliSession) {
|
|
931
966
|
const session = this.runtimeProfile.cliSession;
|
|
932
967
|
args.push(session.resume ? '--resume' : '--session-id', session.id);
|
|
@@ -963,15 +998,33 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
963
998
|
message: { role: 'user', content: [{ type: 'text', text }, ...images] },
|
|
964
999
|
});
|
|
965
1000
|
}
|
|
1001
|
+
/** Resolves false when a stop() during its awaits abandoned the spawn: nothing was
|
|
1002
|
+
* started, and a container attempt it prepared is already cleaned up. */
|
|
966
1003
|
async spawnProcess() {
|
|
1004
|
+
const epoch = this.spawnEpoch;
|
|
967
1005
|
const { historyPrompt, loadedAtSpawn, archivedCount, messageCountAtSpawn } = await this.buildInitialPrompt();
|
|
1006
|
+
if (epoch !== this.spawnEpoch)
|
|
1007
|
+
return false;
|
|
968
1008
|
this.spawnContext = { loadedAtSpawn, archivedCount, messageCountAtSpawn };
|
|
969
1009
|
// Determine if this is a docker-exec app-agent before computing paths
|
|
970
1010
|
(0, container_1.assertContainerBinding)(this.agentConfig, this.runtimeProfile);
|
|
971
1011
|
const isAppAgent = this.agentConfig.type === 'app-agent' && !!this.agentConfig.container;
|
|
1012
|
+
const freshModel = this.readFreshModel();
|
|
1013
|
+
let containerArgs;
|
|
972
1014
|
if (isAppAgent && this.runtimeProfile) {
|
|
973
|
-
|
|
974
|
-
|
|
1015
|
+
const profile = this.runtimeProfile, container = this.agentConfig.container;
|
|
1016
|
+
const attempt = await (0, container_1.prepareContainerProfile)(this.agentConfig, profile, async (directory) => {
|
|
1017
|
+
profile.context = await (0, container_1.containerNode)(container, "process.stdout.write(require('fs').readFileSync('/workspace/CLAUDE.md','utf8'))");
|
|
1018
|
+
const moved = (0, runtime_profile_1.appendSystemPromptViaFile)(this.buildArgs(null, freshModel, { directory, config: directory + '/mcp.json' }), directory + '/system-prompt.md');
|
|
1019
|
+
containerArgs = moved.args;
|
|
1020
|
+
return moved.prompt;
|
|
1021
|
+
});
|
|
1022
|
+
// stop() could not see this attempt yet; remove its ticket and prompt here.
|
|
1023
|
+
if (epoch !== this.spawnEpoch) {
|
|
1024
|
+
await (0, container_1.stopContainerProfile)(container, attempt.directory);
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
this.containerAttempt = attempt;
|
|
975
1028
|
}
|
|
976
1029
|
const mcpConfigPath = this.writeMcpConfig();
|
|
977
1030
|
// For app-agents, Claude runs inside the container where /workspace is mounted.
|
|
@@ -979,14 +1032,15 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
979
1032
|
const toContainerPath = (hostPath) => `/workspace/${path.relative(this.agentConfig.workspace, hostPath)}`;
|
|
980
1033
|
const effectiveMcpPath = (isAppAgent && mcpConfigPath) ? toContainerPath(mcpConfigPath) : mcpConfigPath;
|
|
981
1034
|
const containerRestartPath = isAppAgent ? toContainerPath(this.restartSignalPath) : this.restartSignalPath;
|
|
982
|
-
const
|
|
983
|
-
const args = this.buildArgs(effectiveMcpPath, freshModel);
|
|
1035
|
+
const args = containerArgs ?? this.writeSystemPromptFile(this.buildArgs(effectiveMcpPath, freshModel), mcpConfigPath);
|
|
984
1036
|
// Resolve the claude binary. An explicit CLAUDE_BIN (which may carry args) is
|
|
985
|
-
//
|
|
1037
|
+
// parsed by parseClaudeBin; otherwise probe PATH and the native-installer / legacy
|
|
986
1038
|
// install locations so a gateway launched with a minimal PATH still finds it.
|
|
987
1039
|
let claudeBinRaw;
|
|
1040
|
+
let claudeBinParts;
|
|
988
1041
|
if (process.env.CLAUDE_BIN) {
|
|
989
1042
|
claudeBinRaw = process.env.CLAUDE_BIN;
|
|
1043
|
+
claudeBinParts = (0, claude_bin_1.parseClaudeBin)(claudeBinRaw);
|
|
990
1044
|
}
|
|
991
1045
|
else if (isAppAgent) {
|
|
992
1046
|
// App-agents run claude INSIDE the container; host-side resolution would
|
|
@@ -994,10 +1048,13 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
994
1048
|
// `claude` so the container's own PATH resolves it (agentConfig.claudeBin
|
|
995
1049
|
// overrides below when the image installs claude elsewhere).
|
|
996
1050
|
claudeBinRaw = 'claude';
|
|
1051
|
+
claudeBinParts = { command: claudeBinRaw, args: [] };
|
|
997
1052
|
}
|
|
998
1053
|
else {
|
|
999
1054
|
const resolution = (0, claude_bin_1.resolveClaudeBin)();
|
|
1000
1055
|
claudeBinRaw = resolution.bin;
|
|
1056
|
+
// A resolved path is one executable, never split: it may sit under a home with spaces.
|
|
1057
|
+
claudeBinParts = { command: claudeBinRaw, args: [] };
|
|
1001
1058
|
if (resolution.source === 'fallback') {
|
|
1002
1059
|
this.logger.warn('Could not resolve the claude binary — spawning bare "claude" as a last resort', {
|
|
1003
1060
|
sessionId: this.sessionId,
|
|
@@ -1016,9 +1073,8 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1016
1073
|
});
|
|
1017
1074
|
}
|
|
1018
1075
|
}
|
|
1019
|
-
|
|
1020
|
-
let
|
|
1021
|
-
let allArgs = [...claudeBinParts.slice(1), ...args];
|
|
1076
|
+
let claudeBin = claudeBinParts.command;
|
|
1077
|
+
let allArgs = [...claudeBinParts.args, ...args];
|
|
1022
1078
|
// gateway.headless: false → run the interactive claude TUI under the
|
|
1023
1079
|
// claude-pty-shell PTY wrapper (same stream-json protocol on stdio).
|
|
1024
1080
|
// App-agents always stay headless: the wrapper (node-pty) lives on the
|
|
@@ -1067,10 +1123,13 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1067
1123
|
containerUid = os.userInfo().uid;
|
|
1068
1124
|
}
|
|
1069
1125
|
catch { /* use 1000 */ }
|
|
1070
|
-
const configuredWorkerEnvironment = this.runtimeProfile?.role === 'worker' ? (0, worker_environment_1.workerEnvironment)(this.agentConfig, this.gatewayConfig) : {};
|
|
1126
|
+
const configuredWorkerEnvironment = (0, child_env_1.sanitizeJevChildEnv)(this.runtimeProfile?.role === 'worker' ? (0, worker_environment_1.workerEnvironment)(this.agentConfig, this.gatewayConfig) : {}, this.gatewayConfig.gateway.jev);
|
|
1127
|
+
const turnEnvironment = this.runtimeProfile?.role === 'agent' && this.runtimeProfile.claudeEffort
|
|
1128
|
+
? { CLAUDE_CODE_EFFORT_LEVEL: this.runtimeProfile.claudeEffort } : {};
|
|
1071
1129
|
const containerEnv = {
|
|
1072
1130
|
HOME: os.homedir(),
|
|
1073
1131
|
CLAUDE_WORKSPACE: '/workspace',
|
|
1132
|
+
...turnEnvironment,
|
|
1074
1133
|
GATEWAY_RESTART_SIGNAL_PATH: containerRestartPath,
|
|
1075
1134
|
};
|
|
1076
1135
|
if (!this.runtimeProfile && process.env.GATEWAY_API_URL)
|
|
@@ -1089,6 +1148,8 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1089
1148
|
const dockerEnvFlags = [
|
|
1090
1149
|
...Object.entries(containerEnv).flatMap(([k, v]) => ['-e', `${k}=${v}`]),
|
|
1091
1150
|
...byNameKeys.flatMap((k) => ['-e', k]),
|
|
1151
|
+
// Also mask values baked into an existing container's own environment.
|
|
1152
|
+
...(0, child_env_1.jevCredentialEnvNames)(this.gatewayConfig.gateway.jev).flatMap(k => ['-e', `${k}=`]),
|
|
1092
1153
|
];
|
|
1093
1154
|
const spawnArgs = isAppAgent
|
|
1094
1155
|
? [
|
|
@@ -1126,13 +1187,14 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1126
1187
|
let proc;
|
|
1127
1188
|
try {
|
|
1128
1189
|
proc = (0, child_process_1.spawn)(spawnBin, spawnArgs, {
|
|
1129
|
-
env: {
|
|
1190
|
+
env: (0, child_env_1.sanitizeJevChildEnv)({
|
|
1130
1191
|
...process.env,
|
|
1131
1192
|
...(!isAppAgent && this.runtimeProfile?.checkpointCommand && !this.runtimeProfile.hostExecution ? Object.fromEntries(CONTAINER_CREDENTIAL_KEYS.map(key => [key, undefined])) : {}),
|
|
1132
1193
|
...containerAuthEnv,
|
|
1133
1194
|
...(toolCapture ? { OTEL_LOG_RAW_API_BODIES: 'file:' + toolCapture.directory } : {}),
|
|
1134
1195
|
...(hardenedPath ? { PATH: hardenedPath } : {}),
|
|
1135
1196
|
...configuredWorkerEnvironment,
|
|
1197
|
+
...turnEnvironment,
|
|
1136
1198
|
GATEWAY_ORIGIN_SESSION_ID: this.runtimeProfile?.originSessionId ?? this.sessionId,
|
|
1137
1199
|
GATEWAY_TASK_ID: this.runtimeProfile?.taskId ?? '',
|
|
1138
1200
|
GATEWAY_TASK_ATTEMPT_ID: this.runtimeProfile?.attemptId ?? '',
|
|
@@ -1142,24 +1204,36 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1142
1204
|
...(ptyRealBin ? { CLAUDE_REAL_BIN: ptyRealBin } : {}),
|
|
1143
1205
|
...(ptyHeartbeatPath ? { PTY_SHELL_HEARTBEAT_PATH: ptyHeartbeatPath } : {}),
|
|
1144
1206
|
...(ptyStreamSocketPath ? { PTY_SHELL_STREAM_SOCKET: ptyStreamSocketPath } : {}),
|
|
1145
|
-
},
|
|
1207
|
+
}, this.gatewayConfig.gateway.jev),
|
|
1146
1208
|
cwd: this.agentConfig.workspace,
|
|
1147
|
-
...(this.runtimeProfile?.role === 'worker' &&
|
|
1209
|
+
...(this.runtimeProfile?.role === 'worker' && (0, process_supervisor_1.processSupervisorSupported)() && (0, process_supervisor_1.workerSpawnDetached)() ? { detached: true } : {}),
|
|
1210
|
+
windowsHide: true,
|
|
1148
1211
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
1149
1212
|
});
|
|
1150
1213
|
}
|
|
1151
1214
|
catch (error) {
|
|
1152
1215
|
toolCapture?.close();
|
|
1153
1216
|
releaseCapacity();
|
|
1217
|
+
// Node throws E2BIG/ENAMETOOLONG (and most other execve failures) from spawn()
|
|
1218
|
+
// itself; they never reach proc.on('error') below, so log them here. Sizes
|
|
1219
|
+
// only: the arguments may carry prompts and settings.
|
|
1220
|
+
const cause = error.code;
|
|
1221
|
+
const bytes = [spawnBin, ...spawnArgs].map(arg => Buffer.byteLength(arg));
|
|
1222
|
+
this.logger.error('session subprocess could not be spawned', { sessionId: this.sessionId, code: cause, argCount: bytes.length, largestArgBytes: Math.max(...bytes), totalArgBytes: bytes.reduce((sum, n) => sum + n, 0) });
|
|
1223
|
+
if (cause === 'E2BIG' || cause === 'ENAMETOOLONG')
|
|
1224
|
+
throw new types_1.OrchestrationError('PROCESS_ARGS_TOO_LARGE', `spawn ${cause}`);
|
|
1154
1225
|
throw error;
|
|
1155
1226
|
}
|
|
1156
1227
|
this.process = proc;
|
|
1228
|
+
const startsAtSpawn = this.starts;
|
|
1157
1229
|
proc.once('exit', releaseCapacity);
|
|
1158
1230
|
proc.once('exit', () => { setTimeout(() => toolCapture?.close(), 200).unref(); });
|
|
1159
1231
|
proc.once('error', () => toolCapture?.close());
|
|
1160
1232
|
proc.once('error', releaseCapacity);
|
|
1161
|
-
if (this.runtimeProfile?.role === 'worker' &&
|
|
1233
|
+
if (this.runtimeProfile?.role === 'worker' && (0, process_supervisor_1.processSupervisorSupported)()) {
|
|
1162
1234
|
this.managedProcessGroup = proc.pid;
|
|
1235
|
+
(0, process_supervisor_1.recordProcessRoot)(proc);
|
|
1236
|
+
}
|
|
1163
1237
|
// Fresh child is alive: clear any exit observed for a prior process (e.g.
|
|
1164
1238
|
// after an auto-restart), so isRunning()/interrupt() see it as live.
|
|
1165
1239
|
this._exited = false;
|
|
@@ -1540,6 +1614,15 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1540
1614
|
});
|
|
1541
1615
|
if (ptyStreamSocketPath)
|
|
1542
1616
|
pty_stream_registry_1.ptyStreamRegistry.close(ptyStreamSocketPath);
|
|
1617
|
+
// A start() while an earlier stop() still waited for this exit owns the
|
|
1618
|
+
// session now, whether or not its child is attached yet; this exit is not
|
|
1619
|
+
// that session's death, so no 'exit' listener may see it and nothing restarts.
|
|
1620
|
+
// The stopped turn settles when its stop() resolves.
|
|
1621
|
+
if (this.starts !== startsAtSpawn || (this.process && this.process !== proc)) {
|
|
1622
|
+
if (this.process === proc)
|
|
1623
|
+
this.process = null;
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1543
1626
|
this.process = null;
|
|
1544
1627
|
this._exited = true;
|
|
1545
1628
|
this.resetBackgroundDispatchState();
|
|
@@ -1585,6 +1668,7 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1585
1668
|
this.emit('startup-error', Object.assign(new Error(code), { code }));
|
|
1586
1669
|
}
|
|
1587
1670
|
});
|
|
1671
|
+
return true;
|
|
1588
1672
|
}
|
|
1589
1673
|
scheduleRestart() {
|
|
1590
1674
|
// Graceful self-restart requested by agent — reset counter so it doesn't
|
|
@@ -1624,9 +1708,12 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1624
1708
|
// sendMessage() will no longer silently no-op. Emitted on every
|
|
1625
1709
|
// successful crash-triggered respawn — cheap, and nothing currently
|
|
1626
1710
|
// listens outside that one call site.
|
|
1627
|
-
.then(
|
|
1711
|
+
.then(spawned => {
|
|
1628
1712
|
this._restartScheduled = false;
|
|
1629
|
-
|
|
1713
|
+
if (spawned)
|
|
1714
|
+
this.emit('restarted');
|
|
1715
|
+
else
|
|
1716
|
+
this.emit('restartFailed', new Error('Session restart abandoned: session stopping'));
|
|
1630
1717
|
})
|
|
1631
1718
|
.catch(err => {
|
|
1632
1719
|
this._restartScheduled = false;
|
|
@@ -1987,28 +2074,56 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
1987
2074
|
if (this.diagnostics.outcome === 'pending' && !this.diagnostics.stopReason)
|
|
1988
2075
|
this.diagnostics.stopReason = 'shutdown';
|
|
1989
2076
|
this.stopping = true;
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2077
|
+
this.spawnEpoch++;
|
|
2078
|
+
// Take over what the spawn being stopped wrote, so a start() while this stop
|
|
2079
|
+
// still waits for the exit records its own files from scratch. Connector and
|
|
2080
|
+
// MCP config files keep fixed names, and such a start() rewrites them in place:
|
|
2081
|
+
// at the exit, removeSessionDir skips every path that newer spawn holds again.
|
|
2082
|
+
const owned = {
|
|
2083
|
+
systemPrompt: this.systemPromptPath,
|
|
2084
|
+
connectors: [...this.managedConnectorPaths],
|
|
2085
|
+
managedMcpConfig: this.managedMcpConfigPath,
|
|
2086
|
+
};
|
|
2087
|
+
this.systemPromptPath = undefined;
|
|
2088
|
+
this.managedConnectorPaths = new Set();
|
|
2089
|
+
this.managedMcpConfigPath = undefined;
|
|
2090
|
+
this.sessionDirPath = undefined;
|
|
2091
|
+
// The same for the spawn's live state: a start() during the awaits below
|
|
2092
|
+
// attaches its own child, group, attempt and watcher, which this stop must
|
|
2093
|
+
// neither signal nor clear. A newer stop() of that spawn handles them.
|
|
2094
|
+
const starts = this.starts;
|
|
2095
|
+
const superseded = () => this.starts !== starts;
|
|
2096
|
+
const proc = this.process;
|
|
2097
|
+
const attempt = this.containerAttempt;
|
|
2098
|
+
const group = this.managedProcessGroup;
|
|
2099
|
+
const watcher = this.restartWatcher;
|
|
2100
|
+
this.restartWatcher = null;
|
|
2101
|
+
let exited = false;
|
|
2102
|
+
const exit = proc ? new Promise(resolve => proc.once('exit', () => { exited = true; resolve(); })) : undefined;
|
|
2103
|
+
this.resetBackgroundDispatchState();
|
|
2104
|
+
if (attempt && this.agentConfig.container) {
|
|
2105
|
+
this.managedGroupStopped = await (0, container_1.stopContainerProfile)(this.agentConfig.container, attempt.directory);
|
|
2106
|
+
if (this.containerAttempt === attempt)
|
|
2107
|
+
this.containerAttempt = undefined;
|
|
1993
2108
|
}
|
|
1994
|
-
if (
|
|
1995
|
-
const hostStopped = await (0, process_supervisor_1.stopProcessGroup)(
|
|
2109
|
+
if (group) {
|
|
2110
|
+
const hostStopped = await (0, process_supervisor_1.stopProcessGroup)(group);
|
|
1996
2111
|
this.managedGroupStopped = this.agentConfig.type === 'app-agent' ? this.managedGroupStopped && hostStopped : hostStopped;
|
|
1997
|
-
if (this.managedGroupStopped)
|
|
2112
|
+
if (this.managedGroupStopped && this.managedProcessGroup === group)
|
|
1998
2113
|
this.managedProcessGroup = undefined;
|
|
1999
2114
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
this.restartWatcher = null;
|
|
2003
|
-
try {
|
|
2004
|
-
fs.rmSync(this.restartSignalPath, { force: true });
|
|
2005
|
-
}
|
|
2006
|
-
catch { }
|
|
2007
|
-
if (this.source === 'telegram' && !this.runtimeProfile) {
|
|
2115
|
+
await watcher?.close();
|
|
2116
|
+
if (!superseded()) {
|
|
2008
2117
|
try {
|
|
2009
|
-
fs.rmSync(
|
|
2118
|
+
fs.rmSync(this.restartSignalPath, { force: true });
|
|
2010
2119
|
}
|
|
2011
2120
|
catch { }
|
|
2121
|
+
if (this.source === 'telegram' && !this.runtimeProfile) {
|
|
2122
|
+
try {
|
|
2123
|
+
fs.rmSync(path.join(this.typingDir, `${this.chatId}.processing`), { force: true });
|
|
2124
|
+
}
|
|
2125
|
+
catch { }
|
|
2126
|
+
}
|
|
2012
2127
|
}
|
|
2013
2128
|
// mcp-config.json under here holds fully-substituted secrets (channel bot
|
|
2014
2129
|
// tokens, GATEWAY_API_KEY, connector OAuth tokens) — it must not outlive
|
|
@@ -2018,49 +2133,42 @@ class SessionProcess extends events_1.EventEmitter {
|
|
|
2018
2133
|
// subprocess (or, for a container agent, the still-running container that
|
|
2019
2134
|
// bind-mounts this path) can be alive for up to the 10s graceful-shutdown
|
|
2020
2135
|
// window immediately after this point, and must not find it gone under it.
|
|
2136
|
+
// A newer spawn that wrote the shared directory owns it now; its stop removes it.
|
|
2021
2137
|
const removeSessionDir = () => {
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
if (this.managedMcpConfigPath) {
|
|
2030
|
-
try {
|
|
2031
|
-
fs.rmSync(this.managedMcpConfigPath, { force: true });
|
|
2138
|
+
const reclaimed = (file) => this.managedConnectorPaths.has(file) || file === this.managedMcpConfigPath;
|
|
2139
|
+
for (const file of [...owned.connectors, owned.managedMcpConfig, owned.systemPrompt]) {
|
|
2140
|
+
if (file && !reclaimed(file)) {
|
|
2141
|
+
try {
|
|
2142
|
+
fs.rmSync(file, { force: true });
|
|
2143
|
+
}
|
|
2144
|
+
catch { }
|
|
2032
2145
|
}
|
|
2033
|
-
catch { }
|
|
2034
|
-
this.managedMcpConfigPath = undefined;
|
|
2035
2146
|
}
|
|
2147
|
+
if (this.sessionDirPath)
|
|
2148
|
+
return;
|
|
2036
2149
|
try {
|
|
2037
2150
|
fs.rmSync(path.join(this.agentConfig.workspace, '.sessions', this.sessionId), { recursive: true, force: true });
|
|
2038
2151
|
}
|
|
2039
2152
|
catch { }
|
|
2040
2153
|
};
|
|
2041
|
-
|
|
2154
|
+
// A child that failed to spawn never exits; its 'error' handler already let go of it.
|
|
2155
|
+
if (!proc || exited || (this.process !== proc && !proc.pid)) {
|
|
2042
2156
|
removeSessionDir();
|
|
2043
2157
|
return;
|
|
2044
2158
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
forceKillTimer = setTimeout(() => {
|
|
2059
|
-
forceKillTimer = null;
|
|
2060
|
-
if (this.process)
|
|
2061
|
-
proc.kill('SIGKILL');
|
|
2062
|
-
}, 10000);
|
|
2063
|
-
});
|
|
2159
|
+
let forceKillTimer = null;
|
|
2160
|
+
proc.kill('SIGTERM');
|
|
2161
|
+
forceKillTimer = setTimeout(() => {
|
|
2162
|
+
forceKillTimer = null;
|
|
2163
|
+
if (!exited)
|
|
2164
|
+
proc.kill('SIGKILL');
|
|
2165
|
+
}, 10000);
|
|
2166
|
+
await exit;
|
|
2167
|
+
if (forceKillTimer !== null)
|
|
2168
|
+
clearTimeout(forceKillTimer);
|
|
2169
|
+
if (this.process === proc)
|
|
2170
|
+
this.process = null;
|
|
2171
|
+
removeSessionDir();
|
|
2064
2172
|
}
|
|
2065
2173
|
}
|
|
2066
2174
|
exports.SessionProcess = SessionProcess;
|