pi-agent-ide 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +74 -22
  3. package/assets/gallery/apply-editing.png +0 -0
  4. package/assets/gallery/debugging.png +0 -0
  5. package/assets/gallery/read-web.png +0 -0
  6. package/assets/gallery/search-replace.png +0 -0
  7. package/assets/gallery/terminal.png +0 -0
  8. package/assets/gallery/tool-editing.png +0 -0
  9. package/dist/chunk-25CZ5ZIU.js +3 -0
  10. package/dist/chunk-526E364R.js +3 -0
  11. package/dist/chunk-5PLV4HLG.js +1 -0
  12. package/dist/chunk-5QQABP47.js +14 -0
  13. package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
  14. package/dist/chunk-7ALCBKCW.js +26 -0
  15. package/dist/chunk-AWXVJ5AC.js +1 -0
  16. package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
  17. package/dist/chunk-ESPNEJHK.js +1 -0
  18. package/dist/chunk-G725MARR.js +16 -0
  19. package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
  20. package/dist/chunk-IQD6PON5.js +0 -0
  21. package/dist/chunk-IRECDTJG.js +27 -0
  22. package/dist/chunk-J4RTW44E.js +1 -0
  23. package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
  24. package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
  25. package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
  26. package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
  27. package/dist/chunk-NZYDMBM6.js +1 -0
  28. package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
  29. package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
  30. package/dist/chunk-P7XO5CIP.js +2 -0
  31. package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
  32. package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
  33. package/dist/chunk-U2JKHKLK.js +0 -0
  34. package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.js} +1 -1
  35. package/dist/entry-10.js +1 -1
  36. package/dist/entry-11.js +1 -1
  37. package/dist/entry-12.js +1 -1
  38. package/dist/entry-13.js +1 -1
  39. package/dist/entry-14.js +1 -1
  40. package/dist/entry-15.js +1 -0
  41. package/dist/entry-17.js +1 -1
  42. package/dist/entry-18.js +1 -1
  43. package/dist/entry-19.js +1 -1
  44. package/dist/entry-20.js +1 -1
  45. package/dist/entry-21.js +1 -2
  46. package/dist/entry-22.js +2 -1
  47. package/dist/entry-23.js +1 -1
  48. package/dist/entry-24.js +1 -1
  49. package/dist/entry-25.js +1 -1
  50. package/dist/entry-26.js +1 -12
  51. package/dist/entry-27.js +12 -1
  52. package/dist/entry-28.js +1 -1
  53. package/dist/entry-29.js +1 -1
  54. package/dist/entry-30.js +1 -1
  55. package/dist/entry-31.js +1 -4
  56. package/dist/entry-32.js +3 -8
  57. package/dist/entry-33.js +9 -1
  58. package/dist/entry-34.js +1 -1
  59. package/dist/entry-35.js +1 -1
  60. package/dist/entry-36.js +1 -1
  61. package/dist/entry-37.js +1 -1
  62. package/dist/entry-38.js +1 -1
  63. package/dist/entry-39.js +1 -1
  64. package/dist/entry-40.js +1 -18
  65. package/dist/entry-41.js +18 -1
  66. package/dist/entry-42.js +1 -1
  67. package/dist/entry-43.js +1 -1
  68. package/dist/entry-44.js +1 -1
  69. package/dist/entry-45.js +1 -7
  70. package/dist/entry-46.js +7 -11
  71. package/dist/entry-47.js +11 -1
  72. package/dist/entry-48.js +1 -1
  73. package/dist/entry-49.js +1 -1
  74. package/dist/entry-50.js +1 -1
  75. package/dist/entry-51.js +1 -1
  76. package/dist/entry-52.js +1 -1
  77. package/dist/entry-53.js +1 -1
  78. package/dist/entry-54.js +1 -1
  79. package/dist/entry-55.js +1 -0
  80. package/dist/entry-56.js +0 -1
  81. package/dist/entry-57.js +1 -0
  82. package/dist/entry-58.js +0 -1
  83. package/dist/entry-59.js +1 -1
  84. package/dist/entry-60.js +1 -1
  85. package/dist/entry-61.js +1 -1
  86. package/dist/entry-62.js +1 -1
  87. package/dist/entry-63.js +1 -1
  88. package/dist/entry-64.js +1 -0
  89. package/dist/entry-65.js +0 -1
  90. package/dist/entry-66.js +1 -0
  91. package/dist/entry-67.js +0 -1
  92. package/dist/entry-68.js +1 -1
  93. package/dist/entry-69.js +1 -1
  94. package/dist/entry-70.js +1 -123
  95. package/dist/entry-71.js +198 -25
  96. package/dist/entry-72.js +30 -2
  97. package/dist/entry-73.js +2 -1
  98. package/dist/entry-74.js +1 -1
  99. package/dist/entry-75.js +1 -1
  100. package/dist/entry-76.js +3 -3
  101. package/dist/entry-77.js +3 -1
  102. package/dist/entry-78.js +1 -1
  103. package/dist/entry-79.js +1 -1
  104. package/dist/entry-8.js +1 -1
  105. package/dist/entry-80.js +1 -0
  106. package/dist/entry-9.js +1 -1
  107. package/dist/pi-agent-ide.js +3 -3
  108. package/docs/configuration.md +1 -1
  109. package/docs/development.md +0 -6
  110. package/docs/user-hooks.md +68 -0
  111. package/node_modules/pi-agent-doctor/package.json +6 -6
  112. package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
  113. package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
  114. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -0
  115. package/node_modules/pi-agent-filesystem/package.json +7 -7
  116. package/node_modules/pi-agent-filesystem-image/package.json +4 -4
  117. package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
  118. package/node_modules/pi-agent-filesystem-text/package.json +4 -4
  119. package/node_modules/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  120. package/node_modules/pi-agent-ide-ast/package.json +32 -11
  121. package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  122. package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  123. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  124. package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  125. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  126. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  127. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  128. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  129. package/node_modules/pi-agent-ide-changes/index.ts +3 -1
  130. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  131. package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  132. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  133. package/node_modules/pi-agent-ide-formatter/package.json +9 -4
  134. package/node_modules/pi-agent-ide-languages/package.json +3 -3
  135. package/node_modules/pi-agent-ide-lint/package.json +13 -8
  136. package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
  137. package/node_modules/pi-agent-ide-lsp/package.json +15 -10
  138. package/node_modules/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  139. package/node_modules/pi-agent-image/package.json +3 -3
  140. package/node_modules/pi-agent-invariant/package.json +2 -2
  141. package/node_modules/pi-agent-pdf/package.json +3 -3
  142. package/node_modules/pi-agent-read/package.json +11 -11
  143. package/node_modules/pi-agent-read/runtime/entry-40.js +0 -1
  144. package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
  145. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  146. package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
  147. package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
  148. package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
  149. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  150. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  151. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  152. package/node_modules/pi-agent-resource/package.json +2 -2
  153. package/node_modules/pi-agent-search/package.json +7 -7
  154. package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
  155. package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
  156. package/node_modules/pi-agent-search-text/index.ts +1 -1
  157. package/node_modules/pi-agent-search-text/package.json +9 -9
  158. package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
  159. package/node_modules/pi-agent-search-text/src/resolvers.ts +72 -39
  160. package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
  161. package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
  162. package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
  163. package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
  164. package/node_modules/pi-agent-search-text/src/search-session.ts +33 -4
  165. package/node_modules/pi-agent-text/package.json +3 -3
  166. package/node_modules/pi-agent-text/runtime/entry-49.js +1 -0
  167. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  168. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  169. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  170. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  171. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  172. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  173. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  174. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  175. package/node_modules/pi-agent-text-editor/package.json +25 -25
  176. package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
  177. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  178. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  179. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  180. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  181. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  182. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  183. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  184. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  185. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  186. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  187. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  188. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  189. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  190. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  191. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  192. package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
  193. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  194. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  195. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  196. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  197. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  198. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  199. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  200. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  201. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  202. package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
  203. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  204. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  205. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  206. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  207. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  208. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  209. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +1 -0
  210. package/node_modules/pi-agent-web/package.json +7 -7
  211. package/node_modules/pi-agent-web/src/resolver.ts +128 -1
  212. package/node_modules/pi-agent-web-html/package.json +3 -3
  213. package/node_modules/pi-agent-web-image/package.json +4 -4
  214. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  215. package/node_modules/pi-agent-web-text/package.json +4 -4
  216. package/node_modules/pi-agent-web-text/runtime/entry-80.js +2 -0
  217. package/package.json +59 -39
  218. package/src/api/hooks.ts +168 -0
  219. package/src/api/text-editor.ts +2 -0
  220. package/src/composite/builtin-extensions.ts +7 -0
  221. package/src/composite/module-labels.ts +8 -0
  222. package/src/composite/preferences.ts +3 -3
  223. package/src/core/reload-resource-store.ts +34 -0
  224. package/src/doctor/tip-provider.ts +1 -0
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  230. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +2 -0
  231. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  232. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  233. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  234. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  235. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  236. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +2 -0
  237. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
  238. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +128 -1
  239. package/src/extensions/pi-agent-read/package.json +11 -11
  240. package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
  241. package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
  242. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  243. package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
  244. package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
  245. package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
  246. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  247. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  248. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  249. package/src/extensions/pi-agent-search/package.json +7 -7
  250. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  251. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
  252. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
  253. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
  254. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +72 -39
  255. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
  256. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
  257. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
  258. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
  259. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +33 -4
  260. package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
  261. package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
  262. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
  263. package/src/extensions/pi-agent-text-editor/package.json +25 -25
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  268. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  269. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  270. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  271. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  272. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -0
  273. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  274. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  275. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  276. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  277. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
  278. package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
  279. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  280. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  281. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  282. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  283. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  284. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  285. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  286. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  287. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  288. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  289. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  290. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  291. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  292. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  293. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  294. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
  295. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  296. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  297. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  298. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  299. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  300. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  301. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  302. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  303. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  304. package/src/plugins/pi-agent-ide-ast/package.json +32 -11
  305. package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  306. package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  307. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  308. package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  309. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  310. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  311. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  312. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  313. package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
  314. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  315. package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  316. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  317. package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
  318. package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
  319. package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
  320. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
  321. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
  322. package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
  323. package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
  324. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
  325. package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
  326. package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
  327. package/src/plugins/pi-agent-ide-languages/package.json +3 -3
  328. package/src/plugins/pi-agent-ide-lint/package.json +13 -8
  329. package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
  330. package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
  331. package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  332. package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
  333. package/src/plugins/pi-agent-ide-processes/src/registry.ts +83 -0
  334. package/src/plugins/pi-agent-ide-processes/src/ui.ts +260 -0
  335. package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
  336. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
  337. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +31 -0
  338. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
  339. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
  340. package/src/plugins/pi-agent-ide-terminal/src/search.ts +32 -2
  341. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
  342. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
  343. package/src/plugins/pi-agent-ide-terminal/src/types.ts +14 -1
  344. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
  345. package/dist/chunk-3SE372WC.js +0 -3
  346. package/dist/chunk-5MSNYFDE.js +0 -1
  347. package/dist/chunk-7JYQMAEL.js +0 -14
  348. package/dist/chunk-B5KB2I7J.js +0 -3
  349. package/dist/chunk-NMFQGKPE.js +0 -2
  350. package/dist/chunk-OVUYPHDE.js +0 -1
  351. package/dist/chunk-TPIHQYK2.js +0 -14
  352. package/dist/chunk-XSTHESNR.js +0 -25
  353. package/dist/entry-16.js +0 -1
  354. package/docs/evaluation.md +0 -14
  355. package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
  356. package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
  357. package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  358. package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  359. package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
  360. package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
  361. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  362. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  363. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  364. package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
  365. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
  366. package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
  367. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
  368. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
  369. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
  370. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
  371. package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
  372. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
  373. package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
  374. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  375. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  376. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  377. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
  378. package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
  379. package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  380. package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  381. /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
  382. /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
  383. /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
  384. /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  385. /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  386. /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  387. /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
  388. /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
  389. /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
  390. /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
  391. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
  392. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
  393. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
  394. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
  395. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
  396. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
  397. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
  398. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
  399. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
  400. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
  401. /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
  402. /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
  403. /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
  404. /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
  405. /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
  406. /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
  407. /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  408. /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  409. /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  410. /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
@@ -0,0 +1,573 @@
1
+ import path from "node:path";
2
+ import { access } from "node:fs/promises";
3
+
4
+ import { StringEnum } from "@earendil-works/pi-ai";
5
+ import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
+ import { Type } from "typebox";
7
+ import { connectDoctorPlugin } from "pi-agent-doctor/api/connect-plugin";
8
+ import { connectReadPlugin } from "pi-agent-read/api/connect-plugin";
9
+ import {
10
+ READ_API_VERSION,
11
+ READ_PROTOCOL,
12
+ type ReadPlugin,
13
+ } from "pi-agent-read/api/plugin-protocol";
14
+ import { connectTextEditorPlugin } from "pi-agent-text-editor/api/connect-plugin";
15
+ import {
16
+ TEXT_EDITOR_API_VERSION,
17
+ TEXT_EDITOR_PROTOCOL,
18
+ type TextEditorPlugin,
19
+ } from "pi-agent-text-editor/api/plugin-protocol";
20
+ import type { ResourceResolver } from "pi-agent-resource";
21
+ import { toolCallHeader } from "pi-agent-tool-ui";
22
+
23
+ import {
24
+ forgetReloadResource,
25
+ retainReloadResource,
26
+ takeReloadResource,
27
+ } from "#src/core/reload-resource-store.js";
28
+ import { debuggerDoctorPlugin } from "#src/plugins/pi-agent-ide-debugger/src/doctor-plugin.js";
29
+ import { createBreakpointPresenter } from "#src/plugins/pi-agent-ide-debugger/src/breakpoint-view.js";
30
+ import {
31
+ renderDebugActionCall,
32
+ renderDebugCall,
33
+ renderDebugResult,
34
+ } from "#src/plugins/pi-agent-ide-debugger/src/renderer.js";
35
+ import { debuggerSnapshotFromResult } from "#src/plugins/pi-agent-ide-debugger/src/ui.js";
36
+ import { debuggerProcessProvider } from "#src/plugins/pi-agent-ide-debugger/src/process-provider.js";
37
+ import { agentIdeProcessRegistry } from "#src/plugins/pi-agent-ide-processes/src/registry.js";
38
+
39
+ interface DebugToolDetails {
40
+ readonly source?: string;
41
+ readonly sourceResource?: string;
42
+ readonly breakpointsResource?: string;
43
+ readonly adapter:
44
+ | "dart"
45
+ | "debugpy"
46
+ | "delve"
47
+ | "java"
48
+ | "elixir"
49
+ | "julia"
50
+ | "kotlin"
51
+ | "lldb-dap"
52
+ | "lua"
53
+ | "netcoredbg"
54
+ | "node"
55
+ | "php"
56
+ | "powershell"
57
+ | "r"
58
+ | "ruby"
59
+ | "shell";
60
+ readonly program: string;
61
+ readonly sourceFile?: string;
62
+ readonly cwd: string;
63
+ readonly status: string;
64
+ readonly breakpoints?: readonly unknown[];
65
+ readonly stop?: unknown;
66
+ readonly snapshot?: unknown;
67
+ }
68
+
69
+ import {
70
+ DebugSessionManager,
71
+ renderDebugSession,
72
+ type DebugSession,
73
+ } from "#src/plugins/pi-agent-ide-debugger/src/session-manager.js";
74
+
75
+ const debugParameters = Type.Object(
76
+ {
77
+ adapter: StringEnum(
78
+ [
79
+ "dart",
80
+ "debugpy",
81
+ "delve",
82
+ "java",
83
+ "elixir",
84
+ "julia",
85
+ "kotlin",
86
+ "lldb-dap",
87
+ "lua",
88
+ "netcoredbg",
89
+ "node",
90
+ "php",
91
+ "powershell",
92
+ "r",
93
+ "ruby",
94
+ "shell",
95
+ ] as const,
96
+ {
97
+ description:
98
+ "Select an installed DAP adapter for Dart, Python, Go, Java, Elixir, Julia, Kotlin, C, C++, Rust, Swift, Zig, Lua, C#, JavaScript, TypeScript, PHP, PowerShell, R, Ruby, or shell scripts.",
99
+ },
100
+ ),
101
+ program: Type.String({
102
+ minLength: 1,
103
+ description: "Source file or executable to launch. Relative paths resolve from cwd.",
104
+ }),
105
+ source: Type.Optional(
106
+ Type.String({
107
+ description: "Source file used for anchored breakpoints. Defaults to program.",
108
+ }),
109
+ ),
110
+ args: Type.Optional(
111
+ Type.Array(Type.String(), { description: "Arguments passed to the debugged program." }),
112
+ ),
113
+ mainClass: Type.Optional(
114
+ Type.String({
115
+ minLength: 1,
116
+ description: "Fully qualified JVM main class. Required by Java and Kotlin adapters.",
117
+ }),
118
+ ),
119
+ cwd: Type.Optional(
120
+ Type.String({ description: "Working directory. Relative paths resolve from the workspace." }),
121
+ ),
122
+ },
123
+ { additionalProperties: false },
124
+ );
125
+
126
+ /** Register agent-native debug sessions backed by Debug Adapter Protocol adapters. */
127
+ export default async function registerDebugger(pi: ExtensionAPI): Promise<void> {
128
+ const manager =
129
+ (takeReloadResource("debugger") as DebugSessionManager | undefined) ??
130
+ new DebugSessionManager();
131
+ const deletedSnapshots = new Map<string, ReturnType<DebugSessionManager["snapshot"]>>();
132
+ const readResolver = createDebugResourceResolver(manager, "debugger-source");
133
+ const editorResolver = createDebugResourceResolver(manager, "debugger-input");
134
+ const removeProcessProvider = agentIdeProcessRegistry(pi).add(debuggerProcessProvider(manager));
135
+ const breakpointPresenter = createBreakpointPresenter(manager);
136
+ const readPlugin = {
137
+ protocol: READ_PROTOCOL,
138
+ apiVersion: READ_API_VERSION,
139
+ id: "debugger",
140
+ setup(api) {
141
+ api.addResolver({
142
+ resolver: readResolver,
143
+ matchesCall: (source) => manager.sourceFile(source) !== undefined,
144
+ renderCall(arguments_, theme, context) {
145
+ const input = isRecord(arguments_) ? arguments_ : {};
146
+ const source = typeof input.path === "string" ? input.path : "";
147
+ const session = manager.get(source);
148
+ const sourceFile = manager.sourceFile(source);
149
+ if (session === undefined || sourceFile === undefined) {
150
+ throw new Error("Debugger source header lost its session");
151
+ }
152
+ const relative = path.relative(session.options.cwd, sourceFile);
153
+ const views = Array.isArray(input.views)
154
+ ? input.views.filter((view): view is string => typeof view === "string")
155
+ : [];
156
+ const offset = typeof input.offset === "number" ? input.offset : 1;
157
+ const limit = typeof input.limit === "number" ? input.limit : undefined;
158
+ const range = limit === undefined ? String(offset) : `${offset}-${offset + limit - 1}`;
159
+ return toolCallHeader(
160
+ context.lastComponent,
161
+ {
162
+ tool: "debug file",
163
+ primary: { text: `${relative}:${range}`, color: "accent", underline: true },
164
+ qualifiers: views.length === 0 ? [] : [{ text: `views ${views.join(",")}` }],
165
+ details: [
166
+ { label: "source", value: source },
167
+ { label: "file", value: sourceFile },
168
+ ...(views.length === 0 ? [] : [{ label: "views", value: views.join(",") }]),
169
+ ],
170
+ expanded: context.expanded,
171
+ },
172
+ theme,
173
+ );
174
+ },
175
+ });
176
+ api.addView({ view: "breakpoints", presenter: breakpointPresenter });
177
+ api.describe(
178
+ 'views: ["breakpoints"] — show current debugger breakpoints beside source lines. On a normal file, all current sessions are included; on a debug source, results are session-scoped. debug:<session> — debugger state. Read the returned debug source before selecting a breakpoint line.',
179
+ );
180
+ api.addPromptGuideline(
181
+ 'Use views: ["breakpoints"] when current breakpoint locations matter. Create a debug session with debug. Set adapter to elixir for Elixir or r for R. Read the returned debug source to get current anchors, insert text "breakpoint" at one source anchor, then insert "start" on the session. Use read for the latest stop and delete for a breakpoint or the session.',
182
+ );
183
+ },
184
+ } satisfies ReadPlugin;
185
+ const editorPlugin = {
186
+ protocol: TEXT_EDITOR_PROTOCOL,
187
+ apiVersion: TEXT_EDITOR_API_VERSION,
188
+ id: "debugger",
189
+ setup(api) {
190
+ api.addResolver({ resolver: editorResolver });
191
+ api.tool("insert").addSemanticHandler({
192
+ matches: (input) => matchesDebugInsert(input, manager),
193
+ execute: async (context, input) => {
194
+ const parameters = input as {
195
+ readonly path: string;
196
+ readonly anchor?: string;
197
+ readonly text: string;
198
+ };
199
+ const session = requiredSession(manager, parameters.path);
200
+ if (manager.sourceFile(parameters.path) !== undefined) {
201
+ if (parameters.text !== "breakpoint" || parameters.anchor === undefined) {
202
+ throw new Error('A debug source accepts text "breakpoint" with one anchor');
203
+ }
204
+ const anchor = await context.resolveAnchor("anchor");
205
+ const breakpoint = await manager.addBreakpoint(
206
+ parameters.path,
207
+ anchor.lineNumber,
208
+ context.signal,
209
+ );
210
+ return {
211
+ source: breakpoint.source,
212
+ summary: `Breakpoint ${breakpoint.source} created at ${path.relative(session.options.cwd, breakpoint.file)}:${breakpoint.line}.`,
213
+ data: {
214
+ kind: "debug-breakpoint",
215
+ session: session.source,
216
+ file: breakpoint.file,
217
+ line: breakpoint.line,
218
+ verified: breakpoint.verified,
219
+ snapshot: manager.snapshot(session),
220
+ },
221
+ };
222
+ }
223
+ if (parameters.path !== session.source || parameters.anchor !== undefined) {
224
+ throw new Error("Debug commands target the session resource without an anchor");
225
+ }
226
+ await executeSessionCommand(manager, session, parameters.text, context.signal);
227
+ return {
228
+ source: session.source,
229
+ summary: renderDebugSession(session),
230
+ data: debugActionData(manager, session, parameters.text),
231
+ };
232
+ },
233
+ });
234
+ api.tool("delete").addSemanticHandler({
235
+ matches: (input) => matchesDebugDelete(input, manager),
236
+ execute: async (context, input) => {
237
+ const source = (input as { readonly path: string }).path;
238
+ const session = requiredSession(manager, source);
239
+ const before = manager.snapshot(session);
240
+ deletedSnapshots.set(source, before);
241
+ const deletingBreakpoint = source.includes("/breakpoint/");
242
+ await manager.delete(source, context.signal);
243
+ const snapshot = deletingBreakpoint
244
+ ? manager.snapshot(session)
245
+ : { ...before, status: "terminated" as const };
246
+ return {
247
+ source,
248
+ summary: `Deleted ${source}.`,
249
+ data: {
250
+ kind: deletingBreakpoint ? "debug-breakpoint" : "debug-session",
251
+ deleted: true,
252
+ snapshot,
253
+ },
254
+ };
255
+ },
256
+ });
257
+ api.describe(
258
+ 'For debug:<session> resources, insert performs debugger actions without changing source text. On a debug source, insert "breakpoint" at an anchor. On the session, insert start, continue, step over, step into, or step out. Delete removes a breakpoint or terminates the session.',
259
+ );
260
+ for (const tool of ["insert", "delete"] as const) {
261
+ api.addToolRenderer({
262
+ tool,
263
+ matches(value, phase) {
264
+ if (phase === "call") {
265
+ return (
266
+ isRecord(value) &&
267
+ typeof value.path === "string" &&
268
+ (manager.get(value.path) !== undefined || deletedSnapshots.has(value.path))
269
+ );
270
+ }
271
+ return (
272
+ debuggerSnapshotFromResult(
273
+ isRecord(value) && "details" in value ? value.details : value,
274
+ ) !== undefined
275
+ );
276
+ },
277
+ renderCall(arguments_, theme, context) {
278
+ const input = arguments_ as { readonly path?: string; readonly text?: string };
279
+ const session = input.path === undefined ? undefined : manager.get(input.path);
280
+ const deletedSnapshot =
281
+ input.path === undefined ? undefined : deletedSnapshots.get(input.path);
282
+ const state = context.state as {
283
+ snapshot?: ReturnType<DebugSessionManager["snapshot"]>;
284
+ };
285
+ if (session !== undefined) state.snapshot = manager.snapshot(session);
286
+ else if (deletedSnapshot !== undefined) state.snapshot = deletedSnapshot;
287
+ const snapshot = state.snapshot;
288
+ if (snapshot === undefined) throw new Error("Debugger renderer lost its session");
289
+ const breakpoint =
290
+ input.path === undefined
291
+ ? undefined
292
+ : (manager.breakpoint(input.path) ??
293
+ snapshot.breakpoints.find((candidate) => candidate.source === input.path));
294
+ const sourceFile =
295
+ input.path === undefined ? undefined : manager.sourceFile(input.path);
296
+ const action =
297
+ tool === "delete"
298
+ ? breakpoint === undefined
299
+ ? "delete-session"
300
+ : `delete-breakpoint ${path.basename(breakpoint.file)}:${breakpoint.line}`
301
+ : input.text === "breakpoint" && sourceFile !== undefined
302
+ ? `breakpoint ${path.basename(sourceFile)}:${breakpointLine(input)}`
303
+ : (input.text ?? "debug action");
304
+ return renderDebugActionCall(snapshot, action, theme);
305
+ },
306
+ renderResult(result, options, theme) {
307
+ const snapshot = debuggerSnapshotFromResult(result.details);
308
+ if (snapshot === undefined) throw new Error("Debugger result is missing its session");
309
+ return renderDebugResult(snapshot, options.expanded, theme);
310
+ },
311
+ });
312
+ }
313
+ },
314
+ } satisfies TextEditorPlugin;
315
+
316
+ await Promise.all([
317
+ connectDoctorPlugin(pi, debuggerDoctorPlugin),
318
+ connectReadPlugin(pi, readPlugin),
319
+ ]);
320
+ await connectTextEditorPlugin(pi, editorPlugin);
321
+
322
+ pi.registerTool(
323
+ defineTool<typeof debugParameters, DebugToolDetails>({
324
+ name: "debug",
325
+ label: "Debug session",
326
+ promptSnippet: "Create a local DAP debug session before setting anchored breakpoints",
327
+ promptGuidelines: [
328
+ "Use the returned debug source resource rather than the filesystem path when setting breakpoints; its anchors are checked against fresh text without editing that text.",
329
+ "Use java for Java, kotlin for Kotlin, lldb-dap for C, C++, Rust, Swift, or Zig, and julia for Julia.",
330
+ "Use lldb-dap for C, C++, Rust, Swift, or Zig; use julia for Julia.",
331
+ "Use elixir for Elixir; use r for R.",
332
+ ],
333
+ description:
334
+ "Use debug to create a configured local debugger session. This does not launch the program yet. Sessions survive extension reloads and keep the same debug: resources. Read the returned debug source, set breakpoints with insert, then start and control execution by inserting commands on the session resource.",
335
+ parameters: debugParameters,
336
+ async execute(_toolCallId, input, _signal, _onUpdate, context) {
337
+ const cwd = path.resolve(context.cwd, input.cwd ?? ".");
338
+ const program = path.resolve(cwd, input.program);
339
+ try {
340
+ await access(program);
341
+ const session = manager.create({
342
+ adapter: input.adapter,
343
+ program,
344
+ sourceFile: path.resolve(cwd, input.source ?? input.program),
345
+ args: input.args ?? [],
346
+ cwd,
347
+ ...(input.mainClass === undefined ? {} : { mainClass: input.mainClass }),
348
+ });
349
+ const details = debugDetails(manager, session);
350
+ return {
351
+ content: [
352
+ {
353
+ type: "text",
354
+ text: `${renderDebugSession(session)}\nSource: ${details.sourceResource}\nBreakpoints: ${details.breakpointsResource}\n\nNext: read ${details.sourceResource} with views ["anchors"], then insert a breakpoint at an anchor.`,
355
+ },
356
+ ],
357
+ details,
358
+ };
359
+ } catch (error) {
360
+ return {
361
+ content: [
362
+ { type: "text", text: error instanceof Error ? error.message : String(error) },
363
+ ],
364
+ details: { adapter: input.adapter, program, cwd, status: "failed" },
365
+ isError: true,
366
+ };
367
+ }
368
+ },
369
+ renderCall(input, theme) {
370
+ const cwd = path.resolve(process.cwd(), typeof input.cwd === "string" ? input.cwd : ".");
371
+ const program = path.resolve(
372
+ cwd,
373
+ typeof input.program === "string" ? input.program : "program",
374
+ );
375
+ return renderDebugCall(
376
+ typeof input.adapter === "string" ? input.adapter : "debugger",
377
+ program,
378
+ cwd,
379
+ theme,
380
+ );
381
+ },
382
+ renderResult(result, options, theme) {
383
+ const snapshot = isRecord(result.details) ? result.details.snapshot : undefined;
384
+ if (typeof snapshot === "object" && snapshot !== null) {
385
+ return renderDebugResult(
386
+ snapshot as ReturnType<DebugSessionManager["snapshot"]>,
387
+ options.expanded,
388
+ theme,
389
+ );
390
+ }
391
+ const details = result.details;
392
+ return renderDebugCall(details.adapter, details.program, details.cwd, theme);
393
+ },
394
+ }),
395
+ );
396
+
397
+ pi.on("session_shutdown", (event) => {
398
+ removeProcessProvider();
399
+ if (event.reason !== "quit") {
400
+ retainReloadResource("debugger", manager);
401
+ return;
402
+ }
403
+ forgetReloadResource("debugger", manager);
404
+ manager.dispose();
405
+ });
406
+ }
407
+
408
+ function createDebugResourceResolver(manager: DebugSessionManager, id: string): ResourceResolver {
409
+ return {
410
+ id,
411
+ tryResolve(source) {
412
+ const session = manager.get(source);
413
+ if (session === undefined) return Promise.resolve({ kind: "not-handled" });
414
+ return Promise.resolve({
415
+ kind: "resolved",
416
+ resource: {
417
+ source,
418
+ async read() {
419
+ const sourceFile = manager.sourceFile(source);
420
+ if (sourceFile !== undefined) {
421
+ return [debugSourceContent(sourceFile, await manager.readSource(source))];
422
+ }
423
+ if (source === `${session.source}/breakpoints`) {
424
+ return [{ type: "text" as const, text: renderBreakpointList(session) }];
425
+ }
426
+ const breakpoint = manager.breakpoint(source);
427
+ if (source !== session.source && breakpoint === undefined) {
428
+ throw new Error(`Unknown debug resource ${source}`);
429
+ }
430
+ const text =
431
+ breakpoint === undefined
432
+ ? renderDebugSession(session)
433
+ : `Breakpoint: ${breakpoint.source}\nFile: ${breakpoint.file}\nLine: ${breakpoint.line}\nStatus: ${breakpoint.verified ? "verified" : "pending"}`;
434
+ return [{ type: "text" as const, text }];
435
+ },
436
+ },
437
+ });
438
+ },
439
+ };
440
+ }
441
+
442
+ function matchesDebugInsert(input: unknown, manager: DebugSessionManager): boolean {
443
+ if (!isRecord(input) || typeof input.path !== "string" || typeof input.text !== "string")
444
+ return false;
445
+ const session = manager.get(input.path);
446
+ return (
447
+ session !== undefined &&
448
+ (input.path === session.source || manager.sourceFile(input.path) !== undefined)
449
+ );
450
+ }
451
+
452
+ function matchesDebugDelete(input: unknown, manager: DebugSessionManager): boolean {
453
+ if (!isRecord(input) || typeof input.path !== "string") return false;
454
+ const session = manager.get(input.path);
455
+ return (
456
+ session !== undefined &&
457
+ (input.path === session.source || input.path.startsWith(`${session.source}/breakpoint/`))
458
+ );
459
+ }
460
+
461
+ async function executeSessionCommand(
462
+ manager: DebugSessionManager,
463
+ session: DebugSession,
464
+ command: string,
465
+ signal?: AbortSignal,
466
+ ): Promise<void> {
467
+ switch (command.trim().toLowerCase()) {
468
+ case "start": {
469
+ await manager.start(session, signal);
470
+ return;
471
+ }
472
+ case "continue": {
473
+ await manager.command(session, "continue", signal);
474
+ return;
475
+ }
476
+ case "step over": {
477
+ await manager.command(session, "next", signal);
478
+ return;
479
+ }
480
+ case "step into": {
481
+ await manager.command(session, "stepIn", signal);
482
+ return;
483
+ }
484
+ case "step out": {
485
+ await manager.command(session, "stepOut", signal);
486
+ return;
487
+ }
488
+ default: {
489
+ throw new Error(`Unknown debug command ${JSON.stringify(command)}`);
490
+ }
491
+ }
492
+ }
493
+
494
+ function debugDetails(manager: DebugSessionManager, session: DebugSession) {
495
+ return {
496
+ source: session.source,
497
+ sourceResource: manager.sourceResource(session),
498
+ breakpointsResource: `${session.source}/breakpoints`,
499
+ adapter: session.options.adapter,
500
+ program: session.options.program,
501
+ cwd: session.options.cwd,
502
+ status: session.status,
503
+ breakpoints: [...session.breakpoints.values()].map(({ source, file, line, verified }) => ({
504
+ source,
505
+ file,
506
+ line,
507
+ verified,
508
+ })),
509
+ ...(session.stop === undefined ? {} : { stop: session.stop }),
510
+ snapshot: manager.snapshot(session),
511
+ };
512
+ }
513
+
514
+ function debugActionData(
515
+ manager: DebugSessionManager,
516
+ session: DebugSession,
517
+ command: string,
518
+ ): Readonly<Record<string, unknown>> {
519
+ return {
520
+ kind: "debug-command",
521
+ command,
522
+ status: session.status,
523
+ breakpoints: [...session.breakpoints.values()].map(({ source, file, line, verified }) => ({
524
+ source,
525
+ file,
526
+ line,
527
+ verified,
528
+ })),
529
+ ...(session.stop === undefined ? {} : { stop: session.stop }),
530
+ snapshot: manager.snapshot(session),
531
+ };
532
+ }
533
+
534
+ function renderBreakpointList(session: DebugSession): string {
535
+ if (session.breakpoints.size === 0) return `No breakpoints in ${session.source}.`;
536
+ return [...session.breakpoints.values()]
537
+ .map(
538
+ (breakpoint) =>
539
+ `${breakpoint.verified ? "●" : "○"} ${breakpoint.file}:${breakpoint.line} · ${breakpoint.source}`,
540
+ )
541
+ .join("\n");
542
+ }
543
+
544
+ function requiredSession(manager: DebugSessionManager, source: string): DebugSession {
545
+ const session = manager.get(source);
546
+ if (session === undefined) throw new Error(`Unknown debug session ${source}`);
547
+ return session;
548
+ }
549
+
550
+ function breakpointLine(input: unknown): string {
551
+ const anchor = isRecord(input) && typeof input.anchor === "string" ? input.anchor : undefined;
552
+ const match = /^(\d+)#/u.exec(anchor ?? "");
553
+ return match?.[1] ?? anchor ?? "selected line";
554
+ }
555
+
556
+ function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
557
+ return typeof value === "object" && value !== null;
558
+ }
559
+
560
+ function debugSourceContent(sourceFile: string, text: string) {
561
+ return {
562
+ type: "text" as const,
563
+ text,
564
+ sourceLines: Object.fromEntries(
565
+ text
566
+ .split(/\r?\n/u)
567
+ .map((line, index) => [
568
+ String(index + 1),
569
+ { source: sourceFile, lineNumber: index + 1, content: line },
570
+ ]),
571
+ ),
572
+ };
573
+ }
@@ -0,0 +1,73 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ import type { TextLinePresenter } from "pi-agent-text";
5
+
6
+ import type {
7
+ DebugBreakpoint,
8
+ DebugSessionManager,
9
+ } from "#src/plugins/pi-agent-ide-debugger/src/session-manager.js";
10
+
11
+ /** Annotate source lines with breakpoints from current debug sessions. */
12
+ export function createBreakpointPresenter(manager: DebugSessionManager): TextLinePresenter {
13
+ return {
14
+ id: "debug-breakpoints",
15
+ present(document, context) {
16
+ const debugSession = manager.get(context.source);
17
+ const sourceFile =
18
+ manager.sourceFile(context.source) ?? filesystemSource(document.source, context.cwd);
19
+ if (sourceFile === undefined) return document;
20
+ const breakpoints = manager.breakpointsForFile(sourceFile, debugSession?.source);
21
+ if (breakpoints.length === 0) return document;
22
+ const byLine = groupByLine(breakpoints);
23
+ return {
24
+ ...document,
25
+ lines: document.lines.map((line) => {
26
+ const matches = byLine.get(line.lineNumber);
27
+ if (matches === undefined) return line;
28
+ return {
29
+ ...line,
30
+ presentation: {
31
+ ...line.presentation,
32
+ suffix: `${line.presentation?.suffix ?? ""}${renderAgentBreakpoints(matches)}`,
33
+ compactSuffix: `${line.presentation?.compactSuffix ?? ""}${renderUserBreakpoints(matches)}`,
34
+ },
35
+ };
36
+ }),
37
+ };
38
+ },
39
+ };
40
+ }
41
+
42
+ function groupByLine(
43
+ breakpoints: readonly DebugBreakpoint[],
44
+ ): ReadonlyMap<number, readonly DebugBreakpoint[]> {
45
+ const grouped = new Map<number, DebugBreakpoint[]>();
46
+ for (const breakpoint of breakpoints) {
47
+ const line = grouped.get(breakpoint.line) ?? [];
48
+ line.push(breakpoint);
49
+ grouped.set(breakpoint.line, line);
50
+ }
51
+ return grouped;
52
+ }
53
+ function filesystemSource(source: string, cwd: string): string | undefined {
54
+ if (source.startsWith("file://")) return fileURLToPath(source);
55
+ if (/^[a-z][a-z\d+.-]*:/iu.test(source)) return undefined;
56
+ return path.resolve(cwd, source);
57
+ }
58
+
59
+ function renderAgentBreakpoints(breakpoints: readonly DebugBreakpoint[]): string {
60
+ return breakpoints
61
+ .map(
62
+ (breakpoint) =>
63
+ ` ${breakpoint.verified ? "●" : "○"} breakpoint ${breakpoint.source} (${breakpoint.verified ? "verified" : "pending"})`,
64
+ )
65
+ .join("");
66
+ }
67
+
68
+ function renderUserBreakpoints(breakpoints: readonly DebugBreakpoint[]): string {
69
+ const verified = breakpoints.filter((breakpoint) => breakpoint.verified).length;
70
+ const marker = verified === breakpoints.length ? "●" : "○";
71
+ const count = breakpoints.length === 1 ? "breakpoint" : `${breakpoints.length} breakpoints`;
72
+ return ` ${marker} ${count}`;
73
+ }