@kaisers-io/refs 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.16.1] - 2026-09-13
9
+
10
+ ### Changed
11
+
12
+ - **The skill answers "which packages are not registered?" with `refs doctor`.** Asked whether a
13
+ tracked repository declares packages the configuration does not register, agents often never ran
14
+ doctor. They read `packages_count` from `refs show`, counted directories, and inferred an answer,
15
+ which turned into a confident wrong one when discovery could not finish. `SKILL.md` now routes
16
+ the question to `refs doctor --json`. It also says that `packages_count`, `refs show --packages`
17
+ and `refs list --packages` describe what is registered, not what the repository declares.
18
+ `MAINTAIN.md` explains how to read the answer: the `config-drift` findings regardless of its
19
+ status, the "could not check" case, and declined packages. The claim that an undecided package
20
+ keeps `config-drift` on `warn` is gone. It stopped being true in 0.15.0.
21
+
8
22
  ## [0.16.0] - 2026-09-13
9
23
 
10
24
  ### Added
package/dist/refs.mjs CHANGED
@@ -325,7 +325,7 @@ sync_ttl = "1h"
325
325
  `)[0]??t;return n.length<=200?n:`${n.slice(0,200)}…`},fd=(e,t)=>t?`restored`:e.oldSha===e.newSha?`fresh`:`updated`,pd=(e,t)=>{let n=[];if(e&&n.push(`checkout had local changes (managed checkouts are read-only) — discarded and restored to the remote state`),t!==void 0&&n.push(t),n.length!==0)return n.join(` | `)},md=e=>{let{branchRenamedTo:t,dirty:n,setHeadWarning:r,shas:i}=e,a={...i,status:fd(i,n)};t!==void 0&&(a.branchRenamedTo=t);let o=pd(n,r);return o!==void 0&&(a.warning=o),a},hd=(e,t,n)=>{let r={dirty:t,shas:n};return e.branchRenamedTo!==void 0&&(r.branchRenamedTo=e.branchRenamedTo),e.warning!==void 0&&(r.setHeadWarning=e.warning),r},U=e=>pe(m(e,`.git`)),gd=e=>`refusing to sync ${e}: not a refs-managed checkout`,_d=async(e,t)=>{if(!U(t))throw y(gd(t));let n=await e.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:t});if(n.exitCode!==0||n.stdout.trim()===``)throw y(gd(t))},vd=/filtering not recognized/iu,yd=e=>e===void 0?{}:{cwd:e},bd=(e,t,n)=>({action:e,args:t,cmd:`git`,...yd(n)}),xd=async(e,t)=>{let n=await e.run(t.cmd,t.args,yd(t.cwd));if(n.exitCode===0)return n;let r=n.stderr.trim()||n.stdout.trim()||`exit code ${n.exitCode}`;throw y(`${t.action} failed: ${r}`)},Sd=async(e,t)=>{let n=[`clone`,`-q`];t.mode===`blobless`&&n.push(`--filter=blob:none`),n.push(`--`,t.cloneUrl,t.dest);let r=await xd(e,bd(`git clone`,n));return await xd(e,bd(`git config core.hooksPath`,[`config`,`core.hooksPath`,t.hooksDir],t.dest)),t.mode===`blobless`&&vd.test(r.stderr)?{effectiveMode:`full`,warning:`server did not honour the partial-clone filter (blob:none); fell back to a full clone`}:{effectiveMode:t.mode}},Cd=async(e,t)=>{let n=await e.run(`git`,[`symbolic-ref`,`--short`,`refs/remotes/origin/HEAD`],{cwd:t});if(n.exitCode!==0)return;let r=n.stdout.trim();return r.startsWith(`origin/`)?r.slice(7):r},wd=async(e,t)=>{let n=await Cd(e,t);if(n!==void 0)return n;await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t});let r=await Cd(e,t);if(r!==void 0)return r;throw y(`could not detect the default branch for checkout: ${t}`)},Td=async(e,t)=>(await xd(e,bd(`git rev-parse HEAD`,[`rev-parse`,`HEAD`],t))).stdout.trim(),Ed=async(e,t)=>(await xd(e,bd(`git status --porcelain`,[`status`,`--porcelain`],t))).stdout.trim()!==``,Dd=async(e,t)=>{await xd(e,bd(`git fetch`,[`fetch`,`--prune`,`--tags`,`origin`],t.dir));let n=await e.run(`git`,[`remote`,`set-head`,`origin`,`--auto`],{cwd:t.dir}),r=await wd(e,t.dir),i={branch:r};return r!==t.defaultBranch&&(i.branchRenamedTo=r),n.exitCode!==0&&(i.warning=`could not refresh origin/HEAD: ${dd(n)}`),i},Od=e=>[bd(`git reset --hard HEAD (pre-checkout)`,[`reset`,`--hard`,`HEAD`],e),bd(`git clean -fd`,[`clean`,`-fd`],e)],kd=async(e,t)=>{let{branch:n,dir:r,dirty:i}=t,a=[];i&&a.push(...Od(r)),a.push(bd(`git checkout -B`,[`checkout`,`-B`,n,`origin/${n}`],r),bd(`git reset --hard`,[`reset`,`--hard`,`origin/${n}`],r));for(let t of a)await xd(e,t)},Ad=async(e,t)=>{await _d(e,t.dir);let n=await Td(e,t.dir),r=await Dd(e,t),i=await Ed(e,t.dir);await kd(e,{branch:r.branch,dir:t.dir,dirty:i});let a=await Td(e,t.dir);return md(hd(r,i,{newSha:a,oldSha:n}))},jd=async(e,t,n)=>(await e.run(`git`,[`show-ref`,`--verify`,`--`,`refs/tags/${n}`],{cwd:t})).exitCode===0,Md=[`#!/bin/sh`,`echo "refs: this checkout is a managed read-only reference — commits are blocked" >&2`,`exit 1`,``].join(`
326
326
  `),Nd=async e=>{await Promise.all([`pre-commit`,`pre-push`].map(async n=>{let r=m(e.hooksDir,n);await $l(r,Md),await t(r,493)}))},Pd=async(e,t,n)=>{let r=await xd(e,bd(`git tag`,[`tag`,`--sort=-version:refname`],t)),i=r.stdout.split(`
327
327
  `).map(e=>e.trim()).filter(e=>e!==``),a=!r.stderr.includes(`refs: stdout exceeded`);return n===void 0?{complete:a,tags:i}:{complete:a&&i.length<=n,tags:i.slice(0,n)}},Fd=/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/u,Id=/\d+\.\d+\.\d+/gu,Ld=e=>ll.safeParse(e).success,Rd=e=>{let t=e.match(Id);return t!==null&&t.length>1},zd=e=>{let t=Fd.exec(e);if(!t||Rd(e))return;let[n]=t,r=e.replace(n,`{version}`);if(Ld(r))return r},Bd=(e,t,n)=>{let r=e.get(t);r===void 0?e.set(t,{count:1,index:n}):r.count+=1},Vd=e=>{let t=new Map;for(let[n,r]of e.entries()){let e=zd(r);e&&Bd(t,e,n)}return t},Hd=(e,t)=>e.count>t.count||e.count===t.count&&e.index<t.index,Ud=e=>{let t=[...e.entries()],[n]=t;if(n===void 0)return null;let[r,i]=n;return t.slice(1).reduce(({format:e,data:t},[n,r])=>Hd(r,t)?{data:r,format:n}:{data:t,format:e},{data:i,format:r}).format},Wd=e=>{let t=Vd(e);return Ud(t)},Gd=(e,t)=>e.replaceAll(`{version}`,()=>t),Kd=async(e,t,n,r)=>{let i=Gd(n,r);if(!await jd(e,t,i))throw _(`tag '${i}' not found in ${t} — check the version or tag_format`);return i},qd=/^(?<scheme>[a-z][a-z0-9+.-]*:\/\/)?[\s\S]*@/iu,W=e=>{let t=e.replace(qd,`$<scheme><redacted>@`);return t.length<=200?t:`${t.slice(0,200)}…`},Jd=/\.git$/u,Yd=e=>e.replace(Jd,``),Xd=e=>{let t=0,n=e.length;for(;t<n&&e.charAt(t)===`/`;)t+=1;for(;n>t&&e.charAt(n-1)===`/`;)--n;return e.slice(t,n)},Zd=/^git@(?<host>[^:/\s]+):(?<path>[^\s]+)$/u,Qd=/^git\+/u,$d={"https:":`443`,"ssh:":`22`},ef=e=>e.split(`/`).some(e=>e===`.`||e===`..`),tf=e=>e.includes(`\\`),nf=e=>e.includes(`%`),rf=e=>{let t=il.safeParse(e);if(!t.success)throw y(`not a supported git url: derived key '${W(e)}' is invalid`);return t.data},af=({host:e,port:t,protocol:n})=>{let r=$d[n];return t===``||t===r?e.toLowerCase():`${e.toLowerCase()}_${t}`},of=e=>{let t=Yd(Xd(e.path));return rf(`${af(e)}/${t}`)},sf=e=>{let t=decodeURIComponent(e).split(`/`).filter(e=>e!==``);if(t.length<2)throw y(`not a supported git url: file url path must have at least 2 segments`);let n=t.at(-2)??``,r=t.at(-1)??``;return rf(`local/${n}/${r}`)},cf=(e,t)=>{try{return new URL(e)}catch{throw y(`not a supported git url: ${W(t)}`)}},lf=e=>{if(e.password!==``)throw y(`not a supported git url: credentials embedded in url`);if(e.protocol===`https:`&&e.username!==``)throw y(`not a supported git url: credentials embedded in https url`)},uf=(e,t)=>{if(e.protocol===`file:`){if(!t)throw y(`not a supported git url: unsupported protocol ${e.protocol}`);return sf(e.pathname)}if(e.protocol!==`https:`&&e.protocol!==`ssh:`)throw y(`not a supported git url: unsupported protocol ${e.protocol}`);return lf(e),of({host:e.hostname,path:e.pathname,port:e.port,protocol:e.protocol})},df=(e,t)=>{if(nf(e))throw y(`not a supported git url: percent-encoding not supported in ${W(t)}`);if(e.includes(`:`))throw y(`not a supported git url: ambiguous ':' in scp-style path ${W(t)}; use the ssh:// url form instead`);if(e.startsWith(`/`)||e.startsWith(`~`))throw y(`not a supported git url: ambiguous absolute/home-relative scp path in ${W(t)}; use the ssh:// url form instead`)},ff=(e,t)=>{let n=e.groups?.path??``;return df(n,t),of({host:e.groups?.host??``,path:n,port:``,protocol:`ssh:`})},pf=(e,t)=>{if(tf(e))throw y(`not a supported git url: backslash not allowed in ${W(t)}`)},mf=(e,t)=>{if(ef(e))throw y(`not a supported git url: path traversal segment in ${W(t)}`)},hf=(e,t,n)=>{if(e.protocol!==`file:`&&nf(t))throw y(`not a supported git url: percent-encoding not supported in ${W(n)}`)},gf=(e,t)=>{let n=t?.allowFileUrls??!1,r=e.replace(Qd,``);pf(r,e),mf(r,e);let i=Zd.exec(r);if(i?.groups!==void 0)return{cloneUrl:r,key:ff(i,e)};let a=cf(r,e);return hf(a,r,e),{cloneUrl:r,key:uf(a,n)}},_f=`.git`,vf=e=>e.endsWith(_f)?e:`${e}${_f}`,yf=(e,t)=>`https://${e.toLowerCase()}/${Xd(t)}`,bf=(e,t)=>`git@${e.toLowerCase()}:${vf(Xd(t))}`,xf=e=>{if(e===`https:`)return`https`;if(e===`ssh:`)return`ssh`;throw y(`not a supported git url: unsupported protocol ${e}`)},Sf=(e,t,n)=>{let r=$d[e.protocol];if(e.port!==``&&e.port!==r)throw y(`cannot apply git_transport=${t} to ${W(n)}: its non-default port ${e.port} cannot be expressed in the ${t} url form — add the repo with an explicit url instead`)},Cf=(e,t)=>t===`https`?yf(e.hostname,e.pathname):bf(e.hostname,e.pathname),wf=(e,t,n)=>{let r=gf(t).key;if(r!==n)throw y(`git_transport transform changed repo identity: '${W(e)}' → '${t}' (key '${n}' → '${r}')`);return t},Tf=(e,t)=>{if(t.transport===`ssh`)return t.cloneUrl;let n=e.groups?.host??``,r=e.groups?.path??``;return wf(t.cloneUrl,yf(n,r),t.originalKey)},Ef=e=>{let t=cf(e.cloneUrl,e.cloneUrl);return xf(t.protocol)===e.transport?e.cloneUrl:(Sf(t,e.transport,e.cloneUrl),wf(e.cloneUrl,Cf(t,e.transport),e.originalKey))},Df=(e,t)=>{if(e.startsWith(`file:`))return e;let n={cloneUrl:e,originalKey:gf(e).key,transport:t},r=Zd.exec(e);return r?.groups===void 0?Ef(n):Tf(r,n)},Of=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u,kf=(e,t)=>{if(Of.test(t))return m(e,`lease-${t}`)},Af=async(e,t)=>{let n=kf(e,t);n!==void 0&&await(await o(n,`w`)).close()},jf=async(e,t)=>{let n=kf(e,t);if(n===void 0)return`gone`;let r=new Date;try{await ee(n,r,r)}catch(e){if(R(e))return`gone`;throw e}return`renewed`},Mf=async(e,t)=>{let n=kf(e,t);if(n===void 0)return{state:`absent`};try{return{mtimeMs:(await p(n)).mtimeMs,state:`ok`}}catch(e){return{state:R(e)?`absent`:`unreadable`}}},Nf=`meta.json`,Pf=e=>{if(typeof e==`object`&&e&&`code`in e){let{code:t}=e;if(typeof t==`string`)return t}},Ff=e=>{try{return process.kill(e,0),!0}catch(e){return Pf(e)!==`ESRCH`}},If=e=>{try{return JSON.parse(e)}catch{return}},Lf=async e=>{try{return await s(e,`utf8`)}catch{return}},Rf=new Set([`ENOENT`,`ENOTDIR`]),zf=async e=>{try{return{state:`read`,text:await s(e,`utf8`)}}catch(e){let t=Pf(e);return{state:t!==void 0&&Rf.has(t)?`missing`:`unreadable`}}},Bf=e=>{if(typeof e!=`string`)return;let t=Date.parse(e);if(!Number.isNaN(t))return t},Vf=e=>{if(typeof e!=`object`||!e)return;let{token:t}=e;if(typeof t==`string`)return t},Hf=e=>{if(!(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0||e>2147483647))return e},Uf=e=>{if(typeof e!=`object`||!e)return;let t=e,n=Hf(t.pid),r=Bf(t.acquired_at);if(n===void 0||r===void 0)return;let i=Vf(e);return{acquiredAtMs:r,pid:n,...i===void 0?{}:{token:i}}},Wf=async e=>{let t=await Lf(m(e,Nf));if(t!==void 0)return Vf(If(t))},Gf=async e=>{let t=await zf(m(e,Nf));if(t.state!==`read`)return{state:t.state};let n=Uf(If(t.text));return n===void 0?{state:`malformed`}:{meta:n,state:`valid`}},Kf=async e=>{try{return{mtimeMs:(await p(e)).mtimeMs,state:`ok`}}catch(e){return{state:Pf(e)===`ENOENT`?`gone`:`unreadable`}}},qf=async(e,t)=>{let n=m(e,Nf),r=`${n}.tmp-${de()}`;await te(r,t,`utf8`),await u(r,n)},Jf=()=>de(),Yf=async(e,t)=>{await Af(e,t),await qf(e,JSON.stringify({acquired_at:new Date().toISOString(),pid:process.pid,token:t}))},Xf=5e3,Zf=async(e,t,n)=>{if(t===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let r=await Kf(e);if(r.state===`gone`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`none`,stale:!1};if(r.state===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let i=n-r.mtimeMs;return{ageMs:i,budgetMs:Xf,meta:t,observedAtMs:n,pidState:`unknown`,policy:`grace`,stale:i>Xf}},Qf=async(e,t,n)=>{let r=t.token===void 0?{state:`absent`}:await Mf(e,t.token);return r.state===`unreadable`?{policy:`unknown`}:r.state===`absent`?{ageMs:n-t.acquiredAtMs,budgetMs:6e5,policy:`legacy`}:{ageMs:n-r.mtimeMs,budgetMs:12e4,policy:`lease`}},$f=async(e,t)=>{let n=await Gf(e);if(n.state!==`valid`)return Zf(e,n.state,t);let{meta:r}=n,i=await Qf(e,r,t),a=!Ff(r.pid),o=i.ageMs!==void 0&&i.budgetMs!==void 0&&i.ageMs>i.budgetMs;return{...i,meta:`valid`,observedAtMs:t,pid:r.pid,pidState:a?`definitely-dead`:`present-or-unknown`,stale:a||o,...r.token===void 0?{}:{token:r.token}}},ep=e=>e.meta===`valid`&&e.pidState===`definitely-dead`&&e.token!==void 0,tp=async(e,t)=>await Wf(e)===t?await jf(e,t)===`gone`?`lost`:`renewed`:`lost`,np=new Set([`EEXIST`,`EPERM`,`EACCES`,`EBUSY`]),rp=new Set([`ENOENT`,`EPERM`,`EACCES`,`EBUSY`]),ip=async e=>{try{return await a(e,{recursive:!1}),!0}catch(e){let t=Pf(e);if(t!==void 0&&np.has(t))return!1;throw e}},ap=async(e,t)=>{try{return await u(e,t),!0}catch(e){let t=Pf(e);if(t!==void 0&&rp.has(t))return!1;throw e}},op=`.claims`,sp=`.tombstones`,cp=(e,t)=>({lockPath:m(e,t),locksDir:e,name:t}),lp=e=>m(e.locksDir,op,e.name),up=e=>m(e.locksDir,sp,de()),dp=async e=>{await a(m(e,op),{recursive:!0}),await a(m(e,sp),{recursive:!0})},fp=e=>ip(e),pp=async e=>{try{await f(e)}catch{}},mp=async e=>{let t=up(e);return await ap(e.lockPath,t)?t:void 0},hp=async e=>{let t=await $f(e.lockPath,Date.now());if(!ep(t)||await Wf(e.lockPath)!==t.token)return!1;let n=await mp(e);return n!==void 0&&(await d(n,{force:!0,recursive:!0}),!0)},gp=async e=>{await dp(e.locksDir);let t=lp(e);if(!await fp(t))return!1;let n=await hp(e).then(e=>({ok:!0,stolen:e}),e=>({error:e,ok:!1}));if(await pp(t),!n.ok)throw n.error;return n.stolen},_p=async e=>{try{return(await c(e,{withFileTypes:!0})).map(e=>({isDir:e.isDirectory(),name:e.name})).toSorted((e,t)=>e.name.localeCompare(t.name))}catch(e){if(R(e))return[];throw e}},vp=async e=>(await _p(e)).filter(e=>!e.name.startsWith(`.`)),yp=async(e,t,n)=>{let r=await $f(m(e,t.name),n);if(r.policy!==`none`)return{diagnosis:r,isDirectory:t.isDir,kind:`lock`,name:t.name}},bp=async(e,t)=>{let n=m(e,op),r=await _p(n);return(await Promise.all(r.map(async e=>({diagnosis:await $f(m(n,e.name),t),isDirectory:e.isDir,kind:`claim`,name:e.name})))).filter(e=>e.diagnosis.policy!==`none`)},xp=async e=>{let t=Date.now(),n=await vp(e.locksDir),[r,i]=await Promise.all([Promise.all(n.map(n=>yp(e.locksDir,n,t))),bp(e.locksDir,t)]);return[...r.filter(e=>e!==void 0),...i]},Sp=e=>{let t=Math.floor(e/1e3),n=t%60,r=Math.floor(t/60),i=r%60,a=Math.floor(r/60);return a>0?i===0?`${a}h`:`${a}h ${i}m`:r>0?n===0?`${r}m`:`${r}m ${n}s`:`${n}s`},Cp=e=>e.pid===void 0?`owner unknown (metadata ${e.meta})`:e.pidState===`definitely-dead`?`recorded pid ${e.pid} is not running`:`recorded pid ${e.pid} is present (identity not verified)`,wp={grace:`created`,lease:`lease renewed`,legacy:`acquired`,none:`observed`,unknown:`observed`},Tp={grace:`from creation, while its metadata has not been published`,lease:`from the last renewal`,legacy:`from acquisition (no renewable lease)`,none:``,unknown:``},Ep=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return t===void 0||n===void 0?``:t<0?`, but its recorded time is in the future — check the system clock`:`, ${wp[r]} ${Sp(t)} ago; its window is ${Sp(n)} ${Tp[r]}`},Dp=(e,t)=>{if(t.policy===`none`)return`lock ${e} could not be acquired before the timeout, but it was released while the failure was being diagnosed. Retry the operation.`;let n=`lock ${e} is held: ${Cp(t)}`;return ep(t)?`${n}, and refs is entitled to reclaim it — it could not do so before the timeout. Retry; if it persists, run refs doctor.`:t.stale?`${n}${Ep(t)}. refs does not reclaim this automatically: only a recorded process the operating system reports as gone is reclaimed, and this one is not. Run refs doctor for what to do about it.`:`${n}${Ep(t)}. Retry once the other refs command finishes.`},Op=(e,t)=>{if(t.stopped)return;let n=setTimeout(()=>{t.stopped||(t.inFlight=kp(e,t))},e.intervalMs);n.unref(),t.timer=n},kp=async(e,t)=>{try{if(await e.renew()===`lost`){t.lost=!0,t.stopped=!0;return}}catch{}Op(e,t)},Ap=e=>{let t={inFlight:Promise.resolve(),lost:!1,stopped:!1};return Op(e,t),{ownershipLost:()=>t.lost,stop:async()=>{t.stopped=!0,t.timer!==void 0&&clearTimeout(t.timer),await t.inFlight}}},jp=/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/u,Mp=async(e,t)=>{try{await Yf(e,t)}catch(e){if(Pf(e)===`ENOENT`)return`retry`;throw e}return t},Np=async(e,t)=>{if(!await ip(e))return;let n=await Mp(e,Jf());return n===`retry`?Date.now()>=t?void 0:Np(e,t):n},Pp=async(e,t)=>{if(!await gp(e)){if(Date.now()>=t){let t=await $f(e.lockPath,Date.now());throw Ce(Dp(e.name,t))}await ge(100)}},Fp=async(e,t)=>{let n=await Np(e.lockPath,t);return n===void 0?(await Pp(e,t),Fp(e,t)):n},Ip=async(e,t)=>await Wf(e)===t&&(await d(e,{force:!0,recursive:!0}),!0),Lp=async e=>{try{return{ok:!0,value:await e()}}catch(e){return{error:e,ok:!1}}},Rp=async(e,t,n,r)=>{await n.stop();let i=await Lp(()=>Ip(e.lockPath,t));if(!r.ok)throw r.error;if(!i.ok)throw i.error;if(n.ownershipLost()||!i.value)throw Ce(`lock ${e.name} was lost while the operation was running`);return r.value},zp=e=>e!==`.`&&e!==`..`&&jp.test(e),Bp=e=>{if(!zp(e))throw y(`lock name must not contain "/" or other unsafe characters — only letters, digits, and "_.-" are allowed, and it may not be "." or "..": ${e}`)},G=async(e,t,n,r)=>{Bp(t);let i=cp(e.locksDir,t);await a(e.locksDir,{recursive:!0});let o=Date.now()+(r?.timeoutMs??1e4),s=await Fp(i,o),c=Ap({intervalMs:3e4,renew:()=>tp(i.lockPath,s)});return Rp(i,s,c,await Lp(n))},Vp=sc({directory:P().optional(),url:P().optional()}),Hp=sc({repository:lc([P(),Vp]).optional()}),Up=/^(?:@[a-z0-9-~][a-z0-9._~-]*\/)?[a-z0-9-~][a-z0-9._~-]*$/u,Wp=new Set([`node_modules`,`favicon.ico`]),Gp=e=>_(`package '${e}' has no usable repository field — find the repository and run: refs add <git-url>`),Kp=e=>{let[t,n]=e.split(`/`);return n??t??e},qp=e=>{if(e.length>214)throw v(`invalid package name: '${e}' exceeds maximum length of 214 characters`);if(!Up.test(e))throw v(`invalid package name: '${e}' does not match npm naming rules`);let t=Kp(e);if(Wp.has(t))throw v(`invalid package name: '${e}' uses a reserved name`)},Jp=e=>e.replaceAll(`/`,`%2F`),Yp=e=>typeof e==`string`?e:e?.url,Xp=e=>{if(typeof e==`object`&&e?.directory){let t=ul.safeParse(e.directory);if(t.success)return t.data}},Zp=async(e,t)=>{try{return await e.json()}catch{throw y(`invalid npm registry response for '${t}': not parseable JSON`)}},Qp=async(e,t)=>{let n=await e(`https://registry.npmjs.org/${Jp(t)}`);if(n.status===404)throw _(`npm package '${t}' not found`);if(n.status!==200)throw y(`failed to fetch npm package '${t}': status ${n.status}`);let r=await Zp(n,t),i=Hp.safeParse(r);if(!i.success)throw y(`invalid npm package response for '${t}'`);return i.data},$p=(e,t)=>{try{return gf(e)}catch{throw Gp(t)}},em=async(e,t)=>{qp(t);let n=await Qp(e,t),r=Yp(n.repository);if(r===void 0||r===``)throw Gp(t);let{cloneUrl:i,key:a}=$p(r,t),o=Xp(n.repository);return o===void 0?{cloneUrl:i,key:a}:{cloneUrl:i,directory:o,key:a}},tm=(e,t,n)=>{let r=e instanceof RegExp?nm(e,n):e,i=t instanceof RegExp?nm(t,n):t,a=r!==null&&i!=null&&rm(r,i,n);return a&&{start:a[0],end:a[1],pre:n.slice(0,a[0]),body:n.slice(a[0]+r.length,a[1]),post:n.slice(a[1]+i.length)}},nm=(e,t)=>{let n=t.match(e);return n?n[0]:null},rm=(e,t,n)=>{let r,i,a,o,s,c=n.indexOf(e),l=n.indexOf(t,c+1),u=c;if(c>=0&&l>0){if(e===t)return[c,l];for(r=[],a=n.length;u>=0&&!s;){if(u===c)r.push(u),c=n.indexOf(e,u+1);else if(r.length===1){let e=r.pop();e!==void 0&&(s=[e,l])}else i=r.pop(),i!==void 0&&i<a&&(a=i,o=l),l=n.indexOf(t,u+1);u=c<l&&c>=0?c:l}r.length&&o!==void 0&&(s=[a,o])}return s},im=`\0SLASH`+Math.random()+`\0`,am=`\0OPEN`+Math.random()+`\0`,om=`\0CLOSE`+Math.random()+`\0`,sm=`\0COMMA`+Math.random()+`\0`,cm=`\0PERIOD`+Math.random()+`\0`,lm=new RegExp(im,`g`),um=new RegExp(am,`g`),dm=new RegExp(om,`g`),fm=new RegExp(sm,`g`),pm=new RegExp(cm,`g`),mm=/\\\\/g,hm=/\\{/g,gm=/\\}/g,_m=/\\,/g,vm=/\\\./g;function ym(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function bm(e){return e.replace(mm,im).replace(hm,am).replace(gm,om).replace(_m,sm).replace(vm,cm)}function xm(e){return e.replace(lm,`\\`).replace(um,`{`).replace(dm,`}`).replace(fm,`,`).replace(pm,`.`)}function Sm(e){if(!e)return[``];let t=[],n=tm(`{`,`}`,e);if(!n)return e.split(`,`);let{pre:r,body:i,post:a}=n,o=r.split(`,`);o[o.length-1]+=`{`+i+`}`;let s=Sm(a);return a.length&&(o[o.length-1]+=s.shift(),o.push.apply(o,s)),t.push.apply(t,o),t}function Cm(e,t={}){if(!e)return[];let{max:n=1e5,maxLength:r=4e6}=t;return e.slice(0,2)===`{}`&&(e=`\\{\\}`+e.slice(2)),Am(bm(e),n,r,!0).map(xm)}function wm(e){return`{`+e+`}`}function Tm(e){return/^-?0\d/.test(e)}function Em(e,t){return e<=t}function Dm(e,t){return e>=t}function Om(e,t,n,r,i,a){let o=[],s=0;for(let c=0;c<e.length;c++)for(let l=0;l<n.length;l++){if(o.length>=r)return o;let u=e[c]+t+n[l];if(!a||u){if(s+u.length>i)return o;o.push(u),s+=u.length}}return o}function km(e,t,n,r){let i=e.split(/\.\./),a=[];if(i[0]===void 0||i[1]===void 0)return a;let o=ym(i[0]),s=ym(i[1]),c=Math.max(i[0].length,i[1].length),l=i.length===3&&i[2]!==void 0?Math.max(Math.abs(ym(i[2])),1):1,u=Em;s<o&&(l*=-1,u=Dm);let d=i.some(Tm),f=0;for(let e=o;u(e,s)&&a.length<n;e+=l){let n;if(t)n=String.fromCharCode(e),n===`\\`&&(n=``);else if(n=String(e),d){let t=c-n.length;if(t>0){let r=Array(t+1).join(`0`);n=e<0?`-`+r+n.slice(1):r+n}}if(f+n.length>r)break;a.push(n),f+=n.length}return a}function Am(e,t,n,r){let i=[``],a=!1,o=!0;for(;;){let s=tm(`{`,`}`,e);if(!s)return Om(i,e,[``],t,n,a);let c=s.pre;if(/\$$/.test(c)){if(i=Om(i,c+`{`+s.body+`}`,[``],t,n,a&&!s.post.length),o=!1,!s.post.length)break;e=s.post;continue}let l=/^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(s.body),u=/^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(s.body),d=l||u,f=s.body.indexOf(`,`)>=0;if(!d&&!f){if(s.post.match(/,(?!,).*\}/)){e=s.pre+`{`+s.body+om+s.post,r=!0;continue}return Om(i,c+`{`+s.body+`}`+s.post,[``],t,n,a)}o&&=(a=r&&!d,!1);let p;if(d)p=km(s.body,u,t,n);else{let r=Sm(s.body);if(r.length===1&&r[0]!==void 0&&(r=Am(r[0],t,n,!1).map(wm),r.length===1)){if(i=Om(i,c+r[0],[``],t,n,a&&!s.post.length),!s.post.length)break;e=s.post;continue}let o=a&&!s.post.length&&!c;for(let e=0;o&&e<i.length;e++)i[e]&&(o=!1);p=[];let l=0;outer:for(let e=0;e<r.length;e++){let i=Am(r[e],t,n,!1);for(let e=0;e<i.length;e++){let r=i[e];if(!o||r){if(p.length>=t||l+r.length>n)break outer;p.push(r),l+=r.length}}}}if(i=Om(i,c,p,t,n,a&&!s.post.length),!s.post.length)break;e=s.post}return i}const jm=e=>{if(typeof e!=`string`)throw TypeError(`invalid pattern`);if(e.length>65536)throw TypeError(`pattern is too long`)},Mm={"[:alnum:]":[`\\p{L}\\p{Nl}\\p{Nd}`,!0],"[:alpha:]":[`\\p{L}\\p{Nl}`,!0],"[:ascii:]":[`\\x00-\\x7f`,!1],"[:blank:]":[`\\p{Zs}\\t`,!0],"[:cntrl:]":[`\\p{Cc}`,!0],"[:digit:]":[`\\p{Nd}`,!0],"[:graph:]":[`\\p{Z}\\p{C}`,!0,!0],"[:lower:]":[`\\p{Ll}`,!0],"[:print:]":[`\\p{C}`,!0],"[:punct:]":[`\\p{P}`,!0],"[:space:]":[`\\p{Z}\\t\\r\\n\\v\\f`,!0],"[:upper:]":[`\\p{Lu}`,!0],"[:word:]":[`\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}`,!0],"[:xdigit:]":[`A-Fa-f0-9`,!1]},Nm=e=>e.replace(/[[\]\\-]/g,`\\$&`),Pm=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),Fm=e=>e.join(``),Im=(e,t)=>{let n=t;if(e.charAt(n)!==`[`)throw Error(`not in a brace expression`);let r=[],i=[],a=n+1,o=!1,s=!1,c=!1,l=!1,u=n,d=``;WHILE:for(;a<e.length;){let t=e.charAt(a);if((t===`!`||t===`^`)&&a===n+1){l=!0,a++;continue}if(t===`]`&&o&&!c){u=a+1;break}if(o=!0,t===`\\`&&!c){c=!0,a++;continue}if(t===`[`&&!c){for(let[t,[o,c,l]]of Object.entries(Mm))if(e.startsWith(t,a)){if(d)return[`$.`,!1,e.length-n,!0];a+=t.length,l?i.push(o):r.push(o),s||=c;continue WHILE}}if(c=!1,d){t>d?r.push(Nm(d)+`-`+Nm(t)):t===d&&r.push(Nm(t)),d=``,a++;continue}if(e.startsWith(`-]`,a+1)){r.push(Nm(t+`-`)),a+=2;continue}if(e.startsWith(`-`,a+1)){d=t,a+=2;continue}r.push(Nm(t)),a++}if(u<a)return[``,!1,0,!1];if(!r.length&&!i.length)return[`$.`,!1,e.length-n,!0];if(i.length===0&&r.length===1&&/^\\?.$/.test(r[0])&&!l){let e=r[0].length===2?r[0].slice(-1):r[0];return[Pm(e),!1,u-n,!1]}let f=`[`+(l?`^`:``)+Fm(r)+`]`,p=`[`+(l?``:`^`)+Fm(i)+`]`;return[r.length&&i.length?`(`+f+`|`+p+`)`:r.length?f:p,s,u-n,!0]},Lm=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!0}={})=>n?t?e.replace(/\[([^/\\])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^/\\])\]/g,`$1$2`).replace(/\\([^/])/g,`$1`):t?e.replace(/\[([^/\\{}])\]/g,`$1`):e.replace(/((?!\\).|^)\[([^/\\{}])\]/g,`$1$2`).replace(/\\([^/{}])/g,`$1`);var K;const Rm=new Set([`!`,`?`,`+`,`*`,`@`]),zm=e=>Rm.has(e),Bm=e=>zm(e.type),Vm=new Map([[`!`,[`@`]],[`?`,[`?`,`@`]],[`@`,[`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`]]]),Hm=new Map([[`!`,[`?`]],[`@`,[`?`]],[`+`,[`?`,`*`]]]),Um=new Map([[`!`,[`?`,`@`]],[`?`,[`?`,`@`]],[`@`,[`?`,`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`,`?`,`*`]]]),Wm=new Map([[`!`,new Map([[`!`,`@`]])],[`?`,new Map([[`*`,`*`],[`+`,`*`]])],[`@`,new Map([[`!`,`!`],[`?`,`?`],[`@`,`@`],[`*`,`*`],[`+`,`+`]])],[`+`,new Map([[`?`,`*`],[`*`,`*`]])]]),Gm=`(?!\\.)`,Km=new Set([`[`,`.`]),qm=new Set([`..`,`.`]),Jm=new Set(`().*{}+?[]^$\\!`),Ym=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),Xm=`[^/]+?`;let Zm=0;var Qm=class{type;#e;#t;#n=!1;#r=[];#i;#a;#o;#s=!1;#c;#l;#u=!1;id=++Zm;get depth(){return(this.#i?.depth??-1)+1}[Symbol.for(`nodejs.util.inspect.custom`)](){return{"@@type":`AST`,id:this.id,type:this.type,root:this.#e.id,parent:this.#i?.id,depth:this.depth,partsLength:this.#r.length,parts:this.#r}}constructor(e,t,n={}){this.type=e,e&&(this.#t=!0),this.#i=t,this.#e=this.#i?this.#i.#e:this,this.#c=this.#e===this?n:this.#e.#c,this.#o=this.#e===this?[]:this.#e.#o,e===`!`&&!this.#e.#s&&this.#o.push(this),this.#a=this.#i?this.#i.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let e of this.#r)if(typeof e!=`string`&&(e.type||e.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#l===void 0?this.#l=this.type?this.type+`(`+this.#r.map(e=>String(e)).join(`|`)+`)`:this.#r.map(e=>String(e)).join(``):this.#l}#d(){if(this!==this.#e)throw Error(`should only call on root`);if(this.#s)return this;this.toString(),this.#s=!0;let e;for(;e=this.#o.pop();){if(e.type!==`!`)continue;let t=e,n=t.#i;for(;n;){for(let r=t.#a+1;!n.type&&r<n.#r.length;r++)for(let t of e.#r){if(typeof t==`string`)throw Error(`string part in extglob AST??`);t.copyIn(n.#r[r])}t=n,n=t.#i}}return this}push(...e){for(let t of e)if(t!==``){if(typeof t!=`string`&&!(t instanceof K&&t.#i===this))throw Error(`invalid part: `+t);this.#r.push(t)}}toJSON(){let e=this.type===null?this.#r.slice().map(e=>typeof e==`string`?e:e.toJSON()):[this.type,...this.#r.map(e=>e.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#s&&this.#i?.type===`!`)&&e.push({}),e}isStart(){if(this.#e===this)return!0;if(!this.#i?.isStart())return!1;if(this.#a===0)return!0;let e=this.#i;for(let t=0;t<this.#a;t++){let n=e.#r[t];if(!(n instanceof K&&n.type===`!`))return!1}return!0}isEnd(){if(this.#e===this||this.#i?.type===`!`)return!0;if(!this.#i?.isEnd())return!1;if(!this.type)return this.#i?.isEnd();let e=this.#i?this.#i.#r.length:0;return this.#a===e-1}copyIn(e){typeof e==`string`?this.push(e):this.push(e.clone(this))}clone(e){let t=new K(this.type,e);for(let e of this.#r)t.copyIn(e);return t}static#f(e,t,n,r,i){let a=r.maxExtglobRecursion??2,o=!1,s=!1,c=-1,l=!1;if(t.type===null){let u=n,d=``;for(;u<e.length;){let n=e.charAt(u++);if(o||n===`\\`){o=!o,d+=n;continue}if(s){u===c+1?(n===`^`||n===`!`)&&(l=!0):n===`]`&&!(u===c+2&&l)&&(s=!1),d+=n;continue}if(n===`[`){s=!0,c=u,l=!1,d+=n;continue}if(!r.noext&&zm(n)&&e.charAt(u)===`(`&&i<=a){t.push(d),d=``;let a=new K(n,t);u=K.#f(e,a,u,r,i+1),t.push(a);continue}d+=n}return t.push(d),u}let u=n+1,d=new K(null,t),f=[],p=``;for(;u<e.length;){let n=e.charAt(u++);if(o||n===`\\`){o=!o,p+=n;continue}if(s){u===c+1?(n===`^`||n===`!`)&&(l=!0):n===`]`&&!(u===c+2&&l)&&(s=!1),p+=n;continue}if(n===`[`){s=!0,c=u,l=!1,p+=n;continue}if(!r.noext&&zm(n)&&e.charAt(u)===`(`&&(i<=a||t&&t.#h(n))){let a=t&&t.#h(n)?0:1;d.push(p),p=``;let o=new K(n,d);d.push(o),u=K.#f(e,o,u,r,i+a);continue}if(n===`|`){d.push(p),p=``,f.push(d),d=new K(null,t);continue}if(n===`)`)return p===``&&t.#r.length===0&&(t.#u=!0),d.push(p),p=``,t.push(...f,d),u;p+=n}return t.type=null,t.#t=void 0,t.#r=[e.substring(n-1)],u}#p(e){return this.#m(e,Hm)}#m(e,t=Vm){if(!e||typeof e!=`object`||e.type!==null||e.#r.length!==1||this.type===null)return!1;let n=e.#r[0];return!n||typeof n!=`object`||n.type===null?!1:this.#h(n.type,t)}#h(e,t=Um){return!!t.get(this.type)?.includes(e)}#g(e,t){let n=e.#r[0],r=new K(null,n,this.options);r.#r.push(``),n.push(r),this.#_(e,t)}#_(e,t){let n=e.#r[0];this.#r.splice(t,1,...n.#r);for(let e of n.#r)typeof e==`object`&&(e.#i=this);this.#l=void 0}#v(e){return!!Wm.get(this.type)?.has(e)}#y(e){if(!e||typeof e!=`object`||e.type!==null||e.#r.length!==1||this.type===null||this.#r.length!==1)return!1;let t=e.#r[0];return!t||typeof t!=`object`||t.type===null?!1:this.#v(t.type)}#b(e){let t=Wm.get(this.type),n=e.#r[0],r=t?.get(n.type);if(!r)return!1;this.#r=n.#r;for(let e of this.#r)typeof e==`object`&&(e.#i=this);this.type=r,this.#l=void 0,this.#u=!1}static fromGlob(e,t={}){let n=new K(null,void 0,t);return K.#f(e,n,0,t,0),n}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let e=this.toString(),[t,n,r,i]=this.toRegExpSource();if(!(r||this.#t||this.#c.nocase&&!this.#c.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return n;let a=(this.#c.nocase?`i`:``)+(i?`u`:``);return Object.assign(RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return this.#c}toRegExpSource(e){let t=e??!!this.#c.dot;if(this.#e===this&&(this.#x(),this.#d()),!Bm(this)){let n=this.isStart()&&this.isEnd()&&!this.#r.some(e=>typeof e!=`string`),r=this.#r.map(t=>{let[r,i,a,o]=typeof t==`string`?K.#C(t,this.#t,n):t.toRegExpSource(e);return this.#t=this.#t||a,this.#n=this.#n||o,r}).join(``),i=``;if(this.isStart()&&typeof this.#r[0]==`string`&&!(this.#r.length===1&&qm.has(this.#r[0]))){let n=Km,a=t&&n.has(r.charAt(0))||r.startsWith(`\\.`)&&n.has(r.charAt(2))||r.startsWith(`\\.\\.`)&&n.has(r.charAt(4)),o=!t&&!e&&n.has(r.charAt(0));i=a?`(?!(?:^|/)\\.\\.?(?:$|/))`:o?Gm:``}let a=``;return this.isEnd()&&this.#e.#s&&this.#i?.type===`!`&&(a=`(?:$|\\/)`),[i+r+a,Lm(r),this.#t=!!this.#t,this.#n]}let n=this.type===`*`||this.type===`+`,r=this.type===`!`?`(?:(?!(?:`:`(?:`,i=this.#S(t);if(this.isStart()&&this.isEnd()&&!i&&this.type!==`!`){let e=this.toString(),t=this;return t.#r=[e],t.type=null,t.#t=void 0,[e,Lm(this.toString()),!1,!1]}let a=!n||e||t?``:this.#S(!0);a===i&&(a=``),a&&(i=`(?:${i})(?:${a})*?`);let o=``;if(this.type===`!`&&this.#u)o=(this.isStart()&&!t?Gm:``)+Xm;else{let n=this.type===`!`?`))`+(this.isStart()&&!t&&!e?Gm:``)+`[^/]*?)`:this.type===`@`?`)`:this.type===`?`?`)?`:this.type===`+`&&a?`)`:this.type===`*`&&a?`)?`:`)${this.type}`;o=r+i+n}return[o,Lm(i),this.#t=!!this.#t,this.#n]}#x(){if(Bm(this)){let e=0,t=!1;do{t=!0;for(let e=0;e<this.#r.length;e++){let n=this.#r[e];typeof n==`object`&&(n.#x(),this.#m(n)?(t=!1,this.#_(n,e)):this.#p(n)?(t=!1,this.#g(n,e)):this.#y(n)&&(t=!1,this.#b(n)))}}while(!t&&++e<10)}else for(let e of this.#r)typeof e==`object`&&e.#x();this.#l=void 0}#S(e){return this.#r.map(t=>{if(typeof t==`string`)throw Error(`string type in extglob ast??`);let[n,r,i,a]=t.toRegExpSource(e);return this.#n=this.#n||a,n}).filter(e=>!(this.isStart()&&this.isEnd())||!!e).join(`|`)}static#C(e,t,n=!1){let r=!1,i=``,a=!1,o=!1;for(let s=0;s<e.length;s++){let c=e.charAt(s);if(r){r=!1,i+=(Jm.has(c)?`\\`:``)+c;continue}if(c===`*`){if(o)continue;o=!0,i+=n&&/^[*]+$/.test(e)?Xm:`[^/]*?`,t=!0;continue}if(o=!1,c===`\\`){s===e.length-1?i+=`\\\\`:r=!0;continue}if(c===`[`){let[n,r,o,c]=Im(e,s);if(o){i+=n,a||=r,s+=o-1,t||=c;continue}}if(c===`?`){i+=`[^/]`,t=!0;continue}i+=Ym(c)}return[i,Lm(e),!!t,a]}};K=Qm;const $m=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,`[$&]`):e.replace(/[?*()[\]\\{}]/g,`\\$&`):t?e.replace(/[?*()[\]]/g,`[$&]`):e.replace(/[?*()[\]\\]/g,`\\$&`),q=(e,t,n={})=>(jm(t),!n.nocomment&&t.charAt(0)===`#`?!1:new Th(t,n).match(e)),eh=/^\*+([^+@!?*[(]*)$/,th=e=>t=>!t.startsWith(`.`)&&t.endsWith(e),nh=e=>t=>t.endsWith(e),rh=e=>(e=e.toLowerCase(),t=>!t.startsWith(`.`)&&t.toLowerCase().endsWith(e)),ih=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),ah=/^\*+\.\*+$/,oh=e=>!e.startsWith(`.`)&&e.includes(`.`),sh=e=>e!==`.`&&e!==`..`&&e.includes(`.`),ch=/^\.\*+$/,lh=e=>e!==`.`&&e!==`..`&&e.startsWith(`.`),uh=/^\*+$/,dh=e=>e.length!==0&&!e.startsWith(`.`),fh=e=>e.length!==0&&e!==`.`&&e!==`..`,ph=/^\?+([^+@!?*[(]*)?$/,mh=([e,t=``])=>{let n=vh([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},hh=([e,t=``])=>{let n=yh([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},gh=([e,t=``])=>{let n=yh([e]);return t?e=>n(e)&&e.endsWith(t):n},_h=([e,t=``])=>{let n=vh([e]);return t?e=>n(e)&&e.endsWith(t):n},vh=([e])=>{let t=e.length;return e=>e.length===t&&!e.startsWith(`.`)},yh=([e])=>{let t=e.length;return e=>e.length===t&&e!==`.`&&e!==`..`},bh=typeof process==`object`&&process?typeof process.env==`object`&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:`posix`,xh={win32:{sep:`\\`},posix:{sep:`/`}};q.sep=bh===`win32`?xh.win32.sep:xh.posix.sep;const J=Symbol(`globstar **`);q.GLOBSTAR=J,q.filter=(e,t={})=>n=>q(n,e,t);const Y=(e,t={})=>Object.assign({},e,t);q.defaults=e=>{if(!e||typeof e!=`object`||!Object.keys(e).length)return q;let t=q;return Object.assign((n,r,i={})=>t(n,r,Y(e,i)),{Minimatch:class extends t.Minimatch{constructor(t,n={}){super(t,Y(e,n))}static defaults(n){return t.defaults(Y(e,n)).Minimatch}},AST:class extends t.AST{constructor(t,n,r={}){super(t,n,Y(e,r))}static fromGlob(n,r={}){return t.AST.fromGlob(n,Y(e,r))}},unescape:(n,r={})=>t.unescape(n,Y(e,r)),escape:(n,r={})=>t.escape(n,Y(e,r)),filter:(n,r={})=>t.filter(n,Y(e,r)),defaults:n=>t.defaults(Y(e,n)),makeRe:(n,r={})=>t.makeRe(n,Y(e,r)),braceExpand:(n,r={})=>t.braceExpand(n,Y(e,r)),match:(n,r,i={})=>t.match(n,r,Y(e,i)),sep:t.sep,GLOBSTAR:J})};const Sh=(e,t={})=>(jm(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:Cm(e,{max:t.braceExpandMax}));q.braceExpand=Sh,q.makeRe=(e,t={})=>new Th(e,t).makeRe(),q.match=(e,t,n={})=>{let r=new Th(t,n);return e=e.filter(e=>r.match(e)),r.options.nonull&&!e.length&&e.push(t),e};const Ch=/[?*]|[+@!]\(.*?\)|\[|\]/,wh=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`);var Th=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(e,t={}){jm(e),t||={},this.options=t,this.maxGlobstarRecursion=t.maxGlobstarRecursion??200,this.pattern=e,this.platform=t.platform||bh,this.isWindows=this.platform===`win32`,this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,`/`)),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!t.nonegate,this.comment=!1,this.empty=!1,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot===void 0?!!(this.isWindows&&this.nocase):t.windowsNoMagicRoot,this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let e of this.set)for(let t of e)if(typeof t!=`string`)return!0;return!1}debug(...e){}make(){let e=this.pattern,t=this.options;if(!t.nocomment&&e.charAt(0)===`#`){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...e)=>console.error(...e)),this.debug(this.pattern,this.globSet);let n=this.globSet.map(e=>this.slashSplit(e));this.globParts=this.preprocess(n),this.debug(this.pattern,this.globParts);let r=this.globParts.map((e,t,n)=>{if(this.isWindows&&this.windowsNoMagicRoot){let t=e[0]===``&&e[1]===``&&(e[2]===`?`||!Ch.test(e[2]))&&!Ch.test(e[3]),n=/^[a-z]:/i.test(e[0]);if(t)return[...e.slice(0,4),...e.slice(4).map(e=>this.parse(e))];if(n)return[e[0],...e.slice(1).map(e=>this.parse(e))]}return e.map(e=>this.parse(e))});if(this.debug(this.pattern,r),this.set=r.filter(e=>e.indexOf(!1)===-1),this.isWindows)for(let e=0;e<this.set.length;e++){let t=this.set[e];t[0]===``&&t[1]===``&&this.globParts[e][2]===`?`&&typeof t[3]==`string`&&/^[a-z]:$/i.test(t[3])&&(t[2]=`?`)}this.debug(this.pattern,this.set)}preprocess(e){if(this.options.noglobstar)for(let t of e)for(let e=0;e<t.length;e++)t[e]===`**`&&(t[e]=`*`);let{optimizationLevel:t=1}=this.options;return t>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):e=t>=1?this.levelOneOptimize(e):this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(e=>{let t=-1;for(;(t=e.indexOf(`**`,t+1))!==-1;){let n=t;for(;e[n+1]===`**`;)n++;n!==t&&e.splice(t,n-t)}return e})}levelOneOptimize(e){return e.map(e=>(e=e.reduce((e,t)=>{let n=e[e.length-1];return t===`**`&&n===`**`?e:t===`..`&&n&&n!==`..`&&n!==`.`&&n!==`**`?(e.pop(),e):(e.push(t),e)},[]),e.length===0?[``]:e))}levelTwoFileOptimize(e){Array.isArray(e)||(e=this.slashSplit(e));let t=!1;do{if(t=!1,!this.preserveMultipleSlashes){for(let n=1;n<e.length-1;n++){let r=e[n];(n!==1||r!==``||e[0]!==``)&&(r===`.`||r===``)&&(t=!0,e.splice(n,1),n--)}e[0]===`.`&&e.length===2&&(e[1]===`.`||e[1]===``)&&(t=!0,e.pop())}let n=0;for(;(n=e.indexOf(`..`,n+1))!==-1;){let r=e[n-1];r&&r!==`.`&&r!==`..`&&r!==`**`&&!(this.isWindows&&/^[a-z]:$/i.test(r))&&(t=!0,e.splice(n-1,2),n-=2)}}while(t);return e.length===0?[``]:e}firstPhasePreProcess(e){let t=!1;do{t=!1;for(let n of e){let r=-1;for(;(r=n.indexOf(`**`,r+1))!==-1;){let i=r;for(;n[i+1]===`**`;)i++;i>r&&n.splice(r+1,i-r);let a=n[r+1],o=n[r+2],s=n[r+3];if(a!==`..`||!o||o===`.`||o===`..`||!s||s===`.`||s===`..`)continue;t=!0,n.splice(r,1);let c=n.slice(0);c[r]=`**`,e.push(c),r--}if(!this.preserveMultipleSlashes){for(let e=1;e<n.length-1;e++){let r=n[e];(e!==1||r!==``||n[0]!==``)&&(r===`.`||r===``)&&(t=!0,n.splice(e,1),e--)}n[0]===`.`&&n.length===2&&(n[1]===`.`||n[1]===``)&&(t=!0,n.pop())}let i=0;for(;(i=n.indexOf(`..`,i+1))!==-1;){let e=n[i-1];if(e&&e!==`.`&&e!==`..`&&e!==`**`){t=!0;let e=i===1&&n[i+1]===`**`?[`.`]:[];n.splice(i-1,2,...e),n.length===0&&n.push(``),i-=2}}}}while(t);return e}secondPhasePreProcess(e){for(let t=0;t<e.length-1;t++)for(let n=t+1;n<e.length;n++){let r=this.partsMatch(e[t],e[n],!this.preserveMultipleSlashes);if(r){e[t]=[],e[n]=r;break}}return e.filter(e=>e.length)}partsMatch(e,t,n=!1){let r=0,i=0,a=[],o=``;for(;r<e.length&&i<t.length;)if(e[r]===t[i])a.push(o===`b`?t[i]:e[r]),r++,i++;else if(n&&e[r]===`**`&&t[i]===e[r+1])a.push(e[r]),r++;else if(n&&t[i]===`**`&&e[r]===t[i+1])a.push(t[i]),i++;else if(e[r]===`*`&&t[i]&&(this.options.dot||!t[i].startsWith(`.`))&&t[i]!==`**`){if(o===`b`)return!1;o=`a`,a.push(e[r]),r++,i++}else if(t[i]===`*`&&e[r]&&(this.options.dot||!e[r].startsWith(`.`))&&e[r]!==`**`){if(o===`a`)return!1;o=`b`,a.push(t[i]),r++,i++}else return!1;return e.length===t.length&&a}parseNegate(){if(this.nonegate)return;let e=this.pattern,t=!1,n=0;for(let r=0;r<e.length&&e.charAt(r)===`!`;r++)t=!t,n++;n&&(this.pattern=e.slice(n)),this.negate=t}matchOne(e,t,n=!1){let r=0,i=0;if(this.isWindows){let n=typeof e[0]==`string`&&/^[a-z]:$/i.test(e[0]),a=!n&&e[0]===``&&e[1]===``&&e[2]===`?`&&/^[a-z]:$/i.test(e[3]),o=typeof t[0]==`string`&&/^[a-z]:$/i.test(t[0]),s=!o&&t[0]===``&&t[1]===``&&t[2]===`?`&&typeof t[3]==`string`&&/^[a-z]:$/i.test(t[3]),c=a?3:n?0:void 0,l=s?3:o?0:void 0;if(typeof c==`number`&&typeof l==`number`){let[n,a]=[e[c],t[l]];n.toLowerCase()===a.toLowerCase()&&(t[l]=n,i=l,r=c)}}let{optimizationLevel:a=1}=this.options;return a>=2&&(e=this.levelTwoFileOptimize(e)),t.includes(J)?this.#e(e,t,n,r,i):this.#n(e,t,n,r,i)}#e(e,t,n,r,i){let a=t.indexOf(J,i),o=t.lastIndexOf(J),[s,c,l]=n?[t.slice(i,a),t.slice(a+1),[]]:[t.slice(i,a),t.slice(a+1,o),t.slice(o+1)];if(s.length){let t=e.slice(r,r+s.length);if(!this.#n(t,s,n,0,0))return!1;r+=s.length,i+=s.length}let u=0;if(l.length){if(l.length+r>e.length)return!1;let t=e.length-l.length;if(this.#n(e,l,n,t,0))u=l.length;else{if(e[e.length-1]!==``||r+l.length===e.length||(t--,!this.#n(e,l,n,t,0)))return!1;u=l.length+1}}if(!c.length){let t=!!u;for(let n=r;n<e.length-u;n++){let r=String(e[n]);if(t=!0,r===`.`||r===`..`||!this.options.dot&&r.startsWith(`.`))return!1}return n||t}let d=[[[],0]],f=d[0],p=0,ee=[0];for(let e of c)e===J?(ee.push(p),f=[[],0],d.push(f)):(f[0].push(e),p++);let te=d.length-1,ne=e.length-u;for(let e of d)e[1]=ne-(ee[te--]+e[0].length);return!!this.#t(e,d,r,0,n,0,!!u)}#t(e,t,n,r,i,a,o){let s=t[r];if(!s){for(let t=n;t<e.length;t++){o=!0;let n=e[t];if(n===`.`||n===`..`||!this.options.dot&&n.startsWith(`.`))return!1}return o}let[c,l]=s;for(;n<=l;){if(this.#n(e.slice(0,n+c.length),c,i,n,0)&&a<this.maxGlobstarRecursion){let s=this.#t(e,t,n+c.length,r+1,i,a+1,o);if(s!==!1)return s}let s=e[n];if(s===`.`||s===`..`||!this.options.dot&&s.startsWith(`.`))return!1;n++}return i||null}#n(e,t,n,r,i){let a,o,s,c;for(a=r,o=i,c=e.length,s=t.length;a<c&&o<s;a++,o++){this.debug(`matchOne loop`);let n=t[o],r=e[a];if(this.debug(t,n,r),n===!1||n===J)return!1;let i;if(typeof n==`string`?(i=r===n,this.debug(`string match`,n,r,i)):(i=n.test(r),this.debug(`pattern match`,n,r,i)),!i)return!1}if(a===c&&o===s)return!0;if(a===c)return n;if(o===s)return a===c-1&&e[a]===``;throw Error(`wtf?`)}braceExpand(){return Sh(this.pattern,this.options)}parse(e){jm(e);let t=this.options;if(e===`**`)return J;if(e===``)return``;let n,r=null;(n=e.match(uh))?r=t.dot?fh:dh:(n=e.match(eh))?r=(t.nocase?t.dot?ih:rh:t.dot?nh:th)(n[1]):(n=e.match(ph))?r=(t.nocase?t.dot?hh:mh:t.dot?gh:_h)(n):(n=e.match(ah))?r=t.dot?sh:oh:(n=e.match(ch))&&(r=lh);let i=Qm.fromGlob(e,this.options).toMMPattern();return r&&typeof i==`object`&&Reflect.defineProperty(i,"test",{value:r}),i}makeRe(){if(this.regexp||this.regexp===!1)return this.regexp;let e=this.set;if(!e.length)return this.regexp=!1,this.regexp;let t=this.options,n=t.noglobstar?`[^/]*?`:t.dot?`(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?`:`(?:(?!(?:\\/|^)\\.).)*?`,r=new Set(t.nocase?[`i`]:[]),i=e.map(e=>{let t=e.map(e=>{if(e instanceof RegExp)for(let t of e.flags.split(``))r.add(t);return typeof e==`string`?wh(e):e===J?J:e._src});t.forEach((e,r)=>{let i=t[r+1],a=t[r-1];e===J&&a!==J&&(a===void 0?i!==void 0&&i!==J?t[r+1]=`(?:\\/|`+n+`\\/)?`+i:t[r]=n:i===void 0?t[r-1]=a+`(?:\\/|\\/`+n+`)?`:i!==J&&(t[r-1]=a+`(?:\\/|\\/`+n+`\\/)`+i,t[r+1]=J))});let i=t.filter(e=>e!==J);if(this.partial&&i.length>=1){let e=[];for(let t=1;t<=i.length;t++)e.push(i.slice(0,t).join(`/`));return`(?:`+e.join(`|`)+`)`}return i.join(`/`)}).join(`|`),[a,o]=e.length>1?[`(?:`,`)`]:[``,``];i=`^`+a+i+o+`$`,this.partial&&(i=`^(?:\\/|`+a+i.slice(1,-1)+o+`)$`),this.negate&&(i=`^(?!`+i+`).+$`);try{this.regexp=new RegExp(i,[...r].join(``))}catch{this.regexp=!1}return this.regexp}slashSplit(e){return this.preserveMultipleSlashes?e.split(`/`):this.isWindows&&/^\/\/[^/]+/.test(e)?[``,...e.split(/\/+/)]:e.split(/\/+/)}match(e,t=this.partial){if(this.debug(`match`,e,this.pattern),this.comment)return!1;if(this.empty)return e===``;if(e===`/`&&t)return!0;let n=this.options;this.isWindows&&(e=e.split(`\\`).join(`/`));let r=this.slashSplit(e);this.debug(this.pattern,`split`,r);let i=this.set;this.debug(this.pattern,`set`,i);let a=r[r.length-1];if(!a)for(let e=r.length-2;!a&&e>=0;e--)a=r[e];for(let e of i){let i=r;if(n.matchBase&&e.length===1&&(i=[a]),this.matchOne(i,e,t))return n.flipNegate?!0:!this.negate}return!n.flipNegate&&this.negate}static defaults(e){return q.defaults(e).Minimatch}};q.AST=Qm,q.Minimatch=Th,q.escape=$m,q.unescape=Lm;const Eh=/[/\\]/u,Dh={kind:`ignore`},Oh=e=>!ae(e)&&e.split(Eh).every(e=>e!==`.`&&e!==`..`),kh=/^!+/u,Ah=/^\.?\/+/u,jh=e=>{let t=kh.exec(e)?.[0]??``;return{body:e.slice(t.length).replace(Ah,``),negated:t.length%2==1}},Mh=e=>jh(e).negated,Nh=e=>jh(e).body,Ph=/[?[\]{}()]/u,Fh=e=>Oh(e)&&!Mh(e)&&!Ph.test(e),Ih=(e,t)=>q(e,t),Lh=e=>e.replaceAll(/\/+/gu,`/`).replace(/\/$/u,``),Rh=e=>{let t=Lh(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n===-1?Dh:{baseDir:n===0?`.`:t.slice(0,n).join(`/`),kind:`expand-children`,pattern:Lh(e),suffix:t.slice(n+1).join(`/`)}},zh=e=>{let t=Lh(e).split(`/`).filter(e=>e.includes(`*`));return t.length<=1&&!t.includes(`**`)},Bh=e=>{let t=Lh(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n<=0?`.`:t.slice(0,n).join(`/`)},Vh=e=>Fh(e)?e.includes(`*`)?zh(e)?Rh(e):{baseDir:Bh(e),kind:`expand-recursive`,pattern:Lh(e)}:{dir:e,kind:`probe-dir`,pattern:e}:Dh,Hh=new Set([`candidate_not_inspected`,`scan_budget_exhausted`,`manifest_unreadable`,`unsupported_pattern`,`workspace_declaration_unparsed`,`workspace_dir_unreadable`,`workspace_file_unreadable`]),Uh=(e,t)=>t?.name?{name:t.name,path:e}:void 0,Wh=e=>{let t=e.map(e=>[e.path,e]),n=[...new Map(t).values()];return n.sort((e,t)=>e.path.localeCompare(t.path)),n},Gh=e=>!e.diagnostics.some(e=>Hh.has(e.kind)),Kh=e=>!e.diagnostics.some(e=>e.kind===`no_workspace_declaration`),qh=(e,t)=>e<t?-1:+(e>t),Jh=e=>`path`in e?`${e.kind} ${e.path}`:`file`in e?`${e.kind} ${e.file}`:`pattern`in e?`${e.kind} ${e.pattern}`:e.kind,Yh=e=>e.toSorted((e,t)=>qh(Jh(e),Jh(t))),Xh=e=>!ae(e)&&!e.split(/[/\\]/u).includes(`..`),Zh=(e,t)=>e.kind===`missing`?{kind:`absent`}:e.kind===`outside`?{kind:`unreadable`,reason:`${t} escapes the checkout`}:{kind:`unreadable`,reason:e.code},Qh=async(e,t,n)=>{if(!Xh(t))return{kind:`unreadable`,reason:`path escapes the checkout`};let r=await $h(e,t);if(`probe`in r)return r.probe;let i=await eg(r.real);return`reason`in i?{kind:`unreadable`,reason:i.reason}:i.found===n?{kind:`match`}:{found:i.found,kind:`mismatch`}},$h=async(e,t)=>{let n=await H(e,m(e,t));if(n.kind!==`inside`)return{probe:Zh(n,`path`)};let r=await H(e,m(n.real,`package.json`));return r.kind===`inside`?{real:r.real}:{probe:Zh(r,`manifest`)}},eg=async e=>{try{let t=JSON.parse(await s(e,`utf8`));return{found:Iu(t)}}catch(e){return{reason:e.code??String(e)}}},tg=(e,t)=>{let n=e.filter(e=>e.name===t).map(e=>e.path);return n.length===0?{kind:`absent`}:n.length===1?{kind:`found`,path:n[0]}:{kind:`ambiguous`,paths:n.toSorted(qh)}},ng=new Set;let rg=!1;const ig=()=>{for(let e of ng)try{e.kill(`SIGKILL`)}catch{}},ag=[`SIGINT`,`SIGTERM`,`SIGHUP`,`SIGBREAK`],og=e=>{let t=()=>{ig(),process.removeListener(e,t),process.kill(process.pid,e)};process.on(e,t)},sg=()=>{rg||(rg=!0,ag.forEach(e=>{og(e)}),process.on(`exit`,ig))},cg=()=>{let e=[],t=0,n=!1;return{finish:()=>({text:Buffer.concat(e).toString(`utf8`),truncated:n}),push:r=>{if(n)return;let i=67108864-t;if(r.length<=i){e.push(r),t+=r.length;return}i>0&&e.push(r.subarray(0,i)),n=!0}}},lg=(e,t)=>[e.replace(/\r?\n$/u,``),t].filter(e=>e!==``).join(`
328
- `),ug=(e,t,n)=>{let r=e;return t.truncated&&(r=lg(r,`refs: stdout exceeded 67108864 bytes, truncated`)),n.truncated&&(r=lg(r,`refs: stderr exceeded 67108864 bytes, truncated`)),r},dg={clear:()=>{},markedTimedOut:()=>!1},fg=(e,t)=>{if(t===void 0)return dg;let n=!1,r,i=setTimeout(()=>{n=!0,e.kill(`SIGTERM`),r=setTimeout(()=>{e.kill(`SIGKILL`)},2e3)},t);return{clear:()=>{clearTimeout(i),r!==void 0&&clearTimeout(r)},markedTimedOut:()=>n}},pg=e=>e===void 0?{}:{cwd:e},mg=(e,t)=>lg(e,`refs: command timed out after ${String(t)}ms`),hg=(e,t)=>({exitCode:124,stderr:mg(e,t),stdout:``,timedOut:!0}),gg=(e,t,n)=>{let r=be(e,t,{...pg(n?.cwd),stdio:[`ignore`,`pipe`,`pipe`]});ng.add(r);let i=cg(),a=cg();return r.stdout.on(`data`,e=>{i.push(e)}),r.stderr.on(`data`,e=>{a.push(e)}),{child:r,stderrCollector:a,stdoutCollector:i,timeout:fg(r,n?.timeoutMs)}},_g=(e,t,n)=>{try{return gg(e,t,n)}catch(e){return{exitCode:127,stderr:yg(e),stdout:``}}},vg=e=>!(`child`in e),yg=e=>e instanceof Error?e.message:String(e),bg=async e=>{try{let[t]=await ve(e,`close`);return{code:t}}catch(e){return{code:null,errorMessage:yg(e)}}},xg=e=>e===null?1:e,Sg=(e,t)=>t.truncated?{...e,stdoutTruncated:!0}:e,Cg=e=>e.timedOut?hg(e.stderr.text,e.timeoutMs):e.errorMessage===void 0?Sg({exitCode:xg(e.code),stderr:ug(e.stderr.text,e.stdout,e.stderr),stdout:e.stdout.text},e.stdout):Sg({exitCode:127,stderr:lg(e.stderr.text,e.errorMessage),stdout:e.stdout.text},e.stdout);var wg=class{async run(e,t,n){sg();let r=_g(e,t,n);if(vg(r))return r;let i=await bg(r.child);return ng.delete(r.child),r.timeout.clear(),Cg({code:i.code,errorMessage:i.errorMessage,stderr:r.stderrCollector.finish(),stdout:r.stdoutCollector.finish(),timedOut:r.timeout.markedTimedOut(),timeoutMs:n?.timeoutMs})}};const Tg=`package.json`,Eg=/^\.\/[^\s%?#\\]*$/u,Dg=async e=>{try{return(await p(e)).isDirectory()?`directory`:`file`}catch{return`unverifiable`}},Og=async(e,t)=>{if(!Eg.test(t)||t.includes(`*`))return`not_checked`;let n=await H(e,m(e,t.slice(2)));return n.kind===`missing`?`absent`:n.kind===`inside`?Dg(n.real):`unverifiable`},kg=async(e,t,n)=>Array.isArray(t)?{alternatives:await Promise.all(t.map(t=>Ag(e,t,n+1))),kind:`alternatives`}:{branches:await Promise.all(Object.entries(t).map(async([t,r])=>({condition:t,value:await Ag(e,r,n+1)}))),kind:`conditions`},Ag=async(e,t,n)=>t===null?{kind:`excluded`}:n>8?{kind:`unsupported`,reason:`nested deeper than this reports on`}:typeof t==`string`?{kind:`target`,observed:await Og(e,t),target:t}:typeof t==`object`?kg(e,t,n):{kind:`unsupported`,reason:`unexpected ${typeof t}`},jg=[`main`,`module`,`types`,`typings`],Mg=(e,t)=>{let n=jg.filter(e=>typeof t[e]==`string`);return Promise.all(n.map(async n=>({from:n,subpath:`.`,value:await Ag(e,Ng(t[n]),0)})))},Ng=e=>e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`)?e:`./${e}`,Pg=async(e,t)=>{if(typeof t==`string`||Array.isArray(t))return[{from:`exports`,subpath:`.`,value:await Ag(e,t,0)}];if(t===void 0)return[];if(typeof t!=`object`||!t)return[{from:`exports`,subpath:`.`,value:await Ag(e,t,0)}];let n=Object.keys(t);return n.length>0&&!n.some(e=>e.startsWith(`.`))?[{from:`exports`,subpath:`.`,value:await Ag(e,t,0)}]:Promise.all(Object.entries(t).map(async([t,n])=>({from:`exports`,subpath:t,value:await Ag(e,n,0)})))},Fg=async(e,t)=>{let n=await H(e,m(e,Tg));if(n.kind!==`inside`)return{entries:[],manifest:Tg,reason:n.kind,status:`unverifiable`};try{let r=JSON.parse(await s(n.real,`utf8`));return r.name===t?{entries:[...await Pg(e,r.exports),...await Mg(e,r)],manifest:Tg,status:`complete`}:{entries:[],manifest:Tg,reason:`manifest no longer names this package`,status:`unverifiable`}}catch(e){return{entries:[],manifest:Tg,reason:e.code??String(e),status:`unverifiable`}}},Ig=hl.partial({description:!0}),Lg=I({default_branch:P().min(1),key:il,tag_format_candidate:ll.nullable(),url:P().min(1)});Lg.extend({description:P().default(``),packages:Gc(Ig)});const Rg=Lg.extend({description:P().min(1),packages:Gc(hl)}),zg=I({effective_clone_mode:sl.optional(),head_sha:P().regex(/^[0-9a-f]{40}$/u,`head_sha must be a 40-character lowercase hex string`).optional(),last_error:P().optional(),last_fetched_at:Vc().optional(),pending_proposal_at:Vc().optional()}),Bg=I({refs:Uc(e=>e.length>0&&!Hc.has(e),()=>`state ref key must be non-empty and not "__proto__", "constructor", or "prototype"`,pc(P(),zg)).default({})}),Vg=(e,t,n)=>t?.[e]??n[e],Hg=async e=>{try{return await s(e.statePath,`utf8`)}catch(e){if(R(e))return;throw e}},Ug=e=>{try{return JSON.parse(e)}catch{return}},Wg=async e=>{let t=await Hg(e);if(t===void 0)return Bg.parse({});let n=Ug(t);if(n===void 0)return Bg.parse({});let r=Bg.safeParse(n);return r.success?r.data:Bg.parse({})},Gg=async(e,t)=>{let n=Bg.safeParse(t);if(!n.success)throw y(T(n.error));await $l(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},Kg=/^\d+\.\d+\.\d+$/u,qg=/^0+(?=\d)/u,Jg=(e,t)=>{let n=e.replace(qg,``),r=t.replace(qg,``);return n.length===r.length?n===r?0:n<r?-1:1:n.length<r.length?-1:1},Yg=(e,t)=>{if(!Kg.test(e)||!Kg.test(t))return;let n=e.split(`.`),r=t.split(`.`);return n.map((e,t)=>Jg(e,r[t]??``)).find(e=>e!==0)??0},Xg=sc({version:P().regex(Kg)}),Zg=I({checked_at:Vc(),latest_version:P().regex(Kg)}),Qg=async e=>{try{let t=Zg.safeParse(JSON.parse(await s(e.updateCachePath,`utf8`)));return t.success?t.data:void 0}catch{return}},$g=async(e,t)=>{try{await p(e.root),await $l(e.updateCachePath,`${JSON.stringify(t,void 0,2)}\n`)}catch{}},e_=(e,t)=>{let n=t-Date.parse(e.checked_at);return n>=0&&n<864e5},t_=async e=>{try{let t=await e(`https://registry.npmjs.org/@kaisers-io%2Frefs/latest`,{signal:AbortSignal.timeout(2e3)});if(t.status!==200)return;let n=Xg.safeParse(await t.json());return n.success?n.data.version:void 0}catch{return}},n_=async e=>{let t=await Qg(e.home);if(t!==void 0&&e_(t,e.nowMs))return{latest:t.latest_version,refreshed:!1,stale:!1};let n=await t_(e.fetch);return n===void 0?{latest:t?.latest_version,refreshed:!1,stale:!0}:(await $g(e.home,{checked_at:new Date(e.nowMs).toISOString(),latest_version:n}),{latest:n,refreshed:!0,stale:!1})},r_=(e,t)=>{let n=Yg(e,t);return n!==void 0&&n<0},i_=(e,t)=>`refs ${t} is available (this is ${e}) — update: npm i -g @kaisers-io/refs@latest`,a_=e=>{let t=e.REFS_UPDATE_CHECK?.trim();if(t===`0`)return!1;if(t===`1`)return!0},o_=e=>{let t=e.CI?.trim().toLowerCase();return t!==void 0&&t!==``&&t!==`false`&&t!==`0`},s_={check:!0,notify:!0},c_=e=>{let t=a_(e.env);return t===void 0?(e.updates??s_).check?o_(e.env)?`ci`:`on`:`config`:t?`on`:`env`},l_=e=>c_(e)===`on`,u_=e=>l_(e)&&(e.updates??s_).notify,d_=async(e,t)=>{let n=await H(e,m(t,`package.json`));if(n.kind===`inside`)try{let e=JSON.parse(await s(n.real,`utf8`));return{name:Iu(e)}}catch{return}},f_=async(e,t)=>{let n=await d_(e,m(e,t));if(n===void 0)return{diagnostic:{kind:`manifest_unreadable`,path:t}};let r=Uh(t,n);return r===void 0?{diagnostic:{kind:`manifest_missing_name`,path:t}}:{pkg:r}},p_=e=>{let t=[],n=[];for(let r of e)r.diagnostic!==void 0&&t.push(r.diagnostic),r.pkg!==void 0&&n.push(r.pkg);return{diagnostics:t,packages:n}},m_=new Set([`ENOENT`,`ENOTDIR`]),h_=async(e,t)=>{let n=await H(e,m(t,`package.json`));if(n.kind===`missing`)return`none`;if(n.kind!==`inside`)return`rejected`;try{return await s(n.real,`utf8`),`manifest`}catch{return`rejected`}},g_=async e=>{try{return{entries:await c(e,{withFileTypes:!0})}}catch(e){return{code:e.code??``}}},__=e=>Promise.all(e.entries.map(t=>h_(e.repoDir,m(e.fullPath,t.name,e.suffix)))),v_=(e,t,n)=>e.filter((e,r)=>n(t[r])).map(e=>e.name),y_=async e=>{let{baseDir:t,dirs:n,fullPath:r,repoDir:i,suffix:a,symlinks:o}=e,s=e=>oe.join(t===`.`?``:t,e,a),[c,l]=await Promise.all([__({entries:n,fullPath:r,repoDir:i,suffix:a}),__({entries:o,fullPath:r,repoDir:i,suffix:a})]);return{diagnostics:[...v_(n,c,e=>e===`rejected`).map(e=>({kind:`manifest_unreadable`,path:s(e)})),...v_(o,l,e=>e!==`none`).map(e=>({kind:`candidate_not_inspected`,path:s(e)}))],dirs:v_(n,c,e=>e===`manifest`).map(e=>s(e))}},b_=async e=>{let t=await f_(e,`.`);return`pkg`in t?[t]:[]},x_=e=>{let t=e.find(e=>e.path===`.`);return t===void 0?[...e]:e.some(e=>e.path!==`.`&&e.name===t.name)?e.filter(e=>e!==t):[...e]},S_=async e=>{let[t]=await b_(e);return t!==void 0&&`pkg`in t?t.pkg:void 0},C_=`package.json`,w_=e=>{let t=Lh(e).split(`/`);return t.includes(`**`)?void 0:t.length},T_=e=>Lh(e).split(`/`).some(e=>e.startsWith(`.`)),E_=e=>e===`.`?0:e.split(`/`).length,D_=e=>{let t=Lh(e),n=new Th(`${t}/${C_}`),r=new Th(t);return{couldHold:e=>r.match(e,!0),selects:e=>n.match(oe.join(e,C_))}},O_=e=>({...D_(e),maxDepth:w_(e),selectsHidden:T_(e)}),k_=new Set([`ENOENT`,`ENOTDIR`]),A_=new Set([`.git`,`node_modules`]),j_=e=>e.some(e=>e.name.toLowerCase()===`package.json`&&!e.isDirectory()),M_=e=>e.some(e=>e.isSymbolicLink()&&!A_.has(e.name)),N_=async(e,t)=>{let n=await g_(t);return`code`in n?{answer:k_.has(n.code)}:(e.budget.entries-=n.entries.length,e.budget.entries<0||j_(n.entries)||M_(n.entries)?{answer:!1}:{entries:n.entries})},P_=async(e,t,n)=>{if(e.budget.dirs<=0||n>32)return!1;--e.budget.dirs;let r=await N_(e,t);return`answer`in r?r.answer:F_(e,{dir:t,entries:r.entries},n)},F_=async(e,t,n)=>{let r=t.entries.filter(e=>e.isDirectory()&&!A_.has(e.name));for(let i of r)if(!await P_(e,m(t.dir,i.name),n+1))return!1;return!0},I_=async(e,t)=>{let n=await H(e.repoDir,m(e.repoDir,t));if(n.kind!==`outside`&&n.kind!==`missing`){if(n.kind===`unreadable`){e.diagnostics.push({kind:`candidate_not_inspected`,path:t});return}await P_(e,n.real,1)||e.diagnostics.push({kind:`candidate_not_inspected`,path:t})}},L_=()=>({dirs:2e4,entries:2e5}),R_=new Set([`.git`,`node_modules`]),z_=(e,t)=>{e.diagnostics.push({kind:`scan_budget_exhausted`,path:t,pattern:e.pattern})},B_=async(e,t,n)=>{if(!e.selects(t)||n.has(t))return;let r=await h_(e.repoDir,m(e.repoDir,t));r===`manifest`&&e.dirs.push(t),r===`rejected`&&e.diagnostics.push({kind:`manifest_unreadable`,path:t})},V_=(e,t)=>!e.selectsHidden&&t.excluded.coversSubtree(t.relPath),H_=async(e,t,n)=>!e.couldHold(n.relPath)||R_.has(t.name)||V_(e,n)?!1:t.isSymbolicLink()?(V_(e,n)||await I_(e,n.relPath),!1):t.isDirectory(),U_=async(e,t)=>{let n=await g_(m(e.repoDir,t));if(`code`in n){m_.has(n.code)||e.diagnostics.push({kind:`workspace_dir_unreadable`,path:t});return}if(e.budget.entries-=n.entries.length,e.budget.entries<0){z_(e,t);return}return n.entries},W_=async(e,t,n)=>{if(e.budget.dirs<=0){z_(e,t.relPath);return}if(--e.budget.dirs,await B_(e,t.relPath,n),e.maxDepth!==void 0&&E_(t.relPath)>=e.maxDepth)return;let r=await U_(e,t.relPath);r!==void 0&&await K_(e,{depth:t.depth,entries:r,relPath:t.relPath},n)},G_=(e,t)=>oe.join(e===`.`?``:e,t),K_=async(e,t,n)=>{for(let r of t.entries){let i=G_(t.relPath,r.name);await H_(e,r,{excluded:n,relPath:i})&&(t.depth+1>32?z_(e,i):await W_(e,{depth:t.depth+1,relPath:i},n))}},q_=async(e,t)=>{let n=await H(e,m(e,t));if(n.kind!==`inside`)return n.kind===`missing`?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}},J_=async(e,t,n)=>{let r=await q_(e,t.baseDir);if(r!==void 0)return r;let i={...O_(t.pattern),budget:n.budget,diagnostics:[],dirs:[],pattern:t.pattern,repoDir:e};return await W_(i,{depth:1,relPath:t.baseDir},n.excluded),{diagnostics:i.diagnostics,dirs:i.dirs}},Y_=(e,t)=>oe.join(e.baseDir===`.`?``:e.baseDir,t,e.suffix),X_=(e,t)=>Ih(Y_(t,e.name),t.pattern),Z_=async(e,t)=>{let n=m(e,t),r=await H(e,n);if(r.kind===`missing`)return{result:{diagnostics:[],dirs:[]}};if(r.kind!==`inside`)return{result:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}};let i=await g_(n);return`code`in i?{result:m_.has(i.code)?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}}:{entries:i.entries}},Q_=async(e,t,n)=>{let{baseDir:r}=t,i=await Z_(e,r);if(`result`in i)return i.result;let a=e=>X_(e,t)&&!n.has(Y_(t,e.name)),o={entries:i.entries};return y_({baseDir:r,dirs:o.entries.filter(e=>e.isDirectory()&&a(e)),fullPath:m(e,r),repoDir:e,suffix:t.suffix,symlinks:o.entries.filter(e=>e.isSymbolicLink()&&a(e))})},$_=async(e,t)=>{let n=await h_(e,m(e,t));return n===`manifest`?{diagnostics:[],dirs:[Lh(t)]}:n===`rejected`?{diagnostics:[{kind:`manifest_unreadable`,path:t}],dirs:[]}:{diagnostics:[],dirs:[]}},ev=(e,t,n)=>{let{excluded:r}=n,i=Vh(t.body);return i.kind===`expand-children`?Q_(e,i,r):i.kind===`expand-recursive`?J_(e,i,n):i.kind===`probe-dir`?r.has(Lh(i.dir))?Promise.resolve({diagnostics:[],dirs:[]}):$_(e,i.dir):Promise.resolve({diagnostics:[{kind:`unsupported_pattern`,pattern:t.declared}],dirs:[]})},tv=(e,t)=>Ih(Nh(e),Nh(t)),nv=e=>({negations:e.filter(e=>Mh(e)),patterns:e.filter(e=>!Mh(e))}),rv=e=>{let t=e.reduce((e,t)=>Mh(t)?{negations:[...e.negations,t],patterns:e.patterns}:{negations:e.negations.filter(e=>!tv(t,e)),patterns:[...e.patterns,t]},{negations:[],patterns:[]});return{negations:t.negations,patterns:t.patterns.filter(e=>!t.negations.some(t=>tv(e,t)))}},iv=e=>e.endsWith(`/`)?e:`${e}/`,av=(e,t)=>e.some(e=>Ih(iv(t),iv(Nh(e)))),ov=(e,t)=>{let n=Nh(e);return n.endsWith(`/**`)&&Ih(t,n.slice(0,-3))},sv=e=>({coversSubtree:t=>e.some(e=>ov(e,t)),has:t=>av(e,t)}),cv=e=>{let t=new Set,n=[];for(let r of e)r.dirs.forEach(e=>t.add(e)),n.push(...r.diagnostics);return{diagnostics:n,dirs:[...t]}},lv=async(e,t,n)=>{let{negations:r,patterns:i}=t,a=sv(r),o=cv(await Promise.all(i.map(t=>ev(e,{body:Nh(t),declared:t},{budget:n,excluded:a}))));return{diagnostics:o.diagnostics,dirs:o.dirs}},uv=async(e,t)=>{let n=rv(t.npm),r=nv(t.pnpm),i=L_(),a=await Promise.all([lv(e,n,i),lv(e,r,i)]);return cv(a)},dv=async e=>{let t=await Uu(e);if(t.npm.length===0&&t.pnpm.length===0)return{diagnostics:Yh([...t.diagnostics,{kind:`no_workspace_declaration`}]),packages:[]};let n=await uv(e,t),[r,i]=await Promise.all([b_(e),Promise.all(n.dirs.map(t=>f_(e,t)))]),a=p_([...r,...i]);return{diagnostics:Yh([...t.diagnostics,...n.diagnostics,...a.diagnostics]),packages:x_(Wh(a.packages))}};var fv=`0.16.0`;const pv=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},mv=()=>{try{return he()}catch{return``}},hv=()=>({cliVersion:fv,cwd:process.cwd(),env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:(e,t)=>fetch(e,t),homedir:mv(),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:pv,runner:new wg});var gv=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},_v=class extends gv{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},vv=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new _v(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function yv(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var bv=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>yv(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(t?` `+t:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
328
+ `),ug=(e,t,n)=>{let r=e;return t.truncated&&(r=lg(r,`refs: stdout exceeded 67108864 bytes, truncated`)),n.truncated&&(r=lg(r,`refs: stderr exceeded 67108864 bytes, truncated`)),r},dg={clear:()=>{},markedTimedOut:()=>!1},fg=(e,t)=>{if(t===void 0)return dg;let n=!1,r,i=setTimeout(()=>{n=!0,e.kill(`SIGTERM`),r=setTimeout(()=>{e.kill(`SIGKILL`)},2e3)},t);return{clear:()=>{clearTimeout(i),r!==void 0&&clearTimeout(r)},markedTimedOut:()=>n}},pg=e=>e===void 0?{}:{cwd:e},mg=(e,t)=>lg(e,`refs: command timed out after ${String(t)}ms`),hg=(e,t)=>({exitCode:124,stderr:mg(e,t),stdout:``,timedOut:!0}),gg=(e,t,n)=>{let r=be(e,t,{...pg(n?.cwd),stdio:[`ignore`,`pipe`,`pipe`]});ng.add(r);let i=cg(),a=cg();return r.stdout.on(`data`,e=>{i.push(e)}),r.stderr.on(`data`,e=>{a.push(e)}),{child:r,stderrCollector:a,stdoutCollector:i,timeout:fg(r,n?.timeoutMs)}},_g=(e,t,n)=>{try{return gg(e,t,n)}catch(e){return{exitCode:127,stderr:yg(e),stdout:``}}},vg=e=>!(`child`in e),yg=e=>e instanceof Error?e.message:String(e),bg=async e=>{try{let[t]=await ve(e,`close`);return{code:t}}catch(e){return{code:null,errorMessage:yg(e)}}},xg=e=>e===null?1:e,Sg=(e,t)=>t.truncated?{...e,stdoutTruncated:!0}:e,Cg=e=>e.timedOut?hg(e.stderr.text,e.timeoutMs):e.errorMessage===void 0?Sg({exitCode:xg(e.code),stderr:ug(e.stderr.text,e.stdout,e.stderr),stdout:e.stdout.text},e.stdout):Sg({exitCode:127,stderr:lg(e.stderr.text,e.errorMessage),stdout:e.stdout.text},e.stdout);var wg=class{async run(e,t,n){sg();let r=_g(e,t,n);if(vg(r))return r;let i=await bg(r.child);return ng.delete(r.child),r.timeout.clear(),Cg({code:i.code,errorMessage:i.errorMessage,stderr:r.stderrCollector.finish(),stdout:r.stdoutCollector.finish(),timedOut:r.timeout.markedTimedOut(),timeoutMs:n?.timeoutMs})}};const Tg=`package.json`,Eg=/^\.\/[^\s%?#\\]*$/u,Dg=async e=>{try{return(await p(e)).isDirectory()?`directory`:`file`}catch{return`unverifiable`}},Og=async(e,t)=>{if(!Eg.test(t)||t.includes(`*`))return`not_checked`;let n=await H(e,m(e,t.slice(2)));return n.kind===`missing`?`absent`:n.kind===`inside`?Dg(n.real):`unverifiable`},kg=async(e,t,n)=>Array.isArray(t)?{alternatives:await Promise.all(t.map(t=>Ag(e,t,n+1))),kind:`alternatives`}:{branches:await Promise.all(Object.entries(t).map(async([t,r])=>({condition:t,value:await Ag(e,r,n+1)}))),kind:`conditions`},Ag=async(e,t,n)=>t===null?{kind:`excluded`}:n>8?{kind:`unsupported`,reason:`nested deeper than this reports on`}:typeof t==`string`?{kind:`target`,observed:await Og(e,t),target:t}:typeof t==`object`?kg(e,t,n):{kind:`unsupported`,reason:`unexpected ${typeof t}`},jg=[`main`,`module`,`types`,`typings`],Mg=(e,t)=>{let n=jg.filter(e=>typeof t[e]==`string`);return Promise.all(n.map(async n=>({from:n,subpath:`.`,value:await Ag(e,Ng(t[n]),0)})))},Ng=e=>e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`)?e:`./${e}`,Pg=async(e,t)=>{if(typeof t==`string`||Array.isArray(t))return[{from:`exports`,subpath:`.`,value:await Ag(e,t,0)}];if(t===void 0)return[];if(typeof t!=`object`||!t)return[{from:`exports`,subpath:`.`,value:await Ag(e,t,0)}];let n=Object.keys(t);return n.length>0&&!n.some(e=>e.startsWith(`.`))?[{from:`exports`,subpath:`.`,value:await Ag(e,t,0)}]:Promise.all(Object.entries(t).map(async([t,n])=>({from:`exports`,subpath:t,value:await Ag(e,n,0)})))},Fg=async(e,t)=>{let n=await H(e,m(e,Tg));if(n.kind!==`inside`)return{entries:[],manifest:Tg,reason:n.kind,status:`unverifiable`};try{let r=JSON.parse(await s(n.real,`utf8`));return r.name===t?{entries:[...await Pg(e,r.exports),...await Mg(e,r)],manifest:Tg,status:`complete`}:{entries:[],manifest:Tg,reason:`manifest no longer names this package`,status:`unverifiable`}}catch(e){return{entries:[],manifest:Tg,reason:e.code??String(e),status:`unverifiable`}}},Ig=hl.partial({description:!0}),Lg=I({default_branch:P().min(1),key:il,tag_format_candidate:ll.nullable(),url:P().min(1)});Lg.extend({description:P().default(``),packages:Gc(Ig)});const Rg=Lg.extend({description:P().min(1),packages:Gc(hl)}),zg=I({effective_clone_mode:sl.optional(),head_sha:P().regex(/^[0-9a-f]{40}$/u,`head_sha must be a 40-character lowercase hex string`).optional(),last_error:P().optional(),last_fetched_at:Vc().optional(),pending_proposal_at:Vc().optional()}),Bg=I({refs:Uc(e=>e.length>0&&!Hc.has(e),()=>`state ref key must be non-empty and not "__proto__", "constructor", or "prototype"`,pc(P(),zg)).default({})}),Vg=(e,t,n)=>t?.[e]??n[e],Hg=async e=>{try{return await s(e.statePath,`utf8`)}catch(e){if(R(e))return;throw e}},Ug=e=>{try{return JSON.parse(e)}catch{return}},Wg=async e=>{let t=await Hg(e);if(t===void 0)return Bg.parse({});let n=Ug(t);if(n===void 0)return Bg.parse({});let r=Bg.safeParse(n);return r.success?r.data:Bg.parse({})},Gg=async(e,t)=>{let n=Bg.safeParse(t);if(!n.success)throw y(T(n.error));await $l(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},Kg=/^\d+\.\d+\.\d+$/u,qg=/^0+(?=\d)/u,Jg=(e,t)=>{let n=e.replace(qg,``),r=t.replace(qg,``);return n.length===r.length?n===r?0:n<r?-1:1:n.length<r.length?-1:1},Yg=(e,t)=>{if(!Kg.test(e)||!Kg.test(t))return;let n=e.split(`.`),r=t.split(`.`);return n.map((e,t)=>Jg(e,r[t]??``)).find(e=>e!==0)??0},Xg=sc({version:P().regex(Kg)}),Zg=I({checked_at:Vc(),latest_version:P().regex(Kg)}),Qg=async e=>{try{let t=Zg.safeParse(JSON.parse(await s(e.updateCachePath,`utf8`)));return t.success?t.data:void 0}catch{return}},$g=async(e,t)=>{try{await p(e.root),await $l(e.updateCachePath,`${JSON.stringify(t,void 0,2)}\n`)}catch{}},e_=(e,t)=>{let n=t-Date.parse(e.checked_at);return n>=0&&n<864e5},t_=async e=>{try{let t=await e(`https://registry.npmjs.org/@kaisers-io%2Frefs/latest`,{signal:AbortSignal.timeout(2e3)});if(t.status!==200)return;let n=Xg.safeParse(await t.json());return n.success?n.data.version:void 0}catch{return}},n_=async e=>{let t=await Qg(e.home);if(t!==void 0&&e_(t,e.nowMs))return{latest:t.latest_version,refreshed:!1,stale:!1};let n=await t_(e.fetch);return n===void 0?{latest:t?.latest_version,refreshed:!1,stale:!0}:(await $g(e.home,{checked_at:new Date(e.nowMs).toISOString(),latest_version:n}),{latest:n,refreshed:!0,stale:!1})},r_=(e,t)=>{let n=Yg(e,t);return n!==void 0&&n<0},i_=(e,t)=>`refs ${t} is available (this is ${e}) — update: npm i -g @kaisers-io/refs@latest`,a_=e=>{let t=e.REFS_UPDATE_CHECK?.trim();if(t===`0`)return!1;if(t===`1`)return!0},o_=e=>{let t=e.CI?.trim().toLowerCase();return t!==void 0&&t!==``&&t!==`false`&&t!==`0`},s_={check:!0,notify:!0},c_=e=>{let t=a_(e.env);return t===void 0?(e.updates??s_).check?o_(e.env)?`ci`:`on`:`config`:t?`on`:`env`},l_=e=>c_(e)===`on`,u_=e=>l_(e)&&(e.updates??s_).notify,d_=async(e,t)=>{let n=await H(e,m(t,`package.json`));if(n.kind===`inside`)try{let e=JSON.parse(await s(n.real,`utf8`));return{name:Iu(e)}}catch{return}},f_=async(e,t)=>{let n=await d_(e,m(e,t));if(n===void 0)return{diagnostic:{kind:`manifest_unreadable`,path:t}};let r=Uh(t,n);return r===void 0?{diagnostic:{kind:`manifest_missing_name`,path:t}}:{pkg:r}},p_=e=>{let t=[],n=[];for(let r of e)r.diagnostic!==void 0&&t.push(r.diagnostic),r.pkg!==void 0&&n.push(r.pkg);return{diagnostics:t,packages:n}},m_=new Set([`ENOENT`,`ENOTDIR`]),h_=async(e,t)=>{let n=await H(e,m(t,`package.json`));if(n.kind===`missing`)return`none`;if(n.kind!==`inside`)return`rejected`;try{return await s(n.real,`utf8`),`manifest`}catch{return`rejected`}},g_=async e=>{try{return{entries:await c(e,{withFileTypes:!0})}}catch(e){return{code:e.code??``}}},__=e=>Promise.all(e.entries.map(t=>h_(e.repoDir,m(e.fullPath,t.name,e.suffix)))),v_=(e,t,n)=>e.filter((e,r)=>n(t[r])).map(e=>e.name),y_=async e=>{let{baseDir:t,dirs:n,fullPath:r,repoDir:i,suffix:a,symlinks:o}=e,s=e=>oe.join(t===`.`?``:t,e,a),[c,l]=await Promise.all([__({entries:n,fullPath:r,repoDir:i,suffix:a}),__({entries:o,fullPath:r,repoDir:i,suffix:a})]);return{diagnostics:[...v_(n,c,e=>e===`rejected`).map(e=>({kind:`manifest_unreadable`,path:s(e)})),...v_(o,l,e=>e!==`none`).map(e=>({kind:`candidate_not_inspected`,path:s(e)}))],dirs:v_(n,c,e=>e===`manifest`).map(e=>s(e))}},b_=async e=>{let t=await f_(e,`.`);return`pkg`in t?[t]:[]},x_=e=>{let t=e.find(e=>e.path===`.`);return t===void 0?[...e]:e.some(e=>e.path!==`.`&&e.name===t.name)?e.filter(e=>e!==t):[...e]},S_=async e=>{let[t]=await b_(e);return t!==void 0&&`pkg`in t?t.pkg:void 0},C_=`package.json`,w_=e=>{let t=Lh(e).split(`/`);return t.includes(`**`)?void 0:t.length},T_=e=>Lh(e).split(`/`).some(e=>e.startsWith(`.`)),E_=e=>e===`.`?0:e.split(`/`).length,D_=e=>{let t=Lh(e),n=new Th(`${t}/${C_}`),r=new Th(t);return{couldHold:e=>r.match(e,!0),selects:e=>n.match(oe.join(e,C_))}},O_=e=>({...D_(e),maxDepth:w_(e),selectsHidden:T_(e)}),k_=new Set([`ENOENT`,`ENOTDIR`]),A_=new Set([`.git`,`node_modules`]),j_=e=>e.some(e=>e.name.toLowerCase()===`package.json`&&!e.isDirectory()),M_=e=>e.some(e=>e.isSymbolicLink()&&!A_.has(e.name)),N_=async(e,t)=>{let n=await g_(t);return`code`in n?{answer:k_.has(n.code)}:(e.budget.entries-=n.entries.length,e.budget.entries<0||j_(n.entries)||M_(n.entries)?{answer:!1}:{entries:n.entries})},P_=async(e,t,n)=>{if(e.budget.dirs<=0||n>32)return!1;--e.budget.dirs;let r=await N_(e,t);return`answer`in r?r.answer:F_(e,{dir:t,entries:r.entries},n)},F_=async(e,t,n)=>{let r=t.entries.filter(e=>e.isDirectory()&&!A_.has(e.name));for(let i of r)if(!await P_(e,m(t.dir,i.name),n+1))return!1;return!0},I_=async(e,t)=>{let n=await H(e.repoDir,m(e.repoDir,t));if(n.kind!==`outside`&&n.kind!==`missing`){if(n.kind===`unreadable`){e.diagnostics.push({kind:`candidate_not_inspected`,path:t});return}await P_(e,n.real,1)||e.diagnostics.push({kind:`candidate_not_inspected`,path:t})}},L_=()=>({dirs:2e4,entries:2e5}),R_=new Set([`.git`,`node_modules`]),z_=(e,t)=>{e.diagnostics.push({kind:`scan_budget_exhausted`,path:t,pattern:e.pattern})},B_=async(e,t,n)=>{if(!e.selects(t)||n.has(t))return;let r=await h_(e.repoDir,m(e.repoDir,t));r===`manifest`&&e.dirs.push(t),r===`rejected`&&e.diagnostics.push({kind:`manifest_unreadable`,path:t})},V_=(e,t)=>!e.selectsHidden&&t.excluded.coversSubtree(t.relPath),H_=async(e,t,n)=>!e.couldHold(n.relPath)||R_.has(t.name)||V_(e,n)?!1:t.isSymbolicLink()?(V_(e,n)||await I_(e,n.relPath),!1):t.isDirectory(),U_=async(e,t)=>{let n=await g_(m(e.repoDir,t));if(`code`in n){m_.has(n.code)||e.diagnostics.push({kind:`workspace_dir_unreadable`,path:t});return}if(e.budget.entries-=n.entries.length,e.budget.entries<0){z_(e,t);return}return n.entries},W_=async(e,t,n)=>{if(e.budget.dirs<=0){z_(e,t.relPath);return}if(--e.budget.dirs,await B_(e,t.relPath,n),e.maxDepth!==void 0&&E_(t.relPath)>=e.maxDepth)return;let r=await U_(e,t.relPath);r!==void 0&&await K_(e,{depth:t.depth,entries:r,relPath:t.relPath},n)},G_=(e,t)=>oe.join(e===`.`?``:e,t),K_=async(e,t,n)=>{for(let r of t.entries){let i=G_(t.relPath,r.name);await H_(e,r,{excluded:n,relPath:i})&&(t.depth+1>32?z_(e,i):await W_(e,{depth:t.depth+1,relPath:i},n))}},q_=async(e,t)=>{let n=await H(e,m(e,t));if(n.kind!==`inside`)return n.kind===`missing`?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}},J_=async(e,t,n)=>{let r=await q_(e,t.baseDir);if(r!==void 0)return r;let i={...O_(t.pattern),budget:n.budget,diagnostics:[],dirs:[],pattern:t.pattern,repoDir:e};return await W_(i,{depth:1,relPath:t.baseDir},n.excluded),{diagnostics:i.diagnostics,dirs:i.dirs}},Y_=(e,t)=>oe.join(e.baseDir===`.`?``:e.baseDir,t,e.suffix),X_=(e,t)=>Ih(Y_(t,e.name),t.pattern),Z_=async(e,t)=>{let n=m(e,t),r=await H(e,n);if(r.kind===`missing`)return{result:{diagnostics:[],dirs:[]}};if(r.kind!==`inside`)return{result:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}};let i=await g_(n);return`code`in i?{result:m_.has(i.code)?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}}:{entries:i.entries}},Q_=async(e,t,n)=>{let{baseDir:r}=t,i=await Z_(e,r);if(`result`in i)return i.result;let a=e=>X_(e,t)&&!n.has(Y_(t,e.name)),o={entries:i.entries};return y_({baseDir:r,dirs:o.entries.filter(e=>e.isDirectory()&&a(e)),fullPath:m(e,r),repoDir:e,suffix:t.suffix,symlinks:o.entries.filter(e=>e.isSymbolicLink()&&a(e))})},$_=async(e,t)=>{let n=await h_(e,m(e,t));return n===`manifest`?{diagnostics:[],dirs:[Lh(t)]}:n===`rejected`?{diagnostics:[{kind:`manifest_unreadable`,path:t}],dirs:[]}:{diagnostics:[],dirs:[]}},ev=(e,t,n)=>{let{excluded:r}=n,i=Vh(t.body);return i.kind===`expand-children`?Q_(e,i,r):i.kind===`expand-recursive`?J_(e,i,n):i.kind===`probe-dir`?r.has(Lh(i.dir))?Promise.resolve({diagnostics:[],dirs:[]}):$_(e,i.dir):Promise.resolve({diagnostics:[{kind:`unsupported_pattern`,pattern:t.declared}],dirs:[]})},tv=(e,t)=>Ih(Nh(e),Nh(t)),nv=e=>({negations:e.filter(e=>Mh(e)),patterns:e.filter(e=>!Mh(e))}),rv=e=>{let t=e.reduce((e,t)=>Mh(t)?{negations:[...e.negations,t],patterns:e.patterns}:{negations:e.negations.filter(e=>!tv(t,e)),patterns:[...e.patterns,t]},{negations:[],patterns:[]});return{negations:t.negations,patterns:t.patterns.filter(e=>!t.negations.some(t=>tv(e,t)))}},iv=e=>e.endsWith(`/`)?e:`${e}/`,av=(e,t)=>e.some(e=>Ih(iv(t),iv(Nh(e)))),ov=(e,t)=>{let n=Nh(e);return n.endsWith(`/**`)&&Ih(t,n.slice(0,-3))},sv=e=>({coversSubtree:t=>e.some(e=>ov(e,t)),has:t=>av(e,t)}),cv=e=>{let t=new Set,n=[];for(let r of e)r.dirs.forEach(e=>t.add(e)),n.push(...r.diagnostics);return{diagnostics:n,dirs:[...t]}},lv=async(e,t,n)=>{let{negations:r,patterns:i}=t,a=sv(r),o=cv(await Promise.all(i.map(t=>ev(e,{body:Nh(t),declared:t},{budget:n,excluded:a}))));return{diagnostics:o.diagnostics,dirs:o.dirs}},uv=async(e,t)=>{let n=rv(t.npm),r=nv(t.pnpm),i=L_(),a=await Promise.all([lv(e,n,i),lv(e,r,i)]);return cv(a)},dv=async e=>{let t=await Uu(e);if(t.npm.length===0&&t.pnpm.length===0)return{diagnostics:Yh([...t.diagnostics,{kind:`no_workspace_declaration`}]),packages:[]};let n=await uv(e,t),[r,i]=await Promise.all([b_(e),Promise.all(n.dirs.map(t=>f_(e,t)))]),a=p_([...r,...i]);return{diagnostics:Yh([...t.diagnostics,...n.diagnostics,...a.diagnostics]),packages:x_(Wh(a.packages))}};var fv=`0.16.1`;const pv=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},mv=()=>{try{return he()}catch{return``}},hv=()=>({cliVersion:fv,cwd:process.cwd(),env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:(e,t)=>fetch(e,t),homedir:mv(),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:pv,runner:new wg});var gv=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},_v=class extends gv{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},vv=class{constructor(e,t){switch(this.description=t||``,this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case`<`:this.required=!0,this._name=e.slice(1,-1);break;case`[`:this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e}this._name.endsWith(`...`)&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new _v(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function yv(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var bv=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(e=>!e._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((e,t)=>e.name().localeCompare(t.name())),t}compareOptions(e,t){let n=e=>e.short?e.short.replace(/^-/,``):e.long.replace(/^--/,``);return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(e=>!e.hidden),n=e._getHelpOption();if(n&&!n.hidden){let r=n.short&&e._findOption(n.short),i=n.long&&e._findOption(n.long);!r&&!i?t.push(n):n.long&&!i?t.push(e.createOption(n.long,n.description)):n.short&&!r&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let e=n.options.filter(e=>!e.hidden);t.push(...e)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||``}),e.registeredArguments.find(e=>e.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(e=>yv(e)).join(` `);return e._name+(e._aliases[0]?`|`+e._aliases[0]:``)+(e.options.length?` [options]`:``)+(t?` `+t:``)}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(n)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleOptionTerm(t.optionTerm(n)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((e,n)=>Math.max(e,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(n)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+`|`+e._aliases[0]);let n=``;for(let t=e.parent;t;t=t.parent)n=t.name()+` `+n;return n+t+` `+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue==`boolean`)&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(e=>JSON.stringify(e)).join(`, `)}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(`, `)})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,``]}groupItems(e,t,n){let r=new Map;return e.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[])}),t.forEach(e=>{let t=n(e);r.has(t)||r.set(t,[]),r.get(t).push(e)}),r}formatHelp(e,t){let n=t.padWidth(e,t),r=t.helpWidth??80;function i(e,r){return t.formatItem(e,n,r,t)}let a=[`${t.styleTitle(`Usage:`)} ${t.styleUsage(t.commandUsage(e))}`,``],o=t.commandDescription(e);o.length>0&&(a=a.concat([t.boxWrap(t.styleCommandDescription(o),r),``]));let s=t.visibleArguments(e).map(e=>i(t.styleArgumentTerm(t.argumentTerm(e)),t.styleArgumentDescription(t.argumentDescription(e))));if(a=a.concat(this.formatItemList(`Arguments:`,s,t)),this.groupItems(e.options,t.visibleOptions(e),e=>e.helpGroupHeading??`Options:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),t.showGlobalOptions){let n=t.visibleGlobalOptions(e).map(e=>i(t.styleOptionTerm(t.optionTerm(e)),t.styleOptionDescription(t.optionDescription(e))));a=a.concat(this.formatItemList(`Global Options:`,n,t))}return this.groupItems(e.commands,t.visibleCommands(e),e=>e.helpGroup()||`Commands:`).forEach((e,n)=>{let r=e.map(e=>i(t.styleSubcommandTerm(t.subcommandTerm(e)),t.styleSubcommandDescription(t.subcommandDescription(e))));a=a.concat(this.formatItemList(n,r,t))}),a.join(`
329
329
  `)}displayWidth(e){return xe(e).length}styleTitle(e){return e}styleUsage(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e===`[command]`?this.styleSubcommandText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleCommandText(e)).join(` `)}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(` `).map(e=>e===`[options]`?this.styleOptionText(e):e[0]===`[`||e[0]===`<`?this.styleArgumentText(e):this.styleSubcommandText(e)).join(` `)}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,r){let i=` `.repeat(2);if(!n)return i+e;let a=e.padEnd(t+e.length-r.displayWidth(e)),o=(this.helpWidth??80)-t-2-2,s;return s=o<this.minWidthToWrap||r.preformatted(n)?n:r.boxWrap(n,o).replace(/\n/g,`
330
330
  `+` `.repeat(t+2)),i+a+` `.repeat(2)+s.replace(/\n/g,`\n${i}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),r=/[\s]*[^\s]+/g,i=[];return n.forEach(e=>{let n=e.match(r);if(n===null){i.push(``);return}let a=[n.shift()],o=this.displayWidth(a[0]);n.forEach(e=>{let n=this.displayWidth(e);if(o+n<=t){a.push(e),o+=n;return}i.push(a.join(``));let r=e.trimStart();a=[r],o=this.displayWidth(r)}),i.push(a.join(``))}),i.join(`
331
331
  `)}},xv=class{constructor(e,t){this.flags=e,this.description=t||``,this.required=e.includes(`<`),this.optional=e.includes(`[`),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=wv(e);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith(`--no-`)),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e==`string`&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,t)=>{if(!this.argChoices.includes(e))throw new _v(`Allowed choices are ${this.argChoices.join(`, `)}.`);return this.variadic?this._collectValue(e,t):e},this}name(){return this.long?this.long.replace(/^--/,``):this.short.replace(/^-/,``)}attributeName(){return this.negate?Cv(this.name().replace(/^no-/,``)):Cv(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},Sv=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(e=>{e.negate?this.negativeOptions.set(e.attributeName(),e):this.positiveOptions.set(e.attributeName(),e)}),this.negativeOptions.forEach((e,t)=>{this.positiveOptions.has(t)&&this.dualOptions.add(t)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let r=this.negativeOptions.get(n).presetArg,i=r!==void 0&&r;return t.negate===(i===e)}};function Cv(e){return e.split(`-`).reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function wv(e){let t,n,r=/^-[^-]$/,i=/^--[^-]/,a=e.split(/[ |,]+/).concat(`guard`);if(r.test(a[0])&&(t=a.shift()),i.test(a[0])&&(n=a.shift()),!t&&r.test(a[0])&&(t=a.shift()),!t&&i.test(a[0])&&(t=n,n=a.shift()),a[0].startsWith(`-`)){let t=a[0],n=`option creation failed due to '${t}' in option flags '${e}'`;throw/^-[^-][^-]/.test(t)?Error(`${n}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaisers-io/refs",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Gives coding agents the real source of your dependencies, not a guess.",
5
5
  "keywords": [
6
6
  "ai",