@useconvoy/cli 0.48.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 +90 -0
- package/README.md +495 -0
- package/dist/bin/convoy.d.ts +2 -0
- package/dist/bin/convoy.js +129 -0
- package/dist/bin/convoy.js.map +1 -0
- package/dist/marketplace/.claude-plugin/marketplace.json +14 -0
- package/dist/marketplace/opensana/.claude-plugin/plugin.json +5 -0
- package/dist/marketplace/opensana/README.md +90 -0
- package/dist/marketplace/opensana/skills/tasks/SKILL.md +133 -0
- package/dist/marketplace/opensana/skills/tasks/references/mcp-setup.md +164 -0
- package/dist/src/agent/app/chunk-flush-buffer.d.ts +35 -0
- package/dist/src/agent/app/chunk-flush-buffer.js +133 -0
- package/dist/src/agent/app/chunk-flush-buffer.js.map +1 -0
- package/dist/src/agent/app/chunk-scrub.d.ts +9 -0
- package/dist/src/agent/app/chunk-scrub.js +120 -0
- package/dist/src/agent/app/chunk-scrub.js.map +1 -0
- package/dist/src/agent/app/interaction-router.d.ts +16 -0
- package/dist/src/agent/app/interaction-router.js +29 -0
- package/dist/src/agent/app/interaction-router.js.map +1 -0
- package/dist/src/agent/app/runner.d.ts +41 -0
- package/dist/src/agent/app/runner.js +353 -0
- package/dist/src/agent/app/runner.js.map +1 -0
- package/dist/src/agent/app/runtime-config.d.ts +3 -0
- package/dist/src/agent/app/runtime-config.js +4 -0
- package/dist/src/agent/app/runtime-config.js.map +1 -0
- package/dist/src/agent/app/thread-attachment-cache.d.ts +17 -0
- package/dist/src/agent/app/thread-attachment-cache.js +124 -0
- package/dist/src/agent/app/thread-attachment-cache.js.map +1 -0
- package/dist/src/agent/app/thread-processor.d.ts +40 -0
- package/dist/src/agent/app/thread-processor.js +792 -0
- package/dist/src/agent/app/thread-processor.js.map +1 -0
- package/dist/src/agent/app/worktree-op-processor.d.ts +27 -0
- package/dist/src/agent/app/worktree-op-processor.js +173 -0
- package/dist/src/agent/app/worktree-op-processor.js.map +1 -0
- package/dist/src/agent/runtimes/agent-instructions.d.ts +16 -0
- package/dist/src/agent/runtimes/agent-instructions.js +33 -0
- package/dist/src/agent/runtimes/agent-instructions.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/continuation.d.ts +1 -0
- package/dist/src/agent/runtimes/claudeCode/continuation.js +30 -0
- package/dist/src/agent/runtimes/claudeCode/continuation.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/detect.d.ts +12 -0
- package/dist/src/agent/runtimes/claudeCode/detect.js +109 -0
- package/dist/src/agent/runtimes/claudeCode/detect.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/interactions.d.ts +13 -0
- package/dist/src/agent/runtimes/claudeCode/interactions.js +167 -0
- package/dist/src/agent/runtimes/claudeCode/interactions.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/models.d.ts +3 -0
- package/dist/src/agent/runtimes/claudeCode/models.js +16 -0
- package/dist/src/agent/runtimes/claudeCode/models.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/prompts.d.ts +1 -0
- package/dist/src/agent/runtimes/claudeCode/prompts.js +5 -0
- package/dist/src/agent/runtimes/claudeCode/prompts.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/runner.d.ts +32 -0
- package/dist/src/agent/runtimes/claudeCode/runner.js +941 -0
- package/dist/src/agent/runtimes/claudeCode/runner.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/runtime.d.ts +2 -0
- package/dist/src/agent/runtimes/claudeCode/runtime.js +126 -0
- package/dist/src/agent/runtimes/claudeCode/runtime.js.map +1 -0
- package/dist/src/agent/runtimes/claudeCode/streaming.d.ts +8 -0
- package/dist/src/agent/runtimes/claudeCode/streaming.js +88 -0
- package/dist/src/agent/runtimes/claudeCode/streaming.js.map +1 -0
- package/dist/src/agent/runtimes/codex/app-server-rpc.d.ts +26 -0
- package/dist/src/agent/runtimes/codex/app-server-rpc.js +109 -0
- package/dist/src/agent/runtimes/codex/app-server-rpc.js.map +1 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.d.ts +59 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.js +688 -0
- package/dist/src/agent/runtimes/codex/app-server-runner.js.map +1 -0
- package/dist/src/agent/runtimes/codex/commands.d.ts +23 -0
- package/dist/src/agent/runtimes/codex/commands.js +25 -0
- package/dist/src/agent/runtimes/codex/commands.js.map +1 -0
- package/dist/src/agent/runtimes/codex/detect.d.ts +5 -0
- package/dist/src/agent/runtimes/codex/detect.js +17 -0
- package/dist/src/agent/runtimes/codex/detect.js.map +1 -0
- package/dist/src/agent/runtimes/codex/models.d.ts +2 -0
- package/dist/src/agent/runtimes/codex/models.js +4 -0
- package/dist/src/agent/runtimes/codex/models.js.map +1 -0
- package/dist/src/agent/runtimes/codex/runner.d.ts +46 -0
- package/dist/src/agent/runtimes/codex/runner.js +298 -0
- package/dist/src/agent/runtimes/codex/runner.js.map +1 -0
- package/dist/src/agent/runtimes/codex/runtime.d.ts +10 -0
- package/dist/src/agent/runtimes/codex/runtime.js +73 -0
- package/dist/src/agent/runtimes/codex/runtime.js.map +1 -0
- package/dist/src/agent/runtimes/contracts.d.ts +215 -0
- package/dist/src/agent/runtimes/contracts.js +33 -0
- package/dist/src/agent/runtimes/contracts.js.map +1 -0
- package/dist/src/agent/runtimes/cursor/commands.d.ts +7 -0
- package/dist/src/agent/runtimes/cursor/commands.js +39 -0
- package/dist/src/agent/runtimes/cursor/commands.js.map +1 -0
- package/dist/src/agent/runtimes/cursor/detect.d.ts +17 -0
- package/dist/src/agent/runtimes/cursor/detect.js +54 -0
- package/dist/src/agent/runtimes/cursor/detect.js.map +1 -0
- package/dist/src/agent/runtimes/cursor/models.d.ts +9 -0
- package/dist/src/agent/runtimes/cursor/models.js +97 -0
- package/dist/src/agent/runtimes/cursor/models.js.map +1 -0
- package/dist/src/agent/runtimes/cursor/runner.d.ts +36 -0
- package/dist/src/agent/runtimes/cursor/runner.js +293 -0
- package/dist/src/agent/runtimes/cursor/runner.js.map +1 -0
- package/dist/src/agent/runtimes/cursor/runtime.d.ts +2 -0
- package/dist/src/agent/runtimes/cursor/runtime.js +48 -0
- package/dist/src/agent/runtimes/cursor/runtime.js.map +1 -0
- package/dist/src/agent/runtimes/cursor/streaming.d.ts +8 -0
- package/dist/src/agent/runtimes/cursor/streaming.js +78 -0
- package/dist/src/agent/runtimes/cursor/streaming.js.map +1 -0
- package/dist/src/agent/runtimes/debug.d.ts +8 -0
- package/dist/src/agent/runtimes/debug.js +19 -0
- package/dist/src/agent/runtimes/debug.js.map +1 -0
- package/dist/src/agent/runtimes/message-format.d.ts +6 -0
- package/dist/src/agent/runtimes/message-format.js +31 -0
- package/dist/src/agent/runtimes/message-format.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/client.d.ts +82 -0
- package/dist/src/agent/runtimes/opencode/client.js +109 -0
- package/dist/src/agent/runtimes/opencode/client.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/detect.d.ts +18 -0
- package/dist/src/agent/runtimes/opencode/detect.js +100 -0
- package/dist/src/agent/runtimes/opencode/detect.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/json.d.ts +4 -0
- package/dist/src/agent/runtimes/opencode/json.js +17 -0
- package/dist/src/agent/runtimes/opencode/json.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/runner.d.ts +50 -0
- package/dist/src/agent/runtimes/opencode/runner.js +598 -0
- package/dist/src/agent/runtimes/opencode/runner.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/runtime.d.ts +9 -0
- package/dist/src/agent/runtimes/opencode/runtime.js +82 -0
- package/dist/src/agent/runtimes/opencode/runtime.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/server.d.ts +36 -0
- package/dist/src/agent/runtimes/opencode/server.js +210 -0
- package/dist/src/agent/runtimes/opencode/server.js.map +1 -0
- package/dist/src/agent/runtimes/opencode/streaming.d.ts +7 -0
- package/dist/src/agent/runtimes/opencode/streaming.js +47 -0
- package/dist/src/agent/runtimes/opencode/streaming.js.map +1 -0
- package/dist/src/agent/runtimes/registry.d.ts +10 -0
- package/dist/src/agent/runtimes/registry.js +48 -0
- package/dist/src/agent/runtimes/registry.js.map +1 -0
- package/dist/src/agent/sdk/adapters/adapter-interface.d.ts +2 -0
- package/dist/src/agent/sdk/adapters/adapter-interface.js +4 -0
- package/dist/src/agent/sdk/adapters/adapter-interface.js.map +1 -0
- package/dist/src/agent/sdk/adapters/claude/claude-adapter.d.ts +9 -0
- package/dist/src/agent/sdk/adapters/claude/claude-adapter.js +95 -0
- package/dist/src/agent/sdk/adapters/claude/claude-adapter.js.map +1 -0
- package/dist/src/agent/sdk/adapters/codex/codex-adapter.d.ts +10 -0
- package/dist/src/agent/sdk/adapters/codex/codex-adapter.js +87 -0
- package/dist/src/agent/sdk/adapters/codex/codex-adapter.js.map +1 -0
- package/dist/src/agent/sdk/adapters/executable-resolution.d.ts +2 -0
- package/dist/src/agent/sdk/adapters/executable-resolution.js +50 -0
- package/dist/src/agent/sdk/adapters/executable-resolution.js.map +1 -0
- package/dist/src/agent/sdk/adapters/generic/generic-subprocess-adapter.d.ts +11 -0
- package/dist/src/agent/sdk/adapters/generic/generic-subprocess-adapter.js +61 -0
- package/dist/src/agent/sdk/adapters/generic/generic-subprocess-adapter.js.map +1 -0
- package/dist/src/agent/sdk/adapters/provider-registry.d.ts +8 -0
- package/dist/src/agent/sdk/adapters/provider-registry.js +32 -0
- package/dist/src/agent/sdk/adapters/provider-registry.js.map +1 -0
- package/dist/src/agent/sdk/constants.d.ts +5 -0
- package/dist/src/agent/sdk/constants.js +29 -0
- package/dist/src/agent/sdk/constants.js.map +1 -0
- package/dist/src/agent/sdk/index.d.ts +2 -0
- package/dist/src/agent/sdk/index.js +2 -0
- package/dist/src/agent/sdk/index.js.map +1 -0
- package/dist/src/agent/sdk/run-handle.d.ts +22 -0
- package/dist/src/agent/sdk/run-handle.js +90 -0
- package/dist/src/agent/sdk/run-handle.js.map +1 -0
- package/dist/src/agent/sdk/runtime/isolation-env.d.ts +9 -0
- package/dist/src/agent/sdk/runtime/isolation-env.js +39 -0
- package/dist/src/agent/sdk/runtime/isolation-env.js.map +1 -0
- package/dist/src/agent/sdk/runtime/line-parser.d.ts +11 -0
- package/dist/src/agent/sdk/runtime/line-parser.js +59 -0
- package/dist/src/agent/sdk/runtime/line-parser.js.map +1 -0
- package/dist/src/agent/sdk/runtime/output-pump.d.ts +20 -0
- package/dist/src/agent/sdk/runtime/output-pump.js +88 -0
- package/dist/src/agent/sdk/runtime/output-pump.js.map +1 -0
- package/dist/src/agent/sdk/runtime/process-group.d.ts +9 -0
- package/dist/src/agent/sdk/runtime/process-group.js +69 -0
- package/dist/src/agent/sdk/runtime/process-group.js.map +1 -0
- package/dist/src/agent/sdk/runtime/provider-supervisor-entrypoint.d.ts +1 -0
- package/dist/src/agent/sdk/runtime/provider-supervisor-entrypoint.js +3 -0
- package/dist/src/agent/sdk/runtime/provider-supervisor-entrypoint.js.map +1 -0
- package/dist/src/agent/sdk/runtime/provider-supervisor.d.ts +1 -0
- package/dist/src/agent/sdk/runtime/provider-supervisor.js +190 -0
- package/dist/src/agent/sdk/runtime/provider-supervisor.js.map +1 -0
- package/dist/src/agent/sdk/runtime/spawn-process.d.ts +7 -0
- package/dist/src/agent/sdk/runtime/spawn-process.js +16 -0
- package/dist/src/agent/sdk/runtime/spawn-process.js.map +1 -0
- package/dist/src/agent/sdk/runtime/spawn-supervised-process.d.ts +17 -0
- package/dist/src/agent/sdk/runtime/spawn-supervised-process.js +203 -0
- package/dist/src/agent/sdk/runtime/spawn-supervised-process.js.map +1 -0
- package/dist/src/agent/sdk/runtime/supervisor-protocol.d.ts +29 -0
- package/dist/src/agent/sdk/runtime/supervisor-protocol.js +90 -0
- package/dist/src/agent/sdk/runtime/supervisor-protocol.js.map +1 -0
- package/dist/src/agent/sdk/runtime/timeouts.d.ts +24 -0
- package/dist/src/agent/sdk/runtime/timeouts.js +65 -0
- package/dist/src/agent/sdk/runtime/timeouts.js.map +1 -0
- package/dist/src/agent/sdk/session-manager.d.ts +38 -0
- package/dist/src/agent/sdk/session-manager.js +557 -0
- package/dist/src/agent/sdk/session-manager.js.map +1 -0
- package/dist/src/agent/sdk/transport/json-stream-decoder.d.ts +6 -0
- package/dist/src/agent/sdk/transport/json-stream-decoder.js +29 -0
- package/dist/src/agent/sdk/transport/json-stream-decoder.js.map +1 -0
- package/dist/src/agent/sdk/transport/line-text-decoder.d.ts +6 -0
- package/dist/src/agent/sdk/transport/line-text-decoder.js +9 -0
- package/dist/src/agent/sdk/transport/line-text-decoder.js.map +1 -0
- package/dist/src/agent/sdk/transport/pty-contract.d.ts +12 -0
- package/dist/src/agent/sdk/transport/pty-contract.js +2 -0
- package/dist/src/agent/sdk/transport/pty-contract.js.map +1 -0
- package/dist/src/agent/sdk/types.d.ts +194 -0
- package/dist/src/agent/sdk/types.js +2 -0
- package/dist/src/agent/sdk/types.js.map +1 -0
- package/dist/src/agent/sdk/versioning/provider-version.d.ts +9 -0
- package/dist/src/agent/sdk/versioning/provider-version.js +41 -0
- package/dist/src/agent/sdk/versioning/provider-version.js.map +1 -0
- package/dist/src/cli.d.ts +7 -0
- package/dist/src/cli.js +56 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/config/command.d.ts +2 -0
- package/dist/src/commands/config/command.js +150 -0
- package/dist/src/commands/config/command.js.map +1 -0
- package/dist/src/commands/connect/command.d.ts +4 -0
- package/dist/src/commands/connect/command.js +19 -0
- package/dist/src/commands/connect/command.js.map +1 -0
- package/dist/src/commands/connect/workflow.d.ts +92 -0
- package/dist/src/commands/connect/workflow.js +381 -0
- package/dist/src/commands/connect/workflow.js.map +1 -0
- package/dist/src/commands/devcontainer/command.d.ts +2 -0
- package/dist/src/commands/devcontainer/command.js +49 -0
- package/dist/src/commands/devcontainer/command.js.map +1 -0
- package/dist/src/commands/devcontainer/install.d.ts +46 -0
- package/dist/src/commands/devcontainer/install.js +107 -0
- package/dist/src/commands/devcontainer/install.js.map +1 -0
- package/dist/src/commands/init/config/claude-mcp.d.ts +27 -0
- package/dist/src/commands/init/config/claude-mcp.js +56 -0
- package/dist/src/commands/init/config/claude-mcp.js.map +1 -0
- package/dist/src/commands/init/config/codex-mcp.d.ts +12 -0
- package/dist/src/commands/init/config/codex-mcp.js +83 -0
- package/dist/src/commands/init/config/codex-mcp.js.map +1 -0
- package/dist/src/commands/init/config/opencode-mcp.d.ts +16 -0
- package/dist/src/commands/init/config/opencode-mcp.js +55 -0
- package/dist/src/commands/init/config/opencode-mcp.js.map +1 -0
- package/dist/src/commands/init/errors.d.ts +3 -0
- package/dist/src/commands/init/errors.js +7 -0
- package/dist/src/commands/init/errors.js.map +1 -0
- package/dist/src/commands/init/index.d.ts +9 -0
- package/dist/src/commands/init/index.js +10 -0
- package/dist/src/commands/init/index.js.map +1 -0
- package/dist/src/commands/init/io/file-copy.d.ts +18 -0
- package/dist/src/commands/init/io/file-copy.js +129 -0
- package/dist/src/commands/init/io/file-copy.js.map +1 -0
- package/dist/src/commands/init/marketplace.d.ts +8 -0
- package/dist/src/commands/init/marketplace.js +25 -0
- package/dist/src/commands/init/marketplace.js.map +1 -0
- package/dist/src/commands/init/mcp-service.d.ts +2 -0
- package/dist/src/commands/init/mcp-service.js +66 -0
- package/dist/src/commands/init/mcp-service.js.map +1 -0
- package/dist/src/commands/init/parsers.d.ts +4 -0
- package/dist/src/commands/init/parsers.js +40 -0
- package/dist/src/commands/init/parsers.js.map +1 -0
- package/dist/src/commands/init/prompts.d.ts +4 -0
- package/dist/src/commands/init/prompts.js +72 -0
- package/dist/src/commands/init/prompts.js.map +1 -0
- package/dist/src/commands/init/skill-service.d.ts +2 -0
- package/dist/src/commands/init/skill-service.js +36 -0
- package/dist/src/commands/init/skill-service.js.map +1 -0
- package/dist/src/commands/init/summary.d.ts +2 -0
- package/dist/src/commands/init/summary.js +22 -0
- package/dist/src/commands/init/summary.js.map +1 -0
- package/dist/src/commands/init/targets/claude.d.ts +4 -0
- package/dist/src/commands/init/targets/claude.js +178 -0
- package/dist/src/commands/init/targets/claude.js.map +1 -0
- package/dist/src/commands/init/targets/codex.d.ts +4 -0
- package/dist/src/commands/init/targets/codex.js +75 -0
- package/dist/src/commands/init/targets/codex.js.map +1 -0
- package/dist/src/commands/init/targets/driver.d.ts +28 -0
- package/dist/src/commands/init/targets/driver.js +2 -0
- package/dist/src/commands/init/targets/driver.js.map +1 -0
- package/dist/src/commands/init/targets/opencode.d.ts +4 -0
- package/dist/src/commands/init/targets/opencode.js +77 -0
- package/dist/src/commands/init/targets/opencode.js.map +1 -0
- package/dist/src/commands/init/targets/registry.d.ts +4 -0
- package/dist/src/commands/init/targets/registry.js +15 -0
- package/dist/src/commands/init/targets/registry.js.map +1 -0
- package/dist/src/commands/init/types.d.ts +30 -0
- package/dist/src/commands/init/types.js +7 -0
- package/dist/src/commands/init/types.js.map +1 -0
- package/dist/src/commands/init.d.ts +3 -0
- package/dist/src/commands/init.js +143 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/keys/command.d.ts +2 -0
- package/dist/src/commands/keys/command.js +154 -0
- package/dist/src/commands/keys/command.js.map +1 -0
- package/dist/src/commands/labels/create.d.ts +2 -0
- package/dist/src/commands/labels/create.js +31 -0
- package/dist/src/commands/labels/create.js.map +1 -0
- package/dist/src/commands/labels/delete.d.ts +2 -0
- package/dist/src/commands/labels/delete.js +51 -0
- package/dist/src/commands/labels/delete.js.map +1 -0
- package/dist/src/commands/labels/formatters.d.ts +4 -0
- package/dist/src/commands/labels/formatters.js +6 -0
- package/dist/src/commands/labels/formatters.js.map +1 -0
- package/dist/src/commands/labels/index.d.ts +2 -0
- package/dist/src/commands/labels/index.js +13 -0
- package/dist/src/commands/labels/index.js.map +1 -0
- package/dist/src/commands/labels/list.d.ts +2 -0
- package/dist/src/commands/labels/list.js +29 -0
- package/dist/src/commands/labels/list.js.map +1 -0
- package/dist/src/commands/labels/resolve.d.ts +9 -0
- package/dist/src/commands/labels/resolve.js +23 -0
- package/dist/src/commands/labels/resolve.js.map +1 -0
- package/dist/src/commands/labels/update.d.ts +2 -0
- package/dist/src/commands/labels/update.js +37 -0
- package/dist/src/commands/labels/update.js.map +1 -0
- package/dist/src/commands/lists/constants.d.ts +7 -0
- package/dist/src/commands/lists/constants.js +14 -0
- package/dist/src/commands/lists/constants.js.map +1 -0
- package/dist/src/commands/lists/create.d.ts +2 -0
- package/dist/src/commands/lists/create.js +45 -0
- package/dist/src/commands/lists/create.js.map +1 -0
- package/dist/src/commands/lists/index.d.ts +2 -0
- package/dist/src/commands/lists/index.js +10 -0
- package/dist/src/commands/lists/index.js.map +1 -0
- package/dist/src/commands/lists/list.d.ts +2 -0
- package/dist/src/commands/lists/list.js +66 -0
- package/dist/src/commands/lists/list.js.map +1 -0
- package/dist/src/commands/lists/resolve.d.ts +11 -0
- package/dist/src/commands/lists/resolve.js +24 -0
- package/dist/src/commands/lists/resolve.js.map +1 -0
- package/dist/src/commands/lists/update.d.ts +2 -0
- package/dist/src/commands/lists/update.js +61 -0
- package/dist/src/commands/lists/update.js.map +1 -0
- package/dist/src/commands/login/command.d.ts +8 -0
- package/dist/src/commands/login/command.js +20 -0
- package/dist/src/commands/login/command.js.map +1 -0
- package/dist/src/commands/orgs/index.d.ts +2 -0
- package/dist/src/commands/orgs/index.js +6 -0
- package/dist/src/commands/orgs/index.js.map +1 -0
- package/dist/src/commands/orgs/list.d.ts +2 -0
- package/dist/src/commands/orgs/list.js +29 -0
- package/dist/src/commands/orgs/list.js.map +1 -0
- package/dist/src/commands/paths/command.d.ts +2 -0
- package/dist/src/commands/paths/command.js +90 -0
- package/dist/src/commands/paths/command.js.map +1 -0
- package/dist/src/commands/profiles/index.d.ts +2 -0
- package/dist/src/commands/profiles/index.js +6 -0
- package/dist/src/commands/profiles/index.js.map +1 -0
- package/dist/src/commands/profiles/list.d.ts +2 -0
- package/dist/src/commands/profiles/list.js +50 -0
- package/dist/src/commands/profiles/list.js.map +1 -0
- package/dist/src/commands/project-agents/create.d.ts +2 -0
- package/dist/src/commands/project-agents/create.js +53 -0
- package/dist/src/commands/project-agents/create.js.map +1 -0
- package/dist/src/commands/project-agents/index.d.ts +2 -0
- package/dist/src/commands/project-agents/index.js +10 -0
- package/dist/src/commands/project-agents/index.js.map +1 -0
- package/dist/src/commands/project-agents/list.d.ts +2 -0
- package/dist/src/commands/project-agents/list.js +30 -0
- package/dist/src/commands/project-agents/list.js.map +1 -0
- package/dist/src/commands/project-agents/parsers.d.ts +16 -0
- package/dist/src/commands/project-agents/parsers.js +80 -0
- package/dist/src/commands/project-agents/parsers.js.map +1 -0
- package/dist/src/commands/project-agents/update.d.ts +2 -0
- package/dist/src/commands/project-agents/update.js +74 -0
- package/dist/src/commands/project-agents/update.js.map +1 -0
- package/dist/src/commands/projects/index.d.ts +2 -0
- package/dist/src/commands/projects/index.js +6 -0
- package/dist/src/commands/projects/index.js.map +1 -0
- package/dist/src/commands/projects/list.d.ts +2 -0
- package/dist/src/commands/projects/list.js +41 -0
- package/dist/src/commands/projects/list.js.map +1 -0
- package/dist/src/commands/prompts/create.d.ts +2 -0
- package/dist/src/commands/prompts/create.js +48 -0
- package/dist/src/commands/prompts/create.js.map +1 -0
- package/dist/src/commands/prompts/formatters.d.ts +4 -0
- package/dist/src/commands/prompts/formatters.js +7 -0
- package/dist/src/commands/prompts/formatters.js.map +1 -0
- package/dist/src/commands/prompts/index.d.ts +2 -0
- package/dist/src/commands/prompts/index.js +11 -0
- package/dist/src/commands/prompts/index.js.map +1 -0
- package/dist/src/commands/prompts/list.d.ts +2 -0
- package/dist/src/commands/prompts/list.js +34 -0
- package/dist/src/commands/prompts/list.js.map +1 -0
- package/dist/src/commands/prompts/parsers.d.ts +9 -0
- package/dist/src/commands/prompts/parsers.js +12 -0
- package/dist/src/commands/prompts/parsers.js.map +1 -0
- package/dist/src/commands/prompts/resolve.d.ts +17 -0
- package/dist/src/commands/prompts/resolve.js +43 -0
- package/dist/src/commands/prompts/resolve.js.map +1 -0
- package/dist/src/commands/prompts/update.d.ts +2 -0
- package/dist/src/commands/prompts/update.js +58 -0
- package/dist/src/commands/prompts/update.js.map +1 -0
- package/dist/src/commands/setup/command.d.ts +2 -0
- package/dist/src/commands/setup/command.js +15 -0
- package/dist/src/commands/setup/command.js.map +1 -0
- package/dist/src/commands/setup/prompts.d.ts +66 -0
- package/dist/src/commands/setup/prompts.js +199 -0
- package/dist/src/commands/setup/prompts.js.map +1 -0
- package/dist/src/commands/setup/workflow.d.ts +17 -0
- package/dist/src/commands/setup/workflow.js +141 -0
- package/dist/src/commands/setup/workflow.js.map +1 -0
- package/dist/src/commands/status/command.d.ts +2 -0
- package/dist/src/commands/status/command.js +83 -0
- package/dist/src/commands/status/command.js.map +1 -0
- package/dist/src/commands/task-types/index.d.ts +2 -0
- package/dist/src/commands/task-types/index.js +6 -0
- package/dist/src/commands/task-types/index.js.map +1 -0
- package/dist/src/commands/task-types/list.d.ts +2 -0
- package/dist/src/commands/task-types/list.js +32 -0
- package/dist/src/commands/task-types/list.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/add.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/comments/add.js +32 -0
- package/dist/src/commands/tasks/artifacts/comments/add.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/formatters.d.ts +7 -0
- package/dist/src/commands/tasks/artifacts/comments/formatters.js +32 -0
- package/dist/src/commands/tasks/artifacts/comments/formatters.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/index.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/comments/index.js +13 -0
- package/dist/src/commands/tasks/artifacts/comments/index.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/list.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/comments/list.js +24 -0
- package/dist/src/commands/tasks/artifacts/comments/list.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/parsers.d.ts +6 -0
- package/dist/src/commands/tasks/artifacts/comments/parsers.js +8 -0
- package/dist/src/commands/tasks/artifacts/comments/parsers.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/reply.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/comments/reply.js +23 -0
- package/dist/src/commands/tasks/artifacts/comments/reply.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/comments/resolve.d.ts +3 -0
- package/dist/src/commands/tasks/artifacts/comments/resolve.js +26 -0
- package/dist/src/commands/tasks/artifacts/comments/resolve.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/create.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/create.js +63 -0
- package/dist/src/commands/tasks/artifacts/create.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/delete.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/delete.js +27 -0
- package/dist/src/commands/tasks/artifacts/delete.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/get.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/get.js +54 -0
- package/dist/src/commands/tasks/artifacts/get.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/index.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/index.js +18 -0
- package/dist/src/commands/tasks/artifacts/index.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/list.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/list.js +31 -0
- package/dist/src/commands/tasks/artifacts/list.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/parsers.d.ts +13 -0
- package/dist/src/commands/tasks/artifacts/parsers.js +24 -0
- package/dist/src/commands/tasks/artifacts/parsers.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/replace.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/replace.js +62 -0
- package/dist/src/commands/tasks/artifacts/replace.js.map +1 -0
- package/dist/src/commands/tasks/artifacts/update.d.ts +2 -0
- package/dist/src/commands/tasks/artifacts/update.js +55 -0
- package/dist/src/commands/tasks/artifacts/update.js.map +1 -0
- package/dist/src/commands/tasks/attach.d.ts +2 -0
- package/dist/src/commands/tasks/attach.js +70 -0
- package/dist/src/commands/tasks/attach.js.map +1 -0
- package/dist/src/commands/tasks/attachments/delete.d.ts +2 -0
- package/dist/src/commands/tasks/attachments/delete.js +61 -0
- package/dist/src/commands/tasks/attachments/delete.js.map +1 -0
- package/dist/src/commands/tasks/attachments/download.d.ts +2 -0
- package/dist/src/commands/tasks/attachments/download.js +42 -0
- package/dist/src/commands/tasks/attachments/download.js.map +1 -0
- package/dist/src/commands/tasks/attachments/formatters.d.ts +5 -0
- package/dist/src/commands/tasks/attachments/formatters.js +18 -0
- package/dist/src/commands/tasks/attachments/formatters.js.map +1 -0
- package/dist/src/commands/tasks/attachments/index.d.ts +2 -0
- package/dist/src/commands/tasks/attachments/index.js +11 -0
- package/dist/src/commands/tasks/attachments/index.js.map +1 -0
- package/dist/src/commands/tasks/attachments/list.d.ts +2 -0
- package/dist/src/commands/tasks/attachments/list.js +36 -0
- package/dist/src/commands/tasks/attachments/list.js.map +1 -0
- package/dist/src/commands/tasks/attachments/resolve.d.ts +6 -0
- package/dist/src/commands/tasks/attachments/resolve.js +15 -0
- package/dist/src/commands/tasks/attachments/resolve.js.map +1 -0
- package/dist/src/commands/tasks/attachments/transfer.d.ts +11 -0
- package/dist/src/commands/tasks/attachments/transfer.js +71 -0
- package/dist/src/commands/tasks/attachments/transfer.js.map +1 -0
- package/dist/src/commands/tasks/comments/add.d.ts +2 -0
- package/dist/src/commands/tasks/comments/add.js +44 -0
- package/dist/src/commands/tasks/comments/add.js.map +1 -0
- package/dist/src/commands/tasks/comments/index.d.ts +2 -0
- package/dist/src/commands/tasks/comments/index.js +6 -0
- package/dist/src/commands/tasks/comments/index.js.map +1 -0
- package/dist/src/commands/tasks/create.d.ts +2 -0
- package/dist/src/commands/tasks/create.js +77 -0
- package/dist/src/commands/tasks/create.js.map +1 -0
- package/dist/src/commands/tasks/delete.d.ts +2 -0
- package/dist/src/commands/tasks/delete.js +31 -0
- package/dist/src/commands/tasks/delete.js.map +1 -0
- package/dist/src/commands/tasks/formatters.d.ts +25 -0
- package/dist/src/commands/tasks/formatters.js +40 -0
- package/dist/src/commands/tasks/formatters.js.map +1 -0
- package/dist/src/commands/tasks/get.d.ts +2 -0
- package/dist/src/commands/tasks/get.js +94 -0
- package/dist/src/commands/tasks/get.js.map +1 -0
- package/dist/src/commands/tasks/hydrate.d.ts +20 -0
- package/dist/src/commands/tasks/hydrate.js +47 -0
- package/dist/src/commands/tasks/hydrate.js.map +1 -0
- package/dist/src/commands/tasks/index.d.ts +2 -0
- package/dist/src/commands/tasks/index.js +33 -0
- package/dist/src/commands/tasks/index.js.map +1 -0
- package/dist/src/commands/tasks/links.d.ts +4 -0
- package/dist/src/commands/tasks/links.js +121 -0
- package/dist/src/commands/tasks/links.js.map +1 -0
- package/dist/src/commands/tasks/list.d.ts +2 -0
- package/dist/src/commands/tasks/list.js +47 -0
- package/dist/src/commands/tasks/list.js.map +1 -0
- package/dist/src/commands/tasks/move-to-list.d.ts +2 -0
- package/dist/src/commands/tasks/move-to-list.js +41 -0
- package/dist/src/commands/tasks/move-to-list.js.map +1 -0
- package/dist/src/commands/tasks/move.d.ts +2 -0
- package/dist/src/commands/tasks/move.js +61 -0
- package/dist/src/commands/tasks/move.js.map +1 -0
- package/dist/src/commands/tasks/parsers.d.ts +22 -0
- package/dist/src/commands/tasks/parsers.js +118 -0
- package/dist/src/commands/tasks/parsers.js.map +1 -0
- package/dist/src/commands/tasks/refs.d.ts +2 -0
- package/dist/src/commands/tasks/refs.js +89 -0
- package/dist/src/commands/tasks/refs.js.map +1 -0
- package/dist/src/commands/tasks/resolve.d.ts +20 -0
- package/dist/src/commands/tasks/resolve.js +57 -0
- package/dist/src/commands/tasks/resolve.js.map +1 -0
- package/dist/src/commands/tasks/search.d.ts +2 -0
- package/dist/src/commands/tasks/search.js +110 -0
- package/dist/src/commands/tasks/search.js.map +1 -0
- package/dist/src/commands/tasks/update.d.ts +2 -0
- package/dist/src/commands/tasks/update.js +101 -0
- package/dist/src/commands/tasks/update.js.map +1 -0
- package/dist/src/commands/test-helpers.d.ts +2 -0
- package/dist/src/commands/test-helpers.js +6 -0
- package/dist/src/commands/test-helpers.js.map +1 -0
- package/dist/src/commands/threads/create.d.ts +2 -0
- package/dist/src/commands/threads/create.js +99 -0
- package/dist/src/commands/threads/create.js.map +1 -0
- package/dist/src/commands/threads/formatters.d.ts +10 -0
- package/dist/src/commands/threads/formatters.js +17 -0
- package/dist/src/commands/threads/formatters.js.map +1 -0
- package/dist/src/commands/threads/get.d.ts +2 -0
- package/dist/src/commands/threads/get.js +53 -0
- package/dist/src/commands/threads/get.js.map +1 -0
- package/dist/src/commands/threads/index.d.ts +2 -0
- package/dist/src/commands/threads/index.js +14 -0
- package/dist/src/commands/threads/index.js.map +1 -0
- package/dist/src/commands/threads/list.d.ts +2 -0
- package/dist/src/commands/threads/list.js +69 -0
- package/dist/src/commands/threads/list.js.map +1 -0
- package/dist/src/commands/threads/messages.d.ts +2 -0
- package/dist/src/commands/threads/messages.js +59 -0
- package/dist/src/commands/threads/messages.js.map +1 -0
- package/dist/src/commands/threads/parsers.d.ts +5 -0
- package/dist/src/commands/threads/parsers.js +19 -0
- package/dist/src/commands/threads/parsers.js.map +1 -0
- package/dist/src/commands/threads/send.d.ts +2 -0
- package/dist/src/commands/threads/send.js +49 -0
- package/dist/src/commands/threads/send.js.map +1 -0
- package/dist/src/commands/threads/spawn-target.d.ts +29 -0
- package/dist/src/commands/threads/spawn-target.js +62 -0
- package/dist/src/commands/threads/spawn-target.js.map +1 -0
- package/dist/src/convex/_generated/ai/ai-files.state.json +6 -0
- package/dist/src/convex/_generated/ai/guidelines.md +371 -0
- package/dist/src/convex/_generated/api.d.ts +598 -0
- package/dist/src/convex/_generated/api.js +23 -0
- package/dist/src/convex/_generated/dataModel.d.ts +60 -0
- package/dist/src/convex/_generated/server.d.ts +143 -0
- package/dist/src/convex/_generated/server.js +93 -0
- package/dist/src/lib/argv.d.ts +1 -0
- package/dist/src/lib/argv.js +7 -0
- package/dist/src/lib/argv.js.map +1 -0
- package/dist/src/lib/browser-login.d.ts +43 -0
- package/dist/src/lib/browser-login.js +216 -0
- package/dist/src/lib/browser-login.js.map +1 -0
- package/dist/src/lib/config/convex-client.d.ts +41 -0
- package/dist/src/lib/config/convex-client.js +53 -0
- package/dist/src/lib/config/convex-client.js.map +1 -0
- package/dist/src/lib/config/index.d.ts +7 -0
- package/dist/src/lib/config/index.js +13 -0
- package/dist/src/lib/config/index.js.map +1 -0
- package/dist/src/lib/config/profile.d.ts +40 -0
- package/dist/src/lib/config/profile.js +155 -0
- package/dist/src/lib/config/profile.js.map +1 -0
- package/dist/src/lib/config/provider-keys.d.ts +47 -0
- package/dist/src/lib/config/provider-keys.js +97 -0
- package/dist/src/lib/config/provider-keys.js.map +1 -0
- package/dist/src/lib/config/toml.d.ts +78 -0
- package/dist/src/lib/config/toml.js +228 -0
- package/dist/src/lib/config/toml.js.map +1 -0
- package/dist/src/lib/config/types.d.ts +98 -0
- package/dist/src/lib/config/types.js +65 -0
- package/dist/src/lib/config/types.js.map +1 -0
- package/dist/src/lib/config/validate.d.ts +30 -0
- package/dist/src/lib/config/validate.js +66 -0
- package/dist/src/lib/config/validate.js.map +1 -0
- package/dist/src/lib/connect-events.d.ts +42 -0
- package/dist/src/lib/connect-events.js +65 -0
- package/dist/src/lib/connect-events.js.map +1 -0
- package/dist/src/lib/constants.d.ts +20 -0
- package/dist/src/lib/constants.js +27 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/content-type.d.ts +1 -0
- package/dist/src/lib/content-type.js +27 -0
- package/dist/src/lib/content-type.js.map +1 -0
- package/dist/src/lib/convex-error.d.ts +12 -0
- package/dist/src/lib/convex-error.js +33 -0
- package/dist/src/lib/convex-error.js.map +1 -0
- package/dist/src/lib/git/checkpoint.d.ts +74 -0
- package/dist/src/lib/git/checkpoint.js +210 -0
- package/dist/src/lib/git/checkpoint.js.map +1 -0
- package/dist/src/lib/git/exec.d.ts +23 -0
- package/dist/src/lib/git/exec.js +46 -0
- package/dist/src/lib/git/exec.js.map +1 -0
- package/dist/src/lib/git/file-index.d.ts +8 -0
- package/dist/src/lib/git/file-index.js +125 -0
- package/dist/src/lib/git/file-index.js.map +1 -0
- package/dist/src/lib/git/index.d.ts +5 -0
- package/dist/src/lib/git/index.js +6 -0
- package/dist/src/lib/git/index.js.map +1 -0
- package/dist/src/lib/git/repo.d.ts +32 -0
- package/dist/src/lib/git/repo.js +95 -0
- package/dist/src/lib/git/repo.js.map +1 -0
- package/dist/src/lib/git/worktrees.d.ts +49 -0
- package/dist/src/lib/git/worktrees.js +97 -0
- package/dist/src/lib/git/worktrees.js.map +1 -0
- package/dist/src/lib/global-options.d.ts +3 -0
- package/dist/src/lib/global-options.js +8 -0
- package/dist/src/lib/global-options.js.map +1 -0
- package/dist/src/lib/id.d.ts +3 -0
- package/dist/src/lib/id.js +14 -0
- package/dist/src/lib/id.js.map +1 -0
- package/dist/src/lib/one-shot-command.d.ts +7 -0
- package/dist/src/lib/one-shot-command.js +30 -0
- package/dist/src/lib/one-shot-command.js.map +1 -0
- package/dist/src/lib/one-shot-config.d.ts +3 -0
- package/dist/src/lib/one-shot-config.js +7 -0
- package/dist/src/lib/one-shot-config.js.map +1 -0
- package/dist/src/lib/output.d.ts +10 -0
- package/dist/src/lib/output.js +27 -0
- package/dist/src/lib/output.js.map +1 -0
- package/dist/src/lib/pagination.d.ts +16 -0
- package/dist/src/lib/pagination.js +45 -0
- package/dist/src/lib/pagination.js.map +1 -0
- package/dist/src/lib/parsers.d.ts +2 -0
- package/dist/src/lib/parsers.js +21 -0
- package/dist/src/lib/parsers.js.map +1 -0
- package/dist/src/lib/project-resolution.d.ts +41 -0
- package/dist/src/lib/project-resolution.js +84 -0
- package/dist/src/lib/project-resolution.js.map +1 -0
- package/dist/src/lib/pull-requests.d.ts +47 -0
- package/dist/src/lib/pull-requests.js +305 -0
- package/dist/src/lib/pull-requests.js.map +1 -0
- package/dist/src/lib/skill-install-guidance.d.ts +5 -0
- package/dist/src/lib/skill-install-guidance.js +41 -0
- package/dist/src/lib/skill-install-guidance.js.map +1 -0
- package/dist/src/lib/text-input.d.ts +18 -0
- package/dist/src/lib/text-input.js +36 -0
- package/dist/src/lib/text-input.js.map +1 -0
- package/dist/src/lib/thread-attachments.d.ts +21 -0
- package/dist/src/lib/thread-attachments.js +104 -0
- package/dist/src/lib/thread-attachments.js.map +1 -0
- package/dist/src/lib/url.d.ts +13 -0
- package/dist/src/lib/url.js +25 -0
- package/dist/src/lib/url.js.map +1 -0
- package/dist/src/lib/version.d.ts +2 -0
- package/dist/src/lib/version.js +33 -0
- package/dist/src/lib/version.js.map +1 -0
- package/dist/templates/devcontainer/Dockerfile +95 -0
- package/dist/templates/devcontainer/README.md +129 -0
- package/dist/templates/devcontainer/devcontainer.json +92 -0
- package/dist/templates/devcontainer/init-firewall.sh +271 -0
- package/package.json +79 -0
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
import { createReadStream } from "node:fs";
|
|
2
|
+
import { access, constants } from "node:fs/promises";
|
|
3
|
+
import { createInterface } from "node:readline";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import * as os from "node:os";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { query, } from "@anthropic-ai/claude-agent-sdk";
|
|
8
|
+
import { isRecord } from "../../sdk/adapters/adapter-interface.js";
|
|
9
|
+
import { resolveExecutable } from "../../sdk/adapters/executable-resolution.js";
|
|
10
|
+
import { CLAUDE_PROVIDER_ENV_VAR, buildProviderSettingsJson, } from "../../../lib/config/provider-keys.js";
|
|
11
|
+
import { extractClaudeCodeContinuationId } from "./continuation.js";
|
|
12
|
+
import { createClaudeCanUseTool, toClaudePermissionMode } from "./interactions.js";
|
|
13
|
+
import { PLAN_MODE_SYSTEM_PROMPT } from "./prompts.js";
|
|
14
|
+
import { RunnerExecutionError } from "../contracts.js";
|
|
15
|
+
import { getDebugLevel } from "../debug.js";
|
|
16
|
+
import { threadIdentityInstruction } from "../agent-instructions.js";
|
|
17
|
+
import { ENV_THREAD_ID } from "../../../lib/constants.js";
|
|
18
|
+
function sleep(ms) {
|
|
19
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
|
+
}
|
|
21
|
+
/** Delay between sending each JSON line (ms) */
|
|
22
|
+
const STREAM_DELAY_MS = 1500;
|
|
23
|
+
/** No SDK message observed before this deadline fails the run. */
|
|
24
|
+
const STARTUP_TIMEOUT_MS = 120_000;
|
|
25
|
+
/** No SDK message observed for this long mid-run fails the run. */
|
|
26
|
+
const IDLE_TIMEOUT_MS = 600_000;
|
|
27
|
+
/**
|
|
28
|
+
* Ceiling on holding a finished turn open for live background agents. A held turn occupies
|
|
29
|
+
* one of the worker slots, so this trades a thread's slot against losing the agent's work.
|
|
30
|
+
* Spec: docs/specs/cli-sdk-integration.md (OS-1661).
|
|
31
|
+
*
|
|
32
|
+
* ponytail: one wall-clock ceiling for all live agents; per-agent deadlines if one
|
|
33
|
+
* slow agent starts holding up threads.
|
|
34
|
+
*/
|
|
35
|
+
const BACKGROUND_AGENT_WAIT_MS = readPositiveIntEnv("OPENSANA_BACKGROUND_AGENT_WAIT_MS", 1_800_000);
|
|
36
|
+
function readPositiveIntEnv(name, fallback) {
|
|
37
|
+
const parsed = Number.parseInt(process.env[name] ?? "", 10);
|
|
38
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Task types that must NOT hold the turn open: children of a tool call (`local_bash`,
|
|
42
|
+
* which churn constantly), or work that outlives this process (`remote_agent`).
|
|
43
|
+
* Everything else is treated as in-process and holds — the default is "hold", so a new
|
|
44
|
+
* SDK task type cannot silently regress to killing background work (OS-1661).
|
|
45
|
+
*/
|
|
46
|
+
const NON_BLOCKING_BACKGROUND_TASK_TYPES = new Set(["local_bash", "remote_agent"]);
|
|
47
|
+
/** Synthetic chunk reporting that the background-agent wait hit its ceiling. */
|
|
48
|
+
const BACKGROUND_WAIT_TIMEOUT_CHUNK_TYPE = "opensana.background_wait_timeout";
|
|
49
|
+
/**
|
|
50
|
+
* Candidate in-process background tasks from a `background_tasks_changed` snapshot.
|
|
51
|
+
*
|
|
52
|
+
* `null` means "no usable snapshot" — the caller keeps its prior state. An empty set is a
|
|
53
|
+
* real "nothing live". The two must stay distinct: treating a malformed payload as empty
|
|
54
|
+
* would silently clear the gate and restore the original bug.
|
|
55
|
+
*
|
|
56
|
+
* Ids are kept unfiltered here and intersected with the spawned set at read time, because
|
|
57
|
+
* the snapshot can arrive *before* the `task_started` that announces the same id (observed
|
|
58
|
+
* live) — filtering on arrival would drop the agent and end the turn.
|
|
59
|
+
*/
|
|
60
|
+
function readLiveBackgroundTaskIds(message) {
|
|
61
|
+
const record = message;
|
|
62
|
+
if (record.type !== "system" || record.subtype !== "background_tasks_changed") {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!Array.isArray(record.tasks)) {
|
|
66
|
+
debugLog("background_tasks_malformed", JSON.stringify(record));
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const live = new Set();
|
|
70
|
+
for (const task of record.tasks) {
|
|
71
|
+
if (!isRecord(task))
|
|
72
|
+
continue;
|
|
73
|
+
const taskId = task.task_id;
|
|
74
|
+
const taskType = task.task_type;
|
|
75
|
+
if (typeof taskId !== "string")
|
|
76
|
+
continue;
|
|
77
|
+
if (typeof taskType === "string" && NON_BLOCKING_BACKGROUND_TASK_TYPES.has(taskType)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
live.add(taskId);
|
|
81
|
+
}
|
|
82
|
+
return live;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Background task ids this turn spawned via a tool call, from the typed `task_started`
|
|
86
|
+
* edge event. Only tool-spawned tasks carry a `tool_use_id`.
|
|
87
|
+
*/
|
|
88
|
+
function readSpawnedBackgroundTaskId(message) {
|
|
89
|
+
const record = message;
|
|
90
|
+
if (record.type !== "system" || record.subtype !== "task_started") {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const taskId = record.task_id;
|
|
94
|
+
const taskType = record.task_type;
|
|
95
|
+
if (typeof taskId !== "string" || typeof record.tool_use_id !== "string") {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (typeof taskType === "string" && NON_BLOCKING_BACKGROUND_TASK_TYPES.has(taskType)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return taskId;
|
|
102
|
+
}
|
|
103
|
+
/** Notice emitted when background agents outlive the wait ceiling. */
|
|
104
|
+
function backgroundWaitTimeoutChunk(count) {
|
|
105
|
+
return {
|
|
106
|
+
type: BACKGROUND_WAIT_TIMEOUT_CHUNK_TYPE,
|
|
107
|
+
data: JSON.stringify({
|
|
108
|
+
type: BACKGROUND_WAIT_TIMEOUT_CHUNK_TYPE,
|
|
109
|
+
waitedMs: BACKGROUND_AGENT_WAIT_MS,
|
|
110
|
+
taskCount: count,
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Env var override for the Claude Code executable path. */
|
|
115
|
+
const CLAUDE_EXECUTABLE_ENV = "OPENSANA_CLAUDE_EXECUTABLE";
|
|
116
|
+
/** Synthetic chunk carrying the current context-window snapshot. */
|
|
117
|
+
const CONTEXT_USAGE_CHUNK_TYPE = "opensana.context_usage";
|
|
118
|
+
/** Path to built-in fixtures directory */
|
|
119
|
+
const FIXTURES_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../../fixtures");
|
|
120
|
+
/** Default fixture used when no stream file is specified */
|
|
121
|
+
const DEFAULT_FIXTURE = path.join(FIXTURES_DIR, "claude-code-grep.jsonl");
|
|
122
|
+
/**
|
|
123
|
+
* Parse the `type` field from a JSON line, with fallback regex for
|
|
124
|
+
* lines that may contain binary data (e.g., thinking signatures).
|
|
125
|
+
*/
|
|
126
|
+
function parseChunkType(line) {
|
|
127
|
+
try {
|
|
128
|
+
const parsed = JSON.parse(line);
|
|
129
|
+
return parsed.type;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
const typeMatch = line.match(/"type"\s*:\s*"([^"]+)"/);
|
|
133
|
+
return typeMatch?.[1] ?? "unknown";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function normalizeLogLine(value, maxLength = 240) {
|
|
137
|
+
const oneLine = value.replace(/\s+/g, " ").trim();
|
|
138
|
+
if (maxLength <= 0 || oneLine.length <= maxLength) {
|
|
139
|
+
return oneLine;
|
|
140
|
+
}
|
|
141
|
+
return `${oneLine.slice(0, maxLength)}...`;
|
|
142
|
+
}
|
|
143
|
+
function getDebugMaxChars() {
|
|
144
|
+
// Level 2 means "no truncation" regardless of OPENSANA_CLI_DEBUG_MAX_CHARS.
|
|
145
|
+
if (getDebugLevel() >= 2) {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
const raw = process.env.OPENSANA_CLI_DEBUG_MAX_CHARS;
|
|
149
|
+
if (!raw) {
|
|
150
|
+
return 400;
|
|
151
|
+
}
|
|
152
|
+
const parsed = Number.parseInt(raw, 10);
|
|
153
|
+
if (!Number.isFinite(parsed)) {
|
|
154
|
+
return 400;
|
|
155
|
+
}
|
|
156
|
+
// 0 (or negative) means "no truncation".
|
|
157
|
+
if (parsed <= 0) {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
return parsed;
|
|
161
|
+
}
|
|
162
|
+
function appendStderrTail(stderrTail, line, maxLines = 12) {
|
|
163
|
+
const normalized = normalizeLogLine(line);
|
|
164
|
+
if (!normalized) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
stderrTail.push(normalized);
|
|
168
|
+
if (stderrTail.length > maxLines) {
|
|
169
|
+
stderrTail.shift();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function debugLog(kind, payload) {
|
|
173
|
+
if (getDebugLevel() < 1) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
console.log(`[SDK:${kind}] ${normalizeLogLine(payload, getDebugMaxChars())}`);
|
|
177
|
+
}
|
|
178
|
+
function debugQueryStart(details) {
|
|
179
|
+
if (getDebugLevel() < 1) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Keep full payload for startup diagnostics; truncation hides critical flags.
|
|
183
|
+
console.log(`[SDK:query_started] ${JSON.stringify(details)}`);
|
|
184
|
+
}
|
|
185
|
+
function formatRunFailure(params) {
|
|
186
|
+
const parts = [`Claude run failed: reason=${params.reason}`];
|
|
187
|
+
if (params.detail) {
|
|
188
|
+
parts.push(`detail=${normalizeLogLine(params.detail, 400)}`);
|
|
189
|
+
}
|
|
190
|
+
if (params.stderrTail.length > 0) {
|
|
191
|
+
const tail = params.stderrTail.slice(-3).join(" | ");
|
|
192
|
+
parts.push(`stderrTail=${tail}`);
|
|
193
|
+
}
|
|
194
|
+
if (params.reason === "timeout_startup") {
|
|
195
|
+
parts.push("hint=no output before startup timeout; verify Claude auth/config in HOME/XDG paths");
|
|
196
|
+
}
|
|
197
|
+
return parts.join(" ");
|
|
198
|
+
}
|
|
199
|
+
function buildClaudeSubprocessEnv(threadId) {
|
|
200
|
+
let homedirFallback;
|
|
201
|
+
try {
|
|
202
|
+
homedirFallback = os.homedir();
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
homedirFallback = undefined;
|
|
206
|
+
}
|
|
207
|
+
const home = process.env.HOME ??
|
|
208
|
+
process.env.USERPROFILE ??
|
|
209
|
+
(process.env.HOMEDRIVE && process.env.HOMEPATH
|
|
210
|
+
? `${process.env.HOMEDRIVE}${process.env.HOMEPATH}`
|
|
211
|
+
: undefined) ??
|
|
212
|
+
homedirFallback;
|
|
213
|
+
// The SDK documents env as merged on top of process.env, but merge
|
|
214
|
+
// explicitly so the subprocess environment does not depend on that
|
|
215
|
+
// behavior staying stable across SDK versions.
|
|
216
|
+
const env = {
|
|
217
|
+
...process.env,
|
|
218
|
+
// The API key must never leak into the agent subprocess environment.
|
|
219
|
+
OPENSANA_API_KEY: undefined,
|
|
220
|
+
CLAUDE_AGENT_SDK_CLIENT_APP: "opensana-cli",
|
|
221
|
+
// Thread identity (OS-1223).
|
|
222
|
+
[ENV_THREAD_ID]: threadId,
|
|
223
|
+
};
|
|
224
|
+
if (!home) {
|
|
225
|
+
return env;
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
...env,
|
|
229
|
+
HOME: home,
|
|
230
|
+
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME ?? path.join(home, ".config"),
|
|
231
|
+
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME ?? path.join(home, ".cache"),
|
|
232
|
+
XDG_STATE_HOME: process.env.XDG_STATE_HOME ?? path.join(home, ".local", "state"),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async function resolveClaudeExecutablePath() {
|
|
236
|
+
const configured = process.env[CLAUDE_EXECUTABLE_ENV]?.trim();
|
|
237
|
+
return resolveExecutable("claude", {
|
|
238
|
+
...(configured ? { executablePath: configured } : {}),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function toMessageParam(value) {
|
|
242
|
+
if (!isRecord(value) || value.role !== "user") {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
const content = value.content;
|
|
246
|
+
if (typeof content === "string") {
|
|
247
|
+
return { role: "user", content };
|
|
248
|
+
}
|
|
249
|
+
if (Array.isArray(content)) {
|
|
250
|
+
return {
|
|
251
|
+
role: "user",
|
|
252
|
+
content: content,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
function toSdkUserMessages(frames) {
|
|
258
|
+
const messages = [];
|
|
259
|
+
for (const frame of frames) {
|
|
260
|
+
if (!isRecord(frame) || frame.type !== "user") {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const message = toMessageParam(frame.message);
|
|
264
|
+
if (!message) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
messages.push({
|
|
268
|
+
type: "user",
|
|
269
|
+
message,
|
|
270
|
+
parent_tool_use_id: null,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return messages;
|
|
274
|
+
}
|
|
275
|
+
async function* toAsyncIterable(items) {
|
|
276
|
+
for (const item of items) {
|
|
277
|
+
yield item;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* A streaming-input prompt that stays open after the initial messages so the
|
|
282
|
+
* SDK control channel (canUseTool, interrupt, setPermissionMode) keeps
|
|
283
|
+
* working for the whole run. `push()` injects additional user turns mid-run
|
|
284
|
+
* (steering); `end()` releases the stream once the run finishes.
|
|
285
|
+
*/
|
|
286
|
+
function createOpenEndedInput(messages) {
|
|
287
|
+
let ended = false;
|
|
288
|
+
let release = null;
|
|
289
|
+
const pending = [...messages];
|
|
290
|
+
const iterable = (async function* () {
|
|
291
|
+
while (true) {
|
|
292
|
+
const next = pending.shift();
|
|
293
|
+
if (next) {
|
|
294
|
+
yield next;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (ended) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
await new Promise((resolve) => {
|
|
301
|
+
release = resolve;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
})();
|
|
305
|
+
return {
|
|
306
|
+
iterable,
|
|
307
|
+
push(next) {
|
|
308
|
+
pending.push(...next);
|
|
309
|
+
release?.();
|
|
310
|
+
release = null;
|
|
311
|
+
},
|
|
312
|
+
end() {
|
|
313
|
+
ended = true;
|
|
314
|
+
release?.();
|
|
315
|
+
release = null;
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function promptToSdkUserMessage(prompt) {
|
|
320
|
+
return {
|
|
321
|
+
type: "user",
|
|
322
|
+
message: { role: "user", content: prompt },
|
|
323
|
+
parent_tool_use_id: null,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
const CLAUDE_EFFORT_LEVELS = new Set(["low", "medium", "high", "xhigh", "max"]);
|
|
327
|
+
function isClaudeEffortLevel(value) {
|
|
328
|
+
return value !== undefined && CLAUDE_EFFORT_LEVELS.has(value);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Isolation (OS-1242): the SDK's OS sandbox wraps bash commands only — the file tools
|
|
332
|
+
* write in-process, and under bypassPermissions nothing else constrains them. Hooks still
|
|
333
|
+
* run in bypass mode, so this PreToolUse hook denies file-tool writes resolving outside
|
|
334
|
+
* the writable roots (+ cwd, so worktrees keep working).
|
|
335
|
+
*
|
|
336
|
+
* ponytail: prefix check on the resolved path — a symlink inside a root can still point
|
|
337
|
+
* outside; the OS sandbox contains bash regardless.
|
|
338
|
+
*/
|
|
339
|
+
const SANDBOX_GUARDED_FILE_TOOLS = new Map([
|
|
340
|
+
["Write", "file_path"],
|
|
341
|
+
["Edit", "file_path"],
|
|
342
|
+
["MultiEdit", "file_path"],
|
|
343
|
+
["NotebookEdit", "notebook_path"],
|
|
344
|
+
]);
|
|
345
|
+
function isInsidePath(target, root) {
|
|
346
|
+
const relative = path.relative(root, target);
|
|
347
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
348
|
+
}
|
|
349
|
+
function createSandboxFileGuard(writableRoots, workingDirectory) {
|
|
350
|
+
const roots = [workingDirectory, ...writableRoots];
|
|
351
|
+
const guard = async (input) => {
|
|
352
|
+
if (input.hook_event_name !== "PreToolUse")
|
|
353
|
+
return {};
|
|
354
|
+
const pathKey = SANDBOX_GUARDED_FILE_TOOLS.get(input.tool_name);
|
|
355
|
+
if (!pathKey || !isRecord(input.tool_input))
|
|
356
|
+
return {};
|
|
357
|
+
const rawPath = input.tool_input[pathKey];
|
|
358
|
+
if (typeof rawPath !== "string")
|
|
359
|
+
return {};
|
|
360
|
+
const target = path.resolve(workingDirectory, rawPath);
|
|
361
|
+
if (roots.some((root) => isInsidePath(target, root)))
|
|
362
|
+
return {};
|
|
363
|
+
return {
|
|
364
|
+
decision: "block",
|
|
365
|
+
reason: `Blocked by isolation: ${rawPath} is outside the sandbox writable paths`,
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
return { matcher: [...SANDBOX_GUARDED_FILE_TOOLS.keys()].join("|"), hooks: [guard] };
|
|
369
|
+
}
|
|
370
|
+
function buildQueryOptions(params) {
|
|
371
|
+
const { options } = params;
|
|
372
|
+
const permissionMode = toClaudePermissionMode(options.cliMode);
|
|
373
|
+
const isPlanMode = permissionMode === "plan";
|
|
374
|
+
const isBypass = permissionMode === "bypassPermissions";
|
|
375
|
+
// Profile provider key (Bedrock/Mantle): the env inherited from connect is
|
|
376
|
+
// not enough — settingSources loads ~/.claude/settings.json, whose `env`
|
|
377
|
+
// overrides process env inside Claude Code. `--settings` outranks user
|
|
378
|
+
// settings, so the provider env is re-sent through that layer too.
|
|
379
|
+
const providerSettingsJson = buildProviderSettingsJson(process.env[CLAUDE_PROVIDER_ENV_VAR]);
|
|
380
|
+
// Agent prompt delivery (system-append, OS-1138): the bound agent's prompt
|
|
381
|
+
// snapshot is appended to the claude_code preset on EVERY run — appends do
|
|
382
|
+
// not survive --resume. The agent prompt comes first; plan-mode
|
|
383
|
+
// instructions follow so run-mode rules take precedence over the persona.
|
|
384
|
+
const systemPromptAppend = [
|
|
385
|
+
options.agentPrompt,
|
|
386
|
+
isPlanMode ? PLAN_MODE_SYSTEM_PROMPT : undefined,
|
|
387
|
+
// Thread identity (OS-1223): appended every run so resumes keep it too.
|
|
388
|
+
threadIdentityInstruction(options.threadId),
|
|
389
|
+
]
|
|
390
|
+
.filter((part) => typeof part === "string" && part.length > 0)
|
|
391
|
+
.join("\n\n");
|
|
392
|
+
return {
|
|
393
|
+
...(params.includePartialMessages ? { includePartialMessages: true } : {}),
|
|
394
|
+
cwd: params.workingDirectory,
|
|
395
|
+
pathToClaudeCodeExecutable: params.executablePath,
|
|
396
|
+
abortController: params.abortController,
|
|
397
|
+
// Parity with invoking the user's `claude` CLI directly: load the user's
|
|
398
|
+
// settings/CLAUDE.md and the default Claude Code prompt and tool set.
|
|
399
|
+
// The Agent SDK defaults to isolation mode (no filesystem settings).
|
|
400
|
+
settingSources: ["user", "project", "local"],
|
|
401
|
+
systemPrompt: systemPromptAppend.length > 0
|
|
402
|
+
? { type: "preset", preset: "claude_code", append: systemPromptAppend }
|
|
403
|
+
: { type: "preset", preset: "claude_code" },
|
|
404
|
+
tools: { type: "preset", preset: "claude_code" },
|
|
405
|
+
permissionMode,
|
|
406
|
+
...(isBypass ? { allowDangerouslySkipPermissions: true } : {}),
|
|
407
|
+
...(params.canUseTool ? { canUseTool: params.canUseTool } : {}),
|
|
408
|
+
...(options.resolvedCliModel ? { model: options.resolvedCliModel } : {}),
|
|
409
|
+
...(isClaudeEffortLevel(options.resolvedCliEffort)
|
|
410
|
+
? { effort: options.resolvedCliEffort }
|
|
411
|
+
: {}),
|
|
412
|
+
...(options.continuationId
|
|
413
|
+
? { resume: options.continuationId, forkSession: true }
|
|
414
|
+
: {}),
|
|
415
|
+
// Isolation (OS-1242): OS-level sandbox (Seatbelt/bubblewrap) with the profile paths as the
|
|
416
|
+
// write boundary; the cwd is writable natively. failIfUnavailable stays at the SDK default —
|
|
417
|
+
// the user opted in, so a machine that cannot sandbox fails loudly instead of running open.
|
|
418
|
+
// additionalDirectories lets file tools cross between profile paths.
|
|
419
|
+
...(params.sandbox
|
|
420
|
+
? {
|
|
421
|
+
sandbox: {
|
|
422
|
+
enabled: true,
|
|
423
|
+
// The model can otherwise set `dangerouslyDisableSandbox` on a Bash call to escape
|
|
424
|
+
// (verified: in agent/bypass mode it runs with no prompt). false makes the SDK ignore
|
|
425
|
+
// that flag — the load-bearing part of isolation, without which a hostile prompt just
|
|
426
|
+
// opts out.
|
|
427
|
+
allowUnsandboxedCommands: false,
|
|
428
|
+
filesystem: { allowWrite: params.sandbox.writableRoots },
|
|
429
|
+
},
|
|
430
|
+
additionalDirectories: params.sandbox.writableRoots,
|
|
431
|
+
hooks: {
|
|
432
|
+
PreToolUse: [
|
|
433
|
+
createSandboxFileGuard(params.sandbox.writableRoots, params.workingDirectory),
|
|
434
|
+
],
|
|
435
|
+
},
|
|
436
|
+
}
|
|
437
|
+
: {}),
|
|
438
|
+
...(providerSettingsJson
|
|
439
|
+
? { extraArgs: { settings: providerSettingsJson } }
|
|
440
|
+
: {}),
|
|
441
|
+
env: buildClaudeSubprocessEnv(options.threadId),
|
|
442
|
+
stderr: (data) => {
|
|
443
|
+
appendStderrTail(params.stderrTail, data);
|
|
444
|
+
debugLog("stderr", data);
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function summarizeResultMessage(message) {
|
|
449
|
+
if (message.type !== "result") {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
const record = message;
|
|
453
|
+
const subtype = typeof record.subtype === "string" ? record.subtype : "unknown";
|
|
454
|
+
const isError = record.is_error === true || subtype !== "success";
|
|
455
|
+
const errors = Array.isArray(record.errors)
|
|
456
|
+
? record.errors.filter((value) => typeof value === "string")
|
|
457
|
+
: [];
|
|
458
|
+
return {
|
|
459
|
+
subtype,
|
|
460
|
+
isError,
|
|
461
|
+
...(errors.length > 0 ? { errorText: errors.join("; ") } : {}),
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Snapshot the context-window usage after a completed turn. The result message's `usage`
|
|
466
|
+
* is cumulative API usage for the whole run, so live context size must come from the SDK
|
|
467
|
+
* `get_context_usage` control request. Any failure (closed control channel, older Claude,
|
|
468
|
+
* invalid values) skips the snapshot without failing the run; the meter keeps its last
|
|
469
|
+
* valid value.
|
|
470
|
+
*/
|
|
471
|
+
async function fetchContextUsageChunk(run) {
|
|
472
|
+
try {
|
|
473
|
+
const usage = await run.getContextUsage();
|
|
474
|
+
const usedTokens = usage.totalTokens;
|
|
475
|
+
const maxTokens = usage.maxTokens;
|
|
476
|
+
if (!Number.isFinite(usedTokens) ||
|
|
477
|
+
usedTokens <= 0 ||
|
|
478
|
+
!Number.isFinite(maxTokens) ||
|
|
479
|
+
maxTokens <= 0) {
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
type: CONTEXT_USAGE_CHUNK_TYPE,
|
|
484
|
+
data: JSON.stringify({
|
|
485
|
+
type: CONTEXT_USAGE_CHUNK_TYPE,
|
|
486
|
+
usedTokens,
|
|
487
|
+
maxTokens,
|
|
488
|
+
}),
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
debugLog("context_usage_error", error instanceof Error ? error.message : String(error));
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const TIMED_OUT = Symbol("timed-out");
|
|
497
|
+
/** A silent wait for background agents outlived its ceiling (OS-1661). */
|
|
498
|
+
const BACKGROUND_WAIT_EXPIRED = Symbol("background-wait-expired");
|
|
499
|
+
/**
|
|
500
|
+
* Pull the next SDK message, failing the run when the stream stays silent past the
|
|
501
|
+
* startup/idle deadline — the Agent SDK has no built-in inactivity guard.
|
|
502
|
+
*
|
|
503
|
+
* A run blocked in `canUseTool` awaiting a web approval, or holding a finished turn open
|
|
504
|
+
* for a live background agent, emits nothing while it waits — which is not idleness
|
|
505
|
+
* (OS-1458, OS-1661): the deadline re-arms for as long as `onSilence()` says to wait.
|
|
506
|
+
*/
|
|
507
|
+
async function nextMessageWithTimeout(iterator, timeoutMs, reason, stderrTail, onSilence) {
|
|
508
|
+
const next = iterator.next();
|
|
509
|
+
while (true) {
|
|
510
|
+
let timer;
|
|
511
|
+
const timeout = new Promise((resolve) => {
|
|
512
|
+
timer = setTimeout(() => resolve(TIMED_OUT), timeoutMs);
|
|
513
|
+
timer.unref?.();
|
|
514
|
+
});
|
|
515
|
+
try {
|
|
516
|
+
const settled = await Promise.race([next, timeout]);
|
|
517
|
+
if (settled !== TIMED_OUT) {
|
|
518
|
+
return settled;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
finally {
|
|
522
|
+
if (timer) {
|
|
523
|
+
clearTimeout(timer);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
const verdict = onSilence?.() ?? "fail";
|
|
527
|
+
if (verdict === "background_expired") {
|
|
528
|
+
return BACKGROUND_WAIT_EXPIRED;
|
|
529
|
+
}
|
|
530
|
+
if (verdict === "fail") {
|
|
531
|
+
throw new RunnerExecutionError(formatRunFailure({ reason, stderrTail }));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Create a runner that streams lines from a JSONL file.
|
|
537
|
+
* Each non-empty line is yielded as a ContentChunk with a delay.
|
|
538
|
+
*/
|
|
539
|
+
export function createFileStreamRunner(filePath, options) {
|
|
540
|
+
const delayMs = options?.delayMs ?? STREAM_DELAY_MS;
|
|
541
|
+
let aborted = false;
|
|
542
|
+
return {
|
|
543
|
+
async *execute(_workingDirectory, _prompt, options) {
|
|
544
|
+
aborted = false;
|
|
545
|
+
let continuationId;
|
|
546
|
+
// Validate file exists before starting.
|
|
547
|
+
await access(filePath, constants.R_OK);
|
|
548
|
+
const rl = createInterface({
|
|
549
|
+
input: createReadStream(filePath, { encoding: "utf-8" }),
|
|
550
|
+
crlfDelay: Infinity,
|
|
551
|
+
});
|
|
552
|
+
for await (const line of rl) {
|
|
553
|
+
if (aborted) {
|
|
554
|
+
rl.close();
|
|
555
|
+
return {};
|
|
556
|
+
}
|
|
557
|
+
const trimmed = line.trim();
|
|
558
|
+
if (trimmed === "")
|
|
559
|
+
continue;
|
|
560
|
+
try {
|
|
561
|
+
const parsed = JSON.parse(trimmed);
|
|
562
|
+
const nextContinuation = extractClaudeCodeContinuationId(parsed);
|
|
563
|
+
if (nextContinuation) {
|
|
564
|
+
continuationId = nextContinuation;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
catch {
|
|
568
|
+
// ignore malformed JSON in fixture lines; chunk still streams through.
|
|
569
|
+
}
|
|
570
|
+
yield { type: parseChunkType(trimmed), data: trimmed };
|
|
571
|
+
if (delayMs > 0)
|
|
572
|
+
await sleep(delayMs);
|
|
573
|
+
}
|
|
574
|
+
if (!continuationId && options.requireContinuation) {
|
|
575
|
+
throw new RunnerExecutionError("Claude run completed without session_id/sessionId in stream-json output");
|
|
576
|
+
}
|
|
577
|
+
return continuationId ? { continuationId } : {};
|
|
578
|
+
},
|
|
579
|
+
abort() {
|
|
580
|
+
aborted = true;
|
|
581
|
+
},
|
|
582
|
+
async shutdown() {
|
|
583
|
+
aborted = true;
|
|
584
|
+
},
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Create a Claude Code runner backed by `@anthropic-ai/claude-agent-sdk`.
|
|
589
|
+
*
|
|
590
|
+
* The SDK spawns the user's installed `claude` binary (never a bundled CLI) and yields
|
|
591
|
+
* `SDKMessage` objects byte-equivalent to the CLI's stream-json output, so each is
|
|
592
|
+
* re-serialized into the existing `ContentChunk` pipeline unchanged.
|
|
593
|
+
*/
|
|
594
|
+
export function createClaudeCodeRunner(runnerOptions) {
|
|
595
|
+
const createQuery = runnerOptions?.createQuery ?? query;
|
|
596
|
+
let activeQuery = null;
|
|
597
|
+
let activeAbortController = null;
|
|
598
|
+
let activeRunInteractive = false;
|
|
599
|
+
/**
|
|
600
|
+
* Steering state for the active open-input run. Claude Code absorbs messages pushed
|
|
601
|
+
* mid-turn into the current turn (no extra `result`), but one pushed after the turn
|
|
602
|
+
* finalized queues a new turn. So instead of counting results, a steered run seeing a
|
|
603
|
+
* `result` closes the input (EOF) and drains, letting the CLI finish any queued turn.
|
|
604
|
+
*/
|
|
605
|
+
let activeSteer = null;
|
|
606
|
+
let hardAbortTimer = null;
|
|
607
|
+
let closed = false;
|
|
608
|
+
/**
|
|
609
|
+
* Set when abort was requested for the active run. A graceful interrupt of
|
|
610
|
+
* a turn parked on an unresolved tool call (plan approval, question) makes
|
|
611
|
+
* the CLI end the turn with an `error_during_execution` result
|
|
612
|
+
* (`[ede_diagnostic] … stop_reason=tool_use`) — self-inflicted, not a run
|
|
613
|
+
* failure (OS-1463).
|
|
614
|
+
*/
|
|
615
|
+
let abortRequested = false;
|
|
616
|
+
function clearHardAbortTimer() {
|
|
617
|
+
if (hardAbortTimer) {
|
|
618
|
+
clearTimeout(hardAbortTimer);
|
|
619
|
+
hardAbortTimer = null;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
function hardAbort() {
|
|
623
|
+
activeAbortController?.abort();
|
|
624
|
+
try {
|
|
625
|
+
activeQuery?.close();
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
// best-effort close; the abort signal is the primary cancellation path.
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function abortActiveRun() {
|
|
632
|
+
abortRequested = true;
|
|
633
|
+
const run = activeQuery;
|
|
634
|
+
if (run && activeRunInteractive) {
|
|
635
|
+
// Graceful interrupt first (control protocol); the run yields a final
|
|
636
|
+
// result and ends cleanly, preserving the continuation id. Fall back to
|
|
637
|
+
// a hard abort if the stream does not end promptly.
|
|
638
|
+
void run.interrupt().catch(() => {
|
|
639
|
+
hardAbort();
|
|
640
|
+
});
|
|
641
|
+
if (!hardAbortTimer) {
|
|
642
|
+
hardAbortTimer = setTimeout(() => {
|
|
643
|
+
hardAbortTimer = null;
|
|
644
|
+
hardAbort();
|
|
645
|
+
}, 5_000);
|
|
646
|
+
hardAbortTimer.unref?.();
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
hardAbort();
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
async *execute(workingDirectory, prompt, options) {
|
|
654
|
+
if (closed) {
|
|
655
|
+
throw new Error("Claude runner is shut down");
|
|
656
|
+
}
|
|
657
|
+
if (options.cliType !== "claude-code") {
|
|
658
|
+
throw new Error(`Unsupported cliType "${options.cliType}" for SDK runner. Only "claude-code" is supported.`);
|
|
659
|
+
}
|
|
660
|
+
const abortController = new AbortController();
|
|
661
|
+
activeAbortController = abortController;
|
|
662
|
+
abortRequested = false;
|
|
663
|
+
const stderrTail = [];
|
|
664
|
+
let continuationId;
|
|
665
|
+
let resultSummary = null;
|
|
666
|
+
let openInput = null;
|
|
667
|
+
let inputEnded = false;
|
|
668
|
+
try {
|
|
669
|
+
const executable = await resolveClaudeExecutablePath();
|
|
670
|
+
const bootstrapMessages = options.inputFormat === "stream-json"
|
|
671
|
+
? toSdkUserMessages(options.bootstrapInput ?? [])
|
|
672
|
+
: [];
|
|
673
|
+
if (options.inputFormat === "stream-json" && bootstrapMessages.length === 0) {
|
|
674
|
+
throw new Error("Claude stream-json input requires bootstrapInput frames");
|
|
675
|
+
}
|
|
676
|
+
// Interactive approvals need the SDK control channel, which only works in streaming
|
|
677
|
+
// input mode with the input kept open. Bypass/`agent` mode installs it too: the SDK
|
|
678
|
+
// short-circuits bypass for ordinary tools, but `requiresUserInteraction` ones
|
|
679
|
+
// (AskUserQuestion, ExitPlanMode) still route through canUseTool, and without it they
|
|
680
|
+
// resolve unanswered — the agent asks a question and walks straight past it.
|
|
681
|
+
const interactive = options.interactionBridge !== undefined;
|
|
682
|
+
// Steering also needs the input held open; any open-input run gets the
|
|
683
|
+
// graceful interrupt() abort path.
|
|
684
|
+
const openEnded = interactive || options.steerEnabled === true;
|
|
685
|
+
activeRunInteractive = openEnded;
|
|
686
|
+
// Counts requests parked on the user so the idle deadline can tell
|
|
687
|
+
// "the user is deciding" from "the agent went silent" (OS-1458).
|
|
688
|
+
let pendingInteractions = 0;
|
|
689
|
+
const bridge = options.interactionBridge;
|
|
690
|
+
const canUseTool = interactive && bridge
|
|
691
|
+
? createClaudeCanUseTool({
|
|
692
|
+
bridge: {
|
|
693
|
+
...bridge,
|
|
694
|
+
request: async (input, signal) => {
|
|
695
|
+
pendingInteractions += 1;
|
|
696
|
+
try {
|
|
697
|
+
return await bridge.request(input, signal);
|
|
698
|
+
}
|
|
699
|
+
finally {
|
|
700
|
+
pendingInteractions -= 1;
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
getActiveQuery: () => activeQuery,
|
|
705
|
+
})
|
|
706
|
+
: null;
|
|
707
|
+
const queryOptions = buildQueryOptions({
|
|
708
|
+
workingDirectory,
|
|
709
|
+
executablePath: executable.command,
|
|
710
|
+
options,
|
|
711
|
+
abortController,
|
|
712
|
+
stderrTail,
|
|
713
|
+
includePartialMessages: runnerOptions?.includePartialMessages ?? false,
|
|
714
|
+
canUseTool,
|
|
715
|
+
sandbox: runnerOptions?.sandbox,
|
|
716
|
+
});
|
|
717
|
+
debugQueryStart({
|
|
718
|
+
executable: executable.command,
|
|
719
|
+
executableSource: executable.source,
|
|
720
|
+
cwd: workingDirectory,
|
|
721
|
+
permissionMode: queryOptions.permissionMode ?? "default",
|
|
722
|
+
model: queryOptions.model,
|
|
723
|
+
resumeSessionId: options.continuationId,
|
|
724
|
+
inputFormat: openEnded || options.inputFormat === "stream-json"
|
|
725
|
+
? "stream-json"
|
|
726
|
+
: "prompt",
|
|
727
|
+
});
|
|
728
|
+
let promptInput;
|
|
729
|
+
if (openEnded) {
|
|
730
|
+
const frames = options.inputFormat === "stream-json"
|
|
731
|
+
? bootstrapMessages
|
|
732
|
+
: [promptToSdkUserMessage(prompt)];
|
|
733
|
+
const open = createOpenEndedInput(frames);
|
|
734
|
+
openInput = open;
|
|
735
|
+
promptInput = open.iterable;
|
|
736
|
+
if (options.steerEnabled === true) {
|
|
737
|
+
activeSteer = { push: open.push, pushedFrames: false };
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
else if (options.inputFormat === "stream-json") {
|
|
741
|
+
promptInput = toAsyncIterable(bootstrapMessages);
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
promptInput = prompt;
|
|
745
|
+
}
|
|
746
|
+
const run = createQuery({
|
|
747
|
+
prompt: promptInput,
|
|
748
|
+
options: queryOptions,
|
|
749
|
+
});
|
|
750
|
+
activeQuery = run;
|
|
751
|
+
const iterator = run[Symbol.asyncIterator]();
|
|
752
|
+
let sawFirstMessage = false;
|
|
753
|
+
// Background agents run in-process, so ending the turn kills them (OS-1661).
|
|
754
|
+
const spawnedBackgroundTaskIds = new Set();
|
|
755
|
+
let liveBackgroundTaskIds = new Set();
|
|
756
|
+
let backgroundWaitDeadline = null;
|
|
757
|
+
// Only tasks this turn spawned via a tool call count. Intersected on read, not on
|
|
758
|
+
// arrival: the snapshot can precede the `task_started` for the same id.
|
|
759
|
+
const liveSpawnedCount = () => {
|
|
760
|
+
let count = 0;
|
|
761
|
+
for (const taskId of liveBackgroundTaskIds) {
|
|
762
|
+
if (spawnedBackgroundTaskIds.has(taskId))
|
|
763
|
+
count += 1;
|
|
764
|
+
}
|
|
765
|
+
return count;
|
|
766
|
+
};
|
|
767
|
+
const backgroundWaitExpired = () => backgroundWaitDeadline !== null && Date.now() >= backgroundWaitDeadline;
|
|
768
|
+
// An abort ends the turn at the next result: waiting on background agents would
|
|
769
|
+
// strand the graceful interrupt that preserves the continuation id (OS-1463).
|
|
770
|
+
const holdingForBackgroundAgents = () => liveSpawnedCount() > 0 && !abortRequested && !backgroundWaitExpired();
|
|
771
|
+
while (true) {
|
|
772
|
+
const next = await nextMessageWithTimeout(iterator, sawFirstMessage ? IDLE_TIMEOUT_MS : STARTUP_TIMEOUT_MS, sawFirstMessage ? "timeout_idle" : "timeout_startup", stderrTail,
|
|
773
|
+
// A background agent can work far longer than the idle timeout without
|
|
774
|
+
// emitting anything the parent sees, so it re-arms the deadline the same
|
|
775
|
+
// way a request parked on the user does (OS-1458, OS-1661).
|
|
776
|
+
() => {
|
|
777
|
+
if (pendingInteractions > 0)
|
|
778
|
+
return "wait";
|
|
779
|
+
if (liveSpawnedCount() === 0 || abortRequested)
|
|
780
|
+
return "fail";
|
|
781
|
+
return backgroundWaitExpired() ? "background_expired" : "wait";
|
|
782
|
+
});
|
|
783
|
+
// A silent hold that outlived the ceiling ends the turn with a notice rather
|
|
784
|
+
// than the generic `timeout_idle` this would otherwise surface as.
|
|
785
|
+
if (next === BACKGROUND_WAIT_EXPIRED) {
|
|
786
|
+
yield backgroundWaitTimeoutChunk(liveSpawnedCount());
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
if (next.done) {
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
sawFirstMessage = true;
|
|
793
|
+
const message = next.value;
|
|
794
|
+
const data = JSON.stringify(message);
|
|
795
|
+
debugLog(message.type, data);
|
|
796
|
+
const spawnedTaskId = readSpawnedBackgroundTaskId(message);
|
|
797
|
+
if (spawnedTaskId) {
|
|
798
|
+
spawnedBackgroundTaskIds.add(spawnedTaskId);
|
|
799
|
+
}
|
|
800
|
+
const liveSnapshot = readLiveBackgroundTaskIds(message);
|
|
801
|
+
if (liveSnapshot) {
|
|
802
|
+
liveBackgroundTaskIds = liveSnapshot;
|
|
803
|
+
}
|
|
804
|
+
// Armed on first sight rather than at the result: the ceiling has to bound the
|
|
805
|
+
// idle re-arm above too, or a turn that goes silent mid-agent waits forever.
|
|
806
|
+
const liveCount = liveSpawnedCount();
|
|
807
|
+
backgroundWaitDeadline =
|
|
808
|
+
liveCount === 0
|
|
809
|
+
? null
|
|
810
|
+
: (backgroundWaitDeadline ?? Date.now() + BACKGROUND_AGENT_WAIT_MS);
|
|
811
|
+
// Checked every iteration, not only at a `result`: an agent emitting
|
|
812
|
+
// `task_progress` keeps the loop busy, so a result-only check never fires.
|
|
813
|
+
if (liveCount > 0 && backgroundWaitExpired()) {
|
|
814
|
+
yield backgroundWaitTimeoutChunk(liveCount);
|
|
815
|
+
activeSteer = null;
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
const nextContinuation = extractClaudeCodeContinuationId(message);
|
|
819
|
+
if (nextContinuation) {
|
|
820
|
+
continuationId = nextContinuation;
|
|
821
|
+
}
|
|
822
|
+
resultSummary = summarizeResultMessage(message) ?? resultSummary;
|
|
823
|
+
yield {
|
|
824
|
+
type: typeof message.type === "string" ? message.type : "unknown",
|
|
825
|
+
data,
|
|
826
|
+
};
|
|
827
|
+
// Each completed turn gets a current-context snapshot, queried
|
|
828
|
+
// while the SDK control channel is still alive (before the
|
|
829
|
+
// open-input end/break below tears the run down).
|
|
830
|
+
if (message.type === "result") {
|
|
831
|
+
const contextUsageChunk = await fetchContextUsageChunk(run);
|
|
832
|
+
if (contextUsageChunk) {
|
|
833
|
+
debugLog(contextUsageChunk.type, contextUsageChunk.data);
|
|
834
|
+
yield contextUsageChunk;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
// With an open-ended input stream the session would idle waiting for more user
|
|
838
|
+
// messages after the turn, so an unsteered run ends at its first result. A steered run
|
|
839
|
+
// cannot map results to pushed frames (mid-turn pushes are absorbed into the running
|
|
840
|
+
// turn), so it closes the input and drains to natural completion — letting the CLI
|
|
841
|
+
// finish any turn still queued from a late push.
|
|
842
|
+
if (message.type === "result" && openInput && !inputEnded) {
|
|
843
|
+
// A live background agent means the session is not idle — it has in-process work
|
|
844
|
+
// that ending the turn would kill, losing its output and making the next resume
|
|
845
|
+
// synthesize a "was running when the previous process exited" failure.
|
|
846
|
+
// Spec: docs/specs/cli-sdk-integration.md (OS-1661).
|
|
847
|
+
if (holdingForBackgroundAgents()) {
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
const steered = activeSteer?.pushedFrames === true;
|
|
851
|
+
activeSteer = null;
|
|
852
|
+
if (!steered) {
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
inputEnded = true;
|
|
856
|
+
openInput.end();
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// An error result on a run we interrupted ourselves is self-inflicted: gracefully
|
|
860
|
+
// interrupting a turn parked on an unresolved tool call makes the CLI end with
|
|
861
|
+
// `error_during_execution` / `stop_reason=tool_use`. The run wound down as intended, and
|
|
862
|
+
// surfacing it flashed a red "run failed" on a thread that is merely waiting (OS-1463).
|
|
863
|
+
if (resultSummary?.isError && !abortRequested) {
|
|
864
|
+
throw new RunnerExecutionError(formatRunFailure({
|
|
865
|
+
reason: `result_${resultSummary.subtype}`,
|
|
866
|
+
detail: resultSummary.errorText,
|
|
867
|
+
stderrTail,
|
|
868
|
+
}), { continuationId });
|
|
869
|
+
}
|
|
870
|
+
if (!continuationId && options.requireContinuation) {
|
|
871
|
+
throw new RunnerExecutionError("Claude run completed without session_id/sessionId in stream-json output");
|
|
872
|
+
}
|
|
873
|
+
return continuationId ? { continuationId } : {};
|
|
874
|
+
}
|
|
875
|
+
catch (error) {
|
|
876
|
+
if (error instanceof RunnerExecutionError) {
|
|
877
|
+
if (error.continuationId === undefined && continuationId) {
|
|
878
|
+
error.continuationId = continuationId;
|
|
879
|
+
}
|
|
880
|
+
throw error;
|
|
881
|
+
}
|
|
882
|
+
const reason = abortController.signal.aborted
|
|
883
|
+
? "cancelled_by_user"
|
|
884
|
+
: "sdk_error";
|
|
885
|
+
throw new RunnerExecutionError(formatRunFailure({
|
|
886
|
+
reason,
|
|
887
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
888
|
+
stderrTail,
|
|
889
|
+
}), { continuationId });
|
|
890
|
+
}
|
|
891
|
+
finally {
|
|
892
|
+
activeSteer = null;
|
|
893
|
+
openInput?.end();
|
|
894
|
+
clearHardAbortTimer();
|
|
895
|
+
try {
|
|
896
|
+
activeQuery?.close();
|
|
897
|
+
}
|
|
898
|
+
catch {
|
|
899
|
+
// stream already closed.
|
|
900
|
+
}
|
|
901
|
+
activeQuery = null;
|
|
902
|
+
activeAbortController = null;
|
|
903
|
+
activeRunInteractive = false;
|
|
904
|
+
}
|
|
905
|
+
},
|
|
906
|
+
steer(injection) {
|
|
907
|
+
const steerState = activeSteer;
|
|
908
|
+
if (!steerState) {
|
|
909
|
+
return false;
|
|
910
|
+
}
|
|
911
|
+
const frames = injection.inputFormat === "stream-json"
|
|
912
|
+
? toSdkUserMessages(injection.bootstrapInput ?? [])
|
|
913
|
+
: injection.prompt.length > 0
|
|
914
|
+
? [promptToSdkUserMessage(injection.prompt)]
|
|
915
|
+
: [];
|
|
916
|
+
if (frames.length === 0) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
// Mark before push: once the run loop observes a result it nulls activeSteer synchronously,
|
|
920
|
+
// so a successful steer() here is guaranteed to happen-before that decision and gets its
|
|
921
|
+
// frames processed — absorbed into the running turn, or queued and drained after input EOF.
|
|
922
|
+
steerState.pushedFrames = true;
|
|
923
|
+
steerState.push(frames);
|
|
924
|
+
return true;
|
|
925
|
+
},
|
|
926
|
+
abort() {
|
|
927
|
+
abortActiveRun();
|
|
928
|
+
},
|
|
929
|
+
async shutdown() {
|
|
930
|
+
closed = true;
|
|
931
|
+
abortActiveRun();
|
|
932
|
+
},
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Create a runner that streams from the built-in default fixture.
|
|
937
|
+
*/
|
|
938
|
+
export function createDefaultFixtureRunner() {
|
|
939
|
+
return createFileStreamRunner(DEFAULT_FIXTURE);
|
|
940
|
+
}
|
|
941
|
+
//# sourceMappingURL=runner.js.map
|