pi-agent-ide 0.7.1 → 0.7.3
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 +66 -0
- package/README.md +3 -1
- package/dist/{chunk-PKKDDIWW.js → chunk-2ZMMRINH.js} +1 -1
- package/dist/chunk-6U5OU77O.js +3 -0
- package/dist/chunk-BYZSBXUK.js +2 -0
- package/dist/{chunk-LEEQIQ7D.js → chunk-CEX73RI5.js} +6 -6
- package/dist/chunk-DZWTKF2K.js +1 -0
- package/dist/{chunk-WMO6RNE2.js → chunk-EOKEQ3YH.js} +6 -6
- package/dist/{chunk-HZEY4GT4.js → chunk-H445SHSJ.js} +2 -2
- package/dist/{chunk-4GCWGE2C.js → chunk-HZ5BNF3A.js} +1 -1
- package/dist/chunk-IG56UGSO.js +2 -0
- package/dist/chunk-IICJXZBU.js +6 -0
- package/dist/{chunk-XYS4FSCC.js → chunk-IM24DB3K.js} +1 -1
- package/dist/chunk-MXLSGMRZ.js +3 -0
- package/dist/{chunk-76ZK5ODR.js → chunk-NHKPP2AI.js} +13 -13
- package/dist/chunk-OB46OPMZ.js +1 -0
- package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
- package/dist/chunk-QUYXINGZ.js +7 -0
- package/dist/{chunk-OMVRLWMX.js → chunk-SBP3ABH4.js} +1 -1
- package/dist/{chunk-YP46DVVP.js → chunk-STBJO3Z3.js} +1 -1
- package/dist/{chunk-2TRHFMCZ.js → chunk-TXOTNK6B.js} +1 -1
- package/dist/chunk-WLZIUMJL.js +1 -0
- package/dist/chunk-ZIWPKIBZ.js +1 -0
- package/dist/entry-11.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +1 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-31.js +12 -11
- package/dist/entry-33.js +3 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-42.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +20 -12
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +7 -6
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-77.js +63 -49
- package/dist/entry-78.js +15 -14
- package/dist/entry-79.js +1 -1
- package/dist/entry-82.js +5 -5
- package/dist/entry-83.js +1 -1
- package/dist/entry-84.js +1 -1
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +34 -11
- package/docs/agent-guides/editing.md +14 -7
- package/docs/agent-guides/git-changes.md +10 -0
- package/docs/agent-guides/read-resources.md +9 -46
- package/docs/agent-guides/search-code.md +7 -1
- package/docs/agent-guides/select-code.md +1 -0
- package/docs/agent-guides/terminal.md +9 -1
- package/docs/configuration.md +22 -1
- package/docs/development.md +4 -0
- package/docs/directory-operations.md +45 -0
- package/docs/releases.md +12 -0
- package/docs/research/codemode-write-context.md +56 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/structured-results.md +2 -2
- package/docs/tools.md +10 -2
- package/docs/user-hooks.md +26 -0
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-jq/src/jq.ts +4 -1
- 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 +13 -13
- package/node_modules/pi-agent-ide-ast/src/extension.ts +3 -3
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +0 -3
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +8 -6
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +13 -5
- package/node_modules/pi-agent-ide-changes/package.json +9 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lsp/index.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
- 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 +7 -7
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +3 -3
- package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +1 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +5 -1
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +99 -44
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +1 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +6 -3
- package/node_modules/{pi-agent-read/src/core/tools/read → pi-agent-resource/src}/temp-resource-store.ts +17 -7
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +5 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +2 -2
- package/node_modules/pi-agent-search/src/core/extension.ts +2 -1
- package/node_modules/pi-agent-search/src/core/search-core.ts +13 -4
- package/node_modules/pi-agent-search-text/package.json +7 -7
- package/node_modules/pi-agent-search-text/src/resolvers.ts +11 -1
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +42 -32
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +6 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +17 -3
- package/node_modules/pi-agent-text/package.json +2 -2
- 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-editor/package.json +9 -9
- package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +30 -40
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +24 -4
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +21 -14
- package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
- package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
- package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/src/resolver.ts +11 -13
- package/node_modules/pi-agent-web-html/package.json +2 -2
- package/node_modules/pi-agent-web-image/package.json +3 -3
- package/node_modules/pi-agent-web-pdf/package.json +3 -3
- package/node_modules/pi-agent-web-text/package.json +3 -3
- package/package.json +36 -35
- package/src/api/hooks.ts +24 -0
- package/src/composite/nested-tool-rendering.ts +184 -77
- package/src/composite/output-limits.ts +125 -0
- package/src/composite/responses-tools.ts +25 -0
- package/src/composite/text-results.ts +158 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- 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-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +4 -1
- 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 +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +11 -13
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +3 -3
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +5 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +99 -44
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +11 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +42 -32
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +6 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +17 -3
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +5 -1
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +2 -2
- package/src/extensions/pi-agent-search/src/core/extension.ts +2 -1
- package/src/extensions/pi-agent-search/src/core/search-core.ts +13 -4
- package/src/extensions/pi-agent-text-editor/package.json +9 -9
- 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-editor-renderer/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +30 -40
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +24 -4
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +21 -14
- package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
- package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/src/pi-agent-ide.ts +11 -0
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +3 -3
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +0 -3
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +8 -6
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +13 -5
- package/src/plugins/pi-agent-ide-changes/package.json +9 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/src/plugins/pi-agent-ide-debugger/index.ts +20 -8
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +93 -38
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +3 -2
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lsp/index.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
- package/src/plugins/pi-agent-ide-vision/index.ts +1 -0
- package/src/post-edit/gate.ts +13 -2
- package/dist/chunk-4XMY4H4V.js +0 -1
- package/dist/chunk-64M3SQPG.js +0 -3
- package/dist/chunk-CWD4O5PM.js +0 -3
- package/dist/chunk-D3WTDA6V.js +0 -2
- package/dist/chunk-EAZGN5ND.js +0 -7
- package/dist/chunk-GXEGY7GV.js +0 -1
- package/dist/chunk-MBUXFKIW.js +0 -3
- package/dist/chunk-PGIVHICI.js +0 -1
- package/dist/chunk-VMTR74FF.js +0 -2
- package/dist/chunk-WU6ZK6YD.js +0 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +0 -105
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
2
3
|
import { ResourceScheduler, resourceAccesses } from "pi-agent-resource";
|
|
3
4
|
import type { TextResourceEditOutcome } from "./text-editor-core.js";
|
|
4
5
|
|
|
5
6
|
type Completed = Exclude<TextResourceEditOutcome<unknown>, { readonly kind: "failed" }>;
|
|
6
7
|
type Finalize = () => Promise<Completed>;
|
|
7
|
-
const active = new AsyncLocalStorage<
|
|
8
|
+
const active = new AsyncLocalStorage<{
|
|
9
|
+
readonly pending: Map<string, Finalize>;
|
|
10
|
+
readonly immediate: boolean;
|
|
11
|
+
}>();
|
|
8
12
|
const notifications = new AsyncLocalStorage<Array<() => void>>();
|
|
9
13
|
|
|
10
14
|
/** Schedule observers only after every file in the current finalization has settled. */
|
|
@@ -27,27 +31,32 @@ export async function collectPostEditNotifications<T>(work: () => Promise<T>): P
|
|
|
27
31
|
|
|
28
32
|
/** Replace intermediate post-processing with the latest written state of this resource. */
|
|
29
33
|
export function deferPostEdit(source: string, finalize: Finalize): boolean {
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
32
|
-
|
|
34
|
+
const scope = active.getStore();
|
|
35
|
+
if (!scope) return false;
|
|
36
|
+
if (scope.immediate) {
|
|
37
|
+
scope.pending.delete(source);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
scope.pending.set(source, finalize);
|
|
33
41
|
return true;
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
/** Optional read enrichment must not start checks on an intermediate edited snapshot. */
|
|
37
45
|
export function hasDeferredPostEdit(source: string): boolean {
|
|
38
|
-
return active.getStore()?.has(source) ?? false;
|
|
46
|
+
return active.getStore()?.pending.has(source) ?? false;
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
/** Stop deferred processing when a later operation removes or moves the resource. */
|
|
42
50
|
export function forgetDeferredPostEdit(source: string): void {
|
|
43
|
-
active.getStore()?.delete(source);
|
|
51
|
+
active.getStore()?.pending.delete(source);
|
|
44
52
|
}
|
|
45
53
|
/** Writes stay immediate; finishing drains each surviving final resource once. */
|
|
46
54
|
export function createPostEditScope(cwd = process.cwd()) {
|
|
47
55
|
const pending = new Map<string, Finalize>();
|
|
48
56
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
/** Immediate processing replaces older deferred work for the same written resource. */
|
|
58
|
+
run<T>(operation: () => T, immediate = false): T {
|
|
59
|
+
return active.run({ pending, immediate }, operation);
|
|
51
60
|
},
|
|
52
61
|
forget(source: string): void {
|
|
53
62
|
pending.delete(source);
|
|
@@ -56,7 +65,11 @@ export function createPostEditScope(cwd = process.cwd()) {
|
|
|
56
65
|
sources(): readonly string[] {
|
|
57
66
|
return [...pending.keys()];
|
|
58
67
|
},
|
|
59
|
-
|
|
68
|
+
/** Report each final resource outcome; a failed finalization does not undo its write. */
|
|
69
|
+
async finish(
|
|
70
|
+
onCompleted?: (outcome: Completed) => void,
|
|
71
|
+
onFailed?: (source: string, error: unknown) => void,
|
|
72
|
+
): Promise<Completed[]> {
|
|
60
73
|
const work = [...pending];
|
|
61
74
|
pending.clear();
|
|
62
75
|
const completed: Completed[] = [];
|
|
@@ -68,9 +81,15 @@ export function createPostEditScope(cwd = process.cwd()) {
|
|
|
68
81
|
scheduler.run(resourceAccesses(source, cwd, "write"), finalize),
|
|
69
82
|
),
|
|
70
83
|
);
|
|
71
|
-
for (const outcome of outcomes) {
|
|
84
|
+
for (const [index, outcome] of outcomes.entries()) {
|
|
85
|
+
const source = requiredValue(work[index])[0];
|
|
72
86
|
if (outcome.status === "rejected") {
|
|
73
87
|
errors.push(outcome.reason);
|
|
88
|
+
try {
|
|
89
|
+
onFailed?.(source, outcome.reason);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
errors.push(error);
|
|
92
|
+
}
|
|
74
93
|
continue;
|
|
75
94
|
}
|
|
76
95
|
completed.push(outcome.value);
|
|
@@ -78,6 +97,11 @@ export function createPostEditScope(cwd = process.cwd()) {
|
|
|
78
97
|
onCompleted?.(outcome.value);
|
|
79
98
|
} catch (error) {
|
|
80
99
|
errors.push(error);
|
|
100
|
+
try {
|
|
101
|
+
onFailed?.(source, error);
|
|
102
|
+
} catch (failure) {
|
|
103
|
+
errors.push(failure);
|
|
104
|
+
}
|
|
81
105
|
}
|
|
82
106
|
}
|
|
83
107
|
});
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import type { ResolvedResultTargets } from "pi-agent-resource";
|
|
2
2
|
import { TextChangeDocument } from "./text-change-engine.js";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const writePartialReason =
|
|
5
|
+
"Write received a partial file selection. Use replace to edit that selection, or Read the whole file before deliberately replacing all its contents.";
|
|
6
|
+
|
|
7
|
+
/** Require one complete file; name Write to provide its specific recovery instructions. */
|
|
8
|
+
export function wholeFileResultSource(
|
|
9
|
+
result: ResolvedResultTargets,
|
|
10
|
+
operation?: "write" | "undo",
|
|
11
|
+
): string {
|
|
6
12
|
const target = result.targets[0];
|
|
7
13
|
const range = target?.ranges[0];
|
|
8
|
-
if (result.targets.length !== 1 || target?.ranges.length !== 1 || range === undefined)
|
|
14
|
+
if (result.targets.length !== 1 || target?.ranges.length !== 1 || range === undefined) {
|
|
15
|
+
if (operation === "write") {
|
|
16
|
+
if (result.targets.length === 0)
|
|
17
|
+
throw new Error(
|
|
18
|
+
"Write received no file selection. Read the intended whole file before replacing it.",
|
|
19
|
+
);
|
|
20
|
+
if (result.targets.length > 1)
|
|
21
|
+
throw new Error(
|
|
22
|
+
"Write received multiple files. Choose one file and Read its whole contents before replacing it.",
|
|
23
|
+
);
|
|
24
|
+
throw new Error(writePartialReason);
|
|
25
|
+
}
|
|
9
26
|
throw new Error("This operation requires one whole-file result target.");
|
|
27
|
+
}
|
|
10
28
|
const document = new TextChangeDocument(target.expectedContent);
|
|
11
29
|
const selected = document.range(
|
|
12
30
|
range.start.lineNumber,
|
|
@@ -16,7 +34,9 @@ export function wholeFileResultSource(result: ResolvedResultTargets): string {
|
|
|
16
34
|
);
|
|
17
35
|
if (selected.from !== 0 || selected.to !== document.length)
|
|
18
36
|
throw new Error(
|
|
19
|
-
|
|
37
|
+
operation === "write"
|
|
38
|
+
? writePartialReason
|
|
39
|
+
: "This operation requires one whole-file result target; partial scopes are not widened.",
|
|
20
40
|
);
|
|
21
41
|
return target.source;
|
|
22
42
|
}
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
TextMutationContext,
|
|
5
5
|
TextMutationEdit,
|
|
6
6
|
} from "#src/api/mutation-tool.js";
|
|
7
|
-
import type
|
|
7
|
+
import { TextChangeDocument, type TextChange } from "./text-change-engine.js";
|
|
8
8
|
import {
|
|
9
9
|
anchorSpanRange,
|
|
10
10
|
insertionAfterAnchor,
|
|
@@ -26,6 +26,8 @@ interface TransferSpan {
|
|
|
26
26
|
interface PreparedTransfer {
|
|
27
27
|
readonly input: Readonly<Record<string, unknown>>;
|
|
28
28
|
readonly empty: boolean;
|
|
29
|
+
/** Verified unchanged destination points; no editor operation is needed. */
|
|
30
|
+
readonly noOpTarget?: string;
|
|
29
31
|
readonly verifyFileSource?: () => Promise<void>;
|
|
30
32
|
readonly mutate?: (context: TextMutationContext) => Promise<TextMutation>;
|
|
31
33
|
}
|
|
@@ -46,7 +48,7 @@ export async function prepareResultTransfer(
|
|
|
46
48
|
const selected = store.resolveOrdered(input[field], cwd);
|
|
47
49
|
if (!selected.complete)
|
|
48
50
|
throw new Error(
|
|
49
|
-
"Incomplete result targets cannot establish a complete transfer
|
|
51
|
+
"Incomplete result targets cannot establish a complete transfer. Run Search again with a higher limit or a narrower query, then use the complete result.",
|
|
50
52
|
);
|
|
51
53
|
await store.verify(selected, signal);
|
|
52
54
|
input[field] = store.register(selected.targets, cwd);
|
|
@@ -74,6 +76,28 @@ export async function prepareResultTransfer(
|
|
|
74
76
|
"Transfer source and destination selection counts must match; no broadcast or concatenation.",
|
|
75
77
|
);
|
|
76
78
|
const empty = source?.targets.length === 0 || destination?.targets.length === 0;
|
|
79
|
+
if (operation === "move" && !empty && source !== undefined && destination !== undefined) {
|
|
80
|
+
const spans = (selected: ResolvedResultTargets): TransferSpan[] =>
|
|
81
|
+
selected.targets.map((target) => {
|
|
82
|
+
const range = target.ranges[0];
|
|
83
|
+
if (range === undefined) throw new Error("Transfer selection has no range.");
|
|
84
|
+
return {
|
|
85
|
+
source: target.source,
|
|
86
|
+
...new TextChangeDocument(target.expectedContent).range(
|
|
87
|
+
range.start.lineNumber,
|
|
88
|
+
range.start.column,
|
|
89
|
+
range.end.lineNumber,
|
|
90
|
+
range.end.column,
|
|
91
|
+
),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
const sources = spans(source);
|
|
95
|
+
const destinations = spans(destination);
|
|
96
|
+
if ([...sources, ...destinations].every((span) => span.from === span.to)) {
|
|
97
|
+
assertMoveTargets(sources, destinations);
|
|
98
|
+
return { input, empty: false, noOpTarget: store.register(destination.targets, cwd) };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
77
101
|
return {
|
|
78
102
|
input,
|
|
79
103
|
empty,
|
|
@@ -157,19 +181,30 @@ export async function prepareResultTransfer(
|
|
|
157
181
|
}
|
|
158
182
|
}
|
|
159
183
|
if (operation === "move") {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
sourceSpan.from <= transfer.target.to &&
|
|
165
|
-
transfer.target.from <= sourceSpan.to
|
|
166
|
-
)
|
|
167
|
-
throw new Error("Move target must not overlap or touch any source range.");
|
|
184
|
+
assertMoveTargets(
|
|
185
|
+
sources,
|
|
186
|
+
planned.map((transfer) => transfer.target),
|
|
187
|
+
);
|
|
168
188
|
for (const span of sources)
|
|
169
189
|
append(span, { from: span.from, to: span.to, insert: "" }, false);
|
|
170
190
|
}
|
|
171
|
-
for (const transfer of planned)
|
|
191
|
+
for (const transfer of planned)
|
|
192
|
+
append(
|
|
193
|
+
transfer.target,
|
|
194
|
+
operation === "copy" ? { ...transfer.change, allowUnchanged: true } : transfer.change,
|
|
195
|
+
true,
|
|
196
|
+
);
|
|
172
197
|
return { edits };
|
|
173
198
|
},
|
|
174
199
|
};
|
|
175
200
|
}
|
|
201
|
+
|
|
202
|
+
function assertMoveTargets(
|
|
203
|
+
sources: readonly TransferSpan[],
|
|
204
|
+
destinations: readonly TransferSpan[],
|
|
205
|
+
): void {
|
|
206
|
+
for (const source of sources)
|
|
207
|
+
for (const target of destinations)
|
|
208
|
+
if (source.source === target.source && source.from <= target.to && target.from <= source.to)
|
|
209
|
+
throw new Error("Move target must not overlap or touch any source range.");
|
|
210
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
2
|
import {
|
|
3
3
|
resultError,
|
|
4
|
-
resultErrorSchema,
|
|
5
4
|
structuredResultSchema,
|
|
6
5
|
withStructuredResult,
|
|
7
6
|
type StructuredResult,
|
|
@@ -36,7 +35,7 @@ export function mutationDataSchema(operation: string) {
|
|
|
36
35
|
operation: Type.Literal(operation),
|
|
37
36
|
...receipt,
|
|
38
37
|
operationId: Type.Optional(Type.String()),
|
|
39
|
-
...(operation === "delete"
|
|
38
|
+
...(operation === "delete"
|
|
40
39
|
? {}
|
|
41
40
|
: {
|
|
42
41
|
target: Type.Optional(Type.String()),
|
|
@@ -50,17 +49,18 @@ export function mutationDataSchema(operation: string) {
|
|
|
50
49
|
export function mutationResultSchema(operation: string) {
|
|
51
50
|
return structuredResultSchema(mutationDataSchema(operation));
|
|
52
51
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
/** Observed file and operation effects retained on the parent native script. */
|
|
53
|
+
export interface BatchMutationData {
|
|
54
|
+
operation: "batch";
|
|
55
|
+
effect: MutationData["effect"];
|
|
56
|
+
files: MutationData["files"];
|
|
57
|
+
operations: {
|
|
58
|
+
id: string;
|
|
59
|
+
operation: string;
|
|
60
|
+
effect: MutationData["effect"];
|
|
61
|
+
errors: ResultError[];
|
|
62
|
+
}[];
|
|
63
|
+
}
|
|
64
64
|
/** Small internal receipt used to collect observed file effects. */
|
|
65
65
|
export interface MutationData {
|
|
66
66
|
operation: string;
|
|
@@ -110,6 +110,8 @@ export function mutationOutcome(
|
|
|
110
110
|
...new Set([
|
|
111
111
|
...(data.files ?? []).map((file) => file.path),
|
|
112
112
|
...(data.path ? [data.path] : []),
|
|
113
|
+
...(data.rollback?.failedSources ?? []),
|
|
114
|
+
...(data.rollback?.restoredSources ?? []),
|
|
113
115
|
]),
|
|
114
116
|
];
|
|
115
117
|
for (const source of sources)
|
|
@@ -120,7 +122,11 @@ export function mutationOutcome(
|
|
|
120
122
|
observed.has(source) ||
|
|
121
123
|
(data.ok === true && data.files?.some((file) => file.path === source))
|
|
122
124
|
? "applied"
|
|
123
|
-
: (
|
|
125
|
+
: data.rollback?.failedSources.includes(source)
|
|
126
|
+
? "unknown"
|
|
127
|
+
: data.rollback?.restoredSources.includes(source)
|
|
128
|
+
? "not-applied"
|
|
129
|
+
: (details.effect ?? "unknown"),
|
|
124
130
|
});
|
|
125
131
|
for (const error of data.errors ?? [])
|
|
126
132
|
errors.push({
|
|
@@ -206,6 +212,7 @@ export function mutationOutcome(
|
|
|
206
212
|
)
|
|
207
213
|
errors.push({ code: "UNKNOWN_RESULT", message: "Mutation effects were not reported" });
|
|
208
214
|
const effect =
|
|
215
|
+
details.effect === "unknown" ||
|
|
209
216
|
unique.some((file) => file.effect === "unknown") ||
|
|
210
217
|
errors.some((error) => error.code === "UNKNOWN_RESULT")
|
|
211
218
|
? "unknown"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
interface TemporaryDirectorySettings {
|
|
6
|
+
readonly mode: "replace" | "extend";
|
|
7
|
+
readonly paths: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Load temporary roots for Delete: defaults, then global, then project settings. */
|
|
11
|
+
export async function loadTemporaryDirectories(projectRoot: string): Promise<readonly string[]> {
|
|
12
|
+
const home = await realpath(os.homedir());
|
|
13
|
+
const agent = process.env.PI_CODING_AGENT_DIR?.trim();
|
|
14
|
+
const names = ["tmp", ".tmp", "temp", ".temp"];
|
|
15
|
+
const system = await existingRoot(os.tmpdir());
|
|
16
|
+
// Named defaults do not grant permission to a symlink's destination outside the root.
|
|
17
|
+
let roots = [
|
|
18
|
+
...names.map((name) => path.join(projectRoot, name)),
|
|
19
|
+
...names.map((name) => path.join(home, name)),
|
|
20
|
+
...(system === undefined ? [] : [system]),
|
|
21
|
+
];
|
|
22
|
+
const layers = [
|
|
23
|
+
{
|
|
24
|
+
file: path.join(
|
|
25
|
+
agent ? path.resolve(agent) : path.join(home, ".pi", "agent"),
|
|
26
|
+
"pi-agent-ide",
|
|
27
|
+
"deletion.json",
|
|
28
|
+
),
|
|
29
|
+
base: home,
|
|
30
|
+
},
|
|
31
|
+
{ file: path.join(projectRoot, ".pi", "pi-agent-ide", "deletion.json"), base: projectRoot },
|
|
32
|
+
];
|
|
33
|
+
for (const { file, base } of layers) {
|
|
34
|
+
const settings = await readSettings(file);
|
|
35
|
+
if (settings === undefined) continue;
|
|
36
|
+
const configured: string[] = [];
|
|
37
|
+
for (const entry of settings.paths) {
|
|
38
|
+
const expanded =
|
|
39
|
+
entry === "~"
|
|
40
|
+
? home
|
|
41
|
+
: entry.startsWith("~/")
|
|
42
|
+
? path.join(home, entry.slice(2))
|
|
43
|
+
: path.resolve(base, entry);
|
|
44
|
+
const root = await existingRoot(expanded);
|
|
45
|
+
if (root !== undefined) configured.push(root);
|
|
46
|
+
}
|
|
47
|
+
roots = settings.mode === "replace" ? configured : [...roots, ...configured];
|
|
48
|
+
}
|
|
49
|
+
return [...new Set(roots)].sort();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function readSettings(file: string): Promise<TemporaryDirectorySettings | undefined> {
|
|
53
|
+
let source: string;
|
|
54
|
+
try {
|
|
55
|
+
source = await readFile(file, "utf8");
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (isMissing(error)) return undefined;
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
let value: unknown;
|
|
61
|
+
try {
|
|
62
|
+
value = JSON.parse(source);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new Error(`Invalid JSON in deletion config at ${file}`, { cause: error });
|
|
65
|
+
}
|
|
66
|
+
if (!isRecord(value) || Object.keys(value).some((key) => key !== "temporaryDirectories"))
|
|
67
|
+
throw new Error(`Invalid deletion config at ${file}: expected temporaryDirectories settings`);
|
|
68
|
+
if (value.temporaryDirectories === undefined) return undefined;
|
|
69
|
+
const settings = value.temporaryDirectories;
|
|
70
|
+
if (
|
|
71
|
+
!isRecord(settings) ||
|
|
72
|
+
Object.keys(settings).some((key) => key !== "mode" && key !== "paths") ||
|
|
73
|
+
(settings.mode !== "replace" && settings.mode !== "extend") ||
|
|
74
|
+
!Array.isArray(settings.paths) ||
|
|
75
|
+
settings.paths.some((entry) => typeof entry !== "string" || entry.trim().length === 0)
|
|
76
|
+
)
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Invalid temporaryDirectories at ${file}: use mode replace or extend and a paths array of non-empty strings`,
|
|
79
|
+
);
|
|
80
|
+
return { mode: settings.mode, paths: settings.paths as string[] };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function existingRoot(directory: string): Promise<string | undefined> {
|
|
84
|
+
try {
|
|
85
|
+
return await realpath(directory);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (isMissing(error)) return undefined;
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
92
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
93
|
+
}
|
|
94
|
+
function isMissing(error: unknown): boolean {
|
|
95
|
+
return error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
96
|
+
}
|
|
@@ -8,6 +8,8 @@ export interface TextRange {
|
|
|
8
8
|
|
|
9
9
|
export interface TextChange extends TextRange {
|
|
10
10
|
readonly insert: string;
|
|
11
|
+
/** Copy may retain a destination range even when its text is already identical. */
|
|
12
|
+
readonly allowUnchanged?: true;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export interface AppliedTextChange {
|
|
@@ -220,7 +222,9 @@ export function applyTextChanges(
|
|
|
220
222
|
validateChanges(source.length, ordered);
|
|
221
223
|
if (
|
|
222
224
|
!(creating && source.length === 0) &&
|
|
223
|
-
ordered.some(
|
|
225
|
+
ordered.some(
|
|
226
|
+
(change) => !change.allowUnchanged && source.slice(change.from, change.to) === change.insert,
|
|
227
|
+
)
|
|
224
228
|
) {
|
|
225
229
|
throw new Error("Text changes must change the document.");
|
|
226
230
|
}
|