@imdigitalashish/zpi 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/CHANGELOG.md +2801 -0
- package/README.md +95 -0
- package/dist/cli/args.d.ts +47 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +293 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/config-selector.d.ts +14 -0
- package/dist/cli/config-selector.d.ts.map +1 -0
- package/dist/cli/config-selector.js +31 -0
- package/dist/cli/config-selector.js.map +1 -0
- package/dist/cli/file-processor.d.ts +15 -0
- package/dist/cli/file-processor.d.ts.map +1 -0
- package/dist/cli/file-processor.js +79 -0
- package/dist/cli/file-processor.js.map +1 -0
- package/dist/cli/list-models.d.ts +9 -0
- package/dist/cli/list-models.d.ts.map +1 -0
- package/dist/cli/list-models.js +92 -0
- package/dist/cli/list-models.js.map +1 -0
- package/dist/cli/session-picker.d.ts +9 -0
- package/dist/cli/session-picker.d.ts.map +1 -0
- package/dist/cli/session-picker.js +34 -0
- package/dist/cli/session-picker.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +11 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +68 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +203 -0
- package/dist/config.js.map +1 -0
- package/dist/core/agent-session.d.ts +571 -0
- package/dist/core/agent-session.d.ts.map +1 -0
- package/dist/core/agent-session.js +2353 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/auth-storage.d.ts +129 -0
- package/dist/core/auth-storage.d.ts.map +1 -0
- package/dist/core/auth-storage.js +394 -0
- package/dist/core/auth-storage.js.map +1 -0
- package/dist/core/bash-executor.d.ts +47 -0
- package/dist/core/bash-executor.d.ts.map +1 -0
- package/dist/core/bash-executor.js +212 -0
- package/dist/core/bash-executor.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts +86 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/core/compaction/branch-summarization.js +242 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +121 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -0
- package/dist/core/compaction/compaction.js +607 -0
- package/dist/core/compaction/compaction.js.map +1 -0
- package/dist/core/compaction/index.d.ts +7 -0
- package/dist/core/compaction/index.d.ts.map +1 -0
- package/dist/core/compaction/index.js +7 -0
- package/dist/core/compaction/index.js.map +1 -0
- package/dist/core/compaction/utils.d.ts +35 -0
- package/dist/core/compaction/utils.d.ts.map +1 -0
- package/dist/core/compaction/utils.js +138 -0
- package/dist/core/compaction/utils.js.map +1 -0
- package/dist/core/defaults.d.ts +3 -0
- package/dist/core/defaults.d.ts.map +1 -0
- package/dist/core/defaults.js +2 -0
- package/dist/core/defaults.js.map +1 -0
- package/dist/core/diagnostics.d.ts +15 -0
- package/dist/core/diagnostics.d.ts.map +1 -0
- package/dist/core/diagnostics.js +2 -0
- package/dist/core/diagnostics.js.map +1 -0
- package/dist/core/event-bus.d.ts +9 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/event-bus.js +25 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/exec.d.ts +29 -0
- package/dist/core/exec.d.ts.map +1 -0
- package/dist/core/exec.js +71 -0
- package/dist/core/exec.js.map +1 -0
- package/dist/core/export-html/ansi-to-html.d.ts +22 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
- package/dist/core/export-html/ansi-to-html.js +249 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -0
- package/dist/core/export-html/index.d.ts +34 -0
- package/dist/core/export-html/index.d.ts.map +1 -0
- package/dist/core/export-html/index.js +222 -0
- package/dist/core/export-html/index.js.map +1 -0
- package/dist/core/export-html/template.css +971 -0
- package/dist/core/export-html/template.html +54 -0
- package/dist/core/export-html/template.js +1586 -0
- package/dist/core/export-html/tool-renderer.d.ts +35 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
- package/dist/core/export-html/tool-renderer.js +57 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -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 +11 -0
- package/dist/core/extensions/index.d.ts.map +1 -0
- package/dist/core/extensions/index.js +9 -0
- package/dist/core/extensions/index.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +25 -0
- package/dist/core/extensions/loader.d.ts.map +1 -0
- package/dist/core/extensions/loader.js +402 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/runner.d.ts +146 -0
- package/dist/core/extensions/runner.d.ts.map +1 -0
- package/dist/core/extensions/runner.js +626 -0
- package/dist/core/extensions/runner.js.map +1 -0
- package/dist/core/extensions/types.d.ts +984 -0
- package/dist/core/extensions/types.d.ts.map +1 -0
- package/dist/core/extensions/types.js +35 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/extensions/wrapper.d.ts +27 -0
- package/dist/core/extensions/wrapper.d.ts.map +1 -0
- package/dist/core/extensions/wrapper.js +102 -0
- package/dist/core/extensions/wrapper.js.map +1 -0
- package/dist/core/footer-data-provider.d.ts +32 -0
- package/dist/core/footer-data-provider.d.ts.map +1 -0
- package/dist/core/footer-data-provider.js +134 -0
- package/dist/core/footer-data-provider.js.map +1 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/keybindings.d.ts +55 -0
- package/dist/core/keybindings.d.ts.map +1 -0
- package/dist/core/keybindings.js +153 -0
- package/dist/core/keybindings.js.map +1 -0
- package/dist/core/memory.d.ts +64 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +247 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/messages.d.ts +77 -0
- package/dist/core/messages.d.ts.map +1 -0
- package/dist/core/messages.js +149 -0
- package/dist/core/messages.js.map +1 -0
- package/dist/core/model-registry.d.ts +102 -0
- package/dist/core/model-registry.d.ts.map +1 -0
- package/dist/core/model-registry.js +515 -0
- package/dist/core/model-registry.js.map +1 -0
- package/dist/core/model-resolver.d.ts +104 -0
- package/dist/core/model-resolver.d.ts.map +1 -0
- package/dist/core/model-resolver.js +403 -0
- package/dist/core/model-resolver.js.map +1 -0
- package/dist/core/package-manager.d.ts +151 -0
- package/dist/core/package-manager.d.ts.map +1 -0
- package/dist/core/package-manager.js +1426 -0
- package/dist/core/package-manager.js.map +1 -0
- package/dist/core/prompt-templates.d.ts +50 -0
- package/dist/core/prompt-templates.d.ts.map +1 -0
- package/dist/core/prompt-templates.js +251 -0
- package/dist/core/prompt-templates.js.map +1 -0
- package/dist/core/resolve-config-value.d.ts +17 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -0
- package/dist/core/resolve-config-value.js +59 -0
- package/dist/core/resolve-config-value.js.map +1 -0
- package/dist/core/resource-loader.d.ts +184 -0
- package/dist/core/resource-loader.d.ts.map +1 -0
- package/dist/core/resource-loader.js +673 -0
- package/dist/core/resource-loader.js.map +1 -0
- package/dist/core/sdk.d.ts +90 -0
- package/dist/core/sdk.d.ts.map +1 -0
- package/dist/core/sdk.js +238 -0
- package/dist/core/sdk.js.map +1 -0
- package/dist/core/session-manager.d.ts +323 -0
- package/dist/core/session-manager.d.ts.map +1 -0
- package/dist/core/session-manager.js +1091 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/settings-manager.d.ts +230 -0
- package/dist/core/settings-manager.d.ts.map +1 -0
- package/dist/core/settings-manager.js +656 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/skills.d.ts +58 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +364 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +15 -0
- package/dist/core/slash-commands.d.ts.map +1 -0
- package/dist/core/slash-commands.js +23 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/system-prompt.d.ts +26 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +150 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/timings.d.ts +7 -0
- package/dist/core/timings.d.ts.map +1 -0
- package/dist/core/timings.js +25 -0
- package/dist/core/timings.js.map +1 -0
- package/dist/core/tools/bash.d.ts +55 -0
- package/dist/core/tools/bash.d.ts.map +1 -0
- package/dist/core/tools/bash.js +242 -0
- package/dist/core/tools/bash.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +63 -0
- package/dist/core/tools/edit-diff.d.ts.map +1 -0
- package/dist/core/tools/edit-diff.js +243 -0
- package/dist/core/tools/edit-diff.js.map +1 -0
- package/dist/core/tools/edit.d.ts +39 -0
- package/dist/core/tools/edit.d.ts.map +1 -0
- package/dist/core/tools/edit.js +146 -0
- package/dist/core/tools/edit.js.map +1 -0
- package/dist/core/tools/find.d.ts +39 -0
- package/dist/core/tools/find.d.ts.map +1 -0
- package/dist/core/tools/find.js +206 -0
- package/dist/core/tools/find.js.map +1 -0
- package/dist/core/tools/grep.d.ts +45 -0
- package/dist/core/tools/grep.d.ts.map +1 -0
- package/dist/core/tools/grep.js +239 -0
- package/dist/core/tools/grep.js.map +1 -0
- package/dist/core/tools/index.d.ts +102 -0
- package/dist/core/tools/index.d.ts.map +1 -0
- package/dist/core/tools/index.js +71 -0
- package/dist/core/tools/index.js.map +1 -0
- package/dist/core/tools/ls.d.ts +40 -0
- package/dist/core/tools/ls.d.ts.map +1 -0
- package/dist/core/tools/ls.js +118 -0
- package/dist/core/tools/ls.js.map +1 -0
- package/dist/core/tools/memory.d.ts +45 -0
- package/dist/core/tools/memory.d.ts.map +1 -0
- package/dist/core/tools/memory.js +346 -0
- package/dist/core/tools/memory.js.map +1 -0
- package/dist/core/tools/path-utils.d.ts +8 -0
- package/dist/core/tools/path-utils.d.ts.map +1 -0
- package/dist/core/tools/path-utils.js +81 -0
- package/dist/core/tools/path-utils.js.map +1 -0
- package/dist/core/tools/read.d.ts +39 -0
- package/dist/core/tools/read.d.ts.map +1 -0
- package/dist/core/tools/read.js +166 -0
- package/dist/core/tools/read.js.map +1 -0
- package/dist/core/tools/truncate.d.ts +70 -0
- package/dist/core/tools/truncate.d.ts.map +1 -0
- package/dist/core/tools/truncate.js +205 -0
- package/dist/core/tools/truncate.js.map +1 -0
- package/dist/core/tools/write.d.ts +29 -0
- package/dist/core/tools/write.d.ts.map +1 -0
- package/dist/core/tools/write.js +78 -0
- package/dist/core/tools/write.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +651 -0
- package/dist/main.js.map +1 -0
- package/dist/migrations.d.ts +33 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +261 -0
- package/dist/migrations.js.map +1 -0
- package/dist/modes/index.d.ts +9 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +8 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/interactive/components/armin.d.ts +34 -0
- package/dist/modes/interactive/components/armin.d.ts.map +1 -0
- package/dist/modes/interactive/components/armin.js +333 -0
- package/dist/modes/interactive/components/armin.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +16 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/assistant-message.js +96 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +35 -0
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/bash-execution.js +162 -0
- package/dist/modes/interactive/components/bash-execution.js.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
- package/dist/modes/interactive/components/bordered-loader.js +51 -0
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/branch-summary-message.js +44 -0
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/compaction-summary-message.js +45 -0
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/config-selector.d.ts +71 -0
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/config-selector.js +479 -0
- package/dist/modes/interactive/components/config-selector.js.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
- package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
- package/dist/modes/interactive/components/countdown-timer.js +33 -0
- package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
- package/dist/modes/interactive/components/custom-editor.d.ts +21 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-editor.js +70 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -0
- package/dist/modes/interactive/components/custom-message.d.ts +20 -0
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/custom-message.js +79 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -0
- package/dist/modes/interactive/components/daxnuts.d.ts +23 -0
- package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
- package/dist/modes/interactive/components/daxnuts.js +140 -0
- package/dist/modes/interactive/components/daxnuts.js.map +1 -0
- package/dist/modes/interactive/components/diff.d.ts +12 -0
- package/dist/modes/interactive/components/diff.d.ts.map +1 -0
- package/dist/modes/interactive/components/diff.js +133 -0
- package/dist/modes/interactive/components/diff.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.js +21 -0
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +17 -0
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-editor.js +102 -0
- package/dist/modes/interactive/components/extension-editor.js.map +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts +23 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-input.js +61 -0
- package/dist/modes/interactive/components/extension-input.js.map +1 -0
- package/dist/modes/interactive/components/extension-selector.d.ts +24 -0
- package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/extension-selector.js +78 -0
- package/dist/modes/interactive/components/extension-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts +26 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -0
- package/dist/modes/interactive/components/footer.js +213 -0
- package/dist/modes/interactive/components/footer.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +32 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -0
- package/dist/modes/interactive/components/index.js +33 -0
- package/dist/modes/interactive/components/index.js.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts +41 -0
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
- package/dist/modes/interactive/components/keybinding-hints.js +61 -0
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
- package/dist/modes/interactive/components/login-dialog.d.ts +42 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
- package/dist/modes/interactive/components/login-dialog.js +145 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -0
- package/dist/modes/interactive/components/model-selector.d.ts +47 -0
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/model-selector.js +271 -0
- package/dist/modes/interactive/components/model-selector.js.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/oauth-selector.js +97 -0
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.js +275 -0
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +23 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.js +155 -0
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +95 -0
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector.js +851 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +58 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-selector.js +299 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/show-images-selector.js +35 -0
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
- package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/theme-selector.js +46 -0
- package/dist/modes/interactive/components/theme-selector.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.js +47 -0
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +70 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +636 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/components/tree-selector.d.ts +68 -0
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/tree-selector.js +934 -0
- package/dist/modes/interactive/components/tree-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message-selector.js +113 -0
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +8 -0
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/user-message.js +16 -0
- package/dist/modes/interactive/components/user-message.js.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
- package/dist/modes/interactive/components/visual-truncate.js +33 -0
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +316 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-mode.js +3848 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -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 +78 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme.js +944 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -0
- package/dist/modes/print-mode.d.ts +28 -0
- package/dist/modes/print-mode.d.ts.map +1 -0
- package/dist/modes/print-mode.js +101 -0
- package/dist/modes/print-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +217 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-client.js +405 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -0
- package/dist/modes/rpc/rpc-mode.d.ts +20 -0
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-mode.js +511 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -0
- package/dist/modes/rpc/rpc-types.d.ts +409 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-types.js +8 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -0
- package/dist/utils/changelog.d.ts +21 -0
- package/dist/utils/changelog.d.ts.map +1 -0
- package/dist/utils/changelog.js +87 -0
- package/dist/utils/changelog.js.map +1 -0
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +162 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/dist/utils/clipboard-native.d.ts +7 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -0
- package/dist/utils/clipboard-native.js +14 -0
- package/dist/utils/clipboard-native.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +67 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +8 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +26 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/git.d.ts +26 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +163 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/image-convert.d.ts +9 -0
- package/dist/utils/image-convert.d.ts.map +1 -0
- package/dist/utils/image-convert.js +35 -0
- package/dist/utils/image-convert.js.map +1 -0
- package/dist/utils/image-resize.d.ts +36 -0
- package/dist/utils/image-resize.d.ts.map +1 -0
- package/dist/utils/image-resize.js +181 -0
- package/dist/utils/image-resize.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +26 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/photon.d.ts +21 -0
- package/dist/utils/photon.d.ts.map +1 -0
- package/dist/utils/photon.js +121 -0
- package/dist/utils/photon.js.map +1 -0
- package/dist/utils/shell.d.ts +26 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +186 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/sleep.d.ts +5 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +17 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/tools-manager.d.ts +3 -0
- package/dist/utils/tools-manager.d.ts.map +1 -0
- package/dist/utils/tools-manager.js +207 -0
- package/dist/utils/tools-manager.js.map +1 -0
- package/docs/compaction.md +390 -0
- package/docs/custom-provider.md +548 -0
- package/docs/development.md +69 -0
- package/docs/extensions.md +1935 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/json.md +79 -0
- package/docs/keybindings.md +174 -0
- package/docs/models.md +293 -0
- package/docs/packages.md +209 -0
- package/docs/prompt-templates.md +67 -0
- package/docs/providers.md +186 -0
- package/docs/rpc.md +1317 -0
- package/docs/sdk.md +968 -0
- package/docs/session.md +412 -0
- package/docs/settings.md +223 -0
- package/docs/shell-aliases.md +13 -0
- package/docs/skills.md +231 -0
- package/docs/terminal-setup.md +70 -0
- package/docs/termux.md +127 -0
- package/docs/themes.md +295 -0
- package/docs/tree.md +219 -0
- package/docs/tui.md +887 -0
- package/docs/windows.md +17 -0
- package/examples/README.md +25 -0
- package/examples/extensions/README.md +203 -0
- package/examples/extensions/antigravity-image-gen.ts +413 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +114 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/custom-provider-qwen-cli/index.ts +345 -0
- package/examples/extensions/custom-provider-qwen-cli/package.json +16 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +79 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/handoff.ts +150 -0
- package/examples/extensions/hello.ts +25 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +426 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +55 -0
- package/examples/extensions/overlay-qa-tests.ts +881 -0
- package/examples/extensions/overlay-test.ts +150 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +65 -0
- package/examples/extensions/plan-mode/index.ts +340 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +398 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/qna.ts +119 -0
- package/examples/extensions/question.ts +264 -0
- package/examples/extensions/questionnaire.ts +427 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +124 -0
- package/examples/extensions/sandbox/index.ts +318 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +40 -0
- package/examples/extensions/subagent/README.md +172 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +127 -0
- package/examples/extensions/subagent/index.ts +964 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +195 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +299 -0
- package/examples/extensions/tool-override.ts +143 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +40 -0
- package/examples/extensions/truncated-tool.ts +192 -0
- package/examples/extensions/widget-placement.ts +17 -0
- package/examples/extensions/with-deps/index.ts +36 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/rpc-extension-ui.ts +632 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +55 -0
- package/examples/sdk/04-skills.ts +46 -0
- package/examples/sdk/05-tools.ts +56 -0
- package/examples/sdk/06-extensions.ts +88 -0
- package/examples/sdk/07-context-files.ts +40 -0
- package/examples/sdk/08-prompt-templates.ts +47 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
- package/examples/sdk/10-settings.ts +51 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +82 -0
- package/examples/sdk/README.md +144 -0
- package/package.json +96 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import { type Static } from "@sinclair/typebox";
|
|
3
|
+
import { type TruncationResult } from "./truncate.js";
|
|
4
|
+
declare const grepSchema: import("@sinclair/typebox").TObject<{
|
|
5
|
+
pattern: import("@sinclair/typebox").TString;
|
|
6
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
|
+
glob: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
8
|
+
ignoreCase: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
9
|
+
literal: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
10
|
+
context: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
11
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
12
|
+
}>;
|
|
13
|
+
export type GrepToolInput = Static<typeof grepSchema>;
|
|
14
|
+
export interface GrepToolDetails {
|
|
15
|
+
truncation?: TruncationResult;
|
|
16
|
+
matchLimitReached?: number;
|
|
17
|
+
linesTruncated?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Pluggable operations for the grep tool.
|
|
21
|
+
* Override these to delegate search to remote systems (e.g., SSH).
|
|
22
|
+
*/
|
|
23
|
+
export interface GrepOperations {
|
|
24
|
+
/** Check if path is a directory. Throws if path doesn't exist. */
|
|
25
|
+
isDirectory: (absolutePath: string) => Promise<boolean> | boolean;
|
|
26
|
+
/** Read file contents for context lines */
|
|
27
|
+
readFile: (absolutePath: string) => Promise<string> | string;
|
|
28
|
+
}
|
|
29
|
+
export interface GrepToolOptions {
|
|
30
|
+
/** Custom operations for grep. Default: local filesystem + ripgrep */
|
|
31
|
+
operations?: GrepOperations;
|
|
32
|
+
}
|
|
33
|
+
export declare function createGrepTool(cwd: string, options?: GrepToolOptions): AgentTool<typeof grepSchema>;
|
|
34
|
+
/** Default grep tool using process.cwd() - for backwards compatibility */
|
|
35
|
+
export declare const grepTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
36
|
+
pattern: import("@sinclair/typebox").TString;
|
|
37
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
38
|
+
glob: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
39
|
+
ignoreCase: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
40
|
+
literal: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
41
|
+
context: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
42
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
43
|
+
}>, any>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=grep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AAMtD,OAAO,EAIN,KAAK,gBAAgB,EAGrB,MAAM,eAAe,CAAC;AAEvB,QAAA,MAAM,UAAU;;;;;;;;EAYd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAItD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,kEAAkE;IAClE,WAAW,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAClE,2CAA2C;IAC3C,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC7D;AAOD,MAAM,WAAW,eAAe;IAC/B,sEAAsE;IACtE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAwRnG;AAED,0EAA0E;AAC1E,eAAO,MAAM,QAAQ;;;;;;;;QAAgC,CAAC","sourcesContent":["import { createInterface } from \"node:readline\";\r\nimport type { AgentTool } from \"@mariozechner/pi-agent-core\";\r\nimport { type Static, Type } from \"@sinclair/typebox\";\r\nimport { spawn } from \"child_process\";\r\nimport { readFileSync, statSync } from \"fs\";\r\nimport path from \"path\";\r\nimport { ensureTool } from \"../../utils/tools-manager.js\";\r\nimport { resolveToCwd } from \"./path-utils.js\";\r\nimport {\r\n\tDEFAULT_MAX_BYTES,\r\n\tformatSize,\r\n\tGREP_MAX_LINE_LENGTH,\r\n\ttype TruncationResult,\r\n\ttruncateHead,\r\n\ttruncateLine,\r\n} from \"./truncate.js\";\r\n\r\nconst grepSchema = Type.Object({\r\n\tpattern: Type.String({ description: \"Search pattern (regex or literal string)\" }),\r\n\tpath: Type.Optional(Type.String({ description: \"Directory or file to search (default: current directory)\" })),\r\n\tglob: Type.Optional(Type.String({ description: \"Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'\" })),\r\n\tignoreCase: Type.Optional(Type.Boolean({ description: \"Case-insensitive search (default: false)\" })),\r\n\tliteral: Type.Optional(\r\n\t\tType.Boolean({ description: \"Treat pattern as literal string instead of regex (default: false)\" }),\r\n\t),\r\n\tcontext: Type.Optional(\r\n\t\tType.Number({ description: \"Number of lines to show before and after each match (default: 0)\" }),\r\n\t),\r\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of matches to return (default: 100)\" })),\r\n});\r\n\r\nexport type GrepToolInput = Static<typeof grepSchema>;\r\n\r\nconst DEFAULT_LIMIT = 100;\r\n\r\nexport interface GrepToolDetails {\r\n\ttruncation?: TruncationResult;\r\n\tmatchLimitReached?: number;\r\n\tlinesTruncated?: boolean;\r\n}\r\n\r\n/**\r\n * Pluggable operations for the grep tool.\r\n * Override these to delegate search to remote systems (e.g., SSH).\r\n */\r\nexport interface GrepOperations {\r\n\t/** Check if path is a directory. Throws if path doesn't exist. */\r\n\tisDirectory: (absolutePath: string) => Promise<boolean> | boolean;\r\n\t/** Read file contents for context lines */\r\n\treadFile: (absolutePath: string) => Promise<string> | string;\r\n}\r\n\r\nconst defaultGrepOperations: GrepOperations = {\r\n\tisDirectory: (p) => statSync(p).isDirectory(),\r\n\treadFile: (p) => readFileSync(p, \"utf-8\"),\r\n};\r\n\r\nexport interface GrepToolOptions {\r\n\t/** Custom operations for grep. Default: local filesystem + ripgrep */\r\n\toperations?: GrepOperations;\r\n}\r\n\r\nexport function createGrepTool(cwd: string, options?: GrepToolOptions): AgentTool<typeof grepSchema> {\r\n\tconst customOps = options?.operations;\r\n\r\n\treturn {\r\n\t\tname: \"grep\",\r\n\t\tlabel: \"grep\",\r\n\t\tdescription: `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.`,\r\n\t\tparameters: grepSchema,\r\n\t\texecute: async (\r\n\t\t\t_toolCallId: string,\r\n\t\t\t{\r\n\t\t\t\tpattern,\r\n\t\t\t\tpath: searchDir,\r\n\t\t\t\tglob,\r\n\t\t\t\tignoreCase,\r\n\t\t\t\tliteral,\r\n\t\t\t\tcontext,\r\n\t\t\t\tlimit,\r\n\t\t\t}: {\r\n\t\t\t\tpattern: string;\r\n\t\t\t\tpath?: string;\r\n\t\t\t\tglob?: string;\r\n\t\t\t\tignoreCase?: boolean;\r\n\t\t\t\tliteral?: boolean;\r\n\t\t\t\tcontext?: number;\r\n\t\t\t\tlimit?: number;\r\n\t\t\t},\r\n\t\t\tsignal?: AbortSignal,\r\n\t\t) => {\r\n\t\t\treturn new Promise((resolve, reject) => {\r\n\t\t\t\tif (signal?.aborted) {\r\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet settled = false;\r\n\t\t\t\tconst settle = (fn: () => void) => {\r\n\t\t\t\t\tif (!settled) {\r\n\t\t\t\t\t\tsettled = true;\r\n\t\t\t\t\t\tfn();\r\n\t\t\t\t\t}\r\n\t\t\t\t};\r\n\r\n\t\t\t\t(async () => {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\tconst rgPath = await ensureTool(\"rg\", true);\r\n\t\t\t\t\t\tif (!rgPath) {\r\n\t\t\t\t\t\t\tsettle(() => reject(new Error(\"ripgrep (rg) is not available and could not be downloaded\")));\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tconst searchPath = resolveToCwd(searchDir || \".\", cwd);\r\n\t\t\t\t\t\tconst ops = customOps ?? defaultGrepOperations;\r\n\r\n\t\t\t\t\t\tlet isDirectory: boolean;\r\n\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\tisDirectory = await ops.isDirectory(searchPath);\r\n\t\t\t\t\t\t} catch (_err) {\r\n\t\t\t\t\t\t\tsettle(() => reject(new Error(`Path not found: ${searchPath}`)));\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tconst contextValue = context && context > 0 ? context : 0;\r\n\t\t\t\t\t\tconst effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);\r\n\r\n\t\t\t\t\t\tconst formatPath = (filePath: string): string => {\r\n\t\t\t\t\t\t\tif (isDirectory) {\r\n\t\t\t\t\t\t\t\tconst relative = path.relative(searchPath, filePath);\r\n\t\t\t\t\t\t\t\tif (relative && !relative.startsWith(\"..\")) {\r\n\t\t\t\t\t\t\t\t\treturn relative.replace(/\\\\/g, \"/\");\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\treturn path.basename(filePath);\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst fileCache = new Map<string, string[]>();\r\n\t\t\t\t\t\tconst getFileLines = async (filePath: string): Promise<string[]> => {\r\n\t\t\t\t\t\t\tlet lines = fileCache.get(filePath);\r\n\t\t\t\t\t\t\tif (!lines) {\r\n\t\t\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\t\t\tconst content = await ops.readFile(filePath);\r\n\t\t\t\t\t\t\t\t\tlines = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\").split(\"\\n\");\r\n\t\t\t\t\t\t\t\t} catch {\r\n\t\t\t\t\t\t\t\t\tlines = [];\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\tfileCache.set(filePath, lines);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\treturn lines;\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst args: string[] = [\"--json\", \"--line-number\", \"--color=never\", \"--hidden\"];\r\n\r\n\t\t\t\t\t\tif (ignoreCase) {\r\n\t\t\t\t\t\t\targs.push(\"--ignore-case\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (literal) {\r\n\t\t\t\t\t\t\targs.push(\"--fixed-strings\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (glob) {\r\n\t\t\t\t\t\t\targs.push(\"--glob\", glob);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\targs.push(pattern, searchPath);\r\n\r\n\t\t\t\t\t\tconst child = spawn(rgPath, args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] });\r\n\t\t\t\t\t\tconst rl = createInterface({ input: child.stdout });\r\n\t\t\t\t\t\tlet stderr = \"\";\r\n\t\t\t\t\t\tlet matchCount = 0;\r\n\t\t\t\t\t\tlet matchLimitReached = false;\r\n\t\t\t\t\t\tlet linesTruncated = false;\r\n\t\t\t\t\t\tlet aborted = false;\r\n\t\t\t\t\t\tlet killedDueToLimit = false;\r\n\t\t\t\t\t\tconst outputLines: string[] = [];\r\n\r\n\t\t\t\t\t\tconst cleanup = () => {\r\n\t\t\t\t\t\t\trl.close();\r\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst stopChild = (dueToLimit: boolean = false) => {\r\n\t\t\t\t\t\t\tif (!child.killed) {\r\n\t\t\t\t\t\t\t\tkilledDueToLimit = dueToLimit;\r\n\t\t\t\t\t\t\t\tchild.kill();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst onAbort = () => {\r\n\t\t\t\t\t\t\taborted = true;\r\n\t\t\t\t\t\t\tstopChild();\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\r\n\r\n\t\t\t\t\t\tchild.stderr?.on(\"data\", (chunk) => {\r\n\t\t\t\t\t\t\tstderr += chunk.toString();\r\n\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\tconst formatBlock = async (filePath: string, lineNumber: number): Promise<string[]> => {\r\n\t\t\t\t\t\t\tconst relativePath = formatPath(filePath);\r\n\t\t\t\t\t\t\tconst lines = await getFileLines(filePath);\r\n\t\t\t\t\t\t\tif (!lines.length) {\r\n\t\t\t\t\t\t\t\treturn [`${relativePath}:${lineNumber}: (unable to read file)`];\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tconst block: string[] = [];\r\n\t\t\t\t\t\t\tconst start = contextValue > 0 ? Math.max(1, lineNumber - contextValue) : lineNumber;\r\n\t\t\t\t\t\t\tconst end = contextValue > 0 ? Math.min(lines.length, lineNumber + contextValue) : lineNumber;\r\n\r\n\t\t\t\t\t\t\tfor (let current = start; current <= end; current++) {\r\n\t\t\t\t\t\t\t\tconst lineText = lines[current - 1] ?? \"\";\r\n\t\t\t\t\t\t\t\tconst sanitized = lineText.replace(/\\r/g, \"\");\r\n\t\t\t\t\t\t\t\tconst isMatchLine = current === lineNumber;\r\n\r\n\t\t\t\t\t\t\t\t// Truncate long lines\r\n\t\t\t\t\t\t\t\tconst { text: truncatedText, wasTruncated } = truncateLine(sanitized);\r\n\t\t\t\t\t\t\t\tif (wasTruncated) {\r\n\t\t\t\t\t\t\t\t\tlinesTruncated = true;\r\n\t\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t\tif (isMatchLine) {\r\n\t\t\t\t\t\t\t\t\tblock.push(`${relativePath}:${current}: ${truncatedText}`);\r\n\t\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\t\tblock.push(`${relativePath}-${current}- ${truncatedText}`);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\treturn block;\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\t// Collect matches during streaming, format after\r\n\t\t\t\t\t\tconst matches: Array<{ filePath: string; lineNumber: number }> = [];\r\n\r\n\t\t\t\t\t\trl.on(\"line\", (line) => {\r\n\t\t\t\t\t\t\tif (!line.trim() || matchCount >= effectiveLimit) {\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tlet event: any;\r\n\t\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\t\tevent = JSON.parse(line);\r\n\t\t\t\t\t\t\t} catch {\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (event.type === \"match\") {\r\n\t\t\t\t\t\t\t\tmatchCount++;\r\n\t\t\t\t\t\t\t\tconst filePath = event.data?.path?.text;\r\n\t\t\t\t\t\t\t\tconst lineNumber = event.data?.line_number;\r\n\r\n\t\t\t\t\t\t\t\tif (filePath && typeof lineNumber === \"number\") {\r\n\t\t\t\t\t\t\t\t\tmatches.push({ filePath, lineNumber });\r\n\t\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t\tif (matchCount >= effectiveLimit) {\r\n\t\t\t\t\t\t\t\t\tmatchLimitReached = true;\r\n\t\t\t\t\t\t\t\t\tstopChild(true);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\tchild.on(\"error\", (error) => {\r\n\t\t\t\t\t\t\tcleanup();\r\n\t\t\t\t\t\t\tsettle(() => reject(new Error(`Failed to run ripgrep: ${error.message}`)));\r\n\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\tchild.on(\"close\", async (code) => {\r\n\t\t\t\t\t\t\tcleanup();\r\n\r\n\t\t\t\t\t\t\tif (aborted) {\r\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (!killedDueToLimit && code !== 0 && code !== 1) {\r\n\t\t\t\t\t\t\t\tconst errorMsg = stderr.trim() || `ripgrep exited with code ${code}`;\r\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(errorMsg)));\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (matchCount === 0) {\r\n\t\t\t\t\t\t\t\tsettle(() =>\r\n\t\t\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"No matches found\" }], details: undefined }),\r\n\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Format matches (async to support remote file reading)\r\n\t\t\t\t\t\t\tfor (const match of matches) {\r\n\t\t\t\t\t\t\t\tconst block = await formatBlock(match.filePath, match.lineNumber);\r\n\t\t\t\t\t\t\t\toutputLines.push(...block);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Apply byte truncation (no line limit since we already have match limit)\r\n\t\t\t\t\t\t\tconst rawOutput = outputLines.join(\"\\n\");\r\n\t\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\r\n\r\n\t\t\t\t\t\t\tlet output = truncation.content;\r\n\t\t\t\t\t\t\tconst details: GrepToolDetails = {};\r\n\r\n\t\t\t\t\t\t\t// Build notices\r\n\t\t\t\t\t\t\tconst notices: string[] = [];\r\n\r\n\t\t\t\t\t\t\tif (matchLimitReached) {\r\n\t\t\t\t\t\t\t\tnotices.push(\r\n\t\t\t\t\t\t\t\t\t`${effectiveLimit} matches limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`,\r\n\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tdetails.matchLimitReached = effectiveLimit;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (truncation.truncated) {\r\n\t\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\r\n\t\t\t\t\t\t\t\tdetails.truncation = truncation;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (linesTruncated) {\r\n\t\t\t\t\t\t\t\tnotices.push(\r\n\t\t\t\t\t\t\t\t\t`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`,\r\n\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tdetails.linesTruncated = true;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (notices.length > 0) {\r\n\t\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tsettle(() =>\r\n\t\t\t\t\t\t\t\tresolve({\r\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\r\n\t\t\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\r\n\t\t\t\t\t\t\t\t}),\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t} catch (err) {\r\n\t\t\t\t\t\tsettle(() => reject(err as Error));\r\n\t\t\t\t\t}\r\n\t\t\t\t})();\r\n\t\t\t});\r\n\t\t},\r\n\t};\r\n}\r\n\r\n/** Default grep tool using process.cwd() - for backwards compatibility */\r\nexport const grepTool = createGrepTool(process.cwd());\r\n"]}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import { readFileSync, statSync } from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { ensureTool } from "../../utils/tools-manager.js";
|
|
7
|
+
import { resolveToCwd } from "./path-utils.js";
|
|
8
|
+
import { DEFAULT_MAX_BYTES, formatSize, GREP_MAX_LINE_LENGTH, truncateHead, truncateLine, } from "./truncate.js";
|
|
9
|
+
const grepSchema = Type.Object({
|
|
10
|
+
pattern: Type.String({ description: "Search pattern (regex or literal string)" }),
|
|
11
|
+
path: Type.Optional(Type.String({ description: "Directory or file to search (default: current directory)" })),
|
|
12
|
+
glob: Type.Optional(Type.String({ description: "Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'" })),
|
|
13
|
+
ignoreCase: Type.Optional(Type.Boolean({ description: "Case-insensitive search (default: false)" })),
|
|
14
|
+
literal: Type.Optional(Type.Boolean({ description: "Treat pattern as literal string instead of regex (default: false)" })),
|
|
15
|
+
context: Type.Optional(Type.Number({ description: "Number of lines to show before and after each match (default: 0)" })),
|
|
16
|
+
limit: Type.Optional(Type.Number({ description: "Maximum number of matches to return (default: 100)" })),
|
|
17
|
+
});
|
|
18
|
+
const DEFAULT_LIMIT = 100;
|
|
19
|
+
const defaultGrepOperations = {
|
|
20
|
+
isDirectory: (p) => statSync(p).isDirectory(),
|
|
21
|
+
readFile: (p) => readFileSync(p, "utf-8"),
|
|
22
|
+
};
|
|
23
|
+
export function createGrepTool(cwd, options) {
|
|
24
|
+
const customOps = options?.operations;
|
|
25
|
+
return {
|
|
26
|
+
name: "grep",
|
|
27
|
+
label: "grep",
|
|
28
|
+
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.`,
|
|
29
|
+
parameters: grepSchema,
|
|
30
|
+
execute: async (_toolCallId, { pattern, path: searchDir, glob, ignoreCase, literal, context, limit, }, signal) => {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
if (signal?.aborted) {
|
|
33
|
+
reject(new Error("Operation aborted"));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let settled = false;
|
|
37
|
+
const settle = (fn) => {
|
|
38
|
+
if (!settled) {
|
|
39
|
+
settled = true;
|
|
40
|
+
fn();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
(async () => {
|
|
44
|
+
try {
|
|
45
|
+
const rgPath = await ensureTool("rg", true);
|
|
46
|
+
if (!rgPath) {
|
|
47
|
+
settle(() => reject(new Error("ripgrep (rg) is not available and could not be downloaded")));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const searchPath = resolveToCwd(searchDir || ".", cwd);
|
|
51
|
+
const ops = customOps ?? defaultGrepOperations;
|
|
52
|
+
let isDirectory;
|
|
53
|
+
try {
|
|
54
|
+
isDirectory = await ops.isDirectory(searchPath);
|
|
55
|
+
}
|
|
56
|
+
catch (_err) {
|
|
57
|
+
settle(() => reject(new Error(`Path not found: ${searchPath}`)));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const contextValue = context && context > 0 ? context : 0;
|
|
61
|
+
const effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);
|
|
62
|
+
const formatPath = (filePath) => {
|
|
63
|
+
if (isDirectory) {
|
|
64
|
+
const relative = path.relative(searchPath, filePath);
|
|
65
|
+
if (relative && !relative.startsWith("..")) {
|
|
66
|
+
return relative.replace(/\\/g, "/");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return path.basename(filePath);
|
|
70
|
+
};
|
|
71
|
+
const fileCache = new Map();
|
|
72
|
+
const getFileLines = async (filePath) => {
|
|
73
|
+
let lines = fileCache.get(filePath);
|
|
74
|
+
if (!lines) {
|
|
75
|
+
try {
|
|
76
|
+
const content = await ops.readFile(filePath);
|
|
77
|
+
lines = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
lines = [];
|
|
81
|
+
}
|
|
82
|
+
fileCache.set(filePath, lines);
|
|
83
|
+
}
|
|
84
|
+
return lines;
|
|
85
|
+
};
|
|
86
|
+
const args = ["--json", "--line-number", "--color=never", "--hidden"];
|
|
87
|
+
if (ignoreCase) {
|
|
88
|
+
args.push("--ignore-case");
|
|
89
|
+
}
|
|
90
|
+
if (literal) {
|
|
91
|
+
args.push("--fixed-strings");
|
|
92
|
+
}
|
|
93
|
+
if (glob) {
|
|
94
|
+
args.push("--glob", glob);
|
|
95
|
+
}
|
|
96
|
+
args.push(pattern, searchPath);
|
|
97
|
+
const child = spawn(rgPath, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
98
|
+
const rl = createInterface({ input: child.stdout });
|
|
99
|
+
let stderr = "";
|
|
100
|
+
let matchCount = 0;
|
|
101
|
+
let matchLimitReached = false;
|
|
102
|
+
let linesTruncated = false;
|
|
103
|
+
let aborted = false;
|
|
104
|
+
let killedDueToLimit = false;
|
|
105
|
+
const outputLines = [];
|
|
106
|
+
const cleanup = () => {
|
|
107
|
+
rl.close();
|
|
108
|
+
signal?.removeEventListener("abort", onAbort);
|
|
109
|
+
};
|
|
110
|
+
const stopChild = (dueToLimit = false) => {
|
|
111
|
+
if (!child.killed) {
|
|
112
|
+
killedDueToLimit = dueToLimit;
|
|
113
|
+
child.kill();
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const onAbort = () => {
|
|
117
|
+
aborted = true;
|
|
118
|
+
stopChild();
|
|
119
|
+
};
|
|
120
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
121
|
+
child.stderr?.on("data", (chunk) => {
|
|
122
|
+
stderr += chunk.toString();
|
|
123
|
+
});
|
|
124
|
+
const formatBlock = async (filePath, lineNumber) => {
|
|
125
|
+
const relativePath = formatPath(filePath);
|
|
126
|
+
const lines = await getFileLines(filePath);
|
|
127
|
+
if (!lines.length) {
|
|
128
|
+
return [`${relativePath}:${lineNumber}: (unable to read file)`];
|
|
129
|
+
}
|
|
130
|
+
const block = [];
|
|
131
|
+
const start = contextValue > 0 ? Math.max(1, lineNumber - contextValue) : lineNumber;
|
|
132
|
+
const end = contextValue > 0 ? Math.min(lines.length, lineNumber + contextValue) : lineNumber;
|
|
133
|
+
for (let current = start; current <= end; current++) {
|
|
134
|
+
const lineText = lines[current - 1] ?? "";
|
|
135
|
+
const sanitized = lineText.replace(/\r/g, "");
|
|
136
|
+
const isMatchLine = current === lineNumber;
|
|
137
|
+
// Truncate long lines
|
|
138
|
+
const { text: truncatedText, wasTruncated } = truncateLine(sanitized);
|
|
139
|
+
if (wasTruncated) {
|
|
140
|
+
linesTruncated = true;
|
|
141
|
+
}
|
|
142
|
+
if (isMatchLine) {
|
|
143
|
+
block.push(`${relativePath}:${current}: ${truncatedText}`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
block.push(`${relativePath}-${current}- ${truncatedText}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return block;
|
|
150
|
+
};
|
|
151
|
+
// Collect matches during streaming, format after
|
|
152
|
+
const matches = [];
|
|
153
|
+
rl.on("line", (line) => {
|
|
154
|
+
if (!line.trim() || matchCount >= effectiveLimit) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
let event;
|
|
158
|
+
try {
|
|
159
|
+
event = JSON.parse(line);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (event.type === "match") {
|
|
165
|
+
matchCount++;
|
|
166
|
+
const filePath = event.data?.path?.text;
|
|
167
|
+
const lineNumber = event.data?.line_number;
|
|
168
|
+
if (filePath && typeof lineNumber === "number") {
|
|
169
|
+
matches.push({ filePath, lineNumber });
|
|
170
|
+
}
|
|
171
|
+
if (matchCount >= effectiveLimit) {
|
|
172
|
+
matchLimitReached = true;
|
|
173
|
+
stopChild(true);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
child.on("error", (error) => {
|
|
178
|
+
cleanup();
|
|
179
|
+
settle(() => reject(new Error(`Failed to run ripgrep: ${error.message}`)));
|
|
180
|
+
});
|
|
181
|
+
child.on("close", async (code) => {
|
|
182
|
+
cleanup();
|
|
183
|
+
if (aborted) {
|
|
184
|
+
settle(() => reject(new Error("Operation aborted")));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!killedDueToLimit && code !== 0 && code !== 1) {
|
|
188
|
+
const errorMsg = stderr.trim() || `ripgrep exited with code ${code}`;
|
|
189
|
+
settle(() => reject(new Error(errorMsg)));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (matchCount === 0) {
|
|
193
|
+
settle(() => resolve({ content: [{ type: "text", text: "No matches found" }], details: undefined }));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// Format matches (async to support remote file reading)
|
|
197
|
+
for (const match of matches) {
|
|
198
|
+
const block = await formatBlock(match.filePath, match.lineNumber);
|
|
199
|
+
outputLines.push(...block);
|
|
200
|
+
}
|
|
201
|
+
// Apply byte truncation (no line limit since we already have match limit)
|
|
202
|
+
const rawOutput = outputLines.join("\n");
|
|
203
|
+
const truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });
|
|
204
|
+
let output = truncation.content;
|
|
205
|
+
const details = {};
|
|
206
|
+
// Build notices
|
|
207
|
+
const notices = [];
|
|
208
|
+
if (matchLimitReached) {
|
|
209
|
+
notices.push(`${effectiveLimit} matches limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`);
|
|
210
|
+
details.matchLimitReached = effectiveLimit;
|
|
211
|
+
}
|
|
212
|
+
if (truncation.truncated) {
|
|
213
|
+
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
|
|
214
|
+
details.truncation = truncation;
|
|
215
|
+
}
|
|
216
|
+
if (linesTruncated) {
|
|
217
|
+
notices.push(`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`);
|
|
218
|
+
details.linesTruncated = true;
|
|
219
|
+
}
|
|
220
|
+
if (notices.length > 0) {
|
|
221
|
+
output += `\n\n[${notices.join(". ")}]`;
|
|
222
|
+
}
|
|
223
|
+
settle(() => resolve({
|
|
224
|
+
content: [{ type: "text", text: output }],
|
|
225
|
+
details: Object.keys(details).length > 0 ? details : undefined,
|
|
226
|
+
}));
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
settle(() => reject(err));
|
|
231
|
+
}
|
|
232
|
+
})();
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
/** Default grep tool using process.cwd() - for backwards compatibility */
|
|
238
|
+
export const grepTool = createGrepTool(process.cwd());
|
|
239
|
+
//# sourceMappingURL=grep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,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AC;wBACd,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAY,CAAC,CAAC,CAAC;oBACpC,CAAC;gBAAA,CACD,CAAC,EAAE,CAAC;YAAA,CACL,CAAC,CAAC;QAAA,CACH;KACD,CAAC;AAAA,CACF;AAED,0EAA0E;AAC1E,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC","sourcesContent":["import { createInterface } from \"node:readline\";\r\nimport type { AgentTool } from \"@mariozechner/pi-agent-core\";\r\nimport { type Static, Type } from \"@sinclair/typebox\";\r\nimport { spawn } from \"child_process\";\r\nimport { readFileSync, statSync } from \"fs\";\r\nimport path from \"path\";\r\nimport { ensureTool } from \"../../utils/tools-manager.js\";\r\nimport { resolveToCwd } from \"./path-utils.js\";\r\nimport {\r\n\tDEFAULT_MAX_BYTES,\r\n\tformatSize,\r\n\tGREP_MAX_LINE_LENGTH,\r\n\ttype TruncationResult,\r\n\ttruncateHead,\r\n\ttruncateLine,\r\n} from \"./truncate.js\";\r\n\r\nconst grepSchema = Type.Object({\r\n\tpattern: Type.String({ description: \"Search pattern (regex or literal string)\" }),\r\n\tpath: Type.Optional(Type.String({ description: \"Directory or file to search (default: current directory)\" })),\r\n\tglob: Type.Optional(Type.String({ description: \"Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'\" })),\r\n\tignoreCase: Type.Optional(Type.Boolean({ description: \"Case-insensitive search (default: false)\" })),\r\n\tliteral: Type.Optional(\r\n\t\tType.Boolean({ description: \"Treat pattern as literal string instead of regex (default: false)\" }),\r\n\t),\r\n\tcontext: Type.Optional(\r\n\t\tType.Number({ description: \"Number of lines to show before and after each match (default: 0)\" }),\r\n\t),\r\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of matches to return (default: 100)\" })),\r\n});\r\n\r\nexport type GrepToolInput = Static<typeof grepSchema>;\r\n\r\nconst DEFAULT_LIMIT = 100;\r\n\r\nexport interface GrepToolDetails {\r\n\ttruncation?: TruncationResult;\r\n\tmatchLimitReached?: number;\r\n\tlinesTruncated?: boolean;\r\n}\r\n\r\n/**\r\n * Pluggable operations for the grep tool.\r\n * Override these to delegate search to remote systems (e.g., SSH).\r\n */\r\nexport interface GrepOperations {\r\n\t/** Check if path is a directory. Throws if path doesn't exist. */\r\n\tisDirectory: (absolutePath: string) => Promise<boolean> | boolean;\r\n\t/** Read file contents for context lines */\r\n\treadFile: (absolutePath: string) => Promise<string> | string;\r\n}\r\n\r\nconst defaultGrepOperations: GrepOperations = {\r\n\tisDirectory: (p) => statSync(p).isDirectory(),\r\n\treadFile: (p) => readFileSync(p, \"utf-8\"),\r\n};\r\n\r\nexport interface GrepToolOptions {\r\n\t/** Custom operations for grep. Default: local filesystem + ripgrep */\r\n\toperations?: GrepOperations;\r\n}\r\n\r\nexport function createGrepTool(cwd: string, options?: GrepToolOptions): AgentTool<typeof grepSchema> {\r\n\tconst customOps = options?.operations;\r\n\r\n\treturn {\r\n\t\tname: \"grep\",\r\n\t\tlabel: \"grep\",\r\n\t\tdescription: `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.`,\r\n\t\tparameters: grepSchema,\r\n\t\texecute: async (\r\n\t\t\t_toolCallId: string,\r\n\t\t\t{\r\n\t\t\t\tpattern,\r\n\t\t\t\tpath: searchDir,\r\n\t\t\t\tglob,\r\n\t\t\t\tignoreCase,\r\n\t\t\t\tliteral,\r\n\t\t\t\tcontext,\r\n\t\t\t\tlimit,\r\n\t\t\t}: {\r\n\t\t\t\tpattern: string;\r\n\t\t\t\tpath?: string;\r\n\t\t\t\tglob?: string;\r\n\t\t\t\tignoreCase?: boolean;\r\n\t\t\t\tliteral?: boolean;\r\n\t\t\t\tcontext?: number;\r\n\t\t\t\tlimit?: number;\r\n\t\t\t},\r\n\t\t\tsignal?: AbortSignal,\r\n\t\t) => {\r\n\t\t\treturn new Promise((resolve, reject) => {\r\n\t\t\t\tif (signal?.aborted) {\r\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet settled = false;\r\n\t\t\t\tconst settle = (fn: () => void) => {\r\n\t\t\t\t\tif (!settled) {\r\n\t\t\t\t\t\tsettled = true;\r\n\t\t\t\t\t\tfn();\r\n\t\t\t\t\t}\r\n\t\t\t\t};\r\n\r\n\t\t\t\t(async () => {\r\n\t\t\t\t\ttry {\r\n\t\t\t\t\t\tconst rgPath = await ensureTool(\"rg\", true);\r\n\t\t\t\t\t\tif (!rgPath) {\r\n\t\t\t\t\t\t\tsettle(() => reject(new Error(\"ripgrep (rg) is not available and could not be downloaded\")));\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tconst searchPath = resolveToCwd(searchDir || \".\", cwd);\r\n\t\t\t\t\t\tconst ops = customOps ?? defaultGrepOperations;\r\n\r\n\t\t\t\t\t\tlet isDirectory: boolean;\r\n\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\tisDirectory = await ops.isDirectory(searchPath);\r\n\t\t\t\t\t\t} catch (_err) {\r\n\t\t\t\t\t\t\tsettle(() => reject(new Error(`Path not found: ${searchPath}`)));\r\n\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tconst contextValue = context && context > 0 ? context : 0;\r\n\t\t\t\t\t\tconst effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);\r\n\r\n\t\t\t\t\t\tconst formatPath = (filePath: string): string => {\r\n\t\t\t\t\t\t\tif (isDirectory) {\r\n\t\t\t\t\t\t\t\tconst relative = path.relative(searchPath, filePath);\r\n\t\t\t\t\t\t\t\tif (relative && !relative.startsWith(\"..\")) {\r\n\t\t\t\t\t\t\t\t\treturn relative.replace(/\\\\/g, \"/\");\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\treturn path.basename(filePath);\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst fileCache = new Map<string, string[]>();\r\n\t\t\t\t\t\tconst getFileLines = async (filePath: string): Promise<string[]> => {\r\n\t\t\t\t\t\t\tlet lines = fileCache.get(filePath);\r\n\t\t\t\t\t\t\tif (!lines) {\r\n\t\t\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\t\t\tconst content = await ops.readFile(filePath);\r\n\t\t\t\t\t\t\t\t\tlines = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\").split(\"\\n\");\r\n\t\t\t\t\t\t\t\t} catch {\r\n\t\t\t\t\t\t\t\t\tlines = [];\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\tfileCache.set(filePath, lines);\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\treturn lines;\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst args: string[] = [\"--json\", \"--line-number\", \"--color=never\", \"--hidden\"];\r\n\r\n\t\t\t\t\t\tif (ignoreCase) {\r\n\t\t\t\t\t\t\targs.push(\"--ignore-case\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (literal) {\r\n\t\t\t\t\t\t\targs.push(\"--fixed-strings\");\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (glob) {\r\n\t\t\t\t\t\t\targs.push(\"--glob\", glob);\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\targs.push(pattern, searchPath);\r\n\r\n\t\t\t\t\t\tconst child = spawn(rgPath, args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] });\r\n\t\t\t\t\t\tconst rl = createInterface({ input: child.stdout });\r\n\t\t\t\t\t\tlet stderr = \"\";\r\n\t\t\t\t\t\tlet matchCount = 0;\r\n\t\t\t\t\t\tlet matchLimitReached = false;\r\n\t\t\t\t\t\tlet linesTruncated = false;\r\n\t\t\t\t\t\tlet aborted = false;\r\n\t\t\t\t\t\tlet killedDueToLimit = false;\r\n\t\t\t\t\t\tconst outputLines: string[] = [];\r\n\r\n\t\t\t\t\t\tconst cleanup = () => {\r\n\t\t\t\t\t\t\trl.close();\r\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst stopChild = (dueToLimit: boolean = false) => {\r\n\t\t\t\t\t\t\tif (!child.killed) {\r\n\t\t\t\t\t\t\t\tkilledDueToLimit = dueToLimit;\r\n\t\t\t\t\t\t\t\tchild.kill();\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tconst onAbort = () => {\r\n\t\t\t\t\t\t\taborted = true;\r\n\t\t\t\t\t\t\tstopChild();\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\r\n\r\n\t\t\t\t\t\tchild.stderr?.on(\"data\", (chunk) => {\r\n\t\t\t\t\t\t\tstderr += chunk.toString();\r\n\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\tconst formatBlock = async (filePath: string, lineNumber: number): Promise<string[]> => {\r\n\t\t\t\t\t\t\tconst relativePath = formatPath(filePath);\r\n\t\t\t\t\t\t\tconst lines = await getFileLines(filePath);\r\n\t\t\t\t\t\t\tif (!lines.length) {\r\n\t\t\t\t\t\t\t\treturn [`${relativePath}:${lineNumber}: (unable to read file)`];\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tconst block: string[] = [];\r\n\t\t\t\t\t\t\tconst start = contextValue > 0 ? Math.max(1, lineNumber - contextValue) : lineNumber;\r\n\t\t\t\t\t\t\tconst end = contextValue > 0 ? Math.min(lines.length, lineNumber + contextValue) : lineNumber;\r\n\r\n\t\t\t\t\t\t\tfor (let current = start; current <= end; current++) {\r\n\t\t\t\t\t\t\t\tconst lineText = lines[current - 1] ?? \"\";\r\n\t\t\t\t\t\t\t\tconst sanitized = lineText.replace(/\\r/g, \"\");\r\n\t\t\t\t\t\t\t\tconst isMatchLine = current === lineNumber;\r\n\r\n\t\t\t\t\t\t\t\t// Truncate long lines\r\n\t\t\t\t\t\t\t\tconst { text: truncatedText, wasTruncated } = truncateLine(sanitized);\r\n\t\t\t\t\t\t\t\tif (wasTruncated) {\r\n\t\t\t\t\t\t\t\t\tlinesTruncated = true;\r\n\t\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t\tif (isMatchLine) {\r\n\t\t\t\t\t\t\t\t\tblock.push(`${relativePath}:${current}: ${truncatedText}`);\r\n\t\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\t\tblock.push(`${relativePath}-${current}- ${truncatedText}`);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\treturn block;\r\n\t\t\t\t\t\t};\r\n\r\n\t\t\t\t\t\t// Collect matches during streaming, format after\r\n\t\t\t\t\t\tconst matches: Array<{ filePath: string; lineNumber: number }> = [];\r\n\r\n\t\t\t\t\t\trl.on(\"line\", (line) => {\r\n\t\t\t\t\t\t\tif (!line.trim() || matchCount >= effectiveLimit) {\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tlet event: any;\r\n\t\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\t\tevent = JSON.parse(line);\r\n\t\t\t\t\t\t\t} catch {\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (event.type === \"match\") {\r\n\t\t\t\t\t\t\t\tmatchCount++;\r\n\t\t\t\t\t\t\t\tconst filePath = event.data?.path?.text;\r\n\t\t\t\t\t\t\t\tconst lineNumber = event.data?.line_number;\r\n\r\n\t\t\t\t\t\t\t\tif (filePath && typeof lineNumber === \"number\") {\r\n\t\t\t\t\t\t\t\t\tmatches.push({ filePath, lineNumber });\r\n\t\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t\tif (matchCount >= effectiveLimit) {\r\n\t\t\t\t\t\t\t\t\tmatchLimitReached = true;\r\n\t\t\t\t\t\t\t\t\tstopChild(true);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\tchild.on(\"error\", (error) => {\r\n\t\t\t\t\t\t\tcleanup();\r\n\t\t\t\t\t\t\tsettle(() => reject(new Error(`Failed to run ripgrep: ${error.message}`)));\r\n\t\t\t\t\t\t});\r\n\r\n\t\t\t\t\t\tchild.on(\"close\", async (code) => {\r\n\t\t\t\t\t\t\tcleanup();\r\n\r\n\t\t\t\t\t\t\tif (aborted) {\r\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (!killedDueToLimit && code !== 0 && code !== 1) {\r\n\t\t\t\t\t\t\t\tconst errorMsg = stderr.trim() || `ripgrep exited with code ${code}`;\r\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(errorMsg)));\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (matchCount === 0) {\r\n\t\t\t\t\t\t\t\tsettle(() =>\r\n\t\t\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"No matches found\" }], details: undefined }),\r\n\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\treturn;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Format matches (async to support remote file reading)\r\n\t\t\t\t\t\t\tfor (const match of matches) {\r\n\t\t\t\t\t\t\t\tconst block = await formatBlock(match.filePath, match.lineNumber);\r\n\t\t\t\t\t\t\t\toutputLines.push(...block);\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\t// Apply byte truncation (no line limit since we already have match limit)\r\n\t\t\t\t\t\t\tconst rawOutput = outputLines.join(\"\\n\");\r\n\t\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\r\n\r\n\t\t\t\t\t\t\tlet output = truncation.content;\r\n\t\t\t\t\t\t\tconst details: GrepToolDetails = {};\r\n\r\n\t\t\t\t\t\t\t// Build notices\r\n\t\t\t\t\t\t\tconst notices: string[] = [];\r\n\r\n\t\t\t\t\t\t\tif (matchLimitReached) {\r\n\t\t\t\t\t\t\t\tnotices.push(\r\n\t\t\t\t\t\t\t\t\t`${effectiveLimit} matches limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`,\r\n\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tdetails.matchLimitReached = effectiveLimit;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (truncation.truncated) {\r\n\t\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\r\n\t\t\t\t\t\t\t\tdetails.truncation = truncation;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (linesTruncated) {\r\n\t\t\t\t\t\t\t\tnotices.push(\r\n\t\t\t\t\t\t\t\t\t`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`,\r\n\t\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t\t\tdetails.linesTruncated = true;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tif (notices.length > 0) {\r\n\t\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\r\n\t\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\t\tsettle(() =>\r\n\t\t\t\t\t\t\t\tresolve({\r\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\r\n\t\t\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\r\n\t\t\t\t\t\t\t\t}),\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t} catch (err) {\r\n\t\t\t\t\t\tsettle(() => reject(err as Error));\r\n\t\t\t\t\t}\r\n\t\t\t\t})();\r\n\t\t\t});\r\n\t\t},\r\n\t};\r\n}\r\n\r\n/** Default grep tool using process.cwd() - for backwards compatibility */\r\nexport const grepTool = createGrepTool(process.cwd());\r\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export { type BashOperations, type BashSpawnContext, type BashSpawnHook, type BashToolDetails, type BashToolInput, type BashToolOptions, bashTool, createBashTool, } from "./bash.js";
|
|
2
|
+
export { createEditTool, type EditOperations, type EditToolDetails, type EditToolInput, type EditToolOptions, editTool, } from "./edit.js";
|
|
3
|
+
export { createFindTool, type FindOperations, type FindToolDetails, type FindToolInput, type FindToolOptions, findTool, } from "./find.js";
|
|
4
|
+
export { createGrepTool, type GrepOperations, type GrepToolDetails, type GrepToolInput, type GrepToolOptions, grepTool, } from "./grep.js";
|
|
5
|
+
export { createLsTool, type LsOperations, type LsToolDetails, type LsToolInput, type LsToolOptions, lsTool, } from "./ls.js";
|
|
6
|
+
export { type MemoryToolContext, memoryDeleteTool, memoryReadTool, memoryTools, memoryUpdateTool, memoryWriteTool, setMemoryToolContext, } from "./memory.js";
|
|
7
|
+
export { createReadTool, type ReadOperations, type ReadToolDetails, type ReadToolInput, type ReadToolOptions, readTool, } 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, type WriteOperations, type WriteToolInput, type WriteToolOptions, writeTool, } from "./write.js";
|
|
10
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
11
|
+
import { type BashToolOptions } from "./bash.js";
|
|
12
|
+
import { type ReadToolOptions } from "./read.js";
|
|
13
|
+
/** Tool type (AgentTool from pi-ai) */
|
|
14
|
+
export type Tool = AgentTool<any>;
|
|
15
|
+
export declare const codingTools: Tool[];
|
|
16
|
+
export declare const readOnlyTools: Tool[];
|
|
17
|
+
export declare const allTools: {
|
|
18
|
+
read: AgentTool<import("@sinclair/typebox").TObject<{
|
|
19
|
+
path: import("@sinclair/typebox").TString;
|
|
20
|
+
offset: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
21
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
22
|
+
}>, any>;
|
|
23
|
+
bash: AgentTool<import("@sinclair/typebox").TObject<{
|
|
24
|
+
command: import("@sinclair/typebox").TString;
|
|
25
|
+
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
26
|
+
}>, any>;
|
|
27
|
+
edit: AgentTool<import("@sinclair/typebox").TObject<{
|
|
28
|
+
path: import("@sinclair/typebox").TString;
|
|
29
|
+
oldText: import("@sinclair/typebox").TString;
|
|
30
|
+
newText: import("@sinclair/typebox").TString;
|
|
31
|
+
}>, any>;
|
|
32
|
+
write: AgentTool<import("@sinclair/typebox").TObject<{
|
|
33
|
+
path: import("@sinclair/typebox").TString;
|
|
34
|
+
content: import("@sinclair/typebox").TString;
|
|
35
|
+
}>, any>;
|
|
36
|
+
grep: AgentTool<import("@sinclair/typebox").TObject<{
|
|
37
|
+
pattern: import("@sinclair/typebox").TString;
|
|
38
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
39
|
+
glob: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
40
|
+
ignoreCase: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
41
|
+
literal: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
42
|
+
context: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
43
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
44
|
+
}>, any>;
|
|
45
|
+
find: AgentTool<import("@sinclair/typebox").TObject<{
|
|
46
|
+
pattern: import("@sinclair/typebox").TString;
|
|
47
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
48
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
49
|
+
}>, any>;
|
|
50
|
+
ls: AgentTool<import("@sinclair/typebox").TObject<{
|
|
51
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
52
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
53
|
+
}>, any>;
|
|
54
|
+
memory_write: AgentTool<import("@sinclair/typebox").TObject<{
|
|
55
|
+
type: import("@sinclair/typebox").TUnsafe<"episodic" | "procedural" | "semantic">;
|
|
56
|
+
name: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
57
|
+
trigger: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
58
|
+
steps: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
59
|
+
summary: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
60
|
+
details: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
61
|
+
category: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnsafe<"architecture" | "convention" | "fact" | "preference">>;
|
|
62
|
+
text: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
63
|
+
tags: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
64
|
+
reflection_mistakes: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
65
|
+
reflection_lessons: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
66
|
+
}>, any>;
|
|
67
|
+
memory_read: AgentTool<import("@sinclair/typebox").TObject<{
|
|
68
|
+
type: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnsafe<"all" | "episodic" | "procedural" | "semantic">>;
|
|
69
|
+
id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
70
|
+
query: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
71
|
+
}>, any>;
|
|
72
|
+
memory_update: AgentTool<import("@sinclair/typebox").TObject<{
|
|
73
|
+
id: import("@sinclair/typebox").TString;
|
|
74
|
+
text: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
75
|
+
steps: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
76
|
+
trigger: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
77
|
+
tags: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
|
|
78
|
+
}>, any>;
|
|
79
|
+
memory_delete: AgentTool<import("@sinclair/typebox").TObject<{
|
|
80
|
+
id: import("@sinclair/typebox").TString;
|
|
81
|
+
}>, any>;
|
|
82
|
+
};
|
|
83
|
+
export type ToolName = keyof typeof allTools;
|
|
84
|
+
export interface ToolsOptions {
|
|
85
|
+
/** Options for the read tool */
|
|
86
|
+
read?: ReadToolOptions;
|
|
87
|
+
/** Options for the bash tool */
|
|
88
|
+
bash?: BashToolOptions;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create coding tools configured for a specific working directory.
|
|
92
|
+
*/
|
|
93
|
+
export declare function createCodingTools(cwd: string, options?: ToolsOptions): Tool[];
|
|
94
|
+
/**
|
|
95
|
+
* Create read-only tools configured for a specific working directory.
|
|
96
|
+
*/
|
|
97
|
+
export declare function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[];
|
|
98
|
+
/**
|
|
99
|
+
* Create all tools configured for a specific working directory.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool>;
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,EACR,cAAc,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,MAAM,GACN,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KA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G,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAc1F","sourcesContent":["export {\r\n\ttype BashOperations,\r\n\ttype BashSpawnContext,\r\n\ttype BashSpawnHook,\r\n\ttype BashToolDetails,\r\n\ttype BashToolInput,\r\n\ttype BashToolOptions,\r\n\tbashTool,\r\n\tcreateBashTool,\r\n} from \"./bash.js\";\r\nexport {\r\n\tcreateEditTool,\r\n\ttype EditOperations,\r\n\ttype EditToolDetails,\r\n\ttype EditToolInput,\r\n\ttype EditToolOptions,\r\n\teditTool,\r\n} from \"./edit.js\";\r\nexport {\r\n\tcreateFindTool,\r\n\ttype FindOperations,\r\n\ttype FindToolDetails,\r\n\ttype FindToolInput,\r\n\ttype FindToolOptions,\r\n\tfindTool,\r\n} from \"./find.js\";\r\nexport {\r\n\tcreateGrepTool,\r\n\ttype GrepOperations,\r\n\ttype GrepToolDetails,\r\n\ttype GrepToolInput,\r\n\ttype GrepToolOptions,\r\n\tgrepTool,\r\n} from \"./grep.js\";\r\nexport {\r\n\tcreateLsTool,\r\n\ttype LsOperations,\r\n\ttype LsToolDetails,\r\n\ttype LsToolInput,\r\n\ttype LsToolOptions,\r\n\tlsTool,\r\n} from \"./ls.js\";\r\nexport {\r\n\ttype MemoryToolContext,\r\n\tmemoryDeleteTool,\r\n\tmemoryReadTool,\r\n\tmemoryTools,\r\n\tmemoryUpdateTool,\r\n\tmemoryWriteTool,\r\n\tsetMemoryToolContext,\r\n} from \"./memory.js\";\r\nexport {\r\n\tcreateReadTool,\r\n\ttype ReadOperations,\r\n\ttype ReadToolDetails,\r\n\ttype ReadToolInput,\r\n\ttype ReadToolOptions,\r\n\treadTool,\r\n} from \"./read.js\";\r\nexport {\r\n\tDEFAULT_MAX_BYTES,\r\n\tDEFAULT_MAX_LINES,\r\n\tformatSize,\r\n\ttype TruncationOptions,\r\n\ttype TruncationResult,\r\n\ttruncateHead,\r\n\ttruncateLine,\r\n\ttruncateTail,\r\n} from \"./truncate.js\";\r\nexport {\r\n\tcreateWriteTool,\r\n\ttype WriteOperations,\r\n\ttype WriteToolInput,\r\n\ttype WriteToolOptions,\r\n\twriteTool,\r\n} from \"./write.js\";\r\n\r\nimport type { AgentTool } from \"@mariozechner/pi-agent-core\";\r\nimport { type BashToolOptions, bashTool, createBashTool } from \"./bash.js\";\r\nimport { createEditTool, editTool } from \"./edit.js\";\r\nimport { createFindTool, findTool } from \"./find.js\";\r\nimport { createGrepTool, grepTool } from \"./grep.js\";\r\nimport { createLsTool, lsTool } from \"./ls.js\";\r\nimport { memoryDeleteTool, memoryReadTool, memoryUpdateTool, memoryWriteTool } from \"./memory.js\";\r\nimport { createReadTool, type ReadToolOptions, readTool } from \"./read.js\";\r\nimport { createWriteTool, writeTool } from \"./write.js\";\r\n\r\n/** Tool type (AgentTool from pi-ai) */\r\nexport type Tool = AgentTool<any>;\r\n\r\n// Default tools for full access mode (using process.cwd())\r\nexport const codingTools: Tool[] = [readTool, bashTool, editTool, writeTool];\r\n\r\n// Read-only tools for exploration without modification (using process.cwd())\r\nexport const readOnlyTools: Tool[] = [readTool, grepTool, findTool, lsTool];\r\n\r\n// All available tools (using process.cwd())\r\nexport const allTools = {\r\n\tread: readTool,\r\n\tbash: bashTool,\r\n\tedit: editTool,\r\n\twrite: writeTool,\r\n\tgrep: grepTool,\r\n\tfind: findTool,\r\n\tls: lsTool,\r\n\tmemory_write: memoryWriteTool,\r\n\tmemory_read: memoryReadTool,\r\n\tmemory_update: memoryUpdateTool,\r\n\tmemory_delete: memoryDeleteTool,\r\n};\r\n\r\nexport type ToolName = keyof typeof allTools;\r\n\r\nexport interface ToolsOptions {\r\n\t/** Options for the read tool */\r\n\tread?: ReadToolOptions;\r\n\t/** Options for the bash tool */\r\n\tbash?: BashToolOptions;\r\n}\r\n\r\n/**\r\n * Create coding tools configured for a specific working directory.\r\n */\r\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\r\n\treturn [\r\n\t\tcreateReadTool(cwd, options?.read),\r\n\t\tcreateBashTool(cwd, options?.bash),\r\n\t\tcreateEditTool(cwd),\r\n\t\tcreateWriteTool(cwd),\r\n\t];\r\n}\r\n\r\n/**\r\n * Create read-only tools configured for a specific working directory.\r\n */\r\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\r\n\treturn [createReadTool(cwd, options?.read), createGrepTool(cwd), createFindTool(cwd), createLsTool(cwd)];\r\n}\r\n\r\n/**\r\n * Create all tools configured for a specific working directory.\r\n */\r\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\r\n\treturn {\r\n\t\tread: createReadTool(cwd, options?.read),\r\n\t\tbash: createBashTool(cwd, options?.bash),\r\n\t\tedit: createEditTool(cwd),\r\n\t\twrite: createWriteTool(cwd),\r\n\t\tgrep: createGrepTool(cwd),\r\n\t\tfind: createFindTool(cwd),\r\n\t\tls: createLsTool(cwd),\r\n\t\tmemory_write: memoryWriteTool,\r\n\t\tmemory_read: memoryReadTool,\r\n\t\tmemory_update: memoryUpdateTool,\r\n\t\tmemory_delete: memoryDeleteTool,\r\n\t};\r\n}\r\n"]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export { bashTool, createBashTool, } from "./bash.js";
|
|
2
|
+
export { createEditTool, editTool, } from "./edit.js";
|
|
3
|
+
export { createFindTool, findTool, } from "./find.js";
|
|
4
|
+
export { createGrepTool, grepTool, } from "./grep.js";
|
|
5
|
+
export { createLsTool, lsTool, } from "./ls.js";
|
|
6
|
+
export { memoryDeleteTool, memoryReadTool, memoryTools, memoryUpdateTool, memoryWriteTool, setMemoryToolContext, } from "./memory.js";
|
|
7
|
+
export { createReadTool, readTool, } from "./read.js";
|
|
8
|
+
export { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateHead, truncateLine, truncateTail, } from "./truncate.js";
|
|
9
|
+
export { createWriteTool, writeTool, } from "./write.js";
|
|
10
|
+
import { bashTool, createBashTool } from "./bash.js";
|
|
11
|
+
import { createEditTool, editTool } from "./edit.js";
|
|
12
|
+
import { createFindTool, findTool } from "./find.js";
|
|
13
|
+
import { createGrepTool, grepTool } from "./grep.js";
|
|
14
|
+
import { createLsTool, lsTool } from "./ls.js";
|
|
15
|
+
import { memoryDeleteTool, memoryReadTool, memoryUpdateTool, memoryWriteTool } from "./memory.js";
|
|
16
|
+
import { createReadTool, readTool } from "./read.js";
|
|
17
|
+
import { createWriteTool, writeTool } from "./write.js";
|
|
18
|
+
// Default tools for full access mode (using process.cwd())
|
|
19
|
+
export const codingTools = [readTool, bashTool, editTool, writeTool];
|
|
20
|
+
// Read-only tools for exploration without modification (using process.cwd())
|
|
21
|
+
export const readOnlyTools = [readTool, grepTool, findTool, lsTool];
|
|
22
|
+
// All available tools (using process.cwd())
|
|
23
|
+
export const allTools = {
|
|
24
|
+
read: readTool,
|
|
25
|
+
bash: bashTool,
|
|
26
|
+
edit: editTool,
|
|
27
|
+
write: writeTool,
|
|
28
|
+
grep: grepTool,
|
|
29
|
+
find: findTool,
|
|
30
|
+
ls: lsTool,
|
|
31
|
+
memory_write: memoryWriteTool,
|
|
32
|
+
memory_read: memoryReadTool,
|
|
33
|
+
memory_update: memoryUpdateTool,
|
|
34
|
+
memory_delete: memoryDeleteTool,
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Create coding tools configured for a specific working directory.
|
|
38
|
+
*/
|
|
39
|
+
export function createCodingTools(cwd, options) {
|
|
40
|
+
return [
|
|
41
|
+
createReadTool(cwd, options?.read),
|
|
42
|
+
createBashTool(cwd, options?.bash),
|
|
43
|
+
createEditTool(cwd),
|
|
44
|
+
createWriteTool(cwd),
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create read-only tools configured for a specific working directory.
|
|
49
|
+
*/
|
|
50
|
+
export function createReadOnlyTools(cwd, options) {
|
|
51
|
+
return [createReadTool(cwd, options?.read), createGrepTool(cwd), createFindTool(cwd), createLsTool(cwd)];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create all tools configured for a specific working directory.
|
|
55
|
+
*/
|
|
56
|
+
export function createAllTools(cwd, options) {
|
|
57
|
+
return {
|
|
58
|
+
read: createReadTool(cwd, options?.read),
|
|
59
|
+
bash: createBashTool(cwd, options?.bash),
|
|
60
|
+
edit: createEditTool(cwd),
|
|
61
|
+
write: createWriteTool(cwd),
|
|
62
|
+
grep: createGrepTool(cwd),
|
|
63
|
+
find: createFindTool(cwd),
|
|
64
|
+
ls: createLsTool(cwd),
|
|
65
|
+
memory_write: memoryWriteTool,
|
|
66
|
+
memory_read: memoryReadTool,
|
|
67
|
+
memory_update: memoryUpdateTool,
|
|
68
|
+
memory_delete: memoryDeleteTool,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAON,QAAQ,EACR,cAAc,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EAKd,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EAKd,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,cAAc,EAKd,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,YAAY,EAKZ,MAAM,GACN,MAAM,SAAS,CAAC;AACjB,OAAO,EAEN,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,cAAc,EAKd,QAAQ,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EAGV,YAAY,EACZ,YAAY,EACZ,YAAY,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,E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c,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QAClC,cAAc,CAAC,GAAG,CAAC;QACnB,eAAe,CAAC,GAAG,CAAC;KACpB,CAAC;AAAA,CACF;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,OAAsB,EAAU;IAChF,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AAAA,CACzG;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAsB,EAA0B;IAC3F,OAAO;QACN,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;QACxC,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC;QACzB,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC;QAC3B,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC;QACzB,IAAI,EAAE,cAAc,CAAC,GAAG,CAAC;QACzB,EAAE,EAAE,YAAY,CAAC,GAAG,CAAC;QACrB,YAAY,EAAE,eAAe;QAC7B,WAAW,EAAE,cAAc;QAC3B,aAAa,EAAE,gBAAgB;QAC/B,aAAa,EAAE,gBAAgB;KAC/B,CAAC;AAAA,CACF","sourcesContent":["export {\r\n\ttype BashOperations,\r\n\ttype BashSpawnContext,\r\n\ttype BashSpawnHook,\r\n\ttype BashToolDetails,\r\n\ttype BashToolInput,\r\n\ttype BashToolOptions,\r\n\tbashTool,\r\n\tcreateBashTool,\r\n} from \"./bash.js\";\r\nexport {\r\n\tcreateEditTool,\r\n\ttype EditOperations,\r\n\ttype EditToolDetails,\r\n\ttype EditToolInput,\r\n\ttype EditToolOptions,\r\n\teditTool,\r\n} from \"./edit.js\";\r\nexport {\r\n\tcreateFindTool,\r\n\ttype FindOperations,\r\n\ttype FindToolDetails,\r\n\ttype FindToolInput,\r\n\ttype FindToolOptions,\r\n\tfindTool,\r\n} from \"./find.js\";\r\nexport {\r\n\tcreateGrepTool,\r\n\ttype GrepOperations,\r\n\ttype GrepToolDetails,\r\n\ttype GrepToolInput,\r\n\ttype GrepToolOptions,\r\n\tgrepTool,\r\n} from \"./grep.js\";\r\nexport {\r\n\tcreateLsTool,\r\n\ttype LsOperations,\r\n\ttype LsToolDetails,\r\n\ttype LsToolInput,\r\n\ttype LsToolOptions,\r\n\tlsTool,\r\n} from \"./ls.js\";\r\nexport {\r\n\ttype MemoryToolContext,\r\n\tmemoryDeleteTool,\r\n\tmemoryReadTool,\r\n\tmemoryTools,\r\n\tmemoryUpdateTool,\r\n\tmemoryWriteTool,\r\n\tsetMemoryToolContext,\r\n} from \"./memory.js\";\r\nexport {\r\n\tcreateReadTool,\r\n\ttype ReadOperations,\r\n\ttype ReadToolDetails,\r\n\ttype ReadToolInput,\r\n\ttype ReadToolOptions,\r\n\treadTool,\r\n} from \"./read.js\";\r\nexport {\r\n\tDEFAULT_MAX_BYTES,\r\n\tDEFAULT_MAX_LINES,\r\n\tformatSize,\r\n\ttype TruncationOptions,\r\n\ttype TruncationResult,\r\n\ttruncateHead,\r\n\ttruncateLine,\r\n\ttruncateTail,\r\n} from \"./truncate.js\";\r\nexport {\r\n\tcreateWriteTool,\r\n\ttype WriteOperations,\r\n\ttype WriteToolInput,\r\n\ttype WriteToolOptions,\r\n\twriteTool,\r\n} from \"./write.js\";\r\n\r\nimport type { AgentTool } from \"@mariozechner/pi-agent-core\";\r\nimport { type BashToolOptions, bashTool, createBashTool } from \"./bash.js\";\r\nimport { createEditTool, editTool } from \"./edit.js\";\r\nimport { createFindTool, findTool } from \"./find.js\";\r\nimport { createGrepTool, grepTool } from \"./grep.js\";\r\nimport { createLsTool, lsTool } from \"./ls.js\";\r\nimport { memoryDeleteTool, memoryReadTool, memoryUpdateTool, memoryWriteTool } from \"./memory.js\";\r\nimport { createReadTool, type ReadToolOptions, readTool } from \"./read.js\";\r\nimport { createWriteTool, writeTool } from \"./write.js\";\r\n\r\n/** Tool type (AgentTool from pi-ai) */\r\nexport type Tool = AgentTool<any>;\r\n\r\n// Default tools for full access mode (using process.cwd())\r\nexport const codingTools: Tool[] = [readTool, bashTool, editTool, writeTool];\r\n\r\n// Read-only tools for exploration without modification (using process.cwd())\r\nexport const readOnlyTools: Tool[] = [readTool, grepTool, findTool, lsTool];\r\n\r\n// All available tools (using process.cwd())\r\nexport const allTools = {\r\n\tread: readTool,\r\n\tbash: bashTool,\r\n\tedit: editTool,\r\n\twrite: writeTool,\r\n\tgrep: grepTool,\r\n\tfind: findTool,\r\n\tls: lsTool,\r\n\tmemory_write: memoryWriteTool,\r\n\tmemory_read: memoryReadTool,\r\n\tmemory_update: memoryUpdateTool,\r\n\tmemory_delete: memoryDeleteTool,\r\n};\r\n\r\nexport type ToolName = keyof typeof allTools;\r\n\r\nexport interface ToolsOptions {\r\n\t/** Options for the read tool */\r\n\tread?: ReadToolOptions;\r\n\t/** Options for the bash tool */\r\n\tbash?: BashToolOptions;\r\n}\r\n\r\n/**\r\n * Create coding tools configured for a specific working directory.\r\n */\r\nexport function createCodingTools(cwd: string, options?: ToolsOptions): Tool[] {\r\n\treturn [\r\n\t\tcreateReadTool(cwd, options?.read),\r\n\t\tcreateBashTool(cwd, options?.bash),\r\n\t\tcreateEditTool(cwd),\r\n\t\tcreateWriteTool(cwd),\r\n\t];\r\n}\r\n\r\n/**\r\n * Create read-only tools configured for a specific working directory.\r\n */\r\nexport function createReadOnlyTools(cwd: string, options?: ToolsOptions): Tool[] {\r\n\treturn [createReadTool(cwd, options?.read), createGrepTool(cwd), createFindTool(cwd), createLsTool(cwd)];\r\n}\r\n\r\n/**\r\n * Create all tools configured for a specific working directory.\r\n */\r\nexport function createAllTools(cwd: string, options?: ToolsOptions): Record<ToolName, Tool> {\r\n\treturn {\r\n\t\tread: createReadTool(cwd, options?.read),\r\n\t\tbash: createBashTool(cwd, options?.bash),\r\n\t\tedit: createEditTool(cwd),\r\n\t\twrite: createWriteTool(cwd),\r\n\t\tgrep: createGrepTool(cwd),\r\n\t\tfind: createFindTool(cwd),\r\n\t\tls: createLsTool(cwd),\r\n\t\tmemory_write: memoryWriteTool,\r\n\t\tmemory_read: memoryReadTool,\r\n\t\tmemory_update: memoryUpdateTool,\r\n\t\tmemory_delete: memoryDeleteTool,\r\n\t};\r\n}\r\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import { type Static } from "@sinclair/typebox";
|
|
3
|
+
import { type TruncationResult } from "./truncate.js";
|
|
4
|
+
declare const lsSchema: import("@sinclair/typebox").TObject<{
|
|
5
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
6
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
7
|
+
}>;
|
|
8
|
+
export type LsToolInput = Static<typeof lsSchema>;
|
|
9
|
+
export interface LsToolDetails {
|
|
10
|
+
truncation?: TruncationResult;
|
|
11
|
+
entryLimitReached?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Pluggable operations for the ls tool.
|
|
15
|
+
* Override these to delegate directory listing to remote systems (e.g., SSH).
|
|
16
|
+
*/
|
|
17
|
+
export interface LsOperations {
|
|
18
|
+
/** Check if path exists */
|
|
19
|
+
exists: (absolutePath: string) => Promise<boolean> | boolean;
|
|
20
|
+
/** Get file/directory stats. Throws if not found. */
|
|
21
|
+
stat: (absolutePath: string) => Promise<{
|
|
22
|
+
isDirectory: () => boolean;
|
|
23
|
+
}> | {
|
|
24
|
+
isDirectory: () => boolean;
|
|
25
|
+
};
|
|
26
|
+
/** Read directory entries */
|
|
27
|
+
readdir: (absolutePath: string) => Promise<string[]> | string[];
|
|
28
|
+
}
|
|
29
|
+
export interface LsToolOptions {
|
|
30
|
+
/** Custom operations for directory listing. Default: local filesystem */
|
|
31
|
+
operations?: LsOperations;
|
|
32
|
+
}
|
|
33
|
+
export declare function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema>;
|
|
34
|
+
/** Default ls tool using process.cwd() - for backwards compatibility */
|
|
35
|
+
export declare const lsTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
36
|
+
path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
37
|
+
limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
38
|
+
}>, any>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=ls.d.ts.map
|