@cjhyy/code-shell-core 0.5.0-rc.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 +21 -0
- package/README.md +162 -0
- package/dist/agent/coordinator.d.ts +49 -0
- package/dist/agent/coordinator.js +77 -0
- package/dist/arena/arena.d.ts +43 -0
- package/dist/arena/arena.js +334 -0
- package/dist/arena/context/context-tools.d.ts +16 -0
- package/dist/arena/context/context-tools.js +231 -0
- package/dist/arena/detect-mode.d.ts +20 -0
- package/dist/arena/detect-mode.js +78 -0
- package/dist/arena/digest-builder.d.ts +25 -0
- package/dist/arena/digest-builder.js +120 -0
- package/dist/arena/index.d.ts +29 -0
- package/dist/arena/index.js +29 -0
- package/dist/arena/iterate/convergence.d.ts +25 -0
- package/dist/arena/iterate/convergence.js +103 -0
- package/dist/arena/iterate/formats/index.d.ts +22 -0
- package/dist/arena/iterate/formats/index.js +283 -0
- package/dist/arena/iterate/index.d.ts +11 -0
- package/dist/arena/iterate/index.js +9 -0
- package/dist/arena/iterate/iterative-arena.d.ts +23 -0
- package/dist/arena/iterate/iterative-arena.js +237 -0
- package/dist/arena/iterate/parse.d.ts +42 -0
- package/dist/arena/iterate/parse.js +123 -0
- package/dist/arena/iterate/phases/argue.d.ts +22 -0
- package/dist/arena/iterate/phases/argue.js +159 -0
- package/dist/arena/iterate/phases/revise.d.ts +16 -0
- package/dist/arena/iterate/phases/revise.js +62 -0
- package/dist/arena/iterate/phases/tournament.d.ts +34 -0
- package/dist/arena/iterate/phases/tournament.js +113 -0
- package/dist/arena/iterate/tools/web-tools.d.ts +13 -0
- package/dist/arena/iterate/tools/web-tools.js +54 -0
- package/dist/arena/iterate/types.d.ts +152 -0
- package/dist/arena/iterate/types.js +8 -0
- package/dist/arena/ledger.d.ts +47 -0
- package/dist/arena/ledger.js +151 -0
- package/dist/arena/lenses/architecture.d.ts +5 -0
- package/dist/arena/lenses/architecture.js +22 -0
- package/dist/arena/lenses/engineering.d.ts +5 -0
- package/dist/arena/lenses/engineering.js +22 -0
- package/dist/arena/lenses/general.d.ts +5 -0
- package/dist/arena/lenses/general.js +20 -0
- package/dist/arena/lenses/index.d.ts +16 -0
- package/dist/arena/lenses/index.js +47 -0
- package/dist/arena/lenses/product.d.ts +5 -0
- package/dist/arena/lenses/product.js +22 -0
- package/dist/arena/model-presets.d.ts +23 -0
- package/dist/arena/model-presets.js +44 -0
- package/dist/arena/phases/adjudication.d.ts +24 -0
- package/dist/arena/phases/adjudication.js +144 -0
- package/dist/arena/phases/build-consensus.d.ts +29 -0
- package/dist/arena/phases/build-consensus.js +86 -0
- package/dist/arena/phases/claim-registry.d.ts +26 -0
- package/dist/arena/phases/claim-registry.js +60 -0
- package/dist/arena/phases/cross-review.d.ts +45 -0
- package/dist/arena/phases/cross-review.js +224 -0
- package/dist/arena/phases/debate-rounds.d.ts +27 -0
- package/dist/arena/phases/debate-rounds.js +162 -0
- package/dist/arena/phases/participant-research.d.ts +38 -0
- package/dist/arena/phases/participant-research.js +317 -0
- package/dist/arena/phases/planning-detail-expansion.d.ts +38 -0
- package/dist/arena/phases/planning-detail-expansion.js +121 -0
- package/dist/arena/planner.d.ts +27 -0
- package/dist/arena/planner.js +312 -0
- package/dist/arena/providers/docs.d.ts +6 -0
- package/dist/arena/providers/docs.js +108 -0
- package/dist/arena/providers/git.d.ts +8 -0
- package/dist/arena/providers/git.js +174 -0
- package/dist/arena/providers/index.d.ts +32 -0
- package/dist/arena/providers/index.js +132 -0
- package/dist/arena/providers/none.d.ts +7 -0
- package/dist/arena/providers/none.js +11 -0
- package/dist/arena/providers/repo.d.ts +6 -0
- package/dist/arena/providers/repo.js +255 -0
- package/dist/arena/render/session.d.ts +17 -0
- package/dist/arena/render/session.js +190 -0
- package/dist/arena/render/terminal.d.ts +34 -0
- package/dist/arena/render/terminal.js +286 -0
- package/dist/arena/strategies/discussion.d.ts +25 -0
- package/dist/arena/strategies/discussion.js +143 -0
- package/dist/arena/strategies/index.d.ts +15 -0
- package/dist/arena/strategies/index.js +28 -0
- package/dist/arena/strategies/language-wrapper.d.ts +17 -0
- package/dist/arena/strategies/language-wrapper.js +102 -0
- package/dist/arena/strategies/lens-wrapper.d.ts +16 -0
- package/dist/arena/strategies/lens-wrapper.js +236 -0
- package/dist/arena/strategies/planning.d.ts +30 -0
- package/dist/arena/strategies/planning.js +225 -0
- package/dist/arena/strategies/review.d.ts +26 -0
- package/dist/arena/strategies/review.js +168 -0
- package/dist/arena/strategies/utils.d.ts +39 -0
- package/dist/arena/strategies/utils.js +647 -0
- package/dist/arena/tools/selector.d.ts +17 -0
- package/dist/arena/tools/selector.js +61 -0
- package/dist/arena/transitions.d.ts +48 -0
- package/dist/arena/transitions.js +92 -0
- package/dist/arena/types.d.ts +508 -0
- package/dist/arena/types.js +27 -0
- package/dist/cli/agent-server-stdio.d.ts +32 -0
- package/dist/cli/agent-server-stdio.js +116 -0
- package/dist/colorizer.d.ts +23 -0
- package/dist/colorizer.js +12 -0
- package/dist/context/compaction.d.ts +116 -0
- package/dist/context/compaction.js +534 -0
- package/dist/context/manager.d.ts +145 -0
- package/dist/context/manager.js +423 -0
- package/dist/context/token-counter.d.ts +27 -0
- package/dist/context/token-counter.js +91 -0
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/context/tool-result-storage.js +296 -0
- package/dist/cost-tracker.d.ts +64 -0
- package/dist/cost-tracker.js +314 -0
- package/dist/cron/scheduler.d.ts +34 -0
- package/dist/cron/scheduler.js +115 -0
- package/dist/data/deepseek-models.json +46 -0
- package/dist/data/gemini-models.json +67 -0
- package/dist/data/openai-models.json +175 -0
- package/dist/data/openrouter-models.d.ts +35 -0
- package/dist/data/openrouter-models.js +36 -0
- package/dist/data/openrouter-models.json +4626 -0
- package/dist/data/openrouter-sync.d.ts +16 -0
- package/dist/data/openrouter-sync.js +53 -0
- package/dist/data/static-catalogs.d.ts +25 -0
- package/dist/data/static-catalogs.js +26 -0
- package/dist/data/zai-models.json +56 -0
- package/dist/engine/cost-store.d.ts +22 -0
- package/dist/engine/cost-store.js +15 -0
- package/dist/engine/engine.d.ts +295 -0
- package/dist/engine/engine.js +1467 -0
- package/dist/engine/model-facade.d.ts +24 -0
- package/dist/engine/model-facade.js +194 -0
- package/dist/engine/parse-task.d.ts +59 -0
- package/dist/engine/parse-task.js +135 -0
- package/dist/engine/patch-orphaned-tools.d.ts +52 -0
- package/dist/engine/patch-orphaned-tools.js +95 -0
- package/dist/engine/query.d.ts +50 -0
- package/dist/engine/query.js +107 -0
- package/dist/engine/runtime.d.ts +50 -0
- package/dist/engine/runtime.js +59 -0
- package/dist/engine/streaming-tool-queue.d.ts +34 -0
- package/dist/engine/streaming-tool-queue.js +61 -0
- package/dist/engine/token-budget.d.ts +22 -0
- package/dist/engine/token-budget.js +40 -0
- package/dist/engine/tool-summary.d.ts +13 -0
- package/dist/engine/tool-summary.js +35 -0
- package/dist/engine/turn-loop.d.ts +122 -0
- package/dist/engine/turn-loop.js +602 -0
- package/dist/engine/turn-state.d.ts +20 -0
- package/dist/engine/turn-state.js +17 -0
- package/dist/exceptions.d.ts +61 -0
- package/dist/exceptions.js +116 -0
- package/dist/git/utils.d.ts +35 -0
- package/dist/git/utils.js +98 -0
- package/dist/git/worktree.d.ts +36 -0
- package/dist/git/worktree.js +139 -0
- package/dist/hooks/events.d.ts +114 -0
- package/dist/hooks/events.js +4 -0
- package/dist/hooks/inject.d.ts +19 -0
- package/dist/hooks/inject.js +29 -0
- package/dist/hooks/registry.d.ts +15 -0
- package/dist/hooks/registry.js +84 -0
- package/dist/hooks/shell-runner.d.ts +45 -0
- package/dist/hooks/shell-runner.js +173 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +145 -0
- package/dist/llm/api-key-sanitize.d.ts +22 -0
- package/dist/llm/api-key-sanitize.js +81 -0
- package/dist/llm/capabilities/index.d.ts +20 -0
- package/dist/llm/capabilities/index.js +39 -0
- package/dist/llm/capabilities/rules.d.ts +26 -0
- package/dist/llm/capabilities/rules.js +215 -0
- package/dist/llm/capabilities/types.d.ts +114 -0
- package/dist/llm/capabilities/types.js +24 -0
- package/dist/llm/client-base.d.ts +29 -0
- package/dist/llm/client-base.js +137 -0
- package/dist/llm/client-factory.d.ts +10 -0
- package/dist/llm/client-factory.js +29 -0
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-cache.js +46 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-fetcher.js +282 -0
- package/dist/llm/model-pool.d.ts +95 -0
- package/dist/llm/model-pool.js +246 -0
- package/dist/llm/provider-catalog.d.ts +32 -0
- package/dist/llm/provider-catalog.js +50 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/provider-kinds.js +132 -0
- package/dist/llm/providers/anthropic.d.ts +19 -0
- package/dist/llm/providers/anthropic.js +267 -0
- package/dist/llm/providers/openai.d.ts +64 -0
- package/dist/llm/providers/openai.js +606 -0
- package/dist/llm/retry.d.ts +12 -0
- package/dist/llm/retry.js +17 -0
- package/dist/llm/stream-watchdog.d.ts +42 -0
- package/dist/llm/stream-watchdog.js +70 -0
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/llm/token-counter.js +36 -0
- package/dist/llm/types.d.ts +37 -0
- package/dist/llm/types.js +4 -0
- package/dist/logging/logger.d.ts +109 -0
- package/dist/logging/logger.js +390 -0
- package/dist/logging/sanitize-messages.d.ts +42 -0
- package/dist/logging/sanitize-messages.js +150 -0
- package/dist/logging/session-recorder.d.ts +90 -0
- package/dist/logging/session-recorder.js +304 -0
- package/dist/lsp/client.d.ts +41 -0
- package/dist/lsp/client.js +166 -0
- package/dist/lsp/manager.d.ts +40 -0
- package/dist/lsp/manager.js +124 -0
- package/dist/lsp/servers.d.ts +16 -0
- package/dist/lsp/servers.js +60 -0
- package/dist/migrate-models.d.ts +45 -0
- package/dist/migrate-models.js +179 -0
- package/dist/onboarding.d.ts +189 -0
- package/dist/onboarding.js +625 -0
- package/dist/plugins/gitOps.d.ts +32 -0
- package/dist/plugins/gitOps.js +62 -0
- package/dist/plugins/installedPlugins.d.ts +15 -0
- package/dist/plugins/installedPlugins.js +56 -0
- package/dist/plugins/knownMarketplaces.d.ts +10 -0
- package/dist/plugins/knownMarketplaces.js +46 -0
- package/dist/plugins/loadPluginHooks.d.ts +52 -0
- package/dist/plugins/loadPluginHooks.js +162 -0
- package/dist/plugins/marketplaceManager.d.ts +49 -0
- package/dist/plugins/marketplaceManager.js +142 -0
- package/dist/plugins/parseMarketplaceInput.d.ts +16 -0
- package/dist/plugins/parseMarketplaceInput.js +73 -0
- package/dist/plugins/pluginCommandHook.d.ts +54 -0
- package/dist/plugins/pluginCommandHook.js +180 -0
- package/dist/plugins/pluginCommandsLoader.d.ts +25 -0
- package/dist/plugins/pluginCommandsLoader.js +114 -0
- package/dist/plugins/pluginInstaller.d.ts +36 -0
- package/dist/plugins/pluginInstaller.js +228 -0
- package/dist/plugins/schemas.d.ts +9 -0
- package/dist/plugins/schemas.js +136 -0
- package/dist/plugins/types.d.ts +75 -0
- package/dist/plugins/types.js +7 -0
- package/dist/plugins/varRewrite.d.ts +42 -0
- package/dist/plugins/varRewrite.js +129 -0
- package/dist/preset/index.d.ts +60 -0
- package/dist/preset/index.js +159 -0
- package/dist/product/define.d.ts +60 -0
- package/dist/product/define.js +123 -0
- package/dist/product/index.d.ts +5 -0
- package/dist/product/index.js +4 -0
- package/dist/product/types.d.ts +111 -0
- package/dist/product/types.js +21 -0
- package/dist/prompt/composer.d.ts +49 -0
- package/dist/prompt/composer.js +168 -0
- package/dist/prompt/instruction-scanner.d.ts +54 -0
- package/dist/prompt/instruction-scanner.js +187 -0
- package/dist/prompt/section-cache.d.ts +15 -0
- package/dist/prompt/section-cache.js +31 -0
- package/dist/prompt/section-loader.d.ts +26 -0
- package/dist/prompt/section-loader.js +53 -0
- package/dist/prompt/sections/base.md +35 -0
- package/dist/prompt/sections/coding.md +31 -0
- package/dist/prompt/sections/orchestration.md +16 -0
- package/dist/prompt/sections/tone.md +9 -0
- package/dist/protocol/chat-session-manager.d.ts +33 -0
- package/dist/protocol/chat-session-manager.js +65 -0
- package/dist/protocol/chat-session.d.ts +49 -0
- package/dist/protocol/chat-session.js +86 -0
- package/dist/protocol/client.d.ts +104 -0
- package/dist/protocol/client.js +260 -0
- package/dist/protocol/factories.d.ts +93 -0
- package/dist/protocol/factories.js +64 -0
- package/dist/protocol/helpers.d.ts +42 -0
- package/dist/protocol/helpers.js +55 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +4 -0
- package/dist/protocol/server.d.ts +80 -0
- package/dist/protocol/server.js +855 -0
- package/dist/protocol/transport.d.ts +37 -0
- package/dist/protocol/transport.js +85 -0
- package/dist/protocol/types.d.ts +221 -0
- package/dist/protocol/types.js +61 -0
- package/dist/remote/bridge.d.ts +37 -0
- package/dist/remote/bridge.js +103 -0
- package/dist/run/ArtifactTracker.d.ts +38 -0
- package/dist/run/ArtifactTracker.js +132 -0
- package/dist/run/CheckpointWriter.d.ts +53 -0
- package/dist/run/CheckpointWriter.js +135 -0
- package/dist/run/EngineRunner.d.ts +72 -0
- package/dist/run/EngineRunner.js +119 -0
- package/dist/run/Evaluator.d.ts +56 -0
- package/dist/run/Evaluator.js +62 -0
- package/dist/run/FileRunStore.d.ts +39 -0
- package/dist/run/FileRunStore.js +176 -0
- package/dist/run/Heartbeat.d.ts +54 -0
- package/dist/run/Heartbeat.js +123 -0
- package/dist/run/RunApprovalBackend.d.ts +53 -0
- package/dist/run/RunApprovalBackend.js +85 -0
- package/dist/run/RunLock.d.ts +40 -0
- package/dist/run/RunLock.js +98 -0
- package/dist/run/RunManager.d.ts +82 -0
- package/dist/run/RunManager.js +587 -0
- package/dist/run/RunQueue.d.ts +27 -0
- package/dist/run/RunQueue.js +73 -0
- package/dist/run/RunStore.d.ts +25 -0
- package/dist/run/RunStore.js +9 -0
- package/dist/run/factory.d.ts +63 -0
- package/dist/run/factory.js +51 -0
- package/dist/run/index.d.ts +17 -0
- package/dist/run/index.js +23 -0
- package/dist/run/types.d.ts +136 -0
- package/dist/run/types.js +28 -0
- package/dist/runtime/safe-spawn.d.ts +118 -0
- package/dist/runtime/safe-spawn.js +268 -0
- package/dist/services/analytics.d.ts +29 -0
- package/dist/services/analytics.js +84 -0
- package/dist/services/auto-dream.d.ts +49 -0
- package/dist/services/auto-dream.js +124 -0
- package/dist/services/diagnostics.d.ts +41 -0
- package/dist/services/diagnostics.js +99 -0
- package/dist/services/extract-memories.d.ts +31 -0
- package/dist/services/extract-memories.js +71 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +17 -0
- package/dist/services/memory-orchestrator.d.ts +60 -0
- package/dist/services/memory-orchestrator.js +133 -0
- package/dist/services/notifier.d.ts +25 -0
- package/dist/services/notifier.js +69 -0
- package/dist/services/oauth.d.ts +27 -0
- package/dist/services/oauth.js +153 -0
- package/dist/services/session-memory.d.ts +37 -0
- package/dist/services/session-memory.js +81 -0
- package/dist/session/file-history.d.ts +41 -0
- package/dist/session/file-history.js +115 -0
- package/dist/session/memory.d.ts +104 -0
- package/dist/session/memory.js +310 -0
- package/dist/session/session-manager.d.ts +41 -0
- package/dist/session/session-manager.js +261 -0
- package/dist/session/transcript.d.ts +39 -0
- package/dist/session/transcript.js +186 -0
- package/dist/settings/manager.d.ts +36 -0
- package/dist/settings/manager.js +187 -0
- package/dist/settings/schema.d.ts +1219 -0
- package/dist/settings/schema.js +246 -0
- package/dist/skills/frontmatter.d.ts +13 -0
- package/dist/skills/frontmatter.js +70 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/scanner.d.ts +31 -0
- package/dist/skills/scanner.js +171 -0
- package/dist/state.d.ts +160 -0
- package/dist/state.js +267 -0
- package/dist/tool-system/builtin/agent-notifications.d.ts +84 -0
- package/dist/tool-system/builtin/agent-notifications.js +197 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +67 -0
- package/dist/tool-system/builtin/agent-registry.js +126 -0
- package/dist/tool-system/builtin/agent-transcript-translator.d.ts +22 -0
- package/dist/tool-system/builtin/agent-transcript-translator.js +160 -0
- package/dist/tool-system/builtin/agent.d.ts +16 -0
- package/dist/tool-system/builtin/agent.js +364 -0
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
- package/dist/tool-system/builtin/apply-patch/applier.js +250 -0
- package/dist/tool-system/builtin/apply-patch/index.d.ts +20 -0
- package/dist/tool-system/builtin/apply-patch/index.js +101 -0
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
- package/dist/tool-system/builtin/apply-patch/parser.js +212 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.js +123 -0
- package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
- package/dist/tool-system/builtin/apply-patch/types.js +13 -0
- package/dist/tool-system/builtin/arena.d.ts +31 -0
- package/dist/tool-system/builtin/arena.js +416 -0
- package/dist/tool-system/builtin/ask-user.d.ts +20 -0
- package/dist/tool-system/builtin/ask-user.js +99 -0
- package/dist/tool-system/builtin/bash.d.ts +21 -0
- package/dist/tool-system/builtin/bash.js +149 -0
- package/dist/tool-system/builtin/brief.d.ts +6 -0
- package/dist/tool-system/builtin/brief.js +41 -0
- package/dist/tool-system/builtin/config.d.ts +6 -0
- package/dist/tool-system/builtin/config.js +67 -0
- package/dist/tool-system/builtin/cron.d.ts +10 -0
- package/dist/tool-system/builtin/cron.js +61 -0
- package/dist/tool-system/builtin/edit.d.ts +6 -0
- package/dist/tool-system/builtin/edit.js +100 -0
- package/dist/tool-system/builtin/file-cache.d.ts +11 -0
- package/dist/tool-system/builtin/file-cache.js +39 -0
- package/dist/tool-system/builtin/glob.d.ts +7 -0
- package/dist/tool-system/builtin/glob.js +76 -0
- package/dist/tool-system/builtin/grep.d.ts +7 -0
- package/dist/tool-system/builtin/grep.js +150 -0
- package/dist/tool-system/builtin/index.d.ts +20 -0
- package/dist/tool-system/builtin/index.js +449 -0
- package/dist/tool-system/builtin/lsp.d.ts +6 -0
- package/dist/tool-system/builtin/lsp.js +141 -0
- package/dist/tool-system/builtin/mcp-tools.d.ts +10 -0
- package/dist/tool-system/builtin/mcp-tools.js +102 -0
- package/dist/tool-system/builtin/memory.d.ts +26 -0
- package/dist/tool-system/builtin/memory.js +226 -0
- package/dist/tool-system/builtin/notebook-edit.d.ts +6 -0
- package/dist/tool-system/builtin/notebook-edit.js +124 -0
- package/dist/tool-system/builtin/plan.d.ts +15 -0
- package/dist/tool-system/builtin/plan.js +55 -0
- package/dist/tool-system/builtin/powershell.d.ts +11 -0
- package/dist/tool-system/builtin/powershell.js +64 -0
- package/dist/tool-system/builtin/read.d.ts +6 -0
- package/dist/tool-system/builtin/read.js +70 -0
- package/dist/tool-system/builtin/remote-trigger.d.ts +6 -0
- package/dist/tool-system/builtin/remote-trigger.js +54 -0
- package/dist/tool-system/builtin/repl.d.ts +11 -0
- package/dist/tool-system/builtin/repl.js +82 -0
- package/dist/tool-system/builtin/send-message.d.ts +6 -0
- package/dist/tool-system/builtin/send-message.js +47 -0
- package/dist/tool-system/builtin/skill-prompt.d.ts +20 -0
- package/dist/tool-system/builtin/skill-prompt.js +52 -0
- package/dist/tool-system/builtin/skill.d.ts +9 -0
- package/dist/tool-system/builtin/skill.js +55 -0
- package/dist/tool-system/builtin/sleep.d.ts +6 -0
- package/dist/tool-system/builtin/sleep.js +33 -0
- package/dist/tool-system/builtin/task.d.ts +48 -0
- package/dist/tool-system/builtin/task.js +139 -0
- package/dist/tool-system/builtin/tool-search.d.ts +11 -0
- package/dist/tool-system/builtin/tool-search.js +90 -0
- package/dist/tool-system/builtin/web-fetch.d.ts +10 -0
- package/dist/tool-system/builtin/web-fetch.js +328 -0
- package/dist/tool-system/builtin/web-search.d.ts +25 -0
- package/dist/tool-system/builtin/web-search.js +174 -0
- package/dist/tool-system/builtin/worktree.d.ts +10 -0
- package/dist/tool-system/builtin/worktree.js +95 -0
- package/dist/tool-system/builtin/write.d.ts +6 -0
- package/dist/tool-system/builtin/write.js +36 -0
- package/dist/tool-system/context.d.ts +165 -0
- package/dist/tool-system/context.js +18 -0
- package/dist/tool-system/executor.d.ts +49 -0
- package/dist/tool-system/executor.js +495 -0
- package/dist/tool-system/investigation-guard.d.ts +46 -0
- package/dist/tool-system/investigation-guard.js +155 -0
- package/dist/tool-system/mcp-manager.d.ts +67 -0
- package/dist/tool-system/mcp-manager.js +249 -0
- package/dist/tool-system/permission.d.ts +111 -0
- package/dist/tool-system/permission.js +774 -0
- package/dist/tool-system/registry.d.ts +32 -0
- package/dist/tool-system/registry.js +131 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/bwrap.js +63 -0
- package/dist/tool-system/sandbox/index.d.ts +78 -0
- package/dist/tool-system/sandbox/index.js +222 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/off.js +8 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/tool-system/sandbox/seatbelt.js +109 -0
- package/dist/tool-system/task-guard.d.ts +29 -0
- package/dist/tool-system/task-guard.js +70 -0
- package/dist/tool-system/validation.d.ts +5 -0
- package/dist/tool-system/validation.js +39 -0
- package/dist/types.d.ts +376 -0
- package/dist/types.js +4 -0
- package/dist/updater.d.ts +65 -0
- package/dist/updater.js +405 -0
- package/dist/utils/debug.d.ts +41 -0
- package/dist/utils/debug.js +110 -0
- package/dist/utils/earlyInput.d.ts +43 -0
- package/dist/utils/earlyInput.js +166 -0
- package/dist/utils/env.d.ts +24 -0
- package/dist/utils/env.js +104 -0
- package/dist/utils/envUtils.d.ts +51 -0
- package/dist/utils/envUtils.js +135 -0
- package/dist/utils/execFileNoThrow.d.ts +39 -0
- package/dist/utils/execFileNoThrow.js +74 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/format.js +236 -0
- package/dist/utils/intl.d.ts +22 -0
- package/dist/utils/intl.js +83 -0
- package/dist/utils/lockfile.d.ts +15 -0
- package/dist/utils/lockfile.js +30 -0
- package/dist/utils/memoize.d.ts +19 -0
- package/dist/utils/memoize.js +14 -0
- package/dist/utils/semver.d.ts +6 -0
- package/dist/utils/semver.js +13 -0
- package/dist/utils/sliceAnsi.d.ts +12 -0
- package/dist/utils/sliceAnsi.js +62 -0
- package/dist/utils/systemTheme.d.ts +40 -0
- package/dist/utils/systemTheme.js +108 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/dist/utils/task-sanitizer.js +24 -0
- package/dist/utils/theme.d.ts +93 -0
- package/dist/utils/theme.js +544 -0
- package/dist/utils/toolDisplay.d.ts +31 -0
- package/dist/utils/toolDisplay.js +188 -0
- package/package.json +72 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunQueue — simple in-process FIFO queue with configurable concurrency.
|
|
3
|
+
*
|
|
4
|
+
* Phase 1: single-process, no persistence.
|
|
5
|
+
* The queue holds run IDs; the actual execution is delegated to a callback.
|
|
6
|
+
*/
|
|
7
|
+
export interface RunQueueConfig {
|
|
8
|
+
concurrency?: number;
|
|
9
|
+
}
|
|
10
|
+
export type RunQueueExecutor = (runId: string) => Promise<void>;
|
|
11
|
+
export declare class RunQueue {
|
|
12
|
+
private readonly concurrency;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
private readonly active;
|
|
15
|
+
private executor;
|
|
16
|
+
private draining;
|
|
17
|
+
constructor(config?: RunQueueConfig);
|
|
18
|
+
setExecutor(fn: RunQueueExecutor): void;
|
|
19
|
+
enqueue(runId: string): void;
|
|
20
|
+
cancel(runId: string): boolean;
|
|
21
|
+
isActive(runId: string): boolean;
|
|
22
|
+
isPending(runId: string): boolean;
|
|
23
|
+
get activeCount(): number;
|
|
24
|
+
get pendingCount(): number;
|
|
25
|
+
private drain;
|
|
26
|
+
private processNext;
|
|
27
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunQueue — simple in-process FIFO queue with configurable concurrency.
|
|
3
|
+
*
|
|
4
|
+
* Phase 1: single-process, no persistence.
|
|
5
|
+
* The queue holds run IDs; the actual execution is delegated to a callback.
|
|
6
|
+
*/
|
|
7
|
+
export class RunQueue {
|
|
8
|
+
concurrency;
|
|
9
|
+
pending = [];
|
|
10
|
+
active = new Set();
|
|
11
|
+
executor = null;
|
|
12
|
+
draining = false;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.concurrency = config?.concurrency ?? 1;
|
|
15
|
+
}
|
|
16
|
+
setExecutor(fn) {
|
|
17
|
+
this.executor = fn;
|
|
18
|
+
}
|
|
19
|
+
enqueue(runId) {
|
|
20
|
+
if (this.pending.includes(runId) || this.active.has(runId))
|
|
21
|
+
return;
|
|
22
|
+
this.pending.push(runId);
|
|
23
|
+
this.drain();
|
|
24
|
+
}
|
|
25
|
+
cancel(runId) {
|
|
26
|
+
const idx = this.pending.indexOf(runId);
|
|
27
|
+
if (idx !== -1) {
|
|
28
|
+
this.pending.splice(idx, 1);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
isActive(runId) {
|
|
34
|
+
return this.active.has(runId);
|
|
35
|
+
}
|
|
36
|
+
isPending(runId) {
|
|
37
|
+
return this.pending.includes(runId);
|
|
38
|
+
}
|
|
39
|
+
get activeCount() {
|
|
40
|
+
return this.active.size;
|
|
41
|
+
}
|
|
42
|
+
get pendingCount() {
|
|
43
|
+
return this.pending.length;
|
|
44
|
+
}
|
|
45
|
+
drain() {
|
|
46
|
+
if (this.draining)
|
|
47
|
+
return;
|
|
48
|
+
this.draining = true;
|
|
49
|
+
// Schedule on next microtask to batch enqueues
|
|
50
|
+
queueMicrotask(() => {
|
|
51
|
+
this.draining = false;
|
|
52
|
+
this.processNext();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
processNext() {
|
|
56
|
+
if (!this.executor)
|
|
57
|
+
return;
|
|
58
|
+
while (this.active.size < this.concurrency && this.pending.length > 0) {
|
|
59
|
+
const runId = this.pending.shift();
|
|
60
|
+
this.active.add(runId);
|
|
61
|
+
this.executor(runId)
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
// Executor (RunManager.executeRun) handles state transitions
|
|
64
|
+
// in its own try/catch. Log here as a safety net.
|
|
65
|
+
console.error(`[RunQueue] Executor error for run ${runId}:`, err);
|
|
66
|
+
})
|
|
67
|
+
.finally(() => {
|
|
68
|
+
this.active.delete(runId);
|
|
69
|
+
this.processNext();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunStore — persistence interface for Run lifecycle data.
|
|
3
|
+
*
|
|
4
|
+
* Implementations must guarantee:
|
|
5
|
+
* - Snapshot writes are atomic (no partial state on crash)
|
|
6
|
+
* - Event appends are append-only and ordered
|
|
7
|
+
* - Checkpoint / approval reads return the latest version
|
|
8
|
+
*/
|
|
9
|
+
import type { RunSnapshot, RunEvent, RunCheckpoint, RunApproval, RunArtifactRef, ListRunsQuery } from "./types.js";
|
|
10
|
+
export interface RunStore {
|
|
11
|
+
create(snapshot: RunSnapshot): Promise<void>;
|
|
12
|
+
update(snapshot: RunSnapshot): Promise<void>;
|
|
13
|
+
get(runId: string): Promise<RunSnapshot | null>;
|
|
14
|
+
list(query?: ListRunsQuery): Promise<RunSnapshot[]>;
|
|
15
|
+
delete(runId: string): Promise<void>;
|
|
16
|
+
appendEvent(event: RunEvent): Promise<void>;
|
|
17
|
+
listEvents(runId: string): Promise<RunEvent[]>;
|
|
18
|
+
saveCheckpoint(cp: RunCheckpoint): Promise<void>;
|
|
19
|
+
getLatestCheckpoint(runId: string): Promise<RunCheckpoint | null>;
|
|
20
|
+
saveApproval(approval: RunApproval): Promise<void>;
|
|
21
|
+
getApproval(runId: string, approvalId: string): Promise<RunApproval | null>;
|
|
22
|
+
getPendingApproval(runId: string): Promise<RunApproval | null>;
|
|
23
|
+
appendArtifactRef(ref: RunArtifactRef): Promise<void>;
|
|
24
|
+
listArtifactRefs(runId: string): Promise<RunArtifactRef[]>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunStore — persistence interface for Run lifecycle data.
|
|
3
|
+
*
|
|
4
|
+
* Implementations must guarantee:
|
|
5
|
+
* - Snapshot writes are atomic (no partial state on crash)
|
|
6
|
+
* - Event appends are append-only and ordered
|
|
7
|
+
* - Checkpoint / approval reads return the latest version
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK convenience factory — create a RunManager with sensible defaults.
|
|
3
|
+
*
|
|
4
|
+
* Usage from an external repo:
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { createRunManager } from "code-shell";
|
|
7
|
+
*
|
|
8
|
+
* const manager = createRunManager({
|
|
9
|
+
* llm: {
|
|
10
|
+
* provider: "openai",
|
|
11
|
+
* model: "anthropic/claude-sonnet-4",
|
|
12
|
+
* apiKey: process.env.OPENROUTER_API_KEY,
|
|
13
|
+
* baseUrl: "https://openrouter.ai/api/v1",
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const run = await manager.submit({ objective: "Refactor the auth module" });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { LLMConfig, PermissionMode } from "../types.js";
|
|
21
|
+
import type { EngineConfig, EngineHookConfig } from "../engine/engine.js";
|
|
22
|
+
import type { Evaluator } from "./Evaluator.js";
|
|
23
|
+
import { RunManager } from "./RunManager.js";
|
|
24
|
+
export interface CreateRunManagerOptions {
|
|
25
|
+
/** LLM configuration (required). */
|
|
26
|
+
llm: LLMConfig;
|
|
27
|
+
/** Working directory. Default: process.cwd() */
|
|
28
|
+
cwd?: string;
|
|
29
|
+
/** Max turns per engine execution. Default: 30 */
|
|
30
|
+
maxTurns?: number;
|
|
31
|
+
/** Max context tokens. Default: 200_000 */
|
|
32
|
+
maxContextTokens?: number;
|
|
33
|
+
/** Permission mode. Default: "acceptEdits" */
|
|
34
|
+
permissionMode?: PermissionMode;
|
|
35
|
+
/** Queue concurrency. Default: 1 */
|
|
36
|
+
concurrency?: number;
|
|
37
|
+
/** Custom storage directory for runs. Default: ~/.code-shell/runs */
|
|
38
|
+
runsDir?: string;
|
|
39
|
+
/** Custom storage directory for sessions. Default: ~/.code-shell/sessions */
|
|
40
|
+
sessionStorageDir?: string;
|
|
41
|
+
/** MCP servers to connect. */
|
|
42
|
+
mcpServers?: EngineConfig["mcpServers"];
|
|
43
|
+
/** Enabled builtin tools (add to preset defaults). */
|
|
44
|
+
enabledBuiltinTools?: string[];
|
|
45
|
+
/** Disabled builtin tools (remove from preset defaults). */
|
|
46
|
+
disabledBuiltinTools?: string[];
|
|
47
|
+
/** Custom system prompt (replaces preset prompt). */
|
|
48
|
+
customSystemPrompt?: string;
|
|
49
|
+
/** Append to system prompt (added after preset prompt). */
|
|
50
|
+
appendSystemPrompt?: string;
|
|
51
|
+
/** Optional evaluator for run completion. */
|
|
52
|
+
evaluator?: Evaluator;
|
|
53
|
+
/** Hooks registered into each Engine instance before run execution. */
|
|
54
|
+
hooks?: EngineHookConfig[];
|
|
55
|
+
/** Tags applied to every submitted run unless already present. */
|
|
56
|
+
defaultTags?: string[];
|
|
57
|
+
/** Metadata merged into every submitted run. Submit input wins on conflicts. */
|
|
58
|
+
defaultMetadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a fully configured RunManager with one call.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createRunManager(options: CreateRunManagerOptions): RunManager;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK convenience factory — create a RunManager with sensible defaults.
|
|
3
|
+
*
|
|
4
|
+
* Usage from an external repo:
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { createRunManager } from "code-shell";
|
|
7
|
+
*
|
|
8
|
+
* const manager = createRunManager({
|
|
9
|
+
* llm: {
|
|
10
|
+
* provider: "openai",
|
|
11
|
+
* model: "anthropic/claude-sonnet-4",
|
|
12
|
+
* apiKey: process.env.OPENROUTER_API_KEY,
|
|
13
|
+
* baseUrl: "https://openrouter.ai/api/v1",
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const run = await manager.submit({ objective: "Refactor the auth module" });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import { homedir } from "node:os";
|
|
22
|
+
import { RunManager } from "./RunManager.js";
|
|
23
|
+
import { FileRunStore } from "./FileRunStore.js";
|
|
24
|
+
/**
|
|
25
|
+
* Create a fully configured RunManager with one call.
|
|
26
|
+
*/
|
|
27
|
+
export function createRunManager(options) {
|
|
28
|
+
const runsDir = options.runsDir ?? join(homedir(), ".code-shell", "runs");
|
|
29
|
+
const store = new FileRunStore(runsDir);
|
|
30
|
+
return new RunManager({
|
|
31
|
+
store,
|
|
32
|
+
executor: {
|
|
33
|
+
llm: options.llm,
|
|
34
|
+
maxTurns: options.maxTurns ?? 30,
|
|
35
|
+
maxContextTokens: options.maxContextTokens ?? 200_000,
|
|
36
|
+
permissionMode: options.permissionMode ?? "acceptEdits",
|
|
37
|
+
sessionStorageDir: options.sessionStorageDir,
|
|
38
|
+
mcpServers: options.mcpServers,
|
|
39
|
+
enabledBuiltinTools: options.enabledBuiltinTools,
|
|
40
|
+
disabledBuiltinTools: options.disabledBuiltinTools,
|
|
41
|
+
customSystemPrompt: options.customSystemPrompt,
|
|
42
|
+
appendSystemPrompt: options.appendSystemPrompt,
|
|
43
|
+
hooks: options.hooks,
|
|
44
|
+
},
|
|
45
|
+
concurrency: options.concurrency ?? 1,
|
|
46
|
+
runsDir,
|
|
47
|
+
evaluator: options.evaluator,
|
|
48
|
+
defaultTags: options.defaultTags,
|
|
49
|
+
defaultMetadata: options.defaultMetadata,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run module — managed agent run lifecycle.
|
|
3
|
+
*/
|
|
4
|
+
export type { RunStatus, RunSnapshot, RunEventType, RunEvent, RunCheckpoint, ApprovalStatus, ApprovalCategory, RunApproval, ArtifactKind, ArtifactRole, RunArtifactRef, SubmitRunInput, ResumeRunInput, ListRunsQuery, RunExecutionContext, RunExecutionResult, RunStreamEvent, RunStreamCallback, DetachFn, } from "./types.js";
|
|
5
|
+
export { VALID_TRANSITIONS } from "./types.js";
|
|
6
|
+
export type { RunStore } from "./RunStore.js";
|
|
7
|
+
export { FileRunStore } from "./FileRunStore.js";
|
|
8
|
+
export { RunQueue } from "./RunQueue.js";
|
|
9
|
+
export { RunApprovalBackend, createRunAskUserFn, type RunLifecycleHooks, type PendingApproval, type PendingInput, } from "./RunApprovalBackend.js";
|
|
10
|
+
export { CheckpointWriter, type CheckpointWriterConfig } from "./CheckpointWriter.js";
|
|
11
|
+
export { ArtifactTracker, type ArtifactTrackerConfig } from "./ArtifactTracker.js";
|
|
12
|
+
export { RunLock, type RunLockConfig } from "./RunLock.js";
|
|
13
|
+
export { Heartbeat, type HeartbeatConfig, type HeartbeatData } from "./Heartbeat.js";
|
|
14
|
+
export { NoopEvaluator, CompositeEvaluator, type Evaluator, type EvaluatorResult, type EvaluatorVerdict, type EvaluatorContext, } from "./Evaluator.js";
|
|
15
|
+
export { EngineRunner, type EngineRunnerConfig, type RunExecutionHandle, type RunExecutor, type CustomToolEntry, } from "./EngineRunner.js";
|
|
16
|
+
export { RunManager, type RunManagerConfig } from "./RunManager.js";
|
|
17
|
+
export { createRunManager, type CreateRunManagerOptions } from "./factory.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run module — managed agent run lifecycle.
|
|
3
|
+
*/
|
|
4
|
+
export { VALID_TRANSITIONS } from "./types.js";
|
|
5
|
+
export { FileRunStore } from "./FileRunStore.js";
|
|
6
|
+
// Queue
|
|
7
|
+
export { RunQueue } from "./RunQueue.js";
|
|
8
|
+
// Approval / Input adapters
|
|
9
|
+
export { RunApprovalBackend, createRunAskUserFn, } from "./RunApprovalBackend.js";
|
|
10
|
+
// Checkpoint & Artifacts
|
|
11
|
+
export { CheckpointWriter } from "./CheckpointWriter.js";
|
|
12
|
+
export { ArtifactTracker } from "./ArtifactTracker.js";
|
|
13
|
+
// Hardening
|
|
14
|
+
export { RunLock } from "./RunLock.js";
|
|
15
|
+
export { Heartbeat } from "./Heartbeat.js";
|
|
16
|
+
// Evaluator
|
|
17
|
+
export { NoopEvaluator, CompositeEvaluator, } from "./Evaluator.js";
|
|
18
|
+
// Runner
|
|
19
|
+
export { EngineRunner, } from "./EngineRunner.js";
|
|
20
|
+
// Manager
|
|
21
|
+
export { RunManager } from "./RunManager.js";
|
|
22
|
+
// Factory
|
|
23
|
+
export { createRunManager } from "./factory.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run — managed lifecycle types for long-running agent tasks.
|
|
3
|
+
*
|
|
4
|
+
* A Run wraps one or more Engine executions with queue, state machine,
|
|
5
|
+
* checkpoint, approval, and artifact tracking.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentPresetName } from "../preset/index.js";
|
|
8
|
+
export type RunStatus = "queued" | "running" | "waiting_input" | "waiting_approval" | "blocked" | "completed" | "failed" | "cancelled";
|
|
9
|
+
export interface RunSnapshot {
|
|
10
|
+
runId: string;
|
|
11
|
+
objective: string;
|
|
12
|
+
preset: AgentPresetName;
|
|
13
|
+
cwd: string;
|
|
14
|
+
status: RunStatus;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
updatedAt: number;
|
|
17
|
+
startedAt: number | null;
|
|
18
|
+
finishedAt: number | null;
|
|
19
|
+
parentRunId: string | null;
|
|
20
|
+
sessionId: string | null;
|
|
21
|
+
childSessionIds: string[];
|
|
22
|
+
attemptCount: number;
|
|
23
|
+
latestCheckpointId: string | null;
|
|
24
|
+
latestApprovalId: string | null;
|
|
25
|
+
summary: string | null;
|
|
26
|
+
error: string | null;
|
|
27
|
+
tags: string[];
|
|
28
|
+
metadata: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export type RunEventType = "run_created" | "run_queued" | "run_started" | "session_linked" | "checkpoint_written" | "artifact_recorded" | "approval_requested" | "approval_resolved" | "run_blocked" | "run_resumed" | "run_completed" | "run_failed" | "run_cancelled";
|
|
31
|
+
export interface RunEvent {
|
|
32
|
+
eventId: string;
|
|
33
|
+
runId: string;
|
|
34
|
+
type: RunEventType;
|
|
35
|
+
timestamp: number;
|
|
36
|
+
data: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface RunCheckpoint {
|
|
39
|
+
checkpointId: string;
|
|
40
|
+
runId: string;
|
|
41
|
+
createdAt: number;
|
|
42
|
+
phase: string;
|
|
43
|
+
objective: string;
|
|
44
|
+
summary: string;
|
|
45
|
+
nextAction: string | null;
|
|
46
|
+
linkedSessionId: string | null;
|
|
47
|
+
touchedTools: string[];
|
|
48
|
+
touchedArtifacts: string[];
|
|
49
|
+
waitingFor: null | {
|
|
50
|
+
kind: "input";
|
|
51
|
+
prompt: string;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "approval";
|
|
54
|
+
approvalId: string;
|
|
55
|
+
};
|
|
56
|
+
evaluator: null | {
|
|
57
|
+
status: "pending" | "passed" | "failed";
|
|
58
|
+
findings: string[];
|
|
59
|
+
};
|
|
60
|
+
metadata: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
export type ApprovalStatus = "pending" | "approved" | "rejected";
|
|
63
|
+
export type ApprovalCategory = "tool" | "artifact_publish" | "workflow_transition" | "custom";
|
|
64
|
+
export interface RunApproval {
|
|
65
|
+
approvalId: string;
|
|
66
|
+
runId: string;
|
|
67
|
+
createdAt: number;
|
|
68
|
+
resolvedAt: number | null;
|
|
69
|
+
status: ApprovalStatus;
|
|
70
|
+
category: ApprovalCategory;
|
|
71
|
+
title: string;
|
|
72
|
+
description: string;
|
|
73
|
+
payload: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
export type ArtifactKind = "file" | "document" | "diagram" | "prototype" | "resource" | "custom";
|
|
76
|
+
export type ArtifactRole = "input" | "output" | "checkpoint" | "supporting";
|
|
77
|
+
export interface RunArtifactRef {
|
|
78
|
+
artifactRefId: string;
|
|
79
|
+
runId: string;
|
|
80
|
+
kind: ArtifactKind;
|
|
81
|
+
title: string;
|
|
82
|
+
locator: string;
|
|
83
|
+
role: ArtifactRole;
|
|
84
|
+
version: string | null;
|
|
85
|
+
metadata: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
export interface SubmitRunInput {
|
|
88
|
+
objective: string;
|
|
89
|
+
preset?: AgentPresetName;
|
|
90
|
+
cwd?: string;
|
|
91
|
+
parentRunId?: string;
|
|
92
|
+
tags?: string[];
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export interface ResumeRunInput {
|
|
96
|
+
userInput?: string;
|
|
97
|
+
approvalDecision?: {
|
|
98
|
+
approvalId: string;
|
|
99
|
+
approved: boolean;
|
|
100
|
+
reason?: string;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export interface ListRunsQuery {
|
|
104
|
+
status?: RunStatus | RunStatus[];
|
|
105
|
+
tag?: string;
|
|
106
|
+
limit?: number;
|
|
107
|
+
offset?: number;
|
|
108
|
+
}
|
|
109
|
+
export interface RunExecutionContext {
|
|
110
|
+
onStream?: import("../types.js").StreamCallback;
|
|
111
|
+
signal?: AbortSignal;
|
|
112
|
+
engineConfigOverrides?: Record<string, unknown>;
|
|
113
|
+
}
|
|
114
|
+
export interface RunExecutionResult {
|
|
115
|
+
text: string;
|
|
116
|
+
reason: import("../types.js").TerminalReason;
|
|
117
|
+
sessionId: string;
|
|
118
|
+
turnCount: number;
|
|
119
|
+
}
|
|
120
|
+
export type RunStreamEvent = {
|
|
121
|
+
type: "run_status_changed";
|
|
122
|
+
run: RunSnapshot;
|
|
123
|
+
} | {
|
|
124
|
+
type: "run_event";
|
|
125
|
+
event: RunEvent;
|
|
126
|
+
} | {
|
|
127
|
+
type: "engine_stream";
|
|
128
|
+
event: import("../types.js").StreamEvent;
|
|
129
|
+
};
|
|
130
|
+
export type RunStreamCallback = (event: RunStreamEvent) => void | Promise<void>;
|
|
131
|
+
export type DetachFn = () => void;
|
|
132
|
+
/**
|
|
133
|
+
* Valid state transitions for a Run.
|
|
134
|
+
* Key = current status, Value = allowed next statuses.
|
|
135
|
+
*/
|
|
136
|
+
export declare const VALID_TRANSITIONS: Record<RunStatus, RunStatus[]>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run — managed lifecycle types for long-running agent tasks.
|
|
3
|
+
*
|
|
4
|
+
* A Run wraps one or more Engine executions with queue, state machine,
|
|
5
|
+
* checkpoint, approval, and artifact tracking.
|
|
6
|
+
*/
|
|
7
|
+
// ─── State Machine ───────────────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Valid state transitions for a Run.
|
|
10
|
+
* Key = current status, Value = allowed next statuses.
|
|
11
|
+
*/
|
|
12
|
+
export const VALID_TRANSITIONS = {
|
|
13
|
+
queued: ["running", "cancelled"],
|
|
14
|
+
running: [
|
|
15
|
+
"waiting_input",
|
|
16
|
+
"waiting_approval",
|
|
17
|
+
"blocked",
|
|
18
|
+
"completed",
|
|
19
|
+
"failed",
|
|
20
|
+
"cancelled",
|
|
21
|
+
],
|
|
22
|
+
waiting_input: ["queued", "cancelled"],
|
|
23
|
+
waiting_approval: ["queued", "cancelled"],
|
|
24
|
+
blocked: ["queued", "cancelled"],
|
|
25
|
+
completed: [],
|
|
26
|
+
failed: [],
|
|
27
|
+
cancelled: [],
|
|
28
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SafeSpawn — unified subprocess lifecycle wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* 1. Optional sandbox wrap (Seatbelt / bubblewrap) via {@link SandboxBackend}.
|
|
6
|
+
* 2. UTF-8 IO drain via {@link StringDecoder} (no half-character corruption
|
|
7
|
+
* when a multi-byte sequence spans two `data` events).
|
|
8
|
+
* 3. Per-stream byte cap with a `truncated` flag (no unbounded buffer fill).
|
|
9
|
+
* 4. `ctx.signal` abort cascade — SIGTERM, then SIGKILL after
|
|
10
|
+
* `ioDrainGraceMs` (default 100ms). This is the snappy path because
|
|
11
|
+
* the user is waiting on the cancel.
|
|
12
|
+
* 5. Hard timeout — SIGTERM, then SIGKILL after 2s. Longer grace because
|
|
13
|
+
* we expect the child to be wedged.
|
|
14
|
+
* 6. Listener cleanup on every exit path (no MaxListeners leak across a
|
|
15
|
+
* long session that reuses one AbortSignal across many spawns).
|
|
16
|
+
*
|
|
17
|
+
* Explicit non-goals:
|
|
18
|
+
*
|
|
19
|
+
* - Permission classification. {@link ToolExecutor} already classifies
|
|
20
|
+
* builtin tools BEFORE the tool function runs; re-classifying here
|
|
21
|
+
* would double-prompt. Install/marketplace paths (gitOps) are consented
|
|
22
|
+
* at user-initiated install time; see docs/architecture/17.
|
|
23
|
+
* - Retries. The caller decides retry policy if any.
|
|
24
|
+
* - Output formatting. SafeSpawn returns structured fields and lets the
|
|
25
|
+
* caller compose its own user-facing string (Bash's "STDERR:\n…" /
|
|
26
|
+
* "Exit code: N" / "Killed by signal: X" formatting lives in bash.ts;
|
|
27
|
+
* REPL/PowerShell have their own messages).
|
|
28
|
+
*
|
|
29
|
+
* Two entry points, both share the same internal lifecycle:
|
|
30
|
+
* - {@link safeSpawn}(file, args, opts) — direct argv spawn. Use from
|
|
31
|
+
* REPL, PowerShell, gitOps where the binary + args are known.
|
|
32
|
+
* - {@link safeSpawnShell}(command, opts) — runs `command` through the
|
|
33
|
+
* sandbox backend (or a plain shell if no sandbox). Use from Bash
|
|
34
|
+
* where the LLM provides a free-form shell string.
|
|
35
|
+
*/
|
|
36
|
+
import type { SandboxBackend } from "../tool-system/sandbox/index.js";
|
|
37
|
+
export interface SafeSpawnOptions {
|
|
38
|
+
/** Process working directory. Required — callers know their cwd; SafeSpawn does not fall back to process.cwd(). */
|
|
39
|
+
cwd: string;
|
|
40
|
+
/** Environment for the child. Required — callers decide whether to forward host env (Bash builds a hardened env; REPL/PowerShell/gitOps forward process.env). */
|
|
41
|
+
env: NodeJS.ProcessEnv;
|
|
42
|
+
/** Hard timeout in ms. On expiry: SIGTERM, then SIGKILL after 2s. */
|
|
43
|
+
timeoutMs: number;
|
|
44
|
+
/** Per-stream max bytes captured. Stream output beyond this is dropped and a `truncated` flag is set. Default {@link DEFAULT_MAX_OUTPUT_BYTES}. */
|
|
45
|
+
maxOutputBytes?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Grace period after SIGTERM before SIGKILL when ABORTING via ctx.signal.
|
|
48
|
+
* Defaults to {@link DEFAULT_IO_DRAIN_GRACE_MS}. The timeout path uses a
|
|
49
|
+
* fixed 2s grace because the caller has been waiting; abort comes from
|
|
50
|
+
* a user cancel where snappiness matters.
|
|
51
|
+
*/
|
|
52
|
+
ioDrainGraceMs?: number;
|
|
53
|
+
/** Optional cancellation signal. If already aborted, SafeSpawn resolves immediately without spawning. */
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
export interface SafeSpawnShellOptions extends SafeSpawnOptions {
|
|
57
|
+
/** Optional sandbox to wrap the command through. Required for shell-mode. If omitted, the command runs through `shell ?? /bin/bash -c`. */
|
|
58
|
+
sandbox?: SandboxBackend;
|
|
59
|
+
/** Shell to invoke when no sandbox is provided (also forwarded to sandbox.wrap()). Default `/bin/bash`. */
|
|
60
|
+
shell?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Outcome discriminant for {@link SafeSpawnResult}. Lets SDK callers
|
|
64
|
+
* `switch (result.reason)` instead of reading three booleans and
|
|
65
|
+
* deciding which one to branch on first. `ok` is the normal-exit case
|
|
66
|
+
* (any `exitCode`, including non-zero); `spawn_failed` covers both
|
|
67
|
+
* synchronous `spawn()` throws and the child's `error` event mid-stream
|
|
68
|
+
* — both mean "we never got a clean lifecycle". The existing boolean
|
|
69
|
+
* flags (`timedOut`, `aborted`, `spawnFailed`) are preserved so the
|
|
70
|
+
* per-tool output formatting in Bash/REPL/PowerShell keeps working;
|
|
71
|
+
* `reason` is additive.
|
|
72
|
+
*/
|
|
73
|
+
export type SafeSpawnReason = "ok" | "timeout" | "aborted" | "spawn_failed";
|
|
74
|
+
export interface SafeSpawnResult {
|
|
75
|
+
/**
|
|
76
|
+
* Discriminant for the outcome. `ok` means the process exited
|
|
77
|
+
* normally (any `exitCode`, including non-zero). Mutually exclusive
|
|
78
|
+
* by construction with the boolean flags below — e.g.
|
|
79
|
+
* `reason === "timeout"` ⇒ `timedOut === true`.
|
|
80
|
+
*/
|
|
81
|
+
reason: SafeSpawnReason;
|
|
82
|
+
/** UTF-8 decoded stdout (truncated to `maxOutputBytes` characters when over). */
|
|
83
|
+
stdout: string;
|
|
84
|
+
/** UTF-8 decoded stderr (truncated to `maxOutputBytes` characters when over). */
|
|
85
|
+
stderr: string;
|
|
86
|
+
/** null when killed by signal without an exit code. */
|
|
87
|
+
exitCode: number | null;
|
|
88
|
+
/** Set when the OS reports the child died from a signal. */
|
|
89
|
+
signal: NodeJS.Signals | null;
|
|
90
|
+
/** True when stdout was capped. */
|
|
91
|
+
stdoutTruncated: boolean;
|
|
92
|
+
/** True when stderr was capped. */
|
|
93
|
+
stderrTruncated: boolean;
|
|
94
|
+
/** True when the timeoutMs fired. */
|
|
95
|
+
timedOut: boolean;
|
|
96
|
+
/** True when ctx.signal aborted us (including pre-spawn). */
|
|
97
|
+
aborted: boolean;
|
|
98
|
+
/** True when the spawn itself failed (file not found, permission). `error` carries the message. */
|
|
99
|
+
spawnFailed: boolean;
|
|
100
|
+
/** Spawn error message when spawnFailed is set. */
|
|
101
|
+
error?: string;
|
|
102
|
+
}
|
|
103
|
+
export declare const DEFAULT_MAX_OUTPUT_BYTES = 1000000;
|
|
104
|
+
export declare const DEFAULT_IO_DRAIN_GRACE_MS = 100;
|
|
105
|
+
/**
|
|
106
|
+
* Spawn `(file, args)` directly under the unified lifecycle policy. Use this
|
|
107
|
+
* when you know the binary and args (REPL, PowerShell, gitOps). For shell-
|
|
108
|
+
* string spawning under a sandbox, see {@link safeSpawnShell}.
|
|
109
|
+
*/
|
|
110
|
+
export declare function safeSpawn(file: string, args: string[], opts: SafeSpawnOptions): Promise<SafeSpawnResult>;
|
|
111
|
+
/**
|
|
112
|
+
* Spawn a shell `command` string under an optional sandbox. The sandbox
|
|
113
|
+
* backend decides the actual `(file, args)` (e.g. Seatbelt becomes
|
|
114
|
+
* `/usr/bin/sandbox-exec -f profile shell -c command`). The backend's
|
|
115
|
+
* `cleanup` callback is invoked on every exit path — close, error,
|
|
116
|
+
* abort, timeout, pre-spawn-abort. Used by the Bash tool.
|
|
117
|
+
*/
|
|
118
|
+
export declare function safeSpawnShell(command: string, opts: SafeSpawnShellOptions): Promise<SafeSpawnResult>;
|