pi-agent-ide 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/assets/banner.png +0 -0
- package/docs/architecture.md +100 -0
- package/docs/configuration.md +104 -0
- package/docs/development.md +102 -0
- package/docs/evaluation.md +14 -0
- package/docs/extensions.md +298 -0
- package/docs/tools.md +104 -0
- package/node_modules/pi-agent-filesystem/index.ts +60 -0
- package/node_modules/pi-agent-filesystem/package.json +23 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
- package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-image/package.json +20 -0
- package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
- package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
- package/node_modules/pi-agent-filesystem-text/package.json +20 -0
- package/node_modules/pi-agent-ide-ast/index.ts +1 -0
- package/node_modules/pi-agent-ide-ast/package.json +39 -0
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/node_modules/pi-agent-ide-changes/index.ts +68 -0
- package/node_modules/pi-agent-ide-changes/package.json +29 -0
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
- package/node_modules/pi-agent-ide-formatter/package.json +14 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lint/index.ts +237 -0
- package/node_modules/pi-agent-ide-lint/package.json +19 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
- package/node_modules/pi-agent-ide-lsp/package.json +23 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/node_modules/pi-agent-image/package.json +18 -0
- package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
- package/node_modules/pi-agent-image/src/index.ts +6 -0
- package/node_modules/pi-agent-pdf/package.json +16 -0
- package/node_modules/pi-agent-pdf/src/index.ts +5 -0
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
- package/node_modules/pi-agent-read/index.ts +1 -0
- package/node_modules/pi-agent-read/package.json +41 -0
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/node_modules/pi-agent-resource/package.json +17 -0
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
- package/node_modules/pi-agent-resource/src/content.ts +17 -0
- package/node_modules/pi-agent-resource/src/index.ts +65 -0
- package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
- package/node_modules/pi-agent-resource/src/resource.ts +41 -0
- package/node_modules/pi-agent-resource/src/validation.ts +139 -0
- package/node_modules/pi-agent-search/index.ts +1 -0
- package/node_modules/pi-agent-search/package.json +35 -0
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/node_modules/pi-agent-search/src/api/search.ts +91 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
- package/node_modules/pi-agent-search-semantic/index.ts +105 -0
- package/node_modules/pi-agent-search-semantic/package.json +17 -0
- package/node_modules/pi-agent-search-text/index.ts +54 -0
- package/node_modules/pi-agent-search-text/package.json +33 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
- package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
- package/node_modules/pi-agent-search-web/index.ts +74 -0
- package/node_modules/pi-agent-search-web/package.json +19 -0
- package/node_modules/pi-agent-search-web/src/config.ts +499 -0
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
- package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
- package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
- package/node_modules/pi-agent-search-web/src/search.ts +434 -0
- package/node_modules/pi-agent-search-web/src/types.ts +153 -0
- package/node_modules/pi-agent-text/package.json +18 -0
- package/node_modules/pi-agent-text/src/index.ts +31 -0
- package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
- package/node_modules/pi-agent-text/src/source-line.ts +49 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
- package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
- package/node_modules/pi-agent-text/src/text-document.ts +149 -0
- package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/node_modules/pi-agent-text-editor/index.ts +19 -0
- package/node_modules/pi-agent-text-editor/package.json +92 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
- package/node_modules/pi-agent-web/index.ts +37 -0
- package/node_modules/pi-agent-web/package.json +24 -0
- package/node_modules/pi-agent-web/src/resolver.ts +182 -0
- package/node_modules/pi-agent-web-html/index.ts +15 -0
- package/node_modules/pi-agent-web-html/package.json +18 -0
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
- package/node_modules/pi-agent-web-image/index.ts +14 -0
- package/node_modules/pi-agent-web-image/package.json +17 -0
- package/node_modules/pi-agent-web-pdf/index.ts +14 -0
- package/node_modules/pi-agent-web-pdf/package.json +17 -0
- package/node_modules/pi-agent-web-text/index.ts +14 -0
- package/node_modules/pi-agent-web-text/package.json +17 -0
- package/package.json +176 -0
- package/src/api/code-view.ts +25 -0
- package/src/api/connect-plugin.ts +64 -0
- package/src/api/plugin-protocol.ts +63 -0
- package/src/api/read.ts +5 -0
- package/src/api/resource.ts +2 -0
- package/src/api/search.ts +4 -0
- package/src/api/text-editor.ts +3 -0
- package/src/api/text.ts +2 -0
- package/src/api/toolchain.ts +24 -0
- package/src/code-view/diagnostic-view.ts +82 -0
- package/src/code-view/reference.ts +113 -0
- package/src/code-view/source-view.ts +229 -0
- package/src/composite/builtin-extensions.ts +68 -0
- package/src/composite/config.ts +94 -0
- package/src/composite/selection.ts +66 -0
- package/src/core/extension.ts +48 -0
- package/src/core/ide-core.ts +117 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
- package/src/extensions/pi-agent-read/index.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +41 -0
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/src/extensions/pi-agent-search/index.ts +1 -0
- package/src/extensions/pi-agent-search/package.json +35 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
- package/src/extensions/pi-agent-text-editor/index.ts +19 -0
- package/src/extensions/pi-agent-text-editor/package.json +92 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/src/index.ts +1 -0
- package/src/pi-agent-ide.ts +17 -0
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/package.json +39 -0
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
- package/src/plugins/pi-agent-ide-changes/package.json +29 -0
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
- package/src/plugins/pi-agent-ide-lint/package.json +19 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
- package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/src/post-edit/gate.ts +153 -0
- package/src/toolchain/diagnostic.ts +7 -0
- package/src/toolchain/gate.ts +322 -0
- package/src/toolchain/registry.ts +223 -0
- package/src/toolchain/types.ts +164 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import parser, { type LuceneQueryNode } from "lucene-query-parser";
|
|
2
|
+
|
|
3
|
+
interface CompiledExpression
|
|
4
|
+
{
|
|
5
|
+
readonly condition: string;
|
|
6
|
+
readonly match: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function compileSearchQuery(query: string): string
|
|
10
|
+
{
|
|
11
|
+
if (!containsBooleanOperator(query))
|
|
12
|
+
{
|
|
13
|
+
return escapeRegex(query);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const normalizedQuery = query.replace(/\|{1,2}/gu, " OR ");
|
|
17
|
+
const expression = compileExpression(parser.parse(normalizedQuery));
|
|
18
|
+
return `^(?=${expression.condition}).*?(${expression.match})`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function containsBooleanOperator(query: string): boolean
|
|
22
|
+
{
|
|
23
|
+
return /(?:^|\s)(?:AND|OR|NOT)(?=\s|$)|\|{1,2}/u.test(query);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function compileExpression(node: LuceneQueryNode, inheritedField?: string): CompiledExpression
|
|
27
|
+
{
|
|
28
|
+
const field = concreteField(node.field) ?? inheritedField;
|
|
29
|
+
|
|
30
|
+
if (typeof node.term === "string")
|
|
31
|
+
{
|
|
32
|
+
return compileTerm(node, field);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (node.left === undefined || node.operator === undefined || node.right === undefined || node.right === null)
|
|
36
|
+
{
|
|
37
|
+
throw new Error("Search query must contain a searchable expression.");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const left = compileExpression(node.left, field);
|
|
41
|
+
const right = compileExpression(node.right, field);
|
|
42
|
+
|
|
43
|
+
switch (node.operator)
|
|
44
|
+
{
|
|
45
|
+
case "OR":
|
|
46
|
+
{
|
|
47
|
+
return {
|
|
48
|
+
condition: `(?:${left.condition}|${right.condition})`,
|
|
49
|
+
match: `(?:${left.match}|${right.match})`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
case "AND":
|
|
53
|
+
case "<implicit>":
|
|
54
|
+
{
|
|
55
|
+
return {
|
|
56
|
+
condition: `(?=.*(?:${left.condition}))(?=.*(?:${right.condition}))`,
|
|
57
|
+
match: `(?:${left.match}|${right.match})`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
case "NOT":
|
|
61
|
+
{
|
|
62
|
+
return {
|
|
63
|
+
condition: `(?=.*(?:${left.condition}))(?!.*(?:${right.condition}))`,
|
|
64
|
+
match: left.match,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
default:
|
|
68
|
+
{
|
|
69
|
+
throw new Error(`Search query operator ${JSON.stringify(node.operator)} is not supported.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function compileTerm(node: LuceneQueryNode, field: string | undefined): CompiledExpression
|
|
75
|
+
{
|
|
76
|
+
if (node.prefix !== undefined && node.prefix !== null)
|
|
77
|
+
{
|
|
78
|
+
throw new Error("Search query prefix operators are not supported.");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (node.similarity !== undefined && node.similarity !== null)
|
|
82
|
+
{
|
|
83
|
+
throw new Error("Search query fuzzy operators are not supported.");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (node.proximity !== undefined && node.proximity !== null)
|
|
87
|
+
{
|
|
88
|
+
throw new Error("Search query proximity operators are not supported.");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (node.boost !== undefined && node.boost !== null)
|
|
92
|
+
{
|
|
93
|
+
throw new Error("Search query boost operators are not supported.");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (node.regexpr === true)
|
|
97
|
+
{
|
|
98
|
+
throw new Error("Use the explicit regex: search protocol for regular expressions.");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const term = normalizeTerm(node.term);
|
|
102
|
+
|
|
103
|
+
if (term.length === 0)
|
|
104
|
+
{
|
|
105
|
+
throw new Error("Search query terms must not be empty.");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const pattern = field === undefined
|
|
109
|
+
? escapeRegex(term)
|
|
110
|
+
: fieldPattern(field, term);
|
|
111
|
+
return { condition: pattern, match: pattern };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function concreteField(field: string | undefined): string | undefined
|
|
115
|
+
{
|
|
116
|
+
return field === undefined || field === "<implicit>" ? undefined : field;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function normalizeTerm(term: string | undefined): string
|
|
120
|
+
{
|
|
121
|
+
if (term === undefined)
|
|
122
|
+
{
|
|
123
|
+
throw new Error("Search query term is missing.");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return term.length >= 2 && term.startsWith("'") && term.endsWith("'")
|
|
127
|
+
? term.slice(1, -1)
|
|
128
|
+
: term;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function fieldPattern(field: string, term: string): string
|
|
132
|
+
{
|
|
133
|
+
return `["']?\\b${escapeRegex(field)}\\b["']?\\s*:\\s*["']?${escapeRegex(term)}["']?`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function escapeRegex(value: string): string
|
|
137
|
+
{
|
|
138
|
+
return value.replace(/[\\^$.*+?()[\]{}|]/gu, "\\$&");
|
|
139
|
+
}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type AgentToolResult,
|
|
5
|
+
keyText,
|
|
6
|
+
type Theme,
|
|
7
|
+
type ThemeColor,
|
|
8
|
+
type ToolRenderResultOptions,
|
|
9
|
+
} from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import { type Component, Text, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
11
|
+
|
|
12
|
+
import { isSearchToolDetails } from "#src/search-result.js";
|
|
13
|
+
|
|
14
|
+
import type { SearchResultFile, SearchResultLine, SearchResultRange, SearchToolDetails } from "#src/search-result.js";
|
|
15
|
+
|
|
16
|
+
const COMPACT_SEARCH_ROWS = 12;
|
|
17
|
+
|
|
18
|
+
const FILE_BADGES: Readonly<Record<string, { readonly label: string; readonly color: ThemeColor; }>> = {
|
|
19
|
+
".ts": { label: "TS", color: "accent" },
|
|
20
|
+
".tsx": { label: "TX", color: "accent" },
|
|
21
|
+
".js": { label: "JS", color: "warning" },
|
|
22
|
+
".jsx": { label: "JX", color: "warning" },
|
|
23
|
+
".json": { label: "{}", color: "warning" },
|
|
24
|
+
".md": { label: "MD", color: "mdHeading" },
|
|
25
|
+
".py": { label: "PY", color: "accent" },
|
|
26
|
+
".rs": { label: "RS", color: "accent" },
|
|
27
|
+
".go": { label: "GO", color: "accent" },
|
|
28
|
+
".css": { label: "CS", color: "accent" },
|
|
29
|
+
".html": { label: "<>", color: "accent" },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
interface SearchCallArguments
|
|
33
|
+
{
|
|
34
|
+
readonly query?: unknown;
|
|
35
|
+
readonly path?: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface SearchRenderContext
|
|
39
|
+
{
|
|
40
|
+
readonly lastComponent: Component | undefined;
|
|
41
|
+
readonly isError?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type SearchPanelRow =
|
|
45
|
+
| { readonly kind: "file"; readonly file: SearchResultFile; }
|
|
46
|
+
| { readonly kind: "line"; readonly file: SearchResultFile; readonly line: SearchResultLine; }
|
|
47
|
+
| { readonly kind: "omitted"; readonly matches: number; }
|
|
48
|
+
| { readonly kind: "empty"; };
|
|
49
|
+
|
|
50
|
+
interface SearchLineWindow
|
|
51
|
+
{
|
|
52
|
+
readonly from: number;
|
|
53
|
+
readonly to: number;
|
|
54
|
+
readonly leadingEllipsis: boolean;
|
|
55
|
+
readonly trailingEllipsis: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function renderSearchCall(args: SearchCallArguments, theme: Theme): Component
|
|
59
|
+
{
|
|
60
|
+
const query = typeof args.query === "string" ? args.query : "";
|
|
61
|
+
const scope = typeof args.path === "string" && args.path.length > 0 && args.path !== "."
|
|
62
|
+
? ` in ${args.path}`
|
|
63
|
+
: "";
|
|
64
|
+
return new Text(
|
|
65
|
+
theme.fg("toolTitle", theme.bold("search "))
|
|
66
|
+
+ theme.fg("muted", `${JSON.stringify(query)}${scope}`),
|
|
67
|
+
0,
|
|
68
|
+
0,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function renderSearchResult(
|
|
73
|
+
result: AgentToolResult<SearchToolDetails>,
|
|
74
|
+
options: ToolRenderResultOptions,
|
|
75
|
+
theme: Theme,
|
|
76
|
+
context: SearchRenderContext,
|
|
77
|
+
): Component
|
|
78
|
+
{
|
|
79
|
+
if (options.isPartial || context.isError || !isSearchToolDetails(result.details))
|
|
80
|
+
{
|
|
81
|
+
const content = result.content[0];
|
|
82
|
+
const text = content?.type === "text" ? content.text : "";
|
|
83
|
+
const color: ThemeColor = context.isError ? "error" : options.isPartial ? "dim" : "toolOutput";
|
|
84
|
+
return new Text(theme.fg(color, text), 0, 0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const previous = context.lastComponent instanceof SearchResultPanel ? context.lastComponent : undefined;
|
|
88
|
+
const panel = previous ?? new SearchResultPanel(result.details, theme, options.expanded);
|
|
89
|
+
panel.update(result.details, theme, options.expanded);
|
|
90
|
+
return panel;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class SearchResultPanel implements Component
|
|
94
|
+
{
|
|
95
|
+
private cached: { readonly width: number; readonly lines: string[]; } | undefined;
|
|
96
|
+
|
|
97
|
+
public constructor(
|
|
98
|
+
private details: SearchToolDetails,
|
|
99
|
+
private theme: Theme,
|
|
100
|
+
private expanded: boolean,
|
|
101
|
+
)
|
|
102
|
+
{}
|
|
103
|
+
|
|
104
|
+
public update(details: SearchToolDetails, theme: Theme, expanded: boolean): void
|
|
105
|
+
{
|
|
106
|
+
if (this.details !== details || this.theme !== theme || this.expanded !== expanded)
|
|
107
|
+
{
|
|
108
|
+
this.details = details;
|
|
109
|
+
this.theme = theme;
|
|
110
|
+
this.expanded = expanded;
|
|
111
|
+
this.invalidate();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public render(width: number): string[]
|
|
116
|
+
{
|
|
117
|
+
if (this.cached?.width === width)
|
|
118
|
+
{
|
|
119
|
+
return this.cached.lines;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (width < 4)
|
|
123
|
+
{
|
|
124
|
+
const lines = [truncateToWidth(searchSummary(this.details), Math.max(1, width))];
|
|
125
|
+
this.cached = { width, lines };
|
|
126
|
+
return lines;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const innerWidth = width - 2;
|
|
130
|
+
const rows = searchViewport(this.details, this.expanded);
|
|
131
|
+
const gutterWidth = maximumLineNumberWidth(this.details.files);
|
|
132
|
+
const lines = [renderTopBorder(this.details, innerWidth, this.theme)];
|
|
133
|
+
|
|
134
|
+
for (const row of rows)
|
|
135
|
+
{
|
|
136
|
+
lines.push(renderPanelRow(row, innerWidth, gutterWidth, this.theme));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
lines.push(this.theme.fg("borderMuted", `╰${"─".repeat(innerWidth)}╯`));
|
|
140
|
+
const clipped = lines.map((line) => truncateToWidth(line, width));
|
|
141
|
+
this.cached = { width, lines: clipped };
|
|
142
|
+
return clipped;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public invalidate(): void
|
|
146
|
+
{
|
|
147
|
+
this.cached = undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function searchViewport(details: SearchToolDetails, expanded: boolean): readonly SearchPanelRow[]
|
|
152
|
+
{
|
|
153
|
+
const rows = details.files.length === 0
|
|
154
|
+
? [{ kind: "empty" } satisfies SearchPanelRow]
|
|
155
|
+
: details.files.flatMap((file): SearchPanelRow[] => [
|
|
156
|
+
{ kind: "file", file },
|
|
157
|
+
...file.lines.map((line): SearchPanelRow => ({ kind: "line", file, line })),
|
|
158
|
+
]);
|
|
159
|
+
|
|
160
|
+
if (expanded || rows.length <= COMPACT_SEARCH_ROWS)
|
|
161
|
+
{
|
|
162
|
+
return rows;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const selected = rows.slice(0, COMPACT_SEARCH_ROWS - 1);
|
|
166
|
+
|
|
167
|
+
while (selected.at(-1)?.kind === "file")
|
|
168
|
+
{
|
|
169
|
+
selected.pop();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const shownMatches = selected.reduce(
|
|
173
|
+
(count, row) => count + (row.kind === "line" ? row.line.matchCount : 0),
|
|
174
|
+
0,
|
|
175
|
+
);
|
|
176
|
+
return [...selected, { kind: "omitted", matches: details.matchCount - shownMatches }];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function renderPanelRow(row: SearchPanelRow, width: number, gutterWidth: number, theme: Theme): string
|
|
180
|
+
{
|
|
181
|
+
if (row.kind === "file")
|
|
182
|
+
{
|
|
183
|
+
return framed(renderFileHeader(row.file, width, theme), width, theme, true);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (row.kind === "line")
|
|
187
|
+
{
|
|
188
|
+
return framed(renderMatchLine(row.line, width, gutterWidth, theme), width, theme);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (row.kind === "omitted")
|
|
192
|
+
{
|
|
193
|
+
const hint = `${keyText("app.tools.expand")} to expand`;
|
|
194
|
+
return framed(
|
|
195
|
+
theme.fg("dim", ` … ${String(row.matches)} more ${plural(row.matches, "match", "matches")} · ${hint}`),
|
|
196
|
+
width,
|
|
197
|
+
theme,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return framed(theme.fg("dim", " No matches found"), width, theme);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function renderFileHeader(file: SearchResultFile, width: number, theme: Theme): string
|
|
205
|
+
{
|
|
206
|
+
const badge = fileBadge(file.path, theme);
|
|
207
|
+
const count = theme.fg("accent", theme.bold(String(file.matchCount)));
|
|
208
|
+
const fixedWidth = visibleWidth(badge) + visibleWidth(count) + 4;
|
|
209
|
+
const pathWidth = Math.max(1, width - fixedWidth);
|
|
210
|
+
const displayedPath = truncatePath(file.path, pathWidth);
|
|
211
|
+
const linkedPath = fileLink(displayedPath, file.link, theme);
|
|
212
|
+
const left = ` ${badge} ${linkedPath}`;
|
|
213
|
+
const gap = " ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(count) - 1));
|
|
214
|
+
return truncateToWidth(`${left}${gap}${count} `, width);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function renderMatchLine(line: SearchResultLine, width: number, gutterWidth: number, theme: Theme): string
|
|
218
|
+
{
|
|
219
|
+
const number = String(line.lineNumber).padStart(gutterWidth);
|
|
220
|
+
const gutter = ` ${theme.fg("dim", number)} ${theme.fg("borderMuted", "│")} `;
|
|
221
|
+
const contentWidth = Math.max(1, width - visibleWidth(gutter) - 1);
|
|
222
|
+
return `${gutter}${renderHighlightedLine(line, contentWidth, theme)}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function renderHighlightedLine(line: SearchResultLine, width: number, theme: Theme): string
|
|
226
|
+
{
|
|
227
|
+
const window = searchLineWindow(line, width);
|
|
228
|
+
const ranges = visibleRanges(line.ranges, window.from, window.to);
|
|
229
|
+
let result = window.leadingEllipsis ? theme.fg("dim", "…") : "";
|
|
230
|
+
let offset = window.from;
|
|
231
|
+
|
|
232
|
+
for (const range of ranges)
|
|
233
|
+
{
|
|
234
|
+
if (range.from > offset)
|
|
235
|
+
{
|
|
236
|
+
result += theme.fg("toolOutput", safeText(line.text.slice(offset, range.from)));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const match = safeText(line.text.slice(range.from, range.to));
|
|
240
|
+
result += theme.bg("selectedBg", theme.fg("accent", theme.bold(match)));
|
|
241
|
+
offset = range.to;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (offset < window.to)
|
|
245
|
+
{
|
|
246
|
+
result += theme.fg("toolOutput", safeText(line.text.slice(offset, window.to)));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (window.trailingEllipsis)
|
|
250
|
+
{
|
|
251
|
+
result += theme.fg("dim", "…");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return truncateToWidth(result, width);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function searchLineWindow(line: SearchResultLine, width: number): SearchLineWindow
|
|
258
|
+
{
|
|
259
|
+
if (visibleWidth(safeText(line.text)) <= width)
|
|
260
|
+
{
|
|
261
|
+
return { from: 0, to: line.text.length, leadingEllipsis: false, trailingEllipsis: false };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const focus = line.ranges[0]!;
|
|
265
|
+
const budget = Math.max(1, width - 2);
|
|
266
|
+
const matchWidth = Math.min(budget, Math.max(1, focus.to - focus.from));
|
|
267
|
+
const before = Math.max(0, Math.floor((budget - matchWidth) * 0.4));
|
|
268
|
+
let from = Math.max(0, focus.from - before);
|
|
269
|
+
let to = Math.min(line.text.length, from + budget);
|
|
270
|
+
|
|
271
|
+
if (to < focus.to)
|
|
272
|
+
{
|
|
273
|
+
to = Math.min(line.text.length, focus.to);
|
|
274
|
+
from = Math.max(0, to - budget);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
from,
|
|
279
|
+
to,
|
|
280
|
+
leadingEllipsis: from > 0,
|
|
281
|
+
trailingEllipsis: to < line.text.length,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function visibleRanges(
|
|
286
|
+
ranges: readonly SearchResultRange[],
|
|
287
|
+
from: number,
|
|
288
|
+
to: number,
|
|
289
|
+
): readonly SearchResultRange[]
|
|
290
|
+
{
|
|
291
|
+
const visible: SearchResultRange[] = [];
|
|
292
|
+
|
|
293
|
+
for (const range of ranges)
|
|
294
|
+
{
|
|
295
|
+
const clipped = { from: Math.max(from, range.from), to: Math.min(to, range.to) };
|
|
296
|
+
|
|
297
|
+
if (clipped.to <= clipped.from)
|
|
298
|
+
{
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const previous = visible.at(-1);
|
|
303
|
+
|
|
304
|
+
if (previous !== undefined && clipped.from <= previous.to)
|
|
305
|
+
{
|
|
306
|
+
visible[visible.length - 1] = { from: previous.from, to: Math.max(previous.to, clipped.to) };
|
|
307
|
+
}
|
|
308
|
+
else
|
|
309
|
+
{
|
|
310
|
+
visible.push(clipped);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return visible;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function renderTopBorder(details: SearchToolDetails, width: number, theme: Theme): string
|
|
318
|
+
{
|
|
319
|
+
const frame = (text: string): string => theme.fg("borderMuted", text);
|
|
320
|
+
const title = truncateToWidth(` ${searchSummary(details)} `, Math.max(0, width - 1), "");
|
|
321
|
+
const fill = "─".repeat(Math.max(0, width - visibleWidth(title) - 1));
|
|
322
|
+
return `${frame("╭─")}${theme.fg("accent", title)}${frame(`${fill}╮`)}`;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function searchSummary(details: SearchToolDetails): string
|
|
326
|
+
{
|
|
327
|
+
if (details.matchCount === 0)
|
|
328
|
+
{
|
|
329
|
+
return "No matches";
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const count = `${String(details.matchCount)}${details.complete ? "" : "+"}`;
|
|
333
|
+
return `${count} ${plural(details.matchCount, "match", "matches")} in ${String(details.fileCount)} ${
|
|
334
|
+
plural(details.fileCount, "file", "files")
|
|
335
|
+
}`;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function framed(content: string, width: number, theme: Theme, highlighted = false): string
|
|
339
|
+
{
|
|
340
|
+
const clipped = truncateToWidth(content, width);
|
|
341
|
+
const body = `${clipped}${" ".repeat(Math.max(0, width - visibleWidth(clipped)))}`;
|
|
342
|
+
const renderedBody = highlighted ? theme.bg("selectedBg", body) : body;
|
|
343
|
+
const border = theme.fg("borderMuted", "│");
|
|
344
|
+
return `${border}${renderedBody}${border}`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function fileBadge(filePath: string, theme: Theme): string
|
|
348
|
+
{
|
|
349
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
350
|
+
const badge = FILE_BADGES[extension] ?? {
|
|
351
|
+
label: "◇ ",
|
|
352
|
+
color: extension.length === 0 ? "muted" : "accent",
|
|
353
|
+
} satisfies { readonly label: string; readonly color: ThemeColor; };
|
|
354
|
+
return theme.fg(badge.color, theme.bold(badge.label));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function fileLink(displayedPath: string, link: string, theme: Theme): string
|
|
358
|
+
{
|
|
359
|
+
const separator = Math.max(displayedPath.lastIndexOf("/"), displayedPath.lastIndexOf("\\"));
|
|
360
|
+
const directory = separator === -1 ? "" : displayedPath.slice(0, separator + 1);
|
|
361
|
+
const basename = separator === -1 ? displayedPath : displayedPath.slice(separator + 1);
|
|
362
|
+
const label = theme.fg("muted", directory) + theme.underline(theme.fg("accent", basename));
|
|
363
|
+
return link.includes("\u0007") || link.includes("\u001B")
|
|
364
|
+
? label
|
|
365
|
+
: `\u001B]8;;${link}\u0007${label}\u001B]8;;\u0007`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function truncatePath(filePath: string, width: number): string
|
|
369
|
+
{
|
|
370
|
+
if (visibleWidth(filePath) <= width)
|
|
371
|
+
{
|
|
372
|
+
return filePath;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (width <= 1)
|
|
376
|
+
{
|
|
377
|
+
return "…";
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return `…${filePath.slice(-(width - 1))}`;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function safeText(value: string): string
|
|
384
|
+
{
|
|
385
|
+
let result = "";
|
|
386
|
+
|
|
387
|
+
for (const character of value)
|
|
388
|
+
{
|
|
389
|
+
if (character === "\t")
|
|
390
|
+
{
|
|
391
|
+
result += " ";
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const code = character.codePointAt(0)!;
|
|
396
|
+
result += code < 0x20 || code === 0x7F ? "�" : character;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return result;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function maximumLineNumberWidth(files: readonly SearchResultFile[]): number
|
|
403
|
+
{
|
|
404
|
+
let maximum = 1;
|
|
405
|
+
|
|
406
|
+
for (const file of files)
|
|
407
|
+
{
|
|
408
|
+
for (const line of file.lines)
|
|
409
|
+
{
|
|
410
|
+
maximum = Math.max(maximum, line.lineNumber);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return Math.max(3, String(maximum).length);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function plural(count: number, singular: string, pluralForm: string): string
|
|
418
|
+
{
|
|
419
|
+
return count === 1 ? singular : pluralForm;
|
|
420
|
+
}
|