@tomsun28/pizza 0.1.0 → 0.1.1
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/README.md +20 -143
- package/README.zh-CN.md +36 -0
- package/dist/bun/cli.d.ts +2 -0
- package/dist/bun/cli.js +6 -0
- package/dist/bun/register-bedrock.d.ts +1 -0
- package/dist/bun/register-bedrock.js +3 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/args.js +330 -0
- package/dist/cli/config-selector.d.ts +13 -0
- package/dist/cli/config-selector.js +30 -0
- package/dist/cli/file-processor.d.ts +14 -0
- package/dist/cli/file-processor.js +82 -0
- package/dist/cli/initial-message.d.ts +17 -0
- package/dist/cli/initial-message.js +21 -0
- package/dist/cli/list-models.d.ts +8 -0
- package/dist/cli/list-models.js +96 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +68 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +223 -0
- package/dist/core/agent/index.d.ts +6 -0
- package/dist/core/agent/index.js +6 -0
- package/dist/core/agent/types.d.ts +202 -0
- package/dist/core/agent/types.js +51 -0
- package/dist/core/auth-storage.d.ts +135 -0
- package/dist/core/auth-storage.js +417 -0
- package/dist/core/bash-executor.d.ts +31 -0
- package/dist/core/bash-executor.js +107 -0
- package/dist/core/compaction/branch-summarization.d.ts +87 -0
- package/dist/core/compaction/branch-summarization.js +242 -0
- package/dist/core/compaction/compaction-engine.d.ts +40 -0
- package/dist/core/compaction/compaction-engine.js +292 -0
- package/dist/core/compaction/compaction.d.ts +106 -0
- package/dist/core/compaction/compaction.js +295 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/utils.d.ts +37 -0
- package/dist/core/compaction/utils.js +152 -0
- package/dist/core/defaults.d.ts +2 -0
- package/dist/core/defaults.js +1 -0
- package/dist/core/diagnostics.d.ts +14 -0
- package/dist/core/diagnostics.js +1 -0
- package/dist/core/event-bus.d.ts +8 -0
- package/dist/core/event-bus.js +24 -0
- package/dist/core/event-store/events.d.ts +465 -0
- package/dist/core/event-store/events.js +6 -0
- package/dist/core/event-store/index.d.ts +10 -0
- package/dist/core/event-store/index.js +10 -0
- package/dist/core/event-store/sqlite-store.d.ts +27 -0
- package/dist/core/event-store/sqlite-store.js +275 -0
- package/dist/core/event-store/store.d.ts +91 -0
- package/dist/core/event-store/store.js +7 -0
- package/dist/core/event-store/thread-scoped-store.d.ts +29 -0
- package/dist/core/event-store/thread-scoped-store.js +50 -0
- package/dist/core/event-store/types.d.ts +70 -0
- package/dist/core/event-store/types.js +7 -0
- package/dist/core/event-store/workspace.d.ts +37 -0
- package/dist/core/event-store/workspace.js +71 -0
- package/dist/core/exec.d.ts +28 -0
- package/dist/core/exec.js +74 -0
- package/dist/core/export-html/ansi-to-html.d.ts +21 -0
- package/dist/core/export-html/ansi-to-html.js +248 -0
- package/dist/core/export-html/index.d.ts +29 -0
- package/dist/core/export-html/index.js +186 -0
- package/dist/core/export-html/template.css +1017 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1742 -0
- package/dist/core/export-html/tool-renderer.d.ts +39 -0
- package/dist/core/export-html/tool-renderer.js +94 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +6 -0
- package/dist/core/extensions/index.d.ts +12 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/loader.d.ts +24 -0
- package/dist/core/extensions/loader.js +492 -0
- package/dist/core/extensions/runner.d.ts +167 -0
- package/dist/core/extensions/runner.js +898 -0
- package/dist/core/extensions/session-context.d.ts +67 -0
- package/dist/core/extensions/session-context.js +272 -0
- package/dist/core/extensions/types.d.ts +1147 -0
- package/dist/core/extensions/types.js +44 -0
- package/dist/core/extensions/wrapper.d.ts +19 -0
- package/dist/core/extensions/wrapper.js +21 -0
- package/dist/core/footer-data-provider.d.ts +47 -0
- package/dist/core/footer-data-provider.js +321 -0
- package/dist/core/goal/index.d.ts +3 -0
- package/dist/core/goal/index.js +1 -0
- package/dist/core/goal/scheduler.d.ts +83 -0
- package/dist/core/goal/scheduler.js +154 -0
- package/dist/core/goal/types.d.ts +182 -0
- package/dist/core/goal/types.js +11 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.js +8 -0
- package/dist/core/intent/classifier.d.ts +53 -0
- package/dist/core/intent/classifier.js +353 -0
- package/dist/core/intent/index.d.ts +8 -0
- package/dist/core/intent/index.js +8 -0
- package/dist/core/intent/tool-adapter.d.ts +31 -0
- package/dist/core/intent/tool-adapter.js +168 -0
- package/dist/core/intent/types.d.ts +71 -0
- package/dist/core/intent/types.js +6 -0
- package/dist/core/keybindings.d.ts +297 -0
- package/dist/core/keybindings.js +250 -0
- package/dist/core/messages.d.ts +30 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/model-registry.d.ts +131 -0
- package/dist/core/model-registry.js +634 -0
- package/dist/core/model-resolver.d.ts +109 -0
- package/dist/core/model-resolver.js +486 -0
- package/dist/core/output-guard.d.ts +5 -0
- package/dist/core/output-guard.js +58 -0
- package/dist/core/package-manager.d.ts +196 -0
- package/dist/core/package-manager.js +1873 -0
- package/dist/core/projection/boundary-inferrer.d.ts +58 -0
- package/dist/core/projection/boundary-inferrer.js +122 -0
- package/dist/core/projection/event-to-message.d.ts +35 -0
- package/dist/core/projection/event-to-message.js +253 -0
- package/dist/core/projection/goal-projection.d.ts +67 -0
- package/dist/core/projection/goal-projection.js +339 -0
- package/dist/core/projection/index.d.ts +13 -0
- package/dist/core/projection/index.js +13 -0
- package/dist/core/projection/session-manager.d.ts +100 -0
- package/dist/core/projection/session-manager.js +331 -0
- package/dist/core/projection/session-projection.d.ts +58 -0
- package/dist/core/projection/session-projection.js +257 -0
- package/dist/core/projection/task-history.d.ts +13 -0
- package/dist/core/projection/task-history.js +61 -0
- package/dist/core/projection/timeline-projection.d.ts +82 -0
- package/dist/core/projection/timeline-projection.js +276 -0
- package/dist/core/projection/types.d.ts +69 -0
- package/dist/core/projection/types.js +6 -0
- package/dist/core/prompt-templates.d.ts +51 -0
- package/dist/core/prompt-templates.js +249 -0
- package/dist/core/resolve-config-value.d.ts +22 -0
- package/dist/core/resolve-config-value.js +125 -0
- package/dist/core/resource-loader.d.ts +193 -0
- package/dist/core/resource-loader.js +685 -0
- package/dist/core/runtime/ai-client.d.ts +12 -0
- package/dist/core/runtime/ai-client.js +153 -0
- package/dist/core/runtime/checkpoint.d.ts +12 -0
- package/dist/core/runtime/checkpoint.js +78 -0
- package/dist/core/runtime/index.d.ts +12 -0
- package/dist/core/runtime/index.js +12 -0
- package/dist/core/runtime/llm-types.d.ts +99 -0
- package/dist/core/runtime/llm-types.js +6 -0
- package/dist/core/runtime/local-runtime.d.ts +23 -0
- package/dist/core/runtime/local-runtime.js +59 -0
- package/dist/core/runtime/policies.d.ts +72 -0
- package/dist/core/runtime/policies.js +37 -0
- package/dist/core/runtime/reactor.d.ts +213 -0
- package/dist/core/runtime/reactor.js +992 -0
- package/dist/core/runtime/runtime.d.ts +191 -0
- package/dist/core/runtime/runtime.js +449 -0
- package/dist/core/runtime/types.d.ts +42 -0
- package/dist/core/runtime/types.js +1 -0
- package/dist/core/sdk.d.ts +12 -0
- package/dist/core/sdk.js +10 -0
- package/dist/core/session-context-builder.d.ts +9 -0
- package/dist/core/session-context-builder.js +87 -0
- package/dist/core/session-cwd.d.ts +18 -0
- package/dist/core/session-cwd.js +36 -0
- package/dist/core/session-facade-factory.d.ts +79 -0
- package/dist/core/session-facade-factory.js +460 -0
- package/dist/core/session-facade.d.ts +57 -0
- package/dist/core/session-facade.js +91 -0
- package/dist/core/session-listing.d.ts +30 -0
- package/dist/core/session-listing.js +168 -0
- package/dist/core/session-reader.d.ts +19 -0
- package/dist/core/session-reader.js +101 -0
- package/dist/core/session-ref.d.ts +7 -0
- package/dist/core/session-ref.js +25 -0
- package/dist/core/session-services.d.ts +51 -0
- package/dist/core/session-services.js +90 -0
- package/dist/core/session-stats.d.ts +43 -0
- package/dist/core/session-stats.js +41 -0
- package/dist/core/settings-manager.d.ts +236 -0
- package/dist/core/settings-manager.js +706 -0
- package/dist/core/skill-block-parser.d.ts +12 -0
- package/dist/core/skill-block-parser.js +15 -0
- package/dist/core/skills.d.ts +59 -0
- package/dist/core/skills.js +408 -0
- package/dist/core/slash-commands.d.ts +13 -0
- package/dist/core/slash-commands.js +17 -0
- package/dist/core/source-info.d.ts +17 -0
- package/dist/core/source-info.js +18 -0
- package/dist/core/system-prompt.d.ts +27 -0
- package/dist/core/system-prompt.js +179 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.js +30 -0
- package/dist/core/tools/bash.d.ts +95 -0
- package/dist/core/tools/bash.js +513 -0
- package/dist/core/tools/builtin-commands.d.ts +75 -0
- package/dist/core/tools/builtin-commands.js +503 -0
- package/dist/core/tools/compat-commands.d.ts +12 -0
- package/dist/core/tools/compat-commands.js +1280 -0
- package/dist/core/tools/edit-diff.d.ts +59 -0
- package/dist/core/tools/edit-diff.js +263 -0
- package/dist/core/tools/edit.d.ts +49 -0
- package/dist/core/tools/edit.js +340 -0
- package/dist/core/tools/file-mutation-queue.d.ts +5 -0
- package/dist/core/tools/file-mutation-queue.js +36 -0
- package/dist/core/tools/find.d.ts +34 -0
- package/dist/core/tools/find.js +459 -0
- package/dist/core/tools/grep.d.ts +36 -0
- package/dist/core/tools/grep.js +422 -0
- package/dist/core/tools/index.d.ts +70 -0
- package/dist/core/tools/index.js +129 -0
- package/dist/core/tools/line-anchors.d.ts +33 -0
- package/dist/core/tools/line-anchors.js +151 -0
- package/dist/core/tools/ls.d.ts +36 -0
- package/dist/core/tools/ls.js +268 -0
- package/dist/core/tools/path-utils.d.ts +7 -0
- package/dist/core/tools/path-utils.js +80 -0
- package/dist/core/tools/read.d.ts +35 -0
- package/dist/core/tools/read.js +244 -0
- package/dist/core/tools/render-utils.d.ts +20 -0
- package/dist/core/tools/render-utils.js +48 -0
- package/dist/core/tools/session-split.d.ts +9 -0
- package/dist/core/tools/session-split.js +77 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +13 -0
- package/dist/core/tools/tool-definition-wrapper.js +32 -0
- package/dist/core/tools/truncate.d.ts +69 -0
- package/dist/core/tools/truncate.js +204 -0
- package/dist/core/tools/write.d.ts +25 -0
- package/dist/core/tools/write.js +211 -0
- package/dist/core/types/session-types.d.ts +123 -0
- package/dist/core/types/session-types.js +8 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +38 -0
- package/dist/main.d.ts +11 -2
- package/dist/main.js +577 -149
- package/dist/modes/event-mapper.d.ts +115 -0
- package/dist/modes/event-mapper.js +200 -0
- package/dist/modes/gui/server.d.ts +14 -0
- package/dist/modes/gui/server.js +1032 -0
- package/dist/modes/index.d.ts +10 -0
- package/dist/modes/index.js +9 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/components/armin.d.ts +33 -0
- package/dist/modes/interactive/components/armin.js +328 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +19 -0
- package/dist/modes/interactive/components/assistant-message.js +115 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +33 -0
- package/dist/modes/interactive/components/bash-execution.js +169 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
- package/dist/modes/interactive/components/bordered-loader.js +50 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/branch-summary-message.js +41 -0
- package/dist/modes/interactive/components/brand-header.d.ts +33 -0
- package/dist/modes/interactive/components/brand-header.js +235 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +15 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +42 -0
- package/dist/modes/interactive/components/config-selector.d.ts +70 -0
- package/dist/modes/interactive/components/config-selector.js +469 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +13 -0
- package/dist/modes/interactive/components/countdown-timer.js +27 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +27 -0
- package/dist/modes/interactive/components/custom-editor.js +94 -0
- package/dist/modes/interactive/components/custom-message.d.ts +19 -0
- package/dist/modes/interactive/components/custom-message.js +73 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +22 -0
- package/dist/modes/interactive/components/daxnuts.js +137 -0
- package/dist/modes/interactive/components/diff.d.ts +11 -0
- package/dist/modes/interactive/components/diff.js +132 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +14 -0
- package/dist/modes/interactive/components/dynamic-border.js +19 -0
- package/dist/modes/interactive/components/earendil-announcement.d.ts +4 -0
- package/dist/modes/interactive/components/earendil-announcement.js +39 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +19 -0
- package/dist/modes/interactive/components/extension-editor.js +105 -0
- package/dist/modes/interactive/components/extension-input.d.ts +22 -0
- package/dist/modes/interactive/components/extension-input.js +54 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +23 -0
- package/dist/modes/interactive/components/extension-selector.js +70 -0
- package/dist/modes/interactive/components/footer.d.ts +55 -0
- package/dist/modes/interactive/components/footer.js +207 -0
- package/dist/modes/interactive/components/index.d.ts +31 -0
- package/dist/modes/interactive/components/index.js +32 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
- package/dist/modes/interactive/components/keybinding-hints.js +21 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +41 -0
- package/dist/modes/interactive/components/login-dialog.js +138 -0
- package/dist/modes/interactive/components/model-selector.d.ts +32 -0
- package/dist/modes/interactive/components/model-selector.js +209 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +18 -0
- package/dist/modes/interactive/components/oauth-selector.js +91 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +57 -0
- package/dist/modes/interactive/components/settings-selector.js +299 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +9 -0
- package/dist/modes/interactive/components/show-images-selector.js +37 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +16 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +44 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +10 -0
- package/dist/modes/interactive/components/theme-selector.js +47 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +10 -0
- package/dist/modes/interactive/components/thinking-selector.js +50 -0
- package/dist/modes/interactive/components/timeline-view.d.ts +31 -0
- package/dist/modes/interactive/components/timeline-view.js +81 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +64 -0
- package/dist/modes/interactive/components/tool-execution.js +305 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +88 -0
- package/dist/modes/interactive/components/tree-selector.js +1072 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +29 -0
- package/dist/modes/interactive/components/user-message-selector.js +110 -0
- package/dist/modes/interactive/components/user-message.d.ts +9 -0
- package/dist/modes/interactive/components/user-message.js +27 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +23 -0
- package/dist/modes/interactive/components/visual-truncate.js +32 -0
- package/dist/modes/interactive/interactive-mode.d.ts +394 -0
- package/dist/modes/interactive/interactive-mode.js +4116 -0
- package/dist/modes/interactive/theme/dark.json +85 -0
- package/dist/modes/interactive/theme/light.json +84 -0
- package/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/dist/modes/interactive/theme/theme.d.ts +80 -0
- package/dist/modes/interactive/theme/theme.js +973 -0
- package/dist/modes/print-mode.d.ts +27 -0
- package/dist/modes/print-mode.js +102 -0
- package/dist/modes/rpc/jsonl.d.ts +16 -0
- package/dist/modes/rpc/jsonl.js +48 -0
- package/dist/modes/rpc/rpc-client.d.ts +219 -0
- package/dist/modes/rpc/rpc-client.js +405 -0
- package/dist/modes/rpc/rpc-mode.d.ts +19 -0
- package/dist/modes/rpc/rpc-mode.js +381 -0
- package/dist/modes/rpc/rpc-types.d.ts +406 -0
- package/dist/modes/rpc/rpc-types.js +7 -0
- package/dist/package-manager-cli.d.ts +3 -0
- package/dist/package-manager-cli.js +233 -0
- package/dist/utils/changelog.d.ts +20 -0
- package/dist/utils/changelog.js +86 -0
- package/dist/utils/child-process.d.ts +10 -0
- package/dist/utils/child-process.js +77 -0
- package/dist/utils/clipboard-image.d.ts +10 -0
- package/dist/utils/clipboard-image.js +244 -0
- package/dist/utils/clipboard-native.d.ts +7 -0
- package/dist/utils/clipboard-native.js +13 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.js +77 -0
- package/dist/utils/exif-orientation.d.ts +4 -0
- package/dist/utils/exif-orientation.js +157 -0
- package/dist/utils/frontmatter.d.ts +7 -0
- package/dist/utils/frontmatter.js +25 -0
- package/dist/utils/git.d.ts +25 -0
- package/dist/utils/git.js +162 -0
- package/dist/utils/image-convert.d.ts +8 -0
- package/dist/utils/image-convert.js +38 -0
- package/dist/utils/image-resize.d.ts +35 -0
- package/dist/utils/image-resize.js +136 -0
- package/dist/utils/mime.d.ts +1 -0
- package/dist/utils/mime.js +25 -0
- package/dist/utils/path-shims.d.ts +1 -0
- package/dist/utils/path-shims.js +90 -0
- package/dist/utils/paths.d.ts +6 -0
- package/dist/utils/paths.js +18 -0
- package/dist/utils/photon.d.ts +20 -0
- package/dist/utils/photon.js +120 -0
- package/dist/utils/shell.d.ts +29 -0
- package/dist/utils/shell.js +189 -0
- package/dist/utils/sleep.d.ts +4 -0
- package/dist/utils/sleep.js +16 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.js +101 -0
- package/dist/vendor/bin/darwin-arm64/fd +0 -0
- package/dist/vendor/bin/darwin-arm64/rg +0 -0
- package/dist/vendor/bin/darwin-x64/fd +0 -0
- package/dist/vendor/bin/darwin-x64/rg +0 -0
- package/dist/vendor/bin/linux-arm64/fd +0 -0
- package/dist/vendor/bin/linux-arm64/rg +0 -0
- package/dist/vendor/bin/linux-x64/fd +0 -0
- package/dist/vendor/bin/linux-x64/rg +0 -0
- package/dist/vendor/bin/win32-arm64/fd.exe +0 -0
- package/dist/vendor/bin/win32-arm64/rg.exe +0 -0
- package/dist/vendor/bin/win32-x64/fd.exe +0 -0
- package/dist/vendor/bin/win32-x64/rg.exe +0 -0
- package/package.json +90 -26
- package/dist/extension/core.d.ts +0 -69
- package/dist/extension/core.js +0 -270
- package/dist/extension/core.js.map +0 -1
- package/dist/extension/index.d.ts +0 -14
- package/dist/extension/index.js +0 -374
- package/dist/extension/index.js.map +0 -1
- package/dist/main.js.map +0 -1
- package/themes/pizza.json +0 -87
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
3
|
+
import { Type } from "@sinclair/typebox";
|
|
4
|
+
import { spawn } from "child_process";
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "fs";
|
|
6
|
+
import { minimatch } from "minimatch";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
|
|
9
|
+
import { ensureTool } from "../../utils/tools-manager.js";
|
|
10
|
+
import { resolveToCwd } from "./path-utils.js";
|
|
11
|
+
import { getTextOutput, invalidArgText, shortenPath, str } from "./render-utils.js";
|
|
12
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
13
|
+
import { DEFAULT_MAX_BYTES, formatSize, GREP_MAX_LINE_LENGTH, truncateHead, truncateLine, } from "./truncate.js";
|
|
14
|
+
const grepSchema = Type.Object({
|
|
15
|
+
pattern: Type.String({ description: "Search pattern (regex or literal string)" }),
|
|
16
|
+
path: Type.Optional(Type.String({ description: "Directory or file to search (default: current directory)" })),
|
|
17
|
+
glob: Type.Optional(Type.String({ description: "Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'" })),
|
|
18
|
+
ignoreCase: Type.Optional(Type.Boolean({ description: "Case-insensitive search (default: false)" })),
|
|
19
|
+
literal: Type.Optional(Type.Boolean({ description: "Treat pattern as literal string instead of regex (default: false)" })),
|
|
20
|
+
context: Type.Optional(Type.Number({ description: "Number of lines to show before and after each match (default: 0)" })),
|
|
21
|
+
limit: Type.Optional(Type.Number({ description: "Maximum number of matches to return (default: 100)" })),
|
|
22
|
+
});
|
|
23
|
+
const DEFAULT_LIMIT = 100;
|
|
24
|
+
const SKIP_DIRS = new Set([".git", "node_modules"]);
|
|
25
|
+
const defaultGrepOperations = {
|
|
26
|
+
isDirectory: (p) => statSync(p).isDirectory(),
|
|
27
|
+
readFile: (p) => readFileSync(p, "utf-8"),
|
|
28
|
+
};
|
|
29
|
+
function toPosixPath(value) {
|
|
30
|
+
return value.split(path.sep).join("/");
|
|
31
|
+
}
|
|
32
|
+
function shouldIncludeByGlob(filePath, rootPath, glob) {
|
|
33
|
+
if (!glob)
|
|
34
|
+
return true;
|
|
35
|
+
const relative = toPosixPath(path.relative(rootPath, filePath));
|
|
36
|
+
return minimatch(relative, glob, { dot: true }) || minimatch(path.posix.basename(relative), glob, { dot: true });
|
|
37
|
+
}
|
|
38
|
+
function collectSearchFiles(searchPath, isDirectory, glob) {
|
|
39
|
+
if (!isDirectory)
|
|
40
|
+
return [searchPath];
|
|
41
|
+
const files = [];
|
|
42
|
+
const walk = (dir) => {
|
|
43
|
+
let entries;
|
|
44
|
+
try {
|
|
45
|
+
entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (entry.isDirectory() && SKIP_DIRS.has(entry.name))
|
|
52
|
+
continue;
|
|
53
|
+
const fullPath = path.join(dir, entry.name);
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
walk(fullPath);
|
|
56
|
+
}
|
|
57
|
+
else if (entry.isFile() && shouldIncludeByGlob(fullPath, searchPath, glob)) {
|
|
58
|
+
files.push(fullPath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
walk(searchPath);
|
|
63
|
+
return files;
|
|
64
|
+
}
|
|
65
|
+
function compileSearchPattern(pattern, ignoreCase, literal) {
|
|
66
|
+
const flags = ignoreCase ? "i" : "";
|
|
67
|
+
if (literal) {
|
|
68
|
+
return new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
69
|
+
}
|
|
70
|
+
return new RegExp(pattern, flags);
|
|
71
|
+
}
|
|
72
|
+
function formatGrepCall(args, theme) {
|
|
73
|
+
const pattern = str(args?.pattern);
|
|
74
|
+
const rawPath = str(args?.path);
|
|
75
|
+
const path = rawPath !== null ? shortenPath(rawPath || ".") : null;
|
|
76
|
+
const glob = str(args?.glob);
|
|
77
|
+
const limit = args?.limit;
|
|
78
|
+
const invalidArg = invalidArgText(theme);
|
|
79
|
+
let text = theme.fg("toolTitle", theme.bold("grep")) +
|
|
80
|
+
" " +
|
|
81
|
+
(pattern === null ? invalidArg : theme.fg("accent", `/${pattern || ""}/`)) +
|
|
82
|
+
theme.fg("toolOutput", ` in ${path === null ? invalidArg : path}`);
|
|
83
|
+
if (glob)
|
|
84
|
+
text += theme.fg("toolOutput", ` (${glob})`);
|
|
85
|
+
if (limit !== undefined)
|
|
86
|
+
text += theme.fg("toolOutput", ` limit ${limit}`);
|
|
87
|
+
return text;
|
|
88
|
+
}
|
|
89
|
+
function formatGrepResult(result, options, theme, showImages) {
|
|
90
|
+
const output = getTextOutput(result, showImages).trim();
|
|
91
|
+
let text = "";
|
|
92
|
+
if (output) {
|
|
93
|
+
const lines = output.split("\n");
|
|
94
|
+
const maxLines = options.expanded ? lines.length : 15;
|
|
95
|
+
const displayLines = lines.slice(0, maxLines);
|
|
96
|
+
const remaining = lines.length - maxLines;
|
|
97
|
+
text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
|
|
98
|
+
if (remaining > 0) {
|
|
99
|
+
text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const matchLimit = result.details?.matchLimitReached;
|
|
103
|
+
const truncation = result.details?.truncation;
|
|
104
|
+
const linesTruncated = result.details?.linesTruncated;
|
|
105
|
+
if (matchLimit || truncation?.truncated || linesTruncated) {
|
|
106
|
+
const warnings = [];
|
|
107
|
+
if (matchLimit)
|
|
108
|
+
warnings.push(`${matchLimit} matches limit`);
|
|
109
|
+
if (truncation?.truncated)
|
|
110
|
+
warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
|
|
111
|
+
if (linesTruncated)
|
|
112
|
+
warnings.push("some lines truncated");
|
|
113
|
+
text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
|
|
114
|
+
}
|
|
115
|
+
return text;
|
|
116
|
+
}
|
|
117
|
+
export function createGrepToolDefinition(cwd, options) {
|
|
118
|
+
const customOps = options?.operations;
|
|
119
|
+
return {
|
|
120
|
+
name: "grep",
|
|
121
|
+
label: "grep",
|
|
122
|
+
description: `Search file contents for a pattern. Returns matching lines with file paths and line numbers. Respects .gitignore. Output is truncated to ${DEFAULT_LIMIT} matches or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Long lines are truncated to ${GREP_MAX_LINE_LENGTH} chars.`,
|
|
123
|
+
promptSnippet: "Search file contents for patterns (respects .gitignore)",
|
|
124
|
+
parameters: grepSchema,
|
|
125
|
+
async execute(_toolCallId, { pattern, path: searchDir, glob, ignoreCase, literal, context, limit, }, signal, _onUpdate, _ctx) {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
if (signal?.aborted) {
|
|
128
|
+
reject(new Error("Operation aborted"));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let settled = false;
|
|
132
|
+
const settle = (fn) => {
|
|
133
|
+
if (!settled) {
|
|
134
|
+
settled = true;
|
|
135
|
+
fn();
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
(async () => {
|
|
139
|
+
try {
|
|
140
|
+
const rgPath = await ensureTool("rg", true);
|
|
141
|
+
const searchPath = resolveToCwd(searchDir || ".", cwd);
|
|
142
|
+
const ops = customOps ?? defaultGrepOperations;
|
|
143
|
+
let isDirectory;
|
|
144
|
+
try {
|
|
145
|
+
isDirectory = await ops.isDirectory(searchPath);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
settle(() => reject(new Error(`Path not found: ${searchPath}`)));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const contextValue = context && context > 0 ? context : 0;
|
|
152
|
+
const effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);
|
|
153
|
+
const formatPath = (filePath) => {
|
|
154
|
+
if (isDirectory) {
|
|
155
|
+
const relative = path.relative(searchPath, filePath);
|
|
156
|
+
if (relative && !relative.startsWith("..")) {
|
|
157
|
+
return relative.replace(/\\/g, "/");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return path.basename(filePath);
|
|
161
|
+
};
|
|
162
|
+
const fileCache = new Map();
|
|
163
|
+
const getFileLines = async (filePath) => {
|
|
164
|
+
let lines = fileCache.get(filePath);
|
|
165
|
+
if (!lines) {
|
|
166
|
+
try {
|
|
167
|
+
const content = await ops.readFile(filePath);
|
|
168
|
+
lines = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
lines = [];
|
|
172
|
+
}
|
|
173
|
+
fileCache.set(filePath, lines);
|
|
174
|
+
}
|
|
175
|
+
return lines;
|
|
176
|
+
};
|
|
177
|
+
const formatBlock = async (filePath, lineNumber) => {
|
|
178
|
+
const relativePath = formatPath(filePath);
|
|
179
|
+
const lines = await getFileLines(filePath);
|
|
180
|
+
if (!lines.length)
|
|
181
|
+
return [`${relativePath}:${lineNumber}: (unable to read file)`];
|
|
182
|
+
const block = [];
|
|
183
|
+
const start = contextValue > 0 ? Math.max(1, lineNumber - contextValue) : lineNumber;
|
|
184
|
+
const end = contextValue > 0 ? Math.min(lines.length, lineNumber + contextValue) : lineNumber;
|
|
185
|
+
for (let current = start; current <= end; current++) {
|
|
186
|
+
const lineText = lines[current - 1] ?? "";
|
|
187
|
+
const sanitized = lineText.replace(/\r/g, "");
|
|
188
|
+
const isMatchLine = current === lineNumber;
|
|
189
|
+
// Truncate long lines so grep output stays compact.
|
|
190
|
+
const { text: truncatedText, wasTruncated } = truncateLine(sanitized);
|
|
191
|
+
if (wasTruncated)
|
|
192
|
+
linesTruncated = true;
|
|
193
|
+
if (isMatchLine)
|
|
194
|
+
block.push(`${relativePath}:${current}: ${truncatedText}`);
|
|
195
|
+
else
|
|
196
|
+
block.push(`${relativePath}-${current}- ${truncatedText}`);
|
|
197
|
+
}
|
|
198
|
+
return block;
|
|
199
|
+
};
|
|
200
|
+
let matchCount = 0;
|
|
201
|
+
let matchLimitReached = false;
|
|
202
|
+
let linesTruncated = false;
|
|
203
|
+
const outputLines = [];
|
|
204
|
+
const finalizeMatches = () => {
|
|
205
|
+
if (matchCount === 0) {
|
|
206
|
+
settle(() => resolve({ content: [{ type: "text", text: "No matches found" }], details: undefined }));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const rawOutput = outputLines.join("\n");
|
|
210
|
+
// Apply byte truncation. There is no line limit here because the match limit already capped rows.
|
|
211
|
+
const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
|
|
212
|
+
let output = truncation.content;
|
|
213
|
+
const details = {};
|
|
214
|
+
// Build actionable notices for truncation and match limits.
|
|
215
|
+
const notices = [];
|
|
216
|
+
if (matchLimitReached) {
|
|
217
|
+
notices.push(`${effectiveLimit} matches limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`);
|
|
218
|
+
details.matchLimitReached = effectiveLimit;
|
|
219
|
+
}
|
|
220
|
+
if (truncation.truncated) {
|
|
221
|
+
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
|
|
222
|
+
details.truncation = truncation;
|
|
223
|
+
}
|
|
224
|
+
if (linesTruncated) {
|
|
225
|
+
notices.push(`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`);
|
|
226
|
+
details.linesTruncated = true;
|
|
227
|
+
}
|
|
228
|
+
if (notices.length > 0)
|
|
229
|
+
output += `\n\n[${notices.join(". ")}]`;
|
|
230
|
+
settle(() => resolve({
|
|
231
|
+
content: [{ type: "text", text: output }],
|
|
232
|
+
details: Object.keys(details).length > 0 ? details : undefined,
|
|
233
|
+
}));
|
|
234
|
+
};
|
|
235
|
+
if (!rgPath) {
|
|
236
|
+
if (!existsSync(searchPath)) {
|
|
237
|
+
settle(() => reject(new Error(`Path not found: ${searchPath}`)));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
let regex;
|
|
241
|
+
try {
|
|
242
|
+
regex = compileSearchPattern(pattern, ignoreCase, literal);
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
settle(() => reject(error instanceof Error ? error : new Error(String(error))));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const files = collectSearchFiles(searchPath, isDirectory, glob);
|
|
249
|
+
for (const filePath of files) {
|
|
250
|
+
if (signal?.aborted) {
|
|
251
|
+
settle(() => reject(new Error("Operation aborted")));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const lines = await getFileLines(filePath);
|
|
255
|
+
for (let i = 0; i < lines.length; i++) {
|
|
256
|
+
if (matchCount >= effectiveLimit)
|
|
257
|
+
break;
|
|
258
|
+
regex.lastIndex = 0;
|
|
259
|
+
if (!regex.test(lines[i] ?? ""))
|
|
260
|
+
continue;
|
|
261
|
+
matchCount++;
|
|
262
|
+
if (contextValue === 0) {
|
|
263
|
+
const relativePath = formatPath(filePath);
|
|
264
|
+
const sanitized = (lines[i] ?? "").replace(/\r/g, "");
|
|
265
|
+
const { text: truncatedText, wasTruncated } = truncateLine(sanitized);
|
|
266
|
+
if (wasTruncated)
|
|
267
|
+
linesTruncated = true;
|
|
268
|
+
outputLines.push(`${relativePath}:${i + 1}: ${truncatedText}`);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
outputLines.push(...await formatBlock(filePath, i + 1));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (matchCount >= effectiveLimit) {
|
|
275
|
+
matchLimitReached = true;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
finalizeMatches();
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const args = ["--json", "--line-number", "--color=never", "--hidden"];
|
|
283
|
+
if (ignoreCase)
|
|
284
|
+
args.push("--ignore-case");
|
|
285
|
+
if (literal)
|
|
286
|
+
args.push("--fixed-strings");
|
|
287
|
+
if (glob)
|
|
288
|
+
args.push("--glob", glob);
|
|
289
|
+
args.push(pattern, searchPath);
|
|
290
|
+
const child = spawn(rgPath, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
291
|
+
const rl = createInterface({ input: child.stdout });
|
|
292
|
+
let stderr = "";
|
|
293
|
+
let aborted = false;
|
|
294
|
+
let killedDueToLimit = false;
|
|
295
|
+
const cleanup = () => {
|
|
296
|
+
rl.close();
|
|
297
|
+
signal?.removeEventListener("abort", onAbort);
|
|
298
|
+
};
|
|
299
|
+
const stopChild = (dueToLimit = false) => {
|
|
300
|
+
if (!child.killed) {
|
|
301
|
+
killedDueToLimit = dueToLimit;
|
|
302
|
+
child.kill();
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
const onAbort = () => {
|
|
306
|
+
aborted = true;
|
|
307
|
+
stopChild();
|
|
308
|
+
};
|
|
309
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
310
|
+
child.stderr?.on("data", (chunk) => {
|
|
311
|
+
stderr += chunk.toString();
|
|
312
|
+
});
|
|
313
|
+
// Collect matches during streaming, then format them after rg exits.
|
|
314
|
+
const matches = [];
|
|
315
|
+
rl.on("line", (line) => {
|
|
316
|
+
if (!line.trim() || matchCount >= effectiveLimit)
|
|
317
|
+
return;
|
|
318
|
+
let event;
|
|
319
|
+
try {
|
|
320
|
+
event = JSON.parse(line);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (event.type === "match") {
|
|
326
|
+
matchCount++;
|
|
327
|
+
const filePath = event.data?.path?.text;
|
|
328
|
+
const lineNumber = event.data?.line_number;
|
|
329
|
+
const lineText = event.data?.lines?.text;
|
|
330
|
+
if (filePath && typeof lineNumber === "number")
|
|
331
|
+
matches.push({ filePath, lineNumber, lineText });
|
|
332
|
+
if (matchCount >= effectiveLimit) {
|
|
333
|
+
matchLimitReached = true;
|
|
334
|
+
stopChild(true);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
child.on("error", (error) => {
|
|
339
|
+
cleanup();
|
|
340
|
+
settle(() => reject(new Error(`Failed to run ripgrep: ${error.message}`)));
|
|
341
|
+
});
|
|
342
|
+
child.on("close", async (code) => {
|
|
343
|
+
cleanup();
|
|
344
|
+
if (aborted) {
|
|
345
|
+
settle(() => reject(new Error("Operation aborted")));
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (!killedDueToLimit && code !== 0 && code !== 1) {
|
|
349
|
+
const errorMsg = stderr.trim() || `ripgrep exited with code ${code}`;
|
|
350
|
+
settle(() => reject(new Error(errorMsg)));
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (matchCount === 0) {
|
|
354
|
+
settle(() => resolve({ content: [{ type: "text", text: "No matches found" }], details: undefined }));
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
// Format matches after streaming finishes so custom readFile() backends can be async.
|
|
358
|
+
for (const match of matches) {
|
|
359
|
+
if (contextValue === 0 && match.lineText !== undefined) {
|
|
360
|
+
const relativePath = formatPath(match.filePath);
|
|
361
|
+
const sanitized = match.lineText
|
|
362
|
+
.replace(/\r\n/g, "\n")
|
|
363
|
+
.replace(/\r/g, "")
|
|
364
|
+
.replace(/\n$/, "");
|
|
365
|
+
const { text: truncatedText, wasTruncated } = truncateLine(sanitized);
|
|
366
|
+
if (wasTruncated)
|
|
367
|
+
linesTruncated = true;
|
|
368
|
+
outputLines.push(`${relativePath}:${match.lineNumber}: ${truncatedText}`);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
const block = await formatBlock(match.filePath, match.lineNumber);
|
|
372
|
+
outputLines.push(...block);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const rawOutput = outputLines.join("\n");
|
|
376
|
+
// Apply byte truncation. There is no line limit here because the match limit already capped rows.
|
|
377
|
+
const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
|
|
378
|
+
let output = truncation.content;
|
|
379
|
+
const details = {};
|
|
380
|
+
// Build actionable notices for truncation and match limits.
|
|
381
|
+
const notices = [];
|
|
382
|
+
if (matchLimitReached) {
|
|
383
|
+
notices.push(`${effectiveLimit} matches limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`);
|
|
384
|
+
details.matchLimitReached = effectiveLimit;
|
|
385
|
+
}
|
|
386
|
+
if (truncation.truncated) {
|
|
387
|
+
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
|
|
388
|
+
details.truncation = truncation;
|
|
389
|
+
}
|
|
390
|
+
if (linesTruncated) {
|
|
391
|
+
notices.push(`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`);
|
|
392
|
+
details.linesTruncated = true;
|
|
393
|
+
}
|
|
394
|
+
if (notices.length > 0)
|
|
395
|
+
output += `\n\n[${notices.join(". ")}]`;
|
|
396
|
+
settle(() => resolve({
|
|
397
|
+
content: [{ type: "text", text: output }],
|
|
398
|
+
details: Object.keys(details).length > 0 ? details : undefined,
|
|
399
|
+
}));
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
settle(() => reject(err));
|
|
404
|
+
}
|
|
405
|
+
})();
|
|
406
|
+
});
|
|
407
|
+
},
|
|
408
|
+
renderCall(args, theme, context) {
|
|
409
|
+
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
410
|
+
text.setText(formatGrepCall(args, theme));
|
|
411
|
+
return text;
|
|
412
|
+
},
|
|
413
|
+
renderResult(result, options, theme, context) {
|
|
414
|
+
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
415
|
+
text.setText(formatGrepResult(result, options, theme, context.showImages));
|
|
416
|
+
return text;
|
|
417
|
+
},
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
export function createGrepTool(cwd, options) {
|
|
421
|
+
return wrapToolDefinition(createGrepToolDefinition(cwd, options));
|
|
422
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, createBashTool, createBashToolDefinition, createLocalBashOperations, } from "./bash.js";
|
|
2
|
+
export { createEditTool, createEditToolDefinition, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, } from "./edit.js";
|
|
3
|
+
export { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
4
|
+
export { createFindTool, createFindToolDefinition, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, } from "./find.js";
|
|
5
|
+
export { createGrepTool, createGrepToolDefinition, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, } from "./grep.js";
|
|
6
|
+
export { createLsTool, createLsToolDefinition, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, } from "./ls.js";
|
|
7
|
+
export { createReadTool, createReadToolDefinition, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, } from "./read.js";
|
|
8
|
+
export { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationOptions, type TruncationResult, truncateHead, truncateLine, truncateTail, } from "./truncate.js";
|
|
9
|
+
export { createWriteTool, createWriteToolDefinition, type WriteOperations, type WriteToolInput, type WriteToolOptions, } from "./write.js";
|
|
10
|
+
import type { AgentTool } from "../agent/types.js";
|
|
11
|
+
import type { ToolDefinition } from "../extensions/types.js";
|
|
12
|
+
import { type BashToolOptions } from "./bash.js";
|
|
13
|
+
import { type EditToolOptions } from "./edit.js";
|
|
14
|
+
import { type FindToolOptions } from "./find.js";
|
|
15
|
+
import { type GrepToolOptions } from "./grep.js";
|
|
16
|
+
import { type LsToolOptions } from "./ls.js";
|
|
17
|
+
import { type ReadToolOptions } from "./read.js";
|
|
18
|
+
import { type WriteToolOptions } from "./write.js";
|
|
19
|
+
export type Tool = AgentTool<any>;
|
|
20
|
+
export type ToolDef = ToolDefinition<any, any>;
|
|
21
|
+
/**
|
|
22
|
+
* Default tools exposed to LLM via function calls.
|
|
23
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
24
|
+
* Other commands (grep, find, ls, git, npm, etc.) are passed to the system shell.
|
|
25
|
+
*/
|
|
26
|
+
export type ToolName = "cli" | "bash" | "read" | "edit" | "write" | "grep" | "find" | "ls";
|
|
27
|
+
export declare const allToolNames: Set<ToolName>;
|
|
28
|
+
/**
|
|
29
|
+
* Default tools exposed via function calls.
|
|
30
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
31
|
+
* Other commands (grep, find, ls, etc.) are passed to the system shell.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_LLM_TOOLS: ToolName[];
|
|
34
|
+
export interface ToolsOptions {
|
|
35
|
+
read?: ReadToolOptions;
|
|
36
|
+
cli?: BashToolOptions;
|
|
37
|
+
/** @deprecated Use cli. */
|
|
38
|
+
bash?: BashToolOptions;
|
|
39
|
+
write?: WriteToolOptions;
|
|
40
|
+
edit?: EditToolOptions;
|
|
41
|
+
grep?: GrepToolOptions;
|
|
42
|
+
find?: FindToolOptions;
|
|
43
|
+
ls?: LsToolOptions;
|
|
44
|
+
}
|
|
45
|
+
export declare function createToolDefinition(toolName: ToolName, cwd: string, options?: ToolsOptions): ToolDef;
|
|
46
|
+
export declare function createTool(toolName: ToolName, cwd: string, options?: ToolsOptions): Tool;
|
|
47
|
+
/**
|
|
48
|
+
* Default coding tools exposed via function calls.
|
|
49
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
50
|
+
* Other commands (grep, find, ls, git, npm, etc.) are passed to the system shell.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createCodingToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[];
|
|
53
|
+
/**
|
|
54
|
+
* Read-only tools for analysis mode.
|
|
55
|
+
* Only cli is exposed; read is handled internally; grep/find/ls are passed to shell.
|
|
56
|
+
*/
|
|
57
|
+
export declare function createReadOnlyToolDefinitions(cwd: string, options?: ToolsOptions): ToolDef[];
|
|
58
|
+
export declare function createAllToolDefinitions(cwd: string, options?: ToolsOptions): Record<ToolName, ToolDef>;
|
|
59
|
+
/**
|
|
60
|
+
* Default coding tools exposed to LLM.
|
|
61
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
62
|
+
* Other commands (grep, find, ls, git, npm, etc.) are passed to the system shell.
|
|
63
|
+
*/
|
|
64
|
+
export declare function createCodingTools(cwd: string, options?: ToolsOptions): Tool[];
|
|
65
|
+
/**
|
|
66
|
+
* Read-only tools for analysis mode.
|
|
67
|
+
* Only cli is exposed; read is handled internally; grep/find/ls are passed to shell.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[];
|
|
70
|
+
export declare function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export { createBashTool, createBashToolDefinition, createLocalBashOperations, } from "./bash.js";
|
|
2
|
+
export { createEditTool, createEditToolDefinition, } from "./edit.js";
|
|
3
|
+
export { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
4
|
+
export { createFindTool, createFindToolDefinition, } from "./find.js";
|
|
5
|
+
export { createGrepTool, createGrepToolDefinition, } from "./grep.js";
|
|
6
|
+
export { createLsTool, createLsToolDefinition, } from "./ls.js";
|
|
7
|
+
export { createReadTool, createReadToolDefinition, } from "./read.js";
|
|
8
|
+
export { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, truncateLine, truncateTail, } from "./truncate.js";
|
|
9
|
+
export { createWriteTool, createWriteToolDefinition, } from "./write.js";
|
|
10
|
+
import { createBashTool, createBashToolDefinition } from "./bash.js";
|
|
11
|
+
import { createEditTool, createEditToolDefinition } from "./edit.js";
|
|
12
|
+
import { createFindTool, createFindToolDefinition } from "./find.js";
|
|
13
|
+
import { createGrepTool, createGrepToolDefinition } from "./grep.js";
|
|
14
|
+
import { createLsTool, createLsToolDefinition } from "./ls.js";
|
|
15
|
+
import { createReadTool, createReadToolDefinition } from "./read.js";
|
|
16
|
+
import { createWriteTool, createWriteToolDefinition } from "./write.js";
|
|
17
|
+
export const allToolNames = new Set(["read", "cli", "bash", "edit", "write", "grep", "find", "ls"]);
|
|
18
|
+
/**
|
|
19
|
+
* Default tools exposed via function calls.
|
|
20
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
21
|
+
* Other commands (grep, find, ls, etc.) are passed to the system shell.
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_LLM_TOOLS = ["cli"];
|
|
24
|
+
export function createToolDefinition(toolName, cwd, options) {
|
|
25
|
+
switch (toolName) {
|
|
26
|
+
case "read":
|
|
27
|
+
return createReadToolDefinition(cwd, options?.read);
|
|
28
|
+
case "cli":
|
|
29
|
+
case "bash":
|
|
30
|
+
return createBashToolDefinition(cwd, options?.cli ?? options?.bash);
|
|
31
|
+
case "edit":
|
|
32
|
+
return createEditToolDefinition(cwd, options?.edit);
|
|
33
|
+
case "write":
|
|
34
|
+
return createWriteToolDefinition(cwd, options?.write);
|
|
35
|
+
case "grep":
|
|
36
|
+
return createGrepToolDefinition(cwd, options?.grep);
|
|
37
|
+
case "find":
|
|
38
|
+
return createFindToolDefinition(cwd, options?.find);
|
|
39
|
+
case "ls":
|
|
40
|
+
return createLsToolDefinition(cwd, options?.ls);
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unknown tool name: ${toolName}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function createTool(toolName, cwd, options) {
|
|
46
|
+
switch (toolName) {
|
|
47
|
+
case "read":
|
|
48
|
+
return createReadTool(cwd, options?.read);
|
|
49
|
+
case "cli":
|
|
50
|
+
case "bash":
|
|
51
|
+
return createBashTool(cwd, options?.cli ?? options?.bash);
|
|
52
|
+
case "edit":
|
|
53
|
+
return createEditTool(cwd, options?.edit);
|
|
54
|
+
case "write":
|
|
55
|
+
return createWriteTool(cwd, options?.write);
|
|
56
|
+
case "grep":
|
|
57
|
+
return createGrepTool(cwd, options?.grep);
|
|
58
|
+
case "find":
|
|
59
|
+
return createFindTool(cwd, options?.find);
|
|
60
|
+
case "ls":
|
|
61
|
+
return createLsTool(cwd, options?.ls);
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unknown tool name: ${toolName}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Default coding tools exposed via function calls.
|
|
68
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
69
|
+
* Other commands (grep, find, ls, git, npm, etc.) are passed to the system shell.
|
|
70
|
+
*/
|
|
71
|
+
export function createCodingToolDefinitions(cwd, options) {
|
|
72
|
+
return [
|
|
73
|
+
createBashToolDefinition(cwd, options?.cli ?? options?.bash),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Read-only tools for analysis mode.
|
|
78
|
+
* Only cli is exposed; read is handled internally; grep/find/ls are passed to shell.
|
|
79
|
+
*/
|
|
80
|
+
export function createReadOnlyToolDefinitions(cwd, options) {
|
|
81
|
+
return [
|
|
82
|
+
createBashToolDefinition(cwd, options?.cli ?? options?.bash),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
export function createAllToolDefinitions(cwd, options) {
|
|
86
|
+
const cliDefinition = createBashToolDefinition(cwd, options?.cli ?? options?.bash);
|
|
87
|
+
return {
|
|
88
|
+
read: createReadToolDefinition(cwd, options?.read),
|
|
89
|
+
cli: cliDefinition,
|
|
90
|
+
bash: cliDefinition,
|
|
91
|
+
edit: createEditToolDefinition(cwd, options?.edit),
|
|
92
|
+
write: createWriteToolDefinition(cwd, options?.write),
|
|
93
|
+
grep: createGrepToolDefinition(cwd, options?.grep),
|
|
94
|
+
find: createFindToolDefinition(cwd, options?.find),
|
|
95
|
+
ls: createLsToolDefinition(cwd, options?.ls),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Default coding tools exposed to LLM.
|
|
100
|
+
* Only cli is exposed; read/write/edit are handled internally by the cli tool.
|
|
101
|
+
* Other commands (grep, find, ls, git, npm, etc.) are passed to the system shell.
|
|
102
|
+
*/
|
|
103
|
+
export function createCodingTools(cwd, options) {
|
|
104
|
+
return [
|
|
105
|
+
createBashTool(cwd, options?.cli ?? options?.bash),
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Read-only tools for analysis mode.
|
|
110
|
+
* Only cli is exposed; read is handled internally; grep/find/ls are passed to shell.
|
|
111
|
+
*/
|
|
112
|
+
export function createReadOnlyTools(cwd, options) {
|
|
113
|
+
return [
|
|
114
|
+
createBashTool(cwd, options?.cli ?? options?.bash),
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
export function createAllTools(cwd, options) {
|
|
118
|
+
const cliTool = createBashTool(cwd, options?.cli ?? options?.bash);
|
|
119
|
+
return {
|
|
120
|
+
read: createReadTool(cwd, options?.read),
|
|
121
|
+
cli: cliTool,
|
|
122
|
+
bash: cliTool,
|
|
123
|
+
edit: createEditTool(cwd, options?.edit),
|
|
124
|
+
write: createWriteTool(cwd, options?.write),
|
|
125
|
+
grep: createGrepTool(cwd, options?.grep),
|
|
126
|
+
find: createFindTool(cwd, options?.find),
|
|
127
|
+
ls: createLsTool(cwd, options?.ls),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface LineAnchor {
|
|
2
|
+
line: number;
|
|
3
|
+
hash: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RangeAnchor {
|
|
6
|
+
start: LineAnchor;
|
|
7
|
+
end: LineAnchor;
|
|
8
|
+
}
|
|
9
|
+
export interface LineRecord {
|
|
10
|
+
lineNumber: number;
|
|
11
|
+
text: string;
|
|
12
|
+
startIndex: number;
|
|
13
|
+
contentEndIndex: number;
|
|
14
|
+
replacementEndIndex: number;
|
|
15
|
+
hash: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ResolvedLineRange {
|
|
18
|
+
range: string;
|
|
19
|
+
startLine: number;
|
|
20
|
+
endLine: number;
|
|
21
|
+
startIndex: number;
|
|
22
|
+
endIndex: number;
|
|
23
|
+
existingText: string;
|
|
24
|
+
usedRelocation: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function hashLine(line: string): string;
|
|
27
|
+
export declare function formatLineAnchor(lineNumber: number, line: string): string;
|
|
28
|
+
export declare function formatRange(start: LineAnchor, end?: LineAnchor): string;
|
|
29
|
+
export declare function looksLikeRange(value: string): boolean;
|
|
30
|
+
export declare function parseRange(range: string): RangeAnchor;
|
|
31
|
+
export declare function buildLineRecords(content: string): LineRecord[];
|
|
32
|
+
export declare function annotateTextWithLineAnchors(text: string, startLine?: number): string;
|
|
33
|
+
export declare function resolveRange(content: string, range: string, path: string): ResolvedLineRange;
|