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,400 @@
|
|
|
1
|
+
import { withBlockedToolResult } from "pi-agent-tool-call-interception";
|
|
2
|
+
|
|
3
|
+
import type { SearchPlugin } from "#src/api/plugin-protocol.js";
|
|
4
|
+
import type {
|
|
5
|
+
SearchActionRegistration,
|
|
6
|
+
SearchContext,
|
|
7
|
+
SearchDescriptionSource,
|
|
8
|
+
SearchPluginApi,
|
|
9
|
+
SearchRequest,
|
|
10
|
+
SearchResolutionAttempt,
|
|
11
|
+
SearchResolverRegistration,
|
|
12
|
+
SearchToolDetails,
|
|
13
|
+
} from "#src/api/search.js";
|
|
14
|
+
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
15
|
+
|
|
16
|
+
interface RegisteredResolver
|
|
17
|
+
{
|
|
18
|
+
readonly pluginId: string;
|
|
19
|
+
readonly registration: SearchResolverRegistration;
|
|
20
|
+
readonly order: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SearchCore
|
|
24
|
+
{
|
|
25
|
+
registerPlugin(plugin: SearchPlugin): Promise<void>;
|
|
26
|
+
waitForPendingPlugins(): Promise<void>;
|
|
27
|
+
execute(request: SearchRequest, context: SearchContext): Promise<AgentToolResult<SearchToolDetails>>;
|
|
28
|
+
runAction(
|
|
29
|
+
reference: string,
|
|
30
|
+
capability: string,
|
|
31
|
+
resolverId: string,
|
|
32
|
+
input: unknown,
|
|
33
|
+
context: SearchContext,
|
|
34
|
+
): Promise<unknown>;
|
|
35
|
+
renderPromptGuideline(): string | undefined;
|
|
36
|
+
renderer(resolverId: string): SearchResolverRegistration["resolver"]["renderResult"];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createSearchCore(): SearchCore
|
|
40
|
+
{
|
|
41
|
+
const resolvers: RegisteredResolver[] = [];
|
|
42
|
+
const actions = new Map<string, SearchActionRegistration>();
|
|
43
|
+
const descriptions = new Map<string, SearchDescriptionSource>();
|
|
44
|
+
const plugins = new Map<string, Promise<void>>();
|
|
45
|
+
let queue = Promise.resolve();
|
|
46
|
+
|
|
47
|
+
const core: SearchCore = {
|
|
48
|
+
registerPlugin(plugin): Promise<void>
|
|
49
|
+
{
|
|
50
|
+
if (plugin.id.trim().length === 0)
|
|
51
|
+
{
|
|
52
|
+
return Promise.reject(new Error("Plugin ID must not be empty"));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const existing = plugins.get(plugin.id);
|
|
56
|
+
|
|
57
|
+
if (existing !== undefined)
|
|
58
|
+
{
|
|
59
|
+
return existing;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ready = queue.then(async () =>
|
|
63
|
+
{
|
|
64
|
+
const draftResolvers: SearchResolverRegistration[] = [];
|
|
65
|
+
const draftActions: SearchActionRegistration[] = [];
|
|
66
|
+
let draftDescription: SearchDescriptionSource | undefined;
|
|
67
|
+
const api: SearchPluginApi = {
|
|
68
|
+
addResolver(registration): void
|
|
69
|
+
{
|
|
70
|
+
assertResolver(registration);
|
|
71
|
+
draftResolvers.push(registration);
|
|
72
|
+
},
|
|
73
|
+
addAction(registration): void
|
|
74
|
+
{
|
|
75
|
+
assertAction(registration);
|
|
76
|
+
draftActions.push(registration);
|
|
77
|
+
},
|
|
78
|
+
describe(description): void
|
|
79
|
+
{
|
|
80
|
+
if (draftDescription !== undefined)
|
|
81
|
+
{
|
|
82
|
+
throw new Error(`Plugin ${plugin.id} provides more than one description`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
draftDescription = normalizeDescriptionSource(description);
|
|
86
|
+
},
|
|
87
|
+
search: (request, context) => core.execute(request, context),
|
|
88
|
+
runAction(request, context): Promise<unknown>
|
|
89
|
+
{
|
|
90
|
+
return core.runAction(
|
|
91
|
+
request.reference,
|
|
92
|
+
request.capability,
|
|
93
|
+
request.resolverId,
|
|
94
|
+
request.input,
|
|
95
|
+
context,
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
await plugin.setup(api);
|
|
100
|
+
const ids = new Set(resolvers.map(({ registration }) => registration.resolver.id));
|
|
101
|
+
|
|
102
|
+
for (const registration of draftResolvers)
|
|
103
|
+
{
|
|
104
|
+
if (ids.has(registration.resolver.id))
|
|
105
|
+
{
|
|
106
|
+
throw new Error(`Search resolver ${registration.resolver.id} is already registered`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
ids.add(registration.resolver.id);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (const action of draftActions)
|
|
113
|
+
{
|
|
114
|
+
const key = actionKey(action.resolverId, action.capability);
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
actions.has(key)
|
|
118
|
+
|| draftActions.some((candidate) =>
|
|
119
|
+
candidate !== action && actionKey(candidate.resolverId, candidate.capability) === key
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
{
|
|
123
|
+
throw new Error(`Search action ${key} is already registered`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
for (const registration of draftResolvers)
|
|
128
|
+
{
|
|
129
|
+
resolvers.push({ pluginId: plugin.id, registration, order: resolvers.length });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for (const action of draftActions)
|
|
133
|
+
{
|
|
134
|
+
actions.set(actionKey(action.resolverId, action.capability), action);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (draftDescription !== undefined)
|
|
138
|
+
{
|
|
139
|
+
descriptions.set(plugin.id, draftDescription);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return;
|
|
143
|
+
});
|
|
144
|
+
plugins.set(plugin.id, ready);
|
|
145
|
+
queue = ready.catch(() =>
|
|
146
|
+
{});
|
|
147
|
+
void ready.catch(() =>
|
|
148
|
+
{
|
|
149
|
+
plugins.delete(plugin.id);
|
|
150
|
+
return;
|
|
151
|
+
});
|
|
152
|
+
return ready;
|
|
153
|
+
},
|
|
154
|
+
async waitForPendingPlugins(): Promise<void>
|
|
155
|
+
{
|
|
156
|
+
await Promise.all(plugins.values());
|
|
157
|
+
},
|
|
158
|
+
async execute(request, context): Promise<AgentToolResult<SearchToolDetails>>
|
|
159
|
+
{
|
|
160
|
+
if (request.query.trim().length === 0)
|
|
161
|
+
{
|
|
162
|
+
return failure("INVALID_REQUEST", "Search query must not be empty");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const snapshot = [...resolvers].sort((left, right) =>
|
|
166
|
+
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) || left.order - right.order
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
for (const entry of snapshot)
|
|
170
|
+
{
|
|
171
|
+
const resolver = entry.registration.resolver;
|
|
172
|
+
let attempt: unknown;
|
|
173
|
+
|
|
174
|
+
try
|
|
175
|
+
{
|
|
176
|
+
attempt = await resolver.tryResolve(request, context);
|
|
177
|
+
}
|
|
178
|
+
catch (error)
|
|
179
|
+
{
|
|
180
|
+
return failure(
|
|
181
|
+
"RESOLVE_FAILED",
|
|
182
|
+
messageFor(error, `Resolver ${resolver.id} failed`),
|
|
183
|
+
resolver.id,
|
|
184
|
+
error,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!isAttempt(attempt))
|
|
189
|
+
{
|
|
190
|
+
return failure(
|
|
191
|
+
"INVALID_RESOLVER_RESULT",
|
|
192
|
+
`Resolver ${resolver.id} returned an invalid result`,
|
|
193
|
+
resolver.id,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (attempt.kind === "not-handled")
|
|
198
|
+
{
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (attempt.kind === "failed")
|
|
203
|
+
{
|
|
204
|
+
return failure(
|
|
205
|
+
"RESOLVE_FAILED",
|
|
206
|
+
messageFor(attempt.error, `Resolver ${resolver.id} failed`),
|
|
207
|
+
resolver.id,
|
|
208
|
+
attempt.error,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
try
|
|
213
|
+
{
|
|
214
|
+
const formatted = await resolver.format(attempt.payload, context);
|
|
215
|
+
|
|
216
|
+
if (!isAgentToolResult(formatted))
|
|
217
|
+
{
|
|
218
|
+
return failure(
|
|
219
|
+
"FORMAT_FAILED",
|
|
220
|
+
`Resolver ${resolver.id} formatter returned an invalid result`,
|
|
221
|
+
resolver.id,
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
content: formatted.content,
|
|
227
|
+
details: { resolverId: resolver.id, payload: formatted.details },
|
|
228
|
+
...(formatted.usage === undefined ? {} : { usage: formatted.usage }),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
catch (error)
|
|
232
|
+
{
|
|
233
|
+
return failure(
|
|
234
|
+
"FORMAT_FAILED",
|
|
235
|
+
messageFor(error, `Resolver ${resolver.id} formatter failed`),
|
|
236
|
+
resolver.id,
|
|
237
|
+
error,
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const reason = `No search resolver handled ${request.query}`;
|
|
243
|
+
return withBlockedToolResult(failure("NO_RESOLVER", reason), reason);
|
|
244
|
+
},
|
|
245
|
+
runAction(reference, capability, resolverId, input, context): Promise<unknown>
|
|
246
|
+
{
|
|
247
|
+
const action = actions.get(actionKey(resolverId, capability));
|
|
248
|
+
|
|
249
|
+
if (action === undefined)
|
|
250
|
+
{
|
|
251
|
+
throw new Error(`Search reference does not support ${capability}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return action.execute(reference, input, context);
|
|
255
|
+
},
|
|
256
|
+
renderPromptGuideline(): string | undefined
|
|
257
|
+
{
|
|
258
|
+
const entries = [...descriptions].flatMap(([id, source]) =>
|
|
259
|
+
{
|
|
260
|
+
const description = renderDescription(source);
|
|
261
|
+
return description === undefined ? [] : [`- \`${id}\` — ${description.replaceAll("\n", "\n ")}`];
|
|
262
|
+
});
|
|
263
|
+
return entries.length === 0
|
|
264
|
+
? undefined
|
|
265
|
+
: indentGuidelineContinuation(["Search supports these installed protocols:", ...entries].join("\n"));
|
|
266
|
+
},
|
|
267
|
+
renderer(resolverId)
|
|
268
|
+
{
|
|
269
|
+
return resolvers.find(({ registration }) => registration.resolver.id === resolverId)?.registration.resolver
|
|
270
|
+
.renderResult;
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
function indentGuidelineContinuation(guideline: string): string
|
|
275
|
+
{
|
|
276
|
+
const [firstLine, ...continuationLines] = guideline.split("\n");
|
|
277
|
+
return [firstLine ?? "", ...continuationLines.map((line) => line.length === 0 ? line : ` ${line}`)].join("\n");
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return core;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function assertResolver(value: unknown): asserts value is SearchResolverRegistration
|
|
284
|
+
{
|
|
285
|
+
if (!isRecord(value) || !isRecord(value.resolver))
|
|
286
|
+
{
|
|
287
|
+
throw new TypeError("Invalid search resolver registration");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const resolver = value.resolver;
|
|
291
|
+
|
|
292
|
+
if (
|
|
293
|
+
typeof resolver.id !== "string" || resolver.id.trim().length === 0
|
|
294
|
+
|| typeof resolver.tryResolve !== "function" || typeof resolver.format !== "function"
|
|
295
|
+
)
|
|
296
|
+
{
|
|
297
|
+
throw new TypeError("Invalid search resolver registration");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (value.priority !== undefined && (typeof value.priority !== "number" || !Number.isFinite(value.priority)))
|
|
301
|
+
{
|
|
302
|
+
throw new TypeError("Invalid search resolver priority");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function assertAction(value: unknown): asserts value is SearchActionRegistration
|
|
307
|
+
{
|
|
308
|
+
if (
|
|
309
|
+
!isRecord(value) || typeof value.resolverId !== "string" || value.resolverId.trim().length === 0
|
|
310
|
+
|| typeof value.capability !== "string" || value.capability.trim().length === 0
|
|
311
|
+
|| typeof value.execute !== "function"
|
|
312
|
+
)
|
|
313
|
+
{
|
|
314
|
+
throw new TypeError("Invalid search action registration");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function isRecord(value: unknown): value is Record<string, unknown>
|
|
319
|
+
{
|
|
320
|
+
return typeof value === "object" && value !== null;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function isAttempt(value: unknown): value is SearchResolutionAttempt
|
|
324
|
+
{
|
|
325
|
+
if (typeof value !== "object" || value === null || !("kind" in value))
|
|
326
|
+
{
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const kind = (value as { kind?: unknown; }).kind;
|
|
331
|
+
return kind === "not-handled" || (kind === "resolved" && "payload" in value)
|
|
332
|
+
|| (kind === "failed" && "error" in value);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function isAgentToolResult(value: unknown): value is AgentToolResult<unknown>
|
|
336
|
+
{
|
|
337
|
+
return typeof value === "object" && value !== null && Array.isArray((value as { content?: unknown; }).content);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function failure(
|
|
341
|
+
code: NonNullable<SearchToolDetails["failure"]>["code"],
|
|
342
|
+
message: string,
|
|
343
|
+
resolverId?: string,
|
|
344
|
+
cause?: unknown,
|
|
345
|
+
): AgentToolResult<SearchToolDetails>
|
|
346
|
+
{
|
|
347
|
+
return {
|
|
348
|
+
content: [{ type: "text", text: message }],
|
|
349
|
+
details: {
|
|
350
|
+
failure: {
|
|
351
|
+
code,
|
|
352
|
+
message,
|
|
353
|
+
...(resolverId === undefined ? {} : { resolverId }),
|
|
354
|
+
...(cause === undefined ? {} : { cause }),
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function normalizeDescriptionSource(value: unknown): SearchDescriptionSource
|
|
361
|
+
{
|
|
362
|
+
if (typeof value === "function")
|
|
363
|
+
{
|
|
364
|
+
return value as () => string | undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
368
|
+
{
|
|
369
|
+
throw new TypeError("Search description must not be empty");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return value.trim();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function renderDescription(source: SearchDescriptionSource): string | undefined
|
|
376
|
+
{
|
|
377
|
+
const value = typeof source === "function" ? source() : source;
|
|
378
|
+
|
|
379
|
+
if (value === undefined)
|
|
380
|
+
{
|
|
381
|
+
return undefined;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
385
|
+
{
|
|
386
|
+
throw new TypeError("Search description must not be empty");
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return value.trim();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function actionKey(resolverId: string, capability: string): string
|
|
393
|
+
{
|
|
394
|
+
return `${resolverId}:${capability}`;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function messageFor(error: unknown, fallback: string): string
|
|
398
|
+
{
|
|
399
|
+
return error instanceof Error && error.message.trim().length > 0 ? `${fallback}: ${error.message}` : fallback;
|
|
400
|
+
}
|
|
@@ -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
|
+
}
|