@orion-agents/orion-code 0.1.9 → 0.2.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/CHANGELOG.md +50 -0
- package/README.md +142 -323
- package/README.zh-CN.md +117 -578
- package/dist/cli.js +65 -84
- package/dist/cli.js.map +1 -1
- package/dist/commands/context-commands.d.ts.map +1 -1
- package/dist/commands/context-commands.js +14 -7
- package/dist/commands/context-commands.js.map +1 -1
- package/dist/commands/context-tool-command-handlers.d.ts +4 -5
- package/dist/commands/context-tool-command-handlers.d.ts.map +1 -1
- package/dist/commands/context-tool-command-handlers.js +132 -208
- package/dist/commands/context-tool-command-handlers.js.map +1 -1
- package/dist/commands/core-command-handlers.d.ts +3 -6
- package/dist/commands/core-command-handlers.d.ts.map +1 -1
- package/dist/commands/core-command-handlers.js +66 -664
- package/dist/commands/core-command-handlers.js.map +1 -1
- package/dist/commands/diagnostic-command-handlers.d.ts +1 -2
- package/dist/commands/diagnostic-command-handlers.d.ts.map +1 -1
- package/dist/commands/diagnostic-command-handlers.js +3 -17
- package/dist/commands/diagnostic-command-handlers.js.map +1 -1
- package/dist/commands/diagnostic-commands.d.ts.map +1 -1
- package/dist/commands/diagnostic-commands.js +0 -45
- package/dist/commands/diagnostic-commands.js.map +1 -1
- package/dist/commands/index.d.ts +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -7
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/model-command-handlers.d.ts +1 -1
- package/dist/commands/model-command-handlers.js +2 -2
- package/dist/commands/model-command-handlers.js.map +1 -1
- package/dist/commands/model-commands.d.ts.map +1 -1
- package/dist/commands/model-commands.js +0 -11
- package/dist/commands/model-commands.js.map +1 -1
- package/dist/commands/registry.d.ts.map +1 -1
- package/dist/commands/registry.js +1 -139
- package/dist/commands/registry.js.map +1 -1
- package/dist/commands/session-command-handlers.d.ts.map +1 -1
- package/dist/commands/session-command-handlers.js +29 -205
- package/dist/commands/session-command-handlers.js.map +1 -1
- package/dist/commands/session-commands.d.ts.map +1 -1
- package/dist/commands/session-commands.js +0 -48
- package/dist/commands/session-commands.js.map +1 -1
- package/dist/commands/target-command.d.ts +9 -15
- package/dist/commands/target-command.d.ts.map +1 -1
- package/dist/commands/target-command.js +16 -130
- package/dist/commands/target-command.js.map +1 -1
- package/dist/commands/tool-commands.d.ts.map +1 -1
- package/dist/commands/tool-commands.js +0 -10
- package/dist/commands/tool-commands.js.map +1 -1
- package/dist/commands/types.d.ts +8 -14
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +1 -1
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/workflow-command-handlers.d.ts.map +1 -1
- package/dist/commands/workflow-command-handlers.js +1 -3
- package/dist/commands/workflow-command-handlers.js.map +1 -1
- package/dist/commands/workflow-commands.d.ts.map +1 -1
- package/dist/commands/workflow-commands.js +2 -24
- package/dist/commands/workflow-commands.js.map +1 -1
- package/dist/framework/agent-mode.d.ts +2 -3
- package/dist/framework/agent-mode.d.ts.map +1 -1
- package/dist/framework/agent-mode.js +8 -31
- package/dist/framework/agent-mode.js.map +1 -1
- package/dist/framework/index.d.ts +3 -3
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +6 -9
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/loop-budget-contract.d.ts +20 -0
- package/dist/framework/loop-budget-contract.d.ts.map +1 -0
- package/dist/framework/loop-budget-contract.js +13 -0
- package/dist/framework/loop-budget-contract.js.map +1 -0
- package/dist/framework/prompt.d.ts.map +1 -1
- package/dist/framework/prompt.js +5 -4
- package/dist/framework/prompt.js.map +1 -1
- package/dist/framework/query.d.ts +45 -22
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +64 -52
- package/dist/framework/query.js.map +1 -1
- package/dist/framework/store.d.ts +4 -2
- package/dist/framework/store.d.ts.map +1 -1
- package/dist/framework/store.js +1 -0
- package/dist/framework/store.js.map +1 -1
- package/dist/framework/tool-call-orchestrator.d.ts +80 -0
- package/dist/framework/tool-call-orchestrator.d.ts.map +1 -0
- package/dist/framework/tool-call-orchestrator.js +192 -0
- package/dist/framework/tool-call-orchestrator.js.map +1 -0
- package/dist/framework/tool-state.d.ts +12 -11
- package/dist/framework/tool-state.d.ts.map +1 -1
- package/dist/framework/tool-state.js +36 -28
- package/dist/framework/tool-state.js.map +1 -1
- package/dist/framework/tool.d.ts +0 -9
- package/dist/framework/tool.d.ts.map +1 -1
- package/dist/framework/tool.js.map +1 -1
- package/dist/index.d.ts +70 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -65
- package/dist/index.js.map +1 -1
- package/dist/print-ui/launch.d.ts.map +1 -1
- package/dist/print-ui/launch.js +9 -2
- package/dist/print-ui/launch.js.map +1 -1
- package/dist/product/paths.d.ts +7 -0
- package/dist/product/paths.d.ts.map +1 -1
- package/dist/product/paths.js +19 -0
- package/dist/product/paths.js.map +1 -1
- package/dist/runtime/agent-loop.d.ts +78 -0
- package/dist/runtime/agent-loop.d.ts.map +1 -0
- package/dist/runtime/agent-loop.js +418 -0
- package/dist/runtime/agent-loop.js.map +1 -0
- package/dist/runtime/agent-runtime-controller.d.ts +10 -57
- package/dist/runtime/agent-runtime-controller.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-controller.js +265 -1215
- package/dist/runtime/agent-runtime-controller.js.map +1 -1
- package/dist/runtime/agent-runtime-protocol.d.ts +4 -5
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-protocol.js.map +1 -1
- package/dist/runtime/agent-runtime-runner.d.ts +34 -0
- package/dist/runtime/agent-runtime-runner.d.ts.map +1 -0
- package/dist/runtime/agent-runtime-runner.js +3 -0
- package/dist/runtime/agent-runtime-runner.js.map +1 -0
- package/dist/runtime/batch-read-service.d.ts +29 -0
- package/dist/runtime/batch-read-service.d.ts.map +1 -0
- package/dist/runtime/batch-read-service.js +212 -0
- package/dist/runtime/batch-read-service.js.map +1 -0
- package/dist/runtime/builtin-tool-provider.d.ts +30 -0
- package/dist/runtime/builtin-tool-provider.d.ts.map +1 -0
- package/dist/runtime/builtin-tool-provider.js +233 -0
- package/dist/runtime/builtin-tool-provider.js.map +1 -0
- package/dist/runtime/capabilities/compiler.d.ts +11 -0
- package/dist/runtime/capabilities/compiler.d.ts.map +1 -0
- package/dist/runtime/capabilities/compiler.js +719 -0
- package/dist/runtime/capabilities/compiler.js.map +1 -0
- package/dist/runtime/capabilities/index.d.ts +3 -0
- package/dist/runtime/capabilities/index.d.ts.map +1 -0
- package/dist/runtime/capabilities/index.js +9 -0
- package/dist/runtime/capabilities/index.js.map +1 -0
- package/dist/runtime/capabilities/types.d.ts +175 -0
- package/dist/runtime/capabilities/types.d.ts.map +1 -0
- package/dist/runtime/capabilities/types.js +3 -0
- package/dist/runtime/capabilities/types.js.map +1 -0
- package/dist/runtime/capability-receipt-journal.d.ts +29 -0
- package/dist/runtime/capability-receipt-journal.d.ts.map +1 -0
- package/dist/runtime/capability-receipt-journal.js +264 -0
- package/dist/runtime/capability-receipt-journal.js.map +1 -0
- package/dist/runtime/capability-step-factory.d.ts +73 -0
- package/dist/runtime/capability-step-factory.d.ts.map +1 -0
- package/dist/runtime/capability-step-factory.js +302 -0
- package/dist/runtime/capability-step-factory.js.map +1 -0
- package/dist/runtime/compact-transaction.d.ts +225 -0
- package/dist/runtime/compact-transaction.d.ts.map +1 -0
- package/dist/runtime/compact-transaction.js +622 -0
- package/dist/runtime/compact-transaction.js.map +1 -0
- package/dist/runtime/composer/buffer.d.ts +3 -4
- package/dist/runtime/composer/buffer.d.ts.map +1 -1
- package/dist/runtime/composer/buffer.js +3 -4
- package/dist/runtime/composer/buffer.js.map +1 -1
- package/dist/runtime/composer/grapheme.d.ts +2 -4
- package/dist/runtime/composer/grapheme.d.ts.map +1 -1
- package/dist/runtime/composer/grapheme.js +2 -4
- package/dist/runtime/composer/grapheme.js.map +1 -1
- package/dist/runtime/composer/layout.d.ts +1 -3
- package/dist/runtime/composer/layout.d.ts.map +1 -1
- package/dist/runtime/composer/layout.js +1 -3
- package/dist/runtime/composer/layout.js.map +1 -1
- package/dist/runtime/core-tools/descriptors.d.ts +17 -0
- package/dist/runtime/core-tools/descriptors.d.ts.map +1 -0
- package/dist/runtime/core-tools/descriptors.js +185 -0
- package/dist/runtime/core-tools/descriptors.js.map +1 -0
- package/dist/runtime/first-party-core-provider.d.ts +55 -0
- package/dist/runtime/first-party-core-provider.d.ts.map +1 -0
- package/dist/runtime/first-party-core-provider.js +197 -0
- package/dist/runtime/first-party-core-provider.js.map +1 -0
- package/dist/runtime/first-party-long-tail-provider.d.ts +57 -0
- package/dist/runtime/first-party-long-tail-provider.d.ts.map +1 -0
- package/dist/runtime/first-party-long-tail-provider.js +238 -0
- package/dist/runtime/first-party-long-tail-provider.js.map +1 -0
- package/dist/runtime/first-party-tool-services.d.ts +43 -0
- package/dist/runtime/first-party-tool-services.d.ts.map +1 -0
- package/dist/runtime/first-party-tool-services.js +200 -0
- package/dist/runtime/first-party-tool-services.js.map +1 -0
- package/dist/runtime/first-party-tool-universe.d.ts +14 -0
- package/dist/runtime/first-party-tool-universe.d.ts.map +1 -0
- package/dist/runtime/first-party-tool-universe.js +20 -0
- package/dist/runtime/first-party-tool-universe.js.map +1 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts +63 -0
- package/dist/runtime/goal-lifecycle-v2.d.ts.map +1 -0
- package/dist/runtime/goal-lifecycle-v2.js +253 -0
- package/dist/runtime/goal-lifecycle-v2.js.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts +105 -0
- package/dist/runtime/goal-runtime-coordinator.d.ts.map +1 -0
- package/dist/runtime/goal-runtime-coordinator.js +506 -0
- package/dist/runtime/goal-runtime-coordinator.js.map +1 -0
- package/dist/runtime/harness-confluence.d.ts +165 -0
- package/dist/runtime/harness-confluence.d.ts.map +1 -0
- package/dist/runtime/harness-confluence.js +807 -0
- package/dist/runtime/harness-confluence.js.map +1 -0
- package/dist/runtime/harness-eval.d.ts +96 -0
- package/dist/runtime/harness-eval.d.ts.map +1 -0
- package/dist/runtime/harness-eval.js +181 -0
- package/dist/runtime/harness-eval.js.map +1 -0
- package/dist/runtime/harness-metrics.d.ts +202 -0
- package/dist/runtime/harness-metrics.d.ts.map +1 -0
- package/dist/runtime/harness-metrics.js +415 -0
- package/dist/runtime/harness-metrics.js.map +1 -0
- package/dist/runtime/legacy-session-importer.d.ts +99 -0
- package/dist/runtime/legacy-session-importer.d.ts.map +1 -0
- package/dist/runtime/legacy-session-importer.js +455 -0
- package/dist/runtime/legacy-session-importer.js.map +1 -0
- package/dist/runtime/legacy-thread-materializer.d.ts +72 -0
- package/dist/runtime/legacy-thread-materializer.d.ts.map +1 -0
- package/dist/runtime/legacy-thread-materializer.js +553 -0
- package/dist/runtime/legacy-thread-materializer.js.map +1 -0
- package/dist/runtime/long-tail-tools/descriptors.d.ts +23 -0
- package/dist/runtime/long-tail-tools/descriptors.d.ts.map +1 -0
- package/dist/runtime/long-tail-tools/descriptors.js +423 -0
- package/dist/runtime/long-tail-tools/descriptors.js.map +1 -0
- package/dist/runtime/loop-budget.d.ts +1 -1
- package/dist/runtime/loop-budget.d.ts.map +1 -1
- package/dist/runtime/loop-budget.js +2 -2
- package/dist/runtime/loop-budget.js.map +1 -1
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts +75 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.d.ts.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js +484 -0
- package/dist/runtime/mcp/first-party-mcp-adapter.js.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-config.d.ts +13 -0
- package/dist/runtime/mcp/first-party-mcp-config.d.ts.map +1 -0
- package/dist/runtime/mcp/first-party-mcp-config.js +139 -0
- package/dist/runtime/mcp/first-party-mcp-config.js.map +1 -0
- package/dist/runtime/mcp/index.d.ts +5 -0
- package/dist/runtime/mcp/index.d.ts.map +1 -0
- package/dist/{skills → runtime/mcp}/index.js +3 -9
- package/dist/runtime/mcp/index.js.map +1 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.d.ts +95 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.d.ts.map +1 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.js +854 -0
- package/dist/runtime/mcp/lazy-mcp-runtime.js.map +1 -0
- package/dist/runtime/mcp/types.d.ts +128 -0
- package/dist/runtime/mcp/types.d.ts.map +1 -0
- package/dist/runtime/mcp/types.js +5 -0
- package/dist/runtime/mcp/types.js.map +1 -0
- package/dist/runtime/orion-runtime-v1.d.ts +321 -0
- package/dist/runtime/orion-runtime-v1.d.ts.map +1 -0
- package/dist/runtime/orion-runtime-v1.js +958 -0
- package/dist/runtime/orion-runtime-v1.js.map +1 -0
- package/dist/runtime/orion-session-runner.d.ts +37 -0
- package/dist/runtime/orion-session-runner.d.ts.map +1 -0
- package/dist/runtime/orion-session-runner.js +146 -0
- package/dist/runtime/orion-session-runner.js.map +1 -0
- package/dist/runtime/product-orion-runtime.d.ts +35 -0
- package/dist/runtime/product-orion-runtime.d.ts.map +1 -0
- package/dist/runtime/product-orion-runtime.js +1019 -0
- package/dist/runtime/product-orion-runtime.js.map +1 -0
- package/dist/runtime/prompts/index.d.ts +3 -0
- package/dist/runtime/prompts/index.d.ts.map +1 -0
- package/dist/{ink-ui/types.js → runtime/prompts/index.js} +3 -2
- package/dist/runtime/prompts/index.js.map +1 -0
- package/dist/runtime/prompts/prompt-registry.d.ts +22 -0
- package/dist/runtime/prompts/prompt-registry.d.ts.map +1 -0
- package/dist/runtime/prompts/prompt-registry.js +356 -0
- package/dist/runtime/prompts/prompt-registry.js.map +1 -0
- package/dist/runtime/prompts/types.d.ts +111 -0
- package/dist/runtime/prompts/types.d.ts.map +1 -0
- package/dist/runtime/prompts/types.js +5 -0
- package/dist/runtime/prompts/types.js.map +1 -0
- package/dist/runtime/protocol/canonical.d.ts +3 -0
- package/dist/runtime/protocol/canonical.d.ts.map +1 -0
- package/dist/runtime/protocol/canonical.js +21 -0
- package/dist/runtime/protocol/canonical.js.map +1 -0
- package/dist/runtime/protocol/index.d.ts +4 -0
- package/dist/runtime/protocol/index.d.ts.map +1 -0
- package/dist/runtime/protocol/index.js +16 -0
- package/dist/runtime/protocol/index.js.map +1 -0
- package/dist/runtime/protocol/runtime-protocol-v1.d.ts +671 -0
- package/dist/runtime/protocol/runtime-protocol-v1.d.ts.map +1 -0
- package/dist/runtime/protocol/runtime-protocol-v1.js +557 -0
- package/dist/runtime/protocol/runtime-protocol-v1.js.map +1 -0
- package/dist/runtime/release-receipts.d.ts +109 -0
- package/dist/runtime/release-receipts.d.ts.map +1 -0
- package/dist/runtime/release-receipts.js +304 -0
- package/dist/runtime/release-receipts.js.map +1 -0
- package/dist/runtime/resource-scope.d.ts +123 -0
- package/dist/runtime/resource-scope.d.ts.map +1 -0
- package/dist/runtime/resource-scope.js +363 -0
- package/dist/runtime/resource-scope.js.map +1 -0
- package/dist/runtime/runtime-event-buffer.d.ts +78 -0
- package/dist/runtime/runtime-event-buffer.d.ts.map +1 -0
- package/dist/runtime/runtime-event-buffer.js +237 -0
- package/dist/runtime/runtime-event-buffer.js.map +1 -0
- package/dist/runtime/runtime-services.d.ts +87 -0
- package/dist/runtime/runtime-services.d.ts.map +1 -0
- package/dist/runtime/runtime-services.js +180 -0
- package/dist/runtime/runtime-services.js.map +1 -0
- package/dist/runtime/skills/bounded-lru-cache.d.ts +34 -0
- package/dist/runtime/skills/bounded-lru-cache.d.ts.map +1 -0
- package/dist/runtime/skills/bounded-lru-cache.js +100 -0
- package/dist/runtime/skills/bounded-lru-cache.js.map +1 -0
- package/dist/runtime/skills/filesystem-skill-provider.d.ts +96 -0
- package/dist/runtime/skills/filesystem-skill-provider.d.ts.map +1 -0
- package/dist/runtime/skills/filesystem-skill-provider.js +829 -0
- package/dist/runtime/skills/filesystem-skill-provider.js.map +1 -0
- package/dist/runtime/skills/index.d.ts +5 -0
- package/dist/runtime/skills/index.d.ts.map +1 -0
- package/dist/{ink-ui/controllers/chat-controller.js → runtime/skills/index.js} +5 -2
- package/dist/runtime/skills/index.js.map +1 -0
- package/dist/runtime/skills/lazy-skill-runtime.d.ts +77 -0
- package/dist/runtime/skills/lazy-skill-runtime.d.ts.map +1 -0
- package/dist/runtime/skills/lazy-skill-runtime.js +673 -0
- package/dist/runtime/skills/lazy-skill-runtime.js.map +1 -0
- package/dist/runtime/skills/types.d.ts +137 -0
- package/dist/runtime/skills/types.d.ts.map +1 -0
- package/dist/runtime/skills/types.js +13 -0
- package/dist/runtime/skills/types.js.map +1 -0
- package/dist/runtime/step-snapshot.d.ts +183 -0
- package/dist/runtime/step-snapshot.d.ts.map +1 -0
- package/dist/runtime/step-snapshot.js +286 -0
- package/dist/runtime/step-snapshot.js.map +1 -0
- package/dist/runtime/subagent-thread-runtime.d.ts +239 -0
- package/dist/runtime/subagent-thread-runtime.d.ts.map +1 -0
- package/dist/runtime/subagent-thread-runtime.js +876 -0
- package/dist/runtime/subagent-thread-runtime.js.map +1 -0
- package/dist/runtime/subagents/index.d.ts +4 -1
- package/dist/runtime/subagents/index.d.ts.map +1 -1
- package/dist/runtime/subagents/index.js +10 -2
- package/dist/runtime/subagents/index.js.map +1 -1
- package/dist/runtime/subagents/parent-step-fork.d.ts +36 -0
- package/dist/runtime/subagents/parent-step-fork.d.ts.map +1 -0
- package/dist/runtime/subagents/parent-step-fork.js +83 -0
- package/dist/runtime/subagents/parent-step-fork.js.map +1 -0
- package/dist/runtime/subagents/production.d.ts +65 -46
- package/dist/runtime/subagents/production.d.ts.map +1 -1
- package/dist/runtime/subagents/production.js +494 -170
- package/dist/runtime/subagents/production.js.map +1 -1
- package/dist/runtime/subagents/receipt-journal.d.ts +20 -0
- package/dist/runtime/subagents/receipt-journal.d.ts.map +1 -0
- package/dist/runtime/subagents/receipt-journal.js +74 -0
- package/dist/runtime/subagents/receipt-journal.js.map +1 -0
- package/dist/runtime/subagents/runtime-contract.d.ts +29 -0
- package/dist/runtime/subagents/runtime-contract.d.ts.map +1 -0
- package/dist/runtime/subagents/runtime-contract.js +3 -0
- package/dist/runtime/subagents/runtime-contract.js.map +1 -0
- package/dist/runtime/subagents/runtime-integration.d.ts +41 -56
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -1
- package/dist/runtime/subagents/runtime-integration.js +34 -198
- package/dist/runtime/subagents/runtime-integration.js.map +1 -1
- package/dist/runtime/subagents/supervisor.d.ts +19 -7
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -1
- package/dist/runtime/subagents/supervisor.js +83 -40
- package/dist/runtime/subagents/supervisor.js.map +1 -1
- package/dist/runtime/subagents/types.d.ts +1 -1
- package/dist/runtime/subagents/types.js +1 -1
- package/dist/runtime/task-context-service.d.ts +91 -0
- package/dist/runtime/task-context-service.d.ts.map +1 -0
- package/dist/runtime/task-context-service.js +122 -0
- package/dist/runtime/task-context-service.js.map +1 -0
- package/dist/runtime/thread-admission.d.ts +130 -0
- package/dist/runtime/thread-admission.d.ts.map +1 -0
- package/dist/runtime/thread-admission.js +276 -0
- package/dist/runtime/thread-admission.js.map +1 -0
- package/dist/runtime/thread-compact-persistence.d.ts +50 -0
- package/dist/runtime/thread-compact-persistence.d.ts.map +1 -0
- package/dist/runtime/thread-compact-persistence.js +176 -0
- package/dist/runtime/thread-compact-persistence.js.map +1 -0
- package/dist/runtime/thread-event-store.d.ts +98 -0
- package/dist/runtime/thread-event-store.d.ts.map +1 -0
- package/dist/runtime/thread-event-store.js +737 -0
- package/dist/runtime/thread-event-store.js.map +1 -0
- package/dist/runtime/thread-projection.d.ts +91 -0
- package/dist/runtime/thread-projection.d.ts.map +1 -0
- package/dist/runtime/thread-projection.js +407 -0
- package/dist/runtime/thread-projection.js.map +1 -0
- package/dist/runtime/thread-runtime.d.ts +165 -0
- package/dist/runtime/thread-runtime.d.ts.map +1 -0
- package/dist/runtime/thread-runtime.js +704 -0
- package/dist/runtime/thread-runtime.js.map +1 -0
- package/dist/runtime/thread-tool-journal.d.ts +11 -0
- package/dist/runtime/thread-tool-journal.d.ts.map +1 -0
- package/dist/runtime/thread-tool-journal.js +131 -0
- package/dist/runtime/thread-tool-journal.js.map +1 -0
- package/dist/runtime/thread-ui-adapter.d.ts +85 -0
- package/dist/runtime/thread-ui-adapter.d.ts.map +1 -0
- package/dist/runtime/thread-ui-adapter.js +514 -0
- package/dist/runtime/thread-ui-adapter.js.map +1 -0
- package/dist/runtime/tool-gateway.d.ts +159 -0
- package/dist/runtime/tool-gateway.d.ts.map +1 -0
- package/dist/runtime/tool-gateway.js +311 -0
- package/dist/runtime/tool-gateway.js.map +1 -0
- package/dist/runtime/turn-commit.d.ts +103 -0
- package/dist/runtime/turn-commit.d.ts.map +1 -0
- package/dist/runtime/turn-commit.js +321 -0
- package/dist/runtime/turn-commit.js.map +1 -0
- package/dist/runtime/ui-events.d.ts +13 -5
- package/dist/runtime/ui-events.d.ts.map +1 -1
- package/dist/runtime/ui-events.js +0 -1
- package/dist/runtime/ui-events.js.map +1 -1
- package/dist/runtime/ui-view-model.d.ts +1 -1
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +3 -5
- package/dist/runtime/ui-view-model.js.map +1 -1
- package/dist/services/config-dir.d.ts +1 -1
- package/dist/services/config-dir.d.ts.map +1 -1
- package/dist/services/config-dir.js +2 -1
- package/dist/services/config-dir.js.map +1 -1
- package/dist/services/config.d.ts +2 -16
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +2 -29
- package/dist/services/config.js.map +1 -1
- package/dist/services/doctor.d.ts +0 -2
- package/dist/services/doctor.d.ts.map +1 -1
- package/dist/services/doctor.js +39 -64
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/global-config.d.ts +2 -2
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/skills/builtin/code-review/SKILL.md +51 -0
- package/dist/skills/builtin/security-check/SKILL.md +54 -0
- package/dist/skills/builtin/test-gen/SKILL.md +49 -0
- package/dist/terminal-ui/launch.d.ts +3 -1
- package/dist/terminal-ui/launch.d.ts.map +1 -1
- package/dist/terminal-ui/launch.js +19 -3
- package/dist/terminal-ui/launch.js.map +1 -1
- package/dist/tools/core/common.d.ts +34 -0
- package/dist/tools/core/common.d.ts.map +1 -0
- package/dist/tools/core/common.js +164 -0
- package/dist/tools/core/common.js.map +1 -0
- package/dist/tools/core/edit-file.d.ts +10 -0
- package/dist/tools/core/edit-file.d.ts.map +1 -0
- package/dist/tools/core/edit-file.js +301 -0
- package/dist/tools/core/edit-file.js.map +1 -0
- package/dist/tools/core/exec-command.d.ts +2 -0
- package/dist/tools/core/exec-command.d.ts.map +1 -0
- package/dist/tools/core/exec-command.js +347 -0
- package/dist/tools/core/exec-command.js.map +1 -0
- package/dist/tools/core/glob.d.ts +2 -0
- package/dist/tools/core/glob.d.ts.map +1 -0
- package/dist/tools/core/glob.js +133 -0
- package/dist/tools/core/glob.js.map +1 -0
- package/dist/tools/core/grep.d.ts +12 -0
- package/dist/tools/core/grep.d.ts.map +1 -0
- package/dist/tools/core/grep.js +223 -0
- package/dist/tools/core/grep.js.map +1 -0
- package/dist/tools/core/index.d.ts +15 -0
- package/dist/tools/core/index.d.ts.map +1 -0
- package/dist/tools/core/index.js +31 -0
- package/dist/tools/core/index.js.map +1 -0
- package/dist/tools/core/list-files.d.ts +2 -0
- package/dist/tools/core/list-files.d.ts.map +1 -0
- package/dist/tools/core/list-files.js +87 -0
- package/dist/tools/core/list-files.js.map +1 -0
- package/dist/tools/core/read-file.d.ts +2 -0
- package/dist/tools/core/read-file.d.ts.map +1 -0
- package/dist/tools/core/read-file.js +129 -0
- package/dist/tools/core/read-file.js.map +1 -0
- package/dist/tools/core/write-file.d.ts +2 -0
- package/dist/tools/core/write-file.d.ts.map +1 -0
- package/dist/tools/core/write-file.js +65 -0
- package/dist/tools/core/write-file.js.map +1 -0
- package/dist/tools/todo.d.ts +3 -4
- package/dist/tools/todo.d.ts.map +1 -1
- package/dist/tools/todo.js +80 -79
- package/dist/tools/todo.js.map +1 -1
- package/dist/tui-ui/chrome-view-model.js +1 -1
- package/dist/tui-ui/chrome-view-model.js.map +1 -1
- package/dist/tui-ui/layout.js +1 -1
- package/dist/tui-ui/layout.js.map +1 -1
- package/docs/migration/v0.1.9-to-v0.2.0.md +98 -0
- package/docs/orion.example.json +79 -0
- package/docs/plan/v0.2.0-dsh-harness-redesign-plan.md +1234 -0
- package/docs/plan/v0.2.0-release-checklist.md +91 -0
- package/docs/readme.md +8 -8
- package/npm-shrinkwrap.json +45 -450
- package/package.json +17 -13
- package/dist/agents/coder.d.ts +0 -12
- package/dist/agents/coder.d.ts.map +0 -1
- package/dist/agents/coder.js +0 -48
- package/dist/agents/coder.js.map +0 -1
- package/dist/agents/coordinator.d.ts +0 -86
- package/dist/agents/coordinator.d.ts.map +0 -1
- package/dist/agents/coordinator.js +0 -291
- package/dist/agents/coordinator.js.map +0 -1
- package/dist/agents/fork.d.ts +0 -73
- package/dist/agents/fork.d.ts.map +0 -1
- package/dist/agents/fork.js +0 -163
- package/dist/agents/fork.js.map +0 -1
- package/dist/agents/leader.d.ts +0 -12
- package/dist/agents/leader.d.ts.map +0 -1
- package/dist/agents/leader.js +0 -49
- package/dist/agents/leader.js.map +0 -1
- package/dist/agents/router.d.ts +0 -59
- package/dist/agents/router.d.ts.map +0 -1
- package/dist/agents/router.js +0 -193
- package/dist/agents/router.js.map +0 -1
- package/dist/agents/worker-pool.d.ts +0 -72
- package/dist/agents/worker-pool.d.ts.map +0 -1
- package/dist/agents/worker-pool.js +0 -229
- package/dist/agents/worker-pool.js.map +0 -1
- package/dist/commands/legacy-commands.d.ts +0 -4
- package/dist/commands/legacy-commands.d.ts.map +0 -1
- package/dist/commands/legacy-commands.js +0 -44
- package/dist/commands/legacy-commands.js.map +0 -1
- package/dist/core/agent.d.ts +0 -84
- package/dist/core/agent.d.ts.map +0 -1
- package/dist/core/agent.js +0 -58
- package/dist/core/agent.js.map +0 -1
- package/dist/core/brain.d.ts +0 -50
- package/dist/core/brain.d.ts.map +0 -1
- package/dist/core/brain.js +0 -95
- package/dist/core/brain.js.map +0 -1
- package/dist/framework/tool-scheduler.d.ts +0 -191
- package/dist/framework/tool-scheduler.d.ts.map +0 -1
- package/dist/framework/tool-scheduler.js +0 -573
- package/dist/framework/tool-scheduler.js.map +0 -1
- package/dist/harness/harness.d.ts +0 -58
- package/dist/harness/harness.d.ts.map +0 -1
- package/dist/harness/harness.js +0 -195
- package/dist/harness/harness.js.map +0 -1
- package/dist/harness/safety.d.ts +0 -101
- package/dist/harness/safety.d.ts.map +0 -1
- package/dist/harness/safety.js +0 -322
- package/dist/harness/safety.js.map +0 -1
- package/dist/init.d.ts +0 -108
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -393
- package/dist/init.js.map +0 -1
- package/dist/ink-ui/App.d.ts +0 -9
- package/dist/ink-ui/App.d.ts.map +0 -1
- package/dist/ink-ui/App.js +0 -12
- package/dist/ink-ui/App.js.map +0 -1
- package/dist/ink-ui/components/Markdown.d.ts +0 -10
- package/dist/ink-ui/components/Markdown.d.ts.map +0 -1
- package/dist/ink-ui/components/Markdown.js +0 -210
- package/dist/ink-ui/components/Markdown.js.map +0 -1
- package/dist/ink-ui/components/NativeCursor.d.ts +0 -12
- package/dist/ink-ui/components/NativeCursor.d.ts.map +0 -1
- package/dist/ink-ui/components/NativeCursor.js +0 -35
- package/dist/ink-ui/components/NativeCursor.js.map +0 -1
- package/dist/ink-ui/components/PixelHorseBanner.d.ts +0 -8
- package/dist/ink-ui/components/PixelHorseBanner.d.ts.map +0 -1
- package/dist/ink-ui/components/PixelHorseBanner.js +0 -97
- package/dist/ink-ui/components/PixelHorseBanner.js.map +0 -1
- package/dist/ink-ui/components/PromptInput.d.ts +0 -13
- package/dist/ink-ui/components/PromptInput.d.ts.map +0 -1
- package/dist/ink-ui/components/PromptInput.js +0 -30
- package/dist/ink-ui/components/PromptInput.js.map +0 -1
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts +0 -13
- package/dist/ink-ui/components/RunningHorseIndicator.d.ts.map +0 -1
- package/dist/ink-ui/components/RunningHorseIndicator.js +0 -53
- package/dist/ink-ui/components/RunningHorseIndicator.js.map +0 -1
- package/dist/ink-ui/components/SelectList.d.ts +0 -16
- package/dist/ink-ui/components/SelectList.d.ts.map +0 -1
- package/dist/ink-ui/components/SelectList.js +0 -60
- package/dist/ink-ui/components/SelectList.js.map +0 -1
- package/dist/ink-ui/components/StatusLine.d.ts +0 -11
- package/dist/ink-ui/components/StatusLine.d.ts.map +0 -1
- package/dist/ink-ui/components/StatusLine.js +0 -70
- package/dist/ink-ui/components/StatusLine.js.map +0 -1
- package/dist/ink-ui/components/ToolActivity.d.ts +0 -19
- package/dist/ink-ui/components/ToolActivity.d.ts.map +0 -1
- package/dist/ink-ui/components/ToolActivity.js +0 -134
- package/dist/ink-ui/components/ToolActivity.js.map +0 -1
- package/dist/ink-ui/components/Transcript.d.ts +0 -14
- package/dist/ink-ui/components/Transcript.d.ts.map +0 -1
- package/dist/ink-ui/components/Transcript.js +0 -66
- package/dist/ink-ui/components/Transcript.js.map +0 -1
- package/dist/ink-ui/controllers/chat-controller.d.ts +0 -2
- package/dist/ink-ui/controllers/chat-controller.d.ts.map +0 -1
- package/dist/ink-ui/controllers/chat-controller.js.map +0 -1
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts +0 -6
- package/dist/ink-ui/hooks/use-raw-input-bridge.d.ts.map +0 -1
- package/dist/ink-ui/hooks/use-raw-input-bridge.js +0 -27
- package/dist/ink-ui/hooks/use-raw-input-bridge.js.map +0 -1
- package/dist/ink-ui/hooks/use-terminal-size.d.ts +0 -7
- package/dist/ink-ui/hooks/use-terminal-size.d.ts.map +0 -1
- package/dist/ink-ui/hooks/use-terminal-size.js +0 -34
- package/dist/ink-ui/hooks/use-terminal-size.js.map +0 -1
- package/dist/ink-ui/launch.d.ts +0 -9
- package/dist/ink-ui/launch.d.ts.map +0 -1
- package/dist/ink-ui/launch.js +0 -101
- package/dist/ink-ui/launch.js.map +0 -1
- package/dist/ink-ui/runtime/grapheme.d.ts +0 -10
- package/dist/ink-ui/runtime/grapheme.d.ts.map +0 -1
- package/dist/ink-ui/runtime/grapheme.js +0 -17
- package/dist/ink-ui/runtime/grapheme.js.map +0 -1
- package/dist/ink-ui/runtime/input-buffer.d.ts +0 -10
- package/dist/ink-ui/runtime/input-buffer.d.ts.map +0 -1
- package/dist/ink-ui/runtime/input-buffer.js +0 -18
- package/dist/ink-ui/runtime/input-buffer.js.map +0 -1
- package/dist/ink-ui/runtime/layout-budget.d.ts +0 -13
- package/dist/ink-ui/runtime/layout-budget.d.ts.map +0 -1
- package/dist/ink-ui/runtime/layout-budget.js +0 -25
- package/dist/ink-ui/runtime/layout-budget.js.map +0 -1
- package/dist/ink-ui/runtime/native-cursor.d.ts +0 -62
- package/dist/ink-ui/runtime/native-cursor.d.ts.map +0 -1
- package/dist/ink-ui/runtime/native-cursor.js +0 -398
- package/dist/ink-ui/runtime/native-cursor.js.map +0 -1
- package/dist/ink-ui/runtime/prompt-layout.d.ts +0 -10
- package/dist/ink-ui/runtime/prompt-layout.d.ts.map +0 -1
- package/dist/ink-ui/runtime/prompt-layout.js +0 -21
- package/dist/ink-ui/runtime/prompt-layout.js.map +0 -1
- package/dist/ink-ui/runtime/raw-input.d.ts +0 -4
- package/dist/ink-ui/runtime/raw-input.d.ts.map +0 -1
- package/dist/ink-ui/runtime/raw-input.js +0 -15
- package/dist/ink-ui/runtime/raw-input.js.map +0 -1
- package/dist/ink-ui/runtime/transcript-state.d.ts +0 -37
- package/dist/ink-ui/runtime/transcript-state.d.ts.map +0 -1
- package/dist/ink-ui/runtime/transcript-state.js +0 -91
- package/dist/ink-ui/runtime/transcript-state.js.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.d.ts +0 -27
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +0 -1
- package/dist/ink-ui/screens/ReplScreen.js +0 -781
- package/dist/ink-ui/screens/ReplScreen.js.map +0 -1
- package/dist/ink-ui/types.d.ts +0 -2
- package/dist/ink-ui/types.d.ts.map +0 -1
- package/dist/ink-ui/types.js.map +0 -1
- package/dist/runtime/chat-checkpoint.d.ts +0 -17
- package/dist/runtime/chat-checkpoint.d.ts.map +0 -1
- package/dist/runtime/chat-checkpoint.js +0 -105
- package/dist/runtime/chat-checkpoint.js.map +0 -1
- package/dist/runtime/chat-command-scope.d.ts +0 -5
- package/dist/runtime/chat-command-scope.d.ts.map +0 -1
- package/dist/runtime/chat-command-scope.js +0 -22
- package/dist/runtime/chat-command-scope.js.map +0 -1
- package/dist/runtime/chat-compact.d.ts +0 -26
- package/dist/runtime/chat-compact.d.ts.map +0 -1
- package/dist/runtime/chat-compact.js +0 -132
- package/dist/runtime/chat-compact.js.map +0 -1
- package/dist/runtime/chat-controller.d.ts +0 -62
- package/dist/runtime/chat-controller.d.ts.map +0 -1
- package/dist/runtime/chat-controller.js +0 -1620
- package/dist/runtime/chat-controller.js.map +0 -1
- package/dist/runtime/chat-effort.d.ts +0 -5
- package/dist/runtime/chat-effort.d.ts.map +0 -1
- package/dist/runtime/chat-effort.js +0 -47
- package/dist/runtime/chat-effort.js.map +0 -1
- package/dist/runtime/chat-presentation.d.ts +0 -63
- package/dist/runtime/chat-presentation.d.ts.map +0 -1
- package/dist/runtime/chat-presentation.js +0 -561
- package/dist/runtime/chat-presentation.js.map +0 -1
- package/dist/runtime/chat-trace.d.ts +0 -52
- package/dist/runtime/chat-trace.d.ts.map +0 -1
- package/dist/runtime/chat-trace.js +0 -234
- package/dist/runtime/chat-trace.js.map +0 -1
- package/dist/runtime/chat-workspace.d.ts +0 -22
- package/dist/runtime/chat-workspace.d.ts.map +0 -1
- package/dist/runtime/chat-workspace.js +0 -154
- package/dist/runtime/chat-workspace.js.map +0 -1
- package/dist/runtime/goals/accounting.d.ts +0 -45
- package/dist/runtime/goals/accounting.d.ts.map +0 -1
- package/dist/runtime/goals/accounting.js +0 -114
- package/dist/runtime/goals/accounting.js.map +0 -1
- package/dist/runtime/goals/coordinator.d.ts +0 -92
- package/dist/runtime/goals/coordinator.d.ts.map +0 -1
- package/dist/runtime/goals/coordinator.js +0 -1471
- package/dist/runtime/goals/coordinator.js.map +0 -1
- package/dist/runtime/goals/lifecycle.d.ts +0 -13
- package/dist/runtime/goals/lifecycle.d.ts.map +0 -1
- package/dist/runtime/goals/lifecycle.js +0 -46
- package/dist/runtime/goals/lifecycle.js.map +0 -1
- package/dist/runtime/goals/prompt.d.ts +0 -16
- package/dist/runtime/goals/prompt.d.ts.map +0 -1
- package/dist/runtime/goals/prompt.js +0 -88
- package/dist/runtime/goals/prompt.js.map +0 -1
- package/dist/runtime/goals/stop-policy.d.ts +0 -9
- package/dist/runtime/goals/stop-policy.d.ts.map +0 -1
- package/dist/runtime/goals/stop-policy.js +0 -83
- package/dist/runtime/goals/stop-policy.js.map +0 -1
- package/dist/runtime/goals/tools.d.ts +0 -61
- package/dist/runtime/goals/tools.d.ts.map +0 -1
- package/dist/runtime/goals/tools.js +0 -568
- package/dist/runtime/goals/tools.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -10
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -23
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/init.d.ts +0 -24
- package/dist/sdk/init.d.ts.map +0 -1
- package/dist/sdk/init.js +0 -48
- package/dist/sdk/init.js.map +0 -1
- package/dist/sdk/query.d.ts +0 -19
- package/dist/sdk/query.d.ts.map +0 -1
- package/dist/sdk/query.js +0 -42
- package/dist/sdk/query.js.map +0 -1
- package/dist/sdk/sessions.d.ts +0 -19
- package/dist/sdk/sessions.d.ts.map +0 -1
- package/dist/sdk/sessions.js +0 -57
- package/dist/sdk/sessions.js.map +0 -1
- package/dist/sdk/types.d.ts +0 -47
- package/dist/sdk/types.d.ts.map +0 -1
- package/dist/sdk/types.js +0 -8
- package/dist/sdk/types.js.map +0 -1
- package/dist/services/agent-runner.d.ts +0 -71
- package/dist/services/agent-runner.d.ts.map +0 -1
- package/dist/services/agent-runner.js +0 -185
- package/dist/services/agent-runner.js.map +0 -1
- package/dist/services/task-manager.d.ts +0 -161
- package/dist/services/task-manager.d.ts.map +0 -1
- package/dist/services/task-manager.js +0 -315
- package/dist/services/task-manager.js.map +0 -1
- package/dist/skills/discovery.d.ts +0 -22
- package/dist/skills/discovery.d.ts.map +0 -1
- package/dist/skills/discovery.js +0 -75
- package/dist/skills/discovery.js.map +0 -1
- package/dist/skills/index.d.ts +0 -11
- package/dist/skills/index.d.ts.map +0 -1
- package/dist/skills/index.js.map +0 -1
- package/dist/skills/loader.d.ts +0 -53
- package/dist/skills/loader.d.ts.map +0 -1
- package/dist/skills/loader.js +0 -421
- package/dist/skills/loader.js.map +0 -1
- package/dist/skills/registry.d.ts +0 -41
- package/dist/skills/registry.d.ts.map +0 -1
- package/dist/skills/registry.js +0 -157
- package/dist/skills/registry.js.map +0 -1
- package/dist/skills/runtime.d.ts +0 -46
- package/dist/skills/runtime.d.ts.map +0 -1
- package/dist/skills/runtime.js +0 -363
- package/dist/skills/runtime.js.map +0 -1
- package/dist/skills/types.d.ts +0 -112
- package/dist/skills/types.d.ts.map +0 -1
- package/dist/skills/types.js +0 -24
- package/dist/skills/types.js.map +0 -1
- package/dist/tools/index.d.ts +0 -52
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -2268
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/mcp.d.ts +0 -99
- package/dist/tools/mcp.d.ts.map +0 -1
- package/dist/tools/mcp.js +0 -695
- package/dist/tools/mcp.js.map +0 -1
- package/dist/tools/plan.d.ts +0 -17
- package/dist/tools/plan.d.ts.map +0 -1
- package/dist/tools/plan.js +0 -84
- package/dist/tools/plan.js.map +0 -1
- package/docs/migration/v0.1.8-to-v0.1.9.md +0 -60
- package/docs/plan/v0.1.9-release-checklist.md +0 -64
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coreTool = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const tool_1 = require("../../framework/tool");
|
|
6
|
+
const descriptors_1 = require("../../runtime/core-tools/descriptors");
|
|
7
|
+
const errors_1 = require("../../utils/errors");
|
|
8
|
+
const common_1 = require("./common");
|
|
9
|
+
const descriptor = (0, descriptors_1.coreToolDescriptorV1)('edit_file');
|
|
10
|
+
exports.coreTool = (0, tool_1.buildTool)({
|
|
11
|
+
name: descriptor.name,
|
|
12
|
+
aliases: [...descriptor.aliases],
|
|
13
|
+
description: descriptor.description,
|
|
14
|
+
parameters: structuredClone(descriptor.parameters),
|
|
15
|
+
execute: async (args, context) => {
|
|
16
|
+
// Ensure required parameters are valid strings
|
|
17
|
+
const path = args.path;
|
|
18
|
+
const old_string = args.old_string;
|
|
19
|
+
const new_string = args.new_string;
|
|
20
|
+
if (!path || typeof path !== 'string') {
|
|
21
|
+
return { success: false, output: '', error: 'edit_file requires a path parameter' };
|
|
22
|
+
}
|
|
23
|
+
if (!old_string || typeof old_string !== 'string') {
|
|
24
|
+
return { success: false, output: '', error: 'edit_file requires an old_string parameter' };
|
|
25
|
+
}
|
|
26
|
+
if (typeof new_string !== 'string') {
|
|
27
|
+
return { success: false, output: '', error: 'edit_file requires a new_string parameter' };
|
|
28
|
+
}
|
|
29
|
+
return editFile_(path, old_string, new_string, args.replace_all, args.fuzzy_match, args.preview, context.cwd);
|
|
30
|
+
},
|
|
31
|
+
isDestructive: () => true,
|
|
32
|
+
isFileEdit: () => true,
|
|
33
|
+
checkPermissions: (_args, _context) => {
|
|
34
|
+
return { behavior: 'ask', reason: 'Edit operation modifies file contents' };
|
|
35
|
+
},
|
|
36
|
+
userFacingName: args => `Edit ${args.path}`,
|
|
37
|
+
getSummary: (args, result) => {
|
|
38
|
+
const path = args.path;
|
|
39
|
+
if (!result.success)
|
|
40
|
+
return `✏️ edit ${path} → error`;
|
|
41
|
+
const replaceAll = args.replace_all ? ' (all)' : '';
|
|
42
|
+
return `✏️ edit ${path}${replaceAll}`;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
function lineNumberForIndex(content, index) {
|
|
46
|
+
return content.slice(0, Math.max(0, index)).split('\n').length;
|
|
47
|
+
}
|
|
48
|
+
function findAllMatchIndexes(content, needle, limit = 20) {
|
|
49
|
+
const indexes = [];
|
|
50
|
+
let cursor = 0;
|
|
51
|
+
while (indexes.length < limit) {
|
|
52
|
+
const index = content.indexOf(needle, cursor);
|
|
53
|
+
if (index < 0)
|
|
54
|
+
break;
|
|
55
|
+
indexes.push(index);
|
|
56
|
+
cursor = index + Math.max(needle.length, 1);
|
|
57
|
+
}
|
|
58
|
+
return indexes;
|
|
59
|
+
}
|
|
60
|
+
function previewLine(text) {
|
|
61
|
+
return text.replace(/\s+/g, ' ').trim().slice(0, 120);
|
|
62
|
+
}
|
|
63
|
+
function buildEditCandidates(params) {
|
|
64
|
+
const cursorByMatch = new Map();
|
|
65
|
+
return params.matches.slice(0, 20).map((match, index) => {
|
|
66
|
+
const cursor = cursorByMatch.get(match) ?? 0;
|
|
67
|
+
const matchIndex = params.content.indexOf(match, cursor);
|
|
68
|
+
cursorByMatch.set(match, matchIndex >= 0 ? matchIndex + Math.max(match.length, 1) : cursor);
|
|
69
|
+
const lineNum = matchIndex >= 0 ? lineNumberForIndex(params.content, matchIndex) : 0;
|
|
70
|
+
// Get context lines (3 before, 3 after)
|
|
71
|
+
const allLines = params.content.split('\n');
|
|
72
|
+
const contextBefore = allLines.slice(Math.max(0, lineNum - 4), lineNum).join('\n');
|
|
73
|
+
const contextAfter = allLines.slice(lineNum + 1, lineNum + 4).join('\n');
|
|
74
|
+
return {
|
|
75
|
+
index,
|
|
76
|
+
line: lineNum,
|
|
77
|
+
match,
|
|
78
|
+
contextBefore,
|
|
79
|
+
contextAfter,
|
|
80
|
+
isReplaceAll: (params.count ?? 1) > 1,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function formatEditPreview(params) {
|
|
85
|
+
const cursorByMatch = new Map();
|
|
86
|
+
const lines = [
|
|
87
|
+
`Preview: ${params.kind === 'fuzzy' ? `Fuzzy ${params.strategy ?? 'match'}` : 'Exact match'} candidates (${params.matches.length})`,
|
|
88
|
+
];
|
|
89
|
+
params.matches.slice(0, 20).forEach((match, index) => {
|
|
90
|
+
const cursor = cursorByMatch.get(match) ?? 0;
|
|
91
|
+
const matchIndex = params.content.indexOf(match, cursor);
|
|
92
|
+
cursorByMatch.set(match, matchIndex >= 0 ? matchIndex + Math.max(match.length, 1) : cursor);
|
|
93
|
+
const lineNum = matchIndex >= 0 ? lineNumberForIndex(params.content, matchIndex) : '?';
|
|
94
|
+
lines.push(`${index + 1}. line ${lineNum}: "${previewLine(match)}"`);
|
|
95
|
+
});
|
|
96
|
+
if (params.matches.length > 20) {
|
|
97
|
+
lines.push(`... ${params.matches.length - 20} more candidates omitted`);
|
|
98
|
+
}
|
|
99
|
+
lines.push(`Would replace with: "${previewLine(params.newString)}"`);
|
|
100
|
+
return lines.join('\n');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Attempt to find old_string in content using fuzzy matching strategies.
|
|
104
|
+
* Returns null if no match found, or the matched strings.
|
|
105
|
+
*/
|
|
106
|
+
function fuzzyMatch(content, oldString) {
|
|
107
|
+
// Strategy 1: Line-by-line matching (allow different indentation)
|
|
108
|
+
const oldLines = oldString
|
|
109
|
+
.split('\n')
|
|
110
|
+
.map(l => l.trim())
|
|
111
|
+
.filter(Boolean);
|
|
112
|
+
const contentLines = content.split('\n');
|
|
113
|
+
const lineMatches = [];
|
|
114
|
+
for (let i = 0; i <= contentLines.length - oldLines.length; i++) {
|
|
115
|
+
let allMatch = true;
|
|
116
|
+
for (let j = 0; j < oldLines.length; j++) {
|
|
117
|
+
if (contentLines[i + j].trim() !== oldLines[j]) {
|
|
118
|
+
allMatch = false;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (allMatch) {
|
|
123
|
+
const matchedStr = contentLines.slice(i, i + oldLines.length).join('\n');
|
|
124
|
+
lineMatches.push(matchedStr);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (lineMatches.length > 0) {
|
|
128
|
+
return { matches: lineMatches, strategy: 'line' };
|
|
129
|
+
}
|
|
130
|
+
// Strategy 2: Whitespace-tolerant token match. This preserves the actual
|
|
131
|
+
// matched span without consuming unrelated leading/trailing blank lines.
|
|
132
|
+
const tokens = oldString.trim().split(/\s+/).filter(Boolean);
|
|
133
|
+
if (tokens.length === 0)
|
|
134
|
+
return null;
|
|
135
|
+
const pattern = tokens.map(escapeRegExp).join('\\s+');
|
|
136
|
+
const regex = new RegExp(pattern, 'g');
|
|
137
|
+
const wsMatches = [];
|
|
138
|
+
let match;
|
|
139
|
+
while ((match = regex.exec(content)) !== null) {
|
|
140
|
+
if (match[0]) {
|
|
141
|
+
wsMatches.push(match[0]);
|
|
142
|
+
}
|
|
143
|
+
if (wsMatches.length > 5)
|
|
144
|
+
break; // Safety limit
|
|
145
|
+
if (match.index === regex.lastIndex)
|
|
146
|
+
regex.lastIndex++;
|
|
147
|
+
}
|
|
148
|
+
if (wsMatches.length > 0) {
|
|
149
|
+
return { matches: wsMatches, strategy: 'whitespace' };
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
async function editFile_(path, old_string, new_string, replace_all, fuzzy_match, preview, cwd) {
|
|
154
|
+
try {
|
|
155
|
+
const normalizedPath = (0, common_1.normalizeToolPath)(path);
|
|
156
|
+
const resolved = (0, common_1.safePath)(path, cwd);
|
|
157
|
+
const workspaceRoot = cwd ?? process.cwd();
|
|
158
|
+
if (!(0, common_1.isWithinWorkspace)(resolved, workspaceRoot)) {
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
output: '',
|
|
162
|
+
error: `Refusing to edit outside the workspace: ${normalizedPath}`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (!(0, fs_1.existsSync)(resolved)) {
|
|
166
|
+
return { success: false, output: '', error: `File not found: ${normalizedPath}` };
|
|
167
|
+
}
|
|
168
|
+
const fileStat = (0, common_1.safeStatSync)(resolved);
|
|
169
|
+
if (!fileStat) {
|
|
170
|
+
return {
|
|
171
|
+
success: false,
|
|
172
|
+
output: '',
|
|
173
|
+
error: `Cannot access file: ${normalizedPath} (may be a dangling symlink)`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (fileStat.isDirectory()) {
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
output: '',
|
|
180
|
+
error: `Path is a directory, not a file: ${normalizedPath}`,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const content = (0, common_1.safeReadFileSync)(resolved);
|
|
184
|
+
if (content === null) {
|
|
185
|
+
return { success: false, output: '', error: `Cannot read file: ${normalizedPath}` };
|
|
186
|
+
}
|
|
187
|
+
// Check if old_string exists exactly
|
|
188
|
+
const count = (content.match(new RegExp(escapeRegExp(old_string), 'g')) || []).length;
|
|
189
|
+
if (count > 0 && preview) {
|
|
190
|
+
const matchIndexes = findAllMatchIndexes(content, old_string);
|
|
191
|
+
const matches = matchIndexes.map(() => old_string);
|
|
192
|
+
return {
|
|
193
|
+
success: true,
|
|
194
|
+
output: formatEditPreview({
|
|
195
|
+
kind: 'exact',
|
|
196
|
+
content,
|
|
197
|
+
matches,
|
|
198
|
+
newString: new_string,
|
|
199
|
+
}),
|
|
200
|
+
metadata: {
|
|
201
|
+
candidates: buildEditCandidates({
|
|
202
|
+
kind: 'exact',
|
|
203
|
+
content,
|
|
204
|
+
matches,
|
|
205
|
+
newString: new_string,
|
|
206
|
+
count,
|
|
207
|
+
}),
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (count === 0) {
|
|
212
|
+
if (!fuzzy_match) {
|
|
213
|
+
return {
|
|
214
|
+
success: false,
|
|
215
|
+
output: '',
|
|
216
|
+
error: `old_string not found in file: ${old_string.slice(0, 100)}...`,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
// Try fuzzy match strategies
|
|
220
|
+
const fuzzyResult = fuzzyMatch(content, old_string);
|
|
221
|
+
if (fuzzyResult === null) {
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
output: '',
|
|
225
|
+
error: `old_string not found in file: ${old_string.slice(0, 100)}...`,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (preview) {
|
|
229
|
+
return {
|
|
230
|
+
success: true,
|
|
231
|
+
output: formatEditPreview({
|
|
232
|
+
kind: 'fuzzy',
|
|
233
|
+
content,
|
|
234
|
+
matches: fuzzyResult.matches,
|
|
235
|
+
newString: new_string,
|
|
236
|
+
strategy: fuzzyResult.strategy,
|
|
237
|
+
}),
|
|
238
|
+
metadata: {
|
|
239
|
+
candidates: buildEditCandidates({
|
|
240
|
+
kind: 'fuzzy',
|
|
241
|
+
content,
|
|
242
|
+
matches: fuzzyResult.matches,
|
|
243
|
+
newString: new_string,
|
|
244
|
+
strategy: fuzzyResult.strategy,
|
|
245
|
+
}),
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (fuzzyResult.matches.length > 1) {
|
|
250
|
+
return {
|
|
251
|
+
success: false,
|
|
252
|
+
output: '',
|
|
253
|
+
error: `Fuzzy match found ${fuzzyResult.matches.length} candidates. Provide a more specific string. First 3 candidates:\n${fuzzyResult.matches
|
|
254
|
+
.slice(0, 3)
|
|
255
|
+
.map((m, i) => ` ${i + 1}: "${m.slice(0, 80)}..."`)
|
|
256
|
+
.join('\n')}`,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
// Use the single fuzzy match only.
|
|
260
|
+
const match = fuzzyResult.matches[0];
|
|
261
|
+
const idx = content.indexOf(match);
|
|
262
|
+
const newContent = content.slice(0, idx) + new_string + content.slice(idx + match.length);
|
|
263
|
+
(0, fs_1.writeFileSync)(resolved, newContent, 'utf-8');
|
|
264
|
+
return {
|
|
265
|
+
success: true,
|
|
266
|
+
output: `Fuzzy edited ${normalizedPath} (matched by ${fuzzyResult.strategy}, "${match.slice(0, 50)}...")`,
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
// If not replace_all, require unique match
|
|
270
|
+
if (!replace_all && count > 1) {
|
|
271
|
+
return {
|
|
272
|
+
success: false,
|
|
273
|
+
output: '',
|
|
274
|
+
error: `old_string found ${count} times in file. Use replace_all=true to replace all occurrences, or provide a more specific string that matches exactly once.`,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
// Perform replacement
|
|
278
|
+
let newContent;
|
|
279
|
+
if (replace_all) {
|
|
280
|
+
newContent = content.split(old_string).join(new_string);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// Replace first occurrence only
|
|
284
|
+
const idx = content.indexOf(old_string);
|
|
285
|
+
newContent = content.slice(0, idx) + new_string + content.slice(idx + old_string.length);
|
|
286
|
+
}
|
|
287
|
+
(0, fs_1.writeFileSync)(resolved, newContent, 'utf-8');
|
|
288
|
+
return {
|
|
289
|
+
success: true,
|
|
290
|
+
output: `Replaced ${count} occurrence(s) of old_string with new_string in ${normalizedPath}`,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
return { success: false, output: '', error: (0, errors_1.errorMessage)(err) };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/** Escape special regex characters for literal matching */
|
|
298
|
+
function escapeRegExp(str) {
|
|
299
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=edit-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-file.js","sourceRoot":"","sources":["../../../src/tools/core/edit-file.ts"],"names":[],"mappings":";;;AAAA,2BAA+C;AAE/C,+CAAkE;AAClE,sEAA4E;A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,CAAC,CAAC;QAC3F,CAAC;QAED,IAAA,kBAAa,EAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QAE7C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,YAAY,KAAK,mDAAmD,cAAc,EAAE;SAC7F,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,IAAA,qBAAY,EAAC,GAAG,CAAC,EAAE,CAAC;IAClE,CAAC;AACH,CAAC;AAED,2DAA2D;AAC3D,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-command.d.ts","sourceRoot":"","sources":["../../../src/tools/core/exec-command.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,QAAQ,8CAmHnB,CAAC"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coreTool = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const tool_1 = require("../../framework/tool");
|
|
8
|
+
const descriptors_1 = require("../../runtime/core-tools/descriptors");
|
|
9
|
+
const bash_security_1 = require("../bash_security");
|
|
10
|
+
const sandbox_1 = require("../sandbox");
|
|
11
|
+
const common_1 = require("./common");
|
|
12
|
+
const EXEC_COMMAND_MIN_TIMEOUT_MS = 1;
|
|
13
|
+
const EXEC_COMMAND_MAX_TIMEOUT_MS = 600000;
|
|
14
|
+
const EXEC_COMMAND_MIN_OUTPUT_BYTES = 1024;
|
|
15
|
+
const EXEC_COMMAND_MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
16
|
+
const descriptor = (0, descriptors_1.coreToolDescriptorV1)('exec_command');
|
|
17
|
+
exports.coreTool = (0, tool_1.buildTool)({
|
|
18
|
+
name: descriptor.name,
|
|
19
|
+
aliases: [...descriptor.aliases],
|
|
20
|
+
description: descriptor.description,
|
|
21
|
+
parameters: structuredClone(descriptor.parameters),
|
|
22
|
+
execute: async (args, context) => {
|
|
23
|
+
// Ensure command is a valid string
|
|
24
|
+
const command = args.command;
|
|
25
|
+
if (!command || typeof command !== 'string') {
|
|
26
|
+
return { success: false, output: '', error: 'exec_command requires a command parameter' };
|
|
27
|
+
}
|
|
28
|
+
// Issue #32 #3.2: 传递 abortSignal
|
|
29
|
+
return execCommand_(command, args.cwd, args.timeout, args.maxOutput, context.abortSignal, context.cwd);
|
|
30
|
+
},
|
|
31
|
+
validateInput: args => (0, common_1.validateOptionalSafeInteger)(args, 'exec_command', 'timeout', EXEC_COMMAND_MIN_TIMEOUT_MS, EXEC_COMMAND_MAX_TIMEOUT_MS) ??
|
|
32
|
+
(0, common_1.validateOptionalSafeInteger)(args, 'exec_command', 'maxOutput', EXEC_COMMAND_MIN_OUTPUT_BYTES, EXEC_COMMAND_MAX_OUTPUT_BYTES),
|
|
33
|
+
isDestructive: args => {
|
|
34
|
+
const cmd = args.command || '';
|
|
35
|
+
return (0, bash_security_1.containsRecursiveRm)(cmd) || /(?:^|[;&|]\s*)(?:[^\s]+\/)?(?:mkfs|dd)(?:\s|$)/.test(cmd);
|
|
36
|
+
},
|
|
37
|
+
checkPermissions: (args, context) => {
|
|
38
|
+
const cmd = args.command || '';
|
|
39
|
+
// Use the bash_security module for comprehensive checks
|
|
40
|
+
const security = (0, bash_security_1.assessCommandSecurity)(cmd);
|
|
41
|
+
if (security.level === 'blocked') {
|
|
42
|
+
return {
|
|
43
|
+
behavior: 'deny',
|
|
44
|
+
reason: security.reason || `Command blocked by safety policy: ${cmd.slice(0, 50)}`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// v0.1.3-2 §1.2: a configured-but-unusable sandbox is a hard deny, decided
|
|
48
|
+
// here so the user sees the reason instead of an opaque execution failure.
|
|
49
|
+
let paths;
|
|
50
|
+
try {
|
|
51
|
+
paths = resolveExecCommandPaths(args.cwd, context?.cwd);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
behavior: 'deny',
|
|
56
|
+
reason: error instanceof Error ? error.message : 'exec_command cwd is outside workspace',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const { workdir, projectRoot } = paths;
|
|
60
|
+
const sandboxSettings = (0, sandbox_1.resolveSandboxSettings)(projectRoot);
|
|
61
|
+
let sandboxNote = '';
|
|
62
|
+
if ((sandboxSettings.profile ?? 'none') !== 'none') {
|
|
63
|
+
const plan = (0, sandbox_1.planSandboxedCommand)(cmd, {
|
|
64
|
+
cwd: workdir,
|
|
65
|
+
projectRoot,
|
|
66
|
+
settings: sandboxSettings,
|
|
67
|
+
});
|
|
68
|
+
if (!plan.ok) {
|
|
69
|
+
return {
|
|
70
|
+
behavior: 'deny',
|
|
71
|
+
reason: `sandbox profile "${plan.profile}" is configured but cannot be applied — ${plan.reason}`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
sandboxNote = ` [${(0, sandbox_1.describeSandboxPlan)(plan)}]`;
|
|
75
|
+
}
|
|
76
|
+
if (security.level === 'safe' && security.isReadOnly) {
|
|
77
|
+
return { behavior: 'allow' };
|
|
78
|
+
}
|
|
79
|
+
if (security.level === 'caution') {
|
|
80
|
+
return {
|
|
81
|
+
behavior: 'ask',
|
|
82
|
+
reason: (security.reason || 'Command requires confirmation') + sandboxNote,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// Default: ask for confirmation
|
|
86
|
+
return { behavior: 'ask', reason: 'Command requires confirmation' + sandboxNote };
|
|
87
|
+
},
|
|
88
|
+
isReadOnly: args => {
|
|
89
|
+
const cmd = args.command || '';
|
|
90
|
+
return (0, bash_security_1.isReadOnlyCommand)(cmd);
|
|
91
|
+
},
|
|
92
|
+
isConcurrencySafe: args => {
|
|
93
|
+
const cmd = args.command || '';
|
|
94
|
+
return (0, bash_security_1.isReadOnlyCommand)(cmd);
|
|
95
|
+
},
|
|
96
|
+
userFacingName: args => `Exec ${(0, common_1.compactOneLine)(args.command || '', 80)}`,
|
|
97
|
+
getSummary: (args, result) => {
|
|
98
|
+
const command = args.command || '';
|
|
99
|
+
const commandSummary = command ? `\n $ ${(0, common_1.compactOneLine)(command, 160)}` : '';
|
|
100
|
+
if (!result.success) {
|
|
101
|
+
const detail = (0, common_1.summarizeFailedToolResult)(result);
|
|
102
|
+
return `🔧 exec → error${detail ? ` (${detail})` : ''}${commandSummary}`;
|
|
103
|
+
}
|
|
104
|
+
const bytes = Buffer.byteLength(result.output, 'utf8');
|
|
105
|
+
return `🔧 exec (${bytes}B output)${commandSummary}`;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
// Issue #32 #3.2: execCommand_ 支持 abortSignal
|
|
109
|
+
function resolveExecCommandPaths(cwd, baseCwd) {
|
|
110
|
+
const projectRoot = (0, path_1.resolve)(baseCwd ?? process.cwd());
|
|
111
|
+
if (!cwd)
|
|
112
|
+
return { workdir: projectRoot, projectRoot };
|
|
113
|
+
const normalizedCwd = (0, common_1.normalizeToolPath)(cwd);
|
|
114
|
+
if ((0, path_1.isAbsolute)(normalizedCwd)) {
|
|
115
|
+
throw new Error('exec_command cwd must be a workspace-relative path');
|
|
116
|
+
}
|
|
117
|
+
const workdir = (0, common_1.safePath)(normalizedCwd, projectRoot);
|
|
118
|
+
if (!(0, common_1.isExecCwdWithinWorkspace)(workdir, projectRoot)) {
|
|
119
|
+
throw new Error('exec_command cwd must stay within the workspace');
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
workdir,
|
|
123
|
+
projectRoot,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async function execCommand_(command, cwd, timeout, maxOutput, abortSignal, baseCwd, sandbox) {
|
|
127
|
+
let paths;
|
|
128
|
+
try {
|
|
129
|
+
paths = resolveExecCommandPaths(cwd, baseCwd);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return {
|
|
133
|
+
success: false,
|
|
134
|
+
output: '',
|
|
135
|
+
error: error instanceof Error ? error.message : 'exec_command cwd is outside workspace',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const { workdir, projectRoot } = paths;
|
|
139
|
+
// v0.1.3-2 §1.2: plan the (possibly sandboxed) argv before spawning. A
|
|
140
|
+
// configured sandbox that cannot be honoured must refuse the command rather
|
|
141
|
+
// than silently degrade into an unsandboxed run.
|
|
142
|
+
const plan = (0, sandbox_1.planSandboxedCommand)(command, {
|
|
143
|
+
cwd: workdir,
|
|
144
|
+
projectRoot,
|
|
145
|
+
settings: sandbox ?? (0, sandbox_1.resolveSandboxSettings)(projectRoot),
|
|
146
|
+
});
|
|
147
|
+
if (!plan.ok) {
|
|
148
|
+
return {
|
|
149
|
+
success: false,
|
|
150
|
+
output: '',
|
|
151
|
+
error: `Refusing to run: sandbox profile "${plan.profile}" is configured but cannot be applied — ${plan.reason}. ` +
|
|
152
|
+
'Set sandbox.profile to "none" to run without isolation.',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return new Promise(resolve => {
|
|
156
|
+
const timeoutMs = timeout ?? 30000;
|
|
157
|
+
const maxBytes = maxOutput ?? 51200; // Default 50KB, Issue #28 fix
|
|
158
|
+
// The docker backend bind-mounts `workdir` into the container; the host
|
|
159
|
+
// directory must exist at container-creation time or the mount fails with a
|
|
160
|
+
// confusing "nonexistent directory" error. Create it deterministically
|
|
161
|
+
// rather than relying on docker to materialise it.
|
|
162
|
+
if (plan.backend === 'docker') {
|
|
163
|
+
try {
|
|
164
|
+
(0, fs_1.mkdirSync)(workdir, { recursive: true });
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// If it cannot be created we let the spawn fail with a clear error.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Use spawn for streaming output with truncation support. The user command
|
|
171
|
+
// is a single argv element, so no intermediate shell re-parses it.
|
|
172
|
+
const useProcessGroup = process.platform !== 'win32';
|
|
173
|
+
const child = (0, child_process_1.spawn)(plan.file, plan.args, {
|
|
174
|
+
cwd: workdir,
|
|
175
|
+
detached: useProcessGroup,
|
|
176
|
+
});
|
|
177
|
+
// Issue #53: exec_command runs a complete command as a single argv element
|
|
178
|
+
// and never pipes input into it. If stdin stays open, stdin-reading commands
|
|
179
|
+
// (cat, sort, grep, `python3 -`, ...) block waiting for EOF until the timeout.
|
|
180
|
+
// Close it immediately so the child receives EOF and can proceed.
|
|
181
|
+
child.stdin?.end();
|
|
182
|
+
let stdoutData = '';
|
|
183
|
+
let stderrData = '';
|
|
184
|
+
let stdoutTruncated = false;
|
|
185
|
+
let stderrTruncated = false;
|
|
186
|
+
// Issue #32 修复:使用独立计数器
|
|
187
|
+
let stdoutBytes = 0;
|
|
188
|
+
let stderrBytes = 0;
|
|
189
|
+
let interrupted = null;
|
|
190
|
+
// Issue #32 #3.2: AbortSignal 处理
|
|
191
|
+
// Declared uninitialized on purpose: `finish()` below closes over it before the
|
|
192
|
+
// `timeoutId = setTimeout(...)` assignment. `const` without an initializer is a
|
|
193
|
+
// compile error (TS1155), and inlining the assignment would put it in the closure's TDZ.
|
|
194
|
+
// eslint-disable-next-line prefer-const
|
|
195
|
+
let timeoutId;
|
|
196
|
+
let killTimerId;
|
|
197
|
+
let settled = false;
|
|
198
|
+
const finish = (result) => {
|
|
199
|
+
if (settled)
|
|
200
|
+
return;
|
|
201
|
+
settled = true;
|
|
202
|
+
if (timeoutId)
|
|
203
|
+
clearTimeout(timeoutId);
|
|
204
|
+
if (killTimerId)
|
|
205
|
+
clearTimeout(killTimerId);
|
|
206
|
+
if (abortSignal) {
|
|
207
|
+
abortSignal.removeEventListener('abort', abortHandler);
|
|
208
|
+
}
|
|
209
|
+
resolve(result);
|
|
210
|
+
};
|
|
211
|
+
const terminateChild = () => {
|
|
212
|
+
if (!child.pid || child.killed)
|
|
213
|
+
return;
|
|
214
|
+
try {
|
|
215
|
+
if (useProcessGroup) {
|
|
216
|
+
process.kill(-child.pid, 'SIGTERM');
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
child.kill('SIGTERM');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
child.kill('SIGTERM');
|
|
224
|
+
}
|
|
225
|
+
killTimerId = setTimeout(() => {
|
|
226
|
+
if (!child.pid || child.killed || settled)
|
|
227
|
+
return;
|
|
228
|
+
try {
|
|
229
|
+
if (useProcessGroup) {
|
|
230
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
child.kill('SIGKILL');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
child.kill('SIGKILL');
|
|
238
|
+
}
|
|
239
|
+
}, 500);
|
|
240
|
+
killTimerId.unref?.();
|
|
241
|
+
};
|
|
242
|
+
const abortHandler = () => {
|
|
243
|
+
interrupted = 'aborted';
|
|
244
|
+
terminateChild();
|
|
245
|
+
};
|
|
246
|
+
if (abortSignal) {
|
|
247
|
+
abortSignal.addEventListener('abort', abortHandler);
|
|
248
|
+
if (abortSignal.aborted) {
|
|
249
|
+
abortHandler();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Timeout handling
|
|
253
|
+
timeoutId = setTimeout(() => {
|
|
254
|
+
if (!interrupted) {
|
|
255
|
+
interrupted = 'timeout';
|
|
256
|
+
terminateChild();
|
|
257
|
+
}
|
|
258
|
+
}, timeoutMs);
|
|
259
|
+
// Stream stdout with truncation
|
|
260
|
+
child.stdout.on('data', (data) => {
|
|
261
|
+
if (!stdoutTruncated) {
|
|
262
|
+
const chunk = data.toString();
|
|
263
|
+
// Issue #30: count UTF-8 bytes, not UTF-16 code units, so CJK/emoji
|
|
264
|
+
// output is bounded by `maxBytes` (a UTF-16 count could exceed it ~2x).
|
|
265
|
+
const chunkBytes = Buffer.byteLength(chunk, 'utf8');
|
|
266
|
+
if (stdoutBytes + chunkBytes > maxBytes) {
|
|
267
|
+
stdoutTruncated = true;
|
|
268
|
+
const room = Math.max(0, maxBytes - stdoutBytes);
|
|
269
|
+
// Byte-accurate truncation that respects multi-byte character boundaries.
|
|
270
|
+
stdoutData += (0, common_1.truncateToBytes)(chunk, room).text;
|
|
271
|
+
stdoutBytes = maxBytes;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
stdoutData += chunk;
|
|
275
|
+
stdoutBytes += chunkBytes;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
// Stream stderr with truncation (Issue #32 修复:使用独立计数器)
|
|
280
|
+
child.stderr.on('data', (data) => {
|
|
281
|
+
if (!stderrTruncated) {
|
|
282
|
+
const chunk = data.toString();
|
|
283
|
+
// Issue #30: count UTF-8 bytes, not UTF-16 code units.
|
|
284
|
+
const chunkBytes = Buffer.byteLength(chunk, 'utf8');
|
|
285
|
+
if (stderrBytes + chunkBytes > maxBytes) {
|
|
286
|
+
stderrTruncated = true;
|
|
287
|
+
const room = Math.max(0, maxBytes - stderrBytes);
|
|
288
|
+
stderrData += (0, common_1.truncateToBytes)(chunk, room).text;
|
|
289
|
+
stderrBytes = maxBytes;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
stderrData += chunk;
|
|
293
|
+
stderrBytes += chunkBytes;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
child.on('close', code => {
|
|
298
|
+
if (interrupted === 'aborted') {
|
|
299
|
+
finish({
|
|
300
|
+
success: false,
|
|
301
|
+
output: (0, common_1.truncateToBytes)(stdoutData, maxBytes).text,
|
|
302
|
+
error: 'Command aborted by user',
|
|
303
|
+
});
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (interrupted === 'timeout') {
|
|
307
|
+
finish({
|
|
308
|
+
success: false,
|
|
309
|
+
output: (0, common_1.truncateToBytes)(stdoutData, maxBytes).text,
|
|
310
|
+
error: `Command timed out after ${timeoutMs}ms`,
|
|
311
|
+
});
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const output = stdoutData.trim();
|
|
315
|
+
const errOutput = stderrData.trim();
|
|
316
|
+
// Add truncation notice if output was truncated
|
|
317
|
+
let finalOutput = output;
|
|
318
|
+
if (stdoutTruncated) {
|
|
319
|
+
finalOutput += '\n\n[... output truncated, exceeded 50KB limit]';
|
|
320
|
+
}
|
|
321
|
+
if (code !== 0) {
|
|
322
|
+
finish({
|
|
323
|
+
success: false,
|
|
324
|
+
output: finalOutput || errOutput,
|
|
325
|
+
error: `Command exited with code ${code}`,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
finish({
|
|
330
|
+
success: true,
|
|
331
|
+
output: finalOutput || '(no output)',
|
|
332
|
+
error: stderrTruncated
|
|
333
|
+
? errOutput + '\n\n[... stderr truncated]'
|
|
334
|
+
: errOutput || undefined,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
child.on('error', err => {
|
|
339
|
+
finish({
|
|
340
|
+
success: false,
|
|
341
|
+
output: '',
|
|
342
|
+
error: err.message,
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=exec-command.js.map
|