@visulima/vis 1.0.0-alpha.43 → 1.0.0-alpha.45

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 (156) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/LICENSE.md +256 -0
  3. package/bin/resolve-binary.mjs +85 -0
  4. package/bin/vis.mjs +76 -0
  5. package/dist/bin.d.ts +1 -0
  6. package/dist/bin.js +1 -2
  7. package/dist/binx.js +1 -1
  8. package/dist/packem_chunks/CONFIG_FILES.js +1 -1
  9. package/dist/packem_chunks/bloom-status.js +1 -1
  10. package/dist/packem_chunks/bloom-sync.js +1 -1
  11. package/dist/packem_chunks/catalog.js +63 -62
  12. package/dist/packem_chunks/cli-exec.js +1 -1
  13. package/dist/packem_chunks/cli-main.js +173 -973
  14. package/dist/packem_chunks/detect.js +1 -1
  15. package/dist/packem_chunks/dispatch.js +1 -1
  16. package/dist/packem_chunks/fix.js +1 -1
  17. package/dist/packem_chunks/handler.js +1 -1
  18. package/dist/packem_chunks/handler10.js +1 -1
  19. package/dist/packem_chunks/handler11.js +1 -1
  20. package/dist/packem_chunks/handler12.js +2 -2
  21. package/dist/packem_chunks/handler13.js +1 -1
  22. package/dist/packem_chunks/handler14.js +1 -1
  23. package/dist/packem_chunks/handler15.js +1 -1
  24. package/dist/packem_chunks/handler16.js +1 -1
  25. package/dist/packem_chunks/handler17.js +1 -1
  26. package/dist/packem_chunks/handler18.js +1 -1
  27. package/dist/packem_chunks/handler19.js +1 -1
  28. package/dist/packem_chunks/handler2.js +1 -1
  29. package/dist/packem_chunks/handler20.js +1 -1
  30. package/dist/packem_chunks/handler21.js +1 -1
  31. package/dist/packem_chunks/handler22.js +13 -4
  32. package/dist/packem_chunks/handler23.js +1 -1
  33. package/dist/packem_chunks/handler24.js +1 -1
  34. package/dist/packem_chunks/handler26.js +1 -1
  35. package/dist/packem_chunks/handler27.js +1 -1
  36. package/dist/packem_chunks/handler28.js +1 -1
  37. package/dist/packem_chunks/handler29.js +1 -1
  38. package/dist/packem_chunks/handler3.js +1 -1
  39. package/dist/packem_chunks/handler30.js +1 -1
  40. package/dist/packem_chunks/handler4.js +1 -1
  41. package/dist/packem_chunks/handler5.js +3 -3
  42. package/dist/packem_chunks/handler50.js +4 -4
  43. package/dist/packem_chunks/handler51.js +3 -3
  44. package/dist/packem_chunks/handler53.js +1 -1
  45. package/dist/packem_chunks/handler54.js +2 -2
  46. package/dist/packem_chunks/handler55.js +1 -1
  47. package/dist/packem_chunks/handler57.js +4 -4
  48. package/dist/packem_chunks/handler58.js +1 -1
  49. package/dist/packem_chunks/handler59.js +2 -2
  50. package/dist/packem_chunks/handler6.js +6 -6
  51. package/dist/packem_chunks/handler60.js +18 -18
  52. package/dist/packem_chunks/handler61.js +1 -1
  53. package/dist/packem_chunks/handler62.js +3 -3
  54. package/dist/packem_chunks/handler63.js +4 -4
  55. package/dist/packem_chunks/handler65.js +2 -2
  56. package/dist/packem_chunks/handler66.js +15 -15
  57. package/dist/packem_chunks/handler67.js +5 -5
  58. package/dist/packem_chunks/handler68.js +16 -16
  59. package/dist/packem_chunks/handler69.js +5 -5
  60. package/dist/packem_chunks/handler7.js +1 -1
  61. package/dist/packem_chunks/handler70.js +16 -17
  62. package/dist/packem_chunks/handler71.js +2 -2
  63. package/dist/packem_chunks/handler72.js +2 -2
  64. package/dist/packem_chunks/handler73.js +13 -13
  65. package/dist/packem_chunks/handler74.js +3 -3
  66. package/dist/packem_chunks/handler75.js +3 -3
  67. package/dist/packem_chunks/handler76.js +63 -63
  68. package/dist/packem_chunks/handler77.js +1 -1
  69. package/dist/packem_chunks/handler8.js +1 -1
  70. package/dist/packem_chunks/handler9.js +1 -1
  71. package/dist/packem_chunks/heal-accept.js +1 -1
  72. package/dist/packem_chunks/heal.js +1 -1
  73. package/dist/packem_chunks/help-command.js +1 -1
  74. package/dist/packem_chunks/index2.js +802 -7
  75. package/dist/packem_chunks/index3.js +7 -135
  76. package/dist/packem_chunks/index4.js +134 -73
  77. package/dist/packem_chunks/index5.js +74 -0
  78. package/dist/packem_chunks/keys-refresh.js +1 -1
  79. package/dist/packem_chunks/lean.js +3 -3
  80. package/dist/packem_chunks/list.js +1 -1
  81. package/dist/packem_chunks/loader.js +1 -1
  82. package/dist/packem_chunks/loader2.js +1 -1
  83. package/dist/packem_chunks/print-config.js +1 -1
  84. package/dist/packem_chunks/registry.js +2 -2
  85. package/dist/packem_chunks/shell-runner.js +1 -1
  86. package/dist/packem_chunks/sync.js +1 -1
  87. package/dist/packem_chunks/sync2.js +1 -1
  88. package/dist/packem_chunks/tripwire.js +2 -2
  89. package/dist/packem_chunks/ts-loader.js +22 -2
  90. package/dist/packem_chunks/verify-lockfile.js +1 -1
  91. package/dist/packem_chunks/version-resolver.js +2 -2
  92. package/dist/packem_shared/{Table-CcVkyULl-DLWu6XHL.js → Table-BGIHvenQ-D2oJtNQj.js} +1 -1
  93. package/dist/packem_shared/affected-shas-CCxG4tvm.js +1 -0
  94. package/dist/packem_shared/{ai-analysis-Co-b15d_.js → ai-analysis-rC48NLfB.js} +5 -5
  95. package/dist/packem_shared/{ai-fix-DnJDgPN-.js → ai-fix-D_ijV3Rn.js} +3 -3
  96. package/dist/packem_shared/augment-DaSS2Lgs.js +4 -0
  97. package/dist/packem_shared/bin-CPMo34SM.js +1 -0
  98. package/dist/packem_shared/{build-scripts-Doxce2VM.js → build-scripts-MTSK6TNr.js} +1 -1
  99. package/dist/packem_shared/{command-runtime-RiCMa2C8.js → command-runtime-3FTGuUsK.js} +1 -1
  100. package/dist/packem_shared/{cyclonedx-BTBzGCBW.js → cyclonedx-BeUmPgfO.js} +1 -1
  101. package/dist/packem_shared/{dependency-scan-DEv-scN6.js → dependency-scan-DpOFiZuI.js} +1 -1
  102. package/dist/packem_shared/{docker-DKlF-gk3.js → docker-CViFYtmM.js} +1 -1
  103. package/dist/packem_shared/{env-XJzocuUP.js → env-Ct3hMEYB.js} +2 -2
  104. package/dist/packem_shared/{failure-log-Sp1j-5qo.js → failure-log-Dy2G-rKi.js} +1 -1
  105. package/dist/packem_shared/glob-fqg4KepW-1S3z30c8.js +1 -0
  106. package/dist/packem_shared/index-CE6MsgcV.js +22 -0
  107. package/dist/packem_shared/{index-CkZnT2Fe.js → index-Cntyu-w8.js} +1 -1
  108. package/dist/packem_shared/{index-DJAnbLEh.js → index-XAb0QGqA.js} +1 -1
  109. package/dist/packem_shared/{lifecycle-C4nRsXxc.js → lifecycle-CHcFuWf_.js} +1 -1
  110. package/dist/packem_shared/{lockfile-DIGyLfmF.js → lockfile-C1qCKGH6.js} +1 -1
  111. package/dist/packem_shared/{manifests-pLwnVmCN.js → manifests-WBnsV_Eb.js} +1 -1
  112. package/dist/packem_shared/{min-release-age-B23Mr7NO.js → min-release-age-C71MO72F.js} +1 -1
  113. package/dist/packem_shared/{missing-package-json-DdMNbe_j.js → missing-package-json-CTF71tE5.js} +1 -1
  114. package/dist/packem_shared/{native-config-sync-4K9wWTj5.js → native-config-sync-BFDVK9LH.js} +4 -4
  115. package/dist/packem_shared/{osv-bloom-BsQ-aFiM.js → osv-bloom-DVMlkcAO.js} +2 -2
  116. package/dist/packem_shared/{packument-QjOLAMSk.js → packument-C-A3Uhhx.js} +1 -1
  117. package/dist/packem_shared/pm-runner-CQcraCcu.js +1 -0
  118. package/dist/packem_shared/{provenance-CilBg0Ee.js → provenance-R2csDSNg.js} +1 -1
  119. package/dist/packem_shared/readJsonSync-CvkZyKmL-ihoybKvs.js +1 -0
  120. package/dist/packem_shared/{registry-keys-BEavOCPz.js → registry-keys-CMnS_Qt_.js} +1 -1
  121. package/dist/packem_shared/{resolve-explicit-C4o8_-SE.js → resolve-explicit-C4oQMyoB.js} +1 -1
  122. package/dist/packem_shared/resolve-runtime-QRaQucfL.js +1 -0
  123. package/dist/packem_shared/run-file-DD7Ne23Z.js +1 -0
  124. package/dist/packem_shared/{runtime-check-0lUJvgKt.js → runtime-check-BXehSP06.js} +1 -1
  125. package/dist/packem_shared/{s1ngularity-DuG-LLaX.js → s1ngularity-BCDt28u0.js} +1 -1
  126. package/dist/packem_shared/scan-progress-YRpDs90j.js +2 -0
  127. package/dist/packem_shared/{selectors-UmnAuc26.js → selectors-D4iCvITE.js} +1 -1
  128. package/dist/packem_shared/{signatures-CYheSqd3.js → signatures-B3srzCEv.js} +1 -1
  129. package/dist/packem_shared/target-options-CR0OuYJr.js +1 -0
  130. package/dist/packem_shared/toolchain-C44mPKPu.js +5 -0
  131. package/dist/packem_shared/{typosquats-hCtH-23t.js → typosquats-CQz-1Y6K.js} +1 -1
  132. package/dist/packem_shared/use-measured-height-DHi0xOPO.js +1 -0
  133. package/dist/packem_shared/utils-CRueU43T.js +1 -0
  134. package/dist/packem_shared/verify-DStfg3nb.js +1 -0
  135. package/dist/packem_shared/{vis-update-app-K-qATSeh.js → vis-update-app-B3I14Vfy.js} +1 -1
  136. package/dist/packem_shared/{watch-Bkp_AAbc.js → watch-BXNI7dC6.js} +1 -1
  137. package/dist/packem_shared/{watch-loop-WE7nWIEt.js → watch-loop-JfGKIgKB.js} +1 -1
  138. package/dist/runtime/preload.js +1 -1
  139. package/index.js +52 -52
  140. package/package.json +18 -14
  141. package/dist/packem_shared/affected-shas-C1XuRlvo.js +0 -1
  142. package/dist/packem_shared/augment-8fIWWGSc.js +0 -3
  143. package/dist/packem_shared/bin-DDq2oszw.js +0 -1
  144. package/dist/packem_shared/glob-fqg4KepW-7Bs2kZuM.js +0 -1
  145. package/dist/packem_shared/index-OQZQyN5R.js +0 -19
  146. package/dist/packem_shared/pm-runner-CIH0wPh-.js +0 -1
  147. package/dist/packem_shared/readJsonSync-CvkZyKmL-CY7PZob_.js +0 -4
  148. package/dist/packem_shared/resolve-runtime-CJSWV-K8.js +0 -1
  149. package/dist/packem_shared/run-file-B4TqKa0X.js +0 -1
  150. package/dist/packem_shared/scan-progress-RTMsE3Z4.js +0 -2
  151. package/dist/packem_shared/target-options-ChWcK60i.js +0 -1
  152. package/dist/packem_shared/toolchain-DyCKnGch.js +0 -5
  153. package/dist/packem_shared/use-measured-height-BKUjhm_3.js +0 -1
  154. package/dist/packem_shared/utils-Cxree603.js +0 -1
  155. package/dist/packem_shared/verify-CVPYlUrF.js +0 -1
  156. package/dist/packem_shared/window-ops-DDePlWLV.js +0 -2
@@ -1,61 +1,61 @@
1
- import{createRequire as er}from"node:module";import{m as oe,H as ys,J as sr,T as vs,v as rr,l as ir}from"../packem_shared/index-OQZQyN5R.js";import{buildEnhancedPath as nr,enforceProjectConstraints as or,expandTokensInString as qt,parsePartition as ar,TaskScheduler as cr,createTaskGraph as lr,reverseTaskGraph as dr,resolveTurboEnvCompat as ur,CompositeLifeCycle as Ut,defaultTaskRunner as Ht,createLogReporter as hr,readLastRunSummary as fr,getLastRunSummaryPath as pr,runConcurrently as Qe,generateRunSummary as zt,writeChromeTrace as gr,writeRunSummary as mr,TerminalBuffer as ft}from"@visulima/task-runner";import{I as Ve}from"../packem_shared/index-B0EsgdzO.js";import{V as xs,X as wr,U as yr,y as Vt,Y as vr,Z as xr,_ as kr,aj as jr,b as $r,ak as br,al as Sr,am as Tr,an as Cr}from"./cli-main.js";import{r as W,m as i,n as m,i as c,h as pe,c as K,$ as Ir,C as Rr,b as Er,O as Mr}from"./catalog.js";import{d as Fr,r as Or}from"../packem_shared/lockfile-DIGyLfmF.js";import{a as js}from"../packem_shared/public-api-WqUCiyIe.js";import{F as Gr}from"../packem_shared/failure-log-Sp1j-5qo.js";import{r as _r}from"../packem_shared/command-runtime-RiCMa2C8.js";import{r as qr}from"../packem_shared/toolchain-DyCKnGch.js";import{i as Ur,r as Hr,s as zr,a as Vr,c as Wr,d as Yr,e as Jr,H as Kr,f as Xr,b as Qr}from"../packem_shared/lifecycle-C4nRsXxc.js";import{p as Zr,r as ei,f as ti}from"../packem_shared/selectors-UmnAuc26.js";import{r as nt,l as gt,d as si,s as ri,m as ii,a as ni}from"../packem_shared/target-options-ChWcK60i.js";import{o as oi,m as ai,c as Ze}from"../packem_shared/env-XJzocuUP.js";import"../packem_shared/window-ops-DDePlWLV.js";import{T as $s,C as bs,D as ot,E as Ss}from"../packem_shared/symbols-DPTlrJ3B.js";import{V as lt,E as Jt,q as fi,j as pi}from"../packem_shared/index.server-J83sowC4.js";import{parseStacktrace as gi,codeFrame as mi}from"@visulima/error";import{originalPositionFor as wi,sourceContentFor as yi,loadSourceMap as vi}from"@visulima/source-map";import{o as Ts}from"../packem_shared/spinner-DuJJvFTl.js";import{c as Kt,a as bi,s as Xt}from"../packem_shared/watch-Bkp_AAbc.js";const tr=er(import.meta.url),ze=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Ee=s=>{if(typeof ze<"u"&&ze.versions&&ze.versions.node){const[e,t]=ze.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return ze.getBuiltinModule(s)}return tr(s)},{existsSync:Ae,mkdirSync:Pr,writeFileSync:pt,readFileSync:Ge,openSync:Ar,statSync:Wt,readSync:Dr,closeSync:Lr,mkdtempSync:Br}=Ee("node:fs"),{createInterface:ks,emitKeypressEvents:Nr}=Ee("node:readline"),{spawn:ci}=Ee("node:child_process"),{isAbsolute:li,resolve:Yt,dirname:di,relative:ui}=Ee("node:path"),{fileURLToPath:hi}=Ee("node:url"),{createHash:xi}=Ee("node:crypto"),{mkdir:ki,appendFile:at}=Ee("node:fs/promises"),{platform:ji,homedir:mt,tmpdir:$i}=Ee("node:os"),Cs=s=>s===155||s===157||s===144||s===152||s===158||s===159,Is=(s,e)=>{for(let t=e;t<s.length;t+=1){const r=s.codePointAt(t);if(r>=64&&r<=126)return t}return-1},et=(s,e,t)=>{for(let r=e;r<s.length;r+=1){const o=s.codePointAt(r);if(o===156||t&&o===7)return r;if(o===27&&s.codePointAt(r+1)===92)return r+1}return-1},Si=(s,e)=>{const t=s.codePointAt(e+1);return t===91?Is(s,e+2):t===93?et(s,e+2,!0):t===80||t===88||t===94||t===95?et(s,e+2,!1):t!==void 0?e+1:-1},Ti=(s,e)=>{const t=s.codePointAt(e);return t===155?Is(s,e+1):t===157?et(s,e+1,!0):t===144||t===152||t===158||t===159?et(s,e+1,!1):-1},Ci=s=>{if(s.includes(String.fromCodePoint(27)))return!0;for(let e=0;e<s.length;e+=1)if(Cs(s.codePointAt(e)))return!0;return!1},Ii=s=>{if(!Ci(s))return s;let e="",t=0,r=0;const{length:o}=s;for(;r<o;){const a=s.codePointAt(r);let n;if(a===27)n=Si(s,r);else if(Cs(a))n=Ti(s,r);else{r+=1;continue}n===-1&&(n=o-1),e+=s.slice(t,r),t=n+1,r=n+1}return e+=s.slice(t),e},Qt=new WeakSet,Ri=s=>{if(Qt.has(s))return;const e=["y","mo","w","d","h","m","s","ms","future","past"];for(const r of e)if(!Object.hasOwn(s,r))throw new TypeError(`Missing required property: ${r}`);if(typeof s.future!="string"||typeof s.past!="string")throw new TypeError("Properties future and past must be of type string");const t=["y","mo","w","d","h","m","s","ms"];for(const r of t)if(typeof s[r]!="string"&&typeof s[r]!="function")throw new TypeError(`Property ${r} must be of type string or function`);if(s.decimal&&typeof s.decimal!="string")throw new TypeError("Property decimal must be of type string");if(s.delimiter&&typeof s.delimiter!="string")throw new TypeError("Property delimiter must be of type string");if(s._digitReplacements&&!Array.isArray(s._digitReplacements))throw new TypeError("Property _digitReplacements must be an array");if(s._numberFirst&&typeof s._numberFirst!="boolean")throw new TypeError("Property _numberFirst must be of type boolean");if(s.unitMap&&typeof s.unitMap!="object")throw new TypeError("Property unitMap must be an object");if(s.unitMap&&Object.values(s.unitMap).some(r=>typeof r!="string"))throw new TypeError("All values in unitMap must be of type string");Qt.add(s)},Rs=(s,e)=>{e=e||-1;const t=new RegExp(String.raw`^-?\d+(?:\.\d{0,${String(e)}})?`).exec(s.toString());return t===null?s:Number.parseFloat(t[0])},Zt=({unitCount:s,unitName:e},t,r)=>{let{spacer:o}=r;const{maxDecimalPoints:a}=r;let n=".";r.decimal!==void 0?n=r.decimal:t.decimal!==void 0&&(n=t.decimal);let d;"digitReplacements"in r?d=r.digitReplacements:"_digitReplacements"in t&&(d=t._digitReplacements);let h,f=s;a!==void 0&&(f=Rs(s,a));const u=f.toString();if(!t._hideCountIf2||s!==2)if(d){h="";for(const $ of u)h+=$==="."?n:d[$]}else h=u.replace(".",n);else h="";const p=t[e];let l=p;return typeof p=="function"&&(l=p(s)),t._hideCountIf2&&s===2&&(o=""),t._numberFirst?l+o+h:h+o+l},Ei=(s,e)=>{const{units:t}=e;if(t.length===0)return[];const{unitMeasures:r}=e,o=e.largest??Number.POSITIVE_INFINITY,a={};let n,d,h,f=s;for(d=0;d<t.length;d++){n=t[d];const p=r[n];h=d===t.length-1?f/p:Math.floor(f/p),a[n]=h,f-=h*p}if(e.round){let p=o;for(d=0;d<t.length;d++)if(n=t[d],h=a[n],h!==0&&(p--,p===0)){for(let l=d+1;l<t.length;l++){const $=t[l],I=a[$];a[n]=(a[n]??0)+I*r[$]/r[n],a[$]=0}break}for(d=t.length-1;d>=0;d--){if(n=t[d],h=a[n],h===0)continue;const l=Math.round(h);if(a[n]=l,d===0)break;const $=t[d-1],I=r[$],G=Math.floor(l*r[n]/I);if(G)a[$]=(a[$]??0)+G,a[n]=0;else break}}const u=[];for(d=0;d<t.length&&u.length<o;d++){if(n=t[d],h=a[n],h&&!e.round&&u.length===o-1){let p,l=0;for(p=d+1,t.length;p<t.length;p++){const $=t[p];l+=a[$]*(e.unitMeasures[$]/e.unitMeasures[n])}h+=l,e.maxDecimalPoints!==void 0&&(h=Rs(h,e.maxDecimalPoints))}h&&u.push({unitCount:h,unitName:n})}return u},Mi=(s,e,t)=>{const{language:r,units:o}=e;if(s.length===0){const p=o.at(-1);return Zt({unitCount:0,unitName:p},r,e)}const{conjunction:a,serialComma:n}=e;let d=", ";e.delimiter!==void 0?d=e.delimiter:r.delimiter!==void 0&&(d=r.delimiter);let h="";e.timeAdverb&&t!==0&&(h=r.future??"",t<0&&(h=r.past??""));const f=s.map(p=>Zt(p,r,e));let u;return!a||s.length===1?u=f.join(d):s.length===2?u=f.join(a):u=f.slice(0,-1).join(d)+(n?",":"")+a+(f.at(-1)??""),h&&(u=h.replace("%s",u)),u},Fi=(s,e)=>{if(Number.isNaN(s))throw new TypeError("Expected a valid number");if(typeof s!="number")throw new TypeError("Expected a number for milliseconds input");const t={conjunction:"",language:oi,round:!1,serialComma:!0,spacer:" ",timeAdverb:!1,unitMeasures:{d:864e5,h:36e5,m:6e4,mo:2629746e3,ms:1,s:1e3,w:6048e5,y:31556952e3},units:["w","d","h","m","s"],...e};Ri(t.language);const r=Math.abs(s),o=Ei(r,t);return Mi(o,t,s)},je="@voidzero-dev/vite-task-client",wt="@visulima/task-runner-client",tt=`npm:${wt}@^1`,Es=oe(".vis",".vite-client-override-declined"),st="pnpm-workspace.yaml",Oi=["dependencies","devDependencies","optionalDependencies","peerDependencies"],Ms=s=>{try{return JSON.parse(Ge(s,"utf8"))}catch{return}},Pi=s=>{const e=oe(s,st);if(Ae(e))try{return js(Ge(e,"utf8")).toJS()?.overrides}catch{return}},Ai=s=>s==="pnpm"||s==="aube"?"pnpm.overrides":s==="yarn"?"resolutions":"overrides",Di=s=>{const e=oe(s,st);try{const t=js(Ge(e,"utf8"));return t.setIn(["overrides",je],tt),pt(e,t.toString()),!0}catch{return!1}},es=s=>s!==void 0&&Oi.some(e=>s[e]?.[je]!==void 0),Li=(s,e)=>s!==void 0&&(s.pnpm?.overrides?.[je]!==void 0||s.overrides?.[je]!==void 0||s.resolutions?.[je]!==void 0)||e?.[je]!==void 0,Bi=(s,e=[])=>{const t=Ms(oe(s,"package.json")),r=Ae(oe(s,"node_modules","@voidzero-dev","vite-task-client"));return{alreadyOverridden:Li(t,Pi(s)),declined:Ae(oe(s,Es)),manager:Fr(s)?.manager,present:es(t)||r||e.some(o=>es(o))}},Ni=s=>{try{const e=oe(s,Es);Pr(ys(e),{recursive:!0}),pt(e,`Declined adding the ${je} → ${wt} override.
1
+ import{createRequire as rr}from"node:module";import{m as oe,H as js,J as nr,y as or,T as $s,v as ar,l as cr}from"../packem_shared/index-CE6MsgcV.js";import{expandAffected as lr,getChangedFiles as dr,buildEnhancedPath as ur,enforceProjectConstraints as hr,expandTokensInString as Ht,parsePartition as fr,TaskScheduler as pr,createTaskGraph as gr,reverseTaskGraph as mr,resolveTurboEnvCompat as wr,CompositeLifeCycle as zt,defaultTaskRunner as Yt,createLogReporter as yr,readLastRunSummary as vr,getLastRunSummaryPath as kr,runConcurrently as Qe,generateRunSummary as Jt,writeChromeTrace as xr,writeRunSummary as jr,TerminalBuffer as mt}from"@visulima/task-runner";import{I as He}from"../packem_shared/index-B0EsgdzO.js";import{T as bs,U as $r,Q as br,y as Kt,V as Sr,W as Tr,X as Cr,al as Ir,b as Rr,am as Er,an as Mr,ao as Fr,ap as Or}from"./cli-main.js";import{r as z,m as n,n as m,i as c,h as he,d as K,$ as Pr,C as Ar,b as Dr,O as Lr}from"./catalog.js";import{d as Br,r as Nr}from"../packem_shared/lockfile-C1qCKGH6.js";import{a as Ts}from"../packem_shared/public-api-WqUCiyIe.js";import{F as Hr}from"../packem_shared/failure-log-Dy2G-rKi.js";import{r as zr}from"../packem_shared/command-runtime-3FTGuUsK.js";import{r as Yr}from"../packem_shared/toolchain-C44mPKPu.js";import{i as Jr,r as Kr,s as Xr,a as Qr,c as Zr,d as ei,e as ti,H as si,f as ri,b as ii}from"../packem_shared/lifecycle-CHcFuWf_.js";import{p as ni,r as oi,f as ai}from"../packem_shared/selectors-D4iCvITE.js";import{r as nt,l as yt,d as ci,s as li,m as di,a as ui}from"../packem_shared/target-options-CR0OuYJr.js";import{o as hi,m as fi,c as Ze}from"../packem_shared/env-Ct3hMEYB.js";import{T as Cs,C as Is,D as ot,E as Rs}from"../packem_shared/symbols-DPTlrJ3B.js";import{V as dt,E as Zt,q as vi,j as ki}from"../packem_shared/index.server-J83sowC4.js";import{parseStacktrace as xi,codeFrame as ji}from"@visulima/error";import{originalPositionFor as $i,sourceContentFor as bi,loadSourceMap as Si}from"@visulima/source-map";import{o as Es}from"../packem_shared/spinner-DuJJvFTl.js";import{c as es,a as Ei,s as ts}from"../packem_shared/watch-BXNI7dC6.js";import ft from"./index.js";const ir=rr(import.meta.url),Ve=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Ee=s=>{if(typeof Ve<"u"&&Ve.versions&&Ve.versions.node){const[e,t]=Ve.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return Ve.getBuiltinModule(s)}return ir(s)},{existsSync:Ae,mkdirSync:Gr,writeFileSync:wt,readFileSync:Ge,openSync:_r,statSync:Xt,readSync:qr,closeSync:Wr,mkdtempSync:Ur}=Ee("node:fs"),{createInterface:Ss,emitKeypressEvents:Vr}=Ee("node:readline"),{spawn:pi}=Ee("node:child_process"),{isAbsolute:gi,resolve:Qt,dirname:mi,relative:wi}=Ee("node:path"),{fileURLToPath:yi}=Ee("node:url"),{createHash:Ti}=Ee("node:crypto"),{mkdir:Ci,appendFile:at}=Ee("node:fs/promises"),{platform:Ii,homedir:vt,tmpdir:Ri}=Ee("node:os"),ss=new WeakSet,Mi=s=>{if(ss.has(s))return;const e=["y","mo","w","d","h","m","s","ms","future","past"];for(const r of e)if(!Object.hasOwn(s,r))throw new TypeError(`Missing required property: ${r}`);if(typeof s.future!="string"||typeof s.past!="string")throw new TypeError("Properties future and past must be of type string");const t=["y","mo","w","d","h","m","s","ms"];for(const r of t)if(typeof s[r]!="string"&&typeof s[r]!="function")throw new TypeError(`Property ${r} must be of type string or function`);if(s.decimal&&typeof s.decimal!="string")throw new TypeError("Property decimal must be of type string");if(s.delimiter&&typeof s.delimiter!="string")throw new TypeError("Property delimiter must be of type string");if(s._digitReplacements&&!Array.isArray(s._digitReplacements))throw new TypeError("Property _digitReplacements must be an array");if(s._numberFirst&&typeof s._numberFirst!="boolean")throw new TypeError("Property _numberFirst must be of type boolean");if(s.unitMap&&typeof s.unitMap!="object")throw new TypeError("Property unitMap must be an object");if(s.unitMap&&Object.values(s.unitMap).some(r=>typeof r!="string"))throw new TypeError("All values in unitMap must be of type string");ss.add(s)},Ms=(s,e)=>{e=e||-1;const t=new RegExp(String.raw`^-?\d+(?:\.\d{0,${String(e)}})?`).exec(s.toString());return t===null?s:Number.parseFloat(t[0])},rs=({unitCount:s,unitName:e},t,r)=>{let{spacer:o}=r;const{maxDecimalPoints:a}=r;let i=".";r.decimal!==void 0?i=r.decimal:t.decimal!==void 0&&(i=t.decimal);let d;"digitReplacements"in r?d=r.digitReplacements:"_digitReplacements"in t&&(d=t._digitReplacements);let u,f=s;a!==void 0&&(f=Ms(s,a));const h=f.toString();if(!t._hideCountIf2||s!==2)if(d){u="";for(const $ of h)u+=$==="."?i:d[$]}else u=h.replace(".",i);else u="";const p=t[e];let l=p;return typeof p=="function"&&(l=p(s)),t._hideCountIf2&&s===2&&(o=""),t._numberFirst?l+o+u:u+o+l},Fi=(s,e)=>{const{units:t}=e;if(t.length===0)return[];const{unitMeasures:r}=e,o=e.largest??Number.POSITIVE_INFINITY,a={};let i,d,u,f=s;for(d=0;d<t.length;d++){i=t[d];const p=r[i];u=d===t.length-1?f/p:Math.floor(f/p),a[i]=u,f-=u*p}if(e.round){let p=o;for(d=0;d<t.length;d++)if(i=t[d],u=a[i],u!==0&&(p--,p===0)){for(let l=d+1;l<t.length;l++){const $=t[l],R=a[$];a[i]=(a[i]??0)+R*r[$]/r[i],a[$]=0}break}for(d=t.length-1;d>=0;d--){if(i=t[d],u=a[i],u===0)continue;const l=Math.round(u);if(a[i]=l,d===0)break;const $=t[d-1],R=r[$],G=Math.floor(l*r[i]/R);if(G)a[$]=(a[$]??0)+G,a[i]=0;else break}}const h=[];for(d=0;d<t.length&&h.length<o;d++){if(i=t[d],u=a[i],u&&!e.round&&h.length===o-1){let p,l=0;for(p=d+1,t.length;p<t.length;p++){const $=t[p];l+=a[$]*(e.unitMeasures[$]/e.unitMeasures[i])}u+=l,e.maxDecimalPoints!==void 0&&(u=Ms(u,e.maxDecimalPoints))}u&&h.push({unitCount:u,unitName:i})}return h},Oi=(s,e,t)=>{const{language:r,units:o}=e;if(s.length===0){const p=o.at(-1);return rs({unitCount:0,unitName:p},r,e)}const{conjunction:a,serialComma:i}=e;let d=", ";e.delimiter!==void 0?d=e.delimiter:r.delimiter!==void 0&&(d=r.delimiter);let u="";e.timeAdverb&&t!==0&&(u=r.future??"",t<0&&(u=r.past??""));const f=s.map(p=>rs(p,r,e));let h;return!a||s.length===1?h=f.join(d):s.length===2?h=f.join(a):h=f.slice(0,-1).join(d)+(i?",":"")+a+(f.at(-1)??""),u&&(h=u.replace("%s",h)),h},Pi=(s,e)=>{if(Number.isNaN(s))throw new TypeError("Expected a valid number");if(typeof s!="number")throw new TypeError("Expected a number for milliseconds input");const t={conjunction:"",language:hi,round:!1,serialComma:!0,spacer:" ",timeAdverb:!1,unitMeasures:{d:864e5,h:36e5,m:6e4,mo:2629746e3,ms:1,s:1e3,w:6048e5,y:31556952e3},units:["w","d","h","m","s"],...e};Mi(t.language);const r=Math.abs(s),o=Fi(r,t);return Oi(o,t,s)},Fs=s=>s===155||s===157||s===144||s===152||s===158||s===159,Os=(s,e)=>{for(let t=e;t<s.length;t+=1){const r=s.codePointAt(t);if(r>=64&&r<=126)return t}return-1},et=(s,e,t)=>{for(let r=e;r<s.length;r+=1){const o=s.codePointAt(r);if(o===156||t&&o===7)return r;if(o===27&&s.codePointAt(r+1)===92)return r+1}return-1},Ai=(s,e)=>{const t=s.codePointAt(e+1);return t===91?Os(s,e+2):t===93?et(s,e+2,!0):t===80||t===88||t===94||t===95?et(s,e+2,!1):t!==void 0?e+1:-1},Di=(s,e)=>{const t=s.codePointAt(e);return t===155?Os(s,e+1):t===157?et(s,e+1,!0):t===144||t===152||t===158||t===159?et(s,e+1,!1):-1},Li=s=>{if(s.includes(String.fromCodePoint(27)))return!0;for(let e=0;e<s.length;e+=1)if(Fs(s.codePointAt(e)))return!0;return!1},Bi=s=>{if(!Li(s))return s;let e="",t=0,r=0;const{length:o}=s;for(;r<o;){const a=s.codePointAt(r);let i;if(a===27)i=Ai(s,r);else if(Fs(a))i=Di(s,r);else{r+=1;continue}i===-1&&(i=o-1),e+=s.slice(t,r),t=i+1,r=i+1}return e+=s.slice(t),e},be="@voidzero-dev/vite-task-client",kt="@visulima/task-runner-client",tt=`npm:${kt}@^1`,Ps=oe(".vis",".vite-client-override-declined"),st="pnpm-workspace.yaml",Ni=["dependencies","devDependencies","optionalDependencies","peerDependencies"],As=s=>{try{return JSON.parse(Ge(s,"utf8"))}catch{return}},Gi=s=>{const e=oe(s,st);if(Ae(e))try{return Ts(Ge(e,"utf8")).toJS()?.overrides}catch{return}},_i=s=>s==="pnpm"||s==="aube"?"pnpm.overrides":s==="yarn"?"resolutions":"overrides",qi=s=>{const e=oe(s,st);try{const t=Ts(Ge(e,"utf8"));return t.setIn(["overrides",be],tt),wt(e,t.toString()),!0}catch{return!1}},is=s=>s!==void 0&&Ni.some(e=>s[e]?.[be]!==void 0),Wi=(s,e)=>s!==void 0&&(s.pnpm?.overrides?.[be]!==void 0||s.overrides?.[be]!==void 0||s.resolutions?.[be]!==void 0)||e?.[be]!==void 0,Ui=(s,e=[])=>{const t=As(oe(s,"package.json")),r=Ae(oe(s,"node_modules","@voidzero-dev","vite-task-client"));return{alreadyOverridden:Wi(t,Gi(s)),declined:Ae(oe(s,Ps)),manager:Br(s)?.manager,present:is(t)||r||e.some(o=>is(o))}},Vi=s=>{try{const e=oe(s,Ps);Gr(js(e),{recursive:!0}),wt(e,`Declined adding the ${be} → ${kt} override.
2
2
  Delete this file to be asked again.
3
- `)}catch{}},Gi=(s,e="npm")=>{const t=`${e} install`;if((e==="pnpm"||e==="aube")&&Ae(oe(s,st))&&Di(s))return{file:st,installCommand:t};const r=oe(s,"package.json"),o=Ms(r);if(!o)return;const a=Ai(e);a==="pnpm.overrides"?(o.pnpm??={},o.pnpm.overrides??={},o.pnpm.overrides[je]=tt):(o[a]??={},o[a][je]=tt);try{pt(r,`${JSON.stringify(o,void 0,4)}
4
- `)}catch{return}return{file:"package.json",installCommand:t}},_i=async(s,e)=>{const t=Bi(s,e.projectManifests);if(!t.present||t.alreadyOverridden||t.declined)return!1;const r=ks({input:process.stdin,output:process.stdout});try{e.logger.info(`Detected ${je}. Its cache hints no-op under @visulima/task-runner unless aliased to ${wt} (a drop-in replacement).`);const o=await new Promise(n=>{r.question("Add the override now? [y/N] ",n)});if(!/^y(?:es)?$/i.test(o.trim()))return Ni(s),e.logger.info("Skipped. Delete .vis/.vite-client-override-declined to be asked again."),!1;const a=Gi(s,t.manager);return a===void 0?(e.logger.warn("Could not write the override automatically — add it manually (see @visulima/task-runner-client README)."),!1):(e.logger.info(`Added "${je}": "${tt}" to ${a.file}. Run \`${a.installCommand}\` to apply it.`),!0)}finally{r.close()}},qi=({interactive:s,taskPty:e,workspacePty:t})=>e===!0?!0:e===!1?!1:s&&t!==!1,Ui=s=>s.split(",").map(e=>e.trim()).filter(e=>e!==""),Hi=(s,e,t)=>{const r=new Set,o=[];if(s===void 0||s.trim()==="")return{skipTaskIds:r,unmatchedPatterns:o};const a=[...t],n=new Set(a),d=new Map;for(const h of a){const f=h.lastIndexOf(":");if(f===-1)continue;const u=h.slice(f+1),p=d.get(u);p===void 0?d.set(u,[h]):p.push(h)}for(const h of Ui(s)){if(h.startsWith("~:"))throw new Error(`--skip-cache does not support the closest-project selector "~:" (received "${h}"). Use \`pkg:target\`, \`:target\`, or \`#tag:target\`.`);if(n.has(h)){r.add(h);continue}const f=Zr(h);if(!f){o.push(h);continue}let u=!1;switch(f.kind){case"all":{const p=d.get(f.target)??[];for(const l of p)r.add(l),u=!0;break}case"project":{const p=f.projects?.[0];if(p!==void 0){const l=`${p}:${f.target}`;n.has(l)&&(r.add(l),u=!0)}break}case"tag":{const{tag:p}=f;if(p!==void 0){const l=d.get(f.target)??[];for(const $ of l){const I=$.slice(0,$.lastIndexOf(":"));e.projects[I]?.tags?.includes(p)===!0&&(r.add($),u=!0)}}break}}u||o.push(h)}return{skipTaskIds:r,unmatchedPatterns:o}},zi=/\$(?:\{([A-Z_]\w*)(:-[^}]*)?\}|([A-Z_]\w*))/gi,Vi=new Set(["0","!","#","$","*","-","?","@","_"]),Wi=s=>{const e=new Map;for(const t of s.matchAll(zi)){const r=t[1],o=t[3],a=t[2],n=r??o;if(n===void 0||Vi.has(n))continue;const d=a!==void 0,h=e.get(n);h===void 0?e.set(n,d):h&&!d&&e.set(n,!1)}return[...e.entries()].map(([t,r])=>({hasDefault:r,name:t}))},Yi=s=>{const{command:e,processEnv:t,taskEnv:r,taskId:o}=s,a=Wi(e);if(a.length===0)return;const n=[];for(const{hasDefault:d,name:h}of a){if(d)continue;const f=r[h],u=t[h];f===void 0&&u===void 0&&n.push(h)}if(n.length!==0)return{missing:n.toSorted(),taskId:o}},Ji=s=>{const e=s.missing.map(t=>`$${t}`).join(", ");return`Strict env: ${s.taskId} references unset variable${s.missing.length===1?"":"s"} ${e}. Set ${s.missing.length===1?"it":"them"} in the task env, an envFile, or the parent shell — or opt out with options.strictEnv: false.`},ts=s=>{const e=new Set;for(const t of Object.values(s.projects))for(const r of Object.keys(t.targets??{}))e.add(r);return[...e].sort()},Ki=s=>{const e=new Map;for(const t of s.values())for(const[r,o]of Object.entries(t))for(const a of o.aliases??[])e.has(a)||e.set(a,r);return e},Xi=(s,e)=>e.get(s)??s,Qi=(s,e)=>{if(s.length===0)return e.length;if(e.length===0)return s.length;const t=[];for(let r=0;r<=e.length;r++)t[r]=[r];for(let r=0;r<=s.length;r++)t[0][r]=r;for(let r=1;r<=e.length;r++)for(let o=1;o<=s.length;o++){const a=e[r-1]===s[o-1]?0:1;t[r][o]=Math.min(t[r-1][o]+1,t[r][o-1]+1,t[r-1][o-1]+a)}return t[e.length][s.length]},Zi=(s,e,t=3)=>Fs(s,e,1,t)[0],Fs=(s,e,t=3,r=3)=>{const o=[];for(const a of e){const n=Qi(s.toLowerCase(),a.toLowerCase());n<=r&&o.push({distance:n,name:a})}return o.sort((a,n)=>a.distance-n.distance||a.name.localeCompare(n.name)),o.slice(0,t).map(a=>a.name)},en=s=>s.length===0?" (no targets found)":s.map(e=>` - ${e}`).join(`
5
- `),tn=async s=>{if(s.length===0||!process.stdin.isTTY||!process.stdout.isTTY)return;const e=ks({input:process.stdin,output:process.stdout});try{process.stdout.write(`Available targets:
3
+ `)}catch{}},Hi=(s,e="npm")=>{const t=`${e} install`;if((e==="pnpm"||e==="aube")&&Ae(oe(s,st))&&qi(s))return{file:st,installCommand:t};const r=oe(s,"package.json"),o=As(r);if(!o)return;const a=_i(e);a==="pnpm.overrides"?(o.pnpm??={},o.pnpm.overrides??={},o.pnpm.overrides[be]=tt):(o[a]??={},o[a][be]=tt);try{wt(r,`${JSON.stringify(o,void 0,4)}
4
+ `)}catch{return}return{file:"package.json",installCommand:t}},zi=async(s,e)=>{const t=Ui(s,e.projectManifests);if(!t.present||t.alreadyOverridden||t.declined)return!1;const r=Ss({input:process.stdin,output:process.stdout});try{e.logger.info(`Detected ${be}. Its cache hints no-op under @visulima/task-runner unless aliased to ${kt} (a drop-in replacement).`);const o=await new Promise(i=>{r.question("Add the override now? [y/N] ",i)});if(!/^y(?:es)?$/i.test(o.trim()))return Vi(s),e.logger.info("Skipped. Delete .vis/.vite-client-override-declined to be asked again."),!1;const a=Hi(s,t.manager);return a===void 0?(e.logger.warn("Could not write the override automatically — add it manually (see @visulima/task-runner-client README)."),!1):(e.logger.info(`Added "${be}": "${tt}" to ${a.file}. Run \`${a.installCommand}\` to apply it.`),!0)}finally{r.close()}},Yi=({interactive:s,taskPty:e,workspacePty:t})=>e===!0?!0:e===!1?!1:s&&t!==!1,Ji=s=>s.split(",").map(e=>e.trim()).filter(e=>e!==""),Ki=(s,e,t)=>{const r=new Set,o=[];if(s===void 0||s.trim()==="")return{skipTaskIds:r,unmatchedPatterns:o};const a=[...t],i=new Set(a),d=new Map;for(const u of a){const f=u.lastIndexOf(":");if(f===-1)continue;const h=u.slice(f+1),p=d.get(h);p===void 0?d.set(h,[u]):p.push(u)}for(const u of Ji(s)){if(u.startsWith("~:"))throw new Error(`--skip-cache does not support the closest-project selector "~:" (received "${u}"). Use \`pkg:target\`, \`:target\`, or \`#tag:target\`.`);if(i.has(u)){r.add(u);continue}const f=ni(u);if(!f){o.push(u);continue}let h=!1;switch(f.kind){case"all":{const p=d.get(f.target)??[];for(const l of p)r.add(l),h=!0;break}case"project":{const p=f.projects?.[0];if(p!==void 0){const l=`${p}:${f.target}`;i.has(l)&&(r.add(l),h=!0)}break}case"tag":{const{tag:p}=f;if(p!==void 0){const l=d.get(f.target)??[];for(const $ of l){const R=$.slice(0,$.lastIndexOf(":"));e.projects[R]?.tags?.includes(p)===!0&&(r.add($),h=!0)}}break}}h||o.push(u)}return{skipTaskIds:r,unmatchedPatterns:o}},Xi=/\$(?:\{([A-Z_]\w*)(:-[^}]*)?\}|([A-Z_]\w*))/gi,Qi=new Set(["0","!","#","$","*","-","?","@","_"]),Zi=s=>{const e=new Map;for(const t of s.matchAll(Xi)){const r=t[1],o=t[3],a=t[2],i=r??o;if(i===void 0||Qi.has(i))continue;const d=a!==void 0,u=e.get(i);u===void 0?e.set(i,d):u&&!d&&e.set(i,!1)}return[...e.entries()].map(([t,r])=>({hasDefault:r,name:t}))},en=s=>{const{command:e,processEnv:t,taskEnv:r,taskId:o}=s,a=Zi(e);if(a.length===0)return;const i=[];for(const{hasDefault:d,name:u}of a){if(d)continue;const f=r[u],h=t[u];f===void 0&&h===void 0&&i.push(u)}if(i.length!==0)return{missing:i.toSorted(),taskId:o}},tn=s=>{const e=s.missing.map(t=>`$${t}`).join(", ");return`Strict env: ${s.taskId} references unset variable${s.missing.length===1?"":"s"} ${e}. Set ${s.missing.length===1?"it":"them"} in the task env, an envFile, or the parent shell — or opt out with options.strictEnv: false.`},ns=s=>{const e=new Set;for(const t of Object.values(s.projects))for(const r of Object.keys(t.targets??{}))e.add(r);return[...e].sort()},sn=s=>{const e=new Map;for(const t of s.values())for(const[r,o]of Object.entries(t))for(const a of o.aliases??[])e.has(a)||e.set(a,r);return e},rn=(s,e)=>e.get(s)??s,nn=(s,e)=>{if(s.length===0)return e.length;if(e.length===0)return s.length;const t=[];for(let r=0;r<=e.length;r++)t[r]=[r];for(let r=0;r<=s.length;r++)t[0][r]=r;for(let r=1;r<=e.length;r++)for(let o=1;o<=s.length;o++){const a=e[r-1]===s[o-1]?0:1;t[r][o]=Math.min(t[r-1][o]+1,t[r][o-1]+1,t[r-1][o-1]+a)}return t[e.length][s.length]},on=(s,e,t=3)=>Ds(s,e,1,t)[0],Ds=(s,e,t=3,r=3)=>{const o=[];for(const a of e){const i=nn(s.toLowerCase(),a.toLowerCase());i<=r&&o.push({distance:i,name:a})}return o.sort((a,i)=>a.distance-i.distance||a.name.localeCompare(i.name)),o.slice(0,t).map(a=>a.name)},an=s=>s.length===0?" (no targets found)":s.map(e=>` - ${e}`).join(`
5
+ `),cn=async s=>{if(s.length===0||!process.stdin.isTTY||!process.stdout.isTTY)return;const e=Ss({input:process.stdin,output:process.stdout});try{process.stdout.write(`Available targets:
6
6
  `);for(const[o,a]of s.entries())process.stdout.write(` ${String(o+1).padStart(2," ")}. ${a}
7
7
  `);process.stdout.write(`
8
- `);const t=(await new Promise(o=>{e.question("Select a target (number or name, blank to cancel): ",o)})).trim();if(t.length===0)return;const r=Number.parseInt(t,10);return Number.isFinite(r)&&r>=1&&r<=s.length?s[r-1]:s.includes(t)?t:Zi(t,s)}finally{e.close()}},sn=new RegExp("[\x1B›]\\[[0-?]*[ -/]*[@-~]","g"),dt=s=>s.replaceAll(sn,"").replaceAll("\r","");class ss{#e=[];#r=new Set;#s=new Map;#i=new Map;constructor(e=[]){for(const t of e)this.#i.set(t,{id:t,status:"pending",tailLines:[]});this.#e=[...e],this.#n()}getSnapshot=()=>this.#s;subscribe=e=>(this.#r.add(e),()=>{this.#r.delete(e)});getIds(){return this.#e}getState(e){return this.#i.get(e)}getDockState(){let e=!1,t=!1;for(const r of this.#i.values())r.status==="crashed"||r.status==="failed"?e=!0:(r.status==="pending"||r.status==="starting")&&(t=!0);return e?"crash":t?"boot":"ready"}registerService(e){this.#i.has(e)||(this.#i.set(e,{id:e,status:"pending",tailLines:[]}),this.#e=[...this.#e,e],this.#o())}markStarting(e){this.#t(e,t=>({...t,errorMessage:void 0,startedAt:t.startedAt??Date.now(),status:"starting"}))}markStarted(e,t){this.#t(e,r=>({...r,startedAt:r.startedAt??Date.now(),status:r.status==="ready"?"ready":"starting"}))}markReady(e,t){this.#t(e,r=>({...r,errorMessage:void 0,port:t.port,readyAt:Date.now(),status:"ready"}))}markFailed(e,t,r){const o=r?.message;this.#t(e,a=>({...a,errorMessage:dt(o??t),status:"failed"}))}markCrashed(e,t){const r=t.slice(-256).map(o=>dt(o));this.#t(e,o=>({...o,errorMessage:r.length>0?r[r.length-1]:"process exited",status:"crashed",tailLines:r}))}appendLog(e,t){const r=t.split(`
9
- `).map(o=>dt(o)).filter(o=>o.length>0);r.length!==0&&this.#t(e,o=>{const a=[...o.tailLines,...r];for(;a.length>256;)a.shift();let n=0;for(let d=a.length-1;d>=0;d--)if(n+=a[d].length+1,n>65536){a.splice(0,d+1);break}return{...o,lastLine:r[r.length-1],tailLines:a}})}abortBoot(e){let t=!1;const r=new Map(this.#i);for(const[o,a]of r)(a.status==="pending"||a.status==="starting")&&(r.set(o,{...a,errorMessage:e,status:"failed"}),t=!0);t&&(this.#i=r,this.#n(),this.#o())}#t(e,t){const r=this.#i.get(e);r&&(this.#i.set(e,t(r)),this.#n(),this.#o())}#n(){this.#s=new Map(this.#i)}#o(){for(const e of this.#r)try{e()}catch{}}}const rn=(s,e)=>{if(s===e)return!0;if(!s||!e||s.length!==e.length)return!1;for(const[t,r]of s.entries())if(!Object.is(r,e[t]))return!1;return!0},rs=({children:s,deps:e,onRender:t,style:r,width:o})=>{const a=W.useRef(null),n=W.useRef(!1),d=W.useRef(e),h=W.useRef(s),f=W.useRef(t);f.current=t;let u=!1;e!==void 0?rn(d.current,e)||(u=!0,d.current=e):s!==h.current&&(u=!0,h.current=s),u&&(n.current=!1,a.current&&(a.current.cachedRender=void 0)),W.useLayoutEffect(()=>{const l=a.current;l&&(l.internal_onRendered=()=>{n.current=!0,f.current?.(l)})}),W.useEffect(()=>()=>{const l=a.current;l&&(l.cachedRender=void 0,l.internal_onRendered=void 0)},[]);const p=W.useMemo(()=>({...r,width:o}),[r,o]);return i.jsx("ink-static-render",{ref:a,style:p,children:n.current?null:s()})},nn=s=>Array.isArray(s)?`[${s.join(",")}]`:typeof s=="object"&&s!==null?JSON.stringify(s):String(s),on=(s,e,t)=>e==="_"?`${s}${Array.isArray(t)?t.join(" "):String(t)}`:`${s}--${e}=${nn(t)}`,yt=(s,e,t)=>{const r=new Set(new Set(t.map(l=>l.target.target))),o=new Set(new Set(t.map(l=>l.target.project))),a=e.filter(l=>r.has(l)),n=s.filter(l=>o.has(l)),d=t.length-n.length*a.length,h=a.length===1?"target":"targets",f=a.join(", "),u=n.length===1?`project ${n[0]}`:`${n.length} projects`;let p=`${h} ${f} for ${u}`;return d>0&&(p+=` and ${d} ${d===1?"task":"tasks"} ${d===1?"it depends":"they depend"} on`),p},an={error:"red",info:"white",success:"green"},ht=({children:s,title:e,variant:t})=>{const r=an[t];return i.jsxs(m,{flexDirection:"column",children:[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,inverse:!0,children:" VIS "}),i.jsx(c,{bold:!0,color:r,children:"•"}),i.jsx(c,{children:e})]}),s]})},Os=({cached:s,failed:e,failedIds:t,projectNames:r,retriedIds:o,skippedIds:a,succeeded:n,targets:d,tasks:h,took:f})=>{const u=yt(r,d,h),p=o??[];if(e===0&&(!a||a.length===0)){const l=s>0?` (${s} read from cache)`:"";return i.jsx(rs,{children:()=>i.jsx(ht,{title:`Successfully ran ${u}`,variant:"success",children:i.jsxs(m,{flexDirection:"column",marginTop:1,paddingLeft:3,children:[i.jsxs(c,{children:[i.jsx(c,{color:"green",children:$s})," ",n+s," tasks completed",l?i.jsx(c,{dimColor:!0,children:l}):null,i.jsx(c,{dimColor:!0,children:` · Took ${f}`})]}),p.length>0&&i.jsxs(m,{flexDirection:"column",marginTop:1,children:[i.jsxs(c,{children:[i.jsx(c,{color:"yellow",children:"↻"})," ",i.jsx(c,{color:"yellow",children:String(p.length)})," task",p.length===1?"":"s"," succeeded after retry:"]}),p.map($=>i.jsxs(c,{children:[" ",i.jsx(c,{color:"yellow",children:"↻"})," ",$]},$))]})]})})})}return i.jsx(rs,{children:()=>i.jsx(ht,{title:`Ran ${u}`,variant:"error",children:i.jsxs(m,{flexDirection:"column",marginTop:1,paddingLeft:3,children:[a&&a.length>0&&i.jsxs(m,{flexDirection:"column",children:[i.jsxs(c,{dimColor:!0,children:[a.length," ","task",a.length===1?"":"s"," ","skipped (dependency failed or --bail)"]}),a.map(l=>i.jsxs(c,{dimColor:!0,children:[" - ",l]},l)),i.jsx(c,{})]}),e>0&&i.jsxs(m,{flexDirection:"column",children:[i.jsxs(c,{children:[i.jsx(c,{color:"red",children:String(e)})," ","task",e===1?"":"s"," ","failed:"]}),t.map(l=>i.jsxs(c,{children:[" ",i.jsx(c,{color:"red",children:bs})," ",l]},l)),i.jsx(c,{})]}),p.length>0&&i.jsxs(m,{flexDirection:"column",children:[i.jsxs(c,{children:[i.jsx(c,{color:"yellow",children:String(p.length)})," ","task",p.length===1?"":"s"," ","finished after retry:"]}),p.map(l=>i.jsxs(c,{children:[" ",i.jsx(c,{color:"yellow",children:"↻"})," ",l]},l)),i.jsx(c,{})]}),i.jsx(c,{dimColor:!0,children:` Took ${f}`})]})})})};class rt{#e;#r=new Set;#s=new Map;constructor(e,t){this.#e={autoExitCountdown:null,cached:0,completed:0,done:!1,endTime:null,failed:0,filterActive:!1,filterText:"",focusedPanel:"tasks",interactiveMode:!1,outputs:new Map,pinnedTaskIds:[null,null],rerunRequested:!1,retriedIds:[],retryTaskId:null,rows:e.map(r=>({persistent:!!r.overrides.visOptions?.persistent,status:"pending",taskId:r.id})),running:0,selectedIndex:0,startTime:Date.now(),statusFilter:"all",succeeded:0,totalTasks:t??e.length,viewMode:"list"}}getSnapshot=()=>this.#e;subscribe=e=>(this.#r.add(e),()=>{this.#r.delete(e)});startTasks(e){const t=[...this.#e.rows];for(const r of e){const o=t.findIndex(a=>a.taskId===r.id);o!==-1&&(t[o]={...t[o],elapsed:0,status:"running"},this.#s.set(r.id,process.hrtime()))}this.#t({...this.#e,rows:t,running:this.#e.running+e.length})}endTasks(e){const t=[...this.#e.rows];let{cached:r,completed:o,failed:a,succeeded:n}=this.#e;const d=new Map(this.#e.outputs),h=[...this.#e.retriedIds];for(const p of e){const l=t.findIndex($=>$.taskId===p.task.id);switch(l!==-1&&(t[l]={...t[l],duration:p.startTime&&p.endTime?p.endTime-p.startTime:void 0,retryAttempts:p.retryAttempts,status:p.status}),p.retryAttempts&&p.retryAttempts>0&&h.push(p.task.id),o++,p.status){case"failure":{a++;break}case"local-cache":case"local-cache-kept-existing":case"remote-cache":{r++;break}case"success":{n++;break}}p.terminalOutput&&!d.has(p.task.id)&&d.set(p.task.id,p.terminalOutput),this.#s.delete(p.task.id)}let{selectedIndex:f}=this.#e;if(a>this.#e.failed){const p=t.findIndex(l=>l.status==="failure");p!==-1&&(f=p)}const u=Math.max(0,this.#e.running-e.length);this.#t({...this.#e,cached:r,completed:o,failed:a,outputs:d,retriedIds:h,rows:t,running:u,selectedIndex:f,succeeded:n})}static#i=256*1024;addOutput(e,t){if(!t.trim())return;let r=(this.#e.outputs.get(e)??"")+t;r.length>rt.#i&&(r=r.slice(-rt.#i)),this.#e.outputs.set(e,r),this.#t({...this.#e})}setOutput(e,t){this.#e.outputs.set(e,t),this.#t({...this.#e})}markDone(){this.#t({...this.#e,done:!0,endTime:Date.now()})}unmarkDone(){this.#t({...this.#e,autoExitCountdown:null,done:!1,endTime:null})}tick(){if(this.#s.size===0)return;let e=!1;const t=[...this.#e.rows];for(let r=0;r<t.length;r++){const o=t[r];if(o.status==="running"){const a=this.#s.get(o.taskId);if(a){const n=process.hrtime(a),d=n[0]*1e3+n[1]/1e6;t[r]={...o,elapsed:d},e=!0}}}e&&this.#t({...this.#e,rows:t})}setSelectedIndex(e){e!==this.#e.selectedIndex&&this.#t({...this.#e,selectedIndex:e})}setFocusedPanel(e){e!==this.#e.focusedPanel&&this.#t({...this.#e,focusedPanel:e})}setFilter(e){this.#t({...this.#e,filterText:e,selectedIndex:0})}setFilterActive(e){e!==this.#e.filterActive&&this.#t({...this.#e,filterActive:e,filterText:e?this.#e.filterText:"",selectedIndex:0})}pinTask(e,t){const r=[...this.#e.pinnedTaskIds];r[e]=t,this.#t({...this.#e,pinnedTaskIds:r})}clearPins(){this.#t({...this.#e,pinnedTaskIds:[null,null]})}requestRetry(e){const t=[...this.#e.rows],r=t.findIndex(d=>d.taskId===e);let{completed:o,failed:a,succeeded:n}=this.#e;if(r!==-1){const d=t[r].status;d==="failure"?(a=Math.max(0,a-1),o=Math.max(0,o-1)):d==="success"&&(n=Math.max(0,n-1),o=Math.max(0,o-1)),t[r]={...t[r],elapsed:0,retryAttempts:void 0,status:"running"},this.#s.set(e,process.hrtime())}this.#t({...this.#e,completed:o,done:!1,endTime:null,failed:a,interactiveMode:!1,retriedIds:this.#e.retriedIds.filter(d=>d!==e),retryTaskId:e,rows:t,succeeded:n})}acknowledgeRetry(){const e=this.#e.retryTaskId;return e&&this.#t({...this.#e,retryTaskId:null}),e}setInteractiveMode(e){e!==this.#e.interactiveMode&&this.#t({...this.#e,interactiveMode:e})}setViewMode(e){e!==this.#e.viewMode&&this.#t({...this.#e,viewMode:e})}setStatusFilter(e){this.#t({...this.#e,selectedIndex:0,statusFilter:e})}requestRerun(){this.#s.clear(),this.#t({...this.#e,autoExitCountdown:null,cached:0,completed:0,done:!1,endTime:null,failed:0,interactiveMode:!1,outputs:new Map,rerunRequested:!0,retriedIds:[],rows:this.#e.rows.map(e=>({persistent:e.persistent,status:"pending",taskId:e.taskId})),running:0,startTime:Date.now(),succeeded:0,viewMode:"list"})}acknowledgeRerun(){this.#e.rerunRequested&&this.#t({...this.#e,rerunRequested:!1})}#t(e){this.#e=e;for(const t of this.#r)try{t()}catch{}}}const cn=s=>Ii(s),ln=/^(?<name>(?:[A-Z][\w$]*)?(?:Error|Exception))(?::[ \t](?<message>.*))?$/,dn=/^\s*at\s+/,un=s=>{const e=s.split(`
10
- `);let t;for(let r=0;r<e.length;r++){const o=ln.exec(e[r].trim());if(!o)continue;const a=[];for(let n=r+1;n<e.length&&n<=r+200;n++){const d=e[n];if(dn.test(d))a.push(d.trim());else if(a.length>0||d.trim()!=="")break}if(a.length>0){const n=o.groups?.name??"Error",d=o.groups?.message??"";t={message:d,name:n,stack:`${n}: ${d}
11
- ${a.map(h=>` ${h}`).join(`
12
- `)}`}}}return t},Ps=s=>{if(s.startsWith("file://"))try{return hi(s)}catch{return s}return s},hn=s=>!s.includes("node_modules")&&!s.startsWith("node:")&&!s.startsWith("internal/"),fn=s=>{try{return vi(s)}catch{return}},pn=(s,e)=>{if(!s.file||s.line===void 0)return;const t=Ps(s.file),r=li(t)?t:Yt(e,t);if(!hn(r)||!Ae(r))return;const o=fn(r);if(o){const a=wi(o,{column:s.column===void 0?0:Math.max(0,s.column-1),line:s.line});if(a.source&&a.line!=null){const n=Yt(di(r),a.source),d=yi(o,a.source)??(Ae(n)?Ge(n,"utf8"):void 0);if(d!==void 0)return{column:a.column==null?void 0:a.column+1,file:n,line:a.line,source:d}}}return{column:s.column,file:r,line:s.line,source:Ge(r,"utf8")}},is=(s,e)=>{const t=ui(e,s);return t&&!t.startsWith("..")?t:s},As=(s,e)=>{if(!s?.trim())return s;try{const t=un(cn(s));if(!t)return s;const r=new Error(t.message);r.name=t.name,r.stack=t.stack;const o=gi(r);if(o.length===0)return s;const a=e.color,n={dim:l=>a?Jt(l):l,head:l=>a?pi(lt(l)):l,loc:l=>a?fi(l):l};let d,h;for(const l of o){const $=pn(l,e.cwd);if($){d=$,h=l;break}}const f=[n.head(`✖ ${t.name}${t.message?`: ${t.message}`:""}`)];if(d){const l=`${is(d.file,e.cwd)}:${d.line}${d.column?`:${d.column}`:""}`;f.push(` ${n.loc(l)}`,""),f.push(mi(d.source,{start:{column:d.column,line:d.line}},{color:a?{gutter:Jt,marker:lt,message:lt}:void 0,linesAbove:2,linesBelow:3}))}const u=o.filter(l=>l!==h).slice(0,8).map(l=>{const $=l.methodName??"<anonymous>",I=l.file?`${is(Ps(l.file),e.cwd)}${l.line?`:${l.line}`:""}`:"";return n.dim(` at ${$}${I?` (${I})`:""}`)});u.length>0&&f.push("",...u);const p=n.dim("─".repeat(40));return`${f.join(`
8
+ `);const t=(await new Promise(o=>{e.question("Select a target (number or name, blank to cancel): ",o)})).trim();if(t.length===0)return;const r=Number.parseInt(t,10);return Number.isFinite(r)&&r>=1&&r<=s.length?s[r-1]:s.includes(t)?t:on(t,s)}finally{e.close()}},ln=new RegExp("[\x1B›]\\[[0-?]*[ -/]*[@-~]","g"),ut=s=>s.replaceAll(ln,"").replaceAll("\r","");class os{#e=[];#r=new Set;#s=new Map;#i=new Map;constructor(e=[]){for(const t of e)this.#i.set(t,{id:t,status:"pending",tailLines:[]});this.#e=[...e],this.#n()}getSnapshot=()=>this.#s;subscribe=e=>(this.#r.add(e),()=>{this.#r.delete(e)});getIds(){return this.#e}getState(e){return this.#i.get(e)}getDockState(){let e=!1,t=!1;for(const r of this.#i.values())r.status==="crashed"||r.status==="failed"?e=!0:(r.status==="pending"||r.status==="starting")&&(t=!0);return e?"crash":t?"boot":"ready"}registerService(e){this.#i.has(e)||(this.#i.set(e,{id:e,status:"pending",tailLines:[]}),this.#e=[...this.#e,e],this.#o())}markStarting(e){this.#t(e,t=>({...t,errorMessage:void 0,startedAt:t.startedAt??Date.now(),status:"starting"}))}markStarted(e,t){this.#t(e,r=>({...r,startedAt:r.startedAt??Date.now(),status:r.status==="ready"?"ready":"starting"}))}markReady(e,t){this.#t(e,r=>({...r,errorMessage:void 0,port:t.port,readyAt:Date.now(),status:"ready"}))}markFailed(e,t,r){const o=r?.message;this.#t(e,a=>({...a,errorMessage:ut(o??t),status:"failed"}))}markCrashed(e,t){const r=t.slice(-256).map(o=>ut(o));this.#t(e,o=>({...o,errorMessage:r.length>0?r[r.length-1]:"process exited",status:"crashed",tailLines:r}))}appendLog(e,t){const r=t.split(`
9
+ `).map(o=>ut(o)).filter(o=>o.length>0);r.length!==0&&this.#t(e,o=>{const a=[...o.tailLines,...r];for(;a.length>256;)a.shift();let i=0;for(let d=a.length-1;d>=0;d--)if(i+=a[d].length+1,i>65536){a.splice(0,d+1);break}return{...o,lastLine:r[r.length-1],tailLines:a}})}abortBoot(e){let t=!1;const r=new Map(this.#i);for(const[o,a]of r)(a.status==="pending"||a.status==="starting")&&(r.set(o,{...a,errorMessage:e,status:"failed"}),t=!0);t&&(this.#i=r,this.#n(),this.#o())}#t(e,t){const r=this.#i.get(e);r&&(this.#i.set(e,t(r)),this.#n(),this.#o())}#n(){this.#s=new Map(this.#i)}#o(){for(const e of this.#r)try{e()}catch{}}}const dn=(s,e)=>{if(s===e)return!0;if(!s||!e||s.length!==e.length)return!1;for(const[t,r]of s.entries())if(!Object.is(r,e[t]))return!1;return!0},as=({children:s,deps:e,onRender:t,style:r,width:o})=>{const a=z.useRef(null),i=z.useRef(!1),d=z.useRef(e),u=z.useRef(s),f=z.useRef(t);f.current=t;let h=!1;e!==void 0?dn(d.current,e)||(h=!0,d.current=e):s!==u.current&&(h=!0,u.current=s),h&&(i.current=!1,a.current&&(a.current.cachedRender=void 0)),z.useLayoutEffect(()=>{const l=a.current;l&&(l.internal_onRendered=()=>{i.current=!0,f.current?.(l)})}),z.useEffect(()=>()=>{const l=a.current;l&&(l.cachedRender=void 0,l.internal_onRendered=void 0)},[]);const p=z.useMemo(()=>({...r,width:o}),[r,o]);return n.jsx("ink-static-render",{ref:a,style:p,children:i.current?null:s()})},un=s=>Array.isArray(s)?`[${s.join(",")}]`:typeof s=="object"&&s!==null?JSON.stringify(s):String(s),hn=(s,e,t)=>e==="_"?`${s}${Array.isArray(t)?t.join(" "):String(t)}`:`${s}--${e}=${un(t)}`,xt=(s,e,t)=>{const r=new Set(new Set(t.map(l=>l.target.target))),o=new Set(new Set(t.map(l=>l.target.project))),a=e.filter(l=>r.has(l)),i=s.filter(l=>o.has(l)),d=t.length-i.length*a.length,u=a.length===1?"target":"targets",f=a.join(", "),h=i.length===1?`project ${i[0]}`:`${i.length} projects`;let p=`${u} ${f} for ${h}`;return d>0&&(p+=` and ${d} ${d===1?"task":"tasks"} ${d===1?"it depends":"they depend"} on`),p},fn={error:"red",info:"white",success:"green"},pt=({children:s,title:e,variant:t})=>{const r=fn[t];return n.jsxs(m,{flexDirection:"column",children:[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,inverse:!0,children:" VIS "}),n.jsx(c,{bold:!0,color:r,children:"•"}),n.jsx(c,{children:e})]}),s]})},Ls=({cached:s,failed:e,failedIds:t,projectNames:r,retriedIds:o,skippedIds:a,succeeded:i,targets:d,tasks:u,took:f})=>{const h=xt(r,d,u),p=o??[];if(e===0&&(!a||a.length===0)){const l=s>0?` (${s} read from cache)`:"";return n.jsx(as,{children:()=>n.jsx(pt,{title:`Successfully ran ${h}`,variant:"success",children:n.jsxs(m,{flexDirection:"column",marginTop:1,paddingLeft:3,children:[n.jsxs(c,{children:[n.jsx(c,{color:"green",children:Cs})," ",i+s," tasks completed",l?n.jsx(c,{dimColor:!0,children:l}):null,n.jsx(c,{dimColor:!0,children:` · Took ${f}`})]}),p.length>0&&n.jsxs(m,{flexDirection:"column",marginTop:1,children:[n.jsxs(c,{children:[n.jsx(c,{color:"yellow",children:"↻"})," ",n.jsx(c,{color:"yellow",children:String(p.length)})," task",p.length===1?"":"s"," succeeded after retry:"]}),p.map($=>n.jsxs(c,{children:[" ",n.jsx(c,{color:"yellow",children:"↻"})," ",$]},$))]})]})})})}return n.jsx(as,{children:()=>n.jsx(pt,{title:`Ran ${h}`,variant:"error",children:n.jsxs(m,{flexDirection:"column",marginTop:1,paddingLeft:3,children:[a&&a.length>0&&n.jsxs(m,{flexDirection:"column",children:[n.jsxs(c,{dimColor:!0,children:[a.length," ","task",a.length===1?"":"s"," ","skipped (dependency failed or --bail)"]}),a.map(l=>n.jsxs(c,{dimColor:!0,children:[" - ",l]},l)),n.jsx(c,{})]}),e>0&&n.jsxs(m,{flexDirection:"column",children:[n.jsxs(c,{children:[n.jsx(c,{color:"red",children:String(e)})," ","task",e===1?"":"s"," ","failed:"]}),t.map(l=>n.jsxs(c,{children:[" ",n.jsx(c,{color:"red",children:Is})," ",l]},l)),n.jsx(c,{})]}),p.length>0&&n.jsxs(m,{flexDirection:"column",children:[n.jsxs(c,{children:[n.jsx(c,{color:"yellow",children:String(p.length)})," ","task",p.length===1?"":"s"," ","finished after retry:"]}),p.map(l=>n.jsxs(c,{children:[" ",n.jsx(c,{color:"yellow",children:"↻"})," ",l]},l)),n.jsx(c,{})]}),n.jsx(c,{dimColor:!0,children:` Took ${f}`})]})})})};class rt{#e;#r=new Set;#s=new Map;constructor(e,t){this.#e={autoExitCountdown:null,cached:0,completed:0,done:!1,endTime:null,failed:0,filterActive:!1,filterText:"",focusedPanel:"tasks",interactiveMode:!1,outputs:new Map,pinnedTaskIds:[null,null],rerunRequested:!1,retriedIds:[],retryTaskId:null,rows:e.map(r=>({persistent:!!r.overrides.visOptions?.persistent,status:"pending",taskId:r.id})),running:0,selectedIndex:0,startTime:Date.now(),statusFilter:"all",succeeded:0,totalTasks:t??e.length,viewMode:"list"}}getSnapshot=()=>this.#e;subscribe=e=>(this.#r.add(e),()=>{this.#r.delete(e)});startTasks(e){const t=[...this.#e.rows];for(const r of e){const o=t.findIndex(a=>a.taskId===r.id);o!==-1&&(t[o]={...t[o],elapsed:0,status:"running"},this.#s.set(r.id,process.hrtime()))}this.#t({...this.#e,rows:t,running:this.#e.running+e.length})}endTasks(e){const t=[...this.#e.rows];let{cached:r,completed:o,failed:a,succeeded:i}=this.#e;const d=new Map(this.#e.outputs),u=[...this.#e.retriedIds];for(const p of e){const l=t.findIndex($=>$.taskId===p.task.id);switch(l!==-1&&(t[l]={...t[l],duration:p.startTime&&p.endTime?p.endTime-p.startTime:void 0,retryAttempts:p.retryAttempts,status:p.status}),p.retryAttempts&&p.retryAttempts>0&&u.push(p.task.id),o++,p.status){case"failure":{a++;break}case"local-cache":case"local-cache-kept-existing":case"remote-cache":{r++;break}case"success":{i++;break}}p.terminalOutput&&!d.has(p.task.id)&&d.set(p.task.id,p.terminalOutput),this.#s.delete(p.task.id)}let{selectedIndex:f}=this.#e;if(a>this.#e.failed){const p=t.findIndex(l=>l.status==="failure");p!==-1&&(f=p)}const h=Math.max(0,this.#e.running-e.length);this.#t({...this.#e,cached:r,completed:o,failed:a,outputs:d,retriedIds:u,rows:t,running:h,selectedIndex:f,succeeded:i})}static#i=256*1024;addOutput(e,t){if(!t.trim())return;let r=(this.#e.outputs.get(e)??"")+t;r.length>rt.#i&&(r=r.slice(-rt.#i)),this.#e.outputs.set(e,r),this.#t({...this.#e})}setOutput(e,t){this.#e.outputs.set(e,t),this.#t({...this.#e})}markDone(){this.#t({...this.#e,done:!0,endTime:Date.now()})}unmarkDone(){this.#t({...this.#e,autoExitCountdown:null,done:!1,endTime:null})}tick(){if(this.#s.size===0)return;let e=!1;const t=[...this.#e.rows];for(let r=0;r<t.length;r++){const o=t[r];if(o.status==="running"){const a=this.#s.get(o.taskId);if(a){const i=process.hrtime(a),d=i[0]*1e3+i[1]/1e6;t[r]={...o,elapsed:d},e=!0}}}e&&this.#t({...this.#e,rows:t})}setSelectedIndex(e){e!==this.#e.selectedIndex&&this.#t({...this.#e,selectedIndex:e})}setFocusedPanel(e){e!==this.#e.focusedPanel&&this.#t({...this.#e,focusedPanel:e})}setFilter(e){this.#t({...this.#e,filterText:e,selectedIndex:0})}setFilterActive(e){e!==this.#e.filterActive&&this.#t({...this.#e,filterActive:e,filterText:e?this.#e.filterText:"",selectedIndex:0})}pinTask(e,t){const r=[...this.#e.pinnedTaskIds];r[e]=t,this.#t({...this.#e,pinnedTaskIds:r})}clearPins(){this.#t({...this.#e,pinnedTaskIds:[null,null]})}requestRetry(e){const t=[...this.#e.rows],r=t.findIndex(d=>d.taskId===e);let{completed:o,failed:a,succeeded:i}=this.#e;if(r!==-1){const d=t[r].status;d==="failure"?(a=Math.max(0,a-1),o=Math.max(0,o-1)):d==="success"&&(i=Math.max(0,i-1),o=Math.max(0,o-1)),t[r]={...t[r],elapsed:0,retryAttempts:void 0,status:"running"},this.#s.set(e,process.hrtime())}this.#t({...this.#e,completed:o,done:!1,endTime:null,failed:a,interactiveMode:!1,retriedIds:this.#e.retriedIds.filter(d=>d!==e),retryTaskId:e,rows:t,succeeded:i})}acknowledgeRetry(){const e=this.#e.retryTaskId;return e&&this.#t({...this.#e,retryTaskId:null}),e}setInteractiveMode(e){e!==this.#e.interactiveMode&&this.#t({...this.#e,interactiveMode:e})}setViewMode(e){e!==this.#e.viewMode&&this.#t({...this.#e,viewMode:e})}setStatusFilter(e){this.#t({...this.#e,selectedIndex:0,statusFilter:e})}requestRerun(){this.#s.clear(),this.#t({...this.#e,autoExitCountdown:null,cached:0,completed:0,done:!1,endTime:null,failed:0,interactiveMode:!1,outputs:new Map,rerunRequested:!0,retriedIds:[],rows:this.#e.rows.map(e=>({persistent:e.persistent,status:"pending",taskId:e.taskId})),running:0,startTime:Date.now(),succeeded:0,viewMode:"list"})}acknowledgeRerun(){this.#e.rerunRequested&&this.#t({...this.#e,rerunRequested:!1})}#t(e){this.#e=e;for(const t of this.#r)try{t()}catch{}}}const pn=s=>Bi(s),gn=/^(?<name>(?:[A-Z][\w$]*)?(?:Error|Exception))(?::[ \t](?<message>.*))?$/,mn=/^\s*at\s+/,wn=s=>{const e=s.split(`
10
+ `);let t;for(let r=0;r<e.length;r++){const o=gn.exec(e[r].trim());if(!o)continue;const a=[];for(let i=r+1;i<e.length&&i<=r+200;i++){const d=e[i];if(mn.test(d))a.push(d.trim());else if(a.length>0||d.trim()!=="")break}if(a.length>0){const i=o.groups?.name??"Error",d=o.groups?.message??"";t={message:d,name:i,stack:`${i}: ${d}
11
+ ${a.map(u=>` ${u}`).join(`
12
+ `)}`}}}return t},Bs=s=>{if(s.startsWith("file://"))try{return yi(s)}catch{return s}return s},yn=s=>!s.includes("node_modules")&&!s.startsWith("node:")&&!s.startsWith("internal/"),vn=s=>{try{return Si(s)}catch{return}},kn=(s,e)=>{if(!s.file||s.line===void 0)return;const t=Bs(s.file),r=gi(t)?t:Qt(e,t);if(!yn(r)||!Ae(r))return;const o=vn(r);if(o){const a=$i(o,{column:s.column===void 0?0:Math.max(0,s.column-1),line:s.line});if(a.source&&a.line!=null){const i=Qt(mi(r),a.source),d=bi(o,a.source)??(Ae(i)?Ge(i,"utf8"):void 0);if(d!==void 0)return{column:a.column==null?void 0:a.column+1,file:i,line:a.line,source:d}}}return{column:s.column,file:r,line:s.line,source:Ge(r,"utf8")}},cs=(s,e)=>{const t=wi(e,s);return t&&!t.startsWith("..")?t:s},Ns=(s,e)=>{if(!s?.trim())return s;try{const t=wn(pn(s));if(!t)return s;const r=new Error(t.message);r.name=t.name,r.stack=t.stack;const o=xi(r);if(o.length===0)return s;const a=e.color,i={dim:l=>a?Zt(l):l,head:l=>a?ki(dt(l)):l,loc:l=>a?vi(l):l};let d,u;for(const l of o){const $=kn(l,e.cwd);if($){d=$,u=l;break}}const f=[i.head(`✖ ${t.name}${t.message?`: ${t.message}`:""}`)];if(d){const l=`${cs(d.file,e.cwd)}:${d.line}${d.column?`:${d.column}`:""}`;f.push(` ${i.loc(l)}`,""),f.push(ji(d.source,{start:{column:d.column,line:d.line}},{color:a?{gutter:Zt,marker:dt,message:dt}:void 0,linesAbove:2,linesBelow:3}))}const h=o.filter(l=>l!==u).slice(0,8).map(l=>{const $=l.methodName??"<anonymous>",R=l.file?`${cs(Bs(l.file),e.cwd)}${l.line?`:${l.line}`:""}`:"";return i.dim(` at ${$}${R?` (${R})`:""}`)});h.length>0&&f.push("",...h);const p=i.dim("─".repeat(40));return`${f.join(`
13
13
  `)}
14
14
  ${p}
15
- ${s}`}catch{return s}},gn={delimiter:" ",language:{d:()=>" d",future:"in %s",h:()=>" h",m:()=>" m",mo:()=>" mo",ms:()=>" ms",past:"%s ago",s:()=>" s",w:()=>" w",y:()=>" y"},largest:2,round:!0,spacer:"",units:["h","m","s","ms"]},De=s=>Fi(s,gn),Ne=s=>s==="local-cache"||s==="local-cache-kept-existing"||s==="remote-cache",_e=s=>{switch(s){case"failure":return{color:"red",icon:bs};case"local-cache":case"local-cache-kept-existing":case"remote-cache":case"success":return{color:"green",icon:$s};case"skipped":return{color:"gray",icon:ot};default:return{color:"gray",icon:"?"}}},We=s=>{const{color:e,icon:t}=_e(s);return pe(K.createElement(c,{color:e},t),{columns:10}).trim()},mn=s=>{const{color:e,icon:t}=_e(s);switch(s){case"local-cache":case"local-cache-kept-existing":case"remote-cache":return pe(K.createElement(c,null,K.createElement(c,{color:e},t)," ",K.createElement(c,{color:"cyan"},"[cache]")),{columns:30}).trim();case"skipped":return pe(K.createElement(c,null,K.createElement(c,{dimColor:!0},t)," ",K.createElement(c,{dimColor:!0},"[skipped]")),{columns:30}).trim();default:return pe(K.createElement(c,{color:e},t),{columns:10}).trim()}},wn=s=>s==="azure"||s==="buildkite"||s==="github"||s==="gitlab"||s==="off"?s:process.env.GITHUB_ACTIONS==="true"?"github":process.env.GITLAB_CI==="true"?"gitlab":process.env.BUILDKITE==="true"?"buildkite":process.env.TF_BUILD?.toLowerCase()==="true"?"azure":"off",yn=s=>{const e=s.replaceAll(/\W+/g,"_"),t=xi("sha256").update(s).digest("hex").slice(0,6);return`${e}_${t}`},vn=(s,e,t,r="auto")=>{const o=t.trim();if(!o)return;const a=`
16
- `,n=wn(r);if(n==="github"&&e!=="failure"){process.stdout.write(`::group::${We(e)} ${s}${a}`),process.stdout.write(o+a),process.stdout.write(`::endgroup::${a}`);return}if(n==="gitlab"&&e!=="failure"){const p=Math.floor(Date.now()/1e3),l=yn(s),$="\x1B[0K";process.stdout.write(`${$}section_start:${String(p)}:${l}[collapsed=true]\r${$}${We(e)} ${s}${a}`),process.stdout.write(o+a);const I=Math.floor(Date.now()/1e3);process.stdout.write(`${$}section_end:${String(I)}:${l}\r${$}${a}`);return}if(n==="buildkite"&&e!=="failure"){process.stdout.write(`--- ${We(e)} ${s}${a}`),process.stdout.write(o+a);return}if(n==="azure"&&e!=="failure"){process.stdout.write(`##[group]${We(e)} ${s}${a}`),process.stdout.write(o+a),process.stdout.write(`##[endgroup]${a}`);return}const d=process.stdout.columns||80,h=pe(K.createElement(c,{dimColor:!0},ot.repeat(d)),{columns:d}).trim(),f=mn(e),u=pe(K.createElement(c,{bold:!0},s),{columns:d}).trim();process.stdout.write(`${h}${a}`),process.stdout.write(`${f} ${u}${a}`),process.stdout.write(o+a),process.stdout.write(`${h}${a}`)},xn=s=>s==="running"?{color:"white",icon:"•"}:s==="pending"?{color:"gray",icon:"·"}:_e(s),kn=({autoScroll:s,focused:e,interactiveMode:t,showFullscreenHint:r,statusValue:o,supportsInteractive:a,taskId:n})=>{if(!n)return;if(t)return"Esc cancel | Enter send";const d=s?"":" PAUSED (f resume)",h=a?" i INPUT":"";return e&&o==="running"&&r?`⏎ FULLSCREEN${h} f FOLLOW${d}`:e&&o==="running"?`f FOLLOW${h}${d}`:e&&r?`<enter> full screen${d}`:e?d||void 0:"<tab> or <enter> to focus"},ns=({autoScroll:s=!0,duration:e,focused:t,interactiveMode:r,output:o,scrollRef:a,showFullscreenHint:n,status:d,supportsInteractive:h=!0,taskId:f})=>{const u=d??"pending",{icon:p}=xn(u),l=t?"bold":"single",$=u==="failure"?"red":u==="success"||Ne(u)?t?"green":"gray":u==="running"?t?"white":"cyan":t?"white":"gray",I=f?`${p} ${f}`:void 0,G=e===void 0?void 0:De(e),z=kn({autoScroll:s,focused:t,interactiveMode:r??!1,showFullscreenHint:n??!1,statusValue:u,supportsInteractive:h,taskId:f});if(!f)return i.jsxs(m,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",paddingX:2,paddingY:1,children:[i.jsx(c,{dimColor:!0,children:"Select a task to view output"}),i.jsx(c,{dimColor:!0,children:"Press Enter or 1/2 to pin"})]});const b=[];if(o)for(const x of o.split(`
17
- `))b.push(x.endsWith("\r")?x.slice(0,-1):x);return!o&&(u==="running"||u==="pending")?i.jsx(m,{borderBottomTitle:z,borderColor:$,borderStyle:l,borderTopRightTitle:G,borderTopTitle:I,flexDirection:"column",flexGrow:1,paddingX:2,paddingY:1,children:i.jsx(m,{alignItems:"center",flexGrow:1,justifyContent:"center",children:i.jsx(c,{dimColor:!0,children:"Waiting for task output…"})})}):i.jsxs(m,{borderBottomTitle:z,borderColor:r?"yellow":$,borderStyle:l,borderTopRightTitle:G,borderTopTitle:I,flexDirection:"column",flexGrow:1,children:[i.jsx(m,{flexGrow:1,flexShrink:1,paddingY:1,children:i.jsx(xs,{flexGrow:1,followOutput:s,paddingX:2,ref:a,scrollbar:!0,scrollbarColor:"gray",scrollbarStyle:"block",children:i.jsx(c,{children:b.join(`
18
- `)})})}),r&&i.jsx(m,{flexShrink:0,justifyContent:"center",paddingX:1,children:i.jsx(c,{bold:!0,color:"yellow",children:"INTERACTIVE | keystrokes forwarded to task | Esc to exit"})})]})},jn={crashed:"✖",failed:"✖",pending:"·",ready:"●",starting:"•"},Ds=s=>s==="ready"?"green":s==="crashed"||s==="failed"?"red":s==="starting"?"cyan":"gray",$n=({status:s})=>s==="starting"?i.jsx(c,{color:"cyan",children:i.jsx(Ts,{type:"dots"})}):i.jsx(c,{bold:!0,color:Ds(s),children:jn[s]}),bn=({active:s,focused:e,state:t})=>{const r=e&&s,o=r?">":" ",a=t.status==="ready"?t.port?`running, port ${String(t.port)}`:"running":t.status==="failed"||t.status==="crashed"?t.errorMessage??"exited":t.lastLine??"booting…";return i.jsxs(m,{flexDirection:"row",flexShrink:0,overflow:"hidden",children:[i.jsx(c,{children:o}),i.jsx(c,{children:" "}),i.jsx(m,{flexShrink:0,width:3,children:i.jsx($n,{status:t.status})}),i.jsx(m,{flexGrow:0,flexShrink:0,width:28,children:i.jsx(c,{bold:r,inverse:r,children:t.id})}),i.jsx(m,{flexGrow:1,flexShrink:1,overflow:"hidden",children:i.jsxs(c,{color:Ds(t.status),dimColor:t.status!=="crashed"&&t.status!=="failed",wrap:"truncate-end",children:[" ",a]})})]})},Sn=({states:s})=>{const e=[];for(const r of s)r.status==="ready"&&e.push(r.id);const t=e.join(", ");return i.jsxs(m,{paddingX:1,children:[i.jsxs(c,{bold:!0,color:"green",children:["● ","Services"]}),i.jsxs(c,{children:[" ",String(e.length)," / ",String(s.length)," running"]}),t.length>0&&i.jsxs(c,{dimColor:!0,children:[" ",t]}),i.jsx(c,{dimColor:!0,children:" [Tab ↓]"})]})},Tn=({states:s})=>{const e=s.find(t=>t.status==="crashed"||t.status==="failed");return e?i.jsxs(m,{flexDirection:"column",paddingX:1,children:[i.jsxs(c,{bold:!0,color:"red",children:["✖ ","Service crashed:"," ",e.id]}),e.tailLines.slice(-3).map((t,r)=>i.jsxs(c,{color:"red",dimColor:!0,children:[" ",t]},`crash-${String(r)}`))]}):i.jsx(i.Fragment,{})},Cn=({activeIndex:s,focused:e,store:t})=>{const r=W.useSyncExternalStore(t.subscribe,t.getSnapshot),o=t.getIds();if(o.length===0)return i.jsx(i.Fragment,{});const a=o.map(u=>r.get(u)).filter(u=>u!==void 0),n=t.getDockState(),d=n==="crash"?"red":n==="ready"?"gray":e?"white":"cyan",h=n==="crash"?"Services (crashed)":n==="ready"?"Services":"Services (starting)",f=e?n==="crash"?"↑↓ select Enter logs R retry Esc back":"↑↓ select Enter logs Esc back":"Tab to focus services";return n==="ready"&&!e?i.jsx(m,{borderColor:d,borderStyle:"single",flexDirection:"row",flexShrink:0,children:i.jsx(Sn,{states:a})}):i.jsxs(m,{borderBottomTitle:f,borderColor:d,borderStyle:e?"bold":"single",borderTopTitle:h,flexDirection:"column",flexGrow:2,flexShrink:0,minHeight:6,paddingX:1,children:[n==="crash"&&i.jsx(Tn,{states:a}),a.map((u,p)=>i.jsx(bn,{active:p===s,focused:e,state:u},u.id))]})},Ls=6,Bs=8,Ns=12,In=s=>s==="running"||s==="pending"?Ss:s==="local-cache"||s==="local-cache-kept-existing"?"Local":s==="remote-cache"?"Remote":ot,os=(s,e)=>e[0]===s?"[1]":e[1]===s?"[2]":"",as=({compact:s,focused:e,isSelected:t,pinLabel:r,row:o})=>{const{persistent:a,status:n,taskId:d}=o,h=e&&t,f=h?">":" ",u=n==="running"&&a===!0;let p;if(u)p=i.jsx(c,{bold:!0,color:"green",children:" ● "});else if(n==="running")p=i.jsxs(c,{bold:!0,color:"white",children:[" ",i.jsx(Ts,{type:"dots"})," "]});else if(n==="pending")p=i.jsx(c,{bold:!0,color:"gray",children:" · "});else{const{color:$,icon:I}=_e(n);p=i.jsxs(c,{bold:!0,color:$,children:[" ",I," "]})}let l=Ss;return u?l="running":n!=="running"&&n!=="pending"?l=o.duration===void 0?ot:De(o.duration):n==="running"&&o.elapsed!==void 0&&(l=De(o.elapsed)),i.jsxs(m,{children:[i.jsx(c,{children:f}),i.jsx(m,{width:Ls,children:p}),i.jsxs(m,{flexGrow:1,children:[i.jsx(c,{bold:h,inverse:h,children:d}),r?i.jsx(c,{dimColor:!0,children:` ${r}`}):null]}),!s&&i.jsx(m,{justifyContent:"flex-end",width:Bs,children:i.jsx(c,{dimColor:!Ne(n),children:In(n)})}),!s&&i.jsx(m,{justifyContent:"flex-end",width:Ns,children:i.jsx(c,{color:u?"green":void 0,dimColor:n==="pending"||u,children:l})})]})},cs=({compact:s,filterActive:e,filterText:t,focused:r,headerStatus:o,parallelSlots:a=3,pinnedTaskIds:n,rows:d,scrollRef:h,selectedIndex:f,title:u})=>{const p=o==="error"?"red":o==="success"?"green":r?"white":"gray",l=d[f]?.taskId,$=[];let I=0;for(const x of d)x.status==="running"?$.push(x):x.status==="pending"&&(I+=1);const G=Math.min(a,$.length+I),z=G>1,b=[];if(z)for(let x=0;x<G;x++){const O=$[x];O?b.push(i.jsx(as,{compact:s,focused:r,isSelected:O.taskId===l,pinLabel:os(O.taskId,n),row:O},`par-${O.taskId}`)):b.push(i.jsxs(m,{children:[i.jsx(c,{children:" "}),i.jsx(m,{width:Ls,children:i.jsx(c,{bold:!0,color:"gray",children:" · "})}),i.jsx(c,{dimColor:!0,children:"Waiting for task..."})]},`par-empty-${String(x)}`))}return i.jsxs(m,{borderColor:p,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[i.jsxs(m,{flexShrink:0,paddingX:1,children:[i.jsx(c,{bold:!0,inverse:!0,children:" VIS "}),i.jsx(c,{children:` ${u}`}),!s&&i.jsxs(m,{flexGrow:1,gap:0,justifyContent:"flex-end",children:[i.jsx(m,{justifyContent:"flex-end",width:Bs,children:i.jsx(c,{dimColor:!0,children:"Cache"})}),i.jsx(m,{justifyContent:"flex-end",width:Ns,children:i.jsx(c,{dimColor:!0,children:"Duration"})})]})]}),i.jsx(xs,{flexGrow:1,flexShrink:1,paddingX:1,paddingY:1,ref:h,scrollbar:!0,scrollbarColor:"gray",scrollbarStyle:"block",children:d.map(x=>i.jsx(as,{compact:s,focused:r,isSelected:x.taskId===l,pinLabel:os(x.taskId,n),row:x},x.taskId))}),z&&i.jsx(m,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",borderTop:!0,flexDirection:"column",flexShrink:0,paddingX:1,paddingY:1,children:b}),e&&i.jsxs(m,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",borderTop:!0,flexShrink:0,paddingX:1,children:[i.jsx(c,{bold:!0,color:"white",children:"/ "}),i.jsx(c,{children:t}),i.jsx(c,{inverse:!0,children:" "})]})]})},ls=40,ds=10,us=100,Rn=Object.freeze([]),En=({autoExitSeconds:s,onRetryService:e,parallelSlots:t,projectNames:r,serviceDockStore:o,stdinRegistry:a,store:n,targets:d,tasks:h})=>{const{exit:f}=wr(),{columns:u,rows:p}=yr(),l=W.useSyncExternalStore(n.subscribe,n.getSnapshot),$=W.useCallback(T=>o?o.subscribe(T):()=>{},[o]);W.useSyncExternalStore($,()=>o?o.getDockState():"ready");const I=o?o.getIds():Rn,G=I.length>0,[z,b]=W.useState(0),[x,O]=W.useState(null),k=W.useSyncExternalStore($,()=>x&&o?o.getState(x):void 0),[M,w]=W.useState(!1),A=W.useRef(null),S=W.useRef(null),F=W.useRef(null),[V,te]=W.useState(!1),[ue,q]=W.useState(!0),Y=W.useRef({list:0,splitList:0,splitOutput:0}),ce=W.useCallback(()=>{l.viewMode==="list"?Y.current.list=S.current?.getScrollOffset()??0:l.viewMode==="split"&&(Y.current.splitList=S.current?.getScrollOffset()??0,Y.current.splitOutput=F.current?.getScrollOffset()??0)},[l.viewMode]),re=W.useCallback(T=>{setTimeout(()=>{if(T==="list"){const v=Y.current.list;S.current?.scrollTo(v)}else if(T==="split"){const v=Y.current.splitList;v>0?S.current?.scrollTo(v):S.current?.scrollTo(Math.max(0,n.getSnapshot().selectedIndex-2)),F.current?.scrollTo(Y.current.splitOutput)}},0)},[n]),ie=W.useRef(!1);W.useEffect(()=>{l.done&&!ie.current&&(ie.current=!0,s>0&&l.failed===0&&te(!0)),!l.done&&ie.current&&(ie.current=!1,te(!1))},[l.done,l.failed,s]);const ae=W.useMemo(()=>{const T=I.length>0?new Set(I):null,v=l.filterText?l.filterText.toLowerCase():null,R=[];for(const Q of l.rows)T?.has(Q.taskId)||l.statusFilter==="failed"&&Q.status!=="failure"||l.statusFilter==="running"&&Q.status!=="running"&&Q.status!=="pending"||l.statusFilter==="passed"&&Q.status!=="success"&&!Ne(Q.status)||v&&!Q.taskId.toLowerCase().includes(v)||R.push(Q);return R},[l.rows,l.filterText,l.statusFilter,I]),_=(ae[l.selectedIndex]??null)?.taskId??null,H=x?null:l.pinnedTaskIds[0]??_,X=H?l.rows.find(T=>T.taskId===H):null,he=k??null,C=x?(he?.tailLines??[]).join(`
19
- `):H?l.outputs.get(H)??"":"",ge=W.useMemo(()=>X?.status==="failure"&&C?As(C,{color:!process.env.NO_COLOR,cwd:process.cwd()}):C,[X?.status,C]),Te=x??H,Me=x?he?.status==="crashed"||he?.status==="failed"?"failure":"running":X?.status,Le=yt(r,d,h),Fe=l.done?`Completed ${Le} (${De((l.endTime??Date.now())-l.startTime)})`:`Running ${Le}...`,ee=l.done?l.failed>0?"error":"success":"running",Ce=W.useCallback(T=>{S.current?.scrollTo(Math.max(0,T-2))},[]);if(W.useEffect(()=>{l.interactiveMode&&X?.status!=="running"&&n.setInteractiveMode(!1)},[l.interactiveMode,X?.status,n]),W.useEffect(()=>{if(!H)return;let T=u;l.viewMode==="split"&&u>=us?T=u-Math.floor(u*.4)-2:(l.viewMode==="split"||l.viewMode==="fullscreen")&&(T=u-2);const v=Math.max(1,p-4);a.get(H)?.resize?.(T,v)},[u,p,l.viewMode,H]),Vt((T,v)=>{if(v.escape){n.setInteractiveMode(!1);return}if(!H)return;const R=a.get(H);if(!R){n.setInteractiveMode(!1);return}if(v.return)R.write("\r");else if(v.upArrow)R.write("\x1B[A");else if(v.downArrow)R.write("\x1B[B");else if(v.rightArrow)R.write("\x1B[C");else if(v.leftArrow)R.write("\x1B[D");else if(v.backspace)R.write("");else if(v.delete)R.write("\x1B[3~");else if(v.tab)R.write(" ");else if(v.home)R.write("\x1B[H");else if(v.end)R.write("\x1B[F");else if(v.pageUp)R.write("\x1B[5~");else if(v.pageDown)R.write("\x1B[6~");else if(v.ctrl&&T){const Q=T.toUpperCase().codePointAt(0);Q!==void 0&&Q>=65&&Q<=90&&R.write(String.fromCodePoint(Q-64))}else T&&R.write(T)},{isActive:l.interactiveMode}),Vt((T,v)=>{if(T==="c"&&v.ctrl){f();return}if(!V){if(M){v.escape||T==="?"?w(!1):T==="q"?(w(!1),te(!0)):v.downArrow||T==="j"?A.current?.scrollBy(1):v.upArrow||T==="k"?A.current?.scrollBy(-1):v.pageDown?A.current?.scrollBy(5):v.pageUp?A.current?.scrollBy(-5):v.home?A.current?.scrollToTop():v.end&&A.current?.scrollToBottom();return}if(T==="?"){w(!0);return}if(T==="q"){te(!0);return}if(T==="r"&&l.done){n.requestRerun();return}if(T==="R"&&l.done){const R=ae[l.selectedIndex];R?.status==="failure"&&n.requestRetry(R.taskId);return}if(T==="F"&&!l.filterActive){const R=["all","failed","running","passed"],Q=R.indexOf(l.statusFilter);n.setStatusFilter(R[(Q+1)%R.length]);return}if(l.filterActive){if(v.escape){n.setFilterActive(!1);return}if(v.return){n.setFilterActive(!1);return}if(v.backspace){n.setFilter(l.filterText.slice(0,-1));return}if(T&&!v.ctrl&&!v.meta){n.setFilter(l.filterText+T);return}return}if(T==="i"&&X?.status==="running"&&(l.viewMode==="fullscreen"||l.viewMode==="split"&&l.focusedPanel==="output")){n.setInteractiveMode(!0);return}if(l.viewMode==="fullscreen"){if(v.escape){n.setViewMode("split"),re("split");return}if(T==="f"){const R=!ue;q(R),R&&F.current?.scrollToBottom();return}if(v.downArrow||T==="j"){q(!1),F.current?.scrollBy(1);return}if(v.upArrow||T==="k"){q(!1),F.current?.scrollBy(-1);return}if(v.pageDown||v.ctrl&&T==="d"){q(!1),F.current?.scrollBy(12);return}if(v.pageUp||v.ctrl&&T==="u"){q(!1),F.current?.scrollBy(-12);return}if(v.home){q(!1),F.current?.scrollToTop();return}if(v.end){q(!0),F.current?.scrollToBottom();return}return}if(l.focusedPanel==="dock"&&G&&o){if(v.tab){O(null),n.setFocusedPanel("tasks");return}if(v.escape){n.setFocusedPanel("tasks"),O(null),l.viewMode==="split"&&(n.setViewMode("list"),re("list"));return}if(v.downArrow||T==="j"){b(R=>Math.min(R+1,I.length-1));return}if(v.upArrow||T==="k"){b(R=>Math.max(R-1,0));return}if(v.return){const R=I[z];R&&(O(R),q(!0),ce(),Y.current.splitList=0,Y.current.splitOutput=0,n.setViewMode("split"),n.setFocusedPanel("output"),re("split"));return}if((T==="r"||T==="R")&&e){const R=I[z],Q=R?o.getState(R)?.status:void 0;if(R&&(Q==="crashed"||Q==="failed")){const Oe=e(R);Oe instanceof Promise&&Oe.catch(()=>{})}return}return}if(l.viewMode==="split"){if(v.tab){l.focusedPanel==="tasks"?n.setFocusedPanel("output"):G?n.setFocusedPanel("dock"):(O(null),n.setFocusedPanel("tasks"));return}if(l.focusedPanel==="output"){if(v.escape){if(x&&G){O(null),n.setViewMode("list"),n.setFocusedPanel("dock"),re("list");return}O(null),n.setFocusedPanel("tasks");return}if(v.return){ce(),n.setViewMode("fullscreen");return}if(T==="f"){const R=!ue;q(R),R&&F.current?.scrollToBottom();return}if(v.downArrow||T==="j"){q(!1),F.current?.scrollBy(1);return}if(v.upArrow||T==="k"){q(!1),F.current?.scrollBy(-1);return}if(v.pageDown||v.ctrl&&T==="d"){q(!1),F.current?.scrollBy(12);return}if(v.pageUp||v.ctrl&&T==="u"){q(!1),F.current?.scrollBy(-12);return}if(v.home){q(!1),F.current?.scrollToTop();return}if(v.end){q(!0),F.current?.scrollToBottom();return}return}if(v.escape){n.setViewMode("list"),re("list");return}if(v.return){n.setFocusedPanel("output");return}}if(l.viewMode==="list"||l.viewMode==="split"&&l.focusedPanel==="tasks"){if(v.tab&&l.viewMode==="list"&&G){n.setFocusedPanel("dock");return}if(v.downArrow||T==="j"){const R=Math.min(l.selectedIndex+1,Math.max(0,ae.length-1));n.setSelectedIndex(R),Ce(R);return}if(v.upArrow||T==="k"){const R=Math.max(l.selectedIndex-1,0);n.setSelectedIndex(R),Ce(R);return}if(v.return&&l.viewMode==="list"){q(!0),ce(),Y.current.splitList=0,Y.current.splitOutput=0,n.setViewMode("split"),n.setFocusedPanel("output"),re("split");return}if(T==="/"){n.setFilterActive(!0);return}if(T==="1"&&_){n.pinTask(0,_);return}if(T==="2"&&_){n.pinTask(1,_);return}if(T==="0"){n.clearPins();return}v.escape&&l.filterText&&n.setFilter("")}}},{isActive:!l.interactiveMode}),u<ls||p<ds)return i.jsx(m,{alignItems:"center",height:p,justifyContent:"center",width:u,children:i.jsxs(c,{color:"yellow",children:["Terminal too small (",u,"x",p,"). Minimum:"," ",ls,"x",ds]})});const Ie=i.jsxs(m,{gap:1,children:[l.succeeded>0&&i.jsxs(c,{bold:!0,color:"green",children:["✓"," ",l.succeeded]}),l.cached>0&&i.jsxs(c,{dimColor:!0,children:["✓"," ",l.cached]}),l.failed>0&&i.jsxs(c,{bold:!0,color:"red",children:["✗"," ",l.failed]}),l.running>0&&i.jsxs(c,{color:"cyan",children:["◷"," ",l.running]}),i.jsxs(c,{dimColor:!0,children:[l.totalTasks," ","total"]}),l.statusFilter!=="all"&&i.jsxs(c,{color:"yellow",children:["[",l.statusFilter,"]"]})]});let le;if(l.viewMode==="fullscreen")le=[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"Esc"}),i.jsx(c,{dimColor:!0,children:"BACK"})]},"esc"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"↑↓"}),i.jsx(c,{dimColor:!0,children:"SCROLL"})]},"scroll"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"^u ^d"}),i.jsx(c,{dimColor:!0,children:"PAGE"})]},"page"),...X?.status==="running"?[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"i"}),i.jsx(c,{dimColor:!0,children:"INPUT"})]},"i")]:[],i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"q"}),i.jsx(c,{dimColor:!0,children:"QUIT"})]},"q")];else if(l.done){const T=ae[l.selectedIndex]?.status==="failure";le=[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"q"}),i.jsx(c,{dimColor:!0,children:"QUIT"})]},"q"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"r"}),i.jsx(c,{dimColor:!0,children:"RERUN"})]},"r"),...T?[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"R"}),i.jsx(c,{dimColor:!0,children:"RETRY"})]},"R")]:[],i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"?"}),i.jsx(c,{dimColor:!0,children:"HELP"})]},"?"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"↑↓"}),i.jsx(c,{dimColor:!0,children:"NAV"})]},"nav"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"F"}),i.jsx(c,{dimColor:!0,children:"FILTER"})]},"F"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"⏎"}),i.jsx(c,{dimColor:!0,children:l.viewMode==="list"?"OUTPUT":"FULLSCREEN"})]},"enter")]}else l.viewMode==="split"&&l.focusedPanel==="output"?le=[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"q"}),i.jsx(c,{dimColor:!0,children:"QUIT"})]},"q"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"Esc"}),i.jsx(c,{dimColor:!0,children:"BACK"})]},"esc"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"↑↓"}),i.jsx(c,{dimColor:!0,children:"SCROLL"})]},"scroll"),...X?.status==="running"?[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"i"}),i.jsx(c,{dimColor:!0,children:"INPUT"})]},"i")]:[],i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"⏎"}),i.jsx(c,{dimColor:!0,children:"FULLSCREEN"})]},"enter"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"Tab"}),i.jsx(c,{dimColor:!0,children:"PANEL"})]},"tab"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"?"}),i.jsx(c,{dimColor:!0,children:"HELP"})]},"?")]:le=[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"q"}),i.jsx(c,{dimColor:!0,children:"QUIT"})]},"q"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"?"}),i.jsx(c,{dimColor:!0,children:"HELP"})]},"?"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"↑↓"}),i.jsx(c,{dimColor:!0,children:"NAV"})]},"nav"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"/"}),i.jsx(c,{dimColor:!0,children:"FILTER"})]},"/"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"F"}),i.jsx(c,{dimColor:!0,children:"STATUS"})]},"F"),i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"⏎"}),i.jsx(c,{dimColor:!0,children:l.viewMode==="list"?"OUTPUT":"FULLSCREEN"})]},"enter"),...l.viewMode==="split"?[i.jsxs(m,{gap:1,children:[i.jsx(c,{bold:!0,color:"white",children:"Tab"}),i.jsx(c,{dimColor:!0,children:"PANEL"})]},"tab")]:[]];const we=i.jsxs(m,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",flexShrink:0,justifyContent:"space-between",children:[i.jsx(m,{flexGrow:1,flexWrap:"wrap",gap:2,paddingX:1,children:le}),i.jsx(m,{flexShrink:0,paddingX:1,children:Ie})]}),ye=i.jsxs(vr,{backgroundColor:"#1e1e1e",footer:i.jsxs(c,{dimColor:!0,children:[i.jsx(c,{bold:!0,color:"white",children:"↑↓"})," ","scroll"," ",i.jsx(c,{bold:!0,color:"white",children:"?"}),"/",i.jsx(c,{bold:!0,color:"white",children:"Esc"})," ","close"]}),scrollRef:A,title:"KEYBOARD SHORTCUTS",visible:M,width:52,children:[i.jsxs(m,{flexDirection:"column",marginBottom:1,children:[i.jsxs(m,{marginBottom:1,children:[i.jsx(c,{dimColor:!0,children:"── "}),i.jsx(c,{bold:!0,color:"white",children:"NAVIGATION"})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","↑","/k"]}),i.jsx(c,{dimColor:!0,children:" Move up"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","↓","/j"]}),i.jsx(c,{dimColor:!0,children:" Move down"})]})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","Tab"]}),i.jsx(c,{dimColor:!0,children:" Switch panel (split)"})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","Esc"]}),i.jsx(c,{dimColor:!0,children:" Back / close"})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","Enter"]}),i.jsx(c,{dimColor:!0,children:" Show output / fullscreen"})]})]}),i.jsxs(m,{flexDirection:"column",marginBottom:1,children:[i.jsxs(m,{marginBottom:1,children:[i.jsx(c,{dimColor:!0,children:"── "}),i.jsx(c,{bold:!0,color:"white",children:"VIEWS"})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","Enter"]}),i.jsxs(c,{dimColor:!0,children:[" ","List"," ","→"," ","Split"," ","→"," ","Fullscreen"]})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","Esc"]}),i.jsxs(c,{dimColor:!0,children:[" ","Fullscreen"," ","→"," ","Split"," ","→"," ","List"]})]})]}),i.jsxs(m,{flexDirection:"column",marginBottom:1,children:[i.jsxs(m,{marginBottom:1,children:[i.jsx(c,{dimColor:!0,children:"── "}),i.jsx(c,{bold:!0,color:"white",children:"ACTIONS"})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","/"]}),i.jsx(c,{dimColor:!0,children:" Filter by text"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","F"]}),i.jsx(c,{dimColor:!0,children:" Filter by status"})]})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","1"]}),i.jsx(c,{dimColor:!0,children:"/"}),i.jsx(c,{bold:!0,color:"white",children:"2"}),i.jsx(c,{dimColor:!0,children:" Pin to output pane"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","0"]}),i.jsx(c,{dimColor:!0,children:" Clear pins"})]})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","r"]}),i.jsx(c,{dimColor:!0,children:" Rerun all (done)"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","R"]}),i.jsx(c,{dimColor:!0,children:" Retry failed task"})]})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","i"]}),i.jsx(c,{dimColor:!0,children:" Interactive input (running task)"})]})]}),i.jsxs(m,{flexDirection:"column",marginBottom:1,children:[i.jsxs(m,{marginBottom:1,children:[i.jsx(c,{dimColor:!0,children:"── "}),i.jsx(c,{bold:!0,color:"white",children:"SCROLLING"}),i.jsx(c,{dimColor:!0,children:" (output panel)"})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","↑","/k"]}),i.jsx(c,{dimColor:!0,children:" Scroll up"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","↓","/j"]}),i.jsx(c,{dimColor:!0,children:" Scroll down"})]})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","^u"]}),i.jsx(c,{dimColor:!0,children:" Page up"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","^d"]}),i.jsx(c,{dimColor:!0,children:" Page down"})]})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","Home"]}),i.jsx(c,{dimColor:!0,children:" Top"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","End"]}),i.jsx(c,{dimColor:!0,children:" Bottom (resume follow)"})]})]}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","f"]}),i.jsx(c,{dimColor:!0,children:" Toggle auto-scroll (tail mode)"})]})]}),i.jsxs(m,{flexDirection:"column",children:[i.jsxs(m,{marginBottom:1,children:[i.jsx(c,{dimColor:!0,children:"── "}),i.jsx(c,{bold:!0,color:"white",children:"GENERAL"})]}),i.jsxs(m,{children:[i.jsx(m,{width:24,children:i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","q"]}),i.jsx(c,{dimColor:!0,children:" Quit"})]})}),i.jsxs(c,{children:[i.jsxs(c,{bold:!0,color:"white",children:[" ","?"]}),i.jsx(c,{dimColor:!0,children:" Toggle help"})]})]})]})]}),$e=i.jsx(xr,{autoExitSeconds:s>0?s:3,onCancel:()=>{te(!1)},visible:V}),be=G&&o?i.jsx(Cn,{activeIndex:z,focused:l.focusedPanel==="dock",store:o}):null;if(l.viewMode==="fullscreen")return i.jsxs(m,{flexDirection:"column",height:p,width:u,children:[i.jsx(m,{flexGrow:1,children:i.jsx(ns,{autoScroll:ue,duration:X?.duration??X?.elapsed,focused:!0,interactiveMode:l.interactiveMode,output:ge,scrollRef:F,status:Me,supportsInteractive:!x,taskId:Te})}),be,we,$e,ye]});if(l.viewMode==="split"){const T=u>=us,v=i.jsx(cs,{compact:!0,filterActive:l.filterActive,filterText:l.filterText,focused:l.focusedPanel==="tasks",headerStatus:ee,parallelSlots:t,pinnedTaskIds:l.pinnedTaskIds,rows:ae,scrollRef:S,selectedIndex:l.selectedIndex,title:Fe}),R=i.jsx(ns,{autoScroll:ue,duration:X?.duration??X?.elapsed,focused:l.focusedPanel==="output",interactiveMode:l.interactiveMode,output:ge,scrollRef:F,showFullscreenHint:!0,status:Me,supportsInteractive:!x,taskId:Te});if(T){const Oe=Math.floor(u*.4);return i.jsxs(m,{flexDirection:"column",height:p,width:u,children:[i.jsxs(m,{flexDirection:"row",flexGrow:1,children:[i.jsx(m,{width:Oe,children:v}),i.jsx(m,{flexGrow:1,children:R})]}),be,we,$e,ye]})}const Q=Math.floor(p*.45);return i.jsxs(m,{flexDirection:"column",height:p,width:u,children:[i.jsx(m,{height:Q,children:v}),i.jsx(m,{flexGrow:1,children:R}),be,we,$e,ye]})}return i.jsxs(m,{flexDirection:"column",height:p,width:u,children:[i.jsx(m,{flexGrow:1,children:i.jsx(cs,{filterActive:l.filterActive,filterText:l.filterText,focused:l.focusedPanel!=="dock",headerStatus:ee,parallelSlots:t,pinnedTaskIds:l.pinnedTaskIds,rows:ae,scrollRef:S,selectedIndex:l.selectedIndex,title:Fe})}),be,we,$e,ye]})},Mn=s=>{const{args:e,autoExit:t=!1,onRetryService:r,outputStyle:o="normal",projectNames:a,serviceDockStore:n,stdinRegistry:d,tasks:h,totalTaskCount:f}=s,u=new rt(h,f),p=typeof e.parallel=="number"?e.parallel:3,l=t===!0?3:typeof t=="number"?t:0;let $,I;const G=new Promise(S=>{I=S});let z;const b=()=>{z&&(clearInterval(z),z=void 0)},x=()=>{if(process.stdin.isTTY&&typeof process.stdin.setRawMode=="function")try{process.stdin.setRawMode(!1)}catch{}process.stdin.pause(),process.stdin.unref()},O=()=>{if(d){for(const S of d.values())S.kill?.();d.clear()}},k=()=>{b(),A(),O(),x(),process.stdout.write("\x1B[?1049l\x1B[?25h"),$?.cleanup(),process.exit(1)},M=()=>{const S=u.getSnapshot(),F=De(Date.now()-S.startTime),V=S.rows.filter(q=>q.status==="failure").map(q=>q.taskId),te=process.stdout.columns||80;process.stdout.write(`
20
- `);for(const q of S.rows){const{persistent:Y,status:ce,taskId:re}=q,ie=ce==="running"||ce==="pending",ae=_e(ce),_=ie&&Y?"■":ae.icon,H=ie&&Y?"gray":ae.color;let X="";switch(ce){case"local-cache":case"local-cache-kept-existing":{X=" [local cache]";break}case"remote-cache":{X=" [remote cache]";break}case"skipped":{X=" [skipped]";break}default:{ie&&Y?X=" [stopped]":ie&&(X=" [skipped]");break}}const he=q.retryAttempts&&q.retryAttempts>0?` [retried ${q.retryAttempts}x]`:"",C=pe(K.createElement(c,null," ",K.createElement(c,{color:H},_),` vis run ${re}`,X?K.createElement(c,{dimColor:!0},` ${X}`):null,he?K.createElement(c,{color:"yellow"},he):null),{columns:te});process.stdout.write(`${C}
15
+ ${s}`}catch{return s}},xn={delimiter:" ",language:{d:()=>" d",future:"in %s",h:()=>" h",m:()=>" m",mo:()=>" mo",ms:()=>" ms",past:"%s ago",s:()=>" s",w:()=>" w",y:()=>" y"},largest:2,round:!0,spacer:"",units:["h","m","s","ms"]},De=s=>Pi(s,xn),Ne=s=>s==="local-cache"||s==="local-cache-kept-existing"||s==="remote-cache",_e=s=>{switch(s){case"failure":return{color:"red",icon:Is};case"local-cache":case"local-cache-kept-existing":case"remote-cache":case"success":return{color:"green",icon:Cs};case"skipped":return{color:"gray",icon:ot};default:return{color:"gray",icon:"?"}}},ze=s=>{const{color:e,icon:t}=_e(s);return he(K.createElement(c,{color:e},t),{columns:10}).trim()},jn=s=>{const{color:e,icon:t}=_e(s);switch(s){case"local-cache":case"local-cache-kept-existing":case"remote-cache":return he(K.createElement(c,null,K.createElement(c,{color:e},t)," ",K.createElement(c,{color:"cyan"},"[cache]")),{columns:30}).trim();case"skipped":return he(K.createElement(c,null,K.createElement(c,{dimColor:!0},t)," ",K.createElement(c,{dimColor:!0},"[skipped]")),{columns:30}).trim();default:return he(K.createElement(c,{color:e},t),{columns:10}).trim()}},$n=s=>s==="azure"||s==="buildkite"||s==="github"||s==="gitlab"||s==="off"?s:process.env.GITHUB_ACTIONS==="true"?"github":process.env.GITLAB_CI==="true"?"gitlab":process.env.BUILDKITE==="true"?"buildkite":process.env.TF_BUILD?.toLowerCase()==="true"?"azure":"off",bn=s=>{const e=s.replaceAll(/\W+/g,"_"),t=Ti("sha256").update(s).digest("hex").slice(0,6);return`${e}_${t}`},Sn=(s,e,t,r="auto")=>{const o=t.trim();if(!o)return;const a=`
16
+ `,i=$n(r);if(i==="github"){process.stdout.write(`::group::${ze(e)} ${s}${a}`),process.stdout.write(o+a),process.stdout.write(`::endgroup::${a}`);return}if(i==="gitlab"){const p=Math.floor(Date.now()/1e3),l=bn(s),$=e==="failure"?"":"[collapsed=true]",R="\x1B[0K";process.stdout.write(`${R}section_start:${String(p)}:${l}${$}\r${R}${ze(e)} ${s}${a}`),process.stdout.write(o+a);const G=Math.floor(Date.now()/1e3);process.stdout.write(`${R}section_end:${String(G)}:${l}\r${R}${a}`);return}if(i==="buildkite"){const p=e==="failure"?"+++":"---";process.stdout.write(`${p} ${ze(e)} ${s}${a}`),process.stdout.write(o+a);return}if(i==="azure"){process.stdout.write(`##[group]${ze(e)} ${s}${a}`),process.stdout.write(o+a),process.stdout.write(`##[endgroup]${a}`);return}const d=process.stdout.columns||80,u=he(K.createElement(c,{dimColor:!0},ot.repeat(d)),{columns:d}).trim(),f=jn(e),h=he(K.createElement(c,{bold:!0},s),{columns:d}).trim();process.stdout.write(`${u}${a}`),process.stdout.write(`${f} ${h}${a}`),process.stdout.write(o+a),process.stdout.write(`${u}${a}`)},Tn=s=>s==="running"?{color:"white",icon:"•"}:s==="pending"?{color:"gray",icon:"·"}:_e(s),Cn=({autoScroll:s,focused:e,interactiveMode:t,showFullscreenHint:r,statusValue:o,supportsInteractive:a,taskId:i})=>{if(!i)return;if(t)return"Esc cancel | Enter send";const d=s?"":" PAUSED (f resume)",u=a?" i INPUT":"";return e&&o==="running"&&r?`⏎ FULLSCREEN${u} f FOLLOW${d}`:e&&o==="running"?`f FOLLOW${u}${d}`:e&&r?`<enter> full screen${d}`:e?d||void 0:"<tab> or <enter> to focus"},ls=({autoScroll:s=!0,duration:e,focused:t,interactiveMode:r,output:o,scrollRef:a,showFullscreenHint:i,status:d,supportsInteractive:u=!0,taskId:f})=>{const h=d??"pending",{icon:p}=Tn(h),l=t?"bold":"single",$=h==="failure"?"red":h==="success"||Ne(h)?t?"green":"gray":h==="running"?t?"white":"cyan":t?"white":"gray",R=f?`${p} ${f}`:void 0,G=e===void 0?void 0:De(e),V=Cn({autoScroll:s,focused:t,interactiveMode:r??!1,showFullscreenHint:i??!1,statusValue:h,supportsInteractive:u,taskId:f});if(!f)return n.jsxs(m,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",paddingX:2,paddingY:1,children:[n.jsx(c,{dimColor:!0,children:"Select a task to view output"}),n.jsx(c,{dimColor:!0,children:"Press Enter or 1/2 to pin"})]});const j=[];if(o)for(const I of o.split(`
17
+ `))j.push(I.endsWith("\r")?I.slice(0,-1):I);return!o&&(h==="running"||h==="pending")?n.jsx(m,{borderBottomTitle:V,borderColor:$,borderStyle:l,borderTopRightTitle:G,borderTopTitle:R,flexDirection:"column",flexGrow:1,paddingX:2,paddingY:1,children:n.jsx(m,{alignItems:"center",flexGrow:1,justifyContent:"center",children:n.jsx(c,{dimColor:!0,children:"Waiting for task output…"})})}):n.jsxs(m,{borderBottomTitle:V,borderColor:r?"yellow":$,borderStyle:l,borderTopRightTitle:G,borderTopTitle:R,flexDirection:"column",flexGrow:1,children:[n.jsx(m,{flexGrow:1,flexShrink:1,paddingY:1,children:n.jsx(bs,{flexGrow:1,followOutput:s,paddingX:2,ref:a,scrollbar:!0,scrollbarColor:"gray",scrollbarStyle:"block",children:n.jsx(c,{children:j.join(`
18
+ `)})})}),r&&n.jsx(m,{flexShrink:0,justifyContent:"center",paddingX:1,children:n.jsx(c,{bold:!0,color:"yellow",children:"INTERACTIVE | keystrokes forwarded to task | Esc to exit"})})]})},In={crashed:"✖",failed:"✖",pending:"·",ready:"●",starting:"•"},Gs=s=>s==="ready"?"green":s==="crashed"||s==="failed"?"red":s==="starting"?"cyan":"gray",Rn=({status:s})=>s==="starting"?n.jsx(c,{color:"cyan",children:n.jsx(Es,{type:"dots"})}):n.jsx(c,{bold:!0,color:Gs(s),children:In[s]}),En=({active:s,focused:e,state:t})=>{const r=e&&s,o=r?">":" ",a=t.status==="ready"?t.port?`running, port ${String(t.port)}`:"running":t.status==="failed"||t.status==="crashed"?t.errorMessage??"exited":t.lastLine??"booting…";return n.jsxs(m,{flexDirection:"row",flexShrink:0,overflow:"hidden",children:[n.jsx(c,{children:o}),n.jsx(c,{children:" "}),n.jsx(m,{flexShrink:0,width:3,children:n.jsx(Rn,{status:t.status})}),n.jsx(m,{flexGrow:0,flexShrink:0,width:28,children:n.jsx(c,{bold:r,inverse:r,children:t.id})}),n.jsx(m,{flexGrow:1,flexShrink:1,overflow:"hidden",children:n.jsxs(c,{color:Gs(t.status),dimColor:t.status!=="crashed"&&t.status!=="failed",wrap:"truncate-end",children:[" ",a]})})]})},Mn=({states:s})=>{const e=[];for(const r of s)r.status==="ready"&&e.push(r.id);const t=e.join(", ");return n.jsxs(m,{paddingX:1,children:[n.jsxs(c,{bold:!0,color:"green",children:["● ","Services"]}),n.jsxs(c,{children:[" ",String(e.length)," / ",String(s.length)," running"]}),t.length>0&&n.jsxs(c,{dimColor:!0,children:[" ",t]}),n.jsx(c,{dimColor:!0,children:" [Tab ↓]"})]})},Fn=({states:s})=>{const e=s.find(t=>t.status==="crashed"||t.status==="failed");return e?n.jsxs(m,{flexDirection:"column",paddingX:1,children:[n.jsxs(c,{bold:!0,color:"red",children:["✖ ","Service crashed:"," ",e.id]}),e.tailLines.slice(-3).map((t,r)=>n.jsxs(c,{color:"red",dimColor:!0,children:[" ",t]},`crash-${String(r)}`))]}):n.jsx(n.Fragment,{})},On=({activeIndex:s,focused:e,store:t})=>{const r=z.useSyncExternalStore(t.subscribe,t.getSnapshot),o=t.getIds();if(o.length===0)return n.jsx(n.Fragment,{});const a=o.map(h=>r.get(h)).filter(h=>h!==void 0),i=t.getDockState(),d=i==="crash"?"red":i==="ready"?"gray":e?"white":"cyan",u=i==="crash"?"Services (crashed)":i==="ready"?"Services":"Services (starting)",f=e?i==="crash"?"↑↓ select Enter logs R retry Esc back":"↑↓ select Enter logs Esc back":"Tab to focus services";return i==="ready"&&!e?n.jsx(m,{borderColor:d,borderStyle:"single",flexDirection:"row",flexShrink:0,children:n.jsx(Mn,{states:a})}):n.jsxs(m,{borderBottomTitle:f,borderColor:d,borderStyle:e?"bold":"single",borderTopTitle:u,flexDirection:"column",flexGrow:2,flexShrink:0,minHeight:6,paddingX:1,children:[i==="crash"&&n.jsx(Fn,{states:a}),a.map((h,p)=>n.jsx(En,{active:p===s,focused:e,state:h},h.id))]})},_s=6,qs=8,Ws=12,Pn=s=>s==="running"||s==="pending"?Rs:s==="local-cache"||s==="local-cache-kept-existing"?"Local":s==="remote-cache"?"Remote":ot,ds=(s,e)=>e[0]===s?"[1]":e[1]===s?"[2]":"",us=({compact:s,focused:e,isSelected:t,pinLabel:r,row:o})=>{const{persistent:a,status:i,taskId:d}=o,u=e&&t,f=u?">":" ",h=i==="running"&&a===!0;let p;if(h)p=n.jsx(c,{bold:!0,color:"green",children:" ● "});else if(i==="running")p=n.jsxs(c,{bold:!0,color:"white",children:[" ",n.jsx(Es,{type:"dots"})," "]});else if(i==="pending")p=n.jsx(c,{bold:!0,color:"gray",children:" · "});else{const{color:$,icon:R}=_e(i);p=n.jsxs(c,{bold:!0,color:$,children:[" ",R," "]})}let l=Rs;return h?l="running":i!=="running"&&i!=="pending"?l=o.duration===void 0?ot:De(o.duration):i==="running"&&o.elapsed!==void 0&&(l=De(o.elapsed)),n.jsxs(m,{children:[n.jsx(c,{children:f}),n.jsx(m,{width:_s,children:p}),n.jsxs(m,{flexGrow:1,children:[n.jsx(c,{bold:u,inverse:u,children:d}),r?n.jsx(c,{dimColor:!0,children:` ${r}`}):null]}),!s&&n.jsx(m,{justifyContent:"flex-end",width:qs,children:n.jsx(c,{dimColor:!Ne(i),children:Pn(i)})}),!s&&n.jsx(m,{justifyContent:"flex-end",width:Ws,children:n.jsx(c,{color:h?"green":void 0,dimColor:i==="pending"||h,children:l})})]})},hs=({compact:s,filterActive:e,filterText:t,focused:r,headerStatus:o,parallelSlots:a=3,pinnedTaskIds:i,rows:d,scrollRef:u,selectedIndex:f,title:h})=>{const p=o==="error"?"red":o==="success"?"green":r?"white":"gray",l=d[f]?.taskId,$=[];let R=0;for(const I of d)I.status==="running"?$.push(I):I.status==="pending"&&(R+=1);const G=Math.min(a,$.length+R),V=G>1,j=[];if(V)for(let I=0;I<G;I++){const S=$[I];S?j.push(n.jsx(us,{compact:s,focused:r,isSelected:S.taskId===l,pinLabel:ds(S.taskId,i),row:S},`par-${S.taskId}`)):j.push(n.jsxs(m,{children:[n.jsx(c,{children:" "}),n.jsx(m,{width:_s,children:n.jsx(c,{bold:!0,color:"gray",children:" · "})}),n.jsx(c,{dimColor:!0,children:"Waiting for task..."})]},`par-empty-${String(I)}`))}return n.jsxs(m,{borderColor:p,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[n.jsxs(m,{flexShrink:0,paddingX:1,children:[n.jsx(c,{bold:!0,inverse:!0,children:" VIS "}),n.jsx(c,{children:` ${h}`}),!s&&n.jsxs(m,{flexGrow:1,gap:0,justifyContent:"flex-end",children:[n.jsx(m,{justifyContent:"flex-end",width:qs,children:n.jsx(c,{dimColor:!0,children:"Cache"})}),n.jsx(m,{justifyContent:"flex-end",width:Ws,children:n.jsx(c,{dimColor:!0,children:"Duration"})})]})]}),n.jsx(bs,{flexGrow:1,flexShrink:1,paddingX:1,paddingY:1,ref:u,scrollbar:!0,scrollbarColor:"gray",scrollbarStyle:"block",children:d.map(I=>n.jsx(us,{compact:s,focused:r,isSelected:I.taskId===l,pinLabel:ds(I.taskId,i),row:I},I.taskId))}),V&&n.jsx(m,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",borderTop:!0,flexDirection:"column",flexShrink:0,paddingX:1,paddingY:1,children:j}),e&&n.jsxs(m,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",borderTop:!0,flexShrink:0,paddingX:1,children:[n.jsx(c,{bold:!0,color:"white",children:"/ "}),n.jsx(c,{children:t}),n.jsx(c,{inverse:!0,children:" "})]})]})},fs=40,ps=10,gs=100,An=Object.freeze([]),Dn=({autoExitSeconds:s,onRetryService:e,parallelSlots:t,projectNames:r,serviceDockStore:o,stdinRegistry:a,store:i,targets:d,tasks:u})=>{const{exit:f}=$r(),{columns:h,rows:p}=br(),l=z.useSyncExternalStore(i.subscribe,i.getSnapshot),$=z.useCallback(T=>o?o.subscribe(T):()=>{},[o]);z.useSyncExternalStore($,()=>o?o.getDockState():"ready");const R=o?o.getIds():An,G=R.length>0,[V,j]=z.useState(0),[I,S]=z.useState(null),x=z.useSyncExternalStore($,()=>I&&o?o.getState(I):void 0),[O,w]=z.useState(!1),A=z.useRef(null),b=z.useRef(null),M=z.useRef(null),[H,te]=z.useState(!1),[fe,W]=z.useState(!0),Y=z.useRef({list:0,splitList:0,splitOutput:0}),ce=z.useCallback(()=>{l.viewMode==="list"?Y.current.list=b.current?.getScrollOffset()??0:l.viewMode==="split"&&(Y.current.splitList=b.current?.getScrollOffset()??0,Y.current.splitOutput=M.current?.getScrollOffset()??0)},[l.viewMode]),re=z.useCallback(T=>{setTimeout(()=>{if(T==="list"){const v=Y.current.list;b.current?.scrollTo(v)}else if(T==="split"){const v=Y.current.splitList;v>0?b.current?.scrollTo(v):b.current?.scrollTo(Math.max(0,i.getSnapshot().selectedIndex-2)),M.current?.scrollTo(Y.current.splitOutput)}},0)},[i]),ae=z.useRef(!1);z.useEffect(()=>{l.done&&!ae.current&&(ae.current=!0,s>0&&l.failed===0&&te(!0)),!l.done&&ae.current&&(ae.current=!1,te(!1))},[l.done,l.failed,s]);const ne=z.useMemo(()=>{const T=R.length>0?new Set(R):null,v=l.filterText?l.filterText.toLowerCase():null,C=[];for(const ee of l.rows)T?.has(ee.taskId)||l.statusFilter==="failed"&&ee.status!=="failure"||l.statusFilter==="running"&&ee.status!=="running"&&ee.status!=="pending"||l.statusFilter==="passed"&&ee.status!=="success"&&!Ne(ee.status)||v&&!ee.taskId.toLowerCase().includes(v)||C.push(ee);return C},[l.rows,l.filterText,l.statusFilter,R]),U=(ne[l.selectedIndex]??null)?.taskId??null,_=I?null:l.pinnedTaskIds[0]??U,X=_?l.rows.find(T=>T.taskId===_):null,pe=x??null,je=I?(pe?.tailLines??[]).join(`
19
+ `):_?l.outputs.get(_)??"":"",E=z.useMemo(()=>X?.status==="failure"&&je?Ns(je,{color:!process.env.NO_COLOR,cwd:process.cwd()}):je,[X?.status,je]),ge=I??_,Ie=I?pe?.status==="crashed"||pe?.status==="failed"?"failure":"running":X?.status,Me=xt(r,d,u),Le=l.done?`Completed ${Me} (${De((l.endTime??Date.now())-l.startTime)})`:`Running ${Me}...`,Fe=l.done?l.failed>0?"error":"success":"running",Z=z.useCallback(T=>{b.current?.scrollTo(Math.max(0,T-2))},[]);if(z.useEffect(()=>{l.interactiveMode&&X?.status!=="running"&&i.setInteractiveMode(!1)},[l.interactiveMode,X?.status,i]),z.useEffect(()=>{if(!_)return;let T=h;l.viewMode==="split"&&h>=gs?T=h-Math.floor(h*.4)-2:(l.viewMode==="split"||l.viewMode==="fullscreen")&&(T=h-2);const v=Math.max(1,p-4);a.get(_)?.resize?.(T,v)},[h,p,l.viewMode,_]),Kt((T,v)=>{if(v.escape){i.setInteractiveMode(!1);return}if(!_)return;const C=a.get(_);if(!C){i.setInteractiveMode(!1);return}if(v.return)C.write("\r");else if(v.upArrow)C.write("\x1B[A");else if(v.downArrow)C.write("\x1B[B");else if(v.rightArrow)C.write("\x1B[C");else if(v.leftArrow)C.write("\x1B[D");else if(v.backspace)C.write("");else if(v.delete)C.write("\x1B[3~");else if(v.tab)C.write(" ");else if(v.home)C.write("\x1B[H");else if(v.end)C.write("\x1B[F");else if(v.pageUp)C.write("\x1B[5~");else if(v.pageDown)C.write("\x1B[6~");else if(v.ctrl&&T){const ee=T.toUpperCase().codePointAt(0);ee!==void 0&&ee>=65&&ee<=90&&C.write(String.fromCodePoint(ee-64))}else T&&C.write(T)},{isActive:l.interactiveMode}),Kt((T,v)=>{if(T==="c"&&v.ctrl){f();return}if(!H){if(O){v.escape||T==="?"?w(!1):T==="q"?(w(!1),te(!0)):v.downArrow||T==="j"?A.current?.scrollBy(1):v.upArrow||T==="k"?A.current?.scrollBy(-1):v.pageDown?A.current?.scrollBy(5):v.pageUp?A.current?.scrollBy(-5):v.home?A.current?.scrollToTop():v.end&&A.current?.scrollToBottom();return}if(T==="?"){w(!0);return}if(T==="q"){te(!0);return}if(T==="r"&&l.done){i.requestRerun();return}if(T==="R"&&l.done){const C=ne[l.selectedIndex];C?.status==="failure"&&i.requestRetry(C.taskId);return}if(T==="F"&&!l.filterActive){const C=["all","failed","running","passed"],ee=C.indexOf(l.statusFilter);i.setStatusFilter(C[(ee+1)%C.length]);return}if(l.filterActive){if(v.escape){i.setFilterActive(!1);return}if(v.return){i.setFilterActive(!1);return}if(v.backspace){i.setFilter(l.filterText.slice(0,-1));return}if(T&&!v.ctrl&&!v.meta){i.setFilter(l.filterText+T);return}return}if(T==="i"&&X?.status==="running"&&(l.viewMode==="fullscreen"||l.viewMode==="split"&&l.focusedPanel==="output")){i.setInteractiveMode(!0);return}if(l.viewMode==="fullscreen"){if(v.escape){i.setViewMode("split"),re("split");return}if(T==="f"){const C=!fe;W(C),C&&M.current?.scrollToBottom();return}if(v.downArrow||T==="j"){W(!1),M.current?.scrollBy(1);return}if(v.upArrow||T==="k"){W(!1),M.current?.scrollBy(-1);return}if(v.pageDown||v.ctrl&&T==="d"){W(!1),M.current?.scrollBy(12);return}if(v.pageUp||v.ctrl&&T==="u"){W(!1),M.current?.scrollBy(-12);return}if(v.home){W(!1),M.current?.scrollToTop();return}if(v.end){W(!0),M.current?.scrollToBottom();return}return}if(l.focusedPanel==="dock"&&G&&o){if(v.tab){S(null),i.setFocusedPanel("tasks");return}if(v.escape){i.setFocusedPanel("tasks"),S(null),l.viewMode==="split"&&(i.setViewMode("list"),re("list"));return}if(v.downArrow||T==="j"){j(C=>Math.min(C+1,R.length-1));return}if(v.upArrow||T==="k"){j(C=>Math.max(C-1,0));return}if(v.return){const C=R[V];C&&(S(C),W(!0),ce(),Y.current.splitList=0,Y.current.splitOutput=0,i.setViewMode("split"),i.setFocusedPanel("output"),re("split"));return}if((T==="r"||T==="R")&&e){const C=R[V],ee=C?o.getState(C)?.status:void 0;if(C&&(ee==="crashed"||ee==="failed")){const Te=e(C);Te instanceof Promise&&Te.catch(()=>{})}return}return}if(l.viewMode==="split"){if(v.tab){l.focusedPanel==="tasks"?i.setFocusedPanel("output"):G?i.setFocusedPanel("dock"):(S(null),i.setFocusedPanel("tasks"));return}if(l.focusedPanel==="output"){if(v.escape){if(I&&G){S(null),i.setViewMode("list"),i.setFocusedPanel("dock"),re("list");return}S(null),i.setFocusedPanel("tasks");return}if(v.return){ce(),i.setViewMode("fullscreen");return}if(T==="f"){const C=!fe;W(C),C&&M.current?.scrollToBottom();return}if(v.downArrow||T==="j"){W(!1),M.current?.scrollBy(1);return}if(v.upArrow||T==="k"){W(!1),M.current?.scrollBy(-1);return}if(v.pageDown||v.ctrl&&T==="d"){W(!1),M.current?.scrollBy(12);return}if(v.pageUp||v.ctrl&&T==="u"){W(!1),M.current?.scrollBy(-12);return}if(v.home){W(!1),M.current?.scrollToTop();return}if(v.end){W(!0),M.current?.scrollToBottom();return}return}if(v.escape){i.setViewMode("list"),re("list");return}if(v.return){i.setFocusedPanel("output");return}}if(l.viewMode==="list"||l.viewMode==="split"&&l.focusedPanel==="tasks"){if(v.tab&&l.viewMode==="list"&&G){i.setFocusedPanel("dock");return}if(v.downArrow||T==="j"){const C=Math.min(l.selectedIndex+1,Math.max(0,ne.length-1));i.setSelectedIndex(C),Z(C);return}if(v.upArrow||T==="k"){const C=Math.max(l.selectedIndex-1,0);i.setSelectedIndex(C),Z(C);return}if(v.return&&l.viewMode==="list"){W(!0),ce(),Y.current.splitList=0,Y.current.splitOutput=0,i.setViewMode("split"),i.setFocusedPanel("output"),re("split");return}if(T==="/"){i.setFilterActive(!0);return}if(T==="1"&&U){i.pinTask(0,U);return}if(T==="2"&&U){i.pinTask(1,U);return}if(T==="0"){i.clearPins();return}v.escape&&l.filterText&&i.setFilter("")}}},{isActive:!l.interactiveMode}),h<fs||p<ps)return n.jsx(m,{alignItems:"center",height:p,justifyContent:"center",width:h,children:n.jsxs(c,{color:"yellow",children:["Terminal too small (",h,"x",p,"). Minimum:"," ",fs,"x",ps]})});const Oe=n.jsxs(m,{gap:1,children:[l.succeeded>0&&n.jsxs(c,{bold:!0,color:"green",children:["✓"," ",l.succeeded]}),l.cached>0&&n.jsxs(c,{dimColor:!0,children:["✓"," ",l.cached]}),l.failed>0&&n.jsxs(c,{bold:!0,color:"red",children:["✗"," ",l.failed]}),l.running>0&&n.jsxs(c,{color:"cyan",children:["◷"," ",l.running]}),n.jsxs(c,{dimColor:!0,children:[l.totalTasks," ","total"]}),l.statusFilter!=="all"&&n.jsxs(c,{color:"yellow",children:["[",l.statusFilter,"]"]})]});let we;if(l.viewMode==="fullscreen")we=[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"Esc"}),n.jsx(c,{dimColor:!0,children:"BACK"})]},"esc"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"↑↓"}),n.jsx(c,{dimColor:!0,children:"SCROLL"})]},"scroll"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"^u ^d"}),n.jsx(c,{dimColor:!0,children:"PAGE"})]},"page"),...X?.status==="running"?[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"i"}),n.jsx(c,{dimColor:!0,children:"INPUT"})]},"i")]:[],n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"q"}),n.jsx(c,{dimColor:!0,children:"QUIT"})]},"q")];else if(l.done){const T=ne[l.selectedIndex]?.status==="failure";we=[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"q"}),n.jsx(c,{dimColor:!0,children:"QUIT"})]},"q"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"r"}),n.jsx(c,{dimColor:!0,children:"RERUN"})]},"r"),...T?[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"R"}),n.jsx(c,{dimColor:!0,children:"RETRY"})]},"R")]:[],n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"?"}),n.jsx(c,{dimColor:!0,children:"HELP"})]},"?"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"↑↓"}),n.jsx(c,{dimColor:!0,children:"NAV"})]},"nav"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"F"}),n.jsx(c,{dimColor:!0,children:"FILTER"})]},"F"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"⏎"}),n.jsx(c,{dimColor:!0,children:l.viewMode==="list"?"OUTPUT":"FULLSCREEN"})]},"enter")]}else l.viewMode==="split"&&l.focusedPanel==="output"?we=[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"q"}),n.jsx(c,{dimColor:!0,children:"QUIT"})]},"q"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"Esc"}),n.jsx(c,{dimColor:!0,children:"BACK"})]},"esc"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"↑↓"}),n.jsx(c,{dimColor:!0,children:"SCROLL"})]},"scroll"),...X?.status==="running"?[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"i"}),n.jsx(c,{dimColor:!0,children:"INPUT"})]},"i")]:[],n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"⏎"}),n.jsx(c,{dimColor:!0,children:"FULLSCREEN"})]},"enter"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"Tab"}),n.jsx(c,{dimColor:!0,children:"PANEL"})]},"tab"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"?"}),n.jsx(c,{dimColor:!0,children:"HELP"})]},"?")]:we=[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"q"}),n.jsx(c,{dimColor:!0,children:"QUIT"})]},"q"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"?"}),n.jsx(c,{dimColor:!0,children:"HELP"})]},"?"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"↑↓"}),n.jsx(c,{dimColor:!0,children:"NAV"})]},"nav"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"/"}),n.jsx(c,{dimColor:!0,children:"FILTER"})]},"/"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"F"}),n.jsx(c,{dimColor:!0,children:"STATUS"})]},"F"),n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"⏎"}),n.jsx(c,{dimColor:!0,children:l.viewMode==="list"?"OUTPUT":"FULLSCREEN"})]},"enter"),...l.viewMode==="split"?[n.jsxs(m,{gap:1,children:[n.jsx(c,{bold:!0,color:"white",children:"Tab"}),n.jsx(c,{dimColor:!0,children:"PANEL"})]},"tab")]:[]];const de=n.jsxs(m,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",flexShrink:0,justifyContent:"space-between",children:[n.jsx(m,{flexGrow:1,flexWrap:"wrap",gap:2,paddingX:1,children:we}),n.jsx(m,{flexShrink:0,paddingX:1,children:Oe})]}),ye=n.jsxs(Sr,{backgroundColor:"#1e1e1e",footer:n.jsxs(c,{dimColor:!0,children:[n.jsx(c,{bold:!0,color:"white",children:"↑↓"})," ","scroll"," ",n.jsx(c,{bold:!0,color:"white",children:"?"}),"/",n.jsx(c,{bold:!0,color:"white",children:"Esc"})," ","close"]}),scrollRef:A,title:"KEYBOARD SHORTCUTS",visible:O,width:52,children:[n.jsxs(m,{flexDirection:"column",marginBottom:1,children:[n.jsxs(m,{marginBottom:1,children:[n.jsx(c,{dimColor:!0,children:"── "}),n.jsx(c,{bold:!0,color:"white",children:"NAVIGATION"})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","↑","/k"]}),n.jsx(c,{dimColor:!0,children:" Move up"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","↓","/j"]}),n.jsx(c,{dimColor:!0,children:" Move down"})]})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","Tab"]}),n.jsx(c,{dimColor:!0,children:" Switch panel (split)"})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","Esc"]}),n.jsx(c,{dimColor:!0,children:" Back / close"})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","Enter"]}),n.jsx(c,{dimColor:!0,children:" Show output / fullscreen"})]})]}),n.jsxs(m,{flexDirection:"column",marginBottom:1,children:[n.jsxs(m,{marginBottom:1,children:[n.jsx(c,{dimColor:!0,children:"── "}),n.jsx(c,{bold:!0,color:"white",children:"VIEWS"})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","Enter"]}),n.jsxs(c,{dimColor:!0,children:[" ","List"," ","→"," ","Split"," ","→"," ","Fullscreen"]})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","Esc"]}),n.jsxs(c,{dimColor:!0,children:[" ","Fullscreen"," ","→"," ","Split"," ","→"," ","List"]})]})]}),n.jsxs(m,{flexDirection:"column",marginBottom:1,children:[n.jsxs(m,{marginBottom:1,children:[n.jsx(c,{dimColor:!0,children:"── "}),n.jsx(c,{bold:!0,color:"white",children:"ACTIONS"})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","/"]}),n.jsx(c,{dimColor:!0,children:" Filter by text"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","F"]}),n.jsx(c,{dimColor:!0,children:" Filter by status"})]})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","1"]}),n.jsx(c,{dimColor:!0,children:"/"}),n.jsx(c,{bold:!0,color:"white",children:"2"}),n.jsx(c,{dimColor:!0,children:" Pin to output pane"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","0"]}),n.jsx(c,{dimColor:!0,children:" Clear pins"})]})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","r"]}),n.jsx(c,{dimColor:!0,children:" Rerun all (done)"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","R"]}),n.jsx(c,{dimColor:!0,children:" Retry failed task"})]})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","i"]}),n.jsx(c,{dimColor:!0,children:" Interactive input (running task)"})]})]}),n.jsxs(m,{flexDirection:"column",marginBottom:1,children:[n.jsxs(m,{marginBottom:1,children:[n.jsx(c,{dimColor:!0,children:"── "}),n.jsx(c,{bold:!0,color:"white",children:"SCROLLING"}),n.jsx(c,{dimColor:!0,children:" (output panel)"})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","↑","/k"]}),n.jsx(c,{dimColor:!0,children:" Scroll up"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","↓","/j"]}),n.jsx(c,{dimColor:!0,children:" Scroll down"})]})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","^u"]}),n.jsx(c,{dimColor:!0,children:" Page up"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","^d"]}),n.jsx(c,{dimColor:!0,children:" Page down"})]})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","Home"]}),n.jsx(c,{dimColor:!0,children:" Top"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","End"]}),n.jsx(c,{dimColor:!0,children:" Bottom (resume follow)"})]})]}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","f"]}),n.jsx(c,{dimColor:!0,children:" Toggle auto-scroll (tail mode)"})]})]}),n.jsxs(m,{flexDirection:"column",children:[n.jsxs(m,{marginBottom:1,children:[n.jsx(c,{dimColor:!0,children:"── "}),n.jsx(c,{bold:!0,color:"white",children:"GENERAL"})]}),n.jsxs(m,{children:[n.jsx(m,{width:24,children:n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","q"]}),n.jsx(c,{dimColor:!0,children:" Quit"})]})}),n.jsxs(c,{children:[n.jsxs(c,{bold:!0,color:"white",children:[" ","?"]}),n.jsx(c,{dimColor:!0,children:" Toggle help"})]})]})]})]}),ve=n.jsx(Tr,{autoExitSeconds:s>0?s:3,onCancel:()=>{te(!1)},visible:H}),Se=G&&o?n.jsx(On,{activeIndex:V,focused:l.focusedPanel==="dock",store:o}):null;if(l.viewMode==="fullscreen")return n.jsxs(m,{flexDirection:"column",height:p,width:h,children:[n.jsx(m,{flexGrow:1,children:n.jsx(ls,{autoScroll:fe,duration:X?.duration??X?.elapsed,focused:!0,interactiveMode:l.interactiveMode,output:E,scrollRef:M,status:Ie,supportsInteractive:!I,taskId:ge})}),Se,de,ve,ye]});if(l.viewMode==="split"){const T=h>=gs,v=n.jsx(hs,{compact:!0,filterActive:l.filterActive,filterText:l.filterText,focused:l.focusedPanel==="tasks",headerStatus:Fe,parallelSlots:t,pinnedTaskIds:l.pinnedTaskIds,rows:ne,scrollRef:b,selectedIndex:l.selectedIndex,title:Le}),C=n.jsx(ls,{autoScroll:fe,duration:X?.duration??X?.elapsed,focused:l.focusedPanel==="output",interactiveMode:l.interactiveMode,output:E,scrollRef:M,showFullscreenHint:!0,status:Ie,supportsInteractive:!I,taskId:ge});if(T){const Te=Math.floor(h*.4);return n.jsxs(m,{flexDirection:"column",height:p,width:h,children:[n.jsxs(m,{flexDirection:"row",flexGrow:1,children:[n.jsx(m,{width:Te,children:v}),n.jsx(m,{flexGrow:1,children:C})]}),Se,de,ve,ye]})}const ee=Math.floor(p*.45);return n.jsxs(m,{flexDirection:"column",height:p,width:h,children:[n.jsx(m,{height:ee,children:v}),n.jsx(m,{flexGrow:1,children:C}),Se,de,ve,ye]})}return n.jsxs(m,{flexDirection:"column",height:p,width:h,children:[n.jsx(m,{flexGrow:1,children:n.jsx(hs,{filterActive:l.filterActive,filterText:l.filterText,focused:l.focusedPanel!=="dock",headerStatus:Fe,parallelSlots:t,pinnedTaskIds:l.pinnedTaskIds,rows:ne,scrollRef:b,selectedIndex:l.selectedIndex,title:Le})}),Se,de,ve,ye]})},Ln=s=>{const{args:e,autoExit:t=!1,onRetryService:r,outputStyle:o="normal",projectNames:a,serviceDockStore:i,stdinRegistry:d,tasks:u,totalTaskCount:f}=s,h=new rt(u,f),p=typeof e.parallel=="number"?e.parallel:3,l=t===!0?3:typeof t=="number"?t:0;let $,R;const G=new Promise(b=>{R=b});let V;const j=()=>{V&&(clearInterval(V),V=void 0)},I=()=>{if(process.stdin.isTTY&&typeof process.stdin.setRawMode=="function")try{process.stdin.setRawMode(!1)}catch{}process.stdin.pause(),process.stdin.unref()},S=()=>{if(d){for(const b of d.values())b.kill?.();d.clear()}},x=()=>{j(),A(),S(),I(),process.stdout.write("\x1B[?1049l\x1B[?25h"),$?.cleanup(),process.exit(1)},O=()=>{const b=h.getSnapshot(),M=De(Date.now()-b.startTime),H=b.rows.filter(W=>W.status==="failure").map(W=>W.taskId),te=process.stdout.columns||80;process.stdout.write(`
20
+ `);for(const W of b.rows){const{persistent:Y,status:ce,taskId:re}=W,ae=ce==="running"||ce==="pending",ne=_e(ce),U=ae&&Y?"■":ne.icon,_=ae&&Y?"gray":ne.color;let X="";switch(ce){case"local-cache":case"local-cache-kept-existing":{X=" [local cache]";break}case"remote-cache":{X=" [remote cache]";break}case"skipped":{X=" [skipped]";break}default:{ae&&Y?X=" [stopped]":ae&&(X=" [skipped]");break}}const pe=W.retryAttempts&&W.retryAttempts>0?` [retried ${W.retryAttempts}x]`:"",je=he(K.createElement(c,null," ",K.createElement(c,{color:_},U),` vis run ${re}`,X?K.createElement(c,{dimColor:!0},` ${X}`):null,pe?K.createElement(c,{color:"yellow"},pe):null),{columns:te});process.stdout.write(`${je}
21
21
  `)}process.stdout.write(`
22
- `);const ue=pe(K.createElement(Os,{cached:S.cached,failed:S.failed,failedIds:V,projectNames:a,retriedIds:S.retriedIds.length>0?S.retriedIds:void 0,succeeded:S.succeeded,targets:e.targets,tasks:h,took:F}),{columns:te});if(process.stdout.write(`${ue}
23
- `),o!=="quiet"){const q=[...S.rows.filter(Y=>Y.status!=="failure"),...S.rows.filter(Y=>Y.status==="failure")];for(const Y of q){if(Y.status==="running"||Y.status==="pending")continue;const ce=S.outputs.get(Y.taskId);if(!ce?.trim())continue;const{color:re,icon:ie}=_e(Y.status),ae=pe(K.createElement(c,null,`
24
- `,K.createElement(c,{bold:!0,color:re},` ${ie} vis run ${Y.taskId}`)),{columns:te});process.stdout.write(`${ae}
25
-
26
- `);const _=ce.trim().split(`
27
- `).map(H=>` ${H}`).join(`
28
- `);process.stdout.write(`${_}
29
- `)}}};let w;const A=()=>{w&&(clearInterval(w),w=void 0)};return{lifeCycle:{endCommand(){b(),u.markDone(),w||(w=setInterval(()=>{},1e3))},endTasks(S){u.endTasks(S)},printCacheDisabledByTask(S){u.addOutput(S.id,`ⓘ caching disabled by task via disableCache()
30
- `)},printEmptyFingerprintWarning(S,F){u.addOutput(S.id,`ⓘ caching skipped — ${F}
31
- `)},printSelfModifyingSkip(S,F){u.addOutput(S.id,`ⓘ caching skipped — task modified its own input${F.length===1?"":"s"} (${F.join(", ")})
32
- `)},printTaskTerminalOutput(S,F,V){u.getSnapshot().outputs.has(S.id)||u.addOutput(S.id,V)},startCommand(){process.on("SIGINT",k),process.on("SIGTERM",k),w||(w=setInterval(()=>{},1e3)),$=Ir(K.createElement(En,{autoExitSeconds:l,onRetryService:r,parallelSlots:p,projectNames:a,serviceDockStore:n,stdinRegistry:d??new Map,store:u,targets:e.targets,tasks:h}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}),$.waitUntilExit().then(()=>{A(),O(),x(),process.removeListener("SIGINT",k),process.removeListener("SIGTERM",k),M(),I()}).catch(()=>{A(),O(),x(),process.removeListener("SIGINT",k),process.removeListener("SIGTERM",k),I()})},startTasks(S){u.startTasks(S),z||(z=setInterval(()=>{u.tick()},100))}},renderIsDone:G,store:u}},Fn=s=>s==="quiet"?"quiet":"normal",On=(s,e)=>typeof s=="string"?Fn(s.toLowerCase()):e===!0?"quiet":"normal",Pn=(s,e)=>{const t=s.overrides.visOptions;return t?.outputStyle==="normal"||t?.outputStyle==="quiet"?t.outputStyle:e};class An{#e;#r;#s;#i=[];#t=[];#n=[];#o=new Map;#a;#c;#l;#u=0;constructor(e){this.#e=e.projectNames,this.#r=e.args.targets,this.#s=e.tasks,this.#a=e.logReporter,this.#c=e.outputStyle??"normal",this.#l=e.ciGrouping??"auto"}startCommand(){this.#u=Date.now();const e=process.stdout.columns||80,t=`Running ${yt(this.#e,this.#r,this.#s)}`,r=pe(K.createElement(ht,{title:t,variant:"info"}),{columns:e});process.stdout.write(r);const o=this.#s[0],a=o?.overrides?Object.entries(o.overrides).filter(([n])=>n!=="command"):[];if(a.length>0){process.stdout.write(`
22
+ `);const fe=he(K.createElement(Ls,{cached:b.cached,failed:b.failed,failedIds:H,projectNames:a,retriedIds:b.retriedIds.length>0?b.retriedIds:void 0,succeeded:b.succeeded,targets:e.targets,tasks:u,took:M}),{columns:te});if(process.stdout.write(`${fe}
23
+ `),o!=="quiet"){const W=[...b.rows.filter(Y=>Y.status!=="failure"),...b.rows.filter(Y=>Y.status==="failure")];for(const Y of W){if(Y.status==="running"||Y.status==="pending")continue;const ce=b.outputs.get(Y.taskId);if(!ce?.trim())continue;const{color:re,icon:ae}=_e(Y.status),ne=he(K.createElement(c,null,`
24
+ `,K.createElement(c,{bold:!0,color:re},` ${ae} vis run ${Y.taskId}`)),{columns:te});process.stdout.write(`${ne}
25
+
26
+ `);const U=ce.trim().split(`
27
+ `).map(_=>` ${_}`).join(`
28
+ `);process.stdout.write(`${U}
29
+ `)}}};let w;const A=()=>{w&&(clearInterval(w),w=void 0)};return{lifeCycle:{endCommand(){j(),h.markDone(),w||(w=setInterval(()=>{},1e3))},endTasks(b){h.endTasks(b)},printCacheDisabledByTask(b){h.addOutput(b.id,`ⓘ caching disabled by task via disableCache()
30
+ `)},printEmptyFingerprintWarning(b,M){h.addOutput(b.id,`ⓘ caching skipped — ${M}
31
+ `)},printSelfModifyingSkip(b,M){h.addOutput(b.id,`ⓘ caching skipped — task modified its own input${M.length===1?"":"s"} (${M.join(", ")})
32
+ `)},printTaskTerminalOutput(b,M,H){h.getSnapshot().outputs.has(b.id)||h.addOutput(b.id,H)},startCommand(){process.on("SIGINT",x),process.on("SIGTERM",x),w||(w=setInterval(()=>{},1e3)),$=Pr(K.createElement(Dn,{autoExitSeconds:l,onRetryService:r,parallelSlots:p,projectNames:a,serviceDockStore:i,stdinRegistry:d??new Map,store:h,targets:e.targets,tasks:u}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}),$.waitUntilExit().then(()=>{A(),S(),I(),process.removeListener("SIGINT",x),process.removeListener("SIGTERM",x),O(),R()}).catch(()=>{A(),S(),I(),process.removeListener("SIGINT",x),process.removeListener("SIGTERM",x),R()})},startTasks(b){h.startTasks(b),V||(V=setInterval(()=>{h.tick()},100))}},renderIsDone:G,store:h}},Bn=s=>s==="quiet"?"quiet":"normal",Nn=(s,e)=>typeof s=="string"?Bn(s.toLowerCase()):e===!0?"quiet":"normal",Gn=(s,e)=>{const t=s.overrides.visOptions;return t?.outputStyle==="normal"||t?.outputStyle==="quiet"?t.outputStyle:e};class _n{#e;#r;#s;#i=[];#t=[];#n=[];#o=new Map;#a;#c;#l;#u=0;constructor(e){this.#e=e.projectNames,this.#r=e.args.targets,this.#s=e.tasks,this.#a=e.logReporter,this.#c=e.outputStyle??"normal",this.#l=e.ciGrouping??"auto"}startCommand(){this.#u=Date.now();const e=process.stdout.columns||80,t=`Running ${xt(this.#e,this.#r,this.#s)}`,r=he(K.createElement(pt,{title:t,variant:"info"}),{columns:e});process.stdout.write(r);const o=this.#s[0],a=o?.overrides?Object.entries(o.overrides).filter(([i])=>i!=="command"):[];if(a.length>0){process.stdout.write(`
33
33
  With additional flags:
34
- `);for(const[n,d]of a)process.stdout.write(`${on(" ",n,d)}
34
+ `);for(const[i,d]of a)process.stdout.write(`${hn(" ",i,d)}
35
35
  `)}process.stdout.write(`
36
- `)}startTasks(e){const t=process.stdout.columns||80;for(const r of e){const o=pe(K.createElement(c,null,K.createElement(c,{dimColor:!0},">"),` ${r.id}`),{columns:t});process.stdout.write(`${o}
37
- `)}}endTasks(e){const t=process.stdout.columns||80;for(const r of e){this.#o.set(r.task.id,r),r.status==="failure"?this.#i.push(r):Ne(r.status)&&this.#t.push(r),r.retryAttempts&&r.retryAttempts>0&&this.#n.push(r);const o=We(r.status),a=r.startTime&&r.endTime?` (${De(r.endTime-r.startTime)})`:"",n=Ne(r.status)?" [cache]":"",d=r.retryAttempts&&r.retryAttempts>0?` [retried ${r.retryAttempts}x]`:"",h=pe(K.createElement(c,null,o,` ${r.task.id}`,n?K.createElement(c,{color:"cyan"},n):null,d?K.createElement(c,{color:"yellow"},d):null,a?K.createElement(c,{dimColor:!0},a):null),{columns:t});process.stdout.write(`${h}
38
- `)}}#d(e){const t=process.stdout.columns||80,r=pe(K.createElement(c,{dimColor:!0},` ⓘ ${e}`),{columns:t});process.stdout.write(`${r}
39
- `)}printCacheDisabledByTask(e){this.#d(`${e.id}: caching disabled by task via disableCache()`)}printSelfModifyingSkip(e,t){this.#d(`${e.id}: caching skipped — task modified its own input${t.length===1?"":"s"} (${t.join(", ")})`)}printEmptyFingerprintWarning(e,t){this.#d(`${e.id}: caching skipped — ${t}`)}printTaskTerminalOutput(e,t,r){if(Pn(e,this.#c)==="quiet"&&(t==="success"||Ne(t)))return;const o=t==="failure"?As(r,{color:!process.env.NO_COLOR,cwd:process.cwd()}):r;if(this.#a){this.#a.printTaskTerminalOutput(e,t,o);return}vn(e.id,t,o,this.#l)}endCommand(){const e=De(Date.now()-this.#u),t=this.#s.filter(a=>!this.#o.has(a.id)).map(a=>a.id);process.stdout.write(`
40
- `);const r=process.stdout.columns||80,o=pe(K.createElement(Os,{cached:this.#t.length,failed:this.#i.length,failedIds:this.#i.map(a=>a.task.id),projectNames:this.#e,retriedIds:this.#n.length>0?this.#n.map(a=>a.task.id):void 0,skippedIds:t.length>0?t:void 0,succeeded:this.#o.size-this.#i.length-this.#t.length,targets:this.#r,tasks:this.#s,took:e}),{columns:r});process.stdout.write(`${o}
41
- `)}}const Dn=async s=>{if(process.env.VIS_NO_SHELL_HISTORY)return;if(ji()==="win32"){try{await Nn(s)}catch{}return}const e=process.env.SHELL;if(!e)return;const t=sr(e);try{if(t==="zsh"){await Ln(s);return}if(t==="bash"){await Bn(s);return}t==="fish"&&await Gn(s)}catch{}},vt=s=>s.replaceAll(/[\u0000-\u001F\u007F]/gu," ").trimEnd(),Ln=async s=>{const e=process.env.HISTFILE??oe(process.env.ZDOTDIR??mt(),".zsh_history"),t=`: ${Math.floor(Date.now()/1e3)}:0;${vt(s)}
42
- `;await at(e,t)},Bn=async s=>{const e=process.env.HISTFILE??oe(mt(),".bash_history");await at(e,`${vt(s)}
43
- `)},Nn=async s=>{const e=process.env.VIS_PSREADLINE_HISTORY,t=process.env.APPDATA;if(e===void 0&&(t===void 0||t===""))return;const r=e??oe(t,"Microsoft","Windows","PowerShell","PSReadLine","ConsoleHost_history.txt");await ki(ys(r),{recursive:!0}),await at(r,`${vt(s)}\r
44
- `)},Gn=async s=>{const e=oe(mt(),".local","share","fish","fish_history"),t=`- cmd: ${s.replaceAll("\\","\\\\").replaceAll(`
36
+ `)}startTasks(e){const t=process.stdout.columns||80;for(const r of e){const o=he(K.createElement(c,null,K.createElement(c,{dimColor:!0},">"),` ${r.id}`),{columns:t});process.stdout.write(`${o}
37
+ `)}}endTasks(e){const t=process.stdout.columns||80;for(const r of e){this.#o.set(r.task.id,r),r.status==="failure"?this.#i.push(r):Ne(r.status)&&this.#t.push(r),r.retryAttempts&&r.retryAttempts>0&&this.#n.push(r);const o=ze(r.status),a=r.startTime&&r.endTime?` (${De(r.endTime-r.startTime)})`:"",i=Ne(r.status)?" [cache]":"",d=r.retryAttempts&&r.retryAttempts>0?` [retried ${r.retryAttempts}x]`:"",u=he(K.createElement(c,null,o,` ${r.task.id}`,i?K.createElement(c,{color:"cyan"},i):null,d?K.createElement(c,{color:"yellow"},d):null,a?K.createElement(c,{dimColor:!0},a):null),{columns:t});process.stdout.write(`${u}
38
+ `)}}#d(e){const t=process.stdout.columns||80,r=he(K.createElement(c,{dimColor:!0},` ⓘ ${e}`),{columns:t});process.stdout.write(`${r}
39
+ `)}printCacheDisabledByTask(e){this.#d(`${e.id}: caching disabled by task via disableCache()`)}printSelfModifyingSkip(e,t){this.#d(`${e.id}: caching skipped — task modified its own input${t.length===1?"":"s"} (${t.join(", ")})`)}printEmptyFingerprintWarning(e,t){this.#d(`${e.id}: caching skipped — ${t}`)}printTaskTerminalOutput(e,t,r){if(Gn(e,this.#c)==="quiet"&&(t==="success"||Ne(t)))return;const o=t==="failure"?Ns(r,{color:!process.env.NO_COLOR,cwd:process.cwd()}):r;if(this.#a){this.#a.printTaskTerminalOutput(e,t,o);return}Sn(e.id,t,o,this.#l)}endCommand(){const e=De(Date.now()-this.#u),t=this.#s.filter(a=>!this.#o.has(a.id)).map(a=>a.id);process.stdout.write(`
40
+ `);const r=process.stdout.columns||80,o=he(K.createElement(Ls,{cached:this.#t.length,failed:this.#i.length,failedIds:this.#i.map(a=>a.task.id),projectNames:this.#e,retriedIds:this.#n.length>0?this.#n.map(a=>a.task.id):void 0,skippedIds:t.length>0?t:void 0,succeeded:this.#o.size-this.#i.length-this.#t.length,targets:this.#r,tasks:this.#s,took:e}),{columns:r});process.stdout.write(`${o}
41
+ `)}}const qn=async s=>{if(process.env.VIS_NO_SHELL_HISTORY)return;if(Ii()==="win32"){try{await Vn(s)}catch{}return}const e=process.env.SHELL;if(!e)return;const t=nr(e);try{if(t==="zsh"){await Wn(s);return}if(t==="bash"){await Un(s);return}t==="fish"&&await Hn(s)}catch{}},jt=s=>s.replaceAll(/[\u0000-\u001F\u007F]/gu," ").trimEnd(),Wn=async s=>{const e=process.env.HISTFILE??oe(process.env.ZDOTDIR??vt(),".zsh_history"),t=`: ${Math.floor(Date.now()/1e3)}:0;${jt(s)}
42
+ `;await at(e,t)},Un=async s=>{const e=process.env.HISTFILE??oe(vt(),".bash_history");await at(e,`${jt(s)}
43
+ `)},Vn=async s=>{const e=process.env.VIS_PSREADLINE_HISTORY,t=process.env.APPDATA;if(e===void 0&&(t===void 0||t===""))return;const r=e??oe(t,"Microsoft","Windows","PowerShell","PSReadLine","ConsoleHost_history.txt");await Ci(js(r),{recursive:!0}),await at(r,`${jt(s)}\r
44
+ `)},Hn=async s=>{const e=oe(vt(),".local","share","fish","fish_history"),t=`- cmd: ${s.replaceAll("\\","\\\\").replaceAll(`
45
45
  `,String.raw`\n`).replaceAll("\r",String.raw`\r`)}
46
46
  when: ${Math.floor(Date.now()/1e3)}
47
- `;await at(e,t)},_n=s=>{const{killGracePeriodMs:e=5e3,onTimeout:t,sendSignal:r,timeoutMs:o}=s;if(o<=0)return{cancel:()=>{}};const a=Math.max(e,0);let n;const d=setTimeout(()=>{t?.(),r("SIGTERM"),a>0&&(n=setTimeout(()=>{r("SIGKILL")},a))},o);return{cancel:()=>{clearTimeout(d),n&&clearTimeout(n)}}},qn=(s,e)=>{const t=e?.trim();if(!t)return{filter:void 0,tasks:[...s]};const r=t.toLowerCase();return{filter:t,tasks:s.filter(o=>o.target.project.toLowerCase().includes(r))}},Un=[""," Watch keybinds:"," r, Enter rerun"," a rerun all (clear filter)"," p filter by project name"," q, Ctrl+C quit"," h, ? show this help",""].join(`
48
- `),Hn=s=>{s.write(`${Un}
49
- `)},zn=async(s,e)=>{e.write("filter projects (empty to cancel) > ");const t=s,r=t.isRaw===!0;if(r)try{t.setRawMode?.(!1)}catch{}return await new Promise(o=>{let a="";const n=d=>{a+=typeof d=="string"?d:d.toString("utf8");const h=a.indexOf(`
50
- `);if(h===-1)return;const f=a.slice(0,h).replace(/\r$/,"").trim();if(s.off("data",n),r)try{t.setRawMode?.(!0)}catch{}o(f.length>0?f:void 0)};s.on("data",n)})},Vn=s=>{const{handlers:e}=s,t=s.input??process.stdin,r=s.output??process.stdout,o=s.promptFilter??zn;if(!t||t.isTTY===!1)return{close:()=>{}};Nr(t);const a=t.isRaw===!0;try{t.setRawMode?.(!0)}catch{return{close:()=>{}}}typeof t.resume=="function"&&t.resume();let n=!1;const d=async u=>{if(u.ctrl===!0&&u.name==="c"){await e.onQuit();return}if(!n)switch(u.name){case"?":case"h":{await e.onHelp();break}case"a":{await e.onClearFilter();break}case"p":{n=!0;try{const p=await o(t,r);p===void 0?r.write(`filter cancelled.
51
- `):await e.onFilter(p)}finally{n=!1}break}case"q":{await e.onQuit();break}case"r":{await e.onRerun();break}case"return":{await e.onRerun();break}}},h=(u,p)=>{d(p).catch(l=>{r.write(`[vis watch] keybind handler failed: ${l.message}
52
- `)})},f=t;return f.on("keypress",h),{close:()=>{if(f.off("keypress",h),!a)try{t.setRawMode?.(!1)}catch{}const u=t;if(typeof u.pause=="function")try{u.pause()}catch{}}}},Wn=s=>{const e=s.overrides.visOptions;return e&&typeof e=="object"?e:void 0},Yn=async s=>{const{initialTasks:e,probe:t,registeredEntries:r,taskGraph:o,visVersion:a}=s,n=new Map,d=new Map,h=new Map;for(const w of r)if(Ur(w.pid)){if(w.visVersion!==a){d.set(w.id,w);continue}n.set(w.id,w)}if(t){const w=[...n.values()],A=await Promise.all(w.map(async S=>{try{return[S.id,await t(S)]}catch{return[S.id,!1]}}));for(const[S,F]of A)if(!F){const V=n.get(S);n.delete(S),V&&h.set(S,V)}}const f=new Set(e.map(w=>w.id)),u=new Set,p=[],l=[],$=new Set;for(const w of Object.values(o.dependencies))for(const A of w)$.add(A);for(const[w,A]of Object.entries(o.tasks)){if(!Wn(A)?.service)continue;if(n.has(w)){u.add(w),l.push(n.get(w));continue}if(f.has(w)||!$.has(w))continue;const S=d.get(w),F=h.get(w);let V;S?V=`Service ${w} is registered with vis ${S.visVersion}, but this invocation is vis ${a}. Restart with \`vis service restart ${w}\` to pick up the new version.`:F?V=`Service ${w} is registered (PID ${String(F.pid)}) but failed its readiness probe — the wrapper process is alive but the underlying server is not responding. Run \`vis service restart ${w}\` to recover.`:V=`Target depends on the service ${w}, which is not running. Run \`vis service start ${w}\` first, or invoke \`${w}\` directly.`,p.push({message:V,targetId:w})}if(u.size===0)return{diagnostics:p,initialTasks:e,satisfiedServices:l,serviceDependentsByServiceId:new Map,serviceEnvByTaskId:new Map,taskGraph:o};const I=new Map,G=w=>{const A=new Set,S=[...o.dependencies[w]??[]],F=new Set;for(;S.length>0;){const V=S.pop();if(!F.has(V)){F.add(V),u.has(V)&&A.add(V);for(const te of o.dependencies[V]??[])F.has(te)||S.push(te)}}return[...A].sort()},z=new Map;for(const w of Object.keys(o.dependencies)){if(u.has(w))continue;const A=G(w);if(A.length===0)continue;const S={};for(const F of A){const V=n.get(F);if(!V)continue;Object.assign(S,V.env);const te=z.get(F);te?te.push(w):z.set(F,[w])}Object.keys(S).length>0&&I.set(w,S)}for(const w of z.values())w.sort();const b={};for(const[w,A]of Object.entries(o.tasks))u.has(w)||(b[w]=A);const x={};for(const[w,A]of Object.entries(o.dependencies))u.has(w)||(x[w]=A.filter(S=>!u.has(S)));const O=new Map;for(const w of Object.keys(b))O.set(w,0);for(const w of Object.values(x))for(const A of w)O.has(A)&&O.set(A,(O.get(A)??0)+1);const k=[];for(const w of o.roots)!u.has(w)&&b[w]&&k.push(w);for(const[w,A]of O)A===0&&!k.includes(w)&&b[w]&&k.push(w);const M=e.filter(w=>!u.has(w.id));return{diagnostics:p,initialTasks:M,satisfiedServices:l,serviceDependentsByServiceId:z,serviceEnvByTaskId:I,taskGraph:{dependencies:x,roots:k,tasks:b}}},Xe="[[VIS_BOOT]]",Jn=250,Kn=1e3,hs=3,Xn=s=>{try{return process.kill(s,0),!0}catch{return!1}},fs=s=>{try{const e=Ge(s,"utf8").trim(),t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:null}catch{return null}};class Qn{#e;#r;#s;#i;#t=new Map;#n=new Map;#o=new Map;#a=new Map;#c=new Set;constructor(e){this.#e=e.indexToId,this.#r=new Map(e.services),this.#s=e.sink,this.#i=e.workspaceRoot}onProcessEvent=e=>{if(e.kind!=="stdout"&&e.kind!=="stderr")return;const t=this.#e.get(e.index);t===void 0||e.text===void 0||this.onTaskOutput(t,e.text)};onTaskOutput(e,t){if(!this.#r.has(e))return;const r=((this.#t.get(e)??"")+t).split(`
53
- `),o=r.pop()??"";this.#t.set(e,o);for(const a of r)this.#l(e,a)}notifyRegistryStarting(e){this.#s.starting(e)}notifyRegistryStarted(e,t){this.#s.started(e,t)}onRegistryTaskStarted(e){this.#r.get(e)?.mode==="registry"&&this.notifyRegistryStarting(e)}async onRegistryTaskClosed(e,t,r){if(this.#r.get(e)?.mode!=="registry")return;if(r||t!==0){this.notifyRegistryFailed(e,"exit-code",{exitCode:t,killed:r});return}const o=await Hr(this.#i,e);if(!o){this.notifyRegistryFailed(e,"missing-registry-entry");return}const{config:a}=o,n=a.readiness?.tcp?.port??a.port??0,d=a.readiness?.tcp?.host??"127.0.0.1";this.notifyRegistryReady(e,{host:d,logFile:o.logFile,pid:o.pid,port:n})}notifyRegistryReady(e,t){this.#s.ready(e,{host:t.host,port:t.port}),this.#f(e,t.logFile),t.pid!==null&&this.#p(e,t.pid)}notifyRegistryFailed(e,t,r){this.#s.failed(e,t,r)}async retry(e){const t=this.#r.get(e);if(t){if(this.#h(e),this.#t.delete(e),this.#n.delete(e),this.#s.starting(e),t.mode==="registry"){await this.#v(e,t.registry);return}t.mode==="ephemeral"&&this.#y(e,t.ephemeral)}}async dispose(){for(const e of[...this.#o.keys(),...this.#a.keys()])this.#h(e);this.#c.size>0&&(await Promise.race([Promise.all(this.#c),new Promise(e=>{setTimeout(e,2e3)})]),this.#c.clear()),this.#t.clear(),this.#n.clear()}#l(e,t){if(t.startsWith(Xe)){this.#u(e,t.slice(Xe.length));return}const r=this.#n.get(e)??[];r.push(t),r.length>hs&&r.shift(),this.#n.set(e,r),this.#s.log(e,`${t}
47
+ `;await at(e,t)},zn=s=>{const{killGracePeriodMs:e=5e3,onTimeout:t,sendSignal:r,timeoutMs:o}=s;if(o<=0)return{cancel:()=>{}};const a=Math.max(e,0);let i;const d=setTimeout(()=>{t?.(),r("SIGTERM"),a>0&&(i=setTimeout(()=>{r("SIGKILL")},a))},o);return{cancel:()=>{clearTimeout(d),i&&clearTimeout(i)}}},Yn=(s,e)=>{const t=e?.trim();if(!t)return{filter:void 0,tasks:[...s]};const r=t.toLowerCase();return{filter:t,tasks:s.filter(o=>o.target.project.toLowerCase().includes(r))}},Jn=[""," Watch keybinds:"," r, Enter rerun"," a rerun all (clear filter)"," p filter by project name"," q, Ctrl+C quit"," h, ? show this help",""].join(`
48
+ `),Kn=s=>{s.write(`${Jn}
49
+ `)},Xn=async(s,e)=>{e.write("filter projects (empty to cancel) > ");const t=s,r=t.isRaw===!0;if(r)try{t.setRawMode?.(!1)}catch{}return await new Promise(o=>{let a="";const i=d=>{a+=typeof d=="string"?d:d.toString("utf8");const u=a.indexOf(`
50
+ `);if(u===-1)return;const f=a.slice(0,u).replace(/\r$/,"").trim();if(s.off("data",i),r)try{t.setRawMode?.(!0)}catch{}o(f.length>0?f:void 0)};s.on("data",i)})},Qn=s=>{const{handlers:e}=s,t=s.input??process.stdin,r=s.output??process.stdout,o=s.promptFilter??Xn;if(!t||t.isTTY===!1)return{close:()=>{}};Vr(t);const a=t.isRaw===!0;try{t.setRawMode?.(!0)}catch{return{close:()=>{}}}typeof t.resume=="function"&&t.resume();let i=!1;const d=async h=>{if(h.ctrl===!0&&h.name==="c"){await e.onQuit();return}if(!i)switch(h.name){case"?":case"h":{await e.onHelp();break}case"a":{await e.onClearFilter();break}case"p":{i=!0;try{const p=await o(t,r);p===void 0?r.write(`filter cancelled.
51
+ `):await e.onFilter(p)}finally{i=!1}break}case"q":{await e.onQuit();break}case"r":{await e.onRerun();break}case"return":{await e.onRerun();break}}},u=(h,p)=>{d(p).catch(l=>{r.write(`[vis watch] keybind handler failed: ${l.message}
52
+ `)})},f=t;return f.on("keypress",u),{close:()=>{if(f.off("keypress",u),!a)try{t.setRawMode?.(!1)}catch{}const h=t;if(typeof h.pause=="function")try{h.pause()}catch{}}}},Zn=s=>{const e=s.overrides.visOptions;return e&&typeof e=="object"?e:void 0},eo=async s=>{const{initialTasks:e,probe:t,registeredEntries:r,taskGraph:o,visVersion:a}=s,i=new Map,d=new Map,u=new Map;for(const w of r)if(Jr(w.pid)){if(w.visVersion!==a){d.set(w.id,w);continue}i.set(w.id,w)}if(t){const w=[...i.values()],A=await Promise.all(w.map(async b=>{try{return[b.id,await t(b)]}catch{return[b.id,!1]}}));for(const[b,M]of A)if(!M){const H=i.get(b);i.delete(b),H&&u.set(b,H)}}const f=new Set(e.map(w=>w.id)),h=new Set,p=[],l=[],$=new Set;for(const w of Object.values(o.dependencies))for(const A of w)$.add(A);for(const[w,A]of Object.entries(o.tasks)){if(!Zn(A)?.service)continue;if(i.has(w)){h.add(w),l.push(i.get(w));continue}if(f.has(w)||!$.has(w))continue;const b=d.get(w),M=u.get(w);let H;b?H=`Service ${w} is registered with vis ${b.visVersion}, but this invocation is vis ${a}. Restart with \`vis service restart ${w}\` to pick up the new version.`:M?H=`Service ${w} is registered (PID ${String(M.pid)}) but failed its readiness probe — the wrapper process is alive but the underlying server is not responding. Run \`vis service restart ${w}\` to recover.`:H=`Target depends on the service ${w}, which is not running. Run \`vis service start ${w}\` first, or invoke \`${w}\` directly.`,p.push({message:H,targetId:w})}if(h.size===0)return{diagnostics:p,initialTasks:e,satisfiedServices:l,serviceDependentsByServiceId:new Map,serviceEnvByTaskId:new Map,taskGraph:o};const R=new Map,G=w=>{const A=new Set,b=[...o.dependencies[w]??[]],M=new Set;for(;b.length>0;){const H=b.pop();if(!M.has(H)){M.add(H),h.has(H)&&A.add(H);for(const te of o.dependencies[H]??[])M.has(te)||b.push(te)}}return[...A].sort()},V=new Map;for(const w of Object.keys(o.dependencies)){if(h.has(w))continue;const A=G(w);if(A.length===0)continue;const b={};for(const M of A){const H=i.get(M);if(!H)continue;Object.assign(b,H.env);const te=V.get(M);te?te.push(w):V.set(M,[w])}Object.keys(b).length>0&&R.set(w,b)}for(const w of V.values())w.sort();const j={};for(const[w,A]of Object.entries(o.tasks))h.has(w)||(j[w]=A);const I={};for(const[w,A]of Object.entries(o.dependencies))h.has(w)||(I[w]=A.filter(b=>!h.has(b)));const S=new Map;for(const w of Object.keys(j))S.set(w,0);for(const w of Object.values(I))for(const A of w)S.has(A)&&S.set(A,(S.get(A)??0)+1);const x=[];for(const w of o.roots)!h.has(w)&&j[w]&&x.push(w);for(const[w,A]of S)A===0&&!x.includes(w)&&j[w]&&x.push(w);const O=e.filter(w=>!h.has(w.id));return{diagnostics:p,initialTasks:O,satisfiedServices:l,serviceDependentsByServiceId:V,serviceEnvByTaskId:R,taskGraph:{dependencies:I,roots:x,tasks:j}}},to=s=>s.startsWith("./")||s.startsWith("../")||s.startsWith("/")||s.startsWith("**"),so=s=>{let e=s.trim();if(e==="")return;let t=!1,r=!1,o=!1;e.startsWith("...")&&(t=!0,e=e.slice(3),e.startsWith("^")&&(o=!0,e=e.slice(1))),e.endsWith("...")&&(r=!0,e=e.slice(0,-3),e.endsWith("^")&&(o=!0,e=e.slice(0,-1)));let a;const i=/\[([^\]]*)\]$/.exec(e);i&&(a=i[1]??"",e=e.slice(0,i.index));let d=e.trim(),u=!1;return d.startsWith("{")&&d.endsWith("}")&&d.length>=2?(d=d.slice(1,-1),u=!0):to(d)&&(u=!0),{changedSince:a,excludeSelf:o,includeDependencies:r,includeDependents:t,isPath:u,pattern:d}},gt=s=>{let e=s.replaceAll("\\","/");return e.startsWith("./")&&(e=e.slice(2)),e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e},ro=(s,e,t)=>s===""?!1:ft(s,e)?!0:t!==void 0&&ft(s,t),io=(s,e)=>{if(e===void 0||e==="")return!1;const t=gt(s),r=gt(e);return ft(t,r)},no=(s,e,t)=>{const{affected:r,downstream:o,upstream:a}=lr(s,t,{downstream:e.includeDependents?"deep":"none",upstream:e.includeDependencies?"deep":"none"});if(!e.excludeSelf)return r;const i=new Set([...o,...a]);for(const d of s)i.delete(d);return i},oo=async(s,e)=>{const{packageNameByProject:t,projectGraph:r}=e,o=Object.keys(r.nodes);let a=new Set;if(s.pattern!=="")for(const i of o)s.isPath?io(s.pattern,r.nodes[i]?.data.root)&&a.add(i):ro(s.pattern,i,t?.get(i))&&a.add(i);if(s.changedSince!==void 0){const i=s.changedSince===""?e.defaultBase??"main":s.changedSince,d=e.changedProjectsForRef??ao(e),u=new Set(await d(i));a=s.pattern===""?u:new Set([...a].filter(f=>u.has(f)))}return!s.includeDependents&&!s.includeDependencies?a:no(a,s,r)},ao=s=>async e=>{const{projectGraph:t,workspaceRoot:r}=s;if(!r)return[];let o;try{o=await dr(r,e,"HEAD")}catch(i){const d=i instanceof Error?i.message:String(i);throw new Error(`vis run --filter: invalid changed-since ref "${e}" (${d})`,{cause:i})}const a=new Set;for(const[i,d]of Object.entries(t.nodes)){const u=gt(d.data.root??i);if(!(u===""||u==="."))for(const f of o){const h=or(r,f).replaceAll("\\","/");if(h===u||h.startsWith(`${u}/`)){a.add(i);break}}}return[...a]},co=async(s,e)=>{const t=new Set;for(const r of s)for(const o of await oo(r,e))t.add(o);return[...t]},lo=async(s,e)=>{const t=[];for(const r of s){const o=so(r);o&&t.push(o)}return co(t,e)},Xe="[[VIS_BOOT]]",uo=250,ho=1e3,ms=3,fo=s=>{try{return process.kill(s,0),!0}catch{return!1}},ws=s=>{try{const e=Ge(s,"utf8").trim(),t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:null}catch{return null}};class po{#e;#r;#s;#i;#t=new Map;#n=new Map;#o=new Map;#a=new Map;#c=new Set;constructor(e){this.#e=e.indexToId,this.#r=new Map(e.services),this.#s=e.sink,this.#i=e.workspaceRoot}onProcessEvent=e=>{if(e.kind!=="stdout"&&e.kind!=="stderr")return;const t=this.#e.get(e.index);t===void 0||e.text===void 0||this.onTaskOutput(t,e.text)};onTaskOutput(e,t){if(!this.#r.has(e))return;const r=((this.#t.get(e)??"")+t).split(`
53
+ `),o=r.pop()??"";this.#t.set(e,o);for(const a of r)this.#l(e,a)}notifyRegistryStarting(e){this.#s.starting(e)}notifyRegistryStarted(e,t){this.#s.started(e,t)}onRegistryTaskStarted(e){this.#r.get(e)?.mode==="registry"&&this.notifyRegistryStarting(e)}async onRegistryTaskClosed(e,t,r){if(this.#r.get(e)?.mode!=="registry")return;if(r||t!==0){this.notifyRegistryFailed(e,"exit-code",{exitCode:t,killed:r});return}const o=await Kr(this.#i,e);if(!o){this.notifyRegistryFailed(e,"missing-registry-entry");return}const{config:a}=o,i=a.readiness?.tcp?.port??a.port??0,d=a.readiness?.tcp?.host??"127.0.0.1";this.notifyRegistryReady(e,{host:d,logFile:o.logFile,pid:o.pid,port:i})}notifyRegistryReady(e,t){this.#s.ready(e,{host:t.host,port:t.port}),this.#f(e,t.logFile),t.pid!==null&&this.#p(e,t.pid)}notifyRegistryFailed(e,t,r){this.#s.failed(e,t,r)}async retry(e){const t=this.#r.get(e);if(t){if(this.#h(e),this.#t.delete(e),this.#n.delete(e),this.#s.starting(e),t.mode==="registry"){await this.#v(e,t.registry);return}t.mode==="ephemeral"&&this.#y(e,t.ephemeral)}}async dispose(){for(const e of[...this.#o.keys(),...this.#a.keys()])this.#h(e);this.#c.size>0&&(await Promise.race([Promise.all(this.#c),new Promise(e=>{setTimeout(e,2e3)})]),this.#c.clear()),this.#t.clear(),this.#n.clear()}#l(e,t){if(t.startsWith(Xe)){this.#u(e,t.slice(Xe.length));return}const r=this.#n.get(e)??[];r.push(t),r.length>ms&&r.shift(),this.#n.set(e,r),this.#s.log(e,`${t}
54
54
  `)}#u(e,t){let r;try{r=JSON.parse(t)}catch{this.#s.log(e,`${Xe+t}
55
- `);return}switch(r.event){case"failed":{const o=typeof r.reason=="string"?r.reason:"unknown",a={};for(const[n,d]of Object.entries(r))n!=="event"&&n!=="id"&&n!=="reason"&&(a[n]=d);this.#s.failed(e,o,a);break}case"ready":{const o=typeof r.host=="string"?r.host:"127.0.0.1",a=typeof r.port=="number"?r.port:0;this.#s.ready(e,{host:o,port:a}),this.#d(e);break}case"started":{const o=typeof r.pid=="number"?r.pid:null;this.#s.started(e,o);break}default:this.#s.log(e,`${Xe+t}
56
- `)}}#d(e){const t=this.#r.get(e);if(t?.ephemeral===void 0)return;this.#f(e,t.ephemeral.logFile);const r=fs(t.ephemeral.pidFile);r!==null&&this.#p(e,r)}#f(e,t){if(this.#o.has(e)||!Ae(t))return;const r=Ar(t,"r"),o=(()=>{try{return Wt(t).size}catch{return 0}})(),a={fd:r,logFile:t,pollTimer:setInterval(()=>{this.#m(e)},Jn),position:o};this.#o.set(e,a)}#m(e){const t=this.#o.get(e);if(t)try{const r=Wt(t.logFile);if(r.size<=t.position)return;const o=Buffer.alloc(r.size-t.position),a=Dr(t.fd,o,0,o.length,t.position);if(a>0){t.position+=a;const n=o.subarray(0,a).toString("utf8");for(const d of n.split(`
57
- `))d.length!==0&&this.#w(e,d);this.#s.log(e,n)}}catch{}}#w(e,t){const r=this.#n.get(e)??[];for(r.push(t);r.length>hs;)r.shift();this.#n.set(e,r)}#p(e,t){if(this.#a.has(e))return;const r={pid:t,timer:setInterval(()=>{if(!Xn(t)){const o=[...this.#n.get(e)??[]];this.#h(e),this.#s.crashed(e,o)}},Kn)};this.#a.set(e,r)}#h(e){const t=this.#o.get(e);if(t){clearInterval(t.pollTimer);try{Lr(t.fd)}catch{}this.#o.delete(e)}const r=this.#a.get(e);r&&(clearInterval(r.timer),this.#a.delete(e))}#y(e,t){if(t===void 0)return;const r=fs(t.pidFile);if(r!==null)try{process.kill(-r,"SIGTERM")}catch{}const o=ci("node",[t.scriptPath,t.configFile],{cwd:t.cwd,stdio:["ignore","pipe","pipe"]});o.stdout.on("data",n=>{this.#g(e,n)}),o.stderr.on("data",n=>{this.#g(e,n)}),o.on("error",n=>{this.#s.failed(e,"respawn-error",{message:n.message})});const a=new Promise(n=>{const d=()=>{this.#c.delete(a),n()};o.once("exit",d),o.once("error",d)});this.#c.add(a)}#g(e,t){const r=((this.#t.get(e)??"")+t.toString("utf8")).split(`
58
- `),o=r.pop()??"";this.#t.set(e,o);for(const a of r)this.#l(e,a)}async#v(e,t){if(t!==void 0){try{await zr({id:e,workspaceRoot:this.#i})}catch{}try{const r=await Vr({command:t.command,config:t.config,cwd:t.cwd,env:t.env,id:e,workspaceRoot:this.#i}),o=t.config.readiness?.tcp?.port??t.config.port??0,a=t.config.readiness?.tcp?.host??"127.0.0.1";this.#s.started(e,r.entry.pid),this.notifyRegistryReady(e,{host:a,logFile:r.entry.logFile,pid:r.entry.pid,port:o})}catch(r){const o=r instanceof Error?r.message:String(r);this.#s.failed(e,"retry-failed",{message:o})}}}}const Zn=s=>{const e=s.overrides.visOptions;return e&&typeof e=="object"?e:void 0},Gs=(s,e,t)=>{const r=[],o=[];for(const a of e){const n=t.tasks[a];if(!n){o.push({id:a,reason:"task not in graph"});continue}const d=n.overrides.command;if(!d){o.push({id:a,reason:"no command resolved"});continue}const h=Zn(n);if(!h?.service){o.push({id:a,reason:"no service config"});continue}const f=nt(s,n.projectRoot,!!h.runFromWorkspaceRoot),{envFile:u}=h,p=u===void 0||u===!1?{}:gt(f,u),l=h.service.env??{};r.push({command:d,config:h.service,cwd:f,env:{...p,...l},id:a})}return{services:r,skipped:o}},eo=(s,e)=>{const t=new Set(s),r=new Map;for(const n of s){const d=(e.dependencies[n]??[]).filter(h=>t.has(h));r.set(n,new Set(d))}const o=[],a=new Set;for(;r.size>0;){const n=[];for(const[d,h]of r){for(const f of h)a.has(f)&&h.delete(f);h.size===0&&n.push(d)}n.length===0&&n.push(...r.keys());for(const d of n)a.add(d),r.delete(d);n.sort(),o.push({ids:n})}return o},to=(s,e)=>{const t=[];for(const r of eo(s,e))t.push(...r.ids);return t},so=String.raw`import { spawn } from "node:child_process";
55
+ `);return}switch(r.event){case"failed":{const o=typeof r.reason=="string"?r.reason:"unknown",a={};for(const[i,d]of Object.entries(r))i!=="event"&&i!=="id"&&i!=="reason"&&(a[i]=d);this.#s.failed(e,o,a);break}case"ready":{const o=typeof r.host=="string"?r.host:"127.0.0.1",a=typeof r.port=="number"?r.port:0;this.#s.ready(e,{host:o,port:a}),this.#d(e);break}case"started":{const o=typeof r.pid=="number"?r.pid:null;this.#s.started(e,o);break}default:this.#s.log(e,`${Xe+t}
56
+ `)}}#d(e){const t=this.#r.get(e);if(t?.ephemeral===void 0)return;this.#f(e,t.ephemeral.logFile);const r=ws(t.ephemeral.pidFile);r!==null&&this.#p(e,r)}#f(e,t){if(this.#o.has(e)||!Ae(t))return;const r=_r(t,"r"),o=(()=>{try{return Xt(t).size}catch{return 0}})(),a={fd:r,logFile:t,pollTimer:setInterval(()=>{this.#m(e)},uo),position:o};this.#o.set(e,a)}#m(e){const t=this.#o.get(e);if(t)try{const r=Xt(t.logFile);if(r.size<=t.position)return;const o=Buffer.alloc(r.size-t.position),a=qr(t.fd,o,0,o.length,t.position);if(a>0){t.position+=a;const i=o.subarray(0,a).toString("utf8");for(const d of i.split(`
57
+ `))d.length!==0&&this.#w(e,d);this.#s.log(e,i)}}catch{}}#w(e,t){const r=this.#n.get(e)??[];for(r.push(t);r.length>ms;)r.shift();this.#n.set(e,r)}#p(e,t){if(this.#a.has(e))return;const r={pid:t,timer:setInterval(()=>{if(!fo(t)){const o=[...this.#n.get(e)??[]];this.#h(e),this.#s.crashed(e,o)}},ho)};this.#a.set(e,r)}#h(e){const t=this.#o.get(e);if(t){clearInterval(t.pollTimer);try{Wr(t.fd)}catch{}this.#o.delete(e)}const r=this.#a.get(e);r&&(clearInterval(r.timer),this.#a.delete(e))}#y(e,t){if(t===void 0)return;const r=ws(t.pidFile);if(r!==null)try{process.kill(-r,"SIGTERM")}catch{}const o=pi("node",[t.scriptPath,t.configFile],{cwd:t.cwd,stdio:["ignore","pipe","pipe"]});o.stdout.on("data",i=>{this.#g(e,i)}),o.stderr.on("data",i=>{this.#g(e,i)}),o.on("error",i=>{this.#s.failed(e,"respawn-error",{message:i.message})});const a=new Promise(i=>{const d=()=>{this.#c.delete(a),i()};o.once("exit",d),o.once("error",d)});this.#c.add(a)}#g(e,t){const r=((this.#t.get(e)??"")+t.toString("utf8")).split(`
58
+ `),o=r.pop()??"";this.#t.set(e,o);for(const a of r)this.#l(e,a)}async#v(e,t){if(t!==void 0){try{await Xr({id:e,workspaceRoot:this.#i})}catch{}try{const r=await Qr({command:t.command,config:t.config,cwd:t.cwd,env:t.env,id:e,workspaceRoot:this.#i}),o=t.config.readiness?.tcp?.port??t.config.port??0,a=t.config.readiness?.tcp?.host??"127.0.0.1";this.#s.started(e,r.entry.pid),this.notifyRegistryReady(e,{host:a,logFile:r.entry.logFile,pid:r.entry.pid,port:o})}catch(r){const o=r instanceof Error?r.message:String(r);this.#s.failed(e,"retry-failed",{message:o})}}}}const go=s=>{const e=s.overrides.visOptions;return e&&typeof e=="object"?e:void 0},Us=(s,e,t)=>{const r=[],o=[];for(const a of e){const i=t.tasks[a];if(!i){o.push({id:a,reason:"task not in graph"});continue}const d=i.overrides.command;if(!d){o.push({id:a,reason:"no command resolved"});continue}const u=go(i);if(!u?.service){o.push({id:a,reason:"no service config"});continue}const f=nt(s,i.projectRoot,!!u.runFromWorkspaceRoot),{envFile:h}=u,p=h===void 0||h===!1?{}:yt(f,h),l=u.service.env??{};r.push({command:d,config:u.service,cwd:f,env:{...p,...l},id:a})}return{services:r,skipped:o}},mo=(s,e)=>{const t=new Set(s),r=new Map;for(const i of s){const d=(e.dependencies[i]??[]).filter(u=>t.has(u));r.set(i,new Set(d))}const o=[],a=new Set;for(;r.size>0;){const i=[];for(const[d,u]of r){for(const f of u)a.has(f)&&u.delete(f);u.size===0&&i.push(d)}i.length===0&&i.push(...r.keys());for(const d of i)a.add(d),r.delete(d);i.sort(),o.push({ids:i})}return o},wo=(s,e)=>{const t=[];for(const r of mo(s,e))t.push(...r.ids);return t},yo=String.raw`import { spawn } from "node:child_process";
59
59
  import { closeSync, openSync, readFileSync, readSync, statSync, writeFileSync } from "node:fs";
60
60
  import { createConnection } from "node:net";
61
61
 
@@ -169,22 +169,22 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
169
169
  try { process.kill(-child.pid, "SIGTERM"); } catch {}
170
170
  process.exit(1);
171
171
  })();
172
- `,ro=()=>{const s=Br(oe($i(),"vis-services-")),e=oe(s,"bootstrap.mjs");return vs(e,so),{runDir:s,scriptPath:e}},_s=(s,e,t)=>{const r=t.replaceAll(/[^\w-]/g,"_");return{configFile:oe(s,`${r}.json`),logFile:oe(s,`${r}.log`),pidFile:oe(s,`${r}.pid`),scriptPath:e}},io=s=>{const{paths:e,service:t}=s,r=t.config.readiness?.tcp?.port??t.config.port;if(typeof r!="number")throw new TypeError(`Service ${t.id} has no TCP readiness port — declare \`service.port\` or \`service.readiness.tcp.port\`.`);const o={...t.env,PATH:nr(t.cwd,t.env)};return{command:t.command,cwd:t.cwd,env:o,host:t.config.readiness?.tcp?.host??"127.0.0.1",id:t.id,logFile:e.logFile,pidFile:e.pidFile,port:r,timeoutMs:t.config.readiness?.tcp?.timeoutMs??3e4}},no=s=>`node ${JSON.stringify(s.scriptPath)} ${JSON.stringify(s.configFile)}`,oo=s=>{const{id:e,visBin:t,workspaceRoot:r}=s;return`node ${JSON.stringify(t)} service start ${JSON.stringify(e)} --cwd ${JSON.stringify(r)}`},ao=s=>{const{missingServiceIds:e,mode:t,taskGraph:r,visBin:o,workspaceRoot:a}=s,{services:n,skipped:d}=Gs(a,e,r);if(n.length===0)return{chain:[],ephemeralPidFiles:[],runDir:void 0,serviceEnvByTaskId:new Map,skipped:d};const h=to(n.map(b=>b.id),r),f=new Map(n.map(b=>[b.id,b])),u=[],p=[];if(t==="ephemeral")for(const b of h){const x=f.get(b);x&&p.push({id:b,payload:io({paths:{logFile:"",pidFile:""},service:x})})}let l;t==="ephemeral"&&(l=ro());let $;for(const b of h){const x=f.get(b),O=r.tasks[b];if(!x||!O)continue;let k;if(t==="ephemeral"){const M=_s(l.runDir,l.scriptPath,b),w={...p.find(A=>A.id===b).payload,logFile:M.logFile,pidFile:M.pidFile};vs(M.configFile,JSON.stringify(w)),k=no(M),u.push(M.pidFile)}else k=oo({id:b,visBin:o,workspaceRoot:a});if(O.overrides={...O.overrides,command:k},O.cache=!1,r.tasks[b]=O,$!==void 0){const M=r.dependencies[b]??[];M.includes($)||(r.dependencies[b]=[...M,$])}$=b}const I=new Set(h),G=new Map,z=b=>{const x=new Set,O=[...r.dependencies[b]??[]],k=new Set;for(;O.length>0;){const M=O.pop();if(!k.has(M)){k.add(M),I.has(M)&&x.add(M);for(const w of r.dependencies[M]??[])k.has(w)||O.push(w)}}return[...x].sort()};for(const b of Object.keys(r.dependencies)){if(I.has(b))continue;const x=z(b);if(x.length===0)continue;const O={};for(const k of x){const M=f.get(k);M?.config.env&&Object.assign(O,M.config.env)}Object.keys(O).length>0&&G.set(b,O)}return{chain:h,ephemeralPidFiles:u,runDir:l?.runDir,serviceEnvByTaskId:G,skipped:d}},co=new Set(["auto","ephemeral","off","persistent"]),lo=s=>{const{cli:e,config:t,isCi:r,isPersistentTarget:o,isTty:a,target:n}=s;if(e!==void 0&&!co.has(e))throw new Error(`--services: expected one of auto|ephemeral|persistent|off, got "${e}"`);const d=e??t??(a&&!r?"auto":"off");return d==="off"?"off":d==="ephemeral"?"ephemeral":d==="persistent"?"registry":o||n==="dev"?"ephemeral":"registry"},qs=s=>s.replace(/^--?/u,""),uo=new Set(["0","1","false","no","true","yes"]),ho=s=>!s.startsWith("-")||/^-(?:\d|\.\d)/u.test(s),ps=(s,e,t,r,o,a)=>{if(r!==void 0)return s.set(e,r),0;const n=o[a+1];return(t?.type??"string")==="boolean"?n!==void 0&&uo.has(n.toLowerCase())?(s.set(e,n.toLowerCase()),1):(s.set(e,"true"),0):n!==void 0&&ho(n)?(s.set(e,n),1):(s.set(e,"true"),0)},fo=(s,e)=>{const t=s.type??"string";if(t==="number"){const r=e.trim(),o=Number(r);return r===""||!Number.isFinite(o)?{error:`--${s.name} expects a number, got "${e}"`}:{value:o}}if(t==="boolean")return["1","true","yes"].includes(e.toLowerCase())?{value:!0}:["0","false","no"].includes(e.toLowerCase())?{value:!1}:{error:`--${s.name} expects a boolean, got "${e}"`};if(t==="enum"){const r=s.choices??[];return r.includes(e)?{value:e}:{error:`--${s.name} must be one of [${r.join(", ")}], got "${e}"`}}return{value:e}},po=s=>{const e=[],t=new Set;for(const r of s){const o=r.name||"<unnamed>";(!r.name||!/^[a-zA-Z][\w-]*$/u.test(r.name))&&e.push(`argument name "${o}" is empty or invalid (start with a letter; use letters, digits, '-', '_')`),t.has(r.name)&&e.push(`duplicate argument name "${o}"`),t.add(r.name),r.alias!==void 0&&r.alias.length!==1&&e.push(`argument "${o}" alias "${r.alias}" must be a single character`);const a=r.type??"string";if(a==="enum"&&(r.choices===void 0||r.choices.length===0)&&e.push(`argument "${o}" has type "enum" but declares no choices`),r.default!==void 0){const n=typeof r.default;a==="number"&&n==="number"||a==="boolean"&&n==="boolean"||(a==="string"||a==="enum")&&n==="string"?a==="enum"&&r.choices&&!r.choices.includes(r.default)&&e.push(`argument "${o}" default "${String(r.default)}" is not one of its choices`):e.push(`argument "${o}" default ${JSON.stringify(r.default)} does not match type "${a}"`)}}return e},go=(s,e)=>{const t=new Map,r=new Map;for(const f of s)t.set(f.name,f),f.alias&&r.set(f.alias,f);const o=new Map,a=[];for(let f=0;f<e.length;f+=1){const u=e[f];if(u==="--"){a.push(...e.slice(f+1));break}if(u.startsWith("--no-")){o.set(qs(u.slice(5)),"false");continue}const p=/^--([^=]+)(?:=(.*))?$/su.exec(u);if(p){const I=p[1];f+=ps(o,I,t.get(I),p[2],e,f);continue}const l=/^-([^=-])(?:=(.*))?$/su.exec(u),$=l?.[1];if(l&&$!==void 0){const I=r.get($);f+=ps(o,I?.name??$,I,l[2],e,f);continue}a.push(u)}const n={},d=[];let h=0;for(const f of s){let u=o.get(f.name);if(u===void 0&&f.positional&&h<a.length&&(u=a[h],h+=1),u===void 0){f.default!==void 0?n[f.name]=f.default:f.required&&d.push(`missing required argument --${f.name}`);continue}const{error:p,value:l}=fo(f,u);p?d.push(p):l!==void 0&&(n[f.name]=l)}return{errors:d,values:n}},mo=s=>`VIS_ARG_${qs(s).replaceAll(/[^a-zA-Z0-9]+/gu,"_").toUpperCase()}`,wo=s=>{const e={};for(const[t,r]of Object.entries(s))e[mo(t)]=String(r);return e},ut=(s,e,t)=>{const r=[`Usage: vis run ${s} [-- <args>]`];if(e&&r.push("",e),t.length===0)return r.join(`
173
- `);r.push("","Arguments:");const o=t.map(n=>{const d=n.positional?`<${n.name}>`:`--${n.name}`,h=n.alias?`, -${n.alias}`:"";return{left:`${d}${h}`,right:n}}),a=Math.max(...o.map(n=>n.left.length));for(const{left:n,right:d}of o){const h=[],f=d.type??"string";h.push(f==="enum"?`enum(${(d.choices??[]).join("|")})`:f),d.required&&h.push("required"),d.default!==void 0&&h.push(`default: ${String(d.default)}`);const u=`${d.description??""}${d.description?" ":""}[${h.join(", ")}]`;r.push(` ${n.padEnd(a)} ${u}`)}return r.join(`
174
- `)},yo=(s,e,t,r)=>{if(!t||t.length===0)return{env:{},kind:"ok"};const o=po(t);if(o.length>0)return{errors:o.map(n=>`invalid \`arguments\` schema for "${s}": ${n}`),help:ut(s,e,t),kind:"invalid"};if(r.includes("--help")||r.includes("-h"))return{kind:"help",text:ut(s,e,t)};const a=go(t,r);return a.errors.length>0?{errors:a.errors,help:ut(s,e,t),kind:"invalid"}:{env:wo(a.values),kind:"ok"}},xt="VIS_AFFECTED_FILES",vo=2e3,gs=async(s,e,t,r,o,a)=>{const n=s.map(k=>{const M=k.overrides.command;if(!M)return;const w=k.overrides.visOptions,A=nt(e,k.projectRoot,!!w?.runFromWorkspaceRoot),S=w?.envFile?gt(A,w.envFile):{},F=t&&(w?.affectedFiles==="env"||w?.affectedFiles==="both")?{[xt]:t.join(`
175
- `)}:{},V=a?.get(k.id)??{},te=qi({interactive:!!o,taskPty:k.pty,workspacePty:w?.pty});return{command:M,cwd:A,env:{INIT_CWD:r,...S,...V,...F,...k.overrides[jt]},name:k.id,...te?{ptySize:{cols:process.stdout.columns??80,rows:process.stdout.rows??24},stdin:"pty"}:{}}}).filter(k=>k!==void 0);if(n.length===0)return;if(!o){await Qe(n,{killOthers:["failure"],onEvent:()=>{}});return}const{abortSignal:d,lifeCycle:h,stdinRegistry:f,store:u}=o,p=n.map(k=>s.find(M=>M.id===k.name)).filter(Boolean),l=k=>n[k]?.stdin==="pty",$=new Map,I=k=>{if(!l(k))return;let M=$.get(k);return M||(M=new ft(it),$.set(k,M)),M};u.unmarkDone(),h.startTasks?.(p);const G=new Map,z=new Map;let b;const x=()=>{for(const k of z.values())try{k("SIGTERM")}catch{}b||(b=setTimeout(()=>{for(const k of z.values())try{k("SIGKILL")}catch{}z.clear()},2e3),b.unref?.())};let O;d&&(O=()=>{x()},d.then(()=>{O?.()}).catch(()=>{O?.()}));try{await Qe(n,{killOthers:["failure"],onEvent:k=>{const M=p[k.index];if(M)switch(k.kind){case"close":{const w=G.get(M.id)??Date.now(),A=k.killed||k.exitCode===0?"success":"failure";h.endTasks?.([{code:k.exitCode??0,endTime:Date.now(),startTime:w,status:A,task:M,terminalOutput:u.getSnapshot().outputs.get(M.id)??""}]),z.delete(k.index),f?.delete(M.id);break}case"error":{if(k.message){const w=I(k.index);w?(w.write(`${k.message}
176
- `),u.setOutput(M.id,w.toString())):u.addOutput(M.id,`${k.message}
177
- `)}break}case"started":{G.set(M.id,Date.now()),k.kill&&z.set(k.index,k.kill),k.write&&f&&f.set(M.id,{kill:k.kill,resize:k.resize,write:k.write});break}case"stderr":case"stdout":{if(k.text){const w=I(k.index);w?(w.write(k.text),u.setOutput(M.id,w.toString())):u.addOutput(M.id,`${k.text}
178
- `)}break}}}})}finally{b&&(clearTimeout(b),b=void 0),u.markDone()}},ms=s=>{try{return process.kill(-s,0),!0}catch{try{return process.kill(s,0),!0}catch{return!1}}},xo=s=>{Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,s)},ko=s=>{const{extraPids:e=[],pidFiles:t,runDir:r}=s,o=[],a=n=>{try{process.kill(-n,"SIGTERM")}catch{try{process.kill(n,"SIGTERM")}catch{}}};for(const n of t){let d;try{const h=rr(n),f=Number.parseInt(h.trim(),10);d=Number.isFinite(f)&&f>0?f:void 0}catch{continue}d!==void 0&&(o.push(d),a(d))}for(const n of e)!Number.isFinite(n)||n<=0||(o.push(n),a(n));if(o.length>0){const n=Date.now()+1500;for(;Date.now()<n;){let d=!0;for(const h of o)if(ms(h)){d=!1;break}if(d)break;xo(100)}for(const d of o)if(ms(d))try{process.kill(-d,"SIGKILL")}catch{try{process.kill(d,"SIGKILL")}catch{}}}r&&ir(r)},it=256*1024;class jo{#e;#r="";#s=!1;constructor(e){this.#e=e}append(e){this.#r+=e,this.#r.length>this.#e&&(this.#r=this.#r.slice(-this.#e),this.#s=!0)}toString(){return this.#s?`[...output truncated, showing last ${Math.round(this.#e/1024)}KB...]
179
- ${this.#r}`:this.#r}}const Us=s=>{const e=s.overrides.visOptions;if(e&&typeof e=="object")return e},$o=s=>`'${s.replaceAll("'",String.raw`'\''`)}'`,kt=s=>process.platform==="win32"?s.length>0&&!/[\s"&|<>^()%!]/.test(s)?s:`"${s.replaceAll('"','""')}"`:$o(s),bo=(s,e,t)=>{if(!e||e.length===0||t===!1||t===void 0)return s;if(t==="args"||t==="both"){const r=e.map(o=>kt(o)).join(" ");return`${s} ${r}`}return s},Hs="visForwardedArgs",jt="visTaskArgEnv",So=(s,e)=>{const t=e.overrides[Hs];if(!Array.isArray(t)||t.length===0)return s;const r=t.map(o=>kt(o)).join(" ");return`${s} ${r}`},To=async(s,e,t)=>{if(!e)return t();const r=s.get(e)??Promise.resolve();let o;const a=new Promise(d=>{o=d}),n=r.then(()=>a);s.set(e,n),await r;try{return await t()}finally{o(),s.get(e)===n&&s.delete(e)}},Co=s=>{let e=Math.max(0,Math.floor(s));return{claim(t){const r=Math.max(0,Math.min(t,e));return e-=r,r},get remaining(){return e}}},Io=(s,e,t)=>{const r=`${e}\0${typeof t=="string"?t:String(t)}`,o=s.get(r);if(o)return o;const a=gt(e,t);return s.set(r,a),a},ws=s=>{const e=new Map;return async(t,r)=>{const{affectedFiles:o,currentOs:a,hooks:n,initCwd:d,lifeCycle:h,mutexPool:f,onOutput:u,onOutputReplace:p,retryBudget:l,serviceEnvByTaskId:$,serviceEventBridge:I,stdinRegistry:G,strictEnv:z,workspaceRoot:b}=s,x=Us(t),O=nt(b,r.cwd??t.projectRoot,x?.runFromWorkspaceRoot===!0),k=t.overrides.command;if(!k)return{code:0,terminalOutput:`No command configured for ${t.target.project}:${t.target.target}`};const M=So(k,t),w=bo(M,o,x?.affectedFiles),A=ni(x,a),S=x?.shellArgs,F=S&&S.length>0?S.join(" "):"-c",V=A?`${A} ${F} ${kt(w)}`:w,te=x?.envFile?Io(e,O,x.envFile):void 0,ue={};o&&o.length>0&&(x?.affectedFiles==="env"||x?.affectedFiles==="both")&&(ue[xt]=o.join(`
180
- `));const q=$?.get(t.id),Y={INIT_CWD:d,...te,...q,...r.env,...ue,...t.overrides[jt]};if(x?.strictEnv??z??!1){const C=Yi({command:w,processEnv:process.env,taskEnv:Y,taskId:t.id});if(C){const ge=Ji(C);return h?.onTaskStderr?.(t,ge),{code:1,terminalOutput:ge}}}const ce=x?.pty===!0,re=!!G,ie=t.pty===!0?!0:t.pty===!1?!1:re||ce;ie&&(t.cache=!1);const ae=ie?void 0:new jo(it),_=ie?new ft(it):void 0;let H;const X=C=>{if(C.kind==="started"&&(H=C.kill,C.write&&G&&G.set(t.id,{kill:C.kill,resize:C.resize,write:C.write}),I?.onRegistryTaskStarted(t.id)),(C.kind==="stdout"||C.kind==="stderr")&&C.text!==void 0)if(C.kind==="stdout"?h?.onTaskStdout?.(t,C.text):h?.onTaskStderr?.(t,C.text),_)_.write(C.text),re&&p?.(t.id,_.toString()),I&&I.onTaskOutput(t.id,C.text);else{const ge=`${C.text}
181
- `;ae.append(ge),u?.(t.id,ge)}C.kind==="close"&&(G&&G.delete(t.id),I&&I.onRegistryTaskClosed(t.id,C.exitCode??0,!!C.killed).catch(()=>{}))},he=async()=>{const C=x?.retryCount??0,ge=x?.retryDelay,Te=l?l.claim(C):C,Me=typeof x?.timeout=="number"&&x.timeout>0?x.timeout:0,Le=typeof x?.killGracePeriodMs=="number"&&x.killGracePeriodMs>=0?x.killGracePeriodMs:5e3;let Fe=!1,ee=0;const Ce=_n({killGracePeriodMs:Le,onTimeout:()=>{Fe=!0},sendSignal:ye=>{H?.(ye)},timeoutMs:Me});let Ie;try{Ie=await Qe([{command:V,cwd:O,env:Y,name:t.id,...ie?{ptySize:{cols:process.stdout.columns??80,rows:process.stdout.rows??24},stdin:"pty"}:{}}],{killOthers:["failure"],onEvent:X,...Te>0?{restart:{delay:ge??"exponential",onRetry:async(ye,$e,be)=>{ee=ye,n&&await n.callHook("task:retry",t,ye,be)},tries:Te}}:{}})}finally{Ce.cancel()}const le=Ie.closeEvents[0],we=_?_.toString():ae.toString();return Fe?{code:124,retryAttempts:ee,terminalOutput:`${we}
172
+ `,vo=()=>{const s=Ur(oe(Ri(),"vis-services-")),e=oe(s,"bootstrap.mjs");return $s(e,yo),{runDir:s,scriptPath:e}},Vs=(s,e,t)=>{const r=t.replaceAll(/[^\w-]/g,"_");return{configFile:oe(s,`${r}.json`),logFile:oe(s,`${r}.log`),pidFile:oe(s,`${r}.pid`),scriptPath:e}},ko=s=>{const{paths:e,service:t}=s,r=t.config.readiness?.tcp?.port??t.config.port;if(typeof r!="number")throw new TypeError(`Service ${t.id} has no TCP readiness port — declare \`service.port\` or \`service.readiness.tcp.port\`.`);const o={...t.env,PATH:ur(t.cwd,t.env)};return{command:t.command,cwd:t.cwd,env:o,host:t.config.readiness?.tcp?.host??"127.0.0.1",id:t.id,logFile:e.logFile,pidFile:e.pidFile,port:r,timeoutMs:t.config.readiness?.tcp?.timeoutMs??3e4}},xo=s=>`node ${JSON.stringify(s.scriptPath)} ${JSON.stringify(s.configFile)}`,jo=s=>{const{id:e,visBin:t,workspaceRoot:r}=s;return`node ${JSON.stringify(t)} service start ${JSON.stringify(e)} --cwd ${JSON.stringify(r)}`},$o=s=>{const{missingServiceIds:e,mode:t,taskGraph:r,visBin:o,workspaceRoot:a}=s,{services:i,skipped:d}=Us(a,e,r);if(i.length===0)return{chain:[],ephemeralPidFiles:[],runDir:void 0,serviceEnvByTaskId:new Map,skipped:d};const u=wo(i.map(j=>j.id),r),f=new Map(i.map(j=>[j.id,j])),h=[],p=[];if(t==="ephemeral")for(const j of u){const I=f.get(j);I&&p.push({id:j,payload:ko({paths:{logFile:"",pidFile:""},service:I})})}let l;t==="ephemeral"&&(l=vo());let $;for(const j of u){const I=f.get(j),S=r.tasks[j];if(!I||!S)continue;let x;if(t==="ephemeral"){const O=Vs(l.runDir,l.scriptPath,j),w={...p.find(A=>A.id===j).payload,logFile:O.logFile,pidFile:O.pidFile};$s(O.configFile,JSON.stringify(w)),x=xo(O),h.push(O.pidFile)}else x=jo({id:j,visBin:o,workspaceRoot:a});if(S.overrides={...S.overrides,command:x},S.cache=!1,r.tasks[j]=S,$!==void 0){const O=r.dependencies[j]??[];O.includes($)||(r.dependencies[j]=[...O,$])}$=j}const R=new Set(u),G=new Map,V=j=>{const I=new Set,S=[...r.dependencies[j]??[]],x=new Set;for(;S.length>0;){const O=S.pop();if(!x.has(O)){x.add(O),R.has(O)&&I.add(O);for(const w of r.dependencies[O]??[])x.has(w)||S.push(w)}}return[...I].sort()};for(const j of Object.keys(r.dependencies)){if(R.has(j))continue;const I=V(j);if(I.length===0)continue;const S={};for(const x of I){const O=f.get(x);O?.config.env&&Object.assign(S,O.config.env)}Object.keys(S).length>0&&G.set(j,S)}return{chain:u,ephemeralPidFiles:h,runDir:l?.runDir,serviceEnvByTaskId:G,skipped:d}},bo=new Set(["auto","ephemeral","off","persistent"]),So=s=>{const{cli:e,config:t,isCi:r,isPersistentTarget:o,isTty:a,target:i}=s;if(e!==void 0&&!bo.has(e))throw new Error(`--services: expected one of auto|ephemeral|persistent|off, got "${e}"`);const d=e??t??(a&&!r?"auto":"off");return d==="off"?"off":d==="ephemeral"?"ephemeral":d==="persistent"?"registry":o||i==="dev"?"ephemeral":"registry"},Hs=s=>s.replace(/^--?/u,""),To=new Set(["0","1","false","no","true","yes"]),Co=s=>!s.startsWith("-")||/^-(?:\d|\.\d)/u.test(s),ys=(s,e,t,r,o,a)=>{if(r!==void 0)return s.set(e,r),0;const i=o[a+1];return(t?.type??"string")==="boolean"?i!==void 0&&To.has(i.toLowerCase())?(s.set(e,i.toLowerCase()),1):(s.set(e,"true"),0):i!==void 0&&Co(i)?(s.set(e,i),1):(s.set(e,"true"),0)},Io=(s,e)=>{const t=s.type??"string";if(t==="number"){const r=e.trim(),o=Number(r);return r===""||!Number.isFinite(o)?{error:`--${s.name} expects a number, got "${e}"`}:{value:o}}if(t==="boolean")return["1","true","yes"].includes(e.toLowerCase())?{value:!0}:["0","false","no"].includes(e.toLowerCase())?{value:!1}:{error:`--${s.name} expects a boolean, got "${e}"`};if(t==="enum"){const r=s.choices??[];return r.includes(e)?{value:e}:{error:`--${s.name} must be one of [${r.join(", ")}], got "${e}"`}}return{value:e}},Ro=s=>{const e=[],t=new Set;for(const r of s){const o=r.name||"<unnamed>";(!r.name||!/^[a-zA-Z][\w-]*$/u.test(r.name))&&e.push(`argument name "${o}" is empty or invalid (start with a letter; use letters, digits, '-', '_')`),t.has(r.name)&&e.push(`duplicate argument name "${o}"`),t.add(r.name),r.alias!==void 0&&r.alias.length!==1&&e.push(`argument "${o}" alias "${r.alias}" must be a single character`);const a=r.type??"string";if(a==="enum"&&(r.choices===void 0||r.choices.length===0)&&e.push(`argument "${o}" has type "enum" but declares no choices`),r.default!==void 0){const i=typeof r.default;a==="number"&&i==="number"||a==="boolean"&&i==="boolean"||(a==="string"||a==="enum")&&i==="string"?a==="enum"&&r.choices&&!r.choices.includes(r.default)&&e.push(`argument "${o}" default "${String(r.default)}" is not one of its choices`):e.push(`argument "${o}" default ${JSON.stringify(r.default)} does not match type "${a}"`)}}return e},Eo=(s,e)=>{const t=new Map,r=new Map;for(const f of s)t.set(f.name,f),f.alias&&r.set(f.alias,f);const o=new Map,a=[];for(let f=0;f<e.length;f+=1){const h=e[f];if(h==="--"){a.push(...e.slice(f+1));break}if(h.startsWith("--no-")){o.set(Hs(h.slice(5)),"false");continue}const p=/^--([^=]+)(?:=(.*))?$/su.exec(h);if(p){const R=p[1];f+=ys(o,R,t.get(R),p[2],e,f);continue}const l=/^-([^=-])(?:=(.*))?$/su.exec(h),$=l?.[1];if(l&&$!==void 0){const R=r.get($);f+=ys(o,R?.name??$,R,l[2],e,f);continue}a.push(h)}const i={},d=[];let u=0;for(const f of s){let h=o.get(f.name);if(h===void 0&&f.positional&&u<a.length&&(h=a[u],u+=1),h===void 0){f.default!==void 0?i[f.name]=f.default:f.required&&d.push(`missing required argument --${f.name}`);continue}const{error:p,value:l}=Io(f,h);p?d.push(p):l!==void 0&&(i[f.name]=l)}return{errors:d,values:i}},Mo=s=>`VIS_ARG_${Hs(s).replaceAll(/[^a-zA-Z0-9]+/gu,"_").toUpperCase()}`,Fo=s=>{const e={};for(const[t,r]of Object.entries(s))e[Mo(t)]=String(r);return e},ht=(s,e,t)=>{const r=[`Usage: vis run ${s} [-- <args>]`];if(e&&r.push("",e),t.length===0)return r.join(`
173
+ `);r.push("","Arguments:");const o=t.map(i=>{const d=i.positional?`<${i.name}>`:`--${i.name}`,u=i.alias?`, -${i.alias}`:"";return{left:`${d}${u}`,right:i}}),a=Math.max(...o.map(i=>i.left.length));for(const{left:i,right:d}of o){const u=[],f=d.type??"string";u.push(f==="enum"?`enum(${(d.choices??[]).join("|")})`:f),d.required&&u.push("required"),d.default!==void 0&&u.push(`default: ${String(d.default)}`);const h=`${d.description??""}${d.description?" ":""}[${u.join(", ")}]`;r.push(` ${i.padEnd(a)} ${h}`)}return r.join(`
174
+ `)},Oo=(s,e,t,r)=>{if(!t||t.length===0)return{env:{},kind:"ok"};const o=Ro(t);if(o.length>0)return{errors:o.map(i=>`invalid \`arguments\` schema for "${s}": ${i}`),help:ht(s,e,t),kind:"invalid"};if(r.includes("--help")||r.includes("-h"))return{kind:"help",text:ht(s,e,t)};const a=Eo(t,r);return a.errors.length>0?{errors:a.errors,help:ht(s,e,t),kind:"invalid"}:{env:Fo(a.values),kind:"ok"}},$t="VIS_AFFECTED_FILES",Po=2e3,vs=async(s,e,t,r,o,a)=>{const i=s.map(x=>{const O=x.overrides.command;if(!O)return;const w=x.overrides.visOptions,A=nt(e,x.projectRoot,!!w?.runFromWorkspaceRoot),b=w?.envFile?yt(A,w.envFile):{},M=t&&(w?.affectedFiles==="env"||w?.affectedFiles==="both")?{[$t]:t.join(`
175
+ `)}:{},H=a?.get(x.id)??{},te=Yi({interactive:!!o,taskPty:x.pty,workspacePty:w?.pty});return{command:O,cwd:A,env:{INIT_CWD:r,...b,...H,...M,...x.overrides[St]},name:x.id,...te?{ptySize:{cols:process.stdout.columns??80,rows:process.stdout.rows??24},stdin:"pty"}:{}}}).filter(x=>x!==void 0);if(i.length===0)return;if(!o){await Qe(i,{killOthers:["failure"],onEvent:()=>{}});return}const{abortSignal:d,lifeCycle:u,stdinRegistry:f,store:h}=o,p=i.map(x=>s.find(O=>O.id===x.name)).filter(Boolean),l=x=>i[x]?.stdin==="pty",$=new Map,R=x=>{if(!l(x))return;let O=$.get(x);return O||(O=new mt(it),$.set(x,O)),O};h.unmarkDone(),u.startTasks?.(p);const G=new Map,V=new Map;let j;const I=()=>{for(const x of V.values())try{x("SIGTERM")}catch{}j||(j=setTimeout(()=>{for(const x of V.values())try{x("SIGKILL")}catch{}V.clear()},2e3),j.unref?.())};let S;d&&(S=()=>{I()},d.then(()=>{S?.()}).catch(()=>{S?.()}));try{await Qe(i,{killOthers:["failure"],onEvent:x=>{const O=p[x.index];if(O)switch(x.kind){case"close":{const w=G.get(O.id)??Date.now(),A=x.killed||x.exitCode===0?"success":"failure";u.endTasks?.([{code:x.exitCode??0,endTime:Date.now(),startTime:w,status:A,task:O,terminalOutput:h.getSnapshot().outputs.get(O.id)??""}]),V.delete(x.index),f?.delete(O.id);break}case"error":{if(x.message){const w=R(x.index);w?(w.write(`${x.message}
176
+ `),h.setOutput(O.id,w.toString())):h.addOutput(O.id,`${x.message}
177
+ `)}break}case"started":{G.set(O.id,Date.now()),x.kill&&V.set(x.index,x.kill),x.write&&f&&f.set(O.id,{kill:x.kill,resize:x.resize,write:x.write});break}case"stderr":case"stdout":{if(x.text){const w=R(x.index);w?(w.write(x.text),h.setOutput(O.id,w.toString())):h.addOutput(O.id,`${x.text}
178
+ `)}break}}}})}finally{j&&(clearTimeout(j),j=void 0),h.markDone()}},ks=s=>{try{return process.kill(-s,0),!0}catch{try{return process.kill(s,0),!0}catch{return!1}}},Ao=s=>{Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,s)},Do=s=>{const{extraPids:e=[],pidFiles:t,runDir:r}=s,o=[],a=i=>{try{process.kill(-i,"SIGTERM")}catch{try{process.kill(i,"SIGTERM")}catch{}}};for(const i of t){let d;try{const u=ar(i),f=Number.parseInt(u.trim(),10);d=Number.isFinite(f)&&f>0?f:void 0}catch{continue}d!==void 0&&(o.push(d),a(d))}for(const i of e)!Number.isFinite(i)||i<=0||(o.push(i),a(i));if(o.length>0){const i=Date.now()+1500;for(;Date.now()<i;){let d=!0;for(const u of o)if(ks(u)){d=!1;break}if(d)break;Ao(100)}for(const d of o)if(ks(d))try{process.kill(-d,"SIGKILL")}catch{try{process.kill(d,"SIGKILL")}catch{}}}r&&cr(r)},it=256*1024;class Lo{#e;#r="";#s=!1;constructor(e){this.#e=e}append(e){this.#r+=e,this.#r.length>this.#e&&(this.#r=this.#r.slice(-this.#e),this.#s=!0)}toString(){return this.#s?`[...output truncated, showing last ${Math.round(this.#e/1024)}KB...]
179
+ ${this.#r}`:this.#r}}const zs=s=>{const e=s.overrides.visOptions;if(e&&typeof e=="object")return e},Bo=s=>`'${s.replaceAll("'",String.raw`'\''`)}'`,bt=s=>process.platform==="win32"?s.length>0&&!/[\s"&|<>^()%!]/.test(s)?s:`"${s.replaceAll('"','""')}"`:Bo(s),No=(s,e,t)=>{if(!e||e.length===0||t===!1||t===void 0)return s;if(t==="args"||t==="both"){const r=e.map(o=>bt(o)).join(" ");return`${s} ${r}`}return s},Ys="visForwardedArgs",St="visTaskArgEnv",Go=(s,e)=>{const t=e.overrides[Ys];if(!Array.isArray(t)||t.length===0)return s;const r=t.map(o=>bt(o)).join(" ");return`${s} ${r}`},_o=async(s,e,t)=>{if(!e)return t();const r=s.get(e)??Promise.resolve();let o;const a=new Promise(d=>{o=d}),i=r.then(()=>a);s.set(e,i),await r;try{return await t()}finally{o(),s.get(e)===i&&s.delete(e)}},qo=s=>{let e=Math.max(0,Math.floor(s));return{claim(t){const r=Math.max(0,Math.min(t,e));return e-=r,r},get remaining(){return e}}},Wo=(s,e,t)=>{const r=`${e}\0${typeof t=="string"?t:String(t)}`,o=s.get(r);if(o)return o;const a=yt(e,t);return s.set(r,a),a},xs=s=>{const e=new Map;return async(t,r)=>{const{affectedFiles:o,currentOs:a,hooks:i,initCwd:d,lifeCycle:u,mutexPool:f,onOutput:h,onOutputReplace:p,retryBudget:l,serviceEnvByTaskId:$,serviceEventBridge:R,stdinRegistry:G,strictEnv:V,taskSlots:j,workspaceRoot:I}=s,S=zs(t),x=nt(I,r.cwd??t.projectRoot,S?.runFromWorkspaceRoot===!0),O=t.overrides.command;if(!O)return{code:0,terminalOutput:`No command configured for ${t.target.project}:${t.target.target}`};const w=Go(O,t),A=No(w,o,S?.affectedFiles),b=ui(S,a),M=S?.shellArgs,H=M&&M.length>0?M.join(" "):"-c",te=b?`${b} ${H} ${bt(A)}`:A,fe=S?.envFile?Wo(e,x,S.envFile):void 0,W={};o&&o.length>0&&(S?.affectedFiles==="env"||S?.affectedFiles==="both")&&(W[$t]=o.join(`
180
+ `));const Y=$?.get(t.id),ce={INIT_CWD:d,VIS_TASK_SLOTS:String(j),...fe,...Y,...r.env,...W,...t.overrides[St]};if(S?.strictEnv??V??!1){const E=en({command:A,processEnv:process.env,taskEnv:ce,taskId:t.id});if(E){const ge=tn(E);return u?.onTaskStderr?.(t,ge),{code:1,terminalOutput:ge}}}const re=S?.pty===!0,ae=!!G,ne=t.pty===!0?!0:t.pty===!1?!1:ae||re;ne&&(t.cache=!1);const U=ne?void 0:new Lo(it),_=ne?new mt(it):void 0;let X;const pe=E=>{if(E.kind==="started"&&(X=E.kill,E.write&&G&&G.set(t.id,{kill:E.kill,resize:E.resize,write:E.write}),R?.onRegistryTaskStarted(t.id)),(E.kind==="stdout"||E.kind==="stderr")&&E.text!==void 0)if(E.kind==="stdout"?u?.onTaskStdout?.(t,E.text):u?.onTaskStderr?.(t,E.text),_)_.write(E.text),ae&&p?.(t.id,_.toString()),R&&R.onTaskOutput(t.id,E.text);else{const ge=`${E.text}
181
+ `;U.append(ge),h?.(t.id,ge)}E.kind==="close"&&(G&&G.delete(t.id),R&&R.onRegistryTaskClosed(t.id,E.exitCode??0,!!E.killed).catch(()=>{}))},je=async()=>{const E=S?.retryCount??0,ge=S?.retryDelay,Ie=l?l.claim(E):E,Me=typeof S?.timeout=="number"&&S.timeout>0?S.timeout:0,Le=typeof S?.killGracePeriodMs=="number"&&S.killGracePeriodMs>=0?S.killGracePeriodMs:5e3;let Fe=!1,Z=0;const Oe=zn({killGracePeriodMs:Le,onTimeout:()=>{Fe=!0},sendSignal:ve=>{X?.(ve)},timeoutMs:Me});let we;try{we=await Qe([{command:te,cwd:x,env:ce,name:t.id,...ne?{ptySize:{cols:process.stdout.columns??80,rows:process.stdout.rows??24},stdin:"pty"}:{}}],{killOthers:["failure"],onEvent:pe,...Ie>0?{restart:{delay:ge??"exponential",onRetry:async(ve,Se,T)=>{Z=ve,i&&await i.callHook("task:retry",t,ve,T)},tries:Ie}}:{}})}finally{Oe.cancel()}const de=we.closeEvents[0],ye=_?_.toString():U.toString();return Fe?{code:124,retryAttempts:Z,terminalOutput:`${ye}
182
182
  [timeout] Task "${t.id}" exceeded ${Me}ms budget.
183
- `}:{code:le?.exitCode??1,retryAttempts:ee,terminalOutput:we}};return f?To(f,x?.mutex,he):he()}},Ro=s=>{if(!s||s.trim().length===0)return;const e=Number.parseFloat(s);return!Number.isFinite(e)||e<=0?{invalid:s}:{value:Math.floor(e)}},Eo=async(s,e)=>{const t=await fr(s,{dataDirectory:Ze(s)});if(!t){e.warn(`No previous run recorded yet. Run a task at least once to populate ${pr(s,{dataDirectory:Ze(s)})}.`);return}const r=(t.duration/1e3).toFixed(2);if(e.info(""),e.info(`Last run — ${t.startTime} (${r}s)`),e.info(""),e.info(` Total: ${String(t.stats.total)}`),e.info(` Succeeded: ${String(t.stats.succeeded)}`),e.info(` Cached: ${String(t.stats.cached)}`),e.info(` Failed: ${String(t.stats.failed)}`),e.info(` Skipped: ${String(t.stats.skipped)}`),e.info(""),t.stats.failed>0){const a=t.tasks.filter(n=>n.exitCode!==void 0&&n.exitCode!==0);e.info("Failed tasks:");for(const n of a){const d=n.duration??0;e.info(` × ${n.taskId} (exit ${String(n.exitCode??-1)}, ${d}ms)`)}e.info("")}const o=[...t.tasks].filter(a=>typeof a.duration=="number").sort((a,n)=>(n.duration??0)-(a.duration??0)).slice(0,5);if(o.length>0){e.info("Slowest tasks:");for(const a of o)e.info(` ${a.taskId.padEnd(40)} ${String(a.duration??0).padStart(6)}ms [${a.cacheStatus}]`);e.info("")}},Mo=s=>{if(!(s===void 0||s==="")){if(s!=="read"&&s!=="write"&&s!=="readwrite")throw new Error(`--cache-mode must be one of: read, write, readwrite (received "${s}")`);return s}},Fo=s=>{if(!(s===void 0||s==="")){if(s!=="http"&&s!=="reapi")throw new Error(`--cache-backend must be one of: http, reapi (received "${s}")`);return s}},Oo=s=>{if(!(s===void 0||s==="")){if(s!=="declared"&&s!=="trace")throw new Error(`--hash-mode must be one of: declared, trace (received "${s}")`);return s}},sa=async({argument:s,logger:e,options:t,runtime:r,visConfig:o,workspaceRoot:a})=>{if(!a)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const n=a;if(_r({logger:e,options:t,visConfig:o},n),ai(n),t.lastDetails===!0){await Eo(n,e);return}const d=process.cwd(),h=await Rr(n),{config:f,packageJsons:u,projectOptions:p,workspace:l}=Er(n,o,h),$=Mr(n,l,u);let I=s[0];if(!I){const g=ts(l);if(process.stdout.isTTY&&process.stdin.isTTY){const y=await tn(g);if(!y){e.info("No target selected.");return}I=y,await Dn(`vis run ${y}`)}else{e.info("Available targets:"),e.info(""),e.info(en(g)),e.info(""),e.info("Usage: vis run <target>");return}}if(f.constraints&&!t.skipConstraints){const g=or($,f.constraints);if(g.length>0){for(const y of g)e.error(`[${y.rule}] ${y.message}`);throw new Error(`${g.length} project constraint violation(s) found. Use --skip-constraints to bypass.`)}}if(t.affected){const g=[I];t.parallel!==void 0&&g.push(`--parallel=${String(t.parallel)}`),t.cache||g.push("--no-cache"),t.query&&g.push(`--query=${String(t.query)}`),t.reverse&&g.push("--reverse"),typeof t.runnerTags=="string"&&t.runnerTags!==""&&g.push(`--runner-tags=${t.runnerTags}`),await r.runCommand("affected",{argv:g});return}const G=await ei(I,l,process.cwd(),n),z=Ki(p),b=Xi(G.target,z);b!==G.target&&e.debug?.(`Resolved alias "${G.target}" → "${b}"`);let x=G.projects;const O=s.slice(1).map(String);if(t.projects){const g=new Set(t.projects.split(",").map(y=>y.trim()));if(x=x.filter(y=>g.has(y)),x.length===0)throw new Error(`No matching projects found for: ${String(t.projects)}`)}if(t.query&&(x=ti(x,l,t.query),x.length===0)){e.info(`Query "${String(t.query)}" matched no projects.`);return}const k=si(),M=process.env[xt],w=M?M.split(`
184
- `).filter(Boolean):void 0,A=(typeof t.runnerTags=="string"?t.runnerTags:process.env.VIS_RUNNER_TAGS)??void 0,S=A?new Set(A.split(",").map(g=>g.trim()).filter(Boolean)):void 0,F=[],V=new Map;for(const g of x){const y=p.get(g)?.[b];if(!y)continue;const j=y.options;if(!j?.internal){if(!ri(j,!!Ve)){e.debug?.(`Skipping ${g}:${b} — runInCI filter`);continue}if(!ii(j,S)){e.debug?.(`Skipping ${g}:${b} — runner-tags filter`);continue}F.push(g),V.set(g,y)}}if(F.length===0){const g=ts(l),y=Object.entries(l.projects).filter(([,j])=>j.targets?.[b]!==void 0).map(([j])=>j);if(e.error(`No projects have the "${b}" target.`),y.length>0){e.info(""),e.info(`Target "${b}" exists in these projects but was filtered out:`);for(const j of y.slice(0,5))e.info(` - ${j}`);y.length>5&&e.info(` …and ${y.length-5} more`)}else{const j=Fs(b,g,3);j.length>0&&(e.info(""),e.info(j.length===1?`Did you mean "${j[0]}"?`:`Did you mean one of: ${j.map(L=>`"${L}"`).join(", ")}?`)),e.info(""),e.info("Run `vis run` without arguments to see all available targets.")}return}const te=t.pty===!0,ue=F.map(g=>({project:g,schema:V.get(g)?.arguments})).filter(g=>Array.isArray(g.schema)&&g.schema.length>0),q=new Map;for(const{project:g,schema:y}of ue){const j=JSON.stringify(y),L=q.get(j)??[];L.push(g),q.set(j,L)}if(q.size>1){const g=[...q.values()].map(y=>y.join(", ")).join(" | ");throw new Error(`Target "${b}" declares conflicting \`arguments\` schemas across projects (${g}). Run a single project (e.g. \`vis run ${ue[0]?.project}:${b}\` or --projects=<name>) so the argument contract is unambiguous.`)}const Y=ue[0]?.schema,ce=V.get(ue[0]?.project??F[0])?.description,re=yo(b,ce,Y,O);if(re.kind==="help"){e.info(re.text);return}if(re.kind==="invalid"){e.info(`Invalid arguments for "${b}":`);for(const g of re.errors)e.info(` ✖ ${g}`);throw e.info(""),e.info(re.help),new Error(`Invalid arguments for target "${b}"`)}const ie=re.env,ae=Oo(t.hashMode);let _=F.map(g=>{const y=l.projects[g],j=V.get(g),L={project:g,target:b},U=`${g}:${b}`,J=te?{...j.options,pty:j.options?.pty??!0}:j.options,D=j.command?qt(j.command,{affectedFiles:w,projectRoot:y?.root}):j.command,P=y?.root&&y.root.length>0?y.root:".",se=(j.outputs??[]).map(E=>typeof E!="string"?E:E.replaceAll("{projectRoot}",P).replaceAll("{projectName}",g));return{cache:j.cache,hashMode:ae??j.hashMode,id:U,outputs:se,overrides:{command:D,...O.length>0?{[Hs]:O}:{},...Object.keys(ie).length>0?{[jt]:ie}:{},...J?{visOptions:J}:{}},parallelism:j.parallelism,projectRoot:y?.root,target:L}});const H=[],X=[];for(const g of _)Us(g)?.persistent?(g.cache=!1,H.push(g)):X.push(g);_=X;const he=ar(t.partition);if(he&&(_=cr.partitionTasks(_,he),e.info(`Partition ${he.index}/${he.total}: running ${_.length} task(s)`),_.length===0)){e.info("No tasks assigned to this partition.");return}let C=lr([..._,...H],{onCycleBroken:g=>{e.warn(`Ignoring dev-only dependency cycle (build order is ambiguous): ${g.join(" → ")}`)},projectGraph:$,targetDefaults:f.tasks,workspace:l});for(const[g,y]of Object.entries(C.tasks)){const j=y.target.project,L=y.target.target,U=p.get(j)?.[L];if(!U)continue;const J=l.projects[j];let D=!1;const P={...y.overrides};P.visOptions===void 0&&U.options&&(P.visOptions=U.options,D=!0),P.command===void 0&&U.command&&(P.command=qt(U.command,{affectedFiles:w,projectRoot:J?.root}),D=!0),D&&(y.overrides=P,C.tasks[g]=y)}if(typeof t.skipCache=="string"&&t.skipCache.trim()!=="")if(t.cache){const g=Hi(t.skipCache,l,Object.keys(C.tasks));for(const y of g.skipTaskIds){const j=C.tasks[y];j!==void 0&&(j.cache=!1)}g.unmatchedPatterns.length>0&&e.warn(`--skip-cache: no tasks matched ${g.unmatchedPatterns.map(y=>`"${y}"`).join(", ")}`),g.skipTaskIds.size>0&&e.debug?.(`--skip-cache: bypassing cache for ${String(g.skipTaskIds.size)} task(s)`)}else e.debug?.("--skip-cache ignored: --no-cache already disables caching for the whole run");await qr(n,f.toolchain,{error:g=>{e.error(g)},info:g=>{e.info(g)},warn:g=>{e.warn(g)}},!!t.skipToolchain);const ge=t.preflight!==!1&&f.preflight?.lockfile!==!1,Te=Or(n,Ve,{warn:g=>{e.warn(g)}},{skip:!ge});if(!Te.shouldContinue)throw new Error(`${Te.formattedMessage??"preflight: lockfile drift detected"} (pass --no-preflight to bypass)`);ge&&!Ve&&process.stdin.isTTY&&process.stdout.isTTY&&await _i(n,{logger:{info:g=>{e.info(g)},warn:g=>{e.warn(g)}},projectManifests:[...u.values()]});const Me=process.env.VIS_VERSION??"0.0.0",Le=t.dryRun?void 0:async g=>{try{return await Qr(g.config,{timeoutMs:vo}),!0}catch{return!1}},Fe=await Wr(n),ee=await Yn({initialTasks:[..._,...H],probe:Le,registeredEntries:Fe,taskGraph:C,visVersion:Me}),Ce=[];let Ie,le=0;const we=[],ye=new Map;let $e=[];const be=new Set;let T=null,v=null;if(ee.diagnostics.length>0){const g=!!(process.stdout.isTTY&&process.stdin.isTTY),y=t.dryRun?"off":lo({cli:t.services,config:f.run?.services,isCi:!!Ve,isPersistentTarget:H.length>0,isTty:g,target:b});if(y==="off"){for(const P of ee.diagnostics)e.error(P.message);throw new Error(`${ee.diagnostics.length} service dependency error(s) — start the missing services or invoke them directly.`)}const j=ee.diagnostics.map(P=>P.targetId),L=y,U=L==="registry"?Gs(n,j,C):void 0,J=process.argv[1]??"vis",D=ao({missingServiceIds:j,mode:L,taskGraph:C,visBin:J,workspaceRoot:n});if(D.skipped.length>0){for(const{id:P,reason:se}of D.skipped)e.error(`Cannot auto-start ${P}: ${se}`);throw new Error(`${D.skipped.length} service(s) cannot be auto-started — invoke them directly or add a service config.`)}Ce.push(...D.ephemeralPidFiles),Ie=D.runDir,$e=D.chain;for(const P of D.chain)be.add(P);if(L==="registry"&&(le=D.chain.length,we.push(...D.chain)),D.chain.length>0){const P=new ss(D.chain),se=new Map;if(L==="ephemeral"&&D.runDir)for(const E of D.chain){const N=_s(D.runDir,`${D.runDir}/bootstrap.mjs`,E);se.set(E,{ephemeral:{configFile:N.configFile,cwd:n,logFile:N.logFile,pidFile:N.pidFile,scriptPath:N.scriptPath},mode:"ephemeral"})}else if(L==="registry"&&U)for(const E of U.services)se.set(E.id,{mode:"registry",registry:{command:E.command,config:E.config,cwd:E.cwd,env:E.env}});if(se.size>0){const E=new Qn({indexToId:new Map,services:se,sink:{crashed:(N,B)=>{P.markCrashed(N,B)},failed:(N,B,Z)=>{P.markFailed(N,B,Z)},log:(N,B)=>{P.appendLog(N,B)},ready:(N,B)=>{P.markReady(N,B)},started:(N,B)=>{P.markStarted(N,B),L==="registry"&&B!==null&&ye.set(N,B)},starting:N=>{P.markStarting(N)}},workspaceRoot:n});T=P,v=E}}for(const[P,se]of D.serviceEnvByTaskId){const E=ee.serviceEnvByTaskId.get(P)??{};ee.serviceEnvByTaskId.set(P,{...E,...se})}}const R=new Set(H.map(g=>g.id));if(_=ee.initialTasks.filter(g=>!R.has(g.id)),C=ee.taskGraph,$e.length>0&&(_=[...$e.map(g=>C.tasks[g]).filter(g=>g!==void 0),..._]),H.length>0){const g=new Set(H.map(J=>J.id)),y={};for(const[J,D]of Object.entries(C.tasks))g.has(J)||(y[J]=D);const j={};for(const[J,D]of Object.entries(C.dependencies))g.has(J)||(j[J]=D.filter(P=>!g.has(P)));const L=new Set;for(const J of Object.values(j))for(const D of J)L.add(D);const U=Object.keys(y).filter(J=>!L.has(J));C={dependencies:j,roots:U,tasks:y}}const{serviceEnvByTaskId:Q}=ee;if(ee.satisfiedServices.length>0){const g=ee.satisfiedServices.map(y=>y.id).join(", ");if(e.debug?.(`Auto-attached to running services: ${g}`),T)for(const y of ee.satisfiedServices)T.registerService(y.id);else T=new ss(ee.satisfiedServices.map(y=>y.id));for(const y of ee.satisfiedServices){const j=y.config.readiness?.tcp?.port??y.config.port??0,L=y.config.readiness?.tcp?.host??"127.0.0.1";T.markReady(y.id,{host:L,port:j})}}if(t.reverse&&(C=dr(C),e.debug?.(`Reversed task graph: ${String(C.roots.length)} new root(s) (originally leaves)`)),t.dryRun){const g=Object.keys(C.tasks).length,y=C.roots.length;e.info(`Execution plan (${String(g)} task(s), ${String(y)} root(s)):`),e.info("");const j=new Set,L=(U,J)=>{if(j.has(U))return;j.add(U);for(const E of C.dependencies[U]??[])L(E,J+1);const D=C.tasks[U],P=" ".repeat(J+1),se=`${D?.cache===!1?" (no-cache)":""}${D?.hashMode==="trace"?" (trace)":""}`;e.info(`${P}${U}${se}`)};for(const U of C.roots)L(U,0);for(const U of Object.keys(C.tasks))L(U,0);H.length>0&&(e.info(""),e.info(` + ${String(H.length)} persistent task(s) (run after graph completes)`)),e.info("");return}const Oe=Date.now(),Se=Yr(),$t=(g,y)=>{const j=y instanceof Error?y.message:String(y);e.warn(`Plugin error in ${g}: ${j}`)};await Jr(Se,f.plugins);const qe=typeof t.profile=="string"?t.profile:void 0,bt=async g=>{if(!qe)return;const y=zt(g,C,Oe),j=qe.startsWith("/")?qe:`${n}/${qe}`;await gr(y,j),e.info(`Profile written to ${qe}`)},Ye=f.taskRunner??{},zs=kr(n,t.cacheDir,Ye.cacheDirectory,f.sharedWorktreeCache),Vs=jr(zs,n,f.branchScopedCache),Be=Ro(process.env.VIS_RUN_CONCURRENCY_LIMIT);Be&&"invalid"in Be&&e.warn(`VIS_RUN_CONCURRENCY_LIMIT=${Be.invalid} is not a positive number; falling back to default concurrency.`);const Ws=Be&&"value"in Be?Be.value:void 0,Ys=t.parallel??Ws??3,St=t.strictEnv??f.strictEnv??!1,Tt=new Set,Pe={dryRun:t.dryRun??!1,parallel:Ys,skipNxCache:!t.cache,summarize:t.summarize??!1,...Ye,cacheDirectory:Vs,dataDirectory:Ye.dataDirectory??Ze(n),namedInputs:f.namedInputs,onDiagnostic:(g,y)=>{Tt.has(g)||(Tt.add(g),e.warn(y))},onFingerprint:async(g,y)=>{await Se.callHook("task:fingerprint",g,y)}},Ct=ur(Ye.remoteCache);if(Ct){const g=Mo(t.cacheMode),y=Fo(t.cacheBackend);if(Pe.remoteCache={...Ct,...g?{mode:g}:{},...y?{backend:y}:{}},Pe.remoteCache.attestation){const{expectedIdentity:j,requireOnDownload:L}=Pe.remoteCache.attestation;if(!(j!==void 0&&("github"in j&&typeof j.github?.ref=="string"&&typeof j.github.repo=="string"&&typeof j.github.workflow=="string"||"oidcIssuer"in j&&typeof j.oidcIssuer=="string"&&(typeof j.san=="string"||typeof j.sanRegex=="string"))))throw new Error("[vis run] remoteCache.attestation requires a pinned keyless signer via `expectedIdentity`. Use one of:\n • { github: { repo, workflow, ref } } (GitHub Actions — recommended)\n • { oidcIssuer, san } (literal identity; vis regex-escapes + anchors it)\n • { oidcIssuer, sanRegex } (advanced: raw regex, you own anchoring)\nWithout it, verification is integrity-only — use `remoteCache.signing` (HMAC) for that instead.");"sanRegex"in j&&(!j.sanRegex.startsWith("^")||!j.sanRegex.endsWith("$"))&&e.warn("[vis run] remoteCache.attestation.expectedIdentity.sanRegex is not anchored (^…$). sigstore matches it as a regex; an unanchored value is substring-matched and weakens the identity pin. Prefer the literal `san` form unless you need a pattern.");const{installCommandFor:U,isSigstoreInstalled:J}=await import("./loader.js");J()||e.warn(`[vis run] remoteCache.attestation is configured but the optional \`sigstore\` package is not installed. Cache uploads will be unsigned and signed entries can't be verified until you install it:
185
- ${U(n)}`);const{buildCacheAttestationHooks:D}=await import("./cache-attestation.js");Pe.remoteCache.attestation=D({expectedIdentity:j,onReject:(P,se)=>{e.warn(`[vis run] remote cache entry ${P.slice(0,12)} rejected: attestation ${se}. Treating as a cache miss.`)},onVerifyFailure:P=>{e.warn(`[vis run] attestation verification failed: ${P}`)},requireOnDownload:L,workspaceRoot:n})}}else(t.cacheMode||t.cacheBackend)&&e.warn("[vis run] --cache-mode and --cache-backend require a `remoteCache` block in vis.config.ts (or TURBO_API env); ignoring.");const Js=process.stdout.isTTY&&!Ve,Ks=o?.run?.quietOnSuccess===!0,Xs=f.tui?.autoExit??(Ks?3:!1),It={args:{parallel:Pe.parallel,targets:[b]},autoExit:Xs,projectNames:F,tasks:[..._,...H],totalTaskCount:Object.keys(C.tasks).length+H.length},Rt=typeof t.retryBudget=="number"?t.retryBudget:void 0,Et=Rt===void 0?void 0:Co(Rt),Mt=new Kr(Se,$t),Ft=new Gr(n),Ot=On(t.outputStyle,o?.run?.quietOnSuccess);if(ee.satisfiedServices.length>0)for(const g of ee.satisfiedServices){const y=ee.serviceDependentsByServiceId.get(g.id)??[];try{await Se.callHook("service:attach",g,y)}catch(j){$t("service:attach",j)}}await Se.callHook("run:before",{tasks:_,workspaceRoot:n});const Ue=t.stopServices===!0;let Pt=!1;const At=()=>{if(Pt)return;Pt=!0,v&&v.dispose().catch(()=>{});const g=Ue?[...ye.values()]:void 0;ko({extraPids:g,pidFiles:Ce,runDir:Ie})},Je=()=>{At()},Dt=Ce.length>0||Ie!==void 0||Ue&&we.length>0;Dt&&(process.on("SIGINT",Je),process.on("SIGTERM",Je));try{if(Js){const g=new Map,y=Mn({...It,onRetryService:v?E=>v.retry(E):void 0,outputStyle:Ot,serviceDockStore:T,stdinRegistry:g}),{lifeCycle:j,store:L}=y,U=new Ut([j,Mt,Ft]),J=ws({affectedFiles:w,currentOs:k,hooks:Se,initCwd:d,lifeCycle:U,mutexPool:new Map,onOutput:(E,N)=>{v&&be.has(E)?v.onTaskOutput(E,N):L.addOutput(E,N)},onOutputReplace:(E,N)=>{L.setOutput(E,N)},retryBudget:Et,serviceEnvByTaskId:Q,serviceEventBridge:v??void 0,stdinRegistry:g,strictEnv:St,workspaceRoot:n});let D="rerun",P=null,se=new Map;for(;D!=="quit";){if(D==="rerun"){if(se=await Ht(_,Pe,{lifeCycle:U,projectGraph:$,taskExecutor:J,taskGraph:C,workspaceRoot:n}),H.length>0&&!t.failFast){const E=new Promise(N=>{const B=L.subscribe(()=>{const Z=L.getSnapshot();(Z.rerunRequested||Z.retryTaskId)&&(B(),N())});y.renderIsDone.then(()=>{B(),N()}).catch(()=>{B(),N()})});await gs(H,n,w,d,{abortSignal:E,lifeCycle:U,stdinRegistry:g,store:L},Q)}}else if(D==="retry"&&P){const E=_.find(B=>B.id===P),N=E?.overrides.command;if(E&&N){const B=nt(n,E.projectRoot,!1);U.startTasks?.([E]);const Z=new ft(it),fe=(await Qe([{command:N,cwd:B,name:E.id,ptySize:{cols:process.stdout.columns??80,rows:process.stdout.rows??24},stdin:"pty"}],{onEvent:ne=>{ne.kind==="started"&&ne.write&&g.set(E.id,{kill:ne.kill,resize:ne.resize,write:ne.write}),(ne.kind==="stdout"||ne.kind==="stderr")&&ne.text&&(Z.write(ne.text),L.setOutput(E.id,Z.toString())),ne.kind==="close"&&g.delete(E.id)}})).closeEvents[0];U.endTasks?.([{code:fe?.exitCode??1,status:fe?.exitCode===0?"success":"failure",task:E,terminalOutput:L.getSnapshot().outputs.get(E.id)}])}else E&&U.endTasks?.([{code:1,status:"failure",task:E,terminalOutput:`No command configured for ${E.id}`}]);P=null,L.markDone()}D=await new Promise(E=>{const N=L.subscribe(()=>{const B=L.getSnapshot();B.rerunRequested&&(L.acknowledgeRerun(),N(),E("rerun")),B.retryTaskId&&(P=L.acknowledgeRetry(),N(),E("retry"))});y.renderIsDone.then(()=>{N(),E("quit")}).catch(()=>{N(),E("quit")})})}await y.renderIsDone,await Se.callHook("run:after",se),await bt(se),le>0&&(e.info(""),Ue?e.info(`${String(le)} service(s) stopped (--stop-services).`):e.info(`${String(le)} service(s) started in the background. Run \`vis service stop --all\` to clean up.`))}else{const g=new Map,y=typeof t.log=="string"?t.log.toLowerCase():"",j=y==="labeled"||y==="grouped"||y==="interleaved"?y:void 0,L=j?hr(j):void 0,U=new Ut([new An({...It,ciGrouping:o?.run?.ciGrouping??"auto",logReporter:L,outputStyle:Ot}),Mt,Ft]),J=ws({affectedFiles:w,currentOs:k,hooks:Se,initCwd:d,lifeCycle:U,mutexPool:g,retryBudget:Et,serviceEnvByTaskId:Q,serviceEventBridge:v??void 0,strictEnv:St,workspaceRoot:n}),D=async()=>{const B=Date.now(),Z=await Ht(_,Pe,{lifeCycle:U,projectGraph:$,taskExecutor:J,taskGraph:C,workspaceRoot:n}),fe=Date.now()-B;if(t.summarize){const xe=zt(Z,C,Oe);await mr(xe,n,{dataDirectory:Ze(n)})}let ne=!1;for(const[,xe]of Z)xe.status==="failure"&&(ne=!0);const ve=Sr(Z,fe),ke=Tr(n),Re=Cr(n,fe,ke);return e.info(""),e.info(` ${ve}${Re?` ${Re}`:""}`),{hasFailure:ne,results:Z,runHistory:ke}},P=await D();await Se.callHook("run:after",P.results),await bt(P.results);const{hasFailure:se}=P;if(t.watch){const B=F.map(de=>{const me=l.projects[de]?.root;if(me)return me.startsWith("/")?me:`${n}/${me}`}).filter(de=>de!==void 0),Z=_;let fe;const ne=de=>{const me=qn(Z,de);return fe=me.filter,_=me.tasks,me.tasks.length};let ve=!1,ke=P.results;const Re=()=>{const de=Kt(ke,n);if(de.directories.length>0&&de.files.size>0){const me=bi(de.files,n,de.directories);return{handle:Xt({filter:me,onChange:Ke,paths:de.directories}),mode:"tracked"}}return{handle:Xt({onChange:Ke,paths:B}),mode:"roots"}};let xe;const Ke=async de=>{if(!ve){ve=!0;try{e.info(`Change detected in ${de.length} file(s), rerunning…`),ke=(await D()).results,xe?.close(),xe=Re().handle}finally{ve=!1}}},Lt=Re();xe=Lt.handle;const Qs=Lt.mode==="tracked"?`Watching ${String(Kt(ke,n).files.size)} tracked file(s)`:`Watching ${String(B.length)} project root(s)`;e.info(`${Qs} — edit a file to rerun, press h for keybinds, q to quit.`);const ct=async()=>{if(!ve){ve=!0;try{if(_.length===0){e.info("No tasks match the active filter — press a to clear it.");return}ke=(await D()).results,xe?.close(),xe=Re().handle}finally{ve=!1}}};await new Promise(de=>{let me=!1,Bt;const Nt=()=>{Gt()},Gt=()=>{me||(me=!0,Bt?.close(),process.off("SIGINT",Nt),xe?.close(),de())};process.on("SIGINT",Nt),Bt=Vn({handlers:{onClearFilter:async()=>{const He=ne(void 0);e.info(`Filter cleared — running ${String(He)} task(s).`),await ct()},onFilter:async He=>{const Zs=fe,_t=ne(He);if(_t===0){e.info(`Filter "${He}" matched no projects — keeping previous filter.`),ne(Zs);return}e.info(`Filter "${He}" matched ${String(_t)} task(s).`),await ct()},onHelp:()=>{Hn(process.stdout)},onQuit:()=>{Gt()},onRerun:ct}})});return}if(t.flaky!==!1){const B=$r(n,{minRuns:2},P.runHistory);if(B.length>0){e.info(""),e.info("Flaky tasks (based on historical runs):"),e.info("");for(const Z of br(B))e.info(` ${Z}`);e.info("")}}const E=[];for(const[B,Z]of P.results)Z.retryAttempts&&Z.retryAttempts>0&&E.push(B);const N=t.failOnRetry===!0&&E.length>0;if(N){const B=E.slice(0,5),Z=E.length-B.length,fe=Z>0?`${B.join(", ")}, and ${String(Z)} more`:B.join(", ");e.warn(""),e.warn(`--fail-on-retry: ${String(E.length)} task(s) succeeded only after retry: ${fe}`)}if(se||N){const B=N&&!se?"Some tasks succeeded only after retry (--fail-on-retry).":"Some tasks failed.",Z=2e3,fe=[];for(const[ne,ve]of P.results){if(ve.status!=="failure")continue;const ke=ve.terminalOutput??"",Re=ke.length>Z?`…${ke.slice(-Z)}`:ke,xe=ve.code??"?";fe.push(` ${ne} (exit ${String(xe)}):
183
+ `}:{code:de?.exitCode??1,retryAttempts:Z,terminalOutput:ye}};return f?_o(f,S?.mutex,je):je()}},Uo=s=>{if(!s||s.trim().length===0)return;const e=Number.parseFloat(s);return!Number.isFinite(e)||e<=0?{invalid:s}:{value:Math.floor(e)}},Vo=async(s,e)=>{const t=await vr(s,{dataDirectory:Ze(s)});if(!t){e.warn(`No previous run recorded yet. Run a task at least once to populate ${kr(s,{dataDirectory:Ze(s)})}.`);return}const r=(t.duration/1e3).toFixed(2);if(e.info(""),e.info(`Last run — ${t.startTime} (${r}s)`),e.info(""),e.info(` Total: ${String(t.stats.total)}`),e.info(` Succeeded: ${String(t.stats.succeeded)}`),e.info(` Cached: ${String(t.stats.cached)}`),e.info(` Failed: ${String(t.stats.failed)}`),e.info(` Skipped: ${String(t.stats.skipped)}`),e.info(""),t.stats.failed>0){const a=t.tasks.filter(i=>i.exitCode!==void 0&&i.exitCode!==0);e.info("Failed tasks:");for(const i of a){const d=i.duration??0;e.info(` × ${i.taskId} (exit ${String(i.exitCode??-1)}, ${d}ms)`)}e.info("")}const o=[...t.tasks].filter(a=>typeof a.duration=="number").sort((a,i)=>(i.duration??0)-(a.duration??0)).slice(0,5);if(o.length>0){e.info("Slowest tasks:");for(const a of o)e.info(` ${a.taskId.padEnd(40)} ${String(a.duration??0).padStart(6)}ms [${a.cacheStatus}]`);e.info("")}},Ho=s=>{if(!(s===void 0||s==="")){if(s!=="read"&&s!=="write"&&s!=="readwrite")throw new Error(`--cache-mode must be one of: read, write, readwrite (received "${s}")`);return s}},zo=s=>{if(!(s===void 0||s==="")){if(s!=="http"&&s!=="reapi")throw new Error(`--cache-backend must be one of: http, reapi (received "${s}")`);return s}},Yo=s=>{if(!(s===void 0||s==="")){if(s!=="declared"&&s!=="trace")throw new Error(`--hash-mode must be one of: declared, trace (received "${s}")`);return s}},wa=async({argument:s,logger:e,options:t,runtime:r,visConfig:o,workspaceRoot:a})=>{if(!a)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const i=a;if(zr({logger:e,options:t,visConfig:o},i),fi(i),t.lastDetails===!0){await Vo(i,e);return}const d=process.cwd(),u=await Ar(i),{config:f,packageJsons:h,projectOptions:p,workspace:l}=Dr(i,o,u),$=Lr(i,l,h);let R=s[0];if(!R){const g=ns(l);if(process.stdout.isTTY&&process.stdin.isTTY){const y=await cn(g);if(!y){e.info("No target selected.");return}R=y,await qn(`vis run ${y}`)}else{e.info("Available targets:"),e.info(""),e.info(an(g)),e.info(""),e.info("Usage: vis run <target>");return}}if(f.constraints&&!t.skipConstraints){const g=hr($,f.constraints);if(g.length>0){for(const y of g)e.error(`[${y.rule}] ${y.message}`);throw new Error(`${g.length} project constraint violation(s) found. Use --skip-constraints to bypass.`)}}if(t.affected){const g=[R];t.parallel!==void 0&&g.push(`--parallel=${String(t.parallel)}`),t.cache||g.push("--no-cache"),t.query&&g.push(`--query=${String(t.query)}`),t.reverse&&g.push("--reverse"),typeof t.runnerTags=="string"&&t.runnerTags!==""&&g.push(`--runner-tags=${t.runnerTags}`),await r.runCommand("affected",{argv:g});return}const G=await oi(R,l,process.cwd(),i),V=sn(p),j=rn(G.target,V);j!==G.target&&e.debug?.(`Resolved alias "${G.target}" → "${j}"`);let I=G.projects;const S=s.slice(1).map(String);if(t.projects){const g=new Set(t.projects.split(",").map(y=>y.trim()));if(I=I.filter(y=>g.has(y)),I.length===0)throw new Error(`No matching projects found for: ${String(t.projects)}`)}if(t.filter&&t.filter.length>0){const g=new Map;for(const[P,q]of h)g.set(P,q.name);const y=await lo(t.filter,{defaultBase:o?.defaultBase,packageNameByProject:g,projectGraph:$,workspaceRoot:i}),k=new Set(y);if(I=I.filter(P=>k.has(P)),I.length===0){e.info(`Filter ${t.filter.map(P=>`"${P}"`).join(", ")} matched no projects.`);return}}if(t.query&&(I=ai(I,l,t.query),I.length===0)){e.info(`Query "${String(t.query)}" matched no projects.`);return}const x=ci(),O=process.env[$t],w=O?O.split(`
184
+ `).filter(Boolean):void 0,A=(typeof t.runnerTags=="string"?t.runnerTags:process.env.VIS_RUNNER_TAGS)??void 0,b=A?new Set(A.split(",").map(g=>g.trim()).filter(Boolean)):void 0,M=[],H=new Map;for(const g of I){const y=p.get(g)?.[j];if(!y)continue;const k=y.options;if(!k?.internal){if(!li(k,!!He)){e.debug?.(`Skipping ${g}:${j} — runInCI filter`);continue}if(!di(k,b)){e.debug?.(`Skipping ${g}:${j} — runner-tags filter`);continue}M.push(g),H.set(g,y)}}if(M.length===0){const g=ns(l),y=Object.entries(l.projects).filter(([,k])=>k.targets?.[j]!==void 0).map(([k])=>k);if(e.error(`No projects have the "${j}" target.`),y.length>0){e.info(""),e.info(`Target "${j}" exists in these projects but was filtered out:`);for(const k of y.slice(0,5))e.info(` - ${k}`);y.length>5&&e.info(` …and ${y.length-5} more`)}else{const k=Ds(j,g,3);k.length>0&&(e.info(""),e.info(k.length===1?`Did you mean "${k[0]}"?`:`Did you mean one of: ${k.map(P=>`"${P}"`).join(", ")}?`)),e.info(""),e.info("Run `vis run` without arguments to see all available targets.")}return}const te=t.pty===!0,fe=M.map(g=>({project:g,schema:H.get(g)?.arguments})).filter(g=>Array.isArray(g.schema)&&g.schema.length>0),W=new Map;for(const{project:g,schema:y}of fe){const k=JSON.stringify(y),P=W.get(k)??[];P.push(g),W.set(k,P)}if(W.size>1){const g=[...W.values()].map(y=>y.join(", ")).join(" | ");throw new Error(`Target "${j}" declares conflicting \`arguments\` schemas across projects (${g}). Run a single project (e.g. \`vis run ${fe[0]?.project}:${j}\` or --projects=<name>) so the argument contract is unambiguous.`)}const Y=fe[0]?.schema,ce=H.get(fe[0]?.project??M[0])?.description,re=Oo(j,ce,Y,S);if(re.kind==="help"){e.info(re.text);return}if(re.kind==="invalid"){e.info(`Invalid arguments for "${j}":`);for(const g of re.errors)e.info(` ✖ ${g}`);throw e.info(""),e.info(re.help),new Error(`Invalid arguments for target "${j}"`)}const ae=re.env,ne=Yo(t.hashMode);let U=M.map(g=>{const y=l.projects[g],k=H.get(g),P={project:g,target:j},q=`${g}:${j}`,J=te?{...k.options,pty:k.options?.pty??!0}:k.options,L=k.command?Ht(k.command,{affectedFiles:w,projectRoot:y?.root}):k.command,D=y?.root&&y.root.length>0?y.root:".",se=(k.outputs??[]).map(F=>typeof F!="string"?F:F.replaceAll("{projectRoot}",D).replaceAll("{projectName}",g));return{cache:k.cache,hashMode:ne??k.hashMode,id:q,outputs:se,overrides:{command:L,...S.length>0?{[Ys]:S}:{},...Object.keys(ae).length>0?{[St]:ae}:{},...J?{visOptions:J}:{}},parallelism:k.parallelism,projectRoot:y?.root,target:P}});const _=[],X=[];for(const g of U)zs(g)?.persistent?(g.cache=!1,_.push(g)):X.push(g);U=X;const pe=fr(t.partition);if(pe&&(U=pr.partitionTasks(U,pe),e.info(`Partition ${pe.index}/${pe.total}: running ${U.length} task(s)`),U.length===0)){e.info("No tasks assigned to this partition.");return}const je=new Set([...U,..._].map(g=>g.id));let E=gr([...U,..._],{onCycleBroken:g=>{e.warn(`Ignoring dev-only dependency cycle (build order is ambiguous): ${g.join(" → ")}`)},projectGraph:$,targetDefaults:f.tasks,workspace:l});for(const[g,y]of Object.entries(E.tasks)){const k=y.target.project,P=y.target.target,q=p.get(k)?.[P];if(!q){je.has(g)||e.warn(`${P} required via dependsOn but no command is configured for ${k} — skipping (no-op).`);continue}const J=l.projects[k];let L=!1;const D={...y.overrides};D.visOptions===void 0&&q.options&&(D.visOptions=q.options,L=!0),D.command===void 0&&q.command&&(D.command=Ht(q.command,{affectedFiles:w,projectRoot:J?.root}),L=!0),L&&(y.overrides=D,E.tasks[g]=y)}if(typeof t.skipCache=="string"&&t.skipCache.trim()!=="")if(t.cache){const g=Ki(t.skipCache,l,Object.keys(E.tasks));for(const y of g.skipTaskIds){const k=E.tasks[y];k!==void 0&&(k.cache=!1)}g.unmatchedPatterns.length>0&&e.warn(`--skip-cache: no tasks matched ${g.unmatchedPatterns.map(y=>`"${y}"`).join(", ")}`),g.skipTaskIds.size>0&&e.debug?.(`--skip-cache: bypassing cache for ${String(g.skipTaskIds.size)} task(s)`)}else e.debug?.("--skip-cache ignored: --no-cache already disables caching for the whole run");await Yr(i,f.toolchain,{error:g=>{e.error(g)},info:g=>{e.info(g)},warn:g=>{e.warn(g)}},!!t.skipToolchain);const ge=t.preflight!==!1&&f.preflight?.lockfile!==!1,Ie=Nr(i,He,{warn:g=>{e.warn(g)}},{skip:!ge});if(!Ie.shouldContinue)throw new Error(`${Ie.formattedMessage??"preflight: lockfile drift detected"} (pass --no-preflight to bypass)`);ge&&!He&&process.stdin.isTTY&&process.stdout.isTTY&&await zi(i,{logger:{info:g=>{e.info(g)},warn:g=>{e.warn(g)}},projectManifests:[...h.values()]});const Me=process.env.VIS_VERSION??"0.0.0",Le=t.dryRun?void 0:async g=>{try{return await ii(g.config,{timeoutMs:Po}),!0}catch{return!1}},Fe=await Zr(i),Z=await eo({initialTasks:[...U,..._],probe:Le,registeredEntries:Fe,taskGraph:E,visVersion:Me}),Oe=[];let we,de=0;const ye=[],ve=new Map;let Se=[];const T=new Set;let v=null,C=null;if(Z.diagnostics.length>0){const g=!!(process.stdout.isTTY&&process.stdin.isTTY),y=t.dryRun?"off":So({cli:t.services,config:f.run?.services,isCi:!!He,isPersistentTarget:_.length>0,isTty:g,target:j});if(y==="off"){for(const D of Z.diagnostics)e.error(D.message);throw new Error(`${Z.diagnostics.length} service dependency error(s) — start the missing services or invoke them directly.`)}const k=Z.diagnostics.map(D=>D.targetId),P=y,q=P==="registry"?Us(i,k,E):void 0,J=process.argv[1]??"vis",L=$o({missingServiceIds:k,mode:P,taskGraph:E,visBin:J,workspaceRoot:i});if(L.skipped.length>0){for(const{id:D,reason:se}of L.skipped)e.error(`Cannot auto-start ${D}: ${se}`);throw new Error(`${L.skipped.length} service(s) cannot be auto-started — invoke them directly or add a service config.`)}Oe.push(...L.ephemeralPidFiles),we=L.runDir,Se=L.chain;for(const D of L.chain)T.add(D);if(P==="registry"&&(de=L.chain.length,ye.push(...L.chain)),L.chain.length>0){const D=new os(L.chain),se=new Map;if(P==="ephemeral"&&L.runDir)for(const F of L.chain){const N=Vs(L.runDir,`${L.runDir}/bootstrap.mjs`,F);se.set(F,{ephemeral:{configFile:N.configFile,cwd:i,logFile:N.logFile,pidFile:N.pidFile,scriptPath:N.scriptPath},mode:"ephemeral"})}else if(P==="registry"&&q)for(const F of q.services)se.set(F.id,{mode:"registry",registry:{command:F.command,config:F.config,cwd:F.cwd,env:F.env}});if(se.size>0){const F=new po({indexToId:new Map,services:se,sink:{crashed:(N,B)=>{D.markCrashed(N,B)},failed:(N,B,Q)=>{D.markFailed(N,B,Q)},log:(N,B)=>{D.appendLog(N,B)},ready:(N,B)=>{D.markReady(N,B)},started:(N,B)=>{D.markStarted(N,B),P==="registry"&&B!==null&&ve.set(N,B)},starting:N=>{D.markStarting(N)}},workspaceRoot:i});v=D,C=F}}for(const[D,se]of L.serviceEnvByTaskId){const F=Z.serviceEnvByTaskId.get(D)??{};Z.serviceEnvByTaskId.set(D,{...F,...se})}}const ee=new Set(_.map(g=>g.id));if(U=Z.initialTasks.filter(g=>!ee.has(g.id)),E=Z.taskGraph,Se.length>0&&(U=[...Se.map(g=>E.tasks[g]).filter(g=>g!==void 0),...U]),_.length>0){const g=new Set(_.map(J=>J.id)),y={};for(const[J,L]of Object.entries(E.tasks))g.has(J)||(y[J]=L);const k={};for(const[J,L]of Object.entries(E.dependencies))g.has(J)||(k[J]=L.filter(D=>!g.has(D)));const P=new Set;for(const J of Object.values(k))for(const L of J)P.add(L);const q=Object.keys(y).filter(J=>!P.has(J));E={dependencies:k,roots:q,tasks:y}}const{serviceEnvByTaskId:Te}=Z;if(Z.satisfiedServices.length>0){const g=Z.satisfiedServices.map(y=>y.id).join(", ");if(e.debug?.(`Auto-attached to running services: ${g}`),v)for(const y of Z.satisfiedServices)v.registerService(y.id);else v=new os(Z.satisfiedServices.map(y=>y.id));for(const y of Z.satisfiedServices){const k=y.config.readiness?.tcp?.port??y.config.port??0,P=y.config.readiness?.tcp?.host??"127.0.0.1";v.markReady(y.id,{host:P,port:k})}}if(t.reverse&&(E=mr(E),e.debug?.(`Reversed task graph: ${String(E.roots.length)} new root(s) (originally leaves)`)),t.dryRun){const g=Object.keys(E.tasks).length,y=E.roots.length;e.info(`Execution plan (${String(g)} task(s), ${String(y)} root(s)):`),e.info("");const k=new Set,P=(q,J)=>{if(k.has(q))return;k.add(q);for(const F of E.dependencies[q]??[])P(F,J+1);const L=E.tasks[q],D=" ".repeat(J+1),se=`${L?.cache===!1?" (no-cache)":""}${L?.hashMode==="trace"?" (trace)":""}`;e.info(`${D}${q}${se}`)};for(const q of E.roots)P(q,0);for(const q of Object.keys(E.tasks))P(q,0);_.length>0&&(e.info(""),e.info(` + ${String(_.length)} persistent task(s) (run after graph completes)`)),e.info("");return}const Tt=Date.now(),Ce=ei(),Ct=(g,y)=>{const k=y instanceof Error?y.message:String(y);e.warn(`Plugin error in ${g}: ${k}`)};await ti(Ce,f.plugins);const qe=typeof t.profile=="string"?t.profile:void 0,It=async g=>{if(!qe)return;const y=Jt(g,E,Tt),k=qe.startsWith("/")?qe:`${i}/${qe}`;await xr(y,k),e.info(`Profile written to ${qe}`)},Ye=f.taskRunner??{},Js=Cr(i,t.cacheDir,Ye.cacheDirectory,f.sharedWorktreeCache),Ks=Ir(Js,i,f.branchScopedCache),Be=Uo(process.env.VIS_RUN_CONCURRENCY_LIMIT);Be&&"invalid"in Be&&e.warn(`VIS_RUN_CONCURRENCY_LIMIT=${Be.invalid} is not a positive number; falling back to default concurrency.`);const Xs=Be&&"value"in Be?Be.value:void 0,ct=t.parallel??Xs??3,Rt=t.strictEnv??f.strictEnv??!1,Et=new Set,Pe={dryRun:t.dryRun??!1,parallel:ct,skipNxCache:!t.cache,summarize:t.summarize??!1,...Ye,cacheDirectory:Ks,dataDirectory:Ye.dataDirectory??Ze(i),namedInputs:f.namedInputs,onDiagnostic:(g,y)=>{Et.has(g)||(Et.add(g),e.warn(y))},onFingerprint:async(g,y)=>{await Ce.callHook("task:fingerprint",g,y)}},Mt=wr(Ye.remoteCache);if(Mt){const g=Ho(t.cacheMode),y=zo(t.cacheBackend);if(Pe.remoteCache={...Mt,...g?{mode:g}:{},...y?{backend:y}:{}},Pe.remoteCache.attestation){const{expectedIdentity:k,requireOnDownload:P}=Pe.remoteCache.attestation;if(!(k!==void 0&&("github"in k&&typeof k.github?.ref=="string"&&typeof k.github.repo=="string"&&typeof k.github.workflow=="string"||"oidcIssuer"in k&&typeof k.oidcIssuer=="string"&&(typeof k.san=="string"||typeof k.sanRegex=="string"))))throw new Error("[vis run] remoteCache.attestation requires a pinned keyless signer via `expectedIdentity`. Use one of:\n • { github: { repo, workflow, ref } } (GitHub Actions — recommended)\n • { oidcIssuer, san } (literal identity; vis regex-escapes + anchors it)\n • { oidcIssuer, sanRegex } (advanced: raw regex, you own anchoring)\nWithout it, verification is integrity-only — use `remoteCache.signing` (HMAC) for that instead.");"sanRegex"in k&&(!k.sanRegex.startsWith("^")||!k.sanRegex.endsWith("$"))&&e.warn("[vis run] remoteCache.attestation.expectedIdentity.sanRegex is not anchored (^…$). sigstore matches it as a regex; an unanchored value is substring-matched and weakens the identity pin. Prefer the literal `san` form unless you need a pattern.");const{installCommandFor:q,isSigstoreInstalled:J}=await import("./loader.js");J()||e.warn(`[vis run] remoteCache.attestation is configured but the optional \`sigstore\` package is not installed. Cache uploads will be unsigned and signed entries can't be verified until you install it:
185
+ ${q(i)}`);const{buildCacheAttestationHooks:L}=await import("./cache-attestation.js");Pe.remoteCache.attestation=L({expectedIdentity:k,onReject:(D,se)=>{e.warn(`[vis run] remote cache entry ${D.slice(0,12)} rejected: attestation ${se}. Treating as a cache miss.`)},onVerifyFailure:D=>{e.warn(`[vis run] attestation verification failed: ${D}`)},requireOnDownload:P,workspaceRoot:i})}}else(t.cacheMode||t.cacheBackend)&&e.warn("[vis run] --cache-mode and --cache-backend require a `remoteCache` block in vis.config.ts (or TURBO_API env); ignoring.");const Qs=process.stdout.isTTY&&!He,Zs=o?.run?.quietOnSuccess===!0,er=f.tui?.autoExit??(Zs?3:!1),Ft={args:{parallel:Pe.parallel,targets:[j]},autoExit:er,projectNames:M,tasks:[...U,..._],totalTaskCount:Object.keys(E.tasks).length+_.length},Ot=typeof t.retryBudget=="number"?t.retryBudget:void 0,Pt=Ot===void 0?void 0:qo(Ot),At=new si(Ce,Ct),Dt=new Hr(i),Lt=Nn(t.outputStyle,o?.run?.quietOnSuccess);if(Z.satisfiedServices.length>0)for(const g of Z.satisfiedServices){const y=Z.serviceDependentsByServiceId.get(g.id)??[];try{await Ce.callHook("service:attach",g,y)}catch(k){Ct("service:attach",k)}}await Ce.callHook("run:before",{tasks:U,workspaceRoot:i});const We=t.stopServices===!0;let Bt=!1;const Nt=()=>{if(Bt)return;Bt=!0,C&&C.dispose().catch(()=>{});const g=We?[...ve.values()]:void 0;Do({extraPids:g,pidFiles:Oe,runDir:we})},Je=()=>{Nt()},Gt=Oe.length>0||we!==void 0||We&&ye.length>0;Gt&&(process.on("SIGINT",Je),process.on("SIGTERM",Je));try{if(Qs){const g=new Map,y=Ln({...Ft,onRetryService:C?F=>C.retry(F):void 0,outputStyle:Lt,serviceDockStore:v,stdinRegistry:g}),{lifeCycle:k,store:P}=y,q=new zt([k,At,Dt]),J=xs({affectedFiles:w,currentOs:x,hooks:Ce,initCwd:d,lifeCycle:q,mutexPool:new Map,onOutput:(F,N)=>{C&&T.has(F)?C.onTaskOutput(F,N):P.addOutput(F,N)},onOutputReplace:(F,N)=>{P.setOutput(F,N)},retryBudget:Pt,serviceEnvByTaskId:Te,serviceEventBridge:C??void 0,stdinRegistry:g,strictEnv:Rt,taskSlots:ct,workspaceRoot:i});let L="rerun",D=null,se=new Map;for(;L!=="quit";){if(L==="rerun"){if(se=await Yt(U,Pe,{lifeCycle:q,projectGraph:$,taskExecutor:J,taskGraph:E,workspaceRoot:i}),_.length>0&&!t.failFast){const F=new Promise(N=>{const B=P.subscribe(()=>{const Q=P.getSnapshot();(Q.rerunRequested||Q.retryTaskId)&&(B(),N())});y.renderIsDone.then(()=>{B(),N()}).catch(()=>{B(),N()})});await vs(_,i,w,d,{abortSignal:F,lifeCycle:q,stdinRegistry:g,store:P},Te)}}else if(L==="retry"&&D){const F=U.find(B=>B.id===D),N=F?.overrides.command;if(F&&N){const B=nt(i,F.projectRoot,!1);q.startTasks?.([F]);const Q=new mt(it),ue=(await Qe([{command:N,cwd:B,name:F.id,ptySize:{cols:process.stdout.columns??80,rows:process.stdout.rows??24},stdin:"pty"}],{onEvent:ie=>{ie.kind==="started"&&ie.write&&g.set(F.id,{kill:ie.kill,resize:ie.resize,write:ie.write}),(ie.kind==="stdout"||ie.kind==="stderr")&&ie.text&&(Q.write(ie.text),P.setOutput(F.id,Q.toString())),ie.kind==="close"&&g.delete(F.id)}})).closeEvents[0];q.endTasks?.([{code:ue?.exitCode??1,status:ue?.exitCode===0?"success":"failure",task:F,terminalOutput:P.getSnapshot().outputs.get(F.id)}])}else F&&q.endTasks?.([{code:1,status:"failure",task:F,terminalOutput:`No command configured for ${F.id}`}]);D=null,P.markDone()}L=await new Promise(F=>{const N=P.subscribe(()=>{const B=P.getSnapshot();B.rerunRequested&&(P.acknowledgeRerun(),N(),F("rerun")),B.retryTaskId&&(D=P.acknowledgeRetry(),N(),F("retry"))});y.renderIsDone.then(()=>{N(),F("quit")}).catch(()=>{N(),F("quit")})})}await y.renderIsDone,await Ce.callHook("run:after",se),await It(se),de>0&&(e.info(""),We?e.info(`${String(de)} service(s) stopped (--stop-services).`):e.info(`${String(de)} service(s) started in the background. Run \`vis service stop --all\` to clean up.`))}else{const g=new Map,y=typeof t.log=="string"?t.log.toLowerCase():"",k=y==="labeled"||y==="grouped"||y==="interleaved"?y:void 0,P=k?yr(k):void 0,q=new zt([new _n({...Ft,ciGrouping:o?.run?.ciGrouping??"auto",logReporter:P,outputStyle:Lt}),At,Dt]),J=xs({affectedFiles:w,currentOs:x,hooks:Ce,initCwd:d,lifeCycle:q,mutexPool:g,retryBudget:Pt,serviceEnvByTaskId:Te,serviceEventBridge:C??void 0,strictEnv:Rt,taskSlots:ct,workspaceRoot:i}),L=async()=>{const B=Date.now(),Q=await Yt(U,Pe,{lifeCycle:q,projectGraph:$,taskExecutor:J,taskGraph:E,workspaceRoot:i}),ue=Date.now()-B;if(t.summarize){const xe=Jt(Q,E,Tt);await jr(xe,i,{dataDirectory:Ze(i)})}let ie=!1;for(const[,xe]of Q)xe.status==="failure"&&(ie=!0);const ke=Mr(Q,ue),$e=Fr(i),Re=Or(i,ue,$e);return e.info(""),e.info(` ${ke}${Re?` ${Re}`:""}`),{hasFailure:ie,results:Q,runHistory:$e}},D=await L();await Ce.callHook("run:after",D.results),await It(D.results);const{hasFailure:se}=D;if(t.watch){const B=M.map(le=>{const me=l.projects[le]?.root;if(me)return me.startsWith("/")?me:`${i}/${me}`}).filter(le=>le!==void 0),Q=U;let ue;const ie=le=>{const me=Yn(Q,le);return ue=me.filter,U=me.tasks,me.tasks.length};let ke=!1,$e=D.results;const Re=()=>{const le=es($e,i);if(le.directories.length>0&&le.files.size>0){const me=Ei(le.files,i,le.directories);return{handle:ts({filter:me,onChange:Ke,paths:le.directories}),mode:"tracked"}}return{handle:ts({onChange:Ke,paths:B}),mode:"roots"}};let xe;const Ke=async le=>{if(!ke){ke=!0;try{e.info(`Change detected in ${le.length} file(s), rerunning…`),$e=(await L()).results,xe?.close(),xe=Re().handle}finally{ke=!1}}},_t=Re();xe=_t.handle;const tr=_t.mode==="tracked"?`Watching ${String(es($e,i).files.size)} tracked file(s)`:`Watching ${String(B.length)} project root(s)`;e.info(`${tr} — edit a file to rerun, press h for keybinds, q to quit.`);const lt=async()=>{if(!ke){ke=!0;try{if(U.length===0){e.info("No tasks match the active filter — press a to clear it.");return}$e=(await L()).results,xe?.close(),xe=Re().handle}finally{ke=!1}}};await new Promise(le=>{let me=!1,qt;const Wt=()=>{Ut()},Ut=()=>{me||(me=!0,qt?.close(),process.off("SIGINT",Wt),xe?.close(),le())};process.on("SIGINT",Wt),qt=Qn({handlers:{onClearFilter:async()=>{const Ue=ie(void 0);e.info(`Filter cleared — running ${String(Ue)} task(s).`),await lt()},onFilter:async Ue=>{const sr=ue,Vt=ie(Ue);if(Vt===0){e.info(`Filter "${Ue}" matched no projects — keeping previous filter.`),ie(sr);return}e.info(`Filter "${Ue}" matched ${String(Vt)} task(s).`),await lt()},onHelp:()=>{Kn(process.stdout)},onQuit:()=>{Ut()},onRerun:lt}})});return}if(t.flaky!==!1){const B=Rr(i,{minRuns:2},D.runHistory);if(B.length>0){e.info(""),e.info("Flaky tasks (based on historical runs):"),e.info("");for(const Q of Er(B))e.info(` ${Q}`);e.info("")}}const F=[];for(const[B,Q]of D.results)Q.retryAttempts&&Q.retryAttempts>0&&F.push(B);const N=t.failOnRetry===!0&&F.length>0;if(N){const B=F.slice(0,5),Q=F.length-B.length,ue=Q>0?`${B.join(", ")}, and ${String(Q)} more`:B.join(", ");e.warn(""),e.warn(`--fail-on-retry: ${String(F.length)} task(s) succeeded only after retry: ${ue}`)}if(se||N){const B=N&&!se?"Some tasks succeeded only after retry (--fail-on-retry).":"Some tasks failed.",Q=2e3,ue=[];for(const[ie,ke]of D.results){if(ke.status!=="failure")continue;const $e=ke.terminalOutput??"",Re=$e.length>Q?`…${$e.slice(-Q)}`:$e,xe=ke.code??"?";ue.push(` ${ie} (exit ${String(xe)}):
186
186
  ${Re.split(`
187
187
  `).map(Ke=>` ${Ke}`).join(`
188
- `)}`)}throw new Error(fe.length>0?`${B}
189
- ${fe.join(`
190
- `)}`:B)}H.length>0&&!t.failFast&&await gs(H,n,w,d,void 0,Q),le>0&&(e.info(""),Ue?e.info(`${String(le)} service(s) stopped (--stop-services).`):e.info(`${String(le)} service(s) started in the background. Run \`vis service stop --all\` to clean up.`))}}finally{At(),Dt&&(process.off("SIGINT",Je),process.off("SIGTERM",Je)),Ue&&we.length>0&&await Promise.all(we.map(async g=>{try{await Xr(n,g)}catch{}}))}};export{Co as createRetryBudget,sa as default};
188
+ `)}`)}throw new Error(ue.length>0?`${B}
189
+ ${ue.join(`
190
+ `)}`:B)}_.length>0&&!t.failFast&&await vs(_,i,w,d,void 0,Te),de>0&&(e.info(""),We?e.info(`${String(de)} service(s) stopped (--stop-services).`):e.info(`${String(de)} service(s) started in the background. Run \`vis service stop --all\` to clean up.`))}}finally{Nt(),Gt&&(process.off("SIGINT",Je),process.off("SIGTERM",Je)),We&&ye.length>0&&await Promise.all(ye.map(async g=>{try{await ri(i,g)}catch{}}))}};export{qo as createRetryBudget,wa as default};