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,105 @@
|
|
|
1
|
+
export type ChangeState = "partial" | "staged" | "unstaged";
|
|
2
|
+
|
|
3
|
+
export type ChangeUnavailableReason =
|
|
4
|
+
| "binary"
|
|
5
|
+
| "conflicted"
|
|
6
|
+
| "head-file-lookup-failed"
|
|
7
|
+
| "index-file-lookup-failed"
|
|
8
|
+
| "index-write-failed"
|
|
9
|
+
| "missing-head"
|
|
10
|
+
| "no-worktree"
|
|
11
|
+
| "outside-worktree";
|
|
12
|
+
|
|
13
|
+
export interface ChangeSegment
|
|
14
|
+
{
|
|
15
|
+
readonly headText: string;
|
|
16
|
+
readonly indexText: string;
|
|
17
|
+
readonly worktreeText: string;
|
|
18
|
+
readonly headStart: number;
|
|
19
|
+
readonly headEnd: number;
|
|
20
|
+
readonly indexStart: number;
|
|
21
|
+
readonly indexEnd: number;
|
|
22
|
+
readonly currentStart: number;
|
|
23
|
+
readonly currentEnd: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ChangeGroup
|
|
27
|
+
{
|
|
28
|
+
readonly selector: string;
|
|
29
|
+
readonly digest: string;
|
|
30
|
+
readonly duplicateOrder: number;
|
|
31
|
+
readonly repositoryPath: string;
|
|
32
|
+
readonly state: ChangeState;
|
|
33
|
+
readonly currentStartLine: number;
|
|
34
|
+
readonly currentEndLine: number;
|
|
35
|
+
readonly contextBefore: readonly string[];
|
|
36
|
+
readonly contextAfter: readonly string[];
|
|
37
|
+
readonly canonicalContent: string;
|
|
38
|
+
readonly segments: readonly ChangeSegment[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ChangeInspection =
|
|
42
|
+
| {
|
|
43
|
+
readonly status: "applicable";
|
|
44
|
+
readonly head: string;
|
|
45
|
+
readonly repositoryRoot: string;
|
|
46
|
+
readonly repositoryPath: string;
|
|
47
|
+
readonly groups: readonly ChangeGroup[];
|
|
48
|
+
}
|
|
49
|
+
| {
|
|
50
|
+
readonly status: "not-applicable";
|
|
51
|
+
readonly reason: "clean" | "untracked";
|
|
52
|
+
}
|
|
53
|
+
| {
|
|
54
|
+
readonly status: "unavailable";
|
|
55
|
+
readonly reason: ChangeUnavailableReason;
|
|
56
|
+
readonly message: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export interface ChangeInspectionInput
|
|
60
|
+
{
|
|
61
|
+
readonly source: string;
|
|
62
|
+
readonly worktreeText: string;
|
|
63
|
+
readonly cwd: string;
|
|
64
|
+
readonly signal?: AbortSignal;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ChangeIndexAction = "stage" | "unstage";
|
|
68
|
+
|
|
69
|
+
export interface GitIndexUpdate
|
|
70
|
+
{
|
|
71
|
+
readonly head: string;
|
|
72
|
+
readonly repositoryPath: string;
|
|
73
|
+
readonly headStart: number;
|
|
74
|
+
readonly headEnd: number;
|
|
75
|
+
readonly replacementText: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type ChangeIndexResult =
|
|
79
|
+
| {
|
|
80
|
+
readonly status: "applied" | "unchanged";
|
|
81
|
+
readonly state: "staged" | "unstaged";
|
|
82
|
+
readonly group: ChangeGroup;
|
|
83
|
+
}
|
|
84
|
+
| Exclude<ChangeInspection, { readonly status: "applicable"; }>
|
|
85
|
+
| {
|
|
86
|
+
readonly status: "unavailable";
|
|
87
|
+
readonly reason: "stale-selector";
|
|
88
|
+
readonly message: string;
|
|
89
|
+
readonly availableSelectors: readonly string[];
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type PreparedUndoResult =
|
|
93
|
+
| {
|
|
94
|
+
readonly status: "applied";
|
|
95
|
+
readonly worktreeText: string;
|
|
96
|
+
readonly group: ChangeGroup;
|
|
97
|
+
readonly indexUpdate?: GitIndexUpdate;
|
|
98
|
+
}
|
|
99
|
+
| Exclude<ChangeInspection, { readonly status: "applicable"; }>
|
|
100
|
+
| {
|
|
101
|
+
readonly status: "unavailable";
|
|
102
|
+
readonly reason: "stale-selector";
|
|
103
|
+
readonly message: string;
|
|
104
|
+
readonly availableSelectors: readonly string[];
|
|
105
|
+
};
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
export interface GitCommandResult
|
|
8
|
+
{
|
|
9
|
+
readonly code: number;
|
|
10
|
+
readonly stdout: string;
|
|
11
|
+
readonly stderr: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface GitCommandExecutor
|
|
15
|
+
{
|
|
16
|
+
exec(
|
|
17
|
+
command: string,
|
|
18
|
+
args: string[],
|
|
19
|
+
options: { readonly cwd: string; readonly signal?: AbortSignal; },
|
|
20
|
+
): Promise<GitCommandResult>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type GitChangesBackendCreation =
|
|
24
|
+
| { readonly status: "ready"; readonly backend: GitChangesBackend; }
|
|
25
|
+
| { readonly status: "unavailable"; readonly reason: "no-worktree"; readonly message: string; };
|
|
26
|
+
|
|
27
|
+
export interface TrackedFileVersions
|
|
28
|
+
{
|
|
29
|
+
readonly status: "found";
|
|
30
|
+
readonly head: string;
|
|
31
|
+
readonly repositoryPath: string;
|
|
32
|
+
readonly repositoryRoot: string;
|
|
33
|
+
readonly headText: string;
|
|
34
|
+
readonly indexText: string;
|
|
35
|
+
readonly indexMode: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TrackedFileLookup =
|
|
39
|
+
| TrackedFileVersions
|
|
40
|
+
| { readonly status: "untracked"; }
|
|
41
|
+
| {
|
|
42
|
+
readonly status: "unavailable";
|
|
43
|
+
readonly reason:
|
|
44
|
+
| "conflicted"
|
|
45
|
+
| "head-file-lookup-failed"
|
|
46
|
+
| "index-file-lookup-failed"
|
|
47
|
+
| "missing-head"
|
|
48
|
+
| "outside-worktree";
|
|
49
|
+
readonly message: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
interface GitTreeEntry
|
|
53
|
+
{
|
|
54
|
+
readonly mode: string;
|
|
55
|
+
readonly blob: string;
|
|
56
|
+
readonly path: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface GitIndexEntry extends GitTreeEntry
|
|
60
|
+
{
|
|
61
|
+
readonly stage: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class GitChangesBackend
|
|
65
|
+
{
|
|
66
|
+
static async create(
|
|
67
|
+
executor: GitCommandExecutor,
|
|
68
|
+
cwd: string,
|
|
69
|
+
signal?: AbortSignal,
|
|
70
|
+
): Promise<GitChangesBackendCreation>
|
|
71
|
+
{
|
|
72
|
+
const result = await executor.exec("git", ["rev-parse", "--show-toplevel"], {
|
|
73
|
+
cwd,
|
|
74
|
+
...(signal === undefined ? {} : { signal }),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (result.code !== 0)
|
|
78
|
+
{
|
|
79
|
+
return {
|
|
80
|
+
status: "unavailable",
|
|
81
|
+
reason: "no-worktree",
|
|
82
|
+
message: result.stderr.trim() || "not inside a Git worktree",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return { status: "ready", backend: new GitChangesBackend(executor, path.resolve(result.stdout.trim())) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private constructor(
|
|
90
|
+
private readonly executor: GitCommandExecutor,
|
|
91
|
+
readonly repositoryRoot: string,
|
|
92
|
+
)
|
|
93
|
+
{}
|
|
94
|
+
|
|
95
|
+
async readTrackedFile(source: string, cwd: string, signal?: AbortSignal): Promise<TrackedFileLookup>
|
|
96
|
+
{
|
|
97
|
+
const absoluteSource = path.resolve(cwd, source);
|
|
98
|
+
const repositoryPath = path.relative(this.repositoryRoot, absoluteSource);
|
|
99
|
+
|
|
100
|
+
if (repositoryPath === ".." || repositoryPath.startsWith(`..${path.sep}`) || path.isAbsolute(repositoryPath))
|
|
101
|
+
{
|
|
102
|
+
return {
|
|
103
|
+
status: "unavailable",
|
|
104
|
+
reason: "outside-worktree",
|
|
105
|
+
message: `${absoluteSource} is outside ${this.repositoryRoot}`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return this.readTrackedRepositoryFile(repositoryPath.split(path.sep).join("/"), signal);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async readTrackedRepositoryFile(repositoryPath: string, signal?: AbortSignal): Promise<TrackedFileLookup>
|
|
113
|
+
{
|
|
114
|
+
const head = await this.git(["rev-parse", "--verify", "HEAD"], signal);
|
|
115
|
+
|
|
116
|
+
if (head.code !== 0)
|
|
117
|
+
{
|
|
118
|
+
return {
|
|
119
|
+
status: "unavailable",
|
|
120
|
+
reason: "missing-head",
|
|
121
|
+
message: head.stderr.trim() || "Git HEAD does not exist",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const tree = await this.git(["--literal-pathspecs", "ls-tree", "-z", "HEAD", "--", repositoryPath], signal);
|
|
126
|
+
|
|
127
|
+
if (tree.code !== 0)
|
|
128
|
+
{
|
|
129
|
+
return {
|
|
130
|
+
status: "unavailable",
|
|
131
|
+
reason: "head-file-lookup-failed",
|
|
132
|
+
message: tree.stderr.trim() || `could not inspect HEAD:${repositoryPath}`,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const headEntry = parseTreeEntry(tree.stdout);
|
|
137
|
+
|
|
138
|
+
if (headEntry === undefined)
|
|
139
|
+
{
|
|
140
|
+
return { status: "untracked" };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const headBlob = await this.readBlob(headEntry.blob, "HEAD", repositoryPath, signal);
|
|
144
|
+
|
|
145
|
+
if (headBlob.status !== "found")
|
|
146
|
+
{
|
|
147
|
+
return headBlob;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const index = await this.git(
|
|
151
|
+
["--literal-pathspecs", "ls-files", "--stage", "-z", "--", repositoryPath],
|
|
152
|
+
signal,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
if (index.code !== 0)
|
|
156
|
+
{
|
|
157
|
+
return {
|
|
158
|
+
status: "unavailable",
|
|
159
|
+
reason: "index-file-lookup-failed",
|
|
160
|
+
message: index.stderr.trim() || `could not inspect the index entry for ${repositoryPath}`,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const indexEntries = parseIndexEntries(index.stdout);
|
|
165
|
+
|
|
166
|
+
if (indexEntries.some(({ stage }) => stage !== 0))
|
|
167
|
+
{
|
|
168
|
+
return {
|
|
169
|
+
status: "unavailable",
|
|
170
|
+
reason: "conflicted",
|
|
171
|
+
message: `${repositoryPath} has unresolved Git index entries`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const indexEntry = indexEntries.find(({ stage }) => stage === 0);
|
|
176
|
+
let indexText = "";
|
|
177
|
+
|
|
178
|
+
if (indexEntry !== undefined)
|
|
179
|
+
{
|
|
180
|
+
const indexBlob = await this.readBlob(indexEntry.blob, "index", repositoryPath, signal);
|
|
181
|
+
|
|
182
|
+
if (indexBlob.status !== "found")
|
|
183
|
+
{
|
|
184
|
+
return indexBlob;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
indexText = indexBlob.text;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
status: "found",
|
|
192
|
+
head: head.stdout.trim(),
|
|
193
|
+
repositoryPath,
|
|
194
|
+
repositoryRoot: this.repositoryRoot,
|
|
195
|
+
headText: headBlob.text,
|
|
196
|
+
indexText,
|
|
197
|
+
indexMode: indexEntry?.mode ?? headEntry.mode,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async writeIndexFile(
|
|
202
|
+
repositoryPath: string,
|
|
203
|
+
mode: string,
|
|
204
|
+
text: string,
|
|
205
|
+
signal?: AbortSignal,
|
|
206
|
+
): Promise<void>
|
|
207
|
+
{
|
|
208
|
+
const temporaryDirectory = await mkdtemp(path.join(os.tmpdir(), "pi-agent-index-"));
|
|
209
|
+
const temporaryFile = path.join(temporaryDirectory, "content");
|
|
210
|
+
|
|
211
|
+
try
|
|
212
|
+
{
|
|
213
|
+
await writeFile(temporaryFile, text, "utf8");
|
|
214
|
+
const blob = await this.git(
|
|
215
|
+
["hash-object", "-w", `--path=${repositoryPath}`, temporaryFile],
|
|
216
|
+
signal,
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
if (blob.code !== 0 || blob.stdout.trim().length === 0)
|
|
220
|
+
{
|
|
221
|
+
throw new Error(blob.stderr.trim() || `could not write a Git blob for ${repositoryPath}`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const update = await this.git(
|
|
225
|
+
["update-index", "--add", "--cacheinfo", mode, blob.stdout.trim(), repositoryPath],
|
|
226
|
+
signal,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
if (update.code !== 0)
|
|
230
|
+
{
|
|
231
|
+
throw new Error(update.stderr.trim() || `could not update the Git index entry for ${repositoryPath}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
finally
|
|
235
|
+
{
|
|
236
|
+
await rm(temporaryDirectory, { recursive: true, force: true });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private async readBlob(
|
|
241
|
+
blob: string,
|
|
242
|
+
source: "HEAD" | "index",
|
|
243
|
+
repositoryPath: string,
|
|
244
|
+
signal?: AbortSignal,
|
|
245
|
+
): Promise<
|
|
246
|
+
| { readonly status: "found"; readonly text: string; }
|
|
247
|
+
| {
|
|
248
|
+
readonly status: "unavailable";
|
|
249
|
+
readonly reason: "head-file-lookup-failed" | "index-file-lookup-failed";
|
|
250
|
+
readonly message: string;
|
|
251
|
+
}
|
|
252
|
+
>
|
|
253
|
+
{
|
|
254
|
+
const result = await this.git(["cat-file", "blob", blob], signal);
|
|
255
|
+
|
|
256
|
+
if (result.code !== 0)
|
|
257
|
+
{
|
|
258
|
+
return {
|
|
259
|
+
status: "unavailable",
|
|
260
|
+
reason: source === "HEAD" ? "head-file-lookup-failed" : "index-file-lookup-failed",
|
|
261
|
+
message: result.stderr.trim() || `could not read ${source}:${repositoryPath}`,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return { status: "found", text: result.stdout };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private git(args: string[], signal?: AbortSignal): Promise<GitCommandResult>
|
|
269
|
+
{
|
|
270
|
+
return this.executor.exec("git", args, {
|
|
271
|
+
cwd: this.repositoryRoot,
|
|
272
|
+
...(signal === undefined ? {} : { signal }),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function parseTreeEntry(output: string): GitTreeEntry | undefined
|
|
278
|
+
{
|
|
279
|
+
const record = output.split("\0", 1)[0];
|
|
280
|
+
|
|
281
|
+
if (record === undefined || record.length === 0)
|
|
282
|
+
{
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const separator = record.indexOf("\t");
|
|
287
|
+
|
|
288
|
+
if (separator === -1)
|
|
289
|
+
{
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const [mode, type, blob] = record.slice(0, separator).split(" ");
|
|
294
|
+
|
|
295
|
+
return mode === undefined || type !== "blob" || blob === undefined
|
|
296
|
+
? undefined
|
|
297
|
+
: { mode, blob, path: record.slice(separator + 1) };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function parseIndexEntries(output: string): GitIndexEntry[]
|
|
301
|
+
{
|
|
302
|
+
return output.split("\0").filter(Boolean).flatMap((record) =>
|
|
303
|
+
{
|
|
304
|
+
const separator = record.indexOf("\t");
|
|
305
|
+
|
|
306
|
+
if (separator === -1)
|
|
307
|
+
{
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const [mode, blob, stageValue] = record.slice(0, separator).split(" ");
|
|
312
|
+
const stage = Number(stageValue);
|
|
313
|
+
|
|
314
|
+
return mode === undefined || blob === undefined || !Number.isInteger(stage)
|
|
315
|
+
? []
|
|
316
|
+
: [{ mode, blob, stage, path: record.slice(separator + 1) }];
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function extensionGitExecutor(pi: ExtensionAPI): GitCommandExecutor
|
|
321
|
+
{
|
|
322
|
+
return {
|
|
323
|
+
exec: (command, args, options) => pi.exec(command, args, options),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { diffLines } from "diff";
|
|
2
|
+
|
|
3
|
+
import { ChangeService } from "#src/changes/change-service.js";
|
|
4
|
+
|
|
5
|
+
import type { ChangeGroup } from "#src/changes/change-types.js";
|
|
6
|
+
import type { GitCommandExecutor } from "#src/changes/git-changes-backend.js";
|
|
7
|
+
import type { PresentedTextRow, TextDocument, TextLine, TextLinePresenter } from "pi-agent-text";
|
|
8
|
+
|
|
9
|
+
const FILESYSTEM_RESOLVER_ID = "filesystem";
|
|
10
|
+
|
|
11
|
+
interface LineHunkPresentation
|
|
12
|
+
{
|
|
13
|
+
readonly before: PresentedTextRow[];
|
|
14
|
+
readonly after: PresentedTextRow[];
|
|
15
|
+
readonly annotations: string[];
|
|
16
|
+
added: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type HunkBoundaryTarget =
|
|
20
|
+
| { readonly kind: "current"; readonly lineNumber: number; }
|
|
21
|
+
| { readonly kind: "synthetic"; readonly rows: PresentedTextRow[]; readonly index: number; };
|
|
22
|
+
|
|
23
|
+
export function createCurrentChangePresenter(executor: GitCommandExecutor): TextLinePresenter
|
|
24
|
+
{
|
|
25
|
+
return {
|
|
26
|
+
id: "current-git-changes",
|
|
27
|
+
async present(document, context)
|
|
28
|
+
{
|
|
29
|
+
if (context.purpose !== "read" || context.resolvedBy !== FILESYSTEM_RESOLVER_ID)
|
|
30
|
+
{
|
|
31
|
+
return document;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const creation = await ChangeService.create(executor, context.cwd, context.signal);
|
|
35
|
+
|
|
36
|
+
if (creation.status !== "ready")
|
|
37
|
+
{
|
|
38
|
+
return document;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const inspection = await creation.service.inspect({
|
|
42
|
+
source: context.source,
|
|
43
|
+
worktreeText: document.content,
|
|
44
|
+
cwd: context.cwd,
|
|
45
|
+
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (inspection.status !== "applicable")
|
|
49
|
+
{
|
|
50
|
+
return document;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return presentChangeGroups(document, inspection.groups);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function presentChangeGroups(document: TextDocument, groups: readonly ChangeGroup[]): TextDocument
|
|
59
|
+
{
|
|
60
|
+
const presentations = new Map<number, LineHunkPresentation>();
|
|
61
|
+
|
|
62
|
+
for (const group of groups)
|
|
63
|
+
{
|
|
64
|
+
presentChangeGroup(document, group, presentations);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...document,
|
|
69
|
+
lines: document.lines.map((line) => presentLine(line, presentations.get(line.lineNumber))),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function presentChangeGroup(
|
|
74
|
+
document: TextDocument,
|
|
75
|
+
group: ChangeGroup,
|
|
76
|
+
presentations: Map<number, LineHunkPresentation>,
|
|
77
|
+
): void
|
|
78
|
+
{
|
|
79
|
+
const segment = group.segments[0]!;
|
|
80
|
+
const parts = diffLines(segment.headText, segment.worktreeText);
|
|
81
|
+
let currentLine = group.currentStartLine;
|
|
82
|
+
let firstTarget: HunkBoundaryTarget | undefined;
|
|
83
|
+
let lastTarget: HunkBoundaryTarget | undefined;
|
|
84
|
+
|
|
85
|
+
for (const part of parts)
|
|
86
|
+
{
|
|
87
|
+
const lines = splitLines(part.value);
|
|
88
|
+
|
|
89
|
+
if (part.removed)
|
|
90
|
+
{
|
|
91
|
+
const placement = placementFor(document, currentLine);
|
|
92
|
+
const output = presentationsFor(presentations, placement.lineNumber);
|
|
93
|
+
const targetRows = placement.after ? output.after : output.before;
|
|
94
|
+
|
|
95
|
+
for (const line of lines)
|
|
96
|
+
{
|
|
97
|
+
const target: HunkBoundaryTarget = {
|
|
98
|
+
kind: "synthetic",
|
|
99
|
+
rows: targetRows,
|
|
100
|
+
index: targetRows.length,
|
|
101
|
+
};
|
|
102
|
+
targetRows.push({ marker: "-", prefix: "|", content: line });
|
|
103
|
+
firstTarget ??= target;
|
|
104
|
+
lastTarget = target;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (part.added)
|
|
111
|
+
{
|
|
112
|
+
for (const _line of lines)
|
|
113
|
+
{
|
|
114
|
+
const output = presentationsFor(presentations, currentLine);
|
|
115
|
+
const target: HunkBoundaryTarget = { kind: "current", lineNumber: currentLine };
|
|
116
|
+
output.added = true;
|
|
117
|
+
firstTarget ??= target;
|
|
118
|
+
lastTarget = target;
|
|
119
|
+
currentLine++;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
currentLine += lines.length;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (firstTarget !== undefined && lastTarget !== undefined)
|
|
129
|
+
{
|
|
130
|
+
const annotation = `${group.selector} · ${group.state}`;
|
|
131
|
+
|
|
132
|
+
if (sameTarget(firstTarget, lastTarget))
|
|
133
|
+
{
|
|
134
|
+
annotateTarget(presentations, firstTarget, `<!-- change: ${annotation} -->`);
|
|
135
|
+
}
|
|
136
|
+
else
|
|
137
|
+
{
|
|
138
|
+
annotateTarget(presentations, firstTarget, `<!-- change-begin: ${annotation} -->`);
|
|
139
|
+
annotateTarget(presentations, lastTarget, `<!-- change-end: ${annotation} -->`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function sameTarget(left: HunkBoundaryTarget, right: HunkBoundaryTarget): boolean
|
|
145
|
+
{
|
|
146
|
+
return left.kind === "current" && right.kind === "current"
|
|
147
|
+
? left.lineNumber === right.lineNumber
|
|
148
|
+
: left.kind === "synthetic" && right.kind === "synthetic"
|
|
149
|
+
? left.rows === right.rows && left.index === right.index
|
|
150
|
+
: false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function annotateTarget(
|
|
154
|
+
presentations: Map<number, LineHunkPresentation>,
|
|
155
|
+
target: HunkBoundaryTarget,
|
|
156
|
+
annotation: string,
|
|
157
|
+
): void
|
|
158
|
+
{
|
|
159
|
+
if (target.kind === "current")
|
|
160
|
+
{
|
|
161
|
+
presentationsFor(presentations, target.lineNumber).annotations.push(annotation);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const row = target.rows[target.index]!;
|
|
166
|
+
target.rows[target.index] = { ...row, suffix: `${row.suffix ?? ""} ${annotation}` };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function presentLine(line: TextLine, hunk: LineHunkPresentation | undefined): TextLine
|
|
170
|
+
{
|
|
171
|
+
if (hunk === undefined)
|
|
172
|
+
{
|
|
173
|
+
return line;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const annotations = hunk.annotations.length === 0 ? "" : ` ${hunk.annotations.join(" ")}`;
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
...line,
|
|
180
|
+
presentation: {
|
|
181
|
+
...line.presentation,
|
|
182
|
+
...(hunk.added ? { marker: "+" as const } : {}),
|
|
183
|
+
before: [...(line.presentation?.before ?? []), ...hunk.before],
|
|
184
|
+
after: [...hunk.after, ...(line.presentation?.after ?? [])],
|
|
185
|
+
suffix: `${line.presentation?.suffix ?? ""}${annotations}`,
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function presentationsFor(
|
|
191
|
+
presentations: Map<number, LineHunkPresentation>,
|
|
192
|
+
lineNumber: number,
|
|
193
|
+
): LineHunkPresentation
|
|
194
|
+
{
|
|
195
|
+
const existing = presentations.get(lineNumber);
|
|
196
|
+
|
|
197
|
+
if (existing !== undefined)
|
|
198
|
+
{
|
|
199
|
+
return existing;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const created: LineHunkPresentation = { before: [], after: [], annotations: [], added: false };
|
|
203
|
+
presentations.set(lineNumber, created);
|
|
204
|
+
return created;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function placementFor(document: TextDocument, requestedLine: number): { lineNumber: number; after: boolean; }
|
|
208
|
+
{
|
|
209
|
+
if (requestedLine <= document.lines.length)
|
|
210
|
+
{
|
|
211
|
+
return { lineNumber: Math.max(1, requestedLine), after: false };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return { lineNumber: document.lines.length, after: true };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function splitLines(value: string): string[]
|
|
218
|
+
{
|
|
219
|
+
if (value.length === 0)
|
|
220
|
+
{
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const lines = value.split(/\r\n|\r|\n/u);
|
|
225
|
+
|
|
226
|
+
if (lines.at(-1) === "")
|
|
227
|
+
{
|
|
228
|
+
lines.pop();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return lines;
|
|
232
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class IndexMutationQueue
|
|
2
|
+
{
|
|
3
|
+
private tail: Promise<void> = Promise.resolve();
|
|
4
|
+
|
|
5
|
+
run<Result>(operation: () => Promise<Result>): Promise<Result>
|
|
6
|
+
{
|
|
7
|
+
const result = this.tail.then(operation, operation);
|
|
8
|
+
this.tail = result.then(() => void 0, () => void 0);
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
}
|