@stacksjs/cli 0.75.308 → 0.75.310

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.
package/README.md CHANGED
@@ -44,6 +44,21 @@ or failure, including descendants holding inherited pipes. On Windows cleanup
44
44
  covers the direct process and readers. Use this API for finite inspection or build
45
45
  probes whose descendants should end with the command.
46
46
 
47
+ ### Request cancellation
48
+
49
+ Pass a native `AbortSignal` as `signal`, for example an HTTP request's
50
+ `request.signal`. An already-aborted signal rejects before launching a process.
51
+ Later cancellation terminates the owned process scope and waits for the child
52
+ and readers to settle before rejecting with `Error('<label> canceled')`.
53
+ The signal's reason is retained as `cause` without converting it to text.
54
+
55
+ The first observed failure wins when cancellation overlaps an output or deadline
56
+ failure. Listeners are removed after settlement, so later cancellation cannot
57
+ change a completed capture. Nonzero exits still return the original result
58
+ shape. Cancellation keeps the same POSIX process-group and Windows direct-child
59
+ cleanup scope described above; it does not contain a descendant that deliberately
60
+ escapes that group.
61
+
47
62
  ## 🤖 Usage
48
63
 
49
64
  ```bash
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // @bun
2
- import We from"process";async function Ye(e,t={silent:!0}){let n=t.packageManager??"bun",r=[n==="npm"?"install":"add"];if(t.dev)r.push("-D");if(t.preferOffline&&n!=="bun")r.push("--prefer-offline");if(t.additionalArgs)r.push(...t.additionalArgs);r.push(e);let i=await Bun.spawn([n,...r],{cwd:t.cwd??We.cwd(),stdout:t.silent?"ignore":"inherit",stderr:t.silent?"ignore":"inherit",stdin:"ignore",env:We.env}).exited;if(i!==0)throw Error(`Failed to install ${e} (exit code ${i})`)}async function er(e,t){return Ye(e,t??{silent:!0})}async function tr(e,t){return Ye(`@stacksjs/${e}`,t??{silent:!0})}import{CLI as or,cli as gt,onUnknownSubcommand as ir}from"@stacksjs/clapp";function sr(e,t){if(typeof e==="object")t=e,e=t.name;return gt(e||"buddy")}import{existsSync as ne,readdirSync as dt}from"fs";import{join as Ne}from"path";var mt=/(?:\.test|\.spec|\.bench|\.d)\.ts$/;function ft(e){return e.endsWith(".ts")&&!mt.test(e)&&!e.startsWith("_")}function pt(e){if(!ne(e))return[];let t=[],n=(r,o)=>{for(let i of dt(r,{withFileTypes:!0})){if(i.name.startsWith(".")||i.name==="node_modules")continue;if(i.isDirectory()){n(Ne(r,i.name),`${o}${i.name}/`);continue}if(ft(i.name))t.push(`${o}${i.name.slice(0,-3)}`)}};return n(e,""),t.sort()}async function De(e){if(!e||!ne(e))return{};try{let n=(await import(e)).default;if(!n||typeof n!=="object")return{error:Error(`${e} must default-export a command registry object.`)};return{registry:n}}catch(t){return{error:t}}}async function ht(e){let{commandsDir:t}=e,n=e.registry??(await De(e.registryPath)).registry,r=pt(t),o=new Map;for(let l of r)o.set(l,{file:l,path:Ne(t,`${l}.ts`),aliases:[],enabled:!0,source:"auto"});let i=[];for(let[l,s]of Object.entries(n??{})){let a=typeof s==="string"?{file:s}:s,c=o.get(a.file);if(!c)continue;if(c.signature=l,c.aliases=a.aliases??[],c.enabled=a.enabled!==!1,c.source="registry",!i.includes(c))i.push(c)}for(let l of r){let s=o.get(l);if(s&&!i.includes(s))i.push(s)}return i}function bt(e,t,n){let r=t.trim().split(/\s+/)[0],i=e?.commands?.find((l)=>l.name===r);if(!i||typeof i.alias!=="function")return!1;for(let l of n)i.alias(l);return!0}async function ur(e,t){let n=t.onError??(()=>{}),r=t.onDebug??(()=>{});if(!ne(t.commandsDir))return r(`No ${t.commandsDir} directory, skipping application commands.`),[];let o=t.registry?{registry:t.registry}:await De(t.registryPath);if(o.error)n(`Could not read the command registry at ${t.registryPath}`,o.error);let i=await ht({...t,registry:o.registry}),l=[];for(let s of i){if(!s.enabled){r(`Skipping disabled command ${s.file}.`);continue}try{let a=await import(s.path);if(a.enabled===!1){r(`Skipping ${s.file}: the module exports \`enabled = false\`.`);continue}if(typeof a.default!=="function"){n(`Expected a default export function in ${s.file}.ts, but got: ${typeof a.default}`);continue}let c=e.commands?.length??0;a.default(e);let m=[...s.aliases,...a.aliases??[]];if(m.length)yt(e,s.signature,c,m,r);l.push(s)}catch(a){n(`Failed to load command ${s.file}`,a)}}return l}function yt(e,t,n,r,o){if(t&&bt(e,t,r))return;let s=(e.commands?.slice(n)??[])[0];if(!s||typeof s.alias!=="function"){o(`Could not alias '${t??"command"}': no matching command was registered.`);return}for(let a of r)s.alias(a)}function gr(e){if(typeof e==="function")return e;return(t)=>Ct(t,e)}function Ct(e,t){let n=e.command(t.name,t.description??"",{allowUnknownOptions:t.allowUnknownOptions});if(t.usage)n.usage(t.usage);for(let[r,o]of Object.entries(t.options??{})){let i=typeof o==="string"?{description:o}:o;n.option(r,i.description??"",{...i.default===void 0?{}:{default:i.default},...i.type?{type:i.type}:{}})}for(let r of t.aliases??[])n.alias(r);for(let r of t.examples??[])n.example(r);return n.action((...r)=>{let o=r[r.length-1];return t.handle(o,...r.slice(0,-1))}),n}function dr(e){return e}import K from"process";import{err as _,handleError as oe,ok as xt}from"@stacksjs/error-handling";import{ExitCode as q}from"@stacksjs/types";async function ie(e,t){let n=Array.isArray(e)?e:e.match(/(?:[^\s"]|"[^"]*")+/g);if(!n)return _(oe(`Failed to parse command: ${n}`,t));let r=t?.cwd??K.cwd(),o=t?.timeoutMs,[i,l,s]=Array.isArray(t?.stdio)?t.stdio:[],a=t?.silent||t?.quiet,c=Bun.spawn(n,{stdin:t?.stdin??i??"inherit",stdout:a?"ignore":t?.stdout??l??"inherit",stderr:a?"ignore":t?.stderr??s??"inherit",cwd:r,env:{...K.env,...t?.env},onExit(h,v,w,k){_e("spawn",h,v,w,k)}});if(t?.stdin==="pipe"&&t.input){if(c.stdin)c.stdin.write(t.input),c.stdin.end()}let m,y=await Promise.race([c.exited,new Promise((h)=>{if(!o)return;m=setTimeout(()=>{try{c.kill()}catch{}h(q.FatalError)},o)})]);if(m)clearTimeout(m);if(o&&y===q.FatalError&&c.exitCode===null)return _(oe(`Command timed out after ${o}ms: ${x(n.join(" "))} in ${x(r)}`,t));if(y===q.Success)return xt(c);let C=c.signalCode;if(C==="SIGTERM"||C==="SIGINT"||C==="SIGKILL"||c.exitCode===null&&y!==q.Success)return _(Error(`Command terminated by ${C??"signal"}: ${n.join(" ")}`));return _(oe(`Failed to execute command: ${x(n.join(" "))} in ${x(r)}`,t))}async function ze(e,t){let n=Array.isArray(e)?e:e.match(/(?:[^\s"]|"[^"]*")+/g);if(!n)throw p.error(`Failed to parse command: ${n}`,t),Error(`Failed to parse command: ${n}`);let r=Bun.spawnSync(n,{...t,stdin:t?.stdin??"inherit",stdout:t?.stdout??"pipe",stderr:t?.stderr??"inherit",cwd:t?.cwd??K.cwd(),env:{...K.env,...t?.env},onExit(i,l,s,a){_e("spawnSync",i,l,s,a)}}),o=r.stdout?.toString()??"";if(t?.throwOnError&&r.exitCode!==0){let l=((r.stderr?.toString()??"").trim()||o.trim()||"(no output)").split(`
2
+ import Ne from"process";async function De(e,t={silent:!0}){let n=t.packageManager??"bun",r=[n==="npm"?"install":"add"];if(t.dev)r.push("-D");if(t.preferOffline&&n!=="bun")r.push("--prefer-offline");if(t.additionalArgs)r.push(...t.additionalArgs);r.push(e);let i=await Bun.spawn([n,...r],{cwd:t.cwd??Ne.cwd(),stdout:t.silent?"ignore":"inherit",stderr:t.silent?"ignore":"inherit",stdin:"ignore",env:Ne.env}).exited;if(i!==0)throw Error(`Failed to install ${e} (exit code ${i})`)}async function nr(e,t){return De(e,t??{silent:!0})}async function or(e,t){return De(`@stacksjs/${e}`,t??{silent:!0})}import{CLI as ar,cli as ft,onUnknownSubcommand as lr}from"@stacksjs/clapp";function cr(e,t){if(typeof e==="object")t=e,e=t.name;return ft(e||"buddy")}import{existsSync as ne,readdirSync as pt}from"fs";import{join as ze}from"path";var ht=/(?:\.test|\.spec|\.bench|\.d)\.ts$/;function bt(e){return e.endsWith(".ts")&&!ht.test(e)&&!e.startsWith("_")}function yt(e){if(!ne(e))return[];let t=[],n=(r,o)=>{for(let i of pt(r,{withFileTypes:!0})){if(i.name.startsWith(".")||i.name==="node_modules")continue;if(i.isDirectory()){n(ze(r,i.name),`${o}${i.name}/`);continue}if(bt(i.name))t.push(`${o}${i.name.slice(0,-3)}`)}};return n(e,""),t.sort()}async function _e(e){if(!e||!ne(e))return{};try{let n=(await import(e)).default;if(!n||typeof n!=="object")return{error:Error(`${e} must default-export a command registry object.`)};return{registry:n}}catch(t){return{error:t}}}async function Ct(e){let{commandsDir:t}=e,n=e.registry??(await _e(e.registryPath)).registry,r=yt(t),o=new Map;for(let a of r)o.set(a,{file:a,path:ze(t,`${a}.ts`),aliases:[],enabled:!0,source:"auto"});let i=[];for(let[a,l]of Object.entries(n??{})){let s=typeof l==="string"?{file:l}:l,c=o.get(s.file);if(!c)continue;if(c.signature=a,c.aliases=s.aliases??[],c.enabled=s.enabled!==!1,c.source="registry",!i.includes(c))i.push(c)}for(let a of r){let l=o.get(a);if(l&&!i.includes(l))i.push(l)}return i}function xt(e,t,n){let r=t.trim().split(/\s+/)[0],i=e?.commands?.find((a)=>a.name===r);if(!i||typeof i.alias!=="function")return!1;for(let a of n)i.alias(a);return!0}async function mr(e,t){let n=t.onError??(()=>{}),r=t.onDebug??(()=>{});if(!ne(t.commandsDir))return r(`No ${t.commandsDir} directory, skipping application commands.`),[];let o=t.registry?{registry:t.registry}:await _e(t.registryPath);if(o.error)n(`Could not read the command registry at ${t.registryPath}`,o.error);let i=await Ct({...t,registry:o.registry}),a=[];for(let l of i){if(!l.enabled){r(`Skipping disabled command ${l.file}.`);continue}try{let s=await import(l.path);if(s.enabled===!1){r(`Skipping ${l.file}: the module exports \`enabled = false\`.`);continue}if(typeof s.default!=="function"){n(`Expected a default export function in ${l.file}.ts, but got: ${typeof s.default}`);continue}let c=e.commands?.length??0;s.default(e);let m=[...l.aliases,...s.aliases??[]];if(m.length)wt(e,l.signature,c,m,r);a.push(l)}catch(s){n(`Failed to load command ${l.file}`,s)}}return a}function wt(e,t,n,r,o){if(t&&xt(e,t,r))return;let l=(e.commands?.slice(n)??[])[0];if(!l||typeof l.alias!=="function"){o(`Could not alias '${t??"command"}': no matching command was registered.`);return}for(let s of r)l.alias(s)}function fr(e){if(typeof e==="function")return e;return(t)=>kt(t,e)}function kt(e,t){let n=e.command(t.name,t.description??"",{allowUnknownOptions:t.allowUnknownOptions});if(t.usage)n.usage(t.usage);for(let[r,o]of Object.entries(t.options??{})){let i=typeof o==="string"?{description:o}:o;n.option(r,i.description??"",{...i.default===void 0?{}:{default:i.default},...i.type?{type:i.type}:{}})}for(let r of t.aliases??[])n.alias(r);for(let r of t.examples??[])n.example(r);return n.action((...r)=>{let o=r[r.length-1];return t.handle(o,...r.slice(0,-1))}),n}function pr(e){return e}import K from"process";import{err as _,handleError as oe,ok as $t}from"@stacksjs/error-handling";import{ExitCode as q}from"@stacksjs/types";async function ie(e,t){let n=Array.isArray(e)?e:e.match(/(?:[^\s"]|"[^"]*")+/g);if(!n)return _(oe(`Failed to parse command: ${n}`,t));let r=t?.cwd??K.cwd(),o=t?.timeoutMs,[i,a,l]=Array.isArray(t?.stdio)?t.stdio:[],s=t?.silent||t?.quiet,c=Bun.spawn(n,{stdin:t?.stdin??i??"inherit",stdout:s?"ignore":t?.stdout??a??"inherit",stderr:s?"ignore":t?.stderr??l??"inherit",cwd:r,env:{...K.env,...t?.env},onExit(x,F,h,k){Ke("spawn",x,F,h,k)}});if(t?.stdin==="pipe"&&t.input){if(c.stdin)c.stdin.write(t.input),c.stdin.end()}let m,C=await Promise.race([c.exited,new Promise((x)=>{if(!o)return;m=setTimeout(()=>{try{c.kill()}catch{}x(q.FatalError)},o)})]);if(m)clearTimeout(m);if(o&&C===q.FatalError&&c.exitCode===null)return _(oe(`Command timed out after ${o}ms: ${w(n.join(" "))} in ${w(r)}`,t));if(C===q.Success)return $t(c);let p=c.signalCode;if(p==="SIGTERM"||p==="SIGINT"||p==="SIGKILL"||c.exitCode===null&&C!==q.Success)return _(Error(`Command terminated by ${p??"signal"}: ${n.join(" ")}`));return _(oe(`Failed to execute command: ${w(n.join(" "))} in ${w(r)}`,t))}async function qe(e,t){let n=Array.isArray(e)?e:e.match(/(?:[^\s"]|"[^"]*")+/g);if(!n)throw b.error(`Failed to parse command: ${n}`,t),Error(`Failed to parse command: ${n}`);let r=Bun.spawnSync(n,{...t,stdin:t?.stdin??"inherit",stdout:t?.stdout??"pipe",stderr:t?.stderr??"inherit",cwd:t?.cwd??K.cwd(),env:{...K.env,...t?.env},onExit(i,a,l,s){Ke("spawnSync",i,a,l,s)}}),o=r.stdout?.toString()??"";if(t?.throwOnError&&r.exitCode!==0){let a=((r.stderr?.toString()??"").trim()||o.trim()||"(no output)").split(`
3
3
  `).slice(0,5).join(`
4
4
  `);throw Error(`Command failed with exit code ${r.exitCode}: ${n.join(" ")}
5
- ${l}`)}return o}function _e(e,t,n,r,o){if(p.debug(`exitHandler: ${e}, exitCode: ${n}, signalCode: ${r}`),o)p.debug("Process error:",o.message)}import{handleError as Rt}from"@stacksjs/error-handling";import{log as p}from"@stacksjs/logging";import{ExitCode as Ge}from"@stacksjs/types";import{collect as wt}from"@stacksjs/collections";var g=!process.env.NO_COLOR&&(process.env.FORCE_COLOR?process.env.FORCE_COLOR!=="0":!!process.stdout?.isTTY),d={reset:g?"\x1B[0m":"",black:g?"\x1B[30m":"",red:g?"\x1B[31m":"",green:g?"\x1B[32m":"",yellow:g?"\x1B[33m":"",blue:g?"\x1B[34m":"",magenta:g?"\x1B[35m":"",cyan:g?"\x1B[36m":"",white:g?"\x1B[37m":"",gray:g?"\x1B[90m":"",lightRed:g?"\x1B[91m":"",lightGreen:g?"\x1B[92m":"",lightYellow:g?"\x1B[93m":"",lightBlue:g?"\x1B[94m":"",lightMagenta:g?"\x1B[95m":"",lightCyan:g?"\x1B[96m":"",lightGray:g?"\x1B[37m":"",bgBlack:g?"\x1B[40m":"",bgRed:g?"\x1B[41m":"",bgGreen:g?"\x1B[42m":"",bgYellow:g?"\x1B[43m":"",bgBlue:g?"\x1B[44m":"",bgMagenta:g?"\x1B[45m":"",bgCyan:g?"\x1B[46m":"",bgWhite:g?"\x1B[47m":"",bgGray:g?"\x1B[100m":"",bgLightRed:g?"\x1B[101m":"",bgLightGreen:g?"\x1B[102m":"",bgLightYellow:g?"\x1B[103m":"",bgLightBlue:g?"\x1B[104m":"",bgLightMagenta:g?"\x1B[105m":"",bgLightCyan:g?"\x1B[106m":"",bgLightGray:g?"\x1B[47m":"",bold:g?"\x1B[1m":"",dim:g?"\x1B[2m":"",italic:g?"\x1B[3m":"",underline:g?"\x1B[4m":"",inverse:g?"\x1B[7m":"",hidden:g?"\x1B[8m":"",strikethrough:g?"\x1B[9m":""},V="\x1B[",kt="\x1B]8;;",$t="\x1B]8;;\x07",qe=(e)=>String(e);function B(e,t,n){return Math.min(Math.max(Math.floor(e),t),n)}function u(e,t=d.reset){return(n)=>{if(!g)return String(n);return`${e}${String(n)}${t}`}}function Ft(e){return e.replace(/\x1B\]8;;[^\x07]*(?:\x07|\x1B\\)/g,"").replace(/\x1B\]8;;(?:\x07|\x1B\\)/g,"")}function I(e){return Ft(e).replace(/\x1B\[[0-?]*[ -/]*[@-~]/g,"")}var Ke=I;function Ue(e){return Array.from(I(e)).length}var se=u(d.black),ae=u(d.red),T=u(d.green),le=u(d.yellow),ce=u(d.blue),ue=u(d.magenta),P=u(d.cyan),ge=u(d.white),S=u(d.gray),de=u(d.lightRed),me=u(d.lightGreen),fe=u(d.lightYellow),pe=u(d.lightBlue),he=u(d.lightMagenta),be=u(d.lightCyan),U=u(d.lightGray),ye=u(d.bgBlack),Ce=u(d.bgRed),xe=u(d.bgGreen),we=u(d.bgYellow),ke=u(d.bgBlue),$e=u(d.bgMagenta),W=u(d.bgCyan),Fe=u(d.bgWhite),ve=u(d.bgGray),Be=u(d.bgLightRed),Se=u(d.bgLightGreen),Oe=u(d.bgLightYellow),Le=u(d.bgLightBlue),Re=u(d.bgLightMagenta),Ie=u(d.bgLightCyan),H=u(d.bgLightGray),F=u(d.bold),O=u(d.dim),x=u(d.italic),Me=u(d.underline),Ee=u(d.inverse),Te=u(d.hidden),Pe=u(d.strikethrough),Ae=u(d.reset,"");function He(e){return u(`${V}38;5;${B(e,0,255)}m`)}function Ve(e){return u(`${V}48;5;${B(e,0,255)}m`)}function Je(e,t,n){return u(`${V}38;2;${B(e,0,255)};${B(t,0,255)};${B(n,0,255)}m`)}function Qe(e,t,n){return u(`${V}48;2;${B(e,0,255)};${B(t,0,255)};${B(n,0,255)}m`)}function Xe(e,t){let n=(o,i)=>{let l=String(o);if(!g)return l;return`${kt}${i}\x07${l}${$t}`};if(typeof t==="string")return n(e,t);let r=String(e);return(o)=>n(o,r)}var vt={black:se,red:ae,green:T,yellow:le,blue:ce,magenta:ue,cyan:P,white:ge,gray:S,lightRed:de,lightGreen:me,lightYellow:fe,lightBlue:pe,lightMagenta:he,lightCyan:be,lightGray:U,bgBlack:ye,bgRed:Ce,bgGreen:xe,bgYellow:we,bgBlue:ke,bgMagenta:$e,bgCyan:W,bgWhite:Fe,bgGray:ve,bgLightRed:Be,bgLightGreen:Se,bgLightYellow:Oe,bgLightBlue:Le,bgLightMagenta:Re,bgLightCyan:Ie,bgLightGray:H,bold:F,dim:O,italic:x,underline:Me,inverse:Ee,hidden:Te,strikethrough:Pe,reset:Ae};function Ze(e){return vt[e]??qe}function xr(e,t){if(typeof t==="function")return t(e);return Ze(t)(e)}function Bt(){return g}var wr={black:se,red:ae,green:T,yellow:le,blue:ce,magenta:ue,cyan:P,white:ge,gray:S,lightRed:de,lightGreen:me,lightYellow:fe,lightBlue:pe,lightMagenta:he,lightCyan:be,lightGray:U,bgBlack:ye,bgRed:Ce,bgGreen:xe,bgYellow:we,bgBlue:ke,bgMagenta:$e,bgCyan:W,bgWhite:Fe,bgGray:ve,bgLightRed:Be,bgLightGreen:Se,bgLightYellow:Oe,bgLightBlue:Le,bgLightMagenta:Re,bgLightCyan:Ie,bgLightGray:H,bold:F,dim:O,italic:x,underline:Me,inverse:Ee,hidden:Te,strikethrough:Pe,reset:Ae,ansi256:He,ansi256Bg:Ve,trueColor:Je,trueColorBg:Qe,link:Xe,stripColors:Ke},kr={black:se,red:ae,green:T,yellow:le,blue:ce,magenta:ue,cyan:P,white:ge,gray:S,lightRed:de,lightGreen:me,lightYellow:fe,lightBlue:pe,lightMagenta:he,lightCyan:be,lightGray:U,bgBlack:ye,bgRed:Ce,bgGreen:xe,bgYellow:we,bgBlue:ke,bgMagenta:$e,bgCyan:W,bgWhite:Fe,bgGray:ve,bgLightRed:Be,bgLightGreen:Se,bgLightYellow:Oe,bgLightBlue:Le,bgLightMagenta:Re,bgLightCyan:Ie,bgLightGray:H,bold:F,dim:O,italic:x,underline:Me,inverse:Ee,hidden:Te,strikethrough:Pe,reset:Ae,ansi256:He,ansi256Bg:Ve,trueColor:Je,trueColorBg:Qe,link:Xe,stripColors:Ke,grey:S,lightGrey:U,bgLightGrey:H,supportsColor:Bt};function St(e,t,n,r){let o=Ue(e);if(o>=t)return e;let i=r[0]||" ",l=t-o;if(n==="right")return`${i.repeat(l)}${e}`;if(n==="center"){let s=Math.floor(l/2),a=l-s;return`${i.repeat(s)}${e}${i.repeat(a)}`}return`${e}${i.repeat(l)}`}function J(e){return Math.max(0,...e.map(Ue))}function Q(e,t,n="left"){let r=String(e).split(/\r?\n/),o=typeof t==="object"?t:void 0,i=typeof t==="number"?t:o?.width??J(r),l=o?.align??n,s=o?.padChar??" ";return r.map((a)=>St(a,Math.max(0,i),l,s)).join(`
6
- `)}function $r(e,t){return Q(e,t,"left")}function Fr(e,t){let n=String(e).split(/\r?\n/);return Q(e,t??process.stdout?.columns??J(n),"right")}function vr(e,t){let n=String(e).split(/\r?\n/);return Q(e,t??process.stdout?.columns??J(n),"center")}var Ot={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"}};function et(e,t={}){let n=String(e).split(/\r?\n/),r=Ot[t.borderStyle??"single"],o=Math.max(0,t.padding??1),i=Math.max(0,t.margin??0),l=t.align??"left",s=J(n),a=s+o*2,c=typeof t.borderColor==="function"?t.borderColor:t.borderColor?Ze(t.borderColor):qe,y=c((()=>{if(!t.title)return`${r.topLeft}${r.horizontal.repeat(a)}${r.topRight}`;let k=` ${I(String(t.title))} `.slice(0,a),E=r.horizontal.repeat(Math.max(0,a-k.length));return`${r.topLeft}${k}${E}${r.topRight}`})()),C=c(`${r.bottomLeft}${r.horizontal.repeat(a)}${r.bottomRight}`),h=n.map((w)=>{let k=Q(w,{align:l,width:s}),E=`${" ".repeat(o)}${k}${" ".repeat(o)}`;return`${c(r.vertical)}${E}${c(r.vertical)}`}),v=" ".repeat(i);return[y,...h,C].map((w)=>`${v}${w}`).join(`
7
- `)}var Br=wt(["The best way to get started is to quit talking and begin doing.","The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.","Don\u2019t let yesterday take up too much of today.","You learn more from failure than from success. Don\u2019t let it stop you. Failure builds character.","It\u2019s not whether you get knocked down, it\u2019s whether you get up.","If you are working on something that you really care about, you don\u2019t have to be pushed. The vision pulls you.","People who are crazy enough to think they can change the world, are the ones who do.","Failure will never overtake me if my determination to succeed is strong enough.","Entrepreneurs are great at dealing with uncertainty and also very good at minimizing risk. That\u2019s the classic entrepreneur.","We may encounter many defeats but we must not be defeated.","Knowing is not enough; we must apply. Wishing is not enough; we must do.","Imagine your life is perfect in every respect; what would it look like?","We generate fears while we sit. We overcome them by action.","Whether you think you can or think you can\u2019t, you\u2019re right.","Security is mostly a superstition. Life is either a daring adventure or nothing."]);var tt="0.75.308";async function Tr(e,t){return new Promise((n)=>{if(t?.quiet===!1)console.log(),console.log(P(F("Stacks CLI"))+O(` v${tt}`)),console.log();if(p.info(`Running ${W(x(F(` ${e} `)))}`),t?.showPerformance===!1||t?.quiet)return n(0);return n(performance.now())})}function Pr(e,t,n){let r={type:"success",useSeconds:!0,...t};return r.message=t?.message||e,new Promise((o)=>{if(n)return Rt(n),o(Ge.FatalError);if(r?.startTime){let i=performance.now()-r.startTime;if(r.useSeconds)i=i/1000,i=Math.round(i*100)/100;if(r.quiet===!0)return o(Ge.Success);if(n)p.error(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}] Failed`);else if(r.type==="error")p.error(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}] ${r.message??"Failed"}`);else if(r.type==="warning")p.warn(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}] ${r.message??"Complete"}`);else if(r.type==="info")p.info(`${O(S(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}]`))} ${r.message??"Complete"}`);else p.success(`${O(S(F(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}]`)))} ${F(T(r.message??"Complete"))}`)}else if(r?.type==="info")p.info(e);else if(r?.type==="error")p.error(e);else if(r?.type==="warning")p.warn(e);else if(r?.type==="success"&&r?.quiet!==!0)p.success(e);p.flush().catch(()=>{}).then(()=>o(Ge.Success))})}import X from"process";function rt(e){if(!e)return!1;return e.startsWith("--")}function It(e){return e.startsWith("-")&&!rt(e)}function je(e){if(e==="true")return!0;if(e==="false")return!1;let t=Number.parseFloat(e);if(!Number.isNaN(t))return t;return e.replace(/"/g,"")}function Mt(e,t,n,r){let[o,i]=e.slice(2).split("=");if(i!==void 0)r[o]=je(i);else if(n+1<t.length&&!t[n+1]?.startsWith("-"))r[o]=t[n+1],n++;else r[o]=!0;return n}function Et(e,t,n,r){let[o,i]=e.slice(1).split("=");if(o===void 0)return n;if(i!==void 0&&o!==void 0)for(let l=0;l<o.length;l++)r[o[l]]=je(i);else for(let l=0;l<o.length;l++)if(n+1<t.length&&l===o.length-1&&!t[n+1]?.startsWith("-"))r[o[l]]=je(t[n+1]),n++;else r[o[l]]=!0;return n}function Tt(e){if(e===void 0)e=X.argv.slice(2);let t=[],n={};for(let r=0;r<e.length;r++){let o=e[r];if(!o)continue;if(rt(o))r=Mt(o,e,r,n);else if(It(o))r=Et(o,e,r,n);else t.push(o)}return{args:t,options:n}}function Wr(e){if(e===void 0)e=X.argv.slice(2);return Tt(e).args}function Yr(e){e=e||{};let t={dryRun:!1,quiet:!1,verbose:!1},n=X.argv.slice(2);for(let r=0;r<n.length;r++){let o=n[r];if(o?.startsWith("--")){let l=o.substring(2).replace(/-([a-z])/gi,(s)=>s[1]?s[1].toUpperCase():"");if(r+1<n.length&&!n?.[r+1]?.startsWith("--"))if(n?.[r+1]==="true"||n?.[r+1]==="false")e[l]=n[r+1]==="true",r++;else e[l]=n[r+1],r++;else e[l]=!0}}if(Object.keys(e).length===0)return{};return{...t,...e}}function Pt(e){let t=[];for(let[n,r]of Object.entries(e)){if(n==="--"||n==="_"||r===!1||r===void 0||r===null)continue;if(typeof r==="object"&&!Array.isArray(r))continue;if(typeof r==="function"||typeof r==="symbol")continue;if(r===!0)t.push(`--${n}`);else t.push(`--${n}`,String(r))}return t}function At(e){if(Array.isArray(e)){if(e=Array.from(new Set(e)),Array.isArray(e)&&e[0]&&!e[0].startsWith("-"))e.shift();return e.join(" ")}if(typeof e==="object"&&e!==null)return Pt(e).join(" ");return At(X.argv.slice(2))}async function Dr(e,t){if(!Number.isSafeInteger(t.timeoutMs)||t.timeoutMs<1||t.timeoutMs>120000)throw Error("Invalid bounded process timeout");for(let f of[t.stdoutBytes,t.stderrBytes])if(!Number.isSafeInteger(f)||f<1||f>2000000)throw Error("Invalid bounded process output limit");let n=process.platform!=="win32",r=Bun.spawn(e,{cwd:t.cwd,env:t.env??process.env,stdin:"ignore",stdout:"pipe",stderr:"pipe",detached:n}),o=[r.stdout.getReader(),r.stderr.getReader()],i=[],l,s=!1,a=!1,c="failed",m=[];function y(f){if(f?.code!=="ESRCH")m.push(f)}function C(){if(n)try{process.kill(-r.pid,"SIGKILL")}catch(f){y(f)}if(r.exitCode===null)try{r.kill("SIGKILL")}catch(f){y(f)}}function h(f,L="failed"){if(!s)l=f,s=!0,c=L;if(a)return;a=!0,C();for(let R of o)i.push(R.cancel().catch((D)=>{m.push(D)}))}async function v(f,L,R){let D=[],te=0;try{while(!0){let{done:z,value:re}=await f.read();if(z){let j=Buffer.concat(D,te);return t.strictUtf8===!0?new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(j):j.toString("utf8")}if(re.byteLength>L-te){let j=Error(`${t.label} ${R} exceeds byte limit`);throw h(j,`${R} exceeds byte limit`),j}te+=re.byteLength,D.push(re)}}catch(z){throw h(z,`${R} read failed`),z}}let w=setTimeout(()=>h(Error(`${t.label} timed out`),"timed out"),t.timeoutMs),k=v(o[0],t.stdoutBytes,"stdout"),E=v(o[1],t.stderrBytes,"stderr");try{let[f,L,R]=await Promise.all([r.exited,k,E]);if(s)throw l;return{exitCode:f,stdout:L,stderr:R}}catch(f){throw h(f),f}finally{if(clearTimeout(w),!a)C();if(r.exitCode===null)h(Error(`${t.label} interrupted`));await Promise.allSettled([r.exited,k,E,...i]);for(let f of o)try{f.releaseLock()}catch(L){m.push(L)}if(m.length)throw AggregateError(s?[l,...m]:m,`${t.label} ${s?`${c}; `:""}process cleanup failed`)}}import{writeSync as Gt}from"fs";import{format as Z}from"util";function Kr(...e){ot(1,Z(...e))}function Ur(...e){ot(2,Z(...e))}async function Hr(...e){await nt(process.stdout,Z(...e))}async function Vr(...e){await nt(process.stderr,Z(...e))}function nt(e,t){return new Promise((n,r)=>{let o=(i)=>{e.off("error",o),r(i)};e.once("error",o);try{e.write(`${t}
8
- `,"utf8",(i)=>{if(i)setImmediate(()=>e.off("error",o)),r(i);else e.off("error",o),n()})}catch(i){e.off("error",o),r(i)}})}function ot(e,t){let n=Buffer.from(`${t}
9
- `),r=0;while(r<n.length)r+=Gt(e,n,r,n.length-r)}import b from"process";import{createInterface as jt}from"readline";var Zr=b.stdin.destroy;b.stdin.destroy=function(e){if(e)this.emit("error",e);return this};b.on("SIGINT",()=>{console.log(`
10
- `),b.exit(130)});var A=null;function Wt(){if(!A){let e=b.stdin.isTTY&&b.stdout.isTTY;if(A=jt({input:b.stdin,output:b.stdout,terminal:e}),e&&typeof b.stdin.setRawMode==="function")A.on("SIGINT",()=>{b.emit("SIGINT")});A.once("close",()=>{A=null})}return A}var ee=Symbol("stdin-eof");function it(e){return new Promise((t)=>{let n=Wt(),r=!1,o=(l)=>{if(r)return;r=!0,n.off("close",i),t(l)},i=()=>o(ee);n.once("close",i);try{n.question(e,o)}catch{o(ee)}})}function st(){if(b.argv.includes("--no-interaction"))return!1;if(b.env.CI)return!1;return Boolean(b.stdin.isTTY&&b.stdout.isTTY)}async function Y(e){if(!st())return"";let t=await it(e);return t===ee?"":t}function at(e,t){let n=e.toLowerCase().trim();if(!n)return t;if(n==="y"||n==="yes")return!0;if(n==="n"||n==="no")return!1;return t}async function en(e){let t=typeof e==="string"?{message:e}:e,n=t.initial??!1,r=n?" (Y/n) ":" (y/N) ";if(!st())return null;let o=await it(`${t.message}${r}`);if(o===ee)return null;return at(o,n)}async function Yt(e){let t=typeof e==="string"?{message:e}:e,n=t.initial??!1,r=n?" (Y/n) ":" (y/N) ",o=await Y(`${t.message}${r}`);return at(o,n)}async function Nt(e){let t=typeof e==="string"?{message:e}:e,n=t.placeholder||t.initial||"",r=n?` (${n}) `:" ";return(await Y(`${t.message}${r}`)).trim()||t.initial||""}async function Dt(e){console.log(e.message),e.choices.forEach((o,i)=>{let l=i===(e.initial??0)?">":" ";console.log(`${l} ${i+1}. ${o.label}`)});let t=await Y("Select (number): "),n=Number.parseInt(t.trim(),10)-1,r=e.choices[n]??e.choices[e.initial??0];if(!r)throw Error("select prompt: no choices available");return r.value}async function zt(e){console.log(e.message),console.log("(Enter numbers separated by commas)"),e.choices.forEach((o,i)=>{console.log(` ${i+1}. ${o.label}`)});let n=(await Y("Select (e.g., 1,3,4): ")).split(",").map((o)=>Number.parseInt(o.trim(),10)-1),r=[];for(let o of n){let i=e.choices[o];if(i)r.push(i.value)}return r}async function _t(e){return(await Y(`${(typeof e==="string"?{message:e}:e).message} `)).trim()}var tn={text:Nt,confirm:Yt,select:Dt,multiselect:zt,password:_t};import{handleError as qt}from"@stacksjs/error-handling";async function Kt(e,t){let n={...t,stdin:t?.stdin??"inherit",verbose:t?.verbose??!1};return await ie(e,n)}async function sn(e,t){let n={...t,stdio:[t?.stdin??"inherit","pipe","pipe"],verbose:t?.verbose??!1};return await ie(e,n)}async function an(e,t){let n={...t,stdio:[t?.stdin??"inherit","pipe","pipe"],verbose:t?.verbose??!1};return await ze(e,n)}async function ln(e,t){let n=[];for(let r of e){let o=await Kt(r,t);if(o.isErr)throw qt("Error during runCommands",o.error),o.error;n.push(o)}return n}import Ut from"process";var Ht=["SIGINT","SIGTERM","SIGHUP"],G=new Map,lt=!1;function Vt(){if(lt)return;lt=!0;for(let e of Ht)Ut.on(e,async()=>{for(let[t,n]of G)try{await n()}catch(r){console.error(`[signals] cleanup '${t}' threw:`,r)}})}function gn(e,t){return Vt(),G.set(e,t),()=>{if(G.get(e)===t)G.delete(e)}}function dn(e){G.delete(e)}function mn(){return[...G.keys()]}var ct=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],N=process.stdout.isTTY&&!process.env.CI;function Jt(e){let t=e||"",n=0,r=null,o=!1,i=()=>{if(N)process.stdout.write("\r\x1B[K")},l=()=>{if(!N)return;i();let s=ct[n];process.stdout.write(`${s} ${t}`),n=(n+1)%ct.length};return{start(s){if(s)t=s;if(o)return;if(o=!0,N)l(),r=setInterval(l,80);else if(t)console.log(` ${t}`)},stop(s){if(o=!1,r)clearInterval(r),r=null;if(i(),s)console.log(s)},update(s){if(t=s,!N&&o)console.log(` ${s}`)},succeed(s){let a=s||t;if(o=!1,r)clearInterval(r),r=null;i(),console.log(`\u2713 ${a}`)},fail(s){let a=s||t;if(o=!1,r)clearInterval(r),r=null;i(),console.error(`\u2717 ${a}`)},get text(){return t},set text(s){if(t=s,N&&o)l()},get isSpinning(){return o}}}async function pn(e,t,n){let r=Jt(e);r.start();try{let o=await t();return r.succeed(n?.successMessage||e),o}catch(o){throw r.fail(n?.failMessage||`Failed: ${e}`),o}}import M from"process";var ut="\r\x1B[2K";function Qt(){return{columns:M.stdout.columns??80,rows:M.stdout.rows??24}}function Xt(){return Boolean(M.stdout.isTTY)&&!M.env.CI}function Cn(e,t){console.log(et(e,t===void 0?{}:{title:t}))}function xn(e,t={}){let r=(t.columns??[...new Set(e.flatMap((a)=>Object.keys(a)))]).map((a)=>typeof a==="string"?{key:a}:a);if(r.length===0)return"";let o=(a,c)=>{let m=a[c.key];return m===void 0||m===null?"":String(m)},i=r.map((a)=>{let c=t.header===!1?"":a.header??a.key;return Math.max(I(c).length,...e.map((m)=>I(o(m,a)).length))}),l=(a,c,m)=>{let y=Math.max(0,c-I(a).length);return m==="right"?" ".repeat(y)+a:a+" ".repeat(y)},s=[];if(t.header!==!1)s.push(r.map((a,c)=>l(a.header??a.key,i[c],a.align)).join(" ").trimEnd()),s.push(r.map((a,c)=>"-".repeat(i[c])).join(" "));for(let a of e)s.push(r.map((c,m)=>l(o(a,c),i[m],c.align)).join(" ").trimEnd());return s.join(`
11
- `)}function wn(e){if(!Number.isFinite(e.total)||e.total<=0)throw TypeError(`progress() needs a positive total; got ${e.total}`);let t=e.format??"|{bar}| {percentage}% | {value}/{total}",n=e.width??Math.max(10,Math.floor(Qt().columns/3)),r=Xt(),o=0,i=-1,l=(a)=>{let c=Math.min(1,o/e.total),m=Math.round(c*n),y={bar:"\u2588".repeat(m)+"\u2591".repeat(n-m),percentage:Math.round(c*100),value:o,total:e.total,...a},C=t.replace(/\{(\w+)\}/g,(v,w)=>String(y[w]??v));if(r){M.stdout.write(`${ut}${C}`);return}let h=Math.floor(c*10);if(h>i)i=h,console.log(C)},s={update(a,c={}){o=Math.max(0,Math.min(e.total,a)),l(c)},increment(a=1){s.update(o+a)},stop(a){if(r)M.stdout.write(ut);if(a)console.log(a);else if(r)M.stdout.write(`
12
- `)},get value(){return o},get total(){return e.total}};return s}async function kn(e){let t=[];for(let n of e){let r=Date.now(),o=n.skip?.();if(o){console.log(`- ${n.title}${typeof o==="string"?` (${o})`:""}`),t.push({title:n.title,status:"skipped",durationMs:0});continue}try{await n.task(),console.log(`\u2713 ${n.title}`),t.push({title:n.title,status:"done",durationMs:Date.now()-r})}catch(i){throw console.log(`\u2717 ${n.title}`),t.push({title:n.title,status:"failed",error:i instanceof Error?i:Error(String(i)),durationMs:Date.now()-r}),i}}return t}export{or as CLI,Q as align,He as ansi256,Ve as ansi256Bg,bt as applyAliases,ye as bgBlack,ke as bgBlue,W as bgCyan,ve as bgGray,xe as bgGreen,Le as bgLightBlue,Ie as bgLightCyan,H as bgLightGray,Se as bgLightGreen,Re as bgLightMagenta,Be as bgLightRed,Oe as bgLightYellow,$e as bgMagenta,Ce as bgRed,Fe as bgWhite,we as bgYellow,se as black,ce as blue,F as bold,et as box,Pt as buddyOptionArgs,At as buddyOptions,vr as centerAlign,sr as cli,xr as colorize,wr as colors,Yt as confirm,en as confirmOrNull,P as cyan,gr as defineCommand,dr as defineCommands,O as dim,pt as discoverCommandFiles,ie as exec,ze as execSync,Ze as getColor,Qt as getTerminalSize,S as gray,T as green,Te as hidden,er as installPackage,tr as installStack,Tr as intro,Ee as inverse,Xt as isInteractive,x as italic,kr as kolorist,$r as leftAlign,pe as lightBlue,be as lightCyan,U as lightGray,me as lightGreen,he as lightMagenta,de as lightRed,fe as lightYellow,Xe as link,mn as listSignalHandlers,De as loadCommandRegistry,ur as loadCommands,p as log,ue as magenta,zt as multiselect,Cn as note,dn as offSignal,gn as onSignal,ir as onUnknownSubcommand,Pr as outro,Wr as parseArgs,Tt as parseArgv,Yr as parseOptions,_t as password,Kr as print,Hr as printAsync,Ur as printError,Vr as printErrorAsync,wn as progress,tn as prompts,st as promptsAreInteractive,Br as quotes,ae as red,Ae as reset,ht as resolveCommands,Fr as rightAlign,Dr as runBoundedProcess,Kt as runCommand,an as runCommandSync,ln as runCommands,sn as runProcess,Dt as select,Jt as spinner,Pe as strikethrough,I as stripAnsi,Ke as stripColors,xn as table,kn as tasks,Nt as text,Je as trueColor,Qe as trueColorBg,Me as underline,ge as white,pn as withSpinner,le as yellow};
5
+ ${a}`)}return o}function Ke(e,t,n,r,o){if(b.debug(`exitHandler: ${e}, exitCode: ${n}, signalCode: ${r}`),o)b.debug("Process error:",o.message)}import{handleError as Et}from"@stacksjs/error-handling";import{log as b}from"@stacksjs/logging";import{ExitCode as Ge}from"@stacksjs/types";import{collect as vt}from"@stacksjs/collections";var g=!process.env.NO_COLOR&&(process.env.FORCE_COLOR?process.env.FORCE_COLOR!=="0":!!process.stdout?.isTTY),d={reset:g?"\x1B[0m":"",black:g?"\x1B[30m":"",red:g?"\x1B[31m":"",green:g?"\x1B[32m":"",yellow:g?"\x1B[33m":"",blue:g?"\x1B[34m":"",magenta:g?"\x1B[35m":"",cyan:g?"\x1B[36m":"",white:g?"\x1B[37m":"",gray:g?"\x1B[90m":"",lightRed:g?"\x1B[91m":"",lightGreen:g?"\x1B[92m":"",lightYellow:g?"\x1B[93m":"",lightBlue:g?"\x1B[94m":"",lightMagenta:g?"\x1B[95m":"",lightCyan:g?"\x1B[96m":"",lightGray:g?"\x1B[37m":"",bgBlack:g?"\x1B[40m":"",bgRed:g?"\x1B[41m":"",bgGreen:g?"\x1B[42m":"",bgYellow:g?"\x1B[43m":"",bgBlue:g?"\x1B[44m":"",bgMagenta:g?"\x1B[45m":"",bgCyan:g?"\x1B[46m":"",bgWhite:g?"\x1B[47m":"",bgGray:g?"\x1B[100m":"",bgLightRed:g?"\x1B[101m":"",bgLightGreen:g?"\x1B[102m":"",bgLightYellow:g?"\x1B[103m":"",bgLightBlue:g?"\x1B[104m":"",bgLightMagenta:g?"\x1B[105m":"",bgLightCyan:g?"\x1B[106m":"",bgLightGray:g?"\x1B[47m":"",bold:g?"\x1B[1m":"",dim:g?"\x1B[2m":"",italic:g?"\x1B[3m":"",underline:g?"\x1B[4m":"",inverse:g?"\x1B[7m":"",hidden:g?"\x1B[8m":"",strikethrough:g?"\x1B[9m":""},V="\x1B[",Ft="\x1B]8;;",Bt="\x1B]8;;\x07",Ue=(e)=>String(e);function B(e,t,n){return Math.min(Math.max(Math.floor(e),t),n)}function u(e,t=d.reset){return(n)=>{if(!g)return String(n);return`${e}${String(n)}${t}`}}function St(e){return e.replace(/\x1B\]8;;[^\x07]*(?:\x07|\x1B\\)/g,"").replace(/\x1B\]8;;(?:\x07|\x1B\\)/g,"")}function I(e){return St(e).replace(/\x1B\[[0-?]*[ -/]*[@-~]/g,"")}var He=I;function Ve(e){return Array.from(I(e)).length}var se=u(d.black),ae=u(d.red),T=u(d.green),le=u(d.yellow),ce=u(d.blue),ue=u(d.magenta),P=u(d.cyan),ge=u(d.white),S=u(d.gray),de=u(d.lightRed),me=u(d.lightGreen),fe=u(d.lightYellow),pe=u(d.lightBlue),he=u(d.lightMagenta),be=u(d.lightCyan),U=u(d.lightGray),ye=u(d.bgBlack),Ce=u(d.bgRed),xe=u(d.bgGreen),we=u(d.bgYellow),ke=u(d.bgBlue),$e=u(d.bgMagenta),W=u(d.bgCyan),ve=u(d.bgWhite),Fe=u(d.bgGray),Be=u(d.bgLightRed),Se=u(d.bgLightGreen),Oe=u(d.bgLightYellow),Le=u(d.bgLightBlue),Re=u(d.bgLightMagenta),Ie=u(d.bgLightCyan),H=u(d.bgLightGray),v=u(d.bold),O=u(d.dim),w=u(d.italic),Me=u(d.underline),Ee=u(d.inverse),Te=u(d.hidden),Pe=u(d.strikethrough),Ae=u(d.reset,"");function Je(e){return u(`${V}38;5;${B(e,0,255)}m`)}function Qe(e){return u(`${V}48;5;${B(e,0,255)}m`)}function Xe(e,t,n){return u(`${V}38;2;${B(e,0,255)};${B(t,0,255)};${B(n,0,255)}m`)}function Ze(e,t,n){return u(`${V}48;2;${B(e,0,255)};${B(t,0,255)};${B(n,0,255)}m`)}function et(e,t){let n=(o,i)=>{let a=String(o);if(!g)return a;return`${Ft}${i}\x07${a}${Bt}`};if(typeof t==="string")return n(e,t);let r=String(e);return(o)=>n(o,r)}var Ot={black:se,red:ae,green:T,yellow:le,blue:ce,magenta:ue,cyan:P,white:ge,gray:S,lightRed:de,lightGreen:me,lightYellow:fe,lightBlue:pe,lightMagenta:he,lightCyan:be,lightGray:U,bgBlack:ye,bgRed:Ce,bgGreen:xe,bgYellow:we,bgBlue:ke,bgMagenta:$e,bgCyan:W,bgWhite:ve,bgGray:Fe,bgLightRed:Be,bgLightGreen:Se,bgLightYellow:Oe,bgLightBlue:Le,bgLightMagenta:Re,bgLightCyan:Ie,bgLightGray:H,bold:v,dim:O,italic:w,underline:Me,inverse:Ee,hidden:Te,strikethrough:Pe,reset:Ae};function tt(e){return Ot[e]??Ue}function $r(e,t){if(typeof t==="function")return t(e);return tt(t)(e)}function Lt(){return g}var vr={black:se,red:ae,green:T,yellow:le,blue:ce,magenta:ue,cyan:P,white:ge,gray:S,lightRed:de,lightGreen:me,lightYellow:fe,lightBlue:pe,lightMagenta:he,lightCyan:be,lightGray:U,bgBlack:ye,bgRed:Ce,bgGreen:xe,bgYellow:we,bgBlue:ke,bgMagenta:$e,bgCyan:W,bgWhite:ve,bgGray:Fe,bgLightRed:Be,bgLightGreen:Se,bgLightYellow:Oe,bgLightBlue:Le,bgLightMagenta:Re,bgLightCyan:Ie,bgLightGray:H,bold:v,dim:O,italic:w,underline:Me,inverse:Ee,hidden:Te,strikethrough:Pe,reset:Ae,ansi256:Je,ansi256Bg:Qe,trueColor:Xe,trueColorBg:Ze,link:et,stripColors:He},Fr={black:se,red:ae,green:T,yellow:le,blue:ce,magenta:ue,cyan:P,white:ge,gray:S,lightRed:de,lightGreen:me,lightYellow:fe,lightBlue:pe,lightMagenta:he,lightCyan:be,lightGray:U,bgBlack:ye,bgRed:Ce,bgGreen:xe,bgYellow:we,bgBlue:ke,bgMagenta:$e,bgCyan:W,bgWhite:ve,bgGray:Fe,bgLightRed:Be,bgLightGreen:Se,bgLightYellow:Oe,bgLightBlue:Le,bgLightMagenta:Re,bgLightCyan:Ie,bgLightGray:H,bold:v,dim:O,italic:w,underline:Me,inverse:Ee,hidden:Te,strikethrough:Pe,reset:Ae,ansi256:Je,ansi256Bg:Qe,trueColor:Xe,trueColorBg:Ze,link:et,stripColors:He,grey:S,lightGrey:U,bgLightGrey:H,supportsColor:Lt};function Rt(e,t,n,r){let o=Ve(e);if(o>=t)return e;let i=r[0]||" ",a=t-o;if(n==="right")return`${i.repeat(a)}${e}`;if(n==="center"){let l=Math.floor(a/2),s=a-l;return`${i.repeat(l)}${e}${i.repeat(s)}`}return`${e}${i.repeat(a)}`}function J(e){return Math.max(0,...e.map(Ve))}function Q(e,t,n="left"){let r=String(e).split(/\r?\n/),o=typeof t==="object"?t:void 0,i=typeof t==="number"?t:o?.width??J(r),a=o?.align??n,l=o?.padChar??" ";return r.map((s)=>Rt(s,Math.max(0,i),a,l)).join(`
6
+ `)}function Br(e,t){return Q(e,t,"left")}function Sr(e,t){let n=String(e).split(/\r?\n/);return Q(e,t??process.stdout?.columns??J(n),"right")}function Or(e,t){let n=String(e).split(/\r?\n/);return Q(e,t??process.stdout?.columns??J(n),"center")}var It={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551"},round:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502"}};function rt(e,t={}){let n=String(e).split(/\r?\n/),r=It[t.borderStyle??"single"],o=Math.max(0,t.padding??1),i=Math.max(0,t.margin??0),a=t.align??"left",l=J(n),s=l+o*2,c=typeof t.borderColor==="function"?t.borderColor:t.borderColor?tt(t.borderColor):Ue,C=c((()=>{if(!t.title)return`${r.topLeft}${r.horizontal.repeat(s)}${r.topRight}`;let k=` ${I(String(t.title))} `.slice(0,s),E=r.horizontal.repeat(Math.max(0,s-k.length));return`${r.topLeft}${k}${E}${r.topRight}`})()),p=c(`${r.bottomLeft}${r.horizontal.repeat(s)}${r.bottomRight}`),x=n.map((h)=>{let k=Q(h,{align:a,width:l}),E=`${" ".repeat(o)}${k}${" ".repeat(o)}`;return`${c(r.vertical)}${E}${c(r.vertical)}`}),F=" ".repeat(i);return[C,...x,p].map((h)=>`${F}${h}`).join(`
7
+ `)}var Lr=vt(["The best way to get started is to quit talking and begin doing.","The pessimist sees difficulty in every opportunity. The optimist sees opportunity in every difficulty.","Don\u2019t let yesterday take up too much of today.","You learn more from failure than from success. Don\u2019t let it stop you. Failure builds character.","It\u2019s not whether you get knocked down, it\u2019s whether you get up.","If you are working on something that you really care about, you don\u2019t have to be pushed. The vision pulls you.","People who are crazy enough to think they can change the world, are the ones who do.","Failure will never overtake me if my determination to succeed is strong enough.","Entrepreneurs are great at dealing with uncertainty and also very good at minimizing risk. That\u2019s the classic entrepreneur.","We may encounter many defeats but we must not be defeated.","Knowing is not enough; we must apply. Wishing is not enough; we must do.","Imagine your life is perfect in every respect; what would it look like?","We generate fears while we sit. We overcome them by action.","Whether you think you can or think you can\u2019t, you\u2019re right.","Security is mostly a superstition. Life is either a daring adventure or nothing."]);var nt="0.75.310";async function Gr(e,t){return new Promise((n)=>{if(t?.quiet===!1)console.log(),console.log(P(v("Stacks CLI"))+O(` v${nt}`)),console.log();if(b.info(`Running ${W(w(v(` ${e} `)))}`),t?.showPerformance===!1||t?.quiet)return n(0);return n(performance.now())})}function jr(e,t,n){let r={type:"success",useSeconds:!0,...t};return r.message=t?.message||e,new Promise((o)=>{if(n)return Et(n),o(Ge.FatalError);if(r?.startTime){let i=performance.now()-r.startTime;if(r.useSeconds)i=i/1000,i=Math.round(i*100)/100;if(r.quiet===!0)return o(Ge.Success);if(n)b.error(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}] Failed`);else if(r.type==="error")b.error(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}] ${r.message??"Failed"}`);else if(r.type==="warning")b.warn(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}] ${r.message??"Complete"}`);else if(r.type==="info")b.info(`${O(S(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}]`))} ${r.message??"Complete"}`);else b.success(`${O(S(v(`[${i.toFixed(2)}${r.useSeconds?"s":"ms"}]`)))} ${v(T(r.message??"Complete"))}`)}else if(r?.type==="info")b.info(e);else if(r?.type==="error")b.error(e);else if(r?.type==="warning")b.warn(e);else if(r?.type==="success"&&r?.quiet!==!0)b.success(e);b.flush().catch(()=>{}).then(()=>o(Ge.Success))})}import X from"process";function ot(e){if(!e)return!1;return e.startsWith("--")}function Tt(e){return e.startsWith("-")&&!ot(e)}function je(e){if(e==="true")return!0;if(e==="false")return!1;let t=Number.parseFloat(e);if(!Number.isNaN(t))return t;return e.replace(/"/g,"")}function Pt(e,t,n,r){let[o,i]=e.slice(2).split("=");if(i!==void 0)r[o]=je(i);else if(n+1<t.length&&!t[n+1]?.startsWith("-"))r[o]=t[n+1],n++;else r[o]=!0;return n}function At(e,t,n,r){let[o,i]=e.slice(1).split("=");if(o===void 0)return n;if(i!==void 0&&o!==void 0)for(let a=0;a<o.length;a++)r[o[a]]=je(i);else for(let a=0;a<o.length;a++)if(n+1<t.length&&a===o.length-1&&!t[n+1]?.startsWith("-"))r[o[a]]=je(t[n+1]),n++;else r[o[a]]=!0;return n}function Gt(e){if(e===void 0)e=X.argv.slice(2);let t=[],n={};for(let r=0;r<e.length;r++){let o=e[r];if(!o)continue;if(ot(o))r=Pt(o,e,r,n);else if(Tt(o))r=At(o,e,r,n);else t.push(o)}return{args:t,options:n}}function Dr(e){if(e===void 0)e=X.argv.slice(2);return Gt(e).args}function zr(e){e=e||{};let t={dryRun:!1,quiet:!1,verbose:!1},n=X.argv.slice(2);for(let r=0;r<n.length;r++){let o=n[r];if(o?.startsWith("--")){let a=o.substring(2).replace(/-([a-z])/gi,(l)=>l[1]?l[1].toUpperCase():"");if(r+1<n.length&&!n?.[r+1]?.startsWith("--"))if(n?.[r+1]==="true"||n?.[r+1]==="false")e[a]=n[r+1]==="true",r++;else e[a]=n[r+1],r++;else e[a]=!0}}if(Object.keys(e).length===0)return{};return{...t,...e}}function jt(e){let t=[];for(let[n,r]of Object.entries(e)){if(n==="--"||n==="_"||r===!1||r===void 0||r===null)continue;if(typeof r==="object"&&!Array.isArray(r))continue;if(typeof r==="function"||typeof r==="symbol")continue;if(r===!0)t.push(`--${n}`);else t.push(`--${n}`,String(r))}return t}function Wt(e){if(Array.isArray(e)){if(e=Array.from(new Set(e)),Array.isArray(e)&&e[0]&&!e[0].startsWith("-"))e.shift();return e.join(" ")}if(typeof e==="object"&&e!==null)return jt(e).join(" ");return Wt(X.argv.slice(2))}async function qr(e,t){if(!Number.isSafeInteger(t.timeoutMs)||t.timeoutMs<1||t.timeoutMs>120000)throw Error("Invalid bounded process timeout");for(let f of[t.stdoutBytes,t.stderrBytes])if(!Number.isSafeInteger(f)||f<1||f>2000000)throw Error("Invalid bounded process output limit");let n=t.signal;if(n!==void 0&&!(n instanceof AbortSignal))throw TypeError("Invalid bounded process signal");let r=()=>Error(`${t.label} canceled`,{cause:n?.reason});if(n?.aborted)throw r();let o=process.platform!=="win32",i=Bun.spawn(e,{cwd:t.cwd,env:t.env??process.env,stdin:"ignore",stdout:"pipe",stderr:"pipe",detached:o}),a=[i.stdout.getReader(),i.stderr.getReader()],l=[],s,c=!1,m=!1,C="failed",p=[];function x(f){if(f?.code!=="ESRCH")p.push(f)}function F(){if(o)try{process.kill(-i.pid,"SIGKILL")}catch(f){x(f)}if(i.exitCode===null)try{i.kill("SIGKILL")}catch(f){x(f)}}function h(f,L="failed"){if(!c)s=f,c=!0,C=L;if(m)return;m=!0,F();for(let R of a)l.push(R.cancel().catch((D)=>{p.push(D)}))}let k=()=>h(r(),"canceled");async function E(f,L,R){let D=[],te=0;try{while(!0){let{done:z,value:re}=await f.read();if(z){let j=Buffer.concat(D,te);return t.strictUtf8===!0?new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(j):j.toString("utf8")}if(re.byteLength>L-te){let j=Error(`${t.label} ${R} exceeds byte limit`);throw h(j,`${R} exceeds byte limit`),j}te+=re.byteLength,D.push(re)}}catch(z){throw h(z,`${R} read failed`),z}}let mt=setTimeout(()=>h(Error(`${t.label} timed out`),"timed out"),t.timeoutMs),We=E(a[0],t.stdoutBytes,"stdout"),Ye=E(a[1],t.stderrBytes,"stderr");try{if(n?.addEventListener("abort",k,{once:!0}),n?.aborted)k();let[f,L,R]=await Promise.all([i.exited,We,Ye]);if(c)throw s;return{exitCode:f,stdout:L,stderr:R}}catch(f){throw h(f),s}finally{try{n?.removeEventListener("abort",k)}catch(f){p.push(f)}if(clearTimeout(mt),!m)F();if(i.exitCode===null)h(Error(`${t.label} interrupted`));await Promise.allSettled([i.exited,We,Ye,...l]);for(let f of a)try{f.releaseLock()}catch(L){p.push(L)}if(p.length)throw AggregateError(c?[s,...p]:p,`${t.label} ${c?`${C}; `:""}process cleanup failed`)}}import{writeSync as Yt}from"fs";import{format as Z}from"util";function Vr(...e){st(1,Z(...e))}function Jr(...e){st(2,Z(...e))}async function Qr(...e){await it(process.stdout,Z(...e))}async function Xr(...e){await it(process.stderr,Z(...e))}function it(e,t){return new Promise((n,r)=>{let o=(i)=>{e.off("error",o),r(i)};e.once("error",o);try{e.write(`${t}
8
+ `,"utf8",(i)=>{if(i)setImmediate(()=>e.off("error",o)),r(i);else e.off("error",o),n()})}catch(i){e.off("error",o),r(i)}})}function st(e,t){let n=Buffer.from(`${t}
9
+ `),r=0;while(r<n.length)r+=Yt(e,n,r,n.length-r)}import y from"process";import{createInterface as Nt}from"readline";var rn=y.stdin.destroy;y.stdin.destroy=function(e){if(e)this.emit("error",e);return this};y.on("SIGINT",()=>{console.log(`
10
+ `),y.exit(130)});var A=null;function Dt(){if(!A){let e=y.stdin.isTTY&&y.stdout.isTTY;if(A=Nt({input:y.stdin,output:y.stdout,terminal:e}),e&&typeof y.stdin.setRawMode==="function")A.on("SIGINT",()=>{y.emit("SIGINT")});A.once("close",()=>{A=null})}return A}var ee=Symbol("stdin-eof");function at(e){return new Promise((t)=>{let n=Dt(),r=!1,o=(a)=>{if(r)return;r=!0,n.off("close",i),t(a)},i=()=>o(ee);n.once("close",i);try{n.question(e,o)}catch{o(ee)}})}function lt(){if(y.argv.includes("--no-interaction"))return!1;if(y.env.CI)return!1;return Boolean(y.stdin.isTTY&&y.stdout.isTTY)}async function Y(e){if(!lt())return"";let t=await at(e);return t===ee?"":t}function ct(e,t){let n=e.toLowerCase().trim();if(!n)return t;if(n==="y"||n==="yes")return!0;if(n==="n"||n==="no")return!1;return t}async function nn(e){let t=typeof e==="string"?{message:e}:e,n=t.initial??!1,r=n?" (Y/n) ":" (y/N) ";if(!lt())return null;let o=await at(`${t.message}${r}`);if(o===ee)return null;return ct(o,n)}async function zt(e){let t=typeof e==="string"?{message:e}:e,n=t.initial??!1,r=n?" (Y/n) ":" (y/N) ",o=await Y(`${t.message}${r}`);return ct(o,n)}async function _t(e){let t=typeof e==="string"?{message:e}:e,n=t.placeholder||t.initial||"",r=n?` (${n}) `:" ";return(await Y(`${t.message}${r}`)).trim()||t.initial||""}async function qt(e){console.log(e.message),e.choices.forEach((o,i)=>{let a=i===(e.initial??0)?">":" ";console.log(`${a} ${i+1}. ${o.label}`)});let t=await Y("Select (number): "),n=Number.parseInt(t.trim(),10)-1,r=e.choices[n]??e.choices[e.initial??0];if(!r)throw Error("select prompt: no choices available");return r.value}async function Kt(e){console.log(e.message),console.log("(Enter numbers separated by commas)"),e.choices.forEach((o,i)=>{console.log(` ${i+1}. ${o.label}`)});let n=(await Y("Select (e.g., 1,3,4): ")).split(",").map((o)=>Number.parseInt(o.trim(),10)-1),r=[];for(let o of n){let i=e.choices[o];if(i)r.push(i.value)}return r}async function Ut(e){return(await Y(`${(typeof e==="string"?{message:e}:e).message} `)).trim()}var on={text:_t,confirm:zt,select:qt,multiselect:Kt,password:Ut};import{handleError as Ht}from"@stacksjs/error-handling";async function Vt(e,t){let n={...t,stdin:t?.stdin??"inherit",verbose:t?.verbose??!1};return await ie(e,n)}async function cn(e,t){let n={...t,stdio:[t?.stdin??"inherit","pipe","pipe"],verbose:t?.verbose??!1};return await ie(e,n)}async function un(e,t){let n={...t,stdio:[t?.stdin??"inherit","pipe","pipe"],verbose:t?.verbose??!1};return await qe(e,n)}async function gn(e,t){let n=[];for(let r of e){let o=await Vt(r,t);if(o.isErr)throw Ht("Error during runCommands",o.error),o.error;n.push(o)}return n}import Jt from"process";var Qt=["SIGINT","SIGTERM","SIGHUP"],G=new Map,ut=!1;function Xt(){if(ut)return;ut=!0;for(let e of Qt)Jt.on(e,async()=>{for(let[t,n]of G)try{await n()}catch(r){console.error(`[signals] cleanup '${t}' threw:`,r)}})}function fn(e,t){return Xt(),G.set(e,t),()=>{if(G.get(e)===t)G.delete(e)}}function pn(e){G.delete(e)}function hn(){return[...G.keys()]}var gt=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],N=process.stdout.isTTY&&!process.env.CI;function Zt(e){let t=e||"",n=0,r=null,o=!1,i=()=>{if(N)process.stdout.write("\r\x1B[K")},a=()=>{if(!N)return;i();let l=gt[n];process.stdout.write(`${l} ${t}`),n=(n+1)%gt.length};return{start(l){if(l)t=l;if(o)return;if(o=!0,N)a(),r=setInterval(a,80);else if(t)console.log(` ${t}`)},stop(l){if(o=!1,r)clearInterval(r),r=null;if(i(),l)console.log(l)},update(l){if(t=l,!N&&o)console.log(` ${l}`)},succeed(l){let s=l||t;if(o=!1,r)clearInterval(r),r=null;i(),console.log(`\u2713 ${s}`)},fail(l){let s=l||t;if(o=!1,r)clearInterval(r),r=null;i(),console.error(`\u2717 ${s}`)},get text(){return t},set text(l){if(t=l,N&&o)a()},get isSpinning(){return o}}}async function yn(e,t,n){let r=Zt(e);r.start();try{let o=await t();return r.succeed(n?.successMessage||e),o}catch(o){throw r.fail(n?.failMessage||`Failed: ${e}`),o}}import M from"process";var dt="\r\x1B[2K";function er(){return{columns:M.stdout.columns??80,rows:M.stdout.rows??24}}function tr(){return Boolean(M.stdout.isTTY)&&!M.env.CI}function kn(e,t){console.log(rt(e,t===void 0?{}:{title:t}))}function $n(e,t={}){let r=(t.columns??[...new Set(e.flatMap((s)=>Object.keys(s)))]).map((s)=>typeof s==="string"?{key:s}:s);if(r.length===0)return"";let o=(s,c)=>{let m=s[c.key];return m===void 0||m===null?"":String(m)},i=r.map((s)=>{let c=t.header===!1?"":s.header??s.key;return Math.max(I(c).length,...e.map((m)=>I(o(m,s)).length))}),a=(s,c,m)=>{let C=Math.max(0,c-I(s).length);return m==="right"?" ".repeat(C)+s:s+" ".repeat(C)},l=[];if(t.header!==!1)l.push(r.map((s,c)=>a(s.header??s.key,i[c],s.align)).join(" ").trimEnd()),l.push(r.map((s,c)=>"-".repeat(i[c])).join(" "));for(let s of e)l.push(r.map((c,m)=>a(o(s,c),i[m],c.align)).join(" ").trimEnd());return l.join(`
11
+ `)}function vn(e){if(!Number.isFinite(e.total)||e.total<=0)throw TypeError(`progress() needs a positive total; got ${e.total}`);let t=e.format??"|{bar}| {percentage}% | {value}/{total}",n=e.width??Math.max(10,Math.floor(er().columns/3)),r=tr(),o=0,i=-1,a=(s)=>{let c=Math.min(1,o/e.total),m=Math.round(c*n),C={bar:"\u2588".repeat(m)+"\u2591".repeat(n-m),percentage:Math.round(c*100),value:o,total:e.total,...s},p=t.replace(/\{(\w+)\}/g,(F,h)=>String(C[h]??F));if(r){M.stdout.write(`${dt}${p}`);return}let x=Math.floor(c*10);if(x>i)i=x,console.log(p)},l={update(s,c={}){o=Math.max(0,Math.min(e.total,s)),a(c)},increment(s=1){l.update(o+s)},stop(s){if(r)M.stdout.write(dt);if(s)console.log(s);else if(r)M.stdout.write(`
12
+ `)},get value(){return o},get total(){return e.total}};return l}async function Fn(e){let t=[];for(let n of e){let r=Date.now(),o=n.skip?.();if(o){console.log(`- ${n.title}${typeof o==="string"?` (${o})`:""}`),t.push({title:n.title,status:"skipped",durationMs:0});continue}try{await n.task(),console.log(`\u2713 ${n.title}`),t.push({title:n.title,status:"done",durationMs:Date.now()-r})}catch(i){throw console.log(`\u2717 ${n.title}`),t.push({title:n.title,status:"failed",error:i instanceof Error?i:Error(String(i)),durationMs:Date.now()-r}),i}}return t}export{ar as CLI,Q as align,Je as ansi256,Qe as ansi256Bg,xt as applyAliases,ye as bgBlack,ke as bgBlue,W as bgCyan,Fe as bgGray,xe as bgGreen,Le as bgLightBlue,Ie as bgLightCyan,H as bgLightGray,Se as bgLightGreen,Re as bgLightMagenta,Be as bgLightRed,Oe as bgLightYellow,$e as bgMagenta,Ce as bgRed,ve as bgWhite,we as bgYellow,se as black,ce as blue,v as bold,rt as box,jt as buddyOptionArgs,Wt as buddyOptions,Or as centerAlign,cr as cli,$r as colorize,vr as colors,zt as confirm,nn as confirmOrNull,P as cyan,fr as defineCommand,pr as defineCommands,O as dim,yt as discoverCommandFiles,ie as exec,qe as execSync,tt as getColor,er as getTerminalSize,S as gray,T as green,Te as hidden,nr as installPackage,or as installStack,Gr as intro,Ee as inverse,tr as isInteractive,w as italic,Fr as kolorist,Br as leftAlign,pe as lightBlue,be as lightCyan,U as lightGray,me as lightGreen,he as lightMagenta,de as lightRed,fe as lightYellow,et as link,hn as listSignalHandlers,_e as loadCommandRegistry,mr as loadCommands,b as log,ue as magenta,Kt as multiselect,kn as note,pn as offSignal,fn as onSignal,lr as onUnknownSubcommand,jr as outro,Dr as parseArgs,Gt as parseArgv,zr as parseOptions,Ut as password,Vr as print,Qr as printAsync,Jr as printError,Xr as printErrorAsync,vn as progress,on as prompts,lt as promptsAreInteractive,Lr as quotes,ae as red,Ae as reset,Ct as resolveCommands,Sr as rightAlign,qr as runBoundedProcess,Vt as runCommand,un as runCommandSync,gn as runCommands,cn as runProcess,qt as select,Zt as spinner,Pe as strikethrough,I as stripAnsi,He as stripColors,$n as table,Fn as tasks,_t as text,Xe as trueColor,Ze as trueColorBg,Me as underline,ge as white,yn as withSpinner,le as yellow};
package/dist/process.d.ts CHANGED
@@ -8,6 +8,7 @@ export declare interface BoundedProcessOptions {
8
8
  stderrBytes: number
9
9
  label: string
10
10
  strictUtf8?: boolean
11
+ signal?: AbortSignal
11
12
  }
12
13
  export declare interface BoundedProcessResult {
13
14
  exitCode: number
package/dist/process.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- async function S(P,t){if(!Number.isSafeInteger(t.timeoutMs)||t.timeoutMs<1||t.timeoutMs>120000)throw Error("Invalid bounded process timeout");for(let e of[t.stdoutBytes,t.stderrBytes])if(!Number.isSafeInteger(e)||e<1||e>2000000)throw Error("Invalid bounded process output limit");let g=process.platform!=="win32",r=Bun.spawn(P,{cwd:t.cwd,env:t.env??process.env,stdin:"ignore",stdout:"pipe",stderr:"pipe",detached:g}),c=[r.stdout.getReader(),r.stderr.getReader()],p=[],f,i=!1,m=!1,y="failed",o=[];function b(e){if(e?.code!=="ESRCH")o.push(e)}function B(){if(g)try{process.kill(-r.pid,"SIGKILL")}catch(e){b(e)}if(r.exitCode===null)try{r.kill("SIGKILL")}catch(e){b(e)}}function u(e,n="failed"){if(!i)f=e,i=!0,y=n;if(m)return;m=!0,B();for(let s of c)p.push(s.cancel().catch((a)=>{o.push(a)}))}async function x(e,n,s){let a=[],w=0;try{while(!0){let{done:l,value:h}=await e.read();if(l){let d=Buffer.concat(a,w);return t.strictUtf8===!0?new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(d):d.toString("utf8")}if(h.byteLength>n-w){let d=Error(`${t.label} ${s} exceeds byte limit`);throw u(d,`${s} exceeds byte limit`),d}w+=h.byteLength,a.push(h)}}catch(l){throw u(l,`${s} read failed`),l}}let R=setTimeout(()=>u(Error(`${t.label} timed out`),"timed out"),t.timeoutMs),k=x(c[0],t.stdoutBytes,"stdout"),E=x(c[1],t.stderrBytes,"stderr");try{let[e,n,s]=await Promise.all([r.exited,k,E]);if(i)throw f;return{exitCode:e,stdout:n,stderr:s}}catch(e){throw u(e),e}finally{if(clearTimeout(R),!m)B();if(r.exitCode===null)u(Error(`${t.label} interrupted`));await Promise.allSettled([r.exited,k,E,...p]);for(let e of c)try{e.releaseLock()}catch(n){o.push(n)}if(o.length)throw AggregateError(i?[f,...o]:o,`${t.label} ${i?`${y}; `:""}process cleanup failed`)}}export{S as runBoundedProcess};
2
+ async function R(L,t){if(!Number.isSafeInteger(t.timeoutMs)||t.timeoutMs<1||t.timeoutMs>120000)throw Error("Invalid bounded process timeout");for(let e of[t.stdoutBytes,t.stderrBytes])if(!Number.isSafeInteger(e)||e<1||e>2000000)throw Error("Invalid bounded process output limit");let n=t.signal;if(n!==void 0&&!(n instanceof AbortSignal))throw TypeError("Invalid bounded process signal");let y=()=>Error(`${t.label} canceled`,{cause:n?.reason});if(n?.aborted)throw y();let p=process.platform!=="win32",r=Bun.spawn(L,{cwd:t.cwd,env:t.env??process.env,stdin:"ignore",stdout:"pipe",stderr:"pipe",detached:p}),c=[r.stdout.getReader(),r.stderr.getReader()],B=[],l,d=!1,m=!1,E="failed",o=[];function x(e){if(e?.code!=="ESRCH")o.push(e)}function v(){if(p)try{process.kill(-r.pid,"SIGKILL")}catch(e){x(e)}if(r.exitCode===null)try{r.kill("SIGKILL")}catch(e){x(e)}}function a(e,s="failed"){if(!d)l=e,d=!0,E=s;if(m)return;m=!0,v();for(let i of c)B.push(i.cancel().catch((f)=>{o.push(f)}))}let h=()=>a(y(),"canceled");async function S(e,s,i){let f=[],b=0;try{while(!0){let{done:w,value:g}=await e.read();if(w){let u=Buffer.concat(f,b);return t.strictUtf8===!0?new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(u):u.toString("utf8")}if(g.byteLength>s-b){let u=Error(`${t.label} ${i} exceeds byte limit`);throw a(u,`${i} exceeds byte limit`),u}b+=g.byteLength,f.push(g)}}catch(w){throw a(w,`${i} read failed`),w}}let P=setTimeout(()=>a(Error(`${t.label} timed out`),"timed out"),t.timeoutMs),k=S(c[0],t.stdoutBytes,"stdout"),I=S(c[1],t.stderrBytes,"stderr");try{if(n?.addEventListener("abort",h,{once:!0}),n?.aborted)h();let[e,s,i]=await Promise.all([r.exited,k,I]);if(d)throw l;return{exitCode:e,stdout:s,stderr:i}}catch(e){throw a(e),l}finally{try{n?.removeEventListener("abort",h)}catch(e){o.push(e)}if(clearTimeout(P),!m)v();if(r.exitCode===null)a(Error(`${t.label} interrupted`));await Promise.allSettled([r.exited,k,I,...B]);for(let e of c)try{e.releaseLock()}catch(s){o.push(s)}if(o.length)throw AggregateError(d?[l,...o]:o,`${t.label} ${d?`${E}; `:""}process cleanup failed`)}}export{R as runBoundedProcess};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/cli",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.308",
5
+ "version": "0.75.310",
6
6
  "description": "TypeScript framework for CLI artisans. Build beautiful console apps with ease.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -70,16 +70,16 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@stacksjs/clapp": "^0.2.12",
73
- "@stacksjs/collections": "0.75.308",
74
- "@stacksjs/error-handling": "0.75.308",
75
- "@stacksjs/logging": "0.75.308",
76
- "@stacksjs/types": "0.75.308"
73
+ "@stacksjs/collections": "0.75.310",
74
+ "@stacksjs/error-handling": "0.75.310",
75
+ "@stacksjs/logging": "0.75.310",
76
+ "@stacksjs/types": "0.75.310"
77
77
  },
78
78
  "devDependencies": {
79
- "@stacksjs/config": "0.75.308",
80
- "@stacksjs/path": "0.75.308",
81
- "@stacksjs/utils": "0.75.308",
82
- "@stacksjs/validation": "0.75.308",
79
+ "@stacksjs/config": "0.75.310",
80
+ "@stacksjs/path": "0.75.310",
81
+ "@stacksjs/utils": "0.75.310",
82
+ "@stacksjs/validation": "0.75.310",
83
83
  "better-dx": "^0.2.24"
84
84
  }
85
85
  }