create-crust 0.5.2 → 0.5.3

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 (2) hide show
  1. package/bin/create-crust.js +23 -23
  2. package/package.json +1 -1
@@ -1,36 +1,36 @@
1
1
  #!/usr/bin/env node
2
- var Xn=Symbol.dispose||Symbol.for("Symbol.dispose"),Zn=Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose"),nt=(e,t,n)=>{if(t!=null){if(typeof t!=="object"&&typeof t!=="function")throw TypeError('Object expected to be assigned to "using" declaration');var r;if(n)r=t[Zn];if(r===void 0)r=t[Xn];if(typeof r!=="function")throw TypeError("Object not disposable");e.push([n,r,t])}else if(n)e.push([n]);return t},rt=(e,t,n)=>{var r=typeof SuppressedError==="function"?SuppressedError:function(i,a,c,l){return l=Error(c),l.name="SuppressedError",l.error=i,l.suppressed=a,l},o=(i)=>t=n?new r(i,t,"An error was suppressed during disposal"):(n=!0,i),s=(i)=>{while(i=e.pop())try{var a=i[1]&&i[1].call(i[2]);if(i[0])return Promise.resolve(a).then(s,(c)=>(o(c),s()))}catch(c){o(c)}if(n)throw t};return s()};import{existsSync as Gn,readdirSync as aa}from"node:fs";import{basename as Kn,dirname as Hn,join as ca,resolve as Yn}from"node:path";import{dirname as Na,join as Aa,posix as Ta,resolve as vr,win32 as Fa}from"node:path";import{existsSync as ot,statSync as Qn}from"node:fs";import{dirname as st,isAbsolute as wa,join as er,resolve as tr}from"node:path";function it(e){let t=tr(e);if(ot(t)&&!Qn(t).isDirectory())t=st(t);while(!0){if(ot(er(t,"package.json")))return t;let n=st(t);if(n===t)return null;t=n}}import{realpathSync as nr}from"node:fs";import{dirname as rr,join as pe,resolve as or}from"node:path";import{fileURLToPath as sr}from"node:url";var at="CRUST_INTERNAL_BUILD_OUT_DIR",ir="crustjs.packagedBuild",ar=Symbol.for(ir);function he(){return globalThis[ar]===!0}function cr(){let{Bun:e,Deno:t}=globalThis,n=e?.main??"";return n.startsWith("/$bunfs/")||/^[A-Za-z]:[\\/]~BUN[\\/]/.test(n)||t?.build?.standalone===!0||process.getBuiltinModule?.("node:sea")?.isSea()===!0}function be(e){if(e===""||e==="."||e===".."||/[\\/]/.test(e))throw Error(`Artifact name must be a single directory name, got ${JSON.stringify(e)}.`);if(cr())return pe(rr(process.execPath),e);return he(),or(sr(import.meta.url),"..","..",e);let t=process.env[at];if(t)return pe(t,e);let n=process.argv[1],r=n;if(n)try{r=nr(n)}catch(s){throw Error(`Could not resolve artifact "${e}": could not resolve source entrypoint "${n}".`,{cause:s})}let o=r?it(r):null;if(!o)throw Error(`Could not resolve artifact "${e}": no package.json was found above ${n?`entrypoint "${n}"`:"process.argv[1] (unset)"}.`);return pe(o,".crust","root",e)}import{AsyncLocalStorage as lr}from"node:async_hooks";import{Writable as ur}from"node:stream";var fr=Symbol.for("crustjs.terminal.io"),dr=Symbol.for("crustjs.terminal.ambient-callbacks"),mr=globalThis,gr=globalThis,H=mr[fr]??=new lr,ct=gr[dr]??=new WeakMap;function we(e,t){let n=H.getStore();return H.run({input:e.input??n?.input,output:e.output??n?.output},t)}function K(){return H.getStore()}function pr(e){let t="",n=new ur({decodeStrings:!1,write(r,o,s){t+=r.toString();let i=t.indexOf(`
2
+ var Xn=Symbol.dispose||Symbol.for("Symbol.dispose"),Zn=Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose"),nt=(e,t,n)=>{if(t!=null){if(typeof t!=="object"&&typeof t!=="function")throw TypeError('Object expected to be assigned to "using" declaration');var r;if(n)r=t[Zn];if(r===void 0)r=t[Xn];if(typeof r!=="function")throw TypeError("Object not disposable");e.push([n,r,t])}else if(n)e.push([n]);return t},rt=(e,t,n)=>{var r=typeof SuppressedError==="function"?SuppressedError:function(i,a,c,l){return l=Error(c),l.name="SuppressedError",l.error=i,l.suppressed=a,l},o=(i)=>t=n?new r(i,t,"An error was suppressed during disposal"):(n=!0,i),s=(i)=>{while(i=e.pop())try{var a=i[1]&&i[1].call(i[2]);if(i[0])return Promise.resolve(a).then(s,(c)=>(o(c),s()))}catch(c){o(c)}if(n)throw t};return s()};import{existsSync as Gn,readdirSync as ca}from"node:fs";import{basename as Kn,dirname as Hn,join as la,resolve as Yn}from"node:path";import{dirname as Aa,join as Ta,posix as Fa,resolve as xr,win32 as Pa}from"node:path";import{existsSync as ot,statSync as Qn}from"node:fs";import{dirname as st,isAbsolute as ya,join as er,resolve as tr}from"node:path";function it(e){let t=tr(e);if(ot(t)&&!Qn(t).isDirectory())t=st(t);while(!0){if(ot(er(t,"package.json")))return t;let n=st(t);if(n===t)return null;t=n}}import{realpathSync as nr}from"node:fs";import{dirname as rr,join as pe,resolve as or}from"node:path";import{fileURLToPath as sr}from"node:url";var at="CRUST_INTERNAL_BUILD_OUT_DIR",ir="crustjs.packagedBuild",ar=Symbol.for(ir);function he(){return globalThis[ar]===!0}function cr(){let{Bun:e,Deno:t}=globalThis,n=e?.main??"";return n.startsWith("/$bunfs/")||/^[A-Za-z]:[\\/]~BUN[\\/]/.test(n)||t?.build?.standalone===!0||process.getBuiltinModule?.("node:sea")?.isSea()===!0}function lr(){return he()||!0}function be(e){if(e===""||e==="."||e===".."||/[\\/]/.test(e))throw Error(`Artifact name must be a single directory name, got ${JSON.stringify(e)}.`);if(cr())return pe(rr(process.execPath),e);if(lr())return or(sr(import.meta.url),"..","..",e);let t=process.env[at];if(t)return pe(t,e);let n=process.argv[1],r=n;if(n)try{r=nr(n)}catch(s){throw Error(`Could not resolve artifact "${e}": could not resolve source entrypoint "${n}".`,{cause:s})}let o=r?it(r):null;if(!o)throw Error(`Could not resolve artifact "${e}": no package.json was found above ${n?`entrypoint "${n}"`:"process.argv[1] (unset)"}.`);return pe(o,".crust","root",e)}import{AsyncLocalStorage as ur}from"node:async_hooks";import{Writable as fr}from"node:stream";var dr=Symbol.for("crustjs.terminal.io"),mr=Symbol.for("crustjs.terminal.ambient-callbacks"),gr=globalThis,pr=globalThis,H=gr[dr]??=new ur,ct=pr[mr]??=new WeakMap;function we(e,t){let n=H.getStore();return H.run({input:e.input??n?.input,output:e.output??n?.output},t)}function K(){return H.getStore()}function hr(e){let t="",n=new fr({decodeStrings:!1,write(r,o,s){t+=r.toString();let i=t.indexOf(`
3
3
  `);while(i!==-1)e.stderr(t.slice(0,i)),t=t.slice(i+1),i=t.indexOf(`
4
- `);s()}});return ct.set(n,e),n}function ye(e,t){let n=H.getStore();return we({input:n?.input,output:n?.output&&!ct.has(n.output)?n.output:pr(e)},t)}import{parseArgs as xr}from"node:util";import{isPromise as Sr}from"node:util/types";function lt(e){let t=Number(e);return Number.isNaN(t)?void 0:t}function ve(e){return e==="true"||e==="1"}import{homedir as $r}from"node:os";function hr(e){return typeof e==="number"}function br(e){return e.map((t,n)=>hr(t)?`[${t}]`:n>0?`.${String(t)}`:String(t)).join("")}function wr(e){return typeof e==="object"&&e!==null&&"key"in e}function yr(e){if(!e)return[];return e.map((t)=>wr(t)?t.key:t)}function ut(e,t=[]){return e.map((n)=>{let r=yr(n.path),o=[...t,...r];return{message:n.message,path:br(o)}})}var h=class extends Error{code;details;cause;constructor(e,t,...n){super(t);this.name="CrustError",this.code=e,this.details=n[0]}is(e){return Object.is(this.code,e)}withCause(e){return this.cause=e,this}toJSON(){return{code:this.code,message:this.message,details:this.details}}};function xe(e,t){if(e==="")throw new h("DEFINITION",`Flag ${t} spellings must be non-empty`,{subject:"flag",name:e,reason:"empty-spelling"});if(t!=="short"&&e.startsWith("no-"))throw new h("DEFINITION",`Flag ${t} "${e}" must not start with "no-"; the prefix is reserved for boolean negation`,{subject:"flag",name:e,reason:"reserved-no-prefix"});if(e==="__proto__")throw new h("DEFINITION",`Flag ${t} "__proto__" is a reserved spelling`,{subject:"flag",name:e,reason:"reserved-spelling"})}function ht(e,t){return[e,...t.short===void 0?[]:[t.short],...t.aliases??[]]}function bt(e){return e.type==="boolean"&&e.noNegate!==!0}function wt(e){if(e.choices&&e.default!==void 0){let t="multiple"in e&&e.multiple?e.default:[e.default];for(let n of t)if(!e.choices.includes(n))throw new h("DEFINITION","default must be one of choices")}return Object.freeze({...e,..."aliases"in e&&e.aliases?{aliases:Object.freeze([...e.aliases])}:{},...e.choices?{choices:Object.freeze([...e.choices])}:{},..."env"in e&&e.env?{env:Object.freeze({name:e.env.name,delimiter:e.env.delimiter})}:{},..."multiple"in e&&e.multiple&&Array.isArray(e.default)?{default:Object.freeze([...e.default])}:{}})}function Or(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&"name"in e&&typeof e.name==="string"&&(!("delimiter"in e)||e.delimiter===void 0||typeof e.delimiter==="string")}function yt(e,t){if(xe(e,"canonical"),t.short!==void 0)xe(t.short,"short");for(let r of t.aliases??[])xe(r,"alias");let n=ht(e,t);if(new Set(n).size!==n.length)throw new h("DEFINITION",`Flag "${e}" repeats one of its own spellings`,{subject:"flag",name:e,reason:"flag-collision"});if(t.short!==void 0&&t.short.length!==1)throw new h("DEFINITION","Short flags must be one character");if(t.env!==void 0&&!Or(t.env))throw new h("DEFINITION",`Flag "${e}" env must be an object with a string name and optional string delimiter`,{subject:"flag",name:e,reason:"invalid-env"});if(t.env?.name==="")throw new h("DEFINITION",`Flag "${e}" env variable name must be non-empty`,{subject:"flag",name:e,reason:"empty-env"});for(let[r,o]of[["delimiter",t.delimiter],["env.delimiter",t.env?.delimiter]]){if(o===void 0)continue;if(!t.multiple)throw new h("DEFINITION",`Flag "${e}" ${r} requires multiple: true`,{subject:"flag",name:e,reason:"delimiter-without-multiple"});if(o==="")throw new h("DEFINITION",`Flag "${e}" ${r} must be non-empty`,{subject:"flag",name:e,reason:"empty-delimiter"})}return wt(t)}function vt(e){if(e.name==="")throw new h("DEFINITION","Argument names must be non-empty",{subject:"argument",name:e.name,reason:"empty-name"});return wt(e)}function xt(e){return e.meta.hidden!==!0}var Er={command:"Command",context:"Context",extension:"Extension"};function Ir({subject:e,name:t}){let n=Er[e];return new h("DEFINITION",`${n} "${t}" contains invalid documentation sections`,{subject:e,name:t,reason:"invalid-sections"})}function St(e,t){let{title:n,body:r,only:o,except:s}=e;if(!n.trim()||/[\r\n]/.test(n)||!r.trim()||o?.length===0||s?.length===0||o!==void 0&&s!==void 0)throw Ir(t);let i=(a)=>Object.freeze(a.map((c)=>typeof c==="string"?c:c.id));return Object.freeze({title:n,body:r,...o?{only:i(o)}:s?{except:i(s)}:{}})}function _e(e,t,n="command"){return t.map((r)=>St(r,{subject:n,name:e}))}var Cr=Symbol("crust.defining");function X(e){return e[Cr]}var $t=Symbol.for("crust.contextSources");function Z(e,t){let n=new Set(e.map((s)=>s.name)),r=new Set,o=(s)=>{if(r.has(s))return;r.add(s);let i="contextName"in s?s.contextName:s.name;if(!n.has(i))throw new h("DEFINITION",`No provider for Context "${i}"`,{subject:"context",name:i,reason:"missing-context"});for(let a of s.use)o(a)};for(let s of t)o(s)}function _r(e){if(e===null||typeof e!=="object"&&typeof e!=="function")return!1;let t=e;return typeof t[Symbol.asyncDispose]==="function"||typeof t[Symbol.dispose]==="function"}function jr(e,t,n){if(!_r(e)||n.has(e))return;n.add(e),t.use(e)}function kr(e,t,n,r){let o=new Map(e.map((g)=>[g.name,g])),s=new Map,i=new WeakSet,a,c=!0,l=!1;n.defer(()=>{l=!0});let u=(g,p,w=new Set)=>{if(g.name===p)return[g.name];if(w.has(g.name))return;w.add(g.name);for(let O of g.waitingOn){let x=s.get(O);if(!x)continue;let S=u(x,p,w);if(S)return[g.name,...S]}},f=(g)=>{try{let p=new Set;for(let w=g;w!=null&&!p.has(w);w=w.cause)if(p.add(w),w instanceof h&&w.code==="DEFINITION"&&w.details?.reason==="flags-before-validation")return!0;return!1}catch{return!1}};function d(g){let p=Promise.reject(g);return p.catch(()=>{}),p}let m=(g)=>(p)=>{let w=g?` (pulled while constructing Context "${g.name}")`:"";if(l)return d(new h("DEFINITION",`Context "${p}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:p,reason:"context-after-disposal"}));let O=o.get(p);if(!O)return d(new h("DEFINITION",`No provider for Context "${p}". Add .provide(${p}(...)) to the app or an ancestor command.${w}`,{subject:"context",name:p,reason:"missing-context"}));if(!c&&!s.has(p))return d(new h("DEFINITION",`Context "${p}" cannot be constructed during invocation cleanup. Read it while setting up the Context whose cleanup needs it.`,{subject:"context",name:p,reason:"context-during-disposal"}));if(a===void 0&&Object.keys(O.ownedFlags).length>0)return d(new h("DEFINITION",`Context "${p}" owns flags and cannot be pulled before flag validation${w}. Pull it from an action or a postRun hook after a validated invocation.`,{subject:"context",name:p,reason:"flags-before-validation"}));let x=s.get(p);if(!x){let S=Promise.withResolvers();S.promise.catch(()=>{}),x={name:p,promise:S.promise,resolve:S.resolve,reject:S.reject,waitingOn:new Set,settled:!1},s.set(p,x);let I=x;(async()=>{try{let j=Object.fromEntries(Object.keys(O.ownedFlags).map((_)=>[_,a?.[_]])),C=await O.setup({...t,signal:r,flags:j,ctx:b(O.use,I),defer(_){if(I.settled)throw new h("DEFINITION",`Context "${p}" cannot register cleanup after its setup has finished.`,{subject:"context",name:p,reason:"context-defer-after-setup"});n.defer(_)}});jr(C,n,i),I.resolve(C)}catch(j){if(f(j))s.delete(p);I.reject(j)}finally{I.settled=!0}})()}if(g&&!x.settled){let S=u(x,g.name);if(S)return d(new h("DEFINITION",`Context dependency cycle: ${[g.name,...S].map((I)=>`"${I}"`).join(" -> ")}`,{subject:"context",name:g.name,reason:"context-cycle"}));return g.waitingOn.add(p),x.promise.finally(()=>g.waitingOn.delete(p))}return x.promise},b=(g,p)=>{let w={},O=(x)=>{let S="contextName"in x?x.contextName:x.name;if(Object.hasOwn(w,S))return;Object.defineProperty(w,S,{enumerable:!0,get:()=>m(p)(S)});for(let I of x.use??[])O(I)};for(let x of g)O(x);return Object.defineProperty(w,$t,{value:Object.freeze([...g])}),Object.freeze(w)};return{bag:(g)=>b(g,null),setValidatedFlags(g){a=g},async settle(){for(;;){let g=[...s.values()].filter((p)=>!p.settled);if(g.length===0){c=!1;return}await Promise.allSettled(g.map((p)=>p.promise))}}}}var Nr=Object.freeze({[Symbol("crust.handled")]:!0});function Oe(){return Nr}function Ot(e){return{meta:{name:e},localFlags:{},ownedFlags:{},effectiveFlags:{},flagSpellings:new Map,args:[],subCommands:{},contexts:[],providedContexts:[],demands:[],extensions:[],run:void 0}}function F(e,t,n,r){n=yt(t,n);let o=ht(t,n),s=Object.hasOwn(e.effectiveFlags,t)?t:o.map((a)=>e.flagSpellings.get(a)?.canonicalName).find((a)=>a!==void 0);if(s!==void 0)throw new h("DEFINITION",`Flag "${t}" collides with existing flag "${s}" on command "${e.meta.name}"`,{subject:"flag",name:t,reason:"flag-collision"});(r==="local"?e.localFlags:e.ownedFlags)[t]=n,e.effectiveFlags[t]=n;let i={canonicalName:t,def:n,negatable:bt(n)};if(e.flagSpellings.set(t,{...i,kind:"canonical"}),n.short!==void 0)e.flagSpellings.set(n.short,{...i,kind:"short"});for(let a of n.aliases??[])e.flagSpellings.set(a,{...i,kind:"alias"})}function Et(e,t,n,r){if(F(e,t,n,"owned"),!r)return;for(let o of Object.values(e.subCommands))Et(o,t,n,!0)}function Ar(e,t,n){for(let r of t.commands)e.subCommands[r.name]=n(r,e,t.id)}function Tr(e,t){for(let[n,r]of Object.entries(t.flags)){let{recursive:o=!0,...s}=r;Et(e,n,s,o)}}function Q(e){return{localFlags:{...e.localFlags},ownedFlags:{...e.ownedFlags},effectiveFlags:{...e.effectiveFlags},flagSpellings:new Map(e.flagSpellings)}}function B(e){let t={};for(let[n,r]of Object.entries(e.subCommands))t[n]=B(r);return{...e,meta:{...e.meta},...Q(e),args:[...e.args],subCommands:t,contexts:e.contexts.map((n)=>({...n})),providedContexts:[...e.providedContexts],demands:[...e.demands],extensions:[...e.extensions],run:e.run}}function Fr(e,t,n){let r=e;for(let o of t){let s=Object.hasOwn(r.subCommands,o)?r.subCommands[o]:void 0;if(!s)throw new h("DEFINITION",`Extension "${n.id}" section target "${t.join(" ")}" is not a canonical command path`,{subject:"extension",name:n.id,reason:"invalid-section-path"});r=s}return r}function Pr(e,t,n){if(!t.sections)return;let r={subject:"extension",name:t.id},o=t.sections(n);for(let s of o){let i=St(s,r),a=Fr(e,s.command,t);a.meta.sections=[...a.meta.sections??[],i]}}function Rr(e,t){let n=(r,o,s)=>{let i=[...new Map(s.map((a)=>[a.name,a])).values()];if(i.some((a)=>a.sections.length>0)){let a=new Set((r.meta.sections??[]).map(({title:c})=>c));for(let c of i){for(let{title:l}of c.sections)if(a.has(l))throw new h("DEFINITION",`Context "${c.name}" section "${l}" duplicates a section on command "${o}"`,{subject:"context",name:c.name,reason:"duplicate-section"});for(let{title:l}of c.sections)a.add(l)}r.meta.sections=[...r.meta.sections??[],...i.flatMap((c)=>c.sections)]}for(let[a,c]of Object.entries(r.subCommands))n(c,`${o} ${a}`,c.providedContexts)};n(e,e.meta.name,[...e.providedContexts,...t.flatMap((r)=>r.provide)])}function It(e,t,n){let r=B(e),o=new Set(t.flatMap((i)=>!n.has(i.id)&&e.extensions.includes(i)?[i.id]:[])),s=(i)=>{i.contexts=i.contexts.filter((u)=>u.extensionId===void 0||o.has(u.extensionId));let a=Object.keys(i.effectiveFlags),c=i.localFlags,l={};for(let{instance:u}of i.contexts)Object.assign(l,u.ownedFlags);i.localFlags={},i.ownedFlags={},i.effectiveFlags={},i.flagSpellings=new Map;for(let u of a){let f=Object.hasOwn(l,u)?"owned":"local",d=f==="owned"?l:c;if(Object.hasOwn(d,u))F(i,u,d[u],f)}for(let u of Object.values(i.subCommands))s(u)};s(r);for(let i of t){if(o.has(i.id))continue;let a=i.provide;if(a.length===0)continue;let c=(l,u)=>{let f=a.filter((b)=>!u.has(b.name)),d=f.map((b)=>({instance:b,extensionId:i.id}));l.contexts.push(...d);for(let b of f)for(let[g,p]of Object.entries(b.ownedFlags))F(l,g,p,"owned");let m=new WeakSet(l.contexts.map(({instance:b})=>b));for(let b of Object.values(l.subCommands)){let g=new Set(u);for(let{instance:p}of b.contexts)if(!m.has(p))g.add(p.name);c(b,g)}};c(r,new Set)}return r}function Dr(e){try{return new URL(e)}catch{throw new h("PARSE",`Invalid URL "${e}"${/^[a-z][a-z0-9+.-]*:/i.test(e)?"":" (missing protocol — e.g. https://example.com)"}`)}}function Y(e){if(e==="")throw new h("PARSE","Path cannot be empty");let t=e.replace(/^~(?=\/|$)/,$r());return vr(process.cwd(),t)}function Mr(e){try{return JSON.parse(e)}catch(t){throw new h("PARSE",`Invalid JSON: ${t instanceof Error?t.message:String(t)}. Tip: wrap JSON in single quotes on the command line, e.g. --flag '{"k":1}'`)}}async function ft(e,t,n,r){let o=await e["~standard"].validate(t);if(o.issues)return r.push(...ut(o.issues,n)),{ok:!1};return{ok:!0,value:o.value}}async function Br(e,t){let n=[],r=new Map(Object.entries(t.args)),o=new Map(Object.entries(t.flags));for(let s of e.args){if(s.schema===void 0)continue;let i=await ft(s.schema,r.get(s.name),["args",s.name],n);if(i.ok)r.set(s.name,i.value)}for(let[s,i]of Object.entries(e.effectiveFlags)){if(i.schema===void 0)continue;let a=await ft(i.schema,o.get(s),["flags",s],n);if(a.ok)o.set(s,a.value)}if(n.length>0)throw new h("VALIDATION",`Invalid input:
4
+ `);s()}});return ct.set(n,e),n}function ye(e,t){let n=H.getStore();return we({input:n?.input,output:n?.output&&!ct.has(n.output)?n.output:hr(e)},t)}import{parseArgs as Sr}from"node:util";import{isPromise as $r}from"node:util/types";function lt(e){let t=Number(e);return Number.isNaN(t)?void 0:t}function ve(e){return e==="true"||e==="1"}import{homedir as Or}from"node:os";function br(e){return typeof e==="number"}function wr(e){return e.map((t,n)=>br(t)?`[${t}]`:n>0?`.${String(t)}`:String(t)).join("")}function yr(e){return typeof e==="object"&&e!==null&&"key"in e}function vr(e){if(!e)return[];return e.map((t)=>yr(t)?t.key:t)}function ut(e,t=[]){return e.map((n)=>{let r=vr(n.path),o=[...t,...r];return{message:n.message,path:wr(o)}})}var h=class extends Error{code;details;cause;constructor(e,t,...n){super(t);this.name="CrustError",this.code=e,this.details=n[0]}is(e){return Object.is(this.code,e)}withCause(e){return this.cause=e,this}toJSON(){return{code:this.code,message:this.message,details:this.details}}};function xe(e,t){if(e==="")throw new h("DEFINITION",`Flag ${t} spellings must be non-empty`,{subject:"flag",name:e,reason:"empty-spelling"});if(t!=="short"&&e.startsWith("no-"))throw new h("DEFINITION",`Flag ${t} "${e}" must not start with "no-"; the prefix is reserved for boolean negation`,{subject:"flag",name:e,reason:"reserved-no-prefix"});if(e==="__proto__")throw new h("DEFINITION",`Flag ${t} "__proto__" is a reserved spelling`,{subject:"flag",name:e,reason:"reserved-spelling"})}function ht(e,t){return[e,...t.short===void 0?[]:[t.short],...t.aliases??[]]}function bt(e){return e.type==="boolean"&&e.noNegate!==!0}function wt(e){if(e.choices&&e.default!==void 0){let t="multiple"in e&&e.multiple?e.default:[e.default];for(let n of t)if(!e.choices.includes(n))throw new h("DEFINITION","default must be one of choices")}return Object.freeze({...e,..."aliases"in e&&e.aliases?{aliases:Object.freeze([...e.aliases])}:{},...e.choices?{choices:Object.freeze([...e.choices])}:{},..."env"in e&&e.env?{env:Object.freeze({name:e.env.name,delimiter:e.env.delimiter})}:{},..."multiple"in e&&e.multiple&&Array.isArray(e.default)?{default:Object.freeze([...e.default])}:{}})}function Er(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)&&"name"in e&&typeof e.name==="string"&&(!("delimiter"in e)||e.delimiter===void 0||typeof e.delimiter==="string")}function yt(e,t){if(xe(e,"canonical"),t.short!==void 0)xe(t.short,"short");for(let r of t.aliases??[])xe(r,"alias");let n=ht(e,t);if(new Set(n).size!==n.length)throw new h("DEFINITION",`Flag "${e}" repeats one of its own spellings`,{subject:"flag",name:e,reason:"flag-collision"});if(t.short!==void 0&&t.short.length!==1)throw new h("DEFINITION","Short flags must be one character");if(t.env!==void 0&&!Er(t.env))throw new h("DEFINITION",`Flag "${e}" env must be an object with a string name and optional string delimiter`,{subject:"flag",name:e,reason:"invalid-env"});if(t.env?.name==="")throw new h("DEFINITION",`Flag "${e}" env variable name must be non-empty`,{subject:"flag",name:e,reason:"empty-env"});for(let[r,o]of[["delimiter",t.delimiter],["env.delimiter",t.env?.delimiter]]){if(o===void 0)continue;if(!t.multiple)throw new h("DEFINITION",`Flag "${e}" ${r} requires multiple: true`,{subject:"flag",name:e,reason:"delimiter-without-multiple"});if(o==="")throw new h("DEFINITION",`Flag "${e}" ${r} must be non-empty`,{subject:"flag",name:e,reason:"empty-delimiter"})}return wt(t)}function vt(e){if(e.name==="")throw new h("DEFINITION","Argument names must be non-empty",{subject:"argument",name:e.name,reason:"empty-name"});return wt(e)}function xt(e){return e.meta.hidden!==!0}var Ir={command:"Command",context:"Context",extension:"Extension"};function Cr({subject:e,name:t}){let n=Ir[e];return new h("DEFINITION",`${n} "${t}" contains invalid documentation sections`,{subject:e,name:t,reason:"invalid-sections"})}function St(e,t){let{title:n,body:r,only:o,except:s}=e;if(!n.trim()||/[\r\n]/.test(n)||!r.trim()||o?.length===0||s?.length===0||o!==void 0&&s!==void 0)throw Cr(t);let i=(a)=>Object.freeze(a.map((c)=>typeof c==="string"?c:c.id));return Object.freeze({title:n,body:r,...o?{only:i(o)}:s?{except:i(s)}:{}})}function _e(e,t,n="command"){return t.map((r)=>St(r,{subject:n,name:e}))}var _r=Symbol("crust.defining");function X(e){return e[_r]}var $t=Symbol.for("crust.contextSources");function Z(e,t){let n=new Set(e.map((s)=>s.name)),r=new Set,o=(s)=>{if(r.has(s))return;r.add(s);let i="contextName"in s?s.contextName:s.name;if(!n.has(i))throw new h("DEFINITION",`No provider for Context "${i}"`,{subject:"context",name:i,reason:"missing-context"});for(let a of s.use)o(a)};for(let s of t)o(s)}function jr(e){if(e===null||typeof e!=="object"&&typeof e!=="function")return!1;let t=e;return typeof t[Symbol.asyncDispose]==="function"||typeof t[Symbol.dispose]==="function"}function kr(e,t,n){if(!jr(e)||n.has(e))return;n.add(e),t.use(e)}function Nr(e,t,n,r){let o=new Map(e.map((g)=>[g.name,g])),s=new Map,i=new WeakSet,a,c=!0,l=!1;n.defer(()=>{l=!0});let u=(g,p,w=new Set)=>{if(g.name===p)return[g.name];if(w.has(g.name))return;w.add(g.name);for(let O of g.waitingOn){let x=s.get(O);if(!x)continue;let S=u(x,p,w);if(S)return[g.name,...S]}},f=(g)=>{try{let p=new Set;for(let w=g;w!=null&&!p.has(w);w=w.cause)if(p.add(w),w instanceof h&&w.code==="DEFINITION"&&w.details?.reason==="flags-before-validation")return!0;return!1}catch{return!1}};function d(g){let p=Promise.reject(g);return p.catch(()=>{}),p}let m=(g)=>(p)=>{let w=g?` (pulled while constructing Context "${g.name}")`:"";if(l)return d(new h("DEFINITION",`Context "${p}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:p,reason:"context-after-disposal"}));let O=o.get(p);if(!O)return d(new h("DEFINITION",`No provider for Context "${p}". Add .provide(${p}(...)) to the app or an ancestor command.${w}`,{subject:"context",name:p,reason:"missing-context"}));if(!c&&!s.has(p))return d(new h("DEFINITION",`Context "${p}" cannot be constructed during invocation cleanup. Read it while setting up the Context whose cleanup needs it.`,{subject:"context",name:p,reason:"context-during-disposal"}));if(a===void 0&&Object.keys(O.ownedFlags).length>0)return d(new h("DEFINITION",`Context "${p}" owns flags and cannot be pulled before flag validation${w}. Pull it from an action or a postRun hook after a validated invocation.`,{subject:"context",name:p,reason:"flags-before-validation"}));let x=s.get(p);if(!x){let S=Promise.withResolvers();S.promise.catch(()=>{}),x={name:p,promise:S.promise,resolve:S.resolve,reject:S.reject,waitingOn:new Set,settled:!1},s.set(p,x);let I=x;(async()=>{try{let j=Object.fromEntries(Object.keys(O.ownedFlags).map((_)=>[_,a?.[_]])),C=await O.setup({...t,signal:r,flags:j,ctx:b(O.use,I),defer(_){if(I.settled)throw new h("DEFINITION",`Context "${p}" cannot register cleanup after its setup has finished.`,{subject:"context",name:p,reason:"context-defer-after-setup"});n.defer(_)}});kr(C,n,i),I.resolve(C)}catch(j){if(f(j))s.delete(p);I.reject(j)}finally{I.settled=!0}})()}if(g&&!x.settled){let S=u(x,g.name);if(S)return d(new h("DEFINITION",`Context dependency cycle: ${[g.name,...S].map((I)=>`"${I}"`).join(" -> ")}`,{subject:"context",name:g.name,reason:"context-cycle"}));return g.waitingOn.add(p),x.promise.finally(()=>g.waitingOn.delete(p))}return x.promise},b=(g,p)=>{let w={},O=(x)=>{let S="contextName"in x?x.contextName:x.name;if(Object.hasOwn(w,S))return;Object.defineProperty(w,S,{enumerable:!0,get:()=>m(p)(S)});for(let I of x.use??[])O(I)};for(let x of g)O(x);return Object.defineProperty(w,$t,{value:Object.freeze([...g])}),Object.freeze(w)};return{bag:(g)=>b(g,null),setValidatedFlags(g){a=g},async settle(){for(;;){let g=[...s.values()].filter((p)=>!p.settled);if(g.length===0){c=!1;return}await Promise.allSettled(g.map((p)=>p.promise))}}}}var Ar=Object.freeze({[Symbol("crust.handled")]:!0});function Oe(){return Ar}function Ot(e){return{meta:{name:e},localFlags:{},ownedFlags:{},effectiveFlags:{},flagSpellings:new Map,args:[],subCommands:{},contexts:[],providedContexts:[],demands:[],extensions:[],run:void 0}}function F(e,t,n,r){n=yt(t,n);let o=ht(t,n),s=Object.hasOwn(e.effectiveFlags,t)?t:o.map((a)=>e.flagSpellings.get(a)?.canonicalName).find((a)=>a!==void 0);if(s!==void 0)throw new h("DEFINITION",`Flag "${t}" collides with existing flag "${s}" on command "${e.meta.name}"`,{subject:"flag",name:t,reason:"flag-collision"});(r==="local"?e.localFlags:e.ownedFlags)[t]=n,e.effectiveFlags[t]=n;let i={canonicalName:t,def:n,negatable:bt(n)};if(e.flagSpellings.set(t,{...i,kind:"canonical"}),n.short!==void 0)e.flagSpellings.set(n.short,{...i,kind:"short"});for(let a of n.aliases??[])e.flagSpellings.set(a,{...i,kind:"alias"})}function Et(e,t,n,r){if(F(e,t,n,"owned"),!r)return;for(let o of Object.values(e.subCommands))Et(o,t,n,!0)}function Tr(e,t,n){for(let r of t.commands)e.subCommands[r.name]=n(r,e,t.id)}function Fr(e,t){for(let[n,r]of Object.entries(t.flags)){let{recursive:o=!0,...s}=r;Et(e,n,s,o)}}function Q(e){return{localFlags:{...e.localFlags},ownedFlags:{...e.ownedFlags},effectiveFlags:{...e.effectiveFlags},flagSpellings:new Map(e.flagSpellings)}}function B(e){let t={};for(let[n,r]of Object.entries(e.subCommands))t[n]=B(r);return{...e,meta:{...e.meta},...Q(e),args:[...e.args],subCommands:t,contexts:e.contexts.map((n)=>({...n})),providedContexts:[...e.providedContexts],demands:[...e.demands],extensions:[...e.extensions],run:e.run}}function Pr(e,t,n){let r=e;for(let o of t){let s=Object.hasOwn(r.subCommands,o)?r.subCommands[o]:void 0;if(!s)throw new h("DEFINITION",`Extension "${n.id}" section target "${t.join(" ")}" is not a canonical command path`,{subject:"extension",name:n.id,reason:"invalid-section-path"});r=s}return r}function Rr(e,t,n){if(!t.sections)return;let r={subject:"extension",name:t.id},o=t.sections(n);for(let s of o){let i=St(s,r),a=Pr(e,s.command,t);a.meta.sections=[...a.meta.sections??[],i]}}function Dr(e,t){let n=(r,o,s)=>{let i=[...new Map(s.map((a)=>[a.name,a])).values()];if(i.some((a)=>a.sections.length>0)){let a=new Set((r.meta.sections??[]).map(({title:c})=>c));for(let c of i){for(let{title:l}of c.sections)if(a.has(l))throw new h("DEFINITION",`Context "${c.name}" section "${l}" duplicates a section on command "${o}"`,{subject:"context",name:c.name,reason:"duplicate-section"});for(let{title:l}of c.sections)a.add(l)}r.meta.sections=[...r.meta.sections??[],...i.flatMap((c)=>c.sections)]}for(let[a,c]of Object.entries(r.subCommands))n(c,`${o} ${a}`,c.providedContexts)};n(e,e.meta.name,[...e.providedContexts,...t.flatMap((r)=>r.provide)])}function It(e,t,n){let r=B(e),o=new Set(t.flatMap((i)=>!n.has(i.id)&&e.extensions.includes(i)?[i.id]:[])),s=(i)=>{i.contexts=i.contexts.filter((u)=>u.extensionId===void 0||o.has(u.extensionId));let a=Object.keys(i.effectiveFlags),c=i.localFlags,l={};for(let{instance:u}of i.contexts)Object.assign(l,u.ownedFlags);i.localFlags={},i.ownedFlags={},i.effectiveFlags={},i.flagSpellings=new Map;for(let u of a){let f=Object.hasOwn(l,u)?"owned":"local",d=f==="owned"?l:c;if(Object.hasOwn(d,u))F(i,u,d[u],f)}for(let u of Object.values(i.subCommands))s(u)};s(r);for(let i of t){if(o.has(i.id))continue;let a=i.provide;if(a.length===0)continue;let c=(l,u)=>{let f=a.filter((b)=>!u.has(b.name)),d=f.map((b)=>({instance:b,extensionId:i.id}));l.contexts.push(...d);for(let b of f)for(let[g,p]of Object.entries(b.ownedFlags))F(l,g,p,"owned");let m=new WeakSet(l.contexts.map(({instance:b})=>b));for(let b of Object.values(l.subCommands)){let g=new Set(u);for(let{instance:p}of b.contexts)if(!m.has(p))g.add(p.name);c(b,g)}};c(r,new Set)}return r}function Mr(e){try{return new URL(e)}catch{throw new h("PARSE",`Invalid URL "${e}"${/^[a-z][a-z0-9+.-]*:/i.test(e)?"":" (missing protocol — e.g. https://example.com)"}`)}}function Y(e){if(e==="")throw new h("PARSE","Path cannot be empty");let t=e.replace(/^~(?=\/|$)/,Or());return xr(process.cwd(),t)}function Br(e){try{return JSON.parse(e)}catch(t){throw new h("PARSE",`Invalid JSON: ${t instanceof Error?t.message:String(t)}. Tip: wrap JSON in single quotes on the command line, e.g. --flag '{"k":1}'`)}}async function ft(e,t,n,r){let o=await e["~standard"].validate(t);if(o.issues)return r.push(...ut(o.issues,n)),{ok:!1};return{ok:!0,value:o.value}}async function Lr(e,t){let n=[],r=new Map(Object.entries(t.args)),o=new Map(Object.entries(t.flags));for(let s of e.args){if(s.schema===void 0)continue;let i=await ft(s.schema,r.get(s.name),["args",s.name],n);if(i.ok)r.set(s.name,i.value)}for(let[s,i]of Object.entries(e.effectiveFlags)){if(i.schema===void 0)continue;let a=await ft(i.schema,o.get(s),["flags",s],n);if(a.ok)o.set(s,a.value)}if(n.length>0)throw new h("VALIDATION",`Invalid input:
5
5
  ${n.map((s)=>` - ${s.path}: ${s.message}`).join(`
6
- `)}`,{issues:n});return{args:Object.fromEntries(r),flags:Object.fromEntries(o)}}function Lr(e){let t={};for(let[n,r]of e){if(r.kind==="short")continue;let o={type:r.def.type==="boolean"?"boolean":"string"};if(r.def.multiple)o.multiple=!0;if(r.kind==="canonical"&&r.def.short)o.short=r.def.short;t[n]=o}return t}function Ct(e,t,n){if(t==="number"){let r=lt(e);if(r===void 0)throw new h("PARSE",`Expected number for ${n}, got "${e}"`);return r}if(t==="boolean")return ve(e);if(t==="url")return Dr(e);if(t==="path")return Y(e);if(t==="json")return Mr(e);return e}function je(e,t,n){if(!t.includes(e))throw new h("PARSE",`Invalid value "${e}" for ${n}. Expected one of: ${t.join(", ")}`)}function M(e,t,n,r){let o=r===void 0?n:`${n} element [${r}]`,s;try{if(s=e(t),Sr(s))throw s.catch(()=>{}),Error("parse must be synchronous")}catch(i){throw new h("PARSE",`Failed to parse ${o}: ${i instanceof Error?i.message:String(i)}`).withCause(i)}return s}function Ee(e,t){let{default:n,parse:r}=e;if(n===void 0)return;if(r){if(Array.isArray(n))return n.map((o,s)=>M(r,String(o),t,s));return M(r,String(n),t)}if(e.type==="path"){if(Array.isArray(n))return n.map((o)=>Y(String(o)));return Y(String(n))}return"multiple"in e&&e.multiple&&Array.isArray(n)?[...n]:n}function zr(e,t,n){if(n.kind==="boolean")return n.value;let r=`--${e}`,o=(s,i)=>{if(t.choices)je(s,t.choices,r);if(t.parse)return M(t.parse,s,r,i);return Ct(s,t.type,r)};return Array.isArray(n.value)?n.value.map(o):o(n.value)}function Wr(e,t){let n={};for(let r of e){if(r.kind!=="option")continue;let{canonicalName:o,def:s}=t.get(r.name),i=n[o];if(s.type==="boolean"){let a=!r.rawName.startsWith("--no-");if(s.multiple&&i?.kind==="boolean"&&Array.isArray(i.value))i.value.push(a);else n[o]={kind:"boolean",value:s.multiple?[a]:a}}else{let a=r.value;if(s.multiple&&i?.kind==="string"&&Array.isArray(i.value))i.value.push(a);else n[o]={kind:"string",value:s.multiple?[a]:a}}}return n}function _t(e,t){if(t===void 0)return[...e];return e.flatMap((n)=>n.split(t)).filter((n)=>n!=="")}function Ur(e,t,n){let r=t.multiple?_t([n],t.env?.delimiter):[n];if(t.multiple&&r.length===0)return;if(t.type!=="boolean")return{kind:"string",value:t.multiple?r:n};let o=r.map(ve);if("noNegate"in t&&t.noNegate&&o.includes(!1))throw new h("PARSE",`Flag "--${e}" does not support negation (from ${t.env?.name})`);return{kind:"boolean",value:t.multiple?o:o[0]}}function Vr(e,t,n){let r={};for(let[o,s]of Object.entries(e)){let i=Object.hasOwn(t,o)?t[o]:void 0;if(i!==void 0){if(s.delimiter!==void 0&&i.kind==="string"&&Array.isArray(i.value)){let c=_t(i.value,s.delimiter);r[o]=c.length===0?void 0:{kind:"string",value:c}}else r[o]=i;continue}if(s.env===void 0||!Object.hasOwn(n,s.env.name))continue;let a=n[s.env.name];if(a!==void 0)r[o]=Ur(o,s,a)}return r}function qr(e,t,n){let r={};for(let o of Object.keys(t))if(!Object.hasOwn(e,o)&&t[o]!==void 0)throw new h("PARSE",`Unknown flag "--${o}"`,{flag:o,reason:"unknown-flag"});for(let[o,s]of Object.entries(e)){let i=Object.hasOwn(t,o)?t[o]:void 0;if(!(i===void 0||s.multiple&&Array.isArray(i)&&i.length===0)){r[o]=n(o,s,i);continue}r[o]=Ee(s,`--${o}`)}return r}function Gr(e,t){for(let[n,r]of Object.entries(e))if(r.required===!0&&r.default===void 0){if(t[n]===void 0)throw new h("VALIDATION",`Missing required flag "--${n}"`)}}function Hr(e,t,n,r){if(e.schema)return t;if(e.choices)je(t,e.choices,n);if(e.parse)return M(e.parse,t,n,r);return Ct(t,e.type,n)}function Kr(e,t,n){let r={},o=0;for(let s of e){let{name:i}=s,a=`<${i}>`;if(Object.defineProperty(r,i,{value:void 0,writable:!0,enumerable:!0,configurable:!0}),s.variadic){let c=t.slice(o);r[i]=c.length===0&&s.default!==void 0?[Ee(s,a)]:c.map((l,u)=>n(s,l,a,u)),o=t.length}else if(o<t.length)r[i]=n(s,t[o],a),o++;else r[i]=Ee(s,a)}return{args:r,consumed:o}}function Yr(e,t){for(let n of e){if(n==="--")return;if(!n.startsWith("--no-"))continue;let r=n.indexOf("="),o=r===-1?n.slice(5):n.slice(5,r),s=t.get(o);if(!s||s.def.type!=="boolean"||s.negatable)continue;throw new h("PARSE",`Flag "--${s.canonicalName}" does not support negation ("--no-${o}")`)}}function Jr(e,t){let n=e.flagSpellings,r=Lr(n);Yr(t,n);let o;try{o=xr({args:t,options:r,strict:!0,allowPositionals:!0,allowNegative:!0,tokens:!0})}catch(c){if(c instanceof Error){let l=c.message.match(/Unknown option '(.+?)'/);if(l)throw new h("PARSE",`Unknown flag "${l[1]}"`).withCause(c);if("code"in c&&c.code==="ERR_PARSE_ARGS_INVALID_OPTION_VALUE"&&c.message.length>0)throw new h("PARSE",c.message).withCause(c)}throw new h("PARSE","Failed to parse command arguments").withCause(c)}let s=[],i=[],a=!1;for(let c of o.tokens){if(c.kind==="option-terminator"){a=!0;continue}if(c.kind==="positional")(a?s:i).push(c.value)}return{positionals:i,flagValues:Wr(o.tokens,n),rawArgs:s}}function Xr(e,t,n){let r=e.schema?e.type==="boolean"?"boolean":"string":e.type,o;if(r==="url")o=t instanceof URL;else if(r==="json"){let s=[t],i=new Set;o=!0;while(s.length>0){let a=s.pop();if(a instanceof URL){o=!1;break}if(Array.isArray(a)&&!i.has(a))i.add(a),s.push(...a)}}else o=typeof t===(r==="path"?"string":r);if(!o)throw new h("PARSE",`Expected ${r} for ${n}`);if(t===!1&&"noNegate"in e&&e.noNegate)throw new h("PARSE",`Flag "${n}" does not support negation`)}function Ie(e,t,n,r){if(Xr(e,t,n),e.choices)je(String(t),e.choices,n);if(e.parse)return M(e.parse,String(t),n,r);if(e.type==="path")return Y(String(t));return t}function Zr(e,t,n){let r=`--${e}`;if(t.multiple){if(!Array.isArray(n))throw new h("PARSE",`Expected an occurrence array for ${r}`);return n.map((o,s)=>Ie(t,o,r,s))}return Ie(t,n,r)}function jt(e,t,n,r,o){let s=qr(e.effectiveFlags,n,o);return{...Kr(e.args,t,r),flags:s}}function Qr(e,t,n=process.env){let{positionals:r,flagValues:o,rawArgs:s}=Jr(e,t),{args:i,flags:a,consumed:c}=jt(e,r,Vr(e.effectiveFlags,o,n),Hr,zr);return{args:i,flags:a,excessArgs:r.slice(c),rawArgs:s}}function eo(e,t){let{args:n,flags:r,raw:o}=t,s=[],i;for(let l of e.args){let u=n&&Object.hasOwn(n,l.name)?n[l.name]:void 0;if(u===void 0){i=l.name;continue}if(i!==void 0)throw new h("PARSE",`Argument <${l.name}> cannot be provided after omitted argument <${i}>`,{argument:l.name,reason:"positional-gap"});if(l.variadic){if(!Array.isArray(u))throw new h("PARSE",`Expected an occurrence array for <${l.name}>`);s.push(...u)}else s.push(u)}for(let l of Object.keys(n??{}))if(!e.args.some((u)=>u.name===l)&&n?.[l]!==void 0)throw new h("PARSE",`Unknown argument "${l}"`,{argument:l,reason:"unknown-argument"});let{args:a,flags:c}=jt(e,s,r??{},Ie,Zr);return{args:a,flags:c,excessArgs:[],rawArgs:[...o??[]]}}function to(e,t){let{args:n,effectiveFlags:r}=e,{args:o,flags:s}=t;if(t.excessArgs.length>0)throw new h("VALIDATION",`Unexpected positional argument${t.excessArgs.length===1?"":"s"}: ${t.excessArgs.map((i)=>JSON.stringify(i)).join(", ")}`);for(let i of n){let{name:a}=i,c=`argument "<${a}>"`,l=o[a];if(i.required===!0&&i.default===void 0){if(i.variadic){if(!Array.isArray(l)||l.length===0)throw new h("VALIDATION",`Missing required ${c}`)}else if(l===void 0)throw new h("VALIDATION",`Missing required ${c}`)}}Gr(r,s)}function J(e){for(let t of Object.keys(e))if(e[t]===void 0)delete e[t];return Object.freeze(e)}function ke(e){if(e instanceof URL)return e.href;if(Array.isArray(e))return Object.freeze(e.map(ke));return e}function no(e){return J({name:e.name,type:e.type,description:e.description,required:e.required,variadic:e.variadic,choices:e.choices?Object.freeze([...e.choices]):void 0,default:ke(e.default)})}function ro(e){return J({type:e.type,description:e.description,short:e.short,aliases:e.aliases?Object.freeze([...e.aliases]):void 0,required:e.required,multiple:e.multiple,negatable:bt(e),noNegate:"noNegate"in e?e.noNegate:void 0,choices:e.choices?Object.freeze([...e.choices]):void 0,default:ke(e.default),env:e.env?J({name:e.env.name,delimiter:e.env.delimiter}):void 0,delimiter:e.delimiter})}function k(e){let t={};for(let[r,o]of Object.entries(e.effectiveFlags))t[r]=ro(o);let n={};for(let[r,o]of Object.entries(e.subCommands))n[r]=k(o);return Object.freeze({meta:J({name:e.meta.name,description:e.meta.description,version:e.meta.version,usage:e.meta.usage,sections:e.meta.sections?Object.freeze(e.meta.sections.map((r)=>Object.freeze({...r}))):void 0,aliases:e.meta.aliases?Object.freeze([...e.meta.aliases]):void 0,hidden:e.meta.hidden}),hasAction:e.run!==void 0,args:Object.freeze(e.args.map(no)),flags:Object.freeze(t),subCommands:Object.freeze(n)})}function oo(e,t){for(let[n,r]of Object.entries(e)){let o=r.meta.aliases;if(!o)continue;if(o.includes(t))return{canonicalName:n,node:r}}return null}function dt(e,t){if(t==="--")return null;if(t.startsWith("--")){let r=t.indexOf("="),o=r===-1?t.slice(2):t.slice(2,r),s=e.get(o);if(s)return{consumesValue:s.def.type!=="boolean"&&r===-1};if(o.startsWith("no-")){if(e.get(o.slice(3))?.negatable)return{consumesValue:!1}}return null}let n=t.slice(1);if(n.length===0)return null;for(let r=0;r<n.length;r++){let o=e.get(n[r]);if(!o)return null;if(o.def.type!=="boolean")return{consumesValue:r===n.length-1}}return{consumesValue:!1}}function kt(e,t){let n=[e.meta.name],r=e,o=t,s=[],i=[],a=(c,l)=>{if(i.length===0)return;let u=c.flagSpellings;for(let{token:f,consumesValue:d}of i){let m=dt(u,f);if(m!==null&&m.consumesValue===d)continue;throw new h("PARSE",`Flag "${f}" cannot be used before subcommand "${l}" because "${l}" does not accept it.`,{flag:f,reason:"flag-not-forwardable"})}};while(o.length>0){let c=r.subCommands;if(Object.keys(c).length===0)break;let l=o[0];if(!l)break;if(l.startsWith("-")){let d=dt(r.flagSpellings,l);if(!d)break;s.push(l),i.push({token:l,consumesValue:d.consumesValue}),o=o.slice(1);let m=o[0];if(d.consumesValue&&m!==void 0)s.push(m),o=o.slice(1);continue}if(Object.hasOwn(c,l)&&c[l]){a(c[l],l),r=c[l],n.push(l),o=o.slice(1);continue}let u=oo(c,l);if(u){a(u.node,l),r=u.node,n.push(u.canonicalName),o=o.slice(1);continue}if(r.run)break;let f=k(r);throw new h("COMMAND_NOT_FOUND",`Unknown command "${l}".`,{input:l,available:Object.entries(f.subCommands).flatMap(([d,m])=>xt(m)?[d]:[]),commandPath:[...n],parentCommand:f})}return{command:r,argv:[...s,...o],commandPath:n}}var mt=()=>{};function gt(e,t){let n=()=>{if(e.listenerCount("error")===0)e.once("error",mt)};try{n(),e.write(`${t}
7
- `,(r)=>{if(r)n()})}catch{}finally{e.removeListener("error",mt)}}var so={stdout:(e)=>gt(process.stdout,e),stderr:(e)=>gt(process.stderr,e)};var D=130;function Se(e){if(!(e instanceof Error))return!1;return e.name==="AbortError"}function Nt(e){return At(e)&&"error"in e&&"suppressed"in e&&e.name==="SuppressedError"}function At(e){return typeof e==="object"&&e!==null}function Ce(e,t="Error"){let n=[],r=new Set,o=256,s=!1,i=(c)=>{if(s)return;if(o===0){s=!0,n.push("[additional failures omitted]");return}o--;let l;try{l=c()}catch{n.push("[unreadable failure]");return}a(l)},a=(c)=>{try{if(At(c)){if(r.has(c))return;r.add(c)}let l=n.length;if(Nt(c)){if(i(()=>c.error),i(()=>c.suppressed),n.length>l)return}else if(c instanceof AggregateError){let u=c.errors;if(Array.isArray(u)){for(let f=0;f<u.length;f++)if(i(()=>u[f]),s)break;if(n.length>l)return}}n.push(String(c instanceof Error&&c.message||c))}catch{n.push("[unreadable failure]")}};return i(()=>e),n.map((c)=>`${t}: ${c}`).join(`
8
- `)}function Tt(e){if(Object.freeze(e),Object.freeze(e.localFlags),Object.freeze(e.ownedFlags),Object.freeze(e.effectiveFlags),e.meta.sections)Object.freeze(e.meta.sections);Object.freeze(e.meta),Object.freeze(e.contexts),Object.freeze(e.extensions),Object.freeze(e.args);for(let t of Object.values(e.subCommands))Tt(t);Object.freeze(e.subCommands)}function io(e){return typeof e==="symbol"}var pt=new WeakMap;function ao(e,t){let n=B(e),r=Object.freeze([...e.extensions]);for(let o of r)Ar(n,o,t);for(let o of r)Tr(n,o);return{rootNode:n,extensions:r}}function co(e,t){if(Rr(e,t),t.some((n)=>n.sections!==void 0)){let n=k(e);for(let r of t)Pr(e,r,n)}return Tt(e),e}function L(e,t){let n=pt.get(e);if(n)return n;let r=ao(e,t);return co(r.rootNode,r.extensions),pt.set(e,r),r}function lo(e,t){let n=kt(e,[...t]);return{argv:t,route:n,parsed:Qr(n.command,n.argv)}}function Ne(e,t){let n=kt(e,[...t]);if(n.argv.length>0){let r=n.argv[0],o=k(n.command);throw new h("COMMAND_NOT_FOUND",`Unknown command "${r}".`,{input:r,available:Object.entries(o.subCommands).flatMap(([s,i])=>xt(i)?[s]:[]),commandPath:n.commandPath,parentCommand:o})}return n}function uo(e,t,n){let r=Ne(e,t);return{argv:t,route:r,parsed:eo(r.command,n)}}async function Ft(e,t,n,r,o,s){let I=[];try{let{rootNode:i,extensions:a}=t;let{argv:c,route:l,parsed:u}="argv"in e?lo(i,e.argv):uo(i,e.path,e.input);let f=l.command;const d=nt(I,new AsyncDisposableStack,1);let m=f.contexts.map(({instance:E})=>E);let b=kr(m,n,d,r);let g=k(i);let p=g;for(let E of l.commandPath.slice(1))p=p.subCommands[E];let w=Object.freeze({argv:[...c],rootCommand:g,command:p,commandPath:Object.freeze([...l.commandPath]),args:u.args,flags:u.flags,rawArgs:u.rawArgs,signal:r,ctx:b.bag(a.flatMap((E)=>E.use)),handled:Oe,stdout:n.stdout,stderr:n.stderr});o?.(w);let O=async()=>{to(f,u);let E=await Br(f,u);if(b.setValidatedFlags(E.flags),!f.run)return;let A={args:E.args,flags:E.flags,ctx:b.bag(m),rawArgs:u.rawArgs,signal:r,command:w.command,rootCommand:g,stdout:n.stdout,stderr:n.stderr};return await f.run(A)};let x;let S={status:"completed"};try{try{for(let T of a)if(await T.hooks?.preRun?.(w)===Oe()){S={status:"handled",by:T.id};break}if(S.status!=="handled")x=await O()}catch(T){let G=await s?.(T,w);S={status:"failed",error:T,...G===void 0?{}:{by:G}}}Object.freeze(S);let E=!1,A;for(let T of a.toReversed())try{await T.hooks?.postRun?.(w,S)}catch(G){if(S.status!=="failed"&&!E)E=!0,A=G}if(S.status==="failed")throw S.error;if(E)throw A}finally{await b.settle()}return S.status==="handled"?{status:"handled",by:S.by}:{status:"completed",result:x}}catch(j){var C=j,_=1}finally{var ge=rt(I,C,_);ge&&await ge}}async function $e(e,t,n,r,o,s,i=!1){let a=()=>{if(i)return;r.stderr(Ce(e))};function c(f){return Promise.reject(new h("DEFINITION",`Context "${String(f)}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:String(f),reason:"context-after-disposal"}))}let l=new Proxy({},{get:(f,d)=>d==="then"||io(d)?void 0:c(d)}),u=s;if(!u){let f=k(n.rootNode);u=Object.freeze({argv:[...t],rootCommand:f,command:f,commandPath:Object.freeze([n.rootNode.meta.name]),args:Object.freeze({}),flags:Object.freeze({}),rawArgs:[],signal:o,handled:Oe,stdout:r.stdout,stderr:r.stderr,ctx:l})}try{for(let f of n.extensions)if(await f.hooks?.onError?.(e,u))return f.id}catch{}a()}function fo(e){return e!==void 0&&Object.keys(e).length>0}async function Ae(e,t,n,r){let o=[],s=[];try{let{signal:i=new AbortController().signal,...a}=n??{},c={stdout(l){o.push(l),a.stdout?.(l)},stderr(l){s.push(l),a.stderr?.(l)}};return{...await ye(c,async()=>await Ft(t,L(e,r),c,i)),stdout:o.join(`
6
+ `)}`,{issues:n});return{args:Object.fromEntries(r),flags:Object.fromEntries(o)}}function zr(e){let t={};for(let[n,r]of e){if(r.kind==="short")continue;let o={type:r.def.type==="boolean"?"boolean":"string"};if(r.def.multiple)o.multiple=!0;if(r.kind==="canonical"&&r.def.short)o.short=r.def.short;t[n]=o}return t}function Ct(e,t,n){if(t==="number"){let r=lt(e);if(r===void 0)throw new h("PARSE",`Expected number for ${n}, got "${e}"`);return r}if(t==="boolean")return ve(e);if(t==="url")return Mr(e);if(t==="path")return Y(e);if(t==="json")return Br(e);return e}function je(e,t,n){if(!t.includes(e))throw new h("PARSE",`Invalid value "${e}" for ${n}. Expected one of: ${t.join(", ")}`)}function M(e,t,n,r){let o=r===void 0?n:`${n} element [${r}]`,s;try{if(s=e(t),$r(s))throw s.catch(()=>{}),Error("parse must be synchronous")}catch(i){throw new h("PARSE",`Failed to parse ${o}: ${i instanceof Error?i.message:String(i)}`).withCause(i)}return s}function Ee(e,t){let{default:n,parse:r}=e;if(n===void 0)return;if(r){if(Array.isArray(n))return n.map((o,s)=>M(r,String(o),t,s));return M(r,String(n),t)}if(e.type==="path"){if(Array.isArray(n))return n.map((o)=>Y(String(o)));return Y(String(n))}return"multiple"in e&&e.multiple&&Array.isArray(n)?[...n]:n}function Wr(e,t,n){if(n.kind==="boolean")return n.value;let r=`--${e}`,o=(s,i)=>{if(t.choices)je(s,t.choices,r);if(t.parse)return M(t.parse,s,r,i);return Ct(s,t.type,r)};return Array.isArray(n.value)?n.value.map(o):o(n.value)}function Ur(e,t){let n={};for(let r of e){if(r.kind!=="option")continue;let{canonicalName:o,def:s}=t.get(r.name),i=n[o];if(s.type==="boolean"){let a=!r.rawName.startsWith("--no-");if(s.multiple&&i?.kind==="boolean"&&Array.isArray(i.value))i.value.push(a);else n[o]={kind:"boolean",value:s.multiple?[a]:a}}else{let a=r.value;if(s.multiple&&i?.kind==="string"&&Array.isArray(i.value))i.value.push(a);else n[o]={kind:"string",value:s.multiple?[a]:a}}}return n}function _t(e,t){if(t===void 0)return[...e];return e.flatMap((n)=>n.split(t)).filter((n)=>n!=="")}function Vr(e,t,n){let r=t.multiple?_t([n],t.env?.delimiter):[n];if(t.multiple&&r.length===0)return;if(t.type!=="boolean")return{kind:"string",value:t.multiple?r:n};let o=r.map(ve);if("noNegate"in t&&t.noNegate&&o.includes(!1))throw new h("PARSE",`Flag "--${e}" does not support negation (from ${t.env?.name})`);return{kind:"boolean",value:t.multiple?o:o[0]}}function qr(e,t,n){let r={};for(let[o,s]of Object.entries(e)){let i=Object.hasOwn(t,o)?t[o]:void 0;if(i!==void 0){if(s.delimiter!==void 0&&i.kind==="string"&&Array.isArray(i.value)){let c=_t(i.value,s.delimiter);r[o]=c.length===0?void 0:{kind:"string",value:c}}else r[o]=i;continue}if(s.env===void 0||!Object.hasOwn(n,s.env.name))continue;let a=n[s.env.name];if(a!==void 0)r[o]=Vr(o,s,a)}return r}function Gr(e,t,n){let r={};for(let o of Object.keys(t))if(!Object.hasOwn(e,o)&&t[o]!==void 0)throw new h("PARSE",`Unknown flag "--${o}"`,{flag:o,reason:"unknown-flag"});for(let[o,s]of Object.entries(e)){let i=Object.hasOwn(t,o)?t[o]:void 0;if(!(i===void 0||s.multiple&&Array.isArray(i)&&i.length===0)){r[o]=n(o,s,i);continue}r[o]=Ee(s,`--${o}`)}return r}function Hr(e,t){for(let[n,r]of Object.entries(e))if(r.required===!0&&r.default===void 0){if(t[n]===void 0)throw new h("VALIDATION",`Missing required flag "--${n}"`)}}function Kr(e,t,n,r){if(e.schema)return t;if(e.choices)je(t,e.choices,n);if(e.parse)return M(e.parse,t,n,r);return Ct(t,e.type,n)}function Yr(e,t,n){let r={},o=0;for(let s of e){let{name:i}=s,a=`<${i}>`;if(Object.defineProperty(r,i,{value:void 0,writable:!0,enumerable:!0,configurable:!0}),s.variadic){let c=t.slice(o);r[i]=c.length===0&&s.default!==void 0?[Ee(s,a)]:c.map((l,u)=>n(s,l,a,u)),o=t.length}else if(o<t.length)r[i]=n(s,t[o],a),o++;else r[i]=Ee(s,a)}return{args:r,consumed:o}}function Jr(e,t){for(let n of e){if(n==="--")return;if(!n.startsWith("--no-"))continue;let r=n.indexOf("="),o=r===-1?n.slice(5):n.slice(5,r),s=t.get(o);if(!s||s.def.type!=="boolean"||s.negatable)continue;throw new h("PARSE",`Flag "--${s.canonicalName}" does not support negation ("--no-${o}")`)}}function Xr(e,t){let n=e.flagSpellings,r=zr(n);Jr(t,n);let o;try{o=Sr({args:t,options:r,strict:!0,allowPositionals:!0,allowNegative:!0,tokens:!0})}catch(c){if(c instanceof Error){let l=c.message.match(/Unknown option '(.+?)'/);if(l)throw new h("PARSE",`Unknown flag "${l[1]}"`).withCause(c);if("code"in c&&c.code==="ERR_PARSE_ARGS_INVALID_OPTION_VALUE"&&c.message.length>0)throw new h("PARSE",c.message).withCause(c)}throw new h("PARSE","Failed to parse command arguments").withCause(c)}let s=[],i=[],a=!1;for(let c of o.tokens){if(c.kind==="option-terminator"){a=!0;continue}if(c.kind==="positional")(a?s:i).push(c.value)}return{positionals:i,flagValues:Ur(o.tokens,n),rawArgs:s}}function Zr(e,t,n){let r=e.schema?e.type==="boolean"?"boolean":"string":e.type,o;if(r==="url")o=t instanceof URL;else if(r==="json"){let s=[t],i=new Set;o=!0;while(s.length>0){let a=s.pop();if(a instanceof URL){o=!1;break}if(Array.isArray(a)&&!i.has(a))i.add(a),s.push(...a)}}else o=typeof t===(r==="path"?"string":r);if(!o)throw new h("PARSE",`Expected ${r} for ${n}`);if(t===!1&&"noNegate"in e&&e.noNegate)throw new h("PARSE",`Flag "${n}" does not support negation`)}function Ie(e,t,n,r){if(Zr(e,t,n),e.choices)je(String(t),e.choices,n);if(e.parse)return M(e.parse,String(t),n,r);if(e.type==="path")return Y(String(t));return t}function Qr(e,t,n){let r=`--${e}`;if(t.multiple){if(!Array.isArray(n))throw new h("PARSE",`Expected an occurrence array for ${r}`);return n.map((o,s)=>Ie(t,o,r,s))}return Ie(t,n,r)}function jt(e,t,n,r,o){let s=Gr(e.effectiveFlags,n,o);return{...Yr(e.args,t,r),flags:s}}function eo(e,t,n=process.env){let{positionals:r,flagValues:o,rawArgs:s}=Xr(e,t),{args:i,flags:a,consumed:c}=jt(e,r,qr(e.effectiveFlags,o,n),Kr,Wr);return{args:i,flags:a,excessArgs:r.slice(c),rawArgs:s}}function to(e,t){let{args:n,flags:r,raw:o}=t,s=[],i;for(let l of e.args){let u=n&&Object.hasOwn(n,l.name)?n[l.name]:void 0;if(u===void 0){i=l.name;continue}if(i!==void 0)throw new h("PARSE",`Argument <${l.name}> cannot be provided after omitted argument <${i}>`,{argument:l.name,reason:"positional-gap"});if(l.variadic){if(!Array.isArray(u))throw new h("PARSE",`Expected an occurrence array for <${l.name}>`);s.push(...u)}else s.push(u)}for(let l of Object.keys(n??{}))if(!e.args.some((u)=>u.name===l)&&n?.[l]!==void 0)throw new h("PARSE",`Unknown argument "${l}"`,{argument:l,reason:"unknown-argument"});let{args:a,flags:c}=jt(e,s,r??{},Ie,Qr);return{args:a,flags:c,excessArgs:[],rawArgs:[...o??[]]}}function no(e,t){let{args:n,effectiveFlags:r}=e,{args:o,flags:s}=t;if(t.excessArgs.length>0)throw new h("VALIDATION",`Unexpected positional argument${t.excessArgs.length===1?"":"s"}: ${t.excessArgs.map((i)=>JSON.stringify(i)).join(", ")}`);for(let i of n){let{name:a}=i,c=`argument "<${a}>"`,l=o[a];if(i.required===!0&&i.default===void 0){if(i.variadic){if(!Array.isArray(l)||l.length===0)throw new h("VALIDATION",`Missing required ${c}`)}else if(l===void 0)throw new h("VALIDATION",`Missing required ${c}`)}}Hr(r,s)}function J(e){for(let t of Object.keys(e))if(e[t]===void 0)delete e[t];return Object.freeze(e)}function ke(e){if(e instanceof URL)return e.href;if(Array.isArray(e))return Object.freeze(e.map(ke));return e}function ro(e){return J({name:e.name,type:e.type,description:e.description,required:e.required,variadic:e.variadic,choices:e.choices?Object.freeze([...e.choices]):void 0,default:ke(e.default)})}function oo(e){return J({type:e.type,description:e.description,short:e.short,aliases:e.aliases?Object.freeze([...e.aliases]):void 0,required:e.required,multiple:e.multiple,negatable:bt(e),noNegate:"noNegate"in e?e.noNegate:void 0,choices:e.choices?Object.freeze([...e.choices]):void 0,default:ke(e.default),env:e.env?J({name:e.env.name,delimiter:e.env.delimiter}):void 0,delimiter:e.delimiter})}function k(e){let t={};for(let[r,o]of Object.entries(e.effectiveFlags))t[r]=oo(o);let n={};for(let[r,o]of Object.entries(e.subCommands))n[r]=k(o);return Object.freeze({meta:J({name:e.meta.name,description:e.meta.description,version:e.meta.version,usage:e.meta.usage,sections:e.meta.sections?Object.freeze(e.meta.sections.map((r)=>Object.freeze({...r}))):void 0,aliases:e.meta.aliases?Object.freeze([...e.meta.aliases]):void 0,hidden:e.meta.hidden}),hasAction:e.run!==void 0,args:Object.freeze(e.args.map(ro)),flags:Object.freeze(t),subCommands:Object.freeze(n)})}function so(e,t){for(let[n,r]of Object.entries(e)){let o=r.meta.aliases;if(!o)continue;if(o.includes(t))return{canonicalName:n,node:r}}return null}function dt(e,t){if(t==="--")return null;if(t.startsWith("--")){let r=t.indexOf("="),o=r===-1?t.slice(2):t.slice(2,r),s=e.get(o);if(s)return{consumesValue:s.def.type!=="boolean"&&r===-1};if(o.startsWith("no-")){if(e.get(o.slice(3))?.negatable)return{consumesValue:!1}}return null}let n=t.slice(1);if(n.length===0)return null;for(let r=0;r<n.length;r++){let o=e.get(n[r]);if(!o)return null;if(o.def.type!=="boolean")return{consumesValue:r===n.length-1}}return{consumesValue:!1}}function kt(e,t){let n=[e.meta.name],r=e,o=t,s=[],i=[],a=(c,l)=>{if(i.length===0)return;let u=c.flagSpellings;for(let{token:f,consumesValue:d}of i){let m=dt(u,f);if(m!==null&&m.consumesValue===d)continue;throw new h("PARSE",`Flag "${f}" cannot be used before subcommand "${l}" because "${l}" does not accept it.`,{flag:f,reason:"flag-not-forwardable"})}};while(o.length>0){let c=r.subCommands;if(Object.keys(c).length===0)break;let l=o[0];if(!l)break;if(l.startsWith("-")){let d=dt(r.flagSpellings,l);if(!d)break;s.push(l),i.push({token:l,consumesValue:d.consumesValue}),o=o.slice(1);let m=o[0];if(d.consumesValue&&m!==void 0)s.push(m),o=o.slice(1);continue}if(Object.hasOwn(c,l)&&c[l]){a(c[l],l),r=c[l],n.push(l),o=o.slice(1);continue}let u=so(c,l);if(u){a(u.node,l),r=u.node,n.push(u.canonicalName),o=o.slice(1);continue}if(r.run)break;let f=k(r);throw new h("COMMAND_NOT_FOUND",`Unknown command "${l}".`,{input:l,available:Object.entries(f.subCommands).flatMap(([d,m])=>xt(m)?[d]:[]),commandPath:[...n],parentCommand:f})}return{command:r,argv:[...s,...o],commandPath:n}}var mt=()=>{};function gt(e,t){let n=()=>{if(e.listenerCount("error")===0)e.once("error",mt)};try{n(),e.write(`${t}
7
+ `,(r)=>{if(r)n()})}catch{}finally{e.removeListener("error",mt)}}var io={stdout:(e)=>gt(process.stdout,e),stderr:(e)=>gt(process.stderr,e)};var D=130;function Se(e){if(!(e instanceof Error))return!1;return e.name==="AbortError"}function Nt(e){return At(e)&&"error"in e&&"suppressed"in e&&e.name==="SuppressedError"}function At(e){return typeof e==="object"&&e!==null}function Ce(e,t="Error"){let n=[],r=new Set,o=256,s=!1,i=(c)=>{if(s)return;if(o===0){s=!0,n.push("[additional failures omitted]");return}o--;let l;try{l=c()}catch{n.push("[unreadable failure]");return}a(l)},a=(c)=>{try{if(At(c)){if(r.has(c))return;r.add(c)}let l=n.length;if(Nt(c)){if(i(()=>c.error),i(()=>c.suppressed),n.length>l)return}else if(c instanceof AggregateError){let u=c.errors;if(Array.isArray(u)){for(let f=0;f<u.length;f++)if(i(()=>u[f]),s)break;if(n.length>l)return}}n.push(String(c instanceof Error&&c.message||c))}catch{n.push("[unreadable failure]")}};return i(()=>e),n.map((c)=>`${t}: ${c}`).join(`
8
+ `)}function Tt(e){if(Object.freeze(e),Object.freeze(e.localFlags),Object.freeze(e.ownedFlags),Object.freeze(e.effectiveFlags),e.meta.sections)Object.freeze(e.meta.sections);Object.freeze(e.meta),Object.freeze(e.contexts),Object.freeze(e.extensions),Object.freeze(e.args);for(let t of Object.values(e.subCommands))Tt(t);Object.freeze(e.subCommands)}function ao(e){return typeof e==="symbol"}var pt=new WeakMap;function co(e,t){let n=B(e),r=Object.freeze([...e.extensions]);for(let o of r)Tr(n,o,t);for(let o of r)Fr(n,o);return{rootNode:n,extensions:r}}function lo(e,t){if(Dr(e,t),t.some((n)=>n.sections!==void 0)){let n=k(e);for(let r of t)Rr(e,r,n)}return Tt(e),e}function L(e,t){let n=pt.get(e);if(n)return n;let r=co(e,t);return lo(r.rootNode,r.extensions),pt.set(e,r),r}function uo(e,t){let n=kt(e,[...t]);return{argv:t,route:n,parsed:eo(n.command,n.argv)}}function Ne(e,t){let n=kt(e,[...t]);if(n.argv.length>0){let r=n.argv[0],o=k(n.command);throw new h("COMMAND_NOT_FOUND",`Unknown command "${r}".`,{input:r,available:Object.entries(o.subCommands).flatMap(([s,i])=>xt(i)?[s]:[]),commandPath:n.commandPath,parentCommand:o})}return n}function fo(e,t,n){let r=Ne(e,t);return{argv:t,route:r,parsed:to(r.command,n)}}async function Ft(e,t,n,r,o,s){let I=[];try{let{rootNode:i,extensions:a}=t;let{argv:c,route:l,parsed:u}="argv"in e?uo(i,e.argv):fo(i,e.path,e.input);let f=l.command;const d=nt(I,new AsyncDisposableStack,1);let m=f.contexts.map(({instance:E})=>E);let b=Nr(m,n,d,r);let g=k(i);let p=g;for(let E of l.commandPath.slice(1))p=p.subCommands[E];let w=Object.freeze({argv:[...c],rootCommand:g,command:p,commandPath:Object.freeze([...l.commandPath]),args:u.args,flags:u.flags,rawArgs:u.rawArgs,signal:r,ctx:b.bag(a.flatMap((E)=>E.use)),handled:Oe,stdout:n.stdout,stderr:n.stderr});o?.(w);let O=async()=>{no(f,u);let E=await Lr(f,u);if(b.setValidatedFlags(E.flags),!f.run)return;let A={args:E.args,flags:E.flags,ctx:b.bag(m),rawArgs:u.rawArgs,signal:r,command:w.command,rootCommand:g,stdout:n.stdout,stderr:n.stderr};return await f.run(A)};let x;let S={status:"completed"};try{try{for(let T of a)if(await T.hooks?.preRun?.(w)===Oe()){S={status:"handled",by:T.id};break}if(S.status!=="handled")x=await O()}catch(T){let G=await s?.(T,w);S={status:"failed",error:T,...G===void 0?{}:{by:G}}}Object.freeze(S);let E=!1,A;for(let T of a.toReversed())try{await T.hooks?.postRun?.(w,S)}catch(G){if(S.status!=="failed"&&!E)E=!0,A=G}if(S.status==="failed")throw S.error;if(E)throw A}finally{await b.settle()}return S.status==="handled"?{status:"handled",by:S.by}:{status:"completed",result:x}}catch(j){var C=j,_=1}finally{var ge=rt(I,C,_);ge&&await ge}}async function $e(e,t,n,r,o,s,i=!1){let a=()=>{if(i)return;r.stderr(Ce(e))};function c(f){return Promise.reject(new h("DEFINITION",`Context "${String(f)}" cannot be pulled from onError because invocation Contexts have already been disposed.`,{subject:"context",name:String(f),reason:"context-after-disposal"}))}let l=new Proxy({},{get:(f,d)=>d==="then"||ao(d)?void 0:c(d)}),u=s;if(!u){let f=k(n.rootNode);u=Object.freeze({argv:[...t],rootCommand:f,command:f,commandPath:Object.freeze([n.rootNode.meta.name]),args:Object.freeze({}),flags:Object.freeze({}),rawArgs:[],signal:o,handled:Oe,stdout:r.stdout,stderr:r.stderr,ctx:l})}try{for(let f of n.extensions)if(await f.hooks?.onError?.(e,u))return f.id}catch{}a()}function mo(e){return e!==void 0&&Object.keys(e).length>0}async function Ae(e,t,n,r){let o=[],s=[];try{let{signal:i=new AbortController().signal,...a}=n??{},c={stdout(l){o.push(l),a.stdout?.(l)},stderr(l){s.push(l),a.stderr?.(l)}};return{...await ye(c,async()=>await Ft(t,L(e,r),c,i)),stdout:o.join(`
9
9
  `),stderr:s.join(`
10
10
  `)}}catch(i){return{status:"failed",error:i,stdout:o.join(`
11
11
  `),stderr:s.join(`
12
- `)}}}async function Pt(e,t,n){let r=t?.argv??process.argv.slice(2),o={...so,...t?.io},s=new AbortController,i=t?.signal?AbortSignal.any([t.signal,s.signal]):s.signal;if(!he());let a=async()=>{let c;try{c=L(e,n)}catch(m){if(Se(m))return process.exitCode=D,D;return o.stderr(Ce(m)),process.exitCode=1,1}let l=()=>{if(!s.signal.aborted){s.abort(new DOMException("Interrupted by SIGINT.","AbortError"));return}if(process.removeListener("SIGINT",l),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")};process.on("SIGINT",l);let u,f=!1,d;try{await Ft({argv:r},c,o,i,(m)=>{u=m},async(m,b)=>{f=!0,d=m;let g=Se(m);return process.exitCode=g?D:1,$e(m,r,c,o,i,b,g)})}catch(m){let b;try{if(f&&!Object.is(m,d)&&Nt(m)&&Object.is(m.suppressed,d))b={error:m.error}}catch{}if(b)o.stderr(Ce(b.error,"Cleanup failed"));if(Se(m)){if(!f)await $e(m,r,c,o,i,u,!0);return process.exitCode=D,D}if(process.exitCode=1,!f)await $e(m,r,c,o,i,u);return 1}finally{process.removeListener("SIGINT",l)}return 0};return await(fo(t?.io)?ye(o,a):a())}var Fe=Symbol.for("crust.commandDefinition");function P(e,t,n){let r=e[Fe],o=e.name,s=n?`Extension "${n}" command "${o}"`:`Command "${o}"`,i=(u)=>({subject:n?"extension":"command",name:n??o,reason:u}),a=new ee(o);for(let[u,f]of Object.entries(t.ownedFlags))F(a._node,u,f,"owned");a._node.contexts=t.contexts.map((u)=>({...u}));let c=r.recipe(a);if(!(c instanceof ee)||c._ancestorOwnedFlags!==a._ancestorOwnedFlags)throw new h("DEFINITION",`${s} definition must return the same command builder it received`,i("foreign-command-builder"));if(c._node.extensions.length>0)throw new h("DEFINITION",`${s} cannot register Extensions inside command definitions`,i("nested-command-extension"));let l=B(c._node);return Z(l.contexts.map(({instance:u})=>u),l.demands),l.meta={name:o,...r.meta},l}function Te(e,t=[]){if(e.trim()==="")throw new h("DEFINITION","Command name must be a non-empty string",{subject:"command",name:e,reason:"empty-name"});if(e==="__proto__")throw new h("DEFINITION",'Command name "__proto__" is reserved',{subject:"command",name:e,reason:"reserved-name"});if(t.includes(e))throw new h("DEFINITION",`Command "${e}" must not list its own canonical name as an alias`,{subject:"command",name:e,reason:"alias-collision"});return e}function mo(e){return typeof e==="function"}function go(e,t,n){let r=!mo(t),o=r?t:{},s=r?n:t,i=Te(e,o.aliases);for(let m of o.aliases??[])if(m===""||/[ \t\n\r\v\f]/.test(m)||m.startsWith("-"))throw new h("DEFINITION",`Command "${i}" has an invalid alias "${m}"`);let{sections:a,version:c,...l}=o,u={...l,...o.aliases?{aliases:[...o.aliases]}:{},...a?{sections:_e(i,a)}:{}},f={name:i,recipe:s,meta:u},d=(m)=>Object.freeze({name:m,as:(b)=>d(Te(b,u.aliases)),[Fe]:Object.freeze({...f,name:m})});return d(i)}function po(e){return e.filter((t,n)=>e.findLastIndex((r)=>r.id===t.id)===n)}var ee=class{_node;_ancestorOwnedFlags;constructor(e,...t){let n=t[0]??{},r=Te(e);if(this._node=Ot(r),n.description!==void 0)this._node.meta.description=n.description;if(n.version!==void 0)this._node.meta.version=n.version;if(n.usage!==void 0)this._node.meta.usage=n.usage;if(n.sections!==void 0)this._node.meta.sections=_e(r,n.sections);this._ancestorOwnedFlags={}}_clone(e){let t=Object.create(Object.getPrototypeOf(this));return t._node={...this._node,...e},t._ancestorOwnedFlags=this._ancestorOwnedFlags,t}flags(...e){let t=this._clone(Q(this._node));for(let n of e){let{name:r,...o}=n;F(t._node,r,o,"local")}return t}args(...e){let t=[...this._node.args,...e.map(vt)],n=new Set;for(let[r,o]of t.entries()){if(n.has(o.name))throw new h("DEFINITION",`Argument name "${o.name}" is already defined`,{subject:"argument",name:o.name,reason:"duplicate-arg"});if(n.add(o.name),o.variadic===!0&&r!==t.length-1)throw new h("DEFINITION",`Only the last positional argument can be variadic; "${o.name}" is not last`,{subject:"argument",name:o.name,reason:"variadic-position"})}return this._clone({args:t})}use(...e){return this._clone({demands:[...this._node.demands,...e.map(X)]})}provide(...e){let t=e.map(X);Z([...this._node.contexts.map(({instance:r})=>r),...t],t);let n=this._clone({...Q(this._node),contexts:[...this._node.contexts,...t.map((r)=>({instance:r}))],providedContexts:[...this._node.providedContexts,...t]});for(let r of t)for(let[o,s]of Object.entries(r.ownedFlags))F(n._node,o,s,"owned");return n}action(e){return this._clone({run:e})}extend(...e){let t=e.map(X),n=po([...this._node.extensions,...t]),r=It(this._node,n,new Set(t.map((o)=>o.id)));return Z(r.contexts.map(({instance:o})=>o),n.flatMap((o)=>[...o.use,...o.provide])),this._clone({...r,extensions:n})}add(...e){return this._addDefinitions(e)}command(e,t){let n=go(e,t);return this._addDefinitions([n])}_addDefinitions(e){let t={...this._node.subCommands};for(let n of e){let r=[n.name,...n[Fe].meta.aliases??[]];for(let s of Object.values(t))if([s.meta.name,...s.meta.aliases??[]].some((i)=>r.includes(i)))throw new h("DEFINITION",`Command name "${n.name}" is already registered on this command`,{subject:"command",name:n.name,reason:"command-collision"});let o=P(n,this._node);t[n.name]=o}return this._clone({subCommands:t})}async snapshot(){return k(L(this._node,P).rootNode)}async run(e,...t){let n=t[0]??{},r=t[1];return await Ae(this._node,{path:e,input:n},r,P)}at(e){Ne(L(this._node,P).rootNode,e);let t=this._node,n=Object.freeze([...e]);return{path:n,async run(...r){let o=r[0]??{},s=r[1];return await Ae(t,{path:n,input:o},s,P)}}}async execute(e){return await Pt(this._node,e,P)}};import{existsSync as Me,lstatSync as Ht,mkdirSync as Ut,readFileSync as Ao,readdirSync as Kt,realpathSync as De,statSync as Yt,writeFileSync as To}from"node:fs";import{dirname as Jt,join as R,resolve as Vt,sep as Fo}from"node:path";import{fileURLToPath as Po}from"node:url";function Rt(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}import{isAbsolute as ho,relative as bo,sep as wo}from"node:path";function Dt(e,t){let n=bo(e,t);return n===""||!ho(n)&&n!==".."&&!n.startsWith(`..${wo}`)}import{spawn as Ro,spawnSync as Do}from"node:child_process";import{once as Mo}from"node:events";import{accessSync as Mt,constants as Bt,statSync as Lt}from"node:fs";import{delimiter as yo,extname as vo,join as xo,resolve as So,sep as $o,win32 as Oo}from"node:path";import{spawn as Eo,spawnSync as Io}from"node:child_process";import{once as Co}from"node:events";import{text as zt}from"node:stream/consumers";function Wt(e){if(e?.startsWith("bun"))return"bun";if(e?.startsWith("pnpm"))return"pnpm";if(e?.startsWith("yarn"))return"yarn";if(e?.startsWith("npm"))return"npm";return null}var _o=/[\0\r\n"%!^`<>&|]/,Pe=/([()\][%!^"`<>&|;, *?])/g;function jo(e){let t=e.replace(/(?=(\\+?)?)\1"/g,"$1$1\\\"");return t=t.replace(/(?=(\\+?)?)\1$/g,"$1$1"),t=`"${t}"`.replace(Pe,"^$1"),t.replace(Pe,"^$1")}function ko(e,t,n,r=process.platform){if(n||r!=="win32"||!/\.(cmd|bat)$/i.test(e))return null;let o=Oo.normalize(e);for(let[i,a]of[o,...t].entries())if(_o.test(a)){let c=i===0?"command":`argument ${i}`;throw Error(`Windows command shim ${c} ${JSON.stringify(a)} contains unsafe shell characters`)}let s=[o.replace(Pe,"^$1"),...t.map(jo)].join(" ");return{command:process.env.ComSpec??"cmd.exe",args:["/d","/s","/c",`"${s}"`],windowsVerbatimArguments:!0}}function No(e){if(e.pid===void 0)return;if(process.platform==="win32"){if(e.exitCode===null&&e.signalCode===null){let t=Io("taskkill",["/pid",String(e.pid),"/T","/F"],{stdio:"ignore",timeout:1e4});if(t.error||t.status!==0)e.kill("SIGKILL")}return}try{process.kill(-e.pid,"SIGKILL")}catch(t){if(t.code==="ESRCH")return;throw e.kill("SIGKILL"),t}}async function z(e,t=[],n={}){let r=ko(e,t,n.shell),o=(n.stdio??"collect")==="collect",s=o&&n.stdout!=="ignore",i=Eo(r?.command??e,r?.args??t,{cwd:n.cwd,env:n.env,shell:n.shell,stdio:o?["ignore",s?"pipe":"ignore","pipe"]:"inherit",detached:n.timeout!==void 0&&process.platform!=="win32",windowsVerbatimArguments:r?.windowsVerbatimArguments}),a,c=new Promise((l,u)=>{if(n.timeout===void 0)return;let f=n.timeout;a=setTimeout(()=>{let d=Error(`${[e,...t].join(" ")} did not exit within ${f} ms and was killed.`);try{No(i)}catch(m){d=Error("Process-tree cleanup failed after timeout.",{cause:m})}i.stdout?.destroy(),i.stderr?.destroy(),u(d)},f)});try{let[l,u,[f]]=await Promise.race([Promise.all([s?zt(i.stdout):"",o?zt(i.stderr):"",Co(i,"close")]),c]);return{exitCode:f,stdout:l,stderr:u}}finally{clearTimeout(a)}}function Re(e){if(e.includes($o)||e.includes("/")){try{if(Mt(e,Bt.X_OK),Lt(e).isFile())return e}catch{}return null}let t=process.platform==="win32"&&!vo(e)?(process.env.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";"):[""];for(let n of process.env.PATH?.split(yo)??[])for(let r of t){let o=So(xo(n,e+r));try{if(Mt(o,Bt.X_OK),Lt(o).isFile())return o}catch{}}return null}function Bo(e,t){return e.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,r)=>Object.hasOwn(t,r)?t[r]??n:n)}function Lo(e){let t=Jt(e),n=e.slice(t==="."?0:t.length+1);if(n.startsWith("_")&&!n.startsWith("__")){let r=`.${n.slice(1)}`;return t==="."?r:R(t,r)}return e}function zo(e){if(!Me(e))return!1;if(!Yt(e).isDirectory())return!1;return Kt(e).length>0}function qt(e,t){if(De(e)!==e)throw Error(`Destination root "${e}" was redirected outside the destination.`);let n=e;for(let r of t.split(Fo)){n=R(n,r);let o;try{o=Ht(n).isSymbolicLink()}catch(i){if(Rt(i)&&i.code==="ENOENT")return;throw i}if(!o)continue;let s;try{s=De(n)}catch{}if(s===void 0||!Dt(e,s))throw Error(`Destination path "${n}" is a symlink${s===void 0?" to a missing target":` to "${s}"`} outside the destination "${e}". Remove the link or choose another destination.`)}}async function Xt(e){let{template:t,dest:n,context:r,conflict:o="abort",render:s=Bo}=e,i=t instanceof URL?Po(t):Vt(t),a=Vt(n);if(!Me(i))throw Error(`Template directory "${i}" does not exist (from template: "${String(t)}").`);if(!Yt(i).isDirectory())throw Error(`Template path "${i}" is not a directory (from template: "${String(t)}").`);if(o==="abort"&&zo(a))throw Error(`Destination directory "${a}" already exists and is non-empty. Use conflict: "overwrite" to proceed.`);let c=Kt(i,{recursive:!0,encoding:"utf8"}).filter((d)=>Ht(R(i,d)).isFile());Ut(a,{recursive:!0});let l=De(a),u=c.map((d)=>({relFromTemplate:d,destRelPath:Lo(d)}));for(let{destRelPath:d}of u)qt(l,d);let f=[];for(let{relFromTemplate:d,destRelPath:m}of u){let b=R(i,d),g=R(l,m),p=Ao(b),w=p.subarray(0,8192).includes(0)?p:await s(p.toString("utf-8"),r);qt(l,m),Ut(Jt(g),{recursive:!0}),To(g,w,"utf-8"),f.push(m)}return{files:f}}var Wo=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];function Be(e){let t=e??process.cwd();for(let[n,r]of Wo)if(Me(R(t,n)))return r;return Wt(process.env.npm_config_user_agent)??"npm"}function Zt(e){try{return Do("git",["rev-parse","--is-inside-work-tree"],{cwd:e??process.cwd(),stdio:"ignore"}).status===0}catch{return!1}}async function Le(e,t){for(let n of e)switch(n.type){case"install":await Uo(t);break;case"git-init":await Vo(t,n.commit);break;case"open-editor":await qo(t);break;case"command":await Go(n.cmd,n.cwd??t)}}async function Uo(e){let t=Be(e),n=Re(t);if(!n)throw Error(`Package manager "${t}" was not found on PATH. Install ${t} and try again.`);let{exitCode:r}=await z(n,["install"],{cwd:e,stdio:"inherit"});if(r!==0)throw Error(`"${t} install" exited with code ${r}`)}async function Vo(e,t){let n=Re("git");if(!n)throw Error('"git" was not found on PATH. Install Git and try again.');if(await W([n,"init"],e,"git init"),t)await Ho(e,n),await W([n,"add","."],e,"git add"),await W([n,"commit","-m",t],e,"git commit")}async function qo(e){let t=process.env.EDITOR||"code";try{let n=Ro(t,[e],{stdio:"ignore",shell:process.platform==="win32"});n.unref();let r=await Promise.race([Mo(n,"close").then(([o])=>({kind:"exited",code:o})),new Promise((o)=>setTimeout(()=>o({kind:"timeout"}),500))]);if(r.kind==="exited"&&r.code!==0)console.warn(`Warning: could not open editor "${t}" (exit code ${r.code})`)}catch{console.warn(`Warning: could not open editor "${t}"`)}}async function Go(e,t){let{exitCode:n}=await z(e,[],{cwd:t,shell:!0,stdio:"inherit"});if(n!==0)throw Error(`Command "${e}" exited with code ${n}`)}async function Ho(e,t){let n=await Gt(t,"user.name",e)===0,r=await Gt(t,"user.email",e)===0;if(!n)await W([t,"config","user.name","Crust"],e,"git config user.name");if(!r)await W([t,"config","user.email","crust@scaffolded.project"],e,"git config user.email")}async function Gt(e,t,n){let{exitCode:r}=await z(e,["config",t],{cwd:n,stdio:"collect",stdout:"ignore"});return r}async function W(e,t,n){let{exitCode:r,stderr:o}=await z(e[0],e.slice(1),{cwd:t,stdio:"collect",stdout:"ignore"});if(r!==0)throw Error(`"${n}" failed with exit code ${r}${o?`: ${o.trim()}`:""}`)}var Qt=Object.defineProperty,Ko=(e,t)=>{let n={};for(var r in e)Qt(n,r,{get:e[r],enumerable:!0});if(!t)Qt(n,Symbol.toStringTag,{value:"Module"});return n},Yo=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Jo=/[\p{Cc}\p{Cf}\p{Mn}\p{Me}]/u,Xo=/\p{Emoji_Presentation}|\p{Emoji}\uFE0F/u,Zo=new RegExp([String.raw`(?:\x1b\[|\x9b)[^\x1b\x18\x1a\x9c\x40-\x7e]*[\x40-\x7e\x18\x1a\x9c]?`,String.raw`(?:\x1b\]|\x9d)[^\x07\x1b\x18\x1a\x9c]*(?:\x07|\x1b\\|[\x18\x1a\x9c])?`,String.raw`(?:\x1b[PX^_]|[\x90\x98\x9e\x9f])[^\x1b\x18\x1a\x9c]*(?:\x1b\\|[\x18\x1a\x9c])?`,String.raw`\x1b[\x20-\x2f][^\x1b]?`,String.raw`\x1b[\x18\x1a\x9c\x30-\x7e]?`].join("|"),"g");function Qo(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=94176&&e<=111355||e>=127488&&e<=127743||e>=131072&&e<=262141)}function es(e){return Jo.test(String.fromCodePoint(e))||e>=4448&&e<=4607||e>=55216&&e<=55295}function ts(e){if(!/[^\x20-\x7e]/.test(e))return e.length;let t=0;for(let{segment:n}of Yo.segment(e.replace(Zo,""))){if(Xo.test(n)){let r=n.codePointAt(0);t+=n.length===2&&r>=127462&&r<=127487?1:2;continue}for(let r of n){let o=r.codePointAt(0);if(es(o))continue;t+=Qo(o)?2:1;break}}return t}function rn(e){return globalThis.Bun?.stringWidth(e,{countAnsiEscapeCodes:!1})??ts(e)}var ns=Ko({bgBlack:()=>Is,bgBlue:()=>ks,bgBrightBlack:()=>Fs,bgBrightBlue:()=>Ms,bgBrightCyan:()=>Ls,bgBrightGreen:()=>Rs,bgBrightMagenta:()=>Bs,bgBrightRed:()=>Ps,bgBrightWhite:()=>zs,bgBrightYellow:()=>Ds,bgCyan:()=>As,bgGreen:()=>_s,bgMagenta:()=>Ns,bgRed:()=>Cs,bgWhite:()=>Ts,bgYellow:()=>js,black:()=>us,blue:()=>gs,bold:()=>rs,brightBlue:()=>Ss,brightCyan:()=>Os,brightGreen:()=>vs,brightMagenta:()=>$s,brightRed:()=>ys,brightWhite:()=>Es,brightYellow:()=>xs,cyan:()=>hs,dim:()=>os,gray:()=>ws,green:()=>ds,hidden:()=>cs,inverse:()=>as,isModifierName:()=>on,italic:()=>ss,magenta:()=>ps,red:()=>fs,strikethrough:()=>ls,styleMethodNames:()=>ze,underline:()=>is,white:()=>bs,yellow:()=>ms});function v(e,t){return{open:`\x1B[${e}m`,close:`\x1B[${t}m`}}var rs=v(1,22),os=v(2,22),ss=v(3,23),is=v(4,24),as=v(7,27),cs=v(8,28),ls=v(9,29),us=v(30,39),fs=v(31,39),ds=v(32,39),ms=v(33,39),gs=v(34,39),ps=v(35,39),hs=v(36,39),bs=v(37,39),ws=v(90,39),ys=v(91,39),vs=v(92,39),xs=v(93,39),Ss=v(94,39),$s=v(95,39),Os=v(96,39),Es=v(97,39),Is=v(40,49),Cs=v(41,49),_s=v(42,49),js=v(43,49),ks=v(44,49),Ns=v(45,49),As=v(46,49),Ts=v(47,49),Fs=v(100,49),Ps=v(101,49),Rs=v(102,49),Ds=v(103,49),Ms=v(104,49),Bs=v(105,49),Ls=v(106,49),zs=v(107,49),ze=Object.freeze(["bold","dim","italic","underline","inverse","hidden","strikethrough","black","red","green","yellow","blue","magenta","cyan","white","gray","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite","bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgBrightBlack","bgBrightRed","bgBrightGreen","bgBrightYellow","bgBrightBlue","bgBrightMagenta","bgBrightCyan","bgBrightWhite"]),Ws=new Set(["bold","dim","italic","underline","inverse","hidden","strikethrough"]);function on(e){return Ws.has(e)}function U(e,t,n){return e!==void 0&&t in e?e[t]:n}function sn(e){return U(e,"isTTY",process.stdout?.isTTY)??!1}function an(e){return U(e,"forceColor",process.env.FORCE_COLOR)}function cn(e){return e==="0"||e==="false"}function Us(e){let t=e.toLowerCase();return t.includes("24bit")||t.includes("truecolor")||t.endsWith("-direct")}function ln(e,t){if(e!==void 0){let n=e.toLowerCase();if(n==="truecolor"||n==="24bit")return!0}return t!==void 0&&Us(t)}function en(e,t){if(ln(e,t))return"truecolor";if(t!==void 0&&t.toLowerCase().includes("256color"))return"256";return"16"}function Vs(e,t){if(e==="never")return"none";if(e==="always")return"truecolor";let n=U(t,"colorTerm",process.env.COLORTERM),r=U(t,"term",process.env.TERM),o=an(t);if(o!==void 0){if(cn(o))return"none";if(o==="1")return"16";if(o==="2")return"256";if(o==="3")return"truecolor";return en(n,r)}if(!sn(t))return"none";let s=U(t,"noColor",process.env.NO_COLOR);if(s!==void 0&&s!=="")return"none";if(r!==void 0&&r.toLowerCase()==="dumb"&&!ln(n,r))return"none";return en(n,r)}function qs(e,t){if(e==="always")return!0;if(e==="never")return!1;let n=an(t);if(n!==void 0)return!cn(n);return sn(t)}var un={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};function We(e,t){if(e==null)return"";let n=String(e);if(n==="")return"";let{open:r,close:o}=t;if(n.includes(o))n=n.replaceAll(o,o+r);return r+n+o}var Gs="\x1B[39m",Hs="\x1B[49m",Ks="\x1B[38;",Ys="\x1B[48;";function Js(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function Xs(e){return Object.hasOwn(un,e)}function Ue(e){if(Array.isArray(e)){if(e.length===3&&e.every((t)=>Number.isInteger(t)&&t>=0&&t<=255))return[e[0],e[1],e[2]]}else if(typeof e==="string"){let t=e.toLowerCase();if(Xs(t))return un[t];let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t)?.[1];if(n){let o=n.length===3?n.split("").map((s)=>s+s).join(""):n;return[Number.parseInt(o.slice(0,2),16),Number.parseInt(o.slice(2,4),16),Number.parseInt(o.slice(4,6),16)]}let r=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(t)??/^rgb\(\s*(\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*\)$/.exec(t);if(r){let o=[Number(r[1]),Number(r[2]),Number(r[3])];if(o.every((s)=>s<=255))return o}}throw TypeError(`Invalid color input: ${Js(e)}`)}function Zs(e,t,n){let r=[0,95,135,175,215,255],o=(f)=>r.reduce((d,m,b)=>Math.abs(m-f)<Math.abs(r[d]-f)?b:d,0),[s,i,a]=[o(e),o(t),o(n)],c=Math.min(23,Math.max(0,Math.round(((e+t+n)/3-8)/10))),l=8+c*10,u=(f,d,m)=>(e-f)**2+(t-d)**2+(n-m)**2;return u(l,l,l)<u(r[s],r[i],r[a])?232+c:16+36*s+6*i+a}function fn(e,t,n){let r=Math.round(Math.max(e,t,n)/127.5);if(r===0)return 30;let o=30+((Math.round(n/255)<<2|Math.round(t/255)<<1|Math.round(e/255))&7);if(r===2)o+=60;return o}function dn(e,t){let[n,r,o]=Ue(e);if(t==="16")return`\x1B[${fn(n,r,o)}m`;if(t==="256")return`\x1B[38;5;${Zs(n,r,o)}m`;return`\x1B[38;2;${n};${r};${o}m`}function Qs(e,t){if(t==="16"){let[n,r,o]=Ue(e);return`\x1B[${fn(n,r,o)+10}m`}return dn(e,t).replace(Ks,Ys)}function Ve(e,t,n){if(n==="none")return Ue(t),{open:"",close:""};return{open:e==="fg"?dn(t,n):Qs(t,n),close:e==="fg"?Gs:Hs}}function ei(e,t){return Ve("fg",e,t)}function ti(e,t){return Ve("bg",e,t)}function mn(e,t,n,r){let o=Ve(e,n,r);return r==="none"?t:We(t,o)}function ni(e,t,n="truecolor"){return mn("fg",e,t,n)}function ri(e,t,n="truecolor"){return mn("bg",e,t,n)}var gn="\x1B]",pn="\x1B\\",oi=`${gn}8;;${pn}`;function hn(e,t,n,r=""){if(!n.test(e))throw TypeError(`Invalid ${t}: ${JSON.stringify(e)} must contain only printable ASCII characters${r}.`)}function si(e){let t=e?.id;if(t===void 0||t==="")return"";if(hn(t,"hyperlink id",/^[\x20-\x7e]*$/),t.includes(":")||t.includes(";"))throw TypeError('Invalid hyperlink id: ":" and ";" are reserved by the OSC 8 format.');return`id=${t}`}function bn(e,t){hn(e,"hyperlink URL",/^[\x21-\x7e]*$/," without spaces");let n=si(t);return{open:`${gn}8;${n};${e}${pn}`,close:oi}}function ii(e,t,n){return We(e,bn(t,n))}var wn=[["fg",ni],["bg",ri]],ai=ns;function ci(e){return e.kind==="named"&&on(e.name)}function te(e,t){if(e.kind==="named")return ai[e.name];return e.kind==="fg"?ei(e.input,t):ti(e.input,t)}function yn(e,t){let n={kind:e,input:t};return te(n,"truecolor"),Array.isArray(t)?{kind:e,input:[t[0],t[1],t[2]]}:n}function tn(e,t,n){if(e==null)return"";let r=String(e);if(r==="")return r;let o=n(),{modifiersEnabled:s,colorsEnabled:i}=o;for(let a=t.length-1;a>=0;a--){let c=t[a];if(c===void 0)continue;if(ci(c)?!s:!i)continue;r=We(r,te(c,o.colorDepth))}return r}function li(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)}function ui(e,t){let n=new Map,r=t?"truecolor":e().colorDepth;function o(s){let i=s.map((f)=>f.kind==="named"?f.name:`~${te(f,"truecolor").open}`).join("|"),a=n.get(i);if(a)return a;let c=(f,...d)=>{if(li(f)){let m="";for(let b=0;b<f.length;b++)if(m+=f[b]??"",b<d.length)m+=String(d[b]);return tn(m,s,e)}return tn(f,s,e)};if(n.size>=1024)n.delete(n.keys().next().value);n.set(i,c);for(let f of ze)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,get(){return o([...s,{kind:"named",name:f}])}});for(let[f]of wn)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,value:(d)=>o([...s,yn(f,d)]),writable:!1});let l="",u="";for(let f of s){let d=te(f,r);l+=d.open,u=d.close+u}return Object.defineProperty(c,"open",{value:l,writable:!1,configurable:!1,enumerable:!0}),Object.defineProperty(c,"close",{value:u,writable:!1,configurable:!1,enumerable:!0}),Object.freeze(c)}return o}function fi(e){let t={};for(let n of ze)t[n]=e([{kind:"named",name:n}]);return t}function nn(e){let t=e?.mode??"auto",n=qs(t,e?.overrides),r=Vs(t,e?.overrides);return{modifiersEnabled:n,colorDepth:r,colorsEnabled:r!=="none",trueColorEnabled:r==="truecolor"}}function di(e,t){let n=t?nn:(()=>{let i=nn(e);return()=>i})(),r=ui(n,t),o=fi(r),s={get enabled(){let{modifiersEnabled:i,colorsEnabled:a}=n();return i||a},get colorsEnabled(){return n().colorsEnabled},get trueColorEnabled(){return n().trueColorEnabled},get colorDepth(){return n().colorDepth},link(i,a,c){if(n().modifiersEnabled)return ii(i,a,c);return bn(a,c),i},...Object.fromEntries(wn.map(([i,a])=>[i,(...c)=>{let l=n();if(c.length===1)return r([yn(i,c[0])]);return a(c[0],c[1],l.colorDepth)}])),...o};return Object.freeze(s)}var y=di(void 0,!0),{black:pc,red:ne,green:re,yellow:hc,blue:bc,magenta:vn,cyan:V,white:wc,gray:yc,brightRed:vc,brightGreen:xc,brightYellow:Sc,brightBlue:$c,brightMagenta:Oc,brightCyan:Ec,brightWhite:Ic,bgBlack:Cc,bgRed:_c,bgGreen:jc,bgYellow:kc,bgBlue:Nc,bgMagenta:Ac,bgCyan:Tc,bgWhite:Fc,bgBrightBlack:Pc,bgBrightRed:Rc,bgBrightGreen:Dc,bgBrightYellow:Mc,bgBrightBlue:Bc,bgBrightMagenta:Lc,bgBrightCyan:zc,bgBrightWhite:Wc,bold:oe,dim:se,italic:Uc,underline:Vc,inverse:qc,hidden:Gc,strikethrough:Hc,link:Kc,fg:Yc,bg:Jc}=y;var xn={spinner:vn,message:oe,success:re,error:ne},He="\x1B[",mi=`${He}?25l`,Sn=`${He}?25h`,On=`${He}2K`,En="\r",$n={dots:{frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],interval:80},line:{frames:["-","\\","|","/"],interval:130},arc:{frames:["◐","◓","◑","◒"],interval:100},bounce:{frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"],interval:120}},gi="✓",pi="✗";function hi(e){if(e===void 0)return $n.dots;if(typeof e==="string")return $n[e];if(e.frames.length===0)throw Error("A custom spinner requires at least one frame");return e}function qe(e,t){let n=e[t];if(n===void 0)throw Error("Spinner frame index is out of bounds");return n}function Ge(e,t,n){return`${On}${En}${n.spinner(e)} ${n.message(t)}`}function bi(e,t,n,r){let o=n==="success"?gi:pi,s=`${(n==="success"?t.success:t.error)(o)} ${t.message(e)}
13
- `;return r?On+En+s:s}function wi(e){let t=e.sink??K()?.output??process.stderr,n=e.theme?{...xn,...e.theme}:xn,r=t.isTTY??!1,{frames:o,interval:s}=hi(e.spinner),i=e.sigint??"exit",a=e.message,c=0,l=!1,u=!1,f,d;function m(){if(f!==void 0)clearInterval(f),f=void 0;if(d)process.removeListener("SIGINT",d),d=void 0}return{start(){if(l||u)return;if(l=!0,!r)return;if(t.write(mi),t.write(Ge(qe(o,0),a,n)),f=setInterval(()=>{c=(c+1)%o.length,t.write(Ge(qe(o,c),a,n))},s),i==="exit")d=()=>{if(m(),u=!0,t.write(Sn),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")},process.once("SIGINT",d)},updateMessage(b){if(u)return;if(a=b,l&&r)t.write(Ge(qe(o,c),a,n))},stop(b="success",g){if(u)return;if(u=!0,g!==void 0)a=g;m();let p;try{t.write(bi(a,n,b,l&&r))}catch(w){p={error:w}}if(l&&r)try{t.write(Sn)}catch(w){if(!p)throw w}if(p)throw p.error}}}function Ke(e){let t=wi(e),{task:n}=e;if(!n)return t;return t.start(),Promise.resolve().then(()=>n(t)).then((r)=>(t.stop("success"),r),(r)=>{throw t.stop("error"),r})}import*as N from"node:readline";var In={prefix:V,message:oe,placeholder:se,cursor:V,selected:V,unselected:se,error:ne,success:re,hint:se,filterMatch:V};function ae(e){let t=K();return{input:e?.input??t?.input??process.stdin,output:e?.output??t?.output??process.stderr}}var Xe=Symbol("submit");function Ze(e){return{[Xe]:e}}var Ye=new WeakSet,Je=new WeakSet,kn="\x1B[",yi=`${kn}?25l`,vi=`${kn}?25h`;function Cn(e,t){let n=e.split(`
14
- `),r=0;for(let o of n){let s=rn(o);r+=s===0?1:Math.ceil(s/t)}return r}var xi=class extends Error{constructor(e){super(e??"Prompts require an interactive terminal (TTY).");this.name="NonInteractiveError"}};function Nn(e=ae().input){return!!e.isTTY}function Si(e=ae().input){if(!Nn(e))throw new xi}function $i(e){return typeof e==="object"&&e!==null&&Xe in e}function Qe(e,t){let{render:n,handleKey:r,initialState:o,renderSubmitted:s}=e,i=e.theme?{...In,...e.theme}:In,{input:a,output:c}=ae(t),l=c;return new Promise((u,f)=>{if(Ye.has(a)||Je.has(c)){f(Error("Cannot run multiple prompts concurrently on the same input or output stream. Await each prompt before starting the next."));return}Si(a),Ye.add(a),Je.add(c);let d=o,m=0,b=!1,g=!1;function p(){if(b)return;if(b=!0,Ye.delete(a),Je.delete(c),a.removeListener("keypress",j),g)a.setRawMode?.(!1);a.pause(),c.write(vi)}function w(C){let _=c.columns||80;if(m>0)N.cursorTo(l,0),N.moveCursor(l,0,-(m-1)),N.clearScreenDown(l);c.write(C),m=Cn(C,_)}let O=Promise.resolve(),x=null;function S(){if(x!==null)return;x=setTimeout(()=>{if(x=null,b)return;try{w(n(d,i))}catch(C){p(),f(C)}},0)}function I(){if(x!==null)clearTimeout(x),x=null}function j(C,_){if(_?.ctrl&&_.name==="c"){I(),c.write(`
15
- `),p(),f(new DOMException("Prompt was cancelled.","AbortError"));return}let ge={char:C??"",name:_?.name??"",ctrl:_?.ctrl??!1,meta:_?.meta??!1,shift:_?.shift??!1};O=O.then(async()=>{if(b)return;try{let E=await r(ge,d);if(b)return;if($i(E)){I();let A=E[Xe];if(s)w(s(d,A,i));c.write(`
16
- `),p(),u(A)}else d=E,S()}catch(E){I(),p(),f(E)}})}try{if(N.emitKeypressEvents(a),a.setRawMode)a.setRawMode(!0),g=!0;a.resume(),c.write(yi);let C=n(d,i);c.write(C),m=Cn(C,c.columns||80),a.on("keypress",j)}catch(C){p(),f(C)}})}async function ie(e,t,n){if(e.initial!==void 0)return{shortCircuited:!0,value:n?await n(e.initial,"initial"):e.initial};let r=ae(t);if(!Nn(r.input)&&e.default!==void 0)return{shortCircuited:!0,value:n?await n(e.default,"default"):e.default};return{shortCircuited:!1,promptIO:r}}function et(e,t,n){let r=[e];if(t)r.push(t);if(n)r.push(n);return r.join(" ")}function An(e,t,n,r){let o=t?`${e} ${t}`:e,s=r??"";if(t)return`${o}${s}
17
- ${n}`;return`${o}${s} ${n}`}function Oi(e,t,n,r,o){let s=Math.min(e.length,n),i=[];if(t>0)i.push(o("..."));for(let a=t;a<t+s;a++){let c=e[a];if(c===void 0)break;i.push(r(c,a))}if(t+s<e.length)i.push(o("..."));return i}function Tn(e,t,n,r){let o=Math.min(n,r);if(e<t)return e;if(e>=t+o)return e-o+1;return t}function Ei(e,t,n,r,o){let s=n===-1?e<=0?t-1:e-1:e>=t-1?0:e+1;return{cursor:s,scrollOffset:Tn(s,r,t,o)}}function Ii(e){return e.map((t)=>{if(typeof t==="string")return{label:t,value:t};return t})}function Ci(e,t){if(e.name==="return")return Ze(t.value);if(e.name==="left"||e.name==="right"||e.name==="tab")return{value:!t.value};if(e.name==="h"||e.char==="y"||e.char==="Y")return{value:!0};if(e.name==="l"||e.char==="n"||e.char==="N")return{value:!1};return t}var _i=" · ";function ji(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Are you sure?"),a=e.value?`${t.selected("●")} ${t.selected(r)}`:`${t.unselected("○")} ${t.unselected(r)}`,c=e.value?`${t.unselected("○")} ${t.unselected(o)}`:`${t.selected("●")} ${t.selected(o)}`;return An(s,i,`${a}${_i}${c}`)}function ki(e,t,n,r,o,s){let i=n.success("✓"),a=n.message(r??"Are you sure?"),c=t?o:s;return et(i,a,n.success(c))}async function ce(e,t){let n=await ie(e,t);if(n.shortCircuited)return n.value;let{promptIO:r}=n,o=e.active??"Yes",s=e.inactive??"No";return Qe({initialState:{value:e.default??!0},theme:e.theme,render:(i,a)=>ji(i,a,e.message,o,s),handleKey:Ci,renderSubmitted:(i,a,c)=>ki(i,a,c,e.message,o,s)},r)}async function Ni(e,t,n){let r=await ie(e,n);if(r.shortCircuited)return r;let o=Ii(e.choices),s=e.maxVisible??10,i=e.default===void 0?[]:t==="multiple"?e.default:[e.default],a=new Set(i.flatMap((u)=>{let f=o.findIndex((d)=>d.value===u);return f===-1?[]:[f]})),c=i.length===0?-1:o.findIndex((u)=>u.value===i[0]),l=c===-1?0:c;return{shortCircuited:!1,choices:o,maxVisible:s,cursor:l,scrollOffset:Tn(l,0,o.length,s),selected:a,promptIO:r.promptIO}}async function Fn(e,t,n){if(t){let r=await t["~standard"].validate(e),o=r.issues?.[0];if(o)return{ok:!1,error:o.message||"Validation failed"};if("value"in r)return{ok:!0,value:r.value};return{ok:!1,error:"Validation failed"}}if(n)try{await n(e)}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Validation failed"}}return{ok:!0,value:e}}async function Ai(e,t,n){let r=await Fn(t,e,void 0);if(!r.ok)throw Error(`${n} value rejected by schema: ${r.error}`);return r.value}function Ti(e,t,n,r){if(e==="")return r?n.placeholder(r):n.cursor("│");return`${e.slice(0,t)}${n.cursor("│")}${e.slice(t)}`}function _n(e,t){return(e.codePointAt(t)??0)>65535?2:1}function jn(e,t){return t>=2&&(e.codePointAt(t-2)??0)>65535?2:1}function Fi(e){let t=e.codePointAt(0);return t!==void 0&&e.length===(t>65535?2:1)&&(t<55296||t>57343)}function Pi(e,t,n){if(e.name==="backspace"){if(n===0)return{text:t,cursorPos:n};let r=n-jn(t,n);return{text:t.slice(0,r)+t.slice(n),cursorPos:r}}if(e.name==="delete"){if(n>=t.length)return{text:t,cursorPos:n};let r=n+_n(t,n);return{text:t.slice(0,n)+t.slice(r),cursorPos:n}}if(e.name==="left"){if(n===0)return{text:t,cursorPos:n};return{text:t,cursorPos:n-jn(t,n)}}if(e.name==="right"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t,cursorPos:n+_n(t,n)}}if(e.name==="home")return{text:t,cursorPos:0};if(e.name==="end")return{text:t,cursorPos:t.length};if(Fi(e.char)&&!e.ctrl&&!e.meta){let r=t.slice(0,n),o=t.slice(n);return{text:r+e.char+o,cursorPos:n+e.char.length}}return null}function Ri(e,t,n){return async(r,o)=>{if(r.name==="return"){let i=await Fn(o.value===""&&n!==void 0?n:o.value,e,t);return i.ok?Ze(i.value):{...o,error:i.error}}let s=Pi(r,o.value,o.cursorPos);return s?{value:s.text,cursorPos:s.cursorPos,error:null}:o}}function Di(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Enter a value"),a=r??o,c=o!==void 0&&r!==void 0&&e.value===""?` ${t.hint(`(${o})`)}`:"",l=An(s,i,Ti(e.value,e.cursorPos,t,a),c);if(e.error!==null)l+=`
18
- ${t.error(e.error)}`;return l}function Mi(e,t,n,r){return et(n.success("✓"),n.message(r??"Enter a value"),n.success(String(t)))}async function Pn(e={},t){if(e.schema!==void 0&&e.validate!==void 0)throw Error('input() cannot combine "schema" with "validate"');let n=e.schema,r=n?await ie(e,t,(s,i)=>Ai(n,s,i)):await ie(e,t);if(r.shortCircuited)return r.value;let{promptIO:o}=r;return Qe({initialState:{value:"",cursorPos:0,error:null},theme:e.theme,render:(s,i)=>Di(s,i,e.message,e.placeholder,e.default),handleKey:Ri(e.schema,e.validate,e.default),renderSubmitted:(s,i,a)=>Mi(s,i,a,e.message)},o)}function Bi(e){return(t,n)=>{let r=n.choices.length;if(t.name==="return"){let o=n.choices[n.cursor];if(o)return Ze(o.value);return n}if(["up","down","k","j"].includes(t.name)){let o=t.name==="up"||t.name==="k"?-1:1;return{...n,...Ei(n.cursor,r,o,n.scrollOffset,e)}}return n}}function Li(e,t,n,r){let o=[`${t.prefix("┃")} ${t.message(n??"Pick an option")}`];return o.push(...Oi(e.choices,e.scrollOffset,r,(s,i)=>{let a=s.hint?` ${t.hint(s.hint)}`:"";return i===e.cursor?`${t.cursor("›")} ${t.selected(s.label)}${a}`:` ${t.unselected(s.label)}${a}`},t.hint)),o.join(`
19
- `)}function zi(e,t,n,r){let o=n.success("✓"),s=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return et(o,s,n.success(a))}async function tt(e,t){let n=await Ni(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:o,maxVisible:s,promptIO:i,scrollOffset:a}=n;return Qe({initialState:{cursor:o,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>Li(c,l,e.message,s),handleKey:Bi(s),renderSubmitted:(c,l,u)=>zi(c,l,u,e.message)},i)}var me=class extends Error{constructor(e){super(e),this.name="Eta Error"}},Mn=class extends me{constructor(e){super(e),this.name="EtaParser Error"}},Wi=class extends me{constructor(e){super(e),this.name="EtaRuntime Error"}};var Ui=class extends me{constructor(e){super(e),this.name="EtaNameResolution Error"}};function q(e,t,n){let r=t.slice(0,n).split(/\n/),o=r.length,s=r[o-1].length+1;throw e+=" at line "+o+" col "+s+`:
12
+ `)}}}async function Pt(e,t,n){let r=t?.argv??process.argv.slice(2),o={...io,...t?.io},s=new AbortController,i=t?.signal?AbortSignal.any([t.signal,s.signal]):s.signal;if(!he());let a=async()=>{let c;try{c=L(e,n)}catch(m){if(Se(m))return process.exitCode=D,D;return o.stderr(Ce(m)),process.exitCode=1,1}let l=()=>{if(!s.signal.aborted){s.abort(new DOMException("Interrupted by SIGINT.","AbortError"));return}if(process.removeListener("SIGINT",l),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")};process.on("SIGINT",l);let u,f=!1,d;try{await Ft({argv:r},c,o,i,(m)=>{u=m},async(m,b)=>{f=!0,d=m;let g=Se(m);return process.exitCode=g?D:1,$e(m,r,c,o,i,b,g)})}catch(m){let b;try{if(f&&!Object.is(m,d)&&Nt(m)&&Object.is(m.suppressed,d))b={error:m.error}}catch{}if(b)o.stderr(Ce(b.error,"Cleanup failed"));if(Se(m)){if(!f)await $e(m,r,c,o,i,u,!0);return process.exitCode=D,D}if(process.exitCode=1,!f)await $e(m,r,c,o,i,u);return 1}finally{process.removeListener("SIGINT",l)}return 0};return await(mo(t?.io)?ye(o,a):a())}var Fe=Symbol.for("crust.commandDefinition");function P(e,t,n){let r=e[Fe],o=e.name,s=n?`Extension "${n}" command "${o}"`:`Command "${o}"`,i=(u)=>({subject:n?"extension":"command",name:n??o,reason:u}),a=new ee(o);for(let[u,f]of Object.entries(t.ownedFlags))F(a._node,u,f,"owned");a._node.contexts=t.contexts.map((u)=>({...u}));let c=r.recipe(a);if(!(c instanceof ee)||c._ancestorOwnedFlags!==a._ancestorOwnedFlags)throw new h("DEFINITION",`${s} definition must return the same command builder it received`,i("foreign-command-builder"));if(c._node.extensions.length>0)throw new h("DEFINITION",`${s} cannot register Extensions inside command definitions`,i("nested-command-extension"));let l=B(c._node);return Z(l.contexts.map(({instance:u})=>u),l.demands),l.meta={name:o,...r.meta},l}function Te(e,t=[]){if(e.trim()==="")throw new h("DEFINITION","Command name must be a non-empty string",{subject:"command",name:e,reason:"empty-name"});if(e==="__proto__")throw new h("DEFINITION",'Command name "__proto__" is reserved',{subject:"command",name:e,reason:"reserved-name"});if(t.includes(e))throw new h("DEFINITION",`Command "${e}" must not list its own canonical name as an alias`,{subject:"command",name:e,reason:"alias-collision"});return e}function go(e){return typeof e==="function"}function po(e,t,n){let r=!go(t),o=r?t:{},s=r?n:t,i=Te(e,o.aliases);for(let m of o.aliases??[])if(m===""||/[ \t\n\r\v\f]/.test(m)||m.startsWith("-"))throw new h("DEFINITION",`Command "${i}" has an invalid alias "${m}"`);let{sections:a,version:c,...l}=o,u={...l,...o.aliases?{aliases:[...o.aliases]}:{},...a?{sections:_e(i,a)}:{}},f={name:i,recipe:s,meta:u},d=(m)=>Object.freeze({name:m,as:(b)=>d(Te(b,u.aliases)),[Fe]:Object.freeze({...f,name:m})});return d(i)}function ho(e){return e.filter((t,n)=>e.findLastIndex((r)=>r.id===t.id)===n)}var ee=class{_node;_ancestorOwnedFlags;constructor(e,...t){let n=t[0]??{},r=Te(e);if(this._node=Ot(r),n.description!==void 0)this._node.meta.description=n.description;if(n.version!==void 0)this._node.meta.version=n.version;if(n.usage!==void 0)this._node.meta.usage=n.usage;if(n.sections!==void 0)this._node.meta.sections=_e(r,n.sections);this._ancestorOwnedFlags={}}_clone(e){let t=Object.create(Object.getPrototypeOf(this));return t._node={...this._node,...e},t._ancestorOwnedFlags=this._ancestorOwnedFlags,t}flags(...e){let t=this._clone(Q(this._node));for(let n of e){let{name:r,...o}=n;F(t._node,r,o,"local")}return t}args(...e){let t=[...this._node.args,...e.map(vt)],n=new Set;for(let[r,o]of t.entries()){if(n.has(o.name))throw new h("DEFINITION",`Argument name "${o.name}" is already defined`,{subject:"argument",name:o.name,reason:"duplicate-arg"});if(n.add(o.name),o.variadic===!0&&r!==t.length-1)throw new h("DEFINITION",`Only the last positional argument can be variadic; "${o.name}" is not last`,{subject:"argument",name:o.name,reason:"variadic-position"})}return this._clone({args:t})}use(...e){return this._clone({demands:[...this._node.demands,...e.map(X)]})}provide(...e){let t=e.map(X);Z([...this._node.contexts.map(({instance:r})=>r),...t],t);let n=this._clone({...Q(this._node),contexts:[...this._node.contexts,...t.map((r)=>({instance:r}))],providedContexts:[...this._node.providedContexts,...t]});for(let r of t)for(let[o,s]of Object.entries(r.ownedFlags))F(n._node,o,s,"owned");return n}action(e){return this._clone({run:e})}extend(...e){let t=e.map(X),n=ho([...this._node.extensions,...t]),r=It(this._node,n,new Set(t.map((o)=>o.id)));return Z(r.contexts.map(({instance:o})=>o),n.flatMap((o)=>[...o.use,...o.provide])),this._clone({...r,extensions:n})}add(...e){return this._addDefinitions(e)}command(e,t){let n=po(e,t);return this._addDefinitions([n])}_addDefinitions(e){let t={...this._node.subCommands};for(let n of e){let r=[n.name,...n[Fe].meta.aliases??[]];for(let s of Object.values(t))if([s.meta.name,...s.meta.aliases??[]].some((i)=>r.includes(i)))throw new h("DEFINITION",`Command name "${n.name}" is already registered on this command`,{subject:"command",name:n.name,reason:"command-collision"});let o=P(n,this._node);t[n.name]=o}return this._clone({subCommands:t})}async snapshot(){return k(L(this._node,P).rootNode)}async run(e,...t){let n=t[0]??{},r=t[1];return await Ae(this._node,{path:e,input:n},r,P)}at(e){Ne(L(this._node,P).rootNode,e);let t=this._node,n=Object.freeze([...e]);return{path:n,async run(...r){let o=r[0]??{},s=r[1];return await Ae(t,{path:n,input:o},s,P)}}}async execute(e){return await Pt(this._node,e,P)}};import{existsSync as Me,lstatSync as Ht,mkdirSync as Ut,readFileSync as To,readdirSync as Kt,realpathSync as De,statSync as Yt,writeFileSync as Fo}from"node:fs";import{dirname as Jt,join as R,resolve as Vt,sep as Po}from"node:path";import{fileURLToPath as Ro}from"node:url";function Rt(e){return e instanceof Error&&"code"in e&&typeof e.code==="string"}import{isAbsolute as bo,relative as wo,sep as yo}from"node:path";function Dt(e,t){let n=wo(e,t);return n===""||!bo(n)&&n!==".."&&!n.startsWith(`..${yo}`)}import{spawn as Do,spawnSync as Mo}from"node:child_process";import{once as Bo}from"node:events";import{accessSync as Mt,constants as Bt,statSync as Lt}from"node:fs";import{delimiter as vo,extname as xo,join as So,resolve as $o,sep as Oo,win32 as Eo}from"node:path";import{spawn as Io,spawnSync as Co}from"node:child_process";import{once as _o}from"node:events";import{text as zt}from"node:stream/consumers";function Wt(e){if(e?.startsWith("bun"))return"bun";if(e?.startsWith("pnpm"))return"pnpm";if(e?.startsWith("yarn"))return"yarn";if(e?.startsWith("npm"))return"npm";return null}var jo=/[\0\r\n"%!^`<>&|]/,Pe=/([()\][%!^"`<>&|;, *?])/g;function ko(e){let t=e.replace(/(?=(\\+?)?)\1"/g,"$1$1\\\"");return t=t.replace(/(?=(\\+?)?)\1$/g,"$1$1"),t=`"${t}"`.replace(Pe,"^$1"),t.replace(Pe,"^$1")}function No(e,t,n,r=process.platform){if(n||r!=="win32"||!/\.(cmd|bat)$/i.test(e))return null;let o=Eo.normalize(e);for(let[i,a]of[o,...t].entries())if(jo.test(a)){let c=i===0?"command":`argument ${i}`;throw Error(`Windows command shim ${c} ${JSON.stringify(a)} contains unsafe shell characters`)}let s=[o.replace(Pe,"^$1"),...t.map(ko)].join(" ");return{command:process.env.ComSpec??"cmd.exe",args:["/d","/s","/c",`"${s}"`],windowsVerbatimArguments:!0}}function Ao(e){if(e.pid===void 0)return;if(process.platform==="win32"){if(e.exitCode===null&&e.signalCode===null){let t=Co("taskkill",["/pid",String(e.pid),"/T","/F"],{stdio:"ignore",timeout:1e4});if(t.error||t.status!==0)e.kill("SIGKILL")}return}try{process.kill(-e.pid,"SIGKILL")}catch(t){if(t.code==="ESRCH")return;throw e.kill("SIGKILL"),t}}async function z(e,t=[],n={}){let r=No(e,t,n.shell),o=(n.stdio??"collect")==="collect",s=o&&n.stdout!=="ignore",i=Io(r?.command??e,r?.args??t,{cwd:n.cwd,env:n.env,shell:n.shell,stdio:o?["ignore",s?"pipe":"ignore","pipe"]:"inherit",detached:n.timeout!==void 0&&process.platform!=="win32",windowsVerbatimArguments:r?.windowsVerbatimArguments}),a,c=new Promise((l,u)=>{if(n.timeout===void 0)return;let f=n.timeout;a=setTimeout(()=>{let d=Error(`${[e,...t].join(" ")} did not exit within ${f} ms and was killed.`);try{Ao(i)}catch(m){d=Error("Process-tree cleanup failed after timeout.",{cause:m})}i.stdout?.destroy(),i.stderr?.destroy(),u(d)},f)});try{let[l,u,[f]]=await Promise.race([Promise.all([s?zt(i.stdout):"",o?zt(i.stderr):"",_o(i,"close")]),c]);return{exitCode:f,stdout:l,stderr:u}}finally{clearTimeout(a)}}function Re(e){if(e.includes(Oo)||e.includes("/")){try{if(Mt(e,Bt.X_OK),Lt(e).isFile())return e}catch{}return null}let t=process.platform==="win32"&&!xo(e)?(process.env.PATHEXT??".EXE;.CMD;.BAT;.COM").split(";"):[""];for(let n of process.env.PATH?.split(vo)??[])for(let r of t){let o=$o(So(n,e+r));try{if(Mt(o,Bt.X_OK),Lt(o).isFile())return o}catch{}}return null}function Lo(e,t){return e.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,r)=>Object.hasOwn(t,r)?t[r]??n:n)}function zo(e){let t=Jt(e),n=e.slice(t==="."?0:t.length+1);if(n.startsWith("_")&&!n.startsWith("__")){let r=`.${n.slice(1)}`;return t==="."?r:R(t,r)}return e}function Wo(e){if(!Me(e))return!1;if(!Yt(e).isDirectory())return!1;return Kt(e).length>0}function qt(e,t){if(De(e)!==e)throw Error(`Destination root "${e}" was redirected outside the destination.`);let n=e;for(let r of t.split(Po)){n=R(n,r);let o;try{o=Ht(n).isSymbolicLink()}catch(i){if(Rt(i)&&i.code==="ENOENT")return;throw i}if(!o)continue;let s;try{s=De(n)}catch{}if(s===void 0||!Dt(e,s))throw Error(`Destination path "${n}" is a symlink${s===void 0?" to a missing target":` to "${s}"`} outside the destination "${e}". Remove the link or choose another destination.`)}}async function Xt(e){let{template:t,dest:n,context:r,conflict:o="abort",render:s=Lo}=e,i=t instanceof URL?Ro(t):Vt(t),a=Vt(n);if(!Me(i))throw Error(`Template directory "${i}" does not exist (from template: "${String(t)}").`);if(!Yt(i).isDirectory())throw Error(`Template path "${i}" is not a directory (from template: "${String(t)}").`);if(o==="abort"&&Wo(a))throw Error(`Destination directory "${a}" already exists and is non-empty. Use conflict: "overwrite" to proceed.`);let c=Kt(i,{recursive:!0,encoding:"utf8"}).filter((d)=>Ht(R(i,d)).isFile());Ut(a,{recursive:!0});let l=De(a),u=c.map((d)=>({relFromTemplate:d,destRelPath:zo(d)}));for(let{destRelPath:d}of u)qt(l,d);let f=[];for(let{relFromTemplate:d,destRelPath:m}of u){let b=R(i,d),g=R(l,m),p=To(b),w=p.subarray(0,8192).includes(0)?p:await s(p.toString("utf-8"),r);qt(l,m),Ut(Jt(g),{recursive:!0}),Fo(g,w,"utf-8"),f.push(m)}return{files:f}}var Uo=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];function Be(e){let t=e??process.cwd();for(let[n,r]of Uo)if(Me(R(t,n)))return r;return Wt(process.env.npm_config_user_agent)??"npm"}function Zt(e){try{return Mo("git",["rev-parse","--is-inside-work-tree"],{cwd:e??process.cwd(),stdio:"ignore"}).status===0}catch{return!1}}async function Le(e,t){for(let n of e)switch(n.type){case"install":await Vo(t);break;case"git-init":await qo(t,n.commit);break;case"open-editor":await Go(t);break;case"command":await Ho(n.cmd,n.cwd??t)}}async function Vo(e){let t=Be(e),n=Re(t);if(!n)throw Error(`Package manager "${t}" was not found on PATH. Install ${t} and try again.`);let{exitCode:r}=await z(n,["install"],{cwd:e,stdio:"inherit"});if(r!==0)throw Error(`"${t} install" exited with code ${r}`)}async function qo(e,t){let n=Re("git");if(!n)throw Error('"git" was not found on PATH. Install Git and try again.');if(await W([n,"init"],e,"git init"),t)await Ko(e,n),await W([n,"add","."],e,"git add"),await W([n,"commit","-m",t],e,"git commit")}async function Go(e){let t=process.env.EDITOR||"code";try{let n=Do(t,[e],{stdio:"ignore",shell:process.platform==="win32"});n.unref();let r=await Promise.race([Bo(n,"close").then(([o])=>({kind:"exited",code:o})),new Promise((o)=>setTimeout(()=>o({kind:"timeout"}),500))]);if(r.kind==="exited"&&r.code!==0)console.warn(`Warning: could not open editor "${t}" (exit code ${r.code})`)}catch{console.warn(`Warning: could not open editor "${t}"`)}}async function Ho(e,t){let{exitCode:n}=await z(e,[],{cwd:t,shell:!0,stdio:"inherit"});if(n!==0)throw Error(`Command "${e}" exited with code ${n}`)}async function Ko(e,t){let n=await Gt(t,"user.name",e)===0,r=await Gt(t,"user.email",e)===0;if(!n)await W([t,"config","user.name","Crust"],e,"git config user.name");if(!r)await W([t,"config","user.email","crust@scaffolded.project"],e,"git config user.email")}async function Gt(e,t,n){let{exitCode:r}=await z(e,["config",t],{cwd:n,stdio:"collect",stdout:"ignore"});return r}async function W(e,t,n){let{exitCode:r,stderr:o}=await z(e[0],e.slice(1),{cwd:t,stdio:"collect",stdout:"ignore"});if(r!==0)throw Error(`"${n}" failed with exit code ${r}${o?`: ${o.trim()}`:""}`)}var Qt=Object.defineProperty,Yo=(e,t)=>{let n={};for(var r in e)Qt(n,r,{get:e[r],enumerable:!0});if(!t)Qt(n,Symbol.toStringTag,{value:"Module"});return n},Jo=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Xo=/[\p{Cc}\p{Cf}\p{Mn}\p{Me}]/u,Zo=/\p{Emoji_Presentation}|\p{Emoji}\uFE0F/u,Qo=new RegExp([String.raw`(?:\x1b\[|\x9b)[^\x1b\x18\x1a\x9c\x40-\x7e]*[\x40-\x7e\x18\x1a\x9c]?`,String.raw`(?:\x1b\]|\x9d)[^\x07\x1b\x18\x1a\x9c]*(?:\x07|\x1b\\|[\x18\x1a\x9c])?`,String.raw`(?:\x1b[PX^_]|[\x90\x98\x9e\x9f])[^\x1b\x18\x1a\x9c]*(?:\x1b\\|[\x18\x1a\x9c])?`,String.raw`\x1b[\x20-\x2f][^\x1b]?`,String.raw`\x1b[\x18\x1a\x9c\x30-\x7e]?`].join("|"),"g");function es(e){return e>=4352&&(e<=4447||e===9001||e===9002||e>=11904&&e<=42191&&e!==12351||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=94176&&e<=111355||e>=127488&&e<=127743||e>=131072&&e<=262141)}function ts(e){return Xo.test(String.fromCodePoint(e))||e>=4448&&e<=4607||e>=55216&&e<=55295}function ns(e){if(!/[^\x20-\x7e]/.test(e))return e.length;let t=0;for(let{segment:n}of Jo.segment(e.replace(Qo,""))){if(Zo.test(n)){let r=n.codePointAt(0);t+=n.length===2&&r>=127462&&r<=127487?1:2;continue}for(let r of n){let o=r.codePointAt(0);if(ts(o))continue;t+=es(o)?2:1;break}}return t}function rn(e){return globalThis.Bun?.stringWidth(e,{countAnsiEscapeCodes:!1})??ns(e)}var rs=Yo({bgBlack:()=>Cs,bgBlue:()=>Ns,bgBrightBlack:()=>Ps,bgBrightBlue:()=>Bs,bgBrightCyan:()=>zs,bgBrightGreen:()=>Ds,bgBrightMagenta:()=>Ls,bgBrightRed:()=>Rs,bgBrightWhite:()=>Ws,bgBrightYellow:()=>Ms,bgCyan:()=>Ts,bgGreen:()=>js,bgMagenta:()=>As,bgRed:()=>_s,bgWhite:()=>Fs,bgYellow:()=>ks,black:()=>fs,blue:()=>ps,bold:()=>os,brightBlue:()=>$s,brightCyan:()=>Es,brightGreen:()=>xs,brightMagenta:()=>Os,brightRed:()=>vs,brightWhite:()=>Is,brightYellow:()=>Ss,cyan:()=>bs,dim:()=>ss,gray:()=>ys,green:()=>ms,hidden:()=>ls,inverse:()=>cs,isModifierName:()=>on,italic:()=>is,magenta:()=>hs,red:()=>ds,strikethrough:()=>us,styleMethodNames:()=>ze,underline:()=>as,white:()=>ws,yellow:()=>gs});function v(e,t){return{open:`\x1B[${e}m`,close:`\x1B[${t}m`}}var os=v(1,22),ss=v(2,22),is=v(3,23),as=v(4,24),cs=v(7,27),ls=v(8,28),us=v(9,29),fs=v(30,39),ds=v(31,39),ms=v(32,39),gs=v(33,39),ps=v(34,39),hs=v(35,39),bs=v(36,39),ws=v(37,39),ys=v(90,39),vs=v(91,39),xs=v(92,39),Ss=v(93,39),$s=v(94,39),Os=v(95,39),Es=v(96,39),Is=v(97,39),Cs=v(40,49),_s=v(41,49),js=v(42,49),ks=v(43,49),Ns=v(44,49),As=v(45,49),Ts=v(46,49),Fs=v(47,49),Ps=v(100,49),Rs=v(101,49),Ds=v(102,49),Ms=v(103,49),Bs=v(104,49),Ls=v(105,49),zs=v(106,49),Ws=v(107,49),ze=Object.freeze(["bold","dim","italic","underline","inverse","hidden","strikethrough","black","red","green","yellow","blue","magenta","cyan","white","gray","brightRed","brightGreen","brightYellow","brightBlue","brightMagenta","brightCyan","brightWhite","bgBlack","bgRed","bgGreen","bgYellow","bgBlue","bgMagenta","bgCyan","bgWhite","bgBrightBlack","bgBrightRed","bgBrightGreen","bgBrightYellow","bgBrightBlue","bgBrightMagenta","bgBrightCyan","bgBrightWhite"]),Us=new Set(["bold","dim","italic","underline","inverse","hidden","strikethrough"]);function on(e){return Us.has(e)}function U(e,t,n){return e!==void 0&&t in e?e[t]:n}function sn(e){return U(e,"isTTY",process.stdout?.isTTY)??!1}function an(e){return U(e,"forceColor",process.env.FORCE_COLOR)}function cn(e){return e==="0"||e==="false"}function Vs(e){let t=e.toLowerCase();return t.includes("24bit")||t.includes("truecolor")||t.endsWith("-direct")}function ln(e,t){if(e!==void 0){let n=e.toLowerCase();if(n==="truecolor"||n==="24bit")return!0}return t!==void 0&&Vs(t)}function en(e,t){if(ln(e,t))return"truecolor";if(t!==void 0&&t.toLowerCase().includes("256color"))return"256";return"16"}function qs(e,t){if(e==="never")return"none";if(e==="always")return"truecolor";let n=U(t,"colorTerm",process.env.COLORTERM),r=U(t,"term",process.env.TERM),o=an(t);if(o!==void 0){if(cn(o))return"none";if(o==="1")return"16";if(o==="2")return"256";if(o==="3")return"truecolor";return en(n,r)}if(!sn(t))return"none";let s=U(t,"noColor",process.env.NO_COLOR);if(s!==void 0&&s!=="")return"none";if(r!==void 0&&r.toLowerCase()==="dumb"&&!ln(n,r))return"none";return en(n,r)}function Gs(e,t){if(e==="always")return!0;if(e==="never")return!1;let n=an(t);if(n!==void 0)return!cn(n);return sn(t)}var un={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};function We(e,t){if(e==null)return"";let n=String(e);if(n==="")return"";let{open:r,close:o}=t;if(n.includes(o))n=n.replaceAll(o,o+r);return r+n+o}var Hs="\x1B[39m",Ks="\x1B[49m",Ys="\x1B[38;",Js="\x1B[48;";function Xs(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function Zs(e){return Object.hasOwn(un,e)}function Ue(e){if(Array.isArray(e)){if(e.length===3&&e.every((t)=>Number.isInteger(t)&&t>=0&&t<=255))return[e[0],e[1],e[2]]}else if(typeof e==="string"){let t=e.toLowerCase();if(Zs(t))return un[t];let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t)?.[1];if(n){let o=n.length===3?n.split("").map((s)=>s+s).join(""):n;return[Number.parseInt(o.slice(0,2),16),Number.parseInt(o.slice(2,4),16),Number.parseInt(o.slice(4,6),16)]}let r=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(t)??/^rgb\(\s*(\d{1,3})\s+(\d{1,3})\s+(\d{1,3})\s*\)$/.exec(t);if(r){let o=[Number(r[1]),Number(r[2]),Number(r[3])];if(o.every((s)=>s<=255))return o}}throw TypeError(`Invalid color input: ${Xs(e)}`)}function Qs(e,t,n){let r=[0,95,135,175,215,255],o=(f)=>r.reduce((d,m,b)=>Math.abs(m-f)<Math.abs(r[d]-f)?b:d,0),[s,i,a]=[o(e),o(t),o(n)],c=Math.min(23,Math.max(0,Math.round(((e+t+n)/3-8)/10))),l=8+c*10,u=(f,d,m)=>(e-f)**2+(t-d)**2+(n-m)**2;return u(l,l,l)<u(r[s],r[i],r[a])?232+c:16+36*s+6*i+a}function fn(e,t,n){let r=Math.round(Math.max(e,t,n)/127.5);if(r===0)return 30;let o=30+((Math.round(n/255)<<2|Math.round(t/255)<<1|Math.round(e/255))&7);if(r===2)o+=60;return o}function dn(e,t){let[n,r,o]=Ue(e);if(t==="16")return`\x1B[${fn(n,r,o)}m`;if(t==="256")return`\x1B[38;5;${Qs(n,r,o)}m`;return`\x1B[38;2;${n};${r};${o}m`}function ei(e,t){if(t==="16"){let[n,r,o]=Ue(e);return`\x1B[${fn(n,r,o)+10}m`}return dn(e,t).replace(Ys,Js)}function Ve(e,t,n){if(n==="none")return Ue(t),{open:"",close:""};return{open:e==="fg"?dn(t,n):ei(t,n),close:e==="fg"?Hs:Ks}}function ti(e,t){return Ve("fg",e,t)}function ni(e,t){return Ve("bg",e,t)}function mn(e,t,n,r){let o=Ve(e,n,r);return r==="none"?t:We(t,o)}function ri(e,t,n="truecolor"){return mn("fg",e,t,n)}function oi(e,t,n="truecolor"){return mn("bg",e,t,n)}var gn="\x1B]",pn="\x1B\\",si=`${gn}8;;${pn}`;function hn(e,t,n,r=""){if(!n.test(e))throw TypeError(`Invalid ${t}: ${JSON.stringify(e)} must contain only printable ASCII characters${r}.`)}function ii(e){let t=e?.id;if(t===void 0||t==="")return"";if(hn(t,"hyperlink id",/^[\x20-\x7e]*$/),t.includes(":")||t.includes(";"))throw TypeError('Invalid hyperlink id: ":" and ";" are reserved by the OSC 8 format.');return`id=${t}`}function bn(e,t){hn(e,"hyperlink URL",/^[\x21-\x7e]*$/," without spaces");let n=ii(t);return{open:`${gn}8;${n};${e}${pn}`,close:si}}function ai(e,t,n){return We(e,bn(t,n))}var wn=[["fg",ri],["bg",oi]],ci=rs;function li(e){return e.kind==="named"&&on(e.name)}function te(e,t){if(e.kind==="named")return ci[e.name];return e.kind==="fg"?ti(e.input,t):ni(e.input,t)}function yn(e,t){let n={kind:e,input:t};return te(n,"truecolor"),Array.isArray(t)?{kind:e,input:[t[0],t[1],t[2]]}:n}function tn(e,t,n){if(e==null)return"";let r=String(e);if(r==="")return r;let o=n(),{modifiersEnabled:s,colorsEnabled:i}=o;for(let a=t.length-1;a>=0;a--){let c=t[a];if(c===void 0)continue;if(li(c)?!s:!i)continue;r=We(r,te(c,o.colorDepth))}return r}function ui(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)}function fi(e,t){let n=new Map,r=t?"truecolor":e().colorDepth;function o(s){let i=s.map((f)=>f.kind==="named"?f.name:`~${te(f,"truecolor").open}`).join("|"),a=n.get(i);if(a)return a;let c=(f,...d)=>{if(ui(f)){let m="";for(let b=0;b<f.length;b++)if(m+=f[b]??"",b<d.length)m+=String(d[b]);return tn(m,s,e)}return tn(f,s,e)};if(n.size>=1024)n.delete(n.keys().next().value);n.set(i,c);for(let f of ze)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,get(){return o([...s,{kind:"named",name:f}])}});for(let[f]of wn)Object.defineProperty(c,f,{configurable:!1,enumerable:!0,value:(d)=>o([...s,yn(f,d)]),writable:!1});let l="",u="";for(let f of s){let d=te(f,r);l+=d.open,u=d.close+u}return Object.defineProperty(c,"open",{value:l,writable:!1,configurable:!1,enumerable:!0}),Object.defineProperty(c,"close",{value:u,writable:!1,configurable:!1,enumerable:!0}),Object.freeze(c)}return o}function di(e){let t={};for(let n of ze)t[n]=e([{kind:"named",name:n}]);return t}function nn(e){let t=e?.mode??"auto",n=Gs(t,e?.overrides),r=qs(t,e?.overrides);return{modifiersEnabled:n,colorDepth:r,colorsEnabled:r!=="none",trueColorEnabled:r==="truecolor"}}function mi(e,t){let n=t?nn:(()=>{let i=nn(e);return()=>i})(),r=fi(n,t),o=di(r),s={get enabled(){let{modifiersEnabled:i,colorsEnabled:a}=n();return i||a},get colorsEnabled(){return n().colorsEnabled},get trueColorEnabled(){return n().trueColorEnabled},get colorDepth(){return n().colorDepth},link(i,a,c){if(n().modifiersEnabled)return ai(i,a,c);return bn(a,c),i},...Object.fromEntries(wn.map(([i,a])=>[i,(...c)=>{let l=n();if(c.length===1)return r([yn(i,c[0])]);return a(c[0],c[1],l.colorDepth)}])),...o};return Object.freeze(s)}var y=mi(void 0,!0),{black:hc,red:ne,green:re,yellow:bc,blue:wc,magenta:vn,cyan:V,white:yc,gray:vc,brightRed:xc,brightGreen:Sc,brightYellow:$c,brightBlue:Oc,brightMagenta:Ec,brightCyan:Ic,brightWhite:Cc,bgBlack:_c,bgRed:jc,bgGreen:kc,bgYellow:Nc,bgBlue:Ac,bgMagenta:Tc,bgCyan:Fc,bgWhite:Pc,bgBrightBlack:Rc,bgBrightRed:Dc,bgBrightGreen:Mc,bgBrightYellow:Bc,bgBrightBlue:Lc,bgBrightMagenta:zc,bgBrightCyan:Wc,bgBrightWhite:Uc,bold:oe,dim:se,italic:Vc,underline:qc,inverse:Gc,hidden:Hc,strikethrough:Kc,link:Yc,fg:Jc,bg:Xc}=y;var xn={spinner:vn,message:oe,success:re,error:ne},He="\x1B[",gi=`${He}?25l`,Sn=`${He}?25h`,On=`${He}2K`,En="\r",$n={dots:{frames:["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"],interval:80},line:{frames:["-","\\","|","/"],interval:130},arc:{frames:["◐","◓","◑","◒"],interval:100},bounce:{frames:["⠁","⠂","⠄","⡀","⢀","⠠","⠐","⠈"],interval:120}},pi="✓",hi="✗";function bi(e){if(e===void 0)return $n.dots;if(typeof e==="string")return $n[e];if(e.frames.length===0)throw Error("A custom spinner requires at least one frame");return e}function qe(e,t){let n=e[t];if(n===void 0)throw Error("Spinner frame index is out of bounds");return n}function Ge(e,t,n){return`${On}${En}${n.spinner(e)} ${n.message(t)}`}function wi(e,t,n,r){let o=n==="success"?pi:hi,s=`${(n==="success"?t.success:t.error)(o)} ${t.message(e)}
13
+ `;return r?On+En+s:s}function yi(e){let t=e.sink??K()?.output??process.stderr,n=e.theme?{...xn,...e.theme}:xn,r=t.isTTY??!1,{frames:o,interval:s}=bi(e.spinner),i=e.sigint??"exit",a=e.message,c=0,l=!1,u=!1,f,d;function m(){if(f!==void 0)clearInterval(f),f=void 0;if(d)process.removeListener("SIGINT",d),d=void 0}return{start(){if(l||u)return;if(l=!0,!r)return;if(t.write(gi),t.write(Ge(qe(o,0),a,n)),f=setInterval(()=>{c=(c+1)%o.length,t.write(Ge(qe(o,c),a,n))},s),i==="exit")d=()=>{if(m(),u=!0,t.write(Sn),process.listenerCount("SIGINT")===0)process.kill(process.pid,"SIGINT")},process.once("SIGINT",d)},updateMessage(b){if(u)return;if(a=b,l&&r)t.write(Ge(qe(o,c),a,n))},stop(b="success",g){if(u)return;if(u=!0,g!==void 0)a=g;m();let p;try{t.write(wi(a,n,b,l&&r))}catch(w){p={error:w}}if(l&&r)try{t.write(Sn)}catch(w){if(!p)throw w}if(p)throw p.error}}}function Ke(e){let t=yi(e),{task:n}=e;if(!n)return t;return t.start(),Promise.resolve().then(()=>n(t)).then((r)=>(t.stop("success"),r),(r)=>{throw t.stop("error"),r})}import*as N from"node:readline";var In={prefix:V,message:oe,placeholder:se,cursor:V,selected:V,unselected:se,error:ne,success:re,hint:se,filterMatch:V};function ae(e){let t=K();return{input:e?.input??t?.input??process.stdin,output:e?.output??t?.output??process.stderr}}var Xe=Symbol("submit");function Ze(e){return{[Xe]:e}}var Ye=new WeakSet,Je=new WeakSet,kn="\x1B[",vi=`${kn}?25l`,xi=`${kn}?25h`;function Cn(e,t){let n=e.split(`
14
+ `),r=0;for(let o of n){let s=rn(o);r+=s===0?1:Math.ceil(s/t)}return r}var Si=class extends Error{constructor(e){super(e??"Prompts require an interactive terminal (TTY).");this.name="NonInteractiveError"}};function Nn(e=ae().input){return!!e.isTTY}function $i(e=ae().input){if(!Nn(e))throw new Si}function Oi(e){return typeof e==="object"&&e!==null&&Xe in e}function Qe(e,t){let{render:n,handleKey:r,initialState:o,renderSubmitted:s}=e,i=e.theme?{...In,...e.theme}:In,{input:a,output:c}=ae(t),l=c;return new Promise((u,f)=>{if(Ye.has(a)||Je.has(c)){f(Error("Cannot run multiple prompts concurrently on the same input or output stream. Await each prompt before starting the next."));return}$i(a),Ye.add(a),Je.add(c);let d=o,m=0,b=!1,g=!1;function p(){if(b)return;if(b=!0,Ye.delete(a),Je.delete(c),a.removeListener("keypress",j),g)a.setRawMode?.(!1);a.pause(),c.write(xi)}function w(C){let _=c.columns||80;if(m>0)N.cursorTo(l,0),N.moveCursor(l,0,-(m-1)),N.clearScreenDown(l);c.write(C),m=Cn(C,_)}let O=Promise.resolve(),x=null;function S(){if(x!==null)return;x=setTimeout(()=>{if(x=null,b)return;try{w(n(d,i))}catch(C){p(),f(C)}},0)}function I(){if(x!==null)clearTimeout(x),x=null}function j(C,_){if(_?.ctrl&&_.name==="c"){I(),c.write(`
15
+ `),p(),f(new DOMException("Prompt was cancelled.","AbortError"));return}let ge={char:C??"",name:_?.name??"",ctrl:_?.ctrl??!1,meta:_?.meta??!1,shift:_?.shift??!1};O=O.then(async()=>{if(b)return;try{let E=await r(ge,d);if(b)return;if(Oi(E)){I();let A=E[Xe];if(s)w(s(d,A,i));c.write(`
16
+ `),p(),u(A)}else d=E,S()}catch(E){I(),p(),f(E)}})}try{if(N.emitKeypressEvents(a),a.setRawMode)a.setRawMode(!0),g=!0;a.resume(),c.write(vi);let C=n(d,i);c.write(C),m=Cn(C,c.columns||80),a.on("keypress",j)}catch(C){p(),f(C)}})}async function ie(e,t,n){if(e.initial!==void 0)return{shortCircuited:!0,value:n?await n(e.initial,"initial"):e.initial};let r=ae(t);if(!Nn(r.input)&&e.default!==void 0)return{shortCircuited:!0,value:n?await n(e.default,"default"):e.default};return{shortCircuited:!1,promptIO:r}}function et(e,t,n){let r=[e];if(t)r.push(t);if(n)r.push(n);return r.join(" ")}function An(e,t,n,r){let o=t?`${e} ${t}`:e,s=r??"";if(t)return`${o}${s}
17
+ ${n}`;return`${o}${s} ${n}`}function Ei(e,t,n,r,o){let s=Math.min(e.length,n),i=[];if(t>0)i.push(o("..."));for(let a=t;a<t+s;a++){let c=e[a];if(c===void 0)break;i.push(r(c,a))}if(t+s<e.length)i.push(o("..."));return i}function Tn(e,t,n,r){let o=Math.min(n,r);if(e<t)return e;if(e>=t+o)return e-o+1;return t}function Ii(e,t,n,r,o){let s=n===-1?e<=0?t-1:e-1:e>=t-1?0:e+1;return{cursor:s,scrollOffset:Tn(s,r,t,o)}}function Ci(e){return e.map((t)=>{if(typeof t==="string")return{label:t,value:t};return t})}function _i(e,t){if(e.name==="return")return Ze(t.value);if(e.name==="left"||e.name==="right"||e.name==="tab")return{value:!t.value};if(e.name==="h"||e.char==="y"||e.char==="Y")return{value:!0};if(e.name==="l"||e.char==="n"||e.char==="N")return{value:!1};return t}var ji=" · ";function ki(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Are you sure?"),a=e.value?`${t.selected("●")} ${t.selected(r)}`:`${t.unselected("○")} ${t.unselected(r)}`,c=e.value?`${t.unselected("○")} ${t.unselected(o)}`:`${t.selected("●")} ${t.selected(o)}`;return An(s,i,`${a}${ji}${c}`)}function Ni(e,t,n,r,o,s){let i=n.success("✓"),a=n.message(r??"Are you sure?"),c=t?o:s;return et(i,a,n.success(c))}async function ce(e,t){let n=await ie(e,t);if(n.shortCircuited)return n.value;let{promptIO:r}=n,o=e.active??"Yes",s=e.inactive??"No";return Qe({initialState:{value:e.default??!0},theme:e.theme,render:(i,a)=>ki(i,a,e.message,o,s),handleKey:_i,renderSubmitted:(i,a,c)=>Ni(i,a,c,e.message,o,s)},r)}async function Ai(e,t,n){let r=await ie(e,n);if(r.shortCircuited)return r;let o=Ci(e.choices),s=e.maxVisible??10,i=e.default===void 0?[]:t==="multiple"?e.default:[e.default],a=new Set(i.flatMap((u)=>{let f=o.findIndex((d)=>d.value===u);return f===-1?[]:[f]})),c=i.length===0?-1:o.findIndex((u)=>u.value===i[0]),l=c===-1?0:c;return{shortCircuited:!1,choices:o,maxVisible:s,cursor:l,scrollOffset:Tn(l,0,o.length,s),selected:a,promptIO:r.promptIO}}async function Fn(e,t,n){if(t){let r=await t["~standard"].validate(e),o=r.issues?.[0];if(o)return{ok:!1,error:o.message||"Validation failed"};if("value"in r)return{ok:!0,value:r.value};return{ok:!1,error:"Validation failed"}}if(n)try{await n(e)}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Validation failed"}}return{ok:!0,value:e}}async function Ti(e,t,n){let r=await Fn(t,e,void 0);if(!r.ok)throw Error(`${n} value rejected by schema: ${r.error}`);return r.value}function Fi(e,t,n,r){if(e==="")return r?n.placeholder(r):n.cursor("│");return`${e.slice(0,t)}${n.cursor("│")}${e.slice(t)}`}function _n(e,t){return(e.codePointAt(t)??0)>65535?2:1}function jn(e,t){return t>=2&&(e.codePointAt(t-2)??0)>65535?2:1}function Pi(e){let t=e.codePointAt(0);return t!==void 0&&e.length===(t>65535?2:1)&&(t<55296||t>57343)}function Ri(e,t,n){if(e.name==="backspace"){if(n===0)return{text:t,cursorPos:n};let r=n-jn(t,n);return{text:t.slice(0,r)+t.slice(n),cursorPos:r}}if(e.name==="delete"){if(n>=t.length)return{text:t,cursorPos:n};let r=n+_n(t,n);return{text:t.slice(0,n)+t.slice(r),cursorPos:n}}if(e.name==="left"){if(n===0)return{text:t,cursorPos:n};return{text:t,cursorPos:n-jn(t,n)}}if(e.name==="right"){if(n>=t.length)return{text:t,cursorPos:n};return{text:t,cursorPos:n+_n(t,n)}}if(e.name==="home")return{text:t,cursorPos:0};if(e.name==="end")return{text:t,cursorPos:t.length};if(Pi(e.char)&&!e.ctrl&&!e.meta){let r=t.slice(0,n),o=t.slice(n);return{text:r+e.char+o,cursorPos:n+e.char.length}}return null}function Di(e,t,n){return async(r,o)=>{if(r.name==="return"){let i=await Fn(o.value===""&&n!==void 0?n:o.value,e,t);return i.ok?Ze(i.value):{...o,error:i.error}}let s=Ri(r,o.value,o.cursorPos);return s?{value:s.text,cursorPos:s.cursorPos,error:null}:o}}function Mi(e,t,n,r,o){let s=t.prefix("┃"),i=t.message(n??"Enter a value"),a=r??o,c=o!==void 0&&r!==void 0&&e.value===""?` ${t.hint(`(${o})`)}`:"",l=An(s,i,Fi(e.value,e.cursorPos,t,a),c);if(e.error!==null)l+=`
18
+ ${t.error(e.error)}`;return l}function Bi(e,t,n,r){return et(n.success("✓"),n.message(r??"Enter a value"),n.success(String(t)))}async function Pn(e={},t){if(e.schema!==void 0&&e.validate!==void 0)throw Error('input() cannot combine "schema" with "validate"');let n=e.schema,r=n?await ie(e,t,(s,i)=>Ti(n,s,i)):await ie(e,t);if(r.shortCircuited)return r.value;let{promptIO:o}=r;return Qe({initialState:{value:"",cursorPos:0,error:null},theme:e.theme,render:(s,i)=>Mi(s,i,e.message,e.placeholder,e.default),handleKey:Di(e.schema,e.validate,e.default),renderSubmitted:(s,i,a)=>Bi(s,i,a,e.message)},o)}function Li(e){return(t,n)=>{let r=n.choices.length;if(t.name==="return"){let o=n.choices[n.cursor];if(o)return Ze(o.value);return n}if(["up","down","k","j"].includes(t.name)){let o=t.name==="up"||t.name==="k"?-1:1;return{...n,...Ii(n.cursor,r,o,n.scrollOffset,e)}}return n}}function zi(e,t,n,r){let o=[`${t.prefix("┃")} ${t.message(n??"Pick an option")}`];return o.push(...Ei(e.choices,e.scrollOffset,r,(s,i)=>{let a=s.hint?` ${t.hint(s.hint)}`:"";return i===e.cursor?`${t.cursor("›")} ${t.selected(s.label)}${a}`:` ${t.unselected(s.label)}${a}`},t.hint)),o.join(`
19
+ `)}function Wi(e,t,n,r){let o=n.success("✓"),s=n.message(r??"Pick an option"),i=e.choices[e.cursor],a=i?i.label:"";return et(o,s,n.success(a))}async function tt(e,t){let n=await Ai(e,"single",t);if(n.shortCircuited)return n.value;let{choices:r,cursor:o,maxVisible:s,promptIO:i,scrollOffset:a}=n;return Qe({initialState:{cursor:o,choices:r,scrollOffset:a},theme:e.theme,render:(c,l)=>zi(c,l,e.message,s),handleKey:Li(s),renderSubmitted:(c,l,u)=>Wi(c,l,u,e.message)},i)}var me=class extends Error{constructor(e){super(e),this.name="Eta Error"}},Mn=class extends me{constructor(e){super(e),this.name="EtaParser Error"}},Ui=class extends me{constructor(e){super(e),this.name="EtaRuntime Error"}};var Vi=class extends me{constructor(e){super(e),this.name="EtaNameResolution Error"}};function q(e,t,n){let r=t.slice(0,n).split(/\n/),o=r.length,s=r[o-1].length+1;throw e+=" at line "+o+" col "+s+`:
20
20
 
21
21
  `+t.split(/\n/)[o-1]+`
22
- `+Array(s).join(" ")+"^",new Mn(e)}function Vi(e,t,n,r){let o=t.split(`
22
+ `+Array(s).join(" ")+"^",new Mn(e)}function qi(e,t,n,r){let o=t.split(`
23
23
  `),s=Math.max(n-3,0),i=Math.min(o.length,n+3),a=r,c=o.slice(s,i).map((u,f)=>{let d=f+s+1;return(d===n?" >> ":" ")+d+"| "+u}).join(`
24
- `),l=new Wi((a?a+":"+n+`
24
+ `),l=new Ui((a?a+":"+n+`
25
25
  `:"line "+n+`
26
26
  `)+c+`
27
27
 
28
- `+e.message);throw l.name=e.name,l.cause=e,l}var qi=(async()=>{}).constructor;function Gi(e,t){let n=this.config,r=t?.async?qi:Function;try{return new r(n.varName,"options",this.compileToString.call(this,e,t))}catch(o){throw o instanceof SyntaxError?new Mn(`Bad template syntax
28
+ `+e.message);throw l.name=e.name,l.cause=e,l}var Gi=(async()=>{}).constructor;function Hi(e,t){let n=this.config,r=t?.async?Gi:Function;try{return new r(n.varName,"options",this.compileToString.call(this,e,t))}catch(o){throw o instanceof SyntaxError?new Mn(`Bad template syntax
29
29
 
30
30
  `+o.message+`
31
31
  `+Array(o.message.length+1).join("=")+`
32
32
  `+this.compileToString.call(this,e,t)+`
33
- `):o}}function Hi(e,t){let n=this.config,r=t?.async,o=this.compileBody,s=this.parse.call(this,e),i=`${n.functionHeader}
33
+ `):o}}function Ki(e,t){let n=this.config,r=t?.async,o=this.compileBody,s=this.parse.call(this,e),i=`${n.functionHeader}
34
34
  let include = (__eta_t, __eta_d) => this.render(__eta_t, {...${n.varName}, ...(__eta_d ?? {})}, options);
35
35
  let includeAsync = (__eta_t, __eta_d) => this.renderAsync(__eta_t, {...${n.varName}, ...(__eta_d ?? {})}, options);
36
36
 
@@ -53,15 +53,15 @@ if (__eta.layout) {
53
53
  }
54
54
  ${n.useWith?"}":""}${n.debug?"} catch (e) { this.RuntimeErr(e, __eta.templateStr, __eta.line, options.filepath) }":""}
55
55
  return __eta.res;
56
- `;if(n.plugins)for(let a=0;a<n.plugins.length;a++){let c=n.plugins[a];c.processFnString&&(i=c.processFnString(i,n))}return i}function Ki(e){let t=this.config,n=0,r=e.length,o="";for(;n<r;n++){let s=e[n];if(typeof s=="string")o+="__eta.res+='"+s+`';
56
+ `;if(n.plugins)for(let a=0;a<n.plugins.length;a++){let c=n.plugins[a];c.processFnString&&(i=c.processFnString(i,n))}return i}function Yi(e){let t=this.config,n=0,r=e.length,o="";for(;n<r;n++){let s=e[n];if(typeof s=="string")o+="__eta.res+='"+s+`';
57
57
  `;else{let i=s.t,a=s.val||"";t.debug&&(o+="__eta.line="+s.lineNo+`
58
58
  `),i==="r"?(t.autoFilter&&(a="__eta.f("+a+")"),o+="__eta.res+="+a+`;
59
59
  `):i==="i"?(t.autoFilter&&(a="__eta.f("+a+")"),t.autoEscape&&(a="__eta.e("+a+")"),o+="__eta.res+="+a+`;
60
60
  `):i==="e"?o+=a+`
61
61
  `:Object.hasOwn(t.customTags,i)&&(o+=`__eta.res+=this.config.customTags[${JSON.stringify(i)}](${JSON.stringify(a)},${t.varName});
62
- `)}}return o}function Yi(e,t,n,r){let o,s;return Array.isArray(t.autoTrim)?(o=t.autoTrim[1],s=t.autoTrim[0]):o=s=t.autoTrim,(n||n===!1)&&(o=n),(r||r===!1)&&(s=r),!s&&!o?e:o==="slurp"&&s==="slurp"?e.trim():(o==="_"||o==="slurp"?e=e.trimStart():(o==="-"||o==="nl")&&(e=e.replace(/^(?:\r\n|\n|\r)/,"")),s==="_"||s==="slurp"?e=e.trimEnd():(s==="-"||s==="nl")&&(e=e.replace(/(?:\r\n|\n|\r)$/,"")),e)}var Ji={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Xi(e){return Ji[e]}function Zi(e){let t=String(e);return/[&<>"']/.test(t)?t.replace(/[&<>"']/g,Xi):t}var Rn={autoEscape:!0,autoFilter:!1,autoTrim:[!1,"nl"],cache:!1,cacheFilepaths:!0,customTags:{},debug:!1,escapeFunction:Zi,filterFunction:(e)=>String(e),outputFunctionName:"output",functionHeader:"",parse:{exec:"",interpolate:"=",raw:"~"},plugins:[],rmWhitespace:!1,tags:["<%","%>"],useWith:!1,varName:"it",defaultExtension:".eta"},le=/`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g,ue=/'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g,fe=/"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g;function de(e){return e.replace(/[.*+\-?^${}()|[\]\\]/g,"\\$&")}function Qi(e,t){return e.slice(0,t).split(`
63
- `).length}function ea(e){let t=this.config,n=[],r=!1,o=0,s=t.parse,i=Object.keys(t.customTags);if(t.plugins)for(let d=0;d<t.plugins.length;d++){let m=t.plugins[d];m.processTemplate&&(e=m.processTemplate(e,t))}t.rmWhitespace&&(e=e.replace(/[\r\n]+/g,`
64
- `).replace(/^\s+|\s+$/gm,"")),le.lastIndex=0,ue.lastIndex=0,fe.lastIndex=0;function a(d,m){d&&(d=Yi(d,t,r,m),d&&(d=d.replace(/\\|'/g,"\\$&").replace(/\r\n|\n|\r/g,"\\n"),n.push(d)))}let c=[s.exec,s.interpolate,s.raw,...i].reduce((d,m)=>d&&m?d+"|"+de(m):m?de(m):d,""),l=RegExp(de(t.tags[0])+"(-|_)?\\s*("+c+")?\\s*","g"),u=RegExp("'|\"|`|\\/\\*|(\\s*(-|_)?"+de(t.tags[1])+")","g"),f;for(;f=l.exec(e);){let d=e.slice(o,f.index);o=f[0].length+f.index;let m=f[1],b=f[2]||"";a(d,m),u.lastIndex=o;let g,p=!1;for(;g=u.exec(e);)if(g[1]){let w=e.slice(o,g.index);l.lastIndex=o=u.lastIndex,r=g[2],p={t:b===s.exec?"e":b===s.raw?"r":b===s.interpolate?"i":i.includes(b)?b:"",val:w};break}else{let w=g[0];if(w==="/*"){let O=e.indexOf("*/",u.lastIndex);O===-1&&q("unclosed comment",e,g.index),u.lastIndex=O}else w==="'"?(ue.lastIndex=g.index,ue.exec(e)?u.lastIndex=ue.lastIndex:q("unclosed string",e,g.index)):w==='"'?(fe.lastIndex=g.index,fe.exec(e)?u.lastIndex=fe.lastIndex:q("unclosed string",e,g.index)):w==="`"&&(le.lastIndex=g.index,le.exec(e)?u.lastIndex=le.lastIndex:q("unclosed string",e,g.index))}p?(t.debug&&(p.lineNo=Qi(e,f.index)),n.push(p)):q("unclosed tag",e,f.index)}if(a(e.slice(o,e.length),!1),t.plugins)for(let d=0;d<t.plugins.length;d++){let m=t.plugins[d];m.processAST&&(n=m.processAST(n,t))}return n}function Bn(e,t){let n=t?.async?this.templatesAsync:this.templatesSync;if(this.resolvePath&&this.readFile&&!e.startsWith("@")){let r=t.filepath,o=n.get(r);if(this.config.cache&&o)return o;{let s=this.readFile(r),i=this.compile(s,t);return this.config.cache&&n.define(r,i),i}}else{let r=n.get(e);if(r)return r;throw new Ui(`Failed to get template '${e}'`)}}function Ln(e,t,n){let r,o={...n,async:!1};return typeof e=="string"?(this.resolvePath&&this.readFile&&!e.startsWith("@")&&(o.filepath=this.resolvePath(e,o)),r=Bn.call(this,e,o)):r=e,r.call(this,t,o)}function zn(e,t,n){let r,o={...n,async:!0};typeof e=="string"?(this.resolvePath&&this.readFile&&!e.startsWith("@")&&(o.filepath=this.resolvePath(e,o)),r=Bn.call(this,e,o)):r=e;let s=r.call(this,t,o);return Promise.resolve(s)}function ta(e,t){let n=this.compile(e,{async:!1});return Ln.call(this,n,t)}function na(e,t){let n=this.compile(e,{async:!0});return zn.call(this,n,t)}var Dn=class{constructor(e){this.cache=e}define(e,t){this.cache[e]=t}get(e){return this.cache[e]}remove(e){delete this.cache[e]}reset(){this.cache={}}load(e){this.cache={...this.cache,...e}}},ra=class{constructor(e){e?this.config={...Rn,...e}:this.config={...Rn};let t=[this.config.parse.exec,this.config.parse.interpolate,this.config.parse.raw,"-","_"];for(let n of Object.keys(this.config.customTags))if(t.includes(n))throw new me(`Custom tag prefix "${n}" conflicts with a built-in prefix`)}config;RuntimeErr=Vi;compile=Gi;compileToString=Hi;compileBody=Ki;parse=ea;render=Ln;renderAsync=zn;renderString=ta;renderStringAsync=na;filepathCache={};templatesSync=new Dn({});templatesAsync=new Dn({});resolvePath=null;readFile=null;configure(e){this.config={...this.config,...e}}withConfig(e){return{...this,config:{...this.config,...e}}}loadTemplate(e,t,n){if(typeof t=="string")((n?.async)?this.templatesAsync:this.templatesSync).define(e,this.compile(t,n));else{let r=this.templatesSync;(t.constructor.name==="AsyncFunction"||n?.async)&&(r=this.templatesAsync),r.define(e,t)}}},Wn=class extends ra{};var Un={name:"@crustjs/core",version:"0.5.2",description:"Core library for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/core"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","command","framework","parser","bun","typescript"],files:["dist"],types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./tooling":{types:"./dist/tooling.d.ts",import:"./dist/tooling.js"}},publishConfig:{access:"public"},scripts:{build:"vp run build:task",dev:"vp pack --watch","check:types":"vp run check:types:task",test:"vp run test:task",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","vite-plus":"catalog:"},peerDependencies:{typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=24",deno:">=2.8"}};var Vn={name:"@crustjs/crust",version:"0.5.2",description:"CLI tooling for the Crust framework",type:"module",license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/crust"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","build","compile","standalone","bun","typescript"],publishConfig:{access:"public"},exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},crust:{artifact:"binary",include:["schema","dist"]},bin:{crust:"src/cli.ts"},scripts:{build:"vp run build:task",release:"bun src/cli.ts publish",dev:"bun src/cli.ts",start:"bun .crust/root/bin/crust.js","check:types":"vp run check:types:task",test:"vp run test:task"},dependencies:{"@crustjs/core":"workspace:^","@crustjs/extensions":"workspace:^","@crustjs/style":"workspace:^"},optionalDependencies:{"@tsdown/exe":"0.23.0",tsdown:"0.23.0"},peerDependencies:{"@crustjs/core":"^0.5.0"},devDependencies:{"@arethetypeswrong/core":"^0.18.5","@crustjs/config":"workspace:*","@crustjs/testing":"workspace:*","@crustjs/utils":"workspace:*","@types/semver":"^7.8.0",publint:"^0.3.24",semver:"^7.8.5","vite-plus":"catalog:"},engines:{bun:">=1.4.0"}};var qn={name:"@crustjs/extensions",version:"0.5.2",description:"Official Extensions for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/extensions"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","extension","help","version","completion","did-you-mean","bun","typescript"],files:["dist"],exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},publishConfig:{access:"public"},scripts:{build:"vp run build:task",dev:"vp pack --watch","check:types":"vp run check:types:task",test:"vp run test:task",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/store":"workspace:^","@crustjs/style":"workspace:^","@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","@crustjs/core":"workspace:*","vite-plus":"catalog:"},peerDependencies:{"@crustjs/core":"workspace:^",typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=24",deno:">=2.8"}};var la={bun:{shebang:"#!/usr/bin/env bun",tsLib:'"ESNext"',tsTypes:'"bun"'},node:{shebang:"#!/usr/bin/env node",tsLib:'"ESNext"',tsTypes:'"node"'},deno:{shebang:"#!/usr/bin/env -S deno run -A",tsLib:'"ESNext", "deno.window"',tsTypes:""}},ua=new Wn({autoEscape:!1,autoTrim:!1}),fa=/^[A-Za-z0-9_~][A-Za-z0-9._~-]*$/;function Jn(e){if(e==="__proto__"||!fa.test(e))throw Error(`Project name ${JSON.stringify(e)} is not safe for the generated project.
65
- The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var da=/[<>:"|?*\\]/;function ma(e){if(!e)throw Error("Project directory cannot be empty");if(da.test(e))throw Error(`Project directory contains invalid characters: ${e}`);Jn(Kn(Yn(e)))}var ga=new ee("create-crust",{description:"Scaffold a new Crust CLI project"}).flags({name:"runtime",type:"string",choices:["bun","node","deno"],description:'Runtime to develop and build for ("bun", "node", or "deno")'},{name:"artifact",type:"string",choices:["package","binary"],description:"Build output: runtime package or standalone binary"},{name:"install",type:"boolean",description:"Install dependencies after scaffolding"},{name:"git",type:"boolean",description:"Initialize a git repository after scaffolding"},{name:"overwrite",type:"boolean",description:"Overwrite the destination directory if it already exists"}).args({name:"directory",type:"string",description:"Project directory to scaffold into"}).action(async({args:e,flags:t})=>{let n=e.directory??await Pn({message:"Project directory",default:"my-cli",validate:ma}),r=Yn(process.cwd(),n),o=Kn(r);Jn(o);let s=t.runtime,i=n==="."?aa(r).length>0:Gn(r),a=!1;if(i){if(a=await ce({message:n==="."?"Current directory is not empty. Overwrite conflicting files?":`Directory "${o}" already exists. Overwrite?`,default:!1,...t.overwrite!==void 0?{initial:t.overwrite}:{}}),!a){console.log("Aborted.");return}}let c=await tt({message:"Runtime",choices:[{label:"Bun (recommended)",value:"bun",hint:"Bun APIs and TypeScript execution"},{label:"Node.js",value:"node",hint:"Node.js APIs and ecosystem"},{label:"Deno",value:"deno",hint:"Deno APIs and permission model"}],default:"bun",...s!==void 0?{initial:s}:{}}),l=await tt({message:"Build output",choices:[{label:"Standalone binary",value:"binary",hint:"Embeds the runtime; users need no separate JavaScript runtime"},{label:"Runtime package",value:"package",hint:c==="deno"?"Requires Deno installed; experimental bundling":"JavaScript bundle; requires the selected runtime installed"}],default:c==="node"?"package":"binary",...t.artifact!==void 0?{initial:t.artifact}:{}}),u=await ce({message:"Install dependencies?",default:!0,...t.install!==void 0?{initial:t.install}:{}}),f=r;while(!Gn(f)&&Hn(f)!==f)f=Hn(f);let m=Zt(f)?!1:await ce({message:"Initialize a git repository?",default:!0,...t.git!==void 0?{initial:t.git}:{}}),b=o,g=c==="deno"?"deno":Be(r),p={name:b,runtime:c,artifact:l,run:g==="deno"?"deno task":`${g} run`,install:`${g} install`,...la[c],coreVersion:Un.version,extensionsVersion:qn.version,crustVersion:Vn.version};if(await Ke({message:"Scaffolding project...",task:()=>Xt({template:ca(be("templates"),"base"),dest:r,context:p,render:(w,O)=>ua.renderString(w,O),...a?{conflict:"overwrite"}:{}})}),u)await Le([c==="deno"?{type:"command",cmd:"deno install"}:{type:"install"}],r);if(m)await Ke({message:"Initializing git repository...",task:()=>Le([{type:"git-init",commit:"chore: initial commit"}],r)});if(console.log(`
62
+ `)}}return o}function Ji(e,t,n,r){let o,s;return Array.isArray(t.autoTrim)?(o=t.autoTrim[1],s=t.autoTrim[0]):o=s=t.autoTrim,(n||n===!1)&&(o=n),(r||r===!1)&&(s=r),!s&&!o?e:o==="slurp"&&s==="slurp"?e.trim():(o==="_"||o==="slurp"?e=e.trimStart():(o==="-"||o==="nl")&&(e=e.replace(/^(?:\r\n|\n|\r)/,"")),s==="_"||s==="slurp"?e=e.trimEnd():(s==="-"||s==="nl")&&(e=e.replace(/(?:\r\n|\n|\r)$/,"")),e)}var Xi={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Zi(e){return Xi[e]}function Qi(e){let t=String(e);return/[&<>"']/.test(t)?t.replace(/[&<>"']/g,Zi):t}var Rn={autoEscape:!0,autoFilter:!1,autoTrim:[!1,"nl"],cache:!1,cacheFilepaths:!0,customTags:{},debug:!1,escapeFunction:Qi,filterFunction:(e)=>String(e),outputFunctionName:"output",functionHeader:"",parse:{exec:"",interpolate:"=",raw:"~"},plugins:[],rmWhitespace:!1,tags:["<%","%>"],useWith:!1,varName:"it",defaultExtension:".eta"},le=/`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g,ue=/'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g,fe=/"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g;function de(e){return e.replace(/[.*+\-?^${}()|[\]\\]/g,"\\$&")}function ea(e,t){return e.slice(0,t).split(`
63
+ `).length}function ta(e){let t=this.config,n=[],r=!1,o=0,s=t.parse,i=Object.keys(t.customTags);if(t.plugins)for(let d=0;d<t.plugins.length;d++){let m=t.plugins[d];m.processTemplate&&(e=m.processTemplate(e,t))}t.rmWhitespace&&(e=e.replace(/[\r\n]+/g,`
64
+ `).replace(/^\s+|\s+$/gm,"")),le.lastIndex=0,ue.lastIndex=0,fe.lastIndex=0;function a(d,m){d&&(d=Ji(d,t,r,m),d&&(d=d.replace(/\\|'/g,"\\$&").replace(/\r\n|\n|\r/g,"\\n"),n.push(d)))}let c=[s.exec,s.interpolate,s.raw,...i].reduce((d,m)=>d&&m?d+"|"+de(m):m?de(m):d,""),l=RegExp(de(t.tags[0])+"(-|_)?\\s*("+c+")?\\s*","g"),u=RegExp("'|\"|`|\\/\\*|(\\s*(-|_)?"+de(t.tags[1])+")","g"),f;for(;f=l.exec(e);){let d=e.slice(o,f.index);o=f[0].length+f.index;let m=f[1],b=f[2]||"";a(d,m),u.lastIndex=o;let g,p=!1;for(;g=u.exec(e);)if(g[1]){let w=e.slice(o,g.index);l.lastIndex=o=u.lastIndex,r=g[2],p={t:b===s.exec?"e":b===s.raw?"r":b===s.interpolate?"i":i.includes(b)?b:"",val:w};break}else{let w=g[0];if(w==="/*"){let O=e.indexOf("*/",u.lastIndex);O===-1&&q("unclosed comment",e,g.index),u.lastIndex=O}else w==="'"?(ue.lastIndex=g.index,ue.exec(e)?u.lastIndex=ue.lastIndex:q("unclosed string",e,g.index)):w==='"'?(fe.lastIndex=g.index,fe.exec(e)?u.lastIndex=fe.lastIndex:q("unclosed string",e,g.index)):w==="`"&&(le.lastIndex=g.index,le.exec(e)?u.lastIndex=le.lastIndex:q("unclosed string",e,g.index))}p?(t.debug&&(p.lineNo=ea(e,f.index)),n.push(p)):q("unclosed tag",e,f.index)}if(a(e.slice(o,e.length),!1),t.plugins)for(let d=0;d<t.plugins.length;d++){let m=t.plugins[d];m.processAST&&(n=m.processAST(n,t))}return n}function Bn(e,t){let n=t?.async?this.templatesAsync:this.templatesSync;if(this.resolvePath&&this.readFile&&!e.startsWith("@")){let r=t.filepath,o=n.get(r);if(this.config.cache&&o)return o;{let s=this.readFile(r),i=this.compile(s,t);return this.config.cache&&n.define(r,i),i}}else{let r=n.get(e);if(r)return r;throw new Vi(`Failed to get template '${e}'`)}}function Ln(e,t,n){let r,o={...n,async:!1};return typeof e=="string"?(this.resolvePath&&this.readFile&&!e.startsWith("@")&&(o.filepath=this.resolvePath(e,o)),r=Bn.call(this,e,o)):r=e,r.call(this,t,o)}function zn(e,t,n){let r,o={...n,async:!0};typeof e=="string"?(this.resolvePath&&this.readFile&&!e.startsWith("@")&&(o.filepath=this.resolvePath(e,o)),r=Bn.call(this,e,o)):r=e;let s=r.call(this,t,o);return Promise.resolve(s)}function na(e,t){let n=this.compile(e,{async:!1});return Ln.call(this,n,t)}function ra(e,t){let n=this.compile(e,{async:!0});return zn.call(this,n,t)}var Dn=class{constructor(e){this.cache=e}define(e,t){this.cache[e]=t}get(e){return this.cache[e]}remove(e){delete this.cache[e]}reset(){this.cache={}}load(e){this.cache={...this.cache,...e}}},oa=class{constructor(e){e?this.config={...Rn,...e}:this.config={...Rn};let t=[this.config.parse.exec,this.config.parse.interpolate,this.config.parse.raw,"-","_"];for(let n of Object.keys(this.config.customTags))if(t.includes(n))throw new me(`Custom tag prefix "${n}" conflicts with a built-in prefix`)}config;RuntimeErr=qi;compile=Hi;compileToString=Ki;compileBody=Yi;parse=ta;render=Ln;renderAsync=zn;renderString=na;renderStringAsync=ra;filepathCache={};templatesSync=new Dn({});templatesAsync=new Dn({});resolvePath=null;readFile=null;configure(e){this.config={...this.config,...e}}withConfig(e){return{...this,config:{...this.config,...e}}}loadTemplate(e,t,n){if(typeof t=="string")((n?.async)?this.templatesAsync:this.templatesSync).define(e,this.compile(t,n));else{let r=this.templatesSync;(t.constructor.name==="AsyncFunction"||n?.async)&&(r=this.templatesAsync),r.define(e,t)}}},Wn=class extends oa{};var Un={name:"@crustjs/core",version:"0.5.3",description:"Core library for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/core"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","command","framework","parser","bun","typescript"],files:["dist"],types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"},"./tooling":{types:"./dist/tooling.d.ts",import:"./dist/tooling.js"}},publishConfig:{access:"public"},scripts:{build:"vp run build:task",dev:"vp pack --watch","check:types":"vp run check:types:task",test:"vp run test:task",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","vite-plus":"catalog:"},peerDependencies:{typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=24",deno:">=2.8"}};var Vn={name:"@crustjs/crust",version:"0.5.3",description:"CLI tooling for the Crust framework",type:"module",license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/crust"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","build","compile","standalone","bun","typescript"],publishConfig:{access:"public"},exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},crust:{artifact:"binary",include:["schema","dist"]},bin:{crust:"src/cli.ts"},scripts:{build:"vp run build:task",release:"bun src/cli.ts publish",dev:"bun src/cli.ts",start:"bun .crust/root/bin/crust.js","check:types":"vp run check:types:task",test:"vp run test:task"},dependencies:{"@crustjs/core":"workspace:^","@crustjs/extensions":"workspace:^","@crustjs/style":"workspace:^"},optionalDependencies:{"@tsdown/exe":"0.23.0",tsdown:"0.23.0"},peerDependencies:{"@crustjs/core":"^0.5.0"},devDependencies:{"@arethetypeswrong/core":"^0.18.5","@crustjs/config":"workspace:*","@crustjs/testing":"workspace:*","@crustjs/utils":"workspace:*","@types/semver":"^7.8.0",publint:"^0.3.24",semver:"^7.8.5","vite-plus":"catalog:"},engines:{bun:">=1.4.0"}};var qn={name:"@crustjs/extensions",version:"0.5.3",description:"Official Extensions for the Crust CLI framework",type:"module",sideEffects:!1,license:"MIT",author:"chenxin-yan",repository:{type:"git",url:"git+https://github.com/chenxin-yan/crust.git",directory:"packages/extensions"},homepage:"https://crustjs.com",bugs:{url:"https://github.com/chenxin-yan/crust/issues"},keywords:["cli","extension","help","version","completion","did-you-mean","bun","typescript"],files:["dist"],exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js"}},publishConfig:{access:"public"},scripts:{build:"vp run build:task",dev:"vp pack --watch","check:types":"vp run check:types:task",test:"vp run test:task",prepack:"cp ../../LICENSE LICENSE",postpack:"rm -f LICENSE"},dependencies:{"@crustjs/store":"workspace:^","@crustjs/style":"workspace:^","@crustjs/utils":"workspace:^"},devDependencies:{"@crustjs/config":"workspace:*","@crustjs/core":"workspace:*","vite-plus":"catalog:"},peerDependencies:{"@crustjs/core":"workspace:^",typescript:"^7.0.0"},peerDependenciesMeta:{typescript:{optional:!0}},engines:{bun:">=1.4.0",node:">=24",deno:">=2.8"}};var ua={bun:{shebang:"#!/usr/bin/env bun",tsLib:'"ESNext"',tsTypes:'"bun"'},node:{shebang:"#!/usr/bin/env node",tsLib:'"ESNext"',tsTypes:'"node"'},deno:{shebang:"#!/usr/bin/env -S deno run -A",tsLib:'"ESNext", "deno.window"',tsTypes:""}},fa=new Wn({autoEscape:!1,autoTrim:!1}),da=/^[A-Za-z0-9_~][A-Za-z0-9._~-]*$/;function Jn(e){if(e==="__proto__"||!da.test(e))throw Error(`Project name ${JSON.stringify(e)} is not safe for the generated project.
65
+ The directory basename becomes the package and command name: use letters, digits, ".", "_", "~", and "-", not starting with "." or "-"; "__proto__" is reserved.`)}var ma=/[<>:"|?*\\]/;function ga(e){if(!e)throw Error("Project directory cannot be empty");if(ma.test(e))throw Error(`Project directory contains invalid characters: ${e}`);Jn(Kn(Yn(e)))}var pa=new ee("create-crust",{description:"Scaffold a new Crust CLI project"}).flags({name:"runtime",type:"string",choices:["bun","node","deno"],description:'Runtime to develop and build for ("bun", "node", or "deno")'},{name:"artifact",type:"string",choices:["package","binary"],description:"Build output: runtime package or standalone binary"},{name:"install",type:"boolean",description:"Install dependencies after scaffolding"},{name:"git",type:"boolean",description:"Initialize a git repository after scaffolding"},{name:"overwrite",type:"boolean",description:"Overwrite the destination directory if it already exists"}).args({name:"directory",type:"string",description:"Project directory to scaffold into"}).action(async({args:e,flags:t})=>{let n=e.directory??await Pn({message:"Project directory",default:"my-cli",validate:ga}),r=Yn(process.cwd(),n),o=Kn(r);Jn(o);let s=t.runtime,i=n==="."?ca(r).length>0:Gn(r),a=!1;if(i){if(a=await ce({message:n==="."?"Current directory is not empty. Overwrite conflicting files?":`Directory "${o}" already exists. Overwrite?`,default:!1,...t.overwrite!==void 0?{initial:t.overwrite}:{}}),!a){console.log("Aborted.");return}}let c=await tt({message:"Runtime",choices:[{label:"Bun (recommended)",value:"bun",hint:"Bun APIs and TypeScript execution"},{label:"Node.js",value:"node",hint:"Node.js APIs and ecosystem"},{label:"Deno",value:"deno",hint:"Deno APIs and permission model"}],default:"bun",...s!==void 0?{initial:s}:{}}),l=await tt({message:"Build output",choices:[{label:"Standalone binary",value:"binary",hint:"Embeds the runtime; users need no separate JavaScript runtime"},{label:"Runtime package",value:"package",hint:c==="deno"?"Requires Deno installed; experimental bundling":"JavaScript bundle; requires the selected runtime installed"}],default:c==="node"?"package":"binary",...t.artifact!==void 0?{initial:t.artifact}:{}}),u=await ce({message:"Install dependencies?",default:!0,...t.install!==void 0?{initial:t.install}:{}}),f=r;while(!Gn(f)&&Hn(f)!==f)f=Hn(f);let m=Zt(f)?!1:await ce({message:"Initialize a git repository?",default:!0,...t.git!==void 0?{initial:t.git}:{}}),b=o,g=c==="deno"?"deno":Be(r),p={name:b,runtime:c,artifact:l,run:g==="deno"?"deno task":`${g} run`,install:`${g} install`,...ua[c],coreVersion:Un.version,extensionsVersion:qn.version,crustVersion:Vn.version};if(await Ke({message:"Scaffolding project...",task:()=>Xt({template:la(be("templates"),"base"),dest:r,context:p,render:(w,O)=>fa.renderString(w,O),...a?{conflict:"overwrite"}:{}})}),u)await Le([c==="deno"?{type:"command",cmd:"deno install"}:{type:"install"}],r);if(m)await Ke({message:"Initializing git repository...",task:()=>Le([{type:"git-init",commit:"chore: initial commit"}],r)});if(console.log(`
66
66
  Created ${b}!
67
- `),console.log("Next steps:"),n!=="."){let w=n.startsWith("/")?n:`./${n}`;console.log(` cd ${w}`)}if(!u)console.log(` ${p.install}`);console.log(` ${p.run} dev`),console.log(` ${p.run} build`)});await ga.execute();
67
+ `),console.log("Next steps:"),n!=="."){let w=n.startsWith("/")?n:`./${n}`;console.log(` cd ${w}`)}if(!u)console.log(` ${p.install}`);console.log(` ${p.run} dev`),console.log(` ${p.run} build`)});await pa.execute();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-crust",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Scaffold a new Crust CLI project.",
5
5
  "license": "MIT",
6
6
  "author": "chenxin-yan",