pi-agent-ide 0.9.8 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (908) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +5 -3
  3. package/dist/chunk-26SMC6OS.js +2 -0
  4. package/dist/chunk-2EY3LEZ7.js +1 -0
  5. package/dist/chunk-2QCE7GOV.js +1 -0
  6. package/dist/chunk-3BRGWFEI.js +2 -0
  7. package/dist/chunk-3JBQYLJ4.js +5 -0
  8. package/dist/chunk-3KM5DSWL.js +37 -0
  9. package/dist/chunk-3V3OQO5S.js +118 -0
  10. package/dist/chunk-45EJ4762.js +33 -0
  11. package/dist/chunk-4DLSZYUO.js +1 -0
  12. package/dist/chunk-54EFJYUB.js +1 -0
  13. package/dist/{chunk-5DN2XBVI.js → chunk-5TPYHUJV.js} +1 -1
  14. package/dist/{chunk-KQV2ZXLP.js → chunk-6DC2Q5BI.js} +1 -1
  15. package/dist/chunk-72WO7H5T.js +1 -0
  16. package/dist/chunk-72X24ARV.js +2 -0
  17. package/dist/chunk-7OAAM5FL.js +1 -0
  18. package/dist/chunk-AB6RSWMB.js +23 -0
  19. package/dist/chunk-ASVMQMPX.js +10 -0
  20. package/dist/chunk-BW3XONMZ.js +1 -0
  21. package/dist/chunk-C327T6YP.js +19 -0
  22. package/dist/{chunk-R2U5WXYR.js → chunk-D23NS4VV.js} +1 -1
  23. package/dist/chunk-E4V4VNRM.js +3 -0
  24. package/dist/chunk-E7JBYW43.js +1 -0
  25. package/dist/chunk-GDIF3WT6.js +12 -0
  26. package/dist/chunk-GNYFA6FS.js +2 -0
  27. package/dist/{chunk-DHOIQZUF.js → chunk-GQXZEOND.js} +1 -1
  28. package/dist/chunk-GT2JPOBM.js +1 -0
  29. package/dist/chunk-GTZOIJCH.js +1 -0
  30. package/dist/chunk-HRZAIZGR.js +1 -0
  31. package/dist/{chunk-H6FEBUAP.js → chunk-HSAGZWPO.js} +1 -1
  32. package/dist/{chunk-2DSY4U73.js → chunk-I3G6K7QU.js} +1 -1
  33. package/dist/chunk-IRLWXPL4.js +7 -0
  34. package/dist/chunk-IZTOXSTR.js +6 -0
  35. package/dist/chunk-J5CKSIH7.js +1 -0
  36. package/dist/chunk-JKM4E5VB.js +5 -0
  37. package/dist/chunk-JMCI2ZE2.js +3 -0
  38. package/dist/{chunk-YZTVC7ME.js → chunk-JY63UUC2.js} +1 -1
  39. package/dist/chunk-KM4NOIOB.js +5 -0
  40. package/dist/chunk-L2YDUMZC.js +13 -0
  41. package/dist/chunk-MCHU3BLO.js +53 -0
  42. package/dist/chunk-MJMRV76H.js +1 -0
  43. package/dist/chunk-MMQIHUU5.js +1 -0
  44. package/dist/chunk-MNAIMZRO.js +9 -0
  45. package/dist/chunk-NKI4TZSS.js +2 -0
  46. package/dist/chunk-NSBRKTZ7.js +1 -0
  47. package/dist/chunk-NWCTAVGR.js +4 -0
  48. package/dist/chunk-O2C3F3MA.js +1 -0
  49. package/dist/chunk-OA26FH5G.js +1 -0
  50. package/dist/chunk-OEEE5BLN.js +16 -0
  51. package/dist/chunk-OLMACWQX.js +11 -0
  52. package/dist/{chunk-72FL5FHZ.js → chunk-PBMHSK6J.js} +1 -1
  53. package/dist/chunk-QCAGAJHJ.js +1 -0
  54. package/dist/{chunk-P7FUD4WY.js → chunk-QR7JR3P2.js} +1 -1
  55. package/dist/chunk-QSU5AEKW.js +1 -0
  56. package/dist/chunk-QUK5ZEYX.js +1 -0
  57. package/dist/chunk-R7576HPO.js +25 -0
  58. package/dist/{chunk-B5UJCNQU.js → chunk-RNDSWVJF.js} +1 -1
  59. package/dist/chunk-RYJEEBET.js +1 -0
  60. package/dist/chunk-S4GTWS2J.js +6 -0
  61. package/dist/chunk-SF44YQCB.js +2 -0
  62. package/dist/chunk-SJQGFUXR.js +6 -0
  63. package/dist/chunk-SKZTIAE4.js +4 -0
  64. package/dist/chunk-SZRC24OB.js +1 -0
  65. package/dist/chunk-T5PXAYWC.js +1 -0
  66. package/dist/chunk-TIZ4QDF3.js +1 -0
  67. package/dist/chunk-UN3XLVPR.js +18 -0
  68. package/dist/chunk-V2LLMBTA.js +1 -0
  69. package/dist/chunk-VB5P3TXJ.js +111 -0
  70. package/dist/chunk-VNG4QPPT.js +12 -0
  71. package/dist/chunk-VNNAVC4S.js +15 -0
  72. package/dist/chunk-VPBGKSFI.js +3 -0
  73. package/dist/chunk-VQ2RA43A.js +7 -0
  74. package/dist/chunk-VWYI4WF7.js +3 -0
  75. package/dist/chunk-W25HNEMR.js +4 -0
  76. package/dist/chunk-X7CHS7JB.js +1 -0
  77. package/dist/chunk-XEPCURYZ.js +1 -0
  78. package/dist/chunk-XKVU6AAS.js +7 -0
  79. package/dist/chunk-XLTAP5YC.js +24 -0
  80. package/dist/chunk-XQMNVPNS.js +1 -0
  81. package/dist/chunk-YI32H7Z2.js +4 -0
  82. package/dist/chunk-ZYG5E3DI.js +9 -0
  83. package/dist/entry-0.js +1 -1
  84. package/dist/entry-12.js +1 -1
  85. package/dist/entry-15.js +1 -1
  86. package/dist/entry-17.js +1 -1
  87. package/dist/entry-18.js +1 -1
  88. package/dist/entry-19.js +1 -1
  89. package/dist/entry-20.js +1 -1
  90. package/dist/entry-21.js +1 -1
  91. package/dist/entry-22.js +1 -1
  92. package/dist/entry-27.js +1 -1
  93. package/dist/entry-28.js +1 -1
  94. package/dist/entry-31.js +2 -2
  95. package/dist/entry-32.js +1 -1
  96. package/dist/entry-33.js +1 -1
  97. package/dist/entry-34.js +1 -1
  98. package/dist/entry-35.js +1 -1
  99. package/dist/entry-36.js +1 -1
  100. package/dist/entry-37.js +1 -1
  101. package/dist/entry-38.js +19 -13
  102. package/dist/entry-4.js +1 -1
  103. package/dist/entry-40.js +1 -1
  104. package/dist/entry-41.js +1 -1
  105. package/dist/entry-43.js +1 -1
  106. package/dist/entry-44.js +1 -1
  107. package/dist/entry-45.js +1 -1
  108. package/dist/entry-48.js +1 -1
  109. package/dist/entry-49.js +1 -1
  110. package/dist/entry-50.js +1 -1
  111. package/dist/entry-51.js +1 -1
  112. package/dist/entry-52.js +1 -1
  113. package/dist/entry-53.js +1 -1
  114. package/dist/entry-54.js +1 -1
  115. package/dist/entry-55.js +1 -1
  116. package/dist/entry-56.js +1 -1
  117. package/dist/entry-57.js +1 -1
  118. package/dist/entry-58.js +1 -1
  119. package/dist/entry-59.js +1 -1
  120. package/dist/entry-60.js +1 -1
  121. package/dist/entry-61.js +1 -1
  122. package/dist/entry-62.js +1 -1
  123. package/dist/entry-63.js +1 -1
  124. package/dist/entry-64.js +1 -1
  125. package/dist/entry-65.js +1 -1
  126. package/dist/entry-66.js +1 -1
  127. package/dist/entry-67.js +1 -1
  128. package/dist/entry-68.js +1 -0
  129. package/dist/entry-69.js +1 -1
  130. package/dist/entry-71.js +1 -1
  131. package/dist/entry-72.js +0 -1
  132. package/dist/entry-73.js +1 -1
  133. package/dist/entry-74.js +1 -1
  134. package/dist/entry-75.js +1 -1
  135. package/dist/entry-76.js +1 -1
  136. package/dist/entry-77.js +1 -1
  137. package/dist/entry-78.js +1 -0
  138. package/dist/entry-79.js +1 -1
  139. package/dist/entry-8.js +1 -1
  140. package/dist/entry-80.js +1 -0
  141. package/dist/entry-81.js +0 -1
  142. package/dist/entry-82.js +1 -1
  143. package/dist/entry-83.js +1 -1
  144. package/dist/entry-84.js +0 -1
  145. package/dist/entry-85.js +1 -1
  146. package/dist/entry-86.js +1 -2
  147. package/dist/entry-87.js +1 -1
  148. package/dist/entry-88.js +1 -1
  149. package/dist/entry-89.js +1 -1
  150. package/dist/entry-90.js +1 -1
  151. package/dist/entry-91.js +1 -3
  152. package/dist/entry-92.js +1 -1
  153. package/dist/entry-93.js +1 -1
  154. package/dist/entry-94.js +1 -1
  155. package/dist/entry-95.js +3 -0
  156. package/dist/entry-96.js +1 -0
  157. package/dist/entry-97.js +1 -0
  158. package/dist/entry-98.js +1 -0
  159. package/dist/pi-agent-ide.js +26 -13
  160. package/docs/agent-guides/ast-search.md +15 -4
  161. package/docs/agent-guides/debugger.md +1 -1
  162. package/docs/agent-guides/git-changes.md +1 -0
  163. package/docs/agent-guides/ssh.md +27 -7
  164. package/docs/agent-guides/terminal.md +4 -0
  165. package/docs/configuration.md +65 -11
  166. package/docs/development.md +4 -0
  167. package/docs/extensions.md +6 -4
  168. package/docs/nightly.md +7 -1
  169. package/docs/releases.md +1 -1
  170. package/docs/structured-results.md +29 -15
  171. package/docs/tools.md +95 -29
  172. package/docs/user-hooks.md +1 -1
  173. package/node_modules/pi-agent-doctor/package.json +1 -1
  174. package/node_modules/pi-agent-doctor/src/catalog.ts +2 -0
  175. package/node_modules/pi-agent-doctor/src/executable.ts +1 -1
  176. package/node_modules/pi-agent-documentation/package.json +1 -1
  177. package/node_modules/pi-agent-filesystem/package.json +7 -7
  178. package/node_modules/pi-agent-filesystem/src/file-write-lock.ts +6 -4
  179. package/node_modules/pi-agent-filesystem/src/replace-file.ts +5 -2
  180. package/node_modules/pi-agent-filesystem/src/resolver.ts +26 -10
  181. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  182. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  183. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  184. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  185. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  186. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +56 -65
  187. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +197 -130
  188. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +2 -1
  189. package/node_modules/pi-agent-ide-ast/src/ast-grep-binary.ts +46 -0
  190. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +119 -97
  191. package/node_modules/pi-agent-ide-ast/src/extension.ts +9 -24
  192. package/node_modules/pi-agent-ide-ast/src/outline-page.ts +96 -0
  193. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +42 -78
  194. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +5 -1
  195. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +2 -1
  196. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +24 -5
  197. package/node_modules/pi-agent-ide-ast/src/search-presentation.ts +2 -1
  198. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +406 -200
  199. package/node_modules/pi-agent-ide-ast/src/tool-ast-search.ts +27 -9
  200. package/node_modules/pi-agent-ide-ast/src/tool-outline.ts +191 -0
  201. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  202. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +63 -20
  203. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +1 -0
  204. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +25 -0
  205. package/node_modules/pi-agent-ide-changes/src/changes/git-paths.ts +13 -6
  206. package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +12 -8
  207. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +88 -78
  208. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +29 -3
  209. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  210. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +39 -3
  211. package/node_modules/pi-agent-ide-formatter/src/rustfmt.ts +101 -0
  212. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  213. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  214. package/node_modules/pi-agent-ide-lint/src/catalog.ts +20 -14
  215. package/node_modules/pi-agent-ide-lint/src/registry.ts +2 -2
  216. package/node_modules/pi-agent-ide-lsp/index.ts +15 -88
  217. package/node_modules/pi-agent-ide-lsp/package.json +12 -12
  218. package/node_modules/pi-agent-ide-lsp/src/catalog.ts +21 -9
  219. package/node_modules/pi-agent-ide-lsp/src/lsp/clang-coverage.ts +265 -0
  220. package/node_modules/pi-agent-ide-lsp/src/lsp/clangd-launch.ts +48 -0
  221. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +94 -11
  222. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +514 -207
  223. package/node_modules/pi-agent-ide-lsp/src/lsp/corrected-names.ts +222 -0
  224. package/node_modules/pi-agent-ide-lsp/src/lsp/declaration-scan.ts +116 -0
  225. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +20 -1
  226. package/node_modules/pi-agent-ide-lsp/src/lsp/files-containing.ts +70 -0
  227. package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +1 -1
  228. package/node_modules/pi-agent-ide-lsp/src/lsp/initialization-options.ts +37 -0
  229. package/node_modules/pi-agent-ide-lsp/src/lsp/line-breaks.ts +16 -0
  230. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +185 -131
  231. package/node_modules/pi-agent-ide-lsp/src/lsp/missing-sources.ts +21 -0
  232. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +45 -24
  233. package/node_modules/pi-agent-ide-lsp/src/lsp/position-map.ts +17 -0
  234. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +40 -12
  235. package/node_modules/pi-agent-ide-lsp/src/lsp/range-match.ts +49 -0
  236. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +16 -5
  237. package/node_modules/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +7 -1
  238. package/node_modules/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +133 -37
  239. package/node_modules/pi-agent-ide-lsp/src/lsp/shared-servers.ts +164 -13
  240. package/node_modules/pi-agent-ide-lsp/src/lsp/source-changes.ts +18 -6
  241. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +414 -174
  242. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +424 -0
  243. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +67 -0
  244. package/node_modules/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +10 -0
  245. package/node_modules/pi-agent-ide-lsp/src/name-captures.ts +66 -0
  246. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +384 -93
  247. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +356 -79
  248. package/node_modules/pi-agent-ide-lsp/src/tool-lsp-search.ts +33 -11
  249. package/node_modules/pi-agent-image/package.json +2 -2
  250. package/node_modules/pi-agent-image/src/image-converter.ts +13 -2
  251. package/node_modules/pi-agent-invariant/package.json +1 -1
  252. package/node_modules/pi-agent-pdf/package.json +2 -2
  253. package/node_modules/pi-agent-read/package.json +7 -7
  254. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  255. package/node_modules/pi-agent-read/src/api/read-parameters.ts +51 -12
  256. package/node_modules/pi-agent-read/src/api/tools/read.ts +39 -3
  257. package/node_modules/pi-agent-read/src/core/extension.ts +80 -3
  258. package/node_modules/pi-agent-read/src/core/read-core.ts +6 -0
  259. package/node_modules/pi-agent-read/src/core/tools/read/list-result.ts +79 -0
  260. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +45 -4
  261. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +18 -9
  262. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +16 -3
  263. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +37 -9
  264. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +15 -4
  265. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +49 -18
  266. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +158 -51
  267. package/node_modules/pi-agent-resource/package.json +5 -1
  268. package/node_modules/pi-agent-resource/src/file-text-read.ts +86 -0
  269. package/node_modules/pi-agent-resource/src/index.ts +54 -0
  270. package/node_modules/pi-agent-resource/src/json-structured-arguments.ts +131 -0
  271. package/node_modules/pi-agent-resource/src/line-map.ts +750 -0
  272. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  273. package/node_modules/pi-agent-resource/src/resource-scheduler.ts +63 -23
  274. package/node_modules/pi-agent-resource/src/resource.ts +5 -0
  275. package/node_modules/pi-agent-resource/src/result-targets.ts +693 -66
  276. package/node_modules/pi-agent-resource/src/script-calls.ts +21 -0
  277. package/node_modules/pi-agent-resource/src/tool-deadline.ts +199 -0
  278. package/node_modules/pi-agent-resource/src/tool-result.ts +14 -5
  279. package/node_modules/pi-agent-resource/src/unchanged-read.ts +62 -0
  280. package/node_modules/pi-agent-search/package.json +8 -9
  281. package/node_modules/pi-agent-search/runtime/entry-57.js +0 -1
  282. package/node_modules/pi-agent-search/src/api/fuzzy.ts +2 -1
  283. package/node_modules/pi-agent-search/src/api/null-fields.ts +50 -0
  284. package/node_modules/pi-agent-search/src/api/path-list.ts +68 -0
  285. package/node_modules/pi-agent-search/src/api/presentation.ts +2 -1
  286. package/node_modules/pi-agent-search/src/api/search-call-policy.ts +16 -0
  287. package/node_modules/pi-agent-search/src/api/search-capture.ts +56 -0
  288. package/node_modules/pi-agent-search/src/api/search-parameters.ts +26 -4
  289. package/node_modules/pi-agent-search/src/api/search-scope.ts +38 -2
  290. package/node_modules/pi-agent-search/src/api/search.ts +46 -3
  291. package/node_modules/pi-agent-search/src/api/structured-result.ts +121 -26
  292. package/node_modules/pi-agent-search/src/core/extension.ts +75 -42
  293. package/node_modules/pi-agent-search/src/core/search-config.ts +2 -2
  294. package/node_modules/pi-agent-search/src/core/search-core.ts +103 -39
  295. package/node_modules/pi-agent-search-text/index.ts +62 -20
  296. package/node_modules/pi-agent-search-text/package.json +15 -15
  297. package/node_modules/pi-agent-search-text/runtime/entry-59.js +1 -0
  298. package/node_modules/pi-agent-search-text/src/current-matches.ts +314 -0
  299. package/node_modules/pi-agent-search-text/src/file-search.ts +178 -99
  300. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +40 -17
  301. package/node_modules/pi-agent-search-text/src/persisted-result.ts +3 -8
  302. package/node_modules/pi-agent-search-text/src/resolvers.ts +395 -103
  303. package/node_modules/pi-agent-search-text/src/ripgrep.ts +142 -0
  304. package/node_modules/pi-agent-search-text/src/scoped-search.ts +24 -12
  305. package/node_modules/pi-agent-search-text/src/search-backend.ts +333 -108
  306. package/node_modules/pi-agent-search-text/src/search-presentation.ts +6 -0
  307. package/node_modules/pi-agent-search-text/src/search-query.ts +69 -34
  308. package/node_modules/pi-agent-search-text/src/search-recipe.ts +80 -8
  309. package/node_modules/pi-agent-search-text/src/search-renderer.ts +2 -1
  310. package/node_modules/pi-agent-search-text/src/search-result.ts +10 -1
  311. package/node_modules/pi-agent-search-text/src/search-session.ts +449 -58
  312. package/node_modules/pi-agent-search-text/src/tool-file-search.ts +51 -6
  313. package/node_modules/pi-agent-text/package.json +3 -3
  314. package/node_modules/pi-agent-text/runtime/entry-63.js +1 -0
  315. package/node_modules/pi-agent-text/src/index.ts +18 -0
  316. package/node_modules/pi-agent-text/src/line-anchors.ts +211 -0
  317. package/node_modules/pi-agent-text/src/no-final-line-break.ts +12 -0
  318. package/node_modules/pi-agent-text/src/search-highlight.ts +8 -0
  319. package/node_modules/pi-agent-text/src/source-line.ts +7 -1
  320. package/node_modules/pi-agent-text/src/text-anchor.ts +34 -3
  321. package/node_modules/pi-agent-text/src/text-converter.ts +2 -1
  322. package/node_modules/pi-agent-text/src/text-document.ts +9 -23
  323. package/node_modules/pi-agent-text/src/text-target.ts +14 -6
  324. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  325. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-64.js +2 -0
  326. package/node_modules/pi-agent-text-anchor-exact/index.ts +1 -65
  327. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  328. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-65.js +0 -1
  329. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-66.js +2 -0
  330. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +185 -184
  331. package/node_modules/pi-agent-text-anchor-exact/src/anchored-literal-view.ts +122 -0
  332. package/node_modules/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +2 -1
  333. package/node_modules/pi-agent-text-anchor-exact/src/literal-match.ts +359 -0
  334. package/node_modules/pi-agent-text-anchor-exact/src/recovery.ts +1 -0
  335. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +5 -3
  336. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  337. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-67.js +0 -1
  338. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-68.js +2 -0
  339. package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +92 -67
  340. package/node_modules/pi-agent-text-anchor-line-hash/src/range-history.ts +105 -0
  341. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +22 -17
  342. package/node_modules/pi-agent-text-editor/index.ts +0 -10
  343. package/node_modules/pi-agent-text-editor/package.json +37 -26
  344. package/node_modules/pi-agent-text-editor/runtime/entry-84.js +0 -1
  345. package/node_modules/pi-agent-text-editor/runtime/entry-85.js +1 -0
  346. package/node_modules/pi-agent-text-editor/runtime/entry-86.js +1 -0
  347. package/node_modules/pi-agent-text-editor/runtime/entry-88.js +2 -0
  348. package/node_modules/pi-agent-text-editor/src/api/anchor-excerpt.ts +7 -0
  349. package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +2 -1
  350. package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +2 -0
  351. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +40 -8
  352. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -1
  353. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +37 -2
  354. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +2 -2
  355. package/node_modules/pi-agent-text-editor/src/api/native-files.ts +16 -2
  356. package/node_modules/pi-agent-text-editor/src/api/pi-edit-text.ts +82 -0
  357. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +9 -2
  358. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +1 -0
  359. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +13 -2
  360. package/node_modules/pi-agent-text-editor/src/api/text-selector-fields.ts +210 -0
  361. package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -0
  362. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  363. package/node_modules/pi-agent-text-editor/src/core/already-done.ts +123 -0
  364. package/node_modules/pi-agent-text-editor/src/core/anchor-candidates.ts +116 -0
  365. package/node_modules/pi-agent-text-editor/src/core/anchor-preview.ts +32 -0
  366. package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +109 -23
  367. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +19 -5
  368. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +6 -5
  369. package/node_modules/pi-agent-text-editor/src/core/extension.ts +54 -21
  370. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +7 -3
  371. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +14 -5
  372. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +32 -11
  373. package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +67 -38
  374. package/node_modules/pi-agent-text-editor/src/core/file-write-observations.ts +287 -0
  375. package/node_modules/pi-agent-text-editor/src/core/image-write.ts +16 -4
  376. package/node_modules/pi-agent-text-editor/src/core/lookalike-bytes.ts +254 -0
  377. package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +29 -12
  378. package/node_modules/pi-agent-text-editor/src/core/mutation-result/compact-receipt.ts +48 -0
  379. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +2 -1
  380. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +24 -34
  381. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +13 -20
  382. package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +32 -3
  383. package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +36 -2
  384. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +26 -19
  385. package/node_modules/pi-agent-text-editor/src/core/native-snapshot-source.ts +13 -0
  386. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +526 -148
  387. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +28 -3
  388. package/node_modules/pi-agent-text-editor/src/core/read-fragment-resolver.ts +34 -14
  389. package/node_modules/pi-agent-text-editor/src/core/reference-list.ts +95 -0
  390. package/node_modules/pi-agent-text-editor/src/core/result-scope.ts +129 -0
  391. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +20 -8
  392. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +86 -69
  393. package/node_modules/pi-agent-text-editor/src/core/source-aliases.ts +92 -0
  394. package/node_modules/pi-agent-text-editor/src/core/source-change-retry.ts +92 -7
  395. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +2 -0
  396. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +162 -47
  397. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +321 -101
  398. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +206 -134
  399. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -2
  400. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +133 -18
  401. package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +13 -0
  402. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +823 -226
  403. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +51 -1
  404. package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +7 -4
  405. package/node_modules/pi-agent-text-editor/src/tools/display-marker.ts +15 -0
  406. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +268 -159
  407. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +37 -32
  408. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +24 -70
  409. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +23 -36
  410. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +31 -45
  411. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +33 -65
  412. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +80 -42
  413. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +27 -16
  414. package/node_modules/pi-agent-text-editor-renderer/index.ts +0 -14
  415. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  416. package/node_modules/pi-agent-text-editor-renderer/runtime/entry-89.js +2 -0
  417. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +204 -78
  418. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +75 -8
  419. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +4 -1
  420. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -3
  421. package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +44 -30
  422. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +170 -26
  423. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +83 -83
  424. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -6
  425. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  426. package/node_modules/pi-agent-tool-call-interception/runtime/entry-91.js +1 -0
  427. package/node_modules/pi-agent-tool-ui/package.json +3 -3
  428. package/node_modules/pi-agent-tool-ui/runtime/entry-92.js +1 -0
  429. package/node_modules/pi-agent-tool-ui/runtime/entry-93.js +1 -0
  430. package/node_modules/pi-agent-web/index.ts +0 -3
  431. package/node_modules/pi-agent-web/package.json +8 -8
  432. package/node_modules/pi-agent-web/src/search.ts +1 -2
  433. package/node_modules/pi-agent-web-html/package.json +3 -3
  434. package/node_modules/pi-agent-web-html/runtime/entry-95.js +2 -0
  435. package/node_modules/pi-agent-web-image/package.json +4 -4
  436. package/node_modules/pi-agent-web-image/runtime/entry-96.js +2 -0
  437. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  438. package/node_modules/pi-agent-web-pdf/runtime/entry-97.js +2 -0
  439. package/node_modules/pi-agent-web-text/package.json +4 -4
  440. package/node_modules/pi-agent-web-text/runtime/entry-98.js +2 -0
  441. package/package.json +38 -38
  442. package/skills/capture-code-review-rule/SKILL.md +1 -1
  443. package/skills/configure-agent-ide/SKILL.md +1 -1
  444. package/src/api/code-view.ts +0 -2
  445. package/src/api/tool-config/linters.json +1 -0
  446. package/src/api/tool-config/lsp-servers.json +5 -0
  447. package/src/api/tool-config.ts +23 -2
  448. package/src/backend/config.ts +2 -0
  449. package/src/backend/configured-process.ts +1 -0
  450. package/src/backend/dap-java-transport.ts +4 -2
  451. package/src/backend/dap-java-worker.py +11 -4
  452. package/src/backend/dap-node-transport.ts +4 -2
  453. package/src/backend/dap-tcp-transport.ts +2 -3
  454. package/src/backend/debugger-workspace-owner.ts +6 -6
  455. package/src/backend/doctor-probe-worker.py +23 -15
  456. package/src/backend/doctor-workspace.ts +19 -18
  457. package/src/backend/file-transfer.ts +160 -56
  458. package/src/backend/formatter-registration.ts +54 -2
  459. package/src/backend/identity.ts +81 -12
  460. package/src/backend/lsp-file-watchers.ts +7 -9
  461. package/src/backend/lsp-workspace-owner.ts +25 -1
  462. package/src/backend/object-transfer.ts +28 -15
  463. package/src/backend/owned-command.ts +2 -1
  464. package/src/backend/owned-read-command.ts +2 -1
  465. package/src/backend/packaged-source.ts +12 -0
  466. package/src/backend/process-environment.ts +7 -9
  467. package/src/backend/process-metadata.ts +5 -5
  468. package/src/backend/recipe-evidence-worker.py +2 -0
  469. package/src/backend/recipe-evidence.ts +7 -8
  470. package/src/backend/registration.ts +2 -1
  471. package/src/backend/registry.ts +12 -2
  472. package/src/backend/resource-resolver.ts +11 -32
  473. package/src/backend/search-environment.ts +61 -4
  474. package/src/backend/ssh-channel-worker.py +6 -304
  475. package/src/backend/ssh-channel.ts +287 -36
  476. package/src/backend/ssh-connection-loss.ts +123 -0
  477. package/src/backend/ssh-file-stream.ts +216 -0
  478. package/src/backend/ssh-master.ts +443 -0
  479. package/src/backend/ssh-transfer-worker-windows.py +84 -0
  480. package/src/backend/ssh-transfer-worker.py +43 -10
  481. package/src/backend/ssh-transport.ts +238 -24
  482. package/src/backend/ssh-worker.py +7 -728
  483. package/src/backend/ssh.ts +83 -35
  484. package/src/backend/ssh_channel_common.py +68 -0
  485. package/src/backend/ssh_channel_posix.py +324 -0
  486. package/src/backend/ssh_channel_windows.py +527 -0
  487. package/src/backend/ssh_paths.py +23 -0
  488. package/src/backend/ssh_windows_files.py +254 -0
  489. package/src/backend/ssh_worker_common.py +96 -0
  490. package/src/backend/ssh_worker_posix.py +780 -0
  491. package/src/backend/ssh_worker_windows.py +687 -0
  492. package/src/backend/tool-config-access.ts +14 -11
  493. package/src/backend/tool-project.ts +4 -3
  494. package/src/backend/web-browser.ts +2 -3
  495. package/src/backend/web-http.ts +5 -5
  496. package/src/code-view/diagnostic-view.ts +12 -30
  497. package/src/code-view/reference.ts +9 -18
  498. package/src/code-view/source-view.ts +2 -1
  499. package/src/composite/codemode-tool-names.ts +79 -0
  500. package/src/composite/detached-results.ts +25 -6
  501. package/src/composite/ide-alias-rendering.ts +26 -4
  502. package/src/composite/module-labels.ts +2 -2
  503. package/src/composite/module-settings.ts +1 -0
  504. package/src/composite/nested-tool-rendering.ts +70 -24
  505. package/src/composite/output-limits.ts +12 -5
  506. package/src/composite/parallel-tool-guidance.ts +38 -0
  507. package/src/composite/script-values/ast-search.ts +56 -0
  508. package/src/composite/script-values/copy.ts +8 -0
  509. package/src/composite/script-values/delete.ts +5 -0
  510. package/src/composite/script-values/diff.ts +28 -0
  511. package/src/composite/script-values/edit-selection.ts +48 -0
  512. package/src/composite/script-values/failures.ts +170 -0
  513. package/src/composite/script-values/file-receipts.ts +63 -0
  514. package/src/composite/script-values/file-search.ts +10 -0
  515. package/src/composite/script-values/index.ts +55 -0
  516. package/src/composite/script-values/insert.ts +5 -0
  517. package/src/composite/script-values/lsp-search.ts +136 -0
  518. package/src/composite/script-values/match.ts +53 -0
  519. package/src/composite/script-values/move.ts +8 -0
  520. package/src/composite/script-values/path-list.ts +25 -0
  521. package/src/composite/script-values/provider-value.ts +21 -0
  522. package/src/composite/script-values/read.ts +206 -0
  523. package/src/composite/script-values/replace.ts +5 -0
  524. package/src/composite/script-values/result-reference.ts +9 -0
  525. package/src/composite/script-values/search-matches.ts +113 -0
  526. package/src/composite/script-values/search.ts +64 -0
  527. package/src/composite/script-values/semantic-search.ts +8 -0
  528. package/src/composite/script-values/terminal.ts +112 -0
  529. package/src/composite/script-values/text.ts +7 -0
  530. package/src/composite/script-values/types.ts +56 -0
  531. package/src/composite/script-values/undo.ts +5 -0
  532. package/src/composite/script-values/write.ts +8 -0
  533. package/src/composite/settings-panel.ts +18 -2
  534. package/src/composite/text-results.ts +488 -175
  535. package/src/composite/tool-availability.ts +29 -16
  536. package/src/composite/tool-discovery-guidance.ts +97 -0
  537. package/src/documentation/attachment.ts +31 -0
  538. package/src/documentation/extension.ts +6 -2
  539. package/src/documentation/search.ts +1 -7
  540. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  541. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  542. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  543. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  544. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  545. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/file-write-lock.ts +6 -4
  546. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/replace-file.ts +5 -2
  547. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +26 -10
  548. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +0 -3
  549. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  550. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  551. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-95.js +2 -0
  552. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  553. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-96.js +2 -0
  554. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  555. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-97.js +2 -0
  556. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  557. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-98.js +2 -0
  558. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-94.js +2 -0
  559. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +1 -2
  560. package/src/extensions/pi-agent-read/package.json +7 -7
  561. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  562. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +51 -12
  563. package/src/extensions/pi-agent-read/src/api/tools/read.ts +39 -3
  564. package/src/extensions/pi-agent-read/src/core/extension.ts +80 -3
  565. package/src/extensions/pi-agent-read/src/core/read-core.ts +6 -0
  566. package/src/extensions/pi-agent-read/src/core/tools/read/list-result.ts +79 -0
  567. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +45 -4
  568. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +18 -9
  569. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +16 -3
  570. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +37 -9
  571. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +15 -4
  572. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +49 -18
  573. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +158 -51
  574. package/src/extensions/pi-agent-search/package.json +8 -9
  575. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +62 -20
  576. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +15 -15
  577. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-59.js +1 -0
  578. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-62.js +1 -0
  579. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/current-matches.ts +314 -0
  580. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +178 -99
  581. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +40 -17
  582. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/persisted-result.ts +3 -8
  583. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +395 -103
  584. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +142 -0
  585. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +24 -12
  586. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +333 -108
  587. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +6 -0
  588. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +69 -34
  589. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +80 -8
  590. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +2 -1
  591. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +10 -1
  592. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +449 -58
  593. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/tool-file-search.ts +51 -6
  594. package/src/extensions/pi-agent-search/runtime/entry-57.js +0 -1
  595. package/src/extensions/pi-agent-search/runtime/entry-58.js +2 -0
  596. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +2 -1
  597. package/src/extensions/pi-agent-search/src/api/null-fields.ts +50 -0
  598. package/src/extensions/pi-agent-search/src/api/path-list.ts +68 -0
  599. package/src/extensions/pi-agent-search/src/api/presentation.ts +2 -1
  600. package/src/extensions/pi-agent-search/src/api/search-call-policy.ts +16 -0
  601. package/src/extensions/pi-agent-search/src/api/search-capture.ts +56 -0
  602. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +26 -4
  603. package/src/extensions/pi-agent-search/src/api/search-scope.ts +38 -2
  604. package/src/extensions/pi-agent-search/src/api/search.ts +46 -3
  605. package/src/extensions/pi-agent-search/src/api/structured-result.ts +121 -26
  606. package/src/extensions/pi-agent-search/src/core/extension.ts +75 -42
  607. package/src/extensions/pi-agent-search/src/core/search-config.ts +2 -2
  608. package/src/extensions/pi-agent-search/src/core/search-core.ts +103 -39
  609. package/src/extensions/pi-agent-text-editor/index.ts +0 -10
  610. package/src/extensions/pi-agent-text-editor/package.json +37 -26
  611. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  612. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-64.js +2 -0
  613. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +1 -65
  614. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  615. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-65.js +0 -1
  616. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-66.js +2 -0
  617. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +185 -184
  618. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchored-literal-view.ts +122 -0
  619. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +2 -1
  620. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/literal-match.ts +359 -0
  621. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/recovery.ts +1 -0
  622. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +5 -3
  623. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  624. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-67.js +0 -1
  625. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-68.js +2 -0
  626. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +92 -67
  627. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/range-history.ts +105 -0
  628. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +22 -17
  629. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +0 -14
  630. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  631. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-89.js +2 -0
  632. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +204 -78
  633. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +75 -8
  634. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +4 -1
  635. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -3
  636. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +44 -30
  637. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +170 -26
  638. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +83 -83
  639. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -6
  640. package/src/extensions/pi-agent-text-editor/runtime/entry-84.js +0 -1
  641. package/src/extensions/pi-agent-text-editor/runtime/entry-85.js +1 -0
  642. package/src/extensions/pi-agent-text-editor/runtime/entry-86.js +1 -0
  643. package/src/extensions/pi-agent-text-editor/runtime/entry-87.js +1 -0
  644. package/src/extensions/pi-agent-text-editor/runtime/entry-88.js +2 -0
  645. package/src/extensions/pi-agent-text-editor/src/api/anchor-excerpt.ts +7 -0
  646. package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +2 -1
  647. package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +2 -0
  648. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +40 -8
  649. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -1
  650. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +37 -2
  651. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +2 -2
  652. package/src/extensions/pi-agent-text-editor/src/api/native-files.ts +16 -2
  653. package/src/extensions/pi-agent-text-editor/src/api/pi-edit-text.ts +82 -0
  654. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +9 -2
  655. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +1 -0
  656. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +13 -2
  657. package/src/extensions/pi-agent-text-editor/src/api/text-selector-fields.ts +210 -0
  658. package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -0
  659. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  660. package/src/extensions/pi-agent-text-editor/src/core/already-done.ts +123 -0
  661. package/src/extensions/pi-agent-text-editor/src/core/anchor-candidates.ts +116 -0
  662. package/src/extensions/pi-agent-text-editor/src/core/anchor-preview.ts +32 -0
  663. package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +109 -23
  664. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +19 -5
  665. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +6 -5
  666. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +54 -21
  667. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +7 -3
  668. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +14 -5
  669. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +32 -11
  670. package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +67 -38
  671. package/src/extensions/pi-agent-text-editor/src/core/file-write-observations.ts +287 -0
  672. package/src/extensions/pi-agent-text-editor/src/core/image-write.ts +16 -4
  673. package/src/extensions/pi-agent-text-editor/src/core/lookalike-bytes.ts +254 -0
  674. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +29 -12
  675. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/compact-receipt.ts +48 -0
  676. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +2 -1
  677. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +24 -34
  678. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +13 -20
  679. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +32 -3
  680. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +36 -2
  681. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +26 -19
  682. package/src/extensions/pi-agent-text-editor/src/core/native-snapshot-source.ts +13 -0
  683. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +526 -148
  684. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +28 -3
  685. package/src/extensions/pi-agent-text-editor/src/core/read-fragment-resolver.ts +34 -14
  686. package/src/extensions/pi-agent-text-editor/src/core/reference-list.ts +95 -0
  687. package/src/extensions/pi-agent-text-editor/src/core/result-scope.ts +129 -0
  688. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +20 -8
  689. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +86 -69
  690. package/src/extensions/pi-agent-text-editor/src/core/source-aliases.ts +92 -0
  691. package/src/extensions/pi-agent-text-editor/src/core/source-change-retry.ts +92 -7
  692. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +2 -0
  693. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +162 -47
  694. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +321 -101
  695. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +206 -134
  696. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -2
  697. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +133 -18
  698. package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +13 -0
  699. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +823 -226
  700. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +51 -1
  701. package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +7 -4
  702. package/src/extensions/pi-agent-text-editor/src/tools/display-marker.ts +15 -0
  703. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +268 -159
  704. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +37 -32
  705. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +24 -70
  706. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +23 -36
  707. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +31 -45
  708. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +33 -65
  709. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +80 -42
  710. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +27 -16
  711. package/src/pi-agent-ide.ts +41 -32
  712. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  713. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +56 -65
  714. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +197 -130
  715. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +2 -1
  716. package/src/plugins/pi-agent-ide-ast/src/ast-grep-binary.ts +46 -0
  717. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +119 -97
  718. package/src/plugins/pi-agent-ide-ast/src/extension.ts +9 -24
  719. package/src/plugins/pi-agent-ide-ast/src/outline-page.ts +96 -0
  720. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +42 -78
  721. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +5 -1
  722. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +2 -1
  723. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +24 -5
  724. package/src/plugins/pi-agent-ide-ast/src/search-presentation.ts +2 -1
  725. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +406 -200
  726. package/src/plugins/pi-agent-ide-ast/src/tool-ast-search.ts +27 -9
  727. package/src/plugins/pi-agent-ide-ast/src/tool-outline.ts +191 -0
  728. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  729. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +63 -20
  730. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +1 -0
  731. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +25 -0
  732. package/src/plugins/pi-agent-ide-changes/src/changes/git-paths.ts +13 -6
  733. package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +12 -8
  734. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +88 -78
  735. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +29 -3
  736. package/src/plugins/pi-agent-ide-debugger/index.ts +42 -32
  737. package/src/plugins/pi-agent-ide-debugger/src/string-enum.ts +14 -0
  738. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +124 -79
  739. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  740. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +39 -3
  741. package/src/plugins/pi-agent-ide-formatter/src/rustfmt.ts +101 -0
  742. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  743. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  744. package/src/plugins/pi-agent-ide-lint/src/catalog.ts +20 -14
  745. package/src/plugins/pi-agent-ide-lint/src/registry.ts +2 -2
  746. package/src/plugins/pi-agent-ide-lsp/index.ts +15 -88
  747. package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
  748. package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +21 -9
  749. package/src/plugins/pi-agent-ide-lsp/src/lsp/clang-coverage.ts +265 -0
  750. package/src/plugins/pi-agent-ide-lsp/src/lsp/clangd-launch.ts +48 -0
  751. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +94 -11
  752. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +514 -207
  753. package/src/plugins/pi-agent-ide-lsp/src/lsp/corrected-names.ts +222 -0
  754. package/src/plugins/pi-agent-ide-lsp/src/lsp/declaration-scan.ts +116 -0
  755. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +20 -1
  756. package/src/plugins/pi-agent-ide-lsp/src/lsp/files-containing.ts +70 -0
  757. package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +1 -1
  758. package/src/plugins/pi-agent-ide-lsp/src/lsp/initialization-options.ts +37 -0
  759. package/src/plugins/pi-agent-ide-lsp/src/lsp/line-breaks.ts +16 -0
  760. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +185 -131
  761. package/src/plugins/pi-agent-ide-lsp/src/lsp/missing-sources.ts +21 -0
  762. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +45 -24
  763. package/src/plugins/pi-agent-ide-lsp/src/lsp/position-map.ts +17 -0
  764. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +40 -12
  765. package/src/plugins/pi-agent-ide-lsp/src/lsp/range-match.ts +49 -0
  766. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +16 -5
  767. package/src/plugins/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +7 -1
  768. package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +133 -37
  769. package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-servers.ts +164 -13
  770. package/src/plugins/pi-agent-ide-lsp/src/lsp/source-changes.ts +18 -6
  771. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +414 -174
  772. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +424 -0
  773. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +67 -0
  774. package/src/plugins/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +10 -0
  775. package/src/plugins/pi-agent-ide-lsp/src/name-captures.ts +66 -0
  776. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +384 -93
  777. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +356 -79
  778. package/src/plugins/pi-agent-ide-lsp/src/tool-lsp-search.ts +33 -11
  779. package/src/plugins/pi-agent-ide-processes/src/registry.ts +64 -3
  780. package/src/plugins/pi-agent-ide-processes/src/ui.ts +57 -1
  781. package/src/plugins/pi-agent-ide-semantic/src/backend.ts +18 -6
  782. package/src/plugins/pi-agent-ide-semantic/src/vera-backend.ts +16 -9
  783. package/src/plugins/pi-agent-ide-terminal/index.ts +23 -7
  784. package/src/plugins/pi-agent-ide-terminal/src/list.ts +79 -0
  785. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +22 -0
  786. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +3 -0
  787. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +18 -6
  788. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +132 -18
  789. package/src/plugins/pi-agent-ide-terminal/src/search.ts +117 -50
  790. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +94 -10
  791. package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +24 -1
  792. package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +5 -2
  793. package/src/plugins/pi-agent-ide-terminal/src/terminal-text.ts +173 -0
  794. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +266 -112
  795. package/src/plugins/pi-agent-ide-terminal/src/types.ts +6 -1
  796. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +11 -6
  797. package/src/plugins/pi-agent-ide-terminal/src/unix-pty-output.ts +47 -0
  798. package/src/post-edit/gate.ts +16 -1
  799. package/src/semantic/extension.ts +8 -2
  800. package/src/standalone/scoped-api.ts +85 -18
  801. package/src/toolchain/types.ts +4 -0
  802. package/dist/chunk-2AANEKFS.js +0 -1
  803. package/dist/chunk-33U3RUM3.js +0 -12
  804. package/dist/chunk-34IYWKY5.js +0 -1
  805. package/dist/chunk-4CSNQX54.js +0 -23
  806. package/dist/chunk-53IV6EKV.js +0 -1
  807. package/dist/chunk-5AROEOJB.js +0 -1
  808. package/dist/chunk-5D4C225L.js +0 -1
  809. package/dist/chunk-5W6QQZFI.js +0 -2
  810. package/dist/chunk-6W4OJLCJ.js +0 -1
  811. package/dist/chunk-6ZYCTWQE.js +0 -1
  812. package/dist/chunk-756K3LJY.js +0 -1
  813. package/dist/chunk-AMSNDWBT.js +0 -2
  814. package/dist/chunk-APWMLLSE.js +0 -17
  815. package/dist/chunk-BMSAVDRD.js +0 -13
  816. package/dist/chunk-BRJIXNFU.js +0 -5
  817. package/dist/chunk-C2GZLLSP.js +0 -5
  818. package/dist/chunk-ECSMTGVM.js +0 -6
  819. package/dist/chunk-EWTVVPUA.js +0 -11
  820. package/dist/chunk-FBR7ZLLN.js +0 -1
  821. package/dist/chunk-FGN2ZMEN.js +0 -1
  822. package/dist/chunk-FJSYWOE6.js +0 -1
  823. package/dist/chunk-FTECKRK6.js +0 -1
  824. package/dist/chunk-GRZTKMXQ.js +0 -1
  825. package/dist/chunk-HFCHOFLV.js +0 -2
  826. package/dist/chunk-HFF4GY7R.js +0 -3
  827. package/dist/chunk-HJXSEPO7.js +0 -111
  828. package/dist/chunk-HSEDKYH4.js +0 -1
  829. package/dist/chunk-II7AOJNH.js +0 -9
  830. package/dist/chunk-J34VKQGJ.js +0 -1
  831. package/dist/chunk-J6CDIH3S.js +0 -84
  832. package/dist/chunk-JHWLRL4U.js +0 -1
  833. package/dist/chunk-JMQ67UNK.js +0 -3
  834. package/dist/chunk-JRIP33PC.js +0 -13
  835. package/dist/chunk-K5M65CAF.js +0 -1
  836. package/dist/chunk-KJAR2WDO.js +0 -1
  837. package/dist/chunk-KX7MG72M.js +0 -1
  838. package/dist/chunk-L2B4DTVS.js +0 -1
  839. package/dist/chunk-LEKC4GQK.js +0 -5
  840. package/dist/chunk-LIGOOMJS.js +0 -10
  841. package/dist/chunk-LY2UANKU.js +0 -6
  842. package/dist/chunk-M7P7V4WI.js +0 -25
  843. package/dist/chunk-MXLSGMRZ.js +0 -3
  844. package/dist/chunk-N2NEFXHB.js +0 -13
  845. package/dist/chunk-NF74ITWT.js +0 -2
  846. package/dist/chunk-NQYUIQRH.js +0 -1
  847. package/dist/chunk-OCU6NW5Y.js +0 -1
  848. package/dist/chunk-OIEA4QWF.js +0 -4
  849. package/dist/chunk-ON5HDFNL.js +0 -10
  850. package/dist/chunk-P43GGKUC.js +0 -28
  851. package/dist/chunk-PPCWY4BB.js +0 -1
  852. package/dist/chunk-QGXZ4RWX.js +0 -1
  853. package/dist/chunk-S3T5NOSL.js +0 -1
  854. package/dist/chunk-S7E2D5K7.js +0 -5
  855. package/dist/chunk-SIYPD5MM.js +0 -3
  856. package/dist/chunk-STUZZM5B.js +0 -1
  857. package/dist/chunk-T4FTT3U4.js +0 -1
  858. package/dist/chunk-T5ACAOKJ.js +0 -4
  859. package/dist/chunk-TILMPAF2.js +0 -1
  860. package/dist/chunk-TSNY2FSU.js +0 -1
  861. package/dist/chunk-TWJINFQB.js +0 -9
  862. package/dist/chunk-TWQ6ACOI.js +0 -1
  863. package/dist/chunk-UDVVKVG4.js +0 -1
  864. package/dist/chunk-V2D5MLGE.js +0 -1
  865. package/dist/chunk-VDSSAP6Y.js +0 -1
  866. package/dist/chunk-VHYJTAXX.js +0 -1
  867. package/dist/chunk-WCSWQDJ2.js +0 -22
  868. package/dist/chunk-WQTF6Q2X.js +0 -3
  869. package/dist/chunk-XE4W5YTE.js +0 -2
  870. package/dist/chunk-YFPU2LRR.js +0 -23
  871. package/dist/chunk-YLEERRX3.js +0 -33
  872. package/dist/chunk-YOJHCARZ.js +0 -1
  873. package/dist/chunk-YPTDPMK5.js +0 -1
  874. package/docs/agent-guides/editing.md +0 -43
  875. package/docs/agent-guides/search.md +0 -38
  876. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +0 -73
  877. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-63.js +0 -2
  878. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-64.js +0 -1
  879. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-66.js +0 -1
  880. package/node_modules/pi-agent-text-editor/runtime/entry-68.js +0 -1
  881. package/node_modules/pi-agent-text-editor-renderer/runtime/entry-85.js +0 -2
  882. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +0 -2
  883. package/node_modules/pi-agent-tool-ui/runtime/entry-88.js +0 -1
  884. package/node_modules/pi-agent-tool-ui/runtime/entry-89.js +0 -1
  885. package/node_modules/pi-agent-web-html/runtime/entry-91.js +0 -2
  886. package/node_modules/pi-agent-web-image/runtime/entry-92.js +0 -2
  887. package/node_modules/pi-agent-web-pdf/runtime/entry-93.js +0 -2
  888. package/src/composite/search-facts.ts +0 -45
  889. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-91.js +0 -2
  890. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-92.js +0 -2
  891. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-93.js +0 -2
  892. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-94.js +0 -2
  893. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-58.js +0 -2
  894. package/src/extensions/pi-agent-search/runtime/entry-54.js +0 -1
  895. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-63.js +0 -2
  896. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-64.js +0 -1
  897. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-66.js +0 -1
  898. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-85.js +0 -2
  899. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +0 -2
  900. package/src/extensions/pi-agent-text-editor/runtime/entry-68.js +0 -1
  901. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +0 -73
  902. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-54.js +0 -0
  903. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-58.js +0 -0
  904. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-62.js +0 -0
  905. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-text-editor}/runtime/entry-87.js +0 -0
  906. /package/node_modules/{pi-agent-web → pi-agent-text-editor-stale-anchor}/runtime/entry-90.js +0 -0
  907. /package/node_modules/{pi-agent-web-text → pi-agent-web}/runtime/entry-94.js +0 -0
  908. /package/src/extensions/{pi-agent-read/extensions/pi-agent-web → pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor}/runtime/entry-90.js +0 -0
@@ -0,0 +1,53 @@
1
+ import{a as tt}from"./chunk-VNG4QPPT.js";import{d as et}from"./chunk-BW3XONMZ.js";import{a as Ze}from"./chunk-I3G6K7QU.js";import{a as Ye,b as Ke}from"./chunk-HSAGZWPO.js";import{B as He,g as ve,k as De,m as Ue,ma as ce,na as Ge,ta as Xe,u as Ie,va as Qe,x as ze}from"./chunk-OEEE5BLN.js";import{a as je}from"./chunk-2QCE7GOV.js";import{a as i}from"./chunk-EI7MMDWY.js";import{createHash as Kt}from"node:crypto";import Ot from"node:path";import{DEFAULT_MAX_BYTES as Nt,DEFAULT_MAX_LINES as qt,truncateHead as Jt}from"@earendil-works/pi-coding-agent";var G={bytes:Nt,lines:qt,pixels:4e6,images:20,imageBytes:20*1024*1024};async function K(e,n="",t,r={}){let s=typeof n=="string"?[n]:n,a=[],c=e.flatMap(R=>{if(R.type!=="text")return[];let O=s.find(v=>v.length>0&&R.text.endsWith(v));return O?(a.push(O),[R.text.slice(0,-O.length)]):[R.text]}).join(`
2
+ `),d=a.join(""),g=r.limitText===!1?{truncated:!1,content:c,firstLineExceedsLimit:!1}:Jt(c,{maxBytes:G.bytes,maxLines:G.lines}),k=[],V;if(g.truncated&&t!==void 0)try{V=await t(c)}catch{k.push("[Full output could not be saved. Narrow the request to inspect it.]")}g.truncated&&k.push(`[Output truncated: useful content is limited to ${G.bytes} bytes / ${G.lines} lines. Narrow the request or read a smaller source range.]`),V!==void 0&&k.push(`[Full output: ${JSON.stringify(V)}. Read with offset/limit, or read ${JSON.stringify("raw:"+V)} for byte ranges. Available until this runtime is disposed.]`);let B=e.filter(R=>R.type==="image"),N=B.slice(0,G.images),W=[],F=Math.floor(G.pixels/Math.max(1,N.length)),Q=0,U=B.length-N.length,q;for(let[R,O]of N.entries())try{q??=await import("@napi-rs/canvas");let{createCanvas:v,loadImage:pe}=q,se=Buffer.from(O.data,"base64"),z=await pe(se),ee=Math.min(1,Math.sqrt(F/(z.width*z.height))),o=Math.min(F,Math.max(1,Math.floor(z.height*ee))),u=Math.min(Math.floor(F/o),Math.max(1,Math.floor(z.width*ee))),p=se,h=O.mimeType;if(ee<1||Q+p.byteLength>G.imageBytes){let f=v(u,o);f.getContext("2d").drawImage(z,0,0,u,o),p=await f.encode("png"),h="image/png"}if(Q+p.byteLength>G.imageBytes){U++;continue}Q+=p.byteLength,W.push({type:"image",data:p.toString("base64"),mimeType:h}),ee<1&&k.push(`[Image ${R+1} resized from ${z.width}x${z.height} to ${u}x${o} to fit the shared media budget.]`)}catch{U++,k.push(`[Image ${R+1} could not be decoded and was not returned.]`)}return U>0&&k.push(`[${U} images omitted from the result. Read fewer frames or a smaller image region.]`),{text:g.firstLineExceedsLimit?Wt(c):g.content,textTruncated:g.truncated,images:W,notices:k,metadataSuffix:d,fullOutput:V}}i(K,"limitIdeOutput");function Wt(e){let n=0,t=0;for(let r of e){let s=Buffer.byteLength(r);if(n+s>G.bytes)break;n+=s,t+=r.length}return e.slice(0,t)}i(Wt,"bytePrefix");import _e from"node:path";var E={type:"object",properties:{path:{type:"string"},line:{allOf:[{type:"integer"}]},text:{type:"string"},lineText:{type:"string",description:"Complete containing lines without the final line ending; absent when unavailable."},id:{type:"string"}},required:["path","line","text"],additionalProperties:!1};function ge(e,n){if(n===void 0||!_e.isAbsolute(e))return e;let t=_e.relative(n,e);return t.length>0&&!t.startsWith("..")&&!_e.isAbsolute(t)?t:e}i(ge,"scriptMatchPath");var le=/^<system-result\b[^>]*><uuid>([a-f\d-]{36})<\/uuid><\/system-result>\n?/u;function L(e){let n=le.exec(e)?.[1];return n===void 0?void 0:`RESULT#${n}`}i(L,"resultReference");function oe(e=E,n={}){return{anyOf:[{type:"object",properties:{id:{type:"string"},complete:{type:"boolean"},matches:{type:"array",items:e},...n},required:["complete","matches"],additionalProperties:!1},{type:"string",description:"Readable result of a search whose results are not text matches, such as a provider's object list."}]}}i(oe,"matchListSchema");function he(e,n=!1){let t=x(e.outcome)&&e.outcome.status===(n?"partial":"success")?e.outcome.data:void 0,r=L(e.shown);if(r===void 0||!x(t)||t.kind!=="matches"||!Array.isArray(t.matches)||typeof t.complete!="boolean")return;let s=Ce(t.matches,e.cwd);if(s!==void 0)return{...typeof t.target=="string"&&{id:r},complete:t.complete&&t.truncated!==!0,matches:s}}i(he,"matchList");function Ce(e,n){let t=[];for(let r of e){if(!x(r))return;let s=Me(r,n);if(s===void 0)return;t.push({match:s,data:r})}return t}i(Ce,"matchEntries");function Me(e,n){let{source:t,matchedText:r,target:s,range:a}=e,c=x(a)?a.startLine:void 0;if(!(typeof t!="string"||typeof r!="string"||typeof c!="number"))return{path:ge(t,n),line:c,text:r,...typeof e.lineText=="string"&&{lineText:e.lineText},...typeof s=="string"&&{id:s}}}i(Me,"scriptMatch");function x(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(x,"record");var Te={type:"object",properties:{text:{type:"string"},id:{type:"string"}},required:["text"],additionalProperties:!1},we={schema:oe({...E,properties:{...E.properties,captures:{type:"object",additionalProperties:{type:"array",items:Te}}},required:[...E.required,"captures"]}),project(e){let n=he(e);if(n===void 0)return e.shown;let t=[];for(let{match:r,data:s}of n.matches){let a={};for(let[c,d]of Object.entries(x(s.captures)?s.captures:{})){if(!Array.isArray(d))return e.shown;let g=[];for(let k of d){let V=x(k)?Me(k,e.cwd):void 0;if(V===void 0)return e.shown;g.push({text:V.text,...V.id!==void 0&&{id:V.id}})}a[c]=g}t.push({...r,captures:a})}return{...n.id!==void 0&&{id:n.id},complete:n.complete,matches:t}}};var Ee={type:"object",description:"Value returned by a resource provider, such as a computer action outcome.",additionalProperties:!0};function ue(e){let n=xe(e)?e.metadata:void 0,t=xe(n)?n.semanticAction:void 0,r=xe(t)?t.script:void 0;return xe(r)&&!Array.isArray(r)?r:void 0}i(ue,"providerValue");function xe(e){return e!==null&&typeof e=="object"}i(xe,"record");var P={schema:{anyOf:[{type:"string",description:"RESULT#<uuid> that selects the text the edit produced; pass it to a source parameter. Null when the edit selects no text or its selection cannot be verified, even if the edit succeeded. Check the failure block; read the file before further edits when no selection is verified."},Ee]},project:i(e=>ue(e.details)??Ft(e),"project"),failed:i(({details:e})=>ue(e),"failed")},rt={schema:Ee,project:i(({details:e})=>ue(e)??null,"project"),failed:i(({details:e})=>ue(e),"failed")};function Ft({outcome:e,shown:n}){let t=nt(e)&&e.status==="success"?e.data:void 0;return!nt(t)||typeof t.target!="string"?null:L(n)??null}i(Ft,"editSelection");function nt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(nt,"record");var ot=P;var st=rt;var at={schema:{type:"string",description:'Complete unified diff of the two sources; "" when they are equal.'},project({details:e,shown:n}){let t=it(e)?e.comparison:void 0;return!it(t)||typeof t.equal!="boolean"||typeof t.diff!="string"?n:t.equal?"":t.diff}};function it(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(it,"record");function be(e){return{schema:{type:"array",items:{type:"string"}},project:i(({outcome:n})=>{let t=ct(n)?n.data:void 0,r=ct(t)&&(e===void 0||t.kind===e)?t.files:void 0;return Array.isArray(r)&&r.every(s=>typeof s=="string")?r:null},"project")}}i(be,"pathListValue");function ct(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(ct,"record");var lt=be("files"),ut={...lt,failed:lt.project};var dt=P;var ke={schema:oe(E,{fallback:{type:"object",properties:{mode:{type:"string",enum:["regex","words"]},id:{type:"string"},complete:{type:"boolean"},matches:{type:"array",items:E}},required:["mode","complete","matches"],additionalProperties:!1},notices:{type:"array",items:{type:"string"}},editWarning:{type:"string"}}),project(e){return pt(e)??e.shown},failed(e){return pt(e,!0)}};function pt(e,n=!1){let t=he(e,n);if(t===void 0)return;let r=t.matches.map(({match:g})=>({...g})),s=x(e.outcome)&&x(e.outcome.data)?e.outcome.data:{},a=s.fallback==="regex"||s.fallback==="words"?s.fallback:void 0,c=Array.isArray(s.notices)&&s.notices.every(g=>typeof g=="string")?s.notices:[],d={...t.id!==void 0&&{id:t.id},complete:t.complete,matches:r};return{...a===void 0?d:{complete:!0,matches:[],fallback:{mode:a,...d}},...c.length===0?{}:{notices:c},...typeof s.editWarning=="string"?{editWarning:s.editWarning}:{}}}i(pt,"projectSearch");var Oe={type:"array",items:E},ft={schema:{anyOf:[{type:"object",description:"calls: references in matches, callers in incoming, callees in outgoing.",properties:{id:{type:"string"},complete:{type:"boolean"},matches:Oe,incoming:Oe,outgoing:Oe},required:["id","complete","matches","incoming","outgoing"],additionalProperties:!1},...oe({...E,properties:{...E.properties,captures:{type:"object",properties:{name:{type:"array",items:Te}},additionalProperties:!1}}},{candidateLimits:{type:"array",description:"Workspace symbol candidate limits reached before scope filtering.",items:{type:"object",properties:{server:{type:"string"},limit:{type:"integer"}},required:["server","limit"],additionalProperties:!1}},skipped:{type:"array",description:"Query candidates with no declaration anchor; the result is incomplete.",items:{type:"object",properties:{name:{type:"string"},path:{type:"string"}},required:["name","path"],additionalProperties:!1}}}).anyOf]},project(e){let n=x(e.outcome)&&e.outcome.status==="success"?e.outcome.data:void 0;if(x(n)&&n.kind==="custom")return vt(n.value,e)??e.shown;if(x(n)&&Array.isArray(n.matches)&&n.matches.some(r=>x(r)&&x(r.captures)))return we.project(e);let t=ke.project(e);return!x(t)||!x(n)?t:{...t,...Array.isArray(n.candidateLimits)&&{candidateLimits:n.candidateLimits.flatMap(r=>x(r)&&typeof r.server=="string"&&typeof r.limit=="number"?[{server:r.server,limit:r.limit}]:[])},...Array.isArray(n.skipped)&&{skipped:n.skipped.flatMap(r=>x(r)&&typeof r.name=="string"&&typeof r.source=="string"?[{name:r.name,path:ge(r.source,e.cwd)}]:[])}}}};function vt(e,n){if(!x(e))return;let t=[e.matches,e.incoming,e.outgoing].map(c=>Dt(c,n.cwd)),[r,s,a]=t;if(!(typeof e.target!="string"||typeof e.complete!="boolean"||r===void 0||s===void 0||a===void 0))return{id:e.target,complete:e.complete&&t.every(c=>c?.complete===!0),matches:r.matches,incoming:s.matches,outgoing:a.matches}}i(vt,"callGraph");function Dt(e,n){if(!x(e)||e.kind!=="matches"||!Array.isArray(e.matches))return;let t=Ce(e.matches,n);if(t!==void 0)return{complete:e.truncated!==!0,matches:t.map(({match:r})=>({...r}))}}i(Dt,"places");var mt=P;var yt={type:"object",properties:{type:{const:"image"},data:{type:"string"},mimeType:{type:"string"}},required:["type","data","mimeType"]},xt={type:"object",description:"Text, exactly as requested, without notices. Pass the value or its id to a source parameter.",properties:{text:{type:"string"},id:{type:"string"}},required:["text","id"]},gt=[xt,{type:"object",properties:{bytes:{type:"string"}},required:["bytes"]},{type:"object",properties:{entries:{type:"array",items:{type:"string"}}},required:["entries"]},yt,{type:"object",description:"Several images, such as sequence frames, in source order.",properties:{type:{const:"images"},images:{type:"array",items:yt}},required:["type","images"]}],$e={schema:{anyOf:[...gt,{type:"array",description:"For an array path: the value of each path in order, null when it failed.",items:{anyOf:[...gt,{type:"null"}]}}]},project(e){let n=wt(e.content);if(e.script!==!0)return kt(n)??e.shown;let t=St(e.outcome);return M(t)&&t.kind==="list"?ht(t,e,n):bt(t,L(e.shown),n)??e.shown},failed(e){let n=M(e.outcome)?e.outcome.data:void 0;if(!(e.script!==!0||!M(n)||n.kind!=="list"))return ht(n,e,wt(e.content))},failureReason({outcome:e}){return!M(e)||!M(e.data)||e.data.kind!=="list"?void 0:(Array.isArray(e.errors)?e.errors:[]).flatMap(t=>M(t)&&typeof t.message=="string"?[t.message]:[]).join(`
3
+ `)||void 0}},Le={schema:xt,project:$e.project};function ht(e,n,t){let r=Array.isArray(e.items)?e.items:[],s=0;return r.map(a=>{let c=St(a);if(!M(c))return null;let d=Ut(c),g=t.slice(s,s+d);s+=d;let k=Pe(c),V=k===void 0?void 0:n.publish?.(a,k);return bt(c,V,g)??null})}i(ht,"listValue");function bt(e,n,t){if(!M(e))return;let r=kt(t);if(r!==void 0)return r;if(e.kind==="bytes"&&Array.isArray(e.bytes))return{bytes:Buffer.from(e.bytes.filter(zt)).toString("base64")};if(e.kind==="text"&&Array.isArray(e.entries))return{entries:e.entries.filter(a=>typeof a=="string")};let s=Pe(e);return s===void 0||n===void 0?void 0:{text:s,id:n}}i(bt,"sourceValue");function Pe(e){if(e.kind==="text")return typeof e.text=="string"?e.text:(Array.isArray(e.lines)?e.lines:[]).map(t=>M(t)&&typeof t.content=="string"&&typeof t.lineEnding=="string"?t.content+t.lineEnding:"").join("");if(e.kind==="native"&&Array.isArray(e.blocks))return e.blocks.flatMap(t=>M(t)&&typeof t.text=="string"?[t.text]:[]).join(`
4
+ `);if(e.kind==="resources"&&Array.isArray(e.resources))return e.resources.flatMap(t=>{let r=M(t)?Pe(t):void 0;return r===void 0?[]:[r]}).join(`
5
+ `)}i(Pe,"textOf");function Ut(e){return!M(e)||e.kind!=="native"||!Array.isArray(e.blocks)?0:e.blocks.filter(t=>M(t)&&t.type==="image").length}i(Ut,"imageCount");function wt(e){return e.filter(n=>n.type==="image").map(({data:n,mimeType:t})=>({type:"image",data:n,mimeType:t}))}i(wt,"imageBlocks");function kt(e){let[n]=e;if(n!==void 0)return e.length===1?{...n}:{type:"images",images:e.map(t=>({...t}))}}i(kt,"imageValue");function St(e){return M(e)&&e.status==="success"?e.data:void 0}i(St,"successData");function zt(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=255}i(zt,"isByte");function M(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(M,"record");var Vt=P;var At=be();var Ht={type:"object",properties:{output:{type:"string"},truncated:{type:"boolean"},full_output_path:{type:"string"},exit_code:{type:"number"},wall_time_seconds:{type:"number"},session:{type:"string"}},required:["output","truncated","full_output_path","wall_time_seconds","session"],additionalProperties:!1},de={schema:Ht,project:i(({outcome:e})=>Gt(e)??null,"project"),succeeded:i(({outcome:e})=>{let n=Rt(e);return n!==void 0&&!(n.status==="failed"&&n.exit_code===void 0)},"succeeded")};function Gt(e){let n=Rt(e);if(n!==void 0)return{output:Xt(n),truncated:n.truncated,full_output_path:n.full_output_path,...n.exit_code===void 0?{}:{exit_code:n.exit_code},wall_time_seconds:n.wall_time_seconds,session:n.source}}i(Gt,"terminalOutcome");function Xt({output:e,output_ranges:n}){let[t,r]=n;if(n.length!==2||t===void 0||r===void 0)return e;let s=Buffer.from(e,"utf8"),a=t.end-t.start,c=r.start-t.end;return`${s.subarray(0,a).toString("utf8")}
6
+
7
+ [... ${c} bytes omitted ...]
8
+
9
+ ${s.subarray(a).toString("utf8")}`}i(Xt,"markedOutput");function Rt(e){let n=Be(e)?e.data:void 0;if(!Be(n))return;let{output:t,truncated:r,full_output_path:s,output_ranges:a,exit_code:c}=n,{wall_time_seconds:d,source:g,status:k}=n;if(typeof t!="string"||typeof r!="boolean"||typeof s!="string"||!Array.isArray(a)||typeof d!="number"||typeof g!="string"||typeof k!="string"||c!==void 0&&typeof c!="number")return;let V=a.flatMap(B=>Be(B)&&typeof B.start=="number"&&typeof B.end=="number"?[{start:B.start,end:B.end}]:[]);return{output:t,truncated:r,full_output_path:s,output_ranges:V,...c===void 0?{}:{exit_code:c},wall_time_seconds:d,source:g,status:k}}i(Rt,"shellRecord");function Be(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(Be,"record");var jt={schema:{type:"string"},project:i(({shown:e})=>e,"project")};var It=P;var _t=P;var Qt={read:$e,outline:Le,diagnostics:Le,search:ke,ast_search:we,lsp_search:ft,file_search:ut,semantic_search:At,replace:Vt,insert:dt,delete:st,write:_t,copy:ot,move:mt,undo:It,diff:at,bash:de,powershell:de,remote_bash:de,remote_powershell:de};function Ne(e){return Qt[e]??jt}i(Ne,"scriptValueOf");function Ct(e){let n=e.schema.anyOf;return{anyOf:[...Array.isArray(n)?n:[e.schema],{type:"null"}]}}i(Ct,"nullableValueSchema");var Se=class{static{i(this,"CodemodeCallLedger")}#e=new Map;record(n,t,r){let s=this.#e.get(n)??{calls:new Map,failures:new Map};s.calls.set(t.id,t),r!==void 0&&s.failures.set(t.id,{...Mt(t),...r}),this.#e.set(n,s)}updateReason(n,t,r){let s=this.#e.get(n)?.failures,a=s?.get(t);a!==void 0&&s?.set(t,{...a,reason:r})}recordBatch(n,t){let r=this.#e.get(n);if(r!==void 0)for(let s of t){let a=r.calls.get(s.id);a===void 0||r.failures.has(s.id)||s.errors.length===0&&s.effect!=="unknown"||r.failures.set(s.id,{...Mt(a),reason:["The edit was accepted, then its editor batch failed when it was saved.",...s.errors.map(c=>c.message)].join(`
10
+ `),...s.changed===void 0?{}:{changed:s.changed},...s.unknown===void 0?{}:{unknown:s.unknown}})}}take(n){let t=this.#e.get(n);return this.#e.delete(n),t===void 0||t.failures.size===0?void 0:Yt(t.calls.size,[...t.calls.keys()].flatMap(r=>t.failures.get(r)??[]))}clear(){this.#e.clear()}};function Mt(e){return{tool:e.tool,...e.source===void 0?{}:{source:e.source}}}i(Mt,"identity");function Yt(e,n){let t=[`${n.length} of ${e} IDE call${e===1?"":"s"} failed:`];for(let r of n){t.push(`- ${r.tool}${r.source===void 0?"":` ${r.source}`}`);let s=[...r.changed?.length?[`Changed: ${r.changed.join(", ")}.`]:[],...r.unknown?.length?[`Effect unknown: ${r.unknown.join(", ")}.`]:[]];s.length>0&&t.push(` ${s.join(" ")} Do not repeat this edit blindly; Read the files first.`);for(let a of r.reason.split(`
11
+ `))t.push(a===""?"":` ${a}`)}return t.join(`
12
+ `)}i(Yt,"formatFailures");function Ve(e,n=t=>t){let t=Z(e)?e.data:void 0,r=Z(t)&&Array.isArray(t.files)?t.files:[],s=i(d=>r.flatMap(g=>Z(g)&&g.effect===d&&typeof g.source=="string"?[n(g.source)]:[]),"sources"),a=s("applied"),c=s("unknown");return{...a.length>0&&{changed:a},...c.length>0&&{unknown:c}}}i(Ve,"fileEffects");function Tt(e,n=t=>t){let t=Z(e)?e.editorBatchResults:void 0;return Array.isArray(t)?t.flatMap(r=>(Z(r)&&Z(r.data)&&Array.isArray(r.data.operations)?r.data.operations:[]).flatMap(a=>Z(a)&&typeof a.id=="string"&&typeof a.effect=="string"&&Array.isArray(a.errors)?[{id:a.id,effect:a.effect,errors:a.errors.flatMap(c=>Z(c)&&typeof c.message=="string"?[{message:c.message}]:[]),...Ve({data:{files:a.files}},n)}]:[])):[]}i(Tt,"batchOperations");function Z(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(Z,"record");function Et(e,n,t,r){if(!X(n)||n.status!=="success"||!X(n.data))return[];let s=n.data,a=X(t)&&X(t.metadata)?t.metadata:void 0,c=a&&X(a.semanticAction)?a.semanticAction:void 0;return e==="write"&&c?.kind==="direct-mutation"&&c.ok===!0&&c.effect==="applied"&&Array.isArray(c.files)?c.files.filter(d=>typeof d=="string").map(d=>`write ${r(d)}: saved`):e==="write"&&c===void 0&&X(t)&&t.effect==="not-applied"&&Array.isArray(t.results)?t.results.flatMap(d=>{let g=X(d)&&X(d.data)?d.data:void 0;return g?.ok===!0&&typeof g.path=="string"?[`write ${r(g.path)}: unchanged`]:[]}):s.effect!=="applied"?[]:e==="copy"||e==="move"?c?.kind!=="file-operation"||c.ok!==!0||c.effect!=="applied"||typeof c.path!="string"||typeof c.target!="string"?[]:[`${e} ${r(c.path)} \u2192 ${r(c.target)}: applied`]:e!=="write"||c!==void 0||!Array.isArray(s.files)?[]:s.files.flatMap(d=>X(d)&&d.effect==="applied"&&typeof d.source=="string"&&!/^(?:shell|debug):/u.test(d.source)?[`write ${r(d.source)}: saved`]:[])}i(Et,"fileReceipts");function X(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}i(X,"record");var $t=200,Zt=new Set(["write","replace","insert","delete","copy","move","undo","stage","unstage"]),Re={read:["path"],outline:["path"],search:["path"],ast_search:["path"],lsp_search:["path"],file_search:["path"],replace:["path"],insert:["path"],delete:["path"],write:["path"],copy:["path","target"],move:["path","target"],undo:["file"],diff:["before","after"]},en={bash:["command"],powershell:["command"],remote_bash:["command"],remote_powershell:["command"],debug:["program"],stage:["file"],unstage:["file"]};function Lt(e,n){let t=i(a=>{if(Array.isArray(a))return a.flatMap(t);let c=ce(a);if(c!==void 0)return t(c);if(a!==null&&typeof a=="object"&&"path"in a)return t(a.path);if(typeof a!="string"||a==="")return[];let d=L(a)??a.replaceAll(/\s+/gu," ");return[d.length>$t?`${d.slice(0,$t)}\u2026`:d]},"labels"),s=(en[e]??Re[e]??["path"]).map(a=>t(n[a]).join(", ")).filter(a=>a!=="");return s.length===0?void 0:s.join(" \u2192 ")}i(Lt,"sourceLabel");function Ae(e,n){let t=n.endsWith(Ot.sep)?n:n+Ot.sep;return e.startsWith(t)&&e.length>t.length?e.slice(t.length):e}i(Ae,"displayPath");async function tn(e,n){if(typeof e!="object"||e===null||!("editorBatches"in e)||!("editorBatchResults"in e))return;let{editorBatches:t,editorBatchResults:r,...s}=e,a=JSON.stringify({editorBatches:t,editorBatchResults:r});if(Buffer.byteLength(a)<=24*1024)return;let c=await n(a).catch(()=>{});return{...s,editorBatchReceipts:{truncated:!0,...c===void 0?{}:{fullOutput:c}}}}i(tn,"boundEditorBatchReceipts");function Dr(e,n={}){let t=Xe(e),r=Qe(e),s=new Set,a=new Map,c=new ze,d=i(o=>n.resourceOutput?c.save(o):c.saveFile(o),"saveFullOutput"),g=new Map,k=i(o=>Kt("sha256").update(JSON.stringify(o)).digest("hex"),"signature"),V=i(async(o,u)=>{let p=k(u),h=g.get(o);if(h&&(h.source===p||k(await h.content)===p))return h.content;let f=K(u,"",d).then(l=>[{type:"text",text:l.text+(l.notices.length?`
13
+
14
+ ${l.notices.join(`
15
+ `)}`:"")},...l.images]);return g.set(o,{source:p,content:f}),f},"limitError");Ze(e,{protocol:Ye,apiVersion:Ke,id:"ide-output-retention",setup(o){o.setOutputSaver(d),n.resourceOutput&&o.addResolver({priority:-1e3,resolver:{id:"ide-output-retention",async tryResolve(u,p){let h=await c.resolver.tryResolve(u,p);return h.kind==="failed"?{kind:"not-handled"}:h}}})}}),e.on("session_shutdown",()=>c.dispose());let B=i((o,u)=>{if(o==="message_end"){let h=u;return e.on("message_end",async(f,l)=>{let y=await h(f,l),m=y?.message??f.message;return m.role!=="toolResult"||!m.isError||!s.has(m.toolName)||m.content.some(b=>b.type==="text"&&b.text.startsWith("<system-result"))?y:{...y,message:{...m,content:await V(m.toolCallId,m.content)}}})}let p=u;return o!=="tool_call"?e.on(o,p):e.on("tool_call",async(h,f)=>{let l=s.has(h.toolName);if(l&&N.has(h.toolCallId))return;let y=await p(h,f);if(!y?.block||!l||y.terminate===!0)return y;let m=await K([{type:"text",text:y.reason??"Tool execution was blocked"}],"",d);N.set(h.toolCallId,{...N.get(h.toolCallId),reason:m.text+(m.notices.length?`
16
+
17
+ ${m.notices.join(`
18
+ `)}`:"")})})},"on"),N=new Map,W=new Map,F=new Se,Q=new Set,U=new Map,q=new Map,R=new Map,O=new Map,v=new Map,pe=i(()=>{N.clear(),W.clear(),F.clear(),Q.clear(),U.clear(),R.clear(),O.clear()},"clearCalls"),se=i(()=>{q.clear(),v.clear(),g.clear(),pe()},"clear");e.on("session_start",se),e.on("session_shutdown",se),e.on("agent_end",pe),e.on("before_agent_start",o=>{o.systemPromptOptions.sections[n.promptSection??"ide_results"]="Direct IDE calls return readable text; the system-result reference is not file content. Pass an unchanged result or its UUID to compose tools. Codemode calls return the inline value types. Text Read values hold exactly the requested text without notices; bytes are base64 and directory names end with /. Search match lists hold every found match with whole text and a one-based line; AST captures are keyed by metavariable name without $. An id selects its result, match or capture; pass that value or its RESULT# id to a source or selector parameter. A result selects only its returned ranges, not surrounding preview context. Sources without selections have no id. A false complete means incomplete coverage, so an empty list proves nothing. A broadened Search keeps the original matches empty and places hints in fallback; refine the query before editing them. LSP calls put references in matches and whole caller/callee declarations in incoming/outgoing. Diff is complete, or empty for equal sources. Edits return the id of verified output text or null when no text is selected; filesystem/text delete returns null. A failed IDE call normally resolves to null and the script continues; a multi-source Read keeps its array with null at failed sources, and a provider action keeps its receipt. Terminal exit_code is absent while running; a nonzero exit is a value, not a tool failure. Check the Codemode result's failed calls and effects before retrying. Pi can still reject invalid or blocked calls. Omit optional arguments rather than passing null. Store/load retains values in the session; references cannot be reused across sessions."}),e.on("tool_execution_start",o=>{o.parentToolCallId!==void 0&&q.set(o.toolCallId,q.get(o.parentToolCallId)??o.parentToolCallId)}),e.on("tool_execution_end",o=>{let u=U.get(o.toolCallId);U.delete(o.toolCallId);let p=o.result;if(u&&p!==null&&typeof p=="object"&&"content"in p&&Array.isArray(p.content)){let f=p.content.filter(l=>l!==null&&typeof l=="object"&&"type"in l&&l.type==="text"&&"text"in l&&typeof l.text=="string").map(l=>l.text).join(`
19
+ `).replace(le,"");if(f!==u.original){let l=u.original?f.indexOf(u.original):-1,y=l>=0&&l===f.lastIndexOf(u.original),m=u.filtered?y?f.slice(0,l)+u.reason+f.slice(l+u.original.length):u.reason:f;F.updateReason(u.parent,o.toolCallId,m)}}Q.delete(o.toolCallId)&&p!==null&&typeof p=="object"&&Object.assign(p,{structuredContent:null})}),B("tool_call",(o,u)=>{if(!s.has(o.toolName))return;let p=a.get(o.toolName)?.(),h=p?je(o.input,p,{cwd:u.cwd,sourceFields:[...Re[o.toolName]??[],"path"],resolveSource:i(l=>t.source(l,u.cwd,!0),"resolveSource")}):o.input;W.set(o.toolCallId,Lt(o.toolName,h));let f={...h};try{for(let l of Re[o.toolName]??[]){let y=f[l];if(y!==void 0)if(o.toolName==="diff"&&ce(y)===void 0&&y!==null&&typeof y=="object"&&"path"in y)f[l]={...y,path:t.source(y.path,u.cwd,!0)};else if(o.toolName==="read"){let m=i(b=>{let A=t.source(b,u.cwd,!0);if(Array.isArray(A)||typeof A=="string"&&A.startsWith("RESULT#")){let w=ce(b)??b;if(typeof w=="string"&&!w.startsWith("SEARCH#"))return L(w)??(w.startsWith("RESULT#")?w:`RESULT#${w}`)}if(!Array.isArray(A))return A;let j=t.resolve(A,u.cwd);return t.register(j.targets,u.cwd,j.complete)},"readSource");f[l]=Array.isArray(y)?y.map(m):m(y)}else f[l]=t.source(y,u.cwd,["write","insert","delete"].includes(o.toolName)?"live":!1)}for(let l of et(o.toolName))f[l]!==void 0&&(f[l]=Ge(t,f[l],u.cwd));for(let l of["text","content"]){let y=f[l];if(typeof y=="string"&&(y.trimStart().startsWith("<system-result")||/<system-result\b[^>]*><uuid>[a-f\d-]{36}<\/uuid><\/system-result>/iu.test(y)))return{block:!0,reason:"A system result reference is not file content. Do not insert it into a file."}}Object.assign(o.input,f)}catch(l){let y=l instanceof Error?l.message:String(l);return l instanceof He&&N.set(o.toolCallId,{reason:y,details:{code:l.code,effect:l.effect}}),{block:!0,reason:y}}});let z=i(o=>{s.add(o.name),a.set(o.name,()=>o.parameters);let u={},p=Object.getOwnPropertyDescriptors(o),h=i(m=>{tt(e.events,m);let b=je(m,o.parameters);return o.prepareArguments?o.prepareArguments(b):b},"prepareArguments");p.prepareArguments={value:h,enumerable:!0,configurable:!0,writable:!0},p.outputSchema={value:Ct(Ne(o.name)),enumerable:!0,configurable:!0,writable:!0};let f=i(async(...m)=>{let b=N.get(m[0]);if(b!==void 0)return N.delete(m[0]),{content:[{type:"text",text:b.reason}],details:b.details??{},isError:!0};let A=!(["read","outline"].includes(o.name)&&q.has(m[0])),j=i(async te=>{let C=await o.execute(m[0],m[1],te,m[3],m[4]).catch(async D=>{let ne=await K([{type:"text",text:D instanceof Error?D.message:String(D)}],"",d);throw ne.notices.length===0?D:new Error(ne.text+`
20
+
21
+ ${ne.notices.join(`
22
+ `)}`,{cause:D})}),Y=C.structuredContent,$=typeof Y=="object"&&Y!==null&&"data"in Y?Y.data:void 0;typeof $=="object"&&$!==null&&"effect"in $&&($.effect==="applied"||$.effect==="unknown"||$.effect==="not-applied")&&De($.effect);let T=await K(C.content,Pt(C.details),d,{limitText:A}),ie={type:"text",text:T.text+T.metadataSuffix+(T.notices.length?`
23
+
24
+ ${T.notices.join(`
25
+ `)}`:"")};return{...C,content:[T.textTruncated?ie:Ie(C.content,ie),...T.images]}},"run"),w=ve(o.name);if(w===void 0)return j(m[2]);let J=W.get(m[0])??Lt(o.name,m[1])??m[4].cwd;return await Ue(o.name,J,w,m[2],Zt.has(o.name)||o.annotations?.readOnlyHint===!1?"unknown":void 0,j)},"execute");p.execute={value:f,enumerable:!0,configurable:!0,writable:!0};let l=o.renderCall;if(l){let m=i((b,A,j)=>l(nn(o.name,b),A,j),"renderCall");p.renderCall={value:m,enumerable:!0,configurable:!0,writable:!0}}let y=o.renderResult;if(y){let m=i((b,A,j,w)=>y({...b,content:b.content.map(J=>J.type==="text"?{...J,text:J.text.replace(le,"")}:J)},A,j,w),"renderer");p.renderResult={value:m,enumerable:!0,configurable:!0,writable:!0}}Object.defineProperties(u,p),e.registerTool(u)},"registerTool"),ee=i(()=>{e.on("context",async o=>({messages:await Promise.all(o.messages.map(async u=>u.role!=="toolResult"||!u.isError||!s.has(u.toolName)||u.content.some(p=>p.type==="text"&&p.text.startsWith("<system-result"))?u:{...u,content:await V(u.toolCallId,u.content)}))})),e.on("tool_result",async(o,u)=>{if(o.toolName==="codemode"){t.refreshAll();let S=new Set(o.content.flatMap(_=>_.type==="image"?[_.data]:[])),I=(v.get(o.toolCallId)??[]).filter(_=>!S.has(_.data));v.delete(o.toolCallId);for(let[_,Bt]of q)Bt===o.toolCallId&&q.delete(_);let H=o.content.filter(_=>_.type==="text"&&_.text.startsWith(`
26
+
27
+ ---
28
+
29
+ # Guide:`));F.recordBatch(o.toolCallId,Tt(o.details,_=>Ae(_,u.cwd)));let re=F.take(o.toolCallId),Je=await tn(o.details,d),fe=R.get(o.toolCallId)??[];R.delete(o.toolCallId);let We=O.get(o.toolCallId)??[];O.delete(o.toolCallId);let Fe=o.content.filter(_=>!H.includes(_)),me=We.length?await K([{type:"text",text:We.join(`
30
+ `)}],"",d):void 0,ae=await K([...Fe,...I,...fe.length?[{type:"text",text:`
31
+
32
+ ${fe.join(`
33
+ `)}`}]:[]],"",d),ye=re===void 0?void 0:await K([{type:"text",text:re}],"",d);return{...Je===void 0?{}:{details:Je},content:[...ae.textTruncated?[{type:"text",text:ae.text}]:[...Fe.filter(_=>_.type==="text"),...fe.length?[{type:"text",text:`
34
+
35
+ ${fe.join(`
36
+ `)}`}]:[]],...ae.images,...ae.notices.length?[{type:"text",text:`
37
+
38
+ ${ae.notices.join(`
39
+ `)}`}]:[],...H,...me===void 0?[]:[{type:"text",text:`
40
+
41
+ ${me.text}${me.notices.length?`
42
+
43
+ ${me.notices.join(`
44
+ `)}`:""}`}],...ye===void 0?[]:[{type:"text",text:`
45
+
46
+ ${ye.text}${ye.notices.length?`
47
+
48
+ ${ye.notices.join(`
49
+ `)}`:""}`}]]}}if(!s.has(o.toolName))return;let p=o.content.filter(S=>S.type==="text").map(S=>S.text).join(`
50
+ `),h=o.structuredContent,f=h!==null&&typeof h=="object"&&"data"in h?h:{status:o.isError?"error":"success",data:h},l=f.data,y=l!==null&&typeof l=="object"&&"effect"in l&&l.effect==="applied"&&"targetUnavailable"in l&&typeof l.targetUnavailable=="string"?l.targetUnavailable:void 0,m=y===void 0||p.includes(y)?p:`${p}
51
+
52
+ This result has no verified text selection: ${y}
53
+ Read/Search the file before the next edit; do not repeat the applied edit.`,b=qe(f),A=o.isError||f.status==="error"||f.status==="partial",j=t.publish(f,m,u.cwd,b);r.keep(j,u.cwd,o.toolName==="read"&&!A?o.content.filter(S=>S.type==="image"):[]);let w=q.get(o.toolCallId);q.delete(o.toolCallId);let J={shown:j,outcome:f,content:o.content,details:o.details,cwd:u.cwd,script:w!==void 0,publish:i((S,I)=>L(t.publish(S,I,u.cwd,qe(S))),"publish")},te=Ne(o.toolName),C,Y,$;try{C=A&&te.succeeded?.(J)!==!0,Y=C?te.failed?.(J):te.project(J),C&&w!==void 0&&($=te.failureReason?.(J))}catch(S){let I=W.get(o.toolCallId);if(W.delete(o.toolCallId),w===void 0)return;let H=S instanceof Error?S.message:String(S);return F.record(w,{id:o.toolCallId,tool:o.toolName,...I===void 0?{}:{source:I}},{reason:H,...Ve(f,re=>Ae(re,u.cwd))}),Q.add(o.toolCallId),{content:[{type:"text",text:H}]}}let T=Y===j?void 0:Y,ie=W.get(o.toolCallId);W.delete(o.toolCallId);let D=m.replace(le,"");if(w!==void 0){if(!C){let I=Et(o.toolName,f,o.details,H=>Ae(H,u.cwd));I.length&&O.set(w,[...O.get(w)??[],...I])}if(o.toolName==="search"&&!C&&l!==null&&typeof l=="object"){let I="notices"in l&&Array.isArray(l.notices)?l.notices.filter(re=>typeof re=="string"):[],H="editWarning"in l&&typeof l.editWarning=="string"?[l.editWarning]:[];R.set(w,[...new Set([...R.get(w)??[],...I,...H])])}let S=o.content.filter(I=>I.type==="image");S.length&&v.set(w,[...v.get(w)??[],...S]),F.record(w,{id:o.toolCallId,tool:o.toolName,...ie===void 0?{}:{source:ie}},C?{reason:$??D,...Ve(f,I=>Ae(I,u.cwd))}:void 0),C&&U.set(o.toolCallId,{parent:w,original:D,reason:$??D,filtered:$!==void 0}),(T===null||C&&T===void 0)&&Q.add(o.toolCallId)}let ne={type:"text",text:A?D:j};return{content:[w===void 0&&!A?Ie(o.content,ne):ne,...o.content.filter(S=>S.type!=="text")],...T!=null&&(w!==void 0||T!==L(j))&&{structuredContent:T}}})},"finalize");return{api:{...e,on:B,registerTool:z},finalize:ee}}i(Dr,"createIdeTextResults");function Pt(e){if(e===null||typeof e!="object")return[];let n="outputNotice"in e&&typeof e.outputNotice=="string"?[e.outputNotice]:[];if("resources"in e&&Array.isArray(e.resources)){let t=e.resources;for(let r of t)r!==null&&typeof r=="object"&&"details"in r&&n.push(...Pt(r.details))}return n}i(Pt,"outputNotices");function nn(e,n){let t=i(s=>{if(Array.isArray(s))return s.map(t);let a=ce(s);return a!==void 0?a:s!==null&&typeof s=="object"&&"path"in s?{...s,path:t(s.path)}:typeof s!="string"?s:L(s)??s},"label"),r={...n};for(let s of Re[e]??[])n[s]!==void 0&&Object.assign(r,{[s]:t(n[s])});return r}i(nn,"displaySources");function qe(e){if(e===null||typeof e!="object"||!("data"in e))return[];let n=e.data;return n===null||typeof n!="object"?[]:"resources"in n&&Array.isArray(n.resources)?n.resources.flatMap(r=>qe({data:r})):"files"in n&&Array.isArray(n.files)?n.files.flatMap(r=>r!==null&&typeof r=="object"&&"source"in r&&typeof r.source=="string"&&/^(?:shell|debug):/u.test(r.source)?[r.source]:[]):"source"in n&&typeof n.source=="string"?[n.source]:[]}i(qe,"resultResources");export{Dr as a};
@@ -0,0 +1 @@
1
+ import{a as f,m as l,q as m,r as d,u as h,v as g}from"./chunk-IRLWXPL4.js";import{a}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";var R=8,u=class e extends f{constructor(n,t,i){super(n,t);this.origin=i}static{s(this,"LineHashTextAnchor")}rangeRejection(n,t){if(!(n instanceof e)||this.origin===void 0)return;let{source:i,history:o}=this.origin,c=o.check(i,this.value,n.value,t);if(c!=="unchanged")return{code:"STALE_ANCHOR_RANGE",reason:c==="changed"?"The text between these line anchors changed since they were shown. Read the range and select it with exact text or a result reference for the whole span.":"No retained source window verifies this pair of line anchors. Read both endpoints together, or use exact text or a result reference for the whole span."}}};function y(e){let r=m.exec(e)?.[1];if(r!==void 0)return r;let n=/[\r\n]/u.test(e)?e:e.trim();return d(n)?n:e}s(y,"normalizeLineHashAnchor");function p(e){return h(e.source,e.content)}s(p,"currentAnchors");function v(e,r){return new u(T(e,r),r)}s(v,"createLineHashAnchor");function T(e,r){return a(h("content",e)[r-1])}s(T,"formatLineHashAnchor");function w(e,r=1,n){let t=l("content",e).lines,i=h("content",e),o=Math.max(1,r),c=Math.min(t.length,n??t.length);return t.slice(o-1,Math.max(o-1,c)).map((A,x)=>`${a(i[o+x-1])}|${A.content}`)}s(w,"renderLineHashLines");function k(e){return{id:"line-hash",description:"Use the complete 7-character anchor printed before a source line, for example `K7M2QX4`. It names the line by its content, so it stays valid while other lines change.",normalize:y,renderFull(r){return r},renderCompact(r,n){return`line ${n.anchor.lineNumber}`},tryResolve(r,n){return Promise.resolve(H(r,n,e))},recover(r,n){if(n.rejection.code!=="ambiguous")return Promise.resolve({kind:"unavailable"});let t=l(n.source,n.content).lines,i=g(p(n),r);return Promise.resolve({kind:"candidates",total:i.length,candidates:i.slice(0,R).map((o,c)=>({rank:c+1,range:{start:{lineNumber:o,column:0},end:{lineNumber:o,column:a(t[o-1]).content.length}}}))})}}}s(k,"createLineHashAnchorResolver");function H(e,r,n){if(!d(e))return{kind:"not-handled"};let t=g(p(r),e);return t.length===1?{kind:"resolved",anchor:new u(e,a(t[0]),n===void 0?void 0:{source:r.source,history:n})}:t.length===0?{kind:"rejected",rejection:{code:"stale",reason:`no line of the current file has anchor "${e}"; read or search again for current anchors. To select these bytes literally, use a Search result or longer exact text`}}:{kind:"rejected",rejection:{code:"ambiguous",reason:`anchor "${e}" names ${t.length} lines`}}}s(H,"resolveLineHashAnchor");export{v as a,T as b,w as c,k as d};
@@ -0,0 +1 @@
1
+ import{b as x}from"./chunk-VPBGKSFI.js";import{a as y,b as a,j as m}from"./chunk-S4GTWS2J.js";import{q as w}from"./chunk-OA26FH5G.js";import{a as p}from"./chunk-EI7MMDWY.js";import f from"node:path";async function C(e,c,t,T,h,n){n?.throwIfAborted();let r=a(e.target.id,c).path;if(t&&v(t,r))return{cwd:a(e.target.id,t).source,external:!1};let d=!1;try{d=(await e.stat(r,{signal:n})).kind==="directory"}catch(o){if(!(o instanceof m)||o.code!=="ENOENT")throw o}let g=d?h:h.filter(o=>w(o,r)),E=t===void 0&&v(e.target.workspace,r)?e.target.workspace:void 0,i=d?r:f.posix.dirname(r);for(;;){n?.throwIfAborted();let o=f.posix.join(i,".pi","pi-agent-ide",`${T}.json`),l=!1;try{await e.stat(o,{signal:n}),l=!0}catch(s){if(!(s instanceof m)||s.code!=="ENOENT")throw s}let N=!l&&g.length>0?[...(await x(e,i,g,n)).values()].some(s=>s.score>0):!1;if(l||N||i===E)return{cwd:a(e.target.id,i).source,external:t!==void 0};let u=y(i);if(u===void 0)return;i=u}}p(C,"resolveSshToolProject");function v(e,c){let t=f.posix.relative(e,c);return t===""||t!==".."&&!t.startsWith("../")&&!f.posix.isAbsolute(t)}p(v,"inside");export{C as a};
@@ -0,0 +1,9 @@
1
+ import{b as O,d as be,e as Te,f as Oe,g as Pe,h as Ie,j as l,k as Ae,l as Ne,m as Ce}from"./chunk-S4GTWS2J.js";import{c as Se}from"./chunk-XHFAV2NI.js";import"./chunk-NNCZYO4Q.js";import{a as me}from"./chunk-47SPPIXK.js";import{a as we,b as he}from"./chunk-VAXLSPPU.js";import{f as ye,g as Ee}from"./chunk-KN6VPARZ.js";import{d as pe}from"./chunk-IZTOXSTR.js";import{a as ge}from"./chunk-JY63UUC2.js";import{a as se}from"./chunk-I3G6K7QU.js";import{a as ie,b as ae}from"./chunk-HSAGZWPO.js";import"./chunk-PS2B6THP.js";import{a as de,c as le,d as fe,e as ue}from"./chunk-XEPCURYZ.js";import{ba as K}from"./chunk-OEEE5BLN.js";import"./chunk-2QCE7GOV.js";import{y as ce}from"./chunk-IRLWXPL4.js";import"./chunk-ZC65Z3CK.js";import{a as ke}from"./chunk-ZAWRSA7N.js";import{a as Re,b as ve}from"./chunk-OFILFO6D.js";import{a as c}from"./chunk-EI7MMDWY.js";import _e from"node:path";import{StringDecoder as Ye}from"node:string_decoder";function xe(e,a,s){let n=e==="ast-grep"?"npm install --global @ast-grep/cli":e==="rg"?s?"winget install BurntSushi.ripgrep.MSVC":"install the `ripgrep` package":void 0,d=n===void 0?"":` Install it, for example: ${n}.`;return`${e} is not installed on SSH target ${a}, or is not on the PATH of its SSH sessions.${d} Then start a new search.`}c(xe,"missingToolMessage");function Fe(e){return(a,s)=>{let n=e.resolve(a.path??".",s.cwd);if(n===void 0)return;let{backend:d,location:y}=n,t=d.target.os==="windows",o=c(async(i,p,f,R)=>{if(R?.throwIfAborted(),!(i instanceof l)||i.code!=="ENOENT")return i;let u=!1;try{u=(await d.stat(f,{signal:R})).kind==="directory"}catch{}return R?.throwIfAborted(),u?new Error(xe(p,d.target.id,t),{cause:i}):i},"explainMissing"),r=c((i,p=y.source)=>{let f=e.resolve(i,p);if(f===void 0||f.backend!==d)throw new l("UNSUPPORTED_SOURCE",i,"not-applied");return f.location},"own");return{resolve:c((i,p)=>r(p,i.includes("://")?i:y.source).source,"resolve"),dirname:c(i=>O(y.target,_e.posix.dirname(r(i).path)).source,"dirname"),basename:c(i=>_e.posix.basename(r(i).path),"basename"),isDirectory:c(async(i,p)=>(await d.stat(r(i).path,{signal:p})).kind==="directory","isDirectory"),byteSize:c(async(i,p)=>(await d.stat(r(i).path,{signal:p})).size,"byteSize"),readText:c(async(i,p)=>(await d.read(r(i).path,{signal:p})).bytes.toString("utf8"),"readText"),async execute(i,p,f,R){let u=r(f).path,m;try{m=await d.execute(i,p,u,{signal:R})}catch(h){throw await o(h,i,u,R)}return{code:m.exitCode,stdout:m.stdout.toString("utf8"),stderr:m.stderr.toString("utf8")}},async runLines(i,p,f,R){let u=r(p).path,m;try{let b=t?["--path-separator=/"]:[];m=await d.startProcess("rg",[...b,...i],u,{signal:R})}catch(b){throw await o(b,"rg",u,R)}let h=new Ye("utf8"),w=[],E=0,g="",I,B=c(b=>{let T=b.split(`
2
+ `);for(let[C,A]of T.entries()){if(w.push(A),E+=Buffer.byteLength(A),E>32*1024*1024)throw new l("CONTENT_LIMIT",y.source,"not-applied");C<T.length-1&&(f(w.join("")),w.length=0,E=0)}},"consume"),L=(async()=>{try{for await(let b of m.stdout)B(h.write(b));B(h.end()),E>0&&f(w.join(""))}catch(b){I=b,await m.stop()}})(),N=(async()=>{for await(let b of m.stderr)g+=b.toString("utf8"),g.length>65536&&(g=g.slice(-65536))})();try{try{await m.end()}catch(T){if(!(T instanceof l)||T.code!=="INPUT_CLOSED")throw T}let b=await m.completion;if(await Promise.all([L,N]),I!==void 0)throw I instanceof Error?I:new Error("Search output failed.",{cause:I});return R?.throwIfAborted(),{code:b.exitCode,stderr:g}}catch(b){throw R?.throwIfAborted(),b}finally{try{await m.stop()}finally{await Promise.allSettled([L,N])}}}}}}c(Fe,"createSshSearchEnvironmentProvider");import{lstat as rt,mkdir as Ue,rm as nt,symlink as ot,unlink as it,open as at}from"node:fs/promises";import F from"node:path";import{constants as X}from"node:fs";import{createHash as ze,randomBytes as Ke}from"node:crypto";import{constants as Le}from"node:fs";import{lstat as We,mkdir as Je,open as De,rename as Qe,rm as Xe,unlink as qe}from"node:fs/promises";import $ from"node:path";import{fileURLToPath as Ze}from"node:url";function P(e,a,s){if(s?.has(e)&&s.get(e)!==a)throw new l("CONFLICT",e,"not-applied")}c(P,"checkCapturedRevision");var et=1024*1024,Be=3e4,J=class extends l{constructor(s,n,d,y,t,o,r){super(s,n,y,r);this.target=d;this.transferredBytes=t;this.totalBytes=o;let i=s==="TRANSFER_STALLED"?`no data moved for ${Be/1e3} s; `:"",p=y==="not-applied"?"the target file was not changed":"the target file may have changed, check it before retrying";this.message=`${s}: ${n} to ${d}: ${i}wrote ${t} of ${o} bytes before the failure; ${p}`}static{c(this,"SshTransferError")}};function V(e,a){if(e.startsWith("file:"))try{return Ze(e)}catch{throw new l("UNSUPPORTED_SOURCE",e,"not-applied")}if(/^[a-z][a-z\d+.-]*:/iu.test(e)&&!/^[a-z]:[\\/]/iu.test(e))throw new l("UNSUPPORTED_SOURCE",e,"not-applied");if(a.startsWith("ssh://"))throw new l("UNSUPPORTED_SOURCE",e,"not-applied");return $.resolve(a,e)}c(V,"localTransferSource");function D(e){return[e.dev,e.ino,e.mode,e.uid,e.gid,e.size,e.mtimeNs,e.ctimeNs].join(":")}c(D,"localRevision");async function G(e){let a=await We(e,{bigint:!0});if(!a.isFile()||a.isSymbolicLink())throw new l("INVALID_FILE_TYPE",e,"not-applied");if(a.size>BigInt(Number.MAX_SAFE_INTEGER))throw new l("CONTENT_LIMIT",e,"not-applied");return a}c(G,"localEntry");function je(e){return e!==null&&typeof e=="object"&&"code"in e&&e.code==="ENOENT"}c(je,"missing");function W(e){return e!==null&&typeof e=="object"&&"code"in e&&typeof e.code=="string"&&/^[A-Z][A-Z0-9_]*$/u.test(e.code)?e.code:"TRANSFER_FAILED"}c(W,"errorCode");async function tt(e,a,s,n){s.signal?.throwIfAborted();let d=e.resolve(a.path,s.cwd),y=e.resolve(a.target??"",s.cwd),t=d?.location.source??V(a.path,s.cwd),o=y?.location.source??V(a.target??"",s.cwd);if(t===o)throw new l("SAME_FILE",t,"not-applied");let r=(y?y.backend.lstat(y.location.path,s):G(o)).then(w=>({info:w}),w=>({error:w})),i=d?await d.backend.lstat(d.location.path,s):await G(t);if("kind"in i&&i.kind!=="file")throw new l("INVALID_FILE_TYPE",t,"not-applied");let p=Number(i.size),f="kind"in i?i.mode:de(i),R="revision"in i?i.revision:D(i);P(t,R,n);let u=await r;if("error"in u&&!je(u.error))throw u.error;let m="info"in u?u.info:void 0;if(m!==void 0){if("kind"in m&&m.kind!=="file")throw new l("INVALID_FILE_TYPE",o,"not-applied");if(P(o,"revision"in m?m.revision:D(m),n),d&&y&&d.backend.target.host===y.backend.target.host&&d.backend.target.configFile===y.backend.target.configFile&&"identity"in i&&"identity"in m&&i.identity.device===m.identity.device&&i.identity.inode===m.identity.inode)throw new l("SAME_FILE",t,"not-applied")}let h=m===void 0?null:"revision"in m?m.revision:D(m);return m===void 0&&P(o,null,n),{source:t,target:o,remoteSource:d,remoteTarget:y,size:p,mode:f,sourceRevision:R,targetRevision:h}}c(tt,"prepareTransfer");async function j(e){for(let a of await Promise.allSettled(e))if(a.status==="rejected")throw a.reason}c(j,"settleInOrder");async function Q(e,a,s,n,d,y){let t=tt(e,s,n,d);await j([t,y?.()??Promise.resolve()]);let{source:o,target:r,remoteSource:i,remoteTarget:p,size:f,mode:R,sourceRevision:u,targetRevision:m}=await t,h=i?void 0:await De(o,Le.O_RDONLY|Le.O_NOFOLLOW),w,E,g,I=!1,B=!1,L=!1,N=0,b="",T=new AbortController,C,A=c(()=>{clearTimeout(C),C=setTimeout(()=>T.abort(),Be)},"progress"),ee=n.signal?AbortSignal.any([n.signal,T.signal]):T.signal,te=c(()=>{if(n.signal?.throwIfAborted(),T.signal.aborted)throw new l("TRANSFER_STALLED",o,"not-applied")},"throwIfStopped"),re=c(async()=>{let k=i?await i.backend.lstat(i.location.path,n):await G(o);if(("revision"in k?k.revision:D(k))!==u)throw new l("CONFLICT",o,"not-applied")},"verifySource"),x=ze("sha256"),H,ne=c(async()=>{let k=H;H=void 0,await k},"settle"),oe=c(async k=>{if(te(),x.update(k),g){let S=g.write(k).then(()=>{N+=k.length,A()});S.catch(()=>{});let v=H;H=S,await v;return}if(E===void 0)throw new Error("Missing destination descriptor");for(let S=0;S<k.length;){let v=await E.write(k,S,k.length-S);if(v.bytesWritten===0)throw new l("TRANSFER_FAILED",r,"not-applied");S+=v.bytesWritten}N+=k.length,A()},"deliver");try{if(h&&D(await h.stat({bigint:!0}))!==u)throw new l("CONFLICT",o,"not-applied");if(I=!0,A(),p?(g=await Ie(p.backend.target,Oe(await Pe(be(p.backend.target))),[JSON.stringify({destination:p.location.path,size:f,mode:R,expected:m})],Te(p.backend.target),{...n,signal:ee,gracefulStop:!0}),g.completion.catch(()=>{}),g.stdout.on("data",S=>{b.length<=8192&&(b+=S.toString("utf8")),b.length>8192&&g?.stop().catch(()=>{})}),g.stderr.resume()):(await Je($.dirname(r),{recursive:!0}),w=$.join($.dirname(r),`.pi-ide-transfer-${Ke(12).toString("hex")}`),E=await De(w,"wx",R&4095)),A(),i){let S=await i.backend.readStream(i.location.path,u,oe,{...n,signal:ee});if(await ne(),S.totalBytes!==f||N!==f)throw new l("CONFLICT",o,"not-applied");if(S.sha256!==x.copy().digest("hex"))throw new l("CHECKSUM_MISMATCH",o,"not-applied")}else{if(h===void 0)throw new Error("Missing source descriptor");for(let S=0;S<f;){let v=Math.min(et,f-S),U=Buffer.allocUnsafe(v),{bytesRead:z}=await h.read(U,0,v,S);if(z===0)throw new l("CONFLICT",o,"not-applied");await oe(U.subarray(0,z)),S+=z}await ne()}clearTimeout(C),await re(),await y?.();let k=x.digest("hex");if(te(),g){if(B=!0,A(),await g.write(Buffer.from(`${JSON.stringify({sha256:k})}
3
+ `)),await g.end(),(await g.completion).exitCode!==0||b.length>8192)throw new l("TRANSFER_FAILED",r,"unknown");let v;try{v=JSON.parse(b)}catch{throw new l("INVALID_REPLY",r,"unknown")}if(v===null||typeof v!="object"||!("ok"in v))throw new l("INVALID_REPLY",r,"unknown");if(v.ok!==!0){let U="effect"in v&&(v.effect==="not-applied"||v.effect==="applied")?v.effect:"unknown";throw new l(W(v),r,U)}if(!("sha256"in v)||v.sha256!==k)throw new l("CHECKSUM_MISMATCH",r,"unknown");L=!0}else{if(E===void 0||w===void 0)throw new Error("Missing staged destination");await E.chmod(R&4095),await E.sync(),await E.close(),E=void 0;let S=null;try{S=D(await G(r))}catch(v){if(!je(v))throw v}if(S!==m)throw new l("CONFLICT",r,"not-applied");n.signal?.throwIfAborted(),await Qe(w,r),w=void 0,L=!0}return clearTimeout(C),a==="move"&&(await re(),i?await i.backend.removeEntry(i.location.path,u,n):await qe(o)),{source:o,target:r}}catch(k){if(L)throw new l(W(k),o,"unknown");if(!I)throw k;let S=n.signal?.aborted?"CANCELLED":T.signal.aborted?"TRANSFER_STALLED":W(k),v=B?k instanceof l?k.effect:"unknown":"not-applied";throw new J(S,o,r,v,N,f,k instanceof l?{cause:k}:void 0)}finally{clearTimeout(C),await h?.close(),await E?.close(),w!==void 0&&await Xe(w,{force:!0}),g&&await g.stop().catch(()=>{})}}c(Q,"transferFile");var st=/[<>:"\\|?*\u0000-\u001f]|[. ]$|^(?:con|prn|aux|nul|com\d|lpt\d)(?:\..*)?$/iu;function Me(e,a,s){let n=e.resolve(a,s.cwd);if(n===void 0){let t=V(a,s.cwd);return{path:t,source:t,cwd:s.cwd,files:le}}let d=e.resolve(s.cwd,s.cwd),y=d?.location.target===n.location.target?d.location.path:n.backend.target.workspace;return{remote:n,source:n.location.source,path:n.location.path,cwd:y,windows:n.backend.target.os==="windows",files:{...n.backend.target.os==="windows"&&{caseInsensitive:!0},owner:JSON.stringify([n.backend.target.host,n.backend.target.configFile??null]),realpath:c(t=>n.backend.realpath(t,s),"realpath"),inspect:c(t=>n.backend.lstat(t,s),"inspect"),read:c(async t=>(await n.backend.read(t,s)).bytes.toString("utf8"),"read"),git:c((t,o,r)=>n.backend.queryGit(t,o,{...s,signal:r}),"git"),source:c(t=>O(n.location.target,t).source,"source"),snapshot:c((t,o)=>n.backend.objectSnapshot(t,{...s,signal:o}),"snapshot")}}}c(Me,"endpoint");function M(e,a,s){let n=e.remote?F.posix:F;if(n.sep==="\\"&&s.split("/").some(d=>d.includes("\\")||d.includes(":")))throw new l("INVALID_TARGET",e.source,"not-applied");if(e.windows===!0&&s.split("/").some(d=>st.test(d)))throw new l("INVALID_TARGET",e.source,"not-applied");return n.join(a,...s.split("/"))}c(M,"leaf");function q(e,a){return e.remote?O(e.remote.location.target,a).source:a}c(q,"receiptPath");async function _(e,a,s){let n;try{n=await e.files.inspect(a)}catch(d){if(d!==null&&typeof d=="object"&&"code"in d&&d.code==="ENOENT"){if(s===void 0)return}else throw d}if(s===void 0||n?.revision!==s.revision)throw new l("TRANSFER_TARGET_CHANGED",q(e,a),"not-applied")}c(_,"checkEntry");async function Y(e){let a;try{a=await rt(e)}catch(s){if(s===null||typeof s!="object"||!("code"in s)||s.code!=="ENOENT")throw s;await Y(F.dirname(e)),await Ue(e);return}if(!a.isDirectory()||a.isSymbolicLink())throw new l("INVALID_FILE_TYPE",e,"not-applied");F.dirname(e)!==e&&await Y(F.dirname(e))}c(Y,"directoryParents");async function He(e,a,s,n){e.remote?await e.remote.backend.removeObject(a,s.revision,n):(await _(e,a,s),s.kind==="directory"?await nt(a,{recursive:!0,force:!1}):await it(a))}c(He,"remove");async function $e(e,a,s,n,d,y){let t=Me(e,s.path,n),o=Me(e,s.target??"",n),r=await d.prepareTransfer(a,t,o),i=r.source.entries[0];if(i===void 0)throw new l("ENOENT",t.source,"not-applied");t.remote&&P(t.source,i.revision,y),o.remote&&P(o.source,r.target.entries[0]?.revision??null,y);let p=!1;try{n.signal?.throwIfAborted();for(let f of r.source.entries)M(t,r.source.path,f.relativePath),M(o,r.target.path,f.relativePath);if(r.sourceKind==="file")t.remote&&o.remote&&t.remote.location.target===o.remote.location.target?await t.remote.backend[a](r.source.path,r.target.path,i.revision,r.target.entries[0]?.revision??null,n):await Q(e,a,s,n,y,()=>j([_(t,r.source.path,i),_(o,r.target.path,r.target.entries[0])]));else{if(a==="move"&&t.remote&&o.remote&&t.files.owner===o.files.owner&&await t.remote.backend.moveObject(r.source,r.target,n))return{kind:"file-operation",operation:a,ok:!0,effect:"applied",path:t.source,target:o.source,sourceKind:r.sourceKind};let f=new Map(r.target.entries.map(u=>[u.relativePath,u])),R=new Map;a==="move"&&r.target.entries[0]&&(p=!0,await He(o,r.target.path,r.target.entries[0],n),f.clear());for(let u of r.source.entries){n.signal?.throwIfAborted();let m=M(t,r.source.path,u.relativePath),h=M(o,r.target.path,u.relativePath),w=f.get(u.relativePath);if(await j([_(t,m,u),_(o,h,w)]),u.kind==="directory"){w===void 0&&(p=!0);let E;o.remote?E=await o.remote.backend.ensureObjectDirectory(h,u.mode|448,w?.revision??null,n):w===void 0&&(await Y(F.dirname(h)),await Ue(h,{mode:u.mode|448}),E=(await o.files.inspect(h)).identity),w===void 0&&E!==void 0&&R.set(u.relativePath,E)}else if(u.kind==="symlink"){if(p=!0,u.link===void 0)throw new l("INVALID_RESPONSE",t.source,"unknown");o.remote?await o.remote.backend.createObjectLink(h,u.link,n):(await Y(F.dirname(h)),await ot(Buffer.from(u.link,"base64"),h))}else{p=!0;let E=q(t,m),g=q(o,h);t.remote&&o.remote&&t.files.owner===o.files.owner?await t.remote.backend.copy(m,h,u.revision,w?.revision??null,n):await Q(e,"copy",{path:E,target:g},n,void 0,()=>j([_(t,m,u),_(o,h,w)]))}}for(let u of[...r.source.entries].reverse()){if(u.kind!=="directory"||f.has(u.relativePath))continue;let m=M(o,r.target.path,u.relativePath),h=await o.files.inspect(m),w=R.get(u.relativePath);if(h.kind!=="directory"||w?.device!==h.identity.device||w.inode!==h.identity.inode)throw new l("TRANSFER_TARGET_CHANGED",o.source,"unknown");if(o.remote)await o.remote.backend.setObjectMode(m,u.mode,h.revision,n);else{let E=await at(m,X.O_RDONLY|X.O_DIRECTORY|X.O_NOFOLLOW);try{let g=await E.stat();if(String(g.dev)!==w.device||String(g.ino)!==w.inode)throw new l("TRANSFER_TARGET_CHANGED",o.source,"unknown");process.platform!=="win32"&&await E.chmod(u.mode&4095)}finally{await E.close()}}}await r.verifySource(),a==="move"&&await He(t,r.source.path,i,n)}return{kind:"file-operation",operation:a,ok:!0,effect:"applied",path:t.source,target:o.source,sourceKind:r.sourceKind}}catch(f){throw p?Object.assign(f instanceof Error?f:new Error(String(f)),{effect:"unknown"}):f}}c($e,"transferObject");function Ve(e,a){return async(s,n,d,y)=>{let t=e.resolve(n.path,d.cwd);if(t===void 0&&(n.target===void 0||e.resolve(n.target,d.cwd)===void 0))return;if(s!=="delete"){if(y===void 0)throw new l("TRANSFER_POLICY_REQUIRED",n.path,"not-applied");return $e(e,s,n,d,y,a)}if(t===void 0)return;let o=await t.backend.lstat(t.location.path,d);P(t.location.source,o.revision,a);{if(y===void 0)throw new l("DELETE_POLICY_REQUIRED",t.location.source,"not-applied");let r=e.resolve(d.cwd,d.cwd);if(r!==void 0&&r.location.target!==t.location.target)throw new l("UNSUPPORTED_SOURCE",t.location.source,"not-applied");let i=r?.location.path??t.backend.target.workspace,p=await y.prepare(t.location.path,i,{temporaryEnvironment:c(f=>t.backend.temporaryEnvironment({...d,signal:f}),"temporaryEnvironment"),realpath:c(f=>t.backend.realpath(f,d),"realpath"),inspect:c(f=>t.backend.lstat(f,d),"inspect"),read:c(async f=>(await t.backend.read(f,d)).bytes.toString("utf8"),"read"),git:c((f,R,u)=>t.backend.queryGit(f,R,{...d,signal:u}),"git"),source:c(f=>O(t.location.target,f).source,"source")});if(p.revision!==o.revision)throw new l("DELETE_TARGET_CHANGED",t.location.source,"not-applied");return await t.backend.removeObject(p.resolvedPath,p.revision,d),{kind:"file-operation",operation:s,ok:!0,effect:"applied",path:t.location.source}}}}c(Ve,"createSshFileOperationResolver");function Z(e,a,s){return{id:"ssh",async tryResolve(n,d){try{let y=e.resolve(n,d.cwd);if(!y)return{kind:"not-handled"};let{backend:t,location:o}=y,r=!1;try{r=(await t.stat(o.path,d)).kind==="directory"}catch(h){if(!(h instanceof l)||h.code!=="ENOENT")throw h}let i,p,f,R=c(async h=>{try{let w=await t.read(o.path,h);return i=w.version,w.bytes}catch(w){throw w instanceof l&&w.code==="ENOENT"&&(i=null),w}},"snapshot"),u=c(async h=>{if(p=void 0,f=void 0,r){let w=await t.list(o.path,h);f=w.map(g=>g.kind==="directory"?`${g.name}/`:g.name);let E=w.map(g=>` ${g.kind==="directory"?"\u{1F4C1}":g.kind==="file"?"\u{1F4C4}":"\u{1F517}"} ${g.name}`);return[{type:"text",text:[`\u{1F4C1} ${o.source}/`,...E.length?["",...E]:[]].join(`
4
+ `)}]}return p=await R(h),a.convert({source:o.source,bytes:p},h)},"read"),m=c(async(h,w,E)=>{let g=await t.readRange(o.path,h,w,E);return{bytes:g.bytes,byteOffset:g.offset,totalBytes:g.totalBytes}},"readBytes");return s==="read"||r?{kind:"resolved",resource:{source:o.source,link:o.source,read:u,get sourceBytes(){return p},get entries(){return f},...r?{}:{readBytes:m}}}:{kind:"resolved",resource:{source:o.source,link:o.source,read:u,readBytes:m,get sourceBytes(){return p},async write(h,w){let E=ce(h);if(i===void 0)try{await R(w)}catch(g){if(!(g instanceof l)||g.code!=="ENOENT")throw g}if(i===void 0)throw new l("SNAPSHOT_REQUIRED",o.source,"not-applied");i=await t.write(o.path,Buffer.from(E,"utf8"),i,w)}}}}catch(y){return{kind:"failed",error:y}}}}}c(Z,"createSshResourceResolver");async function Ge(e,a){let s=await ye({id:"ssh",description:"Set up SSH targets and use remote resources",triggers:[{tool:"read",resourcePrefixes:["ssh://","raw:ssh://","web:ssh://"]},{tool:"search",resourcePrefixes:["ssh://","web:ssh://"]},{tool:"debug",resourcePrefixes:["ssh://"]},{tool:"outline",resourcePrefixes:["ssh://"]},...["write","replace","insert","delete","copy","move","stage","unstage","undo"].map(r=>({tool:r,resourcePrefixes:["ssh://"]}))]});if(Ee(e,[{...s,markdown:`${s.markdown}
5
+ ## Configured workspaces
6
+
7
+ ${a.length===0?"No SSH targets are configured. Follow the setup steps above.":a.map(r=>`- \`${O(r.id,r.workspace).source}\``).join(`
8
+ `)}
9
+ `}]),a.length===0)return;let n=new Ce(a),d=K(e,{provider:"filesystem",capability:"read"}),y=K(e,{provider:"filesystem",capability:"write"}),t={protocol:ie,apiVersion:ae,id:"ssh",setup(r){r.addResolver({resolver:Z(n,d,"read"),priority:-50,preserveTruncatedOutput:!0,renderResult:pe({kind:"source"})})}},o={protocol:fe,apiVersion:ue,id:"ssh",setup(r){r.addFileOperationResolver(Ve(n)),r.addResolver({resolver:Z(n,y,"write"),priority:-50})}};await Promise.all([ke(e,{protocol:Re,apiVersion:5,id:"ssh-diagnostic-files",setup(r){r.addDiagnosticFileReader({id:"ssh",async readText(i,p){let f=n.resolve(i,p.cwd);if(f)return(await f.backend.read(f.location.path,{signal:p.signal})).bytes.toString("utf8")}})}}),se(e,t),ge(e,o),me(e,{protocol:we,apiVersion:he,id:"ssh",setup(r){r.addEnvironmentProvider(Fe(n))}})])}c(Ge,"registerSshResources");async function ct(e){let a=await Ne(Ae(Se()));await Ge(e,a)}c(ct,"registerSshModule");export{ct as default};
@@ -0,0 +1,2 @@
1
+ import{a as r}from"./chunk-EI7MMDWY.js";var a=class{static{r(this,"AgentIdeProcessRegistry")}#e=new Map;#n=new Set;#t=new Map;add(e){return this.#t.get(e.id)?.(),this.#e.set(e.id,e),this.#t.set(e.id,e.onDidChange(()=>this.#i())),this.#i(),()=>{this.#e.get(e.id)===e&&(this.#t.get(e.id)?.(),this.#t.delete(e.id),this.#e.delete(e.id),this.#i())}}list(){return[...this.#e.values()].flatMap(e=>e.list())}compactionNotice(e){let i=[],d=[];for(let s of this.#e.values()){let o=s.list().filter(t=>t.sessionId===void 0||t.sessionId===e);o.length!==0&&(i.push(...o.map(t=>[t.source,t.kind,t.status,t.title,u(t.description)].filter(l=>l.length>0).join(" \xB7 "))),s.compactionGuidance!==void 0&&d.push(s.compactionGuidance))}if(i.length!==0)return["Agent IDE processes still active after compaction:",...i.map(s=>`- ${s}`),"Read a source to inspect the process, then continue working with it.",...d].join(`
2
+ `)}onDidChange(e){return this.#n.add(e),()=>this.#n.delete(e)}dispose(){for(let e of this.#t.values())e();this.#t.clear(),this.#e.clear(),this.#n.clear()}#i(){for(let e of this.#n)e()}},c=new WeakMap;function p(n){let e=c.get(n);if(e===void 0){let i=new a;e=i,c.set(n,i),n.on("session_compact",(d,s)=>{let o=i.compactionNotice(s.sessionManager.getSessionId());o!==void 0&&n.sendMessage({customType:g,content:o,display:!1},{deliverAs:"steer"})})}return e}r(p,"agentIdeProcessRegistry");var g="agent-ide-processes-after-compaction";function u(n){let e=n.replaceAll(/\s+/gu," ").trim();return e.length<=120?e:`${e.slice(0,119)}\u2026`}r(u,"oneLine");export{p as a};
@@ -0,0 +1 @@
1
+ import{a as b}from"./chunk-MMQIHUU5.js";import{a as E}from"./chunk-4DLSZYUO.js";import{a as S,b as g}from"./chunk-VPBGKSFI.js";import"./chunk-T5PXAYWC.js";import{b as y}from"./chunk-V2LLMBTA.js";import{b as u,j as c,k as w,l as k,m as v}from"./chunk-S4GTWS2J.js";import{a as l,b as f,c as P,d as O,f as R}from"./chunk-UN3XLVPR.js";import{c as h}from"./chunk-XHFAV2NI.js";import"./chunk-PBMHSK6J.js";import{c as m}from"./chunk-OA26FH5G.js";import"./chunk-BXGMMZT3.js";import"./chunk-3JBQYLJ4.js";import"./chunk-47SPPIXK.js";import"./chunk-VAXLSPPU.js";import"./chunk-BW3XONMZ.js";import"./chunk-GTZOIJCH.js";import"./chunk-JXULBI4S.js";import"./chunk-2YO6RVX4.js";import"./chunk-MLFJU2US.js";import"./chunk-JY63UUC2.js";import"./chunk-I3G6K7QU.js";import"./chunk-HSAGZWPO.js";import"./chunk-PS2B6THP.js";import"./chunk-XEPCURYZ.js";import"./chunk-OEEE5BLN.js";import"./chunk-2QCE7GOV.js";import"./chunk-2EY3LEZ7.js";import"./chunk-YNOR4LIE.js";import"./chunk-JKM4E5VB.js";import"./chunk-XQMNVPNS.js";import"./chunk-IRLWXPL4.js";import"./chunk-ZC65Z3CK.js";import"./chunk-ZAWRSA7N.js";import"./chunk-OFILFO6D.js";import"./chunk-KINKBPPX.js";import{a}from"./chunk-EI7MMDWY.js";import T from"node:path";import I from"node:path";function C(d){let s=a(o=>{let t=d.resolve(o);if(!t)throw new c("UNSUPPORTED_SOURCE",o,"not-applied");return t},"resolve");return{transport:a(o=>E(d,o),"transport"),async readText(o,t){let e=s(o);return(await e.backend.read(e.location.path,{signal:t})).bytes.toString("utf8")},async readSnapshot(o,t){let e=s(o),r=await e.backend.read(e.location.path,{signal:t});return{content:r.bytes.toString("utf8"),version:r.version}},async readBytes(o,t){let e=s(o);return(await e.backend.read(e.location.path,{signal:t})).bytes},async exists(o,t){let e=s(o);try{return await e.backend.stat(e.location.path,{signal:t}),!0}catch(r){if(r instanceof c&&r.code==="ENOENT")return!1;throw r}},async isFile(o,t){let e=s(o);return(await e.backend.stat(e.location.path,{signal:t})).kind==="file"},async entries(o,t){let e=s(o);return(await e.backend.list(e.location.path,{signal:t})).map(r=>({name:r.name,kind:r.kind==="symlink"?"other":r.kind}))},async filesContaining(o,t,e,r){let n=s(o),i=await n.backend.execute("rg",[...P(t,e)],n.location.path,{signal:r});if(i.exitCode!==0&&i.exitCode!==1)throw new Error(`Listing files that contain ${t} on ${n.location.target} failed: ${i.stderr.toString("utf8")}`);return O(i.stdout.toString("utf8")).map(p=>u(n.location.target,I.posix.join(n.location.path,p)).source)}}}a(C,"createSshLspWorkspaceOwner");async function U(d){let s=new v(await k(w(h()))),o=C(s);await R(d,{workspace:a(t=>t.startsWith("ssh://")?o:void 0,"workspace"),async loadRegistry(t,e,r){r?.throwIfAborted();let n=s.resolve(t);if(n)return f.fromPackageDir(t,{signal:r,layerAccess:S(s,r),includeGlobal:!e,requireBuiltInEvidence:e,recipes:l,recipeEvidence:a(i=>g(n.backend,n.location.path,i,r),"recipeEvidence"),executableAvailability:a(i=>y(n.backend,n.location.path,i,r),"executableAvailability")});if(t.includes("://"))throw new c("UNSUPPORTED_SOURCE",t,"not-applied");return f.fromPackageDir(e?t:process.env.PI_AGENT_IDE_CONFIG_DIR??t,{signal:r,includeGlobal:!e,requireBuiltInEvidence:e,recipes:l})},async resolveProject(t,e,r){if(r?.throwIfAborted(),t.startsWith("ssh://")||e.startsWith("ssh://")){let i=s.resolve(t,e);if(!i)throw new c("UNSUPPORTED_SOURCE",t,"not-applied");let p=s.resolve(e);if(p&&p.location.target!==i.location.target)throw new c("UNSUPPORTED_SOURCE",t,"not-applied");return b(i.backend,i.location.path,p?.location.path,"lsp-servers",l,r)}let n=await m(e,t,"lsp-servers",l,r);return n===void 0?void 0:{cwd:n,external:n!==T.resolve(e)}}})}a(U,"registerOwnedLsp");export{U as default};
@@ -0,0 +1,4 @@
1
+ import"./chunk-NNCZYO4Q.js";import{f as x,g as A}from"./chunk-JXULBI4S.js";import{a as E,n as O,o as b}from"./chunk-SJQGFUXR.js";import{d as S}from"./chunk-IZTOXSTR.js";import{d as _}from"./chunk-QCAGAJHJ.js";import{a as k}from"./chunk-I3G6K7QU.js";import{a as I,b as T}from"./chunk-HSAGZWPO.js";import{e as v}from"./chunk-PS2B6THP.js";import"./chunk-XEPCURYZ.js";import{I as D,ta as C}from"./chunk-OEEE5BLN.js";import"./chunk-2QCE7GOV.js";import{a as V,b as q,c as L}from"./chunk-JKM4E5VB.js";import{b as H}from"./chunk-XQMNVPNS.js";import"./chunk-IRLWXPL4.js";import"./chunk-ZC65Z3CK.js";import{a as $}from"./chunk-ZAWRSA7N.js";import{a as W,b as M}from"./chunk-OFILFO6D.js";import"./chunk-KINKBPPX.js";import{a as h}from"./chunk-EI7MMDWY.js";import{randomUUID as U}from"node:crypto";import z from"node:path";import{Type as B}from"typebox";var G=S({kind:"code-view",label:"Diagnostics"});async function K(r){let o=new Map;r.on("session_start",()=>o.clear()),r.on("session_shutdown",()=>o.clear());let n=C(r),s,c=h((t,u,e)=>{if(s===void 0)throw new Error("IDE diagnostics are not connected");return s(t,{cwd:u,...e})},"collect"),l={protocol:W,apiVersion:5,id:"diagnostics",setup(t){s=t.readDiagnostics}},f,R=new WeakMap,w=new WeakMap,N={protocol:I,apiVersion:T,id:"diagnostics",setup(t){f=t;let u=E(n,t.read,e=>o.has(e),"Diagnostic reports are read-only. Read the source file to edit it.");t.addResolver({resolver:{id:"diagnostic-reports",async tryResolve(e){let i=o.get(e);return i===void 0?{kind:"not-handled"}:{kind:"resolved",resource:{source:e,sourceBytes:new TextEncoder().encode(i),async read(){return[{type:"text",text:i}]}}}}}}),t.addView({view:"diagnostics",priority:100,presenter:J(c,w)}),t.addHandler({stage:"read",when:{resolvedBy:"any",contentKind:"text"},handler(e){return e.state?.contentKind==="text"&&e.request.views?.includes("diagnostics")&&R.set(e.request,e.state.text),{kind:"continue",context:e}}}),t.addHandler({stage:"post-read",handler(e){if(e.state&&o.has(e.state.source))return u(e);let i=R.get(e.request),g=i&&w.get(i),p=e.result,m=p?.content[0];return!g||!p||m?.type!=="text"?{kind:"continue",context:e}:{kind:"continue",context:e,transform(a){let d=a.content[0];return d?.type!=="text"?a:{...a,content:[{...d,text:`${g}
2
+ ${d.text}`},...a.content.slice(1)],details:{...a.details,diagnosticStatus:g}}}}}}),t.describe({views:"diagnostics \u2014 diagnostics beside the text."})}};await Promise.all([$(r,l),k(r,N)]);let j=D(r,"diagnostics");r.registerTool(A({name:"diagnostics",label:"diagnostics",exposure:"direct",namespace:{name:"ide_diagnostics",description:"Check file diagnostics from lint and language servers."},annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},description:"Check lint and language-server diagnostics for a file, with nearby source context and check readiness. Returns a report reusable by Read and Search, not an editable source selection.",promptSnippet:"Check file diagnostics and lint/language-server readiness",parameters:B.Object({path:B.String({minLength:1,description:"Local file path or ssh:// file path."})},{additionalProperties:!1}),outputSchema:O,renderCall(t,u,e){return v(e.lastComponent,{tool:"diagnostics",primary:{text:t.path,color:"accent",truncate:"start"},expanded:e.expanded},u)},renderResult:G,async execute(t,u,e,i,g){if(!f)throw new Error("diagnostics needs the Read module (read.core).");let p=H(u.path,g.cwd),m=j(t),a=await c(p,g.cwd,{signal:e}),d=V(p,a.content,a.results),F=d.text.endsWith(`
3
+ `)?d.text:d.text+`
4
+ `,y=`diagnostic-report:${U()}`;o.set(y,F);let P=await f.read({path:y},{cwd:g.cwd,signal:e,...i&&{onUpdate:i}},m?"script":"agent");return b({...P,details:{...P.details,source:p,diagnosticCheck:d.diagnosticCheck}},{complete:m})}},new x))}h(K,"registerDiagnostics");function J(r,o){return{id:"diagnostics",async present(n,s){if(s.purpose!=="read"||!z.isAbsolute(n.source)&&!n.source.startsWith("ssh://"))return n;let c=s.audience==="script"&&!s.requestedViews?.includes("diagnostics");if(c&&_(n.source))return n;let l=await r(n.source,s.cwd,{signal:s.signal,...s.audience==="script"&&{mode:c?"snapshot":"complete"}}).catch(f=>{if(s.signal?.throwIfAborted(),!c)throw f});if(l===void 0||c&&l.content!==n.content)return n;if(l.content!==n.content)throw new Error("File changed during diagnostic read; read it again for current source lines.");return o.set(n,L(l.results)),q(n,l.results)}}}h(J,"createDiagnosticPresenter");export{K as default};
@@ -0,0 +1 @@
1
+ import{a as C}from"./chunk-MMQIHUU5.js";import{a as w}from"./chunk-54EFJYUB.js";import{a as E,b as g}from"./chunk-VPBGKSFI.js";import{b as S}from"./chunk-V2LLMBTA.js";import{j as l,k as u,l as v,m as U}from"./chunk-S4GTWS2J.js";import{a as p,b as O,c as f,e as j}from"./chunk-YI32H7Z2.js";import"./chunk-K5G4FDXD.js";import{c as R}from"./chunk-XHFAV2NI.js";import"./chunk-PBMHSK6J.js";import{c as P}from"./chunk-OA26FH5G.js";import"./chunk-BXGMMZT3.js";import"./chunk-2YO6RVX4.js";import"./chunk-MLFJU2US.js";import"./chunk-OEEE5BLN.js";import"./chunk-2QCE7GOV.js";import"./chunk-2EY3LEZ7.js";import"./chunk-ZC65Z3CK.js";import"./chunk-ZAWRSA7N.js";import"./chunk-OFILFO6D.js";import{a as s}from"./chunk-EI7MMDWY.js";import h from"node:path";import{fileURLToPath as x}from"node:url";function A(i){let c=E(i),T=w(i);return{async resolveProject(e,o){if(e.startsWith("ssh://")||o.startsWith("ssh://")){let n=i.resolve(e,o);if(!n)throw new l("UNSUPPORTED_SOURCE",e,"not-applied");let a=i.resolve(o);if(a&&a.location.target!==n.location.target)throw new l("UNSUPPORTED_SOURCE",e,"not-applied");let r=await C(n.backend,n.location.path,a?.location.path,"linters",p);return r?{projectRoot:r.cwd,external:r.external}:void 0}if(e.includes("://")||o.includes("://"))throw new l("UNSUPPORTED_SOURCE",e,"not-applied");let t=await P(o,e,"linters",p);return t===void 0?void 0:{projectRoot:t,external:t!==h.resolve(o)}},async loadRegistry(e,o){let t=i.resolve(e);return O.fromDirectory(e,{includeGlobal:!o,requireBuiltInEvidence:!0,...t?{layerAccess:c,executableAvailability:s(n=>S(t.backend,t.location.path,n),"executableAvailability"),recipeEvidence:s(n=>g(t.backend,t.location.path,n),"recipeEvidence")}:{}})},async run(e,o){let t=i.resolve(o.filePath);if(!t)return f(e,o);let n=i.resolve(o.projectRoot);if(!n||n.location.target!==t.location.target)throw new l("UNSUPPORTED_SOURCE",o.filePath,"not-applied");let a=e.check.cwd==="file"?h.posix.dirname(t.location.path):n.location.path;return f(e,{...o,processAccess:T,acceptsFile(r){if(r.startsWith("ssh://")){let d=i.resolve(r);return d?.location.target===t.location.target&&d.location.path===t.location.path}let m=r.startsWith("file:")?x(r):r;return m.includes("://")?!1:h.posix.resolve(a,m)===t.location.path}})}}}s(A,"createOwnedLintRuntime");async function L(i){let c=new U(await v(u(R())));await j(i,A(c))}s(L,"registerOwnedLint");export{A as createOwnedLintRuntime,L as default};
@@ -0,0 +1 @@
1
+ import{a as x}from"./chunk-BXGMMZT3.js";import{b as T,c as S,d as I}from"./chunk-2EY3LEZ7.js";import{a as b}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";import G from"cross-spawn";import{spawnSync as J}from"node:child_process";import{access as B,readFile as h,writeFile as q}from"node:fs/promises";import V from"node:os";import l from"node:path";import{fileURLToPath as z}from"node:url";var $=1;function ge(e){return l.win32.basename(b(e[0]))}a(ge,"configuredExecutableName");async function me(e,n,o,r,i){i?.throwIfAborted();let s=l.resolve(e),t=l.resolve(s,n),f=r.filter(d=>ne(d,t));if(re(s,t))return s;let u=l.dirname(t);for(;;){if(i?.throwIfAborted(),await oe(L(u,o),i)||[...(await x(u,f,void 0,i)).values()].some(y=>y.score>0))return u;let c=l.dirname(u);if(c===u)return;u=c}}a(me,"resolveExternalToolProjectRoot");function W(e){return l.join(e,".pi","pi-agent-ide")}a(W,"projectIdeConfigDirectory");function L(e,n){return l.join(W(e),`${n}.json`)}a(L,"projectIdeConfigPath");function K(e,n,o={}){let i=(o.environment??process.env).PI_CODING_AGENT_DIR?.trim(),s=i===void 0||i.length===0?l.join(o.homeDirectory??V.homedir(),".pi","agent"):l.resolve(i);return{project:L(e,n),global:l.join(s,"extensions","pi-agent-ide",`${n}.json`),builtIn:z(new URL(`tool-config/${n}.json`,new URL("../src/api/tool-config.ts",import.meta.url).href))}}a(K,"resolveToolConfigPaths");async function ye(e,n,o,r={}){let i=r.signal;i?.throwIfAborted();let s=r.layerAccess;if(e.includes("://")&&!s)throw Object.assign(new Error("No config owner for this project"),{code:"UNSUPPORTED_SOURCE"});let t={...K(e,n,r),...s?await s.paths(e,n,i):{}},f=[{layer:"project",sourcePath:t.project,optional:!0},...r.includeGlobal===!1?[]:[{layer:"global",sourcePath:t.global,optional:!0}],{layer:"built-in",sourcePath:t.builtIn,optional:!1}],u=[],d=new Set;for(let c of f){i?.throwIfAborted();let y=await Y(c,n,o,c.layer!=="built-in"&&s?m=>s.readText(m,i):void 0,i);for(let[m,P]of Object.entries(y))d.has(m)||(d.add(m),u.push({id:m,config:P,layer:c.layer,sourcePath:c.sourcePath}))}return{entries:u,paths:t}}a(ye,"loadLayeredToolConfig");function H(e,n,o){let r=l.extname(n).toLowerCase();if(e.extensions.every(t=>!(D(t)===r||t==="*"))&&!e.fileNames?.some(t=>process.platform==="win32"?t.toLowerCase()===l.basename(n).toLowerCase():t===l.basename(n)))return!1;let i=l.relative(o,n).split(l.sep).join("/"),s=a(t=>t?.some(f=>l.matchesGlob(i,f))??!1,"matches");return(e.include===void 0||s(e.include))&&!s(e.exclude)}a(H,"matchesConfiguredFile");function pe(e,n,o,r,i){let s=l.resolve(i,r),t=e.filter(d=>H(d.config,s,i)),f=t.find(d=>d.layer!=="built-in");if(f!==void 0)return f;let u=Math.max(0,...t.map(d=>o.get(d.id)?.score??0));return t.find(d=>n.has(d.id)&&(o.get(d.id)?.score??0)===u)}a(pe,"selectConfiguredEntry");async function Q(e,n,o=process.env,r){r?.throwIfAborted(),C(e,"process");let i=b(e.command[0]).replaceAll("{project}",n),s=_(e,n,o);return I(i,n,s,r)}a(Q,"hasConfiguredExecutable");async function be(e,n,o,r){if(r.signal?.throwIfAborted(),e.includes("://")&&!r.executableAvailability)throw Object.assign(new Error("Tool probes require their resource owner"),{code:"UNSUPPORTED_SOURCE"});let i=r.executableAvailability?await r.executableAvailability(n.map(t=>t.config),r.signal):await Promise.all(n.map(t=>Q(t.config,e,r.environment??process.env,r.signal)));if(r.signal?.throwIfAborted(),i.length!==n.length||i.some(t=>typeof t!="boolean"))throw new TypeError("Invalid tool executable availability report");let s=r.recipeEvidence?await r.recipeEvidence(o,r.signal):await x(e,o,void 0,r.signal);return r.signal?.throwIfAborted(),{available:new Set(n.filter((t,f)=>i[f]===!0&&(!r.requireBuiltInEvidence||(s.get(t.id)?.score??0)>0)).map(t=>t.id)),evidence:s}}a(be,"toolRuntimeEvidence");async function X(e,n){if(C(e,"process"),n.processAccess)return n.processAccess.run(e,n);if(n.projectRoot.includes("://")||n.filePath.includes("://"))throw Object.assign(new Error("No process owner for this resource"),{code:"UNSUPPORTED_SOURCE"});let o=e.command.map(u=>ee(u,n)),r=b(o[0]),i=o.slice(1),s=e.cwd==="file"?l.dirname(n.filePath):n.projectRoot,t=e.successExitCodes??[0],f=_(e,n.projectRoot,n.env??process.env);return n.signal?.throwIfAborted(),new Promise((u,d)=>{let c=G(r,i,{cwd:s,env:f,detached:process.platform!=="win32",stdio:[n.input===void 0?"ignore":"pipe","pipe","pipe"]}),y=a(()=>k(c.pid),"stop"),m=a(()=>{y(),d(n.signal?.reason??new Error("The operation was aborted"))},"onAbort");n.signal?.addEventListener("abort",m,{once:!0}),c.pid!==void 0&&v.add(c.pid);let P=a(()=>{clearTimeout(U),n.signal?.removeEventListener("abort",m),c.pid!==void 0&&v.delete(c.pid)},"settle"),A="",R="",j=b(c.stdout),N=b(c.stderr),E=!1,U=setTimeout(()=>{E=!0,y()},e.timeoutMs??3e4);j.setEncoding("utf8"),N.setEncoding("utf8"),j.on("data",g=>{A+=g}),N.on("data",g=>{R+=g}),n.input!==void 0&&c.stdin&&(c.stdin.on("error",g=>{g.code!=="EPIPE"&&(y(),d(g))}),c.stdin.end(n.input)),c.on("error",g=>{P(),d(g)}),c.on("close",g=>{P(),u({ok:!E&&g!==null&&t.includes(g),exitCode:g,...E&&{timedOut:!0},stdout:A,stderr:R})})})}a(X,"runConfiguredProcess");var v=new Set;process.once("exit",()=>{for(let e of v)k(e)});function k(e){if(e!==void 0){if(v.delete(e),process.platform==="win32"){J("taskkill",["/pid",String(e),"/T","/F"],{stdio:"ignore"});return}try{process.kill(-e,"SIGKILL")}catch{}}}a(k,"killProcessTree");async function he(e,n){let o=await h(n.filePath,"utf8"),r=await X(e.run,{...n,input:n.stdin?o:void 0});if(!r.ok)return{ok:!1,changed:await h(n.filePath,"utf8")!==o};if(e.output==="stdout"&&r.stdout!==o){if(n.stdin&&await h(n.filePath,"utf8")!==o)throw new Error("File changed during formatting");await q(n.filePath,r.stdout,"utf8")}let i=await h(n.filePath,"utf8");return{ok:!0,changed:o!==i}}a(he,"runConfiguredFormatter");function we(e){let n=F(e,"formatters");for(let[o,r]of Object.entries(n.entries)){let i=p(r,`formatter ${o}`);if(M(i,`formatter ${o}`),C(i.run,`formatter ${o}.run`),i.output!=="in-place"&&i.output!=="stdout")throw new Error(`formatter ${o}.output must be in-place or stdout`)}return e}a(we,"parseFormattersConfig");function Ce(e){let n=F(e,"linters"),o=new Set(["pi-json","eslint-json","sarif","checkstyle","gcc","clang","regex"]);for(let[r,i]of Object.entries(n.entries)){let s=p(i,`linter ${r}`);if(s.enabled!==void 0&&typeof s.enabled!="boolean")throw new TypeError(`linter ${r}.enabled must be a boolean`);M(s,`linter ${r}`),C(s.check,`linter ${r}.check`),s.fix!==void 0&&C(s.fix,`linter ${r}.fix`);let t=p(s.diagnostics,`linter ${r}.diagnostics`);if(!o.has(String(t.format)))throw new Error(`linter ${r} has an unsupported diagnostics format`);if(t.columnBase!==void 0&&(t.format!=="regex"||t.columnBase!==0&&t.columnBase!==1))throw new Error(`linter ${r} columnBase must be 0 or 1 for regex diagnostics`);if(t.format==="regex"&&typeof t.pattern!="string")throw new Error(`linter ${r} regex diagnostics require pattern`)}return e}a(Ce,"parseLintersConfig");function F(e,n){let o=p(e,"tool config");if(o.version!==$)throw new Error(`tool config version must be ${$}`);return{entries:p(o[n],n)}}a(F,"configRoot");function M(e,n){w(e.extensions,`${n}.extensions`,!1),e.fileNames!==void 0&&w(e.fileNames,`${n}.fileNames`,!1),e.include!==void 0&&w(e.include,`${n}.include`,!1),e.exclude!==void 0&&w(e.exclude,`${n}.exclude`,!0)}a(M,"assertMatcher");function C(e,n){let o=p(e,n);if(w(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(r=>!Number.isInteger(r))))throw new Error(`${n}.successExitCodes must contain integers`);if(o.env!==void 0){let r=p(o.env,`${n}.env`);if(Object.values(r).some(i=>typeof i!="string"))throw new Error(`${n}.env values must be strings`)}}a(C,"assertProcessConfig");function w(e,n,o){if(!Array.isArray(e)||!o&&e.length===0||e.some(r=>typeof r!="string"||r.length===0))throw new Error(`${n} must be ${o?"an":"a non-empty"} array of strings`)}a(w,"assertStringArray");function p(e,n){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(`${n} must be an object`);return e}a(p,"configRecord");function D(e){return e.startsWith(".")?e.toLowerCase():`.${e.toLowerCase()}`}a(D,"normalizeExtension");async function Y(e,n,o,r,i){i?.throwIfAborted();let s;try{s=r?await r(e.sourcePath):await h(e.sourcePath,{encoding:"utf8",signal:i})}catch(t){if(i?.throwIfAborted(),e.optional&&Z(t))return{};throw new Error(`Cannot read ${e.layer} ${n} config at ${e.sourcePath}: ${O(t)}`,{cause:t})}i?.throwIfAborted();try{return o(JSON.parse(s))}catch(t){throw new Error(`Invalid ${e.layer} ${n} config at ${e.sourcePath}: ${O(t)}`,{cause:t})}}a(Y,"readToolConfigLayer");function Z(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}a(Z,"isMissingFile");function O(e){return e instanceof Error?e.message:String(e)}a(O,"errorMessage");function _(e,n,o){return S(n,{...T(o),...T(e.env??{})})}a(_,"createConfiguredProcessEnvironment");function ee(e,n){let o=l.relative(n.projectRoot,n.filePath);return e.replaceAll("{project}",n.projectRoot).replaceAll("{fileDir}",l.dirname(n.filePath)).replaceAll("{relativeFile}",o).replaceAll("{file}",n.filePath)}a(ee,"expandPlaceholders");function ne(e,n){let o=l.extname(n).toLowerCase(),r=l.basename(n),i=a((s,t=[])=>s.some(f=>D(f)===o)||t.some(f=>f===r),"matches");return e.formatter?i(e.formatter.extensions,e.formatter.fileNames):e.linter?i(e.linter.extensions,e.linter.fileNames):e.lsp?i(Object.values(e.lsp.languageIds).flat(),Object.values(e.lsp.fileNames??{}).flat()):!1}a(ne,"recipeMatchesFile");async function oe(e,n){n?.throwIfAborted();try{return await B(e),n?.throwIfAborted(),!0}catch{return n?.throwIfAborted(),!1}}a(oe,"fileExists");function re(e,n){let o=l.relative(e,n);return o===""||o!==".."&&!o.startsWith(`..${l.sep}`)&&!l.isAbsolute(o)}a(re,"isPathInside");export{$ as a,ge as b,me as c,W as d,L as e,K as f,ye as g,H as h,pe as i,Q as j,be as k,X as l,he as m,we as n,Ce as o,_ as p,ne as q};
@@ -0,0 +1,16 @@
1
+ import{a}from"./chunk-EI7MMDWY.js";import{AsyncLocalStorage as Vt}from"node:async_hooks";function Ve(){return{pending:new Set,active:new Vt}}a(Ve,"createSchedulerState");function Ht(t,e){return t===void 0||e===void 0?!0:t.some(n=>e.some(r=>(n.mode==="write"||r.mode==="write")&&(n.resource==="*"||r.resource==="*"||n.resource===r.resource||n.recursive===!0&&r.resource.startsWith(n.resource.endsWith("/")?n.resource:`${n.resource}/`)||r.recursive===!0&&n.resource.startsWith(r.resource.endsWith("/")?r.resource:`${r.resource}/`))))}a(Ht,"conflicts");function Bt(t,e,n){if(e===void 0||!n&&e.some(o=>o.mode!=="read"))return!1;if(t===void 0)return!0;let r=new Map;for(let o of e){let s=o.group??o.resource;r.set(s,[...r.get(s)??[],o])}return[...r.values()].every(o=>o.some(s=>t.some(i=>(s.mode==="read"||i.mode==="write")&&(i.resource==="*"||s.resource===i.resource&&(s.recursive!==!0||i.recursive===!0)||i.recursive===!0&&s.resource.startsWith(i.resource.endsWith("/")?i.resource:`${i.resource}/`)))))}a(Bt,"coveredAccess");async function We(t,e,n,r){e?.throwIfAborted();let o,s,i=new Promise((c,u)=>{s=a(()=>u(e?.reason),"abort"),e?.addEventListener("abort",s,{once:!0}),n!==void 0&&(o=setTimeout(()=>u(r()),Math.max(0,n-performance.now())))});try{let c=await Promise.race([t,i]);if(n!==void 0&&performance.now()>=n)throw r();return c}finally{clearTimeout(o),e?.removeEventListener("abort",s)}}a(We,"waitForDependencies");var re=class t{constructor(e=Ve()){this.state=e}static{a(this,"ResourceScheduler")}run(e,n,r,o={}){let s=Promise.resolve(e),i=this.state.active.getStore();if(i?.open){let g=s.then(y=>{if(r?.throwIfAborted(),!Bt(i.accesses,y,i.allowNestedWrites))throw Object.assign(new Error("Nested resource access must be covered by its parent reservation and permitted by its owner."),{code:"UNDECLARED_RESOURCE_ACCESS"});return y});i.nested??=new t;let p=i.nested.run(g,n,r,{...o,allowNestedWrites:i.allowNestedWrites});return i.children.add(p),p.then(()=>i.children.delete(p),()=>i.children.delete(p)),p}let c=[...this.state.pending],u=s.catch(()=>{}),d,f=new Promise(g=>{d=g}),l={accesses:u,done:f};return this.state.pending.add(l),(async()=>{try{r?.throwIfAborted();let g=performance.now(),p=a(C=>C===void 0?void 0:g+C,"deadlineFor"),y=[],h=a(()=>Object.assign(new Error(`Timed out waiting for ${o.waitFor??(y.join(", ")||"the editor reservation or its resource resolution")}.`),{code:"RESOURCE_WAIT_TIMEOUT",resources:y}),"timeoutError"),m=await We(s,r,p(o.waitTimeoutMs),h);y=[...new Set(m?.map(C=>C.resource))];let R=(m===void 0?void 0:o.waitTimeoutForAccesses?.(m))??o.waitTimeoutMs;await We(Promise.all(c.map(C=>Promise.race([C.done,C.accesses.then(P=>Ht(m,P)?C.done:void 0)]))),r,p(R),h),r?.throwIfAborted();let T={accesses:m,children:new Set,open:!0,allowNestedWrites:o.allowNestedWrites===!0};try{return await this.state.active.run(T,n)}finally{for(;T.children.size>0;)await Promise.allSettled([...T.children]);T.open=!1}}finally{this.state.pending.delete(l),d()}})()}},zt=Symbol.for("pi-agent-resource.resource-scheduler-state"),Gt=globalThis,Kt=Gt[zt]??=Ve(),Xt=new re(Kt);import{AsyncLocalStorage as Jt}from"node:async_hooks";var qt=5e3,O=6e4,Yt=15e3,oe=3e4,He=12e4,Zt=3e4,Be=5e3,Qt=new Map([["search",oe],["file_search",oe],["ast_search",oe],["lsp_search",2e4],["diagnostics",12e4],["debug",6e4],["write",O],["replace",O],["insert",O],["delete",O],["copy",O],["move",O],["undo",O]]),en=new Set(["bash","powershell","remote_bash","remote_powershell"]);function tn(t){return en.has(t)?void 0:Qt.get(t)??Zt}a(tn,"ideToolTimeoutMs");var X=class extends Error{constructor(n,r,o,s){let i=s==="applied"?"The edit was applied. Reread the target before the next edit; do not repeat this one.":s==="unknown"?"The edit effect is unknown. Check the target before retrying.":s==="not-applied"?"No edit was applied. Reread the target before retrying.":n==="lsp_search"?"Narrow the path scope or search the text instead.":n==="debug"?"Check the debugger state before retrying.":"Narrow the path scope or retry on a responsive target.";super(`${n} timed out after ${String(o/1e3)} s on ${r}. ${i}`);this.tool=n;this.target=r;this.timeoutMs=o;this.effect=s;this.name="ToolDeadlineError"}static{a(this,"ToolDeadlineError")}code="TOOL_TIMEOUT"},$=new Jt;function nn(t){let e=$.getStore();e&&(e.recovery=t)}a(nn,"snapshotOnToolDeadline");function rn(t){let e=$.getStore();e?.cleanup.add(t);let n=a(()=>e?.cleanup.delete(t),"settled");t.then(n,n)}a(rn,"trackToolCleanup");function on(t){let e=$.getStore();e&&(e.effect=t)}a(on,"reportToolEffect");function sn(t){let e=$.getStore();return e?.tool!=="search"?!1:(e.configure(Math.min(t??He,He)),!0)}a(sn,"configureSearchDeadline");function an(t,e,n,r,o,s){return ze(t,e,n,r,o,s,(i,c)=>c?.(i)??Ge(i))}a(an,"runWithToolDeadline");async function ze(t,e,n,r,o,s,i){r?.throwIfAborted();let c=new AbortController,u=performance.now(),d,f,l,g=new Promise((y,h)=>{f=y,l=a(()=>{clearTimeout(d),$.run(p,()=>c.abort(r?.reason)),d=setTimeout(()=>h(r?.reason),Be)},"cancel")}),p={tool:t,effect:o,cleanup:new Set,configure(y){if(c.signal.aborted)return;clearTimeout(d);let h=a(()=>{let R=new X(t,e,y,p.effect);f(R),$.run(p,()=>c.abort(R))},"expire"),m=y-(performance.now()-u);m<=0?h():d=setTimeout(h,Math.ceil(m))}};r?.addEventListener("abort",l,{once:!0}),p.configure(n);try{let y=await Promise.race([g,$.run(p,()=>s(c.signal))]);if(!(y instanceof X))return y;if(p.cleanup.size>0){let h=Promise.allSettled(p.cleanup),m=new Promise(T=>{d=setTimeout(()=>T(void 0),Be)}),R=await Promise.race([h,m]);(R===void 0||R.some(T=>T.status==="rejected"))&&(y.message+=" Cancellation was sent, but native cleanup could not be confirmed. Check the target before retrying.")}return i(y,p.recovery)}finally{clearTimeout(d),r?.removeEventListener("abort",l)}}a(ze,"runWithinToolDeadline");function Ge(t){let{code:e,tool:n,target:r,timeoutMs:o,effect:s,message:i}=t;return{content:[{type:"text",text:i}],details:{code:e,tool:n,target:r,timeoutMs:o,...s===void 0?{}:{effect:s}},isError:!0,structuredContent:{status:"error",errors:[{code:e,source:r,message:i}]}}}a(Ge,"toolDeadlineFailure");import{realpath as cn,stat as un}from"node:fs/promises";import J from"node:path";import{fileURLToPath as dn}from"node:url";async function se(t,e,n){if(/^[a-z][a-z\d+.-]*:/iu.test(t)&&!/^[a-z]:[\\/]/iu.test(t)&&!t.startsWith("file:"))return[{resource:t,mode:n}];let r=J.resolve(e,t.startsWith("file:")?dn(t):t),[o,s]=await Promise.allSettled([cn(r),un(r,{bigint:!0})]),i;if(o.status==="fulfilled")i=o.value;else{let f=o.reason;if(!(f instanceof Error)||!("code"in f)||f.code!=="ENOENT")throw f;let l=J.dirname(r);if(l===r)i=r;else{let p=(await se(l,e,n)).find(y=>y.resource.startsWith("file:"));i=J.join(p?.resource.slice(5)??l,J.basename(r))}}let c=i.split(J.sep).join("/"),u=`file:${process.platform==="win32"?c.toLowerCase():c}`,d=[{resource:u,group:u,mode:n}];if(s.status==="fulfilled"){let f=s.value;f.isDirectory()&&(d[0]={resource:u,group:u,mode:n,recursive:!0}),f.ino!==0n&&d.push({resource:`inode:${f.dev}:${f.ino}`,group:u,mode:n,recursive:f.isDirectory()})}else{let f=s.reason;if(!(f instanceof Error)||!("code"in f)||f.code!=="ENOENT")throw f}return d}a(se,"resourceAccesses");import{createHash as ln}from"node:crypto";var fn="pi-agent-resource:file-text-read",gn="pi-agent-resource:file-text-visible",Re=new WeakMap;function Ke(t,e){e.length>0&&Re.set(t,{text:t.text,windows:e})}a(Ke,"attachFileTextWindows");function Xe(t){let e=Re.get(t);return e!==void 0&&"text"in t&&t.text===e.text?e.windows:[]}a(Xe,"fileTextWindows");function pn(t){let e=Xe(t);return Re.delete(t),e}a(pn,"takeFileTextWindows");function mn(t,e){return Ke(e,t.flatMap(n=>n.type==="text"&&"text"in n&&typeof n.text=="string"&&e.text.includes(n.text)?Xe(n):[])),e}a(mn,"retainFileTextWindows");function hn(t){return ln("sha256").update(t).digest("hex")}a(hn,"fileTextDigest");async function yn(t,e){return(await se(t,e,"read").catch(()=>[])).map(({resource:n})=>n)}a(yn,"fileTextKeys");import{randomUUID as wn}from"node:crypto";import{mkdir as Rn,mkdtemp as bn,readFile as Tn,rm as vn,writeFile as Cn}from"node:fs/promises";import{tmpdir as xn}from"node:os";import Je from"node:path";var be=class{static{a(this,"TempResourceStore")}resolver;#e=new Map;#t=new Set;#i;#a;#r;constructor(e={}){this.#i=e.parentDirectory??xn(),this.resolver={id:"temp",tryResolve:a(n=>Promise.resolve(this.#s(n)),"tryResolve")}}save(e){return this.#c(e,!1)}saveFile(e){return this.#c(e,!0)}async#c(e,n){if(this.#r!==void 0)throw new Error("Temporary resource store is closed");let r=this.#o(e,n);this.#t.add(r);try{return await r}finally{this.#t.delete(r)}}dispose(){return this.#r??=this.#n(),this.#r}async#o(e,n){let r=await this.#l(),o=wn(),s=`temp:${o}`,i=Je.join(r,`${o}.txt`);return await Cn(i,e,{encoding:"utf8",flag:"wx",mode:384}),n||this.#e.set(s,i),n?i:s}async#n(){await Promise.allSettled(this.#t),this.#e.clear(),this.#a!==void 0&&await vn(await this.#a,{recursive:!0,force:!0})}#s(e){return e.startsWith("temp:")?this.#r!==void 0||!this.#e.has(e)?{kind:"failed",error:new Error(`Temporary resource ${e} does not exist in this runtime`)}:{kind:"resolved",resource:{source:e,read:a(()=>this.#d(e),"read")}}:{kind:"not-handled"}}async#d(e){let n=this.#e.get(e);if(this.#r!==void 0||n===void 0)throw new Error(`Temporary resource ${e} does not exist in this runtime`);return[{type:"text",text:await Tn(n,"utf8")}]}async#l(){return this.#a??=(async()=>(await Rn(this.#i,{recursive:!0}),bn(Je.join(this.#i,"pi-agent-read-"))))(),this.#a}};import{Type as v}from"typebox";import{Type as j}from"typebox";var qe=["retryAfterMs","resetAt","requestsLimit","requestsRemaining","complexityLimit","complexityRemaining","endpointLimit","endpointRemaining"],Te=j.Object({rateLimit:j.Optional(j.Object({...Object.fromEntries(qe.map(t=>[t,j.Optional(j.Integer({minimum:0,maximum:t==="retryAfterMs"?864e5:Number.MAX_SAFE_INTEGER}))])),endpoint:j.Optional(j.String({maxLength:80,pattern:"^[A-Za-z0-9_:-]{1,80}$"}))},{additionalProperties:!1}))},{additionalProperties:!1});function ie(t,e){if(!t||typeof t!="object"||Array.isArray(t))return;let n=Object.getOwnPropertyDescriptor(t,e);return n&&"value"in n?n.value:void 0}a(ie,"own");function Ye(t){try{let e=ie(t,"rateLimit"),n={};for(let o of qe){let s=ie(e,o);typeof s=="number"&&Number.isSafeInteger(s)&&s>=0&&(o!=="retryAfterMs"||s<=864e5)&&(n[o]=s)}let r=ie(e,"endpoint");if(typeof r=="string"&&/^[A-Za-z0-9_:-]{1,80}$/u.test(r)&&(n.endpoint=r),Object.keys(n).length)return Object.freeze({rateLimit:Object.freeze(n)})}catch{}}a(Ye,"resourceErrorMetadata");function q(t){try{return Ye(ie(t,"metadata"))}catch{return}}a(q,"resourceErrorMetadataOf");var Ze=Symbol.for("pi-agent-resource.ResourceError"),N=class extends Error{constructor(n,r,o,s){if(!/^[A-Z][A-Z0-9_]*$/u.test(n))throw new TypeError("Invalid resource failure code");super(`${n}: ${r}`,s);this.code=n;this.source=r;this.effect=o;this.name="ResourceError";let i=q(s);i&&(this.metadata=i)}static{a(this,"ResourceError")}[Ze]=!0;metadata;static[Symbol.hasInstance](n){return typeof n=="object"&&n!==null&&n[Ze]===!0}};import{Value as Sn}from"typebox/value";var ae=v.Object({code:v.String(),message:v.String(),source:v.Optional(v.String()),metadata:v.Optional(Te)},{additionalProperties:!1});function Qe(t){return{...v.Union([v.Object({status:v.Literal("success"),data:t,errors:v.Array(ae,{maxItems:0})},{additionalProperties:!1}),v.Object({status:v.Union([v.Literal("error"),v.Literal("partial")]),data:v.Optional(t),errors:v.Array(ae,{minItems:1})},{additionalProperties:!1})]),type:"object",properties:{status:v.Union([v.Literal("success"),v.Literal("error"),v.Literal("partial")]),data:v.Optional(t),errors:v.Array(ae)},required:["status","errors"],additionalProperties:!1}}a(Qe,"structuredResultSchema");var ve=1024*1024;function Ce(t,e=ve){let n=new Set,r=a(o=>{if(!(o===null||typeof o=="string"||typeof o=="boolean")&&!(typeof o=="number"&&Number.isFinite(o))){if(typeof o!="object"||n.has(o))throw new TypeError("Structured data must be finite, acyclic JSON");if(!Array.isArray(o)&&Object.getPrototypeOf(o)!==Object.prototype&&Object.getPrototypeOf(o)!==null)throw new TypeError("Structured data must not contain classes or raw byte buffers");n.add(o);for(let s of Array.isArray(o)?o:Object.values(o))r(s);n.delete(o)}},"visit");if(r(t),e!==1/0&&Buffer.byteLength(JSON.stringify(t))>e)throw new RangeError(`Structured data exceeds ${e===ve?"1 MiB":`${String(e)} bytes`}; return a smaller window or a full-result reference`)}a(Ce,"assertJsonData");function et(t,e="EXECUTION_FAILED",n){if(t instanceof N){let r=q(t);return{code:t.code,message:`${t.code}: ${t.source}`,source:n??t.source,...r?{metadata:r}:{}}}return{code:typeof t=="object"&&t!==null&&"code"in t&&typeof t.code=="string"?t.code:e,message:t instanceof Error?t.message:String(t),...n===void 0?{}:{source:n}}}a(et,"resultError");function En(t,e,n,r={}){try{if(Ce(n,r.maxBytes),!Sn.Check(Qe(e),n))throw new TypeError("Result adapter returned data outside its public schema");return{...t,structuredContent:n,isError:n.status!=="success"}}catch(o){let s=et(o,"INVALID_STRUCTURED_RESULT"),i={status:"error",errors:[s]};return Ce(i),{...t,content:[...t.content,{type:"text",text:s.message}],structuredContent:i,isError:!0}}}a(En,"withStructuredResult");function An(t,e){let n=new Set;return t.on("tool_execution_start",r=>{r.toolName===e&&r.parentToolCallId!==void 0&&n.add(r.toolCallId)}),t.on("tool_execution_end",r=>{n.delete(r.toolCallId)}),r=>n.has(r)}a(An,"trackScriptCalls");function kn(t,e){if(e.length===0)return;let n=t.trim();if(n.length===0||/[\r\n]/u.test(n))throw new TypeError("Content provider summary must be one non-empty line");return[n,...e.map(({description:r})=>r)].join(`
2
+ `)}a(kn,"renderContentDescription");import{Type as b}from"typebox";import{Value as Fn}from"typebox/value";import{Type as w}from"typebox";import{Value as On}from"typebox/value";var E={additionalProperties:!0},Y=w.Function([],w.Unknown()),I=w.String({minLength:1}),Nn=w.Object({type:w.Literal("text"),text:w.String(),textSignature:w.Optional(w.String())},E),In=w.Object({type:w.Literal("image"),data:w.String(),mimeType:w.String()},E),Ln=w.Object({type:w.Literal("custom"),kind:I,data:w.Unknown()},E),_n=w.Array(w.Union([Nn,In,Ln]),{minItems:1}),tt=w.Union([w.Object({source:I,link:w.Optional(I),read:Y,write:w.Optional(w.Never())},E),w.Object({source:I,link:w.Optional(I),read:w.Optional(w.Never()),write:Y},E),w.Object({source:I,link:w.Optional(I),read:Y,write:Y},E)]),Mn=w.Object({id:I,tryResolve:Y},E),Pn=w.Union([w.Object({kind:w.Literal("not-handled")},E),w.Object({kind:w.Literal("resolved"),resource:tt},E),w.Object({kind:w.Literal("failed"),error:w.Unknown()},E)]);function xe(t){return ce(_n,t)?ue(()=>t.every(e=>e.type!=="text"||!("textSignature"in e)||typeof e.textSignature=="string")):!1}a(xe,"isAgentContent");function nt(t){return ce(tt,t)?ue(()=>{let e=t,n=!("read"in e)||typeof e.read=="function",r=!("write"in e)||typeof e.write=="function",o=!("readBytes"in e)||typeof e.readBytes=="function";return n&&r&&o}):!1}a(nt,"isResource");function $n(t){return ce(Mn,t)}a($n,"isResourceResolver");function jn(t){return ce(Pn,t)?ue(()=>{let e=t;return e.kind!=="resolved"||nt(e.resource)}):!1}a(jn,"isResourceResolutionAttempt");function ce(t,e){return ue(()=>On.Check(t,e))}a(ce,"safeCheck");function ue(t){try{return t()}catch{return!1}}a(ue,"safeEvaluate");var L={additionalProperties:!0},Dn=b.Function([],b.Unknown()),de=b.String({minLength:1}),Un=b.Object({provider:de,capability:b.Union([b.Literal("read"),b.Literal("write")])},L),Wn=b.Object({source:de,bytes:b.Unknown(),mediaType:b.Optional(b.String())},L),Vn=b.Object({signal:b.Optional(b.Unknown())},L),Hn=b.Object({id:de,description:de,tryConvert:Dn},L),Bn=b.Union([b.Object({kind:b.Literal("not-handled")},L),b.Object({kind:b.Literal("converted"),content:b.Unknown()},L),b.Object({kind:b.Literal("failed"),error:b.Unknown()},L)]),zn=b.Object({target:b.Unknown(),converter:b.Unknown(),priority:b.Optional(b.Number())},L);function W(t){return V(Un,t)&&D(()=>t.provider.trim().length>0)}a(W,"isContentTarget");function Se(t){return V(Wn,t)?D(()=>{let e=t;return e.bytes instanceof Uint8Array&&(!("mediaType"in e)||typeof e.mediaType=="string")}):!1}a(Se,"isContentInput");function Ee(t){return V(Vn,t)?D(()=>{let e=t;return!("signal"in e)||e.signal instanceof AbortSignal}):!1}a(Ee,"isContentConversionContext");function rt(t){return V(Hn,t)?D(()=>{let e=t;return e.id.trim().length>0&&e.description.trim().length>0&&!/[\r\n]/u.test(e.description)}):!1}a(rt,"isContentConverter");function Ae(t){return V(Bn,t)?D(()=>{let e=t;return e.kind!=="converted"||xe(e.content)}):!1}a(Ae,"isContentConversionAttempt");function F(t){return V(zn,t)?D(()=>{let e=t;return W(e.target)&&rt(e.converter)&&(!("priority"in e)||typeof e.priority=="number"&&Number.isFinite(e.priority))}):!1}a(F,"isContentConverterRegistration");function V(t,e){return D(()=>Fn.Check(t,e))}a(V,"safeCheck");function D(t){try{return t()}catch{return!1}}a(D,"safeEvaluate");var le=class extends Error{static{a(this,"UnsupportedContentError")}source;target;constructor(e,n){super(`No content converter for ${e} in ${n.provider}/${n.capability}`),this.name="UnsupportedContentError",this.source=e,this.target=n}};function Oe(t){if(!W(t))throw new TypeError("Invalid content target");let e={...t},n=[],r=a(()=>[...n].sort((o,s)=>o.priority-s.priority||o.order-s.order),"snapshotConverters");return{target:e,register(o){if(!F(o))throw new TypeError("Invalid content converter registration");if(!U(e,o.target))throw new Error(`Content converter ${o.converter.id} targets ${o.target.provider}/${o.target.capability}, not ${e.provider}/${e.capability}`);if(n.some(({converter:s})=>s.id===o.converter.id))throw new Error(`Content converter ${o.converter.id} is already registered for ${e.provider}/${e.capability}`);n.push({converter:o.converter,priority:o.priority??0,order:n.length})},listDescriptions(){return r().map(({converter:o})=>({id:o.id,description:o.description}))},async convert(o,s){if(!Se(o))throw new TypeError("Invalid content input");if(!Ee(s))throw new TypeError("Invalid content conversion context");ke(s.signal);let i=r();for(let{converter:c}of i){ke(s.signal);let u=await c.tryConvert(o,s);if(ke(s.signal),!Ae(u))throw new TypeError(`Content converter ${c.id} returned an invalid outcome`);if(u.kind!=="not-handled"){if(u.kind==="failed")throw u.error;return u.content}}throw new le(o.source,e)}}}a(Oe,"createContentRunner");function U(t,e){return t.provider===e.provider&&t.capability===e.capability}a(U,"targetsEqual");function ke(t){t?.throwIfAborted()}a(ke,"throwIfAborted");import{Type as _}from"typebox";import{Value as Gn}from"typebox/value";var H="pi-agent-resource/content-conversion",fe=2,Z=`${H}/host/ready`,Q=`${H}/converter/register`,ot={additionalProperties:!0},Kn=_.Function([],_.Unknown()),Xn=_.Object({protocol:_.Literal(H),apiVersion:_.Literal(fe),target:_.Unknown()},ot),Jn=_.Object({registration:_.Unknown(),accept:Kn},ot);function Ne(t){return st(Xn,t)&&Le(()=>W(t.target))}a(Ne,"isContentHostReady");function Ie(t){return st(Jn,t)&&Le(()=>F(t.registration))}a(Ie,"isContentConverterRegistrationRequest");function st(t,e){return Le(()=>Gn.Check(t,e))}a(st,"safeCheck");function Le(t){try{return t()}catch{return!1}}a(Le,"safeEvaluate");var it="pi-agent-resource:content-host-lookup";function qn(t,e){let n;if(t.events.emit(it,{target:e,accept(u){if(n)throw new Error("Multiple content hosts registered for one target");n=u}}),n)return at(t,n),n.host;let r=Oe(e),o=t.events.on(Q,u=>{if(!Ie(u))throw new Error("Invalid content converter registration request");if(!U(r.target,u.registration.target))return;let d;try{r.register(u.registration),d=Promise.resolve()}catch(f){d=Promise.reject(f instanceof Error?f:new Error("Content converter registration failed",{cause:f}))}u.accept(d)}),s={target:r.target,listDescriptions(){return r.listDescriptions()},convert(u,d){return r.convert(u,d)}},i=t.events.on(it,u=>{if(!Yn(u))throw new Error("Invalid content host lookup request");U(e,u.target)&&u.accept(c)}),c={host:s,owners:new Set,unsubscribe(){o(),i()}};return at(t,c),t.events.emit(Z,{protocol:H,apiVersion:fe,target:r.target}),s}a(qn,"createContentHost");function Yn(t){return typeof t=="object"&&t!==null&&"target"in t&&typeof t.target=="object"&&t.target!==null&&"provider"in t.target&&typeof t.target.provider=="string"&&"capability"in t.target&&typeof t.target.capability=="string"&&"accept"in t&&typeof t.accept=="function"}a(Yn,"isHostLookup");function at(t,e){e.owners.has(t)||(e.owners.add(t),t.on("session_shutdown",()=>{e.owners.delete(t),e.owners.size===0&&e.unsubscribe()}))}a(at,"retainOwner");function Zn(t,e){if(!F(e))throw new TypeError("Invalid content converter registration");let n=a(()=>{let s,i={registration:e,accept(c){if(s!==void 0)throw new Error(`Content converter ${e.converter.id} registration was accepted more than once`);s=c}};return t.events.emit(Q,i),s},"announce"),r=a(()=>{},"unsubscribe");r=t.events.on(Z,s=>{if(!Ne(s))throw new Error("Invalid content conversion host readiness event");if(!U(e.target,s.target))return;let i=n();if(i===void 0)throw new Error(`${s.target.provider}/${s.target.capability} announced readiness without accepting content converter ${e.converter.id}`);r(),i.catch(()=>{})}),t.on("session_shutdown",r);let o=n();if(o!==void 0)return r(),o}a(Zn,"connectContentConverter");import{createHash as Ct,randomBytes as hr,randomUUID as je}from"node:crypto";import{readFileSync as yr,statSync as Ot}from"node:fs";import{readFile as Nt}from"node:fs/promises";import x from"node:path";import{fileURLToPath as wr}from"node:url";import{Type as z}from"typebox";import{diffArrays as Qn}from"diff";var er=1500;function pe(t){let e=t.split(`
3
+ `);return e.map((n,r)=>r<e.length-1?`${n}
4
+ `:n)}a(pe,"lineTokens");function tr(t,e){let n=pe(t),r=pe(e);return n===void 0||r===void 0?void 0:mt(n,r)}a(tr,"createLineMap");function mt(t,e){let n=new Int32Array(t.length+1),r=0,o=Math.min(t.length,e.length);for(;r<o&&t[r]===e[r];)r+=1;let s=0;for(;s<o-r&&t[t.length-1-s]===e[e.length-1-s];)s+=1;for(let u=0;u<r;u+=1)n[u+1]=u+1;for(let u=0;u<s;u+=1)n[t.length-s+u+1]=e.length-s+u+1;let i=t.slice(r,t.length-s),c=e.slice(r,e.length-s);if(i.length>0&&c.length>0){let u=Qn(i,c,{maxEditLength:er});if(u===void 0)return;let d=0,f=0;for(let l of u)if(l.added)f+=l.count;else if(l.removed)d+=l.count;else{let g=l.count;for(let p=0;p<g;p+=1)n[r+d+p+1]=r+f+p+1;d+=g,f+=g}}return{table:n,oldLines:t,newLines:e,newLine:a(u=>{let d=n[u];return d===void 0||d===0?void 0:d},"newLine")}}a(mt,"orderedMap");function M({start:t,end:e}){return e.column===0&&e.lineNumber>t.lineNumber?e.lineNumber-1:e.lineNumber}a(M,"lastSelectedLine");function ht(t,e){let{start:n,end:r}=t,o=M(t),s=o!==r.lineNumber,i,c;for(let u=n.lineNumber;u<=o;u+=1){let d=e.newLine(u);if(d===void 0||c!==void 0&&d!==c+1)return;i??=d,c=d}if(!(i===void 0||c===void 0))return{...t,start:{lineNumber:i,column:n.column},end:{lineNumber:s?c+1:c,column:r.column}}}a(ht,"rebaseRange");function _e(t,e,n){let{start:r,end:o}=t,s=M(t),i=s!==o.lineNumber,c=!1;for(let g=r.lineNumber;g<=s&&!c;g+=1)c=e.newLine(g)!==void 0;if(!c)return;let u=e.newLine(r.lineNumber),d;if(u!==void 0)d={lineNumber:u,column:r.column};else{let g=0;for(let p=r.lineNumber-1;p>=1;p-=1){let y=e.newLine(p);if(y!==void 0){g=y;break}}d={lineNumber:g+1,column:0}}let f=e.newLine(s),l;if(f!==void 0)l={lineNumber:i?f+1:f,column:o.column};else{let g;for(let p=s+1;p<e.table.length&&g===void 0;p+=1)g=e.newLine(p);l=g===void 0?{lineNumber:n.length,column:n.at(-1)?.length??0}:{lineNumber:g,column:0}}return{...t,start:d,end:l,adjusted:!0}}a(_e,"relocateRange");function nr(t,e,n){return Me(t,e)??_e(t,e,n())}a(nr,"moveRange");var ee=200;function yt(t,e){let n=t.oldLines.length,r=e-1;for(;r>=1&&t.newLine(r)===void 0;)r-=1;let o=e+1;for(;o<=n&&t.newLine(o)===void 0;)o+=1;if(o-r>ee)return;let s=r<1?0:t.newLine(r)??0,i=o>n?t.newLines.length+1:t.newLine(o)??0;return{oldFrom:r+1,oldTo:o-1,newFrom:s+1,newTo:i-1}}a(yt,"hunkAround");function te(t){return t.endsWith(`
5
+ `)?t.slice(0,-1):t}a(te,"withoutEnding");function k(t,e){return te(t[e-1]??"")}a(k,"lineText");function ct(t,e,n,r){let o=[];for(let s=e;s<=n;s+=1){let i=k(t,s);for(let c=i.indexOf(r);c!==-1;c=i.indexOf(r,c+1))o.push({line:s,column:c})}return o}a(ct,"occurrences");function rr(t,e){return wt(t,e.oldLines,e.newLines,()=>yt(e,t.start.lineNumber))}a(rr,"relocateInChangedLine");function wt(t,e,n,r,o=!1){let{start:s,end:i}=t;if(t.linewise===!0||s.lineNumber!==i.lineNumber||s.column>=i.column)return;let c=r();if(c===void 0||c.newTo<c.newFrom)return;let u=k(e,s.lineNumber),d=u.slice(s.column,i.column);if(d.length!==i.column-s.column)return;let f=ct(e,c.oldFrom,c.oldTo,d),l=ct(n,c.newFrom,c.newTo,d),g=f.findIndex(R=>R.line===s.lineNumber&&R.column===s.column);if(g===-1||l.length===0)return;let p=a(R=>R[0]?.line!==R.at(-1)?.line,"spansLines"),h=f.length!==l.length||f.length>1&&(o||p(f)||p(l))?or(t,e,n,f,l):l[g];if(h===void 0)return;let m=k(n,h.line);if(!(u.slice(s.column-1,s.column)!==m.slice(h.column-1,h.column)||u.slice(i.column,i.column+1)!==m.slice(h.column+d.length,h.column+d.length+1)))return{...t,start:{lineNumber:h.line,column:h.column},end:{lineNumber:h.line,column:h.column+d.length}}}a(wt,"relocateInHunk");var ge=256;function ut(t,e,n,r){let o=k(e,t.line),{column:s}=t,i=s+n;if(r)return{position:t,left:o.slice(0,s),right:o.slice(i)};let c=a(f=>f.match(/[\p{ID_Continue}$]+|[^\p{ID_Continue}$]+/gu)??[],"runs"),u=c(o.slice(Math.max(0,s-ge),s)).reverse(),d=c(o.slice(i,i+ge));return s>ge&&u.pop(),o.length-i>ge&&d.pop(),{position:t,left:u,right:d}}a(ut,"matchContext");function dt(t,e){if(typeof t=="string"||typeof e=="string")return typeof t=="string"&&t===e&&/[\p{L}\p{N}]/u.test(t)?1:0;let n=0,r=!1;for(let o of t){if(o!==e[n])break;n>0&&/[\p{L}\p{N}]/u.test(o)&&(r=!0),n+=1}return r?n:0}a(dt,"sharedContext");function lt(t,e,n){let r=a(i=>{let c=t[i],u=0;for(let f of e)f!==t&&(u=Math.max(u,dt(c,f[i])));let d;for(let f of n){let l=dt(c,f[i]);l>u?(u=l,d=f):l===u&&(d=void 0)}return d},"onSide"),o=r("left"),s=r("right");return o!==void 0&&s!==void 0&&o!==s?void 0:o??s}a(lt,"contextMatch");function or({start:t,end:e},n,r,o,s){let i=e.column-t.column,c=o.filter(({line:h})=>h===t.lineNumber).length>1;if(c&&o.length!==s.length)return;let u=o.map(h=>ut(h,n,i,c)),d=s.map(h=>ut(h,r,i,c)),f=u.filter(({position:h})=>h.line===t.lineNumber),l=f.findIndex(({position:h})=>h.column===t.column),g=f[l];if(g===void 0)return;let p=lt(g,u,d);if(p===void 0||lt(p,d,u)!==g)return;let y=d.filter(({position:h})=>h.line===p.position.line);return y.length===f.length&&y[l]===p?p.position:void 0}a(or,"findRepeatedMatch");function Me(t,e){return ht(t,e)??rr(t,e)}a(Me,"rebaseOrRelocateRange");function ft(t){let e=new Map;for(let[n,r]of t.entries())e.set(r,e.has(r)?0:n+1);return e}a(ft,"uniqueLines");function sr(t,e){let n=t.map(te),r=e.map(te),o=ft(n),s=ft(r),i=new Set;for(let[m,R]of o){let T=s.get(m);T!==void 0&&R===0!=(T===0)&&i.add(m)}let c=new Int32Array(t.length+1),u=new Int32Array(c.length),d=new Int32Array(e.length+1),f=0,l=!1;for(let[m,R]of o){let T=s.get(m)??0;R===0||T===0||m===""||(c[R]=T,l||=T<f,f=T)}let g=a((m,R)=>{let T=c[m];T!==0&&T!==R?u[m]=1:c[m]=R;let C=d[R]??0;C!==0&&C!==m?(u[m]=1,u[C]=1):d[R]=m},"claim"),p=a((m,R,T)=>{let C=0;for(let P=m;P!==R;P+=T){let K=n[P-1];if(K===void 0)break;let Ue=o.get(K)===P?s.get(K)??0:0;Ue!==0&&K!==""?C=Ue:C!==0&&r[C+T-1]===K?C+=T:C=0,C!==0&&g(P,C)}},"extend");p(1,c.length,1),p(c.length-1,0,-1);let y=new Int32Array(d.length),h=0;for(let m=1;m<d.length;m+=1)d[m]!==0&&(h+=1),y[m]=h;return{table:c,reordered:l,conflicts:u,newClaims:y,duplicated:i,newLine:a(m=>u[m]===0&&c[m]||void 0,"newLine")}}a(sr,"contextualMap");function gt(t,e){if(t.table[e]!==0)return;let n=e-1;for(;n>0&&t.table[n]===0&&e-n<ee;)n-=1;let r=e+1;for(;r<t.table.length&&t.table[r]===0&&r-n<ee;)r+=1;let o=t.newLine(n),s=t.newLine(r);if(!(o===void 0||s===void 0||s<=o+1||s-o>ee||r-n>ee||t.newClaims[s-1]!==t.newClaims[o]))return{oldFrom:n+1,oldTo:r-1,newFrom:o+1,newTo:s-1}}a(gt,"movedHunk");function ir(t,e,n,r){if(t.linewise!==!0)return;let o,s,i=0,c=0,u=M(t);for(let g=t.start.lineNumber;g<=u;g+=1){let p=e.newLine(g);if(p!==void 0){if(p<=i)return;o??=g,s=g,i=p,c+=1}}if(o===void 0||s===void 0)return;let d=e.newLine(o),f=n[s-1];if(d===void 0||f===void 0||(e.newClaims[i]??0)-(e.newClaims[d-1]??0)!==c)return;let l={...t,start:o===t.start.lineNumber?t.start:{lineNumber:o,column:0},end:s===u?t.end:f.endsWith(`
6
+ `)?{lineNumber:s+1,column:0}:{lineNumber:s,column:f.length}};return _e(l,{...e,oldLines:n,newLines:r},r.map(te))}a(ir,"survivingRegion");function B(t,e){if(t===e)return{move:a(s=>s,"move"),describe:Rt};let n=ar(t,e);if(n===void 0)return pt(t,e);let r,o=a(()=>r??=pt(t,e),"contextual");return{move(s,i){let c=s.start.lineNumber,u=M(s);return Number.isInteger(c)&&Number.isInteger(u)&&c>=1&&c<=u&&u<=n?s:o().move(s,i)},describe:a(s=>o().describe(s),"describe")}}a(B,"createRangeTracker");function ar(t,e){if(e.length<=t.length+1||!t.endsWith(`
7
+ `)||!e.startsWith(t)||e.indexOf(`
8
+ `,t.length)!==e.length-1)return;let n=e.slice(t.length);if(t.startsWith(n)||t.includes(`
9
+ ${n}`))return;let r=0;for(let o=t.indexOf(`
10
+ `);o!==-1;o=t.indexOf(`
11
+ `,o+1))r+=1;return r}a(ar,"unchangedLinesBeforeAppend");function pt(t,e){let n=pe(t),r=pe(e);if(n===void 0||r===void 0)return{move:a(()=>{},"move"),describe:Rt};let o=sr(n,r),s,i=a(()=>(s===void 0&&(s=mt(n,r)??null),s??void 0),"getOrdered"),c,u;return{move:a((l,g=!1)=>{let p=ht(l,{newLine(m){let R=o.newLine(m);if(R!==void 0&&(m===l.end.lineNumber||n[m-1]===r[R-1]))return R}});if(p!==void 0)return p;if(o.reordered){let m=wt(l,n,r,()=>gt(o,l.start.lineNumber),!0);if(m!==void 0||!g)return m}let y=i();if(y===void 0)return;let h=M(l);for(let m=l.start.lineNumber;m<=h;m+=1){let R=o.newLine(m),T=y.newLine(m);if(o.conflicts[m]||R!==void 0&&R!==T||R===void 0&&T!==void 0&&(o.reordered||o.duplicated.has(k(n,m))))return g?ir(l,o,n,r):void 0}return o.reordered?_e(l,y,c??=e.split(`
12
+ `)):g?nr(l,y,()=>c??=e.split(`
13
+ `)):Me(l,y)},"move"),describe:a(l=>{let g=l.start.lineNumber,p=k(n,g),y=o.reordered?gt(o,g):void 0,h=y===void 0?[]:cr(l,p,r,y);if(h.length===0&&p.trim()!==""&&(u??=ur(r),h=u.get(p)??[]),h.length===0&&!o.reordered){let R=i();if(R!==void 0)return bt(l,R)}let m=`line ${String(g)} \`${Pe(p.trim())}\``;return h.length>0?`${m}: cannot verify the same selection; candidate lines: ${h.join(", ")}`:y!==void 0?Tt(m,r,y):`${m}: selected text changed, was deleted, or has no unique surrounding context`},"describe")}}a(pt,"createContextualRangeTracker");function cr(t,e,n,r){let{start:o,end:s}=t;if(t.linewise===!0||o.lineNumber!==s.lineNumber)return[];let i=e.slice(o.column,s.column);if(i.trim()===""||i.length!==s.column-o.column)return[];let c=[];for(let u=r.newFrom;u<=r.newTo&&c.length<3;u+=1)k(n,u).includes(i)&&c.push(u);return c}a(cr,"partialCandidateLines");function ur(t){let e=new Map;for(let[n,r]of t.entries()){let o=te(r),s=e.get(o);s===void 0?e.set(o,[n+1]):s.length<3&&s.push(n+1)}return e}a(ur,"candidateLines");function Rt(t){return`line ${String(t.start.lineNumber)}: the snapshots cannot be compared safely`}a(Rt,"describeUnmappedRange");function dr(t,e,n){let r=B(e,n),o=[];for(let s of t){let i=r.move(s);if(i===void 0)return;o.push(i)}return o}a(dr,"rangesInText");function bt(t,e){let n=t.start.lineNumber;if(e===void 0)return`line ${String(n)}: the file changed too much to follow it`;let r=k(e.oldLines,n).trim(),o=yt(e,n),s=`line ${String(n)} \`${Pe(r)}\``;return o===void 0?`${s}: changed or moved`:Tt(s,e.newLines,o)}a(bt,"describeLostRange");function Pe(t){return t.length>120?`${t.slice(0,120)}\u2026`:t}a(Pe,"preview");function Tt(t,e,n){if(n.newTo<n.newFrom)return`${t}: deleted`;let r=[];for(let o=n.newFrom;o<=Math.min(n.newTo,n.newFrom+2);o+=1)r.push(`${String(o)}| ${Pe(k(e,o).trim())}`);return`${t}: now ${r.join(" / ")}${n.newTo-n.newFrom>2?" \u2026":""}`}a(Tt,"describeHunk");import{stat as lr}from"node:fs/promises";var fr=100000000n,gr=2000000000n;function $e(t,e=Date.now()){let n=t%1000000000n===0n?gr:fr;return BigInt(e)*1000000n-t<n}a($e,"isRacyTimestamp");var pr=a(t=>lr(t,{bigint:!0}),"localGeneration");async function mr(t,e,n,r=pr){let o=await r(t),s=await e(),i=await r(t),c=vt(o);if(c!==vt(i))return;let u=i.mtimeNs>i.ctimeNs?i.mtimeNs:i.ctimeNs;if(!($e(u)&&!n(s,await e())))return{value:s,stamp:c}}a(mr,"readUnchanged");function vt(t){let{dev:e,ino:n,mode:r,size:o,mtimeNs:s,ctimeNs:i}=t;return`${e}:${n}:${r}:${o}:${s}:${i}`}a(vt,"generationStamp");var It=z.Object({id:z.String()}),Fe=z.Union([z.String(),It]),Rr=z.Union([...Fe.anyOf,z.Array(Fe)]),br=new Set(["id","text","path","line","lineText","complete","matches","captures","incoming","outgoing","mode","fallback","notices","editWarning"]),A="RESULT#",xt=/^[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}$/u,St="pi-agent-resource:result-targets",Et="Result reference is unknown or no longer available. Run Read/Search again and use the new result.",At="Invalid result id. Use an issued UUID, RESULT# reference, or SEARCH# selector.";function De(t){if(!(t===null||typeof t!="object"||Array.isArray(t))&&!(!("id"in t)||typeof t.id!="string"))return t.id}a(De,"resultValueId");function Tr(t,e,n){if(De(e)===void 0)return e;let r=t.source(e,n);if(typeof r=="string")return r;let o=t.resolve(r,n);return t.register(o.targets,n,o.complete)}a(Tr,"resultValueReference");var Lt=12,he=/^(?:shell|debug):/u,vr=16*1024*1024,_t=a(t=>Ot(t,{bigint:!0}),"localStat"),G=class{static{a(this,"ResultTargetStore")}version=Lt;#e=new Map;#t=new Map;#i=new Map;#a=new Map;#r=new Map;#c=new Set;#o=new Map;#n=new Map;#s=new Map;#d;constructor(e={}){this.#d=e.stat??_t}clear(){this.#e.clear(),this.#t.clear(),this.#i.clear(),this.#a.clear(),this.#r.clear(),this.#o.clear(),this.#n.clear(),this.#s.clear()}register(e,n,r=!0,o,s){for(let u of e)this.refresh(u.source,n),s!==void 0&&this.#a.set(JSON.stringify([x.resolve(n),S(u.source,n)]),s);let i=`${A}${je()}`,c=this.#g(e,n);return this.#e.set(i,c.lost.length>0?{state:"rejected",cwd:x.resolve(n),reason:me(c.lost)}:{state:"ready",targets:ne(this.#m(c.targets,n)),complete:r,cwd:x.resolve(n)}),o!==void 0&&this.#i.set(i,o),i}reserve(e){let n=`${A}${je()}`;return this.#e.set(n,{state:"pending",cwd:x.resolve(e)}),n}confirm(e,n,r){let o=this.#e.get(e);if(o?.state!=="pending"||o.cwd!==x.resolve(r))throw new Error("Only a pending result in this worktree can be confirmed.");for(let i of n)this.refresh(i.source,r);let s=this.#g(n,r);this.#e.set(e,s.lost.length>0?{state:"rejected",cwd:o.cwd,reason:me(s.lost)}:{state:"ready",cwd:o.cwd,targets:ne(this.#m(s.targets,r)),complete:!0})}reject(e,n){let r=this.#e.get(e);r?.state==="pending"&&this.#e.set(e,{state:"rejected",cwd:r.cwd,reason:n})}resolve(e,n,r={}){e=this.source(e,n);let o=this.#u(e);this.#y(o,n);let s=[],i=!0;for(let c of o){let u=this.#p(c,r.allowAdjusted===!0,r.forScope===!0);i&&=u.complete,s.push(...u.targets)}if(r.forEdit===!0||r.forScope===!0)for(let c of s){let u=this.#a.get(JSON.stringify([x.resolve(n),S(c.source,n)]));if(u!==void 0)throw new N("NO_EDITABLE_TEXT",u,"not-applied")}if(r.forEdit===!0)for(let c of o){let u=this.#i.get(c);if(u!==void 0)throw Object.assign(new Error(u),{code:"UNSAFE_TOKEN_SELECTION"})}return{targets:ne(s),complete:i}}resolveOrdered(e,n){let r=this.resolve(e,n,{forEdit:!0}),o=[],s=new Set;for(let i of new Set(this.#u(this.source(e,n))))for(let c of this.#p(i,!1).targets)for(let u of c.ranges){let d=JSON.stringify([c.source,u]);s.has(d)||(s.add(d),o.push({...c,ranges:[structuredClone(u)]}))}return{targets:o,complete:r.complete}}async resolveCurrent(e,n,r){return $t(this.resolve(e,n,{allowAdjusted:!0}),r)}async verify(e,n){try{await Pt(e,n)}catch(r){if(!n?.aborted)for(let o of e.targets)kt(o.source)||this.invalidate(o.source);throw r}}async verifyUnfollowed(e,n){let r=e.targets.filter(o=>!kt(o.source));r.length>0&&await this.verify({...e,targets:r},n)}registerSearchReference(e,n,r){if(!/^SEARCH#[A-F\d]{4,64}:[1-9]\d*:(line|match)$/u.test(e))throw new Error("Only numbered Search references can alias a snapshot.");let o=this.#e.get(n);if(o===void 0||o.state==="pending"||o.cwd!==x.resolve(r))throw new Error("A Search reference needs a registered result target from this worktree.");this.#f(e,n)}claimSearchId(e){this.#c.add(e)}hasSearchId(e){return this.#c.has(e)}registerAllMatchesReference(e,n){let o=`SEARCH#${this.#l()}:all:match`;return this.#f(o,this.register([e],n)),o}#l(){for(let e=4;e<64;e+=1)for(let n=0;n<8;n+=1){let r=hr(Math.ceil(e/2)).toString("hex").toUpperCase().slice(0,e);if(!this.#c.has(r))return this.#c.add(r),r}throw new Error("Could not allocate a unique search reference id.")}#f(e,n){this.#t.set(e,n),this.#r.set(n,e)}hasSearchReference(e){return this.#t.has(e)}referenceName(e){return this.#r.get(e)??e}resolveSearchReference(e,n){let r=this.#t.get(e);return r===void 0?void 0:this.resolve(r,n)}publish(e,n,r,o=[]){let s=je();for(let d of o)this.refresh(d,r);let i=[];try{i=this.#u(e)}catch{}let c=`<system-result note="Internal reference; not part of the file. Do not edit."><uuid>${s}</uuid></system-result>
14
+ ${n}`,u=e!==null&&typeof e=="object"&&"status"in e&&e.status==="success";if(u&&"data"in e){let d=e.data;if(d!==null&&typeof d=="object"&&"matches"in d&&Array.isArray(d.matches)){let f=d.matches;for(let l of f){if(l===null||typeof l!="object"||!("target"in l)||typeof l.target!="string"||!this.#e.has(l.target)||!("references"in l))continue;let g=l.references;g!==null&&typeof g=="object"&&"match"in g&&typeof g.match=="string"&&/^SEARCH#[A-F\d]+:\d+:match$/u.test(g.match)&&this.#t.set(g.match,l.target)}}}return this.#n.set(s,{cwd:x.resolve(r),digest:Ct("sha256").update(c).digest("hex"),consumable:u,references:i,resources:o}),c}source(e,n,r=!1){if(Array.isArray(e))return e.map(g=>this.source(g,n,r));let o=De(e);if(o!==void 0){let g=Object.keys(e).filter(y=>!br.has(y));if(g.length>0)throw new N("INVALID_RESULT_VALUE",`Unsupported result value fields: ${g.join(", ")}. Pass an unchanged issued value or its id; put edit selectors in the tool arguments.`,"not-applied");let p=o.startsWith(A)?o.slice(A.length):o;if(!xt.test(p)&&!o.startsWith("SEARCH#"))throw new Error(At);return this.source(o,n,r)}if(typeof e!="string")return e;let s=this.#t.get(e);if(s)return this.source(s,n,r);let i=/^<system-result\b[^>]*><uuid>([a-f\d-]{36})<\/uuid><\/system-result>(?:\n|$)/u.exec(e),c=i?.[1]??(e.startsWith(A)?e.slice(A.length):e),u=xt.test(c);if(!i&&!u){if(e.startsWith(A))throw new Error(At);if(e.startsWith("<system-result"))throw new Error("Invalid system result reference.");return e}let d=this.#n.get(c),f=`${A}${c}`;if(!d&&!i&&this.#e.has(f))return f;if(!d)throw new Error(Et);if(d.cwd!==x.resolve(n))throw new Error("Result belongs to another worktree.");if(i&&Ct("sha256").update(e).digest("hex")!==d.digest)throw new Error("Result text changed; pass the original result or its UUID.");for(let g of d.resources)this.refresh(g,n);if(!this.#n.has(c))throw new Error("Result reference expired. Run Read/Search again and use the new result.");if(!d.consumable)throw new Error("Only successful source results can be consumed.");for(let g of d.references)if(!this.#e.has(g))throw this.#n.delete(c),new Error("Result reference expired. Run Read/Search again and use the new result.");if(d.references.length===1)return d.references[0];if(d.references.length>1)return d.references;let l=d.resources.length===1?d.resources[0]:void 0;if(l&&(r===!0||r==="live"&&he.test(l)))return l;throw new Error("This result has no reusable text selection.")}invalidate(e){for(let[r,o]of this.#s)o.identity===e&&this.#s.delete(r);for(let[r,o]of this.#o)S(o.source,o.cwd)===e&&this.#o.set(r,{source:o.source,cwd:o.cwd,stamp:o.stamp});let n=new Set;for(let[r,o]of this.#e)o.state==="ready"&&o.targets.some(s=>S(s.source,o.cwd)===e)&&(this.#e.delete(r),this.#i.delete(r),n.add(r));for(let[r,o]of this.#n)(o.resources.some(s=>S(s,o.cwd)===e)||o.references.some(s=>n.has(s)))&&this.#n.delete(r)}refresh(e,n,r=!1){let o=S(e,n),s=JSON.stringify([x.resolve(n),o]),i=Mt(e,n,this.#d),c=i?.stamp,u=this.#o.get(s),d=r&&!he.test(e),f;if(d||u&&(u.stamp!==c||xr(u,o))){let l=this.#h(o,c);f={source:e,cwd:n,stamp:c,...l===void 0?{}:{content:l}}}else f={...u,source:e,cwd:n,stamp:c};i?.racy===!0&&(f.content??=ye(o)),this.#o.set(s,{...f,racy:i?.racy===!0})}refreshAll(){for(let e of[...this.#o.values()])this.refresh(e.source,e.cwd)}#h(e,n){let r=n===void 0?void 0:ye(e);if(r===void 0){this.invalidate(e);return}let o=new Map,s=new Set;for(let[i,c]of this.#e){if(c.state!=="ready")continue;let u=!1,d=[...c.lost??[]],f=[];for(let l of c.targets){if(S(l.source,c.cwd)!==e){f.push(l);continue}if(u=!0,l.expectedContent===r){f.push(l);continue}let g=o.get(l.expectedContent);g===void 0&&(g=B(l.expectedContent,r),o.set(l.expectedContent,g));let p=[];for(let y of l.ranges){let h=g.move(y,!0);h===void 0?d.push(g.describe(y)):p.push(h)}f.push({...l,expectedContent:r,ranges:p})}u&&(this.#e.set(i,{...c,targets:ne(f),...d.length>0?{lost:d}:{}}),s.add(i))}for(let[i,c]of this.#s)c.identity===e&&this.#s.set(i,{identity:e,content:r});for(let[i,c]of this.#n)c.resources.some(u=>S(u,c.cwd)===e)&&!c.references.some(u=>s.has(u))&&this.#n.delete(i);return r}#g(e,n){let r=[];return{targets:e.map(s=>{let i=S(s.source,n),c=this.#o.get(JSON.stringify([x.resolve(n),i]));if(c?.stamp===void 0||he.test(s.source))return s;c.content??=ye(i);let u=c.content;if(u===void 0)return s;if(s.expectedContent===c.alias||s.expectedContent===u)return c.alias=s.expectedContent,{...s,expectedContent:u};c.older?.text!==s.expectedContent&&(c.older={text:s.expectedContent,tracker:B(s.expectedContent,u)});let d=c.older.tracker,f=[];for(let l of s.ranges){let g=d.move(l,!0);g===void 0?r.push(d.describe(l)):f.push(g)}return{...s,expectedContent:u,ranges:f}}),lost:r}}#y(e,n){let r=new Set;for(let o of e){let s=this.#e.get(o);if(s===void 0)throw new Error(Et);if(s.cwd!==x.resolve(n))throw new Error("Result target belongs to another worktree.");if(s.state==="pending")throw new Error("Result target is pending; its write has not been confirmed.");if(s.state==="rejected")throw new Error(s.reason);for(let i of s.targets)r.add(i.source)}for(let o of r)this.refresh(o,n)}#p(e,n,r=!1){let o=this.#e.get(e);if(o?.state==="rejected")throw new Error(o.reason);if(o?.state!=="ready")throw new Error("Result target expired after its snapshot changed; repeat Read/Search.");if(o.lost!==void 0&&o.lost.length>0){let s=o.targets.filter(i=>i.ranges.length>0);if(!r||s.length===0)throw new Error(me(o.lost))}if(!n){let s=Cr(o.targets);if(s.length>0)throw new Error(me(s))}return r?{targets:o.targets.filter(s=>s.ranges.length>0),complete:o.complete}:o}#m(e,n){return e.map(r=>{let o=S(r.source,n),s=JSON.stringify([x.resolve(n),o]),i=this.#s.get(s);return i?.content===r.expectedContent?{...r,expectedContent:i.content}:(this.#s.set(s,{identity:o,content:r.expectedContent}),r)})}#u(e){if(typeof e=="string"&&e.startsWith(A))return[e];if(Array.isArray(e))return e.flatMap(r=>this.#u(r));if(e===null||typeof e!="object")throw new Error("Unsupported result input.");let n=e;if("status"in n){if(n.status!=="success")throw new Error("Only successful source results can be consumed.");return this.#u(n.data)}if(typeof n.target=="string"&&n.target.startsWith(A))return[n.target];if(n.kind==="resources"&&Array.isArray(n.resources))return this.#u(n.resources);if(n.kind==="list"&&Array.isArray(n.items))return this.#u(n.items);throw new Error("This result has no supported source target; do not use preview text as a source.")}};function me(t){let e=t.slice(0,10),n=t.length-e.length;return[`Result target expired after its snapshot changed: ${String(t.length)} selected range${t.length===1?"":"s"} no longer match${t.length===1?"es":""} the file. Repeat Read/Search.`,...e.map(r=>`- ${r}`),...n>0?[`- and ${String(n)} more`]:[]].join(`
15
+ `)}a(me,"retiredReason");function Cr(t){return t.flatMap(e=>{let n=e.ranges.filter(o=>o.adjusted===!0);if(n.length===0)return[];let r=e.expectedContent.split(`
16
+ `);return n.map(o=>{let s=(r[o.start.lineNumber-1]??"").trim(),i=s.length>120?`${s.slice(0,120)}\u2026`:s;return`lines ${String(o.start.lineNumber)}\u2013${String(M(o))} changed: now ${String(o.start.lineNumber)}| ${i}`})})}a(Cr,"adjustedRegions");function kt(t){return!he.test(t)&&Mt(t,x.parse(t).root||".")!==void 0}a(kt,"followsChanges");function S(t,e){let n=t.startsWith("raw:")?t.slice(4):t;if(/^[a-z][a-z0-9+.-]*:\/\//iu.test(n)&&!n.startsWith("file:"))return n;if(n.startsWith("file:"))try{return wr(n)}catch{}return x.resolve(e,n)}a(S,"sourcePath");function ye(t){try{return Ot(t).size>vr?void 0:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(yr(t))}catch{return}}a(ye,"readLocalText");function Mt(t,e,n=_t){let r;try{r=n(S(t,e))}catch{return}let o=r.mtimeNs>r.ctimeNs?r.mtimeNs:r.ctimeNs,s=$e(o);return{stamp:`${r.dev}:${r.ino}:${r.size}:${r.mtimeNs}:${r.ctimeNs}`,racy:s}}a(Mt,"fileStamp");function xr(t,e){return t.racy!==!0||t.content===void 0?!1:ye(e)!==t.content}a(xr,"changedWithinTick");async function Pt(t,e){let n=new Map;for(let r of t.targets){e?.throwIfAborted();let o=n.get(r.source);if(o===void 0&&(o=r.readCurrent===void 0?await Nt(r.source,{encoding:"utf8",signal:e}):await r.readCurrent(e),e?.throwIfAborted(),n.set(r.source,o)),o!==r.expectedContent)throw new Error("Result target is stale; repeat Read/Search.")}}a(Pt,"verifyResultTargets");async function $t(t,e){let n=new Map;for(let r of t.targets)e?.throwIfAborted(),!n.has(r.source)&&(n.set(r.source,r.readCurrent===void 0?await Nt(r.source,{encoding:"utf8",signal:e}):await r.readCurrent(e)),e?.throwIfAborted());return jt(t,n)}a($t,"currentResultTargets");function jt(t,e){let n=[];for(let r of t.targets){let o=e.get(r.source);if(o===void 0||o===r.expectedContent){n.push(r);continue}let s=B(r.expectedContent,o),i=r.ranges.map(c=>{let u=s.move(c,!0);if(u===void 0)throw new Error(`The region this result selected can no longer be found in ${r.source}: ${s.describe(c)}. Repeat Read/Search.`);return u});n.push({...r,expectedContent:o,ranges:i})}return{targets:ne(n),complete:t.complete}}a(jt,"resultTargetsInText");function Sr(t,e){let n=t.targets.flatMap(s=>s.ranges.filter(i=>i.adjusted===!0).map(i=>{let{start:c}=i,u=M(i),d=e.endsWith(x.sep)?e:`${e}${x.sep}`;return`${s.source.startsWith(d)?s.source.slice(d.length):s.source}:${c.lineNumber}-${u}`}));if(n.length===0)return;let r=n.slice(0,5).join(", "),o=n.length>5?` and ${n.length-5} more`:"";return`The result's text changed after it was issued. Searched the current text of the same region (${r}${o}); matches are anchored to the current file.`}a(Sr,"describeAdjustedRanges");function ne(t){let e=new Map;for(let n of t){let r=e.get(n.source);if(r!==void 0&&r.expectedContent!==n.expectedContent)throw new Error("Result targets refer to different snapshots of the same source.");let o=r??{source:n.source,expectedContent:n.expectedContent,...n.readCurrent===void 0?{}:{readCurrent:n.readCurrent},ranges:[],seen:new Set};for(let s of n.ranges){let i=JSON.stringify(s);o.seen.has(i)||(o.seen.add(i),o.ranges.push(structuredClone(s)))}e.set(n.source,o)}return[...e.values()].filter(n=>n.ranges.length>0).map(({seen:n,...r})=>({...r,ranges:r.ranges.sort((o,s)=>o.start.lineNumber-s.start.lineNumber||o.start.column-s.start.column||o.end.lineNumber-s.end.lineNumber||o.end.column-s.end.column)}))}a(ne,"combineTargets");function Er(t){let e=[];t.events.emit(St,{accept:a(s=>{s!==null&&typeof s=="object"&&!e.includes(s)&&e.push(s)},"accept")});let n=e.find(Ar);if(n!==void 0)return n;let r=new G;for(let s of e)kr(s,r);let o=t.events.on(St,s=>{s!==null&&typeof s=="object"&&"accept"in s&&typeof s.accept=="function"&&s.accept(r)});return t.on("session_start",()=>{r.clear()}),t.on("session_shutdown",()=>{r.clear(),o()}),r}a(Er,"connectResultTargets");function Ft(){return Object.getOwnPropertyNames(G.prototype).filter(t=>t!=="constructor"&&typeof Object.getOwnPropertyDescriptor(G.prototype,t)?.value=="function")}a(Ft,"storeMethods");function Ar(t){return typeof t.version=="number"&&t.version>=Lt&&Ft().every(e=>typeof t[e]=="function")}a(Ar,"isCurrentStore");function kr(t,e){for(let n of Ft()){if(typeof t[n]!="function")continue;let r=e[n];Object.defineProperty(t,n,{configurable:!0,writable:!0,value:a((...o)=>r.apply(e,o),"value")})}}a(kr,"forwardStore");import Dt from"node:path";var Ut="pi-agent-resource:result-images",Or=64*1024*1024,we=class{static{a(this,"ResultImageStore")}#e=new Map;#t=0;clear(){this.#e.clear(),this.#t=0}keep(e,n,r){let o=/^<system-result\b[^>]*><uuid>([a-f\d-]{36})<\/uuid>/u.exec(e)?.[1];if(o!==void 0){this.#e.set(o,{cwd:Dt.resolve(n),images:r}),this.#t+=Wt(r);for(let[s,i]of this.#e){if(this.#t<=Or||s===o)break;i.images.length!==0&&(this.#e.set(s,{...i,images:[]}),this.#t-=Wt(i.images))}}}images(e,n){let r=/^(?:RESULT#)?([a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12})$/u.exec(e)?.[1],o=r===void 0?void 0:this.#e.get(r);if(o!==void 0){if(o.cwd!==Dt.resolve(n))throw new Error("Result belongs to another worktree.");if(o.images.length===0)throw new Error("This result has no kept images. Read the image again and pass the new result.");return o.images}}};function Wt(t){return t.reduce((e,n)=>e+n.data.length,0)}a(Wt,"imageSize");function Nr(t){let e;if(t.events.emit(Ut,{accept:a(o=>{e=o},"accept")}),e!==void 0)return e;let n=new we,r=t.events.on(Ut,o=>{o!==null&&typeof o=="object"&&"accept"in o&&typeof o.accept=="function"&&o.accept(n)});return t.on("session_start",()=>{n.clear()}),t.on("session_shutdown",()=>{n.clear(),r()}),n}a(Nr,"connectResultImages");export{re as a,Xt as b,qt as c,O as d,Yt as e,oe as f,tn as g,X as h,nn as i,rn as j,on as k,sn as l,an as m,ze as n,Ge as o,se as p,fn as q,gn as r,Ke as s,pn as t,mn as u,hn as v,yn as w,be as x,Te as y,Ye as z,q as A,N as B,ae as C,Qe as D,ve as E,Ce as F,et as G,En as H,An as I,kn as J,xe as K,nt as L,$n as M,jn as N,W as O,Se as P,Ee as Q,rt as R,Ae as S,F as T,le as U,Oe as V,U as W,H as X,fe as Y,Z,Q as _,Ne as $,Ie as aa,qn as ba,Zn as ca,tr as da,Me as ea,B as fa,dr as ga,bt as ha,mr as ia,It as ja,Fe as ka,Rr as la,De as ma,Tr as na,G as oa,Pt as pa,$t as qa,jt as ra,Sr as sa,Er as ta,we as ua,Nr as va};
@@ -0,0 +1,11 @@
1
+ import{a as de,b as ce,c as ue}from"./chunk-EHFWODRT.js";import{a as re,b as ie,c as oe}from"./chunk-D23NS4VV.js";import{f as ae,g as se}from"./chunk-KN6VPARZ.js";import{a as te}from"./chunk-2YO6RVX4.js";import{b as J,c as ee}from"./chunk-MLFJU2US.js";import{a as ne}from"./chunk-JY63UUC2.js";import{a as X}from"./chunk-I3G6K7QU.js";import{a as Q,b as K}from"./chunk-HSAGZWPO.js";import{d as Z,e as Y}from"./chunk-XEPCURYZ.js";import{D as z,G as D,H as L,a as j,b as W,c as I,la as V,p as B}from"./chunk-OEEE5BLN.js";import{a as q}from"./chunk-IRLWXPL4.js";import{a as E}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import ke from"node:path";var le={protocol:J,apiVersion:ee,id:"changes",setup(t){t.addSetupCheck({id:"git",async inspect(e){return await re(e,e.workspace?`${e.cwd}/.git`:ke.join(e.cwd,".git"))?await oe(e,"git")?{}:{actions:[{id:"git-unavailable",message:"Git integration is unavailable because Git was not found"}]}:{}}}),t.addCheck({id:"git",title:"Git changes",async run(e){let n=await ie(e,"git",["--version"]);return[n.ok?{status:"pass",message:"Git is available",detail:n.detail}:{status:"warn",message:"Git is not available; change anchors and index tools are disabled",detail:n.detail}]}})}};import{mkdtemp as Ie,rm as Ge,writeFile as Pe}from"node:fs/promises";import Se from"node:os";import k from"node:path";import b from"node:path";var w=/^[a-z][a-z0-9+.-]*:\/\//iu,Ae=/^[A-Za-z]:(?:[\\/]|$)/u;function C(t,e){if(w.test(t))return v(t).href;if(!w.test(e))return b.resolve(e,t);let n=v(e),r=decodeURIComponent(n.pathname),o=Ae.test(t)?`/${t[0]?.toUpperCase()??""}:${b.posix.normalize(t.slice(2).replaceAll("\\","/")||"/")}`:b.posix.resolve(r,t);return n.pathname=o.split("/").map(fe).join("/"),n.href}s(C,"resolveGitSource");function ge(t,e){if(!w.test(t)&&!w.test(e))return b.relative(t,e);if(!w.test(t)||!w.test(e))return;let n=v(t),r=v(e);if(n.host===r.host)return b.posix.relative(decodeURIComponent(n.pathname),decodeURIComponent(r.pathname))}s(ge,"relativeGitSource");function x(t,e){let n=C(t,e);if(!w.test(n))return b.dirname(n);let r=v(n);return r.pathname=b.posix.dirname(decodeURIComponent(r.pathname)).split("/").map(fe).join("/"),r.href}s(x,"gitSourceDirectory");function fe(t){return encodeURIComponent(t).replaceAll("%3A",":")}s(fe,"encodeRemoteSegment");function v(t){let e=new URL(t);if(e.protocol!=="ssh:"||e.username||e.password||e.port||e.search||e.hash)throw new Error(`Unsupported Git resource: ${t}`);return e}s(v,"remoteUrl");var G=class t{constructor(e,n){this.executor=e;this.repositoryRoot=n}static{s(this,"GitChangesBackend")}static async create(e,n,r){let o=await e.exec("git",["rev-parse","--show-toplevel"],{cwd:n,...r!==void 0&&{signal:r}});return o.code!==0?{status:"unavailable",reason:"no-worktree",message:o.stderr.trim()||"not inside a Git worktree"}:{status:"ready",backend:new t(e,C(o.stdout.trim(),n))}}async readTrackedFile(e,n,r){let o=C(e,n),i=ge(this.repositoryRoot,o);return i===void 0||i===".."||i.startsWith(`..${k.sep}`)||k.isAbsolute(i)?{status:"unavailable",reason:"outside-worktree",message:`${o} is outside ${this.repositoryRoot}`}:this.readTrackedRepositoryFile(i.split(k.sep).join("/"),r)}async readTrackedRepositoryFile(e,n){let r=await this.git(["rev-parse","--verify","HEAD"],n);if(r.code!==0)return{status:"unavailable",reason:"missing-head",message:r.stderr.trim()||"Git HEAD does not exist"};let o=await this.git(["--literal-pathspecs","ls-tree","-z","HEAD","--",e],n);if(o.code!==0)return{status:"unavailable",reason:"head-file-lookup-failed",message:o.stderr.trim()||`could not inspect HEAD:${e}`};let i=Re(o.stdout);if(i===void 0)return{status:"untracked"};let c=await this.readBlob(i.blob,"HEAD",e,n);if(c.status!=="found")return c;let u=await this.git(["--literal-pathspecs","ls-files","--stage","-z","--",e],n);if(u.code!==0)return{status:"unavailable",reason:"index-file-lookup-failed",message:u.stderr.trim()||`could not inspect the index entry for ${e}`};let a=He(u.stdout);if(a.some(({stage:d})=>d!==0))return{status:"unavailable",reason:"conflicted",message:`${e} has unresolved Git index entries`};let l=a.find(({stage:d})=>d===0),g="";if(l!==void 0){let d=await this.readBlob(l.blob,"index",e,n);if(d.status!=="found")return d;g=d.text}return{status:"found",head:r.stdout.trim(),repositoryPath:e,repositoryRoot:this.repositoryRoot,headText:c.text,indexText:g,indexMode:l?.mode??i.mode,indexExists:l!==void 0}}async normalizesLineEndings(e,n){let r=await this.git(["--literal-pathspecs","ls-files","--eol","--",e],n),o=/^i\/(?<index>\S+)\s+w\/(?<worktree>\S+)\s+attr\/(?<attributes>[^\t]*)\t/u.exec(r.stdout)?.groups;if(r.code!==0||o===void 0||/crlf|mixed/u.test(o.index??""))return!1;let i=(o.attributes??"").trim().split(/\s+/u);if(i.includes("-text")||i.includes("text=unset"))return!1;if(i.some(u=>/^(?:text(?:=(?!unset)\S+)?|eol=\S+)$/u.test(u)))return!0;let c=await this.git(["config","--get","core.autocrlf"],n);return c.code===0&&["true","input"].includes(c.stdout.trim().toLowerCase())}async writeIndexFile(e,n,r,o,i){if(i&&this.executor.writeIndex&&await this.executor.writeIndex({repositoryPath:e,mode:n,text:r,...i},{cwd:this.repositoryRoot,...o!==void 0&&{signal:o}}))return;if(this.repositoryRoot.startsWith("ssh://"))throw new Error("Remote Git index writes require a guarded owner index writer");let c=await Ie(k.join(Se.tmpdir(),"pi-agent-index-")),u=k.join(c,"content");try{await Pe(u,r,"utf8");let a=await this.git(["hash-object","-w",`--path=${e}`,u],o);if(a.code!==0||a.stdout.trim().length===0)throw new Error(a.stderr.trim()||`could not write a Git blob for ${e}`);let l=await this.git(["update-index","--add","--cacheinfo",n,a.stdout.trim(),e],o);if(l.code!==0)throw new Error(l.stderr.trim()||`could not update the Git index entry for ${e}`)}finally{await Ge(c,{recursive:!0,force:!0})}}async readBlob(e,n,r,o){let i=await this.git(["cat-file","blob",e],o);return i.code!==0?{status:"unavailable",reason:n==="HEAD"?"head-file-lookup-failed":"index-file-lookup-failed",message:i.stderr.trim()||`could not read ${n}:${r}`}:{status:"found",text:i.stdout}}git(e,n){return this.executor.exec("git",e,{cwd:this.repositoryRoot,...n!==void 0&&{signal:n}})}};function Re(t){let e=t.split("\0",1)[0];if(e===void 0||e.length===0)return;let n=e.indexOf(" ");if(n===-1)return;let[r,o,i]=e.slice(0,n).split(" ",3);return r===void 0||o!=="blob"||i===void 0?void 0:{mode:r,blob:i,path:e.slice(n+1)}}s(Re,"parseTreeEntry");function He(t){return t.split("\0").filter(Boolean).flatMap(e=>{let n=e.indexOf(" ");if(n===-1)return[];let[r,o,i]=e.slice(0,n).split(" ",3),c=Number(i);return r===void 0||o===void 0||!Number.isInteger(c)?[]:[{mode:r,blob:o,stage:c,path:e.slice(n+1)}]})}s(He,"parseIndexEntries");function pe(t){return{exec:s((e,n,r)=>{if(/^[a-z][a-z0-9+.-]*:\/\//iu.test(r.cwd))throw new Error(`No Git executor owns ${r.cwd}`);return t.exec(e,n,r)},"exec")}}s(pe,"extensionGitExecutor");var h=class t{constructor(e){this.git=e}static{s(this,"ChangeService")}static async create(e,n,r){let o=await G.create(e,n,r);return o.status==="unavailable"?o:{status:"ready",service:new t(o.backend)}}async inspect(e){return(await this.inspectNormalized(e)).inspection}async inspectNormalized(e){let n=s(l=>({inspection:l,comparable:e.worktreeText,restore:s(g=>g,"restore")}),"unchanged");if(e.worktreeText.includes("\0"))return n({status:"unavailable",reason:"binary",message:"worktree file contains binary content"});let r=await this.git.readTrackedFile(e.source,e.cwd,e.signal);if(r.status!=="found")return n(r.status==="untracked"?{status:"not-applicable",reason:"untracked"}:r);if(r.headText.includes("\0")||r.indexText.includes("\0"))return n({status:"unavailable",reason:"binary",message:"Git file state contains binary content"});let o=e.worktreeText.includes(`\r
2
+ `)&&!r.headText.includes(`\r
3
+ `)&&!r.indexText.includes(`\r
4
+ `)&&await this.git.normalizesLineEndings(r.repositoryPath,e.signal),i=o?e.worktreeText.replaceAll(`\r
5
+ `,`
6
+ `):e.worktreeText,c=!/(?:^|[^\r])\n/u.test(e.worktreeText),u=s(l=>o?c?l.replaceAll(`
7
+ `,`\r
8
+ `):void 0:l,"restore"),a=de(r.repositoryPath,r.headText,r.indexText,i);return a.length===0?{inspection:{status:"not-applicable",reason:"clean"},comparable:i,restore:u}:{inspection:{status:"applicable",head:r.head,repositoryRoot:r.repositoryRoot,repositoryPath:r.repositoryPath,groups:a},comparable:i,restore:u}}async changeIndex(e,n,r){let o=await this.inspect(e);if(o.status!=="applicable")return o;let i=o.groups.find(l=>l.selector===n);if(i===void 0)return U(n,o.groups.map(({selector:l})=>l));let c=r==="stage"?"staged":"unstaged";if(i.state===c)return{status:"unchanged",state:c,group:i};let u=E(i.segments[0]),a={expectedWorktreeText:e.worktreeText,head:o.head,repositoryPath:o.repositoryPath,headStart:u.headStart,headEnd:u.headEnd,replacementText:r==="stage"?u.worktreeText:u.headText};try{await this.applyIndexUpdate(a,e.signal)}catch(l){return{status:"unavailable",reason:"index-write-failed",message:he(l),failure:l instanceof Error?l:new Error(he(l))}}return{status:"applied",state:c,group:i}}async prepareUndo(e,n){let{inspection:r,comparable:o,restore:i}=await this.inspectNormalized(e);if(r.status!=="applicable")return r;let c=r.groups.find(d=>d.selector===n);if(c===void 0)return U(n,r.groups.map(({selector:d})=>d));let u=ce(o,c),a=u===void 0?void 0:i(u);if(a===void 0)return u===void 0?U(n,r.groups.map(({selector:d})=>d)):{status:"unavailable",reason:"mixed-line-endings",message:"the file mixes CRLF and LF line endings, so the change cannot be reversed exactly"};let l=E(c.segments[0]),g=c.state==="unstaged"?void 0:{head:r.head,repositoryPath:r.repositoryPath,headStart:l.headStart,headEnd:l.headEnd,replacementText:l.headText,expectedWorktreeText:a};return{status:"applied",worktreeText:a,group:c,...g!==void 0&&{indexUpdate:g}}}async applyIndexUpdate(e,n){let r=await this.git.readTrackedRepositoryFile(e.repositoryPath,n);if(r.status!=="found")throw new Error(r.status==="untracked"?`${e.repositoryPath} is no longer tracked by HEAD`:r.message);if(r.head!==e.head)throw new Error(`Git HEAD changed while updating ${e.repositoryPath}`);let o=ue(r.headText,r.indexText,e.headStart,e.headEnd,e.replacementText);o!==r.indexText&&await this.git.writeIndexFile(e.repositoryPath,r.indexMode,o,n,{expectedHead:r.head,expectedIndexText:r.indexText,expectedIndexMode:r.indexMode,expectedIndexExists:r.indexExists,...e.expectedWorktreeText!==void 0&&{expectedWorktreeText:e.expectedWorktreeText}})}};function U(t,e){return{status:"unavailable",reason:"stale-selector",message:`${t} is not available in the current file state`,availableSelectors:e}}s(U,"staleSelector");function he(t){return t instanceof Error?t.message:String(t)}s(he,"errorMessage");var P="pi-agent-ide-changes/change",$e=/^CHANGE#[0-9A-F]{4,64}$/,De=/^[A-Za-z][A-Za-z\d+.-]*:\/\//,N=class extends q{static{s(this,"ChangeTextAnchor")}constructor(e){super(e.selector,e.currentStartLine)}};function me(t){return{resolver:Le(s(async n=>{if(De.test(n.source)&&!n.source.startsWith("ssh://"))return;let r=await h.create(t,x(n.source,n.cwd),n.signal);if(r.status!=="ready")throw new Error(r.message);return r.service.inspect({source:n.source,worktreeText:n.content,cwd:n.cwd,...n.signal!==void 0&&{signal:n.signal}})},"inspect"))}}s(me,"createChangeAnchorRegistration");function Le(t){return{id:"git-change",description:"Use the complete `CHANGE#HASH` shown beside a current Git change.",renderFull(e){return e},renderCompact(e){return e},async tryResolve(e,n){if(!$e.test(e))return{kind:"not-handled"};try{let r=await t(n);if(r===void 0)return{kind:"not-handled"};if(r.status==="unavailable")return{kind:"failed",error:new Error(r.message)};let o=r.status==="applicable"?r.groups.find(i=>i.selector===e):void 0;return o===void 0?{kind:"rejected",rejection:{code:"stale",reason:`Change anchor ${e} is stale or unknown`}}:{kind:"resolved",anchor:new N(o)}}catch(r){return{kind:"failed",error:r}}}}}s(Le,"createChangeAnchorResolver");import{diffLines as Ue}from"diff";var Ne="filesystem";function xe(t){return{id:"current-git-changes",async present(e,n){if(n.purpose!=="read"||n.resolvedBy!==Ne&&!n.source.startsWith("ssh://"))return e;let r=await h.create(t,x(n.source,n.cwd),n.signal);if(r.status!=="ready")return e;let o=await r.service.inspect({source:n.source,worktreeText:e.content,cwd:n.cwd,...n.signal!==void 0&&{signal:n.signal}});return o.status!=="applicable"?e:Oe(e,o.groups)}}}s(xe,"createCurrentChangePresenter");function Oe(t,e){let n=new Map;for(let r of e)Me(t,r,n);return{...t,references:e.map(r=>({value:r.selector,kind:"change",state:r.state})),lines:t.lines.map(r=>Fe(r,n.get(r.lineNumber)))}}s(Oe,"presentChangeGroups");function Me(t,e,n){let r=E(e.segments[0]),o=Ue(r.headText,r.worktreeText),i=e.currentStartLine,c,u;for(let a of o){let l=We(a.value);if(a.removed){let g=je(t,i),d=M(n,g.lineNumber),p=g.after?d.after:d.before;for(let T of l){let m={kind:"synthetic",rows:p,index:p.length};p.push({marker:"-",prefix:"|",content:T}),c??=m,u=m}continue}if(a.added){for(let g of l){let d=M(n,i),p={kind:"current",lineNumber:i};d.added=!0,c??=p,u=p,i++}continue}i+=l.length}if(c!==void 0&&u!==void 0){let a=`${e.selector} \xB7 ${e.state}`;_e(c,u)?O(n,c,`<!-- change: ${a} -->`):(O(n,c,`<!-- change-begin: ${a} -->`),O(n,u,`<!-- change-end: ${a} -->`))}}s(Me,"presentChangeGroup");function _e(t,e){return t.kind==="current"&&e.kind==="current"?t.lineNumber===e.lineNumber:t.kind==="synthetic"&&e.kind==="synthetic"?t.rows===e.rows&&t.index===e.index:!1}s(_e,"sameTarget");function O(t,e,n){if(e.kind==="current"){M(t,e.lineNumber).annotations.push(n);return}let r=E(e.rows[e.index]);e.rows[e.index]={...r,suffix:`${r.suffix??""} ${n}`}}s(O,"annotateTarget");function Fe(t,e){if(e===void 0)return t;let n=e.annotations.length===0?"":` ${e.annotations.join(" ")}`;return{...t,presentation:{...t.presentation,...e.added&&{marker:"+"},before:[...t.presentation?.before??[],...e.before],after:[...e.after,...t.presentation?.after??[]],suffix:`${t.presentation?.suffix??""}${n}`}}}s(Fe,"presentLine");function M(t,e){let n=t.get(e);if(n!==void 0)return n;let r={before:[],after:[],annotations:[],added:!1};return t.set(e,r),r}s(M,"presentationsFor");function je(t,e){return e<=t.lines.length?{lineNumber:Math.max(1,e),after:!1}:{lineNumber:t.lines.length,after:!0}}s(je,"placementFor");function We(t){if(t.length===0)return[];let e=t.split(/\r\n|\r|\n/u);return e.at(-1)===""&&e.pop(),e}s(We,"splitLines");var S=class{static{s(this,"IndexMutationQueue")}scheduler=new j;run(e,n,r){return this.scheduler.run(void 0,r,n,{waitTimeoutMs:I,waitFor:`the Git index for ${e}`})}};import{createHash as Be}from"node:crypto";import{realpathSync as ze}from"node:fs";import be from"node:path";import{fileURLToPath as Ve}from"node:url";var H=class{static{s(this,"LastTextTransactionStore")}#e=new Map;observe(e){let n=ye(e.resourceSource,e.cwd);if(e.postProcessing==="final"){let r=this.#e.get(n),o=e.beforePostProcessing??e.before;r&&r.afterDigest===R(o.content)?this.#e.set(n,{...r,afterDigest:R(e.after.content)}):this.#e.delete(n);return}if(e.intent!=="edit"||!e.existed||e.before.content===e.after.content){this.#e.delete(n);return}this.#e.set(n,{before:e.before.content,afterDigest:R(e.after.content)})}restore(e,n,r){let o=ye(e,n),i=this.#e.get(o);if(i===void 0)throw new Error(`No last text transaction is available for ${e}.`);if(i.afterDigest!==R(r))throw this.#e.delete(o),new Error(`${e} changed after its last text transaction; refusing to overwrite newer text.`);return i.before}};function ye(t,e){return t.startsWith("file://")?we(Ve(new URL(t))):/^[a-z][a-z\d+.-]*:/iu.test(t)?t:we(be.resolve(e,t))}s(ye,"sourceKey");function we(t){try{return ze.native(t)}catch{return be.normalize(t)}}s(we,"canonicalFile");function R(t){return Be("sha256").update(t).digest("hex")}s(R,"textDigest");import{readFile as Qe}from"node:fs/promises";import{defineTool as Ke}from"@earendil-works/pi-coding-agent";import{Text as Xe}from"@earendil-works/pi-tui";import{Type as f}from"typebox";var _=f.Object({action:f.Union([f.Literal("stage"),f.Literal("unstage")]),change:f.String(),file:f.String(),state:f.Optional(f.Union([f.Literal("staged"),f.Literal("unstaged")])),effect:f.Union([f.Literal("applied"),f.Literal("not-applied"),f.Literal("unknown")]),unchanged:f.Optional(f.Boolean())},{additionalProperties:!1}),qe=z(_),A=f.Object({file:f.String({description:"Path to the tracked text file"}),change:f.String({description:"Complete CHANGE#HASH anchor shown by read",pattern:"^CHANGE#[0-9A-F]{4,64}$"})},{additionalProperties:!1}),Ze=f.Object({file:{...A.properties.file,description:"Path to a tracked text file in the current Git worktree. Relative paths resolve from the workspace."},change:{...A.properties.change,description:'Select one complete current CHANGE#HASH anchor returned by read with views: ["changes"].'}},{additionalProperties:!1});function Ee(t,e,n){t.registerTool(Te("stage",e,n)),t.registerTool(Te("unstage",e,n))}s(Ee,"registerIndexChangeTools");function Te(t,e,n){let r=Ye(t,e,n),o=t==="stage"?"Staged":"Unstaged",i=t==="stage"?{...A,properties:{file:{...A.properties.file,description:"Path to the tracked text file, absolute or relative to the current working directory."},change:{...A.properties.change,description:'Use the complete current CHANGE#HASH anchor shown by read with views: ["changes"].'}}}:Ze;return Ke({name:t,exposure:"deferred",namespace:{name:"ide_git",description:"Stage or unstage selected Git changes without changing worktree files."},annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},label:t,promptSnippet:`${o.slice(0,-1)} a selected Git change`,description:t==="stage"?"Use stage to add one selected Git change to the index without changing the worktree file.":"Use unstage to remove one selected Git change from the index. Worktree content is kept.",parameters:i,outputSchema:qe,...t==="stage"&&{renderResult(c,u,a){return new Xe(a.fg("toolOutput",c.content.flatMap(l=>l.type==="text"?[l.text]:[]).join(`
9
+ `)),0,0)}},async execute(c,u,a,l,g){try{let d=await r(u,a,g);return L(d,_,{status:"success",data:{...d.details,effect:d.details.unchanged?"not-applied":"applied"},errors:[]})}catch(d){if(a?.aborted)throw d;let p=D(d,"INDEX_CHANGE_FAILED",u.file);return L({content:[{type:"text",text:p.message}],details:{action:t,change:u.change,file:F(u.file,g.cwd)}},_,{status:"error",data:{action:t,change:u.change,file:F(u.file,g.cwd),effect:Ce(d)},errors:[p]})}}})}s(Te,"createIndexChangeTool");function Ye(t,e,n){let r=t==="stage"?"staged":"unstaged",o=t==="stage"?"Staged":"Unstaged";return async(i,c,u)=>{let a=F(i.file,u.cwd);return W.run(B(a,u.cwd,"write"),()=>n.run(a,c,async()=>{let l=e.readText?await e.readText(a,c):await Qe(a,"utf8"),g=await h.create(e,x(a,u.cwd),c);if(g.status!=="ready")throw new Error(t==="stage"?`Cannot stage ${i.file}: ${g.message}`:g.message);let d=await g.service.changeIndex({source:a,worktreeText:l,cwd:u.cwd,...c!==void 0&&{signal:c}},i.change,t);if(d.status==="unavailable"){if("failure"in d&&d.failure!==void 0){if(t==="stage"&&d.reason==="index-write-failed"){let m=D(d.failure,"INDEX_CHANGE_FAILED",i.file);throw Object.assign(new Error(`${m.message}
10
+ The index may have changed. Read ${i.file} with views: ["changes"] before retrying.`,{cause:d.failure}),{effect:Ce(d.failure)})}throw d.failure}throw t==="stage"&&d.reason==="stale-selector"?Object.assign(new Error(`${d.message}. Read ${i.file} with views: ["changes"] and use a current CHANGE# anchor.`),{effect:"not-applied"}):t==="stage"&&d.reason==="index-write-failed"&&!c?.aborted?new Error(`${d.message}
11
+ The index may have changed. Read ${i.file} with views: ["changes"] before retrying.`):Object.assign(new Error(t==="stage"&&d.reason!=="index-write-failed"?`Cannot stage ${i.file}: ${d.message}`:d.message),{effect:"not-applied"})}if(d.status==="not-applicable"){if(t==="stage"){let m=d.reason==="clean"?"the worktree text matches HEAD":"the file is not present in HEAD";throw new Error(`Cannot stage ${i.file}: ${m}.`)}throw new Error(`${t} is not applicable to ${a}: ${d.reason}`)}let p=d.status==="unchanged";return{content:[{type:"text",text:p?`${i.change} is already ${r} in ${i.file}.`:`${o} ${i.change} in ${i.file}.`}],details:{action:t,change:i.change,file:a,state:r,unchanged:p}}}),c,{waitTimeoutMs:I,waitFor:a})}}s(Ye,"createIndexChangeExecutor");function F(t,e){let n=t.startsWith("@")?t.slice(1):t;return C(n,e)}s(F,"resolveFile");function Ce(t){return t!==null&&typeof t=="object"&&"effect"in t&&(t.effect==="applied"||t.effect==="not-applied")?t.effect:"unknown"}s(Ce,"publicationEffect");import{diffChars as Je}from"diff";import{Type as $}from"typebox";var et=$.Object({file:$.Optional($.Union(V.anyOf,{description:"File path or an unchanged whole-file result. Omit to use the file of the CHANGE# anchor or the last file read."})),change:$.String({description:`A CHANGE#HASH anchor from read with views: ["changes"] reverts that change to HEAD in the worktree and index; last reverts the file's last tool edit.`,pattern:"^(?:CHANGE#[0-9A-F]{4,64}|last)$"})},{additionalProperties:!1});function ve(t,e,n){return{name:"undo",description:"Use undo to revert one uncommitted Git change or the last edit a tool made to a file.",promptSnippet:"Restore a Git change or latest text edit",parameters:et,intent:"restore",source:{field:"file",inherited:!0},anchors:[{field:"change",sourceField:"file",kinds:[P],nonAnchorValues:["last"]}],async mutate(r,o){let i=r.sourceFor("file"),c,u;if(o.change==="last")c=e.restore(i,r.cwd,r.sourceDocument.content);else{await r.resolveAnchor("change");let a=await h.create(t,x(i,r.cwd),r.signal);if(a.status!=="ready")throw new Error(a.message);let l=await a.service.prepareUndo({source:i,worktreeText:r.sourceDocument.content,cwd:r.cwd,...r.signal!==void 0&&{signal:r.signal}},o.change);if(l.status!=="applied")throw l.status==="unavailable"?new Error(l.message):new Error(`Undo is not applicable to ${i}: ${l.reason}`);if(c=l.worktreeText,l.indexUpdate!==void 0){let g=l.indexUpdate;u=s(()=>n.run(i,r.signal,()=>a.service.applyIndexUpdate(g,r.signal)),"afterWrite")}}return{edits:new Map([[i,{changes:tt(r.sourceDocument.content,c),action:"edited"}]]),...u!==void 0&&{afterWrite:u}}}}}s(ve,"createUndoMutationTool");function tt(t,e){let n=0,r=Math.min(t.length,e.length);for(;n<r&&t.charCodeAt(n)===e.charCodeAt(n);)n+=1;let o=t.length,i=e.length;for(;o>n&&i>n&&t.charCodeAt(o-1)===e.charCodeAt(i-1);)o-=1,i-=1;let c=t.slice(n,o),u=e.slice(n,i),a=c.length+u.length<=64e3?Je(c,u,{timeout:50,maxEditLength:1e3}):void 0;if(a===void 0)return[{from:n,to:o,insert:u}];let l=[],g=n,d,p=0,T="",m=s(()=>{d!==void 0&&(l.push({from:d,to:d+p,insert:T}),d=void 0,p=0,T="")},"flush");for(let y of a){if(!y.added&&!y.removed){m(),g+=y.value.length;continue}d??=g,y.removed?(g+=y.value.length,p+=y.value.length):T+=y.value}return m(),l}s(tt,"createTextChanges");function nt(t){return rt(t,pe(t))}s(nt,"registerGitChanges");async function rt(t,e){se(t,[await ae({id:"git-changes",description:"Git change anchors, staging, and safe undo",triggers:["stage","unstage","undo"].map(a=>({tool:a}))})]);let n=new H,r=new S,o=xe(e),i=me(e),c={protocol:Q,apiVersion:K,id:"current-git-changes",setup(a){a.addView({view:"changes",presenter:o}),a.describe({views:"changes \u2014 uncommitted Git edits with CHANGE# anchors."})}},u={protocol:Z,apiVersion:Y,id:"current-git-changes",setup(a){a.addAnchorResolver({...i,kind:P,type:"auxiliary"}),a.onDidEdit(l=>{n.observe(l)}),a.addMutationTool(ve(e,n,r)),a.addTextPresenter({presenter:o})}};await Promise.all([te(t,le),X(t,c),ne(t,u)]),Ee(t,e,r)}s(rt,"registerGitChangesWithExecutor");export{nt as a,rt as b};
@@ -1 +1 @@
1
- import{j as s}from"./chunk-S3T5NOSL.js";import{a as i}from"./chunk-EI7MMDWY.js";import{copyFile as c,mkdtemp as l,rm as p}from"node:fs/promises";import a from"node:path";function d(o){let e=o.workspace;return{environment:o.env,signal:o.signal,...e?{layerAccess:{paths:i((r,t,n)=>e.configPaths(t,n),"paths"),async readText(r,t){let n=await e.readText(r,t);if(n===void 0)throw Object.assign(new Error(`ENOENT: ${r}`),{code:"ENOENT"});return n}},executableAvailability:i((r,t)=>e.executableAvailability(r,t),"executableAvailability"),recipeEvidence:i((r,t)=>e.evidence(r,t),"recipeEvidence")}:{}}}i(d,"doctorRuntimeOptions");function f(o){let e=o.workspace;return e?{run:i((r,t)=>e.run(r,t.filePath,t.signal),"run")}:void 0}i(f,"doctorProcessAccess");async function u(o,e){if(o.signal?.throwIfAborted(),!o.workspace)return s(e,o.cwd,o.env,o.signal);let r=await o.workspace.executableAvailability([e],o.signal);if(o.signal?.throwIfAborted(),r.length!==1||typeof r[0]!="boolean")throw new TypeError("Invalid Doctor executable availability report");return r[0]}i(u,"doctorExecutableAvailable");async function w(o,e,r){if(o.signal?.throwIfAborted(),o.workspace)return o.workspace.withProbeCopy(e,r,o.signal);if(e.includes("://"))throw Object.assign(new Error(`Doctor requires the owner of ${e}`),{code:"UNSUPPORTED_SOURCE"});let t=await l(a.join(a.dirname(e),".pi-agent-ide-doctor-")),n=a.join(t,a.basename(e));try{return await c(e,n),o.signal?.throwIfAborted(),await r(n)}finally{await p(t,{recursive:!0,force:!0})}}i(w,"withDoctorProbeCopy");export{d as a,f as b,u as c,w as d};
1
+ import{j as s}from"./chunk-OA26FH5G.js";import{a as i}from"./chunk-EI7MMDWY.js";import{copyFile as c,mkdtemp as l,rm as p}from"node:fs/promises";import a from"node:path";function d(o){let e=o.workspace;return{environment:o.env,signal:o.signal,...e?{layerAccess:{paths:i((r,t,n)=>e.configPaths(t,n),"paths"),async readText(r,t){let n=await e.readText(r,t);if(n===void 0)throw Object.assign(new Error(`ENOENT: ${r}`),{code:"ENOENT"});return n}},executableAvailability:i((r,t)=>e.executableAvailability(r,t),"executableAvailability"),recipeEvidence:i((r,t)=>e.evidence(r,t),"recipeEvidence")}:{}}}i(d,"doctorRuntimeOptions");function f(o){let e=o.workspace;return e?{run:i((r,t)=>e.run(r,t.filePath,t.signal),"run")}:void 0}i(f,"doctorProcessAccess");async function u(o,e){if(o.signal?.throwIfAborted(),!o.workspace)return s(e,o.cwd,o.env,o.signal);let r=await o.workspace.executableAvailability([e],o.signal);if(o.signal?.throwIfAborted(),r.length!==1||typeof r[0]!="boolean")throw new TypeError("Invalid Doctor executable availability report");return r[0]}i(u,"doctorExecutableAvailable");async function w(o,e,r){if(o.signal?.throwIfAborted(),o.workspace)return o.workspace.withProbeCopy(e,r,o.signal);if(e.includes("://"))throw Object.assign(new Error(`Doctor requires the owner of ${e}`),{code:"UNSUPPORTED_SOURCE"});let t=await l(a.join(a.dirname(e),".pi-agent-ide-doctor-")),n=a.join(t,a.basename(e));try{return await c(e,n),o.signal?.throwIfAborted(),await r(n)}finally{await p(t,{recursive:!0,force:!0})}}i(w,"withDoctorProbeCopy");export{d as a,f as b,u as c,w as d};
@@ -0,0 +1 @@
1
+ import{d as S,h as P,n as R}from"./chunk-XEPCURYZ.js";import{a as E,c as x,d as T,n as h,p as w}from"./chunk-OEEE5BLN.js";import{a as b}from"./chunk-ZC65Z3CK.js";import{a as o}from"./chunk-EI7MMDWY.js";import{AsyncLocalStorage as v}from"node:async_hooks";var g=new v,y=new v;function _(t){let e=y.getStore();e?e.push(t):t()}o(_,"afterPostEditScope");async function A(t){if(y.getStore())return t();let e=[];try{return await y.run(e,t)}finally{for(let r of e)r()}}o(A,"collectPostEditNotifications");function U(t,e){let r=g.getStore();return r?r.immediate?(r.pending.delete(t),!1):(r.pending.set(t,e),!0):!1}o(U,"deferPostEdit");function M(t){return g.getStore()?.pending.has(t)??!1}o(M,"hasDeferredPostEdit");function z(t){g.getStore()?.pending.delete(t)}o(z,"forgetDeferredPostEdit");function N(t=process.cwd()){let e=new Map;return{run(r,a=!1){return g.run({pending:e,immediate:a},r)},forget(r){e.delete(r)},sources(){return[...e.keys()]},async finish(r,a){let s=[...e];e.clear();let u=[],i=[];if(await A(async()=>{let l=new E,D=await Promise.allSettled(s.map(([p,d])=>h("editor post-processing",p,T,void 0,"applied",c=>l.run(w(p,t,"write"),()=>d(c),c,{waitTimeoutMs:x,waitFor:p}),c=>{throw c})));for(let[p,d]of D.entries()){let c=b(s[p])[0];if(d.status==="rejected"){i.push(d.reason);try{a?.(c,d.reason)}catch(f){i.push(f)}continue}u.push(d.value);try{r?.(d.value)}catch(f){i.push(f);try{a?.(c,f)}catch(C){i.push(C)}}}}),i.length>0)throw new AggregateError(i,`Some final post-processing failed; completed edits remain applied. ${i.map(l=>l instanceof Error?l.message:String(l)).join("; ")}`);return u}}}o(N,"createPostEditScope");import{Type as n}from"typebox";import{Value as m}from"typebox/value";var H=`${S}/post-edit/register`;function G(t){return m.Check(n.Object({formatting:n.Object({status:n.Union(["disabled","unavailable","skipped-syntax","skipped-style","unchanged","changed","failed","not-reported","deferred"].map(e=>n.Literal(e))),formatter:n.Optional(n.String())})}),t)}o(G,"isFormattingContribution");function K(t){return m.Check(n.Object({diffStatuses:n.Array(n.Object({text:n.String({minLength:1}),origin:n.Optional(n.Literal("after-edit")),formatter:n.Optional(n.String()),tone:n.Optional(n.Union(["muted","success","warning","error"].map(e=>n.Literal(e))))}))}),t)}o(K,"isDiffStatusContribution");var k=n.Function([],n.Unknown()),O=n.Object({id:n.String({minLength:1}),handler:k}),I=n.Object({registration:O,accept:k});function j(t){return m.Check(O,t)}o(j,"isTextPostEditHandlerRegistration");function Y(t){return m.Check(I,t)}o(Y,"isTextPostEditHandlerRegistrationRequest");function J(t){if(typeof t!="object"||t===null)return!1;let e=t;return Array.isArray(e.hints)&&typeof e.scopeMarkers=="object"&&e.scopeMarkers!==null&&Array.isArray(e.warnings)}o(J,"isTextMutationResultContributionData");function Q(t,e){if(!j(e))throw new TypeError("Invalid text editor post-edit handler registration");let r,a=o(()=>{let u={registration:e,accept(i){if(r!==void 0)throw new Error(`Post-edit handler ${e.id} was accepted more than once`);r=i}};return t.events.emit(H,u),r!==void 0},"announce"),s=o(()=>{},"unsubscribeReady");s=t.events.on(P,u=>{if(!R(u))throw new Error("Invalid pi-agent-text-editor core readiness event");if(!a())throw new Error("pi-agent-text-editor core announced readiness without accepting the post-edit handler");s()}),t.on("session_shutdown",()=>{s(),r?.()}),a()&&s()}o(Q,"connectTextEditorPostEditHandler");export{_ as a,A as b,U as c,M as d,z as e,N as f,H as g,G as h,K as i,j,Y as k,J as l,Q as m};
@@ -1 +1 @@
1
- import{a as u}from"./chunk-S7E2D5K7.js";import{a as d}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";var y=Symbol.for("pi-agent-text-editor/TextSelectionAnchor"),x=class extends u{constructor(t,o,i,p){let c=i.map(r=>({start:{...r.start},end:{...r.end},...r.linewise===!0&&{linewise:!0}}));m(c);super(t,d(c[0]).start.lineNumber);this.source=o;if(o.length===0)throw new TypeError("Text selection anchor source must be non-empty");if(this.ranges=c,p!==void 0){let r=p.map(s=>({start:{...s.start},end:{...s.end},...s.linewise===!0&&{linewise:!0}}));if(m(r),r.length!==c.length||r.some((s,h)=>{let f=d(c[h]);return l(s.start,f.start)<0||l(s.end,f.end)>0}))throw new RangeError("Endpoint ranges must stay within their corresponding selection ranges");this.endpointRanges=r}}static{a(this,"TextSelectionAnchor")}[y]=!0;ranges;endpointRanges;static is(t){if(!u.is(t))return!1;try{let o=t,i=o.ranges;return o[y]===!0&&typeof o.source=="string"&&o.source.length>0&&Array.isArray(i)&&i.length>0&&i.every(g)&&(o.endpointRanges===void 0||Array.isArray(o.endpointRanges)&&o.endpointRanges.length===i.length&&o.endpointRanges.every(g))}catch{return!1}}};function m(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(!g(t)||l(t.start,t.end)>0)throw new RangeError("Text selection anchor contains an invalid range");if(e!==void 0&&l(t.start,e.end)<0)throw new Error("Text selection anchor ranges must be ordered and must not overlap");e=t}}a(m,"assertSelectionRanges");function g(n){if(typeof n!="object"||n===null)return!1;let e=n;return T(e.start)&&T(e.end)&&(e.linewise===void 0||typeof e.linewise=="boolean")}a(g,"isTextSelectionRange");function T(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}a(T,"isTextSelectionPosition");function l(n,e){return n.lineNumber-e.lineNumber||n.column-e.column}a(l,"comparePositions");export{x as a};
1
+ import{a as u}from"./chunk-IRLWXPL4.js";import{a as d}from"./chunk-ZC65Z3CK.js";import{a}from"./chunk-EI7MMDWY.js";var y=Symbol.for("pi-agent-text-editor/TextSelectionAnchor"),x=class extends u{constructor(t,o,i,p){let c=i.map(r=>({start:{...r.start},end:{...r.end},...r.linewise===!0&&{linewise:!0}}));m(c);super(t,d(c[0]).start.lineNumber);this.source=o;if(o.length===0)throw new TypeError("Text selection anchor source must be non-empty");if(this.ranges=c,p!==void 0){let r=p.map(s=>({start:{...s.start},end:{...s.end},...s.linewise===!0&&{linewise:!0}}));if(m(r),r.length!==c.length||r.some((s,h)=>{let f=d(c[h]);return l(s.start,f.start)<0||l(s.end,f.end)>0}))throw new RangeError("Endpoint ranges must stay within their corresponding selection ranges");this.endpointRanges=r}}static{a(this,"TextSelectionAnchor")}[y]=!0;ranges;endpointRanges;static is(t){if(!u.is(t))return!1;try{let o=t,i=o.ranges;return o[y]===!0&&typeof o.source=="string"&&o.source.length>0&&Array.isArray(i)&&i.length>0&&i.every(g)&&(o.endpointRanges===void 0||Array.isArray(o.endpointRanges)&&o.endpointRanges.length===i.length&&o.endpointRanges.every(g))}catch{return!1}}};function m(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(!g(t)||l(t.start,t.end)>0)throw new RangeError("Text selection anchor contains an invalid range");if(e!==void 0&&l(t.start,e.end)<0)throw new Error("Text selection anchor ranges must be ordered and must not overlap");e=t}}a(m,"assertSelectionRanges");function g(n){if(typeof n!="object"||n===null)return!1;let e=n;return T(e.start)&&T(e.end)&&(e.linewise===void 0||typeof e.linewise=="boolean")}a(g,"isTextSelectionRange");function T(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}a(T,"isTextSelectionPosition");function l(n,e){return n.lineNumber-e.lineNumber||n.column-e.column}a(l,"comparePositions");export{x as a};
@@ -0,0 +1 @@
1
+ import{c as d,i as w,j as o}from"./chunk-S4GTWS2J.js";import{a as m}from"./chunk-EI7MMDWY.js";async function h(i,n,e,t,s){return w(i,n,e,t,{...s,effect:"not-applied"})}m(h,"readOwnedSshCommand");import{Type as p}from"typebox";import{Value as f}from"typebox/value";var S=p.Object({html:p.String(),source:p.String()}),c=new Set(["CAPABILITY_UNAVAILABLE","INVALID_SOURCE","BYTE_LIMIT","TIMEOUT","HTTP_FAILED","BROWSER_FAILED","CANCELLED"]),u=d(new URL("./web-browser-worker.mjs",new URL("../src/backend/web-browser.ts",import.meta.url).href));async function B(i,n,e,t){let s=await l(i,n,e,t,"html");if(!f.Check(S,s)||Buffer.byteLength(s.html,"utf8")>16*1024*1024)throw new o("INVALID_RESPONSE",e,"not-applied");let r=new URL(s.source);if(!["http:","https:"].includes(r.protocol)||r.username||r.password)throw new o("INVALID_RESPONSE",e,"not-applied");return s}m(B,"readSshBrowserPage");async function N(i,n,e){let t=await l(i,new URL("about:blank"),n,{signal:e,timeoutMs:3e4},"probe");if(!f.Check(p.Object({ready:p.Literal(!0)}),t))throw new o("INVALID_RESPONSE",n,"not-applied")}m(N,"probeSshBrowser");async function l(i,n,e,t,s){t.signal?.throwIfAborted();try{let r=await h(i,"node",["--input-type=module","-e",await u,JSON.stringify({kind:s,url:n.href,timeoutMs:t.timeoutMs})],e,{signal:t.signal,timeoutMs:t.timeoutMs,maxBytes:33554432});if(r.exitCode!==0)throw new o("BROWSER_FAILED",e,"not-applied");let a;try{a=JSON.parse(r.stdout.toString("utf8"))}catch{throw new o("INVALID_RESPONSE",e,"not-applied")}if(typeof a=="object"&&a!==null&&"error"in a)throw new o(typeof a.error=="string"&&c.has(a.error)?a.error:"INVALID_RESPONSE",e,"not-applied");return a}catch(r){throw r instanceof o?new o(r.code==="ENOENT"?"CAPABILITY_UNAVAILABLE":r.code,e,r.effect):r}}m(l,"runBrowser");export{h as a,B as b,N as c};
@@ -0,0 +1 @@
1
+ import{v as b,w as x}from"./chunk-3JBQYLJ4.js";import{a as h}from"./chunk-EI7MMDWY.js";import R from"node:path";import{pathToFileURL as M}from"node:url";function q(e,t="this path"){return e<=1e3?`Search ${t} with limit: ${String(e)}`:`Read a bounded window of ${t}, then Search that result`}h(q,"searchCompactionHint");function z(e,t){let r=new Map;for(let n of e){let s=r.get(n.source)??[];s.push(n),r.set(n.source,s)}let a=new Set,c=e.length,i=[...r].sort(([n,s],[m,d])=>d.length-s.length||n.localeCompare(m));for(let[n,s]of i){if(c<=t)break;a.add(n),c-=s.length-1}let u=[],o=t,l=[...r].sort(([n],[s])=>Number(a.has(n))-Number(a.has(s))||n.localeCompare(s));for(let[n,s]of l){if(!a.has(n)){if(s.length>o)continue;u.push({kind:"detailed",source:n,matches:s}),o-=s.length;continue}if(o<1)continue;o--;let m=new Map;for(let y of s){let p=m.get(y.lineText);p===void 0?m.set(y.lineText,{matchCount:1,first:y}):p.matchCount++}let d=[...m].sort(([y,p],[N,P])=>P.matchCount-p.matchCount||y.localeCompare(N)).map(([y,p])=>({text:y,...p})),C=r.size===1?Math.min(o,d.length-1):0,w=d.slice(0,1+C);o-=C,u.push({kind:"compacted",source:n,matchCount:s.length,uniqueLineCount:m.size,groups:w})}return u.sort((n,s)=>n.source.localeCompare(s.source)),{files:u}}h(z,"planSearchPresentation");function T(e,t,r,a,c,i=50){let u=z(t,i),o=new Set(t.map(n=>n.source)).size,l=u.files.map(n=>n.kind==="detailed"?k(n.source,n.matches,a):{path:S(n.source,a),link:M(n.source).href,matchCount:n.matchCount,uniqueLineCount:n.uniqueLineCount,groups:n.groups.map(({text:s,matchCount:m})=>({text:s,matchCount:m})),lines:[]});return{...c!==void 0&&{sessionId:c},query:e,matchCount:t.length,fileCount:o,...u.files.length<o?{omittedFileCount:o-l.length,omittedMatchCount:t.length-l.reduce((n,s)=>n+s.matchCount,0)}:{},complete:r,files:l}}h(T,"createSearchToolDetails");function H(e,t){return{fileCount:new Set(e.flatMap(r=>r.matches.map(a=>a.source))).size,groups:e.map(r=>{let c=T(r.identifier,r.matches.slice(0,b.previewMatches),r.complete,t).files.map(i=>{let u=i.lines.map(o=>{let l=Math.max(0,(o.ranges[0]?.from??0)-64),n=Math.min(o.text.length,(o.ranges[0]?.to??0)+64),s=l>0?"\u2026":"",m=o.ranges.filter(d=>d.from>=l&&d.to<=n).map(d=>({from:d.from-l+s.length,to:d.to-l+s.length}));return{...o,text:s+o.text.slice(l,n)+(n<o.text.length?"\u2026":""),ranges:m,matchCount:m.length}});return{...i,lines:u,matchCount:u.reduce((o,l)=>o+l.matchCount,0)}});return{identifier:r.identifier,files:c}})}}h(H,"createFuzzyPresentation");function L(e){return g(e)&&f(e.fileCount)&&Array.isArray(e.groups)&&e.groups.every(t=>g(t)&&typeof t.identifier=="string"&&Array.isArray(t.files)&&t.files.every(F))}h(L,"isFuzzyPresentation");function W(e){if(!g(e)||typeof e.query!="string"||!f(e.matchCount)||!f(e.fileCount)||e.omittedFileCount!==void 0&&!f(e.omittedFileCount)||e.omittedMatchCount!==void 0&&!f(e.omittedMatchCount)||typeof e.complete!="boolean"||e.sessionId!==void 0&&typeof e.sessionId!="string"||e.fuzzy!==void 0&&!x(e.fuzzy)||e.fuzzyPresentation!==void 0&&!L(e.fuzzyPresentation)||!Array.isArray(e.files)||!e.files.every(F))return!1;let t=e.files;return e.fileCount===t.length+(e.omittedFileCount??0)&&e.matchCount===t.reduce((r,a)=>r+a.matchCount,0)+(e.omittedMatchCount??0)}h(W,"isSearchToolDetails");function k(e,t,r){let a=new Map;for(let i of t){let u=a.get(i.lineNumber);if(u!==void 0&&u.text!==i.lineText)throw new Error(`Search results disagree about line ${String(i.lineNumber)} in ${e}.`);let o=u??{lineNumber:i.lineNumber,text:i.lineText,ranges:[]};o.ranges.push({from:i.startColumn,to:i.endLineNumber===void 0?i.endColumn:i.lineText.length}),a.set(i.lineNumber,o)}let c=[...a.values()].sort((i,u)=>i.lineNumber-u.lineNumber).map(i=>{let u=[...i.ranges].sort((o,l)=>o.from-l.from||o.to-l.to);return{lineNumber:i.lineNumber,text:i.text,matchCount:u.length,ranges:u}});return{path:S(e,r),link:M(e).href,matchCount:t.length,lines:c}}h(k,"createSearchResultFile");function F(e){if(!g(e)||typeof e.path!="string"||typeof e.link!="string"||!f(e.matchCount)||!Array.isArray(e.lines)||!e.lines.every(A))return!1;let t=e.lines,r=e.groups,a=new Set(t.flatMap(c=>c.logicalMatchIds??[]));return(r===void 0||Array.isArray(r)&&r.every(c=>g(c)&&typeof c.text=="string"&&f(c.matchCount)))&&(e.uniqueLineCount===void 0||f(e.uniqueLineCount))&&(t.length===0||(a.size>0?a.size===e.matchCount:e.matchCount===t.reduce((c,i)=>c+i.matchCount,0)))}h(F,"isSearchResultFile");function A(e){return g(e)&&Number.isSafeInteger(e.lineNumber)&&e.lineNumber>=1&&typeof e.text=="string"&&f(e.matchCount)&&Array.isArray(e.ranges)&&e.ranges.length===e.matchCount&&(e.logicalMatchIds===void 0||Array.isArray(e.logicalMatchIds)&&e.logicalMatchIds.every(t=>typeof t=="string"))&&e.ranges.every(t=>I(t,e.text))}h(A,"isSearchResultLine");function I(e,t){return g(e)&&Number.isSafeInteger(e.from)&&Number.isSafeInteger(e.to)&&e.from>=0&&e.to>e.from&&e.to<=t.length}h(I,"isSearchResultRange");function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}h(g,"isRecord");function f(e){return Number.isSafeInteger(e)&&e>=0}h(f,"isCount");function S(e,t){if(e.includes("://"))return e;let r=R.relative(t,e);return r.length>0&&!r.startsWith("..")&&!R.isAbsolute(r)?r:e}h(S,"displaySource");function J(e,t){let r=e.count===1?"1 path":`${e.count} paths`,{path:a,error:c}=e.first;return`Search notice: could not read ${r}, so matches in them are missing. First: ${S(a,t)}: ${c}`}h(J,"unreadableNotice");export{q as a,z as b,T as c,H as d,W as e,S as f,J as g};