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 @@
|
|
|
1
|
+
export { default } from "./src/core/extension.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-agent-search",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"pi": {
|
|
6
|
+
"extensions": [
|
|
7
|
+
"./index.ts"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"imports": {
|
|
11
|
+
"#src/*": "./src/*"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
"./api/connect-plugin": {
|
|
15
|
+
"types": "./src/api/connect-plugin.ts",
|
|
16
|
+
"default": "./src/api/connect-plugin.ts"
|
|
17
|
+
},
|
|
18
|
+
"./api/plugin-protocol": {
|
|
19
|
+
"types": "./src/api/plugin-protocol.ts",
|
|
20
|
+
"default": "./src/api/plugin-protocol.ts"
|
|
21
|
+
},
|
|
22
|
+
"./api/search": {
|
|
23
|
+
"types": "./src/api/search.ts",
|
|
24
|
+
"default": "./src/api/search.ts"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"pi-agent-tool-call-interception": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
32
|
+
"@earendil-works/pi-tui": "*",
|
|
33
|
+
"typebox": "*"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { connectSearchPlugin } from "pi-agent-search/api/connect-plugin";
|
|
5
|
+
import { SEARCH_API_VERSION, SEARCH_PROTOCOL } from "pi-agent-search/api/plugin-protocol";
|
|
6
|
+
|
|
7
|
+
import { createStore, getDefaultDbPath, type HybridQueryResult } from "@tobilu/qmd";
|
|
8
|
+
|
|
9
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import type { SearchResolver } from "pi-agent-search/api/search";
|
|
11
|
+
|
|
12
|
+
export default function registerSemanticSearch(pi: ExtensionAPI): void | Promise<void>
|
|
13
|
+
{
|
|
14
|
+
return connectSearchPlugin(pi, {
|
|
15
|
+
protocol: SEARCH_PROTOCOL,
|
|
16
|
+
apiVersion: SEARCH_API_VERSION,
|
|
17
|
+
id: "semantic",
|
|
18
|
+
setup(api): void
|
|
19
|
+
{
|
|
20
|
+
api.addResolver({ resolver: semanticResolver() });
|
|
21
|
+
api.describe(
|
|
22
|
+
"Use `semantic:<query>` for conceptual discovery across indexed content when exact terms or paths are unknown. Results provide ranked relevant snippets for further investigation.",
|
|
23
|
+
);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function semanticResolver(): SearchResolver
|
|
29
|
+
{
|
|
30
|
+
return {
|
|
31
|
+
id: "semantic",
|
|
32
|
+
async tryResolve(request, context)
|
|
33
|
+
{
|
|
34
|
+
if (!request.query.startsWith("semantic:"))
|
|
35
|
+
{
|
|
36
|
+
return { kind: "not-handled" };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const query = request.query.slice("semantic:".length).trim();
|
|
40
|
+
|
|
41
|
+
if (query.length === 0)
|
|
42
|
+
{
|
|
43
|
+
return { kind: "failed", error: new Error("semantic: query must not be empty") };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const localDirectory = path.join(context.cwd, ".qmd");
|
|
47
|
+
const localConfig = path.join(localDirectory, "index.yml");
|
|
48
|
+
const localYamlConfig = path.join(localDirectory, "index.yaml");
|
|
49
|
+
const configPath = await firstExisting(localConfig, localYamlConfig);
|
|
50
|
+
const dbPath = configPath === undefined ? getDefaultDbPath() : path.join(localDirectory, "index.sqlite");
|
|
51
|
+
const store = await createStore({ dbPath, ...(configPath === undefined ? {} : { configPath }) });
|
|
52
|
+
|
|
53
|
+
try
|
|
54
|
+
{
|
|
55
|
+
const results = await store.search({ query, limit: request.limit ?? 10 });
|
|
56
|
+
return { kind: "resolved", payload: { query, results } };
|
|
57
|
+
}
|
|
58
|
+
finally
|
|
59
|
+
{
|
|
60
|
+
await store.close();
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
format(payload)
|
|
64
|
+
{
|
|
65
|
+
const { query, results } = payload as {
|
|
66
|
+
readonly query: string;
|
|
67
|
+
readonly results: readonly HybridQueryResult[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (results.length === 0)
|
|
71
|
+
{
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: "text", text: "No semantic matches found." }],
|
|
74
|
+
details: { query, results },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const lines = results.flatMap((result, index) => [
|
|
79
|
+
`${String(index + 1)}. ${result.title} — qmd://${result.displayPath} #${result.docid} (${
|
|
80
|
+
result.score.toFixed(3)
|
|
81
|
+
})`,
|
|
82
|
+
result.body.trim().split("\n").slice(0, 6).map((line) => ` ${line}`).join("\n"),
|
|
83
|
+
]);
|
|
84
|
+
return { content: [{ type: "text", text: lines.join("\n") }], details: { query, results } };
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function firstExisting(...files: readonly string[]): Promise<string | undefined>
|
|
90
|
+
{
|
|
91
|
+
for (const file of files)
|
|
92
|
+
{
|
|
93
|
+
try
|
|
94
|
+
{
|
|
95
|
+
await access(file);
|
|
96
|
+
return file;
|
|
97
|
+
}
|
|
98
|
+
catch
|
|
99
|
+
{
|
|
100
|
+
// Continue to the next supported local config name.
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-agent-search-semantic",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"pi": {
|
|
6
|
+
"extensions": [
|
|
7
|
+
"./index.ts"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@tobilu/qmd": "^2.8.3",
|
|
12
|
+
"pi-agent-search": "0.1.0"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { connectSearchPlugin } from "pi-agent-search/api/connect-plugin";
|
|
2
|
+
import { SEARCH_API_VERSION, SEARCH_PROTOCOL } from "pi-agent-search/api/plugin-protocol";
|
|
3
|
+
import { connectTextEditorPlugin } from "pi-agent-text-editor/api/connect-plugin";
|
|
4
|
+
import {
|
|
5
|
+
TEXT_EDITOR_API_VERSION,
|
|
6
|
+
TEXT_EDITOR_PROTOCOL,
|
|
7
|
+
TEXT_SEARCH_ANCHOR_KIND,
|
|
8
|
+
} from "pi-agent-text-editor/api/plugin-protocol";
|
|
9
|
+
|
|
10
|
+
import { createFileResolver, createRegexResolver, createTextResolver } from "#src/resolvers.js";
|
|
11
|
+
import { SearchSessionStore } from "#src/search-session.js";
|
|
12
|
+
|
|
13
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
14
|
+
|
|
15
|
+
export default async function registerTextSearch(pi: ExtensionAPI): Promise<void>
|
|
16
|
+
{
|
|
17
|
+
const sessions = new SearchSessionStore();
|
|
18
|
+
await Promise.all([
|
|
19
|
+
connectSearchPlugin(pi, {
|
|
20
|
+
protocol: SEARCH_PROTOCOL,
|
|
21
|
+
apiVersion: SEARCH_API_VERSION,
|
|
22
|
+
id: "local",
|
|
23
|
+
setup(api): void
|
|
24
|
+
{
|
|
25
|
+
api.addResolver({ resolver: createRegexResolver(sessions), priority: -10 });
|
|
26
|
+
api.addResolver({ resolver: createFileResolver(), priority: -10 });
|
|
27
|
+
api.addResolver({ resolver: createTextResolver(sessions), priority: 100 });
|
|
28
|
+
api.describe([
|
|
29
|
+
"Searches workspace text and paths.",
|
|
30
|
+
"Use a plain query for literal text, `regex:<pattern>` for a regular expression, or `files:<pattern>` for file paths.",
|
|
31
|
+
"Text and regex results register stale-safe `SEARCH#...` anchors for text editor operations.",
|
|
32
|
+
].join("\n"));
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
connectTextEditorPlugin(pi, {
|
|
36
|
+
protocol: TEXT_EDITOR_PROTOCOL,
|
|
37
|
+
apiVersion: TEXT_EDITOR_API_VERSION,
|
|
38
|
+
id: "search-anchors",
|
|
39
|
+
setup(api): void
|
|
40
|
+
{
|
|
41
|
+
api.addAnchorResolver({
|
|
42
|
+
resolver: sessions.anchorResolver(),
|
|
43
|
+
resources: sessions.resourceResolver(),
|
|
44
|
+
kind: TEXT_SEARCH_ANCHOR_KIND,
|
|
45
|
+
type: "auxiliary",
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { createSearchSessionId } from "#src/search-session.js";
|
|
53
|
+
|
|
54
|
+
export type { TextSearchMatch } from "#src/search-session.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-agent-search-text",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"pi": {
|
|
6
|
+
"extensions": [
|
|
7
|
+
"./index.ts"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"imports": {
|
|
11
|
+
"#src/*": "./src/*"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./index.ts",
|
|
16
|
+
"default": "./index.ts"
|
|
17
|
+
},
|
|
18
|
+
"./search-session": {
|
|
19
|
+
"types": "./src/search-session.ts",
|
|
20
|
+
"default": "./src/search-session.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"lucene-query-parser": "1.2.0",
|
|
25
|
+
"pi-agent-search": "0.1.0",
|
|
26
|
+
"pi-agent-text": "0.1.0",
|
|
27
|
+
"pi-agent-text-editor": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
31
|
+
"@earendil-works/pi-tui": "*"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { SearchRequest } from "pi-agent-search/api/search";
|
|
5
|
+
|
|
6
|
+
export interface FileSearchResult
|
|
7
|
+
{
|
|
8
|
+
readonly files: readonly string[];
|
|
9
|
+
readonly complete: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function searchFiles(
|
|
13
|
+
query: string,
|
|
14
|
+
request: SearchRequest,
|
|
15
|
+
cwd: string,
|
|
16
|
+
signal?: AbortSignal,
|
|
17
|
+
): Promise<FileSearchResult>
|
|
18
|
+
{
|
|
19
|
+
const limit = request.limit ?? 100;
|
|
20
|
+
const args = ["--files", "--hidden", "--no-config", "--no-ignore-parent", "--glob", "!.git/**"];
|
|
21
|
+
|
|
22
|
+
for (const include of splitGlobs(request.include))
|
|
23
|
+
{
|
|
24
|
+
args.push("--glob", include);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const exclude of splitGlobs(request.exclude))
|
|
28
|
+
{
|
|
29
|
+
args.push("--glob", `!${exclude}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (request.path !== undefined)
|
|
33
|
+
{
|
|
34
|
+
args.push(request.path);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return new Promise((resolve, reject) =>
|
|
38
|
+
{
|
|
39
|
+
const child = spawn("rg", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
40
|
+
let stdout = "";
|
|
41
|
+
let stderr = "";
|
|
42
|
+
child.stdout.setEncoding("utf8");
|
|
43
|
+
child.stderr.setEncoding("utf8");
|
|
44
|
+
child.stdout.on("data", (chunk: string) => stdout += chunk);
|
|
45
|
+
child.stderr.on("data", (chunk: string) => stderr += chunk);
|
|
46
|
+
const abort = (): void =>
|
|
47
|
+
{
|
|
48
|
+
child.kill("SIGTERM");
|
|
49
|
+
};
|
|
50
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
51
|
+
child.once("error", reject);
|
|
52
|
+
child.once("close", (code) =>
|
|
53
|
+
{
|
|
54
|
+
signal?.removeEventListener("abort", abort);
|
|
55
|
+
|
|
56
|
+
if (signal?.aborted === true)
|
|
57
|
+
{
|
|
58
|
+
reject(signal.reason instanceof Error ? signal.reason : new Error("File search aborted"));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (code !== 0 && code !== 1)
|
|
63
|
+
{
|
|
64
|
+
reject(new Error(stderr.trim() || `rg exited with code ${String(code)}`));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const matches = stdout.split("\n").filter(Boolean)
|
|
69
|
+
.map((file) => path.relative(cwd, path.resolve(cwd, file)))
|
|
70
|
+
.filter((file) => fuzzyMatch(file, query))
|
|
71
|
+
.sort((left, right) => left.localeCompare(right));
|
|
72
|
+
resolve({ files: matches.slice(0, limit), complete: matches.length <= limit });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function splitGlobs(value: string | undefined): string[]
|
|
78
|
+
{
|
|
79
|
+
return value?.split(",").map((item) => item.trim()).filter(Boolean) ?? [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fuzzyMatch(file: string, query: string): boolean
|
|
83
|
+
{
|
|
84
|
+
if (query.length === 0)
|
|
85
|
+
{
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let index = 0;
|
|
90
|
+
const candidate = file.toLowerCase();
|
|
91
|
+
|
|
92
|
+
for (const character of query.toLowerCase())
|
|
93
|
+
{
|
|
94
|
+
index = candidate.indexOf(character, index);
|
|
95
|
+
|
|
96
|
+
if (index === -1)
|
|
97
|
+
{
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
index += 1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return true;
|
|
105
|
+
}
|
package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module "lucene-query-parser"
|
|
2
|
+
{
|
|
3
|
+
export interface LuceneQueryNode
|
|
4
|
+
{
|
|
5
|
+
readonly field?: string;
|
|
6
|
+
readonly term?: string;
|
|
7
|
+
readonly prefix?: string | null;
|
|
8
|
+
readonly similarity?: number | null;
|
|
9
|
+
readonly proximity?: number | null;
|
|
10
|
+
readonly boost?: number | null;
|
|
11
|
+
readonly regexpr?: boolean;
|
|
12
|
+
readonly left?: LuceneQueryNode;
|
|
13
|
+
readonly operator?: string;
|
|
14
|
+
readonly right?: LuceneQueryNode | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parser: {
|
|
18
|
+
parse(query: string): LuceneQueryNode;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default parser;
|
|
22
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { searchFiles } from "#src/file-search.js";
|
|
4
|
+
import { searchText } from "#src/search-backend.js";
|
|
5
|
+
import { compileSearchQuery } from "#src/search-query.js";
|
|
6
|
+
import { renderSearchResult } from "#src/search-renderer.js";
|
|
7
|
+
import { createSearchToolDetails } from "#src/search-result.js";
|
|
8
|
+
|
|
9
|
+
import type { SearchSessionStore, TextSearchMatch, TextSearchSession } from "#src/search-session.js";
|
|
10
|
+
import type { SearchRequest, SearchResolver } from "pi-agent-search/api/search";
|
|
11
|
+
|
|
12
|
+
interface TextPayload
|
|
13
|
+
{
|
|
14
|
+
readonly request: SearchRequest;
|
|
15
|
+
readonly matches: readonly TextSearchMatch[];
|
|
16
|
+
readonly complete: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface FilePayload
|
|
20
|
+
{
|
|
21
|
+
readonly query: string;
|
|
22
|
+
readonly files: readonly string[];
|
|
23
|
+
readonly complete: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const explicitPrefixes = ["regex:", "files:", "semantic:", "web:", "lsp:", "ast:"] as const;
|
|
27
|
+
|
|
28
|
+
export function createTextResolver(sessions: SearchSessionStore): SearchResolver
|
|
29
|
+
{
|
|
30
|
+
return createMatchResolver(
|
|
31
|
+
"text",
|
|
32
|
+
sessions,
|
|
33
|
+
(query) => explicitPrefixes.some((prefix) => query.startsWith(prefix)) ? undefined : compileSearchQuery(query),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createRegexResolver(sessions: SearchSessionStore): SearchResolver
|
|
38
|
+
{
|
|
39
|
+
return createMatchResolver(
|
|
40
|
+
"regex",
|
|
41
|
+
sessions,
|
|
42
|
+
(query) => query.startsWith("regex:") ? query.slice("regex:".length) : undefined,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createFileResolver(): SearchResolver
|
|
47
|
+
{
|
|
48
|
+
return {
|
|
49
|
+
id: "files",
|
|
50
|
+
async tryResolve(request, context)
|
|
51
|
+
{
|
|
52
|
+
if (!request.query.startsWith("files:"))
|
|
53
|
+
{
|
|
54
|
+
return { kind: "not-handled" };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const query = request.query.slice("files:".length).trim();
|
|
58
|
+
const result = await searchFiles(query, request, context.cwd, context.signal);
|
|
59
|
+
return { kind: "resolved", payload: { query, ...result } satisfies FilePayload };
|
|
60
|
+
},
|
|
61
|
+
format(payload)
|
|
62
|
+
{
|
|
63
|
+
const result = payload as FilePayload;
|
|
64
|
+
const heading = result.complete
|
|
65
|
+
? `${String(result.files.length)} files`
|
|
66
|
+
: `${String(result.files.length)}+ files (limit reached)`;
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: [heading, ...result.files].join("\n") }],
|
|
69
|
+
details: { query: result.query, files: result.files, complete: result.complete },
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createMatchResolver(
|
|
76
|
+
id: "text" | "regex",
|
|
77
|
+
sessions: SearchSessionStore,
|
|
78
|
+
queryBody: (query: string) => string | undefined,
|
|
79
|
+
): SearchResolver
|
|
80
|
+
{
|
|
81
|
+
return {
|
|
82
|
+
id,
|
|
83
|
+
async tryResolve(request, context)
|
|
84
|
+
{
|
|
85
|
+
const query = queryBody(request.query);
|
|
86
|
+
|
|
87
|
+
if (query === undefined)
|
|
88
|
+
{
|
|
89
|
+
return { kind: "not-handled" };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (query.length === 0)
|
|
93
|
+
{
|
|
94
|
+
return { kind: "failed", error: new Error(`${id} search query must not be empty`) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const result = await searchText({ ...request, query, regex: true }, context.cwd, context.signal);
|
|
98
|
+
return { kind: "resolved", payload: { request: { ...request, query }, ...result } satisfies TextPayload };
|
|
99
|
+
},
|
|
100
|
+
async format(payload, context)
|
|
101
|
+
{
|
|
102
|
+
const result = payload as TextPayload;
|
|
103
|
+
|
|
104
|
+
if (result.matches.length === 0)
|
|
105
|
+
{
|
|
106
|
+
return {
|
|
107
|
+
content: [{ type: "text", text: "No matches found." }],
|
|
108
|
+
details: createSearchToolDetails(result.request.query, [], result.complete, context.cwd),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const session = await sessions.register(
|
|
113
|
+
result.request.query,
|
|
114
|
+
result.matches,
|
|
115
|
+
result.complete,
|
|
116
|
+
context.cwd,
|
|
117
|
+
context.signal,
|
|
118
|
+
);
|
|
119
|
+
return {
|
|
120
|
+
content: [{ type: "text", text: formatSearchSession(session, context.cwd) }],
|
|
121
|
+
details: createSearchToolDetails(
|
|
122
|
+
session.query,
|
|
123
|
+
session.matches,
|
|
124
|
+
session.complete,
|
|
125
|
+
context.cwd,
|
|
126
|
+
session.id,
|
|
127
|
+
),
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
renderResult: renderSearchResult as SearchResolver["renderResult"],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function formatSearchSession(session: TextSearchSession, cwd: string): string
|
|
135
|
+
{
|
|
136
|
+
const fileCount = new Set(session.matches.map((match) => match.source)).size;
|
|
137
|
+
const count = session.matches.length;
|
|
138
|
+
const heading = session.complete
|
|
139
|
+
? `SEARCH#${session.id}:all — ${String(count)} ${plural(count, "match", "matches")} in ${String(fileCount)} ${
|
|
140
|
+
plural(fileCount, "file", "files")
|
|
141
|
+
}`
|
|
142
|
+
: `${String(count)}+ matches in ${String(fileCount)} ${
|
|
143
|
+
plural(fileCount, "file", "files")
|
|
144
|
+
} (limit reached; no all anchor was registered)`;
|
|
145
|
+
const lines = [heading];
|
|
146
|
+
let previousSource: string | undefined;
|
|
147
|
+
|
|
148
|
+
for (const [index, match] of session.matches.entries())
|
|
149
|
+
{
|
|
150
|
+
if (previousSource !== undefined && previousSource !== match.source)
|
|
151
|
+
{
|
|
152
|
+
lines.push("");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const source = displaySource(match.source, cwd);
|
|
156
|
+
lines.push(
|
|
157
|
+
`${source}:${String(match.lineNumber)}:${String(match.startColumn + 1)}-${
|
|
158
|
+
String(match.endColumn + 1)
|
|
159
|
+
} SEARCH#${session.id}:${String(index + 1)}`,
|
|
160
|
+
` ${previewMatch(match)}`,
|
|
161
|
+
);
|
|
162
|
+
previousSource = match.source;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!session.complete)
|
|
166
|
+
{
|
|
167
|
+
lines.push("", "Increase limit and search again before applying a complete replacement.");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return lines.join("\n");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function previewMatch(match: TextSearchMatch): string
|
|
174
|
+
{
|
|
175
|
+
const context = 64;
|
|
176
|
+
const from = Math.max(0, match.startColumn - context);
|
|
177
|
+
const to = Math.min(match.lineText.length, match.endColumn + context);
|
|
178
|
+
return `${from > 0 ? "…" : ""}${match.lineText.slice(from, match.startColumn)}⟦${
|
|
179
|
+
match.lineText.slice(match.startColumn, match.endColumn)
|
|
180
|
+
}⟧${match.lineText.slice(match.endColumn, to)}${to < match.lineText.length ? "…" : ""}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function displaySource(source: string, cwd: string): string
|
|
184
|
+
{
|
|
185
|
+
const relative = path.relative(cwd, source);
|
|
186
|
+
return relative.length > 0 && !relative.startsWith("..") && !path.isAbsolute(relative) ? relative : source;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function plural(count: number, singular: string, pluralForm: string): string
|
|
190
|
+
{
|
|
191
|
+
return count === 1 ? singular : pluralForm;
|
|
192
|
+
}
|