@politty/zod 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/agent.d.ts +1 -1
- package/dist/{arg-registry-v1Fxnqj8.d.ts → arg-registry-SvIkYiSr.d.ts} +84 -28
- package/dist/argv-parser-BEwhz0XV.js +1 -0
- package/dist/augment.d.ts +2 -4
- package/dist/cli-main-Dccv0RoX.js +1 -0
- package/dist/{cli-main-DblimvdD.js → cli-main-qfjIxAaA.js} +2 -2
- package/dist/cli-run-DtYY4hyA.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/compile-cache.d.ts +1 -3
- package/dist/{completion-NbQ2jmWx.js → completion-07BWyhmL.js} +1 -1
- package/dist/completion-B9wrL5rH.js +1 -0
- package/dist/completion.d.ts +2 -22
- package/dist/completion.js +1 -1
- package/dist/{detect-agent-EHaSY1KW.d.ts → detect-agent-hU93hctO.d.ts} +0 -4
- package/dist/docs.d.ts +1 -21
- package/dist/docs.js +2 -2
- package/dist/dynamic-CxhC0uOL.js +1 -0
- package/dist/{dynamic-DvdL7L96.js → dynamic-D3fYVKon.js} +2 -2
- package/dist/index.d.ts +36 -48
- package/dist/index.js +1 -1
- package/dist/prompt-QPFzhQ3p.js +1 -0
- package/dist/prompt-clack.d.ts +2 -4
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +2 -4
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +2 -10
- package/dist/prompt.js +1 -1
- package/dist/register-BIQ84gFS.js +1 -0
- package/dist/runner-Bfxogqk4.js +1 -0
- package/dist/runner-BxFyJbWK.js +33 -0
- package/dist/schema-C2QqQGOQ.js +1 -0
- package/dist/schema-extractor-DL8vjWso.js +1 -0
- package/dist/skill.d.ts +7 -24
- package/dist/skill.js +2 -2
- package/dist/{field-meta-CEtC5Mir.js → unflatten-D6YJ7e-J.js} +1 -1
- package/dist/{with-completion-command-CI1rxHay.js → with-completion-command-DSqob4X0.js} +2 -2
- package/dist/{with-completion-command-Cwt9fmEm.d.ts → with-completion-command-M2RHrGAp.d.ts} +1 -9
- package/package.json +2 -2
- package/dist/argv-parser-BzWc9lXh.js +0 -1
- package/dist/cli-main-CykIbGzU.js +0 -1
- package/dist/cli-run-Aso3lU0I.js +0 -1
- package/dist/completion-CmxAA8Op.js +0 -1
- package/dist/dynamic-BEW8hYW1.js +0 -1
- package/dist/prompt-Bs_O6SmK.js +0 -1
- package/dist/register-w1jLVF3B.js +0 -1
- package/dist/runner-Bg6kLaM9.js +0 -1
- package/dist/runner-BsHTbOwS.js +0 -33
- package/dist/schema-C20skX3E.js +0 -1
- package/dist/schema-extractor-lB6-WHOF.js +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{f as e,i as t,l as n,m as r,n as i,p as a,u as o}from"./unflatten-D6YJ7e-J.js";import{a as s,c,l,m as u,n as d,o as f,p,r as m,s as h,t as g,u as _}from"./schema-extractor-DL8vjWso.js";import{t as v}from"./detect-agent-D7KSeWMh.js";import{n as y}from"./compile-cache-6u9hgeWu.js";import{a as ee,c as b,f as x,i as te,l as S,n as C,o as w,r as T,t as E,u as D}from"./subcommand-router-40vA6Mka.js";import{n as O,r as k,t as A}from"./log-collector-uhRWYT-z.js";import{a as j,i as M}from"./logger-CoeDrmRr.js";import{a as N,c as ne,d as re,i as P,l as ie,n as ae,o as F,r as I,s as L,t as R}from"./argv-parser-BEwhz0XV.js";import{isDeepStrictEqual as oe,stripVTControlCharacters as se}from"node:util";async function ce(e,t,n={}){let r,a,o=n.captureLogs??!1?A():null;o?.start();let s={args:t},c={args:t,error:r},l;n.handleSignals&&(l=async t=>{l&&(process.off(`SIGINT`,l),process.off(`SIGTERM`,l));let r=/* @__PURE__ */ Error(`Process interrupted`);if(c.error=r,e.cleanup)try{await e.cleanup(c)}catch(e){console.error(`Error during signal cleanup:`,e)}if(n.globalCleanup)try{await n.globalCleanup({error:r})}catch(e){console.error(`Error during global signal cleanup:`,e)}o?.stop(),process.stdout.writableNeedDrain&&await new Promise(e=>{let t=setTimeout(()=>{process.stdout.off(`drain`,n),e()},200),n=()=>{clearTimeout(t),e()};process.stdout.once(`drain`,n)}),process.exit(1)},process.on(`SIGINT`,l),process.on(`SIGTERM`,l));try{e.requiredPackages?.length&&await x(e.requiredPackages,t);let r=typeof t==`object`&&t?t:{};for(let e of n.packageFields??[])e.requiredPackages?.length&&(e.nested?i(r,e)!==void 0:e.name in r)&&(n.packageDiscriminators?.includes(e.name)||i(r,e)===!0)&&await x(e.requiredPackages,t);e.setup&&await e.setup(s),e.run&&(a=await e.run(t))}catch(e){r=e instanceof Error?e:Error(String(e))}finally{l&&(process.off(`SIGINT`,l),process.off(`SIGTERM`,l))}if(e.cleanup){c.error=r;try{await e.cleanup(c)}catch(e){r||=e instanceof Error?e:Error(String(e))}}o?.stop();let u=n.existingLogs??O(),d=o?.getLogs()??O(),f=k(u,d);return r?{success:!1,error:r,exitCode:1,logs:f}:{success:!0,result:a,exitCode:0,logs:f}}function le(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||e===8203||e>=8204&&e<=8207||e===65279||e>=65024&&e<=65039||e>=917760&&e<=917999}function ue(e){return e>=4352&&e<=4447||e>=11904&&e<=12350||e>=12353&&e<=13311||e>=13312&&e<=19903||e>=19968&&e<=40959||e>=40960&&e<=42191||e>=43360&&e<=43391||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65135||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=110592&&e<=110959||e>=127488&&e<=127569||e>=131072&&e<=262141||e>=9728&&e<=10175||e>=126976&&e<=129791}function de(e){let t=!1,n=!1,r=!1;for(let i of e){let e=i.codePointAt(0);e===65039?r=!0:le(e)||(t=!0,ue(e)&&(n=!0))}return t?n||r?2:1:0}const fe=(()=>{try{return new Intl.Segmenter(`en`,{granularity:`grapheme`})}catch{return}})();function pe(e){if(e.length===0)return 0;let t=e.includes(`\x1B`)||e.includes(``)?se(e):e,n=0;if(fe)for(let{segment:e}of fe.segment(t))n+=de(e);else for(let e of t)n+=de(e);return n}function z(e){let t=[],n=e.replace(/`([^`]+)`/g,(e,n)=>{let r=t.length;return t.push(M.cyan(n)),`\x00CODE${r}\x00`});return n=n.replace(/\*\*(.+?)\*\*/g,(e,t)=>M.bold(t)),n=n.replace(/__(.+?)__/g,(e,t)=>M.bold(t)),n=n.replace(/\*(.+?)\*/g,(e,t)=>M.italic(t)),n=n.replace(/(?<!\w)_(.+?)_(?!\w)/g,(e,t)=>M.italic(t)),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>`${M.underline(t)} ${M.dim(`(${n})`)}`),n=n.replace(/\x00CODE(\d+)\x00/g,(e,n)=>t[Number(n)]),n}function me(e){return we(e.split(`
|
|
2
|
+
`)).map(ke).join(`
|
|
3
|
+
|
|
4
|
+
`)}const he=/^(#{1,6})\s+(.+)$/,ge=/^(?:---+|\*\*\*+|___+)\s*$/,_e=/^>\s?(.*)$/,ve=/^-\s+(.+)$/,ye=/^(\d+)[.)]\s+(.+)$/,be=/^(`{3,}|~{3,})(\S*)\s*$/,xe=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/,Se=/^\|(.+)\|$/,Ce=/^\|(\s*:?-+:?\s*\|)+$/;function we(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.trim()===``){n++;continue}let i=r.match(be);if(i){let r=i[1],a=i[2]??``,o=[];for(n++;n<e.length;){if(e[n].startsWith(r.charAt(0).repeat(r.length))&&e[n].trim()===r.charAt(0).repeat(Math.max(r.length,e[n].trim().length))){n++;break}o.push(e[n]),n++}t.push({type:`code`,lang:a,lines:o});continue}let a=r.match(he);if(a){t.push({type:`heading`,level:a[1].length,content:a[2]}),n++;continue}if(ge.test(r)){t.push({type:`hr`}),n++;continue}if(_e.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(_e);if(t)r.push(t[1]),n++;else break}if(r.length>0){let e=r[0].match(xe);if(e){let n=r.slice(1).filter(e=>e!==``);t.push({type:`alert`,alertType:e[1],lines:n});continue}}t.push({type:`blockquote`,lines:r});continue}if(ve.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(ve);if(t)r.push(t[1]),n++;else break}t.push({type:`ul`,items:r});continue}let o=r.match(ye);if(o){let r=Number(o[1]),i=[];for(;n<e.length;){let t=e[n].match(ye);if(t)i.push(t[2]),n++;else break}t.push({type:`ol`,items:i,start:r});continue}if(Se.test(r)&&n+1<e.length&&Ce.test(e[n+1])){let i=Te(r),a=Ee(e[n+1]);n+=2;let o=[];for(;n<e.length&&Se.test(e[n]);)o.push(Te(e[n])),n++;t.push({type:`table`,headers:i,alignments:a,rows:o});continue}let s=[];for(;n<e.length;){let t=e[n];if(t.trim()===``||he.test(t)||ge.test(t)||_e.test(t)||ve.test(t)||ye.test(t)||be.test(t)||Se.test(t)&&n+1<e.length&&Ce.test(e[n+1]))break;s.push(t),n++}s.length>0&&t.push({type:`paragraph`,lines:s})}return t}function Te(e){return e.slice(1,-1).split(`|`).map(e=>e.trim())}function Ee(e){return e.slice(1,-1).split(`|`).map(e=>{let t=e.trim();return t.startsWith(`:`)&&t.endsWith(`:`)?`center`:t.endsWith(`:`)?`right`:`left`})}function De(e,t,n){let r=pe(e),i=Math.max(0,t-r);if(n===`right`)return` `.repeat(i)+e;if(n===`center`){let t=Math.floor(i/2);return` `.repeat(t)+e+` `.repeat(i-t)}return e+` `.repeat(i)}const Oe={NOTE:{icon:`ℹ`,label:`Note`,styleFn:M.cyan},TIP:{icon:`💡`,label:`Tip`,styleFn:M.green},IMPORTANT:{icon:`❗`,label:`Important`,styleFn:M.magenta},WARNING:{icon:`⚠`,label:`Warning`,styleFn:M.yellow},CAUTION:{icon:`🔴`,label:`Caution`,styleFn:M.red}};function ke(e){switch(e.type){case`heading`:return M.green(M.bold(z(e.content)));case`hr`:return M.dim(`─`.repeat(40));case`blockquote`:{let t=M.dim(`│ `);return e.lines.map(e=>`${t}${z(e)}`).join(`
|
|
5
|
+
`)}case`alert`:{let{icon:t,label:n,styleFn:r}=Oe[e.alertType],i=r(M.bold(`│`))+` `,a=`${i}${r(t)} ${r(n)}`;return e.lines.length===0?a:`${a}\n${e.lines.map(e=>`${i}${z(e)}`).join(`
|
|
6
|
+
`)}`}case`ul`:return e.items.map(e=>`${M.dim(`•`)} ${z(e)}`).join(`
|
|
7
|
+
`);case`ol`:{let t=e.start+e.items.length-1,n=String(t).length;return e.items.map((t,r)=>{let i=String(e.start+r).padStart(n,` `);return`${M.dim(`${i}.`)} ${z(t)}`}).join(`
|
|
8
|
+
`)}case`table`:{let t=e.headers.length,n=e.headers.map(e=>z(e)),r=e.rows.map(e=>Array.from({length:t},(t,n)=>z(e[n]??``))),i=n.map((e,t)=>{let n=pe(e),i=r.map(e=>pe(e[t]));return Math.max(n,...i)}),a=M.dim(`│`),o=M.dim(`┌─${i.map(e=>`─`.repeat(e)).join(`─┬─`)}─┐`),s=M.dim(`├─${i.map(e=>`─`.repeat(e)).join(`─┼─`)}─┤`),c=M.dim(`└─${i.map(e=>`─`.repeat(e)).join(`─┴─`)}─┘`);return[o,`${a} ${n.map((t,n)=>M.bold(De(t,i[n],e.alignments[n]??`left`))).join(` ${a} `)} ${a}`,s,...r.map(t=>{let n=t.map((t,n)=>De(t,i[n],e.alignments[n]??`left`));return`${a} ${n.join(` ${a} `)} ${a}`}),c].join(`
|
|
9
|
+
`)}case`code`:return e.lines.map(e=>` ${M.yellow(e)}`).join(`
|
|
10
|
+
`);case`paragraph`:return z(e.lines.join(` `))}}const B={help:`Show help`,helpAll:`Show help with all subcommand options`,helpJson:`Show help as JSON`,version:`Show version`};function Ae(e){return!e.startsWith(`__`)}function V(e){return Object.entries(e).filter(([e])=>Ae(e))}function je(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?t.commandPath.join(` `):e.name??`command`}function Me(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?`${t.rootName} ${t.commandPath.join(` `)}`:e.name??`command`}function Ne(e,t){let n=[],r=Me(e,t);n.push(M.commandName(r)),t?.globalExtracted?.fields.length&&n.push(M.placeholder(`[global options]`));let i=m(e);if(i){let t=c(i);h(i).length>0&&n.push(M.placeholder(`[options]`)),e.subCommands&&V(e.subCommands).length>0&&(e.run||e.defaultSubCommand?n.push(M.placeholder(`[command]`)):n.push(M.option(`<command>`)));for(let e of t)e.required?n.push(M.option(`<${e.name}>`)):n.push(M.placeholder(`[${e.name}]`))}else e.subCommands&&V(e.subCommands).length>0&&(e.run||e.defaultSubCommand?n.push(M.placeholder(`[command]`)):n.push(M.option(`<command>`)));return n.join(` `)}function Pe(e,t){let n=`${M.dim(`When`)} ${M.option(e)}=${M.bold(t.discriminatorValue)}:`;return t.description?`${n} ${t.description}`:n}function Fe(e,t){return` ${M.bold(`${e.description??`Variant ${t+1}`}:`)}`}function Ie(e,t=0){let n=e.required?M.option(`<${e.name}>`):M.placeholder(`[${e.name}]`),r=e.named?`${n}, ${U(e)}`:n,i=[K(e),e.defaultValue===void 0?void 0:M.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)].filter(Boolean).join(` `);return i?G(r,i,t):`${` `.repeat(t)} ${r}`}function Le(e){let t=m(e);if(!t)return``;let n=[];if(t.schemaType===`discriminatedUnion`&&t.discriminator){let e=t.discriminator;n=(t.variants??[]).map(t=>({label:Pe(e,t),fields:t.fields}))}else(t.schemaType===`union`||t.schemaType===`xor`)&&t.unionOptions&&(n=t.unionOptions.map((e,t)=>({label:Fe(e,t),fields:e.fields})));let r=n.length>0?g(n):void 0,i=t.fields.filter(e=>e.positional&&(r===void 0||r.has(e.name))).map(e=>Ie(e));for(let e of n){let t=e.fields.filter(e=>e.positional&&!r?.has(e.name));t.length!==0&&i.push(``,e.label,...t.map(e=>Ie(e,1)))}return i.join(`
|
|
11
|
+
`)}function Re(e,t={},n){let r=[],i={help:t.help??B.help,helpAll:t.helpAll??B.helpAll,helpJson:t.helpJson??B.helpJson,version:t.version??B.version},a=m(e),s=a?.fields.some(e=>e.overrideBuiltinAlias===!0&&o(e).includes(`h`))??!1,c=a?.fields.some(e=>e.overrideBuiltinAlias===!0&&o(e).includes(`H`))??!1;if(s?r.push(G(M.option(`--help`),i.help)):r.push(G(`${M.option(`-h`)}, ${M.option(`--help`)}`,i.help)),c?r.push(G(M.option(`--help-all`),i.helpAll)):r.push(G(`${M.option(`-H`)}, ${M.option(`--help-all`)}`,i.helpAll)),r.push(G(M.option(`--help-json`),i.helpJson)),n?.rootVersion&&r.push(G(M.option(`--version`),i.version)),!a)return r.join(`
|
|
12
|
+
`);if(a.schemaType===`discriminatedUnion`&&a.discriminator)return ze(a,e,r);if(a.schemaType===`union`&&a.unionOptions||a.schemaType===`xor`&&a.unionOptions)return Be(a,e,r);let l=[],u=a.fields.filter(e=>!e.positional);for(let e of u){let t=U(e),n=K(e);e.defaultValue!==void 0&&(n+=` ${M.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${M.required(`(required)`)}`);let r=W(e.env);r&&(n+=` ${r}`),l.push(G(t,n));let i=H(e);i&&l.push(i)}return l.push(...r),l.join(`
|
|
13
|
+
`)}function H(e,t=0,n=0){return!e.negationDisplay||!e.negationDescription?null:G(M.option(`--${e.negationDisplay}`),`${e.negationDescription} ${M.dim(`(↔ --${e.cliName})`)}`,t,n)}function ze(e,t,n){let r=[],i=e.discriminator,a=e.variants??[],o=f(e,i);if(o){let t=a.map(e=>e.discriminatorValue).join(`|`),n=`${M.option(`--${i}`)} ${M.placeholder(`<${t}>`)}`,s=e.description??o.description??`Action to perform`;r.push(G(n,s))}let s=g(a,i);for(let t of s){let n=e.fields.find(e=>e.name===t);if(n&&!n.positional){let e=U(n),t=K(n);n.defaultValue!==void 0&&(t+=` ${M.defaultValue(`(default: ${JSON.stringify(n.defaultValue)})`)}`);let i=W(n.env);i&&(t+=` ${i}`),r.push(G(e,t));let a=H(n);a&&r.push(a)}}r.push(...n);for(let e of a){let t=e.fields.filter(e=>e.name!==i&&!s.has(e.name)&&!e.positional),n=S(e.fields.find(e=>e.name===i)?.requiredPackages);if(t.length>0||n){r.push(``),r.push(Pe(i,e)),n&&r.push(Ue(n,2));for(let e of t){let t=U(e),n=K(e);e.defaultValue!==void 0&&(n+=` ${M.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${M.required(`(required)`)}`);let i=W(e.env);i&&(n+=` ${i}`),r.push(G(t,n,1));let a=H(e,1);a&&r.push(a)}}}return r.join(`
|
|
14
|
+
`)}function Be(e,t,n){let r=[],i=e.unionOptions??[],a=g(i);for(let t of a){let n=e.fields.find(e=>e.name===t);if(n&&!n.positional){let e=U(n),t=K(n);n.defaultValue!==void 0&&(t+=` ${M.defaultValue(`(default: ${JSON.stringify(n.defaultValue)})`)}`);let i=W(n.env);i&&(t+=` ${i}`),r.push(G(e,t));let a=H(n);a&&r.push(a)}}r.push(...n);for(let e=0;e<i.length;e++){let t=i[e];if(!t)continue;let n=t.fields.filter(e=>!a.has(e.name)&&!e.positional),o=Fe(t,e);if(n.length>0){r.push(``),r.push(o);for(let e of n){let t=U(e),n=K(e);e.defaultValue!==void 0&&(n+=` ${M.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${M.required(`(required)`)}`);let i=W(e.env);i&&(n+=` ${i}`),r.push(G(t,n,1));let a=H(e,1);a&&r.push(a)}}else r.push(``),r.push(o),r.push(` ${M.dim(M.italic(`no options`))}`)}return r.join(`
|
|
15
|
+
`)}function U(e){let t=[];if(e.alias)for(let n of e.alias)n.length===1&&t.push(M.option(`-${n}`));let n=M.option(`--${e.cliName}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();n+=` ${M.placeholder(`<${t}>`)}`}if(t.push(n),e.alias){for(let n of e.alias)if(n.length>1){let r=M.option(`--${n}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();r+=` ${M.placeholder(`<${t}>`)}`}t.push(r)}}let r=t.join(`, `);return e.type===`boolean`&&e.negationDisplay&&!e.negationDescription?`${r} / ${M.option(`--${e.negationDisplay}`)}`:r}function W(e){if(!e)return``;let t=Array.isArray(e)?e:[e];return M.dim(`[env: ${t.join(`, `)}]`)}function Ve(e){return e.replace(/\x1B\[[0-9;]*m/g,``)}function He(e,t){let n=Ve(e).length,r=Math.max(0,t-n);return e+` `.repeat(r)}function Ue(e,t){if(!e.includes(`
|
|
16
|
+
`))return e;let n=` `.repeat(t);return e.split(`
|
|
17
|
+
`).join(`\n${n}`)}function G(e,t,n=0,r=0){let i=` `.repeat(n),a=Ve(e).length,o=32-n*2+r,s=o+2+n*2,c=Ue(t,s);return a>=o?`${i} ${e}\n${` `.repeat(s)}${c}`:`${i} ${He(e,o)}${c}`}function We(e,t=0,n=0){let r=U(e),i=K(e);e.defaultValue!==void 0&&(i+=` ${M.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(i+=` ${M.required(`(required)`)}`);let a=W(e.env);return a&&(i+=` ${a}`),G(r,i,t,n)}function Ge(e){let t=[];for(let n of e.fields){if(n.positional)continue;t.push(We(n));let e=H(n);e&&t.push(e)}return t.join(`
|
|
18
|
+
`)}function Ke(e,t){let n=[],r=m(e);if(r){let e=r.fields.filter(e=>!e.positional);for(let r of e){let e=U(r),i=K(r);r.defaultValue!==void 0&&(i+=` ${M.defaultValue(`(default: ${JSON.stringify(r.defaultValue)})`)}`);let a=W(r.env);a&&(i+=` ${a}`),n.push(G(e,i,t,2));let o=H(r,t,2);o&&n.push(o)}}return n}function qe(e,t,n){let r=[];for(let[i,a]of V(e)){let e=b(a),o=t?`${t} ${i}`:i,s=[e?.description,S(e?.requiredPackages)].filter(Boolean).join(`
|
|
19
|
+
`),c=e?.aliases,l=c&&c.length>0?`${o}, ${c.join(`, `)}`:o;if(r.push(G(M.command(l),s,n)),e){let t=Ke(e,n+1);r.push(...t);let i=e.subCommands?Object.fromEntries(V(e.subCommands)):void 0;if(i&&Object.keys(i).length>0){let e=qe(i,o,n);r.push(...e)}}}return r}function Je(e,t){let n=[],r=t.context;t.agentHelp&&n.push(me(t.agentHelp));let i=je(e,r);if(i){let e=M.commandName(i);r?.rootName&&r.commandPath&&r.commandPath.length>0?r.rootVersion?e+=` ${M.version(`(${r.rootName} v${r.rootVersion})`)}`:e+=` ${M.version(`(${r.rootName})`)}`:r?.rootVersion&&(e+=` ${M.version(`v${r.rootVersion}`)}`),n.push(e)}r?.aliasFor&&n.push(M.dim(`Alias for ${M.commandName(r.aliasFor)}`)),e.description&&n.push(e.description),!r?.aliasFor&&e.aliases&&e.aliases.length>0&&n.push(`${M.sectionHeader(`Aliases:`)} ${e.aliases.map(e=>M.command(e)).join(`, `)}`),n.push(`${M.sectionHeader(`Usage:`)} ${Ne(e,r)}`);let a=Le(e);a&&n.push(`${M.sectionHeader(`Arguments:`)}\n${a}`);let o=Re(e,t.descriptions,r);if(o&&n.push(`${M.sectionHeader(`Options:`)}\n${o}`),r?.globalExtracted?.fields.length&&n.push(`${M.sectionHeader(`Global Options:`)}\n${Ge(r.globalExtracted)}`),t.showSubcommands!==!1&&e.subCommands&&V(e.subCommands).length>0){let i=r?.commandPath?.join(` `)??``,a=Object.fromEntries(V(e.subCommands));if(t.showSubcommandOptions){let e=qe(a,i,0);n.push(`${M.sectionHeader(`Commands:`)}\n${e.join(`
|
|
20
|
+
`)}`)}else{let e=[];for(let[t,n]of Object.entries(a)){let r=b(n),a=[r?.description,S(r?.requiredPackages)].filter(Boolean).join(`
|
|
21
|
+
`),o=i?`${i} ${t}`:t,s=r?.aliases,c=s&&s.length>0?`${o}, ${s.join(`, `)}`:o;e.push(G(M.command(c),a))}n.push(`${M.sectionHeader(`Commands:`)}\n${e.join(`
|
|
22
|
+
`)}`)}}if(e.examples&&e.examples.length>0){let t=Ze(e.examples,r);n.push(`${M.sectionHeader(`Examples:`)}\n${t}`)}let s=S(e.requiredPackages);if(s&&n.push(`${M.sectionHeader(`Required packages:`)}\n${s}`),e.notes){let t=me(e.notes).split(`
|
|
23
|
+
`).map(e=>e===``?``:` ${e}`).join(`
|
|
24
|
+
`);n.push(`${M.sectionHeader(`Notes:`)}\n${t}`)}return`\n${n.join(`
|
|
25
|
+
|
|
26
|
+
`)}\n`}function K(e){return[e.description,S(e.requiredPackages)].filter(Boolean).join(`
|
|
27
|
+
`)}function q(e){let t={name:e.name,cliName:e.cliName,positional:e.positional,named:e.named,required:e.required,type:e.type};return e.requiredPackages?.length&&(t.requiredPackages=e.requiredPackages.map(e=>({name:e.name,install:D(e)}))),e.alias&&(t.alias=e.alias),e.description!==void 0&&(t.description=e.description),e.placeholder!==void 0&&(t.placeholder=e.placeholder),e.env!==void 0&&(t.env=e.env),e.defaultValue!==void 0&&(t.defaultValue=e.defaultValue),e.enumValues!==void 0&&(t.enumValues=e.enumValues),e.negation!==void 0&&(t.negation=e.negation),e.negationDisplay!==void 0&&(t.negationDisplay=e.negationDisplay),e.negationDescription!==void 0&&(t.negationDescription=e.negationDescription),t}function Ye(e,t){let n=Me(e,t),r=!!t?.globalExtracted?.fields.length,i=e.subCommands&&V(e.subCommands).length>0?e.run?`optional`:`required`:void 0,a=m(e);return{commandName:n,hasGlobalOptions:r,hasOptions:a?h(a).length>0:!1,subcommand:i,positionals:a?c(a).map(e=>({name:e.name,required:e.required})):[]}}function Xe(e,t={}){let n=t.context,r=n?.commandPath??[],i={help:t.descriptions?.help??B.help,helpAll:t.descriptions?.helpAll??B.helpAll,helpJson:t.descriptions?.helpJson??B.helpJson,...n?.rootVersion?{version:t.descriptions?.version??B.version}:{}},a=m(e),o,s=[],l=[],u,d,p;if(a){if(o=a.schemaType,s=c(a).map(q),a.schemaType===`discriminatedUnion`&&a.discriminator&&a.variants){let e=a.discriminator;u=e;let t=a.variants,n=g(t,e),r=f(a,e),i=a.fields.filter(e=>!e.positional&&n.has(e.name));l=[...r?[{...q({...r,requiredPackages:void 0}),description:a.description??r.description??`Action to perform`}]:[],...i.map(q)],d=t.map(t=>{let r=t.fields.find(t=>t.name===e);return{discriminatorValue:t.discriminatorValue,...r?.requiredPackages?.length?{requiredPackages:q(r).requiredPackages}:{},description:t.description,fields:t.fields.filter(t=>t.name!==e&&!n.has(t.name)).map(q)}})}else if((a.schemaType===`union`||a.schemaType===`xor`)&&a.unionOptions){let e=a.unionOptions,t=g(e);l=a.fields.filter(e=>!e.positional&&t.has(e.name)).map(q),p=e.map(e=>({description:e.description,fields:e.fields.filter(e=>!t.has(e.name)).map(q)}))}else l=a.fields.filter(e=>!e.positional).map(q)}let h=n?.globalExtracted?.fields.length?n.globalExtracted.fields.filter(e=>!e.positional).map(q):void 0,_;if(e.subCommands){let i=V(e.subCommands);i.length>0&&(_=i.map(([i,a])=>{let o=b(a);if(!o)return{name:i,unresolved:!0};let s={commandPath:[...r,i],rootName:n?.rootName??e.name,rootVersion:n?.rootVersion,globalExtracted:n?.globalExtracted};return{name:i,aliases:o.aliases,data:Xe(o,{descriptions:t.descriptions,context:s})}}))}return{name:e.name??`command`,commandPath:r,rootName:n?.rootName,version:n?.rootVersion,aliasFor:n?.aliasFor,description:e.description,aliases:e.aliases,usage:Ye(e,n),builtinOptions:i,schemaType:o,positionals:s,options:l,discriminator:u,variants:d,unionOptions:p,globalOptions:h,subcommands:_,examples:e.examples,notes:e.notes,...e.requiredPackages?.length?{requiredPackages:e.requiredPackages.map(e=>({name:e.name,install:D(e),description:e.description}))}:{},agentHelp:t.agentHelp}}function Ze(e,t){let n=[],r=t?.rootName?`${t.rootName} `:``,i=t?.commandPath?.join(` `)??``,a=i?`${r}${i} `:r;for(let t of e){if(n.push(` ${M.dim(t.desc).split(`
|
|
28
|
+
`).join(`
|
|
29
|
+
`)}`),n.push(` ${M.dim(`$`)} ${a}${t.cmd}`),t.output)for(let e of t.output.split(`
|
|
30
|
+
`))n.push(` ${e}`);n.push(``)}return n.length>0&&n[n.length-1]===``&&n.pop(),n.join(`
|
|
31
|
+
`)}var Qe=class extends Error{constructor(e){super(e),this.name=`PositionalConfigError`}},$e=class extends Error{constructor(e){super(e),this.name=`ReservedAliasError`}},et=class extends Error{constructor(e){super(e),this.name=`DuplicateFieldError`}},tt=class extends Error{constructor(e){super(e),this.name=`DuplicateAliasError`}},nt=class extends Error{constructor(e){super(e),this.name=`CaseVariantCollisionError`}},rt=class extends Error{constructor(e){super(e),this.name=`DuplicateNegationError`}},it=class extends Error{constructor(e){super(e),this.name=`ReservedFieldNameError`}},at=class extends Error{constructor(e){super(e),this.name=`DefaultSubCommandError`}},ot=class extends Error{constructor(e){super(e),this.name=`FieldTypeConflictError`}};function st(e,t){let n=[],r=/* @__PURE__ */ new Map;for(let i of e.fields)r.has(i.name)&&n.push({commandPath:t,type:`duplicate_field`,message:`Duplicate field name "${i.name}" detected.`,field:i.name}),r.set(i.name,i.name);return n}function ct(t,n){let r=[],i=/* @__PURE__ */ new Map;for(let a of t.fields){let t=e(a.name),o=i.get(t);o&&o!==a.name&&r.push({commandPath:n,type:`case_variant_collision`,message:`Fields "${o}" and "${a.name}" are case variants of each other and would collide.`,field:a.name}),i.set(t,a.name)}return r}function lt(t,n){let r=[],i=/* @__PURE__ */ new Map,a=new Set(t.fields.map(e=>e.name)),s=new Set(t.fields.map(e=>e.cliName)),c=(e,t,o)=>{(a.has(e)||s.has(e))&&r.push({commandPath:n,type:`duplicate_alias`,message:`Alias "${e}" for field "${t}" conflicts with existing field name or CLI name "${e}".`,field:t});let c=i.get(e);if(c&&c!==t){let i=o?` (derived camelCase variant)`:``;r.push({commandPath:n,type:`duplicate_alias`,message:`Duplicate alias "${e}"${i} detected. Both "${c}" and "${t}" use the same alias.`,field:t})}i.set(e,t)};for(let n of t.fields){let t=o(n);if(t.length!==0){for(let r of t)if(c(r,n.name,!1),r.length>1&&r.includes(`-`)){let t=e(r);t!==r&&!a.has(t)&&c(t,n.name,!0)}}}return r}function ut(t,n){let r=[],i=/* @__PURE__ */ new Map,a=(e,t,n)=>{i.has(e)||i.set(e,{field:t,kind:n})};for(let n of t.fields){if(a(n.name,n.name,`field name`),n.name.includes(`-`)){let t=e(n.name);t!==n.name&&a(t,n.name,`field name`)}if(n.cliName!==n.name&&a(n.cliName,n.name,`CLI name`),n.cliName.includes(`-`)){let t=e(n.cliName);t!==n.cliName&&a(t,n.name,`CLI name`)}for(let t of o(n))if(a(t,n.name,`alias`),t.length>1&&t.includes(`-`)){let r=e(t);r!==t&&a(r,n.name,`alias`)}if(n.type===`boolean`&&n.negation===!0){let t=`no-${n.cliName}`;a(t,n.name,`default negation`);let r=e(n.cliName),i=`no${r[0]?.toUpperCase()??``}${r.slice(1)}`;i!==t&&a(i,n.name,`default negation`)}}let s=/* @__PURE__ */ new Map,c=(e,t,a)=>{let o=i.get(e);if(o){let i=a?` (derived camelCase variant)`:``,s=o.field===t?`the same field's own ${o.kind} "${e}"`:`${o.kind} "${e}" of field "${o.field}"`;r.push({commandPath:n,type:`duplicate_negation`,message:`Negation "${e}"${i} for field "${t}" conflicts with ${s}.`,field:t})}let c=s.get(e);if(c&&c!==t){let i=a?` (derived camelCase variant)`:``;r.push({commandPath:n,type:`duplicate_negation`,message:`Duplicate negation "${e}"${i} detected. Both "${c}" and "${t}" use the same negation name.`,field:t})}s.set(e,t)};for(let n of t.fields)if(typeof n.negation==`string`&&(c(n.negation,n.name,!1),n.negation.includes(`-`))){let t=e(n.negation);t!==n.negation&&c(t,n.name,!0)}return r}function dt(e,t){let n=[e,...e.variants??[],...e.unionOptions??[]],r=/* @__PURE__ */ new Set;return n.flatMap(e=>ft(e.fields,t)).filter(e=>!r.has(e.message)&&r.add(e.message))}function ft(e,t){let n=[],r=e.filter(e=>e.positional),i=null,a=null;for(let e of r)i!==null&&n.push({commandPath:t,type:`positional_config`,message:`Positional argument "${e.name}" cannot follow array positional argument "${i}".`,field:e.name}),e.type===`array`&&a!==null&&n.push({commandPath:t,type:`positional_config`,message:`Array positional "${e.name}" cannot be used with optional positional "${a}" (ambiguous parsing).`,field:e.name}),a!==null&&e.required&&n.push({commandPath:t,type:`positional_config`,message:`Required positional "${e.name}" cannot follow optional positional "${a}".`,field:e.name}),e.type===`array`&&(i=e.name),e.required||(a=e.name);return n}function pt(e,t){let r=[];for(let i of e.fields){if(i.overrideBuiltinAlias!==!0)for(let e of o(i))(e===`h`||e===`H`)&&r.push({commandPath:t,type:`reserved_alias`,message:`Alias "${e}" is reserved for --${e===`h`?`help`:`help-all`}. To override this, set { overrideBuiltinAlias: true } for "${i.name}" and keep the alias where it is currently defined (in alias or hiddenAlias).`,field:i.name});let e=/* @__PURE__ */ new Set([i.cliName,...o(i)]);for(let a of e){if(!n.has(a))continue;let e=a===i.cliName;r.push({commandPath:t,type:`reserved_alias`,message:`${e?`Field "${i.name}"`:`Alias "${a}" for field "${i.name}"`} collides with the built-in --${a} option, which always takes precedence. Rename the field or its alias; this collision cannot be overridden.`,field:i.name})}}return r}function mt(e,t){let n=[];for(let r of e.fields)r.name.startsWith(`$`)&&n.push({commandPath:t,type:`reserved_field_name`,message:`Field "${r.name}" starts with "$", which is reserved for framework-injected helpers (e.g. $source).`,field:r.name});return n}function ht(e){let t=st(e,[]);if(t.length>0)throw new et(`Duplicate field name "${t[0]?.field??`unknown`}" detected. Each field must have a unique name.`)}function gt(e){let t=lt(e,[]);if(t.length>0){let e=t[0];throw new tt(e.message)}}function _t(e){let t=dt(e,[]);if(t.length>0){let e=t[0];throw new Qe(e.message)}}function vt(e,t){let n=pt(e,[]);if(n.length>0)throw new $e(n[0].message)}function yt(e){let t=mt(e,[]);if(t.length>0){let e=t[0];throw new it(e.message)}}function bt(e){let t=ut(e,[]);if(t.length>0){let e=t[0];throw new rt(e.message)}}function xt(e){let t=ct(e,[]);if(t.length>0){let e=t[0];throw new nt(e.message)}}function St(t,n,r){let i=[],a=/* @__PURE__ */ new Map;for(let n of t.fields)a.set(e(n.name),n);for(let t of n.fields){let n=e(t.name),o=a.get(n);o&&(o.name===t.name?i.push({commandPath:r,type:`field_type_conflict`,message:`Global field "${o.name}" and command field "${t.name}" share the same name. A field name can only be declared in one schema, even when the definitions are identical.`,field:t.name}):i.push({commandPath:r,type:`case_variant_collision`,message:`Global field "${o.name}" and command field "${t.name}" are case variants of each other and would collide.`,field:t.name}))}return i.push(...Ct(t,n,r)),i}function Ct(e,t,n){let r=e=>e.fields.map(e=>({field:e,path:e.nested?.path??[e.name]})),i=r(e),o=r(t);if(![...i,...o].some(({field:e})=>e.nested))return[];let s=[];for(let e of i)for(let t of o){if(!e.field.nested&&!t.field.nested)continue;let r=Math.min(e.path.length,t.path.length),i=e.path.length!==t.path.length&&e.path.slice(0,r).every((e,n)=>e===t.path[n])?`one is a value where the other nests a group`:e.path[0]!==t.path[0]&&a(e.path[0])===a(t.path[0])?`their group names are spellings of the same name`:void 0;i&&s.push({commandPath:n,type:`field_type_conflict`,message:`Global field "${e.field.name}" and command field "${t.field.name}" nest into conflicting output positions: ${i}.`,field:t.field.name})}return s}function wt(e,t){let n=St(e,t,[])[0];if(n)throw n.type===`case_variant_collision`?new nt(n.message):new ot(n.message)}function Tt(e,t,n){return[...st(e,n),...ct(e,n),...lt(e,n),...ut(e,n),...dt(e,n),...pt(e,n),...mt(e,n)]}function Et(e,t){let n=e,r=[];if(n.defaultSubCommand===void 0)return r;n.run&&r.push({commandPath:t,type:`default_subcommand_conflict`,message:`Command "${n.name}" defines both "run" and "defaultSubCommand". Define only one.`});let i=e.subCommands?Object.keys(e.subCommands):[];return i.includes(n.defaultSubCommand)||r.push({commandPath:t,type:`default_subcommand_not_found`,message:`defaultSubCommand "${n.defaultSubCommand}" does not match any subCommands key of "${n.name}". Registered: ${i.length>0?i.join(`, `):`(none)`}.`,field:n.defaultSubCommand}),r}function Dt(e){let t=Et(e,[]);if(t.length>0)throw new at(t[0].message)}function Ot(e,t){let n=[];if(!e.subCommands)return n;let r=/* @__PURE__ */ new Map;for(let[t]of Object.entries(e.subCommands))r.set(t,t);for(let[i,a]of Object.entries(e.subCommands)){let e=w(a)?a.meta:typeof a==`function`?null:a;if(!e?.aliases)continue;let o=[...t,i];for(let t of e.aliases){if(!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(t)){n.push({commandPath:o,type:`invalid_alias`,message:`Alias "${t}" is invalid. Aliases must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores.`,field:i});continue}if(t===i){n.push({commandPath:o,type:`duplicate_alias`,message:`Alias "${t}" conflicts with its own name.`,field:i});continue}let e=r.get(t);e?e===i?n.push({commandPath:o,type:`duplicate_alias`,message:`Alias "${t}" is duplicated within the alias list.`,field:i}):n.push({commandPath:o,type:`duplicate_alias`,message:`Alias "${t}" conflicts with existing subcommand or alias "${e}".`,field:i}):r.set(t,i)}}return n}function kt(e,t,n){return e===t?[]:[{commandPath:[...n,e],type:`subcommand_key_name_mismatch`,message:`Subcommand registered as "${e}" but its own name is "${t}".`,field:e}]}async function At(e,t={}){return jt(e,t,!1)}async function jt(e,t,n){n||=!!e.requiredPackages?.length;let r=t.commandPath??[e.name],i=[],a=e.subCommands?Object.keys(e.subCommands).length>0:!1,o=t.globalArgs?d(t.globalArgs):void 0;if(e.args){let t=d(e.args);i.push(...Tt(t,a,r)),o&&i.push(...St(o,t,r))}if(i.push(...Ot(e,r)),i.push(...Et(e,r)),e.subCommands)for(let[a,o]of Object.entries(e.subCommands)){let e=await T(o,e=>n||!!e.requiredPackages?.length);i.push(...kt(a,e.name,r));let s=await jt(e,{commandPath:[...r,a],...t.globalArgs?{globalArgs:t.globalArgs}:{}},n);s.valid||i.push(...s.errors)}return i.length===0?{valid:!0}:{valid:!1,errors:i}}function Mt(e){if(e.length===0)return``;let t=[`Command definition errors:`];for(let n of e){let e=n.commandPath.join(` > `);t.push(` - [${e}] ${n.message}`)}return t.join(`
|
|
32
|
+
`)}function Nt(e){let{aliasMap:t=/* @__PURE__ */ new Map,booleanFlags:n=/* @__PURE__ */ new Set,definedNames:r=/* @__PURE__ */ new Set,negationMap:i=/* @__PURE__ */ new Map,defaultNegationDisabledFields:a=/* @__PURE__ */ new Set}=R(e),s=/* @__PURE__ */ new Set;for(let t of e.fields)for(let e of o(t))e.length===1&&s.add(e);return{aliasMap:t,booleanFlags:n,definedNames:r,flagNames:new Set(e.fields.map(e=>e.name)),cliNames:new Set(e.fields.map(e=>e.cliName)),aliases:s,negationMap:i,defaultNegationDisabledFields:a}}function Pt(e,t){let{resolvedName:n,withoutDashes:r,isNegated:i,isCustomNegation:a,isSuppressedNegation:o}=ie(e,t);if(o)return{resolvedName:n,withoutDashes:r,isNegated:!1,isGlobal:!1,isSuppressedNegation:o};let s=i&&!a?r.startsWith(`no-`)?r.slice(3):r[2].toLowerCase()+r.slice(3):r;return{resolvedName:n,withoutDashes:r,isNegated:i,isGlobal:t.flagNames.has(n)||t.cliNames.has(r)||t.cliNames.has(s),isSuppressedNegation:!1}}function J(e,t,n,r,i){return!e.includes(`=`)&&!i.has(t)&&!n&&r!==void 0&&ae(r)}function Y(e,t,n,r,i,a){let o=e[t];return a.push(o),J(o,n,r,e[t+1],i)?(a.push(e[t+1]),2):1}function Ft(e,t,n,r=()=>!1){let i=e[t];if(!I(i))return 0;let a=e=>n.aliasMap.get(e)??e,o=e=>!r(e)&&(n.aliases.has(e)||n.flagNames.has(a(e))),{flags:s,valueOption:c}=L(i.slice(1),e=>o(e)&&!n.booleanFlags.has(a(e)));return s.every(o)?c&&c.value===void 0&&J(i,a(c.name),!1,e[t+1],n.booleanFlags)?2:1:0}function It(e,t,n){let r=Nt(n),i=new Set(t),a=[],o=[],s=0;for(;s<e.length;){let t=e[s];if(t===`--`||Lt.has(t))break;if(!t.startsWith(`-`)&&i.has(t))return{subCommandIndex:s,globalTokensBefore:a,tokensAfterSubcommand:e.slice(s+1),suppressedTokens:o};if(t.startsWith(`--`)){let{resolvedName:n,withoutDashes:i,isNegated:c,isGlobal:l,isSuppressedNegation:u}=Pt(t,r);if(l){s+=Y(e,s,n,c,r.booleanFlags,a);continue}if(u){o.push(i),s++;continue}break}if(t.startsWith(`-`)&&t.length>1){let n=t.includes(`=`)?t.slice(1,t.indexOf(`=`)):t.slice(1);if(n.length===1){let t=r.aliasMap.get(n)??n;if(r.aliases.has(n)||r.flagNames.has(t)){s+=Y(e,s,t,!1,r.booleanFlags,a);continue}}let i=Ft(e,s,r);if(i>0){a.push(...e.slice(s,s+i)),s+=i;continue}break}break}return{subCommandIndex:-1,globalTokensBefore:a,tokensAfterSubcommand:[],suppressedTokens:o}}const Lt=/* @__PURE__ */ new Set([`--help`,`-h`,`--help-all`,`-H`,`--help-json`,`--version`]);function Rt(e,t,n={}){let r=n.stopOnSuppressedNegation===!0||t?.unknownKeysMode===`strict`,i=t?Nt(t):{aliasMap:/* @__PURE__ */ new Map,booleanFlags:/* @__PURE__ */ new Set,definedNames:/* @__PURE__ */ new Set,flagNames:/* @__PURE__ */ new Set,cliNames:/* @__PURE__ */ new Set,aliases:/* @__PURE__ */ new Set,negationMap:/* @__PURE__ */ new Map,defaultNegationDisabledFields:/* @__PURE__ */ new Set};for(let t=0;t<e.length;t++){let n=e[t];if(!n.startsWith(`-`))return t;if(n===`--`||Lt.has(n))return-1;if(n.startsWith(`--`)){let{resolvedName:a,isNegated:o,isGlobal:s,isSuppressedNegation:c}=Pt(n,i);if(s){J(n,a,o,e[t+1],i.booleanFlags)&&t++;continue}if(c){if(r)return-1;continue}return-1}let a=n.includes(`=`)?n.slice(1,n.indexOf(`=`)):n.slice(1);if(a.length===1){let r=i.aliasMap.get(a)??a;if(i.aliases.has(a)||i.flagNames.has(r)){J(n,r,!1,e[t+1],i.booleanFlags)&&t++;continue}}let o=Ft(e,t,i);if(o>0)t+=o-1;else return-1}return-1}function zt(e,t){let n=Rt(e,t);return n>=0?e[n]:void 0}function Bt(e,t,n={}){let r=E(t),i=[...r],a=i.length>0,c=a&&!t.run;if(a&&e.length>0){if(n.globalExtracted){let t=It(e,i,n.globalExtracted);if(t.subCommandIndex>=0){let r=Ut(t.globalTokensBefore,n.globalExtracted);return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:e[t.subCommandIndex],remainingArgs:t.tokensAfterSubcommand,rawArgs:{},positionals:[],rest:[],unknownFlags:t.suppressedTokens,unknownGlobalFlags:t.suppressedTokens,rawGlobalArgs:r}}}else{let t=e[0];if(t&&!t.startsWith(`-`)&&r.has(t))return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:t,remainingArgs:e.slice(1),rawArgs:{},positionals:[],rest:[],unknownFlags:[]}}}let l;t.args&&(l=d(t.args),n.skipValidation||(ht(l),xt(l),gt(l),bt(l),_t(l),vt(l,a),yt(l),n.globalExtracted&&wt(n.globalExtracted,l)));let u=e,f,p=[];if(n.globalExtracted){let t=l?s(l):[],r=new Set(t.map(e=>e.name)),{separated:i,globalParsed:a,suppressedTokens:o}=Wt(e,n.globalExtracted,l&&{...l,fields:[...t,...l.fields.filter(e=>!r.has(e.name))]});u=i,f=a,p=o}let m=e.indexOf(`--`),h=m>=0?e.slice(0,m):e,g=l?.fields.some(e=>e.overrideBuiltinAlias===!0&&o(e).includes(`H`))??!1,_=l?.fields.some(e=>e.overrideBuiltinAlias===!0&&o(e).includes(`h`))??!1,v=h.includes(`--help-all`)||!g&&h.includes(`-H`),y=h.includes(`--help-json`),ee=!v&&!y&&(h.includes(`--help`)||!_&&h.includes(`-h`)),b=h.includes(`--version`);if(ee||v||y||b)return{helpRequested:ee,helpAllRequested:v,helpJsonRequested:y,versionRequested:b,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:[],rest:[],unknownFlags:[],unknownGlobalFlags:p,rawGlobalArgs:f};if(!l){let e=u.indexOf(`--`),t=e>=0?u.slice(0,e):u,r=e>=0?u.slice(e+1):[],i=e=>c&&e.startsWith(`-`)&&e!==`-`,a=new Set(n.globalExtracted?.fields.flatMap(e=>[e.name,e.cliName,...o(e)])),s=n.globalExtracted?R(n.globalExtracted):{},l=t.filter(i).flatMap(e=>Object.keys(N([e],s).options)).filter(e=>!a.has(e));return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:t.filter(e=>!i(e)),rest:r,unknownFlags:l,unknownGlobalFlags:p,rawGlobalArgs:f}}let x=Vt(l,u,{promptAvailable:n.promptAvailable===!0,inheritedNames:n.inheritedNames??/* @__PURE__ */ new Set});if(!x)return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:[],rest:[],unknownFlags:[],unknownGlobalFlags:p,extractedFields:l,matchesNoUnionOption:!0,rawGlobalArgs:f};let te=R(x),S=N(u,{...te,unknownFlagsTakeNoValue:c}),C=P(S,x),w=X(C,x),T=x.fields.filter(e=>e.named),D=new Set(T.map(e=>e.name)),O=new Set(T.map(e=>e.cliName)),k=/* @__PURE__ */ new Set;for(let e of T)for(let t of o(e))k.add(t);if(n.globalExtracted)for(let e of n.globalExtracted.fields){D.add(e.name),O.add(e.cliName);for(let t of o(e))k.add(t)}let A=[];for(let e of Object.keys(S.options))D.has(e)||O.has(e)||k.has(e)||A.push(e);return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:C,positionals:S.positionals,rest:S.rest,unknownFlags:A,unknownGlobalFlags:p,extractedFields:l,optionFields:T,positionalSlotFields:F(x,S.options),rawGlobalArgs:f,envFallbackFields:w}}function Vt(e,t,n){let{discriminator:r,variants:i,unionOptions:a}=e;if(r&&i){let n=e=>{let n=P(N(t,R(e)),e);return X(n,e),n},r=_(e,n);return r===e?i.some(t=>{let r=n({...e,fields:t.fields});return _(e,()=>r)!==e})?void 0:e:r}if(a){let r=a.flatMap(e=>{let r=Vt(e,t,n);return r?[r]:[]}),i=n.promptAvailable?r.filter(e=>Ht(e,t,void 0)):[],o=r.find(e=>Ht(e,t,n.inheritedNames))??(i.length===1?i[0]:void 0);return o&&{...e,fields:o.fields}}return e}function X(e,t){let n=/* @__PURE__ */ new Set;for(let r of t.fields)if(r.env&&e[r.name]===void 0)for(let t of[r.env].flat()){let i=process.env[t];if(i!==void 0){e[r.name]=re(i,r.type),n.add(r.name);break}}return n}function Ht(e,t,n){let r=N(t,R(e)),i=e.fields.filter(e=>e.named),a=new Set(i.flatMap(e=>[e.name,e.cliName,...o(e)]));if(Object.keys(r.options).some(e=>!a.has(e)))return!1;let s=F(e,r.options),c=r.positionals.length+r.rest.length;if(!s.some(e=>e.type===`array`)&&c>s.length)return!1;let l=P(r,e);return e.fields.some(e=>e.type!==`boolean`&&[l[e.name]].flat().includes(!0))?!1:n===void 0||(X(l,e),e.fields.every(e=>!e.required||l[e.name]!==void 0||n.has(e.name)))}function Ut(e,t){if(e.length===0)return{};let n=R(t),r=N(e,n);return P(r,t)}function Wt(t,n,r){let i=Nt(n),a=new Set(r?.fields.map(e=>e.name)??[]),s=new Set(r?.fields.map(e=>e.cliName)??[]),c=r?R(r):void 0,l=new Set(c?.aliasMap?.keys()??[]),u=new Set(c?.negationMap?.keys()??[]),d=/* @__PURE__ */ new Set;for(let t of r?.fields??[])if(t.type===`boolean`&&t.negation===!0)for(let n of[t.cliName,...o(t)]){let t=`no-${n}`;d.add(t),d.add(e(t))}let f=[],p=[],m=[];for(let e=0;e<t.length;e++){let n=t[e];if(n===`--`){p.push(...t.slice(e));break}if(n.startsWith(`--`)){let{resolvedName:r,withoutDashes:o,isNegated:c,isGlobal:p,isSuppressedNegation:h}=Pt(n,i),g=r,_=a.has(o)||a.has(g)||s.has(o)||s.has(g)||l.has(o)||l.has(g)||u.has(o)||u.has(g)||d.has(o);if(p&&!_){e+=Y(t,e,r,c,i.booleanFlags,f)-1;continue}if(h&&!_){m.push(o);continue}}else if(n.startsWith(`-`)&&n.length>1){let r=n.includes(`=`)?n.slice(1,n.indexOf(`=`)):n.slice(1);if(r.length===1){let n=i.aliasMap.get(r)??r;if((i.aliases.has(r)||i.flagNames.has(n))&&!l.has(r)){e+=Y(t,e,n,!1,i.booleanFlags,f)-1;continue}}let a=Ft(t,e,i,e=>l.has(e));if(a>0){f.push(...t.slice(e,e+a)),e+=a-1;continue}}p.push(n)}return{separated:p,globalParsed:Ut(f,n),suppressedTokens:m}}function Z(e,t){return p(t)?u(e,t):r().validate(e,t)}function Q(e){return e.map(e=>`${e.path.length>0?`${e.path.join(`.`)}: `:``}${e.message}`).join(`
|
|
33
|
+
`)}function Gt(e,t){let n=[];for(let e=0;e<=t.length;e++)n[e]=[e];for(let t=0;t<=e.length;t++)n[0][t]=t;for(let r=1;r<=t.length;r++)for(let i=1;i<=e.length;i++)t.charAt(r-1)===e.charAt(i-1)?n[r][i]=n[r-1][i-1]:n[r][i]=Math.min(n[r-1][i-1]+1,n[r][i-1]+1,n[r-1][i]+1);return n[t.length][e.length]}function Kt(e,t){let n=Math.max(2,Math.floor(e.length/2));return t.map(t=>({candidate:t,distance:Gt(e.toLowerCase(),t.toLowerCase())})).filter(({distance:e})=>e<=n).sort((e,t)=>e.distance-t.distance).map(({candidate:e})=>e).slice(0,3)}function qt(e,t){let n=Kt(e.replace(/^-{1,2}/,``),t),r=`${M.warning(`Warning: Unknown option:`)} ${M.bold(e)}`;if(n.length>0){r+=`\n\n${M.info(`Did you mean?`)}`;for(let e of n)r+=`\n ${j.arrow} ${M.option(`--${e}`)}`}return r}function Jt(e,t){return t&&e.stack?`${M.error(`Error:`)} ${e.message}\n\n${M.dim(e.stack)}`:`${M.error(`Error:`)} ${e.message}`}function $(t){return new Proxy(t,{get(t,n,r){if(typeof n==`string`){if(n in t)return Reflect.get(t,n,r);let i=e(n);if(i!==n&&i in t)return Reflect.get(t,i,r);let o=a(n);if(o!==n&&o in t)return Reflect.get(t,o,r)}return Reflect.get(t,n,r)},has(t,n){if(typeof n==`string`){if(n in t)return!0;let r=e(n);if(r!==n&&r in t)return!0;let i=a(n);if(i!==n&&i in t)return!0}return Reflect.has(t,n)}})}async function Yt(e,t,n){for(let r of t.fields)r.effect&&await r.effect(i(e,r),{name:r.name,args:e,...n!=null&&{globalArgs:n}})}const Xt={log:e=>console.log(e),error:e=>console.error(e),warn:e=>console.warn(e)};function Zt(e){let t={};for(let[n,r]of Object.entries(e))try{t[n]=structuredClone(r)}catch{t[n]=r}return t}function Qt(t,n){Object.defineProperty(t,"$source",{value:t=>n.get(t)??n.get(e(t))??n.get(a(t))??`default`,enumerable:!1})}function $t(e,t,n){let r=/* @__PURE__ */ new Map;for(let t of e)r.set(t,`cli`);for(let e of t)r.set(e,`env`);for(let e of n)r.set(e,`prompt`);return r}function en(e,t){Object.defineProperty(e,"$invocation",{value:t,enumerable:!1})}function tn(e,t){Object.defineProperty(e,"$agent",{value:t,enumerable:!1})}function nn(e,t){return e&&(n=>e({...n,agent:t}))}function rn(e,t,n){if(!e.rawGlobalArgs)return;let r=new Set(n.fields.map(e=>e.name)),i={};for(let[t,n]of Object.entries(e.rawGlobalArgs))r.has(t)&&(i[t]=n);let a=new Set(Object.keys(i)),o=X(i,n);for(let[t,n]of Object.entries(e.promptedGlobalArgs??{}))r.has(t)&&(o.delete(t),n===void 0?(delete i[t],a.delete(t)):i[t]=n);for(let n=0;n<=r.size;n++){let n=Z(i,t);if(n.success){let t=n.data,r=/* @__PURE__ */ new Map;for(let e of a)e in i&&r.set(e,`cli`);for(let e of o)e in i&&r.set(e,`env`);for(let[t,n]of Object.entries(e.promptedGlobalArgs??{}))n!==void 0&&t in i&&r.set(t,`prompt`);return Qt(t,r),$(t)}let r=n.errors.map(e=>e.path[0]).filter(e=>e!==void 0&&Object.hasOwn(i,e));if(r.length===0){let e=Object.keys(i).filter(e=>{let{[e]:n,...r}=i;return Z(r,t).success});if(e.length!==1)return;r=e}for(let e of r)delete i[e]}}function an(e,t,n,r){let i=e.success?void 0:e.error;if(e.success||t.effectsRan||!n||!r)return{error:i};try{return{error:i,globalArgs:rn(t,n,r)}}catch{return{error:i}}}function on(e,t){let{agentHelp:n,_agent:r}=e;if(n&&r)return typeof n==`string`?n:n({agent:r,commandPath:t.commandPath??[]})}function sn(e,t){let n=t.commandPath?.at(-1)??e.name;return t.aliasFor?{name:n,aliasFor:t.aliasFor}:{name:n}}async function cn(e,t,n={}){let r=pn(n),i=v(),a=nn(n.cleanup,i),o=n.captureLogs??!1,s=o?A():null;if(n.setup){s?.start();try{await n.setup({agent:i})}catch(e){let t=e instanceof Error?e:Error(String(e));if(a)try{await a({error:t})}catch{}return s?.stop(),{success:!1,error:t,exitCode:1,logs:s?.getLogs()??O()}}s?.stop()}let c={},l=await fn(e,t,{...n,handleSignals:!1,_globalExtracted:r,_globalCleanup:a,_existingLogs:s?.getLogs(),_agent:i,_globalTrace:c});if(a){let e=o?A():null;e?.start();let t=an(l,c,n.globalArgs,r);try{await a(t)}catch(t){if(l.success){let n=t instanceof Error?t:Error(String(t));return e?.stop(),{success:!1,error:n,exitCode:1,logs:k(l.logs,e?.getLogs()??O())}}}e?.stop();let i=e?.getLogs()??O();if(i.entries.length>0)return{...l,logs:k(l.logs,i)}}return l}function ln(e,t,n){let r=zt(t,n);return!r||!r.startsWith(`__`)?!1:Object.hasOwn(e.subCommands??{},r)}async function un(e,t={}){if(t.compileCache!==!1&&y(typeof t.compileCache==`string`?{cacheDir:t.compileCache}:{programName:e.name}),e.runMainHook)try{e.runMainHook(process.argv.slice(2))}catch{}let n=process.argv.slice(2),r;if(t.globalArgs)try{r=d(t.globalArgs)}catch{}let i=t;if(ln(e,n,r)){let{setup:e,cleanup:n,prompt:r,globalArgs:a,...o}=t;i=o}let a=pn(i),o=v(),s=nn(i.cleanup,o);if(i.skipValidation||Dt(e),i.onUnknownSubcommand&&!e.run&&!ln(e,n,r)){let t=E(e);if(t.size>0){let e=Rt(n,a,{stopOnSuppressedNegation:a?.unknownKeysMode!==`passthrough`}),r=e>=0?n[e]:void 0;if(r&&!t.has(r)){let t=n.slice(e+1),a=await i.onUnknownSubcommand({commandPath:[],name:r,args:t,precedingArgs:n.slice(0,e)});if(typeof a==`number`)return await dn(),process.exit(a)}}}if(i.setup)try{await i.setup({agent:o})}catch(e){let t=e instanceof Error?e:Error(String(e));if(s)try{await s({error:t})}catch{}process.exit(1)}let c={},l=await fn(e,n,{debug:i.debug,captureLogs:i.captureLogs,skipValidation:i.skipValidation,handleSignals:!0,logger:i.logger,globalArgs:i.globalArgs,prompt:i.prompt,onUnknownSubcommand:i.onUnknownSubcommand,agentHelp:i.agentHelp,_globalExtracted:a,_globalCleanup:s,_agent:o,_globalTrace:c,_context:{commandPath:[],rootName:e.name,rootVersion:i.version,globalExtracted:a}});if((i.displayErrors??!0)&&!l.success&&l.error&&(i.logger??Xt).error(Jt(l.error,i.debug??!1)),s){let e=an(l,c,i.globalArgs,a);try{await s(e)}catch{}}await dn(),process.exit(l.exitCode)}async function dn(){await Promise.all([process.stdout,process.stderr].map(e=>e.writableLength>0?new Promise(t=>e.write(``,()=>t())):Promise.resolve()))}async function fn(e,n,r={}){let i=r.logger??Xt,a=r._context??{commandPath:[],rootName:e.name,globalExtracted:r._globalExtracted},o=r.captureLogs??!1?A():null;o?.start();let s=()=>{let e=r._existingLogs??O(),t=o?.getLogs()??O();return k(e,t)};try{r.skipValidation||Dt(e);let c=Bt(n,e,{skipValidation:r.skipValidation,globalExtracted:r._globalExtracted,promptAvailable:r.prompt!==void 0,inheritedNames:new Set(Object.keys(r._parsedGlobalArgs??{}))}),u={...r._parsedGlobalArgs,...c.rawGlobalArgs};r._globalTrace&&(r._globalTrace.rawGlobalArgs={...u});let d=a.commandPath??[];if(r.onUnknownSubcommand&&!e.run&&d.length>0){let t=E(e);if(t.size>0){let e=Rt(n,r._globalExtracted,{stopOnSuppressedNegation:r._globalExtracted?.unknownKeysMode!==`passthrough`}),i=e>=0?n[e]:void 0;if(i&&!t.has(i)){let t=n.slice(e+1),a=await r.onUnknownSubcommand({commandPath:d,name:i,args:t,precedingArgs:[...r._precedingArgs??[],...n.slice(0,e)]});if(typeof a==`number`){if(o?.stop(),r.handleSignals){if(r._globalCleanup)try{await r._globalCleanup({error:void 0})}catch{}await dn(),process.exit(a)}return a===0?{success:!0,result:void 0,exitCode:0,logs:s()}:{success:!1,error:/* @__PURE__ */ Error(`Plugin "${[...d,i].join(` `)}" exited with code ${a}`),exitCode:a,logs:s()}}}}}if(c.helpRequested||c.helpAllRequested||c.helpJsonRequested){let t=!1,l=C(e),u=E(e);if(l.length>0){let e=zt(n,a.globalExtracted);e&&!u.has(e)&&(t=!0)}let d=on(r,a);if(c.helpJsonRequested){let t=Xe(e,{context:a,agentHelp:d});i.log(JSON.stringify(t))}else{let t=Je(e,{showSubcommands:r.showSubcommands??!0,showSubcommandOptions:c.helpAllRequested||r.showSubcommandOptions,context:a,agentHelp:d});i.log(t)}if(o?.stop(),t){let e=zt(n,a.globalExtracted)??``,t=Kt(e,[...u]),r=t.length>0?` Did you mean: ${t.join(`, `)}?`:``;return{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${e}${r?`.${r}`:``}`),exitCode:2,logs:s()}}return{success:!0,result:void 0,exitCode:0,logs:s()}}if(c.unknownGlobalFlags&&c.unknownGlobalFlags.length>0){let e=a.globalExtracted?.unknownKeysMode??`strip`;if(e===`strict`)return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown flags: ${c.unknownGlobalFlags.join(`, `)}`),exitCode:2,logs:s()};if(e===`strip`){let e=a.globalExtracted?.fields.map(e=>e.name)??[];for(let t of c.unknownGlobalFlags)i.error(qt(t,e))}}if(c.versionRequested){let e=a.rootVersion;return e&&i.log(e),o?.stop(),{success:!0,result:void 0,exitCode:0,logs:s()}}if(c.subCommand){let t=r._metadataOnly??!1,i=await ee(e,c.subCommand,e=>{if(t)return!0;if(!e.requiredPackages?.length)return!1;let n=e,i=c.remainingArgs;for(;;){let e=Bt(i,n,{skipValidation:r.skipValidation,globalExtracted:a.globalExtracted,promptAvailable:!!r.prompt});if(e.helpRequested||e.helpAllRequested||e.helpJsonRequested||e.versionRequested)return t=!0,!0;if(!e.subCommand||!n.subCommands)return!1;let o=Object.hasOwn(n.subCommands,e.subCommand)?e.subCommand:te(n,e.subCommand)??e.subCommand,s=n.subCommands[o],c=s?b(s):null;if(!c)return!1;n=c,i=e.remainingArgs}});if(i){let e={commandPath:[...a.commandPath??[],c.subCommand],rootName:a.rootName,rootVersion:a.rootVersion,globalExtracted:a.globalExtracted,aliasFor:i.aliasFor};o?.stop();let l=new Set(r._globalExtracted?.unknownKeysMode===`passthrough`?[]:c.unknownGlobalFlags??[]),d=e=>e.startsWith(`--`)&&l.has(ne(e)),f=n.slice(0,n.length-c.remainingArgs.length-1).filter(e=>!d(e));return fn(i.command,c.remainingArgs,{...r,_metadataOnly:t,_context:e,_existingLogs:s(),_parsedGlobalArgs:u,_precedingArgs:[...r._precedingArgs??[],...f]})}}let f=c.positionalSlotFields??[],p=f.some(e=>e.type===`array`),m=[...c.positionals,...c.rest],h=p?[]:m.slice(f.length),g=p?[]:c.positionals.slice(f.length);if(c.matchesNoUnionOption)return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Arguments match none of the accepted forms. See --help for the accepted forms.`),exitCode:2,logs:s()};let v=E(e),y=v.size>0?g.find(e=>!e.startsWith(`-`)&&!v.has(e)):void 0;if(y){let e=Kt(y,[...v]),t=e.length>0?` Did you mean: ${e.join(`, `)}?`:``;return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${y}${t?`.${t}`:``}`),exitCode:2,logs:s()}}if(c.unknownFlags.length>0){let e=c.extractedFields?.unknownKeysMode??a.globalExtracted?.unknownKeysMode??`strip`,t=c.optionFields?.map(e=>e.name)??a.globalExtracted?.fields.map(e=>e.name)??[];if(e===`strict`)return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown flags: ${c.unknownFlags.join(`, `)}`),exitCode:2,logs:s()};if(e===`strip`)for(let e of c.unknownFlags)i.error(qt(e,t))}if(C(e).length>0&&!c.subCommand&&!e.run&&h.length===0){if(e.defaultSubCommand){let t=e.subCommands?.[e.defaultSubCommand];if(t){let i=await T(t),l={commandPath:[...a.commandPath??[],e.defaultSubCommand],rootName:a.rootName,rootVersion:a.rootVersion,globalExtracted:a.globalExtracted};o?.stop();let d=new Set(r._globalExtracted?.unknownKeysMode===`passthrough`?[]:c.unknownGlobalFlags??[]),f=e=>e.startsWith(`--`)&&d.has(ne(e)),p=n.filter(e=>!f(e));return fn(i,[],{...r,_context:l,_existingLogs:s(),_parsedGlobalArgs:u,_precedingArgs:[...r._precedingArgs??[],...p]})}}if(r.globalArgs&&r._globalExtracted){let e={...u};X(e,r._globalExtracted);let t=Z(e,r.globalArgs),n=t.success?[]:t.errors.filter(t=>t.path[0]&&e[t.path[0]]!==void 0);if(n.length>0)return o?.stop(),{success:!1,error:Error(Q(n)),exitCode:2,logs:s()}}let t=Je(e,{showSubcommands:r.showSubcommands??!0,context:a,agentHelp:on(r,a)});return i.log(t),o?.stop(),{success:!0,result:void 0,exitCode:0,logs:s()}}if(h.length>0){let e=c.extractedFields?.unknownKeysMode??`strip`;if(e===`strict`)return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unexpected positional argument${h.length>1?`s`:``}: ${h.join(`, `)}`),exitCode:2,logs:s()};if(e===`strip`)for(let e of h)(i.warn??i.error)(`Warning: Unexpected positional argument: ${e}`)}let x={},S=e.name===`__complete`,w=new Set(Object.keys(u)),D=/* @__PURE__ */ new Set,O=/* @__PURE__ */ new Set;if(r.globalArgs&&r._globalExtracted&&!S){if(D=X(u,r._globalExtracted),r.prompt){let e=Zt(u);try{let e=await r.prompt(u,r._globalExtracted,{globalArgs:u});for(let[t,n]of Object.entries(e))n!==void 0&&(u[t]=n)}finally{let t={};for(let n of/* @__PURE__ */ new Set([...Object.keys(e),...Object.keys(u)])){let r=u[n];oe(e[n],r)||(t[n]=r,r===void 0&&(w.delete(n),D.delete(n)))}O=new Set(Object.keys(t).filter(e=>t[e]!==void 0)),r._globalTrace&&(r._globalTrace.promptedGlobalArgs=t)}}let e=Z(u,r.globalArgs);if(!e.success)return o?.stop(),{success:!1,error:Error(Q(e.errors)),exitCode:2,logs:s()};x=e.data}let k=r.globalArgs&&r._globalExtracted&&!S?l(r._globalExtracted,e=>Z(u,e).success,()=>u):r._globalExtracted,A=S||!r._globalExtracted?void 0:k===r._globalExtracted?_(r._globalExtracted,()=>x).fields:k?.fields;if(!e.args){let t=$t(w,D,O);Qt(x,t),en(x,sn(e,a)),tn(x,r._agent);let n=$(x);return r._globalExtracted&&!S&&(r._globalTrace&&(r._globalTrace.effectsRan=!0),await Yt(n,k,n)),o?.stop(),await ce(e,n,{handleSignals:r.handleSignals,captureLogs:r.captureLogs,existingLogs:s(),globalCleanup:r._globalCleanup,packageDiscriminators:r._globalExtracted?.discriminator?[r._globalExtracted.discriminator]:[],packageFields:A})}let j=c.rawArgs,M=r.prompt?Zt(c.rawArgs):c.rawArgs,N=e=>Object.hasOwn(M,e),re=/* @__PURE__ */ new Set;if(r.prompt&&c.extractedFields){let e=await r.prompt(j,c.extractedFields,{globalArgs:x}),t={...j};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);j=t;for(let[e,t]of Object.entries(j))t===void 0||N(e)&&oe(M[e],t)||re.add(e)}let P=Z(j,e.args);if(!P.success)return o?.stop(),{success:!1,error:Error(Q(P.errors)),exitCode:2,logs:s()};let ie=$(P.data),ae=$t(w,D,O);Qt(x,ae),en(x,sn(e,a)),tn(x,r._agent);let F=$(x);r._globalExtracted&&!S&&(r._globalTrace&&(r._globalTrace.effectsRan=!0),await Yt(F,k,F));let I=c.extractedFields?S?c.extractedFields:l(c.extractedFields,e=>Z(j,e).success,()=>j):void 0;I&&!S&&await Yt(ie,I,F);let L=t({...F},{...ie},k?.fields??[],I?.fields??[]),R=new Map(ae),se=c.envFallbackFields??/* @__PURE__ */ new Set;for(let e of c.extractedFields?.fields??[]){let t=j[e.name]!==void 0;R.set(e.name,re.has(e.name)?`prompt`:t&&se.has(e.name)?`env`:t&&N(e.name)?`cli`:`default`)}Qt(L,R),en(L,sn(e,a)),tn(L,r._agent);let le=$(L);return o?.stop(),await ce(e,le,{handleSignals:r.handleSignals,captureLogs:r.captureLogs,existingLogs:s(),globalCleanup:r._globalCleanup,packageDiscriminators:[c.extractedFields?.discriminator,r._globalExtracted?.discriminator].filter(e=>e!==void 0),packageFields:S?void 0:[...A??[],...I!==c.extractedFields&&I?I.fields:[...c.optionFields??[],...c.positionalSlotFields??[]]]})}catch(e){let t=e instanceof Error?e:Error(String(e));return o?.stop(),{success:!1,error:t,exitCode:1,logs:s()}}}function pn(e){if(!e.globalArgs)return;let t=d(e.globalArgs);if(!e.skipValidation){ht(t),xt(t),gt(t),bt(t),vt(t,!0),yt(t);let e=t.fields.filter(e=>e.positional).map(e=>e.name);if(e.length>0)throw Error(`Global options schema must not contain positional arguments. Found: ${e.join(`, `)}`)}return t}export{$e as C,z as D,Xe as E,me as O,Qe as S,Je as T,at as _,Mt as a,rt as b,wt as c,ht as d,bt as f,nt as g,yt as h,Q as i,Dt as l,vt as m,un as n,xt as o,_t as p,$ as r,At as s,cn as t,gt as u,tt as v,it as w,ot as x,et as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as e,f as t}from"./schema-extractor-DL8vjWso.js";const n=e({shell:t.enum([`bash`,`zsh`,`fish`],{description:`Target shell for output formatting`}),args:t.stringArray({positional:!0,description:`Arguments to complete`})});export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,d as t,m as n,r,s as i}from"./unflatten-D6YJ7e-J.js";const a=`__polittyInternalArgs`,o={string(e){return{kind:`string`,optional:!1,meta:e}},optionalString(e){return{kind:`string`,optional:!0,meta:e}},boolean(e){return{kind:`boolean`,optional:!1,defaultValue:!1,meta:e}},enum(e,t){return{kind:`enum`,enumValues:e,optional:!1,meta:t}},optionalEnum(e,t){return{kind:`enum`,enumValues:e,optional:!0,meta:t}},stringArray(e){return{kind:`string-array`,optional:!1,defaultValue:[],meta:e}},optionalStringArray(e){return{kind:`string-array`,optional:!0,meta:e}}};function s(e,t={}){return{[a]:!0,fields:e,unknownKeys:t.unknownKeys??`strip`}}function c(e){return typeof e==`object`&&!!e&&e[a]===!0}const l={string:`string`,boolean:`boolean`,enum:`string`,"string-array":`array`},u=/* @__PURE__ */ new WeakMap;function d(e){let n=u.get(e);if(n)return n;let r={fields:Object.entries(e.fields).map(([e,n])=>t(e,{argMeta:n.meta,description:void 0,required:!n.optional&&n.defaultValue===void 0,defaultValue:n.defaultValue,type:l[n.kind],enumValues:n.enumValues?[...n.enumValues]:void 0,schema:n})),schema:e,schemaType:`object`,unknownKeysMode:e.unknownKeys};return u.set(e,r),r}function f(e){switch(e.kind){case`enum`:return`one of ${(e.enumValues??[]).map(e=>JSON.stringify(e)).join(` | `)}`;case`string-array`:return`array`;default:return e.kind}}function p(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function m(e,t,n){return{path:[e],message:`Invalid input: expected ${f(t)}, received ${p(n)}`,code:`invalid_type`,received:n,expected:f(t)}}function h(e,t,n){switch(t.kind){case`string`:return typeof n==`string`?null:m(e,t,n);case`boolean`:return typeof n==`boolean`?null:m(e,t,n);case`enum`:return typeof n!=`string`||!(t.enumValues??[]).includes(n)?{path:[e],message:`Invalid option: expected ${f(t)}`,code:`invalid_value`,received:n,expected:f(t)}:null;case`string-array`:return!Array.isArray(n)||n.some(e=>typeof e!=`string`)?m(e,t,n):null}}function g(e,t){let n=[],r={};for(let[i,a]of Object.entries(t.fields)){let t=e[i];if(t===void 0){a.defaultValue===void 0?a.optional||n.push(m(i,a,void 0)):r[i]=Array.isArray(a.defaultValue)?[...a.defaultValue]:a.defaultValue;continue}let o=h(i,a,t);o?n.push(o):r[i]=t}let i=new Set(Object.keys(t.fields)),a=Object.keys(e).filter(e=>!i.has(e));if(a.length>0){if(t.unknownKeys===`strict`)n.push({path:[],message:`Unrecognized key${a.length>1?`s`:``}: ${a.map(e=>JSON.stringify(e)).join(`, `)}`,code:`unrecognized_keys`});else if(t.unknownKeys===`passthrough`)for(let t of a)Object.defineProperty(r,t,{value:e[t],enumerable:!0,writable:!0,configurable:!0})}return n.length>0?{success:!1,errors:n}:{success:!0,data:r}}function _(e){return c(e)?e.unknownKeys:n().getUnknownKeysMode(e)}const v=/* @__PURE__ */ new WeakSet,y=/* @__PURE__ */ new WeakMap;function b(e){let t=c(e)?d(e):S(e,n().extractFields(e));return v.has(t)||(w(t),v.add(t)),t}function x(e){for(let t of e.unionOptions??[])i(t.schema),x(t)}function S(t,n){x(n);let i=r(t);if(!i)return n;let a=y.get(n);return a||(a=C(n,e(i)),y.set(n,a)),a}function C(e,t){let n=e=>e.map(e=>{let n=t(e.name);return n.length>1?{...e,nested:{path:n}}:e});return{...e,fields:n(e.fields),...e.variants&&{variants:e.variants.map(e=>({...e,fields:n(e.fields)}))},...e.unionOptions&&{unionOptions:e.unionOptions.map(e=>C(e,t))}}}function w(e){let t=e.variants??[e];for(let n of t)for(let t of n.fields)if(t.requiredPackages?.length&&t.type!==`boolean`&&t.name!==e.discriminator)throw Error(`Invalid requiredPackages for field "${t.name}": requiredPackages can only be used on boolean fields or discriminators.`);for(let t of e.unionOptions??[])w(t)}function T(e){return e.args?b(e.args):null}function E(e,t){let[n,...r]=e,i=/* @__PURE__ */ new Set;for(let e of n?.fields??[])e.name!==t&&r.every(t=>t.fields.some(t=>t.name===e.name&&t.positional===e.positional&&t.named===e.named&&D(t.requiredPackages,e.requiredPackages)))&&i.add(e.name);return i}function D(e,t){return(e?.length??0)===(t?.length??0)&&(e??[]).every((e,n)=>{let r=t?.[n];return e.name===r?.name&&e.install===r.install&&e.from?.toString()===r.from?.toString()})}function O(e){let t=j(e).filter(e=>e.named);return M(e,e=>e.named).map(e=>{let n=t.filter(t=>t.name===e.name),r=[...new Set(n.flatMap(e=>e.alias??[]))],i=[...new Set(n.flatMap(e=>e.hiddenAlias??[]))];return{...e,alias:r.length>0?r:e.alias,hiddenAlias:i.length>0?i:e.hiddenAlias}})}function k(e){return M(e,e=>e.positional)}function A(e){return M(e,e=>!e.positional)}function j(e){let t=e.variants??e.unionOptions??[];return[e.fields,...t.map(e=>e.fields)].flat()}function M(e,t){let n=/* @__PURE__ */ new Map;for(let r of j(e))t(r)&&!n.has(r.name)&&n.set(r.name,r);return[...n.values()]}function N(e,t){return e.effect===t.effect&&D(e.requiredPackages,t.requiredPackages)&&(e.nested?.path??[]).join(`\0`)===(t.nested?.path??[]).join(`\0`)}function P(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let r of e){if(r.unionOptions&&P(r.unionOptions)||r.variants&&P(r.variants))return!0;for(let e of r.fields){let r=t.get(e.name);if(!r)t.set(e.name,e);else if(!N(r,e))return!0;n.set(e.name,(n.get(e.name)??0)+1)}}return[...t].some(([t,r])=>n.get(t)<e.length&&(r.effect!==void 0||!!r.requiredPackages?.length))}function F(e,t,n){let r=e.unionOptions;if(e.discriminator||!r||!P(r))return e;for(let i of r){if(!t(i.schema))continue;let r=i.discriminator&&i.variants?I(i,n):F(i,t,n);return{...e,fields:r.fields}}return e}function I(e,t){let{discriminator:n,variants:r}=e;if(!n||!r){let n=e.unionOptions??[],r=n.map(e=>I(e,t));if(r.every((e,t)=>e===n[t]))return e;let i=r.filter((r,i)=>{let a=t(r),o=n[i];if(o.discriminator&&a[o.discriminator]!==void 0&&r===o)return!1;let s=new Set(r.fields.map(e=>e.name));return!e.fields.some(e=>a[e.name]!==void 0&&!s.has(e.name))});if(!i.length)return e;let a=/* @__PURE__ */ new Map;for(let e of i)for(let t of e.fields){let e=a.get(t.name);e?a.set(t.name,{...e,type:e.type===t.type?e.type:`unknown`,named:e.named||t.named,positional:e.positional||t.positional,alias:[.../* @__PURE__ */ new Set([...e.alias??[],...t.alias??[]])],hiddenAlias:[.../* @__PURE__ */ new Set([...e.hiddenAlias??[],...t.hiddenAlias??[]])]}):a.set(t.name,t)}return{...e,fields:[...a.values()]}}let i=r.map(r=>{let i={...e,fields:r.fields};return{variant:r,fields:i,value:t(i)[n]}});for(let{variant:e,fields:t,value:n}of i)if(n!==void 0&&String(n)===e.discriminatorValue)return t;for(let{variant:e,fields:t,value:n}of i)if(n!==void 0&&e.normalizeDiscriminator&&String(e.normalizeDiscriminator(n))===e.discriminatorValue)return t;return e}function L(e,t){return A(e).find(e=>e.name===t)}export{O as a,k as c,s as d,o as f,_ as i,F as l,g as m,b as n,L as o,c as p,T as r,A as s,E as t,I as u};
|
package/dist/skill.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as AnyCommand, T as ArgsSchema, it as UnknownKeysMode } from "./arg-registry-SvIkYiSr.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
//#region ../core/src/skill/types.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* SKILL.md frontmatter metadata, validated against the Agent Skills
|
|
6
5
|
* specification (https://agentskills.io/specification). Unknown fields are
|
|
@@ -201,8 +200,8 @@ interface SkillCommandOptions {
|
|
|
201
200
|
* A same-named field of another type (e.g. a string verbosity level)
|
|
202
201
|
* doesn't trigger this — the local boolean flag stays declared. However,
|
|
203
202
|
* politty itself independently rejects that combination: when
|
|
204
|
-
* `globalArgs` and a command's own schema declare a same-named field
|
|
205
|
-
*
|
|
203
|
+
* `globalArgs` and a command's own schema declare a same-named field,
|
|
204
|
+
* `runMain`/`runCommand` throws
|
|
206
205
|
* `FieldTypeConflictError` at parse time. {@link SkillFlagOverrides} can't
|
|
207
206
|
* help here — it only renames the short alias (`-v`/`-x`), not the long
|
|
208
207
|
* `--verbose`/`--json` field name itself, so the conflicting name stays
|
|
@@ -210,15 +209,10 @@ interface SkillCommandOptions {
|
|
|
210
209
|
* `json` field must rename or remove that global field (or make it a
|
|
211
210
|
* plain boolean) instead.
|
|
212
211
|
*
|
|
213
|
-
* (
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* fixed in politty core independently of this option — a same-named
|
|
218
|
-
* local and global field with *identical* definitions now resolves
|
|
219
|
-
* correctly regardless of position. This option still omits the local
|
|
220
|
-
* flag by default for simplicity: hosts don't need to duplicate the
|
|
221
|
-
* flag's definition on both schemas to get the expected behavior.)
|
|
212
|
+
* (This omission is required: politty rejects a field declared in both
|
|
213
|
+
* `globalArgs` and a command's own schema, even when the definitions are
|
|
214
|
+
* identical. Omitting the local flag leaves the host's global field as the
|
|
215
|
+
* only declaration.)
|
|
222
216
|
*
|
|
223
217
|
* @example
|
|
224
218
|
* ```ts
|
|
@@ -358,8 +352,6 @@ type WithSkillCommand<T extends AnyCommand> = T & {
|
|
|
358
352
|
skills: AnyCommand;
|
|
359
353
|
};
|
|
360
354
|
};
|
|
361
|
-
//#endregion
|
|
362
|
-
//#region ../core/src/skill/frontmatter.d.ts
|
|
363
355
|
/**
|
|
364
356
|
* Result of parsing a SKILL.md file.
|
|
365
357
|
*/
|
|
@@ -404,8 +396,6 @@ export declare function parseFrontmatter(content: string): {
|
|
|
404
396
|
* missing or fails schema validation.
|
|
405
397
|
*/
|
|
406
398
|
export declare function parseSkillMd(content: string): ParsedSkillMd | null;
|
|
407
|
-
//#endregion
|
|
408
|
-
//#region ../core/src/skill/installer.d.ts
|
|
409
399
|
/**
|
|
410
400
|
* Key used to read provenance off an installed skill. The SKILL.md's
|
|
411
401
|
* `metadata["politty-cli"]` must equal `"{packageName}:{cliName}"` for the
|
|
@@ -522,8 +512,6 @@ export declare function hasInstalledSkill(name: string, cwd?: string): boolean;
|
|
|
522
512
|
* Use {@link hasInstalledSkill} to distinguish the two cases.
|
|
523
513
|
*/
|
|
524
514
|
export declare function readInstalledOwnership(name: string, cwd?: string): string | null;
|
|
525
|
-
//#endregion
|
|
526
|
-
//#region ../core/src/skill/scanner.d.ts
|
|
527
515
|
/**
|
|
528
516
|
* Scan a source directory for SKILL.md files.
|
|
529
517
|
*
|
|
@@ -552,8 +540,6 @@ export declare function readInstalledOwnership(name: string, cwd?: string): stri
|
|
|
552
540
|
* ```
|
|
553
541
|
*/
|
|
554
542
|
export declare function scanSourceDir(sourceDir: string): ScanResult;
|
|
555
|
-
//#endregion
|
|
556
|
-
//#region ../core/src/skill/index.d.ts
|
|
557
543
|
/**
|
|
558
544
|
* Wrap a command with a `skills` subcommand for managing SKILL.md-based skills.
|
|
559
545
|
*
|
|
@@ -578,8 +564,6 @@ export declare function scanSourceDir(sourceDir: string): ScanResult;
|
|
|
578
564
|
* overwriting it would hide a configuration bug.
|
|
579
565
|
*/
|
|
580
566
|
export declare function withSkillCommand<T extends AnyCommand>(command: T, options: SkillCommandOptions): WithSkillCommand<T>;
|
|
581
|
-
//#endregion
|
|
582
|
-
//#region src/skill-frontmatter-schema.d.ts
|
|
583
567
|
/**
|
|
584
568
|
* Zod schema for SKILL.md frontmatter.
|
|
585
569
|
*
|
|
@@ -604,5 +588,4 @@ export declare const skillFrontmatterSchema: z.ZodObject<{
|
|
|
604
588
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
605
589
|
"allowed-tools": z.ZodOptional<z.ZodString>;
|
|
606
590
|
}, z.core.$loose>;
|
|
607
|
-
//#endregion
|
|
608
591
|
export type { DiscoveredSkill, InstallMode, InstallSkillOptions, ParsedSkillMd, ScanError, ScanErrorReason, ScanResult, SkillCommandOptions, SkillFlagOverrides, SkillFrontmatter, UninstallSkillOptions, WithSkillCommand };
|
package/dist/skill.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./register-w1jLVF3B.js";import{d as e,n as t,u as n}from"./schema-extractor-lB6-WHOF.js";import{n as r}from"./command-BXsTrIgI.js";import{a as i,n as a}from"./logger-CoeDrmRr.js";import{copyFileSync as o,existsSync as s,lstatSync as c,mkdirSync as l,mkdtempSync as u,readFileSync as d,readdirSync as f,readlinkSync as p,realpathSync as m,renameSync as ee,rmSync as h,statSync as g,symlinkSync as te,unlinkSync as _}from"node:fs";import{basename as v,dirname as y,isAbsolute as b,join as x,parse as ne,relative as S,resolve as C,sep as w}from"node:path";import{parse as re}from"yaml";import{z as T}from"zod";const ie=/^[a-z0-9]+(-[a-z0-9]+)*$/;function E(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function ae(e){let t=[],n=(n,r)=>{let i=e[n];i===void 0?r.required&&t.push({path:[n],message:`Invalid input: expected string, received undefined`}):typeof i==`string`?(r.min!==void 0&&i.length<r.min&&t.push({path:[n],message:`Too small: expected string to have >=${r.min} characters`}),r.max!==void 0&&i.length>r.max&&t.push({path:[n],message:`Too big: expected string to have <=${r.max} characters`})):t.push({path:[n],message:`Invalid input: expected string, received ${E(i)}`})};n(`name`,{required:!0,min:1,max:64}),typeof e.name==`string`&&!ie.test(e.name)&&t.push({path:[`name`],message:`name must be lowercase alphanumerics separated by single hyphens`}),n(`description`,{required:!0,min:1,max:1024}),n(`license`,{min:1}),n(`compatibility`,{max:500}),n(`allowed-tools`,{});let r=e.metadata;if(r!==void 0){if(typeof r!=`object`||!r||Array.isArray(r))t.push({path:[`metadata`],message:`Invalid input: expected record, received ${E(r)}`});else for(let[e,n]of Object.entries(r))typeof n!=`string`&&t.push({path:[`metadata`,e],message:`Invalid input: expected string, received ${E(n)}`})}return t.length>0?{success:!1,issues:t}:{success:!0,data:{...e}}}const oe=/^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)([\s\S]*)$/;function D(e){let t=e.match(oe);if(!t)return{data:{},body:e};let n=t[1],r=t[2];try{let e=re(n);return se(e)?{data:e,body:r}:{data:{},body:r}}catch(e){return{data:{},body:r,parseError:e instanceof Error?e.message:String(e)}}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ce(e){let{data:t,body:n}=D(e),r=ae(t);return r.success?{frontmatter:r.data,body:n,rawContent:e}:null}const O=`.agents/skills`,k=[`.claude/skills`],A=`politty-cli`;function j(e){if(e.length<1||e.length>64||!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e))throw Error(`Invalid skill name: ${JSON.stringify(e)}`)}function le(e,t=process.cwd(),n={}){let r=e.frontmatter.name;j(r);let i=n.mode??`symlink`,a=e.frontmatter.metadata?.[`politty-cli`]??null;if(i===`copy`&&a===null)throw Error(`Refusing to install "${e.frontmatter.name}" in copy mode without an ownership stamp. Add metadata.${A}="{package}:{cli}" to the source SKILL.md so subsequent installs can replace the copy in place.`);let o=C(t,O),s=m(e.sourcePath),c=ue(e.sourcePath),u=[x(N(o),r),...k.map(e=>x(N(C(t,e)),r))].find(e=>ye(e,s));if(u!==void 0)throw Error(`Refusing to install "${r}": source ${s} overlaps install destination ${u}. Choose a sourceDir outside .agents/skills/ and any agent-specific slot directory (e.g. .claude/skills/).`);if(i===`symlink`){let e=N(o);M(x(e,r),S(e,c));for(let n of k){let i=N(C(t,n));M(x(i,r),x(S(i,e),r))}}l(o,{recursive:!0});let d=m(o),f=x(d,r);he(f,a),ge({linkTarget:S(d,c),linkPath:f,copyFrom:s,mode:i}),ve(t,r,f,a,i)}function M(e,t){if(b(t))throw Error(`Refusing to write an absolute symlink target at ${e} → ${t}. The skill source and install root appear to live on different filesystem roots (e.g. different Windows drive letters); retry with mode: "copy".`)}function ue(e){let t=C(e),{root:n}=ne(t),r=t.slice(n.length).split(w).filter(e=>e!==``),i=n;for(let[e,t]of r.entries()){let n=x(i,t),a;try{a=c(n)}catch{return x(i,...r.slice(e))}if(a.isSymbolicLink()){if(de(i))return x(i,...r.slice(e));i=m(n)}else i=n}return i}function de(e){return v(e)===`node_modules`||v(e).startsWith(`@`)&&v(y(e))===`node_modules`}function N(e){let t=e,n=[];for(;;)try{let e=m(t);return n.length===0?e:C(e,...n.reverse())}catch{let r=y(t);if(r===t)return e;n.push(t.slice(r.length).replace(/^[/\\]+/,``)),t=r}}function fe(e,t=process.cwd(),n={}){j(e);let r=n.expectedOwnership??null,i=C(t,O,e);for(let n of k)me(C(t,n,e),r,{restrictSymlinkTo:i});me(i,r)}function pe(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n);if(r===t)return!0;try{return m(r)===m(t)}catch{return!1}}function me(e,t,n={}){let r;try{r=c(e)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return;throw e}if(r.isSymbolicLink()){if(n.restrictSymlinkTo!==void 0){pe(e,n.restrictSymlinkTo)&&_(e);return}(t===null||F(e)===t)&&_(e)}else r.isDirectory()&&t!==null&&F(e)===t&&h(e,{recursive:!0,force:!0})}function he(e,t,n={}){let r;try{r=c(e)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return;throw e}if(r.isSymbolicLink()){if(n.restrictSymlinkTo===void 0||pe(e,n.restrictSymlinkTo)){_(e);return}throw Error(`Refusing to replace symlink at ${e}: it does not route to this CLI's canonical slot (${n.restrictSymlinkTo}). Remove or migrate the foreign symlink before retrying.`)}if(r.isDirectory()&&t!==null&&F(e)===t)h(e,{recursive:!0,force:!0});else throw Error(`Refusing to replace non-symlink path at ${e}. This looks like a legacy or manual install; remove or migrate it before retrying.`)}function ge(e){let{linkTarget:t,linkPath:n,copyFrom:r,mode:i}=e;if(i===`copy`)_e(r,n);else{M(n,t);try{te(t,n,`dir`)}catch(e){let r=e instanceof Error?e.message:String(e);throw Error(`Failed to symlink ${n} → ${t}: ${r}. If this filesystem does not support symlinks (e.g. Windows without Developer Mode), retry with mode: "copy".`,{cause:e})}}}function _e(e,t){let n=u(`${t}.partial-`);try{P(e,n),ee(n,t)}catch(e){try{h(n,{recursive:!0,force:!0})}catch{}throw e}}function P(e,t,n=/* @__PURE__ */ new Set){let r=g(e);if(r.isDirectory()){let r=m(e);if(n.has(r))throw Error(`Refusing to recursively copy cyclic directory symlink at ${e} (resolves to ${r}, already on the copy stack).`);n.add(r);try{l(t,{recursive:!0});for(let r of f(e))P(x(e,r),x(t,r),n)}finally{n.delete(r)}}else r.isFile()&&o(e,t)}function F(e){let t;try{t=d(x(e,`SKILL.md`),`utf-8`)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:n}=D(t),r=n.metadata;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r[A];return typeof i==`string`?i:null}function I(e,t=process.cwd()){return j(e),s(C(t,O,e,`SKILL.md`))}function L(e,t=process.cwd()){j(e);let n=C(t,O,e,`SKILL.md`),r;try{r=d(n,`utf-8`)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:i}=D(r),a=i.metadata;if(!a||typeof a!=`object`||Array.isArray(a))return null;let o=a[A];return typeof o==`string`?o:null}function ve(e,t,n,r,i){for(let a of k){let o=C(e,a);l(o,{recursive:!0});let s=m(o),c=x(s,t);he(c,r,{restrictSymlinkTo:n});let u=m(C(n,`..`));ge({linkTarget:x(S(s,u),t),linkPath:c,copyFrom:n,mode:i})}}function R(e){return e instanceof Error&&typeof e.code==`string`}function ye(e,t){if(e===t)return!0;let n=(e,t)=>{let n=S(t,e);return n===``||n===`.`||!b(n)&&n!==`..`&&!n.startsWith(`..${w}`)};return n(e,t)||n(t,e)}const z=`SKILL.md`;function B(e){let t=[],n=[];try{let r;try{r=g(e)}catch(r){return H(r)&&(r.code===`ENOENT`||r.code===`ENOTDIR`)?n.push({path:e,reason:`missing-source`,message:`Source directory does not exist: ${e}`}):n.push({path:e,reason:`read-failed`,message:`Failed to stat source directory ${e}: ${V(r)}`}),{skills:t,errors:n}}if(!r.isDirectory())return n.push({path:e,reason:`missing-source`,message:`Source path is not a directory: ${e}`}),{skills:t,errors:n};let i=x(e,z),a=Se(i);if(a.kind===`error`)return n.push({path:e,reason:`read-failed`,message:`Failed to check ${i}: ${a.message}`}),{skills:t,errors:n};if(a.kind===`present`)return xe(be(e,{enforceParentMatch:!1}),t,n),{skills:t,errors:n};let o=f(e,{withFileTypes:!0});for(let r of o){let i=x(e,r.name),a;try{a=g(i).isDirectory()}catch(e){if(H(e)&&e.code===`ENOENT`&&!r.isSymbolicLink())continue;n.push({path:i,reason:`read-failed`,message:r.isSymbolicLink()?`Dangling symlink at ${i}: ${V(e)}`:`Failed to stat ${i}: ${V(e)}`});continue}if(!a)continue;let o=x(i,z),s=Se(o);s.kind===`error`?n.push({path:i,reason:`read-failed`,message:`Failed to check ${o}: ${s.message}`}):s.kind!==`absent`&&xe(be(i,{enforceParentMatch:!0}),t,n)}}catch(t){n.push({path:e,reason:`read-failed`,message:`Failed to scan ${e}: ${V(t)}`})}return t.sort((e,t)=>e.frontmatter.name<t.frontmatter.name?-1:+(e.frontmatter.name>t.frontmatter.name)),{skills:t,errors:n}}function be(e,t){let n=x(e,z),r;try{r=d(n,`utf-8`)}catch(t){return{path:e,reason:`read-failed`,message:`Failed to read ${n}: ${V(t)}`}}let{data:i,parseError:a}=D(r);if(a!==void 0)return{path:e,reason:`parse-failed`,message:`Invalid SKILL.md frontmatter in ${e}: YAML parse error: ${a}`};let o=ae(i);if(!o.success)return{path:e,reason:`parse-failed`,message:`Invalid SKILL.md frontmatter in ${e}: ${o.issues.map(e=>`${e.path.join(`.`)||`<root>`}: ${e.message}`).join(`; `)}`};if(t.enforceParentMatch){let t=v(e);if(t!==o.data.name)return{path:e,reason:`name-mismatch`,message:`Skill name "${o.data.name}" does not match directory "${t}"`,skillName:o.data.name}}return{frontmatter:o.data,sourcePath:e,rawContent:r}}function xe(e,t,n){`frontmatter`in e?t.push(e):n.push(e)}function V(e){return e instanceof Error?e.message:String(e)}function H(e){return e instanceof Error&&typeof e.code==`string`}function Se(e){try{return c(e),{kind:`present`}}catch(e){return H(e)&&e.code===`ENOENT`?{kind:`absent`}:{kind:`error`,message:V(e)}}}function Ce(e,t={}){let n=0,r=!1;for(let i of e)i.reason===`missing-source`||i.path===t.sourceDir?(r=!0,a.warn(`Failed to scan source directory ${i.path}: ${i.message}`)):(n+=1,a.warn(`Skipping skill at ${i.path}: ${i.message}`));t.silentStdout||(n>0&&a.info(`${i.warning} Skipped ${n} skill(s) due to scan errors (see warnings above).`),r&&a.info(`${i.warning} Source directory scan failed (see warnings above); subsequent operations may be skipped.`))}function U(e,t){let n=e.errors.some(e=>e.reason===`missing-source`||e.path===t),r=e.errors.length>0&&e.skills.length===0;return n||r}function W(e,t={}){let n=B(e.sourceDir);return Ce(n.errors,{...t,sourceDir:e.sourceDir}),n}function we(e){let t={description:`Skill names to exclude from sync`};return e.excludeAlias!==void 0&&(t.alias=e.excludeAlias),t}function Te(e){let t={description:`Print install paths and modes`};return e.verbose.alias!==void 0&&(t.alias=e.verbose.alias),t}function G(e,t){return!!e[t]}function Ee(t){function i(e,n){let{skills:r,errors:i}=W(t),o=t.stamp,s=new Set(r.map(e=>e.frontmatter.name)),c=new Set(Ie(o,t.cwd,t.sourceDir)),l=Array.from(new Set(e.exclude)).filter(e=>!s.has(e)&&!c.has(e));if(l.length>0){let e=l.length===1?`Skill`:`Skills`,t=l.map(e=>JSON.stringify(e)).join(`, `);throw Error(`--exclude: ${e} ${t} not found in source directory or among installed skills.\n`+q({source:r,installed:c}))}let u=new Set(e.exclude),d=r.filter(e=>!u.has(e.frontmatter.name)),f=U({skills:r,errors:i},t.sourceDir),p=0;if(!f){let e=new Set(d.map(e=>e.frontmatter.name)),n=/* @__PURE__ */ new Set;for(let e of i)e.path!==t.sourceDir&&(n.add(v(e.path)),e.skillName!==void 0&&n.add(e.skillName));for(let r of c)e.has(r)||u.has(r)||n.has(r)||(Y(r,o,t.cwd,t.sourceDir),p+=1)}let m=0;for(let e of d)J(e,o,t,n),m+=1;if(m===0&&p===0){let e=f?`source directory scan failed; see warnings`:r.length>0&&d.length===0?`all skills excluded`:`no skills bundled`;a.info(`No skills installed (${e}).`)}else a.info(`Sync complete: ${m} installed, ${p} removed.`)}return t.verbose.disabled?r({name:`sync`,description:t.descriptions.sync,args:n({exclude:e.stringArray(we(t))},{unknownKeys:t.unknownKeys}),run(e){i(e,G(e,`verbose`))}}):r({name:`sync`,description:t.descriptions.sync,args:n({exclude:e.stringArray(we(t)),verbose:e.boolean(Te(t))},{unknownKeys:t.unknownKeys}),run(e){i(e,e.verbose)}})}function De(t){let i={positional:!0,description:`Skill name(s) to install (default: all)`,placeholder:`NAME`};function o(e,n){let r=W(t),i=r.skills,o=t.stamp;if(e.name.length>0){let r=new Set(i.map(e=>e.frontmatter.name)),a=Array.from(new Set(e.name)),s=a.filter(e=>!r.has(e));if(s.length>0){let e=s.length===1?`Skill`:`Skills`,t=s.map(e=>JSON.stringify(e)).join(`, `);throw Error(`${e} ${t} not found in source directory.\n`+q({source:i}))}let c=new Set(a);for(let e of i)c.has(e.frontmatter.name)&&J(e,o,t,n)}else if(i.length===0)U(r,t.sourceDir)?a.info(`No skills installed (source directory scan failed; see warnings).`):a.info(`No skills found in source directory.`);else for(let e of i)J(e,o,t,n)}return t.verbose.disabled?r({name:t.commandNames.add.name,...t.commandNames.add.aliases.length>0?{aliases:t.commandNames.add.aliases}:{},description:t.descriptions.add,args:n({name:e.stringArray(i)},{unknownKeys:t.unknownKeys}),run(e){o(e,G(e,`verbose`))}}):r({name:t.commandNames.add.name,...t.commandNames.add.aliases.length>0?{aliases:t.commandNames.add.aliases}:{},description:t.descriptions.add,args:n({name:e.stringArray(i),verbose:e.boolean(Te(t))},{unknownKeys:t.unknownKeys}),run(e){o(e,e.verbose)}})}function Oe(t){return r({name:t.commandNames.remove.name,...t.commandNames.remove.aliases.length>0?{aliases:t.commandNames.remove.aliases}:{},description:t.descriptions.remove,args:n({name:e.optionalString({positional:!0,description:`Skill name to remove (default: all)`,placeholder:`NAME`})},{unknownKeys:t.unknownKeys}),run(e){let n=W(t),r=n.skills,i=t.stamp;if(e.name){if(r.some(t=>t.frontmatter.name===e.name)&&Me(r,e.name),!Y(e.name,i,t.cwd,t.sourceDir)){if(K(e.name,t.cwd))a.info(`${e.name} is installed without a ${A} stamp this CLI recognises; refusing to remove. Remove .agents/skills/${e.name} manually if intended.`);else{let n=new Set(Ie(i,t.cwd,t.sourceDir));a.info(`${e.name} is not installed; nothing to remove.\n`+q({installed:n}))}}return}if(r.length===0){U(n,t.sourceDir)?a.info(`No skills found (source directory scan failed; see warnings); nothing to remove.`):a.info(`No skills found in source directory; nothing to remove.`);return}let o=0;for(let e of r)Y(e.frontmatter.name,i,t.cwd,t.sourceDir)&&(o+=1);o===0&&a.info(`No installed skills owned by this CLI; nothing to remove.`)}})}function ke(e,t,n,r){let i;try{i=L(e,n)}catch(t){return a.warn(`Failed to read ownership for installed skill ${e}: ${Ae(t)}`),`unreadable`}if(i===t)return`installed`;if(i!==null)return`foreign`;if(!I(e,n)){let t=C(n,O,e);return Z(t)&&X(t,r)?`missing`:K(e,n)?`unstamped`:`not-installed`}return`unstamped`}function Ae(e){return e instanceof Error?e.message:String(e)}function K(e,t){try{return c(C(t,O,e)),!0}catch{return!1}}function je(t){function i(e){let n=W(t,{silentStdout:e}),r=n.skills,i=t.stamp;if(e)console.log(JSON.stringify(r.map(e=>({name:e.frontmatter.name,description:e.frontmatter.description,owner:e.frontmatter.metadata?.[`politty-cli`]??null,expectedOwner:i,status:ke(e.frontmatter.name,i,t.cwd,t.sourceDir),sourcePath:e.sourcePath}))));else if(r.length===0)U(n,t.sourceDir)?a.info(`Source directory scan failed; see warnings.`):a.info(`No skills found in source directory.`);else{a.info(`Available skills:`);for(let e of r){let n=ke(e.frontmatter.name,i,t.cwd,t.sourceDir);a.info(` ${e.frontmatter.name.padEnd(20)} ${n.padEnd(14)} ${e.frontmatter.description}`)}}}return t.json.disabled?r({name:`list`,description:t.descriptions.list,args:n({},{unknownKeys:t.unknownKeys}),run(e){i(G(e,`json`))}}):r({name:`list`,description:t.descriptions.list,args:n({json:e.boolean({description:`Output as JSON`})},{unknownKeys:t.unknownKeys}),run(e){i(e.json)}})}function Me(e,t){let n=e.find(e=>e.frontmatter.name===t);if(!n){let n=e.map(e=>e.frontmatter.name).join(`, `)||`<none>`;throw Error(`Skill "${t}" not found in source directory. Available: ${n}`)}return n}function q(e){let t=[];return e.source!==void 0&&t.push(` Source: ${e.source.map(e=>e.frontmatter.name).join(`, `)||`<none>`}`),e.installed!==void 0&&t.push(` Installed: ${[...e.installed].sort().join(`, `)||`<none>`}`),t.join(`
|
|
2
|
-
`)}function J(e,t,n,r){let o=e.frontmatter.name,s=n.cwd,c=n.mode,l=e.frontmatter.metadata?.[`politty-cli`]??null;if(l!==t)throw Error(`Refusing to install "${o}": source SKILL.md declares metadata.${A}=${JSON.stringify(l)}, expected ${JSON.stringify(t)}.`);let u=L(o,s);if(u!==null&&u!==t)throw Error(`Refusing to install "${o}": owned by ${JSON.stringify(u)}, not ${JSON.stringify(t)}. Check metadata.${A} in .agents/skills/${o}/SKILL.md.`);let d=C(s,O,o),f=Z(d)&&X(d,n.sourceDir);if(u===null&&K(o,s)&&!f)throw Error(`Refusing to install "${o}": .agents/skills/${o} exists without a ${A} stamp, so it was not installed by this CLI. Remove it manually (or add the stamp to take ownership) before running "skills add".`);if(le(e,s,c===void 0?{}:{mode:c}),a.info(`${i.success} Installed ${o}`),r){let e=c??`symlink`;a.info(` mode=${e} path=${d}`)}}function Y(e,t,n,r){let o=L(e,n);if(o===null)return Ne(e,n,r)?(a.info(`${i.success} Removed ${e} (broken symlink)`),!0):!1;if(o!==t)throw Error(`Refusing to remove "${e}": owned by ${JSON.stringify(o)}, not ${JSON.stringify(t)}. Check metadata.${A} in .agents/skills/${e}/SKILL.md.`);return fe(e,n,{expectedOwnership:t}),a.info(`${i.success} Removed ${e}`),!0}function Ne(e,t,n){let r=C(t,O,e);if(!Z(r)||!X(r,n))return!1;for(let n of k){let i=C(t,n,e);Z(i)&&Fe(i,r)&&_(i)}return _(r),!0}function X(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n),i=Pe(C(t)),a=Pe(r),o=S(i,a);return!(b(o)||o===`..`||o.startsWith(`..${w}`))}function Pe(e){let t=e,n=[];for(;;)try{let e=m(t);return n.length===0?e:C(e,...n.reverse())}catch{let r=y(t);if(r===t)return e;n.push(t.slice(r.length).replace(/^[/\\]+/,``)),t=r}}function Fe(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n);if(r===t)return!0;try{return m(r)===m(t)}catch{return!1}}function Z(e){let t;try{t=c(e)}catch{return!1}return t.isSymbolicLink()?!s(e):!1}function Ie(e,t,n){let r=C(t,O),i=[],o;try{o=f(r,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`||t===`ENOTDIR`||a.warn(`Failed to enumerate ${r}: ${e instanceof Error?e.message:String(e)}`),i}for(let s of o){if(!s.isDirectory()&&!s.isSymbolicLink()||s.name.length<1||s.name.length>64||!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(s.name))continue;let o;try{o=L(s.name,t)}catch(e){a.warn(`Failed to read ownership for ${s.name}: ${e instanceof Error?e.message:String(e)}`);continue}if(o===e){i.push(s.name);continue}let c=C(r,s.name);o===null&&Z(c)&&X(c,n)&&i.push(s.name)}return i}const Le=[`add`,`install`],Re=[`remove`,`uninstall`],Q={skills:`Manage agent skills`,sync:`Remove and reinstall all skills from source`,add:`Install skills from source`,remove:`Remove installed skills`,list:`List available skills from source`},ze=/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/,Be=[`.git`,`package.json`];function Ve(e,t){return{sourceDir:e.sourceDir,package:e.package,mode:e.mode,cwd:Ue(e.cwd),excludeAlias:Ge(e.flags?.exclude?.alias),verbose:qe(e.flags?.verbose,e.globalArgs),json:{disabled:$(e.globalArgs,`json`)},commandNames:{add:Ke(e.commandMap?.add,Le,`add`),remove:Ke(e.commandMap?.remove,Re,`remove`)},unknownKeys:e.unknownKeys??`strip`,descriptionAppend:Je(e.descriptionAppend,t),stamp:`${e.package}:${t}`,descriptions:He(e.descriptions)}}function He(e){return{skills:e?.skills??Q.skills,sync:e?.sync??Q.sync,add:e?.add??Q.add,remove:e?.remove??Q.remove,list:e?.list??Q.list}}function Ue(e){if(e!==void 0)return C(e);let t=process.cwd();return We(t)??t}function We(e){let t=C(e);for(;;){for(let e of Be)if(s(C(t,e)))return t;let e=y(t);if(e===t)return null;t=e}}function Ge(e){if(e!==!1)return typeof e==`string`?e:`x`}function Ke(e,t,n){let r=e??t;if(r.length===0)throw Error(`SkillCommandOptions.commandMap.${n} must include at least one name.`);let i=r.find(e=>!ze.test(e));if(i!==void 0)throw Error(`SkillCommandOptions.commandMap.${n} contains an invalid entry ${JSON.stringify(i)}. Names/aliases must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores.`);return{name:r[0],aliases:r.slice(1)}}function qe(e,t){return{alias:e?.alias===!1?void 0:e?.alias??`v`,disabled:$(t,`verbose`)}}function $(e,
|
|
1
|
+
import"./register-BIQ84gFS.js";import{d as e,f as t,n}from"./schema-extractor-DL8vjWso.js";import{n as r}from"./command-BXsTrIgI.js";import{a as i,n as a}from"./logger-CoeDrmRr.js";import{copyFileSync as o,existsSync as s,lstatSync as c,mkdirSync as l,mkdtempSync as u,readFileSync as d,readdirSync as f,readlinkSync as p,realpathSync as m,renameSync as ee,rmSync as h,statSync as g,symlinkSync as te,unlinkSync as _}from"node:fs";import{basename as v,dirname as y,isAbsolute as b,join as x,parse as ne,relative as S,resolve as C,sep as w}from"node:path";import{z as T}from"zod";import{parse as re}from"yaml";const ie=/^[a-z0-9]+(-[a-z0-9]+)*$/;function E(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function ae(e){let t=[],n=(n,r)=>{let i=e[n];i===void 0?r.required&&t.push({path:[n],message:`Invalid input: expected string, received undefined`}):typeof i==`string`?(r.min!==void 0&&i.length<r.min&&t.push({path:[n],message:`Too small: expected string to have >=${r.min} characters`}),r.max!==void 0&&i.length>r.max&&t.push({path:[n],message:`Too big: expected string to have <=${r.max} characters`})):t.push({path:[n],message:`Invalid input: expected string, received ${E(i)}`})};n(`name`,{required:!0,min:1,max:64}),typeof e.name==`string`&&!ie.test(e.name)&&t.push({path:[`name`],message:`name must be lowercase alphanumerics separated by single hyphens`}),n(`description`,{required:!0,min:1,max:1024}),n(`license`,{min:1}),n(`compatibility`,{max:500}),n(`allowed-tools`,{});let r=e.metadata;if(r!==void 0){if(typeof r!=`object`||!r||Array.isArray(r))t.push({path:[`metadata`],message:`Invalid input: expected record, received ${E(r)}`});else for(let[e,n]of Object.entries(r))typeof n!=`string`&&t.push({path:[`metadata`,e],message:`Invalid input: expected string, received ${E(n)}`})}return t.length>0?{success:!1,issues:t}:{success:!0,data:{...e}}}const oe=/^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)([\s\S]*)$/;function D(e){let t=e.match(oe);if(!t)return{data:{},body:e};let n=t[1],r=t[2];try{let e=re(n);return se(e)?{data:e,body:r}:{data:{},body:r}}catch(e){return{data:{},body:r,parseError:e instanceof Error?e.message:String(e)}}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ce(e){let{data:t,body:n}=D(e),r=ae(t);return r.success?{frontmatter:r.data,body:n,rawContent:e}:null}const O=`.agents/skills`,k=[`.claude/skills`],A=`politty-cli`;function j(e){if(e.length<1||e.length>64||!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e))throw Error(`Invalid skill name: ${JSON.stringify(e)}`)}function le(e,t=process.cwd(),n={}){let r=e.frontmatter.name;j(r);let i=n.mode??`symlink`,a=e.frontmatter.metadata?.[`politty-cli`]??null;if(i===`copy`&&a===null)throw Error(`Refusing to install "${e.frontmatter.name}" in copy mode without an ownership stamp. Add metadata.${A}="{package}:{cli}" to the source SKILL.md so subsequent installs can replace the copy in place.`);let o=C(t,O),s=m(e.sourcePath),c=ue(e.sourcePath),u=[x(N(o),r),...k.map(e=>x(N(C(t,e)),r))].find(e=>ye(e,s));if(u!==void 0)throw Error(`Refusing to install "${r}": source ${s} overlaps install destination ${u}. Choose a sourceDir outside .agents/skills/ and any agent-specific slot directory (e.g. .claude/skills/).`);if(i===`symlink`){let e=N(o);M(x(e,r),S(e,c));for(let n of k){let i=N(C(t,n));M(x(i,r),x(S(i,e),r))}}l(o,{recursive:!0});let d=m(o),f=x(d,r);he(f,a),ge({linkTarget:S(d,c),linkPath:f,copyFrom:s,mode:i}),ve(t,r,f,a,i)}function M(e,t){if(b(t))throw Error(`Refusing to write an absolute symlink target at ${e} → ${t}. The skill source and install root appear to live on different filesystem roots (e.g. different Windows drive letters); retry with mode: "copy".`)}function ue(e){let t=C(e),{root:n}=ne(t),r=t.slice(n.length).split(w).filter(e=>e!==``),i=n;for(let[e,t]of r.entries()){let n=x(i,t),a;try{a=c(n)}catch{return x(i,...r.slice(e))}if(a.isSymbolicLink()){if(de(i))return x(i,...r.slice(e));i=m(n)}else i=n}return i}function de(e){return v(e)===`node_modules`||v(e).startsWith(`@`)&&v(y(e))===`node_modules`}function N(e){let t=e,n=[];for(;;)try{let e=m(t);return n.length===0?e:C(e,...n.reverse())}catch{let r=y(t);if(r===t)return e;n.push(t.slice(r.length).replace(/^[/\\]+/,``)),t=r}}function fe(e,t=process.cwd(),n={}){j(e);let r=n.expectedOwnership??null,i=C(t,O,e);for(let n of k)me(C(t,n,e),r,{restrictSymlinkTo:i});me(i,r)}function pe(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n);if(r===t)return!0;try{return m(r)===m(t)}catch{return!1}}function me(e,t,n={}){let r;try{r=c(e)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return;throw e}if(r.isSymbolicLink()){if(n.restrictSymlinkTo!==void 0){pe(e,n.restrictSymlinkTo)&&_(e);return}(t===null||F(e)===t)&&_(e)}else r.isDirectory()&&t!==null&&F(e)===t&&h(e,{recursive:!0,force:!0})}function he(e,t,n={}){let r;try{r=c(e)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return;throw e}if(r.isSymbolicLink()){if(n.restrictSymlinkTo===void 0||pe(e,n.restrictSymlinkTo)){_(e);return}throw Error(`Refusing to replace symlink at ${e}: it does not route to this CLI's canonical slot (${n.restrictSymlinkTo}). Remove or migrate the foreign symlink before retrying.`)}if(r.isDirectory()&&t!==null&&F(e)===t)h(e,{recursive:!0,force:!0});else throw Error(`Refusing to replace non-symlink path at ${e}. This looks like a legacy or manual install; remove or migrate it before retrying.`)}function ge(e){let{linkTarget:t,linkPath:n,copyFrom:r,mode:i}=e;if(i===`copy`)_e(r,n);else{M(n,t);try{te(t,n,`dir`)}catch(e){let r=e instanceof Error?e.message:String(e);throw Error(`Failed to symlink ${n} → ${t}: ${r}. If this filesystem does not support symlinks (e.g. Windows without Developer Mode), retry with mode: "copy".`,{cause:e})}}}function _e(e,t){let n=u(`${t}.partial-`);try{P(e,n),ee(n,t)}catch(e){try{h(n,{recursive:!0,force:!0})}catch{}throw e}}function P(e,t,n=/* @__PURE__ */ new Set){let r=g(e);if(r.isDirectory()){let r=m(e);if(n.has(r))throw Error(`Refusing to recursively copy cyclic directory symlink at ${e} (resolves to ${r}, already on the copy stack).`);n.add(r);try{l(t,{recursive:!0});for(let r of f(e))P(x(e,r),x(t,r),n)}finally{n.delete(r)}}else r.isFile()&&o(e,t)}function F(e){let t;try{t=d(x(e,`SKILL.md`),`utf-8`)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:n}=D(t),r=n.metadata;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r[A];return typeof i==`string`?i:null}function I(e,t=process.cwd()){return j(e),s(C(t,O,e,`SKILL.md`))}function L(e,t=process.cwd()){j(e);let n=C(t,O,e,`SKILL.md`),r;try{r=d(n,`utf-8`)}catch(e){if(R(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:i}=D(r),a=i.metadata;if(!a||typeof a!=`object`||Array.isArray(a))return null;let o=a[A];return typeof o==`string`?o:null}function ve(e,t,n,r,i){for(let a of k){let o=C(e,a);l(o,{recursive:!0});let s=m(o),c=x(s,t);he(c,r,{restrictSymlinkTo:n});let u=m(C(n,`..`));ge({linkTarget:x(S(s,u),t),linkPath:c,copyFrom:n,mode:i})}}function R(e){return e instanceof Error&&typeof e.code==`string`}function ye(e,t){if(e===t)return!0;let n=(e,t)=>{let n=S(t,e);return n===``||n===`.`||!b(n)&&n!==`..`&&!n.startsWith(`..${w}`)};return n(e,t)||n(t,e)}const z=`SKILL.md`;function B(e){let t=[],n=[];try{let r;try{r=g(e)}catch(r){return H(r)&&(r.code===`ENOENT`||r.code===`ENOTDIR`)?n.push({path:e,reason:`missing-source`,message:`Source directory does not exist: ${e}`}):n.push({path:e,reason:`read-failed`,message:`Failed to stat source directory ${e}: ${V(r)}`}),{skills:t,errors:n}}if(!r.isDirectory())return n.push({path:e,reason:`missing-source`,message:`Source path is not a directory: ${e}`}),{skills:t,errors:n};let i=x(e,z),a=Se(i);if(a.kind===`error`)return n.push({path:e,reason:`read-failed`,message:`Failed to check ${i}: ${a.message}`}),{skills:t,errors:n};if(a.kind===`present`)return xe(be(e,{enforceParentMatch:!1}),t,n),{skills:t,errors:n};let o=f(e,{withFileTypes:!0});for(let r of o){let i=x(e,r.name),a;try{a=g(i).isDirectory()}catch(e){if(H(e)&&e.code===`ENOENT`&&!r.isSymbolicLink())continue;n.push({path:i,reason:`read-failed`,message:r.isSymbolicLink()?`Dangling symlink at ${i}: ${V(e)}`:`Failed to stat ${i}: ${V(e)}`});continue}if(!a)continue;let o=x(i,z),s=Se(o);s.kind===`error`?n.push({path:i,reason:`read-failed`,message:`Failed to check ${o}: ${s.message}`}):s.kind!==`absent`&&xe(be(i,{enforceParentMatch:!0}),t,n)}}catch(t){n.push({path:e,reason:`read-failed`,message:`Failed to scan ${e}: ${V(t)}`})}return t.sort((e,t)=>e.frontmatter.name<t.frontmatter.name?-1:+(e.frontmatter.name>t.frontmatter.name)),{skills:t,errors:n}}function be(e,t){let n=x(e,z),r;try{r=d(n,`utf-8`)}catch(t){return{path:e,reason:`read-failed`,message:`Failed to read ${n}: ${V(t)}`}}let{data:i,parseError:a}=D(r);if(a!==void 0)return{path:e,reason:`parse-failed`,message:`Invalid SKILL.md frontmatter in ${e}: YAML parse error: ${a}`};let o=ae(i);if(!o.success)return{path:e,reason:`parse-failed`,message:`Invalid SKILL.md frontmatter in ${e}: ${o.issues.map(e=>`${e.path.join(`.`)||`<root>`}: ${e.message}`).join(`; `)}`};if(t.enforceParentMatch){let t=v(e);if(t!==o.data.name)return{path:e,reason:`name-mismatch`,message:`Skill name "${o.data.name}" does not match directory "${t}"`,skillName:o.data.name}}return{frontmatter:o.data,sourcePath:e,rawContent:r}}function xe(e,t,n){`frontmatter`in e?t.push(e):n.push(e)}function V(e){return e instanceof Error?e.message:String(e)}function H(e){return e instanceof Error&&typeof e.code==`string`}function Se(e){try{return c(e),{kind:`present`}}catch(e){return H(e)&&e.code===`ENOENT`?{kind:`absent`}:{kind:`error`,message:V(e)}}}function Ce(e,t={}){let n=0,r=!1;for(let i of e)i.reason===`missing-source`||i.path===t.sourceDir?(r=!0,a.warn(`Failed to scan source directory ${i.path}: ${i.message}`)):(n+=1,a.warn(`Skipping skill at ${i.path}: ${i.message}`));t.silentStdout||(n>0&&a.info(`${i.warning} Skipped ${n} skill(s) due to scan errors (see warnings above).`),r&&a.info(`${i.warning} Source directory scan failed (see warnings above); subsequent operations may be skipped.`))}function U(e,t){let n=e.errors.some(e=>e.reason===`missing-source`||e.path===t),r=e.errors.length>0&&e.skills.length===0;return n||r}function W(e,t={}){let n=B(e.sourceDir);return Ce(n.errors,{...t,sourceDir:e.sourceDir}),n}function we(e){let t={description:`Skill names to exclude from sync`};return e.excludeAlias!==void 0&&(t.alias=e.excludeAlias),t}function Te(e){let t={description:`Print install paths and modes`};return e.verbose.alias!==void 0&&(t.alias=e.verbose.alias),t}function G(e,t){return!!e[t]}function Ee(n){function i(e,t){let{skills:r,errors:i}=W(n),o=n.stamp,s=new Set(r.map(e=>e.frontmatter.name)),c=new Set(Ie(o,n.cwd,n.sourceDir)),l=Array.from(new Set(e.exclude)).filter(e=>!s.has(e)&&!c.has(e));if(l.length>0){let e=l.length===1?`Skill`:`Skills`,t=l.map(e=>JSON.stringify(e)).join(`, `);throw Error(`--exclude: ${e} ${t} not found in source directory or among installed skills.\n`+q({source:r,installed:c}))}let u=new Set(e.exclude),d=r.filter(e=>!u.has(e.frontmatter.name)),f=U({skills:r,errors:i},n.sourceDir),p=0;if(!f){let e=new Set(d.map(e=>e.frontmatter.name)),t=/* @__PURE__ */ new Set;for(let e of i)e.path!==n.sourceDir&&(t.add(v(e.path)),e.skillName!==void 0&&t.add(e.skillName));for(let r of c)e.has(r)||u.has(r)||t.has(r)||(Y(r,o,n.cwd,n.sourceDir),p+=1)}let m=0;for(let e of d)J(e,o,n,t),m+=1;if(m===0&&p===0){let e=f?`source directory scan failed; see warnings`:r.length>0&&d.length===0?`all skills excluded`:`no skills bundled`;a.info(`No skills installed (${e}).`)}else a.info(`Sync complete: ${m} installed, ${p} removed.`)}return n.verbose.disabled?r({name:`sync`,description:n.descriptions.sync,args:e({exclude:t.stringArray(we(n))},{unknownKeys:n.unknownKeys}),run(e){i(e,G(e,`verbose`))}}):r({name:`sync`,description:n.descriptions.sync,args:e({exclude:t.stringArray(we(n)),verbose:t.boolean(Te(n))},{unknownKeys:n.unknownKeys}),run(e){i(e,e.verbose)}})}function De(n){let i={positional:!0,description:`Skill name(s) to install (default: all)`,placeholder:`NAME`};function o(e,t){let r=W(n),i=r.skills,o=n.stamp;if(e.name.length>0){let r=new Set(i.map(e=>e.frontmatter.name)),a=Array.from(new Set(e.name)),s=a.filter(e=>!r.has(e));if(s.length>0){let e=s.length===1?`Skill`:`Skills`,t=s.map(e=>JSON.stringify(e)).join(`, `);throw Error(`${e} ${t} not found in source directory.\n`+q({source:i}))}let c=new Set(a);for(let e of i)c.has(e.frontmatter.name)&&J(e,o,n,t)}else if(i.length===0)U(r,n.sourceDir)?a.info(`No skills installed (source directory scan failed; see warnings).`):a.info(`No skills found in source directory.`);else for(let e of i)J(e,o,n,t)}return n.verbose.disabled?r({name:n.commandNames.add.name,...n.commandNames.add.aliases.length>0?{aliases:n.commandNames.add.aliases}:{},description:n.descriptions.add,args:e({name:t.stringArray(i)},{unknownKeys:n.unknownKeys}),run(e){o(e,G(e,`verbose`))}}):r({name:n.commandNames.add.name,...n.commandNames.add.aliases.length>0?{aliases:n.commandNames.add.aliases}:{},description:n.descriptions.add,args:e({name:t.stringArray(i),verbose:t.boolean(Te(n))},{unknownKeys:n.unknownKeys}),run(e){o(e,e.verbose)}})}function Oe(n){return r({name:n.commandNames.remove.name,...n.commandNames.remove.aliases.length>0?{aliases:n.commandNames.remove.aliases}:{},description:n.descriptions.remove,args:e({name:t.optionalString({positional:!0,description:`Skill name to remove (default: all)`,placeholder:`NAME`})},{unknownKeys:n.unknownKeys}),run(e){let t=W(n),r=t.skills,i=n.stamp;if(e.name){if(r.some(t=>t.frontmatter.name===e.name)&&Me(r,e.name),!Y(e.name,i,n.cwd,n.sourceDir)){if(K(e.name,n.cwd))a.info(`${e.name} is installed without a ${A} stamp this CLI recognises; refusing to remove. Remove .agents/skills/${e.name} manually if intended.`);else{let t=new Set(Ie(i,n.cwd,n.sourceDir));a.info(`${e.name} is not installed; nothing to remove.\n`+q({installed:t}))}}return}if(r.length===0){U(t,n.sourceDir)?a.info(`No skills found (source directory scan failed; see warnings); nothing to remove.`):a.info(`No skills found in source directory; nothing to remove.`);return}let o=0;for(let e of r)Y(e.frontmatter.name,i,n.cwd,n.sourceDir)&&(o+=1);o===0&&a.info(`No installed skills owned by this CLI; nothing to remove.`)}})}function ke(e,t,n,r){let i;try{i=L(e,n)}catch(t){return a.warn(`Failed to read ownership for installed skill ${e}: ${Ae(t)}`),`unreadable`}if(i===t)return`installed`;if(i!==null)return`foreign`;if(!I(e,n)){let t=C(n,O,e);return Z(t)&&X(t,r)?`missing`:K(e,n)?`unstamped`:`not-installed`}return`unstamped`}function Ae(e){return e instanceof Error?e.message:String(e)}function K(e,t){try{return c(C(t,O,e)),!0}catch{return!1}}function je(n){function i(e){let t=W(n,{silentStdout:e}),r=t.skills,i=n.stamp;if(e)console.log(JSON.stringify(r.map(e=>({name:e.frontmatter.name,description:e.frontmatter.description,owner:e.frontmatter.metadata?.[`politty-cli`]??null,expectedOwner:i,status:ke(e.frontmatter.name,i,n.cwd,n.sourceDir),sourcePath:e.sourcePath}))));else if(r.length===0)U(t,n.sourceDir)?a.info(`Source directory scan failed; see warnings.`):a.info(`No skills found in source directory.`);else{a.info(`Available skills:`);for(let e of r){let t=ke(e.frontmatter.name,i,n.cwd,n.sourceDir);a.info(` ${e.frontmatter.name.padEnd(20)} ${t.padEnd(14)} ${e.frontmatter.description}`)}}}return n.json.disabled?r({name:`list`,description:n.descriptions.list,args:e({},{unknownKeys:n.unknownKeys}),run(e){i(G(e,`json`))}}):r({name:`list`,description:n.descriptions.list,args:e({json:t.boolean({description:`Output as JSON`})},{unknownKeys:n.unknownKeys}),run(e){i(e.json)}})}function Me(e,t){let n=e.find(e=>e.frontmatter.name===t);if(!n){let n=e.map(e=>e.frontmatter.name).join(`, `)||`<none>`;throw Error(`Skill "${t}" not found in source directory. Available: ${n}`)}return n}function q(e){let t=[];return e.source!==void 0&&t.push(` Source: ${e.source.map(e=>e.frontmatter.name).join(`, `)||`<none>`}`),e.installed!==void 0&&t.push(` Installed: ${[...e.installed].sort().join(`, `)||`<none>`}`),t.join(`
|
|
2
|
+
`)}function J(e,t,n,r){let o=e.frontmatter.name,s=n.cwd,c=n.mode,l=e.frontmatter.metadata?.[`politty-cli`]??null;if(l!==t)throw Error(`Refusing to install "${o}": source SKILL.md declares metadata.${A}=${JSON.stringify(l)}, expected ${JSON.stringify(t)}.`);let u=L(o,s);if(u!==null&&u!==t)throw Error(`Refusing to install "${o}": owned by ${JSON.stringify(u)}, not ${JSON.stringify(t)}. Check metadata.${A} in .agents/skills/${o}/SKILL.md.`);let d=C(s,O,o),f=Z(d)&&X(d,n.sourceDir);if(u===null&&K(o,s)&&!f)throw Error(`Refusing to install "${o}": .agents/skills/${o} exists without a ${A} stamp, so it was not installed by this CLI. Remove it manually (or add the stamp to take ownership) before running "skills add".`);if(le(e,s,c===void 0?{}:{mode:c}),a.info(`${i.success} Installed ${o}`),r){let e=c??`symlink`;a.info(` mode=${e} path=${d}`)}}function Y(e,t,n,r){let o=L(e,n);if(o===null)return Ne(e,n,r)?(a.info(`${i.success} Removed ${e} (broken symlink)`),!0):!1;if(o!==t)throw Error(`Refusing to remove "${e}": owned by ${JSON.stringify(o)}, not ${JSON.stringify(t)}. Check metadata.${A} in .agents/skills/${e}/SKILL.md.`);return fe(e,n,{expectedOwnership:t}),a.info(`${i.success} Removed ${e}`),!0}function Ne(e,t,n){let r=C(t,O,e);if(!Z(r)||!X(r,n))return!1;for(let n of k){let i=C(t,n,e);Z(i)&&Fe(i,r)&&_(i)}return _(r),!0}function X(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n),i=Pe(C(t)),a=Pe(r),o=S(i,a);return!(b(o)||o===`..`||o.startsWith(`..${w}`))}function Pe(e){let t=e,n=[];for(;;)try{let e=m(t);return n.length===0?e:C(e,...n.reverse())}catch{let r=y(t);if(r===t)return e;n.push(t.slice(r.length).replace(/^[/\\]+/,``)),t=r}}function Fe(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n);if(r===t)return!0;try{return m(r)===m(t)}catch{return!1}}function Z(e){let t;try{t=c(e)}catch{return!1}return t.isSymbolicLink()?!s(e):!1}function Ie(e,t,n){let r=C(t,O),i=[],o;try{o=f(r,{withFileTypes:!0})}catch(e){let t=e.code;return t===`ENOENT`||t===`ENOTDIR`||a.warn(`Failed to enumerate ${r}: ${e instanceof Error?e.message:String(e)}`),i}for(let s of o){if(!s.isDirectory()&&!s.isSymbolicLink()||s.name.length<1||s.name.length>64||!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(s.name))continue;let o;try{o=L(s.name,t)}catch(e){a.warn(`Failed to read ownership for ${s.name}: ${e instanceof Error?e.message:String(e)}`);continue}if(o===e){i.push(s.name);continue}let c=C(r,s.name);o===null&&Z(c)&&X(c,n)&&i.push(s.name)}return i}const Le=[`add`,`install`],Re=[`remove`,`uninstall`],Q={skills:`Manage agent skills`,sync:`Remove and reinstall all skills from source`,add:`Install skills from source`,remove:`Remove installed skills`,list:`List available skills from source`},ze=/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/,Be=[`.git`,`package.json`];function Ve(e,t){return{sourceDir:e.sourceDir,package:e.package,mode:e.mode,cwd:Ue(e.cwd),excludeAlias:Ge(e.flags?.exclude?.alias),verbose:qe(e.flags?.verbose,e.globalArgs),json:{disabled:$(e.globalArgs,`json`)},commandNames:{add:Ke(e.commandMap?.add,Le,`add`),remove:Ke(e.commandMap?.remove,Re,`remove`)},unknownKeys:e.unknownKeys??`strip`,descriptionAppend:Je(e.descriptionAppend,t),stamp:`${e.package}:${t}`,descriptions:He(e.descriptions)}}function He(e){return{skills:e?.skills??Q.skills,sync:e?.sync??Q.sync,add:e?.add??Q.add,remove:e?.remove??Q.remove,list:e?.list??Q.list}}function Ue(e){if(e!==void 0)return C(e);let t=process.cwd();return We(t)??t}function We(e){let t=C(e);for(;;){for(let e of Be)if(s(C(t,e)))return t;let e=y(t);if(e===t)return null;t=e}}function Ge(e){if(e!==!1)return typeof e==`string`?e:`x`}function Ke(e,t,n){let r=e??t;if(r.length===0)throw Error(`SkillCommandOptions.commandMap.${n} must include at least one name.`);let i=r.find(e=>!ze.test(e));if(i!==void 0)throw Error(`SkillCommandOptions.commandMap.${n} contains an invalid entry ${JSON.stringify(i)}. Names/aliases must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores.`);return{name:r[0],aliases:r.slice(1)}}function qe(e,t){return{alias:e?.alias===!1?void 0:e?.alias??`v`,disabled:$(t,`verbose`)}}function $(e,t){return e?n(e).fields.some(e=>e.name===t&&e.named&&e.type===`boolean`):!1}function Je(e,t){return e===!1?!1:typeof e==`string`?e:`Manage agent skills with \`${t} skills <add|sync|remove|list>\`.`}const Ye=[`parse-failed`,`name-mismatch`,`read-failed`,`missing-source`];function Xe(e,t){if(e.subCommands&&Object.hasOwn(e.subCommands,`skills`))throw Error(`withSkillCommand: command "${e.name}" already defines a "skills" subcommand.`);let n=Ve(t,e.name),i=n.commandNames.add.name,a=n.commandNames.remove.name,o=[`sync`,`list`,i,...n.commandNames.add.aliases,a,...n.commandNames.remove.aliases],s=o.find((e,t)=>o.indexOf(e)!==t);if(s)throw Error(`withSkillCommand: commandMap produced duplicate subcommand name/alias "${s}".`);let c=r({name:`skills`,description:n.descriptions.skills,subCommands:{sync:Ee(n),[i]:De(n),[a]:Oe(n),list:je(n)}});return{...e,description:Ze(e.description,n.descriptionAppend),subCommands:{...e.subCommands,skills:c}}}function Ze(e,t){return t===!1||t===``?e:e?e.endsWith(t)?e:`${e}\n\n${t}`:t}const Qe=T.object({name:T.string().min(1).max(64).regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,{message:`name must be lowercase alphanumerics separated by single hyphens`}),description:T.string().min(1).max(1024),license:T.string().min(1).optional(),compatibility:T.string().max(500).optional(),metadata:T.record(T.string(),T.string()).optional(),"allowed-tools":T.string().optional()}).passthrough();export{A as OWNERSHIP_METADATA_KEY,Ye as SCAN_ERROR_REASONS,I as hasInstalledSkill,le as installSkill,D as parseFrontmatter,ce as parseSkillMd,L as readInstalledOwnership,B as scanSourceDir,Qe as skillFrontmatterSchema,fe as uninstallSkill,Xe as withSkillCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let e;function t(t){e=t}function n(){if(!e)throw Error('No validator adapter registered. Import politty through an adapter package (e.g. `import { defineCommand } from "@politty/zod"` or `from "politty"`) so the schema library integration is set up.');return e}const r=/* @__PURE__ */ new Set([`help`,`help-all`,`help-json`,`version`]);function i(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function a(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function o(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function s(e,t){let n=t.argMeta,a=n?.description??t.description,o=i(e),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(t,n)=>{if(t==null)return;let r=(Array.isArray(t)?t:[t]).map(t=>{if(typeof t!=`string`)throw Error(`Invalid ${n} for field "${e}": expected string or string[], received ${typeof t}.`);let r=t.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${n} "${t}" for field "${e}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(n?.alias,`alias`),u=new Set(l??[]),d=c(n?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=t.type,m=n?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${e}": expected string or boolean, received ${typeof m}.`);let t=m.trim().replace(/^-+/,``);if(t.length===0||!s.test(t))throw Error(`Invalid negation "${m}" for field "${e}": negation names must match ${s}.`);if(r.has(t))throw Error(`Invalid negation "${m}" for field "${e}": negation cannot use reserved built-in flag names (${[...r].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=t}}let g=n?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${e}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${e}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${e}": negationDescription requires \`negation\` to be set (string or true).`);let t=g.trim();if(t.length===0)throw Error(`Invalid negationDescription for field "${e}": negationDescription must be a non-empty string.`);_=t}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y=n?.positional,b={name:e,cliName:o,alias:l,hiddenAlias:f,description:a,positional:y!==void 0&&y!==!1,named:typeof y==`object`?y.named===!0:y!==!0,placeholder:n?.placeholder,env:n?.env,required:t.required,defaultValue:t.defaultValue,type:p,schema:t.schema,enumValues:t.enumValues,completion:n?.completion,prompt:n?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:n?.effect,requiredPackages:n?.requiredPackages};return n&&`overrideBuiltinAlias`in n&&n.overrideBuiltinAlias===!0&&(b.overrideBuiltinAlias=!0),b}
|
|
1
|
+
let e;function t(t){e=t}function n(){if(!e)throw Error('No validator adapter registered. Import politty through an adapter package (e.g. `import { defineCommand } from "@politty/zod"` or `from "politty"`) so the schema library integration is set up.');return e}const r=/* @__PURE__ */ new Set([`help`,`help-all`,`help-json`,`version`]);function i(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function a(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function o(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function s(e,t){let n=t.argMeta,a=n?.description??t.description,o=i(e),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(t,n)=>{if(t==null)return;let r=(Array.isArray(t)?t:[t]).map(t=>{if(typeof t!=`string`)throw Error(`Invalid ${n} for field "${e}": expected string or string[], received ${typeof t}.`);let r=t.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${n} "${t}" for field "${e}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(n?.alias,`alias`),u=new Set(l??[]),d=c(n?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=t.type,m=n?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${e}": expected string or boolean, received ${typeof m}.`);let t=m.trim().replace(/^-+/,``);if(t.length===0||!s.test(t))throw Error(`Invalid negation "${m}" for field "${e}": negation names must match ${s}.`);if(r.has(t))throw Error(`Invalid negation "${m}" for field "${e}": negation cannot use reserved built-in flag names (${[...r].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=t}}let g=n?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${e}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${e}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${e}": negationDescription requires \`negation\` to be set (string or true).`);let t=g.trim();if(t.length===0)throw Error(`Invalid negationDescription for field "${e}": negationDescription must be a non-empty string.`);_=t}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y=n?.positional,b={name:e,cliName:o,alias:l,hiddenAlias:f,description:a,positional:y!==void 0&&y!==!1,named:typeof y==`object`?y.named===!0:y!==!0,placeholder:n?.placeholder,env:n?.env,required:t.required,defaultValue:t.defaultValue,type:p,schema:t.schema,enumValues:t.enumValues,completion:n?.completion,prompt:n?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:n?.effect,requiredPackages:n?.requiredPackages};return n&&`overrideBuiltinAlias`in n&&n.overrideBuiltinAlias===!0&&(b.overrideBuiltinAlias=!0),b}function c(e,t,n){if(e.length<=n.length||!e.startsWith(n))return;if(t===`kebab`)return e[n.length]===`-`?e.slice(n.length+1):void 0;let r=e[n.length];return r===r.toLowerCase()?void 0:r.toLowerCase()+e.slice(n.length+1)}function l(e,t,n){if(t===`dot`){let t=e.indexOf(`.`);return t<0?void 0:[e.slice(0,t),e.slice(t+1)]}let r;for(let i of n)c(e,t,i)!==void 0&&(r===void 0||i.length<r.length)&&(r=i);return r===void 0?void 0:[r,c(e,t,r)]}function u(e,t,n){if(t===`dot`)return e.split(`.`);let r=[],i=e;for(let e=l(i,t,n);e;e=l(i,t,n)){let a=e[0];r.push(a),i=e[1],n=n.flatMap(e=>c(e,t,a)??[])}return r.push(i),r}function d(e={}){let t=e.style??`dot`,n=`prefixes`in e?e.prefixes:[];return e=>u(e,t,n)}function f(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}function p(e,t){let n={},r=/* @__PURE__ */ new Set,i=(e,t)=>({issues:[{message:`Cannot unflatten "${e}": "${t}" is both a value and a group`,path:[e]}]});for(let a of Object.keys(e)){let o=t(a),s=o.length-1,c=n;for(let e=0;e<s;e++){let t=o[e];if(Object.hasOwn(c,t)){let e=c[t];if(!r.has(e))return i(a,t);c=e}else{let e={};r.add(e),f(c,t,e),c=e}}let l=o[s];if(Object.hasOwn(c,l))return i(a,l);f(c,l,e[a])}return{value:n}}function m(e,t={}){let n=d(t),r=p(Object.fromEntries(e.map(e=>[e,void 0])),n);if(r.issues)throw TypeError(r.issues[0].message);let a=/* @__PURE__ */ new Map;for(let t of e){let e=n(t)[0],r=i(e),o=a.get(r);if(o!==void 0&&o!==e)throw TypeError(`Cannot unflatten "${t}": "${o}" and "${e}" are spellings of the same name. Spell the name the same way in every key.`);a.set(r,e)}}const h=/* @__PURE__ */ new WeakMap;function g(e,t={}){return h.set(e,t),e}function _(e){return h.get(e)}function v(e){if(h.has(e))throw Error(`An unflatten schema cannot be an option of a union: unflatten wraps one object schema, so the union cannot tell which option's groups its output nests. Unflatten the object that holds the union instead, or use a plain object for the option.`)}function y(e,t){if(!t.nested)return e[t.name];let n=e;for(let e of t.nested.path)n=typeof n==`object`&&n&&Object.hasOwn(n,e)?n[e]:void 0;return n}function b(e,t,n,r){let i=x(r),a=new Set([...x(n)].filter(e=>i.has(e))),o=(e,t,n)=>{let r={...e,...t};for(let i of Object.keys(t)){let s=[...n,i],c=Object.hasOwn(e,i)?e[i]:void 0,l=t[i];a.has(s.join(`\0`))&&S(c)&&S(l)&&f(r,i,o(c,l,s))}return r};return o(e,t,[])}function x(e){let t=/* @__PURE__ */ new Set;for(let{nested:n}of e){let e=n?.path??[];for(let n=1;n<e.length;n++)t.add(e.slice(0,n).join(`\0`))}return t}function S(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}export{d as a,p as c,s as d,a as f,t as h,b as i,r as l,n as m,y as n,g as o,i as p,_ as r,v as s,m as t,o as u};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{d as e,
|
|
1
|
+
import{d as e,f as t}from"./schema-extractor-DL8vjWso.js";import{n}from"./command-BXsTrIgI.js";import{s as r}from"./subcommand-router-40vA6Mka.js";import{t as i}from"./schema-C2QqQGOQ.js";import{existsSync as a,readFileSync as o}from"node:fs";import{join as s}from"node:path";import{spawn as c}from"node:child_process";function l(){let e=(process.env.SHELL||``).split(`/`).pop()?.toLowerCase()||``;return e.includes(`bash`)?`bash`:e.includes(`zsh`)?`zsh`:e.includes(`fish`)?`fish`:null}function u(e){return`${process.env.XDG_CACHE_HOME??`${process.env.HOME??``}/.cache`}/${e}`}function d(e,t,n){if(t===`fish`){let t=process.env.XDG_CONFIG_HOME??`${process.env.HOME??``}/.config`;return s(t,`fish`,`completions`,`${e}.fish`)}let r=n??u(e);return s(r,`completion.${t}`)}function f(e){try{if(!a(e))return null;let t=o(e,`utf8`).split(`
|
|
2
2
|
`,6).join(`
|
|
3
|
-
`).match(/^# politty-bin-sig: (\S+)/m);return t?t[1]:null}catch{return null}}function p(e,t){return f(d(e.programName,t,e.cacheDir))!==null}function m(e,t){try{c(process.execPath,[e,`__refresh-completion`,t],{detached:!0,stdio:`ignore`}).unref()}catch{}}const h=
|
|
3
|
+
`).match(/^# politty-bin-sig: (\S+)/m);return t?t[1]:null}catch{return null}}function p(e,t){return f(d(e.programName,t,e.cacheDir))!==null}function m(e,t){try{c(process.execPath,[e,`__refresh-completion`,t],{detached:!0,stdio:`ignore`}).unref()}catch{}}const h=e({shell:t.optionalEnum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell type (bash, zsh, or fish)`,placeholder:`SHELL`}),instructions:t.boolean({alias:`i`,description:`Show installation instructions`}),loader:t.boolean({description:`Print just the rc loader snippet (bash/zsh). Add it to ~/.bashrc or ~/.zshrc; it auto-regenerates the cache when the binary changes.`}),install:t.boolean({description:`Write the completion script to its on-disk cache (bash/zsh) or autoload location (fish) instead of printing it.`}),static:t.boolean({description:`Generate the legacy static completion script with command metadata baked in.`}),dispatcher:t.boolean({description:`Generate the runtime dispatcher completion script. This is the default.`}),worker:t.boolean({description:`Generate an internal static worker artifact for dispatcher mode.`})}),g=e({shell:t.enum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell to refresh`,placeholder:`SHELL`}),target:t.optionalString({positional:!0,description:`Existing politty-generated completion file to refresh`,placeholder:`TARGET`}),static:t.boolean({description:`Refresh using the legacy static completion script mode.`}),worker:t.boolean({description:`Refresh an internal static worker completion script.`})}),_=e({shell:t.enum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell worker to locate`,placeholder:`SHELL`})});function v(e,t){let{programName:a,globalArgsSchema:o,cacheDir:s,programVersion:c,bundledWorker:l}=typeof t==`string`?{programName:t}:t??{},u=a??e.name,d={...s!==void 0&&{cacheDir:s},...c!==void 0&&{programVersion:c},...o!==void 0&&{globalArgsSchema:o},...l!==void 0&&{bundledWorker:l}},f={...e};return f.subCommands={...e.subCommands,completion:r(n({name:`completion`,description:`Generate shell completion script`,args:h,run(){}}),()=>import(`./completion-B9wrL5rH.js`).then(e=>e.createCompletionCommand(f,a,o,d))),__complete:r(n({name:`__complete`,args:i,run(){}}),()=>import(`./dynamic-CxhC0uOL.js`).then(e=>e.createDynamicCompleteCommand(f,a,o))),"__refresh-completion":r(n({name:`__refresh-completion`,description:`(internal) Refresh the on-disk completion cache if stale.`,args:g,run(){}}),()=>import(`./completion-B9wrL5rH.js`).then(e=>e.createRefreshCompletionCommand(f,u,d))),"__completion-worker-path":r(n({name:`__completion-worker-path`,description:`(internal) Print the bundled completion worker path when available.`,args:_,run(){}}),()=>import(`./completion-B9wrL5rH.js`).then(e=>e.createCompletionWorkerPathCommand(u,d)))},f.runMainHook=e=>{y(e,{programName:u,...s!==void 0&&{cacheDir:s}})},f}function y(e,t){if(process.env.POLITTY_NO_COMPLETION_REFRESH)return;let n=e.find(e=>!e.startsWith(`-`));if(n===`__complete`||n===`__refresh-completion`||n===`__completion-worker-path`||n===`completion`)return;let r=l();if(!r)return;let i=process.argv[1];i&&p(t,r)&&m(i,r)}export{d as a,_ as i,h as n,f as o,g as r,l as s,v as t};
|
package/dist/{with-completion-command-Cwt9fmEm.d.ts → with-completion-command-M2RHrGAp.d.ts}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region ../core/src/adapter/internal-args.d.ts
|
|
1
|
+
import { C as AnyCommand, T as ArgsSchema, h as ResolvedExpandCandidate, it as UnknownKeysMode, n as ArgMeta, y as DynamicCompletionResolver } from "./arg-registry-SvIkYiSr.js";
|
|
3
2
|
/** Runtime brand distinguishing internal descriptors from library schemas. */
|
|
4
3
|
declare const INTERNAL_ARGS_BRAND = "__polittyInternalArgs";
|
|
5
4
|
type InternalFieldKind = "string" | "boolean" | "enum" | "string-array";
|
|
@@ -37,8 +36,6 @@ type InternalArgsSchema<TOut extends Record<string, unknown> = Record<string, un
|
|
|
37
36
|
type InferInternalArgs<S> = S extends {
|
|
38
37
|
readonly __out?: infer TOut;
|
|
39
38
|
} ? NonNullable<TOut> : never;
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region ../core/src/completion/types.d.ts
|
|
42
39
|
/**
|
|
43
40
|
* A single resolved entry in an "expand" lookup table.
|
|
44
41
|
*
|
|
@@ -305,8 +302,6 @@ interface CompletionResult {
|
|
|
305
302
|
* Generator function type for shell completions
|
|
306
303
|
*/
|
|
307
304
|
type CompletionGenerator = (command: AnyCommand, options: CompletionOptions) => CompletionResult;
|
|
308
|
-
//#endregion
|
|
309
|
-
//#region ../core/src/completion/bundled-worker.d.ts
|
|
310
305
|
interface GenerateBundledCompletionWorkerOptions {
|
|
311
306
|
/** CLI binary or built JS entry file to invoke. */
|
|
312
307
|
bin: string;
|
|
@@ -337,8 +332,6 @@ declare function bundledWorkerShellExtension(shell: ShellType): string;
|
|
|
337
332
|
declare function defaultBundledWorkerOutputPath(shell: ShellType): string;
|
|
338
333
|
declare function validateBundledWorkerFile(path: string, programName: string, shell: ShellType): void;
|
|
339
334
|
declare function generateBundledCompletionWorker(options: GenerateBundledCompletionWorkerOptions): Promise<GenerateBundledCompletionWorkerResult>;
|
|
340
|
-
//#endregion
|
|
341
|
-
//#region ../core/src/completion/with-completion-command.d.ts
|
|
342
335
|
/**
|
|
343
336
|
* Options for withCompletionCommand
|
|
344
337
|
*/
|
|
@@ -380,5 +373,4 @@ interface WithCompletionOptions {
|
|
|
380
373
|
* ```
|
|
381
374
|
*/
|
|
382
375
|
declare function withCompletionCommand<T extends AnyCommand>(command: T, options?: string | WithCompletionOptions): T;
|
|
383
|
-
//#endregion
|
|
384
376
|
export { CompletionResult as _, bundledWorkerShellExtension as a, InferInternalArgs as b, validateBundledWorkerFile as c, CompletablePositional as d, CompletableSubcommand as f, CompletionOptions as g, CompletionMode as h, GenerateBundledCompletionWorkerResult as i, BundledWorkerOptions as l, CompletionGenerator as m, withCompletionCommand as n, defaultBundledWorkerOutputPath as o, CompletionData as p, GenerateBundledCompletionWorkerOptions as r, generateBundledCompletionWorker as s, WithCompletionOptions as t, CompletableOption as u, ShellType as v, InternalArgsSchema as x, ValueCompletion as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@politty/zod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A lightweight CLI framework inspired by citty with zod v4 registry integration for type-safe metadata management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"argument-parser",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@politty/core": "0.1.0",
|
|
82
|
-
"@types/node": "
|
|
82
|
+
"@types/node": "26.6.5",
|
|
83
83
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
84
84
|
"tsdown": "0.23.1",
|
|
85
85
|
"typescript": "7.0.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e,n as t}from"./field-meta-CEtC5Mir.js";const n=/* @__PURE__ */ new Set([`1`,`t`,`T`,`TRUE`,`true`,`True`]),r=/* @__PURE__ */ new Set([`0`,`f`,`F`,`FALSE`,`false`,`False`]);function i(e){return n.has(e)?!0:!r.has(e)&&e}function a(e,t){return t===`boolean`?i(e):e}function o(e){let t=e.indexOf(`=`);return t>=0?e.slice(2,t):e.slice(2)}function s(e,t){let n=o(e);if(!e.includes(`=`)){let e=t.negationMap.get(n);if(e&&t.booleanFlags.has(e))return{resolvedName:e,withoutDashes:n,isNegated:!0,isCustomNegation:!0,isSuppressedNegation:!1}}let r=e.includes(`=`);if(!r&&n.startsWith(`no-`)){let e=n.slice(3);if(e===e.toLowerCase()){let r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}}if(!r&&n.length>2&&n.startsWith(`no`)&&/[A-Z]/.test(n[2])){let e=n[2].toLowerCase()+n.slice(3),r=t.aliasMap.get(e)??e;if(t.booleanFlags.has(r)){let e=t.aliasMap.get(n)??n;if(!t.definedNames.has(e))return t.defaultNegationDisabledFields.has(r)?{resolvedName:r,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!0}:{resolvedName:r,withoutDashes:n,isNegated:!0,isCustomNegation:!1,isSuppressedNegation:!1}}}return{resolvedName:t.aliasMap.get(n)??n,withoutDashes:n,isNegated:!1,isCustomNegation:!1,isSuppressedNegation:!1}}const c=/^-\.?\d/;function l(e){return!e.startsWith(`-`)||c.test(e)}function u(e){return e.startsWith(`-`)&&!e.startsWith(`--`)&&e.length>2&&!e.includes(`=`)}function d(e,t){let n=Array.from(e),r=n.findIndex(t);if(r===-1)return{flags:n,valueOption:void 0};let i=n.slice(r+1).join(``);return{flags:n.slice(0,r),valueOption:{name:n[r],value:i===``?void 0:i}}}function f(e,t={}){let{aliasMap:n=/* @__PURE__ */ new Map,booleanFlags:r=/* @__PURE__ */ new Set,arrayFlags:a=/* @__PURE__ */ new Set,valueFlags:o=/* @__PURE__ */ new Set,definedNames:c=/* @__PURE__ */ new Set,negationMap:u=/* @__PURE__ */ new Map,defaultNegationDisabledFields:f,unknownFlagsTakeNoValue:p=!1}=t,m=f??new Set(r),h=e=>r.has(e)||p&&!c.has(e),g={aliasMap:n,booleanFlags:r,definedNames:c,negationMap:u,defaultNegationDisabledFields:m},_={options:{},positionals:[],rest:[]},v=0,y=!1,b=(e,t)=>{let r=n.get(e)??e;if(a.has(r)){let e=_.options[r];Array.isArray(e)?e.push(t):e===void 0?_.options[r]=[t]:_.options[r]=[e,t]}else _.options[r]=t},x=t=>{let n=e[v+1];n!==void 0&&l(n)?(b(t,n),v+=2):(b(t,!0),v++)};for(;v<e.length;){let t=e[v];if(y)_.rest.push(t),v++;else if(t===`--`)y=!0,v++;else if(t.startsWith(`--`)){let e=t.slice(2),a=s(t,g);if(a.isSuppressedNegation){b(a.withoutDashes,!0),v++;continue}if(a.isNegated){b(a.resolvedName,!1),v++;continue}let o=e.indexOf(`=`);if(o!==-1){let t=e.slice(0,o),a=e.slice(o+1),s=n.get(t)??t;b(t,r.has(s)?i(a):a),v++}else{let t=e;h(n.get(t)??t)?(b(t,!0),v++):x(t)}}else if(t.startsWith(`-`)&&t.length>1&&!t.startsWith(`--`)){let e=t.slice(1),a=e.indexOf(`=`);if(a!==-1){let t=e.slice(0,a),o=e.slice(a+1),s=n.get(t)??t;b(t,r.has(s)?i(o):o),v++}else if(e.length===1){let t=e;h(n.get(t)??t)?(b(t,!0),v++):x(t)}else{let{flags:t,valueOption:r}=d(e,e=>o.has(n.get(e)??e));for(let e of t)b(e,!0);r?r.value===void 0?x(r.name):(b(r.name,r.value),v++):v++}}else _.positionals.push(t),v++}return _}function p(n){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Set;for(let e of n.fields)s.add(e.name);for(let u of n.fields){if(!u.named)continue;u.cliName!==u.name&&r.set(u.cliName,u.name);for(let n of t(u))if(r.set(n,u.name),n.length>1&&n.includes(`-`)){let t=e(n);t!==n&&!s.has(t)&&!r.has(t)&&r.set(t,u.name)}let n=e(u.name);if(n!==u.name&&!s.has(n)&&!r.has(n)&&r.set(n,u.name),u.type===`boolean`?i.add(u.name):o.add(u.name),u.type===`array`&&a.add(u.name),u.type===`boolean`&&u.negation!==!0&&(l.add(u.name),typeof u.negation==`string`&&(c.set(u.negation,u.name),u.negation.includes(`-`)))){let t=e(u.negation);t!==u.negation&&c.set(t,u.name)}}return{aliasMap:r,booleanFlags:i,arrayFlags:a,valueFlags:o,definedNames:s,negationMap:c,defaultNegationDisabledFields:l}}function m(e,t){return e.fields.filter(e=>e.positional&&!(e.named&&Object.hasOwn(t,e.name)))}function h(e,t){let n={...e.options},r=t.fields.filter(e=>e.positional),i=e.rest.length>0?[...e.positionals,...e.rest]:e.positionals;for(let e of r)e.named||delete n[e.name];let a=0;for(let r of m(t,e.options)){if(a>=i.length)break;if(r.type===`array`){n[r.name]=i.slice(a);break}n[r.name]=i[a],a++}return n}export{f as a,o as c,a as d,h as i,s as l,l as n,m as o,u as r,d as s,p as t,i as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as runPolittyCli}from"./cli-main-DblimvdD.js";
|
package/dist/cli-run-Aso3lU0I.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./register-w1jLVF3B.js";const{runPolittyCli:e}=await import(`./cli-main-CykIbGzU.js`);await e(`@politty/zod`);export{};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./with-completion-command-CI1rxHay.js";import"./dynamic-DvdL7L96.js";export{t as createCompletionCommand,n as createCompletionWorkerPathCommand,r as createRefreshCompletionCommand,c as generateBundledCompletionWorker}from"./completion-NbQ2jmWx.js";
|
package/dist/dynamic-BEW8hYW1.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as createDynamicCompleteCommand}from"./dynamic-DvdL7L96.js";
|
package/dist/prompt-Bs_O6SmK.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{l as e}from"./schema-extractor-lB6-WHOF.js";function t(e){let t=e.prompt;if(!t||t.enabled===!1)return null;let n=t.message??e.description??e.name,a=r(e,t),o=i(e,t,a);return{field:e,type:a===`select`&&!o?`text`:a,message:n,...o&&{choices:o}}}function n(e){return e!==void 0&&e.length>0}function r(e,t){return t.type?t.type===`file`||t.type===`directory`?`text`:t.type:n(t.choices)?`select`:e.completion?.type===`file`||e.completion?.type===`directory`?`text`:n(e.enumValues)?`select`:e.type===`boolean`?`confirm`:`text`}function i(e,t,r){if(n(t.choices))return t.choices.map(e=>typeof e==`string`?{label:e,value:e}:e);if(r===`select`&&n(e.enumValues))return e.enumValues.map(e=>({label:e,value:e}))}function a(e,n){let r=[];for(let i of e){if(n[i.name]!==void 0||i.type===`array`)continue;let e=t(i);e&&r.push(e)}return r}function o(){return!(!process.stdin.isTTY||!process.stdout.isTTY||process.env.CI||process.env.POLITTY_NO_PROMPT)}async function s(e,t,n){if(!(n.interactive??o()))return e;let r=n.adapter,i={...e};return t.schemaType===`discriminatedUnion`&&t.discriminator&&t.variants?await c(r,i,t):t.schemaType===`union`||t.schemaType===`xor`||await u(r,i,t.fields),i}async function c(n,r,i){let{discriminator:a,variants:o}=i;if(!a||!o)return;if(r[a]===void 0){let e=l(i.fields,o,a),s=e?t(e):null;if(s){let e=o.map(e=>e.discriminatorValue).filter(Boolean);e.length>0&&(s.type=`select`,s.choices=e.map(e=>({label:e,value:e}))),await d(n,r,s)}}let s=e(i,()=>r);s!==i&&await u(n,r,s.fields.filter(e=>e.name!==a))}function l(e,t,n){let r=e.find(e=>e.name===n);if(r?.prompt)return r;for(let e of t){let t=e.fields.find(e=>e.name===n);if(t?.prompt)return t}}async function u(e,t,n){let r=a(n,t);for(let n of r)await d(e,t,n)}async function d(e,t,n){let{message:r}=n,i;switch(n.type){case`text`:i=await e.text({message:r,placeholder:n.field.placeholder});break;case`password`:i=await e.password({message:r});break;case`confirm`:i=await e.confirm({message:r});break;case`select`:i=await e.select({message:r,options:n.choices??[]})}if(e.isCancelled(i))throw Error(`Prompt cancelled by user`);t[n.field.name]=i}export{t as i,o as n,a as r,s as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e,s as t}from"./field-meta-CEtC5Mir.js";const n=/* @__PURE__ */ new WeakMap;function r(e,t){return t&&n.set(e,t),e}function i(e){return n.get(e)}function a(e,t=/* @__PURE__ */ new Set){if(t.has(e))return;t.add(e);let n=i(e);if(n)return n;if(typeof e.meta==`function`){let t=e.meta();if(t&&typeof t==`object`)return t}let r=e,s=r.def??r._def;if(s?.argMeta)return s.argMeta;if(s?.meta)return s.meta;let c=o(e);if(c===`optional`||c===`nullable`||c==="default"){let e=s?.innerType;if(e)return a(e,t)}if(c===`pipe`){let e=s?.in??s?.schema;if(e)return a(e,t)}}function o(e){let t=e;return t.def?.type??t._def?.type??t.type}function s(e){let t=c(e),n=(t.def??t._def)?.catchall;if(!n)return`strip`;let r=o(n);return r===`never`?`strict`:r===`unknown`||r===`any`?`passthrough`:`strip`}function c(e){let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return c(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return c(e)}return e}function l(e){let t=c(e);if(u(t))return`boolean`;switch(o(t)){case`string`:case`enum`:return`string`;case`number`:case`int`:return`number`;case`boolean`:return`boolean`;case`array`:return`array`;default:return`unknown`}}function u(e){let t=e._zod.values;if(t)return t.size>0&&[...t].every(e=>typeof e==`boolean`);let n=o(e);if(n===`boolean`)return!0;if(n!==`union`)return!1;let r=(e.def??e._def)?.options??[];return r.length>0&&r.every(u)}function d(e){let t=c(e),n=o(t),r=t,i=r.def??r._def;if(n===`enum`){let e=i?.entries;if(e&&typeof e==`object`)return Object.values(e);let t=i?.values;if(Array.isArray(t))return t;let n=r.options;if(Array.isArray(n))return n}if(n===`array`){let e=i?.element;if(e)return d(e)}if(n===`union`){let e=i?.options;if(Array.isArray(e)){let t=[];for(let n of e)if(o(n)===`literal`){let e=n.def??n._def,r=e?.value,i=e?.values,a=r??i?.[0];typeof a==`string`&&t.push(a)}if(t.length===e.length&&t.length>0)return t}}}function f(e){return!e.isOptional()}function p(e){let t=o(e),n=e,r=n.def??n._def;if(t==="default"){let e=r?.defaultValue;return typeof e==`function`?e():e}if(t===`optional`||t===`nullable`){let e=r?.innerType;if(e)return p(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return p(e)}}function m(e){if(e.description)return e.description;let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return m(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return m(e)}}function h(t,n){let r=a(n);return e(t,{argMeta:r,description:m(n),required:f(n),defaultValue:p(n),type:l(n),enumValues:d(n),schema:n})}function g(e){let t=e;return(t.def??t._def)?.shape??t.shape??{}}function _(e){let t=g(e);return Object.entries(t).map(([e,t])=>h(e,t))}function v(e){let t=e,n=t.def??t._def,r=n?.discriminator??``,i=n?.options??[],a=/* @__PURE__ */ new Map,c=[];for(let e of i){let t=g(e),n=[],i=``,s=t[r];if(s){let e=o(s);if(e===`literal`){let e=s.def??s._def,t=e?.value,n=e?.values;i=String(t??n?.[0]??``)}else if(e===`enum`){let e=d(s);e&&e.length===1&&(i=e[0])}}for(let[e,r]of Object.entries(t)){let t=h(e,r);n.push(t),a.has(e)||a.set(e,t)}let l=m(e);c.push({discriminatorValue:i,fields:n,...l?{description:l}:{}})}let l=m(e);return{fields:Array.from(a.values()),schema:e,schemaType:`discriminatedUnion`,unknownKeysMode:s(e),discriminator:r,variants:c,...l?{description:l}:{}}}function y(e,t){let n=e,r=(n.def??n._def)?.options??[],i=/* @__PURE__ */ new Map,a=[];for(let e of r){let t=S(e);a.push(t);for(let e of t.fields)i.has(e.name)||i.set(e.name,e)}let o=m(e);return{fields:Array.from(i.values()),schema:e,schemaType:t,unknownKeysMode:s(e),unionOptions:a,...o?{description:o}:{}}}function b(e){let t=e,n=t.def??t._def,r=n?.left,i=n?.right,a=/* @__PURE__ */ new Map,o=e=>{if(!e)return;let t=S(e);for(let e of t.fields)a.has(e.name)||a.set(e.name,e)};o(r),o(i);let c=m(e);return{fields:Array.from(a.values()),schema:e,schemaType:`intersection`,unknownKeysMode:s(e),...c?{description:c}:{}}}const x=/* @__PURE__ */ new WeakMap;function S(e){let t=x.get(e);if(t)return t;let n=e,r,i=o(n),a=n,c=a.def??a._def;switch(i){case`object`:{let t=m(n);r={fields:_(n),schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}case`union`:r=c?.discriminator?v(n):y(n,`union`);break;case`xor`:r=y(n,`xor`);break;case`intersection`:r=b(n);break;case`optional`:case`nullable`:case`default`:case`pipe`:{let t=c?.innerType??c?.in??c?.schema;if(t){let i=S(t),a=m(n);r={...i,schema:e,...a?{description:a}:{}};break}let i=m(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...i?{description:i}:{}};break}default:{let t=m(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}}return x.set(e,r),r}function C(e){return e.issues.map(e=>({path:e.path.map(String),message:e.message,code:e.code,received:`received`in e?e.received:void 0,expected:`expected`in e?String(e.expected):void 0}))}function w(e,t){let n=t.safeParse(e);return n.success?{success:!0,data:n.data}:{success:!1,errors:C(n.error)}}t({vendor:`zod`,extractFields:S,resolveFieldMeta:(e,t)=>h(e,t),getUnknownKeysMode:e=>s(e),validate:w});export{r as t};
|
package/dist/runner-Bg6kLaM9.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as runCommand}from"./runner-BsHTbOwS.js";
|