@politty/valibot 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +1 -1
- package/dist/argv-parser-CHIJ1BrN.js +1 -0
- package/dist/cli-main-B9hGaaqw.js +1 -0
- package/dist/{cli-main-prrHozEB.js → cli-main-CNiI0QME.js} +2 -2
- package/dist/cli-run-6Crg69qY.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/compile-cache.js +1 -1
- package/dist/{completion-BHfC_VJz.js → completion-BcLMOWYg.js} +1 -1
- package/dist/completion-RQU_Sx7K.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 +13 -13
- package/dist/{dynamic-F2u9XV-p.js → dynamic-TRZXiiHr.js} +2 -2
- package/dist/dynamic-Wt-f3fbl.js +1 -0
- package/dist/{import-meta-resolve-DgKm4LYW.js → import-meta-resolve-DQ_owo_7.js} +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +1 -1
- package/dist/{prompt-CNXUBjZA.js → prompt-Bs_O6SmK.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 +6 -2
- package/dist/prompt.js +1 -1
- package/dist/runner-DQixL-ZF.js +1 -0
- package/dist/runner-Gm-z60xj.js +33 -0
- package/dist/{schema-CmhHwi3R.js → schema-C20skX3E.js} +1 -1
- package/dist/schema-extractor-lB6-WHOF.js +1 -0
- package/dist/skill.d.ts +1 -1
- package/dist/skill.js +1 -1
- package/dist/{subcommand-router-iqmWGZyU.js → subcommand-router-40vA6Mka.js} +1 -1
- package/dist/{types-Dhar1ua6.d.ts → types-DtQ-Zt3n.d.ts} +17 -7
- package/dist/{with-completion-command-B2f3ns8A.js → with-completion-command-Dot_GmfF.js} +2 -2
- package/dist/{with-completion-command-CARvhYvv.d.ts → with-completion-command-QHQsd0Zt.d.ts} +1 -1
- package/package.json +2 -2
- package/dist/argv-parser-Cz8IED8W.js +0 -1
- package/dist/cli-main-Dt2zFNTU.js +0 -1
- package/dist/cli-run-uv2kYRV8.js +0 -1
- package/dist/completion-CQFm_cbd.js +0 -1
- package/dist/dynamic-CpL0yvfn.js +0 -1
- package/dist/runner-Bc0bI0Eh.js +0 -33
- package/dist/runner-C9Wy5o8a.js +0 -1
- package/dist/schema-extractor-BkbKiMq_.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{builtinModules as e}from"node:module";import t,{realpathSync as n,statSync as r}from"node:fs";import i from"node:path";import{fileURLToPath as a,pathToFileURL as o}from"node:url";import{format as s,inspect as c}from"node:util";import l from"node:assert";import u from"node:process";import d from"node:v8";const f={}.hasOwnProperty,ee=/^([A-Z][a-z\d]*)+$/,te=/* @__PURE__ */ new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),p={};function m(e,t=`and`){return e.length<3?e.join(` ${t} `):`${e.slice(0,-1).join(`, `)}, ${t} ${e[e.length-1]}`}const h=/* @__PURE__ */ new Map;let g;p.ERR_INVALID_ARG_TYPE=_(`ERR_INVALID_ARG_TYPE`,(e,t,n)=>{l.ok(typeof e==`string`,`'name' must be a string`),Array.isArray(t)||(t=[t]);let r=`The `;if(e.endsWith(` argument`))r+=`${e} `;else{let t=e.includes(`.`)?`property`:`argument`;r+=`"${e}" ${t} `}r+=`must be `;let i=[],a=[],o=[];for(let e of t)l.ok(typeof e==`string`,`All expected entries have to be of type string`),te.has(e)?i.push(e.toLowerCase()):ee.exec(e)===null?(l.ok(e!==`object`,`The value "object" should be written as "Object"`),o.push(e)):a.push(e);if(a.length>0){let e=i.indexOf(`object`);e!==-1&&(i.slice(e,1),a.push(`Object`))}return i.length>0&&(r+=`${i.length>1?`one of type`:`of type`} ${m(i,`or`)}`,(a.length>0||o.length>0)&&(r+=` or `)),a.length>0&&(r+=`an instance of ${m(a,`or`)}`,o.length>0&&(r+=` or `)),o.length>0&&(o.length>1?r+=`one of ${m(o,`or`)}`:(o[0].toLowerCase()!==o[0]&&(r+=`an `),r+=`${o[0]}`)),r+=`. Received ${b(n)}`,r},TypeError),p.ERR_INVALID_MODULE_SPECIFIER=_(`ERR_INVALID_MODULE_SPECIFIER`,(e,t,n=void 0)=>`Invalid module "${e}" ${t}${n?` imported from ${n}`:``}`,TypeError),p.ERR_INVALID_PACKAGE_CONFIG=_(`ERR_INVALID_PACKAGE_CONFIG`,(e,t,n)=>`Invalid package config ${e}${t?` while importing ${t}`:``}${n?`. ${n}`:``}`,Error),p.ERR_INVALID_PACKAGE_TARGET=_(`ERR_INVALID_PACKAGE_TARGET`,(e,t,n,r=!1,i=void 0)=>{let a=typeof n==`string`&&!r&&n.length>0&&!n.startsWith(`./`);return t===`.`?(l.ok(r===!1),`Invalid "exports" main target ${JSON.stringify(n)} defined in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`):`Invalid "${r?`imports`:`exports`}" target ${JSON.stringify(n)} defined for '${t}' in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`},Error),p.ERR_MODULE_NOT_FOUND=_(`ERR_MODULE_NOT_FOUND`,(e,t,n=!1)=>`Cannot find ${n?`module`:`package`} '${e}' imported from ${t}`,Error),p.ERR_NETWORK_IMPORT_DISALLOWED=_(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error),p.ERR_PACKAGE_IMPORT_NOT_DEFINED=_(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(e,t,n)=>`Package import specifier "${e}" is not defined${t?` in package ${t}package.json`:``} imported from ${n}`,TypeError),p.ERR_PACKAGE_PATH_NOT_EXPORTED=_(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(e,t,n=void 0)=>t===`.`?`No "exports" main defined in ${e}package.json${n?` imported from ${n}`:``}`:`Package subpath '${t}' is not defined by "exports" in ${e}package.json${n?` imported from ${n}`:``}`,Error),p.ERR_UNSUPPORTED_DIR_IMPORT=_(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),p.ERR_UNSUPPORTED_RESOLVE_REQUEST=_(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),p.ERR_UNKNOWN_FILE_EXTENSION=_(`ERR_UNKNOWN_FILE_EXTENSION`,(e,t)=>`Unknown file extension "${e}" for ${t}`,TypeError),p.ERR_INVALID_ARG_VALUE=_(`ERR_INVALID_ARG_VALUE`,(e,t,n=`is invalid`)=>{let r=c(t);return r.length>128&&(r=`${r.slice(0,128)}...`),`The ${e.includes(`.`)?`property`:`argument`} '${e}' ${n}. Received ${r}`},TypeError);function _(e,t,n){return h.set(e,t),ne(n,e)}function ne(e,t){return n;function n(...n){let r=Error.stackTraceLimit;v()&&(Error.stackTraceLimit=0);let i=new e;v()&&(Error.stackTraceLimit=r);let a=ie(t,n,i);return Object.defineProperties(i,{message:{value:a,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),y(i),i.code=t,i}}function v(){try{if(d.startupSnapshot.isBuildingSnapshot())return!1}catch{}let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):f.call(e,`writable`)&&e.writable!==void 0?e.writable:e.set!==void 0}function re(e){let t=`__node_internal_`+e.name;return Object.defineProperty(e,"name",{value:t}),e}const y=re(function(e){let t=v();return t&&(g=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(e),t&&(Error.stackTraceLimit=g),e});function ie(e,t,n){let r=h.get(e);if(l.ok(r!==void 0,"expected `message` to be found"),typeof r==`function`)return l.ok(r.length<=t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${r.length}).`),Reflect.apply(r,n,t);let i=/%[dfijoOs]/g,a=0;for(;i.exec(r)!==null;)a++;return l.ok(a===t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${a}).`),t.length===0?r:(t.unshift(r),Reflect.apply(s,null,t))}function b(e){if(e==null)return String(e);if(typeof e==`function`&&e.name)return`function ${e.name}`;if(typeof e==`object`)return e.constructor&&e.constructor.name?`an instance of ${e.constructor.name}`:`${c(e,{depth:-1})}`;let t=c(e,{colors:!1});return t.length>28&&(t=`${t.slice(0,25)}...`),`type ${typeof e} (${t})`}const x={}.hasOwnProperty,{ERR_INVALID_PACKAGE_CONFIG:ae}=p,S=/* @__PURE__ */ new Map;function C(e,{base:n,specifier:r}){let o=S.get(e);if(o)return o;let s;try{s=t.readFileSync(i.toNamespacedPath(e),`utf8`)}catch(e){let t=e;if(t.code!==`ENOENT`)throw t}let c={exists:!1,pjsonPath:e,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(s!==void 0){let t;try{t=JSON.parse(s)}catch(t){let i=t,o=new ae(e,(n?`"${r}" from `:``)+a(n||r),i.message);throw o.cause=i,o}c.exists=!0,x.call(t,`name`)&&typeof t.name==`string`&&(c.name=t.name),x.call(t,`main`)&&typeof t.main==`string`&&(c.main=t.main),x.call(t,`exports`)&&(c.exports=t.exports),x.call(t,`imports`)&&(c.imports=t.imports),x.call(t,`type`)&&(t.type===`commonjs`||t.type===`module`)&&(c.type=t.type)}return S.set(e,c),c}function w(e){let t=new URL(`package.json`,e);for(;!t.pathname.endsWith(`node_modules/package.json`);){let n=C(a(t),{specifier:e});if(n.exists)return n;let r=t;if(t=new URL(`../package.json`,t),t.pathname===r.pathname)break}return{pjsonPath:a(t),exists:!1,type:`none`}}function T(e){return w(e).type}const{ERR_UNKNOWN_FILE_EXTENSION:oe}=p,se={}.hasOwnProperty,ce={__proto__:null,".cjs":`commonjs`,".js":`module`,".json":`json`,".mjs":`module`};function le(e){return e&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(e)?`module`:e===`application/json`?`json`:null}const E={__proto__:null,"data:":ue,"file:":fe,"http:":D,"https:":D,"node:"(){return`builtin`}};function ue(e){let{1:t}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(e.pathname)||[null,null,null];return le(t)}function de(e){let t=e.pathname,n=t.length;for(;n--;){let e=t.codePointAt(n);if(e===47)return``;if(e===46)return t.codePointAt(n-1)===47?``:t.slice(n)}return``}function fe(e,t,n){let r=de(e);if(r===`.js`){let t=T(e);return t===`none`?`commonjs`:t}if(r===``){let t=T(e);return t===`none`||t===`commonjs`?`commonjs`:`module`}let i=ce[r];if(i)return i;if(n)return;let o=a(e);throw new oe(r,o)}function D(){}function O(e,t){let n=e.protocol;return se.call(E,n)&&E[n](e,t,!0)||null}const{ERR_INVALID_ARG_VALUE:pe}=p,k=Object.freeze([`node`,`import`]),me=new Set(k);function he(){return k}function ge(){return me}function A(e){if(e!==void 0&&e!==he()){if(!Array.isArray(e))throw new pe(`conditions`,e,`expected an array`);return new Set(e)}return ge()}const j=RegExp.prototype[Symbol.replace],{ERR_NETWORK_IMPORT_DISALLOWED:M,ERR_INVALID_MODULE_SPECIFIER:N,ERR_INVALID_PACKAGE_CONFIG:P,ERR_INVALID_PACKAGE_TARGET:_e,ERR_MODULE_NOT_FOUND:F,ERR_PACKAGE_IMPORT_NOT_DEFINED:I,ERR_PACKAGE_PATH_NOT_EXPORTED:ve,ERR_UNSUPPORTED_DIR_IMPORT:ye,ERR_UNSUPPORTED_RESOLVE_REQUEST:L}=p,R={}.hasOwnProperty,z=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,B=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,be=/^\.|%|\\/,V=/\*/g,xe=/%2f|%5c/i,H=/* @__PURE__ */ new Set,Se=/[/\\]{2}/;function U(e,t,n,r,i,o,s){if(u.noDeprecation)return;let c=a(r),l=Se.exec(s?e:t)!==null;u.emitWarning(`Use of deprecated ${l?`double slash`:`leading or trailing slash matching`} resolving "${e}" for module request "${t}" ${t===n?``:`matched to "${n}" `}in the "${i?`imports`:`exports`}" field module resolution of the package at ${c}${o?` imported from ${a(o)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function W(e,t,n,r){if(u.noDeprecation||O(e,{parentURL:n.href})!==`module`)return;let o=a(e.href),s=a(new URL(`.`,t)),c=a(n);r?i.resolve(s,r)!==o&&u.emitWarning(`Package ${s} has a "main" field set to "${r}", excluding the full filename and extension to the resolved file at "${o.slice(s.length)}", imported from ${c}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):u.emitWarning(`No "main" or "exports" field defined in the package.json for ${s} resolving the main entry point "${o.slice(s.length)}", imported from ${c}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function G(e){try{return r(e)}catch{}}function K(e){let t=r(e,{throwIfNoEntry:!1});return(t?t.isFile():void 0)??!1}function Ce(e,t,n){let r;if(t.main!==void 0){if(r=new URL(t.main,e),K(r))return r;let i=[`./${t.main}.js`,`./${t.main}.json`,`./${t.main}.node`,`./${t.main}/index.js`,`./${t.main}/index.json`,`./${t.main}/index.node`],a=-1;for(;++a<i.length&&(r=new URL(i[a],e),!K(r));)r=void 0;if(r)return W(r,e,n,t.main),r}let i=[`./index.js`,`./index.json`,`./index.node`],o=-1;for(;++o<i.length&&(r=new URL(i[o],e),!K(r));)r=void 0;if(r)return W(r,e,n,t.main),r;throw new F(a(new URL(`.`,e)),a(n))}function we(e,t,r){if(xe.exec(e.pathname)!==null)throw new N(e.pathname,`must not include encoded "/" or "\\" characters`,a(t));let s;try{s=a(e)}catch(n){let r=n;throw Object.defineProperty(r,"input",{value:String(e)}),Object.defineProperty(r,"module",{value:String(t)}),r}let c=G(s.endsWith(`/`)?s.slice(-1):s);if(c&&c.isDirectory()){let n=new ye(s,a(t));throw n.url=String(e),n}if(!c||!c.isFile()){let n=new F(s||e.pathname,t&&a(t),!0);throw n.url=String(e),n}if(!r){let t=n(s),{search:r,hash:a}=e;e=o(t+(s.endsWith(i.sep)?`/`:``)),e.search=r,e.hash=a}return e}function Te(e,t,n){return new I(e,t&&a(new URL(`.`,t)),a(n))}function q(e,t,n){return new ve(a(new URL(`.`,t)),e,n&&a(n))}function Ee(e,t,n,r,i){let o=`request is not a valid match in pattern "${t}" for the "${r?`imports`:`exports`}" resolution of ${a(n)}`;throw new N(e,o,i&&a(i))}function J(e,t,n,r,i){return t=typeof t==`object`&&t?JSON.stringify(t,null,``):`${t}`,new _e(a(new URL(`.`,n)),e,t,r,i&&a(i))}function De(e,t,n,r,i,a,o,s,c){if(t!==``&&!a&&e[e.length-1]!==`/`)throw J(n,e,r,o,i);if(!e.startsWith(`./`)){if(o&&!e.startsWith(`../`)&&!e.startsWith(`/`)){let n=!1;try{new URL(e),n=!0}catch{}if(!n)return Q(a?j.call(V,e,()=>t):e+t,r,c)}throw J(n,e,r,o,i)}if(z.exec(e.slice(2))!==null){if(B.exec(e.slice(2))===null){if(!s){let s=a?n.replace(`*`,()=>t):n+t;U(a?j.call(V,e,()=>t):e,s,n,r,o,i,!0)}}else throw J(n,e,r,o,i)}let l=new URL(e,r),u=l.pathname,d=new URL(`.`,r).pathname;if(!u.startsWith(d))throw J(n,e,r,o,i);if(t===``)return l;if(z.exec(t)!==null){let c=a?n.replace(`*`,()=>t):n+t;B.exec(t)===null?s||U(a?j.call(V,e,()=>t):e,c,n,r,o,i,!1):Ee(c,n,r,o,i)}return a?new URL(j.call(V,l.href,()=>t)):new URL(t,l)}function Oe(e){let t=Number(e);return`${t}`===e&&t>=0&&t<4294967295}function Y(e,t,n,r,i,o,s,c,l){if(typeof t==`string`)return De(t,n,r,e,i,o,s,c,l);if(Array.isArray(t)){let a=t;if(a.length===0)return null;let u,d=-1;for(;++d<a.length;){let t=a[d],f;try{f=Y(e,t,n,r,i,o,s,c,l)}catch(e){let t=e;if(u=t,t.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw e}if(f!==void 0){if(f===null){u=null;continue}return f}}if(u==null)return null;throw u}if(typeof t==`object`&&t){let u=Object.getOwnPropertyNames(t),d=-1;for(;++d<u.length;){let t=u[d];if(Oe(t))throw new P(a(e),i,`"exports" cannot contain numeric property keys.`)}for(d=-1;++d<u.length;){let a=u[d];if(a==="default"||l&&l.has(a)){let u=t[a],d=Y(e,u,n,r,i,o,s,c,l);if(d===void 0)continue;return d}}return null}if(t===null)return null;throw J(r,t,e,s,i)}function ke(e,t,n){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let r=Object.getOwnPropertyNames(e),i=!1,o=0,s=-1;for(;++s<r.length;){let e=r[s],c=e===``||e[0]!==`.`;if(o++===0)i=c;else if(i!==c)throw new P(a(t),n,`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return i}function Ae(e,t,n){if(u.noDeprecation)return;let r=a(t);H.has(r+`|`+e)||(H.add(r+`|`+e),u.emitWarning(`Use of deprecated trailing slash pattern mapping "${e}" in the "exports" field module resolution of the package at ${r}${n?` imported from ${a(n)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function X(e,t,n,r,i){let a=n.exports;if(ke(a,e,r)&&(a={".":a}),R.call(a,t)&&!t.includes(`*`)&&!t.endsWith(`/`)){let n=a[t],o=Y(e,n,``,t,r,!1,!1,!1,i);if(o==null)throw q(t,e,r);return o}let o=``,s=``,c=Object.getOwnPropertyNames(a),l=-1;for(;++l<c.length;){let n=c[l],i=n.indexOf(`*`);if(i!==-1&&t.startsWith(n.slice(0,i))){t.endsWith(`/`)&&Ae(t,e,r);let a=n.slice(i+1);t.length>=n.length&&t.endsWith(a)&&Z(o,n)===1&&n.lastIndexOf(`*`)===i&&(o=n,s=t.slice(i,t.length-a.length))}}if(o){let n=a[o],c=Y(e,n,s,o,r,!0,!1,t.endsWith(`/`),i);if(c==null)throw q(t,e,r);return c}throw q(t,e,r)}function Z(e,t){let n=e.indexOf(`*`),r=t.indexOf(`*`),i=n===-1?e.length:n+1,a=r===-1?t.length:r+1;return i>a?-1:a>i||n===-1?1:r===-1||e.length>t.length?-1:+(t.length>e.length)}function je(e,t,n){if(e===`#`||e.startsWith(`#/`)||e.endsWith(`/`))throw new N(e,`is not a valid internal imports specifier name`,a(t));let r,i=w(t);if(i.exists){r=o(i.pjsonPath);let a=i.imports;if(a){if(R.call(a,e)&&!e.includes(`*`)){let i=Y(r,a[e],``,e,t,!1,!0,!1,n);if(i!=null)return i}else{let i=``,o=``,s=Object.getOwnPropertyNames(a),c=-1;for(;++c<s.length;){let t=s[c],n=t.indexOf(`*`);if(n!==-1&&e.startsWith(t.slice(0,-1))){let r=t.slice(n+1);e.length>=t.length&&e.endsWith(r)&&Z(i,t)===1&&t.lastIndexOf(`*`)===n&&(i=t,o=e.slice(n,e.length-r.length))}}if(i){let e=a[i],s=Y(r,e,o,i,t,!0,!0,!1,n);if(s!=null)return s}}}}throw Te(e,r,t)}function Me(e,t){let n=e.indexOf(`/`),r=!0,i=!1;e[0]===`@`&&(i=!0,n===-1||e.length===0?r=!1:n=e.indexOf(`/`,n+1));let o=n===-1?e:e.slice(0,n);if(be.exec(o)!==null&&(r=!1),!r)throw new N(e,`is not a valid package name`,a(t));return{packageName:o,packageSubpath:`.`+(n===-1?``:e.slice(n)),isScoped:i}}function Q(t,n,r){if(e.includes(t))return new URL(`node:`+t);let{packageName:i,packageSubpath:s,isScoped:c}=Me(t,n),l=w(n);
|
|
1
|
+
import{builtinModules as e}from"node:module";import t,{realpathSync as n,statSync as r}from"node:fs";import i from"node:path";import{fileURLToPath as a,pathToFileURL as o}from"node:url";import{format as s,inspect as c}from"node:util";import l from"node:assert";import u from"node:process";import d from"node:v8";const f={}.hasOwnProperty,ee=/^([A-Z][a-z\d]*)+$/,te=/* @__PURE__ */ new Set([`string`,`function`,`number`,`object`,`Function`,`Object`,`boolean`,`bigint`,`symbol`]),p={};function m(e,t=`and`){return e.length<3?e.join(` ${t} `):`${e.slice(0,-1).join(`, `)}, ${t} ${e[e.length-1]}`}const h=/* @__PURE__ */ new Map;let g;p.ERR_INVALID_ARG_TYPE=_(`ERR_INVALID_ARG_TYPE`,(e,t,n)=>{l.ok(typeof e==`string`,`'name' must be a string`),Array.isArray(t)||(t=[t]);let r=`The `;if(e.endsWith(` argument`))r+=`${e} `;else{let t=e.includes(`.`)?`property`:`argument`;r+=`"${e}" ${t} `}r+=`must be `;let i=[],a=[],o=[];for(let e of t)l.ok(typeof e==`string`,`All expected entries have to be of type string`),te.has(e)?i.push(e.toLowerCase()):ee.exec(e)===null?(l.ok(e!==`object`,`The value "object" should be written as "Object"`),o.push(e)):a.push(e);if(a.length>0){let e=i.indexOf(`object`);e!==-1&&(i.slice(e,1),a.push(`Object`))}return i.length>0&&(r+=`${i.length>1?`one of type`:`of type`} ${m(i,`or`)}`,(a.length>0||o.length>0)&&(r+=` or `)),a.length>0&&(r+=`an instance of ${m(a,`or`)}`,o.length>0&&(r+=` or `)),o.length>0&&(o.length>1?r+=`one of ${m(o,`or`)}`:(o[0].toLowerCase()!==o[0]&&(r+=`an `),r+=`${o[0]}`)),r+=`. Received ${b(n)}`,r},TypeError),p.ERR_INVALID_MODULE_SPECIFIER=_(`ERR_INVALID_MODULE_SPECIFIER`,(e,t,n=void 0)=>`Invalid module "${e}" ${t}${n?` imported from ${n}`:``}`,TypeError),p.ERR_INVALID_PACKAGE_CONFIG=_(`ERR_INVALID_PACKAGE_CONFIG`,(e,t,n)=>`Invalid package config ${e}${t?` while importing ${t}`:``}${n?`. ${n}`:``}`,Error),p.ERR_INVALID_PACKAGE_TARGET=_(`ERR_INVALID_PACKAGE_TARGET`,(e,t,n,r=!1,i=void 0)=>{let a=typeof n==`string`&&!r&&n.length>0&&!n.startsWith(`./`);return t===`.`?(l.ok(r===!1),`Invalid "exports" main target ${JSON.stringify(n)} defined in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`):`Invalid "${r?`imports`:`exports`}" target ${JSON.stringify(n)} defined for '${t}' in the package config ${e}package.json${i?` imported from ${i}`:``}${a?`; targets must start with "./"`:``}`},Error),p.ERR_MODULE_NOT_FOUND=_(`ERR_MODULE_NOT_FOUND`,(e,t,n=!1)=>`Cannot find ${n?`module`:`package`} '${e}' imported from ${t}`,Error),p.ERR_NETWORK_IMPORT_DISALLOWED=_(`ERR_NETWORK_IMPORT_DISALLOWED`,`import of '%s' by %s is not supported: %s`,Error),p.ERR_PACKAGE_IMPORT_NOT_DEFINED=_(`ERR_PACKAGE_IMPORT_NOT_DEFINED`,(e,t,n)=>`Package import specifier "${e}" is not defined${t?` in package ${t}package.json`:``} imported from ${n}`,TypeError),p.ERR_PACKAGE_PATH_NOT_EXPORTED=_(`ERR_PACKAGE_PATH_NOT_EXPORTED`,(e,t,n=void 0)=>t===`.`?`No "exports" main defined in ${e}package.json${n?` imported from ${n}`:``}`:`Package subpath '${t}' is not defined by "exports" in ${e}package.json${n?` imported from ${n}`:``}`,Error),p.ERR_UNSUPPORTED_DIR_IMPORT=_(`ERR_UNSUPPORTED_DIR_IMPORT`,`Directory import '%s' is not supported resolving ES modules imported from %s`,Error),p.ERR_UNSUPPORTED_RESOLVE_REQUEST=_(`ERR_UNSUPPORTED_RESOLVE_REQUEST`,`Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.`,TypeError),p.ERR_UNKNOWN_FILE_EXTENSION=_(`ERR_UNKNOWN_FILE_EXTENSION`,(e,t)=>`Unknown file extension "${e}" for ${t}`,TypeError),p.ERR_INVALID_ARG_VALUE=_(`ERR_INVALID_ARG_VALUE`,(e,t,n=`is invalid`)=>{let r=c(t);return r.length>128&&(r=`${r.slice(0,128)}...`),`The ${e.includes(`.`)?`property`:`argument`} '${e}' ${n}. Received ${r}`},TypeError);function _(e,t,n){return h.set(e,t),ne(n,e)}function ne(e,t){return n;function n(...n){let r=Error.stackTraceLimit;v()&&(Error.stackTraceLimit=0);let i=new e;v()&&(Error.stackTraceLimit=r);let a=ie(t,n,i);return Object.defineProperties(i,{message:{value:a,enumerable:!1,writable:!0,configurable:!0},toString:{value(){return`${this.name} [${t}]: ${this.message}`},enumerable:!1,writable:!0,configurable:!0}}),y(i),i.code=t,i}}function v(){try{if(d.startupSnapshot.isBuildingSnapshot())return!1}catch{}let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):f.call(e,`writable`)&&e.writable!==void 0?e.writable:e.set!==void 0}function re(e){let t=`__node_internal_`+e.name;return Object.defineProperty(e,"name",{value:t}),e}const y=re(function(e){let t=v();return t&&(g=Error.stackTraceLimit,Error.stackTraceLimit=1/0),Error.captureStackTrace(e),t&&(Error.stackTraceLimit=g),e});function ie(e,t,n){let r=h.get(e);if(l.ok(r!==void 0,"expected `message` to be found"),typeof r==`function`)return l.ok(r.length<=t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${r.length}).`),Reflect.apply(r,n,t);let i=/%[dfijoOs]/g,a=0;for(;i.exec(r)!==null;)a++;return l.ok(a===t.length,`Code: ${e}; The provided arguments length (${t.length}) does not match the required ones (${a}).`),t.length===0?r:(t.unshift(r),Reflect.apply(s,null,t))}function b(e){if(e==null)return String(e);if(typeof e==`function`&&e.name)return`function ${e.name}`;if(typeof e==`object`)return e.constructor&&e.constructor.name?`an instance of ${e.constructor.name}`:`${c(e,{depth:-1})}`;let t=c(e,{colors:!1});return t.length>28&&(t=`${t.slice(0,25)}...`),`type ${typeof e} (${t})`}const x={}.hasOwnProperty,{ERR_INVALID_PACKAGE_CONFIG:ae}=p,S=/* @__PURE__ */ new Map;function C(e,{base:n,specifier:r}){let o=S.get(e);if(o)return o;let s;try{s=t.readFileSync(i.toNamespacedPath(e),`utf8`)}catch(e){let t=e;if(t.code!==`ENOENT`)throw t}let c={exists:!1,pjsonPath:e,main:void 0,name:void 0,type:`none`,exports:void 0,imports:void 0};if(s!==void 0){let t;try{t=JSON.parse(s)}catch(t){let i=t,o=new ae(e,(n?`"${r}" from `:``)+a(n||r),i.message);throw o.cause=i,o}c.exists=!0,x.call(t,`name`)&&typeof t.name==`string`&&(c.name=t.name),x.call(t,`main`)&&typeof t.main==`string`&&(c.main=t.main),x.call(t,`exports`)&&(c.exports=t.exports),x.call(t,`imports`)&&(c.imports=t.imports),x.call(t,`type`)&&(t.type===`commonjs`||t.type===`module`)&&(c.type=t.type)}return S.set(e,c),c}function w(e){let t=new URL(`package.json`,e);for(;!t.pathname.endsWith(`node_modules/package.json`);){let n=C(a(t),{specifier:e});if(n.exists)return n;let r=t;if(t=new URL(`../package.json`,t),t.pathname===r.pathname)break}return{pjsonPath:a(t),exists:!1,type:`none`}}function T(e){return w(e).type}const{ERR_UNKNOWN_FILE_EXTENSION:oe}=p,se={}.hasOwnProperty,ce={__proto__:null,".cjs":`commonjs`,".js":`module`,".json":`json`,".mjs":`module`};function le(e){return e&&/\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(e)?`module`:e===`application/json`?`json`:null}const E={__proto__:null,"data:":ue,"file:":fe,"http:":D,"https:":D,"node:"(){return`builtin`}};function ue(e){let{1:t}=/^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(e.pathname)||[null,null,null];return le(t)}function de(e){let t=e.pathname,n=t.length;for(;n--;){let e=t.codePointAt(n);if(e===47)return``;if(e===46)return t.codePointAt(n-1)===47?``:t.slice(n)}return``}function fe(e,t,n){let r=de(e);if(r===`.js`){let t=T(e);return t===`none`?`commonjs`:t}if(r===``){let t=T(e);return t===`none`||t===`commonjs`?`commonjs`:`module`}let i=ce[r];if(i)return i;if(n)return;let o=a(e);throw new oe(r,o)}function D(){}function O(e,t){let n=e.protocol;return se.call(E,n)&&E[n](e,t,!0)||null}const{ERR_INVALID_ARG_VALUE:pe}=p,k=Object.freeze([`node`,`import`]),me=new Set(k);function he(){return k}function ge(){return me}function A(e){if(e!==void 0&&e!==he()){if(!Array.isArray(e))throw new pe(`conditions`,e,`expected an array`);return new Set(e)}return ge()}const j=RegExp.prototype[Symbol.replace],{ERR_NETWORK_IMPORT_DISALLOWED:M,ERR_INVALID_MODULE_SPECIFIER:N,ERR_INVALID_PACKAGE_CONFIG:P,ERR_INVALID_PACKAGE_TARGET:_e,ERR_MODULE_NOT_FOUND:F,ERR_PACKAGE_IMPORT_NOT_DEFINED:I,ERR_PACKAGE_PATH_NOT_EXPORTED:ve,ERR_UNSUPPORTED_DIR_IMPORT:ye,ERR_UNSUPPORTED_RESOLVE_REQUEST:L}=p,R={}.hasOwnProperty,z=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i,B=/(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i,be=/^\.|%|\\/,V=/\*/g,xe=/%2f|%5c/i,H=/* @__PURE__ */ new Set,Se=/[/\\]{2}/;function U(e,t,n,r,i,o,s){if(u.noDeprecation)return;let c=a(r),l=Se.exec(s?e:t)!==null;u.emitWarning(`Use of deprecated ${l?`double slash`:`leading or trailing slash matching`} resolving "${e}" for module request "${t}" ${t===n?``:`matched to "${n}" `}in the "${i?`imports`:`exports`}" field module resolution of the package at ${c}${o?` imported from ${a(o)}`:``}.`,`DeprecationWarning`,`DEP0166`)}function W(e,t,n,r){if(u.noDeprecation||O(e,{parentURL:n.href})!==`module`)return;let o=a(e.href),s=a(new URL(`.`,t)),c=a(n);r?i.resolve(s,r)!==o&&u.emitWarning(`Package ${s} has a "main" field set to "${r}", excluding the full filename and extension to the resolved file at "${o.slice(s.length)}", imported from ${c}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`):u.emitWarning(`No "main" or "exports" field defined in the package.json for ${s} resolving the main entry point "${o.slice(s.length)}", imported from ${c}.\nDefault "index" lookups for the main are deprecated for ES modules.`,`DeprecationWarning`,`DEP0151`)}function G(e){try{return r(e)}catch{}}function K(e){let t=r(e,{throwIfNoEntry:!1});return(t?t.isFile():void 0)??!1}function Ce(e,t,n){let r;if(t.main!==void 0){if(r=new URL(t.main,e),K(r))return r;let i=[`./${t.main}.js`,`./${t.main}.json`,`./${t.main}.node`,`./${t.main}/index.js`,`./${t.main}/index.json`,`./${t.main}/index.node`],a=-1;for(;++a<i.length&&(r=new URL(i[a],e),!K(r));)r=void 0;if(r)return W(r,e,n,t.main),r}let i=[`./index.js`,`./index.json`,`./index.node`],o=-1;for(;++o<i.length&&(r=new URL(i[o],e),!K(r));)r=void 0;if(r)return W(r,e,n,t.main),r;throw new F(a(new URL(`.`,e)),a(n))}function we(e,t,r){if(xe.exec(e.pathname)!==null)throw new N(e.pathname,`must not include encoded "/" or "\\" characters`,a(t));let s;try{s=a(e)}catch(n){let r=n;throw Object.defineProperty(r,"input",{value:String(e)}),Object.defineProperty(r,"module",{value:String(t)}),r}let c=G(s.endsWith(`/`)?s.slice(-1):s);if(c&&c.isDirectory()){let n=new ye(s,a(t));throw n.url=String(e),n}if(!c||!c.isFile()){let n=new F(s||e.pathname,t&&a(t),!0);throw n.url=String(e),n}if(!r){let t=n(s),{search:r,hash:a}=e;e=o(t+(s.endsWith(i.sep)?`/`:``)),e.search=r,e.hash=a}return e}function Te(e,t,n){return new I(e,t&&a(new URL(`.`,t)),a(n))}function q(e,t,n){return new ve(a(new URL(`.`,t)),e,n&&a(n))}function Ee(e,t,n,r,i){let o=`request is not a valid match in pattern "${t}" for the "${r?`imports`:`exports`}" resolution of ${a(n)}`;throw new N(e,o,i&&a(i))}function J(e,t,n,r,i){return t=typeof t==`object`&&t?JSON.stringify(t,null,``):`${t}`,new _e(a(new URL(`.`,n)),e,t,r,i&&a(i))}function De(e,t,n,r,i,a,o,s,c){if(t!==``&&!a&&e[e.length-1]!==`/`)throw J(n,e,r,o,i);if(!e.startsWith(`./`)){if(o&&!e.startsWith(`../`)&&!e.startsWith(`/`)){let n=!1;try{new URL(e),n=!0}catch{}if(!n)return Q(a?j.call(V,e,()=>t):e+t,r,c)}throw J(n,e,r,o,i)}if(z.exec(e.slice(2))!==null){if(B.exec(e.slice(2))===null){if(!s){let s=a?n.replace(`*`,()=>t):n+t;U(a?j.call(V,e,()=>t):e,s,n,r,o,i,!0)}}else throw J(n,e,r,o,i)}let l=new URL(e,r),u=l.pathname,d=new URL(`.`,r).pathname;if(!u.startsWith(d))throw J(n,e,r,o,i);if(t===``)return l;if(z.exec(t)!==null){let c=a?n.replace(`*`,()=>t):n+t;B.exec(t)===null?s||U(a?j.call(V,e,()=>t):e,c,n,r,o,i,!1):Ee(c,n,r,o,i)}return a?new URL(j.call(V,l.href,()=>t)):new URL(t,l)}function Oe(e){let t=Number(e);return`${t}`===e&&t>=0&&t<4294967295}function Y(e,t,n,r,i,o,s,c,l){if(typeof t==`string`)return De(t,n,r,e,i,o,s,c,l);if(Array.isArray(t)){let a=t;if(a.length===0)return null;let u,d=-1;for(;++d<a.length;){let t=a[d],f;try{f=Y(e,t,n,r,i,o,s,c,l)}catch(e){let t=e;if(u=t,t.code===`ERR_INVALID_PACKAGE_TARGET`)continue;throw e}if(f!==void 0){if(f===null)u=null;else return f}}if(u==null)return null;throw u}if(typeof t==`object`&&t){let u=Object.getOwnPropertyNames(t),d=-1;for(;++d<u.length;){let t=u[d];if(Oe(t))throw new P(a(e),i,`"exports" cannot contain numeric property keys.`)}for(d=-1;++d<u.length;){let a=u[d];if(a==="default"||l&&l.has(a)){let u=t[a],d=Y(e,u,n,r,i,o,s,c,l);if(d===void 0)continue;return d}}return null}if(t===null)return null;throw J(r,t,e,s,i)}function ke(e,t,n){if(typeof e==`string`||Array.isArray(e))return!0;if(typeof e!=`object`||!e)return!1;let r=Object.getOwnPropertyNames(e),i=!1,o=0,s=-1;for(;++s<r.length;){let e=r[s],c=e===``||e[0]!==`.`;if(o++===0)i=c;else if(i!==c)throw new P(a(t),n,`"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`)}return i}function Ae(e,t,n){if(u.noDeprecation)return;let r=a(t);H.has(r+`|`+e)||(H.add(r+`|`+e),u.emitWarning(`Use of deprecated trailing slash pattern mapping "${e}" in the "exports" field module resolution of the package at ${r}${n?` imported from ${a(n)}`:``}. Mapping specifiers ending in "/" is no longer supported.`,`DeprecationWarning`,`DEP0155`))}function X(e,t,n,r,i){let a=n.exports;if(ke(a,e,r)&&(a={".":a}),R.call(a,t)&&!t.includes(`*`)&&!t.endsWith(`/`)){let n=a[t],o=Y(e,n,``,t,r,!1,!1,!1,i);if(o==null)throw q(t,e,r);return o}let o=``,s=``,c=Object.getOwnPropertyNames(a),l=-1;for(;++l<c.length;){let n=c[l],i=n.indexOf(`*`);if(i!==-1&&t.startsWith(n.slice(0,i))){t.endsWith(`/`)&&Ae(t,e,r);let a=n.slice(i+1);t.length>=n.length&&t.endsWith(a)&&Z(o,n)===1&&n.lastIndexOf(`*`)===i&&(o=n,s=t.slice(i,t.length-a.length))}}if(o){let n=a[o],c=Y(e,n,s,o,r,!0,!1,t.endsWith(`/`),i);if(c==null)throw q(t,e,r);return c}throw q(t,e,r)}function Z(e,t){let n=e.indexOf(`*`),r=t.indexOf(`*`),i=n===-1?e.length:n+1,a=r===-1?t.length:r+1;return i>a?-1:a>i||n===-1?1:r===-1||e.length>t.length?-1:+(t.length>e.length)}function je(e,t,n){if(e===`#`||e.startsWith(`#/`)||e.endsWith(`/`))throw new N(e,`is not a valid internal imports specifier name`,a(t));let r,i=w(t);if(i.exists){r=o(i.pjsonPath);let a=i.imports;if(a){if(R.call(a,e)&&!e.includes(`*`)){let i=Y(r,a[e],``,e,t,!1,!0,!1,n);if(i!=null)return i}else{let i=``,o=``,s=Object.getOwnPropertyNames(a),c=-1;for(;++c<s.length;){let t=s[c],n=t.indexOf(`*`);if(n!==-1&&e.startsWith(t.slice(0,-1))){let r=t.slice(n+1);e.length>=t.length&&e.endsWith(r)&&Z(i,t)===1&&t.lastIndexOf(`*`)===n&&(i=t,o=e.slice(n,e.length-r.length))}}if(i){let e=a[i],s=Y(r,e,o,i,t,!0,!0,!1,n);if(s!=null)return s}}}}throw Te(e,r,t)}function Me(e,t){let n=e.indexOf(`/`),r=!0,i=!1;e[0]===`@`&&(i=!0,n===-1||e.length===0?r=!1:n=e.indexOf(`/`,n+1));let o=n===-1?e:e.slice(0,n);if(be.exec(o)!==null&&(r=!1),!r)throw new N(e,`is not a valid package name`,a(t));return{packageName:o,packageSubpath:`.`+(n===-1?``:e.slice(n)),isScoped:i}}function Q(t,n,r){if(e.includes(t))return new URL(`node:`+t);let{packageName:i,packageSubpath:s,isScoped:c}=Me(t,n),l=w(n);
|
|
2
2
|
/* c8 ignore next 16 */
|
|
3
3
|
if(l.exists){let e=o(l.pjsonPath);if(l.name===i&&l.exports!==void 0&&l.exports!==null)return X(e,s,l,n,r)}let u=new URL(`./node_modules/`+i+`/package.json`,n),d=a(u),f;do{let e=G(d.slice(0,-13));if(!e||!e.isDirectory()){f=d,u=new URL((c?`../../../../node_modules/`:`../../../node_modules/`)+i+`/package.json`,u),d=a(u);continue}let o=C(d,{base:n,specifier:t});return o.exports!==void 0&&o.exports!==null?X(u,s,o,n,r):s===`.`?Ce(u,o,n):new URL(s,u)}while(d.length!==f.length);throw new F(i,a(n),!1)}function Ne(e){return!(e[0]!==`.`||e.length!==1&&e[1]!==`/`&&(e[1]!==`.`||e.length!==2&&e[2]!==`/`))}function $(e){return e===``?!1:e[0]===`/`||Ne(e)}function Pe(t,n,r,i){r===void 0&&(r=A());let a=n.protocol,o=a===`data:`||a===`http:`||a===`https:`,s;if($(t))try{s=new URL(t,n)}catch(e){let r=new L(t,n);throw r.cause=e,r}else if(a===`file:`&&t[0]===`#`)s=je(t,n,r);else try{s=new URL(t)}catch(i){if(o&&!e.includes(t)){let e=new L(t,n);throw e.cause=i,e}s=Q(t,n,r)}return l.ok(s!==void 0,`expected to be defined`),s.protocol===`file:`?we(s,n,i):s}function Fe(t,n,r){if(r){let i=r.protocol;if(i===`http:`||i===`https:`){if($(t)){let e=n?.protocol;if(e&&e!==`https:`&&e!==`http:`)throw new M(t,r,`remote imports cannot import from a local location.`);return{url:n?.href||``}}throw e.includes(t)?new M(t,r,`remote imports cannot import from a local location.`):new M(t,r,`only relative and absolute specifiers are supported.`)}}}function Ie(e){return!!(e&&typeof e==`object`&&`href`in e&&typeof e.href==`string`&&`protocol`in e&&typeof e.protocol==`string`&&e.href&&e.protocol)}function Le(e){if(e!==void 0&&typeof e!=`string`&&!Ie(e))throw new p.ERR_INVALID_ARG_TYPE(`parentURL`,[`string`,`URL`],e)}function Re(e,t={}){let{parentURL:n}=t;l.ok(n!==void 0,"expected `parentURL` to be defined"),Le(n);let r;if(n)try{r=new URL(n)}catch{}let i,a;try{if(i=$(e)?new URL(e,r):new URL(e),a=i.protocol,a===`data:`)return{url:i.href,format:null}}catch{}let o=Fe(e,i,r);if(o)return o;if(a===void 0&&i&&(a=i.protocol),a===`node:`||i&&i.protocol===`node:`)return{url:e};let s=A(t.conditions),c=Pe(e,new URL(n),s,!1);return{url:c.href,format:O(c,{parentURL:n})}}function ze(e,t){if(!t)throw Error("Please pass `parent`: `import-meta-resolve` cannot ponyfill that");try{return Re(e,{parentURL:t}).url}catch(e){let t=e;if((t.code===`ERR_UNSUPPORTED_DIR_IMPORT`||t.code===`ERR_MODULE_NOT_FOUND`)&&typeof t.url==`string`)return t.url;throw e}}export{ze as resolve};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { r as KnownAgentId, t as AgentInfo } from "./detect-agent-EHaSY1KW.js";
|
|
2
|
-
import { $ as DynamicCompletionCandidate, A as SubCommandsRecord, B as ArgFn, C as RunInvocation, D as RunnableCommand, E as RunResultSuccess, F as ExtractedFields, G as EffectContext, H as CompletionMeta, I as ResolvedFieldMeta, J as ValidateArgMeta, K as PromptMeta, L as UnknownKeysMode, M as LazyCommand, N as isLazyCommand, O as SetupContext, P as lazy, Q as CompletionDirectiveMask, R as toCamelCase, S as RunCommandOptions, T as RunResultFailure, U as CompletionType, V as ArgMeta, W as CustomCompletion, X as ExpandCompletion, Y as ExpandCandidate, Z as ResolvedExpandCandidate, _ as LogStream, a as ArgsSchema$1, at as InferSchemaOutput, b as NonRunnableCommand, c as Command, d as GlobalArgs, et as DynamicCompletionContext, f as GlobalCleanupContext, g as LogLevel, h as LogEntry, i as ArgSource, it as loadPackage, j as UnknownSubcommandHandler, k as SubCommandValue, l as CommandBase, m as IsEmpty, n as AgentHelpContext, nt as DynamicCompletionResult, o as CleanupContext, ot as SchemaLike, p as GlobalSetupContext, q as PromptType, r as AnyCommand, rt as PackageRequirement, s as CollectedLogs, t as AgentHelp, tt as DynamicCompletionResolver, u as Example, v as Logger, w as RunResult, x as PromptResolver, y as MainOptions, z as toKebabCase } 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 DynamicCompletionCandidate, A as SubCommandsRecord, B as ArgFn, C as RunInvocation, D as RunnableCommand, E as RunResultSuccess, F as ExtractedFields, G as EffectContext, H as CompletionMeta, I as ResolvedFieldMeta, J as ValidateArgMeta, K as PromptMeta, L as UnknownKeysMode, M as LazyCommand, N as isLazyCommand, O as SetupContext, P as lazy, Q as CompletionDirectiveMask, R as toCamelCase, S as RunCommandOptions, T as RunResultFailure, U as CompletionType, V as ArgMeta, W as CustomCompletion, X as ExpandCompletion, Y as ExpandCandidate, Z as ResolvedExpandCandidate, _ as LogStream, a as ArgsSchema$1, at as InferSchemaOutput, b as NonRunnableCommand, c as Command, d as GlobalArgs, et as DynamicCompletionContext, f as GlobalCleanupContext, g as LogLevel, h as LogEntry, i as ArgSource, it as loadPackage, j as UnknownSubcommandHandler, k as SubCommandValue, l as CommandBase, m as IsEmpty, n as AgentHelpContext, nt as DynamicCompletionResult, o as CleanupContext, ot as SchemaLike, p as GlobalSetupContext, q as PromptType, r as AnyCommand, rt as PackageRequirement, s as CollectedLogs, t as AgentHelp, tt as DynamicCompletionResolver, u as Example, v as Logger, w as RunResult, x as PromptResolver, y as MainOptions, z as toKebabCase } from "./types-DtQ-Zt3n.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-QHQsd0Zt.js";
|
|
4
4
|
import { GenericSchema } from "valibot";
|
|
5
5
|
//#region ../core/src/core/schema-extractor.d.ts
|
|
6
6
|
/**
|
|
@@ -817,6 +817,11 @@ interface ParserOptions {
|
|
|
817
817
|
* `booleanFlags` has default negation suppressed.
|
|
818
818
|
*/
|
|
819
819
|
defaultNegationDisabledFields?: Set<string>;
|
|
820
|
+
/**
|
|
821
|
+
* When true, an option whose resolved name is not in `definedNames` never
|
|
822
|
+
* takes the next token as its value, so the token stays a positional.
|
|
823
|
+
*/
|
|
824
|
+
unknownFlagsTakeNoValue?: boolean;
|
|
820
825
|
}
|
|
821
826
|
/**
|
|
822
827
|
* Parse argv into a flat record
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,i as t}from"./field-meta-CEtC5Mir.js";import{t as n}from"./register-BtPBdvwq.js";import{i as r,n as i}from"./schema-extractor-
|
|
1
|
+
import{a as e,i as t}from"./field-meta-CEtC5Mir.js";import{t as n}from"./register-BtPBdvwq.js";import{i as r,n as i}from"./schema-extractor-lB6-WHOF.js";import{n as a,t as o}from"./cli-main-CNiI0QME.js";import{n as s,t as c}from"./command-BXsTrIgI.js";import{d as l,o as u,s as d}from"./subcommand-router-40vA6Mka.js";import{C as f,D as p,E as m,O as h,S as g,T as _,_ as v,a as y,b,c as x,d as S,f as C,g as w,h as T,i as E,l as D,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-Gm-z60xj.js";import{a as B,i as V,n as H,r as U,t as W}from"./logger-CoeDrmRr.js";import{r as G}from"./argv-parser-CHIJ1BrN.js";import{t as K}from"./with-completion-command-Dot_GmfF.js";const q=a(`@politty/valibot`),J=s,Y=c,X=n;export{w as CaseVariantCollisionError,v as DefaultSubCommandError,I as DuplicateAliasError,z as DuplicateFieldError,b as DuplicateNegationError,R as FieldTypeConflictError,g as PositionalConfigError,f as ReservedAliasError,L as ReservedFieldNameError,X as arg,a as createCompileCacheShimGenerator,Y as createDefineCommand,M as createDualCaseProxy,J as defineCommand,i as extractFields,y as formatCommandValidationErrors,E as formatValidationErrors,q as generateCompileCacheShim,_ as generateHelp,m as generateHelpData,r as getUnknownKeysMode,W as isColorEnabled,u as isLazyCommand,d as lazy,l as loadPackage,H as logger,G as parseArgv,p as renderInline,h as renderMarkdown,P as runCommand,k as runMain,o as runPolittyCli,U as setColorEnabled,V as styles,B as symbols,t as toCamelCase,e as toKebabCase,A as validateCaseVariantCollisions,N as validateCommand,x as validateCrossSchemaCollisions,D as validateDefaultSubCommand,F as validateDuplicateAliases,S as validateDuplicateFields,C as validateDuplicateNegations,j as validatePositionalConfig,O as validateReservedAliases,T as validateReservedFieldNames,K as withCompletionCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as e}from"./schema-extractor-
|
|
1
|
+
import{l as e}from"./schema-extractor-lB6-WHOF.js";function t(e){let t=e.prompt;if(!t||t.enabled===!1)return null;let n=t.message??e.description??e.name,a=r(e,t),o=i(e,t,a);return{field:e,type:a===`select`&&!o?`text`:a,message:n,...o&&{choices:o}}}function n(e){return e!==void 0&&e.length>0}function r(e,t){return t.type?t.type===`file`||t.type===`directory`?`text`:t.type:n(t.choices)?`select`:e.completion?.type===`file`||e.completion?.type===`directory`?`text`:n(e.enumValues)?`select`:e.type===`boolean`?`confirm`:`text`}function i(e,t,r){if(n(t.choices))return t.choices.map(e=>typeof e==`string`?{label:e,value:e}:e);if(r===`select`&&n(e.enumValues))return e.enumValues.map(e=>({label:e,value:e}))}function a(e,n){let r=[];for(let i of e){if(n[i.name]!==void 0||i.type===`array`)continue;let e=t(i);e&&r.push(e)}return r}function o(){return!(!process.stdin.isTTY||!process.stdout.isTTY||process.env.CI||process.env.POLITTY_NO_PROMPT)}async function s(e,t,n){if(!(n.interactive??o()))return e;let r=n.adapter,i={...e};return t.schemaType===`discriminatedUnion`&&t.discriminator&&t.variants?await c(r,i,t):t.schemaType===`union`||t.schemaType===`xor`||await u(r,i,t.fields),i}async function c(n,r,i){let{discriminator:a,variants:o}=i;if(!a||!o)return;if(r[a]===void 0){let e=l(i.fields,o,a),s=e?t(e):null;if(s){let e=o.map(e=>e.discriminatorValue).filter(Boolean);e.length>0&&(s.type=`select`,s.choices=e.map(e=>({label:e,value:e}))),await d(n,r,s)}}let s=e(i,()=>r);s!==i&&await u(n,r,s.fields.filter(e=>e.name!==a))}function l(e,t,n){let r=e.find(e=>e.name===n);if(r?.prompt)return r;for(let e of t){let t=e.fields.find(e=>e.name===n);if(t?.prompt)return t}}async function u(e,t,n){let r=a(n,t);for(let n of r)await d(e,t,n)}async function d(e,t,n){let{message:r}=n,i;switch(n.type){case`text`:i=await e.text({message:r,placeholder:n.field.placeholder});break;case`password`:i=await e.password({message:r});break;case`confirm`:i=await e.confirm({message:r});break;case`select`:i=await e.select({message:r,options:n.choices??[]})}if(e.isCancelled(i))throw Error(`Prompt cancelled by user`);t[n.field.name]=i}export{t as i,o as n,a as r,s as t};
|
package/dist/prompt-clack.d.ts
CHANGED
package/dist/prompt-clack.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-BtPBdvwq.js";import{t as e}from"./prompt-
|
|
1
|
+
import"./register-BtPBdvwq.js";import{t as e}from"./prompt-Bs_O6SmK.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)=>e(t,n,{adapter:o()});export{s as prompt};
|
package/dist/prompt-inquirer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-BtPBdvwq.js";import{t as e}from"./prompt-
|
|
1
|
+
import"./register-BtPBdvwq.js";import{t as e}from"./prompt-Bs_O6SmK.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)=>e(t,n,{adapter:s()});export{c as prompt};
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as ExtractedFields, I as ResolvedFieldMeta } from "./types-
|
|
1
|
+
import { F as ExtractedFields, I as ResolvedFieldMeta } from "./types-DtQ-Zt3n.js";
|
|
2
2
|
//#region ../core/src/prompt/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Resolved prompt configuration for a single field
|
|
@@ -21,7 +21,11 @@ interface ResolvedPromptConfig {
|
|
|
21
21
|
* Implement this to use a custom prompt library instead of the default @clack/prompts.
|
|
22
22
|
*/
|
|
23
23
|
interface PromptAdapter {
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Prompt for free-form text input.
|
|
26
|
+
* `placeholder` is the help-display placeholder (e.g. `FILE`): show it only
|
|
27
|
+
* as a hint and never return it as the value.
|
|
28
|
+
*/
|
|
25
29
|
text(config: {
|
|
26
30
|
message: string;
|
|
27
31
|
placeholder?: string | undefined;
|
package/dist/prompt.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./register-BtPBdvwq.js";
|
|
1
|
+
import"./register-BtPBdvwq.js";export{r as getFieldsToPrompt,n as isInteractive,t as promptMissingArgs,i as resolvePromptConfig}from"./prompt-Bs_O6SmK.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as runCommand}from"./runner-Gm-z60xj.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{a as e,i as t,n,o as r,t as i}from"./field-meta-CEtC5Mir.js";import{a,c as o,f as s,l as c,n as l,o as u,p as d,r as f,s as p,t as m}from"./schema-extractor-lB6-WHOF.js";import{t as h}from"./detect-agent-D7KSeWMh.js";import{n as g}from"./compile-cache-6u9hgeWu.js";import{a as _,c as v,f as y,i as ee,l as b,n as x,o as S,r as C,t as w,u as T}from"./subcommand-router-40vA6Mka.js";import{n as E,r as D,t as O}from"./log-collector-uhRWYT-z.js";import{a as k,i as A}from"./logger-CoeDrmRr.js";import{a as j,c as te,i as M,n as N,o as P,r as F,t as I}from"./argv-parser-CHIJ1BrN.js";import{stripVTControlCharacters as ne}from"node:util";async function re(e,t,n={}){let r,i,a=n.captureLogs??!1?O():null;a?.start();let o={args:t},s={args:t,error:r},c;n.handleSignals&&(c=async t=>{c&&(process.off(`SIGINT`,c),process.off(`SIGTERM`,c));let r=/* @__PURE__ */ Error(`Process interrupted`);if(s.error=r,e.cleanup)try{await e.cleanup(s)}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)}a?.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`,c),process.on(`SIGTERM`,c));try{e.requiredPackages?.length&&await y(e.requiredPackages,t);for(let e of n.packageFields??[])e.requiredPackages?.length&&typeof t==`object`&&t&&e.name in t&&(n.packageDiscriminators?.includes(e.name)||t[e.name]===!0)&&await y(e.requiredPackages,t);e.setup&&await e.setup(o),e.run&&(i=await e.run(t))}catch(e){r=e instanceof Error?e:Error(String(e))}finally{c&&(process.off(`SIGINT`,c),process.off(`SIGTERM`,c))}if(e.cleanup){s.error=r;try{await e.cleanup(s)}catch(e){r||=e instanceof Error?e:Error(String(e))}}a?.stop();let l=n.existingLogs??E(),u=a?.getLogs()??E(),d=D(l,u);return r?{success:!1,error:r,exitCode:1,logs:d}:{success:!0,result:i,exitCode:0,logs:d}}function ie(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 ae(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 oe(e){let t=!1,n=!1,r=!1;for(let i of e){let e=i.codePointAt(0);e===65039?r=!0:ie(e)||(t=!0,ae(e)&&(n=!0))}return t?n||r?2:1:0}const se=(()=>{try{return new Intl.Segmenter(`en`,{granularity:`grapheme`})}catch{return}})();function ce(e){if(e.length===0)return 0;let t=e.includes(`\x1B`)||e.includes(``)?ne(e):e,n=0;if(se)for(let{segment:e}of se.segment(t))n+=oe(e);else for(let e of t)n+=oe(e);return n}function L(e){let t=[],n=e.replace(/`([^`]+)`/g,(e,n)=>{let r=t.length;return t.push(A.cyan(n)),`\x00CODE${r}\x00`});return n=n.replace(/\*\*(.+?)\*\*/g,(e,t)=>A.bold(t)),n=n.replace(/__(.+?)__/g,(e,t)=>A.bold(t)),n=n.replace(/\*(.+?)\*/g,(e,t)=>A.italic(t)),n=n.replace(/(?<!\w)_(.+?)_(?!\w)/g,(e,t)=>A.italic(t)),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>`${A.underline(t)} ${A.dim(`(${n})`)}`),n=n.replace(/\x00CODE(\d+)\x00/g,(e,n)=>t[Number(n)]),n}function le(e){return _e(e.split(`
|
|
2
|
+
`)).map(Se).join(`
|
|
3
|
+
|
|
4
|
+
`)}const ue=/^(#{1,6})\s+(.+)$/,de=/^(?:---+|\*\*\*+|___+)\s*$/,fe=/^>\s?(.*)$/,pe=/^-\s+(.+)$/,R=/^(\d+)[.)]\s+(.+)$/,me=/^(`{3,}|~{3,})(\S*)\s*$/,he=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/,z=/^\|(.+)\|$/,ge=/^\|(\s*:?-+:?\s*\|)+$/;function _e(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.trim()===``){n++;continue}let i=r.match(me);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(ue);if(a){t.push({type:`heading`,level:a[1].length,content:a[2]}),n++;continue}if(de.test(r)){t.push({type:`hr`}),n++;continue}if(fe.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(fe);if(t)r.push(t[1]),n++;else break}if(r.length>0){let e=r[0].match(he);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(pe.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(pe);if(t)r.push(t[1]),n++;else break}t.push({type:`ul`,items:r});continue}let o=r.match(R);if(o){let r=Number(o[1]),i=[];for(;n<e.length;){let t=e[n].match(R);if(t)i.push(t[2]),n++;else break}t.push({type:`ol`,items:i,start:r});continue}if(z.test(r)&&n+1<e.length&&ge.test(e[n+1])){let i=ve(r),a=ye(e[n+1]);n+=2;let o=[];for(;n<e.length&&z.test(e[n]);)o.push(ve(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()===``||ue.test(t)||de.test(t)||fe.test(t)||pe.test(t)||R.test(t)||me.test(t)||z.test(t)&&n+1<e.length&&ge.test(e[n+1]))break;s.push(t),n++}s.length>0&&t.push({type:`paragraph`,lines:s})}return t}function ve(e){return e.slice(1,-1).split(`|`).map(e=>e.trim())}function ye(e){return e.slice(1,-1).split(`|`).map(e=>{let t=e.trim();return t.startsWith(`:`)&&t.endsWith(`:`)?`center`:t.endsWith(`:`)?`right`:`left`})}function be(e,t,n){let r=ce(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 xe={NOTE:{icon:`ℹ`,label:`Note`,styleFn:A.cyan},TIP:{icon:`💡`,label:`Tip`,styleFn:A.green},IMPORTANT:{icon:`❗`,label:`Important`,styleFn:A.magenta},WARNING:{icon:`⚠`,label:`Warning`,styleFn:A.yellow},CAUTION:{icon:`🔴`,label:`Caution`,styleFn:A.red}};function Se(e){switch(e.type){case`heading`:return A.green(A.bold(L(e.content)));case`hr`:return A.dim(`─`.repeat(40));case`blockquote`:{let t=A.dim(`│ `);return e.lines.map(e=>`${t}${L(e)}`).join(`
|
|
5
|
+
`)}case`alert`:{let{icon:t,label:n,styleFn:r}=xe[e.alertType],i=r(A.bold(`│`))+` `,a=`${i}${r(t)} ${r(n)}`;return e.lines.length===0?a:`${a}\n${e.lines.map(e=>`${i}${L(e)}`).join(`
|
|
6
|
+
`)}`}case`ul`:return e.items.map(e=>`${A.dim(`•`)} ${L(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`${A.dim(`${i}.`)} ${L(t)}`}).join(`
|
|
8
|
+
`)}case`table`:{let t=e.headers.length,n=e.headers.map(e=>L(e)),r=e.rows.map(e=>Array.from({length:t},(t,n)=>L(e[n]??``))),i=n.map((e,t)=>{let n=ce(e),i=r.map(e=>ce(e[t]));return Math.max(n,...i)}),a=A.dim(`│`),o=A.dim(`┌─${i.map(e=>`─`.repeat(e)).join(`─┬─`)}─┐`),s=A.dim(`├─${i.map(e=>`─`.repeat(e)).join(`─┼─`)}─┤`),c=A.dim(`└─${i.map(e=>`─`.repeat(e)).join(`─┴─`)}─┘`);return[o,`${a} ${n.map((t,n)=>A.bold(be(t,i[n],e.alignments[n]??`left`))).join(` ${a} `)} ${a}`,s,...r.map(t=>{let n=t.map((t,n)=>be(t,i[n],e.alignments[n]??`left`));return`${a} ${n.join(` ${a} `)} ${a}`}),c].join(`
|
|
9
|
+
`)}case`code`:return e.lines.map(e=>` ${A.yellow(e)}`).join(`
|
|
10
|
+
`);case`paragraph`:return L(e.lines.join(` `))}}const B={help:`Show help`,helpAll:`Show help with all subcommand options`,helpJson:`Show help as JSON`,version:`Show version`};function Ce(e){return!e.startsWith(`__`)}function V(e){return Object.entries(e).filter(([e])=>Ce(e))}function we(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?t.commandPath.join(` `):e.name??`command`}function Te(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?`${t.rootName} ${t.commandPath.join(` `)}`:e.name??`command`}function Ee(e,t){let n=[],r=Te(e,t);n.push(A.commandName(r)),t?.globalExtracted?.fields.length&&n.push(A.placeholder(`[global options]`));let i=f(e);if(i){let t=o(i);p(i).length>0&&n.push(A.placeholder(`[options]`)),e.subCommands&&V(e.subCommands).length>0&&(e.run||e.defaultSubCommand?n.push(A.placeholder(`[command]`)):n.push(A.option(`<command>`)));for(let e of t)e.required?n.push(A.option(`<${e.name}>`)):n.push(A.placeholder(`[${e.name}]`))}else e.subCommands&&V(e.subCommands).length>0&&(e.run||e.defaultSubCommand?n.push(A.placeholder(`[command]`)):n.push(A.option(`<command>`)));return n.join(` `)}function De(e,t){let n=`${A.dim(`When`)} ${A.option(e)}=${A.bold(t.discriminatorValue)}:`;return t.description?`${n} ${t.description}`:n}function Oe(e,t){return` ${A.bold(`${e.description??`Variant ${t+1}`}:`)}`}function ke(e,t=0){let n=e.required?A.option(`<${e.name}>`):A.placeholder(`[${e.name}]`),r=e.named?`${n}, ${U(e)}`:n,i=[K(e),e.defaultValue===void 0?void 0:A.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)].filter(Boolean).join(` `);return i?G(r,i,t):`${` `.repeat(t)} ${r}`}function Ae(e){let t=f(e);if(!t)return``;let n=[];if(t.schemaType===`discriminatedUnion`&&t.discriminator){let e=t.discriminator;n=(t.variants??[]).map(t=>({label:De(e,t),fields:t.fields}))}else(t.schemaType===`union`||t.schemaType===`xor`)&&t.unionOptions&&(n=t.unionOptions.map((e,t)=>({label:Oe(e,t),fields:e.fields})));let r=n.length>0?m(n):void 0,i=t.fields.filter(e=>e.positional&&(r===void 0||r.has(e.name))).map(e=>ke(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=>ke(e,1)))}return i.join(`
|
|
11
|
+
`)}function je(e,t={},r){let i=[],a={help:t.help??B.help,helpAll:t.helpAll??B.helpAll,helpJson:t.helpJson??B.helpJson,version:t.version??B.version},o=f(e),s=o?.fields.some(e=>e.overrideBuiltinAlias===!0&&n(e).includes(`h`))??!1,c=o?.fields.some(e=>e.overrideBuiltinAlias===!0&&n(e).includes(`H`))??!1;if(s?i.push(G(A.option(`--help`),a.help)):i.push(G(`${A.option(`-h`)}, ${A.option(`--help`)}`,a.help)),c?i.push(G(A.option(`--help-all`),a.helpAll)):i.push(G(`${A.option(`-H`)}, ${A.option(`--help-all`)}`,a.helpAll)),i.push(G(A.option(`--help-json`),a.helpJson)),r?.rootVersion&&i.push(G(A.option(`--version`),a.version)),!o)return i.join(`
|
|
12
|
+
`);if(o.schemaType===`discriminatedUnion`&&o.discriminator)return Me(o,e,i);if(o.schemaType===`union`&&o.unionOptions||o.schemaType===`xor`&&o.unionOptions)return Ne(o,e,i);let l=[],u=o.fields.filter(e=>!e.positional);for(let e of u){let t=U(e),n=K(e);e.defaultValue!==void 0&&(n+=` ${A.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${A.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(...i),l.join(`
|
|
13
|
+
`)}function H(e,t=0,n=0){return!e.negationDisplay||!e.negationDescription?null:G(A.option(`--${e.negationDisplay}`),`${e.negationDescription} ${A.dim(`(↔ --${e.cliName})`)}`,t,n)}function Me(e,t,n){let r=[],i=e.discriminator,a=e.variants??[],o=u(e,i);if(o){let t=a.map(e=>e.discriminatorValue).join(`|`),n=`${A.option(`--${i}`)} ${A.placeholder(`<${t}>`)}`,s=e.description??o.description??`Action to perform`;r.push(G(n,s))}let s=m(a,i);for(let t of s){let n=e.fields.find(e=>e.name===t);if(n&&!n.positional){let e=U(n),t=K(n);n.defaultValue!==void 0&&(t+=` ${A.defaultValue(`(default: ${JSON.stringify(n.defaultValue)})`)}`);let i=W(n.env);i&&(t+=` ${i}`),r.push(G(e,t));let a=H(n);a&&r.push(a)}}r.push(...n);for(let e of a){let t=e.fields.filter(e=>e.name!==i&&!s.has(e.name)&&!e.positional),n=b(e.fields.find(e=>e.name===i)?.requiredPackages);if(t.length>0||n){r.push(``),r.push(De(i,e)),n&&r.push(Ie(n,2));for(let e of t){let t=U(e),n=K(e);e.defaultValue!==void 0&&(n+=` ${A.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${A.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 Ne(e,t,n){let r=[],i=e.unionOptions??[],a=m(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+=` ${A.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=Oe(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+=` ${A.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${A.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(` ${A.dim(A.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(A.option(`-${n}`));let n=A.option(`--${e.cliName}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();n+=` ${A.placeholder(`<${t}>`)}`}if(t.push(n),e.alias){for(let n of e.alias)if(n.length>1){let r=A.option(`--${n}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();r+=` ${A.placeholder(`<${t}>`)}`}t.push(r)}}let r=t.join(`, `);return e.type===`boolean`&&e.negationDisplay&&!e.negationDescription?`${r} / ${A.option(`--${e.negationDisplay}`)}`:r}function W(e){if(!e)return``;let t=Array.isArray(e)?e:[e];return A.dim(`[env: ${t.join(`, `)}]`)}function Pe(e){return e.replace(/\x1B\[[0-9;]*m/g,``)}function Fe(e,t){let n=Pe(e).length,r=Math.max(0,t-n);return e+` `.repeat(r)}function Ie(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=Pe(e).length,o=32-n*2+r,s=o+2+n*2,c=Ie(t,s);return a>=o?`${i} ${e}\n${` `.repeat(s)}${c}`:`${i} ${Fe(e,o)}${c}`}function Le(e,t=0,n=0){let r=U(e),i=K(e);e.defaultValue!==void 0&&(i+=` ${A.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(i+=` ${A.required(`(required)`)}`);let a=W(e.env);return a&&(i+=` ${a}`),G(r,i,t,n)}function Re(e){let t=[];for(let n of e.fields){if(n.positional)continue;t.push(Le(n));let e=H(n);e&&t.push(e)}return t.join(`
|
|
18
|
+
`)}function ze(e,t){let n=[],r=f(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+=` ${A.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 Be(e,t,n){let r=[];for(let[i,a]of V(e)){let e=v(a),o=t?`${t} ${i}`:i,s=[e?.description,b(e?.requiredPackages)].filter(Boolean).join(`
|
|
19
|
+
`),c=e?.aliases,l=c&&c.length>0?`${o}, ${c.join(`, `)}`:o;if(r.push(G(A.command(l),s,n)),e){let t=ze(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=Be(i,o,n);r.push(...e)}}}return r}function Ve(e,t){let n=[],r=t.context;t.agentHelp&&n.push(le(t.agentHelp));let i=we(e,r);if(i){let e=A.commandName(i);r?.rootName&&r.commandPath&&r.commandPath.length>0?r.rootVersion?e+=` ${A.version(`(${r.rootName} v${r.rootVersion})`)}`:e+=` ${A.version(`(${r.rootName})`)}`:r?.rootVersion&&(e+=` ${A.version(`v${r.rootVersion}`)}`),n.push(e)}r?.aliasFor&&n.push(A.dim(`Alias for ${A.commandName(r.aliasFor)}`)),e.description&&n.push(e.description),!r?.aliasFor&&e.aliases&&e.aliases.length>0&&n.push(`${A.sectionHeader(`Aliases:`)} ${e.aliases.map(e=>A.command(e)).join(`, `)}`),n.push(`${A.sectionHeader(`Usage:`)} ${Ee(e,r)}`);let a=Ae(e);a&&n.push(`${A.sectionHeader(`Arguments:`)}\n${a}`);let o=je(e,t.descriptions,r);if(o&&n.push(`${A.sectionHeader(`Options:`)}\n${o}`),r?.globalExtracted?.fields.length&&n.push(`${A.sectionHeader(`Global Options:`)}\n${Re(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=Be(a,i,0);n.push(`${A.sectionHeader(`Commands:`)}\n${e.join(`
|
|
20
|
+
`)}`)}else{let e=[];for(let[t,n]of Object.entries(a)){let r=v(n),a=[r?.description,b(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(A.command(c),a))}n.push(`${A.sectionHeader(`Commands:`)}\n${e.join(`
|
|
22
|
+
`)}`)}}if(e.examples&&e.examples.length>0){let t=We(e.examples,r);n.push(`${A.sectionHeader(`Examples:`)}\n${t}`)}let s=b(e.requiredPackages);if(s&&n.push(`${A.sectionHeader(`Required packages:`)}\n${s}`),e.notes){let t=le(e.notes).split(`
|
|
23
|
+
`).map(e=>e===``?``:` ${e}`).join(`
|
|
24
|
+
`);n.push(`${A.sectionHeader(`Notes:`)}\n${t}`)}return`\n${n.join(`
|
|
25
|
+
|
|
26
|
+
`)}\n`}function K(e){return[e.description,b(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:T(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 He(e,t){let n=Te(e,t),r=!!t?.globalExtracted?.fields.length,i=e.subCommands&&V(e.subCommands).length>0?e.run?`optional`:`required`:void 0,a=f(e);return{commandName:n,hasGlobalOptions:r,hasOptions:a?p(a).length>0:!1,subcommand:i,positionals:a?o(a).map(e=>({name:e.name,required:e.required})):[]}}function Ue(e,t={}){let n=t.context,r=n?.commandPath??[],i={help:t.descriptions?.help??B.help,helpAll:t.descriptions?.helpAll??B.helpAll,helpJson:t.descriptions?.helpJson??B.helpJson,...n?.rootVersion?{version:t.descriptions?.version??B.version}:{}},a=f(e),s,c=[],l=[],d,p,h;if(a){if(s=a.schemaType,c=o(a).map(q),a.schemaType===`discriminatedUnion`&&a.discriminator&&a.variants){let e=a.discriminator;d=e;let t=a.variants,n=m(t,e),r=u(a,e),i=a.fields.filter(e=>!e.positional&&n.has(e.name));l=[...r?[{...q({...r,requiredPackages:void 0}),description:a.description??r.description??`Action to perform`}]:[],...i.map(q)],p=t.map(t=>{let r=t.fields.find(t=>t.name===e);return{discriminatorValue:t.discriminatorValue,...r?.requiredPackages?.length?{requiredPackages:q(r).requiredPackages}:{},description:t.description,fields:t.fields.filter(t=>t.name!==e&&!n.has(t.name)).map(q)}})}else if((a.schemaType===`union`||a.schemaType===`xor`)&&a.unionOptions){let e=a.unionOptions,t=m(e);l=a.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 l=a.fields.filter(e=>!e.positional).map(q)}let g=n?.globalExtracted?.fields.length?n.globalExtracted.fields.filter(e=>!e.positional).map(q):void 0,_;if(e.subCommands){let i=V(e.subCommands);i.length>0&&(_=i.map(([i,a])=>{let o=v(a);if(!o)return{name:i,unresolved:!0};let s={commandPath:[...r,i],rootName:n?.rootName??e.name,rootVersion:n?.rootVersion,globalExtracted:n?.globalExtracted};return{name:i,aliases:o.aliases,data:Ue(o,{descriptions:t.descriptions,context:s})}}))}return{name:e.name??`command`,commandPath:r,rootName:n?.rootName,version:n?.rootVersion,aliasFor:n?.aliasFor,description:e.description,aliases:e.aliases,usage:He(e,n),builtinOptions:i,schemaType:s,positionals:c,options:l,discriminator:d,variants:p,unionOptions:h,globalOptions:g,subcommands:_,examples:e.examples,notes:e.notes,...e.requiredPackages?.length?{requiredPackages:e.requiredPackages.map(e=>({name:e.name,install:T(e),description:e.description}))}:{},agentHelp:t.agentHelp}}function We(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(` ${A.dim(t.desc).split(`
|
|
28
|
+
`).join(`
|
|
29
|
+
`)}`),n.push(` ${A.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 Ge=class extends Error{constructor(e){super(e),this.name=`PositionalConfigError`}},Ke=class extends Error{constructor(e){super(e),this.name=`ReservedAliasError`}},qe=class extends Error{constructor(e){super(e),this.name=`DuplicateFieldError`}},Je=class extends Error{constructor(e){super(e),this.name=`DuplicateAliasError`}},Ye=class extends Error{constructor(e){super(e),this.name=`CaseVariantCollisionError`}},Xe=class extends Error{constructor(e){super(e),this.name=`DuplicateNegationError`}},Ze=class extends Error{constructor(e){super(e),this.name=`ReservedFieldNameError`}},Qe=class extends Error{constructor(e){super(e),this.name=`DefaultSubCommandError`}},$e=class extends Error{constructor(e){super(e),this.name=`FieldTypeConflictError`}};function et(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 tt(e,n){let r=[],i=/* @__PURE__ */ new Map;for(let a of e.fields){let e=t(a.name),o=i.get(e);o&&o!==a.name&&r.push({commandPath:n,type:`case_variant_collision`,message:`Fields "${o}" and "${a.name}" are case variants of each other and would collide.`,field:a.name}),i.set(e,a.name)}return r}function nt(e,r){let i=[],a=/* @__PURE__ */ new Map,o=new Set(e.fields.map(e=>e.name)),s=new Set(e.fields.map(e=>e.cliName)),c=(e,t,n)=>{(o.has(e)||s.has(e))&&i.push({commandPath:r,type:`duplicate_alias`,message:`Alias "${e}" for field "${t}" conflicts with existing field name or CLI name "${e}".`,field:t});let c=a.get(e);if(c&&c!==t){let a=n?` (derived camelCase variant)`:``;i.push({commandPath:r,type:`duplicate_alias`,message:`Duplicate alias "${e}"${a} detected. Both "${c}" and "${t}" use the same alias.`,field:t})}a.set(e,t)};for(let r of e.fields){let e=n(r);if(e.length!==0){for(let n of e)if(c(n,r.name,!1),n.length>1&&n.includes(`-`)){let e=t(n);e!==n&&!o.has(e)&&c(e,r.name,!0)}}}return i}function rt(e,r){let i=[],a=/* @__PURE__ */ new Map,o=(e,t,n)=>{a.has(e)||a.set(e,{field:t,kind:n})};for(let r of e.fields){if(o(r.name,r.name,`field name`),r.name.includes(`-`)){let e=t(r.name);e!==r.name&&o(e,r.name,`field name`)}if(r.cliName!==r.name&&o(r.cliName,r.name,`CLI name`),r.cliName.includes(`-`)){let e=t(r.cliName);e!==r.cliName&&o(e,r.name,`CLI name`)}for(let e of n(r))if(o(e,r.name,`alias`),e.length>1&&e.includes(`-`)){let n=t(e);n!==e&&o(n,r.name,`alias`)}if(r.type===`boolean`&&r.negation===!0){let e=`no-${r.cliName}`;o(e,r.name,`default negation`);let n=t(r.cliName),i=`no${n[0]?.toUpperCase()??``}${n.slice(1)}`;i!==e&&o(i,r.name,`default negation`)}}let s=/* @__PURE__ */ new Map,c=(e,t,n)=>{let o=a.get(e);if(o){let a=n?` (derived camelCase variant)`:``,s=o.field===t?`the same field's own ${o.kind} "${e}"`:`${o.kind} "${e}" of field "${o.field}"`;i.push({commandPath:r,type:`duplicate_negation`,message:`Negation "${e}"${a} for field "${t}" conflicts with ${s}.`,field:t})}let c=s.get(e);if(c&&c!==t){let a=n?` (derived camelCase variant)`:``;i.push({commandPath:r,type:`duplicate_negation`,message:`Duplicate negation "${e}"${a} detected. Both "${c}" and "${t}" use the same negation name.`,field:t})}s.set(e,t)};for(let n of e.fields)if(typeof n.negation==`string`&&(c(n.negation,n.name,!1),n.negation.includes(`-`))){let e=t(n.negation);e!==n.negation&&c(e,n.name,!0)}return i}function it(e,t){let n=[e,...e.variants??[],...e.unionOptions??[]],r=/* @__PURE__ */ new Set;return n.flatMap(e=>at(e.fields,t)).filter(e=>!r.has(e.message)&&r.add(e.message))}function at(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 ot(e,t){let r=[];for(let a of e.fields){if(a.overrideBuiltinAlias!==!0)for(let e of n(a))(e===`h`||e===`H`)&&r.push({commandPath:t,type:`reserved_alias`,message:`Alias "${e}" is reserved for --${e===`h`?`help`:`help-all`}. To override this, set { overrideBuiltinAlias: true } for "${a.name}" and keep the alias where it is currently defined (in alias or hiddenAlias).`,field:a.name});let e=/* @__PURE__ */ new Set([a.cliName,...n(a)]);for(let n of e){if(!i.has(n))continue;let e=n===a.cliName;r.push({commandPath:t,type:`reserved_alias`,message:`${e?`Field "${a.name}"`:`Alias "${n}" for field "${a.name}"`} collides with the built-in --${n} option, which always takes precedence. Rename the field or its alias; this collision cannot be overridden.`,field:a.name})}}return r}function st(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 ct(e){let t=et(e,[]);if(t.length>0)throw new qe(`Duplicate field name "${t[0]?.field??`unknown`}" detected. Each field must have a unique name.`)}function lt(e){let t=nt(e,[]);if(t.length>0){let e=t[0];throw new Je(e.message)}}function ut(e){let t=it(e,[]);if(t.length>0){let e=t[0];throw new Ge(e.message)}}function dt(e,t){let n=ot(e,[]);if(n.length>0)throw new Ke(n[0].message)}function ft(e){let t=st(e,[]);if(t.length>0){let e=t[0];throw new Ze(e.message)}}function pt(e){let t=rt(e,[]);if(t.length>0){let e=t[0];throw new Xe(e.message)}}function mt(e){let t=tt(e,[]);if(t.length>0){let e=t[0];throw new Ye(e.message)}}function ht(e,t){if(e.type!==t.type||e.positional!==t.positional)return!1;let n=e.enumValues,r=t.enumValues;if(!n&&!r)return!0;if(!n||!r)return!1;let i=new Set(n),a=new Set(r);if(i.size!==a.size)return!1;for(let e of i)if(!a.has(e))return!1;return!0}function gt(e,n,r){let i=[],a=/* @__PURE__ */ new Map;for(let n of e.fields)a.set(t(n.name),n);for(let e of n.fields){let n=t(e.name),o=a.get(n);o&&(o.name===e.name?ht(o,e)||i.push({commandPath:r,type:`field_type_conflict`,message:`Global field "${o.name}" and command field "${e.name}" share the same name but have different definitions.`,field:e.name}):i.push({commandPath:r,type:`case_variant_collision`,message:`Global field "${o.name}" and command field "${e.name}" are case variants of each other and would collide.`,field:e.name}))}return i}function _t(e,t){let n=gt(e,t,[])[0];if(n)throw n.type===`case_variant_collision`?new Ye(n.message):new $e(n.message)}function vt(e,t,n){return[...et(e,n),...tt(e,n),...nt(e,n),...rt(e,n),...it(e,n),...ot(e,n),...st(e,n)]}function yt(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 bt(e){let t=yt(e,[]);if(t.length>0)throw new Qe(t[0].message)}function xt(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=S(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 St(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 Ct(e,t={}){return wt(e,t,!1)}async function wt(e,t,n){n||=!!e.requiredPackages?.length;let r=t.commandPath??[e.name],i=[],a=e.subCommands?Object.keys(e.subCommands).length>0:!1,o=t.globalArgs?l(t.globalArgs):void 0;if(e.args){let t=l(e.args);i.push(...vt(t,a,r)),o&&i.push(...gt(o,t,r))}if(i.push(...xt(e,r)),i.push(...yt(e,r)),e.subCommands)for(let[a,o]of Object.entries(e.subCommands)){let e=await C(o,e=>n||!!e.requiredPackages?.length);i.push(...St(a,e.name,r));let s=await wt(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 Tt(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 Et(e){let{aliasMap:t=/* @__PURE__ */ new Map,booleanFlags:r=/* @__PURE__ */ new Set,definedNames:i=/* @__PURE__ */ new Set,negationMap:a=/* @__PURE__ */ new Map,defaultNegationDisabledFields:o=/* @__PURE__ */ new Set}=I(e),s=/* @__PURE__ */ new Set;for(let t of e.fields)for(let e of n(t))e.length===1&&s.add(e);return{aliasMap:t,booleanFlags:r,definedNames:i,flagNames:new Set(e.fields.map(e=>e.name)),cliNames:new Set(e.fields.map(e=>e.cliName)),aliases:s,negationMap:a,defaultNegationDisabledFields:o}}function Dt(e,t){let{resolvedName:n,withoutDashes:r,isNegated:i,isCustomNegation:a,isSuppressedNegation:o}=P(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 Ot(e,t,n,r,i){return!e.includes(`=`)&&!i.has(t)&&!n&&r!==void 0&&!r.startsWith(`-`)}function J(e,t,n,r,i,a){let o=e[t];return a.push(o),Ot(o,n,r,e[t+1],i)?(a.push(e[t+1]),2):1}function kt(e,t,n){let r=Et(n),i=new Set(t),a=[],o=[],s=0;for(;s<e.length;){let t=e[s];if(t===`--`||At.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}=Dt(t,r);if(l){s+=J(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+=J(e,s,t,!1,r.booleanFlags,a);continue}}break}break}return{subCommandIndex:-1,globalTokensBefore:a,tokensAfterSubcommand:[],suppressedTokens:o}}const At=/* @__PURE__ */ new Set([`--help`,`-h`,`--help-all`,`-H`,`--help-json`,`--version`]);function jt(e,t,n={}){let r=n.stopOnSuppressedNegation===!0||t?.unknownKeysMode===`strict`,i=t?Et(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===`--`||At.has(n))return-1;if(n.startsWith(`--`)){let{resolvedName:a,isNegated:o,isGlobal:s,isSuppressedNegation:c}=Dt(n,i);if(s){Ot(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)){Ot(n,r,!1,e[t+1],i.booleanFlags)&&t++;continue}}return-1}return-1}function Mt(e,t){let n=jt(e,t);return n>=0?e[n]:void 0}function Nt(e,t,r={}){let i=w(t),o=[...i],s=o.length>0,c=s&&!t.run;if(s&&e.length>0){if(r.globalExtracted){let t=kt(e,o,r.globalExtracted);if(t.subCommandIndex>=0){let n=It(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 u;t.args&&(u=l(t.args),r.skipValidation||(ct(u),mt(u),lt(u),pt(u),ut(u),dt(u,s),ft(u),r.globalExtracted&&_t(r.globalExtracted,u)));let d=e,f,p=[];if(r.globalExtracted){let t=u?a(u):[],n=new Set(t.map(e=>e.name)),{separated:i,globalParsed:o,suppressedTokens:s}=Lt(e,r.globalExtracted,u&&{...u,fields:[...t,...u.fields.filter(e=>!n.has(e.name))]});d=i,f=o,p=s}let m=e.indexOf(`--`),h=m>=0?e.slice(0,m):e,g=u?.fields.some(e=>e.overrideBuiltinAlias===!0&&n(e).includes(`H`))??!1,_=u?.fields.some(e=>e.overrideBuiltinAlias===!0&&n(e).includes(`h`))??!1,v=h.includes(`--help-all`)||!g&&h.includes(`-H`),y=h.includes(`--help-json`),ee=!v&&!y&&(h.includes(`--help`)||!_&&h.includes(`-h`)),b=h.includes(`--version`);if(ee||v||y||b)return{helpRequested:ee,helpAllRequested:v,helpJsonRequested:y,versionRequested:b,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:[],rest:[],unknownFlags:[],unknownGlobalFlags:p,rawGlobalArgs:f};if(!u){let e=d.indexOf(`--`),t=e>=0?d.slice(0,e):d,i=e>=0?d.slice(e+1):[],a=e=>c&&e.startsWith(`-`)&&e!==`-`,o=new Set(r.globalExtracted?.fields.flatMap(e=>[e.name,e.cliName,...n(e)])),s=t.filter(a).flatMap(e=>Object.keys(F([e]).options)).filter(e=>!o.has(e));return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:t.filter(e=>!a(e)),rest:i,unknownFlags:s,unknownGlobalFlags:p,rawGlobalArgs:f}}let x=Pt(u,d,{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:p,extractedFields:u,matchesNoUnionOption:!0,rawGlobalArgs:f};let S=I(x),C=F(d,{...S,unknownFlagsTakeNoValue:c}),T=N(C,x),E=Y(T,x),D=x.fields.filter(e=>e.named),O=new Set(D.map(e=>e.name)),k=new Set(D.map(e=>e.cliName)),A=/* @__PURE__ */ new Set;for(let e of D)for(let t of n(e))A.add(t);if(r.globalExtracted)for(let e of r.globalExtracted.fields){O.add(e.name),k.add(e.cliName);for(let t of n(e))A.add(t)}let j=[];for(let e of Object.keys(C.options))!O.has(e)&&!k.has(e)&&!A.has(e)&&j.push(e);return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:T,positionals:C.positionals,rest:C.rest,unknownFlags:j,unknownGlobalFlags:p,extractedFields:u,optionFields:D,positionalSlotFields:M(x,C.options),rawGlobalArgs:f,envFallbackFields:E}}function Pt(e,t,n){let{discriminator:r,variants:i,unionOptions:a}=e;if(r&&i){let n=e=>{let n=N(F(t,I(e)),e);return Y(n,e),n},r=c(e,n);return r===e?i.some(t=>{let r=n({...e,fields:t.fields});return c(e,()=>r)!==e})?void 0:e:r}if(a){let r=a.flatMap(e=>{let r=Pt(e,t,n);return r?[r]:[]}),i=n.promptAvailable?r.filter(e=>Ft(e,t,void 0)):[],o=r.find(e=>Ft(e,t,n.inheritedNames))??(i.length===1?i[0]:void 0);return o&&{...e,fields:o.fields}}return e}function Y(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]=te(i,r.type),n.add(r.name);break}}return n}function Ft(e,t,r){let i=F(t,I(e)),a=e.fields.filter(e=>e.named),o=new Set(a.flatMap(e=>[e.name,e.cliName,...n(e)]));if(Object.keys(i.options).some(e=>!o.has(e)))return!1;let s=M(e,i.options),c=i.positionals.length+i.rest.length;if(!s.some(e=>e.type===`array`)&&c>s.length)return!1;let l=N(i,e);return e.fields.some(e=>e.type!==`boolean`&&[l[e.name]].flat().includes(!0))?!1:r===void 0||(Y(l,e),e.fields.every(e=>!e.required||l[e.name]!==void 0||r.has(e.name)))}function It(e,t){if(e.length===0)return{};let n=I(t),r=F(e,n);return N(r,t)}function Lt(e,r,i){let a=Et(r),o=new Set(i?.fields.map(e=>e.name)??[]),s=new Set(i?.fields.map(e=>e.cliName)??[]),c=i?I(i):void 0,l=new Set(c?.aliasMap?.keys()??[]),u=new Set(c?.negationMap?.keys()??[]),d=/* @__PURE__ */ new Set;for(let e of i?.fields??[])if(e.type===`boolean`&&e.negation===!0)for(let r of[e.cliName,...n(e)]){let e=`no-${r}`;d.add(e),d.add(t(e))}let f=[],p=[],m=[];for(let t=0;t<e.length;t++){let n=e[t];if(n===`--`){p.push(...e.slice(t));break}if(n.startsWith(`--`)){let{resolvedName:r,withoutDashes:i,isNegated:c,isGlobal:p,isSuppressedNegation:h}=Dt(n,a),g=r,_=o.has(i)||o.has(g)||s.has(i)||s.has(g)||l.has(i)||l.has(g)||u.has(i)||u.has(g)||d.has(i);if(p&&!_){t+=J(e,t,r,c,a.booleanFlags,f)-1;continue}if(h&&!_){m.push(i);continue}}else if(n.startsWith(`-`)&&n.length>1){let r=n.includes(`=`)?n.slice(1,n.indexOf(`=`)):n.slice(1);if(r.length===1){let n=a.aliasMap.get(r)??r;if((a.aliases.has(r)||a.flagNames.has(n))&&!l.has(r)){t+=J(e,t,n,!1,a.booleanFlags,f)-1;continue}}}p.push(n)}return{separated:p,globalParsed:It(f,r),suppressedTokens:m}}function Rt(e,t){return s(t)?d(e,t):r().validate(e,t)}function X(e){return e.map(e=>`${e.path.length>0?`${e.path.join(`.`)}: `:``}${e.message}`).join(`
|
|
33
|
+
`)}function zt(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 Bt(e,t){let n=Math.max(2,Math.floor(e.length/2));return t.map(t=>({candidate:t,distance:zt(e.toLowerCase(),t.toLowerCase())})).filter(({distance:e})=>e<=n).sort((e,t)=>e.distance-t.distance).map(({candidate:e})=>e).slice(0,3)}function Vt(e,t){let n=Bt(e.replace(/^-{1,2}/,``),t),r=`${A.warning(`Warning: Unknown option:`)} ${A.bold(e)}`;if(n.length>0){r+=`\n\n${A.info(`Did you mean?`)}`;for(let e of n)r+=`\n ${k.arrow} ${A.option(`--${e}`)}`}return r}function Ht(e,t){return t&&e.stack?`${A.error(`Error:`)} ${e.message}\n\n${A.dim(e.stack)}`:`${A.error(`Error:`)} ${e.message}`}function Z(n){return new Proxy(n,{get(n,r,i){if(typeof r==`string`){if(r in n)return Reflect.get(n,r,i);let a=t(r);if(a!==r&&a in n)return Reflect.get(n,a,i);let o=e(r);if(o!==r&&o in n)return Reflect.get(n,o,i)}return Reflect.get(n,r,i)},has(n,r){if(typeof r==`string`){if(r in n)return!0;let i=t(r);if(i!==r&&i in n)return!0;let a=e(r);if(a!==r&&a in n)return!0}return Reflect.has(n,r)}})}async function Q(e,t,n){for(let r of t.fields)r.effect&&await r.effect(e[r.name],{name:r.name,args:e,...n!=null&&{globalArgs:n}})}const Ut={log:e=>console.log(e),error:e=>console.error(e),warn:e=>console.warn(e)};function Wt(n,r){Object.defineProperty(n,"$source",{value:n=>r.get(n)??r.get(t(n))??r.get(e(n))??`default`,enumerable:!1})}function Gt(e,t){Object.defineProperty(e,"$invocation",{value:t,enumerable:!1})}function Kt(e,t){Object.defineProperty(e,"$agent",{value:t,enumerable:!1})}function qt(e,t){return e&&(n=>e({...n,agent:t}))}function Jt(e,t){let{agentHelp:n,_agent:r}=e;if(n&&r)return typeof n==`string`?n:n({agent:r,commandPath:t.commandPath??[]})}function Yt(e,t){let n=t.commandPath?.at(-1)??e.name;return t.aliasFor?{name:n,aliasFor:t.aliasFor}:{name:n}}async function Xt(e,t,n={}){let r=en(n),i=h(),a=qt(n.cleanup,i),o=n.captureLogs??!1,s=o?O():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()??E()}}s?.stop()}let c=await $(e,t,{...n,handleSignals:!1,_globalExtracted:r,_globalCleanup:a,_existingLogs:s?.getLogs(),_agent:i});if(a){let e=o?O():null;e?.start();let t={error:c.success?void 0:c.error};try{await a(t)}catch(t){if(c.success){let n=t instanceof Error?t:Error(String(t));return e?.stop(),{success:!1,error:n,exitCode:1,logs:D(c.logs,e?.getLogs()??E())}}}e?.stop();let n=e?.getLogs()??E();if(n.entries.length>0)return{...c,logs:D(c.logs,n)}}return c}function Zt(e,t,n){let r=Mt(t,n);return!r||!r.startsWith(`__`)?!1:Object.hasOwn(e.subCommands??{},r)}async function Qt(e,t={}){if(t.compileCache!==!1&&g(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=l(t.globalArgs)}catch{}let i=t;if(Zt(e,n,r)){let{setup:e,cleanup:n,prompt:r,globalArgs:a,...o}=t;i=o}let a=en(i),o=h(),s=qt(i.cleanup,o);if(i.skipValidation||bt(e),i.onUnknownSubcommand&&!e.run&&!Zt(e,n,r)){let t=w(e);if(t.size>0){let e=jt(n,a,{stopOnSuppressedNegation:a?.unknownKeysMode!==`passthrough`}),r=e>=0?n[e]:void 0;if(r&&!t.has(r)){let t=n.slice(e+1),a=await i.onUnknownSubcommand({commandPath:[],name:r,args:t,precedingArgs:n.slice(0,e)});if(typeof a==`number`)return await $t(),process.exit(a)}}}if(i.setup)try{await i.setup({agent:o})}catch(e){let t=e instanceof Error?e:Error(String(e));if(s)try{await s({error:t})}catch{}process.exit(1)}let c=await $(e,n,{debug:i.debug,captureLogs:i.captureLogs,skipValidation:i.skipValidation,handleSignals:!0,logger:i.logger,globalArgs:i.globalArgs,prompt:i.prompt,onUnknownSubcommand:i.onUnknownSubcommand,agentHelp:i.agentHelp,_globalExtracted:a,_globalCleanup:s,_agent:o,_context:{commandPath:[],rootName:e.name,rootVersion:i.version,globalExtracted:a}});if((i.displayErrors??!0)&&!c.success&&c.error&&(i.logger??Ut).error(Ht(c.error,i.debug??!1)),s){let e={error:c.success?void 0:c.error};try{await s(e)}catch{}}await $t(),process.exit(c.exitCode)}async function $t(){await Promise.all([process.stdout,process.stderr].map(e=>e.writableLength>0?new Promise(t=>e.write(``,()=>t())):Promise.resolve()))}async function $(e,t,n={}){let r=n.logger??Ut,i=n._context??{commandPath:[],rootName:e.name,globalExtracted:n._globalExtracted},a=n.captureLogs??!1?O():null;a?.start();let o=()=>{let e=n._existingLogs??E(),t=a?.getLogs()??E();return D(e,t)};try{n.skipValidation||bt(e);let s=Nt(t,e,{skipValidation:n.skipValidation,globalExtracted:n._globalExtracted,promptAvailable:n.prompt!==void 0,inheritedNames:new Set(Object.keys(n._parsedGlobalArgs??{}))}),l={...n._parsedGlobalArgs,...s.rawGlobalArgs},u=i.commandPath??[];if(n.onUnknownSubcommand&&!e.run&&u.length>0){let r=w(e);if(r.size>0){let e=jt(t,n._globalExtracted,{stopOnSuppressedNegation:n._globalExtracted?.unknownKeysMode!==`passthrough`}),i=e>=0?t[e]:void 0;if(i&&!r.has(i)){let r=t.slice(e+1),s=await n.onUnknownSubcommand({commandPath:u,name:i,args:r,precedingArgs:[...n._precedingArgs??[],...t.slice(0,e)]});if(typeof s==`number`){if(a?.stop(),n.handleSignals){if(n._globalCleanup)try{await n._globalCleanup({error:void 0})}catch{}await $t(),process.exit(s)}return s===0?{success:!0,result:void 0,exitCode:0,logs:o()}:{success:!1,error:/* @__PURE__ */ Error(`Plugin "${[...u,i].join(` `)}" exited with code ${s}`),exitCode:s,logs:o()}}}}}if(s.helpRequested||s.helpAllRequested||s.helpJsonRequested){let c=!1,l=x(e),u=w(e);if(l.length>0){let e=Mt(t,i.globalExtracted);e&&!u.has(e)&&(c=!0)}let d=Jt(n,i);if(s.helpJsonRequested){let t=Ue(e,{context:i,agentHelp:d});r.log(JSON.stringify(t))}else{let t=Ve(e,{showSubcommands:n.showSubcommands??!0,showSubcommandOptions:s.helpAllRequested||n.showSubcommandOptions,context:i,agentHelp:d});r.log(t)}if(a?.stop(),c){let e=Mt(t,i.globalExtracted)??``,n=Bt(e,[...u]),r=n.length>0?` Did you mean: ${n.join(`, `)}?`:``;return{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${e}${r?`.${r}`:``}`),exitCode:2,logs:o()}}return{success:!0,result:void 0,exitCode:0,logs:o()}}if(s.unknownGlobalFlags&&s.unknownGlobalFlags.length>0){let e=i.globalExtracted?.unknownKeysMode??`strip`;if(e===`strict`)return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown flags: ${s.unknownGlobalFlags.join(`, `)}`),exitCode:2,logs:o()};if(e===`strip`){let e=i.globalExtracted?.fields.map(e=>e.name)??[];for(let t of s.unknownGlobalFlags)r.error(Vt(t,e))}}if(s.versionRequested){let e=i.rootVersion;return e&&r.log(e),a?.stop(),{success:!0,result:void 0,exitCode:0,logs:o()}}if(s.subCommand){let r=n._metadataOnly??!1,c=await _(e,s.subCommand,e=>{if(r)return!0;if(!e.requiredPackages?.length)return!1;let t=e,a=s.remainingArgs;for(;;){let e=Nt(a,t,{skipValidation:n.skipValidation,globalExtracted:i.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:ee(t,e.subCommand)??e.subCommand,s=t.subCommands[o],c=s?v(s):null;if(!c)return!1;t=c,a=e.remainingArgs}});if(c){let e={commandPath:[...i.commandPath??[],s.subCommand],rootName:i.rootName,rootVersion:i.rootVersion,globalExtracted:i.globalExtracted,aliasFor:c.aliasFor};a?.stop();let u=new Set(n._globalExtracted?.unknownKeysMode===`passthrough`?[]:s.unknownGlobalFlags??[]),d=e=>e.startsWith(`--`)&&u.has(j(e)),f=t.slice(0,t.length-s.remainingArgs.length-1).filter(e=>!d(e));return $(c.command,s.remainingArgs,{...n,_metadataOnly:r,_context:e,_existingLogs:o(),_parsedGlobalArgs:l,_precedingArgs:[...n._precedingArgs??[],...f]})}}let d=s.positionalSlotFields??[],f=d.some(e=>e.type===`array`),p=[...s.positionals,...s.rest],m=f?[]:p.slice(d.length),h=f?[]:s.positionals.slice(d.length);if(s.matchesNoUnionOption)return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Arguments match none of the accepted forms. See --help for the accepted forms.`),exitCode:2,logs:o()};let g=w(e),y=g.size>0?h.find(e=>!e.startsWith(`-`)&&!g.has(e)):void 0;if(y){let e=Bt(y,[...g]),t=e.length>0?` Did you mean: ${e.join(`, `)}?`:``;return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${y}${t?`.${t}`:``}`),exitCode:2,logs:o()}}if(s.unknownFlags.length>0){let e=s.extractedFields?.unknownKeysMode??i.globalExtracted?.unknownKeysMode??`strip`,t=s.optionFields?.map(e=>e.name)??i.globalExtracted?.fields.map(e=>e.name)??[];if(e===`strict`)return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown flags: ${s.unknownFlags.join(`, `)}`),exitCode:2,logs:o()};if(e===`strip`)for(let e of s.unknownFlags)r.error(Vt(e,t))}if(x(e).length>0&&!s.subCommand&&!e.run&&m.length===0){if(e.defaultSubCommand){let r=e.subCommands?.[e.defaultSubCommand];if(r){let c=await C(r),u={commandPath:[...i.commandPath??[],e.defaultSubCommand],rootName:i.rootName,rootVersion:i.rootVersion,globalExtracted:i.globalExtracted};a?.stop();let d=new Set(n._globalExtracted?.unknownKeysMode===`passthrough`?[]:s.unknownGlobalFlags??[]),f=e=>e.startsWith(`--`)&&d.has(j(e)),p=t.filter(e=>!f(e));return $(c,[],{...n,_context:u,_existingLogs:o(),_parsedGlobalArgs:l,_precedingArgs:[...n._precedingArgs??[],...p]})}}if(n.globalArgs&&n._globalExtracted){let e={...l};Y(e,n._globalExtracted);let t=Rt(e,n.globalArgs),r=t.success?[]:t.errors.filter(t=>t.path[0]&&e[t.path[0]]!==void 0);if(r.length>0)return a?.stop(),{success:!1,error:Error(X(r)),exitCode:2,logs:o()}}let c=Ve(e,{showSubcommands:n.showSubcommands??!0,context:i,agentHelp:Jt(n,i)});return r.log(c),a?.stop(),{success:!0,result:void 0,exitCode:0,logs:o()}}if(m.length>0){let e=s.extractedFields?.unknownKeysMode??`strip`;if(e===`strict`)return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unexpected positional argument${m.length>1?`s`:``}: ${m.join(`, `)}`),exitCode:2,logs:o()};if(e===`strip`)for(let e of m)(r.warn??r.error)(`Warning: Unexpected positional argument: ${e}`)}let b={},S=e.name===`__complete`,T=new Set(Object.keys(l)),E=/* @__PURE__ */ new Set;if(n.globalArgs&&n._globalExtracted&&!S){if(E=Y(l,n._globalExtracted),n.prompt){let e=await n.prompt(l,n._globalExtracted);for(let[t,n]of Object.entries(e))n!==void 0&&(l[t]=n)}let e=Rt(l,n.globalArgs);if(!e.success)return a?.stop(),{success:!1,error:Error(X(e.errors)),exitCode:2,logs:o()};b=e.data}if(!e.args){let t=/* @__PURE__ */ new Map;for(let e of T)t.set(e,`cli`);for(let e of E)t.set(e,`env`);Wt(b,t),Gt(b,Yt(e,i)),Kt(b,n._agent);let r=Z(b);return n._globalExtracted&&!S&&await Q(r,n._globalExtracted,r),a?.stop(),await re(e,r,{handleSignals:n.handleSignals,captureLogs:n.captureLogs,existingLogs:o(),globalCleanup:n._globalCleanup,packageDiscriminators:n._globalExtracted?.discriminator?[n._globalExtracted.discriminator]:[],packageFields:S||!n._globalExtracted?void 0:c(n._globalExtracted,()=>b).fields})}let D=s.rawArgs,O=/* @__PURE__ */ new Set;if(n.prompt&&s.extractedFields){let e=await n.prompt(D,s.extractedFields),t={...D};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r,O.add(n));D=t}let k=/* @__PURE__ */ new Set;if(s.extractedFields)for(let e of s.extractedFields.fields)!(Object.hasOwn(s.rawArgs,e.name)||O.has(e.name))&&T.has(e.name)&&Object.hasOwn(b,e.name)&&(D={...D,[e.name]:b[e.name]},k.add(e.name));let A=Rt(D,e.args);if(!A.success)return a?.stop(),{success:!1,error:Error(X(A.errors)),exitCode:2,logs:o()};let te=Z(A.data),M=/* @__PURE__ */ new Map;for(let e of T)M.set(e,`cli`);for(let e of E)M.set(e,`env`);Wt(b,M),Gt(b,Yt(e,i)),Kt(b,n._agent);let N=Z(b);n._globalExtracted&&!S&&await Q(N,n._globalExtracted,N),s.extractedFields&&!S&&await Q(te,s.extractedFields,N);let P={...N,...te},F=new Map(M),I=s.envFallbackFields??/* @__PURE__ */ new Set;for(let e of s.extractedFields?.fields??[]){if(k.has(e.name)){F.set(e.name,`cli`);continue}let t=Object.hasOwn(s.rawArgs,e.name)||I.has(e.name);F.set(e.name,t?I.has(e.name)?`env`:`cli`:`default`)}Wt(P,F),Gt(P,Yt(e,i)),Kt(P,n._agent);let ne=Z(P);return a?.stop(),await re(e,ne,{handleSignals:n.handleSignals,captureLogs:n.captureLogs,existingLogs:o(),globalCleanup:n._globalCleanup,packageDiscriminators:[s.extractedFields?.discriminator,n._globalExtracted?.discriminator].filter(e=>e!==void 0),packageFields:S?void 0:[...n._globalExtracted?c(n._globalExtracted,()=>b).fields:[],...s.optionFields??[],...s.positionalSlotFields??[]]})}catch(e){let t=e instanceof Error?e:Error(String(e));return a?.stop(),{success:!1,error:t,exitCode:1,logs:o()}}}function en(e){if(!e.globalArgs)return;let t=l(e.globalArgs);if(!e.skipValidation){ct(t),mt(t),lt(t),pt(t),dt(t,!0),ft(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{Ke as C,L as D,Ue as E,le as O,Ge as S,Ve as T,Qe as _,Tt as a,Xe as b,_t as c,ct as d,pt as f,Ye as g,ft as h,X as i,bt as l,dt as m,Qt as n,mt as o,ut as p,Z as r,Ct as s,Xt as t,lt as u,Je as v,Ze as w,$e as x,qe as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e,u as t}from"./schema-extractor-
|
|
1
|
+
import{d as e,u as t}from"./schema-extractor-lB6-WHOF.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{o as e,r as t}from"./field-meta-CEtC5Mir.js";const n=`__polittyInternalArgs`,r={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 i(e,t={}){return{[n]:!0,fields:e,unknownKeys:t.unknownKeys??`strip`}}function a(e){return typeof e==`object`&&!!e&&e[n]===!0}const o={string:`string`,boolean:`boolean`,enum:`string`,"string-array":`array`},s=/* @__PURE__ */ new WeakMap;function c(e){let n=s.get(e);if(n)return n;let r={fields:Object.entries(e.fields).map(([e,n])=>t(e,{argMeta:n.meta,description:void 0,required:!n.optional&&n.defaultValue===void 0,defaultValue:n.defaultValue,type:o[n.kind],enumValues:n.enumValues?[...n.enumValues]:void 0,schema:n})),schema:e,schemaType:`object`,unknownKeysMode:e.unknownKeys};return s.set(e,r),r}function l(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 u(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e}function d(e,t,n){return{path:[e],message:`Invalid input: expected ${l(t)}, received ${u(n)}`,code:`invalid_type`,received:n,expected:l(t)}}function f(e,t,n){switch(t.kind){case`string`:return typeof n==`string`?null:d(e,t,n);case`boolean`:return typeof n==`boolean`?null:d(e,t,n);case`enum`:return typeof n!=`string`||!(t.enumValues??[]).includes(n)?{path:[e],message:`Invalid option: expected ${l(t)}`,code:`invalid_value`,received:n,expected:l(t)}:null;case`string-array`:return!Array.isArray(n)||n.some(e=>typeof e!=`string`)?d(e,t,n):null}}function p(e,t){let n=[],r={};for(let[i,a]of Object.entries(t.fields)){let t=e[i];if(t===void 0){a.defaultValue===void 0?a.optional||n.push(d(i,a,void 0)):r[i]=Array.isArray(a.defaultValue)?[...a.defaultValue]:a.defaultValue;continue}let o=f(i,a,t);o?n.push(o):r[i]=t}let i=new Set(Object.keys(t.fields)),a=Object.keys(e).filter(e=>!i.has(e));if(a.length>0){if(t.unknownKeys===`strict`)n.push({path:[],message:`Unrecognized key${a.length>1?`s`:``}: ${a.map(e=>JSON.stringify(e)).join(`, `)}`,code:`unrecognized_keys`});else if(t.unknownKeys===`passthrough`)for(let t of a)Object.defineProperty(r,t,{value:e[t],enumerable:!0,writable:!0,configurable:!0})}return n.length>0?{success:!1,errors:n}:{success:!0,data:r}}function m(t){return a(t)?t.unknownKeys:e().getUnknownKeysMode(t)}const h=/* @__PURE__ */ new WeakSet;function g(t){let n=a(t)?c(t):e().extractFields(t);return h.has(n)||(_(n),h.add(n)),n}function _(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??[])_(t)}function v(e){return e.args?g(e.args):null}function y(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 x(e){let t=w(e).filter(e=>e.named);return T(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 S(e){return T(e,e=>e.positional)}function C(e){return T(e,e=>!e.positional)}function w(e){let t=e.variants??e.unionOptions??[];return[e.fields,...t.map(e=>e.fields)].flat()}function T(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 E(e,t){let{discriminator:n,variants:r}=e;if(!n||!r){let n=e.unionOptions??[],r=n.map(e=>E(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 D(e,t){return C(e).find(e=>e.name===t)}export{x as a,S as c,r as d,a as f,m as i,E as l,g as n,D as o,p,v as r,C as s,y as t,i as u};
|
package/dist/skill.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as UnknownKeysMode, a as ArgsSchema, r as AnyCommand } from "./types-
|
|
1
|
+
import { L as UnknownKeysMode, a as ArgsSchema, r as AnyCommand } from "./types-DtQ-Zt3n.js";
|
|
2
2
|
//#region ../core/src/skill/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* SKILL.md frontmatter metadata, validated against the Agent Skills
|
package/dist/skill.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./register-BtPBdvwq.js";import{d as e,n as t,u as n}from"./schema-extractor-BkbKiMq_.js";import{n as r}from"./command-BXsTrIgI.js";import{a as i,n as a}from"./logger-CoeDrmRr.js";import{copyFileSync as o,existsSync as s,lstatSync as c,mkdirSync as l,mkdtempSync as u,readFileSync as d,readdirSync as f,readlinkSync as p,realpathSync as m,renameSync as ee,rmSync as h,statSync as g,symlinkSync as te,unlinkSync as _}from"node:fs";import{basename as v,dirname as y,isAbsolute as b,join as x,parse as ne,relative as S,resolve as C,sep as w}from"node:path";import{parse as re}from"yaml";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];if(i===void 0){r.required&&t.push({path:[n],message:`Invalid input: expected string, received undefined`});return}if(typeof i!=`string`){t.push({path:[n],message:`Invalid input: expected string, received ${T(i)}`});return}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`})};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);return}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});return}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);return}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)}return}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);if(s.kind===`error`){n.push({path:i,reason:`read-failed`,message:`Failed to check ${o}: ${s.message}`});continue}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){if(i.reason===`missing-source`||i.path===t.sourceDir){r=!0,a.warn(`Failed to scan source directory ${i.path}: ${i.message}`);continue}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(t){function i(e,n){let{skills:r,errors:i}=W(t),o=t.stamp,s=new Set(r.map(e=>e.frontmatter.name)),c=new Set(Pe(o,t.cwd,t.sourceDir)),l=Array.from(new Set(e.exclude)).filter(e=>!s.has(e)&&!c.has(e));if(l.length>0){let e=l.length===1?`Skill`:`Skills`,t=l.map(e=>JSON.stringify(e)).join(`, `);throw Error(`--exclude: ${e} ${t} not found in source directory or among installed skills.\n`+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},t.sourceDir),p=0;if(!f){let e=new Set(d.map(e=>e.frontmatter.name)),n=/* @__PURE__ */ new Set;for(let e of i)e.path!==t.sourceDir&&(n.add(v(e.path)),e.skillName!==void 0&&n.add(e.skillName));for(let r of c)e.has(r)||u.has(r)||n.has(r)||(X(r,o,t.cwd,t.sourceDir),p+=1)}let m=0;for(let e of d)Y(e,o,t,n),m+=1;if(m===0&&p===0){let e=f?`source directory scan failed; see warnings`:r.length>0&&d.length===0?`all skills excluded`:`no skills bundled`;a.info(`No skills installed (${e}).`)}else a.info(`Sync complete: ${m} installed, ${p} removed.`)}return t.verbose.disabled?r({name:`sync`,description:t.descriptions.sync,args:n({exclude:e.stringArray(Ce(t))},{unknownKeys:t.unknownKeys}),run(e){i(e,K(e,`verbose`))}}):r({name:`sync`,description:t.descriptions.sync,args:n({exclude:e.stringArray(Ce(t)),verbose:e.boolean(G(t))},{unknownKeys:t.unknownKeys}),run(e){i(e,e.verbose)}})}function Te(t){let i={positional:!0,description:`Skill name(s) to install (default: all)`,placeholder:`NAME`};function o(e,n){let r=W(t),i=r.skills,o=t.stamp;if(e.name.length>0){let r=new Set(i.map(e=>e.frontmatter.name)),a=Array.from(new Set(e.name)),s=a.filter(e=>!r.has(e));if(s.length>0){let e=s.length===1?`Skill`:`Skills`,t=s.map(e=>JSON.stringify(e)).join(`, `);throw Error(`${e} ${t} not found in source directory.\n`+J({source:i}))}let c=new Set(a);for(let e of i)c.has(e.frontmatter.name)&&Y(e,o,t,n);return}if(i.length===0){U(r,t.sourceDir)?a.info(`No skills installed (source directory scan failed; see warnings).`):a.info(`No skills found in source directory.`);return}for(let e of i)Y(e,o,t,n)}return t.verbose.disabled?r({name:t.commandNames.add.name,...t.commandNames.add.aliases.length>0?{aliases:t.commandNames.add.aliases}:{},description:t.descriptions.add,args:n({name:e.stringArray(i)},{unknownKeys:t.unknownKeys}),run(e){o(e,K(e,`verbose`))}}):r({name:t.commandNames.add.name,...t.commandNames.add.aliases.length>0?{aliases:t.commandNames.add.aliases}:{},description:t.descriptions.add,args:n({name:e.stringArray(i),verbose:e.boolean(G(t))},{unknownKeys:t.unknownKeys}),run(e){o(e,e.verbose)}})}function Ee(t){return r({name:t.commandNames.remove.name,...t.commandNames.remove.aliases.length>0?{aliases:t.commandNames.remove.aliases}:{},description:t.descriptions.remove,args:n({name:e.optionalString({positional:!0,description:`Skill name to remove (default: all)`,placeholder:`NAME`})},{unknownKeys:t.unknownKeys}),run(e){let n=W(t),r=n.skills,i=t.stamp;if(e.name){if(r.some(t=>t.frontmatter.name===e.name)&&Ae(r,e.name),!X(e.name,i,t.cwd,t.sourceDir)){if(q(e.name,t.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 n=new Set(Pe(i,t.cwd,t.sourceDir));a.info(`${e.name} is not installed; nothing to remove.\n`+J({installed:n}))}}return}if(r.length===0){U(n,t.sourceDir)?a.info(`No skills found (source directory scan failed; see warnings); nothing to remove.`):a.info(`No skills found in source directory; nothing to remove.`);return}let o=0;for(let e of r)X(e.frontmatter.name,i,t.cwd,t.sourceDir)&&(o+=1);o===0&&a.info(`No installed skills owned by this CLI; nothing to remove.`)}})}function 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(t){function i(e){let n=W(t,{silentStdout:e}),r=n.skills,i=t.stamp;if(e){console.log(JSON.stringify(r.map(e=>({name:e.frontmatter.name,description:e.frontmatter.description,owner:e.frontmatter.metadata?.[`politty-cli`]??null,expectedOwner:i,status:De(e.frontmatter.name,i,t.cwd,t.sourceDir),sourcePath:e.sourcePath}))));return}if(r.length===0){U(n,t.sourceDir)?a.info(`Source directory scan failed; see warnings.`):a.info(`No skills found in source directory.`);return}a.info(`Available skills:`);for(let e of r){let n=De(e.frontmatter.name,i,t.cwd,t.sourceDir);a.info(` ${e.frontmatter.name.padEnd(20)} ${n.padEnd(14)} ${e.frontmatter.description}`)}}return t.json.disabled?r({name:`list`,description:t.descriptions.list,args:n({},{unknownKeys:t.unknownKeys}),run(e){i(K(e,`json`))}}):r({name:`list`,description:t.descriptions.list,args:n({json:e.boolean({description:`Output as JSON`})},{unknownKeys:t.unknownKeys}),run(e){i(e.json)}})}function 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"./register-BtPBdvwq.js";import{d as e,n as t,u as n}from"./schema-extractor-lB6-WHOF.js";import{n as r}from"./command-BXsTrIgI.js";import{a as i,n as a}from"./logger-CoeDrmRr.js";import{copyFileSync as o,existsSync as s,lstatSync as c,mkdirSync as l,mkdtempSync as u,readFileSync as d,readdirSync as f,readlinkSync as p,realpathSync as m,renameSync as ee,rmSync as h,statSync as g,symlinkSync as te,unlinkSync as _}from"node:fs";import{basename as v,dirname as y,isAbsolute as b,join as x,parse as ne,relative as S,resolve as C,sep as w}from"node:path";import{parse as re}from"yaml";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(t){function i(e,n){let{skills:r,errors:i}=W(t),o=t.stamp,s=new Set(r.map(e=>e.frontmatter.name)),c=new Set(Pe(o,t.cwd,t.sourceDir)),l=Array.from(new Set(e.exclude)).filter(e=>!s.has(e)&&!c.has(e));if(l.length>0){let e=l.length===1?`Skill`:`Skills`,t=l.map(e=>JSON.stringify(e)).join(`, `);throw Error(`--exclude: ${e} ${t} not found in source directory or among installed skills.\n`+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},t.sourceDir),p=0;if(!f){let e=new Set(d.map(e=>e.frontmatter.name)),n=/* @__PURE__ */ new Set;for(let e of i)e.path!==t.sourceDir&&(n.add(v(e.path)),e.skillName!==void 0&&n.add(e.skillName));for(let r of c)e.has(r)||u.has(r)||n.has(r)||(X(r,o,t.cwd,t.sourceDir),p+=1)}let m=0;for(let e of d)Y(e,o,t,n),m+=1;if(m===0&&p===0){let e=f?`source directory scan failed; see warnings`:r.length>0&&d.length===0?`all skills excluded`:`no skills bundled`;a.info(`No skills installed (${e}).`)}else a.info(`Sync complete: ${m} installed, ${p} removed.`)}return t.verbose.disabled?r({name:`sync`,description:t.descriptions.sync,args:n({exclude:e.stringArray(Ce(t))},{unknownKeys:t.unknownKeys}),run(e){i(e,K(e,`verbose`))}}):r({name:`sync`,description:t.descriptions.sync,args:n({exclude:e.stringArray(Ce(t)),verbose:e.boolean(G(t))},{unknownKeys:t.unknownKeys}),run(e){i(e,e.verbose)}})}function Te(t){let i={positional:!0,description:`Skill name(s) to install (default: all)`,placeholder:`NAME`};function o(e,n){let r=W(t),i=r.skills,o=t.stamp;if(e.name.length>0){let r=new Set(i.map(e=>e.frontmatter.name)),a=Array.from(new Set(e.name)),s=a.filter(e=>!r.has(e));if(s.length>0){let e=s.length===1?`Skill`:`Skills`,t=s.map(e=>JSON.stringify(e)).join(`, `);throw Error(`${e} ${t} not found in source directory.\n`+J({source:i}))}let c=new Set(a);for(let e of i)c.has(e.frontmatter.name)&&Y(e,o,t,n)}else if(i.length===0)U(r,t.sourceDir)?a.info(`No skills installed (source directory scan failed; see warnings).`):a.info(`No skills found in source directory.`);else for(let e of i)Y(e,o,t,n)}return t.verbose.disabled?r({name:t.commandNames.add.name,...t.commandNames.add.aliases.length>0?{aliases:t.commandNames.add.aliases}:{},description:t.descriptions.add,args:n({name:e.stringArray(i)},{unknownKeys:t.unknownKeys}),run(e){o(e,K(e,`verbose`))}}):r({name:t.commandNames.add.name,...t.commandNames.add.aliases.length>0?{aliases:t.commandNames.add.aliases}:{},description:t.descriptions.add,args:n({name:e.stringArray(i),verbose:e.boolean(G(t))},{unknownKeys:t.unknownKeys}),run(e){o(e,e.verbose)}})}function Ee(t){return r({name:t.commandNames.remove.name,...t.commandNames.remove.aliases.length>0?{aliases:t.commandNames.remove.aliases}:{},description:t.descriptions.remove,args:n({name:e.optionalString({positional:!0,description:`Skill name to remove (default: all)`,placeholder:`NAME`})},{unknownKeys:t.unknownKeys}),run(e){let n=W(t),r=n.skills,i=t.stamp;if(e.name){if(r.some(t=>t.frontmatter.name===e.name)&&Ae(r,e.name),!X(e.name,i,t.cwd,t.sourceDir)){if(q(e.name,t.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 n=new Set(Pe(i,t.cwd,t.sourceDir));a.info(`${e.name} is not installed; nothing to remove.\n`+J({installed:n}))}}return}if(r.length===0){U(n,t.sourceDir)?a.info(`No skills found (source directory scan failed; see warnings); nothing to remove.`):a.info(`No skills found in source directory; nothing to remove.`);return}let o=0;for(let e of r)X(e.frontmatter.name,i,t.cwd,t.sourceDir)&&(o+=1);o===0&&a.info(`No installed skills owned by this CLI; nothing to remove.`)}})}function 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(t){function i(e){let n=W(t,{silentStdout:e}),r=n.skills,i=t.stamp;if(e)console.log(JSON.stringify(r.map(e=>({name:e.frontmatter.name,description:e.frontmatter.description,owner:e.frontmatter.metadata?.[`politty-cli`]??null,expectedOwner:i,status:De(e.frontmatter.name,i,t.cwd,t.sourceDir),sourcePath:e.sourcePath}))));else if(r.length===0)U(n,t.sourceDir)?a.info(`Source directory scan failed; see warnings.`):a.info(`No skills found in source directory.`);else{a.info(`Available skills:`);for(let e of r){let n=De(e.frontmatter.name,i,t.cwd,t.sourceDir);a.info(` ${e.frontmatter.name.padEnd(20)} ${n.padEnd(14)} ${e.frontmatter.description}`)}}}return t.json.disabled?r({name:`list`,description:t.descriptions.list,args:n({},{unknownKeys:t.unknownKeys}),run(e){i(K(e,`json`))}}):r({name:`list`,description:t.descriptions.list,args:n({json:e.boolean({description:`Output as JSON`})},{unknownKeys:t.unknownKeys}),run(e){i(e.json)}})}function 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,n){return e?t(e).fields.some(e=>e.name===n&&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};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readFileSync as e,statSync as t}from"node:fs";import{dirname as n,join as r}from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";const o={npm:`npm install`,pnpm:`pnpm add`,yarn:`yarn add`,bun:`bun add`},s=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`],[`npm-shrinkwrap.json`,`npm`]];function c(a){if(a.install!==void 0)return a.install;let c=a.from?new URL(a.from):void 0,l=c?.protocol===`file:`?i(new URL(`.`,c)):process.cwd(),u=`npm`;for(;;){try{let t=JSON.parse(e(r(l,`package.json`),`utf8`));if(typeof t==`object`&&t&&`packageManager`in t&&typeof t.packageManager==`string`){let e=t.packageManager.split(`@`)[0];if(e===`npm`||e===`pnpm`||e===`yarn`||e===`bun`){u=e;break}}}catch{}let i=s.find(([e])=>{try{return t(r(l,e)).isFile()}catch{return!1}});if(i){u=i[1];break}let a=n(l);if(a===l)break;l=a}return`${o[u]} -D ${a.name}`}async function l(e){let{resolve:t}=await import(`./import-meta-resolve-
|
|
1
|
+
import{readFileSync as e,statSync as t}from"node:fs";import{dirname as n,join as r}from"node:path";import{fileURLToPath as i,pathToFileURL as a}from"node:url";const o={npm:`npm install`,pnpm:`pnpm add`,yarn:`yarn add`,bun:`bun add`},s=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`],[`npm-shrinkwrap.json`,`npm`]];function c(a){if(a.install!==void 0)return a.install;let c=a.from?new URL(a.from):void 0,l=c?.protocol===`file:`?i(new URL(`.`,c)):process.cwd(),u=`npm`;for(;;){try{let t=JSON.parse(e(r(l,`package.json`),`utf8`));if(typeof t==`object`&&t&&`packageManager`in t&&typeof t.packageManager==`string`){let e=t.packageManager.split(`@`)[0];if(e===`npm`||e===`pnpm`||e===`yarn`||e===`bun`){u=e;break}}}catch{}let i=s.find(([e])=>{try{return t(r(l,e)).isFile()}catch{return!1}});if(i){u=i[1];break}let a=n(l);if(a===l)break;l=a}return`${o[u]} -D ${a.name}`}async function l(e){let{resolve:t}=await import(`./import-meta-resolve-DQ_owo_7.js`),n=e.from?.toString()??a(r(process.cwd(),`package.json`)).href,i;try{i=t(e.name,n)}catch(t){throw t instanceof Error&&`code`in t&&t.code===`ERR_MODULE_NOT_FOUND`&&t.message.startsWith(`Cannot find package '${e.name}' imported from `)?Error(`Package "${e.name}" is required. Install it with: ${c(e)}`,{cause:t}):t}return import(i)}async function u(e,t){for(let n of e??[])(!n.when||n.when(t))&&await l(n)}function d(e){return(e??[]).map(e=>`${e.description?`${e.description}: `:``}Requires ${e.name}; install with: ${c(e)}`).join(`
|
|
2
2
|
`)}const f=`__politty_lazy__`;function p(e){return typeof e==`object`&&!!e&&f in e&&e[f]===!0}function m(e,t){return{[f]:!0,meta:e,load:e.requiredPackages?.length?async()=>(await u(e.requiredPackages?.filter(e=>!e.when),{}),t()):t}}function h(e){return p(e)?e.meta:typeof e==`function`?null:e}async function g(e,t){return p(e)?t?.(e.meta)?e.meta:await e.load():typeof e==`function`?await e():e}async function _(e,t,n){if(!e.subCommands)return;let r=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(r)return{command:await g(r,n),aliasFor:void 0};let i=v(e,t);if(i)return{command:await g(e.subCommands[i],n),aliasFor:i}}function v(e,t){if(e.subCommands){for(let[n,r]of Object.entries(e.subCommands))if(h(r)?.aliases?.includes(t))return n}}function y(e){let t=/* @__PURE__ */ new Set;if(!e.subCommands)return t;for(let[n,r]of Object.entries(e.subCommands)){t.add(n);let e=h(r);if(e?.aliases)for(let n of e.aliases)t.add(n)}return t}function b(e){return e.subCommands?Object.keys(e.subCommands):[]}export{_ as a,h as c,l as d,u as f,v as i,d as l,b as n,p as o,g as r,m as s,y as t,c as u};
|
|
@@ -900,11 +900,15 @@ interface NonRunnableCommand<TArgsSchema extends ArgsSchema | undefined = undefi
|
|
|
900
900
|
* `run` (which would exempt it from plugin dispatch — see
|
|
901
901
|
* `MainOptions.onUnknownSubcommand`).
|
|
902
902
|
*
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
903
|
+
* Unknown flags at this level are handled first by its `unknownKeys` mode
|
|
904
|
+
* (the `globalArgs` schema's when this command has no `args`): a strict
|
|
905
|
+
* mode rejects them, and the other modes drop them.
|
|
906
|
+
*
|
|
907
|
+
* Only fires when no tokens are left at this level after unknown flags
|
|
908
|
+
* are dropped (the same condition that would otherwise show help). A
|
|
909
|
+
* local flag meant for the default subcommand is not passed to it, so it
|
|
910
|
+
* still needs the subcommand named explicitly (`cli group sub --limit 10`,
|
|
911
|
+
* not `cli group --limit 10`), since this command's own (typically
|
|
908
912
|
* schema-less) parse level has no way to know `--limit` belongs to `sub`.
|
|
909
913
|
*/
|
|
910
914
|
defaultSubCommand?: string | undefined;
|
|
@@ -958,7 +962,10 @@ interface MainOptions {
|
|
|
958
962
|
skipValidation?: boolean;
|
|
959
963
|
/** Custom logger for output (default: console) */
|
|
960
964
|
logger?: Logger;
|
|
961
|
-
/**
|
|
965
|
+
/**
|
|
966
|
+
* Global args schema (shared across all subcommands). Its `unknownKeys`
|
|
967
|
+
* mode also handles unknown flags given to a command group without `args`.
|
|
968
|
+
*/
|
|
962
969
|
globalArgs?: ArgsSchema;
|
|
963
970
|
/** Global setup hook (runs before command execution) */
|
|
964
971
|
setup?: ((context: GlobalSetupContext) => void | Promise<void>) | undefined;
|
|
@@ -1038,7 +1045,10 @@ interface RunCommandOptions {
|
|
|
1038
1045
|
skipValidation?: boolean;
|
|
1039
1046
|
/** Custom logger for output (default: console) */
|
|
1040
1047
|
logger?: Logger;
|
|
1041
|
-
/**
|
|
1048
|
+
/**
|
|
1049
|
+
* Global args schema (shared across all subcommands). Its `unknownKeys`
|
|
1050
|
+
* mode also handles unknown flags given to a command group without `args`.
|
|
1051
|
+
*/
|
|
1042
1052
|
globalArgs?: ArgsSchema;
|
|
1043
1053
|
/** Global setup hook (runs before command execution) */
|
|
1044
1054
|
setup?: ((context: GlobalSetupContext) => void | Promise<void>) | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{d as e,u as t}from"./schema-extractor-
|
|
1
|
+
import{d as e,u as t}from"./schema-extractor-lB6-WHOF.js";import{n}from"./command-BXsTrIgI.js";import{s as r}from"./subcommand-router-40vA6Mka.js";import{t as i}from"./schema-C20skX3E.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-RQU_Sx7K.js`).then(e=>e.createCompletionCommand(f,a,o,d))),__complete:r(n({name:`__complete`,args:i,run(){}}),()=>import(`./dynamic-Wt-f3fbl.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-RQU_Sx7K.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-RQU_Sx7K.js`).then(e=>e.createCompletionWorkerPathCommand(u,d)))},f.runMainHook=e=>{y(e,{programName:u,...s!==void 0&&{cacheDir:s}})},f}function y(e,t){if(process.env.POLITTY_NO_COMPLETION_REFRESH)return;let n=e.find(e=>!e.startsWith(`-`));if(n===`__complete`||n===`__refresh-completion`||n===`__completion-worker-path`||n===`completion`)return;let r=l();if(!r)return;let i=process.argv[1];i&&p(t,r)&&m(i,r)}export{d as a,_ as i,h as n,f as o,g as r,l as s,v as t};
|
package/dist/{with-completion-command-CARvhYvv.d.ts → with-completion-command-QHQsd0Zt.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { L as UnknownKeysMode, V as ArgMeta, Z as ResolvedExpandCandidate, a as ArgsSchema, r as AnyCommand, tt as DynamicCompletionResolver } from "./types-
|
|
1
|
+
import { L as UnknownKeysMode, V as ArgMeta, Z as ResolvedExpandCandidate, a as ArgsSchema, r as AnyCommand, tt as DynamicCompletionResolver } from "./types-DtQ-Zt3n.js";
|
|
2
2
|
//#region ../core/src/adapter/internal-args.d.ts
|
|
3
3
|
/** Runtime brand distinguishing internal descriptors from library schemas. */
|
|
4
4
|
declare const INTERNAL_ARGS_BRAND = "__polittyInternalArgs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@politty/valibot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A lightweight CLI framework inspired by citty with valibot integration for type-safe metadata management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"argument-parser",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@politty/core": "0.1.0",
|
|
78
78
|
"@types/node": "25.9.9",
|
|
79
79
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
80
|
-
"tsdown": "0.23.
|
|
80
|
+
"tsdown": "0.23.1",
|
|
81
81
|
"typescript": "7.0.2",
|
|
82
82
|
"valibot": "1.5.0"
|
|
83
83
|
},
|