@visulima/vis 1.0.0-alpha.40 → 1.0.0-alpha.42

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 (199) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE.md +265 -35
  3. package/dist/bin.js +1 -1
  4. package/dist/binx.js +2 -2
  5. package/dist/config/index.d.ts +19 -1
  6. package/dist/config/index.js +1 -1
  7. package/dist/packem_chunks/bloom-status.js +1 -1
  8. package/dist/packem_chunks/bloom-sync.js +1 -1
  9. package/dist/packem_chunks/cli-exec.js +1 -0
  10. package/dist/packem_chunks/{bin.js → cli-main.js} +282 -274
  11. package/dist/packem_chunks/config.js +8 -11
  12. package/dist/packem_chunks/devtools.js +1 -78
  13. package/dist/packem_chunks/dispatch.js +4 -0
  14. package/dist/packem_chunks/doctor-probe.js +1 -1
  15. package/dist/packem_chunks/fix.js +1 -1
  16. package/dist/packem_chunks/handler.js +1 -1
  17. package/dist/packem_chunks/handler10.js +1 -1
  18. package/dist/packem_chunks/handler11.js +1 -1
  19. package/dist/packem_chunks/handler12.js +1 -1
  20. package/dist/packem_chunks/handler13.js +3 -3
  21. package/dist/packem_chunks/handler14.js +1 -1
  22. package/dist/packem_chunks/handler15.js +1 -1
  23. package/dist/packem_chunks/handler16.js +1 -1
  24. package/dist/packem_chunks/handler17.js +1 -1
  25. package/dist/packem_chunks/handler18.js +1 -1
  26. package/dist/packem_chunks/handler19.js +1 -1
  27. package/dist/packem_chunks/handler2.js +1 -4
  28. package/dist/packem_chunks/handler20.js +1 -1
  29. package/dist/packem_chunks/handler21.js +1 -1
  30. package/dist/packem_chunks/handler22.js +2 -2
  31. package/dist/packem_chunks/handler23.js +5 -1
  32. package/dist/packem_chunks/handler24.js +1 -1
  33. package/dist/packem_chunks/handler25.js +1 -1
  34. package/dist/packem_chunks/handler26.js +1 -5
  35. package/dist/packem_chunks/handler27.js +5 -1
  36. package/dist/packem_chunks/handler28.js +1 -3
  37. package/dist/packem_chunks/handler29.js +3 -1
  38. package/dist/packem_chunks/handler3.js +1 -4
  39. package/dist/packem_chunks/handler30.js +1 -2
  40. package/dist/packem_chunks/handler31.js +1 -2
  41. package/dist/packem_chunks/handler32.js +2 -2
  42. package/dist/packem_chunks/handler33.js +2 -3
  43. package/dist/packem_chunks/handler34.js +2 -6
  44. package/dist/packem_chunks/handler35.js +3 -1
  45. package/dist/packem_chunks/handler36.js +6 -42
  46. package/dist/packem_chunks/handler37.js +1 -8
  47. package/dist/packem_chunks/handler38.js +42 -9
  48. package/dist/packem_chunks/handler39.js +7 -74
  49. package/dist/packem_chunks/handler4.js +4 -6
  50. package/dist/packem_chunks/handler40.js +9 -5
  51. package/dist/packem_chunks/handler41.js +75 -4
  52. package/dist/packem_chunks/handler42.js +5 -3
  53. package/dist/packem_chunks/handler43.js +4 -2
  54. package/dist/packem_chunks/handler44.js +3 -1
  55. package/dist/packem_chunks/handler45.js +2 -1
  56. package/dist/packem_chunks/handler46.js +1 -1
  57. package/dist/packem_chunks/handler47.js +1 -3
  58. package/dist/packem_chunks/handler48.js +1 -1
  59. package/dist/packem_chunks/handler49.js +3 -7
  60. package/dist/packem_chunks/handler5.js +4 -8
  61. package/dist/packem_chunks/handler50.js +1 -33
  62. package/dist/packem_chunks/handler51.js +7 -3
  63. package/dist/packem_chunks/handler52.js +33 -8
  64. package/dist/packem_chunks/handler53.js +3 -4
  65. package/dist/packem_chunks/handler54.js +8 -1
  66. package/dist/packem_chunks/handler55.js +4 -12
  67. package/dist/packem_chunks/handler56.js +1 -7
  68. package/dist/packem_chunks/handler57.js +12 -5
  69. package/dist/packem_chunks/handler58.js +5 -11
  70. package/dist/packem_chunks/handler59.js +11 -3
  71. package/dist/packem_chunks/handler6.js +6 -1
  72. package/dist/packem_chunks/handler60.js +3 -22
  73. package/dist/packem_chunks/handler61.js +21 -60
  74. package/dist/packem_chunks/handler62.js +61 -3
  75. package/dist/packem_chunks/handler63.js +3 -6
  76. package/dist/packem_chunks/handler64.js +6 -708
  77. package/dist/packem_chunks/handler65.js +8 -23
  78. package/dist/packem_chunks/handler66.js +24 -25
  79. package/dist/packem_chunks/handler67.js +25 -153
  80. package/dist/packem_chunks/handler68.js +153 -10
  81. package/dist/packem_chunks/handler69.js +10 -24
  82. package/dist/packem_chunks/handler7.js +8 -1
  83. package/dist/packem_chunks/handler70.js +24 -322
  84. package/dist/packem_chunks/handler71.js +322 -48
  85. package/dist/packem_chunks/handler72.js +700 -19
  86. package/dist/packem_chunks/handler73.js +48 -3
  87. package/dist/packem_chunks/handler74.js +21 -184
  88. package/dist/packem_chunks/handler75.js +3 -38
  89. package/dist/packem_chunks/handler76.js +190 -0
  90. package/dist/packem_chunks/handler77.js +38 -0
  91. package/dist/packem_chunks/handler8.js +1 -1
  92. package/dist/packem_chunks/handler9.js +1 -1
  93. package/dist/packem_chunks/heal-accept.js +1 -1
  94. package/dist/packem_chunks/heal.js +1 -1
  95. package/dist/packem_chunks/help-command.js +4 -4
  96. package/dist/packem_chunks/index2.js +1 -1
  97. package/dist/packem_chunks/index3.js +135 -0
  98. package/dist/packem_chunks/index4.js +74 -0
  99. package/dist/packem_chunks/keys-refresh.js +1 -1
  100. package/dist/packem_chunks/lean.js +4 -0
  101. package/dist/packem_chunks/list.js +1 -1
  102. package/dist/packem_chunks/loader.js +1 -1
  103. package/dist/packem_chunks/loader2.js +1 -1
  104. package/dist/packem_chunks/orchestrator.js +3 -3
  105. package/dist/packem_chunks/prompts.js +1 -1
  106. package/dist/packem_chunks/prune.js +1 -1
  107. package/dist/packem_chunks/registry.js +2 -2
  108. package/dist/packem_chunks/run.js +1 -1
  109. package/dist/packem_chunks/shell-runner.js +1 -1
  110. package/dist/packem_chunks/status.js +1 -1
  111. package/dist/packem_chunks/sync.js +1 -1
  112. package/dist/packem_chunks/sync2.js +1 -1
  113. package/dist/packem_chunks/tar.js +1 -1
  114. package/dist/packem_chunks/tripwire.js +1 -1
  115. package/dist/packem_chunks/ts-loader.js +2 -0
  116. package/dist/packem_chunks/verify-lockfile.js +1 -1
  117. package/dist/packem_chunks/version-resolver.js +2 -2
  118. package/dist/packem_shared/CONFIG_FILES-MsOntfYT.js +1 -0
  119. package/dist/packem_shared/{Table-CcVkyULl-B_ef6zfS.js → Table-CcVkyULl-DLWu6XHL.js} +25 -26
  120. package/dist/packem_shared/{advisories-DLeO5KMN.js → advisories-aiDtubZQ.js} +1 -1
  121. package/dist/packem_shared/{affected-shas-cVnX8-zs.js → affected-shas-C1XuRlvo.js} +1 -1
  122. package/dist/packem_shared/{ai-analysis-BUeX2J2H.js → ai-analysis-CubpCxZJ.js} +4 -4
  123. package/dist/packem_shared/{ai-fix-9Vzlp6XU.js → ai-fix-Btd5AnSr.js} +2 -2
  124. package/dist/packem_shared/augment-8fIWWGSc.js +3 -0
  125. package/dist/packem_shared/bin-CnDBuLh3.js +2 -0
  126. package/dist/packem_shared/build-scripts-Doxce2VM.js +1 -0
  127. package/dist/packem_shared/command-runtime-RiCMa2C8.js +1 -0
  128. package/dist/packem_shared/compile-cache-B_Vf_WxT.js +3 -0
  129. package/dist/packem_shared/{cyclonedx-kYozDyxp.js → cyclonedx-NUJ9R2GQ.js} +1 -1
  130. package/dist/packem_shared/dependency-scan-B0HV_qeB.js +1 -0
  131. package/dist/packem_shared/{docker-BMLrNtWm.js → docker-DKlF-gk3.js} +1 -1
  132. package/dist/packem_shared/failure-log-C7r6UZLP.js +2 -0
  133. package/dist/packem_shared/{giget-DHY1sQZC.js → giget-DVTFJlbR.js} +2 -2
  134. package/dist/packem_shared/glob-fqg4KepW-7Bs2kZuM.js +1 -0
  135. package/dist/packem_shared/index-BKFEWXU_.js +1 -0
  136. package/dist/packem_shared/index-CPhv-r4c.js +28 -0
  137. package/dist/packem_shared/{index-CgcF6_wo.js → index-Cb4x6lWY.js} +1 -1
  138. package/dist/packem_shared/index-DjTWo3sH.js +1 -0
  139. package/dist/packem_shared/{index-BDmTbWX1.js → index-OQZQyN5R.js} +1 -1
  140. package/dist/packem_shared/index.server-J83sowC4.js +2 -0
  141. package/dist/packem_shared/{lifecycle-4z9hHE5b.js → lifecycle-D5roTh0a.js} +2 -2
  142. package/dist/packem_shared/{lockfile-C8Q1_4KK.js → lockfile-DIGyLfmF.js} +1 -1
  143. package/dist/packem_shared/main-B3juSU5z.js +1 -0
  144. package/dist/packem_shared/manifests-pLwnVmCN.js +1 -0
  145. package/dist/packem_shared/{min-release-age-D1alDE3K.js → min-release-age-pUAqTiv3.js} +3 -3
  146. package/dist/packem_shared/missing-package-json-DhYzuKhD.js +1 -0
  147. package/dist/packem_shared/{native-config-sync-BEkJW7g3.js → native-config-sync-4K9wWTj5.js} +1 -1
  148. package/dist/packem_shared/{osv-bloom-B03tUWf3.js → osv-bloom-OuTfu_LE.js} +1 -1
  149. package/dist/packem_shared/{pm-runner-OGResYrA.js → pm-runner-Dws_Bw1y.js} +1 -1
  150. package/dist/packem_shared/provenance-C0P-UYOM.js +1 -0
  151. package/dist/packem_shared/readJsonSync-CvkZyKmL-CY7PZob_.js +4 -0
  152. package/dist/packem_shared/registry-keys-D4chF-Wj.js +1 -0
  153. package/dist/packem_shared/{resolve-explicit-CMDl55Nz.js → resolve-explicit-Cgheka3B.js} +3 -3
  154. package/dist/packem_shared/resolve-runtime-CJSWV-K8.js +1 -0
  155. package/dist/packem_shared/run-file-B4TqKa0X.js +1 -0
  156. package/dist/packem_shared/runtime-check-0lUJvgKt.js +1 -0
  157. package/dist/packem_shared/runtime-process-Dmz0vCJy-DUwTvH1J.js +1 -0
  158. package/dist/packem_shared/s1ngularity-Du1NnSFP.js +1 -0
  159. package/dist/packem_shared/scan-progress-CN9ONR0y.js +2 -0
  160. package/dist/packem_shared/{selectors-GCJIe342.js → selectors-UmnAuc26.js} +1 -1
  161. package/dist/packem_shared/{signatures-C730vkyK.js → signatures-BOUhghTv.js} +1 -1
  162. package/dist/packem_shared/{spinner-CV3WVJLv.js → spinner-lhXugSx3.js} +1 -1
  163. package/dist/packem_shared/tabs-DTiU3usb.js +1 -0
  164. package/dist/packem_shared/target-options-ChWcK60i.js +1 -0
  165. package/dist/packem_shared/toolchain-DyCKnGch.js +5 -0
  166. package/dist/packem_shared/typosquats-DBOvXwph.js +1 -0
  167. package/dist/packem_shared/use-measured-height-CK2Co3XI.js +1 -0
  168. package/dist/packem_shared/verify-CVPYlUrF.js +1 -0
  169. package/dist/packem_shared/vis-update-app-DtHkwBca.js +1 -0
  170. package/dist/packem_shared/watch-Bkp_AAbc.js +1 -0
  171. package/dist/packem_shared/watch-loop-D9zbXzRd.js +11 -0
  172. package/dist/runtime/preload.d.ts +1 -0
  173. package/dist/runtime/preload.js +1 -0
  174. package/index.d.ts +14 -0
  175. package/index.js +28 -27
  176. package/package.json +18 -27
  177. package/schemas/vis-config.schema.json +12 -0
  178. package/dist/packem_shared/CONFIG_FILES-BfaR0jKT.js +0 -1
  179. package/dist/packem_shared/build-scripts-CCCi8U66.js +0 -1
  180. package/dist/packem_shared/dependency-scan-DnTgYleU.js +0 -1
  181. package/dist/packem_shared/failure-log-CEWP3bP0.js +0 -2
  182. package/dist/packem_shared/glob-fqg4KepW-B7EjLRvw.js +0 -1
  183. package/dist/packem_shared/index-Du8RWawQ.js +0 -1
  184. package/dist/packem_shared/index-yBikBkHT.js +0 -30
  185. package/dist/packem_shared/manifests-Dj3pRKBT.js +0 -1
  186. package/dist/packem_shared/missing-package-json-8vNHwbqw.js +0 -1
  187. package/dist/packem_shared/provenance-_CJjMKwu.js +0 -1
  188. package/dist/packem_shared/registry-keys-BfFto6vI.js +0 -1
  189. package/dist/packem_shared/runtime-check-Stc9AI78.js +0 -1
  190. package/dist/packem_shared/s1ngularity-Dhr3bPk0.js +0 -1
  191. package/dist/packem_shared/scan-progress-CFhc0CMj.js +0 -2
  192. package/dist/packem_shared/tabs-BuTy5gPV.js +0 -1
  193. package/dist/packem_shared/toolchain-pR7AJ-tB.js +0 -5
  194. package/dist/packem_shared/typosquats-DN78xx1x.js +0 -1
  195. package/dist/packem_shared/use-measured-height-_eVGWtWt.js +0 -1
  196. package/dist/packem_shared/verify-6WCmFmy8.js +0 -1
  197. package/dist/packem_shared/vis-update-app-k3fDxech.js +0 -1
  198. package/dist/packem_shared/watch-BvIwLG4N.js +0 -1
  199. package/dist/packem_shared/watch-loop-DWkvv2tK.js +0 -11
@@ -1 +1 @@
1
- import{I as t,x as i}from"../packem_shared/pm-runner-OGResYrA.js";const l=async({logger:e,options:a,visConfig:o,workspaceRoot:n})=>{const c=n??process.cwd(),r=t(c,{configBackend:o?.install?.backend,configCorepack:o?.install?.corepack}),s=i(r,a.check||!1,c,e);s!==0&&(process.exitCode=s)};export{l as default};
1
+ import{r as g}from"../packem_shared/affected-shas-C1XuRlvo.js";import{r as m}from"../packem_shared/toolchain-DyCKnGch.js";const w=async({argument:d,logger:t,options:o,runtime:r,visConfig:s,workspaceRoot:e})=>{const l=d[0];if(!l)throw new Error("Missing targets. Usage: vis ci <target>[,<target>…]");const f=l.split(",").map(a=>a.trim()).filter(Boolean);if(f.length===0)throw new Error("Missing targets. Usage: vis ci <target>[,<target>…]");if(!e)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const i=g({defaultBase:s?.defaultBase,workspaceRoot:e}),p=o.base??i.base,c=o.head??i.head;!o.base&&!o.head&&t.info(`▸ Resolved affected refs from ${i.provider} (${i.notes.join("; ")})`),o.skipToolchain||t.info("▸ Toolchain pre-flight"),await m(e,s?.toolchain,{error:a=>{t.error(a)},info:a=>{t.info(a)},warn:a=>{t.warn(a)}},!!o.skipToolchain),o.install===!1?t.info("▸ Skipping install (--no-install)"):(t.info("▸ Installing dependencies"),await r.runCommand("install",{argv:["--ci","--frozen-lockfile"]}));for(const a of f){t.info(`▸ Running affected ${a} (base=${p}, head=${c})`);const n=[a,`--base=${p}`,`--head=${c}`,`--upstream=${String(o.upstream??"none")}`,`--downstream=${String(o.downstream??"deep")}`];o.parallel!==void 0&&n.push(`--parallel=${String(o.parallel)}`),o.partition&&n.push(`--partition=${String(o.partition)}`),o.query&&n.push(`--query=${String(o.query)}`),await r.runCommand("affected",{argv:n})}t.info("▸ CI pipeline complete")};export{w as default};
@@ -1 +1 @@
1
- import{I as f,$ as k}from"../packem_shared/pm-runner-OGResYrA.js";const h=async({argument:n,logger:i,options:a,visConfig:s,workspaceRoot:r})=>{const e=n;if(!e||e.length===0)throw new Error("No package specified. Usage: vis dlx <package[@version]> [args...]");const[l,...g]=e,o=r??process.cwd(),t=f(o,{configBackend:s?.install?.backend,configCorepack:s?.install?.corepack}),p=a.package?Array.isArray(a.package)?a.package:[a.package]:[],c=k(t,{additionalPackages:p,args:g,package:l,shellMode:a.shellMode||!1,silent:a.silent||!1},o,i,{offline:a.offline||!1});c!==0&&(process.exitCode=c)};export{h as default};
1
+ import{createRequire as p}from"node:module";import{m as u,f as _,I as $}from"../packem_shared/index-OQZQyN5R.js";import{cleanWorkspace as R}from"#native";import{l as b}from"../packem_shared/missing-package-json-DhYzuKhD.js";import{p as c}from"./cli-main.js";import{c as j}from"../packem_shared/utils-Cxree603.js";const g=p(import.meta.url),d=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,k=o=>{if(typeof d<"u"&&d.versions&&d.versions.node){const[r,n]=d.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return d.getBuiltinModule(o)}return g(o)},{readdirSync:y,lstatSync:h,rmSync:v}=k("node:fs"),S=/node_modules/,w=/\.git/,C=o=>{const r=[],n=[o];for(;n.length>0;){const s=n.pop();let i;try{i=y(s)}catch{continue}for(const t of i){const e=u(s,t);try{const f=h(e);if(f.isSymbolicLink()||!f.isDirectory())continue}catch{continue}t==="node_modules"?r.push(e):t!==".git"&&t!==".hg"&&n.push(e)}}return r},P=["pnpm-lock.yaml","package-lock.json","npm-shrinkwrap.json","yarn.lock","bun.lock","bun.lockb"],q=(o,r,n)=>{let s=0,i=!1;for(const t of P){const e=u(o,t);if(_(e)){n.info(` ${e}`),s++;continue}}return{hadError:i,removed:s}},x=o=>{for(const r of $(o,{includeDirs:!1,includeSymlinks:!1,skip:[S,w]}))if(r.name==="package.json")return!0;return!1},m=(o,r,n)=>{let s=0,i=!1;for(const{packageDir:t}of b(o)){const e=u(o,t);if(!x(e)){if(r){n.info(` ${e}`),s++;continue}try{v(e,{force:!0,recursive:!0}),c.success(`Removed empty package ${e}`),s++}catch(f){c.error(`${e}: ${j(f)}`),i=!0}}}return{hadError:i,removed:s}},B=async({logger:o,options:r,workspaceRoot:n})=>{const s=n??process.cwd(),i=r.lockfile||!1,t=r.emptyPackages||!1;if(r.dryRun){const l=C(s);if(l.length>0){c.info("Would remove:");for(const a of l)o.info(` ${a}`)}else c.info("No node_modules directories found.");i&&q(s,!0,o),t&&(c.info("Would remove empty packages:"),m(s,!0,o));return}const e=R(s,i);for(const l of e.removed)c.success(`Removed ${l}`);for(const l of e.lockfilesRemoved)c.success(`Removed ${l}`);for(const l of e.errors)c.error(l);e.removed.length===0&&e.lockfilesRemoved.length===0?c.info("No node_modules directories found."):c.info(`Cleaned ${e.removed.length} node_modules director${e.removed.length===1?"y":"ies"}`);let f=!1;if(t){const{hadError:l,removed:a}=m(s,!1,o);f=l,a>0&&c.info(`Cleaned ${a} empty package director${a===1?"y":"ies"}`)}(e.errors.length>0||f)&&(process.exitCode=1)};export{B as default};
@@ -1,4 +1,4 @@
1
- import{createRequire as G}from"node:module";import{B as y,y as N}from"../packem_shared/index-BDmTbWX1.js";import{d as O,k as U,P as H,R as F,p as P}from"./heal.js";import{w as D,M as S}from"../packem_shared/pm-runner-OGResYrA.js";import{p as a}from"./bin.js";const L=G(import.meta.url),_=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,x=e=>{if(typeof _<"u"&&_.versions&&_.versions.node){const[t,o]=_.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return _.getBuiltinModule(e)}return L(e)},{readFile:$}=x("node:fs/promises"),{createInterface:K}=x("node:readline"),j=()=>!!process.stdout.isTTY&&process.env.CI!=="true",V=e=>new Promise(t=>{const o=K({input:process.stdin,output:process.stderr});o.question(`${e} (Y/n) `,i=>{o.close();const s=i.trim().toLowerCase();t(s===""||s==="y"||s==="yes")})}),M=(e,t)=>{const o=D(t),i=S(o,{exact:!1,filter:[],global:!1,optional:!1,packages:[e],peer:!1,saveDev:!1,workspace:!1,workspaceRoot:!1},t,console);return Promise.resolve({exitCode:i})},R=e=>`pnpm add ${e}`,q=e=>e==="@gitbeaker/rest"?import("@gitbeaker/rest"):import("@octokit/rest"),B=async(e,t={})=>{const o=t.interactive??j(),i=t.prompt??V,s=t.runInstall??M,l=t.importImpl??q,d=t.workspaceRoot??process.cwd();try{return await l(e)}catch(n){const{code:p}=n;if(p!=="ERR_MODULE_NOT_FOUND"&&p!=="MODULE_NOT_FOUND")throw n}if(!o)throw new Error(`${e} is not installed. \`vis ai heal accept\` needs it to talk to the host. Install it in your repo first:
1
+ import{createRequire as G}from"node:module";import{B as y,y as N}from"../packem_shared/index-OQZQyN5R.js";import{d as O,k as U,P as H,R as F,p as P}from"./heal.js";import{w as D,M as S}from"../packem_shared/pm-runner-Dws_Bw1y.js";import{p as a}from"./cli-main.js";const L=G(import.meta.url),_=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,x=e=>{if(typeof _<"u"&&_.versions&&_.versions.node){const[t,o]=_.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return _.getBuiltinModule(e)}return L(e)},{readFile:$}=x("node:fs/promises"),{createInterface:K}=x("node:readline"),j=()=>!!process.stdout.isTTY&&process.env.CI!=="true",V=e=>new Promise(t=>{const o=K({input:process.stdin,output:process.stderr});o.question(`${e} (Y/n) `,i=>{o.close();const s=i.trim().toLowerCase();t(s===""||s==="y"||s==="yes")})}),M=(e,t)=>{const o=D(t),i=S(o,{exact:!1,filter:[],global:!1,optional:!1,packages:[e],peer:!1,saveDev:!1,workspace:!1,workspaceRoot:!1},t,console);return Promise.resolve({exitCode:i})},R=e=>`pnpm add ${e}`,q=e=>e==="@gitbeaker/rest"?import("@gitbeaker/rest"):import("@octokit/rest"),B=async(e,t={})=>{const o=t.interactive??j(),i=t.prompt??V,s=t.runInstall??M,l=t.importImpl??q,d=t.workspaceRoot??process.cwd();try{return await l(e)}catch(n){const{code:p}=n;if(p!=="ERR_MODULE_NOT_FOUND"&&p!=="MODULE_NOT_FOUND")throw n}if(!o)throw new Error(`${e} is not installed. \`vis ai heal accept\` needs it to talk to the host. Install it in your repo first:
2
2
  ${R(e)}`);if(!await i(`${e} isn't installed. Install it now?`))throw new Error(`${e} install declined. Re-run \`vis ai heal accept\` after installing manually:
3
3
  ${R(e)}`);const r=await s(e,d);if(r.exitCode!==0)throw new Error(`Install of ${e} failed (exit ${String(r.exitCode)}). Install manually and retry:
4
4
  ${R(e)}`);return await l(e)},Y=e=>{const t=e.indexOf("/");if(t<=0||t===e.length-1)throw new Error(`Expected GITHUB_REPOSITORY in "owner/repo" form, got: ${e}`);return{owner:e.slice(0,t),repo:e.slice(t+1)}},J=async(e,t)=>{if(t.githubClient)return t.githubClient;const o=(await(t.loadSdk??B)("@octokit/rest")).Octokit;if(!o)throw new TypeError("Loaded `@octokit/rest` but no `Octokit` export was found. Reinstall the package or pin to a supported major.");return new o({auth:e})},W=async(e,t,o)=>{if(o.gitlabClient)return o.gitlabClient;const i=(await(o.loadSdk??B)("@gitbeaker/rest")).Gitlab;if(!i)throw new TypeError("Loaded `@gitbeaker/rest` but no `Gitlab` export was found. Reinstall the package or pin to a supported major.");return new i({host:t,token:e})},z=e=>e.replace(/\/api\/v\d+\/?$/,""),X=async e=>{const{branch:t,ciContext:o,files:i,message:s,workspaceRoot:l}=e,d=e.readFile??(w=>$(w,"utf8"));if(!o.repo)throw new Error("Cannot commit on GitHub: GITHUB_REPOSITORY (owner/repo) is not set.");if(!o.token)throw new Error("Cannot commit on GitHub: GITHUB_TOKEN is not set. Grant the workflow `contents: write` and pass the token through.");const{owner:r,repo:n}=Y(o.repo),p=await J(o.token,e),u=(await p.rest.git.getRef({owner:r,ref:`heads/${t}`,repo:n})).data.object.sha,h=(await p.rest.git.getCommit({commit_sha:u,owner:r,repo:n})).data.tree.sha,m=await Promise.all(i.map(async w=>{const C=y(l,w),k=await d(C),b=await p.rest.git.createBlob({content:Buffer.from(k,"utf8").toString("base64"),encoding:"base64",owner:r,repo:n});return{mode:"100644",path:w,sha:b.data.sha,type:"blob"}})),f=await p.rest.git.createTree({base_tree:h,owner:r,repo:n,tree:m}),g=await p.rest.git.createCommit({message:s,owner:r,parents:[u],repo:n,tree:f.data.sha});return await p.rest.git.updateRef({owner:r,ref:`heads/${t}`,repo:n,sha:g.data.sha}),{sha:g.data.sha,url:g.data.html_url}},Q=async e=>{const{branch:t,ciContext:o,files:i,message:s,workspaceRoot:l}=e,d=e.readFile??(m=>$(m,"utf8"));if(!o.repo)throw new Error("Cannot commit on GitLab: CI_PROJECT_ID / CI_PROJECT_PATH is not set.");if(!o.token)throw new Error("Cannot commit on GitLab: no token. CI_JOB_TOKEN cannot push commits — set GITLAB_TOKEN to a PAT/project-token with `api` scope.");if(!o.apiBaseUrl)throw new Error("Cannot commit on GitLab: CI_API_V4_URL is not set.");const r=z(o.apiBaseUrl),n=await W(o.token,r,e),p=await Promise.all(i.map(async m=>{const f=y(l,m);return{action:"update",content:await d(f),filePath:m}})),u=await n.Commits.create(o.repo,t,s,p),h=u.id??u.sha;if(!h)throw new Error("GitLab Commits.create returned no commit ID — cannot reference the new commit.");return{sha:h,url:u.web_url??u.webUrl}},Z=async e=>{if(e.files.length===0)throw new Error("Cannot commit: no files to include.");if(e.ciContext.provider==="github-actions")return await X(e);if(e.ciContext.provider==="gitlab-ci")return await Q(e);throw new Error(`Cannot commit: unsupported CI provider \`${e.ciContext.provider}\`. Run \`vis ai heal accept\` from a recognised CI environment.`)},v="/vis heal accept",ee=async e=>{if(!e)return;let t;try{t=await $(e,"utf8")}catch{return}const o=JSON.parse(t),i=o.comment?.body??"",s=o.comment?.user?.login??"",l=o.pull_request?.head?.repo?.full_name,d=o.pull_request?.base?.repo?.full_name??o.repository?.full_name,r=l!==void 0&&d!==void 0&&l!==d;return{actor:s,body:i,headRef:o.pull_request?.head?.ref,isFork:r}},te=e=>{const t=e.VIS_HEAL_TRIGGER_BODY,o=e.VIS_HEAL_TRIGGER_ACTOR;if(!(!t||!o))return{actor:o,body:t,headRef:e.VIS_HEAL_HEAD_REF,isFork:!1}},oe=e=>{const t=e.BUILDKITE_UNBLOCKER_EMAIL??e.BUILDKITE_UNBLOCKER;if(t)return{actor:t,body:v,headRef:e.BUILDKITE_BRANCH,isFork:!1}},re=async(e,t)=>{if(e.provider==="github-actions")return await ee(t.GITHUB_EVENT_PATH);if(e.provider==="gitlab-ci")return te(t);if(e.provider==="buildkite")return oe(t)},ie=(e,t)=>{const o=t.BUILDKITE_REPO;if(!o)return;const i=/(?:^|@|\/\/)github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/i.exec(o);if(i&&t.GITHUB_TOKEN)return{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:e.prNumber,provider:"github-actions",repo:`${i[1]}/${i[2]}`,sha:e.sha,token:t.GITHUB_TOKEN};const s=/\/\/([^/]*gitlab[^/]*)\/([^/]+)\/(.+?)(?:\.git)?\/?$/i.exec(o),l=s?null:/@([^/:]*gitlab[^/:]*):([^/]+)\/(.+?)(?:\.git)?\/?$/i.exec(o),d=s??l;if(d&&t.GITLAB_TOKEN){const r=d[1];return{apiBaseUrl:t.CI_API_V4_URL??`https://${r}/api/v4`,buildId:void 0,buildNumber:void 0,prNumber:e.prNumber,provider:"gitlab-ci",repo:`${d[2]}/${d[3]}`,sha:e.sha,token:t.GITLAB_TOKEN}}},ae=async e=>{const t=e.fetchImpl??globalThis.fetch,o=`${(e.apiBaseUrl??"https://api.github.com").replace(/\/+$/,"")}/repos/${e.repo}/pulls/${String(e.prNumber)}`;try{const i=await t(o,{headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${e.token}`,"X-GitHub-Api-Version":"2022-11-28"}});return i.ok?(await i.json()).head?.ref:void 0}catch{return}},ne=(e,t,o,i)=>{const s=t.map(l=>`- \`${l}\``).join(`
@@ -1,4 +1,4 @@
1
- import{createRequire as S}from"node:module";import{s as B,j as U,E as I,V as P,I as L}from"../packem_shared/Table-CcVkyULl-B_ef6zfS.js";import{y as A}from"../packem_shared/index-BDmTbWX1.js";import{readLastRunSummary as O}from"@visulima/task-runner";import{a as j,r as G,b as K,c as D}from"../packem_shared/ai-fix-9Vzlp6XU.js";import{p as u,A as H}from"./bin.js";const R=S(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=e=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[t,o]=m.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return m.getBuiltinModule(e)}return R(e)},{spawn:h}=g("node:child_process"),{readFile:F}=g("node:fs/promises"),M=e=>{if(!e)return;const t=/^refs\/pull\/(\d+)\//.exec(e);return t?Number.parseInt(t[1],10):void 0},V=async e=>{if(!e)return{prNumber:void 0,sha:void 0};try{const t=await F(e,"utf8"),o=JSON.parse(t),r=o.pull_request?.number??o.issue?.number??o.number,i=o.pull_request?.head?.sha;return{prNumber:r,sha:i}}catch{return{prNumber:void 0,sha:void 0}}},J=async e=>{const t=M(e.GITHUB_REF),{prNumber:o,sha:r}=t===void 0?await V(e.GITHUB_EVENT_PATH):{prNumber:t,sha:void 0};return{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:t??o,provider:"github-actions",repo:e.GITHUB_REPOSITORY,sha:r??e.GITHUB_SHA,token:e.GITHUB_TOKEN}},q=e=>{const t=e.CI_MERGE_REQUEST_IID,o=t!==void 0&&t!==""?Number.parseInt(t,10):void 0,r=e.CI_API_V4_URL,i=e.GITLAB_TOKEN??e.CI_TOKEN;return{apiBaseUrl:r,buildId:void 0,buildNumber:void 0,prNumber:Number.isFinite(o)?o:void 0,provider:"gitlab-ci",repo:e.CI_PROJECT_ID??e.CI_PROJECT_PATH,sha:e.CI_COMMIT_SHA,token:i}},z=e=>{const t=e.BUILDKITE_PULL_REQUEST,o=t!==void 0&&t!==""&&t!=="false"?Number.parseInt(t,10):void 0,r=e.BUILDKITE_BUILD_NUMBER,i=r!==void 0&&r!==""?Number.parseInt(r,10):void 0,n=e.BUILDKITE_ORGANIZATION_SLUG,a=e.BUILDKITE_PIPELINE_SLUG,s=n!==void 0&&n!==""&&a!==void 0&&a!==""?`${n}/${a}`:void 0;return{apiBaseUrl:(e.BUILDKITE_API_BASE_URL??"https://api.buildkite.com").replace(/\/+$/,""),buildId:e.BUILDKITE_BUILD_ID,buildNumber:Number.isFinite(i)?i:void 0,prNumber:Number.isFinite(o)?o:void 0,provider:"buildkite",repo:s,sha:e.BUILDKITE_COMMIT,token:e.BUILDKITE_API_TOKEN}},Q=async(e=process.env)=>e.GITHUB_ACTIONS==="true"?await J(e):e.GITLAB_CI==="true"?q(e):e.BUILDKITE==="true"?z(e):{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:void 0,provider:"unknown",repo:void 0,sha:void 0,token:void 0},Y=(e,t,o,r)=>new Promise(i=>{const n=["pr","comment",String(t),"--body-file","-"];r&&n.push("--repo",r);const a=h(e,n,{stdio:["pipe","ignore","pipe"]});let s="";a.stderr?.setEncoding("utf8"),a.stderr?.on("data",d=>{s+=d}),a.once("error",()=>{i({exitCode:127,stderr:s})}),a.once("close",d=>{i({exitCode:d??-1,stderr:s})}),a.stdin?.on("error",()=>{}),a.stdin?.end(o)}),Z=async(e,t,o,r,i)=>{const n=`https://api.github.com/repos/${t}/issues/${String(o)}/comments`;try{const a=await e(n,{body:JSON.stringify({body:r}),headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${i}`,"Content-Type":"application/json","X-GitHub-Api-Version":"2022-11-28"},method:"POST"});if(!a.ok){const s=await a.text().catch(()=>"");return{error:`GitHub REST returned ${String(a.status)}: ${s.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(a){return{error:a instanceof Error?a.message:String(a),ok:!1}}},W=async(e,t,o,r,i,n)=>{const a=encodeURIComponent(o),s=`${t.replace(/\/+$/,"")}/projects/${a}/merge_requests/${String(r)}/notes`;try{const d=await e(s,{body:JSON.stringify({body:i}),headers:{"Content-Type":"application/json","PRIVATE-TOKEN":n},method:"POST"});if(!d.ok){const c=await d.text().catch(()=>"");return{error:`GitLab REST returned ${String(d.status)}: ${c.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(d){return{error:d instanceof Error?d.message:String(d),ok:!1}}},X=(e,t,o,r)=>new Promise(i=>{const n=h(e,["annotate","--style",o,"--context",r],{stdio:["pipe","ignore","pipe"]});let a="";n.stderr?.setEncoding("utf8"),n.stderr?.on("data",s=>{a+=s}),n.once("error",()=>{i({exitCode:127,stderr:a})}),n.once("close",s=>{i({exitCode:s??-1,stderr:a})}),n.stdin?.on("error",()=>{}),n.stdin?.end(t)}),tt=async(e,t,o,r,i,n,a,s)=>{const[d,c]=o.split("/",2);if(!d||!c)return{error:`Buildkite repo identifier \`${o}\` is not in {org}/{pipeline} form.`,ok:!1};const f=`${t}/v2/organizations/${encodeURIComponent(d)}/pipelines/${encodeURIComponent(c)}/builds/${String(r)}/annotations`;try{const p=await e(f,{body:JSON.stringify({body:i,context:a,style:n}),headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},method:"POST"});if(!p.ok){const l=await p.text().catch(()=>"");return{error:`Buildkite REST returned ${String(p.status)}: ${l.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(p){return{error:p instanceof Error?p.message:String(p),ok:!1}}},et=async(e,t,o,r)=>{const i=t.buildId?`vis-ai-heal-${t.buildId}`:"vis-ai-heal",n="info",a=await X(o,e,n,i);if(a.exitCode===0)return{method:"buildkite-cli",posted:!0};if(!t.apiBaseUrl||!t.repo||t.buildNumber===void 0||!t.token){const d=[];return t.repo||d.push("BUILDKITE_ORGANIZATION_SLUG / BUILDKITE_PIPELINE_SLUG"),t.buildNumber===void 0&&d.push("BUILDKITE_BUILD_NUMBER"),t.token||d.push("BUILDKITE_API_TOKEN (with `write_build_annotations` scope)"),{error:`buildkite-agent annotate exited ${String(a.exitCode)} (${a.stderr.trim().slice(0,200)}); cannot fall back to REST without ${d.join(", ")}`,method:"buildkite-cli",posted:!1}}const s=await tt(r,t.apiBaseUrl,t.repo,t.buildNumber,e,n,i,t.token);return s.ok?{method:"rest",posted:!0}:{error:`buildkite-agent annotate exited ${String(a.exitCode)}; REST fallback also failed: ${s.error??"unknown"}`,method:"rest",posted:!1}},ot=async(e,t,o,r)=>{if(t.prNumber===void 0)return{method:"skipped",posted:!1};const i=await Y(o,t.prNumber,e,t.repo);if(i.exitCode===0)return{method:"gh-cli",posted:!0};if(!t.repo||!t.token)return{error:`gh exited ${String(i.exitCode)} (${i.stderr.trim().slice(0,200)}); cannot fall back to REST without GITHUB_REPOSITORY + GITHUB_TOKEN`,method:"gh-cli",posted:!1};const n=await Z(r,t.repo,t.prNumber,e,t.token);return n.ok?{method:"rest",posted:!0}:{error:`gh exited ${String(i.exitCode)}; REST fallback also failed: ${n.error??"unknown"}`,method:"rest",posted:!1}},rt=async(e,t,o)=>{if(t.prNumber===void 0)return{method:"skipped",posted:!1};if(!t.apiBaseUrl||!t.repo)return{error:"GitLab CI context is missing CI_API_V4_URL or CI_PROJECT_ID; cannot post note.",method:"rest",posted:!1};if(!t.token)return{error:"GitLab CI context has no token. CI_JOB_TOKEN cannot post MR notes — set GITLAB_TOKEN to a personal/project access token with `api` scope.",method:"rest",posted:!1};const r=await W(o,t.apiBaseUrl,t.repo,t.prNumber,e,t.token);return r.ok?{method:"rest",posted:!0}:{error:r.error,method:"rest",posted:!1}},it=async e=>{const{body:t,buildkiteAgentBin:o="buildkite-agent",context:r,fetchImpl:i=globalThis.fetch,ghBin:n="gh"}=e;return r.provider==="github-actions"?await ot(t,r,n,i):r.provider==="gitlab-ci"?await rt(t,r,i):r.provider==="buildkite"?await et(t,r,o,i):{method:"skipped",posted:!1}},k=e=>{let t=0,o=0;for(const r of e)r.status==="applied"?t+=1:o+=1;return{applied:t,failed:o}},b=(e,t,o)=>{const r=D(e,t,o),i=A(e,r);return i===""||i.startsWith("..")?r:i},nt=(e,t,o,r)=>new Promise(i=>{const n=process.argv[1];if(!n){i({exitCode:-1,stderr:"Cannot locate vis bin (process.argv[1] missing).",stdout:""});return}const a=[n,"run",o,"--projects",t,"--no-cache","--summarize","--fail-fast"],s=h(process.execPath,a,{cwd:e,env:{...process.env,NO_COLOR:"1"},stdio:["ignore","pipe","pipe"]});let d="",c="";const f=setTimeout(()=>{s.kill("SIGTERM"),setTimeout(()=>s.kill("SIGKILL"),2e3).unref()},r);s.stdout?.setEncoding("utf8"),s.stdout?.on("data",p=>{d+=p}),s.stderr?.setEncoding("utf8"),s.stderr?.on("data",p=>{c+=p}),s.once("error",p=>{clearTimeout(f),i({exitCode:-1,stderr:p.message,stdout:d})}),s.once("close",p=>{clearTimeout(f),i({exitCode:p??-1,stderr:c,stdout:d})})}),at=6e4,T=e=>{let t=0;const o=e.match(/`{3,}/g);if(o)for(const r of o)t=Math.max(t,r.length);return"`".repeat(Math.max(3,t+1))},v=(e,t,o)=>{if(e.patches.length===0)return"_No patches proposed._";const r=[];for(const[i,n]of e.patches.entries()){const a=b(t,o,n.file),s=[`**[${String(i+1)}] \`${a}\`**`];n.reason&&s.push(`_${n.reason}_`);const d=T(`${n.oldString}
1
+ import{createRequire as S}from"node:module";import{s as B,j as U,E as I,V as P,I as L}from"../packem_shared/index.server-J83sowC4.js";import{y as A}from"../packem_shared/index-OQZQyN5R.js";import{readLastRunSummary as O}from"@visulima/task-runner";import{a as j,r as G,b as K,c as D}from"../packem_shared/ai-fix-Btd5AnSr.js";import{p as u,z as H}from"./cli-main.js";const R=S(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=e=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[t,o]=m.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return m.getBuiltinModule(e)}return R(e)},{spawn:h}=g("node:child_process"),{readFile:F}=g("node:fs/promises"),M=e=>{if(!e)return;const t=/^refs\/pull\/(\d+)\//.exec(e);return t?Number.parseInt(t[1],10):void 0},V=async e=>{if(!e)return{prNumber:void 0,sha:void 0};try{const t=await F(e,"utf8"),o=JSON.parse(t),r=o.pull_request?.number??o.issue?.number??o.number,i=o.pull_request?.head?.sha;return{prNumber:r,sha:i}}catch{return{prNumber:void 0,sha:void 0}}},J=async e=>{const t=M(e.GITHUB_REF),{prNumber:o,sha:r}=t===void 0?await V(e.GITHUB_EVENT_PATH):{prNumber:t,sha:void 0};return{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:t??o,provider:"github-actions",repo:e.GITHUB_REPOSITORY,sha:r??e.GITHUB_SHA,token:e.GITHUB_TOKEN}},q=e=>{const t=e.CI_MERGE_REQUEST_IID,o=t!==void 0&&t!==""?Number.parseInt(t,10):void 0,r=e.CI_API_V4_URL,i=e.GITLAB_TOKEN??e.CI_TOKEN;return{apiBaseUrl:r,buildId:void 0,buildNumber:void 0,prNumber:Number.isFinite(o)?o:void 0,provider:"gitlab-ci",repo:e.CI_PROJECT_ID??e.CI_PROJECT_PATH,sha:e.CI_COMMIT_SHA,token:i}},z=e=>{const t=e.BUILDKITE_PULL_REQUEST,o=t!==void 0&&t!==""&&t!=="false"?Number.parseInt(t,10):void 0,r=e.BUILDKITE_BUILD_NUMBER,i=r!==void 0&&r!==""?Number.parseInt(r,10):void 0,n=e.BUILDKITE_ORGANIZATION_SLUG,a=e.BUILDKITE_PIPELINE_SLUG,s=n!==void 0&&n!==""&&a!==void 0&&a!==""?`${n}/${a}`:void 0;return{apiBaseUrl:(e.BUILDKITE_API_BASE_URL??"https://api.buildkite.com").replace(/\/+$/,""),buildId:e.BUILDKITE_BUILD_ID,buildNumber:Number.isFinite(i)?i:void 0,prNumber:Number.isFinite(o)?o:void 0,provider:"buildkite",repo:s,sha:e.BUILDKITE_COMMIT,token:e.BUILDKITE_API_TOKEN}},Q=async(e=process.env)=>e.GITHUB_ACTIONS==="true"?await J(e):e.GITLAB_CI==="true"?q(e):e.BUILDKITE==="true"?z(e):{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:void 0,provider:"unknown",repo:void 0,sha:void 0,token:void 0},Y=(e,t,o,r)=>new Promise(i=>{const n=["pr","comment",String(t),"--body-file","-"];r&&n.push("--repo",r);const a=h(e,n,{stdio:["pipe","ignore","pipe"]});let s="";a.stderr?.setEncoding("utf8"),a.stderr?.on("data",d=>{s+=d}),a.once("error",()=>{i({exitCode:127,stderr:s})}),a.once("close",d=>{i({exitCode:d??-1,stderr:s})}),a.stdin?.on("error",()=>{}),a.stdin?.end(o)}),Z=async(e,t,o,r,i)=>{const n=`https://api.github.com/repos/${t}/issues/${String(o)}/comments`;try{const a=await e(n,{body:JSON.stringify({body:r}),headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${i}`,"Content-Type":"application/json","X-GitHub-Api-Version":"2022-11-28"},method:"POST"});if(!a.ok){const s=await a.text().catch(()=>"");return{error:`GitHub REST returned ${String(a.status)}: ${s.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(a){return{error:a instanceof Error?a.message:String(a),ok:!1}}},W=async(e,t,o,r,i,n)=>{const a=encodeURIComponent(o),s=`${t.replace(/\/+$/,"")}/projects/${a}/merge_requests/${String(r)}/notes`;try{const d=await e(s,{body:JSON.stringify({body:i}),headers:{"Content-Type":"application/json","PRIVATE-TOKEN":n},method:"POST"});if(!d.ok){const c=await d.text().catch(()=>"");return{error:`GitLab REST returned ${String(d.status)}: ${c.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(d){return{error:d instanceof Error?d.message:String(d),ok:!1}}},X=(e,t,o,r)=>new Promise(i=>{const n=h(e,["annotate","--style",o,"--context",r],{stdio:["pipe","ignore","pipe"]});let a="";n.stderr?.setEncoding("utf8"),n.stderr?.on("data",s=>{a+=s}),n.once("error",()=>{i({exitCode:127,stderr:a})}),n.once("close",s=>{i({exitCode:s??-1,stderr:a})}),n.stdin?.on("error",()=>{}),n.stdin?.end(t)}),tt=async(e,t,o,r,i,n,a,s)=>{const[d,c]=o.split("/",2);if(!d||!c)return{error:`Buildkite repo identifier \`${o}\` is not in {org}/{pipeline} form.`,ok:!1};const f=`${t}/v2/organizations/${encodeURIComponent(d)}/pipelines/${encodeURIComponent(c)}/builds/${String(r)}/annotations`;try{const p=await e(f,{body:JSON.stringify({body:i,context:a,style:n}),headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},method:"POST"});if(!p.ok){const l=await p.text().catch(()=>"");return{error:`Buildkite REST returned ${String(p.status)}: ${l.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(p){return{error:p instanceof Error?p.message:String(p),ok:!1}}},et=async(e,t,o,r)=>{const i=t.buildId?`vis-ai-heal-${t.buildId}`:"vis-ai-heal",n="info",a=await X(o,e,n,i);if(a.exitCode===0)return{method:"buildkite-cli",posted:!0};if(!t.apiBaseUrl||!t.repo||t.buildNumber===void 0||!t.token){const d=[];return t.repo||d.push("BUILDKITE_ORGANIZATION_SLUG / BUILDKITE_PIPELINE_SLUG"),t.buildNumber===void 0&&d.push("BUILDKITE_BUILD_NUMBER"),t.token||d.push("BUILDKITE_API_TOKEN (with `write_build_annotations` scope)"),{error:`buildkite-agent annotate exited ${String(a.exitCode)} (${a.stderr.trim().slice(0,200)}); cannot fall back to REST without ${d.join(", ")}`,method:"buildkite-cli",posted:!1}}const s=await tt(r,t.apiBaseUrl,t.repo,t.buildNumber,e,n,i,t.token);return s.ok?{method:"rest",posted:!0}:{error:`buildkite-agent annotate exited ${String(a.exitCode)}; REST fallback also failed: ${s.error??"unknown"}`,method:"rest",posted:!1}},ot=async(e,t,o,r)=>{if(t.prNumber===void 0)return{method:"skipped",posted:!1};const i=await Y(o,t.prNumber,e,t.repo);if(i.exitCode===0)return{method:"gh-cli",posted:!0};if(!t.repo||!t.token)return{error:`gh exited ${String(i.exitCode)} (${i.stderr.trim().slice(0,200)}); cannot fall back to REST without GITHUB_REPOSITORY + GITHUB_TOKEN`,method:"gh-cli",posted:!1};const n=await Z(r,t.repo,t.prNumber,e,t.token);return n.ok?{method:"rest",posted:!0}:{error:`gh exited ${String(i.exitCode)}; REST fallback also failed: ${n.error??"unknown"}`,method:"rest",posted:!1}},rt=async(e,t,o)=>{if(t.prNumber===void 0)return{method:"skipped",posted:!1};if(!t.apiBaseUrl||!t.repo)return{error:"GitLab CI context is missing CI_API_V4_URL or CI_PROJECT_ID; cannot post note.",method:"rest",posted:!1};if(!t.token)return{error:"GitLab CI context has no token. CI_JOB_TOKEN cannot post MR notes — set GITLAB_TOKEN to a personal/project access token with `api` scope.",method:"rest",posted:!1};const r=await W(o,t.apiBaseUrl,t.repo,t.prNumber,e,t.token);return r.ok?{method:"rest",posted:!0}:{error:r.error,method:"rest",posted:!1}},it=async e=>{const{body:t,buildkiteAgentBin:o="buildkite-agent",context:r,fetchImpl:i=globalThis.fetch,ghBin:n="gh"}=e;return r.provider==="github-actions"?await ot(t,r,n,i):r.provider==="gitlab-ci"?await rt(t,r,i):r.provider==="buildkite"?await et(t,r,o,i):{method:"skipped",posted:!1}},k=e=>{let t=0,o=0;for(const r of e)r.status==="applied"?t+=1:o+=1;return{applied:t,failed:o}},b=(e,t,o)=>{const r=D(e,t,o),i=A(e,r);return i===""||i.startsWith("..")?r:i},nt=(e,t,o,r)=>new Promise(i=>{const n=process.argv[1];if(!n){i({exitCode:-1,stderr:"Cannot locate vis bin (process.argv[1] missing).",stdout:""});return}const a=[n,"run",o,"--projects",t,"--no-cache","--summarize","--fail-fast"],s=h(process.execPath,a,{cwd:e,env:{...process.env,NO_COLOR:"1"},stdio:["ignore","pipe","pipe"]});let d="",c="";const f=setTimeout(()=>{s.kill("SIGTERM"),setTimeout(()=>s.kill("SIGKILL"),2e3).unref()},r);s.stdout?.setEncoding("utf8"),s.stdout?.on("data",p=>{d+=p}),s.stderr?.setEncoding("utf8"),s.stderr?.on("data",p=>{c+=p}),s.once("error",p=>{clearTimeout(f),i({exitCode:-1,stderr:p.message,stdout:d})}),s.once("close",p=>{clearTimeout(f),i({exitCode:p??-1,stderr:c,stdout:d})})}),at=6e4,T=e=>{let t=0;const o=e.match(/`{3,}/g);if(o)for(const r of o)t=Math.max(t,r.length);return"`".repeat(Math.max(3,t+1))},v=(e,t,o)=>{if(e.patches.length===0)return"_No patches proposed._";const r=[];for(const[i,n]of e.patches.entries()){const a=b(t,o,n.file),s=[`**[${String(i+1)}] \`${a}\`**`];n.reason&&s.push(`_${n.reason}_`);const d=T(`${n.oldString}
2
2
  ${n.newString}`);s.push(`${d}diff`);for(const c of n.oldString.split(`
3
3
  `))s.push(`- ${c}`);for(const c of n.newString.split(`
4
4
  `))s.push(`+ ${c}`);s.push(d),r.push(s.join(`