@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,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in WebSearch tool — search the web via Serper, Tavily, or SearXNG.
|
|
3
|
+
*
|
|
4
|
+
* Provider selection / credentials are read in this precedence:
|
|
5
|
+
* 1. settings.search.{provider, apiKey, baseUrl} from ~/.code-shell/settings.json
|
|
6
|
+
* (set via the desktop "连接" UI or hand-edited)
|
|
7
|
+
* 2. env vars SERPER_API_KEY / TAVILY_API_KEY / SEARXNG_URL (legacy / CI override)
|
|
8
|
+
* Settings take precedence so the desktop UI's "保存连接" + "测试连接" is the
|
|
9
|
+
* single source of truth for end users.
|
|
10
|
+
*/
|
|
11
|
+
import { SettingsManager } from "../../settings/manager.js";
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the active search config. Returns `source` so callers can show
|
|
14
|
+
* the user where the value came from when debugging.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveSearchConfig(cwd = process.cwd()) {
|
|
17
|
+
let settingsProvider;
|
|
18
|
+
let settingsKey;
|
|
19
|
+
let settingsBaseUrl;
|
|
20
|
+
try {
|
|
21
|
+
const merged = new SettingsManager(cwd).get();
|
|
22
|
+
const search = merged.search ?? {};
|
|
23
|
+
const p = search.provider;
|
|
24
|
+
if (p === "serper" || p === "tavily" || p === "searxng")
|
|
25
|
+
settingsProvider = p;
|
|
26
|
+
// Per-provider bag takes precedence over the legacy single-slot fields
|
|
27
|
+
// when the active provider matches the bag entry.
|
|
28
|
+
const bag = search.providers && typeof search.providers === "object"
|
|
29
|
+
? search.providers
|
|
30
|
+
: undefined;
|
|
31
|
+
const bagEntry = settingsProvider && bag ? bag[settingsProvider] : undefined;
|
|
32
|
+
if (bagEntry && typeof bagEntry.apiKey === "string" && bagEntry.apiKey) {
|
|
33
|
+
settingsKey = bagEntry.apiKey;
|
|
34
|
+
}
|
|
35
|
+
else if (typeof search.apiKey === "string" && search.apiKey) {
|
|
36
|
+
settingsKey = search.apiKey;
|
|
37
|
+
}
|
|
38
|
+
if (bagEntry && typeof bagEntry.baseUrl === "string" && bagEntry.baseUrl) {
|
|
39
|
+
settingsBaseUrl = bagEntry.baseUrl;
|
|
40
|
+
}
|
|
41
|
+
else if (typeof search.baseUrl === "string" && search.baseUrl) {
|
|
42
|
+
settingsBaseUrl = search.baseUrl;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* settings unreadable — fall through to env */
|
|
47
|
+
}
|
|
48
|
+
const envSerper = process.env.SERPER_API_KEY;
|
|
49
|
+
const envTavily = process.env.TAVILY_API_KEY;
|
|
50
|
+
const envSearxng = process.env.SEARXNG_URL;
|
|
51
|
+
if (settingsProvider) {
|
|
52
|
+
if (settingsProvider === "searxng") {
|
|
53
|
+
const base = settingsBaseUrl ?? envSearxng;
|
|
54
|
+
return base
|
|
55
|
+
? { provider: "searxng", baseUrl: base, source: settingsBaseUrl ? "settings" : "env" }
|
|
56
|
+
: { provider: "searxng", source: "none" };
|
|
57
|
+
}
|
|
58
|
+
const key = settingsKey ?? (settingsProvider === "serper" ? envSerper : envTavily);
|
|
59
|
+
return key
|
|
60
|
+
? { provider: settingsProvider, apiKey: key, source: settingsKey ? "settings" : "env" }
|
|
61
|
+
: { provider: settingsProvider, source: "none" };
|
|
62
|
+
}
|
|
63
|
+
if (envSerper)
|
|
64
|
+
return { provider: "serper", apiKey: envSerper, source: "env" };
|
|
65
|
+
if (envTavily)
|
|
66
|
+
return { provider: "tavily", apiKey: envTavily, source: "env" };
|
|
67
|
+
if (envSearxng)
|
|
68
|
+
return { provider: "searxng", baseUrl: envSearxng, source: "env" };
|
|
69
|
+
return { provider: "serper", source: "none" };
|
|
70
|
+
}
|
|
71
|
+
export const webSearchToolDef = {
|
|
72
|
+
name: "WebSearch",
|
|
73
|
+
description: "Search the web for information. Returns a list of search results with titles, URLs, and snippets. " +
|
|
74
|
+
"Use this when you need up-to-date information or facts not in your training data.",
|
|
75
|
+
inputSchema: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
query: { type: "string", description: "The search query" },
|
|
79
|
+
num_results: {
|
|
80
|
+
type: "number",
|
|
81
|
+
description: "Number of results to return (default: 10, max: 20)",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ["query"],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
export async function webSearchTool(args) {
|
|
88
|
+
const query = args.query;
|
|
89
|
+
if (!query)
|
|
90
|
+
return "Error: query is required";
|
|
91
|
+
const numResults = Math.min(args.num_results || 10, 20);
|
|
92
|
+
const config = resolveSearchConfig();
|
|
93
|
+
if (config.source === "none") {
|
|
94
|
+
return "Error: No search provider configured. Open desktop 设置 → 连接 to add credentials, or set SERPER_API_KEY / TAVILY_API_KEY / SEARXNG_URL.";
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
let results;
|
|
98
|
+
if (config.provider === "serper" && config.apiKey) {
|
|
99
|
+
results = await searchSerper(query, numResults, config.apiKey);
|
|
100
|
+
}
|
|
101
|
+
else if (config.provider === "tavily" && config.apiKey) {
|
|
102
|
+
results = await searchTavily(query, numResults, config.apiKey);
|
|
103
|
+
}
|
|
104
|
+
else if (config.provider === "searxng" && config.baseUrl) {
|
|
105
|
+
results = await searchSearXNG(query, numResults, config.baseUrl);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return `Error: provider "${config.provider}" missing ${config.provider === "searxng" ? "base URL" : "API key"}`;
|
|
109
|
+
}
|
|
110
|
+
if (results.length === 0)
|
|
111
|
+
return "No results found.";
|
|
112
|
+
return results
|
|
113
|
+
.map((r, i) => `${i + 1}. ${r.title}\n ${r.url}\n ${r.snippet}`)
|
|
114
|
+
.join("\n\n");
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
return `Search error: ${err.message}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async function searchSerper(query, num, apiKey) {
|
|
121
|
+
const res = await fetch("https://google.serper.dev/search", {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers: {
|
|
124
|
+
"X-API-KEY": apiKey,
|
|
125
|
+
"Content-Type": "application/json",
|
|
126
|
+
},
|
|
127
|
+
body: JSON.stringify({ q: query, num }),
|
|
128
|
+
});
|
|
129
|
+
if (!res.ok)
|
|
130
|
+
throw new Error(`Serper API error: ${res.status} ${res.statusText}`);
|
|
131
|
+
const data = (await res.json());
|
|
132
|
+
return (data.organic ?? []).map((item) => ({
|
|
133
|
+
title: item.title ?? "",
|
|
134
|
+
url: item.link ?? "",
|
|
135
|
+
snippet: item.snippet ?? "",
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
async function searchTavily(query, num, apiKey) {
|
|
139
|
+
const res = await fetch("https://api.tavily.com/search", {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: { "Content-Type": "application/json" },
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
api_key: apiKey,
|
|
144
|
+
query,
|
|
145
|
+
max_results: num,
|
|
146
|
+
include_answer: false,
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
if (!res.ok)
|
|
150
|
+
throw new Error(`Tavily API error: ${res.status} ${res.statusText}`);
|
|
151
|
+
const data = (await res.json());
|
|
152
|
+
return (data.results ?? []).map((item) => ({
|
|
153
|
+
title: item.title ?? "",
|
|
154
|
+
url: item.url ?? "",
|
|
155
|
+
snippet: item.content ?? "",
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
async function searchSearXNG(query, num, baseUrl) {
|
|
159
|
+
const url = new URL("/search", baseUrl);
|
|
160
|
+
url.searchParams.set("q", query);
|
|
161
|
+
url.searchParams.set("format", "json");
|
|
162
|
+
url.searchParams.set("pageno", "1");
|
|
163
|
+
const res = await fetch(url.toString(), {
|
|
164
|
+
headers: { Accept: "application/json" },
|
|
165
|
+
});
|
|
166
|
+
if (!res.ok)
|
|
167
|
+
throw new Error(`SearXNG error: ${res.status} ${res.statusText}`);
|
|
168
|
+
const data = (await res.json());
|
|
169
|
+
return (data.results ?? []).slice(0, num).map((item) => ({
|
|
170
|
+
title: item.title ?? "",
|
|
171
|
+
url: item.url ?? "",
|
|
172
|
+
snippet: item.content ?? "",
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnterWorktree / ExitWorktree tools — create and manage isolated git worktrees.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from "../../types.js";
|
|
5
|
+
import { type WorktreeSession } from "../../git/worktree.js";
|
|
6
|
+
export declare function getActiveWorktree(): WorktreeSession | undefined;
|
|
7
|
+
export declare const enterWorktreeToolDef: ToolDefinition;
|
|
8
|
+
export declare function enterWorktreeTool(args: Record<string, unknown>): Promise<string>;
|
|
9
|
+
export declare const exitWorktreeToolDef: ToolDefinition;
|
|
10
|
+
export declare function exitWorktreeTool(args: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnterWorktree / ExitWorktree tools — create and manage isolated git worktrees.
|
|
3
|
+
*/
|
|
4
|
+
import { createWorktree, removeWorktree, validateWorktreeSlug, } from "../../git/worktree.js";
|
|
5
|
+
// Global worktree state
|
|
6
|
+
let _activeWorktree;
|
|
7
|
+
export function getActiveWorktree() {
|
|
8
|
+
return _activeWorktree;
|
|
9
|
+
}
|
|
10
|
+
export const enterWorktreeToolDef = {
|
|
11
|
+
name: "EnterWorktree",
|
|
12
|
+
description: "Create an isolated git worktree for safe code modifications. " +
|
|
13
|
+
"The worktree is a separate copy of the repository on a new branch. " +
|
|
14
|
+
"Changes made in the worktree do not affect the main working directory. " +
|
|
15
|
+
"Use this when you need to make experimental changes or work in isolation.",
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
slug: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "A short identifier for the worktree (alphanumeric, dots, dashes only, max 64 chars). " +
|
|
22
|
+
"Example: 'fix-auth-bug', 'refactor-api'",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ["slug"],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export async function enterWorktreeTool(args) {
|
|
29
|
+
const slug = args.slug;
|
|
30
|
+
if (!slug)
|
|
31
|
+
return "Error: slug is required";
|
|
32
|
+
if (_activeWorktree) {
|
|
33
|
+
return `Error: Already in a worktree at ${_activeWorktree.worktreePath}. Exit it first with ExitWorktree.`;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
validateWorktreeSlug(slug);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return `Error: ${err.message}`;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
// Use a placeholder session ID (the agent should set this properly)
|
|
43
|
+
const sessionId = args.__sessionId ?? `wt-${Date.now()}`;
|
|
44
|
+
const cwd = args.__cwd ?? process.cwd();
|
|
45
|
+
_activeWorktree = createWorktree(cwd, slug, sessionId);
|
|
46
|
+
return (`Worktree created:\n` +
|
|
47
|
+
` Path: ${_activeWorktree.worktreePath}\n` +
|
|
48
|
+
` Branch: ${_activeWorktree.worktreeBranch}\n` +
|
|
49
|
+
` From: ${_activeWorktree.originalBranch ?? "HEAD"}\n\n` +
|
|
50
|
+
`You are now working in an isolated copy. Changes here won't affect the main repo.`);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
return `Error creating worktree: ${err.message}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export const exitWorktreeToolDef = {
|
|
57
|
+
name: "ExitWorktree",
|
|
58
|
+
description: "Exit the current worktree and return to the main working directory. " +
|
|
59
|
+
"Choose whether to keep or discard the changes made in the worktree.",
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
action: {
|
|
64
|
+
type: "string",
|
|
65
|
+
enum: ["keep", "discard"],
|
|
66
|
+
description: "'keep' preserves the worktree branch for later merging. " +
|
|
67
|
+
"'discard' removes the worktree and its branch entirely.",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ["action"],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
export async function exitWorktreeTool(args) {
|
|
74
|
+
if (!_activeWorktree) {
|
|
75
|
+
return "Not currently in a worktree.";
|
|
76
|
+
}
|
|
77
|
+
const action = args.action;
|
|
78
|
+
const session = _activeWorktree;
|
|
79
|
+
_activeWorktree = undefined;
|
|
80
|
+
try {
|
|
81
|
+
if (action === "discard") {
|
|
82
|
+
removeWorktree(session.worktreePath, true);
|
|
83
|
+
return `Worktree removed and branch ${session.worktreeBranch} deleted. Back to ${session.originalCwd}.`;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
removeWorktree(session.worktreePath, false);
|
|
87
|
+
return (`Worktree removed. Branch ${session.worktreeBranch} preserved.\n` +
|
|
88
|
+
`To merge: git merge ${session.worktreeBranch}\n` +
|
|
89
|
+
`Back to ${session.originalCwd}.`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
return `Error exiting worktree: ${err.message}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Write file tool.
|
|
3
|
+
*/
|
|
4
|
+
import { writeFile, mkdir } from "node:fs/promises";
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
import { fileCache } from "./file-cache.js";
|
|
7
|
+
export const writeToolDef = {
|
|
8
|
+
name: "Write",
|
|
9
|
+
description: "Write content to a file. Creates the file if it doesn't exist, " +
|
|
10
|
+
"overwrites if it does. Creates parent directories as needed.",
|
|
11
|
+
inputSchema: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
file_path: { type: "string", description: "Absolute path to the file to write" },
|
|
15
|
+
content: { type: "string", description: "The content to write to the file" },
|
|
16
|
+
},
|
|
17
|
+
required: ["file_path", "content"],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export async function writeTool(args) {
|
|
21
|
+
const filePath = args.file_path;
|
|
22
|
+
const content = args.content;
|
|
23
|
+
if (!filePath)
|
|
24
|
+
return "Error: file_path is required";
|
|
25
|
+
if (content === undefined)
|
|
26
|
+
return "Error: content is required";
|
|
27
|
+
try {
|
|
28
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
29
|
+
await writeFile(filePath, content, "utf-8");
|
|
30
|
+
fileCache.invalidate(filePath);
|
|
31
|
+
return `Successfully wrote to ${filePath}`;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
return `Error writing file: ${err.message}`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolContext — runtime services injected into every tool execution.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the legacy module-level singletons (`setAskUserFn`,
|
|
5
|
+
* `setArenaLLMConfig`, `setSubAgentConfig`, `setToolSearchRegistry`).
|
|
6
|
+
*
|
|
7
|
+
* Each Engine instance builds its own ToolContext when run() starts and
|
|
8
|
+
* passes it through ToolExecutor → ToolRegistry → executor function.
|
|
9
|
+
* That makes concurrent Engine instances safe: tools never see another
|
|
10
|
+
* Engine's askUser handler or LLM credentials.
|
|
11
|
+
*
|
|
12
|
+
* Tools that don't need any context (Read/Write/Bash/...) just ignore
|
|
13
|
+
* the second argument; the type is purely additive.
|
|
14
|
+
*/
|
|
15
|
+
import type { LLMConfig, StreamCallback } from "../types.js";
|
|
16
|
+
import type { ModelPool } from "../llm/model-pool.js";
|
|
17
|
+
import type { ToolRegistry } from "./registry.js";
|
|
18
|
+
import type { AgentPresetName } from "../preset/index.js";
|
|
19
|
+
import type { SandboxBackend } from "./sandbox/index.js";
|
|
20
|
+
import type { HookRegistry } from "../hooks/registry.js";
|
|
21
|
+
import type { Engine } from "../engine/engine.js";
|
|
22
|
+
/** One choice in a multiple-choice AskUserQuestion. */
|
|
23
|
+
export interface AskUserChoice {
|
|
24
|
+
label: string;
|
|
25
|
+
description: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Optional rendering hints / multiple-choice options carried alongside the
|
|
29
|
+
* question. Implementations may ignore unknown fields — they're additive.
|
|
30
|
+
*/
|
|
31
|
+
export interface AskUserOptions {
|
|
32
|
+
/** Short chip-style label (≤12 chars) shown above the question. */
|
|
33
|
+
header?: string;
|
|
34
|
+
/** Multiple-choice options. When omitted, the UI falls back to free-text. */
|
|
35
|
+
options?: AskUserChoice[];
|
|
36
|
+
/** Allow the user to pick more than one option. Defaults to false. */
|
|
37
|
+
multiSelect?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Function the host UI / server uses to ask the user a question.
|
|
41
|
+
*
|
|
42
|
+
* Second argument is optional for backwards compatibility — callers that
|
|
43
|
+
* only need free text can omit it; backends that don't support options
|
|
44
|
+
* should ignore the field and prompt for free text.
|
|
45
|
+
*
|
|
46
|
+
* Return value:
|
|
47
|
+
* - Free-text mode: the user's typed answer (or "(user declined to answer)").
|
|
48
|
+
* - Multiple-choice mode: the selected label, or comma-separated labels for
|
|
49
|
+
* multiSelect, or "Other: <typed>" when the user picks the implicit
|
|
50
|
+
* Other... entry.
|
|
51
|
+
*/
|
|
52
|
+
export type AskUserFn = (question: string, opts?: AskUserOptions) => Promise<string>;
|
|
53
|
+
/** Spawn a sub-agent. Returns the produced text or throws. */
|
|
54
|
+
export interface SubAgentSpawnRequest {
|
|
55
|
+
agentId: string;
|
|
56
|
+
description: string;
|
|
57
|
+
prompt: string;
|
|
58
|
+
maxTurns: number;
|
|
59
|
+
signal: AbortSignal;
|
|
60
|
+
/**
|
|
61
|
+
* Per-call override for where the spawned child Engine's stream events go.
|
|
62
|
+
* Defaults to `spawner.parentStream` (the parent UI). Background sub-agents
|
|
63
|
+
* pass a transcriptSink here so per-event detail is captured in the agent's
|
|
64
|
+
* transcript instead of leaking into the main feed; the main feed still
|
|
65
|
+
* gets `agent_start` / `agent_end` markers via `spawner.parentStream`.
|
|
66
|
+
*/
|
|
67
|
+
streamOverride?: StreamCallback;
|
|
68
|
+
}
|
|
69
|
+
export interface SubAgentSpawner {
|
|
70
|
+
/** Run a sub-agent synchronously and return its text output. */
|
|
71
|
+
spawn(req: SubAgentSpawnRequest): Promise<string>;
|
|
72
|
+
/** Stream callback to forward sub-agent events back to the parent UI. */
|
|
73
|
+
parentStream?: StreamCallback;
|
|
74
|
+
/** Static config used to describe what the spawned engine looks like. */
|
|
75
|
+
describe(): {
|
|
76
|
+
cwd: string;
|
|
77
|
+
preset?: AgentPresetName;
|
|
78
|
+
permissionMode: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The full context object handed to every tool invocation.
|
|
83
|
+
*
|
|
84
|
+
* Optional fields are filled in by Engine.run(); some headless paths may
|
|
85
|
+
* leave them undefined (e.g. running without UI → no askUser).
|
|
86
|
+
*/
|
|
87
|
+
export interface ToolContext {
|
|
88
|
+
/** Active working directory for this Engine. */
|
|
89
|
+
cwd: string;
|
|
90
|
+
/** LLM credentials/endpoint for tools that need to make their own calls. */
|
|
91
|
+
llmConfig: LLMConfig;
|
|
92
|
+
/** Active model pool (Arena reads this to pick participants). */
|
|
93
|
+
modelPool?: ModelPool;
|
|
94
|
+
/** Tool registry (ToolSearch reads this to enumerate available tools). */
|
|
95
|
+
toolRegistry: ToolRegistry;
|
|
96
|
+
/** UI-backed AskUserQuestion handler. Undefined → headless mode. */
|
|
97
|
+
askUser?: AskUserFn;
|
|
98
|
+
/** Sub-agent spawner (Agent tool). Undefined → Agent tool unavailable. */
|
|
99
|
+
subAgentSpawner?: SubAgentSpawner;
|
|
100
|
+
/**
|
|
101
|
+
* True when this Engine is itself a sub-agent. Set from EngineConfig.
|
|
102
|
+
* The Agent tool refuses to spawn when this is true — runtime check
|
|
103
|
+
* layered on top of the tool-list strip in Engine.spawn so a registry
|
|
104
|
+
* regression can't leak nested spawns.
|
|
105
|
+
*/
|
|
106
|
+
isSubAgent?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Active sandbox backend for the Bash tool. Undefined falls back to "off"
|
|
109
|
+
* (plain spawn). Headless runs default to an OS-level sandbox; the REPL
|
|
110
|
+
* defaults to off because a human is in the loop to approve commands.
|
|
111
|
+
*/
|
|
112
|
+
sandbox?: SandboxBackend;
|
|
113
|
+
/** Optional cancellation signal for the whole turn. */
|
|
114
|
+
signal?: AbortSignal;
|
|
115
|
+
/**
|
|
116
|
+
* Engine-owned HookRegistry. Tools that emit lifecycle hooks
|
|
117
|
+
* (notification, file_changed for non-Write/Edit paths, custom
|
|
118
|
+
* tool-defined events) use this. Undefined for legacy callers /
|
|
119
|
+
* standalone tests; tools must tolerate absence.
|
|
120
|
+
*/
|
|
121
|
+
hooks?: HookRegistry;
|
|
122
|
+
/**
|
|
123
|
+
* Per-turn stream sink (engine.run's `onStream`). Tools that need to
|
|
124
|
+
* push UI events independently of their return value use this — e.g.
|
|
125
|
+
* TodoWrite emits a `task_update` so the desktop pinned panel and
|
|
126
|
+
* tui task list refresh immediately rather than waiting for the LLM
|
|
127
|
+
* to surface the snapshot in the next turn. Undefined in
|
|
128
|
+
* headless/test mode; tools must tolerate absence.
|
|
129
|
+
*/
|
|
130
|
+
streamCallback?: StreamCallback;
|
|
131
|
+
/** Whether the owning Engine is currently in plan mode. Replaces the
|
|
132
|
+
* removed module-level `isInPlanMode()` singleton. */
|
|
133
|
+
planMode: boolean;
|
|
134
|
+
/** The Engine that built this context. Lets tools call back into the engine
|
|
135
|
+
* (e.g. ctx.engine.setPlanMode(true/false)) without a module-level singleton. */
|
|
136
|
+
engine: Engine;
|
|
137
|
+
/**
|
|
138
|
+
* sessionId of the Engine.run() turn this context was built for. Tools
|
|
139
|
+
* that emit session-scoped side effects (today: background-agent
|
|
140
|
+
* completion notifications) attribute the event by this. Undefined for
|
|
141
|
+
* ad-hoc contexts built outside Engine.run() — e.g. memory.auto_dream's
|
|
142
|
+
* narrow context, or standalone tool tests. (B2 — Gate 1, standard §S3.)
|
|
143
|
+
*/
|
|
144
|
+
sessionId?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Skill names the user has hidden from the LLM (full namespaced names
|
|
147
|
+
* for plugin skills, e.g. "docs:pdf"). The skill builtin tool uses
|
|
148
|
+
* this to refuse direct invocation of a disabled skill so the UI
|
|
149
|
+
* toggle is honored at dispatch time, not just in the prompt listing.
|
|
150
|
+
* Populated from `settings.disabledSkills` by Engine.run().
|
|
151
|
+
*/
|
|
152
|
+
disabledSkills?: string[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Per-Engine container that produces a fresh ToolContext on demand.
|
|
156
|
+
* Engine creates one of these in run() and passes it to ToolExecutor.
|
|
157
|
+
*/
|
|
158
|
+
export declare class ServiceContainer {
|
|
159
|
+
private readonly base;
|
|
160
|
+
constructor(base: ToolContext);
|
|
161
|
+
/** Snapshot of the context at this moment. */
|
|
162
|
+
get(): ToolContext;
|
|
163
|
+
/** Create a derived context with overridden fields (e.g. per-call signal). */
|
|
164
|
+
withSignal(signal: AbortSignal): ToolContext;
|
|
165
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-Engine container that produces a fresh ToolContext on demand.
|
|
3
|
+
* Engine creates one of these in run() and passes it to ToolExecutor.
|
|
4
|
+
*/
|
|
5
|
+
export class ServiceContainer {
|
|
6
|
+
base;
|
|
7
|
+
constructor(base) {
|
|
8
|
+
this.base = base;
|
|
9
|
+
}
|
|
10
|
+
/** Snapshot of the context at this moment. */
|
|
11
|
+
get() {
|
|
12
|
+
return this.base;
|
|
13
|
+
}
|
|
14
|
+
/** Create a derived context with overridden fields (e.g. per-call signal). */
|
|
15
|
+
withSignal(signal) {
|
|
16
|
+
return { ...this.base, signal };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool executor — orchestrates permission checks, hooks, and execution.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolCall, ToolResult, Message } from "../types.js";
|
|
5
|
+
import type { HookRegistry } from "../hooks/registry.js";
|
|
6
|
+
import { ToolRegistry } from "./registry.js";
|
|
7
|
+
import { PermissionClassifier } from "./permission.js";
|
|
8
|
+
import { logger as rootLogger } from "../logging/logger.js";
|
|
9
|
+
import type { ToolContext } from "./context.js";
|
|
10
|
+
import type { InvestigationGuard } from "./investigation-guard.js";
|
|
11
|
+
import type { TaskGuard } from "./task-guard.js";
|
|
12
|
+
type Logger = typeof rootLogger;
|
|
13
|
+
export declare class ToolExecutor {
|
|
14
|
+
private readonly registry;
|
|
15
|
+
private readonly permission;
|
|
16
|
+
private readonly hooks;
|
|
17
|
+
private signal?;
|
|
18
|
+
/** Per-Engine ToolContext injected for every tool call. */
|
|
19
|
+
private toolCtx?;
|
|
20
|
+
/**
|
|
21
|
+
* Turn-scoped logger set by TurnLoop at the top of each iteration.
|
|
22
|
+
* Falls back to the root logger so executor calls outside the turn loop
|
|
23
|
+
* (tests, ad-hoc tool runs) still write log lines, just without turn tags.
|
|
24
|
+
*/
|
|
25
|
+
private log;
|
|
26
|
+
private guard?;
|
|
27
|
+
private taskGuard?;
|
|
28
|
+
constructor(registry: ToolRegistry, permission: PermissionClassifier, hooks: HookRegistry);
|
|
29
|
+
setInvestigationGuard(guard: InvestigationGuard | undefined): void;
|
|
30
|
+
getInvestigationGuard(): InvestigationGuard | undefined;
|
|
31
|
+
setTaskGuard(guard: TaskGuard | undefined): void;
|
|
32
|
+
getTaskGuard(): TaskGuard | undefined;
|
|
33
|
+
/** Set the abort signal for cascading cancellation. */
|
|
34
|
+
setSignal(signal?: AbortSignal): void;
|
|
35
|
+
/** Set the per-Engine ToolContext (askUser, llmConfig, modelPool, etc.). */
|
|
36
|
+
setContext(ctx: ToolContext | undefined): void;
|
|
37
|
+
/** Inject a turn-scoped logger so tool-execution lines carry turn/turnId. */
|
|
38
|
+
setLogger(log: Logger): void;
|
|
39
|
+
/** Check if a tool is safe for concurrent execution (read-only). */
|
|
40
|
+
isConcurrencySafe(toolName: string): boolean;
|
|
41
|
+
executeSingle(callIn: ToolCall): Promise<ToolResult>;
|
|
42
|
+
private isReadOnlyBashCommand;
|
|
43
|
+
executeAll(calls: ToolCall[]): Promise<ToolResult[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Convert tool results into Message entries for the transcript.
|
|
46
|
+
*/
|
|
47
|
+
resultsToMessages(toolCalls: ToolCall[], results: ToolResult[]): Message[];
|
|
48
|
+
}
|
|
49
|
+
export {};
|