pi-agent-ide 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +7 -7
  3. package/dist/chunk-25CZ5ZIU.js +3 -0
  4. package/dist/chunk-526E364R.js +3 -0
  5. package/dist/chunk-5PLV4HLG.js +1 -0
  6. package/dist/chunk-5QQABP47.js +14 -0
  7. package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
  8. package/dist/chunk-AWXVJ5AC.js +1 -0
  9. package/dist/chunk-BGUSBUUD.js +26 -0
  10. package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
  11. package/dist/chunk-ESPNEJHK.js +1 -0
  12. package/dist/chunk-G725MARR.js +16 -0
  13. package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
  14. package/dist/chunk-IQD6PON5.js +0 -0
  15. package/dist/chunk-J4RTW44E.js +1 -0
  16. package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
  17. package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
  18. package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
  19. package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
  20. package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
  21. package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
  22. package/dist/chunk-QH4ZUDOD.js +1 -0
  23. package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
  24. package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
  25. package/dist/chunk-U2JKHKLK.js +0 -0
  26. package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.js} +1 -1
  27. package/dist/chunk-ZG2MWXCR.js +2 -0
  28. package/dist/chunk-ZUMN6U77.js +27 -0
  29. package/dist/entry-10.js +1 -1
  30. package/dist/entry-11.js +1 -1
  31. package/dist/entry-12.js +1 -1
  32. package/dist/entry-13.js +1 -1
  33. package/dist/entry-14.js +1 -1
  34. package/dist/entry-15.js +1 -0
  35. package/dist/entry-17.js +1 -1
  36. package/dist/entry-18.js +1 -1
  37. package/dist/entry-19.js +1 -1
  38. package/dist/entry-20.js +1 -1
  39. package/dist/entry-21.js +1 -2
  40. package/dist/entry-22.js +2 -1
  41. package/dist/entry-23.js +1 -1
  42. package/dist/entry-24.js +1 -1
  43. package/dist/entry-25.js +1 -1
  44. package/dist/entry-26.js +1 -12
  45. package/dist/entry-27.js +12 -1
  46. package/dist/entry-28.js +1 -1
  47. package/dist/entry-29.js +1 -1
  48. package/dist/entry-30.js +1 -1
  49. package/dist/entry-31.js +1 -4
  50. package/dist/entry-32.js +3 -8
  51. package/dist/entry-33.js +9 -1
  52. package/dist/entry-34.js +1 -1
  53. package/dist/entry-35.js +1 -1
  54. package/dist/entry-36.js +1 -1
  55. package/dist/entry-37.js +1 -1
  56. package/dist/entry-38.js +1 -1
  57. package/dist/entry-39.js +1 -1
  58. package/dist/entry-40.js +1 -18
  59. package/dist/entry-41.js +18 -1
  60. package/dist/entry-42.js +1 -1
  61. package/dist/entry-43.js +1 -1
  62. package/dist/entry-44.js +1 -1
  63. package/dist/entry-45.js +1 -7
  64. package/dist/entry-46.js +7 -11
  65. package/dist/entry-47.js +11 -1
  66. package/dist/entry-48.js +1 -1
  67. package/dist/entry-49.js +1 -1
  68. package/dist/entry-50.js +1 -1
  69. package/dist/entry-51.js +1 -1
  70. package/dist/entry-52.js +1 -1
  71. package/dist/entry-53.js +1 -1
  72. package/dist/entry-54.js +1 -1
  73. package/dist/entry-55.js +1 -0
  74. package/dist/entry-56.js +0 -1
  75. package/dist/entry-57.js +1 -0
  76. package/dist/entry-58.js +0 -1
  77. package/dist/entry-59.js +1 -1
  78. package/dist/entry-60.js +1 -1
  79. package/dist/entry-61.js +1 -1
  80. package/dist/entry-62.js +1 -1
  81. package/dist/entry-63.js +1 -1
  82. package/dist/entry-64.js +1 -0
  83. package/dist/entry-65.js +0 -1
  84. package/dist/entry-66.js +1 -0
  85. package/dist/entry-67.js +0 -1
  86. package/dist/entry-68.js +1 -1
  87. package/dist/entry-69.js +1 -1
  88. package/dist/entry-70.js +1 -123
  89. package/dist/entry-71.js +198 -25
  90. package/dist/entry-72.js +30 -2
  91. package/dist/entry-73.js +2 -1
  92. package/dist/entry-74.js +1 -1
  93. package/dist/entry-75.js +1 -1
  94. package/dist/entry-76.js +1 -3
  95. package/dist/entry-77.js +3 -1
  96. package/dist/entry-78.js +1 -1
  97. package/dist/entry-79.js +1 -1
  98. package/dist/entry-8.js +1 -1
  99. package/dist/entry-80.js +1 -0
  100. package/dist/entry-9.js +1 -1
  101. package/dist/pi-agent-ide.js +3 -3
  102. package/docs/configuration.md +1 -1
  103. package/docs/user-hooks.md +68 -0
  104. package/node_modules/pi-agent-doctor/package.json +6 -6
  105. package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
  106. package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
  107. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -0
  108. package/node_modules/pi-agent-filesystem/package.json +7 -7
  109. package/node_modules/pi-agent-filesystem-image/package.json +4 -4
  110. package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
  111. package/node_modules/pi-agent-filesystem-text/package.json +4 -4
  112. package/node_modules/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  113. package/node_modules/pi-agent-ide-ast/package.json +32 -11
  114. package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  115. package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  116. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  117. package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  118. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  119. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  120. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  121. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  122. package/node_modules/pi-agent-ide-changes/index.ts +3 -1
  123. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  124. package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  125. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  126. package/node_modules/pi-agent-ide-formatter/package.json +9 -4
  127. package/node_modules/pi-agent-ide-languages/package.json +3 -3
  128. package/node_modules/pi-agent-ide-lint/package.json +13 -8
  129. package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
  130. package/node_modules/pi-agent-ide-lsp/package.json +15 -10
  131. package/node_modules/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  132. package/node_modules/pi-agent-image/package.json +3 -3
  133. package/node_modules/pi-agent-invariant/package.json +2 -2
  134. package/node_modules/pi-agent-pdf/package.json +3 -3
  135. package/node_modules/pi-agent-read/package.json +11 -11
  136. package/node_modules/pi-agent-read/runtime/entry-40.js +0 -1
  137. package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
  138. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  139. package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
  140. package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
  141. package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
  142. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  143. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  144. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  145. package/node_modules/pi-agent-resource/package.json +2 -2
  146. package/node_modules/pi-agent-search/package.json +7 -7
  147. package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
  148. package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
  149. package/node_modules/pi-agent-search-text/index.ts +1 -1
  150. package/node_modules/pi-agent-search-text/package.json +9 -9
  151. package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
  152. package/node_modules/pi-agent-search-text/src/resolvers.ts +47 -19
  153. package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
  154. package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
  155. package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
  156. package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
  157. package/node_modules/pi-agent-search-text/src/search-session.ts +6 -3
  158. package/node_modules/pi-agent-text/package.json +3 -3
  159. package/node_modules/pi-agent-text/runtime/entry-49.js +1 -0
  160. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  161. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  162. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  163. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  164. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  165. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  166. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  167. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  168. package/node_modules/pi-agent-text-editor/package.json +25 -25
  169. package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
  170. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  171. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  172. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  173. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  174. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  175. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  176. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  177. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  178. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  179. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  180. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  181. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  182. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  183. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  184. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  185. package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
  186. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  187. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  188. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  189. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  190. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  191. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  192. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  195. package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
  196. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  197. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  198. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  199. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  200. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  201. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  202. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +1 -0
  203. package/node_modules/pi-agent-web/package.json +7 -7
  204. package/node_modules/pi-agent-web-html/package.json +3 -3
  205. package/node_modules/pi-agent-web-image/package.json +4 -4
  206. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  207. package/node_modules/pi-agent-web-text/package.json +4 -4
  208. package/node_modules/pi-agent-web-text/runtime/entry-80.js +2 -0
  209. package/package.json +58 -38
  210. package/src/api/hooks.ts +168 -0
  211. package/src/api/text-editor.ts +2 -0
  212. package/src/composite/builtin-extensions.ts +7 -0
  213. package/src/composite/module-labels.ts +8 -0
  214. package/src/composite/preferences.ts +3 -3
  215. package/src/core/reload-resource-store.ts +34 -0
  216. package/src/doctor/tip-provider.ts +1 -0
  217. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  218. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
  219. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
  220. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
  221. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  222. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +2 -0
  223. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  224. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +2 -0
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
  230. package/src/extensions/pi-agent-read/package.json +11 -11
  231. package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
  232. package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
  233. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  234. package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
  235. package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
  236. package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
  237. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  238. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  239. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  240. package/src/extensions/pi-agent-search/package.json +7 -7
  241. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  242. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
  243. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
  244. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
  245. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +47 -19
  246. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
  247. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
  248. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
  249. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
  250. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +6 -3
  251. package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
  252. package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
  253. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
  254. package/src/extensions/pi-agent-text-editor/package.json +25 -25
  255. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  256. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  257. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  258. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  259. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  260. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  261. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  262. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -0
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  268. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
  269. package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
  270. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  271. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  272. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  273. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  274. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  275. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  276. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  277. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  278. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  279. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  280. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  281. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  282. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  283. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  284. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  285. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
  286. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  287. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  288. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  289. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  290. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  291. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  292. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  293. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  294. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  295. package/src/plugins/pi-agent-ide-ast/package.json +32 -11
  296. package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  297. package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  298. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  299. package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  300. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  301. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  302. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  303. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  304. package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
  305. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  306. package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  307. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  308. package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
  309. package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
  310. package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
  311. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
  312. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
  313. package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
  314. package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
  315. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
  316. package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
  317. package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
  318. package/src/plugins/pi-agent-ide-languages/package.json +3 -3
  319. package/src/plugins/pi-agent-ide-lint/package.json +13 -8
  320. package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
  321. package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
  322. package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  323. package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
  324. package/src/plugins/pi-agent-ide-processes/src/registry.ts +81 -0
  325. package/src/plugins/pi-agent-ide-processes/src/ui.ts +252 -0
  326. package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
  327. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
  328. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +30 -0
  329. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
  330. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
  331. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
  332. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
  333. package/src/plugins/pi-agent-ide-terminal/src/types.ts +13 -1
  334. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
  335. package/dist/chunk-3SE372WC.js +0 -3
  336. package/dist/chunk-5MSNYFDE.js +0 -1
  337. package/dist/chunk-7JYQMAEL.js +0 -14
  338. package/dist/chunk-B5KB2I7J.js +0 -3
  339. package/dist/chunk-NMFQGKPE.js +0 -2
  340. package/dist/chunk-OVUYPHDE.js +0 -1
  341. package/dist/chunk-TPIHQYK2.js +0 -14
  342. package/dist/chunk-XSTHESNR.js +0 -25
  343. package/dist/entry-16.js +0 -1
  344. package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
  345. package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
  346. package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  347. package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  348. package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
  349. package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
  350. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  351. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  352. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  353. package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
  354. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
  355. package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
  356. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
  357. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
  358. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
  359. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
  360. package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
  361. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
  362. package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
  363. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  364. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  365. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  366. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
  367. package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
  368. package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  369. package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  370. /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
  371. /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
  372. /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
  373. /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  374. /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  375. /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  376. /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
  377. /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
  378. /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
  379. /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
  380. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
  381. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
  382. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
  383. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
  384. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
  385. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
  386. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
  387. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
  388. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
  389. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
  390. /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
  391. /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
  392. /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
  393. /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
  394. /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
  395. /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
  396. /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  397. /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  398. /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  399. /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
@@ -1,23 +1,7 @@
1
- import {
2
- DynamicBorder,
3
- type ExtensionAPI,
4
- type ExtensionContext,
5
- } from "@earendil-works/pi-coding-agent";
6
- import {
7
- Box,
8
- Container,
9
- Key,
10
- matchesKey,
11
- SelectList,
12
- Text,
13
- truncateToWidth,
14
- type SelectItem,
15
- } from "@earendil-works/pi-tui";
1
+ import { Box, Container } from "@earendil-works/pi-tui";
2
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
16
3
 
17
- import {
18
- renderTerminalResult,
19
- renderTerminalWidgetLines,
20
- } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
4
+ import { renderTerminalResult } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
21
5
  import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
22
6
  import type {
23
7
  TerminalSession,
@@ -25,65 +9,134 @@ import type {
25
9
  } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
26
10
 
27
11
  const COMPLETION_DELAY_MS = 120;
12
+ const DEFAULT_STALE_INTERVAL_MS = 120_000;
28
13
 
29
- /** Keeps background terminal status and completion rendering separate from agent result data. */
14
+ /** Delivers background terminal completion messages separately from the shared process UI. */
30
15
  export class TerminalUi {
31
16
  readonly #pending = new Map<string, TerminalSession>();
32
- #context: ExtensionContext | undefined;
33
17
  #deliveryTimer: ReturnType<typeof setTimeout> | undefined;
34
- #elapsedTimer: ReturnType<typeof setInterval> | undefined;
18
+ readonly #staleTimers = new Map<string, ReturnType<typeof setTimeout>>();
19
+ readonly #overdue = new Set<string>();
20
+ #context: ExtensionContext | undefined;
35
21
  #closed = false;
22
+ readonly #removeManagerListeners: readonly (() => void)[];
36
23
 
37
- public constructor(
24
+ constructor(
38
25
  private readonly pi: ExtensionAPI,
39
26
  private readonly manager: TerminalSessionManager,
40
- private readonly activityMode: "detailed" | "compact" | "off",
27
+ private readonly staleIntervalMs = DEFAULT_STALE_INTERVAL_MS,
41
28
  ) {
29
+ pi.registerMessageRenderer("terminal-stale", (message, { expanded }, theme) => {
30
+ const snapshot = isTerminalSessionSnapshot(message.details) ? message.details : undefined;
31
+ const content = new Container();
32
+ if (snapshot !== undefined)
33
+ content.addChild(
34
+ renderTerminalResult(snapshot, expanded, theme, "stale · inspect session"),
35
+ );
36
+ const card = new Box(1, 1, (line) => theme.bg("toolPendingBg", line));
37
+ card.addChild(content);
38
+ return card;
39
+ });
42
40
  pi.registerMessageRenderer("terminal-completion", (message, { expanded }, theme) => {
43
41
  const content = new Container();
44
- for (const session of completionSnapshots(message.details)) {
42
+ for (const session of completionSnapshots(message.details))
45
43
  content.addChild(renderTerminalResult(session, expanded, theme));
46
- }
47
44
  const card = new Box(1, 1, (line) => theme.bg("toolSuccessBg", line));
48
45
  card.addChild(content);
49
46
  return card;
50
47
  });
48
+ this.#removeManagerListeners = [
49
+ manager.onDidChange((session) => this.#refreshStaleTimer(session)),
50
+ manager.onDidComplete((session) => {
51
+ this.#clearStaleTimer(session.id);
52
+ if (session.background) this.#queueCompletion(session);
53
+ }),
54
+ ];
55
+ }
51
56
 
52
- manager.onDidChange(() => this.#renderActive());
53
- manager.onDidComplete((session) => {
54
- if (session.background) this.#queueCompletion(session);
55
- this.#renderActive();
56
- });
57
-
58
- pi.registerCommand("terminals", {
59
- description: "Show active and recent terminal sessions",
60
- handler: async (_args, context) => {
61
- this.bind(context);
62
- if (context.mode !== "tui") {
63
- context.ui.notify("The terminal session overlay requires the TUI.", "info");
64
- return;
65
- }
66
- await this.#showOverlay(context);
67
- },
68
- });
57
+ bind(context: ExtensionContext): void {
58
+ this.#context = context;
69
59
  }
70
60
 
71
- public bind(context: ExtensionContext): void {
72
- if (this.#closed) return;
61
+ /** Deliver deferred stale notices after Pi has fully settled. */
62
+ onAgentSettled(context: ExtensionContext): void {
73
63
  this.#context = context;
74
- this.#renderActive();
64
+ for (const id of [...this.#overdue]) {
65
+ this.#overdue.delete(id);
66
+ const session = this.manager.get(id);
67
+ if (session !== undefined) this.#refreshStaleTimer(session, true);
68
+ }
75
69
  }
76
70
 
77
- public dispose(): void {
71
+ /** Notify the agent when an aborted tool result may no longer be deliverable. */
72
+ notifyWaitTransition(session: TerminalSession): void {
73
+ const snapshot = this.manager.snapshot(session);
74
+ this.pi.sendMessage(
75
+ {
76
+ customType: "terminal-wait-transition",
77
+ display: false,
78
+ content: `Terminal wait aborted; ${snapshot.source} is still running in background. Read it to inspect output, then use write or insert to send input.`,
79
+ details: snapshot,
80
+ },
81
+ { triggerTurn: true, deliverAs: "steer" },
82
+ );
83
+ }
84
+
85
+ dispose(): void {
78
86
  this.#closed = true;
79
87
  if (this.#deliveryTimer !== undefined) clearTimeout(this.#deliveryTimer);
80
- if (this.#elapsedTimer !== undefined) clearInterval(this.#elapsedTimer);
81
88
  this.#deliveryTimer = undefined;
82
- this.#elapsedTimer = undefined;
83
- this.#context?.ui.setWidget("agent-terminal", undefined);
84
- this.#context?.ui.setStatus("agent-terminal", undefined);
85
89
  this.#pending.clear();
90
+ for (const timer of this.#staleTimers.values()) clearTimeout(timer);
91
+ this.#staleTimers.clear();
92
+ this.#overdue.clear();
86
93
  this.#context = undefined;
94
+ for (const removeListener of this.#removeManagerListeners) removeListener();
95
+ }
96
+
97
+ #refreshStaleTimer(session: TerminalSession, checkNow = false): void {
98
+ this.#clearStaleTimer(session.id);
99
+ if (this.#closed || !session.background || session.status !== "running") return;
100
+ const snapshot = this.manager.snapshot(session);
101
+ const remaining = Math.max(0, this.staleIntervalMs - snapshot.idleMs);
102
+ if (checkNow && remaining === 0) {
103
+ this.#handleStale(session);
104
+ return;
105
+ }
106
+ this.#staleTimers.set(
107
+ session.id,
108
+ setTimeout(() => this.#handleStale(session), remaining),
109
+ );
110
+ }
111
+
112
+ #handleStale(session: TerminalSession): void {
113
+ this.#staleTimers.delete(session.id);
114
+ if (this.#closed || session.status !== "running" || !session.background) return;
115
+ if (this.#context?.isIdle() !== true) {
116
+ this.#overdue.add(session.id);
117
+ return;
118
+ }
119
+ const snapshot = this.manager.snapshot(session);
120
+ this.pi.sendMessage(
121
+ {
122
+ customType: "terminal-stale",
123
+ display: true,
124
+ content: formatStaleMessage(snapshot),
125
+ details: snapshot,
126
+ },
127
+ { triggerTurn: true, deliverAs: "followUp" },
128
+ );
129
+ this.#staleTimers.set(
130
+ session.id,
131
+ setTimeout(() => this.#handleStale(session), this.staleIntervalMs),
132
+ );
133
+ }
134
+
135
+ #clearStaleTimer(id: string): void {
136
+ const timer = this.#staleTimers.get(id);
137
+ if (timer !== undefined) clearTimeout(timer);
138
+ this.#staleTimers.delete(id);
139
+ this.#overdue.delete(id);
87
140
  }
88
141
 
89
142
  #queueCompletion(session: TerminalSession): void {
@@ -93,198 +146,29 @@ export class TerminalUi {
93
146
  this.#deliveryTimer = setTimeout(() => {
94
147
  this.#deliveryTimer = undefined;
95
148
  const sessions = [...this.#pending.values()].filter(
96
- (session) => !session.completionDelivered,
149
+ (candidate) => !candidate.completionDelivered,
97
150
  );
98
151
  this.#pending.clear();
99
152
  if (this.#closed || sessions.length === 0) return;
100
153
  for (const completed of sessions) completed.completionDelivered = true;
101
154
  const snapshots = sessions.map((completed) => this.manager.snapshot(completed));
102
- const content = formatCompletionMessage(snapshots);
103
155
  this.pi.sendMessage(
104
156
  {
105
157
  customType: "terminal-completion",
106
158
  display: true,
107
- content,
159
+ content: formatCompletionMessage(snapshots),
108
160
  details: { sessions: snapshots },
109
161
  },
110
162
  { triggerTurn: true, deliverAs: "steer" },
111
163
  );
112
164
  }, COMPLETION_DELAY_MS);
113
165
  }
114
-
115
- #renderActive(): void {
116
- const context = this.#context;
117
- if (this.#closed || context === undefined || !context.hasUI) return;
118
- const active = this.manager
119
- .list()
120
- .filter((session) => session.status === "running" || session.status === "stopping");
121
- if (this.activityMode === "off") {
122
- context.ui.setWidget("agent-terminal", undefined);
123
- context.ui.setStatus("agent-terminal", undefined);
124
- return;
125
- }
126
- if (active.length === 0) {
127
- context.ui.setWidget("agent-terminal", undefined);
128
- context.ui.setStatus("agent-terminal", undefined);
129
- if (this.#elapsedTimer !== undefined) clearInterval(this.#elapsedTimer);
130
- this.#elapsedTimer = undefined;
131
- return;
132
- }
133
- if (this.activityMode === "compact") {
134
- context.ui.setWidget("agent-terminal", undefined);
135
- context.ui.setStatus("agent-terminal", `terminals: ${active.length}`);
136
- return;
137
- }
138
- context.ui.setStatus("agent-terminal", undefined);
139
- context.ui.setWidget(
140
- "agent-terminal",
141
- (_tui, theme) => ({
142
- invalidate() {},
143
- render: (width: number) => renderTerminalWidgetLines(active, width, theme),
144
- }),
145
- { placement: "belowEditor" },
146
- );
147
- if (this.#elapsedTimer === undefined) {
148
- this.#elapsedTimer = setInterval(() => this.#renderActive(), 1_000);
149
- }
150
- }
151
-
152
- async #showOverlay(context: ExtensionContext): Promise<void> {
153
- for (;;) {
154
- const sessions = this.manager
155
- .list()
156
- .filter((session) => session.status === "running" || session.status === "stopping");
157
- if (sessions.length === 0) {
158
- context.ui.notify("No active terminal sessions.", "info");
159
- return;
160
- }
161
- const action = await context.ui.custom<TerminalOverlayAction | null>(
162
- (tui, theme, _keybindings, done) => {
163
- const items: SelectItem[] = sessions.map((session) => ({
164
- value: session.source,
165
- label: `${session.status} ${formatElapsed(session.elapsedMs)} ${session.shell}`,
166
- description: shortCommand(session.command, 90),
167
- }));
168
- const list = new SelectList(items, Math.min(items.length, 12), {
169
- selectedPrefix: (text) => theme.fg("accent", text),
170
- selectedText: (text) => theme.fg("accent", text),
171
- description: (text) => theme.fg("muted", text),
172
- scrollInfo: (text) => theme.fg("dim", text),
173
- noMatch: (text) => theme.fg("warning", text),
174
- });
175
- let page: "list" | "detail" | "confirm" = "list";
176
- let selectedSource: string | undefined;
177
- list.onSelect = (item) => {
178
- selectedSource = item.value;
179
- page = "detail";
180
- };
181
- list.onCancel = () => done(null);
182
- return {
183
- render: (width: number) => {
184
- const container = new Container();
185
- container.addChild(new DynamicBorder((text: string) => theme.fg("accent", text)));
186
- if (page === "list") {
187
- container.addChild(
188
- new Text(theme.fg("accent", theme.bold("Terminal sessions")), 1, 0),
189
- );
190
- container.addChild(list);
191
- container.addChild(
192
- new Text(theme.fg("dim", "enter view · d delete · esc close"), 1, 0),
193
- );
194
- } else {
195
- const session =
196
- selectedSource === undefined ? undefined : this.manager.get(selectedSource);
197
- if (session === undefined) {
198
- container.addChild(
199
- new Text(theme.fg("warning", "Terminal is no longer available."), 1, 0),
200
- );
201
- } else {
202
- const snapshot = this.manager.snapshot(session);
203
- container.addChild(
204
- new Text(theme.fg("accent", theme.bold(`${snapshot.shell} terminal`)), 1, 0),
205
- );
206
- container.addChild(
207
- new Text(
208
- theme.fg(
209
- "muted",
210
- truncateToWidth(
211
- `${snapshot.status} · ${formatElapsed(snapshot.elapsedMs)} · ${snapshot.cwd}`,
212
- Math.max(1, width - 2),
213
- ),
214
- ),
215
- 1,
216
- 0,
217
- ),
218
- );
219
- container.addChild(new Text(theme.fg("text", `$ ${snapshot.command}`), 1, 0));
220
- const rows = visibleScreenTail(this.manager.screenRows(session), 24);
221
- container.addChild(
222
- new Text(
223
- rows.map((row) => theme.fg("toolOutput", row || " ")).join("\n"),
224
- 1,
225
- 0,
226
- ),
227
- );
228
- container.addChild(
229
- new Text(
230
- theme.fg(
231
- page === "confirm" ? "warning" : "dim",
232
- page === "confirm"
233
- ? "Delete this terminal session? y confirm · n/esc cancel"
234
- : "esc back · d delete",
235
- ),
236
- 1,
237
- 0,
238
- ),
239
- );
240
- }
241
- }
242
- container.addChild(new DynamicBorder((text: string) => theme.fg("accent", text)));
243
- return container.render(width);
244
- },
245
- handleInput: (data: string) => {
246
- if (page === "list") {
247
- if (data === "d") {
248
- selectedSource = list.getSelectedItem()?.value;
249
- if (selectedSource !== undefined) page = "confirm";
250
- } else {
251
- list.handleInput(data);
252
- }
253
- } else if (page === "detail") {
254
- if (matchesKey(data, Key.escape)) page = "list";
255
- else if (data === "d") page = "confirm";
256
- } else if (data === "y" && selectedSource !== undefined) {
257
- done({ kind: "delete", source: selectedSource });
258
- } else if (data === "n" || matchesKey(data, Key.escape)) {
259
- page = "detail";
260
- }
261
- tui.requestRender();
262
- },
263
- invalidate: () => list.invalidate(),
264
- };
265
- },
266
- { overlay: true, overlayOptions: { width: "75%", maxHeight: "80%", minWidth: 52 } },
267
- );
268
- if (action === null) return;
269
- await this.manager.delete(action.source);
270
- context.ui.notify("Terminal session deleted.", "info");
271
- }
272
- }
273
166
  }
274
167
 
275
- function visibleScreenTail(rows: readonly string[], limit: number): readonly string[] {
276
- const first = rows.findIndex((row) => row.length > 0);
277
- if (first === -1) return ["(no visible output)"];
278
- let last = rows.length - 1;
279
- while (last > first && rows[last]?.length === 0) last -= 1;
280
- return rows.slice(Math.max(first, last - limit + 1), last + 1);
281
- }
282
- type TerminalOverlayAction = { readonly kind: "delete"; readonly source: string };
283
168
  function completionSnapshots(details: unknown): readonly TerminalSessionSnapshot[] {
284
169
  if (!isRecord(details) || !Array.isArray(details.sessions)) return [];
285
170
  return details.sessions.filter(isTerminalSessionSnapshot);
286
171
  }
287
-
288
172
  function isTerminalSessionSnapshot(value: unknown): value is TerminalSessionSnapshot {
289
173
  return (
290
174
  isRecord(value) &&
@@ -293,44 +177,36 @@ function isTerminalSessionSnapshot(value: unknown): value is TerminalSessionSnap
293
177
  typeof value.command === "string" &&
294
178
  typeof value.cwd === "string" &&
295
179
  typeof value.shell === "string" &&
296
- (value.shellFamily === "posix" ||
297
- value.shellFamily === "powershell" ||
298
- value.shellFamily === "cmd") &&
299
180
  typeof value.background === "boolean" &&
300
181
  typeof value.status === "string" &&
301
182
  typeof value.startedAt === "number" &&
302
183
  typeof value.elapsedMs === "number" &&
303
- typeof value.output === "string" &&
304
- typeof value.outputStart === "number" &&
305
- typeof value.outputEnd === "number" &&
306
- typeof value.truncated === "boolean" &&
307
- typeof value.cols === "number" &&
308
- typeof value.rows === "number"
184
+ typeof value.output === "string"
309
185
  );
310
186
  }
311
-
312
187
  function formatCompletionMessage(sessions: readonly TerminalSessionSnapshot[]): string {
313
188
  const heading =
314
189
  sessions.length === 1 ? "Background terminal completed:" : "Background terminals completed:";
315
190
  return `${heading}\n${sessions
316
191
  .map((session) => {
317
192
  const exit = session.exitCode === undefined ? "" : `, exit ${session.exitCode}`;
193
+ const reason =
194
+ session.completionReason === undefined ? "" : `, reason ${session.completionReason}`;
318
195
  const excerpt = session.output.trimEnd().slice(-2_000);
319
- return `- ${session.source}: ${session.status}${exit}, ${formatElapsed(session.elapsedMs)}\n${excerpt || "(no output)"}`;
196
+ return `- ${session.source}: ${session.status}${exit}${reason}, ${formatElapsed(session.elapsedMs)}\n${excerpt || "(no output)"}`;
320
197
  })
321
198
  .join("\n")}`;
322
199
  }
323
-
324
- function shortCommand(command: string, max = 60): string {
325
- const singleLine = command.replaceAll(/\s+/gu, " ").trim();
326
- return singleLine.length <= max ? singleLine : `${singleLine.slice(0, max - 1)}…`;
200
+ function formatStaleMessage(session: TerminalSessionSnapshot): string {
201
+ const excerpt = session.output.trimEnd().slice(-2_000);
202
+ return `Background terminal ${session.source} has produced no output for ${formatElapsed(session.idleMs)}. Inspect it with read. If it is healthy, keep waiting; otherwise send input or stop it.\n${excerpt || "(no output)"}`;
327
203
  }
328
204
 
329
205
  function formatElapsed(milliseconds: number): string {
330
- if (milliseconds < 1_000) return `${milliseconds}ms`;
331
- return `${(milliseconds / 1_000).toFixed(milliseconds < 10_000 ? 1 : 0)}s`;
206
+ return milliseconds < 1_000
207
+ ? `${milliseconds}ms`
208
+ : `${(milliseconds / 1_000).toFixed(milliseconds < 10_000 ? 1 : 0)}s`;
332
209
  }
333
-
334
210
  function isRecord(value: unknown): value is Record<string, unknown> {
335
211
  return typeof value === "object" && value !== null;
336
212
  }
@@ -1,3 +0,0 @@
1
- import{c as M}from"./chunk-YHUTTZC6.js";import{i as b,o as k,t as w,u as T}from"./chunk-5VSE5X5R.js";import{a as R}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";function me(e,n){let{lines:t,truncation:r,...i}=e,o=t?.map(d=>{let l=[d.lineNumber,w(d.content,n),d.lineEnding];return(d.presentation!==void 0||d.metadata!==void 0)&&l.push(d.presentation),d.metadata!==void 0&&l.push(d.metadata),l}),{content:s,...u}=r??{};return{...i,...o===void 0?{}:{storedLines:o},...r===void 0?{}:{truncation:u,truncatedText:w(s??"",n)}}}a(me,"compactReadDetails");function P(e,n){let t=e;if(t.storedLines===void 0&&t.truncatedText===void 0)return e;let{storedLines:r,truncatedText:i,truncation:o,...s}=t;return{...s,...r===void 0?{}:{lines:r.map(([u,d,l,c,m])=>({lineNumber:u,content:T(d,n),lineEnding:l,...c==null?{}:{presentation:c},...m==null?{}:{metadata:m}}))},...o===void 0?{}:{truncation:{...o,content:T(i??"",n)}}}}a(P,"restoreReadDetails");import f from"node:path";import{homedir as I}from"node:os";import{createReadToolDefinition as V,getReadmePath as J}from"@earendil-works/pi-coding-agent";import{Text as Z}from"@earendil-works/pi-tui";var S=V(process.cwd()),K=new Set(["AGENTS.override.md","AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"]);function v(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),s=f.basename(o),u=f.relative(f.dirname(J()),o),d=!f.isAbsolute(u)&&(u==="README.md"||u.startsWith(`docs${f.sep}`)||u.startsWith(`examples${f.sep}`));if(!(s!=="SKILL.md"&&!K.has(s)&&!d))return{path:r,...t.offset===void 0?{}:{offset:t.offset},...t.limit===void 0?{}:{limit:t.limit}}}a(v,"nativeReadArguments");function L(e,n){return{...e,args:n,lastComponent:e.lastComponent instanceof Z?e.lastComponent:void 0}}a(L,"nativeReadContext");import{getLanguageFromPath as q,getMarkdownTheme as X,highlightCode as z,keyHint as Y}from"@earendil-works/pi-coding-agent";import{Container as g,Markdown as Q,Text as _,truncateToWidth as h,visibleWidth as p,wrapTextWithAnsi as N}from"@earendil-works/pi-tui";var E=12;function ee(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 d=r??1,l=i===void 0?String(d):`${d}-${d+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 s=Math.max(1,r??1),u=i===void 0?String(s):`${s}-${s+i-1}`;return{pathSuffix:`:${u}`,qualifiers:[],details:[{label:"lines",value:u}]}}a(ee,"readWindowPresentation");function ke(e,n,t){let r=v(e,t.cwd);if(r!==void 0)return R(S.renderCall)(r,n,L(t,r));if(typeof e.path=="string"&&e.path.startsWith("shell:"))return new g;let i=typeof e.path=="string"?e.path:"inherited source",o=ee(i,e.offset,e.limit),s=Array.isArray(e.views)?e.views.filter(l=>typeof l=="string"):[],u=[...o.qualifiers,...s.length===0?[]:[{text:`views ${s.join(",")}`}]],d=[...typeof e.path=="string"?[{label:"path",value:e.path}]:[],...o.details,...s.length===0?[]:[{label:"views",value:s.join(",")}]];return M(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:d,expanded:t.expanded},n)}a(ke,"renderReadCall");function Me(e){let n=new WeakMap;return(t,r,i,o)=>{let s=e.nativeResources?v(o.args,o.cwd):void 0;if(s!==void 0&&!r.isPartial)return R(S.renderResult)({...t,details:{truncation:$(t.details).truncation}},r,i,L(o,s));if(r.isPartial||o.isError){let m=D(t),H=o.isError?"error":"dim";return new _(i.fg(H,m),0,0)}let u=$(t.details).diagnosticCheck;if(u?.complete&&u.count===0)return new g;if(!de(t))return o.lastComponent instanceof g?o.lastComponent:new g;let d=n.get(t);d===void 0&&(d=P($(t.details),D(t)),n.set(t,d));let c=(o.lastComponent instanceof x?o.lastComponent:void 0)??new x({result:t,details:d,options:e,expanded:r.expanded,theme:i});return c.update({result:t,details:d,options:e,expanded:r.expanded,theme:i}),c}}a(Me,"createReadResultRenderer");var x=class{constructor(n){this.state=n}static{a(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=[h(B(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=ne(this.state,r).flatMap(l=>N(l,r)),o=re(i,this.state.expanded,this.state.theme),s=[ie(this.state,t,this.state.theme)];for(let l of o)for(let c of N(l,r))s.push(W(c,t,this.state.theme));let u=ae(this.state.details,this.state.theme);u!==void 0&&s.push(W(u,t,this.state.theme)),s.push(this.state.theme.fg("borderMuted",`\u2570${"\u2500".repeat(t)}\u256F`));let d=s.map(l=>h(l,n));return this.cached={width:n,lines:d},d}invalidate(){this.cached=void 0}};function ne(e,n){let t=G(e.details),r=se(e.result,t,e.details,!e.expanded);if(e.options.kind==="markdown"||ue(e.details,t,e.options.kind)){let u=new Q(r,0,0,X());return C(u.render(n),e.theme)}if(e.options.kind==="code-view"){let u=t===void 0||j(t)?O(r).map(d=>U(d,e.theme,!1)):te(t,e.theme);return C(u,e.theme)}let i=t===void 0||j(t)?O(r).map(y):t.map(({content:u})=>y(u)),o=A(e.details,t),s=o===void 0?i.map(u=>e.theme.fg("toolOutput",u)):z(i.join(`
2
- `),o);return C(s,e.theme)}a(ne,"renderContentRows");function te(e,n){return e.map(t=>{let r=b(t);if(r===void 0)return U(t.content,n);let i=q(r.source),o=y(F(t.content));return i===void 0?n.fg("toolOutput",o):z(o,i)[0]??n.fg("toolOutput",o)})}a(te,"renderCodeViewLines");function F(e){return e.replace(/(?:[ \t]{2,}<!--[ \t]+scope-(?:begin|end)-[^\s>]+[ \t]+-->)+[ \t]*$/u,"")}a(F,"stripScopeMarkers");function U(e,n,t=!0){let r=y(t?F(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)}a(U,"renderCodeViewLabel");function re(e,n,t){if(n||e.length<=E)return e;let r=e.slice(0,E-1),i=e.length-r.length;return[...r,`${t.fg("dim",`\u2026 ${String(i)} more ${i===1?"row":"rows"} \xB7 `)}${Y("app.tools.expand","to expand")}`]}a(re,"compactRows");function ie(e,n,t){let r=a(s=>t.fg("borderMuted",s),"frame"),i=h(` ${B(e,Math.max(1,n-1))} `,Math.max(0,n-1),""),o="\u2500".repeat(Math.max(0,n-p(i)-1));return`${r("\u256D\u2500")}${i}${r(`${o}\u256E`)}`}a(ie,"renderTopBorder");function B(e,n){let t=e.options.label??fe(A(e.details,G(e.details))),r=e.details.source??"read result",i=oe(e.details),o=e.theme.fg("accent",e.theme.bold(t)),s=i===void 0?"":e.theme.fg("dim",` \xB7 ${i}`),u=Math.max(1,n-p(o)-p(s)-2),d=ce(r,u);return`${o} ${e.theme.fg("muted",d)}${s}`}a(B,"readTitle");function oe(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)}`}a(oe,"sourceRange");function ae(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`)}a(ae,"readStatus");function W(e,n,t){let r=Math.max(0,n-2),i=h(e,r),o=` ${i}${" ".repeat(Math.max(0,r-p(i)))} `,s=t.fg("borderMuted","\u2502");return`${s}${o}${s}`}a(W,"framed");function se(e,n,t,r){if(n!==void 0)return k({source:t.source??"",content:"",lines:n},{compact:r});let i=D(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,"")}a(se,"cleanText");function j(e){return e.some(n=>n.presentation!==void 0)}a(j,"hasPresentation");function O(e){let n=e.split(/\r\n|\r|\n/u);return n.at(-1)===""&&/(?:\r\n|\r|\n)$/u.test(e)&&n.pop(),n}a(O,"splitTextRows");function D(e){return e.content.flatMap(n=>n.type==="text"?[n.text]:[]).join(`
3
- `)}a(D,"textBlocks");function G(e){return e.lines}a(G,"readLines");function $(e){return typeof e=="object"&&e!==null?e:{}}a($,"readDetails");function de(e){return e.content.some(n=>n.type==="text")}a(de,"hasTextContent");function A(e,n){let r=n?.map(b).find(i=>i!==void 0)?.source??e.source;return r===void 0?void 0:q(le(r))}a(A,"languageFor");function ue(e,n,t){return t==="source"&&A(e,n)==="markdown"}a(ue,"isMarkdownSource");function le(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,"")}}a(le,"normalizeSourcePath");function y(e){let n="";for(let t of e.replaceAll(" "," ".repeat(4))){let r=R(t.codePointAt(0));n+=r<32||r===127?"\uFFFD":t}return n}a(y,"normalizeText");function fe(e){return e===void 0?"TEXT":{javascript:"JS",json:"JSON",markdown:"MD",python:"PY",rust:"RS",typescript:"TS"}[e]??e.slice(0,4).toUpperCase()}a(fe,"languageLabel");function C(e,n){return e.length===0?[n.fg("dim","Empty content")]:[...e]}a(C,"nonEmptyRows");function ce(e,n){return p(e)<=n?e:n<=1?"\u2026":`\u2026${e.slice(-(n-1))}`}a(ce,"truncateFromStart");export{me as a,E as b,ke as c,Me as d};
@@ -1 +0,0 @@
1
- import{d as s}from"./chunk-S3ZPXWX7.js";import{a as o}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as i}from"typebox/value";import{Type as n}from"typebox";var l=n.Object({path:n.Optional(n.String({description:"What to read: a file or directory path, URL, returned temp: or SEARCH# reference, or one of the source forms listed in the description. Supply a path; an empty call cannot select a source."})),offset:n.Optional(n.Number({description:"For raw: sources, use a zero-based byte offset; negative offsets count from the file end. For other sources: first line to return, numbered from 1. Omit or use 0 to start at line 1; -1 starts at the last line, -10 at the tenth line from the end. For path#anchor or a SEARCH selection, count from its containing line instead: 0 or 1 starts there, 2 starts one line later, -1 one line earlier."})),limit:n.Optional(n.Number({description:"For raw: sources, use a non-negative byte count (0 reads no bytes). Otherwise, maximum lines from the selected starting position. Output is bounded; omit for the default read."})),views:n.Optional(n.Array(n.String(),{description:`Optional additions to the returned text. Use the views listed in the tool description. Combine views when needed, for example ["anchors", "ast"] for source text with editable line references and scope boundaries. Omit for the source's default presentation.`}))});var a=e.Function([],e.Unknown()),u=e.Object({resolver:e.Unknown(),priority:e.Optional(e.Number()),renderResult:e.Optional(a),preserveTruncatedOutput:e.Optional(e.Boolean())}),R=e.Object({resolver:e.Unknown(),priority:e.Optional(e.Number())}),p=e.Object({id:e.String({pattern:"\\S"}),priority:e.Optional(e.Number()),resolve:a}),y=e.Object({view:e.String({pattern:"\\S"}),includes:e.Optional(e.Array(e.String({pattern:"\\S"}))),presenter:e.Object({id:e.String(),present:a}),priority:e.Optional(e.Number())}),c=e.Object({resolvedBy:e.String({pattern:"\\S"}),contentKind:e.Union([e.Literal("text"),e.Literal("any")])}),g=e.Union([e.Object({stage:e.Literal("pre-read"),handler:a}),e.Object({stage:e.Literal("read"),when:c,handler:a}),e.Object({stage:e.Literal("post-read"),handler:a})]);function h(t){if(!i.Check(R,t))return!1;let r=t,d=r.resolver;return typeof d.id=="string"&&d.id.length>0&&typeof d.tryResolve=="function"&&(!("priority"in r)||typeof r.priority=="number")}o(h,"isTextTargetResolverRegistration");function S(t){if(!i.Check(u,t))return!1;let r=t;return s(r.resolver)?r.resolver.id!=="any"&&(!("priority"in r)||typeof r.priority=="number")&&(!("renderResult"in r)||typeof r.renderResult=="function"):!1}o(S,"isResourceResolverRegistration");function O(t){return i.Check(g,t)}o(O,"isReadHandlerRegistration");function k(t){return i.Check(y,t)}o(k,"isReadViewRegistration");function L(t){return i.Check(p,t)}o(L,"isFragmentResolverRegistration");function P(t){return m(t)?t.kind==="not-handled"?!0:t.kind==="failed"?typeof t.message=="string"&&t.message.length>0:t.kind==="resolved"&&typeof t.originLine=="number":!1}o(P,"isReadFragmentResolution");function m(t){return typeof t=="object"&&t!==null}o(m,"isRecord");export{l as a,h as b,S as c,O as d,k as e,L as f,P as g};
@@ -1,14 +0,0 @@
1
- import{a as b,d as A}from"./chunk-ITSNK5YG.js";import{a as v}from"./chunk-5MSNYFDE.js";import{d as M}from"./chunk-3SE372WC.js";import{f as C}from"./chunk-YHUTTZC6.js";import{a as p}from"./chunk-EI7MMDWY.js";import F from"node:path";import{truncateHead as $,DEFAULT_MAX_BYTES as W,DEFAULT_MAX_LINES as Z}from"@earendil-works/pi-coding-agent";import{Text as S}from"@earendil-works/pi-tui";import{Type as T}from"typebox";import{Value as Q}from"typebox/value";var N=T.Union([T.String({minLength:1}),v]),_=T.Object({before:N,after:N},{additionalProperties:!1});async function ee(e,l,f){if(!Q.Check(_,l))throw Object.assign(new Error("Use before and after source strings or read request objects"),{code:"INVALID_ARGUMENTS"});let n=l,r=p(async s=>{let t=typeof s=="string"?{path:s}:s,c=await e.read(t,f,"script");if(c.isError||c.details.failure)throw Object.assign(new Error(c.details.failure?.message??"Comparison read failed"),{code:c.details.failure?.code??"READ_FAILED",details:c.details.failure});if(c.script===void 0)throw Object.assign(new Error("Source has no comparable text data"),{code:"UNSUPPORTED_CONTENT"});return L(c.script,t.path??"source")},"resolve"),i=await r(n.before),a=await r(n.after),o=b(i.source,i.content,a.content,a.source);return{kind:"diff",ok:!0,equal:i.content===a.content,before:i,after:a,...o}}p(ee,"executeDiff");function L(e,l){if(e.kind==="text")return{source:e.source,sources:[e.source],content:e.content};if(e.kind==="resources"){let f=e.resources.map(n=>L(n,l));return{source:e.source??l,sources:f.flatMap(n=>n.sources),content:f.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(f=>f.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(f=>f.type==="text"?[f.text]:[]).join(`
3
- `)}}p(L,"comparisonText");function R(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="diff"&&"ok"in e&&e.ok===!0}p(R,"isDiffOutcome");function D(e,l=process.cwd()){let f=p(r=>F.isAbsolute(r)?F.relative(l,r)||".":r,"displaySource"),n=`Diff: ${f(e.before.source)} \u2192 ${f(e.after.source)}`;return{results:[new A({ok:!0,path:n,beforeContentMap:{[n]:e.before.content},afterContent:e.after.content,diffs:[e.diff]})]}}p(D,"diffPresentation");function O(e){return e.equal?`No differences: ${e.before.source} \u2192 ${e.after.source}`:e.diff}p(O,"diffText");function Se(e){return{content:[{type:"text",text:O(e)}],details:{}}}p(Se,"diffReadResult");function Te(e,l,f){e.registerTool({name:"diff",label:"Diff",parameters:_,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,i,a){let o=n.details;if(o?.comparison?.equal)return new S(O(o.comparison),0,0);let s=l.getToolRenderer("diff")?.renderResult;return s?s(n,r,i,a):new S(n.content.filter(t=>t.type==="text").map(t=>t.text).join(`
4
- `),0,0)},async execute(n,r,i,a,o){let s=f();if(s===void 0)throw new Error("Diff requires the read extension");let t=await ee(s,r,{cwd:o.cwd,signal:i}),c=O(t),y=$(c).truncated?await s.saveTemporary(c):void 0,d=y===void 0?"":`
5
- Full diff: ${y}`;return{content:[{type:"text",text:y===void 0?c:$(c,{maxLines:Z-2,maxBytes:W-Buffer.byteLength(d)}).content+d}],details:{...D(t,o.cwd),comparison:t,temporarySource:y}}}})}p(Te,"registerDiff");import{parser as B}from"@lezer/javascript";import{TreeFragment as I}from"@lezer/common";var te=new Set(["read","search","diff","write","replace","insert","remove","copy","move","undo","stage","unstage","delete_file","copy_file","move_file"]);function q(e,l=B.parse(e)){let f=[];l.iterate({enter(r){if(r.name==="AssignmentExpression"){let t=r.node.firstChild;t?.name==="VariableName"&&f.push({name:e.slice(t.from,t.to),from:0,to:e.length})}if(r.name!=="VariableDefinition")return;let i=r.node.parent;for(;i?.parent&&!["VariableDeclaration","ParamList","Block","Script"].includes(i.name);)i=i.parent;let a=i?.name==="VariableDeclaration"&&i.firstChild?.name==="var",o=new Set(["Script","FunctionDeclaration","FunctionExpression","ArrowFunction",...a?[]:["Block"]]),s=r.node.parent;for(s?.name==="FunctionDeclaration"&&(s=s.parent);s?.parent&&!o.has(s.name);)s=s.parent;f.push({name:e.slice(r.from,r.to),from:s?.from??0,to:s?.to??e.length})}});let n=[];return l.iterate({enter(r){if(r.name!=="CallExpression")return;let i=r.node.firstChild;if(i?.name!=="VariableName")return;let a=e.slice(i.from,i.to);if(!te.has(a)||f.some(t=>t.name===a&&t.from<=r.from&&t.to>=r.to))return;let o=r.node.getChild("ArgList")?.getChild("ObjectExpression"),s=Object.create(null);if(!o){let t=r.node.getChild("ArgList"),c=t?e.slice(t.from+1,t.to).replace(/\)$/,""):"";c&&(s.arguments={text:c.length>160?c.slice(0,120)+"\u2026":c,literal:!1})}for(let t of o?.getChildren("Property")??[]){let c=t.firstChild,y=(c?e.slice(c.from,c.to):"").replace(/^["']|["']$/g,"");if(!/^[a-zA-Z_$][\w$]*$/.test(y)){for(let K of["path","query","target","before","after"])delete s[K];let w=e.slice(t.from,t.to);s[`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);s[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:a,from:r.from,to:r.to,path:s.path,query:s.query,target:s.target,before:s.before,after:s.after,arguments:s}),!1}}),n}p(q,"parseApplyCalls");function re(e,l=q(e),f,n=r=>r){let r=0,i=[],a=p(o=>n(o.split(`
6
- `).map(s=>s.length>200?s.slice(0,200)+"\u2026":s).join(`
7
- `)),"codePreview");for(let o of l)i.push(a(e.slice(r,o.from))),i.push(f?.(o)??`${o.name}(${o.path?o.path.literal?o.path.text:`\u2039${o.path.text}\u203A`:"\u2026"})`),r=o.to;return i.push(a(e.slice(r))),i.join("")}p(re,"compactApplySource");function U(e,l){let f="",n="",r=[];return i=>{if(i===f)return n;let a=0;for(;a<f.length&&a<i.length&&f[a]===i[a];)a++;r=I.applyChanges(r,[{fromA:a,toA:f.length,fromB:a,toB:i.length}]);let o=B.parse(i,r);return r=I.addTree(o),n=re(i,q(i,o),e,l),f=i,n}}p(U,"createApplySourceProjection");import{lstat as z,unlink as ne}from"node:fs/promises";import V from"node:path";import J from"fs-extra";import{Type as x}from"typebox";import{Value as oe}from"typebox/value";var Ne=["delete_file","move_file","copy_file"],E=x.String({minLength:1,description:"Local regular file path, relative to cwd or absolute."}),ie=x.Object({path:E},{additionalProperties:!1}),ae=x.Object({path:E,target:E,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"}p(k,"isFileOperationResult");function P(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(l=>l!==void 0).join(`
8
- `)}p(P,"formatFileOperation");async function _e(e,l,f,n){let r=!1,i,a;try{let o=e==="delete_file"?ie:ae;if(!oe.Check(o,l))throw Object.assign(new Error("Invalid file operation arguments"),{code:"INVALID_ARGUMENTS"});let s=l;i=V.resolve(f,s.path),a=s.target===void 0?void 0:V.resolve(f,s.target),n?.throwIfAborted();let t=await se(i);if(a!==void 0){let c=await le(a);if(c!==void 0){if(!c.isFile()||c.isSymbolicLink())throw Object.assign(new Error("Target must be a regular file"),{code:"INVALID_FILE_TYPE"});if(i===a||t.ino===c.ino&&t.dev===c.dev)throw Object.assign(new Error("Source and target are the same file"),{code:"SAME_FILE"});if(s.overwrite!==!0)throw Object.assign(new Error("Target exists; use overwrite: true to replace it"),{code:"EEXIST"})}}return n?.throwIfAborted(),r=!0,e==="delete_file"?await ne(i):a!==void 0&&(e==="copy_file"?await J.copy(i,a,{overwrite:s.overwrite===!0,errorOnExist:!0}):await J.move(i,a,{overwrite:s.overwrite===!0})),{kind:"file-operation",operation:e,ok:!0,effect:"applied",path:i,...a===void 0?{}:{target:a}}}catch(o){return{kind:"file-operation",operation:e,ok:!1,effect:r?"unknown":"not-applied",...i===void 0?{}:{path:i},...a===void 0?{}:{target:a},error:{code:o!==null&&typeof o=="object"&&"code"in o?String(o.code):"FILE_OPERATION_FAILED",message:o instanceof Error?o.message:String(o)}}}}p(_e,"executeFileOperation");async function se(e){let l=await z(e);if(!l.isFile()||l.isSymbolicLink())throw Object.assign(new Error("Source must be a regular file"),{code:"INVALID_FILE_TYPE"});return l}p(se,"regularFile");async function le(e){try{return await z(e)}catch(l){if(l!==null&&typeof l=="object"&&"code"in l&&l.code==="ENOENT")return;throw l}}p(le,"optionalStat");import{Text as fe}from"@earendil-works/pi-tui";function G(e){let l=e.select(),f=e.mutationValues().filter(ce);return l.files.map(n=>{let r=f.flatMap(o=>o.files.filter(s=>s.source===n.source).map(s=>({outcome:o,changed:s}))),i=e.mutationPresentation(n.source)?.data,a=i?.afterContent===n.after?i: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:a?.afterDocument,resultPresentation:a?.resultPresentation,scopeMarkers:a?.scopeMarkers,hints:a?.hints,warnings:a?.warnings,diffStatuses:a?.diffStatuses,diffs:[b(n.source,n.before??"",n.after??"").diff],operations:r.map(({outcome:o,changed:s})=>({operation:o.operation==="remove"?"delete":o.operation,changes:s.changes.length})),formatting:a?.formatting??r.at(-1)?.changed.formatting})})}p(G,"finalApplyMutations");function ce(e){return e!==null&&typeof e=="object"&&"operation"in e&&"files"in e&&Array.isArray(e.files)&&"effect"in e}p(ce,"isMutation");import{highlightCode as H}from"@earendil-works/pi-coding-agent";import{wrapTextWithAnsi as X,visibleWidth as Y,truncateToWidth as pe}from"@earendil-works/pi-tui";function Qe(e,l,f,n=process.cwd()){let r=e.select(),i=[...r.automatic,...r.explicit.filter(t=>t.kind==="operation")].filter(t=>R(t.value)&&!t.value.equal),a=i.flatMap(t=>R(t.value)?[D(t.value,n)]:[]),o=new Set(i.flatMap(t=>t.presentation?.content??[]));if(r.files.length===0){let t=[...r.automatic.map(c=>c.presentation),...r.explicit.map(c=>c.kind==="operation"?c.presentation:void 0)].filter(c=>c!==void 0);return{comparisons:a,cwd:n,blocks:l.content.filter(c=>!o.has(c)).flatMap(c=>c.type==="text"?[{text:c.text,read:t.find(g=>g.content.includes(c))}]:[])}}let s=G(e);return{...s.length>0?{mutations:{results:s}}:{},comparisons:a,cwd:n,blocks:[...r.explicit.flatMap(t=>t.kind==="operation"&&R(t.value)&&!t.value.equal?[]:k(t.value)?[{text:P(t.value)}]:t.kind==="operation"?t.presentation?.content.flatMap(c=>c.type==="text"?[{text:c.text,read:t.presentation}]:[])??[]:[{text:typeof t.value=="string"?t.value:t.value===void 0?"undefined":JSON.stringify(t.value,null,2)}]),...r.automatic.flatMap(({value:t,presentation:c})=>k(t)?[{text:P(t)}]:t!==null&&typeof t=="object"&&"kind"in t&&t.kind==="index-operation"?c?.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}]:[])),...f===void 0?[]:[{text:f instanceof Error?f.message:JSON.stringify(f)}]]}}p(Qe,"createApplyDisplay");function j(e,l,f,n,r,i,a=!1){let o=Math.max(1,f);if(o<5)return e.split(`
9
- `).flatMap(u=>X(u,o));let s=o-4,t=p(u=>l.fg("borderMuted",u),"border"),g=pe(` ${n==="call"?"Apply \xB7 JavaScript":"Result"} `,o-4,""),y=[t(`${n==="call"?"\u256D":"\u251C"}\u2500`)+l.fg(a?"error":"accent",g)+t(`${"\u2500".repeat(Math.max(0,o-Y(g)-3))}${n==="call"?"\u256E":"\u2524"}`)],d=`${t("\u2502")}${" ".repeat(o-2)}${t("\u2502")}`;for(let u of e.split(`
10
- `)){let h=i==="diff"?l.fg(u.startsWith("+")?"toolDiffAdded":u.startsWith("-")?"toolDiffRemoved":"toolDiffContext",u):i?H(u,i).join(`
11
- `):l.fg("toolOutput",u);for(let w of X(h,s))y.push(`${t("\u2502")} ${w}${" ".repeat(Math.max(0,s-Y(w)))} ${t("\u2502")}`)}n==="call"&&y.push(d),r&&y.push(t(`\u2570${"\u2500".repeat(o-2)}\u256F`));let m=l.getBgAnsi("toolPendingBg");return y.map(u=>m+C(u,m)+"\x1B[0m")}p(j,"applyFrameRows");function ue(e){return(l,f,n)=>{let r=n.state,i=r.projectSource??=U(e?o=>e(o,f):void 0,e?o=>H(o,"javascript").join(`
12
- `):void 0),a=l!==null&&typeof l=="object"&&"source"in l&&typeof l.source=="string"?l.source:"";return{invalidate(){},render(o){return j(r.codeView||n.expanded?r.displaySource??a:i(r.displaySource??a),f,o,"call",!r.applyResultReady,r.codeView||n.expanded||!e?"javascript":void 0)}}}}p(ue,"createApplyCallRenderer");var et=ue();function de(e){return(l,f,n,r)=>{r.state.applyResultReady=!0;let i=l.details;r.state.displaySource=i?.displaySource;let a=i?.display,o=a?.blocks??[{text:r.isError?"Apply failed":"Apply finished"}],s=M({kind:"source"}),t=o.map(d=>s(d.read??{content:[{type:"text",text:d.text}],details:me(d.text)},f,n,{...r,isError:!1,lastComponent:void 0})),c=a?.mutations,g=(a?.comparisons??[]).flatMap(d=>[e?.(d,n,f.expanded,a?.cwd??process.cwd())??new fe((d.results??[]).flatMap(u=>u.data.diffs??[]).join(`
13
- `),0,0)]),y=c===void 0?void 0:e?.(c,n,f.expanded,a?.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 c!==void 0&&m.push(...(c.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(`
14
- `),n,d,"result",!0,void 0,r.isError)}}}}p(de,"createApplyResultRenderer");function me(e){try{let l=JSON.parse(e);return l!==null&&typeof l=="object"?{source:"result.json"}:{}}catch{return{}}}p(me,"jsonDetails");var tt=de();export{ee as a,Se as b,Te as c,Ne as d,ie as e,ae as f,_e as g,G as h,Qe as i,ue as j,et as k,de as l,tt as m};
@@ -1,3 +0,0 @@
1
- import{a as w}from"./chunk-5VSE5X5R.js";import{a as u}from"./chunk-EI7MMDWY.js";import{createHash as T}from"node:crypto";import{createRequire as P}from"node:module";import L from"node:path";import*as h from"web-tree-sitter";var F=P(new URL("../src/plugins/pi-agent-ide-ast/src/ast/manager.ts",import.meta.url).href),j=new Set(["program","module"]),y=new Set(["body","consequence","alternative","handler","finalizer"]),S,x=new Map;function E(c){switch(c){case".ts":case".tsx":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":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}}u(E,"grammarWasmPath");async function B(c){let n=E(c);if(!n)return;S??=h.Parser.init(),await S;let t=x.get(n);if(t===void 0){let o=F.resolve(n);t=h.Language.load(o),x.set(n,t)}let s=await t,i=new h.Parser;return i.setLanguage(s),i}u(B,"ensureParser");async function W(c,n,t){if(t.length===0)return;let s=L.isAbsolute(c)?c:L.resolve(n,c),i=await B(L.extname(s).toLowerCase());if(i)return i.parse(t.join(`
2
- `))??void 0}u(W,"parseDocument");function A(c,n,t){let s=c.slice(Math.max(0,n-1),Math.max(0,t)).join(`
3
- `);return T("sha1").update(s).digest("hex").slice(0,4).toUpperCase()}u(A,"hashScope");var b=class extends w{static{u(this,"AstScopeTextAnchor")}constructor(n,t,s,i){super(`scope-${n}-${t}${i===void 0?"":`-${i}`}`,s)}};function g(c,n,t,s){return new b(c,n,t,s)}u(g,"createScopeAnchor");var C=class{static{u(this,"AstScopeManager")}async getDocumentScopes(n,t,s){if(s.length===0)return[];let i=await W(n,t,s);if(!i)return[];let o=[];return this.collectCandidates(i.rootNode,o),this.buildEntries(o,s)}collectCandidates(n,t,s=0,i=!1){if(s>100||!n.isNamed)return;let o=n.type;if(!o||j.has(o)){for(let a of n.namedChildren)this.collectCandidates(a,t,s+1);return}for(let a of y){let e=n.childForFieldName(a);if(!e?.isNamed)continue;let r=e.startPosition.row+1,l=e.endPosition.row+1,f=l-r>=3,d=[...y].some(m=>e.childForFieldName(m)!==null);f&&!d&&t.push({startLine:r,endLine:l,kind:`${o}.${a}`,fromBodyField:!0}),this.collectCandidates(e,t,s+1,!0)}if(![...y].some(a=>n.childForFieldName(a)!==null)&&!i){let a=n.startPosition.row+1,e=n.endPosition.row+1;e-a>=3&&n.namedChildren.length>0&&t.push({startLine:a,endLine:e,kind:o,fromBodyField:!1})}for(let a of n.namedChildren)this.collectCandidates(a,t,s+1)}buildEntries(n,t){let s=new Map;for(let e of n){let r=s.get(e.startLine);(!r||e.endLine>r.endLine||e.endLine===r.endLine&&e.fromBodyField&&!r.fromBodyField)&&s.set(e.startLine,e)}let i=[...s.values()].sort((e,r)=>e.startLine-r.startLine||r.endLine-e.endLine),o=[];for(let e of i)o.some(l=>l.startLine<e.startLine&&l.endLine===e.endLine)||o.push(e);let p=new Map;for(let e of o){let r=A(t,e.startLine,e.endLine);p.set(r,(p.get(r)??0)+1)}let a=new Map;return o.map(e=>{let r=A(t,e.startLine,e.endLine),l=p.get(r)??1,f=(a.get(r)??0)+1;a.set(r,f);let d=l>1?f:void 0;return{name:e.kind,kind:e.kind,startLine:e.startLine,endLine:e.endLine,depth:o.filter(m=>m!==e&&m.startLine<=e.startLine&&m.endLine>=e.endLine&&(m.startLine<e.startLine||m.endLine>e.endLine)).length,hash:r,blockHash:r,...d!==void 0&&{occurrence:d},beginAnchor:g("begin",r,e.startLine,d),endScopeAnchor:g("end",r,e.endLine,d),scopeBeginAnchor:g("begin",r,e.startLine,d),scopeEndAnchor:g("end",r,e.endLine,d)}})}};export{W as a,C as b};
@@ -1,2 +0,0 @@
1
- import{a as j}from"./chunk-GUTQ3PWL.js";import{m as b}from"./chunk-5VSE5X5R.js";import{a as S}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";import{createHash as ue}from"node:crypto";import{readFile as q}from"node:fs/promises";import h from"node:path";import{spawn as ee}from"node:child_process";import D from"node:path";import{createInterface as te}from"node:readline";import{existsSync as Y}from"node:fs";import Z from"node:os";import H from"node:path";function F(e=process.env.PI_CODING_AGENT_DIR??H.join(Z.homedir(),".pi","agent"),t=process.platform){let n=H.join(e,"bin",t==="win32"?"rg.exe":"rg");return Y(n)?n:"rg"}a(F,"resolveRipgrepExecutable");async function A(e,t,n){if(e.query.length===0)throw new Error("Search query must not be empty.");if(/\r|\n/u.test(e.query))throw new Error("Search supports one-line patterns only.");let r=e.limit??100,o=D.resolve(t,oe(e.path??".")),s=["--json","--no-config","--no-ignore-parent","--color=never","--with-filename","--line-number",e.caseSensitive===!0?"--case-sensitive":"--ignore-case",...e.wholeWord===!0?["--word-regexp"]:[],...O(e.include).flatMap(i=>["--glob",i]),...O(e.exclude).flatMap(i=>["--glob",`!${i}`]),"--",e.query,o];if(e.regex!==!0)return R(["--fixed-strings",...s],r,n);try{return await R(["--engine","auto",...s],r,n)}catch(i){if(!ne(i))throw i;return R(["--engine","default",...s],r,n)}}a(A,"searchText");function R(e,t,n){return new Promise((r,o)=>{let s=ee(F(),e,{stdio:["ignore","pipe","pipe"]}),i=te({input:s.stdout}),c=[],l="",u=!1,d,g=a(()=>{s.kill()},"abort"),m=a(()=>{n?.removeEventListener("abort",g),i.close()},"cleanup");s.stderr.setEncoding("utf8"),s.stderr.on("data",f=>{l+=f}),i.on("line",f=>{if(!(u||d!==void 0||f.length===0))try{let p=JSON.parse(f);if(p.type!=="match")return;for(let X of re(p)){if(c.length===t){u=!0,s.kill();return}c.push(X)}}catch(p){d=p,s.kill()}}),s.once("error",f=>{m(),o(f)}),s.once("close",f=>{if(m(),n?.aborted===!0){let p=new Error("Search was aborted.");p.name="AbortError",o(p);return}if(d!==void 0){o(new Error("Unable to parse ripgrep search output.",{cause:d}));return}if(!u&&f!==0&&f!==1){o(new Error(l.trim()||`ripgrep exited with code ${String(f)}.`));return}c.sort(ie),r({matches:c,complete:!u})}),n?.addEventListener("abort",g,{once:!0}),n?.aborted===!0&&g()})}a(R,"runRipgrep");function ne(e){return e instanceof Error&&/PCRE2: error matching: match limit exceeded/iu.test(e.message)}a(ne,"isPcre2MatchLimitError");function re(e){let t=e.data.path.text,n=e.data.lines.text;if(t===void 0||n===void 0||!Number.isSafeInteger(e.data.line_number))return[];let r=n.replace(/(?:\r\n|\n)$/u,""),o=Buffer.from(n),s=[];for(let i of e.data.submatches){if(i.start<0||i.end<=i.start||i.end>o.length)continue;let c=o.subarray(0,i.start).toString("utf8").length,l=o.subarray(0,i.end).toString("utf8").length;s.push({source:D.resolve(t),lineNumber:e.data.line_number,startColumn:c,endColumn:l,matchedText:r.slice(c,l),lineText:r})}return s}a(re,"matchesFromEvent");function O(e){if(e===void 0)return[];let t=[],n=0,r="";for(let o of e){if(o==="{"?n+=1:o==="}"&&(n=Math.max(0,n-1)),n===0&&(o===","||/\s/u.test(o))){r.length>0&&(t.push(r),r="");continue}r+=o}return r.length>0&&t.push(r),t}a(O,"splitGlobList");function oe(e){return e.startsWith("@")?e.slice(1):e}a(oe,"stripFilePrefix");function ie(e,t){return e.source.localeCompare(t.source)||e.lineNumber-t.lineNumber||e.startColumn-t.startColumn||e.endColumn-t.endColumn}a(ie,"compareMatches");function N(e,t=!1){let n=M(e);if(!C(n))return t?e:B(e);let r=E(new v(e,n).parse(),t);return`^${r.condition}.*?\\K(${r.match})`}a(N,"compileSearchQuery");function _(e){if(C(M(e)))return;let t=[...new Set(e.trim().split(/\s+/u).filter(Boolean))];return t.length>1?`(?:${t.map(B).join("|")})`:void 0}a(_,"compileSearchFallbackQuery");function C(e){return e.some(t=>t.quoted===!0||t.type==="and"||t.type==="or"||t.type==="not")}a(C,"containsBooleanSyntax");var v=class{static{a(this,"BooleanQueryParser")}#t;#r;#i=0;constructor(t,n){this.#t=t,this.#r=n}parse(){let t=this.#s(),n=this.#e();if(n.type!=="end"){let r=n.type==="right"?"unexpected ')'.":`unexpected ${ae(n)}.`;throw y(n.offset,r)}return t}#s(){let t=this.#n();for(;this.#e().type==="or";){let n=this.#o(),r=this.#c(`after ${n.value}`);t={kind:"or",left:t,right:this.#a(r)}}return t}#n(){return this.#a(this.#c())}#a(t){let n=t;for(;;){let r=this.#e();if(r.type==="and"||r.type==="not"){this.#o();let o=this.#c(`after ${r.value}`);n={kind:r.type,left:n,right:o};continue}if(r.type==="term"||r.type==="left"){n={kind:"and",left:n,right:this.#c()};continue}return n}}#c(t){let n=this.#e();if(n.type==="term")return this.#o(),{kind:"term",value:n.value,quoted:n.quoted};if(n.type==="left"){if(this.#o(),this.#e().type==="right"||this.#e().type==="end")throw y(this.#e().offset,"expected a term after '('.");let o=this.#s();if(this.#e().type!=="right")throw y(this.#e().offset,"expected ')'.");return this.#o(),o}if(t===void 0&&(n.type==="and"||n.type==="or"||n.type==="not"))throw y(n.offset,`expected a term before ${n.value}.`);let r=t===void 0?"":` ${t}`;throw y(n.offset,`expected a term${r}.`)}#e(){return this.#r[this.#i]??{type:"end",value:"",offset:this.#t.length}}#o(){let t=this.#e();return this.#i+=1,t}};function M(e){let t=[],n=0;for(;n<e.length;){let r=e.charAt(n);if(/\s/u.test(r)){n+=1;continue}if(r==="("&&se(e,n)){t.push({type:"left",value:r,offset:n}),n+=1;continue}if(r===")"){t.push({type:"right",value:r,offset:n}),n+=1;continue}if(W(e,n)){let i=e.charAt(n+1)==="|"?2:1;t.push({type:"or",value:e.slice(n,n+i),offset:n}),n+=i;continue}if(r==="'"||r==='"'){let i=n,c=r,l="";for(n+=1;n<e.length&&e.charAt(n)!==c;)e.charAt(n)==="\\"&&(e.charAt(n+1)===c||e.charAt(n+1)==="\\")&&(n+=1),l+=e.charAt(n++);if(n>=e.length)throw y(i,`unterminated ${c==="'"?"single":"double"}-quoted term.`);if(n+=1,l.length===0)throw y(i,"quoted terms must not be empty.");t.push({type:"term",value:l,offset:i,quoted:!0});continue}let o=n;for(;n<e.length;){let i=e.charAt(n);if(/\s/u.test(i)||i===")"||W(e,n))break;i==="\\"&&n+1<e.length?n+=2:i==="["||i==="("?n=$(e,n)??n+1:n+=1}let s=e.slice(o,n);t.push({type:ce(s),value:s,offset:o})}return t.push({type:"end",value:"",offset:e.length}),t}a(M,"tokenize");function W(e,t){return e.charAt(t)==="|"&&(e.charAt(t+1)==="|"||/\s/u.test(e.charAt(t-1))&&/\s/u.test(e.charAt(t+1)))}a(W,"isBooleanPipe");function $(e,t){let n=e.charAt(t)==="["?"]":")",r=t+1;for(;r<e.length;){let o=e.charAt(r);if(o==="\\")r+=2;else{if(o===n)return r+1;if(n===")"&&(o==="("||o==="[")){let s=$(e,r);if(s===void 0)return;r=s}else r+=1}}}a($,"regexBlockEnd");function se(e,t){let n=$(e,t);if(n===void 0)return!0;let r=e.slice(t+1,n-1);return r.trim().length===0?!0:C(M(r))}a(se,"isBooleanGroup");function ce(e){return e==="AND"?"and":e==="OR"?"or":e==="NOT"?"not":"term"}a(ce,"operatorType");function ae(e){return e.value.length>0?JSON.stringify(e.value):"the end of the query"}a(ae,"quoteToken");function y(e,t){return new SyntaxError(`Invalid Boolean search query at column ${String(e+1)}: ${t}`)}a(y,"syntaxError");function E(e,t){if(e.kind==="term"){let o=t&&!e.quoted?e.value:B(e.value);return{condition:`(?=.*(?:${o}))`,match:o}}let n=E(e.left,t),r=E(e.right,t);return e.kind==="or"?{condition:`(?:${n.condition}|${r.condition})`,match:`(?:${n.match}|${r.match})`}:e.kind==="not"?{condition:`${n.condition}(?!${r.condition})`,match:n.match}:{condition:`${n.condition}${r.condition}`,match:`(?:${n.match}|${r.match})`}}a(E,"compileExpression");function B(e){return e.replace(/[\\^$.*+?()[\]{}|]/gu,"\\$&")}a(B,"escapeRegex");function Be(e){let t=N(e.query),n=N(e.query,!0),r=_(e.query),o=[];return n!==t&&o.push({query:n,mode:"regex"}),r!==void 0&&r!==t&&r!==n&&o.push({query:r,mode:"words"}),{...e,query:t,regex:!0,fallbacks:o}}a(Be,"createSearchRecipe");async function P(e,t,n){let r=e.query,o=await A(e,t,n),s=[];for(let i of e.fallbacks??[]){if(o.matches.length>0||!o.complete)break;n?.throwIfAborted();try{o=await A({...e,query:i.query,regex:!0},t,n),r=i.query,s.push(i.mode==="regex"?"Search fallback: no literal matches; tried unquoted terms as regex.":"Search fallback: no matches in earlier modes; tried separate words.")}catch(c){if(i.mode!=="regex"||!le(c)||n?.aborted)throw c;s.push("Search fallback: invalid regex skipped; literal search found no matches.")}}return{...o,query:r,notices:s}}a(P,"runSearchRecipe");function le(e){return e instanceof Error&&/regex parse error:|PCRE2: error compiling pattern/iu.test(e.message)}a(le,"isRegexSyntaxError");var de=/^SEARCH#([A-F0-9]{4,64}):(all|[1-9]\d*):(line|match)$/u,z=4;function _e(e,t,n,r){return U(e,t,n,r).slice(0,z)}a(_e,"createSearchSessionId");function U(e,t,n,r){let o=n===void 0?pe(t.map(c=>c.source)):h.resolve(n),s=t.map(c=>({match:c,source:h.relative(o,h.resolve(c.source))})).sort((c,l)=>c.source.localeCompare(l.source)||L(c.match,l.match)).map(({match:c,source:l})=>[l,c.lineNumber,c.startColumn,c.endLineNumber??c.lineNumber,c.endColumn,c.matchedText,c.lineText]),i=K(r??{query:e,regex:!0},o);return ue("sha256").update(JSON.stringify([e,o,i,s])).digest("hex").toUpperCase()}a(U,"createSearchSessionIdentity");function he(e,t){if(!/^[A-F0-9]{64}$/u.test(e))throw new Error("Search session identity must be a 64-character uppercase hexadecimal value.");for(let n=z;n<=e.length;n+=1){let r=e.slice(0,n);if(!t.has(r))return r}throw new Error("Could not allocate a unique search session id.")}a(he,"allocateSearchSessionId");function K(e,t){return{query:e.query,path:h.resolve(t,e.path??"."),include:e.include??"",exclude:e.exclude??"",caseSensitive:e.caseSensitive===!0,wholeWord:e.wholeWord===!0,limit:e.limit??100,regex:e.regex===!0,fallbacks:e.fallbacks??[]}}a(K,"normalizeRecipe");var Q=class{constructor(t=U){this.createIdentity=t}static{a(this,"SearchSessionStore")}#t=new Map;#r=new Map;async register(t,n,r,o,s,i={query:t,regex:!0},c){let l=n.map(p=>({...p,source:h.resolve(p.source)})).sort(L),u=await J(l,s),d=this.createIdentity(t,l,o,i),m=this.#r.get(d)??he(d,new Set(this.#t.keys())),f={id:m,query:t,matches:l,complete:r,contentBySource:u,recipe:i,...c!==void 0&&{refresh:c},cwd:h.resolve(o)};return this.#r.set(d,m),this.#t.set(m,f),f}async observeAfterEdit(t,n){let r=new Set(t.flatMap(s=>{let i=typeof s=="string"?T(s):void 0;return i===void 0?[]:[i.id]})),o=[];for(let s of r){let i=this.#t.get(s);if(i===void 0)continue;let c={sessionId:s,query:i.recipe.originalQuery??i.query,scope:K(i.recipe,i.cwd)};try{let l=i.refresh===void 0?await P(i.recipe,i.cwd,n):await i.refresh(n);o.push({...c,matches:l.matches.length,complete:l.complete,notices:l.notices})}catch(l){o.push({...c,error:l instanceof Error?l.message:String(l)})}}return o}anchorResolver(){return{id:"search",description:["`SEARCH#HASH:N:line` selects one result's full line; `SEARCH#HASH:N:match` selects its exact match.","`SEARCH#HASH:all:line` selects each unique containing line; `SEARCH#HASH:all:match` selects every exact match.","Omit `path` when `all` spans files."].join(`
2
- `),renderFull(t){return t},renderCompact(t){let n=T(t);return n===void 0?"selected result":n.selector==="all"?n.mode==="match"?"all matches":"all lines":n.mode==="match"?`match ${String(n.selector)}`:`line ${String(n.selector)}`},tryResolve:a((t,n)=>this.#i(t,n.source,n.signal),"tryResolve")}}resourceResolver(){return{id:"search-targets",tryResolve:a((t,n)=>this.#s(t,n.cwd),"tryResolve")}}async#i(t,n,r){let o=T(t);if(o===void 0)return{kind:"not-handled"};let s=this.#t.get(o.id);if(s===void 0)return w();if(o.selector==="all"&&!s.complete)return x();let i=h.resolve(n),c=s;if(o.selector==="all"){if(s.refreshedComplete?.complete===!0)c=s.refreshedComplete;else if(s.refreshedComplete!==void 0&&(c=await this.#n(s,r),!c.complete))return x()}let l=k(c,o.selector,o.mode),u=l.filter(m=>m.source===i);if(u.length===0)return{kind:"rejected",rejection:{code:"missing",reason:"search anchor does not select this resource"}};let d=await I(i,r);if(d===void 0)return w(S(u[0]).lineNumber);if(o.selector==="all"&&d!==c.contentBySource.get(i)){if(c=await this.#n(s,r),!c.complete)return x();l=k(c,o.selector,o.mode),u=l.filter(m=>m.source===i)}if(u.length===0)return{kind:"rejected",rejection:{code:"missing",reason:"search anchor does not select this resource"}};if(o.selector!=="all"&&d!==s.contentBySource.get(i))return w(S(u[0]).lineNumber);let g=b(i,d);return{kind:"resolved",anchor:new j(t,i,u.map(m=>G(g,m,o.mode)))}}async#s(t,n){let r=T(t);if(r===void 0)return{kind:"not-handled"};let o=this.#t.get(r.id);if(o===void 0)return w();if(r.selector==="all"&&!o.complete)return x();let s=o;if(r.selector==="all"){if(o.refreshedComplete?.complete===!0)s=o.refreshedComplete;else if(o.refreshedComplete!==void 0&&(s=await this.#n(o),!s.complete))return x();let u=new Set(k(s,r.selector,r.mode).map(d=>d.source));for(let d of u)if(await I(d)!==s.contentBySource.get(d)){if(s=await this.#n(o),!s.complete)return x();break}}let i=k(s,r.selector,r.mode);if(r.selector!=="all"){let u=i[0]?.source;if(u!==void 0&&await I(u)!==s.contentBySource.get(u))return w(i[0]?.lineNumber)}let c=new Map;for(let u of i){let d=c.get(u.source)??[];d.push(G(b(u.source,s.contentBySource.get(u.source)??u.lineText),u,r.mode)),c.set(u.source,d)}let l=[...c].map(([u,d])=>({source:u,ranges:d,expectedContent:s.contentBySource.get(u)}));return l.length===0?{kind:"rejected",rejection:{code:"missing",reason:"search anchor has no matches"}}:{kind:"resolved",targets:l}}async#n(t,n){let r=t.refresh===void 0?await P(t.recipe,t.cwd,n):await t.refresh(n),o=r.matches.map(i=>({...i,source:h.resolve(i.source)})).sort(L),s={matches:o,complete:r.complete,contentBySource:await J(o,n)};return this.#t.set(t.id,{...t,refreshedComplete:s}),s}};function T(e){let t=de.exec(e);if(t!==null)return{id:S(t[1]),selector:t[2]==="all"?"all":Number(t[2]),mode:t[3]==="line"?"line":"match"}}a(T,"parseSearchAnchor");function k(e,t,n){let r=t==="all"?e.matches:[e.matches[t-1]].filter(fe);if(n==="match"||t!=="all")return r;let o=new Set;return r.flatMap(s=>{let i=b(s.source,e.contentBySource.get(s.source)??s.lineText),c=V(s);return i.lines.slice(s.lineNumber-1,c).flatMap(l=>{let u=`${s.source}\0${String(l.lineNumber)}`;return o.has(u)?[]:(o.add(u),[{...s,lineNumber:l.lineNumber,endLineNumber:l.lineNumber,startColumn:0,endColumn:l.content.length,lineText:l.content,matchedText:l.content}])})})}a(k,"selectMatches");function fe(e){return e!==void 0}a(fe,"isMatch");function V(e){let t=e.endLineNumber??e.lineNumber;return t>e.lineNumber&&e.endColumn===0?t-1:t}a(V,"lastContainingLine");function G(e,t,n){if(n==="match")return{start:{lineNumber:t.lineNumber,column:t.startColumn},end:{lineNumber:t.endLineNumber??t.lineNumber,column:t.endColumn}};let r=V(t),o=S(e.lines[r-1]);return{start:{lineNumber:t.lineNumber,column:0},end:{lineNumber:r+(o.lineEnding.length>0?1:0),column:o.lineEnding.length>0?0:o.content.length},linewise:!0}}a(G,"selectionRange");function me(e,t){let n=t.endLineNumber??t.lineNumber;return e.lines.slice(t.lineNumber-1,n).map(r=>{let o=r.lineNumber===t.lineNumber?t.startColumn:0,s=r.lineNumber===n?t.endColumn:r.content.length;return r.content.slice(o,s)+(r.lineNumber===n?"":r.lineEnding)}).join("")}a(me,"matchedSourceText");async function J(e,t){let n=new Map;for(let r of new Set(e.map(o=>o.source))){let o=await q(r,{encoding:"utf8",...t!==void 0&&{signal:t}}),s=b(r,o);for(let i of e.filter(c=>c.source===r))if(s.lines[i.lineNumber-1]?.content!==i.lineText||me(s,i)!==i.matchedText)throw new Error(`Search result in ${r} changed before its anchors were registered.`);n.set(r,o)}return n}a(J,"snapshotContents");async function I(e,t){try{return await q(e,{encoding:"utf8",...t!==void 0&&{signal:t}})}catch{return}}a(I,"readCurrent");function w(e=1){return{kind:"rejected",rejection:{code:"stale",reason:"search anchor is stale",contextRange:{offset:Math.max(1,e-2),limit:5}}}}a(w,"staleAnchor");function x(){return{kind:"rejected",rejection:{code:"missing",reason:"search did not register an all anchor because its result was limited"}}}a(x,"missingCompleteAnchor");function pe(e){if(e.length===0)return".";let t=h.dirname(h.resolve(S(e[0])));for(let n of e.slice(1)){let r=h.resolve(n);for(;!ge(t,r);){let o=h.dirname(t);if(o===t)return t;t=o}}return t}a(pe,"commonSourceDirectory");function ge(e,t){let n=h.relative(e,t);return n!==".."&&!n.startsWith(`..${h.sep}`)&&!h.isAbsolute(n)}a(ge,"isWithin");function L(e,t){return e.source.localeCompare(t.source)||e.lineNumber-t.lineNumber||e.startColumn-t.startColumn||(e.endLineNumber??e.lineNumber)-(t.endLineNumber??t.lineNumber)||e.endColumn-t.endColumn}a(L,"compareMatches");export{F as a,Be as b,P as c,_e as d,U as e,he as f,Q as g};
@@ -1 +0,0 @@
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 p(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`);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=c(t.parameters,t.name);d(o,t.source.field,`${t.name} primary source`);let a=new Set([t.source.field]);for(let e of t.source.targets??[]){if(d(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(d(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(p,"assertTextMutationToolRegistration");function u(t,n){let o=n[t.source.field];return typeof o=="string"?o:""}r(u,"mutationSource");function c(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(c,"schemaProperties");function d(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(d,"assertProperty");export{l as a,p as b,u as c};