@buddysh/buddy 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/CHANGELOG.md +1633 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +1087 -0
  4. package/bin/cli.ts +3401 -0
  5. package/dist/bin/cli.d.ts +1 -0
  6. package/dist/bin/cli.js +188 -0
  7. package/dist/chunk-0j7z87kh.js +3 -0
  8. package/dist/chunk-0r8zt3d7.js +2 -0
  9. package/dist/chunk-16yqbccr.js +3 -0
  10. package/dist/chunk-1a53wj0h.js +1 -0
  11. package/dist/chunk-1c1gznm9.js +3 -0
  12. package/dist/chunk-1h3ey7k5.js +3 -0
  13. package/dist/chunk-1stt2whn.js +62 -0
  14. package/dist/chunk-1wjnd24b.js +24 -0
  15. package/dist/chunk-1xe07hzm.js +2 -0
  16. package/dist/chunk-2bp7tqca.js +2 -0
  17. package/dist/chunk-2dbkpfy9.js +2 -0
  18. package/dist/chunk-3q6czqs4.js +6 -0
  19. package/dist/chunk-3zdcekfj.js +5 -0
  20. package/dist/chunk-49ey79p0.js +5 -0
  21. package/dist/chunk-4c9m61yd.js +5 -0
  22. package/dist/chunk-4efbxdjr.js +4 -0
  23. package/dist/chunk-4f7panqj.js +21 -0
  24. package/dist/chunk-4hd3rre0.js +2 -0
  25. package/dist/chunk-4xsq18p3.js +9 -0
  26. package/dist/chunk-52x8mvh4.js +15 -0
  27. package/dist/chunk-54sc18p8.js +2 -0
  28. package/dist/chunk-56q4pwb5.js +3 -0
  29. package/dist/chunk-5c3qf34r.js +2 -0
  30. package/dist/chunk-5k40mwd4.js +4 -0
  31. package/dist/chunk-5kt03hx5.js +2 -0
  32. package/dist/chunk-63ept76v.js +2 -0
  33. package/dist/chunk-65b3vq52.js +2 -0
  34. package/dist/chunk-6d9hmjt8.js +3 -0
  35. package/dist/chunk-6g1y9yqh.js +3 -0
  36. package/dist/chunk-6k653r8w.js +2 -0
  37. package/dist/chunk-6md7qf2g.js +4 -0
  38. package/dist/chunk-6patq6bw.js +2 -0
  39. package/dist/chunk-6sgh49z1.js +2 -0
  40. package/dist/chunk-74pxb991.js +7 -0
  41. package/dist/chunk-7mgec8kb.js +7 -0
  42. package/dist/chunk-7tfrww3v.js +2 -0
  43. package/dist/chunk-7xk28xrv.js +2 -0
  44. package/dist/chunk-82dv4p13.js +2 -0
  45. package/dist/chunk-8661pvb8.js +3 -0
  46. package/dist/chunk-887s0w81.js +2 -0
  47. package/dist/chunk-8rc6042h.js +4 -0
  48. package/dist/chunk-9750tenz.js +3 -0
  49. package/dist/chunk-978wtejw.js +44 -0
  50. package/dist/chunk-9eqpaxfz.js +2 -0
  51. package/dist/chunk-9h04nskh.js +8 -0
  52. package/dist/chunk-9p1xkmjy.js +2 -0
  53. package/dist/chunk-agdesgzv.js +2 -0
  54. package/dist/chunk-akffynkc.js +3 -0
  55. package/dist/chunk-ar01x04a.js +2 -0
  56. package/dist/chunk-ay43f085.js +2 -0
  57. package/dist/chunk-bk9bqd5j.js +2 -0
  58. package/dist/chunk-bm8d40j0.js +69 -0
  59. package/dist/chunk-bxfc4g2x.js +73 -0
  60. package/dist/chunk-c3fczawt.js +2 -0
  61. package/dist/chunk-c9r9nd4t.js +1 -0
  62. package/dist/chunk-ctsz0ynx.js +3 -0
  63. package/dist/chunk-czremqk7.js +2 -0
  64. package/dist/chunk-da3wbh04.js +2 -0
  65. package/dist/chunk-dat582cg.js +2 -0
  66. package/dist/chunk-dfesffnr.js +3 -0
  67. package/dist/chunk-djntbp7a.js +105 -0
  68. package/dist/chunk-eagjp0dh.js +3 -0
  69. package/dist/chunk-eht72nnj.js +2 -0
  70. package/dist/chunk-f4nv5x3z.js +2 -0
  71. package/dist/chunk-fdfk918n.js +2 -0
  72. package/dist/chunk-fdj0tewy.js +20 -0
  73. package/dist/chunk-fm8ckj9b.js +2 -0
  74. package/dist/chunk-fqj7e6xa.js +2 -0
  75. package/dist/chunk-frm8zz31.js +2 -0
  76. package/dist/chunk-fvpr07dn.js +16 -0
  77. package/dist/chunk-g0nv8psv.js +2 -0
  78. package/dist/chunk-g0w8n555.js +19 -0
  79. package/dist/chunk-gkmvxjbe.js +2 -0
  80. package/dist/chunk-gngwjf70.js +7 -0
  81. package/dist/chunk-h7hs95wn.js +5 -0
  82. package/dist/chunk-hfvezfxh.js +3 -0
  83. package/dist/chunk-hw70wbzg.js +3 -0
  84. package/dist/chunk-j8asz4hb.js +15 -0
  85. package/dist/chunk-k62w2v03.js +2 -0
  86. package/dist/chunk-mcrfxphm.js +5 -0
  87. package/dist/chunk-mh3x7j6h.js +2 -0
  88. package/dist/chunk-naq32yx3.js +86 -0
  89. package/dist/chunk-nsmcjkas.js +2 -0
  90. package/dist/chunk-p1xm1jvz.js +2 -0
  91. package/dist/chunk-p3wsm8kz.js +2 -0
  92. package/dist/chunk-p4zwy518.js +4 -0
  93. package/dist/chunk-p7zgy37f.js +2 -0
  94. package/dist/chunk-ph1b3vbp.js +315 -0
  95. package/dist/chunk-pkjm2r0a.js +2 -0
  96. package/dist/chunk-pkkwb0n0.js +4 -0
  97. package/dist/chunk-pnpx1kqn.js +6 -0
  98. package/dist/chunk-q9n79dd3.js +3 -0
  99. package/dist/chunk-qpz9k66h.js +2 -0
  100. package/dist/chunk-qvn1rtgp.js +2 -0
  101. package/dist/chunk-qyf90zz3.js +2 -0
  102. package/dist/chunk-r06ce5g6.js +2 -0
  103. package/dist/chunk-r2sbprdb.js +49 -0
  104. package/dist/chunk-r3zyw8x0.js +3 -0
  105. package/dist/chunk-rb1fh9vd.js +1 -0
  106. package/dist/chunk-rqdep14r.js +2 -0
  107. package/dist/chunk-s1km8cyq.js +2 -0
  108. package/dist/chunk-s4ms8zag.js +2 -0
  109. package/dist/chunk-sp818c27.js +9 -0
  110. package/dist/chunk-tb5y0350.js +3 -0
  111. package/dist/chunk-thaxgm5p.js +2 -0
  112. package/dist/chunk-tn8prpny.js +503 -0
  113. package/dist/chunk-ts35hc5t.js +3 -0
  114. package/dist/chunk-tzs22es2.js +3 -0
  115. package/dist/chunk-vagxqhef.js +13 -0
  116. package/dist/chunk-vh504tcv.js +6 -0
  117. package/dist/chunk-vkctfqpm.js +3 -0
  118. package/dist/chunk-vyapg8ca.js +186 -0
  119. package/dist/chunk-wdwvt7gb.js +43 -0
  120. package/dist/chunk-wtjhehz9.js +4 -0
  121. package/dist/chunk-x0ya2r4r.js +3 -0
  122. package/dist/chunk-x3kragh9.js +12 -0
  123. package/dist/chunk-x9ctz1qc.js +1 -0
  124. package/dist/chunk-xakpdqaq.js +3 -0
  125. package/dist/chunk-xqx460y2.js +3 -0
  126. package/dist/chunk-xvptf9jy.js +3 -0
  127. package/dist/chunk-yk23nc4t.js +2 -0
  128. package/dist/chunk-yncea6ty.js +2 -0
  129. package/dist/chunk-yq0gxtzv.js +2 -0
  130. package/dist/chunk-yqhs08ky.js +2 -0
  131. package/dist/chunk-zb62jhwm.js +31 -0
  132. package/dist/chunk-zs3jaj0g.js +1023 -0
  133. package/dist/chunk-zve5d96e.js +2 -0
  134. package/dist/src/agent/index.d.ts +44 -0
  135. package/dist/src/agent/modes.d.ts +33 -0
  136. package/dist/src/agent/runner.d.ts +44 -0
  137. package/dist/src/agent/stacked.d.ts +83 -0
  138. package/dist/src/agent/tasks.d.ts +41 -0
  139. package/dist/src/agent/toolbelt.d.ts +19 -0
  140. package/dist/src/agent/tools/fs.d.ts +26 -0
  141. package/dist/src/agent/tools/shell.d.ts +32 -0
  142. package/dist/src/agent/types.d.ts +56 -0
  143. package/dist/src/ai/aliases.d.ts +62 -0
  144. package/dist/src/ai/client.d.ts +42 -0
  145. package/dist/src/ai/index.d.ts +35 -0
  146. package/dist/src/ai/learnings.d.ts +78 -0
  147. package/dist/src/ai/providers/anthropic.d.ts +12 -0
  148. package/dist/src/ai/providers/google.d.ts +12 -0
  149. package/dist/src/ai/providers/openai.d.ts +15 -0
  150. package/dist/src/ai/redact.d.ts +30 -0
  151. package/dist/src/ai/types.d.ts +75 -0
  152. package/dist/src/analysis/analyzers/actionlint.d.ts +11 -0
  153. package/dist/src/analysis/analyzers/external.d.ts +57 -0
  154. package/dist/src/analysis/analyzers/github-actions.d.ts +9 -0
  155. package/dist/src/analysis/analyzers/hadolint.d.ts +9 -0
  156. package/dist/src/analysis/analyzers/linter.d.ts +53 -0
  157. package/dist/src/analysis/analyzers/markdownlint.d.ts +11 -0
  158. package/dist/src/analysis/analyzers/secrets.d.ts +23 -0
  159. package/dist/src/analysis/analyzers/shellcheck.d.ts +8 -0
  160. package/dist/src/analysis/analyzers/syntax.d.ts +13 -0
  161. package/dist/src/analysis/engine.d.ts +38 -0
  162. package/dist/src/analysis/index.d.ts +13 -0
  163. package/dist/src/analysis/types.d.ts +14 -0
  164. package/dist/src/buddy.d.ts +17 -0
  165. package/dist/src/ci/classify.d.ts +49 -0
  166. package/dist/src/ci/fix.d.ts +42 -0
  167. package/dist/src/ci/index.d.ts +8 -0
  168. package/dist/src/commands/dispatcher.d.ts +49 -0
  169. package/dist/src/commands/handlers.d.ts +23 -0
  170. package/dist/src/commands/index.d.ts +22 -0
  171. package/dist/src/commands/parser.d.ts +71 -0
  172. package/dist/src/config-validation.d.ts +38 -0
  173. package/dist/src/config.d.ts +22 -0
  174. package/dist/src/dashboard/dashboard-generator.d.ts +10 -0
  175. package/dist/src/doctor.d.ts +44 -0
  176. package/dist/src/ecosystems/go.d.ts +10 -0
  177. package/dist/src/ecosystems/index.d.ts +60 -0
  178. package/dist/src/ecosystems/pep440.d.ts +57 -0
  179. package/dist/src/ecosystems/python.d.ts +12 -0
  180. package/dist/src/ecosystems/ruby.d.ts +9 -0
  181. package/dist/src/ecosystems/rust.d.ts +8 -0
  182. package/dist/src/ecosystems/scan.d.ts +49 -0
  183. package/dist/src/ecosystems/shared.d.ts +45 -0
  184. package/dist/src/ecosystems/types.d.ts +58 -0
  185. package/dist/src/events/bus.d.ts +41 -0
  186. package/dist/src/events/index.d.ts +11 -0
  187. package/dist/src/events/sinks.d.ts +33 -0
  188. package/dist/src/gates/ai-checks.d.ts +77 -0
  189. package/dist/src/gates/checks.d.ts +84 -0
  190. package/dist/src/gates/index.d.ts +17 -0
  191. package/dist/src/gates/post-merge.d.ts +56 -0
  192. package/dist/src/git/bitbucket-provider.d.ts +50 -0
  193. package/dist/src/git/github-provider.d.ts +50 -0
  194. package/dist/src/git/gitlab-provider.d.ts +51 -0
  195. package/dist/src/git/provider.d.ts +210 -0
  196. package/dist/src/headless/run.d.ts +78 -0
  197. package/dist/src/index.d.ts +243 -0
  198. package/dist/src/index.js +2 -0
  199. package/dist/src/issues/enrichment.d.ts +76 -0
  200. package/dist/src/issues/index.d.ts +16 -0
  201. package/dist/src/issues/quick-links.d.ts +55 -0
  202. package/dist/src/pr/auto-merge.d.ts +75 -0
  203. package/dist/src/pr/pr-generator.d.ts +9 -0
  204. package/dist/src/pr/pr-manifest.d.ts +82 -0
  205. package/dist/src/pr/templates.d.ts +44 -0
  206. package/dist/src/registry/docker-tags.d.ts +56 -0
  207. package/dist/src/registry/eol.d.ts +87 -0
  208. package/dist/src/registry/oci-client.d.ts +98 -0
  209. package/dist/src/registry/registry-client.d.ts +39 -0
  210. package/dist/src/reports/history.d.ts +51 -0
  211. package/dist/src/reports/index.d.ts +23 -0
  212. package/dist/src/reports/metrics.d.ts +89 -0
  213. package/dist/src/reports/render.d.ts +33 -0
  214. package/dist/src/review/diff.d.ts +50 -0
  215. package/dist/src/review/engine.d.ts +49 -0
  216. package/dist/src/review/findings.d.ts +102 -0
  217. package/dist/src/review/guidelines.d.ts +46 -0
  218. package/dist/src/review/index.d.ts +48 -0
  219. package/dist/src/review/local.d.ts +81 -0
  220. package/dist/src/review/marker.d.ts +34 -0
  221. package/dist/src/review/poster.d.ts +39 -0
  222. package/dist/src/review/run.d.ts +24 -0
  223. package/dist/src/rules/engine.d.ts +108 -0
  224. package/dist/src/rules/index.d.ts +9 -0
  225. package/dist/src/rules/renovate.d.ts +25 -0
  226. package/dist/src/rules/schedule.d.ts +44 -0
  227. package/dist/src/scanner/catalog-scan.d.ts +39 -0
  228. package/dist/src/scanner/package-json-extras.d.ts +101 -0
  229. package/dist/src/scanner/package-scanner.d.ts +17 -0
  230. package/dist/src/scanner/resolution-drift.d.ts +81 -0
  231. package/dist/src/scanner/workspace-catalog.d.ts +53 -0
  232. package/dist/src/scheduler/scheduler.d.ts +27 -0
  233. package/dist/src/security/engine.d.ts +12 -0
  234. package/dist/src/security/loader.d.ts +7 -0
  235. package/dist/src/security/parser.d.ts +15 -0
  236. package/dist/src/security/rules/bash-injection.d.ts +18 -0
  237. package/dist/src/security/rules/dangerous-pull-request-target.d.ts +18 -0
  238. package/dist/src/security/rules/excessive-permissions.d.ts +14 -0
  239. package/dist/src/security/rules/index.d.ts +16 -0
  240. package/dist/src/security/rules/missing-timeout.d.ts +9 -0
  241. package/dist/src/security/rules/self-hosted-exposure.d.ts +13 -0
  242. package/dist/src/security/rules/unpinned-action.d.ts +10 -0
  243. package/dist/src/security/rules/walk.d.ts +13 -0
  244. package/dist/src/security/types.d.ts +64 -0
  245. package/dist/src/services/deprecated-dependencies-checker.d.ts +16 -0
  246. package/dist/src/services/release-notes-fetcher.d.ts +70 -0
  247. package/dist/src/services/security-advisories.d.ts +59 -0
  248. package/dist/src/setup.d.ts +162 -0
  249. package/dist/src/setup.js +2 -0
  250. package/dist/src/templates/github-actions.d.ts +31 -0
  251. package/dist/src/templates/gitlab-ci.d.ts +46 -0
  252. package/dist/src/types.d.ts +449 -0
  253. package/dist/src/upgrades/index.d.ts +18 -0
  254. package/dist/src/upgrades/migrate.d.ts +45 -0
  255. package/dist/src/upgrades/plan.d.ts +112 -0
  256. package/dist/src/upgrades/report.d.ts +22 -0
  257. package/dist/src/upgrades/span.d.ts +47 -0
  258. package/dist/src/upgrades/usage.d.ts +30 -0
  259. package/dist/src/upgrades/wire.d.ts +61 -0
  260. package/dist/src/utils/concurrency.d.ts +50 -0
  261. package/dist/src/utils/dependency-file-parser.d.ts +17 -0
  262. package/dist/src/utils/dockerfile-parser.d.ts +69 -0
  263. package/dist/src/utils/endpoints.d.ts +58 -0
  264. package/dist/src/utils/errors.d.ts +35 -0
  265. package/dist/src/utils/file-changes.d.ts +14 -0
  266. package/dist/src/utils/github-actions-parser.d.ts +21 -0
  267. package/dist/src/utils/globs.d.ts +22 -0
  268. package/dist/src/utils/helpers.d.ts +73 -0
  269. package/dist/src/utils/http.d.ts +81 -0
  270. package/dist/src/utils/lock-file.d.ts +28 -0
  271. package/dist/src/utils/logger.d.ts +45 -0
  272. package/dist/src/utils/package-paths.d.ts +6 -0
  273. package/dist/src/utils/pantry-parser.d.ts +30 -0
  274. package/dist/src/utils/repository.d.ts +41 -0
  275. package/dist/src/utils/security-format.d.ts +18 -0
  276. package/dist/src/utils/zig-parser.d.ts +18 -0
  277. package/dist/src/version/version-resolver.d.ts +9 -0
  278. package/package.json +115 -0
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import{Hi as Z}from"./chunk-g0w8n555.js";import{Rj as Y}from"./chunk-akffynkc.js";import W from"process";var $=[["bun","test"],["npm","test","--silent"]];async function E(G,H){let I=H?[H]:await L(G);for(let z of I){let j=Bun.spawn(z,{cwd:G,stdout:"pipe",stderr:"pipe",env:{PATH:W.env.PATH??"",HOME:W.env.HOME??"",CI:"1"}}),[J,K,Q]=await Promise.all([new Response(j.stdout).text(),new Response(j.stderr).text(),j.exited]);return{ran:!0,passed:Q===0,output:`${J}
3
+ ${K}`.trim().slice(-4000)}}return{ran:!1,passed:!1,output:""}}async function L(G){let H=Bun.file(`${G}/package.json`);if(!await H.exists())return[];try{return(await H.json()).scripts?.test?$:[]}catch{return[]}}function O(G,H){return`${G.head}/buddy-${H}`}async function N(G){let H=G.logger??Y(),{provider:I,pullRequest:z,touch:j}=G;H.info(`\u2728 Running finishing touch '${j.name}' on PR #${z.number}`);let J=await Z(G.ai,{mode:j.mode,task:j.buildTask({summary:z.title,files:G.files??[]}),context:{workspace:G.workspace,baseBranch:z.base,branch:z.head},logger:H}),K=await _(G.workspace);if(K.length===0)return{mode:"none",changedFiles:[],verified:!1,comment:J.stopReason==="completed"?`**${j.description}** \u2014 nothing to change.`:`**${j.description}** \u2014 stopped before finishing (${J.stopReason}), and left nothing behind.`};let Q=J.stopReason==="completed",P=await E(G.workspace,G.testCommand);if(!(Q&&j.defaultOutput!=="suggestion"&&(P.passed||!P.ran)))return{mode:"suggestions",changedFiles:K,verified:P.passed,comment:X(j,K,P,J.stopReason)};let V=O(z,j.name);try{await I.createBranch(V,z.head),await I.commitChanges(V,`chore: ${j.description.toLowerCase()} for #${z.number}`,await x(G.workspace,K),z.head);let U=await I.createPullRequest({title:`${j.description} for #${z.number}`,body:y(j,z,K,P),head:V,base:z.head,labels:["buddy","finishing-touch"]});return{mode:"stacked-pr",pullRequest:U,changedFiles:K,verified:P.passed,comment:`**${j.description}** \u2014 opened [#${U.number}](${U.url}) targeting this branch.`+(P.ran?"":" No test script was found, so this is unverified.")}}catch(U){return H.warn(`\u26A0\uFE0F Could not open a stacked pull request: ${U}`),{mode:"suggestions",changedFiles:K,verified:P.passed,comment:X(j,K,P,J.stopReason)}}}async function _(G){let H=Bun.spawn(["git","status","--porcelain"],{cwd:G,stdout:"pipe",stderr:"ignore"}),[I,z]=await Promise.all([new Response(H.stdout).text(),H.exited]);if(z!==0)return[];let j=[];for(let J of I.split(`
4
+ `)){if(!J.trim())continue;let K=J.slice(0,2),Q=J.slice(3).trim();if(K.includes("D"))continue;j.push(Q.includes(" -> ")?Q.split(" -> ")[1]:Q)}return j}async function x(G,H){let I=[];for(let z of H){let j=Bun.file(`${G}/${z}`);if(await j.exists())I.push({path:z,content:await j.text(),type:"update"})}return I}function y(G,H,I,z){return[`${G.description}, requested on #${H.number}.`,"",`This targets \`${H.head}\` rather than \`${H.base}\`, so merging it`,"adds these changes to that pull request.","",z.ran?z.passed?"\u2705 The repository's tests pass with these changes.":"\u26A0\uFE0F The repository's tests do **not** pass with these changes.":"\u2139\uFE0F No test script was found, so these changes are unverified.","","### Files changed","",...I.map((j)=>`- \`${j}\``)].join(`
5
+ `)}function X(G,H,I,z){let j=[`**${G.description}**`,""];if(z&&z!=="completed")j.push(`The agent stopped before finishing (${z}), so what follows is`,"partial work rather than a complete change.","");if(I.ran&&!I.passed)j.push("The repository's tests do not pass with these changes, so no branch was","opened. Treat what follows as a starting point rather than a result.","");if(j.push("Files that would change:","",...H.map((J)=>`- \`${J}\``)),I.output)j.push("","<details><summary>Test output</summary>","","```",I.output,"```","","</details>");return j.join(`
6
+ `)}
7
+ export{$ as sa,E as ta,O as ua,N as va,_ as wa};
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import{Rj as V}from"./chunk-akffynkc.js";import{join as R}from"path";var K=/^catalog:(.*)$/;function N(X){let J;try{J=Bun.YAML.parse(X)}catch{return{entries:[],hasCatalogs:!1}}if(typeof J!=="object"||J===null)return{entries:[],hasCatalogs:!1};let B=J,z=[],$=!1,H=(M,j)=>{if(typeof M!=="object"||M===null||Array.isArray(M))return;$=!0;for(let[U,q]of Object.entries(M))if(typeof q==="string"&&q.trim())z.push({name:U,version:q.trim(),catalog:j})};if(H(B.catalog,"default"),typeof B.catalogs==="object"&&B.catalogs!==null)for(let[M,j]of Object.entries(B.catalogs))H(j,M);return{entries:z,hasCatalogs:$}}function k(X,J,B){let z=K.exec(X.trim());if(!z)return null;let $=z[1].trim()||"default";return J.find((H)=>H.name===B&&H.catalog===$)?.version??null}function w(X){return K.test(X.trim())}function S(X,J,B){let z=X.split(`
3
+ `),$=/^(\s*)(["']?)([^"':]+)\2(\s*:\s*)(["']?)(.+?)\5(\s*(?:#.*)?)$/,H=null,M=!1,j=0;for(let U=0;U<z.length;U++){let q=z[U],Y=q.length-q.trimStart().length,Z=q.trim();if(/^catalog\s*:\s*$/.test(Z)){H="default",M=!1;continue}if(/^catalogs\s*:\s*$/.test(Z)){M=!0,j=Y,H=null;continue}if(M&&Y>j&&/^[\w@./-]+\s*:\s*$/.test(Z)){H=Z.replace(/\s*:\s*$/,"");continue}if(M&&Z&&Y<=j)M=!1,H=null;if(H!==J.catalog)continue;let D=$.exec(q);if(!D||D[3].trim()!==J.name||D[6].trim()!==J.version)continue;let[,x,F,E,P,G,,Q]=D;return z[U]=`${x}${F}${E}${F}${P}${G}${B}${G}${Q}`,z.join(`
4
+ `)}return X}var W="pnpm-workspace.yaml",I="pnpm-workspace.yml";async function h(X,J,B={}){let z=B.logger??V(),$=new Set(B.ignore??[]);for(let H of[W,I]){let M=Bun.file(R(X,H));if(!await M.exists())continue;let{entries:j,hasCatalogs:U}=N(await M.text());if(!U)return{updates:[],entries:[],file:H};return z.debug(`\uD83D\uDCE6 ${H}: ${j.length} catalog entr(ies)`),{updates:(await Promise.all(j.map(async(Y)=>{if($.has(Y.name))return null;try{let Z=await J(Y.name);if(!Z)return null;let D=Y.version.replace(/^[\^~>=<\s]+/,"").trim();if(!D||D===Z)return null;return{name:Y.name,currentVersion:Y.version,newVersion:_(Y.version,Z),updateType:A(D,Z),dependencyType:"catalog",file:H,resolved:{catalog:Y.catalog}}}catch(Z){return z.debug(`Could not resolve catalog entry ${Y.name}: ${Z}`),null}}))).filter((Y)=>Y!==null),entries:j,file:H}}return{updates:[],entries:[]}}function _(X,J){return`${/^([\^~]|>=|<=|>|<)?/.exec(X.trim())?.[1]??""}${J}`}function A(X,J){let B=(H)=>H.split(".").map((M)=>Number.parseInt(M,10)||0),z=B(X),$=B(J);if((z[0]??0)!==($[0]??0))return"major";if((z[1]??0)!==($[1]??0))return"minor";return"patch"}function v(X,J){let B=X;for(let z of J){if(z.dependencyType!=="catalog")continue;B=S(B,{name:z.name,version:z.currentVersion,catalog:z.resolved?.catalog??"default"},z.newVersion)}return B}
5
+ export{N as Vb,k as Wb,w as Xb,S as Yb,W as Zb,I as _b,h as $b,v as ac};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import"./chunk-6g1y9yqh.js";var $={error:"\x1B[31m",warning:"\x1B[33m",info:"\x1B[34m"},R={error:"error",warning:"warn ",info:"info "};function a(i,g={}){let l=g.color??!0,r=(n,t)=>l?`${n}${t}\x1B[0m`:t;if(i.workflows.length===0)return r("\x1B[90m","buddy security: no workflows found under .github/workflows.");if(i.findings.length===0)return r("\x1B[32m",`buddy security: ${i.workflows.length} workflow${i.workflows.length===1?"":"s"} clean.`);let e=new Map;for(let n of i.findings){if(!e.has(n.file))e.set(n.file,[]);e.get(n.file).push(n)}let s=[];for(let[n,t]of e){s.push(r("\x1B[1m",n));for(let o of t){let u=r($[o.severity],R[o.severity]),w=o.line!==void 0?r("\x1B[90m",`:${o.line}`):"",E=r("\x1B[90m",`(${o.ruleId})`);if(s.push(` ${u}${w} ${o.message} ${E}`),o.detail)s.push(r("\x1B[2m",` ${o.detail}`));if(o.fix)s.push(r("\x1B[2m",` fix: ${o.fix}`))}s.push("")}let f=i.findings.filter((n)=>n.severity==="error").length,c=i.findings.filter((n)=>n.severity==="warning").length,d=`${f} error${f===1?"":"s"}, ${c} warning${c===1?"":"s"} across ${e.size} workflow${e.size===1?"":"s"}`;return s.push(r(i.failed?"\x1B[31m":"\x1B[33m",d)),s.join(`
3
+ `)}export{a as formatPretty};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{Dj as B,Ej as E}from"./chunk-5k40mwd4.js";import{Lj as z}from"./chunk-1h3ey7k5.js";import{Rj as A}from"./chunk-akffynkc.js";class H{logger;constructor(b){this.logger=b??A()}async checkDeprecatedDependencies(b){let j=[];for(let q of b){let w=await this.checkFileForDeprecatedDependencies(q);j.push(...w)}return j}async checkFileForDeprecatedDependencies(b){let j=[];for(let q of b.dependencies){let w=await this.checkDependencyDeprecation(q,b.type);if(w.deprecated)j.push({name:q.name,currentVersion:q.currentVersion,datasource:this.getDatasourceFromFileType(b.type),file:b.path,type:q.type,replacementAvailable:!1,deprecationMessage:w.message,suggestedReplacement:w.suggestedReplacement})}return j}async checkDependencyDeprecation(b,j){try{if(j==="package.json"||j.includes("lock"))return await this.checkNpmDeprecation(b);else if(j==="composer.json"||j==="composer.lock")return await this.checkComposerDeprecation(b);else if(j==="deps.yaml"||j==="deps.yml"||j.includes("deps"))return await this.checkBunDeprecation(b);return{deprecated:!1}}catch(q){return this.logger.warn(`Failed to check deprecation for ${b.name}:`,q),{deprecated:!1}}}async checkNpmDeprecation(b){try{let j=B(b.name),q=await z(`${j}/${encodeURIComponent(b.name).replace("%40","@")}`,{headers:{"User-Agent":"buddy"}});if(!q.ok)return{deprecated:!1};let w=await q.json();if(w.deprecated)return{deprecated:!0,message:w.deprecated,suggestedReplacement:this.extractSuggestedReplacement(w.deprecated)};let x=w.versions?.[b.currentVersion];if(x?.deprecated)return{deprecated:!0,message:x.deprecated,suggestedReplacement:this.extractSuggestedReplacement(x.deprecated)};return{deprecated:!1}}catch(j){return this.logger.warn(`Failed to check npm deprecation for ${b.name}:`,j),{deprecated:!1}}}async checkComposerDeprecation(b){try{let j=await z(`${E()}/packages/${b.name}.json`,{headers:{"User-Agent":"buddy"}});if(!j.ok)return{deprecated:!1};let q=await j.json();if(q.package?.abandoned){let w=typeof q.package.abandoned==="string"?q.package.abandoned:null;return{deprecated:!0,message:`Package is abandoned${w?`, use ${w} instead`:""}`,suggestedReplacement:w||void 0}}return{deprecated:!1}}catch(j){return this.logger.warn(`Failed to check Composer deprecation for ${b.name}:`,j),{deprecated:!1}}}async checkBunDeprecation(b){return await this.checkNpmDeprecation(b)}extractSuggestedReplacement(b){let j=[/use\s+([a-z0-9@/-]+)\s+instead/i,/replaced\s+by\s+([a-z0-9@/-]+)/i,/migrate\s+to\s+([a-z0-9@/-]+)/i,/switch\s+to\s+([a-z0-9@/-]+)/i];for(let q of j){let w=b.match(q);if(w)return w[1]}return}getDatasourceFromFileType(b){if(b==="package.json"||b.includes("lock"))return"npm";else if(b==="composer.json"||b==="composer.lock")return"composer";else if(b==="deps.yaml"||b==="deps.yml"||b.includes("deps"))return"bun";else if(b==="github-actions")return"github-actions";return"unknown"}}
3
+ export{H as bd};
@@ -0,0 +1,15 @@
1
+ // @bun
2
+ import{A as lQ,B as aQ,C as IQ,a as w,b as X,c as R,r as gQ,s as iQ,t as $Q,x as F,y as C,z as JQ}from"./chunk-r2sbprdb.js";import"./chunk-6g1y9yqh.js";import*as B from"fs/promises";import*as WQ from"fs";import*as y from"path";import*as BQ from"child_process";import*as z0 from"crypto";import*as q0 from"readline";function u(V){if(V.inputSchema.type!=="object")throw Error(`JSON schema for tool "${V.name}" must be an object, but got ${V.inputSchema.type}`);return{type:"custom",name:V.name,input_schema:V.inputSchema,description:V.description,run:V.run,parse:(Q)=>Q,...V.close?{close:V.close}:{}}}import*as x from"fs/promises";import*as A from"path";import{randomUUID as U0}from"crypto";var a=493,D0=420;function QQ(V,Q){let $=A.relative(V,Q);return $===""||!$.startsWith(".."+A.sep)&&$!==".."&&!A.isAbsolute($)}async function UQ(V,Q){for(let $ of V)if(QQ(await l(A.resolve($)),Q))return $;return}var G0=40;function o(V){let Q=V?.code;return typeof Q==="string"?Q:void 0}async function l(V){let Q=[],$=V,Z=0;for(;;){let z;try{z=await x.realpath($)}catch(q){let K;try{K=(await x.lstat($)).isSymbolicLink()}catch(Y){let H=o(Y);if(H!=="ENOENT"&&H!=="ENOTDIR")throw Y;let W=A.dirname($);if(W===$)throw Y;Q.push(A.basename($)),$=W;continue}if(!K)throw q;if(++Z>G0)throw Object.assign(Error("too many levels of symbolic links"),{code:"ELOOP"});$=A.resolve(A.dirname($),await x.readlink($));continue}return Q.length?A.join(z,...Q.reverse()):z}}async function OQ(V,Q,$){let Z=$?.allowedRoots??[],z=await l(A.resolve(V)),q;try{q=await l(A.resolve(z,Q))}catch(Y){throw new C(p(Y,`path ${JSON.stringify(Q)}`))}if(QQ(z,q)||await UQ(Z,q)!==void 0)return q;let K=Z.length?"the session's working directory and its other permitted directories":"the session's working directory";throw new C(`path ${JSON.stringify(Q)} is outside ${K}`)}async function DQ(V,Q){let $=A.dirname(V),Z=A.join($,`.tmp-${process.pid}-${U0()}`),z;try{z=await x.open(Z,"wx",D0),await z.writeFile(Q,"utf-8"),await z.sync(),await z.close(),z=void 0,await x.rename(Z,V)}catch(q){if(z)await z.close().catch(()=>{});throw await x.unlink(Z).catch(()=>{}),q}}function p(V,Q){let $=o(V);switch($){case"ENOENT":return`${Q}: no such file or directory`;case"EACCES":case"EPERM":return`${Q}: permission denied`;case"ENOTDIR":return`${Q}: not a directory`;case"EISDIR":return`${Q}: is a directory`;case"ELOOP":return`${Q}: too many levels of symbolic links`;case"ENAMETOOLONG":return`${Q}: file name too long`;case"ENOSPC":return`${Q}: no space left on device`;case"EMFILE":case"ENFILE":return`${Q}: too many open files`;default:return`${Q}: ${$!==void 0?`i/o error (${$})`:"i/o error"}`}}import*as I from"fs/promises";import*as yQ from"fs";import*as M from"path";import{execFile as N0}from"child_process";import{promisify as k0}from"util";import{Readable as L0}from"stream";import{pipeline as w0}from"stream/promises";var A0=k0(N0);async function M0(V){let{client:Q,sessionId:$}=V;if(!Q)return async()=>{};let Z=$Q(Q),z=V.session;if(!z){if($===void 0)return async()=>{};Z.warn("AgentToolContext.sessionId is deprecated and costs an extra session fetch; fetch the session once and set `session` instead",{component:"agent-tool-context"}),z=await Q.beta.sessions.retrieve($)}let q=M.resolve(V.workdir,"skills"),K=[];for(let Y of z.agent.skills)try{let H=await TQ(Q,Y.skill_id,Y.version),W=await Q.beta.skills.versions.retrieve(H,{skill_id:Y.skill_id}),J=M.basename(W.name.trim());if(J===""||J==="."||J==="..")J=Y.skill_id;let U=M.resolve(q,J);if(U!==q&&!U.startsWith(q+M.sep)){Z.warn("skill name escapes the skills dir; skipping",{component:"agent-tool-context",name:W.name});continue}let O=await Q.beta.skills.versions.download(H,{skill_id:Y.skill_id});await I.rm(U,{recursive:!0,force:!0}),await I.mkdir(U,{recursive:!0,mode:a}),K.push(U),await vQ(O,U),Z.info("downloaded skill",{component:"agent-tool-context",skill_id:Y.skill_id,version:H,dest:U})}catch(H){Z.warn("failed to download skill",{component:"agent-tool-context",skill_id:Y.skill_id,error:String(H)})}return async()=>{for(let Y of K)await I.rm(Y,{recursive:!0,force:!0}).catch((H)=>{Z.warn("failed to clean up skill",{component:"agent-tool-context",dest:Y,error:String(H)})})}}async function TQ(V,Q,$){if(/^\d+$/.test($))return $;let Z;for await(let z of V.beta.skills.versions.list(Q))if(/^\d+$/.test(z.version)&&(Z===void 0||BigInt(z.version)>BigInt(Z)))Z=z.version;if(Z===void 0)throw new R(`skill ${JSON.stringify(Q)} has no concrete version to resolve ${JSON.stringify($)} against`);return Z}function R0(V){for(let Q of V){let $=Q.trim();if(!$)continue;if(M.isAbsolute($)||$.split(/[\\/]/).includes(".."))throw new R(`refusing to extract unsafe archive member: ${$}`)}}var NQ="skill archive listing is inconsistent; refusing to extract",I0={unzip:new Set(["-","d","?"]),tar:new Set(["-","d","C"])};function jQ(V){let Q=V.split(`
3
+ `);if(Q[Q.length-1]==="")Q.pop();return Q}function B0(V,Q){return/^[\x20-\x7E]+$/.test(Q)&&!/[\\^#]/.test(Q)&&!(V==="unzip"&&Q.startsWith("-"))}function O0(V,Q,$){let Z=jQ(Q),z=jQ($);if(Z.length!==z.length)throw new R(NQ);let q=[],K=[];return Z.forEach((Y,H)=>{if(I0[V].has(z[H].charAt(0))){q.push(Y);return}if(!B0(V,Y))throw new R(`refusing to extract archive: cannot safely exclude member ${JSON.stringify(Y)}`);K.push(Y)}),{plain:q,special:K}}async function xQ(V){for(let Q of await I.readdir(V,{withFileTypes:!0}))if(Q.isDirectory())await xQ(M.join(V,Q.name));else if(!Q.isFile())throw new R(NQ)}async function GQ(V,Q){try{let{stdout:$}=await A0(V,Q);return $}catch($){if(o($)==="ENOENT")throw new R(`skill extraction requires the \`${V}\` command, but it was not found on PATH`);throw $}}function j0(V){let Q,$=!1;for(let Z of V){let z=Z.trim().split("/").filter((K)=>K!==""&&K!==".");if(z.length===0)continue;let q=z[0];if(Q===void 0)Q=q;else if(q!==Q)return"";if(z.length>1)$=!0}return Q!==void 0&&$?Q:""}async function vQ(V,Q){let $=M.join(Q,`.skill-archive-${process.pid}-${Date.now()}`);if(!V.body)throw new R("skill download response had no body");await w0(L0.fromWeb(V.body),yQ.createWriteStream($));let Z=M.join(M.dirname(Q),`.skill-stage-${process.pid}-${Date.now()}`),z=M.join(M.dirname(Q),`.skill-exclude-${process.pid}-${Date.now()}`);try{let q=await T0($,4),K=q.length>=4&&q[0]===80&&q[1]===75&&q[2]===3&&q[3]===4,Y=K?"unzip":"tar",H=await GQ(Y,K?["-Z1",$]:["-tf",$]),W=await GQ(Y,K?["-Z","--h","--t",$]:["-tvf",$]),{plain:J,special:U}=O0(Y,H,W);R0([...J,...U]);let O=j0(J);if(await I.mkdir(Z,{recursive:!0,mode:a}),J.length>0)await GQ(Y,await y0(Y,$,Z,U,z));await xQ(Z);let g=O?M.join(Z,O):Z,b=await I.readdir(g).catch((P)=>{throw o(P)==="ENOENT"?new R(NQ):P});for(let P of b)await I.rename(M.join(g,P),M.join(Q,P))}finally{await I.rm($,{force:!0}),await I.rm(z,{force:!0}),await I.rm(Z,{recursive:!0,force:!0})}}async function y0(V,Q,$,Z,z){let q=Z.map((K)=>K.replace(/[*?[\\]/g,"\\$&"));if(V==="unzip")return["-oq",Q,"-d",$,...q.length>0?["-x",...q]:[]];if(q.length===0)return["-xf",Q,"-C",$];return await I.writeFile(z,q.join(`
4
+ `)+`
5
+ `,{flag:"wx",mode:384}),["-xf",Q,"-C",$,"-X",z]}async function T0(V,Q){let $=await I.open(V,"r");try{let Z=Buffer.alloc(Q),{bytesRead:z}=await $.read(Z,0,Q,0);return Z.subarray(0,z)}finally{await $.close()}}import*as rQ from"path";import{createHash as h0}from"crypto";import*as N from"fs/promises";import*as L from"path";import{constants as d}from"fs";import{createHash as x0,randomBytes as v0}from"crypto";var EQ=448,b0=384,P0=448,kQ=d.O_NOFOLLOW??0,F0=d.O_NONBLOCK??0;class D extends Error{constructor(V,Q){super(`path ${JSON.stringify(Q)} ${V}`);this.name="FileStoreError",this.reason=V,this.relPath=Q}}D.ESCAPES_ROOT="escapes the store root";D.IS_A_SYMLINK="is a symlink";D.NOT_A_FILE="is not a regular file";D.NOT_A_DIRECTORY="is not a directory";D.NOT_UTF8="is not valid utf-8";D.MOVE_DESTINATION_EXISTS="already exists";function LQ(V){return V.startsWith("/")&&!V.split("/").includes("..")}class h{constructor(V,Q,$=!1){this.hashes=new Map,this.rootPath=V,this.removedOnDispose=Q,this.decoder=$?new TextDecoder("utf-8",{fatal:!0}):void 0}static async open(V,Q){if(!g0())throw Error("FileStore requires O_NOFOLLOW support on this platform");let $=!1;try{await N.lstat(V)}catch(Z){if(Z.code!=="ENOENT")throw Z;$=!0}return new h(L.resolve(V),$,Q?.utf8??!1)}async createRoot(){await E0(this.rootPath)}root(){return{path:this.rootPath,removedOnDispose:this.removedOnDispose}}async dispose(){if(!this.removedOnDispose)return;await N.rm(this.rootPath,{recursive:!0,force:!0})}async put(V,Q,$){let Z=V.replace(/\\/g,"/");if(Z.endsWith("/")||Z.endsWith("/.")||Z===""||Z===".")throw new D(D.NOT_A_FILE,V);let z=this.resolveUnderRoot(V),q=typeof Q==="string"?gQ(Q):Q;this.requireUtf8(V,q),await bQ(this.rootPath,L.dirname(z)),await f0(z,q,$?.executable??!1)}async get(V){let Q=this.resolveUnderRoot(V),$;try{$=await fQ(V,Q)}catch(z){if(z.code==="ENOENT")return null;throw z}let Z;try{let z=await $.readFile();Z=new Uint8Array(z.buffer,z.byteOffset,z.byteLength)}finally{await $.close()}return this.requireUtf8(V,Z),Z}async ls(V="/"){let Q=this.resolveUnderRoot(V);return new Set((await PQ(this.rootPath,V,Q)).map(([$])=>$))}async findSymlinks(V="/"){let Q=this.resolveUnderRoot(V);return m0(this.rootPath,V,Q)}async hashtree(V="/"){let Q=this.resolveUnderRoot(V),$=VQ.nowNs(),Z=Object.create(null);for(let[z,q]of await PQ(this.rootPath,V,Q)){let K=await this.hashViaCache(z,q,$);if(K!==null)Z[z]=K}return Z}async hashFile(V){let Q=this.resolveUnderRoot(V),$;try{$=await N.lstat(Q,{bigint:!0})}catch(z){if(z.code==="ENOENT")return null;throw z}if($.isSymbolicLink())throw new D(D.IS_A_SYMLINK,V);if(!$.isFile())throw new D(D.NOT_A_FILE,V);let Z=L.relative(this.rootPath,Q).split(L.sep).join("/");return this.hashViaCache(Z,Q,VQ.nowNs())}async move(V,Q){let $=this.resolveUnderRoot(V),Z=this.resolveUnderRoot(Q);if($===this.rootPath||Z===this.rootPath)return;if(await N.stat(Z).then(()=>!0,()=>!1))throw new D(D.MOVE_DESTINATION_EXISTS,Q);await bQ(this.rootPath,L.dirname(Z)),await N.rename($,Z)}async remove(V){let Q=this.resolveUnderRoot(V);if(Q===this.rootPath)return;let $;try{$=await N.lstat(Q,{bigint:!0})}catch(Z){if(Z.code==="ENOENT")return;throw Z}if($.isDirectory())await N.rm(Q,{recursive:!0,force:!0});else try{await N.unlink(Q)}catch(Z){if(Z.code!=="ENOENT")throw Z}}resolveUnderRoot(V){let Q=V.replace(/\\/g,"/").replace(/^\/+/,""),$=Q.split("/").filter((Z)=>Z!==""&&Z!==".");if(L.posix.isAbsolute(Q)||$.includes(".."))throw new D(D.ESCAPES_ROOT,V);return $.length===0?this.rootPath:L.join(this.rootPath,...$)}requireUtf8(V,Q){if(!this.decoder)return;try{this.decoder.decode(Q)}catch{throw new D(D.NOT_UTF8,V)}}async hashViaCache(V,Q,$){let Z;try{Z=await N.lstat(Q,{bigint:!0})}catch(K){if(K.code==="ENOENT")return null;throw K}if(!Z.isFile())return null;let z=this.hashes.get(V),q;if(z!==void 0&&S0(z,Z))q=z.sha;else try{q=await VQ.hashFile(Q)}catch(K){let Y=K.code;if(Y==="ENOENT"||K instanceof D)return null;if(Y==="ELOOP"||Y==="EMLINK")return null;throw K}if(p0(Z,$))this.hashes.set(V,{mtimeNs:Z.mtimeNs,ctimeNs:Z.ctimeNs,size:Z.size,sha:q});return q}}h.isPathLegal=LQ;function g0(){return kQ!==0}async function E0(V){let Q=[],$=V;for(;;){try{await N.stat($);break}catch(z){let q=z.code;if(q!=="ENOENT"&&q!=="ENOTDIR"&&q!=="ELOOP")throw z}Q.push($);let Z=L.dirname($);if(Z===$)break;$=Z}for(let Z of Q.reverse())try{await N.mkdir(Z,{mode:EQ})}catch(z){if(z.code!=="EEXIST")throw z}}async function bQ(V,Q){let $=L.relative(V,Q);if($==="")return;let Z=V;for(let z of $.split(L.sep)){Z=L.join(Z,z);try{await N.mkdir(Z,{mode:EQ})}catch(q){if(q.code!=="EEXIST")throw q}}}async function f0(V,Q,$){let Z=$?P0:b0,z=L.join(L.dirname(V),`.fs-${v0(8).toString("hex")}.tmp`),q;try{q=await N.open(z,d.O_WRONLY|d.O_CREAT|d.O_EXCL|kQ,Z),await q.writeFile(Q),await q.close(),q=void 0,await N.rename(z,V)}catch(K){if(q)await q.close().catch(()=>{});throw await N.unlink(z).catch(()=>{}),K}}async function fQ(V,Q){let $;try{$=await N.open(Q,d.O_RDONLY|kQ|F0)}catch(Z){let z=Z.code;if(z==="ELOOP"||z==="EMLINK")throw new D(D.IS_A_SYMLINK,V);throw Z}try{if(!(await $.stat()).isFile())throw new D(D.NOT_A_FILE,V)}catch(Z){throw await $.close().catch(()=>{}),Z}return $}async function u0(V){let Q=x0("sha256"),$=await fQ(L.basename(V),V),Z=new Uint8Array(1048576);try{for(;;){let{bytesRead:z}=await $.read(Z,0,Z.length);if(z===0)break;Q.update(Z.subarray(0,z))}}finally{await $.close()}return Q.digest("hex")}async function PQ(V,Q,$){if(!await _0(Q,$))return[];let Z=[];return await uQ($,(z,q)=>{if(q.isFile())Z.push([L.relative(V,z).split(L.sep).join("/"),z])}),Z.sort(),Z}async function m0(V,Q,$){let Z=(K)=>L.relative(V,K).split(L.sep).join("/"),z;try{z=await N.lstat($,{bigint:!0})}catch(K){let Y=K.code;if(Y==="ENOENT"||Y==="ENOTDIR")return new Set;throw K}if(z.isSymbolicLink())return new Set([Z($)]);if(!z.isDirectory())throw new D(D.NOT_A_DIRECTORY,Q);let q=new Set;return await uQ($,(K,Y)=>{if(Y.isSymbolicLink())q.add(Z(K))}),q}async function _0(V,Q){let $;try{$=await N.lstat(Q,{bigint:!0})}catch(Z){let z=Z.code;if(z==="ENOENT"||z==="ENOTDIR")return!1;throw Z}if(!$.isDirectory())throw new D(D.NOT_A_DIRECTORY,V);return!0}async function uQ(V,Q){let $=[V];while($.length){let Z=$.pop(),z;try{z=await N.readdir(Z,{withFileTypes:!0})}catch(q){if(q.code==="ENOENT")continue;throw q}for(let q of z){let K=L.join(Z,q.name);if(Q(K,q),q.isDirectory()&&!q.isSymbolicLink())$.push(K)}}}function S0(V,Q){return Q.mtimeNs===V.mtimeNs&&Q.ctimeNs===V.ctimeNs&&Q.size===V.size}function p0(V,Q){return(V.mtimeNs>V.ctimeNs?V.mtimeNs:V.ctimeNs)<Q-VQ.timestampTrustMarginNs}var d0=2000000000n,VQ={hashFile:u0,timestampTrustMarginNs:d0,nowNs:()=>BigInt(Date.now())*1000000n},mQ=h,FQ=Symbol.asyncDispose;if(FQ)Object.defineProperty(h.prototype,FQ,{value:h.prototype.dispose,configurable:!0,writable:!0});var k,f,XQ,s,YQ,G,c,qQ,E,oQ,KQ,sQ,tQ,wQ,MQ,_Q,SQ,AQ,pQ,dQ,ZQ,zQ,hQ,cQ,c0=30000,n=".anthropic-memory-store",eQ=1;function nQ(V){return h0("sha256").update(`version ${eQ}
6
+ ${V}`,"utf-8").digest("hex")}var n0=30000,i0=100,l0=20,a0=16,o0=32,s0=8,t0=50;class m extends R{constructor(V,Q){super(V);if(this.name="SessionMemoryError",Q!==void 0)this.cause=Q}}class Q0{constructor(V,Q,$){this.mode=V,this.cap=Q,this.waiveWindow=$,this.attempted=0,this.capped=0,this.suppressed=0}takeSlot(){if(this.attempted>=this.cap)return this.capped++,!1;return this.attempted++,!0}}class $0{constructor(V,Q){k.add(this),f.set(this,void 0),XQ.set(this,void 0),s.set(this,void 0),YQ.set(this,void 0),G.set(this,void 0),c.set(this,void 0),qQ.set(this,!1),E.set(this,[]),w(this,f,V,"f"),w(this,XQ,Q.workdir,"f"),w(this,s,Q.syncIntervalMs??JQ,"f"),aQ(X(this,s,"f"),"syncIntervalMs"),w(this,YQ,Q.syncDeletions??"enabled","f"),w(this,G,$Q(V),"f"),w(this,c,Date.now(),"f")}get roots(){return X(this,E,"f").map((V)=>V.files.root().path)}get readOnlyRoots(){return X(this,E,"f").filter((V)=>V.readOnly).map((V)=>V.files.root().path)}async download(V){for(let Q of V.resources){if(Q.type!=="memory_store")continue;let $=X(this,k,"m",oQ).call(this,Q),Z;try{if(Z={memoryStoreId:Q.memory_store_id,files:await mQ.open($,{utf8:!0}),readOnly:Q.access==="read_only",baseline:new Map,refusedShas:new Map,pendingDeletes:new Map},!Z.files.root().removedOnDispose)throw new m(`something already exists at the memory store's path: ${$} (memory_store_id=${Q.memory_store_id}); it must not exist when the session starts`);try{await Z.files.createRoot()}catch(z){if(!i(z))throw z;throw new m(`cannot create the memory store's folder: ${$} (memory_store_id=${Q.memory_store_id}): ${z}; the worker host must make this mount path writable`,z)}await X(this,k,"m",MQ).call(this,Z),X(this,G,"f").info("downloaded memories",{count:Z.baseline.size,memory_store_id:Z.memoryStoreId,dest:Z.files.root().path}),X(this,E,"f").push(Z)}catch(z){if(Z)await Z.files.dispose().catch(()=>{});if(z instanceof m)throw z;throw new m(`failed to download memory store memory_store_id=${Q.memory_store_id}: ${z}`,z)}}w(this,c,Date.now(),"f")}async finish(){if(X(this,qQ,"f"))throw new R("finish() was already called: it is the session's last sync and runs once");w(this,qQ,!0,"f"),await this.syncAll(!0)}async syncAll(V){await Promise.all(X(this,E,"f").map((Q)=>X(this,k,"m",sQ).call(this,Q,V))),w(this,c,Date.now(),"f")}async syncIfDue(){if(Date.now()-X(this,c,"f")<X(this,s,"f"))return;await this.syncAll(!1)}async flushWrites(V){await Promise.all(X(this,E,"f").map((Q)=>X(this,k,"m",tQ).call(this,Q,V)))}async dispose(){for(let V of X(this,E,"f")){let Q=V.files.root();try{let $=await X(this,k,"m",KQ).call(this,V);if(!$.markerOk&&Object.keys($.files).length>0){X(this,G,"f").warn(`${$.distrustReason}; leaving the memory store folder on disk`,{root:Q.path,memory_store_id:V.memoryStoreId});continue}await V.files.dispose()}catch($){if(!($ instanceof D)&&!i($))throw $;X(this,G,"f").warn("failed to remove the memory store folder",{root:V.files.root().path,memory_store_id:V.memoryStoreId,error:String($)});continue}if(Q.removedOnDispose)X(this,G,"f").info("removed memory store dir",{dest:Q.path,memory_store_id:V.memoryStoreId})}}}f=new WeakMap,XQ=new WeakMap,s=new WeakMap,YQ=new WeakMap,G=new WeakMap,c=new WeakMap,qQ=new WeakMap,E=new WeakMap,k=new WeakSet,oQ=function(Q){if(Q.mount_path){if(!LQ(Q.mount_path))throw new m(`memory store mount_path is not a clean absolute path: ${JSON.stringify(Q.mount_path)} (memory_store_id=${Q.memory_store_id})`);return Q.mount_path}return rQ.join(X(this,XQ,"f"),"memory",Q.name||Q.memory_store_id)},KQ=async function(Q){let $=await Q.files.hashtree(),Z=$[n];if(delete $[n],Z===nQ(Q.memoryStoreId))return{files:$,markerOk:!0,distrustReason:null};return{files:$,markerOk:!1,distrustReason:Z!==void 0?"the marker file does not match this store":"the marker file is gone"}},sQ=async function(Q,$){try{let Z=await X(this,k,"m",KQ).call(this,Q),z=Z.files;if(!Z.markerOk){if(Object.keys(z).length>0){X(this,G,"f").warn(`${Z.distrustReason}; leaving the memory store folder as found and not syncing`,{root:Q.files.root().path,memory_store_id:Q.memoryStoreId});return}await X(this,k,"m",wQ).call(this,Q,"the folder or its marker is gone");return}if(Object.keys(z).length===0&&Q.baseline.size>1){await X(this,k,"m",wQ).call(this,Q,"every memory file is gone at once");return}let q=new Map;for await(let[J,U]of X(this,k,"m",ZQ).call(this,Q.memoryStoreId))q.set(J,U);let K=new Q0(X(this,YQ,"f"),Math.max(s0,Math.min(t0,Math.floor(Q.baseline.size/4))),$),Y=[],H=new Map,W=[...new Set([...q.keys(),...Object.keys(z),...Q.baseline.keys()])].sort();for(let J of W){let U=q.get(J),O=z[J],g=Q.baseline.get(J),b;if(O===void 0&&g!==void 0&&U!==void 0&&U.content_sha256===g&&!Q.readOnly)b=await X(this,k,"m",hQ).call(this,Q,J,U,g,K);else b=await X(this,k,"m",_Q).call(this,Q,J,U,O,Y);if(b!==void 0)H.set(J,b)}if(Q.baseline=H,await X(this,k,"m",pQ).call(this,Q,Y),K.suppressed>0)X(this,G,"f").debug("remote deletes are disabled; locally deleted memories stay on the server",{count:K.suppressed,memory_store_id:Q.memoryStoreId});if(K.capped>0)X(this,G,"f").warn(`delete cap reached: ${K.mode==="log_only"?"would send":"sent"} ${K.attempted} deletes, held ${K.capped} for later syncs`,{memory_store_id:Q.memoryStoreId})}catch(Z){X(this,G,"f").warn("memory sync failed",{memory_store_id:Q.memoryStoreId,error:String(Z)})}},tQ=async function(Q,$){let Z=new Map,z=new Set,q=async()=>{if(Q.readOnly)return;let K=await X(this,k,"m",KQ).call(this,Q);if(!K.markerOk){X(this,G,"f").warn(`${K.distrustReason}; not uploading anything from the memory store folder`,{root:Q.files.root().path,memory_store_id:Q.memoryStoreId});return}for(let[W,J]of Object.entries(K.files))if(J!==Q.baseline.get(W)&&Q.refusedShas.get(W)!==J)Z.set(W,J),z.add(W);if(Z.size===0||$?.aborted)return;let Y=new Map;for await(let[W,J]of X(this,k,"m",ZQ).call(this,Q.memoryStoreId)){if($?.aborted)return;Y.set(W,J)}let H=[];for(let W of[...Z.keys()].sort()){let J=Z.get(W),U=Q.baseline.get(W),O=Y.get(W);if(O!==void 0&&O.content_sha256===J){Q.baseline.set(W,O.content_sha256),z.delete(W);continue}if(O!==void 0&&O.content_sha256!==U){X(this,G,"f").warn("memory changed both locally and remotely; the flush leaves the remote version",{path:W,memory_store_id:Q.memoryStoreId}),z.delete(W);continue}H.push([W,J,O])}await X(this,k,"m",dQ).call(this,Q,H,z,$)};try{if(await r0(q(),$),$?.aborted&&z.size>0)X(this,G,"f").warn(`memory flush cut off part-way; ${z.size} of ${Z.size} changed files had not finished uploading`,{memory_store_id:Q.memoryStoreId})}catch(K){X(this,G,"f").warn("memory flush failed",{memory_store_id:Q.memoryStoreId,error:String(K)})}},wQ=async function(Q,$){X(this,G,"f").warn(`${$}; re-downloading the memory store folder instead of syncing`,{root:Q.files.root().path,memory_store_id:Q.memoryStoreId}),await Q.files.createRoot(),await X(this,k,"m",MQ).call(this,Q)},MQ=async function(Q){Q.baseline=new Map,Q.pendingDeletes.clear(),await Q.files.put(n,`version ${eQ}
7
+ ${Q.memoryStoreId}`);for await(let[$,Z]of X(this,k,"m",ZQ).call(this,Q.memoryStoreId,"full"))if(await X(this,k,"m",AQ).call(this,Q,$,Z.content??""))Q.baseline.set($,Z.content_sha256)},_Q=async function(Q,$,Z,z,q){let K=Q.baseline.get($);if(z!==void 0)Q.pendingDeletes.delete($);if(!Z){if(z===void 0){Q.pendingDeletes.delete($);return}if(K!==void 0){if(z===K){let U=await X(this,k,"m",SQ).call(this,Q,$,K);if(U===void 0)return;if(U===K)return K;z=U}if(Q.readOnly)X(this,G,"f").warn("memory deleted remotely but edited locally; keeping the file, which a read-only store cannot push",{path:$,memory_store_id:Q.memoryStoreId});else if(Q.refusedShas.get($)!==z)X(this,G,"f").info("memory deleted remotely but edited locally; re-creating it from the file",{path:$,memory_store_id:Q.memoryStoreId})}if(Q.readOnly)return;if(Q.refusedShas.get($)===z)return;return await X(this,k,"m",zQ).call(this,Q,$,z,void 0)}let Y=Z.content_sha256,H=Y!==K,W=z!==void 0&&z!==K&&z!==Y,J=!Q.readOnly&&W;if(z===void 0&&K!==void 0){if(H)X(this,G,"f").warn("memory deleted locally but changed remotely; restoring the remote version",{path:$,memory_store_id:Q.memoryStoreId}),Q.pendingDeletes.delete($),q.push([$,Z]);return K}if(H){if(z===Y)return Y;if(W)X(this,G,"f").warn("memory changed both locally and remotely; keeping the remote version",{path:$,memory_store_id:Q.memoryStoreId});return q.push([$,Z]),K}if(J){if(Q.refusedShas.get($)===z)return Y;return await X(this,k,"m",zQ).call(this,Q,$,z,Z)??Y}return Y},SQ=async function(Q,$,Z){let z;try{z=await Q.files.hashFile($)}catch(q){if(!(q instanceof D)&&!i(q))throw q;return Z}if(z===null)return;if(z!==Z)return z;try{await Q.files.remove($)}catch(q){if(!(q instanceof D)&&!i(q))throw q;return X(this,G,"f").warn("failed to remove memory deleted remotely",{path:$,memory_store_id:Q.memoryStoreId,error:String(q)}),Z}return},AQ=async function(Q,$,Z){try{await Q.files.put($,Z)}catch(z){if(!(z instanceof D)&&!i(z))throw z;return X(this,G,"f").warn("failed to write memory",{path:$,memory_store_id:Q.memoryStoreId,error:String(z)}),!1}return!0},pQ=async function(Q,$){if($.length===0)return;let Z=async(K,Y)=>{let H;try{H=await X(this,f,"f").beta.memoryStores.memories.retrieve(Y.id,{memory_store_id:Q.memoryStoreId,view:"full"})}catch(W){if(F(W,404))return;X(this,G,"f").warn("failed to fetch memory content",{path:K,memory_store_id:Q.memoryStoreId,error:String(W)});return}if(await X(this,k,"m",AQ).call(this,Q,K,H.content??""))Q.baseline.set(K,H.content_sha256)},z=$[Symbol.iterator](),q=async()=>{for(let[K,Y]of z)await Z(K,Y)};await Promise.all(Array.from({length:Math.min(a0,$.length)},q))},dQ=async function(Q,$,Z,z){let q=$[Symbol.iterator](),K=async()=>{for(let[Y,H,W]of q){if(z?.aborted)return;let J=await X(this,k,"m",zQ).call(this,Q,Y,H,W);if(Z.delete(Y),J!==void 0)Q.baseline.set(Y,J)}};await Promise.all(Array.from({length:Math.min(o0,$.length)},K))},ZQ=async function*(Q,$="basic"){let Z=$==="basic"?i0:l0;for await(let z of X(this,f,"f").beta.memoryStores.memories.list(Q,{view:$,limit:Z})){if(z.type!=="memory")continue;let q=z.path.replace(/^\/+/,"");if(q===n){X(this,G,"f").warn("the server listed the reserved marker path; skipping",{path:z.path,memory_store_id:Q});continue}yield[q,z]}},zQ=async function V(Q,$,Z,z){try{let q=await Q.files.get($);if(q===null)return;let K=iQ(q),Y=z?await X(this,f,"f").beta.memoryStores.memories.update(z.id,{memory_store_id:Q.memoryStoreId,content:K,precondition:{type:"content_sha256",content_sha256:z.content_sha256}}):await X(this,f,"f").beta.memoryStores.memories.create(Q.memoryStoreId,{path:"/"+$,content:K});return Q.refusedShas.delete($),Y.content_sha256}catch(q){if(z&&F(q,404))return await X(this,k,"m",V).call(this,Q,$,Z,void 0);let K=q instanceof D||F(q,400)||F(q,413);if(z&&F(q,409))X(this,G,"f").warn("memory changed both locally and remotely; the upload was refused and the local edit loses",{path:$,memory_store_id:Q.memoryStoreId});else if(K&&Z!==void 0)Q.refusedShas.set($,Z),X(this,G,"f").warn("the server rejected this memory file, so it stays un-synced until its content changes",{path:$,memory_store_id:Q.memoryStoreId,rejection:String(q)});else X(this,G,"f").warn("failed to upload memory",{path:$,memory_store_id:Q.memoryStoreId,error:String(q)});return}},hQ=async function(Q,$,Z,z,q){if(q.mode==="disabled")return q.suppressed++,z;let K=Q.pendingDeletes.get($);if(K===void 0)K=Date.now(),Q.pendingDeletes.set($,K);if(!q.waiveWindow&&Date.now()-K<n0)return z;let Y,H;try{Y=await Q.files.hashFile(n)===nQ(Q.memoryStoreId),H=await Q.files.hashFile($)===null}catch(J){if(!(J instanceof D)&&!i(J))throw J;Y=H=!1}if(!Y)return z;if(!H)return Q.pendingDeletes.delete($),z;if(!q.takeSlot())return z;if(q.mode==="log_only")return X(this,G,"f").info("log-only: sync would delete this memory on the server",{path:$,memory_store_id:Q.memoryStoreId}),z;let W=await X(this,k,"m",cQ).call(this,Q,$,Z,z);if(W===void 0)Q.pendingDeletes.delete($);return W},cQ=async function(Q,$,Z,z){try{await X(this,f,"f").beta.memoryStores.memories.delete(Z.id,{memory_store_id:Q.memoryStoreId,expected_content_sha256:z})}catch(q){if(F(q,404))return;if(F(q,409)||F(q,412))X(this,G,"f").warn("memory deleted locally but changed remotely; keeping the remote version",{path:$,memory_store_id:Q.memoryStoreId});else X(this,G,"f").warn("failed to delete memory",{path:$,memory_store_id:Q.memoryStoreId,error:String(q)});return z}X(this,G,"f").info("propagated local deletion",{path:$,memory_store_id:Q.memoryStoreId});return};function i(V){return typeof V==="object"&&V!==null&&typeof V.code==="string"}async function r0(V,Q){if(!Q){await V;return}let $,Z=new Promise((z)=>{if($=z,Q.aborted)z()});Q.addEventListener("abort",$,{once:!0});try{await Promise.race([V,Z])}finally{Q.removeEventListener("abort",$)}}var HQ,j,T,t,_,v,RQ,V0=102400,K0=120000,e0=262144,r=102400,Q1=2000,$1=200;class X0 extends R{constructor(V){super(`bash command timed out after ${V}ms`);this.name="BashTimeoutError",this.timeoutMs=V}}var V1=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,Z1=B.glob;function Y0(V){return V===void 0?e0:V}function S(V){if(V===void 0)return;throw new R("The `unrestrictedPaths` option you passed to the agent toolset (AgentToolContext) is no longer supported. The toolset's file tools (read, write, edit, glob, grep) are now always confined to the working directory plus the directories listed in `allowedRoots`. Remove `unrestrictedPaths` from your context; to let the file tools reach any other directory, add it to `allowedRoots`.")}function $2(V){return[q1(V),K1(V),X1(V),Y1(V),H1(V),W1(V)]}async function e(V,Q){return S(V.unrestrictedPaths),OQ(V.workdir,Q,{allowedRoots:V.allowedRoots??[]})}function J0(V,Q){return UQ(V.readOnlyRoots??[],Q)}function z1(){let V={};for(let[Q,$]of Object.entries(process.env)){if(Q.startsWith("ANTHROPIC_"))continue;V[Q]=$}return V}class H0{constructor(V,Q=z1()){HQ.add(this),j.set(this,void 0),T.set(this,""),t.set(this,!1),_.set(this,!1),v.set(this,null),w(this,j,BQ.spawn("/bin/bash",["--noprofile","--norc"],{cwd:V,env:{...Q,PS1:"",PS2:"",TERM:"dumb"},stdio:["pipe","pipe","pipe"],detached:!0}),"f"),X(this,j,"f").stdout.setEncoding("utf8"),X(this,j,"f").stderr.setEncoding("utf8"),X(this,j,"f").stdout.on("data",($)=>X(this,HQ,"m",RQ).call(this,$)),X(this,j,"f").stderr.on("data",($)=>X(this,HQ,"m",RQ).call(this,$)),X(this,j,"f").once("close",()=>{w(this,_,!0,"f");let $=X(this,v,"f");w(this,v,null,"f"),$?.resolve()})}get closed(){return X(this,_,"f")}async exec(V,Q={}){if(X(this,_,"f"))throw new R("bash session terminated");let $=Q.timeoutMs??K0,Z=Q.signal;Z?.throwIfAborted(),w(this,T,"","f"),w(this,t,!1,"f");let z=`__ANT_CMD_${z0.randomUUID()}_DONE__`,q=`${z.slice(0,8)}''${z.slice(8)}`,K=`{ ${V}
8
+ } </dev/null 2>&1; printf '\\n${q}%d\\n' $?
9
+ `;if(X(this,j,"f").stdin.write(K),X(this,T,"f").indexOf(z)<0){let{promise:O,resolve:g}=IQ();w(this,v,{sentinel:z,resolve:g},"f");let b,P;try{await Promise.race([O,new Promise((C0,CQ)=>{b=setTimeout(()=>CQ(new X0($)),$)}),new Promise((C0,CQ)=>{if(!Z)return;P=()=>CQ(Z.reason),Z.addEventListener("abort",P,{once:!0})})])}finally{if(b)clearTimeout(b);if(P&&Z)Z.removeEventListener("abort",P);w(this,v,null,"f")}}let Y=X(this,T,"f").indexOf(z);if(Y<0)throw new R("bash session terminated");let W=X(this,T,"f").slice(Y+z.length).match(/^(-?\d+)/),J=W?parseInt(W[1],10):-1,U=X(this,T,"f").slice(0,Y).replace(V1,"").replace(/\n+$/,"");if(X(this,t,"f"))U=`[output truncated]
10
+ ${U}`;return{output:U,exitCode:J}}close(){if(X(this,_,"f"))return;w(this,_,!0,"f");let V=X(this,v,"f");w(this,v,null,"f"),V?.resolve(),X(this,j,"f").stdout.destroy(),X(this,j,"f").stderr.destroy(),X(this,j,"f").stdin.destroy();try{process.kill(-X(this,j,"f").pid,"SIGKILL")}catch{X(this,j,"f").kill("SIGKILL")}X(this,j,"f").unref()}}j=new WeakMap,T=new WeakMap,t=new WeakMap,_=new WeakMap,v=new WeakMap,HQ=new WeakSet,RQ=function(Q){if(w(this,T,X(this,T,"f")+Q,"f"),X(this,T,"f").length>V0)w(this,T,X(this,T,"f").slice(X(this,T,"f").length-V0),"f"),w(this,t,!0,"f");if(X(this,v,"f")&&X(this,T,"f").indexOf(X(this,v,"f").sentinel)>=0){let $=X(this,v,"f");w(this,v,null,"f"),$.resolve()}};function q1(V){S(V.unrestrictedPaths);let Q,$=Promise.resolve();return u({name:"bash",description:"Run a bash command in a persistent shell. State (cwd, env vars) persists across calls.",inputSchema:{type:"object",properties:{command:{type:"string",description:"The command to run"},restart:{type:"boolean",description:"Restart the persistent shell before running"},timeout_ms:{type:"integer",description:"Per-call timeout in milliseconds"}}},run:async({command:Z,restart:z,timeout_ms:q},K)=>{let Y=$,H=IQ();$=H.promise;try{await Y}catch{}try{if(z)Q?.close(),Q=void 0;if(!Z){if(z)return"bash session restarted";throw new C("bash: command is required")}Q??(Q=new H0(V.workdir,V.env));try{let{output:W,exitCode:J}=await Q.exec(Z,{timeoutMs:q??K0,signal:K?.signal});if(J!==0)throw new C(W||`exit ${J}`);return W}catch(W){if(W instanceof C)throw W;throw Q.close(),Q=void 0,new C(`bash: ${W instanceof Error?W.message:String(W)}`)}}finally{H.resolve()}},close:()=>{Q?.close(),Q=void 0}})}function K1(V){return S(V.unrestrictedPaths),u({name:"read",description:"Read a UTF-8 text file relative to the workdir.",inputSchema:{type:"object",properties:{file_path:{type:"string"},view_range:{type:"array",items:{type:"integer"},description:"[start_line, end_line] 1-indexed inclusive"}},required:["file_path"]},run:async({file_path:Q,view_range:$})=>{if(!Q)throw new C("read: file_path is required");let Z=await e(V,Q),z;try{let J=await B.stat(Z);if(!J.isFile())throw new C(`read: ${Q} is not a regular file`);let U=Y0(V.maxFileBytes);if(U!==null&&J.size>U)throw new C(`read: ${Q} is ${J.size} bytes, exceeds ${U}-byte limit. Use bash (head/tail/sed) to read a slice.`);z=await B.readFile(Z,"utf8")}catch(J){if(J instanceof C)throw J;throw new C(`read: ${p(J,Q)}`)}if(!$?.length)return z;if($.length!==2)throw new C("read: view_range must be [start_line, end_line]");let[q,K]=$,Y=z.split(`
11
+ `),H=Math.max(0,q-1),W=K>0?K:Y.length;return Y.slice(H,W).join(`
12
+ `)}})}function X1(V){return S(V.unrestrictedPaths),u({name:"write",description:"Write a UTF-8 text file relative to the workdir, creating parent directories as needed.",inputSchema:{type:"object",properties:{file_path:{type:"string"},content:{type:"string"}},required:["file_path","content"]},run:async({file_path:Q,content:$})=>{if(!Q)throw new C("write: file_path is required");let Z=await e(V,Q),z=await J0(V,Z);if(z!==void 0)throw new C(`write: ${Q} is inside read-only directory ${z}`);try{await B.mkdir(y.dirname(Z),{recursive:!0,mode:a}),await DQ(Z,$??"")}catch(q){throw new C(`write: ${p(q,Q)}`)}return`wrote ${Buffer.byteLength($??"")} bytes to ${Q}`}})}function Y1(V){return S(V.unrestrictedPaths),u({name:"edit",description:"Replace old_string with new_string in a file. old_string must be unique unless replace_all.",inputSchema:{type:"object",properties:{file_path:{type:"string"},old_string:{type:"string"},new_string:{type:"string"},replace_all:{type:"boolean"}},required:["file_path","old_string","new_string"]},run:async({file_path:Q,old_string:$,new_string:Z,replace_all:z})=>{if(!Q)throw new C("edit: file_path is required");if(!$)throw new C("edit: old_string is required");let q=await e(V,Q),K=await J0(V,q);if(K!==void 0)throw new C(`edit: ${Q} is inside read-only directory ${K}`);let Y;try{let J=await B.stat(q);if(!J.isFile())throw new C(`edit: ${Q} is not a regular file`);let U=Y0(V.maxFileBytes);if(U!==null&&J.size>U)throw new C(`edit: ${Q} is ${J.size} bytes, exceeds ${U}-byte limit. Use bash (sed/awk) to edit a large file.`);Y=await B.readFile(q,"utf8")}catch(J){if(J instanceof C)throw J;throw new C(`edit: ${p(J,Q)}`)}let H=Y.split($).length-1;if(H===0)throw new C(`edit: old_string not found in ${Q}`);let W;if(z)W=Y.split($).join(Z);else{if(H>1)throw new C(`edit: old_string appears ${H} times in ${Q} (must be unique)`);W=Y.replace($,()=>Z)}try{await DQ(q,W)}catch(J){throw new C(`edit: write: ${p(J,Q)}`)}return`edited ${Q} (${z?H:1} replacement(s))`}})}function J1(V){return V.split(/[\\/{},]/).includes("..")}function H1(V){return S(V.unrestrictedPaths),u({name:"glob",description:"Match files under the workdir against a glob pattern. Results are mtime-sorted, newest first.",inputSchema:{type:"object",properties:{pattern:{type:"string"},path:{type:"string",description:"Directory to search in. Defaults to the workdir."}},required:["pattern"]},run:async({pattern:Q,path:$})=>{if(!Q)throw new C("glob: pattern is required");if(y.isAbsolute(Q))throw new C("glob: absolute pattern not permitted; pass a relative pattern (and optionally path)");if(J1(Q))throw new C('glob: ".." is not permitted in the pattern');let Z=$?await e(V,$):y.resolve(V.workdir),z=$?Z:await l(Z),q=[],K=W0;try{for await(let Y of Z1(Q,{cwd:Z,withFileTypes:!0,exclude:(H)=>H.name===".git"||H.name==="node_modules"})){if(K--<=0)break;if(!Y.isFile())continue;let H=y.join(Y.parentPath,Y.name),W;try{W=await B.realpath(H)}catch{continue}if(!QQ(z,W))continue;let J=0;try{J=(await B.stat(H)).mtimeMs}catch{}q.push({path:H,mtime:J})}}catch(Y){throw new C(`glob: ${Y instanceof Error?Y.message:String(Y)}`)}if(q.length===0)return"no matches";return q.sort((Y,H)=>H.mtime-Y.mtime),q.slice(0,$1).map((Y)=>Y.path).join(`
13
+ `)}})}function W1(V){return S(V.unrestrictedPaths),u({name:"grep",description:"Search file contents for a regex. Uses ripgrep if available, otherwise a built-in walker.",inputSchema:{type:"object",properties:{pattern:{type:"string"},path:{type:"string"}},required:["pattern"]},run:async({pattern:Q,path:$},Z)=>{if(!Q)throw new C("grep: pattern is required");let z=y.resolve(V.workdir);if($)z=await e(V,$);let q=await N1();return q?C1(q,Q,z,Z?.signal):U1(Q,z,Z?.signal)}})}function C1(V,Q,$,Z){return new Promise((z,q)=>{let K=BQ.spawn(V,["-n","--no-heading","-e",Q,"--",$],{...Z?{signal:Z}:{}}),Y="",H="",W=!1;K.stdout.on("data",(J)=>{if(W)return;if(Y+=J,Y.length>r)W=!0,Y=Y.slice(0,r),K.kill("SIGKILL")}),K.stderr.on("data",(J)=>H+=J),K.on("close",(J)=>{if(Z?.aborted)return q(new C("grep: aborted"));if(W)return z(Y+`
14
+ [output truncated at ${r} bytes]`);if(J===0)return z(Y);if(J===1)return z("no matches");q(new C(`grep: rg failed: ${H||`exit ${J}`}`))}),K.on("error",(J)=>{if(Z?.aborted)return q(new C("grep: aborted"));q(new C(`grep: rg failed: ${J.message}`))})})}async function U1(V,Q,$){let Z;try{Z=new RegExp(V)}catch(H){throw new C(`grep: invalid regex: ${H instanceof Error?H.message:String(H)}`)}let z=[],q=r,K=(H)=>{if(q-=H.length+1,q<0)return z.push(`[output truncated at ${r} bytes]`),!1;return z.push(H),!0};if((await B.stat(Q).catch(()=>null))?.isFile())await Z0(Q,Z,K);else await G1(Q,"",(H)=>Z0(y.join(Q,H),Z,K),$);if($?.aborted)throw new C("grep: aborted");if(z.length===0)return"no matches";return z.join(`
15
+ `)}async function Z0(V,Q,$){let Z=WQ.createReadStream(V,{encoding:"utf8"}),z=q0.createInterface({input:Z,crlfDelay:1/0}),q=0;try{for await(let K of z){if(q++,K.length>Q1)continue;if(Q.test(K)&&!$(`${V}:${q}:${K}`))return!1}}catch{}finally{Z.destroy()}return!0}var D1=40,W0=50000;async function G1(V,Q,$,Z){let z=W0;async function q(K,Y){if(Y>D1)return!0;if(Z?.aborted)return!1;let H;try{H=await B.readdir(y.join(V,K),{withFileTypes:!0})}catch{return!0}for(let W of H){if(W.name===".git"||W.name==="node_modules")continue;if(z--<=0)return!1;if(Z?.aborted)return!1;let J=K?y.join(K,W.name):W.name;if(W.isDirectory()){if(!await q(J,Y+1))return!1}else if(W.isFile()){if(await $(J)===!1)return!1}}return!0}await q(Q,0)}async function N1(){let V=(process.env.PATH??"").split(y.delimiter);for(let Q of V){let $=y.join(Q,"rg");try{return await B.access($,WQ.constants.X_OK),$}catch{}}return null}export{M0 as setupSkills,TQ as resolveSkillVersion,e as resolvePath,vQ as extractSkillArchive,X1 as betaWriteTool,K1 as betaReadTool,W1 as betaGrepTool,H1 as betaGlobTool,Y1 as betaEditTool,q1 as betaBashTool,$2 as betaAgentToolset20260401,$0 as SessionMemoryStores,m as SessionMemoryError,lQ as MIN_MEMORY_SYNC_INTERVAL_MS,c0 as MEMORY_FLUSH_TIMEOUT_MS,n as MARKER_PATH,JQ as DEFAULT_MEMORY_SYNC_INTERVAL_MS,X0 as BashTimeoutError,H0 as BashSession};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{zj as a}from"./chunk-tn8prpny.js";import"./chunk-6g1y9yqh.js";export{a as GitHubActionsTemplate};
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import{Cd as _}from"./chunk-vagxqhef.js";import{Hd as C,Id as I}from"./chunk-ts35hc5t.js";import{ee as N}from"./chunk-16yqbccr.js";var x=["major","minor","patch","all"],M=["merge","squash","rebase"],T=["patch-only","minor-only","security-only","all"],O=["anthropic","openai","google","openrouter","openai-compatible"],m=["low","medium","high"],P=["chill","assertive"],R=["never","critical"],A=["low","moderate","high","critical"],S=["silent","error","warn","info","debug"],d=["npm","composer","github-actions","docker","pkgx","zig","python","rust","go","ruby"],b=["major","minor","patch"],L=_.map((J)=>J.name);function K(J){return JSON.stringify(J)}function H(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}function F(J,B,X,$){if(X===void 0)return;if(typeof X!=="string"||!$.includes(X))J.push({path:B,message:`expected one of ${$.map(K).join(", ")}, got ${K(X)}`})}function V(J,B,X,$={}){let Q=$.min??0,W=$.integer??!1;if(X===void 0)return;if(typeof X!=="number"||!Number.isFinite(X)||X<Q){J.push({path:B,message:`expected a number >= ${Q}, got ${K(X)}`});return}if(W&&!Number.isInteger(X))J.push({path:B,message:`expected a whole number, got ${K(X)}`})}function U(J,B,X,$){if(X===void 0)return;if(!Array.isArray(X)){J.push({path:B,message:`expected an array, got ${K(X)}`});return}X.forEach((Q,W)=>F(J,`${B}[${W}]`,Q,$))}function z(J,B,X){if(X===void 0)return;if(!Array.isArray(X)){J.push({path:B,message:`expected an array of strings, got ${K(X)}`});return}X.forEach(($,Q)=>{if(typeof $!=="string"||!$.trim())J.push({path:`${B}[${Q}]`,message:`expected a non-empty string, got ${K($)}`})})}function G(J,B,X){if(X===void 0)return;if(typeof X!=="string"){J.push({path:B,message:`expected a URL string, got ${K(X)}`});return}try{let $=new URL(X);if($.protocol!=="http:"&&$.protocol!=="https:")J.push({path:B,message:`expected an http(s) URL, got ${K(X)}`})}catch{J.push({path:B,message:`expected a valid absolute URL, got ${K(X)}`})}}function D(J,B,X){if(X===void 0)return;if(typeof X!=="string"||!X.trim()){J.push({path:B,message:`expected a cron expression string, got ${K(X)}`});return}let $=X.trim().split(/\s+/);if($.length!==5&&$.length!==6)J.push({path:B,message:`expected 5 or 6 whitespace-separated fields, got ${$.length} (${K(X)})`})}function w(J){let B=[];if(J.verbose!==void 0&&typeof J.verbose!=="boolean")B.push({path:"verbose",message:`expected a boolean, got ${K(J.verbose)}`});return F(B,"logLevel",J.logLevel,S),V(B,"maxPRsPerRun",J.maxPRsPerRun,{min:1,integer:!0}),p(B,J),f(B,J),v(B,J),g(B,J),n(B,J),c(B,J),l(B,J),t(B,J),k(B,J),q(B,J),B}function E(J,B){if(B===void 0)return;if(!H(B)){J.push({path:"registries.docker",message:`expected an object keyed by registry host, got ${K(B)}`});return}for(let[X,$]of Object.entries(B)){let Q=`registries.docker.${X}`;if(!H($)){J.push({path:Q,message:`expected an object, got ${K($)}`});continue}for(let W of["username","passwordEnv","tokenEnv"]){let Y=$[W];if(Y!==void 0&&(typeof Y!=="string"||!Y.trim()))J.push({path:`${Q}.${W}`,message:`expected a non-empty string, got ${K(Y)}`})}if($.username&&!$.passwordEnv&&!$.tokenEnv)J.push({path:`${Q}.passwordEnv`,message:"is required when a username is given"});if($.passwordEnv&&!$.username)J.push({path:`${Q}.username`,message:"is required when passwordEnv is given"})}}function q(J,B){let X=B.analysis;if(X===void 0)return;if(!H(X)){J.push({path:"analysis",message:`expected an object, got ${K(X)}`});return}if(X.enabled!==void 0&&typeof X.enabled!=="boolean")J.push({path:"analysis.enabled",message:`expected a boolean, got ${K(X.enabled)}`});if(X.tools===void 0)return;if(!H(X.tools)){J.push({path:"analysis.tools",message:`expected an object mapping analyzer names to booleans, got ${K(X.tools)}`});return}for(let[$,Q]of Object.entries(X.tools))if(typeof Q!=="boolean")J.push({path:`analysis.tools.${$}`,message:`expected a boolean, got ${K(Q)}`});else if(!L.includes($))J.push({path:`analysis.tools.${$}`,message:`unknown analyzer; expected one of ${L.map(K).join(", ")}`})}function p(J,B){let X=B.repository;if(X===void 0)return;if(!H(X)){J.push({path:"repository",message:`expected an object, got ${K(X)}`});return}if(X.provider!==void 0&&!C.includes(X.provider)){let $=I[String(X.provider)];J.push({path:"repository.provider",message:$?`${K(X.provider)} support is not implemented yet \u2014 follow ${$}`:`only ${C.map(K).join(", ")} is supported, got ${K(X.provider)}`})}for(let $ of["owner","name","baseBranch","token"]){let Q=X[$];if(Q!==void 0&&typeof Q!=="string")J.push({path:`repository.${$}`,message:`expected a string, got ${K(Q)}`})}G(J,"repository.apiUrl",X.apiUrl),G(J,"repository.serverUrl",X.serverUrl)}function f(J,B){let X=B.packages;if(X===void 0)return;if(!H(X)){J.push({path:"packages",message:`expected an object, got ${K(X)}`});return}F(J,"packages.strategy",X.strategy,x),z(J,"packages.ignore",X.ignore),z(J,"packages.ignorePaths",X.ignorePaths),z(J,"packages.minimumReleaseAgeExclude",X.minimumReleaseAgeExclude),V(J,"packages.minimumReleaseAge",X.minimumReleaseAge,{min:0});for(let $ of["includePrerelease","excludeMajor","respectLatest"]){let Q=X[$];if(Q!==void 0&&typeof Q!=="boolean")J.push({path:`packages.${$}`,message:`expected a boolean, got ${K(Q)}`})}if(X.pin!==void 0){if(!H(X.pin))J.push({path:"packages.pin",message:`expected an object mapping package names to versions, got ${K(X.pin)}`});else for(let[$,Q]of Object.entries(X.pin))if(typeof Q!=="string"||!Q.trim())J.push({path:`packages.pin.${$}`,message:`expected a version string, got ${K(Q)}`})}if(X.groups!==void 0){if(!Array.isArray(X.groups)){J.push({path:"packages.groups",message:`expected an array of groups, got ${K(X.groups)}`});return}X.groups.forEach(($,Q)=>{let W=`packages.groups[${Q}]`;if(!H($)){J.push({path:W,message:`expected an object, got ${K($)}`});return}if(typeof $.name!=="string"||!$.name.trim())J.push({path:`${W}.name`,message:`expected a non-empty string, got ${K($.name)}`});if(!Array.isArray($.patterns)||$.patterns.length===0)J.push({path:`${W}.patterns`,message:`expected a non-empty array of patterns, got ${K($.patterns)}`});else z(J,`${W}.patterns`,$.patterns);F(J,`${W}.strategy`,$.strategy,x)})}y(J,X.rules)}var j=["matchPackages","matchEcosystems","matchDepTypes","matchUpdateTypes","matchFiles","matchCurrentVersion","schedule"],h=["enabled","strategy","groupName","labels","reviewers","assignees","autoMerge","autoMigrate","minimumReleaseAge","prPriority","scheduleTimezone"];function y(J,B){if(B===void 0)return;if(!Array.isArray(B)){J.push({path:"packages.rules",message:`expected an array of rules, got ${K(B)}`});return}let X=new Set([...j,...h]);B.forEach(($,Q)=>{let W=`packages.rules[${Q}]`;if(!H($)){J.push({path:W,message:`expected an object, got ${K($)}`});return}for(let Z of Object.keys($))if(!X.has(Z))J.push({path:`${W}.${Z}`,message:`unknown key; expected one of ${[...X].map(K).join(", ")}`});if(!j.some((Z)=>$[Z]!==void 0))J.push({path:W,message:'has no matchers, so it applies to every update \u2014 add `matchPackages: ["*"]` if that is intended'});if(z(J,`${W}.matchPackages`,$.matchPackages),z(J,`${W}.matchDepTypes`,$.matchDepTypes),z(J,`${W}.matchFiles`,$.matchFiles),z(J,`${W}.labels`,$.labels),z(J,`${W}.reviewers`,$.reviewers),z(J,`${W}.assignees`,$.assignees),U(J,`${W}.matchEcosystems`,$.matchEcosystems,d),U(J,`${W}.matchUpdateTypes`,$.matchUpdateTypes,b),F(J,`${W}.strategy`,$.strategy,x),V(J,`${W}.minimumReleaseAge`,$.minimumReleaseAge,{min:0}),$.prPriority!==void 0&&typeof $.prPriority!=="number")J.push({path:`${W}.prPriority`,message:`expected a number, got ${K($.prPriority)}`});for(let Z of["enabled","autoMerge","autoMigrate"])if($[Z]!==void 0&&typeof $[Z]!=="boolean")J.push({path:`${W}.${Z}`,message:`expected a boolean, got ${K($[Z])}`});for(let Z of["groupName","matchCurrentVersion","scheduleTimezone"])if($[Z]!==void 0&&(typeof $[Z]!=="string"||!String($[Z]).trim()))J.push({path:`${W}.${Z}`,message:`expected a non-empty string, got ${K($[Z])}`});D(J,`${W}.schedule`,$.schedule)})}function v(J,B){let X=B.pullRequest;if(X===void 0)return;if(!H(X)){J.push({path:"pullRequest",message:`expected an object, got ${K(X)}`});return}z(J,"pullRequest.reviewers",X.reviewers),z(J,"pullRequest.assignees",X.assignees),z(J,"pullRequest.labels",X.labels);let $=X.autoMerge;if($!==void 0){if(!H($)){J.push({path:"pullRequest.autoMerge",message:`expected an object, got ${K($)}`});return}if($.enabled!==void 0&&typeof $.enabled!=="boolean")J.push({path:"pullRequest.autoMerge.enabled",message:`expected a boolean, got ${K($.enabled)}`});if(F(J,"pullRequest.autoMerge.strategy",$.strategy,M),z(J,"pullRequest.autoMerge.conditions",$.conditions),Array.isArray($.conditions))for(let[Q,W]of $.conditions.entries())F(J,`pullRequest.autoMerge.conditions[${Q}]`,W,T);if($.requireGreenCI!==void 0&&typeof $.requireGreenCI!=="boolean")J.push({path:"pullRequest.autoMerge.requireGreenCI",message:`expected a boolean, got ${K($.requireGreenCI)}`});if($.optOutLabel!==void 0&&typeof $.optOutLabel!=="string")J.push({path:"pullRequest.autoMerge.optOutLabel",message:`expected a string, got ${K($.optOutLabel)}`})}}function k(J,B){let X=B.ai;if(X===void 0)return;if(!H(X)){J.push({path:"ai",message:`expected an object, got ${K(X)}`});return}if(X.enabled!==void 0&&typeof X.enabled!=="boolean")J.push({path:"ai.enabled",message:`expected a boolean, got ${K(X.enabled)}`});F(J,"ai.provider",X.provider,O),F(J,"ai.effort",X.effort,m);for(let Q of["model","apiKeyEnv","baseUrl"])if(X[Q]!==void 0&&typeof X[Q]!=="string")J.push({path:`ai.${Q}`,message:`expected a string, got ${K(X[Q])}`});if(typeof X.apiKeyEnv==="string"&&/^sk-|^AIza/.test(X.apiKeyEnv))J.push({path:"ai.apiKeyEnv",message:"expected the NAME of an environment variable, not an API key"});let $=X.review;if($!==void 0)if(!H($))J.push({path:"ai.review",message:`expected an object, got ${K($)}`});else{for(let Q of["enabled","drafts","autoReview","summaryOnly"])if($[Q]!==void 0&&typeof $[Q]!=="boolean")J.push({path:`ai.review.${Q}`,message:`expected a boolean, got ${K($[Q])}`});if(F(J,"ai.review.profile",$.profile,P),F(J,"ai.review.requestChangesOn",$.requestChangesOn,R),z(J,"ai.review.ignoreTitleKeywords",$.ignoreTitleKeywords),z(J,"ai.review.ignoreUsernames",$.ignoreUsernames),z(J,"ai.review.pathFilters",$.pathFilters),$.instructions!==void 0&&typeof $.instructions!=="string")J.push({path:"ai.review.instructions",message:`expected a string, got ${K($.instructions)}`});if($.guidelineFiles!==void 0&&$.guidelineFiles!==!1)z(J,"ai.review.guidelineFiles",$.guidelineFiles);if($.pathInstructions!==void 0)if(!Array.isArray($.pathInstructions))J.push({path:"ai.review.pathInstructions",message:`expected an array, got ${K($.pathInstructions)}`});else $.pathInstructions.forEach((Q,W)=>{let Y=`ai.review.pathInstructions[${W}]`;if(!H(Q)){J.push({path:Y,message:`expected an object, got ${K(Q)}`});return}for(let Z of["path","instructions"])if(typeof Q[Z]!=="string"||!Q[Z].trim())J.push({path:`${Y}.${Z}`,message:`expected a non-empty string, got ${K(Q[Z])}`})})}if(X.maxTokensPerRun!==void 0){if(typeof X.maxTokensPerRun!=="number"||!Number.isFinite(X.maxTokensPerRun)||X.maxTokensPerRun<=0)J.push({path:"ai.maxTokensPerRun",message:`expected a positive number, got ${K(X.maxTokensPerRun)}`})}}function g(J,B){let X=B.registries;if(X===void 0)return;if(!H(X)){J.push({path:"registries",message:`expected an object, got ${K(X)}`});return}if(E(J,X.docker),G(J,"registries.npm",X.npm),G(J,"registries.composer",X.composer),X.npmScopes!==void 0){if(!H(X.npmScopes)){J.push({path:"registries.npmScopes",message:`expected an object keyed by scope, got ${K(X.npmScopes)}`});return}for(let[$,Q]of Object.entries(X.npmScopes)){if(!$.startsWith("@"))J.push({path:`registries.npmScopes.${$}`,message:`scope keys must start with "@", got ${K($)}`});G(J,`registries.npmScopes.${$}`,Q)}}}function n(J,B){let X=B.security;if(X===void 0)return;if(!H(X)){J.push({path:"security",message:`expected an object, got ${K(X)}`});return}for(let $ of["enabled","prioritize"]){let Q=X[$];if(Q!==void 0&&typeof Q!=="boolean")J.push({path:`security.${$}`,message:`expected a boolean, got ${K(Q)}`})}if(X.label!==void 0&&(typeof X.label!=="string"||!X.label.trim()))J.push({path:"security.label",message:`expected a non-empty string, got ${K(X.label)}`});F(J,"security.minimumSeverity",X.minimumSeverity,A)}function c(J,B){if(B.schedule!==void 0){if(!H(B.schedule))J.push({path:"schedule",message:`expected an object, got ${K(B.schedule)}`});else if(D(J,"schedule.cron",B.schedule.cron),B.schedule.timezone!==void 0&&typeof B.schedule.timezone!=="string")J.push({path:"schedule.timezone",message:`expected a string, got ${K(B.schedule.timezone)}`})}let X=B.workflows?.custom;if(X===void 0)return;if(!Array.isArray(X)){J.push({path:"workflows.custom",message:`expected an array, got ${K(X)}`});return}X.forEach(($,Q)=>{let W=`workflows.custom[${Q}]`;if(!H($)){J.push({path:W,message:`expected an object, got ${K($)}`});return}if(typeof $.name!=="string"||!$.name.trim())J.push({path:`${W}.name`,message:`expected a non-empty string, got ${K($.name)}`});D(J,`${W}.schedule`,$.schedule),F(J,`${W}.strategy`,$.strategy,x),z(J,`${W}.reviewers`,$.reviewers),z(J,`${W}.assignees`,$.assignees),z(J,`${W}.labels`,$.labels)})}function l(J,B){let X=B.releaseNotes;if(X===void 0)return;if(!H(X)){J.push({path:"releaseNotes",message:`expected an object, got ${K(X)}`});return}for(let $ of["enabled","sanitizeReferences","includeCompareLinks"]){let Q=X[$];if(Q!==void 0&&typeof Q!=="boolean")J.push({path:`releaseNotes.${$}`,message:`expected a boolean, got ${K(Q)}`})}V(J,"releaseNotes.maxReleases",X.maxReleases,{min:1,integer:!0}),V(J,"releaseNotes.maxBodyLength",X.maxBodyLength,{min:1,integer:!0})}function t(J,B){let X=B.dashboard;if(X===void 0)return;if(!H(X)){J.push({path:"dashboard",message:`expected an object, got ${K(X)}`});return}if(z(J,"dashboard.labels",X.labels),z(J,"dashboard.assignees",X.assignees),V(J,"dashboard.issueNumber",X.issueNumber,{min:1,integer:!0}),X.title!==void 0&&(typeof X.title!=="string"||!X.title.trim()))J.push({path:"dashboard.title",message:`expected a non-empty string, got ${K(X.title)}`})}function o(J){return J.map((B)=>` \u2022 ${B.path}: ${B.message}`).join(`
3
+ `)}function u(J){let B=w(J);if(B.length===0)return;throw new N(`Invalid buddy configuration (${B.length} issue${B.length===1?"":"s"}):
4
+ ${o(B)}`,B[0].path)}
5
+ export{w as Fc,o as Gc,u as Hc};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{sb as a,tb as b,ub as c}from"./chunk-4xsq18p3.js";import"./chunk-6g1y9yqh.js";export{b as renderDiffForReview,a as parseUnifiedDiff,c as collectGitDiff};
@@ -0,0 +1,86 @@
1
+ // @bun
2
+ import{pi as M}from"./chunk-bxfc4g2x.js";import{Hi as N}from"./chunk-g0w8n555.js";import{Xi as v}from"./chunk-7mgec8kb.js";import{Rj as I}from"./chunk-akffynkc.js";var R={type:"object",properties:{changes:{type:"array",items:{type:"object",properties:{description:{type:"string",description:"What upstream changed"},version:{type:"string",description:"Version the change landed in"},affectedFiles:{type:"array",items:{type:"string"}},action:{type:"string",description:"What must be done in this repository"},automatable:{type:"boolean",description:"Whether the fix is mechanical"}},required:["description","affectedFiles","action","automatable"],additionalProperties:!1}},codemod:{type:"object",properties:{command:{type:"string",description:"Command that applies the official codemod"},source:{type:"string",description:"Where the codemod is documented"}},required:["command","source"],additionalProperties:!1},confidence:{type:"string",enum:["high","medium","low"]},effort:{type:"integer",description:"1 (trivial) to 5 (demanding)"},risks:{type:"array",items:{type:"string"}}},required:["changes","confidence","effort","risks"],additionalProperties:!1},k=[/^(?:bunx|npx|pnpm dlx|yarn dlx)\s+[\w@/.-]+(?:\s+[\w@/.:=-]+)*$/];function f(J){let Y=J.trim();if(/[;&|`$><\n]/.test(Y))return!1;return k.some((Q)=>Q.test(Y))}function T(J){let Y=J.usage.slice(0,100).map((Q)=>`${Q.path}:${Q.line} (${Q.kind}) ${Q.text}`).join(`
3
+ `);return[`Analyse upgrading \`${J.packageName}\` from ${J.fromVersion} to ${J.toVersion}.`,"","Report only breaking changes that affect THIS repository, judged against the","usage sites below. A breaking change in a feature this repository does not use","is not worth reporting, and listing it makes the real ones harder to find.","","Mark a change automatable only when the fix is a mechanical edit you could write","exactly. Anything needing judgement is not automatable.","","If the package publishes an official codemod for this upgrade, report the command.","","Set confidence honestly: high when every change is understood and mechanical,","low when the notes are unclear or the change touches something subtle. A low","confidence plan is more useful than a wrong high confidence one.","","--- Release notes across the version span ---",J.releaseNotes||"(none available)","",`--- Usage in this repository (${J.usage.length} site(s)) ---`,Y||"(no direct usage found)"].join(`
4
+ `)}function C(J,Y){let Q=J??{},Z=new Set(Y.knownFiles),K=(Array.isArray(Q.changes)?Q.changes:[]).filter(($)=>Boolean($&&typeof $.description==="string"&&typeof $.action==="string")).map(($)=>({description:$.description,...$.version?{version:$.version}:{},affectedFiles:(Array.isArray($.affectedFiles)?$.affectedFiles:[]).filter((W)=>Z.has(W)),action:$.action,automatable:$.automatable===!0})),H=Q.codemod&&f(Q.codemod.command)?Q.codemod:void 0;return{packageName:Y.packageName,fromVersion:Y.fromVersion,toVersion:Y.toVersion,changes:K,...H?{codemod:H}:{},confidence:b(Q.confidence,K),effort:y(Q.effort),risks:(Array.isArray(Q.risks)?Q.risks:[]).filter(($)=>typeof $==="string")}}function A(J,Y="high"){let Q={low:0,medium:1,high:2};return Q[J.confidence]<Q[Y]}function b(J,Y){let Q=J==="high"||J==="medium"||J==="low"?J:"low";if(Q==="high"&&Y.some((Z)=>!Z.automatable))return"medium";return Q}function y(J){let Y=Number(J);if(!Number.isFinite(Y))return 3;return Math.min(5,Math.max(1,Math.round(Y)))}import{resolve as h}from"path";var m=/\.(?:[cm]?[jt]sx?|vue|svelte)$/,g=/(?:^|\/)(?:[\w.-]*\.config\.[cm]?[jt]s|\.?[\w-]*rc(?:\.\w+)?|tsconfig\.json|vite\.config\.[cm]?[jt]s)$/;async function E(J,Y,Q){let Z=J.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),K=`${Z}(?:/[^'"\`]*)?`,H=new RegExp(`(?:^|\\s)import\\s[^'"\`]*['"\`]${K}['"\`]|from\\s*['"\`]${K}['"\`]`),$=new RegExp(`require\\s*\\(\\s*['"\`]${K}['"\`]\\s*\\)`),W=new RegExp(`import\\s*\\(\\s*['"\`]${K}['"\`]\\s*\\)`),j=new RegExp(`(?:^|[^\\w@/.-])${Z}(?![\\w/.-])`),z=[];for(let X of Y){let B=m.test(X),O=g.test(X);if(!B&&!O)continue;let D;try{let _=Bun.file(h(Q,X));if(!await _.exists())continue;D=await _.text()}catch{continue}if(!D.includes(J))continue;for(let[_,U]of D.split(`
5
+ `).entries()){let P=null;if(H.test(U)||W.test(U))P="import";else if($.test(U))P="require";else if(O&&j.test(U))P="config";if(P)z.push({path:X,line:_+1,text:U.trim().slice(0,200),kind:P})}}return z}function x(J){let Y=new Map;for(let Q of J)Y.set(Q.path,(Y.get(Q.path)??0)+1);return[...Y.entries()].map(([Q,Z])=>({path:Q,count:Z})).sort((Q,Z)=>Z.count-Q.count)}var u={high:"\uD83D\uDFE2 high",medium:"\uD83D\uDFE1 medium",low:"\uD83D\uDD34 low"};function G(J,Y,Q=[]){let Z=`## \uD83D\uDD27 Migration report
6
+
7
+ `;if(Z+=`Upgrading \`${J.packageName}\` from \`${J.fromVersion}\` to \`${J.toVersion}\`.
8
+
9
+ `,Z+=`**Confidence:** ${u[J.confidence]} \xB7 **Effort:** ${"\u25CF".repeat(J.effort)}${"\u25CB".repeat(5-J.effort)} (${J.effort}/5)
10
+
11
+ `,J.changes.length===0)Z+=`No breaking changes in this span affect how this repository uses the package.
12
+
13
+ `;else{Z+=`### Breaking changes affecting this repository
14
+
15
+ `;for(let H of J.changes){let $=H.version?` _(${H.version})_`:"",W=H.automatable?"\uD83D\uDD27":"\u270B";if(Z+=`- ${W} **${F(H.description)}**${$}
16
+ `,Z+=` - ${F(H.action)}
17
+ `,H.affectedFiles.length>0)Z+=` - Affects: ${H.affectedFiles.map((j)=>`\`${j}\``).join(", ")}
18
+ `}Z+=`
19
+ \uD83D\uDD27 applied automatically \xB7 \u270B needs a person
20
+
21
+ `}if(J.codemod)Z+=`### Codemod
22
+
23
+ Ran \`${F(J.codemod.command)}\` (${F(J.codemod.source)}).
24
+
25
+ `;if(Y){if(Z+=`### What was done
26
+
27
+ `,!Y.applied)Z+=`No code changes were made \u2014 this is analysis only.
28
+
29
+ `;else if(Z+=`Changed ${Y.changedFiles.length} file(s):
30
+
31
+ `,Z+=`${Y.changedFiles.map((H)=>`- \`${H}\``).join(`
32
+ `)}
33
+
34
+ `,Z+=Y.verified?`\u2705 The repository's own tests pass with these changes.
35
+
36
+ `:`\u274C Verification did **not** pass. Treat these changes as a starting point, not a finished migration.
37
+
38
+ `,Y.verificationOutput&&!Y.verified)Z+=`<details><summary>Verification output</summary>
39
+
40
+ \`\`\`
41
+ ${Y.verificationOutput.slice(0,3000)}
42
+ \`\`\`
43
+
44
+ </details>
45
+
46
+ `;if(Y.unresolved.length>0)Z+=`### Still to do
47
+
48
+ `,Z+=`${Y.unresolved.map((H)=>`- [ ] ${F(H)}`).join(`
49
+ `)}
50
+
51
+ `}if(J.risks.length>0)Z+=`### Risks
52
+
53
+ ${J.risks.map((H)=>`- ${F(H)}`).join(`
54
+ `)}
55
+
56
+ `;let K=x(Q);if(K.length>0)Z+=`<details><summary>Where this package is used (${Q.length} site(s))</summary>
57
+
58
+ `,Z+=`${K.slice(0,40).map((H)=>`- \`${H.path}\` \u2014 ${H.count} reference(s)`).join(`
59
+ `)}
60
+
61
+ `,Z+=`</details>
62
+
63
+ `;return Z}function F(J){return J.replace(/\|/g,"\\|").replace(/\n/g," ").replace(/#(\d)/g,"#\u200B$1")}async function V(J){let Y=J.logger??I(),{update:Q}=J;if(!J.ai)return Y.debug("\uD83D\uDD27 Major upgrade analysis skipped: no AI provider configured"),{plan:null,report:"",draft:!1,status:"skipped"};let Z=await E(Q.name,J.files,J.workspace);Y.info(`\uD83D\uDD27 Analysing ${Q.name} ${Q.currentVersion} \u2192 ${Q.newVersion} (${Z.length} usage site(s))`);let K=[...new Set(Z.map((B)=>B.path))],H=await J.ai.complete({system:"You analyse major dependency upgrades. Report only what affects the repository "+"you are shown, and state confidence honestly \u2014 a low-confidence plan is more useful "+"than a wrong high-confidence one.",messages:[{role:"user",content:T({packageName:Q.name,fromVersion:Q.currentVersion,toVersion:Q.newVersion,releaseNotes:J.releaseNotes,usage:Z})}],jsonSchema:R}),$=C(H.json,{packageName:Q.name,fromVersion:Q.currentVersion,toVersion:Q.newVersion,knownFiles:K}),W=A($,J.draftBelowConfidence??"high");if(J.autoMigrate!==!0)return{plan:$,report:G($,void 0,Z),draft:W,status:"analysis-only"};if($.changes.length===0)return Y.info("\uD83D\uDD27 No breaking changes affect this repository; nothing to migrate"),{plan:$,report:G($,void 0,Z),draft:!1,status:"analysis-only"};let j=await N(J.ai,{mode:M,task:c($),context:{workspace:J.workspace,baseBranch:J.baseBranch,...J.branch?{branch:J.branch}:{}},logger:Y}),z=j.stopReason==="completed",X={applied:j.toolCalls>0,verified:z,changedFiles:K,unresolved:z?[]:$.changes.filter((B)=>!B.automatable).map((B)=>B.action),...z?{}:{verificationOutput:j.output}};return{plan:$,outcome:X,report:G($,X,Z),draft:W||!z,status:z?"migrated":"migration-failed"}}function c(J){let Y=J.changes.map((Q,Z)=>`${Z+1}. ${Q.description}
64
+ Action: ${Q.action}
65
+ Files: ${Q.affectedFiles.join(", ")||"(none identified)"}`);return[`Migrate this repository for the ${J.packageName} upgrade from ${J.fromVersion} to ${J.toVersion}.`,"",J.codemod?`An official codemod exists. Run it first:
66
+ ${J.codemod.command}
67
+ `:"","Breaking changes to address:","",Y.join(`
68
+
69
+ `),"","Change only what these require. A migration commit that also refactors","surrounding code is one a reviewer has to disentangle.","","Run the repository's tests when you are done. If they fail and you cannot fix it,","stop and report what failed \u2014 do not report success you have not verified."].filter(Boolean).join(`
70
+ `)}var WJ=24000,d=/^v?(\d+)\.(\d+)\.(\d+)/;function q(J){let Y=d.exec(J.trim());return Y?[Number(Y[1]),Number(Y[2]),Number(Y[3])]:null}function L(J,Y){return J[0]-Y[0]||J[1]-Y[1]||J[2]-Y[2]}function l(J,Y,Q){let[Z,K,H]=[q(J),q(Y),q(Q)];if(!Z||!K||!H)return!1;return L(Z,K)>0&&L(Z,H)<=0}function i(J){return q(J)?.[2]===0}function S(J,Y,Q,Z=24000){let K=J.filter((X)=>!X.isPrerelease&&l(X.version,Y,Q)),H=[],$=[];for(let X of K){let B=q(X.version)!==null&&q(Q)!==null&&L(q(X.version),q(Q))===0;if(i(X.version)||B)$.push(X);else H.push({version:X.version,reason:"patch-release"})}$.sort((X,B)=>L(q(B.version)??[0,0,0],q(X.version)??[0,0,0]));let W=[],j=[],z=0;for(let X of $){let B=r(X);if(z+B.length>Z){H.push({version:X.version,reason:"budget"});continue}W.push(B),j.push(X.version),z+=B.length}return{notes:W.join(`
71
+
72
+ ---
73
+
74
+ `),included:j,omitted:H,truncated:K.length===0&&Y!==Q}}function r(J){return`${J.htmlUrl?`## [${J.version}](${J.htmlUrl})`:`## ${J.version}`}
75
+
76
+ ${J.body.trim()}`.trim()}function w(J){if(J.truncated)return"\u26A0\uFE0F No release notes were found for this version span; the analysis below is based on usage sites alone.";let Y=J.omitted.filter((Q)=>Q.reason==="budget");if(Y.length===0)return"";return`\u26A0\uFE0F ${Y.length} release(s) in this span were omitted for length: ${Y.map((Q)=>Q.version).join(", ")}.`}function p(J,Y){if(!Y?.length)return!0;return Y.some((Q)=>{let Z=Q.split("*").map((K)=>K.replace(/[.+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(`^${Z}$`).test(J)})}async function FJ(J){let Y=J.logger??I(),Q=J.config.ai?.majorUpgrades,Z={report:"",draft:!1,results:[],skipped:[]};if(!Q?.enabled||!J.ai)return Z;let K=J.updates.filter((W)=>W.updateType==="major");if(K.length===0)return Z;let H=[],$=[];for(let W of K){if(!p(W.name,Q.packages)){$.push({name:W.name,reason:"not matched by ai.majorUpgrades.packages"});continue}try{let j=await J.fetchReleases(W.name,W.currentVersion,W.newVersion),z=S(j,W.currentVersion,W.newVersion),X=w(z),B=await V({update:W,releaseNotes:z.notes,files:J.files,workspace:J.workspace,baseBranch:J.baseBranch,ai:J.ai,...Q.autoMigrate!==void 0?{autoMigrate:Q.autoMigrate}:{},...Q.draftBelowConfidence?{draftBelowConfidence:Q.draftBelowConfidence}:{},logger:Y});H.push({update:W,result:X?{...B,report:`${X}
77
+
78
+ ${B.report}`}:B})}catch(j){Y.warn(`\u26A0\uFE0F Could not analyse the ${W.name} major upgrade: ${j}`),$.push({name:W.name,reason:"analysis failed"})}}return{report:s(H,$),draft:H.some((W)=>W.result.draft),results:H,skipped:$}}function s(J,Y){let Q=J.filter((K)=>K.result.report).map((K)=>`### ${K.update.name} ${K.update.currentVersion} \u2192 ${K.update.newVersion}
79
+
80
+ ${K.result.report}`);if(Q.length===0&&Y.length===0)return"";let Z=["## Major upgrade analysis","",...Q];if(Y.length>0)Z.push("",`Not analysed: ${Y.map((K)=>`\`${K.name}\` (${K.reason})`).join(", ")}.`);return Z.join(`
81
+ `)}function UJ(J,Y){if(!Y.trim())return J;let Q=v(J),Z=J.slice(Q.length);return`${Q}
82
+
83
+ ---
84
+
85
+ ${Y}${Z}`}
86
+ export{R as $h,f as ai,T as bi,C as ci,A as di,E as ei,x as fi,G as gi,V as hi,WJ as ii,S as ji,w as ki,p as li,FJ as mi,UJ as ni};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import"./chunk-1a53wj0h.js";import{$a as b,_a as a,ab as c,bb as d}from"./chunk-fdj0tewy.js";import"./chunk-bxfc4g2x.js";import"./chunk-g0w8n555.js";import"./chunk-tzs22es2.js";import"./chunk-9750tenz.js";import"./chunk-akffynkc.js";import"./chunk-6g1y9yqh.js";export{b as extractErrorLines,c as describeFailure,a as classifyFailure,d as attemptFix};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Ja as a,Ka as b,La as c,Ma as d,Na as e,Oa as f}from"./chunk-xvptf9jy.js";import"./chunk-1h3ey7k5.js";import"./chunk-akffynkc.js";import"./chunk-6g1y9yqh.js";export{b as productFor,f as describeEol,c as cycleFor,d as checkEol,e as EOL_WARNING_DAYS,a as EOL_PRODUCTS};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import"./chunk-x9ctz1qc.js";import{cb as d,db as e,eb as f,fb as g,gb as h,hb as i,ib as j,jb as k,kb as l,lb as q,mb as r,nb as s,ob as t,pb as u,qb as v,rb as w}from"./chunk-bm8d40j0.js";import{sb as a,tb as b,ub as c}from"./chunk-4xsq18p3.js";import{Ab as n,Bb as o,Cb as p,zb as m}from"./chunk-49ey79p0.js";import"./chunk-74pxb991.js";import"./chunk-p4zwy518.js";import"./chunk-vagxqhef.js";import"./chunk-xqx460y2.js";import"./chunk-ts35hc5t.js";import{Rd as x,Sd as y,Td as z,Ud as A,Vd as B,Wd as C,Xd as D,Yd as E,Zd as F,_d as G}from"./chunk-fvpr07dn.js";import"./chunk-q9n79dd3.js";import"./chunk-tzs22es2.js";import"./chunk-1h3ey7k5.js";import"./chunk-akffynkc.js";import"./chunk-6g1y9yqh.js";export{g as validateFindings,G as shouldFail,n as serializeReviewState,w as runReviewForPR,j as reviewDiff,u as renderFinding,b as renderDiffForReview,v as prepareReview,a as parseUnifiedDiff,o as parseReviewState,p as needsReview,s as loadGuidelines,E as formatReview,A as formatPretty,B as formatGithub,C as formatAgent,f as fingerprint,y as diffArgsFor,l as defaultIncludePath,h as dedupeFindings,D as countBySeverity,t as composeInstructions,z as collectLocalDiff,c as collectGitDiff,F as applySuggestion,k as anchorMap,d as SEVERITY_ORDER,m as REVIEW_STATE_VERSION,e as REVIEW_SCHEMA,x as REVIEW_FORMATS,r as MAX_GUIDELINE_CHARS,q as DEFAULT_GUIDELINE_FILES,i as DEFAULT_EXCLUDED_PATHS};
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import{Ji as K,Li as T,Mi as S,Ni as F}from"./chunk-tzs22es2.js";import{Lj as N}from"./chunk-1h3ey7k5.js";import{Rj as C}from"./chunk-akffynkc.js";import{Fk as _}from"./chunk-6g1y9yqh.js";var x={claude:"claude-opus-5","claude-opus":"claude-opus-5",opus:"claude-opus-5","claude-sonnet":"claude-sonnet-5",sonnet:"claude-sonnet-5","claude-haiku":"claude-haiku-4-5",haiku:"claude-haiku-4-5","claude-fable":"claude-fable-5",fable:"claude-fable-5"},L={anthropic:"claude-opus-5"},w={anthropic:["ANTHROPIC_API_KEY"],openai:["OPENAI_API_KEY"],google:["GOOGLE_API_KEY","GEMINI_API_KEY"],openrouter:["OPENROUTER_API_KEY"],"openai-compatible":["OPENAI_COMPATIBLE_API_KEY","OPENAI_API_KEY"]},D=["anthropic","openai","google","openrouter"];function M(j){return x[j.toLowerCase().trim()]??j}var b=16000;function k(j){let Z;async function $(){if(Z)return Z;let H;try{H=(await import("./chunk-yk23nc4t.js")).default}catch{throw new F(`The Anthropic provider needs @anthropic-ai/sdk, which is an optional peer dependency.
3
+ Install it with: bun add @anthropic-ai/sdk`,"anthropic")}return Z=new H({apiKey:j.apiKey,...j.baseUrl?{baseURL:j.baseUrl}:{}}),Z}return{name:"anthropic",async complete(H,G){let W={};if(H.effort)W.effort=H.effort;if(H.jsonSchema)W.format={type:"json_schema",schema:H.jsonSchema};let z=await(await $()).messages.create({model:G,max_tokens:H.maxTokens??b,...H.system?{system:H.system}:{},messages:H.messages.map((Q)=>({role:Q.role,content:Q.content})),...H.tools?.length?{tools:H.tools.map((Q)=>({name:Q.name,description:Q.description,input_schema:Q.parameters}))}:{},...Object.keys(W).length>0?{output_config:W}:{}}),X="",J=[];for(let Q of z.content)if(Q.type==="text")X+=Q.text;else if(Q.type==="tool_use")J.push({id:Q.id,name:Q.name,input:Q.input});return{text:X,toolCalls:J,json:y(X,H.jsonSchema!==void 0),stopReason:P(z.stop_reason),usage:{inputTokens:z.usage.input_tokens,outputTokens:z.usage.output_tokens,...z.usage.cache_read_input_tokens!=null?{cachedInputTokens:z.usage.cache_read_input_tokens}:{}},model:z.model}}}}function P(j){switch(j){case"end_turn":case"stop_sequence":return"end";case"tool_use":return"tool_use";case"max_tokens":return"max_tokens";case"refusal":return"refusal";default:return"other"}}function y(j,Z){if(!Z)return;try{return JSON.parse(j)}catch{throw new F("Model returned malformed JSON for a schema-constrained request","anthropic")}}var f=16000,A="https://generativelanguage.googleapis.com/v1beta";function U(j){let Z=(j.baseUrl??A).replace(/\/+$/,"");return{name:"google",async complete($,H){let G={contents:$.messages.map((Y)=>({role:Y.role==="assistant"?"model":"user",parts:[{text:Y.content}]})),generationConfig:{maxOutputTokens:$.maxTokens??f,...$.jsonSchema?{responseMimeType:"application/json",responseSchema:$.jsonSchema}:{}}};if($.system)G.systemInstruction={parts:[{text:$.system}]};if($.tools?.length)G.tools=[{functionDeclarations:$.tools.map((Y)=>({name:Y.name,description:Y.description,parameters:Y.parameters}))}];let W=await N(`${Z}/models/${encodeURIComponent(H)}:generateContent`,{method:"POST",headers:{"x-goog-api-key":j.apiKey,"Content-Type":"application/json"},body:JSON.stringify(G)});if(!W.ok){let Y=await W.text().catch(()=>"");throw new F(`google request failed: ${W.status} ${W.statusText} ${K(Y.slice(0,500))}`.trim(),"google",W.status)}let z=await W.json(),X=z.candidates?.[0],J="",Q=[];for(let[Y,V]of(X?.content?.parts??[]).entries()){if(V.text)J+=V.text;if(V.functionCall?.name)Q.push({id:`${V.functionCall.name}-${Y}`,name:V.functionCall.name,input:V.functionCall.args??{}})}return{text:J,toolCalls:Q,json:$.jsonSchema?h(J):void 0,stopReason:E(X?.finishReason,Q.length>0),usage:{inputTokens:z.usageMetadata?.promptTokenCount??0,outputTokens:z.usageMetadata?.candidatesTokenCount??0,...z.usageMetadata?.cachedContentTokenCount!=null?{cachedInputTokens:z.usageMetadata.cachedContentTokenCount}:{}},model:z.modelVersion??H}}}}function E(j,Z){if(Z)return"tool_use";switch(j){case"STOP":return"end";case"MAX_TOKENS":return"max_tokens";case"SAFETY":case"PROHIBITED_CONTENT":case"BLOCKLIST":return"refusal";default:return"other"}}function h(j){try{return JSON.parse(j)}catch{throw new F("Model returned malformed JSON for a schema-constrained request","google")}}var g=16000,v="https://api.openai.com/v1",m="https://openrouter.ai/api/v1";function O(j){let Z=j.provider??"openai",$=(j.baseUrl??q(Z)).replace(/\/+$/,"");return{name:Z,async complete(H,G){let W=[];if(H.system)W.push({role:"system",content:H.system});for(let B of H.messages)W.push({role:B.role,content:B.content});let z={model:G,messages:W,max_completion_tokens:H.maxTokens??g};if(H.tools?.length)z.tools=H.tools.map((B)=>({type:"function",function:{name:B.name,description:B.description,parameters:B.parameters}}));if(H.jsonSchema)z.response_format={type:"json_schema",json_schema:{name:"response",schema:H.jsonSchema,strict:!0}};if(H.effort)z.reasoning_effort=H.effort;let X={Authorization:`Bearer ${j.apiKey}`,"Content-Type":"application/json"};if(Z==="openrouter")X["HTTP-Referer"]="https://github.com/stacksjs/buddy",X["X-Title"]="buddy";let J=await N(`${$}/chat/completions`,{method:"POST",headers:X,body:JSON.stringify(z)});if(!J.ok){let B=await J.text().catch(()=>"");throw new F(`${Z} request failed: ${J.status} ${J.statusText} ${K(B.slice(0,500))}`.trim(),Z,J.status)}let Q=await J.json(),Y=Q.choices?.[0],V=Y?.message?.content??"",I=(Y?.message?.tool_calls??[]).map((B)=>({id:B.id,name:B.function?.name??"",input:p(B.function?.arguments,Z)}));return{text:V,toolCalls:I,json:H.jsonSchema?d(V,Z):void 0,stopReason:c(Y?.finish_reason,I.length>0),usage:{inputTokens:Q.usage?.prompt_tokens??0,outputTokens:Q.usage?.completion_tokens??0,...Q.usage?.prompt_tokens_details?.cached_tokens!=null?{cachedInputTokens:Q.usage.prompt_tokens_details.cached_tokens}:{}},model:Q.model??G}}}}function q(j){return j==="openrouter"?m:v}function c(j,Z){if(Z||j==="tool_calls")return"tool_use";switch(j){case"stop":return"end";case"length":return"max_tokens";case"content_filter":return"refusal";default:return"other"}}function p(j,Z){if(!j)return{};try{return JSON.parse(j)}catch{throw new F("Model returned malformed JSON tool arguments",Z)}}function d(j,Z){try{return JSON.parse(j)}catch{throw new F("Model returned malformed JSON for a schema-constrained request",Z)}}import R from"process";function u(j,Z=R.env){let $=j.ai;if($?.enabled===!1)return null;let H=$?.provider?[$.provider]:D;for(let G of H){let W=i(G,$?.apiKeyEnv,Z);if(!W)continue;let{key:z,source:X}=W,J=a(G,$?.model);if(!J)continue;return{provider:G,model:J,apiKey:z,apiKeyEnv:X,...$?.baseUrl?{baseUrl:$.baseUrl}:{}}}return null}function Vj(j,Z=C()){let $=u(j);if(!$)return Z.debug("AI disabled: no provider configured with an available API key"),null;let H=n($),G=j.ai?.maxTokensPerRun,W=j.ai?.effort,z=0;return{provider:$.provider,model:$.model,get tokensUsed(){return z},async complete(X){if(G!==void 0&&z>=G)throw new S(z,G);let J=X.model?M(X.model):$.model;try{let Q=await H.complete({...X,effort:X.effort??W},J);return z+=Q.usage.outputTokens,Z.debug(`AI ${$.provider}/${Q.model}: ${Q.usage.inputTokens} in, ${Q.usage.outputTokens} out (${Q.stopReason})`),Q}catch(Q){if(Q instanceof S)throw Q;let Y=T(Q);throw Z.warn(`\u26A0\uFE0F AI request failed (${$.provider}): ${Y}`),Q instanceof F?Q:new F(Y,$.provider)}}}}function n(j){switch(j.provider){case"anthropic":return k({apiKey:j.apiKey,baseUrl:j.baseUrl});case"google":return U({apiKey:j.apiKey,baseUrl:j.baseUrl});case"openai":case"openrouter":case"openai-compatible":return O({apiKey:j.apiKey,baseUrl:j.baseUrl,provider:j.provider})}}function i(j,Z,$){let H=Z?[Z,...w[j]]:w[j];for(let G of H){let W=$[G];if(W&&W.trim().length>0)return{key:W.trim(),source:G}}return}function a(j,Z){let $=R.env.BUDDY_MODEL||Z;if($)return M($);return L[j]}
4
+ export{x as Mb,w as Nb,D as Ob,M as Pb,k as Qb,U as Rb,O as Sb,u as Tb,Vj as Ub};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{$c as e,Xc as a,Yc as b,Zc as c,_c as d,ad as f}from"./chunk-1c1gznm9.js";import"./chunk-q9n79dd3.js";import"./chunk-978wtejw.js";import"./chunk-pkkwb0n0.js";import"./chunk-ph1b3vbp.js";import"./chunk-0j7z87kh.js";import"./chunk-7mgec8kb.js";import"./chunk-5k40mwd4.js";import"./chunk-1h3ey7k5.js";import"./chunk-akffynkc.js";import"./chunk-x3kragh9.js";import"./chunk-wdwvt7gb.js";import"./chunk-8661pvb8.js";import"./chunk-ctsz0ynx.js";import"./chunk-vkctfqpm.js";import"./chunk-6g1y9yqh.js";export{b as ruleMatches,c as resolveRuleEffects,e as mergeGroupEffects,f as groupsToRules,a as ecosystemOf,d as applyRules};