pi-agent-ide 0.7.0 → 0.7.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 (218) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/chunk-2TRHFMCZ.js +11 -0
  3. package/dist/{chunk-FXNKMNSJ.js → chunk-4GCWGE2C.js} +1 -1
  4. package/dist/chunk-4XMY4H4V.js +1 -0
  5. package/dist/{chunk-3HYXQ4YA.js → chunk-76ZK5ODR.js} +2 -2
  6. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  7. package/dist/chunk-CWD4O5PM.js +3 -0
  8. package/dist/chunk-D3WTDA6V.js +2 -0
  9. package/dist/chunk-GXEGY7GV.js +1 -0
  10. package/dist/{chunk-GBLKIB6O.js → chunk-HZEY4GT4.js} +1 -1
  11. package/dist/{chunk-S5LXX32D.js → chunk-LEEQIQ7D.js} +6 -6
  12. package/dist/chunk-NRZO5KJT.js +9 -0
  13. package/dist/chunk-OMVRLWMX.js +5 -0
  14. package/dist/{chunk-KR36BT5E.js → chunk-PGIVHICI.js} +1 -1
  15. package/dist/{chunk-YRF7OATP.js → chunk-PKKDDIWW.js} +1 -1
  16. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  17. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  18. package/dist/chunk-VMTR74FF.js +2 -0
  19. package/dist/{chunk-PYPPV2F5.js → chunk-WMO6RNE2.js} +1 -1
  20. package/dist/{chunk-3JO7QFIL.js → chunk-WU6ZK6YD.js} +1 -1
  21. package/dist/{chunk-F5YZG77W.js → chunk-XH5WN5XA.js} +1 -1
  22. package/dist/{chunk-AJRIASPQ.js → chunk-YP46DVVP.js} +1 -1
  23. package/dist/entry-11.js +1 -1
  24. package/dist/entry-13.js +1 -1
  25. package/dist/entry-14.js +1 -1
  26. package/dist/entry-15.js +1 -1
  27. package/dist/entry-17.js +1 -1
  28. package/dist/entry-25.js +2 -2
  29. package/dist/entry-26.js +1 -1
  30. package/dist/entry-27.js +2 -2
  31. package/dist/entry-28.js +1 -1
  32. package/dist/entry-29.js +1 -1
  33. package/dist/entry-31.js +13 -12
  34. package/dist/entry-33.js +1 -1
  35. package/dist/entry-37.js +6 -6
  36. package/dist/entry-41.js +1 -1
  37. package/dist/entry-43.js +1 -1
  38. package/dist/entry-44.js +1 -1
  39. package/dist/entry-45.js +13 -14
  40. package/dist/entry-46.js +1 -1
  41. package/dist/entry-49.js +1 -1
  42. package/dist/entry-50.js +1 -1
  43. package/dist/entry-51.js +2 -2
  44. package/dist/entry-53.js +1 -1
  45. package/dist/entry-54.js +1 -1
  46. package/dist/entry-56.js +1 -1
  47. package/dist/entry-57.js +1 -1
  48. package/dist/entry-58.js +1 -1
  49. package/dist/entry-60.js +1 -1
  50. package/dist/entry-62.js +1 -1
  51. package/dist/entry-65.js +1 -1
  52. package/dist/entry-68.js +1 -1
  53. package/dist/entry-70.js +1 -1
  54. package/dist/entry-75.js +1 -1
  55. package/dist/entry-77.js +33 -34
  56. package/dist/entry-78.js +1 -1
  57. package/dist/entry-79.js +1 -1
  58. package/dist/entry-80.js +1 -1
  59. package/dist/entry-82.js +2 -2
  60. package/dist/entry-83.js +1 -1
  61. package/dist/entry-84.js +1 -1
  62. package/dist/entry-85.js +1 -1
  63. package/dist/entry-86.js +1 -1
  64. package/dist/pi-agent-ide.js +14 -9
  65. package/docs/agent-guides/editing.md +35 -46
  66. package/docs/agent-guides/read-resources.md +5 -9
  67. package/docs/agent-guides/search-code.md +12 -17
  68. package/docs/agent-guides/select-code.md +61 -140
  69. package/docs/structured-results.md +27 -62
  70. package/docs/tools.md +6 -10
  71. package/node_modules/pi-agent-doctor/package.json +1 -1
  72. package/node_modules/pi-agent-documentation/package.json +1 -1
  73. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  74. package/node_modules/pi-agent-filesystem/package.json +7 -7
  75. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  76. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  77. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  78. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  79. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  80. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  81. package/node_modules/pi-agent-ide-ast/src/extension.ts +7 -4
  82. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +35 -6
  83. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  84. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +2 -2
  85. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +18 -1
  86. package/node_modules/pi-agent-ide-changes/index.ts +4 -3
  87. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  88. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  89. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  90. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  91. package/node_modules/pi-agent-ide-lsp/index.ts +3 -3
  92. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  93. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +5 -1
  94. package/node_modules/pi-agent-image/package.json +2 -2
  95. package/node_modules/pi-agent-invariant/package.json +1 -1
  96. package/node_modules/pi-agent-pdf/package.json +2 -2
  97. package/node_modules/pi-agent-read/package.json +7 -7
  98. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  99. package/node_modules/pi-agent-read/src/api/read-parameters.ts +38 -1
  100. package/node_modules/pi-agent-read/src/api/tools/read.ts +7 -1
  101. package/node_modules/pi-agent-read/src/core/extension.ts +7 -1
  102. package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
  103. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  104. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +9 -2
  105. package/node_modules/pi-agent-resource/package.json +1 -1
  106. package/node_modules/pi-agent-resource/src/result-targets.ts +183 -9
  107. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  108. package/node_modules/pi-agent-search/package.json +5 -5
  109. package/node_modules/pi-agent-search/src/api/search-parameters.ts +1 -1
  110. package/node_modules/pi-agent-search-text/index.ts +1 -1
  111. package/node_modules/pi-agent-search-text/package.json +7 -7
  112. package/node_modules/pi-agent-text/package.json +2 -2
  113. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  114. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  115. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  116. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  117. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  118. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  119. package/node_modules/pi-agent-text-editor/package.json +9 -9
  120. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  121. package/node_modules/pi-agent-text-editor/src/core/extension.ts +10 -3
  122. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  123. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +18 -11
  124. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +43 -209
  125. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +37 -31
  126. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  127. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +2 -7
  128. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  129. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +2 -2
  130. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  131. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  132. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  133. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
  134. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  135. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  136. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  137. package/node_modules/pi-agent-web/index.ts +4 -3
  138. package/node_modules/pi-agent-web/package.json +7 -7
  139. package/node_modules/pi-agent-web-html/package.json +2 -2
  140. package/node_modules/pi-agent-web-image/package.json +3 -3
  141. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  142. package/node_modules/pi-agent-web-text/package.json +3 -3
  143. package/package.json +35 -35
  144. package/src/composite/text-results.ts +221 -0
  145. package/src/documentation/extension.ts +11 -9
  146. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  147. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  148. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  149. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  150. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  151. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  152. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  153. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +4 -3
  154. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  155. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  156. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  157. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  158. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  159. package/src/extensions/pi-agent-read/package.json +7 -7
  160. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  161. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +38 -1
  162. package/src/extensions/pi-agent-read/src/api/tools/read.ts +7 -1
  163. package/src/extensions/pi-agent-read/src/core/extension.ts +7 -1
  164. package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
  165. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +3 -3
  166. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +9 -2
  167. package/src/extensions/pi-agent-search/package.json +5 -5
  168. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  169. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
  170. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +1 -1
  171. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  172. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  173. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  174. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  175. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  176. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  177. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  178. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  179. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
  180. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  181. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +10 -3
  182. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +3 -13
  183. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +18 -11
  184. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +43 -209
  185. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +37 -31
  186. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  187. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +2 -7
  188. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  189. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +2 -2
  190. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  191. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  192. package/src/pi-agent-ide.ts +4 -1
  193. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  194. package/src/plugins/pi-agent-ide-ast/src/extension.ts +7 -4
  195. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +35 -6
  196. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +1 -1
  197. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +2 -2
  198. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +18 -1
  199. package/src/plugins/pi-agent-ide-changes/index.ts +4 -3
  200. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  201. package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
  202. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
  203. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  204. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  205. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  206. package/src/plugins/pi-agent-ide-lsp/index.ts +3 -3
  207. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  208. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +5 -1
  209. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  210. package/src/plugins/pi-agent-ide-vision/index.ts +12 -4
  211. package/dist/chunk-4NIFBFFR.js +0 -11
  212. package/dist/chunk-7LZKOHH2.js +0 -1
  213. package/dist/chunk-FK42RSF4.js +0 -1
  214. package/dist/chunk-KBP3QUDT.js +0 -2
  215. package/dist/chunk-OE7QVAI2.js +0 -5
  216. package/dist/chunk-SILJ3OL4.js +0 -9
  217. package/dist/chunk-SQKAXYIR.js +0 -2
  218. package/dist/chunk-VCGNVTXQ.js +0 -1
@@ -0,0 +1,9 @@
1
+ import"./chunk-MPT3R4BL.js";import{a as y,b as A,c as D,d as k}from"./chunk-T7I2VX3J.js";import{a as I}from"./chunk-BU7IZLKB.js";import{a as E,b as P}from"./chunk-S5PL5DFQ.js";import{a as s}from"./chunk-EI7MMDWY.js";var N=/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/,h=class{static{s(this,"AgentDocumentationRegistry")}#e=new Map;register(n){let o=new Set(this.#e.keys());for(let i of n)_(i,o),o.add(i.id);for(let i of n)this.#e.set(i.id,T(i))}list(){return[...this.#e.values()].sort((n,o)=>n.id.localeCompare(o.id))}get(n){return this.#e.get(n)}matching(n,o){let i=v(o);return i?.startsWith("docs:")===!0?[]:this.list().filter(d=>d.triggers.some(a=>{if(a.tool!==n)return!1;let l=a.resourcePrefixes===void 0||i!==void 0&&a.resourcePrefixes.some(r=>i.startsWith(r)),t=a.viewPrefixes===void 0||b(o).some(r=>a.viewPrefixes?.some(u=>r.startsWith(u)));return l&&t}))}};function _(e,n){if(!N.test(e.id))throw new Error(`Invalid documentation ID: ${e.id}`);if(e.description.trim().length===0)throw new Error(`Documentation ${e.id} has no description`);if(e.markdown.trim().length===0)throw new Error(`Documentation ${e.id} has no Markdown content`);if(e.triggers.length===0||e.triggers.some(o=>o.tool.trim().length===0||o.resourcePrefixes?.some(i=>i.length===0)===!0||o.viewPrefixes?.some(i=>i.length===0)===!0))throw new Error(`Documentation ${e.id} has no valid triggers`);if(n.has(e.id))throw new Error(`Documentation ${e.id} is already registered`)}s(_,"validateDocument");function T(e){return Object.freeze({...e,triggers:Object.freeze(e.triggers.map(n=>Object.freeze({...n,...n.resourcePrefixes===void 0?{}:{resourcePrefixes:Object.freeze([...n.resourcePrefixes])},...n.viewPrefixes===void 0?{}:{viewPrefixes:Object.freeze([...n.viewPrefixes])}})))})}s(T,"freezeDocument");function b(e){if(typeof e!="object"||e===null)return[];let n=e.views;return Array.isArray(n)?n.filter(o=>typeof o=="string"):[]}s(b,"readViews");function v(e){if(typeof e!="object"||e===null)return;let n=e.path;return typeof n=="string"?n:void 0}s(v,"readPath");var R="agent-documentation-read";async function M(e){let n=new h,o=new Set,i=new Map,d=new Map,a=s(t=>{let r=t.filter(u=>!o.has(u));if(r.length!==0){e.appendEntry(R,{ids:r});for(let u of r)o.add(u)}},"remember"),l=e.events.on(k,t=>{if(!z(t))throw new Error("Invalid agent documentation registration");n.register(t.documents)});e.on("session_shutdown",l),await I(e,{protocol:E,apiVersion:P,id:"agent-documentation",setup(t){t.addResolver({resolver:{id:"agent-documentation",tryResolve(r){if(!r.startsWith("docs:"))return Promise.resolve({kind:"not-handled"});let u=r.slice(5),m=u.length===0?void 0:n.get(u),g=u.length===0?$(n.list()):m?.markdown;return g===void 0?Promise.resolve({kind:"failed",error:new Error(`Unknown documentation ID: ${u}`)}):Promise.resolve({kind:"resolved",resource:{source:r,read:s(()=>Promise.resolve([{type:"text",text:g}]),"read")}})}}}),t.describe({path:s(()=>n.list().length===0?void 0:"docs: lists packaged agent guidance; docs:<id> reads a listed guide.","path")}),t.addPromptGuideline(()=>j(n.list()))}}),e.on("session_start",(t,r)=>{p(r.sessionManager.getBranch(),n,o)}),e.on("session_tree",(t,r)=>{p(r.sessionManager.getBranch(),n,o)}),e.on("session_compact",(t,r)=>{p(r.sessionManager.getBranch(),n,o)}),e.on("tool_call",t=>{t.toolCallId.includes("-preflight-")||t.parentToolCallId!==void 0&&i.set(t.toolCallId,t.parentToolCallId)}),e.on("tool_result",t=>{if(t.toolCallId.includes("-preflight-"))return;let r=i.get(t.toolCallId);i.delete(t.toolCallId);let u=d.get(t.toolCallId)??[];d.delete(t.toolCallId);let m=t.toolName==="read"?S(t.input):void 0;if(m!==void 0){let c=m.slice(5),C=c.length===0||n.get(c)!==void 0,w=n.get(c);return w!==void 0&&!t.isError&&O(t.content,w)&&a([c]),{content:t.content,structuredContent:t.structuredContent,details:{...f(t.details)?t.details:{},documentation:C?c.length===0?{kind:"list",ids:n.list().map(x=>x.id)}:{kind:"document",id:c}:{kind:"error",code:"UNKNOWN_DOCUMENTATION",id:c}},isError:t.isError}}let g=[...u,...n.matching(t.toolName,t.input).filter(c=>!o.has(c.id))];if(g.length!==0){if(a(g.map(c=>c.id)),r!==void 0){d.set(r,[...d.get(r)??[],...g]);return}return{content:[...t.content,...g.map(c=>({type:"text",text:`
2
+
3
+ ---
4
+
5
+ # Guide: ${c.id}
6
+
7
+ ${c.markdown.trim()}`}))],structuredContent:t.structuredContent,details:{...f(t.details)?t.details:{},documentation:{kind:"attachment",ids:g.map(c=>c.id)}},isError:t.isError}}}),e.events.emit(D,{protocol:y,apiVersion:A})}s(M,"registerProgressiveDocumentation");function $(e){return e.length===0?"No agent documentation is currently available.":["# Available agent documentation","",...e.map(n=>`- \`${n.id}\` \u2014 ${n.description}`)].join(`
8
+ `)}s($,"renderListing");function j(e){if(e.length!==0)return["Read the matching docs:<id> before using any tool or feature with packaged guidance, including tools discovered later or called through Codemode. Read each guide once per branch. Tool descriptions and docs: listings do not replace the full guide.","If a result includes a Guide, read it before your next use. The call has already run: do not repeat it just to obtain documentation. Nested calls keep their guides on the parent result, even when the script does not print the child output.","Available documents:",...e.map(n=>` - ${n.id} \u2014 ${n.description}`)].join(`
9
+ `)}s(j,"renderPromptGuideline");function p(e,n,o){o.clear();for(let d of e){if(!f(d))continue;if(d.type==="custom"&&d.customType===R&&f(d.data)){i(d.data.ids);continue}if(d.type!=="message"||!f(d.message))continue;let a=d.message;if(a.role!=="toolResult"||!f(a.details))continue;let l=a.details.documentation;if(f(l)&&(l.kind==="attachment"&&i(l.ids),l.kind==="document"&&!a.isError&&typeof l.id=="string")){let t=n.get(l.id);t!==void 0&&O(a.content,t)&&i([t.id])}}function i(d){if(Array.isArray(d))for(let a of d)typeof a=="string"&&n.get(a)!==void 0&&o.add(a)}s(i,"addIds")}s(p,"restoreClaims");function O(e,n){return Array.isArray(e)&&e.some(o=>f(o)&&o.type==="text"&&typeof o.text=="string"&&o.text.includes(n.markdown.trim()))}s(O,"containsFullGuide");function S(e){if(!(!f(e)||typeof e.path!="string"||!e.path.startsWith("docs:")))return e.path}s(S,"documentationSource");function z(e){return f(e)&&Array.isArray(e.documents)}s(z,"isRegistrationRequest");function f(e){return typeof e=="object"&&e!==null}s(f,"isRecord");export{M as default};
@@ -0,0 +1,5 @@
1
+ import{a as _}from"./chunk-M5IVSCR2.js";import{e as M,f as V}from"./chunk-T7I2VX3J.js";import{a as O}from"./chunk-BU7IZLKB.js";import{a as T,b as k}from"./chunk-S5PL5DFQ.js";import{a as z}from"./chunk-ZTYWHL2F.js";import{a as W,b as L}from"./chunk-7UGNGK7Y.js";import{a as U}from"./chunk-PS2B6THP.js";import{a as c}from"./chunk-EI7MMDWY.js";import{execFile as te}from"node:child_process";import re from"node:os";import{promisify as oe}from"node:util";import{createCanvas as B,loadImage as se}from"@napi-rs/canvas";var f=oe(te),x=20*1024*1024,H={durationSeconds:2,intervalSeconds:.5,scale:.5},j=new Set;function G(e){let n=A({mode:"sequence",durationSeconds:Number(e.durationSeconds??2),intervalSeconds:Number(e.intervalSeconds??.5),scale:Number(e.scale??.5)});H={durationSeconds:n.durationSeconds,intervalSeconds:n.intervalSeconds,scale:n.scale},j=new Set((e.allowedExecutables??"").split(",").map(o=>o.trim().toLowerCase()).filter(Boolean))}c(G,"configureVision");function h(){return H}c(h,"getVisionDefaults");function X(e){let n=e.includes("\\")?e.slice(e.lastIndexOf("\\")+1):e,o=n.trim().split(/\s+/u)[0]??"",r=o.slice(o.lastIndexOf("/")+1);return j.has((e.includes("\\")?n:r).toLowerCase())}c(X,"isExecutableAllowed");function Y(e,n){let o=e?.filter(s=>/^(?:image|sequence)(?::|$)/u.test(s))??[];if(o.length===0)return;if(o.length>1)throw new Error("Use only one image or sequence view");let r=o[0],i=r.indexOf(":"),a=r.slice(0,i<0?void 0:i),t={};if(i>=0&&ie(r.slice(i+1),t),a==="image"&&(t.duration!==void 0||t.interval!==void 0))throw new Error("duration and interval are supported only by the sequence view");return A({mode:a,durationSeconds:t.duration??n.durationSeconds,intervalSeconds:t.interval??n.intervalSeconds,scale:t.scale??n.scale,...t.region===void 0?{}:{region:t.region}})}c(Y,"parseVisionView");function ie(e,n){if(e.length===0)throw new Error("View parameters cannot be empty");let o=e.split(",");for(let r=0;r<o.length;r+=1){let i=o[r],a=i.indexOf("=");if(a<=0)throw new Error(`Invalid view parameter ${i}`);let t=i.slice(0,a),s=i.slice(a+1);if(t==="region"){let u=[s,o[r+1],o[r+2],o[r+3]].map(Number);if(u.some(l=>!Number.isFinite(l)))throw new Error("region requires x,y,width,height values");n.region={x:u[0],y:u[1],width:u[2],height:u[3]},r+=3;continue}if(t!=="duration"&&t!=="interval"&&t!=="scale")throw new Error(`Unknown view parameter ${t}`);let d=Number(s);if(!Number.isFinite(d))throw new Error(`View parameter ${t} must be a number`);if(n[t]!==void 0)throw new Error(`Duplicate view parameter ${t}`);n[t]=d}}c(ie,"parseViewParameters");function J(e){if(!e.startsWith("display:"))return;if(e==="display:")return 0;let n=/^display:#(\d+)$/u.exec(e);if(n===null)throw new Error("Display sources use display: or display:#N with a zero-based index");let o=Number(n[1]);if(!Number.isSafeInteger(o))throw new Error("Display sources use display: or display:#N with a zero-based index");return o}c(J,"parseDisplaySource");async function I(e){let n=new Map(e.list().flatMap(i=>i.pid===void 0?[]:[[i.pid,i]]));if(process.platform!=="linux"&&process.platform!=="darwin")return[...n].map(([i,a])=>({pid:i,command:a.description,owned:!0,source:a.source,host:"local"}));let{stdout:o}=await f("ps",["-eo","pid=,ppid=,lstart=,args="],{maxBuffer:4*1024*1024}),r=o.split(`
2
+ `).flatMap(i=>{let a=/^\s*(\d+)\s+(\d+)\s+(\S+\s+\S+\s+\d+\s+\d+:\d+:\d+\s+\d+)\s+(.*)$/u.exec(i);if(a===null)return[];let t=Number(a[1]),s=n.get(t);return[{pid:t,parentPid:Number(a[2]),started:a[3],command:a[4]??"",owned:s!==void 0,host:"local",...s===void 0?{}:{source:s.source}}]});return P()?[...r,...await ae()]:r}c(I,"listProcesses");async function ae(){try{let{stdout:e}=await f("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-Command","Get-Process | Select-Object Id,ProcessName,Path,StartTime | ConvertTo-Json -Compress"],{maxBuffer:4194304}),n=JSON.parse(e);return(Array.isArray(n)?n:[n]).flatMap(r=>{if(typeof r!="object"||r===null||!("Id"in r)||typeof r.Id!="number")return[];let i="ProcessName"in r&&typeof r.ProcessName=="string"?r.ProcessName:"Windows process",a="Path"in r&&typeof r.Path=="string"?r.Path:void 0,t="StartTime"in r&&typeof r.StartTime=="string"?r.StartTime:void 0;return[{pid:r.Id,command:a??i,owned:!1,host:"windows",...t===void 0?{}:{started:t}}]})}catch{return[]}}c(ae,"listWindowsProcesses");async function E(e,n){if(!Number.isSafeInteger(e)||e<=0)throw new Error("Process PID must be a positive integer");let o=(await I(n)).find(r=>r.pid===e);if(o===void 0)throw new Error(`Process ${e} is not running`);return o}c(E,"readProcess");function A(e){let n=e.scale??1;if(!(n>0&&n<=1))throw new Error("Image scale must be greater than 0 and at most 1");let o=e.durationSeconds??0,r=e.intervalSeconds??1;if(e.mode==="sequence"){if(!(o>0&&o<=10))throw new Error("Sequence duration must be greater than 0 and at most 10 seconds");if(!(r>0))throw new Error("Sequence interval must be greater than 0 seconds");if(Math.floor(o/r)+1>20)throw new Error("Sequence capture is limited to 20 frames")}if(e.region!==void 0){let{x:i,y:a,width:t,height:s}=e.region;if(i<0||a<0||t<=0||s<=0||i+t>1||a+s>1)throw new Error("Image region x,y,width,height must fit within normalized bounds 0..1")}if(e.cellIndex!==void 0&&e.cellSize===void 0)throw new Error("Image offset requires limit to set the square grid cell size");if(e.cellSize!==void 0&&(!Number.isSafeInteger(e.cellSize)||e.cellSize<=0))throw new Error("Image limit must be a positive integer pixel size");if(e.cellIndex!==void 0&&(!Number.isSafeInteger(e.cellIndex)||e.cellIndex<0))throw new Error("Image offset must be a zero-based cell index");return e}c(A,"validateVisionOptions");async function y(e,n,o){let r=A(n),i=r.mode==="image"?1:Math.floor(r.durationSeconds/r.intervalSeconds)+1,a=[],t=0;for(let s=0;s<i;s+=1){o?.throwIfAborted(),s>0&&await pe(r.intervalSeconds*1e3,o);let d=await e();if(t+=d.byteLength,t>x)throw new Error("Captured images exceed the 20MB aggregate limit");for(let u of await ce(d,r))a.push({type:"image",data:Buffer.from(u).toString("base64"),mimeType:"image/png"})}return a}c(y,"captureImages");async function ce(e,n){let o=await se(e),r=n.region??{x:0,y:0,width:1,height:1},i=Math.round(r.x*o.width),a=Math.round(r.y*o.height),t=Math.max(1,Math.round(r.width*o.width)),s=Math.max(1,Math.round(r.height*o.height)),d=n.scale??1,u=Math.max(1,Math.round(t*d)),l=Math.max(1,Math.round(s*d)),m=B(u,l);if(m.getContext("2d").drawImage(o,i,a,t,s,0,0,u,l),n.cellSize===void 0)return[await m.encode("png")];let p=Math.ceil(u/n.cellSize),N=Math.ceil(l/n.cellSize),g=n.cellIndex??0;if(g>=p*N)throw new Error(`Image cell offset ${g} exceeds the ${p}x${N} grid`);let ee=g%p,ne=Math.floor(g/p),q=ee*n.cellSize,$=ne*n.cellSize,v=Math.min(n.cellSize,u-q),S=Math.min(n.cellSize,l-$),C=B(v,S);return C.getContext("2d").drawImage(m,q,$,v,S,0,0,v,S),[await C.encode("png")]}c(ce,"selectImage");function de(e,n){return e&&n==="windows"}c(de,"usesWindowsHostWindowCapture");function K(){return{async captureWindow(e,n,o){if(o?.throwIfAborted(),de(P(),n))return ue(e,o);if(process.platform!=="linux"&&process.platform!=="darwin")throw new Error(`Window capture is unsupported on ${process.platform}`);let{Window:r}=await import("node-screenshots"),i;try{i=r.all()}catch(s){throw new Error(`Desktop window enumeration is unavailable: ${F(s)}`,{cause:s})}let a=i.find(s=>{try{return s.pid()===e}catch{return!1}});if(a===void 0)throw new Error(`No capturable desktop window belongs to PID ${e}`);let t=await a.captureImage();return o?.throwIfAborted(),new Uint8Array(await t.toPng())},async captureDisplay(e,n){if(n?.throwIfAborted(),P())return le(e,n);if(process.platform!=="linux"&&process.platform!=="darwin"&&process.platform!=="win32")throw new Error(`Display capture is unsupported on ${process.platform}`);let{Monitor:o}=await import("node-screenshots"),r;try{r=o.all()}catch(t){throw new Error(`Desktop display enumeration is unavailable: ${F(t)}`,{cause:t})}let i=r[e];if(i===void 0)throw new Error(`Display index ${e} is unavailable; found ${r.length} display(s)`);let a=await i.captureImage();return n?.throwIfAborted(),new Uint8Array(await a.toPng())},async captureUrl(e,n){if(e.protocol!=="http:"&&e.protocol!=="https:")throw new Error("Web screenshots require an HTTP(S) URL");let{chromium:o}=await import("playwright-core"),r=await me(),i=await o.launch({executablePath:r,headless:!0,chromiumSandbox:!1,timeout:3e4}),a=c(()=>{i.close()},"abort");n?.addEventListener("abort",a,{once:!0});try{let t=await i.newPage({viewport:{width:1280,height:720}});return await t.goto(e.href,{waitUntil:"domcontentloaded",timeout:3e4}),await t.waitForLoadState("networkidle",{timeout:1500}).catch(()=>{}),n?.throwIfAborted(),new Uint8Array(await t.screenshot({type:"png",fullPage:!0}))}finally{n?.removeEventListener("abort",a),await i.close().catch(()=>{})}}}}c(K,"createCaptureBackend");async function ue(e,n){let o=new URL("windows-window-capture.ps1",new URL("../src/plugins/pi-agent-ide-vision/src/vision.ts",import.meta.url).href);n?.throwIfAborted();let{stdout:r}=await f("wslpath",["-w",o.pathname],{signal:n}),{stdout:i}=await f("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",r.trim(),"-ProcessId",String(e)],{encoding:"buffer",maxBuffer:x,signal:n});return new Uint8Array(i)}c(ue,"captureWslWindow");async function le(e,n){let o=new URL("windows-display-capture.ps1",new URL("../src/plugins/pi-agent-ide-vision/src/vision.ts",import.meta.url).href);n?.throwIfAborted();let{stdout:r}=await f("wslpath",["-w",o.pathname],{signal:n}),{stdout:i}=await f("powershell.exe",["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",r.trim(),"-DisplayIndex",String(e)],{encoding:"buffer",maxBuffer:x,signal:n});return new Uint8Array(i)}c(le,"captureWslDisplay");function P(){return process.platform==="linux"&&(process.env.WSL_DISTRO_NAME!==void 0||re.release().toLowerCase().includes("microsoft"))}c(P,"isWsl");async function me(){let e=process.env.PI_AGENT_IDE_BROWSER_PATH;if(e!==void 0)return e;let{stdout:n}=await f("bash",["-lc","command -v google-chrome-stable || command -v google-chrome || command -v chromium || command -v chromium-browser"]),o=n.trim();if(o.length===0)throw new Error("No Chrome or Chromium executable was found; set PI_AGENT_IDE_BROWSER_PATH");return o}c(me,"resolveBrowser");function pe(e,n){return new Promise((o,r)=>{let i=setTimeout(o,e),a=c(()=>{clearTimeout(i),r(n?.reason??new Error("Capture aborted"))},"abort");n?.addEventListener("abort",a,{once:!0}),i.unref()})}c(pe,"delay");function F(e){return e instanceof Error?e.message:String(e)}c(F,"errorMessage");async function fe(e,n){V(e,[await M({id:"vision",description:"Window, display, image, and sequence capture",triggers:[{tool:"read",resourcePrefixes:["window:","display:"]}]})]);let o=n?.preferences??{};G({durationSeconds:o["vision.sequenceDurationSeconds"],intervalSeconds:o["vision.sequenceIntervalSeconds"],scale:o["vision.imageScale"],allowedExecutables:o["vision.allowedExecutables"]});let r=_(e),i=K();await Promise.all([O(e,{protocol:T,apiVersion:k,id:"vision",setup(a){for(let t of["image","sequence"])a.addView({view:t,presenter:{id:`vision-${t}`,present:c(s=>s,"present")}});a.addHandler({stage:"pre-read",async handler(t){let s=t.request.path;if(s===void 0)return{kind:"continue",context:t};let d=J(s);if(d!==void 0){if(e.getFlag("pi-agent-ide-vision-displays")!==!0)return w(s,"Display capture is disabled. Enable --pi-agent-ide-vision-displays to allow it.");try{let m=await y(()=>i.captureDisplay(d,t.resolverContext.signal),R(t.request),t.resolverContext.signal);return b(s,m)}catch(m){return w(s,D(m))}}let u=Q(s,"process:");if(u!==void 0){let m=await E(u,r);return b(s,[{type:"text",text:Z(m)}])}let l=Q(s,"window:");if(l!==void 0){let m=await E(l,r);if(!m.owned&&!X(m.command)&&e.getFlag("pi-agent-ide-vision-arbitrary-windows")!==!0)return w(s,`Window capture for PID ${l} is denied because the process is neither Agent IDE-owned nor allowlisted by executable name. Enable --pi-agent-ide-vision-arbitrary-windows to allow it.`);try{let p=await y(()=>i.captureWindow(l,m.host,t.resolverContext.signal),R(t.request),t.resolverContext.signal);return b(s,p)}catch(p){return w(s,D(p))}}if(/^https?:\/\//iu.test(s)&&we(t.request)){let m=new URL(s);try{let p=await y(()=>i.captureUrl(m,t.resolverContext.signal),R(t.request),t.resolverContext.signal);return b(m.href,p)}catch(p){return w(m.href,D(p))}}return{kind:"continue",context:t}}}),a.describe({path:c(()=>`process:PID \u2014 process metadata. window:PID \u2014 capture a window of an IDE-owned or allowlisted process${e.getFlag("pi-agent-ide-vision-arbitrary-windows")===!0?"; arbitrary windows are enabled":"; other processes require --pi-agent-ide-vision-arbitrary-windows"}. display: or display:#N \u2014 display capture with a zero-based index; ${e.getFlag("pi-agent-ide-vision-displays")===!0?"enabled":"requires --pi-agent-ide-vision-displays"}. HTTP(S) URLs accept image or sequence screenshots.`,"path"),views:c(()=>{let t=h();return`image or image:scale=S,region=X,Y,W,H \u2014 one screenshot. sequence or sequence:duration=D,interval=I,scale=S,region=X,Y,W,H \u2014 timed frames. Only one image/sequence view per request. duration and interval are seconds and only valid for sequence: 0 < D <= 10, I > 0, at most 20 frames (floor(D/I)+1). Scale satisfies 0 < S <= 1. Region uses normalized x,y,width,height: x,y >= 0, width,height > 0, and the rectangle must fit in 0..1; crop runs before scaling. Settings are optional; defaults: duration=${t.durationSeconds}, interval=${t.intervalSeconds}, scale=${t.scale}.`},"views"),offset:"For window:, display: and HTTP(S) image/sequence captures, a non-negative integer zero-based row-major grid cell index in the transformed image. Requires limit; omit to select cell 0 when limit is set.",limit:"For window:, display: and HTTP(S) image/sequence captures, a positive integer square grid cell size in output pixels. Omit both offset and limit for the bounded transformed image."})}}),z(e,{protocol:W,apiVersion:L,id:"vision-processes",setup(a){a.addResolver({priority:-100,resolver:{id:"processes",readResources:c(t=>/^process:/iu.test(t.query)?void 0:[],"readResources"),toScriptData(t){return{kind:"custom",resolverId:"processes",value:{processes:t.map(d=>({pid:d.pid,command:d.command}))}}},async tryResolve(t){let s=/^process:(.*)$/isu.exec(t.query);if(s===null)return{kind:"not-handled"};let d=(s[1]??"").trim().toLowerCase();return{kind:"resolved",payload:(await I(r)).filter(l=>d.length===0||String(l.pid)===d||l.command.toLowerCase().includes(d)).slice(0,Math.min(t.limit??50,100))}},renderResult(t,s,d){let u=t.details;return new U({summary:`${u.processes.length} processes shown`,rows:u.processes.length?u.processes.map(l=>({kind:"note",text:`${l.pid} ${l.command}`})):[{kind:"note",text:"No matching processes"}]},d,s.expanded)},format(t){let s=t;return{content:[{type:"text",text:s.length===0?"No matching processes.":s.map(Z).join(`
3
+
4
+ `)}],details:{count:s.length,processes:s}}}}}),a.describe("process:<query> finds running processes by PID or command for process:PID metadata reads and guarded window:PID capture.")}})])}c(fe,"registerVision");function Q(e,n){if(!e.startsWith(n))return;let o=e.slice(n.length);if(!/^\d+$/u.test(o))throw new Error(`${n} sources require a numeric PID`);return Number(o)}c(Q,"prefixedPid");function R(e){return{...Y(e.views,h())??{mode:"image",...h()},...e.limit===void 0?{}:{cellSize:e.limit},...e.offset===void 0?{}:{cellIndex:e.offset}}}c(R,"options");function we(e){return e.views?.some(n=>/^(?:image|sequence)(?::|$)/u.test(n))===!0}c(we,"requestsScreenshot");function b(e,n){return{kind:"return",result:{content:n,script:{kind:"native",source:e,blocks:n},details:{source:e,resolvedBy:"vision"}}}}c(b,"returned");function w(e,n){return{kind:"return",result:{content:[{type:"text",text:n}],details:{source:e,resolvedBy:"vision",failure:{code:"READ_FAILED",source:e,resolverId:"vision",message:n}},isError:!0}}}c(w,"failed");function D(e){return e instanceof Error?e.message:String(e)}c(D,"errorMessage");function Z(e){return[`PID: ${e.pid}`,`Command: ${e.command}`,`Owned by Agent IDE: ${e.owned?"yes":"no"}`,...e.parentPid===void 0?[]:[`Parent PID: ${e.parentPid}`],...e.started===void 0?[]:[`Started: ${e.started}`],...e.source===void 0?[]:[`Agent IDE source: ${e.source}`]].join(`
5
+ `)}c(Z,"formatProcess");export{fe as default};
@@ -1 +1 @@
1
- import{a as x,e as y,k as E}from"./chunk-FXNKMNSJ.js";import{a as g,c as m}from"./chunk-SQKAXYIR.js";import{a as o}from"./chunk-EI7MMDWY.js";import{AsyncLocalStorage as T}from"node:async_hooks";var u=new T,f=new T;function S(t){let e=f.getStore();e?e.push(t):t()}o(S,"afterPostEditScope");async function R(t){if(f.getStore())return t();let e=[];try{return await f.run(e,t)}finally{for(let r of e)r()}}o(R,"collectPostEditNotifications");function A(t,e){let r=u.getStore();return r?(r.set(t,e),!0):!1}o(A,"deferPostEdit");function v(t){return u.getStore()?.has(t)??!1}o(v,"hasDeferredPostEdit");function H(t){u.getStore()?.delete(t)}o(H,"forgetDeferredPostEdit");function j(t=process.cwd()){let e=new Map;return{run(r){return u.run(e,r)},forget(r){e.delete(r)},sources(){return[...e.keys()]},async finish(r){let c=[...e];e.clear();let a=[],i=[];if(await R(async()=>{let s=new g,P=await Promise.allSettled(c.map(([d,p])=>s.run(m(d,t,"write"),p)));for(let d of P){if(d.status==="rejected"){i.push(d.reason);continue}a.push(d.value);try{r?.(d.value)}catch(p){i.push(p)}}}),i.length>0)throw new AggregateError(i,`Some final post-processing failed; completed edits remain applied. ${i.map(s=>s instanceof Error?s.message:String(s)).join("; ")}`);return a}}}o(j,"createPostEditScope");import{Type as n}from"typebox";import{Value as l}from"typebox/value";var b=`${x}/post-edit/register`;function L(t){return l.Check(n.Object({formatting:n.Object({status:n.Union(["disabled","unavailable","skipped-syntax","unchanged","changed","failed","not-reported","deferred"].map(e=>n.Literal(e))),formatter:n.Optional(n.String())})}),t)}o(L,"isFormattingContribution");function z(t){return l.Check(n.Object({diffStatuses:n.Array(n.Object({text:n.String({minLength:1}),formatter:n.Optional(n.String()),tone:n.Optional(n.Union(["muted","success","warning","error"].map(e=>n.Literal(e))))}))}),t)}o(z,"isDiffStatusContribution");var h=n.Function([],n.Unknown()),w=n.Object({id:n.String({minLength:1}),handler:h}),k=n.Object({registration:w,accept:h});function C(t){return l.Check(w,t)}o(C,"isTextPostEditHandlerRegistration");function N(t){return l.Check(k,t)}o(N,"isTextPostEditHandlerRegistrationRequest");function U(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(U,"isTextMutationResultContributionData");function V(t,e){if(!C(e))throw new TypeError("Invalid text editor post-edit handler registration");let r,c=o(()=>{let i={registration:e,accept(s){if(r!==void 0)throw new Error(`Post-edit handler ${e.id} was accepted more than once`);r=s}};return t.events.emit(b,i),r!==void 0},"announce"),a=o(()=>{},"unsubscribeReady");a=t.events.on(y,i=>{if(!E(i))throw new Error("Invalid pi-agent-text-editor core readiness event");if(!c())throw new Error("pi-agent-text-editor core announced readiness without accepting the post-edit handler");a()}),t.on("session_shutdown",()=>{a(),r?.()}),c()&&a()}o(V,"connectTextEditorPostEditHandler");export{S as a,R as b,A as c,v as d,H as e,j as f,b as g,L as h,z as i,C as j,N as k,U as l,V as m};
1
+ import{a as x,e as y,k as E}from"./chunk-4GCWGE2C.js";import{a as g,c as m}from"./chunk-CWD4O5PM.js";import{a as o}from"./chunk-EI7MMDWY.js";import{AsyncLocalStorage as T}from"node:async_hooks";var u=new T,f=new T;function S(t){let e=f.getStore();e?e.push(t):t()}o(S,"afterPostEditScope");async function R(t){if(f.getStore())return t();let e=[];try{return await f.run(e,t)}finally{for(let r of e)r()}}o(R,"collectPostEditNotifications");function A(t,e){let r=u.getStore();return r?(r.set(t,e),!0):!1}o(A,"deferPostEdit");function v(t){return u.getStore()?.has(t)??!1}o(v,"hasDeferredPostEdit");function H(t){u.getStore()?.delete(t)}o(H,"forgetDeferredPostEdit");function j(t=process.cwd()){let e=new Map;return{run(r){return u.run(e,r)},forget(r){e.delete(r)},sources(){return[...e.keys()]},async finish(r){let c=[...e];e.clear();let a=[],i=[];if(await R(async()=>{let s=new g,P=await Promise.allSettled(c.map(([d,p])=>s.run(m(d,t,"write"),p)));for(let d of P){if(d.status==="rejected"){i.push(d.reason);continue}a.push(d.value);try{r?.(d.value)}catch(p){i.push(p)}}}),i.length>0)throw new AggregateError(i,`Some final post-processing failed; completed edits remain applied. ${i.map(s=>s instanceof Error?s.message:String(s)).join("; ")}`);return a}}}o(j,"createPostEditScope");import{Type as n}from"typebox";import{Value as l}from"typebox/value";var b=`${x}/post-edit/register`;function L(t){return l.Check(n.Object({formatting:n.Object({status:n.Union(["disabled","unavailable","skipped-syntax","unchanged","changed","failed","not-reported","deferred"].map(e=>n.Literal(e))),formatter:n.Optional(n.String())})}),t)}o(L,"isFormattingContribution");function z(t){return l.Check(n.Object({diffStatuses:n.Array(n.Object({text:n.String({minLength:1}),formatter:n.Optional(n.String()),tone:n.Optional(n.Union(["muted","success","warning","error"].map(e=>n.Literal(e))))}))}),t)}o(z,"isDiffStatusContribution");var h=n.Function([],n.Unknown()),w=n.Object({id:n.String({minLength:1}),handler:h}),k=n.Object({registration:w,accept:h});function C(t){return l.Check(w,t)}o(C,"isTextPostEditHandlerRegistration");function N(t){return l.Check(k,t)}o(N,"isTextPostEditHandlerRegistrationRequest");function U(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(U,"isTextMutationResultContributionData");function V(t,e){if(!C(e))throw new TypeError("Invalid text editor post-edit handler registration");let r,c=o(()=>{let i={registration:e,accept(s){if(r!==void 0)throw new Error(`Post-edit handler ${e.id} was accepted more than once`);r=s}};return t.events.emit(b,i),r!==void 0},"announce"),a=o(()=>{},"unsubscribeReady");a=t.events.on(y,i=>{if(!E(i))throw new Error("Invalid pi-agent-text-editor core readiness event");if(!c())throw new Error("pi-agent-text-editor core announced readiness without accepting the post-edit handler");a()}),t.on("session_shutdown",()=>{a(),r?.()}),c()&&a()}o(V,"connectTextEditorPostEditHandler");export{S as a,R as b,A as c,v as d,H as e,j as f,b as g,L as h,z as i,C as j,N as k,U as l,V as m};
@@ -1 +1 @@
1
- import{e as u,f as E,k as a}from"./chunk-FXNKMNSJ.js";import{a as n}from"./chunk-EI7MMDWY.js";function T(o,r){let s=n(()=>{let e,i={plugin:r,accept(c){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=c}};return o.events.emit(E,i),e},"announce"),t=n(()=>{},"unsubscribe");t=o.events.on(u,e=>{if(!a(e))throw new Error("Invalid pi-agent-text-editor core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-text-editor core announced readiness without accepting the plugin");t(),i.catch(()=>{})}),o.on("session_shutdown",t);let d=s();if(d!==void 0)return t(),d}n(T,"connectTextEditorPlugin");export{T as a};
1
+ import{e as u,f as E,k as a}from"./chunk-4GCWGE2C.js";import{a as n}from"./chunk-EI7MMDWY.js";function T(o,r){let s=n(()=>{let e,i={plugin:r,accept(c){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=c}};return o.events.emit(E,i),e},"announce"),t=n(()=>{},"unsubscribe");t=o.events.on(u,e=>{if(!a(e))throw new Error("Invalid pi-agent-text-editor core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-text-editor core announced readiness without accepting the plugin");t(),i.catch(()=>{})}),o.on("session_shutdown",t);let d=s();if(d!==void 0)return t(),d}n(T,"connectTextEditorPlugin");export{T as a};
@@ -1,4 +1,4 @@
1
- import{a as y}from"./chunk-PLKYHUNT.js";import{a as s}from"./chunk-EI7MMDWY.js";import{Worker as v}from"node:worker_threads";var p=String.raw`
1
+ import{a as y}from"./chunk-PLKYHUNT.js";import{a as s}from"./chunk-EI7MMDWY.js";import{Worker as L}from"node:worker_threads";var p=String.raw`
2
2
  const { parentPort, workerData } = require("node:worker_threads");
3
3
  let fuzzy;
4
4
  let prepared;
@@ -96,14 +96,14 @@ parentPort.once("message", (message) => {
96
96
  prepare().catch((error) => {
97
97
  parentPort.postMessage({ kind: "failed", message: error instanceof Error ? error.message : String(error) });
98
98
  });
99
- `;async function x(n,e,r){if(e.rejection.code==="ambiguous"){let i=b(n,e,r.exactCandidateLimit);return{kind:"candidates",total:i.total,candidates:i.ranges.map((a,c)=>({rank:c+1,range:a}))}}if(e.rejection.code!=="missing"||!z(n,e.content,r))return{kind:"unavailable"};if(e.signal!==void 0&&e.signal.aborted)return{kind:"failed",error:e.signal.reason};let t=await R(n,e.lines,r,e.signal);if(t.kind!=="blocks")return t.outcome;let o=[];for(let[i,a]of t.blocks.entries()){let c=e.lines[a.endLine-1];if(c===void 0)return{kind:"failed",error:new Error("Fuzzy Worker returned an invalid source range")};o.push({rank:i+1,range:{start:{lineNumber:a.startLine,column:0},end:{lineNumber:a.endLine,column:c.length}}})}return{kind:"candidates",candidates:o,total:o.length}}s(x,"recoverExactText");function z(n,e,r){if(!r.fuzzyEnabled||n.replace(/\s/gu,"").length<4)return!1;let t=new TextEncoder;return t.encode(n).byteLength<=r.maxQuerySizeKiB*1024&&t.encode(e).byteLength<=r.maxFileSizeMiB*1024*1024}s(z,"canSearch");function R(n,e,r,t){return new Promise(o=>{let i=new v(p,{eval:!0,workerData:{moduleUrl:import.meta.resolve("fast-fuzzy"),value:n,sourceLines:e,config:r}}),a=!1,c,u=s(l=>{a||(a=!0,c!==void 0&&clearTimeout(c),t!==void 0&&t.removeEventListener("abort",d),i.terminate(),o(l))},"finish"),d=s(()=>{t!==void 0&&u({kind:"outcome",outcome:{kind:"failed",error:t.reason}})},"abort");t!==void 0&&t.addEventListener("abort",d,{once:!0}),i.on("error",l=>u({kind:"outcome",outcome:{kind:"failed",error:l}})),i.on("message",l=>{if(l.kind==="ready"){c=setTimeout(()=>u({kind:"outcome",outcome:{kind:"timed-out"}}),r.timeoutMs),i.postMessage("search",[]);return}if(l.kind==="failed"){u({kind:"outcome",outcome:{kind:"failed",error:new Error(l.message??"Fuzzy Worker failed")}});return}if(l.blocks===void 0){u({kind:"outcome",outcome:{kind:"failed",error:new Error("Fuzzy Worker omitted result blocks")}});return}u({kind:"blocks",blocks:l.blocks})})})}s(R,"runFuzzyWorker");function q(n){return{id:"exact-text",description:"Any non-empty value not handled as a structured anchor selects one unique exact text span.",renderFull(e){return e},renderCompact(){return"selected text"},tryResolve(e,r){return Promise.resolve(T(e,r))},recover(e,r){return x(e,r,n)}}}s(q,"createExactTextAnchorResolver");function T(n,e){if(n.length===0)return k("invalid","exact text anchor must be non-empty");let r=m(f(e.content)),t=m(f(n)).text,o=A(r.text,t,2);if(o.length===0)return k("missing","exact text anchor was not found");if(o.length>1)return k("ambiguous","exact text anchor matched more than once");let i=o[0];if(i===void 0)return{kind:"failed",error:new Error("Exact match index is missing")};let a=e.content.startsWith("\uFEFF")?1:0,c=a+h(r.boundaries,i),u=a+h(r.boundaries,i+t.length),d=w(e.content,c,u),l=d&&!t.endsWith(`
100
- `)?E(e.content,u):u,L={start:g(e.content,c),end:g(e.content,l),...d&&{linewise:!0}};return{kind:"resolved",anchor:new y(n,e.source,[L])}}s(T,"resolveExactTextAnchor");function b(n,e,r){let t=m(f(e.content)),o=m(f(n)).text;if(o.length===0)return{ranges:[],total:0};let i=C(t.text,o,r),a=e.content.startsWith("\uFEFF")?1:0;return{total:i.total,ranges:i.starts.map(c=>({start:g(e.content,a+h(t.boundaries,c)),end:g(e.content,a+h(t.boundaries,c+o.length))}))}}s(b,"findExactTextMatches");function w(n,e,r){let t=e===0||n[e-1]===`
99
+ `;async function x(n,e,r){if(e.rejection.code==="ambiguous"){let i=b(n,e,r.exactCandidateLimit);return{kind:"candidates",total:i.total,candidates:i.ranges.map((a,c)=>({rank:c+1,range:a}))}}if(e.rejection.code!=="missing"||!z(n,e.content,r))return{kind:"unavailable"};if(e.signal!==void 0&&e.signal.aborted)return{kind:"failed",error:e.signal.reason};let t=await R(n,e.lines,r,e.signal);if(t.kind!=="blocks")return t.outcome;let o=[];for(let[i,a]of t.blocks.entries()){let c=e.lines[a.endLine-1];if(c===void 0)return{kind:"failed",error:new Error("Fuzzy Worker returned an invalid source range")};o.push({rank:i+1,range:{start:{lineNumber:a.startLine,column:0},end:{lineNumber:a.endLine,column:c.length}}})}return{kind:"candidates",candidates:o,total:o.length}}s(x,"recoverExactText");function z(n,e,r){if(!r.fuzzyEnabled||n.replace(/\s/gu,"").length<4)return!1;let t=new TextEncoder;return t.encode(n).byteLength<=r.maxQuerySizeKiB*1024&&t.encode(e).byteLength<=r.maxFileSizeMiB*1024*1024}s(z,"canSearch");function R(n,e,r,t){return new Promise(o=>{let i=new L(p,{eval:!0,workerData:{moduleUrl:import.meta.resolve("fast-fuzzy"),value:n,sourceLines:e,config:r}}),a=!1,c,u=s(l=>{a||(a=!0,c!==void 0&&clearTimeout(c),t!==void 0&&t.removeEventListener("abort",d),i.terminate(),o(l))},"finish"),d=s(()=>{t!==void 0&&u({kind:"outcome",outcome:{kind:"failed",error:t.reason}})},"abort");t!==void 0&&t.addEventListener("abort",d,{once:!0}),i.on("error",l=>u({kind:"outcome",outcome:{kind:"failed",error:l}})),i.on("message",l=>{if(l.kind==="ready"){c=setTimeout(()=>u({kind:"outcome",outcome:{kind:"timed-out"}}),r.timeoutMs),i.postMessage("search",[]);return}if(l.kind==="failed"){u({kind:"outcome",outcome:{kind:"failed",error:new Error(l.message??"Fuzzy Worker failed")}});return}if(l.blocks===void 0){u({kind:"outcome",outcome:{kind:"failed",error:new Error("Fuzzy Worker omitted result blocks")}});return}u({kind:"blocks",blocks:l.blocks})})})}s(R,"runFuzzyWorker");function q(n,e=()=>!1){return{id:"exact-text",description:"Any non-empty value not handled as a structured anchor selects one unique exact text span.",renderFull(r){return r},renderCompact(){return"selected text"},tryResolve(r,t){return Promise.resolve(e(t.source,t.cwd)?f("invalid","Exact-text editing is blocked for this file; use a current returned anchor for the next edit."):T(r,t))},recover(r,t){return x(r,t,n)}}}s(q,"createExactTextAnchorResolver");function T(n,e){if(n.length===0)return f("invalid","exact text anchor must be non-empty");let r=h(m(e.content)),t=h(m(n)).text,o=A(r.text,t,2);if(o.length===0)return f("missing","exact text anchor was not found");if(o.length>1)return f("ambiguous","exact text anchor matched more than once");let i=o[0];if(i===void 0)return{kind:"failed",error:new Error("Exact match index is missing")};let a=e.content.startsWith("\uFEFF")?1:0,c=a+g(r.boundaries,i),u=a+g(r.boundaries,i+t.length),d=w(e.content,c,u),l=d&&!t.endsWith(`
100
+ `)?E(e.content,u):u,v={start:k(e.content,c),end:k(e.content,l),...d&&{linewise:!0}};return{kind:"resolved",anchor:new y(n,e.source,[v])}}s(T,"resolveExactTextAnchor");function b(n,e,r){let t=h(m(e.content)),o=h(m(n)).text;if(o.length===0)return{ranges:[],total:0};let i=C(t.text,o,r),a=e.content.startsWith("\uFEFF")?1:0;return{total:i.total,ranges:i.starts.map(c=>({start:k(e.content,a+g(t.boundaries,c)),end:k(e.content,a+g(t.boundaries,c+o.length))}))}}s(b,"findExactTextMatches");function w(n,e,r){let t=e===0||n[e-1]===`
101
101
  `||n[e-1]==="\r",o=r===n.length||n[r]===`
102
102
  `||n[r]==="\r"||n[r-1]===`
103
103
  `||n[r-1]==="\r";return t&&o}s(w,"isWholeLineMatch");function E(n,e){return n[e]==="\r"&&n[e+1]===`
104
104
  `?e+2:n[e]==="\r"||n[e]===`
105
- `?e+1:e}s(E,"includeTrailingLineBreak");function k(n,e){return{kind:"rejected",rejection:{code:n,reason:e}}}s(k,"rejected");function f(n){return n.startsWith("\uFEFF")?n.slice(1):n}s(f,"stripInitialBom");function m(n){let e=[],r=[0];for(let t=0;t<n.length;t+=1){let o=n[t];if(o==="\r"){let i=n[t+1]===`
105
+ `?e+1:e}s(E,"includeTrailingLineBreak");function f(n,e){return{kind:"rejected",rejection:{code:n,reason:e}}}s(f,"rejected");function m(n){return n.startsWith("\uFEFF")?n.slice(1):n}s(m,"stripInitialBom");function h(n){let e=[],r=[0];for(let t=0;t<n.length;t+=1){let o=n[t];if(o==="\r"){let i=n[t+1]===`
106
106
  `?2:1;e.push(`
107
- `),t+=i-1,r.push(t+1);continue}e.push(o??""),r.push(t+1)}return{text:e.join(""),boundaries:r}}s(m,"normalizeText");function A(n,e,r){if(e.length===0)return[];let t=[],o=0;for(;t.length<r&&o<=n.length-e.length;){let i=n.indexOf(e,o);if(i===-1)break;t.push(i),o=i+1}return t}s(A,"overlappingMatches");function C(n,e,r){if(e.length===0)return{starts:[],total:0};let t=[],o=0,i=0;for(;i<=n.length-e.length;){let a=n.indexOf(e,i);if(a===-1)break;o+=1,t.length<r&&t.push(a),i=a+1}return{starts:t,total:o}}s(C,"scanMatches");function h(n,e){let r=n[e];if(r===void 0)throw new RangeError("Exact text match is outside normalized source boundaries");return r}s(h,"boundaryAt");function g(n,e){let r=1,t=0;for(let o=0;o<e;o+=1){let i=n[o];i==="\r"?(n[o+1]===`
107
+ `),t+=i-1,r.push(t+1);continue}e.push(o??""),r.push(t+1)}return{text:e.join(""),boundaries:r}}s(h,"normalizeText");function A(n,e,r){if(e.length===0)return[];let t=[],o=0;for(;t.length<r&&o<=n.length-e.length;){let i=n.indexOf(e,o);if(i===-1)break;t.push(i),o=i+1}return t}s(A,"overlappingMatches");function C(n,e,r){if(e.length===0)return{starts:[],total:0};let t=[],o=0,i=0;for(;i<=n.length-e.length;){let a=n.indexOf(e,i);if(a===-1)break;o+=1,t.length<r&&t.push(a),i=a+1}return{starts:t,total:o}}s(C,"scanMatches");function g(n,e){let r=n[e];if(r===void 0)throw new RangeError("Exact text match is outside normalized source boundaries");return r}s(g,"boundaryAt");function k(n,e){let r=1,t=0;for(let o=0;o<e;o+=1){let i=n[o];i==="\r"?(n[o+1]===`
108
108
  `&&(o+=1),r+=1,t=0):i===`
109
- `?(r+=1,t=0):t+=1}return{lineNumber:r,column:t}}s(g,"positionAt");export{q as a,T as b,b as c};
109
+ `?(r+=1,t=0):t+=1}return{lineNumber:r,column:t}}s(k,"positionAt");export{q as a,T as b,b as c};
@@ -1 +1 @@
1
- import{a as i}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as n}from"typebox/value";var t="pi-agent-read",r=13,c=`${t}/core/ready`,s=`${t}/plugin/register`,a=e.Function([],e.Unknown()),p=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(r)}),R=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(r),id:e.String(),setup:a}),l=e.Object({plugin:R,accept:a});function g(o){return n.Check(p,o)}i(g,"isReadCoreReady");function P(o){return n.Check(R,o)}i(P,"isReadPlugin");function y(o){return n.Check(l,o)}i(y,"isReadPluginRegistrationRequest");export{t as a,r as b,c,s as d,g as e,P as f,y as g};
1
+ import{a as i}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as n}from"typebox/value";var t="pi-agent-read",r=14,c=`${t}/core/ready`,s=`${t}/plugin/register`,a=e.Function([],e.Unknown()),p=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(r)}),R=e.Object({protocol:e.Literal(t),apiVersion:e.Literal(r),id:e.String(),setup:a}),l=e.Object({plugin:R,accept:a});function g(o){return n.Check(p,o)}i(g,"isReadCoreReady");function P(o){return n.Check(R,o)}i(P,"isReadPlugin");function y(o){return n.Check(l,o)}i(y,"isReadPluginRegistrationRequest");export{t as a,r as b,c,s as d,g as e,P as f,y as g};
@@ -0,0 +1,2 @@
1
+ import{e as E,f as b}from"./chunk-T7I2VX3J.js";import{d as M}from"./chunk-PGIVHICI.js";import"./chunk-4GCWGE2C.js";import"./chunk-NNCZYO4Q.js";import{d as q}from"./chunk-64M3SQPG.js";import{a as T}from"./chunk-BU7IZLKB.js";import{a as N,b as O}from"./chunk-S5PL5DFQ.js";import"./chunk-PS2B6THP.js";import"./chunk-CWD4O5PM.js";import{e as h,f as w,g as P,h as k,i as y,l as I}from"./chunk-KVHDMIZS.js";import"./chunk-ZPT5D4VP.js";import{a as A}from"./chunk-QDLTO5PH.js";import{a as v,b as C}from"./chunk-QIK2E64R.js";import"./chunk-KINKBPPX.js";import"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";import H from"node:path";var S="diagnostics",L=q({kind:"code-view",label:"Diagnostics"});async function V(r){b(r,[await E({id:"diagnostics",description:"Diagnostic resources, readiness, and verification",triggers:[{tool:"read",resourcePrefixes:["diagnostics:"]}]})]);let i,t=l((c,f,e)=>{if(i===void 0)throw new Error("IDE diagnostics are not connected");return i(c,{cwd:f,...e})},"collect"),s={protocol:v,apiVersion:4,id:"diagnostics",setup(c){i=c.readDiagnostics}},o=new WeakMap,n=new WeakMap,a=new WeakMap,u=new WeakMap,W={protocol:N,apiVersion:O,id:"diagnostics",setup(c){c.addResolver({resolver:j(t,n),renderResult:L});let f=I();c.addView({view:"diagnostics",priority:100,presenter:B(t,u)}),c.addHandler({stage:"read",when:{resolvedBy:"any",contentKind:"text"},handler(e){if(e.state?.resolvedBy==="diagnostics"){let p=e.state.content[0],g=n.get(p);return g&&o.set(e.request,g),f(e)}return e.state?.contentKind==="text"&&e.request.views?.includes("diagnostics")&&a.set(e.request,e.state.text),{kind:"continue",context:e}}}),c.addHandler({stage:"post-read",handler(e){let p=o.get(e.request);if(p&&e.result)return{kind:"continue",context:e,transform:l(d=>({...d,details:{...d.details,diagnosticCheck:p}}),"transform")};let g=a.get(e.request),m=g&&u.get(g),D=e.result,_=D?.content[0];return!m||!D||_?.type!=="text"?{kind:"continue",context:e}:{kind:"continue",context:e,transform(d){let R=d.content[0];return R?.type!=="text"?d:{...d,content:[{...R,text:`${m}
2
+ ${R.text}`},...d.content.slice(1)]}}}}}),c.describe({path:"diagnostics:<path> \u2014 lint and language-server diagnostics with reporting tool and readiness. Pending results and snapshots are not completed checks.",views:"diagnostics \u2014 diagnostics alongside source text, with reporting tool and readiness. Pending results and snapshots are not completed checks."})}};await Promise.all([A(r,s),T(r,W)])}l(V,"registerDiagnostics");function j(r,i){return{id:"diagnostics",tryResolve(t,s){return Promise.resolve(x(t,s.cwd,r,i,{signal:s.signal,...s.audience==="script"&&{mode:"complete"}}))}}}l(j,"createDiagnosticResolver");function x(r,i,t,s,o){let n;try{n=h(r,S,i)}catch(a){return{kind:"failed",error:a}}return n===void 0?{kind:"not-handled"}:{kind:"resolved",resource:{source:w(S,n),async read(){let a=await t(n,i,o),u=P(n,a.content,a.results);return s.set(u,u.diagnosticCheck),[u]}}}}l(x,"resolveDiagnosticSource");function B(r,i){return{id:"diagnostics",async present(t,s){if(s.purpose!=="read"||!H.isAbsolute(t.source))return t;let o=s.audience==="script"&&!s.requestedViews?.includes("diagnostics");if(o&&M(t.source))return t;let n=await r(t.source,s.cwd,{signal:s.signal,...s.audience==="script"&&{mode:o?"snapshot":"complete"}}).catch(a=>{if(s.signal?.throwIfAborted(),!o)throw a});if(n===void 0||o&&n.content!==t.content)return t;if(n.content!==t.content)throw new Error("File changed during diagnostic read; read it again for current source lines.");return i.set(t,y(n.results)),k(t,n.results)}}}l(B,"createDiagnosticPresenter");export{V as default};
@@ -1,4 +1,4 @@
1
- import{a as D,m as ee}from"./chunk-KR36BT5E.js";import{a as I}from"./chunk-YRF7OATP.js";import{a as P,b as R}from"./chunk-FXNKMNSJ.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import{a as H,b as X,c as K,d as Q,g as Z}from"./chunk-QIK2E64R.js";import{a as Y}from"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";var S=[],$=[],L=[];function M(i,t,e){if(t.some(r=>r.name===e))throw new Error(`[pi-agent-ide] ${i} "${e}" is already registered. Use a unique name.`)}l(M,"assertUniqueName");function ie(i){let t=new Set;for(let e of i){let r=`${e.kind}:${e.name}`;if(t.has(r))throw new Error(`[pi-agent-ide] ${e.kind} "${e.name}" is registered twice by one plugin.`);switch(t.add(r),e.kind){case"compiler":{M(e.kind,$,e.name);break}case"formatter":{M(e.kind,S,e.name);break}case"linter":{M(e.kind,L,e.name);break}}}for(let e of i)switch(e.kind){case"compiler":{$.push(e);break}case"formatter":{S.push(e);break}case"linter":{L.push(e);break}}}l(ie,"registerTools");async function te(i,t){let e=[];for(let r of i)try{await r.detect(t)&&e.push(r)}catch(n){console.error(`[pi-agent-ide] detect failed for "${r.name}":`,n)}return e.sort((r,n)=>n.priority-r.priority),we(e),e}l(te,"filterActive");function we(i){let t=new Map;for(let e of i)for(let r of e.extensions){let n=`${r}@${e.priority}`,s=t.get(n);if(s!==void 0)throw new Error(`[pi-agent-ide] priority conflict: tools "${s}" and "${e.name}" both claim "${r}" at priority ${e.priority}.`);t.set(n,e.name)}}l(we,"assertNoPriorityConflicts");async function re(i){let[t,e]=await Promise.all([te(S,i),te($.filter(r=>r.syntaxOnly===!0),i)]);return{ctx:i,formatters:t,compilers:e,linters:[]}}l(re,"warmupFormatting");function j(){S.length=0,$.length=0,L.length=0}l(j,"resetRegistry");import{readFile as J}from"node:fs/promises";import w from"node:path";var C=class{constructor(t,e={}){this.sources=t;this.options=e}static{l(this,"DiagnosticStore")}files=new Map;dirty=new Set;sent=new Map;queue=[];running=0;disposed=!1;changeListeners=new Set;onDidChange(t){return this.changeListeners.add(t),()=>this.changeListeners.delete(t)}schedule(t,e,{cwd:r}){this.disposed||this.ensure(t,e,r)}async read(t,{cwd:e,mode:r,signal:n}){n?.throwIfAborted(),this.assertActive();let s=w.resolve(e,t),o=await J(s,"utf8");this.assertActive();let a=this.ensure(s,o,e);r==="complete"?await this.waitComplete(a,n):r!=="snapshot"&&await ve(Promise.all(a.jobs),this.options.readWaitMs??5e3),n?.throwIfAborted(),this.assertActive();let d=await J(s,"utf8");this.assertActive();let c=this.ensure(s,d,e);if(r==="complete"&&c!==a)throw Object.assign(new Error("File changed during diagnostics"),{code:"DIAGNOSTICS_STALE"});return{filePath:s,content:c.content,results:[...c.results.values()]}}async waitComplete(t,e){let r=e?AbortSignal.any([e,t.controller.signal]):t.controller.signal;r.throwIfAborted();let n=[];await new Promise((s,o)=>{let a=l(m=>o(Object.assign(new Error(m),{code:m,details:[...t.results.values()]})),"fail"),d=l(()=>{let m=[...t.results.values()];m.some(h=>h.status==="unavailable")?a("DIAGNOSTICS_UNAVAILABLE"):m.every(h=>h.status==="ready")&&s()},"check"),c=l(()=>o(r.reason),"abort"),u=this.onDidChange(d),f=setTimeout(()=>a("DIAGNOSTICS_TIMEOUT"),this.options.checkTimeoutMs??3e4);r.addEventListener("abort",c,{once:!0});let p=l(()=>{clearTimeout(f),u(),r.removeEventListener("abort",c)},"cleanup");Promise.resolve().then(d),n.push(p)}).finally(()=>{for(let s of n)s()})}async takeNotifications(t){let e=[];for(let r of[...this.dirty]){if(r.cwd!==w.resolve(t)||(this.dirty.delete(r),!await this.isCurrent(r)))continue;let n=[...r.results.values()].filter(d=>d.status!=="pending"&&d.status!=="unavailable"&&d.diagnostics.length>0),s=this.key(r.filePath,r.cwd),o=JSON.stringify(n);if(this.sent.get(s)===o||(this.sent.set(s,o),n.length===0))continue;let a=n.map(d=>{let c=["error","warning","info","hint"].flatMap(u=>{let f=d.diagnostics.filter(p=>p.severity===u).length;return f>0?[`${f} ${u}`]:[]});return`${d.source} ${c.join(", ")}${d.status==="snapshot"?" (snapshot; completion unknown)":d.status==="unversioned"?" (unversioned)":""}`}).join("; ");e.push({filePath:w.relative(t,r.filePath),results:n,text:`${JSON.stringify(w.relative(t,r.filePath))}: ${a}.`})}return e}dispose(){this.disposed=!0,this.changeListeners.clear();for(let t of this.files.values())t.controller.abort();this.files.clear(),this.dirty.clear(),this.sent.clear(),this.pump()}key(t,e){return JSON.stringify([w.resolve(e),w.resolve(e,t)])}ensure(t,e,r){let n=this.key(t,r),s=this.files.get(n);if(s?.content===e)return s;s?.controller.abort(),s&&this.dirty.delete(s);let o={cwd:w.resolve(r),filePath:w.resolve(r,t),content:e,controller:new AbortController,results:new Map,jobs:[],publications:new Map};this.files.set(n,o),this.sources.length===0&&o.results.set("diagnostics",{source:"diagnostics",status:"unavailable",diagnostics:[],reason:"No diagnostic sources registered"}),this.dirty.add(o);for(let a of this.sources){o.results.set(a.id,{source:a.id,status:"pending",diagnostics:[]});let d=new Promise(c=>{this.queue.push(async()=>{try{await this.check(o,a)}finally{c()}})});o.jobs.push(d)}return queueMicrotask(()=>this.pump()),o}pump(){for(;this.running<(this.options.concurrency??4)&&this.queue.length>0;){let t=this.queue.shift();if(!t)break;this.running++,t().finally(()=>{this.running--,this.pump()})}}active(t){return!this.disposed&&!t.controller.signal.aborted}assertActive(){if(this.disposed)throw new Error("Diagnostics session has ended")}async isCurrent(t){if(!this.active(t))return!1;let e=await J(t.filePath,"utf8").catch(()=>{});return this.active(t)&&e===t.content}async publish(t,e,r){let n=(t.publications.get(e)??0)+1;if(t.publications.set(e,n),!await this.isCurrent(t)||t.publications.get(e)!==n)return;let s={...r,source:r.source??e};if(JSON.stringify(t.results.get(e))===JSON.stringify(s))return;t.results.set(e,s),this.dirty.add(t);let o=[...t.results.values()].some(a=>a.status!=="pending"&&a.status!=="unavailable"&&a.diagnostics.length>0);o||this.sent.delete(this.key(t.filePath,t.cwd));for(let a of this.changeListeners)a(t.cwd,o)}async check(t,e){if(!await this.isCurrent(t))return;let r=new AbortController,n=AbortSignal.any([r.signal,t.controller.signal]);if(n.aborted)return;let s,o;try{let a=new Promise((c,u)=>{o=l(()=>u(n.reason),"onAbort"),n.addEventListener("abort",o,{once:!0}),s=setTimeout(()=>r.abort(new Error("Diagnostic check timed out")),this.options.checkTimeoutMs??3e4)}),d=await Promise.race([e.diagnose(t.filePath,{cwd:t.cwd,content:t.content,signal:n,publish:l(c=>{n.aborted||this.publish(t,e.id,c)},"publish")}),a]);await this.publish(t,e.id,d)}catch(a){await this.publish(t,e.id,{status:"unavailable",diagnostics:[],reason:a instanceof Error?a.message:String(a)})}finally{clearTimeout(s),o&&n.removeEventListener("abort",o)}}};async function ve(i,t){let e;try{await Promise.race([i,new Promise(r=>{e=setTimeout(r,t)})])}finally{clearTimeout(e)}}l(ve,"waitAtMost");function ne(){let i=new Map,t=[],e=new C(t),r=Promise.resolve();return{diagnostics:e,registerPlugin(n){if(n.id.trim().length===0)return Promise.reject(new Error("Plugin ID must not be empty"));let s=i.get(n.id);if(s!==void 0)return s;let o=r.then(async()=>{let a=[],d=[],c=!0,u={addTool(f){if(!c)throw new Error(`Plugin ${n.id} setup is already complete`);xe(f),a.push(f)},addDiagnosticSource(f){if(!c)throw new Error(`Plugin ${n.id} setup is already complete`);Ee(f),d.push(f)},readDiagnostics(f,p){return e.read(f,p)}};try{await n.setup(u)}catch(f){throw c=!1,f}c=!1,be(t,d),ie(a),t.push(...d)});return i.set(n.id,o),r=o.catch(()=>{}),o.catch(()=>{i.delete(n.id)}),o},async waitForPendingPlugins(){await Promise.all(i.values())}}}l(ne,"createIdeCore");function be(i,t){let e=new Set(i.map(r=>r.id));for(let r of t){if(e.has(r.id))throw new Error(`Diagnostic source ${r.id} is already registered`);e.add(r.id)}}l(be,"assertUniqueDiagnosticSources");function xe(i){if(!oe(i))throw new TypeError("IDE tool must be an object");let t=i.kind,e=t==="compiler"?i.compile:t==="formatter"?i.format:t==="linter"?i.lint:void 0;if(e===void 0||typeof e!="function"||typeof i.detect!="function"||typeof i.name!="string"||i.name.trim().length===0||typeof i.priority!="number"||!Number.isFinite(i.priority)||!Array.isArray(i.extensions)||i.extensions.length===0||i.extensions.some(r=>typeof r!="string"||r.length===0))throw new TypeError("Invalid pi-agent-ide tool contribution")}l(xe,"assertIdeTool");function Ee(i){if(!oe(i)||typeof i.id!="string"||i.id.trim().length===0||typeof i.diagnose!="function")throw new TypeError("Invalid pi-agent-ide diagnostic source contribution")}l(Ee,"assertDiagnosticSource");function oe(i){return typeof i=="object"&&i!==null}l(oe,"isRecord");function se(i,t,e=console.error){let r=new Map,n=!1,s=Promise.resolve();return{schedule(o){if(n||r.has(o))return;let a=setTimeout(()=>{r.delete(o),s=s.then(async()=>{n||await i(o)}).catch(e)},t);r.set(o,a)},dispose(){n=!0;for(let o of r.values())clearTimeout(o);r.clear()}}}l(se,"createDiagnosticDelivery");import{Text as ae}from"@earendil-works/pi-tui";var U="ide-diagnostic-summary";function ce(i){return{filePath:i.filePath,sources:i.results.map(t=>{let e={error:0,warning:0,info:0,hint:0};for(let r of t.diagnostics)e[r.severity]++;return{source:t.source,status:t.status,counts:e}})}}l(ce,"diagnosticEntryData");function V(i,t,e=!1){return{render(r){let n=i.sources.filter(a=>a.status!=="pending"&&a.status!=="unavailable"&&Object.values(a.counts).some(d=>d>0));if(n.length===0)return[];let s=n.map(a=>`${G(a.counts,t)} ${t.fg("dim",`(${q(a.source)})`)}`+(a.status==="ready"?"":` \xB7 ${t.fg("dim",a.status)}`)).join(" \xB7 "),o=[`${t.fg("accent","Diagnostics")} ${t.fg("toolTitle",q(i.filePath))} \xB7 ${s}`];if(e)for(let a of n)o.push(` ${t.fg("dim",q(a.source))} \xB7 ${G(a.counts,t)} \xB7 ${t.fg("dim",a.status)}`);return new ae(o.join(`
1
+ import{a as D,m as ee}from"./chunk-PGIVHICI.js";import{a as I}from"./chunk-PKKDDIWW.js";import{a as P,b as R}from"./chunk-4GCWGE2C.js";import"./chunk-CWD4O5PM.js";import"./chunk-ZPT5D4VP.js";import{a as H,b as X,c as K,d as Q,g as Z}from"./chunk-QIK2E64R.js";import{a as Y}from"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";var S=[],$=[],L=[];function M(i,t,e){if(t.some(r=>r.name===e))throw new Error(`[pi-agent-ide] ${i} "${e}" is already registered. Use a unique name.`)}l(M,"assertUniqueName");function ie(i){let t=new Set;for(let e of i){let r=`${e.kind}:${e.name}`;if(t.has(r))throw new Error(`[pi-agent-ide] ${e.kind} "${e.name}" is registered twice by one plugin.`);switch(t.add(r),e.kind){case"compiler":{M(e.kind,$,e.name);break}case"formatter":{M(e.kind,S,e.name);break}case"linter":{M(e.kind,L,e.name);break}}}for(let e of i)switch(e.kind){case"compiler":{$.push(e);break}case"formatter":{S.push(e);break}case"linter":{L.push(e);break}}}l(ie,"registerTools");async function te(i,t){let e=[];for(let r of i)try{await r.detect(t)&&e.push(r)}catch(n){console.error(`[pi-agent-ide] detect failed for "${r.name}":`,n)}return e.sort((r,n)=>n.priority-r.priority),we(e),e}l(te,"filterActive");function we(i){let t=new Map;for(let e of i)for(let r of e.extensions){let n=`${r}@${e.priority}`,s=t.get(n);if(s!==void 0)throw new Error(`[pi-agent-ide] priority conflict: tools "${s}" and "${e.name}" both claim "${r}" at priority ${e.priority}.`);t.set(n,e.name)}}l(we,"assertNoPriorityConflicts");async function re(i){let[t,e]=await Promise.all([te(S,i),te($.filter(r=>r.syntaxOnly===!0),i)]);return{ctx:i,formatters:t,compilers:e,linters:[]}}l(re,"warmupFormatting");function j(){S.length=0,$.length=0,L.length=0}l(j,"resetRegistry");import{readFile as J}from"node:fs/promises";import w from"node:path";var C=class{constructor(t,e={}){this.sources=t;this.options=e}static{l(this,"DiagnosticStore")}files=new Map;dirty=new Set;sent=new Map;queue=[];running=0;disposed=!1;changeListeners=new Set;onDidChange(t){return this.changeListeners.add(t),()=>this.changeListeners.delete(t)}schedule(t,e,{cwd:r}){this.disposed||this.ensure(t,e,r)}async read(t,{cwd:e,mode:r,signal:n}){n?.throwIfAborted(),this.assertActive();let s=w.resolve(e,t),o=await J(s,"utf8");this.assertActive();let a=this.ensure(s,o,e);r==="complete"?await this.waitComplete(a,n):r!=="snapshot"&&await ve(Promise.all(a.jobs),this.options.readWaitMs??5e3),n?.throwIfAborted(),this.assertActive();let d=await J(s,"utf8");this.assertActive();let c=this.ensure(s,d,e);if(r==="complete"&&c!==a)throw Object.assign(new Error("File changed during diagnostics"),{code:"DIAGNOSTICS_STALE"});return{filePath:s,content:c.content,results:[...c.results.values()]}}async waitComplete(t,e){let r=e?AbortSignal.any([e,t.controller.signal]):t.controller.signal;r.throwIfAborted();let n=[];await new Promise((s,o)=>{let a=l(m=>o(Object.assign(new Error(m),{code:m,details:[...t.results.values()]})),"fail"),d=l(()=>{let m=[...t.results.values()];m.some(h=>h.status==="unavailable")?a("DIAGNOSTICS_UNAVAILABLE"):m.every(h=>h.status==="ready")&&s()},"check"),c=l(()=>o(r.reason),"abort"),u=this.onDidChange(d),f=setTimeout(()=>a("DIAGNOSTICS_TIMEOUT"),this.options.checkTimeoutMs??3e4);r.addEventListener("abort",c,{once:!0});let p=l(()=>{clearTimeout(f),u(),r.removeEventListener("abort",c)},"cleanup");Promise.resolve().then(d),n.push(p)}).finally(()=>{for(let s of n)s()})}async takeNotifications(t){let e=[];for(let r of[...this.dirty]){if(r.cwd!==w.resolve(t)||(this.dirty.delete(r),!await this.isCurrent(r)))continue;let n=[...r.results.values()].filter(d=>d.status!=="pending"&&d.status!=="unavailable"&&d.diagnostics.length>0),s=this.key(r.filePath,r.cwd),o=JSON.stringify(n);if(this.sent.get(s)===o||(this.sent.set(s,o),n.length===0))continue;let a=n.map(d=>{let c=["error","warning","info","hint"].flatMap(u=>{let f=d.diagnostics.filter(p=>p.severity===u).length;return f>0?[`${f} ${u}`]:[]});return`${d.source} ${c.join(", ")}${d.status==="snapshot"?" (snapshot; completion unknown)":d.status==="unversioned"?" (unversioned)":""}`}).join("; ");e.push({filePath:w.relative(t,r.filePath),results:n,text:`${JSON.stringify(w.relative(t,r.filePath))}: ${a}.`})}return e}dispose(){this.disposed=!0,this.changeListeners.clear();for(let t of this.files.values())t.controller.abort();this.files.clear(),this.dirty.clear(),this.sent.clear(),this.pump()}key(t,e){return JSON.stringify([w.resolve(e),w.resolve(e,t)])}ensure(t,e,r){let n=this.key(t,r),s=this.files.get(n);if(s?.content===e)return s;s?.controller.abort(),s&&this.dirty.delete(s);let o={cwd:w.resolve(r),filePath:w.resolve(r,t),content:e,controller:new AbortController,results:new Map,jobs:[],publications:new Map};this.files.set(n,o),this.sources.length===0&&o.results.set("diagnostics",{source:"diagnostics",status:"unavailable",diagnostics:[],reason:"No diagnostic sources registered"}),this.dirty.add(o);for(let a of this.sources){o.results.set(a.id,{source:a.id,status:"pending",diagnostics:[]});let d=new Promise(c=>{this.queue.push(async()=>{try{await this.check(o,a)}finally{c()}})});o.jobs.push(d)}return queueMicrotask(()=>this.pump()),o}pump(){for(;this.running<(this.options.concurrency??4)&&this.queue.length>0;){let t=this.queue.shift();if(!t)break;this.running++,t().finally(()=>{this.running--,this.pump()})}}active(t){return!this.disposed&&!t.controller.signal.aborted}assertActive(){if(this.disposed)throw new Error("Diagnostics session has ended")}async isCurrent(t){if(!this.active(t))return!1;let e=await J(t.filePath,"utf8").catch(()=>{});return this.active(t)&&e===t.content}async publish(t,e,r){let n=(t.publications.get(e)??0)+1;if(t.publications.set(e,n),!await this.isCurrent(t)||t.publications.get(e)!==n)return;let s={...r,source:r.source??e};if(JSON.stringify(t.results.get(e))===JSON.stringify(s))return;t.results.set(e,s),this.dirty.add(t);let o=[...t.results.values()].some(a=>a.status!=="pending"&&a.status!=="unavailable"&&a.diagnostics.length>0);o||this.sent.delete(this.key(t.filePath,t.cwd));for(let a of this.changeListeners)a(t.cwd,o)}async check(t,e){if(!await this.isCurrent(t))return;let r=new AbortController,n=AbortSignal.any([r.signal,t.controller.signal]);if(n.aborted)return;let s,o;try{let a=new Promise((c,u)=>{o=l(()=>u(n.reason),"onAbort"),n.addEventListener("abort",o,{once:!0}),s=setTimeout(()=>r.abort(new Error("Diagnostic check timed out")),this.options.checkTimeoutMs??3e4)}),d=await Promise.race([e.diagnose(t.filePath,{cwd:t.cwd,content:t.content,signal:n,publish:l(c=>{n.aborted||this.publish(t,e.id,c)},"publish")}),a]);await this.publish(t,e.id,d)}catch(a){await this.publish(t,e.id,{status:"unavailable",diagnostics:[],reason:a instanceof Error?a.message:String(a)})}finally{clearTimeout(s),o&&n.removeEventListener("abort",o)}}};async function ve(i,t){let e;try{await Promise.race([i,new Promise(r=>{e=setTimeout(r,t)})])}finally{clearTimeout(e)}}l(ve,"waitAtMost");function ne(){let i=new Map,t=[],e=new C(t),r=Promise.resolve();return{diagnostics:e,registerPlugin(n){if(n.id.trim().length===0)return Promise.reject(new Error("Plugin ID must not be empty"));let s=i.get(n.id);if(s!==void 0)return s;let o=r.then(async()=>{let a=[],d=[],c=!0,u={addTool(f){if(!c)throw new Error(`Plugin ${n.id} setup is already complete`);xe(f),a.push(f)},addDiagnosticSource(f){if(!c)throw new Error(`Plugin ${n.id} setup is already complete`);Ee(f),d.push(f)},readDiagnostics(f,p){return e.read(f,p)}};try{await n.setup(u)}catch(f){throw c=!1,f}c=!1,be(t,d),ie(a),t.push(...d)});return i.set(n.id,o),r=o.catch(()=>{}),o.catch(()=>{i.delete(n.id)}),o},async waitForPendingPlugins(){await Promise.all(i.values())}}}l(ne,"createIdeCore");function be(i,t){let e=new Set(i.map(r=>r.id));for(let r of t){if(e.has(r.id))throw new Error(`Diagnostic source ${r.id} is already registered`);e.add(r.id)}}l(be,"assertUniqueDiagnosticSources");function xe(i){if(!oe(i))throw new TypeError("IDE tool must be an object");let t=i.kind,e=t==="compiler"?i.compile:t==="formatter"?i.format:t==="linter"?i.lint:void 0;if(e===void 0||typeof e!="function"||typeof i.detect!="function"||typeof i.name!="string"||i.name.trim().length===0||typeof i.priority!="number"||!Number.isFinite(i.priority)||!Array.isArray(i.extensions)||i.extensions.length===0||i.extensions.some(r=>typeof r!="string"||r.length===0))throw new TypeError("Invalid pi-agent-ide tool contribution")}l(xe,"assertIdeTool");function Ee(i){if(!oe(i)||typeof i.id!="string"||i.id.trim().length===0||typeof i.diagnose!="function")throw new TypeError("Invalid pi-agent-ide diagnostic source contribution")}l(Ee,"assertDiagnosticSource");function oe(i){return typeof i=="object"&&i!==null}l(oe,"isRecord");function se(i,t,e=console.error){let r=new Map,n=!1,s=Promise.resolve();return{schedule(o){if(n||r.has(o))return;let a=setTimeout(()=>{r.delete(o),s=s.then(async()=>{n||await i(o)}).catch(e)},t);r.set(o,a)},dispose(){n=!0;for(let o of r.values())clearTimeout(o);r.clear()}}}l(se,"createDiagnosticDelivery");import{Text as ae}from"@earendil-works/pi-tui";var U="ide-diagnostic-summary";function ce(i){return{filePath:i.filePath,sources:i.results.map(t=>{let e={error:0,warning:0,info:0,hint:0};for(let r of t.diagnostics)e[r.severity]++;return{source:t.source,status:t.status,counts:e}})}}l(ce,"diagnosticEntryData");function V(i,t,e=!1){return{render(r){let n=i.sources.filter(a=>a.status!=="pending"&&a.status!=="unavailable"&&Object.values(a.counts).some(d=>d>0));if(n.length===0)return[];let s=n.map(a=>`${G(a.counts,t)} ${t.fg("dim",`(${q(a.source)})`)}`+(a.status==="ready"?"":` \xB7 ${t.fg("dim",a.status)}`)).join(" \xB7 "),o=[`${t.fg("accent","Diagnostics")} ${t.fg("toolTitle",q(i.filePath))} \xB7 ${s}`];if(e)for(let a of n)o.push(` ${t.fg("dim",q(a.source))} \xB7 ${G(a.counts,t)} \xB7 ${t.fg("dim",a.status)}`);return new ae(o.join(`
2
2
  `),0,0).render(r)},invalidate(){}}}l(V,"renderDiagnosticEntry");function le(i){i.registerEntryRenderer(U,(t,e,r)=>{let n=Y(t.data);return"files"in n?Te(n.files,r,e.expanded):V(n,r,e.expanded)})}l(le,"registerDiagnosticEntryRenderer");function Te(i,t,e=!1){return{render(r){let n=i.filter(d=>d.sources.some(c=>c.status!=="pending"&&c.status!=="unavailable"&&Object.values(c.counts).some(u=>u>0)));if(n.length===1&&n[0])return V(n[0],t,e).render(r);if(n.length===0)return[];let s={error:0,warning:0,info:0,hint:0},o=new Set;for(let d of n)for(let c of d.sources)if(!(c.status==="pending"||c.status==="unavailable")){o.add(c.source);for(let u of["error","warning","info","hint"])s[u]+=c.counts[u]}let a=new ae(`${t.fg("accent","Diagnostics")} \xB7 ${n.length} files \xB7 ${G(s,t)} \xB7 ${o.size} tools`,0,0).render(r);return e?[...a,...n.flatMap(d=>V(d,t,!0).render(r))]:a},invalidate(){}}}l(Te,"renderDiagnosticBatch");function G(i,t){return["error","warning","info","hint"].filter(e=>i[e]>0).map(e=>{let r=i[e],n=e==="info"||r===1?e:`${e}s`,s=r>0&&(e==="error"||e==="warning")?e:"muted";return t.fg(s,`${r} ${n}`)}).join(", ")}l(G,"renderCounts");function q(i){return i.replace(/[\u0000-\u001f\u007f-\u009f]/g," ")}l(q,"plain");import de from"node:path";async function ue(i){if(!de.isAbsolute(i.resourceSource))return{formatting:{status:"unavailable"}};let t;try{let e=await re({cwd:i.cwd}),r=de.extname(i.resourceSource).toLowerCase(),n=l(d=>d.extensions.includes(r)||d.extensions.includes("*"),"matches"),s=e.compilers.find(n);if(s&&(await s.compile({filePath:i.resourceSource},e.ctx)).syntaxErrors.length>0)return{formatting:{status:"skipped-syntax"}};let o=e.formatters.find(n);if(!o)return{formatting:{status:"unavailable"}};t=o.name;let a=await o.format({filePath:i.resourceSource},e.ctx);return a.formatter===null?{formatting:{status:"unavailable"}}:(t=a.formatter??o.name,{formatting:{status:a.ok?a.edits>0?"changed":"unchanged":"failed",formatter:t},...a.ok?{diffStatuses:[{text:`Formatted (${t})`,tone:"success",formatter:t}]}:{diffStatuses:[{text:`Formatting failed (${t})`,tone:"error"}]}})}catch{return{diffStatuses:[{text:"Formatting failed",tone:"error"}],formatting:{status:"failed",...t===void 0?{}:{formatter:t}}}}}l(ue,"runIdePostEditGate");import{readFile as Ae}from"node:fs/promises";import me from"node:path";import{Text as _e}from"@earendil-works/pi-tui";import{readFile as Pe}from"node:fs/promises";import Re from"node:path";import{Type as b}from"typebox";import{Value as Ie}from"typebox/value";import{parseDocument as De}from"yaml";var k=".pi/pi-agent-ide/code-review.yaml",Se=b.Object({rules:b.Array(b.Object({id:b.String({pattern:"^[a-z][a-z0-9-]*$",maxLength:64}),description:b.String({minLength:1,maxLength:2048}),enabled:b.Optional(b.Boolean())},{additionalProperties:!1}),{maxItems:32})},{additionalProperties:!1});function $e(i){if(Buffer.byteLength(i,"utf8")>65536)throw new Error("Review rules file is too large (64 KiB limit).");let t=De(i),[e]=t.errors;if(e)throw new Error(e.message);let r=t.toJS({maxAliasCount:0});if(!Ie.Check(Se,r))throw new Error("Expected rules: [{ id, description, enabled? }]; at most 32 rules with descriptions up to 2048 characters.");let n=new Set,s=[];for(let o of r.rules){if(n.has(o.id))throw new Error(`Duplicate review rule: ${o.id}`);if(n.add(o.id),!o.description.trim())throw new Error(`Empty description for ${o.id}`);o.enabled!==!1&&s.push({id:o.id,description:o.description.trim()})}return s}l($e,"parseReviewRules");async function fe(i){let t=Re.resolve(i,k);try{return $e(await Pe(t,"utf8"))}catch(e){if(e.code==="ENOENT")return[];throw new Error(`Cannot load ${t}: ${e instanceof Error?e.message:String(e)}`,{cause:e})}}l(fe,"readReviewRules");import{createHash as ke}from"node:crypto";import{structuredPatch as Ce}from"diff";function ge(i,t){if(i===t)return[];if(i.length+t.length>3e5)throw new Error("File is too large for automatic review.");let e=Ce("before","after",i,t,void 0,void 0,{context:3,timeout:100});if(!e)throw new Error("Diff exceeded the automatic review time limit.");if(e.hunks.length>16)throw new Error("Change has too many fragments for automatic review (16 limit).");return e.hunks.map(r=>{let n=`@@ -${r.oldStart},${r.oldLines} +${r.newStart},${r.newLines} @@
3
3
  ${r.lines.join(`
4
4
  `)}`;if(n.length>12e3)throw new Error("Fragment is too large for automatic review (12000 character limit).");return{diff:n}})}l(ge,"reviewFragments");function pe(i,t=300){let e=new Map,r=!1,n=Promise.resolve(),s=l(c=>!r&&i.enabled()&&e.get(c.edit.file)===c&&!c.controller.signal.aborted,"valid"),o=l(async c=>s(c)&&await i.current(c.edit.file)===c.edit.after&&s(c),"fresh");async function a(c){if(!s(c))return;c.started=!0;let{edit:u}=c;try{let f=i.runtime();if(!f)return;let p=AbortSignal.any([c.controller.signal,AbortSignal.timeout(15e3)]),m=await f.available(p),h=m.find(g=>g.provider==="typesafe"&&/jev/i.test(g.id))??m.find(g=>/jev/i.test(g.id));if(!h||!s(c))return;let A=await i.rules(u.cwd);if(A.length===0||!await o(c))return;let he=Object.fromEntries(A.map(g=>[g.id,{type:"choice",instructions:`Check whether this change violates the following project rule: ${g.description}
@@ -1 +1 @@
1
- import{c as g,d as p}from"./chunk-AJRIASPQ.js";import{a as c}from"./chunk-EI7MMDWY.js";import b from"node:path";import{pathToFileURL as C}from"node:url";function S(e,r){let o=new Map;for(let n of e){let t=o.get(n.source)??[];t.push(n),o.set(n.source,t)}let i=new Set,a=e.length,s=[...o].sort(([n,t],[h,l])=>l.length-t.length||n.localeCompare(h));for(let[n,t]of s){if(a<=r)break;i.add(n),a-=t.length}return{files:[...o].sort(([n],[t])=>n.localeCompare(t)).map(([n,t])=>{if(!i.has(n))return{kind:"detailed",source:n,matches:t};let h=new Map;for(let l of t)h.set(l.lineText,(h.get(l.lineText)??0)+1);return{kind:"compacted",source:n,matchCount:t.length,uniqueLineCount:h.size,groups:o.size===1?[...h].sort(([l,d],[m,R])=>R-d||l.localeCompare(m)).slice(0,r).map(([l,d])=>({text:l,matchCount:d})):[]}})}}c(S,"planSearchPresentation");function F(e,r,o,i,a,s=50){let n=S(r,s).files.map(t=>t.kind==="detailed"?k(t.source,t.matches,i):{path:z(t.source,i),link:C(t.source).href,matchCount:t.matchCount,uniqueLineCount:t.uniqueLineCount,groups:t.groups,lines:[]});return{...a!==void 0&&{sessionId:a},query:e,matchCount:r.length,fileCount:n.length,complete:o,files:n}}c(F,"createSearchToolDetails");function D(e,r){return{fileCount:new Set(e.flatMap(o=>o.matches.map(i=>i.source))).size,groups:e.map(o=>{let a=F(o.identifier,o.matches.slice(0,g.previewMatches),o.complete,r).files.map(s=>{let u=s.lines.map(n=>{let t=Math.max(0,(n.ranges[0]?.from??0)-64),h=Math.min(n.text.length,(n.ranges[0]?.to??0)+64),l=t>0?"\u2026":"",d=n.ranges.filter(m=>m.from>=t&&m.to<=h).map(m=>({from:m.from-t+l.length,to:m.to-t+l.length}));return{...n,text:l+n.text.slice(t,h)+(h<n.text.length?"\u2026":""),ranges:d,matchCount:d.length}});return{...s,lines:u,matchCount:u.reduce((n,t)=>n+t.matchCount,0)}});return{identifier:o.identifier,files:a}})}}c(D,"createFuzzyPresentation");function M(e){return f(e)&&y(e.fileCount)&&Array.isArray(e.groups)&&e.groups.every(r=>f(r)&&typeof r.identifier=="string"&&Array.isArray(r.files)&&r.files.every(x))}c(M,"isFuzzyPresentation");function G(e){if(!f(e)||typeof e.query!="string"||!y(e.matchCount)||!y(e.fileCount)||typeof e.complete!="boolean"||e.sessionId!==void 0&&typeof e.sessionId!="string"||e.fuzzy!==void 0&&!p(e.fuzzy)||e.fuzzyPresentation!==void 0&&!M(e.fuzzyPresentation)||!Array.isArray(e.files)||!e.files.every(x))return!1;let r=e.files;return e.fileCount===r.length&&e.matchCount===r.reduce((o,i)=>o+i.matchCount,0)}c(G,"isSearchToolDetails");function k(e,r,o){let i=new Map;for(let s of r){let u=i.get(s.lineNumber);if(u!==void 0&&u.text!==s.lineText)throw new Error(`Search results disagree about line ${String(s.lineNumber)} in ${e}.`);let n=u??{lineNumber:s.lineNumber,text:s.lineText,ranges:[]};n.ranges.push({from:s.startColumn,to:s.endColumn}),i.set(s.lineNumber,n)}let a=[...i.values()].sort((s,u)=>s.lineNumber-u.lineNumber).map(s=>{let u=[...s.ranges].sort((n,t)=>n.from-t.from||n.to-t.to);return{lineNumber:s.lineNumber,text:s.text,matchCount:u.length,ranges:u}});return{path:z(e,o),link:C(e).href,matchCount:r.length,lines:a}}c(k,"createSearchResultFile");function x(e){if(!f(e)||typeof e.path!="string"||typeof e.link!="string"||!y(e.matchCount)||!Array.isArray(e.lines)||!e.lines.every(w))return!1;let r=e.lines,o=e.groups,i=new Set(r.flatMap(a=>a.logicalMatchIds??[]));return(o===void 0||Array.isArray(o)&&o.every(a=>f(a)&&typeof a.text=="string"&&y(a.matchCount)))&&(e.uniqueLineCount===void 0||y(e.uniqueLineCount))&&(r.length===0||(i.size>0?i.size===e.matchCount:e.matchCount===r.reduce((a,s)=>a+s.matchCount,0)))}c(x,"isSearchResultFile");function w(e){return f(e)&&Number.isSafeInteger(e.lineNumber)&&e.lineNumber>=1&&typeof e.text=="string"&&y(e.matchCount)&&Array.isArray(e.ranges)&&e.ranges.length===e.matchCount&&(e.logicalMatchIds===void 0||Array.isArray(e.logicalMatchIds)&&e.logicalMatchIds.every(r=>typeof r=="string"))&&e.ranges.every(r=>L(r,e.text))}c(w,"isSearchResultLine");function L(e,r){return f(e)&&Number.isSafeInteger(e.from)&&Number.isSafeInteger(e.to)&&e.from>=0&&e.to>e.from&&e.to<=r.length}c(L,"isSearchResultRange");function f(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}c(f,"isRecord");function y(e){return Number.isSafeInteger(e)&&e>=0}c(y,"isCount");function z(e,r){let o=b.relative(r,e);return o.length>0&&!o.startsWith("..")&&!b.isAbsolute(o)?o:e}c(z,"displaySource");export{S as a,F as b,D as c,G as d};
1
+ import{c as g,d as p}from"./chunk-YP46DVVP.js";import{a as c}from"./chunk-EI7MMDWY.js";import b from"node:path";import{pathToFileURL as C}from"node:url";function S(e,r){let o=new Map;for(let n of e){let t=o.get(n.source)??[];t.push(n),o.set(n.source,t)}let i=new Set,a=e.length,s=[...o].sort(([n,t],[h,l])=>l.length-t.length||n.localeCompare(h));for(let[n,t]of s){if(a<=r)break;i.add(n),a-=t.length}return{files:[...o].sort(([n],[t])=>n.localeCompare(t)).map(([n,t])=>{if(!i.has(n))return{kind:"detailed",source:n,matches:t};let h=new Map;for(let l of t)h.set(l.lineText,(h.get(l.lineText)??0)+1);return{kind:"compacted",source:n,matchCount:t.length,uniqueLineCount:h.size,groups:o.size===1?[...h].sort(([l,d],[m,R])=>R-d||l.localeCompare(m)).slice(0,r).map(([l,d])=>({text:l,matchCount:d})):[]}})}}c(S,"planSearchPresentation");function F(e,r,o,i,a,s=50){let n=S(r,s).files.map(t=>t.kind==="detailed"?k(t.source,t.matches,i):{path:z(t.source,i),link:C(t.source).href,matchCount:t.matchCount,uniqueLineCount:t.uniqueLineCount,groups:t.groups,lines:[]});return{...a!==void 0&&{sessionId:a},query:e,matchCount:r.length,fileCount:n.length,complete:o,files:n}}c(F,"createSearchToolDetails");function D(e,r){return{fileCount:new Set(e.flatMap(o=>o.matches.map(i=>i.source))).size,groups:e.map(o=>{let a=F(o.identifier,o.matches.slice(0,g.previewMatches),o.complete,r).files.map(s=>{let u=s.lines.map(n=>{let t=Math.max(0,(n.ranges[0]?.from??0)-64),h=Math.min(n.text.length,(n.ranges[0]?.to??0)+64),l=t>0?"\u2026":"",d=n.ranges.filter(m=>m.from>=t&&m.to<=h).map(m=>({from:m.from-t+l.length,to:m.to-t+l.length}));return{...n,text:l+n.text.slice(t,h)+(h<n.text.length?"\u2026":""),ranges:d,matchCount:d.length}});return{...s,lines:u,matchCount:u.reduce((n,t)=>n+t.matchCount,0)}});return{identifier:o.identifier,files:a}})}}c(D,"createFuzzyPresentation");function M(e){return f(e)&&y(e.fileCount)&&Array.isArray(e.groups)&&e.groups.every(r=>f(r)&&typeof r.identifier=="string"&&Array.isArray(r.files)&&r.files.every(x))}c(M,"isFuzzyPresentation");function G(e){if(!f(e)||typeof e.query!="string"||!y(e.matchCount)||!y(e.fileCount)||typeof e.complete!="boolean"||e.sessionId!==void 0&&typeof e.sessionId!="string"||e.fuzzy!==void 0&&!p(e.fuzzy)||e.fuzzyPresentation!==void 0&&!M(e.fuzzyPresentation)||!Array.isArray(e.files)||!e.files.every(x))return!1;let r=e.files;return e.fileCount===r.length&&e.matchCount===r.reduce((o,i)=>o+i.matchCount,0)}c(G,"isSearchToolDetails");function k(e,r,o){let i=new Map;for(let s of r){let u=i.get(s.lineNumber);if(u!==void 0&&u.text!==s.lineText)throw new Error(`Search results disagree about line ${String(s.lineNumber)} in ${e}.`);let n=u??{lineNumber:s.lineNumber,text:s.lineText,ranges:[]};n.ranges.push({from:s.startColumn,to:s.endColumn}),i.set(s.lineNumber,n)}let a=[...i.values()].sort((s,u)=>s.lineNumber-u.lineNumber).map(s=>{let u=[...s.ranges].sort((n,t)=>n.from-t.from||n.to-t.to);return{lineNumber:s.lineNumber,text:s.text,matchCount:u.length,ranges:u}});return{path:z(e,o),link:C(e).href,matchCount:r.length,lines:a}}c(k,"createSearchResultFile");function x(e){if(!f(e)||typeof e.path!="string"||typeof e.link!="string"||!y(e.matchCount)||!Array.isArray(e.lines)||!e.lines.every(w))return!1;let r=e.lines,o=e.groups,i=new Set(r.flatMap(a=>a.logicalMatchIds??[]));return(o===void 0||Array.isArray(o)&&o.every(a=>f(a)&&typeof a.text=="string"&&y(a.matchCount)))&&(e.uniqueLineCount===void 0||y(e.uniqueLineCount))&&(r.length===0||(i.size>0?i.size===e.matchCount:e.matchCount===r.reduce((a,s)=>a+s.matchCount,0)))}c(x,"isSearchResultFile");function w(e){return f(e)&&Number.isSafeInteger(e.lineNumber)&&e.lineNumber>=1&&typeof e.text=="string"&&y(e.matchCount)&&Array.isArray(e.ranges)&&e.ranges.length===e.matchCount&&(e.logicalMatchIds===void 0||Array.isArray(e.logicalMatchIds)&&e.logicalMatchIds.every(r=>typeof r=="string"))&&e.ranges.every(r=>L(r,e.text))}c(w,"isSearchResultLine");function L(e,r){return f(e)&&Number.isSafeInteger(e.from)&&Number.isSafeInteger(e.to)&&e.from>=0&&e.to>e.from&&e.to<=r.length}c(L,"isSearchResultRange");function f(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}c(f,"isRecord");function y(e){return Number.isSafeInteger(e)&&e>=0}c(y,"isCount");function z(e,r){let o=b.relative(r,e);return o.length>0&&!o.startsWith("..")&&!b.isAbsolute(o)?o:e}c(z,"displaySource");export{S as a,F as b,D as c,G as d};
@@ -1,2 +1,2 @@
1
- import{c as w,h as _}from"./chunk-PS2B6THP.js";import{a as l}from"./chunk-EI7MMDWY.js";import{Container as D,Text as H,truncateToWidth as E,visibleWidth as W}from"@earendil-works/pi-tui";var v="pi-agent-text-editor/tool-call-interception",h=Symbol("pi-agent-tool-call-interception/annotation"),k=Symbol("pi-agent-tool-call-interception/render-argument-patch"),y=Symbol("pi-agent-tool-call-interception/anchor-render-patch");function x(n){if(!C(n))return;let e=n[v];return Y(e)?e:void 0}l(x,"getToolCallInterception");function M(n,e,o){let t={annotation:e,...o!==void 0&&{blocked:{reason:o}}};return C(n)?{...n,[v]:t}:{[v]:t,agentDetails:n??null}}l(M,"withToolCallInterceptionDetails");function Q(n,e){return{...n,details:M(n.details,{kind:"blocked",reason:e},e)}}l(Q,"withBlockedToolResult");function j(n,e){if(n===void 0)return!1;let o=n,t=e,r=Reflect.ownKeys(e);return r.length===Reflect.ownKeys(n).length&&r.every(d=>o[d]===t[d])}l(j,"sameArgumentPatch");function U(n,e){let o={...n,...e},t=b(n),r=b(e);return(t!==void 0||r!==void 0)&&(o[y]={...t,...r}),o}l(U,"mergeArgumentPatches");function O(n){if(n===void 0||!(y in n))return n;let e={...n};return delete e[y],e}l(O,"argumentPatchWithoutAnchorRendering");function b(n){if(n!==void 0)return n[y]}l(b,"anchorRenderPatchFromArguments");var L=class{static{l(this,"ToolCallInterceptionRenderStore")}entries=new Map;annotate=l((e,o)=>{let t=this.entries.get(e);this.entries.set(e,{annotation:o,renderArgumentPatch:t?.renderArgumentPatch,invalidate:t?.invalidate}),t?.invalidate?.()},"annotate");bind(e,o){let t=this.entries.get(e);return this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:t?.renderArgumentPatch,invalidate:o}),t?.annotation}get(e){return this.entries.get(e)?.annotation}resolveArguments=l((e,o)=>{let t=this.entries.get(e),r=U(t?.renderArgumentPatch,o);j(t?.renderArgumentPatch,r)||(this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:r,invalidate:t?.invalidate}),t?.invalidate?.())},"resolveArguments");getRenderArgumentPatch(e){return this.entries.get(e)?.renderArgumentPatch}complete(e){this.entries.delete(e)}clear(){this.entries.clear()}},P=class{constructor(e,o,t,r,d,s){this.component=e;this.theme=o;this.state=t;this.annotations=r;this.toolCallId=d;this.backgroundAnsi=s}static{l(this,"AnnotatedToolCall")}get inner(){return this.component}update(e,o,t,r){this.component=e,this.theme=o,this.state=t,this.backgroundAnsi=r}render(e){let o=this.component.render(e),t=this.annotations.get(this.toolCallId)??this.state[h],r;if(t===void 0)r=o;else{let d=F(t,this.theme);if(o.length===0)r=[E(d,e)];else{let s=` \u2190 ${d}`,a=W(s);r=a>=e?[E(s.trimStart(),e,""),...o.slice(1)]:[`${E(o[0]??"",e-a,"")}${s}`,...o.slice(1)]}}return B(r,this.backgroundAnsi)}invalidate(){this.component.invalidate()}},I=class{constructor(e,o){this.component=e;this.backgroundAnsi=o}static{l(this,"EnclosingBackgroundComponent")}get inner(){return this.component}update(e,o){this.component=e,this.backgroundAnsi=o}render(e){return B(this.component.render(e),this.backgroundAnsi)}invalidate(){this.component.invalidate()}};function B(n,e){return e===void 0?[...n]:n.map(o=>_(o,e))}l(B,"preserveBackgroundLines");function V(n,e){let o=n.renderCall,t=n.renderResult,r=n.renderShell!=="self";return{...n,get description(){return n.description},get promptGuidelines(){return n.promptGuidelines},renderCall(d,s,a){let i=a.state,c=e.bind(a.toolCallId,a.invalidate),u=e.getRenderArgumentPatch(a.toolCallId)??i[k],T=b(u),R=O(u);u!==void 0&&(i[k]=u),T!==void 0&&(i[y]=T);let p=R===void 0?d:{...R,...d};c!==void 0&&(i[h]=c);let g=a.lastComponent instanceof P?a.lastComponent:void 0,f;try{f=o?.(p,s,{...a,args:p,lastComponent:g?.inner})??K(n.name,s)}catch{f=K(n.name,s)}let A=r?w(s,a):void 0;return g!==void 0?(g.update(f,s,i,A),g):new P(f,s,i,e,a.toolCallId,A)},renderResult(d,s,a,i){let c=i.state,u=e.getRenderArgumentPatch(i.toolCallId)??c[k],T=b(u),R=O(u);u!==void 0&&(c[k]=u),T!==void 0&&(c[y]=T);let p=i.lastComponent instanceof I?i.lastComponent:void 0,g={...i,...R!==void 0&&{args:{...R,...i.args}},lastComponent:p?.inner??i.lastComponent},f=x(d.details)?.annotation,A=e.get(i.toolCallId)??c[h],N=f??(s.isPartial||i.isError?A:void 0);if(N!==void 0){if(c[h]=N,e.complete(i.toolCallId),t!==void 0){let G={...d,content:[],details:void 0};try{t(G,s,a,g)}catch{return new D}}return new D}e.complete(i.toolCallId),Reflect.deleteProperty(c,h);let m;if(t!==void 0)try{m=t(d,s,a,g)}catch{m=$(d,a,i.isError)}else m=$(d,a,i.isError);if(!r)return m;let S=w(a,i);return p!==void 0?(p.update(m,S),p):new I(m,S)}}}l(V,"withToolCallInterceptionRendering");function K(n,e){return new H(e.fg("toolTitle",e.bold(n)),0,0)}l(K,"fallbackCall");function $(n,e,o){let t=n.content.filter(r=>r.type==="text").map(r=>r.text).join(`
1
+ import{c as w,h as _}from"./chunk-PS2B6THP.js";import{a as l}from"./chunk-EI7MMDWY.js";import{Container as D,Text as H,truncateToWidth as E,visibleWidth as W}from"@earendil-works/pi-tui";var v="pi-agent-text-editor/tool-call-interception",h=Symbol("pi-agent-tool-call-interception/annotation"),k=Symbol("pi-agent-tool-call-interception/render-argument-patch"),y=Symbol("pi-agent-tool-call-interception/anchor-render-patch");function x(n){if(!C(n))return;let e=n[v];return Y(e)?e:void 0}l(x,"getToolCallInterception");function M(n,e,o){let t={annotation:e,...o!==void 0&&{blocked:{reason:o}}};return C(n)?{...n,[v]:t}:{[v]:t,agentDetails:n??null}}l(M,"withToolCallInterceptionDetails");function Q(n,e){return{...n,details:M(n.details,{kind:"blocked",reason:e},e)}}l(Q,"withBlockedToolResult");function j(n,e){if(n===void 0)return!1;let o=n,t=e,r=Reflect.ownKeys(e);return r.length===Reflect.ownKeys(n).length&&r.every(d=>o[d]===t[d])}l(j,"sameArgumentPatch");function U(n,e){let o={...n,...e},t=b(n),r=b(e);return(t!==void 0||r!==void 0)&&(o[y]={...t,...r}),o}l(U,"mergeArgumentPatches");function O(n){if(n===void 0||!(y in n))return n;let e={...n};return delete e[y],e}l(O,"argumentPatchWithoutAnchorRendering");function b(n){if(n!==void 0)return n[y]}l(b,"anchorRenderPatchFromArguments");var L=class{static{l(this,"ToolCallInterceptionRenderStore")}entries=new Map;annotate=l((e,o)=>{let t=this.entries.get(e);this.entries.set(e,{annotation:o,renderArgumentPatch:t?.renderArgumentPatch,invalidate:t?.invalidate}),t?.invalidate?.()},"annotate");bind(e,o){let t=this.entries.get(e);return this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:t?.renderArgumentPatch,invalidate:o}),t?.annotation}get(e){return this.entries.get(e)?.annotation}resolveArguments=l((e,o)=>{let t=this.entries.get(e),r=U(t?.renderArgumentPatch,o);j(t?.renderArgumentPatch,r)||(this.entries.set(e,{annotation:t?.annotation,renderArgumentPatch:r,invalidate:t?.invalidate}),t?.invalidate?.())},"resolveArguments");getRenderArgumentPatch(e){return this.entries.get(e)?.renderArgumentPatch}complete(e){this.entries.delete(e)}clear(){this.entries.clear()}},P=class{constructor(e,o,t,r,d,s){this.component=e;this.theme=o;this.state=t;this.annotations=r;this.toolCallId=d;this.backgroundAnsi=s}static{l(this,"AnnotatedToolCall")}get inner(){return this.component}update(e,o,t,r){this.component=e,this.theme=o,this.state=t,this.backgroundAnsi=r}render(e){let o=this.component.render(e),t=this.annotations.get(this.toolCallId)??this.state[h],r;if(t===void 0)r=o;else{let d=F(t,this.theme);if(o.length===0)r=[E(d,e)];else{let s=` \u2190 ${d}`,a=W(s);r=a>=e?[E(s.trimStart(),e,""),...o.slice(1)]:[`${E(o[0]??"",e-a,"")}${s}`,...o.slice(1)]}}return B(r,this.backgroundAnsi)}invalidate(){this.component.invalidate()}},I=class{constructor(e,o){this.component=e;this.backgroundAnsi=o}static{l(this,"EnclosingBackgroundComponent")}get inner(){return this.component}update(e,o){this.component=e,this.backgroundAnsi=o}render(e){return B(this.component.render(e),this.backgroundAnsi)}invalidate(){this.component.invalidate()}};function B(n,e){return e===void 0?[...n]:n.map(o=>_(o,e))}l(B,"preserveBackgroundLines");function V(n,e){let o=n.renderCall,t=n.renderResult,r=n.renderShell!=="self";return{...n,get description(){return n.description},get promptGuidelines(){return n.promptGuidelines},get parameters(){return n.parameters},renderCall(d,s,a){let i=a.state,c=e.bind(a.toolCallId,a.invalidate),u=e.getRenderArgumentPatch(a.toolCallId)??i[k],T=b(u),R=O(u);u!==void 0&&(i[k]=u),T!==void 0&&(i[y]=T);let p=R===void 0?d:{...R,...d};c!==void 0&&(i[h]=c);let g=a.lastComponent instanceof P?a.lastComponent:void 0,f;try{f=o?.(p,s,{...a,args:p,lastComponent:g?.inner})??K(n.name,s)}catch{f=K(n.name,s)}let A=r?w(s,a):void 0;return g!==void 0?(g.update(f,s,i,A),g):new P(f,s,i,e,a.toolCallId,A)},renderResult(d,s,a,i){let c=i.state,u=e.getRenderArgumentPatch(i.toolCallId)??c[k],T=b(u),R=O(u);u!==void 0&&(c[k]=u),T!==void 0&&(c[y]=T);let p=i.lastComponent instanceof I?i.lastComponent:void 0,g={...i,...R!==void 0&&{args:{...R,...i.args}},lastComponent:p?.inner??i.lastComponent},f=x(d.details)?.annotation,A=e.get(i.toolCallId)??c[h],N=f??(s.isPartial||i.isError?A:void 0);if(N!==void 0){if(c[h]=N,e.complete(i.toolCallId),t!==void 0){let G={...d,content:[],details:void 0};try{t(G,s,a,g)}catch{return new D}}return new D}e.complete(i.toolCallId),Reflect.deleteProperty(c,h);let m;if(t!==void 0)try{m=t(d,s,a,g)}catch{m=$(d,a,i.isError)}else m=$(d,a,i.isError);if(!r)return m;let S=w(a,i);return p!==void 0?(p.update(m,S),p):new I(m,S)}}}l(V,"withToolCallInterceptionRendering");function K(n,e){return new H(e.fg("toolTitle",e.bold(n)),0,0)}l(K,"fallbackCall");function $(n,e,o){let t=n.content.filter(r=>r.type==="text").map(r=>r.text).join(`
2
2
  `);return t.length===0?new D:new H(e.fg(o?"error":"toolOutput",t),0,0)}l($,"fallbackResult");function F(n,e){let o=n.kind==="stale-anchor",t=o?"\u26A0":"\u2298",r=n.label??(o?"Stale Anchor":"Blocked"),d=n.color??(o?"warning":"error"),s=n.reason===void 0?"":`: ${n.reason}`;return e.fg(d,`${t} ${r}${s}`)}l(F,"renderAnnotation");function Y(n){return!C(n)||!q(n.annotation)?!1:n.blocked===void 0||C(n.blocked)&&typeof n.blocked.reason=="string"}l(Y,"isToolCallInterceptionDetails");function q(n){return!C(n)||typeof n.kind!="string"||n.label!==void 0&&typeof n.label!="string"||n.reason!==void 0&&typeof n.reason!="string"||n.color!==void 0&&typeof n.color!="string"?!1:n.kind==="blocked"?typeof n.reason=="string":n.kind==="custom"?typeof n.label=="string"&&typeof n.color=="string":n.kind==="stale-anchor"||n.kind==="aborted"}l(q,"isToolCallAnnotation");function C(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}l(C,"isRecord");export{v as a,y as b,x as c,M as d,Q as e,L as f,V as g,q as h};
@@ -1,2 +1,2 @@
1
- import{b as k,e as m}from"./chunk-FK42RSF4.js";import{a as b,b as v}from"./chunk-PS2B6THP.js";import{a as s}from"./chunk-EI7MMDWY.js";import h from"node:path";import{pathToFileURL as $}from"node:url";function T(e,n,t,o,i,a=[],l=[]){let c=a.map(r=>({kind:"note",text:r}));c.push(...v(e.flatMap(r=>{let p=h.isAbsolute(r.source),D=p&&i?h.relative(i,r.source)||h.basename(r.source):r.source,z=p?$(r.source).href:/^https?:/iu.test(r.source)?r.source:void 0,R=r.endLineNumber??r.lineNumber;return(R===r.lineNumber?[r.lineText]:[r.lineText,...r.matchedText.split(/\r\n|\n|\r/u).slice(1)]).slice(0,20).map((x,g)=>({source:r.source,label:D,...z===void 0?{}:{link:z},...p?{}:{badge:/^https?:/iu.test(r.source)?"WEB":"SH"},lineNumber:r.lineNumber+g,text:x,ranges:[{from:g?0:r.startColumn,to:r.lineNumber+g===R?r.endColumn:x.length}]}))}))),e.length||c.push({kind:"note",text:"No matches found"}),e.some(r=>(r.endLineNumber??r.lineNumber)-r.lineNumber>=20)&&c.push({kind:"note",text:"\u2026 source preview shortened"}),c.push(...l.map(r=>({kind:"note",text:r,expandedOnly:!0})));let u=`${e.length}${n?"":"+"}`,f=new Set(e.map(r=>r.source)),A=e.every(r=>h.isAbsolute(r.source));return new b({summary:`${u} ${e.length===1?"match":"matches"} in ${f.size} ${A?f.size===1?"file":"files":f.size===1?"source":"sources"}`,rows:c},t,o)}s(T,"renderSearchMatches");function N(e,n){return e.targets.some(t=>t.source===n.source&&t.ranges.some(o=>(o.start.lineNumber<n.lineNumber||o.start.lineNumber===n.lineNumber&&o.start.column<=n.startColumn)&&(o.end.lineNumber>(n.endLineNumber??n.lineNumber)||o.end.lineNumber===(n.endLineNumber??n.lineNumber)&&o.end.column>=n.endColumn)))}s(N,"containsSearchMatch");import{Value as I}from"typebox/value";var d={candidates:5,previewMatches:3,identifiers:2e4,identifierLength:80,vocabularyBytes:8*1024*1024,matchesPerCandidate:200,verificationBytes:4*1024*1024,timeoutMs:2e3};function L(e){return I.Check(k,e)}s(L,"isFuzzyResultData");function y(e){return e.length>=5&&e.length<=d.identifierLength&&/^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(e)&&/[A-Za-z]/u.test(e)}s(y,"isFuzzyQuery");var S=class{static{s(this,"FuzzyVocabulary")}names=new Set;bytes=0;limited=!1;account(n){return this.bytes+=n,this.bytes>d.vocabularyBytes&&(this.limited=!0),!this.limited}add(n){if(!(this.limited||!y(n)||this.names.has(n))){if(this.names.size===d.identifiers){this.limited=!0;return}this.names.add(n)}}addText(n){if(this.account(Buffer.byteLength(n))){for(let t of n.matchAll(/[A-Za-z_$][A-Za-z0-9_$]*/gu))if(this.add(t[0]),this.limited)break}}};function C(e){return e.replace(/([A-Z]+)([A-Z][a-z])/gu,"$1 $2").replace(/([a-z0-9])([A-Z])/gu,"$1 $2").split(/[^A-Za-z0-9]+/u).filter(Boolean).map(n=>n.toLowerCase())}s(C,"splitName");function w(e,n){return e.length===n.length&&e.every((t,o)=>t===n[o])}s(w,"same");function M(e,n){if(e.length<5||n.length<5||Math.abs(e.length-n.length)>1||/\d/u.test(e+n))return!1;let t=0;for(;t<Math.min(e.length,n.length)&&e[t]===n[t];)t++;if(e.length===n.length)return e.slice(t+1)===n.slice(t+1)||e[t]===n[t+1]&&e[t+1]===n[t]&&e.slice(t+2)===n.slice(t+2);let o=e.length<n.length?e:n,i=e.length<n.length?n:e;return o.slice(t)===i.slice(t+1)}s(M,"oneTypo");function P(e,n){if(e.join("")===n.join(""))return{kind:"normalized",reason:"same spelling with different case or separators"};let t=e.length<n.length?e:n,o=e.length<n.length?n:e;if(o.length===t.length+1&&t.length>=2&&t.every(l=>l.length>=3)){let l=w(t,o.slice(1)),c=w(t,o.slice(0,-1));if(l||c)return{kind:"component",reason:`${e.length>n.length?"remove":"add"} ${l?"leading":"trailing"} component '${l?o[0]:o.at(-1)}'`}}if(e.length!==n.length)return;let i=e.flatMap((l,c)=>{let u=n[c];return u!==void 0&&l!==u?[{word:l,other:u}]:[]}),a=i[0];if(!(i.length!==1||!a||!M(a.word,a.other)))return{kind:"typo",reason:`one character edit: '${a.word}' \u2192 '${a.other}'`}}s(P,"relation");var F={normalized:0,component:1,typo:2};function E(e,n){if(!y(e))return[];let t=C(e);if(t.length===0)return[];let o=[];for(let i of new Set(n)){if(i===e||!y(i))continue;let a=P(t,C(i));a&&o.push({identifier:i,...a})}return o.sort((i,a)=>F[i.kind]-F[a.kind]||(i.identifier<a.identifier?-1:i.identifier>a.identifier?1:0)).slice(0,d.candidates)}s(E,"rankFuzzyIdentifiers");function _(e,n,t){return{identifier:e.identifier,kind:e.kind,reason:e.reason,matchCount:e.matches.length,fileCount:new Set(e.matches.map(o=>o.source)).size,selection:{...m(e.matches.slice(0,d.previewMatches),e.complete,n,t),truncated:e.matches.length>d.previewMatches}}}s(_,"fuzzyCandidateData");function O(e){let n=e.selection.complete?"":"+",t=e.selection.all?.line??e.selection.matches[0]?.references?.line,o=e.selection.matches[0],i=t??o?.source;return[`Possible name: ${e.identifier} (${e.reason})`,`${e.matchCount}${n} ${e.matchCount===1&&e.selection.complete?"match":"matches"} in ${e.fileCount}${n} ${e.fileCount===1&&e.selection.complete?"file":"files"}`,`Exact alternative: ${JSON.stringify(e.identifier)} (case-sensitive, whole identifier)`,...e.selection.complete?[]:["Capture limit reached; no complete all reference."],...i?[`Read: ${i}${t||!o?"":` \xB7 line ${o.range.startLine}`}`]:[]].join(`
1
+ import{b as k,e as m}from"./chunk-GXEGY7GV.js";import{a as b,b as v}from"./chunk-PS2B6THP.js";import{a as s}from"./chunk-EI7MMDWY.js";import h from"node:path";import{pathToFileURL as $}from"node:url";function T(e,n,t,o,i,a=[],l=[]){let c=a.map(r=>({kind:"note",text:r}));c.push(...v(e.flatMap(r=>{let p=h.isAbsolute(r.source),D=p&&i?h.relative(i,r.source)||h.basename(r.source):r.source,z=p?$(r.source).href:/^https?:/iu.test(r.source)?r.source:void 0,R=r.endLineNumber??r.lineNumber;return(R===r.lineNumber?[r.lineText]:[r.lineText,...r.matchedText.split(/\r\n|\n|\r/u).slice(1)]).slice(0,20).map((x,g)=>({source:r.source,label:D,...z===void 0?{}:{link:z},...p?{}:{badge:/^https?:/iu.test(r.source)?"WEB":"SH"},lineNumber:r.lineNumber+g,text:x,ranges:[{from:g?0:r.startColumn,to:r.lineNumber+g===R?r.endColumn:x.length}]}))}))),e.length||c.push({kind:"note",text:"No matches found"}),e.some(r=>(r.endLineNumber??r.lineNumber)-r.lineNumber>=20)&&c.push({kind:"note",text:"\u2026 source preview shortened"}),c.push(...l.map(r=>({kind:"note",text:r,expandedOnly:!0})));let u=`${e.length}${n?"":"+"}`,f=new Set(e.map(r=>r.source)),A=e.every(r=>h.isAbsolute(r.source));return new b({summary:`${u} ${e.length===1?"match":"matches"} in ${f.size} ${A?f.size===1?"file":"files":f.size===1?"source":"sources"}`,rows:c},t,o)}s(T,"renderSearchMatches");function N(e,n){return e.targets.some(t=>t.source===n.source&&t.ranges.some(o=>(o.start.lineNumber<n.lineNumber||o.start.lineNumber===n.lineNumber&&o.start.column<=n.startColumn)&&(o.end.lineNumber>(n.endLineNumber??n.lineNumber)||o.end.lineNumber===(n.endLineNumber??n.lineNumber)&&o.end.column>=n.endColumn)))}s(N,"containsSearchMatch");import{Value as I}from"typebox/value";var d={candidates:5,previewMatches:3,identifiers:2e4,identifierLength:80,vocabularyBytes:8*1024*1024,matchesPerCandidate:200,verificationBytes:4*1024*1024,timeoutMs:2e3};function L(e){return I.Check(k,e)}s(L,"isFuzzyResultData");function y(e){return e.length>=5&&e.length<=d.identifierLength&&/^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(e)&&/[A-Za-z]/u.test(e)}s(y,"isFuzzyQuery");var S=class{static{s(this,"FuzzyVocabulary")}names=new Set;bytes=0;limited=!1;account(n){return this.bytes+=n,this.bytes>d.vocabularyBytes&&(this.limited=!0),!this.limited}add(n){if(!(this.limited||!y(n)||this.names.has(n))){if(this.names.size===d.identifiers){this.limited=!0;return}this.names.add(n)}}addText(n){if(this.account(Buffer.byteLength(n))){for(let t of n.matchAll(/[A-Za-z_$][A-Za-z0-9_$]*/gu))if(this.add(t[0]),this.limited)break}}};function C(e){return e.replace(/([A-Z]+)([A-Z][a-z])/gu,"$1 $2").replace(/([a-z0-9])([A-Z])/gu,"$1 $2").split(/[^A-Za-z0-9]+/u).filter(Boolean).map(n=>n.toLowerCase())}s(C,"splitName");function w(e,n){return e.length===n.length&&e.every((t,o)=>t===n[o])}s(w,"same");function M(e,n){if(e.length<5||n.length<5||Math.abs(e.length-n.length)>1||/\d/u.test(e+n))return!1;let t=0;for(;t<Math.min(e.length,n.length)&&e[t]===n[t];)t++;if(e.length===n.length)return e.slice(t+1)===n.slice(t+1)||e[t]===n[t+1]&&e[t+1]===n[t]&&e.slice(t+2)===n.slice(t+2);let o=e.length<n.length?e:n,i=e.length<n.length?n:e;return o.slice(t)===i.slice(t+1)}s(M,"oneTypo");function P(e,n){if(e.join("")===n.join(""))return{kind:"normalized",reason:"same spelling with different case or separators"};let t=e.length<n.length?e:n,o=e.length<n.length?n:e;if(o.length===t.length+1&&t.length>=2&&t.every(l=>l.length>=3)){let l=w(t,o.slice(1)),c=w(t,o.slice(0,-1));if(l||c)return{kind:"component",reason:`${e.length>n.length?"remove":"add"} ${l?"leading":"trailing"} component '${l?o[0]:o.at(-1)}'`}}if(e.length!==n.length)return;let i=e.flatMap((l,c)=>{let u=n[c];return u!==void 0&&l!==u?[{word:l,other:u}]:[]}),a=i[0];if(!(i.length!==1||!a||!M(a.word,a.other)))return{kind:"typo",reason:`one character edit: '${a.word}' \u2192 '${a.other}'`}}s(P,"relation");var F={normalized:0,component:1,typo:2};function E(e,n){if(!y(e))return[];let t=C(e);if(t.length===0)return[];let o=[];for(let i of new Set(n)){if(i===e||!y(i))continue;let a=P(t,C(i));a&&o.push({identifier:i,...a})}return o.sort((i,a)=>F[i.kind]-F[a.kind]||(i.identifier<a.identifier?-1:i.identifier>a.identifier?1:0)).slice(0,d.candidates)}s(E,"rankFuzzyIdentifiers");function _(e,n,t){return{identifier:e.identifier,kind:e.kind,reason:e.reason,matchCount:e.matches.length,fileCount:new Set(e.matches.map(o=>o.source)).size,selection:{...m(e.matches.slice(0,d.previewMatches),e.complete,n,t),truncated:e.matches.length>d.previewMatches}}}s(_,"fuzzyCandidateData");function O(e){let n=e.selection.complete?"":"+",t=e.selection.all?.line??e.selection.matches[0]?.references?.line,o=e.selection.matches[0],i=t??o?.source;return[`Possible name: ${e.identifier} (${e.reason})`,`${e.matchCount}${n} ${e.matchCount===1&&e.selection.complete?"match":"matches"} in ${e.fileCount}${n} ${e.fileCount===1&&e.selection.complete?"file":"files"}`,`Exact alternative: ${JSON.stringify(e.identifier)} (case-sensitive, whole identifier)`,...e.selection.complete?[]:["Capture limit reached; no complete all reference."],...i?[`Read: ${i}${t||!o?"":` \xB7 line ${o.range.startLine}`}`]:[]].join(`
2
2
  `)}s(O,"formatFuzzyCandidate");export{T as a,N as b,d as c,L as d,y as e,S as f,E as g,_ as h,O as i};
package/dist/entry-11.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-IQD6PON5.js";import"./chunk-KR36BT5E.js";import{a as l}from"./chunk-YRF7OATP.js";import{a as s,b as c}from"./chunk-FXNKMNSJ.js";import"./chunk-U2JKHKLK.js";import"./chunk-7LZKOHH2.js";import"./chunk-NNCZYO4Q.js";import"./chunk-64M3SQPG.js";import{a as g}from"./chunk-6CZO43OH.js";import{a as f,b as y}from"./chunk-OBNING2A.js";import"./chunk-PS2B6THP.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function x(n,e){return u(e),g(n,{protocol:f,apiVersion:y,id:`hook/before-read/${e.id}`,setup(t){t.addResourceGuard({id:e.id,async guard(o){let r=await e.run(o);return r.decision==="allow"?{kind:"accepted"}:{kind:"rejected",reason:r.reason}}})}})}d(x,"connectBeforeReadHook");function A(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/before-edit/${e.id}`,setup(t){t.addMutationGuard({id:e.id,async guard(o,r){let a=await e.run({cwd:r.cwd,intent:r.intent??"edit",resources:o.resources.map(i=>({resourceSource:i.source,existed:i.existed,before:i.before,after:i.after,changes:i.changes})),...r.signal!==void 0&&{signal:r.signal}});return a.decision==="allow"?{kind:"accepted"}:{kind:"rejected",rejection:{code:"MUTATION_REJECTED",reason:a.reason,message:`Edit blocked by hook ${e.id}: ${a.reason}`,effect:"not-applied"}}}})}})}d(A,"connectBeforeEditHook");function m(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/after-edit/${e.id}`,setup(t){t.onDidEdit(async o=>{if(o.postProcessing!=="deferred")try{return await e.run(o)}catch(r){return{feedback:`After-edit hook ${e.id} failed after the edit was saved: ${r instanceof Error?r.message:String(r)}`,tone:"error"}}})}})}d(m,"connectAfterEditHook");function u(n){if(n.id.trim().length===0||typeof n.run!="function")throw new TypeError("A file hook needs a non-empty id and run function")}d(u,"assertHook");export{m as connectAfterEditHook,A as connectBeforeEditHook,x as connectBeforeReadHook};
1
+ import"./chunk-IQD6PON5.js";import"./chunk-PGIVHICI.js";import{a as l}from"./chunk-PKKDDIWW.js";import{a as s,b as c}from"./chunk-4GCWGE2C.js";import"./chunk-U2JKHKLK.js";import"./chunk-D3WTDA6V.js";import"./chunk-NNCZYO4Q.js";import"./chunk-64M3SQPG.js";import{a as g}from"./chunk-BU7IZLKB.js";import{a as f,b as y}from"./chunk-S5PL5DFQ.js";import"./chunk-PS2B6THP.js";import"./chunk-CWD4O5PM.js";import"./chunk-ZPT5D4VP.js";import"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function x(n,e){return u(e),g(n,{protocol:f,apiVersion:y,id:`hook/before-read/${e.id}`,setup(t){t.addResourceGuard({id:e.id,async guard(o){let r=await e.run(o);return r.decision==="allow"?{kind:"accepted"}:{kind:"rejected",reason:r.reason}}})}})}d(x,"connectBeforeReadHook");function A(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/before-edit/${e.id}`,setup(t){t.addMutationGuard({id:e.id,async guard(o,r){let a=await e.run({cwd:r.cwd,intent:r.intent??"edit",resources:o.resources.map(i=>({resourceSource:i.source,existed:i.existed,before:i.before,after:i.after,changes:i.changes})),...r.signal!==void 0&&{signal:r.signal}});return a.decision==="allow"?{kind:"accepted"}:{kind:"rejected",rejection:{code:"MUTATION_REJECTED",reason:a.reason,message:`Edit blocked by hook ${e.id}: ${a.reason}`,effect:"not-applied"}}}})}})}d(A,"connectBeforeEditHook");function m(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/after-edit/${e.id}`,setup(t){t.onDidEdit(async o=>{if(o.postProcessing!=="deferred")try{return await e.run(o)}catch(r){return{feedback:`After-edit hook ${e.id} failed after the edit was saved: ${r instanceof Error?r.message:String(r)}`,tone:"error"}}})}})}d(m,"connectAfterEditHook");function u(n){if(n.id.trim().length===0||typeof n.run!="function")throw new TypeError("A file hook needs a non-empty id and run function")}d(u,"assertHook");export{m as connectAfterEditHook,A as connectBeforeEditHook,x as connectBeforeReadHook};
package/dist/entry-13.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-U2JKHKLK.js";import{a as k,b as l,c as m,d as n,e as o,f as p,g as q,h as r,i as s,j as t}from"./chunk-7LZKOHH2.js";import"./chunk-NNCZYO4Q.js";import{b as i,d as j}from"./chunk-64M3SQPG.js";import{a as h}from"./chunk-6CZO43OH.js";import{a,b,c,d,e,f,g}from"./chunk-OBNING2A.js";import"./chunk-PS2B6THP.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import"./chunk-ZC65Z3CK.js";import"./chunk-EI7MMDWY.js";export{i as COMPACT_READ_ROWS,b as READ_API_VERSION,c as READ_CORE_READY_EVENT,d as READ_PLUGIN_REGISTER_EVENT,a as READ_PROTOCOL,h as connectReadPlugin,j as createReadResultRenderer,s as isFragmentResolverRegistration,e as isReadCoreReady,t as isReadFragmentResolution,q as isReadHandlerRegistration,f as isReadPlugin,g as isReadPluginRegistrationRequest,r as isReadViewRegistration,p as isResourceResolverRegistration,o as isTextTargetResolverRegistration,l as readDataSchema,m as readOutputSchema,k as readParameters,n as structuredRead};
1
+ import"./chunk-U2JKHKLK.js";import{a as k,c as l,d as m,e as n,f as o,g as p,h as q,i as r,j as s,k as t}from"./chunk-D3WTDA6V.js";import"./chunk-NNCZYO4Q.js";import{b as i,d as j}from"./chunk-64M3SQPG.js";import{a as h}from"./chunk-BU7IZLKB.js";import{a,b,c,d,e,f,g}from"./chunk-S5PL5DFQ.js";import"./chunk-PS2B6THP.js";import"./chunk-CWD4O5PM.js";import"./chunk-ZPT5D4VP.js";import"./chunk-ZC65Z3CK.js";import"./chunk-EI7MMDWY.js";export{i as COMPACT_READ_ROWS,b as READ_API_VERSION,c as READ_CORE_READY_EVENT,d as READ_PLUGIN_REGISTER_EVENT,a as READ_PROTOCOL,h as connectReadPlugin,j as createReadResultRenderer,s as isFragmentResolverRegistration,e as isReadCoreReady,t as isReadFragmentResolution,q as isReadHandlerRegistration,f as isReadPlugin,g as isReadPluginRegistrationRequest,r as isReadViewRegistration,p as isResourceResolverRegistration,o as isTextTargetResolverRegistration,l as readDataSchema,m as readOutputSchema,k as readParameters,n as structuredRead};
package/dist/entry-14.js CHANGED
@@ -1 +1 @@
1
- import{A,B,C,D,E,F,G,H,I,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"./chunk-SQKAXYIR.js";import"./chunk-EI7MMDWY.js";export{y as CONTENT_API_VERSION,A as CONTENT_CONVERTER_REGISTER_EVENT,z as CONTENT_HOST_READY_EVENT,w as CONTENT_PROTOCOL,p as MAX_STRUCTURED_BYTES,o as ResourceScheduler,G as ResultTargetStore,s as UnsupportedContentError,t as assertJsonData,E as connectContentConverter,I as connectResultTargets,D as createContentHost,u as createContentRunner,c as isAgentContent,n as isContentConversionAttempt,k as isContentConversionContext,l as isContentConverter,q as isContentConverterRegistration,C as isContentConverterRegistrationRequest,B as isContentHostReady,j as isContentInput,i as isContentTarget,d as isResource,h as isResourceResolutionAttempt,g as isResourceResolver,b as renderContentDescription,e as resourceAccesses,r as resourceScheduler,x as resultError,f as resultErrorSchema,F as resultInputSchema,m as structuredResultSchema,v as targetsEqual,H as verifyResultTargets,a as withStructuredResult};
1
+ import{A,B,C,D,E,F,G,H,I,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"./chunk-CWD4O5PM.js";import"./chunk-EI7MMDWY.js";export{y as CONTENT_API_VERSION,A as CONTENT_CONVERTER_REGISTER_EVENT,z as CONTENT_HOST_READY_EVENT,w as CONTENT_PROTOCOL,p as MAX_STRUCTURED_BYTES,o as ResourceScheduler,G as ResultTargetStore,s as UnsupportedContentError,t as assertJsonData,E as connectContentConverter,I as connectResultTargets,D as createContentHost,u as createContentRunner,c as isAgentContent,n as isContentConversionAttempt,k as isContentConversionContext,l as isContentConverter,q as isContentConverterRegistration,C as isContentConverterRegistrationRequest,B as isContentHostReady,j as isContentInput,i as isContentTarget,d as isResource,h as isResourceResolutionAttempt,g as isResourceResolver,b as renderContentDescription,e as resourceAccesses,r as resourceScheduler,x as resultError,f as resultErrorSchema,F as resultInputSchema,m as structuredResultSchema,v as targetsEqual,H as verifyResultTargets,a as withStructuredResult};
package/dist/entry-15.js CHANGED
@@ -1 +1 @@
1
- import{a as b,b as c,c as i,d as j,e as k,f as l,g as n,h as q,i as s}from"./chunk-AJRIASPQ.js";import{a,c as d,d as g,e as h}from"./chunk-FK42RSF4.js";import{a as x}from"./chunk-ZTYWHL2F.js";import{a as o,b as r,c as e,d as f,e as m,f as p,g as t}from"./chunk-7UGNGK7Y.js";import"./chunk-PS2B6THP.js";import"./chunk-SQKAXYIR.js";import"./chunk-EI7MMDWY.js";export{l as FuzzyVocabulary,r as SEARCH_API_VERSION,e as SEARCH_CORE_READY_EVENT,f as SEARCH_PLUGIN_REGISTER_EVENT,o as SEARCH_PROTOCOL,x as connectSearchPlugin,c as containsSearchMatch,s as formatFuzzyCandidate,q as fuzzyCandidateData,i as fuzzyLimits,k as isFuzzyQuery,j as isFuzzyResultData,m as isSearchCoreReady,p as isSearchPlugin,t as isSearchPluginRegistrationRequest,n as rankFuzzyIdentifiers,b as renderSearchMatches,d as searchDataSchema,g as searchOutputSchema,a as searchSchema,h as selectionData};
1
+ import{a as b,b as c,c as i,d as j,e as k,f as l,g as n,h as q,i as s}from"./chunk-YP46DVVP.js";import{a,c as d,d as g,e as h}from"./chunk-GXEGY7GV.js";import{a as x}from"./chunk-ZTYWHL2F.js";import{a as o,b as r,c as e,d as f,e as m,f as p,g as t}from"./chunk-7UGNGK7Y.js";import"./chunk-PS2B6THP.js";import"./chunk-CWD4O5PM.js";import"./chunk-EI7MMDWY.js";export{l as FuzzyVocabulary,r as SEARCH_API_VERSION,e as SEARCH_CORE_READY_EVENT,f as SEARCH_PLUGIN_REGISTER_EVENT,o as SEARCH_PROTOCOL,x as connectSearchPlugin,c as containsSearchMatch,s as formatFuzzyCandidate,q as fuzzyCandidateData,i as fuzzyLimits,k as isFuzzyQuery,j as isFuzzyResultData,m as isSearchCoreReady,p as isSearchPlugin,t as isSearchPluginRegistrationRequest,n as rankFuzzyIdentifiers,b as renderSearchMatches,d as searchDataSchema,g as searchOutputSchema,a as searchSchema,h as selectionData};
package/dist/entry-17.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-IQD6PON5.js";import{m as o}from"./chunk-KR36BT5E.js";import{a as n}from"./chunk-YRF7OATP.js";import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-FXNKMNSJ.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import"./chunk-EI7MMDWY.js";export{b as TEXT_EDITOR_API_VERSION,e as TEXT_EDITOR_CORE_READY_EVENT,f as TEXT_EDITOR_PLUGIN_REGISTER_EVENT,a as TEXT_EDITOR_PROTOCOL,c as TEXT_POSITION_ANCHOR_KIND,d as TEXT_SEARCH_ANCHOR_KIND,n as connectTextEditorPlugin,o as connectTextEditorPostEditHandler,h as isResourceResolverRegistration,i as isTextAnchorResolverRegistration,j as isTextAnchorResourceResolutionAttempt,k as isTextEditorCoreReady,l as isTextEditorPlugin,m as isTextEditorPluginRegistrationRequest,g as isTextEditorToolId};
1
+ import"./chunk-IQD6PON5.js";import{m as o}from"./chunk-PGIVHICI.js";import{a as n}from"./chunk-PKKDDIWW.js";import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-4GCWGE2C.js";import"./chunk-CWD4O5PM.js";import"./chunk-ZPT5D4VP.js";import"./chunk-EI7MMDWY.js";export{b as TEXT_EDITOR_API_VERSION,e as TEXT_EDITOR_CORE_READY_EVENT,f as TEXT_EDITOR_PLUGIN_REGISTER_EVENT,a as TEXT_EDITOR_PROTOCOL,c as TEXT_POSITION_ANCHOR_KIND,d as TEXT_SEARCH_ANCHOR_KIND,n as connectTextEditorPlugin,o as connectTextEditorPostEditHandler,h as isResourceResolverRegistration,i as isTextAnchorResolverRegistration,j as isTextAnchorResourceResolutionAttempt,k as isTextEditorCoreReady,l as isTextEditorPlugin,m as isTextEditorPluginRegistrationRequest,g as isTextEditorToolId};
package/dist/entry-25.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as k}from"./chunk-YRF7OATP.js";import{a as A,b as D}from"./chunk-FXNKMNSJ.js";import"./chunk-NNCZYO4Q.js";import{d as T}from"./chunk-64M3SQPG.js";import{a as P}from"./chunk-6CZO43OH.js";import{a as F,b as C}from"./chunk-OBNING2A.js";import"./chunk-PS2B6THP.js";import{D as v,j as E}from"./chunk-SQKAXYIR.js";import{r as b}from"./chunk-ZPT5D4VP.js";import{a as p}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import{readdirSync as V,realpathSync as j,statSync as U}from"node:fs";import{mkdir as $,readFile as z,writeFile as Z}from"node:fs/promises";import I from"node:path";import{fileURLToPath as B,pathToFileURL as G}from"node:url";function O(e){return _("read",e)}s(O,"createFilesystemReadResolver");function S(e){return _("write",e)}s(S,"createFilesystemWriteResolver");function _(e,t){return{id:"filesystem",tryResolve(r,n){return Promise.resolve(X(r,n,e,t))}}}s(_,"createFilesystemResolver");function X(e,t,r,n){if(e.length===0)return{kind:"failed",error:new TypeError("Filesystem source must not be empty")};if(!K(e))return{kind:"not-handled"};if(t.signal?.aborted===!0)return{kind:"failed",error:x()};let o=e.startsWith("file://")?j(B(new URL(e))):I.resolve(t.cwd,e),i=G(o).href,d=(()=>{try{return U(o).isDirectory()}catch{return!1}})(),u=s(async({signal:f})=>d?q(o,f):J(o,n,f),"read");return r==="read"||d?{kind:"resolved",resource:{source:o,link:i,read:u}}:{kind:"resolved",resource:{source:o,link:i,read:u,async write(f,m){y(m.signal);let h=b(f);await $(I.dirname(o),{recursive:!0}),y(m.signal),await Z(o,h,{encoding:"utf8",...m.signal!==void 0&&{signal:m.signal}})}}}}s(X,"resolveFilesystemSource");function q(e,t){y(t);let r=V(e,{withFileTypes:!0}),n=[`\u{1F4C1} ${e}/`];r.length>0&&n.push("");for(let o of r){let i=o.isDirectory()?"\u{1F4C1}":o.isFile()?"\u{1F4C4}":"\u{1F517}";n.push(` ${i} ${o.name}`)}return[{type:"text",text:n.join(`
2
- `)}]}s(q,"readDirectoryContent");async function J(e,t,r){y(r);let n=await z(e,{encoding:null,...r!==void 0&&{signal:r}});return y(r),t.convert({source:e,bytes:n},r===void 0?{}:{signal:r})}s(J,"readFilesystemContent");function K(e){return/^[A-Za-z]:[\\/]/u.test(e)||e.startsWith("file://")?!0:!/^[A-Za-z][A-Za-z\d+.-]*:/u.test(e)}s(K,"isFilesystemSource");function y(e){if(e?.aborted===!0)throw x()}s(y,"throwIfAborted");function x(){let e=new Error("The operation was aborted");return e.name="AbortError",e}s(x,"abortError");import{execFile as Q}from"node:child_process";import{existsSync as Y}from"node:fs";import{realpath as H}from"node:fs/promises";import ee from"node:os";import c from"node:path";import{fileURLToPath as te}from"node:url";async function L(e,t){let r=e.cause,n=Date.now()+500;if(t.signal?.aborted||e.source===void 0||typeof r!="object"||r===null||!("code"in r)||r.code!=="ENOENT")return;let o=e.source.startsWith("file://")?te(e.source):e.source,i=c.relative(t.cwd,c.resolve(t.cwd,o));if(!w(i)||i.includes("#"))return;let d=c.basename(i).toLowerCase();if(d.length<3||d.length>160)return;let u=c.join(process.env.PI_CODING_AGENT_DIR??c.join(ee.homedir(),".pi","agent"),"bin",process.platform==="win32"?"rg.exe":"rg"),f=await new Promise(a=>{Q(Y(u)?u:"rg",["--files","--hidden","--no-config","--no-ignore-parent","--null","--glob","!.git/**"],{cwd:t.cwd,timeout:250,maxBuffer:2*1024*1024,...t.signal===void 0?{}:{signal:t.signal}},(l,R)=>a(l?[]:R.split("\0").filter(Boolean).slice(0,2e4)))}),m=Math.min(3,Math.max(1,Math.floor(d.length*.2))),h=f.flatMap(a=>{if(t.signal?.aborted||Date.now()>n||!w(a))return[];let l=c.basename(a).toLowerCase();if(l.length>160||Math.abs(l.length-d.length)>m)return[];let R=re(d,l);if(R>m)return[];let M=c.dirname(i).toLowerCase(),W=c.dirname(a).toLowerCase();return[{path:a,distance:R,directoryDistance:M===W?0:1}]}).sort((a,l)=>a.distance-l.distance||a.directoryDistance-l.directoryDistance||a.path.localeCompare(l.path)),g=[],N=await H(t.cwd);for(let a of h.slice(0,20)){if(t.signal?.aborted||Date.now()>n)return;try{let l=await H(c.resolve(t.cwd,a.path));w(c.relative(N,l))&&g.push({path:a.path})}catch{}if(g.length===3)break}return g.length?g:void 0}s(L,"recoverFilesystemPath");function w(e){return e!==""&&!/^\.\.(?:[\\/]|$)/u.test(e)&&!c.isAbsolute(e)}s(w,"insideWorkspace");function re(e,t){let r=Array.from({length:t.length+1},(n,o)=>o);for(let n=1;n<=e.length;n++){let o=[n];for(let i=1;i<=t.length;i++)o[i]=Math.min(p(o[i-1])+1,p(r[i])+1,p(r[i-1])+(e[n-1]===t[i-1]?0:1));r=o}return p(r[t.length])}s(re,"editDistance");var oe={provider:"filesystem",capability:"read"},ne={provider:"filesystem",capability:"write"},ie=T({kind:"source",nativeResources:!0});async function se(e){let t=v(e,oe),r=v(e,ne),n=O(t),o=S(r),i={protocol:F,apiVersion:C,id:"filesystem",setup(u){u.addResolver({resolver:n,renderResult:ie,recoverFailure:L}),u.describe(()=>E("File path \u2014 file content; directory path \u2014 entry listing. Relative, absolute and file:// paths accepted.",t.listDescriptions()))}},d={protocol:A,apiVersion:D,id:"filesystem",setup(u){u.addResolver({resolver:o})}};await Promise.all([P(e,i),k(e,d)])}s(se,"registerFilesystemPlugin");export{se as default};
1
+ import{a as k}from"./chunk-PKKDDIWW.js";import{a as A,b as D}from"./chunk-4GCWGE2C.js";import"./chunk-NNCZYO4Q.js";import{d as T}from"./chunk-64M3SQPG.js";import{a as P}from"./chunk-BU7IZLKB.js";import{a as F,b as C}from"./chunk-S5PL5DFQ.js";import"./chunk-PS2B6THP.js";import{D as v,j as E}from"./chunk-CWD4O5PM.js";import{r as b}from"./chunk-ZPT5D4VP.js";import{a as p}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import{readdirSync as V,realpathSync as j,statSync as U}from"node:fs";import{mkdir as $,readFile as z,writeFile as Z}from"node:fs/promises";import I from"node:path";import{fileURLToPath as B,pathToFileURL as G}from"node:url";function O(e){return _("read",e)}s(O,"createFilesystemReadResolver");function S(e){return _("write",e)}s(S,"createFilesystemWriteResolver");function _(e,t){return{id:"filesystem",tryResolve(r,n){return Promise.resolve(X(r,n,e,t))}}}s(_,"createFilesystemResolver");function X(e,t,r,n){if(e.length===0)return{kind:"failed",error:new TypeError("Filesystem source must not be empty")};if(!K(e))return{kind:"not-handled"};if(t.signal?.aborted===!0)return{kind:"failed",error:x()};let o=e.startsWith("file://")?j(B(new URL(e))):I.resolve(t.cwd,e),i=G(o).href,d=(()=>{try{return U(o).isDirectory()}catch{return!1}})(),u=s(async({signal:f})=>d?q(o,f):J(o,n,f),"read");return r==="read"||d?{kind:"resolved",resource:{source:o,link:i,read:u}}:{kind:"resolved",resource:{source:o,link:i,read:u,async write(f,m){y(m.signal);let h=b(f);await $(I.dirname(o),{recursive:!0}),y(m.signal),await Z(o,h,{encoding:"utf8",...m.signal!==void 0&&{signal:m.signal}})}}}}s(X,"resolveFilesystemSource");function q(e,t){y(t);let r=V(e,{withFileTypes:!0}),n=[`\u{1F4C1} ${e}/`];r.length>0&&n.push("");for(let o of r){let i=o.isDirectory()?"\u{1F4C1}":o.isFile()?"\u{1F4C4}":"\u{1F517}";n.push(` ${i} ${o.name}`)}return[{type:"text",text:n.join(`
2
+ `)}]}s(q,"readDirectoryContent");async function J(e,t,r){y(r);let n=await z(e,{encoding:null,...r!==void 0&&{signal:r}});return y(r),t.convert({source:e,bytes:n},r===void 0?{}:{signal:r})}s(J,"readFilesystemContent");function K(e){return/^[A-Za-z]:[\\/]/u.test(e)||e.startsWith("file://")?!0:!/^[A-Za-z][A-Za-z\d+.-]*:/u.test(e)}s(K,"isFilesystemSource");function y(e){if(e?.aborted===!0)throw x()}s(y,"throwIfAborted");function x(){let e=new Error("The operation was aborted");return e.name="AbortError",e}s(x,"abortError");import{execFile as Q}from"node:child_process";import{existsSync as Y}from"node:fs";import{realpath as H}from"node:fs/promises";import ee from"node:os";import c from"node:path";import{fileURLToPath as te}from"node:url";async function L(e,t){let r=e.cause,n=Date.now()+500;if(t.signal?.aborted||e.source===void 0||typeof r!="object"||r===null||!("code"in r)||r.code!=="ENOENT")return;let o=e.source.startsWith("file://")?te(e.source):e.source,i=c.relative(t.cwd,c.resolve(t.cwd,o));if(!w(i)||i.includes("#"))return;let d=c.basename(i).toLowerCase();if(d.length<3||d.length>160)return;let u=c.join(process.env.PI_CODING_AGENT_DIR??c.join(ee.homedir(),".pi","agent"),"bin",process.platform==="win32"?"rg.exe":"rg"),f=await new Promise(a=>{Q(Y(u)?u:"rg",["--files","--hidden","--no-config","--no-ignore-parent","--null","--glob","!.git/**"],{cwd:t.cwd,timeout:250,maxBuffer:2*1024*1024,...t.signal===void 0?{}:{signal:t.signal}},(l,R)=>a(l?[]:R.split("\0").filter(Boolean).slice(0,2e4)))}),m=Math.min(3,Math.max(1,Math.floor(d.length*.2))),h=f.flatMap(a=>{if(t.signal?.aborted||Date.now()>n||!w(a))return[];let l=c.basename(a).toLowerCase();if(l.length>160||Math.abs(l.length-d.length)>m)return[];let R=re(d,l);if(R>m)return[];let M=c.dirname(i).toLowerCase(),W=c.dirname(a).toLowerCase();return[{path:a,distance:R,directoryDistance:M===W?0:1}]}).sort((a,l)=>a.distance-l.distance||a.directoryDistance-l.directoryDistance||a.path.localeCompare(l.path)),g=[],N=await H(t.cwd);for(let a of h.slice(0,20)){if(t.signal?.aborted||Date.now()>n)return;try{let l=await H(c.resolve(t.cwd,a.path));w(c.relative(N,l))&&g.push({path:a.path})}catch{}if(g.length===3)break}return g.length?g:void 0}s(L,"recoverFilesystemPath");function w(e){return e!==""&&!/^\.\.(?:[\\/]|$)/u.test(e)&&!c.isAbsolute(e)}s(w,"insideWorkspace");function re(e,t){let r=Array.from({length:t.length+1},(n,o)=>o);for(let n=1;n<=e.length;n++){let o=[n];for(let i=1;i<=t.length;i++)o[i]=Math.min(p(o[i-1])+1,p(r[i])+1,p(r[i-1])+(e[n-1]===t[i-1]?0:1));r=o}return p(r[t.length])}s(re,"editDistance");var oe={provider:"filesystem",capability:"read"},ne={provider:"filesystem",capability:"write"},ie=T({kind:"source",nativeResources:!0});async function se(e){let t=v(e,oe),r=v(e,ne),n=O(t),o=S(r),i={protocol:F,apiVersion:C,id:"filesystem",setup(u){u.addResolver({resolver:n,renderResult:ie,recoverFailure:L}),u.describe({path:s(()=>E("File path \u2014 file content; directory path \u2014 entry listing. Relative, absolute and file:// paths accepted.",t.listDescriptions()),"path")})}},d={protocol:A,apiVersion:D,id:"filesystem",setup(u){u.addResolver({resolver:o})}};await Promise.all([P(e,i),k(e,d)])}s(se,"registerFilesystemPlugin");export{se as default};
package/dist/entry-26.js CHANGED
@@ -1 +1 @@
1
- import{a as r}from"./chunk-QIJMV2P2.js";import{E as e}from"./chunk-SQKAXYIR.js";import{a as t}from"./chunk-EI7MMDWY.js";var n={target:{provider:"filesystem",capability:"read"},converter:r(),priority:100};async function i(o){await e(o,n)}t(i,"registerFilesystemImage");export{i as default};
1
+ import{a as r}from"./chunk-QIJMV2P2.js";import{E as e}from"./chunk-CWD4O5PM.js";import{a as t}from"./chunk-EI7MMDWY.js";var n={target:{provider:"filesystem",capability:"read"},converter:r(),priority:100};async function i(o){await e(o,n)}t(i,"registerFilesystemImage");export{i as default};
package/dist/entry-27.js CHANGED
@@ -1,2 +1,2 @@
1
- import{e as P,f as x}from"./chunk-T7I2VX3J.js";import{a as T}from"./chunk-MGCHOGQD.js";import{a as E,b as h}from"./chunk-T6LX2RX5.js";import{a as S}from"./chunk-6CZO43OH.js";import{a as R,b as O}from"./chunk-OBNING2A.js";import{m as q}from"./chunk-ZPT5D4VP.js";import{c as j,d as v,e as y}from"./chunk-N34ATN52.js";import{a as o}from"./chunk-EI7MMDWY.js";import C from"cross-spawn";import{fileURLToPath as L}from"node:url";var b=5e3,J=10*1024*1024,k=L(new URL(".",new URL("../src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts",import.meta.url).href));function _(r){let e=r?.filter(i=>i==="jq"||i.startsWith("jq:"))??[];if(e.length===0)return;if(e.length>1)throw new Error("Read accepts only one jq view");if(r?.length!==1)throw new Error("The jq view cannot be combined with other views");let t=e[0];if(t===void 0||t==="jq"||t.slice(3).trim().length===0)throw new Error('The jq view requires a filter, for example views: ["jq:.scripts"]');return{filter:t.slice(3)}}o(_,"parseJqView");function A(r,e,t){return t.signal?.aborted===!0?Promise.reject(new Error("jq execution was cancelled")):new Promise((i,d)=>{let s=C(t.command??"jq",["-L",k,"--",r],{cwd:t.cwd,env:V(t.cwd),shell:!1,stdio:["pipe","pipe","pipe"],windowsHide:!0}),a="",l="",u=!1,m=0,c=o(n=>{u||(u=!0,clearTimeout(p),t.signal?.removeEventListener("abort",g),n===void 0?i(a):d(n))},"finish"),f=o(n=>{s.kill(),c(n)},"stop"),g=o(()=>f(new Error("jq execution was cancelled")),"abort"),p=setTimeout(()=>f(new Error(`jq did not finish within ${b/1e3} seconds`)),b);p.unref(),t.signal?.addEventListener("abort",g,{once:!0}),s.stdout?.setEncoding("utf8"),s.stderr?.setEncoding("utf8"),s.stdout?.on("data",n=>{if(m+=Buffer.byteLength(n),m>J){f(new Error(`jq output exceeded ${J/1024/1024}MB`));return}a+=n}),s.stderr?.on("data",n=>{Buffer.byteLength(l)<16384&&(l+=n)}),s.once("error",n=>c(new Error(`Cannot start jq: ${n.message}`))),s.once("close",(n,w)=>{if(!u)if(n===0)c();else{let I=l.trim().split(/\r?\n/u).slice(0,8).join(`
2
- `);c(new Error(I||`jq exited ${w===null?`with code ${String(n)}`:`after signal ${w}`}`))}}),s.stdin?.once("error",n=>c(new Error(`Cannot send JSON to jq: ${n.message}`))),s.stdin?.end(e)})}o(A,"executeJq");function V(r){let e=j(r,process.env),t={};for(let i of["PATH","PATHEXT","SystemRoot","SYSTEMROOT","WINDIR"])e[i]!==void 0&&(t[i]=e[i]);return t}o(V,"safeEnvironment");async function N(r){x(r,[await P({id:"json-reading",description:"Query and transform JSON resources with jq read views",triggers:[{tool:"read",viewPrefixes:["jq:"]}]})]),await Promise.all([S(r,B),T(r,$)])}o(N,"registerFilesystemJq");var B={protocol:R,apiVersion:O,id:"filesystem-jq",setup(r){r.addView({view:"jq",presenter:{id:"filesystem-jq",present:o(e=>e,"present")}}),r.addHandler({stage:"read",when:{resolvedBy:"filesystem",contentKind:"text"},async handler(e){let t=e.state;if(t?.contentKind!=="text")return{kind:"continue",context:e};let i;try{i=_(e.request.views)}catch(a){return D(t,a instanceof Error?a.message:String(a))}if(i===void 0)return{kind:"continue",context:e};let d;try{d=await A(i.filter,t.content[0].text,{cwd:e.resolverContext.cwd,...e.resolverContext.signal===void 0?{}:{signal:e.resolverContext.signal}})}catch(a){return D(t,a instanceof Error?a.message:String(a))}let s={...t,content:[{type:"text",text:d}],text:q(t.source,d),preserveTruncatedOutput:!0};return{kind:"continue",context:{...e,state:s}}}}),r.describe('JSON files accept views such as ["jq:.scripts | keys"] to query them with the installed jq executable.')}};function D(r,e){return{kind:"return",result:{content:[{type:"text",text:`jq failed: ${e}`}],details:{source:r.source,resolvedBy:r.resolvedBy,failure:{code:"READ_FAILED",source:r.source,resolverId:r.resolvedBy,pluginId:"filesystem-jq",stage:"read",message:e}},isError:!0}}}o(D,"jqFailure");var $={protocol:E,apiVersion:1,id:"filesystem-jq",setup(r){r.addSetupCheck({id:"jq",async inspect(e){return await v("jq",e.cwd,e.env)?{}:{actions:[{id:"jq-unavailable",message:"JSON jq views are unavailable because jq was not found"}]}}}),r.addCheck({id:"jq",title:"JSON jq views",async run(e){let t=await y("jq",["--version"],e.cwd,e.env);return[t.ok?{status:"pass",message:"jq is available",detail:t.detail}:{status:"fail",message:"jq is not available",detail:t.detail}]}})}};export{N as default};
1
+ import{e as x,f as P}from"./chunk-T7I2VX3J.js";import{a as T}from"./chunk-MGCHOGQD.js";import{a as E,b as h}from"./chunk-T6LX2RX5.js";import{a as b}from"./chunk-BU7IZLKB.js";import{a as R,b as O}from"./chunk-S5PL5DFQ.js";import{m as q}from"./chunk-ZPT5D4VP.js";import{c as j,d as y,e as v}from"./chunk-N34ATN52.js";import{a as o}from"./chunk-EI7MMDWY.js";import C from"cross-spawn";import{fileURLToPath as L}from"node:url";var S=5e3,J=10*1024*1024,k=L(new URL(".",new URL("../src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts",import.meta.url).href));function _(r){let e=r?.filter(i=>i==="jq"||i.startsWith("jq:"))??[];if(e.length===0)return;if(e.length>1)throw new Error("Read accepts only one jq view");if(r?.length!==1)throw new Error("The jq view cannot be combined with other views");let t=e[0];if(t===void 0||t==="jq"||t.slice(3).trim().length===0)throw new Error('The jq view requires a filter, for example views: ["jq:.scripts"]');return{filter:t.slice(3)}}o(_,"parseJqView");function A(r,e,t){return t.signal?.aborted===!0?Promise.reject(new Error("jq execution was cancelled")):new Promise((i,d)=>{let s=C(t.command??"jq",["-L",k,"--",r],{cwd:t.cwd,env:V(t.cwd),shell:!1,stdio:["pipe","pipe","pipe"],windowsHide:!0}),a="",c="",u=!1,m=0,l=o(n=>{u||(u=!0,clearTimeout(p),t.signal?.removeEventListener("abort",g),n===void 0?i(a):d(n))},"finish"),f=o(n=>{s.kill(),l(n)},"stop"),g=o(()=>f(new Error("jq execution was cancelled")),"abort"),p=setTimeout(()=>f(new Error(`jq did not finish within ${S/1e3} seconds`)),S);p.unref(),t.signal?.addEventListener("abort",g,{once:!0}),s.stdout?.setEncoding("utf8"),s.stderr?.setEncoding("utf8"),s.stdout?.on("data",n=>{if(m+=Buffer.byteLength(n),m>J){f(new Error(`jq output exceeded ${J/1024/1024}MB`));return}a+=n}),s.stderr?.on("data",n=>{Buffer.byteLength(c)<16384&&(c+=n)}),s.once("error",n=>l(new Error(`Cannot start jq: ${n.message}`))),s.once("close",(n,w)=>{if(!u)if(n===0)l();else{let I=c.trim().split(/\r?\n/u).slice(0,8).join(`
2
+ `);l(new Error(I||`jq exited ${w===null?`with code ${String(n)}`:`after signal ${w}`}`))}}),s.stdin?.once("error",n=>l(new Error(`Cannot send JSON to jq: ${n.message}`))),s.stdin?.end(e)})}o(A,"executeJq");function V(r){let e=j(r,process.env),t={};for(let i of["PATH","PATHEXT","SystemRoot","SYSTEMROOT","WINDIR"])e[i]!==void 0&&(t[i]=e[i]);return t}o(V,"safeEnvironment");async function N(r){P(r,[await x({id:"json-reading",description:"Query and transform JSON resources with jq read views",triggers:[{tool:"read",viewPrefixes:["jq:"]}]})]),await Promise.all([b(r,B),T(r,$)])}o(N,"registerFilesystemJq");var B={protocol:R,apiVersion:O,id:"filesystem-jq",setup(r){r.addView({view:"jq",presenter:{id:"filesystem-jq",present:o(e=>e,"present")}}),r.addHandler({stage:"read",when:{resolvedBy:"filesystem",contentKind:"text"},async handler(e){let t=e.state;if(t?.contentKind!=="text")return{kind:"continue",context:e};let i;try{i=_(e.request.views)}catch(a){return D(t,a instanceof Error?a.message:String(a))}if(i===void 0)return{kind:"continue",context:e};let d;try{d=await A(i.filter,t.content[0].text,{cwd:e.resolverContext.cwd,...e.resolverContext.signal===void 0?{}:{signal:e.resolverContext.signal}})}catch(a){return D(t,a instanceof Error?a.message:String(a))}let s={...t,content:[{type:"text",text:d}],text:q(t.source,d),preserveTruncatedOutput:!0};return{kind:"continue",context:{...e,state:s}}}}),r.describe({views:'jq:<filter> \u2014 query local JSON text with the installed jq executable, e.g. ["jq:.scripts | keys"]. Exactly one non-empty jq filter is required; it cannot be combined with other views. offset/limit apply to the transformed output, not original source lines.'})}};function D(r,e){return{kind:"return",result:{content:[{type:"text",text:`jq failed: ${e}`}],details:{source:r.source,resolvedBy:r.resolvedBy,failure:{code:"READ_FAILED",source:r.source,resolverId:r.resolvedBy,pluginId:"filesystem-jq",stage:"read",message:e}},isError:!0}}}o(D,"jqFailure");var $={protocol:E,apiVersion:1,id:"filesystem-jq",setup(r){r.addSetupCheck({id:"jq",async inspect(e){return await y("jq",e.cwd,e.env)?{}:{actions:[{id:"jq-unavailable",message:"JSON jq views are unavailable because jq was not found"}]}}}),r.addCheck({id:"jq",title:"JSON jq views",async run(e){let t=await v("jq",["--version"],e.cwd,e.env);return[t.ok?{status:"pass",message:"jq is available",detail:t.detail}:{status:"fail",message:"jq is not available",detail:t.detail}]}})}};export{N as default};
package/dist/entry-28.js CHANGED
@@ -1 +1 @@
1
- import{a as r}from"./chunk-BHSO2MDK.js";import{E as e}from"./chunk-SQKAXYIR.js";import{a as t}from"./chunk-EI7MMDWY.js";var n={target:{provider:"filesystem",capability:"read"},converter:r(),priority:200};async function i(o){await e(o,n)}t(i,"registerFilesystemPdf");export{i as default};
1
+ import{a as r}from"./chunk-BHSO2MDK.js";import{E as e}from"./chunk-CWD4O5PM.js";import{a as t}from"./chunk-EI7MMDWY.js";var n={target:{provider:"filesystem",capability:"read"},converter:r(),priority:200};async function i(o){await e(o,n)}t(i,"registerFilesystemPdf");export{i as default};
package/dist/entry-29.js CHANGED
@@ -1 +1 @@
1
- import{E as t}from"./chunk-SQKAXYIR.js";import{p as i}from"./chunk-ZPT5D4VP.js";import{a as r}from"./chunk-EI7MMDWY.js";var o=i(),n={target:{provider:"filesystem",capability:"read"},converter:o,priority:300},s={target:{provider:"filesystem",capability:"write"},converter:o,priority:300};async function a(e){await Promise.all([t(e,n),t(e,s)])}r(a,"registerFilesystemText");export{a as default};
1
+ import{E as t}from"./chunk-CWD4O5PM.js";import{p as i}from"./chunk-ZPT5D4VP.js";import{a as r}from"./chunk-EI7MMDWY.js";var o=i(),n={target:{provider:"filesystem",capability:"read"},converter:o,priority:300},s={target:{provider:"filesystem",capability:"write"},converter:o,priority:300};async function a(e){await Promise.all([t(e,n),t(e,s)])}r(a,"registerFilesystemText");export{a as default};