@kaisers-io/refs 0.14.1 → 0.16.0
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 +75 -0
- package/dist/refs.mjs +21 -21
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,81 @@ 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.0] - 2026-09-13
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`refs resolve` reports the package's declared entry points, and what is actually at each
|
|
13
|
+
target.** The agent's next step after a resolve was always the same: open `package.json` and work
|
|
14
|
+
out which file to read. The manifest's own answer is frequently wrong in a source checkout,
|
|
15
|
+
because a source checkout is not built — measured on repositories refs tracks, `zod` declares
|
|
16
|
+
`types`/`import`/`require` targets that do not exist there, and `astro` declares `./dist/index.js`,
|
|
17
|
+
which does not either. The only present target in zod's case sits behind a non-standard
|
|
18
|
+
`@zod/source` condition, visible only because every condition is reported rather than the ones a
|
|
19
|
+
resolver knows.
|
|
20
|
+
|
|
21
|
+
`package.entry_points` is the declaration with an observation at each target (`file`,
|
|
22
|
+
`directory`, `absent`, `not_checked`, `unverifiable`) — **not** a resolution. Which condition is
|
|
23
|
+
right depends on who is importing, and refs is not that consumer; that is also why no resolver
|
|
24
|
+
library is involved, since `resolve.exports` and `resolve-pkg-maps` both need the caller to supply
|
|
25
|
+
the conditions. The structure is preserved because it carries meaning: conditions are ordered,
|
|
26
|
+
`alternatives` is not a list of equals (Node takes the first string; an absent file does not fall
|
|
27
|
+
through), and an explicit `null` rules a subpath out. Legacy `main`/`module`/`types`/`typings` are
|
|
28
|
+
reported beside `exports`, each naming its field, which is not a claim about precedence.
|
|
29
|
+
|
|
30
|
+
An absent target describes this checkout and says nothing about the package's health — SKILL.md
|
|
31
|
+
says so in the same words, because an agent reporting "this dependency is broken" over an unbuilt
|
|
32
|
+
`dist/` is the failure this field could most easily cause. Patterns are reported as declared and
|
|
33
|
+
not probed: statting `./src/*.js` literally would report an absence about a filename nobody
|
|
34
|
+
declared.
|
|
35
|
+
|
|
36
|
+
Payload cost, measured on real checkouts: 267 bytes for `next`, 5.3 KB for `zod` (14 entries),
|
|
37
|
+
8.7 KB for `astro` (63 entries).
|
|
38
|
+
|
|
39
|
+
## [0.15.0] - 2026-09-13
|
|
40
|
+
|
|
41
|
+
### Upgrading
|
|
42
|
+
|
|
43
|
+
**`refs doctor` no longer warns about packages a repository declares and your configuration has
|
|
44
|
+
never registered.** They are still reported, grouped by directory, beside a health line that is now
|
|
45
|
+
about your configured entries alone. A ref tracking 37 packages of a repository that declares 554
|
|
46
|
+
goes from a permanent `warn` to `ok`. If you were treating a `warn` on `config-drift` as "every
|
|
47
|
+
package has been decided about", that is the assertion that is gone — the check never had evidence
|
|
48
|
+
for it. `refs doctor --json` carries every candidate.
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- **`config-drift` warns about broken routes, not about every package nobody registered.** The
|
|
53
|
+
check reported two different kinds of finding and derived one status from both: entries that are
|
|
54
|
+
wrong (`missing`, `relocated`, `ambiguous`, `unverifiable`) and packages the checkout declares
|
|
55
|
+
that the configuration does not have. Those are separate assertions. A refs configuration
|
|
56
|
+
expresses "every registered route is valid"; the warning silently demanded "every declared
|
|
57
|
+
package has received a registration decision", which nothing justifies — registering 37 packages
|
|
58
|
+
of a repository that declares 554 is not 517 oversights, and the probe has no evidence either
|
|
59
|
+
way.
|
|
60
|
+
|
|
61
|
+
Only findings about configured entries decide the status now. Discovery candidates are still
|
|
62
|
+
reported, in their own `discovery` key and grouped by the directory they sit under —
|
|
63
|
+
structurally, never under a label like "fixtures" that refs would have to guess at. On a ref
|
|
64
|
+
tracking 37 of astro's 554 packages the check goes from `warn` with 517 findings, ten printed
|
|
65
|
+
and 507 hidden, to:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
[OK] config-drift: every configured package path resolves in 1 checkout(s);
|
|
69
|
+
examples: 24 unregistered package(s) the configuration does not have;
|
|
70
|
+
packages: 493 unregistered package(s) the configuration does not have
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
An incomplete discovery pass keeps its own prominence and still downgrades `ok` — "could not
|
|
74
|
+
look" never becomes "zero candidates". `refs doctor --json` carries every candidate, so a
|
|
75
|
+
grouped count is never a summary of something unreachable. The per-package
|
|
76
|
+
`refs edit --decline` stays: it is still the right answer for a candidate someone reviewed, and
|
|
77
|
+
it stops being mandatory bookkeeping for a healthy result.
|
|
78
|
+
|
|
79
|
+
What this costs, stated plainly: a package genuinely forgotten is easier to overlook, because it
|
|
80
|
+
appears under discovery rather than in a warning. The root-package migration case (#88) is
|
|
81
|
+
exactly such a finding and loses warning-level prominence.
|
|
82
|
+
|
|
8
83
|
## [0.14.1] - 2026-09-13
|
|
9
84
|
|
|
10
85
|
### Fixed
|
package/dist/refs.mjs
CHANGED
|
@@ -319,38 +319,38 @@ sync_ttl = "1h"
|
|
|
319
319
|
# tag_format = "v{version}"
|
|
320
320
|
# # Per-ref overrides of [settings] go in the same table, e.g.:
|
|
321
321
|
# # clone_mode = "full"
|
|
322
|
-
`.replaceAll(`{{CLI_VERSION}}`,t)),`seeded`),hu=(e,t)=>{let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];t===void 0?n[e]=r:au(t)&&au(r)&&(n[e]=hu(t,r))}return n},gu={meta:{},refs:{},settings:{}},_u=async e=>{try{return await su(e)}catch(e){if(e instanceof g&&e.code===`not_found`)return;throw e}},vu=e=>{if(e!==void 0&&e>1)throw y(`config schema ${e} is newer than this CLI supports — upgrade refs`)},yu=async(e,t,n)=>{let r=ou(t.meta,{});if(r.cli_version===n)return;let i={...t,meta:{...r,cli_version:n}};await $l(e.configPath,Ql(i))},bu=async(e,t,n)=>{await r(e.configPath,eu(e));let i=hu(t,gu),a=ou(i.meta,{}),o={...i,meta:{...a,cli_version:n,schema_version:1}},s=bl.safeParse(o);if(!s.success)throw y(`config in ${e.configPath} is malformed beyond automatic migration (backup preserved at ${eu(e)}): ${T(s.error)}`);await $l(e.configPath,Ql(o))},xu=async(e,t,n)=>{let r=cu(t,e.configPath),i=uu(r);return vu(i),i===1?(await yu(e,r,n),`noop`):(await bu(e,r,n),`migrated`)},Su=async(e,t)=>{let n=await _u(e);return n===void 0?(await mu(e,t),`seeded`):xu(e,n,t)},Cu=new Set([`ENOENT`,`ENOTDIR`]),wu=e=>e.code??String(e),Tu=async e=>{try{return await i(e),!0}catch{return!1}},Eu=(e,t)=>{let n=se(e,t);return n===``||n!==`..`&&!n.startsWith(`..`+le)&&!ae(n)},Du=async e=>{try{return{real:await l(e)}}catch(e){return{code:wu(e)}}},
|
|
323
|
-
`));return{ok:!0,patterns:r,unparsed:
|
|
324
|
-
`));return
|
|
325
|
-
`)[0]??t;return n.length<=200?n:`${n.slice(0,200)}…`},
|
|
326
|
-
`),
|
|
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)}},Id=/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/u,Ld=/\d+\.\d+\.\d+/gu,Rd=e=>ll.safeParse(e).success,zd=e=>{let t=e.match(Ld);return t!==null&&t.length>1},Bd=e=>{let t=Id.exec(e);if(!t||zd(e))return;let[n]=t,r=e.replace(n,`{version}`);if(Rd(r))return r},Vd=(e,t,n)=>{let r=e.get(t);r===void 0?e.set(t,{count:1,index:n}):r.count+=1},Hd=e=>{let t=new Map;for(let[n,r]of e.entries()){let e=Bd(r);e&&Vd(t,e,n)}return t},Ud=(e,t)=>e.count>t.count||e.count===t.count&&e.index<t.index,Wd=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])=>Ud(r,t)?{data:r,format:n}:{data:t,format:e},{data:i,format:r}).format},Gd=e=>{let t=Hd(e);return Wd(t)},Kd=(e,t)=>e.replaceAll(`{version}`,()=>t),qd=async(e,t,n,r)=>{let i=Kd(n,r);if(!await Md(e,t,i))throw _(`tag '${i}' not found in ${t} — check the version or tag_format`);return i},Jd=/^(?<scheme>[a-z][a-z0-9+.-]*:\/\/)?[\s\S]*@/iu,U=e=>{let t=e.replace(Jd,`$<scheme><redacted>@`);return t.length<=200?t:`${t.slice(0,200)}…`},Yd=/\.git$/u,Xd=e=>e.replace(Yd,``),Zd=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)},Qd=/^git@(?<host>[^:/\s]+):(?<path>[^\s]+)$/u,$d=/^git\+/u,ef={"https:":`443`,"ssh:":`22`},tf=e=>e.split(`/`).some(e=>e===`.`||e===`..`),nf=e=>e.includes(`\\`),rf=e=>e.includes(`%`),af=e=>{let t=il.safeParse(e);if(!t.success)throw y(`not a supported git url: derived key '${U(e)}' is invalid`);return t.data},of=({host:e,port:t,protocol:n})=>{let r=ef[n];return t===``||t===r?e.toLowerCase():`${e.toLowerCase()}_${t}`},sf=e=>{let t=Xd(Zd(e.path));return af(`${of(e)}/${t}`)},cf=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 af(`local/${n}/${r}`)},lf=(e,t)=>{try{return new URL(e)}catch{throw y(`not a supported git url: ${U(t)}`)}},uf=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`)},df=(e,t)=>{if(e.protocol===`file:`){if(!t)throw y(`not a supported git url: unsupported protocol ${e.protocol}`);return cf(e.pathname)}if(e.protocol!==`https:`&&e.protocol!==`ssh:`)throw y(`not a supported git url: unsupported protocol ${e.protocol}`);return uf(e),sf({host:e.hostname,path:e.pathname,port:e.port,protocol:e.protocol})},ff=(e,t)=>{if(rf(e))throw y(`not a supported git url: percent-encoding not supported in ${U(t)}`);if(e.includes(`:`))throw y(`not a supported git url: ambiguous ':' in scp-style path ${U(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 ${U(t)}; use the ssh:// url form instead`)},pf=(e,t)=>{let n=e.groups?.path??``;return ff(n,t),sf({host:e.groups?.host??``,path:n,port:``,protocol:`ssh:`})},mf=(e,t)=>{if(nf(e))throw y(`not a supported git url: backslash not allowed in ${U(t)}`)},hf=(e,t)=>{if(tf(e))throw y(`not a supported git url: path traversal segment in ${U(t)}`)},gf=(e,t,n)=>{if(e.protocol!==`file:`&&rf(t))throw y(`not a supported git url: percent-encoding not supported in ${U(n)}`)},_f=(e,t)=>{let n=t?.allowFileUrls??!1,r=e.replace($d,``);mf(r,e),hf(r,e);let i=Qd.exec(r);if(i?.groups!==void 0)return{cloneUrl:r,key:pf(i,e)};let a=lf(r,e);return gf(a,r,e),{cloneUrl:r,key:df(a,n)}},vf=`.git`,yf=e=>e.endsWith(vf)?e:`${e}${vf}`,bf=(e,t)=>`https://${e.toLowerCase()}/${Zd(t)}`,xf=(e,t)=>`git@${e.toLowerCase()}:${yf(Zd(t))}`,Sf=e=>{if(e===`https:`)return`https`;if(e===`ssh:`)return`ssh`;throw y(`not a supported git url: unsupported protocol ${e}`)},Cf=(e,t,n)=>{let r=ef[e.protocol];if(e.port!==``&&e.port!==r)throw y(`cannot apply git_transport=${t} to ${U(n)}: its non-default port ${e.port} cannot be expressed in the ${t} url form — add the repo with an explicit url instead`)},wf=(e,t)=>t===`https`?bf(e.hostname,e.pathname):xf(e.hostname,e.pathname),Tf=(e,t,n)=>{let r=_f(t).key;if(r!==n)throw y(`git_transport transform changed repo identity: '${U(e)}' → '${t}' (key '${n}' → '${r}')`);return t},Ef=(e,t)=>{if(t.transport===`ssh`)return t.cloneUrl;let n=e.groups?.host??``,r=e.groups?.path??``;return Tf(t.cloneUrl,bf(n,r),t.originalKey)},Df=e=>{let t=lf(e.cloneUrl,e.cloneUrl);return Sf(t.protocol)===e.transport?e.cloneUrl:(Cf(t,e.transport,e.cloneUrl),Tf(e.cloneUrl,wf(t,e.transport),e.originalKey))},Of=(e,t)=>{if(e.startsWith(`file:`))return e;let n={cloneUrl:e,originalKey:_f(e).key,transport:t},r=Qd.exec(e);return r?.groups===void 0?Df(n):Ef(r,n)},kf=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u,Af=(e,t)=>{if(kf.test(t))return m(e,`lease-${t}`)},jf=async(e,t)=>{let n=Af(e,t);n!==void 0&&await(await o(n,`w`)).close()},Mf=async(e,t)=>{let n=Af(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`},Nf=async(e,t)=>{let n=Af(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`}}},Pf=`meta.json`,Ff=e=>{if(typeof e==`object`&&e&&`code`in e){let{code:t}=e;if(typeof t==`string`)return t}},If=e=>{try{return process.kill(e,0),!0}catch(e){return Ff(e)!==`ESRCH`}},Lf=e=>{try{return JSON.parse(e)}catch{return}},Rf=async e=>{try{return await s(e,`utf8`)}catch{return}},zf=new Set([`ENOENT`,`ENOTDIR`]),Bf=async e=>{try{return{state:`read`,text:await s(e,`utf8`)}}catch(e){let t=Ff(e);return{state:t!==void 0&&zf.has(t)?`missing`:`unreadable`}}},Vf=e=>{if(typeof e!=`string`)return;let t=Date.parse(e);if(!Number.isNaN(t))return t},Hf=e=>{if(typeof e!=`object`||!e)return;let{token:t}=e;if(typeof t==`string`)return t},Uf=e=>{if(!(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0||e>2147483647))return e},Wf=e=>{if(typeof e!=`object`||!e)return;let t=e,n=Uf(t.pid),r=Vf(t.acquired_at);if(n===void 0||r===void 0)return;let i=Hf(e);return{acquiredAtMs:r,pid:n,...i===void 0?{}:{token:i}}},Gf=async e=>{let t=await Rf(m(e,Pf));if(t!==void 0)return Hf(Lf(t))},Kf=async e=>{let t=await Bf(m(e,Pf));if(t.state!==`read`)return{state:t.state};let n=Wf(Lf(t.text));return n===void 0?{state:`malformed`}:{meta:n,state:`valid`}},qf=async e=>{try{return{mtimeMs:(await p(e)).mtimeMs,state:`ok`}}catch(e){return{state:Ff(e)===`ENOENT`?`gone`:`unreadable`}}},Jf=async(e,t)=>{let n=m(e,Pf),r=`${n}.tmp-${de()}`;await te(r,t,`utf8`),await u(r,n)},Yf=()=>de(),Xf=async(e,t)=>{await jf(e,t),await Jf(e,JSON.stringify({acquired_at:new Date().toISOString(),pid:process.pid,token:t}))},Zf=5e3,Qf=async(e,t,n)=>{if(t===`unreadable`)return{meta:t,observedAtMs:n,pidState:`unknown`,policy:`unknown`,stale:!1};let r=await qf(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:Zf,meta:t,observedAtMs:n,pidState:`unknown`,policy:`grace`,stale:i>Zf}},$f=async(e,t,n)=>{let r=t.token===void 0?{state:`absent`}:await Nf(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`}},ep=async(e,t)=>{let n=await Kf(e);if(n.state!==`valid`)return Qf(e,n.state,t);let{meta:r}=n,i=await $f(e,r,t),a=!If(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}}},tp=e=>e.meta===`valid`&&e.pidState===`definitely-dead`&&e.token!==void 0,np=async(e,t)=>await Gf(e)===t?await Mf(e,t)===`gone`?`lost`:`renewed`:`lost`,rp=new Set([`EEXIST`,`EPERM`,`EACCES`,`EBUSY`]),ip=new Set([`ENOENT`,`EPERM`,`EACCES`,`EBUSY`]),ap=async e=>{try{return await a(e,{recursive:!1}),!0}catch(e){let t=Ff(e);if(t!==void 0&&rp.has(t))return!1;throw e}},op=async(e,t)=>{try{return await u(e,t),!0}catch(e){let t=Ff(e);if(t!==void 0&&ip.has(t))return!1;throw e}},sp=`.claims`,cp=`.tombstones`,lp=(e,t)=>({lockPath:m(e,t),locksDir:e,name:t}),up=e=>m(e.locksDir,sp,e.name),dp=e=>m(e.locksDir,cp,de()),fp=async e=>{await a(m(e,sp),{recursive:!0}),await a(m(e,cp),{recursive:!0})},pp=e=>ap(e),mp=async e=>{try{await f(e)}catch{}},hp=async e=>{let t=dp(e);return await op(e.lockPath,t)?t:void 0},gp=async e=>{let t=await ep(e.lockPath,Date.now());if(!tp(t)||await Gf(e.lockPath)!==t.token)return!1;let n=await hp(e);return n!==void 0&&(await d(n,{force:!0,recursive:!0}),!0)},_p=async e=>{await fp(e.locksDir);let t=up(e);if(!await pp(t))return!1;let n=await gp(e).then(e=>({ok:!0,stolen:e}),e=>({error:e,ok:!1}));if(await mp(t),!n.ok)throw n.error;return n.stolen},vp=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}},yp=async e=>(await vp(e)).filter(e=>!e.name.startsWith(`.`)),bp=async(e,t,n)=>{let r=await ep(m(e,t.name),n);if(r.policy!==`none`)return{diagnosis:r,isDirectory:t.isDir,kind:`lock`,name:t.name}},xp=async(e,t)=>{let n=m(e,sp),r=await vp(n);return(await Promise.all(r.map(async e=>({diagnosis:await ep(m(n,e.name),t),isDirectory:e.isDir,kind:`claim`,name:e.name})))).filter(e=>e.diagnosis.policy!==`none`)},Sp=async e=>{let t=Date.now(),n=await yp(e.locksDir),[r,i]=await Promise.all([Promise.all(n.map(n=>bp(e.locksDir,n,t))),xp(e.locksDir,t)]);return[...r.filter(e=>e!==void 0),...i]},Cp=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`},wp=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)`,Tp={grace:`created`,lease:`lease renewed`,legacy:`acquired`,none:`observed`,unknown:`observed`},Ep={grace:`from creation, while its metadata has not been published`,lease:`from the last renewal`,legacy:`from acquisition (no renewable lease)`,none:``,unknown:``},Dp=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`:`, ${Tp[r]} ${Cp(t)} ago; its window is ${Cp(n)} ${Ep[r]}`},Op=(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: ${wp(t)}`;return tp(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}${Dp(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}${Dp(t)}. Retry once the other refs command finishes.`},kp=(e,t)=>{if(t.stopped)return;let n=setTimeout(()=>{t.stopped||(t.inFlight=Ap(e,t))},e.intervalMs);n.unref(),t.timer=n},Ap=async(e,t)=>{try{if(await e.renew()===`lost`){t.lost=!0,t.stopped=!0;return}}catch{}kp(e,t)},jp=e=>{let t={inFlight:Promise.resolve(),lost:!1,stopped:!1};return kp(e,t),{ownershipLost:()=>t.lost,stop:async()=>{t.stopped=!0,t.timer!==void 0&&clearTimeout(t.timer),await t.inFlight}}},Mp=/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/u,Np=async(e,t)=>{try{await Xf(e,t)}catch(e){if(Ff(e)===`ENOENT`)return`retry`;throw e}return t},Pp=async(e,t)=>{if(!await ap(e))return;let n=await Np(e,Yf());return n===`retry`?Date.now()>=t?void 0:Pp(e,t):n},Fp=async(e,t)=>{if(!await _p(e)){if(Date.now()>=t){let t=await ep(e.lockPath,Date.now());throw Ce(Op(e.name,t))}await ge(100)}},Ip=async(e,t)=>{let n=await Pp(e.lockPath,t);return n===void 0?(await Fp(e,t),Ip(e,t)):n},Lp=async(e,t)=>await Gf(e)===t&&(await d(e,{force:!0,recursive:!0}),!0),Rp=async e=>{try{return{ok:!0,value:await e()}}catch(e){return{error:e,ok:!1}}},zp=async(e,t,n,r)=>{await n.stop();let i=await Rp(()=>Lp(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},Bp=e=>e!==`.`&&e!==`..`&&Mp.test(e),Vp=e=>{if(!Bp(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}`)},W=async(e,t,n,r)=>{Vp(t);let i=lp(e.locksDir,t);await a(e.locksDir,{recursive:!0});let o=Date.now()+(r?.timeoutMs??1e4),s=await Ip(i,o),c=jp({intervalMs:3e4,renew:()=>np(i.lockPath,s)});return zp(i,s,c,await Rp(n))},Hp=sc({directory:P().optional(),url:P().optional()}),Up=sc({repository:lc([P(),Hp]).optional()}),Wp=/^(?:@[a-z0-9-~][a-z0-9._~-]*\/)?[a-z0-9-~][a-z0-9._~-]*$/u,Gp=new Set([`node_modules`,`favicon.ico`]),Kp=e=>_(`package '${e}' has no usable repository field — find the repository and run: refs add <git-url>`),qp=e=>{let[t,n]=e.split(`/`);return n??t??e},Jp=e=>{if(e.length>214)throw v(`invalid package name: '${e}' exceeds maximum length of 214 characters`);if(!Wp.test(e))throw v(`invalid package name: '${e}' does not match npm naming rules`);let t=qp(e);if(Gp.has(t))throw v(`invalid package name: '${e}' uses a reserved name`)},Yp=e=>e.replaceAll(`/`,`%2F`),Xp=e=>typeof e==`string`?e:e?.url,Zp=e=>{if(typeof e==`object`&&e?.directory){let t=ul.safeParse(e.directory);if(t.success)return t.data}},Qp=async(e,t)=>{try{return await e.json()}catch{throw y(`invalid npm registry response for '${t}': not parseable JSON`)}},$p=async(e,t)=>{let n=await e(`https://registry.npmjs.org/${Yp(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 Qp(n,t),i=Up.safeParse(r);if(!i.success)throw y(`invalid npm package response for '${t}'`);return i.data},em=(e,t)=>{try{return _f(e)}catch{throw Kp(t)}},tm=async(e,t)=>{Jp(t);let n=await $p(e,t),r=Xp(n.repository);if(r===void 0||r===``)throw Kp(t);let{cloneUrl:i,key:a}=em(r,t),o=Zp(n.repository);return o===void 0?{cloneUrl:i,key:a}:{cloneUrl:i,directory:o,key:a}},nm=(e,t,n)=>{let r=e instanceof RegExp?rm(e,n):e,i=t instanceof RegExp?rm(t,n):t,a=r!==null&&i!=null&&im(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)}},rm=(e,t)=>{let n=t.match(e);return n?n[0]:null},im=(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},am=`\0SLASH`+Math.random()+`\0`,om=`\0OPEN`+Math.random()+`\0`,sm=`\0CLOSE`+Math.random()+`\0`,cm=`\0COMMA`+Math.random()+`\0`,lm=`\0PERIOD`+Math.random()+`\0`,um=new RegExp(am,`g`),dm=new RegExp(om,`g`),fm=new RegExp(sm,`g`),pm=new RegExp(cm,`g`),mm=new RegExp(lm,`g`),hm=/\\\\/g,gm=/\\{/g,_m=/\\}/g,vm=/\\,/g,ym=/\\\./g;function bm(e){return isNaN(e)?e.charCodeAt(0):parseInt(e,10)}function xm(e){return e.replace(hm,am).replace(gm,om).replace(_m,sm).replace(vm,cm).replace(ym,lm)}function Sm(e){return e.replace(um,`\\`).replace(dm,`{`).replace(fm,`}`).replace(pm,`,`).replace(mm,`.`)}function Cm(e){if(!e)return[``];let t=[],n=nm(`{`,`}`,e);if(!n)return e.split(`,`);let{pre:r,body:i,post:a}=n,o=r.split(`,`);o[o.length-1]+=`{`+i+`}`;let s=Cm(a);return a.length&&(o[o.length-1]+=s.shift(),o.push.apply(o,s)),t.push.apply(t,o),t}function wm(e,t={}){if(!e)return[];let{max:n=1e5,maxLength:r=4e6}=t;return e.slice(0,2)===`{}`&&(e=`\\{\\}`+e.slice(2)),jm(xm(e),n,r,!0).map(Sm)}function Tm(e){return`{`+e+`}`}function Em(e){return/^-?0\d/.test(e)}function Dm(e,t){return e<=t}function Om(e,t){return e>=t}function km(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 Am(e,t,n,r){let i=e.split(/\.\./),a=[];if(i[0]===void 0||i[1]===void 0)return a;let o=bm(i[0]),s=bm(i[1]),c=Math.max(i[0].length,i[1].length),l=i.length===3&&i[2]!==void 0?Math.max(Math.abs(bm(i[2])),1):1,u=Dm;s<o&&(l*=-1,u=Om);let d=i.some(Em),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 jm(e,t,n,r){let i=[``],a=!1,o=!0;for(;;){let s=nm(`{`,`}`,e);if(!s)return km(i,e,[``],t,n,a);let c=s.pre;if(/\$$/.test(c)){if(i=km(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+sm+s.post,r=!0;continue}return km(i,c+`{`+s.body+`}`+s.post,[``],t,n,a)}o&&=(a=r&&!d,!1);let p;if(d)p=Am(s.body,u,t,n);else{let r=Cm(s.body);if(r.length===1&&r[0]!==void 0&&(r=jm(r[0],t,n,!1).map(Tm),r.length===1)){if(i=km(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=jm(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=km(i,c,p,t,n,a&&!s.post.length),!s.post.length)break;e=s.post}return i}const Mm=e=>{if(typeof e!=`string`)throw TypeError(`invalid pattern`);if(e.length>65536)throw TypeError(`pattern is too long`)},Nm={"[: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]},Pm=e=>e.replace(/[[\]\\-]/g,`\\$&`),Fm=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),Im=e=>e.join(``),Lm=(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(Nm))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(Pm(d)+`-`+Pm(t)):t===d&&r.push(Pm(t)),d=``,a++;continue}if(e.startsWith(`-]`,a+1)){r.push(Pm(t+`-`)),a+=2;continue}if(e.startsWith(`-`,a+1)){d=t,a+=2;continue}r.push(Pm(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[Fm(e),!1,u-n,!1]}let f=`[`+(l?`^`:``)+Im(r)+`]`,p=`[`+(l?``:`^`)+Im(i)+`]`;return[r.length&&i.length?`(`+f+`|`+p+`)`:r.length?f:p,s,u-n,!0]},Rm=(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 G;const zm=new Set([`!`,`?`,`+`,`*`,`@`]),Bm=e=>zm.has(e),Vm=e=>Bm(e.type),Hm=new Map([[`!`,[`@`]],[`?`,[`?`,`@`]],[`@`,[`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`]]]),Um=new Map([[`!`,[`?`]],[`@`,[`?`]],[`+`,[`?`,`*`]]]),Wm=new Map([[`!`,[`?`,`@`]],[`?`,[`?`,`@`]],[`@`,[`?`,`@`]],[`*`,[`*`,`+`,`?`,`@`]],[`+`,[`+`,`@`,`?`,`*`]]]),Gm=new Map([[`!`,new Map([[`!`,`@`]])],[`?`,new Map([[`*`,`*`],[`+`,`*`]])],[`@`,new Map([[`!`,`!`],[`?`,`?`],[`@`,`@`],[`*`,`*`],[`+`,`+`]])],[`+`,new Map([[`?`,`*`],[`*`,`*`]])]]),Km=`(?!\\.)`,qm=new Set([`[`,`.`]),Jm=new Set([`..`,`.`]),Ym=new Set(`().*{}+?[]^$\\!`),Xm=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`),Zm=`[^/]+?`;let Qm=0;var $m=class{type;#e;#t;#n=!1;#r=[];#i;#a;#o;#s=!1;#c;#l;#u=!1;id=++Qm;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 G&&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 G&&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 G(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&&Bm(n)&&e.charAt(u)===`(`&&i<=a){t.push(d),d=``;let a=new G(n,t);u=G.#f(e,a,u,r,i+1),t.push(a);continue}d+=n}return t.push(d),u}let u=n+1,d=new G(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&&Bm(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 G(n,d);d.push(o),u=G.#f(e,o,u,r,i+a);continue}if(n===`|`){d.push(p),p=``,f.push(d),d=new G(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,Um)}#m(e,t=Hm){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=Wm){return!!t.get(this.type)?.includes(e)}#g(e,t){let n=e.#r[0],r=new G(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!!Gm.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=Gm.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 G(null,void 0,t);return G.#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()),!Vm(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`?G.#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&&Jm.has(this.#r[0]))){let n=qm,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?Km:``}let a=``;return this.isEnd()&&this.#e.#s&&this.#i?.type===`!`&&(a=`(?:$|\\/)`),[i+r+a,Rm(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,Rm(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?Km:``)+Zm;else{let n=this.type===`!`?`))`+(this.isStart()&&!t&&!e?Km:``)+`[^/]*?)`:this.type===`@`?`)`:this.type===`?`?`)?`:this.type===`+`&&a?`)`:this.type===`*`&&a?`)?`:`)${this.type}`;o=r+i+n}return[o,Rm(i),this.#t=!!this.#t,this.#n]}#x(){if(Vm(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+=(Ym.has(c)?`\\`:``)+c;continue}if(c===`*`){if(o)continue;o=!0,i+=n&&/^[*]+$/.test(e)?Zm:`[^/]*?`,t=!0;continue}if(o=!1,c===`\\`){s===e.length-1?i+=`\\\\`:r=!0;continue}if(c===`[`){let[n,r,o,c]=Lm(e,s);if(o){i+=n,a||=r,s+=o-1,t||=c;continue}}if(c===`?`){i+=`[^/]`,t=!0;continue}i+=Xm(c)}return[i,Rm(e),!!t,a]}};G=$m;const eh=(e,{windowsPathsNoEscape:t=!1,magicalBraces:n=!1}={})=>n?t?e.replace(/[?*()[\]{}]/g,`[$&]`):e.replace(/[?*()[\]\\{}]/g,`\\$&`):t?e.replace(/[?*()[\]]/g,`[$&]`):e.replace(/[?*()[\]\\]/g,`\\$&`),K=(e,t,n={})=>(Mm(t),!n.nocomment&&t.charAt(0)===`#`?!1:new Eh(t,n).match(e)),th=/^\*+([^+@!?*[(]*)$/,nh=e=>t=>!t.startsWith(`.`)&&t.endsWith(e),rh=e=>t=>t.endsWith(e),ih=e=>(e=e.toLowerCase(),t=>!t.startsWith(`.`)&&t.toLowerCase().endsWith(e)),ah=e=>(e=e.toLowerCase(),t=>t.toLowerCase().endsWith(e)),oh=/^\*+\.\*+$/,sh=e=>!e.startsWith(`.`)&&e.includes(`.`),ch=e=>e!==`.`&&e!==`..`&&e.includes(`.`),lh=/^\.\*+$/,uh=e=>e!==`.`&&e!==`..`&&e.startsWith(`.`),dh=/^\*+$/,fh=e=>e.length!==0&&!e.startsWith(`.`),ph=e=>e.length!==0&&e!==`.`&&e!==`..`,mh=/^\?+([^+@!?*[(]*)?$/,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=bh([e]);return t?(t=t.toLowerCase(),e=>n(e)&&e.toLowerCase().endsWith(t)):n},_h=([e,t=``])=>{let n=bh([e]);return t?e=>n(e)&&e.endsWith(t):n},vh=([e,t=``])=>{let n=yh([e]);return t?e=>n(e)&&e.endsWith(t):n},yh=([e])=>{let t=e.length;return e=>e.length===t&&!e.startsWith(`.`)},bh=([e])=>{let t=e.length;return e=>e.length===t&&e!==`.`&&e!==`..`},xh=typeof process==`object`&&process?typeof process.env==`object`&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:`posix`,Sh={win32:{sep:`\\`},posix:{sep:`/`}};K.sep=xh===`win32`?Sh.win32.sep:Sh.posix.sep;const q=Symbol(`globstar **`);K.GLOBSTAR=q,K.filter=(e,t={})=>n=>K(n,e,t);const J=(e,t={})=>Object.assign({},e,t);K.defaults=e=>{if(!e||typeof e!=`object`||!Object.keys(e).length)return K;let t=K;return Object.assign((n,r,i={})=>t(n,r,J(e,i)),{Minimatch:class extends t.Minimatch{constructor(t,n={}){super(t,J(e,n))}static defaults(n){return t.defaults(J(e,n)).Minimatch}},AST:class extends t.AST{constructor(t,n,r={}){super(t,n,J(e,r))}static fromGlob(n,r={}){return t.AST.fromGlob(n,J(e,r))}},unescape:(n,r={})=>t.unescape(n,J(e,r)),escape:(n,r={})=>t.escape(n,J(e,r)),filter:(n,r={})=>t.filter(n,J(e,r)),defaults:n=>t.defaults(J(e,n)),makeRe:(n,r={})=>t.makeRe(n,J(e,r)),braceExpand:(n,r={})=>t.braceExpand(n,J(e,r)),match:(n,r,i={})=>t.match(n,r,J(e,i)),sep:t.sep,GLOBSTAR:q})};const Ch=(e,t={})=>(Mm(e),t.nobrace||!/\{(?:(?!\{).)*\}/.test(e)?[e]:wm(e,{max:t.braceExpandMax}));K.braceExpand=Ch,K.makeRe=(e,t={})=>new Eh(e,t).makeRe(),K.match=(e,t,n={})=>{let r=new Eh(t,n);return e=e.filter(e=>r.match(e)),r.options.nonull&&!e.length&&e.push(t),e};const wh=/[?*]|[+@!]\(.*?\)|\[|\]/,Th=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,`\\$&`);var Eh=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;maxGlobstarRecursion;regexp;constructor(e,t={}){Mm(e),t||={},this.options=t,this.maxGlobstarRecursion=t.maxGlobstarRecursion??200,this.pattern=e,this.platform=t.platform||xh,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]===`?`||!wh.test(e[2]))&&!wh.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(q)?this.#e(e,t,n,r,i):this.#n(e,t,n,r,i)}#e(e,t,n,r,i){let a=t.indexOf(q,i),o=t.lastIndexOf(q),[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===q?(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===q)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 Ch(this.pattern,this.options)}parse(e){Mm(e);let t=this.options;if(e===`**`)return q;if(e===``)return``;let n,r=null;(n=e.match(dh))?r=t.dot?ph:fh:(n=e.match(th))?r=(t.nocase?t.dot?ah:ih:t.dot?rh:nh)(n[1]):(n=e.match(mh))?r=(t.nocase?t.dot?gh:hh:t.dot?_h:vh)(n):(n=e.match(oh))?r=t.dot?ch:sh:(n=e.match(lh))&&(r=uh);let i=$m.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`?Th(e):e===q?q:e._src});t.forEach((e,r)=>{let i=t[r+1],a=t[r-1];e===q&&a!==q&&(a===void 0?i!==void 0&&i!==q?t[r+1]=`(?:\\/|`+n+`\\/)?`+i:t[r]=n:i===void 0?t[r-1]=a+`(?:\\/|\\/`+n+`)?`:i!==q&&(t[r-1]=a+`(?:\\/|\\/`+n+`\\/)`+i,t[r+1]=q))});let i=t.filter(e=>e!==q);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 K.defaults(e).Minimatch}};K.AST=$m,K.Minimatch=Eh,K.escape=eh,K.unescape=Rm;const Dh=/[/\\]/u,Oh={kind:`ignore`},kh=e=>!ae(e)&&e.split(Dh).every(e=>e!==`.`&&e!==`..`),Ah=/^!+/u,jh=/^\.?\/+/u,Mh=e=>{let t=Ah.exec(e)?.[0]??``;return{body:e.slice(t.length).replace(jh,``),negated:t.length%2==1}},Nh=e=>Mh(e).negated,Ph=e=>Mh(e).body,Fh=/[?[\]{}()]/u,Ih=e=>kh(e)&&!Nh(e)&&!Fh.test(e),Lh=(e,t)=>K(e,t),Rh=e=>e.replaceAll(/\/+/gu,`/`).replace(/\/$/u,``),zh=e=>{let t=Rh(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n===-1?Oh:{baseDir:n===0?`.`:t.slice(0,n).join(`/`),kind:`expand-children`,pattern:Rh(e),suffix:t.slice(n+1).join(`/`)}},Bh=e=>{let t=Rh(e).split(`/`).filter(e=>e.includes(`*`));return t.length<=1&&!t.includes(`**`)},Vh=e=>{let t=Rh(e).split(`/`),n=t.findIndex(e=>e.includes(`*`));return n<=0?`.`:t.slice(0,n).join(`/`)},Hh=e=>Ih(e)?e.includes(`*`)?Bh(e)?zh(e):{baseDir:Vh(e),kind:`expand-recursive`,pattern:Rh(e)}:{dir:e,kind:`probe-dir`,pattern:e}:Oh,Uh=new Set([`candidate_not_inspected`,`scan_budget_exhausted`,`manifest_unreadable`,`unsupported_pattern`,`workspace_declaration_unparsed`,`workspace_dir_unreadable`,`workspace_file_unreadable`]),Wh=(e,t)=>t?.name?{name:t.name,path:e}:void 0,Gh=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},Kh=e=>!e.diagnostics.some(e=>Uh.has(e.kind)),qh=e=>!e.diagnostics.some(e=>e.kind===`no_workspace_declaration`),Jh=(e,t)=>e<t?-1:+(e>t),Yh=e=>`path`in e?`${e.kind} ${e.path}`:`file`in e?`${e.kind} ${e.file}`:`pattern`in e?`${e.kind} ${e.pattern}`:e.kind,Xh=e=>e.toSorted((e,t)=>Jh(Yh(e),Yh(t))),Zh=e=>!ae(e)&&!e.split(/[/\\]/u).includes(`..`),Qh=(e,t)=>e.kind===`missing`?{kind:`absent`}:e.kind===`outside`?{kind:`unreadable`,reason:`${t} escapes the checkout`}:{kind:`unreadable`,reason:e.code},$h=async(e,t,n)=>{if(!Zh(t))return{kind:`unreadable`,reason:`path escapes the checkout`};let r=await eg(e,t);if(`probe`in r)return r.probe;let i=await tg(r.real);return`reason`in i?{kind:`unreadable`,reason:i.reason}:i.found===n?{kind:`match`}:{found:i.found,kind:`mismatch`}},eg=async(e,t)=>{let n=await Ou(e,m(e,t));if(n.kind!==`inside`)return{probe:Qh(n,`path`)};let r=await Ou(e,m(n.real,`package.json`));return r.kind===`inside`?{real:r.real}:{probe:Qh(r,`manifest`)}},tg=async e=>{try{let t=JSON.parse(await s(e,`utf8`));return{found:Lu(t)}}catch(e){return{reason:e.code??String(e)}}},ng=(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(Jh)}},rg=new Set;let ig=!1;const ag=()=>{for(let e of rg)try{e.kill(`SIGKILL`)}catch{}},og=[`SIGINT`,`SIGTERM`,`SIGHUP`,`SIGBREAK`],sg=e=>{let t=()=>{ag(),process.removeListener(e,t),process.kill(process.pid,e)};process.on(e,t)},cg=()=>{ig||(ig=!0,og.forEach(e=>{sg(e)}),process.on(`exit`,ag))},lg=()=>{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}}},ug=(e,t)=>[e.replace(/\r?\n$/u,``),t].filter(e=>e!==``).join(`
|
|
328
|
-
`),dg=(e,t,n)=>{let r=e;return t.truncated&&(r=ug(r,`refs: stdout exceeded 67108864 bytes, truncated`)),n.truncated&&(r=ug(r,`refs: stderr exceeded 67108864 bytes, truncated`)),r},fg={clear:()=>{},markedTimedOut:()=>!1},pg=(e,t)=>{if(t===void 0)return fg;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}},mg=e=>e===void 0?{}:{cwd:e},hg=(e,t)=>ug(e,`refs: command timed out after ${String(t)}ms`),gg=(e,t)=>({exitCode:124,stderr:hg(e,t),stdout:``,timedOut:!0}),_g=(e,t,n)=>{let r=be(e,t,{...mg(n?.cwd),stdio:[`ignore`,`pipe`,`pipe`]});rg.add(r);let i=lg(),a=lg();return r.stdout.on(`data`,e=>{i.push(e)}),r.stderr.on(`data`,e=>{a.push(e)}),{child:r,stderrCollector:a,stdoutCollector:i,timeout:pg(r,n?.timeoutMs)}},vg=(e,t,n)=>{try{return _g(e,t,n)}catch(e){return{exitCode:127,stderr:bg(e),stdout:``}}},yg=e=>!(`child`in e),bg=e=>e instanceof Error?e.message:String(e),xg=async e=>{try{let[t]=await ve(e,`close`);return{code:t}}catch(e){return{code:null,errorMessage:bg(e)}}},Sg=e=>e===null?1:e,Cg=(e,t)=>t.truncated?{...e,stdoutTruncated:!0}:e,wg=e=>e.timedOut?gg(e.stderr.text,e.timeoutMs):e.errorMessage===void 0?Cg({exitCode:Sg(e.code),stderr:dg(e.stderr.text,e.stdout,e.stderr),stdout:e.stdout.text},e.stdout):Cg({exitCode:127,stderr:ug(e.stderr.text,e.errorMessage),stdout:e.stdout.text},e.stdout);var Tg=class{async run(e,t,n){cg();let r=vg(e,t,n);if(yg(r))return r;let i=await xg(r.child);return rg.delete(r.child),r.timeout.clear(),wg({code:i.code,errorMessage:i.errorMessage,stderr:r.stderrCollector.finish(),stdout:r.stdoutCollector.finish(),timedOut:r.timeout.markedTimedOut(),timeoutMs:n?.timeoutMs})}};const Eg=hl.partial({description:!0}),Dg=I({default_branch:P().min(1),key:il,tag_format_candidate:ll.nullable(),url:P().min(1)});Dg.extend({description:P().default(``),packages:Gc(Eg)});const Og=Dg.extend({description:P().min(1),packages:Gc(hl)}),kg=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()}),Ag=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(),kg)).default({})}),jg=(e,t,n)=>t?.[e]??n[e],Mg=async e=>{try{return await s(e.statePath,`utf8`)}catch(e){if(R(e))return;throw e}},Ng=e=>{try{return JSON.parse(e)}catch{return}},Pg=async e=>{let t=await Mg(e);if(t===void 0)return Ag.parse({});let n=Ng(t);if(n===void 0)return Ag.parse({});let r=Ag.safeParse(n);return r.success?r.data:Ag.parse({})},Fg=async(e,t)=>{let n=Ag.safeParse(t);if(!n.success)throw y(T(n.error));await $l(e.statePath,`${JSON.stringify(n.data,void 0,2)}\n`)},Ig=/^\d+\.\d+\.\d+$/u,Lg=/^0+(?=\d)/u,Rg=(e,t)=>{let n=e.replace(Lg,``),r=t.replace(Lg,``);return n.length===r.length?n===r?0:n<r?-1:1:n.length<r.length?-1:1},zg=(e,t)=>{if(!Ig.test(e)||!Ig.test(t))return;let n=e.split(`.`),r=t.split(`.`);return n.map((e,t)=>Rg(e,r[t]??``)).find(e=>e!==0)??0},Bg=sc({version:P().regex(Ig)}),Vg=I({checked_at:Vc(),latest_version:P().regex(Ig)}),Hg=async e=>{try{let t=Vg.safeParse(JSON.parse(await s(e.updateCachePath,`utf8`)));return t.success?t.data:void 0}catch{return}},Ug=async(e,t)=>{try{await p(e.root),await $l(e.updateCachePath,`${JSON.stringify(t,void 0,2)}\n`)}catch{}},Wg=(e,t)=>{let n=t-Date.parse(e.checked_at);return n>=0&&n<864e5},Gg=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=Bg.safeParse(await t.json());return n.success?n.data.version:void 0}catch{return}},Kg=async e=>{let t=await Hg(e.home);if(t!==void 0&&Wg(t,e.nowMs))return{latest:t.latest_version,refreshed:!1,stale:!1};let n=await Gg(e.fetch);return n===void 0?{latest:t?.latest_version,refreshed:!1,stale:!0}:(await Ug(e.home,{checked_at:new Date(e.nowMs).toISOString(),latest_version:n}),{latest:n,refreshed:!0,stale:!1})},qg=(e,t)=>{let n=zg(e,t);return n!==void 0&&n<0},Jg=(e,t)=>`refs ${t} is available (this is ${e}) — update: npm i -g @kaisers-io/refs@latest`,Yg=e=>{let t=e.REFS_UPDATE_CHECK?.trim();if(t===`0`)return!1;if(t===`1`)return!0},Xg=e=>{let t=e.CI?.trim().toLowerCase();return t!==void 0&&t!==``&&t!==`false`&&t!==`0`},Zg={check:!0,notify:!0},Qg=e=>{let t=Yg(e.env);return t===void 0?(e.updates??Zg).check?Xg(e.env)?`ci`:`on`:`config`:t?`on`:`env`},$g=e=>Qg(e)===`on`,e_=e=>$g(e)&&(e.updates??Zg).notify,t_=async(e,t)=>{let n=await Ou(e,m(t,`package.json`));if(n.kind===`inside`)try{let e=JSON.parse(await s(n.real,`utf8`));return{name:Lu(e)}}catch{return}},n_=async(e,t)=>{let n=await t_(e,m(e,t));if(n===void 0)return{diagnostic:{kind:`manifest_unreadable`,path:t}};let r=Wh(t,n);return r===void 0?{diagnostic:{kind:`manifest_missing_name`,path:t}}:{pkg:r}},r_=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}},i_=new Set([`ENOENT`,`ENOTDIR`]),a_=async(e,t)=>{let n=await Ou(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`}},o_=async e=>{try{return{entries:await c(e,{withFileTypes:!0})}}catch(e){return{code:e.code??``}}},s_=e=>Promise.all(e.entries.map(t=>a_(e.repoDir,m(e.fullPath,t.name,e.suffix)))),c_=(e,t,n)=>e.filter((e,r)=>n(t[r])).map(e=>e.name),l_=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([s_({entries:n,fullPath:r,repoDir:i,suffix:a}),s_({entries:o,fullPath:r,repoDir:i,suffix:a})]);return{diagnostics:[...c_(n,c,e=>e===`rejected`).map(e=>({kind:`manifest_unreadable`,path:s(e)})),...c_(o,l,e=>e!==`none`).map(e=>({kind:`candidate_not_inspected`,path:s(e)}))],dirs:c_(n,c,e=>e===`manifest`).map(e=>s(e))}},u_=async e=>{let t=await n_(e,`.`);return`pkg`in t?[t]:[]},d_=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]},f_=async e=>{let[t]=await u_(e);return t!==void 0&&`pkg`in t?t.pkg:void 0},p_=`package.json`,m_=e=>{let t=Rh(e).split(`/`);return t.includes(`**`)?void 0:t.length},h_=e=>Rh(e).split(`/`).some(e=>e.startsWith(`.`)),g_=e=>e===`.`?0:e.split(`/`).length,__=e=>{let t=Rh(e),n=new Eh(`${t}/${p_}`),r=new Eh(t);return{couldHold:e=>r.match(e,!0),selects:e=>n.match(oe.join(e,p_))}},v_=e=>({...__(e),maxDepth:m_(e),selectsHidden:h_(e)}),y_=new Set([`ENOENT`,`ENOTDIR`]),b_=new Set([`.git`,`node_modules`]),x_=e=>e.some(e=>e.name.toLowerCase()===`package.json`&&!e.isDirectory()),S_=e=>e.some(e=>e.isSymbolicLink()&&!b_.has(e.name)),C_=async(e,t)=>{let n=await o_(t);return`code`in n?{answer:y_.has(n.code)}:(e.budget.entries-=n.entries.length,e.budget.entries<0||x_(n.entries)||S_(n.entries)?{answer:!1}:{entries:n.entries})},w_=async(e,t,n)=>{if(e.budget.dirs<=0||n>32)return!1;--e.budget.dirs;let r=await C_(e,t);return`answer`in r?r.answer:T_(e,{dir:t,entries:r.entries},n)},T_=async(e,t,n)=>{let r=t.entries.filter(e=>e.isDirectory()&&!b_.has(e.name));for(let i of r)if(!await w_(e,m(t.dir,i.name),n+1))return!1;return!0},E_=async(e,t)=>{let n=await Ou(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 w_(e,n.real,1)||e.diagnostics.push({kind:`candidate_not_inspected`,path:t})}},D_=()=>({dirs:2e4,entries:2e5}),O_=new Set([`.git`,`node_modules`]),k_=(e,t)=>{e.diagnostics.push({kind:`scan_budget_exhausted`,path:t,pattern:e.pattern})},A_=async(e,t,n)=>{if(!e.selects(t)||n.has(t))return;let r=await a_(e.repoDir,m(e.repoDir,t));r===`manifest`&&e.dirs.push(t),r===`rejected`&&e.diagnostics.push({kind:`manifest_unreadable`,path:t})},j_=(e,t)=>!e.selectsHidden&&t.excluded.coversSubtree(t.relPath),M_=async(e,t,n)=>!e.couldHold(n.relPath)||O_.has(t.name)||j_(e,n)?!1:t.isSymbolicLink()?(j_(e,n)||await E_(e,n.relPath),!1):t.isDirectory(),N_=async(e,t)=>{let n=await o_(m(e.repoDir,t));if(`code`in n){i_.has(n.code)||e.diagnostics.push({kind:`workspace_dir_unreadable`,path:t});return}if(e.budget.entries-=n.entries.length,e.budget.entries<0){k_(e,t);return}return n.entries},P_=async(e,t,n)=>{if(e.budget.dirs<=0){k_(e,t.relPath);return}if(--e.budget.dirs,await A_(e,t.relPath,n),e.maxDepth!==void 0&&g_(t.relPath)>=e.maxDepth)return;let r=await N_(e,t.relPath);r!==void 0&&await I_(e,{depth:t.depth,entries:r,relPath:t.relPath},n)},F_=(e,t)=>oe.join(e===`.`?``:e,t),I_=async(e,t,n)=>{for(let r of t.entries){let i=F_(t.relPath,r.name);await M_(e,r,{excluded:n,relPath:i})&&(t.depth+1>32?k_(e,i):await P_(e,{depth:t.depth+1,relPath:i},n))}},L_=async(e,t)=>{let n=await Ou(e,m(e,t));if(n.kind!==`inside`)return n.kind===`missing`?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}},R_=async(e,t,n)=>{let r=await L_(e,t.baseDir);if(r!==void 0)return r;let i={...v_(t.pattern),budget:n.budget,diagnostics:[],dirs:[],pattern:t.pattern,repoDir:e};return await P_(i,{depth:1,relPath:t.baseDir},n.excluded),{diagnostics:i.diagnostics,dirs:i.dirs}},z_=(e,t)=>oe.join(e.baseDir===`.`?``:e.baseDir,t,e.suffix),B_=(e,t)=>Lh(z_(t,e.name),t.pattern),V_=async(e,t)=>{let n=m(e,t),r=await Ou(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 o_(n);return`code`in i?{result:i_.has(i.code)?{diagnostics:[],dirs:[]}:{diagnostics:[{kind:`workspace_dir_unreadable`,path:t}],dirs:[]}}:{entries:i.entries}},H_=async(e,t,n)=>{let{baseDir:r}=t,i=await V_(e,r);if(`result`in i)return i.result;let a=e=>B_(e,t)&&!n.has(z_(t,e.name)),o={entries:i.entries};return l_({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))})},U_=async(e,t)=>{let n=await a_(e,m(e,t));return n===`manifest`?{diagnostics:[],dirs:[Rh(t)]}:n===`rejected`?{diagnostics:[{kind:`manifest_unreadable`,path:t}],dirs:[]}:{diagnostics:[],dirs:[]}},W_=(e,t,n)=>{let{excluded:r}=n,i=Hh(t.body);return i.kind===`expand-children`?H_(e,i,r):i.kind===`expand-recursive`?R_(e,i,n):i.kind===`probe-dir`?r.has(Rh(i.dir))?Promise.resolve({diagnostics:[],dirs:[]}):U_(e,i.dir):Promise.resolve({diagnostics:[{kind:`unsupported_pattern`,pattern:t.declared}],dirs:[]})},G_=(e,t)=>Lh(Ph(e),Ph(t)),K_=e=>({negations:e.filter(e=>Nh(e)),patterns:e.filter(e=>!Nh(e))}),q_=e=>{let t=e.reduce((e,t)=>Nh(t)?{negations:[...e.negations,t],patterns:e.patterns}:{negations:e.negations.filter(e=>!G_(t,e)),patterns:[...e.patterns,t]},{negations:[],patterns:[]});return{negations:t.negations,patterns:t.patterns.filter(e=>!t.negations.some(t=>G_(e,t)))}},J_=e=>e.endsWith(`/`)?e:`${e}/`,Y_=(e,t)=>e.some(e=>Lh(J_(t),J_(Ph(e)))),X_=(e,t)=>{let n=Ph(e);return n.endsWith(`/**`)&&Lh(t,n.slice(0,-3))},Z_=e=>({coversSubtree:t=>e.some(e=>X_(e,t)),has:t=>Y_(e,t)}),Q_=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]}},$_=async(e,t,n)=>{let{negations:r,patterns:i}=t,a=Z_(r),o=Q_(await Promise.all(i.map(t=>W_(e,{body:Ph(t),declared:t},{budget:n,excluded:a}))));return{diagnostics:o.diagnostics,dirs:o.dirs}},ev=async(e,t)=>{let n=q_(t.npm),r=K_(t.pnpm),i=D_(),a=await Promise.all([$_(e,n,i),$_(e,r,i)]);return Q_(a)},tv=async e=>{let t=await Wu(e);if(t.npm.length===0&&t.pnpm.length===0)return{diagnostics:Xh([...t.diagnostics,{kind:`no_workspace_declaration`}]),packages:[]};let n=await ev(e,t),[r,i]=await Promise.all([u_(e),Promise.all(n.dirs.map(t=>n_(e,t)))]),a=r_([...r,...i]);return{diagnostics:Xh([...t.diagnostics,...n.diagnostics,...a.diagnostics]),packages:d_(Gh(a.packages))}};var nv=`0.14.1`;const rv=async()=>{let e=[];for await(let t of process.stdin)e.push(Buffer.from(t));return Buffer.concat(e).toString(`utf8`)},iv=()=>{try{return he()}catch{return``}},av=()=>({cliVersion:nv,cwd:process.cwd(),env:process.env,errLine:e=>{process.stderr.write(`${e}\n`)},fetcher:(e,t)=>fetch(e,t),homedir:iv(),nodeVersion:process.version,out:e=>{process.stdout.write(`${e}\n`)},readStdin:rv,runner:new Tg});var ov=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}},sv=class extends ov{constructor(e){super(1,`commander.invalidArgument`,e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},cv=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 sv(`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 lv(e){let t=e.name()+(e.variadic===!0?`...`:``);return e.required?`<`+t+`>`:`[`+t+`]`}var uv=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=>lv(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(`
|
|
322
|
+
`.replaceAll(`{{CLI_VERSION}}`,t)),`seeded`),hu=(e,t)=>{let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];t===void 0?n[e]=r:au(t)&&au(r)&&(n[e]=hu(t,r))}return n},gu={meta:{},refs:{},settings:{}},_u=async e=>{try{return await su(e)}catch(e){if(e instanceof g&&e.code===`not_found`)return;throw e}},vu=e=>{if(e!==void 0&&e>1)throw y(`config schema ${e} is newer than this CLI supports — upgrade refs`)},yu=async(e,t,n)=>{let r=ou(t.meta,{});if(r.cli_version===n)return;let i={...t,meta:{...r,cli_version:n}};await $l(e.configPath,Ql(i))},bu=async(e,t,n)=>{await r(e.configPath,eu(e));let i=hu(t,gu),a=ou(i.meta,{}),o={...i,meta:{...a,cli_version:n,schema_version:1}},s=bl.safeParse(o);if(!s.success)throw y(`config in ${e.configPath} is malformed beyond automatic migration (backup preserved at ${eu(e)}): ${T(s.error)}`);await $l(e.configPath,Ql(o))},xu=async(e,t,n)=>{let r=cu(t,e.configPath),i=uu(r);return vu(i),i===1?(await yu(e,r,n),`noop`):(await bu(e,r,n),`migrated`)},Su=async(e,t)=>{let n=await _u(e);return n===void 0?(await mu(e,t),`seeded`):xu(e,n,t)},Cu=new Set([`ENOENT`,`ENOTDIR`]),wu=e=>e.code??String(e),Tu=async e=>{try{return await i(e),!0}catch{return!1}},Eu=(e,t)=>{let n=se(e,t);return n===``||n!==`..`&&!n.startsWith(`..`+le)&&!ae(n)},Du=async e=>{try{return{real:await l(e)}}catch(e){return{code:wu(e)}}},H=async(e,t)=>{let n=await Du(e);if(`code`in n)return{code:n.code,kind:`unreadable`};let r=await Du(t);return`code`in r?Cu.has(r.code)?await Tu(t)?{code:r.code,kind:`unreadable`}:{kind:`missing`}:{code:r.code,kind:`unreadable`}:Eu(n.real,r.real)?{kind:`inside`,real:r.real}:{kind:`outside`}},Ou=/^\s*-\s+["']?(?<pattern>[^"'#]+)["']?/u,ku=/^packages:\s*(?:#.*)?$/u,Au=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ju=e=>{if(Array.isArray(e))return e.filter(e=>typeof e==`string`);if(!Au(e))return[];let{packages:t}=e;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]},Mu=Symbol(`end-of-section`),Nu=e=>{let t=e.trim();if(t&&!t.startsWith(`-`)&&t.includes(`:`)&&!ku.test(e))return Mu;if(!t.startsWith(`-`))return;let n=Ou.exec(e)?.groups?.pattern?.trim();if(n)return n},Pu=e=>{let t=[];for(let n of e){let e=Nu(n);if(e===Mu)break;e!==void 0&&t.push(e)}return t},Fu=e=>{let t=e.findIndex(e=>ku.test(e));return t===-1?[]:Pu(e.slice(t+1))},Iu=e=>{let{name:t}=e;if(typeof t==`string`)return t},Lu=async(e,t)=>{let n=await H(e,t);if(n.kind===`missing`)return{ok:!0};if(n.kind!==`inside`)return{ok:!1};try{return{content:await s(n.real,`utf8`),ok:!0}}catch{return{ok:!1}}},Ru=async(e,t)=>{let n=await Lu(e,t);return n.ok?n.content===void 0?{ok:!0,patterns:[]}:zu(n.content):{ok:!1,patterns:[]}},zu=e=>{try{let t=JSON.parse(e);return{ok:!0,patterns:ju(t.workspaces)}}catch{return{ok:!1,patterns:[]}}},Bu=/^packages:/mu,Vu=(e,t)=>t.length===0&&Bu.test(e),Hu=async(e,t)=>{let n=await Lu(e,t);if(!n.ok)return{ok:!1,patterns:[]};if(n.content===void 0)return{ok:!0,patterns:[]};let r=Fu(n.content.split(`
|
|
323
|
+
`));return{ok:!0,patterns:r,unparsed:Vu(n.content,r)}},Uu=async e=>{let[t,n]=await Promise.all([Ru(e,m(e,`package.json`)),Hu(e,m(e,`pnpm-workspace.yaml`))]),r=[];return t.ok||r.push({file:`package.json`,kind:`workspace_file_unreadable`}),n.ok||r.push({file:`pnpm-workspace.yaml`,kind:`workspace_file_unreadable`}),n.unparsed===!0&&r.push({file:`pnpm-workspace.yaml`,kind:`workspace_declaration_unparsed`}),{diagnostics:r,npm:t.patterns,pnpm:n.patterns}},Wu=`\0unreadable`,Gu=`pnpm-workspace.yaml`,Ku=async(e,t)=>{let n=await e.run(`git`,[`ls-tree`,`-z`,`--name-only`,t.rev,`--`,t.path],{cwd:t.dir});return n.exitCode===0?n.stdout.includes(t.path):void 0},qu=async(e,t)=>{let n=await Ku(e,t);if(n===void 0)return{kind:`unreadable`};if(!n)return{kind:`absent`};let r=await e.run(`git`,[`show`,`${t.rev}:${t.path}`],{cwd:t.dir});return r.exitCode===0?{contents:r.stdout}:{kind:`unreadable`}},Ju=async(e,t,n)=>{let r=await qu(e,{dir:t.dir,path:`package.json`,rev:n});if(`kind`in r)return r.kind===`absent`?[]:[Wu];try{let e=JSON.parse(r.contents);return ju(e.workspaces)}catch{return[Wu]}},Yu=async(e,t,n)=>{let r=await qu(e,{dir:t.dir,path:Gu,rev:n});if(`kind`in r)return r.kind===`absent`?[]:[Wu];let{contents:i}=r,a=Fu(i.split(`
|
|
324
|
+
`));return Vu(i,a)?[Wu]:a},Xu=async(e,t,n)=>{let[r,i]=await Promise.all([Ju(e,t,n),Yu(e,t,n)]);return{npm:r,pnpm:i}},Zu=(e,t)=>{let n=0;for(let r of t)if(n<e.length&&e[n]===r)n+=1;else if(r.startsWith(`!`))return!1;return n===e.length},Qu=async(e,t)=>{if(!t.touched)return!1;let[n,r]=await Promise.all([Xu(e,t,t.from),Xu(e,t,t.to)]);return!Zu(n.npm,r.npm)||!Zu(n.pnpm,r.pnpm)},$u=e=>re(e)===`package.json`,ed=async(e,t,n)=>{let r=await e.run(`git`,[...n],{cwd:t});return r.exitCode===0?r.stdout:void 0},td=e=>e.split(`\0`).filter(e=>e.length>0&&$u(e)),nd=async(e,t)=>{let n=await ed(e,t.dir,[`diff`,`--name-only`,`-z`,`--no-renames`,`${t.from}..${t.to}`,`--`,`*package.json`,Gu]);return n===void 0?void 0:n.split(`\0`).filter(e=>e.length>0)},rd=async(e,t)=>{if(t.paths.length===0)return new Set;let n=await ed(e,t.dir,[`ls-tree`,`-r`,`-z`,`--name-only`,t.rev,`--`,...t.paths]);return n===void 0?void 0:new Set(td(n))},id=async(e,t)=>{let n=await ed(e,t.dir,[`show`,`${t.rev}:${t.path}`]);if(n!==void 0)try{let e=JSON.parse(n);return{name:Iu(e)}}catch{return}},ad=async(e,t,n)=>{let r=[];for(let i of n){let n=await id(e,{dir:t.dir,path:i,rev:t.rev});if(n===void 0)return;n.name!==void 0&&r.push(n.name)}return r},od={changedDirs:[],namesBefore:[]},sd=(e,t,n)=>Qu(e,{...t,touched:n.some(e=>e===`pnpm-workspace.yaml`||e===`package.json`)}),cd=e=>[...new Set(e.map(e=>ie(e)))].filter(e=>e!==`.`).toSorted(),ld=async(e,t,n)=>{let r=await rd(e,{dir:t.dir,paths:n,rev:t.from});if(r!==void 0)return ad(e,{dir:t.dir,rev:t.from},n.filter(e=>r.has(e)))},ud=async(e,t)=>{if(t.from===t.to)return od;let n=await nd(e,t);if(n===void 0||await sd(e,t,n))return;let r=n.filter(e=>$u(e));if(r.length>200)return;let i=await ld(e,t,r);return i===void 0?void 0:{changedDirs:cd(r),namesBefore:i}},dd=e=>{let t=e.stderr.trim()||e.stdout.trim()||`exit code ${e.exitCode}`,n=t.split(`
|
|
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
|
+
`),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
|
+
`).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(`
|
|
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}
|
|
332
332
|
- a short flag is a single dash and a single character
|
|
333
333
|
- either use a single dash and a single character (for a short flag)
|
|
334
334
|
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`):r.test(t)?Error(`${n}
|
|
335
335
|
- too many short flags`):i.test(t)?Error(`${n}
|
|
336
336
|
- too many long flags`):Error(`${n}
|
|
337
|
-
- unrecognised flag format`)}if(t===void 0&&n===void 0)throw Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:n}}function
|
|
338
|
-
- specify the name in Command constructor or using .name()`);return t||={},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new
|
|
339
|
-
Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return this._exitCallback=e||(e=>{if(e.code!==`commander.executeSubCommandAsync`)throw e}),this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new
|
|
340
|
-
- already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),n=t(e).find(e=>this._findCommand(e));if(n){let r=t(this._findCommand(n)).join(`|`),i=t(e).join(`|`);throw Error(`cannot add command '${i}' as already have command '${r}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,`default`);let r=(t,r,i)=>{t==null&&e.presetArg!==void 0&&(t=e.presetArg);let a=this.getOptionValue(n);t!==null&&e.parseArg?t=this._callParseArg(e,t,a,r):t!==null&&e.variadic&&(t=e._collectValue(t,a)),t??=e.negate?!1:e.isBoolean()||e.optional?!0:``,this.setOptionValueWithSource(n,t,i)};return this.on(`option:`+t,t=>{let n=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,n,`cli`)}),e.envVar&&this.on(`optionEnv:`+t,t=>{let n=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,n,`env`)}),this}_optionEx(e,t,n,r,i){if(typeof t==`object`&&t instanceof
|
|
337
|
+
- unrecognised flag format`)}if(t===void 0&&n===void 0)throw Error(`option creation failed due to no flags found in '${e}'.`);return{shortFlag:t,longFlag:n}}function Tv(e,t){if(Math.abs(e.length-t.length)>3)return Math.max(e.length,t.length);let n=[];for(let t=0;t<=e.length;t++)n[t]=[t];for(let e=0;e<=t.length;e++)n[0][e]=e;for(let r=1;r<=t.length;r++)for(let i=1;i<=e.length;i++){let a;a=e[i-1]===t[r-1]?0:1,n[i][r]=Math.min(n[i-1][r]+1,n[i][r-1]+1,n[i-1][r-1]+a),i>1&&r>1&&e[i-1]===t[r-2]&&e[i-2]===t[r-1]&&(n[i][r]=Math.min(n[i][r],n[i-2][r-2]+1))}return n[e.length][t.length]}function Ev(e,t){if(!t||t.length===0)return``;t=Array.from(new Set(t));let n=e.startsWith(`--`);n&&(e=e.slice(2),t=t.map(e=>e.slice(2)));let r=[],i=3;return t.forEach(t=>{if(t.length<=1)return;let n=Tv(e,t),a=Math.max(e.length,t.length);(a-n)/a>.4&&(n<i?(i=n,r=[t]):n===i&&r.push(t))}),r.sort((e,t)=>e.localeCompare(t)),n&&(r=r.map(e=>`--${e}`)),r.length>1?`\n(Did you mean one of ${r.join(`, `)}?)`:r.length===1?`\n(Did you mean ${r[0]}?)`:``}var Dv=class e extends _e{constructor(e){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=e||``,this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description=``,this._summary=``,this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:e=>h.stdout.write(e),writeErr:e=>h.stderr.write(e),outputError:(e,t)=>t(e),getOutHelpWidth:()=>h.stdout.isTTY?h.stdout.columns:void 0,getErrHelpWidth:()=>h.stderr.isTTY?h.stderr.columns:void 0,getOutHasColors:()=>kv()??(h.stdout.isTTY&&h.stdout.hasColors?.()),getErrHasColors:()=>kv()??(h.stderr.isTTY&&h.stderr.hasColors?.()),stripColor:e=>xe(e)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let r=t,i=n;typeof r==`object`&&r&&(i=r,r=null),i||={};let[,a,o]=e.match(/([^ ]+) *(.*)/),s=this.createCommand(a);return r&&(s.description(r),s._executableHandler=!0),i.isDefault&&(this._defaultCommandName=s._name),s._hidden=!!(i.noHelp||i.hidden),s._executableFile=i.executableFile||null,o&&s.arguments(o),this._registerCommand(s),s.parent=this,s.copyInheritedSettings(this),r?this:s}createCommand(t){return new e(t)}createHelp(){return Object.assign(new bv,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!=`string`&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw Error(`Command passed to .addCommand() must have a name
|
|
338
|
+
- specify the name in Command constructor or using .name()`);return t||={},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new vv(e,t)}argument(e,t,n,r){let i=this.createArgument(e,t);return typeof n==`function`?i.default(r).argParser(n):i.default(n),this.addArgument(i),this}arguments(e){return e.trim().split(/ +/).forEach(e=>{this.argument(e)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e==`boolean`)return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let[,n,r]=(e??`help [command]`).match(/([^ ]+) *(.*)/),i=t??`display help for command`,a=this.createCommand(n);return a.helpOption(!1),r&&a.arguments(r),i&&a.description(i),this._addImplicitHelpCommand=!0,this._helpCommand=a,(e||t)&&this._initCommandGroup(a),this}addHelpCommand(e,t){return typeof e==`object`?(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this):(this.helpCommand(e,t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand(`help`))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=[`preSubcommand`,`preAction`,`postAction`];if(!n.includes(e))throw Error(`Unexpected value for event passed to hook : '${e}'.
|
|
339
|
+
Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return this._exitCallback=e||(e=>{if(e.code!==`commander.executeSubCommandAsync`)throw e}),this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new gv(e,t,n)),h.exit(e)}action(e){let t=t=>{let n=this.registeredArguments.length,r=t.slice(0,n);return r[n]=this._storeOptionsAsProperties?this:this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new xv(e,t)}_callParseArg(e,t,n,r){try{return e.parseArg(t,n)}catch(e){if(e.code===`commander.invalidArgument`){let t=`${r} ${e.message}`;this.error(t,{exitCode:e.exitCode,code:e.code})}throw e}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
|
|
340
|
+
- already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=e=>[e.name()].concat(e.aliases()),n=t(e).find(e=>this._findCommand(e));if(n){let r=t(this._findCommand(n)).join(`|`),i=t(e).join(`|`);throw Error(`cannot add command '${i}' as already have command '${r}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,`default`);let r=(t,r,i)=>{t==null&&e.presetArg!==void 0&&(t=e.presetArg);let a=this.getOptionValue(n);t!==null&&e.parseArg?t=this._callParseArg(e,t,a,r):t!==null&&e.variadic&&(t=e._collectValue(t,a)),t??=e.negate?!1:e.isBoolean()||e.optional?!0:``,this.setOptionValueWithSource(n,t,i)};return this.on(`option:`+t,t=>{let n=`error: option '${e.flags}' argument '${t}' is invalid.`;r(t,n,`cli`)}),e.envVar&&this.on(`optionEnv:`+t,t=>{let n=`error: option '${e.flags}' value '${t}' from env '${e.envVar}' is invalid.`;r(t,n,`env`)}),this}_optionEx(e,t,n,r,i){if(typeof t==`object`&&t instanceof xv)throw Error(`To add an Option object use addOption() instead of option() or requiredOption()`);let a=this.createOption(t,n);if(a.makeOptionMandatory(!!e.mandatory),typeof r==`function`)a.default(i).argParser(r);else if(r instanceof RegExp){let e=r;r=(t,n)=>{let r=e.exec(t);return r?r[0]:n},a.default(i).argParser(r)}else a.default(r);return this.addOption(a)}option(e,t,n,r){return this._optionEx({},e,t,n,r)}requiredOption(e,t,n,r){return this._optionEx({mandatory:!0},e,t,n,r)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(e=!0){if(this.options.length)throw Error(`call .storeOptionsAsProperties() before adding options`);if(Object.keys(this._optionValues).length)throw Error(`call .storeOptionsAsProperties() before setting option values`);return this._storeOptionsAsProperties=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw Error(`first parameter to parse must be array or undefined`);if(t||={},e===void 0&&t.from===void 0){h.versions?.electron&&(t.from=`electron`);let e=h.execArgv??[];(e.includes(`-e`)||e.includes(`--eval`)||e.includes(`-p`)||e.includes(`--print`))&&(t.from=`eval`)}e===void 0&&(e=h.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case`node`:this._scriptPath=e[1],n=e.slice(2);break;case`electron`:h.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case`user`:n=e.slice(0);break;case`eval`:n=e.slice(1);break;default:throw Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||`program`,n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,`--`);this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,`default`)}),this.saveStateBeforeParse()):this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
341
341
|
- either make a new Command for each call to parse, or stop storing options as properties`);this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(e,t,n){if(fe.existsSync(e))return;let r=`'${e}' does not exist
|
|
342
342
|
- if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
343
343
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
344
|
-
- ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=ne.resolve(e,t);if(fe.existsSync(r))return r;if(n.includes(ne.extname(t)))return;let i=n.find(e=>fe.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=fe.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=ne.resolve(ne.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=ne.basename(this._scriptPath,ne.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(ne.extname(i)),s;h.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=
|
|
345
|
-
`),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in h.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,h.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new
|
|
346
|
-
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function
|
|
347
|
-
refs add ${
|
|
344
|
+
- ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function r(e,t){let r=ne.resolve(e,t);if(fe.existsSync(r))return r;if(n.includes(ne.extname(t)))return;let i=n.find(e=>fe.existsSync(`${r}${e}`));if(i)return`${r}${i}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=e._executableFile||`${this._name}-${e._name}`,a=this._executableDir||``;if(this._scriptPath){let e;try{e=fe.realpathSync(this._scriptPath)}catch{e=this._scriptPath}a=ne.resolve(ne.dirname(e),a)}if(a){let t=r(a,i);if(!t&&!e._executableFile&&this._scriptPath){let n=ne.basename(this._scriptPath,ne.extname(this._scriptPath));n!==this._name&&(t=r(a,`${n}-${e._name}`))}i=t||i}let o=n.includes(ne.extname(i)),s;h.platform===`win32`?(this._checkForMissingExecutable(i,a,e._name),t.unshift(i),t=Ov(h.execArgv).concat(t),s=ye.spawn(h.execPath,t,{stdio:`inherit`})):o?(t.unshift(i),t=Ov(h.execArgv).concat(t),s=ye.spawn(h.argv[0],t,{stdio:`inherit`})):s=ye.spawn(i,t,{stdio:`inherit`}),s.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(e=>{h.on(e,()=>{s.killed===!1&&s.exitCode===null&&s.kill(e)})});let c=this._exitCallback;s.on(`close`,e=>{e??=1,c?c(new gv(e,`commander.executeSubCommandAsync`,`(close)`)):h.exit(e)}),s.on(`error`,t=>{if(t.code===`ENOENT`)this._checkForMissingExecutable(i,a,e._name);else if(t.code===`EACCES`)throw Error(`'${i}' not executable`);if(!c)h.exit(1);else{let e=new gv(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=t,c(e)}}),this.runningCommand=s}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)!==void 0&&this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l))){this.emit(`option:${o.name()}`,l);continue}if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
345
|
+
`),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in h.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,h.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new Sv(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=Ev(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=e.length,i=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${r}: ${e.join(`, `)}.`;this.error(i,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=Ev(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>yv(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=ne.basename(e,ne.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(h.exitCode??0);t===0&&e&&typeof e!=`function`&&e.error&&(t=1),this._exit(t,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
|
|
346
|
+
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function Ov(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function kv(){if(h.env.NO_COLOR||h.env.FORCE_COLOR===`0`||h.env.FORCE_COLOR===`false`)return!1;if(h.env.FORCE_COLOR||h.env.CLICOLOR_FORCE!==void 0)return!0}new Dv;const Av=[],jv=e=>Array.isArray(e)?e:[e],Mv=e=>e===void 0?Av:[e],Nv=e=>e instanceof Error?e.message:String(e),X=e=>{let t=e.optsWithGlobals();return{json:t.json===!0,verbose:t.verbose===!0}},Z=(e,t,n,r,i)=>{if(t.json){let t={data:r,ok:!0,warnings:i??Av};e.out(JSON.stringify(t));return}for(let t of jv(n))e.out(t);for(let t of i??Av)e.errLine(`refs: warning: ${t}`)},Pv=(e,t,n)=>{if(t.json){let t={error:{code:n.code,message:n.message,...n.reason===void 0?{}:{reason:n.reason}},ok:!1};e.out(JSON.stringify(t));return}e.errLine(`refs: ${n.message}`)},Fv=(e,t)=>{e.errLine(`refs: ${t}`)},Q=(e,t,n)=>async()=>{try{await n()}catch(n){let r=Te(n,{verbose:t.verbose});Pv(e,t,r),process.exitCode=r.exitCode}},Iv=e=>`'${e.replaceAll(`'`,String.raw`'\''`)}'`,Lv=(e,t)=>{let n=t.some(e=>e.startsWith(`-`))?[`--`]:[];return[`refs edit`,...e,...n,...t.map(e=>Iv(e))].join(` `)},Rv=e=>`rm -rf -- ${Iv(e)}`,zv=e=>`rmdir -- ${Iv(e)}`,Bv=e=>({path:e.path}),Vv=e=>e.filter(e=>e.path!==`.`),Hv=e=>e.find(e=>e.path===`.`),Uv=e=>{let t=Hv(e);return t===void 0?{}:{[t.name]:Bv(t)}},Wv=(e,t,n)=>{let r=Vv(e),i=Uv(e);return r.length>0?{...i,...Object.fromEntries(r.map(e=>[e.name,Bv(e)]))}:n===void 0?i:{...i,[n]:{path:t??`.`}}},Gv=e=>{let t=e.description??``;return e.tag_format===void 0?{description:t,path:e.path}:{description:t,path:e.path,tag_format:e.tag_format}},Kv=(e,t)=>{let n=Object.entries(e);if(n.length!==0)return Object.fromEntries(n.map(([e,n])=>[e,Gv(e===t.rootPackageName?Jv(n,t.refDescription):n)]))},qv=(e,t)=>{let[n]=Object.keys(Uv(e));if(n!==void 0)return t[n]?.path===`.`?n:void 0},Jv=(e,t)=>({...e,description:t}),Yv=(e,t)=>Object.keys(e).filter(e=>e!==t).toSorted(),Xv=(e,t,n)=>{if(Yv(e,n).length!==0)throw y(`refs add --description cannot describe a package: it has one description, about the repository. Run the two-phase flow instead:
|
|
347
|
+
refs add ${Iv(t)} --dry-run --json > proposal.json\nFill in the ref's own description, and one written from its own source for each package below, then:
|
|
348
348
|
refs add --proposal proposal.json
|
|
349
|
-
packages to describe: ${Object.keys(e).toSorted().join(`, `)}`)},
|
|
350
|
-
`)},Hy=e=>{let t=Og.safeParse(e);if(!t.success)throw y(Vy(t.error));return t.data},Uy=async(e,t)=>{let n=await jy(e,t);return Hy(Fy(My(n)))},Wy=(e,t)=>[`refs add: dry-run proposal ready for '${e}' (checkout: ${t})`,`next: review the proposal, then run refs add --proposal <file> to finalize`],Gy=e=>[...Sv(e.warning),...Sv(e.detectionWarning)],Ky=async(e,t)=>{let n=await Ey(e,t),r=z(e.env);await Dy(r,n.proposal.key,n.effectiveCloneMode);let i=Gy(n);return{data:n.proposal,human:Wy(n.proposal.key,n.dest),warnings:i}},qy=e=>[`refs add: '${e}' added to config`],Jy=e=>{let t={default_branch:e.default_branch,description:e.description,key:e.key,url:e.url};e.tag_format_candidate!==null&&(t.tag_format=e.tag_format_candidate);let n=Bv(e.packages);return n!==void 0&&(t.packages=n),t},Yy=async(e,t)=>{let n=await Uy(e,t),r=z(e.env),i=B(r,n.key);if(!H(i))throw _(`no checkout found at ${i} — run: refs add <source> --dry-run first`);let a=Jy(n),{entry:o,key:s}=await Ay(e,{dest:i,home:r,ref:a});return{data:{entry:o,key:s},human:qy(s),warnings:[]}},Xy=(e,t,n)=>{zv(e.proposal.packages,n,e.rootPackageName);let r={default_branch:e.proposal.default_branch,description:t,key:e.proposal.key,url:e.proposal.url};e.proposal.tag_format_candidate!==null&&(r.tag_format=e.proposal.tag_format_candidate);let i=Fv(e.proposal.packages,{refDescription:t,...e.rootPackageName===void 0?{}:{rootPackageName:e.rootPackageName}});return i!==void 0&&(r.packages=i),r},Zy=async(e,t,n)=>{let r=await Ey(e,t),i=z(e.env);await Dy(i,r.proposal.key,r.effectiveCloneMode);let a=Xy(r,n,t),o={dest:r.dest,home:i,ref:a};r.effectiveCloneMode!==void 0&&(o.effectiveCloneMode=r.effectiveCloneMode);let{entry:s,key:c}=await Ay(e,o);return{data:{entry:s,key:c},human:qy(c),warnings:Gy(r)}},Qy=e=>{let t=[e.dryRun,e.proposal!==void 0,e.description!==void 0].filter(Boolean).length;if(t>1)throw v(`refs add: use only one of --dry-run, --proposal, or --description`);if(t===0)throw v(`refs add needs --dry-run, --proposal, or --description`)},$y=e=>{if(e===void 0||e===``)throw v(`refs add requires <source> (a git url or npm:<package>)`);return e},eb=(e,t)=>(Qy(t),t.proposal===void 0?t.description===void 0?Ky(e,$y(t.source)):Zy(e,$y(t.source),t.description):Yy(e,t.proposal)),tb=(e,t)=>{let n={dryRun:t.dryRun===!0};return e!==void 0&&(n.source=e),t.proposal!==void 0&&(n.proposal=t.proposal),t.description!==void 0&&(n.description=t.description),n},nb=(e,t)=>{e.command(`add`).description(`Add a git reference in two phases: propose (--dry-run), then finalize (--proposal).`).argument(`[source]`,`git url or npm:<package> (omit when finalizing with --proposal)`).option(`--dry-run`,`resolve and clone the source, writing a reviewable proposal`).option(`--proposal <file>`,`finalize from a completed proposal JSON file (- for stdin)`).option(`--description <text>`,`one-shot: dry-run then finalize immediately with this description`).action((e,n,r)=>{let i=Y(r);return Z(t,i,async()=>{let r=await eb(t,tb(e,n));X(t,i,r.human,r.data,r.warnings)})()})},rb=async e=>{let t=await e.runner.run(`git`,[`--version`]);return t.exitCode===0?{detail:t.stdout.trim(),name:`git`,status:`ok`}:{detail:t.stderr.trim()||`git --version exited with code ${t.exitCode}`,name:`git`,status:`fail`}},ib=/^v(?<major>\d+)\.(?<minor>\d+)/u,ab=e=>{let t=ib.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(n!==void 0&&r!==void 0)return{major:Number(n),minor:Number(r)}},ob=e=>e===void 0?!1:e.major>24||e.major===24&&e.minor>=2,sb=e=>{let{nodeVersion:t}=e;return ob(ab(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.2`,name:`node`,status:`fail`}},cb=()=>bl.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),lb=async e=>{try{return{config:await V(e)}}catch(e){return{config:cb(),errorMessage:Cv(e)}}},ub=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},db={ci:`update check is off in CI — set REFS_UPDATE_CHECK=1 to run it here anyway`,config:`update check is off ([updates].check = false in config.toml)`,env:`update check is off (REFS_UPDATE_CHECK=0)`},fb=(e,t,n)=>{if(qg(e,t)){let r=n?` (npm was unreachable just now; this was its last answer)`:``;return{detail:`${Jg(e,t)}${r}`,name:`cli-update`,status:`warn`}}return n?{detail:`could not reach npm to check; its last answer was ${t}, which this CLI (${e}) already has`,name:`cli-update`,status:`warn`}:{detail:`this CLI (${e}) is npm's latest published release`,name:`cli-update`,status:`ok`}},pb=async(e,t)=>{let n=Qg({env:e.env,updates:t.updates});if(n!==`on`)return{detail:db[n],name:`cli-update`,status:`ok`};let{latest:r,stale:i}=await Kg({fetch:e.fetcher,home:z(e.env),nowMs:Date.now()});return r===void 0?{detail:`could not reach npm to learn the latest published version — not a fault of your setup, and nothing else depends on it`,name:`cli-update`,status:`warn`}:fb(e.cliVersion,r,i)},mb=(e,t)=>Object.keys(t.refs).map(e=>il.parse(e)).map(t=>({dest:B(e,t),key:t})).filter(e=>H(e.dest)),hb=[`pre-commit`,`pre-push`],gb=async(t,r)=>{try{return await e(m(t.hooksDir,r),n.X_OK),!0}catch{return!1}},_b=async e=>{let t=await Promise.all(hb.map(t=>gb(e,t)));return hb.filter((e,n)=>!t[n])},vb=async(e,t,n)=>{let r=await e.runner.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:n});return r.exitCode===0&&r.stdout.trim()===t.hooksDir},yb=e=>e.missingHooks.length>0?{detail:`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`,name:`hooks-guard`,status:`fail`}:e.badKeys.length>0?{detail:`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`,name:`hooks-guard`,status:`fail`}:{detail:`${hb.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`},bb=async(e,t,n)=>{let r=mb(t,n),[i,a]=await Promise.all([_b(t),Promise.all(r.map(n=>vb(e,t,n.dest)))]),o=r.filter((e,t)=>!a[t]).map(e=>e.key);return yb({badKeys:o,checkoutCount:r.length,missingHooks:i})},xb=async(e,t)=>{let n=await e.runner.run(`git`,[`status`,`--porcelain`],{cwd:t.dest});return n.exitCode===0?{broken:!1,detail:``,dirty:n.stdout.trim()!==``,key:t.key}:{broken:!0,detail:n.stderr.trim(),dirty:!1,key:t.key}},Sb=e=>{let t=e.filter(e=>e.broken);if(t.length>0)return{detail:t.map(e=>`${e.key}: git status failed — ${e.detail}`).join(`; `),name:`dirty-checkouts`,status:`fail`};let n=e.filter(e=>e.dirty).map(e=>e.key);return n.length===0?{detail:`no local changes in any checkout`,name:`dirty-checkouts`,status:`ok`}:{detail:`local changes will be discarded on next sync: ${n.join(`, `)}`,name:`dirty-checkouts`,status:`warn`}},Cb=async(e,t,n)=>{let r=mb(t,n),i=await Promise.all(r.map(t=>xb(e,t)));return Sb(i)},wb=async e=>{try{return await Pg(e)}catch{return Ag.parse({})}},Tb=async e=>{try{return(await c(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(R(e))return[];throw e}},Eb=async(e,t)=>{if(H(e))return[[...t]];let n=await Tb(e);return(await Promise.all(n.map(n=>Eb(m(e,n),[...t,n])))).flat()},Db=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r!==void 0&&n-Date.parse(r)<864e5},Ob=(e,t,n)=>Db(t,e.key,n)?`${e.key}: pending add`:`${e.key}: orphan — remove with: ${Dv(e.dest)}`,kb=(e,t)=>({dest:m(e.sourcesDir,...t),key:t.join(`/`)}),Ab=async(e,t,n)=>{let r=(await Eb(e.sourcesDir,[])).map(t=>kb(e,t)).filter(e=>!Object.hasOwn(t.refs,e.key));if(r.length===0)return{detail:`no orphaned checkouts under sources/`,name:`orphans`,status:`ok`};let i=Date.now();return{detail:r.map(e=>Ob(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},jb=e=>e!==`unmaterialized`&&e!==`verified`,Mb=new Set([`ambiguous`,`missing`,`relocated`,`unregistered`]),Nb=(e,t={})=>{let{declined:n=[],discoveryIncomplete:r}=t,i=n.length===0?{}:{declined:[...n]},[a]=e;return a===void 0?r===void 0?{...i,status:`ok`}:{...i,discovery_incomplete:r,status:`unknown`}:{...i,...r===void 0?{}:{discovery_incomplete:r},packages:[...e],status:e.some(e=>Mb.has(e.status))?`drift`:`unknown`}},Pb=`(unknown)`,Fb=e=>ul.safeParse(e.path).success,Ib=(e,t)=>{let n=`${e.name}: declared in this checkout but not registered — it cannot be resolved by name until it is`;if(e.path===void 0)return`${n}. Declared at several paths (${(e.candidates??[]).join(`, `)}) — pick one`;if(!Fb(e))return`${n}. Its path is one the configuration cannot hold, so there is no command for it — report it and leave it unregistered`;let r=Ev([`--package=${Q(e.name)}`,`--decline`,`--path=${Q(e.path)}`],[t]);return Kc(e.name)?`${n}. To register it: ${Ev([`--package=${Q(e.name)}`,`--create`,`--path=${Q(e.path)}`,`--description="<what it is>"`],[t])}. If it should not be: ${r}`:`${n}. Its name is one the packages table cannot hold, so it cannot be registered — if that is the answer, record it: ${r}`},Lb=(e,t,n)=>{let r=`${e.name}: moved to ${e.path??Pb} — update the entry's path (${n})`,i=Ev([`--package=${Q(e.name)}`],[t,`path`,e.path??``]);return ul.safeParse(e.path).success?`${r}. To fix it: ${i}`:r},Rb=(e,t)=>{let n=`configured: ${e.configured_path??Pb}`;if(e.status===`relocated`)return Lb(e,t,n);if(e.status===`missing`){let r=Ev([`--package=${Q(e.name)}`,`--remove`],[t]);return`${e.name}: gone from this repo's workspaces (${n}) — repoint the entry if it moved out of them, or unregister it: ${r}`}if(e.status===`ambiguous`){let t=(e.candidates??[]).join(`, `);return`${e.name}: declared at several paths (${t}) — point the entry at one (${n})`}return`${e.name}: could not be checked — ${e.reason??`(no reason given)`} (${n})`},zb=(e,t)=>e.status===`unregistered`?Ib(e,t):Rb(e,t),Bb=e=>`could not check for unregistered packages — ${e}`,Vb=e=>`…and ${e} more finding(s) — act on the ones above (register, repoint or decline) and run the check again to see the rest`,Hb=e=>{let t=e.length-10;return t<=0?[...e]:[...e.slice(0,10),Vb(t)]},Ub=(e,t)=>{if(e.reason!==void 0)return[`could not be checked — ${e.reason}`];let n=Hb((e.packages??[]).map(e=>zb(e,t)));return e.discovery_incomplete===void 0?n:[...n,Bb(e.discovery_incomplete)]},Wb=e=>{let t;return()=>(t??=tv(e),t)},Gb=async(e,t,n)=>{let r=await f_(e);if(r===void 0||t.some(e=>e.packageName===r.name))return{issues:[]};let i=await n();if(!Kh(i))return{incomplete:sy(i),issues:[]};let a=ng(i.packages,r.name);return a.kind===`ambiguous`?{issues:[{candidates:a.paths,name:r.name,status:`unregistered`}]}:{issues:a.kind===`found`?[{name:r.name,path:a.path,status:`unregistered`}]:[]}},Kb=e=>{let t=new Map;for(let n of e)t.set(n.name,[...t.get(n.name)??[],n.path]);return t},qb=(e,t)=>{let n=new Set(e.changedDirs),r=t.filter(e=>!n.has(e.path)).map(e=>e.name);return new Set([...e.namesBefore,...r])},Jb=(e,t)=>t.length===1&&t[0]!==void 0?{name:e,path:t[0],status:`unregistered`}:{candidates:[...t],name:e,status:`unregistered`},Yb=async(e,t,n)=>{if(t.kind===`arrivals`&&t.changedDirs.length===0)return{issues:[]};let r=await n();if(!Kh(r))return{incomplete:sy(r),issues:[]};let i=new Set(e.map(e=>e.packageName)),a=r.packages.filter(e=>e.path!==`.`),o=t.kind===`all`?void 0:qb(t,a);return{issues:[...Kb(a)].filter(([e])=>!i.has(e)).filter(([e])=>o===void 0||!o.has(e)).map(([e,t])=>Jb(e,t)).toSorted((e,t)=>e.name.localeCompare(t.name))}},Xb=(e,t)=>{if(t.length===0)return{issues:[...e],suppressed:[]};let n=(e,n)=>t.some(t=>t.name===e&&t.path===n),r=[];return{issues:e.flatMap(e=>{if(e.status!==`unregistered`)return[e];let t=e.path===void 0?e.candidates??[]:[e.path],i=t.filter(t=>!n(e.name,t)),a=t.filter(t=>n(e.name,t));return r.push(...a.map(t=>({name:e.name,path:t}))),i.length===0?[]:[Jb(e.name,i)]}),suppressed:r}},Zb=(e,t)=>({path:e.configuredPath,reason:t,status:`unverifiable`}),Qb=(e,t)=>qh(t)?{configuredPath:e.configuredPath,path:null,status:`missing`}:Zb(e,`this repo declares no workspaces, so there was nowhere to search`),$b=(e,t)=>t===e.configuredPath,ex=e=>e.packages.filter(e=>e.path!==`.`),tx=(e,t)=>{let n=ng(ex(t),e.packageName);return n.kind===`ambiguous`?{candidates:n.paths,configuredPath:e.configuredPath,path:null,status:`ambiguous`}:Kh(t)?n.kind===`absent`?Qb(e,t):$b(e,n.path)?Zb(e,`the checkout changed while it was being inspected`):{configuredPath:e.configuredPath,path:n.path,status:`relocated`}:Zb(e,n.kind===`found`?`workspace detection was incomplete, so the new location is not confirmed unique`:`workspace detection was incomplete`)},nx=e=>{let t=new Map(Object.entries(e??{}));return[...t.keys()].toSorted().flatMap(e=>{let n=t.get(e);return n===void 0?[]:[{configuredPath:n.path,packageName:e}]})},rx=async(e,t)=>{let n=await $h(e,t.configuredPath,t.packageName);if(n.kind===`match`)return{path:t.configuredPath,status:`verified`};if(n.kind===`unreadable`)return{path:t.configuredPath,reason:n.reason,status:`unverifiable`}},ix=e=>e.flatMap(e=>e.settled===void 0?[]:[{outcome:e.settled,query:e.query}]),ax=async(e,t,n)=>{let r=await Promise.all(t.map(async t=>({query:t,settled:await rx(e,t)})));if(r.every(e=>e.settled!==void 0))return ix(r);let i=await n();return r.map(e=>({outcome:e.settled??tx(e.query,i),query:e.query}))},ox=e=>{let{outcome:t,query:n}=e;return jb(t.status)?[{...t.candidates===void 0?{}:{candidates:t.candidates},configured_path:n.configuredPath,name:n.packageName,...t.status===`relocated`&&t.path!==null?{path:t.path}:{},...t.reason===void 0?{}:{reason:t.reason},status:t.status}]:[]},sx=(e,t)=>{let n=new Set(e.map(e=>e.name));return[...e,...t.filter(e=>!n.has(e.name))]},cx=async(e,t,n)=>{let r=nx(t.packages),[i]=r;if(i===void 0)return{status:`ok`};let a=Wb(e);try{let[i,o,s]=await Promise.all([ax(e,r,a),Gb(e,r,a),Yb(r,n,a)]),c=Xb([...i.flatMap(e=>ox(e)),...sx(o.issues,s.issues)],t.declined_packages??[]);return Nb(c.issues,{declined:c.suppressed,...(s.incomplete??o.incomplete)===void 0?{}:{discoveryIncomplete:s.incomplete??o.incomplete}})}catch(e){return{reason:Cv(e),status:`unknown`}}},lx=async(e,t,n)=>{try{return await W(e,Kv(n.key),()=>cx(n.dest,t.refs[n.key]??{},{kind:`all`}),{timeoutMs:100})}catch(e){if(e instanceof g&&e.code===`conflict`)return{reason:`another refs process is holding this ref`,status:`unknown`};throw e}},ux=`config-drift`,dx=e=>e===0?``:` (${e} declined package(s) not reported)`,fx=(e,t)=>{let{declined:n,findings:r,lines:i}=e,[a]=i;return a===void 0?{detail:`every configured package path resolves in ${t} checkout(s)${dx(n)}`,name:ux,status:`ok`}:{detail:`${i.join(`; `)}${dx(n)}`,findings:r,name:ux,status:`warn`}},px=async(e,t,n)=>{let[r,...i]=n;if(r===void 0)return{declined:0,findings:[],lines:[]};let a=await lx(e,t,r),o=await px(e,t,i),s=a.packages??[];return{declined:(a.declined??[]).length+o.declined,findings:s.length===0?o.findings:[{key:r.key,packages:s},...o.findings],lines:[...Ub(a,r.key).map(e=>`${r.key}: ${e}`),...o.lines]}},mx=async(e,t)=>{let n=mb(e,t);return fx(await px(e,t,n),n.length)},hx=e=>{let{diagnosis:t}=e;return e.kind===`claim`||!e.isDirectory||t.pidState===`definitely-dead`||t.stale||t.meta===`malformed`||t.meta===`unreadable`||t.policy===`unknown`?!1:t.ageMs===void 0||t.ageMs>=0},gx=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return r===`unknown`?`, state could not be read`:t===void 0||n===void 0?``:t<0?`, recorded time is in the future — check the system clock`:`, ${Cp(t)} into a ${Cp(n)} window`},_x=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} present`,vx=(e,t)=>{let n=m(e.locksDir,sp,t.name),r=t.diagnosis.ageMs===void 0?``:` for ${Cp(t.diagnosis.ageMs)}`;return`steal claim on ${t.name}: present${r}. Stealing this lock is blocked while it is here. A reclaim in progress clears it within a moment; if it stays, ${yx}: ${Ov(n)}`},yx=`stop every refs process using this home — including suspended ones — and then run`,bx=(e,t)=>{let{diagnosis:n}=t;if(tp(n))return`, reclaimable now`;if(!n.stale&&t.isDirectory)return``;let r=m(e.locksDir,t.name);return`, not automatically reclaimable — if it is genuinely abandoned, ${yx}: ${Dv(r)}`},xx=(e,t)=>{let{diagnosis:n}=t,r=t.isDirectory?``:`not a directory, `,i=bx(e,t);return`${t.name}: ${r}${_x(n)}${gx(n)}${i}`},Sx=async e=>{let t=await Sp(e),[n]=t;return n===void 0?{detail:`no locks held`,name:`locks`,status:`ok`}:{detail:t.map(t=>t.kind===`claim`?vx(e,t):xx(e,t)).join(`; `),name:`locks`,status:t.every(e=>hx(e))?`ok`:`warn`}},Cx=[`.agents`,`skills`,`refs`,`SKILL.md`],wx=[`skills`,`refs`,`SKILL.md`],Tx=[`.claude`,`skills`,`refs`,`SKILL.md`],Ex=`npx skills add kaisers-io/refs`,Dx=`npm i -g @kaisers-io/refs@latest`,Ox=(e,t)=>e===void 0?void 0:{display:t,path:e},kx=e=>{let{dirName:t,env:n,home:r,overrideName:i}=e,a=n[i]?.trim();return a!==void 0&&a.length>0?{display:a,path:a}:Ox(r===void 0?void 0:m(r,t),`~/${t}`)},Ax=e=>{let t=e.homedir.length>0?e.homedir:void 0;return[{label:`shared ~/.agents`,root:Ox(t,`~/.agents`),segments:Cx},{label:`Claude Code`,root:kx({dirName:`.claude`,env:e.env,home:t,overrideName:`CLAUDE_CONFIG_DIR`}),segments:wx},{label:`Codex`,root:kx({dirName:`.codex`,env:e.env,home:t,overrideName:`CODEX_HOME`}),segments:wx},{label:`project ./.agents`,root:Ox(e.cwd,`./.agents`),segments:Cx},{label:`project ./.claude`,root:Ox(e.cwd,`./.claude`),segments:Tx}].flatMap(({label:e,root:t,segments:n})=>t===void 0?[]:[{display:t.display,label:e,path:m(t.path,...n)}])},jx=async(e,t)=>{try{let n=await l(e);return{label:t,realPath:n,source:await s(n,`utf8`)}}catch{return}},Mx=e=>{let t=new Map;for(let n of e)t.has(n.realPath)||t.set(n.realPath,n);return[...t.values()]},Nx=/^---\r?\n(?<body>[\s\S]*?)\r?\n---/u,Px=/^\s*cli_version:\s*["']?(?<version>[^"'\s]+)["']?\s*$/mu,Fx=e=>{let t=Nx.exec(e)?.groups?.body;if(t!==void 0)return Px.exec(t)?.groups?.version},Ix=(e,t)=>{if(e===t)return`match`;let n=zg(e,t);return n===void 0?`unknown`:n===0?`match`:n>0?`cli-older`:`skill-older`},Lx={"cli-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the CLI: ${Dx}`,match:(e,t)=>`the refs skill is installed and matches this CLI (${t})`,"skill-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the skill: ${Ex}`,unknown:(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — reinstall both: ${Dx} and ${Ex}`},Rx=e=>{let{cliVersion:t,label:n,skillVersion:r}=e;if(r===void 0)return{detail:`the refs skill (${n}) predates the version gate — update it: ${Ex}`,name:`skill`,status:`warn`};let i=Ix(r,t);return{detail:`${n}: ${Lx[i](r,t)}`,name:`skill`,status:i===`match`?`ok`:`warn`}},zx=e=>({detail:`refs skill not found in the locations this check knows about (${e.map(e=>e.display).join(`, `)}) — an install anywhere else is invisible here and still works; if it really is missing: ${Ex}`,name:`skill`,status:`warn`}),Bx=async e=>{let t=Ax(e),n=await Promise.all(t.map(e=>jx(e.path,e.label))),r=Mx(n.filter(e=>e!==void 0)).map(t=>Rx({cliVersion:e.cliVersion,label:t.label,skillVersion:Fx(t.source)}));return r.find(e=>e.status!==`ok`)??r[0]??zx(t)},Vx=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,Hx=e=>e===``?{}:{user:e},Ux=e=>e===``?{}:{port:e},Wx=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...Hx(t.username),...Ux(t.port)}:void 0}catch{return}},Gx=e=>{let t=Vx.exec(e),n=t?.groups?.host;return n===void 0?Wx(e):{host:n,user:t?.groups?.user??`git`}},Kx=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,qx=e=>e.user===void 0?Kx(e):`${e.user}@${Kx(e)}`,Jx=e=>{let t=Object.values(e.refs).map(e=>Gx(e.url)).filter(e=>e!==void 0),n=new Map;for(let e of t)n.set(qx(e),e);return[...n.values()].toSorted((e,t)=>qx(e).localeCompare(qx(t)))},Yx=/Permission denied/u,Xx=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],Zx=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,Qx=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=Zx(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},$x=async(e,t,n)=>{let r=qx(t),i=await e.runner.run(`ssh`,Qx(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:Yx.test(i.stderr)?{host:r,outcome:`denied`}:Xx.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},eS=(e,t)=>{let n=e.filter(e=>e.outcome===`timeout`).map(e=>e.host);if(n.length!==0)return{detail:`ssh probe timed out after ${t/1e3}s: ${n.join(`, `)}`,name:`ssh-auth`,status:`fail`}},tS=e=>{let t=e.filter(e=>e.outcome===`denied`).map(e=>e.host);if(t.length!==0)return{detail:`ssh permission denied for: ${t.join(`, `)}`,name:`ssh-auth`,status:`fail`}},nS=e=>{let t=e.filter(e=>e.outcome===`connection-warn`);if(t.length!==0)return{detail:`ssh connection issue, treated as warn: ${t.map(e=>`${e.host} (${e.detail??``})`).join(`; `)}`,name:`ssh-auth`,status:`warn`}},rS=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),iS=(e,t)=>eS(e,t)??tS(e)??nS(e)??rS(e),aS=async(e,t,n)=>{let r=Jx(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>$x(e,t,i)));return iS(a,i)},oS=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${Cv(t)}`,name:e.name,status:`fail`}}},sS=async e=>{let[t,...n]=e;if(t===void 0)return[];let r=await oS(t),i=await sS(n);return r===void 0?i:[r,...i]},cS=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>rb(n)},{name:`node`,run:()=>Promise.resolve(sb(n))},{name:`config`,run:()=>Promise.resolve(ub(t.errorMessage))},{name:`hooks-guard`,run:()=>bb(n,r,t.config)},{name:`dirty-checkouts`,run:()=>Cb(n,r,t.config)},{name:`config-drift`,run:()=>mx(r,t.config)},{name:`orphans`,run:()=>Ab(r,t.config,i)},{name:`locks`,run:()=>Sx(r)},{name:`skill`,run:()=>Bx(n)},{name:`cli-update`,run:()=>pb(n,t.config)},{name:`ssh-auth`,run:()=>aS(n,t.config)}]},lS=async e=>{let t=z(e.env),n=await lb(t),r=await wb(t);return sS(cS({configLoad:n,ctx:e,home:t,state:r}))},uS={fail:`FAIL`,ok:`OK`,warn:`WARN`},dS=e=>e.map(e=>`[${uS[e.status]}] ${e.name}: ${e.detail}`),fS=e=>e.some(e=>e.status===`fail`),pS=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, drift, locks, ssh).`).action((e,n)=>{let r=Y(n);return Z(t,r,async()=>{let e=await lS(t);X(t,r,dS(e),{checks:e}),fS(e)&&(process.exitCode=Se.UNEXPECTED)})()})},mS=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},hS=(e,t)=>{if(!H(e))throw _(`checkout for '${t}' is missing — run: refs sync ${t}`)},gS=(e,t,n)=>{let r=e.packages?.[n];if(r===void 0)throw _(`no package '${n}' registered on ref '${t}'`);return r},_S=`never`,vS=(e,t,n)=>e===void 0||n-Date.parse(e)>t,yS=(e,t)=>`${e} ${t}${e===1?``:`s`} ago`,bS=(e,t)=>{if(e===void 0)return _S;let n=t-Date.parse(e);if(Number.isNaN(n))return _S;let r=Math.floor(n/1e3);if(r<60)return`just now`;let i=Math.floor(r/60);if(i<60)return yS(i,`minute`);let a=Math.floor(i/60);if(a<24)return yS(a,`hour`);let o=Math.floor(a/24);return o<365?yS(o,`day`):yS(Math.floor(o/365),`year`)},xS=e=>{let t=bS(e.lastFetchedAt,e.now),n=[`synced: ${t}`];return e.stale&&t!==_S&&n.push(`status: stale`),e.missing&&n.push(`missing: checkout not found — run: refs sync`),n},SS=(e,t,n)=>{let r=e.state.refs[t],i=ol(jg(`sync_ttl`,n,e.settings)),a=Object.keys(n.packages??{}).toSorted();return{clone_mode:jg(`clone_mode`,n,e.settings),description:n.description,key:t,...r?.last_fetched_at===void 0?{}:{last_fetched_at:r.last_fetched_at},missing:!H(B(e.home,il.parse(t))),...e.includePackages?{packages:a}:{},packages_count:a.length,stale:vS(r?.last_fetched_at,i,e.now)}},CS=e=>{let t={home:e.home,includePackages:e.includePackages,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>SS(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},wS=async(e,t,n)=>{let r=z(e.env),i=await V(r),a=await Pg(r);return CS({config:i,home:r,includePackages:t,now:n,state:a})},TS=(e,t)=>[`ref: ${e.key}`,`description: ${e.description}`,...xS({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale})],ES=(e,t)=>e.length===0?[`no refs configured — run: refs add <source>`]:e.reduce((e,n,r)=>(r>0&&e.push(``),e.push(...TS(n,t)),e),[]),DS=e=>e.split(`/`),OS=(e,t)=>{let n=DS(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},kS=(e,t)=>{if(Object.hasOwn(e.refs,t))return il.parse(t);let n=DS(t),r=Object.keys(e.refs).filter(e=>OS(e,n)).toSorted(),[i]=r;if(i===void 0)throw _(`no ref matches '${t}'`);if(r.length>1)throw v(`'${t}' matches more than one ref: ${r.join(`, `)}`);return il.parse(i)},AS=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).option(`--packages`,`include each ref's package names in --json output (off by default)`).action((e,n)=>{let r=Y(n);return Z(t,r,async()=>{let n=Date.now(),i=await wS(t,e.packages===!0,n);X(t,r,ES(i,n),i)})()})},jS=e=>e===void 0?null:e,MS=(e,t)=>e.name===t.name&&e.path===t.path,NS=(e,t)=>{let n=(e.declined_packages??[]).filter(e=>!MS(e,t));if(n.length===0){let{declined_packages:t,...n}=e;return n}return{...e,declined_packages:n}},PS=(e,t)=>`package '${e.name}' at '${e.path}' is already declined on ref '${t}'`,FS=(e,t)=>`package '${e.name}' at '${e.path}' is not declined on ref '${t}' — nothing to undo`,IS=(e,t)=>`package '${e}' is registered on ref '${t}' — declining applies to packages the configuration does not have; unregister it first with --remove`,LS=(e,t,n)=>{if(Object.hasOwn(e.packages??{},t.name))throw y(IS(t.name,n));let r=e.declined_packages??[];if(r.some(e=>MS(e,t)))throw y(PS(t,n));return{...e,declined_packages:[...r,t]}},RS=e=>{if(e.declined)return LS(e.entry,e.record,e.key);if(!(e.entry.declined_packages??[]).some(t=>MS(t,e.record)))throw y(FS(e.record,e.key));return NS(e.entry,e.record)},zS=(e,t)=>{let n=z(e.env);return W(n,`home`,async()=>{let e=await V(n),r=kS(e,t.query),i=mS(e,r),a={name:t.packageName,path:t.path},o=RS({declined:t.declined,entry:i,key:r,record:a});return await fu(n,{...e,refs:{...e.refs,[r]:o}}),{declined:t.declined,field:`declined_packages`,key:r,new:t.declined?a:null,old:t.declined?null:a}})},BS=`packages`,VS=()=>Object.keys(hl.shape).toSorted().join(`, `),HS=e=>`unknown package field '${e}' — valid fields: ${VS()}`,US=e=>Object.hasOwn(hl.shape,e),WS=(e,t,n)=>{if(!US(t))throw v(HS(t));let r=e[t],i=hl.safeParse({...e,[t]:n});if(!i.success)throw y(T(i.error));return{field:t,newValue:i.data[t],oldValue:r,updated:i.data}},GS=async e=>{let t=gS(e.entry,e.key,e.packageName),n=WS(t,e.field,e.value),r={...e.entry,packages:{...e.entry.packages,[e.packageName]:n.updated}};return await fu(e.home,{...e.config,refs:{...e.config.refs,[e.key]:r}}),{field:n.field,key:e.key,new:jS(n.newValue),old:jS(n.oldValue)}},KS=(e,t)=>`package '${e}' is already registered on ref '${t}' — edit its fields instead`,qS=(e,t)=>{let n=z(e.env);return W(n,`home`,async()=>{let e=await V(n),r=kS(e,t.query),i=mS(e,r);if(Object.hasOwn(i.packages??{},t.packageName))throw y(KS(t.packageName,r));let a=gl.safeParse({...NS(i,{name:t.packageName,path:t.path}),packages:{...i.packages,[t.packageName]:{description:t.description,path:t.path}}});if(!a.success)throw y(T(a.error));return await fu(n,{...e,refs:{...e.refs,[r]:a.data}}),{created:!0,field:BS,key:r,new:{description:t.description,name:t.packageName,path:t.path},old:null}})},JS=(e,t)=>`package '${e}' is not registered on ref '${t}' — nothing to remove`,YS=(e,t)=>{let n=z(e.env);return W(n,`home`,async()=>{let e=await V(n),r=kS(e,t.query),i=mS(e,r),a=i.packages??{};if(!Object.hasOwn(a,t.packageName))throw y(JS(t.packageName,r));let{[t.packageName]:o,...s}=a,c=Object.keys(s).length===0?XS(i):{...i,packages:s};return await fu(n,{...e,refs:{...e.refs,[r]:c}}),{field:BS,key:r,new:null,old:{description:o?.description??``,name:t.packageName,path:o?.path??``},removed:!0}})},XS=e=>{let{packages:t,...n}=e;return n},ZS=e=>e.second===void 0&&e.value===void 0,QS=e=>{let{description:t,path:n}=e.create,{packageName:r}=e;if(r===void 0||t===void 0||n===void 0||!ZS(e))throw v(`--create registers a new package: it needs --package <name>, --path <path> and --description <text>, and takes no <field> <value> arguments`);return{description:t,packageName:r,path:n}},$S=e=>{let{packageName:t}=e;if(t===void 0||e.create.path!==void 0||!ZS(e)||e.create.description!==void 0)throw v(`--remove unregisters a package: it needs --package <name>, and takes no <field> <value> arguments, no --path and no --description`);return{packageName:t}},eC=e=>{let{packageName:t}=e,{path:n}=e.create;if(t===void 0||n===void 0||!ZS(e)||e.create.description!==void 0)throw v(`--decline and --undecline record a decision about one package at one path: each needs --package <name> and --path <path>, and takes no <field> <value> arguments and no --description`);return{packageName:t,path:n}},tC=[`create`,`remove`,`decline`,`undecline`],nC=e=>{let t=tC.filter(t=>e[t]===!0);if(t.length>1)throw v(`use one of --create, --remove, --decline or --undecline: they are different answers about the same package, and running two at once would guess which one was meant`);return t[0]},rC=(e,t,n)=>t===`create`?qS(e,{...QS(n),query:n.first}):t===`remove`?YS(e,{...$S(n),query:n.first}):zS(e,{...eC(n),declined:t===`decline`,query:n.first}),iC=`packages`,aC=()=>Object.keys(gl.shape).filter(e=>e!==iC).toSorted().join(`, `),oC=e=>`unknown ref field '${e}' — valid fields: ${aC()}`,sC=e=>Object.hasOwn(gl.shape,e),cC=(e,t,n)=>`failed to rewrite git remote at ${e} to '${U(t)}': ${n.trim()}`,lC=async(e,t)=>{if(iu(t.home,t.dest),!H(t.dest))return;let n=await e.runner.run(`git`,[`remote`,`set-url`,`--`,`origin`,t.cloneUrl],{cwd:t.dest});if(n.exitCode!==0)throw y(cC(t.dest,t.cloneUrl,n.stderr))},uC=async(e,t)=>{let n=_f(t.value,{allowFileUrls:qv(e.env)});if(n.key!==t.key)throw y(`new url derives a different key — remove and re-add instead`);let r=B(t.home,t.key);return await lC(e,{cloneUrl:n.cloneUrl,dest:r,home:t.home}),{...t.entry,url:n.cloneUrl}},dC=(e,t,n)=>{let r={...e,[t]:n},i=gl.safeParse(r);if(!i.success)throw y(T(i.error));return i.data},fC=(e,t)=>t.field===`url`?uC(e,{entry:t.entry,home:t.home,key:t.key,value:t.value}):Promise.resolve(dC(t.entry,t.field,t.value)),pC=async(e,t)=>{let{field:n}=t;if(n===iC)throw v(`use --package <name> <field> <value>`);if(!sC(n))throw v(oC(n));let r=t.entry[n],i=await fC(e,{entry:t.entry,field:n,home:t.home,key:t.key,value:t.value});return{new:i[n],old:r,updated:i}},mC=(e,t)=>{let n=z(e.env),{field:r,opts:i,query:a,value:o}=t;return W(n,`home`,async()=>{let t=await V(n),s=kS(t,a),c=mS(t,s);if(i.packageName!==void 0)return GS({config:t,entry:c,field:r,home:n,key:s,packageName:i.packageName,value:o});let l=await pC(e,{entry:c,field:r,home:n,key:s,value:o});return await fu(n,{...t,refs:{...t.refs,[s]:l.updated}}),{field:r,key:s,new:jS(l.new),old:jS(l.old)}})},hC=`settings`,gC=[],_C=()=>Object.keys(fl.shape).toSorted().join(`, `),vC=e=>`unknown setting '${e}' — valid settings: ${_C()}`,yC=e=>Object.hasOwn(fl.shape,e),bC=e=>`note: 'settings' addressed the global settings, not ${e} — use the full ref key to edit that ref`,xC=e=>{try{let t=kS(e,hC);return[bC(`ref '${t}'`)]}catch(e){if(e instanceof g&&e.code===`usage`)return[bC("one of several matching refs — see `refs list`")];if(e instanceof g&&e.code===`not_found`)return gC;throw e}},SC=e=>({data:{field:e.key,key:hC,new:jS(e.parsed[e.key]),old:jS(e.old)},warnings:xC(e.config)}),CC=(e,t)=>{let n=z(e.env);return W(n,`home`,async()=>{let e=await V(n);if(!yC(t.key))throw v(vC(t.key));let r=e.settings[t.key],i={...e.settings,[t.key]:t.value},a=fl.safeParse(i);if(!a.success)throw y(T(a.error));return await fu(n,{...e,settings:a.data}),SC({config:e,key:t.key,old:r,parsed:a.data})})},wC=[],TC=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},EC=e=>{if(e.second===void 0||e.value===void 0)throw v(`missing <field> and <value> — see 'refs edit --help'`);return{field:e.second,value:e.value}},DC=(e,t,n)=>{if(t.opts.packageName!==void 0)throw v(`--package is not valid with 'refs edit settings ...' — it only applies to ref/package edits`);return CC(e,n)},OC=async(e,t)=>{if(t.create.description!==void 0||t.create.path!==void 0)throw v(`--path and --description only apply to the package modes — to change one field of a registered package use: refs edit <ref> <field> <value> --package <name>`);let{field:n,value:r}=EC(t);return t.first===`settings`?DC(e,t,{key:n,value:r}):{data:await mC(e,{field:n,opts:t.opts,query:t.first,value:r}),warnings:wC}},kC=async(e,t)=>{let n=nC(t.create);return n===void 0?OC(e,t):{data:await rC(e,n,{create:t.create,first:t.first,packageName:t.opts.packageName,second:t.second,value:t.value}),warnings:wC}},AC=e=>e==null?`(unset)`:String(e),jC=(e,t)=>{let n=t?e.new:e.old,r=t?`declined`:`no longer declining`;return`${e.key}: ${r} '${n.name}' at ${n.path}`},MC=e=>{if(e.created===!0){let t=e.new;return`${e.key}: registered '${t.name}' at ${t.path}`}if(e.removed===!0){let t=e.old;return`${e.key}: unregistered '${t.name}' (was at ${t.path})`}return e.declined===void 0?void 0:jC(e,e.declined)},NC=e=>{let t=MC(e);return t===void 0?[`${e.key}: ${e.field} '${AC(e.old)}' -> '${AC(e.new)}'`]:[t]},PC=(e,t)=>{e.command(`edit`).description(`Edit one field: 'refs edit settings <key> <value>' for a global setting, or 'refs edit <ref> <field> <value> [--package <name>]' for a ref or package field. With --create, registers a package the config does not have yet; with --remove, unregisters one it has; with --decline, records that a package the checkout declares is deliberately not registered, so drift stops reporting it.`).argument(`<ref-or-settings>`,`a ref key/unique suffix, or the literal 'settings'`).argument(`[field-or-key]`,`field to edit (or, in settings mode, the setting key)`).argument(`[value]`,`the new value`).option(`--package <name>`,`edit this package's field instead of a top-level ref field`).option(`--create`,`register --package as a new package on this ref`).option(`--remove`,`unregister --package from this ref, leaving the checkout alone`).option(`--decline`,`record that --package at --path is deliberately not registered`).option(`--undecline`,`withdraw a decline, so the package is reported again`).option(`--path <path>`,`with --create/--decline/--undecline: the package path, relative to the checkout root`).option(`--description <text>`,`with --create: what the package is`).action((e,n,r,i,a)=>{let o=Y(a);return Z(t,o,async()=>{let{data:a,warnings:s}=await kC(t,{create:i,first:e,opts:TC(i),second:n,value:r});X(t,o,NC(a),a,s)})()})},FC=`Install the agent skill: npx skills add kaisers-io/refs (from a local clone: npx skills add <path-to-this-repo> --skill refs)`,IC={migrated:`migrated`,noop:`unchanged`,seeded:`seeded`},LC=async e=>{await a(e.root,{recursive:!0}),await a(e.sourcesDir,{recursive:!0}),await a(e.locksDir,{recursive:!0}),await a(e.hooksDir,{recursive:!0})},RC=async e=>{let t=z(e.env);return await LC(t),{config:await W(t,`home`,async()=>{let e=await Su(t,nv);return await Pd(t),e}),home:t.root,skill_hint:FC}},zC=(e,t)=>{e.command(`init`).description(`Seed or migrate the refs home directory, its config, and the git hooks guard.`).action((e,n)=>{let r=Y(n);return Z(t,r,async()=>{let e=await RC(t);X(t,r,[`home: ${e.home}`,`config: ${IC[e.config]}`,``,FC],e)})()})},BC=async e=>{let t=z(e.env),n=await W(t,`home`,()=>Su(t,nv));return n===`migrated`?{backup:eu(t),result:n}:{backup:null,result:n}},VC=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${re(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,HC=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=Y(n);return Z(t,r,async()=>{let e=await BC(t);X(t,r,VC(e),e)})()})},UC=async e=>{try{return await i(e),!0}catch(e){if(R(e))return!1;throw e}},WC=async e=>{try{return await c(e)}catch(e){if(R(e))return;throw e}},GC=async e=>{try{return(await i(e)).isDirectory()}catch(e){if(R(e))return;throw e}},KC=async e=>{let t=await WC(e);if(t===void 0)return!0;if(t.length>0)return!1;try{await f(e)}catch(e){if(!R(e))throw e}return!0},qC=async e=>{let t=await GC(e);return t===void 0?!0:t?KC(e):!1},JC=async(e,t)=>{t!==e.sourcesDir&&await qC(t)&&await JC(e,ie(t))},YC=async(e,t)=>await UC(t)?(iu(e,t),await d(t,{force:!0,recursive:!0}),await JC(e,ie(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},XC=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),ZC=async(e,t)=>{let n=await V(e),r={...n,refs:XC(n.refs,t)};await fu(e,r);let i=await Pg(e),a={...i,refs:XC(i.refs,t)};await Fg(e,a)},QC=async(e,t)=>{let n=z(e.env),r=await V(n),i=kS(r,t),a=B(n,i),{removedCheckout:o,warning:s}=await W(n,Kv(i),()=>YC(n,a));return await W(n,`home`,()=>ZC(n,i)),{data:{key:i,removed_checkout:o},warnings:Sv(s)}},$C=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],ew=(e,t)=>{e.command(`remove`).description(`Remove a configured ref: its config/state entry AND its checkout directory.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).action((e,n,r)=>{let i=Y(r);return Z(t,i,async()=>{let{data:n,warnings:r}=await QC(t,e);X(t,i,$C(n),n,r)})()})},tw=async e=>{let t=await $h(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:nw(e)},nw=async e=>tx(e,await tv(e.checkoutDir)),rw=async e=>{try{return await W(e.home,Kv(e.key),()=>tw(e),e.lockTimeoutMs===void 0?void 0:{timeoutMs:e.lockTimeoutMs})}catch(t){if(t instanceof g&&t.code===`conflict`)return{path:e.configuredPath,reason:`could not acquire the ref lock in time`,status:`unverifiable`};throw t}},iw=async e=>{if(!H(e.checkoutDir))return{path:e.configuredPath,status:`unmaterialized`};let t=await $h(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:(e.onProbed?.(),rw(e))},aw=(e,t)=>({local_path:null,name:e,path:null,reason:t,status:`unverifiable`}),ow=async e=>{if(!e.checkoutManaged)return aw(e.packageName,e.checkoutReason);let t=await iw(e);return{...t.candidates===void 0?{}:{candidates:t.candidates},...t.configuredPath===void 0?{}:{configured_path:t.configuredPath},local_path:t.path===null?null:m(e.checkoutDir,t.path),name:e.packageName,path:t.path,...t.reason===void 0?{}:{reason:t.reason},status:t.status}},sw=e=>[`package: ${e.name}`,`package path: ${e.local_path??`(unknown)`}`,...e.status===`verified`?[]:[`package status: ${e.status}`],...e.configured_path===void 0?[]:[`configured path: ${e.configured_path}`],...e.candidates===void 0?[]:[`candidates: ${e.candidates.join(`, `)}`],...e.reason===void 0?[]:[`reason: ${e.reason}`]],cw=`node_modules`,lw=[`.pnp.cjs`,`.pnp.js`],uw=new Set([``,`.`,`..`]),dw=e=>!ae(e)&&!e.includes(`\\`)&&e.split(`/`).every(e=>!uw.has(e)),fw=function*(e){let t=ce(e);for(;;){re(t)!==cw&&(yield m(t,cw));let e=ie(t);if(e===t)return;t=e}},pw=async e=>{if(await gw(e)!==`absent`)try{let t=JSON.parse(await s(e,`utf8`)),{name:n,version:r}=typeof t==`object`&&t?t:{};return typeof r!=`string`||r===``?{package_json:e,reason:`manifest_has_no_version`,status:`unverifiable`}:{...typeof n==`string`?{name:n}:{},package_json:e,status:`found`,version:r}}catch{return{package_json:e,reason:`manifest_unreadable`,status:`unverifiable`}}},mw=new Set([`ENOENT`,`ENOTDIR`]),hw=async e=>{try{return(await c(e)).length===0}catch{return!1}},gw=async e=>{try{return await p(e),`present`}catch(e){let t=typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0;return t!==void 0&&mw.has(t)?`absent`:`unreadable`}},_w=async e=>{for(let t of fw(e)){let e=ie(t);if((await Promise.all(lw.map(t=>gw(m(e,t))))).includes(`present`))return!0}return!1},vw=async e=>{try{if(!(await p(e)).isDirectory())throw v(`--project must be a directory: ${e}`)}catch(t){throw t instanceof Error&&t.message.startsWith(`--project`)?t:v(`--project path does not exist: ${e}`)}},yw=async e=>{let t=await gw(e);if(t===`unreadable`)return{reason:`slot_unreadable`,status:`unverifiable`};if(t===`absent`)return;let n=await pw(m(e,`package.json`));return n===void 0?await hw(e)?void 0:{reason:`installed_without_manifest`,status:`unverifiable`}:n},bw=async(e,t)=>{if(!dw(t))return{reason:`unsupported_package_name`,status:`unverifiable`};for(let n of fw(e)){let e=await yw(m(n,...t.split(`/`)));if(e!==void 0)return e}return await _w(e)?{reason:`yarn_pnp`,status:`unsupported_layout`}:{status:`not_materialized`}},xw={'"':`"`,"\\":`\\`,b:`\b`,n:`
|
|
351
|
-
`,t:` `},
|
|
349
|
+
packages to describe: ${Object.keys(e).toSorted().join(`, `)}`)},Zv=e=>{if(Object.keys(e).length!==0)return e},Qv=e=>{let t={default_branch:e.default_branch,description:e.description,url:e.url};return e.packages!==void 0&&(t.packages=e.packages),e.tag_format!==void 0&&(t.tag_format=e.tag_format),t},$v=`ref.`,ey=`${$v}_`,ty=`${ey}_`,ny=e=>`${ty}${ue(`sha256`).update(e,`utf8`).digest(`hex`)}`,ry=e=>{let t=e.includes(`_`)?`${ey}${e.replaceAll(`_`,`_u`).replaceAll(`/`,`_s`)}`:`${$v}${e.replaceAll(`/`,`_`)}`;return Buffer.byteLength(t,`utf8`)<=212&&zp(t)?t:ny(e)},iy=e=>e.REFS_ALLOW_FILE_URLS===`1`,ay=(e,t)=>{let n=gf(t,{allowFileUrls:iy(e.env)});return{cloneUrl:n.cloneUrl,key:n.key}},oy=async(e,t)=>{if(t===``)throw v(`refs add npm: requires a package name, e.g. npm:left-pad`);Fv(e,`resolving npm package '${t}'…`);let n=await em(e.fetcher,t),r={cloneUrl:n.cloneUrl,key:n.key,npmPkgName:t};return n.directory!==void 0&&(r.npmDirectory=n.directory),r},sy=(e,t)=>t.startsWith(`npm:`)?oy(e,t.slice(4)):Promise.resolve(ay(e,t)),cy=(e,t)=>{if(e.npmPkgName===void 0)return e;let n=Vg(`git_transport`,void 0,t);return{...e,cloneUrl:Df(e.cloneUrl,n)}},ly=e=>`ref '${e}' already exists — use refs edit or refs remove`,uy=(e,t)=>{if(e.refs[t]!==void 0)throw Ce(ly(t))},dy=async e=>{try{return await c(e,{withFileTypes:!0})}catch(e){if(R(e))return;throw e}},fy=e=>e.filter(e=>e.isDirectory()).map(e=>e.name),py=async(e,t)=>{let n=await dy(e);if(n===void 0)return{kind:`stop`};let r=fy(n);if(r.includes(t))return{kind:`continue`,nextDir:m(e,t)};let i=r.find(e=>e.toLowerCase()===t.toLowerCase());return i===void 0?{kind:`stop`}:{kind:`collision`,name:i}},my=async(e,t,n)=>{let[r,...i]=t;if(r===void 0)return;let a=await py(e,r);if(a.kind!==`stop`)return a.kind===`collision`?[...n,a.name].join(`/`):my(a.nextDir,i,[...n,r])},hy=[],gy=async(e,t)=>{let n=await my(e.sourcesDir,t.split(`/`),hy);if(n!==void 0)throw Ce(`checkout path for '${t}' collides case-insensitively with existing '${n}'`)},_y=e=>{switch(e.kind){case`candidate_not_inspected`:case`manifest_missing_name`:case`manifest_unreadable`:case`workspace_dir_unreadable`:return e.path;case`workspace_declaration_unparsed`:case`workspace_file_unreadable`:return e.file;case`unsupported_pattern`:return e.pattern;case`scan_budget_exhausted`:return`${e.pattern} at ${e.path}`;case`no_workspace_declaration`:return}},vy=e=>e.diagnostics.filter(e=>!Gh({diagnostics:[e],packages:[]})).map(e=>{let t=_y(e);return t===void 0?e.kind:`${t}: ${e.kind}`}).toSorted().join(`, `),yy=(e,t,n)=>`checkout at ${e} points at '${W(t)}' — expected '${W(n)}'; remove the checkout directory or run refs remove before retrying`,by=e=>e.exitCode===0?e.stdout.trim():`(no origin remote)`,xy=(e,t)=>{try{return gf(e,{allowFileUrls:t}).key}catch{return}},Sy=async(e,t)=>{let n=await e.run(`git`,[`remote`,`get-url`,`origin`],{cwd:t.dest}),r=by(n),i=xy(t.expectedUrl,t.allowFileUrls),a=xy(r,t.allowFileUrls);if(i===void 0||a!==i)throw Ce(yy(t.dest,r,t.expectedUrl))},Cy=e=>`checkout at ${e} exists but is not refs-managed — remove it (${Rv(e)}) and retry`,wy=async(e,t)=>{let n=await e.run(`git`,[`config`,`--local`,`core.hooksPath`],{cwd:t.dest});if(n.exitCode!==0||n.stdout.trim()!==t.hooksDir)throw Ce(Cy(t.dest))},Ty=async(e,t)=>{await a(ie(t.dest),{recursive:!0}),Fv(e,`cloning ${W(t.cloneUrl)} into ${t.dest}…`);let n=await Sd(e.runner,t);return n.warning===void 0?{effectiveMode:n.effectiveMode}:{effectiveMode:n.effectiveMode,warning:n.warning}},Ey=async(e,t)=>(iu(t.home,t.dest),U(t.dest)?(await Sy(e.runner,{allowFileUrls:t.allowFileUrls,dest:t.dest,expectedUrl:t.cloneUrl}),await wy(e.runner,{dest:t.dest,hooksDir:t.hooksDir}),{}):Ty(e,t)),Dy=(e,t)=>`checkout for '${e}' at ${t} is missing or corrupt (git rev-parse HEAD failed) — run: refs remove ${e}, then refs add <source> --dry-run again`,Oy=(e,t,n)=>`checkout for '${e}' at ${t} has a HEAD sha refs cannot store yet (${n.length} hex chars, expected 40) — only SHA-1 repositories are supported for now; \`--object-format=sha256\` repositories are not yet supported`,ky=async(e,t)=>{await Sy(e,t),await wy(e,{dest:t.dest,hooksDir:t.hooksDir});let n=await e.run(`git`,[`rev-parse`,`HEAD`],{cwd:t.dest});if(n.exitCode!==0)throw y(Dy(t.key,t.dest));let r=n.stdout.trim();if(!zg.shape.head_sha.safeParse(r).success)throw y(Oy(t.key,t.dest,r));return r},Ay=e=>Gh(e)?void 0:`workspace detection could not fully inspect the declared workspaces (${vy(e)}) — members may be missing from the detected packages; the repository's own workspace declaration is what settles it`,jy=(e,t)=>{let n=Wv(e.packages,t.resolved.npmDirectory,t.resolved.npmPkgName),r=qv(e.packages,n),i=Ay(e);return{defaultBranch:t.defaultBranch,...i===void 0?{}:{detectionWarning:i},packages:n,...r===void 0?{}:{rootPackageName:r},tagFormatCandidate:t.tagFormatCandidate}},My=e=>e.complete?Wd(e.tags):null,Ny=async(e,t,n)=>{let r=await wd(e.runner,t),i=await Pd(e.runner,t),a=My(i);Fv(e,`detecting workspace packages…`);let o=await dv(t);return jy(o,{defaultBranch:r,resolved:n,tagFormatCandidate:a})},Py=(e,t)=>G(t.home,ry(t.resolved.key),async()=>{let n=await Ey(e,{allowFileUrls:iy(e.env),cloneUrl:t.resolved.cloneUrl,dest:t.dest,home:t.home,hooksDir:t.home.hooksDir,mode:t.cloneMode}),r={fields:await Ny(e,t.dest,t.resolved)};return n.effectiveMode!==void 0&&(r.effectiveMode=n.effectiveMode),n.warning!==void 0&&(r.warning=n.warning),r}),Fy=(e,t)=>({default_branch:e.defaultBranch,description:``,key:t.key,packages:e.packages,tag_format_candidate:e.tagFormatCandidate,url:t.cloneUrl}),Iy=e=>{let{effectiveMode:t,fields:n,warning:r}=e.cloneResult;return{dest:e.dest,proposal:Fy(n,e.resolved),...n.detectionWarning===void 0?{}:{detectionWarning:n.detectionWarning},...n.rootPackageName===void 0?{}:{rootPackageName:n.rootPackageName},...t===void 0?{}:{effectiveCloneMode:t},...r===void 0?{}:{warning:r}}},Ly=async(e,t)=>{let n=z(e.env),r=await V(n),i=cy(await sy(e,t),r.settings);uy(r,i.key),await gy(n,i.key);let a=B(n,i.key),o=Vg(`clone_mode`,void 0,r.settings),s=await Py(e,{cloneMode:o,dest:a,home:n,resolved:i});return Iy({cloneResult:s,dest:a,resolved:i})},Ry=(e,t,n)=>G(e,`home`,async()=>{let r=await V(e);uy(r,t);let i=await Wg(e),a=i.refs[t],o=n??a?.effective_clone_mode,s={...a,pending_proposal_at:new Date().toISOString()};o!==void 0&&(s.effective_clone_mode=o),i.refs[t]=s,await Gg(e,i)}),zy=(e,t)=>{let n=bl.safeParse(e);if(!n.success)throw y(T(n.error));let r=Bg.safeParse(t);if(!r.success)throw y(T(r.error));return{config:n.data,state:r.data}},By=async(e,t)=>{let n=await V(e.home);uy(n,e.ref.key);let r=Qv(e.ref);n.refs[e.ref.key]=r;let i=await Wg(e.home);return i.refs[e.ref.key]={effective_clone_mode:e.effectiveCloneMode??i.refs[e.ref.key]?.effective_clone_mode??Vg(`clone_mode`,void 0,n.settings),head_sha:t,last_fetched_at:new Date().toISOString()},{...zy(n,i),entry:r}},Vy=async(e,t)=>{let n=iy(e.env),r=await G(t.home,ry(t.ref.key),()=>(iu(t.home,t.dest),ky(e.runner,{allowFileUrls:n,dest:t.dest,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.ref.key})));return G(t.home,`home`,async()=>{let{config:e,entry:n,state:i}=await By(t,r);return await Gg(t.home,i),await fu(t.home,e),{entry:n,key:t.ref.key}})},Hy=(e,t)=>t===`-`?e.readStdin():s(t,`utf8`),Uy=e=>{try{return JSON.parse(e)}catch(e){throw y(`invalid JSON in proposal: ${Nv(e)}`)}},Wy=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Gy=e=>Wy(e)&&`ok`in e&&!(`key`in e),Ky=e=>{if(!Gy(e))return e;if(e.ok===!1)throw y(`proposal file contains a failed refs envelope (ok is false) — re-run the dry-run`);if(Wy(e.data))return e.data;throw y(`proposal file is a refs envelope without a usable data object — re-run the dry-run`)},qy=e=>e.code===`unrecognized_keys`,Jy=e=>e.path.length===0,Yy=(e,t)=>{let n=t.toSorted().map(e=>`"${e}"`).join(`, `);return e===``?`✖ unrecognized key(s) in proposal: ${n}`:`✖ unrecognized key(s) in proposal at ${e}: ${n}`},Xy=e=>{let t=new Map;for(let n of e){let e=Yt(n.path);t.set(e,[...t.get(e)??[],...n.keys])}return[...t.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>Yy(e,t))},Zy=e=>`✖ invalid proposal: ${e.message}`,Qy=e=>{let t=e.issues.filter(e=>qy(e)),n=e.issues.filter(e=>!qy(e)),r=n.filter(e=>Jy(e));if(t.length===0&&r.length===0)return T(e);let i=n.filter(e=>!Jy(e)),a=[...Xy(t),...r.map(e=>Zy(e))];return i.length>0&&a.push(T({issues:i})),a.join(`
|
|
350
|
+
`)},$y=e=>{let t=Rg.safeParse(e);if(!t.success)throw y(Qy(t.error));return t.data},eb=async(e,t)=>{let n=await Hy(e,t);return $y(Ky(Uy(n)))},tb=(e,t)=>[`refs add: dry-run proposal ready for '${e}' (checkout: ${t})`,`next: review the proposal, then run refs add --proposal <file> to finalize`],nb=e=>[...Mv(e.warning),...Mv(e.detectionWarning)],rb=async(e,t)=>{let n=await Ly(e,t),r=z(e.env);await Ry(r,n.proposal.key,n.effectiveCloneMode);let i=nb(n);return{data:n.proposal,human:tb(n.proposal.key,n.dest),warnings:i}},ib=e=>[`refs add: '${e}' added to config`],ab=e=>{let t={default_branch:e.default_branch,description:e.description,key:e.key,url:e.url};e.tag_format_candidate!==null&&(t.tag_format=e.tag_format_candidate);let n=Zv(e.packages);return n!==void 0&&(t.packages=n),t},ob=async(e,t)=>{let n=await eb(e,t),r=z(e.env),i=B(r,n.key);if(!U(i))throw _(`no checkout found at ${i} — run: refs add <source> --dry-run first`);let a=ab(n),{entry:o,key:s}=await Vy(e,{dest:i,home:r,ref:a});return{data:{entry:o,key:s},human:ib(s),warnings:[]}},sb=(e,t,n)=>{Xv(e.proposal.packages,n,e.rootPackageName);let r={default_branch:e.proposal.default_branch,description:t,key:e.proposal.key,url:e.proposal.url};e.proposal.tag_format_candidate!==null&&(r.tag_format=e.proposal.tag_format_candidate);let i=Kv(e.proposal.packages,{refDescription:t,...e.rootPackageName===void 0?{}:{rootPackageName:e.rootPackageName}});return i!==void 0&&(r.packages=i),r},cb=async(e,t,n)=>{let r=await Ly(e,t),i=z(e.env);await Ry(i,r.proposal.key,r.effectiveCloneMode);let a=sb(r,n,t),o={dest:r.dest,home:i,ref:a};r.effectiveCloneMode!==void 0&&(o.effectiveCloneMode=r.effectiveCloneMode);let{entry:s,key:c}=await Vy(e,o);return{data:{entry:s,key:c},human:ib(c),warnings:nb(r)}},lb=e=>{let t=[e.dryRun,e.proposal!==void 0,e.description!==void 0].filter(Boolean).length;if(t>1)throw v(`refs add: use only one of --dry-run, --proposal, or --description`);if(t===0)throw v(`refs add needs --dry-run, --proposal, or --description`)},ub=e=>{if(e===void 0||e===``)throw v(`refs add requires <source> (a git url or npm:<package>)`);return e},db=(e,t)=>(lb(t),t.proposal===void 0?t.description===void 0?rb(e,ub(t.source)):cb(e,ub(t.source),t.description):ob(e,t.proposal)),fb=(e,t)=>{let n={dryRun:t.dryRun===!0};return e!==void 0&&(n.source=e),t.proposal!==void 0&&(n.proposal=t.proposal),t.description!==void 0&&(n.description=t.description),n},pb=(e,t)=>{e.command(`add`).description(`Add a git reference in two phases: propose (--dry-run), then finalize (--proposal).`).argument(`[source]`,`git url or npm:<package> (omit when finalizing with --proposal)`).option(`--dry-run`,`resolve and clone the source, writing a reviewable proposal`).option(`--proposal <file>`,`finalize from a completed proposal JSON file (- for stdin)`).option(`--description <text>`,`one-shot: dry-run then finalize immediately with this description`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=await db(t,fb(e,n));Z(t,i,r.human,r.data,r.warnings)})()})},mb=async e=>{let t=await e.runner.run(`git`,[`--version`]);return t.exitCode===0?{detail:t.stdout.trim(),name:`git`,status:`ok`}:{detail:t.stderr.trim()||`git --version exited with code ${t.exitCode}`,name:`git`,status:`fail`}},hb=/^v(?<major>\d+)\.(?<minor>\d+)/u,gb=e=>{let t=hb.exec(e),n=t?.groups?.major,r=t?.groups?.minor;if(n!==void 0&&r!==void 0)return{major:Number(n),minor:Number(r)}},_b=e=>e===void 0?!1:e.major>24||e.major===24&&e.minor>=2,vb=e=>{let{nodeVersion:t}=e;return _b(gb(t))?{detail:t,name:`node`,status:`ok`}:{detail:`${t} does not satisfy the required range >=24.2`,name:`node`,status:`fail`}},yb=()=>bl.parse({meta:{cli_version:`0.0.0`,schema_version:1},refs:{},settings:{}}),bb=async e=>{try{return{config:await V(e)}}catch(e){return{config:yb(),errorMessage:Nv(e)}}},xb=e=>e===void 0?{detail:`config is present and matches the current schema`,name:`config`,status:`ok`}:{detail:e,name:`config`,status:`fail`},Sb={ci:`update check is off in CI — set REFS_UPDATE_CHECK=1 to run it here anyway`,config:`update check is off ([updates].check = false in config.toml)`,env:`update check is off (REFS_UPDATE_CHECK=0)`},Cb=(e,t,n)=>{if(r_(e,t)){let r=n?` (npm was unreachable just now; this was its last answer)`:``;return{detail:`${i_(e,t)}${r}`,name:`cli-update`,status:`warn`}}return n?{detail:`could not reach npm to check; its last answer was ${t}, which this CLI (${e}) already has`,name:`cli-update`,status:`warn`}:{detail:`this CLI (${e}) is npm's latest published release`,name:`cli-update`,status:`ok`}},wb=async(e,t)=>{let n=c_({env:e.env,updates:t.updates});if(n!==`on`)return{detail:Sb[n],name:`cli-update`,status:`ok`};let{latest:r,stale:i}=await n_({fetch:e.fetcher,home:z(e.env),nowMs:Date.now()});return r===void 0?{detail:`could not reach npm to learn the latest published version — not a fault of your setup, and nothing else depends on it`,name:`cli-update`,status:`warn`}:Cb(e.cliVersion,r,i)},Tb=(e,t)=>Object.keys(t.refs).map(e=>il.parse(e)).map(t=>({dest:B(e,t),key:t})).filter(e=>U(e.dest)),Eb=[`pre-commit`,`pre-push`],Db=async(t,r)=>{try{return await e(m(t.hooksDir,r),n.X_OK),!0}catch{return!1}},Ob=async e=>{let t=await Promise.all(Eb.map(t=>Db(e,t)));return Eb.filter((e,n)=>!t[n])},kb=async(e,t,n)=>{let r=await e.runner.run(`git`,[`config`,`--local`,`--get`,`core.hooksPath`],{cwd:n});return r.exitCode===0&&r.stdout.trim()===t.hooksDir},Ab=e=>e.missingHooks.length>0?{detail:`${e.missingHooks.map(e=>`hooks/${e}`).join(`, `)} missing or not executable — run: refs init`,name:`hooks-guard`,status:`fail`}:e.badKeys.length>0?{detail:`core.hooksPath not set for: ${e.badKeys.join(`, `)} — run: refs init`,name:`hooks-guard`,status:`fail`}:{detail:`${Eb.map(e=>`hooks/${e}`).join(`, `)} present; ${e.checkoutCount} checkout(s) guarded`,name:`hooks-guard`,status:`ok`},jb=async(e,t,n)=>{let r=Tb(t,n),[i,a]=await Promise.all([Ob(t),Promise.all(r.map(n=>kb(e,t,n.dest)))]),o=r.filter((e,t)=>!a[t]).map(e=>e.key);return Ab({badKeys:o,checkoutCount:r.length,missingHooks:i})},Mb=async(e,t)=>{let n=await e.runner.run(`git`,[`status`,`--porcelain`],{cwd:t.dest});return n.exitCode===0?{broken:!1,detail:``,dirty:n.stdout.trim()!==``,key:t.key}:{broken:!0,detail:n.stderr.trim(),dirty:!1,key:t.key}},Nb=e=>{let t=e.filter(e=>e.broken);if(t.length>0)return{detail:t.map(e=>`${e.key}: git status failed — ${e.detail}`).join(`; `),name:`dirty-checkouts`,status:`fail`};let n=e.filter(e=>e.dirty).map(e=>e.key);return n.length===0?{detail:`no local changes in any checkout`,name:`dirty-checkouts`,status:`ok`}:{detail:`local changes will be discarded on next sync: ${n.join(`, `)}`,name:`dirty-checkouts`,status:`warn`}},Pb=async(e,t,n)=>{let r=Tb(t,n),i=await Promise.all(r.map(t=>Mb(e,t)));return Nb(i)},Fb=async e=>{try{return await Wg(e)}catch{return Bg.parse({})}},Ib=async e=>{try{return(await c(e,{withFileTypes:!0})).filter(e=>e.isDirectory()).map(e=>e.name)}catch(e){if(R(e))return[];throw e}},Lb=async(e,t)=>{if(U(e))return[[...t]];let n=await Ib(e);return(await Promise.all(n.map(n=>Lb(m(e,n),[...t,n])))).flat()},Rb=(e,t,n)=>{let r=e.refs[t]?.pending_proposal_at;return r!==void 0&&n-Date.parse(r)<864e5},zb=(e,t,n)=>Rb(t,e.key,n)?`${e.key}: pending add`:`${e.key}: orphan — remove with: ${Rv(e.dest)}`,Bb=(e,t)=>({dest:m(e.sourcesDir,...t),key:t.join(`/`)}),Vb=async(e,t,n)=>{let r=(await Lb(e.sourcesDir,[])).map(t=>Bb(e,t)).filter(e=>!Object.hasOwn(t.refs,e.key));if(r.length===0)return{detail:`no orphaned checkouts under sources/`,name:`orphans`,status:`ok`};let i=Date.now();return{detail:r.map(e=>zb(e,n,i)).join(`; `),name:`orphans`,status:`warn`}},Hb=e=>{let t=(e??``).lastIndexOf(`/`);return t===-1?`.`:(e??``).slice(0,t)},Ub=e=>{let[t=`.`,...n]=e,r=t.split(`/`),i=r.length;for(let e of n){let t=e.split(`/`),n=0;for(;n<i&&n<t.length&&r[n]===t[n];)n+=1;i=n}return i===0?`.`:r.slice(0,i).join(`/`)},Wb=`(unknown)`,Gb=e=>ul.safeParse(e.path).success,Kb=(e,t)=>{let n=`${e.name}: declared in this checkout but not registered — it cannot be resolved by name until it is`;if(e.path===void 0)return`${n}. Declared at several paths (${(e.candidates??[]).join(`, `)}) — pick one`;if(!Gb(e))return`${n}. Its path is one the configuration cannot hold, so there is no command for it — report it and leave it unregistered`;let r=Lv([`--package=${Iv(e.name)}`,`--decline`,`--path=${Iv(e.path)}`],[t]);return Kc(e.name)?`${n}. To register it: ${Lv([`--package=${Iv(e.name)}`,`--create`,`--path=${Iv(e.path)}`,`--description="<what it is>"`],[t])}. If it should not be: ${r}`:`${n}. Its name is one the packages table cannot hold, so it cannot be registered — if that is the answer, record it: ${r}`},qb=(e,t,n)=>{let r=`${e.name}: moved to ${e.path??Wb} — update the entry's path (${n})`,i=Lv([`--package=${Iv(e.name)}`],[t,`path`,e.path??``]);return ul.safeParse(e.path).success?`${r}. To fix it: ${i}`:r},Jb=(e,t)=>{let n=`configured: ${e.configured_path??Wb}`;if(e.status===`relocated`)return qb(e,t,n);if(e.status===`missing`){let r=Lv([`--package=${Iv(e.name)}`,`--remove`],[t]);return`${e.name}: gone from this repo's workspaces (${n}) — repoint the entry if it moved out of them, or unregister it: ${r}`}if(e.status===`ambiguous`){let t=(e.candidates??[]).join(`, `);return`${e.name}: declared at several paths (${t}) — point the entry at one (${n})`}return`${e.name}: could not be checked — ${e.reason??`(no reason given)`} (${n})`},Yb=(e,t)=>e.status===`unregistered`?Kb(e,t):Jb(e,t),Xb=e=>`could not check for unregistered packages — ${e}`,Zb=e=>`…and ${e} more finding(s) — act on the ones above (register, repoint or decline) and run the check again to see the rest`,Qb=e=>{let t=e.length-10;return t<=0?[...e]:[...e.slice(0,10),Zb(t)]},$b=e=>{let t=new Map;for(let n of e){let[e=`.`]=Hb(n.path).split(`/`);t.set(e,[...t.get(e)??[],n])}return t},ex=e=>e.path===void 0,tx=(e,t,n)=>{if(e.length<3)return e.map(e=>({candidates:1,dir:n,line:Kb(e,t)}));let r=Ub(e.map(e=>Hb(e.path)));return[{candidates:e.length,dir:r,line:`${r}: ${e.length} unregistered package(s) the configuration does not have`}]},nx=e=>{let t=e.reduce((e,t)=>e+t.candidates,0),n=new Set(e.flatMap(e=>e.dir===void 0?[]:[e.dir])).size;return`…and ${t} more unregistered package(s)${n===0?``:` in ${n} director(ies)`} — 'refs doctor --json' lists every candidate`},rx=(e,t)=>{let n=e.filter(e=>ex(e)).map(e=>({candidates:1,line:Kb(e,t)})),r=[...$b(e.filter(e=>!ex(e)))].toSorted(([e],[t])=>e.localeCompare(t)).flatMap(([e,n])=>tx(n,t,e)),i=[...n,...r],a=i.slice(10);return a.length===0?i.map(e=>e.line):[...i.slice(0,10).map(e=>e.line),nx(a)]},ix=(e,t)=>e.reason===void 0?[...Qb((e.packages??[]).map(e=>Yb(e,t))),...rx(e.discovery??[],t),...e.discovery_incomplete===void 0?[]:[Xb(e.discovery_incomplete)]]:[`could not be checked — ${e.reason}`],ax=e=>{let t;return()=>(t??=dv(e),t)},ox=async(e,t,n)=>{let r=await S_(e);if(r===void 0||t.some(e=>e.packageName===r.name))return{issues:[]};let i=await n();if(!Gh(i))return{incomplete:vy(i),issues:[]};let a=tg(i.packages,r.name);return a.kind===`ambiguous`?{issues:[{candidates:a.paths,name:r.name,status:`unregistered`}]}:{issues:a.kind===`found`?[{name:r.name,path:a.path,status:`unregistered`}]:[]}},sx=e=>{let t=new Map;for(let n of e)t.set(n.name,[...t.get(n.name)??[],n.path]);return t},cx=(e,t)=>{let n=new Set(e.changedDirs),r=t.filter(e=>!n.has(e.path)).map(e=>e.name);return new Set([...e.namesBefore,...r])},lx=(e,t)=>t.length===1&&t[0]!==void 0?{name:e,path:t[0],status:`unregistered`}:{candidates:[...t],name:e,status:`unregistered`},ux=async(e,t,n)=>{if(t.kind===`arrivals`&&t.changedDirs.length===0)return{issues:[]};let r=await n();if(!Gh(r))return{incomplete:vy(r),issues:[]};let i=new Set(e.map(e=>e.packageName)),a=r.packages.filter(e=>e.path!==`.`),o=t.kind===`all`?void 0:cx(t,a);return{issues:[...sx(a)].filter(([e])=>!i.has(e)).filter(([e])=>o===void 0||!o.has(e)).map(([e,t])=>lx(e,t)).toSorted((e,t)=>e.name.localeCompare(t.name))}},dx=(e,t)=>{if(t.length===0)return{issues:[...e],suppressed:[]};let n=(e,n)=>t.some(t=>t.name===e&&t.path===n),r=[];return{issues:e.flatMap(e=>{if(e.status!==`unregistered`)return[e];let t=e.path===void 0?e.candidates??[]:[e.path],i=t.filter(t=>!n(e.name,t)),a=t.filter(t=>n(e.name,t));return r.push(...a.map(t=>({name:e.name,path:t}))),i.length===0?[]:[lx(e.name,i)]}),suppressed:r}},fx=e=>e!==`unmaterialized`&&e!==`verified`,px=new Set([`ambiguous`,`missing`,`relocated`]),mx=(e,t={})=>{let{declined:n=[],discoveryIncomplete:r}=t,i=e.filter(e=>e.status!==`unregistered`),a=e.filter(e=>e.status===`unregistered`);return{...n.length===0?{}:{declined:[...n]},...a.length===0?{}:{discovery:a},...r===void 0?{}:{discovery_incomplete:r},...i.length===0?{}:{packages:i},status:hx(i,r)}},hx=(e,t)=>e.some(e=>px.has(e.status))?`drift`:e.length===0&&t===void 0?`ok`:`unknown`,gx=(e,t)=>({path:e.configuredPath,reason:t,status:`unverifiable`}),_x=(e,t)=>Kh(t)?{configuredPath:e.configuredPath,path:null,status:`missing`}:gx(e,`this repo declares no workspaces, so there was nowhere to search`),vx=(e,t)=>t===e.configuredPath,yx=e=>e.packages.filter(e=>e.path!==`.`),bx=(e,t)=>{let n=tg(yx(t),e.packageName);return n.kind===`ambiguous`?{candidates:n.paths,configuredPath:e.configuredPath,path:null,status:`ambiguous`}:Gh(t)?n.kind===`absent`?_x(e,t):vx(e,n.path)?gx(e,`the checkout changed while it was being inspected`):{configuredPath:e.configuredPath,path:n.path,status:`relocated`}:gx(e,n.kind===`found`?`workspace detection was incomplete, so the new location is not confirmed unique`:`workspace detection was incomplete`)},xx=e=>{let t=new Map(Object.entries(e??{}));return[...t.keys()].toSorted().flatMap(e=>{let n=t.get(e);return n===void 0?[]:[{configuredPath:n.path,packageName:e}]})},Sx=async(e,t)=>{let n=await Qh(e,t.configuredPath,t.packageName);if(n.kind===`match`)return{path:t.configuredPath,status:`verified`};if(n.kind===`unreadable`)return{path:t.configuredPath,reason:n.reason,status:`unverifiable`}},Cx=e=>e.flatMap(e=>e.settled===void 0?[]:[{outcome:e.settled,query:e.query}]),wx=async(e,t,n)=>{let r=await Promise.all(t.map(async t=>({query:t,settled:await Sx(e,t)})));if(r.every(e=>e.settled!==void 0))return Cx(r);let i=await n();return r.map(e=>({outcome:e.settled??bx(e.query,i),query:e.query}))},Tx=e=>{let{outcome:t,query:n}=e;return fx(t.status)?[{...t.candidates===void 0?{}:{candidates:t.candidates},configured_path:n.configuredPath,name:n.packageName,...t.status===`relocated`&&t.path!==null?{path:t.path}:{},...t.reason===void 0?{}:{reason:t.reason},status:t.status}]:[]},Ex=(e,t)=>{let n=new Set(e.map(e=>e.name));return[...e,...t.filter(e=>!n.has(e.name))]},Dx=async(e,t,n)=>{let r=xx(t.packages),[i]=r;if(i===void 0)return{status:`ok`};let a=ax(e);try{let[i,o,s]=await Promise.all([wx(e,r,a),ox(e,r,a),ux(r,n,a)]),c=dx([...i.flatMap(e=>Tx(e)),...Ex(o.issues,s.issues)],t.declined_packages??[]);return mx(c.issues,{declined:c.suppressed,...(s.incomplete??o.incomplete)===void 0?{}:{discoveryIncomplete:s.incomplete??o.incomplete}})}catch(e){return{reason:Nv(e),status:`unknown`}}},Ox=async(e,t,n)=>{try{return await G(e,ry(n.key),()=>Dx(n.dest,t.refs[n.key]??{},{kind:`all`}),{timeoutMs:100})}catch(e){if(e instanceof g&&e.code===`conflict`)return{reason:`another refs process is holding this ref`,status:`unknown`};throw e}},kx=e=>e===0?``:` (${e} declined package(s) not reported)`,Ax=(e,t)=>e.unhealthy.length===0?`every configured package path resolves in ${t} checkout(s)`:e.unhealthy.join(`; `),jx=(e,t)=>{let{declined:n,discovery:r,findings:i}=e;return{detail:[Ax(e,t)+kx(n),...r].join(`; `),...i.length===0?{}:{findings:i},name:`config-drift`,status:e.unhealthy.length===0?`ok`:`warn`}},Mx=async(e,t,n)=>{let[r,...i]=n;if(r===void 0)return{declined:0,discovery:[],findings:[],unhealthy:[]};let a=await Ox(e,t,r),o=await Mx(e,t,i);return Nx(o,{key:r.key,report:a})},Nx=(e,t)=>{let{key:n,report:r}=t,i=e=>e.map(e=>`${n}: ${e}`),a=r.discovery??[],o=r.packages??[],s=[...o,...a];return{declined:(r.declined??[]).length+e.declined,discovery:[...i(ix({discovery:a,status:`ok`},n)),...e.discovery],findings:s.length===0?e.findings:[{key:n,packages:s},...e.findings],unhealthy:[...i(ix({...r.discovery_incomplete===void 0?{}:{discovery_incomplete:r.discovery_incomplete},...r.reason===void 0?{}:{reason:r.reason},packages:o,status:r.status},n)),...e.unhealthy]}},Px=async(e,t)=>{let n=Tb(e,t);return jx(await Mx(e,t,n),n.length)},Fx=e=>{let{diagnosis:t}=e;return e.kind===`claim`||!e.isDirectory||t.pidState===`definitely-dead`||t.stale||t.meta===`malformed`||t.meta===`unreadable`||t.policy===`unknown`?!1:t.ageMs===void 0||t.ageMs>=0},Ix=e=>{let{ageMs:t,budgetMs:n,policy:r}=e;return r===`unknown`?`, state could not be read`:t===void 0||n===void 0?``:t<0?`, recorded time is in the future — check the system clock`:`, ${Sp(t)} into a ${Sp(n)} window`},Lx=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} present`,Rx=(e,t)=>{let n=m(e.locksDir,op,t.name),r=t.diagnosis.ageMs===void 0?``:` for ${Sp(t.diagnosis.ageMs)}`;return`steal claim on ${t.name}: present${r}. Stealing this lock is blocked while it is here. A reclaim in progress clears it within a moment; if it stays, ${zx}: ${zv(n)}`},zx=`stop every refs process using this home — including suspended ones — and then run`,Bx=(e,t)=>{let{diagnosis:n}=t;if(ep(n))return`, reclaimable now`;if(!n.stale&&t.isDirectory)return``;let r=m(e.locksDir,t.name);return`, not automatically reclaimable — if it is genuinely abandoned, ${zx}: ${Rv(r)}`},Vx=(e,t)=>{let{diagnosis:n}=t,r=t.isDirectory?``:`not a directory, `,i=Bx(e,t);return`${t.name}: ${r}${Lx(n)}${Ix(n)}${i}`},Hx=async e=>{let t=await xp(e),[n]=t;return n===void 0?{detail:`no locks held`,name:`locks`,status:`ok`}:{detail:t.map(t=>t.kind===`claim`?Rx(e,t):Vx(e,t)).join(`; `),name:`locks`,status:t.every(e=>Fx(e))?`ok`:`warn`}},Ux=[`.agents`,`skills`,`refs`,`SKILL.md`],Wx=[`skills`,`refs`,`SKILL.md`],Gx=[`.claude`,`skills`,`refs`,`SKILL.md`],Kx=`npx skills add kaisers-io/refs`,qx=`npm i -g @kaisers-io/refs@latest`,Jx=(e,t)=>e===void 0?void 0:{display:t,path:e},Yx=e=>{let{dirName:t,env:n,home:r,overrideName:i}=e,a=n[i]?.trim();return a!==void 0&&a.length>0?{display:a,path:a}:Jx(r===void 0?void 0:m(r,t),`~/${t}`)},Xx=e=>{let t=e.homedir.length>0?e.homedir:void 0;return[{label:`shared ~/.agents`,root:Jx(t,`~/.agents`),segments:Ux},{label:`Claude Code`,root:Yx({dirName:`.claude`,env:e.env,home:t,overrideName:`CLAUDE_CONFIG_DIR`}),segments:Wx},{label:`Codex`,root:Yx({dirName:`.codex`,env:e.env,home:t,overrideName:`CODEX_HOME`}),segments:Wx},{label:`project ./.agents`,root:Jx(e.cwd,`./.agents`),segments:Ux},{label:`project ./.claude`,root:Jx(e.cwd,`./.claude`),segments:Gx}].flatMap(({label:e,root:t,segments:n})=>t===void 0?[]:[{display:t.display,label:e,path:m(t.path,...n)}])},Zx=async(e,t)=>{try{let n=await l(e);return{label:t,realPath:n,source:await s(n,`utf8`)}}catch{return}},Qx=e=>{let t=new Map;for(let n of e)t.has(n.realPath)||t.set(n.realPath,n);return[...t.values()]},$x=/^---\r?\n(?<body>[\s\S]*?)\r?\n---/u,eS=/^\s*cli_version:\s*["']?(?<version>[^"'\s]+)["']?\s*$/mu,tS=e=>{let t=$x.exec(e)?.groups?.body;if(t!==void 0)return eS.exec(t)?.groups?.version},nS=(e,t)=>{if(e===t)return`match`;let n=Yg(e,t);return n===void 0?`unknown`:n===0?`match`:n>0?`cli-older`:`skill-older`},rS={"cli-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the CLI: ${qx}`,match:(e,t)=>`the refs skill is installed and matches this CLI (${t})`,"skill-older":(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — update the skill: ${Kx}`,unknown:(e,t)=>`the refs skill targets CLI ${e} but this CLI is ${t} — reinstall both: ${qx} and ${Kx}`},iS=e=>{let{cliVersion:t,label:n,skillVersion:r}=e;if(r===void 0)return{detail:`the refs skill (${n}) predates the version gate — update it: ${Kx}`,name:`skill`,status:`warn`};let i=nS(r,t);return{detail:`${n}: ${rS[i](r,t)}`,name:`skill`,status:i===`match`?`ok`:`warn`}},aS=e=>({detail:`refs skill not found in the locations this check knows about (${e.map(e=>e.display).join(`, `)}) — an install anywhere else is invisible here and still works; if it really is missing: ${Kx}`,name:`skill`,status:`warn`}),oS=async e=>{let t=Xx(e),n=await Promise.all(t.map(e=>Zx(e.path,e.label))),r=Qx(n.filter(e=>e!==void 0)).map(t=>iS({cliVersion:e.cliVersion,label:t.label,skillVersion:tS(t.source)}));return r.find(e=>e.status!==`ok`)??r[0]??aS(t)},sS=/^(?<user>[^/\s@]+)@(?<host>[^:/\s]+):/u,cS=e=>e===``?{}:{user:e},lS=e=>e===``?{}:{port:e},uS=e=>{try{let t=new URL(e);return t.protocol===`ssh:`?{host:t.hostname,...cS(t.username),...lS(t.port)}:void 0}catch{return}},dS=e=>{let t=sS.exec(e),n=t?.groups?.host;return n===void 0?uS(e):{host:n,user:t?.groups?.user??`git`}},fS=e=>e.port===void 0?e.host:`${e.host}:${e.port}`,pS=e=>e.user===void 0?fS(e):`${e.user}@${fS(e)}`,mS=e=>{let t=Object.values(e.refs).map(e=>dS(e.url)).filter(e=>e!==void 0),n=new Map;for(let e of t)n.set(pS(e),e);return[...n.values()].toSorted((e,t)=>pS(e).localeCompare(pS(t)))},hS=/Permission denied/u,gS=[/Could not resolve hostname/u,/Connection refused/u,/Host key verification failed/u,/timed out/u],_S=e=>e.user===void 0?e.host:`${e.user}@${e.host}`,vS=e=>{let t=[`-o`,`ConnectTimeout=5`,`-o`,`BatchMode=yes`],n=_S(e);return e.port===void 0?[...t,`-T`,n]:[...t,`-p`,e.port,`-T`,n]},yS=async(e,t,n)=>{let r=pS(t),i=await e.runner.run(`ssh`,vS(t),{timeoutMs:n});return i.timedOut===!0?{host:r,outcome:`timeout`}:hS.test(i.stderr)?{host:r,outcome:`denied`}:gS.some(e=>e.test(i.stderr))?{detail:i.stderr.trim(),host:r,outcome:`connection-warn`}:{host:r,outcome:`ok`}},bS=(e,t)=>{let n=e.filter(e=>e.outcome===`timeout`).map(e=>e.host);if(n.length!==0)return{detail:`ssh probe timed out after ${t/1e3}s: ${n.join(`, `)}`,name:`ssh-auth`,status:`fail`}},xS=e=>{let t=e.filter(e=>e.outcome===`denied`).map(e=>e.host);if(t.length!==0)return{detail:`ssh permission denied for: ${t.join(`, `)}`,name:`ssh-auth`,status:`fail`}},SS=e=>{let t=e.filter(e=>e.outcome===`connection-warn`);if(t.length!==0)return{detail:`ssh connection issue, treated as warn: ${t.map(e=>`${e.host} (${e.detail??``})`).join(`; `)}`,name:`ssh-auth`,status:`warn`}},CS=e=>({detail:`ssh auth ok for: ${e.map(e=>e.host).join(`, `)}`,name:`ssh-auth`,status:`ok`}),wS=(e,t)=>bS(e,t)??xS(e)??SS(e)??CS(e),TS=async(e,t,n)=>{let r=mS(t);if(r.length===0)return;let i=n?.timeoutMs??1e4,a=await Promise.all(r.map(t=>yS(e,t,i)));return wS(a,i)},ES=async e=>{try{return await e.run()}catch(t){return{detail:`check crashed: ${Nv(t)}`,name:e.name,status:`fail`}}},DS=async e=>{let[t,...n]=e;if(t===void 0)return[];let r=await ES(t),i=await DS(n);return r===void 0?i:[r,...i]},OS=e=>{let{configLoad:t,ctx:n,home:r,state:i}=e;return[{name:`git`,run:()=>mb(n)},{name:`node`,run:()=>Promise.resolve(vb(n))},{name:`config`,run:()=>Promise.resolve(xb(t.errorMessage))},{name:`hooks-guard`,run:()=>jb(n,r,t.config)},{name:`dirty-checkouts`,run:()=>Pb(n,r,t.config)},{name:`config-drift`,run:()=>Px(r,t.config)},{name:`orphans`,run:()=>Vb(r,t.config,i)},{name:`locks`,run:()=>Hx(r)},{name:`skill`,run:()=>oS(n)},{name:`cli-update`,run:()=>wb(n,t.config)},{name:`ssh-auth`,run:()=>TS(n,t.config)}]},kS=async e=>{let t=z(e.env),n=await bb(t),r=await Fb(t);return DS(OS({configLoad:n,ctx:e,home:t,state:r}))},AS={fail:`FAIL`,ok:`OK`,warn:`WARN`},jS=e=>e.map(e=>`[${AS[e.status]}] ${e.name}: ${e.detail}`),MS=e=>e.some(e=>e.status===`fail`),NS=(e,t)=>{e.command(`doctor`).description(`Run environment/integrity checks (git, node, config, hooks, checkouts, drift, locks, ssh).`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await kS(t);Z(t,r,jS(e),{checks:e}),MS(e)&&(process.exitCode=Se.UNEXPECTED)})()})},PS=(e,t)=>{let n=e.refs[t];if(n===void 0)throw Error(`internal: matched ref key '${t}' is missing from config.refs`);return n},FS=(e,t)=>{if(!U(e))throw _(`checkout for '${t}' is missing — run: refs sync ${t}`)},IS=(e,t,n)=>{let r=e.packages?.[n];if(r===void 0)throw _(`no package '${n}' registered on ref '${t}'`);return r},LS=`never`,RS=(e,t,n)=>e===void 0||n-Date.parse(e)>t,zS=(e,t)=>`${e} ${t}${e===1?``:`s`} ago`,BS=(e,t)=>{if(e===void 0)return LS;let n=t-Date.parse(e);if(Number.isNaN(n))return LS;let r=Math.floor(n/1e3);if(r<60)return`just now`;let i=Math.floor(r/60);if(i<60)return zS(i,`minute`);let a=Math.floor(i/60);if(a<24)return zS(a,`hour`);let o=Math.floor(a/24);return o<365?zS(o,`day`):zS(Math.floor(o/365),`year`)},VS=e=>{let t=BS(e.lastFetchedAt,e.now),n=[`synced: ${t}`];return e.stale&&t!==LS&&n.push(`status: stale`),e.missing&&n.push(`missing: checkout not found — run: refs sync`),n},HS=(e,t,n)=>{let r=e.state.refs[t],i=ol(Vg(`sync_ttl`,n,e.settings)),a=Object.keys(n.packages??{}).toSorted();return{clone_mode:Vg(`clone_mode`,n,e.settings),description:n.description,key:t,...r?.last_fetched_at===void 0?{}:{last_fetched_at:r.last_fetched_at},missing:!U(B(e.home,il.parse(t))),...e.includePackages?{packages:a}:{},packages_count:a.length,stale:RS(r?.last_fetched_at,i,e.now)}},US=e=>{let t={home:e.home,includePackages:e.includePackages,now:e.now,settings:e.config.settings,state:e.state};return Object.entries(e.config.refs).map(([e,n])=>HS(t,e,n)).toSorted((e,t)=>e.key.localeCompare(t.key))},WS=async(e,t,n)=>{let r=z(e.env),i=await V(r),a=await Wg(r);return US({config:i,home:r,includePackages:t,now:n,state:a})},GS=(e,t)=>[`ref: ${e.key}`,`description: ${e.description}`,...VS({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale})],KS=(e,t)=>e.length===0?[`no refs configured — run: refs add <source>`]:e.reduce((e,n,r)=>(r>0&&e.push(``),e.push(...GS(n,t)),e),[]),qS=e=>e.split(`/`),JS=(e,t)=>{let n=qS(e);if(t.length>n.length)return!1;let r=n.length-t.length;return t.every((e,t)=>e===n[r+t])},YS=(e,t)=>{if(Object.hasOwn(e.refs,t))return il.parse(t);let n=qS(t),r=Object.keys(e.refs).filter(e=>JS(e,n)).toSorted(),[i]=r;if(i===void 0)throw _(`no ref matches '${t}'`);if(r.length>1)throw v(`'${t}' matches more than one ref: ${r.join(`, `)}`);return il.parse(i)},XS=(e,t)=>{e.command(`list`).description(`List configured refs with their staleness/missing checkout status.`).option(`--packages`,`include each ref's package names in --json output (off by default)`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let n=Date.now(),i=await WS(t,e.packages===!0,n);Z(t,r,KS(i,n),i)})()})},ZS=e=>e===void 0?null:e,QS=(e,t)=>e.name===t.name&&e.path===t.path,$S=(e,t)=>{let n=(e.declined_packages??[]).filter(e=>!QS(e,t));if(n.length===0){let{declined_packages:t,...n}=e;return n}return{...e,declined_packages:n}},eC=(e,t)=>`package '${e.name}' at '${e.path}' is already declined on ref '${t}'`,tC=(e,t)=>`package '${e.name}' at '${e.path}' is not declined on ref '${t}' — nothing to undo`,nC=(e,t)=>`package '${e}' is registered on ref '${t}' — declining applies to packages the configuration does not have; unregister it first with --remove`,rC=(e,t,n)=>{if(Object.hasOwn(e.packages??{},t.name))throw y(nC(t.name,n));let r=e.declined_packages??[];if(r.some(e=>QS(e,t)))throw y(eC(t,n));return{...e,declined_packages:[...r,t]}},iC=e=>{if(e.declined)return rC(e.entry,e.record,e.key);if(!(e.entry.declined_packages??[]).some(t=>QS(t,e.record)))throw y(tC(e.record,e.key));return $S(e.entry,e.record)},aC=(e,t)=>{let n=z(e.env);return G(n,`home`,async()=>{let e=await V(n),r=YS(e,t.query),i=PS(e,r),a={name:t.packageName,path:t.path},o=iC({declined:t.declined,entry:i,key:r,record:a});return await fu(n,{...e,refs:{...e.refs,[r]:o}}),{declined:t.declined,field:`declined_packages`,key:r,new:t.declined?a:null,old:t.declined?null:a}})},oC=`packages`,sC=()=>Object.keys(hl.shape).toSorted().join(`, `),cC=e=>`unknown package field '${e}' — valid fields: ${sC()}`,lC=e=>Object.hasOwn(hl.shape,e),uC=(e,t,n)=>{if(!lC(t))throw v(cC(t));let r=e[t],i=hl.safeParse({...e,[t]:n});if(!i.success)throw y(T(i.error));return{field:t,newValue:i.data[t],oldValue:r,updated:i.data}},dC=async e=>{let t=IS(e.entry,e.key,e.packageName),n=uC(t,e.field,e.value),r={...e.entry,packages:{...e.entry.packages,[e.packageName]:n.updated}};return await fu(e.home,{...e.config,refs:{...e.config.refs,[e.key]:r}}),{field:n.field,key:e.key,new:ZS(n.newValue),old:ZS(n.oldValue)}},fC=(e,t)=>`package '${e}' is already registered on ref '${t}' — edit its fields instead`,pC=(e,t)=>{let n=z(e.env);return G(n,`home`,async()=>{let e=await V(n),r=YS(e,t.query),i=PS(e,r);if(Object.hasOwn(i.packages??{},t.packageName))throw y(fC(t.packageName,r));let a=gl.safeParse({...$S(i,{name:t.packageName,path:t.path}),packages:{...i.packages,[t.packageName]:{description:t.description,path:t.path}}});if(!a.success)throw y(T(a.error));return await fu(n,{...e,refs:{...e.refs,[r]:a.data}}),{created:!0,field:oC,key:r,new:{description:t.description,name:t.packageName,path:t.path},old:null}})},mC=(e,t)=>`package '${e}' is not registered on ref '${t}' — nothing to remove`,hC=(e,t)=>{let n=z(e.env);return G(n,`home`,async()=>{let e=await V(n),r=YS(e,t.query),i=PS(e,r),a=i.packages??{};if(!Object.hasOwn(a,t.packageName))throw y(mC(t.packageName,r));let{[t.packageName]:o,...s}=a,c=Object.keys(s).length===0?gC(i):{...i,packages:s};return await fu(n,{...e,refs:{...e.refs,[r]:c}}),{field:oC,key:r,new:null,old:{description:o?.description??``,name:t.packageName,path:o?.path??``},removed:!0}})},gC=e=>{let{packages:t,...n}=e;return n},_C=e=>e.second===void 0&&e.value===void 0,vC=e=>{let{description:t,path:n}=e.create,{packageName:r}=e;if(r===void 0||t===void 0||n===void 0||!_C(e))throw v(`--create registers a new package: it needs --package <name>, --path <path> and --description <text>, and takes no <field> <value> arguments`);return{description:t,packageName:r,path:n}},yC=e=>{let{packageName:t}=e;if(t===void 0||e.create.path!==void 0||!_C(e)||e.create.description!==void 0)throw v(`--remove unregisters a package: it needs --package <name>, and takes no <field> <value> arguments, no --path and no --description`);return{packageName:t}},bC=e=>{let{packageName:t}=e,{path:n}=e.create;if(t===void 0||n===void 0||!_C(e)||e.create.description!==void 0)throw v(`--decline and --undecline record a decision about one package at one path: each needs --package <name> and --path <path>, and takes no <field> <value> arguments and no --description`);return{packageName:t,path:n}},xC=[`create`,`remove`,`decline`,`undecline`],SC=e=>{let t=xC.filter(t=>e[t]===!0);if(t.length>1)throw v(`use one of --create, --remove, --decline or --undecline: they are different answers about the same package, and running two at once would guess which one was meant`);return t[0]},CC=(e,t,n)=>t===`create`?pC(e,{...vC(n),query:n.first}):t===`remove`?hC(e,{...yC(n),query:n.first}):aC(e,{...bC(n),declined:t===`decline`,query:n.first}),wC=`packages`,TC=()=>Object.keys(gl.shape).filter(e=>e!==wC).toSorted().join(`, `),EC=e=>`unknown ref field '${e}' — valid fields: ${TC()}`,DC=e=>Object.hasOwn(gl.shape,e),OC=(e,t,n)=>`failed to rewrite git remote at ${e} to '${W(t)}': ${n.trim()}`,kC=async(e,t)=>{if(iu(t.home,t.dest),!U(t.dest))return;let n=await e.runner.run(`git`,[`remote`,`set-url`,`--`,`origin`,t.cloneUrl],{cwd:t.dest});if(n.exitCode!==0)throw y(OC(t.dest,t.cloneUrl,n.stderr))},AC=async(e,t)=>{let n=gf(t.value,{allowFileUrls:iy(e.env)});if(n.key!==t.key)throw y(`new url derives a different key — remove and re-add instead`);let r=B(t.home,t.key);return await kC(e,{cloneUrl:n.cloneUrl,dest:r,home:t.home}),{...t.entry,url:n.cloneUrl}},jC=(e,t,n)=>{let r={...e,[t]:n},i=gl.safeParse(r);if(!i.success)throw y(T(i.error));return i.data},MC=(e,t)=>t.field===`url`?AC(e,{entry:t.entry,home:t.home,key:t.key,value:t.value}):Promise.resolve(jC(t.entry,t.field,t.value)),NC=async(e,t)=>{let{field:n}=t;if(n===wC)throw v(`use --package <name> <field> <value>`);if(!DC(n))throw v(EC(n));let r=t.entry[n],i=await MC(e,{entry:t.entry,field:n,home:t.home,key:t.key,value:t.value});return{new:i[n],old:r,updated:i}},PC=(e,t)=>{let n=z(e.env),{field:r,opts:i,query:a,value:o}=t;return G(n,`home`,async()=>{let t=await V(n),s=YS(t,a),c=PS(t,s);if(i.packageName!==void 0)return dC({config:t,entry:c,field:r,home:n,key:s,packageName:i.packageName,value:o});let l=await NC(e,{entry:c,field:r,home:n,key:s,value:o});return await fu(n,{...t,refs:{...t.refs,[s]:l.updated}}),{field:r,key:s,new:ZS(l.new),old:ZS(l.old)}})},FC=`settings`,IC=[],LC=()=>Object.keys(fl.shape).toSorted().join(`, `),RC=e=>`unknown setting '${e}' — valid settings: ${LC()}`,zC=e=>Object.hasOwn(fl.shape,e),BC=e=>`note: 'settings' addressed the global settings, not ${e} — use the full ref key to edit that ref`,VC=e=>{try{let t=YS(e,FC);return[BC(`ref '${t}'`)]}catch(e){if(e instanceof g&&e.code===`usage`)return[BC("one of several matching refs — see `refs list`")];if(e instanceof g&&e.code===`not_found`)return IC;throw e}},HC=e=>({data:{field:e.key,key:FC,new:ZS(e.parsed[e.key]),old:ZS(e.old)},warnings:VC(e.config)}),UC=(e,t)=>{let n=z(e.env);return G(n,`home`,async()=>{let e=await V(n);if(!zC(t.key))throw v(RC(t.key));let r=e.settings[t.key],i={...e.settings,[t.key]:t.value},a=fl.safeParse(i);if(!a.success)throw y(T(a.error));return await fu(n,{...e,settings:a.data}),HC({config:e,key:t.key,old:r,parsed:a.data})})},WC=[],GC=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},KC=e=>{if(e.second===void 0||e.value===void 0)throw v(`missing <field> and <value> — see 'refs edit --help'`);return{field:e.second,value:e.value}},qC=(e,t,n)=>{if(t.opts.packageName!==void 0)throw v(`--package is not valid with 'refs edit settings ...' — it only applies to ref/package edits`);return UC(e,n)},JC=async(e,t)=>{if(t.create.description!==void 0||t.create.path!==void 0)throw v(`--path and --description only apply to the package modes — to change one field of a registered package use: refs edit <ref> <field> <value> --package <name>`);let{field:n,value:r}=KC(t);return t.first===`settings`?qC(e,t,{key:n,value:r}):{data:await PC(e,{field:n,opts:t.opts,query:t.first,value:r}),warnings:WC}},YC=async(e,t)=>{let n=SC(t.create);return n===void 0?JC(e,t):{data:await CC(e,n,{create:t.create,first:t.first,packageName:t.opts.packageName,second:t.second,value:t.value}),warnings:WC}},XC=e=>e==null?`(unset)`:String(e),ZC=(e,t)=>{let n=t?e.new:e.old,r=t?`declined`:`no longer declining`;return`${e.key}: ${r} '${n.name}' at ${n.path}`},QC=e=>{if(e.created===!0){let t=e.new;return`${e.key}: registered '${t.name}' at ${t.path}`}if(e.removed===!0){let t=e.old;return`${e.key}: unregistered '${t.name}' (was at ${t.path})`}return e.declined===void 0?void 0:ZC(e,e.declined)},$C=e=>{let t=QC(e);return t===void 0?[`${e.key}: ${e.field} '${XC(e.old)}' -> '${XC(e.new)}'`]:[t]},ew=(e,t)=>{e.command(`edit`).description(`Edit one field: 'refs edit settings <key> <value>' for a global setting, or 'refs edit <ref> <field> <value> [--package <name>]' for a ref or package field. With --create, registers a package the config does not have yet; with --remove, unregisters one it has; with --decline, records that a package the checkout declares is deliberately not registered, so drift stops reporting it.`).argument(`<ref-or-settings>`,`a ref key/unique suffix, or the literal 'settings'`).argument(`[field-or-key]`,`field to edit (or, in settings mode, the setting key)`).argument(`[value]`,`the new value`).option(`--package <name>`,`edit this package's field instead of a top-level ref field`).option(`--create`,`register --package as a new package on this ref`).option(`--remove`,`unregister --package from this ref, leaving the checkout alone`).option(`--decline`,`record that --package at --path is deliberately not registered`).option(`--undecline`,`withdraw a decline, so the package is reported again`).option(`--path <path>`,`with --create/--decline/--undecline: the package path, relative to the checkout root`).option(`--description <text>`,`with --create: what the package is`).action((e,n,r,i,a)=>{let o=X(a);return Q(t,o,async()=>{let{data:a,warnings:s}=await YC(t,{create:i,first:e,opts:GC(i),second:n,value:r});Z(t,o,$C(a),a,s)})()})},tw=`Install the agent skill: npx skills add kaisers-io/refs (from a local clone: npx skills add <path-to-this-repo> --skill refs)`,nw={migrated:`migrated`,noop:`unchanged`,seeded:`seeded`},rw=async e=>{await a(e.root,{recursive:!0}),await a(e.sourcesDir,{recursive:!0}),await a(e.locksDir,{recursive:!0}),await a(e.hooksDir,{recursive:!0})},iw=async e=>{let t=z(e.env);return await rw(t),{config:await G(t,`home`,async()=>{let e=await Su(t,fv);return await Nd(t),e}),home:t.root,skill_hint:tw}},aw=(e,t)=>{e.command(`init`).description(`Seed or migrate the refs home directory, its config, and the git hooks guard.`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await iw(t);Z(t,r,[`home: ${e.home}`,`config: ${nw[e.config]}`,``,tw],e)})()})},ow=async e=>{let t=z(e.env),n=await G(t,`home`,()=>Su(t,fv));return n===`migrated`?{backup:eu(t),result:n}:{backup:null,result:n}},sw=e=>e.result===`migrated`&&e.backup!==null?`config migrated (backup: ${re(e.backup)})`:e.result===`seeded`?`config seeded`:`config up to date`,cw=(e,t)=>{e.command(`migrate`).description(`Migrate the refs config to the current schema, seeding it if absent.`).action((e,n)=>{let r=X(n);return Q(t,r,async()=>{let e=await ow(t);Z(t,r,sw(e),e)})()})},lw=async e=>{try{return await i(e),!0}catch(e){if(R(e))return!1;throw e}},uw=async e=>{try{return await c(e)}catch(e){if(R(e))return;throw e}},dw=async e=>{try{return(await i(e)).isDirectory()}catch(e){if(R(e))return;throw e}},fw=async e=>{let t=await uw(e);if(t===void 0)return!0;if(t.length>0)return!1;try{await f(e)}catch(e){if(!R(e))throw e}return!0},pw=async e=>{let t=await dw(e);return t===void 0?!0:t?fw(e):!1},mw=async(e,t)=>{t!==e.sourcesDir&&await pw(t)&&await mw(e,ie(t))},hw=async(e,t)=>await lw(t)?(iu(e,t),await d(t,{force:!0,recursive:!0}),await mw(e,ie(t)),{removedCheckout:!0}):{removedCheckout:!1,warning:`checkout was already missing`},gw=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),_w=async(e,t)=>{let n=await V(e),r={...n,refs:gw(n.refs,t)};await fu(e,r);let i=await Wg(e),a={...i,refs:gw(i.refs,t)};await Gg(e,a)},vw=async(e,t)=>{let n=z(e.env),r=await V(n),i=YS(r,t),a=B(n,i),{removedCheckout:o,warning:s}=await G(n,ry(i),()=>hw(n,a));return await G(n,`home`,()=>_w(n,i)),{data:{key:i,removed_checkout:o},warnings:Mv(s)}},yw=e=>e.removed_checkout?[`removed ${e.key} (checkout deleted)`]:[`removed ${e.key} (checkout was already missing)`],bw=(e,t)=>{e.command(`remove`).description(`Remove a configured ref: its config/state entry AND its checkout directory.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let{data:n,warnings:r}=await vw(t,e);Z(t,i,yw(n),n,r)})()})},xw=async e=>{let t=await Qh(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:Sw(e)},Sw=async e=>bx(e,await dv(e.checkoutDir)),Cw=async e=>{try{return await G(e.home,ry(e.key),()=>xw(e),e.lockTimeoutMs===void 0?void 0:{timeoutMs:e.lockTimeoutMs})}catch(t){if(t instanceof g&&t.code===`conflict`)return{path:e.configuredPath,reason:`could not acquire the ref lock in time`,status:`unverifiable`};throw t}},ww=async e=>{if(!U(e.checkoutDir))return{path:e.configuredPath,status:`unmaterialized`};let t=await Qh(e.checkoutDir,e.configuredPath,e.packageName);return t.kind===`match`?{path:e.configuredPath,status:`verified`}:t.kind===`unreadable`?{path:e.configuredPath,reason:t.reason,status:`unverifiable`}:(e.onProbed?.(),Cw(e))},Tw=(e,t)=>({local_path:null,name:e,path:null,reason:t,status:`unverifiable`}),Ew=async e=>{if(!e.checkoutManaged)return Tw(e.packageName,e.checkoutReason);let t=await ww(e),n=(t.status===`verified`||t.status===`relocated`)&&t.path!==null?await Fg(m(e.checkoutDir,t.path),e.packageName):void 0;return{...t.candidates===void 0?{}:{candidates:t.candidates},...t.configuredPath===void 0?{}:{configured_path:t.configuredPath},...n===void 0?{}:{entry_points:n},local_path:t.path===null?null:m(e.checkoutDir,t.path),name:e.packageName,path:t.path,...t.reason===void 0?{}:{reason:t.reason},status:t.status}},Dw=e=>e.kind===`target`?[{observed:e.observed,target:e.target}]:e.kind===`alternatives`?e.alternatives.flatMap(e=>Dw(e)):e.kind===`conditions`?e.branches.flatMap(e=>Dw(e.value)):[],Ow=e=>{if(e.length===0)return[];let t=e.filter(e=>e.observed===`not_checked`||e.observed===`unverifiable`).length,n=e.length-t,r=t===0?``:`, ${t} not inspected`;return n===0?[`entry points: none of the ${e.length} declared target(s) was inspected`]:[`entry points: ${n} declared target(s) absent here${r}`]},kw=e=>{if(e.status!==`complete`)return[`entry points: could not be read (${e.reason??`unknown`})`];let t=e.entries.flatMap(e=>Dw(e.value)),n=t.filter(e=>e.observed===`file`||e.observed===`directory`);if(n.length===0)return Ow(t);let r=n.slice(0,3).map(e=>e.target),i=n.length-r.length;return[`entry points present: ${r.join(`, `)}${i===0?``:` (+${i} more)`}`]},Aw=e=>[`package: ${e.name}`,`package path: ${e.local_path??`(unknown)`}`,...e.status===`verified`?[]:[`package status: ${e.status}`],...e.configured_path===void 0?[]:[`configured path: ${e.configured_path}`],...e.candidates===void 0?[]:[`candidates: ${e.candidates.join(`, `)}`],...e.reason===void 0?[]:[`reason: ${e.reason}`],...e.entry_points===void 0?[]:kw(e.entry_points)],jw=`node_modules`,Mw=[`.pnp.cjs`,`.pnp.js`],Nw=new Set([``,`.`,`..`]),Pw=e=>!ae(e)&&!e.includes(`\\`)&&e.split(`/`).every(e=>!Nw.has(e)),Fw=function*(e){let t=ce(e);for(;;){re(t)!==jw&&(yield m(t,jw));let e=ie(t);if(e===t)return;t=e}},Iw=async e=>{if(await zw(e)!==`absent`)try{let t=JSON.parse(await s(e,`utf8`)),{name:n,version:r}=typeof t==`object`&&t?t:{};return typeof r!=`string`||r===``?{package_json:e,reason:`manifest_has_no_version`,status:`unverifiable`}:{...typeof n==`string`?{name:n}:{},package_json:e,status:`found`,version:r}}catch{return{package_json:e,reason:`manifest_unreadable`,status:`unverifiable`}}},Lw=new Set([`ENOENT`,`ENOTDIR`]),Rw=async e=>{try{return(await c(e)).length===0}catch{return!1}},zw=async e=>{try{return await p(e),`present`}catch(e){let t=typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0;return t!==void 0&&Lw.has(t)?`absent`:`unreadable`}},Bw=async e=>{for(let t of Fw(e)){let e=ie(t);if((await Promise.all(Mw.map(t=>zw(m(e,t))))).includes(`present`))return!0}return!1},Vw=async e=>{try{if(!(await p(e)).isDirectory())throw v(`--project must be a directory: ${e}`)}catch(t){throw t instanceof Error&&t.message.startsWith(`--project`)?t:v(`--project path does not exist: ${e}`)}},Hw=async e=>{let t=await zw(e);if(t===`unreadable`)return{reason:`slot_unreadable`,status:`unverifiable`};if(t===`absent`)return;let n=await Iw(m(e,`package.json`));return n===void 0?await Rw(e)?void 0:{reason:`installed_without_manifest`,status:`unverifiable`}:n},Uw=async(e,t)=>{if(!Pw(t))return{reason:`unsupported_package_name`,status:`unverifiable`};for(let n of Fw(e)){let e=await Hw(m(n,...t.split(`/`)));if(e!==void 0)return e}return await Bw(e)?{reason:`yarn_pnp`,status:`unsupported_layout`}:{status:`not_materialized`}},Ww={'"':`"`,"\\":`\\`,b:`\b`,n:`
|
|
351
|
+
`,t:` `},Gw={'"':`"`,"\\":`\\`},Kw=new Set([` `,` `]),$=Symbol(`malformed git config`),qw=e=>e!==void 0&&!e.quoted&&Kw.has(e.char),Jw=e=>{let t=0,n=e.length;for(;t<n&&qw(e[t]);)t+=1;for(;n>t&&qw(e[n-1]);)--n;return e.slice(t,n).map(e=>e.char).join(``)},Yw=e=>{let t=[],n=!1;for(let r=0;r<e.length;r+=1){let i=e[r];if(i===`\\`){r+=1;let n=Ww[e[r]??``];if(n===void 0)return $;t.push({char:n,quoted:!0})}else if(i===`"`)n=!n;else if(!n&&(i===`#`||i===`;`))return Jw(t);else t.push({char:i??``,quoted:n})}return n?$:Jw(t)},Xw=e=>{let t=``;for(let n=0;n<e.length;n+=1){let r=e[n];if(r===`\\`){n+=1;let r=Gw[e[n]??``];if(r===void 0)return $;t+=r}else t+=r??``}return t},Zw=/^[ \t]+|[ \t]+$/gu,Qw=e=>e.replace(Zw,``),$w=/^\[[ \t]*(?<section>[A-Za-z0-9.-]+)[ \t]*(?:"(?<subsection>(?:[^"\\]|\\.)*)")?[ \t]*\]/u,eT=/^(?<name>[A-Za-z][A-Za-z0-9-]*)[ \t]*(?:=[ \t]*(?<value>.*))?$/u,tT=function*(e){let t=``,n=!1,r=!1;for(let i=0;i<e.length;i+=1){let a=e[i];if(a===`
|
|
352
352
|
`)yield t,t=``,n=!1,r=!1;else if(a!==`\r`||e[i+1]!==`
|
|
353
353
|
`){if(r)t+=a;else if(a===`\\`){let n=e[i+1];n===`
|
|
354
354
|
`||n===`\r`&&e[i+2]===`
|
|
355
|
-
`?i+=n===`\r`?2:1:(t+=a+(n??``),i+=1)}else a===`"`?n=!n:!n&&(a===`#`||a===`;`)&&(r=!0),t+=a}}t!==``&&(yield t)},Nw=(e,t)=>e.subsection===void 0?`${e.name}.${t.toLowerCase()}`:`${e.name}.${e.subsection}.${t.toLowerCase()}`,Pw=(e,t)=>{let n=e.toLowerCase();if(t===void 0)return{name:n};let r=Dw(t);return r===$?$:{name:n,subsection:r}},Fw=e=>{let t=Aw.exec(e),n=t?.groups?.section;if(n===void 0)return;let r=kw(e.slice(t?.[0].length??0)),i=Pw(n,t?.groups?.subsection);return i===$?$:{rest:r,section:i}},Iw=e=>e===``||e.startsWith(`#`)||e.startsWith(`;`),Lw=e=>{let t=jw.exec(e),n=t?.groups?.name;if(n===void 0)return $;let r=Ew(t?.groups?.value??``);return r===$?$:{name:n,value:r}},Rw=(e,t)=>{let n=Lw(t.line);if(n===$)return`malformed`;let r=Nw(t.section,n.name);return t.wanted.includes(r)&&e.set(r,[...e.get(r)??[],n.value]),`ok`},zw=(e,t,n)=>t.rest===``||Iw(t.rest)?t.section:Rw(e,{line:t.rest,section:t.section,wanted:n})===`malformed`?$:t.section,Bw=(e,t)=>{let n=Fw(t.line);return n===$?$:n===void 0?t.section===Vw||Rw(e,t)===`malformed`?$:t.section:zw(e,n,t.wanted)},Vw={name:``},Hw=(e,t)=>{let n=new Map,r=Vw;for(let i of Mw(e)){let e=kw(i),a=Iw(e)?r:Bw(n,{line:e,section:r,wanted:t});if(a===$)return;r=a}return n},Uw=`core.hookspath`,Ww=`remote.origin.url`,Gw=[Uw,Ww],Kw={status:`managed`},qw={status:`missing`},Jw=e=>({reason:e,status:`unmanaged`}),Yw=e=>({reason:e,status:`unverifiable`}),Xw=new Set([`ENOENT`,`ENOTDIR`]),Zw=e=>typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0,Qw=async e=>{try{return await i(e),`present`}catch(e){let t=Zw(e);return t!==void 0&&Xw.has(t)?`absent`:`unreadable`}},$w=async e=>{try{let t=await i(m(e,`.git`));return t.isSymbolicLink()?Jw(`git_is_symlink`):t.isDirectory()?void 0:Jw(`git_is_file`)}catch(e){let t=Zw(e);return t!==void 0&&Xw.has(t)?Jw(`no_git`):Yw(`git_unreadable`)}},eT=(e,t)=>{let n=e.get(t);if(n===void 0||n.length!==1)return;let[r]=n;return r===void 0||r===``?void 0:r},tT=(e,t,n)=>{try{return _f(e,{allowFileUrls:n}).key===_f(t,{allowFileUrls:n}).key}catch{return!1}},nT=e=>(e.get(Uw)?.length??0)>1||(e.get(Ww)?.length??0)>1,rT=(e,t)=>{let n=Hw(e,Gw);return n===void 0?Yw(`config_malformed`):nT(n)?Yw(`duplicate_config_values`):iT(n,t)},iT=(e,t)=>{if(eT(e,Uw)!==t.hooksDir)return Jw(`no_refs_marker`);let n=eT(e,Ww);return n===void 0?Jw(`no_origin`):tT(n,t.expectedUrl,t.allowFileUrls)?Kw:Jw(`origin_mismatch`)},aT={missing:qw,outside:Jw(`outside_sources`),unreadable:Yw(`path_unreadable`)},oT=async e=>{let t=await Ou(e.sourcesDir,e.dest);if(t.kind!==`inside`)return t.kind===`unreadable`?await Qw(e.sourcesDir)===`absent`?qw:aT.unreadable:aT[t.kind]},sT=async e=>{let t=await oT(e);if(t!==void 0)return t;let n=await $w(e.dest);if(n!==void 0)return n;try{return rT(await s(m(e.dest,`.git`,`config`),`utf8`),e)}catch{return Yw(`config_unreadable`)}},cT=e=>`no registered package or ref matches '${e}' — this does not establish that the repository is untracked; it may be registered under a different identifier. Run: refs list --json`,lT=e=>`ref '${e}' is not in the active refs configuration — to track it: refs add <url>`,uT=e=>`--ref '${e}' matched no configured ref — pass a full ref key or a unique suffix of one. Run: refs list --json`,dT=/^[a-z][a-z0-9+.-]*:\/\//iu,fT=/^git@[^:/\s]+:[^\s]+$/u,pT=e=>dT.test(e)||fT.test(e),mT=(e,t)=>{try{return _f(e,t)}catch{if(pT(e))throw y(`query looks like a git url but is not a supported form — check the url (credentials are never accepted) or run: refs resolve <package|ref-suffix>`);return}},hT=(e,t,n)=>{let r=mT(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw _(lT(r.key),`ref_not_registered`)}},gT=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages?.[t];i!==void 0&&n.push({entry:i,key:il.parse(r)})}return n},_T=(e,t)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — pick one with: refs resolve ${e} --ref <ref>`,vT=(e,t)=>{let n=gT(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw v(_T(t,n.map(e=>e.key)));return r}},yT=function*(e){let t=e.split(`/`);for(let e=t.length-1;e>=1;--e)yield t.slice(0,e).join(`/`)},bT=(e,t)=>{for(let n of yT(t)){let t=vT(e,n);if(t!==void 0)return{...t,name:n}}},xT=(e,t,n)=>{try{return kS(e,t)}catch(e){throw e instanceof g&&e.code===`not_found`?_(n,`unmatched_query`):e}},ST=(e,t)=>{let n=e[t];if(n!==void 0)return{entry:n,name:t};for(let n of yT(t)){let t=e[n];if(t!==void 0)return{entry:t,name:n}}},CT=(e,t,n)=>{let r=xT(e,n,uT(n)),i=ST(e.refs[r]?.packages??{},t);if(i===void 0)throw _(pT(t)?`ref '${r}' is tracked but registers no package matching that query — inspect: refs show ${r} --packages --json`:`ref '${r}' is tracked but registers no package matching '${t}' — inspect: refs show ${r} --packages --json`,`package_not_registered`);return{key:r,packageMatch:{...i,key:r}}},wT=(e,t,n)=>{let r=hT(e,t,n);if(r!==void 0)return r;let i=vT(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=bT(e,t);return a===void 0?{key:xT(e,t,cT(t))}:{key:a.key,packageMatch:a}},TT=(e,t,n)=>n.ref===void 0?wT(e,t,n):CT(e,t,n.ref),ET=(e,t)=>{let n={head_sha:t.headSha,last_fetched_at:new Date().toISOString()},r=t.effectiveCloneMode??e?.effective_clone_mode;return r!==void 0&&(n.effective_clone_mode=r),n},DT=async(e,t,n)=>{let r=await V(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await fu(e,r))},OT=(e,t,n)=>W(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await DT(e,t,n.branchRenamedTo);let r=await Pg(e);r.refs[t]=ET(r.refs[t],n),await Fg(e,r)}),kT=2e3,AT=e=>{if(e.length<=kT)return e;let t=e.slice(0,1500),n=e.slice(e.length-500),r=e.length-kT;return`${t}\n… ${String(r)} characters omitted …\n${n}`},jT=async(e,t,n)=>{try{await W(e,`home`,async()=>{let r=await Pg(e);r.refs[t]={...r.refs[t],last_error:AT(n)},await Fg(e,r)})}catch{}},MT=e=>{let t=0,n=[];return{acquire:()=>{if(t<e)return t+=1,Promise.resolve();let{promise:r,resolve:i}=Promise.withResolvers();return n.push(()=>{t+=1,i()}),r},release:()=>{--t;let e=n.shift();e!==void 0&&e()}}},NT=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},PT=(e,t,n)=>`sync produced a HEAD sha for '${e}' at ${t} that refs cannot store yet (${n.length} hex chars) — only SHA-1 repositories are supported for now`,FT=(e,t,n)=>{if(!kg.shape.head_sha.safeParse(n).success)throw y(PT(e,t,n));return n},IT=(e,t,n)=>{let r={effectiveCloneMode:t.effectiveMode,headSha:n.headSha,status:`cloned`};return n.actualBranch!==e.ref.default_branch&&(r.branchRenamedTo=n.actualBranch),t.warning!==void 0&&(r.warning=t.warning),r},LT=async(e,t,n)=>{await a(ie(n),{recursive:!0});let r=jg(`clone_mode`,t.ref,t.settings),i=await Cd(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),o=await Td(e.runner,n),s=await vy(e.runner,{allowFileUrls:qv(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return IT(t,i,{actualBranch:o,headSha:s})},RT=async(e,t,n)=>{await py(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await dy(e.runner,{allowFileUrls:qv(e.env),dest:n,expectedUrl:t.ref.url});let r=await jd(e.runner,{defaultBranch:t.ref.default_branch,dir:n}),i={headSha:FT(t.key,n,r.newSha),previousSha:r.oldSha,status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},zT=(e,t,n)=>(iu(t.home,n),H(n)?RT(e,t,n):LT(e,t,n)),BT={changedDirs:[],kind:`arrivals`,namesBefore:[]},VT=async(e,t,n)=>{if(n.previousSha===void 0)return BT;let r=await dd(e.runner,{dir:t,from:n.previousSha,to:n.headSha});return r===void 0?BT:{...r,kind:`arrivals`}},HT=(e,t)=>W(t.home,Kv(t.key),async()=>{let n=B(t.home,t.key),r=await zT(e,t,n),i=await VT(e,n,r);return{...r,structure:await cx(n,t.ref,i)}}),UT=e=>{let t=[];e.branchRenamedTo!==void 0&&t.push(`default branch renamed to ${e.branchRenamedTo}`),e.warning!==void 0&&t.push(e.warning);let[n]=t;if(n!==void 0)return t.join(` | `)},WT=(e,t)=>{let n={key:e,status:t.status},r=UT(t);return r!==void 0&&(n.warning=r),t.structure!==void 0&&(n.structure=t.structure),n},GT=async(e,t)=>{try{let n=await HT(e,t);return await OT(t.home,t.key,n),n}catch(e){throw await jT(t.home,t.key,Cv(e)),e}},KT=async(e,t)=>{try{return WT(t.key,await GT(e,t))}catch(e){return{error:Cv(e),key:t.key,status:`failed`}}},qT=(e,t)=>e.status===`rejected`?{error:Cv(e.reason),key:t,status:`failed`}:e.value,JT=async(e,t)=>{let n=MT(4);return(await Promise.allSettled(t.map(t=>NT(n,()=>KT(e,t))))).map((e,n)=>{let r=t[n];if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return qT(e,r.key)})},YT=async e=>{let{packageMatch:t}=e.match;return t===void 0?null:await ow({checkoutDir:e.dest,checkoutManaged:e.checkout.status===`managed`||e.checkout.status===`missing`,checkoutReason:`checkout is ${e.checkout.status}`,configuredPath:t.entry.path,home:e.home,key:e.match.key,packageName:t.name})},XT=(e,t,n)=>TT(t,n.query,{allowFileUrls:qv(e.env),...n.ref===void 0?{}:{ref:n.ref}}),ZT=async(e,t)=>{let n=z(e.env),r=await V(n);return{config:r,home:n,match:XT(e,r,t),state:await Pg(n)}},QT=async(e,t)=>{if(t===void 0)return;let{packageMatch:n}=e;if(n===void 0)throw v(`--project needs a query that names a package; '${e.key}' resolves to the ref itself`);return await bw(t,n.name)},$T=(e,t)=>{if(e.status!==`managed`&&e.status!==`missing`)throw y(`refusing to sync ${t}: its checkout is ${e.status}${e.reason===void 0?``:` (${e.reason})`} — run: refs doctor`)},eE=async(e,t)=>(await GT(e,{home:t.home,key:t.match.key,ref:mS(t.config,t.match.key),settings:t.config.settings})).status,tE=async(e,t)=>{t.project!==void 0&&await vw(t.project);let n=await ZT(e,t),r=await rE(e,n,t);return t.syncIfStale!==!0||!(r.stale||r.missing)?r:($T(r.checkout,r.key),await nE(e,{key:r.key,opts:t,target:n}))},nE=async(e,t)=>{let{key:n,opts:r}=t,i=await eE(e,t.target),a=await ZT(e,r);if(a.match.key!==n)throw Ce(`configuration changed while resolving '${r.query}' — retry`);return{...await rE(e,a,r),sync:{status:i}}},rE=async(e,t,n)=>{let{config:r,home:i,match:a,state:o}=t,{now:s}=n,c=mS(r,a.key),l=B(i,a.key),u=ol(jg(`sync_ttl`,c,r.settings)),d=o.refs[a.key]?.last_fetched_at,f=await sT({allowFileUrls:qv(e.env),dest:l,expectedUrl:c.url,hooksDir:i.hooksDir,sourcesDir:i.sourcesDir}),p=await QT(a,n.project);return{checkout:f,key:a.key,...d===void 0?{}:{last_fetched_at:d},...p===void 0?{}:{installed:p},local_path:l,missing:f.status===`missing`,package:await YT({checkout:f,dest:l,home:i,match:a}),stale:vS(d,u,s)}},iE=(e,t)=>{let n=[`ref: ${e.key}`,`path: ${e.local_path}`,...xS({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale}),...e.checkout.status===`managed`||e.checkout.status===`missing`?[]:[`checkout: ${e.checkout.status}${e.checkout.reason===void 0?``:` (${e.checkout.reason})`}`]];return e.package!==null&&n.push(...sw(e.package)),e.sync!==void 0&&n.push(`sync: ${e.sync.status}`),e.installed!==void 0&&n.push(`installed: ${e.installed.version??`(${e.installed.status})`}`,...e.installed.name===void 0?[]:[`installed name: ${e.installed.name}`],...e.installed.reason===void 0?[]:[`installed reason: ${e.installed.reason}`]),n},aE=(e,t,n)=>({now:t,...n.project===void 0?{}:{project:n.project},query:e,...n.ref===void 0?{}:{ref:n.ref},...n.syncIfStale===!0?{syncIfStale:!0}:{}}),oE=(e,t)=>{e.command(`resolve`).description(`Resolve a git url, npm package name, import path, or ref-key suffix to its ref/package.`).argument(`<query>`,`git url, npm package name, import path, or unique ref-key suffix`).option(`--ref <ref>`,`resolve the query as a package within this ref (full key or unique suffix)`).option(`--project <dir>`,`report the version this project has installed of the query's package`).option(`--sync-if-stale`,`fetch or clone first when the ref is stale or its checkout is absent`).action((e,n,r)=>{let i=Y(r);return Z(t,i,async()=>{let r=Date.now(),a=await tE(t,aE(e,r,n));X(t,i,iE(a,r),a)})()})},sE={},cE=async(e,t)=>{if(!H(t))return{tags:[]};try{let{tags:n}=await Fd(e.runner,t,5);return{tags:n}}catch(e){return{tags:[],warning:`could not list tags: ${Cv(e)}`}}},lE=async(e,t,n,r)=>{let i=z(e.env),a=await V(i),o=kS(a,t),s=mS(a,o),c=await Pg(i),l=B(i,o),{packages:u,...d}=s,f=n.tags?await cE(e,l):void 0,p=c.refs[o]??sE;return{data:{...d,key:o,local_path:l,missing:!H(l),...n.packages?{packages:u??{}}:{},packages_count:Object.keys(u??{}).length,...f===void 0?{}:{sample_tags:f.tags},stale:vS(p.last_fetched_at,ol(jg(`sync_ttl`,s,a.settings)),r),state:p},warnings:Sv(f?.warning)}},uE=(e,t)=>{let n=[`ref: ${e.key}`,`description: ${e.description}`,`url: ${e.url}`,`path: ${e.local_path}`,...xS({lastFetchedAt:e.state.last_fetched_at,missing:e.missing,now:t,stale:e.stale})];return e.sample_tags!==void 0&&e.sample_tags.length>0&&n.push(`tags: ${e.sample_tags.join(`, `)}`),n},dE=(e,t)=>{e.command(`show`).description(`Show a configured ref: entry, state, local path, package count; --packages/--tags add the package map and sample tags to --json.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).option(`--packages`,`include the ref's full package map in --json output (off by default)`).option(`--tags`,`include sample tags in --json output (human output always probes for them)`).action((e,n,r)=>{let i=Y(r);return Z(t,i,async()=>{let r={packages:n.packages===!0,tags:!i.json||n.tags===!0},a=Date.now(),{data:o,warnings:s}=await lE(t,e,r,a);X(t,i,uE(o,a),o,s)})()})},fE=(e,t,n)=>({home:e,key:n,ref:mS(t,n),settings:t.settings}),pE=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>fE(e,t,il.parse(n))):n.map(n=>fE(e,t,kS(t,n))),mE=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=ol(jg(`sync_ttl`,t.ref,t.settings)),a=vS(n.refs[t.key]?.last_fetched_at,i,r),o=!H(B(e,t.key));return a||o})},hE=async(e,t,n)=>{if(!e_({env:e.env,updates:n.updates}))return[];let{latest:r,refreshed:i}=await Kg({fetch:e.fetcher,home:t,nowMs:Date.now()});return!i||r===void 0||!qg(e.cliVersion,r)?[]:[Jg(e.cliVersion,r)]},gE=async(e,t,n)=>{if(!n)return t;let r=await Pg(e);return mE(e,t,r)},_E=async(e,t)=>{let n=z(e.env),r=await V(n),i=pE(n,r,t.refs),a=await gE(n,i,t.staleOnly),[o,s]=await Promise.all([JT(e,a),a.length>0?hE(e,n,r):Promise.resolve([])]);return{failedCount:o.filter(e=>e.status===`failed`).length,results:o,warnings:s}},vE=[`updated`,`fresh`,`cloned`,`restored`,`failed`],yE={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},bE=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},xE=e=>{if(e.status===`failed`)return[` ${e.key}: ${e.error??`unknown error`}`];let t=e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`;return e.structure===void 0?[t]:[t,...Ub(e.structure,e.key).map(e=>` ${e}`)]},SE=e=>{let t=bE(e),n=[vE.map(e=>`${yE[e]} (${t[e].length})`).join(` / `)];for(let e of vE)for(let r of t[e])n.push(...xE(r));return n},CE=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),wE=(e,t)=>{e.command(`sync`).description(`Fetch (or re-clone, if the checkout is missing) configured refs — all by default.`).argument(`[refs...]`,`ref keys or unique suffixes to sync (default: every configured ref)`).option(`--stale-only`,`skip refs whose last sync is still within their ref's sync_ttl`).action((e,n,r)=>{let i=Y(r);return Z(t,i,async()=>{let r=await _E(t,CE(e,n));X(t,i,SE(r.results),{results:r.results},r.warnings),r.failedCount>0&&(process.exitCode=Se.UNEXPECTED)})()})},TE=(e,t,n)=>n===void 0?e.tag_format:gS(e,t,n).tag_format??e.tag_format,EE=(e,t,n)=>{if(e!==void 0)return e;let r=n===void 0?`ref '${t}'`:`package '${n}'`,i=n===void 0?[]:[`--package=${Q(n)}`];throw y(`${r} has no tag_format configured — inspect the repository's real tags and set one with: ${Ev(i,[t,`tag_format`,`<format>`])}`)},DE=async(e,t)=>{let n=z(e.env),r=await V(n),i=kS(r,t.query),a=mS(r,i),o=EE(TE(a,i,t.opts.packageName),i,t.opts.packageName),s=B(n,i);hS(s,i);let c=await qd(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},OE=e=>[`${e.key}@${e.version} -> ${e.tag}`],kE=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},AE=[zC,nb,PC,AS,pS,HC,ew,oE,dE,wE,(e,t)=>{e.command(`tag`).description(`Resolve a version to its git tag, via the ref's (or a package's) tag_format.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).argument(`<version>`,`version to resolve, e.g. 4.1.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=Y(i);return Z(t,a,async()=>{let i=await DE(t,{opts:kE(r),query:e,version:n});X(t,a,OE(i),i)})()})}],jE=(e,t)=>{for(let n of AE)n(e,t)},ME=[``,`Examples:`,` $ refs list --json`,` $ refs sync --stale-only --json`,` $ refs resolve zod/mini --json`,``,`Every command accepts --json for structured output and --verbose for stack traces on error.`].join(`
|
|
356
|
-
`),
|
|
355
|
+
`?i+=n===`\r`?2:1:(t+=a+(n??``),i+=1)}else a===`"`?n=!n:!n&&(a===`#`||a===`;`)&&(r=!0),t+=a}}t!==``&&(yield t)},nT=(e,t)=>e.subsection===void 0?`${e.name}.${t.toLowerCase()}`:`${e.name}.${e.subsection}.${t.toLowerCase()}`,rT=(e,t)=>{let n=e.toLowerCase();if(t===void 0)return{name:n};let r=Xw(t);return r===$?$:{name:n,subsection:r}},iT=e=>{let t=$w.exec(e),n=t?.groups?.section;if(n===void 0)return;let r=Qw(e.slice(t?.[0].length??0)),i=rT(n,t?.groups?.subsection);return i===$?$:{rest:r,section:i}},aT=e=>e===``||e.startsWith(`#`)||e.startsWith(`;`),oT=e=>{let t=eT.exec(e),n=t?.groups?.name;if(n===void 0)return $;let r=Yw(t?.groups?.value??``);return r===$?$:{name:n,value:r}},sT=(e,t)=>{let n=oT(t.line);if(n===$)return`malformed`;let r=nT(t.section,n.name);return t.wanted.includes(r)&&e.set(r,[...e.get(r)??[],n.value]),`ok`},cT=(e,t,n)=>t.rest===``||aT(t.rest)?t.section:sT(e,{line:t.rest,section:t.section,wanted:n})===`malformed`?$:t.section,lT=(e,t)=>{let n=iT(t.line);return n===$?$:n===void 0?t.section===uT||sT(e,t)===`malformed`?$:t.section:cT(e,n,t.wanted)},uT={name:``},dT=(e,t)=>{let n=new Map,r=uT;for(let i of tT(e)){let e=Qw(i),a=aT(e)?r:lT(n,{line:e,section:r,wanted:t});if(a===$)return;r=a}return n},fT=`core.hookspath`,pT=`remote.origin.url`,mT=[fT,pT],hT={status:`managed`},gT={status:`missing`},_T=e=>({reason:e,status:`unmanaged`}),vT=e=>({reason:e,status:`unverifiable`}),yT=new Set([`ENOENT`,`ENOTDIR`]),bT=e=>typeof e==`object`&&e&&`code`in e&&typeof e.code==`string`?e.code:void 0,xT=async e=>{try{return await i(e),`present`}catch(e){let t=bT(e);return t!==void 0&&yT.has(t)?`absent`:`unreadable`}},ST=async e=>{try{let t=await i(m(e,`.git`));return t.isSymbolicLink()?_T(`git_is_symlink`):t.isDirectory()?void 0:_T(`git_is_file`)}catch(e){let t=bT(e);return t!==void 0&&yT.has(t)?_T(`no_git`):vT(`git_unreadable`)}},CT=(e,t)=>{let n=e.get(t);if(n===void 0||n.length!==1)return;let[r]=n;return r===void 0||r===``?void 0:r},wT=(e,t,n)=>{try{return gf(e,{allowFileUrls:n}).key===gf(t,{allowFileUrls:n}).key}catch{return!1}},TT=e=>(e.get(fT)?.length??0)>1||(e.get(pT)?.length??0)>1,ET=(e,t)=>{let n=dT(e,mT);return n===void 0?vT(`config_malformed`):TT(n)?vT(`duplicate_config_values`):DT(n,t)},DT=(e,t)=>{if(CT(e,fT)!==t.hooksDir)return _T(`no_refs_marker`);let n=CT(e,pT);return n===void 0?_T(`no_origin`):wT(n,t.expectedUrl,t.allowFileUrls)?hT:_T(`origin_mismatch`)},OT={missing:gT,outside:_T(`outside_sources`),unreadable:vT(`path_unreadable`)},kT=async e=>{let t=await H(e.sourcesDir,e.dest);if(t.kind!==`inside`)return t.kind===`unreadable`?await xT(e.sourcesDir)===`absent`?gT:OT.unreadable:OT[t.kind]},AT=async e=>{let t=await kT(e);if(t!==void 0)return t;let n=await ST(e.dest);if(n!==void 0)return n;try{return ET(await s(m(e.dest,`.git`,`config`),`utf8`),e)}catch{return vT(`config_unreadable`)}},jT=e=>`no registered package or ref matches '${e}' — this does not establish that the repository is untracked; it may be registered under a different identifier. Run: refs list --json`,MT=e=>`ref '${e}' is not in the active refs configuration — to track it: refs add <url>`,NT=e=>`--ref '${e}' matched no configured ref — pass a full ref key or a unique suffix of one. Run: refs list --json`,PT=/^[a-z][a-z0-9+.-]*:\/\//iu,FT=/^git@[^:/\s]+:[^\s]+$/u,IT=e=>PT.test(e)||FT.test(e),LT=(e,t)=>{try{return gf(e,t)}catch{if(IT(e))throw y(`query looks like a git url but is not a supported form — check the url (credentials are never accepted) or run: refs resolve <package|ref-suffix>`);return}},RT=(e,t,n)=>{let r=LT(t,n);if(r!==void 0){if(Object.hasOwn(e.refs,r.key))return{key:r.key};throw _(MT(r.key),`ref_not_registered`)}},zT=(e,t)=>{let n=[];for(let r of Object.keys(e.refs).toSorted()){let i=e.refs[r]?.packages?.[t];i!==void 0&&n.push({entry:i,key:il.parse(r)})}return n},BT=(e,t)=>`package '${e}' is registered by more than one ref: ${t.join(`, `)} — pick one with: refs resolve ${e} --ref <ref>`,VT=(e,t)=>{let n=zT(e,t),[r]=n;if(r!==void 0){if(n.length>1)throw v(BT(t,n.map(e=>e.key)));return r}},HT=function*(e){let t=e.split(`/`);for(let e=t.length-1;e>=1;--e)yield t.slice(0,e).join(`/`)},UT=(e,t)=>{for(let n of HT(t)){let t=VT(e,n);if(t!==void 0)return{...t,name:n}}},WT=(e,t,n)=>{try{return YS(e,t)}catch(e){throw e instanceof g&&e.code===`not_found`?_(n,`unmatched_query`):e}},GT=(e,t)=>{let n=e[t];if(n!==void 0)return{entry:n,name:t};for(let n of HT(t)){let t=e[n];if(t!==void 0)return{entry:t,name:n}}},KT=(e,t,n)=>{let r=WT(e,n,NT(n)),i=GT(e.refs[r]?.packages??{},t);if(i===void 0)throw _(IT(t)?`ref '${r}' is tracked but registers no package matching that query — inspect: refs show ${r} --packages --json`:`ref '${r}' is tracked but registers no package matching '${t}' — inspect: refs show ${r} --packages --json`,`package_not_registered`);return{key:r,packageMatch:{...i,key:r}}},qT=(e,t,n)=>{let r=RT(e,t,n);if(r!==void 0)return r;let i=VT(e,t);if(i!==void 0)return{key:i.key,packageMatch:{...i,name:t}};let a=UT(e,t);return a===void 0?{key:WT(e,t,jT(t))}:{key:a.key,packageMatch:a}},JT=(e,t,n)=>n.ref===void 0?qT(e,t,n):KT(e,t,n.ref),YT=(e,t)=>{let n={head_sha:t.headSha,last_fetched_at:new Date().toISOString()},r=t.effectiveCloneMode??e?.effective_clone_mode;return r!==void 0&&(n.effective_clone_mode=r),n},XT=async(e,t,n)=>{let r=await V(e),i=r.refs[t];i!==void 0&&(r.refs[t]={...i,default_branch:n},await fu(e,r))},ZT=(e,t,n)=>G(e,`home`,async()=>{n.branchRenamedTo!==void 0&&await XT(e,t,n.branchRenamedTo);let r=await Wg(e);r.refs[t]=YT(r.refs[t],n),await Gg(e,r)}),QT=2e3,$T=e=>{if(e.length<=QT)return e;let t=e.slice(0,1500),n=e.slice(e.length-500),r=e.length-QT;return`${t}\n… ${String(r)} characters omitted …\n${n}`},eE=async(e,t,n)=>{try{await G(e,`home`,async()=>{let r=await Wg(e);r.refs[t]={...r.refs[t],last_error:$T(n)},await Gg(e,r)})}catch{}},tE=e=>{let t=0,n=[];return{acquire:()=>{if(t<e)return t+=1,Promise.resolve();let{promise:r,resolve:i}=Promise.withResolvers();return n.push(()=>{t+=1,i()}),r},release:()=>{--t;let e=n.shift();e!==void 0&&e()}}},nE=async(e,t)=>{await e.acquire();try{return await t()}finally{e.release()}},rE=(e,t,n)=>`sync produced a HEAD sha for '${e}' at ${t} that refs cannot store yet (${n.length} hex chars) — only SHA-1 repositories are supported for now`,iE=(e,t,n)=>{if(!zg.shape.head_sha.safeParse(n).success)throw y(rE(e,t,n));return n},aE=(e,t,n)=>{let r={effectiveCloneMode:t.effectiveMode,headSha:n.headSha,status:`cloned`};return n.actualBranch!==e.ref.default_branch&&(r.branchRenamedTo=n.actualBranch),t.warning!==void 0&&(r.warning=t.warning),r},oE=async(e,t,n)=>{await a(ie(n),{recursive:!0});let r=Vg(`clone_mode`,t.ref,t.settings),i=await Sd(e.runner,{cloneUrl:t.ref.url,dest:n,hooksDir:t.home.hooksDir,mode:r}),o=await wd(e.runner,n),s=await ky(e.runner,{allowFileUrls:iy(e.env),dest:n,expectedUrl:t.ref.url,hooksDir:t.home.hooksDir,key:t.key});return aE(t,i,{actualBranch:o,headSha:s})},sE=async(e,t,n)=>{await wy(e.runner,{dest:n,hooksDir:t.home.hooksDir}),await Sy(e.runner,{allowFileUrls:iy(e.env),dest:n,expectedUrl:t.ref.url});let r=await Ad(e.runner,{defaultBranch:t.ref.default_branch,dir:n}),i={headSha:iE(t.key,n,r.newSha),previousSha:r.oldSha,status:r.status};return r.branchRenamedTo!==void 0&&(i.branchRenamedTo=r.branchRenamedTo),r.warning!==void 0&&(i.warning=r.warning),i},cE=(e,t,n)=>(iu(t.home,n),U(n)?sE(e,t,n):oE(e,t,n)),lE={changedDirs:[],kind:`arrivals`,namesBefore:[]},uE=async(e,t,n)=>{if(n.previousSha===void 0)return lE;let r=await ud(e.runner,{dir:t,from:n.previousSha,to:n.headSha});return r===void 0?lE:{...r,kind:`arrivals`}},dE=(e,t)=>G(t.home,ry(t.key),async()=>{let n=B(t.home,t.key),r=await cE(e,t,n),i=await uE(e,n,r);return{...r,structure:await Dx(n,t.ref,i)}}),fE=e=>{let t=[];e.branchRenamedTo!==void 0&&t.push(`default branch renamed to ${e.branchRenamedTo}`),e.warning!==void 0&&t.push(e.warning);let[n]=t;if(n!==void 0)return t.join(` | `)},pE=(e,t)=>{let n={key:e,status:t.status},r=fE(t);return r!==void 0&&(n.warning=r),t.structure!==void 0&&(n.structure=t.structure),n},mE=async(e,t)=>{try{let n=await dE(e,t);return await ZT(t.home,t.key,n),n}catch(e){throw await eE(t.home,t.key,Nv(e)),e}},hE=async(e,t)=>{try{return pE(t.key,await mE(e,t))}catch(e){return{error:Nv(e),key:t.key,status:`failed`}}},gE=(e,t)=>e.status===`rejected`?{error:Nv(e.reason),key:t,status:`failed`}:e.value,_E=async(e,t)=>{let n=tE(4);return(await Promise.allSettled(t.map(t=>nE(n,()=>hE(e,t))))).map((e,n)=>{let r=t[n];if(r===void 0)throw Error(`internal: sync target at index ${n} is missing`);return gE(e,r.key)})},vE=async e=>{let{packageMatch:t}=e.match;return t===void 0?null:await Ew({checkoutDir:e.dest,checkoutManaged:e.checkout.status===`managed`||e.checkout.status===`missing`,checkoutReason:`checkout is ${e.checkout.status}`,configuredPath:t.entry.path,home:e.home,key:e.match.key,packageName:t.name})},yE=(e,t,n)=>JT(t,n.query,{allowFileUrls:iy(e.env),...n.ref===void 0?{}:{ref:n.ref}}),bE=async(e,t)=>{let n=z(e.env),r=await V(n);return{config:r,home:n,match:yE(e,r,t),state:await Wg(n)}},xE=async(e,t)=>{if(t===void 0)return;let{packageMatch:n}=e;if(n===void 0)throw v(`--project needs a query that names a package; '${e.key}' resolves to the ref itself`);return await Uw(t,n.name)},SE=(e,t)=>{if(e.status!==`managed`&&e.status!==`missing`)throw y(`refusing to sync ${t}: its checkout is ${e.status}${e.reason===void 0?``:` (${e.reason})`} — run: refs doctor`)},CE=async(e,t)=>(await mE(e,{home:t.home,key:t.match.key,ref:PS(t.config,t.match.key),settings:t.config.settings})).status,wE=async(e,t)=>{t.project!==void 0&&await Vw(t.project);let n=await bE(e,t),r=await EE(e,n,t);return t.syncIfStale!==!0||!(r.stale||r.missing)?r:(SE(r.checkout,r.key),await TE(e,{key:r.key,opts:t,target:n}))},TE=async(e,t)=>{let{key:n,opts:r}=t,i=await CE(e,t.target),a=await bE(e,r);if(a.match.key!==n)throw Ce(`configuration changed while resolving '${r.query}' — retry`);return{...await EE(e,a,r),sync:{status:i}}},EE=async(e,t,n)=>{let{config:r,home:i,match:a,state:o}=t,{now:s}=n,c=PS(r,a.key),l=B(i,a.key),u=ol(Vg(`sync_ttl`,c,r.settings)),d=o.refs[a.key]?.last_fetched_at,f=await AT({allowFileUrls:iy(e.env),dest:l,expectedUrl:c.url,hooksDir:i.hooksDir,sourcesDir:i.sourcesDir}),p=await xE(a,n.project);return{checkout:f,key:a.key,...d===void 0?{}:{last_fetched_at:d},...p===void 0?{}:{installed:p},local_path:l,missing:f.status===`missing`,package:await vE({checkout:f,dest:l,home:i,match:a}),stale:RS(d,u,s)}},DE=(e,t)=>{let n=[`ref: ${e.key}`,`path: ${e.local_path}`,...VS({lastFetchedAt:e.last_fetched_at,missing:e.missing,now:t,stale:e.stale}),...e.checkout.status===`managed`||e.checkout.status===`missing`?[]:[`checkout: ${e.checkout.status}${e.checkout.reason===void 0?``:` (${e.checkout.reason})`}`]];return e.package!==null&&n.push(...Aw(e.package)),e.sync!==void 0&&n.push(`sync: ${e.sync.status}`),e.installed!==void 0&&n.push(`installed: ${e.installed.version??`(${e.installed.status})`}`,...e.installed.name===void 0?[]:[`installed name: ${e.installed.name}`],...e.installed.reason===void 0?[]:[`installed reason: ${e.installed.reason}`]),n},OE=(e,t,n)=>({now:t,...n.project===void 0?{}:{project:n.project},query:e,...n.ref===void 0?{}:{ref:n.ref},...n.syncIfStale===!0?{syncIfStale:!0}:{}}),kE=(e,t)=>{e.command(`resolve`).description(`Resolve a git url, npm package name, import path, or ref-key suffix to its ref/package.`).argument(`<query>`,`git url, npm package name, import path, or unique ref-key suffix`).option(`--ref <ref>`,`resolve the query as a package within this ref (full key or unique suffix)`).option(`--project <dir>`,`report the version this project has installed of the query's package`).option(`--sync-if-stale`,`fetch or clone first when the ref is stale or its checkout is absent`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=Date.now(),a=await wE(t,OE(e,r,n));Z(t,i,DE(a,r),a)})()})},AE={},jE=async(e,t)=>{if(!U(t))return{tags:[]};try{let{tags:n}=await Pd(e.runner,t,5);return{tags:n}}catch(e){return{tags:[],warning:`could not list tags: ${Nv(e)}`}}},ME=async(e,t,n,r)=>{let i=z(e.env),a=await V(i),o=YS(a,t),s=PS(a,o),c=await Wg(i),l=B(i,o),{packages:u,...d}=s,f=n.tags?await jE(e,l):void 0,p=c.refs[o]??AE;return{data:{...d,key:o,local_path:l,missing:!U(l),...n.packages?{packages:u??{}}:{},packages_count:Object.keys(u??{}).length,...f===void 0?{}:{sample_tags:f.tags},stale:RS(p.last_fetched_at,ol(Vg(`sync_ttl`,s,a.settings)),r),state:p},warnings:Mv(f?.warning)}},NE=(e,t)=>{let n=[`ref: ${e.key}`,`description: ${e.description}`,`url: ${e.url}`,`path: ${e.local_path}`,...VS({lastFetchedAt:e.state.last_fetched_at,missing:e.missing,now:t,stale:e.stale})];return e.sample_tags!==void 0&&e.sample_tags.length>0&&n.push(`tags: ${e.sample_tags.join(`, `)}`),n},PE=(e,t)=>{e.command(`show`).description(`Show a configured ref: entry, state, local path, package count; --packages/--tags add the package map and sample tags to --json.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).option(`--packages`,`include the ref's full package map in --json output (off by default)`).option(`--tags`,`include sample tags in --json output (human output always probes for them)`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r={packages:n.packages===!0,tags:!i.json||n.tags===!0},a=Date.now(),{data:o,warnings:s}=await ME(t,e,r,a);Z(t,i,NE(o,a),o,s)})()})},FE=(e,t,n)=>({home:e,key:n,ref:PS(t,n),settings:t.settings}),IE=(e,t,n)=>n.length===0?Object.keys(t.refs).toSorted().map(n=>FE(e,t,il.parse(n))):n.map(n=>FE(e,t,YS(t,n))),LE=(e,t,n)=>{let r=Date.now();return t.filter(t=>{let i=ol(Vg(`sync_ttl`,t.ref,t.settings)),a=RS(n.refs[t.key]?.last_fetched_at,i,r),o=!U(B(e,t.key));return a||o})},RE=async(e,t,n)=>{if(!u_({env:e.env,updates:n.updates}))return[];let{latest:r,refreshed:i}=await n_({fetch:e.fetcher,home:t,nowMs:Date.now()});return!i||r===void 0||!r_(e.cliVersion,r)?[]:[i_(e.cliVersion,r)]},zE=async(e,t,n)=>{if(!n)return t;let r=await Wg(e);return LE(e,t,r)},BE=async(e,t)=>{let n=z(e.env),r=await V(n),i=IE(n,r,t.refs),a=await zE(n,i,t.staleOnly),[o,s]=await Promise.all([_E(e,a),a.length>0?RE(e,n,r):Promise.resolve([])]);return{failedCount:o.filter(e=>e.status===`failed`).length,results:o,warnings:s}},VE=[`updated`,`fresh`,`cloned`,`restored`,`failed`],HE={cloned:`Cloned`,failed:`Failed`,fresh:`Fresh`,restored:`Restored`,updated:`Updated`},UE=e=>{let t={cloned:[],failed:[],fresh:[],restored:[],updated:[]};for(let n of e)t[n.status].push(n);return t},WE=e=>{if(e.status===`failed`)return[` ${e.key}: ${e.error??`unknown error`}`];let t=e.warning===void 0?` ${e.key}`:` ${e.key} (${e.warning})`;return e.structure===void 0?[t]:[t,...ix(e.structure,e.key).map(e=>` ${e}`)]},GE=e=>{let t=UE(e),n=[VE.map(e=>`${HE[e]} (${t[e].length})`).join(` / `)];for(let e of VE)for(let r of t[e])n.push(...WE(r));return n},KE=(e,t)=>({refs:e,staleOnly:t.staleOnly===!0}),qE=(e,t)=>{e.command(`sync`).description(`Fetch (or re-clone, if the checkout is missing) configured refs — all by default.`).argument(`[refs...]`,`ref keys or unique suffixes to sync (default: every configured ref)`).option(`--stale-only`,`skip refs whose last sync is still within their ref's sync_ttl`).action((e,n,r)=>{let i=X(r);return Q(t,i,async()=>{let r=await BE(t,KE(e,n));Z(t,i,GE(r.results),{results:r.results},r.warnings),r.failedCount>0&&(process.exitCode=Se.UNEXPECTED)})()})},JE=(e,t,n)=>n===void 0?e.tag_format:IS(e,t,n).tag_format??e.tag_format,YE=(e,t,n)=>{if(e!==void 0)return e;let r=n===void 0?`ref '${t}'`:`package '${n}'`,i=n===void 0?[]:[`--package=${Iv(n)}`];throw y(`${r} has no tag_format configured — inspect the repository's real tags and set one with: ${Lv(i,[t,`tag_format`,`<format>`])}`)},XE=async(e,t)=>{let n=z(e.env),r=await V(n),i=YS(r,t.query),a=PS(r,i),o=YE(JE(a,i,t.opts.packageName),i,t.opts.packageName),s=B(n,i);FS(s,i);let c=await Kd(e.runner,s,o,t.version);return{key:i,ref_path:`refs/tags/${c}`,tag:c,version:t.version}},ZE=e=>[`${e.key}@${e.version} -> ${e.tag}`],QE=e=>{let t={};return e.package!==void 0&&(t.packageName=e.package),t},$E=[aw,pb,ew,XS,NS,cw,bw,kE,PE,qE,(e,t)=>{e.command(`tag`).description(`Resolve a version to its git tag, via the ref's (or a package's) tag_format.`).argument(`<ref>`,`full ref key or a unique suffix, e.g. zod`).argument(`<version>`,`version to resolve, e.g. 4.1.0`).option(`--package <name>`,`resolve against this package's tag_format instead of the ref's`).action((e,n,r,i)=>{let a=X(i);return Q(t,a,async()=>{let i=await XE(t,{opts:QE(r),query:e,version:n});Z(t,a,ZE(i),i)})()})}],eD=(e,t)=>{for(let n of $E)n(e,t)},tD=[``,`Examples:`,` $ refs list --json`,` $ refs sync --stale-only --json`,` $ refs resolve zod/mini --json`,``,`Every command accepts --json for structured output and --verbose for stack traces on error.`].join(`
|
|
356
|
+
`),nD=new Set([`commander.help`,`commander.helpDisplayed`,`commander.version`]),rD=`--json`,iD=`--verbose`,aD=/\n$/u,oD=/^error: /u,sD=e=>e.replace(oD,``),cD=(e,t)=>{for(let n of e){if(n===`--`)return!1;if(n===t)return!0}return!1},lD=e=>cD(e,rD),uD=e=>cD(e,iD),dD=(e,t,n)=>n&&t!==void 0?`${e}\n${t}`:e,fD=e=>{let t=new Dv().name(`refs`).description(`Manage git-based reference checkouts shared across a workspace.`).version(fv).option(rD,`emit machine-readable JSON on stdout instead of human-readable text`).option(iD,`include stack traces in error output`).allowExcessArguments(!1).exitOverride().configureOutput({outputError:()=>{},writeErr:t=>{e.errLine(t.replace(aD,``))},writeOut:t=>{e.out(t.replace(aD,``))}});return t.addHelpText(`after`,tD),eD(t,e),t},pD=()=>{process.exitCode=Se.OK},mD=(e,t,n)=>{let r={code:`usage`,message:dD(sD(n.message),n.stack,t.verbose)};Pv(e,t,r),process.exitCode=Se.USAGE},hD=(e,t,n)=>{if(nD.has(n.code)){pD();return}mD(e,t,n)},gD=(e,t,n)=>{let r=Te(n,{verbose:t.verbose});Pv(e,t,r),process.exitCode=r.exitCode},_D=async(e,t,n)=>{let r={json:lD(n),verbose:uD(n)};try{await t.parseAsync(n)}catch(t){if(t instanceof gv){hD(e,r,t);return}gD(e,r,t)}},vD=(e,t)=>_D(e,fD(e),t);import.meta.main&&await vD(hv(),process.argv);export{fD as buildProgram,X as cliOptsOf,Z as emit,Pv as emitError,Nv as errorMessageOf,Fv as progress,hv as realContext,eD as registerCommands,vD as run,_D as runProgram,Mv as warningsFor,Q as wrapAction};
|