@kjanat/dreamcli 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.md +63 -6
  2. package/LICENSE +1 -1
  3. package/README.md +296 -164
  4. package/dist/core/cli/dispatch.d.mts +85 -0
  5. package/dist/core/cli/dispatch.mjs +1 -0
  6. package/dist/core/cli/index.d.mts +418 -0
  7. package/dist/core/cli/index.mjs +1 -0
  8. package/dist/core/cli/planner.d.mts +143 -0
  9. package/dist/core/cli/planner.mjs +1 -0
  10. package/dist/core/cli/plugin.d.mts +94 -0
  11. package/dist/core/cli/plugin.mjs +1 -0
  12. package/dist/core/cli/propagate.d.mts +39 -0
  13. package/dist/core/cli/propagate.mjs +1 -0
  14. package/dist/core/cli/root-help.d.mts +28 -0
  15. package/dist/core/cli/root-help.mjs +7 -0
  16. package/dist/core/cli/root-surface.d.mts +42 -0
  17. package/dist/core/cli/root-surface.mjs +1 -0
  18. package/dist/core/cli/runtime-preflight.d.mts +149 -0
  19. package/dist/core/cli/runtime-preflight.mjs +1 -0
  20. package/dist/core/completion/index.d.mts +46 -0
  21. package/dist/core/completion/index.mjs +1 -0
  22. package/dist/core/completion/shells/bash.d.mts +24 -0
  23. package/dist/core/completion/shells/bash.mjs +3 -0
  24. package/dist/core/completion/shells/fish.d.mts +20 -0
  25. package/dist/core/completion/shells/fish.mjs +2 -0
  26. package/dist/core/completion/shells/powershell.d.mts +14 -0
  27. package/dist/core/completion/shells/powershell.mjs +2 -0
  28. package/dist/core/completion/shells/shared.d.mts +139 -0
  29. package/dist/core/completion/shells/shared.mjs +1 -0
  30. package/dist/core/completion/shells/zsh.d.mts +24 -0
  31. package/dist/core/completion/shells/zsh.mjs +2 -0
  32. package/dist/core/config/index.d.mts +161 -0
  33. package/dist/core/config/index.mjs +1 -0
  34. package/dist/core/config/package-json.d.mts +68 -0
  35. package/dist/core/config/package-json.mjs +1 -0
  36. package/dist/core/errors/index.d.mts +126 -0
  37. package/dist/core/errors/index.mjs +1 -0
  38. package/dist/core/execution/index.d.mts +49 -0
  39. package/dist/core/execution/index.mjs +1 -0
  40. package/dist/core/help/index.d.mts +49 -0
  41. package/dist/core/help/index.mjs +8 -0
  42. package/dist/core/json-schema/index.d.mts +109 -0
  43. package/dist/core/json-schema/index.mjs +55 -0
  44. package/dist/core/json-schema/meta-descriptions.generated.d.mts +185 -0
  45. package/dist/core/json-schema/meta-descriptions.generated.mjs +28 -0
  46. package/dist/core/output/activity.d.mts +194 -0
  47. package/dist/core/output/activity.mjs +1 -0
  48. package/dist/core/output/contracts.d.mts +88 -0
  49. package/dist/core/output/contracts.mjs +1 -0
  50. package/dist/core/output/display-value.d.mts +19 -0
  51. package/dist/core/output/display-value.mjs +1 -0
  52. package/dist/core/output/index.d.mts +280 -0
  53. package/dist/core/output/index.mjs +2 -0
  54. package/dist/core/output/renderers.d.mts +46 -0
  55. package/dist/core/output/renderers.mjs +1 -0
  56. package/dist/core/output/writer.d.mts +40 -0
  57. package/dist/core/output/writer.mjs +1 -0
  58. package/dist/core/parse/index.d.mts +79 -0
  59. package/dist/core/parse/index.mjs +1 -0
  60. package/dist/core/prompt/index.d.mts +205 -0
  61. package/dist/core/prompt/index.mjs +6 -0
  62. package/dist/core/resolve/args.d.mts +8 -0
  63. package/dist/core/resolve/args.mjs +1 -0
  64. package/dist/core/resolve/coerce.d.mts +22 -0
  65. package/dist/core/resolve/coerce.mjs +1 -0
  66. package/dist/core/resolve/config.d.mts +10 -0
  67. package/dist/core/resolve/config.mjs +1 -0
  68. package/dist/core/resolve/contracts.d.mts +112 -0
  69. package/dist/core/resolve/errors.d.mts +11 -0
  70. package/dist/core/resolve/errors.mjs +2 -0
  71. package/dist/core/resolve/flags.d.mts +10 -0
  72. package/dist/core/resolve/flags.mjs +1 -0
  73. package/dist/core/resolve/index.d.mts +42 -0
  74. package/dist/core/resolve/index.mjs +1 -0
  75. package/dist/core/resolve/property.d.mts +47 -0
  76. package/dist/core/resolve/property.mjs +1 -0
  77. package/dist/core/schema/activity.d.mts +169 -0
  78. package/dist/core/schema/arg.d.mts +559 -0
  79. package/dist/core/schema/arg.mjs +1 -0
  80. package/dist/core/schema/command.d.mts +960 -0
  81. package/dist/core/schema/command.mjs +1 -0
  82. package/dist/core/schema/flag.d.mts +491 -0
  83. package/dist/core/schema/flag.mjs +1 -0
  84. package/dist/core/schema/index.d.mts +8 -0
  85. package/dist/core/schema/middleware.d.mts +122 -0
  86. package/dist/core/schema/middleware.mjs +1 -0
  87. package/dist/core/schema/prompt.d.mts +117 -0
  88. package/dist/core/schema/run.d.mts +171 -0
  89. package/dist/core/schema-dsl/runtime.d.mts +144 -0
  90. package/dist/core/schema-dsl/runtime.mjs +2 -0
  91. package/dist/core/schema-dsl/to-json-schema.d.mts +30 -0
  92. package/dist/core/schema-dsl/to-json-schema.mjs +1 -0
  93. package/dist/core/testkit/index.d.mts +54 -0
  94. package/dist/core/testkit/index.mjs +1 -0
  95. package/dist/index.d.mts +28 -920
  96. package/dist/index.mjs +1 -10
  97. package/dist/runtime/adapter.d.mts +212 -0
  98. package/dist/{adapter-B37d9oia.mjs → runtime/adapter.mjs} +1 -1
  99. package/dist/runtime/auto.d.mts +26 -0
  100. package/dist/runtime/auto.mjs +1 -0
  101. package/dist/runtime/bun.d.mts +28 -0
  102. package/dist/runtime/bun.mjs +1 -0
  103. package/dist/runtime/deno.d.mts +76 -0
  104. package/dist/runtime/deno.mjs +2 -0
  105. package/dist/runtime/detect.d.mts +86 -0
  106. package/dist/runtime/detect.mjs +1 -0
  107. package/dist/runtime/index.d.mts +7 -0
  108. package/dist/runtime/node.d.mts +65 -0
  109. package/dist/runtime/node.mjs +2 -0
  110. package/dist/runtime/paths.d.mts +31 -0
  111. package/dist/runtime/paths.mjs +1 -0
  112. package/dist/runtime/support.d.mts +42 -0
  113. package/dist/runtime/support.mjs +1 -0
  114. package/dist/runtime.d.mts +6 -252
  115. package/dist/runtime.mjs +1 -1
  116. package/dist/testkit.d.mts +5 -24
  117. package/dist/testkit.mjs +1 -1
  118. package/dist/version.d.mts +16 -0
  119. package/dist/version.mjs +1 -0
  120. package/dreamcli.schema.json +338 -0
  121. package/examples/basic.ts +2 -2
  122. package/examples/gh/package.json +7 -11
  123. package/examples/gh/src/commands/auth.ts +2 -2
  124. package/examples/gh/src/commands/issue.ts +4 -4
  125. package/examples/gh/src/commands/pr.ts +4 -4
  126. package/examples/gh/src/docs.ts +11 -0
  127. package/examples/gh/src/lib/auth.ts +1 -1
  128. package/examples/gh/src/main.test.ts +6 -5
  129. package/examples/gh/src/main.ts +8 -6
  130. package/examples/interactive.ts +3 -3
  131. package/examples/json-mode.ts +4 -6
  132. package/examples/middleware.ts +3 -3
  133. package/examples/multi-command.ts +3 -3
  134. package/examples/spinner-progress.ts +5 -5
  135. package/examples/testing.ts +8 -6
  136. package/package.json +70 -44
  137. package/src/core/cli/dispatch.ts +4 -0
  138. package/src/core/cli/index.ts +185 -632
  139. package/src/core/cli/planner.ts +413 -0
  140. package/src/core/cli/plugin.ts +7 -1
  141. package/src/core/cli/propagate.ts +1 -1
  142. package/src/core/cli/runtime-preflight.ts +409 -0
  143. package/src/core/completion/index.ts +15 -9
  144. package/src/core/completion/shells/bash.ts +6 -3
  145. package/src/core/completion/shells/fish.ts +245 -10
  146. package/src/core/completion/shells/powershell.ts +390 -9
  147. package/src/core/completion/shells/shared.ts +4 -4
  148. package/src/core/completion/shells/zsh.ts +12 -7
  149. package/src/core/config/index.ts +7 -4
  150. package/src/core/config/package-json.ts +6 -2
  151. package/src/core/errors/index.ts +23 -8
  152. package/src/core/execution/index.ts +270 -0
  153. package/src/core/help/index.ts +13 -15
  154. package/src/core/json-schema/index.ts +193 -7
  155. package/src/core/json-schema/meta-descriptions.generated.ts +202 -0
  156. package/src/core/output/contracts.ts +194 -0
  157. package/src/core/output/index.ts +47 -82
  158. package/src/core/output/renderers.ts +125 -0
  159. package/src/core/parse/index.ts +39 -21
  160. package/src/core/prompt/index.ts +44 -27
  161. package/src/core/resolve/args.ts +144 -0
  162. package/src/core/resolve/coerce.ts +432 -0
  163. package/src/core/resolve/config.ts +26 -0
  164. package/src/core/resolve/contracts.ts +135 -0
  165. package/src/core/resolve/errors.ts +227 -0
  166. package/src/core/resolve/flags.ts +205 -0
  167. package/src/core/resolve/index.ts +41 -1264
  168. package/src/core/resolve/property.ts +99 -0
  169. package/src/core/schema/activity.ts +3 -0
  170. package/src/core/schema/arg.ts +26 -14
  171. package/src/core/schema/command.ts +265 -38
  172. package/src/core/schema/flag.ts +120 -15
  173. package/src/core/schema/index.ts +11 -2
  174. package/src/core/schema/middleware.ts +6 -6
  175. package/src/core/schema/prompt.ts +9 -1
  176. package/src/core/schema/run.ts +25 -17
  177. package/src/core/schema-dsl/index.ts +109 -0
  178. package/src/core/schema-dsl/parse.ts +262 -0
  179. package/src/core/schema-dsl/runtime.ts +609 -0
  180. package/src/core/schema-dsl/to-json-schema.ts +102 -0
  181. package/src/core/testkit/index.ts +55 -297
  182. package/src/index.ts +10 -4
  183. package/src/runtime/adapter.ts +13 -10
  184. package/src/runtime/auto.ts +3 -3
  185. package/src/runtime/bun.ts +4 -4
  186. package/src/runtime/deno.ts +43 -29
  187. package/src/runtime/detect.ts +4 -1
  188. package/src/runtime/index.ts +1 -1
  189. package/src/runtime/node.ts +43 -21
  190. package/src/runtime/paths.ts +9 -3
  191. package/src/runtime/support.ts +20 -4
  192. package/src/runtime.ts +1 -1
  193. package/src/testkit.ts +10 -8
  194. package/dist/adapter-CCSh5juX.cjs +0 -1
  195. package/dist/adapter-DIwO-q7K.d.mts +0 -3447
  196. package/dist/adapter-DQnxxLiE.d.cts +0 -3447
  197. package/dist/auto-5cjZaF9V.mjs +0 -3
  198. package/dist/auto-B0eSgoDw.cjs +0 -3
  199. package/dist/index.cjs +0 -10
  200. package/dist/index.d.cts +0 -920
  201. package/dist/runtime.cjs +0 -1
  202. package/dist/runtime.d.cts +0 -253
  203. package/dist/testkit-CEDYPvhF.mjs +0 -14
  204. package/dist/testkit-ClIKijxC.cjs +0 -14
  205. package/dist/testkit.cjs +0 -1
  206. package/dist/testkit.d.cts +0 -25
  207. package/examples/gh/tsconfig.json +0 -37
  208. package/examples/tsconfig.json +0 -17
  209. package/src/core/cli/AGENTS.md +0 -72
  210. package/src/core/completion/AGENTS.md +0 -72
  211. package/src/core/completion/completion-test-helpers.ts +0 -48
  212. package/src/core/output/AGENTS.md +0 -69
  213. package/src/core/resolve/AGENTS.md +0 -69
  214. package/src/core/schema/AGENTS.md +0 -61
  215. package/src/core/testkit/AGENTS.md +0 -55
  216. package/src/runtime/AGENTS.md +0 -74
  217. package/src/runtime/test-helpers.ts +0 -40
@@ -1,3 +0,0 @@
1
- function e(e,t){return t?e.USERPROFILE?e.USERPROFILE:e.HOMEDRIVE&&e.HOMEPATH?e.HOMEDRIVE+e.HOMEPATH:e.HOME||`C:\\`:e.HOME||`/`}function t(e,t,n){if(t)return e.APPDATA!==void 0&&e.APPDATA!==``?e.APPDATA:`${n.replace(/[\\/]+$/,``)||n}\\AppData\\Roaming`;let r=n.replace(/\/+$/,``)||n;return e.XDG_CONFIG_HOME||`${r}/.config`}const n=[{runtime:`node`,displayName:`Node.js`,minimum:`22.22.2`,engineRange:`>=22.22.2`,packageName:`dreamcli`,adapterName:`NodeAdapter`},{runtime:`bun`,displayName:`Bun`,minimum:`1.3.11`,engineRange:`>=1.3.11`,packageName:`dreamcli`,adapterName:`BunAdapter`},{runtime:`deno`,displayName:`Deno`,minimum:`2.6.0`,engineRange:`>=2.6.0`,packageName:`@kjanat/dreamcli`,adapterName:`DenoAdapter`}],r=/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/;function i(e){for(let t of n)if(t.runtime===e)return t;throw Error(`Unknown supported runtime '${e}'`)}function a(e){let t=r.exec(e);if(t===null)return;let n=Number.parseInt(t[1]??``,10),i=t[2],a=i===void 0?0:Number.parseInt(i,10),o=t[3],s=o===void 0?0:Number.parseInt(o,10);if(!(Number.isNaN(n)||Number.isNaN(a)||Number.isNaN(s)))return{major:n,minor:a,patch:s}}function o(e,t){return e.major===t.major?e.minor===t.minor?e.patch-t.patch:e.minor-t.minor:e.major-t.major}function s(e){let t=i(e);return`${t.displayName} >= ${t.minimum}`}function c(e,t){let n=a(t),r=a(i(e).minimum);return n===void 0||r===void 0?!1:o(n,r)>=0}function l(e,t){if(t!==void 0&&!c(e,t))throw Error(`dreamcli requires ${s(e)}. Detected ${i(e).displayName} ${t}.`)}function u(){return globalThis.process}function d(e){return typeof e!=`object`||!e||!(`code`in e)?!1:typeof e.code==`string`}function f(t,n){return e(t,n===`win32`)}function p(e,n,r){return t(e,n===`win32`,r)}function m(e){if(e.versions?.bun!==void 0){l(`bun`,e.versions.bun);return}l(`node`,e.versions?.node)}function h(e){let t=e??u();m(t);let n=e=>{t.stdout.write(e)},r=e=>{t.stderr.write(e)},i=()=>_(t),a=async e=>{let t=await import(`node:fs/promises`);try{return await t.readFile(e,`utf8`)}catch(e){if(d(e)&&e.code===`ENOENT`)return null;throw e}},o=f(t.env,t.platform),s=p(t.env,t.platform,o),c=t.stdin.isTTY===!0;return{argv:t.argv,env:t.env,cwd:t.cwd(),stdout:n,stderr:r,stdin:i,readStdin:()=>g(t,c),isTTY:t.stdout.isTTY===!0,stdinIsTTY:c,exit:e=>t.exit(e),readFile:a,homedir:o,configDir:s}}async function g(e,t){if(t)return null;let n=[],r=new TextDecoder;for await(let t of e.stdin)n.push(r.decode(t,{stream:!0}));return n.push(r.decode()),n.join(``)}async function _(e){let t=e.stdin[Symbol.asyncIterator](),n=new TextDecoder,r=``,i=await t.next();for(;!i.done;){r+=n.decode(i.value,{stream:!0});let e=r.indexOf(`
2
- `);if(e!==-1)return r.slice(0,e).replace(/\r$/,``);i=await t.next()}return r+=n.decode(),r.length>0?r:null}function v(e){return e?.versions?.bun===void 0?globalThis.Bun?.version:e.versions.bun}function y(e){return l(`bun`,v(e)),h(e)}function b(e,t){if(typeof e!=`object`||!e||!(`name`in e))return!1;let n=e;return typeof n.name==`string`&&n.name===t}function x(e){try{return e.env.toObject()}catch(e){if(b(e,`PermissionDenied`))return{};throw e}}function S(e){try{return e.cwd()}catch(e){if(b(e,`PermissionDenied`))return`/`;throw e}}function C(e){let t=e??w();l(`deno`,t.version?.deno);let n=new TextEncoder,r=[`deno`,`run`,...t.args],i=x(t),a=S(t),o=e=>{t.stdout.writeSync(n.encode(e))},s=e=>{t.stderr.writeSync(n.encode(e))},c=()=>E(t),u=async e=>{try{return await t.readTextFile(e)}catch(e){if(b(e,`NotFound`)||b(e,`PermissionDenied`))return null;throw e}},d=D(i,t.build.os===`windows`),f=O(i,d,t.build.os===`windows`),p=t.stdin.isTerminal();return{argv:r,env:i,cwd:a,stdout:o,stderr:s,stdin:c,readStdin:()=>T(t,p),isTTY:t.stdout.isTerminal(),stdinIsTTY:p,exit:e=>t.exit(e),readFile:u,homedir:d,configDir:f}}function w(){return globalThis.Deno}async function T(e,t){if(t)return null;let n=e.stdin.readable.getReader(),r=new TextDecoder,i=[];try{for(;;){let{value:e,done:t}=await n.read();if(t){i.push(r.decode());break}i.push(r.decode(e,{stream:!0}))}}finally{n.releaseLock()}return i.join(``)}async function E(e){let t=e.stdin.readable.getReader(),n=new TextDecoder,r=``;try{for(;;){let{value:e,done:i}=await t.read();if(i)return r+=n.decode(),r.length>0?r:null;r+=n.decode(e,{stream:!0});let a=r.indexOf(`
3
- `);if(a!==-1)return r.slice(0,a).replace(/\r$/,``)}}finally{t.releaseLock()}}function D(t,n){return e(t,n)}function O(e,n,r){return t(e,r,n)}const k=[`node`,`bun`,`deno`,`unknown`];function A(e){let t=e??globalThis;return typeof t.Bun?.version==`string`?`bun`:typeof t.Deno?.version?.deno==`string`?`deno`:typeof t.process?.versions?.node==`string`?`node`:`unknown`}function j(e,t){switch(e){case`bun`:return t.Bun?.version;case`deno`:return t.Deno?.version?.deno;case`node`:return t.process?.versions?.node;case`unknown`:return;default:return e}}function M(e){if(typeof e!=`object`||!e)return!1;let t=e;return Array.isArray(t.args)&&typeof t.cwd==`function`&&typeof t.exit==`function`&&typeof t.readTextFile==`function`&&typeof t.env?.get==`function`&&typeof t.env.toObject==`function`&&typeof t.stdout?.writeSync==`function`&&typeof t.stdout.isTerminal==`function`&&typeof t.stderr?.writeSync==`function`&&typeof t.stdin?.isTerminal==`function`&&typeof t.stdin?.readable?.getReader==`function`}function N(e){let t=e.Deno;return M(t)?t:void 0}function P(e){let t=e??globalThis,n=A(t);switch(n!==`unknown`&&l(n,j(n,t)),n){case`bun`:return y();case`deno`:return C(N(t));case`node`:case`unknown`:return h();default:return n}}export{y as a,C as i,k as n,h as o,A as r,P as t};
@@ -1,3 +0,0 @@
1
- function e(e,t){return t?e.USERPROFILE?e.USERPROFILE:e.HOMEDRIVE&&e.HOMEPATH?e.HOMEDRIVE+e.HOMEPATH:e.HOME||`C:\\`:e.HOME||`/`}function t(e,t,n){if(t)return e.APPDATA!==void 0&&e.APPDATA!==``?e.APPDATA:`${n.replace(/[\\/]+$/,``)||n}\\AppData\\Roaming`;let r=n.replace(/\/+$/,``)||n;return e.XDG_CONFIG_HOME||`${r}/.config`}const n=[{runtime:`node`,displayName:`Node.js`,minimum:`22.22.2`,engineRange:`>=22.22.2`,packageName:`dreamcli`,adapterName:`NodeAdapter`},{runtime:`bun`,displayName:`Bun`,minimum:`1.3.11`,engineRange:`>=1.3.11`,packageName:`dreamcli`,adapterName:`BunAdapter`},{runtime:`deno`,displayName:`Deno`,minimum:`2.6.0`,engineRange:`>=2.6.0`,packageName:`@kjanat/dreamcli`,adapterName:`DenoAdapter`}],r=/^(\d+)(?:\.(\d+))?(?:\.(\d+))?/;function i(e){for(let t of n)if(t.runtime===e)return t;throw Error(`Unknown supported runtime '${e}'`)}function a(e){let t=r.exec(e);if(t===null)return;let n=Number.parseInt(t[1]??``,10),i=t[2],a=i===void 0?0:Number.parseInt(i,10),o=t[3],s=o===void 0?0:Number.parseInt(o,10);if(!(Number.isNaN(n)||Number.isNaN(a)||Number.isNaN(s)))return{major:n,minor:a,patch:s}}function o(e,t){return e.major===t.major?e.minor===t.minor?e.patch-t.patch:e.minor-t.minor:e.major-t.major}function s(e){let t=i(e);return`${t.displayName} >= ${t.minimum}`}function c(e,t){let n=a(t),r=a(i(e).minimum);return n===void 0||r===void 0?!1:o(n,r)>=0}function l(e,t){if(t!==void 0&&!c(e,t))throw Error(`dreamcli requires ${s(e)}. Detected ${i(e).displayName} ${t}.`)}function u(){return globalThis.process}function d(e){return typeof e!=`object`||!e||!(`code`in e)?!1:typeof e.code==`string`}function f(t,n){return e(t,n===`win32`)}function p(e,n,r){return t(e,n===`win32`,r)}function m(e){if(e.versions?.bun!==void 0){l(`bun`,e.versions.bun);return}l(`node`,e.versions?.node)}function h(e){let t=e??u();m(t);let n=e=>{t.stdout.write(e)},r=e=>{t.stderr.write(e)},i=()=>_(t),a=async e=>{let t=await import(`node:fs/promises`);try{return await t.readFile(e,`utf8`)}catch(e){if(d(e)&&e.code===`ENOENT`)return null;throw e}},o=f(t.env,t.platform),s=p(t.env,t.platform,o),c=t.stdin.isTTY===!0;return{argv:t.argv,env:t.env,cwd:t.cwd(),stdout:n,stderr:r,stdin:i,readStdin:()=>g(t,c),isTTY:t.stdout.isTTY===!0,stdinIsTTY:c,exit:e=>t.exit(e),readFile:a,homedir:o,configDir:s}}async function g(e,t){if(t)return null;let n=[],r=new TextDecoder;for await(let t of e.stdin)n.push(r.decode(t,{stream:!0}));return n.push(r.decode()),n.join(``)}async function _(e){let t=e.stdin[Symbol.asyncIterator](),n=new TextDecoder,r=``,i=await t.next();for(;!i.done;){r+=n.decode(i.value,{stream:!0});let e=r.indexOf(`
2
- `);if(e!==-1)return r.slice(0,e).replace(/\r$/,``);i=await t.next()}return r+=n.decode(),r.length>0?r:null}function v(e){return e?.versions?.bun===void 0?globalThis.Bun?.version:e.versions.bun}function y(e){return l(`bun`,v(e)),h(e)}function b(e,t){if(typeof e!=`object`||!e||!(`name`in e))return!1;let n=e;return typeof n.name==`string`&&n.name===t}function x(e){try{return e.env.toObject()}catch(e){if(b(e,`PermissionDenied`))return{};throw e}}function S(e){try{return e.cwd()}catch(e){if(b(e,`PermissionDenied`))return`/`;throw e}}function C(e){let t=e??w();l(`deno`,t.version?.deno);let n=new TextEncoder,r=[`deno`,`run`,...t.args],i=x(t),a=S(t),o=e=>{t.stdout.writeSync(n.encode(e))},s=e=>{t.stderr.writeSync(n.encode(e))},c=()=>E(t),u=async e=>{try{return await t.readTextFile(e)}catch(e){if(b(e,`NotFound`)||b(e,`PermissionDenied`))return null;throw e}},d=D(i,t.build.os===`windows`),f=O(i,d,t.build.os===`windows`),p=t.stdin.isTerminal();return{argv:r,env:i,cwd:a,stdout:o,stderr:s,stdin:c,readStdin:()=>T(t,p),isTTY:t.stdout.isTerminal(),stdinIsTTY:p,exit:e=>t.exit(e),readFile:u,homedir:d,configDir:f}}function w(){return globalThis.Deno}async function T(e,t){if(t)return null;let n=e.stdin.readable.getReader(),r=new TextDecoder,i=[];try{for(;;){let{value:e,done:t}=await n.read();if(t){i.push(r.decode());break}i.push(r.decode(e,{stream:!0}))}}finally{n.releaseLock()}return i.join(``)}async function E(e){let t=e.stdin.readable.getReader(),n=new TextDecoder,r=``;try{for(;;){let{value:e,done:i}=await t.read();if(i)return r+=n.decode(),r.length>0?r:null;r+=n.decode(e,{stream:!0});let a=r.indexOf(`
3
- `);if(a!==-1)return r.slice(0,a).replace(/\r$/,``)}}finally{t.releaseLock()}}function D(t,n){return e(t,n)}function O(e,n,r){return t(e,r,n)}const k=[`node`,`bun`,`deno`,`unknown`];function A(e){let t=e??globalThis;return typeof t.Bun?.version==`string`?`bun`:typeof t.Deno?.version?.deno==`string`?`deno`:typeof t.process?.versions?.node==`string`?`node`:`unknown`}function j(e,t){switch(e){case`bun`:return t.Bun?.version;case`deno`:return t.Deno?.version?.deno;case`node`:return t.process?.versions?.node;case`unknown`:return;default:return e}}function M(e){if(typeof e!=`object`||!e)return!1;let t=e;return Array.isArray(t.args)&&typeof t.cwd==`function`&&typeof t.exit==`function`&&typeof t.readTextFile==`function`&&typeof t.env?.get==`function`&&typeof t.env.toObject==`function`&&typeof t.stdout?.writeSync==`function`&&typeof t.stdout.isTerminal==`function`&&typeof t.stderr?.writeSync==`function`&&typeof t.stdin?.isTerminal==`function`&&typeof t.stdin?.readable?.getReader==`function`}function N(e){let t=e.Deno;return M(t)?t:void 0}function P(e){let t=e??globalThis,n=A(t);switch(n!==`unknown`&&l(n,j(n,t)),n){case`bun`:return y();case`deno`:return C(N(t));case`node`:case`unknown`:return h();default:return n}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return P}});
package/dist/index.cjs DELETED
@@ -1,10 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./testkit-ClIKijxC.cjs`),t=require(`./auto-B0eSgoDw.cjs`);function n(e){if(e.length<=1)return{};let t={};for(let n=0;n<e.length-1;n++){let r=e[n];if(r!==void 0){for(let[i,a]of Object.entries(r.flags))if(a.propagate){let r=!1;for(let t=n+1;t<e.length-1;t++){let n=e[t];if(n!==void 0&&i in n.flags){r=!0;break}}r||(t[i]=a)}}}let n=e[e.length-1];if(n!==void 0)for(let e of Object.keys(n.flags))delete t[e];return t}function r(e){let t=e.commands.map(e=>e.schema).filter(e=>!e.hidden),n=e.defaultCommand?.schema,r=n!==void 0&&!n.hidden?n:void 0;return{visibleCommands:t,visibleDefaultCommand:r,hasSingleVisibleDefault:r!==void 0&&t.length===1&&t[0]?.name===r.name,hasVisibleSiblingCommands:r!==void 0&&t.some(e=>e.name!==r.name)}}function i(){return`dreamcli v1.0.0 (e399212)`}function a(e,t=`subcommands`){let n=r(e),i=o(e.version!==void 0),a=n.visibleDefaultCommand?.flags??{},s=t===`surface`?n.visibleDefaultCommand!==void 0:n.hasSingleVisibleDefault;return{visibleCommands:n.visibleCommands,visibleDefaultCommand:n.visibleDefaultCommand,rootFlags:i,defaultFlags:a,includeDefaultFlags:s}}function o(e){return{help:s(`Show help text`),...e?{version:s(`Show version`)}:{}}}function s(e){return{kind:`boolean`,presence:`optional`,defaultValue:void 0,aliases:[],envVar:void 0,configPath:void 0,description:e,enumValues:void 0,elementSchema:void 0,prompt:void 0,parseFn:void 0,deprecated:void 0,propagate:!1}}function c(e,t=[]){let r=[];for(let i of e){if(i.hidden)continue;let e=[...t,i],a=n(e),o={...a,...i.flags},s=i.commands.filter(e=>!e.hidden);r.push({path:e.map(e=>e.name),schema:i,propagatedFlags:a,mergedFlags:o,children:s}),s.length>0&&r.push(...c(s,e))}return r}function l(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 u(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:`'${e.replace(/'/g,`'\\''`)}'`}function d(e,t){let n=`_${l(t?.functionPrefix??e.name)}_completions`,r=a(e,t?.rootMode),o=r.visibleCommands,s=c(o),d=s.reduce((e,t)=>Math.max(e,t.path.length),0),m=[];if(m.push(`#!/usr/bin/env bash`),m.push(`# Bash completion for ${e.name}`),m.push(`# Generated by ${i()}`),m.push(`#`),m.push(`# Usage: source <(${e.name} completions bash)`),m.push(`#`),m.push(`# Install permanently:`),m.push(`# ${e.name} completions bash > /etc/bash_completion.d/${e.name} # Linux`),m.push(`# ${e.name} completions bash > $(brew --prefix)/etc/bash_completion.d/${e.name} # macOS`),m.push(`#`),m.push(`# Requires: bash-completion (provides _init_completion)`),m.push(``),m.push(`${n}() {`),m.push(` local cur prev words cword`),m.push(` _init_completion || return`),m.push(``),o.length>0){let e=s.filter(e=>e.children.length>0),t=ee(s,r);m.push(` # Build subcommand path by scanning COMP_WORDS`),m.push(` local subcmd_path=""`),m.push(` local i`),m.push(` for ((i = 1; i < cword; i++)); do`),m.push(' case "${words[i]}" in'),m.push(` --) break ;;`),t.length>0&&m.push(`\t\t\t${t}) ((i++)); continue ;;`),m.push(` -*) continue ;;`),m.push(` esac`),f(m,o,e,d),m.push(` done`),m.push(``),m.push(` # Complete flags and subcommands for the active path`),m.push(` case "$subcmd_path" in`);for(let e of s){let t=e.path.join(` `),n=e.mergedFlags,r=te(n),i=y(n),a=b(e.children.flatMap(e=>[e.name,...e.aliases])).map(g).join(` `),o=i.split(` `).filter(Boolean).map(g).join(` `),s=a.length>0?`${a} ${o}`:o;if(m.push(`\t\t${p(t)})`),r.length>0){m.push(` local enum_flag=""`),m.push(` local enum_cur="$cur"`),m.push(` local enum_prefix=""`),m.push(` if [[ "$cur" == --*=* ]]; then`),m.push(' enum_flag="${cur%%=*}"'),m.push(' enum_cur="${cur#*=}"'),m.push(' enum_prefix="${cur%%=*}="'),m.push(` fi`),m.push(' case "${enum_flag:-$prev}" in');for(let e of r)m.push(`\t\t\t\t${e.flags})`),m.push(_(e.values,` `,`enum_cur`,`enum_prefix`)),m.push(` return`),m.push(` ;;`);m.push(` *)`),m.push(` ;;`),m.push(` esac`)}m.push(`\t\t\tCOMPREPLY=($(compgen -W '${s.trim()}' -- "$cur"))`),m.push(` return`),m.push(` ;;`)}m.push(` *)`),m.push(` ;;`),m.push(` esac`),m.push(``);let n=y(r.rootFlags).split(` `).filter(Boolean),i=r.includeDefaultFlags?y(r.defaultFlags).split(` `).filter(Boolean):[],a=b([...o.flatMap(e=>[e.name,...e.aliases]),...n,...i]).map(g).join(` `);m.push(` # Root-level completions: visible root surface`),m.push(`\tCOMPREPLY=($(compgen -W '${a}' -- "$cur"))`)}else{let e=y(r.rootFlags);m.push(`\tCOMPREPLY=($(compgen -W '${e}' -- "$cur"))`)}return m.push(`}`),m.push(``),m.push(`complete -F ${n} ${u(e.name)}`),m.push(``),m.join(`
2
- `)}function f(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(m);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="${h(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${p(n)})`),e.push(' case "${words[i]}" in');for(let n of t.children){let t=[n.name,...n.aliases].map(m);e.push(`\t\t\t\t\t${t.join(`|`)})`),e.push(`\t\t\t\t\t\tsubcmd_path="$subcmd_path ${h(n.name)}"`),e.push(` ;;`)}e.push(` esac`),e.push(` ;;`)}e.push(` esac`)}function p(e){return e.includes(` `)?`"${h(e)}"`:m(e)}function m(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 h(e){return e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\$/g,`\\$`).replace(/`/g,"\\`")}function g(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/'/g,`'\\''`)}function _(e,t,n=`cur`,r){let i=[];if(e.some(e=>!/^[a-zA-Z0-9_\-.]+$/.test(e))){let r=e.map(v).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.join(`
3
- `)}function v(e){return e.replace(/\\/g,`\\\\`).replace(/'/g,`\\'`).replace(/\n/g,`\\n`)}function y(e){let t=[];for(let[n,r]of Object.entries(e)){t.push(`--${n}`);for(let e of r.aliases)t.push(e.length===1?`-${e}`:`--${e}`)}return t.join(` `)}function ee(e,t){let n=new Set,r=e=>{for(let[t,r]of Object.entries(e))if(r.kind!==`boolean`){n.add(`--${t}`);for(let e of r.aliases)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(m).join(`|`)}function b(e){return[...new Set(e)]}function te(e){let t=[];for(let[n,r]of Object.entries(e)){if(r.kind!==`enum`||r.enumValues===void 0)continue;let e=[`--${n}`,...r.aliases.map(e=>e.length===1?`-${e}`:`--${e}`)].map(m);t.push({flags:e.join(`|`),values:r.enumValues})}return t}function ne(t,n){throw new e.p(`Shell completion for 'fish' is not yet supported`,{code:`UNSUPPORTED_OPERATION`,suggest:`Supported shells: bash, zsh`})}function re(t,n){throw new e.p(`Shell completion for 'powershell' is not yet supported`,{code:`UNSUPPORTED_OPERATION`,suggest:`Supported shells: bash, zsh`})}function ie(t,n){let r=`_${l(n?.functionPrefix??t.name)}`,o=a(t,n?.rootMode),s=o.visibleCommands,d=c(s),f=[];f.push(`#compdef ${u(t.name)}`),f.push(`# Zsh completion for ${t.name}`),f.push(`# Generated by ${i()}`),f.push(`#`),f.push(`# Usage: source <(${t.name} completions zsh)`),f.push(`#`),f.push(`# Install permanently:`),f.push(`# ${t.name} completions zsh > "\${fpath[1]}/_${t.name}"`),f.push(`# # Then restart your shell`),f.push(``);let p=d.filter(e=>e.children.length>0),m=d.filter(e=>e.children.length===0);for(let e of m)e.path.length<2||oe(f,`${r}_${e.path.map(l).join(`_`)}`,e);let h=[...p].sort((e,t)=>t.path.length-e.path.length);for(let e of h)ae(f,`${r}_${e.path.map(l).join(`_`)}`,r,e);if(f.push(`${r}() {`),s.length>0){f.push(` local -a subcmds`),f.push(` local line state`),f.push(``);let t=S({...o.rootFlags,...o.includeDefaultFlags?o.defaultFlags:{}});f.push(` _arguments -C \\`);for(let e of t)f.push(`\t\t${e} \\`);f.push(` '1: :->subcmd' \\`),f.push(` '*::arg:->args'`),f.push(``),f.push(` case "$state" in`),f.push(` subcmd)`),f.push(` subcmds=(`),se(f,s,` `),f.push(` )`),f.push(` _describe 'command' subcmds`),f.push(` ;;`),f.push(` args)`),f.push(` case "$line[1]" in`);for(let t of s){let n=[t.name,...t.aliases].map(x),i=t.commands.filter(e=>!e.hidden);if(f.push(`\t\t\t\t${n.join(`|`)})`),i.length>0){let e=`${r}_${l(t.name)}`;f.push(`\t\t\t\t\t${e}`)}else{let n=d.find(e=>e.path.length===1&&e.schema.name===t.name);if(n===void 0)throw new e.p(`Missing completion node for command '${t.name}'`,{code:`UNEXPECTED_ERROR`});let r=S(n.mergedFlags);if(r.length>0){f.push(` _arguments \\`);for(let e=0;e<r.length;e++){let t=e<r.length-1?` \\`:``;f.push(`\t\t\t\t\t\t${r[e]}${t}`)}}}f.push(` ;;`)}f.push(` esac`),f.push(` ;;`),f.push(` esac`)}else{let e=S(o.rootFlags);f.push(` _arguments \\`);for(let t=0;t<e.length;t++){let n=t<e.length-1?` \\`:``;f.push(`\t\t${e[t]}${n}`)}}return f.push(`}`),f.push(``),f.push(`${r} "$@"`),f.push(``),f.join(`
4
- `)}function ae(e,t,n,r){e.push(`${t}() {`),e.push(` local -a subcmds`),e.push(` local line state`),e.push(``);let i=S(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=(`),se(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(x),a=`${n}_${[...r.path,t.name].map(l).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 oe(e,t,n){let r=S(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 se(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}${u(`${i}:${t}`)}`)}}function x(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 ce(e){return e.replace(/\\/g,`\\\\`).replace(/\]/g,`\\]`)}function S(e){let t=[];for(let[n,r]of Object.entries(e)){let e=ce(r.description??n),i=`--${n}`,a=r.aliases.filter(e=>e.length===1).map(e=>`-${e}`),o=``;if(r.kind===`boolean`||(o=r.kind===`enum`&&r.enumValues!==void 0?`:value:(${r.enumValues.map(le).join(` `)})`:`:value:`),a.length>0){let n=[...a,i],r=n.map(x).join(`,`);t.push(`${u(`(${n.join(` `)})`)}{${r}}${u(`[${e}]${o}`)}`)}else t.push(u(`${i}[${e}]${o}`))}return t}function le(e){return/^[a-zA-Z0-9_\-.]+$/.test(e)?e:e.replace(/\\/g,`\\\\`).replace(/ /g,`\\ `).replace(/\(/g,`\\(`).replace(/\)/g,`\\)`)}const C=Object.freeze([`bash`,`zsh`]);function w(e,t,n){switch(t){case`bash`:return d(e,n);case`zsh`:return ie(e,n);case`fish`:return ne(e,n);case`powershell`:return re(e,n)}}function T(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ue(e){let t=e.lastIndexOf(`/`),n=e.lastIndexOf(`\\`),r=Math.max(t,n),i=n>t?`\\`:`/`;if(r<0)return;if(r===0)return e.length>1?i:void 0;let a=e.slice(0,r);if(a.length===2&&a[1]===`:`){let t=`${a}${i}`;return t===e?void 0:t}return a}function de(e,t){let n=e.includes(`\\`)?`\\`:`/`;return e.endsWith(n)?`${e}${t}`:`${e}${n}${t}`}async function E(e){let t=e.cwd;for(;t!==void 0;){let n=null;try{n=await e.readFile(de(t,`package.json`))}catch{}if(n!==null){let e=fe(n);if(e!==null)return e}t=ue(t)}return null}function fe(e){try{let t=JSON.parse(e);if(!T(t))return null;let n=typeof t.name==`string`?t.name:void 0,r=typeof t.version==`string`?t.version:void 0,i=typeof t.description==`string`?t.description:void 0,a=pe(t.bin);return{...n===void 0?{}:{name:n},...r===void 0?{}:{version:r},...i===void 0?{}:{description:i},...a===void 0?{}:{bin:a}}}catch{return null}}function pe(e){if(typeof e==`string`)return e;if(!T(e))return;let t={};for(let[n,r]of Object.entries(e)){if(typeof r!=`string`)return;t[n]=r}return t}function D(e){if(typeof e.bin==`object`){let t=Object.keys(e.bin);if(t.length>0&&t[0]!==void 0)return t[0]}if(e.name!==void 0){let t=e.name.indexOf(`/`);return t>=0?e.name.slice(t+1):e.name}}function me(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}const O={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 k(e,...t){let n=e.includes(`\\`)?`\\`:`/`;return[e,...t].join(n)}function he(e){let t=e.lastIndexOf(`.`);return t<=Math.max(e.lastIndexOf(`/`),e.lastIndexOf(`\\`))?``:e.slice(t+1).toLowerCase()}function A(e,t,n,r){let i=ge(r),a=[];for(let n of i)a.push(k(t,`.${e}.${n}`));for(let n of i)a.push(k(t,`${e}.config.${n}`));for(let t of i)a.push(k(n,e,`config.${t}`));return a}function ge(e){let t=new Set,n=[];for(let e of O.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 _e(e){let t=new Map;for(let e of O.extensions)t.set(e.toLowerCase(),O);if(e!==void 0)for(let n of e)for(let e of n.extensions)t.set(e.toLowerCase(),n);return t}async function j(t,n,r){let i=_e(r?.loaders),a=r?.configPath===void 0?r?.searchPaths??A(t,n.cwd,n.configDir,r?.loaders):[r.configPath];for(let t of a){let a=await n.readFile(t);if(a===null){if(r?.configPath!==void 0)throw new e.p(`Config file not found: ${t}`,{code:`CONFIG_NOT_FOUND`,details:{path:t},suggest:`Create the config file or remove the --config flag`});continue}let o=he(t),s=i.get(o);if(s===void 0)throw new e.p(`No loader registered for config format: .${o}`,{code:`CONFIG_UNKNOWN_FORMAT`,details:{path:t,extension:o},suggest:`Supported formats: ${[...i.keys()].join(`, `)}`});try{let e=s.parse(a);if(!me(e))throw Error(`Config loader must return a plain object`);return{found:!0,path:t,data:e,format:o}}catch(n){throw new e.p(`Failed to parse config file: ${t}`,{code:`CONFIG_PARSE_ERROR`,cause:n,details:{path:t,format:o,message:n instanceof Error?n.message:String(n)},suggest:`Check the config file for syntax errors`})}}return{found:!1}}function ve(e,t){return{extensions:e,parse:t}}function M(e,t){return{kind:e,presence:`required`,variadic:!1,stdinMode:!1,defaultValue:void 0,description:void 0,envVar:void 0,enumValues:void 0,parseFn:void 0,deprecated:void 0,...t}}var N=class e{schema;constructor(e){this.schema=e}required(){return new e({...this.schema,presence:`required`})}optional(){return new e({...this.schema,presence:`optional`})}default(t){return new e({...this.schema,presence:`defaulted`,defaultValue:t})}variadic(){return new e({...this.schema,variadic:!0})}stdin(){return new e({...this.schema,stdinMode:!0})}env(t){return new e({...this.schema,envVar:t})}describe(t){return new e({...this.schema,description:t})}deprecated(t){return new e({...this.schema,deprecated:t??!0})}};const P={string(){return new N(M(`string`))},number(){return new N(M(`number`))},enum(e){return new N(M(`enum`,{enumValues:e}))},custom(e){return new N(M(`custom`,{parseFn:e}))}};function ye(t,n,r){if(n.stdinMode&&n.variadic)throw new e.p(`Argument <${t}> cannot be both variadic and stdin-backed`,{code:`INVALID_BUILDER_STATE`,details:{arg:t,stdinMode:!0,variadic:!0},suggest:`Remove .stdin() or .variadic() from this argument`});if(!n.stdinMode)return;let i=r.find(e=>e.schema.stdinMode);if(i!==void 0)throw new e.p(`Only one stdin argument is allowed; <${i.name}> is already stdin-backed`,{code:`DUPLICATE_STDIN_ARG`,details:{arg:t,existingArg:i.name},suggest:`Keep .stdin() on a single argument per command`})}function be(e){return e}var F=class e{schema;handler;_subcommands;_executionSteps;constructor(e,t,n,r){this.schema=e,this.handler=t,this._subcommands=n??[],this._executionSteps=r??[]}interactive(t){let n=t;return new e({...this.schema,interactive:n},this.handler,this._subcommands,this._executionSteps)}derive(t){let n=t;return new e({...this.schema,hasAction:!1},void 0,this._subcommands,[...this._executionSteps,{kind:`derive`,handler:n}])}middleware(t){return new e({...this.schema,middleware:[...this.schema.middleware,t._handler],hasAction:!1},void 0,this._subcommands,[...this._executionSteps,{kind:`middleware`,handler:t._handler}])}description(t){return new e({...this.schema,description:t},this.handler,this._subcommands,this._executionSteps)}alias(t){return new e({...this.schema,aliases:[...this.schema.aliases,t]},this.handler,this._subcommands,this._executionSteps)}hidden(){return new e({...this.schema,hidden:!0},this.handler,this._subcommands,this._executionSteps)}example(t,n){let r=n===void 0?{command:t}:{command:t,description:n};return new e({...this.schema,examples:[...this.schema.examples,r]},this.handler,this._subcommands,this._executionSteps)}flag(t,n){let r={...this.schema.flags,[t]:n.schema};return new e({...this.schema,flags:r,hasAction:!1},void 0,this._subcommands,this._executionSteps)}arg(t,n){ye(t,n.schema,this.schema.args);let r={name:t,schema:n.schema},i=[...this.schema.args,r];return new e({...this.schema,args:i,hasAction:!1},void 0,this._subcommands,this._executionSteps)}command(t){return new e({...this.schema,commands:[...this.schema.commands,t.schema]},this.handler,[...this._subcommands,be(t)],this._executionSteps)}action(t){return new e({...this.schema,hasAction:!0},t,this._subcommands,this._executionSteps)}};function I(e){return new F({name:e,description:void 0,aliases:[],hidden:!1,examples:[],flags:{},args:[],hasAction:!1,interactive:void 0,middleware:[],commands:[]})}function xe(e){return I(e)}function L(e,t,n=[]){let r=-1;for(let t=0;t<e.length;t++){let n=e[t];if(n===`--`){t+1<e.length&&(r=t+1);break}if(n!==void 0&&!n.startsWith(`-`)){r=t;break}}if(r===-1)return{kind:`unknown`,input:``,candidates:B(t),parentPath:n};let i=e[r];if(i===void 0)return{kind:`unknown`,input:``,candidates:B(t),parentPath:n};let a=t.get(i);if(a===void 0)return{kind:`unknown`,input:i,candidates:B(t),parentPath:n};let o=[...e.slice(0,r),...e.slice(r+1)],s=[...n,a.schema];if(a.subcommands.size>0){let e=L(o,a.subcommands,s);switch(e.kind){case`match`:return e;case`unknown`:return e.input===``?a.schema.hasAction?{kind:`match`,command:a,commandPath:s,remainingArgv:o}:{kind:`needs-subcommand`,command:a,commandPath:s}:a.schema.hasAction?{kind:`match`,command:a,commandPath:s,remainingArgv:o}:e;case`needs-subcommand`:return e;default:return e}}return{kind:`match`,command:a,commandPath:s,remainingArgv:o}}function R(e,t){let n=e.length,r=t.length,i=r+1,a=new Uint16Array(i),o=new Uint16Array(i);for(let e=0;e<=r;e++)a[e]=e;for(let i=1;i<=n;i++){o[0]=i;for(let n=1;n<=r;n++){let r=e.charAt(i-1)===t.charAt(n-1)?0:1,s=a[n]??0,c=o[n-1]??0,l=a[n-1]??0;o[n]=Math.min(s+1,c+1,l+r)}[a,o]=[o,a]}return a[r]??Math.max(n,r)}function z(e,t){let n,r=4;for(let i of t){let t=R(e,i.schema.name);t<r&&(r=t,n=i.schema.name);for(let t of i.schema.aliases){let a=R(e,t);a<r&&(r=a,n=i.schema.name)}}return r<=3?n:void 0}function B(e){let t=new Set,n=[];for(let r of e.values())t.has(r)||(t.add(r),n.push(r));return n}function Se(e,t){let n=Object.freeze({...e});return Object.freeze({hooks:n,name:t})}function V(t,n){let i=n?.width??80,a=r(t);if(a.hasSingleVisibleDefault){let r=a.visibleDefaultCommand;if(r!==void 0){let o=H(t,a.visibleCommands,a.visibleDefaultCommand,i),s=o.findIndex(e=>e.startsWith(`Usage: `)),c=[...e.f(r,{...n,binName:t.name,isDefaultHelp:!0})],l=c.shift();return s!==-1&&l!==void 0&&(o[s]=we(o[s]??``,l)),r.description!==void 0&&t.description!==void 0&&r.description===t.description&&c.shift(),o.push(...c),`${o.join(`
5
-
6
- `)}\n`}}let o=H(t,a.visibleCommands,a.visibleDefaultCommand,i),s=U(a.visibleCommands,a.visibleDefaultCommand);return o.push(s.length>0?`Run '${t.name} ${s} --help' for more information.`:`Run '${t.name} --help' for more information.`),`${o.join(`
7
-
8
- `)}\n`}function H(e,t,n,r){let i=[],a=e.version===void 0?e.name:`${e.name} v${e.version}`;i.push(a),e.description!==void 0&&i.push(e.description);let o=U(t,n);return i.push(o.length>0?`Usage: ${e.name} ${o} [options]`:`Usage: ${e.name} [options]`),t.length>0&&i.push(Ce(t,n?.name,r)),i}function U(e,t){return e.length===0&&t===void 0?``:t===void 0?`<command>`:`[command]`}function Ce(e,t,n){let r=[`Commands:`],i=0;for(let n of e){let e=n.name===t?10:0,r=n.name.length+e;r>i&&(i=r)}let a=2+i+2;for(let i of e){let e=Te(` ${i.name===t?`${i.name} (default)`:i.name}`,a),o=i.description??``;o.length===0?r.push(e.trimEnd()):r.push(`${e}${Ee(o,n,a)}`)}return r.join(`
9
- `)}function we(e,t){let n=t.startsWith(`Usage: `)?t.slice(7):t;return`${e}\n${` `.repeat(7)}${n}`}function Te(e,t){return e.length>=t?e:e+` `.repeat(t-e.length)}function Ee(e,t,n){if(e.length+n<=t)return e;let r=t-n;if(r<=0)return e;let i=e.split(` `),a=[],o=``;for(let e of i)o.length===0?o=e:o.length+1+e.length<=r?o+=` ${e}`:(a.push(o),o=e);o.length>0&&a.push(o);let s=` `.repeat(n);return a.map((e,t)=>t===0?e:`${s}${e}`).join(`
10
- `)}function W(t){let n=new Map;for(let e of t._subcommands){let t=W(e);n.set(e.schema.name,t);for(let r of e.schema.aliases)n.set(r,t)}return{schema:t.schema,subcommands:n,_execute(n,r){return e.t(t,n,r)}}}function De(e){let t=e.findIndex(e=>e.startsWith(`--config=`));if(t!==-1){let n=e[t].slice(9),r=[...e.slice(0,t),...e.slice(t+1)];return{configPath:n.length>0?n:void 0,filteredArgv:r}}let n=e.indexOf(`--config`),r=n>=0?e[n+1]:void 0;return n===-1||r===void 0?{configPath:void 0,filteredArgv:e}:{configPath:r,filteredArgv:[...e.slice(0,n),...e.slice(n+2)]}}function G(e,t,n){return{name:e.name,bin:t.binName??e.name,version:e.version,command:n}}function K(e,t,n){return{help:t,...n===void 0?{}:{meta:n},...e?.plugins===void 0?{}:{plugins:e.plugins},...e?.env===void 0?{}:{env:e.env},...e?.config===void 0?{}:{config:e.config},...e?.stdinData===void 0?{}:{stdinData:e.stdinData},...e?.prompter===void 0?{}:{prompter:e.prompter},...e?.answers===void 0?{}:{answers:e.answers},...e?.verbosity===void 0?{}:{verbosity:e.verbosity},...e?.jsonMode===void 0?{}:{jsonMode:e.jsonMode},...e?.isTTY===void 0?{}:{isTTY:e.isTTY},...e?.out===void 0?{}:{out:e.out},...e?.captured===void 0?{}:{captured:e.captured}}}function Oe(e){let t=new Map;for(let n of e){t.set(n.schema.name,n);for(let e of n.schema.aliases)t.set(e,n)}return t}function ke(t,n){if(n.includes(`--help`)||n.includes(`-h`))return!1;try{let r=e.s(t,n);return t.args.some(({name:e,schema:t})=>{let n=r.args[e];return t.stdinMode&&(n===void 0||n===`-`)})}catch(t){if(t instanceof e.m)return!1;throw t}}function Ae(e,t){let r=t.includes(`--json`)?t.filter(e=>e!==`--json`):t;if(r.includes(`--version`)||r.includes(`-V`)||r.includes(`--help`)||r.includes(`-h`))return!1;let i=r[0];if(i===`help`&&!e.schema.commands.some(e=>e.schema.name===`help`||e.schema.aliases.includes(`help`))||i===void 0&&e.schema.defaultCommand===void 0||e.schema.commands.length===0)return!1;let a=L(r,Oe(e.schema.commands)),o=e.schema.defaultCommand;switch(a.kind){case`unknown`:return o!==void 0&&a.parentPath.length===0&&(a.input===``?void 0:z(a.input,a.candidates))===void 0?ke(o.schema,r):!1;case`needs-subcommand`:return!1;case`match`:{let e=n(a.commandPath);return ke(Object.keys(e).length>0?{...a.command.schema,flags:{...e,...a.command.schema.flags}}:a.command.schema,a.remainingArgv)}}}var je=class r{schema;constructor(e){this.schema=e}version(e){return new r({...this.schema,version:e})}description(e){return new r({...this.schema,description:e})}config(e,t){return new r({...this.schema,configSettings:{appName:e,loaders:t}})}configLoader(t){if(this.schema.configSettings===void 0)throw new e.p(`.configLoader() requires .config() to be called first`,{code:`INVALID_BUILDER_STATE`,suggest:`Call .config(appName) before .configLoader()`});let n=this.schema.configSettings.loaders??[];return new r({...this.schema,configSettings:{...this.schema.configSettings,loaders:[...n,t]}})}packageJson(e){return new r({...this.schema,packageJsonSettings:{inferName:e?.inferName??!1}})}command(e){return new r({...this.schema,commands:[...this.schema.commands,W(e)]})}default(t){if(this.schema.defaultCommand!==void 0)throw new e.p(`Only one default command is allowed`,{code:`DUPLICATE_DEFAULT`,suggest:`Call .default() only once when building the CLI`});if(this.schema.commands.some(e=>e.schema.name===t.schema.name))throw new e.p(`Command '${t.schema.name}' is already registered`,{code:`DUPLICATE_COMMAND`,suggest:`Use .default() instead of .command() to register the default command`});let n=W(t);return new r({...this.schema,commands:[...this.schema.commands,n],defaultCommand:n})}plugin(e){return new r({...this.schema,plugins:[...this.schema.plugins,e]})}completions(t){if(this.schema.commands.some(e=>e.schema.name===`completions`))throw new e.p(`.completions() has already been called`,{code:`DUPLICATE_COMMAND`,suggest:`Call .completions() only once when building the CLI`});let n=this.schema,r=t,i=new Map;for(let e of C)i.set(e,e);let a=I(`completions`).alias(`completion`).description(`Generate shell completion script`).arg(`shell`,P.custom(e=>{let t=e.split(/[\\/]/),n=(t[t.length-1]??e).replace(/\.(?:exe|cmd|bat)$/i,``),r=i.get(n);if(r===void 0)throw Error(`Unknown shell '${n}'. Valid shells: ${C.join(`, `)}`);return r}).env(`SHELL`).describe(`Target shell (${C.join(`, `)})`)).action(({args:e,meta:t,out:i})=>{let a=w(t.bin===n.name?n:{...n,name:t.bin},e.shell,r);i.jsonMode?i.json({shell:e.shell,script:a}):i.log(a)});return this.command(a)}async execute(t,r){let i=t.includes(`--json`),a=i||r?.jsonMode===!0,o=i?t.filter(e=>e!==`--json`):t,s={...r?.verbosity===void 0?{}:{verbosity:r.verbosity},...a?{jsonMode:a}:{},...r?.isTTY===void 0?{}:{isTTY:r.isTTY}},c,l;r?.out===void 0?[c,l]=e.l(Object.keys(s).length>0?s:void 0):(c=r.out,l=r.captured??{stdout:[],stderr:[],activity:[]});let u={...r?.help,binName:r?.help?.binName??this.schema.name};if(this.schema.version!==void 0&&(o.includes(`--version`)||o.includes(`-V`)))return c.log(this.schema.version),q(0,l,void 0);let d=o.length>0?o[0]:void 0;if(d===`--help`||d===`-h`){let e=V(this.schema,u);return c.log(e),q(0,l,void 0)}if(d===`help`&&!this.schema.commands.some(e=>e.schema.name===`help`||e.schema.aliases.includes(`help`))){let e=o.slice(1);if(e.length===0){let e=V(this.schema,u);return c.log(e),q(0,l,void 0)}return this.execute([...e,`--help`],a?{...r,jsonMode:a}:r)}if(d===void 0&&this.schema.defaultCommand===void 0){let e=V(this.schema,u);return c.log(e),q(0,l,void 0)}if(this.schema.commands.length===0){let t=new e.p(`No commands registered`,{code:`NO_ACTION`,suggest:`Add commands via .command() before calling .run()`});return a?c.json({error:t.toJSON()}):c.error(t.message),q(1,l,t)}let f=L(o,Oe(this.schema.commands)),p=this.schema.defaultCommand,m={...r,plugins:this.schema.plugins,...a?{jsonMode:a}:{}};switch(f.kind){case`unknown`:{if(p!==void 0&&f.parentPath.length===0&&(f.input===``?void 0:z(f.input,f.candidates))===void 0){let e=K(m,u,G(this.schema,u,p.schema.name));return p._execute(o,{...e})}if(f.input===``){let t=o.find(e=>e.startsWith(`-`));if(t!==void 0){let n=new e.m(`Unknown flag ${t}`,{code:`UNKNOWN_FLAG`,suggest:`Run '${this.schema.name} --help' for available commands`});return a?c.json({error:n.toJSON()}):(c.error(n.message),c.error(`Suggestion: ${n.suggest}`)),q(2,l,n)}let n=V(this.schema,u);return c.log(n),q(0,l,void 0)}let t=z(f.input,f.candidates),n=f.parentPath.length>0?`${this.schema.name} ${f.parentPath.map(e=>e.name).join(` `)}`:this.schema.name,r=new e.m(`Unknown command: ${f.input}`,{code:`UNKNOWN_COMMAND`,suggest:t===void 0?`Run '${n} --help' for available commands`:`Did you mean '${t}'?`});return a?c.json({error:r.toJSON()}):(c.error(r.message),r.suggest!==void 0&&c.error(`Suggestion: ${r.suggest}`)),q(2,l,r)}case`needs-subcommand`:{let t=f.commandPath.slice(0,-1).map(e=>e.name),n=[this.schema.name,...t].join(` `),r={...u,binName:n},i=e.d(f.command.schema,r);return c.log(i),q(0,l,void 0)}case`match`:{let e=n(f.commandPath),t=Object.keys(e).length>0?{...f.command.schema,flags:{...e,...f.command.schema.flags}}:void 0,r=K(m,u,G(this.schema,u,f.command.schema.name));return f.command._execute(f.remainingArgv,{...r,...t===void 0?{}:{mergedSchema:t}})}}}async run(n){let i=n?.adapter??t.t(),a=this.schema.inheritName?Pe(i.argv):void 0,{configPath:o,filteredArgv:s}=De(i.argv.slice(2)),c=s.includes(`--json`)||n?.jsonMode===!0,l=s[0],u=((l===void 0?void 0:this.schema.commands.find(e=>e.schema.name===l||e.schema.aliases.includes(l)))?.schema.name??this.schema.defaultCommand?.schema.name)===`completions`,d;if(this.schema.configSettings!==void 0&&!u&&n?.config===void 0)try{let e=await j(this.schema.configSettings.appName,i,{...o===void 0?{}:{configPath:o},...this.schema.configSettings.loaders===void 0?{}:{loaders:this.schema.configSettings.loaders}});e.found&&(d=e.data)}catch(t){if(t instanceof e.p)return c?i.stdout(`${JSON.stringify({error:t.toJSON()})}\n`):(i.stderr(`Error: ${t.message}\n`),t.suggest!==void 0&&i.stderr(`Suggestion: ${t.suggest}\n`)),i.exit(t.exitCode);throw t}let f=this.schema.packageJsonSettings,p=f!==void 0&&!u?await(async()=>{let e=await E(i);if(e===null)return this;let t=this.schema,n=f.inferName?D(e):void 0;return new r({...t,...t.version===void 0&&e.version!==void 0?{version:e.version}:{},...t.description===void 0&&e.description!==void 0?{description:e.description}:{},...n===void 0?{}:{name:n}})})():this,m=a===void 0?p:new r({...p.schema,name:a}),h=n?.prompter===void 0&&i.stdinIsTTY?e.i(i.stdin,i.stderr):void 0,g=n?.stdinData===void 0&&Ae(m,s)?await i.readStdin():void 0,_={...n,...n?.env===void 0?{env:i.env}:{},...n?.isTTY===void 0?{isTTY:i.isTTY}:{},...g===void 0?{}:{stdinData:g},...h===void 0?{}:{prompter:h},...d===void 0?{}:{config:d},out:e.u({stdout:i.stdout,stderr:i.stderr,jsonMode:c,isTTY:n?.isTTY??i.isTTY,...n?.verbosity===void 0?{}:{verbosity:n.verbosity}})},v=await m.execute(s,_);for(let e of v.stdout)i.stdout(e);for(let e of v.stderr)i.stderr(e);return i.exit(v.exitCode)}};function q(e,t,n){return{exitCode:e,stdout:t.stdout,stderr:t.stderr,activity:t.activity,error:n}}const Me=new Set([`bun`,`deno`,`node`,`tsx`]);function J(e){let t=e.replace(/[\\/]+$/g,``);if(t.length===0)return;let n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`)),r=n>=0?t.slice(n+1):t;return r.length>0?r:void 0}function Ne(e){let t=e.toLowerCase().replace(/\.exe$/i,``);return Me.has(t)}function Pe(e){let t=e[0],n=e[1],r=t===void 0?void 0:J(t);if(r!==void 0&&Ne(r)){if(r===`bun`&&n===`run`){let t=e[2];return t===void 0||t.startsWith(`-`)?void 0:J(t)}return r===`deno`&&n===`run`||n===void 0||n.startsWith(`-`)?void 0:J(n)}return t===void 0?void 0:J(t)}function Fe(e){return new je({name:typeof e==`string`?e:e.name??`cli`,inheritName:typeof e==`string`?!1:e.inherit??!1,version:void 0,description:void 0,commands:[],defaultCommand:void 0,configSettings:void 0,packageJsonSettings:void 0,plugins:[]})}function Ie(e){return{includeHidden:e?.includeHidden??!0,includePrompts:e?.includePrompts??!0}}const Y=`https://json-schema.org/draft/2020-12/schema`;function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Le(e,t){let n=Ie(t),r={$schema:`https://dreamcli.kjanat.com/schemas/cli/v1.json`,name:e.name};return e.version!==void 0&&(r.version=e.version),e.description!==void 0&&(r.description=e.description),e.defaultCommand!==void 0&&(n.includeHidden||!e.defaultCommand.schema.hidden)&&(r.defaultCommand=e.defaultCommand.schema.name),r.commands=e.commands.filter(e=>n.includeHidden||!e.schema.hidden).map(e=>Re(e.schema,n)),r}function Re(e,t){let n={name:e.name};e.description!==void 0&&(n.description=e.description),e.aliases.length>0&&(n.aliases=[...e.aliases]),e.hidden&&(n.hidden=!0),e.examples.length>0&&(n.examples=e.examples.map(Ue));let r={};for(let[n,i]of Object.entries(e.flags))r[n]=ze(i,t);return n.flags=r,n.args=e.args.map(Be),n.commands=e.commands.filter(e=>t.includeHidden||!e.hidden).map(e=>Re(e,t)),n}function ze(e,t){let n={kind:e.kind,presence:e.presence};return e.presence===`defaulted`&&Z(e.defaultValue)&&(n.defaultValue=e.defaultValue),e.aliases.length>0&&(n.aliases=[...e.aliases]),e.envVar!==void 0&&(n.envVar=e.envVar),e.configPath!==void 0&&(n.configPath=e.configPath),e.description!==void 0&&(n.description=e.description),e.enumValues!==void 0&&(n.enumValues=[...e.enumValues]),e.elementSchema!==void 0&&(n.elementSchema=ze(e.elementSchema,t)),t.includePrompts&&e.prompt!==void 0&&(n.prompt=Ve(e.prompt)),e.deprecated!==void 0&&(n.deprecated=e.deprecated),e.propagate&&(n.propagate=!0),n}function Be(e){let{name:t,schema:n}=e,r={name:t,kind:n.kind,presence:n.presence};return n.variadic&&(r.variadic=!0),n.stdinMode&&(r.stdinMode=!0),n.presence===`defaulted`&&Z(n.defaultValue)&&(r.defaultValue=n.defaultValue),n.description!==void 0&&(r.description=n.description),n.envVar!==void 0&&(r.envVar=n.envVar),n.enumValues!==void 0&&(r.enumValues=[...n.enumValues]),n.deprecated!==void 0&&(r.deprecated=n.deprecated),r}function Ve(e){let t={kind:e.kind,message:e.message};switch(e.kind){case`input`:e.placeholder!==void 0&&(t.placeholder=e.placeholder);break;case`select`:e.choices!==void 0&&(t.choices=e.choices.map(He));break;case`multiselect`:e.choices!==void 0&&(t.choices=e.choices.map(He)),e.min!==void 0&&(t.min=e.min),e.max!==void 0&&(t.max=e.max);break;case`confirm`:break}return t}function He(e){let t={value:e.value};return e.label!==void 0&&(t.label=e.label),e.description!==void 0&&(t.description=e.description),t}function Ue(e){let t={command:e.command};return e.description!==void 0&&(t.description=e.description),t}function We(e,t){let n=Ie(t);if(Ge(e))return{$schema:Y,...qe(e)};let r=[];for(let t of e.commands)!n.includeHidden&&t.schema.hidden||Ke(t.schema,``,r,n);if(r.length===1)return{$schema:Y,...Je(r[0]??{})};if(r.length>0){let t=e.defaultCommand!==void 0&&(n.includeHidden||!e.defaultCommand.schema.hidden)?e.defaultCommand.schema.name:void 0;return{$schema:Y,oneOf:t===void 0?r:r.map(e=>Ye(e)===t?Je(e):e)}}return{$schema:Y,type:`object`}}function Ge(e){return`flags`in e&&`args`in e&&`middleware`in e&&`hasAction`in e}function Ke(e,t,n,r){let i=t?`${t}.${e.name}`:e.name;e.hasAction&&n.push(qe(e,i));for(let t of e.commands)!r.includeHidden&&t.hidden||Ke(t,i,n,r)}function qe(e,t){let n={},r=[];t!==void 0&&(n.command={const:t},r.push(`command`));for(let[t,i]of Object.entries(e.flags))n[t]=Xe(i),i.presence===`required`&&r.push(t);for(let t of e.args)n[t.name]=Ze(t.schema),t.schema.presence===`required`&&r.push(t.name);let i={type:`object`,properties:n,additionalProperties:!1};return r.length>0&&(i.required=r),i}function Je(e){let t=e.properties,n=e.required,r=X(t)?{...t}:void 0,i=Array.isArray(n)?n.filter(e=>typeof e==`string`):void 0;r!==void 0&&delete r.command;let a=i?.filter(e=>e!==`command`),o={...e};return r!==void 0&&(o.properties=r),a!==void 0&&a.length>0?o.required=a:delete o.required,o}function Ye(e){let t=e.properties;if(!X(t))return;let n=t.command;return X(n)&&typeof n.const==`string`?n.const:void 0}function Xe(e){let t={};switch(e.kind){case`string`:t.type=`string`;break;case`number`:t.type=`number`;break;case`boolean`:t.type=`boolean`;break;case`enum`:t.type=`string`,e.enumValues!==void 0&&(t.enum=[...e.enumValues]);break;case`array`:t.type=`array`,e.elementSchema!==void 0&&(t.items=Xe(e.elementSchema));break;case`custom`:break}return e.description!==void 0&&(t.description=e.description),e.presence===`defaulted`&&Z(e.defaultValue)&&(t.default=e.defaultValue),e.deprecated!==void 0&&(t.deprecated=!0),t}function Ze(e){let t=Qe(e),n=e.variadic?{type:`array`,items:t}:{...t};return e.description!==void 0&&(n.description=e.description),e.presence===`defaulted`&&Z(e.defaultValue)&&(n.default=e.defaultValue),e.deprecated!==void 0&&(n.deprecated=!0),n}function Qe(e){switch(e.kind){case`string`:return{type:`string`};case`number`:return{type:`number`};case`enum`:{let t={type:`string`};return e.enumValues!==void 0&&(t.enum=[...e.enumValues]),t}case`custom`:return{}}}function Z(e,t=new WeakSet){if(e===void 0)return!1;if(e===null)return!0;let n=typeof e;if(n===`string`||n===`boolean`)return!0;if(n===`number`)return Number.isFinite(e);if(n===`function`||n===`symbol`||n===`bigint`)return!1;if(Array.isArray(e)){if(t.has(e))return!1;t.add(e);try{return e.every(e=>Z(e,t))}finally{t.delete(e)}}if(n===`object`){let n=e;if(!$e(n)||t.has(n))return!1;t.add(n);try{return Object.values(n).every(e=>Z(e,t))}finally{t.delete(n)}}return!1}function $e(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Q(e,t){return{kind:e,presence:`optional`,defaultValue:void 0,aliases:[],envVar:void 0,configPath:void 0,description:void 0,enumValues:void 0,elementSchema:void 0,prompt:void 0,parseFn:void 0,deprecated:void 0,propagate:!1,...t}}var $=class e{schema;constructor(e){this.schema=e}default(t){return new e({...this.schema,presence:`defaulted`,defaultValue:t})}required(){return new e({...this.schema,presence:`required`})}alias(t){return new e({...this.schema,aliases:[...this.schema.aliases,t]})}env(t){return new e({...this.schema,envVar:t})}config(t){return new e({...this.schema,configPath:t})}describe(t){return new e({...this.schema,description:t})}prompt(t){return new e({...this.schema,prompt:t})}deprecated(t){return new e({...this.schema,deprecated:t??!0})}propagate(){return new e({...this.schema,propagate:!0})}};const et={string(){return new $(Q(`string`))},number(){return new $(Q(`number`))},boolean(){return new $(Q(`boolean`,{presence:`defaulted`,defaultValue:!1}))},enum(e){return new $(Q(`enum`,{enumValues:e}))},array(e){return new $(Q(`array`,{elementSchema:e.schema}))},custom(e){return new $(Q(`custom`,{parseFn:e}))}};function tt(e){return{_handler:e}}exports.ArgBuilder=N,exports.CLIBuilder=je,exports.CLIError=e.p,exports.CommandBuilder=F,exports.FlagBuilder=$,exports.ParseError=e.m,exports.SHELLS=C,exports.ValidationError=e.h,exports.arg=P,exports.buildConfigSearchPaths=A,exports.cli=Fe,exports.command=I,exports.configFormat=ve,exports.createArgSchema=M,exports.createOutput=e.u,exports.createSchema=Q,exports.createTerminalPrompter=e.i,exports.discoverConfig=j,exports.discoverPackageJson=E,exports.flag=et,exports.formatHelp=e.d,exports.generateBashCompletion=d,exports.generateCompletion=w,exports.generateInputSchema=We,exports.generateSchema=Le,exports.generateZshCompletion=ie,exports.group=xe,exports.inferCliName=D,exports.isCLIError=e.g,exports.isParseError=e._,exports.isValidationError=e.v,exports.middleware=tt,exports.parse=e.s,exports.plugin=Se,exports.resolve=e.n,exports.resolvePromptConfig=e.o,exports.tokenize=e.c;