@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,945 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { closeSync, constants, createReadStream, mkdtempSync, openSync, readSync, statSync } from "node:fs";
|
|
4
|
+
import { access, appendFile, lstat, mkdir, mkdtemp, readdir, readFile, readlink, realpath, rm, writeFile, } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
7
|
+
import { createInterface } from "node:readline";
|
|
8
|
+
import { ExecutionError, err, FileError, ok, toError, } from "../harness/types.js";
|
|
9
|
+
import { killProcessTree } from "./kill-tree.js";
|
|
10
|
+
import { scrubSecretEnv } from "../../core/secret-env.js";
|
|
11
|
+
import { RollingTailBuffer, markTruncated } from "../../core/exec-output-tail.js";
|
|
12
|
+
import { BackgroundShellError } from "../../core/background-shell.js";
|
|
13
|
+
import { SchedulerError } from "../../core/scheduler.js";
|
|
14
|
+
const MAX_TIMER_TIMEOUT_MS = 2_147_000_000;
|
|
15
|
+
function resolvePath(cwd, path) {
|
|
16
|
+
return isAbsolute(path) ? path : resolve(cwd, path);
|
|
17
|
+
}
|
|
18
|
+
export function resolveExecTimeoutMs(timeoutSeconds) {
|
|
19
|
+
if (typeof timeoutSeconds !== "number" ||
|
|
20
|
+
!Number.isFinite(timeoutSeconds) ||
|
|
21
|
+
timeoutSeconds <= 0) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const milliseconds = Math.floor(timeoutSeconds * 1000);
|
|
25
|
+
if (!Number.isFinite(milliseconds) || milliseconds <= 0) {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
return Math.min(milliseconds, MAX_TIMER_TIMEOUT_MS);
|
|
29
|
+
}
|
|
30
|
+
function fileKindFromStats(stats) {
|
|
31
|
+
if (stats.isFile()) {
|
|
32
|
+
return "file";
|
|
33
|
+
}
|
|
34
|
+
if (stats.isDirectory()) {
|
|
35
|
+
return "directory";
|
|
36
|
+
}
|
|
37
|
+
if (stats.isSymbolicLink()) {
|
|
38
|
+
return "symlink";
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
function fileInfoFromStats(path, stats) {
|
|
43
|
+
const kind = fileKindFromStats(stats);
|
|
44
|
+
if (!kind) {
|
|
45
|
+
return err(new FileError("invalid", "Unsupported file type", path));
|
|
46
|
+
}
|
|
47
|
+
return ok({
|
|
48
|
+
name: (() => {
|
|
49
|
+
const t = path.replace(/[\\/]+$/, "");
|
|
50
|
+
return t.slice(Math.max(t.lastIndexOf("/"), t.lastIndexOf("\\")) + 1) || path;
|
|
51
|
+
})(),
|
|
52
|
+
path,
|
|
53
|
+
kind,
|
|
54
|
+
size: stats.size,
|
|
55
|
+
mtimeMs: stats.mtimeMs,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function isNodeError(error) {
|
|
59
|
+
return error instanceof Error && "code" in error;
|
|
60
|
+
}
|
|
61
|
+
function toFileError(error, path) {
|
|
62
|
+
if (error instanceof FileError) {
|
|
63
|
+
return error;
|
|
64
|
+
}
|
|
65
|
+
const cause = toError(error);
|
|
66
|
+
if (isNodeError(error)) {
|
|
67
|
+
const message = error.message;
|
|
68
|
+
switch (error.code) {
|
|
69
|
+
case "ABORT_ERR":
|
|
70
|
+
return new FileError("aborted", message, path, cause);
|
|
71
|
+
case "ENOENT":
|
|
72
|
+
return new FileError("not_found", message, path, cause);
|
|
73
|
+
case "EACCES":
|
|
74
|
+
case "EPERM":
|
|
75
|
+
return new FileError("permission_denied", message, path, cause);
|
|
76
|
+
case "ENOTDIR":
|
|
77
|
+
return new FileError("not_directory", message, path, cause);
|
|
78
|
+
case "EISDIR":
|
|
79
|
+
return new FileError("is_directory", message, path, cause);
|
|
80
|
+
case "EINVAL":
|
|
81
|
+
return new FileError("invalid", message, path, cause);
|
|
82
|
+
default:
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return new FileError("unknown", cause.message, path, cause);
|
|
87
|
+
}
|
|
88
|
+
function abortResult(signal, path) {
|
|
89
|
+
return signal?.aborted ? err(new FileError("aborted", "aborted", path)) : undefined;
|
|
90
|
+
}
|
|
91
|
+
async function pathExists(path) {
|
|
92
|
+
try {
|
|
93
|
+
await access(path, constants.F_OK);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function runCommand(command, args, timeoutMs) {
|
|
101
|
+
return await new Promise((resolveLocal) => {
|
|
102
|
+
let stdout = "";
|
|
103
|
+
let child;
|
|
104
|
+
try {
|
|
105
|
+
child = spawn(command, args, {
|
|
106
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
107
|
+
windowsHide: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
resolveLocal({ stdout: "", status: null });
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const timeout = setTimeout(() => {
|
|
115
|
+
if (child.pid) {
|
|
116
|
+
killProcessTree(child.pid, { force: true });
|
|
117
|
+
}
|
|
118
|
+
}, timeoutMs);
|
|
119
|
+
child.stdout?.setEncoding("utf8");
|
|
120
|
+
child.stdout?.on("data", (chunk) => {
|
|
121
|
+
stdout += chunk;
|
|
122
|
+
});
|
|
123
|
+
child.stdout?.on("error", () => { });
|
|
124
|
+
child.on("error", () => {
|
|
125
|
+
clearTimeout(timeout);
|
|
126
|
+
resolveLocal({ stdout: "", status: null });
|
|
127
|
+
});
|
|
128
|
+
child.on("close", (status) => {
|
|
129
|
+
clearTimeout(timeout);
|
|
130
|
+
resolveLocal({ stdout, status });
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export function isWslBashLauncher(p) {
|
|
135
|
+
return /[/\\](system32|windowsapps)[/\\]bash\.exe$/i.test(p);
|
|
136
|
+
}
|
|
137
|
+
async function findBashOnPath() {
|
|
138
|
+
const result = process.platform === "win32"
|
|
139
|
+
? await runCommand("where", ["bash.exe"], 5000)
|
|
140
|
+
: await runCommand("which", ["bash"], 5000);
|
|
141
|
+
if (result.status !== 0 || !result.stdout) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const lines = result.stdout.trim().split(/\r?\n/);
|
|
145
|
+
const firstMatch = process.platform === "win32" ? lines.find((l) => !isWslBashLauncher(l)) : lines[0];
|
|
146
|
+
return firstMatch && (await pathExists(firstMatch)) ? firstMatch : null;
|
|
147
|
+
}
|
|
148
|
+
export async function getShellConfig(customShellPath) {
|
|
149
|
+
if (customShellPath) {
|
|
150
|
+
if (await pathExists(customShellPath)) {
|
|
151
|
+
return ok({ shell: customShellPath, args: ["-c"] });
|
|
152
|
+
}
|
|
153
|
+
return err(new ExecutionError("shell_unavailable", `Custom shell path not found: ${customShellPath}`));
|
|
154
|
+
}
|
|
155
|
+
if (process.platform === "win32") {
|
|
156
|
+
const candidates = [];
|
|
157
|
+
const programFiles = process.env.ProgramFiles;
|
|
158
|
+
if (programFiles) {
|
|
159
|
+
candidates.push(`${programFiles}\\Git\\bin\\bash.exe`);
|
|
160
|
+
}
|
|
161
|
+
const programFilesX86 = process.env["ProgramFiles(x86)"];
|
|
162
|
+
if (programFilesX86) {
|
|
163
|
+
candidates.push(`${programFilesX86}\\Git\\bin\\bash.exe`);
|
|
164
|
+
}
|
|
165
|
+
for (const candidate of candidates) {
|
|
166
|
+
if (await pathExists(candidate)) {
|
|
167
|
+
return ok({ shell: candidate, args: ["-c"] });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const bashOnPath = await findBashOnPath();
|
|
171
|
+
if (bashOnPath) {
|
|
172
|
+
return ok({ shell: bashOnPath, args: ["-c"] });
|
|
173
|
+
}
|
|
174
|
+
return err(new ExecutionError("shell_unavailable", "No bash shell found"));
|
|
175
|
+
}
|
|
176
|
+
if (await pathExists("/bin/bash")) {
|
|
177
|
+
return ok({ shell: "/bin/bash", args: ["-c"] });
|
|
178
|
+
}
|
|
179
|
+
const bashOnPath = await findBashOnPath();
|
|
180
|
+
if (bashOnPath) {
|
|
181
|
+
return ok({ shell: bashOnPath, args: ["-c"] });
|
|
182
|
+
}
|
|
183
|
+
return ok({ shell: "sh", args: ["-c"] });
|
|
184
|
+
}
|
|
185
|
+
const EXEC_FORCE_SETTLE_GRACE_MS = 3000;
|
|
186
|
+
function getShellEnv(inheritEnv, baseEnv, extraEnv) {
|
|
187
|
+
let inherited;
|
|
188
|
+
if (inheritEnv === "all") {
|
|
189
|
+
inherited = process.env;
|
|
190
|
+
}
|
|
191
|
+
else if (Array.isArray(inheritEnv)) {
|
|
192
|
+
inherited = {};
|
|
193
|
+
for (const k of inheritEnv)
|
|
194
|
+
if (process.env[k] !== undefined)
|
|
195
|
+
inherited[k] = process.env[k];
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
inherited = scrubSecretEnv(process.env);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
...inherited,
|
|
202
|
+
...baseEnv,
|
|
203
|
+
...extraEnv,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const SIGNUM = { SIGHUP: 1, SIGINT: 2, SIGQUIT: 3, SIGABRT: 6, SIGKILL: 9, SIGSEGV: 11, SIGPIPE: 13, SIGTERM: 15 };
|
|
207
|
+
export function openSpoolPair(base) {
|
|
208
|
+
const outPath = `${base}.out.log`;
|
|
209
|
+
const errPath = `${base}.err.log`;
|
|
210
|
+
const fdOut = openSync(outPath, "wx", 0o600);
|
|
211
|
+
let fdErr;
|
|
212
|
+
try {
|
|
213
|
+
fdErr = openSync(errPath, "wx", 0o600);
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
try {
|
|
217
|
+
closeSync(fdOut);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
}
|
|
221
|
+
throw e;
|
|
222
|
+
}
|
|
223
|
+
return { outPath, errPath, fds: [fdOut, fdErr] };
|
|
224
|
+
}
|
|
225
|
+
export class NodeExecutionEnv {
|
|
226
|
+
cwd;
|
|
227
|
+
shellPath;
|
|
228
|
+
shellEnv;
|
|
229
|
+
inheritEnv;
|
|
230
|
+
scheduler;
|
|
231
|
+
bgShells = new Map();
|
|
232
|
+
bgCounter = 0;
|
|
233
|
+
retainBackgroundProcesses;
|
|
234
|
+
bgSpoolDir;
|
|
235
|
+
backgroundCapabilities;
|
|
236
|
+
constructor(options) {
|
|
237
|
+
this.cwd = options.cwd;
|
|
238
|
+
this.shellPath = options.shellPath;
|
|
239
|
+
this.shellEnv = options.shellEnv;
|
|
240
|
+
this.inheritEnv = options.inheritEnv ?? "scrub";
|
|
241
|
+
this.scheduler = options.scheduler;
|
|
242
|
+
this.retainBackgroundProcesses = options.retainBackgroundProcesses ?? false;
|
|
243
|
+
this.backgroundCapabilities = {
|
|
244
|
+
supported: true,
|
|
245
|
+
maxConcurrent: 8,
|
|
246
|
+
defaultBgTimeoutSec: 30 * 60,
|
|
247
|
+
maxBgTimeoutSec: 2 * 60 * 60,
|
|
248
|
+
supportsDetach: true,
|
|
249
|
+
retainBackgroundProcesses: this.retainBackgroundProcesses,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
get schedulerCapabilities() {
|
|
253
|
+
return (this.scheduler?.schedulerCapabilities ?? {
|
|
254
|
+
supported: false,
|
|
255
|
+
maxScheduledPerScope: 0,
|
|
256
|
+
minDelaySec: 0,
|
|
257
|
+
minCronIntervalSec: 0,
|
|
258
|
+
maxScheduledHorizonSec: 0,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async schedule(intent, ctx) {
|
|
262
|
+
if (!this.scheduler)
|
|
263
|
+
return err(new SchedulerError("unsupported", "No scheduler backend wired on this environment."));
|
|
264
|
+
return this.scheduler.schedule(intent, ctx);
|
|
265
|
+
}
|
|
266
|
+
async cancel(id, ctx) {
|
|
267
|
+
if (!this.scheduler)
|
|
268
|
+
return err(new SchedulerError("unsupported", "No scheduler backend wired on this environment."));
|
|
269
|
+
return this.scheduler.cancel(id, ctx);
|
|
270
|
+
}
|
|
271
|
+
async list(ctx) {
|
|
272
|
+
if (!this.scheduler)
|
|
273
|
+
return err(new SchedulerError("unsupported", "No scheduler backend wired on this environment."));
|
|
274
|
+
return this.scheduler.list(ctx);
|
|
275
|
+
}
|
|
276
|
+
async absolutePath(path) {
|
|
277
|
+
return ok(resolvePath(this.cwd, path));
|
|
278
|
+
}
|
|
279
|
+
async joinPath(parts) {
|
|
280
|
+
return ok(join(...parts));
|
|
281
|
+
}
|
|
282
|
+
async exec(command, options) {
|
|
283
|
+
if (options?.abortSignal?.aborted) {
|
|
284
|
+
return err(new ExecutionError("aborted", "aborted"));
|
|
285
|
+
}
|
|
286
|
+
const cwd = options?.cwd ? resolvePath(this.cwd, options.cwd) : this.cwd;
|
|
287
|
+
const shellConfig = await getShellConfig(this.shellPath);
|
|
288
|
+
if (!shellConfig.ok) {
|
|
289
|
+
return shellConfig;
|
|
290
|
+
}
|
|
291
|
+
return await new Promise((resolvePromise) => {
|
|
292
|
+
const stdoutTail = new RollingTailBuffer();
|
|
293
|
+
const stderrTail = new RollingTailBuffer();
|
|
294
|
+
let settled = false;
|
|
295
|
+
let timedOut = false;
|
|
296
|
+
let callbackError;
|
|
297
|
+
let child;
|
|
298
|
+
const timeoutRef = {};
|
|
299
|
+
const forceSettleRef = {};
|
|
300
|
+
const armForceSettle = (result) => {
|
|
301
|
+
if (forceSettleRef.current || settled)
|
|
302
|
+
return;
|
|
303
|
+
forceSettleRef.current = setTimeout(() => {
|
|
304
|
+
try {
|
|
305
|
+
child?.stdout?.destroy();
|
|
306
|
+
child?.stderr?.destroy();
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
}
|
|
310
|
+
settle(result);
|
|
311
|
+
}, EXEC_FORCE_SETTLE_GRACE_MS);
|
|
312
|
+
forceSettleRef.current.unref?.();
|
|
313
|
+
};
|
|
314
|
+
const partialOutput = () => {
|
|
315
|
+
const so = stdoutTail.result();
|
|
316
|
+
const se = stderrTail.result();
|
|
317
|
+
return { stdout: markTruncated(so.text, so.droppedBytes), stderr: markTruncated(se.text, se.droppedBytes) };
|
|
318
|
+
};
|
|
319
|
+
const onAbort = () => {
|
|
320
|
+
if (child?.pid) {
|
|
321
|
+
killProcessTree(child.pid, { force: true });
|
|
322
|
+
}
|
|
323
|
+
armForceSettle(err(new ExecutionError("aborted", "aborted", undefined, partialOutput())));
|
|
324
|
+
};
|
|
325
|
+
const settle = (result) => {
|
|
326
|
+
if (timeoutRef.current) {
|
|
327
|
+
clearTimeout(timeoutRef.current);
|
|
328
|
+
}
|
|
329
|
+
if (forceSettleRef.current) {
|
|
330
|
+
clearTimeout(forceSettleRef.current);
|
|
331
|
+
}
|
|
332
|
+
if (options?.abortSignal) {
|
|
333
|
+
options.abortSignal.removeEventListener("abort", onAbort);
|
|
334
|
+
}
|
|
335
|
+
if (settled) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
settled = true;
|
|
339
|
+
resolvePromise(result);
|
|
340
|
+
};
|
|
341
|
+
try {
|
|
342
|
+
child = spawn(shellConfig.value.shell, [...shellConfig.value.args, command], {
|
|
343
|
+
cwd,
|
|
344
|
+
detached: process.platform !== "win32",
|
|
345
|
+
env: getShellEnv(this.inheritEnv, this.shellEnv, options?.env),
|
|
346
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
347
|
+
windowsHide: true,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
const cause = toError(error);
|
|
352
|
+
settle(err(new ExecutionError("spawn_error", cause.message, cause)));
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const timeoutMs = resolveExecTimeoutMs(options?.timeout);
|
|
356
|
+
timeoutRef.current =
|
|
357
|
+
timeoutMs === undefined
|
|
358
|
+
? undefined
|
|
359
|
+
: setTimeout(() => {
|
|
360
|
+
timedOut = true;
|
|
361
|
+
if (child?.pid) {
|
|
362
|
+
killProcessTree(child.pid, { force: true });
|
|
363
|
+
}
|
|
364
|
+
armForceSettle(err(new ExecutionError("timeout", `timeout:${options?.timeout}`, undefined, partialOutput())));
|
|
365
|
+
}, timeoutMs);
|
|
366
|
+
if (options?.abortSignal) {
|
|
367
|
+
if (options.abortSignal.aborted) {
|
|
368
|
+
onAbort();
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
options.abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const onDetach = () => {
|
|
375
|
+
if (settled || !child)
|
|
376
|
+
return;
|
|
377
|
+
const shellId = this.adoptRunningChild(child, stdoutTail.result().text, stderrTail.result().text);
|
|
378
|
+
if (shellId === undefined)
|
|
379
|
+
return;
|
|
380
|
+
if (timeoutRef.current)
|
|
381
|
+
clearTimeout(timeoutRef.current);
|
|
382
|
+
settle(ok({ stdout: stdoutTail.result().text, stderr: stderrTail.result().text, exitCode: 0, detached: { shellId } }));
|
|
383
|
+
};
|
|
384
|
+
if (options?.detachSignal) {
|
|
385
|
+
if (options.detachSignal.aborted)
|
|
386
|
+
onDetach();
|
|
387
|
+
else {
|
|
388
|
+
const dl = () => onDetach();
|
|
389
|
+
options.detachSignal.addEventListener("abort", dl, { once: true });
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
child.stdout?.setEncoding("utf8");
|
|
393
|
+
child.stderr?.setEncoding("utf8");
|
|
394
|
+
child.stdout?.on("data", (chunk) => {
|
|
395
|
+
stdoutTail.push(Buffer.from(chunk, "utf8"));
|
|
396
|
+
try {
|
|
397
|
+
options?.onStdout?.(chunk);
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
const cause = toError(error);
|
|
401
|
+
callbackError = new ExecutionError("callback_error", cause.message, cause);
|
|
402
|
+
onAbort();
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
child.stderr?.on("data", (chunk) => {
|
|
406
|
+
stderrTail.push(Buffer.from(chunk, "utf8"));
|
|
407
|
+
try {
|
|
408
|
+
options?.onStderr?.(chunk);
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
const cause = toError(error);
|
|
412
|
+
callbackError = new ExecutionError("callback_error", cause.message, cause);
|
|
413
|
+
onAbort();
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
child.stdout?.on("error", () => { });
|
|
417
|
+
child.stderr?.on("error", () => { });
|
|
418
|
+
child.on("error", (error) => {
|
|
419
|
+
if (options?.abortSignal?.aborted) {
|
|
420
|
+
settle(err(new ExecutionError("aborted", "aborted", undefined, partialOutput())));
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
settle(err(new ExecutionError("spawn_error", error.message, error)));
|
|
424
|
+
});
|
|
425
|
+
child.on("close", (code, signal) => {
|
|
426
|
+
if (callbackError) {
|
|
427
|
+
settle(err(callbackError));
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (timedOut) {
|
|
431
|
+
settle(err(new ExecutionError("timeout", `timeout:${options?.timeout}`, undefined, partialOutput())));
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (options?.abortSignal?.aborted) {
|
|
435
|
+
settle(err(new ExecutionError("aborted", "aborted", undefined, partialOutput())));
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const so = stdoutTail.result();
|
|
439
|
+
const se = stderrTail.result();
|
|
440
|
+
if (code === null && signal) {
|
|
441
|
+
const signum = { SIGHUP: 1, SIGINT: 2, SIGQUIT: 3, SIGABRT: 6, SIGKILL: 9, SIGSEGV: 11, SIGPIPE: 13, SIGTERM: 15 };
|
|
442
|
+
settle(ok({
|
|
443
|
+
stdout: markTruncated(so.text, so.droppedBytes),
|
|
444
|
+
stderr: `${markTruncated(se.text, se.droppedBytes)}${se.text.endsWith("\n") || se.text === "" ? "" : "\n"}[process terminated by ${signal}]`,
|
|
445
|
+
exitCode: 128 + (signum[signal] ?? 9),
|
|
446
|
+
}));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
settle(ok({ stdout: markTruncated(so.text, so.droppedBytes), stderr: markTruncated(se.text, se.droppedBytes), exitCode: code ?? 0 }));
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
async readTextFile(path, abortSignal) {
|
|
454
|
+
const resolved = resolvePath(this.cwd, path);
|
|
455
|
+
const aborted = abortResult(abortSignal, resolved);
|
|
456
|
+
if (aborted) {
|
|
457
|
+
return aborted;
|
|
458
|
+
}
|
|
459
|
+
try {
|
|
460
|
+
return ok(await readFile(resolved, { encoding: "utf8", signal: abortSignal }));
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
return err(toFileError(error, resolved));
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
async readTextLines(path, options) {
|
|
467
|
+
const resolved = resolvePath(this.cwd, path);
|
|
468
|
+
const aborted = abortResult(options?.abortSignal, resolved);
|
|
469
|
+
if (aborted) {
|
|
470
|
+
return aborted;
|
|
471
|
+
}
|
|
472
|
+
if (options?.maxLines !== undefined && options.maxLines <= 0) {
|
|
473
|
+
return ok([]);
|
|
474
|
+
}
|
|
475
|
+
let stream;
|
|
476
|
+
let lineReader;
|
|
477
|
+
try {
|
|
478
|
+
stream = createReadStream(resolved, { encoding: "utf8", signal: options?.abortSignal });
|
|
479
|
+
lineReader = createInterface({ input: stream, crlfDelay: Infinity });
|
|
480
|
+
const lines = [];
|
|
481
|
+
for await (const line of lineReader) {
|
|
482
|
+
const loopAbort = abortResult(options?.abortSignal, resolved);
|
|
483
|
+
if (loopAbort) {
|
|
484
|
+
return loopAbort;
|
|
485
|
+
}
|
|
486
|
+
lines.push(line);
|
|
487
|
+
if (options?.maxLines !== undefined && lines.length >= options.maxLines) {
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const afterReadAbort = abortResult(options?.abortSignal, resolved);
|
|
492
|
+
if (afterReadAbort) {
|
|
493
|
+
return afterReadAbort;
|
|
494
|
+
}
|
|
495
|
+
return ok(lines);
|
|
496
|
+
}
|
|
497
|
+
catch (error) {
|
|
498
|
+
return err(toFileError(error, resolved));
|
|
499
|
+
}
|
|
500
|
+
finally {
|
|
501
|
+
lineReader?.close();
|
|
502
|
+
stream?.destroy();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async readBinaryFile(path, abortSignal) {
|
|
506
|
+
const resolved = resolvePath(this.cwd, path);
|
|
507
|
+
const aborted = abortResult(abortSignal, resolved);
|
|
508
|
+
if (aborted) {
|
|
509
|
+
return aborted;
|
|
510
|
+
}
|
|
511
|
+
try {
|
|
512
|
+
return ok(await readFile(resolved, { signal: abortSignal }));
|
|
513
|
+
}
|
|
514
|
+
catch (error) {
|
|
515
|
+
return err(toFileError(error, resolved));
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async writeFile(path, content, abortSignal) {
|
|
519
|
+
const resolved = resolvePath(this.cwd, path);
|
|
520
|
+
const aborted = abortResult(abortSignal, resolved);
|
|
521
|
+
if (aborted) {
|
|
522
|
+
return aborted;
|
|
523
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
await mkdir(resolve(resolved, ".."), { recursive: true });
|
|
526
|
+
const afterMkdirAbort = abortResult(abortSignal, resolved);
|
|
527
|
+
if (afterMkdirAbort) {
|
|
528
|
+
return afterMkdirAbort;
|
|
529
|
+
}
|
|
530
|
+
await writeFile(resolved, content, { signal: abortSignal });
|
|
531
|
+
return ok(undefined);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
return err(toFileError(error, resolved));
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
async writeFileExclusive(path, content, abortSignal) {
|
|
538
|
+
const resolved = resolvePath(this.cwd, path);
|
|
539
|
+
const aborted = abortResult(abortSignal, resolved);
|
|
540
|
+
if (aborted) {
|
|
541
|
+
return aborted;
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
await mkdir(resolve(resolved, ".."), { recursive: true });
|
|
545
|
+
}
|
|
546
|
+
catch (error) {
|
|
547
|
+
return err(toFileError(error, resolved));
|
|
548
|
+
}
|
|
549
|
+
const afterMkdirAbort = abortResult(abortSignal, resolved);
|
|
550
|
+
if (afterMkdirAbort) {
|
|
551
|
+
return afterMkdirAbort;
|
|
552
|
+
}
|
|
553
|
+
try {
|
|
554
|
+
await writeFile(resolved, content, { signal: abortSignal, flag: "wx" });
|
|
555
|
+
return ok(undefined);
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
if (error?.code === "EEXIST") {
|
|
559
|
+
return err(new FileError("already_exists", `file already exists: ${resolved}`, resolved, error instanceof Error ? error : undefined));
|
|
560
|
+
}
|
|
561
|
+
return err(toFileError(error, resolved));
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
async appendFile(path, content) {
|
|
565
|
+
const resolved = resolvePath(this.cwd, path);
|
|
566
|
+
try {
|
|
567
|
+
await mkdir(resolve(resolved, ".."), { recursive: true });
|
|
568
|
+
await appendFile(resolved, content);
|
|
569
|
+
return ok(undefined);
|
|
570
|
+
}
|
|
571
|
+
catch (error) {
|
|
572
|
+
return err(toFileError(error, resolved));
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
async fileInfo(path) {
|
|
576
|
+
const resolved = resolvePath(this.cwd, path);
|
|
577
|
+
try {
|
|
578
|
+
return fileInfoFromStats(resolved, await lstat(resolved));
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
return err(toFileError(error, resolved));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
async listDir(path, abortSignal) {
|
|
585
|
+
const resolved = resolvePath(this.cwd, path);
|
|
586
|
+
const aborted = abortResult(abortSignal, resolved);
|
|
587
|
+
if (aborted) {
|
|
588
|
+
return aborted;
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
const entries = await readdir(resolved, { withFileTypes: true });
|
|
592
|
+
const infos = [];
|
|
593
|
+
for (const entry of entries) {
|
|
594
|
+
const loopAbort = abortResult(abortSignal, resolved);
|
|
595
|
+
if (loopAbort) {
|
|
596
|
+
return loopAbort;
|
|
597
|
+
}
|
|
598
|
+
const entryPath = resolve(resolved, entry.name);
|
|
599
|
+
try {
|
|
600
|
+
const info = fileInfoFromStats(entryPath, await lstat(entryPath));
|
|
601
|
+
if (info.ok) {
|
|
602
|
+
infos.push(info.value);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
return err(toFileError(error, entryPath));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return ok(infos);
|
|
610
|
+
}
|
|
611
|
+
catch (error) {
|
|
612
|
+
return err(toFileError(error, resolved));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
async canonicalPath(path) {
|
|
616
|
+
const resolved = resolvePath(this.cwd, path);
|
|
617
|
+
try {
|
|
618
|
+
return ok(await realpath(resolved));
|
|
619
|
+
}
|
|
620
|
+
catch (error) {
|
|
621
|
+
return err(toFileError(error, resolved));
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
async readLink(path) {
|
|
625
|
+
const resolved = resolvePath(this.cwd, path);
|
|
626
|
+
try {
|
|
627
|
+
return ok(await readlink(resolved));
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
return err(toFileError(error, resolved));
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
async exists(path) {
|
|
634
|
+
const result = await this.fileInfo(path);
|
|
635
|
+
if (result.ok) {
|
|
636
|
+
return ok(true);
|
|
637
|
+
}
|
|
638
|
+
if (result.error.code === "not_found") {
|
|
639
|
+
return ok(false);
|
|
640
|
+
}
|
|
641
|
+
return err(result.error);
|
|
642
|
+
}
|
|
643
|
+
async createDir(path, options) {
|
|
644
|
+
const resolved = resolvePath(this.cwd, path);
|
|
645
|
+
try {
|
|
646
|
+
await mkdir(resolved, { recursive: options?.recursive ?? true });
|
|
647
|
+
return ok(undefined);
|
|
648
|
+
}
|
|
649
|
+
catch (error) {
|
|
650
|
+
return err(toFileError(error, resolved));
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
async remove(path, options) {
|
|
654
|
+
const resolved = resolvePath(this.cwd, path);
|
|
655
|
+
try {
|
|
656
|
+
await rm(resolved, {
|
|
657
|
+
recursive: options?.recursive ?? false,
|
|
658
|
+
force: options?.force ?? false,
|
|
659
|
+
});
|
|
660
|
+
return ok(undefined);
|
|
661
|
+
}
|
|
662
|
+
catch (error) {
|
|
663
|
+
return err(toFileError(error, resolved));
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
async createTempDir(prefix = "tmp-") {
|
|
667
|
+
try {
|
|
668
|
+
return ok(await mkdtemp(join(tmpdir(), prefix)));
|
|
669
|
+
}
|
|
670
|
+
catch (error) {
|
|
671
|
+
return err(toFileError(error));
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
async createTempFile(options) {
|
|
675
|
+
const dir = await this.createTempDir("tmp-");
|
|
676
|
+
if (!dir.ok) {
|
|
677
|
+
return dir;
|
|
678
|
+
}
|
|
679
|
+
const filePath = join(dir.value, `${options?.prefix ?? ""}${randomUUID()}${options?.suffix ?? ""}`);
|
|
680
|
+
try {
|
|
681
|
+
await writeFile(filePath, "");
|
|
682
|
+
return ok(filePath);
|
|
683
|
+
}
|
|
684
|
+
catch (error) {
|
|
685
|
+
return err(toFileError(error, filePath));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
adoptRunningChild(child, stdoutSoFar, stderrSoFar) {
|
|
689
|
+
const liveCount = [...this.bgShells.values()].filter((e) => e.status === "running").length;
|
|
690
|
+
if (liveCount >= this.backgroundCapabilities.maxConcurrent)
|
|
691
|
+
return undefined;
|
|
692
|
+
const shellId = `bg_${++this.bgCounter}_${randomUUID()}`;
|
|
693
|
+
const entry = {
|
|
694
|
+
child,
|
|
695
|
+
stdout: { tail: new RollingTailBuffer(), totalBytes: 0, cursorBytes: 0 },
|
|
696
|
+
stderr: { tail: new RollingTailBuffer(), totalBytes: 0, cursorBytes: 0 },
|
|
697
|
+
status: "running",
|
|
698
|
+
};
|
|
699
|
+
const seedOut = Buffer.from(stdoutSoFar, "utf8");
|
|
700
|
+
const seedErr = Buffer.from(stderrSoFar, "utf8");
|
|
701
|
+
entry.stdout.tail.push(seedOut);
|
|
702
|
+
entry.stdout.totalBytes += seedOut.length;
|
|
703
|
+
entry.stderr.tail.push(seedErr);
|
|
704
|
+
entry.stderr.totalBytes += seedErr.length;
|
|
705
|
+
child.stdout?.on("data", (chunk) => {
|
|
706
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk;
|
|
707
|
+
entry.stdout.tail.push(buf);
|
|
708
|
+
entry.stdout.totalBytes += buf.length;
|
|
709
|
+
});
|
|
710
|
+
child.stderr?.on("data", (chunk) => {
|
|
711
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk;
|
|
712
|
+
entry.stderr.tail.push(buf);
|
|
713
|
+
entry.stderr.totalBytes += buf.length;
|
|
714
|
+
});
|
|
715
|
+
child.on("error", () => {
|
|
716
|
+
if (entry.timer)
|
|
717
|
+
clearTimeout(entry.timer);
|
|
718
|
+
if (entry.status === "running")
|
|
719
|
+
entry.status = "failed";
|
|
720
|
+
});
|
|
721
|
+
child.on("close", (code, signal) => {
|
|
722
|
+
if (entry.timer)
|
|
723
|
+
clearTimeout(entry.timer);
|
|
724
|
+
if (entry.status === "killed")
|
|
725
|
+
return;
|
|
726
|
+
entry.status = "exited";
|
|
727
|
+
entry.exitCode = code === null && signal ? 128 + (SIGNUM[signal] ?? 9) : (code ?? 0);
|
|
728
|
+
});
|
|
729
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
730
|
+
entry.status = "exited";
|
|
731
|
+
entry.exitCode = child.exitCode ?? (child.signalCode ? 128 + (SIGNUM[child.signalCode] ?? 9) : 0);
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
const timeoutSec = this.backgroundCapabilities.defaultBgTimeoutSec;
|
|
735
|
+
entry.timer = setTimeout(() => {
|
|
736
|
+
entry.status = "killed";
|
|
737
|
+
if (child.pid)
|
|
738
|
+
killProcessTree(child.pid, { force: true });
|
|
739
|
+
}, timeoutSec * 1000);
|
|
740
|
+
entry.timer.unref?.();
|
|
741
|
+
}
|
|
742
|
+
this.bgShells.set(shellId, entry);
|
|
743
|
+
return shellId;
|
|
744
|
+
}
|
|
745
|
+
async spawnBackground(command, options) {
|
|
746
|
+
const liveCount = [...this.bgShells.values()].filter((e) => e.status === "running").length;
|
|
747
|
+
if (liveCount >= this.backgroundCapabilities.maxConcurrent) {
|
|
748
|
+
return err(new BackgroundShellError("limit_exceeded", `Too many running background shells (max ${this.backgroundCapabilities.maxConcurrent}); TaskStop one first.`));
|
|
749
|
+
}
|
|
750
|
+
const shellConfig = await getShellConfig(this.shellPath);
|
|
751
|
+
if (!shellConfig.ok) {
|
|
752
|
+
return err(new BackgroundShellError("spawn_failed", shellConfig.error.message, shellConfig.error));
|
|
753
|
+
}
|
|
754
|
+
let spool;
|
|
755
|
+
let spoolFds;
|
|
756
|
+
if (this.retainBackgroundProcesses) {
|
|
757
|
+
try {
|
|
758
|
+
if (!this.bgSpoolDir)
|
|
759
|
+
this.bgSpoolDir = mkdtempSync(join(tmpdir(), "sema-bg-"));
|
|
760
|
+
const pair = openSpoolPair(join(this.bgSpoolDir, `bg_${this.bgCounter + 1}_${randomUUID()}`));
|
|
761
|
+
spool = { outPath: pair.outPath, errPath: pair.errPath };
|
|
762
|
+
spoolFds = pair.fds;
|
|
763
|
+
}
|
|
764
|
+
catch {
|
|
765
|
+
spool = undefined;
|
|
766
|
+
spoolFds = undefined;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
let child;
|
|
770
|
+
try {
|
|
771
|
+
child = spawn(shellConfig.value.shell, [...shellConfig.value.args, command], {
|
|
772
|
+
cwd: options?.cwd ? resolvePath(this.cwd, options.cwd) : this.cwd,
|
|
773
|
+
detached: process.platform !== "win32",
|
|
774
|
+
env: getShellEnv(this.inheritEnv, this.shellEnv, options?.env),
|
|
775
|
+
stdio: spoolFds ? ["ignore", spoolFds[0], spoolFds[1]] : ["ignore", "pipe", "pipe"],
|
|
776
|
+
windowsHide: true,
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
catch (error) {
|
|
780
|
+
if (spoolFds) {
|
|
781
|
+
for (const fd of spoolFds) {
|
|
782
|
+
try {
|
|
783
|
+
closeSync(fd);
|
|
784
|
+
}
|
|
785
|
+
catch {
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
const cause = toError(error);
|
|
790
|
+
return err(new BackgroundShellError("spawn_failed", cause.message, cause));
|
|
791
|
+
}
|
|
792
|
+
if (spoolFds) {
|
|
793
|
+
for (const fd of spoolFds) {
|
|
794
|
+
try {
|
|
795
|
+
closeSync(fd);
|
|
796
|
+
}
|
|
797
|
+
catch {
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
const shellId = `bg_${++this.bgCounter}_${randomUUID()}`;
|
|
802
|
+
const entry = {
|
|
803
|
+
child,
|
|
804
|
+
stdout: { tail: new RollingTailBuffer(), totalBytes: 0, cursorBytes: 0 },
|
|
805
|
+
stderr: { tail: new RollingTailBuffer(), totalBytes: 0, cursorBytes: 0 },
|
|
806
|
+
status: "running",
|
|
807
|
+
...(spool ? { spool } : {}),
|
|
808
|
+
};
|
|
809
|
+
child.stdout?.setEncoding("utf8");
|
|
810
|
+
child.stderr?.setEncoding("utf8");
|
|
811
|
+
child.stdout?.on("data", (chunk) => {
|
|
812
|
+
const buf = Buffer.from(chunk, "utf8");
|
|
813
|
+
entry.stdout.tail.push(buf);
|
|
814
|
+
entry.stdout.totalBytes += buf.length;
|
|
815
|
+
});
|
|
816
|
+
child.stderr?.on("data", (chunk) => {
|
|
817
|
+
const buf = Buffer.from(chunk, "utf8");
|
|
818
|
+
entry.stderr.tail.push(buf);
|
|
819
|
+
entry.stderr.totalBytes += buf.length;
|
|
820
|
+
});
|
|
821
|
+
child.stdout?.on("error", () => { });
|
|
822
|
+
child.stderr?.on("error", () => { });
|
|
823
|
+
child.on("error", () => {
|
|
824
|
+
if (entry.timer)
|
|
825
|
+
clearTimeout(entry.timer);
|
|
826
|
+
if (entry.status === "running")
|
|
827
|
+
entry.status = "failed";
|
|
828
|
+
});
|
|
829
|
+
child.on("close", (code, signal) => {
|
|
830
|
+
if (entry.timer)
|
|
831
|
+
clearTimeout(entry.timer);
|
|
832
|
+
if (entry.status === "killed")
|
|
833
|
+
return;
|
|
834
|
+
entry.status = "exited";
|
|
835
|
+
entry.exitCode = code === null && signal ? 128 + (SIGNUM[signal] ?? 9) : (code ?? 0);
|
|
836
|
+
});
|
|
837
|
+
const timeoutSec = Math.min(options?.timeout ?? this.backgroundCapabilities.defaultBgTimeoutSec, this.backgroundCapabilities.maxBgTimeoutSec);
|
|
838
|
+
entry.timer = setTimeout(() => {
|
|
839
|
+
if (child.pid && entry.status === "running") {
|
|
840
|
+
entry.status = "killed";
|
|
841
|
+
killProcessTree(child.pid, { force: true });
|
|
842
|
+
}
|
|
843
|
+
}, timeoutSec * 1000);
|
|
844
|
+
entry.timer.unref?.();
|
|
845
|
+
this.bgShells.set(shellId, entry);
|
|
846
|
+
return ok({ shellId });
|
|
847
|
+
}
|
|
848
|
+
async pollBackground(shellId) {
|
|
849
|
+
const entry = this.bgShells.get(shellId);
|
|
850
|
+
if (!entry) {
|
|
851
|
+
return err(new BackgroundShellError("not_found", `Unknown background shell: ${shellId}`));
|
|
852
|
+
}
|
|
853
|
+
this.syncSpool(entry);
|
|
854
|
+
const slice = (s) => {
|
|
855
|
+
const { text, droppedBytes } = s.tail.result();
|
|
856
|
+
const droppedBeforeCursor = Math.max(0, droppedBytes - s.cursorBytes);
|
|
857
|
+
const startByte = Math.max(s.cursorBytes, droppedBytes);
|
|
858
|
+
const startInTail = startByte - droppedBytes;
|
|
859
|
+
const inc = startInTail <= 0 ? text : Buffer.from(text, "utf8").subarray(startInTail).toString("utf8");
|
|
860
|
+
s.cursorBytes = s.totalBytes;
|
|
861
|
+
return { inc, droppedBeforeCursor };
|
|
862
|
+
};
|
|
863
|
+
const out = slice(entry.stdout);
|
|
864
|
+
const er = slice(entry.stderr);
|
|
865
|
+
const droppedBeforeCursor = out.droppedBeforeCursor + er.droppedBeforeCursor;
|
|
866
|
+
return ok({
|
|
867
|
+
stdout: out.inc,
|
|
868
|
+
stderr: er.inc,
|
|
869
|
+
status: entry.status,
|
|
870
|
+
...(entry.exitCode !== undefined ? { exitCode: entry.exitCode } : {}),
|
|
871
|
+
...(droppedBeforeCursor > 0 ? { truncated: true, bytesDroppedBeforeCursor: droppedBeforeCursor } : {}),
|
|
872
|
+
bytesFromStart: entry.stdout.totalBytes + entry.stderr.totalBytes,
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
async killBackground(shellId) {
|
|
876
|
+
const entry = this.bgShells.get(shellId);
|
|
877
|
+
if (!entry) {
|
|
878
|
+
return err(new BackgroundShellError("not_found", `Unknown background shell: ${shellId}`));
|
|
879
|
+
}
|
|
880
|
+
if (entry.status === "running" && entry.child.pid) {
|
|
881
|
+
entry.status = "killed";
|
|
882
|
+
if (entry.timer)
|
|
883
|
+
clearTimeout(entry.timer);
|
|
884
|
+
killProcessTree(entry.child.pid, { force: true });
|
|
885
|
+
}
|
|
886
|
+
return ok(undefined);
|
|
887
|
+
}
|
|
888
|
+
syncSpool(entry) {
|
|
889
|
+
if (!entry.spool)
|
|
890
|
+
return;
|
|
891
|
+
const streams = [
|
|
892
|
+
[entry.stdout, entry.spool.outPath],
|
|
893
|
+
[entry.stderr, entry.spool.errPath],
|
|
894
|
+
];
|
|
895
|
+
for (const [stream, path] of streams) {
|
|
896
|
+
try {
|
|
897
|
+
const size = statSync(path).size;
|
|
898
|
+
if (size <= stream.totalBytes)
|
|
899
|
+
continue;
|
|
900
|
+
const fd = openSync(path, "r");
|
|
901
|
+
try {
|
|
902
|
+
const want = Math.min(size - stream.totalBytes, 8 * 1024 * 1024 + 4096);
|
|
903
|
+
const buf = Buffer.alloc(want);
|
|
904
|
+
const got = readSync(fd, buf, 0, want, stream.totalBytes);
|
|
905
|
+
if (got > 0) {
|
|
906
|
+
stream.tail.push(buf.subarray(0, got));
|
|
907
|
+
stream.totalBytes += got;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
finally {
|
|
911
|
+
closeSync(fd);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
catch {
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
async disposeBackgroundShells(opts) {
|
|
919
|
+
if (this.retainBackgroundProcesses)
|
|
920
|
+
return;
|
|
921
|
+
const keep = opts?.except !== undefined && opts.except.length > 0 ? new Set(opts.except) : undefined;
|
|
922
|
+
for (const [id, entry] of this.bgShells) {
|
|
923
|
+
if (keep?.has(id))
|
|
924
|
+
continue;
|
|
925
|
+
try {
|
|
926
|
+
if (entry.timer)
|
|
927
|
+
clearTimeout(entry.timer);
|
|
928
|
+
if (entry.status === "running" && entry.child.pid) {
|
|
929
|
+
entry.status = "killed";
|
|
930
|
+
killProcessTree(entry.child.pid, { force: true });
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
catch {
|
|
934
|
+
}
|
|
935
|
+
if (keep !== undefined)
|
|
936
|
+
this.bgShells.delete(id);
|
|
937
|
+
}
|
|
938
|
+
if (keep === undefined)
|
|
939
|
+
this.bgShells.clear();
|
|
940
|
+
}
|
|
941
|
+
async cleanup() {
|
|
942
|
+
await this.disposeBackgroundShells();
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
//# sourceMappingURL=node-execution-env.js.map
|