pi-agent-ide 0.2.2 → 0.3.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 +25 -0
- package/README.md +12 -8
- package/dist/chunk-5MSNYFDE.js +1 -0
- package/dist/chunk-5VSE5X5R.js +2 -0
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
- 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-WNMGUALD.js → chunk-CEKXBS55.js} +1 -1
- package/dist/chunk-CW53ZTU3.js +2 -0
- package/dist/chunk-EWNWKDMP.js +4 -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-KAB3AYA2.js +1 -0
- package/dist/{chunk-THSCUT2L.js → chunk-LRYE2WCN.js} +1 -1
- 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-RHV5STR3.js +3 -0
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/chunk-SSHZEWWV.js +1 -0
- package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
- package/dist/chunk-VZJIZXSH.js +14 -0
- 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 +6 -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 +61 -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-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/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 +173 -49
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +261 -9
- 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 +19 -10
- 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 +38 -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 +4 -15
- package/src/composite/extensions-config.ts +41 -0
- package/src/composite/feature-flags.ts +32 -0
- package/src/composite/module-labels.ts +55 -0
- package/src/composite/module-settings-store.ts +44 -0
- package/src/composite/module-settings.ts +132 -0
- package/src/composite/selection.ts +4 -4
- package/src/composite/settings-panel.ts +71 -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 +61 -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 +19 -10
- 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/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 +173 -49
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +261 -9
- 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 +42 -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/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-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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { open, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import type { ReadRequest, ReadToolResult } from "#src/api/tools/read.js";
|
|
6
|
+
import { failureResult } from "#src/core/tools/read/read-result.js";
|
|
7
|
+
import {
|
|
8
|
+
READ_OUTPUT_MAX_BYTES,
|
|
9
|
+
READ_OUTPUT_MAX_LINES,
|
|
10
|
+
} from "#src/core/tools/read/output-truncation.js";
|
|
11
|
+
|
|
12
|
+
/** Read original local file bytes, without text conversion or source annotations. */
|
|
13
|
+
export async function readRaw(
|
|
14
|
+
request: ReadRequest,
|
|
15
|
+
context: { cwd: string; signal?: AbortSignal },
|
|
16
|
+
audience: "agent" | "script",
|
|
17
|
+
): Promise<ReadToolResult> {
|
|
18
|
+
const requested = request.path ?? "";
|
|
19
|
+
try {
|
|
20
|
+
if ((request.views?.length ?? 0) > 0)
|
|
21
|
+
throw new Error("Raw byte reads do not accept text views");
|
|
22
|
+
const offset = request.offset ?? 0;
|
|
23
|
+
const limit = request.limit;
|
|
24
|
+
if (
|
|
25
|
+
!Number.isSafeInteger(offset) ||
|
|
26
|
+
(limit !== undefined && (!Number.isSafeInteger(limit) || limit < 0))
|
|
27
|
+
)
|
|
28
|
+
throw new Error("Use an integer byte offset and a non-negative integer byte limit");
|
|
29
|
+
const input = requested.slice(4);
|
|
30
|
+
if (input.length === 0) throw new Error("Supply a local file after raw:");
|
|
31
|
+
const file = input.startsWith("file://")
|
|
32
|
+
? fileURLToPath(input)
|
|
33
|
+
: path.resolve(context.cwd, input);
|
|
34
|
+
context.signal?.throwIfAborted();
|
|
35
|
+
if (!(await stat(file)).isFile()) throw new Error("Raw reads require a regular file");
|
|
36
|
+
const handle = await open(file, "r");
|
|
37
|
+
try {
|
|
38
|
+
const stat = await handle.stat();
|
|
39
|
+
if (!stat.isFile()) throw new Error("Raw reads require a regular file");
|
|
40
|
+
const start = Math.min(stat.size, Math.max(0, offset < 0 ? stat.size + offset : offset));
|
|
41
|
+
const requestedLength = Math.min(limit ?? stat.size, stat.size - start);
|
|
42
|
+
// A row contains 16 bytes and at most 90 ASCII characters, including large offsets.
|
|
43
|
+
const displayBudget =
|
|
44
|
+
16 *
|
|
45
|
+
Math.max(
|
|
46
|
+
1,
|
|
47
|
+
Math.min(READ_OUTPUT_MAX_LINES - 4, Math.floor((READ_OUTPUT_MAX_BYTES - 1024) / 90)),
|
|
48
|
+
);
|
|
49
|
+
const length =
|
|
50
|
+
audience === "script" ? requestedLength : Math.min(requestedLength, displayBudget);
|
|
51
|
+
const buffer = Buffer.alloc(length);
|
|
52
|
+
let count = 0;
|
|
53
|
+
while (count < length) {
|
|
54
|
+
context.signal?.throwIfAborted();
|
|
55
|
+
const chunk = await handle.read(buffer, count, length - count, start + count);
|
|
56
|
+
if (chunk.bytesRead === 0) break;
|
|
57
|
+
count += chunk.bytesRead;
|
|
58
|
+
}
|
|
59
|
+
context.signal?.throwIfAborted();
|
|
60
|
+
const bytes = buffer.subarray(0, count);
|
|
61
|
+
const source = `raw:${file}`;
|
|
62
|
+
const nextOffset = start + count;
|
|
63
|
+
const hasMore = nextOffset < stat.size;
|
|
64
|
+
const header = `${source}\nBytes ${start}..${nextOffset} (end exclusive), ${stat.size} bytes total`;
|
|
65
|
+
const rows = formatRawBytes(bytes, start);
|
|
66
|
+
const continuation = hasMore ? `\nUse offset=${nextOffset} to continue in bytes.` : "";
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: `${header}\n${rows}${continuation}` }],
|
|
69
|
+
details: {
|
|
70
|
+
source,
|
|
71
|
+
resolvedBy: "raw",
|
|
72
|
+
byteOffset: start,
|
|
73
|
+
byteLength: count,
|
|
74
|
+
totalBytes: stat.size,
|
|
75
|
+
},
|
|
76
|
+
...(audience === "script" && {
|
|
77
|
+
script: {
|
|
78
|
+
kind: "bytes" as const,
|
|
79
|
+
source,
|
|
80
|
+
byteOffset: start,
|
|
81
|
+
byteLength: count,
|
|
82
|
+
totalBytes: stat.size,
|
|
83
|
+
bytes: Array.from(bytes),
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
87
|
+
} finally {
|
|
88
|
+
await handle.close();
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (context.signal?.aborted) throw error;
|
|
92
|
+
return failureResult({
|
|
93
|
+
code: "READ_FAILED",
|
|
94
|
+
source: requested,
|
|
95
|
+
message: error instanceof Error ? error.message : String(error),
|
|
96
|
+
cause: error,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Render exact byte values with absolute hexadecimal offsets and a printable ASCII preview. */
|
|
102
|
+
export function formatRawBytes(bytes: Uint8Array, offset: number): string {
|
|
103
|
+
const rows: string[] = [];
|
|
104
|
+
for (let index = 0; index < bytes.length; index += 16) {
|
|
105
|
+
const row = bytes.subarray(index, index + 16);
|
|
106
|
+
const hex = Array.from(row, (byte) => byte.toString(16).padStart(2, "0")).join(" ");
|
|
107
|
+
const ascii = Array.from(row, (byte) =>
|
|
108
|
+
byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : ".",
|
|
109
|
+
).join("");
|
|
110
|
+
rows.push(`${(offset + index).toString(16).padStart(8, "0")} ${hex.padEnd(47)} |${ascii}|`);
|
|
111
|
+
}
|
|
112
|
+
return rows.join("\n");
|
|
113
|
+
}
|
|
@@ -39,6 +39,57 @@ interface ReadCallArguments {
|
|
|
39
39
|
readonly views?: unknown;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
interface ReadWindowPresentation {
|
|
43
|
+
readonly pathSuffix: string;
|
|
44
|
+
readonly qualifiers: readonly { readonly text: string }[];
|
|
45
|
+
readonly details: readonly { readonly label: string; readonly value: string }[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readWindowPresentation(
|
|
49
|
+
path: string,
|
|
50
|
+
rawOffset: unknown,
|
|
51
|
+
rawLimit: unknown,
|
|
52
|
+
): ReadWindowPresentation {
|
|
53
|
+
const offset = typeof rawOffset === "number" ? rawOffset : undefined;
|
|
54
|
+
const limit = typeof rawLimit === "number" ? rawLimit : undefined;
|
|
55
|
+
if (offset === undefined && limit === undefined) {
|
|
56
|
+
return { pathSuffix: "", qualifiers: [], details: [] };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const relative = path === "inherited source" || path.includes("#");
|
|
60
|
+
if (relative) {
|
|
61
|
+
const start = offset ?? 1;
|
|
62
|
+
const range = limit === undefined ? String(start) : `${start}-${start + limit - 1}`;
|
|
63
|
+
return {
|
|
64
|
+
pathSuffix: "",
|
|
65
|
+
qualifiers: [{ text: `relative lines ${range}` }],
|
|
66
|
+
details: [{ label: "relative lines", value: range }],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (offset !== undefined && offset < 0) {
|
|
71
|
+
return {
|
|
72
|
+
pathSuffix: "",
|
|
73
|
+
qualifiers: [
|
|
74
|
+
{ text: `tail ${Math.abs(offset)}` },
|
|
75
|
+
...(limit === undefined ? [] : [{ text: `limit ${limit}` }]),
|
|
76
|
+
],
|
|
77
|
+
details: [
|
|
78
|
+
{ label: "tail", value: String(Math.abs(offset)) },
|
|
79
|
+
...(limit === undefined ? [] : [{ label: "limit", value: String(limit) }]),
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const start = Math.max(1, offset ?? 1);
|
|
85
|
+
const range = limit === undefined ? String(start) : `${start}-${start + limit - 1}`;
|
|
86
|
+
return {
|
|
87
|
+
pathSuffix: `:${range}`,
|
|
88
|
+
qualifiers: [],
|
|
89
|
+
details: [{ label: "lines", value: range }],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
42
93
|
/** Renders the requested read source and non-default options in the shared tool-card header. */
|
|
43
94
|
export function renderReadCall(
|
|
44
95
|
arguments_: ReadCallArguments,
|
|
@@ -54,26 +105,17 @@ export function renderReadCall(
|
|
|
54
105
|
);
|
|
55
106
|
}
|
|
56
107
|
const path = typeof arguments_.path === "string" ? arguments_.path : "inherited source";
|
|
57
|
-
const
|
|
58
|
-
const limit = typeof arguments_.limit === "number" ? arguments_.limit : undefined;
|
|
108
|
+
const window = readWindowPresentation(path, arguments_.offset, arguments_.limit);
|
|
59
109
|
const views = Array.isArray(arguments_.views)
|
|
60
110
|
? arguments_.views.filter((view): view is string => typeof view === "string")
|
|
61
111
|
: [];
|
|
62
112
|
const qualifiers = [
|
|
63
|
-
...
|
|
64
|
-
? []
|
|
65
|
-
: [
|
|
66
|
-
{
|
|
67
|
-
text: offset < 0 ? `tail ${String(Math.abs(offset))}` : `offset ${String(offset)}`,
|
|
68
|
-
},
|
|
69
|
-
]),
|
|
70
|
-
...(limit === undefined ? [] : [{ text: `limit ${String(limit)}` }]),
|
|
113
|
+
...window.qualifiers,
|
|
71
114
|
...(views.length === 0 ? [] : [{ text: `views ${views.join(",")}` }]),
|
|
72
115
|
];
|
|
73
116
|
const details = [
|
|
74
117
|
...(typeof arguments_.path === "string" ? [{ label: "path", value: arguments_.path }] : []),
|
|
75
|
-
...
|
|
76
|
-
...(limit === undefined ? [] : [{ label: "limit", value: String(limit) }]),
|
|
118
|
+
...window.details,
|
|
77
119
|
...(views.length === 0 ? [] : [{ label: "views", value: views.join(",") }]),
|
|
78
120
|
];
|
|
79
121
|
return toolCallHeader(
|
|
@@ -81,7 +123,7 @@ export function renderReadCall(
|
|
|
81
123
|
{
|
|
82
124
|
tool: "read",
|
|
83
125
|
primary: {
|
|
84
|
-
text: path
|
|
126
|
+
text: `${path}${window.pathSuffix}`,
|
|
85
127
|
color: typeof arguments_.path === "string" ? "accent" : "muted",
|
|
86
128
|
underline: typeof arguments_.path === "string",
|
|
87
129
|
truncate: "start",
|
|
@@ -122,6 +164,9 @@ export function createReadResultRenderer(options: ReadResultRendererOptions): Re
|
|
|
122
164
|
return new Text(theme.fg(color, text), 0, 0);
|
|
123
165
|
}
|
|
124
166
|
|
|
167
|
+
const check = readDetails(result.details).diagnosticCheck;
|
|
168
|
+
if (check?.complete && check.count === 0) return new Container();
|
|
169
|
+
|
|
125
170
|
if (!hasTextContent(result)) {
|
|
126
171
|
return context.lastComponent instanceof Container ? context.lastComponent : new Container();
|
|
127
172
|
}
|
|
@@ -180,7 +225,9 @@ export class ReadResultPanel implements Component {
|
|
|
180
225
|
|
|
181
226
|
const innerWidth = width - 2;
|
|
182
227
|
const contentWidth = Math.max(1, innerWidth - 2);
|
|
183
|
-
const renderedRows = renderContentRows(this.state, contentWidth)
|
|
228
|
+
const renderedRows = renderContentRows(this.state, contentWidth).flatMap((row) =>
|
|
229
|
+
wrapTextWithAnsi(row, contentWidth),
|
|
230
|
+
);
|
|
184
231
|
const rows = compactRows(renderedRows, this.state.expanded, this.state.theme);
|
|
185
232
|
const lines = [renderTopBorder(this.state, innerWidth, this.state.theme)];
|
|
186
233
|
|
|
@@ -42,6 +42,7 @@ export function createReadState(
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export interface ReadProjectionOptions {
|
|
45
|
+
readonly audience?: "agent" | "script";
|
|
45
46
|
/** Absolute 1-based line where an anchored read's window starts. */
|
|
46
47
|
readonly originLine?: number;
|
|
47
48
|
}
|
|
@@ -64,6 +65,9 @@ export function projectReadState(
|
|
|
64
65
|
const projected = projectAgentContent(state.content);
|
|
65
66
|
|
|
66
67
|
return {
|
|
68
|
+
...(options?.audience === "script" && {
|
|
69
|
+
script: { kind: "native" as const, source: state.source, blocks: state.content },
|
|
70
|
+
}),
|
|
67
71
|
content: projected.content,
|
|
68
72
|
details: {
|
|
69
73
|
...readDetails(state),
|
|
@@ -100,6 +104,17 @@ export function projectReadState(
|
|
|
100
104
|
];
|
|
101
105
|
|
|
102
106
|
return {
|
|
107
|
+
...(options?.audience === "script" && {
|
|
108
|
+
script: {
|
|
109
|
+
kind: "text" as const,
|
|
110
|
+
source: state.source,
|
|
111
|
+
content: lines.map((line) => line.content + line.lineEnding).join(""),
|
|
112
|
+
lines,
|
|
113
|
+
startLine: lines[0]?.lineNumber ?? 0,
|
|
114
|
+
endLine: lines.at(-1)?.lineNumber ?? 0,
|
|
115
|
+
totalLines,
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
103
118
|
content,
|
|
104
119
|
details: {
|
|
105
120
|
...readDetails(state),
|
|
@@ -1,73 +1,68 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { mkdir, mkdtemp, readFile, rm,
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
6
|
import type { AgentContent, ResourceResolutionAttempt, ResourceResolver } from "pi-agent-resource";
|
|
7
7
|
|
|
8
|
-
export const TEMP_RESOURCE_TTL_MS = 5 * 60_000;
|
|
9
|
-
|
|
10
|
-
interface TemporaryResource {
|
|
11
|
-
activeReads: number;
|
|
12
|
-
lastUsedAt: number;
|
|
13
|
-
readonly filePath: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
8
|
export interface TempResourceStoreOptions {
|
|
9
|
+
/** Parent folder for this store's private temporary directory. */
|
|
17
10
|
readonly parentDirectory?: string;
|
|
18
|
-
readonly ttlMs?: number;
|
|
19
11
|
}
|
|
20
12
|
|
|
13
|
+
/** Keeps temporary text resources isolated and readable until the owning runtime disposes it. */
|
|
21
14
|
export class TempResourceStore {
|
|
22
15
|
readonly resolver: ResourceResolver;
|
|
23
|
-
readonly #entries = new Map<string,
|
|
16
|
+
readonly #entries = new Map<string, string>();
|
|
17
|
+
readonly #pendingSaves = new Set<Promise<string>>();
|
|
24
18
|
readonly #parentDirectory: string;
|
|
25
|
-
readonly #ttlMs: number;
|
|
26
19
|
#directoryReady: Promise<string> | undefined;
|
|
27
|
-
#
|
|
28
|
-
#timer: ReturnType<typeof setTimeout> | undefined;
|
|
20
|
+
#disposal: Promise<void> | undefined;
|
|
29
21
|
|
|
30
22
|
constructor(options: TempResourceStoreOptions = {}) {
|
|
31
23
|
this.#parentDirectory = options.parentDirectory ?? tmpdir();
|
|
32
|
-
this.#ttlMs = options.ttlMs ?? TEMP_RESOURCE_TTL_MS;
|
|
33
|
-
|
|
34
|
-
if (!Number.isFinite(this.#ttlMs) || this.#ttlMs <= 0) {
|
|
35
|
-
throw new TypeError("Temporary resource TTL must be a positive finite number");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
24
|
this.resolver = {
|
|
39
25
|
id: "temp",
|
|
40
26
|
tryResolve: (source) => Promise.resolve(this.#resolve(source)),
|
|
41
27
|
};
|
|
42
28
|
}
|
|
43
29
|
|
|
30
|
+
/** Saves text and returns a reference owned by this store. Rejects after disposal starts. */
|
|
44
31
|
async save(text: string): Promise<string> {
|
|
45
|
-
if (this.#
|
|
32
|
+
if (this.#disposal !== undefined) {
|
|
46
33
|
throw new Error("Temporary resource store is closed");
|
|
47
34
|
}
|
|
48
35
|
|
|
36
|
+
const saving = this.#save(text);
|
|
37
|
+
this.#pendingSaves.add(saving);
|
|
38
|
+
try {
|
|
39
|
+
return await saving;
|
|
40
|
+
} finally {
|
|
41
|
+
this.#pendingSaves.delete(saving);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Closes the store, waits for pending saves, and removes its private directory. */
|
|
46
|
+
dispose(): Promise<void> {
|
|
47
|
+
this.#disposal ??= this.#dispose();
|
|
48
|
+
return this.#disposal;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async #save(text: string): Promise<string> {
|
|
49
52
|
const directory = await this.#getDirectory();
|
|
50
53
|
const id = randomUUID();
|
|
51
54
|
const source = `temp:${id}`;
|
|
52
55
|
const filePath = path.join(directory, `${id}.txt`);
|
|
53
56
|
await writeFile(filePath, text, { encoding: "utf8", flag: "wx" });
|
|
54
|
-
this.#entries.set(source,
|
|
55
|
-
this.#scheduleCleanup();
|
|
57
|
+
this.#entries.set(source, filePath);
|
|
56
58
|
return source;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
async dispose(): Promise<void> {
|
|
60
|
-
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.#disposed = true;
|
|
65
|
-
this.#clearTimer();
|
|
61
|
+
async #dispose(): Promise<void> {
|
|
62
|
+
await Promise.allSettled(this.#pendingSaves);
|
|
66
63
|
this.#entries.clear();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (directoryReady !== undefined) {
|
|
70
|
-
await rm(await directoryReady, { recursive: true, force: true });
|
|
64
|
+
if (this.#directoryReady !== undefined) {
|
|
65
|
+
await rm(await this.#directoryReady, { recursive: true, force: true });
|
|
71
66
|
}
|
|
72
67
|
}
|
|
73
68
|
|
|
@@ -76,22 +71,10 @@ export class TempResourceStore {
|
|
|
76
71
|
return { kind: "not-handled" };
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (entry === undefined) {
|
|
82
|
-
return {
|
|
83
|
-
kind: "failed",
|
|
84
|
-
error: new Error(`Temporary resource ${source} expired or does not exist`),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (entry.activeReads === 0 && entry.lastUsedAt + this.#ttlMs <= Date.now()) {
|
|
89
|
-
this.#entries.delete(source);
|
|
90
|
-
void unlink(entry.filePath).catch(() => {});
|
|
91
|
-
this.#scheduleCleanup();
|
|
74
|
+
if (this.#disposal !== undefined || !this.#entries.has(source)) {
|
|
92
75
|
return {
|
|
93
76
|
kind: "failed",
|
|
94
|
-
error: new Error(`Temporary resource ${source}
|
|
77
|
+
error: new Error(`Temporary resource ${source} does not exist in this runtime`),
|
|
95
78
|
};
|
|
96
79
|
}
|
|
97
80
|
|
|
@@ -105,22 +88,11 @@ export class TempResourceStore {
|
|
|
105
88
|
}
|
|
106
89
|
|
|
107
90
|
async #read(source: string): Promise<AgentContent> {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
throw new Error(`Temporary resource ${source} expired or does not exist`);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
entry.activeReads += 1;
|
|
115
|
-
this.#scheduleCleanup();
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
return [{ type: "text" as const, text: await readFile(entry.filePath, "utf8") }];
|
|
119
|
-
} finally {
|
|
120
|
-
entry.activeReads -= 1;
|
|
121
|
-
entry.lastUsedAt = Date.now();
|
|
122
|
-
this.#scheduleCleanup();
|
|
91
|
+
const filePath = this.#entries.get(source);
|
|
92
|
+
if (this.#disposal !== undefined || filePath === undefined) {
|
|
93
|
+
throw new Error(`Temporary resource ${source} does not exist in this runtime`);
|
|
123
94
|
}
|
|
95
|
+
return [{ type: "text", text: await readFile(filePath, "utf8") }];
|
|
124
96
|
}
|
|
125
97
|
|
|
126
98
|
async #getDirectory(): Promise<string> {
|
|
@@ -130,67 +102,4 @@ export class TempResourceStore {
|
|
|
130
102
|
})();
|
|
131
103
|
return this.#directoryReady;
|
|
132
104
|
}
|
|
133
|
-
|
|
134
|
-
#scheduleCleanup(): void {
|
|
135
|
-
this.#clearTimer();
|
|
136
|
-
|
|
137
|
-
if (this.#disposed) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const now = Date.now();
|
|
142
|
-
let nextDeadline: number | undefined;
|
|
143
|
-
|
|
144
|
-
for (const entry of this.#entries.values()) {
|
|
145
|
-
if (entry.activeReads > 0) {
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const deadline = entry.lastUsedAt + this.#ttlMs;
|
|
150
|
-
nextDeadline = nextDeadline === undefined ? deadline : Math.min(nextDeadline, deadline);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (nextDeadline === undefined) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.#timer = setTimeout(
|
|
158
|
-
() => {
|
|
159
|
-
this.#timer = undefined;
|
|
160
|
-
void this.#removeExpired().catch(() => {
|
|
161
|
-
this.#scheduleCleanup();
|
|
162
|
-
});
|
|
163
|
-
},
|
|
164
|
-
Math.max(0, nextDeadline - now),
|
|
165
|
-
);
|
|
166
|
-
this.#timer.unref();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async #removeExpired(): Promise<void> {
|
|
170
|
-
const now = Date.now();
|
|
171
|
-
const expired = [...this.#entries].filter(
|
|
172
|
-
([, entry]) => entry.activeReads === 0 && entry.lastUsedAt + this.#ttlMs <= now,
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
await Promise.all(
|
|
176
|
-
expired.map(async ([source, entry]) => {
|
|
177
|
-
await unlink(entry.filePath).catch((error: unknown) => {
|
|
178
|
-
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
this.#entries.delete(source);
|
|
183
|
-
}),
|
|
184
|
-
);
|
|
185
|
-
this.#scheduleCleanup();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
#clearTimer(): void {
|
|
189
|
-
if (this.#timer === undefined) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
clearTimeout(this.#timer);
|
|
194
|
-
this.#timer = undefined;
|
|
195
|
-
}
|
|
196
105
|
}
|