@politty/loculus 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{argv-parser-CVlS6mSo.js → argv-parser-CVXuhpy6.js} +1 -1
- package/dist/cli-main-CTVeQxs0.js +1 -0
- package/dist/{cli-main-CYw9CO6g.js → cli-main-CdXCj3sh.js} +2 -2
- package/dist/cli-run-x5wuUkuB.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/{completion-DjxPFcWB.js → completion-ChgOYSFp.js} +1 -1
- package/dist/completion-Df9_25sa.js +1 -0
- package/dist/completion.d.ts +2 -2
- package/dist/completion.js +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +32 -32
- package/dist/{dynamic-D_i-A8Qb.js → dynamic-D2uon-av.js} +2 -2
- package/dist/dynamic-plXaUNoz.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{prompt-Bmm7QM-I.js → prompt-CHjlvNAb.js} +1 -1
- package/dist/prompt-clack.d.ts +1 -1
- package/dist/prompt-clack.js +1 -1
- package/dist/prompt-inquirer.d.ts +1 -1
- package/dist/prompt-inquirer.js +1 -1
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/{register-Ceh-HlVN.js → register-D-aEK58y.js} +1 -1
- package/dist/{registry-BEz5iex_.js → registry-ZnSdmqJ1.js} +1 -1
- package/dist/runner-BbIyh52c.js +33 -0
- package/dist/runner-fgBRxl0e.js +1 -0
- package/dist/{schema-Dqan9VXJ.js → schema-Bz8oC0xQ.js} +1 -1
- package/dist/schema-extractor-BI5ypJ21.js +1 -0
- package/dist/skill.d.ts +1 -1
- package/dist/skill.js +1 -1
- package/dist/{types-CaP5nn8i.d.ts → types-D3ubanZt.d.ts} +20 -0
- package/dist/{with-completion-command-BhjWVp1l.d.ts → with-completion-command-BkTioGwX.d.ts} +1 -1
- package/dist/{with-completion-command-DQ1vWryG.js → with-completion-command-DOtEG943.js} +2 -2
- package/package.json +1 -1
- package/dist/cli-main-D-cfXp31.js +0 -1
- package/dist/cli-run-BxsmKHV0.js +0 -1
- package/dist/completion-W_nxO_kv.js +0 -1
- package/dist/dynamic-CDaJH0_w.js +0 -1
- package/dist/runner-B7QLJFxY.js +0 -33
- package/dist/runner-BdAfqN-z.js +0 -1
- package/dist/schema-extractor-D6Se8W6B.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function y(e){return`'${e.replace(/'/g,`'\\''`)}'`}function b(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function x(e){return e.length===1?`-${e}`:`--${e}`}function S(e,n){C(e,x(n)),n.length===1?C(e,`--${n}`):n.includes(`-`)&&C(e,`--${t(n)}`)}function C(e,t){e.includes(t)||e.push(t)}function w(e,n){let r=[`--${e}`];e.length===1&&r.push(`-${e}`),e.includes(`-`)&&r.push(`--${t(e)}`);for(let e of n??[])S(r,e);return r}function T(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function E(e,n,r,i){let a=new Set(w(e,n));if(r&&(a.add(`--${r}`),r.includes(`-`)&&a.add(`--${t(r)}`)),i?.frameOptions){if(i.isGlobal===!0){for(let e of i.frameOptions)if(e.isGlobal!==!0)for(let t of A(e.cliName,e.alias))a.delete(t)}else{let e=T(i.frameOptions);if(e.size>0){let t=new Set((n??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let n of e)t.has(n)||a.delete(n)}}}return[...a].map(e=>`"${e}"`)}function D(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&E(n.cliName,n.alias,n.negation,{frameOptions:t})})}function O(e,t,n,r=`$_pos_count`){let i=D(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function k(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of O(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function A(e,n){let r=[`--${e}`];e.includes(`-`)&&r.push(`--${t(e)}`);for(let e of n??[])S(r,e);return r}function j(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function M(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?N(e.args):[]}function N(e){return n(r(e)).map(P)}function P(t){let n=e(t);return{name:t.name,cliName:t.cliName,alias:n.length>0?n:void 0,negation:t.negationDisplay,negationDescription:t.negationDescription,description:t.description,takesValue:t.type!==`boolean`,valueType:t.type,required:t.required,defaultNegationAccepted:t.type===`boolean`&&t.negation===!0,valueCompletion:M(j(t))}}function F(e){return new Set(w(e.cliName,e.alias))}function te(e,t){let n=F(t);for(let t of e)for(let e of F(t))if(n.has(e))return t}function ne(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{G(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;if(u(i)){let{isGlobal:s,flags:l,valueOption:u}=z(i,t);if(!s)break;for(let{opt:e}of l)n[e.name]=!0,r.add(e.name);if(u?.value!==void 0)a(u.opt,u.value);else if(u){let t=e[o+1];if(t===void 0)break;c(t)&&(a(u.opt,t),o++)}o++;continue}if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let s=R(i),l=q(t,s);if(!l){if(de(t,s)){o++;continue}break}if(l.takesValue){if(B(i)){let e=i.indexOf(`=`);a(l,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(!c(t)){o++;continue}a(l,t),o+=2}else break}else{let e=V(l,s,i);e!==void 0&&(n[l.name]=e),r.add(l.name),o++}}return r}function re(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function ie(e,t){return t.length===0?e:[...e,...t]}function ae(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function I(e,t){return n=>{let r={...e};return l(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function oe(e,t,n){if(!e.args)return;let a=r(e.args),o=i(a,I(t,n));if(o!==a)return o.fields.filter(e=>e.named).map(P)}function se(e,t,n){if(!e.args)return[];let a=i(r(e.args),I(t,n));return l(a,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:M(j(e))}))}function ce(e){if(!e.subCommands)return[];let t=[];for(let[n,r]of Object.entries(e.subCommands)){if(n.startsWith(`__`))continue;t.push(n);let e=o(r);e?.aliases&&t.push(...e.aliases)}return t}function le(e,t){if(!e.subCommands)return null;let n=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(n)return o(n);let r=s(e,t);return r?o(e.subCommands[r]):null}function L(e){return e.startsWith(`-`)}function R(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function z(e,t){let n=(e,t)=>q(e,{name:t,isLong:!1}),r=t.filter(e=>e.isGlobal!==!0),i=t.filter(e=>e.isGlobal===!0),a=e=>!n(r,e)&&n(i,e)!==void 0,o=d(e.slice(1),e=>a(e)&&n(i,e).takesValue),s=o.flags.every(a),c=s?i:r,{flags:l,valueOption:u}=s?o:d(e.slice(1),e=>n(r,e)?.takesValue===!0);return{isGlobal:s,flags:l.flatMap(e=>{let t=n(c,e);return t?[{opt:t,name:e}]:[]}),valueOption:u&&{opt:n(c,u.name),value:u.value}}}function ue(e,t){let{valueOption:n}=z(e,t);return n?.value===void 0?n?.opt:void 0}function B(e){return e.includes(`=`)}function V(e,t,n){let r=fe(e,t);return B(n)?r?void 0:f(n.slice(n.indexOf(`=`)+1)):!r}function H(e,n,r){if(!r||e.valueType!==`boolean`)return!1;let i=[e.cliName,...e.alias??[]];for(let e of i){let r=`no-${e}`;if(n===r||n===t(r))return!0}return!1}function U(e,t,n){return e.defaultNegationAccepted===!0&&H(e,t,n)}function de(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&H(e,t.name,t.isLong))}function W(e,n){return e!==void 0&&e.includes(`-`)&&t(e)===n}function G(e,t,n,r){if(t.valueType!==`array`)e[t.name]=n;else if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function fe(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||W(e.negation,t.name))?!0:U(e,t.name,t.isLong):!1}function K(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:W(e.cliName,t)||e.alias?.some(e=>W(e,t))?!0:W(e.negation,t)}function q(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&K(e,t.name,t.isLong));if(r)return r}return e.find(e=>K(e,t.name,t.isLong))||e.find(e=>U(e,t.name,t.isLong))}function J(e,t,n){let r=Y(e,t,n);return r.variantOptions?Y(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function Y(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,o=[],s=n?N(n).map(e=>({...e,isGlobal:!0})):[],l=/* @__PURE__ */ new Set,d=!1,f=0,p={},m=[],h={},g=/* @__PURE__ */ new Set,_=0,v=/* @__PURE__ */ new Set,y=e=>{l.add(e.cliName);for(let t of e.alias??[])l.add(t);e.negation&&l.add(e.negation),d=!0},b=(e,t)=>{G(e.isGlobal===!0?h:p,e,t,v)},x=(e,t,n=``)=>{let r=e.isGlobal===!0?h:p,i=V(e,t,n);i!==void 0&&(r[e.name]=i)},S=0,C=ie(i(a),s),w=!1;for(;S<e.length-1;){let t=e[S];if(!w&&t===`--`){w=!0,S++;continue}if(!w&&u(t)){d=!0;let{flags:n,valueOption:r}=z(t,C);for(let{opt:e,name:t}of n)y(e),x(e,{name:t,isLong:!1});r&&(y(r.opt),r.value===void 0?S+1<e.length-1&&c(e[S+1])&&(b(r.opt,e[S+1]),S++):b(r.opt,r.value)),S++;continue}if(!w&&L(t)){d=!0;let n=R(t),r=q(C,n);if(r){if(y(r),r.takesValue){if(B(t)){let e=t.indexOf(`=`);b(r,t.slice(e+1))}else if(S+1<e.length-1){let t=e[S+1];c(t)&&(b(r,t),S++)}}else x(r,n,t)}S++;continue}let n=w?null:le(a,t);if(n){o.push(t);let r=i(a),c=e.slice(_,S);for(let e of ne(c,s,h))g.add(e);a=n,C=ie(i(a),s);for(let e of Object.keys(p)){let t=r.find(t=>t.name===e),n=s.find(t=>t.name===e)??(t?te(s,t):void 0);n&&(g.has(n.name)||(h[n.name]=re(p[e],n)))}l.clear(),f=0,p={},m=[],v=/* @__PURE__ */ new Set,_=S+1,S++}else m.push(t),f++,S++}let T=e[e.length-1]??``,E=e[e.length-2]??``,D=oe(a,p,m),O=se(a,p,m),k=ce(a);for(let e=0;e<O.length;e++){let t=O[e];if(t.variadic){p[t.name]=m.slice(e);break}e<m.length&&(p[t.name]=m[e])}let A,j,M;if(!w&&E&&L(E)&&!B(E)){let e=u(E)?ue(E,C):q(C,R(E));e&&e.takesValue?(A=`option-value`,j=e):T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f),A===`positional`&&(M=f))}else if(!w&&T.startsWith(`-`)&&B(T)){let e=q(C,R(T));e&&e.takesValue?(A=`option-value`,j=e):A=`option-name`}else!w&&T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f,w),A===`positional`&&(M=f));let P=[];if(j){if(j.valueType===`array`){let e=(j.isGlobal===!0?h:p)[j.name];P=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(A===`positional`&&M!==void 0){let e=ae(M,O);e!==void 0&&O[e]?.variadic&&(P=m.slice(e))}let F={...h,...p};return{context:{subcommandPath:o,currentCommand:a,currentWord:T,previousWord:E,completionType:A,targetOption:j,positionalIndex:M,options:C,subcommands:k,positionals:O,usedOptions:l,hasAnyOptionBeenUsed:d,providedPositionalCount:f,parsedArgs:F,previousValues:P},variantOptions:D}}function X(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const Z={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function pe(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function me(e,t){switch(e.completionType){case`subcommand`:return we(e);case`option-name`:return Te(e);case`option-value`:{let n=e.targetOption,r=n?pe(e.currentWord):void 0;return Q(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=he(e);return n?Q(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:Z.NoFileCompletion}}}}function he(e){let t=e.positionalIndex??0,n=ae(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function ge(e){try{return m(e,{encoding:`utf-8`,timeout:5e3}).split(`
|
|
1
|
+
import{a as e,n as t,u as n}from"./schema-extractor-BI5ypJ21.js";import{i as r,o as i}from"./registry-ZnSdmqJ1.js";import{n as a}from"./command-BXsTrIgI.js";import{c as o,i as s}from"./subcommand-router-40vA6Mka.js";import{n as c,o as l,r as u,s as d,u as f}from"./argv-parser-CVXuhpy6.js";import{t as p}from"./schema-Bz8oC0xQ.js";import{execSync as m}from"node:child_process";function h(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:_(e.valueCompletion,e.isGlobal===!0,t,n)}}function g(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:_(e.valueCompletion,!1,t,n)}}function _(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function v(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
|
|
2
|
+
`?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function y(e){return`'${e.replace(/'/g,`'\\''`)}'`}function b(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function x(e){return e.length===1?`-${e}`:`--${e}`}function S(e,t){C(e,x(t)),t.length===1?C(e,`--${t}`):t.includes(`-`)&&C(e,`--${i(t)}`)}function C(e,t){e.includes(t)||e.push(t)}function w(e,t){let n=[`--${e}`];e.length===1&&n.push(`-${e}`),e.includes(`-`)&&n.push(`--${i(e)}`);for(let e of t??[])S(n,e);return n}function T(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function E(e,t,n,r){let a=new Set(w(e,t));if(n&&(a.add(`--${n}`),n.includes(`-`)&&a.add(`--${i(n)}`)),r?.frameOptions){if(r.isGlobal===!0){for(let e of r.frameOptions)if(e.isGlobal!==!0)for(let t of A(e.cliName,e.alias))a.delete(t)}else{let e=T(r.frameOptions);if(e.size>0){let n=new Set((t??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let t of e)n.has(t)||a.delete(t)}}}return[...a].map(e=>`"${e}"`)}function D(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&E(n.cliName,n.alias,n.negation,{frameOptions:t})})}function O(e,t,n,r=`$_pos_count`){let i=D(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function k(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of O(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function A(e,t){let n=[`--${e}`];e.includes(`-`)&&n.push(`--${i(e)}`);for(let e of t??[])S(n,e);return n}function j(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function M(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?N(e.args):[]}function N(n){return e(t(n)).map(P)}function P(e){let t=r(e);return{name:e.name,cliName:e.cliName,alias:t.length>0?t:void 0,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:e.type===`boolean`&&e.negation===!0,valueCompletion:M(j(e))}}function F(e){return new Set(w(e.cliName,e.alias))}function te(e,t){let n=F(t);for(let t of e)for(let e of F(t))if(n.has(e))return t}function ne(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{G(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;if(u(i)){let{isGlobal:s,flags:l,valueOption:u}=z(i,t);if(!s)break;for(let{opt:e}of l)n[e.name]=!0,r.add(e.name);if(u?.value!==void 0)a(u.opt,u.value);else if(u){let t=e[o+1];if(t===void 0)break;c(t)&&(a(u.opt,t),o++)}o++;continue}if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let s=R(i),l=q(t,s);if(!l){if(de(t,s)){o++;continue}break}if(l.takesValue){if(B(i)){let e=i.indexOf(`=`);a(l,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(!c(t)){o++;continue}a(l,t),o+=2}else break}else{let e=V(l,s,i);e!==void 0&&(n[l.name]=e),r.add(l.name),o++}}return r}function re(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function ie(e,t){return t.length===0?e:[...e,...t]}function ae(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function I(e,t){return n=>{let r={...e};return l(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function oe(e,r,i){if(!e.args)return;let a=t(e.args),o=n(a,I(r,i));if(o!==a)return o.fields.filter(e=>e.named).map(P)}function se(e,r,i){if(!e.args)return[];let a=n(t(e.args),I(r,i));return l(a,r).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:M(j(e))}))}function ce(e){if(!e.subCommands)return[];let t=[];for(let[n,r]of Object.entries(e.subCommands)){if(n.startsWith(`__`))continue;t.push(n);let e=o(r);e?.aliases&&t.push(...e.aliases)}return t}function le(e,t){if(!e.subCommands)return null;let n=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(n)return o(n);let r=s(e,t);return r?o(e.subCommands[r]):null}function L(e){return e.startsWith(`-`)}function R(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function z(e,t){let n=(e,t)=>q(e,{name:t,isLong:!1}),r=t.filter(e=>e.isGlobal!==!0),i=t.filter(e=>e.isGlobal===!0),a=e=>!n(r,e)&&n(i,e)!==void 0,o=d(e.slice(1),e=>a(e)&&n(i,e).takesValue),s=o.flags.every(a),c=s?i:r,{flags:l,valueOption:u}=s?o:d(e.slice(1),e=>n(r,e)?.takesValue===!0);return{isGlobal:s,flags:l.flatMap(e=>{let t=n(c,e);return t?[{opt:t,name:e}]:[]}),valueOption:u&&{opt:n(c,u.name),value:u.value}}}function ue(e,t){let{valueOption:n}=z(e,t);return n?.value===void 0?n?.opt:void 0}function B(e){return e.includes(`=`)}function V(e,t,n){let r=fe(e,t);return B(n)?r?void 0:f(n.slice(n.indexOf(`=`)+1)):!r}function H(e,t,n){if(!n||e.valueType!==`boolean`)return!1;let r=[e.cliName,...e.alias??[]];for(let e of r){let n=`no-${e}`;if(t===n||t===i(n))return!0}return!1}function U(e,t,n){return e.defaultNegationAccepted===!0&&H(e,t,n)}function de(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&H(e,t.name,t.isLong))}function W(e,t){return e!==void 0&&e.includes(`-`)&&i(e)===t}function G(e,t,n,r){if(t.valueType!==`array`)e[t.name]=n;else if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function fe(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||W(e.negation,t.name))?!0:U(e,t.name,t.isLong):!1}function K(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:W(e.cliName,t)||e.alias?.some(e=>W(e,t))?!0:W(e.negation,t)}function q(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&K(e,t.name,t.isLong));if(r)return r}return e.find(e=>K(e,t.name,t.isLong))||e.find(e=>U(e,t.name,t.isLong))}function J(e,t,n){let r=Y(e,t,n);return r.variantOptions?Y(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function Y(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,o=[],s=n?N(n).map(e=>({...e,isGlobal:!0})):[],l=/* @__PURE__ */ new Set,d=!1,f=0,p={},m=[],h={},g=/* @__PURE__ */ new Set,_=0,v=/* @__PURE__ */ new Set,y=e=>{l.add(e.cliName);for(let t of e.alias??[])l.add(t);e.negation&&l.add(e.negation),d=!0},b=(e,t)=>{G(e.isGlobal===!0?h:p,e,t,v)},x=(e,t,n=``)=>{let r=e.isGlobal===!0?h:p,i=V(e,t,n);i!==void 0&&(r[e.name]=i)},S=0,C=ie(i(a),s),w=!1;for(;S<e.length-1;){let t=e[S];if(!w&&t===`--`){w=!0,S++;continue}if(!w&&u(t)){d=!0;let{flags:n,valueOption:r}=z(t,C);for(let{opt:e,name:t}of n)y(e),x(e,{name:t,isLong:!1});r&&(y(r.opt),r.value===void 0?S+1<e.length-1&&c(e[S+1])&&(b(r.opt,e[S+1]),S++):b(r.opt,r.value)),S++;continue}if(!w&&L(t)){d=!0;let n=R(t),r=q(C,n);if(r){if(y(r),r.takesValue){if(B(t)){let e=t.indexOf(`=`);b(r,t.slice(e+1))}else if(S+1<e.length-1){let t=e[S+1];c(t)&&(b(r,t),S++)}}else x(r,n,t)}S++;continue}let n=w?null:le(a,t);if(n){o.push(t);let r=i(a),c=e.slice(_,S);for(let e of ne(c,s,h))g.add(e);a=n,C=ie(i(a),s);for(let e of Object.keys(p)){let t=r.find(t=>t.name===e),n=s.find(t=>t.name===e)??(t?te(s,t):void 0);n&&(g.has(n.name)||(h[n.name]=re(p[e],n)))}l.clear(),f=0,p={},m=[],v=/* @__PURE__ */ new Set,_=S+1,S++}else m.push(t),f++,S++}let T=e[e.length-1]??``,E=e[e.length-2]??``,D=oe(a,p,m),O=se(a,p,m),k=ce(a);for(let e=0;e<O.length;e++){let t=O[e];if(t.variadic){p[t.name]=m.slice(e);break}e<m.length&&(p[t.name]=m[e])}let A,j,M;if(!w&&E&&L(E)&&!B(E)){let e=u(E)?ue(E,C):q(C,R(E));e&&e.takesValue?(A=`option-value`,j=e):T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f),A===`positional`&&(M=f))}else if(!w&&T.startsWith(`-`)&&B(T)){let e=q(C,R(T));e&&e.takesValue?(A=`option-value`,j=e):A=`option-name`}else!w&&T.startsWith(`-`)?A=`option-name`:(A=X(T,k,O,f,w),A===`positional`&&(M=f));let P=[];if(j){if(j.valueType===`array`){let e=(j.isGlobal===!0?h:p)[j.name];P=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(A===`positional`&&M!==void 0){let e=ae(M,O);e!==void 0&&O[e]?.variadic&&(P=m.slice(e))}let F={...h,...p};return{context:{subcommandPath:o,currentCommand:a,currentWord:T,previousWord:E,completionType:A,targetOption:j,positionalIndex:M,options:C,subcommands:k,positionals:O,usedOptions:l,hasAnyOptionBeenUsed:d,providedPositionalCount:f,parsedArgs:F,previousValues:P},variantOptions:D}}function X(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const Z={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function pe(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function me(e,t){switch(e.completionType){case`subcommand`:return we(e);case`option-name`:return Te(e);case`option-value`:{let n=e.targetOption,r=n?pe(e.currentWord):void 0;return Q(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=he(e);return n?Q(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:Z.NoFileCompletion}}}}function he(e){let t=e.positionalIndex??0,n=ae(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function ge(e){try{return m(e,{encoding:`utf-8`,timeout:5e3}).split(`
|
|
3
3
|
`).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function _e(e){return e?.type===`choices`?e.choices:void 0}function ve(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return _e(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return _e(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function ye(e,t){let n=!t.includes(`=`),r=n?be(e):xe(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function be(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function xe(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function Se(e,t,n,r,i){let a=[],o=Z.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=Z.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=Z.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=Z.FileCompletion)):o|=Z.FileCompletion;break;case`directory`:o|=Z.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...ge(e.shellCommand)),o|=Z.NoFileCompletion;break;case`none`:o|=Z.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??Z.FilterPrefix|Z.NoFileCompletion}catch{o=Z.NoFileCompletion|Z.Error}break;case`expand`:o|=Z.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=ve(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=/* @__PURE__ */ new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=Z.NoFileCompletion|Z.Error;break}o|=Z.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=ye(e.type===`runtime-expand`&&i===!0?Ce(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=Z.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function Ce(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function we(e){let t=[];for(let n of e.subcommands){let r=e.currentCommand.subCommands,i=r?.[n],a=i?void 0:s(e.currentCommand,n),c=i??(a?r?.[a]:void 0),l=c?o(c)?.description:void 0;t.push({value:n,description:l,type:`subcommand`})}if(t.length===0||e.currentWord.startsWith(`-`)){let n=Te(e);t.push(...n.candidates)}return{candidates:t,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Te(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:Z.FilterPrefix|Z.NoFileCompletion}}function Ee(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:De(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function De(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function Q(e,t,n,r,i,a){return r?Se(r,Ee(e,t,n),e,i,a):{candidates:[],directive:Z.FilterPrefix}}function Oe(e,t){switch(t.shell){case`bash`:return ke(e,t);case`zsh`:return Ae(e,t);case`fish`:return je(e,t)}}function $(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function ke(e,t){let n=((e.directive&Z.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return $(n,e),n.join(`
|
|
4
4
|
`)}function Ae(e,t){let n=e.candidates.map(e=>{let t=e.value.replace(/:/g,`\\:`);return e.description?`${t}:${e.description.replace(/:/g,`\\:`)}`:t});return $(n,e),n.join(`
|
|
5
5
|
`)}function je(e,t){let n=e.candidates.map(e=>e.description?`${e.value}\t${e.description}`:e.value);return $(n,e),n.join(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as createDynamicCompleteCommand}from"./dynamic-D2uon-av.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as KnownAgentId, t as AgentInfo } from "./detect-agent-hU93hctO.js";
|
|
2
|
-
import { $ as ExpandCandidate, A as SubCommandValue, B as toKebabCase, C as RunCommandOptions, D as RunResultSuccess, E as RunResultFailure, F as lazy, G as CustomCompletion, H as ArgMeta, I as ExtractedFields, J as PromptChoicesContext, K as EffectContext, L as ResolvedFieldMeta, M as UnknownSubcommandHandler, N as LazyCommand, O as RunnableCommand, P as isLazyCommand, Q as ValidateArgMeta, R as UnknownKeysMode, S as PromptResolverContext, T as RunResult, U as CompletionMeta, V as ArgFn, W as CompletionType, X as PromptMeta, Y as PromptChoicesResolver, Z as PromptType, _ as LogStream, a as ArgsSchema$1, at as DynamicCompletionResolver, b as NonRunnableCommand, c as Command, ct as loadPackage, d as GlobalArgs, et as ExpandCompletion, f as GlobalCleanupContext, g as LogLevel, h as LogEntry, i as ArgSource, it as DynamicCompletionContext, j as SubCommandsRecord, k as SetupContext, l as CommandBase, lt as InferSchemaOutput, m as IsEmpty, n as AgentHelpContext, nt as CompletionDirectiveMask, o as CleanupContext, ot as DynamicCompletionResult, p as GlobalSetupContext, q as PromptChoices, r as AnyCommand, rt as DynamicCompletionCandidate, s as CollectedLogs, st as PackageRequirement, t as AgentHelp, tt as ResolvedExpandCandidate, u as Example, ut as SchemaLike, v as Logger, w as RunInvocation, x as PromptResolver, y as MainOptions, z as toCamelCase } from "./types-
|
|
3
|
-
import { _ as CompletionResult, g as CompletionOptions, i as GenerateBundledCompletionWorkerResult, n as withCompletionCommand, r as GenerateBundledCompletionWorkerOptions, t as WithCompletionOptions, x as InternalArgsSchema } from "./with-completion-command-
|
|
2
|
+
import { $ as ExpandCandidate, A as SubCommandValue, B as toKebabCase, C as RunCommandOptions, D as RunResultSuccess, E as RunResultFailure, F as lazy, G as CustomCompletion, H as ArgMeta, I as ExtractedFields, J as PromptChoicesContext, K as EffectContext, L as ResolvedFieldMeta, M as UnknownSubcommandHandler, N as LazyCommand, O as RunnableCommand, P as isLazyCommand, Q as ValidateArgMeta, R as UnknownKeysMode, S as PromptResolverContext, T as RunResult, U as CompletionMeta, V as ArgFn, W as CompletionType, X as PromptMeta, Y as PromptChoicesResolver, Z as PromptType, _ as LogStream, a as ArgsSchema$1, at as DynamicCompletionResolver, b as NonRunnableCommand, c as Command, ct as loadPackage, d as GlobalArgs, et as ExpandCompletion, f as GlobalCleanupContext, g as LogLevel, h as LogEntry, i as ArgSource, it as DynamicCompletionContext, j as SubCommandsRecord, k as SetupContext, l as CommandBase, lt as InferSchemaOutput, m as IsEmpty, n as AgentHelpContext, nt as CompletionDirectiveMask, o as CleanupContext, ot as DynamicCompletionResult, p as GlobalSetupContext, q as PromptChoices, r as AnyCommand, rt as DynamicCompletionCandidate, s as CollectedLogs, st as PackageRequirement, t as AgentHelp, tt as ResolvedExpandCandidate, u as Example, ut as SchemaLike, v as Logger, w as RunInvocation, x as PromptResolver, y as MainOptions, z as toCamelCase } from "./types-D3ubanZt.js";
|
|
3
|
+
import { _ as CompletionResult, g as CompletionOptions, i as GenerateBundledCompletionWorkerResult, n as withCompletionCommand, r as GenerateBundledCompletionWorkerOptions, t as WithCompletionOptions, x as InternalArgsSchema } from "./with-completion-command-BkTioGwX.js";
|
|
4
4
|
import { Field, Schema, unflatten as unflatten$1 } from "loculus";
|
|
5
5
|
/**
|
|
6
6
|
* Detect the unknown-keys handling mode of an args schema. Works for any
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as e,i as t,m as n,n as r}from"./schema-extractor-BI5ypJ21.js";import{o as i,s as a}from"./registry-ZnSdmqJ1.js";import{n as o,t as s}from"./cli-main-CdXCj3sh.js";import{n as c,t as l}from"./command-BXsTrIgI.js";import{d as u,o as d,s as f}from"./subcommand-router-40vA6Mka.js";import{C as p,D as m,E as h,O as g,S as _,T as v,_ as y,a as b,b as x,c as S,d as C,f as w,g as T,h as E,i as D,l as ee,m as O,n as k,o as A,p as j,r as M,s as N,t as P,u as F,v as I,w as L,x as R,y as z}from"./runner-BbIyh52c.js";import{a as B,i as V,n as H,r as U,t as W}from"./logger-CoeDrmRr.js";import{a as G}from"./argv-parser-CVXuhpy6.js";import{t as K}from"./with-completion-command-DOtEG943.js";import{t as q}from"./register-D-aEK58y.js";import{unflatten as J}from"loculus";const Y=o(`@politty/loculus`),X=c,Z=l,Q=q,$=((t,r)=>(t.meta.shape&&e(Object.keys(t.meta.shape),r),n(J(t,r),r??{})));export{T as CaseVariantCollisionError,y as DefaultSubCommandError,I as DuplicateAliasError,z as DuplicateFieldError,x as DuplicateNegationError,R as FieldTypeConflictError,_ as PositionalConfigError,p as ReservedAliasError,L as ReservedFieldNameError,Q as arg,o as createCompileCacheShimGenerator,Z as createDefineCommand,M as createDualCaseProxy,X as defineCommand,r as extractFields,b as formatCommandValidationErrors,D as formatValidationErrors,Y as generateCompileCacheShim,v as generateHelp,h as generateHelpData,t as getUnknownKeysMode,W as isColorEnabled,d as isLazyCommand,f as lazy,u as loadPackage,H as logger,G as parseArgv,m as renderInline,g as renderMarkdown,P as runCommand,k as runMain,s as runPolittyCli,U as setColorEnabled,V as styles,B as symbols,i as toCamelCase,a as toKebabCase,$ as unflatten,A as validateCaseVariantCollisions,N as validateCommand,S as validateCrossSchemaCollisions,ee as validateDefaultSubCommand,F as validateDuplicateAliases,C as validateDuplicateFields,w as validateDuplicateNegations,j as validatePositionalConfig,O as validateReservedAliases,E as validateReservedFieldNames,K as withCompletionCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as e}from"./schema-extractor-
|
|
1
|
+
import{u as e}from"./schema-extractor-BI5ypJ21.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&&typeof t.choices!=`function`?`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:typeof t.choices==`function`||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(typeof t.choices!=`function`){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},a=n.globalArgs===e?i:n.globalArgs??{};return t.schemaType===`discriminatedUnion`&&t.discriminator&&t.variants?await c(r,i,t,a):t.schemaType===`union`||t.schemaType===`xor`||await u(r,i,t.fields,a),i}async function c(n,r,i,a){let{discriminator:o,variants:s}=i;if(!o||!s)return;if(r[o]===void 0){let e=l(i.fields,s,o),c=e?t(e):null;if(c){let e=s.map(e=>e.discriminatorValue).filter(Boolean);e.length>0&&(c.type=`select`,c.choices=e.map(e=>({label:e,value:e}))),await d(n,r,c,a)}}let c=e(i,()=>r);c!==i&&await u(n,r,c.fields.filter(e=>e.name!==o),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,r){let i=a(n,t);for(let n of i)await d(e,t,n,r)}async function d(e,t,n,r){let i=n.field.prompt?.choices;if(n.type===`select`&&!n.choices&&typeof i==`function`){let e;try{e=await i({rawArgs:{...t},globalArgs:{...r}})}catch(e){throw Error(`Failed to resolve prompt choices for "${n.field.name}": ${e instanceof Error?e.message:String(e)}`,{cause:e})}if(!Array.isArray(e)||e.length===0)throw Error(`No prompt choices available for "${n.field.name}"`);n={...n,choices:e.map(e=>{if(typeof e==`string`)return{label:e,value:e};if(typeof e==`object`&&e&&typeof e.label==`string`&&typeof e.value==`string`)return e;throw Error(`Invalid prompt choice for "${n.field.name}"`)})}}let{message:a}=n,o;switch(n.type){case`text`:o=await e.text({message:a,placeholder:n.field.placeholder});break;case`password`:o=await e.password({message:a});break;case`confirm`:o=await e.confirm({message:a});break;case`select`:o=await e.select({message:a,options:n.choices??[]})}if(e.isCancelled(o))throw Error(`Prompt cancelled by user`);t[n.field.name]=o}export{t as i,o as n,a as r,s as t};
|
package/dist/prompt-clack.d.ts
CHANGED
package/dist/prompt-clack.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-D-aEK58y.js";import{t as e}from"./prompt-CHjlvNAb.js";import{confirm as t,isCancel as n,password as r,select as i,text as a}from"@clack/prompts";function o(){return{text:e=>a({message:e.message,...e.placeholder!==void 0&&{placeholder:e.placeholder}}),password:e=>r(e),confirm:e=>t(e),select:e=>i(e),isCancelled:n}}const s=(t,n,r)=>e(t,n,{adapter:o(),...r});export{s as prompt};
|
package/dist/prompt-inquirer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-D-aEK58y.js";import{t as e}from"./prompt-CHjlvNAb.js";import{confirm as t,input as n,password as r,select as i}from"@inquirer/prompts";const a=Symbol(`inquirer-cancel`);async function o(e){try{return await e()}catch(e){if(e instanceof Error&&e.name===`ExitPromptError`)return a;throw e}}function s(){return{text:e=>o(()=>n({message:e.message})),password:e=>o(()=>r({message:e.message})),confirm:e=>o(()=>t({message:e.message})),select:e=>o(()=>i({message:e.message,choices:e.options.map(e=>({name:e.label,value:e.value}))})),isCancelled:e=>e===a}}const c=(t,n,r)=>e(t,n,{adapter:s(),...r});export{c as prompt};
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as ExtractedFields, L as ResolvedFieldMeta, S as PromptResolverContext } from "./types-
|
|
1
|
+
import { I as ExtractedFields, L as ResolvedFieldMeta, S as PromptResolverContext } from "./types-D3ubanZt.js";
|
|
2
2
|
/**
|
|
3
3
|
* Resolved prompt configuration for a single field
|
|
4
4
|
*/
|
package/dist/prompt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-
|
|
1
|
+
import"./register-D-aEK58y.js";export{r as getFieldsToPrompt,n as isInteractive,t as promptMissingArgs,i as resolvePromptConfig}from"./prompt-CHjlvNAb.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,n as t}from"./registry-
|
|
1
|
+
import{a as e,n as t}from"./registry-ZnSdmqJ1.js";import{boolean as n,intersection as r,number as i,union as a,xor as o}from"loculus";const s=/* @__PURE__ */ new WeakMap;function c(e,t){return t&&s.set(e,t),e}function l(e){return s.get(e)}function u(e){return l(e)??(e.meta.inner?u(e.meta.inner):void 0)}function d(t,n){let r=n.meta;return e(t,{argMeta:u(n),description:r.description,required:!r.optional,defaultValue:r.defaultValue,type:r.kind===`date`?`string`:[`string`,`number`,`boolean`,`array`].includes(r.kind)?r.kind:`unknown`,enumValues:(r.enumValues??r.literalValues)?.map(String),schema:n})}function f(e){return e.unknownKeys??`strip`}const p=/* @__PURE__ */ new WeakMap;function m(e){let t=p.get(e);if(t)return t;let n=e.meta,r;if(n.shape)r={fields:Object.entries(n.shape).map(([e,t])=>d(e,t)),schema:e,schemaType:`object`,unknownKeysMode:f(n)};else if(n.options){let t=n.options.map(e=>m(e)),i=t[0]?.unknownKeysMode??`strip`,a=/* @__PURE__ */ new Map;for(let e of t)for(let t of e.fields)a.has(t.name)||a.set(t.name,t);if(r={fields:[...a.values()],schema:e,schemaType:n.discriminator?`discriminatedUnion`:n.kind,unknownKeysMode:t.every(e=>e.unknownKeysMode===i)?i:`strip`},n.discriminator){let e=n.discriminator,i=new Set(t.map(t=>t.fields.find(t=>t.name===e)?.type)),a=i.size===1?[...i][0]:`unknown`,o=t=>t.map(t=>t.name===e?{...t,type:a}:t);r.fields=o(r.fields);let s=/* @__PURE__ */ new Map;r.discriminator=e,r.variants=t.flatMap((t,r)=>{let i=n.options[r].meta.shape?.[e]?.meta,a=i?.enumValues??i?.literalValues??[];return[...new Set(a)].map(n=>{let a=String(n),c=s.get(a);if(c!==void 0&&c!==r)throw TypeError(`Ambiguous CLI discriminator: ${e}=${a}`);return s.set(a,r),{discriminatorValue:a,normalizeDiscriminator:e=>g(e,i),fields:o(t.fields),...t.description?{description:t.description}:{}}})})}else n.kind!==`intersection`&&(r.unionOptions=t)}else throw TypeError(`loculus command arguments must have object output`);return n.description&&(r.description=n.description),p.set(e,r),r}const h={number:i()[`~standard`].validate,boolean:n()[`~standard`].validate};function g(e,t){if(typeof e!=`string`||t.enumValues?.includes(e)||t.literalValues?.includes(e))return e;for(let n of t.literalValues??[]){let t=typeof n;if(t!==`number`&&t!==`boolean`)continue;let r=h[t](e);if(!r.issues&&r.value===n)return r.value}return e}function _(e,t){let n=t.meta.discriminator;if(!n||typeof e[n]!=`string`)return e;let r=(t.meta.options??[]).map(e=>e.meta.shape?.[n]),i=e[n];if(r.some(e=>e?.meta.enumValues?.includes(i)||e?.meta.literalValues?.includes(i)))return e;for(let t of r){let r=t?.meta.literalValues?.find(e=>String(e)===i);if(r!==void 0)return{...e,[n]:r}}for(let t of r){if(!t)continue;let r=g(i,t.meta);if(r!==i)return{...e,[n]:r}}return e}const v=/* @__PURE__ */ new WeakMap;function y(e){let t=v.get(e);if(t)return t;let n=e[`~standard`].validate,{meta:i}=e;if(i.discriminator&&i.options?.some(e=>e.meta.shape?.[i.discriminator]?.meta.literalValues?.some(e=>typeof e!=`string`)))n=t=>!t||typeof t!=`object`||Array.isArray(t)?e[`~standard`].validate(t):e[`~standard`].validate(_(t,e));else if(i.options&&!i.inner){let e=i.options.map(e=>({...e,"~standard":{...e[`~standard`],validate:y(e)}}));if(e.some((e,t)=>e[`~standard`].validate!==i.options[t][`~standard`].validate)){if(i.kind===`intersection`)n=r(e[0],e[1])[`~standard`].validate;else if(i.kind===`union`||i.kind===`xor`){let t=e;n=(i.kind===`union`?a(t):o(t))[`~standard`].validate}}}return v.set(e,n),n}t({vendor:`loculus`,extractFields:m,resolveFieldMeta:(e,t)=>d(e,t),getUnknownKeysMode:e=>m(e).unknownKeysMode,validate:(e,t)=>{let n=y(t)(e);return n.issues?{success:!1,errors:n.issues.map(e=>({path:(e.path??[]).map(e=>String(typeof e==`object`?e.key:e)),message:e.message,code:e.code??`invalid_value`}))}:{success:!0,data:n.value}}});export{c as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=/* @__PURE__ */ new Set([`help`,`help-all`,`help-json`,`version`]);function t(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function n(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function r(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function i(n,r){let i=r.argMeta,a=i?.description??r.description,o=t(n),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(e,t)=>{if(e==null)return;let r=(Array.isArray(e)?e:[e]).map(e=>{if(typeof e!=`string`)throw Error(`Invalid ${t} for field "${n}": expected string or string[], received ${typeof e}.`);let r=e.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${t} "${e}" for field "${n}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(i?.alias,`alias`),u=new Set(l??[]),d=c(i?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=r.type,m=i?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${n}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${n}": 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 "${n}": negation names must match ${s}.`);if(e.has(t))throw Error(`Invalid negation "${m}" for field "${n}": negation cannot use reserved built-in flag names (${[...e].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${n}": negation can only be used on boolean fields.`);h=t}}let g=i?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${n}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${n}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${n}": negationDescription requires \`negation\` to be set (string or true).`);let e=g.trim();if(e.length===0)throw Error(`Invalid negationDescription for field "${n}": negationDescription must be a non-empty string.`);_=e}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y=i?.positional,b={name:n,cliName:o,alias:l,hiddenAlias:f,description:a,positional:y!==void 0&&y!==!1,named:typeof y==`object`?y.named===!0:y!==!0,placeholder:i?.placeholder,env:i?.env,required:r.required,defaultValue:r.defaultValue,type:p,schema:r.schema,enumValues:r.enumValues,completion:i?.completion,prompt:i?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:i?.effect,requiredPackages:i?.requiredPackages};return i&&`overrideBuiltinAlias`in i&&i.overrideBuiltinAlias===!0&&(b.overrideBuiltinAlias=!0),b}let a;function o(e){a=e}function s(){if(!a)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 a}export{i as a,r as i,o as n,n as o,e as r,t as s,s as t};
|
|
1
|
+
const e=/* @__PURE__ */ new Set([`help`,`help-all`,`help-json`,`version`]);function t(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function n(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function r(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function i(n,r){let i=r.argMeta,a=i?.description??r.description,o=t(n),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(e,t)=>{if(e==null)return;let r=(Array.isArray(e)?e:[e]).map(e=>{if(typeof e!=`string`)throw Error(`Invalid ${t} for field "${n}": expected string or string[], received ${typeof e}.`);let r=e.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${t} "${e}" for field "${n}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(i?.alias,`alias`),u=new Set(l??[]),d=c(i?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=r.type,m=i?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${n}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${n}": 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 "${n}": negation names must match ${s}.`);if(e.has(t))throw Error(`Invalid negation "${m}" for field "${n}": negation cannot use reserved built-in flag names (${[...e].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${n}": negation can only be used on boolean fields.`);h=t}}let g=i?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${n}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${n}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${n}": negationDescription requires \`negation\` to be set (string or true).`);let e=g.trim();if(e.length===0)throw Error(`Invalid negationDescription for field "${n}": negationDescription must be a non-empty string.`);_=e}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y=i?.positional,b={name:n,cliName:o,alias:l,hiddenAlias:f,description:a,positional:y!==void 0&&y!==!1,named:typeof y==`object`?y.named===!0:y!==!0,placeholder:i?.placeholder,env:i?.env,envFile:i?.envFile,required:r.required,defaultValue:r.defaultValue,type:p,schema:r.schema,enumValues:r.enumValues,completion:i?.completion,prompt:i?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:i?.effect,requiredPackages:i?.requiredPackages};return i&&`overrideBuiltinAlias`in i&&i.overrideBuiltinAlias===!0&&(b.overrideBuiltinAlias=!0),b}let a;function o(e){a=e}function s(){if(!a)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 a}export{i as a,r as i,o as n,n as o,e as r,t as s,s as t};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{_ as e,a as t,c as n,f as r,l as i,n as a,o,p as s,r as c,s as l,t as u,u as d,v as f}from"./schema-extractor-BI5ypJ21.js";import{i as p,o as m,r as h,s as g,t as _}from"./registry-ZnSdmqJ1.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 ne,o as C,r as w,t as T,u as E}from"./subcommand-router-40vA6Mka.js";import{n as D,r as O,t as k}from"./log-collector-uhRWYT-z.js";import{a as A,i as j}from"./logger-CoeDrmRr.js";import{a as M,c as re,d as ie,i as N,l as ae,n as P,o as F,r as oe,s as I,t as L}from"./argv-parser-CVXuhpy6.js";import*as R from"node:fs";import*as se from"node:path";import{isDeepStrictEqual as ce,parseEnv as le,stripVTControlCharacters as ue}from"node:util";async function de(e,t,n={}){let i,a,o=n.captureLogs??!1?k():null;o?.start();let s={args:t},c={args:t,error:i},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 i=typeof t==`object`&&t?t:{};for(let e of n.packageFields??[])e.requiredPackages?.length&&(e.nested?r(i,e)!==void 0:e.name in i)&&(n.packageDiscriminators?.includes(e.name)||r(i,e)===!0)&&await x(e.requiredPackages,t);e.setup&&await e.setup(s),e.run&&(a=await e.run(t))}catch(e){i=e instanceof Error?e:Error(String(e))}finally{l&&(process.off(`SIGINT`,l),process.off(`SIGTERM`,l))}if(e.cleanup){c.error=i;try{await e.cleanup(c)}catch(e){i||=e instanceof Error?e:Error(String(e))}}o?.stop();let u=n.existingLogs??D(),d=o?.getLogs()??D(),f=O(u,d);return i?{success:!1,error:i,exitCode:1,logs:f}:{success:!0,result:a,exitCode:0,logs:f}}function fe(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 pe(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 me(e){let t=!1,n=!1,r=!1;for(let i of e){let e=i.codePointAt(0);e===65039?r=!0:fe(e)||(t=!0,pe(e)&&(n=!0))}return t?n||r?2:1:0}const he=(()=>{try{return new Intl.Segmenter(`en`,{granularity:`grapheme`})}catch{return}})();function ge(e){if(e.length===0)return 0;let t=e.includes(`\x1B`)||e.includes(``)?ue(e):e,n=0;if(he)for(let{segment:e}of he.segment(t))n+=me(e);else for(let e of t)n+=me(e);return n}function z(e){let t=[],n=e.replace(/`([^`]+)`/g,(e,n)=>{let r=t.length;return t.push(j.cyan(n)),`\x00CODE${r}\x00`});return n=n.replace(/\*\*(.+?)\*\*/g,(e,t)=>j.bold(t)),n=n.replace(/__(.+?)__/g,(e,t)=>j.bold(t)),n=n.replace(/\*(.+?)\*/g,(e,t)=>j.italic(t)),n=n.replace(/(?<!\w)_(.+?)_(?!\w)/g,(e,t)=>j.italic(t)),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>`${j.underline(t)} ${j.dim(`(${n})`)}`),n=n.replace(/\x00CODE(\d+)\x00/g,(e,n)=>t[Number(n)]),n}function _e(e){return De(e.split(`
|
|
2
|
+
`)).map(Me).join(`
|
|
3
|
+
|
|
4
|
+
`)}const ve=/^(#{1,6})\s+(.+)$/,ye=/^(?:---+|\*\*\*+|___+)\s*$/,be=/^>\s?(.*)$/,xe=/^-\s+(.+)$/,Se=/^(\d+)[.)]\s+(.+)$/,Ce=/^(`{3,}|~{3,})(\S*)\s*$/,we=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/,Te=/^\|(.+)\|$/,Ee=/^\|(\s*:?-+:?\s*\|)+$/;function De(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.trim()===``){n++;continue}let i=r.match(Ce);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(ve);if(a){t.push({type:`heading`,level:a[1].length,content:a[2]}),n++;continue}if(ye.test(r)){t.push({type:`hr`}),n++;continue}if(be.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(be);if(t)r.push(t[1]),n++;else break}if(r.length>0){let e=r[0].match(we);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(xe.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(xe);if(t)r.push(t[1]),n++;else break}t.push({type:`ul`,items:r});continue}let o=r.match(Se);if(o){let r=Number(o[1]),i=[];for(;n<e.length;){let t=e[n].match(Se);if(t)i.push(t[2]),n++;else break}t.push({type:`ol`,items:i,start:r});continue}if(Te.test(r)&&n+1<e.length&&Ee.test(e[n+1])){let i=Oe(r),a=ke(e[n+1]);n+=2;let o=[];for(;n<e.length&&Te.test(e[n]);)o.push(Oe(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()===``||ve.test(t)||ye.test(t)||be.test(t)||xe.test(t)||Se.test(t)||Ce.test(t)||Te.test(t)&&n+1<e.length&&Ee.test(e[n+1]))break;s.push(t),n++}s.length>0&&t.push({type:`paragraph`,lines:s})}return t}function Oe(e){return e.slice(1,-1).split(`|`).map(e=>e.trim())}function ke(e){return e.slice(1,-1).split(`|`).map(e=>{let t=e.trim();return t.startsWith(`:`)&&t.endsWith(`:`)?`center`:t.endsWith(`:`)?`right`:`left`})}function Ae(e,t,n){let r=ge(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 je={NOTE:{icon:`ℹ`,label:`Note`,styleFn:j.cyan},TIP:{icon:`💡`,label:`Tip`,styleFn:j.green},IMPORTANT:{icon:`❗`,label:`Important`,styleFn:j.magenta},WARNING:{icon:`⚠`,label:`Warning`,styleFn:j.yellow},CAUTION:{icon:`🔴`,label:`Caution`,styleFn:j.red}};function Me(e){switch(e.type){case`heading`:return j.green(j.bold(z(e.content)));case`hr`:return j.dim(`─`.repeat(40));case`blockquote`:{let t=j.dim(`│ `);return e.lines.map(e=>`${t}${z(e)}`).join(`
|
|
5
|
+
`)}case`alert`:{let{icon:t,label:n,styleFn:r}=je[e.alertType],i=r(j.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=>`${j.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`${j.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=ge(e),i=r.map(e=>ge(e[t]));return Math.max(n,...i)}),a=j.dim(`│`),o=j.dim(`┌─${i.map(e=>`─`.repeat(e)).join(`─┬─`)}─┐`),s=j.dim(`├─${i.map(e=>`─`.repeat(e)).join(`─┼─`)}─┤`),c=j.dim(`└─${i.map(e=>`─`.repeat(e)).join(`─┴─`)}─┘`);return[o,`${a} ${n.map((t,n)=>j.bold(Ae(t,i[n],e.alignments[n]??`left`))).join(` ${a} `)} ${a}`,s,...r.map(t=>{let n=t.map((t,n)=>Ae(t,i[n],e.alignments[n]??`left`));return`${a} ${n.join(` ${a} `)} ${a}`}),c].join(`
|
|
9
|
+
`)}case`code`:return e.lines.map(e=>` ${j.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 Ne(e){return!e.startsWith(`__`)}function V(e){return Object.entries(e).filter(([e])=>Ne(e))}function Pe(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?t.commandPath.join(` `):e.name??`command`}function Fe(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?`${t.rootName} ${t.commandPath.join(` `)}`:e.name??`command`}function Ie(e,t){let r=[],i=Fe(e,t);r.push(j.commandName(i)),t?.globalExtracted?.fields.length&&r.push(j.placeholder(`[global options]`));let a=c(e);if(a){let t=n(a);l(a).length>0&&r.push(j.placeholder(`[options]`)),e.subCommands&&V(e.subCommands).length>0&&(e.run||e.defaultSubCommand?r.push(j.placeholder(`[command]`)):r.push(j.option(`<command>`)));for(let e of t)e.required?r.push(j.option(`<${e.name}>`)):r.push(j.placeholder(`[${e.name}]`))}else e.subCommands&&V(e.subCommands).length>0&&(e.run||e.defaultSubCommand?r.push(j.placeholder(`[command]`)):r.push(j.option(`<command>`)));return r.join(` `)}function Le(e,t){let n=`${j.dim(`When`)} ${j.option(e)}=${j.bold(t.discriminatorValue)}:`;return t.description?`${n} ${t.description}`:n}function Re(e,t){return` ${j.bold(`${e.description??`Variant ${t+1}`}:`)}`}function ze(e,t=0){let n=e.required?j.option(`<${e.name}>`):j.placeholder(`[${e.name}]`),r=e.named?`${n}, ${U(e)}`:n,i=[K(e),e.defaultValue===void 0?void 0:j.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)].filter(Boolean).join(` `);return i?G(r,i,t):`${` `.repeat(t)} ${r}`}function Be(e){let t=c(e);if(!t)return``;let n=[];if(t.schemaType===`discriminatedUnion`&&t.discriminator){let e=t.discriminator;n=(t.variants??[]).map(t=>({label:Le(e,t),fields:t.fields}))}else(t.schemaType===`union`||t.schemaType===`xor`)&&t.unionOptions&&(n=t.unionOptions.map((e,t)=>({label:Re(e,t),fields:e.fields})));let r=n.length>0?u(n):void 0,i=t.fields.filter(e=>e.positional&&(r===void 0||r.has(e.name))).map(e=>ze(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=>ze(e,1)))}return i.join(`
|
|
11
|
+
`)}function Ve(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=c(e),o=a?.fields.some(e=>e.overrideBuiltinAlias===!0&&p(e).includes(`h`))??!1,s=a?.fields.some(e=>e.overrideBuiltinAlias===!0&&p(e).includes(`H`))??!1;if(o?r.push(G(j.option(`--help`),i.help)):r.push(G(`${j.option(`-h`)}, ${j.option(`--help`)}`,i.help)),s?r.push(G(j.option(`--help-all`),i.helpAll)):r.push(G(`${j.option(`-H`)}, ${j.option(`--help-all`)}`,i.helpAll)),r.push(G(j.option(`--help-json`),i.helpJson)),n?.rootVersion&&r.push(G(j.option(`--version`),i.version)),!a)return r.join(`
|
|
12
|
+
`);if(a.schemaType===`discriminatedUnion`&&a.discriminator)return He(a,e,r);if(a.schemaType===`union`&&a.unionOptions||a.schemaType===`xor`&&a.unionOptions)return Ue(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+=` ${j.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${j.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(j.option(`--${e.negationDisplay}`),`${e.negationDescription} ${j.dim(`(↔ --${e.cliName})`)}`,t,n)}function He(e,t,n){let r=[],i=e.discriminator,a=e.variants??[],s=o(e,i);if(s){let t=a.map(e=>e.discriminatorValue).join(`|`),n=`${j.option(`--${i}`)} ${j.placeholder(`<${t}>`)}`,o=e.description??s.description??`Action to perform`;r.push(G(n,o))}let c=u(a,i);for(let t of c){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+=` ${j.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&&!c.has(e.name)&&!e.positional),n=S(e.fields.find(e=>e.name===i)?.requiredPackages);if(t.length>0||n){r.push(``),r.push(Le(i,e)),n&&r.push(Ke(n,2));for(let e of t){let t=U(e),n=K(e);e.defaultValue!==void 0&&(n+=` ${j.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${j.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 Ue(e,t,n){let r=[],i=e.unionOptions??[],a=u(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+=` ${j.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=Re(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+=` ${j.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${j.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(` ${j.dim(j.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(j.option(`-${n}`));let n=j.option(`--${e.cliName}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();n+=` ${j.placeholder(`<${t}>`)}`}if(t.push(n),e.alias){for(let n of e.alias)if(n.length>1){let r=j.option(`--${n}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();r+=` ${j.placeholder(`<${t}>`)}`}t.push(r)}}let r=t.join(`, `);return e.type===`boolean`&&e.negationDisplay&&!e.negationDescription?`${r} / ${j.option(`--${e.negationDisplay}`)}`:r}function W(e){if(!e)return``;let t=Array.isArray(e)?e:[e];return j.dim(`[env: ${t.join(`, `)}]`)}function We(e){return e.replace(/\x1B\[[0-9;]*m/g,``)}function Ge(e,t){let n=We(e).length,r=Math.max(0,t-n);return e+` `.repeat(r)}function Ke(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=We(e).length,o=32-n*2+r,s=o+2+n*2,c=Ke(t,s);return a>=o?`${i} ${e}\n${` `.repeat(s)}${c}`:`${i} ${Ge(e,o)}${c}`}function qe(e,t=0,n=0){let r=U(e),i=K(e);e.defaultValue!==void 0&&(i+=` ${j.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(i+=` ${j.required(`(required)`)}`);let a=W(e.env);return a&&(i+=` ${a}`),G(r,i,t,n)}function Je(e){let t=[];for(let n of e.fields){if(n.positional)continue;t.push(qe(n));let e=H(n);e&&t.push(e)}return t.join(`
|
|
18
|
+
`)}function Ye(e,t){let n=[],r=c(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+=` ${j.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 Xe(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(j.command(l),s,n)),e){let t=Ye(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=Xe(i,o,n);r.push(...e)}}}return r}function Ze(e,t){let n=[],r=t.context;t.agentHelp&&n.push(_e(t.agentHelp));let i=Pe(e,r);if(i){let e=j.commandName(i);r?.rootName&&r.commandPath&&r.commandPath.length>0?r.rootVersion?e+=` ${j.version(`(${r.rootName} v${r.rootVersion})`)}`:e+=` ${j.version(`(${r.rootName})`)}`:r?.rootVersion&&(e+=` ${j.version(`v${r.rootVersion}`)}`),n.push(e)}r?.aliasFor&&n.push(j.dim(`Alias for ${j.commandName(r.aliasFor)}`)),e.description&&n.push(e.description),!r?.aliasFor&&e.aliases&&e.aliases.length>0&&n.push(`${j.sectionHeader(`Aliases:`)} ${e.aliases.map(e=>j.command(e)).join(`, `)}`),n.push(`${j.sectionHeader(`Usage:`)} ${Ie(e,r)}`);let a=Be(e);a&&n.push(`${j.sectionHeader(`Arguments:`)}\n${a}`);let o=Ve(e,t.descriptions,r);if(o&&n.push(`${j.sectionHeader(`Options:`)}\n${o}`),r?.globalExtracted?.fields.length&&n.push(`${j.sectionHeader(`Global Options:`)}\n${Je(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=Xe(a,i,0);n.push(`${j.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(j.command(c),a))}n.push(`${j.sectionHeader(`Commands:`)}\n${e.join(`
|
|
22
|
+
`)}`)}}if(e.examples&&e.examples.length>0){let t=et(e.examples,r);n.push(`${j.sectionHeader(`Examples:`)}\n${t}`)}let s=S(e.requiredPackages);if(s&&n.push(`${j.sectionHeader(`Required packages:`)}\n${s}`),e.notes){let t=_e(e.notes).split(`
|
|
23
|
+
`).map(e=>e===``?``:` ${e}`).join(`
|
|
24
|
+
`);n.push(`${j.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:E(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 Qe(e,t){let r=Fe(e,t),i=!!t?.globalExtracted?.fields.length,a=e.subCommands&&V(e.subCommands).length>0?e.run?`optional`:`required`:void 0,o=c(e);return{commandName:r,hasGlobalOptions:i,hasOptions:o?l(o).length>0:!1,subcommand:a,positionals:o?n(o).map(e=>({name:e.name,required:e.required})):[]}}function $e(e,t={}){let r=t.context,i=r?.commandPath??[],a={help:t.descriptions?.help??B.help,helpAll:t.descriptions?.helpAll??B.helpAll,helpJson:t.descriptions?.helpJson??B.helpJson,...r?.rootVersion?{version:t.descriptions?.version??B.version}:{}},s=c(e),l,d=[],f=[],p,m,h;if(s){if(l=s.schemaType,d=n(s).map(q),s.schemaType===`discriminatedUnion`&&s.discriminator&&s.variants){let e=s.discriminator;p=e;let t=s.variants,n=u(t,e),r=o(s,e),i=s.fields.filter(e=>!e.positional&&n.has(e.name));f=[...r?[{...q({...r,requiredPackages:void 0}),description:s.description??r.description??`Action to perform`}]:[],...i.map(q)],m=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((s.schemaType===`union`||s.schemaType===`xor`)&&s.unionOptions){let e=s.unionOptions,t=u(e);f=s.fields.filter(e=>!e.positional&&t.has(e.name)).map(q),h=e.map(e=>({description:e.description,fields:e.fields.filter(e=>!t.has(e.name)).map(q)}))}else f=s.fields.filter(e=>!e.positional).map(q)}let g=r?.globalExtracted?.fields.length?r.globalExtracted.fields.filter(e=>!e.positional).map(q):void 0,_;if(e.subCommands){let n=V(e.subCommands);n.length>0&&(_=n.map(([n,a])=>{let o=b(a);if(!o)return{name:n,unresolved:!0};let s={commandPath:[...i,n],rootName:r?.rootName??e.name,rootVersion:r?.rootVersion,globalExtracted:r?.globalExtracted};return{name:n,aliases:o.aliases,data:$e(o,{descriptions:t.descriptions,context:s})}}))}return{name:e.name??`command`,commandPath:i,rootName:r?.rootName,version:r?.rootVersion,aliasFor:r?.aliasFor,description:e.description,aliases:e.aliases,usage:Qe(e,r),builtinOptions:a,schemaType:l,positionals:d,options:f,discriminator:p,variants:m,unionOptions:h,globalOptions:g,subcommands:_,examples:e.examples,notes:e.notes,...e.requiredPackages?.length?{requiredPackages:e.requiredPackages.map(e=>({name:e.name,install:E(e),description:e.description}))}:{},agentHelp:t.agentHelp}}function et(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(` ${j.dim(t.desc).split(`
|
|
28
|
+
`).join(`
|
|
29
|
+
`)}`),n.push(` ${j.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 tt=class extends Error{constructor(e){super(e),this.name=`PositionalConfigError`}},nt=class extends Error{constructor(e){super(e),this.name=`ReservedAliasError`}},rt=class extends Error{constructor(e){super(e),this.name=`DuplicateFieldError`}},it=class extends Error{constructor(e){super(e),this.name=`DuplicateAliasError`}},at=class extends Error{constructor(e){super(e),this.name=`CaseVariantCollisionError`}},ot=class extends Error{constructor(e){super(e),this.name=`DuplicateNegationError`}},st=class extends Error{constructor(e){super(e),this.name=`ReservedFieldNameError`}},ct=class extends Error{constructor(e){super(e),this.name=`DefaultSubCommandError`}},lt=class extends Error{constructor(e){super(e),this.name=`FieldTypeConflictError`}};function ut(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 dt(e,t){let n=[],r=/* @__PURE__ */ new Map;for(let i of e.fields){let e=m(i.name),a=r.get(e);a&&a!==i.name&&n.push({commandPath:t,type:`case_variant_collision`,message:`Fields "${a}" and "${i.name}" are case variants of each other and would collide.`,field:i.name}),r.set(e,i.name)}return n}function ft(e,t){let n=[],r=/* @__PURE__ */ new Map,i=new Set(e.fields.map(e=>e.name)),a=new Set(e.fields.map(e=>e.cliName)),o=(e,o,s)=>{(i.has(e)||a.has(e))&&n.push({commandPath:t,type:`duplicate_alias`,message:`Alias "${e}" for field "${o}" conflicts with existing field name or CLI name "${e}".`,field:o});let c=r.get(e);if(c&&c!==o){let r=s?` (derived camelCase variant)`:``;n.push({commandPath:t,type:`duplicate_alias`,message:`Duplicate alias "${e}"${r} detected. Both "${c}" and "${o}" use the same alias.`,field:o})}r.set(e,o)};for(let t of e.fields){let e=p(t);if(e.length!==0){for(let n of e)if(o(n,t.name,!1),n.length>1&&n.includes(`-`)){let e=m(n);e!==n&&!i.has(e)&&o(e,t.name,!0)}}}return n}function pt(e,t){let n=[],r=/* @__PURE__ */ new Map,i=(e,t,n)=>{r.has(e)||r.set(e,{field:t,kind:n})};for(let t of e.fields){if(i(t.name,t.name,`field name`),t.name.includes(`-`)){let e=m(t.name);e!==t.name&&i(e,t.name,`field name`)}if(t.cliName!==t.name&&i(t.cliName,t.name,`CLI name`),t.cliName.includes(`-`)){let e=m(t.cliName);e!==t.cliName&&i(e,t.name,`CLI name`)}for(let e of p(t))if(i(e,t.name,`alias`),e.length>1&&e.includes(`-`)){let n=m(e);n!==e&&i(n,t.name,`alias`)}if(t.type===`boolean`&&t.negation===!0){let e=`no-${t.cliName}`;i(e,t.name,`default negation`);let n=m(t.cliName),r=`no${n[0]?.toUpperCase()??``}${n.slice(1)}`;r!==e&&i(r,t.name,`default negation`)}}let a=/* @__PURE__ */ new Map,o=(e,i,o)=>{let s=r.get(e);if(s){let r=o?` (derived camelCase variant)`:``,a=s.field===i?`the same field's own ${s.kind} "${e}"`:`${s.kind} "${e}" of field "${s.field}"`;n.push({commandPath:t,type:`duplicate_negation`,message:`Negation "${e}"${r} for field "${i}" conflicts with ${a}.`,field:i})}let c=a.get(e);if(c&&c!==i){let r=o?` (derived camelCase variant)`:``;n.push({commandPath:t,type:`duplicate_negation`,message:`Duplicate negation "${e}"${r} detected. Both "${c}" and "${i}" use the same negation name.`,field:i})}a.set(e,i)};for(let t of e.fields)if(typeof t.negation==`string`&&(o(t.negation,t.name,!1),t.negation.includes(`-`))){let e=m(t.negation);e!==t.negation&&o(e,t.name,!0)}return n}function mt(e,t){let n=[e,...e.variants??[],...e.unionOptions??[]],r=/* @__PURE__ */ new Set;return n.flatMap(e=>ht(e.fields,t)).filter(e=>!r.has(e.message)&&r.add(e.message))}function ht(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 gt(e,t){let n=[];for(let r of e.fields){if(r.overrideBuiltinAlias!==!0)for(let e of p(r))(e===`h`||e===`H`)&&n.push({commandPath:t,type:`reserved_alias`,message:`Alias "${e}" is reserved for --${e===`h`?`help`:`help-all`}. To override this, set { overrideBuiltinAlias: true } for "${r.name}" and keep the alias where it is currently defined (in alias or hiddenAlias).`,field:r.name});let e=/* @__PURE__ */ new Set([r.cliName,...p(r)]);for(let i of e){if(!h.has(i))continue;let e=i===r.cliName;n.push({commandPath:t,type:`reserved_alias`,message:`${e?`Field "${r.name}"`:`Alias "${i}" for field "${r.name}"`} collides with the built-in --${i} option, which always takes precedence. Rename the field or its alias; this collision cannot be overridden.`,field:r.name})}}return n}function _t(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 vt(e){let t=ut(e,[]);if(t.length>0)throw new rt(`Duplicate field name "${t[0]?.field??`unknown`}" detected. Each field must have a unique name.`)}function yt(e){let t=ft(e,[]);if(t.length>0){let e=t[0];throw new it(e.message)}}function bt(e){let t=mt(e,[]);if(t.length>0){let e=t[0];throw new tt(e.message)}}function xt(e,t){let n=gt(e,[]);if(n.length>0)throw new nt(n[0].message)}function St(e){let t=_t(e,[]);if(t.length>0){let e=t[0];throw new st(e.message)}}function Ct(e){let t=pt(e,[]);if(t.length>0){let e=t[0];throw new ot(e.message)}}function wt(e){let t=dt(e,[]);if(t.length>0){let e=t[0];throw new at(e.message)}}function Tt(e,t,n){let r=[],i=/* @__PURE__ */ new Map;for(let t of e.fields)i.set(m(t.name),t);for(let e of t.fields){let t=m(e.name),a=i.get(t);a&&(a.name===e.name?r.push({commandPath:n,type:`field_type_conflict`,message:`Global field "${a.name}" and command field "${e.name}" share the same name. A field name can only be declared in one schema, even when the definitions are identical.`,field:e.name}):r.push({commandPath:n,type:`case_variant_collision`,message:`Global field "${a.name}" and command field "${e.name}" are case variants of each other and would collide.`,field:e.name}))}return r.push(...Et(e,t,n)),r}function Et(e,t,n){let r=e=>e.fields.map(e=>({field:e,path:e.nested?.path??[e.name]})),i=r(e),a=r(t);if(![...i,...a].some(({field:e})=>e.nested))return[];let o=[];for(let e of i)for(let t of a){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]&&g(e.path[0])===g(t.path[0])?`their group names are spellings of the same name`:void 0;i&&o.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 o}function Dt(e,t){let n=Tt(e,t,[])[0];if(n)throw n.type===`case_variant_collision`?new at(n.message):new lt(n.message)}function Ot(e,t,n){return[...ut(e,n),...dt(e,n),...ft(e,n),...pt(e,n),...mt(e,n),...gt(e,n),..._t(e,n)]}function kt(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 At(e){let t=kt(e,[]);if(t.length>0)throw new ct(t[0].message)}function jt(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=C(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 Mt(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 Nt(e,t={}){return Pt(e,t,!1)}async function Pt(e,t,n){n||=!!e.requiredPackages?.length;let r=t.commandPath??[e.name],i=[],o=e.subCommands?Object.keys(e.subCommands).length>0:!1,s=t.globalArgs?a(t.globalArgs):void 0;if(e.args){let t=a(e.args);i.push(...Ot(t,o,r)),s&&i.push(...Tt(s,t,r))}if(i.push(...jt(e,r)),i.push(...kt(e,r)),e.subCommands)for(let[a,o]of Object.entries(e.subCommands)){let e=await w(o,e=>n||!!e.requiredPackages?.length);i.push(...Mt(a,e.name,r));let s=await Pt(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 Ft(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 It(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}=L(e),o=/* @__PURE__ */ new Set;for(let t of e.fields)for(let e of p(t))e.length===1&&o.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:o,negationMap:i,defaultNegationDisabledFields:a}}function Lt(e,t){let{resolvedName:n,withoutDashes:r,isNegated:i,isCustomNegation:a,isSuppressedNegation:o}=ae(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&&P(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 Rt(e,t,n,r=()=>!1){let i=e[t];if(!oe(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}=I(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 zt(e,t,n){let r=It(n),i=new Set(t),a=[],o=[],s=0;for(;s<e.length;){let t=e[s];if(t===`--`||Bt.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}=Lt(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=Rt(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 Bt=/* @__PURE__ */ new Set([`--help`,`-h`,`--help-all`,`-H`,`--help-json`,`--version`]);function Vt(e,t,n={}){let r=n.stopOnSuppressedNegation===!0||t?.unknownKeysMode===`strict`,i=t?It(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===`--`||Bt.has(n))return-1;if(n.startsWith(`--`)){let{resolvedName:a,isNegated:o,isGlobal:s,isSuppressedNegation:c}=Lt(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=Rt(e,t,i);if(o>0)t+=o-1;else return-1}return-1}function Ht(e,t){let n=Vt(e,t);return n>=0?e[n]:void 0}function Ut(e,n,r={}){let i=T(n),o=[...i],s=o.length>0,c=s&&!n.run;if(s&&e.length>0){if(r.globalExtracted){let t=zt(e,o,r.globalExtracted);if(t.subCommandIndex>=0){let n=Kt(t.globalTokensBefore,r.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:n}}}else{let t=e[0];if(t&&!t.startsWith(`-`)&&i.has(t))return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:t,remainingArgs:e.slice(1),rawArgs:{},positionals:[],rest:[],unknownFlags:[]}}}let l;n.args&&(l=a(n.args),r.skipValidation||(vt(l),wt(l),yt(l),Ct(l),bt(l),xt(l,s),St(l),r.globalExtracted&&Dt(r.globalExtracted,l)));let u=e,d,f=[];if(r.globalExtracted){let n=l?t(l):[],i=new Set(n.map(e=>e.name)),{separated:a,globalParsed:o,suppressedTokens:s}=qt(e,r.globalExtracted,l&&{...l,fields:[...n,...l.fields.filter(e=>!i.has(e.name))]});u=a,d=o,f=s}let m=e.indexOf(`--`),h=m>=0?e.slice(0,m):e,g=l?.fields.some(e=>e.overrideBuiltinAlias===!0&&p(e).includes(`H`))??!1,_=l?.fields.some(e=>e.overrideBuiltinAlias===!0&&p(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:f,rawGlobalArgs:d};if(c||r.beforeEnvFallback?.(d),!l){let e=u.indexOf(`--`),t=e>=0?u.slice(0,e):u,n=e>=0?u.slice(e+1):[],i=e=>c&&e.startsWith(`-`)&&e!==`-`,a=new Set(r.globalExtracted?.fields.flatMap(e=>[e.name,e.cliName,...p(e)])),o=r.globalExtracted?L(r.globalExtracted):{},s=t.filter(i).flatMap(e=>Object.keys(M([e],o).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:n,unknownFlags:s,unknownGlobalFlags:f,rawGlobalArgs:d}}let x=Wt(l,u,{promptAvailable:r.promptAvailable===!0,inheritedNames:r.inheritedNames??/* @__PURE__ */ new Set});if(!x)return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:[],rest:[],unknownFlags:[],unknownGlobalFlags:f,extractedFields:l,matchesNoUnionOption:!0,rawGlobalArgs:d};let te=L(x),S=M(u,{...te,unknownFlagsTakeNoValue:c}),ne=N(S,x),C=X(ne,x),w=x.fields.filter(e=>e.named),E=new Set(w.map(e=>e.name)),D=new Set(w.map(e=>e.cliName)),O=/* @__PURE__ */ new Set;for(let e of w)for(let t of p(e))O.add(t);if(r.globalExtracted)for(let e of r.globalExtracted.fields){E.add(e.name),D.add(e.cliName);for(let t of p(e))O.add(t)}let k=[];for(let e of Object.keys(S.options))E.has(e)||D.has(e)||O.has(e)||k.push(e);return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:ne,positionals:S.positionals,rest:S.rest,unknownFlags:k,unknownGlobalFlags:f,extractedFields:l,optionFields:w,positionalSlotFields:F(x,S.options),rawGlobalArgs:d,envFallbackFields:C}}function Wt(e,t,n){let{discriminator:r,variants:i,unionOptions:a}=e;if(r&&i){let n=e=>{let n=N(M(t,L(e)),e);return X(n,e),n},r=d(e,n);return r===e?i.some(t=>{let r=n({...e,fields:t.fields});return d(e,()=>r)!==e})?void 0:e:r}if(a){let r=a.flatMap(e=>{let r=Wt(e,t,n);return r?[r]:[]}),i=n.promptAvailable?r.filter(e=>Gt(e,t,void 0)):[],o=r.find(e=>Gt(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]=ie(i,r.type),n.add(r.name);break}}return n}function Gt(e,t,n){let r=M(t,L(e)),i=e.fields.filter(e=>e.named),a=new Set(i.flatMap(e=>[e.name,e.cliName,...p(e)]));if(Object.keys(r.options).some(e=>!a.has(e)))return!1;let o=F(e,r.options),s=r.positionals.length+r.rest.length;if(!o.some(e=>e.type===`array`)&&s>o.length)return!1;let c=N(r,e);return e.fields.some(e=>e.type!==`boolean`&&[c[e.name]].flat().includes(!0))?!1:n===void 0||(X(c,e),e.fields.every(e=>!e.required||c[e.name]!==void 0||n.has(e.name)))}function Kt(e,t){if(e.length===0)return{};let n=L(t),r=M(e,n);return N(r,t)}function qt(e,t,n){let r=It(t),i=new Set(n?.fields.map(e=>e.name)??[]),a=new Set(n?.fields.map(e=>e.cliName)??[]),o=n?L(n):void 0,s=new Set(o?.aliasMap?.keys()??[]),c=new Set(o?.negationMap?.keys()??[]),l=/* @__PURE__ */ new Set;for(let e of n?.fields??[])if(e.type===`boolean`&&e.negation===!0)for(let t of[e.cliName,...p(e)]){let e=`no-${t}`;l.add(e),l.add(m(e))}let u=[],d=[],f=[];for(let t=0;t<e.length;t++){let n=e[t];if(n===`--`){d.push(...e.slice(t));break}if(n.startsWith(`--`)){let{resolvedName:o,withoutDashes:d,isNegated:p,isGlobal:m,isSuppressedNegation:h}=Lt(n,r),g=o,_=i.has(d)||i.has(g)||a.has(d)||a.has(g)||s.has(d)||s.has(g)||c.has(d)||c.has(g)||l.has(d);if(m&&!_){t+=Y(e,t,o,p,r.booleanFlags,u)-1;continue}if(h&&!_){f.push(d);continue}}else if(n.startsWith(`-`)&&n.length>1){let i=n.includes(`=`)?n.slice(1,n.indexOf(`=`)):n.slice(1);if(i.length===1){let n=r.aliasMap.get(i)??i;if((r.aliases.has(i)||r.flagNames.has(n))&&!s.has(i)){t+=Y(e,t,n,!1,r.booleanFlags,u)-1;continue}}let a=Rt(e,t,r,e=>s.has(e));if(a>0){u.push(...e.slice(t,t+a)),t+=a-1;continue}}d.push(n)}return{separated:d,globalParsed:Kt(u,t),suppressedTokens:f}}function Z(t,n){return e(n)?f(t,n):_().validate(t,n)}function Q(e){return e.map(e=>`${e.path.length>0?`${e.path.join(`.`)}: `:``}${e.message}`).join(`
|
|
33
|
+
`)}function Jt(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 Yt(e,t){let n=Math.max(2,Math.floor(e.length/2));return t.map(t=>({candidate:t,distance:Jt(e.toLowerCase(),t.toLowerCase())})).filter(({distance:e})=>e<=n).sort((e,t)=>e.distance-t.distance).map(({candidate:e})=>e).slice(0,3)}function Xt(e,t){let n=Yt(e.replace(/^-{1,2}/,``),t),r=`${j.warning(`Warning: Unknown option:`)} ${j.bold(e)}`;if(n.length>0){r+=`\n\n${j.info(`Did you mean?`)}`;for(let e of n)r+=`\n ${A.arrow} ${j.option(`--${e}`)}`}return r}function Zt(e,t){return t&&e.stack?`${j.error(`Error:`)} ${e.message}\n\n${j.dim(e.stack)}`:`${j.error(`Error:`)} ${e.message}`}function $(e){return new Proxy(e,{get(e,t,n){if(typeof t==`string`){if(t in e)return Reflect.get(e,t,n);let r=m(t);if(r!==t&&r in e)return Reflect.get(e,r,n);let i=g(t);if(i!==t&&i in e)return Reflect.get(e,i,n)}return Reflect.get(e,t,n)},has(e,t){if(typeof t==`string`){if(t in e)return!0;let n=m(t);if(n!==t&&n in e)return!0;let r=g(t);if(r!==t&&r in e)return!0}return Reflect.has(e,t)}})}async function Qt(e,t,n){for(let i of t.fields)i.effect&&await i.effect(r(e,i),{name:i.name,args:e,...n!=null&&{globalArgs:n}})}var $t=class extends Error{constructor(e){super(`Environment file not found: ${e}`),this.name=`EnvFileNotFoundError`}};function en(e,t){return t.fields.flatMap(t=>{if(!t.envFile)return[];let n=t.envFile===`if-exists`;return e.flatMap(e=>[e[t.name]].flat().filter(e=>typeof e==`string`).map(e=>({path:e,ifExists:n})))})}function tn(e,t){return Object.fromEntries((t?.fields??[]).flatMap(t=>{if(!t.envFile||t.type!==`array`)return[];let n=e.flatMap(e=>[e[t.name]].flat());return n.length>0&&n.every(e=>typeof e==`string`)?[[t.name,n]]:[]}))}function nn(e){let t=e.flatMap(e=>{let t=se.resolve(process.cwd(),e.path);if(!R.existsSync(t)){if(e.ifExists)return[];throw new $t(t)}return[le(R.readFileSync(t,`utf-8`))]}),n=new Set(t.flatMap(e=>Object.keys(e)).filter(e=>typeof process.env[e]==`string`));for(let e of t)for(let[t,r]of Object.entries(e))n.has(t)||(process.env[t]=r)}function rn(e){return[...e.fields,...(e.variants??[]).flatMap(e=>e.fields),...(e.unionOptions??[]).flatMap(rn)]}function an(e){let t=/* @__PURE__ */ new Map;for(let n of rn(e)){if(n.envFile&&n.type!==`string`&&n.type!==`array`)throw Error(`Global option "${n.name}" sets envFile but its value is not a string or an array of strings`);let e=t.get(n.name)??/* @__PURE__ */ new Set;e.add(n.envFile??!1),t.set(n.name,e)}for(let[e,n]of t)if(n.size>1)throw Error(`Global option "${e}" has different envFile settings across union variants (${[...n].map(e=>JSON.stringify(e)).join(`, `)}); use the same setting in every variant`)}const on={log:e=>console.log(e),error:e=>console.error(e),warn:e=>console.warn(e)};function sn(e){let t={};for(let[n,r]of Object.entries(e))try{t[n]=structuredClone(r)}catch{t[n]=r}return t}function cn(e,t){Object.defineProperty(e,"$source",{value:e=>t.get(e)??t.get(m(e))??t.get(g(e))??`default`,enumerable:!1})}function ln(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 un(e,t){Object.defineProperty(e,"$invocation",{value:t,enumerable:!1})}function dn(e,t){Object.defineProperty(e,"$agent",{value:t,enumerable:!1})}function fn(e,t){return e&&(n=>e({...n,agent:t}))}function pn(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 cn(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 mn(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:pn(t,n,r)}}catch{return{error:i}}}function hn(e,t){let{agentHelp:n,_agent:r}=e;if(n&&r)return typeof n==`string`?n:n({agent:r,commandPath:t.commandPath??[]})}function gn(e,t){let n=t.commandPath?.at(-1)??e.name;return t.aliasFor?{name:n,aliasFor:t.aliasFor}:{name:n}}async function _n(e,t,n={}){let r=Sn(n),i=v(),a=fn(n.cleanup,i),o=n.captureLogs??!1,s=o?k():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()??D()}}s?.stop()}let c={},l=await xn(e,t,{...n,handleSignals:!1,_globalExtracted:r,_globalCleanup:a,_existingLogs:s?.getLogs(),_agent:i,_globalTrace:c});if(a){let e=o?k():null;e?.start();let t=mn(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:O(l.logs,e?.getLogs()??D())}}}e?.stop();let i=e?.getLogs()??D();if(i.entries.length>0)return{...l,logs:O(l.logs,i)}}return l}function vn(e,t,n){let r=Ht(t,n);return!r||!r.startsWith(`__`)?!1:Object.hasOwn(e.subCommands??{},r)}async function yn(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=a(t.globalArgs)}catch{}let i=t;if(vn(e,n,r)){let{setup:e,cleanup:n,prompt:r,globalArgs:a,...o}=t;i=o}let o=Sn(i),s=v(),c=fn(i.cleanup,s);if(i.skipValidation||At(e),i.onUnknownSubcommand&&!e.run&&!vn(e,n,r)){let t=T(e);if(t.size>0){let e=Vt(n,o,{stopOnSuppressedNegation:o?.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 bn(),process.exit(a)}}}if(i.setup)try{await i.setup({agent:s})}catch(e){let t=e instanceof Error?e:Error(String(e));if(c)try{await c({error:t})}catch{}process.exit(1)}let l={},u=await xn(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:o,_globalCleanup:c,_agent:s,_globalTrace:l,_context:{commandPath:[],rootName:e.name,rootVersion:i.version,globalExtracted:o}});if((i.displayErrors??!0)&&!u.success&&u.error&&(i.logger??on).error(Zt(u.error,i.debug??!1)),c){let e=mn(u,l,i.globalArgs,o);try{await c(e)}catch{}}await bn(),process.exit(u.exitCode)}async function bn(){await Promise.all([process.stdout,process.stderr].map(e=>e.writableLength>0?new Promise(t=>e.write(``,()=>t())):Promise.resolve()))}async function xn(e,t,n={}){let r=n.logger??on,a=n._context??{commandPath:[],rootName:e.name,globalExtracted:n._globalExtracted},o=n.captureLogs??!1?k():null;o?.start();let c=()=>{let e=n._existingLogs??D(),t=o?.getLogs()??D();return O(e,t)};try{n.skipValidation||At(e);let l=(()=>{if(!n.onUnknownSubcommand||e.run||(a.commandPath??[]).length===0)return;let r=T(e);if(r.size===0)return;let i=Vt(t,n._globalExtracted,{stopOnSuppressedNegation:n._globalExtracted?.unknownKeysMode!==`passthrough`}),o=i>=0?t[i]:void 0;return o&&!r.has(o)?{positionalIndex:i,name:o}:void 0})(),u;try{u=Ut(t,e,{skipValidation:n.skipValidation,globalExtracted:n._globalExtracted,promptAvailable:n.prompt!==void 0,inheritedNames:new Set(Object.keys(n._parsedGlobalArgs??{})),beforeEnvFallback:e=>{n._globalExtracted&&!l&&(n._globalTrace&&(n._globalTrace.rawGlobalArgs={...n._parsedGlobalArgs,...e,...tn([n._parsedGlobalArgs??{},e??{}],n._globalExtracted)}),nn(en([...n._globalArgLevels??[],e??{}],n._globalExtracted)))}})}catch(e){if(!(e instanceof $t))throw e;return o?.stop(),{success:!1,error:e,exitCode:2,logs:c()}}let f={...n._parsedGlobalArgs,...u.rawGlobalArgs,...tn([n._parsedGlobalArgs??{},u.rawGlobalArgs??{}],n._globalExtracted)};n._globalTrace&&(n._globalTrace.rawGlobalArgs={...f});let p=a.commandPath??[],m=n.onUnknownSubcommand;if(l&&m){let{positionalIndex:e,name:r}=l;{let i=await m({commandPath:p,name:r,args:t.slice(e+1),precedingArgs:[...n._precedingArgs??[],...t.slice(0,e)]});if(typeof i==`number`){if(o?.stop(),n.handleSignals){if(n._globalCleanup)try{await n._globalCleanup({error:void 0})}catch{}await bn(),process.exit(i)}return i===0?{success:!0,result:void 0,exitCode:0,logs:c()}:{success:!1,error:/* @__PURE__ */ Error(`Plugin "${[...p,r].join(` `)}" exited with code ${i}`),exitCode:i,logs:c()}}}}if(u.helpRequested||u.helpAllRequested||u.helpJsonRequested){let i=!1,s=ne(e),l=T(e);if(s.length>0){let e=Ht(t,a.globalExtracted);e&&!l.has(e)&&(i=!0)}let d=hn(n,a);if(u.helpJsonRequested){let t=$e(e,{context:a,agentHelp:d});r.log(JSON.stringify(t))}else{let t=Ze(e,{showSubcommands:n.showSubcommands??!0,showSubcommandOptions:u.helpAllRequested||n.showSubcommandOptions,context:a,agentHelp:d});r.log(t)}if(o?.stop(),i){let e=Ht(t,a.globalExtracted)??``,n=Yt(e,[...l]),r=n.length>0?` Did you mean: ${n.join(`, `)}?`:``;return{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${e}${r?`.${r}`:``}`),exitCode:2,logs:c()}}return{success:!0,result:void 0,exitCode:0,logs:c()}}if(u.unknownGlobalFlags&&u.unknownGlobalFlags.length>0){let e=a.globalExtracted?.unknownKeysMode??`strip`;if(e===`strict`)return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown flags: ${u.unknownGlobalFlags.join(`, `)}`),exitCode:2,logs:c()};if(e===`strip`){let e=a.globalExtracted?.fields.map(e=>e.name)??[];for(let t of u.unknownGlobalFlags)r.error(Xt(t,e))}}if(u.versionRequested){let e=a.rootVersion;return e&&r.log(e),o?.stop(),{success:!0,result:void 0,exitCode:0,logs:c()}}if(u.subCommand){let r=n._metadataOnly??!1,i=await ee(e,u.subCommand,e=>{if(r)return!0;if(!e.requiredPackages?.length)return!1;let t=e,i=u.remainingArgs;for(;;){let e=Ut(i,t,{skipValidation:n.skipValidation,globalExtracted:a.globalExtracted,promptAvailable:!!n.prompt});if(e.helpRequested||e.helpAllRequested||e.helpJsonRequested||e.versionRequested)return r=!0,!0;if(!e.subCommand||!t.subCommands)return!1;let o=Object.hasOwn(t.subCommands,e.subCommand)?e.subCommand:te(t,e.subCommand)??e.subCommand,s=t.subCommands[o],c=s?b(s):null;if(!c)return!1;t=c,i=e.remainingArgs}});if(i){let e={commandPath:[...a.commandPath??[],u.subCommand],rootName:a.rootName,rootVersion:a.rootVersion,globalExtracted:a.globalExtracted,aliasFor:i.aliasFor};o?.stop();let s=new Set(n._globalExtracted?.unknownKeysMode===`passthrough`?[]:u.unknownGlobalFlags??[]),l=e=>e.startsWith(`--`)&&s.has(re(e)),d=t.slice(0,t.length-u.remainingArgs.length-1).filter(e=>!l(e));return xn(i.command,u.remainingArgs,{...n,_metadataOnly:r,_context:e,_existingLogs:c(),_parsedGlobalArgs:f,_globalArgLevels:[...n._globalArgLevels??[],u.rawGlobalArgs??{}],_precedingArgs:[...n._precedingArgs??[],...d]})}}let h=u.positionalSlotFields??[],g=h.some(e=>e.type===`array`),_=[...u.positionals,...u.rest],v=g?[]:_.slice(h.length),y=g?[]:u.positionals.slice(h.length);if(u.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:c()};let x=T(e),S=x.size>0?y.find(e=>!e.startsWith(`-`)&&!x.has(e)):void 0;if(S){let e=Yt(S,[...x]),t=e.length>0?` Did you mean: ${e.join(`, `)}?`:``;return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${S}${t?`.${t}`:``}`),exitCode:2,logs:c()}}if(u.unknownFlags.length>0){let e=u.extractedFields?.unknownKeysMode??a.globalExtracted?.unknownKeysMode??`strip`,t=u.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: ${u.unknownFlags.join(`, `)}`),exitCode:2,logs:c()};if(e===`strip`)for(let e of u.unknownFlags)r.error(Xt(e,t))}if(ne(e).length>0&&!u.subCommand&&!e.run&&v.length===0){if(e.defaultSubCommand){let r=e.subCommands?.[e.defaultSubCommand];if(r){let i=await w(r),s={commandPath:[...a.commandPath??[],e.defaultSubCommand],rootName:a.rootName,rootVersion:a.rootVersion,globalExtracted:a.globalExtracted};o?.stop();let l=new Set(n._globalExtracted?.unknownKeysMode===`passthrough`?[]:u.unknownGlobalFlags??[]),d=e=>e.startsWith(`--`)&&l.has(re(e)),p=t.filter(e=>!d(e));return xn(i,[],{...n,_context:s,_existingLogs:c(),_parsedGlobalArgs:f,_globalArgLevels:[...n._globalArgLevels??[],u.rawGlobalArgs??{}],_precedingArgs:[...n._precedingArgs??[],...p]})}}if(n.globalArgs&&n._globalExtracted){let e={...f};X(e,n._globalExtracted);let t=Z(e,n.globalArgs),r=t.success?[]:t.errors.filter(t=>t.path[0]&&e[t.path[0]]!==void 0);if(r.length>0)return o?.stop(),{success:!1,error:Error(Q(r)),exitCode:2,logs:c()}}let i=Ze(e,{showSubcommands:n.showSubcommands??!0,context:a,agentHelp:hn(n,a)});return r.log(i),o?.stop(),{success:!0,result:void 0,exitCode:0,logs:c()}}if(v.length>0){let e=u.extractedFields?.unknownKeysMode??`strip`;if(e===`strict`)return o?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unexpected positional argument${v.length>1?`s`:``}: ${v.join(`, `)}`),exitCode:2,logs:c()};if(e===`strip`)for(let e of v)(r.warn??r.error)(`Warning: Unexpected positional argument: ${e}`)}let C={},E=e.name===`__complete`,D=new Set(Object.keys(f)),O=/* @__PURE__ */ new Set,k=/* @__PURE__ */ new Set;if(n.globalArgs&&n._globalExtracted&&!E){if(O=X(f,n._globalExtracted),n.prompt){let e=sn(f);try{let e=await n.prompt(f,n._globalExtracted,{globalArgs:f});for(let[t,n]of Object.entries(e))n!==void 0&&(f[t]=n)}finally{let t={};for(let n of/* @__PURE__ */ new Set([...Object.keys(e),...Object.keys(f)])){let r=f[n];ce(e[n],r)||(t[n]=r,r===void 0&&(D.delete(n),O.delete(n)))}k=new Set(Object.keys(t).filter(e=>t[e]!==void 0)),n._globalTrace&&(n._globalTrace.promptedGlobalArgs=t)}}let e=Z(f,n.globalArgs);if(!e.success)return o?.stop(),{success:!1,error:Error(Q(e.errors)),exitCode:2,logs:c()};C=e.data}let A=n.globalArgs&&n._globalExtracted&&!E?i(n._globalExtracted,e=>Z(f,e).success,()=>f):n._globalExtracted,j=E||!n._globalExtracted?void 0:A===n._globalExtracted?d(n._globalExtracted,()=>C).fields:A?.fields;if(!e.args){let t=ln(D,O,k);cn(C,t),un(C,gn(e,a)),dn(C,n._agent);let r=$(C);return n._globalExtracted&&!E&&(n._globalTrace&&(n._globalTrace.effectsRan=!0),await Qt(r,A,r)),o?.stop(),await de(e,r,{handleSignals:n.handleSignals,captureLogs:n.captureLogs,existingLogs:c(),globalCleanup:n._globalCleanup,packageDiscriminators:n._globalExtracted?.discriminator?[n._globalExtracted.discriminator]:[],packageFields:j})}let M=u.rawArgs,ie=n.prompt?sn(u.rawArgs):u.rawArgs,N=e=>Object.hasOwn(ie,e),ae=/* @__PURE__ */ new Set;if(n.prompt&&u.extractedFields){let e=await n.prompt(M,u.extractedFields,{globalArgs:C}),t={...M};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);M=t;for(let[e,t]of Object.entries(M))t===void 0||N(e)&&ce(ie[e],t)||ae.add(e)}let P=Z(M,e.args);if(!P.success)return o?.stop(),{success:!1,error:Error(Q(P.errors)),exitCode:2,logs:c()};let F=$(P.data),oe=ln(D,O,k);cn(C,oe),un(C,gn(e,a)),dn(C,n._agent);let I=$(C);n._globalExtracted&&!E&&(n._globalTrace&&(n._globalTrace.effectsRan=!0),await Qt(I,A,I));let L=u.extractedFields?E?u.extractedFields:i(u.extractedFields,e=>Z(M,e).success,()=>M):void 0;L&&!E&&await Qt(F,L,I);let R=s({...I},{...F},A?.fields??[],L?.fields??[]),se=new Map(oe),le=u.envFallbackFields??/* @__PURE__ */ new Set;for(let e of u.extractedFields?.fields??[]){let t=M[e.name]!==void 0;se.set(e.name,ae.has(e.name)?`prompt`:t&&le.has(e.name)?`env`:t&&N(e.name)?`cli`:`default`)}cn(R,se),un(R,gn(e,a)),dn(R,n._agent);let ue=$(R);return o?.stop(),await de(e,ue,{handleSignals:n.handleSignals,captureLogs:n.captureLogs,existingLogs:c(),globalCleanup:n._globalCleanup,packageDiscriminators:[u.extractedFields?.discriminator,n._globalExtracted?.discriminator].filter(e=>e!==void 0),packageFields:E?void 0:[...j??[],...L!==u.extractedFields&&L?L.fields:[...u.optionFields??[],...u.positionalSlotFields??[]]]})}catch(e){let t=e instanceof Error?e:Error(String(e));return o?.stop(),{success:!1,error:t,exitCode:1,logs:c()}}}function Sn(e){if(!e.globalArgs)return;let t=a(e.globalArgs);if(!e.skipValidation){vt(t),wt(t),yt(t),Ct(t),xt(t,!0),St(t),an(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{nt as C,z as D,$e as E,_e as O,tt as S,Ze as T,ct as _,Ft as a,ot as b,Dt as c,vt as d,Ct as f,at as g,St as h,Q as i,At as l,xt as m,yn as n,wt as o,bt as p,$ as r,Nt as s,_n as t,yt as u,it as v,st as w,lt as x,rt as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as runCommand}from"./runner-BbIyh52c.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e,h as t}from"./schema-extractor-
|
|
1
|
+
import{g as e,h as t}from"./schema-extractor-BI5ypJ21.js";const n=t({shell:e.enum([`bash`,`zsh`,`fish`],{description:`Target shell for output formatting`}),args:e.stringArray({positional:!0,description:`Arguments to complete`})});export{n as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,s as t,t as n}from"./registry-ZnSdmqJ1.js";function r(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}const i=`__polittyInternalArgs`,a={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 o(e,t={}){return{[i]:!0,fields:e,unknownKeys:t.unknownKeys??`strip`}}function s(e){return typeof e==`object`&&!!e&&e[i]===!0}const c={string:`string`,boolean:`boolean`,enum:`string`,"string-array":`array`},l=/* @__PURE__ */ new WeakMap;function u(t){let n=l.get(t);if(n)return n;let r={fields:Object.entries(t.fields).map(([t,n])=>e(t,{argMeta:n.meta,description:void 0,required:!n.optional&&n.defaultValue===void 0,defaultValue:n.defaultValue,type:c[n.kind],enumValues:n.enumValues?[...n.enumValues]:void 0,schema:n})),schema:t,schemaType:`object`,unknownKeysMode:t.unknownKeys};return l.set(t,r),r}function d(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 f(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function p(e,t,n){return{path:[e],message:`Invalid input: expected ${d(t)}, received ${f(n)}`,code:`invalid_type`,received:n,expected:d(t)}}function m(e,t,n){switch(t.kind){case`string`:return typeof n==`string`?null:p(e,t,n);case`boolean`:return typeof n==`boolean`?null:p(e,t,n);case`enum`:return typeof n!=`string`||!(t.enumValues??[]).includes(n)?{path:[e],message:`Invalid option: expected ${d(t)}`,code:`invalid_value`,received:n,expected:d(t)}:null;case`string-array`:return!Array.isArray(n)||n.some(e=>typeof e!=`string`)?p(e,t,n):null}}function h(e,t){let n=[],i={};for(let[r,a]of Object.entries(t.fields)){let t=e[r];if(t===void 0){a.defaultValue===void 0?a.optional||n.push(p(r,a,void 0)):i[r]=Array.isArray(a.defaultValue)?[...a.defaultValue]:a.defaultValue;continue}let o=m(r,a,t);o?n.push(o):i[r]=t}let a=new Set(Object.keys(t.fields)),o=Object.keys(e).filter(e=>!a.has(e));if(o.length>0){if(t.unknownKeys===`strict`)n.push({path:[],message:`Unrecognized key${o.length>1?`s`:``}: ${o.map(e=>JSON.stringify(e)).join(`, `)}`,code:`unrecognized_keys`});else if(t.unknownKeys===`passthrough`)for(let t of o)r(i,t,e[t])}return n.length>0?{success:!1,errors:n}:{success:!0,data:i}}function g(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 _(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)g(e,t,i)!==void 0&&(r===void 0||i.length<r.length)&&(r=i);return r===void 0?void 0:[r,g(e,t,r)]}function v(e,t,n){if(t===`dot`)return e.split(`.`);let r=[],i=e;for(let e=_(i,t,n);e;e=_(i,t,n)){let a=e[0];r.push(a),i=e[1],n=n.flatMap(e=>g(e,t,a)??[])}return r.push(i),r}function y(e={}){let t=e.style??`dot`,n=`prefixes`in e?e.prefixes:[];return e=>v(e,t,n)}function b(e,t){let n={},i=/* @__PURE__ */ new Set,a=(e,t)=>({issues:[{message:`Cannot unflatten "${e}": "${t}" is both a value and a group`,path:[e]}]});for(let o of Object.keys(e)){let s=t(o),c=s.length-1,l=n;for(let e=0;e<c;e++){let t=s[e];if(Object.hasOwn(l,t)){let e=l[t];if(!i.has(e))return a(o,t);l=e}else{let e={};i.add(e),r(l,t,e),l=e}}let u=s[c];if(Object.hasOwn(l,u))return a(o,u);r(l,u,e[o])}return{value:n}}function x(e,n={}){let r=y(n),i=b(Object.fromEntries(e.map(e=>[e,void 0])),r);if(i.issues)throw TypeError(i.issues[0].message);let a=/* @__PURE__ */ new Map;for(let n of e){let e=r(n)[0],i=t(e),o=a.get(i);if(o!==void 0&&o!==e)throw TypeError(`Cannot unflatten "${n}": "${o}" and "${e}" are spellings of the same name. Spell the name the same way in every key.`);a.set(i,e)}}const S=/* @__PURE__ */ new WeakMap;function C(e,t={}){return S.set(e,t),e}function w(e){return S.get(e)}function T(e){if(S.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 E(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 D(e,t,n,i){let a=O(i),o=new Set([...O(n)].filter(e=>a.has(e))),s=(e,t,n)=>{let i={...e,...t};for(let a of Object.keys(t)){let c=[...n,a],l=Object.hasOwn(e,a)?e[a]:void 0,u=t[a];o.has(c.join(`\0`))&&k(l)&&k(u)&&r(i,a,s(l,u,c))}return i};return s(e,t,[])}function O(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 k(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function A(e){return s(e)?e.unknownKeys:n().getUnknownKeysMode(e)}const j=/* @__PURE__ */ new WeakSet,M=/* @__PURE__ */ new WeakMap;function N(e){let t=s(e)?u(e):F(e,n().extractFields(e));return j.has(t)||(L(t),j.add(t)),t}function P(e){for(let t of e.unionOptions??[])T(t.schema),P(t)}function F(e,t){P(t);let n=w(e);if(!n)return t;let r=M.get(t);return r||(r=I(t,y(n)),M.set(t,r)),r}function I(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=>I(e,t))}}}function L(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??[])L(t)}function R(e){return e.args?N(e.args):null}function z(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&&B(t.requiredPackages,e.requiredPackages)))&&i.add(e.name);return i}function B(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 V(e){let t=W(e).filter(e=>e.named);return G(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 H(e){return G(e,e=>e.positional)}function U(e){return G(e,e=>!e.positional)}function W(e){let t=e.variants??e.unionOptions??[];return[e.fields,...t.map(e=>e.fields)].flat()}function G(e,t){let n=/* @__PURE__ */ new Map;for(let r of W(e))t(r)&&!n.has(r.name)&&n.set(r.name,r);return[...n.values()]}function K(e,t){return e.effect===t.effect&&B(e.requiredPackages,t.requiredPackages)&&(e.nested?.path??[]).join(`\0`)===(t.nested?.path??[]).join(`\0`)}function q(e){let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;for(let r of e){if(r.unionOptions&&q(r.unionOptions)||r.variants&&q(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(!K(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 J(e,t,n){let r=e.unionOptions;if(e.discriminator||!r||!q(r))return e;for(let i of r){if(!t(i.schema))continue;let r=i.discriminator&&i.variants?Y(i,n):J(i,t,n);return{...e,fields:r.fields}}return e}function Y(e,t){let{discriminator:n,variants:r}=e;if(!n||!r){let n=e.unionOptions??[],r=n.map(e=>Y(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 X(e,t){return U(e).find(e=>e.name===t)}export{s as _,V as a,H as c,x as d,E as f,a as g,o as h,A as i,J as l,C as m,N as n,X as o,D as p,R as r,U as s,z as t,Y as u,h as v,r as y};
|
package/dist/skill.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as UnknownKeysMode, a as ArgsSchema, r as AnyCommand } from "./types-
|
|
1
|
+
import { R as UnknownKeysMode, a as ArgsSchema, r as AnyCommand } from "./types-D3ubanZt.js";
|
|
2
2
|
/**
|
|
3
3
|
* SKILL.md frontmatter metadata, validated against the Agent Skills
|
|
4
4
|
* specification (https://agentskills.io/specification). Unknown fields are
|
package/dist/skill.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{g as e,h as t,n}from"./schema-extractor-D6Se8W6B.js";import{n as r}from"./command-BXsTrIgI.js";import{a as i,n as a}from"./logger-CoeDrmRr.js";import"./register-Ceh-HlVN.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";const ie=/^[a-z0-9]+(-[a-z0-9]+)*$/;function T(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 ${T(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 ${T(r)}`});else for(let[e,n]of Object.entries(r))typeof n!=`string`&&t.push({path:[`metadata`,e],message:`Invalid input: expected string, received ${T(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 E(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}=E(e),r=ae(t);return r.success?{frontmatter:r.data,body:n,rawContent:e}:null}const D=`.agents/skills`,O=[`.claude/skills`],k=`politty-cli`;function A(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;A(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.${k}="{package}:{cli}" to the source SKILL.md so subsequent installs can replace the copy in place.`);let o=C(t,D),s=m(e.sourcePath),c=ue(e.sourcePath),u=[x(M(o),r),...O.map(e=>x(M(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=M(o);j(x(e,r),S(e,c));for(let n of O){let i=M(C(t,n));j(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 j(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 M(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={}){A(e);let r=n.expectedOwnership??null,i=C(t,D,e);for(let n of O)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(L(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||P(e)===t)&&_(e)}else r.isDirectory()&&t!==null&&P(e)===t&&h(e,{recursive:!0,force:!0})}function he(e,t,n={}){let r;try{r=c(e)}catch(e){if(L(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&&P(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{j(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{N(e,n),ee(n,t)}catch(e){try{h(n,{recursive:!0,force:!0})}catch{}throw e}}function N(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))N(x(e,r),x(t,r),n)}finally{n.delete(r)}}else r.isFile()&&o(e,t)}function P(e){let t;try{t=d(x(e,`SKILL.md`),`utf-8`)}catch(e){if(L(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:n}=E(t),r=n.metadata;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r[k];return typeof i==`string`?i:null}function F(e,t=process.cwd()){return A(e),s(C(t,D,e,`SKILL.md`))}function I(e,t=process.cwd()){A(e);let n=C(t,D,e,`SKILL.md`),r;try{r=d(n,`utf-8`)}catch(e){if(L(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:i}=E(r),a=i.metadata;if(!a||typeof a!=`object`||Array.isArray(a))return null;let o=a[k];return typeof o==`string`?o:null}function ve(e,t,n,r,i){for(let a of O){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 L(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 R=`SKILL.md`;function z(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,R),a=xe(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 be(B(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,R),s=xe(o);s.kind===`error`?n.push({path:i,reason:`read-failed`,message:`Failed to check ${o}: ${s.message}`}):s.kind!==`absent`&&be(B(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 B(e,t){let n=x(e,R),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}=E(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 be(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 xe(e){try{return c(e),{kind:`present`}}catch(e){return H(e)&&e.code===`ENOENT`?{kind:`absent`}:{kind:`error`,message:V(e)}}}function Se(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=z(e.sourceDir);return Se(n.errors,{...t,sourceDir:e.sourceDir}),n}function Ce(e){let t={description:`Skill names to exclude from sync`};return e.excludeAlias!==void 0&&(t.alias=e.excludeAlias),t}function G(e){let t={description:`Print install paths and modes`};return e.verbose.alias!==void 0&&(t.alias=e.verbose.alias),t}function K(e,t){return!!e[t]}function we(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(Pe(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`+J({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)||(X(r,o,n.cwd,n.sourceDir),p+=1)}let m=0;for(let e of d)Y(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:t({exclude:e.stringArray(Ce(n))},{unknownKeys:n.unknownKeys}),run(e){i(e,K(e,`verbose`))}}):r({name:`sync`,description:n.descriptions.sync,args:t({exclude:e.stringArray(Ce(n)),verbose:e.boolean(G(n))},{unknownKeys:n.unknownKeys}),run(e){i(e,e.verbose)}})}function Te(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`+J({source:i}))}let c=new Set(a);for(let e of i)c.has(e.frontmatter.name)&&Y(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)Y(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:t({name:e.stringArray(i)},{unknownKeys:n.unknownKeys}),run(e){o(e,K(e,`verbose`))}}):r({name:n.commandNames.add.name,...n.commandNames.add.aliases.length>0?{aliases:n.commandNames.add.aliases}:{},description:n.descriptions.add,args:t({name:e.stringArray(i),verbose:e.boolean(G(n))},{unknownKeys:n.unknownKeys}),run(e){o(e,e.verbose)}})}function Ee(n){return r({name:n.commandNames.remove.name,...n.commandNames.remove.aliases.length>0?{aliases:n.commandNames.remove.aliases}:{},description:n.descriptions.remove,args:t({name:e.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)&&Ae(r,e.name),!X(e.name,i,n.cwd,n.sourceDir)){if(q(e.name,n.cwd))a.info(`${e.name} is installed without a ${k} stamp this CLI recognises; refusing to remove. Remove .agents/skills/${e.name} manually if intended.`);else{let t=new Set(Pe(i,n.cwd,n.sourceDir));a.info(`${e.name} is not installed; nothing to remove.\n`+J({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)X(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 De(e,t,n,r){let i;try{i=I(e,n)}catch(t){return a.warn(`Failed to read ownership for installed skill ${e}: ${Oe(t)}`),`unreadable`}if(i===t)return`installed`;if(i!==null)return`foreign`;if(!F(e,n)){let t=C(n,D,e);return Q(t)&&Z(t,r)?`missing`:q(e,n)?`unstamped`:`not-installed`}return`unstamped`}function Oe(e){return e instanceof Error?e.message:String(e)}function q(e,t){try{return c(C(t,D,e)),!0}catch{return!1}}function ke(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:De(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=De(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:t({},{unknownKeys:n.unknownKeys}),run(e){i(K(e,`json`))}}):r({name:`list`,description:n.descriptions.list,args:t({json:e.boolean({description:`Output as JSON`})},{unknownKeys:n.unknownKeys}),run(e){i(e.json)}})}function Ae(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 J(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(`
|
|
1
|
+
import{g as e,h as t,n}from"./schema-extractor-BI5ypJ21.js";import{n as r}from"./command-BXsTrIgI.js";import{a as i,n as a}from"./logger-CoeDrmRr.js";import"./register-D-aEK58y.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";const ie=/^[a-z0-9]+(-[a-z0-9]+)*$/;function T(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 ${T(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 ${T(r)}`});else for(let[e,n]of Object.entries(r))typeof n!=`string`&&t.push({path:[`metadata`,e],message:`Invalid input: expected string, received ${T(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 E(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}=E(e),r=ae(t);return r.success?{frontmatter:r.data,body:n,rawContent:e}:null}const D=`.agents/skills`,O=[`.claude/skills`],k=`politty-cli`;function A(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;A(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.${k}="{package}:{cli}" to the source SKILL.md so subsequent installs can replace the copy in place.`);let o=C(t,D),s=m(e.sourcePath),c=ue(e.sourcePath),u=[x(M(o),r),...O.map(e=>x(M(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=M(o);j(x(e,r),S(e,c));for(let n of O){let i=M(C(t,n));j(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 j(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 M(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={}){A(e);let r=n.expectedOwnership??null,i=C(t,D,e);for(let n of O)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(L(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||P(e)===t)&&_(e)}else r.isDirectory()&&t!==null&&P(e)===t&&h(e,{recursive:!0,force:!0})}function he(e,t,n={}){let r;try{r=c(e)}catch(e){if(L(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&&P(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{j(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{N(e,n),ee(n,t)}catch(e){try{h(n,{recursive:!0,force:!0})}catch{}throw e}}function N(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))N(x(e,r),x(t,r),n)}finally{n.delete(r)}}else r.isFile()&&o(e,t)}function P(e){let t;try{t=d(x(e,`SKILL.md`),`utf-8`)}catch(e){if(L(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:n}=E(t),r=n.metadata;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r[k];return typeof i==`string`?i:null}function F(e,t=process.cwd()){return A(e),s(C(t,D,e,`SKILL.md`))}function I(e,t=process.cwd()){A(e);let n=C(t,D,e,`SKILL.md`),r;try{r=d(n,`utf-8`)}catch(e){if(L(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))return null;throw e}let{data:i}=E(r),a=i.metadata;if(!a||typeof a!=`object`||Array.isArray(a))return null;let o=a[k];return typeof o==`string`?o:null}function ve(e,t,n,r,i){for(let a of O){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 L(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 R=`SKILL.md`;function z(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,R),a=xe(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 be(B(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,R),s=xe(o);s.kind===`error`?n.push({path:i,reason:`read-failed`,message:`Failed to check ${o}: ${s.message}`}):s.kind!==`absent`&&be(B(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 B(e,t){let n=x(e,R),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}=E(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 be(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 xe(e){try{return c(e),{kind:`present`}}catch(e){return H(e)&&e.code===`ENOENT`?{kind:`absent`}:{kind:`error`,message:V(e)}}}function Se(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=z(e.sourceDir);return Se(n.errors,{...t,sourceDir:e.sourceDir}),n}function Ce(e){let t={description:`Skill names to exclude from sync`};return e.excludeAlias!==void 0&&(t.alias=e.excludeAlias),t}function G(e){let t={description:`Print install paths and modes`};return e.verbose.alias!==void 0&&(t.alias=e.verbose.alias),t}function K(e,t){return!!e[t]}function we(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(Pe(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`+J({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)||(X(r,o,n.cwd,n.sourceDir),p+=1)}let m=0;for(let e of d)Y(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:t({exclude:e.stringArray(Ce(n))},{unknownKeys:n.unknownKeys}),run(e){i(e,K(e,`verbose`))}}):r({name:`sync`,description:n.descriptions.sync,args:t({exclude:e.stringArray(Ce(n)),verbose:e.boolean(G(n))},{unknownKeys:n.unknownKeys}),run(e){i(e,e.verbose)}})}function Te(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`+J({source:i}))}let c=new Set(a);for(let e of i)c.has(e.frontmatter.name)&&Y(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)Y(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:t({name:e.stringArray(i)},{unknownKeys:n.unknownKeys}),run(e){o(e,K(e,`verbose`))}}):r({name:n.commandNames.add.name,...n.commandNames.add.aliases.length>0?{aliases:n.commandNames.add.aliases}:{},description:n.descriptions.add,args:t({name:e.stringArray(i),verbose:e.boolean(G(n))},{unknownKeys:n.unknownKeys}),run(e){o(e,e.verbose)}})}function Ee(n){return r({name:n.commandNames.remove.name,...n.commandNames.remove.aliases.length>0?{aliases:n.commandNames.remove.aliases}:{},description:n.descriptions.remove,args:t({name:e.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)&&Ae(r,e.name),!X(e.name,i,n.cwd,n.sourceDir)){if(q(e.name,n.cwd))a.info(`${e.name} is installed without a ${k} stamp this CLI recognises; refusing to remove. Remove .agents/skills/${e.name} manually if intended.`);else{let t=new Set(Pe(i,n.cwd,n.sourceDir));a.info(`${e.name} is not installed; nothing to remove.\n`+J({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)X(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 De(e,t,n,r){let i;try{i=I(e,n)}catch(t){return a.warn(`Failed to read ownership for installed skill ${e}: ${Oe(t)}`),`unreadable`}if(i===t)return`installed`;if(i!==null)return`foreign`;if(!F(e,n)){let t=C(n,D,e);return Q(t)&&Z(t,r)?`missing`:q(e,n)?`unstamped`:`not-installed`}return`unstamped`}function Oe(e){return e instanceof Error?e.message:String(e)}function q(e,t){try{return c(C(t,D,e)),!0}catch{return!1}}function ke(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:De(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=De(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:t({},{unknownKeys:n.unknownKeys}),run(e){i(K(e,`json`))}}):r({name:`list`,description:n.descriptions.list,args:t({json:e.boolean({description:`Output as JSON`})},{unknownKeys:n.unknownKeys}),run(e){i(e.json)}})}function Ae(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 J(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
2
|
`)}function Y(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.${k}=${JSON.stringify(l)}, expected ${JSON.stringify(t)}.`);let u=I(o,s);if(u!==null&&u!==t)throw Error(`Refusing to install "${o}": owned by ${JSON.stringify(u)}, not ${JSON.stringify(t)}. Check metadata.${k} in .agents/skills/${o}/SKILL.md.`);let d=C(s,D,o),f=Q(d)&&Z(d,n.sourceDir);if(u===null&&q(o,s)&&!f)throw Error(`Refusing to install "${o}": .agents/skills/${o} exists without a ${k} 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 X(e,t,n,r){let o=I(e,n);if(o===null)return je(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.${k} in .agents/skills/${e}/SKILL.md.`);return fe(e,n,{expectedOwnership:t}),a.info(`${i.success} Removed ${e}`),!0}function je(e,t,n){let r=C(t,D,e);if(!Q(r)||!Z(r,n))return!1;for(let n of O){let i=C(t,n,e);Q(i)&&Ne(i,r)&&_(i)}return _(r),!0}function Z(e,t){let n;try{n=p(e)}catch{return!1}let r=b(n)?n:C(y(e),n),i=Me(C(t)),a=Me(r),o=S(i,a);return!(b(o)||o===`..`||o.startsWith(`..${w}`))}function Me(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 Ne(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 Q(e){let t;try{t=c(e)}catch{return!1}return t.isSymbolicLink()?!s(e):!1}function Pe(e,t,n){let r=C(t,D),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=I(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&&Q(c)&&Z(c,n)&&i.push(s.name)}return i}const Fe=[`add`,`install`],Ie=[`remove`,`uninstall`],$={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`},Le=/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/,Re=[`.git`,`package.json`];function ze(e,t){return{sourceDir:e.sourceDir,package:e.package,mode:e.mode,cwd:Ve(e.cwd),excludeAlias:Ue(e.flags?.exclude?.alias),verbose:Ge(e.flags?.verbose,e.globalArgs),json:{disabled:Ke(e.globalArgs,`json`)},commandNames:{add:We(e.commandMap?.add,Fe,`add`),remove:We(e.commandMap?.remove,Ie,`remove`)},unknownKeys:e.unknownKeys??`strip`,descriptionAppend:qe(e.descriptionAppend,t),stamp:`${e.package}:${t}`,descriptions:Be(e.descriptions)}}function Be(e){return{skills:e?.skills??$.skills,sync:e?.sync??$.sync,add:e?.add??$.add,remove:e?.remove??$.remove,list:e?.list??$.list}}function Ve(e){if(e!==void 0)return C(e);let t=process.cwd();return He(t)??t}function He(e){let t=C(e);for(;;){for(let e of Re)if(s(C(t,e)))return t;let e=y(t);if(e===t)return null;t=e}}function Ue(e){if(e!==!1)return typeof e==`string`?e:`x`}function We(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=>!Le.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 Ge(e,t){return{alias:e?.alias===!1?void 0:e?.alias??`v`,disabled:Ke(t,`verbose`)}}function Ke(e,t){return e?n(e).fields.some(e=>e.name===t&&e.named&&e.type===`boolean`):!1}function qe(e,t){return e===!1?!1:typeof e==`string`?e:`Manage agent skills with \`${t} skills <add|sync|remove|list>\`.`}const Je=[`parse-failed`,`name-mismatch`,`read-failed`,`missing-source`];function Ye(e,t){if(e.subCommands&&Object.hasOwn(e.subCommands,`skills`))throw Error(`withSkillCommand: command "${e.name}" already defines a "skills" subcommand.`);let n=ze(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:we(n),[i]:Te(n),[a]:Ee(n),list:ke(n)}});return{...e,description:Xe(e.description,n.descriptionAppend),subCommands:{...e.subCommands,skills:c}}}function Xe(e,t){return t===!1||t===``?e:e?e.endsWith(t)?e:`${e}\n\n${t}`:t}export{k as OWNERSHIP_METADATA_KEY,Je as SCAN_ERROR_REASONS,F as hasInstalledSkill,le as installSkill,E as parseFrontmatter,ce as parseSkillMd,I as readInstalledOwnership,z as scanSourceDir,fe as uninstallSkill,Ye as withSkillCommand};
|
|
@@ -328,6 +328,24 @@ interface BaseArgMeta<TValue = unknown> {
|
|
|
328
328
|
* ```
|
|
329
329
|
*/
|
|
330
330
|
env?: string | string[];
|
|
331
|
+
/**
|
|
332
|
+
* Treat this global option's value(s) as env file path(s) and load them into
|
|
333
|
+
* `process.env` before any `env` fallback is applied, like Node.js
|
|
334
|
+
* `--env-file`. `true` fails when a file does not exist; `"if-exists"`
|
|
335
|
+
* skips a missing file, like `--env-file-if-exists`.
|
|
336
|
+
*
|
|
337
|
+
* Only meaningful on a `globalArgs` option whose value is a string or an array of
|
|
338
|
+
* strings. Files load in option declaration order, then in the order given on
|
|
339
|
+
* the command line (outer command first); a later file overrides an earlier
|
|
340
|
+
* one, and variables already set in the environment are never overridden.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* "env-file": arg(z.string().array().optional(), { alias: "e", envFile: true }),
|
|
345
|
+
* "env-file-if-exists": arg(z.string().array().optional(), { envFile: "if-exists" }),
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
envFile?: boolean | "if-exists";
|
|
331
349
|
/** Completion configuration for shell tab-completion */
|
|
332
350
|
completion?: CompletionMeta;
|
|
333
351
|
/**
|
|
@@ -573,6 +591,8 @@ interface ResolvedFieldMeta {
|
|
|
573
591
|
* If an array, earlier entries take priority.
|
|
574
592
|
*/
|
|
575
593
|
env?: string | string[] | undefined;
|
|
594
|
+
/** Load the value(s) as env file path(s); `"if-exists"` skips a missing file */
|
|
595
|
+
envFile?: boolean | "if-exists" | undefined;
|
|
576
596
|
/** Whether this argument is required */
|
|
577
597
|
required: boolean;
|
|
578
598
|
/** Default value if any */
|
package/dist/{with-completion-command-BhjWVp1l.d.ts → with-completion-command-BkTioGwX.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as ArgMeta, R as UnknownKeysMode, a as ArgsSchema, at as DynamicCompletionResolver, r as AnyCommand, tt as ResolvedExpandCandidate } from "./types-
|
|
1
|
+
import { H as ArgMeta, R as UnknownKeysMode, a as ArgsSchema, at as DynamicCompletionResolver, r as AnyCommand, tt as ResolvedExpandCandidate } from "./types-D3ubanZt.js";
|
|
2
2
|
/** Runtime brand distinguishing internal descriptors from library schemas. */
|
|
3
3
|
declare const INTERNAL_ARGS_BRAND = "__polittyInternalArgs";
|
|
4
4
|
type InternalFieldKind = "string" | "boolean" | "enum" | "string-array";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{g as e,h as t}from"./schema-extractor-
|
|
1
|
+
import{g as e,h as t}from"./schema-extractor-BI5ypJ21.js";import{n}from"./command-BXsTrIgI.js";import{s as r}from"./subcommand-router-40vA6Mka.js";import{t as i}from"./schema-Bz8oC0xQ.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=t({shell:e.optionalEnum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell type (bash, zsh, or fish)`,placeholder:`SHELL`}),instructions:e.boolean({alias:`i`,description:`Show installation instructions`}),loader:e.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:e.boolean({description:`Write the completion script to its on-disk cache (bash/zsh) or autoload location (fish) instead of printing it.`}),static:e.boolean({description:`Generate the legacy static completion script with command metadata baked in.`}),dispatcher:e.boolean({description:`Generate the runtime dispatcher completion script. This is the default.`}),worker:e.boolean({description:`Generate an internal static worker artifact for dispatcher mode.`})}),g=t({shell:e.enum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell to refresh`,placeholder:`SHELL`}),target:e.optionalString({positional:!0,description:`Existing politty-generated completion file to refresh`,placeholder:`TARGET`}),static:e.boolean({description:`Refresh using the legacy static completion script mode.`}),worker:e.boolean({description:`Refresh an internal static worker completion script.`})}),_=t({shell:e.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-
|
|
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=t({shell:e.optionalEnum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell type (bash, zsh, or fish)`,placeholder:`SHELL`}),instructions:e.boolean({alias:`i`,description:`Show installation instructions`}),loader:e.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:e.boolean({description:`Write the completion script to its on-disk cache (bash/zsh) or autoload location (fish) instead of printing it.`}),static:e.boolean({description:`Generate the legacy static completion script with command metadata baked in.`}),dispatcher:e.boolean({description:`Generate the runtime dispatcher completion script. This is the default.`}),worker:e.boolean({description:`Generate an internal static worker artifact for dispatcher mode.`})}),g=t({shell:e.enum([`bash`,`zsh`,`fish`],{positional:!0,description:`Shell to refresh`,placeholder:`SHELL`}),target:e.optionalString({positional:!0,description:`Existing politty-generated completion file to refresh`,placeholder:`TARGET`}),static:e.boolean({description:`Refresh using the legacy static completion script mode.`}),worker:e.boolean({description:`Refresh an internal static worker completion script.`})}),_=t({shell:e.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-Df9_25sa.js`).then(e=>e.createCompletionCommand(f,a,o,d))),__complete:r(n({name:`__complete`,args:i,run(){}}),()=>import(`./dynamic-plXaUNoz.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-Df9_25sa.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-Df9_25sa.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};
|