pi-agent-ide 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (490) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +12 -8
  3. package/dist/{chunk-XNXQYPVT.js → chunk-4LUW26BX.js} +1 -1
  4. package/dist/chunk-5MSNYFDE.js +1 -0
  5. package/dist/chunk-5VSE5X5R.js +2 -0
  6. package/dist/chunk-6EYWFBNG.js +0 -0
  7. package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
  8. package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
  9. package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
  10. package/dist/{chunk-SMSIT3CE.js → chunk-B5KB2I7J.js} +1 -1
  11. package/dist/chunk-BHSO2MDK.js +6 -0
  12. package/dist/chunk-BMOJTJJJ.js +3 -0
  13. package/dist/{chunk-EEH4WYI7.js → chunk-CEKXBS55.js} +1 -1
  14. package/dist/chunk-CW53ZTU3.js +2 -0
  15. package/dist/chunk-EWNWKDMP.js +4 -0
  16. package/dist/{chunk-VSP2QQPQ.js → chunk-GIRAEVUJ.js} +1 -1
  17. package/dist/{chunk-MTTKFJV6.js → chunk-GUTQ3PWL.js} +1 -1
  18. package/dist/chunk-HGPUI7F3.js +1 -0
  19. package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
  20. package/dist/chunk-ITSNK5YG.js +7 -0
  21. package/dist/chunk-KAB3AYA2.js +1 -0
  22. package/dist/{chunk-266RH77Z.js → chunk-LRYE2WCN.js} +1 -1
  23. package/dist/chunk-M5L42DWE.js +7 -0
  24. package/dist/chunk-M5MJP7Z2.js +1 -0
  25. package/dist/chunk-NMFQGKPE.js +2 -0
  26. package/dist/chunk-NTYXZ3EL.js +3 -0
  27. package/dist/{chunk-PETQCA7G.js → chunk-QDST6VIU.js} +1 -1
  28. package/dist/chunk-QIJMV2P2.js +2 -0
  29. package/dist/chunk-RHV5STR3.js +3 -0
  30. package/dist/chunk-ROXXK6TW.js +0 -0
  31. package/dist/chunk-S3ZPXWX7.js +2 -0
  32. package/dist/chunk-SSHZEWWV.js +1 -0
  33. package/dist/chunk-TPIHQYK2.js +14 -0
  34. package/dist/chunk-VZJIZXSH.js +14 -0
  35. package/dist/chunk-YHADTHQM.js +1 -0
  36. package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
  37. package/dist/{chunk-SJYDLHEF.js → chunk-ZM4L5AGN.js} +1 -1
  38. package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
  39. package/dist/entry-0.js +1 -1
  40. package/dist/entry-1.js +1 -1
  41. package/dist/entry-10.js +1 -1
  42. package/dist/entry-11.js +1 -1
  43. package/dist/entry-12.js +1 -1
  44. package/dist/entry-13.js +1 -1
  45. package/dist/entry-14.js +1 -1
  46. package/dist/entry-2.js +1 -1
  47. package/dist/entry-21.js +2 -1
  48. package/dist/entry-22.js +1 -1
  49. package/dist/entry-23.js +1 -1
  50. package/dist/entry-24.js +1 -1
  51. package/dist/entry-25.js +1 -1
  52. package/dist/entry-26.js +12 -1
  53. package/dist/entry-28.js +1 -1
  54. package/dist/entry-29.js +1 -1
  55. package/dist/entry-30.js +1 -1
  56. package/dist/entry-31.js +4 -1
  57. package/dist/entry-32.js +9 -1
  58. package/dist/entry-33.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-4.js +1 -1
  65. package/dist/entry-40.js +18 -1
  66. package/dist/entry-41.js +1 -1
  67. package/dist/entry-42.js +1 -1
  68. package/dist/entry-43.js +1 -1
  69. package/dist/entry-44.js +1 -1
  70. package/dist/entry-45.js +7 -1
  71. package/dist/entry-46.js +11 -1
  72. package/dist/entry-47.js +1 -1
  73. package/dist/entry-48.js +1 -1
  74. package/dist/entry-49.js +1 -1
  75. package/dist/entry-50.js +1 -1
  76. package/dist/entry-51.js +1 -1
  77. package/dist/entry-52.js +1 -1
  78. package/dist/entry-53.js +1 -1
  79. package/dist/entry-54.js +1 -0
  80. package/dist/entry-55.js +0 -1
  81. package/dist/entry-56.js +1 -0
  82. package/dist/entry-57.js +0 -1
  83. package/dist/entry-58.js +1 -1
  84. package/dist/entry-59.js +1 -1
  85. package/dist/entry-60.js +1 -1
  86. package/dist/entry-61.js +1 -1
  87. package/dist/entry-62.js +1 -1
  88. package/dist/entry-63.js +1 -0
  89. package/dist/entry-64.js +0 -1
  90. package/dist/entry-65.js +1 -0
  91. package/dist/entry-66.js +0 -1
  92. package/dist/entry-67.js +1 -1
  93. package/dist/entry-68.js +1 -1
  94. package/dist/entry-69.js +1 -1
  95. package/dist/entry-70.js +123 -1
  96. package/dist/entry-71.js +30 -1
  97. package/dist/entry-72.js +2 -1
  98. package/dist/entry-73.js +1 -1
  99. package/dist/entry-74.js +1 -1
  100. package/dist/entry-75.js +1 -1
  101. package/dist/entry-76.js +3 -1
  102. package/dist/entry-77.js +1 -1
  103. package/dist/entry-78.js +1 -1
  104. package/dist/entry-79.js +1 -1
  105. package/dist/pi-agent-ide.js +3 -13
  106. package/docs/configuration.md +57 -11
  107. package/docs/extensions.md +4 -2
  108. package/docs/tools.md +7 -1
  109. package/node_modules/pi-agent-doctor/package.json +1 -1
  110. package/node_modules/pi-agent-filesystem/index.ts +2 -2
  111. package/node_modules/pi-agent-filesystem/package.json +6 -6
  112. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  113. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  114. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  115. package/node_modules/pi-agent-ide-ast/package.json +9 -9
  116. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +89 -19
  117. package/node_modules/pi-agent-ide-ast/src/extension.ts +11 -15
  118. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +83 -0
  119. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  120. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
  121. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  122. package/node_modules/pi-agent-ide-changes/index.ts +22 -10
  123. package/node_modules/pi-agent-ide-changes/package.json +6 -6
  124. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  125. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +5 -9
  126. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +1 -5
  127. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  128. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +36 -13
  129. package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
  130. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  131. package/node_modules/pi-agent-ide-lint/index.ts +49 -17
  132. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  133. package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
  134. package/node_modules/pi-agent-ide-lsp/index.ts +127 -20
  135. package/node_modules/pi-agent-ide-lsp/package.json +9 -8
  136. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  137. package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +25 -7
  138. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +12 -1
  139. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  140. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  141. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  142. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  143. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  144. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  145. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  146. package/node_modules/pi-agent-image/package.json +2 -2
  147. package/node_modules/pi-agent-image/src/image-converter.ts +1 -1
  148. package/node_modules/pi-agent-invariant/package.json +1 -1
  149. package/node_modules/pi-agent-pdf/package.json +2 -2
  150. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +1 -1
  151. package/node_modules/pi-agent-read/package.json +6 -6
  152. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  153. package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
  154. package/node_modules/pi-agent-read/src/api/rendering.ts +3 -0
  155. package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
  156. package/node_modules/pi-agent-read/src/core/read-core.ts +32 -28
  157. package/node_modules/pi-agent-read/src/core/tools/read/native-resource-renderer.ts +74 -0
  158. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  159. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  160. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +87 -19
  161. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  162. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  163. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +87 -53
  164. package/node_modules/pi-agent-resource/package.json +1 -1
  165. package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +1 -8
  166. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  167. package/node_modules/pi-agent-search/package.json +3 -3
  168. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  169. package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
  170. package/node_modules/pi-agent-search/src/api/search.ts +55 -1
  171. package/node_modules/pi-agent-search/src/core/extension.ts +8 -27
  172. package/node_modules/pi-agent-search/src/core/search-core.ts +38 -3
  173. package/node_modules/pi-agent-search-text/index.ts +82 -33
  174. package/node_modules/pi-agent-search-text/package.json +6 -6
  175. package/node_modules/pi-agent-search-text/src/file-search.ts +9 -1
  176. package/node_modules/pi-agent-search-text/src/resolvers.ts +1 -1
  177. package/node_modules/pi-agent-search-text/src/search-recipe.ts +2 -0
  178. package/node_modules/pi-agent-search-text/src/search-session.ts +112 -24
  179. package/node_modules/pi-agent-text/package.json +2 -2
  180. package/node_modules/pi-agent-text/src/text-converter.ts +1 -1
  181. package/node_modules/pi-agent-text/src/text-document.ts +5 -0
  182. package/node_modules/pi-agent-text/src/text-target.ts +4 -0
  183. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  184. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  185. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +2 -6
  186. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  187. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  188. package/node_modules/pi-agent-text-editor/index.ts +1 -3
  189. package/node_modules/pi-agent-text-editor/package.json +34 -24
  190. package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
  191. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  192. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  193. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  194. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  195. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -0
  196. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  197. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +74 -1
  198. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  199. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  200. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  201. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  202. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  203. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  204. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  205. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  206. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  207. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  208. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  209. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  210. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +4 -12
  211. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  212. package/node_modules/pi-agent-text-editor/src/core/extension.ts +13 -9
  213. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  214. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  215. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  216. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +28 -2
  217. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +43 -0
  218. package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +2 -0
  219. package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +81 -0
  220. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  221. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +5 -2
  222. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  223. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +40 -0
  224. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +178 -58
  225. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +313 -21
  226. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +45 -43
  227. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +18 -8
  228. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +7 -4
  229. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +13 -5
  230. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +18 -8
  231. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -5
  232. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -1
  233. package/node_modules/pi-agent-text-editor-renderer/index.ts +93 -2
  234. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  235. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +7 -0
  236. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +1 -1
  237. package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +11 -2
  238. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +140 -52
  239. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +69 -4
  240. package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +53 -1
  241. package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +8 -2
  242. package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +10 -0
  243. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +24 -13
  244. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  245. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  246. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  247. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
  248. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  249. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  250. package/node_modules/pi-agent-web/index.ts +1 -6
  251. package/node_modules/pi-agent-web/package.json +7 -7
  252. package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
  253. package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
  254. package/node_modules/pi-agent-web-html/package.json +3 -3
  255. package/node_modules/pi-agent-web-html/src/html-converter.ts +1 -1
  256. package/node_modules/pi-agent-web-image/package.json +4 -4
  257. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  258. package/node_modules/pi-agent-web-text/package.json +4 -4
  259. package/package.json +38 -38
  260. package/src/api/plugin-protocol.ts +12 -2
  261. package/src/api/text-editor.ts +7 -0
  262. package/src/api/tool-config.ts +77 -2
  263. package/src/code-view/diagnostic-view.ts +22 -3
  264. package/src/composite/builtin-extensions.ts +138 -67
  265. package/src/composite/extensions-config.ts +59 -0
  266. package/src/composite/feature-flags.ts +32 -0
  267. package/src/composite/module-labels.ts +55 -0
  268. package/src/composite/module-settings-store.ts +44 -0
  269. package/src/composite/module-settings.ts +132 -0
  270. package/src/composite/selection.ts +4 -4
  271. package/src/composite/settings-panel.ts +71 -0
  272. package/src/core/diagnostic-delivery.ts +29 -0
  273. package/src/core/diagnostic-entry.ts +142 -0
  274. package/src/core/diagnostic-store.ts +96 -23
  275. package/src/core/extension.ts +45 -22
  276. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +2 -2
  277. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
  278. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  279. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  280. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  281. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +1 -6
  282. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  283. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  284. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
  285. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +1 -1
  286. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  287. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  288. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  289. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
  290. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
  291. package/src/extensions/pi-agent-read/package.json +6 -6
  292. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  293. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
  294. package/src/extensions/pi-agent-read/src/api/rendering.ts +3 -0
  295. package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
  296. package/src/extensions/pi-agent-read/src/core/read-core.ts +32 -28
  297. package/src/extensions/pi-agent-read/src/core/tools/read/native-resource-renderer.ts +74 -0
  298. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  299. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  300. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +87 -19
  301. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  302. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  303. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +87 -53
  304. package/src/extensions/pi-agent-search/package.json +3 -3
  305. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +82 -33
  306. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  307. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +9 -1
  308. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +1 -1
  309. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +2 -0
  310. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +112 -24
  311. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  312. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
  313. package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
  314. package/src/extensions/pi-agent-search/src/core/extension.ts +8 -27
  315. package/src/extensions/pi-agent-search/src/core/search-core.ts +38 -3
  316. package/src/extensions/pi-agent-text-editor/index.ts +1 -3
  317. package/src/extensions/pi-agent-text-editor/package.json +34 -24
  318. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  319. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  320. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +2 -6
  321. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  322. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  323. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +93 -2
  324. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  325. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +7 -0
  326. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +1 -1
  327. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +11 -2
  328. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +140 -52
  329. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +69 -4
  330. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +53 -1
  331. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +8 -2
  332. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +10 -0
  333. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +24 -13
  334. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  335. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  336. package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
  337. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
  338. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  339. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  340. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  341. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  342. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -0
  343. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  344. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +74 -1
  345. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  346. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  347. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  348. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  349. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  350. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  351. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  352. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  353. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  354. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  355. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  356. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  357. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +4 -12
  358. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  359. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +13 -9
  360. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  361. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  362. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  363. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +28 -2
  364. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +43 -0
  365. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +2 -0
  366. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +81 -0
  367. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  368. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +5 -2
  369. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  370. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +40 -0
  371. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +178 -58
  372. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +313 -21
  373. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +45 -43
  374. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +18 -8
  375. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +7 -4
  376. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +13 -5
  377. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +18 -8
  378. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -5
  379. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -1
  380. package/src/pi-agent-ide.ts +45 -0
  381. package/src/plugins/pi-agent-ide-ast/package.json +9 -9
  382. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +89 -19
  383. package/src/plugins/pi-agent-ide-ast/src/extension.ts +11 -15
  384. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +83 -0
  385. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  386. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
  387. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  388. package/src/plugins/pi-agent-ide-changes/index.ts +22 -10
  389. package/src/plugins/pi-agent-ide-changes/package.json +6 -6
  390. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  391. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +5 -9
  392. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +1 -5
  393. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -26
  394. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  395. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +36 -13
  396. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
  397. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  398. package/src/plugins/pi-agent-ide-lint/index.ts +49 -17
  399. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  400. package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
  401. package/src/plugins/pi-agent-ide-lsp/index.ts +127 -20
  402. package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
  403. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  404. package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +25 -7
  405. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +12 -1
  406. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  407. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  408. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  409. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  410. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  411. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  412. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  413. package/src/post-edit/gate.ts +57 -15
  414. package/src/toolchain/types.ts +2 -0
  415. package/dist/chunk-2SKAED2I.js +0 -2
  416. package/dist/chunk-2XYXV5HS.js +0 -4
  417. package/dist/chunk-2ZMYT6ZC.js +0 -1
  418. package/dist/chunk-34ZQTTU2.js +0 -2
  419. package/dist/chunk-4SQQKEVD.js +0 -16
  420. package/dist/chunk-5BWUVAR4.js +0 -1
  421. package/dist/chunk-6DN7NO7L.js +0 -1
  422. package/dist/chunk-6SMFVLTY.js +0 -1
  423. package/dist/chunk-6XQQBKPE.js +0 -58
  424. package/dist/chunk-BYWAG6X3.js +0 -6
  425. package/dist/chunk-EW2KVKCN.js +0 -2
  426. package/dist/chunk-F6SESI3P.js +0 -4
  427. package/dist/chunk-GTK5AREE.js +0 -2
  428. package/dist/chunk-HOBTFFQR.js +0 -1
  429. package/dist/chunk-IMVCVPMP.js +0 -3
  430. package/dist/chunk-IOCABSRL.js +0 -1
  431. package/dist/chunk-JASLOB2X.js +0 -1
  432. package/dist/chunk-KH5KPBCR.js +0 -10
  433. package/dist/chunk-KNMWCDDK.js +0 -7
  434. package/dist/chunk-KYVOMBO5.js +0 -1
  435. package/dist/chunk-L4FA6OD4.js +0 -1
  436. package/dist/chunk-LFV6G5Z3.js +0 -1
  437. package/dist/chunk-LGN7EJYR.js +0 -13
  438. package/dist/chunk-MB6VVVAF.js +0 -2
  439. package/dist/chunk-MTQSGWZJ.js +0 -1
  440. package/dist/chunk-NI2NK4JU.js +0 -1
  441. package/dist/chunk-NXHPO7ER.js +0 -6
  442. package/dist/chunk-OFHVDY4Q.js +0 -2
  443. package/dist/chunk-OIL6BB2S.js +0 -33
  444. package/dist/chunk-ONWUJXUR.js +0 -1
  445. package/dist/chunk-PODWLGNO.js +0 -6
  446. package/dist/chunk-QZANC2IG.js +0 -1
  447. package/dist/chunk-SSZB66C3.js +0 -3
  448. package/dist/chunk-TG6H6EOI.js +0 -1
  449. package/dist/chunk-UTTW55S2.js +0 -1
  450. package/dist/chunk-VEJGSURY.js +0 -8
  451. package/dist/chunk-W3XYKJ5H.js +0 -1
  452. package/dist/chunk-XGUAL3CA.js +0 -1
  453. package/dist/chunk-YPHXLAQF.js +0 -1
  454. package/dist/chunk-ZIHEF6K3.js +0 -3
  455. package/dist/entry-80.js +0 -1
  456. package/node_modules/pi-agent-read/src/core/tools/read/views.ts +0 -29
  457. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  458. package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
  459. package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
  460. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  461. package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
  462. package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
  463. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  464. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
  465. package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
  466. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
  467. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
  468. package/src/extensions/pi-agent-read/src/core/tools/read/views.ts +0 -29
  469. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
  470. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
  471. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
  472. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  473. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
  474. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
  475. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  476. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  477. /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
  478. /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
  479. /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  480. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
  481. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
  482. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
  483. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  484. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  485. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  486. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  487. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  488. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  489. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  490. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 — 2026-09-10
4
+
5
+ ### Composable IDE tools
6
+
7
+ - Add `apply`, a JavaScript scratchpad for combining reads, searches, diffs, guarded text edits, whole-file operations, and Git change operations in one call. Calls run in order, return structured data, and keep completed changes when a later operation fails.
8
+ - Add standalone `diff`, `copy_file`, `move_file`, and `delete_file` tools. The same operations are available inside `apply`.
9
+ - Let `apply` reuse search selections, text anchors, AST matches, inherited sources, formatter hooks, and explicitly requested diagnostics from the existing IDE tools.
10
+ - Add safe symbol operations backed by language servers. Tools can resolve declarations and rename a symbol with native reference updates when the server supports it.
11
+ - Add `raw:` reads for inspecting original file bytes without text decoding or conversion.
12
+
13
+ ### Editing and post-processing
14
+
15
+ - Keep formatter, linter, and language-server discovery local to the project that owns each edited file. Files outside the active project no longer inherit its toolchain.
16
+ - Preserve successful effects, explicit results, preview arguments, and recovery details across mixed `apply` scripts. Keep empty-file creation and formatted results visible and reusable.
17
+ - Run only explicitly requested diagnostics inline. Automatic post-edit checks remain asynchronous and no longer break otherwise successful reads or edits.
18
+ - Reuse resolved search and AST selections across guarded operations, including exact replacements and multi-file scripts.
19
+
20
+ ### Interface and settings
21
+
22
+ - Add incremental previews for mixed `apply` scripts, with syntax-coloured calls, results, diffs, formatting status, and grouped diagnostic feedback.
23
+ - Add settings for enabling `apply`, choosing its preview style, and managing IDE modules and feature groups from named settings tabs.
24
+ - Show ordinary read windows as line ranges, while keeping anchor-relative reads and tail reads explicit.
25
+ - Show whole-file operation names as `copy file`, `move file`, and `delete file` in tool cards and results.
26
+ - Tighten compact spacing and keep explicit output visible when reads, edits, and Git operations share one preview.
27
+
28
+ ## 0.2.2 — 2026-09-08
29
+
30
+ ### Agent guidance
31
+
32
+ - Clarify tool descriptions and input parameters so agents can choose the right read, search, or edit operation. Keep tool-specific details with each tool and shared workflow rules in the system prompt.
33
+ - Explain how to reuse anchors, recover from broadened searches, and batch independent edits without retrying changes that already applied.
34
+
35
+ ### Editing and search
36
+
37
+ - Fix ranges that mix exact text, line anchors, and search references. Explicit start and end anchors select inclusive whole lines; insert, copy, and move destinations use the containing line boundaries.
38
+ - Fix empty replacements of whole-line selections so they remove the lines instead of leaving a blank line.
39
+ - Preserve unselected line breaks when deleting exact search matches at the end of a file.
40
+ - Fix `files:` glob matching, including nested paths, basename patterns, character classes, and brace alternatives.
41
+ - Report applied edit counts and formatting outcomes. Group repeated replacements into a compact summary with every affected file, and rerun referenced searches to report remaining matches within their original scope.
42
+
43
+ ### Reading
44
+
45
+ - Show a compact, source-numbered AST overview when a supported code file exceeds the read limit. Reduce detail until it fits, and keep ordinary truncation when no usable outline is available.
46
+ - Fix AST outline positions for CRLF text and characters such as emoji.
47
+ - Remove the standalone `lines` view. Use `anchors` for source line numbers with edit references.
48
+ - Preserve Pi's native read presentation for skills, agent context files, and Pi documentation when no extra views are requested.
49
+
50
+ ### Interface and configuration
51
+
52
+ - Keep local diffs aligned after formatting shifts lines. Report changes outside the displayed area or changes that cannot be assigned to one edit instead of showing misleading hunks.
53
+ - Show formatting status alongside diffs and visible background diagnostic summaries with per-file counts and expandable provider details. Send automatic notifications only for actual findings; keep pending, unavailable, and empty reports out of both the chat and the agent's context.
54
+ - Add `noAnimations` and `noPostProcessing` settings, with matching `--pi-agent-ide-no-animations` and `--pi-agent-ide-no-post-processing` flags. These can disable edit animations or automatic post-edit checks and formatting while keeping explicit reads and requested edits available.
55
+ - Name the actual formatter, linter, or language-server executable in formatting results and diagnostic messages. Show diagnostic tool names beside their counts even when the entry is collapsed.
56
+ - Deliver new diagnostic findings immediately to the chat and agent. Late findings wake an idle agent without waiting for another user message; duplicate and empty reports stay silent.
57
+ - Load built-in extension entry modules only when selected, avoiding imports for disabled built-ins.
58
+
3
59
  ## 0.2.1 — 2026-09-07
4
60
 
5
61
  ### Stability and Windows
package/README.md CHANGED
@@ -23,15 +23,19 @@ The current focus is measurement. The project is being compared with vanilla Pi
23
23
 
24
24
  ## What it does
25
25
 
26
- Pi Agent IDE provides a small set of tools with more specialized behavior behind them:
26
+ Pi Agent IDE gives the agent a focused set of tools that work together:
27
27
 
28
- - `read` handles files, web pages, images, PDFs, code views, and diagnostics;
29
- - `search` routes text and structural searches;
30
- - `write`, `replace`, `insert`, `delete`, `copy`, and `move` cover common text mutations; range-based edits can target snapshot and semantic anchors instead of reproducing the `oldText` block required by Pi's built-in `edit` tool;
31
- - optional plugins add AST, LSP, formatting, linting, and Git-aware behavior;
32
- - `/pi-agent-ide-doctor` detects project languages and lets each loaded plugin check or configure its own scope.
28
+ - `read` handles text files, original bytes, web pages, images, PDFs, code views, and diagnostics;
29
+ - `search` finds files, text, symbols, and syntax-tree patterns;
30
+ - `write`, `replace`, `insert`, `delete`, `copy`, and `move` edit text with exact matches, line anchors, search results, AST matches, and language-server symbols;
31
+ - `diff` compares readable sources, while `copy_file`, `move_file`, and `delete_file` handle whole files;
32
+ - `apply` combines reads, searches, diffs, edits, whole-file operations, and Git change operations in one JavaScript call;
33
+ - formatting and diagnostics run after edits and stay local to the project that owns each file;
34
+ - `/pi-agent-ide-doctor` checks the languages and tools available in the current project.
33
35
 
34
- The public interface is intentionally small. Resources, resolvers, anchors, renderers, and toolchain integrations are connected through versioned plugin protocols. The npm package loads as one Pi extension, while its built-ins remain separate modules that can be replaced or extended.
36
+ The tools share the same resources and safeguards. An `apply` script can reuse a search result or anchor from an earlier call, and completed edits remain visible if a later call fails. Formatting, diagnostics, previews, and safe undo work the same way for standalone tools and composed operations.
37
+
38
+ The npm package loads as one Pi extension. Its built-in modules can be enabled, disabled, replaced, or extended through versioned plugin protocols.
35
39
 
36
40
  ## Installation
37
41
 
@@ -45,7 +49,7 @@ Pi packages run with your full system permissions. Review the package before ins
45
49
 
46
50
  ## Check project tools
47
51
 
48
- Pi Agent IDE includes formatter, linter, and LSP mappings. It runs their external commands through your current `PATH`, so projects work without copied IDE config files when those commands are installed.
52
+ Pi Agent IDE includes formatter, linter, and LSP mappings. It finds each tool from the project that owns the file, including project-local binaries and commands on your `PATH`. Settings from one project do not leak into another.
49
53
 
50
54
  Start Pi in your project directory, then run:
51
55
 
@@ -1,4 +1,4 @@
1
- import{d as w,h as P}from"./chunk-VSP2QQPQ.js";import{a as y}from"./chunk-EI7MMDWY.js";import{Allow as _}from"partial-json";import{Guard as h}from"typebox-guard/guard";import{Allow as D,parse as z}from"partial-json";function B(o,e=D.ALL){if(!(!o||o.trim().length===0))try{let t=z(o,e);return t==null||typeof t!="object"||Array.isArray(t)?void 0:t}catch{return}}y(B,"resolvePartial");var R=class{static{y(this,"PartialToolRecoveryRegistry")}registrations=new Map;states=new Map;register(e){this.registrations.set(e.recoveryKey??e.toolName,e)}unregister(e){for(let[t,n]of this.registrations)(n.toolName===e||t===e)&&this.registrations.delete(t)}recoveryKeyFor(e){for(let[t,n]of this.registrations)if(n.toolName===e||n.toolNames?.includes(e)||t===e)return t}async recover(e){let t=this.states.get(e.contentIndex);if(t?.status==="done")return t.result;if(t?.status==="running")return t.promise;let n=this.registrations.get(e.recoveryKey??e.toolName);if(!n)return;let r=this.run(n,e);this.states.set(e.contentIndex,{status:"running",promise:r});let a=await r;return this.states.set(e.contentIndex,{status:"done",result:a}),a}cancel(e){this.states.delete(e)}cleanup(e){this.states.delete(e)}cleanupAll(){this.states.clear()}async run(e,t){let n=[],r=new Set(t.completedEntryIndexes),a=new Set(t.blockedEntryIndexes),s=e.extractEntries(t).filter(c=>{if(r.has(c.index))return n.push({index:c.index,reason:"entry already completed before recovery"}),!1;if(a.has(c.index))return n.push({index:c.index,reason:"entry was blocked by a guard"}),!1;let g=e.isCompleteEntry?.(c,t)??c.complete;return g||n.push({index:c.index,reason:t.recoverCompleteBatch?"entry was incomplete in the recovered batch":"entry was incomplete before the stale entry"}),!t.recoverCompleteBatch&&t.staleEntryIndex!==void 0&&c.index>=t.staleEntryIndex?!1:g}),i=e.filterEntries?.(s,t)??s,d=new Set(i.map(c=>c.index));for(let c of s)d.has(c.index)||n.push({index:c.index,reason:"entry was excluded by recovery filtering"});let u=[];for(let c of i)try{e.validateEntry?.(c,t),u.push(c)}catch(g){n.push({index:c.index,reason:g instanceof Error?g.message:String(g)})}let m={toolName:t.toolName,contentIndex:t.contentIndex,...t.staleEntryIndex!==void 0&&{staleEntryIndex:t.staleEntryIndex},staleDetails:t.staleDetails};if(u.length===0)return{...m,status:"skipped",appliedEntries:[],skippedEntries:n};try{let c=e.buildParams(u,t),g=await e.execute(c,{contentIndex:t.contentIndex,toolCallId:t.toolCallId,toolName:t.toolName,cwd:t.cwd,ctx:t.ctx,signal:new AbortController().signal});return{...m,status:"recovered",appliedEntries:e.getAppliedEntries?.(g,u,t)??u.map(b=>b.index),skippedEntries:n,normalResult:g}}catch(c){return{...m,status:"failed",appliedEntries:[],skippedEntries:n,error:c instanceof Error?c.message:String(c)}}}};import{createAssistantMessageEventStream as L}from"@earendil-works/pi-ai";var M=Symbol.for("pi-agent-text-editor.tool-call-interceptor.streaming-provider.state");function N(o,e,t,n){let r=new Map,a={context:void 0,processStreamEvent:e,markStreamEventProcessed:t,finalizeStreamInterception:n},l=y((s,i)=>{if(!s)return;let d=i.modelRegistry.getProvider(s.provider);if(!d)return;let u=r.get(s.provider);if(u){if(u.subscribers.add(a),u.api===s.api&&d.streamSimple===u.wrapper)return;u.api=s.api;let p=i.modelRegistry.getRegisteredProviderConfig(s.provider);o.registerProvider(s.provider,{...p,api:s.api,streamSimple:u.wrapper});return}let m=d.streamSimple[M];if(m){if(m.subscribers.add(a),r.set(s.provider,m),m.api===s.api)return;m.api=s.api;let p=i.modelRegistry.getRegisteredProviderConfig(s.provider);o.registerProvider(s.provider,{...p,api:s.api,streamSimple:m.wrapper});return}let c=d.streamSimple.bind(d),g=new Set([a]),b=y((p,v,C)=>F(c,p,v,C,g),"wrapper"),E={api:s.api,delegate:c,wrapper:b,subscribers:g};b[M]=E;let f=i.modelRegistry.getRegisteredProviderConfig(s.provider);o.registerProvider(s.provider,{...f,api:s.api,streamSimple:b}),r.set(s.provider,E)},"install");o.on("before_provider_request",(s,i)=>{a.context=i,l(i.model,i)}),o.on("turn_start",(s,i)=>{a.context=i,l(i.model,i)}),o.on("agent_start",(s,i)=>{a.context=i,l(i.model,i)}),o.on("session_start",(s,i)=>{a.context=i,l(i.model,i)}),o.on("model_select",(s,i)=>{a.context=i,l(s.model,i)}),o.on("session_shutdown",()=>{for(let[s,i]of r)i.subscribers.delete(a),i.subscribers.size===0&&o.unregisterProvider(s);r.clear(),a.context=void 0})}y(N,"registerStreamingInterceptorProvider");function F(o,e,t,n,r){let a=L(),l=new AbortController,s=n?.signal,i=!1,d=Q(e),u=new Set,m=new Set,c=new Set,g=new Set,b=y(f=>{for(let p of r)p.markStreamEventProcessed(f)},"markStreamEventProcessed"),E=y(()=>{l.abort()},"abortFromParent");return s&&(s.aborted?l.abort():s.addEventListener("abort",E,{once:!0})),(async()=>{try{let f=o(e,t,{...n,signal:l.signal});for await(let p of f){if(i)continue;p.type==="done"?d=structuredClone(p.message):p.type==="error"?d=structuredClone(p.error):d=structuredClone(p.partial),H(p,u);let v;for(let C of r){let I=C.context;if(I){let T=await C.processStreamEvent(p,I);v??=T}}if(b(p),W(p,m,c,g),a.push(structuredClone(p)),v){if(p.type==="toolcall_delta"||p.type==="toolcall_end")for(let x of r)x.finalizeStreamInterception(p.contentIndex);i=!0,l.abort();let C=p.type==="toolcall_delta"||p.type==="toolcall_end"?p.contentIndex:void 0,I={...d,content:d.content.filter((x,A)=>u.has(A)&&(C===void 0||A<=C||g.has(A))).map(x=>x.type==="toolCall"&&x.id===v.toolCallId?{...x,arguments:structuredClone(v.arguments)}:x)};U(a,b,I,u,m,c,g);let{errorMessage:T,...j}=I;a.push({type:"done",reason:"toolUse",message:{...j,stopReason:"toolUse"}}),a.end();continue}if(p.type==="done"||p.type==="error"){a.end();return}}}catch(f){if(i)return;let p=d,v=s?.aborted===!0?"aborted":"error",C={...p,stopReason:v,errorMessage:f instanceof Error?f.message:String(f)};a.push({type:"error",reason:v,error:C}),a.end()}finally{s?.removeEventListener("abort",E)}})(),a}y(F,"wrapStream");function H(o,e){(o.type==="text_start"||o.type==="thinking_start"||o.type==="toolcall_start")&&e.add(o.contentIndex)}y(H,"rememberStartEvent");function W(o,e,t,n){switch(o.type){case"text_end":{e.add(o.contentIndex);break}case"thinking_end":{t.add(o.contentIndex);break}case"toolcall_end":{n.add(o.contentIndex);break}}}y(W,"rememberEndEvent");function U(o,e,t,n,r,a,l){for(let[s,i]of t.content.entries())if(n.has(s)){if(i.type==="text"&&!r.has(s)){let d={type:"text_end",contentIndex:s,content:i.text,partial:t};e(d),o.push(d)}else if(i.type==="thinking"&&!a.has(s)){let d={type:"thinking_end",contentIndex:s,content:i.thinking,partial:t};e(d),o.push(d)}else if(i.type==="toolCall"&&!l.has(s)){let d={type:"toolcall_end",contentIndex:s,toolCall:i,partial:t};e(d),o.push(d)}}}y(U,"emitMissingEndEvents");function Q(o){return{role:"assistant",content:[],api:o.api,provider:o.provider,model:o.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"toolUse",timestamp:Date.now()}}y(Q,"emptyAssistantMessage");var V="agentic-ide-partial-tool-recovery",$="pi-agent-text-editor/tool-call-annotation",S=new WeakMap,k=class{constructor(e){this.pi=e;e.on("tool_call",t=>{let n=this.toolCallRecords.get(t.toolCallId),r=n?.blockExecution?n.guardResult:void 0;return r?{block:!0,reason:r.content.filter(l=>l.type==="text").map(l=>l.text).join(`
1
+ import{d as w,h as P}from"./chunk-GIRAEVUJ.js";import{a as y}from"./chunk-EI7MMDWY.js";import{Allow as _}from"partial-json";import{Guard as h}from"typebox-guard/guard";import{Allow as D,parse as z}from"partial-json";function B(o,e=D.ALL){if(!(!o||o.trim().length===0))try{let t=z(o,e);return t==null||typeof t!="object"||Array.isArray(t)?void 0:t}catch{return}}y(B,"resolvePartial");var R=class{static{y(this,"PartialToolRecoveryRegistry")}registrations=new Map;states=new Map;register(e){this.registrations.set(e.recoveryKey??e.toolName,e)}unregister(e){for(let[t,n]of this.registrations)(n.toolName===e||t===e)&&this.registrations.delete(t)}recoveryKeyFor(e){for(let[t,n]of this.registrations)if(n.toolName===e||n.toolNames?.includes(e)||t===e)return t}async recover(e){let t=this.states.get(e.contentIndex);if(t?.status==="done")return t.result;if(t?.status==="running")return t.promise;let n=this.registrations.get(e.recoveryKey??e.toolName);if(!n)return;let r=this.run(n,e);this.states.set(e.contentIndex,{status:"running",promise:r});let a=await r;return this.states.set(e.contentIndex,{status:"done",result:a}),a}cancel(e){this.states.delete(e)}cleanup(e){this.states.delete(e)}cleanupAll(){this.states.clear()}async run(e,t){let n=[],r=new Set(t.completedEntryIndexes),a=new Set(t.blockedEntryIndexes),s=e.extractEntries(t).filter(c=>{if(r.has(c.index))return n.push({index:c.index,reason:"entry already completed before recovery"}),!1;if(a.has(c.index))return n.push({index:c.index,reason:"entry was blocked by a guard"}),!1;let g=e.isCompleteEntry?.(c,t)??c.complete;return g||n.push({index:c.index,reason:t.recoverCompleteBatch?"entry was incomplete in the recovered batch":"entry was incomplete before the stale entry"}),!t.recoverCompleteBatch&&t.staleEntryIndex!==void 0&&c.index>=t.staleEntryIndex?!1:g}),i=e.filterEntries?.(s,t)??s,d=new Set(i.map(c=>c.index));for(let c of s)d.has(c.index)||n.push({index:c.index,reason:"entry was excluded by recovery filtering"});let u=[];for(let c of i)try{e.validateEntry?.(c,t),u.push(c)}catch(g){n.push({index:c.index,reason:g instanceof Error?g.message:String(g)})}let m={toolName:t.toolName,contentIndex:t.contentIndex,...t.staleEntryIndex!==void 0&&{staleEntryIndex:t.staleEntryIndex},staleDetails:t.staleDetails};if(u.length===0)return{...m,status:"skipped",appliedEntries:[],skippedEntries:n};try{let c=e.buildParams(u,t),g=await e.execute(c,{contentIndex:t.contentIndex,toolCallId:t.toolCallId,toolName:t.toolName,cwd:t.cwd,ctx:t.ctx,signal:new AbortController().signal});return{...m,status:"recovered",appliedEntries:e.getAppliedEntries?.(g,u,t)??u.map(b=>b.index),skippedEntries:n,normalResult:g}}catch(c){return{...m,status:"failed",appliedEntries:[],skippedEntries:n,error:c instanceof Error?c.message:String(c)}}}};import{createAssistantMessageEventStream as L}from"@earendil-works/pi-ai";var M=Symbol.for("pi-agent-text-editor.tool-call-interceptor.streaming-provider.state");function N(o,e,t,n){let r=new Map,a={context:void 0,processStreamEvent:e,markStreamEventProcessed:t,finalizeStreamInterception:n},l=y((s,i)=>{if(!s)return;let d=i.modelRegistry.getProvider(s.provider);if(!d)return;let u=r.get(s.provider);if(u){if(u.subscribers.add(a),u.api===s.api&&d.streamSimple===u.wrapper)return;u.api=s.api;let p=i.modelRegistry.getRegisteredProviderConfig(s.provider);o.registerProvider(s.provider,{...p,api:s.api,streamSimple:u.wrapper});return}let m=d.streamSimple[M];if(m){if(m.subscribers.add(a),r.set(s.provider,m),m.api===s.api)return;m.api=s.api;let p=i.modelRegistry.getRegisteredProviderConfig(s.provider);o.registerProvider(s.provider,{...p,api:s.api,streamSimple:m.wrapper});return}let c=d.streamSimple.bind(d),g=new Set([a]),b=y((p,v,C)=>F(c,p,v,C,g),"wrapper"),E={api:s.api,delegate:c,wrapper:b,subscribers:g};b[M]=E;let f=i.modelRegistry.getRegisteredProviderConfig(s.provider);o.registerProvider(s.provider,{...f,api:s.api,streamSimple:b}),r.set(s.provider,E)},"install");o.on("before_provider_request",(s,i)=>{a.context=i,l(i.model,i)}),o.on("turn_start",(s,i)=>{a.context=i,l(i.model,i)}),o.on("agent_start",(s,i)=>{a.context=i,l(i.model,i)}),o.on("session_start",(s,i)=>{a.context=i,l(i.model,i)}),o.on("model_select",(s,i)=>{a.context=i,l(s.model,i)}),o.on("session_shutdown",()=>{for(let[s,i]of r)i.subscribers.delete(a),i.subscribers.size===0&&o.unregisterProvider(s);r.clear(),a.context=void 0})}y(N,"registerStreamingInterceptorProvider");function F(o,e,t,n,r){let a=L(),l=new AbortController,s=n?.signal,i=!1,d=Q(e),u=new Set,m=new Set,c=new Set,g=new Set,b=y(f=>{for(let p of r)p.markStreamEventProcessed(f)},"markStreamEventProcessed"),E=y(()=>{l.abort()},"abortFromParent");return s&&(s.aborted?l.abort():s.addEventListener("abort",E,{once:!0})),(async()=>{try{let f=o(e,t,{...n,signal:l.signal});for await(let p of f){if(i)continue;p.type==="done"?d=structuredClone(p.message):p.type==="error"?d=structuredClone(p.error):d=structuredClone(p.partial),H(p,u);let v;for(let C of r){let I=C.context;if(I){let T=await C.processStreamEvent(p,I);v??=T}}if(b(p),W(p,m,c,g),a.push(structuredClone(p)),v){if(p.type==="toolcall_delta"||p.type==="toolcall_end")for(let x of r)x.finalizeStreamInterception(p.contentIndex);i=!0,l.abort();let C=p.type==="toolcall_delta"||p.type==="toolcall_end"?p.contentIndex:void 0,I={...d,content:d.content.filter((x,A)=>u.has(A)&&(C===void 0||A<=C||g.has(A))).map(x=>x.type==="toolCall"&&x.id===v.toolCallId?{...x,arguments:structuredClone(v.arguments)}:x)};U(a,b,I,u,m,c,g);let{errorMessage:T,...j}=I;a.push({type:"done",reason:"toolUse",message:{...j,stopReason:"toolUse"}}),a.end();continue}if(p.type==="done"||p.type==="error"){a.end();return}}}catch(f){if(i)return;let p=d,v=s?.aborted===!0?"aborted":"error",C={...p,stopReason:v,errorMessage:f instanceof Error?f.message:String(f)};a.push({type:"error",reason:v,error:C}),a.end()}finally{s?.removeEventListener("abort",E)}})(),a}y(F,"wrapStream");function H(o,e){(o.type==="text_start"||o.type==="thinking_start"||o.type==="toolcall_start")&&e.add(o.contentIndex)}y(H,"rememberStartEvent");function W(o,e,t,n){switch(o.type){case"text_end":{e.add(o.contentIndex);break}case"thinking_end":{t.add(o.contentIndex);break}case"toolcall_end":{n.add(o.contentIndex);break}}}y(W,"rememberEndEvent");function U(o,e,t,n,r,a,l){for(let[s,i]of t.content.entries())if(n.has(s)){if(i.type==="text"&&!r.has(s)){let d={type:"text_end",contentIndex:s,content:i.text,partial:t};e(d),o.push(d)}else if(i.type==="thinking"&&!a.has(s)){let d={type:"thinking_end",contentIndex:s,content:i.thinking,partial:t};e(d),o.push(d)}else if(i.type==="toolCall"&&!l.has(s)){let d={type:"toolcall_end",contentIndex:s,toolCall:i,partial:t};e(d),o.push(d)}}}y(U,"emitMissingEndEvents");function Q(o){return{role:"assistant",content:[],api:o.api,provider:o.provider,model:o.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"toolUse",timestamp:Date.now()}}y(Q,"emptyAssistantMessage");var V="agentic-ide-partial-tool-recovery",$="pi-agent-text-editor/tool-call-annotation",S=new WeakMap,k=class{constructor(e){this.pi=e;e.on("tool_call",t=>{let n=this.toolCallRecords.get(t.toolCallId),r=n?.blockExecution?n.guardResult:void 0;return r?{block:!0,reason:r.content.filter(l=>l.type==="text").map(l=>l.text).join(`
2
2
  `)||`Tool call ${t.toolName} was blocked by a streaming interceptor.`}:void 0}),e.on("tool_result",t=>{let n=this.toolCallBatchEntryIndexes.get(t.toolCallId);n!==void 0&&this.completedBatchEntryIndexes.add(n);let r=this.toolCallRecords.get(t.toolCallId)?.guardResult;if(this.toolCallRecords.delete(t.toolCallId),r)return{content:r.content,details:r.details,isError:!0}}),e.on("message_update",async(t,n)=>{let r=t.assistantMessageEvent;this.consumeProcessedStreamEvent(r)||await this.processStreamEvent(r,n)}),e.on("message_end",async t=>{if(await this.finalizeRecovery(),this.annotateIncompleteCalls(),t.message.role!=="assistant")return;let n=this.pendingAbortReason;if(this.pendingAbortReason=void 0,!(n===void 0||t.message.stopReason!=="aborted"))return{message:{...t.message,errorMessage:n}}}),e.on("agent_end",async()=>{await this.finalizeRecovery(),this.annotateIncompleteCalls(),this.cleanupAll()})}static{y(this,"InterceptorImpl")}handlers=new Map;recoveryRegistry=new R;pendingRecoveryBlocks=[];pendingAbortReason;recoveryAppliedBatchIndexes=new Set;partialBuffers=new Map;completeArgumentContentIndices=new Set;streamedBatchEntries=new Map;batchEntryIndexes=new Map;toolCallBatchEntryIndexes=new Map;completedBatchEntryIndexes=new Set;nextBatchEntryIndex=0;contentNames=new Map;contentToolCallIds=new Map;pendingToolCallAnnotations=new Map;emittedToolCallAnnotationKinds=new Map;abortedContentIndices=new Set;dispatchQueues=new Map;abortCleanups=new Map;processedStreamEvents=new WeakSet;processedStreamEventKeys=new Map;toolCallRecords=new Map;blockedCallSink;processStreamEvent(e,t){if(e.type==="toolcall_start"){let n=e.partial.content[e.contentIndex];if(n?.type==="toolCall"){let r=this.getOrCreateBatchEntryIndex(e.contentIndex);this.contentNames.set(e.contentIndex,n.name),typeof n.id=="string"&&this.bindToolCallId(e.contentIndex,n.id),this.partialBuffers.set(e.contentIndex,""),this.streamedBatchEntries.set(e.contentIndex,{index:r,toolName:n.name,args:{},complete:!1}),this.installAbortCleanup(e.contentIndex,t.signal)}return Promise.resolve(void 0)}return e.type==="toolcall_delta"?this.enqueue(e.contentIndex,async()=>{let n=this.contentNames.get(e.contentIndex),r=this.contentToolCallIds.get(e.contentIndex);if(!n)return;let a=(this.partialBuffers.get(e.contentIndex)??"")+e.delta;this.partialBuffers.set(e.contentIndex,a),this.installAbortCleanup(e.contentIndex,t.signal);let l=B(a,_.OBJ|_.ARR)??{},s=J(a),i=this.getOrCreateBatchEntryIndex(e.contentIndex);this.streamedBatchEntries.set(e.contentIndex,{index:i,toolName:n,args:l,complete:s!==void 0});let d=this.handlers.get(n);if(!r||!d||d.length===0||!s&&Object.keys(l).length===0)return;let u=s!==void 0;if(u&&this.completeArgumentContentIndices.has(e.contentIndex))return;u&&this.completeArgumentContentIndices.add(e.contentIndex);let m=s??l,c=await this.dispatchHandlers(d,{toolCall:{id:r,name:n,arguments:m},args:m,...!u&&{partialArgs:l},batchEntryIndex:i,batchEntries:this.getBatchEntries(i),contentIndex:e.contentIndex,cwd:t.cwd,signal:t.signal,ctx:t});return c&&this.rememberOriginalArguments(c.toolCallId,c.arguments),c}):e.type==="toolcall_end"?this.enqueue(e.contentIndex,async()=>{let n=e.toolCall.name,r=this.handlers.get(n),a=this.getOrCreateBatchEntryIndex(e.contentIndex);this.bindToolCallId(e.contentIndex,e.toolCall.id);let l=this.toolCallRecords.get(e.toolCall.id);this.toolCallRecords.set(e.toolCall.id,{originalArguments:structuredClone(e.toolCall.arguments),...l?.guardResult&&{guardResult:l.guardResult},...l?.blockExecution&&{blockExecution:!0}}),this.streamedBatchEntries.set(e.contentIndex,{index:a,toolName:n,args:e.toolCall.arguments,complete:!1});let s=!this.completeArgumentContentIndices.has(e.contentIndex),i;s&&(this.completeArgumentContentIndices.add(e.contentIndex),i=r&&r.length>0?await this.dispatchHandlers(r,{toolCall:e.toolCall,args:e.toolCall.arguments,batchEntryIndex:a,batchEntries:this.getBatchEntries(a),contentIndex:e.contentIndex,cwd:t.cwd,signal:t.signal,ctx:t}):void 0);let d=this.streamedBatchEntries.get(e.contentIndex);return d&&this.streamedBatchEntries.set(e.contentIndex,{...d,complete:!0}),this.cleanupContent(e.contentIndex,n),i}):Promise.resolve(void 0)}markStreamEventProcessed(e){this.processedStreamEvents.add(e);let t=O(e);t!==void 0&&this.processedStreamEventKeys.set(t,(this.processedStreamEventKeys.get(t)??0)+1)}consumeProcessedStreamEvent(e){let t=this.processedStreamEvents.delete(e),n=O(e);if(n===void 0)return t;let r=this.processedStreamEventKeys.get(n)??0;return r===0?t:(r===1?this.processedStreamEventKeys.delete(n):this.processedStreamEventKeys.set(n,r-1),!0)}finalizeStreamInterception(e){this.cleanupTransientContent(e,void 0,!0)}getToolCallRecord(e){return this.toolCallRecords.get(e)}rememberOriginalArguments(e,t){let n=this.toolCallRecords.get(e);n&&this.toolCallRecords.set(e,{originalArguments:structuredClone(t),...n.guardResult&&{guardResult:n.guardResult},...n.blockExecution&&{blockExecution:!0}})}async dispatchHandlers(e,t){for(let n of e){let r=await n.intercept(t);if(r!==void 0){this.pendingRecoveryBlocks.push({blocked:r,ctx:t});let a={content:[{type:"text",text:r.message.content}],details:r.message.details??null};return this.blockedCallSink?.({callId:t.toolCall.id,toolName:t.toolCall.name,arguments:structuredClone(t.args),...t.contentIndex!==void 0&&{contentIndex:t.contentIndex},...t.batchEntryIndex!==void 0&&{batchEntryIndex:t.batchEntryIndex},...r.message.details!==void 0&&{details:r.message.details},result:a,nativeExecutionBlocked:n.blockExecution===!0}),{toolCallId:t.toolCall.id,arguments:structuredClone(t.args),result:this.abortToolCall(r,t,n.name,n.blockExecution===!0)}}}}annotateIncompleteCalls(){for(let[e,t]of this.streamedBatchEntries)!t.complete&&this.contentNames.has(e)&&!this.recoveryAppliedBatchIndexes.has(t.index)&&!this.emittedToolCallAnnotationKinds.get(e)?.has("stale-anchor")&&this.annotateContent(e,{kind:"aborted"})}bindToolCallId(e,t){this.contentToolCallIds.set(e,t);let n=this.batchEntryIndexes.get(e);n!==void 0&&this.toolCallBatchEntryIndexes.set(t,n);let r=this.pendingToolCallAnnotations.get(e);if(r){for(let a of r)this.emitToolCallAnnotation(t,a);this.pendingToolCallAnnotations.delete(e)}}annotateContent(e,t){let n=this.emittedToolCallAnnotationKinds.get(e)??new Set;if(n.has(t.kind))return;n.add(t.kind),this.emittedToolCallAnnotationKinds.set(e,n);let r=this.contentToolCallIds.get(e);if(r){this.emitToolCallAnnotation(r,t);return}let a=this.pendingToolCallAnnotations.get(e)??[];a.push(t),this.pendingToolCallAnnotations.set(e,a)}emitToolCallAnnotation(e,t){let n={toolCallId:e,annotation:t};this.pi.events.emit($,n)}getOrCreateBatchEntryIndex(e){let t=this.batchEntryIndexes.get(e);if(t!==void 0)return t;let n=this.nextBatchEntryIndex;return this.nextBatchEntryIndex+=1,this.batchEntryIndexes.set(e,n),n}getBatchEntries(e){return[...this.streamedBatchEntries.values()].filter(t=>t.index<=e).sort((t,n)=>t.index-n.index)}getAllBatchEntries(){return[...this.streamedBatchEntries.values()].sort((e,t)=>e.index-t.index)}abortToolCall(e,t,n,r){let a=Y(e,n),l=e.annotation?e.annotation.kind==="aborted"&&e.annotation.label===void 0?{...e.annotation,label:a}:e.annotation:e.message.customType==="text-editor-stale-anchor-block"?{kind:"stale-anchor",label:a}:{kind:"aborted",label:a,color:"error"};t.contentIndex!==void 0&&(this.abortedContentIndices.add(t.contentIndex),this.annotateContent(t.contentIndex,l));let s={content:[{type:"text",text:e.message.content}],details:w(e.message.details,l,a)};return this.toolCallRecords.set(t.toolCall.id,{originalArguments:structuredClone(t.args),guardResult:s,...r&&{blockExecution:!0}}),s}async finalizeRecovery(){let e=this.pendingRecoveryBlocks.splice(0);if(e.length===0)return;let t=new Map;for(let n of e){let r=this.recoveryRegistry.recoveryKeyFor(n.ctx.toolCall.name);if(r===void 0)continue;let a=t.get(r)??[];a.push(n),t.set(r,a)}for(let n of t.values()){let r=n[0];if(!r)continue;let a=await this.recoverIfNeeded(r.blocked,r.ctx,this.getAllBatchEntries(),n);if(a===r.blocked)continue;let l=a.message.details,i=(h.IsObjectNotArray(l)&&h.IsObjectNotArray(l.recovery)?l.recovery:void 0)?.appliedEntries;if(Array.isArray(i))for(let d of i)typeof d=="number"&&this.recoveryAppliedBatchIndexes.add(d)}}async recoverIfNeeded(e,t,n,r){if(t.contentIndex===void 0)return e;let a=e.message.details,l=h.IsObjectNotArray(a)&&typeof a.entryIndex=="number"?a.entryIndex:void 0,s=[...new Set(r.map(g=>g.ctx.batchEntryIndex).filter(g=>g!==void 0))],i=[...new Set(r.map(g=>g.ctx.toolCall.id))],d=r.map(g=>g.blocked.message.details),u=r[0],m=u?this.recoveryRegistry.recoveryKeyFor(u.ctx.toolCall.name):void 0;if(!m)return e;let c=await this.recoveryRegistry.recover({contentIndex:t.contentIndex,toolCallId:t.toolCall.id,toolName:t.toolCall.name,...l!==void 0&&{staleEntryIndex:l},staleDetails:a,...t.partialArgs&&{partialArgs:t.partialArgs},args:t.args,batchEntries:n,...t.batchEntryIndex!==void 0&&{batchEntryIndex:t.batchEntryIndex},recoverCompleteBatch:!0,completedEntryIndexes:[...this.completedBatchEntryIndexes],blockedEntryIndexes:s,blockedToolCallIds:i,blockedDetails:d,recoveryKey:m,cwd:t.cwd,ctx:t.ctx});return c&&(c.appliedEntries.length>0||c.skippedEntries.length>0)?ee(e,c):e}async enqueue(e,t){let r=(this.dispatchQueues.get(e)??Promise.resolve()).catch(()=>{}).then(t);this.dispatchQueues.set(e,r);try{return await r}finally{this.dispatchQueues.get(e)===r&&this.dispatchQueues.delete(e)}}installAbortCleanup(e,t){if(!t||this.abortCleanups.has(e))return;let n=y(()=>{let r=this.contentNames.get(e),a=r?this.handlers.get(r):void 0;for(let l of a??[])l.onAbort?.(e)},"listener");t.addEventListener("abort",n,{once:!0}),this.abortCleanups.set(e,()=>{t.removeEventListener("abort",n)})}cleanupContent(e,t){this.cleanupTransientContent(e,t),this.recoveryRegistry.cleanup(e)}cleanupTransientContent(e,t,n=!1){let r=t??this.contentNames.get(e),a=r?this.handlers.get(r):void 0;for(let l of a??[])n&&l.onAbort?.(e),l.onContentEnd?.(e);this.abortCleanups.get(e)?.(),this.abortCleanups.delete(e),this.contentNames.delete(e),this.contentToolCallIds.delete(e),this.pendingToolCallAnnotations.delete(e),this.emittedToolCallAnnotationKinds.delete(e),this.completeArgumentContentIndices.delete(e),this.partialBuffers.delete(e),this.abortedContentIndices.delete(e)}cleanupAll(){for(let e of this.handlers.values())for(let t of e)t.onAgentEnd?.();for(let e of this.abortCleanups.values())e();this.abortCleanups.clear(),this.contentNames.clear(),this.contentToolCallIds.clear(),this.pendingToolCallAnnotations.clear(),this.completeArgumentContentIndices.clear(),this.emittedToolCallAnnotationKinds.clear(),this.partialBuffers.clear(),this.streamedBatchEntries.clear(),this.batchEntryIndexes.clear(),this.toolCallBatchEntryIndexes.clear(),this.toolCallRecords.clear(),this.completedBatchEntryIndexes.clear(),this.nextBatchEntryIndex=0,this.abortedContentIndices.clear(),this.pendingAbortReason=void 0,this.dispatchQueues.clear(),this.processedStreamEventKeys.clear(),this.recoveryRegistry.cleanupAll(),this.pendingRecoveryBlocks.length=0,this.recoveryAppliedBatchIndexes.clear()}registerRecovery(e){this.recoveryRegistry.register(e)}unregisterRecovery(e){this.recoveryRegistry.unregister(e)}registerBlockedCallSink(e){this.blockedCallSink=e}register(e){let t=new Set(e.toolNames);for(let[n,r]of this.handlers){let a=r.findIndex(l=>l.name===e.name);a!==-1&&(t.has(n)?(r[a]=e,t.delete(n)):r.splice(a,1))}for(let n of t){let r=this.handlers.get(n)??[];r.push(e),this.handlers.set(n,r)}}unregister(e){for(let[t,n]of this.handlers)this.handlers.set(t,n.filter(r=>r.name!==e))}};function O(o){if(o.type==="toolcall_end")return`${o.type}\0${o.contentIndex}\0${o.toolCall.id}`;if(o.type!=="toolcall_start"&&o.type!=="toolcall_delta")return;let e=o.partial.content[o.contentIndex],t=e?.type==="toolCall"?e.id:"",n=o.type==="toolcall_delta"?o.delta:"";return`${o.type}\0${o.contentIndex}\0${t}\0${n}`}y(O,"toolStreamEventKey");function Y(o,e){return o.annotation?.reason?o.annotation.reason:o.annotation?.label?o.annotation.label:o.message.customType==="text-editor-stale-anchor-block"?"Stale Anchor":e.replace(/[-_]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().replace(/\b\w/g,t=>t.toUpperCase())||"Blocked"}y(Y,"abortReason");function J(o){try{let e=JSON.parse(o);return h.IsObjectNotArray(e)?e:void 0}catch{return}}y(J,"parseCompleteArguments");function Z(o){let e=o.normalResult;if(!h.IsObjectNotArray(e)||!h.IsObjectNotArray(e.details))return[];let t=e.details.results;if(!Array.isArray(t))return[];let n=h.IsObjectNotArray(o.staleDetails)&&typeof o.staleDetails.path=="string"?o.staleDetails.path:void 0,r=t.filter(h.IsObjectNotArray).map(i=>h.IsObjectNotArray(i.data)?i.data:i),a=n===void 0?r:r.filter(i=>i.path===n),s=(a.length>0?a:r).flatMap(i=>{let d=i.freshAnchors;return Array.isArray(d)?d.filter(u=>typeof u=="string"):[]});return[...new Set(s)]}y(Z,"freshAnchorsAfterRecovery");function X(o,e){let n=o.indexOf(`
3
3
 
4
4
  Current nearby anchors:`);return`${n===-1?o:o.slice(0,n)}
@@ -0,0 +1 @@
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};
@@ -0,0 +1,2 @@
1
+ import{a as o}from"./chunk-EI7MMDWY.js";import{Type as t}from"typebox";import{Value as C}from"typebox/value";var f=Symbol.for("pi-agent-text/TextAnchor"),u=class{constructor(n,r){this.value=n;this.lineNumber=r;if(n.length===0)throw new TypeError("Text anchor value must be non-empty");if(!Number.isSafeInteger(r)||r<1)throw new RangeError("Text anchor line number must be a positive safe integer")}static{o(this,"TextAnchor")}[f]=!0;static is(n){if(typeof n!="object"||n===null)return!1;try{let r=n;return r[f]===!0&&typeof r.value=="string"&&Number.isSafeInteger(r.lineNumber)&&r.lineNumber>=1}catch{return!1}}toString(){return this.value}},x=new WeakMap;function w(e,n,r){x.set(e,{renderer:n,resolverId:r})}o(w,"attachTextAnchorRenderer");function S(e){return x.get(e)?.renderer}o(S,"getTextAnchorRenderer");function P(e,n,r){let i=x.get(e);if(i===void 0)throw new Error(`No renderer is attached to text anchor "${n}"`);return{...i.renderer,resolverId:i.resolverId,full:i.renderer.renderFull(n,r),compact:i.renderer.renderCompact(n,r)}}o(P,"renderTextAnchor");var a={additionalProperties:!0},l=t.Function([],t.Unknown()),g=t.Object({lineNumber:t.Integer({minimum:1}),column:t.Integer({minimum:0})},a),j=t.Object({rank:t.Integer({minimum:1}),range:t.Object({start:g,end:g},a)},a),L=t.Object({id:t.String({minLength:1}),description:t.Union([t.String(),l]),normalize:t.Optional(l),renderFull:l,renderCompact:l,tryResolve:l,recover:t.Optional(l)},a),O=t.Object({code:t.Union([t.Literal("invalid"),t.Literal("stale"),t.Literal("missing"),t.Literal("ambiguous")]),reason:t.String(),contextRange:t.Optional(t.Object({offset:t.Number(),limit:t.Number()}))}),E=t.Union([t.Object({kind:t.Literal("not-handled")},a),t.Object({kind:t.Literal("resolved"),anchor:t.Unknown()},a),t.Object({kind:t.Literal("rejected"),rejection:O},a),t.Object({kind:t.Literal("failed"),error:t.Unknown()},a)]),N=t.Union([t.Object({kind:t.Literal("unavailable")},a),t.Object({kind:t.Literal("candidates"),candidates:t.Array(j),total:t.Integer({minimum:0})},a),t.Object({kind:t.Literal("timed-out")},a),t.Object({kind:t.Literal("failed"),error:t.Unknown()},a)]);function D(e){return p(L,e)&&y(()=>e.id.trim().length>0)}o(D,"isTextAnchorResolver");function I(e){return p(E,e)&&y(()=>{let n=e;return n.kind!=="resolved"||u.is(n.anchor)})}o(I,"isTextAnchorResolutionAttempt");function M(e){return p(N,e)}o(M,"isTextAnchorRecoveryOutcome");function p(e,n){return y(()=>C.Check(e,n))}o(p,"safeCheck");function y(e){try{return e()}catch{return!1}}o(y,"safeEvaluate");function T(e){if(!e.some(i=>i.marker!==void 0))return e.map(i=>`${i.prefix??""}${i.content}${i.suffix??""}`);let r=Math.max(0,...e.map(i=>i.prefix?.length??0));return e.map(i=>`${i.marker??" "}|${(i.prefix??"").padStart(r," ")}${i.content}${i.suffix??""}`)}o(T,"renderPresentedTextRows");var h="pi-agent-text/source-line";function $(e){let n=e.metadata?.[h];if(F(n))return n}o($,"getTextSourceLine");function U(e,n){return{...e,metadata:{...e.metadata,[h]:n}}}o(U,"withTextSourceLine");function F(e){if(typeof e!="object"||e===null)return!1;let n=e;return typeof n.source=="string"&&n.source.length>0&&typeof n.lineNumber=="number"&&Number.isInteger(n.lineNumber)&&n.lineNumber>0&&typeof n.content=="string"}o(F,"isTextSourceLine");import{Type as d}from"typebox";import{Value as W}from"typebox/value";var q=d.Function([],d.Unknown()),R=d.Object({id:d.String({minLength:1}),present:q}),B=d.Object({presenter:R,priority:d.Optional(d.Number())});function V(e){return A(R,e)}o(V,"isTextLinePresenter");function _(e){return A(B,e)}o(_,"isTextPresenterRegistration");function z(e,n){return{source:e,content:n,lines:H(n)}}o(z,"createTextDocument");function K(e){return e.lines.map(n=>`${n.content}${n.lineEnding}`).join("")}o(K,"renderTextDocument");function Y(e,n={}){let r=e.lines.flatMap(s=>[...s.presentation?.before??[],G(s,n.compact===!0),...s.presentation?.after??[]]),i=T(r),c=0;return e.lines.map(s=>{let m=1+(s.presentation?.before?.length??0)+(s.presentation?.after?.length??0),k=i.slice(c,c+m).join(`
2
+ `);return c+=m,`${k}${s.lineEnding}`}).join("")}o(Y,"renderPresentedTextDocument");function G(e,n){let r=n&&e.presentation?.compactPrefix!==void 0?e.presentation.compactPrefix:e.presentation?.prefix,i=n&&e.presentation?.compactSuffix!==void 0?e.presentation.compactSuffix:e.presentation?.suffix;return{content:e.content,...r!==void 0&&{prefix:r},...i!==void 0&&{suffix:i},...e.presentation?.marker!==void 0&&{marker:e.presentation.marker}}}o(G,"presentedRowFor");function H(e){if(e.length===0)return[];let n=[],r=/([^\r\n]*)(\r\n|\r|\n|$)/gu,i;for(;(i=r.exec(e))!==null&&i[0].length!==0;)n.push({lineNumber:n.length+1,content:i[1]??"",lineEnding:i[2]??""});return n}o(H,"splitTextLines");function A(e,n){try{return W.Check(e,n)}catch{return!1}}o(A,"safeCheck");var J=new Set(["application/ecmascript","application/graphql","application/javascript","application/json","application/sql","application/toml","application/x-httpd-php","application/x-javascript","application/x-ndjson","application/x-www-form-urlencoded","application/x-yaml","application/xml","application/yaml"]);function Q(){return{id:"text",description:"Text file paths and URLs return their text.",tryConvert(e,n){return Promise.resolve(X(e,n))}}}o(Q,"createTextContentConverter");function X(e,n){let r=ee(n.signal);if(r!==void 0)return{kind:"failed",error:r};try{return{kind:"converted",content:[{type:"text",text:new TextDecoder("utf8",{fatal:!0}).decode(e.bytes)}]}}catch(i){return b(e.mediaType)?{kind:"failed",error:new TypeError(`${e.source} is not valid UTF-8 text`,{cause:i})}:{kind:"not-handled"}}}o(X,"convertText");function b(e){if(e===void 0)return!1;let n=e.split(";",1)[0]?.trim().toLowerCase()??"";return n.startsWith("text/")||J.has(n)||n.endsWith("+json")||n.endsWith("+xml")}o(b,"isTextualMediaType");function Z(e){let n=e[0];if(e.length!==1||n.type!=="text")throw new TypeError("Text resources require exactly one text block");return n.text}o(Z,"textFromAgentContent");function ee(e){if(e?.aborted===!0)return e.reason instanceof Error?e.reason:ne()}o(ee,"cancellationError");function ne(){let e=new Error("The operation was aborted");return e.name="AbortError",e}o(ne,"abortError");function te(e){if(e===null||typeof e!="object")return!1;let n=e;if(n.kind==="not-handled")return!0;if(n.kind==="failed")return"error"in n;if(n.kind==="rejected"){let r=n.rejection;return r!==null&&typeof r=="object"&&["invalid","stale","missing","ambiguous"].includes(r.code)&&typeof r.reason=="string"}return n.kind!=="resolved"||!Array.isArray(n.targets)||n.targets.length===0?!1:n.targets.every(r=>{if(r===null||typeof r!="object")return!1;let i=r.source,c=r.ranges;return typeof i=="string"&&i.length>0&&(r.expectedContent===void 0||typeof r.expectedContent=="string")&&(c===void 0||Array.isArray(c)&&c.every(re))})}o(te,"isTextTargetResolutionAttempt");function re(e){if(e===null||typeof e!="object")return!1;let n=e;return v(n.start)&&v(n.end)&&(n.linewise===void 0||typeof n.linewise=="boolean")}o(re,"isTextSelectionRange");function v(e){if(e===null||typeof e!="object")return!1;let n=e;return Number.isInteger(n.lineNumber)&&n.lineNumber>=1&&Number.isInteger(n.column)&&n.column>=0}o(v,"isTextSelectionPosition");function oe(e,n){if(e.length<16)return e;let r=n.indexOf(e);return r<0?e:[r,e.length]}o(oe,"storeText");function ie(e,n){return typeof e=="string"?e:n.slice(e[0],e[0]+e[1])}o(ie,"restoreText");export{u as a,w as b,S as c,P as d,D as e,I as f,M as g,T as h,$ as i,U as j,V as k,_ as l,z as m,K as n,Y as o,Q as p,b as q,Z as r,te as s,oe as t,ie as u};
File without changes
@@ -1 +1 @@
1
- import{c as a,d as u,e as c}from"./chunk-JASLOB2X.js";import{a as t}from"./chunk-EI7MMDWY.js";function E(o,r){let s=t(()=>{let e,i={plugin:r,accept(R){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=R}};return o.events.emit(u,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(a,e=>{if(!c(e))throw new Error("Invalid pi-agent-read core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-read core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(E,"connectReadPlugin");export{E as a};
1
+ import{c as a,d as u,e as c}from"./chunk-KAB3AYA2.js";import{a as t}from"./chunk-EI7MMDWY.js";function E(o,r){let s=t(()=>{let e,i={plugin:r,accept(R){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=R}};return o.events.emit(u,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(a,e=>{if(!c(e))throw new Error("Invalid pi-agent-read core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-read core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(E,"connectReadPlugin");export{E as a};
@@ -1 +1 @@
1
- import{a as o}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as n}from"typebox/value";var t="pi-agent-search",i=1,S="pi-agent-search/core/ready",R="pi-agent-search/plugin/register",a=e.Unsafe({type:"Function"}),s=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(i)}),c=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(i),id:e.String({minLength:1}),setup:a}),p=e.Object({plugin:c,accept:a});function g(r){return n.Check(s,r)}o(g,"isSearchCoreReady");function h(r){return n.Check(c,r)}o(h,"isSearchPlugin");function y(r){return n.Check(p,r)}o(y,"isSearchPluginRegistrationRequest");export{t as a,i as b,S as c,R as d,g as e,h as f,y as g};
1
+ import{a as o}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as n}from"typebox/value";var t="pi-agent-search",i=3,S="pi-agent-search/core/ready",R="pi-agent-search/plugin/register",a=e.Unsafe({type:"Function"}),s=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(i)}),c=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(i),id:e.String({minLength:1}),setup:a}),p=e.Object({plugin:c,accept:a});function g(r){return n.Check(s,r)}o(g,"isSearchCoreReady");function h(r){return n.Check(c,r)}o(h,"isSearchPlugin");function y(r){return n.Check(p,r)}o(y,"isSearchPluginRegistrationRequest");export{t as a,i as b,S as c,R as d,g as e,h as f,y as g};
@@ -1 +1 @@
1
- import{a as n}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as i}from"typebox/value";var t=e.Function([],e.Unknown()),d=e.Union([e.Object({stage:e.Literal("text-pre-edit"),handler:t}),e.Object({stage:e.Literal("text-edit"),handler:t}),e.Object({stage:e.Literal("text-post-edit"),handler:t})]);function l(r){return i.Check(d,r)}n(l,"isTextEditHandlerRegistration");export{l as a};
1
+ import{a as n}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as d}from"typebox/value";var t=e.Function([],e.Unknown()),i=e.Union([e.Object({stage:e.Literal("text-pre-edit"),handler:t}),e.Object({stage:e.Literal("text-edit"),handler:t}),e.Object({stage:e.Literal("text-post-edit"),handler:t})]);function l(r){return d.Check(i,r)}n(l,"isTextEditHandlerRegistration");export{l as a};
@@ -1,3 +1,3 @@
1
- import{a as w}from"./chunk-2SKAED2I.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(`
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
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
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};
@@ -0,0 +1,6 @@
1
+ import{a as r}from"./chunk-EI7MMDWY.js";var c=new TextEncoder().encode("%PDF-"),b=1024;function w(){return{id:"pdf",description:"PDF paths and URLs return the document's readable content.",async tryConvert(e,t){let n=f(t.signal);if(n!==void 0)return{kind:"failed",error:n};if(!h(e.bytes))return T(e.mediaType)?{kind:"failed",error:new TypeError(`${e.source} is not a valid PDF document`)}:{kind:"not-handled"};try{return{kind:"converted",content:await y(e.bytes,t.signal)}}catch(o){return{kind:"failed",error:f(t.signal)??new TypeError(`Unable to read PDF document ${e.source}: ${A(o)}`,{cause:o})}}}}}r(w,"createPdfContentConverter");function h(e){let t=Math.min(e.length,b+c.length);for(let n=0;n+c.length<=t;n+=1)if(c.every((o,s)=>e[n+s]===o))return!0;return!1}r(h,"isPdf");async function y(e,t){i(t);let{getDocument:n}=await import("pdfjs-dist/legacy/build/pdf.mjs");i(t);let o=n({data:new Uint8Array(e),useSystemFonts:!0}),s,u=r(()=>s??=o.destroy(),"destroy"),l=r(()=>{u()},"abort");t?.addEventListener("abort",l,{once:!0});try{let d=await o.promise;i(t);let g=[];for(let a=1;a<=d.numPages;a+=1){i(t);let m=await d.getPage(a),P=await m.getTextContent();i(t);let p=x(P.items);g.push([`## Page ${a} of ${d.numPages}`,"",p.length===0?"[No extractable text on this page.]":p].join(`
2
+ `)),m.cleanup()}return[{type:"text",text:["# PDF document",...g].join(`
3
+
4
+ `)}]}finally{t?.removeEventListener("abort",l),await u().catch(()=>{})}}r(y,"createPdfContent");function x(e){let t="";for(let n of e)!C(n)||n.str.length===0||(t.length>0&&!E(t)&&!v(n.str)&&(t+=" "),t+=n.str,n.hasEOL===!0&&!t.endsWith(`
5
+ `)&&(t+=`
6
+ `));return t.trim()}r(x,"extractPageText");function C(e){return typeof e=="object"&&e!==null&&"str"in e&&typeof e.str=="string"}r(C,"isPdfTextItem");function v(e){return/^\s/u.test(e)}r(v,"startsWithWhitespace");function E(e){return/\s$/u.test(e)}r(E,"endsWithWhitespace");function T(e){return e?.split(";",1)[0]?.trim().toLowerCase()==="application/pdf"}r(T,"isPdfMediaType");function A(e){return e instanceof Error?e.message:String(e)}r(A,"errorMessage");function i(e){let t=f(e);if(t!==void 0)throw t}r(i,"throwIfAborted");function f(e){if(e?.aborted!==!0)return;if(e.reason instanceof Error)return e.reason;let t=new Error("The operation was aborted");return t.name="AbortError",t}r(f,"cancellationError");export{w as a,h as b,y as c};
@@ -0,0 +1,3 @@
1
+ import{b as v,c as E,d as S,e as I,g as _}from"./chunk-JMVDFOTQ.js";import{a as s}from"./chunk-EI7MMDWY.js";import{truncateToWidth as k,wrapTextWithAnsi as R}from"@earendil-works/pi-tui";var O="PI AGENT IDE",N=/\/[a-z][\w-]*/giu,m=class{constructor(t,r){this.tip=t;this.theme=r}static{s(this,"TipCallout")}cached;render(t){if(this.cached?.width===t)return this.cached.lines;let r=L(this.tip,this.theme,t);return this.cached={width:t,lines:r},r}invalidate(){this.cached=void 0}};function L(e,t,r){if(r<=0)return[];if(r<=2)return[t.fg("accent",r===1?"\u2502":"\u2502 ")];let i=r-2,n=t.fg("accent",t.bold(O))+t.fg("dim"," \xB7 ")+t.bold(e.title),o=e.body.split(`
2
+ `).map(c=>c.length===0?"":$(c,t)),a=[n,...o].flatMap(c=>D(c,i)),d=t.fg("accent","\u2502");return a.map(c=>k(`${d} ${c}`,r))}s(L,"renderTip");function D(e,t){return e.length===0?[""]:R(e,t)}s(D,"wrapLine");function $(e,t){let r="",i=0;for(let n of e.matchAll(N)){let o=n.index;r+=t.fg("muted",e.slice(i,o)),r+=t.fg("accent",t.bold(n[0])),i=o+n[0].length}return r+t.fg("muted",e.slice(i))}s($,"styleBodyLine");var y=class{static{s(this,"TipCore")}providers=new Map;registerProvider(t){if(!/^[a-z0-9][a-z0-9.-]*$/u.test(t.id))return Promise.reject(new Error(`Invalid tip provider ID: ${t.id}`));let r=this.providers.get(t.id);return r!==void 0?r===t?Promise.resolve():Promise.reject(new Error(`Tip provider ${t.id} is already registered`)):(this.providers.set(t.id,t),Promise.resolve())}get isEmpty(){return this.providers.size===0}async collectTips(t){let r=[];for(let i of this.providers.values()){if(t.signal?.aborted)break;try{let n=await M(i,t);n!==void 0&&z(n)&&r.push({providerId:i.id,tip:n})}catch{}}return r}};async function M(e,t){let r=t.signal;if(r===void 0)return e.getTip(t);if(r.aborted)return;let i=s(()=>{},"abort"),n=new Promise(o=>{i=s(()=>o(void 0),"abort"),r.addEventListener("abort",i,{once:!0})});try{return await Promise.race([e.getTip(t),n])}finally{r.removeEventListener("abort",i)}}s(M,"collectTip");function z(e){return typeof e.id=="string"&&/^[a-z0-9][a-z0-9.-]*$/u.test(e.id)&&typeof e.title=="string"&&e.title.trim().length>0&&typeof e.body=="string"&&e.body.trim().length>0}s(z,"isTip");import{randomUUID as U}from"node:crypto";import{mkdir as P,readFile as V,rename as G,rm as b,stat as J,writeFile as Y}from"node:fs/promises";import{setTimeout as F}from"node:timers/promises";import{homedir as K}from"node:os";import f from"node:path";var l=1,W=10,B=5e3,Q=6e4,u=Promise.resolve();function X(e=process.env){let t=e.PI_CODING_AGENT_DIR??f.join(K(),".pi","agent");return f.join(t,"pi-agent-ide","tips.json")}s(X,"resolveTipStatePath");var h=class{constructor(t=X()){this.statePath=t}static{s(this,"TipStateStore")}async shownFor(t){let r=await g(this.statePath);return new Set(r.projects[t]??[])}async claimIfUnseen(t,r,i){let n=u.then(async()=>{try{return await w(this.statePath,async()=>{let o=await g(this.statePath),a=new Set(o.projects[t]??[]);if(a.has(r)||i!==void 0&&a.has(i))return!1;a.add(r);let d={version:l,projects:{...o.projects,[t]:[...a]}};return await T(this.statePath,d),!0})}catch{return!0}});return u=n.then(()=>{},()=>{}),n}async markShown(t,r){if(r.length===0)return;u=u.then(async()=>{await w(this.statePath,async()=>{let n=await g(this.statePath),o=new Set(n.projects[t]??[]);for(let d of r)o.add(d);let a={version:l,projects:{...n.projects,[t]:[...o]}};await T(this.statePath,a)})}).catch(()=>{}),await u}async unmarkShown(t,r){u=u.then(async()=>{try{await w(this.statePath,async()=>{let n=await g(this.statePath),o=new Set(n.projects[t]??[]);if(!o.delete(r))return;let a={version:l,projects:{...n.projects,[t]:[...o]}};await T(this.statePath,a)})}catch{}}).catch(()=>{}),await u}};function j(e){return f.resolve(e)}s(j,"normalizeProjectPath");async function g(e){try{let t=JSON.parse(await V(e,"utf8"));return H(t)?t:C()}catch{return C()}}s(g,"readState");async function w(e,t){let r=`${e}.lock`;await P(f.dirname(e),{recursive:!0});let i=Date.now();for(;;)try{await P(r);break}catch(n){if(q(n)!=="EEXIST")throw n;try{if(Date.now()-(await J(r)).mtimeMs>Q){await b(r,{recursive:!0,force:!0});continue}}catch{}if(Date.now()-i>=B)throw new Error(`Timed out waiting for startup-tip state lock: ${r}`,{cause:n});await F(W)}try{return await t()}finally{await b(r,{recursive:!0,force:!0})}}s(w,"withStateLock");function q(e){return typeof e=="object"&&e!==null&&"code"in e?String(e.code):void 0}s(q,"errorCode");async function T(e,t){try{await P(f.dirname(e),{recursive:!0});let r=`${e}.${process.pid}.${U()}.tmp`;try{await Y(r,`${JSON.stringify(t,null,2)}
3
+ `,"utf8"),await G(r,e)}finally{await b(r,{force:!0})}}catch{}}s(T,"writeState");function C(){return{version:l,projects:{}}}s(C,"emptyState");function H(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e;return t.version!==l||typeof t.projects!="object"||t.projects===null?!1:Object.values(t.projects).every(r=>Array.isArray(r)&&r.every(i=>typeof i=="string"))}s(H,"isState");var A="pi-agent-ide-startup-tip";function Z(e){let t=new y,r=new h;e.registerEntryRenderer(A,(a,d,p)=>{let c=a.data;if(!(typeof c.title!="string"||typeof c.body!="string"))return new m({title:c.title,body:c.body},p)});let i=e.events.on(I,a=>{if(!_(a))throw new Error("Invalid tip provider registration request");a.accept(t.registerProvider(a.provider))});e.on("session_shutdown",i);let n,o=Promise.resolve();e.on("session_start",(a,d)=>{n?.abort(),n=new AbortController;let p=n.signal;o=o.then(()=>tt(e,t,r,a.reason,d,p)).catch(()=>{})}),e.on("session_shutdown",async()=>{n?.abort(),await o}),e.events.emit(S,{protocol:v,apiVersion:E})}s(Z,"registerTips");async function tt(e,t,r,i,n,o){if(n.mode!=="tui"||(o.throwIfAborted(),t.isEmpty))return;let a=await t.collectTips({cwd:n.cwd,mode:n.mode,hasUI:n.hasUI,signal:o,reason:i});if(o.throwIfAborted(),a.length===0)return;let d=j(n.cwd);for(let p of a){let c=et(p.providerId,p.tip.id);if(await r.claimIfUnseen(d,c,p.tip.id)){if(o.aborted){await r.unmarkShown(d,c);return}try{e.appendEntry(A,p.tip);return}catch(x){throw await r.unmarkShown(d,c),x}}}}s(tt,"displayTip");function et(e,t){return JSON.stringify([e,t])}s(et,"tipIdentity");export{Z as default};
@@ -1 +1 @@
1
- import{e as u,f as E,k as a}from"./chunk-266RH77Z.js";import{a as n}from"./chunk-EI7MMDWY.js";function T(o,r){let s=n(()=>{let e,i={plugin:r,accept(c){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=c}};return o.events.emit(E,i),e},"announce"),t=n(()=>{},"unsubscribe");t=o.events.on(u,e=>{if(!a(e))throw new Error("Invalid pi-agent-text-editor core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-text-editor core announced readiness without accepting the plugin");t(),i.catch(()=>{})}),o.on("session_shutdown",t);let d=s();if(d!==void 0)return t(),d}n(T,"connectTextEditorPlugin");export{T as a};
1
+ import{e as u,f as E,k as a}from"./chunk-LRYE2WCN.js";import{a as n}from"./chunk-EI7MMDWY.js";function T(o,r){let s=n(()=>{let e,i={plugin:r,accept(c){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=c}};return o.events.emit(E,i),e},"announce"),t=n(()=>{},"unsubscribe");t=o.events.on(u,e=>{if(!a(e))throw new Error("Invalid pi-agent-text-editor core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-text-editor core announced readiness without accepting the plugin");t(),i.catch(()=>{})}),o.on("session_shutdown",t);let d=s();if(d!==void 0)return t(),d}n(T,"connectTextEditorPlugin");export{T as a};
@@ -0,0 +1,2 @@
1
+ import"./chunk-NNCZYO4Q.js";import{c as N}from"./chunk-RHV5STR3.js";import"./chunk-YHUTTZC6.js";import{a as E}from"./chunk-72EEL2DW.js";import{a as A,b}from"./chunk-KAB3AYA2.js";import{d as O}from"./chunk-SSHZEWWV.js";import"./chunk-LRYE2WCN.js";import"./chunk-S3ZPXWX7.js";import{e as m,f as D,g as w,h as k,i as P,l as v}from"./chunk-NTYXZ3EL.js";import"./chunk-5VSE5X5R.js";import{a as C}from"./chunk-HKMBQLEK.js";import{a as y,b as I}from"./chunk-Z3VC3S2T.js";import"./chunk-KINKBPPX.js";import"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";import S from"node:path";var T="diagnostics",V=N({kind:"code-view",label:"Diagnostics"});async function q(c){let n,t=l((o,f,e)=>{if(n===void 0)throw new Error("IDE diagnostics are not connected");return n(o,{cwd:f,...e})},"collect"),i={protocol:y,apiVersion:4,id:"diagnostics",setup(o){n=o.readDiagnostics}},r=new WeakMap,s=new WeakMap,a=new WeakMap,d=new WeakMap,M={protocol:A,apiVersion:b,id:"diagnostics",setup(o){o.addResolver({resolver:W(t,s),renderResult:V});let f=v();o.addView({view:"diagnostics",priority:100,presenter:j(t,d)}),o.addHandler({stage:"read",when:{resolvedBy:"any",contentKind:"text"},handler(e){if(e.state?.resolvedBy==="diagnostics"){let g=e.state.content[0],u=s.get(g);return u&&r.set(e.request,u),f(e)}return e.state?.contentKind==="text"&&e.request.views?.includes("diagnostics")&&a.set(e.request,e.state.text),{kind:"continue",context:e}}}),o.addHandler({stage:"post-read",handler(e){let g=r.get(e.request);if(g&&e.result)return{kind:"continue",context:{...e,result:{...e.result,details:{...e.result.details,diagnosticCheck:g}}}};let u=a.get(e.request),h=u&&d.get(u),p=e.result,R=p?.content[0];return!h||!p||R?.type!=="text"?{kind:"continue",context:e}:{kind:"continue",context:{...e,result:{...p,content:[{...R,text:`${h}
2
+ ${R.text}`},...p.content.slice(1)]}}}}}),o.describe('diagnostics:<path> \u2014 lint and language-server diagnostics. views: ["diagnostics"] \u2014 diagnostics alongside source text. Diagnostic sources name the actual reporting tools. Automatic notices include findings only and wake an idle agent after the notification buffer (five seconds by default); silence does not prove the file is clean. Use an explicit diagnostic read to check readiness. Pending results and snapshots are not completed checks; an empty snapshot does not prove the file is clean.'),o.addPromptGuideline("Use read with `diagnostics:<path>` or the `diagnostics` view for per-file diagnostics instead of running equivalent checks through Bash. Project builds and tests remain separate verification.")}};await Promise.all([C(c,i),E(c,M)])}l(q,"registerDiagnostics");function W(c,n){return{id:"diagnostics",tryResolve(t,i){return Promise.resolve(_(t,i.cwd,c,n,{signal:i.signal,...i.audience==="script"&&{mode:"complete"}}))}}}l(W,"createDiagnosticResolver");function _(c,n,t,i,r){let s;try{s=m(c,T,n)}catch(a){return{kind:"failed",error:a}}return s===void 0?{kind:"not-handled"}:{kind:"resolved",resource:{source:D(T,s),async read(){let a=await t(s,n,r),d=w(s,a.content,a.results);return i.set(d,d.diagnosticCheck),[d]}}}}l(_,"resolveDiagnosticSource");function j(c,n){return{id:"diagnostics",async present(t,i){if(i.purpose!=="read"||!S.isAbsolute(t.source))return t;let r=i.audience==="script"&&!i.requestedViews?.includes("diagnostics");if(r&&O(t.source))return t;let s=await c(t.source,i.cwd,{signal:i.signal,...i.audience==="script"&&{mode:r?"snapshot":"complete"}}).catch(a=>{if(i.signal?.throwIfAborted(),!r)throw a});if(s===void 0||r&&s.content!==t.content)return t;if(s.content!==t.content)throw new Error("File changed during diagnostic read; read it again for current source lines.");return n.set(t,P(s.results)),k(t,s.results)}}}l(j,"createDiagnosticPresenter");export{q as default};
@@ -0,0 +1,4 @@
1
+ import{a as j,l as M}from"./chunk-SSHZEWWV.js";import{a as _}from"./chunk-CEKXBS55.js";import{a as N,b as O}from"./chunk-LRYE2WCN.js";import"./chunk-S3ZPXWX7.js";import"./chunk-5VSE5X5R.js";import{a as C,b as R,c as A,d as $,g as F}from"./chunk-Z3VC3S2T.js";import{a as k}from"./chunk-ZC65Z3CK.js";import{a as c}from"./chunk-EI7MMDWY.js";var h=[],y=[],P=[];function b(n,t,e){if(t.some(i=>i.name===e))throw new Error(`[pi-agent-ide] ${n} "${e}" is already registered. Use a unique name.`)}c(b,"assertUniqueName");function q(n){let t=new Set;for(let e of n){let i=`${e.kind}:${e.name}`;if(t.has(i))throw new Error(`[pi-agent-ide] ${e.kind} "${e.name}" is registered twice by one plugin.`);switch(t.add(i),e.kind){case"compiler":{b(e.kind,y,e.name);break}case"formatter":{b(e.kind,h,e.name);break}case"linter":{b(e.kind,P,e.name);break}}}for(let e of n)switch(e.kind){case"compiler":{y.push(e);break}case"formatter":{h.push(e);break}case"linter":{P.push(e);break}}}c(q,"registerTools");async function L(n,t){let e=[];for(let i of n)try{await i.detect(t)&&e.push(i)}catch(o){console.error(`[pi-agent-ide] detect failed for "${i.name}":`,o)}return e.sort((i,o)=>o.priority-i.priority),H(e),e}c(L,"filterActive");function H(n){let t=new Map;for(let e of n)for(let i of e.extensions){let o=`${i}@${e.priority}`,a=t.get(o);if(a!==void 0)throw new Error(`[pi-agent-ide] priority conflict: tools "${a}" and "${e.name}" both claim "${i}" at priority ${e.priority}.`);t.set(o,e.name)}}c(H,"assertNoPriorityConflicts");async function G(n){let[t,e]=await Promise.all([L(h,n),L(y.filter(i=>i.syntaxOnly===!0),n)]);return{ctx:n,formatters:t,compilers:e,linters:[]}}c(G,"warmupFormatting");function T(){h.length=0,y.length=0,P.length=0}c(T,"resetRegistry");import{readFile as D}from"node:fs/promises";import g from"node:path";var v=class{constructor(t,e={}){this.sources=t;this.options=e}static{c(this,"DiagnosticStore")}files=new Map;dirty=new Set;sent=new Map;queue=[];running=0;disposed=!1;changeListeners=new Set;onDidChange(t){return this.changeListeners.add(t),()=>this.changeListeners.delete(t)}schedule(t,e,{cwd:i}){this.disposed||this.ensure(t,e,i)}async read(t,{cwd:e,mode:i,signal:o}){o?.throwIfAborted(),this.assertActive();let a=g.resolve(e,t),s=await D(a,"utf8");this.assertActive();let r=this.ensure(a,s,e);i==="complete"?await this.waitComplete(r,o):i!=="snapshot"&&await K(Promise.all(r.jobs),this.options.readWaitMs??5e3),o?.throwIfAborted(),this.assertActive();let d=await D(a,"utf8");this.assertActive();let l=this.ensure(a,d,e);if(i==="complete"&&l!==r)throw Object.assign(new Error("File changed during diagnostics"),{code:"DIAGNOSTICS_STALE"});return{filePath:a,content:l.content,results:[...l.results.values()]}}async waitComplete(t,e){let i=e?AbortSignal.any([e,t.controller.signal]):t.controller.signal;i.throwIfAborted();let o=[];await new Promise((a,s)=>{let r=c(m=>s(Object.assign(new Error(m),{code:m,details:[...t.results.values()]})),"fail"),d=c(()=>{let m=[...t.results.values()];m.some(w=>w.status==="unavailable")?r("DIAGNOSTICS_UNAVAILABLE"):m.every(w=>w.status==="ready")&&a()},"check"),l=c(()=>s(i.reason),"abort"),f=this.onDidChange(d),u=setTimeout(()=>r("DIAGNOSTICS_TIMEOUT"),this.options.checkTimeoutMs??3e4);i.addEventListener("abort",l,{once:!0});let p=c(()=>{clearTimeout(u),f(),i.removeEventListener("abort",l)},"cleanup");Promise.resolve().then(d),o.push(p)}).finally(()=>{for(let a of o)a()})}async takeNotifications(t){let e=[];for(let i of[...this.dirty]){if(i.cwd!==g.resolve(t)||(this.dirty.delete(i),!await this.isCurrent(i)))continue;let o=[...i.results.values()].filter(d=>d.status!=="pending"&&d.status!=="unavailable"&&d.diagnostics.length>0),a=this.key(i.filePath,i.cwd),s=JSON.stringify(o);if(this.sent.get(a)===s||(this.sent.set(a,s),o.length===0))continue;let r=o.map(d=>{let l=["error","warning","info","hint"].flatMap(f=>{let u=d.diagnostics.filter(p=>p.severity===f).length;return u>0?[`${u} ${f}`]:[]});return`${d.source} ${l.join(", ")}${d.status==="snapshot"?" (snapshot; completion unknown)":d.status==="unversioned"?" (unversioned)":""}`}).join("; ");e.push({filePath:g.relative(t,i.filePath),results:o,text:`${JSON.stringify(g.relative(t,i.filePath))}: ${r}.`})}return e}dispose(){this.disposed=!0,this.changeListeners.clear();for(let t of this.files.values())t.controller.abort();this.files.clear(),this.dirty.clear(),this.sent.clear(),this.pump()}key(t,e){return JSON.stringify([g.resolve(e),g.resolve(e,t)])}ensure(t,e,i){let o=this.key(t,i),a=this.files.get(o);if(a?.content===e)return a;a?.controller.abort(),a&&this.dirty.delete(a);let s={cwd:g.resolve(i),filePath:g.resolve(i,t),content:e,controller:new AbortController,results:new Map,jobs:[],publications:new Map};this.files.set(o,s),this.sources.length===0&&s.results.set("diagnostics",{source:"diagnostics",status:"unavailable",diagnostics:[],reason:"No diagnostic sources registered"}),this.dirty.add(s);for(let r of this.sources){s.results.set(r.id,{source:r.id,status:"pending",diagnostics:[]});let d=new Promise(l=>{this.queue.push(async()=>{try{await this.check(s,r)}finally{l()}})});s.jobs.push(d)}return queueMicrotask(()=>this.pump()),s}pump(){for(;this.running<(this.options.concurrency??4)&&this.queue.length>0;){let t=this.queue.shift();if(!t)break;this.running++,t().finally(()=>{this.running--,this.pump()})}}active(t){return!this.disposed&&!t.controller.signal.aborted}assertActive(){if(this.disposed)throw new Error("Diagnostics session has ended")}async isCurrent(t){if(!this.active(t))return!1;let e=await D(t.filePath,"utf8").catch(()=>{});return this.active(t)&&e===t.content}async publish(t,e,i){let o=(t.publications.get(e)??0)+1;if(t.publications.set(e,o),!await this.isCurrent(t)||t.publications.get(e)!==o)return;let a={...i,source:i.source??e};if(JSON.stringify(t.results.get(e))===JSON.stringify(a))return;t.results.set(e,a),this.dirty.add(t);let s=[...t.results.values()].some(r=>r.status!=="pending"&&r.status!=="unavailable"&&r.diagnostics.length>0);s||this.sent.delete(this.key(t.filePath,t.cwd));for(let r of this.changeListeners)r(t.cwd,s)}async check(t,e){if(!await this.isCurrent(t))return;let i=new AbortController,o=AbortSignal.any([i.signal,t.controller.signal]);if(o.aborted)return;let a,s;try{let r=new Promise((l,f)=>{s=c(()=>f(o.reason),"onAbort"),o.addEventListener("abort",s,{once:!0}),a=setTimeout(()=>i.abort(new Error("Diagnostic check timed out")),this.options.checkTimeoutMs??3e4)}),d=await Promise.race([e.diagnose(t.filePath,{cwd:t.cwd,content:t.content,signal:o,publish:c(l=>{o.aborted||this.publish(t,e.id,l)},"publish")}),r]);await this.publish(t,e.id,d)}catch(r){await this.publish(t,e.id,{status:"unavailable",diagnostics:[],reason:r instanceof Error?r.message:String(r)})}finally{clearTimeout(a),s&&o.removeEventListener("abort",s)}}};async function K(n,t){let e;try{await Promise.race([n,new Promise(i=>{e=setTimeout(i,t)})])}finally{clearTimeout(e)}}c(K,"waitAtMost");function V(){let n=new Map,t=[],e=new v(t),i=Promise.resolve();return{diagnostics:e,registerPlugin(o){if(o.id.trim().length===0)return Promise.reject(new Error("Plugin ID must not be empty"));let a=n.get(o.id);if(a!==void 0)return a;let s=i.then(async()=>{let r=[],d=[],l=!0,f={addTool(u){if(!l)throw new Error(`Plugin ${o.id} setup is already complete`);Z(u),r.push(u)},addDiagnosticSource(u){if(!l)throw new Error(`Plugin ${o.id} setup is already complete`);tt(u),d.push(u)},readDiagnostics(u,p){return e.read(u,p)}};try{await o.setup(f)}catch(u){throw l=!1,u}l=!1,Q(t,d),q(r),t.push(...d)});return n.set(o.id,s),i=s.catch(()=>{}),s.catch(()=>{n.delete(o.id)}),s},async waitForPendingPlugins(){await Promise.all(n.values())}}}c(V,"createIdeCore");function Q(n,t){let e=new Set(n.map(i=>i.id));for(let i of t){if(e.has(i.id))throw new Error(`Diagnostic source ${i.id} is already registered`);e.add(i.id)}}c(Q,"assertUniqueDiagnosticSources");function Z(n){if(!U(n))throw new TypeError("IDE tool must be an object");let t=n.kind,e=t==="compiler"?n.compile:t==="formatter"?n.format:t==="linter"?n.lint:void 0;if(e===void 0||typeof e!="function"||typeof n.detect!="function"||typeof n.name!="string"||n.name.trim().length===0||typeof n.priority!="number"||!Number.isFinite(n.priority)||!Array.isArray(n.extensions)||n.extensions.length===0||n.extensions.some(i=>typeof i!="string"||i.length===0))throw new TypeError("Invalid pi-agent-ide tool contribution")}c(Z,"assertIdeTool");function tt(n){if(!U(n)||typeof n.id!="string"||n.id.trim().length===0||typeof n.diagnose!="function")throw new TypeError("Invalid pi-agent-ide diagnostic source contribution")}c(tt,"assertDiagnosticSource");function U(n){return typeof n=="object"&&n!==null}c(U,"isRecord");function J(n,t,e=console.error){let i=new Map,o=!1,a=Promise.resolve();return{schedule(s){if(o||i.has(s))return;let r=setTimeout(()=>{i.delete(s),a=a.then(async()=>{o||await n(s)}).catch(e)},t);i.set(s,r)},dispose(){o=!0;for(let s of i.values())clearTimeout(s);i.clear()}}}c(J,"createDiagnosticDelivery");import{Text as Y}from"@earendil-works/pi-tui";var S="ide-diagnostic-summary";function W(n){return{filePath:n.filePath,sources:n.results.map(t=>{let e={error:0,warning:0,info:0,hint:0};for(let i of t.diagnostics)e[i.severity]++;return{source:t.source,status:t.status,counts:e}})}}c(W,"diagnosticEntryData");function E(n,t,e=!1){return{render(i){let o=n.sources.filter(r=>r.status!=="pending"&&r.status!=="unavailable"&&Object.values(r.counts).some(d=>d>0));if(o.length===0)return[];let a=o.map(r=>`${x(r.counts,t)} ${t.fg("dim",`(${I(r.source)})`)}`+(r.status==="ready"?"":` \xB7 ${t.fg("dim",r.status)}`)).join(" \xB7 "),s=[`${t.fg("accent","Diagnostics")} ${t.fg("toolTitle",I(n.filePath))} \xB7 ${a}`];if(e)for(let r of o)s.push(` ${t.fg("dim",I(r.source))} \xB7 ${x(r.counts,t)} \xB7 ${t.fg("dim",r.status)}`);return new Y(s.join(`
2
+ `),0,0).render(i)},invalidate(){}}}c(E,"renderDiagnosticEntry");function B(n){n.registerEntryRenderer(S,(t,e,i)=>{let o=k(t.data);return"files"in o?et(o.files,i,e.expanded):E(o,i,e.expanded)})}c(B,"registerDiagnosticEntryRenderer");function et(n,t,e=!1){return{render(i){let o=n.filter(d=>d.sources.some(l=>l.status!=="pending"&&l.status!=="unavailable"&&Object.values(l.counts).some(f=>f>0)));if(o.length===1&&o[0])return E(o[0],t,e).render(i);if(o.length===0)return[];let a={error:0,warning:0,info:0,hint:0},s=new Set;for(let d of o)for(let l of d.sources)if(!(l.status==="pending"||l.status==="unavailable")){s.add(l.source);for(let f of["error","warning","info","hint"])a[f]+=l.counts[f]}let r=new Y(`${t.fg("accent","Diagnostics")} \xB7 ${o.length} files \xB7 ${x(a,t)} \xB7 ${s.size} tools`,0,0).render(i);return e?[...r,...o.flatMap(d=>E(d,t,!0).render(i))]:r},invalidate(){}}}c(et,"renderDiagnosticBatch");function x(n,t){return["error","warning","info","hint"].filter(e=>n[e]>0).map(e=>{let i=n[e],o=e==="info"||i===1?e:`${e}s`,a=i>0&&(e==="error"||e==="warning")?e:"muted";return t.fg(a,`${i} ${o}`)}).join(", ")}c(x,"renderCounts");function I(n){return n.replace(/[\u0000-\u001f\u007f-\u009f]/g," ")}c(I,"plain");import X from"node:path";async function z(n){if(!X.isAbsolute(n.resourceSource))return{formatting:{status:"unavailable"}};let t;try{let e=await G({cwd:n.cwd}),i=X.extname(n.resourceSource).toLowerCase(),o=c(d=>d.extensions.includes(i)||d.extensions.includes("*"),"matches"),a=e.compilers.find(o);if(a&&(await a.compile({filePath:n.resourceSource},e.ctx)).syntaxErrors.length>0)return{formatting:{status:"skipped-syntax"}};let s=e.formatters.find(o);if(!s)return{formatting:{status:"unavailable"}};t=s.name;let r=await s.format({filePath:n.resourceSource},e.ctx);return r.formatter===null?{formatting:{status:"unavailable"}}:(t=r.formatter??s.name,{formatting:{status:r.ok?r.edits>0?"changed":"unchanged":"failed",formatter:t},...r.ok?{diffStatuses:[{text:`Formatted (${t})`,tone:"success",formatter:t}]}:{diffStatuses:[{text:`Formatting failed (${t})`,tone:"error"}]}})}catch{return{diffStatuses:[{text:"Formatting failed",tone:"error"}],formatting:{status:"failed",...t===void 0?{}:{formatter:t}}}}}c(z,"runIdePostEditGate");import it from"node:path";async function nt(n){T();let t=V();B(n);let e=n.events.on($,s=>{if(!F(s))throw new Error("Invalid pi-agent-ide plugin registration request");s.accept(t.registerPlugin(s.plugin))});n.on("session_shutdown",()=>{e(),t.diagnostics.dispose(),T()}),M(n,{id:"pi-agent-ide",handler:c(s=>n.getFlag("pi-agent-ide-no-post-processing")===!0?Promise.resolve({formatting:{status:"disabled"}}):z(s),"handler")}),n.events.emit(A,{protocol:C,apiVersion:4}),await _(n,{protocol:N,apiVersion:O,id:"ide-diagnostics",setup(s){s.onDidEdit(r=>{n.getFlag("pi-agent-ide-no-post-processing")===!0||r.postProcessing==="deferred"||it.isAbsolute(r.resourceSource)&&j(()=>t.diagnostics.schedule(r.resourceSource,r.after.content,{cwd:r.cwd}))})}});let i=!1,o=J(async s=>{let r=await t.diagnostics.takeNotifications(s);i||r.length===0||(n.sendMessage({customType:"ide-diagnostics",display:!1,content:`File diagnostics:
3
+ ${r.map(d=>d.text).join(`
4
+ `)}`},{triggerTurn:!0,deliverAs:"steer"}),n.appendEntry(S,{files:r.map(W)}))},n.getFlag("pi-agent-ide-no-diagnostic-buffer")===!0?0:5e3),a=t.diagnostics.onDidChange((s,r)=>{r&&o.schedule(s)});n.on("session_shutdown",()=>{i=!0,o.dispose(),a()}),await t.waitForPendingPlugins()}c(nt,"registerPiAgentIde");export{nt as default};
@@ -1,2 +1,2 @@
1
- import{a as w,f as _}from"./chunk-YHUTTZC6.js";import{a as l}from"./chunk-EI7MMDWY.js";import{Container as D,Text as H,truncateToWidth as E,visibleWidth as W}from"@earendil-works/pi-tui";var v="pi-agent-text-editor/tool-call-interception",h=Symbol("pi-agent-tool-call-interception/annotation"),k=Symbol("pi-agent-tool-call-interception/render-argument-patch"),y=Symbol("pi-agent-tool-call-interception/anchor-render-patch");function x(n){if(!C(n))return;let e=n[v];return Y(e)?e:void 0}l(x,"getToolCallInterception");function M(n,e,o){let t={annotation:e,...o!==void 0&&{blocked:{reason:o}}};return C(n)?{...n,[v]:t}:{[v]:t,agentDetails:n??null}}l(M,"withToolCallInterceptionDetails");function Q(n,e){return{...n,details:M(n.details,{kind:"blocked",reason:e},e)}}l(Q,"withBlockedToolResult");function j(n,e){if(n===void 0)return!1;let o=n,t=e,r=Reflect.ownKeys(e);return r.length===Reflect.ownKeys(n).length&&r.every(d=>o[d]===t[d])}l(j,"sameArgumentPatch");function U(n,e){let o={...n,...e},t=b(n),r=b(e);return(t!==void 0||r!==void 0)&&(o[y]={...t,...r}),o}l(U,"mergeArgumentPatches");function O(n){if(n===void 0||!(y in n))return n;let e={...n};return delete e[y],e}l(O,"argumentPatchWithoutAnchorRendering");function b(n){if(n!==void 0)return n[y]}l(b,"anchorRenderPatchFromArguments");var L=class{static{l(this,"ToolCallInterceptionRenderStore")}entries=new Map;annotate=l((e,o)=>{let t=this.entries.get(e);this.entries.set(e,{annotation:o,renderArgumentPatch:t?.renderArgumentPatch,invalidate:t?.invalidate}),t?.invalidate?.()},"annotate");bind(e,o){let t=this.entries.get(e);return this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:t?.renderArgumentPatch,invalidate:o}),t?.annotation}get(e){return this.entries.get(e)?.annotation}resolveArguments=l((e,o)=>{let t=this.entries.get(e),r=U(t?.renderArgumentPatch,o);j(t?.renderArgumentPatch,r)||(this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:r,invalidate:t?.invalidate}),t?.invalidate?.())},"resolveArguments");getRenderArgumentPatch(e){return this.entries.get(e)?.renderArgumentPatch}complete(e){this.entries.delete(e)}clear(){this.entries.clear()}},P=class{constructor(e,o,t,r,d,s){this.component=e;this.theme=o;this.state=t;this.annotations=r;this.toolCallId=d;this.backgroundAnsi=s}static{l(this,"AnnotatedToolCall")}get inner(){return this.component}update(e,o,t,r){this.component=e,this.theme=o,this.state=t,this.backgroundAnsi=r}render(e){let o=this.component.render(e),t=this.annotations.get(this.toolCallId)??this.state[h],r;if(t===void 0)r=o;else{let d=F(t,this.theme);if(o.length===0)r=[E(d,e)];else{let s=` \u2190 ${d}`,a=W(s);r=a>=e?[E(s.trimStart(),e,""),...o.slice(1)]:[`${E(o[0]??"",e-a,"")}${s}`,...o.slice(1)]}}return B(r,this.backgroundAnsi)}invalidate(){this.component.invalidate()}},I=class{constructor(e,o){this.component=e;this.backgroundAnsi=o}static{l(this,"EnclosingBackgroundComponent")}get inner(){return this.component}update(e,o){this.component=e,this.backgroundAnsi=o}render(e){return B(this.component.render(e),this.backgroundAnsi)}invalidate(){this.component.invalidate()}};function B(n,e){return e===void 0?[...n]:n.map(o=>_(o,e))}l(B,"preserveBackgroundLines");function V(n,e){let o=n.renderCall,t=n.renderResult,r=n.renderShell!=="self";return{...n,get promptGuidelines(){return n.promptGuidelines},renderCall(d,s,a){let i=a.state,c=e.bind(a.toolCallId,a.invalidate),u=e.getRenderArgumentPatch(a.toolCallId)??i[k],T=b(u),R=O(u);u!==void 0&&(i[k]=u),T!==void 0&&(i[y]=T);let p=R===void 0?d:{...R,...d};c!==void 0&&(i[h]=c);let g=a.lastComponent instanceof P?a.lastComponent:void 0,f;try{f=o?.(p,s,{...a,args:p,lastComponent:g?.inner})??K(n.name,s)}catch{f=K(n.name,s)}let A=r?w(s,a):void 0;return g!==void 0?(g.update(f,s,i,A),g):new P(f,s,i,e,a.toolCallId,A)},renderResult(d,s,a,i){let c=i.state,u=e.getRenderArgumentPatch(i.toolCallId)??c[k],T=b(u),R=O(u);u!==void 0&&(c[k]=u),T!==void 0&&(c[y]=T);let p=i.lastComponent instanceof I?i.lastComponent:void 0,g={...i,...R!==void 0&&{args:{...R,...i.args}},lastComponent:p?.inner??i.lastComponent},f=x(d.details)?.annotation,A=e.get(i.toolCallId)??c[h],N=f??(s.isPartial||i.isError?A:void 0);if(N!==void 0){if(c[h]=N,e.complete(i.toolCallId),t!==void 0){let G={...d,content:[],details:void 0};try{t(G,s,a,g)}catch{return new D}}return new D}e.complete(i.toolCallId),Reflect.deleteProperty(c,h);let m;if(t!==void 0)try{m=t(d,s,a,g)}catch{m=$(d,a,i.isError)}else m=$(d,a,i.isError);if(!r)return m;let S=w(a,i);return p!==void 0?(p.update(m,S),p):new I(m,S)}}}l(V,"withToolCallInterceptionRendering");function K(n,e){return new H(e.fg("toolTitle",e.bold(n)),0,0)}l(K,"fallbackCall");function $(n,e,o){let t=n.content.filter(r=>r.type==="text").map(r=>r.text).join(`
1
+ import{a as w,f as _}from"./chunk-YHUTTZC6.js";import{a as l}from"./chunk-EI7MMDWY.js";import{Container as D,Text as H,truncateToWidth as E,visibleWidth as W}from"@earendil-works/pi-tui";var v="pi-agent-text-editor/tool-call-interception",h=Symbol("pi-agent-tool-call-interception/annotation"),k=Symbol("pi-agent-tool-call-interception/render-argument-patch"),y=Symbol("pi-agent-tool-call-interception/anchor-render-patch");function x(n){if(!C(n))return;let e=n[v];return Y(e)?e:void 0}l(x,"getToolCallInterception");function M(n,e,o){let t={annotation:e,...o!==void 0&&{blocked:{reason:o}}};return C(n)?{...n,[v]:t}:{[v]:t,agentDetails:n??null}}l(M,"withToolCallInterceptionDetails");function Q(n,e){return{...n,details:M(n.details,{kind:"blocked",reason:e},e)}}l(Q,"withBlockedToolResult");function j(n,e){if(n===void 0)return!1;let o=n,t=e,r=Reflect.ownKeys(e);return r.length===Reflect.ownKeys(n).length&&r.every(d=>o[d]===t[d])}l(j,"sameArgumentPatch");function U(n,e){let o={...n,...e},t=b(n),r=b(e);return(t!==void 0||r!==void 0)&&(o[y]={...t,...r}),o}l(U,"mergeArgumentPatches");function O(n){if(n===void 0||!(y in n))return n;let e={...n};return delete e[y],e}l(O,"argumentPatchWithoutAnchorRendering");function b(n){if(n!==void 0)return n[y]}l(b,"anchorRenderPatchFromArguments");var L=class{static{l(this,"ToolCallInterceptionRenderStore")}entries=new Map;annotate=l((e,o)=>{let t=this.entries.get(e);this.entries.set(e,{annotation:o,renderArgumentPatch:t?.renderArgumentPatch,invalidate:t?.invalidate}),t?.invalidate?.()},"annotate");bind(e,o){let t=this.entries.get(e);return this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:t?.renderArgumentPatch,invalidate:o}),t?.annotation}get(e){return this.entries.get(e)?.annotation}resolveArguments=l((e,o)=>{let t=this.entries.get(e),r=U(t?.renderArgumentPatch,o);j(t?.renderArgumentPatch,r)||(this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:r,invalidate:t?.invalidate}),t?.invalidate?.())},"resolveArguments");getRenderArgumentPatch(e){return this.entries.get(e)?.renderArgumentPatch}complete(e){this.entries.delete(e)}clear(){this.entries.clear()}},P=class{constructor(e,o,t,r,d,s){this.component=e;this.theme=o;this.state=t;this.annotations=r;this.toolCallId=d;this.backgroundAnsi=s}static{l(this,"AnnotatedToolCall")}get inner(){return this.component}update(e,o,t,r){this.component=e,this.theme=o,this.state=t,this.backgroundAnsi=r}render(e){let o=this.component.render(e),t=this.annotations.get(this.toolCallId)??this.state[h],r;if(t===void 0)r=o;else{let d=F(t,this.theme);if(o.length===0)r=[E(d,e)];else{let s=` \u2190 ${d}`,a=W(s);r=a>=e?[E(s.trimStart(),e,""),...o.slice(1)]:[`${E(o[0]??"",e-a,"")}${s}`,...o.slice(1)]}}return B(r,this.backgroundAnsi)}invalidate(){this.component.invalidate()}},I=class{constructor(e,o){this.component=e;this.backgroundAnsi=o}static{l(this,"EnclosingBackgroundComponent")}get inner(){return this.component}update(e,o){this.component=e,this.backgroundAnsi=o}render(e){return B(this.component.render(e),this.backgroundAnsi)}invalidate(){this.component.invalidate()}};function B(n,e){return e===void 0?[...n]:n.map(o=>_(o,e))}l(B,"preserveBackgroundLines");function V(n,e){let o=n.renderCall,t=n.renderResult,r=n.renderShell!=="self";return{...n,get description(){return n.description},get promptGuidelines(){return n.promptGuidelines},renderCall(d,s,a){let i=a.state,c=e.bind(a.toolCallId,a.invalidate),u=e.getRenderArgumentPatch(a.toolCallId)??i[k],T=b(u),R=O(u);u!==void 0&&(i[k]=u),T!==void 0&&(i[y]=T);let p=R===void 0?d:{...R,...d};c!==void 0&&(i[h]=c);let g=a.lastComponent instanceof P?a.lastComponent:void 0,f;try{f=o?.(p,s,{...a,args:p,lastComponent:g?.inner})??K(n.name,s)}catch{f=K(n.name,s)}let A=r?w(s,a):void 0;return g!==void 0?(g.update(f,s,i,A),g):new P(f,s,i,e,a.toolCallId,A)},renderResult(d,s,a,i){let c=i.state,u=e.getRenderArgumentPatch(i.toolCallId)??c[k],T=b(u),R=O(u);u!==void 0&&(c[k]=u),T!==void 0&&(c[y]=T);let p=i.lastComponent instanceof I?i.lastComponent:void 0,g={...i,...R!==void 0&&{args:{...R,...i.args}},lastComponent:p?.inner??i.lastComponent},f=x(d.details)?.annotation,A=e.get(i.toolCallId)??c[h],N=f??(s.isPartial||i.isError?A:void 0);if(N!==void 0){if(c[h]=N,e.complete(i.toolCallId),t!==void 0){let G={...d,content:[],details:void 0};try{t(G,s,a,g)}catch{return new D}}return new D}e.complete(i.toolCallId),Reflect.deleteProperty(c,h);let m;if(t!==void 0)try{m=t(d,s,a,g)}catch{m=$(d,a,i.isError)}else m=$(d,a,i.isError);if(!r)return m;let S=w(a,i);return p!==void 0?(p.update(m,S),p):new I(m,S)}}}l(V,"withToolCallInterceptionRendering");function K(n,e){return new H(e.fg("toolTitle",e.bold(n)),0,0)}l(K,"fallbackCall");function $(n,e,o){let t=n.content.filter(r=>r.type==="text").map(r=>r.text).join(`
2
2
  `);return t.length===0?new D:new H(e.fg(o?"error":"toolOutput",t),0,0)}l($,"fallbackResult");function F(n,e){let o=n.kind==="stale-anchor",t=o?"\u26A0":"\u2298",r=n.label??(o?"Stale Anchor":"Blocked"),d=n.color??(o?"warning":"error"),s=n.reason===void 0?"":`: ${n.reason}`;return e.fg(d,`${t} ${r}${s}`)}l(F,"renderAnnotation");function Y(n){return!C(n)||!q(n.annotation)?!1:n.blocked===void 0||C(n.blocked)&&typeof n.blocked.reason=="string"}l(Y,"isToolCallInterceptionDetails");function q(n){return!C(n)||typeof n.kind!="string"||n.label!==void 0&&typeof n.label!="string"||n.reason!==void 0&&typeof n.reason!="string"||n.color!==void 0&&typeof n.color!="string"?!1:n.kind==="blocked"?typeof n.reason=="string":n.kind==="custom"?typeof n.label=="string"&&typeof n.color=="string":n.kind==="stale-anchor"||n.kind==="aborted"}l(q,"isToolCallAnnotation");function C(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}l(C,"isRecord");export{v as a,y as b,x as c,M as d,Q as e,L as f,V as g,q as h};
@@ -1 +1 @@
1
- import{a as c}from"./chunk-2SKAED2I.js";import{a as l}from"./chunk-ZC65Z3CK.js";import{a as r}from"./chunk-EI7MMDWY.js";var u=Symbol.for("pi-agent-text-editor/TextSelectionAnchor"),d=class extends c{constructor(t,o,i){let s=i.map(a=>({start:{...a.start},end:{...a.end},...a.linewise===!0&&{linewise:!0}}));g(s);super(t,l(s[0]).start.lineNumber);this.source=o;if(o.length===0)throw new TypeError("Text selection anchor source must be non-empty");this.ranges=s}static{r(this,"TextSelectionAnchor")}[u]=!0;ranges;static is(t){if(!c.is(t))return!1;try{let o=t,i=o.ranges;return o[u]===!0&&typeof o.source=="string"&&o.source.length>0&&Array.isArray(i)&&i.length>0&&i.every(x)}catch{return!1}}};function g(n){if(n.length===0)throw new TypeError("Text selection anchor must contain at least one range");let e;for(let t of n){if(!x(t)||p(t.start,t.end)>0)throw new RangeError("Text selection anchor contains an invalid range");if(e!==void 0&&p(t.start,e.end)<0)throw new Error("Text selection anchor ranges must be ordered and must not overlap");e=t}}r(g,"assertSelectionRanges");function x(n){if(typeof n!="object"||n===null)return!1;let e=n;return f(e.start)&&f(e.end)&&(e.linewise===void 0||typeof e.linewise=="boolean")}r(x,"isTextSelectionRange");function f(n){if(typeof n!="object"||n===null)return!1;let e=n;return Number.isSafeInteger(e.lineNumber)&&(e.lineNumber??0)>=1&&Number.isSafeInteger(e.column)&&(e.column??-1)>=0}r(f,"isTextSelectionPosition");function p(n,e){return n.lineNumber-e.lineNumber||n.column-e.column}r(p,"comparePositions");export{d as a};
1
+ import{a as c}from"./chunk-5VSE5X5R.js";import{a as l}from"./chunk-ZC65Z3CK.js";import{a as r}from"./chunk-EI7MMDWY.js";var u=Symbol.for("pi-agent-text-editor/TextSelectionAnchor"),d=class extends c{constructor(t,o,i){let s=i.map(a=>({start:{...a.start},end:{...a.end},...a.linewise===!0&&{linewise:!0}}));g(s);super(t,l(s[0]).start.lineNumber);this.source=o;if(o.length===0)throw new TypeError("Text selection anchor source must be non-empty");this.ranges=s}static{r(this,"TextSelectionAnchor")}[u]=!0;ranges;static is(t){if(!c.is(t))return!1;try{let o=t,i=o.ranges;return o[u]===!0&&typeof o.source=="string"&&o.source.length>0&&Array.isArray(i)&&i.length>0&&i.every(x)}catch{return!1}}};function g(n){if(n.length===0)throw new TypeError("Text selection anchor must contain at least one range");let e;for(let t of n){if(!x(t)||p(t.start,t.end)>0)throw new RangeError("Text selection anchor contains an invalid range");if(e!==void 0&&p(t.start,e.end)<0)throw new Error("Text selection anchor ranges must be ordered and must not overlap");e=t}}r(g,"assertSelectionRanges");function x(n){if(typeof n!="object"||n===null)return!1;let e=n;return f(e.start)&&f(e.end)&&(e.linewise===void 0||typeof e.linewise=="boolean")}r(x,"isTextSelectionRange");function f(n){if(typeof n!="object"||n===null)return!1;let e=n;return Number.isSafeInteger(e.lineNumber)&&(e.lineNumber??0)>=1&&Number.isSafeInteger(e.column)&&(e.column??-1)>=0}r(f,"isTextSelectionPosition");function p(n,e){return n.lineNumber-e.lineNumber||n.column-e.column}r(p,"comparePositions");export{d as a};
@@ -0,0 +1 @@
1
+ import{Type as e}from"typebox";var o=e.Object({query:e.String({minLength:1,description:"Text to find, a Boolean expression, or a prefixed query described below, such as files:*.ts. Quote text to keep it literal, or use regex:<pattern> for regular-expression matching."}),path:e.Optional(e.String({description:"Optional file or directory scope for local search"})),include:e.Optional(e.String({description:"Optional include glob for local search"})),exclude:e.Optional(e.String({description:"Optional exclude glob for local search"})),caseSensitive:e.Optional(e.Boolean({description:"Match letter case in local search"})),wholeWord:e.Optional(e.Boolean({description:"Match complete words in local search"})),limit:e.Optional(e.Integer({minimum:1,maximum:1e3,description:"Maximum results (default 100)"}))},{additionalProperties:!1});export{o as a};
@@ -1 +1 @@
1
- import{c as u,d as a,e as c}from"./chunk-KZBAJFCV.js";import{a as t}from"./chunk-EI7MMDWY.js";function f(o,r){let s=t(()=>{let e,i={plugin:r,accept(g){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=g}};return o.events.emit(a,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(u,e=>{if(!c(e))throw new Error("Invalid pi-agent-ide core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-ide core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(f,"connectIdePlugin");export{f as a};
1
+ import{c as u,d as a,e as c}from"./chunk-Z3VC3S2T.js";import{a as t}from"./chunk-EI7MMDWY.js";function f(o,r){let s=t(()=>{let e,i={plugin:r,accept(g){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=g}};return o.events.emit(a,i),e},"announce"),n=t(()=>{},"unsubscribe");n=o.events.on(u,e=>{if(!c(e))throw new Error("Invalid pi-agent-ide core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-ide core announced readiness without accepting the plugin");n(),i.catch(()=>{})}),o.on("session_shutdown",n);let d=s();if(d!==void 0)return n(),d}t(f,"connectIdePlugin");export{f as a};
@@ -0,0 +1,7 @@
1
+ import{a as d}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import{createTwoFilesPatch as m,diffLines as g}from"diff";function y(i,e,n,r=i){return{diff:m(i,r,e,n,"","",{context:3}).replace(/^(?:Index: .*\n)?={3,}\n?/m,"").trimEnd(),stats:p(e,n)}}s(y,"createUnifiedDiff");function p(i,e){let n=0,r=0;for(let t of g(i,e)){let a=l(t.value);t.removed&&(n+=a),t.added&&(r+=a)}return{removed:n,added:r}}s(p,"computeStats");function l(i){if(i.length===0)return 0;let e=i.replaceAll(`\r
2
+ `,`
3
+ `);return e.endsWith(`
4
+ `)?e.slice(0,-1).split(`
5
+ `).length:e.split(`
6
+ `).length}s(l,"countDiffLines");function x(i,e){let n=g(i,e),r=[],t=0;for(let a of n){let o=l(a.value);o!==0&&(a.removed||(a.added&&r.push({start:t+1,end:t+o}),t+=o))}return E(r)}s(x,"computeChangedRanges");function E(i){if(i.length===0)return[];let e=[...i].sort((r,t)=>r.start-t.start),n=[d(e[0])];for(let r=1;r<e.length;r++){let t=d(n.at(-1)),a=d(e[r]);a.start<=t.end+1?t.end=Math.max(t.end,a.end):n.push(a)}return n}s(E,"mergeAdjacentRanges");var f=class i{static{s(this,"FileRange")}start;end;constructor(e,n=e){n.lineNumber<e.lineNumber&&([e,n]=[n,e]),this.start=e,this.end=n}static fromLines(e,n){let r=n??e;return new i({lineNumber:e},{lineNumber:r})}},c=class i{static{s(this,"FileMutationResult")}data;constructor(e){this.data=e??{}}get ok(){return this.data.ok??!1}get isPartial(){return this.data.isPartial??!1}get diffs(){return this.data.diffs??[]}get files(){return this.data.files??[]}get warnings(){return this.data.warnings??[]}get errors(){return this.data.errors??[]}get lintViolations(){return this.data.lintViolations??[]}get hints(){return this.data.hints??[]}get syntaxErrorSummary(){return this.data.syntaxErrorSummary}get path(){return this.data.path}get editRange(){let e=this.data.activeEdits,n=e?.[0];if(n?.range){let r=n.range.start,a=d(e).at(-1)?.range?.end??r;return new f(r,a)}return this.data.editRange}get resolvedStartLine(){return this.editRange?.start.lineNumber}get resolvedEndLine(){return this.editRange?.end.lineNumber}get freshAnchors(){return this.data.freshAnchors}get failurePoint(){return this.data.failurePoint}get recovery(){return this.data.recovery}get expectedAnchor(){return this.data.expectedAnchor}get currentAnchor(){return this.data.currentAnchor}get internalErrorType(){return this.data.internalErrorType}get internalErrorMessage(){return this.data.internalErrorMessage}get editCount(){return this.data.editCount}get editRanges(){return this.data.editRanges}get addedLines(){return this.data.addedLines}get removedLines(){return this.data.removedLines}get appliedPaths(){return this.data.appliedPaths}get beforeContentMap(){return this.data.beforeContentMap}get afterContent(){return this.data.afterContent}get skipCount(){return this.data.skipCount??0}get staleEdits(){return this.data.staleEdits??[]}get proposedDiff(){return this.data.proposedDiff}get editIndex(){return this.data.editIndex}get editIndices(){return this.data.editIndices}get staleDiagnostic(){return this.data.staleDiagnostic}get fileChangedStatement(){return this.data.fileChangedStatement}get affectedPaths(){let e=new Set;for(let n of this.files)e.add(n.path);for(let n of this.errors)n.path&&e.add(n.path);for(let n of this.warnings)n.file&&e.add(n.file);return[...e]}get didChange(){return this.ok&&(this.files.length>0||this.diffs.length>0)}get createdFiles(){return this.files.filter(e=>e.action==="created")}get overwrittenFiles(){return this.files.filter(e=>e.action==="overwritten"||e.action==="edited")}get staleCount(){return this.staleEdits.length}get summary(){if(!this.ok){let t=this.errors[0];return t?`Failed: ${t.code??"ERROR"}${t.reason?` \u2014 ${t.reason}`:""}`:"Mutation failed"}if(this.files.length===0&&this.diffs.length===0){let t=this.appliedPaths;return t&&t.length>0?`${t.length} path${t.length===1?"":"s"} affected`:"No changes"}let e=this.createdFiles.length,n=this.overwrittenFiles.length,r=[];if(e>0&&r.push(`Created ${e} ${e===1?"file":"files"}`),n>0&&r.push(`Edited ${n} ${n===1?"file":"files"}`),this.diffs.length>0){let t=0,a=0;for(let o of this.diffs)for(let u of o.split(`
7
+ `))u.startsWith("+")&&!u.startsWith("+++")?t++:u.startsWith("-")&&!u.startsWith("---")&&a++;(t>0||a>0)&&r.push(`+${t}/-${a} lines`)}return r.join(", ")}getFileChange(e){return this.files.find(n=>n.path===e)}getDiffFor(e){let n=h(e);for(let r of this.diffs){let t=r.match(/^---\s+(.+)$/m);if(t&&(h(d(t[1]))===n||t[1]===e))return r}}getErrorsFor(e){return this.errors.filter(n=>n.path===e)}getWarningsFor(e){return this.warnings.filter(n=>n.file===e)}static fromFailureOptions(e){return new i({ok:!1,path:e.path,errors:[{path:e.path,code:e.code,reason:e.reason}],failurePoint:e.failurePoint,recovery:e.recovery,expectedAnchor:e.expectedAnchor,currentAnchor:e.currentAnchor,freshAnchors:e.freshLines?[...e.freshLines]:void 0,internalErrorType:e.internalError instanceof Error?e.internalError.name:void 0,internalErrorMessage:e.internalError instanceof Error?e.internalError.message:void 0})}static ensure(e){if(e instanceof i)return e;if(e&&typeof e=="object"){let n=e;return n.data&&typeof n.data=="object"?(Object.setPrototypeOf(n,i.prototype),n):new i(n)}return new i}};function h(i){return i.replace(/\\/g,"/").replace(/^a\//,"").replace(/^b\//,"")}s(h,"normalisePath");export{y as a,x as b,f as c,c as d};
@@ -0,0 +1 @@
1
+ import{a as i}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as n}from"typebox/value";var t="pi-agent-read",r=11,c=`${t}/core/ready`,s=`${t}/plugin/register`,a=e.Function([],e.Unknown()),p=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(r)}),R=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(r),id:e.String(),setup:a}),l=e.Object({plugin:R,accept:a});function g(o){return n.Check(p,o)}i(g,"isReadCoreReady");function P(o){return n.Check(R,o)}i(P,"isReadPlugin");function y(o){return n.Check(l,o)}i(y,"isReadPluginRegistrationRequest");export{t as a,r as b,c,s as d,g as e,P as f,y as g};
@@ -1 +1 @@
1
- import{d as c}from"./chunk-EW2KVKCN.js";import{e as a}from"./chunk-2SKAED2I.js";import{a as r}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as i}from"typebox/value";var n="pi-agent-text-editor",p=17,P="pi-agent-text-editor/position",I="pi-agent-text-editor/search",b=`${n}/core/ready`,S=`${n}/plugin/register`,s=e.Function([],e.Unknown()),d=e.Object({tryResolve:s},{additionalProperties:!0}),l=e.Object({lineNumber:e.Integer({minimum:1}),column:e.Integer({minimum:0})}),T=e.Object({start:l,end:l,linewise:e.Optional(e.Boolean())}),R=e.Object({source:e.String({minLength:1}),ranges:e.Optional(e.Array(T))}),x=e.Union([e.Object({kind:e.Literal("not-handled")},{additionalProperties:!0}),e.Object({kind:e.Literal("resolved"),targets:e.Array(R,{minItems:1})},{additionalProperties:!0}),e.Object({kind:e.Literal("rejected"),rejection:e.Object({code:e.Union([e.Literal("invalid"),e.Literal("stale"),e.Literal("missing"),e.Literal("ambiguous")]),reason:e.String(),contextRange:e.Optional(e.Object({offset:e.Number(),limit:e.Number()}))})},{additionalProperties:!0}),e.Object({kind:e.Literal("failed"),error:e.Unknown()},{additionalProperties:!0})]),g=e.String({pattern:"\\S"}),m=e.Object({resolver:e.Unknown(),priority:e.Optional(e.Number())}),y=e.Object({resolver:e.Unknown(),resources:e.Optional(e.Unknown()),kind:e.String({pattern:"\\S"}),type:e.Union([e.Literal("major"),e.Literal("auxiliary"),e.Literal("constant")]),priority:e.Optional(e.Number())}),v=e.Object({protocol:e.Literal(n),apiVersion:e.Literal(p)}),u=e.Object({protocol:e.Literal(n),apiVersion:e.Literal(p),id:e.String(),setup:s}),E=e.Object({plugin:u,accept:s});function k(t){return i.Check(g,t)}r(k,"isTextEditorToolId");function _(t){if(!i.Check(m,t))return!1;let o=t;return c(o.resolver)&&(!("priority"in o)||typeof o.priority=="number")}r(_,"isResourceResolverRegistration");function j(t){if(!i.Check(y,t))return!1;let o=t;return a(o.resolver)&&(!("resources"in o)||i.Check(d,o.resources))&&(!("priority"in o)||typeof o.priority=="number")}r(j,"isTextAnchorResolverRegistration");function C(t){return i.Check(x,t)}r(C,"isTextAnchorResourceResolutionAttempt");function L(t){return i.Check(v,t)}r(L,"isTextEditorCoreReady");function w(t){return i.Check(u,t)}r(w,"isTextEditorPlugin");function N(t){return i.Check(E,t)}r(N,"isTextEditorPluginRegistrationRequest");export{n as a,p as b,P as c,I as d,b as e,S as f,k as g,_ as h,j as i,C as j,L as k,w as l,N as m};
1
+ import{d as c}from"./chunk-S3ZPXWX7.js";import{e as a}from"./chunk-5VSE5X5R.js";import{a as r}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as i}from"typebox/value";var n="pi-agent-text-editor",p=20,P="pi-agent-text-editor/position",I="pi-agent-text-editor/search",S=`${n}/core/ready`,b=`${n}/plugin/register`,s=e.Function([],e.Unknown()),d=e.Object({tryResolve:s},{additionalProperties:!0}),l=e.Object({lineNumber:e.Integer({minimum:1}),column:e.Integer({minimum:0})}),T=e.Object({start:l,end:l,linewise:e.Optional(e.Boolean())}),x=e.Object({source:e.String({minLength:1}),ranges:e.Optional(e.Array(T))}),R=e.Union([e.Object({kind:e.Literal("not-handled")},{additionalProperties:!0}),e.Object({kind:e.Literal("resolved"),targets:e.Array(x,{minItems:1})},{additionalProperties:!0}),e.Object({kind:e.Literal("rejected"),rejection:e.Object({code:e.Union([e.Literal("invalid"),e.Literal("stale"),e.Literal("missing"),e.Literal("ambiguous")]),reason:e.String(),contextRange:e.Optional(e.Object({offset:e.Number(),limit:e.Number()}))})},{additionalProperties:!0}),e.Object({kind:e.Literal("failed"),error:e.Unknown()},{additionalProperties:!0})]),g=e.String({pattern:"\\S"}),m=e.Object({resolver:e.Unknown(),priority:e.Optional(e.Number())}),y=e.Object({resolver:e.Unknown(),resources:e.Optional(e.Unknown()),kind:e.String({pattern:"\\S"}),type:e.Union([e.Literal("major"),e.Literal("auxiliary"),e.Literal("constant")]),priority:e.Optional(e.Number())}),v=e.Object({protocol:e.Literal(n),apiVersion:e.Literal(p)}),u=e.Object({protocol:e.Literal(n),apiVersion:e.Literal(p),id:e.String(),setup:s}),E=e.Object({plugin:u,accept:s});function k(t){return i.Check(g,t)}r(k,"isTextEditorToolId");function _(t){if(!i.Check(m,t))return!1;let o=t;return c(o.resolver)&&(!("priority"in o)||typeof o.priority=="number")}r(_,"isResourceResolverRegistration");function C(t){if(!i.Check(y,t))return!1;let o=t;return a(o.resolver)&&(!("resources"in o)||i.Check(d,o.resources))&&(!("priority"in o)||typeof o.priority=="number")}r(C,"isTextAnchorResolverRegistration");function j(t){return i.Check(R,t)}r(j,"isTextAnchorResourceResolutionAttempt");function w(t){return i.Check(v,t)}r(w,"isTextEditorCoreReady");function L(t){return i.Check(u,t)}r(L,"isTextEditorPlugin");function N(t){return i.Check(E,t)}r(N,"isTextEditorPluginRegistrationRequest");export{n as a,p as b,P as c,I as d,S as e,b as f,k as g,_ as h,C as i,j,w as k,L as l,N as m};
@@ -0,0 +1,7 @@
1
+ import"./chunk-3YK4XMWB.js";import{a as J,b as V,c as U,d as q,f as z}from"./chunk-VFBLX4TG.js";import{d as L,e as h}from"./chunk-M5MJP7Z2.js";import{a as E}from"./chunk-WZI4YC2O.js";import{d as N}from"./chunk-N34ATN52.js";import{a as O}from"./chunk-ZC65Z3CK.js";import{a as _,b as F,c as M}from"./chunk-JMVDFOTQ.js";import{a as c}from"./chunk-EI7MMDWY.js";import{mkdir as ie,readFile as B,writeFile as re}from"node:fs/promises";async function G(n,t){await ie(L(n),{recursive:!0});let e=[],o=t.filter(r=>r.recipe.formatter!==void 0),i=t.filter(r=>r.recipe.linter!==void 0),s=t.filter(r=>r.recipe.lsp!==void 0);if(o.length>0){let r=h(n,"formatters"),a=await S(r,{version:1,formatters:{}}),u=P(a,"formatters");for(let l of o)u[l.recipe.id]??=l.recipe.formatter;await R(r,a)&&e.push(r)}if(i.length>0){let r=h(n,"linters"),a=await S(r,{version:1,linters:{}}),u=P(a,"linters");for(let l of i)u[l.recipe.id]??=l.recipe.linter;await R(r,a)&&e.push(r)}if(s.length>0){let r=h(n,"lsp-servers"),a=await S(r,{version:1,servers:{}}),u=P(a,"servers");for(let l of s){let d=O(l.recipe.lsp);u[l.recipe.id]??={command:d.command,transport:"stdio",rootMarkers:d.rootMarkers,...d.initializationOptions!==void 0&&{initializationOptions:d.initializationOptions},...d.settings!==void 0&&{settings:d.settings},...d.requireRootMarker!==void 0&&{requireRootMarker:d.requireRootMarker},languages:Object.fromEntries(Object.entries(d.languageIds).map(([p,f])=>[p,{extensions:f,...d.fileNames?.[p]&&{fileNames:d.fileNames[p]}}])),capabilities:["diagnostics"]}}await R(r,a)&&e.push(r)}return e}c(G,"writeSuggestedConfigs");async function S(n,t){try{let e=JSON.parse(await B(n,"utf8"));if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(`${n} must contain an object`);return e}catch(e){if(typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT")return t;throw e}}c(S,"readObject");function P(n,t){let e=n[t];if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(`${t} must be an object`);return e}c(P,"objectMember");async function R(n,t){let e=`${JSON.stringify(t,null,2)}
2
+ `;return await B(n,"utf8").catch(()=>{})===e?!1:(await re(n,e,"utf8"),!0)}c(R,"writeJson");var C=class{static{c(this,"DoctorCore")}plugins=new Map;languages=[];recipes=[];setupChecks=[];checks=[];queue=Promise.resolve();registerPlugin(t){let e=this.plugins.get(t.id);if(e!==void 0)return e;let o=this.queue.then(async()=>{let i=!0,s=[],r=[],a=[],u=[],l={addLanguage:c(d=>{b(d,s,t.id,"language",()=>i)},"addLanguage"),addToolRecipe:c(d=>{b(d,r,t.id,"tool recipe",()=>i)},"addToolRecipe"),addSetupCheck:c(d=>{b(d,a,t.id,"setup check",()=>i)},"addSetupCheck"),addCheck:c(d=>{b(d,u,t.id,"check",()=>i)},"addCheck")};try{await t.setup(l)}finally{i=!1}W(this.languages,s,"language"),W(this.recipes,r,"tool recipe"),this.languages.push(...s),this.recipes.push(...r),this.setupChecks.push(...a),this.checks.push(...u)});return this.plugins.set(t.id,o),this.queue=o.catch(()=>{}),o.catch(()=>{this.plugins.delete(t.id)}),o}async waitForPlugins(){await Promise.all(this.plugins.values())}snapshot(){return{languages:[...this.languages],recipes:[...this.recipes],setupChecks:[...this.setupChecks],checks:[...this.checks]}}};async function H(n,t){let e=[],o=[];for(let i of n.setupChecks)try{let s=await i.value.inspect(t);e.push(...(s.selections??[]).map(r=>({...r,pluginId:i.pluginId}))),o.push(...(s.actions??[]).map(r=>({...r,pluginId:i.pluginId})))}catch{}return{selections:e,actions:o}}c(H,"runContributedSetupChecks");async function X(n,t){let e=[];for(let o of n.checks)try{e.push({pluginId:o.pluginId,title:o.value.title,findings:await o.value.run(t)})}catch(i){e.push({pluginId:o.pluginId,title:o.value.title,findings:[{status:"fail",message:i instanceof Error?i.message:String(i)}]})}return e}c(X,"runContributedChecks");function W(n,t,e){for(let o of t){let i=n.find(s=>s.value.id===o.value.id)?.pluginId;if(i!==void 0)throw new Error(`${e} ${o.value.id} is already owned by doctor plugin ${i}`)}}c(W,"assertAvailable");function b(n,t,e,o,i){if(!i())throw new Error(`Doctor plugin ${e} setup is complete`);if(!/^[a-z0-9][a-z0-9.-]*$/u.test(n.id))throw new Error(`Invalid ${o} ID: ${n.id}`);if(t.some(s=>s.value.id===n.id))throw new Error(`Doctor plugin ${e} registered ${o} ${n.id} twice`);t.push({pluginId:e,value:n})}c(b,"add");import fe from"node:path";import{readFile as se}from"node:fs/promises";async function Y(n,t,e,o=process.env){let i=await E(n,e.map(a=>a.value)),s=await ce(n),r=[];for(let a of e){let u=a.value;if(u.languages.every(v=>!t.has(v)))continue;let l=[],d=1,p=i.get(u.id),f=p?.config;f!==void 0&&(d+=6,l.push(`project config: ${f}`)),s.has(`${u.kind}:${u.id}`)&&(d+=6,l.push("Pi Agent IDE config"));let w=p?.dependency;w!==void 0&&(d+=4,l.push(`project dependency: ${w}`));let m=await ae(n,u.executables,o);m!==void 0&&(d+=3,l.push(`executable: ${m}`)),r.push({pluginId:a.pluginId,recipe:u,score:d,evidence:l,...m&&{executable:m}})}return r.sort((a,u)=>u.score-a.score||a.recipe.id.localeCompare(u.recipe.id))}c(Y,"discoverRecipeCandidates");function K(n,t,e=[]){let o=new Map,i=new Map(e.map(s=>[`${s.kind}:${s.languageId}`,s.toolId]));for(let s of t)for(let r of["formatter","linter","lsp"]){let a=i.get(`${r}:${s}`),u=a===void 0?4:7,l=n.filter(p=>p.recipe.kind===r&&p.recipe.languages.includes(s)&&p.executable!==void 0&&p.recipe.id!==a&&p.score>=u),d=l[0];d!==void 0&&(l.filter(p=>p.score===d.score).length>1||o.set(`${d.recipe.kind}:${d.recipe.id}`,d))}return[...o.values()]}c(K,"selectSuggestedRecipes");async function ae(n,t,e){for(let o of t)if(await N(o,n,e))return o}c(ae,"firstExecutable");async function ce(n){let t=new Set;for(let[e,o,i]of[["formatters","formatters","formatter"],["linters","linters","linter"],["lsp-servers","servers","lsp"]])try{let s=JSON.parse(await se(h(n,e),"utf8"));if(typeof s!="object"||s===null||Array.isArray(s))continue;let a=s[o];if(typeof a=="object"&&a!==null&&!Array.isArray(a))for(let u of Object.keys(a))t.add(`${i}:${u}`)}catch{}return t}c(ce,"managedRecipeIds");import{execFile as de}from"node:child_process";import{readdir as ue}from"node:fs/promises";import y from"node:path";import{promisify as le}from"node:util";var pe=le(de),ge=new Set([".git",".hg",".svn","node_modules","vendor","build","dist","coverage",".cache",".next","target"]);async function Q(n,t){t?.throwIfAborted();try{let o=(await pe("git",["ls-files","--cached","--others","--exclude-standard","-z"],{cwd:n,encoding:"utf8",maxBuffer:16777216,signal:t})).stdout.split("\0").filter(Boolean).map(i=>y.resolve(n,i)).filter(i=>!ee(i));return t?.throwIfAborted(),o.length>0?o:await k(n,t)}catch{return t?.throwIfAborted(),k(n,t)}}c(Q,"collectProjectFiles");function Z(n,t){let e=new Map;for(let o of t){let i=new Set(o.extensions.map(a=>a.toLowerCase())),s=new Set(o.fileNames),r=n.filter(a=>!a.split(y.sep).join("/").includes("/.pi/pi-agent-ide/")&&(i.has(y.extname(a).toLowerCase())||s.has(y.basename(a))));r.length>0&&e.set(o.id,r)}return e}c(Z,"detectProjectLanguages");async function k(n,t){t?.throwIfAborted();let e=[];for(let o of await ue(n,{withFileTypes:!0})){if(o.isDirectory()&&ge.has(o.name))continue;let i=y.join(n,o.name);ee(i)||(o.isDirectory()?e.push(...await k(i,t)):o.isFile()&&e.push(i))}return e}c(k,"walk");function ee(n){return n.split(y.sep).join("/").includes("/.pi/pi-agent-ide/")}c(ee,"isManagedIdeConfig");async function $(n,t,e=process.env,o){o?.throwIfAborted();let i=await Q(t,o);o?.throwIfAborted();let s=Z(i,n.languages.map(p=>p.value)),r=new Set(s.keys()),a={cwd:t,files:i,detectedLanguageIds:r,detectedLanguages:s,env:e},[u,l]=await Promise.all([Y(t,r,n.recipes,e),H(n,a)]),d=new Map;for(let p of r)for(let f of["formatter","linter","lsp"]){if(l.selections.some(g=>g.languageId===p&&g.kind===f))continue;let w=u.filter(g=>g.recipe.kind===f&&g.recipe.languages.includes(p)),m=c(g=>g.score-(g.executable===void 0?0:3),"nativeScore"),v=Math.max(1,...w.map(m));for(let g of w){if(g.executable!==void 0||m(g)!==v||v<=1)continue;let T=`${f}-${g.recipe.id}-unavailable`;d.set(T,{id:T,pluginId:g.pluginId,message:`Native project setup selects ${g.recipe.id}, but its executable is unavailable. Install ${g.recipe.executables.join(" or ")} and run Doctor again.`})}}return{cwd:t,files:i,detectedLanguages:s,candidates:u,selections:l.selections,actions:[...l.actions,...d.values()],suggestions:K(u,r,l.selections)}}c($,"inspectDoctorSetup");async function I(n,t,e=process.env){let o=await $(n,t,e),i=new Set(o.detectedLanguages.keys()),s={cwd:t,files:o.files,detectedLanguageIds:i,detectedLanguages:o.detectedLanguages,env:e},r=await X(n,s),a=[{status:"pass",message:`Project: ${t}`},o.files.length>0?{status:"pass",message:`${o.files.length} project files inspected`}:{status:"warn",message:"No project files found"},i.size>0?{status:"pass",message:`Detected: ${[...i].join(", ")}`}:{status:"warn",message:"No registered project languages detected"}];return{...o,sections:[{title:"Project",pluginId:"doctor",findings:a},...r]}}c(I,"runDoctor");function D(n){let t=["Pi Agent IDE doctor",""];for(let e of n.sections){t.push(`${e.title} (${e.pluginId})`);for(let o of e.findings)t.push(` ${o.status.toUpperCase().padEnd(4)} ${o.message}`),o.detail!==void 0&&t.push(` \`${o.detail}\``);t.push("")}if(n.actions.length>0){t.push("Setup needs attention");for(let e of n.actions)t.push(` ${e.message} [${e.pluginId}]`);t.push("")}if(n.suggestions.length>0){t.push("Suggested configuration");for(let e of n.suggestions){let o=e.evidence.length>0?` \u2014 ${e.evidence.join(", ")}`:"";t.push(` ${e.recipe.kind.padEnd(9)} ${e.recipe.id} [${e.pluginId}]${o}`)}t.push("")}return t.join(`
3
+ `).trimEnd()}c(D,"formatDoctorReport");function j(n){return n.actions.length>0||n.suggestions.length>0||n.sections.some(t=>t.findings.some(e=>e.status==="fail"))}c(j,"doctorNeedsWork");function te(n){let t=n.candidates.map(e=>({owner:e.pluginId,id:e.recipe.id,kind:e.recipe.kind,languages:e.recipe.languages,evidence:e.evidence,documentation:e.recipe.documentation}));return["Finish configuring Pi Agent IDE for this project.","Preserve existing formatter, linter, compiler, and style rules. Do not invent or replace native project settings.","Do not install packages, write credentials, or change source files without the user's normal confirmation.","Pi Agent IDE project configs live in .pi/pi-agent-ide/.","Use only the relevant plugin contributions listed below; each owner remains responsible for its own scope.","",D(n),"","Relevant registered recipes:",JSON.stringify(t,null,2),"",`Project root: ${fe.resolve(n.cwd)}`].join(`
4
+ `)}c(te,"buildDoctorAgentPrompt");import{createHash as me}from"node:crypto";var he="doctor",x=3;function ne(n,t){let e=_(n,ye(t));e!==void 0&&e.catch(()=>{})}c(ne,"registerDoctorTipProvider");function ye(n){return{protocol:F,apiVersion:M,id:he,async getTip(t){let e=await n(t),o=we(e);if(o.length===0)return;let i=o.slice(0,x).map(s=>`\u2022 ${s.message}`);return o.length>x&&i.push(`\u2022 ${o.length-x} more`),{id:`doctor-setup-${De(o)}`,title:o.length===1?"Project setup needs attention":`${o.length} project setup items`,body:[...i,"Run /pi-agent-ide-doctor"].join(`
5
+ `)}}}}c(ye,"createDoctorTipProvider");function we(n){let t=n.actions.map(o=>({id:`action:${o.pluginId}:${o.id}`,message:o.message})),e=n.suggestions.map(o=>{let i=o.recipe.languages.filter(r=>n.detectedLanguages.has(r)).join(", "),s={formatter:"formatting",linter:"linting",lsp:"language support"}[o.recipe.kind];return{id:`suggestion:${o.pluginId}:${o.recipe.kind}:${o.recipe.id}`,message:`Use ${o.recipe.name} for ${i} ${s}`}});return[...t,...e].sort((o,i)=>o.id.localeCompare(i.id))}c(we,"setupItems");function De(n){return me("sha256").update(n.map(t=>`${t.id}\0${t.message}`).join("\0")).digest("hex").slice(0,12)}c(De,"fingerprint");async function oe(n){let t=new C;ne(n,async i=>(await t.waitForPlugins(),$(t.snapshot(),i.cwd,process.env,i.signal)));let e,o=n.events.on(q,i=>{if(!z(i))throw new Error("Invalid doctor plugin registration request");i.accept(t.registerPlugin(i.plugin))});n.on("session_shutdown",o),n.registerCommand("pi-agent-ide-doctor",{description:"Check and configure Pi Agent IDE for this project",handler:c(async(i,s)=>{await t.waitForPlugins();let r=await I(t.snapshot(),s.cwd);A(n,D(r));let a=new Set(i.trim().split(/\s+/u).filter(Boolean));if(r.suggestions.length>0&&!a.has("--no-apply")&&(a.has("--apply")||s.hasUI&&await s.ui.confirm("Apply suggested configuration?","Add detected tools to .pi/pi-agent-ide/. Existing entries and native tool settings are kept."))){let d=await G(s.cwd,r.suggestions),p=d.length===0?"Pi Agent IDE configs are already up to date":`Updated ${d.length} Pi Agent IDE config ${d.length===1?"file":"files"}`;s.ui.notify(p,"info"),r=await I(t.snapshot(),s.cwd),A(n,D(r))}if(!j(r)&&!a.has("--agent"))return;(a.has("--agent")||s.hasUI&&await s.ui.confirm("Ask the agent to finish setup?","The agent will receive this redacted report and relevant plugin recipes."))&&(e=s.cwd,n.sendUserMessage(te(r)))},"handler")}),n.on("agent_end",async(i,s)=>{let r=e;if(r===void 0)return;e=void 0;let a=await I(t.snapshot(),r,process.env);A(n,`Doctor recheck after agent setup
6
+
7
+ ${D(a)}`),j(a)?s.ui.notify("Pi Agent IDE setup still needs attention","warning"):s.ui.notify("Pi Agent IDE setup is ready","info")}),n.events.emit(U,{protocol:J,apiVersion:1}),await t.waitForPlugins()}c(oe,"registerDoctor");function A(n,t){n.sendMessage({customType:"pi-agent-ide-doctor",content:t,display:!0},{triggerTurn:!1})}c(A,"sendReport");export{oe as default};
@@ -0,0 +1 @@
1
+ import{a as R}from"./chunk-WZI4YC2O.js";import{b as v,c as j,d as $}from"./chunk-N34ATN52.js";import{a as y}from"./chunk-ZC65Z3CK.js";import{a as i}from"./chunk-EI7MMDWY.js";import M from"cross-spawn";import{access as D,readFile as w,writeFile as N}from"node:fs/promises";import _ from"node:os";import a from"node:path";import{fileURLToPath as G}from"node:url";var L=1;function ie(e){return a.win32.basename(y(e[0]))}i(ie,"configuredExecutableName");async function se(e,n,o,t){let r=a.resolve(e),l=a.resolve(r,n),s=t.filter(d=>W(d,l));if(Q(r,l))return r;let c=a.dirname(l);for(;;){if(await H(F(c,o))||[...(await R(c,s)).values()].some(u=>u.score>0))return c;let f=a.dirname(c);if(f===c)return;c=f}}i(se,"resolveExternalToolProjectRoot");function J(e){return a.join(e,".pi","pi-agent-ide")}i(J,"projectIdeConfigDirectory");function F(e,n){return a.join(J(e),`${n}.json`)}i(F,"projectIdeConfigPath");function B(e,n,o={}){let r=(o.environment??process.env).PI_CODING_AGENT_DIR?.trim(),l=r===void 0||r.length===0?a.join(o.homeDirectory??_.homedir(),".pi","agent"):a.resolve(r);return{project:F(e,n),global:a.join(l,"extensions","pi-agent-ide",`${n}.json`),builtIn:G(new URL(`tool-config/${n}.json`,new URL("../src/api/tool-config.ts",import.meta.url).href))}}i(B,"resolveToolConfigPaths");async function ae(e,n,o,t={}){let r=B(e,n,t),l=[{layer:"project",sourcePath:r.project,optional:!0},...t.includeGlobal===!1?[]:[{layer:"global",sourcePath:r.global,optional:!0}],{layer:"built-in",sourcePath:r.builtIn,optional:!1}],s=[],c=new Set;for(let d of l){let f=await U(d,n,o);for(let[u,C]of Object.entries(f))c.has(u)||(c.add(u),s.push({id:u,config:C,layer:d.layer,sourcePath:d.sourcePath}))}return{entries:s,paths:r}}i(ae,"loadLayeredToolConfig");function V(e,n,o){let t=a.extname(n).toLowerCase();if(e.extensions.every(s=>!(S(s)===t||s==="*"))&&!e.fileNames?.some(s=>process.platform==="win32"?s.toLowerCase()===a.basename(n).toLowerCase():s===a.basename(n)))return!1;let r=a.relative(o,n).split(a.sep).join("/"),l=i(s=>s?.some(c=>a.matchesGlob(r,c))??!1,"matches");return(e.include===void 0||l(e.include))&&!l(e.exclude)}i(V,"matchesConfiguredFile");function le(e,n,o,t,r){let l=a.resolve(r,t),s=e.filter(f=>V(f.config,l,r)),c=s.find(f=>f.layer!=="built-in");if(c!==void 0)return c;let d=Math.max(0,...s.map(f=>o.get(f.id)?.score??0));return s.find(f=>n.has(f.id)&&(o.get(f.id)?.score??0)===d)}i(le,"selectConfiguredEntry");async function ce(e,n,o=process.env){h(e,"process");let t=y(e.command[0]).replaceAll("{project}",n),r=A(e,n,o);return $(t,n,r)}i(ce,"hasConfiguredExecutable");async function q(e,n){h(e,"process");let o=e.command.map(d=>K(d,n)),t=y(o[0]),r=o.slice(1),l=e.cwd==="file"?a.dirname(n.filePath):n.projectRoot,s=e.successExitCodes??[0],c=A(e,n.projectRoot,n.env??process.env);return new Promise((d,f)=>{let u=M(t,r,{cwd:l,env:c,signal:n.signal,killSignal:"SIGKILL",stdio:["ignore","pipe","pipe"]}),C="",P="",b=y(u.stdout),x=y(u.stderr),E=!1,T=setTimeout(()=>{E=!0,u.kill("SIGKILL")},e.timeoutMs??3e4);b.setEncoding("utf8"),x.setEncoding("utf8"),b.on("data",g=>{C+=g}),x.on("data",g=>{P+=g}),u.on("error",g=>{clearTimeout(T),f(g)}),u.on("close",g=>{clearTimeout(T),d({ok:!E&&g!==null&&s.includes(g),exitCode:g,stdout:C,stderr:P})})})}i(q,"runConfiguredProcess");async function fe(e,n){let o=await w(n.filePath,"utf8"),t=await q(e.run,n);if(!t.ok)return e.output==="in-place"&&await w(n.filePath,"utf8")!==o&&await N(n.filePath,o,"utf8"),{ok:!1,changed:!1};e.output==="stdout"&&t.stdout!==o&&await N(n.filePath,t.stdout,"utf8");let r=await w(n.filePath,"utf8");return{ok:!0,changed:o!==r}}i(fe,"runConfiguredFormatter");function de(e){let n=O(e,"formatters");for(let[o,t]of Object.entries(n.entries)){let r=m(t,`formatter ${o}`);if(I(r,`formatter ${o}`),h(r.run,`formatter ${o}.run`),r.output!=="in-place"&&r.output!=="stdout")throw new Error(`formatter ${o}.output must be in-place or stdout`)}return e}i(de,"parseFormattersConfig");function ue(e){let n=O(e,"linters"),o=new Set(["pi-json","eslint-json","sarif","checkstyle","gcc","clang","regex"]);for(let[t,r]of Object.entries(n.entries)){let l=m(r,`linter ${t}`);I(l,`linter ${t}`),h(l.check,`linter ${t}.check`),l.fix!==void 0&&h(l.fix,`linter ${t}.fix`);let s=m(l.diagnostics,`linter ${t}.diagnostics`);if(!o.has(String(s.format)))throw new Error(`linter ${t} has an unsupported diagnostics format`);if(s.columnBase!==void 0&&(s.format!=="regex"||s.columnBase!==0&&s.columnBase!==1))throw new Error(`linter ${t} columnBase must be 0 or 1 for regex diagnostics`);if(s.format==="regex"&&typeof s.pattern!="string")throw new Error(`linter ${t} regex diagnostics require pattern`)}return e}i(ue,"parseLintersConfig");function O(e,n){let o=m(e,"tool config");if(o.version!==L)throw new Error(`tool config version must be ${L}`);return{entries:m(o[n],n)}}i(O,"configRoot");function I(e,n){p(e.extensions,`${n}.extensions`,!1),e.fileNames!==void 0&&p(e.fileNames,`${n}.fileNames`,!1),e.include!==void 0&&p(e.include,`${n}.include`,!1),e.exclude!==void 0&&p(e.exclude,`${n}.exclude`,!0)}i(I,"assertMatcher");function h(e,n){let o=m(e,n);if(p(o.command,`${n}.command`,!1),o.cwd!==void 0&&o.cwd!=="project"&&o.cwd!=="file")throw new Error(`${n}.cwd must be project or file`);if(o.timeoutMs!==void 0&&(!Number.isFinite(o.timeoutMs)||Number(o.timeoutMs)<=0))throw new Error(`${n}.timeoutMs must be positive`);if(o.successExitCodes!==void 0&&(!Array.isArray(o.successExitCodes)||o.successExitCodes.some(t=>!Number.isInteger(t))))throw new Error(`${n}.successExitCodes must contain integers`);if(o.env!==void 0){let t=m(o.env,`${n}.env`);if(Object.values(t).some(r=>typeof r!="string"))throw new Error(`${n}.env values must be strings`)}}i(h,"assertProcessConfig");function p(e,n,o){if(!Array.isArray(e)||!o&&e.length===0||e.some(t=>typeof t!="string"||t.length===0))throw new Error(`${n} must be ${o?"an":"a non-empty"} array of strings`)}i(p,"assertStringArray");function m(e,n){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(`${n} must be an object`);return e}i(m,"configRecord");function S(e){return e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`}i(S,"normalizeExtension");async function U(e,n,o){let t;try{t=await w(e.sourcePath,"utf8")}catch(r){if(e.optional&&z(r))return{};throw new Error(`Cannot read ${e.layer} ${n} config at ${e.sourcePath}: ${k(r)}`,{cause:r})}try{return o(JSON.parse(t))}catch(r){throw new Error(`Invalid ${e.layer} ${n} config at ${e.sourcePath}: ${k(r)}`,{cause:r})}}i(U,"readToolConfigLayer");function z(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}i(z,"isMissingFile");function k(e){return e instanceof Error?e.message:String(e)}i(k,"errorMessage");function A(e,n,o){return j(n,{...v(o),...v(e.env??{})})}i(A,"createConfiguredProcessEnvironment");function K(e,n){let o=a.relative(n.projectRoot,n.filePath);return e.replaceAll("{project}",n.projectRoot).replaceAll("{fileDir}",a.dirname(n.filePath)).replaceAll("{relativeFile}",o).replaceAll("{file}",n.filePath)}i(K,"expandPlaceholders");function W(e,n){let o=a.extname(n).toLowerCase(),t=a.basename(n),r=i((l,s=[])=>l.some(c=>S(c)===o)||s.some(c=>c===t),"matches");return e.formatter?r(e.formatter.extensions,e.formatter.fileNames):e.linter?r(e.linter.extensions,e.linter.fileNames):e.lsp?r(Object.values(e.lsp.languageIds).flat(),Object.values(e.lsp.fileNames??{}).flat()):!1}i(W,"recipeMatchesFile");async function H(e){try{return await D(e),!0}catch{return!1}}i(H,"fileExists");function Q(e,n){let o=a.relative(e,n);return o===""||o!==".."&&!o.startsWith(`..${a.sep}`)&&!a.isAbsolute(o)}i(Q,"isPathInside");export{L as a,ie as b,se as c,J as d,F as e,B as f,ae as g,V as h,le as i,ce as j,q as k,fe as l,de as m,ue as n,A as o};
@@ -0,0 +1,2 @@
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};