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,88 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
import type { TextEditCompletion } from "pi-agent-text-editor/api/edit-completion";
|
|
7
|
+
|
|
8
|
+
interface LastTextTransaction
|
|
9
|
+
{
|
|
10
|
+
readonly before: string;
|
|
11
|
+
readonly afterDigest: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class LastTextTransactionStore
|
|
15
|
+
{
|
|
16
|
+
readonly #transactions = new Map<string, LastTextTransaction>();
|
|
17
|
+
|
|
18
|
+
public observe(completion: TextEditCompletion): void
|
|
19
|
+
{
|
|
20
|
+
const key = sourceKey(completion.resourceSource, completion.cwd);
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
completion.intent !== "edit"
|
|
24
|
+
|| !completion.existed
|
|
25
|
+
|| completion.before.content === completion.after.content
|
|
26
|
+
)
|
|
27
|
+
{
|
|
28
|
+
this.#transactions.delete(key);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.#transactions.set(key, {
|
|
33
|
+
before: completion.before.content,
|
|
34
|
+
afterDigest: textDigest(completion.after.content),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public restore(source: string, cwd: string, currentText: string): string
|
|
39
|
+
{
|
|
40
|
+
const key = sourceKey(source, cwd);
|
|
41
|
+
const transaction = this.#transactions.get(key);
|
|
42
|
+
|
|
43
|
+
if (transaction === undefined)
|
|
44
|
+
{
|
|
45
|
+
throw new Error(`No last text transaction is available for ${source}.`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (transaction.afterDigest !== textDigest(currentText))
|
|
49
|
+
{
|
|
50
|
+
this.#transactions.delete(key);
|
|
51
|
+
throw new Error(`${source} changed after its last text transaction; refusing to overwrite newer text.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return transaction.before;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function sourceKey(source: string, cwd: string): string
|
|
59
|
+
{
|
|
60
|
+
if (source.startsWith("file://"))
|
|
61
|
+
{
|
|
62
|
+
return canonicalFile(fileURLToPath(new URL(source)));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (/^[a-z][a-z\d+.-]*:/iu.test(source))
|
|
66
|
+
{
|
|
67
|
+
return source;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return canonicalFile(path.resolve(cwd, source));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function canonicalFile(file: string): string
|
|
74
|
+
{
|
|
75
|
+
try
|
|
76
|
+
{
|
|
77
|
+
return realpathSync.native(file);
|
|
78
|
+
}
|
|
79
|
+
catch
|
|
80
|
+
{
|
|
81
|
+
return path.normalize(file);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function textDigest(text: string): string
|
|
86
|
+
{
|
|
87
|
+
return createHash("sha256").update(text).digest("hex");
|
|
88
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { defineTool, type ExtensionAPI, withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
|
|
7
|
+
import { ChangeService } from "#src/changes/change-service.js";
|
|
8
|
+
|
|
9
|
+
import type { ChangeIndexAction } from "#src/changes/change-types.js";
|
|
10
|
+
import type { GitCommandExecutor } from "#src/changes/git-changes-backend.js";
|
|
11
|
+
import type { IndexMutationQueue } from "#src/index-mutation-queue.js";
|
|
12
|
+
|
|
13
|
+
const indexChangeSchema = Type.Object({
|
|
14
|
+
file: Type.String({ description: "Path to the tracked text file" }),
|
|
15
|
+
change: Type.String({
|
|
16
|
+
description: "Complete CHANGE#HASH anchor shown by read",
|
|
17
|
+
pattern: "^CHANGE#[0-9A-F]{4,64}$",
|
|
18
|
+
}),
|
|
19
|
+
}, { additionalProperties: false });
|
|
20
|
+
|
|
21
|
+
interface IndexChangeToolDetails
|
|
22
|
+
{
|
|
23
|
+
readonly action: ChangeIndexAction;
|
|
24
|
+
readonly change: string;
|
|
25
|
+
readonly file: string;
|
|
26
|
+
readonly state: "staged" | "unstaged";
|
|
27
|
+
readonly unchanged: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function registerIndexChangeTools(
|
|
31
|
+
pi: ExtensionAPI,
|
|
32
|
+
executor: GitCommandExecutor,
|
|
33
|
+
queue: IndexMutationQueue,
|
|
34
|
+
): void
|
|
35
|
+
{
|
|
36
|
+
pi.registerTool(createIndexChangeTool("stage", executor, queue));
|
|
37
|
+
pi.registerTool(createIndexChangeTool("unstage", executor, queue));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createIndexChangeTool(
|
|
41
|
+
action: ChangeIndexAction,
|
|
42
|
+
executor: GitCommandExecutor,
|
|
43
|
+
queue: IndexMutationQueue,
|
|
44
|
+
)
|
|
45
|
+
{
|
|
46
|
+
const targetState = action === "stage" ? "staged" : "unstaged";
|
|
47
|
+
const pastTense = action === "stage" ? "Staged" : "Unstaged";
|
|
48
|
+
|
|
49
|
+
return defineTool<typeof indexChangeSchema, IndexChangeToolDetails>({
|
|
50
|
+
name: action,
|
|
51
|
+
label: action,
|
|
52
|
+
description: `${
|
|
53
|
+
pastTense.slice(0, -1)
|
|
54
|
+
} one current Git change selected by a CHANGE# anchor without changing the worktree.`,
|
|
55
|
+
parameters: indexChangeSchema,
|
|
56
|
+
async execute(_toolCallId, params, signal, _onUpdate, context)
|
|
57
|
+
{
|
|
58
|
+
const file = resolveFile(params.file, context.cwd);
|
|
59
|
+
|
|
60
|
+
return withFileMutationQueue(file, () =>
|
|
61
|
+
queue.run(async () =>
|
|
62
|
+
{
|
|
63
|
+
const worktreeText = await readFile(file, "utf8");
|
|
64
|
+
const creation = await ChangeService.create(executor, context.cwd, signal);
|
|
65
|
+
|
|
66
|
+
if (creation.status !== "ready")
|
|
67
|
+
{
|
|
68
|
+
throw new Error(creation.message);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const result = await creation.service.changeIndex(
|
|
72
|
+
{
|
|
73
|
+
source: file,
|
|
74
|
+
worktreeText,
|
|
75
|
+
cwd: context.cwd,
|
|
76
|
+
...(signal === undefined ? {} : { signal }),
|
|
77
|
+
},
|
|
78
|
+
params.change,
|
|
79
|
+
action,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (result.status === "unavailable")
|
|
83
|
+
{
|
|
84
|
+
throw new Error(result.message);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (result.status === "not-applicable")
|
|
88
|
+
{
|
|
89
|
+
throw new Error(`${action} is not applicable to ${file}: ${result.reason}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const unchanged = result.status === "unchanged";
|
|
93
|
+
const text = unchanged
|
|
94
|
+
? `${params.change} is already ${targetState} in ${params.file}.`
|
|
95
|
+
: `${pastTense} ${params.change} in ${params.file}.`;
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
content: [{ type: "text", text }],
|
|
99
|
+
details: {
|
|
100
|
+
action,
|
|
101
|
+
change: params.change,
|
|
102
|
+
file,
|
|
103
|
+
state: targetState,
|
|
104
|
+
unchanged,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}));
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function resolveFile(file: string, cwd: string): string
|
|
113
|
+
{
|
|
114
|
+
const normalized = file.startsWith("@") ? file.slice(1) : file;
|
|
115
|
+
return path.resolve(cwd, normalized);
|
|
116
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { diffChars } from "diff";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
|
|
4
|
+
import { CHANGE_ANCHOR_KIND } from "#src/change-anchor.js";
|
|
5
|
+
import { ChangeService } from "#src/changes/change-service.js";
|
|
6
|
+
|
|
7
|
+
import type { GitCommandExecutor } from "#src/changes/git-changes-backend.js";
|
|
8
|
+
import type { IndexMutationQueue } from "#src/index-mutation-queue.js";
|
|
9
|
+
import type { LastTextTransactionStore } from "#src/last-text-transaction-store.js";
|
|
10
|
+
import type { TextMutationToolRegistration } from "pi-agent-text-editor/api/mutation-tool";
|
|
11
|
+
|
|
12
|
+
export const undoSchema = Type.Object({
|
|
13
|
+
file: Type.Optional(Type.String({
|
|
14
|
+
description: "File to restore; may be omitted to inherit the previous batched source",
|
|
15
|
+
})),
|
|
16
|
+
change: Type.String({
|
|
17
|
+
description:
|
|
18
|
+
"Complete CHANGE#HASH anchor shown by read, or last for this file's latest text-editor transaction",
|
|
19
|
+
pattern: "^(?:CHANGE#[0-9A-F]{4,64}|last)$",
|
|
20
|
+
}),
|
|
21
|
+
}, { additionalProperties: false });
|
|
22
|
+
|
|
23
|
+
interface UndoParams
|
|
24
|
+
{
|
|
25
|
+
readonly file?: string;
|
|
26
|
+
readonly change: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createUndoMutationTool(
|
|
30
|
+
executor: GitCommandExecutor,
|
|
31
|
+
transactions: LastTextTransactionStore,
|
|
32
|
+
queue: IndexMutationQueue,
|
|
33
|
+
): TextMutationToolRegistration<typeof undoSchema>
|
|
34
|
+
{
|
|
35
|
+
return {
|
|
36
|
+
name: "undo",
|
|
37
|
+
description:
|
|
38
|
+
"Restore one selected current Git change to HEAD in the worktree and index, or restore one file to its state before its latest text-editor transaction.",
|
|
39
|
+
parameters: undoSchema,
|
|
40
|
+
intent: "restore",
|
|
41
|
+
source: { field: "file", inherited: true },
|
|
42
|
+
anchors: [{
|
|
43
|
+
field: "change",
|
|
44
|
+
sourceField: "file",
|
|
45
|
+
kinds: [CHANGE_ANCHOR_KIND],
|
|
46
|
+
}],
|
|
47
|
+
async mutate(context, params: UndoParams)
|
|
48
|
+
{
|
|
49
|
+
const source = context.sourceFor("file");
|
|
50
|
+
let restoredText: string;
|
|
51
|
+
let afterWrite: (() => Promise<void>) | undefined;
|
|
52
|
+
|
|
53
|
+
if (params.change === "last")
|
|
54
|
+
{
|
|
55
|
+
restoredText = transactions.restore(source, context.cwd, context.sourceDocument.content);
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
{
|
|
59
|
+
await context.resolveAnchor("change");
|
|
60
|
+
const creation = await ChangeService.create(executor, context.cwd, context.signal);
|
|
61
|
+
|
|
62
|
+
if (creation.status !== "ready")
|
|
63
|
+
{
|
|
64
|
+
throw new Error(creation.message);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const result = await creation.service.prepareUndo({
|
|
68
|
+
source,
|
|
69
|
+
worktreeText: context.sourceDocument.content,
|
|
70
|
+
cwd: context.cwd,
|
|
71
|
+
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
72
|
+
}, params.change);
|
|
73
|
+
|
|
74
|
+
if (result.status !== "applied")
|
|
75
|
+
{
|
|
76
|
+
if (result.status === "unavailable")
|
|
77
|
+
{
|
|
78
|
+
throw new Error(result.message);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new Error(`Undo is not applicable to ${source}: ${result.reason}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
restoredText = result.worktreeText;
|
|
85
|
+
|
|
86
|
+
if (result.indexUpdate !== undefined)
|
|
87
|
+
{
|
|
88
|
+
const update = result.indexUpdate;
|
|
89
|
+
afterWrite = () => queue.run(() => creation.service.applyIndexUpdate(update, context.signal));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
edits: new Map([[source, {
|
|
95
|
+
changes: createTextChanges(context.sourceDocument.content, restoredText),
|
|
96
|
+
action: "edited",
|
|
97
|
+
}]]),
|
|
98
|
+
...(afterWrite === undefined ? {} : { afterWrite }),
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function createTextChanges(currentText: string, restoredText: string)
|
|
105
|
+
{
|
|
106
|
+
const changes: { from: number; to: number; insert: string; }[] = [];
|
|
107
|
+
let sourceOffset = 0;
|
|
108
|
+
let changeStart: number | undefined;
|
|
109
|
+
let removedLength = 0;
|
|
110
|
+
let insertedText = "";
|
|
111
|
+
|
|
112
|
+
const flush = (): void =>
|
|
113
|
+
{
|
|
114
|
+
if (changeStart === undefined)
|
|
115
|
+
{
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
changes.push({
|
|
120
|
+
from: changeStart,
|
|
121
|
+
to: changeStart + removedLength,
|
|
122
|
+
insert: insertedText,
|
|
123
|
+
});
|
|
124
|
+
changeStart = undefined;
|
|
125
|
+
removedLength = 0;
|
|
126
|
+
insertedText = "";
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
for (const part of diffChars(currentText, restoredText))
|
|
130
|
+
{
|
|
131
|
+
if (!part.added && !part.removed)
|
|
132
|
+
{
|
|
133
|
+
flush();
|
|
134
|
+
sourceOffset += part.value.length;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
changeStart ??= sourceOffset;
|
|
139
|
+
|
|
140
|
+
if (part.removed)
|
|
141
|
+
{
|
|
142
|
+
sourceOffset += part.value.length;
|
|
143
|
+
removedLength += part.value.length;
|
|
144
|
+
}
|
|
145
|
+
else
|
|
146
|
+
{
|
|
147
|
+
insertedText += part.value;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
flush();
|
|
152
|
+
return changes;
|
|
153
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { connectIdePlugin } from "pi-agent-ide/api/connect-plugin";
|
|
2
|
+
import { IDE_API_VERSION, IDE_PROTOCOL, type IdePlugin } from "pi-agent-ide/api/plugin-protocol";
|
|
3
|
+
|
|
4
|
+
import { createFormatter } from "./src/formatter.js";
|
|
5
|
+
|
|
6
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import type { IdeTool } from "pi-agent-ide/api/toolchain";
|
|
8
|
+
|
|
9
|
+
export default function registerFormatter(pi: ExtensionAPI): void | Promise<void>
|
|
10
|
+
{
|
|
11
|
+
const formatter = {
|
|
12
|
+
kind: "formatter",
|
|
13
|
+
name: "pi-agent-ide-formatter",
|
|
14
|
+
priority: 200,
|
|
15
|
+
extensions: ["*"],
|
|
16
|
+
detect: () => Promise.resolve(true),
|
|
17
|
+
async format(input, context)
|
|
18
|
+
{
|
|
19
|
+
return createFormatter().format(input, context);
|
|
20
|
+
},
|
|
21
|
+
} satisfies IdeTool;
|
|
22
|
+
const plugin = {
|
|
23
|
+
protocol: IDE_PROTOCOL,
|
|
24
|
+
apiVersion: IDE_API_VERSION,
|
|
25
|
+
id: "formatter",
|
|
26
|
+
setup(api): void
|
|
27
|
+
{
|
|
28
|
+
api.addTool(formatter);
|
|
29
|
+
},
|
|
30
|
+
} satisfies IdePlugin;
|
|
31
|
+
|
|
32
|
+
return connectIdePlugin(pi, plugin);
|
|
33
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import { FormatterCommandRegistry } from "./registry.js";
|
|
4
|
+
|
|
5
|
+
import type { Formatter } from "pi-agent-ide/api/toolchain";
|
|
6
|
+
|
|
7
|
+
const registries = new Map<string, Promise<FormatterCommandRegistry | undefined>>();
|
|
8
|
+
|
|
9
|
+
/** Creates a formatter that runs a configured external process. */
|
|
10
|
+
export function createFormatter(): Formatter
|
|
11
|
+
{
|
|
12
|
+
return {
|
|
13
|
+
kind: "formatter",
|
|
14
|
+
name: "formatter",
|
|
15
|
+
priority: 100,
|
|
16
|
+
extensions: ["*"],
|
|
17
|
+
detect: () => Promise.resolve(true),
|
|
18
|
+
async format({ filePath }, ctx)
|
|
19
|
+
{
|
|
20
|
+
const registry = await loadRegistry(ctx.cwd);
|
|
21
|
+
const ext = filePath.slice(filePath.lastIndexOf(".")).toLowerCase();
|
|
22
|
+
const formatter = registry?.resolve(ext);
|
|
23
|
+
|
|
24
|
+
if (!formatter)
|
|
25
|
+
{
|
|
26
|
+
return { ok: true, edits: 0 };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const result = spawnSync(formatter.command[0]!, [...formatter.command.slice(1), filePath], {
|
|
30
|
+
cwd: ctx.cwd,
|
|
31
|
+
});
|
|
32
|
+
return { ok: result.status === 0, edits: result.status === 0 ? 1 : 0 };
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function loadRegistry(cwd: string): Promise<FormatterCommandRegistry | undefined>
|
|
38
|
+
{
|
|
39
|
+
let registry = registries.get(cwd);
|
|
40
|
+
|
|
41
|
+
if (registry === undefined)
|
|
42
|
+
{
|
|
43
|
+
registry = FormatterCommandRegistry.fromDirectory(cwd).catch((): undefined =>
|
|
44
|
+
{
|
|
45
|
+
});
|
|
46
|
+
registries.set(cwd, registry);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return registry;
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { FormatterCommandConfig, FormattersConfig } from "./types.js";
|
|
5
|
+
|
|
6
|
+
export class FormatterCommandRegistry
|
|
7
|
+
{
|
|
8
|
+
private constructor(private readonly formatters: readonly FormatterCommandConfig[])
|
|
9
|
+
{}
|
|
10
|
+
|
|
11
|
+
public static async fromDirectory(directory: string): Promise<FormatterCommandRegistry>
|
|
12
|
+
{
|
|
13
|
+
const raw = await readFile(path.join(directory, "formatters.json"), "utf8");
|
|
14
|
+
return FormatterCommandRegistry.fromConfig(JSON.parse(raw) as FormattersConfig);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static fromConfig(config: FormattersConfig): FormatterCommandRegistry
|
|
18
|
+
{
|
|
19
|
+
return new FormatterCommandRegistry(Object.values(config.formatters));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public resolve(extension: string): FormatterCommandConfig | undefined
|
|
23
|
+
{
|
|
24
|
+
const normalized = extension.startsWith(".") ? extension.toLowerCase() : `.${extension.toLowerCase()}`;
|
|
25
|
+
return this.formatters.find((formatter) =>
|
|
26
|
+
formatter.command.length > 0
|
|
27
|
+
&& formatter.extensions.some((candidate) => candidate.toLowerCase() === normalized)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|