@kjanat/dreamcli 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/completion-B4oRc2Ae.mjs +59 -0
  2. package/dist/completion.d.mts +11 -1
  3. package/dist/completion.mjs +1 -1
  4. package/dist/config-DSh3QJpX.mjs +1 -0
  5. package/dist/config.d.mts +11 -1
  6. package/dist/config.mjs +1 -1
  7. package/dist/core-BZx351-p.mjs +21 -0
  8. package/dist/dynamic-BK2lQF2M.mjs +1 -0
  9. package/dist/{index-BidVVmln.d.mts → index-CLtWJqwn.d.mts} +8 -5
  10. package/dist/{index-BIMjOsR6.d.mts → index-CuhI1Ynv.d.mts} +394 -4
  11. package/dist/{index-DpslpOVV.d.mts → index-DDhRLoTu.d.mts} +7 -1
  12. package/dist/{index-jq_FJRKt.d.mts → index-DIWRV_wp.d.mts} +1 -1
  13. package/dist/{index-hzYPRc_O.d.mts → index-Vjl2_m23.d.mts} +5 -5
  14. package/dist/{index-AIC5Gler.d.mts → index-aTmg9yfl.d.mts} +1 -1
  15. package/dist/index.d.mts +30 -7
  16. package/dist/index.mjs +1 -1
  17. package/dist/json-schema-CYgq_hFu.mjs +59 -0
  18. package/dist/json-schema.d.mts +9 -1
  19. package/dist/json-schema.mjs +1 -1
  20. package/dist/{package-json-fYhxDdWD.mjs → package-json-hqUWeazy.mjs} +1 -1
  21. package/dist/prompt.d.mts +12 -1
  22. package/dist/prompt.mjs +1 -1
  23. package/dist/rolldown-runtime-DOYBPklu.mjs +1 -0
  24. package/dist/runtime.d.mts +20 -2
  25. package/dist/runtime.mjs +1 -1
  26. package/dist/session-BEKj0yLA.mjs +1 -0
  27. package/dist/{terminal-DRsRn4sc.mjs → terminal-Dws_b5UK.mjs} +1 -1
  28. package/dist/test-prompter-euLYzWWO.mjs +1 -0
  29. package/dist/testkit.d.mts +17 -4
  30. package/dist/testkit.mjs +1 -1
  31. package/dist/version.mjs +1 -1
  32. package/dreamcli.schema.json +11 -0
  33. package/package.json +7 -7
  34. package/skills/cli-creation/SKILL.md +1 -1
  35. package/dist/adapter-DBeedKmD.d.mts +0 -283
  36. package/dist/completion-Bh-qywmB.mjs +0 -6
  37. package/dist/config-DruA8aFV.mjs +0 -1
  38. package/dist/core-B9YNSJeA.mjs +0 -19
  39. package/dist/json-schema-DF5fXdKQ.mjs +0 -59
  40. package/dist/rolldown-runtime-G4Kt5YOX.mjs +0 -1
  41. package/dist/session-Crtzt7LY.mjs +0 -1
  42. package/dist/test-prompter-BLNGCOA_.mjs +0 -1
@@ -0,0 +1,59 @@
1
+ import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{F as resolvePlainHelpDescription,at as acceptsArgv,ct as flagValueSchema,ft as builtinEnabled,it as getFlagNegatedName,lt as valueEnumValues,p as resolveRootSurface,pt as CLIError,rt as getFlagAliasNames,tt as createFlagSchema,v as collectPropagatedFlags,z as flagExpectsValue}from"./core-BZx351-p.mjs";import{DREAMCLI_REVISION,DREAMCLI_VERSION}from"./version.mjs";function versionTag(){let e=` (${DREAMCLI_REVISION})`;return`@kjanat/dreamcli v${DREAMCLI_VERSION}${e}`}function programTag(e){return e.version===void 0?e.name:`${e.name} v${e.version}`}function resolveRootCompletionSurface(e,t=`subcommands`){let n=resolveRootSurface(e),r=createRootFlags(builtinEnabled(e.builtins,`help`),e.version!==void 0),i=n.visibleDefaultCommand?.flags??{},a=t===`surface`?n.hasVisibleDefault:n.hasVisibleDefault&&!n.hasVisibleSubcommands,o=n.visibleDefaultCommand,s=o!==void 0&&n.visibleCommands.some(e=>e.name===o.name);return{visibleCommands:n.defaultRouted&&o!==void 0&&!s?[o,...n.visibleCommands]:n.defaultRouted?n.visibleCommands:n.visibleSubcommands,visibleDefaultCommand:n.visibleDefaultCommand,rootFlags:r,defaultFlags:i,includeDefaultFlags:a}}function createRootFlags(e,t){return{...e?{help:createSyntheticRootFlag(`Show help text`)}:{},...t?{version:createSyntheticRootFlag(`Show version`)}:{}}}function createSyntheticRootFlag(e){return createFlagSchema(`boolean`,{description:e})}function walkCommandTree(e,t=[]){let n=[];for(let r of e){if(r.hidden)continue;let e=[...t,r],i=collectPropagatedFlags(e),a={...i,...r.flags},o=r.commands.filter(e=>!e.hidden);n.push({path:e.map(e=>e.name),schema:r,propagatedFlags:i,mergedFlags:a,children:o}),o.length>0&&n.push(...walkCommandTree(o,e))}return n}function getVisibleNegatedName(e,t){if(!(t.negation===void 0||t.negation.hidden))return getFlagNegatedName(e,t)}function sanitizeShellIdentifier(e){let t=e.replace(/[^a-zA-Z0-9_]/g,`_`);if(t===e)return t;let n=2166136261;for(let t=0;t<e.length;t+=1)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return`${t}_${(n>>>0).toString(16).padStart(8,`0`)}`}function quoteShellArg(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function hasDynamicCompletion(e){let t=e=>Object.values(e.flags).some(e=>acceptsArgv(e)&&e.completion!==void 0)||e.args.some(e=>acceptsArgv(e.schema)&&e.schema.completion!==void 0)||e.commands.some(t);return e.commands.some(t)||e.defaultCommand!==void 0&&t(e.defaultCommand)}function generateBashCompletion(e,t){let n=`_${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=resolveRootCompletionSurface(e,t?.rootMode),i=r.visibleCommands,a=walkCommandTree(i),o=a.reduce((e,t)=>Math.max(e,t.path.length),0),s=[];if(s.push(`#!/usr/bin/env bash`),s.push(`# Bash completion for ${programTag(e)}`),s.push(`# Generated by ${versionTag()}`),s.push(`#`),s.push(`# Usage: source <(${e.name} completions bash)`),s.push(`#`),s.push(`# Install permanently:`),s.push(`# ${e.name} completions bash > /etc/bash_completion.d/${e.name} # Linux`),s.push(`# ${e.name} completions bash > $(brew --prefix)/etc/bash_completion.d/${e.name} # macOS`),s.push(`#`),s.push(`# Requires: bash-completion (provides _init_completion)`),s.push(``),hasDynamicCompletion(e)&&(s.push(`${n}_unquote() {`),s.push(` local text="$1" char escaped=0 i`),s.push(` unquoted="" quote=""`),s.push(" for ((i = 0; i < ${#text}; i++)); do"),s.push(' char="${text:i:1}"'),s.push(` if ((escaped)); then`),s.push(` [[ "$quote" == '"' && "$char" != [\\\\\\"\\$\\\`] ]] && unquoted+='\\'`),s.push(` unquoted+="$char"; escaped=0`),s.push(` elif [[ "$char" == '\\' && "$quote" != "'" ]]; then`),s.push(` escaped=1`),s.push(` elif [[ -n "$quote" ]]; then`),s.push(` if [[ "$char" == "$quote" ]]; then quote=""; else unquoted+="$char"; fi`),s.push(` elif [[ "$char" == "'" || "$char" == '"' ]]; then`),s.push(` quote="$char"`),s.push(` else`),s.push(` unquoted+="$char"`),s.push(` fi`),s.push(` done`),s.push(` ((escaped)) && unquoted+='\\'`),s.push(` return 0`),s.push(`}`),s.push(``)),s.push(`${n}() {`),s.push(` local cur prev words cword`),s.push(hasDynamicCompletion(e)?` _init_completion -n =: || return`:` _init_completion || return`),s.push(` local readline_prefix=""`),s.push(` if [[ $# -ge 2 && "$cur" == *"$2" ]]; then`),s.push(' readline_prefix="${cur%"$2"}"'),s.push(` fi`),hasDynamicCompletion(e)&&(s.push(` local dynamic candidate unquoted quote readline_quote word char i quoted`),s.push(`\t${n}_unquote "$readline_prefix"`),s.push(` readline_prefix="$unquoted" readline_quote="$quote"`),s.push(` local -a dynamic_words=()`),s.push(' for word in "${words[@]:1:cword-1}" "$cur"; do'),s.push(`\t\t${n}_unquote "$word"`),s.push(` dynamic_words+=("$unquoted")`),s.push(` done`),s.push(`\tif dynamic=$(command ${quoteShellArg(e.name)} __complete -- "\${dynamic_words[@]}" 2>/dev/null); then`),s.push(` compopt -o noquote 2>/dev/null`),s.push(` COMPREPLY=()`),s.push(` while IFS= read -r candidate; do`),s.push(` [[ -n "$candidate" ]] || continue`),s.push(' candidate="${candidate#"$readline_prefix"}"'),s.push(` if [[ -z "$readline_quote" ]]; then`),s.push(` printf -v candidate %q "$candidate"`),s.push(` else`),s.push(` quoted="$readline_quote"`),s.push(" for ((i = 0; i < ${#candidate}; i++)); do"),s.push(' char="${candidate:i:1}"'),s.push(` if [[ "$readline_quote" == '"' && "$char" == [\\\\\\"\\$\\\`] ]]; then quoted+='\\'; fi`),s.push(` if [[ "$readline_quote" == "'" && "$char" == "'" ]]; then quoted+="'\\\\''"; else quoted+="$char"; fi`),s.push(` done`),s.push(` candidate="$quoted"`),s.push(` fi`),s.push(` COMPREPLY+=("$candidate")`),s.push(` done <<< "$dynamic"`),s.push(` return`),s.push(` fi`)),s.push(``),i.length>0){let e=a.filter(e=>e.children.length>0),t=collectValueFlagPattern(a,r);s.push(` # Build subcommand path by scanning COMP_WORDS`),s.push(` local subcmd_path=""`),s.push(` local i`),s.push(` for ((i = 1; i < cword; i++)); do`),s.push(' case "${words[i]}" in'),s.push(` --) break ;;`),t.length>0&&s.push(`\t\t\t${t}) ((i++)); continue ;;`),s.push(` -*) continue ;;`),s.push(` esac`),emitBashPathDetection(s,i,e,o),s.push(` done`),s.push(``),s.push(` # Complete flags and subcommands for the active path`),s.push(` case "$subcmd_path" in`);for(let e of a){let t=e.path.join(` `),n=e.mergedFlags,r=collectEnumCasesFromFlags(n),i=collectFlagWords(n),a=dedupeWords(e.children.flatMap(e=>[e.name,...e.aliases])).map(escapeForSingleQuote).join(` `),o=i.split(` `).filter(Boolean).map(escapeForSingleQuote).join(` `),c=a.length>0?`${a} ${o}`:o;if(s.push(`\t\t${quoteShellCasePattern(t)})`),r.length>0){s.push(` local enum_flag=""`),s.push(` local enum_cur="$cur"`),s.push(` local enum_prefix=""`),s.push(` if [[ "$cur" == --*=* ]]; then`),s.push(' enum_flag="${cur%%=*}"'),s.push(' enum_cur="${cur#*=}"'),s.push(' enum_prefix="${cur%%=*}="'),s.push(` fi`),s.push(' case "${enum_flag:-$prev}" in');for(let e of r)s.push(`\t\t\t\t${e.flags})`),s.push(formatBashEnumCompletion(e.values,` `,`enum_cur`,`enum_prefix`)),s.push(` return`),s.push(` ;;`);s.push(` *)`),s.push(` ;;`),s.push(` esac`)}s.push(`\t\t\tCOMPREPLY=($(compgen -W '${c.trim()}' -- "$cur"))`),s.push(` return`),s.push(` ;;`)}s.push(` *)`),s.push(` ;;`),s.push(` esac`),s.push(``);let n=collectFlagWords(r.rootFlags).split(` `).filter(Boolean),c=r.includeDefaultFlags?collectFlagWords(r.defaultFlags).split(` `).filter(Boolean):[],l=dedupeWords([...i.flatMap(e=>[e.name,...e.aliases]),...n,...c]).map(escapeForSingleQuote).join(` `);s.push(` # Root-level completions: visible root surface`),s.push(`\tCOMPREPLY=($(compgen -W '${l}' -- "$cur"))`)}else{let e=collectFlagWords({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});s.push(`\tCOMPREPLY=($(compgen -W '${e}' -- "$cur"))`)}return s.push(`}`),s.push(``),s.push(`complete -F ${n} ${quoteShellArg(e.name)}`),s.push(``),s.join(`
2
+ `)}function emitBashPathDetection(e,t,n,r){e.push(` case "$subcmd_path" in`),e.push(` '')`),e.push(' case "${words[i]}" in');for(let n of t){let t=[n.name,...n.aliases].map(escapeBashCasePatternValue);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="${escapeBashDoubleQuotedValue(n.name)}"`),e.push(` ;;`)}if(e.push(` esac`),e.push(` ;;`),r>1)for(let t of n){let n=t.path.join(` `);e.push(`\t\t\t${quoteShellCasePattern(n)})`),e.push(' case "${words[i]}" in');for(let n of t.children){let t=[n.name,...n.aliases].map(escapeBashCasePatternValue);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="$subcmd_path ${escapeBashDoubleQuotedValue(n.name)}"`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`)}e.push(` esac`)}function quoteShellCasePattern(e){return e.includes(` `)?`"${escapeBashDoubleQuotedValue(e)}"`:escapeBashCasePatternValue(e)}function escapeBashCasePatternValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/"/g,`\\"`).replace(/\|/g,`\\|`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`).replace(/\{/g,`\\{`).replace(/\}/g,`\\}`).replace(/\+/g,`\\+`).replace(/!/g,`\\!`).replace(/@/g,`\\@`).replace(/#/g,`\\#`).replace(/~/g,`\\~`).replace(/\s/g,e=>e===` `?`\\ `:`\\${e}`)}function escapeBashDoubleQuotedValue(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function escapeForSingleQuote(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/'/g,`'\\''`)}function formatBashEnumCompletion(e,t,n=`cur`,r){let i=[];if(e.some(e=>!/^[a-zA-Z0-9_\-.]+$/.test(e))){let r=e.map(escapeBashDollarQuote).join(`\\n`);i.push(`${t}local IFS=$'\\n'`),i.push(`${t}COMPREPLY=($(compgen -W $'${r}' -- "$${n}"))`)}else i.push(`${t}COMPREPLY=($(compgen -W '${e.join(` `)}' -- "$${n}"))`);return r!==void 0&&(i.push(`${t}if [[ -n "$${r}" && "\${#COMPREPLY[@]}" -gt 0 ]]; then`),i.push(`${t}\tlocal i`),i.push(`${t}\tfor ((i = 0; i < \${#COMPREPLY[@]}; i++)); do`),i.push(`${t}\t\tCOMPREPLY[i]="$${r}\${COMPREPLY[i]}"`),i.push(`${t}\tdone`),i.push(`${t}fi`)),i.push(`${t}local reply`),i.push(`${t}for reply in "\${!COMPREPLY[@]}"; do`),i.push(`${t}\tCOMPREPLY[reply]="\${COMPREPLY[reply]#"$readline_prefix"}"`),i.push(`${t}done`),i.join(`
3
+ `)}function escapeBashDollarQuote(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\n/g,`\\n`)}function collectFlagWords(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;t.push(`--${n}`);for(let e of getFlagAliasNames(r))t.push(e.length===1?`-${e}`:`--${e}`);let e=getVisibleNegatedName(n,r);e!==void 0&&t.push(`--${e}`)}return t.join(` `)}function collectValueFlagPattern(e,t){let n=/* @__PURE__ */ new Set,r=e=>{for(let[t,r]of Object.entries(e))if(acceptsArgv(r)&&flagExpectsValue(r)){n.add(`--${t}`);for(let e of getFlagAliasNames(r,{includeHidden:!0}))n.add(e.length===1?`-${e}`:`--${e}`)}};for(let t of e)r(t.mergedFlags);return r(t.rootFlags),t.includeDefaultFlags&&r(t.defaultFlags),[...n].map(escapeBashCasePatternValue).join(`|`)}function dedupeWords(e){return[...new Set(e)]}function collectEnumCasesFromFlags(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;let e=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r));if(e===void 0)continue;let i=[`--${n}`,...getFlagAliasNames(r,{includeHidden:!0}).map(e=>e.length===1?`-${e}`:`--${e}`)].map(escapeBashCasePatternValue);t.push({flags:i.join(`|`),values:e})}return t}function generateFishCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_path`,i=`${n}_path_is`,a=resolveRootCompletionSurface(e,t?.rootMode),o=a.visibleCommands,s=walkCommandTree(o),c=quoteShellArg(e.name),l=[];l.push(`# Fish completion for ${programTag(e)}`),l.push(`# Generated by ${versionTag()}`),l.push(`#`),l.push(`# Usage: source (${e.name} completions fish | psub)`),l.push(`#`),l.push(`# Install permanently:`),l.push(`# ${e.name} completions fish > ~/.config/fish/completions/${e.name}.fish`),l.push(``),l.push(`complete -c ${c} -f`),l.push(``),hasDynamicCompletion(e)&&(l.push(`function ${n}_dynamic`),l.push(` set -l words (commandline -xpc)`),l.push(` set -l raw (commandline -ct)`),l.push(` set -l prefix (commandline --input "$raw" --tokens-expanded)`),l.push(`\tcommand ${c} __complete --value-only -- $words[2..-1] "$prefix" 2>/dev/null`),l.push(`end`),l.push(`complete -c ${c} -f -a '(${n}_dynamic)'`),l.push(``)),emitFishPathHelpers(l,r,i,o,s,a),appendFishCommandCompletions(l,c,i,``,o),appendFishFlagCompletions(l,c,i,``,a.rootFlags,`${n}_dynamic`),a.includeDefaultFlags&&appendFishFlagCompletions(l,c,i,``,a.defaultFlags,`${n}_dynamic`);for(let e of s){let t=e.path.join(` `);appendFishCommandCompletions(l,c,i,t,e.children),appendFishFlagCompletions(l,c,i,t,e.mergedFlags,`${n}_dynamic`)}return l.join(`
4
+ `)}function emitFishPathHelpers(e,t,n,r,i,a){let o=collectFishValueFlagPatterns(i,a);e.push(`function ${t}`),e.push(` set -l words (commandline -xpc)`),e.push(` if test (count $words) -gt 0`),e.push(` set -e words[1]`),e.push(` end`),e.push(` set -l subcmd_path ''`),e.push(` set -l expect_value 0`),e.push(` for word in $words`),e.push(` if test $expect_value -eq 1`),e.push(` set expect_value 0`),e.push(` continue`),e.push(` end`),e.push(` switch $word`),e.push(` case '--'`),e.push(` break`),o.exact.length>0&&(e.push(`\t\t\tcase ${o.exact.map(quoteShellArg).join(` `)}`),e.push(` set expect_value 1`),e.push(` continue`)),o.prefix.length>0&&(e.push(`\t\t\tcase ${o.prefix.map(quoteShellArg).join(` `)}`),e.push(` continue`)),e.push(` case '-*'`),e.push(` continue`),e.push(` end`),e.push(` switch "$subcmd_path|$word"`);for(let t of r)for(let n of[t.name,...t.aliases])e.push(`\t\t\tcase ${quoteShellArg(`|${n}`)}`),e.push(`\t\t\t\tset subcmd_path ${quoteShellArg(t.name)}`);for(let t of i)for(let n of t.children)for(let r of[n.name,...n.aliases])e.push(`\t\t\tcase ${quoteShellArg(`${t.path.join(` `)}|${r}`)}`),e.push(`\t\t\t\tset subcmd_path ${quoteShellArg(`${t.path.join(` `)} ${n.name}`)}`);e.push(` case '*'`),e.push(` break`),e.push(` end`),e.push(` end`),e.push(` printf '%s\\n' "$subcmd_path"`),e.push(`end`),e.push(``),e.push(`function ${n}`),e.push(` set -l expected "$argv[1]"`),e.push(`\ttest (${t}) = "$expected"`),e.push(`end`),e.push(``)}function appendFishCommandCompletions(e,t,n,r,i){let a=buildFishCondition(n,r);for(let n of i){let r=quoteShellArg(n.description??n.name);for(let i of[n.name,...n.aliases])e.push(`complete -c ${t} -n "${a}" -a ${quoteShellArg(i)} -d ${r}`)}i.length>0&&e.push(``)}function appendFishFlagCompletions(e,t,n,r,i,a){let o=buildFishCondition(n,r);for(let[n,r]of Object.entries(i)){if(!acceptsArgv(r))continue;let i=[`complete -c ${t}`,`-n "${o}"`];for(let e of getFlagAliasNames(r,{kind:`short`}))i.push(`-s ${quoteShellArg(e)}`);i.push(`-l ${quoteShellArg(n)}`);for(let e of getFlagAliasNames(r,{kind:`long`}))i.push(`-l ${quoteShellArg(e)}`);let s=getVisibleNegatedName(n,r);s!==void 0&&i.push(`-l ${quoteShellArg(s)}`),i.push(`-d ${quoteShellArg(r.description===void 0?n:resolvePlainHelpDescription(r.description))}`),flagExpectsValue(r)&&i.push(`-r`,`-f`),r.completion!==void 0&&i.push(`-a '(${a})'`);let c=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r));if(c!==void 0&&r.completion===void 0)for(let t of c)e.push([...i,`-a ${quoteShellArg(t)}`].join(` `));else e.push(i.join(` `))}Object.keys(i).length>0&&e.push(``)}function collectFishValueFlagPatterns(e,t){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=[t.rootFlags,...t.includeDefaultFlags?[t.defaultFlags]:[],...e.map(e=>e.mergedFlags)];for(let e of i)for(let[t,i]of Object.entries(e))if(acceptsArgv(i)&&flagExpectsValue(i)){n.add(`--${t}`),r.add(`--${t}=*`);for(let e of getFlagAliasNames(i,{kind:`short`,includeHidden:!0}))n.add(`-${e}`),r.add(`-${e}*`);for(let e of getFlagAliasNames(i,{kind:`long`,includeHidden:!0}))n.add(`--${e}`),r.add(`--${e}=*`)}return{exact:[...n],prefix:[...r]}}function buildFishCondition(e,t){return`${e} ${quoteShellArg(t)}`}function generatePowerShellCompletion(e,t){let n=`__${sanitizeShellIdentifier(t?.functionPrefix??e.name)}_completions`,r=`${n}_paths`,i=resolveRootCompletionSurface(e,t?.rootMode),a=i.visibleCommands,o=walkCommandTree(a),s=[];return s.push(`# PowerShell completion for ${programTag(e)}`),s.push(`# Generated by ${versionTag()}`),s.push(`#`),s.push(`# Install for the current session:`),s.push(`# ${e.name} completions powershell | Out-String | Invoke-Expression`),s.push(`#`),s.push(`# Install permanently:`),s.push(`# ${e.name} completions powershell > $PROFILE.CurrentUserCurrentHost`),s.push(``),s.push(`using namespace System.Management.Automation`),s.push(`using namespace System.Management.Automation.Language`),s.push(``),emitPowerShellPathTable(s,r,i,o),s.push(``),emitPowerShellHelpers(s,n,r),s.push(``),s.push(`Register-ArgumentCompleter -Native -CommandName ${quotePowerShellString(e.name)} -ScriptBlock {`),s.push(` param($wordToComplete, $commandAst, $cursorPosition)`),hasDynamicCompletion(e)&&(s.push(` $dynamicArgs = [System.Collections.Generic.List[string]]::new()`),s.push(` $dynamicArgs.Add('__complete')`),s.push(` $dynamicArgs.Add('--')`),s.push(` $currentText = $wordToComplete`),s.push(` foreach ($element in $commandAst.CommandElements | Select-Object -Skip 1) {`),s.push(` if ($element.Extent.StartOffset -gt $cursorPosition) { break }`),s.push(` if ($element.Extent.EndOffset -ge $cursorPosition) {`),s.push(` $currentText = $element.Extent.Text.Substring(0, $cursorPosition - $element.Extent.StartOffset)`),s.push(` break`),s.push(` }`),s.push(`\t\t$dynamicArgs.Add((${n}_UnquoteToken $element.Extent.Text))`),s.push(` }`),s.push(`\t$dynamicArgs.Add((${n}_UnquoteToken $currentText))`),s.push(`\t$dynamic = & ${quotePowerShellString(e.name)} @dynamicArgs 2>$null`),s.push(` if ($LASTEXITCODE -eq 0) {`),s.push(` foreach ($candidate in $dynamic) {`),s.push(`\t\t\t$text = ${n}_FormatCompletionValue -Value $candidate`),s.push(` [CompletionResult]::new($text, $candidate, [CompletionResultType]::ParameterValue, $candidate)`),s.push(` }`),s.push(` return`),s.push(` }`)),s.push(`\t$state = ${n}_GetState -CommandAst $commandAst -CursorPosition $cursorPosition`),s.push(` if ($null -eq $state.PathData) {`),s.push(` return`),s.push(` }`),s.push(``),s.push(` $results = [System.Collections.Generic.List[CompletionResult]]::new()`),s.push(` if ($state.AfterSeparator) {`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(` $wordPrefix = if ([string]::IsNullOrEmpty($wordToComplete)) { '' } else { $wordToComplete }`),s.push(``),s.push(` if ($state.ExpectingValue) {`),s.push(`\t\t${n}_AddEnumResults -Results $results -Flag $state.ValueFlag -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(`\t$inlineValue = ${n}_ResolveInlineValueCompletion -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` if ($null -ne $inlineValue) {`),s.push(`\t\t${n}_AddInlineEnumResults -Results $results -InlineValue $inlineValue -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(` if ($wordPrefix.StartsWith('-')) {`),s.push(`\t\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(` }`),s.push(``),s.push(`\t${n}_AddCommandResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(`\t${n}_AddFlagResults -Results $results -PathData $state.PathData -WordToComplete $wordPrefix`),s.push(` return $results`),s.push(`}`),s.join(`
5
+ `)}function emitPowerShellPathTable(e,t,n,r){e.push(`$script:${t} = @{`),appendPowerShellPathEntry(e,``,n.visibleCommands,{...n.rootFlags,...n.includeDefaultFlags?n.defaultFlags:{}});for(let t of r)appendPowerShellPathEntry(e,t.path.join(` `),t.children,t.mergedFlags);e.push(`}`)}function appendPowerShellPathEntry(e,t,n,r){e.push(`\t${quotePowerShellString(t)} = @{`),e.push(` Commands = @(`);for(let t of n)e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t.name)}`),e.push(`\t\t\t\tNames = ${formatPowerShellArray([t.name,...t.aliases])}`),e.push(`\t\t\t\tDescription = ${quotePowerShellString(t.description??t.name)}`),e.push(` }`);e.push(` )`),e.push(` Flags = @(`);for(let[t,n]of Object.entries(r)){if(!acceptsArgv(n))continue;let r=getVisibleNegatedName(t,n),i=getFlagNegatedName(t,n),a=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`}).map(e=>`--${e}`),...r===void 0?[]:[`--${r}`]]),o=dedupeValues([`--${t}`,...getFlagAliasNames(n,{kind:`short`,includeHidden:!0}).map(e=>`-${e}`),...getFlagAliasNames(n,{kind:`long`,includeHidden:!0}).map(e=>`--${e}`),...i===void 0?[]:[`--${i}`]]);e.push(` @{`),e.push(`\t\t\t\tCanonicalName = ${quotePowerShellString(t)}`),e.push(`\t\t\t\tForms = ${formatPowerShellArray(a)}`),e.push(`\t\t\t\tParseForms = ${formatPowerShellArray(o)}`),e.push(`\t\t\t\tRequiresValue = ${flagExpectsValue(n)?`$true`:`$false`}`),e.push(`\t\t\t\tDescription = ${quotePowerShellString(n.description===void 0?t:resolvePlainHelpDescription(n.description))}`),e.push(`\t\t\t\tEnumValues = ${formatPowerShellArray((n.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(n)))??[])}`),e.push(` }`)}e.push(` )`),e.push(` }`)}function emitPowerShellHelpers(e,t,n){e.push(`function ${t}_UnquoteToken {`),e.push(` param([string]$TokenText)`),e.push(...String.raw`
6
+ $result = [System.Text.StringBuilder]::new()
7
+ $quote = [char]0
8
+ for ($i = 0; $i -lt $TokenText.Length; $i++) {
9
+ $char = $TokenText[$i]
10
+ if ($quote -eq "'") {
11
+ if ($char -eq "'") {
12
+ if ($i + 1 -lt $TokenText.Length -and $TokenText[$i + 1] -eq "'") {
13
+ [void]$result.Append("'")
14
+ $i++
15
+ } else { $quote = [char]0 }
16
+ } else { [void]$result.Append($char) }
17
+ } elseif ($char -eq [char]96) {
18
+ if ($i + 1 -lt $TokenText.Length) {
19
+ $i++
20
+ $escaped = $TokenText[$i]
21
+ $decoded = switch -CaseSensitive ($escaped) {
22
+ '0' { [char]0 }
23
+ 'a' { [char]7 }
24
+ 'b' { [char]8 }
25
+ 'e' { [char]27 }
26
+ 'f' { [char]12 }
27
+ 'n' { [char]10 }
28
+ 'r' { [char]13 }
29
+ 't' { [char]9 }
30
+ 'v' { [char]11 }
31
+ 'u' {
32
+ $match = [regex]::Match($TokenText.Substring($i + 1), '^\{([0-9a-fA-F]{1,6})\}')
33
+ if ($match.Success) {
34
+ $codepoint = [Convert]::ToInt32($match.Groups[1].Value, 16)
35
+ if ($codepoint -le 0x10ffff -and ($codepoint -lt 0xd800 -or $codepoint -gt 0xdfff)) {
36
+ $i += $match.Length
37
+ [char]::ConvertFromUtf32($codepoint)
38
+ } else { $escaped }
39
+ } else { $escaped }
40
+ }
41
+ default { $escaped }
42
+ }
43
+ [void]$result.Append($decoded)
44
+ } else { [void]$result.Append($char) }
45
+ } elseif ($quote -eq '"') {
46
+ if ($char -eq '"') {
47
+ if ($i + 1 -lt $TokenText.Length -and $TokenText[$i + 1] -eq '"') {
48
+ [void]$result.Append('"')
49
+ $i++
50
+ } else { $quote = [char]0 }
51
+ } else { [void]$result.Append($char) }
52
+ } elseif ($char -eq "'" -or $char -eq '"') {
53
+ $quote = $char
54
+ } else { [void]$result.Append($char) }
55
+ }
56
+ return $result.ToString()
57
+ `.trimEnd().split(`
58
+ `).slice(1)),e.push(`}`),e.push(``),e.push(`function ${t}_FindCommand {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if ($name -eq $Token) {`),e.push(` return $command`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveFlagToken {`),e.push(` param($PathData, [string]$Token)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.ParseForms) {`),e.push(` if ($Token -eq $form) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $null }`),e.push(` }`),e.push(``),e.push(` if (-not $flag.RequiresValue) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('--') -and $Token.StartsWith("$form=")) {`),e.push(` return @{ Flag = $flag; InlinePrefix = "$form=" }`),e.push(` }`),e.push(``),e.push(` if ($form.StartsWith('-') -and -not $form.StartsWith('--') -and $Token.StartsWith($form) -and $Token.Length -gt $form.Length) {`),e.push(` return @{ Flag = $flag; InlinePrefix = $form }`),e.push(` }`),e.push(` }`),e.push(` }`),e.push(` return $null`),e.push(`}`),e.push(``),e.push(`function ${t}_GetState {`),e.push(` param([CommandAst]$CommandAst, [int]$CursorPosition)`),e.push(`\t$pathData = $script:${n}[${quotePowerShellString(``)}]`),e.push(` $path = ""`),e.push(` $afterSeparator = $false`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` $tokens = [System.Collections.Generic.List[string]]::new()`),e.push(``),e.push(` foreach ($element in $CommandAst.CommandElements | Select-Object -Skip 1) {`),e.push(` if ($element.Extent.EndOffset -ge $CursorPosition) {`),e.push(` break`),e.push(` }`),e.push(`\t\t$tokenText = ${t}_UnquoteToken $element.Extent.Text`),e.push(` [void]$tokens.Add($tokenText)`),e.push(` }`),e.push(``),e.push(` foreach ($token in $tokens) {`),e.push(` if ($expectingValue) {`),e.push(` $expectingValue = $false`),e.push(` $valueFlag = $null`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token -eq '--') {`),e.push(` $afterSeparator = $true`),e.push(` break`),e.push(` }`),e.push(``),e.push(`\t\t$flagMatch = ${t}_ResolveFlagToken -PathData $pathData -Token $token`),e.push(` if ($null -ne $flagMatch) {`),e.push(` if ($flagMatch.InlinePrefix -eq $null -and $flagMatch.Flag.RequiresValue) {`),e.push(` $expectingValue = $true`),e.push(` $valueFlag = $flagMatch.Flag`),e.push(` }`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` if ($token.StartsWith('-')) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(`\t\t$command = ${t}_FindCommand -PathData $pathData -Token $token`),e.push(` if ($null -eq $command) {`),e.push(` break`),e.push(` }`),e.push(``),e.push(` $path = if ([string]::IsNullOrEmpty($path)) {`),e.push(` $command.CanonicalName`),e.push(` } else {`),e.push(` "$path $($command.CanonicalName)"`),e.push(` }`),e.push(`\t\t$nextPathData = $script:${n}[$path]`),e.push(` if ($null -eq $nextPathData) {`),e.push(` break`),e.push(` }`),e.push(` $pathData = $nextPathData`),e.push(` }`),e.push(``),e.push(` return @{`),e.push(` Path = $path`),e.push(` PathData = $pathData`),e.push(` AfterSeparator = $afterSeparator`),e.push(` ExpectingValue = $expectingValue`),e.push(` ValueFlag = $valueFlag`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_ResolveInlineValueCompletion {`),e.push(` param($PathData, [string]$WordToComplete)`),e.push(`\t$flagMatch = ${t}_ResolveFlagToken -PathData $PathData -Token $WordToComplete`),e.push(` if ($null -eq $flagMatch -or $flagMatch.InlinePrefix -eq $null) {`),e.push(` return $null`),e.push(` }`),e.push(` return $flagMatch`),e.push(`}`),e.push(``),e.push(`function ${t}_FormatCompletionValue {`),e.push(` param([string]$Value)`),e.push(` if ($Value.Length -eq 0) {`),e.push(` return "''"`),e.push(` }`),e.push(``),e.push(` if ($Value -match '^[a-zA-Z0-9_./:\\\\-]+$') {`),e.push(` return $Value`),e.push(` }`),e.push(``),e.push(` return "'$([CodeGeneration]::EscapeSingleQuotedStringContent($Value))'"`),e.push(`}`),e.push(``),e.push(`function ${t}_MatchesCompletionPrefix {`),e.push(` param([string]$WordToComplete, [string]$RawText, [string]$CompletionText)`),e.push(` if ([string]::IsNullOrEmpty($WordToComplete)) {`),e.push(` return $true`),e.push(` }`),e.push(``),e.push(` return $RawText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase) -or $CompletionText.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)`),e.push(`}`),e.push(``),e.push(`function ${t}_AddCommandResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($command in $PathData.Commands) {`),e.push(` foreach ($name in $command.Names) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $name.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $name,`),e.push(` $name,`),e.push(` [CompletionResultType]::Command,`),e.push(` $command.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddFlagResults {`),e.push(` param($Results, $PathData, [string]$WordToComplete)`),e.push(` foreach ($flag in $PathData.Flags) {`),e.push(` foreach ($form in $flag.Forms) {`),e.push(` if (-not [string]::IsNullOrEmpty($WordToComplete) -and -not $form.StartsWith($WordToComplete, [System.StringComparison]::OrdinalIgnoreCase)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $form,`),e.push(` $form,`),e.push(` [CompletionResultType]::ParameterName,`),e.push(` $flag.Description`),e.push(` ))`),e.push(` }`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddEnumResults {`),e.push(` param($Results, $Flag, [string]$WordToComplete)`),e.push(` foreach ($value in $Flag.EnumValues) {`),e.push(`\t\t$completionText = ${t}_FormatCompletionValue -Value $value`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $value -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`),e.push(``),e.push(`function ${t}_AddInlineEnumResults {`),e.push(` param($Results, $InlineValue, [string]$WordToComplete)`),e.push(` foreach ($value in $InlineValue.Flag.EnumValues) {`),e.push(` $rawCompletion = "$($InlineValue.InlinePrefix)$value"`),e.push(`\t\t$formattedValue = ${t}_FormatCompletionValue -Value $value`),e.push(` $completionText = "$($InlineValue.InlinePrefix)$formattedValue"`),e.push(`\t\tif (-not (${t}_MatchesCompletionPrefix -WordToComplete $WordToComplete -RawText $rawCompletion -CompletionText $completionText)) {`),e.push(` continue`),e.push(` }`),e.push(``),e.push(` $Results.Add([CompletionResult]::new(`),e.push(` $completionText,`),e.push(` $value,`),e.push(` [CompletionResultType]::ParameterValue,`),e.push(` $InlineValue.Flag.Description`),e.push(` ))`),e.push(` }`),e.push(`}`)}function quotePowerShellString(e){return`'${e.replace(/'/g,`''`)}'`}function formatPowerShellArray(e){return e.length===0?`@()`:`@(${e.map(quotePowerShellString).join(`, `)})`}function dedupeValues(e){return[...new Set(e)]}function generateZshCompletion(e,t){let n=`_${sanitizeShellIdentifier(t?.functionPrefix??e.name)}`,r=resolveRootCompletionSurface(e,t?.rootMode),i=r.visibleCommands,a=walkCommandTree(i),o=[];o.push(`#compdef ${quoteShellArg(e.name)}`),o.push(`# Zsh completion for ${programTag(e)}`),o.push(`# Generated by ${versionTag()}`),o.push(`#`),o.push(`# Usage: source <(${e.name} completions zsh)`),o.push(`#`),o.push(`# Install permanently:`),o.push(`# ${e.name} completions zsh > "\${fpath[1]}/_${e.name}"`),o.push(`# # Then restart your shell`),o.push(``);let s=a.filter(e=>e.children.length>0),c=a.filter(e=>e.children.length===0);for(let e of c)e.path.length<2||emitZshLeafFunction(o,`${n}_${e.path.map(sanitizeShellIdentifier).join(`_`)}`,e);let l=[...s].sort((e,t)=>t.path.length-e.path.length);for(let e of l)emitZshGroupFunction(o,`${n}_${e.path.map(sanitizeShellIdentifier).join(`_`)}`,n,e);if(o.push(`${n}() {`),hasDynamicCompletion(e)&&(o.push(` local dynamic word current_prefix=$PREFIX`),o.push(` local -a dynamic_words=()`),o.push(' for word in "${words[@]:1:$((CURRENT-2))}"; do'),o.push(' dynamic_words+=("${(Q)word}")'),o.push(` done`),o.push(` if [[ $compstate[quoting] = (single|double) ]]; then`),o.push(` current_prefix="$compstate[quote]$PREFIX$compstate[quote]"`),o.push(` fi`),o.push(' dynamic_words+=("${(Q)current_prefix}")'),o.push(`\tif dynamic=$(command ${quoteShellArg(e.name)} __complete -- "\${dynamic_words[@]}" 2>/dev/null); then`),o.push(` local -a candidates`),o.push(` if [[ -n "$dynamic" ]]; then`),o.push(' candidates=("${(@f)dynamic}")'),o.push(` compadd -a candidates`),o.push(` fi`),o.push(` return`),o.push(` fi`)),i.length>0){o.push(` local -a subcmds`),o.push(` local line state`),o.push(``);let e=buildZshFlagSpecsFromFlags({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});o.push(` _arguments -C \\`);for(let t of e)o.push(`\t\t${t} \\`);o.push(` '1: :->subcmd' \\`),o.push(` '*::arg:->args'`),o.push(``),o.push(` case "$state" in`),o.push(` subcmd)`),o.push(` subcmds=(`),appendZshCommandCandidates(o,i,` `),o.push(` )`),o.push(` _describe 'command' subcmds`),o.push(` ;;`),o.push(` args)`),o.push(` case "$line[1]" in`);for(let e of i){let t=[e.name,...e.aliases].map(escapeZshCasePatternValue),r=e.commands.filter(e=>!e.hidden);if(o.push(`\t\t\t\t${t.join(`|`)})`),r.length>0){let t=`${n}_${sanitizeShellIdentifier(e.name)}`;o.push(`\t\t\t\t\t${t}`)}else{let t=a.find(t=>t.path.length===1&&t.schema.name===e.name);if(t===void 0)throw new CLIError(`Missing completion node for command '${e.name}'`,{code:`UNEXPECTED_ERROR`});let n=buildZshFlagSpecsFromFlags(t.mergedFlags);if(n.length>0){o.push(` _arguments \\`);for(let e=0;e<n.length;e++){let t=e<n.length-1?` \\`:``;o.push(`\t\t\t\t\t\t${n[e]}${t}`)}}}o.push(` ;;`)}o.push(` esac`),o.push(` ;;`),o.push(` esac`)}else{let e=buildZshFlagSpecsFromFlags({...r.rootFlags,...r.includeDefaultFlags?r.defaultFlags:{}});o.push(` _arguments \\`);for(let t=0;t<e.length;t++){let n=t<e.length-1?` \\`:``;o.push(`\t\t${e[t]}${n}`)}}return o.push(`}`),o.push(``),o.push(`compdef ${n} ${quoteShellArg(e.name)}`),o.push(``),o.join(`
59
+ `)}function emitZshGroupFunction(e,t,n,r){e.push(`${t}() {`),e.push(` local -a subcmds`),e.push(` local line state`),e.push(``);let i=buildZshFlagSpecsFromFlags(r.mergedFlags);e.push(` _arguments -C \\`);for(let t of i)e.push(`\t\t${t} \\`);e.push(` '1: :->subcmd' \\`),e.push(` '*::arg:->args'`),e.push(``),e.push(` case "$state" in`),e.push(` subcmd)`),e.push(` subcmds=(`),appendZshCommandCandidates(e,r.children,` `),e.push(` )`),e.push(` _describe 'command' subcmds`),e.push(` ;;`),e.push(` args)`),e.push(` case "$line[1]" in`);for(let t of r.children){let i=[t.name,...t.aliases].map(escapeZshCasePatternValue),a=`${n}_${[...r.path,t.name].map(sanitizeShellIdentifier).join(`_`)}`;e.push(`\t\t\t\t${i.join(`|`)})`),e.push(`\t\t\t\t\t${a}`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`),e.push(` esac`),e.push(`}`),e.push(``)}function emitZshLeafFunction(e,t,n){let r=buildZshFlagSpecsFromFlags(n.mergedFlags);if(e.push(`${t}() {`),r.length>0){e.push(` _arguments \\`);for(let t=0;t<r.length;t++){let n=t<r.length-1?` \\`:``;e.push(`\t\t${r[t]}${n}`)}}e.push(`}`),e.push(``)}function appendZshCommandCandidates(e,t,n){for(let r of t){let t=r.description??r.name;for(let i of[r.name,...r.aliases])e.push(`${n}${quoteShellArg(`${i}:${t}`)}`)}}function escapeZshCasePatternValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/"/g,`\\"`).replace(/`/g,"\\`").replace(/\|/g,`\\|`).replace(/\*/g,`\\*`).replace(/\?/g,`\\?`).replace(/\[/g,`\\[`).replace(/\]/g,`\\]`).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`).replace(/\{/g,`\\{`).replace(/\}/g,`\\}`).replace(/\+/g,`\\+`).replace(/!/g,`\\!`).replace(/@/g,`\\@`).replace(/#/g,`\\#`).replace(/~/g,`\\~`).replace(/\s/g,e=>e===` `?`\\ `:`\\${e}`)}function escapeZshDescription(e){return e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`)}function buildZshFlagSpecsFromFlags(e){let t=[];for(let[n,r]of Object.entries(e)){if(!acceptsArgv(r))continue;let e=escapeZshDescription(r.description===void 0?n:resolvePlainHelpDescription(r.description)),i=`--${n}`,a=getFlagAliasNames(r,{kind:`short`}).map(e=>`-${e}`),o=getFlagAliasNames(r,{kind:`long`}).map(e=>`--${e}`),s=getVisibleNegatedName(n,r),c=s===void 0?[]:[`--${s}`],l=[...a,i,...o,...c],u=r.kind===`keyValue`?void 0:valueEnumValues(flagValueSchema(r)),d=``;if(flagExpectsValue(r)&&(d=u===void 0?`:value:`:`:value:(${u.map(escapeZshEnumValue).join(` `)})`),l.length>1){let n=l.map(escapeZshCasePatternValue).join(`,`);t.push(`${quoteShellArg(`(${l.join(` `)})`)}{${n}}${quoteShellArg(`[${e}]${d}`)}`)}else t.push(quoteShellArg(`${i}[${e}]${d}`))}return t}function escapeZshEnumValue(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/ /g,`\\ `).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`)}var completion_exports=/* @__PURE__ */ __exportAll({generateCompletion:()=>generateCompletion});function generateCompletion(e,t,n){switch(t){case`bash`:return generateBashCompletion(e,n);case`zsh`:return generateZshCompletion(e,n);case`fish`:return generateFishCompletion(e,n);case`powershell`:return generatePowerShellCompletion(e,n)}}export{generateFishCompletion as a,generatePowerShellCompletion as i,generateCompletion as n,generateBashCompletion as o,generateZshCompletion as r,completion_exports as t};
@@ -1,4 +1,14 @@
1
- import { C as SHELLS, T as CompletionOptions, o as CLISchema, w as Shell } from "./index-hzYPRc_O.mjs";
1
+ /**
2
+ * Shell completion script generation.
3
+ *
4
+ * Generates Bash, Zsh, Fish, and PowerShell completion scripts from a CLI
5
+ * schema. `CLIBuilder.completions()` loads this module on demand, so import
6
+ * it directly only to write scripts yourself or to drive completion from
7
+ * custom tooling.
8
+ *
9
+ * @module @kjanat/dreamcli/completion
10
+ */
11
+ import { C as SHELLS, T as CompletionOptions, o as CLISchema, w as Shell } from "./index-Vjl2_m23.mjs";
2
12
  /**
3
13
  * Generate a bash completion script for the CLI.
4
14
  *
@@ -1 +1 @@
1
- import{st as SHELLS}from"./core-B9YNSJeA.mjs";import{a as generateFishCompletion,i as generatePowerShellCompletion,n as generateCompletion,o as generateBashCompletion,r as generateZshCompletion}from"./completion-Bh-qywmB.mjs";export{SHELLS,generateBashCompletion,generateCompletion,generateFishCompletion,generatePowerShellCompletion,generateZshCompletion};
1
+ import{a as generateFishCompletion,i as generatePowerShellCompletion,n as generateCompletion,o as generateBashCompletion,r as generateZshCompletion}from"./completion-B4oRc2Ae.mjs";import{yt as SHELLS}from"./core-BZx351-p.mjs";export{SHELLS,generateBashCompletion,generateCompletion,generateFishCompletion,generatePowerShellCompletion,generateZshCompletion};
@@ -0,0 +1 @@
1
+ import{t as __exportAll}from"./rolldown-runtime-DOYBPklu.mjs";import{pt as CLIError}from"./core-BZx351-p.mjs";var config_exports=/* @__PURE__ */ __exportAll({discoverConfig:()=>discoverConfig});function isPlainObject(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const jsonLoader={extensions:[`json`],parse:e=>{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`Config must be a JSON object`);return t}};function joinPath(e,...t){let n=e.includes(`\\`)?`\\`:`/`;return[e.endsWith(n)?e.slice(0,-1):e,...t].join(n)}function ancestorDirs(e){let t=e.includes(`\\`)?`\\`:`/`,n=e;for(;n.length>1&&n.endsWith(t)&&!n.endsWith(`:${t}`);)n=n.slice(0,-1);let r=[n];for(;;){let e=n.lastIndexOf(t);if(e<0)break;let i=n.slice(0,e);if(i===``?i=t:/^[A-Za-z]:$/.test(i)&&(i=`${i}${t}`),i===n)break;r.push(i),n=i}return r}function getExtension(e){let t=e.lastIndexOf(`.`);return t<=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))?``:e.slice(t+1).toLowerCase()}function buildConfigSearchPaths(e,t){let n=buildExtensionList(t.loaders),r=[];for(let i of ancestorDirs(t.baseDir)){for(let t of n)r.push(joinPath(i,`.${e}.${t}`));for(let t of n)r.push(joinPath(i,`${e}.config.${t}`));for(let t of n)r.push(joinPath(i,`.config`,`${e}.${t}`))}for(let i of t.userConfigDirs)for(let t of n)r.push(joinPath(i,e,`config.${t}`));for(let i of t.systemConfigDirs??[])for(let t of n)r.push(joinPath(i,e,`config.${t}`));return r}function buildExtensionList(e){let t=/* @__PURE__ */ new Set,n=[];for(let e of jsonLoader.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}if(e!==void 0)for(let r of e)for(let e of r.extensions){let r=e.toLowerCase();t.has(r)||(t.add(r),n.push(r))}return n}function buildLoaderMap(e){let t=/* @__PURE__ */ new Map;for(let e of jsonLoader.extensions)t.set(e.toLowerCase(),jsonLoader);if(e!==void 0)for(let n of e)for(let e of n.extensions)t.set(e.toLowerCase(),n);return t}async function discoverConfig(e,t,n){let r=buildLoaderMap(n?.loaders),i=n?.configPath===void 0?n?.searchPaths??buildConfigSearchPaths(e,{baseDir:n?.baseDir??t.cwd,userConfigDirs:t.userConfigDirs??[t.configDir],systemConfigDirs:t.systemConfigDirs??[],...n?.loaders===void 0?{}:{loaders:n.loaders}}):[n.configPath];for(let e of i){let i=await t.readFile(e);if(i===null){if(n?.configPath!==void 0)throw new CLIError(`Config file not found: ${e}`,{code:`CONFIG_NOT_FOUND`,details:{path:e},suggest:`Create the config file or remove the --config flag`});continue}let a=getExtension(e),o=r.get(a);if(o===void 0)throw new CLIError(`No loader registered for config format: .${a}`,{code:`CONFIG_UNKNOWN_FORMAT`,details:{path:e,extension:a},suggest:`Supported formats: ${[...r.keys()].join(`, `)}`});try{let t=o.parse(i);if(!isPlainObject(t))throw Error(`Config loader must return a plain object`);return{found:!0,path:e,data:t,format:a}}catch(t){throw new CLIError(`Failed to parse config file: ${e}`,{code:`CONFIG_PARSE_ERROR`,cause:t,details:{path:e,format:a,message:t instanceof Error?t.message:String(t)},suggest:`Check the config file for syntax errors`})}}return{found:!1}}function configFormat(e,t){return{extensions:e,parse:t}}export{discoverConfig as i,configFormat as n,config_exports as r,buildConfigSearchPaths as t};
package/dist/config.d.mts CHANGED
@@ -1,2 +1,12 @@
1
- import { _ as discoverManifest, a as ConfigNotFound, c as buildConfigSearchPaths, d as PackageRepositoryUrlOptions, f as packageRepositoryUrl, g as PackageRepository, h as PackageJsonData, i as ConfigFound, l as configFormat, m as PackageJsonAdapter, n as ConfigDiscoveryOptions, o as ConfigSearchPathOptions, p as ManifestDiscoveryOptions, r as ConfigDiscoveryResult, s as FormatLoader, t as ConfigAdapter, u as discoverConfig, v as inferCliName } from "./index-jq_FJRKt.mjs";
1
+ /**
2
+ * Config file and package manifest discovery.
3
+ *
4
+ * `CLIBuilder.run()` loads discovery code on demand when config or manifest
5
+ * discovery runs. Preloaded `.manifest(data)` keeps discovery cold.
6
+ * Import this module directly to run discovery from your own
7
+ * bootstrap code or to register custom config formats.
8
+ *
9
+ * @module @kjanat/dreamcli/config
10
+ */
11
+ import { _ as discoverManifest, a as ConfigNotFound, c as buildConfigSearchPaths, d as PackageRepositoryUrlOptions, f as packageRepositoryUrl, g as PackageRepository, h as PackageJsonData, i as ConfigFound, l as configFormat, m as PackageJsonAdapter, n as ConfigDiscoveryOptions, o as ConfigSearchPathOptions, p as ManifestDiscoveryOptions, r as ConfigDiscoveryResult, s as FormatLoader, t as ConfigAdapter, u as discoverConfig, v as inferCliName } from "./index-DIWRV_wp.mjs";
2
12
  export { type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSearchPathOptions, type FormatLoader, type ManifestDiscoveryOptions, type PackageJsonAdapter, type PackageJsonData, type PackageRepository, type PackageRepositoryUrlOptions, buildConfigSearchPaths, configFormat, discoverConfig, discoverManifest, inferCliName, packageRepositoryUrl };
package/dist/config.mjs CHANGED
@@ -1 +1 @@
1
- import{h as packageRepositoryUrl}from"./core-B9YNSJeA.mjs";import{n as inferCliName,t as discoverManifest}from"./package-json-fYhxDdWD.mjs";import{i as discoverConfig,n as configFormat,t as buildConfigSearchPaths}from"./config-DruA8aFV.mjs";export{buildConfigSearchPaths,configFormat,discoverConfig,discoverManifest,inferCliName,packageRepositoryUrl};
1
+ import{x as packageRepositoryUrl}from"./core-BZx351-p.mjs";import{n as inferCliName,t as discoverManifest}from"./package-json-hqUWeazy.mjs";import{i as discoverConfig,n as configFormat,t as buildConfigSearchPaths}from"./config-DSh3QJpX.mjs";export{buildConfigSearchPaths,configFormat,discoverConfig,discoverManifest,inferCliName,packageRepositoryUrl};