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,499 @@
|
|
|
1
|
+
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { CONFIG_DIR_NAME, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
import { isAllowedProviderBaseUrl } from "./providers/endpoints.ts";
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
CodexSearchMode,
|
|
10
|
+
ConfigLoadResult,
|
|
11
|
+
JsonObject,
|
|
12
|
+
JsonValue,
|
|
13
|
+
ProviderValidationResult,
|
|
14
|
+
RoutingStrategy,
|
|
15
|
+
SearchContextSize,
|
|
16
|
+
SearchProvider,
|
|
17
|
+
SearchProviderConfig,
|
|
18
|
+
SearchProviderEntry,
|
|
19
|
+
SearchUserLocation,
|
|
20
|
+
WebsearchConfig,
|
|
21
|
+
} from "./types.ts";
|
|
22
|
+
|
|
23
|
+
export const SEARCH_PROVIDERS: readonly SearchProvider[] = [
|
|
24
|
+
"exa",
|
|
25
|
+
"tavily",
|
|
26
|
+
"brave",
|
|
27
|
+
"duckduckgo-html",
|
|
28
|
+
"serper",
|
|
29
|
+
"parallel",
|
|
30
|
+
"google-cse",
|
|
31
|
+
"z-ai",
|
|
32
|
+
"openai",
|
|
33
|
+
"codex",
|
|
34
|
+
"anthropic",
|
|
35
|
+
"perplexity",
|
|
36
|
+
"xai",
|
|
37
|
+
"kimi",
|
|
38
|
+
];
|
|
39
|
+
const CONTEXT_SIZES: readonly SearchContextSize[] = ["low", "medium", "high"];
|
|
40
|
+
const CODEX_MODES: readonly CodexSearchMode[] = ["cached", "live"];
|
|
41
|
+
const STRATEGIES: readonly RoutingStrategy[] = ["priority", "round-robin", "fill-first"];
|
|
42
|
+
const DEFAULT_MAX_RESULTS = 10;
|
|
43
|
+
const DEFAULT_FREE_CONFIG: WebsearchConfig = {
|
|
44
|
+
strategy: "priority",
|
|
45
|
+
fallback: true,
|
|
46
|
+
providers: [{ id: "default", provider: "duckduckgo-html", maxResults: DEFAULT_MAX_RESULTS }],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export interface ConfigLoadOptions
|
|
50
|
+
{
|
|
51
|
+
cwd: string;
|
|
52
|
+
piRoot?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isJsonObject(value: unknown): value is JsonObject
|
|
56
|
+
{
|
|
57
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function oneOf<TValue extends string>(values: readonly TValue[], value: unknown): value is TValue
|
|
61
|
+
{
|
|
62
|
+
return typeof value === "string" && (values as readonly string[]).includes(value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isStringArray(value: JsonValue | undefined): value is string[]
|
|
66
|
+
{
|
|
67
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function optionalString(value: JsonValue | undefined): string | undefined
|
|
71
|
+
{
|
|
72
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function optionalNumber(value: JsonValue | undefined): number | undefined
|
|
76
|
+
{
|
|
77
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function optionalBoolean(value: JsonValue | undefined): boolean | undefined
|
|
81
|
+
{
|
|
82
|
+
return typeof value === "boolean" ? value : undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function optionalProvider(value: JsonValue | undefined): SearchProvider | undefined
|
|
86
|
+
{
|
|
87
|
+
return oneOf(SEARCH_PROVIDERS, value) ? value : undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function optionalContextSize(value: JsonValue | undefined): SearchContextSize | undefined
|
|
91
|
+
{
|
|
92
|
+
return oneOf(CONTEXT_SIZES, value) ? value : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function optionalCodexMode(value: JsonValue | undefined): CodexSearchMode | undefined
|
|
96
|
+
{
|
|
97
|
+
return oneOf(CODEX_MODES, value) ? value : undefined;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function optionalStrategy(value: JsonValue | undefined): RoutingStrategy | undefined
|
|
101
|
+
{
|
|
102
|
+
return oneOf(STRATEGIES, value) ? value : undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function optionalLocation(value: JsonValue | undefined): SearchUserLocation | undefined
|
|
106
|
+
{
|
|
107
|
+
if (!isJsonObject(value))
|
|
108
|
+
{
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const location: SearchUserLocation = {};
|
|
113
|
+
const country = optionalString(value.country);
|
|
114
|
+
const region = optionalString(value.region);
|
|
115
|
+
const city = optionalString(value.city);
|
|
116
|
+
const timezone = optionalString(value.timezone);
|
|
117
|
+
|
|
118
|
+
if (country)
|
|
119
|
+
{
|
|
120
|
+
location.country = country;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (region)
|
|
124
|
+
{
|
|
125
|
+
location.region = region;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (city)
|
|
129
|
+
{
|
|
130
|
+
location.city = city;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (timezone)
|
|
134
|
+
{
|
|
135
|
+
location.timezone = timezone;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return Object.keys(location).length > 0 ? location : undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function normalizedProviderOrder(values: readonly string[]): string[] | undefined
|
|
142
|
+
{
|
|
143
|
+
const order: string[] = [];
|
|
144
|
+
const seen = new Set<string>();
|
|
145
|
+
|
|
146
|
+
for (const value of values)
|
|
147
|
+
{
|
|
148
|
+
const trimmed = value.trim();
|
|
149
|
+
const normalized = trimmed.toLowerCase();
|
|
150
|
+
|
|
151
|
+
if (!trimmed || seen.has(normalized))
|
|
152
|
+
{
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
seen.add(normalized);
|
|
157
|
+
order.push(trimmed);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return order.length > 0 ? order : undefined;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function optionalProviderOrder(value: JsonValue | undefined): string[] | undefined
|
|
164
|
+
{
|
|
165
|
+
return isStringArray(value) ? normalizedProviderOrder(value) : undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function matchesProviderOrder(provider: SearchProviderEntry, selector: string): boolean
|
|
169
|
+
{
|
|
170
|
+
const normalized = selector.trim().toLowerCase();
|
|
171
|
+
return provider.provider.toLowerCase() === normalized || provider.id?.toLowerCase() === normalized;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function applyProviderOrder(
|
|
175
|
+
providers: SearchProviderEntry[],
|
|
176
|
+
providerOrder?: readonly string[],
|
|
177
|
+
): SearchProviderEntry[]
|
|
178
|
+
{
|
|
179
|
+
if (!providerOrder?.length)
|
|
180
|
+
{
|
|
181
|
+
return providers;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const remaining = [...providers];
|
|
185
|
+
const ordered: SearchProviderEntry[] = [];
|
|
186
|
+
|
|
187
|
+
for (const selector of providerOrder)
|
|
188
|
+
{
|
|
189
|
+
const index = remaining.findIndex((provider) => matchesProviderOrder(provider, selector));
|
|
190
|
+
|
|
191
|
+
if (index !== -1)
|
|
192
|
+
{
|
|
193
|
+
ordered.push(...remaining.splice(index, 1));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return [...ordered, ...remaining];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function parseJsonObject(content: string): JsonObject | null
|
|
201
|
+
{
|
|
202
|
+
let parsed: unknown;
|
|
203
|
+
|
|
204
|
+
try
|
|
205
|
+
{
|
|
206
|
+
parsed = JSON.parse(content);
|
|
207
|
+
}
|
|
208
|
+
catch
|
|
209
|
+
{
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return isJsonObject(parsed) ? parsed : null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function providerEntryFromObject(raw: JsonObject): SearchProviderEntry | null
|
|
217
|
+
{
|
|
218
|
+
const provider = optionalProvider(raw.provider);
|
|
219
|
+
|
|
220
|
+
if (!provider)
|
|
221
|
+
{
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const config: SearchProviderEntry = { provider };
|
|
226
|
+
const id = optionalString(raw.id);
|
|
227
|
+
const apiKey = optionalString(raw.apiKey);
|
|
228
|
+
const baseUrl = optionalString(raw.baseUrl);
|
|
229
|
+
const searchEngineId = optionalString(raw.searchEngineId);
|
|
230
|
+
const maxResults = optionalNumber(raw.maxResults);
|
|
231
|
+
const model = optionalString(raw.model);
|
|
232
|
+
const codexMode = optionalCodexMode(raw.codexMode);
|
|
233
|
+
const searchContextSize = optionalContextSize(raw.searchContextSize);
|
|
234
|
+
const rawAllowedDomains = raw.allowedDomains;
|
|
235
|
+
const rawBlockedDomains = raw.blockedDomains;
|
|
236
|
+
const allowedDomains = isStringArray(rawAllowedDomains) ? rawAllowedDomains : undefined;
|
|
237
|
+
const blockedDomains = isStringArray(rawBlockedDomains) ? rawBlockedDomains : undefined;
|
|
238
|
+
const userLocation = optionalLocation(raw.userLocation);
|
|
239
|
+
const priority = optionalNumber(raw.priority);
|
|
240
|
+
const weight = optionalNumber(raw.weight);
|
|
241
|
+
|
|
242
|
+
if (id)
|
|
243
|
+
{
|
|
244
|
+
config.id = id;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (apiKey)
|
|
248
|
+
{
|
|
249
|
+
config.apiKey = apiKey;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (baseUrl)
|
|
253
|
+
{
|
|
254
|
+
config.baseUrl = baseUrl;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (searchEngineId)
|
|
258
|
+
{
|
|
259
|
+
config.searchEngineId = searchEngineId;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (maxResults)
|
|
263
|
+
{
|
|
264
|
+
config.maxResults = maxResults;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (model)
|
|
268
|
+
{
|
|
269
|
+
config.model = model;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (codexMode)
|
|
273
|
+
{
|
|
274
|
+
config.codexMode = codexMode;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (searchContextSize)
|
|
278
|
+
{
|
|
279
|
+
config.searchContextSize = searchContextSize;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (allowedDomains)
|
|
283
|
+
{
|
|
284
|
+
config.allowedDomains = allowedDomains;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (blockedDomains)
|
|
288
|
+
{
|
|
289
|
+
config.blockedDomains = blockedDomains;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (userLocation)
|
|
293
|
+
{
|
|
294
|
+
config.userLocation = userLocation;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (priority !== undefined)
|
|
298
|
+
{
|
|
299
|
+
config.priority = priority;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (weight !== undefined)
|
|
303
|
+
{
|
|
304
|
+
config.weight = weight;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return config;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function configFromObject(raw: JsonObject): WebsearchConfig | null
|
|
311
|
+
{
|
|
312
|
+
const strategy = optionalStrategy(raw.strategy) ?? "priority";
|
|
313
|
+
const fallback = optionalBoolean(raw.fallback) ?? true;
|
|
314
|
+
const providerOrder = optionalProviderOrder(raw.providerOrder);
|
|
315
|
+
const providersValue = raw.providers;
|
|
316
|
+
const rawProviders = Array.isArray(providersValue) ? providersValue : undefined;
|
|
317
|
+
|
|
318
|
+
if (rawProviders)
|
|
319
|
+
{
|
|
320
|
+
if (optionalProvider(raw.provider))
|
|
321
|
+
{
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const providers = rawProviders
|
|
326
|
+
.map((value) => (isJsonObject(value) ? providerEntryFromObject(value) : null))
|
|
327
|
+
.filter((entry): entry is SearchProviderEntry => entry !== null);
|
|
328
|
+
const orderedProviders = applyProviderOrder(providers, providerOrder);
|
|
329
|
+
return { strategy, fallback, providers: orderedProviders, ...(providerOrder ? { providerOrder } : {}) };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const provider = providerEntryFromObject(raw);
|
|
333
|
+
|
|
334
|
+
if (provider)
|
|
335
|
+
{
|
|
336
|
+
return { strategy, fallback, providers: [provider], ...(providerOrder ? { providerOrder } : {}) };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (providerOrder || raw.strategy !== undefined || raw.fallback !== undefined)
|
|
340
|
+
{
|
|
341
|
+
return { strategy, fallback, providers: [], ...(providerOrder ? { providerOrder } : {}) };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function hasApiKey(config: SearchProviderConfig): boolean
|
|
348
|
+
{
|
|
349
|
+
return typeof config.apiKey === "string" && config.apiKey.length > 0;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function validateProviderConfig(config: SearchProviderEntry): ProviderValidationResult
|
|
353
|
+
{
|
|
354
|
+
if (!SEARCH_PROVIDERS.includes(config.provider))
|
|
355
|
+
{
|
|
356
|
+
return { ok: false, reason: "invalid_config", message: `Unsupported provider: ${config.provider}` };
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (config.allowedDomains && config.blockedDomains)
|
|
360
|
+
{
|
|
361
|
+
return {
|
|
362
|
+
ok: false,
|
|
363
|
+
reason: "invalid_config",
|
|
364
|
+
message: "Provider config cannot specify both allowedDomains and blockedDomains.",
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (config.weight !== undefined && config.weight <= 0)
|
|
369
|
+
{
|
|
370
|
+
return { ok: false, reason: "invalid_config", message: "Provider weight must be greater than 0." };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (config.baseUrl && !isAllowedProviderBaseUrl(config.baseUrl))
|
|
374
|
+
{
|
|
375
|
+
return {
|
|
376
|
+
ok: false,
|
|
377
|
+
reason: "invalid_config",
|
|
378
|
+
message: `Provider ${config.provider} baseUrl must be a public HTTPS URL without credentials.`,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (config.provider === "google-cse" && !config.searchEngineId)
|
|
383
|
+
{
|
|
384
|
+
return { ok: false, reason: "missing_api_key", message: "Provider google-cse requires searchEngineId." };
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if ((config.provider === "codex" || config.provider === "openai") && !hasApiKey(config))
|
|
388
|
+
{
|
|
389
|
+
return {
|
|
390
|
+
ok: false,
|
|
391
|
+
reason: "missing_api_key",
|
|
392
|
+
message: `Provider ${config.provider} requires apiKey for hosted Responses API search.`,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (
|
|
397
|
+
config.provider !== "codex"
|
|
398
|
+
&& config.provider !== "openai"
|
|
399
|
+
&& config.provider !== "duckduckgo-html"
|
|
400
|
+
&& !hasApiKey(config)
|
|
401
|
+
)
|
|
402
|
+
{
|
|
403
|
+
return { ok: false, reason: "missing_api_key", message: `Provider ${config.provider} requires apiKey.` };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return { ok: true, config };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function validateWebsearchConfig(
|
|
410
|
+
config: WebsearchConfig,
|
|
411
|
+
): ProviderValidationResult | { ok: true; config: WebsearchConfig; }
|
|
412
|
+
{
|
|
413
|
+
if (!STRATEGIES.includes(config.strategy))
|
|
414
|
+
{
|
|
415
|
+
return { ok: false, reason: "invalid_config", message: `Unsupported routing strategy: ${config.strategy}` };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (config.providers.length === 0)
|
|
419
|
+
{
|
|
420
|
+
return { ok: false, reason: "invalid_config", message: "Websearch config requires at least one provider." };
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
for (const provider of config.providers)
|
|
424
|
+
{
|
|
425
|
+
const validation = validateProviderConfig(provider);
|
|
426
|
+
|
|
427
|
+
if (!validation.ok)
|
|
428
|
+
{
|
|
429
|
+
return validation;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return { ok: true, config };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async function fileExists(path: string): Promise<boolean>
|
|
437
|
+
{
|
|
438
|
+
try
|
|
439
|
+
{
|
|
440
|
+
await access(path);
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
catch
|
|
444
|
+
{
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
export async function loadWebsearchConfig(options: ConfigLoadOptions): Promise<ConfigLoadResult>
|
|
450
|
+
{
|
|
451
|
+
const piRoot = options.piRoot ?? path.dirname(getAgentDir());
|
|
452
|
+
const configPaths = [
|
|
453
|
+
path.join(options.cwd, CONFIG_DIR_NAME, "websearch.json"),
|
|
454
|
+
path.join(piRoot, "websearch.json"),
|
|
455
|
+
];
|
|
456
|
+
|
|
457
|
+
for (const configPath of configPaths)
|
|
458
|
+
{
|
|
459
|
+
if (!(await fileExists(configPath)))
|
|
460
|
+
{
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const raw = parseJsonObject(await readFile(configPath, "utf8"));
|
|
465
|
+
|
|
466
|
+
if (!raw)
|
|
467
|
+
{
|
|
468
|
+
return {
|
|
469
|
+
ok: false,
|
|
470
|
+
reason: "invalid_config",
|
|
471
|
+
message: `Invalid JSON object in ${configPath}`,
|
|
472
|
+
source: configPath,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const config = configFromObject(raw);
|
|
477
|
+
|
|
478
|
+
if (!config)
|
|
479
|
+
{
|
|
480
|
+
return {
|
|
481
|
+
ok: false,
|
|
482
|
+
reason: "invalid_config",
|
|
483
|
+
message: `Invalid provider config in ${configPath}`,
|
|
484
|
+
source: configPath,
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const validation = validateWebsearchConfig(config);
|
|
489
|
+
|
|
490
|
+
if (!validation.ok)
|
|
491
|
+
{
|
|
492
|
+
return { ...validation, source: configPath };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return { ok: true, config, source: configPath };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return { ok: true, config: DEFAULT_FREE_CONFIG, source: "default:duckduckgo-html" };
|
|
499
|
+
}
|
package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { SearchResultItem } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
function result(title: string | undefined, url: string | undefined, snippet?: string): SearchResultItem | null
|
|
4
|
+
{
|
|
5
|
+
if (!title || !url)
|
|
6
|
+
{
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const item: SearchResultItem = { title, url };
|
|
11
|
+
|
|
12
|
+
if (snippet)
|
|
13
|
+
{
|
|
14
|
+
item.snippet = snippet;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return item;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function collect(items: (SearchResultItem | null)[], max = 50): SearchResultItem[]
|
|
21
|
+
{
|
|
22
|
+
return items.filter((item): item is SearchResultItem => item !== null).slice(0, max);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function htmlDecode(value: string): string
|
|
26
|
+
{
|
|
27
|
+
return value
|
|
28
|
+
.replaceAll("&", "&")
|
|
29
|
+
.replaceAll(""", "\"")
|
|
30
|
+
.replaceAll("'", "'")
|
|
31
|
+
.replaceAll("<", "<")
|
|
32
|
+
.replaceAll(">", ">");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function stripHtml(value: string): string
|
|
36
|
+
{
|
|
37
|
+
return htmlDecode(
|
|
38
|
+
value
|
|
39
|
+
.replace(/<[^>]*>/g, "")
|
|
40
|
+
.replace(/\s+/g, " ")
|
|
41
|
+
.trim(),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function duckDuckGoResultUrl(rawHref: string): string | undefined
|
|
46
|
+
{
|
|
47
|
+
const decodedHref = htmlDecode(rawHref);
|
|
48
|
+
const absoluteHref = decodedHref.startsWith("//") ? `https:${decodedHref}` : decodedHref;
|
|
49
|
+
let url: URL;
|
|
50
|
+
|
|
51
|
+
try
|
|
52
|
+
{
|
|
53
|
+
url = new URL(absoluteHref);
|
|
54
|
+
}
|
|
55
|
+
catch
|
|
56
|
+
{
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const redirected = url.searchParams.get("uddg");
|
|
61
|
+
return redirected ?? absoluteHref;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function normalizeDuckDuckGoHtml(html: string): SearchResultItem[]
|
|
65
|
+
{
|
|
66
|
+
const matches = [...html.matchAll(/<a\b[^>]*class="[^"]*result__a[^"]*"[^>]*href="([^"]+)"[^>]*>([\s\S]*?)<\/a>/g)];
|
|
67
|
+
const snippets = [...html.matchAll(/<a\b[^>]*class="[^"]*result__snippet[^"]*"[^>]*>([\s\S]*?)<\/a>/g)].map(
|
|
68
|
+
(match) => stripHtml(match[1] ?? ""),
|
|
69
|
+
);
|
|
70
|
+
return collect(
|
|
71
|
+
matches.map((match, index) =>
|
|
72
|
+
{
|
|
73
|
+
const title = stripHtml(match[2] ?? "");
|
|
74
|
+
const url = duckDuckGoResultUrl(match[1] ?? "");
|
|
75
|
+
return result(title, url, snippets[index]);
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { SearchProvider, SearchProviderConfig } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_PROVIDER_URLS: Record<SearchProvider, string> = {
|
|
4
|
+
exa: "https://api.exa.ai/search",
|
|
5
|
+
tavily: "https://api.tavily.com/search",
|
|
6
|
+
brave: "https://api.search.brave.com/res/v1/web/search",
|
|
7
|
+
"duckduckgo-html": "https://html.duckduckgo.com/html/",
|
|
8
|
+
serper: "https://google.serper.dev/search",
|
|
9
|
+
parallel: "https://api.parallel.ai/v1/search",
|
|
10
|
+
"google-cse": "https://customsearch.googleapis.com/customsearch/v1",
|
|
11
|
+
"z-ai": "https://api.z.ai/api/paas/v4/web_search",
|
|
12
|
+
openai: "https://api.openai.com/v1/responses",
|
|
13
|
+
codex: "https://api.openai.com/v1/responses",
|
|
14
|
+
anthropic: "https://api.anthropic.com/v1/messages",
|
|
15
|
+
perplexity: "https://api.perplexity.ai/search",
|
|
16
|
+
xai: "https://api.x.ai/v1/responses",
|
|
17
|
+
kimi: "https://api.kimi.com/coding/v1/search",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function defaultProviderUrl(provider: SearchProvider): string
|
|
21
|
+
{
|
|
22
|
+
return DEFAULT_PROVIDER_URLS[provider];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isPrivateIpv4(hostname: string): boolean
|
|
26
|
+
{
|
|
27
|
+
const parts = hostname.split(".").map((part) => Number.parseInt(part, 10));
|
|
28
|
+
|
|
29
|
+
if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255))
|
|
30
|
+
{
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const first = parts[0] ?? -1;
|
|
35
|
+
const second = parts[1] ?? -1;
|
|
36
|
+
|
|
37
|
+
if (first === 10 || first === 127 || first === 0 || (first === 169 && second === 254))
|
|
38
|
+
{
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (first === 172 && second >= 16 && second <= 31)
|
|
43
|
+
{
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return first === 192 && second === 168;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isPrivateHostname(hostname: string): boolean
|
|
51
|
+
{
|
|
52
|
+
const normalized = hostname.toLowerCase().replace(/^\[/, "").replace(/\]$/, "");
|
|
53
|
+
return (
|
|
54
|
+
normalized === "localhost"
|
|
55
|
+
|| normalized.endsWith(".localhost")
|
|
56
|
+
|| normalized.includes(":")
|
|
57
|
+
|| normalized === "::1"
|
|
58
|
+
|| normalized.startsWith("fc")
|
|
59
|
+
|| normalized.startsWith("fd")
|
|
60
|
+
|| /^fe[89ab][0-9a-f]:/.test(normalized)
|
|
61
|
+
|| isPrivateIpv4(normalized)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isAllowedProviderBaseUrl(baseUrl: string): boolean
|
|
66
|
+
{
|
|
67
|
+
let configured: URL;
|
|
68
|
+
|
|
69
|
+
try
|
|
70
|
+
{
|
|
71
|
+
configured = new URL(baseUrl);
|
|
72
|
+
}
|
|
73
|
+
catch
|
|
74
|
+
{
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
configured.protocol === "https:"
|
|
80
|
+
&& configured.username === ""
|
|
81
|
+
&& configured.password === ""
|
|
82
|
+
&& !isPrivateHostname(configured.hostname)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function providerUrl(config: SearchProviderConfig): string
|
|
87
|
+
{
|
|
88
|
+
return config.baseUrl ?? defaultProviderUrl(config.provider);
|
|
89
|
+
}
|