pi-agent-ide 0.4.0 → 0.5.1
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 +41 -0
- package/README.md +74 -22
- package/assets/gallery/apply-editing.png +0 -0
- package/assets/gallery/debugging.png +0 -0
- package/assets/gallery/read-web.png +0 -0
- package/assets/gallery/search-replace.png +0 -0
- package/assets/gallery/terminal.png +0 -0
- package/assets/gallery/tool-editing.png +0 -0
- package/dist/chunk-25CZ5ZIU.js +3 -0
- package/dist/chunk-526E364R.js +3 -0
- package/dist/chunk-5PLV4HLG.js +1 -0
- package/dist/chunk-5QQABP47.js +14 -0
- package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
- package/dist/chunk-7ALCBKCW.js +26 -0
- package/dist/chunk-AWXVJ5AC.js +1 -0
- package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
- package/dist/chunk-ESPNEJHK.js +1 -0
- package/dist/chunk-G725MARR.js +16 -0
- package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
- package/dist/chunk-IQD6PON5.js +0 -0
- package/dist/chunk-IRECDTJG.js +27 -0
- package/dist/chunk-J4RTW44E.js +1 -0
- package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
- package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
- package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
- package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
- package/dist/chunk-NZYDMBM6.js +1 -0
- package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
- package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
- package/dist/chunk-P7XO5CIP.js +2 -0
- package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
- package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
- package/dist/chunk-U2JKHKLK.js +0 -0
- package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.js} +1 -1
- package/dist/entry-10.js +1 -1
- package/dist/entry-11.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-15.js +1 -0
- package/dist/entry-17.js +1 -1
- package/dist/entry-18.js +1 -1
- package/dist/entry-19.js +1 -1
- package/dist/entry-20.js +1 -1
- package/dist/entry-21.js +1 -2
- package/dist/entry-22.js +2 -1
- package/dist/entry-23.js +1 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -12
- package/dist/entry-27.js +12 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +1 -4
- package/dist/entry-32.js +3 -8
- package/dist/entry-33.js +9 -1
- package/dist/entry-34.js +1 -1
- package/dist/entry-35.js +1 -1
- 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-40.js +1 -18
- package/dist/entry-41.js +18 -1
- 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 +1 -7
- package/dist/entry-46.js +7 -11
- package/dist/entry-47.js +11 -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 -1
- package/dist/entry-55.js +1 -0
- package/dist/entry-56.js +0 -1
- package/dist/entry-57.js +1 -0
- package/dist/entry-58.js +0 -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 -1
- package/dist/entry-64.js +1 -0
- package/dist/entry-65.js +0 -1
- package/dist/entry-66.js +1 -0
- package/dist/entry-67.js +0 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -123
- package/dist/entry-71.js +198 -25
- package/dist/entry-72.js +30 -2
- package/dist/entry-73.js +2 -1
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +3 -3
- package/dist/entry-77.js +3 -1
- package/dist/entry-78.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/entry-8.js +1 -1
- package/dist/entry-80.js +1 -0
- package/dist/entry-9.js +1 -1
- package/dist/pi-agent-ide.js +3 -3
- package/docs/configuration.md +1 -1
- package/docs/development.md +0 -6
- package/docs/user-hooks.md +68 -0
- package/node_modules/pi-agent-doctor/package.json +6 -6
- package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
- package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -0
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +4 -4
- package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
- package/node_modules/pi-agent-ide-ast/package.json +32 -11
- package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
- package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
- package/node_modules/pi-agent-ide-changes/index.ts +3 -1
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
- package/node_modules/pi-agent-ide-formatter/package.json +9 -4
- package/node_modules/pi-agent-ide-languages/package.json +3 -3
- package/node_modules/pi-agent-ide-lint/package.json +13 -8
- package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
- package/node_modules/pi-agent-ide-lsp/package.json +15 -10
- package/node_modules/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
- package/node_modules/pi-agent-image/package.json +3 -3
- package/node_modules/pi-agent-invariant/package.json +2 -2
- package/node_modules/pi-agent-pdf/package.json +3 -3
- package/node_modules/pi-agent-read/package.json +11 -11
- package/node_modules/pi-agent-read/runtime/entry-40.js +0 -1
- package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
- package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
- package/node_modules/pi-agent-resource/package.json +2 -2
- package/node_modules/pi-agent-search/package.json +7 -7
- package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
- package/node_modules/pi-agent-search-text/index.ts +1 -1
- package/node_modules/pi-agent-search-text/package.json +9 -9
- package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +72 -39
- package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
- package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
- package/node_modules/pi-agent-search-text/src/search-session.ts +33 -4
- package/node_modules/pi-agent-text/package.json +3 -3
- package/node_modules/pi-agent-text/runtime/entry-49.js +1 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
- package/node_modules/pi-agent-text-editor/package.json +25 -25
- package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
- 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 +141 -6
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
- package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +1 -0
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/src/resolver.ts +128 -1
- 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/node_modules/pi-agent-web-text/runtime/entry-80.js +2 -0
- package/package.json +59 -39
- package/src/api/hooks.ts +168 -0
- package/src/api/text-editor.ts +2 -0
- package/src/composite/builtin-extensions.ts +7 -0
- package/src/composite/module-labels.ts +8 -0
- package/src/composite/preferences.ts +3 -3
- package/src/core/reload-resource-store.ts +34 -0
- package/src/doctor/tip-provider.ts +1 -0
- 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 +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +2 -0
- 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-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/plugins/pi-agent-web-text/runtime/entry-80.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +128 -1
- package/src/extensions/pi-agent-read/package.json +11 -11
- package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
- package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
- package/src/extensions/pi-agent-search/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +72 -39
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +33 -4
- package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
- package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
- package/src/extensions/pi-agent-text-editor/package.json +25 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -0
- 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/renderer.ts +59 -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/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
- 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 +141 -6
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
- package/src/plugins/pi-agent-ide-ast/package.json +32 -11
- package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
- package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
- package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
- package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
- package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
- package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
- package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
- package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
- package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
- package/src/plugins/pi-agent-ide-languages/package.json +3 -3
- package/src/plugins/pi-agent-ide-lint/package.json +13 -8
- package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
- package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
- package/src/plugins/pi-agent-ide-processes/src/registry.ts +83 -0
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +260 -0
- package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
- package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +31 -0
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +32 -2
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +14 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
- package/dist/chunk-3SE372WC.js +0 -3
- package/dist/chunk-5MSNYFDE.js +0 -1
- package/dist/chunk-7JYQMAEL.js +0 -14
- package/dist/chunk-B5KB2I7J.js +0 -3
- package/dist/chunk-NMFQGKPE.js +0 -2
- package/dist/chunk-OVUYPHDE.js +0 -1
- package/dist/chunk-TPIHQYK2.js +0 -14
- package/dist/chunk-XSTHESNR.js +0 -25
- package/dist/entry-16.js +0 -1
- package/docs/evaluation.md +0 -14
- package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
- package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
- package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
- package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
- package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
- package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
- package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
- package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
- package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
- package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
- /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
- /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
- /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
- /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
- /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
- /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
- /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
- /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
- /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
- /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
- /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
- /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
- /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
- /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
- /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
- /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
- /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
- /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
- /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 — 2026-09-13
|
|
4
|
+
|
|
5
|
+
### Debugging
|
|
6
|
+
|
|
7
|
+
- Add agent-native debugger sessions backed by the Debug Adapter Protocol. Agents can launch programs, set and remove breakpoints, continue execution, step through code, inspect stopped source, and terminate sessions through addressable `debug:` resources.
|
|
8
|
+
- Add verified Linux adapters and project checks for JavaScript, TypeScript source maps, shell scripts, C, C++, Rust, Swift, Zig, Java, Kotlin, C#, Python, Go, Dart, PHP, Ruby, Lua, PowerShell, R, Julia, and Elixir.
|
|
9
|
+
- Bring terminal and debugger activity into one `/agent-ide-processes` panel with live state, elapsed time, source context, and session controls.
|
|
10
|
+
- Keep active debugger sessions attached across extension reloads, preserving their `debug:` resources and stopped state.
|
|
11
|
+
|
|
12
|
+
### Transactional Apply
|
|
13
|
+
|
|
14
|
+
- Replace full-file rewrites inside `apply` with a snapshot-guarded editor API. Scripts open immutable file snapshots, stage exact text and whole-file changes, and commit them together with an explicit `apply()` call.
|
|
15
|
+
- Validate every staged operation before writing. If a multi-file commit fails after writing starts, Apply attempts to restore the original files and reports whether rollback completed.
|
|
16
|
+
- Return a session-scoped `APPLY#` receipt to the agent after a successful commit. `undo` can use it once to restore every touched path together, refuses stale receipts before changing files, and reports any restore or compensating-rollback failure.
|
|
17
|
+
- Keep the undo receipt out of the user-facing Apply result. Undo itself uses a compact success or failure status with the number of restored files.
|
|
18
|
+
- Compact long Apply source previews to a useful head and tail, and render explicit `result()` values as first-class result blocks.
|
|
19
|
+
|
|
20
|
+
### Terminal reliability
|
|
21
|
+
|
|
22
|
+
- Replace the generic `run` tool with `bash` on Unix-like systems and `powershell` on Windows. Commands still run in the user’s configured system shell, whose syntax is included in the agent guidance.
|
|
23
|
+
- Preserve foreground commands when the agent turn times out or is interrupted. They continue as background sessions instead of being terminated, and interactive prompts return control without losing the process.
|
|
24
|
+
- Add configurable foreground wait timeouts and report process timeouts, signals, failures, and successful exits as soon as they happen.
|
|
25
|
+
- Wake an idle agent when a running background session produces no output for two minutes. Repeat the notice every two silent minutes until the session changes or finishes.
|
|
26
|
+
- Bound terminal output in both command results and `shell:` reads. Keep the useful tail in context and save the complete output to a readable log file.
|
|
27
|
+
- Keep process panels live while terminal and debugger sessions change state.
|
|
28
|
+
- Keep live terminal sessions attached across extension reloads with the same `shell:` resource and process.
|
|
29
|
+
|
|
30
|
+
### Reading, search, and language support
|
|
31
|
+
|
|
32
|
+
- Expand AST parsing and structural search across the supported language catalog, including native parsers for Go and other non-TypeScript languages.
|
|
33
|
+
- Apply syntax highlighting before AST scope and anchor annotations, so structural reads keep both code colours and stable line markers.
|
|
34
|
+
- Promote semantic code views in agent guidance: workspace symbols for discovery, file graphs for relationships, and declaration reads for focused implementation work.
|
|
35
|
+
- Compact large text-search results before they consume the agent context while preserving reusable search selections.
|
|
36
|
+
|
|
37
|
+
### File operations and hooks
|
|
38
|
+
|
|
39
|
+
- Unify whole-file and selected-text operations under `copy`, `move`, and `delete`. Supplying only source and target paths performs a whole-file operation; selectors continue to operate on text.
|
|
40
|
+
- Show whole-file copy, move, and delete results as compact success or failure cards without repeating paths already present in the header.
|
|
41
|
+
- Add project and global file hooks for reads and text edits. Extensions can deny reads, reject resolved text edits and file creation before their first write, or attach feedback after a saved text edit.
|
|
42
|
+
- Run before-edit hooks once against the complete set of staged text edits in an Apply commit. Whole-file copy, move, and delete operations remain outside the edit-hook contract.
|
|
43
|
+
|
|
3
44
|
## 0.4.0 — 2026-09-11
|
|
4
45
|
|
|
5
46
|
### Terminal sessions
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<h1 align="center">Pi Agent IDE</h1>
|
|
6
6
|
|
|
7
|
-
<p align="center">
|
|
7
|
+
<p align="center">IDE capabilities for coding agents in <a href="https://pi.dev/">Pi</a>.</p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="https://www.npmjs.com/package/pi-agent-ide"><img src="https://img.shields.io/npm/v/pi-agent-ide" alt="npm version"></a>
|
|
@@ -12,31 +12,81 @@
|
|
|
12
12
|
<a href="https://github.com/alexshpunt/pi-agent-ide/actions/workflows/ci.yml"><img src="https://github.com/alexshpunt/pi-agent-ide/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI status"></a>
|
|
13
13
|
<a href="https://github.com/alexshpunt/pi-agent-ide/actions/workflows/ci.yml"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Falexshpunt%2F0d28d39557e2a9976c4548e7737c102d%2Fraw%2Funit.json" alt="Unit test count"></a>
|
|
14
14
|
<a href="https://github.com/alexshpunt/pi-agent-ide/actions/workflows/ci.yml"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Falexshpunt%2F0d28d39557e2a9976c4548e7737c102d%2Fraw%2Fintegration.json" alt="Integration test count"></a>
|
|
15
|
+
<a href="https://alexshpunt-benchmark-explorer.static.hf.space/?filter.harness=pi-agent-ide"><img src="https://img.shields.io/badge/Explicit%20Edit%20Benchmark-v0.5.1%20%E2%80%A2%20not%20tested-lightgrey?style=flat-square" alt="Explicit Edit Benchmark: pi-agent-ide v0.5.1 is not tested yet"></a>
|
|
15
16
|
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/pi-agent-ide" alt="MIT license"></a>
|
|
16
17
|
</p>
|
|
17
18
|
|
|
18
|
-
##
|
|
19
|
+
## Summary
|
|
19
20
|
|
|
20
|
-
Pi Agent IDE is
|
|
21
|
+
Pi Agent IDE is a set of agent-facing tools built to give a coding agent the same practical capabilities that a programmer expects from an IDE.
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
There are two common views of coding agents. One says that an agent only needs a shell and can build everything else for itself. The other says that useful tooling makes an agent more effective. Both are partly right. Stronger models can often make precise edits and recover with little help. Smaller models are more likely to lose context, choose an unsafe edit, or fail on the mechanics of the task. Pi Agent IDE gives models direct tools without taking the shell away.
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
The project started as another take on hash-based editing. It later brought back edits by exact string occurrence, with every occurrence checked before a change is applied. The result is a hybrid approach rather than one required selection method.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
## Gallery
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
-
|
|
35
|
-
- `/pi-agent-ide-doctor` checks the languages and tools available in the current project.
|
|
29
|
+
| Read and guarded tool editing | Transactional Apply |
|
|
30
|
+
| --------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
|  |  |
|
|
32
|
+
| Web reading | Search and replace |
|
|
33
|
+
|  |  |
|
|
34
|
+
| Background processes | Source-level debugging |
|
|
35
|
+
|  |  |
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
## Core principles
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
### One interface for each intent
|
|
40
|
+
|
|
41
|
+
The agent should express what it wants to do without choosing a different tool for every implementation behind it.
|
|
42
|
+
|
|
43
|
+
`read` is the main interface to the environment. It reads text, source code, raw bytes, web pages, images, PDFs, terminal sessions, debugger sessions, and diagnostics. The same interface can ask for AST structure, language-server information, anchors, or other views. The agent chooses the information it needs while the parsing, conversion, and resource handling stay behind one facade.
|
|
44
|
+
|
|
45
|
+
`search` follows the same rule. It searches files, text, symbols, syntax trees, and supported live resources through one interface.
|
|
46
|
+
|
|
47
|
+
Editing tools state concrete intentions such as `write`, `replace`, `insert`, `delete`, `copy`, and `move`. Simple edits use guarded operations that verify the selected text or resource. Independent edits can be submitted together as a tool-call batch. For conditional or multi-file work, `apply` gives the agent isolated JavaScript over immutable file snapshots and the same guarded editing model, then validates and commits the staged changes as one transaction. This lets models use scripts for complex work without reducing an edit to an unchecked rewrite.
|
|
48
|
+
|
|
49
|
+
### IDE tools
|
|
50
|
+
|
|
51
|
+
The shell remains available, but it behaves like part of an IDE. The agent can start long-running and interactive processes, leave them in the background, reconnect after an extension reload, and receive completion or stale-process notifications. Aborting an agent turn does not kill the process.
|
|
52
|
+
|
|
53
|
+
Debugger sessions are also addressable resources. The agent can set breakpoints, inspect source and variables, step through a program, and reconnect after a reload. Formatting, diagnostics, AST views, language-server views, terminal output, and debugger state work through the same resource model. This support is currently focused on Linux and WSL.
|
|
54
|
+
|
|
55
|
+
### Extensible by protocol
|
|
56
|
+
|
|
57
|
+
The visible tools stay small because their internals are protocols. HTTP reads, filesystem reads, terminal and debugger resources, file formats, AST views, language-server views, converters, search backends, anchors, formatters, and diagnostics can be added or replaced independently.
|
|
58
|
+
|
|
59
|
+
The goal is simple primitives on the outside and composable complexity on the inside. New capabilities should extend an existing intent-shaped interface instead of adding another one-off tool.
|
|
60
|
+
|
|
61
|
+
### Make recovery cheap
|
|
62
|
+
|
|
63
|
+
Agents can edit through exact strings, hash anchors, search results, AST matches, and language-server symbols. If one method fails, the tool explains why, shows the available alternatives, and points the agent to a more precise method. The goal is not to punish a bad selection with stricter guardrails. Smaller models will make mistakes. Recovery should cost as little time and context as possible.
|
|
64
|
+
|
|
65
|
+
The tools are designed to combine. A common flow is `search` followed by `replace`: the agent finds the intended occurrences, then edits all selected matches in one guarded operation. The same model supports structural changes and renames through search, AST, and LSP without requiring a separate workflow for each one.
|
|
66
|
+
|
|
67
|
+
### Observability
|
|
68
|
+
|
|
69
|
+
Powerful agents still need to be observable. A person should be able to see whether the harness is efficient, whether the agent is solving the real task, which tools fit its work, and where weak points or corner cases appear.
|
|
70
|
+
|
|
71
|
+
This is more than presentation. Observable behavior provides the evidence that drives tool design, regression fixes, and benchmark work.
|
|
72
|
+
|
|
73
|
+
### Data-driven development
|
|
74
|
+
|
|
75
|
+
Daily use and judgement still matter, but features should not be built on vibes alone. Changes are measured on real tasks to find where agents fail, which model families work better or worse with the tools, and how Pi Agent IDE compares with other harnesses.
|
|
76
|
+
|
|
77
|
+
The [Explicit Edit Benchmark](https://github.com/alexshpunt/explicit-edit-benchmark) was created for this purpose. It measures how easily agents can use editing tools on exact, deterministic tasks. These tasks are especially useful for smaller models and models with limited reasoning, where tool design has a larger effect on reliability.
|
|
78
|
+
|
|
79
|
+
Agent results are stochastic and no benchmark captures everything. We publish the score we actually get and build broader statistics instead of selecting only favorable runs.
|
|
80
|
+
|
|
81
|
+
Pi Agent IDE is experimental and under active development. Interfaces and behavior may change.
|
|
82
|
+
|
|
83
|
+
## Customization
|
|
84
|
+
|
|
85
|
+
Pi Agent IDE follows Pi's permissive, YOLO-style default: the agent can use the tools without asking for approval at every step. You can make it as strict as your work requires.
|
|
86
|
+
|
|
87
|
+
- [Settings](./docs/configuration.md) control built-in tools, project mappings, search, and presentation.
|
|
88
|
+
- [File hooks](./docs/user-hooks.md) can inspect, change, or deny reads and edits.
|
|
89
|
+
- [Extensions](./docs/extensions.md) can add or replace protocols, resolvers, anchors, search backends, and other behavior.
|
|
40
90
|
|
|
41
91
|
## Installation
|
|
42
92
|
|
|
@@ -50,7 +100,7 @@ Pi packages run with your full system permissions. Review the package before ins
|
|
|
50
100
|
|
|
51
101
|
## Check project tools
|
|
52
102
|
|
|
53
|
-
Pi Agent IDE includes formatter, linter, and
|
|
103
|
+
Pi Agent IDE includes formatter, linter, LSP, and debugger mappings. It finds each tool from the project that owns the file, including project-local binaries and commands on your `PATH`. Settings from one project do not leak into another.
|
|
54
104
|
|
|
55
105
|
Start Pi in your project directory, then run:
|
|
56
106
|
|
|
@@ -66,6 +116,12 @@ Doctor also reports optional system Chrome/Chromium support for browser-rendered
|
|
|
66
116
|
|
|
67
117
|
Run doctor again after installing or changing project tools. For configuration paths, precedence, and command flags, see [Configuration](./docs/configuration.md#doctor).
|
|
68
118
|
|
|
119
|
+
## Feedback and contributions
|
|
120
|
+
|
|
121
|
+
Pi Agent IDE is used actively in real development, but I can only reproduce the models, tools, environments, and workflows available to me. Everyone works differently, and I cannot find or cover every case on my own. I can fix problems when I encounter them or when someone reports them.
|
|
122
|
+
|
|
123
|
+
If something breaks, behaves badly, or does not fit your workflow, please [open an issue](https://github.com/alexshpunt/pi-agent-ide/issues). Bug reports, ideas, and questions are welcome. Pull requests are welcome too. Every contribution will be considered, and I am fully open to making the project much better with help from its users.
|
|
124
|
+
|
|
69
125
|
## Documentation
|
|
70
126
|
|
|
71
127
|
| Document | Contents |
|
|
@@ -73,13 +129,9 @@ Run doctor again after installing or changing project tools. For configuration p
|
|
|
73
129
|
| [Tools and workflow](./docs/tools.md) | Read, search, editing, anchors, and feedback |
|
|
74
130
|
| [Architecture](./docs/architecture.md) | Module boundaries, protocols, and the umbrella extension |
|
|
75
131
|
| [Configuration](./docs/configuration.md) | Run doctor, configure project tools and search, or disable built-ins |
|
|
132
|
+
| [File hooks](./docs/user-hooks.md) | Inspect, change, or deny reads and edits |
|
|
76
133
|
| [Writing extensions](./docs/extensions.md) | Add resolvers, anchors, search backends, and IDE plugins |
|
|
77
134
|
| [Development](./docs/development.md) | Work from a checkout, test, and run modular mode |
|
|
78
|
-
| [Evaluation](./docs/evaluation.md) | Compare Pi Agent IDE with vanilla Pi on repeatable tasks |
|
|
79
|
-
|
|
80
|
-
## Repository
|
|
81
|
-
|
|
82
|
-
Executable behavior is defined by the source and tests. The documents above explain the intended boundaries, extension contracts, and development workflows.
|
|
83
135
|
|
|
84
136
|
## License
|
|
85
137
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{a as S}from"./chunk-5VSE5X5R.js";import{a as d}from"./chunk-EI7MMDWY.js";import{createRequire as j}from"node:module";import{Lang as y,parse as T,registerDynamicLanguage as F}from"@ast-grep/napi";var R=j(new URL("../src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts",import.meta.url).href),B={bash:"@ast-grep/lang-bash",csharp:"@ast-grep/lang-csharp",dart:"@ast-grep/lang-dart",elixir:"@ast-grep/lang-elixir",go:"@ast-grep/lang-go",html:"@ast-grep/lang-html",java:"@ast-grep/lang-java",kotlin:"@ast-grep/lang-kotlin",lua:"@ast-grep/lang-lua",markdown:"@ast-grep/lang-markdown",php:"@ast-grep/lang-php",ruby:"@ast-grep/lang-ruby",scala:"@ast-grep/lang-scala",sql:"@ast-grep/lang-sql",swift:"@ast-grep/lang-swift"},D={".bash":"bash",".cs":"csharp",".css":y.Css,".less":y.Css,".scss":y.Css,".dart":"dart",".ex":"elixir",".exs":"elixir",".go":"go",".htm":"html",".html":"html",".java":"java",".kt":"kotlin",".kts":"kotlin",".lua":"lua",".md":"markdown",".mdx":"markdown",".php":"php",".rb":"ruby",".rake":"ruby",".scala":"scala",".sc":"scala",".sql":"sql",".sh":"bash",".swift":"swift"},N=!1;function O(){if(N)return;let r={};for(let[e,t]of Object.entries(B))r[e]=R(t);F(r),N=!0}d(O,"ensureLanguagesRegistered");function C(r,e){let t=D[r];if(t)return O(),{rootNode:new b(T(t,e).root(),e)}}d(C,"parseNativeDocument");var b=class r{constructor(e,t){this.node=e;this.source=t}static{d(this,"NativeSyntaxNode")}get type(){return String(this.node.kind())}get text(){return this.node.text()}get isNamed(){return this.node.isNamed()}get hasError(){return this.type==="ERROR"||this.node.children().some(e=>new r(e,this.source).hasError)}get startIndex(){return k(this.source,this.node.range().start.index)}get endIndex(){return k(this.source,this.node.range().end.index)}get startPosition(){let{line:e,column:t}=this.node.range().start;return{row:e,column:t}}get endPosition(){let{line:e,column:t}=this.node.range().end;return{row:e,column:t}}get parent(){let e=this.node.parent();return e?new r(e,this.source):null}get namedChildCount(){return this.namedChildren.length}get namedChildren(){return this.node.children().filter(e=>e.isNamed()).map(e=>new r(e,this.source))}childForFieldName(e){let t=this.node.field(e);return t?new r(t,this.source):null}};function k(r,e){return Buffer.from(r).subarray(0,e).toString("utf8").length}d(k,"byteOffsetToStringIndex");import{createHash as q}from"node:crypto";import{createRequire as W}from"node:module";import L from"node:path";import*as p from"web-tree-sitter";var I=W(new URL("../src/plugins/pi-agent-ide-ast/src/ast/manager.ts",import.meta.url).href),M=new Set(["program","module"]),x=new Set(["body","consequence","alternative","handler","finalizer"]),A,P=new Map;function $(r){switch(r){case".ts":case".tsx":case".mts":case".cts":return"tree-sitter-typescript/tree-sitter-typescript.wasm";case".js":case".jsx":case".mjs":case".cjs":return"tree-sitter-javascript/tree-sitter-javascript.wasm";case".py":case".pyi":return"tree-sitter-python/tree-sitter-python.wasm";case".rs":return"tree-sitter-rust/tree-sitter-rust.wasm";case".c":case".cc":case".hh":case".hxx":case".cpp":case".cxx":case".h":case".hpp":return"tree-sitter-cpp/tree-sitter-cpp.wasm";case".json":case".jsonc":return"tree-sitter-json/tree-sitter-json.wasm";case".yaml":case".yml":return"@tree-sitter-grammars/tree-sitter-yaml/tree-sitter-yaml.wasm";case".toml":return"@tree-sitter-grammars/tree-sitter-toml/tree-sitter-toml.wasm";default:return}}d($,"grammarWasmPath");async function G(r){let e=$(r);if(!e)return;A??=p.Parser.init(),await A;let t=P.get(e);if(t===void 0){let i=I.resolve(e);t=p.Language.load(i),P.set(e,t)}let a=await t,o=new p.Parser;return o.setLanguage(a),o}d(G,"ensureParser");async function U(r,e,t){if(t.length===0)return;let a=L.isAbsolute(r)?r:L.resolve(e,r),o=L.extname(a).toLowerCase(),i=t.join(`
|
|
2
|
+
`),u=await G(o);return u?u.parse(i)??void 0:C(o,i)}d(U,"parseDocument");function E(r,e,t){let a=r.slice(Math.max(0,e-1),Math.max(0,t)).join(`
|
|
3
|
+
`);return q("sha1").update(a).digest("hex").slice(0,4).toUpperCase()}d(E,"hashScope");var w=class extends S{static{d(this,"AstScopeTextAnchor")}constructor(e,t,a,o){super(`scope-${e}-${t}${o===void 0?"":`-${o}`}`,a)}};function f(r,e,t,a){return new w(r,e,t,a)}d(f,"createScopeAnchor");var v=class{static{d(this,"AstScopeManager")}async getDocumentScopes(e,t,a){if(a.length===0)return[];let o=await U(e,t,a);if(!o)return[];let i=[];return this.collectCandidates(o.rootNode,i),this.buildEntries(i,a)}collectCandidates(e,t,a=0,o=!1){if(a>100||!e.isNamed)return;let i=e.type;if(!i||M.has(i)){for(let c of e.namedChildren)this.collectCandidates(c,t,a+1);return}for(let c of x){let n=e.childForFieldName(c);if(!n?.isNamed)continue;let s=n.startPosition.row+1,g=n.endPosition.row+1,h=g-s>=3,l=[...x].some(m=>n.childForFieldName(m)!==null);h&&!l&&t.push({startLine:s,endLine:g,kind:`${i}.${c}`,fromBodyField:!0}),this.collectCandidates(n,t,a+1,!0)}if(![...x].some(c=>e.childForFieldName(c)!==null)&&!o){let c=e.startPosition.row+1,n=e.endPosition.row+1;n-c>=3&&e.namedChildren.length>0&&t.push({startLine:c,endLine:n,kind:i,fromBodyField:!1})}for(let c of e.namedChildren)this.collectCandidates(c,t,a+1)}buildEntries(e,t){let a=new Map;for(let n of e){let s=a.get(n.startLine);(!s||n.endLine>s.endLine||n.endLine===s.endLine&&n.fromBodyField&&!s.fromBodyField)&&a.set(n.startLine,n)}let o=[...a.values()].sort((n,s)=>n.startLine-s.startLine||s.endLine-n.endLine),i=[];for(let n of o)i.some(g=>g.startLine<n.startLine&&g.endLine===n.endLine)||i.push(n);let u=new Map;for(let n of i){let s=E(t,n.startLine,n.endLine);u.set(s,(u.get(s)??0)+1)}let c=new Map;return i.map(n=>{let s=E(t,n.startLine,n.endLine),g=u.get(s)??1,h=(c.get(s)??0)+1;c.set(s,h);let l=g>1?h:void 0;return{name:n.kind,kind:n.kind,startLine:n.startLine,endLine:n.endLine,depth:i.filter(m=>m!==n&&m.startLine<=n.startLine&&m.endLine>=n.endLine&&(m.startLine<n.startLine||m.endLine>n.endLine)).length,hash:s,blockHash:s,...l!==void 0&&{occurrence:l},beginAnchor:f("begin",s,n.startLine,l),endScopeAnchor:f("end",s,n.endLine,l),scopeBeginAnchor:f("begin",s,n.startLine,l),scopeEndAnchor:f("end",s,n.endLine,l)}})}};export{D as a,U as b,v as c};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{c as O}from"./chunk-YHUTTZC6.js";import{i as y,o as p,t as S,u as L}from"./chunk-5VSE5X5R.js";import{a as x}from"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function Re(e,n){let{lines:t,truncation:r,...i}=e,o=t?.map(s=>{let l=[s.lineNumber,S(s.content,n),s.lineEnding];return(s.presentation!==void 0||s.metadata!==void 0)&&l.push(s.presentation),s.metadata!==void 0&&l.push(s.metadata),l}),{content:a,...u}=r??{};return{...i,...o===void 0?{}:{storedLines:o},...r===void 0?{}:{truncation:u,truncatedText:S(a??"",n)}}}d(Re,"compactReadDetails");function W(e,n){let t=e;if(t.storedLines===void 0&&t.truncatedText===void 0)return e;let{storedLines:r,truncatedText:i,truncation:o,...a}=t;return{...a,...r===void 0?{}:{lines:r.map(([u,s,l,c,h])=>({lineNumber:u,content:L(s,n),lineEnding:l,...c==null?{}:{presentation:c},...h==null?{}:{metadata:h}}))},...o===void 0?{}:{truncation:{...o,content:L(i??"",n)}}}}d(W,"restoreReadDetails");import f from"node:path";import{homedir as I}from"node:os";import{createReadToolDefinition as J,getReadmePath as Z}from"@earendil-works/pi-coding-agent";import{Text as K}from"@earendil-works/pi-tui";var v=J(process.cwd()),X=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]);function $(e,n=process.cwd()){if(typeof e!="object"||e===null)return;let t=e,r=t.path;if(typeof r!="string"||r.length===0||r.includes("#")||!f.isAbsolute(r)&&/^[a-z][a-z\d+.-]*:/iu.test(r)||t.views!==void 0&&(!Array.isArray(t.views)||t.views.length>0)||t.offset!==void 0&&(typeof t.offset!="number"||!Number.isInteger(t.offset)||t.offset<1)||t.limit!==void 0&&(typeof t.limit!="number"||!Number.isInteger(t.limit)||t.limit<1))return;let i=r.startsWith("~/")?f.join(I(),r.slice(2)):r,o=f.resolve(n,i),a=f.basename(o),u=f.relative(f.dirname(Z()),o),s=!f.isAbsolute(u)&&(u==="README.md"||u.startsWith(`docs${f.sep}`)||u.startsWith(`examples${f.sep}`));if(!(a!=="SKILL.md"&&!X.has(a)&&!s))return{path:r,...t.offset===void 0?{}:{offset:t.offset},...t.limit===void 0?{}:{limit:t.limit}}}d($,"nativeReadArguments");function C(e,n){return{...e,args:n,lastComponent:e.lastComponent instanceof K?e.lastComponent:void 0}}d(C,"nativeReadContext");import{getLanguageFromPath as M,getMarkdownTheme as Y,highlightCode as P,keyHint as Q}from"@earendil-works/pi-coding-agent";import{Container as b,Markdown as _,Text as ee,truncateToWidth as T,visibleWidth as m,wrapTextWithAnsi as j}from"@earendil-works/pi-tui";var q=12;function ne(e,n,t){let r=typeof n=="number"?n:void 0,i=typeof t=="number"?t:void 0;if(r===void 0&&i===void 0)return{pathSuffix:"",qualifiers:[],details:[]};if(e==="inherited source"||e.includes("#")){let s=r??1,l=i===void 0?String(s):`${s}-${s+i-1}`;return{pathSuffix:"",qualifiers:[{text:`relative lines ${l}`}],details:[{label:"relative lines",value:l}]}}if(r!==void 0&&r<0)return{pathSuffix:"",qualifiers:[{text:`tail ${Math.abs(r)}`},...i===void 0?[]:[{text:`limit ${i}`}]],details:[{label:"tail",value:String(Math.abs(r))},...i===void 0?[]:[{label:"limit",value:String(i)}]]};let a=Math.max(1,r??1),u=i===void 0?String(a):`${a}-${a+i-1}`;return{pathSuffix:`:${u}`,qualifiers:[],details:[{label:"lines",value:u}]}}d(ne,"readWindowPresentation");function Pe(e,n,t){let r=$(e,t.cwd);if(r!==void 0)return x(v.renderCall)(r,n,C(t,r));if(typeof e.path=="string"&&e.path.startsWith("shell:"))return new b;let i=typeof e.path=="string"?e.path:"inherited source",o=ne(i,e.offset,e.limit),a=Array.isArray(e.views)?e.views.filter(l=>typeof l=="string"):[],u=[...o.qualifiers,...a.length===0?[]:[{text:`views ${a.join(",")}`}]],s=[...typeof e.path=="string"?[{label:"path",value:e.path}]:[],...o.details,...a.length===0?[]:[{label:"views",value:a.join(",")}]];return O(t.lastComponent,{tool:"read",primary:{text:`${i}${o.pathSuffix}`,color:typeof e.path=="string"?"accent":"muted",underline:typeof e.path=="string",truncate:"start"},qualifiers:u,details:s,expanded:t.expanded},n)}d(Pe,"renderReadCall");function Ne(e){let n=new WeakMap;return(t,r,i,o)=>{let a=e.nativeResources?$(o.args,o.cwd):void 0;if(a!==void 0&&!r.isPartial)return x(v.renderResult)({...t,details:{truncation:D(t.details).truncation}},r,i,C(o,a));if(r.isPartial||o.isError){let h=k(t),G=o.isError?"error":"dim";return new ee(i.fg(G,h),0,0)}let u=D(t.details).diagnosticCheck;if(u?.complete&&u.count===0)return new b;if(!le(t))return o.lastComponent instanceof b?o.lastComponent:new b;let s=n.get(t);s===void 0&&(s=W(D(t.details),k(t)),n.set(t,s));let c=(o.lastComponent instanceof w?o.lastComponent:void 0)??new w({result:t,details:s,options:e,expanded:r.expanded,theme:i});return c.update({result:t,details:s,options:e,expanded:r.expanded,theme:i}),c}}d(Ne,"createReadResultRenderer");var w=class{constructor(n){this.state=n}static{d(this,"ReadResultPanel")}cached;update(n){this.state.result===n.result&&this.state.details===n.details&&this.state.options===n.options&&this.state.expanded===n.expanded&&this.state.theme===n.theme||(this.state=n,this.invalidate())}render(n){if(this.cached?.width===n)return this.cached.lines;if(n<8){let l=[T(V(this.state,n),Math.max(1,n))];return this.cached={width:n,lines:l},l}let t=n-2,r=Math.max(1,t-2),i=te(this.state,r).flatMap(l=>j(l,r)),o=oe(i,this.state.expanded,this.state.theme),a=[ae(this.state,t,this.state.theme)];for(let l of o)for(let c of j(l,r))a.push(z(c,t,this.state.theme));let u=de(this.state.details,this.state.theme);u!==void 0&&a.push(z(u,t,this.state.theme)),a.push(this.state.theme.fg("borderMuted",`\u2570${"\u2500".repeat(t)}\u256F`));let s=a.map(l=>T(l,n));return this.cached={width:n,lines:s},s}invalidate(){this.cached=void 0}};function te(e,n){let t=B(e.details),r=ue(e.result,t,e.details,!e.expanded);if(e.options.kind==="markdown"||ce(e.details,t,e.options.kind)){let s=new _(r,0,0,Y());return A(s.render(n),e.theme)}if(e.options.kind==="code-view"){let s=t===void 0?g(r).map(l=>N(l,e.theme,!1)):F(t)?re(t,!e.expanded,e.theme):ie(t,e.theme);return A(s,e.theme)}let i=t!==void 0&&F(t),o=t===void 0||i?g(r).map(R):t.map(({content:s})=>R(s)),a=E(e.details,t),u=a===void 0?o.map(s=>e.theme.fg("toolOutput",s)):i?H(t,a,!e.expanded,e.theme):P(o.join(`
|
|
2
|
+
`),a);return A(u,e.theme)}d(te,"renderContentRows");function H(e,n,t,r){return e.flatMap(i=>{let o=R(i.content),a=P(o,n)[0]??r.fg("toolOutput",o),u=!1,s=p({source:"",content:i.content,lines:[i]},{compact:t});return g(s).map(l=>{if(!u&&o.length>0){let c=l.indexOf(o);if(c>=0)return u=!0,`${r.fg("toolOutput",l.slice(0,c))}${a}${r.fg("toolOutput",l.slice(c+o.length))}`}return r.fg("toolOutput",l)})})}d(H,"renderHighlightedPresentedLines");function re(e,n,t){return e.flatMap(r=>{let i=y(r);if(i===void 0){let a=p({source:"",content:r.content,lines:[r]},{compact:n});return g(a).map(u=>N(u,t,!1))}let o=M(i.source);if(o===void 0){let a=p({source:"",content:r.content,lines:[r]},{compact:n});return g(a).map(u=>t.fg("toolOutput",u))}return H([r],o,n,t)})}d(re,"renderPresentedCodeViewLines");function ie(e,n){return e.map(t=>{let r=y(t);if(r===void 0)return N(t.content,n);let i=M(r.source),o=R(U(t.content));return i===void 0?n.fg("toolOutput",o):P(o,i)[0]??n.fg("toolOutput",o)})}d(ie,"renderCodeViewLines");function U(e){return e.replace(/(?:[ \t]{2,}<!--[ \t]+scope-(?:begin|end)-[^\s>]+[ \t]+-->)+[ \t]*$/u,"")}d(U,"stripScopeMarkers");function N(e,n,t=!0){let r=R(t?U(e):e);return/^#{2,3}\s/u.test(r)?n.fg("mdHeading",n.bold(r.replace(/^#{2,3}\s+/u,""))):/^(?:Lines|Reason|Recovery):/u.test(r)?n.fg("dim",r):/^[\p{L}][^:]*:$/u.test(r)?n.fg("accent",n.bold(r)):/^\s*[-*]\s/u.test(r)?n.fg("mdListBullet",r):n.fg("toolOutput",r)}d(N,"renderCodeViewLabel");function oe(e,n,t){if(n||e.length<=q)return e;let r=e.slice(0,q-1),i=e.length-r.length;return[...r,`${t.fg("dim",`\u2026 ${String(i)} more ${i===1?"row":"rows"} \xB7 `)}${Q("app.tools.expand","to expand")}`]}d(oe,"compactRows");function ae(e,n,t){let r=d(a=>t.fg("borderMuted",a),"frame"),i=T(` ${V(e,Math.max(1,n-1))} `,Math.max(0,n-1),""),o="\u2500".repeat(Math.max(0,n-m(i)-1));return`${r("\u256D\u2500")}${i}${r(`${o}\u256E`)}`}d(ae,"renderTopBorder");function V(e,n){let t=e.options.label??pe(E(e.details,B(e.details))),r=e.details.source??"read result",i=se(e.details),o=e.theme.fg("accent",e.theme.bold(t)),a=i===void 0?"":e.theme.fg("dim",` \xB7 ${i}`),u=Math.max(1,n-m(o)-m(a)-2),s=me(r,u);return`${o} ${e.theme.fg("muted",s)}${a}`}d(V,"readTitle");function se(e){if(!(e.startLine===void 0||e.endLine===void 0||e.totalLines===void 0||e.totalLines<=0))return`${String(e.startLine)}\u2013${String(e.endLine)} / ${String(e.totalLines)}`}d(se,"sourceRange");function de(e,n){let t=e.truncation;if(t?.firstLineExceedsLimit===!0)return n.fg("warning","First source line is larger than the saved read limit");if(t?.truncated===!0)return n.fg("warning",`Saved result contains ${String(t.outputLines)} of ${String(t.totalLines)} rendered rows`)}d(de,"readStatus");function z(e,n,t){let r=Math.max(0,n-2),i=T(e,r),o=` ${i}${" ".repeat(Math.max(0,r-m(i)))} `,a=t.fg("borderMuted","\u2502");return`${a}${o}${a}`}d(z,"framed");function ue(e,n,t,r){if(n!==void 0)return p({source:t.source??"",content:"",lines:n},{compact:r});let i=k(e);return t.truncation===void 0&&!(t.totalLines!==void 0&&t.endLine!==void 0&&t.endLine<t.totalLines)?i:i.replace(/\n\n\[(?:Showing lines|Output truncated|\d+ more lines in source)[\s\S]*\]$/u,"")}d(ue,"cleanText");function F(e){return e.some(n=>n.presentation!==void 0)}d(F,"hasPresentation");function g(e){let n=e.split(/\r\n|\r|\n/u);return n.at(-1)===""&&/(?:\r\n|\r|\n)$/u.test(e)&&n.pop(),n}d(g,"splitTextRows");function k(e){return e.content.flatMap(n=>n.type==="text"?[n.text]:[]).join(`
|
|
3
|
+
`)}d(k,"textBlocks");function B(e){return e.lines}d(B,"readLines");function D(e){return typeof e=="object"&&e!==null?e:{}}d(D,"readDetails");function le(e){return e.content.some(n=>n.type==="text")}d(le,"hasTextContent");function E(e,n){let r=n?.map(y).find(i=>i!==void 0)?.source??e.source;return r===void 0?void 0:M(fe(r))}d(E,"languageFor");function ce(e,n,t){return t==="source"&&E(e,n)==="markdown"}d(ce,"isMarkdownSource");function fe(e){try{let n=new URL(e);return n.protocol==="file:"?n.pathname:`${n.pathname}${n.search}`}catch{return e.replace(/#[^/\\]*$/u,"").replace(/^[A-Za-z][A-Za-z\d+.-]*:(?=[/\\])/u,"")}}d(fe,"normalizeSourcePath");function R(e){let n="";for(let t of e.replaceAll(" "," ".repeat(4))){let r=x(t.codePointAt(0));n+=r<32||r===127?"\uFFFD":t}return n}d(R,"normalizeText");function pe(e){return e===void 0?"TEXT":{javascript:"JS",json:"JSON",markdown:"MD",python:"PY",rust:"RS",typescript:"TS"}[e]??e.slice(0,4).toUpperCase()}d(pe,"languageLabel");function A(e,n){return e.length===0?[n.fg("dim","Empty content")]:[...e]}d(A,"nonEmptyRows");function me(e,n){return m(e)<=n?e:n<=1?"\u2026":`\u2026${e.slice(-(n-1))}`}d(me,"truncateFromStart");export{Re as a,q as b,Pe as c,Ne as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as s}from"./chunk-EI7MMDWY.js";var i=class{static{s(this,"AgentIdeProcessRegistry")}#t=new Map;#s=new Set;#e=new Map;add(e){return this.#e.get(e.id)?.(),this.#t.set(e.id,e),this.#e.set(e.id,e.onDidChange(()=>this.#i())),this.#i(),()=>{this.#t.get(e.id)===e&&(this.#e.get(e.id)?.(),this.#e.delete(e.id),this.#t.delete(e.id),this.#i())}}list(){return[...this.#t.values()].flatMap(e=>e.list())}onDidChange(e){return this.#s.add(e),()=>this.#s.delete(e)}dispose(){for(let e of this.#e.values())e();this.#e.clear(),this.#t.clear(),this.#s.clear()}#i(){for(let e of this.#s)e()}},n=new WeakMap;function r(t){let e=n.get(t);return e===void 0&&(e=new i,n.set(t,e)),e}s(r,"agentIdeProcessRegistry");export{r as a};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{a as k,b as I,c as A}from"./chunk-25CZ5ZIU.js";import{j as E,k as S}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 K}from"node:fs/promises";import W from"node:path";async function T(e){let n=[],t=await K(e,{withFileTypes:!0});for(let i of t){let o=W.join(e,i.name);i.isDirectory()?n.push(...await T(o)):(i.isFile()||i.isSymbolicLink())&&n.push(o)}return n}s(T,"collectFiles");import{readFile as X}from"node:fs/promises";var v=256*1024;async function w(e){let n=await X(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
|
+
`,`
|
|
3
|
+
`),i=t.endsWith(`
|
|
4
|
+
`)?t.slice(0,-1):t,o=i.length===0?[]:i.split(`
|
|
5
|
+
`);return{content:t,lines:o}}s(w,"readTextFile");var H=new Set([...Object.keys(k),".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".py",".pyi",".rs",".c",".cc",".hh",".hxx",".cpp",".cxx",".h",".hpp",".json",".jsonc",".yaml",".yml",".toml"]),G=new Set([".json",".jsonc",".yaml",".yml",".toml"]),B=new Set(["class_declaration","class_definition","class_specifier","enum_declaration","enum_definition","enum_item","enum_specifier","export_statement","function_declaration","function_definition","function_item","impl_item","interface_declaration","lexical_declaration","namespace_definition","mod_item","public_field_definition","method_definition","method_signature","property_signature","field_declaration","struct_item","struct_specifier","trait_item","type_alias_declaration","type_item","variable_declaration","assignment"]),q=new Set(["module","program","source_file"]),Z=new Set(["import_declaration","import_from_statement","import_statement","use_declaration"]),M=new Set(["arrow_function","function_declaration","function_definition","function_item","function_expression","method_definition"]),z=new Set(["public_field_definition","variable_declarator","assignment"]),C=new Set(["field_identifier","identifier","property_identifier","shorthand_property_identifier_pattern","type_identifier"]);function N(e){return H.has(h.extname(e).toLowerCase())}s(N,"isSupportedOutlinePath");var L={failureLabel:"PEEK_FAILED",emptyReason:"no entries to peek.",recovery:['Call peek with { peers: [{ path: "path/to/file.ts" }, ...] }.']},J={failureLabel:"AST_OUTLINE_FAILED",emptyReason:"no AST outline was produced."};function Ce(e){return S([e],J)}s(Ce,"formatAstOutline");var R=class{constructor(n=Number.POSITIVE_INFINITY){this.maxDepth=n}static{s(this,"AstOutlineManager")}fallbackScopeManager=new A;async readFileOutline(n,t){let i=P(n,t),o=h.relative(t,i)||i;if(!N(i))throw new Error(`AST outline is not supported for ${o}.`);let r=await w(i);return this.readDocumentOutline(i,t,r.lines)}async readDocumentOutline(n,t,i,o){let r=P(n,t),c=h.relative(t,r)||r;if(!N(r))throw new Error(`AST outline is not supported for ${c}.`);let a=await I(r,t,i);if(!a)throw new Error(`No AST parser is available for ${c}.`);if(Number.isFinite(this.maxDepth)&&a.rootNode.hasError)throw new Error(`Cannot build an automatic outline from invalid syntax in ${c}.`);let u=i.join(`
|
|
6
|
+
`);for(let d=this.maxDepth;;d-=1){let l=await this.createSourceViewBlock(a.rootNode,r,c,t,i,u,h.extname(r).toLowerCase(),void 0,void 0,d);if(o===void 0||o(l)||d<=0||!Number.isFinite(d))return l}}async formatFile(n,t){let i=P(n,t),o=h.relative(t,i)||i;if(!N(i)){let r=await w(i);return S([Q(i,o,r.lines)],L)}try{return S([await this.readFileOutline(i,t)],L)}catch(r){let c=r instanceof Error?r.message:String(r);return S([j(o,c)],L)}}async formatSymbol(n,t){let o=(await T(t)).filter(r=>N(r)).sort();for(let r of o){let c;try{c=await w(r)}catch{continue}let a;try{a=await I(r,t,c.lines)}catch{continue}if(!a)continue;let u=ne(a.rootNode,n);if(!u)continue;let d=h.relative(t,r)||r,l=await this.createSourceViewBlock(u,r,d,t,c.lines,c.content,h.extname(r).toLowerCase(),n,[`defined in: ${d}:${u.startPosition.row+1}`]);return S([l],L)}return S([j("",`symbol not found: ${n}`,"PEEK_NOT_FOUND")],L)}async createSourceViewBlock(n,t,i,o,r,c,a,u,d,l=this.maxDepth){let f=oe(n,c,a,l),m=await ee(this.fallbackScopeManager,t,o,r),x=te(m),g=f.map(y=>{let p=y.sourceLine,_=p===void 0?void 0:r[p-1]??"",O=(p===void 0?void 0:x.get(p))?.map(Y=>` <!-- ${Y} -->`).join("")??"";return E({content:y.content,...!(p===void 0||_===void 0)&&{sourceLine:{source:t,lineNumber:p,content:_}},...O.length>0&&{suffix:O}})});return{path:i,...u!==void 0&&{heading:u},...d!==void 0&&{details:d},startLine:n.startPosition.row+1,endLine:n.endPosition.row+1,totalLines:r.length,renderedLines:g}}};function Q(e,n,t){return{path:n,startLine:t.length>0?1:0,endLine:t.length,totalLines:t.length,renderedLines:t.map((i,o)=>E({content:i,sourceLine:{source:e,lineNumber:o+1,content:i}}))}}s(Q,"formatUnsupportedSourceBlock");function j(e,n,t="PEEK_FAILED"){return{path:e,startLine:0,endLine:0,totalLines:0,renderedLines:[],status:"failed",error:n,code:t}}s(j,"failedSourceViewBlock");function ee(e,n,t,i){return e.getDocumentScopes(n,t,i)}s(ee,"getOutlineScopes");function te(e){let n=new Map;for(let t of e){let i=n.get(t.startLine)??[];i.push(t.beginAnchor.value),n.set(t.startLine,i);let o=n.get(t.endLine)??[];o.push(t.endScopeAnchor.value),n.set(t.endLine,o)}return n}s(te,"buildScopeMarkers");function P(e,n){return e.startsWith("file://")?decodeURIComponent(e.slice(7)):h.isAbsolute(e)?e:h.resolve(n,e)}s(P,"resolvePath");function ne(e,n){let t,i=s(o=>{if(!t){if(B.has(o.type)&&re(o)===n){t=ie(o);return}for(let r of o.namedChildren)i(r)}},"visit");return i(e),t}s(ne,"findSymbol");function re(e){let n=e.childForFieldName("name");if(n&&C.has(n.type))return n.text;for(let t of e.namedChildren)if(C.has(t.type))return t.text;if(e.type==="lexical_declaration"||e.type==="variable_declaration")return e.namedChildren.find(o=>o.type==="variable_declarator")?.childForFieldName("name")?.text;if(e.type==="function_definition"){let t=e.childForFieldName("declarator");return t?V(t):void 0}}s(re,"getNodeName");function V(e){if(C.has(e.type))return e.text;for(let n of e.namedChildren){let t=V(n);if(t)return t}}s(V,"findNestedName");function ie(e){let n=e.parent;return n&&(n.type==="export_statement"||n.type==="decorated_definition"||n.type==="template_declaration")?n:e}s(ie,"unwrapDeclaration");function oe(e,n,t,i){let o=[];G.has(t)?$(e,t,o,i):U(e,t,o,!1,i);let r=se(n,e.startIndex),c=ae(n,e.endIndex),a=o.filter(l=>l.start>=r&&l.end<=c).sort((l,f)=>f.start-l.start),u=ce(n,r,c);for(let l of a){let f=l.start-r,m=l.end-r,x=le(l);u.splice(f,m-f,...x)}for(;u.length>0&&/\s/u.test(b(u.at(-1)).char);)u.pop();let d=[[]];for(let l of u)l.char===`
|
|
7
|
+
`?d.push([]):b(d.at(-1)).push(l);return d.map(l=>{let f=[...new Set(l.flatMap(m=>m.sourceLine===void 0?[]:[m.sourceLine]))];return{content:l.map(m=>m.char).join(""),...f.length===1&&{sourceLine:f[0]}}})}s(oe,"renderNodeLines");function se(e,n){return e.lastIndexOf(`
|
|
8
|
+
`,Math.max(0,n-1))+1}s(se,"lineStartAt");function ae(e,n){let t=e.indexOf(`
|
|
9
|
+
`,n);return t===-1?e.length:t}s(ae,"lineEndAt");function ce(e,n,t){let i=e.slice(0,n).split(`
|
|
10
|
+
`).length,o=[];for(let r=n;r<t;r+=1){let c=b(e[r]);o.push({char:c,sourceLine:i}),c===`
|
|
11
|
+
`&&(i+=1)}return o}s(ce,"mapSourceRange");function le(e){let n=e.lineSourceLines??[],t=0,i=[];for(let o=0;o<e.text.length;o+=1){let r=b(e.text[o]),c=n[t];i.push(c===void 0?{char:r}:{char:r,sourceLine:c}),r===`
|
|
12
|
+
`&&(t+=1)}return i}s(le,"mapReplacement");function D(e,n,t,i){return t<i||e.namedChildCount===0?!1:(n.push({start:e.startIndex,end:e.endIndex,text:"\u2026",lineSourceLines:[e.startPosition.row+1]}),!0)}s(D,"collapseDeepNode");function $(e,n,t,i,o=0){if(!D(e,t,o,i))for(let r of e.namedChildren){if(ue(r,n)){de(r)||t.push({start:r.startIndex,end:r.endIndex,text:"\u2026",lineSourceLines:[r.startPosition.row+1]});continue}$(r,n,t,i,o+1)}}s($,"collectDataReplacements");function ue(e,n){return(n===".json"||n===".jsonc"?["string","number","true","false","null"]:n===".yaml"||n===".yml"?["string_scalar","integer_scalar","float_scalar","boolean_scalar","null_scalar","block_scalar"]:["string","integer","float","boolean","date_time","offset_date_time","local_date_time","local_date","local_time"]).includes(e.type)}s(ue,"isDataScalar");function de(e){let n=e.parent;for(;n&&!n.type.endsWith("pair")&&n.type!=="pair"&&n.type!=="table";)n=n.parent;let t=n?.namedChildren[0];return t!==void 0&&t.startIndex<=e.startIndex&&t.endIndex>=e.endIndex}s(de,"isDataKey");function U(e,n,t,i,o,r=0){if(D(e,t,r,o))return;let c=Number.isFinite(o)&&e.type==="expression_statement";if(i&&!pe(e)&&!c){t.push({start:e.startIndex,end:e.endIndex,text:"\u2026",lineSourceLines:[e.startPosition.row+1]});return}if(M.has(e.type)){let a=fe(e);if(a){let u=me(a,n);t.push({start:a.startIndex,end:a.endIndex,text:u.text,lineSourceLines:u.lineSourceLines});return}}if(z.has(e.type)){let a=e.childForFieldName("value");if(a&&!M.has(a.type)){t.push({start:a.startIndex,end:a.endIndex,text:"\u2026",lineSourceLines:[a.startPosition.row+1]});return}}for(let a of e.namedChildren)U(a,n,t,q.has(e.type),o,r+1)}s(U,"collectReplacements");function pe(e){return B.has(e.type)||Z.has(e.type)||e.type==="comment"||e.type.startsWith("preproc")}s(pe,"isTopLevelInterfaceNode");function fe(e){let n=e.childForFieldName("body");return n||e.namedChildren.find(t=>t.type==="block"||t.type==="compound_statement"||t.type==="statement_block")}s(fe,"findBody");function me(e,n){let t=e.startPosition.row+1,i=e.endPosition.row+1;if(n===".py")return{text:"...",lineSourceLines:[t]};let o=e.text.split(`
|
|
13
|
+
`),r=o[0]??"",c=o.at(-1)??"",a=r.indexOf("{"),u=c.lastIndexOf("}");if(a===-1||u===-1)return{text:"\u2026",lineSourceLines:[t]};if(o.length===1){let p=r.slice(a+1,u);return p.trim()===""?{text:e.text,lineSourceLines:[t]}:{text:r.slice(0,a+1)+F(p)+r.slice(u),lineSourceLines:[t]}}let d=r.slice(a+1),l=c.slice(0,u),f=o.slice(1,-1).some(p=>p.trim()!==""),m=d.trim()!=="",x=l.trim()!=="";if(!f&&!m&&!x)return{text:e.text,lineSourceLines:o.map((p,_)=>t+_)};let g=[],y=[];if(g.push(m?r.slice(0,a+1)+F(d):r),y.push(t),!m&&f){let p=o.slice(1,-1).find(_=>_.trim()!=="")?.match(/^\s*/u)?.[0]??"";g.push(`${p}\u2026`),y.push(void 0)}return g.push(x?F(l)+c.slice(u):c),y.push(i),{text:g.join(`
|
|
14
|
+
`),lineSourceLines:y}}s(me,"renderBodyPlaceholder");function F(e){let n=/^\s*/u.exec(e)?.[0]??"",t=/\s*$/u.exec(e)?.[0]??"";return`${n}\u2026${t}`}s(F,"maskSegment");export{R as AstOutlineManager,Ce as formatAstOutline,N as isSupportedOutlinePath};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as a,d as u,e as c}from"./chunk-
|
|
1
|
+
import{c as a,d as u,e as c}from"./chunk-OBNING2A.js";import{a as t}from"./chunk-EI7MMDWY.js";function E(o,r){let s=t(()=>{let e,i={plugin:r,accept(R){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=R}};return o.events.emit(u,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(a,e=>{if(!c(e))throw new Error("Invalid pi-agent-read core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-read core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(E,"connectReadPlugin");export{E as a};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{a as re,b as ie,c as oe}from"./chunk-ESPNEJHK.js";import{a as ne}from"./chunk-5PLV4HLG.js";import{b as R}from"./chunk-526E364R.js";import"./chunk-YHUTTZC6.js";import{a as K}from"./chunk-6CZO43OH.js";import{a as Y,b as V}from"./chunk-OBNING2A.js";import{a as te}from"./chunk-ZTYWHL2F.js";import{a as Q,b as ee}from"./chunk-7UGNGK7Y.js";import{a as Z}from"./chunk-L7JMDDSD.js";import{a as z,b as J}from"./chunk-O6LE42GK.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";import Fe from"node:path";import{stripVTControlCharacters as je}from"node:util";import{truncateLine as Ge}from"@earendil-works/pi-coding-agent";import{Text as x}from"@earendil-works/pi-tui";import{DEFAULT_MAX_BYTES as se,DEFAULT_MAX_LINES as ae,formatSize as Ue,truncateTail as We}from"@earendil-works/pi-coding-agent";function I(t){return We(t,{maxBytes:se-4096,maxLines:ae-32})}a(I,"terminalOutputTail");function P(t){let e=I(t.output),n=[`session: ${t.source}`,`status: ${t.status}`,`shell: ${t.shell}`,`cwd: ${t.cwd}`,`elapsedMs: ${t.elapsedMs}`,t.exitCode===void 0?void 0:`exitCode: ${t.exitCode}`,t.signal===void 0?void 0:`signal: ${t.signal}`,t.error===void 0?void 0:`error: ${t.error}`,t.waitReason===void 0?void 0:`reason: ${t.waitReason}`,t.completionReason===void 0?void 0:`completionReason: ${t.completionReason}`,t.waitReason===void 0?void 0:`next: Read ${t.source} to inspect it, then use write or insert to send input.`,`outputRange: ${t.outputStart}-${t.outputEnd}`,t.truncated?"retainedOutput: earlier data omitted from memory":void 0,e.truncated?`fullOutput: ${t.fullOutputPath}`:void 0].filter(o=>o!==void 0),r=e.content.trimEnd();if(!e.truncated)return`${n.join(`
|
|
2
|
+
`)}
|
|
3
|
+
output:${r.length===0?" (empty)":`
|
|
4
|
+
${r}`}`;let i=e.truncatedBy==="lines"?`${ae} line output budget`:`${Ue(se)} output budget`,s=`[Earlier output omitted: showing the last ${e.outputLines} of ${e.totalLines} lines (${i}). Full output: ${t.fullOutputPath}]`;return`${n.join(`
|
|
5
|
+
`)}
|
|
6
|
+
output:
|
|
7
|
+
${s}${r.length===0?"":`
|
|
8
|
+
${r}`}`}a(P,"formatAgentTerminalSnapshot");var He=500;function le(t,e,n,r,i){let s=e?"background":"wait",o=`${i.fg("toolTitle",r.displayName.toLocaleLowerCase())} ${i.fg("muted",`\xB7 ${E(n)} \xB7 ${s}`)}`;return new x(`${o}
|
|
9
|
+
${i.fg("accent",O(r.family))} ${t}`,0,0)}a(le,"renderRunCall");function ue(t,e,n){let r=e.map(i=>` ${n.fg("dim",i)}`);return r.push(n.fg("success",t==="delete"?"\u2713 stopped":"\u2713 sent")),new x(r.join(`
|
|
10
|
+
`),0,0)}a(ue,"renderTerminalActionResult");function $(t,e,n,r,i){let s=[Ye(t,i),i.fg("accent",`${e} ${n}`)];return r.length>0&&s.push(...r.map(o=>` ${i.fg("dim",o)}`)),new x(s.join(`
|
|
11
|
+
`),0,0)}a($,"renderTerminalAction");function S(t,e,n,r){let i=Be(t,R,n);return r!==void 0&&i.splice(1,1,n.fg("accent",r)),new x(i.join(`
|
|
12
|
+
`),0,0)}a(S,"renderTerminalResult");function ce(t,e,n){if(e)return S(t,!0,n);let r=_(t.output??"",R),i=[...r.omission===void 0?[]:[` ${n.fg("muted",r.omission)}`],...r.lines.map(s=>` ${n.fg("dim",s)}`)];return i.push(D(t,(s,o)=>n.fg(s,o))),new x(i.join(`
|
|
13
|
+
`),0,0)}a(ce,"renderRunResult");function de(t,e){let n=a((o,l)=>e?.fg(o,l)??l,"color"),i=[`${n("accent",t.shell.toLocaleLowerCase())} ${n("muted",`\xB7 ${E(t.cwd)} \xB7 ${t.background?"background":"wait"}`)}`,`${n("accent",O(t.shellFamily))} ${M(t.command,84)}`],s=qe(t.output,2);return s.length>0&&i.push(...s.map(o=>` ${n("dim",M(o,90))}`)),i.push(D(t,n)),i.join(`
|
|
14
|
+
`)}a(de,"renderActiveTerminal");function Be(t,e,n){let r=(t.shell??"terminal").toLocaleLowerCase(),i=t.background===!0?"background":"wait",s=t.cwd===void 0?"workspace":E(t.cwd),o=t.shellFamily??"posix",l=[`${n.fg("accent",r)} ${n.fg("muted",`\xB7 ${s} \xB7 ${i}`)}`,`${n.fg("accent",O(o))} ${t.command??""}`],u=_(t.output??"",e);return u.omission!==void 0&&l.push(` ${n.fg("muted",u.omission)}`),u.lines.length>0&&l.push(...u.lines.map(c=>` ${n.fg("dim",c)}`)),l.push(D(t,(c,d)=>n.fg(c,d))),l}a(Be,"terminalCardLines");function qe(t,e){return _(t,e).lines}a(qe,"outputTail");function _(t,e){let n=I(je(t).replaceAll("\r","")),r=n.content.split(`
|
|
15
|
+
`).map(u=>Ge(u.trimEnd(),He).text);r.at(-1)===""&&r.pop();let i=Number.isFinite(e)?Math.max(0,e):r.length,s=Math.max(0,r.length-i),o=Math.max(0,n.totalLines-n.outputLines),l=s+o;return{lines:r.slice(s),...n.truncated||l>0?{omission:l>0?`\u2026 ${l} earlier lines`:"\u2026 earlier output omitted"}:{}}}a(_,"outputWindow");function D(t,e){let n=t.status??"running",r=Xe(n),i=n==="completed"?"success":n==="running"?"accent":"error",s=[`${r} ${n}`,Ve(t.elapsedMs??0)];return t.waitReason!==void 0&&s.push(`background \xB7 ${t.waitReason}`),t.completionReason!==void 0&&s.push(`reason ${t.completionReason}`),t.exitCode!==void 0?s.push(`exit ${t.exitCode}`):t.signal!==void 0&&s.push(`signal ${t.signal}`),e(i,s.join(" \xB7 "))}a(D,"statusLine");function Xe(t){return t==="completed"?"\u2713":t==="running"?"\u25CF":t==="stopping"?"\u25CC":"\u2717"}a(Xe,"statusIcon");function O(t){return t==="powershell"?"PS>":t==="cmd"?">":"$"}a(O,"promptMarker");function Ye(t,e){let n=(t.shell??"terminal").toLocaleLowerCase(),r=t.cwd===void 0?"workspace":E(t.cwd),i=t.background===!0?"background":"wait",s=M(t.command??"process",48);return`${e.fg("toolTitle",n)} ${e.fg("muted",`\xB7 ${r} \xB7 ${i} \xB7 ${s}`)}`}a(Ye,"terminalIdentity");function E(t){let e=process.env.HOME;return e!==void 0&&(t===e||t.startsWith(`${e}${Fe.sep}`))?`~${t.slice(e.length)}`:t}a(E,"shortCwd");function M(t,e){let n=t.replaceAll(/\s+/gu," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}a(M,"oneLine");function Ve(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(t<1e4?1:0)}s`}a(Ve,"formatElapsed");function me(t){return{id:"terminal",onDidChange:a(e=>t.onDidChange(e),"onDidChange"),list:a(()=>t.list().filter(e=>e.status==="running"||e.status==="stopping").map(e=>({source:e.source,kind:"terminal",title:e.shell.toLocaleLowerCase(),description:e.command,status:e.status==="stopping"?"stopping":"running",renderSummary:a(n=>de(e,n).split(`
|
|
16
|
+
`),"renderSummary"),renderDetail:a(n=>S(e,!0,n),"renderDetail"),sendInput:a(n=>t.write(e.source,n),"sendInput"),stop:a(()=>t.delete(e.source),"stop")})),"list")}}a(me,"terminalProcessProvider");var Ke="#d8dee9",N="#111418",ze=["#000000","#cd0000","#00cd00","#cdcd00","#0000ee","#cd00cd","#00cdcd","#e5e5e5","#7f7f7f","#ff0000","#00ff00","#ffff00","#5c5cff","#ff00ff","#00ffff","#ffffff"];async function U(t,e,n){let r=t.get(e);if(r===void 0)throw new Error(`Unknown terminal session ${e}`);await r.screenReady;let{createCanvas:i}=await import("@napi-rs/canvas"),s=Math.max(0,Math.min(r.rows-1,n?.start??0)),o=Math.max(1,Math.min(r.rows-s,n?.count??r.rows)),l=i(r.cols*9+24,o*18+24),u=l.getContext("2d");u.fillStyle=N,u.fillRect(0,0,l.width,l.height),u.textBaseline="top";let c=r.screen.buffer.active,d=Math.max(0,c.baseY);for(let m=0;m<o;m+=1){let p=c.getLine(d+s+m);if(p!==void 0)for(let f=0;f<r.cols;f+=1){let h=p.getCell(f);h===void 0||h.getWidth()===0||Je(u,h,f,m)}}return r.status==="running"&&c.cursorY>=s&&c.cursorY<s+o&&(u.fillStyle="rgba(216, 222, 233, 0.75)",u.fillRect(12+c.cursorX*9,12+(c.cursorY-s)*18+18-2,9,2)),l.toBuffer("image/png").toString("base64")}a(U,"renderTerminalScreen");function Je(t,e,n,r){let i=pe(e,"foreground"),s=pe(e,"background");e.isInverse()&&([i,s]=[s,i]);let o=12+n*9,l=12+r*18;s!==N&&(t.fillStyle=s,t.fillRect(o,l,9*Math.max(1,e.getWidth()),18));let u=e.getChars();u.length!==0&&(t.font=`${e.isBold()?"bold ":""}14px monospace`,t.fillStyle=i,t.fillText(u,o,l),e.isUnderline()&&t.fillRect(o,l+18-2,9*Math.max(1,e.getWidth()),1))}a(Je,"drawCell");function pe(t,e){let n=e==="foreground";if(n?t.isFgDefault():t.isBgDefault())return n?Ke:N;let i=n?t.isFgRGB():t.isBgRGB(),s=n?t.getFgColor():t.getBgColor();return i?`#${s.toString(16).padStart(6,"0")}`:Ze(s)}a(pe,"cellColor");function Ze(t){let e=ze[t];if(e!==void 0)return e;if(t>=232){let l=8+(t-232)*10;return fe(l,l,l)}let n=Math.max(0,t-16),r=Math.floor(n/36),i=Math.floor(n%36/6),s=n%6,o=a(l=>l===0?0:55+l*40,"channel");return fe(o(r),o(i),o(s))}a(Ze,"ansiColor");function fe(t,e,n){return`#${[t,e,n].map(r=>r.toString(16).padStart(2,"0")).join("")}`}a(fe,"rgb");var W="\0pi-terminal-write\0",F="\0pi-terminal-keys\0";async function Se(t,e){let n=new Map,r=new Map,i={protocol:Y,apiVersion:V,id:"terminal",setup(o){o.addResolver({resolver:Qe(e),preserveTruncatedOutput:!0,renderResult(l,u,c){let d=l.details,m=d.source===void 0?void 0:e.get(d.source),p=m===void 0?{}:e.snapshot(m);return S(m===void 0?p:{...p,output:e.screenTail(m).join(`
|
|
17
|
+
`)},u.expanded,c,"read terminal")}}),o.addHandler({stage:"pre-read",async handler(l){let u=l.request.path;if(u===void 0||!y(u)||l.request.views?.includes("image")!==!0)return{kind:"continue",context:l};let c=e.get(u);if(c===void 0)return{kind:"return",result:ge(u,`Unknown terminal session ${u}`)};try{return e.markInspected(u),{kind:"return",result:{content:[{type:"image",data:await U(e,u),mimeType:"image/png"}],details:{source:c.source,resolvedBy:"terminal"}}}}catch(d){return{kind:"return",result:ge(u,d instanceof Error?d.message:String(d))}}}}),o.describe('shell:<session> \u2014 terminal session status and a bounded output tail with a full-log path when truncated. 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:z,apiVersion:J,id:"terminal",setup(o){o.addResolver({resolver:et(e)}),o.tool("write").addHandler({stage:"text-pre-edit",handler:a(async l=>(ye(l.input,e,n),await he(l.input,e,r),tt(l,W)),"handler")}),o.tool("insert").addHandler({stage:"text-pre-edit",handler:a(async l=>(await he(l.input,e,r),ye(l.input,e,n),nt(l)),"handler")});for(let l of["write","insert","delete"])o.addToolRenderer({tool:l,matches:a((u,c)=>st(u,c),"matches"),renderCall(u,c,d){let m=u,p=typeof m.path=="string"?e.get(m.path):void 0,f=d.state;return p!==void 0&&(f.snapshot=e.snapshot(p)),$(f.snapshot??{},l,we(l,m),[],c)},renderResult(u,c,d){let m=ot(u.details);return ue(m.action,m.changedLines,d)}});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(t,i),Z(t,s)]),t.on("tool_result",async(o,l)=>{if(!w(o.input))return;let u=o.input.path;if(o.toolName==="replace"&&typeof u=="string"&&y(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"&&y(u)){let X=e.get(u);if(X===void 0)return;let Ne=e.snapshot(X);return e.delete(u).then(()=>({content:[{type:"text",text:`Deleted terminal session ${u}.`}],details:{source:u,deleted:!0,snapshot:Ne,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 c=o.input.path;if(typeof c!="string"||!y(c))return;let d=e.get(c);if(d===void 0)return;let m=r.get(c)??e.screenRows(d);r.delete(c);let p=n.get(c)??d.outputStart+d.output.length;n.delete(c),await e.waitForOutputAfter(d,p);let f=e.snapshot(d),h=o.toolName,v=we(h,o.input),b=e.screenChangeRegion(d,m,6),q=[{type:"text",text:`Sent ${v} to ${d.source}.`}];return l.model?.input.includes("image")===!0&&q.push({type:"image",data:await U(e,c,{start:b.startRow,count:b.lines.length}),mimeType:"image/png"}),{content:q,details:{source:d.source,action:h,status:d.status,snapshot:f,input:v,changedLines:b.lines},isError:o.isError}})}a(Se,"registerTerminalResources");function Qe(t){return{id:"terminal",async tryResolve(e){if(!y(e))return{kind:"not-handled"};let n=t.get(e);return n===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${e}`)}:{kind:"resolved",resource:{source:n.source,async read(){t.markInspected(n.source);let r=t.snapshot(n);return[{type:"text",text:rt(r)}]}}}}}}a(Qe,"createReadResolver");function et(t){return{id:"terminal-input",async tryResolve(e){if(!y(e))return{kind:"not-handled"};let n=t.get(e);return n===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${e}`)}:{kind:"resolved",resource:{source:n.source,skipPostEdit:!0,async read(){return[{type:"text",text:"terminal input"}]},async write(r){let i=it(r),s=i.indexOf(W),o=i.indexOf(F);if(s>=0){t.write(n.source,i.slice(s+W.length));return}if(o>=0){t.sendKeys(n.source,i.slice(o+F.length).trim());return}throw new Error(`Unsupported text operation for ${n.source}`)}}}}}}a(et,"createInputResolver");function tt(t,e){return!w(t.input)||!Te(t.input.path)?t:{...t,input:{...t.input,content:`${e}${typeof t.input.content=="string"?t.input.content:""}`}}}a(tt,"transformWriteInput");function nt(t){if(!w(t.input)||!Te(t.input.path))return t;if(t.input.before===!0)throw new Error("Shell keys can only be inserted after the active input position");return{...t,input:{...t.input,anchor:"end",before:!1,text:`${F}${typeof t.input.text=="string"?t.input.text:""}`}}}a(nt,"transformInsertInput");function rt(t){return P(t)}a(rt,"formatSnapshot");function it(t){if(t.length!==1||t[0].type!=="text")throw new Error("Terminal input must contain one text block");return t[0].text}a(it,"singleText");function ge(t,e){return{content:[{type:"text",text:e}],details:{source:t,failure:{code:"READ_FAILED",source:t,resolverId:"terminal",message:e}},isError:!0}}a(ge,"failure");function y(t){return/^shell:[a-f\d]{12}$/u.test(t)}a(y,"isShellSource");function Te(t){return typeof t=="string"&&y(t)}a(Te,"isShellSourceValue");function ot(t){if(!w(t)||!w(t.snapshot))throw new TypeError("Invalid terminal action result");let e=t.snapshot,n=t.action;if(n!=="write"&&n!=="insert"&&n!=="delete")throw new TypeError("Invalid terminal action");return{source:typeof t.source=="string"?t.source:"shell:unknown",action:n,input:typeof t.input=="string"?t.input:"",changedLines:Array.isArray(t.changedLines)?t.changedLines.filter(r=>typeof r=="string"):[],snapshot:{...typeof e.shell=="string"?{shell:e.shell}:{},...typeof e.cwd=="string"?{cwd:e.cwd}:{},...typeof e.command=="string"?{command:e.command}:{},...typeof e.background=="boolean"?{background:e.background}:{},...typeof e.status=="string"?{status:e.status}:{}}}}a(ot,"terminalActionDetails");async function he(t,e,n){if(!w(t)||typeof t.path!="string"||!y(t.path))return;let r=e.get(t.path);r!==void 0&&await r.screenReady,r!==void 0&&n.set(t.path,e.screenRows(r))}a(he,"rememberScreen");function ye(t,e,n){if(!w(t)||typeof t.path!="string"||!y(t.path))return;let r=e.get(t.path);r!==void 0&&n.set(t.path,r.outputStart+r.output.length)}a(ye,"rememberOutputEnd");function we(t,e){if(t==="delete")return"session";let n=t==="write"?e.content:e.text,r=typeof n=="string"?n:"";return t==="write"?`text ${JSON.stringify(r)}`:`keys ${r}`}a(we,"terminalInputLabel");function st(t,e){if(!w(t))return!1;if(e==="call")return typeof t.path=="string"&&y(t.path);let n=t.details;return w(n)&&typeof n.source=="string"&&y(n.source)}a(st,"isTerminalRenderValue");function w(t){return typeof t=="object"&&t!==null}a(w,"isRecord");async function Re(t,e){await te(t,{protocol:Q,apiVersion:ee,id:"terminal",setup(r){r.addResolver({resolver:at(e),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(Re,"registerTerminalSearch");function at(t){return{id:"terminal",async tryResolve(e){if(e.path===void 0||!e.path.startsWith("shell:"))return{kind:"not-handled"};let n=t.get(e.path);if(n===void 0)return{kind:"failed",error:new Error(`Unknown terminal session ${e.path}`)};let r=t.snapshot(n),i=lt(r,e);return{kind:"resolved",payload:{snapshot:r,query:e.query,matches:i}}},format(e){let n=j(e),r=n.matches.map(i=>`${n.snapshot.source}:${i.lineNumber}: ${i.lineText}`);return{content:[{type:"text",text:r.length===0?`No matches in ${n.snapshot.source}`:`${r.join(`
|
|
18
|
+
`)}
|
|
19
|
+
|
|
20
|
+
${r.length} match${r.length===1?"":"es"} in ${n.snapshot.source}`}],details:{source:n.snapshot.source,payload:n}}},renderResult(e,n,r){let i=e.details,s=H(i)?j(i.payload):j(void 0),o=$(s.snapshot,"search",JSON.stringify(s.query),s.matches.slice(-6).map(l=>`${l.lineNumber}: ${l.lineText}`),r);return new G(o,n.expanded===!0,r)}}}a(at,"terminalSearchResolver");var be=12,G=class{constructor(e,n,r){this.content=e;this.expanded=n;this.theme=r}static{a(this,"TerminalSearchPanel")}render(e){let n=this.content.render(e);if(this.expanded||n.length<=be)return n;let r=be-1;return[...n.slice(0,r),this.theme.fg("muted",`\u2026 ${String(n.length-r)} visual rows omitted \xB7 ctrl+o to expand`)]}invalidate(){this.content.invalidate()}};function lt(t,e){let n=e.caseSensitive===!0?e.query:e.query.toLocaleLowerCase();if(n.length===0)return[];let r=[],i=e.limit??100;for(let[s,o]of t.output.replaceAll("\r","").split(`
|
|
21
|
+
`).entries()){let l=e.caseSensitive===!0?o:o.toLocaleLowerCase(),u=0;for(;r.length<i;){let c=l.indexOf(n,u);if(c<0)break;let d=c+n.length;(e.wholeWord!==!0||ut(l,c,d))&&r.push({source:t.source,lineNumber:s+1,startColumn:c,endColumn:d,matchedText:o.slice(c,d),lineText:o}),u=Math.max(d,c+1)}if(r.length>=i)break}return r}a(lt,"findTerminalMatches");function ut(t,e,n){return!/[\p{L}\p{N}_]/u.test(t[e-1]??"")&&!/[\p{L}\p{N}_]/u.test(t[n]??"")}a(ut,"isWordBoundary");function j(t){if(!ct(t))throw new TypeError("Invalid terminal search result");return t}a(j,"parsePayload");function ct(t){return H(t)&&typeof t.query=="string"&&Array.isArray(t.matches)&&H(t.snapshot)&&typeof t.snapshot.source=="string"}a(ct,"isTerminalSearchPayload");function H(t){return typeof t=="object"&&t!==null}a(H,"isRecord");import{spawn as dt}from"node:child_process";import{closeSync as mt,mkdirSync as pt,openSync as ft,rmSync as gt,writeSync as ht}from"node:fs";import yt from"node:os";import xe from"node:path";import{createRequire as wt}from"node:module";import{randomUUID as St}from"node:crypto";import{stripVTControlCharacters as Tt}from"node:util";var $e=wt(new URL("../src/plugins/pi-agent-ide-terminal/src/session-manager.ts",import.meta.url).href),ve=1e6,bt=100,Rt=30,xt=2e3,k=class{static{a(this,"TerminalSessionManager")}#a;#e=new Map;#t=new Set;#r=new Set;#i=new Map;#o=!1;constructor(e=$t){this.#a=e}onDidChange(e){return this.#t.add(e),()=>this.#t.delete(e)}onDidComplete(e){return this.#r.add(e),()=>this.#r.delete(e)}list(){return[...this.#e.values()].sort((e,n)=>n.startedAt-e.startedAt).map(e=>this.snapshot(e))}get(e){return this.#e.get(Et(e))}snapshot(e,n=Date.now()){return{id:e.id,source:e.source,command:e.command,cwd:e.cwd,shell:e.shell.displayName,shellFamily:e.shell.family,background:e.background,status:e.status,...e.waitReason===void 0?{}:{waitReason:e.waitReason},...e.completionReason===void 0?{}:{completionReason:e.completionReason},lastActivityAt:e.lastActivityAt,idleMs:Math.max(0,n-e.lastActivityAt),startedAt:e.startedAt,...e.endedAt===void 0?{}:{endedAt:e.endedAt},elapsedMs:(e.endedAt??n)-e.startedAt,...e.exitCode===void 0?{}:{exitCode:e.exitCode},...e.signal===void 0?{}:{signal:e.signal},...e.error===void 0?{}:{error:e.error},output:e.output,outputStart:e.outputStart,outputEnd:e.outputStart+e.output.length,truncated:e.outputStart>0,fullOutputPath:e.fullOutputPath,cols:e.cols,rows:e.rows}}start(e){if(this.#o)throw new Error("Terminal session manager is closed");let n=this.#a();if(!/^[a-f\d]{12}$/u.test(n)||this.#e.has(n))throw new Error("Terminal session IDs must be unique 12-character hexadecimal values");let r=Mt(n);this.#i.set(n,ft(r,"a",384));let i=e.cols??bt,s=e.rows??Rt,o=Pt(i,s),l=a(p=>{},"resolveCompletion"),u=new Promise(p=>{l=p}),c={id:n,source:`shell:${n}`,command:e.command,background:e.background,cwd:e.cwd,shell:e.shell,startedAt:Date.now(),lastActivityAt:Date.now(),cols:i,rows:s,fullOutputPath:r,screen:o,status:"running",output:"",outputStart:0,screenReady:Promise.resolve(),completion:u,resolveCompletion:l,completionDelivered:!1},d;try{let p=$e("node-pty"),f={name:"xterm-256color",cols:i,rows:s,cwd:e.cwd,env:At(kt())};d=p.spawn(e.shell.executable,[...e.shell.commandArgs(e.command)],f)}catch(p){let f={...c,status:"failed",endedAt:Date.now(),error:It(p)};return this.#e.set(n,f),this.#s(n),l(f),queueMicrotask(()=>this.#l(f)),f}let m={...c,process:d};return this.#e.set(n,m),d.onData(p=>this.#u(m,p)),d.onExit(({exitCode:p,signal:f})=>{T(m.status)||(m.endedAt=Date.now(),m.exitCode=p,f!==0&&(m.signal=f),m.status=m.status==="stopping"?"stopped":p===0?"completed":"failed",(p===124||p===137)&&(m.completionReason="timeout"),this.#s(m.id),m.resolveCompletion(m),this.#n(m),this.#l(m))}),this.#n(m),m}async wait(e,n){let r=this.required(e);return T(r.status)?r:n?.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");n?.addEventListener("abort",o,{once:!0}),r.completion.then(l=>{n?.removeEventListener("abort",o),i(l)},s)})}async waitForForeground(e,n){let r=this.required(e);if(T(r.status))return{session:r};let i=n.interactiveDelayMs??3e3;return await new Promise(s=>{let o=!1,l,u=a(p=>{o||(p!==void 0&&T(r.status)&&(p=void 0),o=!0,clearTimeout(d),clearInterval(m),n.signal?.removeEventListener("abort",c),p!==void 0&&(r.background=!0,p!=="aborted"&&(r.waitReason=p),this.#n(r)),s({session:r,...p===void 0?{}:{reason:p}}))},"finish"),c=a(()=>u("aborted"),"onAbort"),d=setTimeout(()=>u("timeout"),n.timeoutMs),m=setInterval(()=>{if(!vt(r)){l=void 0;return}l??=Date.now(),Date.now()-l>=i&&u("interactive")},Math.min(100,Math.max(10,i/2)));n.signal?.addEventListener("abort",c,{once:!0}),n.signal?.aborted===!0&&c(),r.completion.then(()=>u())})}async waitForOutputAfter(e,n){let r=Date.now()+300,i=n,s;for(;Date.now()<r;){let o=e.outputStart+e.output.length;if(o!==i)i=o,s=Date.now(),await e.screenReady;else if(s!==void 0&&Date.now()-s>=40)return;await B(10)}await e.screenReady}screenRows(e){let n=e.screen.buffer.active;return Array.from({length:e.rows},(r,i)=>(n.getLine(n.baseY+i)?.translateToString(!0)??"").trimEnd())}screenChangeRegion(e,n,r=6){let i=this.screenRows(e),s=Math.max(1,Math.min(e.rows,r)),o=Math.max(0,e.screen.buffer.active.cursorY-Math.floor(s/2)),l=-1;for(let d=0;d<=e.rows-s;d+=1){let m=0;for(let p=d;p<d+s;p+=1){let f=n[p]??"",h=i[p]??"",v=h.length>0&&!n.includes(h),b=f.length>0&&h.length===0;f!==h&&(v||b)&&(m+=1)}m>l&&(l=m,o=d)}let u=e.screen.buffer.active;return{lines:i.slice(o,o+s).map((d,m)=>{if(o+m!==u.cursorY)return d;let f=d.padEnd(u.cursorX," ");return`${f.slice(0,u.cursorX)}\u258C${f.slice(u.cursorX)}`}),startRow:o}}screenChangeWindow(e,n,r=6){return this.screenChangeRegion(e,n,r).lines}screenTail(e,n=e.rows){let r=e.screen.buffer.active,i=Math.max(0,r.baseY),s=[];for(let o=0;o<e.rows;o+=1){let l=r.getLine(i+o)?.translateToString(!0).trimEnd();l!==void 0&&l.length>0&&s.push(l)}return s.slice(-Math.max(0,n))}markInspected(e){let n=this.required(e);n.status==="running"&&(n.lastActivityAt=Date.now(),this.#n(n))}write(e,n){this.requiredRunning(e).process?.write(n)}sendKeys(e,n){this.requiredRunning(e).process?.write(Ct(n))}async stop(e,n="stopped"){let r=this.required(e);return T(r.status)||(r.status="stopping",this.#n(r),await Pe(r,!1),await Promise.race([r.completion.then(()=>!0),B(xt).then(()=>!1)])||(await Pe(r,!0),await Promise.race([r.completion,B(1e3)])),T(r.status)||(r.status=n,r.endedAt=Date.now(),this.#s(r.id),r.resolveCompletion(r),this.#l(r)),n==="cancelled"&&(r.status="cancelled"),this.#n(r)),r}async delete(e){let n=this.required(e);n.completionDelivered=!0,await this.stop(n.source),n.screen.dispose(),this.#s(n.id),gt(n.fullOutputPath,{force:!0}),this.#e.delete(n.id),this.#n(n)}async screenLines(e){let n=this.required(e);await n.screenReady;let r=n.screen.buffer.active,i=[],s=Math.max(0,r.baseY);for(let o=s;o<s+n.rows;o+=1)i.push(r.getLine(o)?.translateToString(!0)??"");return i}cursor(e){let n=this.required(e);return{x:n.screen.buffer.active.cursorX,y:n.screen.buffer.active.cursorY}}async dispose(){if(!this.#o){this.#o=!0,await Promise.all([...this.#e.values()].filter(e=>!T(e.status)).map(e=>this.stop(e.source)));for(let e of this.#e.values())e.screen.dispose(),this.#s(e.id);this.#t.clear(),this.#r.clear()}}required(e){let n=this.get(e);if(n===void 0)throw new Error(`Unknown terminal session ${e}`);return n}requiredRunning(e){let n=this.required(e);if(n.status!=="running")throw new Error(`Terminal session ${n.source} is ${n.status}; input is unavailable`);return n}#u(e,n){e.lastActivityAt=Date.now();let r=Tt(n),i=this.#i.get(e.id);if(i!==void 0&&ht(i,r),e.output+=r,e.output.length>ve){let s=e.output.length-ve;e.output=e.output.slice(s),e.outputStart+=s}e.screenReady=e.screenReady.then(()=>new Promise(s=>{e.screen.write(n,s)})),this.#n(e)}#s(e){let n=this.#i.get(e);n!==void 0&&(mt(n),this.#i.delete(e))}#n(e){for(let n of this.#t)n(e)}#l(e){for(let n of this.#r)n(e)}};function vt(t){if(t.status!=="running")return!1;let e=t.screen.buffer.active,n=e.getLine(e.baseY+e.cursorY)?.translateToString(!0).trimEnd()??"";return/\[[^\]\n]{1,20}(?:\/[^\]\n]{1,20})+\]\s*[:?>]?\s*$/iu.test(n)||/(?:choose|select|enter|password|confirm|continue|proceed)[^\n]{0,60}[:?]\s*$/iu.test(n)||/^(?:❯|›)\s+\S/u.test(n)}a(vt,"looksInteractive");function Pt(t,e){let{Terminal:n}=$e("@xterm/headless");return new n({cols:t,rows:e,scrollback:2e3,allowProposedApi:!0})}a(Pt,"createScreen");function $t(){return St().replaceAll("-","").slice(0,12)}a($t,"defaultSessionId");function Et(t){return t.startsWith("shell:")?t.slice(6):t}a(Et,"normalizeSessionId");function T(t){return t!=="running"&&t!=="stopping"}a(T,"isTerminalStatus");function kt(){return process.env}a(kt,"processEnvironment");function At(t){return{...Object.fromEntries(Object.entries(t).filter(e=>e[1]!==void 0)),PAGER:"cat",GIT_PAGER:"cat",SYSTEMD_PAGER:"cat",GH_PAGER:"cat"}}a(At,"cleanEnvironment");function Ct(t){return t.split(/[\s,]+/u).filter(Boolean).map(Lt).join("")}a(Ct,"encodeTerminalKeys");function Lt(t){if(/^\^[?@A-Z[\\\]^_]$/iu.test(t)){let d=t.slice(1).toUpperCase();return d==="?"?"\x7F":String.fromCharCode(d.charCodeAt(0)&31)}let e=t.toLowerCase().split("+"),n=e.pop()??"",r=new Set(e);if([...r].some(d=>!["ctrl","control","alt","meta","shift"].includes(d)))throw new Error(`Unsupported terminal key ${t}`);let i=r.has("ctrl")||r.has("control"),s=r.has("alt")||r.has("meta"),o=r.has("shift");if(i&&n.length===1&&/[a-z@[\\\]^_?]/u.test(n)){let d=n.toUpperCase(),m=d==="?"?"\x7F":String.fromCharCode(d.charCodeAt(0)&31);return s?`\x1B${m}`:m}let l={enter:"\r",tab:" ",escape:"\x1B",esc:"\x1B",backspace:"\x7F",home:"\x1B[H",end:"\x1B[F",delete:"\x1B[3~"};if(!i&&!s&&!o&&l[n]!==void 0)return l[n];if(s&&!i&&!o&&l[n]!==void 0)return`\x1B${l[n]}`;let c={up:"A",down:"B",right:"C",left:"D",home:"H",end:"F"}[n];if(c!==void 0)return!i&&!s&&!o?`\x1B[${c}`:`\x1B[1;${1+(o?1:0)+(s?2:0)+(i?4:0)}${c}`;if(s&&!i&&n.length===1)return`\x1B${o?n.toUpperCase():n}`;throw new Error(`Unsupported terminal key ${t}`)}a(Lt,"encodeTerminalKey");async function Pe(t,e){let n=t.process;if(n!==void 0){if(globalThis.process.platform!=="win32")try{globalThis.process.kill(-n.pid,e?"SIGKILL":"SIGTERM");return}catch{try{n.kill(e?"SIGKILL":"SIGTERM")}catch{}return}await new Promise(r=>{let i=dt("taskkill.exe",["/PID",String(n.pid),"/T",...e?["/F"]:[]],{windowsHide:!0,stdio:"ignore"});i.once("error",()=>r()),i.once("exit",()=>r())})}}a(Pe,"terminateProcessTree");function B(t){return new Promise(e=>setTimeout(e,t))}a(B,"delay");function It(t){return t instanceof Error?t.message:String(t)}a(It,"errorMessage");function Mt(t){let e=xe.join(yt.tmpdir(),`pi-agent-ide-terminal-${process.pid}`);return pt(e,{recursive:!0,mode:448}),xe.join(e,`${t}.log`)}a(Mt,"createOutputLog");import _t from"node:os";import Ee from"node:path";function ke(t=process.platform,e=process.env){if(t==="win32"){let i=e.SHELL?.trim()||"powershell.exe",s=Ee.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 n=e.SHELL?.trim()||_t.userInfo().shell||(t==="darwin"?"/bin/zsh":"/bin/bash"),r=Ee.basename(n);return{executable:n,displayName:r==="zsh"?"zsh":r==="bash"?"Bash":r,family:"posix",commandArgs:a(i=>["-c",i],"commandArgs")}}a(ke,"resolveShellProfile");function Ae(t){switch(t.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 ${t.displayName} syntax. Use POSIX-style paths, \`$NAME\` for environment variables, and \`&&\` or pipelines to compose commands.`}}a(Ae,"shellSyntaxGuidance");import Ce from"node:path";import{stripVTControlCharacters as Dt}from"node:util";import{defineTool as Ot}from"@earendil-works/pi-coding-agent";import{Type as g}from"typebox";var Nt=g.Object({command:g.String({minLength:1,description:"Command written in the syntax of the configured system shell"}),background:g.Optional(g.Boolean({description:"Return immediately while the terminal session continues. Defaults to false."})),timeoutSeconds:g.Optional(g.Number({minimum:.1,maximum:86400,description:"Maximum foreground wait in seconds before returning the live session as background. Defaults to 60."})),cwd:g.Optional(g.String({description:"Working directory. Relative paths resolve from the current workspace."})),cols:g.Optional(g.Integer({minimum:20,maximum:300,description:"Virtual terminal width in cells"})),rows:g.Optional(g.Integer({minimum:5,maximum:120,description:"Virtual terminal height in cells"}))},{additionalProperties:!1});function Le(t,e,n,r){let i=process.platform==="win32"?"powershell":"bash";t.registerTool(Ot({name:i,label:n.displayName,promptSnippet:`Execute ${n.displayName} commands in synchronous or background terminal sessions`,promptGuidelines:[`Write commands for ${n.displayName}; commands are not translated between shell languages.`,`Use ${i} with background for servers, watchers, and long builds. Foreground waits become background after timeoutSeconds (60 by default), on a stable interactive prompt, or when the turn is aborted. After a session enters background, do not poll it continuously; continue other work or wait for its automatic completion notification. Keep a short task in foreground wait when it should finish soon and no independent work remains. A background session with no output for two minutes wakes an idle agent so it can be inspected. Sessions survive extension reloads and keep the same shell: source. Large output returns a bounded tail and a fullOutput file path. Use the returned shell: source with read, write, insert, and delete.`],description:`Use ${i} to execute a command in the user's configured ${n.displayName} shell (${n.executable}). Every call creates an addressable terminal session. Set background to true to continue without waiting. A foreground wait automatically returns the live session as background on timeout, a stable interactive prompt, or turn abort. Background completion is delivered automatically and wakes the agent, so background sessions do not need continuous polling. Keep short tasks in foreground wait when they should finish soon and no independent work remains. Sessions survive extension reloads and keep the same shell: source. Output uses the shared Read limits, keeps the tail, and links a complete log file when truncated. ${Ae(n)}`,parameters:Nt,async execute(s,o,l,u,c){r.bind(c);let d=o.cwd===void 0?c.cwd:Ce.resolve(c.cwd,o.cwd),m=e.start({command:o.command,background:o.background??!1,cwd:d,shell:n,...o.cols===void 0?{}:{cols:o.cols},...o.rows===void 0?{}:{rows:o.rows}});if(o.background===!0&&m.status!=="failed")return await Ut(e,m,u),m.status!=="running"&&(m.completionDelivered=!0),A(e.snapshot(m));if(m.status==="failed")return A(e.snapshot(m));let p=await e.waitForForeground(m.source,{signal:l,timeoutMs:(o.timeoutSeconds??60)*1e3});return p.reason==="aborted"&&r.notifyWaitTransition(p.session),A(e.snapshot(p.session))},renderCall(s,o){let l=typeof s.command=="string"?s.command:"",u=typeof s.cwd=="string"?Ce.resolve(process.cwd(),s.cwd):process.cwd();return le(l,s.background===!0,u,n,o)},renderResult(s,o,l){return ce(s.details,o.expanded,l)}}))}a(Le,"registerTerminalTools");function A(t){return{content:[{type:"text",text:P(t)}],details:t,isError:t.status==="failed"||t.status==="lost"}}a(A,"terminalResult");async function Ut(t,e,n){await new Promise(r=>{let i=!1,s,o=a(()=>{},"unsubscribe"),l=a(()=>{i||(i=!0,clearTimeout(s),o(),r())},"finish"),u=a(()=>{let c=t.snapshot(e);n?.(A(c)),(Dt(c.output).replaceAll("\r","").split(`
|
|
22
|
+
`).filter(m=>m.length>0).length>=R||c.status!=="running")&&l()},"publish");o=t.onDidChange(c=>{c.id===e.id&&u()}),s=setTimeout(l,2e3),u()})}a(Ut,"captureInitialBackgroundPreview");import{Box as Ie,Container as Me}from"@earendil-works/pi-tui";var Wt=120,Ft=12e4,C=class{constructor(e,n,r=Ft){this.pi=e;this.manager=n;this.staleIntervalMs=r;e.registerMessageRenderer("terminal-stale",(i,{expanded:s},o)=>{let l=_e(i.details)?i.details:void 0,u=new Me;l!==void 0&&u.addChild(S(l,s,o,"stale \xB7 inspect session"));let c=new Ie(1,1,d=>o.bg("toolPendingBg",d));return c.addChild(u),c}),e.registerMessageRenderer("terminal-completion",(i,{expanded:s},o)=>{let l=new Me;for(let c of jt(i.details))l.addChild(S(c,s,o));let u=new Ie(1,1,c=>o.bg("toolSuccessBg",c));return u.addChild(l),u}),this.#u=[n.onDidChange(i=>this.#s(i)),n.onDidComplete(i=>{this.#l(i.id),i.background&&this.#c(i)})]}static{a(this,"TerminalUi")}#a=new Map;#e;#t=new Map;#r=new Set;#i;#o=!1;#u;bind(e){this.#i=e}onAgentSettled(e){this.#i=e;for(let n of[...this.#r]){this.#r.delete(n);let r=this.manager.get(n);r!==void 0&&this.#s(r,!0)}}notifyWaitTransition(e){let n=this.manager.snapshot(e);this.pi.sendMessage({customType:"terminal-wait-transition",display:!1,content:`Terminal wait ended; ${n.source} is still running in background. Read it to inspect output, then use write or insert to send input.`,details:n},{triggerTurn:!0,deliverAs:"steer"})}dispose(){this.#o=!0,this.#e!==void 0&&clearTimeout(this.#e),this.#e=void 0,this.#a.clear();for(let e of this.#t.values())clearTimeout(e);this.#t.clear(),this.#r.clear(),this.#i=void 0;for(let e of this.#u)e()}#s(e,n=!1){if(this.#l(e.id),this.#o||!e.background||e.status!=="running")return;let r=this.manager.snapshot(e),i=Math.max(0,this.staleIntervalMs-r.idleMs);if(n&&i===0){this.#n(e);return}this.#t.set(e.id,setTimeout(()=>this.#n(e),i))}#n(e){if(this.#t.delete(e.id),this.#o||e.status!=="running"||!e.background)return;if(this.#i?.isIdle()!==!0){this.#r.add(e.id);return}let n=this.manager.snapshot(e);this.pi.sendMessage({customType:"terminal-stale",display:!0,content:Ht(n),details:n},{triggerTurn:!0,deliverAs:"followUp"}),this.#t.set(e.id,setTimeout(()=>this.#n(e),this.staleIntervalMs))}#l(e){let n=this.#t.get(e);n!==void 0&&clearTimeout(n),this.#t.delete(e),this.#r.delete(e)}#c(e){this.#o||e.completionDelivered||(this.#a.set(e.id,e),this.#e===void 0&&(this.#e=setTimeout(()=>{this.#e=void 0;let n=[...this.#a.values()].filter(i=>!i.completionDelivered);if(this.#a.clear(),this.#o||n.length===0)return;for(let i of n)i.completionDelivered=!0;let r=n.map(i=>this.manager.snapshot(i));this.pi.sendMessage({customType:"terminal-completion",display:!0,content:Gt(r),details:{sessions:r}},{triggerTurn:!0,deliverAs:"steer"})},Wt)))}};function jt(t){return!Oe(t)||!Array.isArray(t.sessions)?[]:t.sessions.filter(_e)}a(jt,"completionSnapshots");function _e(t){return Oe(t)&&typeof t.id=="string"&&typeof t.source=="string"&&typeof t.command=="string"&&typeof t.cwd=="string"&&typeof t.shell=="string"&&typeof t.background=="boolean"&&typeof t.status=="string"&&typeof t.startedAt=="number"&&typeof t.elapsedMs=="number"&&typeof t.output=="string"}a(_e,"isTerminalSessionSnapshot");function Gt(t){return`${t.length===1?"Background terminal completed:":"Background terminals completed:"}
|
|
23
|
+
${t.map(n=>{let r=n.exitCode===void 0?"":`, exit ${n.exitCode}`,i=n.completionReason===void 0?"":`, reason ${n.completionReason}`,s=n.output.trimEnd().slice(-2e3);return`- ${n.source}: ${n.status}${r}${i}, ${De(n.elapsedMs)}
|
|
24
|
+
${s||"(no output)"}`}).join(`
|
|
25
|
+
`)}`}a(Gt,"formatCompletionMessage");function Ht(t){let e=t.output.trimEnd().slice(-2e3);return`Background terminal ${t.source} has produced no output for ${De(t.idleMs)}. Inspect it with read. If it is healthy, keep waiting; otherwise send input or stop it.
|
|
26
|
+
${e||"(no output)"}`}a(Ht,"formatStaleMessage");function De(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(t<1e4?1:0)}s`}a(De,"formatElapsed");function Oe(t){return typeof t=="object"&&t!==null}a(Oe,"isRecord");async function Bt(t){let e=ie("terminal")??new k,n=ke(),r=new C(t,e),i=ne(t).add(me(e));await Promise.all([Se(t,e),Re(t,e)]),Le(t,e,n,r),t.on("session_start",(s,o)=>r.bind(o)),t.on("agent_settled",(s,o)=>r.onAgentSettled(o)),t.on("session_shutdown",async s=>{if(r.dispose(),i(),s.reason!=="quit"){re("terminal",e);return}oe("terminal",e),await e.dispose()})}a(Bt,"registerTerminal");export{Bt as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./chunk-EI7MMDWY.js";function l(t,n){return typeof n=="string"&&n.length>0&&t.nonAnchorValues?.includes(n)!==!0}r(l,"isMutationAnchorValue");function u(t){if(typeof t.name!="string"||t.name.trim().length===0)throw new TypeError("Mutation tool name must be a non-empty string");if(typeof t.description!="string"||typeof t.mutate!="function")throw new TypeError(`Mutation tool ${t.name} has an invalid description or operation`);if(t.direct!==void 0&&(typeof t.direct.matches!="function"||typeof t.direct.execute!="function"))throw new TypeError(`Mutation tool ${t.name} has an invalid direct operation`);let n=t.intent;if(n!==void 0&&n!=="edit"&&n!=="restore")throw new TypeError(`Mutation tool ${t.name} has an invalid intent`);let o=d(t.parameters,t.name);c(o,t.source.field,`${t.name} primary source`);let a=new Set([t.source.field]);for(let e of t.source.targets??[]){if(c(o,e.field,`${t.name} target source`),!a.has(e.fallbackTo))throw new TypeError(`Mutation tool ${t.name} target ${e.field} has an unknown fallback ${e.fallbackTo}`);a.add(e.field)}let s=new Set;for(let e of t.anchors??[]){if(c(o,e.field,`${t.name} anchor`),!a.has(e.sourceField))throw new TypeError(`Mutation tool ${t.name} anchor ${e.field} has an unknown source ${e.sourceField}`);if(!Array.isArray(e.kinds)||e.kinds.length===0||e.kinds.some(i=>typeof i!="string"||i.trim().length===0))throw new TypeError(`Mutation tool ${t.name} anchor ${e.field} must accept non-empty kinds`);if(new Set(e.kinds).size!==e.kinds.length)throw new TypeError(`Mutation tool ${t.name} anchor ${e.field} declares duplicate kinds`);if(e.nonAnchorValues!==void 0&&(e.nonAnchorValues.length===0||e.nonAnchorValues.some(i=>typeof i!="string"||i.length===0)))throw new TypeError(`Mutation tool ${t.name} anchor ${e.field} must declare non-empty non-anchor values`);if(e.nonAnchorValues!==void 0&&new Set(e.nonAnchorValues).size!==e.nonAnchorValues.length)throw new TypeError(`Mutation tool ${t.name} anchor ${e.field} declares duplicate non-anchor values`);if(s.has(e.field))throw new TypeError(`Mutation tool ${t.name} declares anchor ${e.field} more than once`);s.add(e.field)}for(let e of t.pair??[])if(!s.has(e))throw new TypeError(`Mutation tool ${t.name} pair field ${e} is not an anchor`)}r(u,"assertTextMutationToolRegistration");function p(t,n){let o=n[t.source.field];return typeof o=="string"?o:""}r(p,"mutationSource");function d(t,n){let o=t.properties;if(typeof o!="object"||o===null)throw new TypeError(`Mutation tool ${n} parameters must be an object schema`);return o}r(d,"schemaProperties");function c(t,n,o){if(typeof n!="string"||n.length===0||!(n in t))throw new TypeError(`${o} field ${n} is not declared by its schema`)}r(c,"assertProperty");export{l as a,u as b,p as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./chunk-NNCZYO4Q.js";import{d as N}from"./chunk-
|
|
1
|
+
import"./chunk-NNCZYO4Q.js";import{d as N}from"./chunk-526E364R.js";import"./chunk-YHUTTZC6.js";import{a as E}from"./chunk-6CZO43OH.js";import{a as A,b}from"./chunk-OBNING2A.js";import{d as O}from"./chunk-WGGIQ7IJ.js";import"./chunk-O6LE42GK.js";import"./chunk-S3ZPXWX7.js";import{e as m,f as D,g as w,h as k,i as P,l as v}from"./chunk-NTYXZ3EL.js";import"./chunk-5VSE5X5R.js";import{a as C}from"./chunk-HKMBQLEK.js";import{a as y,b as I}from"./chunk-Z3VC3S2T.js";import"./chunk-KINKBPPX.js";import"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";import S from"node:path";var T="diagnostics",V=N({kind:"code-view",label:"Diagnostics"});async function q(c){let n,t=l((o,f,e)=>{if(n===void 0)throw new Error("IDE diagnostics are not connected");return n(o,{cwd:f,...e})},"collect"),i={protocol:y,apiVersion:4,id:"diagnostics",setup(o){n=o.readDiagnostics}},r=new WeakMap,s=new WeakMap,a=new WeakMap,d=new WeakMap,M={protocol:A,apiVersion:b,id:"diagnostics",setup(o){o.addResolver({resolver:W(t,s),renderResult:V});let f=v();o.addView({view:"diagnostics",priority:100,presenter:j(t,d)}),o.addHandler({stage:"read",when:{resolvedBy:"any",contentKind:"text"},handler(e){if(e.state?.resolvedBy==="diagnostics"){let g=e.state.content[0],u=s.get(g);return u&&r.set(e.request,u),f(e)}return e.state?.contentKind==="text"&&e.request.views?.includes("diagnostics")&&a.set(e.request,e.state.text),{kind:"continue",context:e}}}),o.addHandler({stage:"post-read",handler(e){let g=r.get(e.request);if(g&&e.result)return{kind:"continue",context:{...e,result:{...e.result,details:{...e.result.details,diagnosticCheck:g}}}};let u=a.get(e.request),h=u&&d.get(u),p=e.result,R=p?.content[0];return!h||!p||R?.type!=="text"?{kind:"continue",context:e}:{kind:"continue",context:{...e,result:{...p,content:[{...R,text:`${h}
|
|
2
2
|
${R.text}`},...p.content.slice(1)]}}}}}),o.describe('diagnostics:<path> \u2014 lint and language-server diagnostics. views: ["diagnostics"] \u2014 diagnostics alongside source text. Diagnostic sources name the actual reporting tools. Automatic notices include findings only and wake an idle agent after the notification buffer (five seconds by default); silence does not prove the file is clean. Use an explicit diagnostic read to check readiness. Pending results and snapshots are not completed checks; an empty snapshot does not prove the file is clean.'),o.addPromptGuideline("Use read with `diagnostics:<path>` or the `diagnostics` view for per-file diagnostics instead of running equivalent checks through Bash. Project builds and tests remain separate verification.")}};await Promise.all([C(c,i),E(c,M)])}l(q,"registerDiagnostics");function W(c,n){return{id:"diagnostics",tryResolve(t,i){return Promise.resolve(_(t,i.cwd,c,n,{signal:i.signal,...i.audience==="script"&&{mode:"complete"}}))}}}l(W,"createDiagnosticResolver");function _(c,n,t,i,r){let s;try{s=m(c,T,n)}catch(a){return{kind:"failed",error:a}}return s===void 0?{kind:"not-handled"}:{kind:"resolved",resource:{source:D(T,s),async read(){let a=await t(s,n,r),d=w(s,a.content,a.results);return i.set(d,d.diagnosticCheck),[d]}}}}l(_,"resolveDiagnosticSource");function j(c,n){return{id:"diagnostics",async present(t,i){if(i.purpose!=="read"||!S.isAbsolute(t.source))return t;let r=i.audience==="script"&&!i.requestedViews?.includes("diagnostics");if(r&&O(t.source))return t;let s=await c(t.source,i.cwd,{signal:i.signal,...i.audience==="script"&&{mode:r?"snapshot":"complete"}}).catch(a=>{if(i.signal?.throwIfAborted(),!r)throw a});if(s===void 0||r&&s.content!==t.content)return t;if(s.content!==t.content)throw new Error("File changed during diagnostic read; read it again for current source lines.");return n.set(t,P(s.results)),k(t,s.results)}}}l(j,"createDiagnosticPresenter");export{q as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t}from"./chunk-EI7MMDWY.js";var s=Symbol.for("pi-agent-ide.reload-resource-store");function n(){let e=globalThis,o=e[s];if(o!==void 0)return o;let r=new Map;return e[s]=r,r}t(n,"store");function u(e,o){n().set(e,o)}t(u,"retainReloadResource");function a(e){let o=n(),r=o.get(e);return o.delete(e),r}t(a,"takeReloadResource");function c(e,o){let r=n();r.get(e)===o&&r.delete(e)}t(c,"forgetReloadResource");export{u as a,a as b,c};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{a as b,d as A}from"./chunk-ITSNK5YG.js";import{a as $}from"./chunk-J4RTW44E.js";import{b as F,d as v}from"./chunk-526E364R.js";import{f as M}from"./chunk-YHUTTZC6.js";import{a as f}from"./chunk-EI7MMDWY.js";import N from"node:path";import{truncateHead as L,DEFAULT_MAX_BYTES as ee,DEFAULT_MAX_LINES as te}from"@earendil-works/pi-coding-agent";import{Text as S}from"@earendil-works/pi-tui";import{Type as O}from"typebox";import{Value as re}from"typebox/value";var _=O.Union([O.String({minLength:1}),$]),I=O.Object({before:_,after:_},{additionalProperties:!1});async function ne(e,i,c){if(!re.Check(I,i))throw Object.assign(new Error("Use before and after source strings or read request objects"),{code:"INVALID_ARGUMENTS"});let n=i,r=f(async l=>{let t=typeof l=="string"?{path:l}:l,p=await e.read(t,c,"script");if(p.isError||p.details.failure)throw Object.assign(new Error(p.details.failure?.message??"Comparison read failed"),{code:p.details.failure?.code??"READ_FAILED",details:p.details.failure});if(p.script===void 0)throw Object.assign(new Error("Source has no comparable text data"),{code:"UNSUPPORTED_CONTENT"});return B(p.script,t.path??"source")},"resolve"),a=await r(n.before),s=await r(n.after),o=b(a.source,a.content,s.content,s.source);return{kind:"diff",ok:!0,equal:a.content===s.content,before:a,after:s,...o}}f(ne,"executeDiff");function B(e,i){if(e.kind==="text")return{source:e.source,sources:[e.source],content:e.content};if(e.kind==="resources"){let c=e.resources.map(n=>B(n,i));return{source:e.source??i,sources:c.flatMap(n=>n.sources),content:c.map(n=>n.content).join(`
|
|
2
|
+
`)}}if(e.kind==="bytes")throw Object.assign(new Error(`Byte sources are not text: ${e.source}`),{code:"UNSUPPORTED_CONTENT"});if(e.blocks.length===0||e.blocks.some(c=>c.type!=="text"))throw Object.assign(new Error(`Source is not text: ${e.source}`),{code:"UNSUPPORTED_CONTENT"});return{source:e.source,sources:[e.source],content:e.blocks.flatMap(c=>c.type==="text"?[c.text]:[]).join(`
|
|
3
|
+
`)}}f(B,"comparisonText");function R(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="diff"&&"ok"in e&&e.ok===!0}f(R,"isDiffOutcome");function E(e,i=process.cwd()){let c=f(r=>N.isAbsolute(r)?N.relative(i,r)||".":r,"displaySource"),n=`Diff: ${c(e.before.source)} \u2192 ${c(e.after.source)}`;return{results:[new A({ok:!0,path:n,beforeContentMap:{[n]:e.before.content},afterContent:e.after.content,diffs:[e.diff]})]}}f(E,"diffPresentation");function T(e){return e.equal?`No differences: ${e.before.source} \u2192 ${e.after.source}`:e.diff}f(T,"diffText");function Pe(e){return{content:[{type:"text",text:T(e)}],details:{}}}f(Pe,"diffReadResult");function ke(e,i,c){e.registerTool({name:"diff",label:"Diff",parameters:I,promptSnippet:"Compare two text-readable sources without changing them",description:"Use diff to compare two sources without modifying them. before and after accept a source string or a read request {path, offset?, limit?, views?}. Use any source that read can resolve as text. Omit limit to compare complete resolved text; read presentation limits do not clip comparison inputs. Multiple resolved resources are joined with one newline separator in resolver order. Diff line numbers are relative to each selected text, not the original file when a window is selected. Native non-text content is rejected. Output uses the existing text diff and a shared output budget; oversized output has a full temporary reference. The same diff function is available inside Apply.",renderCall(n,r){return new S(r.fg("toolTitle",r.bold("Diff")),0,0)},renderResult(n,r,a,s){let o=n.details;if(o?.comparison?.equal)return new S(T(o.comparison),0,0);let l=i.getToolRenderer("diff")?.renderResult;return l?l(n,r,a,s):new S(n.content.filter(t=>t.type==="text").map(t=>t.text).join(`
|
|
4
|
+
`),0,0)},async execute(n,r,a,s,o){let l=c();if(l===void 0)throw new Error("Diff requires the read extension");let t=await ne(l,r,{cwd:o.cwd,signal:a}),p=T(t),y=L(p).truncated?await l.saveTemporary(p):void 0,d=y===void 0?"":`
|
|
5
|
+
Full diff: ${y}`;return{content:[{type:"text",text:y===void 0?p:L(p,{maxLines:te-2,maxBytes:ee-Buffer.byteLength(d)}).content+d}],details:{...E(t,o.cwd),comparison:t,temporarySource:y}}}})}f(ke,"registerDiff");import{parser as q}from"@lezer/javascript";import{TreeFragment as U}from"@lezer/common";var oe=new Set(["read","search","diff","open","createFile","deleteFile","copyFile","moveFile","apply","result"]);function V(e,i=q.parse(e)){let c=[];i.iterate({enter(r){if(r.name==="AssignmentExpression"){let t=r.node.firstChild;t?.name==="VariableName"&&c.push({name:e.slice(t.from,t.to),from:0,to:e.length})}if(r.name!=="VariableDefinition")return;let a=r.node.parent;for(;a?.parent&&!["VariableDeclaration","ParamList","Block","Script"].includes(a.name);)a=a.parent;let s=a?.name==="VariableDeclaration"&&a.firstChild?.name==="var",o=new Set(["Script","FunctionDeclaration","FunctionExpression","ArrowFunction",...s?[]:["Block"]]),l=r.node.parent;for(l?.name==="FunctionDeclaration"&&(l=l.parent);l?.parent&&!o.has(l.name);)l=l.parent;c.push({name:e.slice(r.from,r.to),from:l?.from??0,to:l?.to??e.length})}});let n=[];return i.iterate({enter(r){if(r.name!=="CallExpression")return;let a=r.node.firstChild;if(a?.name!=="VariableName")return;let s=e.slice(a.from,a.to);if(!oe.has(s)||c.some(t=>t.name===s&&t.from<=r.from&&t.to>=r.to))return;let o=r.node.getChild("ArgList")?.getChild("ObjectExpression"),l=Object.create(null);if(!o){let t=r.node.getChild("ArgList"),p=t?e.slice(t.from+1,t.to).replace(/\)$/,""):"";p&&(l.arguments={text:p.length>160?p.slice(0,120)+"\u2026":p,literal:!1})}for(let t of o?.getChildren("Property")??[]){let p=t.firstChild,y=(p?e.slice(p.from,p.to):"").replace(/^["']|["']$/g,"");if(!/^[a-zA-Z_$][\w$]*$/.test(y)){for(let Q of["path","query","target","before","after"])delete l[Q];let w=e.slice(t.from,t.to);l[`argument@${t.from}`]={text:w.length>160?w.slice(0,160)+"\u2026":w,literal:!1};continue}let d=t.lastChild;if(!d||d.type.isError||d.name===":")continue;let m=e.slice(d.from,d.to),u=m.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t"),h=/^(?:["'])(?:\d+#[0-9A-F]+|CHANGE#[0-9A-F]+|begin|end|scope-(?:begin|end)-[^"']+)["']$/.test(m);l[y]={text:u.length>160&&!h?`${u.slice(0,100)}\u2026${u.slice(-40)} (${m.length} source chars)`:u,literal:["String","Number","BooleanLiteral","Null"].includes(d.name)&&d.lastChild?.type.isError!==!0}}return n.push({name:s,from:r.from,to:r.to,path:l.path,query:l.query,target:l.target,before:l.before,after:l.after,arguments:l}),!1}}),n}f(V,"parseApplyCalls");function ie(e,i=V(e),c,n=r=>r){let r=0,a=[],s=f(o=>n(o.split(`
|
|
6
|
+
`).map(l=>l.length>200?l.slice(0,200)+"\u2026":l).join(`
|
|
7
|
+
`)),"codePreview");for(let o of i)a.push(s(e.slice(r,o.from))),a.push(c?.(o)??`${o.name}(${o.path?o.path.literal?o.path.text:`\u2039${o.path.text}\u203A`:"\u2026"})`),r=o.to;return a.push(s(e.slice(r))),a.join("")}f(ie,"compactApplySource");function J(e,i){let c="",n="",r=[];return a=>{if(a===c)return n;let s=0;for(;s<c.length&&s<a.length&&c[s]===a[s];)s++;r=U.applyChanges(r,[{fromA:s,toA:c.length,fromB:s,toB:a.length}]);let o=q.parse(a,r);return r=U.addTree(o),n=ie(a,V(a,o),e,i),c=a,n}}f(J,"createApplySourceProjection");import{lstat as G,unlink as ae}from"node:fs/promises";import Y from"node:path";import z from"fs-extra";import{Type as x}from"typebox";import{Value as se}from"typebox/value";var P=x.String({minLength:1,description:"Local regular file path, relative to cwd or absolute."}),le=x.Object({path:P},{additionalProperties:!1}),ce=x.Object({path:P,target:P,overwrite:x.Optional(x.Boolean({description:"Allow replacing an existing regular target file. Defaults to false."}))},{additionalProperties:!1});function k(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="file-operation"}f(k,"isFileOperationResult");function D(e){return[`${e.operation}: ${e.effect}`,e.path,e.target===void 0?void 0:`Target: ${e.target}`,e.error===void 0?void 0:`${e.error.code}: ${e.error.message}`].filter(i=>i!==void 0).join(`
|
|
8
|
+
`)}f(D,"formatFileOperation");async function Be(e,i,c,n){let r=!1,a,s;try{let o=e==="delete"?le:ce;if(!se.Check(o,i))throw Object.assign(new Error("Invalid file operation arguments"),{code:"INVALID_ARGUMENTS"});let l=i;a=Y.resolve(c,l.path),s=l.target===void 0?void 0:Y.resolve(c,l.target),n?.throwIfAborted();let t=await pe(a);if(s!==void 0){let p=await fe(s);if(p!==void 0){if(!p.isFile()||p.isSymbolicLink())throw Object.assign(new Error("Target must be a regular file"),{code:"INVALID_FILE_TYPE"});if(a===s||t.ino===p.ino&&t.dev===p.dev)throw Object.assign(new Error("Source and target are the same file"),{code:"SAME_FILE"});if(l.overwrite!==!0)throw Object.assign(new Error("Target exists; use overwrite: true to replace it"),{code:"EEXIST"})}}return n?.throwIfAborted(),r=!0,e==="delete"?await ae(a):s!==void 0&&(e==="copy"?await z.copy(a,s,{overwrite:l.overwrite===!0,errorOnExist:!0}):await z.move(a,s,{overwrite:l.overwrite===!0})),{kind:"file-operation",operation:e,ok:!0,effect:"applied",path:a,...s===void 0?{}:{target:s}}}catch(o){return{kind:"file-operation",operation:e,ok:!1,effect:r?"unknown":"not-applied",...a===void 0?{}:{path:a},...s===void 0?{}:{target:s},error:{code:o!==null&&typeof o=="object"&&"code"in o?String(o.code):"FILE_OPERATION_FAILED",message:o instanceof Error?o.message:String(o)}}}}f(Be,"executeFileOperation");async function pe(e){let i=await G(e);if(!i.isFile()||i.isSymbolicLink())throw Object.assign(new Error("Source must be a regular file"),{code:"INVALID_FILE_TYPE"});return i}f(pe,"regularFile");async function fe(e){try{return await G(e)}catch(i){if(i!==null&&typeof i=="object"&&"code"in i&&i.code==="ENOENT")return;throw i}}f(fe,"optionalStat");import{Text as de}from"@earendil-works/pi-tui";function K(e){let i=e.select(),c=e.mutationValues().filter(ue);return i.files.map(n=>{let r=c.flatMap(o=>o.files.filter(l=>l.source===n.source).map(l=>({outcome:o,changed:l}))),a=e.mutationPresentation(n.source)?.data,s=a?.afterContent===n.after?a:void 0;return new A({ok:!0,path:n.source,files:[{path:n.source,action:n.before===null?"created":"edited"}],snapshot:{content:n.before??""},beforeContentMap:{[n.source]:n.before},afterContent:n.after??"",afterDocument:s?.afterDocument,resultPresentation:s?.resultPresentation,scopeMarkers:s?.scopeMarkers,hints:s?.hints,warnings:s?.warnings,diffStatuses:s?.diffStatuses,diffs:[b(n.source,n.before??"",n.after??"").diff],operations:r.map(({outcome:o,changed:l})=>({operation:o.operation==="remove"?"delete":o.operation,changes:l.changes.length})),formatting:s?.formatting??r.at(-1)?.changed.formatting})})}f(K,"finalApplyMutations");function ue(e){return e!==null&&typeof e=="object"&&"operation"in e&&"files"in e&&Array.isArray(e.files)&&"effect"in e}f(ue,"isMutation");import{highlightCode as Z}from"@earendil-works/pi-coding-agent";import{wrapTextWithAnsi as W,visibleWidth as X,truncateToWidth as me}from"@earendil-works/pi-tui";function rt(e,i,c,n=process.cwd()){let r=e.select(),a=[...r.automatic,...r.explicit.filter(t=>t.kind==="operation")].filter(t=>R(t.value)&&!t.value.equal),s=a.flatMap(t=>R(t.value)?[E(t.value,n)]:[]),o=new Set(a.flatMap(t=>t.presentation?.content??[]));if(r.files.length===0){let t=[...r.automatic.map(p=>p.presentation),...r.explicit.map(p=>p.kind==="operation"?p.presentation:void 0)].filter(p=>p!==void 0);return{comparisons:s,cwd:n,blocks:[...i.content.filter(p=>!o.has(p)).flatMap(p=>p.type==="text"?[{text:H(p.text),read:t.find(g=>g.content.includes(p))}]:[])]}}let l=K(e);return{...l.length>0?{mutations:{results:l}}:{},comparisons:s,cwd:n,blocks:[...r.explicit.flatMap(t=>t.kind==="operation"&&R(t.value)&&!t.value.equal?[]:k(t.value)?[{text:D(t.value)}]:t.kind==="operation"?t.presentation?.content.flatMap(p=>p.type==="text"?[{text:p.text,read:t.presentation}]:[])??[]:[{text:H(typeof t.value=="string"?t.value:t.value===void 0?"undefined":JSON.stringify(t.value,null,2))}]),...r.automatic.flatMap(({value:t,presentation:p})=>k(t)?[{text:D(t)}]:t!==null&&typeof t=="object"&&"kind"in t&&t.kind==="index-operation"?p?.content.flatMap(g=>g.type==="text"?[{text:g.text}]:[])??[]:t===null||typeof t!="object"||!("errors"in t)||!Array.isArray(t.errors)?[]:t.errors.flatMap(g=>g!==null&&typeof g=="object"&&"message"in g&&typeof g.message=="string"?[{text:g.message}]:[])),...c===void 0?[]:[{text:c instanceof Error?c.message:JSON.stringify(c)}]]}}f(rt,"createApplyDisplay");function j(e,i,c,n,r,a,s=!1){let o=Math.max(1,c);if(o<5)return e.split(`
|
|
9
|
+
`).flatMap(u=>W(u,o));let l=o-4,t=f(u=>i.fg("borderMuted",u),"border"),g=me(` ${n==="call"?"Apply \xB7 JavaScript":"Result"} `,o-4,""),y=[t(`${n==="call"?"\u256D":"\u251C"}\u2500`)+i.fg(s?"error":"accent",g)+t(`${"\u2500".repeat(Math.max(0,o-X(g)-3))}${n==="call"?"\u256E":"\u2524"}`)],d=`${t("\u2502")}${" ".repeat(o-2)}${t("\u2502")}`;for(let u of e.split(`
|
|
10
|
+
`)){let h=a==="diff"?i.fg(u.startsWith("+")?"toolDiffAdded":u.startsWith("-")?"toolDiffRemoved":"toolDiffContext",u):a?Z(u,a).join(`
|
|
11
|
+
`):i.fg("toolOutput",u);for(let w of W(h,l))y.push(`${t("\u2502")} ${w}${" ".repeat(Math.max(0,l-X(w)))} ${t("\u2502")}`)}n==="call"&&y.push(d),r&&y.push(t(`\u2570${"\u2500".repeat(o-2)}\u256F`));let m=i.getBgAnsi("toolPendingBg");return y.map(u=>m+M(u,m)+"\x1B[0m")}f(j,"applyFrameRows");function ge(e){return(i,c,n)=>{let r=n.state,a=r.projectSource??=J(e?o=>e(o,c):void 0,e?o=>Z(o,"javascript").join(`
|
|
12
|
+
`):void 0),s=i!==null&&typeof i=="object"&&"source"in i&&typeof i.source=="string"?i.source:"";return{invalidate(){},render(o){return j(r.codeView||n.expanded?r.displaySource??s:ye(a(r.displaySource??s)),c,o,"call",!r.applyResultReady,r.codeView||n.expanded||!e?"javascript":void 0)}}}}f(ge,"createApplyCallRenderer");function ye(e,i=F){let c=e.split(`
|
|
13
|
+
`);if(c.length<=i)return e;let n=Math.max(2,i-1),r=Math.ceil(n/2),a=Math.floor(n/2),s=c.length-r-a;return[...c.slice(0,r),`\u2026 ${s} lines omitted \u2026`,...c.slice(-a)].join(`
|
|
14
|
+
`)}f(ye,"compactApplyPreview");var nt=ge();function he(e){return(i,c,n,r)=>{r.state.applyResultReady=!0;let a=i.details;r.state.displaySource=a?.displaySource;let s=a?.display,o=s?.blocks??[{text:r.isError?"Apply failed":"Apply finished"}],l=v({kind:"source"}),t=o.map(d=>l(d.read??{content:[{type:"text",text:d.text}],details:we(d.text)},c,n,{...r,isError:!1,lastComponent:void 0})),p=s?.mutations,g=(s?.comparisons??[]).flatMap(d=>[e?.(d,n,c.expanded,s?.cwd??process.cwd())??new de((d.results??[]).flatMap(u=>u.data.diffs??[]).join(`
|
|
15
|
+
`),0,0)]),y=p===void 0?void 0:e?.(p,n,c.expanded,s?.cwd??process.cwd());return{invalidate(){y?.invalidate();for(let d of g)d.invalidate()},render(d){let m=[];for(let u of t){let h=u.render(Math.max(1,d-4));h.length!==0&&(m.length>0&&m.push(""),m.push(...h))}for(let u of g)m.length>0&&m.push(""),m.push(...u.render(Math.max(1,d-4)));if(y!==void 0){let u=y.render(Math.max(1,d-4));m.length>0&&u.length>0&&m.push(""),m.push(...u)}else p!==void 0&&m.push(...(p.results??[]).map(u=>u.path??"Changed file"));return m.length===0&&o.length>0&&o.every(u=>u.read?.details.diagnosticCheck?.complete&&u.read.details.diagnosticCheck.count===0)?j("",n,d,"result",!0).slice(-1):j(m.length===0?"No output":m.join(`
|
|
16
|
+
`),n,d,"result",!0,void 0,r.isError)}}}}f(he,"createApplyResultRenderer");function H(e){if(/^(?:Undo transaction:|Undo available)/u.test(e.trim()))return"";try{let i=JSON.parse(e);return JSON.stringify(C(i),null,2)}catch{return e.replace(/APPLY#[0-9A-F]{12}/gu,"Apply transaction")}}f(H,"redactApplyReceipts");function C(e){return Array.isArray(e)?e.map(C):e===null||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([i])=>i!=="transaction").map(([i,c])=>[i,C(c)]))}f(C,"redactTransactionKeys");function we(e){try{let i=JSON.parse(e);return i!==null&&typeof i=="object"?{source:"result.json"}:{}}catch{return{}}}f(we,"jsonDetails");var ot=he();export{ne as a,Pe as b,ke as c,Be as d,K as e,rt as f,ge as g,nt as h,he as i,ot as j};
|