pi-agent-ide 0.2.2 → 0.4.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/CHANGELOG.md +46 -0
- package/README.md +13 -8
- package/dist/chunk-3SE372WC.js +3 -0
- package/dist/chunk-5MSNYFDE.js +1 -0
- package/dist/chunk-5VSE5X5R.js +2 -0
- package/dist/chunk-6DZA4CLO.js +4 -0
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
- package/dist/chunk-7JYQMAEL.js +14 -0
- package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
- package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
- package/dist/{chunk-XF5PVZOS.js → chunk-B5KB2I7J.js} +1 -1
- package/dist/chunk-DQF5QMJ2.js +1 -0
- package/dist/chunk-EJ5OACQM.js +1 -0
- package/dist/chunk-GFW5QPQV.js +2 -0
- package/dist/{chunk-LQYZG62K.js → chunk-GUTQ3PWL.js} +1 -1
- package/dist/chunk-HGPUI7F3.js +1 -0
- package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
- package/dist/chunk-ITSNK5YG.js +7 -0
- package/dist/chunk-J34VKQGJ.js +1 -0
- package/dist/chunk-KAB3AYA2.js +1 -0
- package/dist/{chunk-76WHES5H.js → chunk-M5L42DWE.js} +5 -5
- package/dist/chunk-M5MJP7Z2.js +1 -0
- package/dist/chunk-NMFQGKPE.js +2 -0
- package/dist/chunk-NTYXZ3EL.js +3 -0
- package/dist/{chunk-P6T3Q7LB.js → chunk-QDST6VIU.js} +1 -1
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/{chunk-WNMGUALD.js → chunk-TI5GMJ7Q.js} +1 -1
- package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
- package/dist/chunk-XSTHESNR.js +25 -0
- package/dist/{chunk-THSCUT2L.js → chunk-Y7ZMR4LT.js} +1 -1
- package/dist/chunk-YHADTHQM.js +1 -0
- package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
- package/dist/{chunk-ZXN3TWWW.js → chunk-ZM4L5AGN.js} +1 -1
- package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
- package/dist/entry-0.js +1 -1
- package/dist/entry-1.js +1 -1
- package/dist/entry-10.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-2.js +1 -1
- package/dist/entry-21.js +1 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +10 -5
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-31.js +3 -3
- package/dist/entry-32.js +6 -5
- package/dist/entry-36.js +1 -1
- package/dist/entry-37.js +1 -1
- package/dist/entry-38.js +1 -1
- package/dist/entry-39.js +1 -1
- package/dist/entry-4.js +1 -1
- package/dist/entry-40.js +12 -8
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +4 -4
- package/dist/entry-46.js +10 -10
- package/dist/entry-47.js +1 -1
- package/dist/entry-48.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -0
- package/dist/entry-55.js +0 -1
- package/dist/entry-56.js +1 -0
- package/dist/entry-57.js +0 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-63.js +1 -0
- package/dist/entry-64.js +0 -1
- package/dist/entry-65.js +1 -0
- package/dist/entry-66.js +0 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -59
- package/dist/entry-70.js +123 -4
- package/dist/entry-71.js +30 -1
- package/dist/entry-72.js +2 -29
- package/dist/entry-73.js +1 -2
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +3 -1
- package/dist/entry-77.js +1 -3
- package/dist/entry-78.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/pi-agent-ide.js +3 -2
- package/docs/configuration.md +32 -11
- package/docs/tools.md +17 -0
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +6 -6
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +9 -9
- package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -3
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
- package/node_modules/pi-agent-ide-changes/index.ts +21 -5
- package/node_modules/pi-agent-ide-changes/package.json +6 -6
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +26 -8
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/index.ts +46 -17
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
- package/node_modules/pi-agent-ide-lsp/index.ts +126 -8
- package/node_modules/pi-agent-ide-lsp/package.json +9 -8
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
- package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +6 -6
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +26 -2
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +73 -44
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
- package/node_modules/pi-agent-resource/src/resource.ts +2 -0
- package/node_modules/pi-agent-search/package.json +3 -3
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
- package/node_modules/pi-agent-search/src/api/search.ts +55 -1
- package/node_modules/pi-agent-search/src/core/extension.ts +2 -23
- package/node_modules/pi-agent-search/src/core/search-core.ts +28 -3
- package/node_modules/pi-agent-search-text/index.ts +44 -4
- package/node_modules/pi-agent-search-text/package.json +6 -6
- package/node_modules/pi-agent-search-text/src/search-session.ts +65 -25
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/text-document.ts +5 -0
- package/node_modules/pi-agent-text/src/text-target.ts +4 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
- package/node_modules/pi-agent-text-editor/index.ts +1 -3
- package/node_modules/pi-agent-text-editor/package.json +34 -24
- package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
- package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +6 -0
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/index.ts +88 -1
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
- package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
- package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/package.json +41 -38
- package/src/api/plugin-protocol.ts +10 -2
- package/src/api/tool-config.ts +73 -2
- package/src/code-view/diagnostic-view.ts +22 -3
- package/src/composite/builtin-extensions.ts +10 -15
- package/src/composite/extensions-config.ts +59 -0
- package/src/composite/feature-flags.ts +32 -0
- package/src/composite/module-labels.ts +59 -0
- package/src/composite/module-settings-store.ts +60 -0
- package/src/composite/module-settings.ts +162 -0
- package/src/composite/preferences.ts +26 -0
- package/src/composite/selection.ts +4 -4
- package/src/composite/settings-panel.ts +103 -0
- package/src/core/diagnostic-delivery.ts +29 -0
- package/src/core/diagnostic-entry.ts +51 -3
- package/src/core/diagnostic-store.ts +56 -5
- package/src/core/extension.ts +34 -33
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +6 -6
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +26 -2
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +73 -44
- package/src/extensions/pi-agent-search/package.json +3 -3
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +44 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +65 -25
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
- package/src/extensions/pi-agent-search/src/core/extension.ts +2 -23
- package/src/extensions/pi-agent-search/src/core/search-core.ts +28 -3
- package/src/extensions/pi-agent-text-editor/index.ts +1 -3
- package/src/extensions/pi-agent-text-editor/package.json +34 -24
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +88 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +6 -0
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
- package/src/pi-agent-ide.ts +43 -8
- package/src/plugins/pi-agent-ide-ast/package.json +9 -9
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -3
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
- package/src/plugins/pi-agent-ide-changes/index.ts +21 -5
- package/src/plugins/pi-agent-ide-changes/package.json +6 -6
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -11
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +26 -8
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/index.ts +46 -17
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
- package/src/plugins/pi-agent-ide-lsp/index.ts +126 -8
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
- package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
- package/src/plugins/pi-agent-ide-terminal/index.ts +34 -0
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +238 -0
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +461 -0
- package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +127 -0
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +159 -0
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +529 -0
- package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +56 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +157 -0
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +66 -0
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +336 -0
- package/src/post-edit/gate.ts +15 -2
- package/dist/chunk-4U6KGABH.js +0 -1
- package/dist/chunk-6ACQQBUY.js +0 -7
- package/dist/chunk-GFWDXTOB.js +0 -4
- package/dist/chunk-JASLOB2X.js +0 -1
- package/dist/chunk-JJVXUL5U.js +0 -2
- package/dist/chunk-KCEOTU5Z.js +0 -3
- package/dist/chunk-KVGQG43U.js +0 -1
- package/dist/chunk-QJFRAMK7.js +0 -2
- package/dist/chunk-RAZOACDD.js +0 -2
- package/dist/chunk-RIGRP3FD.js +0 -1
- package/dist/chunk-VCCMVQXU.js +0 -1
- package/dist/chunk-X6MPU7UO.js +0 -3
- package/dist/chunk-YPHXLAQF.js +0 -1
- package/dist/entry-80.js +0 -1
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
- package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
- package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
- package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
- /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
- /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
- /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
- /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
- /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as u,f as E,k as a}from"./chunk-
|
|
1
|
+
import{e as u,f as E,k as a}from"./chunk-Y7ZMR4LT.js";import{a as n}from"./chunk-EI7MMDWY.js";function T(o,r){let s=n(()=>{let e,i={plugin:r,accept(c){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=c}};return o.events.emit(E,i),e},"announce"),t=n(()=>{},"unsubscribe");t=o.events.on(u,e=>{if(!a(e))throw new Error("Invalid pi-agent-text-editor core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-text-editor core announced readiness without accepting the plugin");t(),i.catch(()=>{})}),o.on("session_shutdown",t);let d=s();if(d!==void 0)return t(),d}n(T,"connectTextEditorPlugin");export{T as a};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as I,b as k}from"./chunk-
|
|
1
|
+
import{a as I,b as k}from"./chunk-B5KB2I7J.js";import{j as N,k as y}from"./chunk-NTYXZ3EL.js";import"./chunk-5VSE5X5R.js";import"./chunk-KINKBPPX.js";import{a as b}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import h from"node:path";import{readdir as U}from"node:fs/promises";import Y from"node:path";async function E(e){let n=[],t=await U(e,{withFileTypes:!0});for(let i of t){let o=Y.join(e,i.name);i.isDirectory()?n.push(...await E(o)):(i.isFile()||i.isSymbolicLink())&&n.push(o)}return n}s(E,"collectFiles");import{readFile as K}from"node:fs/promises";var v=256*1024;async function L(e){let n=await K(e);if(n.byteLength>v)throw new Error(`File exceeds the ${v}-byte AST outline limit: ${e}`);if(n.includes(0))throw new Error(`File appears to be binary and cannot be read as text: ${e}`);let t=n.toString("utf8").replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`),i=t.endsWith(`
|
|
4
4
|
`)?t.slice(0,-1):t,o=i.length===0?[]:i.split(`
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import{b as x}from"./chunk-3SE372WC.js";import"./chunk-YHUTTZC6.js";import{a as K}from"./chunk-72EEL2DW.js";import{a as X,b as Y}from"./chunk-KAB3AYA2.js";import{a as Z}from"./chunk-ZTYWHL2F.js";import{a as z,b as J}from"./chunk-7UGNGK7Y.js";import{a as ne}from"./chunk-TI5GMJ7Q.js";import{a as Q,b as ee}from"./chunk-Y7ZMR4LT.js";import"./chunk-S3ZPXWX7.js";import{a as te,b as re}from"./chunk-EJ5OACQM.js";import"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";var _e="#d8dee9",M="#111418",De=["#000000","#cd0000","#00cd00","#cdcd00","#0000ee","#cd00cd","#00cdcd","#e5e5e5","#7f7f7f","#ff0000","#00ff00","#ffff00","#5c5cff","#ff00ff","#00ffff","#ffffff"];async function _(e,n,t){let r=e.get(n);if(r===void 0)throw new Error(`Unknown terminal session ${n}`);await r.screenReady;let{createCanvas:i}=await import("@napi-rs/canvas"),s=Math.max(0,Math.min(r.rows-1,t?.start??0)),o=Math.max(1,Math.min(r.rows-s,t?.count??r.rows)),c=i(r.cols*9+24,o*18+24),u=c.getContext("2d");u.fillStyle=M,u.fillRect(0,0,c.width,c.height),u.textBaseline="top";let d=r.screen.buffer.active,l=Math.max(0,d.baseY);for(let f=0;f<o;f+=1){let m=d.getLine(l+s+f);if(m!==void 0)for(let p=0;p<r.cols;p+=1){let g=m.getCell(p);g===void 0||g.getWidth()===0||Oe(u,g,p,f)}}return r.status==="running"&&d.cursorY>=s&&d.cursorY<s+o&&(u.fillStyle="rgba(216, 222, 233, 0.75)",u.fillRect(12+d.cursorX*9,12+(d.cursorY-s)*18+18-2,9,2)),c.toBuffer("image/png").toString("base64")}a(_,"renderTerminalScreen");function Oe(e,n,t,r){let i=ie(n,"foreground"),s=ie(n,"background");n.isInverse()&&([i,s]=[s,i]);let o=12+t*9,c=12+r*18;s!==M&&(e.fillStyle=s,e.fillRect(o,c,9*Math.max(1,n.getWidth()),18));let u=n.getChars();u.length!==0&&(e.font=`${n.isBold()?"bold ":""}14px monospace`,e.fillStyle=i,e.fillText(u,o,c),n.isUnderline()&&e.fillRect(o,c+18-2,9*Math.max(1,n.getWidth()),1))}a(Oe,"drawCell");function ie(e,n){let t=n==="foreground";if(t?e.isFgDefault():e.isBgDefault())return t?_e:M;let i=t?e.isFgRGB():e.isBgRGB(),s=t?e.getFgColor():e.getBgColor();return i?`#${s.toString(16).padStart(6,"0")}`:Ne(s)}a(ie,"cellColor");function Ne(e){let n=De[e];if(n!==void 0)return n;if(e>=232){let c=8+(e-232)*10;return se(c,c,c)}let t=Math.max(0,e-16),r=Math.floor(t/36),i=Math.floor(t%36/6),s=t%6,o=a(c=>c===0?0:55+c*40,"channel");return se(o(r),o(i),o(s))}a(Ne,"ansiColor");function se(e,n,t){return`#${[e,n,t].map(r=>r.toString(16).padStart(2,"0")).join("")}`}a(se,"rgb");import We from"node:path";import{stripVTControlCharacters as Ue}from"node:util";import{Text as $,truncateToWidth as ae,visibleWidth as D}from"@earendil-works/pi-tui";function le(e,n,t,r,i){let s=n?"background":"wait",o=`${i.fg("toolTitle",r.displayName.toLocaleLowerCase())} ${i.fg("muted",`\xB7 ${k(t)} \xB7 ${s}`)}`;return new $(`${o}
|
|
2
|
+
${i.fg("accent",U(r.family))} ${e}`,0,0)}a(le,"renderRunCall");function ce(e,n,t){let r=n.map(i=>` ${t.fg("dim",i)}`);return r.push(t.fg("success",e==="delete"?"\u2713 stopped":"\u2713 sent")),new $(r.join(`
|
|
3
|
+
`),0,0)}a(ce,"renderTerminalActionResult");function P(e,n,t,r,i){let s=[Ve(e,i),i.fg("accent",`${n} ${t}`)];return r.length>0&&s.push(...r.map(o=>` ${i.fg("dim",o)}`)),new $(s.join(`
|
|
4
|
+
`),0,0)}a(P,"renderTerminalAction");function C(e,n,t,r){let i=Ge(e,n?Number.POSITIVE_INFINITY:x,t);return r!==void 0&&i.splice(1,1,t.fg("accent",r)),new $(i.join(`
|
|
5
|
+
`),0,0)}a(C,"renderTerminalResult");function ue(e,n,t){if(n)return C(e,!0,t);let r=N(e.output??"",x),i=[...r.omitted>0?[` ${t.fg("muted",`\u2026 ${r.omitted} earlier lines`)}`]:[],...r.lines.map(s=>` ${t.fg("dim",s)}`)];return i.push(W(e,(s,o)=>t.fg(s,o))),new $(i.join(`
|
|
6
|
+
`),0,0)}a(ue,"renderRunResult");function Fe(e,n){let t=a((o,c)=>n?.fg(o,c)??c,"color"),i=[`${t("accent",e.shell.toLocaleLowerCase())} ${t("muted",`\xB7 ${k(e.cwd)} \xB7 ${e.background?"background":"wait"}`)}`,`${t("accent",U(e.shellFamily))} ${O(e.command,84)}`],s=Be(e.output,2);return s.length>0&&i.push(...s.map(o=>` ${t("dim",O(o,90))}`)),i.push(W(e,t)),i.join(`
|
|
7
|
+
`)}a(Fe,"renderActiveTerminal");function Ge(e,n,t){let r=(e.shell??"terminal").toLocaleLowerCase(),i=e.background===!0?"background":"wait",s=e.cwd===void 0?"workspace":k(e.cwd),o=e.shellFamily??"posix",c=[`${t.fg("accent",r)} ${t.fg("muted",`\xB7 ${s} \xB7 ${i}`)}`,`${t.fg("accent",U(o))} ${e.command??""}`],u=N(e.output??"",n);return u.omitted>0&&c.push(` ${t.fg("muted",`\u2026 ${u.omitted} earlier lines`)}`),u.lines.length>0&&c.push(...u.lines.map(d=>` ${t.fg("dim",d)}`)),c.push(W(e,(d,l)=>t.fg(d,l))),c}a(Ge,"terminalCardLines");function de(e,n,t){if(e.length===0)return[];let r=a(s=>t.fg("accent",s),"accent"),i=[He("Terminals",`${e.length} active`,n,r)];for(let s of e){let o=Fe(s,t).split(`
|
|
8
|
+
`);for(let c of o)i.push(oe(` ${c} `,n,r));s!==e.at(-1)&&i.push(oe("",n,r))}return i.push(je(n,r)),i}a(de,"renderTerminalWidgetLines");function He(e,n,t,r){if(t<=1)return r("\u256D");let i=t-2,s=`\u2500 ${e} `,o=` ${n} \u2500`,c="\u2500".repeat(Math.max(0,i-D(s)-D(o)));return r(`\u256D${ae(`${s}${c}${o}`,i).padEnd(i,"\u2500")}\u256E`)}a(He,"borderTop");function oe(e,n,t){if(n<=1)return t("\u2502");let r=n-2,i=ae(e,r);return`${t("\u2502")}${i}${" ".repeat(Math.max(0,r-D(i)))}${t("\u2502")}`}a(oe,"borderLine");function je(e,n){return n(e<=1?"\u2570":`\u2570${"\u2500".repeat(e-2)}\u256F`)}a(je,"borderBottom");function Be(e,n){return N(e,n).lines}a(Be,"outputTail");function N(e,n){let t=Ue(e).replaceAll("\r","").split(`
|
|
9
|
+
`).map(s=>s.trimEnd());t.at(-1)===""&&t.pop();let r=Number.isFinite(n)?Math.max(0,n):t.length,i=Math.max(0,t.length-r);return{lines:t.slice(i),omitted:i}}a(N,"outputWindow");function W(e,n){let t=e.status??"running",r=qe(t),i=t==="completed"?"success":t==="running"?"accent":"error",s=[`${r} ${t}`,Xe(e.elapsedMs??0)];return e.exitCode!==void 0?s.push(`exit ${e.exitCode}`):e.signal!==void 0&&s.push(`signal ${e.signal}`),n(i,s.join(" \xB7 "))}a(W,"statusLine");function qe(e){return e==="completed"?"\u2713":e==="running"?"\u25CF":e==="stopping"?"\u25CC":"\u2717"}a(qe,"statusIcon");function U(e){return e==="powershell"?"PS>":e==="cmd"?">":"$"}a(U,"promptMarker");function Ve(e,n){let t=(e.shell??"terminal").toLocaleLowerCase(),r=e.cwd===void 0?"workspace":k(e.cwd),i=e.background===!0?"background":"wait",s=O(e.command??"process",48);return`${n.fg("toolTitle",t)} ${n.fg("muted",`\xB7 ${r} \xB7 ${i} \xB7 ${s}`)}`}a(Ve,"terminalIdentity");function k(e){let n=process.env.HOME;return n!==void 0&&(e===n||e.startsWith(`${n}${We.sep}`))?`~${e.slice(n.length)}`:e}a(k,"shortCwd");function O(e,n){let t=e.replaceAll(/\s+/gu," ").trim();return t.length<=n?t:`${t.slice(0,n-1)}\u2026`}a(O,"oneLine");function Xe(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(e<1e4?1:0)}s`}a(Xe,"formatElapsed");var F="\0pi-terminal-write\0",G="\0pi-terminal-keys\0";async function he(e,n){let t=new Map,r=new Map,i={protocol:X,apiVersion:Y,id:"terminal",setup(o){o.addResolver({resolver:Ye(n),preserveTruncatedOutput:!0,renderResult(c,u,d){let l=c.details,f=l.source===void 0?void 0:n.get(l.source),m=f===void 0?{}:n.snapshot(f);return C(f===void 0?m:{...m,output:n.screenTail(f).join(`
|
|
10
|
+
`)},u.expanded,d,"read terminal")}}),o.addHandler({stage:"pre-read",async handler(c){let u=c.request.path;if(u===void 0||!h(u)||c.request.views?.includes("image")!==!0)return{kind:"continue",context:c};let d=n.get(u);if(d===void 0)return{kind:"return",result:me(u,`Unknown terminal session ${u}`)};try{return{kind:"return",result:{content:[{type:"image",data:await _(n,u),mimeType:"image/png"}],details:{source:d.source,resolvedBy:"terminal"}}}}catch(l){return{kind:"return",result:me(u,l instanceof Error?l.message:String(l))}}}}),o.describe('shell:<session> \u2014 terminal session status and bounded output. Use views: ["image"] to read the current virtual terminal screen as a PNG.'),o.addPromptGuideline("Use read with a returned shell:<session> source to inspect terminal status and output. Add the image view when cursor movement, ANSI layout, or a full-screen terminal interface matters.")}},s={protocol:Q,apiVersion:ee,id:"terminal",setup(o){o.addResolver({resolver:Ke(n)}),o.tool("write").addHandler({stage:"text-pre-edit",handler:a(async c=>(pe(c.input,n,t),await fe(c.input,n,r),ze(c,F)),"handler")}),o.tool("insert").addHandler({stage:"text-pre-edit",handler:a(async c=>(await fe(c.input,n,r),pe(c.input,n,t),Je(c)),"handler")});for(let c of["write","insert","delete"])o.addToolRenderer({tool:c,matches:a((u,d)=>nn(u,d),"matches"),renderCall(u,d,l){let f=u,m=typeof f.path=="string"?n.get(f.path):void 0,p=l.state;return m!==void 0&&(p.snapshot=n.snapshot(m)),P(p.snapshot??{},c,ge(c,f),[],d)},renderResult(u,d,l){let f=en(u.details);return ce(f.action,f.changedLines,l)}});o.describe("For shell:<session> resources, write sends exact terminal input, insert sends named keys at end, and delete terminates and removes the session. replace is unsupported."),o.tool("write").describe("When path is shell:<session>, send content exactly as terminal input without adding Enter."),o.tool("insert").describe("When path is shell:<session>, omit anchor or use end, keep before false, and put whitespace- or comma-separated named keys and chords such as Enter, Ctrl+C, Ctrl+Left, Ctrl+Shift+Left, Up, or Backspace in text. Use Unix caret forms such as ^C and ^U for control characters.")}};await Promise.all([K(e,i),ne(e,s)]),e.on("tool_result",async(o,c)=>{if(!S(o.input))return;let u=o.input.path;if(o.toolName==="replace"&&typeof u=="string"&&h(u))return{content:[{type:"text",text:`replace is unsupported for ${u}; use write for text, insert for keys, or delete to terminate and remove the session.`}],details:o.details,isError:!0};if(o.toolName==="delete"&&typeof u=="string"&&h(u)){let V=n.get(u);if(V===void 0)return;let Me=n.snapshot(V);return n.delete(u).then(()=>({content:[{type:"text",text:`Deleted terminal session ${u}.`}],details:{source:u,deleted:!0,snapshot:Me,action:"delete",input:"session",changedLines:[]},isError:!1}),L=>({content:[{type:"text",text:L instanceof Error?L.message:String(L)}],details:{source:u,deleted:!1},isError:!0}))}if(o.toolName!=="write"&&o.toolName!=="insert"||o.isError)return;let d=o.input.path;if(typeof d!="string"||!h(d))return;let l=n.get(d);if(l===void 0)return;let f=r.get(d)??n.screenRows(l);r.delete(d);let m=t.get(d)??l.outputStart+l.output.length;t.delete(d),await n.waitForOutputAfter(l,m);let p=n.snapshot(l),g=o.toolName,y=ge(g,o.input),b=n.screenChangeRegion(l,f,6),R=[{type:"text",text:`Sent ${y} to ${l.source}.`}];return c.model?.input.includes("image")===!0&&R.push({type:"image",data:await _(n,d,{start:b.startRow,count:b.lines.length}),mimeType:"image/png"}),{content:R,details:{source:l.source,action:g,status:l.status,snapshot:p,input:y,changedLines:b.lines},isError:o.isError}})}a(he,"registerTerminalResources");function Ye(e){return{id:"terminal",async tryResolve(n){if(!h(n))return{kind:"not-handled"};let t=e.get(n);return t===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${n}`)}:{kind:"resolved",resource:{source:t.source,async read(){let r=e.snapshot(t);return[{type:"text",text:Ze(r)}]}}}}}}a(Ye,"createReadResolver");function Ke(e){return{id:"terminal-input",async tryResolve(n){if(!h(n))return{kind:"not-handled"};let t=e.get(n);return t===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${n}`)}:{kind:"resolved",resource:{source:t.source,skipPostEdit:!0,async read(){return[{type:"text",text:"terminal input"}]},async write(r){let i=Qe(r),s=i.indexOf(F),o=i.indexOf(G);if(s>=0){e.write(t.source,i.slice(s+F.length));return}if(o>=0){e.sendKeys(t.source,i.slice(o+G.length).trim());return}throw new Error(`Unsupported text operation for ${t.source}`)}}}}}}a(Ke,"createInputResolver");function ze(e,n){return!S(e.input)||!ye(e.input.path)?e:{...e,input:{...e.input,content:`${n}${typeof e.input.content=="string"?e.input.content:""}`}}}a(ze,"transformWriteInput");function Je(e){if(!S(e.input)||!ye(e.input.path))return e;if(e.input.before===!0)throw new Error("Shell keys can only be inserted after the active input position");return{...e,input:{...e.input,anchor:"end",before:!1,text:`${G}${typeof e.input.text=="string"?e.input.text:""}`}}}a(Je,"transformInsertInput");function Ze(e){return`${[`session: ${e.source}`,`status: ${e.status}`,`shell: ${e.shell}`,`cwd: ${e.cwd}`,`elapsedMs: ${e.elapsedMs}`,e.exitCode===void 0?void 0:`exitCode: ${e.exitCode}`,e.signal===void 0?void 0:`signal: ${e.signal}`,`outputRange: ${e.outputStart}-${e.outputEnd}`,`truncated: ${String(e.truncated)}`].filter(t=>t!==void 0).join(`
|
|
11
|
+
`)}
|
|
12
|
+
|
|
13
|
+
${e.output}`}a(Ze,"formatSnapshot");function Qe(e){if(e.length!==1||e[0].type!=="text")throw new Error("Terminal input must contain one text block");return e[0].text}a(Qe,"singleText");function me(e,n){return{content:[{type:"text",text:n}],details:{source:e,failure:{code:"READ_FAILED",source:e,resolverId:"terminal",message:n}},isError:!0}}a(me,"failure");function h(e){return/^shell:[a-f\d]{12}$/u.test(e)}a(h,"isShellSource");function ye(e){return typeof e=="string"&&h(e)}a(ye,"isShellSourceValue");function en(e){if(!S(e)||!S(e.snapshot))throw new TypeError("Invalid terminal action result");let n=e.snapshot,t=e.action;if(t!=="write"&&t!=="insert"&&t!=="delete")throw new TypeError("Invalid terminal action");return{source:typeof e.source=="string"?e.source:"shell:unknown",action:t,input:typeof e.input=="string"?e.input:"",changedLines:Array.isArray(e.changedLines)?e.changedLines.filter(r=>typeof r=="string"):[],snapshot:{...typeof n.shell=="string"?{shell:n.shell}:{},...typeof n.cwd=="string"?{cwd:n.cwd}:{},...typeof n.command=="string"?{command:n.command}:{},...typeof n.background=="boolean"?{background:n.background}:{},...typeof n.status=="string"?{status:n.status}:{}}}}a(en,"terminalActionDetails");async function fe(e,n,t){if(!S(e)||typeof e.path!="string"||!h(e.path))return;let r=n.get(e.path);r!==void 0&&await r.screenReady,r!==void 0&&t.set(e.path,n.screenRows(r))}a(fe,"rememberScreen");function pe(e,n,t){if(!S(e)||typeof e.path!="string"||!h(e.path))return;let r=n.get(e.path);r!==void 0&&t.set(e.path,r.outputStart+r.output.length)}a(pe,"rememberOutputEnd");function ge(e,n){if(e==="delete")return"session";let t=e==="write"?n.content:n.text,r=typeof t=="string"?t:"";return e==="write"?`text ${JSON.stringify(r)}`:`keys ${r}`}a(ge,"terminalInputLabel");function nn(e,n){if(!S(e))return!1;if(n==="call")return typeof e.path=="string"&&h(e.path);let t=e.details;return S(t)&&typeof t.source=="string"&&h(t.source)}a(nn,"isTerminalRenderValue");function S(e){return typeof e=="object"&&e!==null}a(S,"isRecord");async function we(e,n){await Z(e,{protocol:z,apiVersion:J,id:"terminal",setup(r){r.addResolver({resolver:tn(n),priority:100}),r.describe("path shell:<session> searches the retained text output of that terminal, including rows outside its current screen."),r.addPromptGuideline("Use search with path shell:<session> to find text in retained terminal output. Read the same shell source with the returned line number when more context is needed.")}})}a(we,"registerTerminalSearch");function tn(e){return{id:"terminal",async tryResolve(n){if(n.path===void 0||!n.path.startsWith("shell:"))return{kind:"not-handled"};let t=e.get(n.path);if(t===void 0)return{kind:"failed",error:new Error(`Unknown terminal session ${n.path}`)};let r=e.snapshot(t),i=rn(r,n);return{kind:"resolved",payload:{snapshot:r,query:n.query,matches:i}}},format(n){let t=H(n),r=t.matches.map(i=>`${t.snapshot.source}:${i.lineNumber}: ${i.lineText}`);return{content:[{type:"text",text:r.length===0?`No matches in ${t.snapshot.source}`:`${r.join(`
|
|
14
|
+
`)}
|
|
15
|
+
|
|
16
|
+
${r.length} match${r.length===1?"":"es"} in ${t.snapshot.source}`}],details:{source:t.snapshot.source,payload:t}}},renderResult(n,t,r){let i=n.details,s=j(i)?H(i.payload):H(void 0);return P(s.snapshot,"search",JSON.stringify(s.query),s.matches.slice(-6).map(o=>`${o.lineNumber}: ${o.lineText}`),r)}}}a(tn,"terminalSearchResolver");function rn(e,n){let t=n.caseSensitive===!0?n.query:n.query.toLocaleLowerCase();if(t.length===0)return[];let r=[],i=n.limit??100;for(let[s,o]of e.output.replaceAll("\r","").split(`
|
|
17
|
+
`).entries()){let c=n.caseSensitive===!0?o:o.toLocaleLowerCase(),u=0;for(;r.length<i;){let d=c.indexOf(t,u);if(d<0)break;let l=d+t.length;(n.wholeWord!==!0||sn(c,d,l))&&r.push({source:e.source,lineNumber:s+1,startColumn:d,endColumn:l,matchedText:o.slice(d,l),lineText:o}),u=Math.max(l,d+1)}if(r.length>=i)break}return r}a(rn,"findTerminalMatches");function sn(e,n,t){return!/[\p{L}\p{N}_]/u.test(e[n-1]??"")&&!/[\p{L}\p{N}_]/u.test(e[t]??"")}a(sn,"isWordBoundary");function H(e){if(!on(e))throw new TypeError("Invalid terminal search result");return e}a(H,"parsePayload");function on(e){return j(e)&&typeof e.query=="string"&&Array.isArray(e.matches)&&j(e.snapshot)&&typeof e.snapshot.source=="string"}a(on,"isTerminalSearchPayload");function j(e){return typeof e=="object"&&e!==null}a(j,"isRecord");import{spawn as an}from"node:child_process";import{createRequire as ln}from"node:module";import{randomUUID as cn}from"node:crypto";import{stripVTControlCharacters as un}from"node:util";var be=ln(new URL("../src/plugins/pi-agent-ide-terminal/src/session-manager.ts",import.meta.url).href),Se=1e6,dn=100,mn=30,fn=2e3,v=class{static{a(this,"TerminalSessionManager")}#s;#e=new Map;#t=new Set;#n=new Set;#i=!1;constructor(n=gn){this.#s=n}onDidChange(n){return this.#t.add(n),()=>this.#t.delete(n)}onDidComplete(n){return this.#n.add(n),()=>this.#n.delete(n)}list(){return[...this.#e.values()].sort((n,t)=>t.startedAt-n.startedAt).map(n=>this.snapshot(n))}get(n){return this.#e.get(hn(n))}snapshot(n,t=Date.now()){return{id:n.id,source:n.source,command:n.command,cwd:n.cwd,shell:n.shell.displayName,shellFamily:n.shell.family,background:n.background,status:n.status,startedAt:n.startedAt,...n.endedAt===void 0?{}:{endedAt:n.endedAt},elapsedMs:(n.endedAt??t)-n.startedAt,...n.exitCode===void 0?{}:{exitCode:n.exitCode},...n.signal===void 0?{}:{signal:n.signal},...n.error===void 0?{}:{error:n.error},output:n.output,outputStart:n.outputStart,outputEnd:n.outputStart+n.output.length,truncated:n.outputStart>0,cols:n.cols,rows:n.rows}}start(n){if(this.#i)throw new Error("Terminal session manager is closed");let t=this.#s();if(!/^[a-f\d]{12}$/u.test(t)||this.#e.has(t))throw new Error("Terminal session IDs must be unique 12-character hexadecimal values");let r=n.cols??dn,i=n.rows??mn,s=pn(r,i),o=a(f=>{},"resolveCompletion"),c=new Promise(f=>{o=f}),u={id:t,source:`shell:${t}`,command:n.command,background:n.background,cwd:n.cwd,shell:n.shell,startedAt:Date.now(),cols:r,rows:i,screen:s,status:"running",output:"",outputStart:0,screenReady:Promise.resolve(),completion:c,resolveCompletion:o,completionDelivered:!1},d;try{let f=be("node-pty"),m={name:"xterm-256color",cols:r,rows:i,cwd:n.cwd,env:wn(yn())};d=f.spawn(n.shell.executable,[...n.shell.commandArgs(n.command)],m)}catch(f){let m={...u,status:"failed",endedAt:Date.now(),error:bn(f)};return this.#e.set(t,m),o(m),queueMicrotask(()=>this.#o(m)),m}let l={...u,process:d};return this.#e.set(t,l),d.onData(f=>this.#a(l,f)),d.onExit(({exitCode:f,signal:m})=>{E(l.status)||(l.endedAt=Date.now(),l.exitCode=f,m!==0&&(l.signal=m),l.status=l.status==="stopping"?"stopped":f===0?"completed":"failed",l.resolveCompletion(l),this.#r(l),this.#o(l))}),this.#r(l),l}async wait(n,t){let r=this.required(n);return E(r.status)?r:t?.aborted===!0?(await this.stop(r.source,"cancelled"),r):await new Promise((i,s)=>{let o=a(()=>{this.stop(r.source,"cancelled").then(i,s)},"onAbort");t?.addEventListener("abort",o,{once:!0}),r.completion.then(c=>{t?.removeEventListener("abort",o),i(c)},s)})}async waitForOutputAfter(n,t){let r=Date.now()+300,i=t,s;for(;Date.now()<r;){let o=n.outputStart+n.output.length;if(o!==i)i=o,s=Date.now(),await n.screenReady;else if(s!==void 0&&Date.now()-s>=40)return;await B(10)}await n.screenReady}screenRows(n){let t=n.screen.buffer.active;return Array.from({length:n.rows},(r,i)=>(t.getLine(t.baseY+i)?.translateToString(!0)??"").trimEnd())}screenChangeRegion(n,t,r=6){let i=this.screenRows(n),s=Math.max(1,Math.min(n.rows,r)),o=Math.max(0,n.screen.buffer.active.cursorY-Math.floor(s/2)),c=-1;for(let l=0;l<=n.rows-s;l+=1){let f=0;for(let m=l;m<l+s;m+=1){let p=t[m]??"",g=i[m]??"",y=g.length>0&&!t.includes(g),b=p.length>0&&g.length===0;p!==g&&(y||b)&&(f+=1)}f>c&&(c=f,o=l)}let u=n.screen.buffer.active;return{lines:i.slice(o,o+s).map((l,f)=>{if(o+f!==u.cursorY)return l;let p=l.padEnd(u.cursorX," ");return`${p.slice(0,u.cursorX)}\u258C${p.slice(u.cursorX)}`}),startRow:o}}screenChangeWindow(n,t,r=6){return this.screenChangeRegion(n,t,r).lines}screenTail(n,t=n.rows){let r=n.screen.buffer.active,i=Math.max(0,r.baseY),s=[];for(let o=0;o<n.rows;o+=1){let c=r.getLine(i+o)?.translateToString(!0).trimEnd();c!==void 0&&c.length>0&&s.push(c)}return s.slice(-Math.max(0,t))}write(n,t){this.requiredRunning(n).process?.write(t)}sendKeys(n,t){this.requiredRunning(n).process?.write(Sn(t))}async stop(n,t="stopped"){let r=this.required(n);return E(r.status)||(r.status="stopping",this.#r(r),await Te(r,!1),await Promise.race([r.completion.then(()=>!0),B(fn).then(()=>!1)])||(await Te(r,!0),await Promise.race([r.completion,B(1e3)])),E(r.status)||(r.status=t,r.endedAt=Date.now(),r.resolveCompletion(r),this.#o(r)),t==="cancelled"&&(r.status="cancelled"),this.#r(r)),r}async delete(n){let t=this.required(n);t.completionDelivered=!0,await this.stop(t.source),t.screen.dispose(),this.#e.delete(t.id),this.#r(t)}async screenLines(n){let t=this.required(n);await t.screenReady;let r=t.screen.buffer.active,i=[],s=Math.max(0,r.baseY);for(let o=s;o<s+t.rows;o+=1)i.push(r.getLine(o)?.translateToString(!0)??"");return i}cursor(n){let t=this.required(n);return{x:t.screen.buffer.active.cursorX,y:t.screen.buffer.active.cursorY}}async dispose(){if(!this.#i){this.#i=!0,await Promise.all([...this.#e.values()].filter(n=>!E(n.status)).map(n=>this.stop(n.source)));for(let n of this.#e.values())n.screen.dispose();this.#t.clear(),this.#n.clear()}}required(n){let t=this.get(n);if(t===void 0)throw new Error(`Unknown terminal session ${n}`);return t}requiredRunning(n){let t=this.required(n);if(t.status!=="running")throw new Error(`Terminal session ${t.source} is ${t.status}; input is unavailable`);return t}#a(n,t){let r=un(t);if(n.output+=r,n.output.length>Se){let i=n.output.length-Se;n.output=n.output.slice(i),n.outputStart+=i}n.screenReady=n.screenReady.then(()=>new Promise(i=>{n.screen.write(t,i)})),this.#r(n)}#r(n){for(let t of this.#t)t(n)}#o(n){for(let t of this.#n)t(n)}};function pn(e,n){let{Terminal:t}=be("@xterm/headless");return new t({cols:e,rows:n,scrollback:2e3,allowProposedApi:!0})}a(pn,"createScreen");function gn(){return cn().replaceAll("-","").slice(0,12)}a(gn,"defaultSessionId");function hn(e){return e.startsWith("shell:")?e.slice(6):e}a(hn,"normalizeSessionId");function E(e){return e!=="running"&&e!=="stopping"}a(E,"isTerminalStatus");function yn(){return process.env}a(yn,"processEnvironment");function wn(e){return{...Object.fromEntries(Object.entries(e).filter(n=>n[1]!==void 0)),PAGER:"cat",GIT_PAGER:"cat",SYSTEMD_PAGER:"cat",GH_PAGER:"cat"}}a(wn,"cleanEnvironment");function Sn(e){return e.split(/[\s,]+/u).filter(Boolean).map(Tn).join("")}a(Sn,"encodeTerminalKeys");function Tn(e){if(/^\^[?@A-Z[\\\]^_]$/iu.test(e)){let l=e.slice(1).toUpperCase();return l==="?"?"\x7F":String.fromCharCode(l.charCodeAt(0)&31)}let n=e.toLowerCase().split("+"),t=n.pop()??"",r=new Set(n);if([...r].some(l=>!["ctrl","control","alt","meta","shift"].includes(l)))throw new Error(`Unsupported terminal key ${e}`);let i=r.has("ctrl")||r.has("control"),s=r.has("alt")||r.has("meta"),o=r.has("shift");if(i&&t.length===1&&/[a-z@[\\\]^_?]/u.test(t)){let l=t.toUpperCase(),f=l==="?"?"\x7F":String.fromCharCode(l.charCodeAt(0)&31);return s?`\x1B${f}`:f}let c={enter:"\r",tab:" ",escape:"\x1B",esc:"\x1B",backspace:"\x7F",home:"\x1B[H",end:"\x1B[F",delete:"\x1B[3~"};if(!i&&!s&&!o&&c[t]!==void 0)return c[t];if(s&&!i&&!o&&c[t]!==void 0)return`\x1B${c[t]}`;let d={up:"A",down:"B",right:"C",left:"D",home:"H",end:"F"}[t];if(d!==void 0)return!i&&!s&&!o?`\x1B[${d}`:`\x1B[1;${1+(o?1:0)+(s?2:0)+(i?4:0)}${d}`;if(s&&!i&&t.length===1)return`\x1B${o?t.toUpperCase():t}`;throw new Error(`Unsupported terminal key ${e}`)}a(Tn,"encodeTerminalKey");async function Te(e,n){let t=e.process;if(t!==void 0){if(globalThis.process.platform!=="win32")try{globalThis.process.kill(-t.pid,n?"SIGKILL":"SIGTERM");return}catch{try{t.kill(n?"SIGKILL":"SIGTERM")}catch{}return}await new Promise(r=>{let i=an("taskkill.exe",["/PID",String(t.pid),"/T",...n?["/F"]:[]],{windowsHide:!0,stdio:"ignore"});i.once("error",()=>r()),i.once("exit",()=>r())})}}a(Te,"terminateProcessTree");function B(e){return new Promise(n=>setTimeout(n,e))}a(B,"delay");function bn(e){return e instanceof Error?e.message:String(e)}a(bn,"errorMessage");import xn from"node:os";import xe from"node:path";function $e(e=process.platform,n=process.env){if(e==="win32"){let i=n.SHELL?.trim()||"powershell.exe",s=xe.win32.basename(i).toLowerCase();return s==="cmd"||s==="cmd.exe"?{executable:i,displayName:"Command Prompt",family:"cmd",commandArgs:a(o=>["/d","/s","/c",o],"commandArgs")}:{executable:i,displayName:s.startsWith("pwsh")?"PowerShell":"Windows PowerShell",family:"powershell",commandArgs:a(o=>["-NoLogo","-NoProfile","-Command",o],"commandArgs")}}let t=n.SHELL?.trim()||xn.userInfo().shell||(e==="darwin"?"/bin/zsh":"/bin/bash"),r=xe.basename(t);return{executable:t,displayName:r==="zsh"?"zsh":r==="bash"?"Bash":r,family:"posix",commandArgs:a(i=>["-c",i],"commandArgs")}}a($e,"resolveShellProfile");function Ce(e){switch(e.family){case"powershell":return"Write PowerShell syntax. Use PowerShell cmdlets, `$env:NAME` for environment variables, and `;` or pipelines to compose commands.";case"cmd":return"Write Command Prompt syntax. Use `%NAME%` for environment variables and `&&` to chain successful commands.";case"posix":return`Write ${e.displayName} syntax. Use POSIX-style paths, \`$NAME\` for environment variables, and \`&&\` or pipelines to compose commands.`}}a(Ce,"shellSyntaxGuidance");import Ee from"node:path";import{stripVTControlCharacters as Re}from"node:util";import{defineTool as $n}from"@earendil-works/pi-coding-agent";import{Type as w}from"typebox";var Cn=w.Object({command:w.String({minLength:1,description:"Command written in the syntax of the configured system shell"}),background:w.Optional(w.Boolean({description:"Return immediately while the terminal session continues. Defaults to false."})),cwd:w.Optional(w.String({description:"Working directory. Relative paths resolve from the current workspace."})),cols:w.Optional(w.Integer({minimum:20,maximum:300,description:"Virtual terminal width in cells"})),rows:w.Optional(w.Integer({minimum:5,maximum:120,description:"Virtual terminal height in cells"}))},{additionalProperties:!1});function Pe(e,n,t,r){e.registerTool($n({name:"run",label:`${t.displayName} run`,promptSnippet:`Run ${t.displayName} commands in synchronous or background terminal sessions`,promptGuidelines:[`Write commands for ${t.displayName}; commands are not translated between shell languages.`,"Use background for servers, watchers, long builds, and work that can finish while you continue. Use the returned shell: source with read, write, insert, and delete."],description:`Use run to execute a command in the user's configured ${t.displayName} shell (${t.executable}). Every call creates an addressable terminal session. Set background to true to continue without waiting; completion is delivered automatically and wakes the agent. ${Ce(t)}`,parameters:Cn,async execute(i,s,o,c,u){r.bind(u);let d=s.cwd===void 0?u.cwd:Ee.resolve(u.cwd,s.cwd),l=n.start({command:s.command,background:s.background??!1,cwd:d,shell:t,...s.cols===void 0?{}:{cols:s.cols},...s.rows===void 0?{}:{rows:s.rows}});if(s.background===!0&&l.status!=="failed")return await Rn(n,l,c),l.status!=="running"&&(l.completionDelivered=!0),A(n.snapshot(l));if(l.status==="failed")return A(n.snapshot(l));let f=await n.wait(l.source,o);return A(n.snapshot(f))},renderCall(i,s){let o=typeof i.command=="string"?i.command:"",c=typeof i.cwd=="string"?Ee.resolve(process.cwd(),i.cwd):process.cwd();return le(o,i.background===!0,c,t,s)},renderResult(i,s,o){return ue(i.details,s.expanded,o)}}))}a(Pe,"registerTerminalTools");function A(e){let n=En(e.output);return{content:[{type:"text",text:[`session: ${e.source}`,`status: ${e.status}`,`shell: ${e.shell}`,`cwd: ${e.cwd}`,`elapsedMs: ${e.elapsedMs}`,e.exitCode===void 0?void 0:`exitCode: ${e.exitCode}`,e.signal===void 0?void 0:`signal: ${e.signal}`,e.error===void 0?void 0:`error: ${e.error}`,`outputRange: ${e.outputStart}-${e.outputEnd}`,e.truncated?"output: truncated; use read for the retained log":void 0,n.length===0?"output: (empty)":`output:
|
|
18
|
+
${n}`].filter(r=>r!==void 0).join(`
|
|
19
|
+
`)}],details:e,isError:e.status==="failed"||e.status==="lost"}}a(A,"terminalResult");function En(e){let n=Re(e).trimEnd();return n.length<=8e3?n:`[earlier output omitted]
|
|
20
|
+
${n.slice(-8e3)}`}a(En,"outputExcerpt");async function Rn(e,n,t){await new Promise(r=>{let i=!1,s,o=a(()=>{},"unsubscribe"),c=a(()=>{i||(i=!0,clearTimeout(s),o(),r())},"finish"),u=a(()=>{let d=e.snapshot(n);t?.(A(d)),(Re(d.output).replaceAll("\r","").split(`
|
|
21
|
+
`).filter(f=>f.length>0).length>=x||d.status!=="running")&&c()},"publish");o=e.onDidChange(d=>{d.id===n.id&&u()}),s=setTimeout(c,2e3),u()})}a(Rn,"captureInitialBackgroundPreview");import{DynamicBorder as ke}from"@earendil-works/pi-coding-agent";import{Box as Pn,Container as ve,Key as Ae,matchesKey as Ie,SelectList as kn,Text as T,truncateToWidth as vn}from"@earendil-works/pi-tui";var An=120,I=class{constructor(n,t,r){this.pi=n;this.manager=t;this.activityMode=r;n.registerMessageRenderer("terminal-completion",(i,{expanded:s},o)=>{let c=new ve;for(let d of Ln(i.details))c.addChild(C(d,s,o));let u=new Pn(1,1,d=>o.bg("toolSuccessBg",d));return u.addChild(c),u}),t.onDidChange(()=>this.#r()),t.onDidComplete(i=>{i.background&&this.#a(i),this.#r()}),n.registerCommand("terminals",{description:"Show active and recent terminal sessions",handler:a(async(i,s)=>{if(this.bind(s),s.mode!=="tui"){s.ui.notify("The terminal session overlay requires the TUI.","info");return}await this.#o(s)},"handler")})}static{a(this,"TerminalUi")}#s=new Map;#e;#t;#n;#i=!1;bind(n){this.#i||(this.#e=n,this.#r())}dispose(){this.#i=!0,this.#t!==void 0&&clearTimeout(this.#t),this.#n!==void 0&&clearInterval(this.#n),this.#t=void 0,this.#n=void 0,this.#e?.ui.setWidget("agent-terminal",void 0),this.#e?.ui.setStatus("agent-terminal",void 0),this.#s.clear(),this.#e=void 0}#a(n){this.#i||n.completionDelivered||(this.#s.set(n.id,n),this.#t===void 0&&(this.#t=setTimeout(()=>{this.#t=void 0;let t=[...this.#s.values()].filter(s=>!s.completionDelivered);if(this.#s.clear(),this.#i||t.length===0)return;for(let s of t)s.completionDelivered=!0;let r=t.map(s=>this.manager.snapshot(s)),i=_n(r);this.pi.sendMessage({customType:"terminal-completion",display:!0,content:i,details:{sessions:r}},{triggerTurn:!0,deliverAs:"steer"})},An)))}#r(){let n=this.#e;if(this.#i||n===void 0||!n.hasUI)return;let t=this.manager.list().filter(r=>r.status==="running"||r.status==="stopping");if(this.activityMode==="off"){n.ui.setWidget("agent-terminal",void 0),n.ui.setStatus("agent-terminal",void 0);return}if(t.length===0){n.ui.setWidget("agent-terminal",void 0),n.ui.setStatus("agent-terminal",void 0),this.#n!==void 0&&clearInterval(this.#n),this.#n=void 0;return}if(this.activityMode==="compact"){n.ui.setWidget("agent-terminal",void 0),n.ui.setStatus("agent-terminal",`terminals: ${t.length}`);return}n.ui.setStatus("agent-terminal",void 0),n.ui.setWidget("agent-terminal",(r,i)=>({invalidate(){},render:a(s=>de(t,s,i),"render")}),{placement:"belowEditor"}),this.#n===void 0&&(this.#n=setInterval(()=>this.#r(),1e3))}async#o(n){for(;;){let t=this.manager.list().filter(i=>i.status==="running"||i.status==="stopping");if(t.length===0){n.ui.notify("No active terminal sessions.","info");return}let r=await n.ui.custom((i,s,o,c)=>{let u=t.map(m=>({value:m.source,label:`${m.status} ${q(m.elapsedMs)} ${m.shell}`,description:Dn(m.command,90)})),d=new kn(u,Math.min(u.length,12),{selectedPrefix:a(m=>s.fg("accent",m),"selectedPrefix"),selectedText:a(m=>s.fg("accent",m),"selectedText"),description:a(m=>s.fg("muted",m),"description"),scrollInfo:a(m=>s.fg("dim",m),"scrollInfo"),noMatch:a(m=>s.fg("warning",m),"noMatch")}),l="list",f;return d.onSelect=m=>{f=m.value,l="detail"},d.onCancel=()=>c(null),{render:a(m=>{let p=new ve;if(p.addChild(new ke(g=>s.fg("accent",g))),l==="list")p.addChild(new T(s.fg("accent",s.bold("Terminal sessions")),1,0)),p.addChild(d),p.addChild(new T(s.fg("dim","enter view \xB7 d delete \xB7 esc close"),1,0));else{let g=f===void 0?void 0:this.manager.get(f);if(g===void 0)p.addChild(new T(s.fg("warning","Terminal is no longer available."),1,0));else{let y=this.manager.snapshot(g);p.addChild(new T(s.fg("accent",s.bold(`${y.shell} terminal`)),1,0)),p.addChild(new T(s.fg("muted",vn(`${y.status} \xB7 ${q(y.elapsedMs)} \xB7 ${y.cwd}`,Math.max(1,m-2))),1,0)),p.addChild(new T(s.fg("text",`$ ${y.command}`),1,0));let b=In(this.manager.screenRows(g),24);p.addChild(new T(b.map(R=>s.fg("toolOutput",R||" ")).join(`
|
|
22
|
+
`),1,0)),p.addChild(new T(s.fg(l==="confirm"?"warning":"dim",l==="confirm"?"Delete this terminal session? y confirm \xB7 n/esc cancel":"esc back \xB7 d delete"),1,0))}}return p.addChild(new ke(g=>s.fg("accent",g))),p.render(m)},"render"),handleInput:a(m=>{l==="list"?m==="d"?(f=d.getSelectedItem()?.value,f!==void 0&&(l="confirm")):d.handleInput(m):l==="detail"?Ie(m,Ae.escape)?l="list":m==="d"&&(l="confirm"):m==="y"&&f!==void 0?c({kind:"delete",source:f}):(m==="n"||Ie(m,Ae.escape))&&(l="detail"),i.requestRender()},"handleInput"),invalidate:a(()=>d.invalidate(),"invalidate")}},{overlay:!0,overlayOptions:{width:"75%",maxHeight:"80%",minWidth:52}});if(r===null)return;await this.manager.delete(r.source),n.ui.notify("Terminal session deleted.","info")}}};function In(e,n){let t=e.findIndex(i=>i.length>0);if(t===-1)return["(no visible output)"];let r=e.length-1;for(;r>t&&e[r]?.length===0;)r-=1;return e.slice(Math.max(t,r-n+1),r+1)}a(In,"visibleScreenTail");function Ln(e){return!Le(e)||!Array.isArray(e.sessions)?[]:e.sessions.filter(Mn)}a(Ln,"completionSnapshots");function Mn(e){return Le(e)&&typeof e.id=="string"&&typeof e.source=="string"&&typeof e.command=="string"&&typeof e.cwd=="string"&&typeof e.shell=="string"&&(e.shellFamily==="posix"||e.shellFamily==="powershell"||e.shellFamily==="cmd")&&typeof e.background=="boolean"&&typeof e.status=="string"&&typeof e.startedAt=="number"&&typeof e.elapsedMs=="number"&&typeof e.output=="string"&&typeof e.outputStart=="number"&&typeof e.outputEnd=="number"&&typeof e.truncated=="boolean"&&typeof e.cols=="number"&&typeof e.rows=="number"}a(Mn,"isTerminalSessionSnapshot");function _n(e){return`${e.length===1?"Background terminal completed:":"Background terminals completed:"}
|
|
23
|
+
${e.map(t=>{let r=t.exitCode===void 0?"":`, exit ${t.exitCode}`,i=t.output.trimEnd().slice(-2e3);return`- ${t.source}: ${t.status}${r}, ${q(t.elapsedMs)}
|
|
24
|
+
${i||"(no output)"}`}).join(`
|
|
25
|
+
`)}`}a(_n,"formatCompletionMessage");function Dn(e,n=60){let t=e.replaceAll(/\s+/gu," ").trim();return t.length<=n?t:`${t.slice(0,n-1)}\u2026`}a(Dn,"shortCommand");function q(e){return e<1e3?`${e}ms`:`${(e/1e3).toFixed(e<1e4?1:0)}s`}a(q,"formatElapsed");function Le(e){return typeof e=="object"&&e!==null}a(Le,"isRecord");async function On(e){let n=new v,t=$e(),r=await re(te()),i=Nn(r.preferences?.["terminal.activity"]),s=new I(e,n,i);await Promise.all([he(e,n),we(e,n)]),Pe(e,n,t,s),e.on("session_start",(o,c)=>s.bind(c)),e.on("session_shutdown",async()=>{s.dispose(),await n.dispose()})}a(On,"registerTerminal");function Nn(e){return e==="compact"||e==="off"?e:"detailed"}a(Nn,"terminalActivityMode");export{On as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as c}from"./chunk-S3ZPXWX7.js";import{e as a}from"./chunk-
|
|
1
|
+
import{d as c}from"./chunk-S3ZPXWX7.js";import{e as a}from"./chunk-5VSE5X5R.js";import{a as r}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as i}from"typebox/value";var n="pi-agent-text-editor",p=21,P="pi-agent-text-editor/position",I="pi-agent-text-editor/search",S=`${n}/core/ready`,b=`${n}/plugin/register`,s=e.Function([],e.Unknown()),d=e.Object({tryResolve:s},{additionalProperties:!0}),l=e.Object({lineNumber:e.Integer({minimum:1}),column:e.Integer({minimum:0})}),T=e.Object({start:l,end:l,linewise:e.Optional(e.Boolean())}),x=e.Object({source:e.String({minLength:1}),ranges:e.Optional(e.Array(T))}),R=e.Union([e.Object({kind:e.Literal("not-handled")},{additionalProperties:!0}),e.Object({kind:e.Literal("resolved"),targets:e.Array(x,{minItems:1})},{additionalProperties:!0}),e.Object({kind:e.Literal("rejected"),rejection:e.Object({code:e.Union([e.Literal("invalid"),e.Literal("stale"),e.Literal("missing"),e.Literal("ambiguous")]),reason:e.String(),contextRange:e.Optional(e.Object({offset:e.Number(),limit:e.Number()}))})},{additionalProperties:!0}),e.Object({kind:e.Literal("failed"),error:e.Unknown()},{additionalProperties:!0})]),g=e.String({pattern:"\\S"}),m=e.Object({resolver:e.Unknown(),priority:e.Optional(e.Number())}),y=e.Object({resolver:e.Unknown(),resources:e.Optional(e.Unknown()),kind:e.String({pattern:"\\S"}),type:e.Union([e.Literal("major"),e.Literal("auxiliary"),e.Literal("constant")]),priority:e.Optional(e.Number())}),v=e.Object({protocol:e.Literal(n),apiVersion:e.Literal(p)}),u=e.Object({protocol:e.Literal(n),apiVersion:e.Literal(p),id:e.String(),setup:s}),E=e.Object({plugin:u,accept:s});function k(t){return i.Check(g,t)}r(k,"isTextEditorToolId");function _(t){if(!i.Check(m,t))return!1;let o=t;return c(o.resolver)&&(!("priority"in o)||typeof o.priority=="number")}r(_,"isResourceResolverRegistration");function C(t){if(!i.Check(y,t))return!1;let o=t;return a(o.resolver)&&(!("resources"in o)||i.Check(d,o.resources))&&(!("priority"in o)||typeof o.priority=="number")}r(C,"isTextAnchorResolverRegistration");function j(t){return i.Check(R,t)}r(j,"isTextAnchorResourceResolutionAttempt");function w(t){return i.Check(v,t)}r(w,"isTextEditorCoreReady");function L(t){return i.Check(u,t)}r(L,"isTextEditorPlugin");function N(t){return i.Check(E,t)}r(N,"isTextEditorPluginRegistrationRequest");export{n as a,p as b,P as c,I as d,S as e,b as f,k as g,_ as h,C as i,j,w as k,L as l,N as m};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./chunk-EI7MMDWY.js";var t=Symbol.for("pi-agent-text-editor.last-resolved-resource");function i(e,o){if(!u(o))return;if(Array.isArray(o.resources))for(let c of o.resources)u(c)&&i(e,c.details);let n=o.source,s=o.resolvedBy;typeof n!="string"||n.length===0||typeof s!="string"||s.length===0||(e[t]={source:n,resolverId:s})}r(i,"rememberLastResolvedResource");function R(e){return e[t]}r(R,"getLastResolvedResource");function d(e){e[t]=void 0}r(d,"clearLastResolvedResource");function u(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}r(u,"isRecord");export{i as a,R as b,d as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o}from"./chunk-EI7MMDWY.js";var t="pi-agent-ide",r=
|
|
1
|
+
import{a as o}from"./chunk-EI7MMDWY.js";var t="pi-agent-ide",r=4,s="pi-agent-ide/core/ready",a="pi-agent-ide/plugin/register";function d(e){return n(e)&&e.protocol===t&&e.apiVersion===4}o(d,"isIdeCoreReady");function i(e){return n(e)&&e.protocol===t&&e.apiVersion===4&&typeof e.id=="string"&&e.id.length>0&&typeof e.setup=="function"}o(i,"isIdePlugin");function c(e){return n(e)&&i(e.plugin)&&typeof e.accept=="function"}o(c,"isIdePluginRegistrationRequest");function n(e){return typeof e=="object"&&e!==null}o(n,"isRecord");export{t as a,r as b,s as c,a as d,d as e,i as f,c as g};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as y}from"./chunk-
|
|
1
|
+
import{a as y}from"./chunk-GUTQ3PWL.js";import{a as s}from"./chunk-EI7MMDWY.js";import{Worker as v}from"node:worker_threads";var p=String.raw`
|
|
2
2
|
const { parentPort, workerData } = require("node:worker_threads");
|
|
3
3
|
let fuzzy;
|
|
4
4
|
let prepared;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c,d,e as u}from"./chunk-
|
|
1
|
+
import{c,d,e as u}from"./chunk-7UGNGK7Y.js";import{a as r}from"./chunk-EI7MMDWY.js";function E(t,o){let s=r(()=>{let e,i={plugin:o,accept(g){if(e!==void 0)throw new Error(`Plugin ${o.id} registration was accepted more than once`);e=g}};return t.events.emit(d,i),e},"announce"),n=r(()=>{},"unsubscribe");n=t.events.on(c,e=>{if(!u(e))throw new Error("Invalid pi-agent-search core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-search core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),t.on("session_shutdown",n);let a=s();if(a!==void 0)return n(),a}r(E,"connectSearchPlugin");export{E as a};
|
package/dist/entry-0.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-NTYXZ3EL.js";import"./chunk-5VSE5X5R.js";import"./chunk-KINKBPPX.js";import"./chunk-ZC65Z3CK.js";import"./chunk-EI7MMDWY.js";export{h as addDiagnosticAnnotations,g as createDiagnosticViewContent,l as createSourceMappedTextReadHandler,i as diagnosticStatus,c as formatCodeViewReference,f as formatDiagnosticViewSource,k as formatSourceViewResults,d as formatSymbolSelector,a as parseCodeViewReference,j as renderSourceViewLine,b as resolveCodeViewPath,e as resolveDiagnosticViewPath};
|
package/dist/entry-1.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-HKMBQLEK.js";import"./chunk-Z3VC3S2T.js";import"./chunk-EI7MMDWY.js";export{a as connectIdePlugin};
|
package/dist/entry-10.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,b as c,c as d,d as g,e as h,f as i}from"./chunk-
|
|
1
|
+
import{a as b,b as c,c as d,d as g,e as h,f as i,g as j}from"./chunk-5MSNYFDE.js";import"./chunk-NNCZYO4Q.js";import{d as a}from"./chunk-3SE372WC.js";import"./chunk-YHUTTZC6.js";import{a as x}from"./chunk-72EEL2DW.js";import{a as o,b as r,c as e,d as f,e as m,f as p,g as t}from"./chunk-KAB3AYA2.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import"./chunk-EI7MMDWY.js";export{r as READ_API_VERSION,e as READ_CORE_READY_EVENT,f as READ_PLUGIN_REGISTER_EVENT,o as READ_PROTOCOL,x as connectReadPlugin,a as createReadResultRenderer,i as isFragmentResolverRegistration,m as isReadCoreReady,j as isReadFragmentResolution,g as isReadHandlerRegistration,p as isReadPlugin,t as isReadPluginRegistrationRequest,h as isReadViewRegistration,d as isResourceResolverRegistration,c as isTextTargetResolverRegistration,b as readParameters};
|
package/dist/entry-12.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-
|
|
1
|
+
import"./chunk-ROXXK6TW.js";import{a}from"./chunk-HGPUI7F3.js";import{a as x}from"./chunk-ZTYWHL2F.js";import{a as o,b as r,c as e,d as f,e as m,f as p,g as t}from"./chunk-7UGNGK7Y.js";import"./chunk-EI7MMDWY.js";export{r as SEARCH_API_VERSION,e as SEARCH_CORE_READY_EVENT,f as SEARCH_PLUGIN_REGISTER_EVENT,o as SEARCH_PROTOCOL,x as connectSearchPlugin,m as isSearchCoreReady,p as isSearchPlugin,t as isSearchPluginRegistrationRequest,a as searchSchema};
|
package/dist/entry-13.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s}from"./chunk-
|
|
1
|
+
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s}from"./chunk-5VSE5X5R.js";import"./chunk-EI7MMDWY.js";export{o as TextAnchor,r as attachTextAnchorRenderer,j as createTextContentConverter,g as createTextDocument,e as getTextAnchorRenderer,a as getTextSourceLine,t as isTextAnchorRecoveryOutcome,p as isTextAnchorResolutionAttempt,m as isTextAnchorResolver,c as isTextLinePresenter,d as isTextPresenterRegistration,n as isTextTargetResolutionAttempt,k as isTextualMediaType,i as renderPresentedTextDocument,x as renderPresentedTextRows,f as renderTextAnchor,h as renderTextDocument,s as restoreText,q as storeText,l as textFromAgentContent,b as withTextSourceLine};
|
package/dist/entry-14.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{l as t}from"./chunk-DQF5QMJ2.js";import{a as E}from"./chunk-TI5GMJ7Q.js";import{a as o,b as e,c as r,d as i,e as n,f as a,g as p,h as x,i as s,j as d,k as f,l as u,m}from"./chunk-Y7ZMR4LT.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import"./chunk-EI7MMDWY.js";export{e as TEXT_EDITOR_API_VERSION,n as TEXT_EDITOR_CORE_READY_EVENT,a as TEXT_EDITOR_PLUGIN_REGISTER_EVENT,o as TEXT_EDITOR_PROTOCOL,r as TEXT_POSITION_ANCHOR_KIND,i as TEXT_SEARCH_ANCHOR_KIND,E as connectTextEditorPlugin,t as connectTextEditorPostEditHandler,x as isResourceResolverRegistration,s as isTextAnchorResolverRegistration,d as isTextAnchorResourceResolutionAttempt,f as isTextEditorCoreReady,u as isTextEditorPlugin,m as isTextEditorPluginRegistrationRequest,p as isTextEditorToolId};
|
package/dist/entry-2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g}from"./chunk-Z3VC3S2T.js";import"./chunk-EI7MMDWY.js";export{b as IDE_API_VERSION,c as IDE_CORE_READY_EVENT,d as IDE_PLUGIN_REGISTER_EVENT,a as IDE_PROTOCOL,e as isIdeCoreReady,f as isIdePlugin,g as isIdePluginRegistrationRequest};
|
package/dist/entry-21.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./chunk-NNCZYO4Q.js";import{
|
|
1
|
+
import"./chunk-NNCZYO4Q.js";import{d as v}from"./chunk-3SE372WC.js";import"./chunk-YHUTTZC6.js";import{a as R}from"./chunk-72EEL2DW.js";import{a as y,b as p}from"./chunk-KAB3AYA2.js";import{a as w}from"./chunk-TI5GMJ7Q.js";import{a as h,b as F}from"./chunk-Y7ZMR4LT.js";import{a as g,u as m}from"./chunk-S3ZPXWX7.js";import{r as f}from"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import{a as o}from"./chunk-EI7MMDWY.js";import{readdirSync as x,realpathSync as H,statSync as S}from"node:fs";import{mkdir as k,readFile as D,writeFile as O}from"node:fs/promises";import b from"node:path";import{fileURLToPath as I,pathToFileURL as _}from"node:url";function T(e){return P("read",e)}o(T,"createFilesystemReadResolver");function C(e){return P("write",e)}o(C,"createFilesystemWriteResolver");function P(e,s){return{id:"filesystem",tryResolve(t,i){return Promise.resolve(L(t,i,e,s))}}}o(P,"createFilesystemResolver");function L(e,s,t,i){if(e.length===0)return{kind:"failed",error:new TypeError("Filesystem source must not be empty")};if(!W(e))return{kind:"not-handled"};if(s.signal?.aborted===!0)return{kind:"failed",error:E()};let r=e.startsWith("file://")?H(I(new URL(e))):b.resolve(s.cwd,e),l=_(r).href,c=(()=>{try{return S(r).isDirectory()}catch{return!1}})(),n=o(async({signal:d})=>c?U(r,d):V(r,i,d),"read");return t==="read"||c?{kind:"resolved",resource:{source:r,link:l,read:n}}:{kind:"resolved",resource:{source:r,link:l,read:n,async write(d,u){a(u.signal);let A=f(d);await k(b.dirname(r),{recursive:!0}),a(u.signal),await O(r,A,{encoding:"utf8",...u.signal!==void 0&&{signal:u.signal}})}}}}o(L,"resolveFilesystemSource");function U(e,s){a(s);let t=x(e,{withFileTypes:!0}),i=[`\u{1F4C1} ${e}/`];t.length>0&&i.push("");for(let r of t){let l=r.isDirectory()?"\u{1F4C1}":r.isFile()?"\u{1F4C4}":"\u{1F517}";i.push(` ${l} ${r.name}`)}return[{type:"text",text:i.join(`
|
|
2
2
|
`)}]}o(U,"readDirectoryContent");async function V(e,s,t){a(t);let i=await D(e,{encoding:null,...t!==void 0&&{signal:t}});return a(t),s.convert({source:e,bytes:i},t===void 0?{}:{signal:t})}o(V,"readFilesystemContent");function W(e){return/^[A-Za-z]:[\\/]/u.test(e)||e.startsWith("file://")?!0:!/^[A-Za-z][A-Za-z\d+.-]*:/u.test(e)}o(W,"isFilesystemSource");function a(e){if(e?.aborted===!0)throw E()}o(a,"throwIfAborted");function E(){let e=new Error("The operation was aborted");return e.name="AbortError",e}o(E,"abortError");var z={provider:"filesystem",capability:"read"},Z={provider:"filesystem",capability:"write"},$=v({kind:"source",nativeResources:!0});async function j(e){let s=m(e,z),t=m(e,Z),i=T(s),r=C(t),l={protocol:y,apiVersion:p,id:"filesystem",setup(n){n.addResolver({resolver:i,renderResult:$}),n.describe(()=>g("File path \u2014 file content; directory path \u2014 entry listing. Relative, absolute and file:// paths accepted.",s.listDescriptions())),n.addPromptGuideline("Use read with paths relative to the current working directory for project files. Use read with absolute paths for files elsewhere on the system.")}},c={protocol:h,apiVersion:F,id:"filesystem",setup(n){n.addResolver({resolver:r})}};await Promise.all([R(e,l),w(e,c)])}o(j,"registerFilesystemPlugin");export{j as default};
|
package/dist/entry-24.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v as t}from"./chunk-S3ZPXWX7.js";import{p as i}from"./chunk-
|
|
1
|
+
import{v as t}from"./chunk-S3ZPXWX7.js";import{p as i}from"./chunk-5VSE5X5R.js";import{a as r}from"./chunk-EI7MMDWY.js";var o=i(),n={target:{provider:"filesystem",capability:"read"},converter:o,priority:300},s={target:{provider:"filesystem",capability:"write"},converter:o,priority:300};async function a(e){await Promise.all([t(e,n),t(e,s)])}r(a,"registerFilesystemText");export{a as default};
|
package/dist/entry-25.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,b as o}from"./chunk-
|
|
1
|
+
import{a as e,b as o}from"./chunk-B5KB2I7J.js";import"./chunk-5VSE5X5R.js";import"./chunk-EI7MMDWY.js";export{o as AstScopeManager,e as parseDocument};
|
package/dist/entry-26.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as j,b as V}from"./chunk-B5KB2I7J.js";import{a as T}from"./chunk-ERVMDQGX.js";import{a as L,b as E}from"./chunk-VFBLX4TG.js";import"./chunk-NNCZYO4Q.js";import{d as $}from"./chunk-3SE372WC.js";import"./chunk-YHUTTZC6.js";import{a as k}from"./chunk-72EEL2DW.js";import{a as P,b as M}from"./chunk-KAB3AYA2.js";import{a as N}from"./chunk-ZTYWHL2F.js";import{a as I,b as C}from"./chunk-7UGNGK7Y.js";import{a as B}from"./chunk-TI5GMJ7Q.js";import{a as _,b as D,c as H}from"./chunk-Y7ZMR4LT.js";import"./chunk-S3ZPXWX7.js";import{a as R,b,c as w,l as v}from"./chunk-NTYXZ3EL.js";import"./chunk-5VSE5X5R.js";import"./chunk-KINKBPPX.js";import{j as O}from"./chunk-M5MJP7Z2.js";import"./chunk-WZI4YC2O.js";import{e as x}from"./chunk-N34ATN52.js";import"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";import{readFile as te}from"node:fs/promises";var y=new Set(["c","cpp","javascript","typescript","python","rust","json","yaml","toml"]),G={protocol:L,apiVersion:1,id:"ast",setup(o){o.addSetupCheck({id:"structural-search",async inspect(e){return[...e.detectedLanguageIds].some(s=>y.has(s))?await O({command:["ast-grep"]},e.cwd,e.env)?{}:{actions:[{id:"ast-grep-unavailable",message:"Structural search is unavailable because ast-grep was not found"}]}:{}}}),o.addCheck({id:"parsers",title:"AST",async run(e){let n=[];for(let s of e.detectedLanguageIds){if(!y.has(s))continue;let t=e.files.find(r=>ne(r,s));if(t!==void 0)try{let r=await te(t,"utf8"),a=await j(t,e.cwd,r.replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`).split(`
|
|
4
|
-
`));
|
|
5
|
-
`),"format");
|
|
6
|
-
`,a=
|
|
7
|
-
`)}],details:
|
|
4
|
+
`));n.push(a===void 0?{status:"fail",message:`${s} parser did not return a tree`}:{status:"pass",message:`${s} parser loaded`,detail:t})}catch(r){n.push({status:"fail",message:`${s}: ${r instanceof Error?r.message:String(r)}`})}}return n.length>0?n:[{status:"skip",message:"No supported AST files found"}]}}),o.addCheck({id:"ast-grep",title:"Structural search",async run(e){if(![...e.detectedLanguageIds].some(s=>y.has(s)))return[{status:"skip",message:"No supported structural-search files found"}];let n=await x("ast-grep",["--version"],e.cwd,e.env);return[n.ok?{status:"pass",message:"ast-grep is available",detail:n.detail}:{status:"fail",message:"ast-grep is not available",detail:n.detail}]}})}};function ne(o,e){let n=o.slice(o.lastIndexOf(".")).toLowerCase();return{c:[".c",".h"],cpp:[".cc",".cpp",".cxx",".hh",".hpp",".hxx"],javascript:[".js",".jsx",".mjs",".cjs"],typescript:[".ts",".tsx",".mts",".cts"],python:[".py",".pyi"],rust:[".rs"],json:[".json",".jsonc"],yaml:[".yaml",".yml"],toml:[".toml"]}[e]?.includes(n)??!1}d(ne,"matchesLanguage");var re,se;function F(o){return{id:"ast",tryResolve(e,n){return Promise.resolve(oe(e,n,o))}}}d(F,"createAstOutlineResolver");function oe(o,e,n){let s;try{s=R(o,"ast")}catch(a){return{kind:"failed",error:a}}if(s===void 0)return{kind:"not-handled"};let t;try{t=b(s.path,e.cwd)}catch(a){return{kind:"failed",error:a}}return{kind:"resolved",resource:{source:w("ast",t),async read({signal:a}){a?.throwIfAborted();let i=await(se??=import("./chunk-TPIHQYK2.js")),c=await(n??(re??=new i.AstOutlineManager)).readFileOutline(t,e.cwd);return a?.throwIfAborted(),[i.formatAstOutline(c)]}}}}d(oe,"resolveAstOutlineSource");import{DEFAULT_MAX_BYTES as ae,DEFAULT_MAX_LINES as ie,truncateHead as A}from"@earendil-works/pi-coding-agent";var S=d(async(o,e,n)=>{let{source:s,resolvedBy:t,lines:r,totalLines:a,startLine:i}=o.details;if(!(s===void 0||t!=="filesystem"||r===void 0||r.length!==a||i!==void 0&&i!==1))try{let{AstOutlineManager:u,isSupportedOutlinePath:c}=await import("./chunk-TPIHQYK2.js");if(!c(s))return;let l=d(m=>[`AST overview of ${m.path}, source lines 1-${m.totalLines}: the requested text exceeded the read buffer.`,"Source line numbers are on the left. Detail is reduced to fit the buffer; omitted bodies are not exact source text. Read a small source range when needed.",...m.renderedLines.map(g=>`${g.sourceLine?.lineNumber??"\u2026"} | ${g.text}`)].join(`
|
|
5
|
+
`),"format");e.signal?.throwIfAborted();let p=await new u(12).readDocumentOutline(s,e.cwd,r.map(m=>m.content),m=>(e.signal?.throwIfAborted(),!A(l(m),n).truncated)),f=l(p);return A(f,n).truncated?void 0:{content:[{type:"text",text:f}],details:{source:s,resolvedBy:"ast-overflow"}}}catch{e.signal?.throwIfAborted();return}},"reduceAstReadOutput");function X(){return async o=>{let{state:e,result:n}=o,s=n?.content.length===1?n.content[0]:void 0;if(o.audience==="script"||n===void 0||e?.contentKind!=="text"||e.resolvedBy!=="filesystem"||s?.type!=="text"||!A(s.text).truncated)return{kind:"continue",context:o};let t=await S({...n,details:{...n.details,source:e.source,resolvedBy:e.resolvedBy,lines:e.text.lines,startLine:1,totalLines:e.text.lines.length}},o.resolverContext,{maxBytes:ae,maxLines:ie});return t===void 0?{kind:"continue",context:o}:{kind:"return",result:t}}}d(X,"createAstOverflowHandler");var z="pi-agent-ast";function K(o){return{id:"ast-scopes",async present(e,n){if(n.resolvedBy!=="filesystem")return e;try{let s=await o.getDocumentScopes(e.source,n.cwd,e.lines.map(r=>r.content)),t=ce(e.lines,s);return t===e.lines?e:{...e,lines:t}}catch{return e}}}}d(K,"createAstScopePresenter");function U(){return o=>{let e=o.state,n=o.result;if(e?.contentKind!=="text"||n===void 0)return{kind:"continue",context:o};let s=n.details.lines;if(s===void 0)return{kind:"continue",context:o};let t=new Map(e.text.lines.map(l=>[l.lineNumber,l])),r=new Set(s.map(l=>l.lineNumber)),a=new Map;for(let l of s){let p=t.get(l.lineNumber),f=J(p);for(let m of f?.boundaries??[]){if(r.has(m.endLine))continue;let g=t.get(m.endLine);g!==void 0&&a.set(m.endLine,g)}}if(a.size===0)return{kind:"continue",context:o};let i=[...a.values()].sort((l,p)=>l.lineNumber-p.lineNumber),u=[...s,...i],c=de(n,u,s.at(-1));return{kind:"continue",context:{...o,result:c}}}}d(U,"createAstScopePostReadHandler");function ce(o,e){if(e.length===0)return o;let n=new Map,s=new Map;for(let t of e){let r=n.get(t.startLine)??[];r.push(t.beginAnchor.value),n.set(t.startLine,r);let a=s.get(t.startLine)??[];a.push({endLine:t.endLine,beginAnchor:t.beginAnchor.value,endAnchor:t.endScopeAnchor.value}),s.set(t.startLine,a);let i=n.get(t.endLine)??[];i.push(t.endScopeAnchor.value),n.set(t.endLine,i)}return o.map(t=>{let r=n.get(t.lineNumber),a=s.get(t.lineNumber);return r===void 0&&a===void 0?t:{...t,...r!==void 0&&{anchors:[...new Set([...t.anchors??[],...r])],presentation:{...t.presentation,suffix:`${t.presentation?.suffix??""}${r.map(i=>` <!-- ${i} -->`).join("")}`}},metadata:{...t.metadata,[z]:{...J(t),...a!==void 0&&{boundaries:a}}}}})}d(ce,"addScopeMarkers");function J(o){let e=o?.metadata?.[z];if(!(typeof e!="object"||e===null))return e}d(J,"getAstScopeMetadata");function de(o,e,n){let s=o.content.length===1?o.content[0]:void 0;if(s?.type!=="text"||o.details.lines===void 0)return o;let t=e.slice(o.details.lines.length);if(t.length===0)return o;let r=n?.lineEnding!==void 0&&n.lineEnding.length>0?n.lineEnding:t[0]?.lineEnding!==void 0&&t[0].lineEnding.length>0?t[0].lineEnding:`
|
|
6
|
+
`,a=t.map((c,l)=>{let f=l===t.length-1?c.lineEnding:c.lineEnding||r,m=c.presentation?.prefix??"",g=c.presentation?.suffix??"";return`${m}${c.content}${g}${f}`}).join(""),i=/(?:\r\n|\r|\n)$/.test(s.text)?"":r,u=`${s.text}${i}${a}`;return{...o,content:[{...s,text:u}],details:{...o.details,lines:e}}}d(de,"appendTextLines");var Y=/^scope-(begin|end)-[A-Z0-9]{3,4}(?:-[1-9]\d*)?$/;function W(o){return{id:"ast-scope",description:'`scope-begin-HASH` / `scope-end-HASH` from read views: ["ast"] \u2014 first/last lines of a scope. Any numeric suffix is part of the anchor.',renderFull(e){return e},renderCompact(e){return Y.exec(e)?.[1]==="begin"?"scope start":"scope end"},async tryResolve(e,n){if(!Y.test(e))return{kind:"not-handled"};try{let t=(await o.getDocumentScopes(n.source,n.cwd,n.lines)).find(r=>r.beginAnchor.value===e||r.endScopeAnchor.value===e);return t===void 0?{kind:"rejected",rejection:{code:"stale",reason:`AST scope anchor ${e} is stale`}}:{kind:"resolved",anchor:t.beginAnchor.value===e?t.beginAnchor:t.endScopeAnchor}}catch(s){return{kind:"failed",error:s}}}}}d(W,"createAstScopeAnchorResolver");import{spawn as le}from"node:child_process";import{readFile as ue,stat as Z}from"node:fs/promises";import h from"node:path";function Q(o){return{id:"ast",async tryResolve(e,n){if(!e.query.startsWith("ast:"))return{kind:"not-handled"};let s=e.query.slice(4).trim();if(s.length===0)return{kind:"failed",error:new Error("ast: pattern must not be empty")};let t=d(async i=>{let u=Date.now(),c=await fe(s,e,n.cwd,i);c.sort((p,f)=>h.resolve(n.cwd,p.file).localeCompare(h.resolve(n.cwd,f.file))||p.range.byteOffset.start-f.range.byteOffset.start||p.range.byteOffset.end-f.range.byteOffset.end);let l=c.slice(0,e.limit??100);return{raw:l,matches:await pe(l,n.cwd,u,i),complete:c.length<=(e.limit??100)}},"collect"),r=await t(n.signal),a=await o({request:e,matches:r.matches,complete:r.complete,refresh:t},n);return{kind:"resolved",payload:{pattern:s,matches:r.raw,complete:r.complete,sessionId:a.id}}},format(e){let n=e;if(n.matches.length===0)return{content:[{type:"text",text:"No AST matches found."}],details:n};let s=n.matches.flatMap((t,r)=>[`SEARCH#${n.sessionId}:${String(r+1)}:match ${t.file}:${String(t.range.start.line+1)}:${String(t.range.start.column+1)} ${t.language}`,` ${t.lines.trim()}`]);return n.complete&&s.unshift(`SEARCH#${n.sessionId}:all:match selects all exact AST matches.`),n.complete||s.push("Result limit reached."),{content:[{type:"text",text:s.join(`
|
|
7
|
+
`)}],details:n}}}}d(Q,"createAstSearchResolver");async function pe(o,e,n,s){let t=new Map;for(let r of o){let a=h.resolve(e,r.file);if(t.has(a))continue;let i=await Z(a),u=await ue(a,{signal:s}),c=await Z(a);if(i.mtimeMs>n||i.mtimeMs!==c.mtimeMs||i.size!==c.size)throw new Error("AST source changed during search. Run the structural query again.");t.set(a,u)}return o.map(r=>{let a=h.resolve(e,r.file),i=t.get(a);if(i===void 0)throw new Error("Missing AST source snapshot");let{start:u,end:c}=r.range.byteOffset;if(!Number.isInteger(u)||!Number.isInteger(c)||u<0||c<u||c>i.length||i.subarray(u,c).toString("utf8")!==r.text)throw new Error("AST range does not match its source snapshot. Search again.");let l=i.subarray(0,u).toString("utf8"),p=i.subarray(0,c).toString("utf8"),f=l.split(`
|
|
8
|
+
`).length;return{source:a,lineNumber:f,endLineNumber:p.split(`
|
|
9
|
+
`).length,startColumn:l.length-l.lastIndexOf(`
|
|
10
|
+
`)-1,endColumn:p.length-p.lastIndexOf(`
|
|
11
|
+
`)-1,matchedText:r.text,lineText:i.toString("utf8").split(`
|
|
12
|
+
`)[f-1]?.replace(/\r$/u,"")??""}})}d(pe,"selectionMatches");function fe(o,e,n,s){let t=["run","--pattern",o,"--json=compact","--no-ignore","parent"];for(let r of q(e.include))t.push("--globs",r);for(let r of q(e.exclude))t.push("--globs",`!${r}`);return t.push(e.path??"."),new Promise((r,a)=>{let i=le("ast-grep",t,{cwd:n,stdio:["ignore","pipe","pipe"]}),u="",c="";i.stdout.setEncoding("utf8"),i.stderr.setEncoding("utf8"),i.stdout.on("data",p=>u+=p),i.stderr.on("data",p=>c+=p);let l=d(()=>{i.kill("SIGTERM")},"abort");s?.addEventListener("abort",l,{once:!0}),i.once("error",a),i.once("close",p=>{if(s?.removeEventListener("abort",l),s?.aborted===!0){a(s.reason instanceof Error?s.reason:new Error("AST search aborted"));return}if(p!==0&&p!==1){a(new Error(c.trim()||`ast-grep exited with code ${String(p)}`));return}try{let f=JSON.parse(u.length===0?"[]":u);if(!Array.isArray(f))throw new TypeError("ast-grep returned non-array JSON");r(f)}catch(f){a(f instanceof Error?f:new Error(String(f)))}})})}d(fe,"runAstGrep");function q(o){return o?.split(",").map(e=>e.trim()).filter(Boolean)??[]}d(q,"splitGlobs");var me=$({kind:"code-view",label:"AST"});async function ee(o){let e=new V,n=K(e),s={protocol:P,apiVersion:M,id:"ast",setup(r){r.addResolver({resolver:F(),renderResult:me}),r.addHandler({stage:"read",when:{resolvedBy:"ast",contentKind:"text"},handler:v()}),r.addView({view:"ast",presenter:n});let a=X();r.addOutputReducer(S);let i=U();r.addHandler({stage:"post-read",async handler(u){let c=await a(u);return c.kind==="return"?c:i(c.context)}}),r.describe('ast:<path> \u2014 compact declaration outline. views: ["ast"] \u2014 scope boundaries alongside source text. Oversized code reads may return an outline with source line numbers; offset/limit read a smaller source range.')}},t={protocol:_,apiVersion:D,id:"ast",setup(r){r.addAnchorResolver({resolver:W(e),kind:H,type:"auxiliary"}),r.addTextPresenter({presenter:n})}};await Promise.all([k(o,s),T(o,G),B(o,t),N(o,{protocol:I,apiVersion:C,id:"ast-search",setup(r){r.addResolver({resolver:Q(r.registerSelection)}),r.describe("Search code structure with ast:<pattern>, using source-code syntax and placeholders such as $NAME for one node and $$$BODY for several nodes. path, include and exclude narrow the search. Use returned SEARCH# references to read, replace, copy, move or delete exact AST matches, including multiline nodes. A single :match reference becomes stale after its file changes; :all:match reruns the original structural query. Incomplete results do not provide all selections. Use captures in Apply to compute replacement text; these edits do not update imports or references.")}})])}d(ee,"registerAst");export{ee as default};
|
package/dist/entry-28.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as j,b as _,c as B}from"./chunk-DEP55R35.js";import{a as D}from"./chunk-ERVMDQGX.js";import{a as H,b as $}from"./chunk-VFBLX4TG.js";import{a as F}from"./chunk-ORAPGW7W.js";import{a as L,b as N}from"./chunk-JASLOB2X.js";import{a as M}from"./chunk-WNMGUALD.js";import{a as O,b as U}from"./chunk-THSCUT2L.js";import"./chunk-S3ZPXWX7.js";import{a as I}from"./chunk-RAZOACDD.js";import{d as R,e as S}from"./chunk-N34ATN52.js";import{a as x}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";import{access as te}from"node:fs/promises";import ne from"node:path";var V={protocol:H,apiVersion:1,id:"changes",setup(r){r.addSetupCheck({id:"git",async inspect(e){return await re(e.cwd)?await R("git",e.cwd,e.env)?{}:{actions:[{id:"git-unavailable",message:"Git integration is unavailable because Git was not found"}]}:{}}}),r.addCheck({id:"git",title:"Git changes",async run(e){let t=await S("git",["--version"],e.cwd,e.env);return[t.ok?{status:"pass",message:"Git is available",detail:t.detail}:{status:"warn",message:"Git is not available; change anchors and index tools are disabled",detail:t.detail}]}})}};async function re(r){try{return await te(ne.join(r,".git")),!0}catch{return!1}}a(re,"isGitProject");import{mkdtemp as oe,rm as ie,writeFile as ae}from"node:fs/promises";import se from"node:os";import m from"node:path";var b=class r{constructor(e,t){this.executor=e;this.repositoryRoot=t}static{a(this,"GitChangesBackend")}static async create(e,t,n){let o=await e.exec("git",["rev-parse","--show-toplevel"],{cwd:t,...n!==void 0&&{signal:n}});return o.code!==0?{status:"unavailable",reason:"no-worktree",message:o.stderr.trim()||"not inside a Git worktree"}:{status:"ready",backend:new r(e,m.resolve(o.stdout.trim()))}}async readTrackedFile(e,t,n){let o=m.resolve(t,e),i=m.relative(this.repositoryRoot,o);return i===".."||i.startsWith(`..${m.sep}`)||m.isAbsolute(i)?{status:"unavailable",reason:"outside-worktree",message:`${o} is outside ${this.repositoryRoot}`}:this.readTrackedRepositoryFile(i.split(m.sep).join("/"),n)}async readTrackedRepositoryFile(e,t){let n=await this.git(["rev-parse","--verify","HEAD"],t);if(n.code!==0)return{status:"unavailable",reason:"missing-head",message:n.stderr.trim()||"Git HEAD does not exist"};let o=await this.git(["--literal-pathspecs","ls-tree","-z","HEAD","--",e],t);if(o.code!==0)return{status:"unavailable",reason:"head-file-lookup-failed",message:o.stderr.trim()||`could not inspect HEAD:${e}`};let i=de(o.stdout);if(i===void 0)return{status:"untracked"};let d=await this.readBlob(i.blob,"HEAD",e,t);if(d.status!=="found")return d;let c=await this.git(["--literal-pathspecs","ls-files","--stage","-z","--",e],t);if(c.code!==0)return{status:"unavailable",reason:"index-file-lookup-failed",message:c.stderr.trim()||`could not inspect the index entry for ${e}`};let s=ce(c.stdout);if(s.some(({stage:g})=>g!==0))return{status:"unavailable",reason:"conflicted",message:`${e} has unresolved Git index entries`};let u=s.find(({stage:g})=>g===0),l="";if(u!==void 0){let g=await this.readBlob(u.blob,"index",e,t);if(g.status!=="found")return g;l=g.text}return{status:"found",head:n.stdout.trim(),repositoryPath:e,repositoryRoot:this.repositoryRoot,headText:d.text,indexText:l,indexMode:u?.mode??i.mode}}async writeIndexFile(e,t,n,o){let i=await oe(m.join(se.tmpdir(),"pi-agent-index-")),d=m.join(i,"content");try{await ae(d,n,"utf8");let c=await this.git(["hash-object","-w",`--path=${e}`,d],o);if(c.code!==0||c.stdout.trim().length===0)throw new Error(c.stderr.trim()||`could not write a Git blob for ${e}`);let s=await this.git(["update-index","--add","--cacheinfo",t,c.stdout.trim(),e],o);if(s.code!==0)throw new Error(s.stderr.trim()||`could not update the Git index entry for ${e}`)}finally{await ie(i,{recursive:!0,force:!0})}}async readBlob(e,t,n,o){let i=await this.git(["cat-file","blob",e],o);return i.code!==0?{status:"unavailable",reason:t==="HEAD"?"head-file-lookup-failed":"index-file-lookup-failed",message:i.stderr.trim()||`could not read ${t}:${n}`}:{status:"found",text:i.stdout}}git(e,t){return this.executor.exec("git",e,{cwd:this.repositoryRoot,...t!==void 0&&{signal:t}})}};function de(r){let e=r.split("\0",1)[0];if(e===void 0||e.length===0)return;let t=e.indexOf(" ");if(t===-1)return;let[n,o,i]=e.slice(0,t).split(" ",3);return n===void 0||o!=="blob"||i===void 0?void 0:{mode:n,blob:i,path:e.slice(t+1)}}a(de,"parseTreeEntry");function ce(r){return r.split("\0").filter(Boolean).flatMap(e=>{let t=e.indexOf(" ");if(t===-1)return[];let[n,o,i]=e.slice(0,t).split(" ",3),d=Number(i);return n===void 0||o===void 0||!Number.isInteger(d)?[]:[{mode:n,blob:o,stage:d,path:e.slice(t+1)}]})}a(ce,"parseIndexEntries");function z(r){return{exec:a((e,t,n)=>r.exec(e,t,n),"exec")}}a(z,"extensionGitExecutor");var p=class r{constructor(e){this.git=e}static{a(this,"ChangeService")}static async create(e,t,n){let o=await b.create(e,t,n);return o.status==="unavailable"?o:{status:"ready",service:new r(o.backend)}}async inspect(e){if(e.worktreeText.includes("\0"))return{status:"unavailable",reason:"binary",message:"worktree file contains binary content"};let t=await this.git.readTrackedFile(e.source,e.cwd,e.signal);if(t.status!=="found")return t.status==="untracked"?{status:"not-applicable",reason:"untracked"}:t;if(t.headText.includes("\0")||t.indexText.includes("\0"))return{status:"unavailable",reason:"binary",message:"Git file state contains binary content"};let n=j(t.repositoryPath,t.headText,t.indexText,e.worktreeText);return n.length===0?{status:"not-applicable",reason:"clean"}:{status:"applicable",head:t.head,repositoryRoot:t.repositoryRoot,repositoryPath:t.repositoryPath,groups:n}}async changeIndex(e,t,n){let o=await this.inspect(e);if(o.status!=="applicable")return o;let i=o.groups.find(u=>u.selector===t);if(i===void 0)return k(t,o.groups.map(({selector:u})=>u));let d=n==="stage"?"staged":"unstaged";if(i.state===d)return{status:"unchanged",state:d,group:i};let c=x(i.segments[0]),s={head:o.head,repositoryPath:o.repositoryPath,headStart:c.headStart,headEnd:c.headEnd,replacementText:n==="stage"?c.worktreeText:c.headText};try{await this.applyIndexUpdate(s,e.signal)}catch(u){return{status:"unavailable",reason:"index-write-failed",message:ue(u)}}return{status:"applied",state:d,group:i}}async prepareUndo(e,t){let n=await this.inspect(e);if(n.status!=="applicable")return n;let o=n.groups.find(s=>s.selector===t);if(o===void 0)return k(t,n.groups.map(({selector:s})=>s));let i=_(e.worktreeText,o);if(i===void 0)return k(t,n.groups.map(({selector:s})=>s));let d=x(o.segments[0]),c=o.state==="unstaged"?void 0:{head:n.head,repositoryPath:n.repositoryPath,headStart:d.headStart,headEnd:d.headEnd,replacementText:d.headText};return{status:"applied",worktreeText:i,group:o,...c!==void 0&&{indexUpdate:c}}}async applyIndexUpdate(e,t){let n=await this.git.readTrackedRepositoryFile(e.repositoryPath,t);if(n.status!=="found")throw new Error(n.status==="untracked"?`${e.repositoryPath} is no longer tracked by HEAD`:n.message);if(n.head!==e.head)throw new Error(`Git HEAD changed while updating ${e.repositoryPath}`);let o=B(n.headText,n.indexText,e.headStart,e.headEnd,e.replacementText);o!==n.indexText&&await this.git.writeIndexFile(e.repositoryPath,n.indexMode,o,t)}};function k(r,e){return{status:"unavailable",reason:"stale-selector",message:`${r} is not available in the current file state`,availableSelectors:e}}a(k,"staleSelector");function ue(r){return r instanceof Error?r.message:String(r)}a(ue,"errorMessage");var w="pi-agent-ide-changes/change",le=/^CHANGE#[0-9A-F]{4,64}$/,ge=/^[A-Za-z][A-Za-z\d+.-]*:\/\//,E=class extends I{static{a(this,"ChangeTextAnchor")}constructor(e){super(e.selector,e.currentStartLine)}};function Q(r){return{resolver:fe(a(async t=>{if(ge.test(t.source))return;let n=await p.create(r,t.cwd,t.signal);if(n.status!=="ready")throw new Error(n.message);return n.service.inspect({source:t.source,worktreeText:t.content,cwd:t.cwd,...t.signal!==void 0&&{signal:t.signal}})},"inspect"))}}a(Q,"createChangeAnchorRegistration");function fe(r){return{id:"git-change",description:"Use the complete `CHANGE#HASH` shown beside a current Git change.",renderFull(e){return e},renderCompact(e){return e},async tryResolve(e,t){if(!le.test(e))return{kind:"not-handled"};try{let n=await r(t);if(n===void 0)return{kind:"not-handled"};if(n.status==="unavailable")return{kind:"failed",error:new Error(n.message)};let o=n.status==="applicable"?n.groups.find(i=>i.selector===e):void 0;return o===void 0?{kind:"rejected",rejection:{code:"stale",reason:`Change anchor ${e} is stale or unknown`}}:{kind:"resolved",anchor:new E(o)}}catch(n){return{kind:"failed",error:n}}}}}a(fe,"createChangeAnchorResolver");import{diffLines as pe}from"diff";var me="filesystem";function K(r){return{id:"current-git-changes",async present(e,t){if(t.purpose!=="read"||t.resolvedBy!==me)return e;let n=await p.create(r,t.cwd,t.signal);if(n.status!=="ready")return e;let o=await n.service.inspect({source:t.source,worktreeText:e.content,cwd:t.cwd,...t.signal!==void 0&&{signal:t.signal}});return o.status!=="applicable"?e:he(e,o.groups)}}}a(K,"createCurrentChangePresenter");function he(r,e){let t=new Map;for(let n of e)xe(r,n,t);return{...r,lines:r.lines.map(n=>be(n,t.get(n.lineNumber)))}}a(he,"presentChangeGroups");function xe(r,e,t){let n=x(e.segments[0]),o=pe(n.headText,n.worktreeText),i=e.currentStartLine,d,c;for(let s of o){let u=Te(s.value);if(s.removed){let l=we(r,i),g=A(t,l.lineNumber),f=l.after?g.after:g.before;for(let h of u){let y={kind:"synthetic",rows:f,index:f.length};f.push({marker:"-",prefix:"|",content:h}),d??=y,c=y}continue}if(s.added){for(let l of u){let g=A(t,i),f={kind:"current",lineNumber:i};g.added=!0,d??=f,c=f,i++}continue}i+=u.length}if(d!==void 0&&c!==void 0){let s=`${e.selector} \xB7 ${e.state}`;ye(d,c)?P(t,d,`<!-- change: ${s} -->`):(P(t,d,`<!-- change-begin: ${s} -->`),P(t,c,`<!-- change-end: ${s} -->`))}}a(xe,"presentChangeGroup");function ye(r,e){return r.kind==="current"&&e.kind==="current"?r.lineNumber===e.lineNumber:r.kind==="synthetic"&&e.kind==="synthetic"?r.rows===e.rows&&r.index===e.index:!1}a(ye,"sameTarget");function P(r,e,t){if(e.kind==="current"){A(r,e.lineNumber).annotations.push(t);return}let n=x(e.rows[e.index]);e.rows[e.index]={...n,suffix:`${n.suffix??""} ${t}`}}a(P,"annotateTarget");function be(r,e){if(e===void 0)return r;let t=e.annotations.length===0?"":` ${e.annotations.join(" ")}`;return{...r,presentation:{...r.presentation,...e.added&&{marker:"+"},before:[...r.presentation?.before??[],...e.before],after:[...e.after,...r.presentation?.after??[]],suffix:`${r.presentation?.suffix??""}${t}`}}}a(be,"presentLine");function A(r,e){let t=r.get(e);if(t!==void 0)return t;let n={before:[],after:[],annotations:[],added:!1};return r.set(e,n),n}a(A,"presentationsFor");function we(r,e){return e<=r.lines.length?{lineNumber:Math.max(1,e),after:!1}:{lineNumber:r.lines.length,after:!0}}a(we,"placementFor");function Te(r){if(r.length===0)return[];let e=r.split(/\r\n|\r|\n/u);return e.at(-1)===""&&e.pop(),e}a(Te,"splitLines");var T=class{static{a(this,"IndexMutationQueue")}tail=Promise.resolve();run(e){let t=this.tail.then(e,e);return this.tail=t.then(()=>{},()=>{}),t}};import{createHash as ve}from"node:crypto";import{realpathSync as Ce}from"node:fs";import Z from"node:path";import{fileURLToPath as ke}from"node:url";var v=class{static{a(this,"LastTextTransactionStore")}#e=new Map;observe(e){let t=W(e.resourceSource,e.cwd);if(e.intent!=="edit"||!e.existed||e.before.content===e.after.content){this.#e.delete(t);return}this.#e.set(t,{before:e.before.content,afterDigest:X(e.after.content)})}restore(e,t,n){let o=W(e,t),i=this.#e.get(o);if(i===void 0)throw new Error(`No last text transaction is available for ${e}.`);if(i.afterDigest!==X(n))throw this.#e.delete(o),new Error(`${e} changed after its last text transaction; refusing to overwrite newer text.`);return i.before}};function W(r,e){return r.startsWith("file://")?q(ke(new URL(r))):/^[a-z][a-z\d+.-]*:/iu.test(r)?r:q(Z.resolve(e,r))}a(W,"sourceKey");function q(r){try{return Ce.native(r)}catch{return Z.normalize(r)}}a(q,"canonicalFile");function X(r){return ve("sha256").update(r).digest("hex")}a(X,"textDigest");import{readFile as Ee}from"node:fs/promises";import Pe from"node:path";import{defineTool as Ae,withFileMutationQueue as Ge}from"@earendil-works/pi-coding-agent";import{Type as G}from"typebox";var Ie=G.Object({file:G.String({description:"Path to the tracked text file"}),change:G.String({description:"Complete CHANGE#HASH anchor shown by read",pattern:"^CHANGE#[0-9A-F]{4,64}$"})},{additionalProperties:!1});function J(r,e,t){r.registerTool(Y("stage",e,t)),r.registerTool(Y("unstage",e,t))}a(J,"registerIndexChangeTools");function Y(r,e,t){let n=r==="stage"?"staged":"unstaged",o=r==="stage"?"Staged":"Unstaged";return Ae({name:r,label:r,promptSnippet:`${o.slice(0,-1)} a selected Git change`,description:`Use ${r} to ${r==="stage"?"add one current Git change to the index":"remove one current Git change from the index"}. Select the change with a CHANGE# anchor; worktree content is kept.`,parameters:Ie,async execute(i,d,c,s,u){let l=Re(d.file,u.cwd);return Ge(l,()=>t.run(async()=>{let g=await Ee(l,"utf8"),f=await p.create(e,u.cwd,c);if(f.status!=="ready")throw new Error(f.message);let h=await f.service.changeIndex({source:l,worktreeText:g,cwd:u.cwd,...c!==void 0&&{signal:c}},d.change,r);if(h.status==="unavailable")throw new Error(h.message);if(h.status==="not-applicable")throw new Error(`${r} is not applicable to ${l}: ${h.reason}`);let y=h.status==="unchanged";return{content:[{type:"text",text:y?`${d.change} is already ${n} in ${d.file}.`:`${o} ${d.change} in ${d.file}.`}],details:{action:r,change:d.change,file:l,state:n,unchanged:y}}}))}})}a(Y,"createIndexChangeTool");function Re(r,e){let t=r.startsWith("@")?r.slice(1):r;return Pe.resolve(e,t)}a(Re,"resolveFile");import{diffChars as Se}from"diff";import{Type as C}from"typebox";var He=C.Object({file:C.Optional(C.String({description:"File to restore; may be omitted to inherit the previous batched source"})),change:C.String({description:"Complete CHANGE#HASH anchor shown by read, or last for this file's latest text-editor transaction",pattern:"^(?:CHANGE#[0-9A-F]{4,64}|last)$"})},{additionalProperties:!1});function ee(r,e,t){return{name:"undo",description:"Use undo to revert a selected uncommitted Git change or the latest text-editor transaction for one file. A CHANGE# anchor restores that change to HEAD in both worktree and index; last restores the file's state before its latest text-editor transaction.",promptSnippet:"Restore a Git change or the latest text edit",parameters:He,intent:"restore",source:{field:"file",inherited:!0},anchors:[{field:"change",sourceField:"file",kinds:[w],nonAnchorValues:["last"]}],async mutate(n,o){let i=n.sourceFor("file"),d,c;if(o.change==="last")d=e.restore(i,n.cwd,n.sourceDocument.content);else{await n.resolveAnchor("change");let s=await p.create(r,n.cwd,n.signal);if(s.status!=="ready")throw new Error(s.message);let u=await s.service.prepareUndo({source:i,worktreeText:n.sourceDocument.content,cwd:n.cwd,...n.signal!==void 0&&{signal:n.signal}},o.change);if(u.status!=="applied")throw u.status==="unavailable"?new Error(u.message):new Error(`Undo is not applicable to ${i}: ${u.reason}`);if(d=u.worktreeText,u.indexUpdate!==void 0){let l=u.indexUpdate;c=a(()=>t.run(()=>s.service.applyIndexUpdate(l,n.signal)),"afterWrite")}}return{edits:new Map([[i,{changes:$e(n.sourceDocument.content,d),action:"edited"}]]),...c!==void 0&&{afterWrite:c}}}}}a(ee,"createUndoMutationTool");function $e(r,e){let t=[],n=0,o,i=0,d="",c=a(()=>{o!==void 0&&(t.push({from:o,to:o+i,insert:d}),o=void 0,i=0,d="")},"flush");for(let s of Se(r,e)){if(!s.added&&!s.removed){c(),n+=s.value.length;continue}o??=n,s.removed?(n+=s.value.length,i+=s.value.length):d+=s.value}return c(),t}a($e,"createTextChanges");async function De(r){if(process.argv.includes("--old-tools"))return;let e=z(r),t=new v,n=new T,o=K(e),i=Q(e),d={protocol:L,apiVersion:N,id:"current-git-changes",setup(s){s.addView({view:"changes",presenter:o}),s.describe('views: ["changes"] \u2014 uncommitted edits in tracked files, staged/unstaged state, and CHANGE# anchors for stage, unstage and undo.')}},c={protocol:O,apiVersion:U,id:"current-git-changes",setup(s){s.addAnchorResolver({...i,kind:w,type:"auxiliary"}),s.onDidEdit(u=>{t.observe(u)}),s.addMutationTool(ee(e,t,n)),s.addTextPresenter({presenter:o})}};await Promise.all([D(r,V),F(r,d),M(r,c)]),J(r,e,n)}a(De,"registerGitChanges");export{De as default};
|
|
1
|
+
import{a as V,b as z,c as Q}from"./chunk-DEP55R35.js";import{a as O}from"./chunk-ERVMDQGX.js";import{a as L,b as N}from"./chunk-VFBLX4TG.js";import{a as M}from"./chunk-72EEL2DW.js";import{a as F,b as U}from"./chunk-KAB3AYA2.js";import{a as B}from"./chunk-TI5GMJ7Q.js";import{a as j,b as _}from"./chunk-Y7ZMR4LT.js";import"./chunk-S3ZPXWX7.js";import{a as H}from"./chunk-5VSE5X5R.js";import{d as $,e as D}from"./chunk-N34ATN52.js";import{a as x}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";import{Value as De}from"typebox/value";import{access as ne}from"node:fs/promises";import re from"node:path";var K={protocol:L,apiVersion:1,id:"changes",setup(r){r.addSetupCheck({id:"git",async inspect(e){return await oe(e.cwd)?await $("git",e.cwd,e.env)?{}:{actions:[{id:"git-unavailable",message:"Git integration is unavailable because Git was not found"}]}:{}}}),r.addCheck({id:"git",title:"Git changes",async run(e){let t=await D("git",["--version"],e.cwd,e.env);return[t.ok?{status:"pass",message:"Git is available",detail:t.detail}:{status:"warn",message:"Git is not available; change anchors and index tools are disabled",detail:t.detail}]}})}};async function oe(r){try{return await ne(re.join(r,".git")),!0}catch{return!1}}a(oe,"isGitProject");import{mkdtemp as ie,rm as ae,writeFile as se}from"node:fs/promises";import de from"node:os";import m from"node:path";var b=class r{constructor(e,t){this.executor=e;this.repositoryRoot=t}static{a(this,"GitChangesBackend")}static async create(e,t,n){let o=await e.exec("git",["rev-parse","--show-toplevel"],{cwd:t,...n!==void 0&&{signal:n}});return o.code!==0?{status:"unavailable",reason:"no-worktree",message:o.stderr.trim()||"not inside a Git worktree"}:{status:"ready",backend:new r(e,m.resolve(o.stdout.trim()))}}async readTrackedFile(e,t,n){let o=m.resolve(t,e),i=m.relative(this.repositoryRoot,o);return i===".."||i.startsWith(`..${m.sep}`)||m.isAbsolute(i)?{status:"unavailable",reason:"outside-worktree",message:`${o} is outside ${this.repositoryRoot}`}:this.readTrackedRepositoryFile(i.split(m.sep).join("/"),n)}async readTrackedRepositoryFile(e,t){let n=await this.git(["rev-parse","--verify","HEAD"],t);if(n.code!==0)return{status:"unavailable",reason:"missing-head",message:n.stderr.trim()||"Git HEAD does not exist"};let o=await this.git(["--literal-pathspecs","ls-tree","-z","HEAD","--",e],t);if(o.code!==0)return{status:"unavailable",reason:"head-file-lookup-failed",message:o.stderr.trim()||`could not inspect HEAD:${e}`};let i=ce(o.stdout);if(i===void 0)return{status:"untracked"};let d=await this.readBlob(i.blob,"HEAD",e,t);if(d.status!=="found")return d;let c=await this.git(["--literal-pathspecs","ls-files","--stage","-z","--",e],t);if(c.code!==0)return{status:"unavailable",reason:"index-file-lookup-failed",message:c.stderr.trim()||`could not inspect the index entry for ${e}`};let s=ue(c.stdout);if(s.some(({stage:g})=>g!==0))return{status:"unavailable",reason:"conflicted",message:`${e} has unresolved Git index entries`};let u=s.find(({stage:g})=>g===0),l="";if(u!==void 0){let g=await this.readBlob(u.blob,"index",e,t);if(g.status!=="found")return g;l=g.text}return{status:"found",head:n.stdout.trim(),repositoryPath:e,repositoryRoot:this.repositoryRoot,headText:d.text,indexText:l,indexMode:u?.mode??i.mode}}async writeIndexFile(e,t,n,o){let i=await ie(m.join(de.tmpdir(),"pi-agent-index-")),d=m.join(i,"content");try{await se(d,n,"utf8");let c=await this.git(["hash-object","-w",`--path=${e}`,d],o);if(c.code!==0||c.stdout.trim().length===0)throw new Error(c.stderr.trim()||`could not write a Git blob for ${e}`);let s=await this.git(["update-index","--add","--cacheinfo",t,c.stdout.trim(),e],o);if(s.code!==0)throw new Error(s.stderr.trim()||`could not update the Git index entry for ${e}`)}finally{await ae(i,{recursive:!0,force:!0})}}async readBlob(e,t,n,o){let i=await this.git(["cat-file","blob",e],o);return i.code!==0?{status:"unavailable",reason:t==="HEAD"?"head-file-lookup-failed":"index-file-lookup-failed",message:i.stderr.trim()||`could not read ${t}:${n}`}:{status:"found",text:i.stdout}}git(e,t){return this.executor.exec("git",e,{cwd:this.repositoryRoot,...t!==void 0&&{signal:t}})}};function ce(r){let e=r.split("\0",1)[0];if(e===void 0||e.length===0)return;let t=e.indexOf(" ");if(t===-1)return;let[n,o,i]=e.slice(0,t).split(" ",3);return n===void 0||o!=="blob"||i===void 0?void 0:{mode:n,blob:i,path:e.slice(t+1)}}a(ce,"parseTreeEntry");function ue(r){return r.split("\0").filter(Boolean).flatMap(e=>{let t=e.indexOf(" ");if(t===-1)return[];let[n,o,i]=e.slice(0,t).split(" ",3),d=Number(i);return n===void 0||o===void 0||!Number.isInteger(d)?[]:[{mode:n,blob:o,stage:d,path:e.slice(t+1)}]})}a(ue,"parseIndexEntries");function W(r){return{exec:a((e,t,n)=>r.exec(e,t,n),"exec")}}a(W,"extensionGitExecutor");var p=class r{constructor(e){this.git=e}static{a(this,"ChangeService")}static async create(e,t,n){let o=await b.create(e,t,n);return o.status==="unavailable"?o:{status:"ready",service:new r(o.backend)}}async inspect(e){if(e.worktreeText.includes("\0"))return{status:"unavailable",reason:"binary",message:"worktree file contains binary content"};let t=await this.git.readTrackedFile(e.source,e.cwd,e.signal);if(t.status!=="found")return t.status==="untracked"?{status:"not-applicable",reason:"untracked"}:t;if(t.headText.includes("\0")||t.indexText.includes("\0"))return{status:"unavailable",reason:"binary",message:"Git file state contains binary content"};let n=V(t.repositoryPath,t.headText,t.indexText,e.worktreeText);return n.length===0?{status:"not-applicable",reason:"clean"}:{status:"applicable",head:t.head,repositoryRoot:t.repositoryRoot,repositoryPath:t.repositoryPath,groups:n}}async changeIndex(e,t,n){let o=await this.inspect(e);if(o.status!=="applicable")return o;let i=o.groups.find(u=>u.selector===t);if(i===void 0)return A(t,o.groups.map(({selector:u})=>u));let d=n==="stage"?"staged":"unstaged";if(i.state===d)return{status:"unchanged",state:d,group:i};let c=x(i.segments[0]),s={head:o.head,repositoryPath:o.repositoryPath,headStart:c.headStart,headEnd:c.headEnd,replacementText:n==="stage"?c.worktreeText:c.headText};try{await this.applyIndexUpdate(s,e.signal)}catch(u){return{status:"unavailable",reason:"index-write-failed",message:le(u)}}return{status:"applied",state:d,group:i}}async prepareUndo(e,t){let n=await this.inspect(e);if(n.status!=="applicable")return n;let o=n.groups.find(s=>s.selector===t);if(o===void 0)return A(t,n.groups.map(({selector:s})=>s));let i=z(e.worktreeText,o);if(i===void 0)return A(t,n.groups.map(({selector:s})=>s));let d=x(o.segments[0]),c=o.state==="unstaged"?void 0:{head:n.head,repositoryPath:n.repositoryPath,headStart:d.headStart,headEnd:d.headEnd,replacementText:d.headText};return{status:"applied",worktreeText:i,group:o,...c!==void 0&&{indexUpdate:c}}}async applyIndexUpdate(e,t){let n=await this.git.readTrackedRepositoryFile(e.repositoryPath,t);if(n.status!=="found")throw new Error(n.status==="untracked"?`${e.repositoryPath} is no longer tracked by HEAD`:n.message);if(n.head!==e.head)throw new Error(`Git HEAD changed while updating ${e.repositoryPath}`);let o=Q(n.headText,n.indexText,e.headStart,e.headEnd,e.replacementText);o!==n.indexText&&await this.git.writeIndexFile(e.repositoryPath,n.indexMode,o,t)}};function A(r,e){return{status:"unavailable",reason:"stale-selector",message:`${r} is not available in the current file state`,availableSelectors:e}}a(A,"staleSelector");function le(r){return r instanceof Error?r.message:String(r)}a(le,"errorMessage");var w="pi-agent-ide-changes/change",ge=/^CHANGE#[0-9A-F]{4,64}$/,fe=/^[A-Za-z][A-Za-z\d+.-]*:\/\//,G=class extends H{static{a(this,"ChangeTextAnchor")}constructor(e){super(e.selector,e.currentStartLine)}};function q(r){return{resolver:pe(a(async t=>{if(fe.test(t.source))return;let n=await p.create(r,t.cwd,t.signal);if(n.status!=="ready")throw new Error(n.message);return n.service.inspect({source:t.source,worktreeText:t.content,cwd:t.cwd,...t.signal!==void 0&&{signal:t.signal}})},"inspect"))}}a(q,"createChangeAnchorRegistration");function pe(r){return{id:"git-change",description:"Use the complete `CHANGE#HASH` shown beside a current Git change.",renderFull(e){return e},renderCompact(e){return e},async tryResolve(e,t){if(!ge.test(e))return{kind:"not-handled"};try{let n=await r(t);if(n===void 0)return{kind:"not-handled"};if(n.status==="unavailable")return{kind:"failed",error:new Error(n.message)};let o=n.status==="applicable"?n.groups.find(i=>i.selector===e):void 0;return o===void 0?{kind:"rejected",rejection:{code:"stale",reason:`Change anchor ${e} is stale or unknown`}}:{kind:"resolved",anchor:new G(o)}}catch(n){return{kind:"failed",error:n}}}}}a(pe,"createChangeAnchorResolver");import{diffLines as he}from"diff";var me="filesystem";function X(r){return{id:"current-git-changes",async present(e,t){if(t.purpose!=="read"||t.resolvedBy!==me)return e;let n=await p.create(r,t.cwd,t.signal);if(n.status!=="ready")return e;let o=await n.service.inspect({source:t.source,worktreeText:e.content,cwd:t.cwd,...t.signal!==void 0&&{signal:t.signal}});return o.status!=="applicable"?e:xe(e,o.groups)}}}a(X,"createCurrentChangePresenter");function xe(r,e){let t=new Map;for(let n of e)ye(r,n,t);return{...r,lines:r.lines.map(n=>we(n,t.get(n.lineNumber)))}}a(xe,"presentChangeGroups");function ye(r,e,t){let n=x(e.segments[0]),o=he(n.headText,n.worktreeText),i=e.currentStartLine,d,c;for(let s of o){let u=Ce(s.value);if(s.removed){let l=Te(r,i),g=R(t,l.lineNumber),f=l.after?g.after:g.before;for(let h of u){let y={kind:"synthetic",rows:f,index:f.length};f.push({marker:"-",prefix:"|",content:h}),d??=y,c=y}continue}if(s.added){for(let l of u){let g=R(t,i),f={kind:"current",lineNumber:i};g.added=!0,d??=f,c=f,i++}continue}i+=u.length}if(d!==void 0&&c!==void 0){let s=`${e.selector} \xB7 ${e.state}`;be(d,c)?I(t,d,`<!-- change: ${s} -->`):(I(t,d,`<!-- change-begin: ${s} -->`),I(t,c,`<!-- change-end: ${s} -->`))}}a(ye,"presentChangeGroup");function be(r,e){return r.kind==="current"&&e.kind==="current"?r.lineNumber===e.lineNumber:r.kind==="synthetic"&&e.kind==="synthetic"?r.rows===e.rows&&r.index===e.index:!1}a(be,"sameTarget");function I(r,e,t){if(e.kind==="current"){R(r,e.lineNumber).annotations.push(t);return}let n=x(e.rows[e.index]);e.rows[e.index]={...n,suffix:`${n.suffix??""} ${t}`}}a(I,"annotateTarget");function we(r,e){if(e===void 0)return r;let t=e.annotations.length===0?"":` ${e.annotations.join(" ")}`;return{...r,presentation:{...r.presentation,...e.added&&{marker:"+"},before:[...r.presentation?.before??[],...e.before],after:[...e.after,...r.presentation?.after??[]],suffix:`${r.presentation?.suffix??""}${t}`}}}a(we,"presentLine");function R(r,e){let t=r.get(e);if(t!==void 0)return t;let n={before:[],after:[],annotations:[],added:!1};return r.set(e,n),n}a(R,"presentationsFor");function Te(r,e){return e<=r.lines.length?{lineNumber:Math.max(1,e),after:!1}:{lineNumber:r.lines.length,after:!0}}a(Te,"placementFor");function Ce(r){if(r.length===0)return[];let e=r.split(/\r\n|\r|\n/u);return e.at(-1)===""&&e.pop(),e}a(Ce,"splitLines");var T=class{static{a(this,"IndexMutationQueue")}tail=Promise.resolve();run(e){let t=this.tail.then(e,e);return this.tail=t.then(()=>{},()=>{}),t}};import{createHash as ve}from"node:crypto";import{realpathSync as ke}from"node:fs";import J from"node:path";import{fileURLToPath as Ee}from"node:url";var v=class{static{a(this,"LastTextTransactionStore")}#e=new Map;observe(e){let t=Z(e.resourceSource,e.cwd);if(e.postProcessing==="final"){let n=this.#e.get(t);n&&n.afterDigest===C(e.before.content)?this.#e.set(t,{...n,afterDigest:C(e.after.content)}):this.#e.delete(t);return}if(e.intent!=="edit"||!e.existed||e.before.content===e.after.content){this.#e.delete(t);return}this.#e.set(t,{before:e.before.content,afterDigest:C(e.after.content)})}restore(e,t,n){let o=Z(e,t),i=this.#e.get(o);if(i===void 0)throw new Error(`No last text transaction is available for ${e}.`);if(i.afterDigest!==C(n))throw this.#e.delete(o),new Error(`${e} changed after its last text transaction; refusing to overwrite newer text.`);return i.before}};function Z(r,e){return r.startsWith("file://")?Y(Ee(new URL(r))):/^[a-z][a-z\d+.-]*:/iu.test(r)?r:Y(J.resolve(e,r))}a(Z,"sourceKey");function Y(r){try{return ke.native(r)}catch{return J.normalize(r)}}a(Y,"canonicalFile");function C(r){return ve("sha256").update(r).digest("hex")}a(C,"textDigest");import{readFile as Pe}from"node:fs/promises";import Ae from"node:path";import{defineTool as Ge,withFileMutationQueue as Ie}from"@earendil-works/pi-coding-agent";import{Type as S}from"typebox";var E=S.Object({file:S.String({description:"Path to the tracked text file"}),change:S.String({description:"Complete CHANGE#HASH anchor shown by read",pattern:"^CHANGE#[0-9A-F]{4,64}$"})},{additionalProperties:!1});function ee(r,e,t){r.registerTool(k("stage",e,t)),r.registerTool(k("unstage",e,t))}a(ee,"registerIndexChangeTools");function k(r,e,t){let n=r==="stage"?"staged":"unstaged",o=r==="stage"?"Staged":"Unstaged";return Ge({name:r,label:r,promptSnippet:`${o.slice(0,-1)} a selected Git change`,description:`Use ${r} to ${r==="stage"?"add one current Git change to the index":"remove one current Git change from the index"}. Select the change with a CHANGE# anchor; worktree content is kept.`,parameters:E,async execute(i,d,c,s,u){let l=Re(d.file,u.cwd);return Ie(l,()=>t.run(async()=>{let g=await Pe(l,"utf8"),f=await p.create(e,u.cwd,c);if(f.status!=="ready")throw new Error(f.message);let h=await f.service.changeIndex({source:l,worktreeText:g,cwd:u.cwd,...c!==void 0&&{signal:c}},d.change,r);if(h.status==="unavailable")throw new Error(h.message);if(h.status==="not-applicable")throw new Error(`${r} is not applicable to ${l}: ${h.reason}`);let y=h.status==="unchanged";return{content:[{type:"text",text:y?`${d.change} is already ${n} in ${d.file}.`:`${o} ${d.change} in ${d.file}.`}],details:{action:r,change:d.change,file:l,state:n,unchanged:y}}}))}})}a(k,"createIndexChangeTool");function Re(r,e){let t=r.startsWith("@")?r.slice(1):r;return Ae.resolve(e,t)}a(Re,"resolveFile");import{diffChars as Se}from"diff";import{Type as P}from"typebox";var He=P.Object({file:P.Optional(P.String({description:"File to restore; may be omitted to inherit the previous batched source"})),change:P.String({description:"Complete CHANGE#HASH anchor shown by read, or last for this file's latest text-editor transaction",pattern:"^(?:CHANGE#[0-9A-F]{4,64}|last)$"})},{additionalProperties:!1});function te(r,e,t){return{name:"undo",description:"Use undo to revert a selected uncommitted Git change or the latest text-editor transaction for one file. A CHANGE# anchor restores that change to HEAD in both worktree and index; last restores the file's state before its latest text-editor transaction.",promptSnippet:"Restore a Git change or the latest text edit",parameters:He,intent:"restore",source:{field:"file",inherited:!0},anchors:[{field:"change",sourceField:"file",kinds:[w],nonAnchorValues:["last"]}],async mutate(n,o){let i=n.sourceFor("file"),d,c;if(o.change==="last")d=e.restore(i,n.cwd,n.sourceDocument.content);else{await n.resolveAnchor("change");let s=await p.create(r,n.cwd,n.signal);if(s.status!=="ready")throw new Error(s.message);let u=await s.service.prepareUndo({source:i,worktreeText:n.sourceDocument.content,cwd:n.cwd,...n.signal!==void 0&&{signal:n.signal}},o.change);if(u.status!=="applied")throw u.status==="unavailable"?new Error(u.message):new Error(`Undo is not applicable to ${i}: ${u.reason}`);if(d=u.worktreeText,u.indexUpdate!==void 0){let l=u.indexUpdate;c=a(()=>t.run(()=>s.service.applyIndexUpdate(l,n.signal)),"afterWrite")}}return{edits:new Map([[i,{changes:$e(n.sourceDocument.content,d),action:"edited"}]]),...c!==void 0&&{afterWrite:c}}}}}a(te,"createUndoMutationTool");function $e(r,e){let t=[],n=0,o,i=0,d="",c=a(()=>{o!==void 0&&(t.push({from:o,to:o+i,insert:d}),o=void 0,i=0,d="")},"flush");for(let s of Se(r,e)){if(!s.added&&!s.removed){c(),n+=s.value.length;continue}o??=n,s.removed?(n+=s.value.length,i+=s.value.length):d+=s.value}return c(),t}a($e,"createTextChanges");async function Le(r){let e=W(r),t=new v,n=new T,o=X(e),i=q(e),d={protocol:F,apiVersion:U,id:"current-git-changes",setup(s){s.addView({view:"changes",presenter:o}),s.describe('views: ["changes"] \u2014 uncommitted edits in tracked files, staged/unstaged state, and CHANGE# anchors for stage, unstage and undo.')}},c={protocol:j,apiVersion:_,id:"current-git-changes",setup(s){s.addAnchorResolver({...i,kind:w,type:"auxiliary"}),s.onDidEdit(u=>{t.observe(u)}),s.addMutationTool(te(e,t,n));for(let u of["stage","unstage"]){let l=k(u,e,n);s.addScriptIndexOperation({name:u,parameters:E,execute:a((g,f,h)=>l.execute(`apply-${u}`,De.Decode(E,g),f,void 0,h),"execute")})}s.addTextPresenter({presenter:o})}};await Promise.all([O(r,K),M(r,d),B(r,c)]),ee(r,e,n)}a(Le,"registerGitChanges");export{Le as default};
|
package/dist/entry-29.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as P}from"./chunk-WZI4YC2O.js";import{a as F}from"./chunk-ERVMDQGX.js";import{a as x,b as E}from"./chunk-VFBLX4TG.js";import{a as j}from"./chunk-OBWZ5RYN.js";import{a as h,b as v}from"./chunk-KZBAJFCV.js";import{b,f as C,h as w,i as d,k as g,l as k}from"./chunk-KVGQG43U.js";import"./chunk-N34ATN52.js";import"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";import{copyFile as z,mkdtemp as $,rm as A}from"node:fs/promises";import y from"node:path";var D=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".mts",".cts",".json",".jsonc",".css",".scss",".html",".md",".yaml",".yml",".vue",".svelte"],O=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".mts",".cts",".json",".jsonc",".css",".scss",".less",".html",".htm",".md",".markdown",".mdx",".yaml",".yml",".toml"],u=[o("dart-format",["dart"],["dart"],["pubspec.yaml","analysis_options.yaml"],[".dart"],["dart","format","{file}"],"https://dart.dev/tools/dart-format"),o("zig-format",["zig"],["zig"],["build.zig","build.zig.zon","zls.json"],[".zig",".zon"],["zig","fmt","{file}"],"https://ziglang.org/documentation/master/"),o("styler",["r"],["Rscript"],[".Rprofile","DESCRIPTION"],[".r"],["Rscript","-e","styler::style_file(commandArgs(TRUE)[1])","{file}"],"https://styler.r-lib.org/"),o("clang-format",["c","cpp"],["clang-format"],[".clang-format","_clang-format"],[".c",".h",".cc",".cpp",".cxx",".hh",".hpp",".hxx"],["clang-format","-i","{file}"],"https://clang.llvm.org/docs/ClangFormat.html"),o("prettier",["javascript","typescript","html","css","json","yaml","markdown","vue","svelte"],["prettier"],[".prettierrc",".prettierrc.json",".prettierrc.json5",".prettierrc.yaml",".prettierrc.yml",".prettierrc.toml",".prettierrc.js",".prettierrc.cjs",".prettierrc.mjs","prettier.config.js","prettier.config.cjs","prettier.config.mjs","prettier.config.ts","prettier.config.mts","prettier.config.cts"],D,["prettier","--write","{file}"],"https://prettier.io/docs/",["prettier"],{"package.json":["prettier"]}),o("biome",["javascript","typescript","json","css"],["biome"],["biome.json","biome.jsonc"],[".js",".jsx",".mjs",".cjs",".ts",".tsx",".mts",".cts",".json",".jsonc",".css"],["biome","format","--write","{file}"],"https://biomejs.dev/",["@biomejs/biome"]),o("oxfmt",["javascript","typescript","json","css","html","markdown","yaml","toml"],["oxfmt"],[".oxfmtrc.json",".oxfmtrc.jsonc","oxfmt.config.ts","oxfmt.config.mts"],O,["oxfmt","--write","{file}"],"https://oxc.rs/docs/guide/usage/formatter.html",["oxfmt"]),o("ruff-format",["python"],["ruff"],["ruff.toml",".ruff.toml"],[".py",".pyi"],["ruff","format","{file}"],"https://docs.astral.sh/ruff/formatter/",["ruff"],{"pyproject.toml":["tool.ruff"]}),o("black",["python"],["black"],[],[".py",".pyi"],["black","--quiet","{file}"],"https://black.readthedocs.io/",["black"],{"pyproject.toml":["tool.black"]}),o("gofmt",["go"],["gofmt"],["go.mod"],[".go"],["gofmt","-w","{file}"],"https://pkg.go.dev/cmd/gofmt"),o("goimports",["go"],["goimports"],["go.mod"],[".go"],["goimports","-w","{file}"],"https://pkg.go.dev/golang.org/x/tools/cmd/goimports"),o("rustfmt",["rust"],["rustfmt"],["rustfmt.toml",".rustfmt.toml","Cargo.toml"],[".rs"],["rustfmt","{file}"],"https://github.com/rust-lang/rustfmt"),o("csharpier",["csharp"],["csharpier"],[".csharpierrc",".csharpierrc.json",".csharpierrc.yaml",".csharpierrc.yml"],[".cs"],["csharpier","format","{file}"],"https://csharpier.com/"),o("google-java-format",["java"],["google-java-format"],["pom.xml","build.gradle"],[".java"],["google-java-format","--replace","{file}"],"https://github.com/google/google-java-format"),o("ktlint-format",["kotlin"],["ktlint"],[".editorconfig","build.gradle.kts"],[".kt",".kts"],["ktlint","-F","{file}"],"https://pinterest.github.io/ktlint/"),o("rubocop-format",["ruby"],["rubocop"],[".rubocop.yml","Gemfile"],[".rb",".rake"],["rubocop","--fix-layout","{file}"],"https://docs.rubocop.org/"),o("pint",["php"],["pint"],["pint.json","composer.json"],[".php"],["pint","{file}"],"https://laravel.com/docs/pint"),o("swift-format",["swift"],["swift-format"],[".swift-format","Package.swift"],[".swift"],["swift-format","format","--in-place","{file}"],"https://github.com/swiftlang/swift-format"),o("stylua",["lua"],["stylua"],["stylua.toml",".stylua.toml"],[".lua"],["stylua","{file}"],"https://github.com/JohnnyMorganz/StyLua"),o("shfmt",["shell"],["shfmt"],[".editorconfig"],[".sh",".bash",".zsh"],["shfmt","-w","{file}"],"https://github.com/mvdan/sh"),o("taplo",["toml"],["taplo"],["taplo.toml"],[".toml"],["taplo","format","{file}"],"https://taplo.tamasfe.dev/"),o("sqlfluff-format",["sql"],["sqlfluff"],[".sqlfluff","pyproject.toml"],[".sql"],["sqlfluff","format","{file}"],"https://docs.sqlfluff.com/"),o("terraform-fmt",["terraform"],["terraform"],[".terraform.lock.hcl"],[".tf",".tfvars"],["terraform","fmt","{file}"],"https://developer.hashicorp.com/terraform/cli/commands/fmt"),o("cmake-format",["cmake"],["cmake-format"],[".cmake-format.py","CMakeLists.txt"],[".cmake"],["cmake-format","-i","{file}"],"https://cmake-format.readthedocs.io/",void 0,void 0,["CMakeLists.txt"]),o("xmlformat",["xml"],["xmlformat"],[".xmlformat.conf"],[".xml",".xsd",".xsl"],["xmlformat","--overwrite","{file}"],"https://github.com/pamoller/xmlformatter"),o("mix-format",["elixir"],["mix"],["mix.exs",".formatter.exs"],[".ex",".exs"],["mix","format","{file}"],"https://hexdocs.pm/mix/Mix.Tasks.Format.html"),o("scalafmt",["scala"],["scalafmt"],[".scalafmt.conf"],[".scala",".sc",".sbt"],["scalafmt","{file}"],"https://scalameta.org/scalafmt/"),o("julia-format",["julia"],["julia"],[".JuliaFormatter.toml","Project.toml"],[".jl"],["julia","--startup-file=no","--history-file=no","-e","using JuliaFormatter; format_file(ARGS[1])","{file}"],"https://github.com/domluna/JuliaFormatter.jl"),o("powershell-format",["powershell"],["pwsh"],["PSScriptAnalyzerSettings.psd1"],[".ps1",".psm1",".psd1"],["pwsh","-NoProfile","-NonInteractive","-CommandWithArgs",'$ErrorActionPreference="Stop";$p=$args[0];$options=@{};if(Test-Path -LiteralPath PSScriptAnalyzerSettings.psd1){$options.Settings="PSScriptAnalyzerSettings.psd1"};[IO.File]::WriteAllText($p,(Invoke-Formatter -ScriptDefinition ([IO.File]::ReadAllText($p)) @options))',"{file}"],"https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-formatter"),o("dockfmt",["dockerfile"],["dockfmt"],["Dockerfile","Containerfile"],[".dockerfile"],["dockfmt","fmt","--write","{file}"],"https://github.com/jessfraz/dockfmt",void 0,void 0,["Dockerfile","Containerfile"])];function o(r,t,e,i,a,n,m,f,s,c){return{id:r,name:r,kind:"formatter",languages:t,executables:e,configFiles:i,documentation:m,...f&&{dependencies:f},...s&&{configSections:s},formatter:{extensions:a,...c&&{fileNames:c},run:{command:n},output:"in-place"}}}l(o,"recipe");var p=class r{constructor(t,e,i=new Map){this.formatters=t;this.availableBuiltIns=e;this.evidence=i}static{l(this,"FormatterCommandRegistry")}static async fromDirectory(t,e={}){let i=await C(t,"formatters",s=>k(s).formatters,e),a=e.environment??process.env,n=await Promise.all(i.entries.filter(s=>s.layer==="built-in").map(async s=>({id:s.id,available:await d(s.config.run,t,a)}))),m=await P(t,u),f=[...i.entries].sort((s,c)=>s.layer==="built-in"&&c.layer==="built-in"?(m.get(c.id)?.score??0)-(m.get(s.id)?.score??0):0);return new r(f,new Set(n.filter(s=>s.available).map(s=>s.id)),m)}static fromConfig(t){return new r(Object.entries(t.formatters).map(([e,i])=>({id:e,config:i,layer:"project",sourcePath:"<memory>"})),new Set)}resolve(t,e){return this.resolveEntry(t,e)?.config}resolveEntry(t,e){return w(this.formatters,this.availableBuiltIns,this.evidence,t,e)}get entries(){return this.formatters}};var R={protocol:x,apiVersion:1,id:"formatter",setup(r){for(let t of u)r.addToolRecipe(t);r.addSetupCheck({id:"effective-config",inspect:M}),r.addCheck({id:"config",title:"Formatter",async run(t){try{let e=await p.fromDirectory(t.cwd,{environment:t.env}),i=_(e,t.files,t.cwd);return i.length===0?[{status:"skip",message:"No formatter matches the inspected project files"}]:await Promise.all(i.map(async({entry:a,source:n})=>{let m=`${a.id} [${a.layer}] command ${JSON.stringify(a.config.run.command)}`,f=await $(y.join(y.dirname(n),".pi-agent-ide-doctor-")),s=y.join(f,y.basename(n));try{return await z(n,s),(await g(a.config,{projectRoot:t.cwd,filePath:s,env:t.env})).ok?{status:"pass",message:`${m}: probe passed`,detail:a.sourcePath}:{status:"fail",message:`${m}: probe failed`,detail:a.sourcePath}}catch(c){return{status:"fail",message:`${m}: ${c instanceof Error?c.message:String(c)}`,detail:a.sourcePath}}finally{await A(f,{recursive:!0,force:!0})}}))}catch(e){return[{status:"fail",message:e instanceof Error?e.message:String(e)}]}}})}};async function M(r){try{let t=await p.fromDirectory(r.cwd,{environment:r.env}),e=[],i=new Map;for(let[a,n]of r.detectedLanguages){let m=n.map(f=>t.resolveEntry(f,r.cwd)).find(f=>f!==void 0);m!==void 0&&(e.push({kind:"formatter",languageId:a,toolId:m.id}),await d(m.config.run,r.cwd,r.env)||i.set(m.id,{id:`formatter-${m.id}-unavailable`,message:`Configured formatter ${m.id} cannot run ${JSON.stringify(m.config.run.command)}`}))}return{selections:e,actions:[...i.values()]}}catch(t){return{actions:[{id:"formatter-config-invalid",message:`Formatter configuration cannot load: ${t instanceof Error?t.message:String(t)}`}]}}}l(M,"inspectFormatterSetup");function _(r,t,e){let i=new Map;for(let a of t){let n=r.resolveEntry(a,e);n!==void 0&&!i.has(n.id)&&i.set(n.id,{entry:n,source:a})}return[...i.values()]}l(_,"applicableFormatters");var T=new Map;function I(){return{kind:"formatter",name:"formatter",priority:100,extensions:["*"],detect:l(async r=>(await S(r.cwd),!0),"detect"),async format({filePath:r},t){let i=(await S(t.cwd)).resolve(r,t.cwd);if(i===void 0)return{ok:!0,edits:0,formatter:null};let a=b(i.run.command);try{let n=await g(i,{projectRoot:t.cwd,filePath:r});return{ok:n.ok,edits:n.changed?1:0,formatter:a}}catch{return{ok:!1,edits:0,formatter:a}}}}}l(I,"createFormatter");async function S(r){let t=T.get(r);return t===void 0&&(t=p.fromDirectory(r),T.set(r,t)),t}l(S,"loadRegistry");async function L(r){let t={kind:"formatter",name:"pi-agent-ide-formatter",priority:200,extensions:["*"],detect:l(()=>Promise.resolve(!0),"detect"),async format(i,a){return I().format(i,a)}},e={protocol:h,apiVersion:3,id:"formatter",setup(i){i.addTool(t)}};await Promise.all([j(r,e),F(r,R)])}l(L,"registerFormatter");export{L as default};
|
|
1
|
+
import{a as P}from"./chunk-ERVMDQGX.js";import{a as F,b as R}from"./chunk-VFBLX4TG.js";import{a as j}from"./chunk-HKMBQLEK.js";import{a as h,b as v}from"./chunk-Z3VC3S2T.js";import{b as C,c as w,g as k,i as x,j as g,l as u,m as E}from"./chunk-M5MJP7Z2.js";import{a as b}from"./chunk-WZI4YC2O.js";import"./chunk-N34ATN52.js";import"./chunk-ZC65Z3CK.js";import{a as f}from"./chunk-EI7MMDWY.js";import{copyFile as $,mkdtemp as A,rm as M}from"node:fs/promises";import y from"node:path";var D=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".mts",".cts",".json",".jsonc",".css",".scss",".html",".md",".yaml",".yml",".vue",".svelte"],z=[".js",".jsx",".mjs",".cjs",".ts",".tsx",".mts",".cts",".json",".jsonc",".css",".scss",".less",".html",".htm",".md",".markdown",".mdx",".yaml",".yml",".toml"],d=[e("dart-format",["dart"],["dart"],["pubspec.yaml","analysis_options.yaml"],[".dart"],["dart","format","{file}"],"https://dart.dev/tools/dart-format"),e("zig-format",["zig"],["zig"],["build.zig","build.zig.zon","zls.json"],[".zig",".zon"],["zig","fmt","{file}"],"https://ziglang.org/documentation/master/"),e("styler",["r"],["Rscript"],[".Rprofile","DESCRIPTION"],[".r"],["Rscript","-e","styler::style_file(commandArgs(TRUE)[1])","{file}"],"https://styler.r-lib.org/"),e("clang-format",["c","cpp"],["clang-format"],[".clang-format","_clang-format"],[".c",".h",".cc",".cpp",".cxx",".hh",".hpp",".hxx"],["clang-format","-i","{file}"],"https://clang.llvm.org/docs/ClangFormat.html"),e("prettier",["javascript","typescript","html","css","json","yaml","markdown","vue","svelte"],["prettier"],[".prettierrc",".prettierrc.json",".prettierrc.json5",".prettierrc.yaml",".prettierrc.yml",".prettierrc.toml",".prettierrc.js",".prettierrc.cjs",".prettierrc.mjs","prettier.config.js","prettier.config.cjs","prettier.config.mjs","prettier.config.ts","prettier.config.mts","prettier.config.cts"],D,["prettier","--write","{file}"],"https://prettier.io/docs/",["prettier"],{"package.json":["prettier"]}),e("biome",["javascript","typescript","json","css"],["biome"],["biome.json","biome.jsonc"],[".js",".jsx",".mjs",".cjs",".ts",".tsx",".mts",".cts",".json",".jsonc",".css"],["biome","format","--write","{file}"],"https://biomejs.dev/",["@biomejs/biome"]),e("oxfmt",["javascript","typescript","json","css","html","markdown","yaml","toml"],["oxfmt"],[".oxfmtrc.json",".oxfmtrc.jsonc","oxfmt.config.ts","oxfmt.config.mts"],z,["oxfmt","--write","{file}"],"https://oxc.rs/docs/guide/usage/formatter.html",["oxfmt"]),e("ruff-format",["python"],["ruff"],["ruff.toml",".ruff.toml"],[".py",".pyi"],["ruff","format","{file}"],"https://docs.astral.sh/ruff/formatter/",["ruff"],{"pyproject.toml":["tool.ruff"]}),e("black",["python"],["black"],[],[".py",".pyi"],["black","--quiet","{file}"],"https://black.readthedocs.io/",["black"],{"pyproject.toml":["tool.black"]}),e("gofmt",["go"],["gofmt"],["go.mod"],[".go"],["gofmt","-w","{file}"],"https://pkg.go.dev/cmd/gofmt"),e("goimports",["go"],["goimports"],["go.mod"],[".go"],["goimports","-w","{file}"],"https://pkg.go.dev/golang.org/x/tools/cmd/goimports"),e("rustfmt",["rust"],["rustfmt"],["rustfmt.toml",".rustfmt.toml","Cargo.toml"],[".rs"],["rustfmt","{file}"],"https://github.com/rust-lang/rustfmt"),e("csharpier",["csharp"],["csharpier"],[".csharpierrc",".csharpierrc.json",".csharpierrc.yaml",".csharpierrc.yml"],[".cs"],["csharpier","format","{file}"],"https://csharpier.com/"),e("google-java-format",["java"],["google-java-format"],["pom.xml","build.gradle"],[".java"],["google-java-format","--replace","{file}"],"https://github.com/google/google-java-format"),e("ktlint-format",["kotlin"],["ktlint"],[".editorconfig","build.gradle.kts"],[".kt",".kts"],["ktlint","-F","{file}"],"https://pinterest.github.io/ktlint/"),e("rubocop-format",["ruby"],["rubocop"],[".rubocop.yml","Gemfile"],[".rb",".rake"],["rubocop","--fix-layout","{file}"],"https://docs.rubocop.org/"),e("pint",["php"],["pint"],["pint.json","composer.json"],[".php"],["pint","{file}"],"https://laravel.com/docs/pint"),e("swift-format",["swift"],["swift-format"],[".swift-format","Package.swift"],[".swift"],["swift-format","format","--in-place","{file}"],"https://github.com/swiftlang/swift-format"),e("stylua",["lua"],["stylua"],["stylua.toml",".stylua.toml"],[".lua"],["stylua","{file}"],"https://github.com/JohnnyMorganz/StyLua"),e("shfmt",["shell"],["shfmt"],[".editorconfig"],[".sh",".bash",".zsh"],["shfmt","-w","{file}"],"https://github.com/mvdan/sh"),e("taplo",["toml"],["taplo"],["taplo.toml"],[".toml"],["taplo","format","{file}"],"https://taplo.tamasfe.dev/"),e("sqlfluff-format",["sql"],["sqlfluff"],[".sqlfluff","pyproject.toml"],[".sql"],["sqlfluff","format","{file}"],"https://docs.sqlfluff.com/"),e("terraform-fmt",["terraform"],["terraform"],[".terraform.lock.hcl"],[".tf",".tfvars"],["terraform","fmt","{file}"],"https://developer.hashicorp.com/terraform/cli/commands/fmt"),e("cmake-format",["cmake"],["cmake-format"],[".cmake-format.py","CMakeLists.txt"],[".cmake"],["cmake-format","-i","{file}"],"https://cmake-format.readthedocs.io/",void 0,void 0,["CMakeLists.txt"]),e("xmlformat",["xml"],["xmlformat"],[".xmlformat.conf"],[".xml",".xsd",".xsl"],["xmlformat","--overwrite","{file}"],"https://github.com/pamoller/xmlformatter"),e("mix-format",["elixir"],["mix"],["mix.exs",".formatter.exs"],[".ex",".exs"],["mix","format","{file}"],"https://hexdocs.pm/mix/Mix.Tasks.Format.html"),e("scalafmt",["scala"],["scalafmt"],[".scalafmt.conf"],[".scala",".sc",".sbt"],["scalafmt","{file}"],"https://scalameta.org/scalafmt/"),e("julia-format",["julia"],["julia"],[".JuliaFormatter.toml","Project.toml"],[".jl"],["julia","--startup-file=no","--history-file=no","-e","using JuliaFormatter; format_file(ARGS[1])","{file}"],"https://github.com/domluna/JuliaFormatter.jl"),e("powershell-format",["powershell"],["pwsh"],["PSScriptAnalyzerSettings.psd1"],[".ps1",".psm1",".psd1"],["pwsh","-NoProfile","-NonInteractive","-CommandWithArgs",'$ErrorActionPreference="Stop";$p=$args[0];$options=@{};if(Test-Path -LiteralPath PSScriptAnalyzerSettings.psd1){$options.Settings="PSScriptAnalyzerSettings.psd1"};[IO.File]::WriteAllText($p,(Invoke-Formatter -ScriptDefinition ([IO.File]::ReadAllText($p)) @options))',"{file}"],"https://learn.microsoft.com/powershell/module/psscriptanalyzer/invoke-formatter"),e("dockfmt",["dockerfile"],["dockfmt"],["Dockerfile","Containerfile"],[".dockerfile"],["dockfmt","fmt","--write","{file}"],"https://github.com/jessfraz/dockfmt",void 0,void 0,["Dockerfile","Containerfile"])];function e(o,t,r,i,n,m,a,l,s,c){return{id:o,name:o,kind:"formatter",languages:t,executables:r,configFiles:i,documentation:a,...l&&{dependencies:l},...s&&{configSections:s},formatter:{extensions:n,...c&&{fileNames:c},run:{command:m},output:"in-place"}}}f(e,"recipe");var p=class o{constructor(t,r,i=new Map){this.formatters=t;this.availableBuiltIns=r;this.evidence=i}static{f(this,"FormatterCommandRegistry")}static async fromDirectory(t,r={}){let i=await k(t,"formatters",s=>E(s).formatters,r),n=r.environment??process.env,m=await Promise.all(i.entries.filter(s=>s.layer==="built-in").map(async s=>({id:s.id,available:await g(s.config.run,t,n)}))),a=await b(t,d),l=[...i.entries].sort((s,c)=>s.layer==="built-in"&&c.layer==="built-in"?(a.get(c.id)?.score??0)-(a.get(s.id)?.score??0):0);return new o(l,new Set(m.filter(s=>s.available&&(!r.requireBuiltInEvidence||(a.get(s.id)?.score??0)>0)).map(s=>s.id)),a)}static fromConfig(t){return new o(Object.entries(t.formatters).map(([r,i])=>({id:r,config:i,layer:"project",sourcePath:"<memory>"})),new Set)}resolve(t,r){return this.resolveEntry(t,r)?.config}resolveEntry(t,r){return x(this.formatters,this.availableBuiltIns,this.evidence,t,r)}get entries(){return this.formatters}};var T={protocol:F,apiVersion:1,id:"formatter",setup(o){for(let t of d)o.addToolRecipe(t);o.addSetupCheck({id:"effective-config",inspect:_}),o.addCheck({id:"config",title:"Formatter",async run(t){try{let r=await p.fromDirectory(t.cwd,{environment:t.env}),i=q(r,t.files,t.cwd);return i.length===0?[{status:"skip",message:"No formatter matches the inspected project files"}]:await Promise.all(i.map(async({entry:n,source:m})=>{let a=`${n.id} [${n.layer}] command ${JSON.stringify(n.config.run.command)}`,l=await A(y.join(y.dirname(m),".pi-agent-ide-doctor-")),s=y.join(l,y.basename(m));try{return await $(m,s),(await u(n.config,{projectRoot:t.cwd,filePath:s,env:t.env})).ok?{status:"pass",message:`${a}: probe passed`,detail:n.sourcePath}:{status:"fail",message:`${a}: probe failed`,detail:n.sourcePath}}catch(c){return{status:"fail",message:`${a}: ${c instanceof Error?c.message:String(c)}`,detail:n.sourcePath}}finally{await M(l,{recursive:!0,force:!0})}}))}catch(r){return[{status:"fail",message:r instanceof Error?r.message:String(r)}]}}})}};async function _(o){try{let t=await p.fromDirectory(o.cwd,{environment:o.env}),r=[],i=new Map;for(let[n,m]of o.detectedLanguages){let a=m.map(l=>t.resolveEntry(l,o.cwd)).find(l=>l!==void 0);a!==void 0&&(r.push({kind:"formatter",languageId:n,toolId:a.id}),await g(a.config.run,o.cwd,o.env)||i.set(a.id,{id:`formatter-${a.id}-unavailable`,message:`Configured formatter ${a.id} cannot run ${JSON.stringify(a.config.run.command)}`}))}return{selections:r,actions:[...i.values()]}}catch(t){return{actions:[{id:"formatter-config-invalid",message:`Formatter configuration cannot load: ${t instanceof Error?t.message:String(t)}`}]}}}f(_,"inspectFormatterSetup");function q(o,t,r){let i=new Map;for(let n of t){let m=o.resolveEntry(n,r);m!==void 0&&!i.has(m.id)&&i.set(m.id,{entry:m,source:n})}return[...i.values()]}f(q,"applicableFormatters");import L from"node:path";var S=new Map;function O(){return{kind:"formatter",name:"formatter",priority:100,extensions:["*"],detect:f(async o=>(await I(o.cwd),!0),"detect"),async format({filePath:o},t){let r=await w(t.cwd,o,"formatters",d);if(r===void 0)return{ok:!0,edits:0,formatter:null};let i=r!==L.resolve(t.cwd),m=(await I(r,i)).resolve(o,r);if(m===void 0)return{ok:!0,edits:0,formatter:null};let a=C(m.run.command);try{let l=await u(m,{projectRoot:r,filePath:o});return{ok:l.ok,edits:l.changed?1:0,formatter:a}}catch{return{ok:!1,edits:0,formatter:a}}}}}f(O,"createFormatter");async function I(o,t=!1){let r=JSON.stringify([o,t]),i=S.get(r);return i===void 0&&(i=p.fromDirectory(o,{includeGlobal:!t,requireBuiltInEvidence:t}),S.set(r,i)),i}f(I,"loadRegistry");async function N(o){let t={kind:"formatter",name:"pi-agent-ide-formatter",priority:200,extensions:["*"],detect:f(()=>Promise.resolve(!0),"detect"),async format(i,n){return O().format(i,n)}},r={protocol:h,apiVersion:4,id:"formatter",setup(i){i.addTool(t)}};await Promise.all([j(o,r),P(o,T)])}f(N,"registerFormatter");export{N as default};
|