@politty/zod 0.4.0 → 0.4.2

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.
Files changed (54) hide show
  1. package/README.md +17 -2
  2. package/dist/agent.d.ts +2 -0
  3. package/dist/agent.js +1 -0
  4. package/dist/{arg-registry-Dvi0co21.d.ts → arg-registry-vcm6uTB1.d.ts} +37 -2
  5. package/dist/argv-parser-CawJSYjw.js +1 -0
  6. package/dist/augment.d.ts +1 -1
  7. package/dist/cli-main-DcB9Slb7.js +2 -0
  8. package/dist/cli-main-Dp25rn4L.js +1 -0
  9. package/dist/cli-run-C-K9FeKJ.js +1 -0
  10. package/dist/cli.js +1 -1
  11. package/dist/completion-CizQSJgq.js +1 -0
  12. package/dist/{completion-OvSe3W9y.js → completion-nNzHfI1i.js} +3 -3
  13. package/dist/completion.d.ts +2 -2
  14. package/dist/completion.js +1 -1
  15. package/dist/detect-agent-D7KSeWMh.js +3 -0
  16. package/dist/detect-agent-EHaSY1KW.d.ts +49 -0
  17. package/dist/docs.d.ts +1 -1
  18. package/dist/docs.js +12 -12
  19. package/dist/dynamic-DG-l9V-y.js +1 -0
  20. package/dist/dynamic-DbvYJg3o.js +6 -0
  21. package/dist/field-meta-D9ySul7J.js +1 -0
  22. package/dist/index.d.ts +15 -4
  23. package/dist/index.js +1 -1
  24. package/dist/log-collector-uhRWYT-z.js +1 -0
  25. package/dist/prompt-clack.d.ts +1 -1
  26. package/dist/prompt-clack.js +1 -1
  27. package/dist/prompt-inquirer.d.ts +1 -1
  28. package/dist/prompt-inquirer.js +1 -1
  29. package/dist/prompt.d.ts +1 -1
  30. package/dist/prompt.js +1 -1
  31. package/dist/register-TbOCQNeI.js +1 -0
  32. package/dist/runner-CqslNxyn.js +30 -0
  33. package/dist/runner-DD6DzZky.js +1 -0
  34. package/dist/schema-extractor-fZZ2_WAZ.js +1 -0
  35. package/dist/{schema-DhMPssIJ.js → schema-tWeEQULd.js} +1 -1
  36. package/dist/skill.d.ts +1 -1
  37. package/dist/skill.js +1 -1
  38. package/dist/{subcommand-router-D8GTMXYL.js → subcommand-router-DR2KBQAt.js} +1 -1
  39. package/dist/{with-completion-command-CQcqFHq8.js → with-completion-command-DG-C9_0Z.js} +2 -2
  40. package/dist/{with-completion-command-BKHwbzEc.d.ts → with-completion-command-DR98pkpR.d.ts} +1 -1
  41. package/package.json +5 -1
  42. package/dist/argv-parser-DZQ0qnXG.js +0 -1
  43. package/dist/cli-main-BX5IVgNq.js +0 -1
  44. package/dist/cli-main-uRzr666k.js +0 -2
  45. package/dist/cli-run-DtG5fM18.js +0 -1
  46. package/dist/completion-8frPuaX8.js +0 -1
  47. package/dist/dynamic-4uRohypH.js +0 -6
  48. package/dist/dynamic-C5e2NuDv.js +0 -1
  49. package/dist/field-meta-_l-FHbh7.js +0 -1
  50. package/dist/log-collector-DICKib75.js +0 -1
  51. package/dist/register-BXOytPt7.js +0 -1
  52. package/dist/runner-BTD1-gUd.js +0 -30
  53. package/dist/runner-BTF0HIGj.js +0 -1
  54. package/dist/schema-extractor-Du9ipDD4.js +0 -1
package/dist/docs.js CHANGED
@@ -1,4 +1,4 @@
1
- import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";import{c as t,n,o as r,r as i,s as a,t as o}from"./schema-extractor-Du9ipDD4.js";import{t as s}from"./log-collector-DICKib75.js";import{r as c}from"./subcommand-router-D8GTMXYL.js";import*as l from"node:fs";import*as u from"node:path";import d from"node:path";import{isDeepStrictEqual as f}from"node:util";const p=[`option`,`alias`,`description`,`required`,`default`];function m(e){return`(↔ \`--${e.cliName}\`)`}function h(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function g(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${h(e)}>`}function _(e){let t=g(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:m(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function v(e){return e.map(_)}function y(e){return e.replace(/\r?\n/g,`<br>`)}function b(e){return y(e.replace(/\|/g,`\\|`))}function x(e){return`\`${e}\``}function S(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function C(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function ee(e,t){switch(t){case`option`:{let t=x(e.longFlag);return e.inlineNegation?`${t} / ${x(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(x).join(`, `):`-`;case`description`:return b(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return S(e);case`env`:return C(e.env)}}function E(e,t){switch(t){case`option`:return x(e.flag);case`description`:return`${b(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function D(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...p,`env`]:p),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>ee(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>E(t.negationRow,e)).join(` | `)} |`);return r.join(`
1
+ import{o as e}from"./field-meta-D9ySul7J.js";import"./register-TbOCQNeI.js";import{c as t,n,o as r,r as i,s as a,t as o}from"./schema-extractor-fZZ2_WAZ.js";import{t as s}from"./log-collector-uhRWYT-z.js";import{r as c}from"./subcommand-router-DR2KBQAt.js";import*as l from"node:fs";import*as u from"node:path";import d from"node:path";import{isDeepStrictEqual as f}from"node:util";const p=[`option`,`alias`,`description`,`required`,`default`];function m(e){return`(↔ \`--${e.cliName}\`)`}function h(e){return e.placeholder??e.cliName.toUpperCase().replace(/-/g,`_`)}function g(e){return e.type===`boolean`?`--${e.cliName}`:`--${e.cliName} <${h(e)}>`}function _(e){let t=g(e),n=[];if(e.alias)for(let t of e.alias)n.push(t.length===1?`-${t}`:`--${t}`);let r=e.type===`boolean`&&!!e.negationDisplay,i=r&&!e.negationDescription?`--${e.negationDisplay}`:void 0,a=r&&e.negationDescription?{flag:`--${e.negationDisplay}`,description:e.negationDescription,relationMarker:m(e),required:e.required}:void 0;return{longFlag:t,aliases:n,inlineNegation:i,description:e.description,required:e.required,hasDefault:e.defaultValue!==void 0,defaultValue:e.defaultValue,env:e.env,negationRow:a}}function v(e){return e.map(_)}function y(e){return e.replace(/\r?\n/g,`<br>`)}function b(e){return y(e.replace(/\|/g,`\\|`))}function x(e){return`\`${e}\``}function S(e){return e.hasDefault?`\`${JSON.stringify(e.defaultValue)}\``:`-`}function C(e){return e?Array.isArray(e)?e.map(e=>`\`${e}\``).join(`, `):`\`${e}\``:`-`}function w(e){return e?` [env: ${(Array.isArray(e)?e:[e]).join(`, `)}]`:``}const T={option:{header:`Option`,separator:`--------`},alias:{header:`Alias`,separator:`-------`},description:{header:`Description`,separator:`-------------`},required:{header:`Required`,separator:`----------`},default:{header:`Default`,separator:`---------`},env:{header:`Env`,separator:`-----`}};function ee(e,t){switch(t){case`option`:{let t=x(e.longFlag);return e.inlineNegation?`${t} / ${x(e.inlineNegation)}`:t}case`alias`:return e.aliases.length>0?e.aliases.map(x).join(`, `):`-`;case`description`:return b(e.description??``);case`required`:return e.required?`Yes`:`No`;case`default`:return S(e);case`env`:return C(e.env)}}function E(e,t){switch(t){case`option`:return x(e.flag);case`description`:return`${b(e.description)} ${e.relationMarker}`;case`required`:return e.required?`Yes`:`No`;case`alias`:case`default`:case`env`:return`-`}}function D(e,t){if(e.length===0)return``;let n=t??(e.some(e=>e.env)?[...p,`env`]:p),r=[];r.push(`| ${n.map(e=>T[e].header).join(` | `)} |`),r.push(`|${n.map(e=>T[e].separator).join(`|`)}|`);for(let t of e)r.push(`| ${n.map(e=>ee(t,e)).join(` | `)} |`),t.negationRow&&r.push(`| ${n.map(e=>E(t.negationRow,e)).join(` | `)} |`);return r.join(`
2
2
  `)}function O(e){if(e.length===0)return``;let t=[];for(let n of e){let e=n.aliases.filter(e=>!e.startsWith(`--`)),r=n.aliases.filter(e=>e.startsWith(`--`)),i=[...e,n.longFlag,...r].map(x).join(`, `);n.inlineNegation&&(i+=` / ${x(n.inlineNegation)}`);let a=n.description?` - ${y(n.description)}`:``,o=n.required?` (required)`:``,s=n.hasDefault?` (default: ${JSON.stringify(n.defaultValue)})`:``,c=w(n.env);t.push(`- ${i}${a}${o}${s}${c}`),n.negationRow&&t.push(`- ${x(n.negationRow.flag)} - ${y(n.negationRow.description)} ${n.negationRow.relationMarker}`)}return t.join(`
3
3
  `)}const k=`POLITTY_DOCS_UPDATE`,A=`POLITTY_DOCS_DOCTOR`,j=[`heading`,`description`,`usage`,`arguments`,`options`,`global-options-link`,`subcommands`,`examples`,`notes`],M=`politty:command`;function N(e,t){return`<!-- ${M}:${t}:${e}:start -->`}function P(e,t){return`<!-- ${M}:${t}:${e}:end -->`}const F=`politty:global-options`;function I(){return`<!-- ${F}:start -->`}function te(){return`<!-- ${F}:end -->`}const L=`politty:root-header`;function ne(){return`<!-- ${L}:start -->`}function re(){return`<!-- ${L}:end -->`}const R=`politty:root-footer`;function ie(){return`<!-- ${R}:start -->`}function ae(){return`<!-- ${R}:end -->`}const z=`politty:index`;function B(e){return`<!-- ${z}:${e}:start -->`}function oe(e){return`<!-- ${z}:${e}:end -->`}function se(e){return y(e.replace(/\|/g,`\\|`))}function ce(e){let t=[e.fullCommandPath];e.options.length>0&&t.push(`[options]`),e.subCommands.length>0&&(e.command.run||e.command.defaultSubCommand?t.push(`[command]`):t.push(`<command>`));for(let n of e.positionalArgs)n.required?t.push(`<${n.name}>`):t.push(`[${n.name}]`);return t.join(` `)}function le(e){return fe(e,Ce)}function ue(e){return e.named?`\`${e.name}\`, \`${g(e)}\``:`\`${e.name}\``}function de(e){return fe(e,we)}function fe(e,t,n=e.positionalArgs){let r=pe(e.extracted),i=r.length>0?o(r):void 0,a=new Set(n.map(e=>e.name)),s=[],c=n.filter(e=>i===void 0||i.has(e.name));c.length>0&&s.push(t(c));for(let e of r){let n=e.fields.filter(e=>e.positional&&!i?.has(e.name)&&a.has(e.name));n.length>0&&s.push(`${e.label}\n\n${t(n)}`)}return s.join(`
4
4
 
@@ -18,16 +18,16 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
18
18
  `}}const ke={command:e=>U(e),tableStyle:U({optionStyle:`table`}),listStyle:U({optionStyle:`list`})};function Ae(e,t){let n=u.resolve(t);if(!l.existsSync(n))return{match:!1,fileExists:!1};let r=l.readFileSync(n,`utf-8`);return e===r?{match:!0,fileExists:!0}:{match:!1,diff:W(r,e),fileExists:!0}}function W(e,t){let n=e.split(`
19
19
  `),r=t.split(`
20
20
  `),i=[];i.push(`--- existing`),i.push(`+++ generated`),i.push(``);let a=Math.max(n.length,r.length),o=!1,s=0,c=[],l=()=>{c.length>0&&(i.push(`@@ -${s+1},${c.length} @@`),i.push(...c),c.length=0),o=!1};for(let e=0;e<a;e++){let t=n[e],i=r[e];if(t===i){if(o){c.push(` ${t??``}`);let e=c.findIndex((e,t)=>(e.startsWith(`-`)||e.startsWith(`+`))&&c.slice(t+1).every(e=>e.startsWith(` `)));e!==-1&&c.length-e>3&&l()}}else{if(!o){o=!0,s=e;let t=Math.max(0,e-3);for(let r=t;r<e;r++)c.push(` ${n[r]??``}`)}t!==void 0&&(i===void 0||t!==i)&&c.push(`-${t}`),i!==void 0&&(t===void 0||t!==i)&&c.push(`+${i}`)}}return l(),i.join(`
21
- `)}function G(e,t){let n=u.resolve(e),r=u.dirname(n);l.existsSync(r)||l.mkdirSync(r,{recursive:!0}),l.writeFileSync(n,t,`utf-8`)}function je(e){let t=u.resolve(e);return l.existsSync(t)?l.readFileSync(t,`utf-8`):null}function Me(e,t=l){let n=u.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,n,r=[]){let o=i(e),s=o?t(o):[],l=o?a(o):[],u=[];if(e.subCommands)for(let[t,n]of Object.entries(e.subCommands)){let e=await c(n),i=[...r,t];u.push({name:t,description:e.description,aliases:e.aliases,fullPath:i})}return{name:e.name??``,description:e.description,aliases:e.aliases,fullCommandPath:r.length>0?`${n} ${r.join(` `)}`:n,commandPath:r.join(` `),depth:r.length+1,positionalArgs:s,options:l,subCommands:u,extracted:o,command:e,notes:e.notes,examples:e.examples}}async function Pe(e,t){let n=t??e.name??`command`,r=new Map;async function i(e,t){let a=await Ne(e,n,t),o=t.join(` `);if(r.set(o,a),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await c(r),[...t,n])}return await i(e,[]),r}async function Fe(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Ie(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Ie(e,t,n){let r=Le(e.cmd),i=[...n,...r],a=s({passthrough:!1});a.start();let o=!0;try{let{runCommand:e}=await import(`./runner-BTF0HIGj.js`),n=await e(t,i);o=n.success,!n.success&&n.error&&console.error(n.error.message)}catch(e){o=!1,console.error(e instanceof Error?e.message:String(e))}finally{a.stop()}let c=a.getLogs(),l=c.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
21
+ `)}function G(e,t){let n=u.resolve(e),r=u.dirname(n);l.existsSync(r)||l.mkdirSync(r,{recursive:!0}),l.writeFileSync(n,t,`utf-8`)}function je(e){let t=u.resolve(e);return l.existsSync(t)?l.readFileSync(t,`utf-8`):null}function Me(e,t=l){let n=u.resolve(e);t.existsSync(n)&&t.unlinkSync(n)}async function Ne(e,n,r=[]){let o=i(e),s=o?t(o):[],l=o?a(o):[],u=[];if(e.subCommands)for(let[t,n]of Object.entries(e.subCommands)){let e=await c(n),i=[...r,t];u.push({name:t,description:e.description,aliases:e.aliases,fullPath:i})}return{name:e.name??``,description:e.description,aliases:e.aliases,fullCommandPath:r.length>0?`${n} ${r.join(` `)}`:n,commandPath:r.join(` `),depth:r.length+1,positionalArgs:s,options:l,subCommands:u,extracted:o,command:e,notes:e.notes,examples:e.examples}}async function Pe(e,t){let n=t??e.name??`command`,r=/* @__PURE__ */ new Map;async function i(e,t){let a=await Ne(e,n,t),o=t.join(` `);if(r.set(o,a),e.subCommands)for(let[n,r]of Object.entries(e.subCommands))await i(await c(r),[...t,n])}return await i(e,[]),r}async function Fe(e,t,n,r=[]){let i=[];t.mock&&await t.mock();try{for(let t of e){let e=await Ie(t,n,r);i.push(e)}}finally{t.cleanup&&await t.cleanup()}return i}async function Ie(e,t,n){let r=Le(e.cmd),i=[...n,...r],a=s({passthrough:!1});a.start();let o=!0;try{let{runCommand:e}=await import(`./runner-DD6DzZky.js`),n=await e(t,i);o=n.success,!n.success&&n.error&&console.error(n.error.message)}catch(e){o=!1,console.error(e instanceof Error?e.message:String(e))}finally{a.stop()}let c=a.getLogs(),l=c.entries.filter(e=>e.stream===`stdout`).map(e=>e.message).join(`
22
22
  `),u=c.entries.filter(e=>e.stream===`stderr`).map(e=>e.message).join(`
23
- `);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:l,stderr:u,success:o}}function Le(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function Re(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t))}function ze(e,t){let n=Re(e).filter(e=>!e.positional);return n.length===0?``:D(v(n),t?.columns)}function Be(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function Ve(e){return e.replace(/\s+/g,`-`).toLowerCase()}function He(e){return e.subCommands.length===0}function Ue(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function We(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(He(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(He(a)||!n)&&r.push(e)}}return r}function Ge(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:We(e.commands,t,r),s=o,c=new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>Ue(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!He(i))continue;let o=n||i.name,s=Ve(o),l=Be(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
23
+ `);return{cmd:e.cmd,desc:e.desc,expectedOutput:e.output,stdout:l,stderr:u,success:o}}function Le(e){let t=[],n=``,r=!1,i=``;for(let a=0;a<e.length;a++){let o=e[a];(o===`"`||o===`'`)&&!r?(r=!0,i=o):o===i&&r?(r=!1,i=``):o===` `&&!r?n&&=(t.push(n),``):n+=o}return n&&t.push(n),t}function Re(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t))}function ze(e,t){let n=Re(e).filter(e=>!e.positional);return n.length===0?``:D(v(n),t?.columns)}function Be(e){return e.replace(/\|/g,`\\|`).replace(/\n/g,` `)}function Ve(e){return e.replace(/\s+/g,`-`).toLowerCase()}function He(e){return e.subCommands.length===0}function Ue(e,t){return e===t?!0:t===``?e!==``:e.startsWith(t+` `)}function We(e,t,n){let r=[];for(let i of e){let e=t.get(i);if(e){if(He(e))r.push(i);else for(let[e,a]of t)(i===``?e.length>0:e.startsWith(i+` `)||e===i)&&(He(a)||!n)&&r.push(e)}}return r}function Ge(e,t,n,r){let i=`#`.repeat(n),a=[];a.push(`${i} [${e.title}](${e.docPath})`),a.push(``),a.push(e.description),a.push(``);let o=e.noExpand?e.commands:We(e.commands,t,r),s=o,c=/* @__PURE__ */ new Set;if(e.allowedCommands){let t=new Set(e.allowedCommands);s=o.filter(e=>t.has(e));for(let n of e.commands)t.has(n)&&!s.some(e=>Ue(e,n))&&(s.push(n),c.add(n))}a.push(`| Command | Description |`),a.push(`|---------|-------------|`);for(let n of s){let i=t.get(n);if(!i||!e.noExpand&&r&&!c.has(n)&&!He(i))continue;let o=n||i.name,s=Ve(o),l=Be(i.description??``);a.push(`| [${o}](${e.docPath}#${s}) | ${l} |`)}return a.join(`
24
24
  `)}async function Ke(e,t,n){let r=n?.headingLevel??3,i=n?.leafOnly??!0,a=await Pe(e),o=[];for(let e of t){let t=Ge(e,a,r,i);o.push(t)}return o.join(`
25
25
 
26
26
  `)}async function K(e,t){if(!t)return e;let n=await t(e);return!e.endsWith(`
27
27
  `)&&n.endsWith(`
28
28
  `)?n.slice(0,-1):n}function qe(e){let t=process.env[e];return t===`true`||t===`1`}function Je(e){let t=e.split(/\r?\n/);if(t[0]!==`---`)return null;let n=[];for(let e=1;e<t.length;e++){let r=t[e];if(r===`---`||r===`...`)return n.join(`
29
- `);n.push(r??``)}return null}function Ye(e){let t=Et(e),n=e.split(/\r?\n/);if(n[0]!==`---`)return e;let r=-1;for(let e=1;e<n.length;e++){let t=n[e];if(t===`---`||t===`...`){r=e;break}}if(r===-1)return e;let i=n.slice(1,r),a=[];for(let e=0;e<i.length;e++){let t=i[e]??``;if(!/^politty\s*:\s*(.*)$/.test(t)){a.push(t);continue}for(;e+1<i.length;){let t=i[e+1]??``;if(t.trim()!==``&&!t.startsWith(` `)&&!t.startsWith(` `))break;e++}}let o=n.slice(r+1);return a.some(e=>e.trim()!==``)?[`---`,...a,n[r]??`---`,...o].join(t):o.join(t).replace(RegExp(`^${t}`),``)}function Xe(e){let t=e.trim();return t.length>=2&&(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))?t.slice(1,-1):t}function Ze(e){let t=Xe(e);if(t===``)return null;let n=t.match(/^\{\{politty:([^{}]*)\}\}$/);return n?t=n[1]??``:t.startsWith(`politty:`)&&(t=t.slice(8)),t===``?null:t}function Qe(e){return e.slice(2,-2).slice(8)}function $e(e){let t=e.trim();return!t.startsWith(`[`)||!t.endsWith(`]`)?[t]:t.slice(1,-1).split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function et(e,t){let n=Ze(t);n!==null&&e.add(n)}function tt(e){let t=new Set,n=Je(e);if(n===null)return t;let r=!1,i=!1,a=0;for(let e of n.split(/\r?\n/)){let n=e.trim();if(n===``||n.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){r=(o[1]?.trim()??``)===``,i=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){r=!1,i=!1;continue}if(!r)continue;let s=e.match(/^(\s+)(?:exclude|excludes)\s*:\s*(.*)$/);if(s){let e=s[2]?.trim()??``;if(e===``)i=!0,a=s[1]?.length??0;else{i=!1;for(let n of $e(e))et(t,n)}continue}if(!i)continue;let c=e.match(/^(\s*)-\s*(.+)$/);if(!c||(c[1]?.length??0)<=a){i=!1;continue}et(t,c[2]??``)}return t}function nt(e){let t=Je(e);if(t===null)return{};let n=!1,r=!1,i=0,a={};for(let e of t.split(/\r?\n/)){let t=e.trim();if(t===``||t.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){n=(o[1]?.trim()??``)===``,r=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){n=!1,r=!1;continue}if(!n)continue;let s=e.match(/^(\s+)index\s*:\s*(.*)$/);if(s){r=(s[2]?.trim()??``)===``,i=s[1]?.length??0;continue}if(!r)continue;if((e.match(/^(\s*)/)?.[1]?.length??0)<=i){r=!1;continue}let c=e.match(/^\s+(title|description)\s*:\s*(.+)$/);if(!c)continue;let l=c[1],u=Xe(c[2]??``);l===`title`?a.title=u:l===`description`&&(a.description=u)}return a}function rt(e){return{rawKeys:e,commandScopes:new Set,commandSections:new Map,globalOptions:!1,index:!1}}function it(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function at(e){if(Array.isArray(e))return{commands:e};if(!(`commands`in e)||!Array.isArray(e.commands))throw Error(`Invalid file config: object form must include a "commands" array. Use [] to skip generation intentionally.`);return e}function q(e,t){return t===``||e===t||e.startsWith(t+` `)}function J(e){return e.includes(`*`)}function ot(e,t){let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);if(n.length!==r.length)return!1;for(let e=0;e<r.length;e++){let t=r[e],i=n[e];if(t!==`*`&&t!==i)return!1}return!0}function st(e,t){let n=[];for(let r of t.keys())ot(r,e)&&n.push(r);return n}function ct(e,t){if(J(t)){if(ot(e,t))return!0;let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);return n.length>r.length&&ot(n.slice(0,r.length).join(` `),t)}return q(e,t)}function lt(e,t){let n=new Set,r=e.flatMap(e=>J(e)?st(e,t):[e]);for(let e of r)for(let r of t.keys())q(r,e)&&n.add(r);return Array.from(n)}function ut(e,t){return e.filter(e=>!t.some(t=>ct(e,t)))}function dt(e,t){let n=[];for(let r of e)J(r)?n.push(...st(r,t)):t.has(r)&&n.push(r);return n}function Y(e,t,n){let r=at(e),i=r.commands;return{fileConfig:r,specifiedCommands:i,commandPaths:ut(r.noExpand?i.filter(e=>t.has(e)):lt(i,t),n),topLevelCommands:ut(dt(i,t),n)}}function ft(e,t,n){let r=[];for(let i of e){let e=J(i)?st(i,n):[i];for(let n of e)for(let e of t)J(e)?ot(n,e)&&r.push(`"${n}" is both in files and ignored by "${e}"`):(n===e||q(n,e))&&r.push(`"${n}" is both in files and ignored by "${e}"`)}if(r.length>0)throw Error(`Conflict between files and ignores:\n - ${r.join(`
30
- - `)}`)}function pt(e,t){let n=[];for(let r of e)J(r)?st(r,t).length===0&&n.push(`"${r}"`):t.has(r)||n.push(`"${r}"`);if(n.length>0)throw Error(`Ignored command paths do not exist: ${n.join(`, `)}`)}function mt(e,t){let n=new Set(e),r=t.filter(e=>n.has(e));for(let t of e)(t===``?0:t.split(` `).length)===1&&!r.includes(t)&&r.push(t);let i=[],a=new Set;function o(t){if(a.has(t)||!n.has(t))return;a.add(t),i.push(t);let r=e.filter(e=>e===t||a.has(e)?!1:t===``?e.split(` `).length===1:e.startsWith(t+` `)&&e.split(` `).length===t.split(` `).length+1).sort((e,t)=>e.localeCompare(t));for(let e of r)o(e)}for(let e of r)o(e);for(let t of e)a.has(t)||i.push(t);return i}function ht(e){if(!e.title&&!e.description)return null;let t=[];if(e.title){let n=`#`.repeat(e.headingLevel??1);t.push(`${n} ${e.title}`)}return e.description&&(t.push(``),t.push(e.description)),t.push(``),t.join(`
29
+ `);n.push(r??``)}return null}function Ye(e){let t=Et(e),n=e.split(/\r?\n/);if(n[0]!==`---`)return e;let r=-1;for(let e=1;e<n.length;e++){let t=n[e];if(t===`---`||t===`...`){r=e;break}}if(r===-1)return e;let i=n.slice(1,r),a=[];for(let e=0;e<i.length;e++){let t=i[e]??``;if(!/^politty\s*:\s*(.*)$/.test(t)){a.push(t);continue}for(;e+1<i.length;){let t=i[e+1]??``;if(t.trim()!==``&&!t.startsWith(` `)&&!t.startsWith(` `))break;e++}}let o=n.slice(r+1);return a.some(e=>e.trim()!==``)?[`---`,...a,n[r]??`---`,...o].join(t):o.join(t).replace(RegExp(`^${t}`),``)}function Xe(e){let t=e.trim();return t.length>=2&&(t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`))?t.slice(1,-1):t}function Ze(e){let t=Xe(e);if(t===``)return null;let n=t.match(/^\{\{politty:([^{}]*)\}\}$/);return n?t=n[1]??``:t.startsWith(`politty:`)&&(t=t.slice(8)),t===``?null:t}function Qe(e){return e.slice(2,-2).slice(8)}function $e(e){let t=e.trim();return!t.startsWith(`[`)||!t.endsWith(`]`)?[t]:t.slice(1,-1).split(`,`).map(e=>e.trim()).filter(e=>e.length>0)}function et(e,t){let n=Ze(t);n!==null&&e.add(n)}function tt(e){let t=/* @__PURE__ */ new Set,n=Je(e);if(n===null)return t;let r=!1,i=!1,a=0;for(let e of n.split(/\r?\n/)){let n=e.trim();if(n===``||n.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){r=(o[1]?.trim()??``)===``,i=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){r=!1,i=!1;continue}if(!r)continue;let s=e.match(/^(\s+)(?:exclude|excludes)\s*:\s*(.*)$/);if(s){let e=s[2]?.trim()??``;if(e===``)i=!0,a=s[1]?.length??0;else{i=!1;for(let n of $e(e))et(t,n)}continue}if(!i)continue;let c=e.match(/^(\s*)-\s*(.+)$/);if(!c||(c[1]?.length??0)<=a){i=!1;continue}et(t,c[2]??``)}return t}function nt(e){let t=Je(e);if(t===null)return{};let n=!1,r=!1,i=0,a={};for(let e of t.split(/\r?\n/)){let t=e.trim();if(t===``||t.startsWith(`#`))continue;let o=e.match(/^politty\s*:\s*(.*)$/);if(o){n=(o[1]?.trim()??``)===``,r=!1;continue}if(!e.startsWith(` `)&&!e.startsWith(` `)){n=!1,r=!1;continue}if(!n)continue;let s=e.match(/^(\s+)index\s*:\s*(.*)$/);if(s){r=(s[2]?.trim()??``)===``,i=s[1]?.length??0;continue}if(!r)continue;if((e.match(/^(\s*)/)?.[1]?.length??0)<=i){r=!1;continue}let c=e.match(/^\s+(title|description)\s*:\s*(.+)$/);if(!c)continue;let l=c[1],u=Xe(c[2]??``);l===`title`?a.title=u:l===`description`&&(a.description=u)}return a}function rt(e){return{rawKeys:e,commandScopes:/* @__PURE__ */ new Set,commandSections:/* @__PURE__ */ new Map,globalOptions:!1,index:!1}}function it(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function at(e){if(Array.isArray(e))return{commands:e};if(!(`commands`in e)||!Array.isArray(e.commands))throw Error(`Invalid file config: object form must include a "commands" array. Use [] to skip generation intentionally.`);return e}function q(e,t){return t===``||e===t||e.startsWith(t+` `)}function J(e){return e.includes(`*`)}function ot(e,t){let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);if(n.length!==r.length)return!1;for(let e=0;e<r.length;e++){let t=r[e],i=n[e];if(t!==`*`&&t!==i)return!1}return!0}function st(e,t){let n=[];for(let r of t.keys())ot(r,e)&&n.push(r);return n}function ct(e,t){if(J(t)){if(ot(e,t))return!0;let n=e===``?[]:e.split(` `),r=t===``?[]:t.split(` `);return n.length>r.length&&ot(n.slice(0,r.length).join(` `),t)}return q(e,t)}function lt(e,t){let n=/* @__PURE__ */ new Set,r=e.flatMap(e=>J(e)?st(e,t):[e]);for(let e of r)for(let r of t.keys())q(r,e)&&n.add(r);return Array.from(n)}function ut(e,t){return e.filter(e=>!t.some(t=>ct(e,t)))}function dt(e,t){let n=[];for(let r of e)J(r)?n.push(...st(r,t)):t.has(r)&&n.push(r);return n}function Y(e,t,n){let r=at(e),i=r.commands;return{fileConfig:r,specifiedCommands:i,commandPaths:ut(r.noExpand?i.filter(e=>t.has(e)):lt(i,t),n),topLevelCommands:ut(dt(i,t),n)}}function ft(e,t,n){let r=[];for(let i of e){let e=J(i)?st(i,n):[i];for(let n of e)for(let e of t)J(e)?ot(n,e)&&r.push(`"${n}" is both in files and ignored by "${e}"`):(n===e||q(n,e))&&r.push(`"${n}" is both in files and ignored by "${e}"`)}if(r.length>0)throw Error(`Conflict between files and ignores:\n - ${r.join(`
30
+ - `)}`)}function pt(e,t){let n=[];for(let r of e)J(r)?st(r,t).length===0&&n.push(`"${r}"`):t.has(r)||n.push(`"${r}"`);if(n.length>0)throw Error(`Ignored command paths do not exist: ${n.join(`, `)}`)}function mt(e,t){let n=new Set(e),r=t.filter(e=>n.has(e));for(let t of e)(t===``?0:t.split(` `).length)===1&&!r.includes(t)&&r.push(t);let i=[],a=/* @__PURE__ */ new Set;function o(t){if(a.has(t)||!n.has(t))return;a.add(t),i.push(t);let r=e.filter(e=>e===t||a.has(e)?!1:t===``?e.split(` `).length===1:e.startsWith(t+` `)&&e.split(` `).length===t.split(` `).length+1).sort((e,t)=>e.localeCompare(t));for(let e of r)o(e)}for(let e of r)o(e);for(let t of e)a.has(t)||i.push(t);return i}function ht(e){if(!e.title&&!e.description)return null;let t=[];if(e.title){let n=`#`.repeat(e.headingLevel??1);t.push(`${n} ${e.title}`)}return e.description&&(t.push(``),t.push(e.description)),t.push(``),t.join(`
31
31
  `)}function gt(e){if(!/^#{1,6} /.test(e))return null;let t=e.indexOf(`
32
32
  `);if(t===-1)return e;let n=t+1;for(e[n]===`
33
33
  `&&(n+=1);n<e.length;){let t=e.indexOf(`
@@ -48,7 +48,7 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
48
48
 
49
49
  `;return e.slice(0,t)+n+r+`
50
50
 
51
- `+e.slice(c)}throw Error(`No insertion point found for section "${t}" (scope="${n}"). This should be unreachable when at least one marker exists for the command.`)}function bt(e,t){let n=[];for(let r of j)Z(e,r,t)!==null&&n.push(r);return n}function xt(e){let t=j.join(`|`),n=RegExp(`<!--\\s*politty:command:(.*?):(?:${t}):start\\s*-->`,`g`),r=new Set;for(let t of e.matchAll(n))r.add(t[1]??``);return Array.from(r)}function St(e,t,n,r){let i=r.indexOf(t);if(i===-1)return e.trimEnd()+`
51
+ `+e.slice(c)}throw Error(`No insertion point found for section "${t}" (scope="${n}"). This should be unreachable when at least one marker exists for the command.`)}function bt(e,t){let n=[];for(let r of j)Z(e,r,t)!==null&&n.push(r);return n}function xt(e){let t=j.join(`|`),n=RegExp(`<!--\\s*politty:command:(.*?):(?:${t}):start\\s*-->`,`g`),r=/* @__PURE__ */ new Set;for(let t of e.matchAll(n))r.add(t[1]??``);return Array.from(r)}function St(e,t,n,r){let i=r.indexOf(t);if(i===-1)return e.trimEnd()+`
52
52
 
53
53
  `+n+`
54
54
  `;for(let t=i+1;t<r.length;t++){let i=r[t];if(i===void 0)continue;let a=N(`heading`,i),o=e.indexOf(a);if(o!==-1){let t=o;for(;t>0&&e[t-1]===`
@@ -65,9 +65,9 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
65
65
  `)}function Et(e){return e.includes(`\r
66
66
  `)?`\r
67
67
  `:`
68
- `}function Dt(e){return(e.match(/\n/g)??[]).length}function Ot(e){return j.some(t=>t===e)}function kt(e){switch(Math.min(6,Math.max(1,Math.trunc(e)))){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 5:return 5;default:return 6}}function At(e,t){if(e.length===0)return t===void 0||t.has(``)?``:null;let n=e.join(`:`);if(t?.has(n))return n;let r=e.join(` `);return t?.has(r)||t===void 0?r:null}function jt(e){return e.join(` `)}function Mt(e,t){let n=e.slice(2,-2).split(`:`),r=n[1];if(r===`command`){let r=n.slice(2);if(r.length===1&&r[0]===``)return{kind:`invalid`,reason:`Trailing colon in "${e}"; use {{politty:command}} for the root command.`};let i=At(r,t);if(i!==null)return{kind:`command`,scope:i,type:void 0};if(r.length>=2){let e=r[r.length-1],n=r.slice(0,-1),i=At(n,t);if(e!==void 0&&Ot(e))return{kind:`command`,scope:i??jt(n),type:e};if(e!==void 0&&i!==null)return{kind:`invalid`,reason:`Unknown section type "${e}" for command scope "${X(i)}". Valid section types: ${j.join(`, `)}`}}return{kind:`command`,scope:jt(r),type:void 0}}return r===`global-options`?n.length===2?{kind:`global-options`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:global-options}}.`}:r===`index`?n.length===2?{kind:`index`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:index}}.`}:{kind:`invalid`,reason:`Unknown politty directive "${r??``}" in "${e}". Valid directives: command, global-options, index`}}function Nt(e,t){let n=rt(e);for(let r of e){let e=Mt(`{{politty:${r}}}`,t);if(e.kind===`command`){if(e.type===void 0)n.commandScopes.add(e.scope);else{let t=n.commandSections.get(e.scope);t||(t=new Set,n.commandSections.set(e.scope,t)),t.add(e.type)}}else e.kind===`global-options`?n.globalOptions=!0:e.kind===`index`&&(n.index=!0)}return n}function Q(e,t){for(let n of t)if(q(e,n))return!0;return!1}function Pt(e,t,n){return Q(e,n.commandScopes)?!0:n.commandSections.get(e)?.has(t)??!1}function Ft(e,t,n,r){return mt(ut(lt([e],t),n).filter(e=>!Q(e,r.commandScopes)),[e])}function It(e,t,n){return n.rawKeys.has(Qe(e))?!0:t.kind===`command`?Q(t.scope,n.commandScopes)?!0:t.type!==void 0&&(n.commandSections.get(t.scope)?.has(t.type)??!1):t.kind===`global-options`?n.globalOptions:t.kind===`index`&&n.index}function Lt(e,t){if(!e.startsWith(`command:`))return!1;let n=e.slice(8).split(`:`);for(let e of t.commandScopes){if(e===``)return!0;let t=e.split(` `);if(n.slice(0,t.length).join(` `)===e)return!0;let r=e.split(`:`);if(n.slice(0,r.length).join(`:`)===e)return!0}return!1}const Rt=/\{\{politty:[^{}]*\}\}/g;function zt(e,t){let n=new Set;for(let r of e.matchAll(Rt)){let i=r.index,a=i+r[0].length;if(e[i-1]===`{`||e[a]===`}`){let n=e.slice(Math.max(0,i-1),Math.min(e.length,a+1)).split(`
68
+ `}function Dt(e){return(e.match(/\n/g)??[]).length}function Ot(e){return j.some(t=>t===e)}function kt(e){switch(Math.min(6,Math.max(1,Math.trunc(e)))){case 1:return 1;case 2:return 2;case 3:return 3;case 4:return 4;case 5:return 5;default:return 6}}function At(e,t){if(e.length===0)return t===void 0||t.has(``)?``:null;let n=e.join(`:`);if(t?.has(n))return n;let r=e.join(` `);return t?.has(r)||t===void 0?r:null}function jt(e){return e.join(` `)}function Mt(e,t){let n=e.slice(2,-2).split(`:`),r=n[1];if(r===`command`){let r=n.slice(2);if(r.length===1&&r[0]===``)return{kind:`invalid`,reason:`Trailing colon in "${e}"; use {{politty:command}} for the root command.`};let i=At(r,t);if(i!==null)return{kind:`command`,scope:i,type:void 0};if(r.length>=2){let e=r[r.length-1],n=r.slice(0,-1),i=At(n,t);if(e!==void 0&&Ot(e))return{kind:`command`,scope:i??jt(n),type:e};if(e!==void 0&&i!==null)return{kind:`invalid`,reason:`Unknown section type "${e}" for command scope "${X(i)}". Valid section types: ${j.join(`, `)}`}}return{kind:`command`,scope:jt(r),type:void 0}}return r===`global-options`?n.length===2?{kind:`global-options`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:global-options}}.`}:r===`index`?n.length===2?{kind:`index`}:{kind:`invalid`,reason:`Malformed placeholder "${e}". Expected {{politty:index}}.`}:{kind:`invalid`,reason:`Unknown politty directive "${r??``}" in "${e}". Valid directives: command, global-options, index`}}function Nt(e,t){let n=rt(e);for(let r of e){let e=Mt(`{{politty:${r}}}`,t);if(e.kind===`command`){if(e.type===void 0)n.commandScopes.add(e.scope);else{let t=n.commandSections.get(e.scope);t||(t=/* @__PURE__ */ new Set,n.commandSections.set(e.scope,t)),t.add(e.type)}}else e.kind===`global-options`?n.globalOptions=!0:e.kind===`index`&&(n.index=!0)}return n}function Q(e,t){for(let n of t)if(q(e,n))return!0;return!1}function Pt(e,t,n){return Q(e,n.commandScopes)?!0:n.commandSections.get(e)?.has(t)??!1}function Ft(e,t,n,r){return mt(ut(lt([e],t),n).filter(e=>!Q(e,r.commandScopes)),[e])}function It(e,t,n){return n.rawKeys.has(Qe(e))?!0:t.kind===`command`?Q(t.scope,n.commandScopes)?!0:t.type!==void 0&&(n.commandSections.get(t.scope)?.has(t.type)??!1):t.kind===`global-options`?n.globalOptions:t.kind===`index`&&n.index}function Lt(e,t){if(!e.startsWith(`command:`))return!1;let n=e.slice(8).split(`:`);for(let e of t.commandScopes){if(e===``)return!0;let t=e.split(` `);if(n.slice(0,t.length).join(` `)===e)return!0;let r=e.split(`:`);if(n.slice(0,r.length).join(`:`)===e)return!0}return!1}const Rt=/\{\{politty:[^{}]*\}\}/g;function zt(e,t){let n=/* @__PURE__ */ new Set;for(let r of e.matchAll(Rt)){let i=r.index,a=i+r[0].length;if(e[i-1]===`{`||e[a]===`}`){let n=e.slice(Math.max(0,i-1),Math.min(e.length,a+1)).split(`
69
69
  `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}n.add(i)}let r=0;for(;;){let i=e.indexOf(`{{politty:`,r);if(i===-1)return;if(!n.has(i)){let n=e.slice(i,i+80).split(`
70
- `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Bt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${X(r)}". Valid section types: ${j.join(`, `)}`}function Vt(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ht(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Ut(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Wt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Ut(e.args)}function Gt(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t)).filter(e=>!e.positional)}function Kt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return f(r,a)}function qt(e){if(e)return Wt(e)?e:{args:e}}function Jt(e){if(!e)return;let t=n(e).fields.filter(e=>!e.positional);if(t.length!==0)return Object.fromEntries(t.map(e=>[e.name,e.schema]))}function Yt(e){let t=new Map;if(!e?.globalOptions)return t;let n=qt(e.globalOptions);if(!n)return t;for(let e of Gt(n.args))t.set(e.name,e);return t}function Xt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=Y(o,n,r);if(e.length===0)continue;let c=`./`+u.relative(u.dirname(t),a).replace(/\\/g,`/`),l=e[0],d=l===void 0?void 0:n.get(l),f=Array.isArray(o)?void 0:o;i.push({title:f?.title??d?.name??u.basename(a,u.extname(a)),description:f?.description??d?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Zt(e,t,n,r){let i=$(t),a=[];for(let[t,o]of e.entries()){if($(t)===i)continue;let e=o.headingScopes;if(e.length===0)continue;let s=`./`+u.relative(u.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??u.basename(t,u.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function Qt(e,t,n){let r=new Set;for(let i of Object.values(e)){let{commandPaths:e}=Y(i,t,n);for(let t of e)r.add(t)}return r}function $t(e,t,n,r){let i=new Set;for(let a of Object.keys(t)){let o=fn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function en(e,t){return t.some(t=>q(e,t))}function tn(e,t){return e.referencedScopes.some(e=>en(e,t))}function nn(e,t){return e.emitsIndex||e.emitsGlobalOptions||tn(e,t)}function rn(e,t,n){if(n.size===0)return;let r=[];for(let i of e){let e=t.get(i);if(e)for(let t of e.options){let e=n.get(t.name);e&&(Kt(e,t)||r.push(`Command "${X(i)}" option "--${t.cliName}" does not match globalOptions definition for "${t.name}".`))}}if(r.length>0)throw Error(`Invalid globalOptions configuration:\n - ${r.join(`
70
+ `)[0];throw Error(`Malformed politty placeholder in template "${t}": "${n}". Expected {{politty:...}}.`)}r=i+10}}function Bt(e,t){let n=e.lastIndexOf(`:`);if(n===-1)return null;let r=e.slice(0,n),i=e.slice(n+1);return i===``||!t.has(r)?null:`Unknown section type "${i}" for command scope "${X(r)}". Valid section types: ${j.join(`, `)}`}function Vt(e,t,n){let r=e.indexOf(t);if(r===-1)return null;let i=e.indexOf(n,r);return i===-1?null:e.slice(r,i+n.length)}function Ht(e,t,n,r){let i=e.indexOf(t);if(i===-1)return null;let a=e.indexOf(n,i);return a===-1?null:e.slice(0,i)+r+e.slice(a+n.length)}function Ut(e){if(typeof e!=`object`||!e)return!1;let t=e[`~standard`];if(typeof t!=`object`||!t)return!1;let{vendor:n,validate:r}=t;return typeof n==`string`&&typeof r==`function`}function Wt(e){return typeof e!=`object`||!e||!(`args`in e)?!1:!Ut(e.args)}function Gt(t){let n=e();return Object.entries(t).map(([e,t])=>n.resolveFieldMeta(e,t)).filter(e=>!e.positional)}function Kt(e,t){let{schema:n,...r}=e,{schema:i,...a}=t;return f(r,a)}function qt(e){if(e)return Wt(e)?e:{args:e}}function Jt(e){if(!e)return;let t=n(e).fields.filter(e=>!e.positional);if(t.length!==0)return Object.fromEntries(t.map(e=>[e.name,e.schema]))}function Yt(e){let t=/* @__PURE__ */ new Map;if(!e?.globalOptions)return t;let n=qt(e.globalOptions);if(!n)return t;for(let e of Gt(n.args))t.set(e.name,e);return t}function Xt(e,t,n,r){let i=[];for(let[a,o]of Object.entries(e)){let{commandPaths:e,topLevelCommands:s}=Y(o,n,r);if(e.length===0)continue;let c=`./`+u.relative(u.dirname(t),a).replace(/\\/g,`/`),l=e[0],d=l===void 0?void 0:n.get(l),f=Array.isArray(o)?void 0:o;i.push({title:f?.title??d?.name??u.basename(a,u.extname(a)),description:f?.description??d?.description??``,commands:s,allowedCommands:e,docPath:c})}return i}function Zt(e,t,n,r){let i=$(t),a=[];for(let[t,o]of e.entries()){if($(t)===i)continue;let e=o.headingScopes;if(e.length===0)continue;let s=`./`+u.relative(u.dirname(n),t).replace(/\\/g,`/`),c=e[0],l=c===void 0?void 0:r.get(c);a.push({title:o.indexTitle??l?.name??u.basename(t,u.extname(t)),description:o.indexDescription??l?.description??``,commands:e,docPath:s,noExpand:!0})}return a}function Qt(e,t,n){let r=/* @__PURE__ */ new Set;for(let i of Object.values(e)){let{commandPaths:e}=Y(i,t,n);for(let t of e)r.add(t)}return r}function $t(e,t,n,r){let i=/* @__PURE__ */ new Set;for(let a of Object.keys(t)){let o=fn(e,a,t,n,r);for(let e of o)i.add(e)}return i}function en(e,t){return t.some(t=>q(e,t))}function tn(e,t){return e.referencedScopes.some(e=>en(e,t))}function nn(e,t){return e.emitsIndex||e.emitsGlobalOptions||tn(e,t)}function rn(e,t,n){if(n.size===0)return;let r=[];for(let i of e){let e=t.get(i);if(e)for(let t of e.options){let e=n.get(t.name);e&&(Kt(e,t)||r.push(`Command "${X(i)}" option "--${t.cliName}" does not match globalOptions definition for "${t.name}".`))}}if(r.length>0)throw Error(`Invalid globalOptions configuration:\n - ${r.join(`
71
71
  - `)}`)}function an(e){return[`<a id="global-options"></a>`,ze(e.args,e.options)].join(`
72
72
  `)}function on(e){return[I(),an(e),te()].join(`
73
73
  `)}async function sn(e,t,n,r){let i=B(n),a=oe(n);return[i,await Ke(t,e,r),a].join(`
@@ -78,15 +78,15 @@ import{o as e}from"./field-meta-_l-FHbh7.js";import"./register-BXOytPt7.js";impo
78
78
  `),p=Vt(c,n,r);if(!p)return a&&s?(c=c.trimEnd()+`
79
79
 
80
80
  `+f+`
81
- `,d=!0,{content:c,diffs:l,hasError:u,wasUpdated:d}):(u=!0,l.push(`${t} marker not found in file. Expected markers:\n${n}\n...\n${r}`),{content:c,diffs:l,hasError:u,wasUpdated:d});if(p!==f){if(a){let e=Ht(c,n,r,f);e?(c=e,d=!0):(u=!0,l.push(`Failed to replace ${t} section`))}else u=!0,l.push(W(p,f))}return{content:c,diffs:l,hasError:u,wasUpdated:d}}async function un(e,t,n,r,i,a,o){let s=e,c=[],l=!1,u=!1,d=B(r),f=oe(r),p=s.includes(d),m=s.includes(f);if(!p&&!m)return{content:s,diffs:c,hasError:l,wasUpdated:u};if(!p||!m)return l=!0,c.push(`Index marker section is malformed: both start and end markers are required.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let h=Vt(s,d,f);if(!h)return l=!0,c.push(`Index marker section is malformed: start marker must appear before end marker.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let g=await K(await sn(t,n,r,o),a);if(h!==g){if(i){let e=Ht(s,d,f,g);e?(s=e,u=!0):(l=!0,c.push(`Failed to replace index section`))}else l=!0,c.push(W(h,g))}return{content:s,diffs:c,hasError:l,wasUpdated:u}}function dn(e,t,n,r){for(let[i,a]of Object.entries(t)){let{commandPaths:t}=Y(a,n,r);if(t.includes(e))return i}return null}function fn(e,t,n,r,i){let a=n[t];if(!a)return[];let{specifiedCommands:o,commandPaths:s}=Y(a,r,i),c=new Set;for(let t of e)if(s.includes(t)){c.add(t);for(let e of s)q(e,t)&&!o.includes(e)&&c.add(e)}return Array.from(c)}function pn(e,t,n,r,i,a,o,s=[],c,l){let u=t.get(e);if(!u||l&&Q(u.commandPath,l.commandScopes))return null;let d={...u,filePath:r,fileMap:i,rootDocPath:a};(s.length>0||l&&l.commandScopes.size>0)&&(d.subCommands=u.subCommands.filter(e=>{let t=e.fullPath.join(` `);return!s.some(e=>ct(t,e))&&!(l&&Q(t,l.commandScopes))})),o!==void 0&&(d.hasGlobalOptions=o),c&&c.size>0&&(d.options=u.options.filter(e=>!c.has(e.name)),u.extracted&&(d.extracted=hn(u.extracted,c)));let f=n(d);if(l){for(let[e,t]of l.commandSections)if(e===u.commandPath){for(let n of t){let t=Z(f,n,e);t!==null&&(f=f.replace(t,``))}f=Tt(f)}}return f}function mn(e,t,n,r,i,a,o,s,c,l){let u=Ft(e,t,r,l),d=[];for(let e of u){let u=pn(e,t,n,i,a,o,s,r,c,l);u!==null&&d.push(u)}return d.length===0?null:d.join(`
81
+ `,d=!0,{content:c,diffs:l,hasError:u,wasUpdated:d}):(u=!0,l.push(`${t} marker not found in file. Expected markers:\n${n}\n...\n${r}`),{content:c,diffs:l,hasError:u,wasUpdated:d});if(p!==f){if(a){let e=Ht(c,n,r,f);e?(c=e,d=!0):(u=!0,l.push(`Failed to replace ${t} section`))}else u=!0,l.push(W(p,f))}return{content:c,diffs:l,hasError:u,wasUpdated:d}}async function un(e,t,n,r,i,a,o){let s=e,c=[],l=!1,u=!1,d=B(r),f=oe(r),p=s.includes(d),m=s.includes(f);if(!p&&!m)return{content:s,diffs:c,hasError:l,wasUpdated:u};if(!p||!m)return l=!0,c.push(`Index marker section is malformed: both start and end markers are required.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let h=Vt(s,d,f);if(!h)return l=!0,c.push(`Index marker section is malformed: start marker must appear before end marker.`),{content:s,diffs:c,hasError:l,wasUpdated:u};let g=await K(await sn(t,n,r,o),a);if(h!==g){if(i){let e=Ht(s,d,f,g);e?(s=e,u=!0):(l=!0,c.push(`Failed to replace index section`))}else l=!0,c.push(W(h,g))}return{content:s,diffs:c,hasError:l,wasUpdated:u}}function dn(e,t,n,r){for(let[i,a]of Object.entries(t)){let{commandPaths:t}=Y(a,n,r);if(t.includes(e))return i}return null}function fn(e,t,n,r,i){let a=n[t];if(!a)return[];let{specifiedCommands:o,commandPaths:s}=Y(a,r,i),c=/* @__PURE__ */ new Set;for(let t of e)if(s.includes(t)){c.add(t);for(let e of s)q(e,t)&&!o.includes(e)&&c.add(e)}return Array.from(c)}function pn(e,t,n,r,i,a,o,s=[],c,l){let u=t.get(e);if(!u||l&&Q(u.commandPath,l.commandScopes))return null;let d={...u,filePath:r,fileMap:i,rootDocPath:a};(s.length>0||l&&l.commandScopes.size>0)&&(d.subCommands=u.subCommands.filter(e=>{let t=e.fullPath.join(` `);return!s.some(e=>ct(t,e))&&!(l&&Q(t,l.commandScopes))})),o!==void 0&&(d.hasGlobalOptions=o),c&&c.size>0&&(d.options=u.options.filter(e=>!c.has(e.name)),u.extracted&&(d.extracted=hn(u.extracted,c)));let f=n(d);if(l){for(let[e,t]of l.commandSections)if(e===u.commandPath){for(let n of t){let t=Z(f,n,e);t!==null&&(f=f.replace(t,``))}f=Tt(f)}}return f}function mn(e,t,n,r,i,a,o,s,c,l){let u=Ft(e,t,r,l),d=[];for(let e of u){let u=pn(e,t,n,i,a,o,s,r,c,l);u!==null&&d.push(u)}return d.length===0?null:d.join(`
82
82
  `)}function hn(e,t){let n={...e,fields:e.fields.filter(e=>!t.has(e.name))};return e.unionOptions&&(n.unionOptions=e.unionOptions.map(e=>hn(e,t))),e.variants&&(n.variants=e.variants.map(e=>({...e,fields:e.fields.filter(e=>!t.has(e.name))}))),n}function gn(e,t,n,r,i,a,o,s,c,l=[]){let u=[],d=o?ht(o):null;d&&u.push(d);let f=mt(e,a??[]);for(let e of f){let a=pn(e,t,n,r,i,s,c,l);a&&u.push(a)}return`${u.join(`
83
- `)}\n`}function _n(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let{commandPaths:e}=Y(a,t,n);for(let t of e)it(r,t,i)}return r}async function vn(e,t,n){for(let[r,i]of Object.entries(t)){let t=e.get(r);if(!t?.examples?.length)continue;let a=i===!0?{}:i,o=r?r.split(` `):[];t.exampleResults=await Fe(t.examples,a,n,o)}}function yn(e,t){if(typeof e==`string`)return{files:{[e]:Array.from(t.keys())},rootDocPath:e};let{root:n,commands:r={}}=e,i={},a=new Set,o=Object.entries(r).sort(([e],[t])=>t.split(` `).length-e.split(` `).length);for(let[e,n]of o){i[n]||(i[n]={commands:[],noExpand:!0});let r=i[n];for(let n of t.keys())(n===e||n.startsWith(e+` `))&&!a.has(n)&&(r.commands.push(n),a.add(n))}return i[n]={commands:Array.from(t.keys()).filter(e=>!a.has(e)),noExpand:!0},{files:i,rootDocPath:n}}async function bn(e){let{command:t,ignores:r=[],format:i={},formatter:a,examples:o,targetCommands:s,globalArgs:c,customizable:l=!1}=e,d=await Pe(t),f,p=!1,m;if(e.path!==void 0){if(e.files!==void 0)throw Error(`Cannot specify both "path" and "files". Use one or the other.`);let t=yn(e.path,d);f=t.files,m=t.rootDocPath,p=!0}else if(e.files!==void 0)f=e.files;else if(e.templates!==void 0)f={};else throw Error(`Either "path", "files", or "templates" must be specified.`);let h=e.rootDoc;if(!h&&p&&(c||e.rootInfo)&&(h={path:m}),c&&h&&!h.globalOptions){let e=n(c).fields.filter(e=>!e.positional);if(e.length>0){let t=Object.fromEntries(e.map(e=>[e.name,e.schema]));h={...h,globalOptions:t}}}let g=qe(k),_=qe(A),v=!1;if(h&&!p){let e=$(h.path);if(Object.keys(f).some(t=>$(t)===e))throw Error(`rootDoc.path "${h.path}" must not also appear as a key in files.`)}o&&await vn(d,o,t);let y=s!==void 0&&s.length>0,b=Yt(h),x=new Map;if(e.templates){if(b.size>0)for(let[e,t]of b)x.set(e,t);else{let e=Jt(c);if(e)for(let t of Gt(e))x.set(t.name,t)}}let S=y?$t(s,f,d,r):Qt(f,d,r),C=[];for(let e of Object.values(f)){let t=at(e);C.push(...t.commands)}pt(r,d),ft(C,r,d);let w=_n(f,d,r),T=new Map,ee=new Map;if(e.templates)for(let[t,n]of Object.entries(e.templates)){let e=je(n);T.set(t,e),e!==null&&ee.set(t,Nt(tt(e),d))}let E=Object.entries(e.templates??{}),D=new Map,O=new Map;if(E.length>0){let e=h?$(h.path):null,t=new Set(Object.keys(f).map($)),n=new Set,i=new Set(E.map(([e])=>$(e)));for(let[r,a]of E){let o=$(r),s=$(a);if(t.has(o))throw Error(`Template output path "${r}" conflicts with an existing files key.`);if(e&&o===e)throw Error(`Template output path "${r}" conflicts with rootDoc.path "${h.path}".`);if(n.has(o))throw Error(`Duplicate template output path: "${r}".`);if(n.add(o),s===o)throw Error(`Template output path "${r}" must not be the same as its source template path.`);if(t.has(s))throw Error(`Template source path "${a}" conflicts with a files output key.`);if(e&&s===e)throw Error(`Template source path "${a}" conflicts with rootDoc.path "${h.path}".`);if(i.has(s))throw Error(`Template source path "${a}" conflicts with a template output path.`)}let a=Array.from(d.keys()).join(`, `);for(let[e,t]of E){let n=T.get(e)??null,i=[];if(n===null){D.set(e,{referencedScopes:[],headingScopes:[],commandTreeRoots:[],emitsGlobalOptions:!1,emitsIndex:!1}),O.set(e,i);continue}try{zt(n,t)}catch(e){i.push(e instanceof Error?e.message:String(e))}let o=Array.from(new Set(n.match(Rt)??[])),s=new Set,l=new Set,u=new Set,f=!1,p=!1,m=ee.get(e)??rt(new Set),g=nt(n);for(let e of o){let n=Qe(e);if(m.rawKeys.has(n)||Lt(n,m))continue;let o=Mt(e,d);if(!It(e,o,m)){if(o.kind===`invalid`){i.push(`${o.reason} (in template "${t}")`);continue}if(o.kind===`command`){let{scope:e,type:n}=o;if(!d.has(e)){let n=Bt(e,d);if(n){i.push(`${n} (in template "${t}")`);continue}i.push(`Unknown command scope "${e}" in template "${t}". Available: ${a}`);continue}if(r.some(t=>ct(e,t))){i.push(`Command scope "${e}" in template "${t}" conflicts with ignores configuration.`);continue}if(n===void 0){let t=Ft(e,d,r,m);Pt(e,`heading`,m)||u.add(e);for(let e of t)s.add(e),Pt(e,`heading`,m)||l.add(e)}else s.add(e),n===`heading`&&!Pt(e,`heading`,m)&&(l.add(e),u.add(e))}else o.kind===`global-options`?f=!0:o.kind===`index`&&(p=!0)}}f&&(h?.globalOptions||Jt(c)!==void 0||i.push(`Template "${t}" uses {{politty:global-options}} but no global options are configured (neither rootDoc.globalOptions nor globalArgs with non-positional options).`)),D.set(e,{referencedScopes:Array.from(s),headingScopes:Array.from(l),commandTreeRoots:Array.from(u),emitsGlobalOptions:f,emitsIndex:p,...g.title===void 0?{}:{indexTitle:g.title},...g.description===void 0?{}:{indexDescription:g.description}}),O.set(e,i)}for(let e of D.values())if(!y||nn(e,s))for(let t of e.referencedScopes)S.add(t)}if(y)for(let e of s){let t=dn(e,f,d,r),n=Array.from(D.values()).some(t=>tn(t,[e]));if(!t&&!n)throw Error(`Target command "${e}" not found in any file or template configuration`)}let j=y&&e.templates?new Map(Array.from(D.entries()).filter(([,e])=>nn(e,s))):D;for(let[e,t]of O.entries())if(t.length>0&&j.has(e))throw Error(t.join(`
84
- `));let M=Array.from(D.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),F=M.length===1?M[0]:void 0;if(rn(S,d,b),b.size===0&&x.size>0){let e=new Set;for(let t of j.values())if(t.emitsGlobalOptions||F!==void 0)for(let n of t.referencedScopes)e.add(n);rn(e,d,x)}if(b.size>0)for(let e of d.values())e.options=e.options.filter(e=>!b.has(e.name)),e.extracted&&=hn(e.extracted,new Set(b.keys()));let I={};for(let[e,t]of Object.entries(w))it(I,e,t);let te=e=>e===``?0:e.split(` `).length,L=new Map;for(let[e,t]of D.entries())for(let n of t.headingScopes){if(Object.prototype.hasOwnProperty.call(w,n))continue;let r=-1;for(let e of t.commandTreeRoots)q(n,e)&&(r=Math.max(r,te(e)));if(r<0)continue;let i=L.get(n);(!i||r>i.rootLen)&&L.set(n,{outputPath:e,rootLen:r})}for(let[e,{outputPath:t}]of L)it(I,e,t);let R=[],z=!1;for(let[e,t]of Object.entries(f)){let{fileConfig:n,specifiedCommands:o,commandPaths:c}=Y(t,d,r);if(o.length===0||c.length===0)continue;let u=y?fn(s,e,f,d,r):[];if(y&&u.length===0)continue;let m=`match`,x=[],S=Math.min(...c.map(e=>d.get(e)?.depth??1)),C=Math.max(1,(i?.headingLevel??1)-(S-1)),w=p&&h&&$(e)===$(h.path),T=p||l,ee=U({...i,headingLevel:C,markerless:!T}),E=n.render??ee;if(w||y&&T){let t=je(e),i=mt(c,o),s=y?u:c;for(let o of s){let s=pn(o,d,E,e,I,h?.path,b.size>0,r);if(!s)throw Error(`Target command "${o}" not found in commands`);let c=await K(s,a);if(!t){if(g){let r=o===``&&n?ht(n):null,i=r?`${r}\n${c}`:c;G(e,i),t=i,m=`created`}else z=!0,m=`diff`,x.push(`File does not exist. Target command "${o}" section cannot be validated.`);continue}let u=bt(t,o);if(u.length===0){g?(t=St(t,o,c,i),G(e,t),m!==`created`&&(m=`updated`)):(z=!0,m=`diff`,x.push(`Existing file does not contain section markers for command "${o}"`));continue}for(let n of u){let r=Z(t,n,o),i=Z(c,n,o);if(r){if(!i){let i=N(n,o)+`
83
+ `)}\n`}function _n(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let{commandPaths:e}=Y(a,t,n);for(let t of e)it(r,t,i)}return r}async function vn(e,t,n){for(let[r,i]of Object.entries(t)){let t=e.get(r);if(!t?.examples?.length)continue;let a=i===!0?{}:i,o=r?r.split(` `):[];t.exampleResults=await Fe(t.examples,a,n,o)}}function yn(e,t){if(typeof e==`string`)return{files:{[e]:Array.from(t.keys())},rootDocPath:e};let{root:n,commands:r={}}=e,i={},a=/* @__PURE__ */ new Set,o=Object.entries(r).sort(([e],[t])=>t.split(` `).length-e.split(` `).length);for(let[e,n]of o){i[n]||(i[n]={commands:[],noExpand:!0});let r=i[n];for(let n of t.keys())(n===e||n.startsWith(e+` `))&&!a.has(n)&&(r.commands.push(n),a.add(n))}return i[n]={commands:Array.from(t.keys()).filter(e=>!a.has(e)),noExpand:!0},{files:i,rootDocPath:n}}async function bn(e){let{command:t,ignores:r=[],format:i={},formatter:a,examples:o,targetCommands:s,globalArgs:c,customizable:l=!1}=e,d=await Pe(t),f,p=!1,m;if(e.path!==void 0){if(e.files!==void 0)throw Error(`Cannot specify both "path" and "files". Use one or the other.`);let t=yn(e.path,d);f=t.files,m=t.rootDocPath,p=!0}else if(e.files!==void 0)f=e.files;else if(e.templates!==void 0)f={};else throw Error(`Either "path", "files", or "templates" must be specified.`);let h=e.rootDoc;if(!h&&p&&(c||e.rootInfo)&&(h={path:m}),c&&h&&!h.globalOptions){let e=n(c).fields.filter(e=>!e.positional);if(e.length>0){let t=Object.fromEntries(e.map(e=>[e.name,e.schema]));h={...h,globalOptions:t}}}let g=qe(k),_=qe(A),v=!1;if(h&&!p){let e=$(h.path);if(Object.keys(f).some(t=>$(t)===e))throw Error(`rootDoc.path "${h.path}" must not also appear as a key in files.`)}o&&await vn(d,o,t);let y=s!==void 0&&s.length>0,b=Yt(h),x=/* @__PURE__ */ new Map;if(e.templates){if(b.size>0)for(let[e,t]of b)x.set(e,t);else{let e=Jt(c);if(e)for(let t of Gt(e))x.set(t.name,t)}}let S=y?$t(s,f,d,r):Qt(f,d,r),C=[];for(let e of Object.values(f)){let t=at(e);C.push(...t.commands)}pt(r,d),ft(C,r,d);let w=_n(f,d,r),T=/* @__PURE__ */ new Map,ee=/* @__PURE__ */ new Map;if(e.templates)for(let[t,n]of Object.entries(e.templates)){let e=je(n);T.set(t,e),e!==null&&ee.set(t,Nt(tt(e),d))}let E=Object.entries(e.templates??{}),D=/* @__PURE__ */ new Map,O=/* @__PURE__ */ new Map;if(E.length>0){let e=h?$(h.path):null,t=new Set(Object.keys(f).map($)),n=/* @__PURE__ */ new Set,i=new Set(E.map(([e])=>$(e)));for(let[r,a]of E){let o=$(r),s=$(a);if(t.has(o))throw Error(`Template output path "${r}" conflicts with an existing files key.`);if(e&&o===e)throw Error(`Template output path "${r}" conflicts with rootDoc.path "${h.path}".`);if(n.has(o))throw Error(`Duplicate template output path: "${r}".`);if(n.add(o),s===o)throw Error(`Template output path "${r}" must not be the same as its source template path.`);if(t.has(s))throw Error(`Template source path "${a}" conflicts with a files output key.`);if(e&&s===e)throw Error(`Template source path "${a}" conflicts with rootDoc.path "${h.path}".`);if(i.has(s))throw Error(`Template source path "${a}" conflicts with a template output path.`)}let a=Array.from(d.keys()).join(`, `);for(let[e,t]of E){let n=T.get(e)??null,i=[];if(n===null){D.set(e,{referencedScopes:[],headingScopes:[],commandTreeRoots:[],emitsGlobalOptions:!1,emitsIndex:!1}),O.set(e,i);continue}try{zt(n,t)}catch(e){i.push(e instanceof Error?e.message:String(e))}let o=Array.from(new Set(n.match(Rt)??[])),s=/* @__PURE__ */ new Set,l=/* @__PURE__ */ new Set,u=/* @__PURE__ */ new Set,f=!1,p=!1,m=ee.get(e)??rt(/* @__PURE__ */ new Set),g=nt(n);for(let e of o){let n=Qe(e);if(m.rawKeys.has(n)||Lt(n,m))continue;let o=Mt(e,d);if(!It(e,o,m)){if(o.kind===`invalid`){i.push(`${o.reason} (in template "${t}")`);continue}if(o.kind===`command`){let{scope:e,type:n}=o;if(!d.has(e)){let n=Bt(e,d);if(n){i.push(`${n} (in template "${t}")`);continue}i.push(`Unknown command scope "${e}" in template "${t}". Available: ${a}`);continue}if(r.some(t=>ct(e,t))){i.push(`Command scope "${e}" in template "${t}" conflicts with ignores configuration.`);continue}if(n===void 0){let t=Ft(e,d,r,m);Pt(e,`heading`,m)||u.add(e);for(let e of t)s.add(e),Pt(e,`heading`,m)||l.add(e)}else s.add(e),n===`heading`&&!Pt(e,`heading`,m)&&(l.add(e),u.add(e))}else o.kind===`global-options`?f=!0:o.kind===`index`&&(p=!0)}}f&&(h?.globalOptions||Jt(c)!==void 0||i.push(`Template "${t}" uses {{politty:global-options}} but no global options are configured (neither rootDoc.globalOptions nor globalArgs with non-positional options).`)),D.set(e,{referencedScopes:Array.from(s),headingScopes:Array.from(l),commandTreeRoots:Array.from(u),emitsGlobalOptions:f,emitsIndex:p,...g.title===void 0?{}:{indexTitle:g.title},...g.description===void 0?{}:{indexDescription:g.description}}),O.set(e,i)}for(let e of D.values())if(!y||nn(e,s))for(let t of e.referencedScopes)S.add(t)}if(y)for(let e of s){let t=dn(e,f,d,r),n=Array.from(D.values()).some(t=>tn(t,[e]));if(!t&&!n)throw Error(`Target command "${e}" not found in any file or template configuration`)}let j=y&&e.templates?new Map(Array.from(D.entries()).filter(([,e])=>nn(e,s))):D;for(let[e,t]of O.entries())if(t.length>0&&j.has(e))throw Error(t.join(`
84
+ `));let M=Array.from(D.entries()).filter(([,e])=>e.emitsGlobalOptions).map(([e])=>e),F=M.length===1?M[0]:void 0;if(rn(S,d,b),b.size===0&&x.size>0){let e=/* @__PURE__ */ new Set;for(let t of j.values())if(t.emitsGlobalOptions||F!==void 0)for(let n of t.referencedScopes)e.add(n);rn(e,d,x)}if(b.size>0)for(let e of d.values())e.options=e.options.filter(e=>!b.has(e.name)),e.extracted&&=hn(e.extracted,new Set(b.keys()));let I={};for(let[e,t]of Object.entries(w))it(I,e,t);let te=e=>e===``?0:e.split(` `).length,L=/* @__PURE__ */ new Map;for(let[e,t]of D.entries())for(let n of t.headingScopes){if(Object.prototype.hasOwnProperty.call(w,n))continue;let r=-1;for(let e of t.commandTreeRoots)q(n,e)&&(r=Math.max(r,te(e)));if(r<0)continue;let i=L.get(n);(!i||r>i.rootLen)&&L.set(n,{outputPath:e,rootLen:r})}for(let[e,{outputPath:t}]of L)it(I,e,t);let R=[],z=!1;for(let[e,t]of Object.entries(f)){let{fileConfig:n,specifiedCommands:o,commandPaths:c}=Y(t,d,r);if(o.length===0||c.length===0)continue;let u=y?fn(s,e,f,d,r):[];if(y&&u.length===0)continue;let m=`match`,x=[],S=Math.min(...c.map(e=>d.get(e)?.depth??1)),C=Math.max(1,(i?.headingLevel??1)-(S-1)),w=p&&h&&$(e)===$(h.path),T=p||l,ee=U({...i,headingLevel:C,markerless:!T}),E=n.render??ee;if(w||y&&T){let t=je(e),i=mt(c,o),s=y?u:c;for(let o of s){let s=pn(o,d,E,e,I,h?.path,b.size>0,r);if(!s)throw Error(`Target command "${o}" not found in commands`);let c=await K(s,a);if(!t){if(g){let r=o===``&&n?ht(n):null,i=r?`${r}\n${c}`:c;G(e,i),t=i,m=`created`}else z=!0,m=`diff`,x.push(`File does not exist. Target command "${o}" section cannot be validated.`);continue}let u=bt(t,o);if(u.length===0){g?(t=St(t,o,c,i),G(e,t),m!==`created`&&(m=`updated`)):(z=!0,m=`diff`,x.push(`Existing file does not contain section markers for command "${o}"`));continue}for(let n of u){let r=Z(t,n,o),i=Z(c,n,o);if(r){if(!i){let i=N(n,o)+`
85
85
  `+P(n,o);if(r!==i){if(g){let r=vt(t,n,o,i);if(!r)throw Error(`Failed to replace stale ${n} section for command "${o}"`);t=r.replace(/\n{3,}/g,`
86
86
 
87
87
  `),G(e,t),m!==`created`&&(m=`updated`)}else z=!0,m=`diff`,x.push(W(r,i))}continue}if(r!==i){if(g){let r=vt(t,n,o,i);if(r)t=r,G(e,t),m!==`created`&&(m=`updated`);else throw Error(`Failed to replace ${n} section for command "${o}"`)}else z=!0,m=`diff`,x.push(W(r,i))}}}if(_||l){let n=bt(c,o),r=new Set(u);for(let i of n){if(r.has(i))continue;let n=Z(c,i,o);n&&(_&&g?(t=yt(t,i,o,n),G(e,t),m!==`created`&&(m=`updated`)):_?(z=!0,v=!0,m=`diff`,x.push(`[doctor] Missing section marker "${i}" for command "${X(o)}". Run with ${A}=true ${k}=true to insert.\n${n}`)):console.warn(`[politty] Missing "${i}" section for command "${X(o)}" in ${e}. Run with ${A}=true ${k}=true to insert it, or leave it removed to opt that section out.`))}}}if(t){let n=xt(t),r=new Set(c);if(g){let i=!1;for(let e of n)r.has(e)||(t=Ct(t,e),i=!0);i&&(G(e,t),m!==`created`&&(m=`updated`))}else for(let e of n)r.has(e)||(z=!0,m=`diff`,x.push(`Found orphaned section markers for deleted command "${X(e)}"`))}}else{let t=await K(gn(c,d,E,e,I,o,n,h?.path,b.size>0,r),a),i=Ae(t,e);i.match||(g?(G(e,t),m=i.fileExists?`updated`:`created`):(z=!0,m=`diff`,i.diff&&x.push(i.diff)))}x.length>0&&(m=`diff`),R.push({path:e,status:m,diff:x.length>0?x.join(`
88
88
 
89
- `):void 0})}let B;if(h?.globalOptions)B=qt(h.globalOptions);else{let e=Jt(c);e&&(B={args:e})}for(let[e,n]of E){if(!j.has(e))continue;let o=T.get(e)??null;if(o===null){z=!0,R.push({path:e,status:`diff`,diff:`Template file not found: ${n}`});continue}let s=D.get(e),c=Et(o),l=Ye(o),u=(s?.headingScopes??[]).map(e=>d.get(e)?.depth??1),p=u.length>0?Math.min(...u):1,m=kt((i?.headingLevel??1)-(p-1)),_=U({...i,headingLevel:m}),v=s?.emitsGlobalOptions??!1,y=(h!==void 0&&b.size>0||v||F!==void 0)&&x.size>0?new Set(x.keys()):void 0,S=y!==void 0,C=v?e:h?.path??F,w=Array.from(new Set(l.match(Rt)??[])),E=new Map,O=ee.get(e)??rt(new Set);for(let i of w){let a=Qe(i);if(O.rawKeys.has(a)||Lt(a,O)){E.set(i,``);continue}let o=Mt(i,d);if(It(i,o,O)){E.set(i,``);continue}if(o.kind===`invalid`)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}": ${o.reason}`);if(o.kind===`command`){let{scope:t,type:n}=o;if(n===void 0){let n=mn(t,d,_,r,e,I,C,S,y,O);if(n===null){E.set(i,``);continue}E.set(i,wt(n))}else{let a=pn(t,d,_,e,I,C,S,r,y,O);if(a===null){E.set(i,``);continue}let o=Z(a,n,t);E.set(i,o===null?``:wt(o))}}else if(o.kind===`global-options`)B?E.set(i,an(B)):E.set(i,``);else if(o.kind===`index`){let n=await Ke(t,[...Xt(f,e,d,r),...Zt(D,e,e,d)],h?.index);E.set(i,n)}}let k=l.replace(/((?:\r?\n)*)([ \t]*)(\{\{politty:[^{}]*\}\})([ \t]*)((?:\r?\n)*)/g,(e,t,r,i,a,o,s,c)=>{let l=E.get(i);if(l===void 0)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}".`);let u=t!==``||s===0||c[s-1]===`
89
+ `):void 0})}let B;if(h?.globalOptions)B=qt(h.globalOptions);else{let e=Jt(c);e&&(B={args:e})}for(let[e,n]of E){if(!j.has(e))continue;let o=T.get(e)??null;if(o===null){z=!0,R.push({path:e,status:`diff`,diff:`Template file not found: ${n}`});continue}let s=D.get(e),c=Et(o),l=Ye(o),u=(s?.headingScopes??[]).map(e=>d.get(e)?.depth??1),p=u.length>0?Math.min(...u):1,m=kt((i?.headingLevel??1)-(p-1)),_=U({...i,headingLevel:m}),v=s?.emitsGlobalOptions??!1,y=(h!==void 0&&b.size>0||v||F!==void 0)&&x.size>0?new Set(x.keys()):void 0,S=y!==void 0,C=v?e:h?.path??F,w=Array.from(new Set(l.match(Rt)??[])),E=/* @__PURE__ */ new Map,O=ee.get(e)??rt(/* @__PURE__ */ new Set);for(let i of w){let a=Qe(i);if(O.rawKeys.has(a)||Lt(a,O)){E.set(i,``);continue}let o=Mt(i,d);if(It(i,o,O)){E.set(i,``);continue}if(o.kind===`invalid`)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}": ${o.reason}`);if(o.kind===`command`){let{scope:t,type:n}=o;if(n===void 0){let n=mn(t,d,_,r,e,I,C,S,y,O);if(n===null){E.set(i,``);continue}E.set(i,wt(n))}else{let a=pn(t,d,_,e,I,C,S,r,y,O);if(a===null){E.set(i,``);continue}let o=Z(a,n,t);E.set(i,o===null?``:wt(o))}}else if(o.kind===`global-options`)B?E.set(i,an(B)):E.set(i,``);else if(o.kind===`index`){let n=await Ke(t,[...Xt(f,e,d,r),...Zt(D,e,e,d)],h?.index);E.set(i,n)}}let k=l.replace(/((?:\r?\n)*)([ \t]*)(\{\{politty:[^{}]*\}\})([ \t]*)((?:\r?\n)*)/g,(e,t,r,i,a,o,s,c)=>{let l=E.get(i);if(l===void 0)throw Error(`Internal error: unresolved placeholder "${i}" in template "${n}".`);let u=t!==``||s===0||c[s-1]===`
90
90
  `,d=o!==``||s+e.length===c.length;if(l===``&&u&&d){if(t===``||o===``)return``;let e=Dt(t),n=Dt(o),r=Math.max(e,n),i=Et(e>=n?t:o);return r>=2?i+i:r===1?i:``}return`${t}${r}${l}${a}${o}`});k=`${k.trimEnd()}${c}`,k=await K(k,a);let A=Ae(k,e),M=`match`,N;A.match||(g?(G(e,k),M=A.fileExists?`updated`:`created`):(z=!0,M=`diff`,A.diff&&(N=A.diff))),R.push({path:e,status:M,diff:N})}if(h){let n=h.path,i=`match`,o=[],s=je(n);if(s===null)z=!0,i=`diff`,o.push(`File does not exist. Cannot validate rootDoc markers.`);else{let c=s,l=!1,m=e.rootInfo,_={title:m?.title??t.name};h.headingLevel!==void 0&&(_.headingLevel=h.headingLevel);let v=m?.description??t.description;v!==void 0&&(_.description=v);let y=_t(c,_,g);if(c=y.content,y.diff&&o.push(y.diff),y.hasError&&(z=!0),y.wasUpdated&&(l=!0),m?.header){let e=await ln(c,`Root header`,ne(),re(),m.header,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(z=!0),e.wasUpdated&&(l=!0)}if(!p){let e=xt(c);if(e.length>0){if(g){for(let t of e)c=Ct(c,t);l=!0}else z=!0,o.push(`Found unexpected section markers in rootDoc: ${e.map(e=>`"${X(e)}"`).join(`, `)}.`)}}let b=qt(h.globalOptions);if(b){let e=await cn(c,b,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(z=!0),e.wasUpdated&&(l=!0)}let x=Xt(f,n,d,r),S=u.relative(process.cwd(),n).replace(/\\/g,`/`),C=await un(c,x,t,S,g,a,h.index);if(c=C.content,o.push(...C.diffs),C.hasError&&(z=!0),C.wasUpdated&&(l=!0),m?.footer){let e=await ln(c,`Root footer`,ie(),ae(),m.footer,g,a,p);c=e.content,o.push(...e.diffs),e.hasError&&(z=!0),e.wasUpdated&&(l=!0)}g&&l&&(G(n,c),i===`match`&&(i=`updated`))}o.length>0&&(i=`diff`),R.push({path:n,status:i,diff:o.length>0?o.join(`
91
91
 
92
92
  `):void 0})}return{success:!z,files:R,error:z?`Documentation is out of date. ${v?`Run with ${A}=true ${k}=true to fix missing markers.`:`Run with ${k}=true to update.`}`:void 0}}async function xn(e){let t=await bn(e);if(!t.success){let e=t.files.filter(e=>e.status===`diff`).map(e=>{let t=`File: ${e.path}\n`;return e.diff&&(t+=e.diff),t}).join(`
@@ -0,0 +1 @@
1
+ import{t as e}from"./dynamic-DbvYJg3o.js";export{e as createDynamicCompleteCommand};
@@ -0,0 +1,6 @@
1
+ import{i as e,n as t}from"./field-meta-D9ySul7J.js";import{a as n,l as r,n as i}from"./schema-extractor-fZZ2_WAZ.js";import{n as a}from"./command-tLHaJHe6.js";import{c as o,i as s}from"./subcommand-router-DR2KBQAt.js";import{i as c}from"./argv-parser-CawJSYjw.js";import{t as l}from"./schema-tWeEQULd.js";import{execSync as u}from"node:child_process";function d(e,t,n){return{fieldName:e.name,isArrayOption:e.valueType===`array`,isGlobal:e.isGlobal===!0,resolvedDeps:p(e.valueCompletion,e.isGlobal===!0,t,n)}}function f(e,t,n){return{fieldName:e.name,isArrayOption:!1,isGlobal:!1,resolvedDeps:p(e.valueCompletion,!1,t,n)}}function p(e,t,n,r=[]){if(e?.type!==`expand`)return[];let i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let e of n)e.isGlobal===!0?i.add(e.name):a.add(e.name);for(let e of r)a.add(e.name);return e.dependsOn.map(e=>({name:e,isGlobal:t||i.has(e)&&!a.has(e)}))}function m(e){let t=`$'`;for(let n of e){let e=n.codePointAt(0);t+=n===`\\`?`\\\\`:n===`'`?`\\'`:n===`
2
+ `?`\\n`:n===`\r`?`\\r`:n===` `?`\\t`:e<32||e===127?`\\x${e.toString(16).padStart(2,`0`)}`:n}return t+=`'`,t}function h(e){return`'${e.replace(/'/g,`'\\''`)}'`}function g(e,t){let n=t.withSize?`%Y:%s`:`%Y`,r=t.withSize?`%m:%z`:`%m`,i=`stat -L -c '${n}' "${e}" 2>/dev/null`,a=`stat -L -f '${r}' "${e}" 2>/dev/null`;return t.shell===`fish`?`(${i}; or ${a})`:`$(${i} || ${a})`}function _(e){return e.length===1?`-${e}`:`--${e}`}function v(t,n){y(t,_(n)),n.length===1?y(t,`--${n}`):n.includes(`-`)&&y(t,`--${e(n)}`)}function y(e,t){e.includes(t)||e.push(t)}function b(t,n){let r=[`--${t}`];t.length===1&&r.push(`-${t}`),t.includes(`-`)&&r.push(`--${e(t)}`);for(let e of n??[])v(r,e);return r}function x(e){let t=/* @__PURE__ */ new Set;for(let n of e)if(n.isGlobal===!0){n.cliName.length===1&&t.add(`-${n.cliName}`);for(let e of n.alias??[])e.length===1&&t.add(`-${e}`)}return t}function S(t,n,r,i){let a=new Set(b(t,n));if(r&&(a.add(`--${r}`),r.includes(`-`)&&a.add(`--${e(r)}`)),i?.frameOptions){if(i.isGlobal===!0){for(let e of i.frameOptions)if(e.isGlobal!==!0)for(let t of E(e.cliName,e.alias))a.delete(t)}else{let e=x(i.frameOptions);if(e.size>0){let t=new Set((n??[]).filter(e=>e.length===1).map(e=>`-${e}`));for(let n of e)t.has(n)||a.delete(n)}}}return[...a].map(e=>`"${e}"`)}function C(e,t){return e.map(e=>{let n=t.find(t=>t.isGlobal!==!0&&t.name===e.name);return n&&S(n.cliName,n.alias,n.negation,{frameOptions:t})})}function w(e,t,n,r=`$_pos_count`){let i=C(e,t);if(i.every(e=>e===void 0))return;let a=[` local _slot=-1 _left=${r}`];return e.forEach((e,t)=>{let r=i[t],o=r?` && __${n}_not_used ${r.join(` `)}`:``,s=e.variadic?`_slot=${e.position}`:`if (( _left == 0 )); then _slot=${e.position}; else (( _left-- )); fi`;a.push(` if (( _slot < 0 ))${o}; then ${s}; fi`)}),a}function T(e,t){let n=[`__${e}_track_positionals() {`,` local _k=0 _w`,' for _w in "${_pos_words[@]}"; do',` local _slot=$_k`,` case "$_subcmd" in`];for(let r of t){n.push(` ${r.pathStrs.map(e=>`"${e}"`).join(`|`)})`);for(let t of w(r.positionals,r.options,e,`$_k`)??[])n.push(` ${t}`);n.push(` ;;`)}return n.push(` esac`,` __${e}_track_pos "$_subcmd" "$_slot" "$_w"`,` (( _k++ ))`,` done`,`}`,``),n}function E(t,n){let r=[`--${t}`];t.includes(`-`)&&r.push(`--${e(t)}`);for(let e of n??[])v(r,e);return r}function D(e){let t=e.completion;if(t?.custom){let n=t.custom,r=[];if(n.expand&&r.push(`expand`),n.resolve&&r.push(`resolve`),n.choices&&n.choices.length>0&&r.push(`choices`),n.shellCommand&&r.push(`shellCommand`),r.length>1)throw Error(`Field "${e.name??`<unknown>`}": completion.custom may only specify one of choices, shellCommand, resolve, expand (got ${r.join(`, `)}).`);if(n.expand)return{type:`pending-expand`,spec:n.expand};if(n.resolve)return{type:`dynamic`,resolve:n.resolve};if(n.choices&&n.choices.length>0)return{type:`choices`,choices:n.choices};if(n.shellCommand)return{type:`command`,shellCommand:n.shellCommand}}if(t?.type){if(t.type===`file`)return t.matcher?{type:`file`,matcher:t.matcher}:t.extensions?{type:`file`,extensions:t.extensions}:{type:`file`};if(t.type===`directory`)return{type:`directory`};if(t.type===`none`)return{type:`none`}}if(e.enumValues&&e.enumValues.length>0)return{type:`choices`,choices:e.enumValues}}function O(e){if(e)return e.type===`pending-expand`?{type:`runtime-expand`,dependsOn:e.spec.dependsOn,enumerate:e.spec.enumerate}:e}function ee(e){return e.args?te(e.args):[]}function te(e){return n(i(e)).map(k)}function k(e){let n=t(e);return{name:e.name,cliName:e.cliName,alias:n.length>0?n:void 0,negation:e.negationDisplay,negationDescription:e.negationDescription,description:e.description,takesValue:e.type!==`boolean`,valueType:e.type,required:e.required,defaultNegationAccepted:e.type===`boolean`&&e.negation===!0,valueCompletion:O(D(e))}}function A(e){return new Set(b(e.cliName,e.alias))}function ne(e,t){let n=A(t);for(let t of e)for(let e of A(t))if(n.has(e))return t}function re(e,t,n){let r=/* @__PURE__ */ new Set;if(t.length===0)return r;let i=/* @__PURE__ */ new Set,a=(e,t)=>{B(n,e,t,i),r.add(e.name)},o=0;for(;o<e.length;){let i=e[o];if(i===`--`||!i.startsWith(`-`))break;if(!i.startsWith(`--`)&&i.length>2){let e=i.indexOf(`=`);if((e>=0?i.slice(1,e):i.slice(1)).length>1)break}let s=F(i),c=U(t,s);if(!c){if(le(t,s)){o++;continue}break}if(c.takesValue){if(I(i)){let e=i.indexOf(`=`);a(c,i.slice(e+1)),o++}else if(o+1<e.length){let t=e[o+1];if(t.startsWith(`-`)){o++;continue}a(c,t),o+=2}else break}else n[c.name]=!V(c,s),r.add(c.name),o++}return r}function ie(e,t){return t.valueType===`array`?Array.isArray(e)?e:[e]:Array.isArray(e)?e.at(-1):e}function j(e,t){return t.length===0?e:[...e,...t]}function M(e,t){let n=t.length-1;if(!(n<0))return e>n?n:e}function N(e,t){return n=>{let r={...e};return c(n,e).forEach((e,n)=>{n<t.length&&(r[e.name]=t[n])}),r}}function ae(e,t,n){if(!e.args)return;let a=i(e.args),o=r(a,N(t,n));if(o!==a)return o.fields.filter(e=>e.named).map(k)}function oe(e,t,n){if(!e.args)return[];let a=r(i(e.args),N(t,n));return c(a,t).map((e,t)=>({name:e.name,cliName:e.cliName,position:t,description:e.description,required:e.required,variadic:e.type===`array`,valueCompletion:O(D(e))}))}function se(e){if(!e.subCommands)return[];let t=[];for(let[n,r]of Object.entries(e.subCommands)){if(n.startsWith(`__`))continue;t.push(n);let e=o(r);e?.aliases&&t.push(...e.aliases)}return t}function ce(e,t){if(!e.subCommands)return null;let n=Object.hasOwn(e.subCommands,t)?e.subCommands[t]:void 0;if(n)return o(n);let r=s(e,t);return r?o(e.subCommands[r]):null}function P(e){return e.startsWith(`-`)}function F(e){if(e.startsWith(`--`)){let t=e.slice(2),n=t.indexOf(`=`);return{name:n>=0?t.slice(0,n):t,isLong:!0}}return e.startsWith(`-`)?{name:e.slice(1,2),isLong:!1}:{name:e,isLong:!0}}function I(e){return e.includes(`=`)}function L(t,n,r){if(!r||t.valueType!==`boolean`)return!1;let i=[t.cliName,...t.alias??[]];for(let t of i){let r=`no-${t}`;if(n===r||n===e(r))return!0}return!1}function R(e,t,n){return e.defaultNegationAccepted===!0&&L(e,t,n)}function le(e,t){return e.some(e=>e.defaultNegationAccepted!==!0&&L(e,t.name,t.isLong))}function z(t,n){return t!==void 0&&t.includes(`-`)&&e(t)===n}function B(e,t,n,r){if(t.valueType!==`array`){e[t.name]=n;return}if(r.has(t.name)){let r=e[t.name];e[t.name]=Array.isArray(r)?[...r,n]:[n]}else e[t.name]=[n],r.add(t.name)}function V(e,t){return t.isLong?e.negation!==void 0&&(e.negation===t.name||z(e.negation,t.name))?!0:R(e,t.name,t.isLong):!1}function H(e,t,n){if(e.cliName===t&&(n||e.cliName.length===1))return!0;if(e.alias){for(let r of e.alias)if(r===t&&(n||r.length===1))return!0}return n&&e.negation===t?!0:!n||t.length<=1?!1:z(e.cliName,t)||e.alias?.some(e=>z(e,t))?!0:z(e.negation,t)}function U(e,t){if(!t.isLong){let n=e.find(e=>e.isGlobal!==!0&&e.alias?.includes(t.name)===!0);if(n)return n;let r=e.find(e=>e.isGlobal===!0&&H(e,t.name,t.isLong));if(r)return r}return e.find(e=>H(e,t.name,t.isLong))||e.find(e=>R(e,t.name,t.isLong))}function W(e,t,n){let r=G(e,t,n);return r.variantOptions?G(e,t,n,{command:r.context.currentCommand,options:r.variantOptions}).context:r.context}function G(e,t,n,r){let i=e=>e===r?.command?r.options:ee(e),a=t,o=[],s=n?te(n).map(e=>({...e,isGlobal:!0})):[],c=/* @__PURE__ */ new Set,l=!1,u=0,d={},f=[],p={},m=/* @__PURE__ */ new Set,h=0,g=/* @__PURE__ */ new Set,_=e=>{c.add(e.cliName);for(let t of e.alias??[])c.add(t);e.negation&&c.add(e.negation),l=!0},v=(e,t)=>{B(e.isGlobal===!0?p:d,e,t,g)},y=(e,t)=>{let n=e.isGlobal===!0?p:d;n[e.name]=!V(e,t)},b=0,x=j(i(a),s),S=!1;for(;b<e.length-1;){let t=e[b];if(!S&&t===`--`){S=!0,b++;continue}if(!S&&t.startsWith(`-`)&&!t.startsWith(`--`)&&t.length>2&&!t.includes(`=`)){l=!0;let e=Array.from(t.slice(1)),n=x.filter(e=>e.isGlobal!==!0);for(let t of e){let e=U(n,{name:t,isLong:!1});e&&!e.takesValue&&(_(e),y(e,{name:t,isLong:!1}))}b++;continue}if(!S&&P(t)){l=!0;let n=F(t),r=U(x,n);if(r){if(_(r),r.takesValue){if(I(t)){let e=t.indexOf(`=`);v(r,t.slice(e+1))}else if(b+1<e.length-1){let t=e[b+1];P(t)||(v(r,t),b++)}}else y(r,n)}b++;continue}let n=S?null:ce(a,t);if(n){o.push(t);let r=i(a),l=e.slice(h,b);for(let e of re(l,s,p))m.add(e);a=n,x=j(i(a),s);for(let e of Object.keys(d)){let t=r.find(t=>t.name===e),n=s.find(t=>t.name===e)??(t?ne(s,t):void 0);n&&(m.has(n.name)||(p[n.name]=ie(d[e],n)))}c.clear(),u=0,d={},f=[],g=/* @__PURE__ */ new Set,h=b+1,b++;continue}f.push(t),u++,b++}let C=e[e.length-1]??``,w=e[e.length-2]??``,T=ae(a,d,f),E=oe(a,d,f),D=se(a);for(let e=0;e<E.length;e++){let t=E[e];if(t.variadic){d[t.name]=f.slice(e);break}e<f.length&&(d[t.name]=f[e])}let O,k,A;if(!S&&w&&P(w)&&!I(w)){let e=U(x,F(w));e&&e.takesValue?(O=`option-value`,k=e):C.startsWith(`-`)?O=`option-name`:(O=K(C,D,E,u),O===`positional`&&(A=u))}else if(!S&&C.startsWith(`-`)&&I(C)){let e=U(x,F(C));e&&e.takesValue?(O=`option-value`,k=e):O=`option-name`}else!S&&C.startsWith(`-`)?O=`option-name`:(O=K(C,D,E,u,S),O===`positional`&&(A=u));let N=[];if(k){if(k.valueType===`array`){let e=(k.isGlobal===!0?p:d)[k.name];N=Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}}else if(O===`positional`&&A!==void 0){let e=M(A,E);e!==void 0&&E[e]?.variadic&&(N=f.slice(e))}let L={...p,...d};return{context:{subcommandPath:o,currentCommand:a,currentWord:C,previousWord:w,completionType:O,targetOption:k,positionalIndex:A,options:x,subcommands:D,positionals:E,usedOptions:c,hasAnyOptionBeenUsed:l,providedPositionalCount:u,parsedArgs:L,previousValues:N},variantOptions:T}}function K(e,t,n,r,i){return i?`positional`:t.length>0&&(t.filter(t=>t.startsWith(e)).length>0||e===``)?`subcommand`:r<n.length||n.length>0&&n[n.length-1].variadic?`positional`:`subcommand`}const q={Default:0,NoSpace:1,NoFileCompletion:2,FilterPrefix:4,KeepOrder:8,FileCompletion:16,DirectoryCompletion:32,Error:64};function J(e){if(!e.startsWith(`-`))return;let t=e.indexOf(`=`);if(!(t<=0))return e.slice(0,t+1)}async function Y(e,t){switch(e.completionType){case`subcommand`:return ve(e);case`option-name`:return Z(e);case`option-value`:{let n=e.targetOption,r=n?J(e.currentWord):void 0;return xe(r?{...e,currentWord:e.currentWord.slice(r.length)}:e,t,n?.name,n?.valueCompletion,void 0,n?.valueType===`array`)}case`positional`:{let n=ue(e);return n?xe(e,t,n.name,n.valueCompletion,n.description,!1):{candidates:[],directive:q.NoFileCompletion}}}}function ue(e){let t=e.positionalIndex??0,n=M(t,e.positionals);if(n===void 0)return;let r=e.positionals[n];if(r)return n===t||r.variadic?r:void 0}function de(e){try{return u(e,{encoding:`utf-8`,timeout:5e3}).split(`
3
+ `).map(e=>e.trim()).filter(e=>e.length>0).map(e=>({value:e,type:`value`}))}catch{return[]}}function X(e){return e?.type===`choices`?e.choices:void 0}function fe(e,t){let n=e.options.find(e=>e.name===t&&e.isGlobal!==!0);if(n)return X(n.valueCompletion);let r=e.positionals.find(e=>e.name===t);return X(r?r.valueCompletion:e.options.find(e=>e.name===t&&e.isGlobal===!0)?.valueCompletion)}function pe(e,t){let n=!t.includes(`=`),r=n?me(e):he(e,t);return{candidates:r,hasEqSuffix:n&&r.some(e=>e.value.endsWith(`=`))}}function me(e){let t=/* @__PURE__ */ new Set,n=[];for(let r of e){let e=r.value.indexOf(`=`);if(e<=0){n.push(r);continue}let i=r.value.slice(0,e+1);t.has(i)||(t.add(i),n.push({...r,value:i}))}return n}function he(e,t){let n=t.slice(0,t.indexOf(`=`)+1);return e.filter(e=>e.value!==n)}async function ge(e,t,n,r,i){let a=[],o=q.FilterPrefix,s,c;switch(e.type){case`choices`:if(e.choices)for(let t of e.choices)a.push({value:t,description:r,type:`value`});o|=q.NoFileCompletion;break;case`file`:e.matcher&&e.matcher.length>0?(c=e.matcher.filter(e=>e.trim().length>0),c.length===0&&(c=void 0,o|=q.FileCompletion)):e.extensions&&e.extensions.length>0?(s=Array.from(new Set(e.extensions.map(e=>e.trim().replace(/^\./,``)).filter(e=>e.length>0))),s.length===0&&(s=void 0,o|=q.FileCompletion)):o|=q.FileCompletion;break;case`directory`:o|=q.DirectoryCompletion;break;case`command`:e.shellCommand&&a.push(...de(e.shellCommand)),o|=q.NoFileCompletion;break;case`none`:o|=q.NoFileCompletion;break;case`dynamic`:try{let n=await e.resolve(t);for(let e of n.candidates){let t=typeof e==`string`?{value:e}:e;a.push({...t,type:`value`})}o=n.directive??q.FilterPrefix|q.NoFileCompletion}catch{o=q.NoFileCompletion|q.Error}break;case`expand`:o|=q.NoFileCompletion;break;case`runtime-expand`:{let r={},i=!1;for(let a of e.dependsOn){let e=t.parsedArgs[a],o=Array.isArray(e)?e[e.length-1]:e,s=fe(n,a);if(typeof o!=`string`||s===void 0||!s.includes(o)){i=!0;break}r[a]=o}if(!i)try{let t=/* @__PURE__ */ new Set;for(let n of e.enumerate(r)){let e=typeof n==`string`?{value:n}:n;t.has(e.value)||(t.add(e.value),a.push({...e,type:`value`}))}}catch{o=q.NoFileCompletion|q.Error;break}o|=q.NoFileCompletion;break}}if(e.type===`dynamic`||e.type===`expand`||e.type===`runtime-expand`){let n=pe(e.type===`runtime-expand`&&i===!0?_e(a,t.previousValues):a,t.currentWord);return n.hasEqSuffix&&(o|=q.NoSpace),{candidates:n.candidates,directive:o,fileExtensions:s,fileMatchers:c}}return{candidates:a,directive:o,fileExtensions:s,fileMatchers:c}}function _e(e,t){let n=/* @__PURE__ */ new Set;for(let e of t){let t=e.indexOf(`=`);t>0&&n.add(e.slice(0,t))}return n.size===0?[...e]:e.filter(e=>{let t=e.value.indexOf(`=`);return t<=0||!n.has(e.value.slice(0,t))})}function ve(e){let t=[];for(let n of e.subcommands){let r=e.currentCommand.subCommands,i=r?.[n],a=i?void 0:s(e.currentCommand,n),c=i??(a?r?.[a]:void 0),l=c?o(c)?.description:void 0;t.push({value:n,description:l,type:`subcommand`})}if(t.length===0||e.currentWord.startsWith(`-`)){let n=Z(e);t.push(...n.candidates)}return{candidates:t,directive:q.FilterPrefix|q.NoFileCompletion}}function Z(e){let t=[],n=e.options.filter(t=>t.valueType===`array`||!(e.usedOptions.has(t.cliName)||t.alias&&t.alias.some(t=>e.usedOptions.has(t))||t.negation&&e.usedOptions.has(t.negation)));for(let e of n)t.push({value:`--${e.cliName}`,description:e.description,type:`option`}),e.negation&&t.push({value:`--${e.negation}`,description:e.negationDescription??e.description,type:`option`});return e.hasAnyOptionBeenUsed||t.push({value:`--help`,description:`Show help information`,type:`option`},{value:`--help-all`,description:`Show help with all subcommand options`,type:`option`},{value:`--help-json`,description:`Show help as JSON`,type:`option`}),{candidates:t,directive:q.FilterPrefix|q.NoFileCompletion}}function ye(e,t,n){return{currentWord:e.currentWord,shell:t.shell,parsedArgs:be(e.parsedArgs,n),previousValues:e.previousValues,subcommandPath:e.subcommandPath}}function be(e,t){if(t===void 0||!(t in e))return e;let n={...e};return delete n[t],n}async function xe(e,t,n,r,i,a){return r?ge(r,ye(e,t,n),e,i,a):{candidates:[],directive:q.FilterPrefix}}function Q(e,t){switch(t.shell){case`bash`:return Se(e,t);case`zsh`:return Ce(e,t);case`fish`:return we(e,t)}}function $(e,t){let n=`:${t.directive}`;t.fileExtensions&&t.fileExtensions.length>0&&(n+=`\t@ext:${t.fileExtensions.join(`,`)}`),t.fileMatchers&&t.fileMatchers.length>0&&(n+=`\t@matcher:${t.fileMatchers.join(`,`)}`),e.push(n)}function Se(e,t){let n=((e.directive&q.FilterPrefix)!==0&&t.currentWord?e.candidates.filter(e=>e.value.startsWith(t.currentWord)):e.candidates).map(e=>t.inlinePrefix?`${t.inlinePrefix}${e.value}`:e.value);return $(n,e),n.join(`
4
+ `)}function Ce(e,t){let n=e.candidates.map(e=>{let t=e.value.replace(/:/g,`\\:`);return e.description?`${t}:${e.description.replace(/:/g,`\\:`)}`:t});return $(n,e),n.join(`
5
+ `)}function we(e,t){let n=e.candidates.map(e=>e.description?`${e.value}\t${e.description}`:e.value);return $(n,e),n.join(`
6
+ `)}function Te(e,t,n){return a({name:`__complete`,args:l,async run(t){let r=W(t.args,e,n),i=r.completionType===`option-value`&&r.targetOption?J(r.currentWord):void 0,a=i?r.currentWord.slice(i.length):r.currentWord,o=Q(await Y(r,{shell:t.shell}),{shell:t.shell,currentWord:a,inlinePrefix:i});console.log(o)}})}function Ee(e){return!!e.subCommands?.__complete}export{S as _,Y as a,m as c,E as d,C as f,T as g,w as h,q as i,b as l,f as m,Ee as n,W as o,d as p,Q as r,D as s,Te as t,x as u,h as v,g as y};
@@ -0,0 +1 @@
1
+ let e;function t(t){e=t}function n(){if(!e)throw Error('No validator adapter registered. Import politty through an adapter package (e.g. `import { defineCommand } from "@politty/zod"` or `from "politty"`) so the schema library integration is set up.');return e}const r=/* @__PURE__ */ new Set([`help`,`help-all`,`help-json`,`version`]);function i(e){return e.replace(/([a-z])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}function a(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function o(e){return!e.alias&&!e.hiddenAlias?[]:[...e.alias??[],...e.hiddenAlias??[]]}function s(e,t){let n=t.argMeta,a=n?.description??t.description,o=i(e),s=/^[A-Za-z0-9][A-Za-z0-9-]*$/,c=(t,n)=>{if(t==null)return;let r=(Array.isArray(t)?t:[t]).map(t=>{if(typeof t!=`string`)throw Error(`Invalid ${n} for field "${e}": expected string or string[], received ${typeof t}.`);let r=t.trim().replace(/^-+/,``);if(r.length===0||!s.test(r))throw Error(`Invalid ${n} "${t}" for field "${e}": aliases must match ${s}.`);return r}),i=Array.from(new Set(r));return i.length>0?i:void 0},l=c(n?.alias,`alias`),u=new Set(l??[]),d=c(n?.hiddenAlias,`hiddenAlias`)?.filter(e=>!u.has(e)),f=d&&d.length>0?d:void 0,p=t.type,m=n?.negation,h;if(m!=null){if(typeof m==`boolean`){if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=m}else{if(typeof m!=`string`)throw Error(`Invalid negation for field "${e}": expected string or boolean, received ${typeof m}.`);let t=m.trim().replace(/^-+/,``);if(t.length===0||!s.test(t))throw Error(`Invalid negation "${m}" for field "${e}": negation names must match ${s}.`);if(r.has(t))throw Error(`Invalid negation "${m}" for field "${e}": negation cannot use reserved built-in flag names (${[...r].map(e=>`--${e}`).join(`, `)}).`);if(p!==`boolean`)throw Error(`Invalid negation for field "${e}": negation can only be used on boolean fields.`);h=t}}let g=n?.negationDescription,_;if(g!=null){if(typeof g!=`string`)throw Error(`Invalid negationDescription for field "${e}": expected string, received ${typeof g}.`);if(h===!1)throw Error(`Invalid negationDescription for field "${e}": negationDescription cannot be used when negation is false.`);if(h===void 0)throw Error(`Invalid negationDescription for field "${e}": negationDescription requires \`negation\` to be set (string or true).`);let t=g.trim();if(t.length===0)throw Error(`Invalid negationDescription for field "${e}": negationDescription must be a non-empty string.`);_=t}let v=typeof h==`string`?h:h===!0?`no-${o}`:void 0,y=n?.positional,b={name:e,cliName:o,alias:l,hiddenAlias:f,description:a,positional:y!==void 0&&y!==!1,named:typeof y==`object`?y.named===!0:y!==!0,placeholder:n?.placeholder,env:n?.env,required:t.required,defaultValue:t.defaultValue,type:p,schema:t.schema,enumValues:t.enumValues,completion:n?.completion,prompt:n?.prompt,negation:h,negationDisplay:v,negationDescription:_,effect:n?.effect};return n&&`overrideBuiltinAlias`in n&&n.overrideBuiltinAlias===!0&&(b.overrideBuiltinAlias=!0),b}export{i as a,a as i,o as n,n as o,s as r,t as s,r as t};
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { $ as toCamelCase, A as LogEntry, B as RunResultFailure, C as Command, D as GlobalCleanupContext, E as GlobalArgs, F as NonRunnableCommand, G as SubCommandsRecord, H as RunnableCommand, I as PromptResolver, J as isLazyCommand, K as UnknownSubcommandHandler, L as RunCommandOptions, M as LogStream, N as Logger, O as GlobalSetupContext, P as MainOptions, Q as UnknownKeysMode, R as RunInvocation, S as CollectedLogs, T as Example, U as SetupContext, V as RunResultSuccess, W as SubCommandValue, X as ExtractedFields, Y as lazy, Z as ResolvedFieldMeta, _ as DynamicCompletionResult, a as CustomCompletion, b as ArgsSchema$1, c as PromptType, d as ExpandCompletion, et as toKebabCase, f as ResolvedExpandCandidate, g as DynamicCompletionResolver, h as DynamicCompletionContext, i as CompletionType, j as LogLevel, k as IsEmpty, l as ValidateArgMeta, m as DynamicCompletionCandidate, n as ArgMeta, nt as SchemaLike, o as EffectContext, p as CompletionDirectiveMask, q as LazyCommand, r as CompletionMeta, s as PromptMeta, t as ArgFn, tt as InferSchemaOutput, u as ExpandCandidate, v as AnyCommand, w as CommandBase, x as CleanupContext, y as ArgSource, z as RunResult } from "./arg-registry-Dvi0co21.js";
2
- 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-BKHwbzEc.js";
1
+ import { r as KnownAgentId, t as AgentInfo } from "./detect-agent-EHaSY1KW.js";
2
+ import { $ as ResolvedFieldMeta, A as GlobalSetupContext, B as RunInvocation, C as CleanupContext, D as Example, E as CommandBase, F as Logger, G as SetupContext, H as RunResultFailure, I as MainOptions, J as UnknownSubcommandHandler, K as SubCommandValue, L as NonRunnableCommand, M as LogEntry, N as LogLevel, O as GlobalArgs, P as LogStream, Q as ExtractedFields, R as PromptResolver, S as ArgsSchema$1, T as Command, U as RunResultSuccess, V as RunResult, W as RunnableCommand, X as isLazyCommand, Y as LazyCommand, Z as lazy, _ as DynamicCompletionResult, a as CustomCompletion, b as AnyCommand, c as PromptType, d as ExpandCompletion, et as UnknownKeysMode, f as ResolvedExpandCandidate, g as DynamicCompletionResolver, h as DynamicCompletionContext, i as CompletionType, it as SchemaLike, j as IsEmpty, k as GlobalCleanupContext, l as ValidateArgMeta, m as DynamicCompletionCandidate, n as ArgMeta, nt as toKebabCase, o as EffectContext, p as CompletionDirectiveMask, q as SubCommandsRecord, r as CompletionMeta, rt as InferSchemaOutput, s as PromptMeta, t as ArgFn, tt as toCamelCase, u as ExpandCandidate, v as AgentHelp, w as CollectedLogs, x as ArgSource, y as AgentHelpContext, z as RunCommandOptions } from "./arg-registry-vcm6uTB1.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-DR98pkpR.js";
3
4
  import { z } from "zod";
4
5
  //#region ../core/src/core/schema-extractor.d.ts
5
6
  /**
@@ -243,7 +244,7 @@ type InferArgs<TArgsSchema> = TArgsSchema extends InternalArgsSchema<infer TInte
243
244
  */
244
245
  type MergedArgs<TLocalArgs, TGlobalArgs> = IsEmpty<TGlobalArgs> extends true ? TLocalArgs : TLocalArgs & WithCaseVariants<TGlobalArgs>;
245
246
  /**
246
- * Add the `$source` and `$invocation` run-time metadata helpers.
247
+ * Add the `$source`, `$invocation` and `$agent` run-time metadata helpers.
247
248
  *
248
249
  * `$source` reports whether a given field's final value came from an
249
250
  * explicit CLI token, a `field.env` fallback, or neither (schema default /
@@ -257,10 +258,14 @@ type MergedArgs<TLocalArgs, TGlobalArgs> = IsEmpty<TGlobalArgs> extends true ? T
257
258
  *
258
259
  * `$invocation` reports the CLI name (canonical or alias) this command was
259
260
  * invoked with.
261
+ *
262
+ * `$agent` reports the AI coding agent running the CLI (see `detectAgent`),
263
+ * or `undefined` when none is detected.
260
264
  */
261
265
  type WithRunMeta<T> = T & {
262
266
  $source?: (name: string) => ArgSource;
263
267
  $invocation?: RunInvocation;
268
+ $agent?: AgentInfo | undefined;
264
269
  };
265
270
  /**
266
271
  * Resolve merged args from schema and global args type
@@ -446,6 +451,8 @@ interface HelpOptions {
446
451
  descriptions?: BuiltinOptionDescriptions | undefined;
447
452
  /** Command hierarchy context */
448
453
  context?: CommandContext | undefined;
454
+ /** Agent-only guidance (Markdown) shown above everything else */
455
+ agentHelp?: string | undefined;
449
456
  }
450
457
  /**
451
458
  * Serializable representation of a single argument (positional or option),
@@ -608,6 +615,8 @@ interface HelpData {
608
615
  examples?: Example[] | undefined;
609
616
  /** Additional notes (raw Markdown, unrendered) */
610
617
  notes?: string | undefined;
618
+ /** Agent-only guidance (raw Markdown), set only when an AI coding agent is detected */
619
+ agentHelp?: string | undefined;
611
620
  }
612
621
  /**
613
622
  * Generate help text for a command
@@ -625,6 +634,8 @@ interface HelpDataOptions {
625
634
  descriptions?: BuiltinOptionDescriptions | undefined;
626
635
  /** Command hierarchy context */
627
636
  context?: CommandContext | undefined;
637
+ /** Agent-only guidance (raw Markdown) to include as {@link HelpData.agentHelp} */
638
+ agentHelp?: string | undefined;
628
639
  }
629
640
  /**
630
641
  * Generate a structured, JSON-serializable representation of a command's help.
@@ -1074,4 +1085,4 @@ export declare const defineCommand: DefineCommandFn<ArgsSchema>;
1074
1085
  export declare const createDefineCommand: CreateDefineCommandFn<ArgsSchema>;
1075
1086
  export declare const arg: ArgFn<z.ZodType>;
1076
1087
  //#endregion
1077
- export { type AnyCommand, type ArgFn, type ArgMeta, type ArgSource, type BoundDefineCommandFn, type BuiltinOptionDescriptions, type CamelCase, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CreateDefineCommandFn, type CustomCompletion, type DefineCommandFn, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GenerateCompileCacheShimOptions, type GenerateCompileCacheShimResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpData, type HelpDataOptions, type HelpFieldData, type HelpOptions, type HelpSubcommandData, type HelpUsageData, type HelpVariantData, type InferSchemaOutput, type KebabCase, type LazyCommand, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type ParsedArgv, type ParserOptions, type PromptMeta, type PromptResolver, type PromptType, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunInvocation, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SchemaLike, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidateArgMeta, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, isLazyCommand, lazy, toCamelCase, toKebabCase, withCompletionCommand };
1088
+ export { type AgentHelp, type AgentHelpContext, type AgentInfo, type AnyCommand, type ArgFn, type ArgMeta, type ArgSource, type BoundDefineCommandFn, type BuiltinOptionDescriptions, type CamelCase, type CleanupContext, type CollectedLogs, type Command, type CommandBase, type CommandContext, type CommandValidationError, type CommandValidationResult, type CompletionDirectiveMask, type CompletionMeta, type CompletionOptions, type CompletionResult, type CompletionType, type CreateDefineCommandFn, type CustomCompletion, type DefineCommandFn, type DynamicCompletionCandidate, type DynamicCompletionContext, type DynamicCompletionResolver, type DynamicCompletionResult, type EffectContext, type Example, type ExpandCandidate, type ExpandCompletion, type ExtractedFields, type GenerateBundledCompletionWorkerOptions, type GenerateBundledCompletionWorkerResult, type GenerateCompileCacheShimOptions, type GenerateCompileCacheShimResult, type GlobalArgs, type GlobalCleanupContext, type GlobalSetupContext, type HelpData, type HelpDataOptions, type HelpFieldData, type HelpOptions, type HelpSubcommandData, type HelpUsageData, type HelpVariantData, type InferSchemaOutput, type KebabCase, type KnownAgentId, type LazyCommand, type LogEntry, type LogLevel, type LogStream, type Logger, type MainOptions, type MergedArgs, type NonRunnableCommand, type ParsedArgv, type ParserOptions, type PromptMeta, type PromptResolver, type PromptType, type ResolvedExpandCandidate, type ResolvedFieldMeta, type RunCommandOptions, type RunInvocation, type RunResult, type RunResultFailure, type RunResultSuccess, type RunnableCommand, type SchemaLike, type SetupContext, type SubCommandValue, type SubCommandsRecord, type UnknownKeysMode, type UnknownSubcommandHandler, type ValidateArgMeta, type ValidationError, type ValidationResult, type WithCaseVariants, type WithCompletionOptions, isLazyCommand, lazy, toCamelCase, toKebabCase, withCompletionCommand };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,i as t}from"./field-meta-_l-FHbh7.js";import{t as n}from"./register-BXOytPt7.js";import{i as r,n as i}from"./schema-extractor-Du9ipDD4.js";import{n as a,t as o}from"./cli-main-uRzr666k.js";import{n as s,t as c}from"./command-tLHaJHe6.js";import{C as l,D as u,E as d,O as f,S as p,T as m,_ as h,a as g,b as _,c as v,d as y,f as b,g as x,h as S,i as C,l as w,m as T,n as E,o as D,p as O,r as k,s as A,t as j,u as M,v as N,w as P,x as F,y as I}from"./runner-BTD1-gUd.js";import{o as L,s as R}from"./subcommand-router-D8GTMXYL.js";import{a as z,i as B,n as V,r as H,t as U}from"./logger-CoeDrmRr.js";import{r as W}from"./argv-parser-DZQ0qnXG.js";import{t as G}from"./with-completion-command-CQcqFHq8.js";const K=a(`@politty/zod`),q=s,J=c,Y=n;export{x as CaseVariantCollisionError,h as DefaultSubCommandError,N as DuplicateAliasError,I as DuplicateFieldError,_ as DuplicateNegationError,F as FieldTypeConflictError,p as PositionalConfigError,l as ReservedAliasError,P as ReservedFieldNameError,Y as arg,a as createCompileCacheShimGenerator,J as createDefineCommand,k as createDualCaseProxy,q as defineCommand,i as extractFields,g as formatCommandValidationErrors,C as formatValidationErrors,K as generateCompileCacheShim,m as generateHelp,d as generateHelpData,r as getUnknownKeysMode,U as isColorEnabled,L as isLazyCommand,R as lazy,V as logger,W as parseArgv,u as renderInline,f as renderMarkdown,j as runCommand,E as runMain,o as runPolittyCli,H as setColorEnabled,B as styles,z as symbols,t as toCamelCase,e as toKebabCase,D as validateCaseVariantCollisions,A as validateCommand,v as validateCrossSchemaCollisions,w as validateDefaultSubCommand,M as validateDuplicateAliases,y as validateDuplicateFields,b as validateDuplicateNegations,O as validatePositionalConfig,T as validateReservedAliases,S as validateReservedFieldNames,G as withCompletionCommand};
1
+ import{a as e,i as t}from"./field-meta-D9ySul7J.js";import{t as n}from"./register-TbOCQNeI.js";import{i as r,n as i}from"./schema-extractor-fZZ2_WAZ.js";import{n as a,t as o}from"./cli-main-DcB9Slb7.js";import{n as s,t as c}from"./command-tLHaJHe6.js";import{C as l,D as u,E as d,O as f,S as p,T as m,_ as h,a as g,b as _,c as v,d as y,f as b,g as x,h as S,i as C,l as w,m as T,n as E,o as D,p as O,r as k,s as A,t as j,u as M,v as N,w as P,x as F,y as I}from"./runner-CqslNxyn.js";import{o as L,s as R}from"./subcommand-router-DR2KBQAt.js";import{a as z,i as B,n as V,r as H,t as U}from"./logger-CoeDrmRr.js";import{r as W}from"./argv-parser-CawJSYjw.js";import{t as G}from"./with-completion-command-DG-C9_0Z.js";const K=a(`@politty/zod`),q=s,J=c,Y=n;export{x as CaseVariantCollisionError,h as DefaultSubCommandError,N as DuplicateAliasError,I as DuplicateFieldError,_ as DuplicateNegationError,F as FieldTypeConflictError,p as PositionalConfigError,l as ReservedAliasError,P as ReservedFieldNameError,Y as arg,a as createCompileCacheShimGenerator,J as createDefineCommand,k as createDualCaseProxy,q as defineCommand,i as extractFields,g as formatCommandValidationErrors,C as formatValidationErrors,K as generateCompileCacheShim,m as generateHelp,d as generateHelpData,r as getUnknownKeysMode,U as isColorEnabled,L as isLazyCommand,R as lazy,V as logger,W as parseArgv,u as renderInline,f as renderMarkdown,j as runCommand,E as runMain,o as runPolittyCli,H as setColorEnabled,B as styles,z as symbols,t as toCamelCase,e as toKebabCase,D as validateCaseVariantCollisions,A as validateCommand,v as validateCrossSchemaCollisions,w as validateDefaultSubCommand,M as validateDuplicateAliases,y as validateDuplicateFields,b as validateDuplicateNegations,O as validatePositionalConfig,T as validateReservedAliases,S as validateReservedFieldNames,G as withCompletionCommand};
@@ -0,0 +1 @@
1
+ import{StringDecoder as e}from"node:string_decoder";const t={log:`stdout`,info:`stdout`,debug:`stdout`,warn:`stderr`,error:`stderr`},n=[`log`,`info`,`debug`,`warn`,`error`];function r(e){return e.map(e=>{if(e instanceof Error)return e.message;if(typeof e==`object`&&e)try{return JSON.stringify(e)}catch{return String(e)}return String(e)}).join(` `)}function i(e){return e.replace(/\r?\n$/,``)}function a(a={}){let o=[],s=a.levels??n,c=a.passthrough??!0,l=null,u=null,d=null,f=!1,p=(e,t,n)=>{o.push({message:n,timestamp:/* @__PURE__ */ new Date,level:e,stream:t})},m=(e,n)=>(...i)=>{p(e,t[e],r(i)),f=!0;try{c&&n.apply(console,i)}finally{f=!1}},h=(t,n,r)=>{let a=new e(`utf8`);return((e,o,s)=>{if(!f){let r=typeof e==`string`?typeof o==`string`&&o!==`utf8`&&o!==`utf-8`?Buffer.from(e,o).toString(`utf8`):e:a.write(e);r!==``&&p(t,n,i(r))}if(c)return r.call(process[n],e,o,s);let l=typeof o==`function`?o:s;return typeof l==`function`&&l(),!0})};return{getLogs(){return{entries:[...o]}},start(){if(l===null){l={log:console.log,info:console.info,debug:console.debug,warn:console.warn,error:console.error};for(let e of s)console[e]=m(e,l[e]);s.includes(`log`)&&(u=process.stdout.write,process.stdout.write=h(`log`,`stdout`,u)),s.includes(`error`)&&(d=process.stderr.write,process.stderr.write=h(`error`,`stderr`,d))}},stop(){if(l!==null){for(let e of s)console[e]=l[e];l=null,u!==null&&(process.stdout.write=u,u=null),d!==null&&(process.stderr.write=d,d=null)}}}}function o(...e){return{entries:e.flatMap(e=>e.entries).sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime())}}function s(){return{entries:[]}}export{s as n,o as r,a as t};
@@ -1,4 +1,4 @@
1
- import { I as PromptResolver } from "./arg-registry-Dvi0co21.js";
1
+ import { R as PromptResolver } from "./arg-registry-vcm6uTB1.js";
2
2
  //#region ../core/src/prompt/clack/index.d.ts
3
3
  /**
4
4
  * Prompt resolver backed by @clack/prompts.
@@ -1 +1 @@
1
- import"./register-BXOytPt7.js";import{t as e}from"./prompt-CqmGq1_N.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};
1
+ import"./register-TbOCQNeI.js";import{t as e}from"./prompt-CqmGq1_N.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};
@@ -1,4 +1,4 @@
1
- import { I as PromptResolver } from "./arg-registry-Dvi0co21.js";
1
+ import { R as PromptResolver } from "./arg-registry-vcm6uTB1.js";
2
2
  //#region ../core/src/prompt/inquirer/index.d.ts
3
3
  /**
4
4
  * Prompt resolver backed by @inquirer/prompts.
@@ -1 +1 @@
1
- import"./register-BXOytPt7.js";import{t as e}from"./prompt-CqmGq1_N.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,...e.placeholder!==void 0&&{default:e.placeholder}})),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};
1
+ import"./register-TbOCQNeI.js";import{t as e}from"./prompt-CqmGq1_N.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,...e.placeholder!==void 0&&{default:e.placeholder}})),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 { X as ExtractedFields, Z as ResolvedFieldMeta } from "./arg-registry-Dvi0co21.js";
1
+ import { $ as ResolvedFieldMeta, Q as ExtractedFields } from "./arg-registry-vcm6uTB1.js";
2
2
  //#region ../core/src/prompt/types.d.ts
3
3
  /**
4
4
  * Resolved prompt configuration for a single field
package/dist/prompt.js CHANGED
@@ -1 +1 @@
1
- import"./register-BXOytPt7.js";import{i as e,n as t,r as n,t as r}from"./prompt-CqmGq1_N.js";export{n as getFieldsToPrompt,t as isInteractive,r as promptMissingArgs,e as resolvePromptConfig};
1
+ import"./register-TbOCQNeI.js";import{i as e,n as t,r as n,t as r}from"./prompt-CqmGq1_N.js";export{n as getFieldsToPrompt,t as isInteractive,r as promptMissingArgs,e as resolvePromptConfig};
@@ -0,0 +1 @@
1
+ import{r as e,s as t}from"./field-meta-D9ySul7J.js";const n=/* @__PURE__ */ new WeakMap;function r(e,t){return t&&n.set(e,t),e}function i(e){return n.get(e)}function a(e,t=/* @__PURE__ */ new Set){if(t.has(e))return;t.add(e);let n=i(e);if(n)return n;if(typeof e.meta==`function`){let t=e.meta();if(t&&typeof t==`object`)return t}let r=e,s=r.def??r._def;if(s?.argMeta)return s.argMeta;if(s?.meta)return s.meta;let c=o(e);if(c===`optional`||c===`nullable`||c==="default"){let e=s?.innerType;if(e)return a(e,t)}if(c===`pipe`){let e=s?.in??s?.schema;if(e)return a(e,t)}}function o(e){let t=e;return t.def?.type??t._def?.type??t.type}function s(e){let t=c(e),n=(t.def??t._def)?.catchall;if(!n)return`strip`;let r=o(n);return r===`never`?`strict`:r===`unknown`||r===`any`?`passthrough`:`strip`}function c(e){let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return c(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return c(e)}return e}function l(e){switch(o(c(e))){case`string`:case`enum`:return`string`;case`number`:case`int`:return`number`;case`boolean`:return`boolean`;case`array`:return`array`;default:return`unknown`}}function u(e){let t=c(e),n=o(t),r=t,i=r.def??r._def;if(n===`enum`){let e=i?.entries;if(e&&typeof e==`object`)return Object.values(e);let t=i?.values;if(Array.isArray(t))return t;let n=r.options;if(Array.isArray(n))return n}if(n===`array`){let e=i?.element;if(e)return u(e)}if(n===`union`){let e=i?.options;if(Array.isArray(e)){let t=[];for(let n of e)if(o(n)===`literal`){let e=n.def??n._def,r=e?.value,i=e?.values,a=r??i?.[0];typeof a==`string`&&t.push(a)}if(t.length===e.length&&t.length>0)return t}}}function d(e){return!e.isOptional()}function f(e){let t=o(e),n=e,r=n.def??n._def;if(t==="default"){let e=r?.defaultValue;return typeof e==`function`?e():e}if(t===`optional`||t===`nullable`){let e=r?.innerType;if(e)return f(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return f(e)}}function p(e){if(e.description)return e.description;let t=o(e),n=e,r=n.def??n._def;if(t===`optional`||t===`nullable`||t==="default"){let e=r?.innerType;if(e)return p(e)}if(t===`pipe`){let e=r?.in??r?.schema;if(e)return p(e)}}function m(t,n){let r=a(n);return e(t,{argMeta:r,description:p(n),required:d(n),defaultValue:f(n),type:l(n),enumValues:u(n),schema:n})}function h(e){let t=e;return(t.def??t._def)?.shape??t.shape??{}}function g(e){let t=h(e);return Object.entries(t).map(([e,t])=>m(e,t))}function _(e){let t=e,n=t.def??t._def,r=n?.discriminator??``,i=n?.options??[],a=/* @__PURE__ */ new Map,c=[];for(let e of i){let t=h(e),n=[],i=``,s=t[r];if(s){let e=o(s);if(e===`literal`){let e=s.def??s._def,t=e?.value,n=e?.values;i=String(t??n?.[0]??``)}else if(e===`enum`){let e=u(s);e&&e.length===1&&(i=e[0])}}for(let[e,r]of Object.entries(t)){let t=m(e,r);n.push(t),a.has(e)||a.set(e,t)}let l=p(e);c.push({discriminatorValue:i,fields:n,...l?{description:l}:{}})}let l=p(e);return{fields:Array.from(a.values()),schema:e,schemaType:`discriminatedUnion`,unknownKeysMode:s(e),discriminator:r,variants:c,...l?{description:l}:{}}}function v(e,t){let n=e,r=(n.def??n._def)?.options??[],i=/* @__PURE__ */ new Map,a=[];for(let e of r){let t=x(e);a.push(t);for(let e of t.fields)i.has(e.name)||i.set(e.name,e)}let o=p(e);return{fields:Array.from(i.values()),schema:e,schemaType:t,unknownKeysMode:s(e),unionOptions:a,...o?{description:o}:{}}}function y(e){let t=e,n=t.def??t._def,r=n?.left,i=n?.right,a=/* @__PURE__ */ new Map,o=e=>{if(!e)return;let t=x(e);for(let e of t.fields)a.has(e.name)||a.set(e.name,e)};o(r),o(i);let c=p(e);return{fields:Array.from(a.values()),schema:e,schemaType:`intersection`,unknownKeysMode:s(e),...c?{description:c}:{}}}const b=/* @__PURE__ */ new WeakMap;function x(e){let t=b.get(e);if(t)return t;let n=e,r,i=o(n),a=n,c=a.def??a._def;switch(i){case`object`:{let t=p(n);r={fields:g(n),schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}case`union`:r=c?.discriminator?_(n):v(n,`union`);break;case`xor`:r=v(n,`xor`);break;case`intersection`:r=y(n);break;case`optional`:case`nullable`:case`default`:case`pipe`:{let t=c?.innerType??c?.in??c?.schema;if(t){let i=x(t),a=p(n);r={...i,schema:e,...a?{description:a}:{}};break}let i=p(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...i?{description:i}:{}};break}default:{let t=p(n);r={fields:[],schema:e,schemaType:`object`,unknownKeysMode:s(n),...t?{description:t}:{}};break}}return b.set(e,r),r}function S(e){return e.issues.map(e=>({path:e.path.map(String),message:e.message,code:e.code,received:`received`in e?e.received:void 0,expected:`expected`in e?String(e.expected):void 0}))}function C(e,t){let n=t.safeParse(e);return n.success?{success:!0,data:n.data}:{success:!1,errors:S(n.error)}}t({vendor:`zod`,extractFields:x,resolveFieldMeta:(e,t)=>m(e,t),getUnknownKeysMode:e=>s(e),validate:C});export{r as t};
@@ -0,0 +1,30 @@
1
+ import{a as e,i as t,n,o as r,t as i}from"./field-meta-D9ySul7J.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-fZZ2_WAZ.js";import{t as h}from"./detect-agent-D7KSeWMh.js";import{n as g}from"./compile-cache-6u9hgeWu.js";import{n as _,r as v,t as y}from"./log-collector-uhRWYT-z.js";import{a as ee,c as b,n as te,o as x,r as S,t as C}from"./subcommand-router-DR2KBQAt.js";import{a as w,i as T}from"./logger-CoeDrmRr.js";import{a as E,i as D,n as O,o as k,r as A,s as j,t as M}from"./argv-parser-CawJSYjw.js";import{stripVTControlCharacters as N}from"node:util";async function ne(e,t,n={}){let r,i,a=n.captureLogs??!1?y():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.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??_(),u=a?.getLogs()??_(),d=v(l,u);return r?{success:!1,error:r,exitCode:1,logs:d}:{success:!0,result:i,exitCode:0,logs:d}}function re(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 ie(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 ae(e){let t=!1,n=!1,r=!1;for(let i of e){let e=i.codePointAt(0);if(e===65039){r=!0;continue}re(e)||(t=!0,ie(e)&&(n=!0))}return t?n||r?2:1:0}const oe=(()=>{try{return new Intl.Segmenter(`en`,{granularity:`grapheme`})}catch{return}})();function se(e){if(e.length===0)return 0;let t=e.includes(`\x1B`)||e.includes(`›`)?N(e):e,n=0;if(oe)for(let{segment:e}of oe.segment(t))n+=ae(e);else for(let e of t)n+=ae(e);return n}function P(e){let t=[],n=e.replace(/`([^`]+)`/g,(e,n)=>{let r=t.length;return t.push(T.cyan(n)),`\x00CODE${r}\x00`});return n=n.replace(/\*\*(.+?)\*\*/g,(e,t)=>T.bold(t)),n=n.replace(/__(.+?)__/g,(e,t)=>T.bold(t)),n=n.replace(/\*(.+?)\*/g,(e,t)=>T.italic(t)),n=n.replace(/(?<!\w)_(.+?)_(?!\w)/g,(e,t)=>T.italic(t)),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(e,t,n)=>`${T.underline(t)} ${T.dim(`(${n})`)}`),n=n.replace(/\x00CODE(\d+)\x00/g,(e,n)=>t[Number(n)]),n}function F(e){return he(e.split(`
2
+ `)).map(be).join(`
3
+
4
+ `)}const ce=/^(#{1,6})\s+(.+)$/,le=/^(?:---+|\*\*\*+|___+)\s*$/,I=/^>\s?(.*)$/,L=/^-\s+(.+)$/,ue=/^(\d+)[.)]\s+(.+)$/,de=/^(`{3,}|~{3,})(\S*)\s*$/,fe=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/,pe=/^\|(.+)\|$/,me=/^\|(\s*:?-+:?\s*\|)+$/;function he(e){let t=[],n=0;for(;n<e.length;){let r=e[n];if(r.trim()===``){n++;continue}let i=r.match(de);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(ce);if(a){t.push({type:`heading`,level:a[1].length,content:a[2]}),n++;continue}if(le.test(r)){t.push({type:`hr`}),n++;continue}if(I.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(I);if(t)r.push(t[1]),n++;else break}if(r.length>0){let e=r[0].match(fe);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(L.test(r)){let r=[];for(;n<e.length;){let t=e[n].match(L);if(t)r.push(t[1]),n++;else break}t.push({type:`ul`,items:r});continue}let o=r.match(ue);if(o){let r=Number(o[1]),i=[];for(;n<e.length;){let t=e[n].match(ue);if(t)i.push(t[2]),n++;else break}t.push({type:`ol`,items:i,start:r});continue}if(pe.test(r)&&n+1<e.length&&me.test(e[n+1])){let i=ge(r),a=_e(e[n+1]);n+=2;let o=[];for(;n<e.length&&pe.test(e[n]);)o.push(ge(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()===``||ce.test(t)||le.test(t)||I.test(t)||L.test(t)||ue.test(t)||de.test(t)||pe.test(t)&&n+1<e.length&&me.test(e[n+1]))break;s.push(t),n++}s.length>0&&t.push({type:`paragraph`,lines:s})}return t}function ge(e){return e.slice(1,-1).split(`|`).map(e=>e.trim())}function _e(e){return e.slice(1,-1).split(`|`).map(e=>{let t=e.trim();return t.startsWith(`:`)&&t.endsWith(`:`)?`center`:t.endsWith(`:`)?`right`:`left`})}function ve(e,t,n){let r=se(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 ye={NOTE:{icon:`ℹ`,label:`Note`,styleFn:T.cyan},TIP:{icon:`💡`,label:`Tip`,styleFn:T.green},IMPORTANT:{icon:`❗`,label:`Important`,styleFn:T.magenta},WARNING:{icon:`⚠`,label:`Warning`,styleFn:T.yellow},CAUTION:{icon:`🔴`,label:`Caution`,styleFn:T.red}};function be(e){switch(e.type){case`heading`:return T.green(T.bold(P(e.content)));case`hr`:return T.dim(`─`.repeat(40));case`blockquote`:{let t=T.dim(`│ `);return e.lines.map(e=>`${t}${P(e)}`).join(`
5
+ `)}case`alert`:{let{icon:t,label:n,styleFn:r}=ye[e.alertType],i=r(T.bold(`│`))+` `,a=`${i}${r(t)} ${r(n)}`;return e.lines.length===0?a:`${a}\n${e.lines.map(e=>`${i}${P(e)}`).join(`
6
+ `)}`}case`ul`:return e.items.map(e=>`${T.dim(`•`)} ${P(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`${T.dim(`${i}.`)} ${P(t)}`}).join(`
8
+ `)}case`table`:{let t=e.headers.length,n=e.headers.map(e=>P(e)),r=e.rows.map(e=>Array.from({length:t},(t,n)=>P(e[n]??``))),i=n.map((e,t)=>{let n=se(e),i=r.map(e=>se(e[t]));return Math.max(n,...i)}),a=T.dim(`│`),o=T.dim(`┌─${i.map(e=>`─`.repeat(e)).join(`─┬─`)}─┐`),s=T.dim(`├─${i.map(e=>`─`.repeat(e)).join(`─┼─`)}─┤`),c=T.dim(`└─${i.map(e=>`─`.repeat(e)).join(`─┴─`)}─┘`);return[o,`${a} ${n.map((t,n)=>T.bold(ve(t,i[n],e.alignments[n]??`left`))).join(` ${a} `)} ${a}`,s,...r.map(t=>{let n=t.map((t,n)=>ve(t,i[n],e.alignments[n]??`left`));return`${a} ${n.join(` ${a} `)} ${a}`}),c].join(`
9
+ `)}case`code`:return e.lines.map(e=>` ${T.yellow(e)}`).join(`
10
+ `);case`paragraph`:return P(e.lines.join(` `))}}const R={help:`Show help`,helpAll:`Show help with all subcommand options`,helpJson:`Show help as JSON`,version:`Show version`};function xe(e){return!e.startsWith(`__`)}function z(e){return Object.entries(e).filter(([e])=>xe(e))}function Se(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?t.commandPath.join(` `):e.name??`command`}function Ce(e,t){return t?.rootName&&t.commandPath&&t.commandPath.length>0?`${t.rootName} ${t.commandPath.join(` `)}`:e.name??`command`}function we(e,t){let n=[],r=Ce(e,t);n.push(T.commandName(r)),t?.globalExtracted?.fields.length&&n.push(T.placeholder(`[global options]`));let i=f(e);if(i){let t=o(i);p(i).length>0&&n.push(T.placeholder(`[options]`)),e.subCommands&&z(e.subCommands).length>0&&(e.run||e.defaultSubCommand?n.push(T.placeholder(`[command]`)):n.push(T.option(`<command>`)));for(let e of t)e.required?n.push(T.option(`<${e.name}>`)):n.push(T.placeholder(`[${e.name}]`))}else e.subCommands&&z(e.subCommands).length>0&&(e.run||e.defaultSubCommand?n.push(T.placeholder(`[command]`)):n.push(T.option(`<command>`)));return n.join(` `)}function Te(e,t){let n=`${T.dim(`When`)} ${T.option(e)}=${T.bold(t.discriminatorValue)}:`;return t.description?`${n} ${t.description}`:n}function Ee(e,t){return` ${T.bold(`${e.description??`Variant ${t+1}`}:`)}`}function De(e,t=0){let n=e.required?T.option(`<${e.name}>`):T.placeholder(`[${e.name}]`),r=e.named?`${n}, ${V(e)}`:n,i=[e.description,e.defaultValue===void 0?void 0:T.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)].filter(Boolean).join(` `);return i?U(r,i,t):`${` `.repeat(t)} ${r}`}function Oe(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:Te(e,t),fields:t.fields}))}else(t.schemaType===`union`||t.schemaType===`xor`)&&t.unionOptions&&(n=t.unionOptions.map((e,t)=>({label:Ee(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=>De(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=>De(e,1)))}return i.join(`
11
+ `)}function ke(e,t={},r){let i=[],a={help:t.help??R.help,helpAll:t.helpAll??R.helpAll,helpJson:t.helpJson??R.helpJson,version:t.version??R.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(U(T.option(`--help`),a.help)):i.push(U(`${T.option(`-h`)}, ${T.option(`--help`)}`,a.help)),c?i.push(U(T.option(`--help-all`),a.helpAll)):i.push(U(`${T.option(`-H`)}, ${T.option(`--help-all`)}`,a.helpAll)),i.push(U(T.option(`--help-json`),a.helpJson)),r?.rootVersion&&i.push(U(T.option(`--version`),a.version)),!o)return i.join(`
12
+ `);if(o.schemaType===`discriminatedUnion`&&o.discriminator)return Ae(o,e,i);if(o.schemaType===`union`&&o.unionOptions||o.schemaType===`xor`&&o.unionOptions)return je(o,e,i);let l=[],u=o.fields.filter(e=>!e.positional);for(let e of u){let t=V(e),n=e.description??``;e.defaultValue!==void 0&&(n+=` ${T.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${T.required(`(required)`)}`);let r=H(e.env);r&&(n+=` ${r}`),l.push(U(t,n));let i=B(e);i&&l.push(i)}return l.push(...i),l.join(`
13
+ `)}function B(e,t=0,n=0){return!e.negationDisplay||!e.negationDescription?null:U(T.option(`--${e.negationDisplay}`),`${e.negationDescription} ${T.dim(`(↔ --${e.cliName})`)}`,t,n)}function Ae(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=`${T.option(`--${i}`)} ${T.placeholder(`<${t}>`)}`,s=e.description??o.description??`Action to perform`;r.push(U(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=V(n),t=n.description??``;n.defaultValue!==void 0&&(t+=` ${T.defaultValue(`(default: ${JSON.stringify(n.defaultValue)})`)}`);let i=H(n.env);i&&(t+=` ${i}`),r.push(U(e,t));let a=B(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);if(t.length>0){r.push(``),r.push(Te(i,e));for(let e of t){let t=V(e),n=e.description??``;e.defaultValue!==void 0&&(n+=` ${T.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${T.required(`(required)`)}`);let i=H(e.env);i&&(n+=` ${i}`),r.push(U(t,n,1));let a=B(e,1);a&&r.push(a)}}}return r.join(`
14
+ `)}function je(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=V(n),t=n.description??``;n.defaultValue!==void 0&&(t+=` ${T.defaultValue(`(default: ${JSON.stringify(n.defaultValue)})`)}`);let i=H(n.env);i&&(t+=` ${i}`),r.push(U(e,t));let a=B(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=Ee(t,e);if(n.length>0){r.push(``),r.push(o);for(let e of n){let t=V(e),n=e.description??``;e.defaultValue!==void 0&&(n+=` ${T.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(n+=` ${T.required(`(required)`)}`);let i=H(e.env);i&&(n+=` ${i}`),r.push(U(t,n,1));let a=B(e,1);a&&r.push(a)}}else r.push(``),r.push(o),r.push(` ${T.dim(T.italic(`no options`))}`)}return r.join(`
15
+ `)}function V(e){let t=[];if(e.alias)for(let n of e.alias)n.length===1&&t.push(T.option(`-${n}`));let n=T.option(`--${e.cliName}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();n+=` ${T.placeholder(`<${t}>`)}`}if(t.push(n),e.alias){for(let n of e.alias)if(n.length>1){let r=T.option(`--${n}`);if(e.type!==`boolean`){let t=e.placeholder??e.cliName.toUpperCase();r+=` ${T.placeholder(`<${t}>`)}`}t.push(r)}}let r=t.join(`, `);return e.type===`boolean`&&e.negationDisplay&&!e.negationDescription?`${r} / ${T.option(`--${e.negationDisplay}`)}`:r}function H(e){if(!e)return``;let t=Array.isArray(e)?e:[e];return T.dim(`[env: ${t.join(`, `)}]`)}function Me(e){return e.replace(/\x1B\[[0-9;]*m/g,``)}function Ne(e,t){let n=Me(e).length,r=Math.max(0,t-n);return e+` `.repeat(r)}function Pe(e,t){if(!e.includes(`
16
+ `))return e;let n=` `.repeat(t);return e.split(`
17
+ `).join(`\n${n}`)}function U(e,t,n=0,r=0){let i=` `.repeat(n),a=Me(e).length,o=32-n*2+r,s=o+2+n*2,c=Pe(t,s);return a>=o?`${i} ${e}\n${` `.repeat(s)}${c}`:`${i} ${Ne(e,o)}${c}`}function Fe(e,t=0,n=0){let r=V(e),i=e.description??``;e.defaultValue!==void 0&&(i+=` ${T.defaultValue(`(default: ${JSON.stringify(e.defaultValue)})`)}`),e.required&&(i+=` ${T.required(`(required)`)}`);let a=H(e.env);return a&&(i+=` ${a}`),U(r,i,t,n)}function Ie(e){let t=[];for(let n of e.fields){if(n.positional)continue;t.push(Fe(n));let e=B(n);e&&t.push(e)}return t.join(`
18
+ `)}function Le(e,t){let n=[],r=f(e);if(r){let e=r.fields.filter(e=>!e.positional);for(let r of e){let e=V(r),i=r.description??``;r.defaultValue!==void 0&&(i+=` ${T.defaultValue(`(default: ${JSON.stringify(r.defaultValue)})`)}`);let a=H(r.env);a&&(i+=` ${a}`),n.push(U(e,i,t,2));let o=B(r,t,2);o&&n.push(o)}}return n}function Re(e,t,n){let r=[];for(let[i,a]of z(e)){let e=b(a),o=t?`${t} ${i}`:i,s=e?.description??``,c=e?.aliases,l=c&&c.length>0?`${o}, ${c.join(`, `)}`:o;if(r.push(U(T.command(l),s,n)),e){let t=Le(e,n+1);r.push(...t);let i=e.subCommands?Object.fromEntries(z(e.subCommands)):void 0;if(i&&Object.keys(i).length>0){let e=Re(i,o,n);r.push(...e)}}}return r}function W(e,t){let n=[],r=t.context;t.agentHelp&&n.push(F(t.agentHelp));let i=Se(e,r);if(i){let e=T.commandName(i);r?.rootName&&r.commandPath&&r.commandPath.length>0?r.rootVersion?e+=` ${T.version(`(${r.rootName} v${r.rootVersion})`)}`:e+=` ${T.version(`(${r.rootName})`)}`:r?.rootVersion&&(e+=` ${T.version(`v${r.rootVersion}`)}`),n.push(e)}r?.aliasFor&&n.push(T.dim(`Alias for ${T.commandName(r.aliasFor)}`)),e.description&&n.push(e.description),!r?.aliasFor&&e.aliases&&e.aliases.length>0&&n.push(`${T.sectionHeader(`Aliases:`)} ${e.aliases.map(e=>T.command(e)).join(`, `)}`),n.push(`${T.sectionHeader(`Usage:`)} ${we(e,r)}`);let a=Oe(e);a&&n.push(`${T.sectionHeader(`Arguments:`)}\n${a}`);let o=ke(e,t.descriptions,r);if(o&&n.push(`${T.sectionHeader(`Options:`)}\n${o}`),r?.globalExtracted?.fields.length&&n.push(`${T.sectionHeader(`Global Options:`)}\n${Ie(r.globalExtracted)}`),t.showSubcommands!==!1&&e.subCommands&&z(e.subCommands).length>0){let i=r?.commandPath?.join(` `)??``,a=Object.fromEntries(z(e.subCommands));if(t.showSubcommandOptions){let e=Re(a,i,0);n.push(`${T.sectionHeader(`Commands:`)}\n${e.join(`
19
+ `)}`)}else{let e=[];for(let[t,n]of Object.entries(a)){let r=b(n),a=r?.description??``,o=i?`${i} ${t}`:t,s=r?.aliases,c=s&&s.length>0?`${o}, ${s.join(`, `)}`:o;e.push(U(T.command(c),a))}n.push(`${T.sectionHeader(`Commands:`)}\n${e.join(`
20
+ `)}`)}}if(e.examples&&e.examples.length>0){let t=Be(e.examples,r);n.push(`${T.sectionHeader(`Examples:`)}\n${t}`)}if(e.notes){let t=F(e.notes).split(`
21
+ `).map(e=>e===``?``:` ${e}`).join(`
22
+ `);n.push(`${T.sectionHeader(`Notes:`)}\n${t}`)}return`\n${n.join(`
23
+
24
+ `)}\n`}function G(e){let t={name:e.name,cliName:e.cliName,positional:e.positional,named:e.named,required:e.required,type:e.type};return 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 ze(e,t){let n=Ce(e,t),r=!!t?.globalExtracted?.fields.length,i=e.subCommands&&z(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 K(e,t={}){let n=t.context,r=n?.commandPath??[],i={help:t.descriptions?.help??R.help,helpAll:t.descriptions?.helpAll??R.helpAll,helpJson:t.descriptions?.helpJson??R.helpJson,...n?.rootVersion?{version:t.descriptions?.version??R.version}:{}},a=f(e),s,c=[],l=[],d,p,h;if(a){if(s=a.schemaType,c=o(a).map(G),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?[{...G(r),description:a.description??r.description??`Action to perform`}]:[],...i.map(G)],p=t.map(t=>({discriminatorValue:t.discriminatorValue,description:t.description,fields:t.fields.filter(t=>t.name!==e&&!n.has(t.name)).map(G)}))}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(G),h=e.map(e=>({description:e.description,fields:e.fields.filter(e=>!t.has(e.name)).map(G)}))}else l=a.fields.filter(e=>!e.positional).map(G)}let g=n?.globalExtracted?.fields.length?n.globalExtracted.fields.filter(e=>!e.positional).map(G):void 0,_;if(e.subCommands){let i=z(e.subCommands);i.length>0&&(_=i.map(([i,a])=>{let o=b(a);if(!o)return{name:i,unresolved:!0};let s={commandPath:[...r,i],rootName:n?.rootName??e.name,rootVersion:n?.rootVersion,globalExtracted:n?.globalExtracted};return{name:i,aliases:o.aliases,data:K(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:ze(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,agentHelp:t.agentHelp}}function Be(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(` ${T.dim(t.desc).split(`
25
+ `).join(`
26
+ `)}`),n.push(` ${T.dim(`$`)} ${a}${t.cmd}`),t.output)for(let e of t.output.split(`
27
+ `))n.push(` ${e}`);n.push(``)}return n.length>0&&n[n.length-1]===``&&n.pop(),n.join(`
28
+ `)}var Ve=class extends Error{constructor(e){super(e),this.name=`PositionalConfigError`}},He=class extends Error{constructor(e){super(e),this.name=`ReservedAliasError`}},Ue=class extends Error{constructor(e){super(e),this.name=`DuplicateFieldError`}},We=class extends Error{constructor(e){super(e),this.name=`DuplicateAliasError`}},q=class extends Error{constructor(e){super(e),this.name=`CaseVariantCollisionError`}},Ge=class extends Error{constructor(e){super(e),this.name=`DuplicateNegationError`}},Ke=class extends Error{constructor(e){super(e),this.name=`ReservedFieldNameError`}},qe=class extends Error{constructor(e){super(e),this.name=`DefaultSubCommandError`}},Je=class extends Error{constructor(e){super(e),this.name=`FieldTypeConflictError`}};function Ye(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 Xe(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 Ze(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 Qe(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 $e(e,t){let n=[e,...e.variants??[],...e.unionOptions??[]],r=/* @__PURE__ */ new Set;return n.flatMap(e=>et(e.fields,t)).filter(e=>!r.has(e.message)&&r.add(e.message))}function et(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 tt(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 nt(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 J(e){let t=Ye(e,[]);if(t.length>0)throw new Ue(`Duplicate field name "${t[0]?.field??`unknown`}" detected. Each field must have a unique name.`)}function Y(e){let t=Ze(e,[]);if(t.length>0){let e=t[0];throw new We(e.message)}}function rt(e){let t=$e(e,[]);if(t.length>0){let e=t[0];throw new Ve(e.message)}}function it(e,t){let n=tt(e,[]);if(n.length>0)throw new He(n[0].message)}function at(e){let t=nt(e,[]);if(t.length>0){let e=t[0];throw new Ke(e.message)}}function ot(e){let t=Qe(e,[]);if(t.length>0){let e=t[0];throw new Ge(e.message)}}function X(e){let t=Xe(e,[]);if(t.length>0){let e=t[0];throw new q(e.message)}}function st(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 ct(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);if(o){if(o.name!==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});continue}st(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})}}return i}function lt(e,t){let n=ct(e,t,[])[0];if(n)throw n.type===`case_variant_collision`?new q(n.message):new Je(n.message)}function ut(e,t,n){return[...Ye(e,n),...Xe(e,n),...Ze(e,n),...Qe(e,n),...$e(e,n),...tt(e,n),...nt(e,n)]}function dt(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 ft(e){let t=dt(e,[]);if(t.length>0)throw new qe(t[0].message)}function pt(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=x(a)?a.meta:typeof a==`function`?null:a;if(!e?.aliases)continue;let o=[...t,i];for(let t of e.aliases){if(!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(t)){n.push({commandPath:o,type:`invalid_alias`,message:`Alias "${t}" is invalid. Aliases must start with an alphanumeric character and contain only alphanumeric characters, hyphens, or underscores.`,field:i});continue}if(t===i){n.push({commandPath:o,type:`duplicate_alias`,message:`Alias "${t}" conflicts with its own name.`,field:i});continue}let e=r.get(t);e?e===i?n.push({commandPath:o,type:`duplicate_alias`,message:`Alias "${t}" is duplicated within the alias list.`,field:i}):n.push({commandPath:o,type:`duplicate_alias`,message:`Alias "${t}" conflicts with existing subcommand or alias "${e}".`,field:i}):r.set(t,i)}}return n}function mt(e,t,n){return e===t?[]:[{commandPath:[...n,e],type:`subcommand_key_name_mismatch`,message:`Subcommand registered as "${e}" but its own name is "${t}".`,field:e}]}async function ht(e,t={}){let n=t.commandPath??[e.name],r=[],i=e.subCommands?Object.keys(e.subCommands).length>0:!1,a=t.globalArgs?l(t.globalArgs):void 0;if(e.args){let t=l(e.args);r.push(...ut(t,i,n)),a&&r.push(...ct(a,t,n))}if(r.push(...pt(e,n)),r.push(...dt(e,n)),e.subCommands)for(let[i,a]of Object.entries(e.subCommands)){let e=await S(a);r.push(...mt(i,e.name,n));let o=await ht(e,{commandPath:[...n,i],...t.globalArgs?{globalArgs:t.globalArgs}:{}});o.valid||r.push(...o.errors)}return r.length===0?{valid:!0}:{valid:!1,errors:r}}function gt(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(`
29
+ `)}function _t(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}=M(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 vt(e,t){let{resolvedName:n,withoutDashes:r,isNegated:i,isCustomNegation:a,isSuppressedNegation:o}=k(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 yt(e,t,n,r,i){return!e.includes(`=`)&&!i.has(t)&&!n&&r!==void 0&&!r.startsWith(`-`)}function Z(e,t,n,r,i,a){let o=e[t];return a.push(o),yt(o,n,r,e[t+1],i)?(a.push(e[t+1]),2):1}function bt(e,t,n){let r=_t(n),i=new Set(t),a=[],o=[],s=0;for(;s<e.length;){let t=e[s];if(t===`--`||xt.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}=vt(t,r);if(l){s+=Z(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+=Z(e,s,t,!1,r.booleanFlags,a);continue}}break}break}return{subCommandIndex:-1,globalTokensBefore:a,tokensAfterSubcommand:[],suppressedTokens:o}}const xt=/* @__PURE__ */ new Set([`--help`,`-h`,`--help-all`,`-H`,`--help-json`,`--version`]);function St(e,t,n={}){let r=n.stopOnSuppressedNegation===!0||t?.unknownKeysMode===`strict`,i=t?_t(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===`--`||xt.has(n))return-1;if(n.startsWith(`--`)){let{resolvedName:a,isNegated:o,isGlobal:s,isSuppressedNegation:c}=vt(n,i);if(s){yt(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)){yt(n,r,!1,e[t+1],i.booleanFlags)&&t++;continue}}return-1}return-1}function Ct(e,t){let n=St(e,t);return n>=0?e[n]:void 0}function wt(e,t,r={}){let i=C(t),o=[...i],s=o.length>0;if(s&&e.length>0){if(r.globalExtracted){let t=bt(e,o,r.globalExtracted);if(t.subCommandIndex>=0){let n=Ot(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 c;t.args&&(c=l(t.args),r.skipValidation||(J(c),X(c),Y(c),ot(c),rt(c),it(c,s),at(c),r.globalExtracted&&lt(r.globalExtracted,c)));let u=e,d,f=[];if(r.globalExtracted){let t=c?a(c):[],n=new Set(t.map(e=>e.name)),{separated:i,globalParsed:o,suppressedTokens:s}=kt(e,r.globalExtracted,c&&{...c,fields:[...t,...c.fields.filter(e=>!n.has(e.name))]});u=i,d=o,f=s}let p=e.indexOf(`--`),m=p>=0?e.slice(0,p):e,h=c?.fields.some(e=>e.overrideBuiltinAlias===!0&&n(e).includes(`H`))??!1,g=c?.fields.some(e=>e.overrideBuiltinAlias===!0&&n(e).includes(`h`))??!1,_=m.includes(`--help-all`)||!h&&m.includes(`-H`),v=m.includes(`--help-json`),y=!_&&!v&&(m.includes(`--help`)||!g&&m.includes(`-h`)),ee=m.includes(`--version`);if(y||_||v||ee)return{helpRequested:y,helpAllRequested:_,helpJsonRequested:v,versionRequested:ee,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:[],rest:[],unknownFlags:[],unknownGlobalFlags:f,rawGlobalArgs:d};if(!c){let e=u.indexOf(`--`);return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:e>=0?u.slice(0,e):u,rest:e>=0?u.slice(e+1):[],unknownFlags:[],unknownGlobalFlags:f,rawGlobalArgs:d}}let b=Tt(c,u,{promptAvailable:r.promptAvailable===!0,inheritedNames:r.inheritedNames??/* @__PURE__ */ new Set});if(!b)return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:{},positionals:[],rest:[],unknownFlags:[],unknownGlobalFlags:f,extractedFields:c,matchesNoUnionOption:!0,rawGlobalArgs:d};let te=M(b),x=A(u,te),S=O(x,b),w=Et(S,b),T=b.fields.filter(e=>e.named),E=new Set(T.map(e=>e.name)),k=new Set(T.map(e=>e.cliName)),j=/* @__PURE__ */ new Set;for(let e of T)for(let t of n(e))j.add(t);if(r.globalExtracted)for(let e of r.globalExtracted.fields){E.add(e.name),k.add(e.cliName);for(let t of n(e))j.add(t)}let N=[];for(let e of Object.keys(x.options))!E.has(e)&&!k.has(e)&&!j.has(e)&&N.push(e);return{helpRequested:!1,helpAllRequested:!1,helpJsonRequested:!1,versionRequested:!1,subCommand:void 0,remainingArgs:[],rawArgs:S,positionals:x.positionals,rest:x.rest,unknownFlags:N,unknownGlobalFlags:f,extractedFields:c,optionFields:T,positionalSlotFields:D(b,x.options),rawGlobalArgs:d,envFallbackFields:w}}function Tt(e,t,n){let{discriminator:r,variants:i,unionOptions:a}=e;if(r&&i){let n=e=>{let n=O(A(t,M(e)),e);return Et(n,e),n},a=c(e,n);if(a!==e)return a;let o=new Set(i.map(e=>e.discriminatorValue));return i.some(t=>o.has(n({...e,fields:t.fields})[r]))?void 0:e}if(a){let r=n.promptAvailable?a.filter(e=>Dt(e,t,void 0)):[],i=a.find(e=>Dt(e,t,n.inheritedNames))??(r.length===1?r[0]:void 0);return i&&{...e,fields:i.fields}}return e}function Et(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]=j(i,r.type),n.add(r.name);break}}return n}function Dt(e,t,r){let i=A(t,M(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=D(e,i.options),c=i.positionals.length+i.rest.length;if(!s.some(e=>e.type===`array`)&&c>s.length)return!1;let l=O(i,e);return e.fields.some(e=>e.type!==`boolean`&&[l[e.name]].flat().includes(!0))?!1:r===void 0||(Et(l,e),e.fields.every(e=>!e.required||l[e.name]!==void 0||r.has(e.name)))}function Ot(e,t){if(e.length===0)return{};let n=M(t),r=A(e,n);return O(r,t)}function kt(e,r,i){let a=_t(r),o=new Set(i?.fields.map(e=>e.name)??[]),s=new Set(i?.fields.map(e=>e.cliName)??[]),c=i?M(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}=vt(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+=Z(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+=Z(e,t,n,!1,a.booleanFlags,f)-1;continue}}}p.push(n)}return{separated:p,globalParsed:Ot(f,r),suppressedTokens:m}}function At(e,t){return s(t)?d(e,t):r().validate(e,t)}function jt(e){return e.map(e=>`${e.path.length>0?`${e.path.join(`.`)}: `:``}${e.message}`).join(`
30
+ `)}function Mt(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 Nt(e,t){let n=Math.max(2,Math.floor(e.length/2));return t.map(t=>({candidate:t,distance:Mt(e.toLowerCase(),t.toLowerCase())})).filter(({distance:e})=>e<=n).sort((e,t)=>e.distance-t.distance).map(({candidate:e})=>e).slice(0,3)}function Pt(e,t){let n=Nt(e.replace(/^-{1,2}/,``),t),r=`${T.warning(`Warning: Unknown option:`)} ${T.bold(e)}`;if(n.length>0){r+=`\n\n${T.info(`Did you mean?`)}`;for(let e of n)r+=`\n ${w.arrow} ${T.option(`--${e}`)}`}return r}function Ft(e,t){return t&&e.stack?`${T.error(`Error:`)} ${e.message}\n\n${T.dim(e.stack)}`:`${T.error(`Error:`)} ${e.message}`}function Q(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 It(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 Lt={log:e=>console.log(e),error:e=>console.error(e),warn:e=>console.warn(e)};function Rt(n,r){Object.defineProperty(n,"$source",{value:n=>r.get(n)??r.get(t(n))??r.get(e(n))??`default`,enumerable:!1})}function zt(e,t){Object.defineProperty(e,"$invocation",{value:t,enumerable:!1})}function Bt(e,t){Object.defineProperty(e,"$agent",{value:t,enumerable:!1})}function Vt(e,t){return e&&(n=>e({...n,agent:t}))}function Ht(e,t){let{agentHelp:n,_agent:r}=e;if(n&&r)return typeof n==`string`?n:n({agent:r,commandPath:t.commandPath??[]})}function Ut(e,t){let n=t.commandPath?.at(-1)??e.name;return t.aliasFor?{name:n,aliasFor:t.aliasFor}:{name:n}}async function Wt(e,t,n={}){let r=Jt(n),i=h(),a=Vt(n.cleanup,i),o=n.captureLogs??!1,s=o?y():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()??_()}}s?.stop()}let c=await $(e,t,{...n,handleSignals:!1,_globalExtracted:r,_globalCleanup:a,_existingLogs:s?.getLogs(),_agent:i});if(a){let e=o?y():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:v(c.logs,e?.getLogs()??_())}}}e?.stop();let n=e?.getLogs()??_();if(n.entries.length>0)return{...c,logs:v(c.logs,n)}}return c}function Gt(e,t,n){let r=Ct(t,n);return!r||!r.startsWith(`__`)?!1:Object.hasOwn(e.subCommands??{},r)}async function Kt(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(Gt(e,n,r)){let{setup:e,cleanup:n,prompt:r,globalArgs:a,...o}=t;i=o}let a=Jt(i),o=h(),s=Vt(i.cleanup,o);if(i.skipValidation||ft(e),i.onUnknownSubcommand&&!e.run&&!Gt(e,n,r)){let t=C(e);if(t.size>0){let e=St(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 qt(),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??Lt).error(Ft(c.error,i.debug??!1)),s){let e={error:c.success?void 0:c.error};try{await s(e)}catch{}}await qt(),process.exit(c.exitCode)}async function qt(){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??Lt,i=n._context??{commandPath:[],rootName:e.name,globalExtracted:n._globalExtracted},a=n.captureLogs??!1?y():null;a?.start();let o=()=>{let e=n._existingLogs??_(),t=a?.getLogs()??_();return v(e,t)};try{n.skipValidation||ft(e);let s=wt(t,e,{skipValidation:n.skipValidation,globalExtracted:n._globalExtracted,promptAvailable:n.prompt!==void 0,inheritedNames:new Set(Object.keys(n._parsedGlobalArgs??{}))}),c={...n._parsedGlobalArgs,...s.rawGlobalArgs},l=i.commandPath??[];if(n.onUnknownSubcommand&&!e.run&&l.length>0){let r=C(e);if(r.size>0){let e=St(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:l,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 qt(),process.exit(s)}return s===0?{success:!0,result:void 0,exitCode:0,logs:o()}:{success:!1,error:/* @__PURE__ */ Error(`Plugin "${[...l,i].join(` `)}" exited with code ${s}`),exitCode:s,logs:o()}}}}}if(s.helpRequested||s.helpAllRequested||s.helpJsonRequested){let c=!1,l=te(e),u=C(e);if(l.length>0){let e=Ct(t,i.globalExtracted);e&&!u.has(e)&&(c=!0)}let d=Ht(n,i);if(s.helpJsonRequested){let t=K(e,{context:i,agentHelp:d});r.log(JSON.stringify(t))}else{let t=W(e,{showSubcommands:n.showSubcommands??!0,showSubcommandOptions:s.helpAllRequested||n.showSubcommandOptions,context:i,agentHelp:d});r.log(t)}if(a?.stop(),c){let e=Ct(t,i.globalExtracted)??``,n=Nt(e,[...u]),r=n.length>0?` Did you mean: ${n.join(`, `)}?`:``;return{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${e}${r?`.${r}`:``}`),exitCode:1,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:1,logs:o()};if(e===`strip`){let e=i.globalExtracted?.fields.map(e=>e.name)??[];for(let t of s.unknownGlobalFlags)r.error(Pt(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=await ee(e,s.subCommand);if(r){let e={commandPath:[...i.commandPath??[],s.subCommand],rootName:i.rootName,rootVersion:i.rootVersion,globalExtracted:i.globalExtracted,aliasFor:r.aliasFor};a?.stop();let l=new Set(n._globalExtracted?.unknownKeysMode===`passthrough`?[]:s.unknownGlobalFlags??[]),u=e=>e.startsWith(`--`)&&l.has(E(e)),d=t.slice(0,t.length-s.remainingArgs.length-1).filter(e=>!u(e));return $(r.command,s.remainingArgs,{...n,_context:e,_existingLogs:o(),_parsedGlobalArgs:c,_precedingArgs:[...n._precedingArgs??[],...d]})}}let u=s.positionalSlotFields??[],d=u.some(e=>e.type===`array`),f=[...s.positionals,...s.rest],p=d?[]:f.slice(u.length),m=d?[]:s.positionals.slice(u.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:1,logs:o()};if(te(e).length>0&&!s.subCommand&&!e.run&&p.length===0){if(e.defaultSubCommand&&s.unknownFlags.length===0){let r=e.subCommands?.[e.defaultSubCommand];if(r){let l=await S(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(E(e)),p=t.filter(e=>!f(e));return $(l,[],{...n,_context:u,_existingLogs:o(),_parsedGlobalArgs:c,_precedingArgs:[...n._precedingArgs??[],...p]})}}let l=W(e,{showSubcommands:n.showSubcommands??!0,context:i,agentHelp:Ht(n,i)});return r.log(l),a?.stop(),{success:!0,result:void 0,exitCode:0,logs:o()}}if(s.unknownFlags.length>0){let e=s.extractedFields?.unknownKeysMode??`strip`,t=s.optionFields?.map(e=>e.name)??[];if(e===`strict`)return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown flags: ${s.unknownFlags.join(`, `)}`),exitCode:1,logs:o()};if(e===`strip`)for(let e of s.unknownFlags)r.error(Pt(e,t))}if(p.length>0){let t=C(e);if(t.size>0){let e=m.find(e=>!e.startsWith(`-`)&&!t.has(e));if(e){let n=Nt(e,[...t]),r=n.length>0?` Did you mean: ${n.join(`, `)}?`:``;return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unknown subcommand: ${e}${r?`.${r}`:``}`),exitCode:1,logs:o()}}}let n=s.extractedFields?.unknownKeysMode??`strip`;if(n===`strict`)return a?.stop(),{success:!1,error:/* @__PURE__ */ Error(`Unexpected positional argument${p.length>1?`s`:``}: ${p.join(`, `)}`),exitCode:1,logs:o()};if(n===`strip`)for(let e of p)(r.warn??r.error)(`Warning: Unexpected positional argument: ${e}`)}let h={},g=e.name===`__complete`,_=new Set(Object.keys(c)),v=/* @__PURE__ */ new Set;if(n.globalArgs&&n._globalExtracted&&!g){for(let e of n._globalExtracted.fields)if(e.env&&c[e.name]===void 0){let t=Array.isArray(e.env)?e.env:[e.env];for(let n of t){let t=process.env[n];if(t!==void 0){c[e.name]=j(t,e.type),v.add(e.name);break}}}if(n.prompt){let e=await n.prompt(c,n._globalExtracted);for(let[t,n]of Object.entries(e))n!==void 0&&(c[t]=n)}let e=At(c,n.globalArgs);if(!e.success)return a?.stop(),{success:!1,error:Error(jt(e.errors)),exitCode:1,logs:o()};h=e.data}if(!e.args){let t=/* @__PURE__ */ new Map;for(let e of _)t.set(e,`cli`);for(let e of v)t.set(e,`env`);Rt(h,t),zt(h,Ut(e,i)),Bt(h,n._agent);let r=Q(h);return n._globalExtracted&&!g&&await It(r,n._globalExtracted,r),a?.stop(),await ne(e,r,{handleSignals:n.handleSignals,captureLogs:n.captureLogs,existingLogs:o(),globalCleanup:n._globalCleanup})}let y=s.rawArgs,b=/* @__PURE__ */ new Set;if(n.prompt&&s.extractedFields){let e=await n.prompt(y,s.extractedFields),t={...y};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r,b.add(n));y=t}let x=/* @__PURE__ */ new Set;if(s.extractedFields)for(let e of s.extractedFields.fields)!(Object.hasOwn(s.rawArgs,e.name)||b.has(e.name))&&_.has(e.name)&&Object.hasOwn(h,e.name)&&(y={...y,[e.name]:h[e.name]},x.add(e.name));let w=At(y,e.args);if(!w.success)return a?.stop(),{success:!1,error:Error(jt(w.errors)),exitCode:1,logs:o()};let T=Q(w.data),D=/* @__PURE__ */ new Map;for(let e of _)D.set(e,`cli`);for(let e of v)D.set(e,`env`);Rt(h,D),zt(h,Ut(e,i)),Bt(h,n._agent);let O=Q(h);n._globalExtracted&&!g&&await It(O,n._globalExtracted,O),s.extractedFields&&!g&&await It(T,s.extractedFields,O);let k={...O,...T},A=new Map(D),M=s.envFallbackFields??/* @__PURE__ */ new Set;for(let e of s.extractedFields?.fields??[]){if(x.has(e.name)){A.set(e.name,`cli`);continue}let t=Object.hasOwn(s.rawArgs,e.name)||M.has(e.name);A.set(e.name,t?M.has(e.name)?`env`:`cli`:`default`)}Rt(k,A),zt(k,Ut(e,i)),Bt(k,n._agent);let N=Q(k);return a?.stop(),await ne(e,N,{handleSignals:n.handleSignals,captureLogs:n.captureLogs,existingLogs:o(),globalCleanup:n._globalCleanup})}catch(e){let t=e instanceof Error?e:Error(String(e));return a?.stop(),{success:!1,error:t,exitCode:1,logs:o()}}}function Jt(e){if(!e.globalArgs)return;let t=l(e.globalArgs);if(!e.skipValidation){J(t),X(t),Y(t),ot(t),it(t,!0),at(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{He as C,P as D,K as E,F as O,Ve as S,W as T,qe as _,gt as a,Ge as b,lt as c,J as d,ot as f,q as g,at as h,jt as i,ft as l,it as m,Kt as n,X as o,rt as p,Q as r,ht as s,Wt as t,Y as u,We as v,Ke as w,Je as x,Ue as y};
@@ -0,0 +1 @@
1
+ import{t as e}from"./runner-CqslNxyn.js";export{e as runCommand};
@@ -0,0 +1 @@
1
+ import{o as e,r as t}from"./field-meta-D9ySul7J.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);if(o){n.push(o);continue}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)}function h(t){return a(t)?c(t):e().extractFields(t)}function g(e){return e.args?h(e.args):null}function _(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))&&i.add(e.name);return i}function v(e){let t=x(e).filter(e=>e.named);return S(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 y(e){return S(e,e=>e.positional)}function b(e){return S(e,e=>!e.positional)}function x(e){let t=e.variants??e.unionOptions??[];return[e.fields,...t.map(e=>e.fields)].flat()}function S(e,t){let n=/* @__PURE__ */ new Map;for(let r of x(e))t(r)&&!n.has(r.name)&&n.set(r.name,r);return[...n.values()]}function C(e,t){let{discriminator:n,variants:r}=e;if(!n||!r)return e;for(let i of r){let r={...e,fields:i.fields};if(t(r)[n]===i.discriminatorValue)return r}return e}function w(e,t){return b(e).find(e=>e.name===t)}export{v as a,y as c,r as d,a as f,m as i,C as l,h as n,w as o,p,g as r,b as s,_ as t,i as u};
@@ -1 +1 @@
1
- import{d as e,u as t}from"./schema-extractor-Du9ipDD4.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};
1
+ import{d as e,u as t}from"./schema-extractor-fZZ2_WAZ.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};