@sema-agent/core 1.279.0
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/LICENSE +104 -0
- package/NOTICE.md +30 -0
- package/README.md +143 -0
- package/README.zh-CN.md +138 -0
- package/dist/agents/agent-definition.d.ts +3 -0
- package/dist/agents/agent-definition.d.ts.map +1 -0
- package/dist/agents/agent-definition.js +9 -0
- package/dist/agents/agent-definition.js.map +1 -0
- package/dist/agents/builtin-agents.d.ts +9 -0
- package/dist/agents/builtin-agents.d.ts.map +1 -0
- package/dist/agents/builtin-agents.js +114 -0
- package/dist/agents/builtin-agents.js.map +1 -0
- package/dist/agents/cascade.d.ts +44 -0
- package/dist/agents/cascade.d.ts.map +1 -0
- package/dist/agents/cascade.js +153 -0
- package/dist/agents/cascade.js.map +1 -0
- package/dist/agents/observer.d.ts +122 -0
- package/dist/agents/observer.d.ts.map +1 -0
- package/dist/agents/observer.js +365 -0
- package/dist/agents/observer.js.map +1 -0
- package/dist/agents/repair-loop.d.ts +49 -0
- package/dist/agents/repair-loop.d.ts.map +1 -0
- package/dist/agents/repair-loop.js +147 -0
- package/dist/agents/repair-loop.js.map +1 -0
- package/dist/agents/session-util.d.ts +3 -0
- package/dist/agents/session-util.d.ts.map +1 -0
- package/dist/agents/session-util.js +4 -0
- package/dist/agents/session-util.js.map +1 -0
- package/dist/agents/subagent-steps.d.ts +31 -0
- package/dist/agents/subagent-steps.d.ts.map +1 -0
- package/dist/agents/subagent-steps.js +167 -0
- package/dist/agents/subagent-steps.js.map +1 -0
- package/dist/agents/subagent.d.ts +152 -0
- package/dist/agents/subagent.d.ts.map +1 -0
- package/dist/agents/subagent.js +1698 -0
- package/dist/agents/subagent.js.map +1 -0
- package/dist/agents/suspend-guard.d.ts +6 -0
- package/dist/agents/suspend-guard.d.ts.map +1 -0
- package/dist/agents/suspend-guard.js +19 -0
- package/dist/agents/suspend-guard.js.map +1 -0
- package/dist/agents/teacher.d.ts +70 -0
- package/dist/agents/teacher.d.ts.map +1 -0
- package/dist/agents/teacher.js +462 -0
- package/dist/agents/teacher.js.map +1 -0
- package/dist/agents/team.d.ts +92 -0
- package/dist/agents/team.d.ts.map +1 -0
- package/dist/agents/team.js +231 -0
- package/dist/agents/team.js.map +1 -0
- package/dist/agents/tool-filter.d.ts +4 -0
- package/dist/agents/tool-filter.d.ts.map +1 -0
- package/dist/agents/tool-filter.js +18 -0
- package/dist/agents/tool-filter.js.map +1 -0
- package/dist/agents/verify.d.ts +46 -0
- package/dist/agents/verify.d.ts.map +1 -0
- package/dist/agents/verify.js +177 -0
- package/dist/agents/verify.js.map +1 -0
- package/dist/bench/metrics.d.ts +259 -0
- package/dist/bench/metrics.d.ts.map +1 -0
- package/dist/bench/metrics.js +439 -0
- package/dist/bench/metrics.js.map +1 -0
- package/dist/bin/sema-tb.d.ts +3 -0
- package/dist/bin/sema-tb.d.ts.map +1 -0
- package/dist/bin/sema-tb.js +373 -0
- package/dist/bin/sema-tb.js.map +1 -0
- package/dist/bin/tb-env.d.ts +2 -0
- package/dist/bin/tb-env.d.ts.map +1 -0
- package/dist/bin/tb-env.js +15 -0
- package/dist/bin/tb-env.js.map +1 -0
- package/dist/brain/anthropic.d.ts +16 -0
- package/dist/brain/anthropic.d.ts.map +1 -0
- package/dist/brain/anthropic.js +635 -0
- package/dist/brain/anthropic.js.map +1 -0
- package/dist/brain/circuit-breaker.d.ts +26 -0
- package/dist/brain/circuit-breaker.d.ts.map +1 -0
- package/dist/brain/circuit-breaker.js +118 -0
- package/dist/brain/circuit-breaker.js.map +1 -0
- package/dist/brain/degrading.d.ts +33 -0
- package/dist/brain/degrading.d.ts.map +1 -0
- package/dist/brain/degrading.js +175 -0
- package/dist/brain/degrading.js.map +1 -0
- package/dist/brain/errors.d.ts +14 -0
- package/dist/brain/errors.d.ts.map +1 -0
- package/dist/brain/errors.js +43 -0
- package/dist/brain/errors.js.map +1 -0
- package/dist/brain/failover.d.ts +3 -0
- package/dist/brain/failover.d.ts.map +1 -0
- package/dist/brain/failover.js +85 -0
- package/dist/brain/failover.js.map +1 -0
- package/dist/brain/model-presets.d.ts +5 -0
- package/dist/brain/model-presets.d.ts.map +1 -0
- package/dist/brain/model-presets.js +30 -0
- package/dist/brain/model-presets.js.map +1 -0
- package/dist/brain/openai.d.ts +13 -0
- package/dist/brain/openai.d.ts.map +1 -0
- package/dist/brain/openai.js +581 -0
- package/dist/brain/openai.js.map +1 -0
- package/dist/brain/reasoning.d.ts +33 -0
- package/dist/brain/reasoning.d.ts.map +1 -0
- package/dist/brain/reasoning.js +84 -0
- package/dist/brain/reasoning.js.map +1 -0
- package/dist/brain/repetition.d.ts +16 -0
- package/dist/brain/repetition.d.ts.map +1 -0
- package/dist/brain/repetition.js +96 -0
- package/dist/brain/repetition.js.map +1 -0
- package/dist/brain/request-params.d.ts +6 -0
- package/dist/brain/request-params.d.ts.map +1 -0
- package/dist/brain/request-params.js +44 -0
- package/dist/brain/request-params.js.map +1 -0
- package/dist/brain/retry.d.ts +3 -0
- package/dist/brain/retry.d.ts.map +1 -0
- package/dist/brain/retry.js +23 -0
- package/dist/brain/retry.js.map +1 -0
- package/dist/brain/routing.d.ts +7 -0
- package/dist/brain/routing.d.ts.map +1 -0
- package/dist/brain/routing.js +34 -0
- package/dist/brain/routing.js.map +1 -0
- package/dist/brain/status-sink.d.ts +27 -0
- package/dist/brain/status-sink.d.ts.map +1 -0
- package/dist/brain/status-sink.js +20 -0
- package/dist/brain/status-sink.js.map +1 -0
- package/dist/brain/stream-engine.d.ts +37 -0
- package/dist/brain/stream-engine.d.ts.map +1 -0
- package/dist/brain/stream-engine.js +295 -0
- package/dist/brain/stream-engine.js.map +1 -0
- package/dist/brain/timeout.d.ts +12 -0
- package/dist/brain/timeout.d.ts.map +1 -0
- package/dist/brain/timeout.js +34 -0
- package/dist/brain/timeout.js.map +1 -0
- package/dist/brain/tool-call-repair.d.ts +6 -0
- package/dist/brain/tool-call-repair.d.ts.map +1 -0
- package/dist/brain/tool-call-repair.js +58 -0
- package/dist/brain/tool-call-repair.js.map +1 -0
- package/dist/brain/walltime.d.ts +2 -0
- package/dist/brain/walltime.d.ts.map +1 -0
- package/dist/brain/walltime.js +2 -0
- package/dist/brain/walltime.js.map +1 -0
- package/dist/core/arg-summary.d.ts +3 -0
- package/dist/core/arg-summary.d.ts.map +1 -0
- package/dist/core/arg-summary.js +76 -0
- package/dist/core/arg-summary.js.map +1 -0
- package/dist/core/ask-question.d.ts +36 -0
- package/dist/core/ask-question.d.ts.map +1 -0
- package/dist/core/ask-question.js +171 -0
- package/dist/core/ask-question.js.map +1 -0
- package/dist/core/auto-compaction.d.ts +88 -0
- package/dist/core/auto-compaction.d.ts.map +1 -0
- package/dist/core/auto-compaction.js +253 -0
- package/dist/core/auto-compaction.js.map +1 -0
- package/dist/core/auto-mode-prompt-assets.d.ts +3 -0
- package/dist/core/auto-mode-prompt-assets.d.ts.map +1 -0
- package/dist/core/auto-mode-prompt-assets.js +3 -0
- package/dist/core/auto-mode-prompt-assets.js.map +1 -0
- package/dist/core/auto-mode-prompt.d.ts +22 -0
- package/dist/core/auto-mode-prompt.d.ts.map +1 -0
- package/dist/core/auto-mode-prompt.js +84 -0
- package/dist/core/auto-mode-prompt.js.map +1 -0
- package/dist/core/auto-mode.d.ts +35 -0
- package/dist/core/auto-mode.d.ts.map +1 -0
- package/dist/core/auto-mode.js +100 -0
- package/dist/core/auto-mode.js.map +1 -0
- package/dist/core/auto-promote.d.ts +26 -0
- package/dist/core/auto-promote.d.ts.map +1 -0
- package/dist/core/auto-promote.js +93 -0
- package/dist/core/auto-promote.js.map +1 -0
- package/dist/core/background-shell.d.ts +41 -0
- package/dist/core/background-shell.d.ts.map +1 -0
- package/dist/core/background-shell.js +21 -0
- package/dist/core/background-shell.js.map +1 -0
- package/dist/core/cache-break-detector.d.ts +29 -0
- package/dist/core/cache-break-detector.d.ts.map +1 -0
- package/dist/core/cache-break-detector.js +80 -0
- package/dist/core/cache-break-detector.js.map +1 -0
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +68 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +257 -0
- package/dist/core/checkpoint-store.d.ts.map +1 -0
- package/dist/core/checkpoint-store.js +292 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/consolidate-scope.d.ts +19 -0
- package/dist/core/consolidate-scope.d.ts.map +1 -0
- package/dist/core/consolidate-scope.js +96 -0
- package/dist/core/consolidate-scope.js.map +1 -0
- package/dist/core/context-edit.d.ts +18 -0
- package/dist/core/context-edit.d.ts.map +1 -0
- package/dist/core/context-edit.js +98 -0
- package/dist/core/context-edit.js.map +1 -0
- package/dist/core/context-guard.d.ts +14 -0
- package/dist/core/context-guard.d.ts.map +1 -0
- package/dist/core/context-guard.js +110 -0
- package/dist/core/context-guard.js.map +1 -0
- package/dist/core/dynamic-recall.d.ts +33 -0
- package/dist/core/dynamic-recall.d.ts.map +1 -0
- package/dist/core/dynamic-recall.js +77 -0
- package/dist/core/dynamic-recall.js.map +1 -0
- package/dist/core/exec-gate.d.ts +30 -0
- package/dist/core/exec-gate.d.ts.map +1 -0
- package/dist/core/exec-gate.js +106 -0
- package/dist/core/exec-gate.js.map +1 -0
- package/dist/core/exec-output-tail.d.ts +15 -0
- package/dist/core/exec-output-tail.d.ts.map +1 -0
- package/dist/core/exec-output-tail.js +39 -0
- package/dist/core/exec-output-tail.js.map +1 -0
- package/dist/core/file-snapshot-store.d.ts +53 -0
- package/dist/core/file-snapshot-store.d.ts.map +1 -0
- package/dist/core/file-snapshot-store.js +244 -0
- package/dist/core/file-snapshot-store.js.map +1 -0
- package/dist/core/git-worktree-env.d.ts +16 -0
- package/dist/core/git-worktree-env.d.ts.map +1 -0
- package/dist/core/git-worktree-env.js +40 -0
- package/dist/core/git-worktree-env.js.map +1 -0
- package/dist/core/hooks.d.ts +128 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +184 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/lsp-diagnostics.d.ts +31 -0
- package/dist/core/lsp-diagnostics.d.ts.map +1 -0
- package/dist/core/lsp-diagnostics.js +79 -0
- package/dist/core/lsp-diagnostics.js.map +1 -0
- package/dist/core/lsp-protocol.d.ts +10 -0
- package/dist/core/lsp-protocol.d.ts.map +1 -0
- package/dist/core/lsp-protocol.js +136 -0
- package/dist/core/lsp-protocol.js.map +1 -0
- package/dist/core/lsp-session.d.ts +27 -0
- package/dist/core/lsp-session.d.ts.map +1 -0
- package/dist/core/lsp-session.js +134 -0
- package/dist/core/lsp-session.js.map +1 -0
- package/dist/core/lsp.d.ts +56 -0
- package/dist/core/lsp.d.ts.map +1 -0
- package/dist/core/lsp.js +130 -0
- package/dist/core/lsp.js.map +1 -0
- package/dist/core/mcp.d.ts +108 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +692 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/media-byte-cap.d.ts +13 -0
- package/dist/core/media-byte-cap.d.ts.map +1 -0
- package/dist/core/media-byte-cap.js +51 -0
- package/dist/core/media-byte-cap.js.map +1 -0
- package/dist/core/memory-engine/data-plane.d.ts +60 -0
- package/dist/core/memory-engine/data-plane.d.ts.map +1 -0
- package/dist/core/memory-engine/data-plane.js +198 -0
- package/dist/core/memory-engine/data-plane.js.map +1 -0
- package/dist/core/memory-engine/dual-root.d.ts +16 -0
- package/dist/core/memory-engine/dual-root.d.ts.map +1 -0
- package/dist/core/memory-engine/dual-root.js +75 -0
- package/dist/core/memory-engine/dual-root.js.map +1 -0
- package/dist/core/memory-engine/engine.d.ts +67 -0
- package/dist/core/memory-engine/engine.d.ts.map +1 -0
- package/dist/core/memory-engine/engine.js +828 -0
- package/dist/core/memory-engine/engine.js.map +1 -0
- package/dist/core/memory-engine/file-backend.d.ts +55 -0
- package/dist/core/memory-engine/file-backend.d.ts.map +1 -0
- package/dist/core/memory-engine/file-backend.js +752 -0
- package/dist/core/memory-engine/file-backend.js.map +1 -0
- package/dist/core/memory-engine/frontmatter.d.ts +13 -0
- package/dist/core/memory-engine/frontmatter.d.ts.map +1 -0
- package/dist/core/memory-engine/frontmatter.js +119 -0
- package/dist/core/memory-engine/frontmatter.js.map +1 -0
- package/dist/core/memory-engine/index.d.ts +13 -0
- package/dist/core/memory-engine/index.d.ts.map +1 -0
- package/dist/core/memory-engine/index.js +12 -0
- package/dist/core/memory-engine/index.js.map +1 -0
- package/dist/core/memory-engine/layout.d.ts +44 -0
- package/dist/core/memory-engine/layout.d.ts.map +1 -0
- package/dist/core/memory-engine/layout.js +459 -0
- package/dist/core/memory-engine/layout.js.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -0
- package/dist/core/memory-engine/memory-backend-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/memory-backend-contract.js +269 -0
- package/dist/core/memory-engine/memory-backend-contract.js.map +1 -0
- package/dist/core/memory-engine/migrate.d.ts +8 -0
- package/dist/core/memory-engine/migrate.d.ts.map +1 -0
- package/dist/core/memory-engine/migrate.js +23 -0
- package/dist/core/memory-engine/migrate.js.map +1 -0
- package/dist/core/memory-engine/scan.d.ts +8 -0
- package/dist/core/memory-engine/scan.d.ts.map +1 -0
- package/dist/core/memory-engine/scan.js +49 -0
- package/dist/core/memory-engine/scan.js.map +1 -0
- package/dist/core/memory-engine/scope-contract.d.ts +44 -0
- package/dist/core/memory-engine/scope-contract.d.ts.map +1 -0
- package/dist/core/memory-engine/scope-contract.js +205 -0
- package/dist/core/memory-engine/scope-contract.js.map +1 -0
- package/dist/core/memory-engine/sync-client.d.ts +57 -0
- package/dist/core/memory-engine/sync-client.d.ts.map +1 -0
- package/dist/core/memory-engine/sync-client.js +257 -0
- package/dist/core/memory-engine/sync-client.js.map +1 -0
- package/dist/core/memory-engine/sync.d.ts +37 -0
- package/dist/core/memory-engine/sync.d.ts.map +1 -0
- package/dist/core/memory-engine/sync.js +68 -0
- package/dist/core/memory-engine/sync.js.map +1 -0
- package/dist/core/memory-engine/types.d.ts +128 -0
- package/dist/core/memory-engine/types.d.ts.map +1 -0
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory-engine/types.js.map +1 -0
- package/dist/core/memory-recall.d.ts +82 -0
- package/dist/core/memory-recall.d.ts.map +1 -0
- package/dist/core/memory-recall.js +352 -0
- package/dist/core/memory-recall.js.map +1 -0
- package/dist/core/memory-vector.d.ts +4 -0
- package/dist/core/memory-vector.d.ts.map +1 -0
- package/dist/core/memory-vector.js +31 -0
- package/dist/core/memory-vector.js.map +1 -0
- package/dist/core/memory.d.ts +112 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +512 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/message-utils.d.ts +4 -0
- package/dist/core/message-utils.d.ts.map +1 -0
- package/dist/core/message-utils.js +7 -0
- package/dist/core/message-utils.js.map +1 -0
- package/dist/core/oracle-isolation.d.ts +16 -0
- package/dist/core/oracle-isolation.d.ts.map +1 -0
- package/dist/core/oracle-isolation.js +50 -0
- package/dist/core/oracle-isolation.js.map +1 -0
- package/dist/core/permission-rules.d.ts +35 -0
- package/dist/core/permission-rules.d.ts.map +1 -0
- package/dist/core/permission-rules.js +270 -0
- package/dist/core/permission-rules.js.map +1 -0
- package/dist/core/present-plan-tool.d.ts +8 -0
- package/dist/core/present-plan-tool.d.ts.map +1 -0
- package/dist/core/present-plan-tool.js +82 -0
- package/dist/core/present-plan-tool.js.map +1 -0
- package/dist/core/pricing.d.ts +22 -0
- package/dist/core/pricing.d.ts.map +1 -0
- package/dist/core/pricing.js +23 -0
- package/dist/core/pricing.js.map +1 -0
- package/dist/core/property-harness.d.ts +40 -0
- package/dist/core/property-harness.d.ts.map +1 -0
- package/dist/core/property-harness.js +121 -0
- package/dist/core/property-harness.js.map +1 -0
- package/dist/core/push-queue.d.ts +9 -0
- package/dist/core/push-queue.d.ts.map +1 -0
- package/dist/core/push-queue.js +41 -0
- package/dist/core/push-queue.js.map +1 -0
- package/dist/core/remote-env.d.ts +105 -0
- package/dist/core/remote-env.d.ts.map +1 -0
- package/dist/core/remote-env.js +27 -0
- package/dist/core/remote-env.js.map +1 -0
- package/dist/core/roles.d.ts +35 -0
- package/dist/core/roles.d.ts.map +1 -0
- package/dist/core/roles.js +182 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/runner/active-skill-scope.d.ts +26 -0
- package/dist/core/runner/active-skill-scope.d.ts.map +1 -0
- package/dist/core/runner/active-skill-scope.js +116 -0
- package/dist/core/runner/active-skill-scope.js.map +1 -0
- package/dist/core/runner/assemble-result.d.ts +89 -0
- package/dist/core/runner/assemble-result.d.ts.map +1 -0
- package/dist/core/runner/assemble-result.js +141 -0
- package/dist/core/runner/assemble-result.js.map +1 -0
- package/dist/core/runner/call-cap.d.ts +38 -0
- package/dist/core/runner/call-cap.d.ts.map +1 -0
- package/dist/core/runner/call-cap.js +76 -0
- package/dist/core/runner/call-cap.js.map +1 -0
- package/dist/core/runner/grounding-signal.d.ts +2 -0
- package/dist/core/runner/grounding-signal.d.ts.map +1 -0
- package/dist/core/runner/grounding-signal.js +32 -0
- package/dist/core/runner/grounding-signal.js.map +1 -0
- package/dist/core/runner/image.d.ts +6 -0
- package/dist/core/runner/image.d.ts.map +1 -0
- package/dist/core/runner/image.js +116 -0
- package/dist/core/runner/image.js.map +1 -0
- package/dist/core/runner/memory-consolidation.d.ts +52 -0
- package/dist/core/runner/memory-consolidation.d.ts.map +1 -0
- package/dist/core/runner/memory-consolidation.js +253 -0
- package/dist/core/runner/memory-consolidation.js.map +1 -0
- package/dist/core/runner/prepare-task.d.ts +219 -0
- package/dist/core/runner/prepare-task.d.ts.map +1 -0
- package/dist/core/runner/prepare-task.js +2087 -0
- package/dist/core/runner/prepare-task.js.map +1 -0
- package/dist/core/runner/prompt-suggestions.d.ts +26 -0
- package/dist/core/runner/prompt-suggestions.d.ts.map +1 -0
- package/dist/core/runner/prompt-suggestions.js +104 -0
- package/dist/core/runner/prompt-suggestions.js.map +1 -0
- package/dist/core/runner/runtask.d.ts +53 -0
- package/dist/core/runner/runtask.d.ts.map +1 -0
- package/dist/core/runner/runtask.js +2703 -0
- package/dist/core/runner/runtask.js.map +1 -0
- package/dist/core/runner/session-rule-policy.d.ts +11 -0
- package/dist/core/runner/session-rule-policy.d.ts.map +1 -0
- package/dist/core/runner/session-rule-policy.js +76 -0
- package/dist/core/runner/session-rule-policy.js.map +1 -0
- package/dist/core/runner/strict-output-schema.d.ts +21 -0
- package/dist/core/runner/strict-output-schema.d.ts.map +1 -0
- package/dist/core/runner/strict-output-schema.js +304 -0
- package/dist/core/runner/strict-output-schema.js.map +1 -0
- package/dist/core/runner/synthetic-tools.d.ts +30 -0
- package/dist/core/runner/synthetic-tools.d.ts.map +1 -0
- package/dist/core/runner/synthetic-tools.js +124 -0
- package/dist/core/runner/synthetic-tools.js.map +1 -0
- package/dist/core/runner/tool-disclosure.d.ts +46 -0
- package/dist/core/runner/tool-disclosure.d.ts.map +1 -0
- package/dist/core/runner/tool-disclosure.js +220 -0
- package/dist/core/runner/tool-disclosure.js.map +1 -0
- package/dist/core/runner/turn-attachments.d.ts +110 -0
- package/dist/core/runner/turn-attachments.d.ts.map +1 -0
- package/dist/core/runner/turn-attachments.js +334 -0
- package/dist/core/runner/turn-attachments.js.map +1 -0
- package/dist/core/runner/usage-accounting.d.ts +19 -0
- package/dist/core/runner/usage-accounting.d.ts.map +1 -0
- package/dist/core/runner/usage-accounting.js +30 -0
- package/dist/core/runner/usage-accounting.js.map +1 -0
- package/dist/core/runtime.d.ts +4 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +12 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/safety-axis-vocab.d.ts +10 -0
- package/dist/core/safety-axis-vocab.d.ts.map +1 -0
- package/dist/core/safety-axis-vocab.js +12 -0
- package/dist/core/safety-axis-vocab.js.map +1 -0
- package/dist/core/safety-merge-corpus.d.ts +11 -0
- package/dist/core/safety-merge-corpus.d.ts.map +1 -0
- package/dist/core/safety-merge-corpus.js +195 -0
- package/dist/core/safety-merge-corpus.js.map +1 -0
- package/dist/core/scheduler.d.ts +55 -0
- package/dist/core/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler.js +32 -0
- package/dist/core/scheduler.js.map +1 -0
- package/dist/core/secret-env.d.ts +3 -0
- package/dist/core/secret-env.d.ts.map +1 -0
- package/dist/core/secret-env.js +13 -0
- package/dist/core/secret-env.js.map +1 -0
- package/dist/core/select-model.d.ts +11 -0
- package/dist/core/select-model.d.ts.map +1 -0
- package/dist/core/select-model.js +44 -0
- package/dist/core/select-model.js.map +1 -0
- package/dist/core/sensitive-path-policy.d.ts +9 -0
- package/dist/core/sensitive-path-policy.d.ts.map +1 -0
- package/dist/core/sensitive-path-policy.js +61 -0
- package/dist/core/sensitive-path-policy.js.map +1 -0
- package/dist/core/session-policy-store.d.ts +38 -0
- package/dist/core/session-policy-store.d.ts.map +1 -0
- package/dist/core/session-policy-store.js +112 -0
- package/dist/core/session-policy-store.js.map +1 -0
- package/dist/core/session-reconcile.d.ts +15 -0
- package/dist/core/session-reconcile.d.ts.map +1 -0
- package/dist/core/session-reconcile.js +48 -0
- package/dist/core/session-reconcile.js.map +1 -0
- package/dist/core/session-store.d.ts +36 -0
- package/dist/core/session-store.d.ts.map +1 -0
- package/dist/core/session-store.js +192 -0
- package/dist/core/session-store.js.map +1 -0
- package/dist/core/session.d.ts +44 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +27 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/spec-contract.d.ts +58 -0
- package/dist/core/spec-contract.d.ts.map +1 -0
- package/dist/core/spec-contract.js +256 -0
- package/dist/core/spec-contract.js.map +1 -0
- package/dist/core/strategy-store.d.ts +25 -0
- package/dist/core/strategy-store.d.ts.map +1 -0
- package/dist/core/strategy-store.js +81 -0
- package/dist/core/strategy-store.js.map +1 -0
- package/dist/core/stub-env.d.ts +28 -0
- package/dist/core/stub-env.d.ts.map +1 -0
- package/dist/core/stub-env.js +61 -0
- package/dist/core/stub-env.js.map +1 -0
- package/dist/core/task-notification.d.ts +56 -0
- package/dist/core/task-notification.d.ts.map +1 -0
- package/dist/core/task-notification.js +200 -0
- package/dist/core/task-notification.js.map +1 -0
- package/dist/core/task-outcome.d.ts +27 -0
- package/dist/core/task-outcome.d.ts.map +1 -0
- package/dist/core/task-outcome.js +12 -0
- package/dist/core/task-outcome.js.map +1 -0
- package/dist/core/task-registry.d.ts +188 -0
- package/dist/core/task-registry.d.ts.map +1 -0
- package/dist/core/task-registry.js +1443 -0
- package/dist/core/task-registry.js.map +1 -0
- package/dist/core/tighten-task-spec.d.ts +6 -0
- package/dist/core/tighten-task-spec.d.ts.map +1 -0
- package/dist/core/tighten-task-spec.js +50 -0
- package/dist/core/tighten-task-spec.js.map +1 -0
- package/dist/core/tool-detach.d.ts +10 -0
- package/dist/core/tool-detach.d.ts.map +1 -0
- package/dist/core/tool-detach.js +41 -0
- package/dist/core/tool-detach.js.map +1 -0
- package/dist/core/tool-errors.d.ts +8 -0
- package/dist/core/tool-errors.d.ts.map +1 -0
- package/dist/core/tool-errors.js +132 -0
- package/dist/core/tool-errors.js.map +1 -0
- package/dist/core/tool-name-aliases.d.ts +3 -0
- package/dist/core/tool-name-aliases.d.ts.map +1 -0
- package/dist/core/tool-name-aliases.js +60 -0
- package/dist/core/tool-name-aliases.js.map +1 -0
- package/dist/core/tool-policy.d.ts +75 -0
- package/dist/core/tool-policy.d.ts.map +1 -0
- package/dist/core/tool-policy.js +363 -0
- package/dist/core/tool-policy.js.map +1 -0
- package/dist/core/tool-result-budget.d.ts +17 -0
- package/dist/core/tool-result-budget.d.ts.map +1 -0
- package/dist/core/tool-result-budget.js +103 -0
- package/dist/core/tool-result-budget.js.map +1 -0
- package/dist/core/tool-result-store.d.ts +55 -0
- package/dist/core/tool-result-store.d.ts.map +1 -0
- package/dist/core/tool-result-store.js +154 -0
- package/dist/core/tool-result-store.js.map +1 -0
- package/dist/core/tools.d.ts +6 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +61 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/trace.d.ts +208 -0
- package/dist/core/trace.d.ts.map +1 -0
- package/dist/core/trace.js +10 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +684 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/untrusted-egress.d.ts +7 -0
- package/dist/core/untrusted-egress.d.ts.map +1 -0
- package/dist/core/untrusted-egress.js +23 -0
- package/dist/core/untrusted-egress.js.map +1 -0
- package/dist/core/untrusted-text.d.ts +5 -0
- package/dist/core/untrusted-text.d.ts.map +1 -0
- package/dist/core/untrusted-text.js +36 -0
- package/dist/core/untrusted-text.js.map +1 -0
- package/dist/core/warm-resume.d.ts +6 -0
- package/dist/core/warm-resume.d.ts.map +1 -0
- package/dist/core/warm-resume.js +11 -0
- package/dist/core/warm-resume.js.map +1 -0
- package/dist/core/with-retry.d.ts +19 -0
- package/dist/core/with-retry.d.ts.map +1 -0
- package/dist/core/with-retry.js +36 -0
- package/dist/core/with-retry.js.map +1 -0
- package/dist/core/workflow-journal-store.d.ts +16 -0
- package/dist/core/workflow-journal-store.d.ts.map +1 -0
- package/dist/core/workflow-journal-store.js +34 -0
- package/dist/core/workflow-journal-store.js.map +1 -0
- package/dist/core/workflow-run-store-contract.d.ts +6 -0
- package/dist/core/workflow-run-store-contract.d.ts.map +1 -0
- package/dist/core/workflow-run-store-contract.js +144 -0
- package/dist/core/workflow-run-store-contract.js.map +1 -0
- package/dist/core/workflow-run-store.d.ts +54 -0
- package/dist/core/workflow-run-store.d.ts.map +1 -0
- package/dist/core/workflow-run-store.js +86 -0
- package/dist/core/workflow-run-store.js.map +1 -0
- package/dist/engine/compaction/compaction.d.ts +63 -0
- package/dist/engine/compaction/compaction.d.ts.map +1 -0
- package/dist/engine/compaction/compaction.js +770 -0
- package/dist/engine/compaction/compaction.js.map +1 -0
- package/dist/engine/compaction/utils.d.ts +19 -0
- package/dist/engine/compaction/utils.d.ts.map +1 -0
- package/dist/engine/compaction/utils.js +167 -0
- package/dist/engine/compaction/utils.js.map +1 -0
- package/dist/engine/execution-env/kill-tree.d.ts +10 -0
- package/dist/engine/execution-env/kill-tree.d.ts.map +1 -0
- package/dist/engine/execution-env/kill-tree.js +143 -0
- package/dist/engine/execution-env/kill-tree.js.map +1 -0
- package/dist/engine/execution-env/node-execution-env.d.ts +98 -0
- package/dist/engine/execution-env/node-execution-env.d.ts.map +1 -0
- package/dist/engine/execution-env/node-execution-env.js +945 -0
- package/dist/engine/execution-env/node-execution-env.js.map +1 -0
- package/dist/engine/harness/agent-harness.d.ts +112 -0
- package/dist/engine/harness/agent-harness.d.ts.map +1 -0
- package/dist/engine/harness/agent-harness.js +932 -0
- package/dist/engine/harness/agent-harness.js.map +1 -0
- package/dist/engine/harness/messages.d.ts +12 -0
- package/dist/engine/harness/messages.d.ts.map +1 -0
- package/dist/engine/harness/messages.js +102 -0
- package/dist/engine/harness/messages.js.map +1 -0
- package/dist/engine/harness/types.d.ts +484 -0
- package/dist/engine/harness/types.d.ts.map +1 -0
- package/dist/engine/harness/types.js +91 -0
- package/dist/engine/harness/types.js.map +1 -0
- package/dist/engine/llm/diagnostics.d.ts +19 -0
- package/dist/engine/llm/diagnostics.d.ts.map +1 -0
- package/dist/engine/llm/diagnostics.js +28 -0
- package/dist/engine/llm/diagnostics.js.map +1 -0
- package/dist/engine/llm/event-stream.d.ts +22 -0
- package/dist/engine/llm/event-stream.d.ts.map +1 -0
- package/dist/engine/llm/event-stream.js +91 -0
- package/dist/engine/llm/event-stream.js.map +1 -0
- package/dist/engine/llm/index.d.ts +5 -0
- package/dist/engine/llm/index.d.ts.map +1 -0
- package/dist/engine/llm/index.js +5 -0
- package/dist/engine/llm/index.js.map +1 -0
- package/dist/engine/llm/types.d.ts +359 -0
- package/dist/engine/llm/types.d.ts.map +1 -0
- package/dist/engine/llm/types.js +2 -0
- package/dist/engine/llm/types.js.map +1 -0
- package/dist/engine/llm/validation.d.ts +5 -0
- package/dist/engine/llm/validation.d.ts.map +1 -0
- package/dist/engine/llm/validation.js +293 -0
- package/dist/engine/llm/validation.js.map +1 -0
- package/dist/engine/loop/agent-loop.d.ts +19 -0
- package/dist/engine/loop/agent-loop.d.ts.map +1 -0
- package/dist/engine/loop/agent-loop.js +1087 -0
- package/dist/engine/loop/agent-loop.js.map +1 -0
- package/dist/engine/loop/runtime-deps.d.ts +10 -0
- package/dist/engine/loop/runtime-deps.d.ts.map +1 -0
- package/dist/engine/loop/runtime-deps.js +19 -0
- package/dist/engine/loop/runtime-deps.js.map +1 -0
- package/dist/engine/loop/types.d.ts +209 -0
- package/dist/engine/loop/types.d.ts.map +1 -0
- package/dist/engine/loop/types.js +2 -0
- package/dist/engine/loop/types.js.map +1 -0
- package/dist/engine/lsp/frame-decoder.d.ts +3 -0
- package/dist/engine/lsp/frame-decoder.d.ts.map +1 -0
- package/dist/engine/lsp/frame-decoder.js +36 -0
- package/dist/engine/lsp/frame-decoder.js.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts +49 -0
- package/dist/engine/lsp/node-lsp-manager.d.ts.map +1 -0
- package/dist/engine/lsp/node-lsp-manager.js +267 -0
- package/dist/engine/lsp/node-lsp-manager.js.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts +32 -0
- package/dist/engine/lsp/stdio-lsp-transport.d.ts.map +1 -0
- package/dist/engine/lsp/stdio-lsp-transport.js +154 -0
- package/dist/engine/lsp/stdio-lsp-transport.js.map +1 -0
- package/dist/engine/session/import-validate.d.ts +13 -0
- package/dist/engine/session/import-validate.d.ts.map +1 -0
- package/dist/engine/session/import-validate.js +56 -0
- package/dist/engine/session/import-validate.js.map +1 -0
- package/dist/engine/session/memory-repo.d.ts +20 -0
- package/dist/engine/session/memory-repo.d.ts.map +1 -0
- package/dist/engine/session/memory-repo.js +54 -0
- package/dist/engine/session/memory-repo.js.map +1 -0
- package/dist/engine/session/memory-storage.d.ts +12 -0
- package/dist/engine/session/memory-storage.d.ts.map +1 -0
- package/dist/engine/session/memory-storage.js +16 -0
- package/dist/engine/session/memory-storage.js.map +1 -0
- package/dist/engine/session/repo-utils.d.ts +11 -0
- package/dist/engine/session/repo-utils.d.ts.map +1 -0
- package/dist/engine/session/repo-utils.js +40 -0
- package/dist/engine/session/repo-utils.js.map +1 -0
- package/dist/engine/session/session.d.ts +27 -0
- package/dist/engine/session/session.d.ts.map +1 -0
- package/dist/engine/session/session.js +197 -0
- package/dist/engine/session/session.js.map +1 -0
- package/dist/engine/session/storage-base.d.ts +30 -0
- package/dist/engine/session/storage-base.d.ts.map +1 -0
- package/dist/engine/session/storage-base.js +138 -0
- package/dist/engine/session/storage-base.js.map +1 -0
- package/dist/engine/session/timestamps.d.ts +3 -0
- package/dist/engine/session/timestamps.d.ts.map +1 -0
- package/dist/engine/session/timestamps.js +15 -0
- package/dist/engine/session/timestamps.js.map +1 -0
- package/dist/engine/session/uuid.d.ts +2 -0
- package/dist/engine/session/uuid.d.ts.map +1 -0
- package/dist/engine/session/uuid.js +50 -0
- package/dist/engine/session/uuid.js.map +1 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/harness.d.ts +19 -0
- package/dist/internal/harness.d.ts.map +1 -0
- package/dist/internal/harness.js +13 -0
- package/dist/internal/harness.js.map +1 -0
- package/dist/internal/llm.d.ts +3 -0
- package/dist/internal/llm.d.ts.map +1 -0
- package/dist/internal/llm.js +2 -0
- package/dist/internal/llm.js.map +1 -0
- package/dist/orchestration/builtin-workflows.d.ts +11 -0
- package/dist/orchestration/builtin-workflows.d.ts.map +1 -0
- package/dist/orchestration/builtin-workflows.js +134 -0
- package/dist/orchestration/builtin-workflows.js.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts +5 -0
- package/dist/orchestration/dev-vm-script-runner.d.ts.map +1 -0
- package/dist/orchestration/dev-vm-script-runner.js +68 -0
- package/dist/orchestration/dev-vm-script-runner.js.map +1 -0
- package/dist/orchestration/goal.d.ts +40 -0
- package/dist/orchestration/goal.d.ts.map +1 -0
- package/dist/orchestration/goal.js +190 -0
- package/dist/orchestration/goal.js.map +1 -0
- package/dist/orchestration/run-spec.d.ts +21 -0
- package/dist/orchestration/run-spec.d.ts.map +1 -0
- package/dist/orchestration/run-spec.js +201 -0
- package/dist/orchestration/run-spec.js.map +1 -0
- package/dist/orchestration/run-workflow-tool.d.ts +80 -0
- package/dist/orchestration/run-workflow-tool.d.ts.map +1 -0
- package/dist/orchestration/run-workflow-tool.js +431 -0
- package/dist/orchestration/run-workflow-tool.js.map +1 -0
- package/dist/orchestration/workflow-governance.d.ts +30 -0
- package/dist/orchestration/workflow-governance.d.ts.map +1 -0
- package/dist/orchestration/workflow-governance.js +125 -0
- package/dist/orchestration/workflow-governance.js.map +1 -0
- package/dist/orchestration/workflow-meta.d.ts +13 -0
- package/dist/orchestration/workflow-meta.d.ts.map +1 -0
- package/dist/orchestration/workflow-meta.js +367 -0
- package/dist/orchestration/workflow-meta.js.map +1 -0
- package/dist/orchestration/workflow-observe.d.ts +18 -0
- package/dist/orchestration/workflow-observe.d.ts.map +1 -0
- package/dist/orchestration/workflow-observe.js +73 -0
- package/dist/orchestration/workflow-observe.js.map +1 -0
- package/dist/orchestration/workflow-primitives.d.ts +12 -0
- package/dist/orchestration/workflow-primitives.d.ts.map +1 -0
- package/dist/orchestration/workflow-primitives.js +56 -0
- package/dist/orchestration/workflow-primitives.js.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts +5 -0
- package/dist/orchestration/workflow-sandbox-conformance.d.ts.map +1 -0
- package/dist/orchestration/workflow-sandbox-conformance.js +220 -0
- package/dist/orchestration/workflow-sandbox-conformance.js.map +1 -0
- package/dist/orchestration/workflow-script-runner.d.ts +39 -0
- package/dist/orchestration/workflow-script-runner.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-runner.js +23 -0
- package/dist/orchestration/workflow-script-runner.js.map +1 -0
- package/dist/orchestration/workflow-script-store.d.ts +20 -0
- package/dist/orchestration/workflow-script-store.d.ts.map +1 -0
- package/dist/orchestration/workflow-script-store.js +73 -0
- package/dist/orchestration/workflow-script-store.js.map +1 -0
- package/dist/orchestration/workflow-size-guideline.d.ts +10 -0
- package/dist/orchestration/workflow-size-guideline.d.ts.map +1 -0
- package/dist/orchestration/workflow-size-guideline.js +38 -0
- package/dist/orchestration/workflow-size-guideline.js.map +1 -0
- package/dist/orchestration/workflow.d.ts +281 -0
- package/dist/orchestration/workflow.d.ts.map +1 -0
- package/dist/orchestration/workflow.js +1095 -0
- package/dist/orchestration/workflow.js.map +1 -0
- package/dist/prompts/default.d.ts +104 -0
- package/dist/prompts/default.d.ts.map +1 -0
- package/dist/prompts/default.js +397 -0
- package/dist/prompts/default.js.map +1 -0
- package/dist/prompts/supervisor.d.ts +5 -0
- package/dist/prompts/supervisor.d.ts.map +1 -0
- package/dist/prompts/supervisor.js +107 -0
- package/dist/prompts/supervisor.js.map +1 -0
- package/dist/scenarios/env.d.ts +13 -0
- package/dist/scenarios/env.d.ts.map +1 -0
- package/dist/scenarios/env.js +40 -0
- package/dist/scenarios/env.js.map +1 -0
- package/dist/scenarios/full-body.d.ts +13 -0
- package/dist/scenarios/full-body.d.ts.map +1 -0
- package/dist/scenarios/full-body.js +20 -0
- package/dist/scenarios/full-body.js.map +1 -0
- package/dist/scenarios/scenario-registry.d.ts +47 -0
- package/dist/scenarios/scenario-registry.d.ts.map +1 -0
- package/dist/scenarios/scenario-registry.js +139 -0
- package/dist/scenarios/scenario-registry.js.map +1 -0
- package/dist/scenarios/teacher-quickstart.d.ts +14 -0
- package/dist/scenarios/teacher-quickstart.d.ts.map +1 -0
- package/dist/scenarios/teacher-quickstart.js +13 -0
- package/dist/scenarios/teacher-quickstart.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +115 -0
- package/dist/server/http.js.map +1 -0
- package/dist/stores/file/checkpoint-store.d.ts +40 -0
- package/dist/stores/file/checkpoint-store.d.ts.map +1 -0
- package/dist/stores/file/checkpoint-store.js +198 -0
- package/dist/stores/file/checkpoint-store.js.map +1 -0
- package/dist/stores/file/file-snapshot-store.d.ts +25 -0
- package/dist/stores/file/file-snapshot-store.d.ts.map +1 -0
- package/dist/stores/file/file-snapshot-store.js +313 -0
- package/dist/stores/file/file-snapshot-store.js.map +1 -0
- package/dist/stores/file/fs-atomic.d.ts +24 -0
- package/dist/stores/file/fs-atomic.d.ts.map +1 -0
- package/dist/stores/file/fs-atomic.js +276 -0
- package/dist/stores/file/fs-atomic.js.map +1 -0
- package/dist/stores/file/index.d.ts +45 -0
- package/dist/stores/file/index.d.ts.map +1 -0
- package/dist/stores/file/index.js +77 -0
- package/dist/stores/file/index.js.map +1 -0
- package/dist/stores/file/memory-store.d.ts +35 -0
- package/dist/stores/file/memory-store.d.ts.map +1 -0
- package/dist/stores/file/memory-store.js +300 -0
- package/dist/stores/file/memory-store.js.map +1 -0
- package/dist/stores/file/session-policy-store.d.ts +11 -0
- package/dist/stores/file/session-policy-store.d.ts.map +1 -0
- package/dist/stores/file/session-policy-store.js +96 -0
- package/dist/stores/file/session-policy-store.js.map +1 -0
- package/dist/stores/file/session-store.d.ts +24 -0
- package/dist/stores/file/session-store.d.ts.map +1 -0
- package/dist/stores/file/session-store.js +134 -0
- package/dist/stores/file/session-store.js.map +1 -0
- package/dist/stores/file/tool-result-store.d.ts +12 -0
- package/dist/stores/file/tool-result-store.d.ts.map +1 -0
- package/dist/stores/file/tool-result-store.js +44 -0
- package/dist/stores/file/tool-result-store.js.map +1 -0
- package/dist/stores/file/workflow-journal-store.d.ts +17 -0
- package/dist/stores/file/workflow-journal-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-journal-store.js +104 -0
- package/dist/stores/file/workflow-journal-store.js.map +1 -0
- package/dist/stores/file/workflow-run-store.d.ts +41 -0
- package/dist/stores/file/workflow-run-store.d.ts.map +1 -0
- package/dist/stores/file/workflow-run-store.js +147 -0
- package/dist/stores/file/workflow-run-store.js.map +1 -0
- package/dist/stores/pg.d.ts +96 -0
- package/dist/stores/pg.d.ts.map +1 -0
- package/dist/stores/pg.js +451 -0
- package/dist/stores/pg.js.map +1 -0
- package/dist/tools/fs/encoding.d.ts +16 -0
- package/dist/tools/fs/encoding.d.ts.map +1 -0
- package/dist/tools/fs/encoding.js +44 -0
- package/dist/tools/fs/encoding.js.map +1 -0
- package/dist/tools/fs/gh-rate-limit.d.ts +3 -0
- package/dist/tools/fs/gh-rate-limit.d.ts.map +1 -0
- package/dist/tools/fs/gh-rate-limit.js +16 -0
- package/dist/tools/fs/gh-rate-limit.js.map +1 -0
- package/dist/tools/fs/index.d.ts +74 -0
- package/dist/tools/fs/index.d.ts.map +1 -0
- package/dist/tools/fs/index.js +1576 -0
- package/dist/tools/fs/index.js.map +1 -0
- package/dist/tools/fs/pdf.d.ts +47 -0
- package/dist/tools/fs/pdf.d.ts.map +1 -0
- package/dist/tools/fs/pdf.js +124 -0
- package/dist/tools/fs/pdf.js.map +1 -0
- package/dist/tools/fs/repo-map.d.ts +5 -0
- package/dist/tools/fs/repo-map.d.ts.map +1 -0
- package/dist/tools/fs/repo-map.js +209 -0
- package/dist/tools/fs/repo-map.js.map +1 -0
- package/dist/tools/fs/safety.d.ts +52 -0
- package/dist/tools/fs/safety.d.ts.map +1 -0
- package/dist/tools/fs/safety.js +314 -0
- package/dist/tools/fs/safety.js.map +1 -0
- package/dist/tools/fs/search.d.ts +57 -0
- package/dist/tools/fs/search.d.ts.map +1 -0
- package/dist/tools/fs/search.js +574 -0
- package/dist/tools/fs/search.js.map +1 -0
- package/dist/tools/gitea-issue.d.ts +14 -0
- package/dist/tools/gitea-issue.d.ts.map +1 -0
- package/dist/tools/gitea-issue.js +74 -0
- package/dist/tools/gitea-issue.js.map +1 -0
- package/dist/tools/monitor.d.ts +20 -0
- package/dist/tools/monitor.d.ts.map +1 -0
- package/dist/tools/monitor.js +90 -0
- package/dist/tools/monitor.js.map +1 -0
- package/dist/tools/scheduler-tools.d.ts +15 -0
- package/dist/tools/scheduler-tools.d.ts.map +1 -0
- package/dist/tools/scheduler-tools.js +338 -0
- package/dist/tools/scheduler-tools.js.map +1 -0
- package/dist/tools/sql-adapters.d.ts +14 -0
- package/dist/tools/sql-adapters.d.ts.map +1 -0
- package/dist/tools/sql-adapters.js +13 -0
- package/dist/tools/sql-adapters.js.map +1 -0
- package/dist/tools/sql.d.ts +11 -0
- package/dist/tools/sql.d.ts.map +1 -0
- package/dist/tools/sql.js +104 -0
- package/dist/tools/sql.js.map +1 -0
- package/dist/tools/task-list.d.ts +14 -0
- package/dist/tools/task-list.d.ts.map +1 -0
- package/dist/tools/task-list.js +318 -0
- package/dist/tools/task-list.js.map +1 -0
- package/dist/tools/todo.d.ts +3 -0
- package/dist/tools/todo.d.ts.map +1 -0
- package/dist/tools/todo.js +97 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.d.ts +26 -0
- package/dist/tools/web.d.ts.map +1 -0
- package/dist/tools/web.js +498 -0
- package/dist/tools/web.js.map +1 -0
- package/dist/tools/worktree.d.ts +18 -0
- package/dist/tools/worktree.d.ts.map +1 -0
- package/dist/tools/worktree.js +288 -0
- package/dist/tools/worktree.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,1443 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { defineTool } from "./tools.js";
|
|
4
|
+
import { hasBackgroundShell } from "./background-shell.js";
|
|
5
|
+
import { summarizeWorkflowRun } from "./workflow-run-store.js";
|
|
6
|
+
import { delimitUntrusted } from "./untrusted-text.js";
|
|
7
|
+
import { boundedRedactedSummary } from "./untrusted-egress.js";
|
|
8
|
+
const defaultMonitorTimers = {
|
|
9
|
+
setInterval: (fn, ms) => {
|
|
10
|
+
const h = setInterval(() => void fn(), ms);
|
|
11
|
+
h.unref?.();
|
|
12
|
+
return h;
|
|
13
|
+
},
|
|
14
|
+
clearInterval: (h) => clearInterval(h),
|
|
15
|
+
now: () => Date.now(),
|
|
16
|
+
};
|
|
17
|
+
const BLOCK_DEFAULT_TIMEOUT_MS = 30_000;
|
|
18
|
+
const BLOCK_MAX_TIMEOUT_MS = 600_000;
|
|
19
|
+
const BLOCK_POLL_INTERVAL_MS = 400;
|
|
20
|
+
function blockDeadline(timeoutMs, now) {
|
|
21
|
+
const t = Math.min(BLOCK_MAX_TIMEOUT_MS, Math.max(1, Math.floor(timeoutMs ?? BLOCK_DEFAULT_TIMEOUT_MS)));
|
|
22
|
+
return now + t;
|
|
23
|
+
}
|
|
24
|
+
const sleepPollStep = (deadline, signal) => sleepMs(deadline === undefined ? BLOCK_POLL_INTERVAL_MS : Math.max(1, Math.min(BLOCK_POLL_INTERVAL_MS, deadline - Date.now())), signal);
|
|
25
|
+
const sleepMs = (ms, signal) => new Promise((resolve) => {
|
|
26
|
+
const t = setTimeout(done, ms);
|
|
27
|
+
function done() {
|
|
28
|
+
clearTimeout(t);
|
|
29
|
+
signal?.removeEventListener("abort", done);
|
|
30
|
+
resolve();
|
|
31
|
+
}
|
|
32
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
33
|
+
});
|
|
34
|
+
const TASK_PREFIX = {
|
|
35
|
+
background_bash: "b",
|
|
36
|
+
workflow: "w",
|
|
37
|
+
background_agent: "a",
|
|
38
|
+
monitor: "m",
|
|
39
|
+
};
|
|
40
|
+
export const BG_AGENT_REAP_STOP_ERROR = "stopped (parent task ended or TaskStop)";
|
|
41
|
+
export const MONITOR_BATCH_WINDOW_MS = 200;
|
|
42
|
+
export const MONITOR_DEFAULT_TIMEOUT_MS = 300_000;
|
|
43
|
+
export const MONITOR_MAX_TIMEOUT_MS = 3_600_000;
|
|
44
|
+
export const MONITOR_MAX_BATCHES_PER_MINUTE = 50;
|
|
45
|
+
const MONITOR_EVENT_RESULT_CAP = 2_000;
|
|
46
|
+
const TASK_OUTPUT_DEFAULT_CHARS = 32_000;
|
|
47
|
+
const TASK_OUTPUT_MAX_CHARS = 160_000;
|
|
48
|
+
const TASK_OUTPUT_ALIASES = ["BashOutput", "AgentOutputTool", "BashOutputTool", "AgentOutput", "WorkflowStatus"];
|
|
49
|
+
const TASK_STOP_ALIASES = ["KillShell", "KillBash"];
|
|
50
|
+
function taskMaxOutputChars() {
|
|
51
|
+
const raw = process.env.TASK_MAX_OUTPUT_LENGTH;
|
|
52
|
+
if (!raw)
|
|
53
|
+
return TASK_OUTPUT_DEFAULT_CHARS;
|
|
54
|
+
const n = parseInt(raw, 10);
|
|
55
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
56
|
+
return TASK_OUTPUT_DEFAULT_CHARS;
|
|
57
|
+
return Math.min(n, TASK_OUTPUT_MAX_CHARS);
|
|
58
|
+
}
|
|
59
|
+
export function clipTaskOutput(s, fullOutputPath) {
|
|
60
|
+
const limit = taskMaxOutputChars();
|
|
61
|
+
if (s.length <= limit)
|
|
62
|
+
return s;
|
|
63
|
+
if (fullOutputPath !== undefined) {
|
|
64
|
+
const header = `[Truncated. Full output: ${fullOutputPath}]\n\n`;
|
|
65
|
+
return header + s.slice(-(limit - header.length));
|
|
66
|
+
}
|
|
67
|
+
const half = Math.floor(limit / 2);
|
|
68
|
+
const omitted = s.length - 2 * half;
|
|
69
|
+
return `${s.slice(0, half)}\n…[${s.length} chars total, ${omitted} omitted from the middle]…\n${s.slice(s.length - half)}`;
|
|
70
|
+
}
|
|
71
|
+
function firstString(...values) {
|
|
72
|
+
for (const value of values) {
|
|
73
|
+
if (typeof value === "string" && value.trim() !== "")
|
|
74
|
+
return value.trim();
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
function noTask(taskId) {
|
|
79
|
+
return {
|
|
80
|
+
content: JSON.stringify({ error: "task not found" }),
|
|
81
|
+
details: { task_id: taskId, retrieval_status: "not_ready", error: "not_found" },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function normalizeAgentName(s) {
|
|
85
|
+
return s
|
|
86
|
+
.normalize("NFKC")
|
|
87
|
+
.replace(/[\p{Cc}\p{Cf}]/gu, (t) => (/\s/.test(t) ? t : ""))
|
|
88
|
+
.trim()
|
|
89
|
+
.toLowerCase()
|
|
90
|
+
.replace(/\s+/g, "-");
|
|
91
|
+
}
|
|
92
|
+
function editDistance(a, b) {
|
|
93
|
+
if (a === b)
|
|
94
|
+
return 0;
|
|
95
|
+
const m = a.length;
|
|
96
|
+
const n = b.length;
|
|
97
|
+
const d = Array.from({ length: m + 1 }, (_, i) => Array.from({ length: n + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
|
|
98
|
+
for (let i = 1; i <= m; i++) {
|
|
99
|
+
for (let j = 1; j <= n; j++) {
|
|
100
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
101
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
102
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
103
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return d[m][n];
|
|
108
|
+
}
|
|
109
|
+
function closestName(query, candidates) {
|
|
110
|
+
let best;
|
|
111
|
+
let bestDist = 3;
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
for (const c of candidates) {
|
|
114
|
+
if (seen.has(c))
|
|
115
|
+
continue;
|
|
116
|
+
seen.add(c);
|
|
117
|
+
if (Math.abs(c.length - query.length) > 2)
|
|
118
|
+
continue;
|
|
119
|
+
const dist = editDistance(query, c);
|
|
120
|
+
if (dist <= 2 && dist < bestDist) {
|
|
121
|
+
bestDist = dist;
|
|
122
|
+
best = c;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return best;
|
|
126
|
+
}
|
|
127
|
+
function noTaskForStop(taskId, enrich) {
|
|
128
|
+
let content = `No task found with ID: ${taskId}`;
|
|
129
|
+
if (enrich?.suggestion !== undefined)
|
|
130
|
+
content += `. Did you mean: ${enrich.suggestion}?`;
|
|
131
|
+
if (enrich?.runningAgents !== undefined && enrich.runningAgents.length > 0)
|
|
132
|
+
content += `. Running background agents: ${enrich.runningAgents.join(", ")}`;
|
|
133
|
+
return {
|
|
134
|
+
content,
|
|
135
|
+
details: { task_id: taskId, retrieval_status: "not_ready", error: "not_found" },
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function statusFromBackground(status, exitCode) {
|
|
139
|
+
if (status === "running")
|
|
140
|
+
return "running";
|
|
141
|
+
if (status === "killed")
|
|
142
|
+
return "killed";
|
|
143
|
+
if (status === "failed")
|
|
144
|
+
return "failed";
|
|
145
|
+
if (status === "exited")
|
|
146
|
+
return exitCode === 0 ? "completed" : "failed";
|
|
147
|
+
return "failed";
|
|
148
|
+
}
|
|
149
|
+
function monitorInTimeoutWindow(handle) {
|
|
150
|
+
return handle.status === "running" && handle.deadlineAt !== undefined && handle.timers.now() < handle.deadlineAt;
|
|
151
|
+
}
|
|
152
|
+
function canAccess(handle, access) {
|
|
153
|
+
if (handle.scope !== undefined && access.scope !== handle.scope)
|
|
154
|
+
return false;
|
|
155
|
+
if (handle.owner === undefined)
|
|
156
|
+
return true;
|
|
157
|
+
if (access.owner === handle.owner)
|
|
158
|
+
return true;
|
|
159
|
+
if (handle.sessionScoped && access.sessionId !== undefined && access.sessionId === handle.owner)
|
|
160
|
+
return true;
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
function assertOwnership(input, site) {
|
|
164
|
+
if (input.owner === undefined && input.scope === undefined) {
|
|
165
|
+
throw new Error(`TaskRegistry.${site}: refusing to register a task with neither owner nor scope (would be accessible to every caller)`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function canAccessWorkflowRun(run, access) {
|
|
169
|
+
if (access.scope === undefined || run.scope !== access.scope)
|
|
170
|
+
return false;
|
|
171
|
+
if (access.owner !== undefined && run.sourceTaskId !== access.owner)
|
|
172
|
+
return false;
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
function formatWorkflowRun(run) {
|
|
176
|
+
const summary = summarizeWorkflowRun(run);
|
|
177
|
+
const done = run.agents.filter((a) => a.status === "completed" || a.status === "failed").length;
|
|
178
|
+
const failed = run.agents.filter((a) => a.status === "failed").length;
|
|
179
|
+
return {
|
|
180
|
+
content: JSON.stringify({
|
|
181
|
+
task_id: run.id,
|
|
182
|
+
runId: run.id,
|
|
183
|
+
type: "workflow",
|
|
184
|
+
status: run.status,
|
|
185
|
+
...(summary.name ? { name: summary.name } : {}),
|
|
186
|
+
...(summary.currentPhase ? { currentPhase: summary.currentPhase } : {}),
|
|
187
|
+
agents: { done, total: run.agents.length, failed },
|
|
188
|
+
startedAt: run.startedAt,
|
|
189
|
+
...(run.endedAt !== undefined ? { endedAt: run.endedAt, elapsedMs: run.endedAt - run.startedAt } : {}),
|
|
190
|
+
...(run.status === "failed" && run.error ? { error: delimitUntrusted("workflow error", boundedRedactedSummary(run.error, 500)) } : {}),
|
|
191
|
+
...(run.status === "completed" && run.result !== undefined
|
|
192
|
+
? { result: delimitUntrusted("workflow result", run.resultFull ?? run.result) }
|
|
193
|
+
: {}),
|
|
194
|
+
note: run.status === "running"
|
|
195
|
+
? "still running — poll again shortly."
|
|
196
|
+
: run.status === "completed"
|
|
197
|
+
? run.result !== undefined
|
|
198
|
+
? "completed — `result` above is the workflow's return value."
|
|
199
|
+
: "completed — this run predates result persistence; its result was delivered on the completion notification."
|
|
200
|
+
: "failed — see error.",
|
|
201
|
+
}),
|
|
202
|
+
details: {
|
|
203
|
+
task_id: run.id,
|
|
204
|
+
type: "workflow",
|
|
205
|
+
status: run.status,
|
|
206
|
+
retrieval_status: "success",
|
|
207
|
+
details: summary,
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
export class TaskRegistry {
|
|
212
|
+
handles = new Map();
|
|
213
|
+
sessionReapHooks = new Set();
|
|
214
|
+
legacyToTaskId = new Map();
|
|
215
|
+
mintTaskId(type) {
|
|
216
|
+
const prefix = TASK_PREFIX[type];
|
|
217
|
+
for (let i = 0; i < 32; i++) {
|
|
218
|
+
const id = `${prefix}${randomBytes(8).toString("hex")}`;
|
|
219
|
+
if (!this.handles.has(id) && !this.legacyToTaskId.has(id))
|
|
220
|
+
return id;
|
|
221
|
+
}
|
|
222
|
+
throw new Error(`TaskRegistry: exhausted task id mint retries for ${type}`);
|
|
223
|
+
}
|
|
224
|
+
registerBackgroundBash(input) {
|
|
225
|
+
assertOwnership(input, "registerBackgroundBash");
|
|
226
|
+
const id = input.id ?? this.mintTaskId("background_bash");
|
|
227
|
+
if (this.handles.has(id))
|
|
228
|
+
throw new Error(`TaskRegistry: task id already registered: ${id}`);
|
|
229
|
+
const now = input.now ?? Date.now();
|
|
230
|
+
this.handles.set(id, {
|
|
231
|
+
id,
|
|
232
|
+
type: "background_bash",
|
|
233
|
+
status: "running",
|
|
234
|
+
...(input.sessionScoped ? { sessionScoped: true } : {}),
|
|
235
|
+
...(input.description !== undefined ? { description: input.description } : {}),
|
|
236
|
+
...(input.owner !== undefined ? { owner: input.owner } : {}),
|
|
237
|
+
...(input.scope !== undefined ? { scope: input.scope } : {}),
|
|
238
|
+
...(input.toolUseId !== undefined ? { toolUseId: input.toolUseId } : {}),
|
|
239
|
+
createdAt: now,
|
|
240
|
+
updatedAt: now,
|
|
241
|
+
env: input.env,
|
|
242
|
+
shellId: input.shellId,
|
|
243
|
+
...(input.onTerminal !== undefined ? { onTerminal: input.onTerminal } : {}),
|
|
244
|
+
});
|
|
245
|
+
this.legacyToTaskId.set(String(input.shellId), id);
|
|
246
|
+
if (input.onTerminal)
|
|
247
|
+
this.startBashWatcher(id, input.onTerminal);
|
|
248
|
+
return id;
|
|
249
|
+
}
|
|
250
|
+
registerBackgroundAgent(input) {
|
|
251
|
+
assertOwnership(input, "registerBackgroundAgent");
|
|
252
|
+
const id = this.mintTaskId("background_agent");
|
|
253
|
+
const now = input.now ?? Date.now();
|
|
254
|
+
this.handles.set(id, {
|
|
255
|
+
id,
|
|
256
|
+
type: "background_agent",
|
|
257
|
+
status: "running",
|
|
258
|
+
...(input.sessionScoped ? { sessionScoped: true } : {}),
|
|
259
|
+
...(input.description !== undefined ? { description: input.description } : {}),
|
|
260
|
+
...(input.owner !== undefined ? { owner: input.owner } : {}),
|
|
261
|
+
...(input.scope !== undefined ? { scope: input.scope } : {}),
|
|
262
|
+
...(input.toolUseId !== undefined ? { toolUseId: input.toolUseId } : {}),
|
|
263
|
+
createdAt: now,
|
|
264
|
+
updatedAt: now,
|
|
265
|
+
abort: input.abort,
|
|
266
|
+
});
|
|
267
|
+
return id;
|
|
268
|
+
}
|
|
269
|
+
markStopSource(id, source) {
|
|
270
|
+
const handle = this.handles.get(id);
|
|
271
|
+
if (!handle || (handle.type !== "background_agent" && handle.type !== "background_bash" && handle.type !== "monitor"))
|
|
272
|
+
return;
|
|
273
|
+
if (handle.status !== "running" || handle.stopSource !== undefined)
|
|
274
|
+
return;
|
|
275
|
+
handle.stopSource = source;
|
|
276
|
+
}
|
|
277
|
+
markStopSourceByShellId(shellId, source, env) {
|
|
278
|
+
const sid = String(shellId);
|
|
279
|
+
const taskId = this.legacyToTaskId.get(sid);
|
|
280
|
+
if (taskId !== undefined) {
|
|
281
|
+
const handle = this.handles.get(taskId);
|
|
282
|
+
if (handle && handle.type === "background_bash" && (env === undefined || handle.env === env)) {
|
|
283
|
+
this.markStopSource(taskId, source);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (env === undefined)
|
|
288
|
+
return;
|
|
289
|
+
for (const [id, handle] of this.handles) {
|
|
290
|
+
if (handle.type === "background_bash" && String(handle.shellId) === sid && handle.env === env) {
|
|
291
|
+
this.markStopSource(id, source);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
clearPendingStopSourceByShellId(shellId, source, env) {
|
|
297
|
+
const sid = String(shellId);
|
|
298
|
+
const clear = (id) => {
|
|
299
|
+
const handle = this.handles.get(id);
|
|
300
|
+
if (!handle || handle.type !== "background_bash")
|
|
301
|
+
return false;
|
|
302
|
+
if (env !== undefined && handle.env !== env)
|
|
303
|
+
return false;
|
|
304
|
+
if (handle.status === "running" && handle.stopSource === source && handle.stoppedBy === undefined) {
|
|
305
|
+
handle.stopSource = undefined;
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
};
|
|
309
|
+
const taskId = this.legacyToTaskId.get(sid);
|
|
310
|
+
if (taskId !== undefined && clear(taskId))
|
|
311
|
+
return;
|
|
312
|
+
if (env === undefined)
|
|
313
|
+
return;
|
|
314
|
+
for (const [id, handle] of this.handles) {
|
|
315
|
+
if (handle.type === "background_bash" && String(handle.shellId) === sid && handle.env === env) {
|
|
316
|
+
clear(id);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
getStopAttribution(id) {
|
|
322
|
+
const handle = this.handles.get(id);
|
|
323
|
+
if (!handle || (handle.type !== "background_agent" && handle.type !== "background_bash" && handle.type !== "monitor"))
|
|
324
|
+
return undefined;
|
|
325
|
+
if (handle.status !== "killed")
|
|
326
|
+
return undefined;
|
|
327
|
+
return handle.stoppedBy ?? handle.stopSource ?? "system";
|
|
328
|
+
}
|
|
329
|
+
settleBackgroundAgent(id, outcome) {
|
|
330
|
+
const handle = this.handles.get(id);
|
|
331
|
+
if (!handle || handle.type !== "background_agent")
|
|
332
|
+
return undefined;
|
|
333
|
+
if (handle.status !== "running") {
|
|
334
|
+
if (handle.status === "killed") {
|
|
335
|
+
let backfilled = false;
|
|
336
|
+
if (handle.result === undefined && outcome.result !== undefined && outcome.result !== "") {
|
|
337
|
+
handle.result = outcome.result;
|
|
338
|
+
handle.resultIsPartial = true;
|
|
339
|
+
backfilled = true;
|
|
340
|
+
}
|
|
341
|
+
if (handle.error === undefined && outcome.error !== undefined && outcome.error !== BG_AGENT_REAP_STOP_ERROR) {
|
|
342
|
+
handle.error = outcome.error;
|
|
343
|
+
backfilled = true;
|
|
344
|
+
}
|
|
345
|
+
if (backfilled)
|
|
346
|
+
handle.updatedAt = Date.now();
|
|
347
|
+
}
|
|
348
|
+
return handle.status === "completed" || handle.status === "failed" || handle.status === "killed" ? handle.status : undefined;
|
|
349
|
+
}
|
|
350
|
+
handle.status = outcome.status;
|
|
351
|
+
if (outcome.status === "killed" && handle.stoppedBy === undefined) {
|
|
352
|
+
handle.stoppedBy = outcome.stoppedBy ?? handle.stopSource ?? "system";
|
|
353
|
+
}
|
|
354
|
+
if (outcome.result !== undefined)
|
|
355
|
+
handle.result = outcome.result;
|
|
356
|
+
if (outcome.status === "killed" && outcome.result !== undefined && outcome.result !== "") {
|
|
357
|
+
handle.resultIsPartial = true;
|
|
358
|
+
}
|
|
359
|
+
if (outcome.error !== undefined && !(outcome.status === "killed" && outcome.error === BG_AGENT_REAP_STOP_ERROR)) {
|
|
360
|
+
handle.error = outcome.error;
|
|
361
|
+
}
|
|
362
|
+
handle.updatedAt = Date.now();
|
|
363
|
+
return outcome.status;
|
|
364
|
+
}
|
|
365
|
+
abortBackgroundAgentsForOwner(access, opts) {
|
|
366
|
+
let aborted = 0;
|
|
367
|
+
for (const handle of this.handles.values()) {
|
|
368
|
+
if (handle.type !== "background_agent" || handle.status !== "running" || !canAccess(handle, access))
|
|
369
|
+
continue;
|
|
370
|
+
if (opts?.skipSessionScoped && handle.sessionScoped)
|
|
371
|
+
continue;
|
|
372
|
+
if (opts?.sessionScopedOnly && !handle.sessionScoped)
|
|
373
|
+
continue;
|
|
374
|
+
this.markStopSource(handle.id, "parent");
|
|
375
|
+
handle.abort.abort();
|
|
376
|
+
aborted++;
|
|
377
|
+
}
|
|
378
|
+
return aborted;
|
|
379
|
+
}
|
|
380
|
+
markStopSourceForOwner(access, source, opts) {
|
|
381
|
+
let marked = 0;
|
|
382
|
+
for (const handle of this.handles.values()) {
|
|
383
|
+
if (handle.type !== "background_agent" && handle.type !== "background_bash" && handle.type !== "monitor")
|
|
384
|
+
continue;
|
|
385
|
+
if (handle.status !== "running" || !canAccess(handle, access))
|
|
386
|
+
continue;
|
|
387
|
+
if (opts?.skipSessionScoped && handle.sessionScoped)
|
|
388
|
+
continue;
|
|
389
|
+
if (handle.type === "monitor" && monitorInTimeoutWindow(handle))
|
|
390
|
+
continue;
|
|
391
|
+
const before = handle.stopSource;
|
|
392
|
+
this.markStopSource(handle.id, source);
|
|
393
|
+
if (before === undefined && handle.stopSource !== undefined)
|
|
394
|
+
marked++;
|
|
395
|
+
}
|
|
396
|
+
return marked;
|
|
397
|
+
}
|
|
398
|
+
async settleKilledForOwner(access, opts) {
|
|
399
|
+
const source = opts?.source ?? "parent";
|
|
400
|
+
const clause = (by) => by === "user" ? "stopped by user" : by === "parent" ? "its parent run ended" : `stopped by ${by}`;
|
|
401
|
+
let settled = 0;
|
|
402
|
+
for (const handle of this.handles.values()) {
|
|
403
|
+
if (handle.type !== "background_bash" && handle.type !== "monitor")
|
|
404
|
+
continue;
|
|
405
|
+
if (handle.status !== "running" || !canAccess(handle, access))
|
|
406
|
+
continue;
|
|
407
|
+
if (opts?.skipSessionScoped && handle.sessionScoped && !(opts?.envDying === true && handle.type === "background_bash"))
|
|
408
|
+
continue;
|
|
409
|
+
if (handle.env.backgroundCapabilities.retainBackgroundProcesses === true && !opts?.envDying)
|
|
410
|
+
continue;
|
|
411
|
+
if (handle.type === "monitor" && monitorInTimeoutWindow(handle) && !opts?.envDying)
|
|
412
|
+
continue;
|
|
413
|
+
this.markStopSource(handle.id, source);
|
|
414
|
+
if (handle.type === "background_bash") {
|
|
415
|
+
if (handle.watcher !== undefined) {
|
|
416
|
+
clearInterval(handle.watcher);
|
|
417
|
+
handle.watcher = undefined;
|
|
418
|
+
}
|
|
419
|
+
const kill = await handle.env.killBackground(handle.shellId);
|
|
420
|
+
const killFailed = !kill.ok && kill.error.code !== "not_found";
|
|
421
|
+
handle.status = "killed";
|
|
422
|
+
handle.stoppedBy = handle.stopSource ?? source;
|
|
423
|
+
handle.updatedAt = Date.now();
|
|
424
|
+
const tail = handle.spool !== undefined ? handle.spool.stdout.slice(-2_000) : "";
|
|
425
|
+
try {
|
|
426
|
+
handle.onTerminal?.({
|
|
427
|
+
task_id: handle.id,
|
|
428
|
+
task_type: "background_bash",
|
|
429
|
+
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
430
|
+
status: "killed",
|
|
431
|
+
stoppedBy: handle.stoppedBy,
|
|
432
|
+
summary: `${(handle.description ?? "background command").slice(0, 200)} — killed before completion (${clause(handle.stoppedBy)})${killFailed ? ` — kill attempt reported ${kill.ok ? "" : kill.error.code}: the process may still be terminating; the environment teardown retries` : ""}`,
|
|
433
|
+
...(tail.length > 0 ? { result: tail } : {}),
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
if (handle.watcher !== undefined) {
|
|
441
|
+
handle.timers.clearInterval(handle.watcher);
|
|
442
|
+
handle.watcher = undefined;
|
|
443
|
+
}
|
|
444
|
+
const kill = await handle.env.killBackground(handle.shellId);
|
|
445
|
+
const killFailed = !kill.ok && kill.error.code !== "not_found";
|
|
446
|
+
handle.status = "killed";
|
|
447
|
+
handle.stoppedBy = handle.stopSource ?? source;
|
|
448
|
+
handle.updatedAt = Date.now();
|
|
449
|
+
const lastLines = handle.lineBuf !== "" ? [handle.lineBuf] : [];
|
|
450
|
+
handle.lineBuf = "";
|
|
451
|
+
try {
|
|
452
|
+
handle.onEvent?.({
|
|
453
|
+
task_id: handle.id,
|
|
454
|
+
task_type: "monitor",
|
|
455
|
+
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
456
|
+
status: "killed",
|
|
457
|
+
stoppedBy: handle.stoppedBy,
|
|
458
|
+
summary: `${(handle.description ?? "monitor").slice(0, 200)} — killed before completion (${clause(handle.stoppedBy)}); watch ended.${killFailed ? ` Kill attempt reported ${kill.ok ? "" : kill.error.code}: the process may still be terminating; the environment teardown retries.` : ""}`,
|
|
459
|
+
...(lastLines.length > 0 ? { lines: lastLines, result: lastLines.join("\n") } : {}),
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
settled++;
|
|
466
|
+
}
|
|
467
|
+
return settled;
|
|
468
|
+
}
|
|
469
|
+
reapSessionBackground(sessionId, scope) {
|
|
470
|
+
const access = { owner: sessionId, ...(scope !== undefined ? { scope } : {}) };
|
|
471
|
+
let reaped = 0;
|
|
472
|
+
for (const handle of this.handles.values()) {
|
|
473
|
+
if (handle.type === "monitor" && handle.status === "running" && handle.sessionScoped && canAccess(handle, access)) {
|
|
474
|
+
this.markStopSource(handle.id, "system");
|
|
475
|
+
if (handle.watcher !== undefined) {
|
|
476
|
+
handle.timers.clearInterval(handle.watcher);
|
|
477
|
+
handle.watcher = undefined;
|
|
478
|
+
}
|
|
479
|
+
if (handle.env.backgroundCapabilities.retainBackgroundProcesses !== true) {
|
|
480
|
+
void handle.env.killBackground(handle.shellId).catch(() => undefined);
|
|
481
|
+
}
|
|
482
|
+
handle.status = "killed";
|
|
483
|
+
handle.stoppedBy = handle.stopSource ?? "system";
|
|
484
|
+
handle.updatedAt = Date.now();
|
|
485
|
+
reaped++;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (handle.type === "background_bash" && handle.status === "running" && handle.sessionScoped && canAccess(handle, access)) {
|
|
489
|
+
this.markStopSource(handle.id, "system");
|
|
490
|
+
if (handle.watcher !== undefined) {
|
|
491
|
+
clearInterval(handle.watcher);
|
|
492
|
+
handle.watcher = undefined;
|
|
493
|
+
}
|
|
494
|
+
if (handle.env.backgroundCapabilities.retainBackgroundProcesses !== true) {
|
|
495
|
+
void handle.env.killBackground(handle.shellId).catch(() => undefined);
|
|
496
|
+
}
|
|
497
|
+
handle.status = "killed";
|
|
498
|
+
handle.stoppedBy = handle.stopSource ?? "system";
|
|
499
|
+
handle.updatedAt = Date.now();
|
|
500
|
+
reaped++;
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (handle.type !== "background_agent" || handle.status !== "running" || !handle.sessionScoped)
|
|
504
|
+
continue;
|
|
505
|
+
if (!canAccess(handle, access))
|
|
506
|
+
continue;
|
|
507
|
+
this.markStopSource(handle.id, "system");
|
|
508
|
+
handle.abort.abort();
|
|
509
|
+
this.settleBackgroundAgent(handle.id, { status: "killed", error: "session released" });
|
|
510
|
+
reaped++;
|
|
511
|
+
}
|
|
512
|
+
for (const hook of this.sessionReapHooks) {
|
|
513
|
+
try {
|
|
514
|
+
hook(sessionId, scope);
|
|
515
|
+
}
|
|
516
|
+
catch {
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return reaped;
|
|
520
|
+
}
|
|
521
|
+
reapAllSessionBackground() {
|
|
522
|
+
const pairs = new Map();
|
|
523
|
+
for (const handle of this.handles.values()) {
|
|
524
|
+
if (handle.status !== "running")
|
|
525
|
+
continue;
|
|
526
|
+
if (!handle.sessionScoped || handle.owner === undefined)
|
|
527
|
+
continue;
|
|
528
|
+
const key = JSON.stringify([handle.owner, handle.scope ?? null]);
|
|
529
|
+
if (!pairs.has(key))
|
|
530
|
+
pairs.set(key, { owner: handle.owner, ...(handle.scope !== undefined ? { scope: handle.scope } : {}) });
|
|
531
|
+
}
|
|
532
|
+
let reaped = 0;
|
|
533
|
+
for (const p of pairs.values())
|
|
534
|
+
reaped += this.reapSessionBackground(p.owner, p.scope);
|
|
535
|
+
return reaped;
|
|
536
|
+
}
|
|
537
|
+
onSessionReap(hook) {
|
|
538
|
+
this.sessionReapHooks.add(hook);
|
|
539
|
+
return () => void this.sessionReapHooks.delete(hook);
|
|
540
|
+
}
|
|
541
|
+
startBashWatcher(id, onTerminal) {
|
|
542
|
+
const handle = this.handles.get(id);
|
|
543
|
+
if (!handle || handle.type !== "background_bash")
|
|
544
|
+
return;
|
|
545
|
+
handle.spool = { stdout: "", stderr: "", rolledChars: 0 };
|
|
546
|
+
const ROLL_CAP = 2 * TASK_OUTPUT_MAX_CHARS;
|
|
547
|
+
const roll = (s) => {
|
|
548
|
+
if (s.length <= ROLL_CAP)
|
|
549
|
+
return s;
|
|
550
|
+
const half = Math.floor(ROLL_CAP / 2);
|
|
551
|
+
handle.spool.rolledChars += s.length - 2 * half;
|
|
552
|
+
return s.slice(0, half) + s.slice(s.length - half);
|
|
553
|
+
};
|
|
554
|
+
let ticking = false;
|
|
555
|
+
const stop = () => {
|
|
556
|
+
if (handle.watcher !== undefined) {
|
|
557
|
+
clearInterval(handle.watcher);
|
|
558
|
+
handle.watcher = undefined;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
const tick = async () => {
|
|
562
|
+
if (ticking)
|
|
563
|
+
return;
|
|
564
|
+
ticking = true;
|
|
565
|
+
try {
|
|
566
|
+
if (this.handles.get(id) !== handle)
|
|
567
|
+
return stop();
|
|
568
|
+
if (handle.status !== "running")
|
|
569
|
+
return stop();
|
|
570
|
+
const r = await handle.env.pollBackground(handle.shellId);
|
|
571
|
+
if (this.handles.get(id) !== handle || handle.status !== "running")
|
|
572
|
+
return stop();
|
|
573
|
+
if (!r.ok)
|
|
574
|
+
return stop();
|
|
575
|
+
const spool = handle.spool;
|
|
576
|
+
spool.stdout = roll(spool.stdout + r.value.stdout);
|
|
577
|
+
spool.stderr = roll(spool.stderr + r.value.stderr);
|
|
578
|
+
handle.status = statusFromBackground(r.value.status, r.value.exitCode);
|
|
579
|
+
if (handle.status === "killed" && handle.stoppedBy === undefined)
|
|
580
|
+
handle.stoppedBy = handle.stopSource ?? "system";
|
|
581
|
+
handle.updatedAt = Date.now();
|
|
582
|
+
if (r.value.status !== "running") {
|
|
583
|
+
spool.exitCode = r.value.exitCode;
|
|
584
|
+
stop();
|
|
585
|
+
const tail = spool.stdout.slice(-2_000);
|
|
586
|
+
onTerminal({
|
|
587
|
+
task_id: id,
|
|
588
|
+
task_type: "background_bash",
|
|
589
|
+
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
590
|
+
status: handle.status === "completed" ? "completed" : handle.status === "killed" ? "killed" : "failed",
|
|
591
|
+
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
592
|
+
summary: r.value.status === "exited"
|
|
593
|
+
? `Background command "${(handle.description ?? "background command").slice(0, 200)}" completed (exit code ${r.value.exitCode})`
|
|
594
|
+
: `${(handle.description ?? "background command").slice(0, 200)} — ${r.value.status}`,
|
|
595
|
+
...(tail.length > 0 ? { result: tail } : {}),
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
catch {
|
|
600
|
+
stop();
|
|
601
|
+
}
|
|
602
|
+
finally {
|
|
603
|
+
ticking = false;
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
handle.watcher = setInterval(() => void tick(), 1_000);
|
|
607
|
+
handle.watcher.unref?.();
|
|
608
|
+
}
|
|
609
|
+
sessionResidentShellIds(sessionId, env) {
|
|
610
|
+
const out = [];
|
|
611
|
+
for (const handle of this.handles.values()) {
|
|
612
|
+
if ((handle.type === "monitor" || handle.type === "background_bash") && handle.status === "running" && handle.sessionScoped === true && handle.owner === sessionId && handle.env === env) {
|
|
613
|
+
out.push(handle.shellId);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return out;
|
|
617
|
+
}
|
|
618
|
+
timeoutResidentShellIds(env) {
|
|
619
|
+
const out = [];
|
|
620
|
+
for (const handle of this.handles.values()) {
|
|
621
|
+
if (handle.type === "monitor" && handle.env === env && monitorInTimeoutWindow(handle)) {
|
|
622
|
+
out.push(handle.shellId);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return out;
|
|
626
|
+
}
|
|
627
|
+
registerMonitor(input) {
|
|
628
|
+
assertOwnership(input, "registerMonitor");
|
|
629
|
+
const id = this.mintTaskId("monitor");
|
|
630
|
+
const now = input.now ?? Date.now();
|
|
631
|
+
const timers = input.timers ?? defaultMonitorTimers;
|
|
632
|
+
const persistent = input.persistent === true;
|
|
633
|
+
const timeoutMs = persistent
|
|
634
|
+
? undefined
|
|
635
|
+
: Math.min(MONITOR_MAX_TIMEOUT_MS, Math.max(1, Math.floor(input.timeoutMs ?? MONITOR_DEFAULT_TIMEOUT_MS)));
|
|
636
|
+
const handle = {
|
|
637
|
+
id,
|
|
638
|
+
type: "monitor",
|
|
639
|
+
status: "running",
|
|
640
|
+
...(input.description !== undefined ? { description: input.description } : {}),
|
|
641
|
+
...(input.owner !== undefined ? { owner: input.owner } : {}),
|
|
642
|
+
...(input.scope !== undefined ? { scope: input.scope } : {}),
|
|
643
|
+
...(input.toolUseId !== undefined ? { toolUseId: input.toolUseId } : {}),
|
|
644
|
+
...(persistent ? { persistent: true } : {}),
|
|
645
|
+
...(input.sessionScoped ? { sessionScoped: true } : {}),
|
|
646
|
+
createdAt: now,
|
|
647
|
+
updatedAt: now,
|
|
648
|
+
env: input.env,
|
|
649
|
+
shellId: input.shellId,
|
|
650
|
+
spool: { stdout: "", stderr: "", rolledChars: 0 },
|
|
651
|
+
lineBuf: "",
|
|
652
|
+
seq: 0,
|
|
653
|
+
batchTimes: [],
|
|
654
|
+
batchWindowMs: Math.max(1, Math.floor(input.batchWindowMs ?? MONITOR_BATCH_WINDOW_MS)),
|
|
655
|
+
maxBatchesPerMinute: Math.max(1, Math.floor(input.maxBatchesPerMinute ?? MONITOR_MAX_BATCHES_PER_MINUTE)),
|
|
656
|
+
...(timeoutMs !== undefined ? { timeoutMs, deadlineAt: timers.now() + timeoutMs } : {}),
|
|
657
|
+
timers,
|
|
658
|
+
...(input.onEvent !== undefined ? { onEvent: input.onEvent } : {}),
|
|
659
|
+
};
|
|
660
|
+
this.handles.set(id, handle);
|
|
661
|
+
this.startMonitorWatcher(id);
|
|
662
|
+
return id;
|
|
663
|
+
}
|
|
664
|
+
startMonitorWatcher(id) {
|
|
665
|
+
const handle = this.handles.get(id);
|
|
666
|
+
if (!handle || handle.type !== "monitor")
|
|
667
|
+
return;
|
|
668
|
+
const timers = handle.timers;
|
|
669
|
+
const ROLL_CAP = 2 * TASK_OUTPUT_MAX_CHARS;
|
|
670
|
+
const roll = (s) => {
|
|
671
|
+
if (s.length <= ROLL_CAP)
|
|
672
|
+
return s;
|
|
673
|
+
const half = Math.floor(ROLL_CAP / 2);
|
|
674
|
+
handle.spool.rolledChars += s.length - 2 * half;
|
|
675
|
+
return s.slice(0, half) + s.slice(s.length - half);
|
|
676
|
+
};
|
|
677
|
+
let ticking = false;
|
|
678
|
+
const stop = () => {
|
|
679
|
+
if (handle.watcher !== undefined) {
|
|
680
|
+
timers.clearInterval(handle.watcher);
|
|
681
|
+
handle.watcher = undefined;
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const emit = (n) => {
|
|
685
|
+
try {
|
|
686
|
+
handle.onEvent?.(n);
|
|
687
|
+
}
|
|
688
|
+
catch {
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
const clipEvent = (s) => s.length <= MONITOR_EVENT_RESULT_CAP ? s : `${s.slice(0, MONITOR_EVENT_RESULT_CAP)}\n…[+${s.length - MONITOR_EVENT_RESULT_CAP} chars truncated]`;
|
|
692
|
+
const pendingFinalLines = (lines) => {
|
|
693
|
+
const out = handle.lineBuf !== "" ? [...lines, handle.lineBuf] : lines;
|
|
694
|
+
handle.lineBuf = "";
|
|
695
|
+
return out;
|
|
696
|
+
};
|
|
697
|
+
const terminal = (status, summary, finalLines) => {
|
|
698
|
+
handle.updatedAt = Date.now();
|
|
699
|
+
stop();
|
|
700
|
+
emit({
|
|
701
|
+
task_id: id,
|
|
702
|
+
task_type: "monitor",
|
|
703
|
+
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
704
|
+
status,
|
|
705
|
+
...(status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
706
|
+
summary: `${(handle.description ?? "monitor").slice(0, 200)} — ${summary}`,
|
|
707
|
+
...(finalLines.length > 0 ? { lines: finalLines, result: clipEvent(finalLines.join("\n")) } : {}),
|
|
708
|
+
});
|
|
709
|
+
};
|
|
710
|
+
const tick = async () => {
|
|
711
|
+
if (ticking)
|
|
712
|
+
return;
|
|
713
|
+
ticking = true;
|
|
714
|
+
try {
|
|
715
|
+
if (this.handles.get(id) !== handle)
|
|
716
|
+
return stop();
|
|
717
|
+
if (handle.status !== "running")
|
|
718
|
+
return stop();
|
|
719
|
+
const r = await handle.env.pollBackground(handle.shellId);
|
|
720
|
+
if (this.handles.get(id) !== handle || handle.status !== "running")
|
|
721
|
+
return stop();
|
|
722
|
+
if (!r.ok) {
|
|
723
|
+
handle.status = "failed";
|
|
724
|
+
return terminal("failed", `monitor lost its process (${r.error.message}); watch ended.`, pendingFinalLines([]));
|
|
725
|
+
}
|
|
726
|
+
const spool = handle.spool;
|
|
727
|
+
spool.stdout = roll(spool.stdout + r.value.stdout);
|
|
728
|
+
spool.stderr = roll(spool.stderr + r.value.stderr);
|
|
729
|
+
handle.lineBuf += r.value.stdout;
|
|
730
|
+
const parts = handle.lineBuf.split(/\r?\n/);
|
|
731
|
+
handle.lineBuf = parts.pop() ?? "";
|
|
732
|
+
const lines = parts.filter((l) => l !== "");
|
|
733
|
+
handle.status = statusFromBackground(r.value.status, r.value.exitCode);
|
|
734
|
+
if (r.value.status !== "running") {
|
|
735
|
+
spool.exitCode = r.value.exitCode;
|
|
736
|
+
if (handle.status === "killed" && handle.stoppedBy === undefined)
|
|
737
|
+
handle.stoppedBy = handle.stopSource ?? "system";
|
|
738
|
+
const label = r.value.status === "exited"
|
|
739
|
+
? `exited(code ${r.value.exitCode}); watch ended.`
|
|
740
|
+
: `${r.value.status}; watch ended.`;
|
|
741
|
+
return terminal(handle.status === "completed" ? "completed" : handle.status === "killed" ? "killed" : "failed", label, pendingFinalLines(lines));
|
|
742
|
+
}
|
|
743
|
+
const now = timers.now();
|
|
744
|
+
if (handle.deadlineAt !== undefined && now >= handle.deadlineAt) {
|
|
745
|
+
this.markStopSource(id, "timeout");
|
|
746
|
+
const k = await handle.env.killBackground(handle.shellId);
|
|
747
|
+
if (this.handles.get(id) !== handle || handle.status !== "running")
|
|
748
|
+
return stop();
|
|
749
|
+
if (!k.ok && k.error.code !== "not_found") {
|
|
750
|
+
handle.status = "failed";
|
|
751
|
+
return terminal("failed", `timed out after ${handle.timeoutMs}ms, but the kill failed (${k.error.message}); the process may still be running. Watch ended.`, pendingFinalLines(lines));
|
|
752
|
+
}
|
|
753
|
+
handle.status = "killed";
|
|
754
|
+
handle.stoppedBy = handle.stopSource ?? "timeout";
|
|
755
|
+
return terminal("killed", `timed out after ${handle.timeoutMs}ms; the process was killed and the watch ended.`, pendingFinalLines(lines));
|
|
756
|
+
}
|
|
757
|
+
if (lines.length === 0) {
|
|
758
|
+
if (r.value.stdout.length > 0 || r.value.stderr.length > 0)
|
|
759
|
+
handle.updatedAt = Date.now();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
const cutoff = now - 60_000;
|
|
763
|
+
handle.batchTimes = handle.batchTimes.filter((t) => t > cutoff);
|
|
764
|
+
handle.batchTimes.push(now);
|
|
765
|
+
if (handle.batchTimes.length > handle.maxBatchesPerMinute) {
|
|
766
|
+
this.markStopSource(id, "system");
|
|
767
|
+
const k = await handle.env.killBackground(handle.shellId);
|
|
768
|
+
if (this.handles.get(id) !== handle || handle.status !== "running")
|
|
769
|
+
return stop();
|
|
770
|
+
if (!k.ok && k.error.code !== "not_found") {
|
|
771
|
+
handle.status = "failed";
|
|
772
|
+
return terminal("failed", `auto-stop triggered (more than ${handle.maxBatchesPerMinute} notification batches within a minute), but the kill failed (${k.error.message}); the process may still be running. Watch ended.`, pendingFinalLines(lines));
|
|
773
|
+
}
|
|
774
|
+
handle.status = "killed";
|
|
775
|
+
handle.stoppedBy = handle.stopSource ?? "system";
|
|
776
|
+
return terminal("killed", `auto-stopped: it produced too many events (more than ${handle.maxBatchesPerMinute} notification batches within a minute). ` +
|
|
777
|
+
`The process was killed; its full output remains readable via TaskOutput. Restart it with a quieter command (filter its output) if you still need the watch.`, pendingFinalLines(lines));
|
|
778
|
+
}
|
|
779
|
+
handle.seq += 1;
|
|
780
|
+
handle.updatedAt = Date.now();
|
|
781
|
+
emit({
|
|
782
|
+
task_id: id,
|
|
783
|
+
task_type: "monitor",
|
|
784
|
+
...(handle.toolUseId !== undefined ? { toolUseId: handle.toolUseId } : {}),
|
|
785
|
+
status: "event",
|
|
786
|
+
seq: handle.seq,
|
|
787
|
+
lines,
|
|
788
|
+
summary: `${(handle.description ?? "monitor").slice(0, 200)} — ${lines.length} new output line(s)`,
|
|
789
|
+
result: clipEvent(lines.join("\n")),
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
catch {
|
|
793
|
+
stop();
|
|
794
|
+
}
|
|
795
|
+
finally {
|
|
796
|
+
ticking = false;
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
handle.watcher = timers.setInterval(tick, handle.batchWindowMs);
|
|
800
|
+
}
|
|
801
|
+
registerWorkflow(input) {
|
|
802
|
+
assertOwnership(input, "registerWorkflow");
|
|
803
|
+
const id = input.runId;
|
|
804
|
+
if (this.handles.has(id))
|
|
805
|
+
throw new Error(`TaskRegistry: task id already registered: ${id}`);
|
|
806
|
+
const now = input.now ?? Date.now();
|
|
807
|
+
const handle = {
|
|
808
|
+
id,
|
|
809
|
+
type: "workflow",
|
|
810
|
+
status: "running",
|
|
811
|
+
...(input.description !== undefined ? { description: input.description } : {}),
|
|
812
|
+
...(input.owner !== undefined ? { owner: input.owner } : {}),
|
|
813
|
+
...(input.scope !== undefined ? { scope: input.scope } : {}),
|
|
814
|
+
...(input.toolUseId !== undefined ? { toolUseId: input.toolUseId } : {}),
|
|
815
|
+
createdAt: now,
|
|
816
|
+
updatedAt: now,
|
|
817
|
+
runId: id,
|
|
818
|
+
handle: input.handle,
|
|
819
|
+
...(input.store !== undefined ? { store: input.store } : {}),
|
|
820
|
+
...(input.onServedTerminal !== undefined ? { onServedTerminal: input.onServedTerminal } : {}),
|
|
821
|
+
};
|
|
822
|
+
this.handles.set(id, handle);
|
|
823
|
+
void input.handle.done.then((res) => {
|
|
824
|
+
handle.status = "completed";
|
|
825
|
+
const run = res?.run;
|
|
826
|
+
const r = run?.resultFull ?? run?.result;
|
|
827
|
+
if (typeof r === "string")
|
|
828
|
+
handle.result = r;
|
|
829
|
+
handle.updatedAt = Date.now();
|
|
830
|
+
}, (err) => {
|
|
831
|
+
if (handle.status !== "cancelled")
|
|
832
|
+
handle.status = "failed";
|
|
833
|
+
handle.error = boundedRedactedSummary(err instanceof Error ? err.message : String(err), 500);
|
|
834
|
+
handle.updatedAt = Date.now();
|
|
835
|
+
});
|
|
836
|
+
return id;
|
|
837
|
+
}
|
|
838
|
+
async pollTask(id, access, opts = {}) {
|
|
839
|
+
const taskId = id.trim();
|
|
840
|
+
const deadline = opts.block ? blockDeadline(opts.timeoutMs, Date.now()) : undefined;
|
|
841
|
+
const handle = this.resolveInternal(taskId, access);
|
|
842
|
+
if (handle) {
|
|
843
|
+
if (handle.type === "background_bash")
|
|
844
|
+
return this.pollBackgroundBash(handle, taskId, opts.filter, deadline, opts.signal);
|
|
845
|
+
if (handle.type === "background_agent")
|
|
846
|
+
return this.pollBackgroundAgent(handle, deadline, opts.signal);
|
|
847
|
+
if (handle.type === "monitor")
|
|
848
|
+
return this.pollMonitor(handle, opts.filter, deadline, opts.signal);
|
|
849
|
+
return this.pollWorkflow(handle, access, deadline, opts.signal);
|
|
850
|
+
}
|
|
851
|
+
if (opts.workflowStore) {
|
|
852
|
+
for (;;) {
|
|
853
|
+
const run = await opts.workflowStore.get(taskId);
|
|
854
|
+
if (!run || !canAccessWorkflowRun(run, access))
|
|
855
|
+
break;
|
|
856
|
+
if (run.status !== "running" || deadline === undefined || Date.now() >= deadline || opts.signal?.aborted) {
|
|
857
|
+
const out = formatWorkflowRun(run);
|
|
858
|
+
if (run.status === "running" && deadline !== undefined && Date.now() >= deadline)
|
|
859
|
+
out.details.retrieval_status = "timeout";
|
|
860
|
+
return out;
|
|
861
|
+
}
|
|
862
|
+
await sleepPollStep(deadline, opts.signal);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return noTask(taskId);
|
|
866
|
+
}
|
|
867
|
+
async stopTask(id, access, opts = {}) {
|
|
868
|
+
const taskId = id.trim();
|
|
869
|
+
const handle = this.resolveInternal(taskId, access);
|
|
870
|
+
if (handle) {
|
|
871
|
+
if (handle.type === "background_bash")
|
|
872
|
+
return this.stopBackgroundBash(handle);
|
|
873
|
+
if (handle.type === "background_agent")
|
|
874
|
+
return this.stopBackgroundAgent(handle);
|
|
875
|
+
if (handle.type === "monitor")
|
|
876
|
+
return this.stopMonitor(handle);
|
|
877
|
+
return this.stopWorkflow(handle);
|
|
878
|
+
}
|
|
879
|
+
if (opts.workflowStore) {
|
|
880
|
+
const run = await opts.workflowStore.get(taskId);
|
|
881
|
+
if (run && canAccessWorkflowRun(run, access)) {
|
|
882
|
+
return {
|
|
883
|
+
content: JSON.stringify({
|
|
884
|
+
task_id: taskId,
|
|
885
|
+
runId: taskId,
|
|
886
|
+
status: run.status,
|
|
887
|
+
stopped: false,
|
|
888
|
+
error: "workflow task is not attached to this process; cannot stop it here",
|
|
889
|
+
}),
|
|
890
|
+
details: {
|
|
891
|
+
task_id: taskId,
|
|
892
|
+
type: "workflow",
|
|
893
|
+
status: run.status,
|
|
894
|
+
retrieval_status: "success",
|
|
895
|
+
error: "not_local",
|
|
896
|
+
},
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
const byName = this.resolveBackgroundAgentByName(taskId, access);
|
|
901
|
+
if (byName.status === "found")
|
|
902
|
+
return this.stopBackgroundAgent(byName.handle);
|
|
903
|
+
if (byName.status === "ambiguous") {
|
|
904
|
+
return {
|
|
905
|
+
content: byName.message,
|
|
906
|
+
details: { task_id: taskId, retrieval_status: "not_ready", error: "ambiguous" },
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
return noTaskForStop(taskId, {
|
|
910
|
+
...(byName.suggestion !== undefined ? { suggestion: byName.suggestion } : {}),
|
|
911
|
+
runningAgents: this.runningBackgroundAgentLabels(access),
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
resolveBackgroundAgentByName(name, access) {
|
|
915
|
+
const key = normalizeAgentName(name);
|
|
916
|
+
if (key === "")
|
|
917
|
+
return { status: "not_found" };
|
|
918
|
+
const exact = [];
|
|
919
|
+
for (const h of this.handles.values()) {
|
|
920
|
+
if (h.type !== "background_agent" || !canAccess(h, access))
|
|
921
|
+
continue;
|
|
922
|
+
if (h.description === name)
|
|
923
|
+
exact.push(h);
|
|
924
|
+
}
|
|
925
|
+
const exactRunning = exact.filter((h) => h.status === "running");
|
|
926
|
+
const exactPool = exactRunning.length > 0 ? exactRunning : exact;
|
|
927
|
+
if (exactPool.length === 1)
|
|
928
|
+
return { status: "found", handle: exactPool[0] };
|
|
929
|
+
if (exactPool.length > 1) {
|
|
930
|
+
return {
|
|
931
|
+
status: "ambiguous",
|
|
932
|
+
message: `Multiple background agents match "${name}": ${exactPool.map((h) => (h.description ? `${h.id} (${h.description})` : h.id)).join(", ")}. Use the task ID.`,
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
const matches = [];
|
|
936
|
+
for (const h of this.handles.values()) {
|
|
937
|
+
if (h.type !== "background_agent" || !canAccess(h, access))
|
|
938
|
+
continue;
|
|
939
|
+
if (h.description !== undefined && normalizeAgentName(h.description) === key)
|
|
940
|
+
matches.push(h);
|
|
941
|
+
}
|
|
942
|
+
const running = matches.filter((h) => h.status === "running");
|
|
943
|
+
const pool = running.length > 0 ? running : matches;
|
|
944
|
+
if (pool.length === 1)
|
|
945
|
+
return { status: "found", handle: pool[0] };
|
|
946
|
+
if (pool.length > 1) {
|
|
947
|
+
return {
|
|
948
|
+
status: "ambiguous",
|
|
949
|
+
message: `Multiple background agents match "${name}": ${pool.map((h) => (h.description ? `${h.id} (${h.description})` : h.id)).join(", ")}. Use the task ID.`,
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
const byKey = new Map();
|
|
953
|
+
for (const h of this.handles.values()) {
|
|
954
|
+
if (h.type !== "background_agent" || h.status !== "running" || !canAccess(h, access) || h.description === undefined)
|
|
955
|
+
continue;
|
|
956
|
+
const k = normalizeAgentName(h.description);
|
|
957
|
+
if (k !== "" && !byKey.has(k))
|
|
958
|
+
byKey.set(k, h.description);
|
|
959
|
+
}
|
|
960
|
+
const closest = closestName(key, byKey.keys());
|
|
961
|
+
return { status: "not_found", ...(closest !== undefined ? { suggestion: byKey.get(closest) } : {}) };
|
|
962
|
+
}
|
|
963
|
+
runningBackgroundAgentLabels(access) {
|
|
964
|
+
const out = [];
|
|
965
|
+
for (const h of this.handles.values()) {
|
|
966
|
+
if (h.type !== "background_agent" || h.status !== "running" || !canAccess(h, access))
|
|
967
|
+
continue;
|
|
968
|
+
out.push(h.description ? `${h.id} (${h.description})` : h.id);
|
|
969
|
+
}
|
|
970
|
+
return out;
|
|
971
|
+
}
|
|
972
|
+
lastGcAt = 0;
|
|
973
|
+
list(access, opts = {}) {
|
|
974
|
+
const limit = Math.min(500, Math.max(1, Math.floor(opts.limit ?? 50)));
|
|
975
|
+
const out = [];
|
|
976
|
+
for (const h of this.handles.values()) {
|
|
977
|
+
if (!canAccess(h, access))
|
|
978
|
+
continue;
|
|
979
|
+
out.push({
|
|
980
|
+
task_id: h.id,
|
|
981
|
+
type: h.type,
|
|
982
|
+
status: h.status,
|
|
983
|
+
sessionScoped: h.sessionScoped === true,
|
|
984
|
+
...(h.description !== undefined ? { description: h.description } : {}),
|
|
985
|
+
...(h.toolUseId !== undefined ? { toolUseId: h.toolUseId } : {}),
|
|
986
|
+
createdAt: h.createdAt,
|
|
987
|
+
updatedAt: h.updatedAt,
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
out.sort((a, b) => b.createdAt - a.createdAt);
|
|
991
|
+
return out.slice(0, limit);
|
|
992
|
+
}
|
|
993
|
+
maybeGc(now = Date.now()) {
|
|
994
|
+
if (now - this.lastGcAt < 60_000)
|
|
995
|
+
return 0;
|
|
996
|
+
this.lastGcAt = now;
|
|
997
|
+
return this.gc(now);
|
|
998
|
+
}
|
|
999
|
+
gc(now = Date.now(), terminalTtlMs = 60 * 60 * 1000) {
|
|
1000
|
+
let deleted = 0;
|
|
1001
|
+
for (const [id, handle] of this.handles) {
|
|
1002
|
+
if (handle.status === "running" || handle.status === "pending")
|
|
1003
|
+
continue;
|
|
1004
|
+
if (now - handle.updatedAt < terminalTtlMs)
|
|
1005
|
+
continue;
|
|
1006
|
+
this.handles.delete(id);
|
|
1007
|
+
if (handle.type === "background_bash") {
|
|
1008
|
+
this.legacyToTaskId.delete(String(handle.shellId));
|
|
1009
|
+
if (handle.watcher !== undefined)
|
|
1010
|
+
clearInterval(handle.watcher);
|
|
1011
|
+
}
|
|
1012
|
+
if (handle.type === "monitor" && handle.watcher !== undefined) {
|
|
1013
|
+
handle.timers.clearInterval(handle.watcher);
|
|
1014
|
+
handle.watcher = undefined;
|
|
1015
|
+
}
|
|
1016
|
+
deleted++;
|
|
1017
|
+
}
|
|
1018
|
+
return deleted;
|
|
1019
|
+
}
|
|
1020
|
+
clearBackgroundForOwner(access) {
|
|
1021
|
+
let deleted = 0;
|
|
1022
|
+
for (const [id, handle] of this.handles) {
|
|
1023
|
+
if (handle.type === "monitor" && !handle.sessionScoped && canAccess(handle, access)) {
|
|
1024
|
+
if (monitorInTimeoutWindow(handle))
|
|
1025
|
+
continue;
|
|
1026
|
+
this.handles.delete(id);
|
|
1027
|
+
if (handle.watcher !== undefined) {
|
|
1028
|
+
handle.timers.clearInterval(handle.watcher);
|
|
1029
|
+
handle.watcher = undefined;
|
|
1030
|
+
}
|
|
1031
|
+
deleted++;
|
|
1032
|
+
continue;
|
|
1033
|
+
}
|
|
1034
|
+
if (handle.type !== "background_bash" || !canAccess(handle, access))
|
|
1035
|
+
continue;
|
|
1036
|
+
if (handle.sessionScoped)
|
|
1037
|
+
continue;
|
|
1038
|
+
this.handles.delete(id);
|
|
1039
|
+
this.legacyToTaskId.delete(String(handle.shellId));
|
|
1040
|
+
if (handle.watcher !== undefined)
|
|
1041
|
+
clearInterval(handle.watcher);
|
|
1042
|
+
deleted++;
|
|
1043
|
+
}
|
|
1044
|
+
return deleted;
|
|
1045
|
+
}
|
|
1046
|
+
resolveInternal(id, access) {
|
|
1047
|
+
const taskId = this.handles.has(id) ? id : this.legacyToTaskId.get(id);
|
|
1048
|
+
if (!taskId)
|
|
1049
|
+
return undefined;
|
|
1050
|
+
const handle = this.handles.get(taskId);
|
|
1051
|
+
if (!handle || !canAccess(handle, access))
|
|
1052
|
+
return undefined;
|
|
1053
|
+
return handle;
|
|
1054
|
+
}
|
|
1055
|
+
async pollBackgroundBash(handle, requestedId, filter, deadline, signal) {
|
|
1056
|
+
let rx;
|
|
1057
|
+
if (filter !== undefined) {
|
|
1058
|
+
try {
|
|
1059
|
+
rx = new RegExp(filter);
|
|
1060
|
+
}
|
|
1061
|
+
catch {
|
|
1062
|
+
return {
|
|
1063
|
+
content: `Error (TaskOutput): invalid filter regex: ${filter}`,
|
|
1064
|
+
details: { task_id: handle.id, type: "background_bash", status: handle.status, retrieval_status: "not_ready" },
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if (!hasBackgroundShell(handle.env))
|
|
1069
|
+
return noTask(requestedId);
|
|
1070
|
+
if (handle.spool !== undefined) {
|
|
1071
|
+
while (handle.status === "running" && deadline !== undefined && Date.now() < deadline && !signal?.aborted) {
|
|
1072
|
+
await sleepPollStep(deadline, signal);
|
|
1073
|
+
}
|
|
1074
|
+
const spool = handle.spool;
|
|
1075
|
+
const shape = (text) => clipTaskOutput(rx ? text.split(/\r?\n/).filter((l) => rx.test(l)).join("\n") : text, handle.outputFile);
|
|
1076
|
+
const running = handle.status === "running";
|
|
1077
|
+
const retrieval = running && deadline !== undefined && Date.now() >= deadline ? "timeout" : "success";
|
|
1078
|
+
const displayStatus = spool.exitCode !== undefined ? `exited(code ${spool.exitCode})` : running ? "running" : handle.status;
|
|
1079
|
+
const rolledNote = spool.rolledChars > 0 ? `[!] ${spool.rolledChars} earlier char(s) dropped from the spool (memory bound)\n` : "";
|
|
1080
|
+
const body = `status: ${displayStatus}\n${rolledNote}--- stdout (full, re-readable) ---\n${shape(spool.stdout) || "(none)"}\n` +
|
|
1081
|
+
`--- stderr ---\n${shape(spool.stderr) || "(none)"}`;
|
|
1082
|
+
return {
|
|
1083
|
+
content: delimitUntrusted(`TaskOutput ${handle.id}`, body),
|
|
1084
|
+
details: {
|
|
1085
|
+
task_id: handle.id,
|
|
1086
|
+
type: "background_bash",
|
|
1087
|
+
status: handle.status,
|
|
1088
|
+
retrieval_status: retrieval,
|
|
1089
|
+
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
1090
|
+
details: { status: running ? "running" : handle.status, exitCode: spool.exitCode },
|
|
1091
|
+
},
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
const ROLL_CAP = 2 * TASK_OUTPUT_MAX_CHARS;
|
|
1095
|
+
let rolledChars = 0;
|
|
1096
|
+
const roll = (s) => {
|
|
1097
|
+
if (s.length <= ROLL_CAP)
|
|
1098
|
+
return s;
|
|
1099
|
+
const half = Math.floor(ROLL_CAP / 2);
|
|
1100
|
+
rolledChars += s.length - 2 * half;
|
|
1101
|
+
return s.slice(0, half) + s.slice(s.length - half);
|
|
1102
|
+
};
|
|
1103
|
+
let stdout = "";
|
|
1104
|
+
let stderr = "";
|
|
1105
|
+
let dropped = 0;
|
|
1106
|
+
for (;;) {
|
|
1107
|
+
const r = await handle.env.pollBackground(handle.shellId);
|
|
1108
|
+
if (!r.ok) {
|
|
1109
|
+
if (r.error.code === "not_found")
|
|
1110
|
+
return noTask(requestedId);
|
|
1111
|
+
const retrieval_status = r.error.code === "timeout" ? "timeout" : "not_ready";
|
|
1112
|
+
const salvaged = stdout.length > 0 || stderr.length > 0
|
|
1113
|
+
? `\n--- output accumulated before the error ---\n${clipTaskOutput(stdout, handle.outputFile)}${stderr ? `\n--- stderr ---\n${clipTaskOutput(stderr, handle.outputFile)}` : ""}`
|
|
1114
|
+
: "";
|
|
1115
|
+
return {
|
|
1116
|
+
content: `Error (TaskOutput): ${r.error.message}${salvaged}`,
|
|
1117
|
+
details: { task_id: handle.id, type: "background_bash", status: handle.status, retrieval_status, error: r.error.code },
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
stdout = roll(stdout + r.value.stdout);
|
|
1121
|
+
stderr = roll(stderr + r.value.stderr);
|
|
1122
|
+
dropped += r.value.bytesDroppedBeforeCursor ?? 0;
|
|
1123
|
+
handle.status = statusFromBackground(r.value.status, r.value.exitCode);
|
|
1124
|
+
if (handle.status === "killed" && handle.stoppedBy === undefined)
|
|
1125
|
+
handle.stoppedBy = handle.stopSource ?? "system";
|
|
1126
|
+
handle.updatedAt = Date.now();
|
|
1127
|
+
const running = r.value.status === "running";
|
|
1128
|
+
if (!running || deadline === undefined || Date.now() >= deadline || signal?.aborted) {
|
|
1129
|
+
const retrieval = running && deadline !== undefined && Date.now() >= deadline ? "timeout" : "success";
|
|
1130
|
+
const shape = (text) => clipTaskOutput(rx ? text.split(/\r?\n/).filter((l) => rx.test(l)).join("\n") : text, handle.outputFile);
|
|
1131
|
+
const displayStatus = r.value.status === "exited" ? `exited(code ${r.value.exitCode})` : r.value.status;
|
|
1132
|
+
const droppedNote = (dropped > 0 ? `[!] ${dropped} earlier byte(s) permanently dropped before this window (8MB buffer evicted)\n` : "") +
|
|
1133
|
+
(rolledChars > 0 ? `[!] ${rolledChars} accumulated char(s) dropped from the middle during the blocked wait (memory bound)\n` : "");
|
|
1134
|
+
const body = `status: ${displayStatus}\n${droppedNote}--- new stdout ---\n${shape(stdout) || "(none)"}\n` +
|
|
1135
|
+
`--- new stderr ---\n${shape(stderr) || "(none)"}`;
|
|
1136
|
+
return {
|
|
1137
|
+
content: delimitUntrusted(`TaskOutput ${handle.id}`, body),
|
|
1138
|
+
details: {
|
|
1139
|
+
task_id: handle.id,
|
|
1140
|
+
type: "background_bash",
|
|
1141
|
+
status: handle.status,
|
|
1142
|
+
retrieval_status: retrieval,
|
|
1143
|
+
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
1144
|
+
details: { status: r.value.status, exitCode: r.value.exitCode, bytesDroppedBeforeCursor: dropped },
|
|
1145
|
+
},
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
await sleepPollStep(deadline, signal);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
fireServedTerminal(handle) {
|
|
1152
|
+
const cb = handle.onServedTerminal;
|
|
1153
|
+
if (!cb)
|
|
1154
|
+
return;
|
|
1155
|
+
handle.onServedTerminal = undefined;
|
|
1156
|
+
try {
|
|
1157
|
+
cb();
|
|
1158
|
+
}
|
|
1159
|
+
catch {
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
async pollWorkflow(handle, access, deadline, signal) {
|
|
1163
|
+
const store = handle.store;
|
|
1164
|
+
if (store) {
|
|
1165
|
+
for (;;) {
|
|
1166
|
+
const run = await store.get(handle.runId);
|
|
1167
|
+
if (!run || !canAccessWorkflowRun(run, access))
|
|
1168
|
+
break;
|
|
1169
|
+
if (run.status !== "running" || deadline === undefined || Date.now() >= deadline || signal?.aborted) {
|
|
1170
|
+
const out = formatWorkflowRun(run);
|
|
1171
|
+
if (run.status === "running" && deadline !== undefined && Date.now() >= deadline)
|
|
1172
|
+
out.details.retrieval_status = "timeout";
|
|
1173
|
+
else if (run.status !== "running")
|
|
1174
|
+
this.fireServedTerminal(handle);
|
|
1175
|
+
return out;
|
|
1176
|
+
}
|
|
1177
|
+
await sleepPollStep(deadline, signal);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
while (handle.status === "running" && deadline !== undefined && Date.now() < deadline && !signal?.aborted) {
|
|
1181
|
+
await sleepPollStep(deadline, signal);
|
|
1182
|
+
}
|
|
1183
|
+
if (handle.status !== "running")
|
|
1184
|
+
this.fireServedTerminal(handle);
|
|
1185
|
+
return {
|
|
1186
|
+
content: JSON.stringify({
|
|
1187
|
+
task_id: handle.id,
|
|
1188
|
+
runId: handle.id,
|
|
1189
|
+
type: "workflow",
|
|
1190
|
+
status: handle.status,
|
|
1191
|
+
...(handle.status === "completed" && handle.result !== undefined
|
|
1192
|
+
? { result: delimitUntrusted("workflow result", handle.result) }
|
|
1193
|
+
: {}),
|
|
1194
|
+
...(handle.status === "failed" && handle.error !== undefined
|
|
1195
|
+
? { error: delimitUntrusted("workflow error", handle.error) }
|
|
1196
|
+
: {}),
|
|
1197
|
+
note: handle.status === "running"
|
|
1198
|
+
? "still running — poll again shortly."
|
|
1199
|
+
: handle.status === "completed"
|
|
1200
|
+
? handle.result !== undefined
|
|
1201
|
+
? "completed — `result` above is the workflow's return value."
|
|
1202
|
+
: "completed — its result was delivered on the completion notification."
|
|
1203
|
+
: handle.status === "failed" && handle.error !== undefined
|
|
1204
|
+
? "failed — see error."
|
|
1205
|
+
: "workflow reached a terminal state.",
|
|
1206
|
+
}),
|
|
1207
|
+
details: {
|
|
1208
|
+
task_id: handle.id,
|
|
1209
|
+
type: "workflow",
|
|
1210
|
+
status: handle.status,
|
|
1211
|
+
retrieval_status: handle.status === "running" && deadline !== undefined && Date.now() >= deadline ? "timeout" : "success",
|
|
1212
|
+
},
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
async stopBackgroundBash(handle) {
|
|
1216
|
+
if (handle.watcher !== undefined) {
|
|
1217
|
+
clearInterval(handle.watcher);
|
|
1218
|
+
handle.watcher = undefined;
|
|
1219
|
+
}
|
|
1220
|
+
this.markStopSource(handle.id, "parent");
|
|
1221
|
+
const r = await handle.env.killBackground(handle.shellId);
|
|
1222
|
+
if (!r.ok) {
|
|
1223
|
+
if (r.error.code === "not_found")
|
|
1224
|
+
return noTask(handle.id);
|
|
1225
|
+
const retrieval_status = r.error.code === "timeout" ? "timeout" : "not_ready";
|
|
1226
|
+
return {
|
|
1227
|
+
content: `Error (TaskStop): ${r.error.message}`,
|
|
1228
|
+
details: { task_id: handle.id, type: "background_bash", status: handle.status, retrieval_status, error: r.error.code },
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
if (handle.stoppedBy === undefined)
|
|
1232
|
+
handle.stoppedBy = handle.stopSource ?? "parent";
|
|
1233
|
+
handle.status = "killed";
|
|
1234
|
+
handle.updatedAt = Date.now();
|
|
1235
|
+
return {
|
|
1236
|
+
content: `Terminated ${handle.id}.`,
|
|
1237
|
+
details: { task_id: handle.id, type: "background_bash", status: "killed", retrieval_status: "success", stoppedBy: handle.stoppedBy },
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
async pollMonitor(handle, filter, deadline, signal) {
|
|
1241
|
+
let rx;
|
|
1242
|
+
if (filter !== undefined) {
|
|
1243
|
+
try {
|
|
1244
|
+
rx = new RegExp(filter);
|
|
1245
|
+
}
|
|
1246
|
+
catch {
|
|
1247
|
+
return {
|
|
1248
|
+
content: `Error (TaskOutput): invalid filter regex: ${filter}`,
|
|
1249
|
+
details: { task_id: handle.id, type: "monitor", status: handle.status, retrieval_status: "not_ready" },
|
|
1250
|
+
};
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
while (handle.status === "running" && deadline !== undefined && Date.now() < deadline && !signal?.aborted) {
|
|
1254
|
+
await sleepPollStep(deadline, signal);
|
|
1255
|
+
}
|
|
1256
|
+
const spool = handle.spool;
|
|
1257
|
+
const shape = (text) => clipTaskOutput(rx ? text.split(/\r?\n/).filter((l) => rx.test(l)).join("\n") : text, handle.outputFile);
|
|
1258
|
+
const running = handle.status === "running";
|
|
1259
|
+
const retrieval = running && deadline !== undefined && Date.now() >= deadline ? "timeout" : "success";
|
|
1260
|
+
const displayStatus = spool.exitCode !== undefined ? `exited(code ${spool.exitCode})` : running ? "running" : handle.status;
|
|
1261
|
+
const rolledNote = spool.rolledChars > 0 ? `[!] ${spool.rolledChars} earlier char(s) dropped from the spool (memory bound)\n` : "";
|
|
1262
|
+
const body = `status: ${displayStatus}\n${rolledNote}--- stdout (full, re-readable) ---\n${shape(spool.stdout) || "(none)"}\n` +
|
|
1263
|
+
`--- stderr ---\n${shape(spool.stderr) || "(none)"}`;
|
|
1264
|
+
return {
|
|
1265
|
+
content: delimitUntrusted(`TaskOutput ${handle.id}`, body),
|
|
1266
|
+
details: {
|
|
1267
|
+
task_id: handle.id,
|
|
1268
|
+
type: "monitor",
|
|
1269
|
+
status: handle.status,
|
|
1270
|
+
retrieval_status: retrieval,
|
|
1271
|
+
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
1272
|
+
details: { status: running ? "running" : handle.status, exitCode: spool.exitCode },
|
|
1273
|
+
},
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
async stopMonitor(handle) {
|
|
1277
|
+
if (handle.watcher !== undefined) {
|
|
1278
|
+
handle.timers.clearInterval(handle.watcher);
|
|
1279
|
+
handle.watcher = undefined;
|
|
1280
|
+
}
|
|
1281
|
+
this.markStopSource(handle.id, "parent");
|
|
1282
|
+
const r = await handle.env.killBackground(handle.shellId);
|
|
1283
|
+
if (!r.ok) {
|
|
1284
|
+
if (r.error.code === "not_found")
|
|
1285
|
+
return noTask(handle.id);
|
|
1286
|
+
const retrieval_status = r.error.code === "timeout" ? "timeout" : "not_ready";
|
|
1287
|
+
return {
|
|
1288
|
+
content: `Error (TaskStop): ${r.error.message}`,
|
|
1289
|
+
details: { task_id: handle.id, type: "monitor", status: handle.status, retrieval_status, error: r.error.code },
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
if (handle.status === "running") {
|
|
1293
|
+
if (handle.stoppedBy === undefined)
|
|
1294
|
+
handle.stoppedBy = handle.stopSource ?? "parent";
|
|
1295
|
+
handle.status = "killed";
|
|
1296
|
+
handle.updatedAt = Date.now();
|
|
1297
|
+
}
|
|
1298
|
+
return {
|
|
1299
|
+
content: `Terminated ${handle.id}.`,
|
|
1300
|
+
details: {
|
|
1301
|
+
task_id: handle.id,
|
|
1302
|
+
type: "monitor",
|
|
1303
|
+
status: handle.status,
|
|
1304
|
+
retrieval_status: "success",
|
|
1305
|
+
...(handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
1306
|
+
},
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
async pollBackgroundAgent(handle, deadline, signal) {
|
|
1310
|
+
while (handle.status === "running" && deadline !== undefined && Date.now() < deadline && !signal?.aborted) {
|
|
1311
|
+
await sleepPollStep(deadline, signal);
|
|
1312
|
+
}
|
|
1313
|
+
const running = handle.status === "running";
|
|
1314
|
+
const retrieval = running && deadline !== undefined && Date.now() >= deadline ? "timeout" : "success";
|
|
1315
|
+
const body = running
|
|
1316
|
+
? `status: running
|
|
1317
|
+
The agent is still working — you will be notified when it completes.`
|
|
1318
|
+
: `status: ${handle.status}
|
|
1319
|
+
${handle.error ? `error: ${handle.error}
|
|
1320
|
+
` : ""}${handle.result ? `--- result${handle.resultIsPartial ? " (partial — produced before the task was stopped)" : ""} ---
|
|
1321
|
+
${clipTaskOutput(handle.result, handle.outputFile)}` : "(no result text)"}`;
|
|
1322
|
+
return {
|
|
1323
|
+
content: delimitUntrusted(`TaskOutput ${handle.id}`, body),
|
|
1324
|
+
details: {
|
|
1325
|
+
task_id: handle.id,
|
|
1326
|
+
type: "background_agent",
|
|
1327
|
+
status: handle.status,
|
|
1328
|
+
retrieval_status: retrieval,
|
|
1329
|
+
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
1330
|
+
...(handle.resultIsPartial ? { partial_result: true } : {}),
|
|
1331
|
+
},
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
async stopBackgroundAgent(handle) {
|
|
1335
|
+
if (handle.status === "running") {
|
|
1336
|
+
this.markStopSource(handle.id, "parent");
|
|
1337
|
+
handle.abort.abort();
|
|
1338
|
+
handle.status = "killed";
|
|
1339
|
+
handle.stoppedBy = handle.stopSource ?? "parent";
|
|
1340
|
+
handle.updatedAt = Date.now();
|
|
1341
|
+
}
|
|
1342
|
+
return {
|
|
1343
|
+
content: `Terminated ${handle.id}.`,
|
|
1344
|
+
details: {
|
|
1345
|
+
task_id: handle.id,
|
|
1346
|
+
type: "background_agent",
|
|
1347
|
+
status: handle.status,
|
|
1348
|
+
retrieval_status: "success",
|
|
1349
|
+
...(handle.status === "killed" && handle.stoppedBy !== undefined ? { stoppedBy: handle.stoppedBy } : {}),
|
|
1350
|
+
},
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
async stopWorkflow(handle) {
|
|
1354
|
+
if (handle.status !== "running") {
|
|
1355
|
+
return {
|
|
1356
|
+
content: JSON.stringify({
|
|
1357
|
+
task_id: handle.id,
|
|
1358
|
+
runId: handle.id,
|
|
1359
|
+
type: "workflow",
|
|
1360
|
+
status: handle.status,
|
|
1361
|
+
stopped: false,
|
|
1362
|
+
note: `workflow already ${handle.status} — nothing to stop; poll TaskOutput for its final state.`,
|
|
1363
|
+
}),
|
|
1364
|
+
details: { task_id: handle.id, type: "workflow", status: handle.status, retrieval_status: "success" },
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
handle.status = "cancelled";
|
|
1368
|
+
handle.updatedAt = Date.now();
|
|
1369
|
+
handle.handle.cancel("TaskStop requested");
|
|
1370
|
+
return {
|
|
1371
|
+
content: JSON.stringify({
|
|
1372
|
+
task_id: handle.id,
|
|
1373
|
+
runId: handle.id,
|
|
1374
|
+
type: "workflow",
|
|
1375
|
+
status: "cancelled",
|
|
1376
|
+
stopped: true,
|
|
1377
|
+
note: "workflow cancellation requested; durable run status maps cancellation to failed when it finalizes.",
|
|
1378
|
+
}),
|
|
1379
|
+
details: { task_id: handle.id, type: "workflow", status: "cancelled", retrieval_status: "success" },
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
export const defaultTaskRegistry = new TaskRegistry();
|
|
1384
|
+
export function createTaskOutputTool(opts) {
|
|
1385
|
+
return defineTool({
|
|
1386
|
+
name: "TaskOutput",
|
|
1387
|
+
aliases: [...TASK_OUTPUT_ALIASES],
|
|
1388
|
+
description: "Retrieve output or status for a background task by task_id. Supports background Bash tasks and workflow " +
|
|
1389
|
+
"tasks returned by RunWorkflow. Returns only the caller's own task scope; unknown and out-of-scope ids are " +
|
|
1390
|
+
"reported the same way. Legacy bash_id and runId arguments are accepted for compatibility.",
|
|
1391
|
+
parameters: Type.Object({
|
|
1392
|
+
task_id: Type.Optional(Type.String({ description: "The task_id returned by Bash(run_in_background) or RunWorkflow." })),
|
|
1393
|
+
block: Type.Optional(Type.Boolean({ description: "Whether to wait for completion (default true — the call waits until the task finishes or `timeout`, saving re-poll turns). Pass false for an instantaneous snapshot." })),
|
|
1394
|
+
timeout: Type.Optional(Type.Number({ description: "Optional timeout in milliseconds when block is true (default 30000, max 600000)." })),
|
|
1395
|
+
filter: Type.Optional(Type.String({ description: "Optional regex filter for background Bash output (sema extension)." })),
|
|
1396
|
+
}),
|
|
1397
|
+
effect: "read",
|
|
1398
|
+
execute: async (rawArgs, ctx) => {
|
|
1399
|
+
const args = rawArgs;
|
|
1400
|
+
const id = firstString(args.task_id, args.bash_id, args.runId);
|
|
1401
|
+
if (!id)
|
|
1402
|
+
return "Error (TaskOutput): Missing required parameter: task_id";
|
|
1403
|
+
const r = await opts.registry.pollTask(id, { owner: ctx.taskId ?? opts.owner, scope: ctx.principal ?? opts.scope, ...(opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {}) }, {
|
|
1404
|
+
workflowStore: opts.workflowStore,
|
|
1405
|
+
filter: typeof args.filter === "string" ? args.filter : undefined,
|
|
1406
|
+
block: args.block !== false,
|
|
1407
|
+
timeoutMs: typeof args.timeout === "number" ? args.timeout : undefined,
|
|
1408
|
+
signal: ctx.signal,
|
|
1409
|
+
});
|
|
1410
|
+
const { type: taskType, ...rest } = r.details;
|
|
1411
|
+
return { content: r.content, details: { type: "task-output", ...(taskType !== undefined ? { taskType } : {}), ...rest } };
|
|
1412
|
+
},
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
export function createTaskStopTool(opts) {
|
|
1416
|
+
return defineTool({
|
|
1417
|
+
name: "TaskStop",
|
|
1418
|
+
aliases: [...TASK_STOP_ALIASES],
|
|
1419
|
+
description: "- Stops a running background task by its ID\n" +
|
|
1420
|
+
"- Takes a task_id parameter identifying the task to stop\n" +
|
|
1421
|
+
"- To stop a background agent spawned with a name, pass that name as task_id\n" +
|
|
1422
|
+
"- Returns a success or failure status\n" +
|
|
1423
|
+
"- Use this tool when you need to terminate a long-running task",
|
|
1424
|
+
parameters: Type.Object({
|
|
1425
|
+
task_id: Type.Optional(Type.String({ description: "The ID of the background task to stop" })),
|
|
1426
|
+
shell_id: Type.Optional(Type.String({ description: "Deprecated: use task_id instead" })),
|
|
1427
|
+
}),
|
|
1428
|
+
effect: "write",
|
|
1429
|
+
execute: async (rawArgs, ctx) => {
|
|
1430
|
+
const args = rawArgs;
|
|
1431
|
+
const id = firstString(args.task_id, args.shell_id, args.runId);
|
|
1432
|
+
if (!id)
|
|
1433
|
+
return "Missing required parameter: task_id";
|
|
1434
|
+
const r = await opts.registry.stopTask(id, { owner: ctx.taskId ?? opts.owner, scope: ctx.principal ?? opts.scope, ...(opts.sessionId !== undefined ? { sessionId: opts.sessionId } : {}) }, { workflowStore: opts.workflowStore });
|
|
1435
|
+
const { type: taskType, ...rest } = r.details;
|
|
1436
|
+
return {
|
|
1437
|
+
content: r.content,
|
|
1438
|
+
details: { type: "task-stop", message: r.content, task_type: taskType ?? "unknown", ...rest },
|
|
1439
|
+
};
|
|
1440
|
+
},
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
//# sourceMappingURL=task-registry.js.map
|