@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,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan mode — restricts the agent to read-only exploration and text output.
|
|
3
|
+
*
|
|
4
|
+
* In plan mode the agent:
|
|
5
|
+
* - Can only use read-only tools (Read, Glob, Grep, Bash read-only, WebSearch, etc.)
|
|
6
|
+
* - CANNOT write, edit, or create files
|
|
7
|
+
* - Outputs its plan as text directly in the conversation
|
|
8
|
+
* - Exits plan mode when the user approves or via ExitPlanMode tool
|
|
9
|
+
*/
|
|
10
|
+
export const enterPlanModeToolDef = {
|
|
11
|
+
name: "EnterPlanMode",
|
|
12
|
+
description: "Enter plan mode for complex, high-risk, or ambiguous tasks. " +
|
|
13
|
+
"ONLY use this when: (1) the user explicitly asks for a plan before implementation, " +
|
|
14
|
+
"(2) the task involves large-scale refactoring across many files, or " +
|
|
15
|
+
"(3) the task is ambiguous and you need to propose an approach for user approval. " +
|
|
16
|
+
"Do NOT enter plan mode for straightforward tasks like fixing a bug, adding a small feature, " +
|
|
17
|
+
"or answering a question. In plan mode, output your plan as text, then call ExitPlanMode.",
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const exitPlanModeToolDef = {
|
|
24
|
+
name: "ExitPlanMode",
|
|
25
|
+
description: "Exit plan mode and return to normal mode. Call this after outputting your plan " +
|
|
26
|
+
"so you can proceed with implementation.",
|
|
27
|
+
inputSchema: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
// ─── Tool implementations ─────────────────────────────────────
|
|
33
|
+
export async function enterPlanModeTool(_args, ctx) {
|
|
34
|
+
if (ctx?.engine?.planMode) {
|
|
35
|
+
return "Already in plan mode. Output your plan as text, then call ExitPlanMode.";
|
|
36
|
+
}
|
|
37
|
+
ctx?.engine.setPlanMode(true);
|
|
38
|
+
return [
|
|
39
|
+
"Entered plan mode.",
|
|
40
|
+
"",
|
|
41
|
+
"Rules:",
|
|
42
|
+
"- You can ONLY use read-only tools: Read, Glob, Grep, WebSearch, WebFetch, and read-only Bash commands",
|
|
43
|
+
"- You CANNOT write, edit, or create any files",
|
|
44
|
+
"- Output your plan as text directly in the conversation",
|
|
45
|
+
"- Use markdown formatting with clear steps, file paths, and rationale",
|
|
46
|
+
"- Call ExitPlanMode when your plan is complete and ready for review",
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
49
|
+
export async function exitPlanModeTool(_args, ctx) {
|
|
50
|
+
if (!ctx?.engine?.planMode) {
|
|
51
|
+
return "Not currently in plan mode.";
|
|
52
|
+
}
|
|
53
|
+
ctx?.engine.setPlanMode(false);
|
|
54
|
+
return "Exited plan mode. You can now write and edit files to implement the plan.";
|
|
55
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PowerShellTool — execute PowerShell commands (Windows or pwsh).
|
|
3
|
+
*
|
|
4
|
+
* The lifecycle (spawn, abort/timeout cascade, IO drain, byte cap) is
|
|
5
|
+
* centralized in {@link safeSpawn}; this file only carries the pwsh /
|
|
6
|
+
* powershell.exe selection + the PowerShell-specific output formatting.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolDefinition } from "../../types.js";
|
|
9
|
+
import type { ToolContext } from "../context.js";
|
|
10
|
+
export declare const powershellToolDef: ToolDefinition;
|
|
11
|
+
export declare function powershellTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PowerShellTool — execute PowerShell commands (Windows or pwsh).
|
|
3
|
+
*
|
|
4
|
+
* The lifecycle (spawn, abort/timeout cascade, IO drain, byte cap) is
|
|
5
|
+
* centralized in {@link safeSpawn}; this file only carries the pwsh /
|
|
6
|
+
* powershell.exe selection + the PowerShell-specific output formatting.
|
|
7
|
+
*/
|
|
8
|
+
import { safeSpawn } from "../../runtime/safe-spawn.js";
|
|
9
|
+
export const powershellToolDef = {
|
|
10
|
+
name: "PowerShell",
|
|
11
|
+
description: "Execute PowerShell commands. Available on Windows and cross-platform where PowerShell Core is installed.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
command: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "The PowerShell command to execute",
|
|
18
|
+
},
|
|
19
|
+
timeout: {
|
|
20
|
+
type: "number",
|
|
21
|
+
description: "Timeout in milliseconds (default: 120000)",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ["command"],
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const PS_MAX_BUFFER = 5 * 1024 * 1024;
|
|
28
|
+
export async function powershellTool(args, ctx) {
|
|
29
|
+
const command = args.command;
|
|
30
|
+
const timeout = args.timeout ?? 120_000;
|
|
31
|
+
if (!command.trim()) {
|
|
32
|
+
return "Error: command is required.";
|
|
33
|
+
}
|
|
34
|
+
// Determine PowerShell executable.
|
|
35
|
+
const psCmd = process.platform === "win32" ? "powershell.exe" : "pwsh";
|
|
36
|
+
// A4: child process runs in the Engine's cwd, not the host process cwd.
|
|
37
|
+
const cwd = ctx?.cwd ?? process.cwd();
|
|
38
|
+
const wasAbortedBeforeStart = ctx?.signal?.aborted === true;
|
|
39
|
+
// PowerShell's -Command flag takes the script as a single argument;
|
|
40
|
+
// passing it through argv avoids shell quoting issues.
|
|
41
|
+
const result = await safeSpawn(psCmd, ["-NoProfile", "-NonInteractive", "-Command", command], {
|
|
42
|
+
cwd,
|
|
43
|
+
env: { ...process.env },
|
|
44
|
+
timeoutMs: timeout,
|
|
45
|
+
maxOutputBytes: PS_MAX_BUFFER,
|
|
46
|
+
signal: ctx?.signal,
|
|
47
|
+
});
|
|
48
|
+
if (result.aborted) {
|
|
49
|
+
return wasAbortedBeforeStart
|
|
50
|
+
? "PowerShell aborted before starting."
|
|
51
|
+
: "PowerShell aborted by signal.";
|
|
52
|
+
}
|
|
53
|
+
if (result.timedOut) {
|
|
54
|
+
return `PowerShell timed out after ${timeout}ms`;
|
|
55
|
+
}
|
|
56
|
+
if (result.spawnFailed) {
|
|
57
|
+
return `PowerShell spawn error: ${result.error ?? "unknown error"}`;
|
|
58
|
+
}
|
|
59
|
+
if (result.exitCode !== 0) {
|
|
60
|
+
const out = [result.stdout.trim(), result.stderr.trim()].filter(Boolean).join("\n");
|
|
61
|
+
return `PowerShell error:\n${out || `exit code ${result.exitCode}`}`;
|
|
62
|
+
}
|
|
63
|
+
return result.stdout.trim() || "(no output)";
|
|
64
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Read file tool.
|
|
3
|
+
*/
|
|
4
|
+
import { readFile, stat } from "node:fs/promises";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { fileCache } from "./file-cache.js";
|
|
7
|
+
export const readToolDef = {
|
|
8
|
+
name: "Read",
|
|
9
|
+
description: "Read a file from the local filesystem. Returns the file content with line numbers. " +
|
|
10
|
+
"By default reads up to 2000 lines from the beginning. " +
|
|
11
|
+
"Use offset and limit to read specific portions of large files. " +
|
|
12
|
+
"For large files, consider using Grep first to find the relevant lines.\n\n" +
|
|
13
|
+
"Do NOT re-read a file you just edited to verify — Edit/Write would have errored " +
|
|
14
|
+
"if the change failed.\n" +
|
|
15
|
+
"Do NOT re-read a file (or the same range of a file) you've already read earlier in " +
|
|
16
|
+
"this conversation. The content is already in your context. If you need a different " +
|
|
17
|
+
"part of the file, read a different offset; otherwise decide with what you have.",
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
file_path: { type: "string", description: "Absolute path to the file to read" },
|
|
22
|
+
offset: { type: "number", description: "Line number to start reading from (1-based)" },
|
|
23
|
+
limit: { type: "number", description: "Number of lines to read (default: 2000)" },
|
|
24
|
+
},
|
|
25
|
+
required: ["file_path"],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const MAX_CONTENT_CHARS = 200_000;
|
|
29
|
+
export async function readTool(args) {
|
|
30
|
+
const filePath = args.file_path;
|
|
31
|
+
if (!filePath)
|
|
32
|
+
return "Error: file_path is required";
|
|
33
|
+
if (!existsSync(filePath))
|
|
34
|
+
return `Error: File not found: ${filePath}`;
|
|
35
|
+
try {
|
|
36
|
+
// Get file info first
|
|
37
|
+
const fileInfo = await stat(filePath);
|
|
38
|
+
const sizeKB = Math.round(fileInfo.size / 1024);
|
|
39
|
+
// Skip binary or excessively large files
|
|
40
|
+
if (fileInfo.size > 5 * 1024 * 1024) {
|
|
41
|
+
return `Error: File is too large (${sizeKB}KB). Use Grep to search for specific content, or provide offset and limit to read a portion.`;
|
|
42
|
+
}
|
|
43
|
+
// Try cache first, fall back to disk read
|
|
44
|
+
let content = await fileCache.get(filePath);
|
|
45
|
+
if (content === null) {
|
|
46
|
+
content = await readFile(filePath, "utf-8");
|
|
47
|
+
fileCache.set(filePath, content, fileInfo.mtimeMs);
|
|
48
|
+
}
|
|
49
|
+
const lines = content.split("\n");
|
|
50
|
+
const totalLines = lines.length;
|
|
51
|
+
const offset = Math.max(1, args.offset || 1);
|
|
52
|
+
const limit = args.limit || 2000;
|
|
53
|
+
const end = Math.min(totalLines, offset - 1 + limit);
|
|
54
|
+
const selected = lines.slice(offset - 1, end);
|
|
55
|
+
let numbered = selected.map((line, i) => `${offset + i}\t${line}`).join("\n");
|
|
56
|
+
// Truncate if too much content
|
|
57
|
+
if (numbered.length > MAX_CONTENT_CHARS) {
|
|
58
|
+
numbered = numbered.slice(0, MAX_CONTENT_CHARS) + "\n\n... content truncated";
|
|
59
|
+
}
|
|
60
|
+
// Add file metadata header
|
|
61
|
+
let header = "";
|
|
62
|
+
if (totalLines > limit || offset > 1) {
|
|
63
|
+
header = `[${filePath} — ${totalLines} lines total, showing ${offset}-${end}]\n`;
|
|
64
|
+
}
|
|
65
|
+
return header + (numbered || "(empty file)");
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
return `Error reading file: ${err.message}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RemoteTriggerTool — trigger remote agents/workflows.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from "../../types.js";
|
|
5
|
+
export declare const remoteTriggerToolDef: ToolDefinition;
|
|
6
|
+
export declare function remoteTriggerTool(args: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RemoteTriggerTool — trigger remote agents/workflows.
|
|
3
|
+
*/
|
|
4
|
+
export const remoteTriggerToolDef = {
|
|
5
|
+
name: "RemoteTrigger",
|
|
6
|
+
description: "Trigger a remote agent or workflow to execute a task. " +
|
|
7
|
+
"The agent runs asynchronously and results can be checked later.",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
name: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "The name/identifier of the remote trigger to execute",
|
|
14
|
+
},
|
|
15
|
+
prompt: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "The task prompt to send to the remote agent",
|
|
18
|
+
},
|
|
19
|
+
config: {
|
|
20
|
+
type: "object",
|
|
21
|
+
description: "Optional configuration for the remote execution",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ["name", "prompt"],
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export async function remoteTriggerTool(args) {
|
|
28
|
+
const name = args.name;
|
|
29
|
+
const prompt = args.prompt;
|
|
30
|
+
const config = args.config;
|
|
31
|
+
// Remote triggers are dispatched via the cron scheduler or external API
|
|
32
|
+
try {
|
|
33
|
+
const { existsSync, readFileSync, writeFileSync, mkdirSync } = await import("node:fs");
|
|
34
|
+
const { join } = await import("node:path");
|
|
35
|
+
const { homedir } = await import("node:os");
|
|
36
|
+
// Store trigger request for pickup by external scheduler
|
|
37
|
+
const triggerDir = join(homedir(), ".code-shell", "triggers");
|
|
38
|
+
mkdirSync(triggerDir, { recursive: true });
|
|
39
|
+
const trigger = {
|
|
40
|
+
id: `trigger_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
41
|
+
name,
|
|
42
|
+
prompt,
|
|
43
|
+
config,
|
|
44
|
+
createdAt: new Date().toISOString(),
|
|
45
|
+
status: "pending",
|
|
46
|
+
};
|
|
47
|
+
const triggerFile = join(triggerDir, `${trigger.id}.json`);
|
|
48
|
+
writeFileSync(triggerFile, JSON.stringify(trigger, null, 2), "utf-8");
|
|
49
|
+
return `Remote trigger "${name}" dispatched (ID: ${trigger.id}).\nStored at: ${triggerFile}`;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return `Remote trigger error: ${err.message}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REPLTool — execute code in an interactive REPL environment.
|
|
3
|
+
*
|
|
4
|
+
* The lifecycle (spawn, abort/timeout cascade, IO drain, byte cap) is
|
|
5
|
+
* centralized in {@link safeSpawn}; this file only carries the language
|
|
6
|
+
* runtime selection table and the REPL-specific output formatting.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolDefinition } from "../../types.js";
|
|
9
|
+
import type { ToolContext } from "../context.js";
|
|
10
|
+
export declare const replToolDef: ToolDefinition;
|
|
11
|
+
export declare function replTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REPLTool — execute code in an interactive REPL environment.
|
|
3
|
+
*
|
|
4
|
+
* The lifecycle (spawn, abort/timeout cascade, IO drain, byte cap) is
|
|
5
|
+
* centralized in {@link safeSpawn}; this file only carries the language
|
|
6
|
+
* runtime selection table and the REPL-specific output formatting.
|
|
7
|
+
*/
|
|
8
|
+
import { safeSpawn } from "../../runtime/safe-spawn.js";
|
|
9
|
+
export const replToolDef = {
|
|
10
|
+
name: "REPL",
|
|
11
|
+
description: "Execute code in an interactive REPL environment. Supports JavaScript/TypeScript (Node/Bun), " +
|
|
12
|
+
"Python, and Ruby. Results are returned as text output.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
language: {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["javascript", "typescript", "python", "ruby"],
|
|
19
|
+
description: "The programming language to execute",
|
|
20
|
+
},
|
|
21
|
+
code: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "The code to execute",
|
|
24
|
+
},
|
|
25
|
+
timeout: {
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Timeout in milliseconds (default: 30000)",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["language", "code"],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const REPL_MAX_BUFFER = 1024 * 1024;
|
|
34
|
+
export async function replTool(args, ctx) {
|
|
35
|
+
const language = args.language;
|
|
36
|
+
const code = args.code;
|
|
37
|
+
const timeout = args.timeout ?? 30_000;
|
|
38
|
+
// A4: child process runs in the Engine's cwd, not the host process cwd.
|
|
39
|
+
const cwd = ctx?.cwd ?? process.cwd();
|
|
40
|
+
if (!code.trim()) {
|
|
41
|
+
return "Error: no code provided.";
|
|
42
|
+
}
|
|
43
|
+
// A2: each entry is (file, [args]) so we can spawn without a shell.
|
|
44
|
+
// Args are passed as separate arguv entries, eliminating the
|
|
45
|
+
// execSync-style shell-quoting risk.
|
|
46
|
+
const commands = {
|
|
47
|
+
javascript: { file: "node", pre: ["-e"] },
|
|
48
|
+
typescript: typeof globalThis.Bun !== "undefined"
|
|
49
|
+
? { file: "bun", pre: ["-e"] }
|
|
50
|
+
: { file: "npx", pre: ["tsx", "-e"] },
|
|
51
|
+
python: { file: "python3", pre: ["-c"] },
|
|
52
|
+
ruby: { file: "ruby", pre: ["-e"] },
|
|
53
|
+
};
|
|
54
|
+
const runtime = commands[language];
|
|
55
|
+
if (!runtime) {
|
|
56
|
+
return `Unsupported language: ${language}. Supported: ${Object.keys(commands).join(", ")}`;
|
|
57
|
+
}
|
|
58
|
+
const wasAbortedBeforeStart = ctx?.signal?.aborted === true;
|
|
59
|
+
const result = await safeSpawn(runtime.file, [...runtime.pre, code], {
|
|
60
|
+
cwd,
|
|
61
|
+
env: { ...process.env },
|
|
62
|
+
timeoutMs: timeout,
|
|
63
|
+
maxOutputBytes: REPL_MAX_BUFFER,
|
|
64
|
+
signal: ctx?.signal,
|
|
65
|
+
});
|
|
66
|
+
if (result.aborted) {
|
|
67
|
+
return wasAbortedBeforeStart
|
|
68
|
+
? `${language} aborted before starting.`
|
|
69
|
+
: `${language} aborted by signal.`;
|
|
70
|
+
}
|
|
71
|
+
if (result.timedOut) {
|
|
72
|
+
return `${language} timed out after ${timeout}ms`;
|
|
73
|
+
}
|
|
74
|
+
if (result.spawnFailed) {
|
|
75
|
+
return `Failed to spawn ${language}: ${result.error ?? "unknown error"}`;
|
|
76
|
+
}
|
|
77
|
+
if (result.exitCode !== 0) {
|
|
78
|
+
const out = [result.stdout.trim(), result.stderr.trim()].filter(Boolean).join("\n");
|
|
79
|
+
return `Error executing ${language}:\n${out || `exit code ${result.exitCode}`}`;
|
|
80
|
+
}
|
|
81
|
+
return result.stdout.trim() || "(no output)";
|
|
82
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SendMessage tool — send messages between named agents.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from "../../types.js";
|
|
5
|
+
export declare const sendMessageToolDef: ToolDefinition;
|
|
6
|
+
export declare function sendMessageTool(args: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SendMessage tool — send messages between named agents.
|
|
3
|
+
*/
|
|
4
|
+
import { agentCoordinator } from "../../agent/coordinator.js";
|
|
5
|
+
export const sendMessageToolDef = {
|
|
6
|
+
name: "SendMessage",
|
|
7
|
+
description: "Send a message to another named agent. The target agent must have been " +
|
|
8
|
+
"spawned with a 'name' parameter via the Agent tool. " +
|
|
9
|
+
"Use this for coordinating work between multiple agents.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
to: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "The name of the target agent",
|
|
16
|
+
},
|
|
17
|
+
content: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "The message content to send",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ["to", "content"],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
export async function sendMessageTool(args) {
|
|
26
|
+
const to = args.to;
|
|
27
|
+
const content = args.content;
|
|
28
|
+
const from = args.__agentName ?? "main";
|
|
29
|
+
if (!to)
|
|
30
|
+
return "Error: 'to' is required";
|
|
31
|
+
if (!content)
|
|
32
|
+
return "Error: 'content' is required";
|
|
33
|
+
const target = agentCoordinator.get(to);
|
|
34
|
+
if (!target) {
|
|
35
|
+
const active = agentCoordinator.listActive();
|
|
36
|
+
const names = active.map((a) => a.name).join(", ");
|
|
37
|
+
return `Error: No agent named "${to}". Active agents: ${names || "none"}`;
|
|
38
|
+
}
|
|
39
|
+
if (target.status !== "running") {
|
|
40
|
+
return `Agent "${to}" is not running (status: ${target.status}).`;
|
|
41
|
+
}
|
|
42
|
+
const sent = agentCoordinator.send(from, to, content);
|
|
43
|
+
if (!sent) {
|
|
44
|
+
return `Failed to send message to "${to}".`;
|
|
45
|
+
}
|
|
46
|
+
return `Message sent to "${to}".`;
|
|
47
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill listing renderer for the system prompt. Mirrors Claude Code's split
|
|
3
|
+
* between scan/data layer (skills/scanner.ts) and render layer (this file),
|
|
4
|
+
* matching tools/SkillTool/prompt.ts in CC.
|
|
5
|
+
*/
|
|
6
|
+
import type { SkillDefinition } from "../../skills/scanner.js";
|
|
7
|
+
/**
|
|
8
|
+
* Render the system-prompt skill listing grouped by namespace.
|
|
9
|
+
*
|
|
10
|
+
* Skill names follow the convention `<namespace>:<short>` for plugin
|
|
11
|
+
* skills (see scanner.ts's `namespacedName`) and plain `<short>` for
|
|
12
|
+
* skills the user installs into ~/.code-shell/skills or the project's
|
|
13
|
+
* .code-shell/skills directory.
|
|
14
|
+
*
|
|
15
|
+
* A flat list grew unreadable once a few plugins were installed, and
|
|
16
|
+
* the LLM had to skim 40+ lines under a single heading. Grouping by
|
|
17
|
+
* namespace keeps related skills adjacent and lets the LLM scan
|
|
18
|
+
* intents ("which plugin handles X?") in one pass.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildSkillListing(skills: SkillDefinition[]): string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill listing renderer for the system prompt. Mirrors Claude Code's split
|
|
3
|
+
* between scan/data layer (skills/scanner.ts) and render layer (this file),
|
|
4
|
+
* matching tools/SkillTool/prompt.ts in CC.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Render the system-prompt skill listing grouped by namespace.
|
|
8
|
+
*
|
|
9
|
+
* Skill names follow the convention `<namespace>:<short>` for plugin
|
|
10
|
+
* skills (see scanner.ts's `namespacedName`) and plain `<short>` for
|
|
11
|
+
* skills the user installs into ~/.code-shell/skills or the project's
|
|
12
|
+
* .code-shell/skills directory.
|
|
13
|
+
*
|
|
14
|
+
* A flat list grew unreadable once a few plugins were installed, and
|
|
15
|
+
* the LLM had to skim 40+ lines under a single heading. Grouping by
|
|
16
|
+
* namespace keeps related skills adjacent and lets the LLM scan
|
|
17
|
+
* intents ("which plugin handles X?") in one pass.
|
|
18
|
+
*/
|
|
19
|
+
export function buildSkillListing(skills) {
|
|
20
|
+
if (skills.length === 0)
|
|
21
|
+
return "";
|
|
22
|
+
// Bucket by the part before the first ":" — that is either the
|
|
23
|
+
// plugin name (e.g. "superpowers") or an empty namespace for
|
|
24
|
+
// user/project skills, which we group under a friendlier label.
|
|
25
|
+
const USER_GROUP = "用户 / 项目";
|
|
26
|
+
const groups = new Map();
|
|
27
|
+
for (const s of skills) {
|
|
28
|
+
const colon = s.name.indexOf(":");
|
|
29
|
+
const key = colon > 0 ? s.name.slice(0, colon) : USER_GROUP;
|
|
30
|
+
const list = groups.get(key);
|
|
31
|
+
if (list)
|
|
32
|
+
list.push(s);
|
|
33
|
+
else
|
|
34
|
+
groups.set(key, [s]);
|
|
35
|
+
}
|
|
36
|
+
// Stable order: user/project first, then plugin namespaces
|
|
37
|
+
// alphabetically. The LLM benefits from a predictable layout.
|
|
38
|
+
const entries = [...groups.entries()].sort(([a], [b]) => {
|
|
39
|
+
if (a === USER_GROUP)
|
|
40
|
+
return -1;
|
|
41
|
+
if (b === USER_GROUP)
|
|
42
|
+
return 1;
|
|
43
|
+
return a.localeCompare(b);
|
|
44
|
+
});
|
|
45
|
+
const sections = [];
|
|
46
|
+
for (const [group, list] of entries) {
|
|
47
|
+
list.sort((a, b) => a.name.localeCompare(b.name));
|
|
48
|
+
const lines = list.map((s) => s.description ? `- ${s.name}: ${s.description}` : `- ${s.name}:`);
|
|
49
|
+
sections.push(`## ${group} (${list.length})\n${lines.join("\n")}`);
|
|
50
|
+
}
|
|
51
|
+
return `# Available Skills\n\n${sections.join("\n\n")}`;
|
|
52
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillTool — load a skill's SKILL.md body and return it as the tool result.
|
|
3
|
+
* The scanner is the single source of truth; this tool never reads the disk
|
|
4
|
+
* directly. Matches Claude Code's tools/SkillTool/SkillTool.ts pattern.
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolDefinition } from "../../types.js";
|
|
7
|
+
import type { ToolContext } from "../context.js";
|
|
8
|
+
export declare const skillToolDef: ToolDefinition;
|
|
9
|
+
export declare function skillTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillTool — load a skill's SKILL.md body and return it as the tool result.
|
|
3
|
+
* The scanner is the single source of truth; this tool never reads the disk
|
|
4
|
+
* directly. Matches Claude Code's tools/SkillTool/SkillTool.ts pattern.
|
|
5
|
+
*/
|
|
6
|
+
import { dirname } from "node:path";
|
|
7
|
+
import { scanSkills } from "../../skills/scanner.js";
|
|
8
|
+
export const skillToolDef = {
|
|
9
|
+
name: "Skill",
|
|
10
|
+
description: "Execute a skill within the main conversation. Skills provide specialized " +
|
|
11
|
+
"capabilities and domain knowledge. Use this tool with the skill name and " +
|
|
12
|
+
"optional arguments.",
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
skill: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "The skill name to invoke (e.g., 'pdf', 'brainstorming')",
|
|
19
|
+
},
|
|
20
|
+
args: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Optional arguments substituted into $ARGUMENTS / {args} placeholders",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ["skill"],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export async function skillTool(args, ctx) {
|
|
29
|
+
const skillName = args.skill;
|
|
30
|
+
const skillArgs = args.args ?? "";
|
|
31
|
+
if (!skillName) {
|
|
32
|
+
return "Error: skill name is required.";
|
|
33
|
+
}
|
|
34
|
+
// Reject disabled skills before scanning so the user gets a clear
|
|
35
|
+
// message that distinguishes "disabled" from "not found" — matches
|
|
36
|
+
// the UI's toggle semantics. The scanner would also filter the entry
|
|
37
|
+
// out, which alone would produce a misleading "not found" reply.
|
|
38
|
+
const disabledSkills = ctx?.disabledSkills;
|
|
39
|
+
if (disabledSkills && disabledSkills.includes(skillName)) {
|
|
40
|
+
return `Skill "${skillName}" is disabled. Enable it in Customize or remove it from settings.disabledSkills.`;
|
|
41
|
+
}
|
|
42
|
+
// A4: scan skills from the Engine's cwd, not the host process cwd.
|
|
43
|
+
const skills = scanSkills(ctx?.cwd ?? process.cwd(), { disabledSkills });
|
|
44
|
+
const found = skills.find((s) => s.name === skillName);
|
|
45
|
+
if (!found) {
|
|
46
|
+
return `Skill "${skillName}" not found. Run /skills to list available skills.`;
|
|
47
|
+
}
|
|
48
|
+
const skillDir = dirname(found.filePath);
|
|
49
|
+
const body = found.content
|
|
50
|
+
.replace(/\$ARGUMENTS/g, skillArgs)
|
|
51
|
+
.replace(/\{args\}/g, skillArgs)
|
|
52
|
+
.replace(/\$\{CODESHELL_SKILL_DIR\}/g, skillDir)
|
|
53
|
+
.replace(/\$\{CLAUDE_SKILL_DIR\}/g, skillDir);
|
|
54
|
+
return `Base directory for this skill: ${skillDir}\n\n${body}`;
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SleepTool — pause execution for a specified duration.
|
|
3
|
+
*/
|
|
4
|
+
export const sleepToolDef = {
|
|
5
|
+
name: "Sleep",
|
|
6
|
+
description: "Pause execution for a specified number of seconds. " +
|
|
7
|
+
"Useful for polling workflows or waiting for external processes. " +
|
|
8
|
+
"Maximum duration is 300 seconds (5 minutes).",
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
seconds: {
|
|
13
|
+
type: "number",
|
|
14
|
+
description: "Number of seconds to sleep (max 300)",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ["seconds"],
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export async function sleepTool(args) {
|
|
21
|
+
const seconds = Math.min(Math.max(Number(args.seconds) || 1, 0.1), 300);
|
|
22
|
+
const signal = args.__signal;
|
|
23
|
+
if (signal?.aborted)
|
|
24
|
+
return "Sleep aborted.";
|
|
25
|
+
await new Promise((resolve, reject) => {
|
|
26
|
+
const timer = setTimeout(resolve, seconds * 1000);
|
|
27
|
+
signal?.addEventListener("abort", () => {
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
reject(new Error("Sleep aborted"));
|
|
30
|
+
});
|
|
31
|
+
}).catch(() => { });
|
|
32
|
+
return `Slept for ${seconds} seconds.`;
|
|
33
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in task management — a single TodoWrite tool, cc-style.
|
|
3
|
+
*
|
|
4
|
+
* Design (2026-05-24 simplification, replacing the legacy 6-tool API):
|
|
5
|
+
*
|
|
6
|
+
* - One tool, one shape: TodoWrite({ todos: [{content, status, activeForm}] }).
|
|
7
|
+
* Each call replaces the entire snapshot — no per-item update API.
|
|
8
|
+
* - The transcript IS the task store. The LLM reads its own last
|
|
9
|
+
* TodoWrite tool_use input to know "where am I in the list".
|
|
10
|
+
* - No module singleton. No in-memory map. No file persistence.
|
|
11
|
+
* Resume hydrates by scanning the loaded transcript for the most
|
|
12
|
+
* recent TodoWrite tool_use.
|
|
13
|
+
* - Sub-agent isolation: when called from a spawned sub-agent, the
|
|
14
|
+
* emitted task_update event carries the sub-agent's id so the UI
|
|
15
|
+
* can keep the main and sub-agent todo lists separate (cc bucketing
|
|
16
|
+
* by `context.agentId ?? sessionId`).
|
|
17
|
+
*
|
|
18
|
+
* Why no TaskManager:
|
|
19
|
+
* The legacy TaskCreate/Update/Stop/Get/Output/List sextet stored
|
|
20
|
+
* state behind a module-level TaskManager singleton. Desktop spawns
|
|
21
|
+
* one worker process per agent/run, so the singleton vanished after
|
|
22
|
+
* each run — the next run's `TaskList` returned "No tasks" even
|
|
23
|
+
* though the transcript still had the full plan. Replacing the
|
|
24
|
+
* sextet with one snapshot tool whose output lives in the transcript
|
|
25
|
+
* makes the worker's lifecycle irrelevant: every restart re-reads
|
|
26
|
+
* the snapshot for free.
|
|
27
|
+
*/
|
|
28
|
+
import type { ToolDefinition, TaskInfo, TranscriptEvent } from "../../types.js";
|
|
29
|
+
import type { ToolContext } from "../context.js";
|
|
30
|
+
export type TaskStatus = "pending" | "in_progress" | "completed";
|
|
31
|
+
export interface TodoItem {
|
|
32
|
+
content: string;
|
|
33
|
+
status: TaskStatus;
|
|
34
|
+
/** Present-continuous form shown while in_progress (e.g. "Fixing auth"). */
|
|
35
|
+
activeForm: string;
|
|
36
|
+
}
|
|
37
|
+
export type Task = TaskInfo;
|
|
38
|
+
export declare const todoWriteToolDef: ToolDefinition;
|
|
39
|
+
export declare function todoWriteTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Pull the latest todo snapshot from a transcript's event stream.
|
|
42
|
+
*
|
|
43
|
+
* Walks newest-first looking for a `tool_use` event whose toolName is
|
|
44
|
+
* TodoWrite — its args carry the canonical snapshot. Returns null if
|
|
45
|
+
* no TodoWrite call exists in the transcript (e.g. fresh session, or
|
|
46
|
+
* a session where the agent never used the tool).
|
|
47
|
+
*/
|
|
48
|
+
export declare function readLastTodoSnapshot(events: TranscriptEvent[]): TaskInfo[] | null;
|