@visulima/vis 1.0.0-alpha.2 → 1.0.0-alpha.20
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 +830 -14
- package/LICENSE.md +7667 -0
- package/README.md +322 -19
- package/dist/bin.js +1 -146
- package/dist/config/index.d.ts +2795 -0
- package/dist/config/index.js +1 -0
- package/dist/generate/index.d.ts +157 -0
- package/dist/generate/index.js +1 -0
- package/dist/packem_chunks/bin.js +1295 -0
- package/dist/packem_chunks/config.js +19 -0
- package/dist/packem_chunks/doctor-probe.js +2 -0
- package/dist/packem_chunks/fix.js +11 -0
- package/dist/packem_chunks/handler.js +1 -0
- package/dist/packem_chunks/handler10.js +1 -0
- package/dist/packem_chunks/handler11.js +5 -0
- package/dist/packem_chunks/handler12.js +1 -0
- package/dist/packem_chunks/handler13.js +27 -0
- package/dist/packem_chunks/handler14.js +5 -0
- package/dist/packem_chunks/handler15.js +1 -0
- package/dist/packem_chunks/handler16.js +1 -0
- package/dist/packem_chunks/handler17.js +1 -0
- package/dist/packem_chunks/handler18.js +1 -0
- package/dist/packem_chunks/handler19.js +1 -0
- package/dist/packem_chunks/handler2.js +2 -0
- package/dist/packem_chunks/handler20.js +5 -0
- package/dist/packem_chunks/handler21.js +2 -0
- package/dist/packem_chunks/handler22.js +2 -0
- package/dist/packem_chunks/handler23.js +18 -0
- package/dist/packem_chunks/handler24.js +1 -0
- package/dist/packem_chunks/handler25.js +1 -0
- package/dist/packem_chunks/handler26.js +5 -0
- package/dist/packem_chunks/handler27.js +1 -0
- package/dist/packem_chunks/handler28.js +3 -0
- package/dist/packem_chunks/handler29.js +1 -0
- package/dist/packem_chunks/handler3.js +4 -0
- package/dist/packem_chunks/handler30.js +7 -0
- package/dist/packem_chunks/handler31.js +33 -0
- package/dist/packem_chunks/handler32.js +3 -0
- package/dist/packem_chunks/handler33.js +1 -0
- package/dist/packem_chunks/handler34.js +26 -0
- package/dist/packem_chunks/handler35.js +3 -0
- package/dist/packem_chunks/handler36.js +7 -0
- package/dist/packem_chunks/handler37.js +22 -0
- package/dist/packem_chunks/handler38.js +428 -0
- package/dist/packem_chunks/handler39.js +6 -0
- package/dist/packem_chunks/handler4.js +8 -0
- package/dist/packem_chunks/handler40.js +24 -0
- package/dist/packem_chunks/handler41.js +10 -0
- package/dist/packem_chunks/handler42.js +153 -0
- package/dist/packem_chunks/handler43.js +25 -0
- package/dist/packem_chunks/handler44.js +24 -0
- package/dist/packem_chunks/handler45.js +213 -0
- package/dist/packem_chunks/handler46.js +3 -0
- package/dist/packem_chunks/handler47.js +27 -0
- package/dist/packem_chunks/handler48.js +167 -0
- package/dist/packem_chunks/handler49.js +34 -0
- package/dist/packem_chunks/handler5.js +1 -0
- package/dist/packem_chunks/handler6.js +1 -0
- package/dist/packem_chunks/handler7.js +1 -0
- package/dist/packem_chunks/handler8.js +1 -0
- package/dist/packem_chunks/handler9.js +2 -0
- package/dist/packem_chunks/heal-accept.js +10 -0
- package/dist/packem_chunks/heal.js +14 -0
- package/dist/packem_chunks/help-command.js +18 -0
- package/dist/packem_chunks/index.js +7 -0
- package/dist/packem_chunks/keys-refresh.js +4 -0
- package/dist/packem_chunks/list.js +3 -0
- package/dist/packem_chunks/loader.js +1 -0
- package/dist/packem_chunks/prune.js +3 -0
- package/dist/packem_chunks/run.js +1 -0
- package/dist/packem_chunks/status.js +2 -0
- package/dist/packem_chunks/sync.js +2 -0
- package/dist/packem_chunks/sync2.js +2 -0
- package/dist/packem_chunks/tar.js +3 -0
- package/dist/packem_chunks/tripwire.js +2 -0
- package/dist/packem_shared/advisories-DsynpacV.js +1 -0
- package/dist/packem_shared/ai-analysis-uYuTIIXi.js +68 -0
- package/dist/packem_shared/ai-cache-DuwHYx2O.js +1 -0
- package/dist/packem_shared/ai-fix-DzrA-dVz.js +43 -0
- package/dist/packem_shared/applyDefaults-BOVDw1jD.js +1 -0
- package/dist/packem_shared/build-scripts-DsWMSWDs.js +1 -0
- package/dist/packem_shared/cache-directory-DQak1Vjc.js +1 -0
- package/dist/packem_shared/cyclonedx-CiHXuG8M.js +4 -0
- package/dist/packem_shared/definePlugin-CWm4Dv_t.js +1 -0
- package/dist/packem_shared/dependency-scan-DC3nAFHS.js +1 -0
- package/dist/packem_shared/docker-B-CIN_nj.js +60 -0
- package/dist/packem_shared/failure-log-C3LEMmkq.js +2 -0
- package/dist/packem_shared/flakiness-Dq6K4ymq.js +1 -0
- package/dist/packem_shared/giget-CcEy_Elm.js +2 -0
- package/dist/packem_shared/glob-MHJQjR39-CQ2GC0b_.js +1 -0
- package/dist/packem_shared/index-DH-5hsrC.js +1 -0
- package/dist/packem_shared/lifecycle-Dv3nAtoD.js +2 -0
- package/dist/packem_shared/lockfile-C5DYMHVq.js +1 -0
- package/dist/packem_shared/manifests-B0fMp872.js +1 -0
- package/dist/packem_shared/min-release-age-BFozFonQ.js +34 -0
- package/dist/packem_shared/native-config-sync-Dvi1g2nQ.js +21 -0
- package/dist/packem_shared/otelPlugin-CJR2T_lk.js +1 -0
- package/dist/packem_shared/registry-keys-CewRFW0e.js +1 -0
- package/dist/packem_shared/resolve-explicit-CC4Kifk5.js +5 -0
- package/dist/packem_shared/run-summary-utils-BaBGP3bo.js +1 -0
- package/dist/packem_shared/runtime-check-BusAwPb2.js +1 -0
- package/dist/packem_shared/scan-progress-CMynp3eA.js +2 -0
- package/dist/packem_shared/selectors-B2ISH581.js +3 -0
- package/dist/packem_shared/signatures-5ZdjJ2Pu.js +2 -0
- package/dist/packem_shared/symbols-CQmER5MT.js +1 -0
- package/dist/packem_shared/toolchain-Cc3cwyLP.js +5 -0
- package/dist/packem_shared/typosquats-BCeR-sLf.js +1 -0
- package/dist/packem_shared/use-measured-height-DjYgUOKk.js +1 -0
- package/dist/packem_shared/utils-DrNg0XTR.js +1 -0
- package/dist/packem_shared/verify-07kUNTuP.js +1 -0
- package/dist/packem_shared/vis-update-app-CFrlJ3mW.js +1 -0
- package/dist/packem_shared/xxh3-DrAUNq4n.js +1 -0
- package/index.d.ts +358 -0
- package/index.js +609 -0
- package/package.json +57 -22
- package/schemas/project.schema.json +872 -0
- package/schemas/vis-config.schema.json +4306 -0
- package/skills/vis/SKILL.md +96 -0
- package/templates/buildkite-ci/.buildkite/pipeline.yml.tera +85 -0
- package/templates/buildkite-ci/template.yml +20 -0
- package/dist/ai-analysis.d.ts +0 -40
- package/dist/ai-cache.d.ts +0 -21
- package/dist/bin.d.ts +0 -1
- package/dist/catalog.d.ts +0 -110
- package/dist/commands/affected.d.ts +0 -3
- package/dist/commands/ai.d.ts +0 -3
- package/dist/commands/analyze.d.ts +0 -3
- package/dist/commands/check.d.ts +0 -3
- package/dist/commands/graph.d.ts +0 -3
- package/dist/commands/hook/constants.d.ts +0 -8
- package/dist/commands/hook/index.d.ts +0 -3
- package/dist/commands/hook/install.d.ts +0 -7
- package/dist/commands/hook/migrate.d.ts +0 -27
- package/dist/commands/hook/uninstall.d.ts +0 -3
- package/dist/commands/migrate/constants.d.ts +0 -12
- package/dist/commands/migrate/deps.d.ts +0 -32
- package/dist/commands/migrate/index.d.ts +0 -3
- package/dist/commands/migrate/json.d.ts +0 -20
- package/dist/commands/migrate/lint-staged.d.ts +0 -62
- package/dist/commands/migrate/types.d.ts +0 -20
- package/dist/commands/run.d.ts +0 -3
- package/dist/commands/staged.d.ts +0 -3
- package/dist/commands/update.d.ts +0 -3
- package/dist/config.d.ts +0 -40
- package/dist/config.js +0 -1
- package/dist/package-manager.d.ts +0 -23
- package/dist/workspace.d.ts +0 -58
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var h=Object.defineProperty;var g=(r,n)=>h(r,"name",{value:n,configurable:!0});import{r as m}from"../packem_shared/toolchain-Cc3cwyLP.js";var C=Object.defineProperty,a=g((r,n)=>C(r,"name",{value:n,configurable:!0}),"a");const u=a(()=>process.env.GITHUB_BASE_REF?{base:`origin/${process.env.GITHUB_BASE_REF}`,head:process.env.GITHUB_SHA??"HEAD"}:process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME?{base:`origin/${process.env.CI_MERGE_REQUEST_TARGET_BRANCH_NAME}`,head:process.env.CI_COMMIT_SHA??"HEAD"}:process.env.BUILDKITE_PULL_REQUEST_BASE_BRANCH?{base:`origin/${process.env.BUILDKITE_PULL_REQUEST_BASE_BRANCH}`,head:process.env.BUILDKITE_COMMIT??"HEAD"}:process.env.CIRCLE_BRANCH&&process.env.CIRCLE_SHA1?{base:"origin/main",head:process.env.CIRCLE_SHA1}:{base:"origin/main",head:"HEAD"},"detectCiRefs"),A=a(async({argument:r,logger:n,options:e,runtime:s,visConfig:f,workspaceRoot:t})=>{const p=r[0];if(!p)throw new Error("Missing targets. Usage: vis ci <target>[,<target>…]");const l=p.split(",").map(o=>o.trim()).filter(Boolean);if(l.length===0)throw new Error("Missing targets. Usage: vis ci <target>[,<target>…]");if(!t)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const{base:_,head:d}=u(),c=e.base??_,E=e.head??d;e.skipToolchain||n.info("▸ Toolchain pre-flight"),await m(t,f?.toolchain,{error:a(o=>{n.error(o)},"error"),info:a(o=>{n.info(o)},"info"),warn:a(o=>{n.warn(o)},"warn")},!!e.skipToolchain),e.install===!1?n.info("▸ Skipping install (--no-install)"):(n.info("▸ Installing dependencies"),await s.runCommand("install",{argv:["--ci","--frozen-lockfile"]}));for(const o of l){n.info(`▸ Running affected ${o} (base=${c}, head=${E})`);const i=[o,`--base=${c}`,`--head=${E}`,`--upstream=${String(e.upstream??"none")}`,`--downstream=${String(e.downstream??"deep")}`];e.parallel!==void 0&&i.push(`--parallel=${String(e.parallel)}`),e.partition&&i.push(`--partition=${String(e.partition)}`),e.query&&i.push(`--query=${String(e.query)}`),await s.runCommand("affected",{argv:i})}n.info("▸ CI pipeline complete")},"execute");export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty;var d=(s,o)=>m(s,"name",{value:o,configurable:!0});import{createRequire as p}from"node:module";import{M as a,i as k}from"./config.js";import{cleanWorkspace as b}from"#native";import{p as c}from"./bin.js";import{f as $}from"../packem_shared/utils-DrNg0XTR.js";const g=p(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=d(s=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[o,n]=f.versions.node.split(".").map(Number);if(o>22||o===22&&n>=3||o===20&&n>=16)return f.getBuiltinModule(s)}return g(s)},"__cjs_getBuiltinModule"),{readdirSync:v,lstatSync:y,unlinkSync:_}=h("node:fs");var R=Object.defineProperty,u=d((s,o)=>R(s,"name",{value:o,configurable:!0}),"f");const j=u(s=>{const o=[],n=[s];for(;n.length>0;){const t=n.pop();let i;try{i=v(t)}catch{continue}for(const r of i){const e=a(t,r);try{const l=y(e);if(l.isSymbolicLink()||!l.isDirectory())continue}catch{continue}r==="node_modules"?o.push(e):r!==".git"&&r!==".hg"&&n.push(e)}}return o},"findNodeModulesDirectories"),M=["pnpm-lock.yaml","package-lock.json","npm-shrinkwrap.json","yarn.lock","bun.lock","bun.lockb"],x=u((s,o,n)=>{let t=0,i=!1;for(const r of M){const e=a(s,r);if(k(e)){if(o){n.info(` ${e}`),t++;continue}try{_(e),c.success(`Removed ${e}`),t++}catch(l){c.error(`${e}: ${$(l)}`),i=!0}}}return{hadError:i,removed:t}},"removeLockfiles"),C=u(async({logger:s,options:o,workspaceRoot:n})=>{const t=n??process.cwd(),i=o.lockfile||!1;if(o.dryRun){const e=j(t);if(e.length>0){c.info("Would remove:");for(const l of e)s.info(` ${l}`)}else c.info("No node_modules directories found.");i&&x(t,!0,s);return}const r=b(t,i);for(const e of r.removed)c.success(`Removed ${e}`);for(const e of r.lockfilesRemoved)c.success(`Removed ${e}`);for(const e of r.errors)c.error(e);r.removed.length===0&&r.lockfilesRemoved.length===0?c.info("No node_modules directories found."):c.info(`Cleaned ${r.removed.length} node_modules director${r.removed.length===1?"y":"ies"}`),r.errors.length>0&&(process.exitCode=1)},"execute");export{C as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=Object.defineProperty;var s=(e,o)=>i(e,"name",{value:o,configurable:!0});import{f as l,x as p}from"./bin.js";var f=Object.defineProperty,d=s((e,o)=>f(e,"name",{value:o,configurable:!0}),"n");const u=d(async({logger:e,options:o,visConfig:a,workspaceRoot:r})=>{const c=r??process.cwd(),t=l(c,{configBackend:a?.install?.backend,configCorepack:a?.install?.corepack}),n=p(t,o.check||!1,c,e);n!==0&&(process.exitCode=n)},"execute");export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var i=(e,s)=>d(e,"name",{value:s,configurable:!0});import{f as k,g as u}from"./bin.js";var v=Object.defineProperty,x=i((e,s)=>v(e,"name",{value:s,configurable:!0}),"n");const w=x(async({argument:e,logger:s,options:a,visConfig:r,workspaceRoot:l})=>{const o=e;if(!o||o.length===0)throw new Error("No package specified. Usage: vis dlx <package[@version]> [args...]");const[g,...t]=o,n=l??process.cwd(),f=k(n,{configBackend:r?.install?.backend,configCorepack:r?.install?.corepack}),p=a.package?Array.isArray(a.package)?a.package:[a.package]:[],c=u(f,{additionalPackages:p,args:t,package:g,shellMode:a.shellMode||!1,silent:a.silent||!1},n,s,{offline:a.offline||!1});c!==0&&(process.exitCode=c)},"execute");export{w as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.defineProperty;var d=(t,o)=>g(t,"name",{value:o,configurable:!0});import{M as l}from"./config.js";import{y as v,m as h}from"./bin.js";import{s as j,p as x}from"../packem_shared/docker-B-CIN_nj.js";var E=Object.defineProperty,m=d((t,o)=>E(t,"name",{value:o,configurable:!0}),"f");const C=m(async({argument:t,logger:o,options:s,visConfig:w,workspaceRoot:e})=>{const n=t[0];if(!n)throw new Error("Missing subcommand. Usage: vis docker <scaffold|prune>");if(!e)throw new Error("Could not determine workspace root. Run inside a monorepo.");const{packageJsons:k,workspace:c}=v(e,w);if(n==="scaffold"){const a=h(e,c,k),r=s.focus;if(!r)throw new Error("Missing --focus. Pass one or more project names, comma-separated.");const f=r.split(",").map(i=>i.trim()).filter(Boolean);if(f.length===0)throw new Error("--focus resolved to an empty list. Provide at least one project name.");const u=l(e,s.out??".vis/docker"),{projects:p}=j({focus:f,includeSources:!!s.includeSources,log:m(i=>{o.info(i)},"log"),outDir:u,projectGraph:a,pruneLockfile:s.pruneLockfile!==!1,workspace:c,workspaceRoot:e});o.info(`Scaffolded ${p.length} project(s) into ${u}`),o.info(`Focus closure: ${p.toSorted().join(", ")}`);return}if(n==="prune"){const a=l(e,s.context??".vis/docker"),{removed:r}=x({contextRoot:a,workspace:c,workspaceRoot:e});o.info(`Pruned ${r.length} unfocused project(s)`),r.length>0&&o.debug?.(r.join(`
|
|
2
|
+
`));return}throw new Error(`Unknown subcommand: "${n}". Expected scaffold or prune.`)},"execute");export{C as default};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var H=Object.defineProperty;var I=(e,t)=>H(e,"name",{value:t,configurable:!0});import{createRequire as U}from"node:module";import{C as O,z as F}from"./config.js";import{d as D,P as K,R as S,w as j,p as V}from"./heal.js";import{A as q,af as Y,p as a}from"./bin.js";const P=U(import.meta.url),T=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,A=I(e=>{if(typeof T<"u"&&T.versions&&T.versions.node){const[t,o]=T.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return T.getBuiltinModule(e)}return P(e)},"__cjs_getBuiltinModule"),{readFile:B}=A("node:fs/promises"),{createInterface:M}=A("node:readline");var J=Object.defineProperty,k=I((e,t)=>J(e,"name",{value:t,configurable:!0}),"o");const z=k(()=>!!process.stdout.isTTY&&process.env.CI!=="true","isInteractive"),W=k(e=>new Promise(t=>{const o=M({input:process.stdin,output:process.stderr});o.question(`${e} (Y/n) `,i=>{o.close();const s=i.trim().toLowerCase();t(s===""||s==="y"||s==="yes")})}),"defaultPrompt"),X=k((e,t)=>{const o=q(t),i=Y(o,{exact:!1,filter:[],global:!1,optional:!1,packages:[e],peer:!1,saveDev:!1,workspace:!1,workspaceRoot:!1},t,console);return Promise.resolve({exitCode:i})},"defaultRunInstall"),y=k(e=>`pnpm add ${e}`,"installCommandFor"),Q=k(e=>e==="@gitbeaker/rest"?import("@gitbeaker/rest"):import("@octokit/rest"),"defaultImport"),L=k(async(e,t={})=>{const o=t.interactive??z(),i=t.prompt??W,s=t.runInstall??X,l=t.importImpl??Q,d=t.workspaceRoot??process.cwd();try{return await l(e)}catch(n){const{code:u}=n;if(u!=="ERR_MODULE_NOT_FOUND"&&u!=="MODULE_NOT_FOUND")throw n}if(!o)throw new Error(`${e} is not installed. \`vis ai heal accept\` needs it to talk to the host. Install it in your repo first:
|
|
2
|
+
${y(e)}`);if(!await i(`${e} isn't installed. Install it now?`))throw new Error(`${e} install declined. Re-run \`vis ai heal accept\` after installing manually:
|
|
3
|
+
${y(e)}`);const r=await s(e,d);if(r.exitCode!==0)throw new Error(`Install of ${e} failed (exit ${String(r.exitCode)}). Install manually and retry:
|
|
4
|
+
${y(e)}`);return await l(e)},"loadOptionalSdk");var Z=Object.defineProperty,_=I((e,t)=>Z(e,"name",{value:t,configurable:!0}),"s");const ee=_(e=>{const t=e.indexOf("/");if(t<=0||t===e.length-1)throw new Error(`Expected GITHUB_REPOSITORY in "owner/repo" form, got: ${e}`);return{owner:e.slice(0,t),repo:e.slice(t+1)}},"splitGithubRepo"),te=_(async(e,t)=>{if(t.githubClient)return t.githubClient;const o=(await(t.loadSdk??L)("@octokit/rest")).Octokit;if(!o)throw new TypeError("Loaded `@octokit/rest` but no `Octokit` export was found. Reinstall the package or pin to a supported major.");return new o({auth:e})},"loadGithubClient"),oe=_(async(e,t,o)=>{if(o.gitlabClient)return o.gitlabClient;const i=(await(o.loadSdk??L)("@gitbeaker/rest")).Gitlab;if(!i)throw new TypeError("Loaded `@gitbeaker/rest` but no `Gitlab` export was found. Reinstall the package or pin to a supported major.");return new i({host:t,token:e})},"loadGitlabClient"),re=_(e=>e.replace(/\/api\/v\d+\/?$/,""),"apiBaseToHost"),ie=_(async e=>{const{branch:t,ciContext:o,files:i,message:s,workspaceRoot:l}=e,d=e.readFile??(w=>B(w,"utf8"));if(!o.repo)throw new Error("Cannot commit on GitHub: GITHUB_REPOSITORY (owner/repo) is not set.");if(!o.token)throw new Error("Cannot commit on GitHub: GITHUB_TOKEN is not set. Grant the workflow `contents: write` and pass the token through.");const{owner:r,repo:n}=ee(o.repo),u=await te(o.token,e),p=(await u.rest.git.getRef({owner:r,ref:`heads/${t}`,repo:n})).data.object.sha,h=(await u.rest.git.getCommit({commit_sha:p,owner:r,repo:n})).data.tree.sha,m=await Promise.all(i.map(async w=>{const v=O(l,w),E=await d(v),C=await u.rest.git.createBlob({content:Buffer.from(E,"utf8").toString("base64"),encoding:"base64",owner:r,repo:n});return{mode:"100644",path:w,sha:C.data.sha,type:"blob"}})),f=await u.rest.git.createTree({base_tree:h,owner:r,repo:n,tree:m}),b=await u.rest.git.createCommit({message:s,owner:r,parents:[p],repo:n,tree:f.data.sha});return await u.rest.git.updateRef({owner:r,ref:`heads/${t}`,repo:n,sha:b.data.sha}),{sha:b.data.sha,url:b.data.html_url}},"commitToGithub"),ae=_(async e=>{const{branch:t,ciContext:o,files:i,message:s,workspaceRoot:l}=e,d=e.readFile??(m=>B(m,"utf8"));if(!o.repo)throw new Error("Cannot commit on GitLab: CI_PROJECT_ID / CI_PROJECT_PATH is not set.");if(!o.token)throw new Error("Cannot commit on GitLab: no token. CI_JOB_TOKEN cannot push commits — set GITLAB_TOKEN to a PAT/project-token with `api` scope.");if(!o.apiBaseUrl)throw new Error("Cannot commit on GitLab: CI_API_V4_URL is not set.");const r=re(o.apiBaseUrl),n=await oe(o.token,r,e),u=await Promise.all(i.map(async m=>{const f=O(l,m);return{action:"update",content:await d(f),filePath:m}})),p=await n.Commits.create(o.repo,t,s,u),h=p.id??p.sha;if(!h)throw new Error("GitLab Commits.create returned no commit ID — cannot reference the new commit.");return{sha:h,url:p.web_url??p.webUrl}},"commitToGitlab"),ne=_(async e=>{if(e.files.length===0)throw new Error("Cannot commit: no files to include.");if(e.ciContext.provider==="github-actions")return await ie(e);if(e.ciContext.provider==="gitlab-ci")return await ae(e);throw new Error(`Cannot commit: unsupported CI provider \`${e.ciContext.provider}\`. Run \`vis ai heal accept\` from a recognised CI environment.`)},"commitFiles");var se=Object.defineProperty,g=I((e,t)=>se(e,"name",{value:t,configurable:!0}),"u");const G="/vis heal accept",ce=g(async e=>{if(!e)return;let t;try{t=await B(e,"utf8")}catch{return}const o=JSON.parse(t),i=o.comment?.body??"",s=o.comment?.user?.login??"",l=o.pull_request?.head?.repo?.full_name,d=o.pull_request?.base?.repo?.full_name??o.repository?.full_name,r=l!==void 0&&d!==void 0&&l!==d;return{actor:s,body:i,headRef:o.pull_request?.head?.ref,isFork:r}},"loadGithubTrigger"),le=g(e=>{const t=e.VIS_HEAL_TRIGGER_BODY,o=e.VIS_HEAL_TRIGGER_ACTOR;if(!(!t||!o))return{actor:o,body:t,headRef:e.VIS_HEAL_HEAD_REF,isFork:!1}},"loadGitlabTrigger"),de=g(e=>{const t=e.BUILDKITE_UNBLOCKER_EMAIL??e.BUILDKITE_UNBLOCKER;if(t)return{actor:t,body:G,headRef:e.BUILDKITE_BRANCH,isFork:!1}},"loadBuildkiteTrigger"),ue=g(async(e,t)=>{if(e.provider==="github-actions")return await ce(t.GITHUB_EVENT_PATH);if(e.provider==="gitlab-ci")return le(t);if(e.provider==="buildkite")return de(t)},"loadTrigger"),pe=g((e,t)=>{const o=t.BUILDKITE_REPO;if(!o)return;const i=/(?:^|@|\/\/)github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/i.exec(o);if(i&&t.GITHUB_TOKEN)return{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:e.prNumber,provider:"github-actions",repo:`${i[1]}/${i[2]}`,sha:e.sha,token:t.GITHUB_TOKEN};const s=/\/\/([^/]*gitlab[^/]*)\/([^/]+)\/(.+?)(?:\.git)?\/?$/i.exec(o),l=s?null:/@([^/:]*gitlab[^/:]*):([^/]+)\/(.+?)(?:\.git)?\/?$/i.exec(o),d=s??l;if(d&&t.GITLAB_TOKEN){const r=d[1];return{apiBaseUrl:t.CI_API_V4_URL??`https://${r}/api/v4`,buildId:void 0,buildNumber:void 0,prNumber:e.prNumber,provider:"gitlab-ci",repo:`${d[2]}/${d[3]}`,sha:e.sha,token:t.GITLAB_TOKEN}}},"deriveBuildkiteCommitContext"),me=g(async e=>{const t=e.fetchImpl??globalThis.fetch,o=`${(e.apiBaseUrl??"https://api.github.com").replace(/\/+$/,"")}/repos/${e.repo}/pulls/${String(e.prNumber)}`;try{const i=await t(o,{headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${e.token}`,"X-GitHub-Api-Version":"2022-11-28"}});return i.ok?(await i.json()).head?.ref:void 0}catch{return}},"fetchGithubHeadRef"),fe=g((e,t,o,i)=>{const s=t.map(l=>`- \`${l}\``).join(`
|
|
5
|
+
`);return["## vis ai heal — committed","",`Accepted by @${i}.`,"",`Failing task: \`${o}\``,e.url?`Commit: [\`${e.sha.slice(0,7)}\`](${e.url})`:`Commit: \`${e.sha.slice(0,7)}\``,"","### Files changed",s,"","_Re-run the failing job to confirm the fix landed._"].join(`
|
|
6
|
+
`)},"summariseDetail"),he=g(async(e,t={})=>{const{logger:o,visConfig:i,workspaceRoot:s}=e,l=s??process.cwd(),d=t.env??process.env,r=await(t.detectCi??(()=>D(d)))();if(r.provider==="unknown"){a.error("`vis ai heal accept` must run inside a recognised CI provider (GitHub Actions, GitLab CI, or Buildkite)."),process.exitCode=1;return}const n=await ue(r,d);if(!n){const c=r.provider==="github-actions"?"No issue_comment payload found. Trigger this command from a workflow listening for `issue_comment.created`.":r.provider==="gitlab-ci"?"No GitLab trigger payload found. Set VIS_HEAL_TRIGGER_BODY, VIS_HEAL_TRIGGER_ACTOR, and VIS_HEAL_HEAD_REF in the bridge that re-emits note hooks as pipeline runs.":"No Buildkite unblock signal found. Wire this command to run after a manually-unblocked block step so BUILDKITE_UNBLOCKER_EMAIL is set.";a.error(c),process.exitCode=1;return}if(r.provider!=="buildkite"&&!n.body.includes(G)){a.notice(`Trigger comment does not contain \`${G}\`; nothing to do.`);return}const u=i?.ai?.heal?.allowedActors??[];if(u.length===0){a.error("`ai.heal.allowedActors` is empty. Configure the allow-list in `vis.config.*` before enabling auto-commit."),process.exitCode=1;return}if(!n.actor||!u.includes(n.actor)){const c=r.provider==="buildkite"?"Buildkite entries are emails (BUILDKITE_UNBLOCKER_EMAIL) or Buildkite usernames (BUILDKITE_UNBLOCKER), not the upstream GitHub/GitLab username.":r.provider==="gitlab-ci"?"GitLab entries are platform usernames (without the leading `@`).":"GitHub entries are platform usernames (without the leading `@`).";a.error(`Actor \`${n.actor||"(unknown)"}\` is not in \`ai.heal.allowedActors\`. Refusing to commit. ${c}`),process.exitCode=1;return}if(n.isFork){a.error("Refusing to accept: the change is from a forked repository. The CI token does not have write access to the fork."),process.exitCode=1;return}let p=n.headRef;if(!p&&r.provider==="github-actions"&&r.prNumber!==void 0&&r.repo&&r.token&&(p=await me({fetchImpl:t.fetchImpl,prNumber:r.prNumber,repo:r.repo,token:r.token})),!p){a.error("Could not resolve the PR / MR head branch. Ensure the trigger payload includes head.ref or set VIS_HEAL_HEAD_REF."),process.exitCode=1;return}a.info(`Accepting fix on \`${p}\` for actor \`${n.actor}\`.`);const h=await K(l,e.options.run);if(h.outcome==="no-failed-task"){a.error("No failed tasks found in the run summary. The accept command should run on the same workspace as the original failure."),process.exitCode=1;return}if(h.outcome==="missing-metadata"){a.error(`Failed task ${h.failedTask.taskId} is missing project/target metadata; cannot validate the fix.`),process.exitCode=1;return}if(h.outcome==="no-failure-context"){a.error(`No failure log or run summary found for ${h.failedTask.taskId}.`),process.exitCode=1;return}const m=h,f=await S(e,m);if(f.outcome==="no-proposal"){a.error("AI fix proposal failed; cannot commit."),process.exitCode=1;return}if(f.outcome==="cannot-fix"){a.warn(`AI declined to fix: ${f.detail??"(no reason)"}. Nothing to commit.`),process.exitCode=1;return}if(f.outcome==="empty-patches"){a.warn("AI returned an empty patch set. Nothing to commit."),process.exitCode=1;return}if(f.outcome==="no-patches-applied"){a.error("Patches could not be applied to the workspace. Refusing to commit."),process.exitCode=1;return}a.info(`Re-running ${m.failedTask.taskId} to validate the fix before committing...`);const b=await j(e,m,{validate:t.validate});if(b.exitCode!==0){a.error(`Validation failed (exit ${String(b.exitCode)}). Refusing to commit.`),b.stderr.trim().length>0&&(o.info("--- validation stderr (tail) ---"),o.info(b.stderr.split(`
|
|
7
|
+
`).slice(-20).join(`
|
|
8
|
+
`))),process.exitCode=1;return}a.success("Validation passed. Committing.");const w=(f.applyResults??[]).filter(c=>c.status==="applied").map(c=>{const $=c.absolutePath??c.patch.file,x=F(l,$);return x===""||x.startsWith("..")?c.patch.file:x});if(w.length===0){a.error("No applied files to commit. Aborting."),process.exitCode=1;return}const v=[`fix: vis ai heal accepted by @${n.actor}`,"",`Failing task: ${m.failedTask.taskId}`,f.proposal?.explanation?`
|
|
9
|
+
${f.proposal.explanation}`:"","","Auto-committed by `vis ai heal accept`."].join(`
|
|
10
|
+
`);let E=r;if(r.provider==="buildkite"){const c=pe(r,d);if(!c){a.error("Cannot determine the upstream VCS to commit to. Buildkite jobs need GITHUB_TOKEN or GITLAB_TOKEN set (matching the host parsed from BUILDKITE_REPO) for `vis ai heal accept` to land the commit."),process.exitCode=1;return}E=c}let C;try{C=await ne({branch:p,ciContext:E,files:w,message:v,workspaceRoot:l,...t.commitOverrides})}catch(c){a.error(`Commit failed: ${c instanceof Error?c.message:String(c)}`),process.exitCode=1;return}a.success(`Committed as ${C.sha.slice(0,7)}${C.url?` — ${C.url}`:""}.`);const N=fe(C,w,m.failedTask.taskId,n.actor),R=await(t.postComment??(async(c,$)=>V({body:c,context:$})))(N,r);!R.posted&&R.method!=="skipped"&&a.warn(`Commit landed but the confirmation comment failed: ${R.error??"unknown"}`)},"acceptHeal"),ke=g(async e=>{await he(e)},"aiHealAccept");export{G as TRIGGER_PHRASE,ke as aiHealAccept,pe as deriveBuildkiteCommitContextForTesting,me as fetchGithubHeadRefForTesting,de as loadBuildkiteTriggerForTesting,ce as loadGithubTriggerForTesting,le as loadGitlabTriggerForTesting,he as runHealAcceptForTesting,fe as summariseDetailForTesting};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var U=Object.defineProperty;var I=(t,e)=>U(t,"name",{value:e,configurable:!0});import{createRequire as A}from"node:module";import{j as O,E as v,a as G,I as j,p as u,e as F}from"./bin.js";import{z as D}from"./config.js";import{readLastRunSummary as K}from"@visulima/task-runner";import{r as H,a as M,b as V,c as z}from"../packem_shared/ai-fix-DzrA-dVz.js";import{r as q}from"../packem_shared/run-summary-utils-BaBGP3bo.js";const L=A(import.meta.url),b=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=I(t=>{if(typeof b<"u"&&b.versions&&b.versions.node){const[e,o]=b.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return b.getBuiltinModule(t)}return L(t)},"__cjs_getBuiltinModule"),{spawn:k}=T("node:child_process"),{readFile:J}=T("node:fs/promises");var Q=Object.defineProperty,g=I((t,e)=>Q(t,"name",{value:e,configurable:!0}),"i");const W=g(t=>{if(!t)return;const e=/^refs\/pull\/(\d+)\//.exec(t);return e?Number.parseInt(e[1],10):void 0},"parsePrNumberFromGithubRef"),Y=g(async t=>{if(!t)return{prNumber:void 0,sha:void 0};try{const e=await J(t,"utf8"),o=JSON.parse(e),r=o.pull_request?.number??o.issue?.number??o.number,i=o.pull_request?.head?.sha;return{prNumber:r,sha:i}}catch{return{prNumber:void 0,sha:void 0}}},"readPrNumberFromGithubEvent"),Z=g(async t=>{const e=W(t.GITHUB_REF),{prNumber:o,sha:r}=e===void 0?await Y(t.GITHUB_EVENT_PATH):{prNumber:e,sha:void 0};return{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:e??o,provider:"github-actions",repo:t.GITHUB_REPOSITORY,sha:r??t.GITHUB_SHA,token:t.GITHUB_TOKEN}},"detectGithubActions"),X=g(t=>{const e=t.CI_MERGE_REQUEST_IID,o=e!==void 0&&e!==""?Number.parseInt(e,10):void 0,r=t.CI_API_V4_URL,i=t.GITLAB_TOKEN??t.CI_TOKEN;return{apiBaseUrl:r,buildId:void 0,buildNumber:void 0,prNumber:Number.isFinite(o)?o:void 0,provider:"gitlab-ci",repo:t.CI_PROJECT_ID??t.CI_PROJECT_PATH,sha:t.CI_COMMIT_SHA,token:i}},"detectGitlabCi"),ee=g(t=>{const e=t.BUILDKITE_PULL_REQUEST,o=e!==void 0&&e!==""&&e!=="false"?Number.parseInt(e,10):void 0,r=t.BUILDKITE_BUILD_NUMBER,i=r!==void 0&&r!==""?Number.parseInt(r,10):void 0,n=t.BUILDKITE_ORGANIZATION_SLUG,a=t.BUILDKITE_PIPELINE_SLUG,s=n!==void 0&&n!==""&&a!==void 0&&a!==""?`${n}/${a}`:void 0;return{apiBaseUrl:(t.BUILDKITE_API_BASE_URL??"https://api.buildkite.com").replace(/\/+$/,""),buildId:t.BUILDKITE_BUILD_ID,buildNumber:Number.isFinite(i)?i:void 0,prNumber:Number.isFinite(o)?o:void 0,provider:"buildkite",repo:s,sha:t.BUILDKITE_COMMIT,token:t.BUILDKITE_API_TOKEN}},"detectBuildkite"),te=g(async(t=process.env)=>t.GITHUB_ACTIONS==="true"?await Z(t):t.GITLAB_CI==="true"?X(t):t.BUILDKITE==="true"?ee(t):{apiBaseUrl:void 0,buildId:void 0,buildNumber:void 0,prNumber:void 0,provider:"unknown",repo:void 0,sha:void 0,token:void 0},"detectCiContext");var oe=Object.defineProperty,h=I((t,e)=>oe(t,"name",{value:e,configurable:!0}),"p");const re=h((t,e,o,r)=>new Promise(i=>{const n=["pr","comment",String(e),"--body-file","-"];r&&n.push("--repo",r);const a=k(t,n,{stdio:["pipe","ignore","pipe"]});let s="";a.stderr?.setEncoding("utf8"),a.stderr?.on("data",d=>{s+=d}),a.once("error",()=>{i({exitCode:127,stderr:s})}),a.once("close",d=>{i({exitCode:d??-1,stderr:s})}),a.stdin?.on("error",()=>{}),a.stdin?.end(o)}),"runGhComment"),ie=h(async(t,e,o,r,i)=>{const n=`https://api.github.com/repos/${e}/issues/${String(o)}/comments`;try{const a=await t(n,{body:JSON.stringify({body:r}),headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${i}`,"Content-Type":"application/json","X-GitHub-Api-Version":"2022-11-28"},method:"POST"});if(!a.ok){const s=await a.text().catch(()=>"");return{error:`GitHub REST returned ${String(a.status)}: ${s.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(a){return{error:a instanceof Error?a.message:String(a),ok:!1}}},"postViaGithubRest"),ne=h(async(t,e,o,r,i,n)=>{const a=encodeURIComponent(o),s=`${e.replace(/\/+$/,"")}/projects/${a}/merge_requests/${String(r)}/notes`;try{const d=await t(s,{body:JSON.stringify({body:i}),headers:{"Content-Type":"application/json","PRIVATE-TOKEN":n},method:"POST"});if(!d.ok){const p=await d.text().catch(()=>"");return{error:`GitLab REST returned ${String(d.status)}: ${p.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(d){return{error:d instanceof Error?d.message:String(d),ok:!1}}},"postViaGitlabRest"),ae=h((t,e,o,r)=>new Promise(i=>{const n=k(t,["annotate","--style",o,"--context",r],{stdio:["pipe","ignore","pipe"]});let a="";n.stderr?.setEncoding("utf8"),n.stderr?.on("data",s=>{a+=s}),n.once("error",()=>{i({exitCode:127,stderr:a})}),n.once("close",s=>{i({exitCode:s??-1,stderr:a})}),n.stdin?.on("error",()=>{}),n.stdin?.end(e)}),"runBuildkiteAnnotate"),se=h(async(t,e,o,r,i,n,a,s)=>{const[d,p]=o.split("/",2);if(!d||!p)return{error:`Buildkite repo identifier \`${o}\` is not in {org}/{pipeline} form.`,ok:!1};const m=`${e}/v2/organizations/${encodeURIComponent(d)}/pipelines/${encodeURIComponent(p)}/builds/${String(r)}/annotations`;try{const c=await t(m,{body:JSON.stringify({body:i,context:a,style:n}),headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},method:"POST"});if(!c.ok){const l=await c.text().catch(()=>"");return{error:`Buildkite REST returned ${String(c.status)}: ${l.slice(0,500)}`,ok:!1}}return{ok:!0}}catch(c){return{error:c instanceof Error?c.message:String(c),ok:!1}}},"postViaBuildkiteRest"),de=h(async(t,e,o,r)=>{const i=e.buildId?`vis-ai-heal-${e.buildId}`:"vis-ai-heal",n="info",a=await ae(o,t,n,i);if(a.exitCode===0)return{method:"buildkite-cli",posted:!0};if(!e.apiBaseUrl||!e.repo||e.buildNumber===void 0||!e.token){const d=[];return e.repo||d.push("BUILDKITE_ORGANIZATION_SLUG / BUILDKITE_PIPELINE_SLUG"),e.buildNumber===void 0&&d.push("BUILDKITE_BUILD_NUMBER"),e.token||d.push("BUILDKITE_API_TOKEN (with `write_build_annotations` scope)"),{error:`buildkite-agent annotate exited ${String(a.exitCode)} (${a.stderr.trim().slice(0,200)}); cannot fall back to REST without ${d.join(", ")}`,method:"buildkite-cli",posted:!1}}const s=await se(r,e.apiBaseUrl,e.repo,e.buildNumber,t,n,i,e.token);return s.ok?{method:"rest",posted:!0}:{error:`buildkite-agent annotate exited ${String(a.exitCode)}; REST fallback also failed: ${s.error??"unknown"}`,method:"rest",posted:!1}},"postBuildkiteAnnotation"),pe=h(async(t,e,o,r)=>{if(e.prNumber===void 0)return{method:"skipped",posted:!1};const i=await re(o,e.prNumber,t,e.repo);if(i.exitCode===0)return{method:"gh-cli",posted:!0};if(!e.repo||!e.token)return{error:`gh exited ${String(i.exitCode)} (${i.stderr.trim().slice(0,200)}); cannot fall back to REST without GITHUB_REPOSITORY + GITHUB_TOKEN`,method:"gh-cli",posted:!1};const n=await ie(r,e.repo,e.prNumber,t,e.token);return n.ok?{method:"rest",posted:!0}:{error:`gh exited ${String(i.exitCode)}; REST fallback also failed: ${n.error??"unknown"}`,method:"rest",posted:!1}},"postGithubComment"),ce=h(async(t,e,o)=>{if(e.prNumber===void 0)return{method:"skipped",posted:!1};if(!e.apiBaseUrl||!e.repo)return{error:"GitLab CI context is missing CI_API_V4_URL or CI_PROJECT_ID; cannot post note.",method:"rest",posted:!1};if(!e.token)return{error:"GitLab CI context has no token. CI_JOB_TOKEN cannot post MR notes — set GITLAB_TOKEN to a personal/project access token with `api` scope.",method:"rest",posted:!1};const r=await ne(o,e.apiBaseUrl,e.repo,e.prNumber,t,e.token);return r.ok?{method:"rest",posted:!0}:{error:r.error,method:"rest",posted:!1}},"postGitlabComment"),ue=h(async t=>{const{body:e,buildkiteAgentBin:o="buildkite-agent",context:r,fetchImpl:i=globalThis.fetch,ghBin:n="gh"}=t;return r.provider==="github-actions"?await pe(e,r,n,i):r.provider==="gitlab-ci"?await ce(e,r,i):r.provider==="buildkite"?await de(e,r,o,i):{method:"skipped",posted:!1}},"postPrComment");var le=Object.defineProperty,f=I((t,e)=>le(t,"name",{value:e,configurable:!0}),"l");const C=f(t=>{let e=0,o=0;for(const r of t)r.status==="applied"?e+=1:o+=1;return{applied:e,failed:o}},"summarizeApply"),_=f((t,e,o)=>{const r=H(t,e,o),i=D(t,r);return i===""||i.startsWith("..")?r:i},"formatDisplayPath"),fe=f((t,e,o,r)=>new Promise(i=>{const n=process.argv[1];if(!n){i({exitCode:-1,stderr:"Cannot locate vis bin (process.argv[1] missing).",stdout:""});return}const a=[n,"run",o,"--projects",e,"--no-cache","--summarize","--fail-fast"],s=k(process.execPath,a,{cwd:t,env:{...process.env,NO_COLOR:"1"},stdio:["ignore","pipe","pipe"]});let d="",p="";const m=setTimeout(()=>{s.kill("SIGTERM"),setTimeout(()=>s.kill("SIGKILL"),2e3).unref()},r);s.stdout?.setEncoding("utf8"),s.stdout?.on("data",c=>{d+=c}),s.stderr?.setEncoding("utf8"),s.stderr?.on("data",c=>{p+=c}),s.once("error",c=>{clearTimeout(m),i({exitCode:-1,stderr:c.message,stdout:d})}),s.once("close",c=>{clearTimeout(m),i({exitCode:c??-1,stderr:p,stdout:d})})}),"validateFixByRerun"),me=6e4,y=f(t=>{let e=0;const o=t.match(/`{3,}/g);if(o)for(const r of o)e=Math.max(e,r.length);return"`".repeat(Math.max(3,e+1))},"pickFence"),$=f((t,e,o)=>{if(t.patches.length===0)return"_No patches proposed._";const r=[];for(const[i,n]of t.patches.entries()){const a=_(e,o,n.file),s=[`**[${String(i+1)}] \`${a}\`**`];n.reason&&s.push(`_${n.reason}_`);const d=y(`${n.oldString}
|
|
2
|
+
${n.newString}`);s.push(`${d}diff`);for(const p of n.oldString.split(`
|
|
3
|
+
`))s.push(`- ${p}`);for(const p of n.newString.split(`
|
|
4
|
+
`))s.push(`+ ${p}`);s.push(d),r.push(s.join(`
|
|
5
|
+
`))}return r.join(`
|
|
6
|
+
|
|
7
|
+
`)},"renderProposalDiff"),x=f((t,e,o,r)=>{const i=["## vis ai heal — proposed fix","",`Failing task: \`${e.taskId}\` (provider: \`${t.provider}\`, confidence: \`${t.confidence}\`)`];r&&i.push(`Run anchored at \`${r.slice(0,7)}\`.`),i.push(""),i.push("### Root cause"),i.push(t.explanation||"_(no explanation)_"),i.push("");const n=["### Proposed patch",$(t,o,e.cwd),""],a=["### Validation",`Re-ran \`${e.taskId}\` after applying the patch on the CI runner — task **passed**.`,"","### Apply locally","```sh",`vis ai fix ${e.taskId} --apply`,"```","","---","","_Auto-generated by `vis ai heal`. Auto-commit is on the roadmap; for now the patch lives in this comment and is yours to accept or reject._"],s=[...i,...n,...a].join(`
|
|
8
|
+
`);if(Buffer.byteLength(s,"utf8")<=me)return s;const d=["### Proposed patch",`_Patch set is too large for a comment (${String(t.patches.length)} files). Run \`vis ai fix ${e.taskId} --apply\` locally to inspect and apply it._`,""];return[...i,...d,...a].join(`
|
|
9
|
+
`)},"renderCommentBody"),he=f((t,e,o)=>{const r=[O(`Proposal (${t.provider}, confidence: ${t.confidence})`),t.explanation||v("<no explanation>")];for(const[i,n]of t.patches.entries()){r.push(""),r.push(`[${String(i+1)}] ${_(e,o,n.file)}`),n.reason&&r.push(v(` reason: ${n.reason}`));for(const a of n.oldString.split(`
|
|
10
|
+
`))r.push(G(` - ${a}`));for(const a of n.newString.split(`
|
|
11
|
+
`))r.push(j(` + ${a}`))}return r.join(`
|
|
12
|
+
`)},"renderProposalForLog"),ge=f(async(t,e)=>{const o=e===void 0?await K(t):await q(t,e);if(o){for(const r of o.tasks)if(r.exitCode!==void 0&&r.exitCode!==0)return{project:r.target?.project,runId:o.id,target:r.target?.target,taskId:r.taskId}}},"findFirstFailedTask"),Ie=1800*1e3,w=f(async(t,e)=>{const o=await ge(t,e);if(!o)return{outcome:"no-failed-task"};if(!o.project||!o.target)return{failedTask:o,outcome:"missing-metadata"};const r=await M(t,o.taskId,{runId:o.runId});return r?{failedTask:{project:o.project,runId:o.runId,target:o.target,taskId:o.taskId},failureContext:r,outcome:"ready"}:{failedTask:{project:o.project,runId:o.runId,target:o.target,taskId:o.taskId},outcome:"no-failure-context"}},"findHealCandidate"),N=f(async(t,e)=>{const{logger:o,options:r,visConfig:i,workspaceRoot:n}=t,a=n??process.cwd(),s=r.dryRun===!0,d=i?.ai,p=await V(e.failureContext,o,{cache:r.cache!==!1,config:d});if(!p)return{outcome:"no-proposal"};if(p.cannotFix)return{detail:p.cannotFix,outcome:"cannot-fix",proposal:p};if(p.patches.length===0)return{outcome:"empty-patches",proposal:p};if(s)return{outcome:"dry-run",proposal:p};const m=await z(a,e.failureContext.cwd,p);return C(m).applied===0?{applyResults:m,outcome:"no-patches-applied",proposal:p}:{applyResults:m,outcome:"applied",proposal:p}},"proposeAndApply"),E=f(async(t,e,o={})=>{const r=t.workspaceRoot??process.cwd(),i=t.options.validationTimeout===void 0?Ie:t.options.validationTimeout*1e3;return await(o.validate??((n,a)=>fe(r,n,a,i)))(e.failedTask.project,e.failedTask.target)},"validateAppliedFix"),S=f(async(t,e,o,r={})=>{const i=await(r.detectCi??te)(),n=i.provider==="gitlab-ci"?"MR":i.provider==="buildkite"?"annotation":"PR";if(i.provider==="unknown")return{ciContext:i,outcome:"no-ci",surface:n};const a=x(e,o,t,i.sha),s=await(r.postComment??(async(d,p)=>ue({body:d,context:p})))(a,i);return s.posted?{ciContext:i,method:s.method,outcome:"posted",surface:n}:s.method==="skipped"?{ciContext:i,outcome:"no-pr",surface:n}:{ciContext:i,error:s.error,method:s.method,outcome:"post-failed",surface:n}},"postHealComment"),R=f(async(t,e={})=>{const{logger:o,workspaceRoot:r}=t,i=r??process.cwd(),n=await w(i,t.options.run);if(n.outcome==="no-failed-task"){u.info("No failed tasks found in the latest run summary. Nothing to heal.");return}if(n.outcome==="missing-metadata"){u.error(`Failed task ${n.failedTask.taskId} is missing project/target metadata in the run summary; cannot validate a fix.`),process.exitCode=1;return}if(n.outcome==="no-failure-context"){u.error(`No failure log or run summary found for ${n.failedTask.taskId}.`),process.exitCode=1;return}const a={failedTask:n.failedTask,failureContext:n.failureContext};u.info(`Healing ${a.failedTask.taskId} (run ${a.failedTask.runId??"unknown"})`),a.failureContext.terminalOutputCaptured||u.warn(`No captured terminal output for ${a.failedTask.taskId}; the AI proposal will be weaker without it.`);const s=await N(t,a);if(s.outcome==="no-proposal"){u.error("AI fix proposal failed or no provider available."),process.exitCode=1;return}if(s.outcome==="cannot-fix"){u.warn(`AI declined to fix: ${s.detail??"(no reason)"}`);return}if(s.outcome==="empty-patches"){u.warn("AI returned an empty patch set.");return}const d=s.proposal;if(o.info(he(d,i,a.failureContext.cwd)),s.outcome==="dry-run"){u.info("Dry run: skipping apply, validation, and PR comment.");return}const p=s.applyResults??[],m=C(p);if(u.info(`Applied ${String(m.applied)}/${String(p.length)} patches.`),s.outcome==="no-patches-applied"){u.error("No patches could be applied (all failed validation)."),process.exitCode=1;return}u.info(`Re-running ${a.failedTask.taskId} to validate the fix...`);const c=await E(t,a,{validate:e.validate});if(c.exitCode!==0){u.error(`Validation failed (exit ${String(c.exitCode)}). Patch is not posted.`),c.stderr.trim().length>0&&(o.info(F("--- validation stderr (tail) ---")),o.info(c.stderr.split(`
|
|
13
|
+
`).slice(-20).join(`
|
|
14
|
+
`))),process.exitCode=1;return}u.success("Validation passed.");const l=await S(i,d,a.failureContext,{detectCi:e.detectCi,postComment:e.postComment});if(l.outcome==="no-ci"){u.notice("Not running in a recognised CI provider; skipping PR comment. Patch was applied + validated locally.");return}if(l.outcome==="posted"){const P=l.surface==="annotation"?`build #${String(l.ciContext.buildNumber??"?")}`:`${l.surface} #${String(l.ciContext.prNumber)}`;u.success(`Posted fix proposal to ${P} via ${l.method??"unknown"}.`);return}if(l.outcome==="no-pr"){u.notice(`No ${l.surface} number detected (push-event run); skipping comment.`);return}const B=l.surface==="annotation"?"annotation":`${l.surface} comment`;u.error(`Failed to post ${B}: ${l.error??"unknown error"}`)},"heal"),be=f(async t=>{await R(t)},"aiHeal"),xe=Object.defineProperty({__proto__:null,aiHeal:be,findHealCandidate:w,pickFenceForTesting:y,postHealComment:S,proposeAndApply:N,renderCommentBodyForTesting:x,renderProposalDiffForTesting:$,runHealForTesting:R,validateAppliedFix:E},Symbol.toStringTag,{value:"Module"});export{w as P,N as R,te as d,xe as h,ue as p,E as w};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var fr=Object.defineProperty;var B=(e,t)=>fr(e,"name",{value:t,configurable:!0});import{createRequire as mr}from"node:module";import{be as pe,bf as Ie,bg as vt,bh as gr,j as br,bi as wr,I as V,bj as M,q as he,e as qe}from"./bin.js";const pr=mr(import.meta.url),le=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Qe=B(e=>{if(typeof le<"u"&&le.versions&&le.versions.node){const[t,i]=le.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return le.getBuiltinModule(e)}return pr(e)},"__cjs_getBuiltinModule"),{createRequire:ji}=Qe("node:module"),ee=le,{execFileSync:yr}=Qe("node:child_process"),ye=Qe("node:fs"),vr=Qe("node:tty");var $r=Object.defineProperty,Pt=B((e,t)=>$r(e,"name",{value:t,configurable:!0}),"s$4"),xr=Object.defineProperty,Xe=Pt((e,t)=>xr(e,"name",{value:t,configurable:!0}),"l");const Tt=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],Ft=[12288,12288,65281,65376,65504,65510],Lt=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],_t=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],et=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141];var Wr=Object.defineProperty,Br=Xe((e,t)=>Wr(e,"name",{value:t,configurable:!0}),"r$1");const xe=Br((e,t)=>{let i=0,r=Math.floor(e.length/2)-1;for(;i<=r;){const s=Math.floor((i+r)/2),o=s*2;if(t<e[o])r=s-1;else if(t>e[o+1])i=s+1;else return!0}return!1},"isInRange");var Sr=Object.defineProperty,ne=Xe((e,t)=>Sr(e,"name",{value:t,configurable:!0}),"r");const Ar=Tt[0],Or=Tt.at(-1),Ir=Ft[0],Cr=Ft.at(-1),Nr=Lt[0],jr=Lt.at(-1),Er=_t[0],kr=_t.at(-1),Rr=et[0],Mr=et.at(-1),ti=19968,[Pr,Tr]=tt(et);function tt(e){let t=e[0],i=e[1];for(let r=0;r<e.length;r+=2){const s=e[r],o=e[r+1];if(ti>=s&&ti<=o)return[s,o];o-s>i-t&&(t=s,i=o)}return[t,i]}B(tt,"b$6");Pt(tt,"b");Xe(tt,"N");ne(tt,"findWideFastPathRange");const Ei=ne(e=>e<Ar||e>Or?!1:xe(Tt,e),"isAmbiguous"),ki=ne(e=>e<Ir||e>Cr?!1:xe(Ft,e),"isFullWidth"),Fr=ne(e=>e<Nr||e>jr?!1:xe(Lt,e),"isHalfWidth"),Lr=ne(e=>e<Er||e>kr?!1:xe(_t,e),"isNarrow"),Ri=ne(e=>e>=Pr&&e<=Tr?!0:e<Rr||e>Mr?!1:xe(et,e),"isWide");function it(e){return Ei(e)?"ambiguous":ki(e)?"fullwidth":Fr(e)?"halfwidth":Lr(e)?"narrow":Ri(e)?"wide":"neutral"}B(it,"v$5");Pt(it,"q");Xe(it,"getCategory");ne(it,"getCategory");var _r=Object.defineProperty,rt=B((e,t)=>_r(e,"name",{value:t,configurable:!0}),"i$3"),Hr=Object.defineProperty,nt=rt((e,t)=>Hr(e,"name",{value:t,configurable:!0}),"a"),Gr=Object.defineProperty,Ht=nt((e,t)=>Gr(e,"name",{value:t,configurable:!0}),"e");function We(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}B(We,"s$3");rt(We,"s");nt(We,"r");Ht(We,"validate");function Be(e){return We(e),it(e)}B(Be,"r$2");rt(Be,"p");nt(Be,"eastAsianWidthType");Ht(Be,"eastAsianWidthType");function Gt(e,{ambiguousAsWide:t=!1}={}){return We(e),ki(e)||Ri(e)||t&&Ei(e)?2:1}B(Gt,"o$3");rt(Gt,"W");nt(Gt,"eastAsianWidth");Ht(Gt,"eastAsianWidth");var Vr=Object.defineProperty,Jr=B((e,t)=>Vr(e,"name",{value:t,configurable:!0}),"E$3"),zr=Object.defineProperty,qr=Jr((e,t)=>zr(e,"name",{value:t,configurable:!0}),"A"),Ur=Object.defineProperty,ot=qr((e,t)=>Ur(e,"name",{value:t,configurable:!0}),"d");const ii=new Map,Ce=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,Fe=ot(e=>e>=32&&e<=126?"latin":e===8203||e===8204||e===8205||e===8288?"zero":e<=31||e>=127&&e<=159?"control":e>=160&&e<=255||e>=9472&&e<=9599?"latin":e>=4352&&e<=4607||e>=11904&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65519&&!(e>=65377&&e<=65439)||e>=12352&&e<=12543?"wide":e===8230?"latin":"other","getCharType"),Dr=ot((e,t)=>{const i=Math.floor(e/65536),r=e%65536;let s=ii.get(i);if(s||(s=new Map,ii.set(i,s)),s.has(r))return s.get(r);let o;if(Fe(e)==="latin")o=t.width.regular;else if(Fe(e)==="control")o=t.width.control;else if(Fe(e)==="wide")o=t.width.wide;else switch(Be(e)){case"ambiguous":{o=t.width.ambiguousIsNarrow?t.width.regular:t.width.wide;break}case"fullwidth":{o=t.width.fullWidth;break}case"wide":{o=t.width.wide;break}default:o=t.width.regular}return s.set(r,o),o},"getCachedCharWidth"),Yr=ot(e=>e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||e>=917760&&e<=917999||e>=65024&&e<=65039||e>=3633&&e<=3642||e>=3655&&e<=3662||e>=3761&&e<=3769||e>=3771&&e<=3772||e>=3784&&e<=3789||e>=2304&&e<=2307||e>=2362&&e<=2383||e>=2385&&e<=2391||e>=2402&&e<=2403||e>=2433&&e<=2435||e>=2492&&e<=2500||e>=2509&&e<=2509||e>=2561&&e<=2563||e>=2620&&e<=2637||e>=1611&&e<=1631||e>=1648&&e<=1648||e>=1750&&e<=1773||e>=2276&&e<=2302||e>=1425&&e<=1469||e>=1471&&e<=1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e>=1479&&e<=1479||e>=3893&&e<=3893||e>=3895&&e<=3895||e>=3897&&e<=3897||e>=3953&&e<=3966||e>=3968&&e<=3972||e>=3974&&e<=3975?!0:e>=768&&e<=777||e>=803&&e<=803,"isCombiningCharacter"),Bt=ot((e,t={})=>{if(!e||e.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const i={truncation:{countAnsiEscapeCodes:t.countAnsiEscapeCodes??!1,ellipsis:t.ellipsis??"",ellipsisWidth:t.ellipsisWidth??(t.ellipsis?Bt(t.ellipsis,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:t.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:t.ambiguousIsNarrow??!1,ansi:t.ansiWidth??0,control:t.controlWidth??0,emoji:t.emojiWidth??2,fullWidth:t.fullWidth??2,halfWidth:t.halfWidth??1,regular:t.regularWidth??1,tab:t.tabWidth??8,wide:t.wideWidth??2}},r=Math.max(0,i.truncation.limit-i.truncation.ellipsisWidth),{length:s}=e,o=s>1e4;let n=0,a=0,l=s,h=!1;const c=e.includes("\x1B")||e.includes("");for(;n<s;){if(c&&(e[n]==="\x1B"||e[n]==="")){if(e.startsWith("\x1B]8;;",n)){const m="\x1B]8;;\x07",u=m.length,$=e.indexOf("\x07",n+5);if($!==-1){const w=e.indexOf(m,$+1);if(w!==-1){const v=w+u,x=e.slice($+1,w).replace(pe,""),W=Bt(x,{ambiguousIsNarrow:i.width.ambiguousIsNarrow,ansiWidth:i.width.ansi,controlWidth:i.width.control,countAnsiEscapeCodes:!1,ellipsis:i.truncation.ellipsis,ellipsisWidth:i.truncation.ellipsisWidth,emojiWidth:i.width.emoji,fullWidth:i.width.fullWidth,halfWidth:i.width.halfWidth,limit:Math.max(0,r-a),regularWidth:i.width.regular,tabWidth:i.width.tab,wideWidth:i.width.wide}),S=W.width;if(W.truncated)h=!0,l=Math.min(l,n);else if(a+S>r&&(l=Math.min(l,n),h=!0,a+S>i.truncation.limit))break;if(a+=S,n=v,h&&a>=i.truncation.limit)break;continue}}}if(pe.lastIndex=n,pe.test(e)){const m=pe.lastIndex-n,u=i.truncation.countAnsiEscapeCodes?m:i.width.ansi;if(a+u>r&&(l=Math.min(l,n),a+u>i.truncation.limit)){h=!0;break}a+=u,n=pe.lastIndex;continue}}const b=e.codePointAt(n);if(b===8203||b===65279||b>=8288&&b<=8292){n+=1;continue}if(b===9){if(a+i.width.tab>r&&(l=Math.min(l,n),a+i.width.tab>i.truncation.limit)){h=!0;break}a+=i.width.tab,n+=1;continue}if(Ce.lastIndex=n,Ce.test(e)){const m=(Ce.lastIndex-n)*i.width.regular;if(a+m>r){const u=Math.floor((r-a)/i.width.regular);if(l=Math.min(l,n+u),a+m>i.truncation.limit){h=!0;break}}a+=m,n=Ce.lastIndex;continue}if((b<=31||b>=127&&b<=159)&&(Ie.lastIndex=n,Ie.test(e))){const m=(Ie.lastIndex-n)*i.width.control;if(a+m>r&&(l=Math.min(l,n+Math.floor((r-a)/i.width.control)),a+m>i.truncation.limit)){h=!0;break}a+=m,n=Ie.lastIndex;continue}if(vt.lastIndex=n,vt.test(e)){if(a+i.width.emoji>r&&(l=Math.min(l,n),a+i.width.emoji>i.truncation.limit)){h=!0;break}a+=i.width.emoji,n=vt.lastIndex;continue}const f=e.codePointAt(n)??0;if(Yr(f)){n+=f>65535?2:1;continue}let p;if(o)p=Dr(f,i);else switch(Fe(f)){case"control":{p=i.width.control;break}case"latin":{p=i.width.regular;break}case"wide":{p=i.width.wide;break}case"zero":{p=0;break}default:switch(Be(f)){case"ambiguous":{p=i.width.ambiguousIsNarrow?i.width.regular:i.width.wide;break}case"fullwidth":{p=i.width.fullWidth;break}case"wide":{p=i.width.wide;break}default:p=i.width.regular}}if(a+p>r&&(l=Math.min(l,n),a+p>i.truncation.limit)){h=!0;break}a+=p,n+=f>65535?2:1}let d=a,g=!1;return h&&i.truncation.limit>=i.truncation.ellipsisWidth&&(d=i.truncation.limit,g=!0),{ellipsed:g,index:h?l:s,truncated:h,width:d}},"getStringTruncatedWidth");var Kr=Object.defineProperty,Zr=B((e,t)=>Kr(e,"name",{value:t,configurable:!0}),"i$2"),Qr=Object.defineProperty,Xr=Zr((e,t)=>Qr(e,"name",{value:t,configurable:!0}),"e"),en=Object.defineProperty,tn=Xr((e,t)=>en(e,"name",{value:t,configurable:!0}),"r");const rn=tn((e,t={})=>Bt(e,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,"getStringWidth");var nn=Object.defineProperty,J=B((e,t)=>nn(e,"name",{value:t,configurable:!0}),"O$5"),on=Object.defineProperty,O=J((e,t)=>on(e,"name",{value:t,configurable:!0}),"y");const sn=ji(import.meta.url),ce=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Vt=O(e=>{if(typeof ce<"u"&&ce.versions&&ce.versions.node){const[t,i]=ce.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return ce.getBuiltinModule(e)}return sn(e)},"__cjs_getBuiltinModule"),te=ce,{execFileSync:an}=Vt("node:child_process"),ve=Vt("node:fs"),ln=Vt("node:tty");var cn=Object.defineProperty,K=O((e,t)=>cn(e,"name",{value:t,configurable:!0}),"n$5");const Jt=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],zt=[12288,12288,65281,65376,65504,65510],qt=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],Ut=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],st=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141],Se=K((e,t)=>{let i=0,r=Math.floor(e.length/2)-1;for(;i<=r;){const s=Math.floor((i+r)/2),o=s*2;if(t<e[o])r=s-1;else if(t>e[o+1])i=s+1;else return!0}return!1},"isInRange"),hn=Jt[0],dn=Jt.at(-1),un=zt[0],fn=zt.at(-1),mn=qt[0],pn=qt.at(-1),gn=Ut[0],bn=Ut.at(-1),wn=st[0],yn=st.at(-1),ri=19968,[vn,$n]=at(st);function at(e){let t=e[0],i=e[1];for(let r=0;r<e.length;r+=2){const s=e[r],o=e[r+1];if(ri>=s&&ri<=o)return[s,o];o-s>i-t&&(t=s,i=o)}return[t,i]}B(at,"Nt");J(at,"Kt");O(at,"k$3");K(at,"findWideFastPathRange");const Mi=K(e=>e<hn||e>dn?!1:Se(Jt,e),"isAmbiguous"),Pi=K(e=>e<un||e>fn?!1:Se(zt,e),"isFullWidth"),xn=K(e=>e<mn||e>pn?!1:Se(qt,e),"isHalfWidth"),Wn=K(e=>e<gn||e>bn?!1:Se(Ut,e),"isNarrow"),Ti=K(e=>e>=vn&&e<=$n?!0:e<wn||e>yn?!1:Se(st,e),"isWide");function lt(e){return Mi(e)?"ambiguous":Pi(e)?"fullwidth":xn(e)?"halfwidth":Wn(e)?"narrow":Ti(e)?"wide":"neutral"}B(lt,"Ot");J(lt,"Qt");O(lt,"I$2");K(lt,"getCategory");var Bn=Object.defineProperty,Dt=O((e,t)=>Bn(e,"name",{value:t,configurable:!0}),"e$2");function Ae(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}B(Ae,"mt");J(Ae,"Et");O(Ae,"r$4");Dt(Ae,"validate");function Oe(e){return Ae(e),lt(e)}B(Oe,"pt");J(Oe,"Mt");O(Oe,"p$6");Dt(Oe,"eastAsianWidthType");function Yt(e,{ambiguousAsWide:t=!1}={}){return Ae(e),Pi(e)||Ti(e)||t&&Mi(e)?2:1}B(Yt,"ie");J(Yt,"je");O(Yt,"g$3");Dt(Yt,"eastAsianWidth");var Sn=Object.defineProperty,Fi=O((e,t)=>Sn(e,"name",{value:t,configurable:!0}),"n$4");const Li=String.raw,ni=Li`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,An=Fi(()=>new RegExp(Li`\p{RI}{2}|(?)${ni}(?:\u200D${ni})*`,"gu"),"emojiRegex"),ue=new Set(["\x1B",""]),ct="\x07",_i="[",Kt="m",Ue="]8;;",On=39,In=/[\u200B\uFEFF\u2060-\u2064]/g,Cn=new RegExp(`(?:\\${_i}(?<code>\\d+)m|\\${Ue}(?<uri>.*)${ct})`),Nn=Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]])),X=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g,oi=/\u001B\[(\d+(?:;\d+)*)?m[^\u001B]*(?:\u001B\[(?:\d+(?:;\d+)*)?m|$)/g,si=/\u001B\]8;[^\u0007\u001B]*(?:\u0007|\u001B\\)(.*?)\u001B\]8;;(?:\u0007|\u001B\\)/g,Ne=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,Le=An();Fi(e=>e.replace(Le,""),"stripEmoji");var jn=Object.defineProperty,ht=O((e,t)=>jn(e,"name",{value:t,configurable:!0}),"b$5");const ai=new Map,je=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,_e=ht(e=>e>=32&&e<=126?"latin":e===8203||e===8204||e===8205||e===8288?"zero":e<=31||e>=127&&e<=159?"control":e>=160&&e<=255||e>=9472&&e<=9599?"latin":e>=4352&&e<=4607||e>=11904&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65519&&!(e>=65377&&e<=65439)||e>=12352&&e<=12543?"wide":e===8230?"latin":"other","getCharType"),En=ht((e,t)=>{const i=Math.floor(e/65536),r=e%65536;let s=ai.get(i);if(s||(s=new Map,ai.set(i,s)),s.has(r))return s.get(r);let o;if(_e(e)==="latin")o=t.width.regular;else if(_e(e)==="control")o=t.width.control;else if(_e(e)==="wide")o=t.width.wide;else switch(Oe(e)){case"ambiguous":{o=t.width.ambiguousIsNarrow?t.width.regular:t.width.wide;break}case"fullwidth":{o=t.width.fullWidth;break}case"wide":{o=t.width.wide;break}default:o=t.width.regular}return s.set(r,o),o},"getCachedCharWidth"),kn=ht(e=>e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||e>=917760&&e<=917999||e>=65024&&e<=65039||e>=3633&&e<=3642||e>=3655&&e<=3662||e>=3761&&e<=3769||e>=3771&&e<=3772||e>=3784&&e<=3789||e>=2304&&e<=2307||e>=2362&&e<=2383||e>=2385&&e<=2391||e>=2402&&e<=2403||e>=2433&&e<=2435||e>=2492&&e<=2500||e>=2509&&e<=2509||e>=2561&&e<=2563||e>=2620&&e<=2637||e>=1611&&e<=1631||e>=1648&&e<=1648||e>=1750&&e<=1773||e>=2276&&e<=2302||e>=1425&&e<=1469||e>=1471&&e<=1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e>=1479&&e<=1479||e>=3893&&e<=3893||e>=3895&&e<=3895||e>=3897&&e<=3897||e>=3953&&e<=3966||e>=3968&&e<=3972||e>=3974&&e<=3975?!0:e>=768&&e<=777||e>=803&&e<=803,"isCombiningCharacter"),de=ht((e,t={})=>{if(!e||e.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const i={truncation:{countAnsiEscapeCodes:t.countAnsiEscapeCodes??!1,ellipsis:t.ellipsis??"",ellipsisWidth:t.ellipsisWidth??(t.ellipsis?de(t.ellipsis,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:t.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:t.ambiguousIsNarrow??!1,ansi:t.ansiWidth??0,control:t.controlWidth??0,emoji:t.emojiWidth??2,fullWidth:t.fullWidth??2,halfWidth:t.halfWidth??1,regular:t.regularWidth??1,tab:t.tabWidth??8,wide:t.wideWidth??2}},r=Math.max(0,i.truncation.limit-i.truncation.ellipsisWidth),{length:s}=e,o=s>1e4;let n=0,a=0,l=s,h=!1;const c=e.includes("\x1B")||e.includes("");for(;n<s;){if(c&&(e[n]==="\x1B"||e[n]==="")){if(e.startsWith("\x1B]8;;",n)){const m="\x1B]8;;\x07",u=m.length,$=e.indexOf("\x07",n+5);if($!==-1){const w=e.indexOf(m,$+1);if(w!==-1){const v=w+u,x=e.slice($+1,w).replace(X,""),W=de(x,{ambiguousIsNarrow:i.width.ambiguousIsNarrow,ansiWidth:i.width.ansi,controlWidth:i.width.control,countAnsiEscapeCodes:!1,ellipsis:i.truncation.ellipsis,ellipsisWidth:i.truncation.ellipsisWidth,emojiWidth:i.width.emoji,fullWidth:i.width.fullWidth,halfWidth:i.width.halfWidth,limit:Math.max(0,r-a),regularWidth:i.width.regular,tabWidth:i.width.tab,wideWidth:i.width.wide}),S=W.width;if(W.truncated)h=!0,l=Math.min(l,n);else if(a+S>r&&(l=Math.min(l,n),h=!0,a+S>i.truncation.limit))break;if(a+=S,n=v,h&&a>=i.truncation.limit)break;continue}}}if(X.lastIndex=n,X.test(e)){const m=X.lastIndex-n,u=i.truncation.countAnsiEscapeCodes?m:i.width.ansi;if(a+u>r&&(l=Math.min(l,n),a+u>i.truncation.limit)){h=!0;break}a+=u,n=X.lastIndex;continue}}const b=e.codePointAt(n);if(b===8203||b===65279||b>=8288&&b<=8292){n+=1;continue}if(b===9){if(a+i.width.tab>r&&(l=Math.min(l,n),a+i.width.tab>i.truncation.limit)){h=!0;break}a+=i.width.tab,n+=1;continue}if(je.lastIndex=n,je.test(e)){const m=(je.lastIndex-n)*i.width.regular;if(a+m>r){const u=Math.floor((r-a)/i.width.regular);if(l=Math.min(l,n+u),a+m>i.truncation.limit){h=!0;break}}a+=m,n=je.lastIndex;continue}if((b<=31||b>=127&&b<=159)&&(Ne.lastIndex=n,Ne.test(e))){const m=(Ne.lastIndex-n)*i.width.control;if(a+m>r&&(l=Math.min(l,n+Math.floor((r-a)/i.width.control)),a+m>i.truncation.limit)){h=!0;break}a+=m,n=Ne.lastIndex;continue}if(Le.lastIndex=n,Le.test(e)){if(a+i.width.emoji>r&&(l=Math.min(l,n),a+i.width.emoji>i.truncation.limit)){h=!0;break}a+=i.width.emoji,n=Le.lastIndex;continue}const f=e.codePointAt(n)??0;if(kn(f)){n+=f>65535?2:1;continue}let p;if(o)p=En(f,i);else switch(_e(f)){case"control":{p=i.width.control;break}case"latin":{p=i.width.regular;break}case"wide":{p=i.width.wide;break}case"zero":{p=0;break}default:switch(Oe(f)){case"ambiguous":{p=i.width.ambiguousIsNarrow?i.width.regular:i.width.wide;break}case"fullwidth":{p=i.width.fullWidth;break}case"wide":{p=i.width.wide;break}default:p=i.width.regular}}if(a+p>r&&(l=Math.min(l,n),a+p>i.truncation.limit)){h=!0;break}a+=p,n+=f>65535?2:1}let d=a,g=!1;return h&&i.truncation.limit>=i.truncation.ellipsisWidth&&(d=i.truncation.limit,g=!0),{ellipsed:g,index:h?l:s,truncated:h,width:d}},"getStringTruncatedWidth");var Rn=Object.defineProperty,Mn=O((e,t)=>Rn(e,"name",{value:t,configurable:!0}),"e$1");const E=Mn((e,t={})=>de(e,{...t,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,"getStringWidth");var Pn=Object.defineProperty,Tn=O((e,t)=>Pn(e,"name",{value:t,configurable:!0}),"r$1");class Fn{static{B(this,"Xe")}static{J(this,"Ue")}static{O(this,"c")}static{Tn(this,"LRUCache")}capacity;cache;keyOrder;constructor(t){this.capacity=t,this.cache=new Map,this.keyOrder=[]}get(t){if(this.cache.has(t))return this.keyOrder=this.keyOrder.filter(i=>i!==t),this.keyOrder.push(t),this.cache.get(t)}has(t){return this.cache.has(t)}set(t,i){if(this.cache.has(t))this.keyOrder=this.keyOrder.filter(r=>r!==t);else if(this.cache.size>=this.capacity){const r=this.keyOrder.shift();r!==void 0&&this.cache.delete(r)}this.cache.set(t,i),this.keyOrder.push(t)}delete(t){this.cache.delete(t),this.keyOrder=this.keyOrder.filter(i=>i!==t)}clear(){this.cache.clear(),this.keyOrder=[]}size(){return this.cache.size}}var Ln=Object.defineProperty,fe=O((e,t)=>Ln(e,"name",{value:t,configurable:!0}),"p$3");const li=new Fn(100),_n=new Intl.Segmenter("en",{granularity:"grapheme"}),Hn=/^[\u0000-\u007F]*$/,Gn=new Set(["0","22","23","24","27","28","29","39","49"]),Vn=new Set(["1","3","4","7","8","9"]),ci=new Map([["22","1"],["23","3"],["24","4"],["27","7"],["28","8"],["29","9"]]),Ee=fe(e=>e>="30"&&e<="37"||e>="90"&&e<="97"||e.startsWith("38;"),"isForegroundColor"),ke=fe(e=>e>="40"&&e<="47"||e>="100"&&e<="107"||e.startsWith("48;"),"isBackgroundColor"),Jn=[{close:"\x1B[22m",open:"\x1B[1m"},{close:"\x1B[23m",open:"\x1B[3m"},{close:"\x1B[24m",open:"\x1B[4m"},{close:"\x1B[27m",open:"\x1B[7m"},{close:"\x1B[28m",open:"\x1B[8m"},{close:"\x1B[29m",open:"\x1B[9m"}],hi=fe((e,t)=>{let i=-1;for(const r of t){const s=e.indexOf(r);s!==-1&&(i===-1||s<i)&&(i=s)}return i},"findFirstPositionOfAny"),zn=fe((e,t)=>{if(!e.includes("\x1B"))return[{after:"",before:"",content:e,visibleLength:E(e,t.width)}];const i=li.get(e);if(i)return i;const r=[],s=[];let o=0,n;for(X.lastIndex=0;(n=X.exec(e))!==null;){const c=n[0];r.push(e.slice(o,n.index)),s.push(c),o=n.index+c.length}o<e.length&&r.push(e.slice(o));const a=[];for(const c of s){if(c==="\x1B[0m"||c==="\x1B]8;;\x07"){a.push(c);continue}if(c.startsWith("\x1B[")&&c.endsWith("m")){const d=c.slice(2,-1);if(Gn.has(d)){a.push(c);continue}}}const l=new Set,h=[];for(const[c,d]of r.entries()){if(c>0&&s[c-1]){const f=s[c-1];if(f==="\x1B[0m")l.clear();else if(f==="\x1B]8;;\x07"){for(const p of l)if(p.startsWith("\x1B]8;;")&&!p.endsWith("\x1B]8;;\x07")){l.delete(p);break}}else if(f.startsWith("\x1B[")&&f.endsWith("m")){const p=f.slice(2,-1);if(p==="39"){for(const m of l)if(m.startsWith("\x1B[")&&m.endsWith("m")){const u=m.slice(2,-1);if(Ee(u)){l.delete(m);break}}}else if(p==="49"){for(const m of l)if(m.startsWith("\x1B[")&&m.endsWith("m")){const u=m.slice(2,-1);if(ke(u)){l.delete(m);break}}}else if(ci.has(p)){const m=ci.get(p);for(const u of l)if(u===`\x1B[${m}m`){l.delete(u);break}}else{if(Ee(p)){for(const m of l)if(m.startsWith("\x1B[")&&m.endsWith("m")){const u=m.slice(2,-1);if(Ee(u)){l.delete(m);break}}}else if(ke(p)){for(const m of l)if(m.startsWith("\x1B[")&&m.endsWith("m")){const u=m.slice(2,-1);if(ke(u)){l.delete(m);break}}}else if(Vn.has(p)){const m=`\x1B[${p}m`;l.has(m)&&l.delete(m)}l.add(f)}}else if(f.startsWith("\x1B]8;;")&&!f.endsWith("\x1B]8;;\x07")){for(const p of l)if(p.startsWith("\x1B]8;;")&&!p.endsWith("\x1B]8;;\x07")){l.delete(p);break}l.add(f)}}if(d==="")continue;let g="";if(l.size>0)if(a.includes("\x1B[0m"))g="\x1B[0m";else{const f=[];let p=!1;for(const w of l)if(w.startsWith("\x1B]8;;")&&!w.endsWith("\x1B]8;;\x07")){p=!0;break}p&&a.includes("\x1B]8;;\x07")&&f.push("\x1B]8;;\x07");let m=!1,u=!1;for(const w of l)if(w.startsWith("\x1B[")&&w.endsWith("m")){const v=w.slice(2,-1);Ee(v)?m=!0:ke(v)&&(u=!0)}if(m&&u){const w=hi(e,["\x1B[3","\x1B[9","\x1B[38;"]),v=hi(e,["\x1B[4","\x1B[10","\x1B[48;"]);w>=0&&v>=0?w>v?f.push("\x1B[39m","\x1B[49m"):f.push("\x1B[49m","\x1B[39m"):f.push("\x1B[39m","\x1B[49m")}else m&&f.push("\x1B[39m"),u&&f.push("\x1B[49m");m&&u&&e.includes("\x1B[39m")&&e.includes("\x1B[49m")&&(e.indexOf("\x1B[39m")<e.indexOf("\x1B[49m")?(f.length-=2,f.push("\x1B[39m","\x1B[49m")):e.indexOf("\x1B[49m")<e.indexOf("\x1B[39m")&&(f.length-=2,f.push("\x1B[49m","\x1B[39m")));const $=Jn.filter(w=>l.has(w.open)).map(w=>({position:e.indexOf(w.open),style:w})).filter(w=>w.position>=0).toSorted((w,v)=>v.position-w.position);for(const w of $){const v=w;a.includes(v.style.close)&&f.push(v.style.close)}g=f.join("")}const b=[...l].join("");h.push({after:g,before:b,content:d,visibleLength:E(d,{fullWidth:1,wideWidth:1})})}return li.set(e,h),h},"processIntoStyledSegments"),qn=fe((e,t,i,r)=>{const s=[...r.segmenter.segment(e)],o=[];let n=0,a=!1;for(const l of s){const h=E(l.segment,r.width),c=n,d=n+h;if(!a)if(c<t){n=d;continue}else a=!0;if(c>=i||d>i)break;o.push(l.segment),n=d}return o.join("")},"fastSlice"),U=fe((e,t=0,i=Number.MAX_SAFE_INTEGER,r={})=>{const s={segmenter:_n,...r};if(t>=i||e==="")return"";const o=E(e,s.width);if(t===0&&i>=o)return e;if(t<0||i<0)throw new RangeError("Negative indices aren't supported");if(!e.includes("\x1B"))return Hn.test(e)?e.slice(t,i):qn(e,t,i,s);if(oi.lastIndex=0,si.lastIndex=0,!oi.test(e)&&!si.test(e))return e;const n=zn(e,s);if(n.length===0)return"";let a=0;const l=[];for(const[d,g]of n.entries()){const b=a,f=a+g.visibleLength;if(f>t&&b<i){const p=Math.max(0,t-b),m=Math.min(g.visibleLength,i-b);l.push({end:m,index:d,segment:g,start:p})}a=f}if(l.length===0)return"";const h=[],c=l[0].segment;h.push(c.before);for(let d=0;d<l.length;d++){const{end:g,segment:b,start:f}=l[d];if(f===0&&g===b.visibleLength)h.push(b.content);else{const p=[...s.segmenter.segment(b.content)];h.push(p.slice(f,g).map(m=>m.segment).join(""))}if(d<l.length-1){const p=l[d+1].segment,m=b.after,u=p.before;m!==u&&(m||u)&&h.push(m,u)}}return h.push(l.at(-1).segment.after),h.join("")},"slice");var Un=Object.defineProperty,dt=O((e,t)=>Un(e,"name",{value:t,configurable:!0}),"u$3");const di="…",Dn=3,Re=dt((e,t,i=!1)=>{if(e.charAt(t)===" ")return t;const r=i?1:-1,s=Math.min(Dn,i?e.length-t:t);for(let o=1;o<=s;o++){const n=t+o*r;if(e.charAt(n)===" ")return n}return t},"findNearestSpace"),Me=dt((e,t,i)=>de(e,{...i,ellipsis:"",ellipsisWidth:0,limit:t}).index,"widthToIndex"),Pe=dt((e,t,i)=>E(e.slice(0,t),i),"indexToWidth"),ui=dt((e,t,i={})=>{if(typeof e!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof e}`);if(typeof t!="number")throw new TypeError(`Expected \`limit\` to be a number, got ${typeof t}`);if(e===""||t<=0)return"";const r=e.normalize("NFC"),{ellipsis:s=di,position:o="end",preferTruncationOnSpace:n=!1}=i;let a=i.ellipsisWidth??s===di?1:void 0;a??=de(s,{...i.width,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width;const{width:l}=de(r,{...i.width,ellipsis:s,ellipsisWidth:a});if(l<=t)return r;switch(o){case"end":{if(n){const h=t-a,c=Me(r,h,i.width),d=Re(r,c),g=Pe(r,d,i.width);return U(r,0,g,{width:i.width})+s}return U(r,0,t-a,{width:i.width})+s}case"middle":{const h=Math.floor(t/2),c=Math.max(0,t-a),d=Math.min(h,c),g=Math.max(0,c-d);if(n){const b=Me(r,d,i.width),f=Re(r,b),p=Pe(r,f,i.width),m=l-g,u=Me(r,m,i.width),$=Re(r,u,!0),w=Pe(r,$,i.width);return U(r,0,p,{width:i.width})+s+U(r,w,l,{width:i.width}).trim()}return U(r,0,d,{width:i.width})+s+U(r,l-g,l,{width:i.width})}case"start":{if(n){const h=l-t+a,c=Me(r,h,i.width),d=Re(r,c,!0),g=Pe(r,d,i.width);return s+U(r,g,l,{width:i.width}).trim()}return s+U(r,l-t+a,l,{width:i.width})}default:throw new Error(`Invalid position: expected 'start', 'middle' or 'end', got '${o}'`)}},"truncate");var Yn=Object.defineProperty,T=O((e,t)=>Yn(e,"name",{value:t,configurable:!0}),"p$2");const Kn=/\x1B\[(\d+)m/;class Hi{static{B(this,"se")}static{J(this,"re")}static{O(this,"C")}static{T(this,"AnsiStateTracker")}activeForeground=void 0;activeBackground=void 0;activeFormatting=[];processEscape(t){const i=Kn.exec(t);if(!i)return;const r=Number.parseInt(i[1],10);switch(r){case 0:{this.activeForeground=void 0,this.activeBackground=void 0,this.activeFormatting=[];break}case 39:{this.activeForeground=void 0;break}case 49:{this.activeBackground=void 0;break}default:if(r>=30&&r<=37||r>=90&&r<=97)this.activeForeground=t;else if(r>=40&&r<=47||r>=100&&r<=107)this.activeBackground=t;else if([1,2,3,4,7,8,9].includes(r))this.activeFormatting.push(t);else if([22,23,24,27,28,29].includes(r)){const s={22:"[1m",23:"[3m",24:"[4m",27:"[7m",28:"[8m",29:"[9m"}[r];s&&(this.activeFormatting=this.activeFormatting.filter(o=>!o.includes(s)))}}}getStartEscapesForAllActiveAttributes(){return[this.activeBackground,this.activeForeground,...this.activeFormatting].filter(Boolean).join("")}getEndEscapesForAllActiveAttributes(){const t=[];if(this.activeFormatting.length>0){const i={"\x1B[1m":"\x1B[22m","\x1B[2m":"\x1B[22m","\x1B[3m":"\x1B[23m","\x1B[4m":"\x1B[24m","\x1B[7m":"\x1B[27m","\x1B[8m":"\x1B[28m","\x1B[9m":"\x1B[29m"};[...this.activeFormatting].toReversed().forEach(r=>{const s=i[r];s&&t.push(s)})}return this.activeForeground&&t.push("\x1B[39m"),this.activeBackground&&t.push("\x1B[49m"),t.join("")}}const Gi=T((e,t)=>{if(!ue.has(e[t]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const i=!0,r=e.slice(t+1,t+1+Ue.length).join("")===Ue;return{isInsideEscape:i,isInsideLinkEscape:r}},"checkEscapeSequence"),Zn=T((e,t={})=>{const i=new Hi;let r="",s=!1,o="",n="",a=!1;const l=[...e];for(let h=0;h<l.length;h++){const c=l[h];if(c&&ue.has(c)){if(r){const p=t.getWidth?.(r)??0,m={isEscapeSequence:!1,isGrapheme:!0,text:r,width:p};if(a&&(m.isHyperlink=!0,m.hyperlinkUrl=n),t.onSegment?.(m,i)===!1)return;r=""}s=!0,o=c;const b=Gi(l,h),{isInsideLinkEscape:f}=b;if(f){let p=h+1;for(n="";p<l.length;){const u=l[p];if(u===ct)break;n+=u,p+=1}n=n.slice(4);const m={hyperlinkUrl:n,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(t.onSegment?.(m,i)===!1)return;h=p,a=!0,s=!1,o="";continue}if(h+1<l.length&&l[h+1]==="\\"&&a){const p={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(t.onSegment?.(p,i)===!1)return;a=!1,n="",h+=1,s=!1,o="";continue}}if(s){if(o!==c&&(o+=c),c===Kt){s=!1,i.processEscape(o);const b={isEscapeSequence:!0,isGrapheme:!1,text:o,width:0};if(t.onSegment?.(b,i)===!1)return;o=""}continue}r+=c;const d=t.getWidth?.(r)??0,g={isEscapeSequence:!1,isGrapheme:!0,text:r,width:d};if(a&&(g.isHyperlink=!0,g.hyperlinkUrl=n),t.onSegment?.(g,i)===!1)return;r=""}if(r){const h=t.getWidth?.(r)??0,c={isEscapeSequence:!1,isGrapheme:!0,text:r,width:h};a&&(c.isHyperlink=!0,c.hyperlinkUrl=n),t.onSegment?.(c,i)}if(o){const h={isEscapeSequence:!0,isGrapheme:!1,text:o,width:0};t.onSegment?.(h,i)}},"processAnsiString"),fi=T(e=>`${ue.values().next().value}${_i}${String(e)}${Kt}`,"wrapAnsiCode"),mi=T(e=>`${ue.values().next().value}${Ue}${e}${ct}`,"wrapAnsiHyperlink"),Qn=T(e=>{if(e.length===0)return"";if(e.length===1)return e[0];let t="",i,r;const s=e.join(`
|
|
2
|
+
`),o=[...s];let n=0;for(const[a,l]of o.entries()){if(t+=l,ue.has(l)){const c=Cn.exec(s.slice(n))?.groups??{};if(c.code!==void 0){const d=Number.parseFloat(c.code);i=d===On?void 0:d}else c.uri!==void 0&&(r=c.uri.length===0?void 0:c.uri)}const h=Nn.get(Number(i));o[a+1]===`
|
|
3
|
+
`?(r&&(t+=mi("")),i&&h&&(t+=fi(h))):l===`
|
|
4
|
+
`&&(i&&h&&(t+=fi(i)),r&&(t+=mi(r))),n+=l.length}return t},"preserveAnsi"),Vi=/(?=\s)|(?<=\s)/,Ji=/^\s+$/,$t=T(e=>{if(!e.includes("\x1B"))return e;let t=e;return e.includes("\x1B[30m")&&(t+="\x1B[39m"),e.includes("\x1B[42m")&&(t+="\x1B[49m"),t},"resetAnsiAtLineBreak"),ie=T(e=>{const t=e.split(" ");let i=t.length;for(;i>0&&E(t[i-1])===0;)i--;return i===t.length?e:t.slice(0,i).join(" ")+t.slice(i).join("")},"stringVisibleTrimSpacesRight"),zi=T((e,t,i)=>{if(e.length===0)return[""];if(t<=0)return[e];const r=[],s=new Hi;let o="",n=0,a=!1,l=!1,h="",c=0;for(;c<e.length;){const d=e[c];if(ue.has(d)){a=!0,h=d,o+=d,l=Gi([...e],c).isInsideLinkEscape,c+=1;continue}if(a){h+=d,o+=d,l?d===ct&&(a=l=!1):d===Kt&&(a=!1,s.processEscape(h)),c+=1;continue}const g=E(d),b=d===" ";if(g===0){o+=d,c+=1;continue}if(n+g>t&&(o&&r.push(o+s.getEndEscapesForAllActiveAttributes()),o=s.getStartEscapesForAllActiveAttributes(),n=E(o),b&&i)){for(;c<e.length&&e[c]===" ";)c+=1;continue}if(o+=d,n+=g,n===t&&c<e.length-1&&(r.push(o+s.getEndEscapesForAllActiveAttributes()),o=s.getStartEscapesForAllActiveAttributes(),n=E(o),c+1<e.length&&e[c+1]===" "&&i)){for(c+=1;c<e.length&&e[c]===" ";)c+=1;continue}c+=1}return o&&r.push(o+s.getEndEscapesForAllActiveAttributes()),i?r.map(d=>ie(d)):r},"wrapWithBreakAtWidth"),Xn=T((e,t,i)=>{if(e.length===0)return[];const r=i?e.trim():e;if(r.length===0)return[];const s=[];let o="",n=0;return Zn(r,{getWidth:E,onSegment:T((a,l)=>{const h=a.text??"";if(a.isEscapeSequence)o+=h;else{const c=h===" ";if(a.width===0)return o+=h,!0;if(n+a.width>t&&(o&&s.push(o),o=l.getStartEscapesForAllActiveAttributes(),n=0,c))return i||s.push(l.getStartEscapesForAllActiveAttributes()+h),!0;o+=h,n+=a.width}return!0},"onSegment")}),o&&s.push(o),i?s.map(a=>ie(a)):s},"wrapCharByChar"),eo=T((e,t,i)=>{if(e.length===0)return[];const r=i?e.trim():e;if(r.length===0)return[];const s=r.split(Vi),o=[];let n="",a=0,l=0;for(;l<s.length;){const h=s[l],c=Ji.test(h),d=E(h);if(h.length===0){l+=1;continue}if(i&&c&&a===0){l+=1;continue}if(a+d>t&&a>0){i?o.push(ie(n)):o.push(n),n="",a=0;continue}n+=h,a+=d,l+=1}return n&&(i?o.push(ie(n)):o.push(n)),o},"wrapWithWordBoundaries"),to=T((e,t,i)=>{if(e.length===0)return[];const r=i?e.trim():e;if(r.length===0)return[];const s=r.split(Vi),o=[];let n="",a=0,l=0;for(;l<s.length;){const h=s[l],c=Ji.test(h),d=E(h);if(h.length===0){l+=1;continue}if(i&&c&&a===0){l+=1;continue}if(d>t){n&&o.push($t(i?ie(n):n));const g=zi(h,t,i);if(g.length>0){for(let b=0;b<g.length-1;b+=1)o.push(g[b]);n=g.at(-1),a=E(n)}else n="",a=0;l+=1;continue}if(a+d>t&&a>0&&(o.push($t(i?ie(n):n)),n="",a=0,i&&c)){l+=1;continue}n+=h,a+=d,l+=1}return n&&o.push($t(i?ie(n):n)),o},"wrapAndBreakWords"),Te={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},io=T((e,t={})=>{const{removeZeroWidthCharacters:i=!0,trim:r=!0,width:s=80,wrapMode:o=Te.PRESERVE_WORDS}=t;if(r&&e.trim()==="")return"";let n=e.normalize("NFC").replaceAll(`\r
|
|
5
|
+
`,`
|
|
6
|
+
`);return i&&(n=n.replaceAll(In,"")),n.split(`
|
|
7
|
+
`).map(a=>{if(r&&a.trim()==="")return"";let l;switch(o){case Te.BREAK_AT_CHARACTERS:{l=Xn(a,s,r);break}case Te.BREAK_WORDS:{l=to(a,s,r);break}case Te.STRICT_WIDTH:{l=zi(a,s,r);break}default:l=eo(a,s,r)}return Qn(l)}).join(`
|
|
8
|
+
`)},"wordWrap");var ro=Object.defineProperty,Z=O((e,t)=>ro(e,"name",{value:t,configurable:!0}),"n$3");const qi=80,Ui=24,St=Z((e,t,{shell:i,env:r}={})=>an(e,t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:500,shell:i,env:r}).trim(),"exec"),He=Z((e,t)=>({columns:Number.parseInt(e,10),rows:Number.parseInt(t,10)}),"create"),Di=Z((e,t)=>{const{columns:i,rows:r}=He(e,t);if(!(Number.isNaN(i)||Number.isNaN(r))&&!(i===qi&&r===Ui))return{columns:i,rows:r}},"createIfNotDefault"),no=Z(()=>{if(te.platform!=="linux")return!0;try{const e=ve.readFileSync("/proc/self/stat","utf8"),t=e.lastIndexOf(") ");if(t===-1)return!1;const i=e.slice(t+2).trim().split(/\s+/),r=Number.parseInt(i[2],10),s=Number.parseInt(i[5],10);return Number.isNaN(r)||Number.isNaN(s)||s<=0?!1:r===s}catch{return!1}},"isForegroundProcess");function ut(){const{env:e,stdout:t,stderr:i}=te;if(t?.columns&&t?.rows)return He(t.columns,t.rows);if(i?.columns&&i?.rows)return He(i.columns,i.rows);if(e.COLUMNS&&e.LINES)return He(e.COLUMNS,e.LINES);const r={columns:qi,rows:Ui};return te.platform==="win32"?xt()??r:te.platform==="darwin"?pi()??xt()??r:pi()??xt()??oo()??r}B(ut,"Tt");J(ut,"de");O(ut,"O");Z(ut,"terminalSize");const pi=Z(()=>{try{const e=te.platform==="darwin"?ve.constants.O_EVTONLY|ve.constants.O_NONBLOCK:ve.constants.O_NONBLOCK,{columns:t,rows:i}=ln.WriteStream(ve.openSync("/dev/tty",e));return{columns:t,rows:i}}catch{}},"devTty"),xt=Z(()=>{try{const e=St("tput",["cols"],{env:{TERM:"dumb",...te.env}}),t=St("tput",["lines"],{env:{TERM:"dumb",...te.env}});if(e&&t)return Di(e,t)}catch{}},"tput"),oo=Z(()=>{try{if(!no())return;const e=St("resize",["-u"]).match(/\d+/g);if(e.length===2)return Di(e[0],e[1])}catch{}},"resize");var so=Object.defineProperty,Yi=O((e,t)=>so(e,"name",{value:t,configurable:!0}),"e");const se=Yi((e,t)=>{switch(t){case"bottom":return{body:e.bottomBody,join:e.bottomJoin,left:e.bottomLeft,right:e.bottomRight};case"middle":return{body:e.joinBody,join:e.joinJoin,left:e.joinLeft,right:e.joinRight};case"top":return{body:e.topBody,join:e.topJoin,left:e.topLeft,right:e.topRight};default:throw new Error(`Invalid borderType: ${String(t)}`)}},"getHorizontalBorderChars"),ao=Yi(e=>({join:e.bodyJoin,left:e.bodyLeft,right:e.bodyRight}),"getVerticalBorderChars");var lo=Object.defineProperty,co=O((e,t)=>lo(e,"name",{value:t,configurable:!0}),"n$1");const De=co((e,t,i)=>{let r=0;for(let s=0;s<i;s+=1)r+=e[t+s]??0;return i>1&&(r+=i-1),r},"calculateCellTotalWidth");var ho=Object.defineProperty,uo=O((e,t)=>ho(e,"name",{value:t,configurable:!0}),"a");const At=uo((e,t,i,r)=>{let s=t;for(;s>0&&e[s-1]?.[i]===r;)s-=1;let o=t;for(;o<e.length-1&&e[o+1]?.[i]===r;)o+=1;let n;const a=o-s+1;if(a===1)n=!0;else switch(r.vAlign){case"bottom":{n=t===o;break}case"middle":{const l=s+Math.floor(a/2);n=t===l;break}case"top":{n=t===s;break}default:n=t===s}return{firstRow:s,lastRow:o,showContent:n}},"determineCellVerticalPosition");var fo=Object.defineProperty,mo=O((e,t)=>fo(e,"name",{value:t,configurable:!0}),"F");const po=mo((e,t,i,r,s)=>{if(e.length===0)return[];let o=e.length-1;for(let l=0;l<e.length;l+=1){const h=e[l];if(h){for(const[c,d]of h.entries())if(d&&s(e,l,c,d)===l){const g=At(e,l,c,d);o=Math.max(o,g.lastRow)}}}const n=Array.from({length:o+1}).fill(1);for(let l=0;l<e.length;l+=1){const h=e[l];if(h)for(let c=0;c<i.columns;c+=1){const d=h[c];if(d&&s(e,l,c,d)===l&&(d.rowSpan??1)===1){const g=d.colSpan??1,b=De(t,c,g),f=r(d,b).length;n[l]=Math.max(n[l]??1,f)}}}const a=Array.from({length:n.length}).fill(!1);if(i.fixedRowHeights)for(let l=0;l<n.length;l+=1){let h;i.fixedRowHeights[l]!==void 0?h=i.fixedRowHeights[l]:i.fixedRowHeights.length===1&&i.fixedRowHeights[0]!==void 0&&(h=i.fixedRowHeights[0]),h!==void 0&&(n[l]=Math.max(1,h),a[l]=!0)}for(let l=0;l<e.length;l+=1){const h=e[l];if(h)for(let c=0;c<i.columns;c+=1){const d=h[c];if(d&&s(e,l,c,d)===l&&(d.rowSpan??1)>1){const g=d.colSpan??1,b=De(t,c,g),f=r(d,b).length-1,p=At(e,l,c,d),{firstRow:m,lastRow:u}=p;let $=0,w=0;for(let x=m;x<=u&&x<n.length;x+=1)$+=n[x]??1,a[x]||(w+=1);const v=f-$;if(v>0)if(w>0){const x=Math.ceil(v/w);let W=0;for(let S=m;S<=u&&S<n.length;S+=1)if(!a[S]){const I=Math.min(x,v-W);if(n[S]=(n[S]??1)+I,W+=I,W>=v)break}}else console.warn(`[calculateRowHeights] Content of spanning cell exceeds fixed height allocated. Cell: ${JSON.stringify(d.content)}, Required: ${String(f)}, Allocated: ${String($)} (fixed).`)}}}return n},"calculateRowHeights");var go=Object.defineProperty,bo=O((e,t)=>go(e,"name",{value:t,configurable:!0}),"i");const ae=bo((e,t,i,r)=>{let s=t;for(;s>0&&e[s-1]?.[i]===r;)s-=1;return s},"findFirstOccurrenceRow");var wo=Object.defineProperty,yo=O((e,t)=>wo(e,"name",{value:t,configurable:!0}),"n");const Ot="__EMPTY__",gi=yo(e=>{if(typeof e=="string")return{content:e};if(typeof e=="number"||typeof e=="bigint"||typeof e=="boolean")return{content:String(e)};if(e==null)return{content:Ot};if(typeof e=="object"&&"content"in e){let{content:t}=e;if(typeof t=="number"||typeof t=="bigint"||typeof t=="boolean")t=String(t);else if(t==null)t=Ot;else if(typeof t!="string")throw new TypeError(`Invalid item type in grid cell: expected string, number, null, undefined, or GridItem object, but received ${JSON.stringify(e)} (type: ${typeof e})`);return{...e,content:t}}throw new TypeError(`Invalid item type in grid cell: expected string, number, null, undefined, or GridItem object, but received ${JSON.stringify(e)} (type: ${typeof e})`)},"normalizeGridCell");var vo=Object.defineProperty,$o=O((e,t)=>vo(e,"name",{value:t,configurable:!0}),"p");const xo=$o((e,t,i,r,s)=>{const o=E(e),n=" ".repeat(Math.max(0,r)),a=" ".repeat(Math.max(0,s));if(o===0)return n+" ".repeat(Math.max(0,t))+a;const l=Math.max(0,t-o);switch(i){case"center":{const h=Math.floor(l/2),c=l-h;return n+" ".repeat(h)+e+" ".repeat(c)+a}case"right":return n+" ".repeat(l)+e+a;default:return n+e+" ".repeat(l)+a}},"padAndAlignContent");var Wo=Object.defineProperty,Zt=O((e,t)=>Wo(e,"name",{value:t,configurable:!0}),"H");const ge=/\r?\n/,bi=/\s+/,A=Zt((e,t)=>!e||!t?e:typeof t=="function"?t(e):t.open+e+t.close,"applyColor");class ft{static{B(this,"xt")}static{J(this,"Nt")}static{O(this,"Grid")}static{Zt(this,"Grid")}#e;#n=[];#t;#o=new WeakMap;#i=new WeakMap;static createGridLayout(){return[]}constructor(t){const i={autoColumns:1,autoFlow:"row",autoRows:1,balancedWidths:!1,gap:0,paddingLeft:1,paddingRight:1,rows:0,showBorders:t.border!==void 0,truncate:!1,truncateOverflow:!0,wordWrap:!1};let r;Array.isArray(t.fixedRowHeights)?r=t.fixedRowHeights:typeof t.fixedRowHeights=="number"&&(r=[t.fixedRowHeights]),this.#e={...i,...t,columns:t.columns,fixedRowHeights:r,showBorders:t.border!==void 0||(t.showBorders??!1)};let{terminalWidth:s}=this.#e;if(s===void 0){const{columns:o}=ut();s=o}this.#t=s,this.#e.maxWidth&&(this.#e.maxWidth=Math.min(this.#e.maxWidth,this.#t))}addItem(t){return this.#n.push(gi(t)),this}addItems(t){return this.#n.push(...t.map(i=>gi(i))),this}setColumns(t){return this.#e.columns=t,this}setRows(t){return this.#e.rows=t,this}setBorder(t){return this.#e.border=t,this}setShowBorders(t){return this.#e.showBorders=t,this}setMaxWidth(t){return this.#e.maxWidth=t,this}toString(){const t=ft.createGridLayout();if(this.placeItems(t),t.length===0||t[0]?.length===0)return"";let i=this.calculateColumnWidths(t);const r=this.calculateTotalGridWidth(i),s=typeof this.#e.maxWidth=="number"&&this.#e.maxWidth>0?Math.min(this.#e.maxWidth,this.#t):this.#t;return r>s&&(i=this.adjustColumnWidthsForTerminal(i,r)),this.renderGrid(t,i)}placeItems(t){let i=0,r=0;const s=this.#e.rows>0?this.#e.rows:Number.POSITIVE_INFINITY;for(let o=0;o<this.#n.length;o+=1){const n=this.#n[o];if(n.content===Ot&&!(n.rowSpan&&n.rowSpan>1)&&!(n.colSpan&&n.colSpan>1)){if(this.#e.autoFlow==="row")r+=1,r>=this.#e.columns&&(r=0,i+=1);else{i+=1;const f=t.length>0?t.length:s;i>=f&&f!==Number.POSITIVE_INFINITY?(i=0,r+=1):t.length===0&&f===Number.POSITIVE_INFINITY&&(r+=1)}continue}const a=n.colSpan??1,l=n.rowSpan??1;let h=!1,c=i,d=r,g=0;const b=(t.length+l+5)*this.#e.columns;for(;!h&&c<s&&g<b;){for(g+=1;c+l>t.length;)t.push(Array.from({length:this.#e.columns}).fill(void 0));if(this.canPlaceItem(t,c,d,a,l))if(this.placeItem(t,c,d,n),h=!0,this.#e.autoFlow==="row")r=d+a,i=c,r>=this.#e.columns&&(r=0,i+=1);else{i=c+l,r=d;const f=t.length>0?t.length:s;i>=f&&(i=0,r+=1)}else if(this.#e.autoFlow==="row")d+=1,d>=this.#e.columns&&(d=0,c+=1);else{for(c+=1;c+l>t.length;)t.push(Array.from({length:this.#e.columns}).fill(void 0));const f=t.length>0?t.length:s;if(c>=f&&(c=0,d+=1,d>=this.#e.columns))break}}if(!h)if(console.warn(`@visulima/tabular: Could not find position for item: ${JSON.stringify(n)} after ${String(g)} attempts. Grid might be too small or layout impossible.`),this.#e.autoFlow==="row")r+=1,r>=this.#e.columns&&(r=0,i+=1);else{i+=1;const f=t.length>0?t.length:s;i>=f&&(i=0,r+=1)}if(g>=b)break}if(this.#e.rows===0)for(;t.length>0&&t.at(-1)?.every(o=>o===void 0);)t.pop()}canPlaceItem(t,i,r,s,o,n=!1){if(r+s>this.#e.columns)return!1;for(let a=i;a<i+o;a+=1)if(a<t.length){if(!t[a])return console.warn(`Grid layout unexpectedly missing row ${String(a)} during canPlaceItem check.`),!1;for(let l=r;l<r+s;l+=1)if(t[a]?.[l]!==void 0)return!1}else if(!n)return!1;return!0}computeWrappedContentWidth(t,i,r,s){let o=t;if(s){if(o>20){let n=0;for(const a of i){const l=a.split(bi);for(const h of l)n=Math.max(n,Math.min(E(h),r))}o=Math.min(o,Math.max(n+4,12))}}else{let n=0;for(const a of i){const l=a.split(bi);for(const h of l)n=Math.max(n,Math.min(E(h),r))}o=Math.min(o,Math.max(n+12,20))}return o}placeItem(t,i,r,s){const o=s.rowSpan??1,n=s.colSpan??1;for(let a=i;a<i+o;a+=1){for(;a>=t.length;)t.push(Array.from({length:this.#e.columns}).fill(void 0));for(let l=r;l<r+n;l+=1)l<this.#e.columns&&(t[a]||(console.error(`Logic error: Row ${String(a)} not found in placeItem despite check.`),t[a]=Array.from({length:this.#e.columns}).fill(void 0)),t[a][l]=s)}}calculateTotalGridWidth(t){let i=0;const r=this.#e.showBorders?this.#e.border:void 0;r&&(i+=r.bodyLeft.width,i+=r.bodyRight.width);const s=t.length,o=this.#e.showBorders?r?.bodyJoin.width??0:0,n=this.#e.gap;for(let a=0;a<s;a+=1)i+=t[a]??0,a<s-1&&(i+=n,i+=o);return i}adjustColumnWidthsForTerminal(t,i){const r=typeof this.#e.maxWidth=="number"&&this.#e.maxWidth>0?Math.min(this.#e.maxWidth??0,this.#t):this.#t;if(i<=r)return t;let s=0;const o=t.length,n=this.#e.showBorders?this.#e.border:void 0;if(n&&(s+=n.bodyLeft.width,s+=n.bodyRight.width),o>1){s+=(o-1)*this.#e.gap;const d=n?.bodyJoin.width??0;s+=(o-1)*d}if(s>=r)return Array.from({length:o}).fill(1);const a=r-s,l=t.reduce((d,g)=>d+g,0);if(l===0){const d=Math.floor(a/o);return Array.from({length:o}).fill(d)}const h=t.map(d=>{const g=d/l;return Math.max(1,Math.floor(a*g))});let c=a-h.reduce((d,g)=>d+g,0);if(c>0){const d=h.map((g,b)=>{const f=l>0?(t[b]??0)/l:1/o;return{index:b,remainder:a*f%1}}).toSorted((g,b)=>b.remainder-g.remainder);for(const g of d){if(c<=0)break;const{index:b}=g;h[b]!==void 0&&(h[b]+=1,c-=1)}}return h}calculateBalancedColumnWidths(t){const i=this.calculateMinimumColumnWidthsWithGrowableInfo(t),r=i.widths,{growableColumns:s}=i,o=typeof this.#e.maxWidth=="number"&&this.#e.maxWidth>0?Math.min(this.#e.maxWidth,this.#t):this.#t,n=this.#e.showBorders?this.#e.border:void 0;let a=0;if(n&&(a+=n.bodyLeft.width,a+=n.bodyRight.width),this.#e.columns>1){a+=(this.#e.columns-1)*this.#e.gap;const c=n?.bodyJoin.width??0;a+=(this.#e.columns-1)*c}const l=Math.max(0,o-a);if(r.reduce((c,d)=>c+d,0)>0){const c=Math.floor(l/this.#e.columns),d=Array.from({length:this.#e.columns}).fill(c),g=c*this.#e.columns;let b=l-g;for(let u=0;u<d.length&&b>0;u+=1)d[u]=(d[u]??0)+1,b-=1;const f=[];let p=0;for(let u=0;u<this.#e.columns;u+=1){const $=d[u]??0,w=r[u]??0,v=Math.max($,w);f.push(v),p+=v}if(p>l){const u=l/p,$=f.map(x=>Math.max(3,Math.floor(x*u))),w=$.reduce((x,W)=>x+W,0);let v=l-w;for(let x=0;x<$.length&&v>0;x+=1)$[x]=($[x]??0)+1,v-=1;return $}let m=l-p;if(m>0){const u=s.length>0?s:f.map(($,w)=>w);for(;m>0&&u.length>0;)for(const $ of u){if(m<=0)break;f[$]=(f[$]??0)+1,m-=1}}return f}const h=Math.floor(l/this.#e.columns);return Array.from({length:this.#e.columns}).fill(h)}calculateMinimumColumnWidthsWithGrowableInfo(t){const i=Array.from({length:this.#e.columns}).fill(0),r=[],s=this.#e.paddingLeft+this.#e.paddingRight,o=this.#e.gap+(this.#e.showBorders?this.#e.border?.bodyJoin.width??0:0);for(let n=0;n<this.#e.columns;n+=1)for(let a=0;a<t.length;a+=1){const l=t[a]?.[n];if(!l||ae(t,a,n,l)!==a||n>0&&t[a]?.[n-1]===l)continue;const h=l.colSpan??1,c=l.maxWidth??Number.POSITIVE_INFINITY,d=String(l.content??"").split(ge),g=this.#e.wordWrap&&l.wordWrap!==!1;let b=0;for(const f of d)b=Math.max(b,Math.min(E(f),c));b=this.computeWrappedContentWidth(b,d,c,g),h===1&&(i[n]=Math.max(i[n]??0,b+s),g&&!r.includes(n)&&r.push(n))}for(let n=0;n<t.length;n+=1)for(let a=0;a<this.#e.columns;a+=1){const l=t[n]?.[a];if(!l||ae(t,n,a,l)!==n||a>0&&t[n]?.[a-1]===l)continue;const h=l.colSpan??1;if(h>1){const c=l.maxWidth??Number.POSITIVE_INFINITY,d=String(l.content??"").split(ge),g=this.#e.wordWrap&&l.wordWrap!==!1;let b=0;for(const u of d)b=Math.max(b,Math.min(E(u),c));b=this.computeWrappedContentWidth(b,d,c,g);const f=(h-1)*o,p=b+s+f;let m=0;for(let u=a;u<a+h;u+=1)m+=i[u]??0;if(p>m){const u=p-m,$=Math.ceil(u/h);for(let w=0;w<h&&a+w<this.#e.columns;w+=1)i[a+w]=Math.max(i[a+w]??0,$)}}}return{growableColumns:r,widths:i}}calculateColumnWidths(t){if(this.#e.fixedColumnWidths&&this.#e.fixedColumnWidths.length===this.#e.columns){const o=this.#e.fixedColumnWidths;if(!o.some(n=>n===void 0||!Number.isFinite(n)))return[...o];if(this.#e.balancedWidths){const n=Array.from({length:o.length}).fill(0),a=typeof this.#e.maxWidth=="number"&&this.#e.maxWidth>0?Math.min(this.#e.maxWidth,this.#t):this.#t,l=this.calculateTotalGridWidth(Array.from({length:n.length}).fill(0)),h=Math.max(0,a-l);let c=0;const d=[];for(const[f,p]of o.entries())typeof p=="number"&&Number.isFinite(p)?(n[f]=p,c+=p):d.push(f);let g=Math.max(0,h-c);const b=d.length>0?Math.floor(g/d.length):0;for(const f of d)n[f]=b;g-=b*d.length;for(const f of d){if(g<=0)break;n[f]+=1,g-=1}return n}}if(this.#e.balancedWidths)return this.calculateBalancedColumnWidths(t);const i=Array.from({length:this.#e.columns}).fill(0),r=this.#e.paddingLeft+this.#e.paddingRight,s=this.#e.gap+(this.#e.showBorders?this.#e.border?.bodyJoin.width??0:0);for(let o=0;o<this.#e.columns;o+=1)for(let n=0;n<t.length;n+=1){const a=t[n]?.[o];if(!a||ae(t,n,o,a)!==n||o>0&&t[n]?.[o-1]===a)continue;const l=a.colSpan??1,h=a.maxWidth??Number.POSITIVE_INFINITY,c=String(a.content??"").split(ge);let d=0;for(const g of c)d=Math.max(d,Math.min(E(g),h));l===1&&(i[o]=Math.max(i[o]??0,d+r))}for(let o=0;o<t.length;o+=1)for(let n=0;n<this.#e.columns;n+=1){const a=t[o]?.[n];if(!a||ae(t,o,n,a)!==o||n>0&&t[o]?.[n-1]===a)continue;const l=a.colSpan??1;if(l>1){const h=a.maxWidth??Number.POSITIVE_INFINITY,c=String(a.content??"").split(ge),d=this.#e.wordWrap&&a.wordWrap!==!1;let g=0;for(const u of c)g=Math.max(g,Math.min(E(u),h));g=this.computeWrappedContentWidth(g,c,h,d);let b=0;for(let u=n;u<n+l;u+=1)b+=i[u]??0;const f=l>1?(l-1)*s:0,p=g+r+f,m=b+f;if(p>m){const u=p-m,$=Math.floor(u/l);let w=0;for(let v=0;v<l&&n+v<this.#e.columns;v+=1){const x=Math.min($,u-w);if(i[n+v]=(i[n+v]??0)+x,w+=x,w>=u)break}}}}if(this.#e.maxWidth){const o=this.calculateTotalGridWidth(i);if(o>this.#e.maxWidth)return this.adjustColumnWidthsForTerminal(i,o)}return i}renderVisualRowContent(t,i,r,s,o){const n=t[i];if(!n)return"";const a=this.#e.borderColor??this.#e.foregroundColor??void 0,l=[],h=this.#e.showBorders&&this.#e.border?ao(this.#e.border):void 0,c=h&&h.left.width>0?h.left.char:"",d=h&&h.right.width>0?h.right.char:"",g=h&&h.join.width>0?h.join.char:"",b=" ".repeat(this.#e.gap);c&&l.push(A(A(c,a),this.#e.backgroundColor));let f=0;for(;f<this.#e.columns;){const p=n[f]??void 0;let m=1,u;if(p){const $=p.colSpan??1;m=$;const w=ae(t,i,f,p),v=De(s,f,$),x=this.alignCellContent(p,v),W=x.length,S=this.getCachedCellVerticalPosition(t,i,f,p);S.firstRow!==w&&console.warn(`Mismatch between findFirstOccurrenceRow (${String(w)}) and determineCellVerticalPosition (${String(S.firstRow)})`);const I=o.slice(w,S.lastRow+1).reduce((C,_)=>C+_,0),k=S.lastRow-S.firstRow+1;let F=r,L=0;for(let C=w;C<i;C+=1)C<o.length&&(F+=o[C]??1),C<S.lastRow&&(L+=1);F+=L;const q=p.vAlign??"top";let G;switch(q){case"bottom":{let C=r;for(let H=w;H<i;H+=1)C+=o[H]??1;const _=I-W;G=C>=_?C-_:-1;break}case"middle":{const C=Math.round((I-W)/2);let _=r;for(let H=w;H<i;H+=1)_+=o[H]??1;G=_>=C&&_<C+W?_-C:-1;break}case"top":{G=F;break}default:G=F}const wt=G>=0&&G<W;if(u=" ".repeat(Math.max(0,v)),wt){let C=!1;q==="middle"&&k%2===0&&G===0&&(C=!0),C||(u=x[G]??u)}p.colSpan&&p.colSpan>1&&(u+=b.repeat(p.colSpan)),p.foregroundColor?u=A(u,p.foregroundColor):this.#e.foregroundColor&&(u=A(u,this.#e.foregroundColor)),p.backgroundColor?u=A(u,p.backgroundColor):this.#e.backgroundColor&&(u=A(u,this.#e.backgroundColor))}else{const $=this.#e.paddingLeft+this.#e.paddingRight,w=Math.max(0,(s[f]??0)-$),v=" ".repeat(this.#e.paddingLeft+w+this.#e.paddingRight);u=A(A(r===0?v:" ".repeat(v.length),this.#e.foregroundColor),this.#e.backgroundColor)}l.push(u),f+m<this.#e.columns&&(l.push(b),this.#e.showBorders&&g&&l.push(A(A(g,a),this.#e.backgroundColor)),this.#e.gap>0&&l.push(b)),f+=m}return d&&l.push(A(A(d,a),this.#e.backgroundColor)),l.join("")}alignCellContent(t,i){const r=this.#o.get(t);if(r?.has(i))return r.get(i);const{paddingLeft:s,paddingRight:o}=this.#e,n=s+o,a=i-n;if(a<=0){const d=[" ".repeat(n+this.#e.gap)];return r?r.set(i,d):this.#o.set(t,new Map([[i,d]])),d}let l;const h=String(t.content??"");if(l=h.includes(`
|
|
9
|
+
`)||h.includes("\r")?h.split(ge):[h],this.#e.wordWrap&&t.wordWrap!==!1){const d=typeof this.#e.wordWrap=="object"?this.#e.wordWrap:{},g=typeof t.wordWrap=="object"?t.wordWrap:d;l=io(h,{...g,width:a}).split(`
|
|
10
|
+
`)}if(this.#e.truncate&&t.truncate!==!1){const d=typeof this.#e.truncate=="object"?this.#e.truncate:{},g=typeof t.truncate=="object"?t.truncate:d;l=l.map(b=>ui(b,a,g))}else this.#e.truncateOverflow&&(l=l.map(d=>E(d)>a?ui(d,a,{}):d));const c=l.map(d=>xo(d,a,t.hAlign??"left",s,o));return r?r.set(i,c):this.#o.set(t,new Map([[i,c]])),c}renderHorizontalBorder(t,i,r,s,o,n=-1){if(!this.#e.showBorders||!this.#e.border)return"";const a=this.#e.border,l=se(a,o),h=l.body.char,c=l.body.width,d=a.bodyJoin.char;if(o!=="middle"&&c===0)return"";let g=l.left.char,b=l.right.char;if(o==="middle"&&n!==-1){const u=t[r]?.[0]??void 0,$=t[n]?.[0]??void 0;u&&$&&u===$&&(g=d);const w=this.#e.columns-1,v=t[r]?.[w]??void 0,x=t[n]?.[w]??void 0;v&&x&&v===x&&(b=d)}const f=[],p=" ".repeat(this.#e.gap);g&&f.push(A(A(g,this.#e.borderColor),this.#e.backgroundColor));let m;for(let u=0;u<this.#e.columns;u+=1){const $=t[r]?.[u]??void 0,w=o==="middle"&&n!==-1?t[n]?.[u]??void 0:void 0;let v,x=!1;if($&&(u===0||t[r]?.[u-1]!==$)&&(v=$,x=!0),$&&!x)continue;if(!$){const I=s[u]??0;if(m=c>0?h.repeat(I):" ".repeat(I),f.push(A(A(m,this.#e.borderColor),this.#e.backgroundColor)),u<this.#e.columns-1){const k=this.determineJoinChar(o,t,r,n,u,u+1);f.push(p),k.width>0&&f.push(A(A(k.char,this.#e.borderColor),this.#e.backgroundColor))}continue}const W=v?.colSpan??1;if(o==="middle"&&o==="middle"&&w&&$===w&&v){const I=v.vAlign==="middle",{firstRow:k,lastRow:F}=this.getCachedCellVerticalPosition(t,r,u,v),L=F-k+1,q=L%2===0,G=k+Math.ceil(L/2)-1,wt=De(s,u,W),C=this.alignCellContent(v,wt),_=C.length;if(I&&q&&r===G)m=A(C[0]??"",this.#e.borderColor);else{let H=0;for(let oe=k;oe<=r;oe+=1)H+=i[oe]??1,oe<r&&(H+=1);const yt=H;if(yt>=0&&yt<_)m=A(C[yt]??"",this.#e.foregroundColor);else{const oe=s.slice(u,u+W).reduce((dr,ur)=>dr+ur,0)+(W-1)*(this.#e.gap+this.#e.border.bodyJoin.width);m=A(" ".repeat(oe),this.#e.borderColor)}}f.push(A(m,this.#e.backgroundColor))}else{const I=[];for(let k=u;k<u+W;k+=1){const F=s[k]??0,L=c>0?h:" ";if(I.push(L.repeat(F+this.#e.gap)),k<u+W-1){const q=this.determineJoinChar(o,t,r,n,k,k+1);q.width>0&&I.push(q.char)}}m=I.join(""),f.push(A(A(m,this.#e.borderColor),this.#e.backgroundColor))}const S=u+W-1;if(S<this.#e.columns-1){const I=this.determineJoinChar(o,t,r,n,S,S+1);I.width>0&&f.push(A(A(I.char,this.#e.borderColor),this.#e.backgroundColor))}u+=W-1}return b&&f.push(A(A(b,this.#e.borderColor),this.#e.backgroundColor)),f.join("")}determineJoinChar(t,i,r,s,o,n=-1){if(!this.#e.showBorders||!this.#e.border)return{char:" ",width:this.#e.gap};const a=this.#e.border;if(t!=="middle"){const x=se(a,t),W=i[r]?.[o]??void 0,S=n===-1?o+1:n,I=i[r]?.[S]??void 0,k=W!==void 0&&I!==void 0&&W===I?x.body:x.join,{char:F,width:L}=k;return{char:F,width:L>0?L:this.#e.gap}}if(s===-1||n===-1)return{char:" ",width:this.#e.gap};const l=a.bodyJoin,h=i[r]?.[o]??void 0,c=i[s]?.[o]??void 0,d=i[r]?.[n]??void 0,g=i[s]?.[n]??void 0,b=h!==void 0&&c!==void 0&&h===c,f=d!==void 0&&g!==void 0&&d===g,p=h!==void 0&&d!==void 0&&h===d,m=c!==void 0&&g!==void 0&&c===g;let u;const $=se(a,"middle");b&&f?u=p?{char:" ",width:l.width}:l:b?u=a.joinLeft:f?u=a.joinRight:p&&m?u=$.body:p?u=a.topJoin:m?u=a.bottomJoin:u=a.joinJoin;const{char:w,width:v}=u;return{char:w,width:v>0?v:this.#e.gap}}renderGrid(t,i){if(t.length===0)return"";const r=[],s=po(t,i,this.#e,this.alignCellContent.bind(this),ae),o=this.#e.showBorders&&this.#e.border?se(this.#e.border,"top"):void 0;o&&o.body.width>0&&r.push(this.renderHorizontalBorder(t,s,0,i,"top"));for(let a=0;a<t.length;a+=1){const l=s[a]??1;for(let c=0;c<l;c+=1)r.push(this.renderVisualRowContent(t,a,c,i,s));const h=this.#e.showBorders&&this.#e.border?se(this.#e.border,"middle"):void 0;if(a<t.length-1&&h&&h.body.width>0){const c=t[a],d=t[a+1];let g=!1;if(c&&d)for(let b=0;b<this.#e.columns;b+=1){const f=c[b],p=d[b];if(f!==p){g=!0;break}}g&&r.push(this.renderHorizontalBorder(t,s,a,i,"middle",a+1))}}const n=this.#e.showBorders&&this.#e.border?se(this.#e.border,"bottom"):void 0;return n&&n.body.width>0&&r.push(this.renderHorizontalBorder(t,s,t.length-1,i,"bottom")),r.join(`
|
|
11
|
+
`)}getCachedCellVerticalPosition(t,i,r,s){const o=this.#i.get(s);if(o)return o;const n=At(t,i,r,s);return this.#i.set(s,n),n}}Zt(e=>new ft(e),"createGrid");const Bo={bodyJoin:{char:"│",width:1},bodyLeft:{char:"│",width:1},bodyRight:{char:"│",width:1},bottomBody:{char:"─",width:1},bottomJoin:{char:"┴",width:1},bottomLeft:{char:"└",width:1},bottomRight:{char:"┘",width:1},joinBody:{char:"─",width:1},joinJoin:{char:"┼",width:1},joinLeft:{char:"├",width:1},joinRight:{char:"┤",width:1},topBody:{char:"─",width:1},topJoin:{char:"┬",width:1},topLeft:{char:"┌",width:1},topRight:{char:"┐",width:1}},Ge={bodyJoin:{char:"",width:0},bodyLeft:{char:"",width:0},bodyRight:{char:"",width:0},bottomBody:{char:"",width:0},bottomJoin:{char:"",width:0},bottomLeft:{char:"",width:0},bottomRight:{char:"",width:0},joinBody:{char:"",width:0},joinJoin:{char:"",width:0},joinLeft:{char:"",width:0},joinRight:{char:"",width:0},topBody:{char:"",width:0},topJoin:{char:"",width:0},topLeft:{char:"",width:0},topRight:{char:"",width:0}};var So=Object.defineProperty,Ki=B((e,t)=>So(e,"name",{value:t,configurable:!0}),"p$2"),Ao=Object.defineProperty,Qt=Ki((e,t)=>Ao(e,"name",{value:t,configurable:!0}),"g"),Oo=Object.defineProperty,Io=Qt((e,t)=>Oo(e,"name",{value:t,configurable:!0}),"u");const Co=Io(e=>e.reduce((t,i)=>i===null?t+1:typeof i=="object"&&!Array.isArray(i)?(i.colSpan??=1,i.colSpan<=0?t+1:t+i.colSpan):t+1,0),"computeRowLogicalWidth");var No=Object.defineProperty,Zi=Qt((e,t)=>No(e,"name",{value:t,configurable:!0}),"b");let jo=class{static{B(this,"H")}static{Ki(this,"$")}static{Qt(this,"Table")}static{Zi(this,"Table")}#e;#n=[];#t=[];#o=[];#i=!0;#r=void 0;constructor(t={}){this.#e={...t,showFooter:t.showFooter??!0,showHeader:t.showHeader??!0,style:{border:Bo,paddingLeft:1,paddingRight:1,...t.style}}}setHeaders(t){return t.length>0&&!Array.isArray(t[0])?this.#t=[t]:this.#t=t.map(i=>Array.isArray(i)?i:[i]),this.#i=!0,this.#r=void 0,this}setFooter(t){return t.length>0&&!Array.isArray(t[0])?this.#o=[t]:this.#o=t.map(i=>Array.isArray(i)?i:[i]),this.#i=!0,this.#r=void 0,this}addRow(t){if(!Array.isArray(t))throw new TypeError("Row must be an array");return this.#n.push(t),this.#i=!0,this.#r=void 0,this}addRows(...t){for(const i of t)this.addRow(i);return this.#i=!0,this.#r=void 0,this}toString(){if(!this.#i&&this.#r!==void 0)return this.#r;const t=this.#e.showHeader?this.#t:[],i=this.#e.showFooter?this.#o:[],r=[...t,...this.#n,...i];if(r.length===0)return this.#r="",this.#i=!1,"";let s=0;for(const d of r){const g=d;Array.isArray(g)?s=Math.max(s,Co(g)):console.error("Unexpected non-array element found while calculating columns:",g)}if(s===0)return this.#r="",this.#i=!1,"";let o;Array.isArray(this.#e.columnWidths)?o=this.#e.columnWidths.length>=s?this.#e.columnWidths.slice(0,s):[...this.#e.columnWidths,...Array.from({length:s-this.#e.columnWidths.length}).fill(void 0)]:typeof this.#e.columnWidths=="number"&&(o=Array.from({length:s}).fill(this.#e.columnWidths));let n;const a=r.length;if(Array.isArray(this.#e.rowHeights)?n=this.#e.rowHeights:typeof this.#e.rowHeights=="number"&&(n=Array.from({length:a}).fill(this.#e.rowHeights)),o&&Array.isArray(o)){const d=[...o];for(const g of r){const b=g;for(const[f,p]of b.entries()){let m={};if(typeof p=="object"&&p!==null&&!Array.isArray(p)){const{content:u,href:$,...w}=p;m=w}m.width!==void 0?d[f]=m.width:m.maxWidth!==void 0&&d[f]!==void 0&&(d[f]=Math.min(d[f],m.maxWidth))}}o=d}const l={autoFlow:"row",backgroundColor:this.#e.style?.backgroundColor,balancedWidths:this.#e.balancedWidths??!1,border:this.#e.style?.border,borderColor:this.#e.style?.borderColor,columns:s,fixedColumnWidths:o,fixedRowHeights:n,foregroundColor:this.#e.style?.foregroundColor,gap:this.#e.gap??0,maxWidth:this.#e.maxWidth,paddingLeft:this.#e.style?.paddingLeft,paddingRight:this.#e.style?.paddingRight,terminalWidth:this.#e.terminalWidth,truncate:this.#e.truncate??(o?.every(d=>typeof d=="number")||this.#e.maxWidth!==void 0&&!this.#e.balancedWidths),truncateOverflow:this.#e.truncateOverflow??!0,wordWrap:this.#e.wordWrap??!1},h=new ft(l),c=[];for(const[d,g]of r.entries()){const b=g;if(!Array.isArray(b)){console.error("Skipping non-array row while creating GridItems:",b);continue}const f=this.#e.showHeader?this.#t.length:0,p=this.#n.length,m=this.#e.showHeader&&d<f,u=this.#e.showFooter&&d>=f+p,$=m&&b.length===1&&s>1,w=u&&b.length===1&&s>1;for(const v of b){let x=v,W={};if(typeof x=="object"&&x!==null&&!Array.isArray(x)){const{content:F,href:L,...q}=x;x=L?`\x1B]8;;${L}\x1B\\${String(F)}\x1B]8;;\x1B\\`:F,W=q}$&&(W.colSpan=s),w&&(W.colSpan=s);const S=this.#e.transformTabToSpace&&typeof x=="string"?x.replaceAll(" "," ".repeat(this.#e.transformTabToSpace)):x,{maxWidth:I,width:k}=W;c.push({backgroundColor:W.backgroundColor,colSpan:W.colSpan,content:S,foregroundColor:W.foregroundColor,hAlign:W.hAlign,maxWidth:I,rowSpan:W.rowSpan,truncate:W.truncate??(I===void 0?void 0:!0),vAlign:W.vAlign,width:k,wordWrap:W.wordWrap})}}return h.addItems(c),this.#r=h.toString(),this.#i=!1,this.#r}};const Ve=Zi(e=>new jo(e),"createTable");var Eo=Object.defineProperty,Q=B((e,t)=>Eo(e,"name",{value:t,configurable:!0}),"n");const Qi=80,Xi=24,It=Q((e,t,{shell:i,env:r}={})=>yr(e,t,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:500,shell:i,env:r}).trim(),"exec"),Je=Q((e,t)=>({columns:Number.parseInt(e,10),rows:Number.parseInt(t,10)}),"create"),er=Q((e,t)=>{const{columns:i,rows:r}=Je(e,t);if(!(Number.isNaN(i)||Number.isNaN(r))&&!(i===Qi&&r===Xi))return{columns:i,rows:r}},"createIfNotDefault"),ko=Q(()=>{if(ee.platform!=="linux")return!0;try{const e=ye.readFileSync("/proc/self/stat","utf8"),t=e.lastIndexOf(") ");if(t===-1)return!1;const i=e.slice(t+2).trim().split(/\s+/),r=Number.parseInt(i[2],10),s=Number.parseInt(i[5],10);return Number.isNaN(r)||Number.isNaN(s)||s<=0?!1:r===s}catch{return!1}},"isForegroundProcess");function tr(){const{env:e,stdout:t,stderr:i}=ee;if(t?.columns&&t?.rows)return Je(t.columns,t.rows);if(i?.columns&&i?.rows)return Je(i.columns,i.rows);if(e.COLUMNS&&e.LINES)return Je(e.COLUMNS,e.LINES);const r={columns:Qi,rows:Xi};return ee.platform==="win32"?Wt()??r:ee.platform==="darwin"?wi()??Wt()??r:wi()??Wt()??Ro()??r}B(tr,"O$4");Q(tr,"terminalSize");const wi=Q(()=>{try{const e=ee.platform==="darwin"?ye.constants.O_EVTONLY|ye.constants.O_NONBLOCK:ye.constants.O_NONBLOCK,{columns:t,rows:i}=vr.WriteStream(ye.openSync("/dev/tty",e));return{columns:t,rows:i}}catch{}},"devTty"),Wt=Q(()=>{try{const e=It("tput",["cols"],{env:{TERM:"dumb",...ee.env}}),t=It("tput",["lines"],{env:{TERM:"dumb",...ee.env}});if(e&&t)return er(e,t)}catch{}},"tput"),Ro=Q(()=>{try{if(!ko())return;const e=It("resize",["-u"]).match(/\d+/g);if(e.length===2)return er(e[0],e[1])}catch{}},"resize");var Mo=Object.defineProperty,Po=B((e,t)=>Mo(e,"name",{value:t,configurable:!0}),"b$5"),To=Object.defineProperty,Fo=Po((e,t)=>To(e,"name",{value:t,configurable:!0}),"s"),Lo=Object.defineProperty,_o=Fo((e,t)=>Lo(e,"name",{value:t,configurable:!0}),"a");const Ho=/([a-f\d]{3,6})/i,Ct=_o(e=>{let[,t]=Ho.exec(e)??[];const i=t?t.length:0;if(i===3){const s=t.charAt(0),o=t.charAt(1),n=t.charAt(2);t=s+s+o+o+n+n}else if(i!==6)return[0,0,0];const r=Number.parseInt(t,16);return[r>>16&255,r>>8&255,r&255]},"convertHexToRgb");var Go=Object.defineProperty,Vo=B((e,t)=>Go(e,"name",{value:t,configurable:!0}),"o$1"),Jo=Object.defineProperty,zo=Vo((e,t)=>Jo(e,"name",{value:t,configurable:!0}),"s"),qo=Object.defineProperty,Xt=zo((e,t)=>qo(e,"name",{value:t,configurable:!0}),"e");const ir=Xt((e,t,i)=>e===t&&t===i?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/51)+6*Math.round(t/51)+Math.round(i/51),"rgbToAnsi256"),Nt=Xt(e=>{let t,i,r;if(e<8)return 30+e;if(e<16)return 90+(e-8);if(e>=232)t=i=r=((e-232)*10+8)/255;else{e-=16;const n=e%36;t=Math.floor(e/36)/5,i=Math.floor(n/6)/5,r=n%6/5}const s=Math.max(t,i,r)*2;if(s===0)return 30;const o=30+(Math.round(r)<<2|Math.round(i)<<1|Math.round(t));return s===2?o+60:o},"ansi256To16"),yi=Xt((e,t,i)=>Nt(ir(e,t,i)),"rgbToAnsi16");var Uo=Object.defineProperty,rr=B((e,t)=>Uo(e,"name",{value:t,configurable:!0}),"m"),Do=Object.defineProperty,me=rr((e,t)=>Do(e,"name",{value:t,configurable:!0}),"u"),Yo=Object.defineProperty,Ko=me((e,t)=>Yo(e,"name",{value:t,configurable:!0}),"e");function mt({onlyFirst:e=!1}={}){const t="(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";return new RegExp(t,e?void 0:"g")}B(mt,"$$3");rr(mt,"j");me(mt,"t$1");Ko(mt,"ansiRegex");var Zo=Object.defineProperty,Qo=me((e,t)=>Zo(e,"name",{value:t,configurable:!0}),"n$1");const D=Qo((e,t,i)=>t>e?t:Math.min(e,i),"clamp");var Xo=Object.defineProperty,P=me((e,t)=>Xo(e,"name",{value:t,configurable:!0}),"b");const N=39,j=49,vi=10,jt=gr(),nr={close:"",open:""},y=jt>0?(e,t)=>({close:`\x1B[${String(t)}m`,open:`\x1B[${String(e)}m`}):()=>nr,$i=P(e=>(t,i,r)=>e(ir(Number(t),Number(i),Number(r))),"createRgbFunction"),xi=P(e=>t=>{const[i,r,s]=Ct(t);return e(i,r,s)},"createHexFunction");let Et=P(e=>y(`38;5;${String(e)}`,N),"createAnsi256"),kt=P(e=>y(`48;5;${String(e)}`,j),"createBgAnsi256"),Ye=P((e,t,i)=>y(`38;2;${String(e)};${String(t)};${String(i)}`,N),"createRgb"),Ke=P((e,t,i)=>y(`48;2;${String(e)};${String(t)};${String(i)}`,j),"createBgRgb");jt===1?(Et=P(e=>y(Nt(Number(e)),N),"createAnsi256"),kt=P(e=>y(Nt(Number(e))+vi,j),"createBgAnsi256"),Ye=P((e,t,i)=>y(yi(Number(e),Number(t),Number(i)),N),"createRgb"),Ke=P((e,t,i)=>y(yi(Number(e),Number(t),Number(i))+vi,j),"createBgRgb")):jt===2&&(Ye=$i(Et),Ke=$i(kt));const Wi={bold:y(1,22),dim:y(2,22),hidden:y(8,28),inverse:y(7,27),italic:y(3,23),overline:y(53,55),reset:y(0,0),strike:y(9,29),strikethrough:y(9,29),underline:y(4,24),visible:nr},Bi={bgBlack:y(40,j),bgBlackBright:y(100,j),bgBlue:y(44,j),bgBlueBright:y(104,j),bgCyan:y(46,j),bgCyanBright:y(106,j),bgGray:y(100,j),bgGreen:y(42,j),bgGreenBright:y(102,j),bgGrey:y(100,j),bgMagenta:y(45,j),bgMagentaBright:y(105,j),bgRed:y(41,j),bgRedBright:y(101,j),bgWhite:y(47,j),bgWhiteBright:y(107,j),bgYellow:y(43,j),bgYellowBright:y(103,j),black:y(30,N),blackBright:y(90,N),blue:y(34,N),blueBright:y(94,N),cyan:y(36,N),cyanBright:y(96,N),gray:y(90,N),green:y(32,N),greenBright:y(92,N),grey:y(90,N),magenta:y(35,N),magentaBright:y(95,N),red:y(31,N),redBright:y(91,N),white:y(37,N),whiteBright:y(97,N),yellow:y(33,N),yellowBright:y(93,N)},Si={bg:P(e=>kt(D(e,0,255)),"bg"),bgHex:xi(Ke),bgRgb:P((e,t,i)=>Ke(D(e,0,255),D(t,0,255),D(i,0,255)),"bgRgb"),fg:P(e=>Et(D(e,0,255)),"fg"),hex:xi(Ye),rgb:P((e,t,i)=>Ye(D(e,0,255),D(t,0,255),D(i,0,255)),"rgb")};var es=Object.defineProperty,ts=me((e,t)=>es(e,"name",{value:t,configurable:!0}),"s");const is=ts((e,t,i)=>{if(t==="")return e;let r=e.indexOf(t);if(r<0)return e;const s=t.length;let o=0,n="";for(;~r;)n+=e.slice(o,r)+i,o=r+s,r=e.indexOf(t,o);return n+e.slice(o)},"stringReplaceAll");var rs=Object.defineProperty,$e=me((e,t)=>rs(e,"name",{value:t,configurable:!0}),"a");const Y={};let Rt=null;const ns=$e((e,t,i)=>{if(!e)return"";let r;if(e.raw===void 0?r=String(e):r=String.raw(e,...t),r.includes("\x1B"))for(let s=i;s;s=s.props)r=is(r,s.close,s.open);return r.includes(`
|
|
12
|
+
`)&&(r=r.replace(/(\r*\n)/g,`${i.closeStack}$1${i.openStack}`)),i.openStack+r+i.closeStack},"wrapText"),Mt=$e(({props:e},{close:t,open:i})=>{const r=(e?.openStack??"")+i,s=t+(e?.closeStack??""),o=$e((n,...a)=>ns(n,a,o.props),"style");return Object.setPrototypeOf(o,Rt),o.props={close:t,closeStack:s,open:i,openStack:r,props:e},o.open=r,o.close=s,o},"createStyle"),os=$e(function(){const e=$e(t=>String(t),"self");e.strip=t=>t.replaceAll(mt(),"");for(const t in Bi)Y[t]={get(){const i=Mt(this,Bi[t]);return Object.defineProperty(this,t,{value:i}),i}};for(const t in Wi)Y[t]={get(){const i=Mt(this,Wi[t]);return Object.defineProperty(this,t,{value:i}),i}};return Rt=Object.defineProperties({},Y),Object.setPrototypeOf(e,Rt),e},"Colorize");for(const e in Si)Y[e]={get(){return(...t)=>Mt(this,Si[e](...t))}};Y.ansi256=Y.fg;Y.bgAnsi256=Y.bg;var ss=Object.defineProperty,as=B((e,t)=>ss(e,"name",{value:t,configurable:!0}),"g"),ls=Object.defineProperty,pt=as((e,t)=>ls(e,"name",{value:t,configurable:!0}),"i"),cs=Object.defineProperty,hs=pt((e,t)=>cs(e,"name",{value:t,configurable:!0}),"n");const or=hs(e=>(t,...i)=>{if(!Array.isArray(t)||!Array.isArray(t.raw))throw new TypeError("A tagged template literal must be provided");const r=[t.raw[0]];for(let s=1;s<t.raw.length;s+=1)r.push(String(i[s-1]).replaceAll(/[{}\\]/g,String.raw`\$&`),String(t.raw[s]));return e(r.join(""))},"makeColorizeTemplate");var ds=Object.defineProperty,us=pt((e,t)=>ds(e,"name",{value:t,configurable:!0}),"e$1");const fs=new Map([["0","\0"],["\\","\\"],["a","\x07"],["b","\b"],["e","\x1B"],["f","\f"],["n",`
|
|
13
|
+
`],["r","\r"],["t"," "],["v","\v"]]),sr=us(e=>{const t=e.startsWith("u"),i=e[1]==="{";return t&&!i&&e.length===5||e.startsWith("x")&&e.length===3?String.fromCodePoint(Number.parseInt(e.slice(1),16)):t&&i?String.fromCodePoint(Number.parseInt(e.slice(2,-1),16)):fs.get(e)??e},"unescape");var ms=Object.defineProperty,gt=pt((e,t)=>ms(e,"name",{value:t,configurable:!0}),"u");const ps=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi,Ai=/(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi,gs=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,bs=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi,ws=/\s*,\s*/,ys=gt((e,t)=>{const i=[],r=t.trim().split(ws);let s;for(const o of r){const n=Number(o);if(!Number.isNaN(n))i.push(n);else if(s=gs.exec(o))i.push(s[2].replaceAll(bs,(a,l,h)=>l?sr(l):h));else throw new Error(`Invalid template style argument: ${o} (in style '${e}')`)}return i},"parseArguments"),vs=gt(e=>{Ai.lastIndex=0;const t=[];let i;for(;(i=Ai.exec(e))!==null;){const r=i[1];i[2]?t.push([r,...ys(r,i[2])]):i[3]||i[4]?(i[3]&&t.push(["rgb",...Ct(i[3])]),i[4]&&t.push(["bgRgb",...Ct(i[4])])):t.push([r])}return t},"parseStyle"),Oi=gt((e,t)=>{const i={};for(const s of t)for(const o of s.styles)i[o[0]]=s.inverse?void 0:o.slice(1);let r=e;for(const[s,o]of Object.entries(i))if(Array.isArray(o)){if(!(s in r))throw new Error(`Unknown style: ${s}`);r=o.length>0?r[s](...o):r[s]}return r},"buildStyle"),ar=gt(e=>t=>{const i=[],r=[];let s=[];if(t.replaceAll(ps,(o,n,a,l,h,c)=>{if(n)s.push(sr(n));else if(l){const d=s.join("");s=[],r.push(i.length===0?d:Oi(e,i)(d)),i.push({inverse:a,styles:vs(l)})}else if(h){if(i.length===0)throw new Error("Found extraneous } in template literal");r.push(Oi(e,i)(s.join(""))),s=[],i.pop()}else s.push(c)}),r.push(s.join("")),i.length>0)throw new Error(`template literal is missing ${String(i.length)} closing bracket${i.length===1?"":"s"} (\`}\`)`);return r.join("")},"makeTemplate");var $s=Object.defineProperty,xs=pt((e,t)=>$s(e,"name",{value:t,configurable:!0}),"e");const Ws=new os;xs(e=>or(ar(e)),"makeTaggedTemplate");const Bs=ar(Ws),Ss=or(Bs);var As=Object.defineProperty,bt=B((e,t)=>As(e,"name",{value:t,configurable:!0}),"f"),Os=Object.defineProperty,z=bt((e,t)=>Os(e,"name",{value:t,configurable:!0}),"l");const Is=ji(import.meta.url),be=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Cs=z(e=>{if(typeof be<"u"&&be.versions&&be.versions.node){const[t,i]=be.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return be.getBuiltinModule(e)}return Is(e)},"__cjs_getBuiltinModule"),Ns=Cs("node:os");var js=Object.defineProperty,Es=z((e,t)=>js(e,"name",{value:t,configurable:!0}),"s");const we=new Map,ks=500,R=Es(e=>{if(!e||e==="")return"";const t=we.get(e);if(t!==void 0)return t;const i=Ss(Object.assign([],{raw:[e]}));if(we.size>=ks){const r=we.keys().next().value;r!==void 0&&we.delete(r)}return we.set(e,i),i},"templateFormat");var Rs=Object.defineProperty,Ms=z((e,t)=>Rs(e,"name",{value:t,configurable:!0}),"t$1");const ze=Ms(()=>{const e=wr().CEREBRO_TERMINAL_WIDTH;if(e===void 0)return;const t=Number.parseInt(e,10);if(!(Number.isNaN(t)||t<=0))return t},"getTerminalWidth");var Ps=Object.defineProperty,Ts=z((e,t)=>Ps(e,"name",{value:t,configurable:!0}),"t");let lr=class{static{B(this,"O")}static{bt(this,"w")}static{z(this,"n")}static{Ts(this,"BaseSection")}lines;constructor(){this.lines=[]}add(t){this.lines.push(t)}toString(){return this.lines.join(Ns.EOL)}header(t){this.add(br(t)),this.lines.push("")}};var Fs=Object.defineProperty,Ze=z((e,t)=>Fs(e,"name",{value:t,configurable:!0}),"g");const Ls=Ze(e=>e!==void 0&&e>0?e:tr().columns,"resolveTerminalWidth"),_s=Ze((e,t,i,r)=>{if(e.length===0||e.some(h=>h.length!==2))return;let s=0;for(const h of e){const c=h[0];if(c===void 0)continue;const d=rn(c);d>s&&(s=d)}if(s===0)return;const o=i+r,n=s+o,a=20+o;if(n+a>t)return;const l=t-n;return[n,l]},"computeColumnWidths");class Hs extends lr{static{B(this,"J")}static{bt(this,"z")}static{z(this,"S")}static{Ze(this,"ContentSection")}constructor(t){if(super(),t.header&&this.header(R(t.header)),t.content){if(t.raw)if(Array.isArray(t.content)&&t.content.every(i=>typeof i=="string"))t.content.forEach(i=>{Array.isArray(i)?i.forEach(r=>{this.add(R(r))}):this.add(R(i))});else if(typeof t.content=="string")this.add(R(t.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(t.content));this.add("")}}getContentLines(t){if(typeof t=="string"){const i=Ve({showHeader:!1,style:{border:Ge,paddingLeft:4,paddingRight:1},terminalWidth:ze(),truncateOverflow:!1,wordWrap:!0});return i.addRow([R(t)]),i.toString()}if(Array.isArray(t)&&t.every(i=>typeof i=="string"||Array.isArray(i)&&i.every(r=>typeof r=="string"))){const i=Ls(ze()),r=Ze(a=>Array.isArray(a)?a.map(l=>R(l)):[R(a)],"formatRow"),s=t.map(a=>r(a)),o=_s(s,i,4,1),n=Ve({columnWidths:o,showHeader:!1,style:{border:Ge,paddingLeft:4,paddingRight:1},terminalWidth:i,truncateOverflow:!1,wordWrap:!0});return s.forEach(a=>{o!==void 0&&a.length===2?n.addRow([{content:a[0],wordWrap:!1},a[1]]):n.addRow(a)}),n.toString()}if(typeof t=="object"){const i=t;if(!i.options||!i.data)throw new Error(`Must have an "options" or "data" property
|
|
14
|
+
${JSON.stringify(t)}`);const r=Ve({showHeader:!1,style:{border:Ge,paddingLeft:4,paddingRight:1},terminalWidth:ze(),truncateOverflow:!1,wordWrap:!0});return i.data.forEach(s=>{Array.isArray(s)?r.addRow(s.map(o=>R(o))):r.addRow([R(s)])}),r.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
|
|
15
|
+
|
|
16
|
+
${JSON.stringify(t)}`)}}var Gs=Object.defineProperty,Vs=z((e,t)=>Gs(e,"name",{value:t,configurable:!0}),"m");class Js extends lr{static{B(this,"U")}static{bt(this,"k")}static{z(this,"O")}static{Vs(this,"OptionListSection")}constructor(t){super();let i=t.optionList??[];const r=Array.isArray(t.hide)?t.hide:[t.hide].filter(n=>typeof n=="string"),s=Array.isArray(t.group)?t.group:[t.group].filter(n=>typeof n=="string");r.length>0&&(i=i.filter(n=>!r.includes(n.name))),t.header&&this.header(R(t.header)),s.length>0&&(i=i.filter(n=>{const a=n,l=s.includes("_none")&&!a.group,h=a.group,c=this.intersect(Array.isArray(h)?h:[h],s);return l||c?n:void 0}));const o=Ve({showHeader:!1,style:{border:Ge,paddingLeft:2,paddingRight:1,...t.tableOptions?.style},terminalWidth:ze()??t.tableOptions?.terminalWidth,truncateOverflow:!1,wordWrap:t.tableOptions?.wordWrap??!0,...t.tableOptions});i.forEach(n=>{const a=n;o.addRow([this.getOptionNames(a,t.reverseNameOrder??!1,t.isArgument??!1),R(a.description)])}),this.add(o.toString()),this.lines.push("")}getOptionNames(t,i,r){if(!t.name)throw new TypeError("Invalid option definition, name is required.");let s=t.type?t.type.name.toLowerCase():"string";const o=t.multiple||t.lazyMultiple?"[]":"";s=R(t.typeLabel??`{underline ${s}${o}}`);let n;if(t.alias)if(t.name){const a=r?t.name:`{yellow --${t.name}}`;n=R(i?`{bold ${a}}, {bold -${t.alias}} ${s}`:`{bold -${t.alias}}, {bold ${a}} ${s}`)}else i?n=R(`{bold -${t.alias}} ${s}`):n=R(`{bold -${t.alias}} ${s}`);else n=R(`{bold ${r?t.name:`{yellow --${t.name}}`}} ${s}`);return n}intersect(t,i){return t.some(r=>i.includes(r))}}var zs=Object.defineProperty,qs=z((e,t)=>zs(e,"name",{value:t,configurable:!0}),"o");const ei=qs(e=>(Array.isArray(e)?e:[e]).length===0?"":`
|
|
17
|
+
${e.map(t=>t.optionList?new Js(t).toString():new Hs(t).toString()).join(`
|
|
18
|
+
`)}`,"commandLineUsage");var Us=Object.defineProperty,cr=B((e,t)=>Us(e,"name",{value:t,configurable:!0}),"b"),Ds=Object.defineProperty,hr=cr((e,t)=>Ds(e,"name",{value:t,configurable:!0}),"b");const Ys=[{defaultValue:"32",description:"Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",name:"CEREBRO_OUTPUT_LEVEL",type:String},{description:"Sets the minimum required Node.js version. Overrides the default minimum version check",name:"CEREBRO_MIN_NODE_VERSION",type:Number},{defaultValue:!1,description:"When set, disables the update notifier check",name:"NO_UPDATE_NOTIFIER",type:Boolean},{description:"Standard Node.js environment variable. When set to 'test', disables update notifier",name:"NODE_ENV",type:String},{defaultValue:!1,description:"When set, enables debug output (same as --debug flag)",name:"DEBUG",type:Boolean},{description:"Sets the terminal width for table rendering. Useful for testing and consistent output",name:"CEREBRO_TERMINAL_WIDTH",type:Number}];var Ks=Object.defineProperty,re=hr((e,t)=>Ks(e,"name",{value:t,configurable:!0}),"f");const Ii="__Other",Ci=re(e=>e.charAt(0).toUpperCase()+e.slice(1),"upperFirstChar"),Zs=re((e,t,i,r)=>{e.debug("no command given, printing general help...");let s=[...new Set(i.values())].filter(a=>!a.hidden);r&&(s=s.filter(a=>a.group===r));const o=s.reduce((a,l)=>{const h=l.group??Ii;return a[h]??=[],a[h].push(l),a},{}),n=re(a=>a.map(l=>{let h="";typeof l.alias=="string"?h=l.alias:Array.isArray(l.alias)&&(h=l.alias.join(", ")),h!==""&&(h=` [${h}]`);let c=l.name;return l.commandPath&&l.commandPath.length>0&&(c=`${l.commandPath.join(" ")} ${l.name}`),[`${V(c)}${h}`,l.description??""]}),"buildCommandList");(e.raw??e.log)(ei([{content:`${he(t.getCliName())} ${V("<command>")} [positional arguments] ${qe("[options]")}`,header:M.cyan(" Usage ")},...Object.keys(o).map(a=>{const l=r?` ${Ci(r)}`:"";return{content:n(o[a]),header:a===Ii||r?M.green(` Available${l} Commands `):` ${M.green(` ${Ci(a)} `)}`}}),i.has("help")?{header:M.yellow(" Command Options "),optionList:i.get("help").options?.filter(a=>!a.hidden)}:void 0,{header:M.yellow(" Global Options "),optionList:t.getGlobalOptions()},{content:Ys.filter(a=>!a.hidden).map(a=>[a.name,a.description??""]),header:M.magenta(" Environment Variables ")},{content:`Run "${he(t.getCliName())} ${V("help <command>")}" or "${he(t.getCliName())} ${V("<command>")} ${qe("--help")}" for help with a specific command.`,raw:!0}].filter(Boolean)))},"printGeneralHelp"),Ni=re((e,t)=>{const i=[];for(const r of e.values()){if(r.hidden)continue;const s=r.commandPath??[];if(s.length!==t.length)continue;let o=!0;for(const[n,a]of t.entries())if(s[n]!==a){o=!1;break}o&&i.push(r)}return i},"findChildren"),Qs=re((e,t,i,r)=>{const s=i.join(" "),o=[{content:`${he(t.getCliName())} ${V(s)} ${V("<subcommand>")} [positional arguments] ${qe("[options]")}`,header:M.cyan(" Usage ")},{content:r.map(n=>{const a=[...n.commandPath??[],n.name].join(" ");return[V(a),n.description??""]}),header:M.green(" Subcommands ")},{header:M.yellow(" Global Options "),optionList:t.getGlobalOptions()},{content:`Run "${he(t.getCliName())} ${V(`${s} <subcommand>`)} ${qe("--help")}" for help with a specific subcommand.`,raw:!0}];(e.raw??e.log)(ei(o))},"printParentHelp"),Xs=re((e,t,i,r,s)=>{let o=s??i.get(r);if(!o)for(const c of i.values()){const d=c.commandPath?[...c.commandPath,c.name]:[c.name];if(d.at(-1)===r||d.join(" ")===r){o=c;break}}if(!o){const c=r.split(" ").filter(Boolean),d=c.length>0?Ni(i,c):[];if(d.length>0){Qs(e,t,c,d);return}e.error(`Command "${r}" not found`);return}const n=[],a=(o.commandPath?[...o.commandPath,o.name]:[o.name]).join(" ");if(n.push({content:`${he(t.getCliName())} ${V(a)}${o.argument?" [positional arguments]":""}${o.options?" [options]":""}`,header:M.cyan(" Usage ")}),o.description&&n.push({content:o.description,header:M.green(" Description ")}),o.argument&&n.push({header:"Command Positional Arguments",isArgument:!0,optionList:[o.argument]}),Array.isArray(o.options)&&o.options.length>0&&n.push({header:M.yellow(" Command Options "),optionList:o.options.filter(c=>!c.hidden)}),n.push({header:M.yellow(" Global Options "),optionList:t.getGlobalOptions()}),Array.isArray(o.env)&&o.env.length>0){const c=o.env.filter(d=>!d.hidden);c.length>0&&n.push({content:c.map(d=>[d.name,d.description??""]),header:M.magenta(" Environment Variables ")})}if(o.alias!==void 0&&o.alias.length>0){let c=o.alias;typeof o.alias=="string"&&(c=[o.alias]),n.splice(1,0,{content:c,header:"Alias(es)"})}Array.isArray(o.examples)&&o.examples.length>0&&n.push({content:o.examples,header:"Examples"});const l=[...o.commandPath??[],o.name],h=Ni(i,l);h.length>0&&n.push({content:h.map(c=>{const d=[...c.commandPath??[],c.name].join(" ");return[V(d),c.description??""]}),header:M.green(" Subcommands ")}),(e.raw??e.log)(ei(n))},"printCommandHelp");class oa{static{B(this,"L")}static{cr(this,"L")}static{hr(this,"x")}static{re(this,"HelpCommand")}argument={description:"Command to show help for (subcommand path supported, e.g. `cli help docker build`)",name:"command",type:String};name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(t){this.commands=t}execute(t){const{argument:i,command:r,commandName:s,logger:o,options:n,runtime:a}=t,{footer:l,header:h}=a.getCommandSection();h&&(o.raw??o.log)(R(h));const c=s==="help"&&Array.isArray(i)&&i.length>0?i.join(" "):void 0;if(s==="help"&&c===void 0)Zs(o,a,this.commands,typeof n?.group=="string"?n.group:void 0);else{const d=c!==void 0||r===void 0||r.name==="help"?void 0:r;Xs(o,a,this.commands,c??s,d)}l&&(o.raw??o.log)(R(l))}}export{oa as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var ie=Object.defineProperty;var h=(e,t)=>ie(e,"name",{value:t,configurable:!0});import{b0 as S,b1 as E,b2 as _,b3 as U,b4 as z,b5 as W,b6 as q,b7 as ae,u as oe,ay as se,p as le,b8 as ce}from"./bin.js";import{z as Q,M as G,$ as A}from"./config.js";var fe=Object.defineProperty,ue=h((e,t)=>fe(e,"name",{value:t,configurable:!0}),"l$3"),pe=Object.defineProperty,me=ue((e,t)=>pe(e,"name",{value:t,configurable:!0}),"l"),de=Object.defineProperty,he=me((e,t)=>de(e,"name",{value:t,configurable:!0}),"o");const ye=new E(1e3),T=he((e,t)=>{if(typeof e!="string")return"";const n=t?.cache??!1,r=t?.cacheStore??ye;let i;if(n&&(i=S(e,t)),n&&i&&r.has(i))return r.get(i);const a=_(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(s=>{if(t?.handleAnsi&&U.test(s))return s;if(t?.toUpperCase)return t.locale?s.toLocaleUpperCase(t.locale):s.toUpperCase();const l=t?.locale?.startsWith("de")?z(s):s;return t?.locale?l.toLocaleLowerCase(t.locale):l.toLowerCase()}),o=W(a,t?.joiner??"-");return n&&i&&r.set(i,o),o},"kebabCase");var be=Object.defineProperty,ge=h((e,t)=>be(e,"name",{value:t,configurable:!0}),"r$2"),ve=Object.defineProperty,$e=ge((e,t)=>ve(e,"name",{value:t,configurable:!0}),"a"),we=Object.defineProperty,je=$e((e,t)=>we(e,"name",{value:t,configurable:!0}),"s");const Oe=new E(1e3),Ee=je((e,t)=>T(e,{cacheStore:Oe,...t,joiner:"_",toUpperCase:!0}),"constantCase");var xe=Object.defineProperty,Ae=h((e,t)=>xe(e,"name",{value:t,configurable:!0}),"l$2"),ke=Object.defineProperty,Pe=Ae((e,t)=>ke(e,"name",{value:t,configurable:!0}),"l"),Ce=Object.defineProperty,Se=Pe((e,t)=>Ce(e,"name",{value:t,configurable:!0}),"i");const _e=new E(1e3),We=Se((e,t)=>{if(typeof e!="string"||!e)return"";const n=t?.cache??!1,r=t?.cacheStore??_e;let i;if(n&&(i=S(e,t)),n&&i&&r.has(i))return r.get(i);const a=W(_(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(o=>{if(t?.handleAnsi&&U.test(o))return o;const s=t?.locale?.startsWith("de")?z(o):o;return q(t?.locale?s.toLocaleLowerCase(t.locale):s.toLowerCase(),{locale:t?.locale})}),"");return n&&i&&r.set(i,a),a},"pascalCase");var Te=Object.defineProperty,Le=h((e,t)=>Te(e,"name",{value:t,configurable:!0}),"r$1"),Me=Object.defineProperty,Fe=Le((e,t)=>Me(e,"name",{value:t,configurable:!0}),"a"),Ne=Object.defineProperty,Re=Fe((e,t)=>Ne(e,"name",{value:t,configurable:!0}),"s");const Ie=new E(1e3),Ue=Re((e,t)=>T(e,{cacheStore:Ie,...t,joiner:"_"}),"snakeCase");var ze=Object.defineProperty,qe=h((e,t)=>ze(e,"name",{value:t,configurable:!0}),"r"),Qe=Object.defineProperty,Ge=qe((e,t)=>Qe(e,"name",{value:t,configurable:!0}),"e"),Ve=Object.defineProperty,Be=Ge((e,t)=>Ve(e,"name",{value:t,configurable:!0}),"i");const De=new E(1e3),Je=Be((e,t)=>{if(typeof e!="string")return"";const n=t?.cache??!1,r=t?.cacheStore??De;let i;if(n&&(i=S(e,t)),n&&i&&r.has(i))return r.get(i);const a=W(_(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(o=>q(o,{locale:t?.locale})),"-");return n&&i&&r.set(i,a),a},"trainCase");var Ke=Object.defineProperty,d=h((e,t)=>Ke(e,"name",{value:t,configurable:!0}),"e");const y=d(e=>e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):JSON.stringify(e),"stringify"),P={camel_case:d(e=>ae(y(e)),"camel_case"),kebab_case:d(e=>T(y(e)),"kebab_case"),lower_case:d(e=>y(e).toLowerCase(),"lower_case"),pascal_case:d(e=>We(y(e)),"pascal_case"),path_join:d((e,...t)=>{const n=[y(e),...t.map(r=>y(r))];return G(...n)},"path_join"),path_relative:d((e,t)=>Q(y(t),y(e)),"path_relative"),snake_case:d(e=>Ue(y(e)),"snake_case"),upper_case:d(e=>y(e).toUpperCase(),"upper_case"),upper_kebab_case:d(e=>Je(y(e)),"upper_kebab_case"),upper_snake_case:d(e=>Ee(y(e)),"upper_snake_case")};d(e=>Object.hasOwn(P,e),"isKnownFilter");const V=d((e,t,n=[])=>{const r=P[e];if(!r)throw new Error(`Unknown filter "${e}". Known filters: ${Object.keys(P).sort().join(", ")}.`);return r(t,...n)},"applyFilter");var Ye=Object.defineProperty,B=h((e,t)=>Ye(e,"name",{value:t,configurable:!0}),"d$1");const D=B(e=>{const t=[];let n=0,r=0,i,a=-1;for(const o of e){if(a+=1,i){o===i&&(i=void 0);continue}if(o==='"'||o==="'"){i=o;continue}o==="("?n+=1:o===")"?n-=1:o===","&&n===0&&(t.push(e.slice(r,a)),r=a+1)}return t.push(e.slice(r)),t},"splitCommaOutsideQuotes"),He=B(e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1)},"stripQuotes");var Xe=Object.defineProperty,w=h((e,t)=>Xe(e,"name",{value:t,configurable:!0}),"s$1");const Ze=/\[([^\]]+)\]/g,et=w(e=>{const t=e.trim(),n=t.indexOf("(");if(n===-1)return{args:[],name:t};if(!t.endsWith(")"))throw new Error(`Filter call "${e}" missing closing ")"`);const r=t.slice(0,n).trim(),i=t.slice(n+1,-1).trim();return i===""?{args:[],name:r}:{args:D(i).map(a=>{const o=a.trim();return He(o)??o}),name:r}},"parseFilterCall"),tt=w(e=>{const t=e.split("|").map(r=>r.trim()),n=t[0]??"";if(!n)throw new Error(`Empty variable name in expression "${e}"`);return{filters:t.slice(1).map(r=>et(r)),name:n}},"parsePipe"),rt=w(e=>e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):JSON.stringify(e),"stringify"),nt=w((e,t)=>{const n=e.replaceAll(Ze,(r,i)=>{const{filters:a,name:o}=tt(i);if(!Object.hasOwn(t,o))throw new Error(`Variable "${o}" used in filename "${e}" but not defined`);let s=t[o];for(const l of a)s=V(l.name,s,l.args);return rt(s)});return J(n)},"interpolateFilename"),J=w(e=>e.split("/").map(t=>t.endsWith(".tera")||t.endsWith(".twig")?t.slice(0,-5):t).join("/"),"stripTeraSuffix"),it=w(e=>e.endsWith(".raw")?e.slice(0,-4):e,"stripRawSuffix"),at=w(e=>{const t=e.split("/");return(t.at(-1)??"").startsWith("_")?!0:t.slice(0,-1).includes("partials")},"isPartialPath");var ot=Object.defineProperty,st=h((e,t)=>ot(e,"name",{value:t,configurable:!0}),"i");const lt=st((e,t)=>{if(!e.startsWith(`---
|
|
2
|
+
`)&&!e.startsWith(`---\r
|
|
3
|
+
`))return{body:e};const n=e.indexOf(`
|
|
4
|
+
---`,3);if(n===-1)return{body:e};let r=n+1+3;e[r]==="\r"&&(r+=1),e[r]===`
|
|
5
|
+
`&&(r+=1);const i=e.startsWith(`---\r
|
|
6
|
+
`)?5:4,a=e.slice(i,n).replaceAll("\r","");let o;try{o=t(a)}catch(s){const l=s instanceof Error?s.message:String(s);throw new Error(`Failed to parse frontmatter YAML: ${l}`,{cause:s})}if(o==null)return{body:e.slice(r)};if(typeof o!="object"||Array.isArray(o))throw new TypeError(`Frontmatter must be a YAML mapping, got ${Array.isArray(o)?"array":typeof o}`);return{body:e.slice(r),frontmatter:o}},"splitFrontmatter");var ct=Object.defineProperty,f=h((e,t)=>ct(e,"name",{value:t,configurable:!0}),"c");const ft=/\{\{-?(.+?)-?\}\}|\{%-?(.+?)-?%\}/gs,K=f(e=>{const t=[];let n=0,r=1;const i=f(a=>{for(const o of a)o===`
|
|
7
|
+
`&&(r+=1)},"advanceLine");for(const a of e.matchAll(ft)){const o=a.index??0;if(o>n){const c=e.slice(n,o);t.push({line:r,type:"text",value:c}),i(c)}const s=r,l=a[0];l.startsWith("{{")?t.push({line:s,type:"expr",value:(a[1]??"").trim()}):t.push({line:s,type:"stmt",value:(a[2]??"").trim()}),i(l),n=o+l.length}if(n<e.length){const a=e.slice(n);t.push({line:r,type:"text",value:a})}return t},"tokenize"),ut=new Set(["block","endblock","endfilter","endmacro","extends","filter","import","macro","set"]),Y=f((e,t)=>{let n=0;const r=f((a,o)=>{throw new Error(`${t}:${a}: ${o}`)},"error"),i=f(a=>{const o=[];for(;n<e.length;){const s=e[n];if(s.type==="text"){o.push({type:"text",value:s.value}),n+=1;continue}if(s.type==="expr"){o.push({expression:s.value,line:s.line,type:"expr"}),n+=1;continue}const l=s.value.split(/\s+/)[0]??"";if(a.includes(l))return o;if(ut.has(l)&&r(s.line,`Tera feature "{% ${l} %}" is not supported. Supported: if/else/endif, for/endfor, include. Rewrite the template to avoid macros, set, extends, block, and import.`),l==="if"){n+=1;const c=s.value.slice(2).trim(),m=i(["else","endif"]);let u;n<e.length&&e[n].type==="stmt"&&e[n].value.split(/\s+/)[0]==="else"&&(n+=1,u=i(["endif"])),(n>=e.length||e[n].type!=="stmt"||e[n].value.split(/\s+/)[0]!=="endif")&&r(s.line,"Unterminated {% if %} — missing {% endif %}"),n+=1,o.push({alternate:u,condition:c,consequent:m,line:s.line,type:"if"});continue}if(l==="for"){n+=1;const c=s.value.slice(3).trim(),m=c.indexOf(" in ");m===-1&&r(s.line,"Malformed {% for %} — expected `for <name> in <collection>`");const u=c.slice(0,m).trim(),g=c.slice(m+4).trim();(!u||!g)&&r(s.line,"Malformed {% for %} — missing binding or collection");const p=i(["endfor"]);(n>=e.length||e[n].type!=="stmt"||e[n].value.split(/\s+/)[0]!=="endfor")&&r(s.line,"Unterminated {% for %} — missing {% endfor %}"),n+=1,o.push({binding:u,body:p,collection:g,line:s.line,type:"for"});continue}if(l==="include"){n+=1;const c=s.value.slice(7).trim(),m=H(c);m===void 0&&r(s.line,"Malformed {% include %} — expected a quoted partial name"),o.push({line:s.line,name:m,type:"include"});continue}r(s.line,`Unknown tag "{% ${l} %}". Supported: if, for, include.`)}return o},"parseBlock");return i([])},"parse"),H=f(e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1)},"stripQuotes"),pt=f(e=>e==null?"":typeof e=="boolean"||typeof e=="number"?String(e):typeof e=="string"?e:JSON.stringify(e),"stringify"),mt=f(e=>e==null||e===!1||e===0||e===""?!1:Array.isArray(e)?e.length>0:!0,"isTruthy"),X=f((e,t,n,r,i=!0)=>{const a=e.split(".");if(i&&a.length>0&&!Object.hasOwn(t,a[0]))throw new Error(`${r}:${n}: Variable "${e}" is not defined`);let o=t;for(const s of a){if(o==null)return;if(typeof o!="object")throw new TypeError(`${r}:${n}: Cannot read "${s}" on non-object value`);o=o[s]}return o},"lookupVariable"),dt=f(e=>{const t=[];let n=0,r=0,i;for(let a=0;a<e.length;a+=1){const o=e[a];if(i){o===i&&(i=void 0);continue}if(o==='"'||o==="'"){i=o;continue}o==="("?n+=1:o===")"?n-=1:o==="|"&&n===0&&(t.push(e.slice(r,a)),r=a+1)}return t.push(e.slice(r)),t},"splitFilterPipe"),ht=f(e=>{const t=e.trim(),n=t.indexOf("(");if(n===-1)return{args:[],name:t};if(!t.endsWith(")"))throw new Error(`Filter call "${e}" missing closing ")"`);const r=t.slice(0,n).trim(),i=t.slice(n+1,-1).trim();return i?{args:D(i).map(a=>a.trim()),name:r}:{args:[],name:r}},"parseFilterCall"),k=f((e,t,n,r,i=!0)=>{const a=e.trim();if(a==="true")return!0;if(a==="false")return!1;if(a==="null"||a==="none")return null;const o=H(a);return o!==void 0?o:/^-?\d+(?:\.\d+)?$/.test(a)?Number(a):X(a,t,n,r,i)},"evaluatePrimary"),Z=f((e,t,n,r,i=!0)=>{const a=dt(e),o=a[0].trim();let s=k(o,t,n,r,i);for(let l=1;l<a.length;l+=1){const c=a[l].trim(),{args:m,name:u}=ht(c),g=m.map(p=>k(p,t,n,r,i));try{s=V(u,s,g)}catch(p){const $=p instanceof Error?p.message:String(p);throw new Error(`${r}:${n}: ${$}`,{cause:p})}}return s},"evaluateExpression"),ee=f((e,t)=>{let n,r=0;for(let i=0;i<=e.length-t.length;i+=1){const a=e[i];if(n){a===n&&(n=void 0);continue}if(a==='"'||a==="'"){n=a;continue}if(a==="("){r+=1;continue}if(a===")"){r-=1;continue}if(r===0&&e.slice(i,i+t.length)===t)return i}return-1},"findOperatorOutsideQuotes"),N=f((e,t)=>{const n=[];let r=0,i=0;for(;i<=e.length-t.length;){const a=ee(e.slice(i),t);if(a===-1)break;n.push(e.slice(r,i+a)),i+=a+t.length,r=i}return n.push(e.slice(r)),n},"splitLogical"),j=f((e,t,n,r)=>{const i=e.trim();if(i==="")return!1;if(i.startsWith("(")&&i.endsWith(")")&&yt(i)===i.length-1)return j(i.slice(1,-1),t,n,r);const a=N(i," or ");if(a.length>1)return a.some(s=>j(s,t,n,r));const o=N(i," and ");if(o.length>1)return o.every(s=>j(s,t,n,r));if(i.startsWith("not "))return!j(i.slice(4),t,n,r);for(const s of["==","!="]){const l=ee(i,s);if(l!==-1){const c=k(i.slice(0,l),t,r,n,!1),m=k(i.slice(l+s.length),t,r,n,!1),u=c===m;return s==="=="?u:!u}}return mt(Z(i,t,r,n,!1))},"evaluateConditionExpression"),yt=f(e=>{if(e[0]!=="(")return-1;let t=0,n,r=-1;for(const i of e){if(r+=1,n){i===n&&(n=void 0);continue}if(i==='"'||i==="'"){n=i;continue}if(i==="(")t+=1;else if(i===")"&&(t-=1,t===0))return r}return-1},"matchingParen"),O=f((e,t)=>{let n="";for(const r of e){if(r.type==="text"){n+=r.value;continue}if(r.type==="expr"){n+=pt(Z(r.expression,t.scope,r.line,t.filename));continue}if(r.type==="if"){const i=j(r.condition,t.scope,t.filename,r.line)?r.consequent:r.alternate??[];n+=O(i,t);continue}if(r.type==="for"){const i=X(r.collection,t.scope,r.line,t.filename,!1);if(i==null)continue;if(!Array.isArray(i))throw new TypeError(`${t.filename}:${r.line}: {% for %} expected an array, got ${typeof i}`);for(const a of i){const o={...t.scope,[r.binding]:a};n+=O(r.body,{...t,scope:o})}continue}if(r.type==="include"){const i=t.partials?.get(r.name);if(!i)throw new Error(`${t.filename}:${r.line}: Partial "${r.name}" not found. Available: ${[...t.partials?.keys()??[]].join(", ")||"(none)"}`);const a=t.includeStack??new Set;if(a.has(r.name)){const o=[...a,r.name].join(" → ");throw new Error(`${t.filename}:${r.line}: Circular partial include detected: ${o}`)}a.add(r.name);try{n+=O(i,{...t,filename:`<partial:${r.name}>`,includeStack:a})}finally{a.delete(r.name)}}}return n},"renderNodes"),bt=f((e,t)=>Y(K(e),t),"parseTemplate");f((e,t)=>O(e,t),"renderAst");const C=f((e,t)=>O(Y(K(e),t.filename),t),"renderTemplate");var gt=Object.defineProperty,b=h((e,t)=>gt(e,"name",{value:t,configurable:!0}),"s");const R="template.yml",vt=".raw",$t=new Set([".cjs",".css",".env",".gitattributes",".gitignore",".graphql",".html",".ini",".js",".json",".json5",".jsonc",".jsx",".lock",".md",".mdx",".mjs",".prettierrc",".raw",".rs",".scss",".sh",".sql",".svg",".tera",".toml",".ts",".tsx",".twig",".txt",".vue",".xml",".yaml",".yml"]),wt=new Set(["Brewfile","CHANGELOG","CODEOWNERS","CONTRIBUTING","COPYING","Dockerfile","Gemfile","LICENCE","LICENSE","Makefile","NOTICE","Procfile","Rakefile","README","VERSION"]),jt=b(e=>{const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\")),n=t===-1?e:e.slice(t+1),r=n.lastIndexOf(".");return r===-1||r===0?"":n.slice(r).toLowerCase()},"lastDot"),te=b(e=>{const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t===-1?e:e.slice(t+1)},"basename"),Ot=b(e=>{const t=jt(e);if(t!=="")return $t.has(t);const n=te(e);return wt.has(n)},"isLikelyText"),Et=b(e=>{const t={default:e.default,internal:e.internal,order:e.order,prompt:e.prompt,required:e.required};switch(e.type){case"array":return{...t,type:"array"};case"boolean":return{...t,default:typeof t.default=="boolean"?t.default:void 0,type:"boolean"};case"enum":return{...t,multiple:e.multiple,type:"enum",values:e.values??[]};case"number":return{...t,type:"number"};case"string":return{...t,type:"string"};default:throw new Error(`Unsupported variable type "${String(e.type)}"`)}},"yamlVariableToVariable"),xt=b(e=>e.replaceAll("\\","/").replace(/^\.\//,"").replaceAll(/\/+/g,"/"),"normalizeDestinationPath"),At=b((e,t,n)=>{const r=t.split("/").filter(Boolean);if(r.length===0)throw new Error("Empty destination path for value");let i=e;for(let a=0;a<r.length-1;a+=1){const o=r[a],s=i[o];if(s===void 0){const l={};i[o]=l,i=l}else if(typeof s=="object"&&!Buffer.isBuffer(s))i=s;else throw new TypeError(`Path conflict: "${r.slice(0,a+1).join("/")}" is both a file and a directory`)}i[r.at(-1)]=n},"flattenFiles"),I=b((e,t,n)=>{if(typeof e!="string")return kt(e);const r=e.includes("{{")||e.includes("{%")?C(e,{filename:`${n}#frontmatter`,scope:t}):e;return j(r,t,`${n}#frontmatter`,1)},"evaluateGate"),kt=b(e=>e==null||e===!1||e===0||e===""?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e!=="false"&&e!=="0":!0,"truthyValue"),Wt=b((e,t)=>{const n=G(e,R),r=oe(n);if(!r||typeof r!="object")throw new Error(`${n}: must contain a YAML mapping`);const i={};if(r.variables)for(const[l,c]of Object.entries(r.variables))i[l]=Et(c);const a=new Map,o=[];for(const l of se(e,{includeDirs:!1,includeSymlinks:!1})){if(l.path===n)continue;const c=Q(e,l.path).replaceAll("\\","/");if(c===R)continue;if(at(c)){const u=A(l.path),g=bt(u,c);for(const p of Pt(c))a.has(p)&&a.get(p)!==g&&le.warn(`partial name "${p}" is declared by multiple files — last one wins. Use distinct names or fully-qualified includes.`),a.set(p,g);continue}if(c.endsWith(vt)){const u=A(l.path);o.push({binary:null,isRaw:!0,rawText:u,relativePath:c});continue}if(Ot(c)){const u=A(l.path);o.push({binary:null,isRaw:!1,rawText:u,relativePath:c});continue}const m=A(l.path,{buffer:!0});o.push({binary:m,isRaw:!1,rawText:null,relativePath:c})}const s=b(l=>{const c={...l.builtins,...l.options},m={},u={};for(const p of o){const $=p.relativePath;let x,L,M=!1;if(p.binary)x=p.binary;else if(p.isRaw)x=p.rawText??"";else{const re=p.rawText??"",v=lt(re,ne=>ce(ne));if(v.frontmatter){if(v.frontmatter.skip!==void 0&&I(v.frontmatter.skip,c,$)||v.frontmatter.if!==void 0&&!I(v.frontmatter.if,c,$))continue;typeof v.frontmatter.to=="string"&&(L=C(v.frontmatter.to,{filename:`${$}#frontmatter.to`,partials:a,scope:c})),v.frontmatter.force===!0&&(M=!0)}x=C(v.body,{filename:$,partials:a,scope:c})}const F=xt(L??nt(it($),c));At(m,F,x),M&&(u[F]={force:!0})}const g={files:m};return Object.keys(u).length>0&&(g.filesMeta=u),g},"produce");return{about:{description:r.description??`Moon-format template at ${e}`,name:r.title??t},destination:r.destination,options:i,produce:s}},"loadMoonTemplate"),Pt=b(e=>{const t=J(e),n=te(t),r=new Set([n,t]);if(n.startsWith("_")){r.add(n.replace(/^_+/,""));const i=t.slice(0,t.length-n.length);r.add(`${i}${n.replace(/^_+/,"")}`)}return[...r]},"partialKeys");export{Wt as loadMoonTemplate};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var i=Object.defineProperty;var a=(r,e)=>i(r,"name",{value:e,configurable:!0});import{p as s}from"./bin.js";import{c as o,f as c}from"../packem_shared/registry-keys-CewRFW0e.js";var n=Object.defineProperty,f=a((r,e)=>n(r,"name",{value:e,configurable:!0}),"n");const g=f(async({options:r})=>{if(r.clear){const t=o();if(r.json){process.stdout.write(`${JSON.stringify({cleared:t,refetched:!1},void 0,2)}
|
|
2
|
+
`);return}s.success(t?"Cleared cached npm signing keys.":"No cached npm signing keys to clear.");return}const e=await c({forceRefresh:!0});if(e===void 0){if(r.json){process.stdout.write(`${JSON.stringify({cleared:!1,error:"fetch-failed",refetched:!1},void 0,2)}
|
|
3
|
+
`),process.exitCode=1;return}s.error("Failed to fetch npm signing keys (network error and no cached keys available)."),process.exitCode=1;return}if(r.json){process.stdout.write(`${JSON.stringify({cleared:!1,fromCache:e.fromCache,keyCount:e.keys.length,refetched:!e.fromCache,stale:e.stale??!1},void 0,2)}
|
|
4
|
+
`);return}if(e.fromCache&&e.stale===!0){s.warn(`Network fetch failed — falling back to expired cache (${String(e.keys.length)} keys).`);return}s.success(`Refreshed npm signing keys (${String(e.keys.length)} keys).`)},"execute");export{g as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var x=Object.defineProperty;var k=(t,s)=>x(t,"name",{value:s,configurable:!0});import{createRequire as B}from"node:module";import{A as P,ak as R,p as o,al as V}from"./bin.js";import{x as C}from"../packem_shared/build-scripts-DsWMSWDs.js";import{M as y,i as w,n as q}from"./config.js";const D=B(import.meta.url),v=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,M=k(t=>{if(typeof v<"u"&&v.versions&&v.versions.node){const[s,f]=v.versions.node.split(".").map(Number);if(s>22||s===22&&f>=3||s===20&&f>=16)return v.getBuiltinModule(t)}return D(t)},"__cjs_getBuiltinModule"),{readdirSync:j,statSync:O}=M("node:fs");var A=Object.defineProperty,_=k((t,s)=>A(t,"name",{value:s,configurable:!0}),"p$1");const N=_((t,s={})=>{const f=y(t,"node_modules");if(!w(f))return[];const l=new Map,p=new Set,b=_((n,i,a)=>{const e=`${i}@${a}`;if(p.has(e))return;p.add(e);const r=a.startsWith(t)?a.slice(t.length+1):a;let u=l.get(n);u||(u=[],l.set(n,u)),u.some($=>$.name===i)||u.push({name:i,relativePath:r})},"recordBin"),m=_((n,i="")=>{let a;try{a=j(n)}catch{return}for(const e of a){const r=y(n,e);if(e.startsWith("@")){m(r,`${e}/`);continue}if(e===".pnpm"&&i===""){let c;try{c=j(r)}catch{continue}for(const d of c){const h=y(r,d,"node_modules");w(h)&&m(h)}continue}if(e.startsWith("."))continue;const u=i+e,$=y(r,"package.json");try{if(!O(r).isDirectory()||!w($))continue;const c=q($),d=typeof c.name=="string"?c.name:u;if(typeof c.bin=="string"){const S=d.includes("/")?d.split("/").pop():d;b(S,d,r)}else if(c.bin&&typeof c.bin=="object")for(const S of Object.keys(c.bin))b(S,d,r);const h=y(r,"node_modules");w(h)&&m(h)}catch{}}},"scanDir");m(f);const g=[];for(const[n,i]of l)i.length<2||s[n]===!0||i.every(a=>s[`${a.name}#${n}`]===!0)||g.push({bin:n,packages:i});return g.sort((n,i)=>n.bin.localeCompare(i.bin))},"collectBinShadows");var T=Object.defineProperty,W=k((t,s)=>T(t,"name",{value:s,configurable:!0}),"p");const U=new Set(["bun","npm","pnpm","yarn"]),H=W(({options:t,visConfig:s,workspaceRoot:f})=>{const l=f??process.cwd(),p=P(l),b=s?.security?.policies?.installScripts?.allow??{},m=s?.security?.allowBins??{},g=s?.security?.pinVersions===!0,n=C(l,b,{pinVersions:g}),i=N(l,m),a=s&&U.has(p.name)?R(s,p.name,l):void 0;if(t.json){process.stdout.write(`${JSON.stringify({binConflicts:i,drift:a,excess:n.excess,installed:n.installed.map(e=>({hooks:e.hooks,name:e.name,version:e.version})),packageManager:p.name,pinVersions:g,unapproved:n.unapproved.map(e=>({hooks:e.hooks,name:e.name,version:e.version})),versionDrift:n.versionDrift},void 0,2)}
|
|
2
|
+
`);return}if(o.info(`Build-script status (${p.name}):
|
|
3
|
+
`),n.installed.length===0&&n.unapproved.length===0&&o.success(" No installed packages declare lifecycle scripts."),n.installed.length>0){o.success(` Approved (${String(n.installed.length)}):`);for(const e of n.installed)o.info(` ✓ ${e.name} — ${e.hooks.join(", ")}`)}if(n.unapproved.length>0){o.info(""),o.warn(` Unapproved (${String(n.unapproved.length)}):`);for(const e of n.unapproved)o.info(` ✗ ${e.name} — ${e.hooks.join(", ")}`);o.notice(" Run 'vis approve-builds' to review.")}if(n.excess.length>0){o.info(""),o.warn(` Stale allowlist entries (${String(n.excess.length)}):`);for(const e of n.excess)o.info(` ! ${e}`);o.notice(" Remove these from vis.config.ts security.policies.installScripts.allow.")}if(n.versionDrift.length>0){o.info(""),o.warn(` Version drift (pinVersions: true) — ${String(n.versionDrift.length)} entr${n.versionDrift.length===1?"y":"ies"} point at outdated versions:`);for(const{from:e,to:r}of n.versionDrift)o.info(` ${e} → ${r}`);o.notice(" Update vis.config.ts security.policies.installScripts.allow keys to migrate.")}if(i.length>0){o.info(""),o.warn(` Bin conflicts (${String(i.length)}) — multiple packages expose the same bin name:`);for(const e of i)o.info(` ${e.bin} ← ${e.packages.map(r=>r.name).join(", ")}`);o.notice(" Add the bin (or 'pkg#bin') to vis.config.ts security.allowBins to silence this.")}if(a?.hasDrift){o.info("");for(const e of V(a))o.warn(e)}},"execute");export{H as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var u=Object.defineProperty;var o=(t,e)=>u(t,"name",{value:e,configurable:!0});import{g as n}from"./config.js";import{createJiti as l}from"jiti";var p=Object.defineProperty,a=o((t,e)=>p(t,"name",{value:e,configurable:!0}),"r");const i=a((t,e)=>{if(!e||typeof e!="object")throw new TypeError(`${t}: default export must be an object (got ${e===null?"null":typeof e}). Use createTemplate({ ... }).`);const r=e;if(typeof r.about!="object"||r.about===null)throw new TypeError(`${t}: default export missing required "about" object`);if(typeof r.produce!="function")throw new TypeError(`${t}: default export missing required "produce" function`);return e},"validateTemplateExport"),m=a(async t=>{const e=await l(n(t),{fsCache:!1,moduleCache:!1}).import(t,{default:!0,try:!0})??null;return i(t,e)},"loadNativeTemplate");export{m as loadNativeTemplate};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var f=Object.defineProperty;var i=(o,e)=>f(o,"name",{value:e,configurable:!0});import{createRequire as p}from"node:module";import{p as n}from"./bin.js";import{r as h}from"../packem_shared/advisories-DsynpacV.js";const l=p(import.meta.url),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,m=i(o=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[e,s]=t.versions.node.split(".").map(Number);if(e>22||e===22&&s>=3||e===20&&s>=16)return t.getBuiltinModule(o)}return l(o)},"__cjs_getBuiltinModule"),{rm:v}=m("node:fs/promises");var _=Object.defineProperty,g=i((o,e)=>_(o,"name",{value:e,configurable:!0}),"c");const w=g(async({logger:o,options:e,workspaceRoot:s})=>{if(!s)throw new Error("Could not determine workspace root. Run this command inside a workspace.");const r=e.db??h(s),c=e.format==="json";if(!e.force){n.warn(`Prune is destructive. Will remove: ${r}`),n.info("Re-run with --force to proceed."),c&&process.stdout.write(`${JSON.stringify({dbPath:r,reason:"needs --force",removed:!1})}
|
|
2
|
+
`);return}const d=[r,`${r}-wal`,`${r}-shm`,`${r}-journal`],a=[];for(const u of d)try{await v(u,{force:!0}),a.push(u)}catch{}if(c){process.stdout.write(`${JSON.stringify({dbPath:r,files:a,removed:!0})}
|
|
3
|
+
`);return}n.success(`Removed ${r}.`)},"execute"),$=w;export{$ as advisoriesPruneExecute};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var a=(t,o)=>l(t,"name",{value:o,configurable:!0});import{p as c,Z as p,a0 as u}from"./bin.js";var w=Object.defineProperty,f=a((t,o)=>w(t,"name",{value:o,configurable:!0}),"c");const m=f(({options:t,visConfig:o,workspaceRoot:s})=>{const i=s??process.cwd(),n=o?.security?.policies?.installScripts?.allow??{},r=Object.entries(n).filter(([,e])=>e).map(([e])=>e);r.length===0&&!t.rootOnly&&(c.warn("No approved packages in security.policies.installScripts.allow — nothing to run."),!t.withRoot)||(t.rootOnly||p(i,r),(t.withRoot||t.rootOnly)&&u(i))},"execute");export{m as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var c=(s,e)=>l(s,"name",{value:e,configurable:!0});import{p as r,e as v,E as f,I as g}from"./bin.js";import{r as p,g as h}from"../packem_shared/advisories-DsynpacV.js";var $=Object.defineProperty,i=c((s,e)=>$(s,"name",{value:e,configurable:!0}),"a");const B=i(s=>{if(s===0)return"0 B";const e=["B","KB","MB","GB"],a=Math.min(Math.floor(Math.log(s)/Math.log(1024)),e.length-1),o=s/1024**a;return`${o.toFixed(o<10&&a>0?1:0)} ${e[a]}`},"formatBytes"),w=i(s=>{if(!s)return"never";const e=Date.parse(s);if(Number.isNaN(e))return s;const a=Date.now()-e;if(a<0)return s;const o=Math.floor(a/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const t=Math.floor(o/60);return t<24?`${t}h ago`:`${Math.floor(t/24)}d ago`},"formatRelative"),S=i(async({logger:s,options:e,workspaceRoot:a})=>{if(!a)throw new Error("Could not determine workspace root. Run this command inside a workspace.");const o=e.db??p(a),t=await h(a,o);if(e.format==="json"){process.stdout.write(`${JSON.stringify({dbPath:o,ecosystems:t.ecosystems.map(n=>({advisoryCount:n.advisoryCount,lastSyncIso:n.lastSyncIso,manifestEtag:n.manifestEtag??null,name:n.name})),exists:t.exists,schemaVersion:t.schemaVersion,sizeBytes:t.sizeBytes},void 0,2)}
|
|
2
|
+
`);return}if(r.info(`DB: ${o}`),!t.exists){r.warn(`No advisory DB yet. Run ${v("vis advisories sync")} to populate.`);return}if(r.info(`Schema: v${t.schemaVersion} Size: ${B(t.sizeBytes)}`),t.ecosystems.length===0){r.warn("DB exists but contains no ecosystems. Run `vis advisories sync`.");return}r.info(""),r.info("Ecosystem Advisories Last sync ETag"),r.info(f("────────── ────────── ───────────────── ──────"));for(const n of t.ecosystems){const m=n.name.padEnd(10),u=n.advisoryCount.toLocaleString().padStart(10),d=`${n.lastSyncIso||"never"} (${w(n.lastSyncIso)})`.padEnd(19),y=n.manifestEtag??f("—");r.info(`${g(m)} ${u} ${d} ${y}`)}},"execute"),b=S;export{b as advisoriesStatusExecute};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var w=Object.defineProperty;var y=(e,o)=>w(e,"name",{value:o,configurable:!0});import{p as l,E as $}from"./bin.js";import{s as D}from"../packem_shared/scan-progress-CMynp3eA.js";import{s as b,D as S}from"../packem_shared/advisories-DsynpacV.js";var E=Object.defineProperty,c=y((e,o)=>E(e,"name",{value:o,configurable:!0}),"c");const P=c(e=>e?.security?.audit?.advisories??{},"readAdvisoriesConfig"),k=c(e=>e?e.split(",").map(o=>o.trim()).filter(o=>o.length>0):["npm"],"parseEcosystems"),x=c(async({logger:e,options:o,visConfig:g,workspaceRoot:d})=>{if(!d)throw new Error("Could not determine workspace root. Run this command inside a workspace.");const u=o.format==="json",m=P(g),f=o.source??m.source??S,p=k(o.ecosystem),v=p.map(s=>({id:s,label:`Sync ${s} advisories`})),n=D(v,{live:!u}),i=[];try{for(const s of p){n.start(s);const r=Date.now();try{const t=await b({allowedHosts:m.allowedHosts,dbPath:o.db,ecosystem:s,force:!!o.force,source:f,workspaceRoot:d});i.push({ecosystem:s,result:t}),t.upToDate?n.finish(s,"ok",`up to date · ${h(Date.now()-r)}`):n.finish(s,"ok",`${t.advisoriesIngested.toLocaleString()} advisories · ${h(t.durationMs)}`)}catch(t){const a=t instanceof Error?t.message:String(t);i.push({ecosystem:s,error:a}),n.finish(s,"error",a)}}}finally{n.stop()}if(u){const s={ecosystems:i.map(r=>({advisoriesIngested:r.result?.advisoriesIngested??0,dbPath:r.result?.dbPath??null,durationMs:r.result?.durationMs??0,ecosystem:r.ecosystem,error:r.error??null,upToDate:r.result?.upToDate??!1})),source:f};process.stdout.write(`${JSON.stringify(s,void 0,2)}
|
|
2
|
+
`)}else{const s=i.filter(a=>a.error),r=i.filter(a=>a.result),t=r[0];t?.result?.dbPath&&l.info($(`DB: ${t.result.dbPath}`)),s.length===0?l.success(`Synced ${r.length} ecosystem${r.length===1?"":"s"}.`):l.error(`${s.length} ecosystem${s.length===1?"":"s"} failed to sync.`)}i.some(s=>s.error)&&(process.exitCode=1)},"execute"),h=c(e=>e>=1e3?`${(e/1e3).toFixed(1)}s`:`${Math.round(e)}ms`,"formatDuration"),M=x;export{M as advisoriesSyncExecute};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var g=Object.defineProperty;var f=(e,n)=>g(e,"name",{value:n,configurable:!0});import{A as m,p as t}from"./bin.js";import{N as y}from"../packem_shared/native-config-sync-Dvi1g2nQ.js";import{E as v}from"../packem_shared/min-release-age-BFozFonQ.js";var h=Object.defineProperty,w=f((e,n)=>h(e,"name",{value:n,configurable:!0}),"l");const b=new Set(["bun","npm","pnpm","yarn"]),O=w(({options:e,visConfig:n,workspaceRoot:u})=>{const o=u??process.cwd(),s=m(o);if(!b.has(s.name)){t.warn(`Package manager '${s.name}' has no native security config to sync.`);return}if(!n?.security){t.warn("vis.config has no `security` block — nothing to sync.");return}const r=n.security.policies??{},a=Object.fromEntries(Object.entries(r.installScripts?.allow??{}).filter(([,c])=>c)),l=r.firstSeen?.minutes,p=r.firstSeen?.exclude??[],i=[];if(Object.keys(a).length>0&&!e.skipAllowBuilds&&i.push(...y(s.name,o,a)),e.skipMinReleaseAge||i.push(...v(s.name,o,l,p)),i.length===0){t.success("Nothing to sync — vis.config and native PM config are aligned.");return}t.info(`Syncing vis.config security settings to ${s.name} native config…
|
|
2
|
+
`);for(const c of i)t.success(` ${c}`)},"execute");export{O as default};
|