@kjanat/dreamcli 3.0.0-rc.1 → 3.0.0-rc.10

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 (194) hide show
  1. package/CHANGELOG.md +217 -1
  2. package/dist/core/cli/dispatch.d.mts +6 -5
  3. package/dist/core/cli/dispatch.mjs +205 -1
  4. package/dist/core/cli/help-links.d.mts +0 -1
  5. package/dist/core/cli/help-links.mjs +41 -1
  6. package/dist/core/cli/index.d.mts +81 -8
  7. package/dist/core/cli/index.mjs +945 -1
  8. package/dist/core/cli/planner.d.mts +5 -1
  9. package/dist/core/cli/planner.mjs +300 -1
  10. package/dist/core/cli/plugin.d.mts +1 -1
  11. package/dist/core/cli/plugin.mjs +41 -1
  12. package/dist/core/cli/propagate.d.mts +1 -1
  13. package/dist/core/cli/propagate.mjs +57 -1
  14. package/dist/core/cli/root-help.d.mts +2 -1
  15. package/dist/core/cli/root-help.mjs +226 -4
  16. package/dist/core/cli/root-surface.d.mts +12 -1
  17. package/dist/core/cli/root-surface.mjs +28 -1
  18. package/dist/core/cli/runtime-preflight.d.mts +14 -2
  19. package/dist/core/cli/runtime-preflight.mjs +169 -1
  20. package/dist/core/completion/index.d.mts +0 -1
  21. package/dist/core/completion/index.mjs +90 -1
  22. package/dist/core/completion/shells/bash.d.mts +0 -1
  23. package/dist/core/completion/shells/bash.mjs +308 -3
  24. package/dist/core/completion/shells/fish.d.mts +0 -1
  25. package/dist/core/completion/shells/fish.mjs +162 -2
  26. package/dist/core/completion/shells/powershell.d.mts +0 -1
  27. package/dist/core/completion/shells/powershell.mjs +358 -2
  28. package/dist/core/completion/shells/shared.d.mts +13 -2
  29. package/dist/core/completion/shells/shared.mjs +176 -1
  30. package/dist/core/completion/shells/zsh.d.mts +0 -1
  31. package/dist/core/completion/shells/zsh.mjs +251 -2
  32. package/dist/core/config/index.d.mts +2 -3
  33. package/dist/core/config/index.mjs +246 -1
  34. package/dist/core/config/package-json.d.mts +27 -4
  35. package/dist/core/config/package-json.mjs +386 -3
  36. package/dist/core/errors/index.d.mts +3 -3
  37. package/dist/core/errors/index.mjs +87 -1
  38. package/dist/core/execution/index.d.mts +0 -1
  39. package/dist/core/execution/index.mjs +201 -1
  40. package/dist/core/help/ansi.d.mts +11 -5
  41. package/dist/core/help/ansi.mjs +121 -2
  42. package/dist/core/help/index.d.mts +22 -3
  43. package/dist/core/help/index.mjs +341 -7
  44. package/dist/core/help/theme.d.mts +68 -0
  45. package/dist/core/help/theme.mjs +46 -0
  46. package/dist/core/json-schema/index.d.mts +15 -2
  47. package/dist/core/json-schema/index.mjs +536 -12
  48. package/dist/core/json-schema/meta-descriptions.generated.d.mts +55 -38
  49. package/dist/core/json-schema/meta-descriptions.generated.mjs +102 -28
  50. package/dist/core/output/activity.d.mts +0 -1
  51. package/dist/core/output/activity.mjs +452 -1
  52. package/dist/core/output/bind.mjs +56 -1
  53. package/dist/core/output/contracts.d.mts +4 -5
  54. package/dist/core/output/contracts.mjs +57 -1
  55. package/dist/core/output/display-value.mjs +32 -1
  56. package/dist/core/output/index.d.mts +21 -1
  57. package/dist/core/output/index.mjs +442 -2
  58. package/dist/core/output/renderers.d.mts +0 -1
  59. package/dist/core/output/renderers.mjs +46 -1
  60. package/dist/core/output/writer.mjs +12 -1
  61. package/dist/core/parse/index.d.mts +40 -7
  62. package/dist/core/parse/index.mjs +727 -1
  63. package/dist/core/prompt/index.d.mts +1 -1
  64. package/dist/core/prompt/index.mjs +348 -6
  65. package/dist/core/resolve/args.d.mts +1 -1
  66. package/dist/core/resolve/args.mjs +105 -1
  67. package/dist/core/resolve/coerce.d.mts +1 -1
  68. package/dist/core/resolve/coerce.mjs +336 -1
  69. package/dist/core/resolve/config.mjs +19 -1
  70. package/dist/core/resolve/contracts.d.mts +9 -4
  71. package/dist/core/resolve/errors.d.mts +0 -1
  72. package/dist/core/resolve/errors.mjs +140 -2
  73. package/dist/core/resolve/flags.d.mts +7 -2
  74. package/dist/core/resolve/flags.mjs +251 -1
  75. package/dist/core/resolve/index.d.mts +2 -2
  76. package/dist/core/resolve/index.mjs +85 -1
  77. package/dist/core/resolve/property.d.mts +4 -2
  78. package/dist/core/resolve/property.mjs +53 -1
  79. package/dist/core/schema/activity.d.mts +31 -11
  80. package/dist/core/schema/arg.d.mts +3 -4
  81. package/dist/core/schema/arg.mjs +463 -1
  82. package/dist/core/schema/command.d.mts +26 -6
  83. package/dist/core/schema/command.mjs +726 -1
  84. package/dist/core/schema/flag.d.mts +485 -19
  85. package/dist/core/schema/flag.mjs +705 -1
  86. package/dist/core/schema/index.d.mts +4 -2
  87. package/dist/core/schema/middleware.d.mts +4 -3
  88. package/dist/core/schema/middleware.mjs +41 -1
  89. package/dist/core/schema/number-constraints.mjs +60 -1
  90. package/dist/core/schema/prompt.d.mts +6 -3
  91. package/dist/core/schema/run.d.mts +20 -1
  92. package/dist/core/schema/string-constraints.d.mts +97 -0
  93. package/dist/core/schema/string-constraints.mjs +69 -0
  94. package/dist/core/schema/value-parsers.d.mts +78 -0
  95. package/dist/core/schema/value-parsers.mjs +142 -0
  96. package/dist/core/schema-dsl/runtime.mjs +271 -2
  97. package/dist/core/schema-dsl/to-json-schema.d.mts +0 -1
  98. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  99. package/dist/core/testkit/index.d.mts +0 -31
  100. package/dist/core/testkit/index.mjs +83 -1
  101. package/dist/index.d.mts +11 -6
  102. package/dist/index.mjs +22 -1
  103. package/dist/runtime/adapter.d.mts +38 -2
  104. package/dist/runtime/adapter.mjs +87 -1
  105. package/dist/runtime/auto.d.mts +2 -3
  106. package/dist/runtime/auto.mjs +45 -1
  107. package/dist/runtime/deno.d.mts +24 -5
  108. package/dist/runtime/deno.mjs +262 -2
  109. package/dist/runtime/detect.mjs +45 -1
  110. package/dist/runtime/index.d.mts +3 -4
  111. package/dist/runtime/node.d.mts +8 -2
  112. package/dist/runtime/node.mjs +220 -2
  113. package/dist/runtime/paths.mjs +48 -1
  114. package/dist/runtime.d.mts +4 -4
  115. package/dist/runtime.mjs +6 -1
  116. package/dist/strings.mjs +22 -1
  117. package/dist/testkit.d.mts +1 -0
  118. package/dist/testkit.mjs +5 -1
  119. package/dist/version.d.mts +7 -3
  120. package/dist/version.mjs +7 -1
  121. package/dreamcli.schema.json +36 -7
  122. package/package.json +45 -42
  123. package/dist/runtime/bun.d.mts +0 -28
  124. package/dist/runtime/bun.mjs +0 -1
  125. package/src/core/cli/dispatch.ts +0 -355
  126. package/src/core/cli/help-links.ts +0 -82
  127. package/src/core/cli/index.ts +0 -1614
  128. package/src/core/cli/planner.ts +0 -656
  129. package/src/core/cli/plugin.ts +0 -117
  130. package/src/core/cli/propagate.ts +0 -97
  131. package/src/core/cli/root-help.ts +0 -342
  132. package/src/core/cli/root-surface.ts +0 -87
  133. package/src/core/cli/runtime-preflight.ts +0 -456
  134. package/src/core/completion/index.ts +0 -138
  135. package/src/core/completion/shells/bash.ts +0 -459
  136. package/src/core/completion/shells/fish.ts +0 -259
  137. package/src/core/completion/shells/powershell.ts +0 -439
  138. package/src/core/completion/shells/shared.ts +0 -310
  139. package/src/core/completion/shells/zsh.ts +0 -381
  140. package/src/core/config/index.ts +0 -417
  141. package/src/core/config/package-json.ts +0 -560
  142. package/src/core/errors/index.ts +0 -193
  143. package/src/core/execution/index.ts +0 -265
  144. package/src/core/help/ansi.ts +0 -144
  145. package/src/core/help/index.ts +0 -563
  146. package/src/core/json-schema/index.ts +0 -910
  147. package/src/core/json-schema/meta-descriptions.generated.ts +0 -202
  148. package/src/core/output/activity.ts +0 -575
  149. package/src/core/output/bind.ts +0 -59
  150. package/src/core/output/contracts.ts +0 -194
  151. package/src/core/output/display-value.ts +0 -48
  152. package/src/core/output/index.ts +0 -704
  153. package/src/core/output/renderers.ts +0 -125
  154. package/src/core/output/writer.ts +0 -46
  155. package/src/core/parse/index.ts +0 -742
  156. package/src/core/prompt/index.ts +0 -623
  157. package/src/core/resolve/args.ts +0 -144
  158. package/src/core/resolve/coerce.ts +0 -500
  159. package/src/core/resolve/config.ts +0 -26
  160. package/src/core/resolve/contracts.ts +0 -135
  161. package/src/core/resolve/errors.ts +0 -227
  162. package/src/core/resolve/flags.ts +0 -269
  163. package/src/core/resolve/index.ts +0 -108
  164. package/src/core/resolve/property.ts +0 -99
  165. package/src/core/schema/activity.ts +0 -240
  166. package/src/core/schema/arg.ts +0 -841
  167. package/src/core/schema/command.ts +0 -1500
  168. package/src/core/schema/flag.ts +0 -917
  169. package/src/core/schema/index.ts +0 -96
  170. package/src/core/schema/middleware.ts +0 -171
  171. package/src/core/schema/number-constraints.ts +0 -153
  172. package/src/core/schema/prompt.ts +0 -171
  173. package/src/core/schema/run.ts +0 -198
  174. package/src/core/schema-dsl/index.ts +0 -109
  175. package/src/core/schema-dsl/parse.ts +0 -262
  176. package/src/core/schema-dsl/runtime.ts +0 -609
  177. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  178. package/src/core/testkit/index.ts +0 -147
  179. package/src/index.ts +0 -181
  180. package/src/runtime/adapter.ts +0 -303
  181. package/src/runtime/auto.ts +0 -86
  182. package/src/runtime/bun.ts +0 -48
  183. package/src/runtime/deno.ts +0 -367
  184. package/src/runtime/detect.ts +0 -105
  185. package/src/runtime/index.ts +0 -21
  186. package/src/runtime/node-builtins.d.ts +0 -27
  187. package/src/runtime/node.ts +0 -289
  188. package/src/runtime/paths.ts +0 -64
  189. package/src/runtime/support.ts +0 -77
  190. package/src/runtime.ts +0 -31
  191. package/src/schema.ts +0 -16
  192. package/src/strings.ts +0 -34
  193. package/src/testkit.ts +0 -25
  194. package/src/version.ts +0 -20
@@ -1 +1,87 @@
1
- var e=class extends Error{name=`ExitError`;code;constructor(e){super(`Process exited with code ${e}`),this.code=e}};const t=()=>{},n=()=>Promise.resolve(null),r=()=>Promise.resolve(null);function i(i){let a=i?.stdinIsTTY??!1,o=a?void 0:i?.stdinData;return{argv:i?.argv??[`node`,`test`],env:i?.env??{},cwd:i?.cwd??`/test`,stdout:i?.stdout??t,stderr:i?.stderr??t,stdin:i?.stdin??n,readStdin:()=>{if(o===void 0)return Promise.resolve(null);let e=o;return o=void 0,Promise.resolve(e)},isTTY:i?.isTTY??!1,stdinIsTTY:a,exit:i?.exit??(t=>{throw new e(t)}),readFile:i?.readFile??r,homedir:i?.homedir??`/home/test`,configDir:i?.configDir??`/home/test/.config`}}export{e as ExitError,i as createTestAdapter};
1
+ //#region src/runtime/adapter.ts
2
+ /**
3
+ * Error thrown by adapter implementations that model process exit as an
4
+ * exception instead of terminating immediately.
5
+ *
6
+ * Runtime and CLI dispatch layers can catch this to perform real process
7
+ * termination, while tests can assert on exit codes without killing the
8
+ * runner:
9
+ *
10
+ * ```ts
11
+ * try {
12
+ * await cli.run({ adapter: createTestAdapter() });
13
+ * } catch (e) {
14
+ * if (e instanceof ExitError) expect(e.code).toBe(0);
15
+ * }
16
+ * ```
17
+ */
18
+ var ExitError = class extends Error {
19
+ /** Error name — always `'ExitError'` for `instanceof` checks. */
20
+ name = "ExitError";
21
+ /** The exit code passed to `exit()`. */
22
+ code;
23
+ /** Create an ExitError for the given process exit code. */
24
+ constructor(code) {
25
+ super(`Process exited with code ${code}`);
26
+ this.code = code;
27
+ }
28
+ };
29
+ /** Noop writer — silently discards output. */
30
+ const noopWrite = () => {};
31
+ /** Noop reader — returns `null` (EOF) immediately. */
32
+ const eofRead = () => Promise.resolve(null);
33
+ /** Noop file reader — returns `null` (not found) for all paths. */
34
+ const noopReadFile = () => Promise.resolve(null);
35
+ /** Noop stat — reports `null` (nothing exists) for all paths. */
36
+ const noopStat = () => Promise.resolve(null);
37
+ /**
38
+ * Create a test runtime adapter with injectable process state.
39
+ *
40
+ * Use this in `@kjanat/dreamcli/testkit` tests when you need to simulate argv,
41
+ * environment variables, TTY state, stdin, or config-file reads without
42
+ * touching the host process.
43
+ *
44
+ * @param options - Optional overrides for any adapter field.
45
+ * @returns A {@linkcode RuntimeAdapter} suitable for test scenarios.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const adapter = createTestAdapter({
50
+ * argv: ['node', 'cli.js', 'deploy', '--force'],
51
+ * env: { DEPLOY_REGION: 'us' },
52
+ * });
53
+ *
54
+ * const result = await cli('mycli').run({ adapter });
55
+ * ```
56
+ */
57
+ function createTestAdapter(options) {
58
+ const stdinIsTTY = options?.stdinIsTTY ?? false;
59
+ let stdinData = !stdinIsTTY ? options?.stdinData : void 0;
60
+ return {
61
+ argv: options?.argv ?? ["node", "test"],
62
+ env: options?.env ?? {},
63
+ cwd: options?.cwd ?? "/test",
64
+ stdout: options?.stdout ?? noopWrite,
65
+ stderr: options?.stderr ?? noopWrite,
66
+ stdin: options?.stdin ?? eofRead,
67
+ readStdin: () => {
68
+ if (stdinData === void 0) return Promise.resolve(null);
69
+ const result = stdinData;
70
+ stdinData = void 0;
71
+ return Promise.resolve(result);
72
+ },
73
+ isTTY: options?.isTTY ?? false,
74
+ stdinIsTTY,
75
+ getTerminalSize: () => options?.terminalSize,
76
+ onTerminalResize: (listener) => options?.onTerminalResize?.(listener),
77
+ exit: options?.exit ?? ((code) => {
78
+ throw new ExitError(code);
79
+ }),
80
+ readFile: options?.readFile ?? noopReadFile,
81
+ stat: options?.stat ?? noopStat,
82
+ homedir: options?.homedir ?? "/home/test",
83
+ configDir: options?.configDir ?? "/home/test/.config"
84
+ };
85
+ }
86
+ //#endregion
87
+ export { ExitError, createTestAdapter };
@@ -1,13 +1,12 @@
1
1
  import { RuntimeAdapter } from "./adapter.mjs";
2
2
  import { GlobalForDetect } from "./detect.mjs";
3
-
4
3
  //#region src/runtime/auto.d.ts
5
4
  /**
6
5
  * Create a runtime adapter for the current environment.
7
6
  *
8
7
  * Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
9
- * Unknown runtimes fall back to the Node adapter because most JS runtimes
10
- * expose a Node-compatible `process` global.
8
+ * Only Deno needs a distinct adapter; Bun, Node, and unknown runtimes all use
9
+ * the Node adapter because they expose a Node-compatible `process` global.
11
10
  *
12
11
  * @param globals - Override `globalThis` for testing. Production callers
13
12
  * should omit this parameter.
@@ -1 +1,45 @@
1
- import{createNodeAdapter as e}from"./node.mjs";import{createBunAdapter as t}from"./bun.mjs";import{createDenoAdapter as n}from"./deno.mjs";import{detectRuntime as r}from"./detect.mjs";function i(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 a(e){let t=e.Deno;return i(t)?t:void 0}function o(i){let o=i??globalThis,s=r(o);switch(s){case`bun`:return t();case`deno`:return n(a(o));case`node`:case`unknown`:return e();default:return s}}export{o as createAdapter};
1
+ import { createDenoAdapter } from "./deno.mjs";
2
+ import { detectRuntime } from "./detect.mjs";
3
+ import { createNodeAdapter } from "./node.mjs";
4
+ //#region src/runtime/auto.ts
5
+ function isDenoNamespace(value) {
6
+ if (typeof value !== "object" || value === null) return false;
7
+ const candidate = value;
8
+ return Array.isArray(candidate.args) && typeof candidate.cwd === "function" && typeof candidate.exit === "function" && typeof candidate.readTextFile === "function" && typeof candidate.env?.get === "function" && typeof candidate.env.toObject === "function" && typeof candidate.stdout?.writeSync === "function" && typeof candidate.stdout.isTerminal === "function" && typeof candidate.stderr?.writeSync === "function" && typeof candidate.stdin?.isTerminal === "function" && typeof candidate.stdin?.readable?.getReader === "function";
9
+ }
10
+ function getInjectedDenoNamespace(globals) {
11
+ const candidate = globals.Deno;
12
+ return isDenoNamespace(candidate) ? candidate : void 0;
13
+ }
14
+ /**
15
+ * Create a runtime adapter for the current environment.
16
+ *
17
+ * Detection order follows {@link detectRuntime}: Bun → Deno → Node → unknown.
18
+ * Only Deno needs a distinct adapter; Bun, Node, and unknown runtimes all use
19
+ * the Node adapter because they expose a Node-compatible `process` global.
20
+ *
21
+ * @param globals - Override `globalThis` for testing. Production callers
22
+ * should omit this parameter.
23
+ * @returns A {@linkcode RuntimeAdapter} for the detected runtime.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { cli } from '@kjanat/dreamcli';
28
+ *
29
+ * // Auto-detects Node/Bun/Deno and creates the right adapter
30
+ * cli('mycli').run(); // uses createAdapter() internally
31
+ * ```
32
+ */
33
+ function createAdapter(globals) {
34
+ const runtimeGlobals = globals ?? globalThis;
35
+ const runtime = detectRuntime(runtimeGlobals);
36
+ switch (runtime) {
37
+ case "deno": return createDenoAdapter(getInjectedDenoNamespace(runtimeGlobals));
38
+ case "bun":
39
+ case "node":
40
+ case "unknown": return createNodeAdapter();
41
+ default: return runtime;
42
+ }
43
+ }
44
+ //#endregion
45
+ export { createAdapter };
@@ -1,5 +1,4 @@
1
1
  import { RuntimeAdapter } from "./adapter.mjs";
2
-
3
2
  //#region src/runtime/deno.d.ts
4
3
  /**
5
4
  * Minimal subset of the Deno namespace needed by the adapter.
@@ -24,29 +23,49 @@ interface DenoNamespace {
24
23
  readonly args: readonly string[];
25
24
  /** Environment variable access (requires `--allow-env`). */
26
25
  readonly env: {
27
- /** Get a single env var. Returns `undefined` if unset or permission denied. */get(key: string): string | undefined; /** Get all env vars as a plain object. Throws on permission denied. */
26
+ /** Get a single env var. Returns `undefined` if unset or permission denied. */
27
+ get(key: string): string | undefined;
28
+ /** Get all env vars as a plain object. Throws on permission denied. */
28
29
  toObject(): Record<string, string>;
29
30
  };
30
31
  /** Current working directory (may throw if `--allow-read` is denied for cwd). */
31
32
  cwd(): string;
32
33
  /** Standard output — synchronous byte writer with TTY detection. */
33
34
  readonly stdout: {
34
- /** Write raw bytes to stdout synchronously. */writeSync(p: Uint8Array): number; /** Whether stdout is connected to a TTY. */
35
+ /** Write raw bytes to stdout synchronously. */
36
+ writeSync(p: Uint8Array): number;
37
+ /** Whether stdout is connected to a TTY. */
35
38
  isTerminal(): boolean;
36
39
  };
40
+ /** Current console dimensions. */
41
+ consoleSize?(): {
42
+ readonly columns: number;
43
+ readonly rows: number;
44
+ };
45
+ /** Register a native signal listener. */
46
+ addSignalListener?(signal: 'SIGWINCH', listener: () => void): void;
47
+ /** Remove a native signal listener. */
48
+ removeSignalListener?(signal: 'SIGWINCH', listener: () => void): void;
37
49
  /** Standard error — synchronous byte writer. */
38
50
  readonly stderr: {
39
- /** Write raw bytes to stderr synchronously. */writeSync(p: Uint8Array): number;
51
+ /** Write raw bytes to stderr synchronously. */
52
+ writeSync(p: Uint8Array): number;
40
53
  };
41
54
  /** Standard input — TTY detection and readable byte stream. */
42
55
  readonly stdin: {
43
- /** Whether stdin is connected to a TTY. */isTerminal(): boolean; /** Readable stream for stdin bytes. */
56
+ /** Whether stdin is connected to a TTY. */
57
+ isTerminal(): boolean;
58
+ /** Readable stream for stdin bytes. */
44
59
  readonly readable: ReadableStream<Uint8Array>;
45
60
  };
46
61
  /** Exit the process with the given code. */
47
62
  exit(code: number): never;
48
63
  /** Read a file as UTF-8 text (requires `--allow-read`). */
49
64
  readTextFile(path: string): Promise<string>;
65
+ /** Probe a filesystem path (requires `--allow-read`). */
66
+ stat(path: string): Promise<{
67
+ readonly isDirectory: boolean;
68
+ }>;
50
69
  }
51
70
  /**
52
71
  * Create a runtime adapter backed by the Deno namespace.
@@ -1,2 +1,262 @@
1
- import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";function n(e,t){if(typeof e!=`object`||!e||!(`name`in e))return!1;let n=e;return typeof n.name==`string`&&n.name===t}function r(e){try{return e.env.toObject()}catch(e){if(n(e,`PermissionDenied`))return{};throw e}}function i(e){try{return e.cwd()}catch(e){if(n(e,`PermissionDenied`))return`/`;throw e}}function a(e){let t=e??o(),a=new TextEncoder,d=[`deno`,`run`,...t.args],f=r(t),p=i(t),m=e=>{t.stdout.writeSync(a.encode(e))},h=e=>{t.stderr.writeSync(a.encode(e))},g=c(t),_=async e=>{try{return await t.readTextFile(e)}catch(e){if(n(e,`NotFound`)||n(e,`PermissionDenied`))return null;throw e}},v=l(f,t.build.os===`windows`),y=u(f,v,t.build.os===`windows`),b=t.stdin.isTerminal();return{argv:d,env:f,cwd:p,stdout:m,stderr:h,stdin:g,readStdin:()=>s(t,b),isTTY:t.stdout.isTerminal(),stdinIsTTY:b,exit:e=>t.exit(e),readFile:_,homedir:v,configDir:y}}function o(){return globalThis.Deno}async function s(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(``)}function c(e){let t=new TextDecoder,n=``,r=!1;return async()=>{let i=e.stdin.readable.getReader();try{for(;;){let e=n.indexOf(`
2
- `);if(e!==-1){let t=n.slice(0,e).replace(/\r$/,``);return n=n.slice(e+1),t}if(r){if(n.length===0)return null;let e=n;return n=``,e}let{value:a,done:o}=await i.read();if(o){n+=t.decode(),r=!0;continue}n+=t.decode(a,{stream:!0})}}finally{i.releaseLock()}}}function l(e,n){return t(e,n)}function u(t,n,r){return e(t,r,n)}export{a as createDenoAdapter};
1
+ import { resolveConfigDirectory, resolveHomeDirectory } from "./paths.mjs";
2
+ //#region src/runtime/deno.ts
3
+ /**
4
+ * Detect whether an unknown thrown value is a Deno error by name.
5
+ *
6
+ * @internal
7
+ */
8
+ function isDenoErrorNamed(err, name) {
9
+ if (typeof err !== "object" || err === null || !("name" in err)) return false;
10
+ const candidate = err;
11
+ return typeof candidate.name === "string" && candidate.name === name;
12
+ }
13
+ /**
14
+ * Safely read all environment variables. Returns empty object if
15
+ * `--allow-env` permission is not granted.
16
+ *
17
+ * @internal
18
+ */
19
+ function safeEnvToObject(deno) {
20
+ try {
21
+ return deno.env.toObject();
22
+ } catch (err) {
23
+ if (isDenoErrorNamed(err, "PermissionDenied")) return {};
24
+ throw err;
25
+ }
26
+ }
27
+ /**
28
+ * Safely get the current working directory. Returns `/` if the cwd is
29
+ * inaccessible due to missing permissions.
30
+ *
31
+ * @internal
32
+ */
33
+ function safeCwd(deno) {
34
+ try {
35
+ return deno.cwd();
36
+ } catch (err) {
37
+ if (isDenoErrorNamed(err, "PermissionDenied")) return "/";
38
+ throw err;
39
+ }
40
+ }
41
+ /**
42
+ * Create a runtime adapter backed by the Deno namespace.
43
+ *
44
+ * Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based
45
+ * I/O into the {@linkcode WriteFn}/{@linkcode ReadFn} functions expected by the framework.
46
+ *
47
+ * Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`.
48
+ * The adapter prepends synthetic entries (`['deno', 'run']`) so the argv
49
+ * shape matches the {@linkcode RuntimeAdapter} contract (binary + script + user args).
50
+ *
51
+ * @param ns - Override the Deno namespace (useful for testing the adapter itself).
52
+ * @returns A {@linkcode RuntimeAdapter} backed by Deno's namespace APIs.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { cli } from '@kjanat/dreamcli';
57
+ * import { createDenoAdapter } from '@kjanat/dreamcli/runtime';
58
+ *
59
+ * cli('mycli')
60
+ * .command(deploy)
61
+ * .run({ adapter: createDenoAdapter() });
62
+ * ```
63
+ */
64
+ function createDenoAdapter(ns) {
65
+ const d = ns ?? getDenoNamespace();
66
+ const encoder = new TextEncoder();
67
+ const argv = [
68
+ "deno",
69
+ "run",
70
+ ...d.args
71
+ ];
72
+ const env = safeEnvToObject(d);
73
+ const cwd = safeCwd(d);
74
+ const stdoutWrite = (data) => {
75
+ d.stdout.writeSync(encoder.encode(data));
76
+ };
77
+ const stderrWrite = (data) => {
78
+ d.stderr.writeSync(encoder.encode(data));
79
+ };
80
+ const stdinRead = createDenoReadLine(d);
81
+ const readFile = async (path) => {
82
+ try {
83
+ return await d.readTextFile(path);
84
+ } catch (err) {
85
+ if (isDenoErrorNamed(err, "NotFound")) return null;
86
+ if (isDenoErrorNamed(err, "PermissionDenied")) return null;
87
+ throw err;
88
+ }
89
+ };
90
+ const stat = async (path) => {
91
+ try {
92
+ return (await d.stat(path)).isDirectory ? "directory" : "file";
93
+ } catch (err) {
94
+ if (isDenoErrorNamed(err, "NotFound")) return null;
95
+ throw err;
96
+ }
97
+ };
98
+ const homedir = resolveDenoHomedir(env, d.build.os === "windows");
99
+ const configDir = resolveDenoConfigDir(env, homedir, d.build.os === "windows");
100
+ const stdinIsTTY = d.stdin.isTerminal();
101
+ return {
102
+ argv,
103
+ env,
104
+ cwd,
105
+ stdout: stdoutWrite,
106
+ stderr: stderrWrite,
107
+ stdin: stdinRead,
108
+ readStdin: () => readDenoStdinAll(d, stdinIsTTY),
109
+ isTTY: d.stdout.isTerminal(),
110
+ stdinIsTTY,
111
+ getTerminalSize: () => readDenoTerminalSize(d),
112
+ onTerminalResize: (listener) => onDenoTerminalResize(d, listener),
113
+ exit: (code) => d.exit(code),
114
+ readFile,
115
+ stat,
116
+ homedir,
117
+ configDir
118
+ };
119
+ }
120
+ /** Normalize terminal dimensions and discard unusable values. @internal */
121
+ function normalizeTerminalSize(columns, rows) {
122
+ if (columns === void 0 || rows === void 0) return void 0;
123
+ if (!Number.isFinite(columns) || !Number.isFinite(rows)) return void 0;
124
+ if (columns <= 0 || rows <= 0) return void 0;
125
+ return {
126
+ columns,
127
+ rows
128
+ };
129
+ }
130
+ /** Read native Deno terminal dimensions. @internal */
131
+ function readDenoTerminalSize(deno) {
132
+ if (!deno.stdout.isTerminal() || deno.consoleSize === void 0) return void 0;
133
+ try {
134
+ const size = deno.consoleSize();
135
+ return normalizeTerminalSize(size.columns, size.rows);
136
+ } catch {
137
+ return;
138
+ }
139
+ }
140
+ /** Subscribe to native Deno resize signals where SIGWINCH exists. @internal */
141
+ function onDenoTerminalResize(deno, listener) {
142
+ if (!deno.stdout.isTerminal()) return void 0;
143
+ if (deno.build.os === "windows") return void 0;
144
+ if (deno.addSignalListener === void 0 || deno.removeSignalListener === void 0) return;
145
+ try {
146
+ deno.addSignalListener("SIGWINCH", listener);
147
+ } catch {
148
+ return;
149
+ }
150
+ return () => {
151
+ deno.removeSignalListener?.("SIGWINCH", listener);
152
+ };
153
+ }
154
+ /**
155
+ * Access the global `Deno` namespace.
156
+ *
157
+ * Cast through `unknown` to avoid TypeScript errors when Deno types
158
+ * aren't installed. Safe because this adapter is only used on Deno
159
+ * where `globalThis.Deno` is always defined.
160
+ *
161
+ * @internal
162
+ */
163
+ function getDenoNamespace() {
164
+ return globalThis.Deno;
165
+ }
166
+ /**
167
+ * Read all of stdin as a single string (for piped data).
168
+ *
169
+ * Returns `null` immediately if stdin is a TTY — the user is typing
170
+ * interactively, so there's no piped data to consume. When stdin is
171
+ * piped, collects all chunks via the `ReadableStream` until EOF and
172
+ * returns the decoded string, which may be empty for an empty pipe.
173
+ *
174
+ * @internal
175
+ */
176
+ async function readDenoStdinAll(deno, stdinIsTTY) {
177
+ if (stdinIsTTY) return null;
178
+ const reader = deno.stdin.readable.getReader();
179
+ const decoder = new TextDecoder();
180
+ const chunks = [];
181
+ try {
182
+ for (;;) {
183
+ const { value, done } = await reader.read();
184
+ if (done) {
185
+ chunks.push(decoder.decode());
186
+ break;
187
+ }
188
+ chunks.push(decoder.decode(value, { stream: true }));
189
+ }
190
+ } finally {
191
+ reader.releaseLock();
192
+ }
193
+ return chunks.join("");
194
+ }
195
+ /**
196
+ * Read a single line from Deno's stdin.
197
+ *
198
+ * Uses the `ReadableStream` API with a manual buffer to read until
199
+ * a newline character is found. Returns `null` on EOF.
200
+ *
201
+ * This is intentionally simple — the terminal prompter handles retries
202
+ * and validation.
203
+ *
204
+ * @internal
205
+ */
206
+ function createDenoReadLine(deno) {
207
+ const decoder = new TextDecoder();
208
+ let buffer = "";
209
+ let done = false;
210
+ return async () => {
211
+ const reader = deno.stdin.readable.getReader();
212
+ try {
213
+ for (;;) {
214
+ const newlineIndex = buffer.indexOf("\n");
215
+ if (newlineIndex !== -1) {
216
+ const line = buffer.slice(0, newlineIndex).replace(/\r$/, "");
217
+ buffer = buffer.slice(newlineIndex + 1);
218
+ return line;
219
+ }
220
+ if (done) {
221
+ if (buffer.length === 0) return null;
222
+ const line = buffer;
223
+ buffer = "";
224
+ return line;
225
+ }
226
+ const { value, done: readDone } = await reader.read();
227
+ if (readDone) {
228
+ buffer += decoder.decode();
229
+ done = true;
230
+ continue;
231
+ }
232
+ buffer += decoder.decode(value, { stream: true });
233
+ }
234
+ } finally {
235
+ reader.releaseLock();
236
+ }
237
+ };
238
+ }
239
+ /**
240
+ * Resolve the user's home directory from environment variables.
241
+ *
242
+ * Deno doesn't expose `os.homedir()` without `--allow-sys`, so we derive
243
+ * it from env vars — same approach as the Node adapter.
244
+ *
245
+ * @internal
246
+ */
247
+ function resolveDenoHomedir(env, isWindows) {
248
+ return resolveHomeDirectory(env, isWindows);
249
+ }
250
+ /**
251
+ * Resolve the platform-specific user configuration directory.
252
+ *
253
+ * Uses `Deno.build.os` for platform detection, then applies the same fallback
254
+ * chain as the Node adapter.
255
+ *
256
+ * @internal
257
+ */
258
+ function resolveDenoConfigDir(env, homedir, isWindows) {
259
+ return resolveConfigDirectory(env, isWindows, homedir);
260
+ }
261
+ //#endregion
262
+ export { createDenoAdapter };
@@ -1 +1,45 @@
1
- const e=[`node`,`bun`,`deno`,`unknown`];function t(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`}export{e as RUNTIMES,t as detectRuntime};
1
+ //#region src/runtime/detect.ts
2
+ /**
3
+ * All known runtime values as a readonly tuple.
4
+ *
5
+ * Useful for validation, iteration, and exhaustiveness checks.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * if (RUNTIMES.includes(value)) {
10
+ * // value is a valid Runtime
11
+ * }
12
+ * ```
13
+ */
14
+ const RUNTIMES = [
15
+ "node",
16
+ "bun",
17
+ "deno",
18
+ "unknown"
19
+ ];
20
+ /**
21
+ * Detect the current JavaScript runtime.
22
+ *
23
+ * Uses `globalThis` feature detection to identify the host runtime.
24
+ * Detection order is significant: Bun is checked before Node because
25
+ * Bun exposes a Node-compatible `process` global.
26
+ *
27
+ * @param globals - Override `globalThis` for testing. Production callers
28
+ * should omit this parameter.
29
+ * @returns The detected {@link Runtime} identifier.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const rt = detectRuntime();
34
+ * // rt === 'node' | 'bun' | 'deno' | 'unknown'
35
+ * ```
36
+ */
37
+ function detectRuntime(globals) {
38
+ const g = globals ?? globalThis;
39
+ if (typeof g.Bun?.version === "string") return "bun";
40
+ if (typeof g.Deno?.version?.deno === "string") return "deno";
41
+ if (typeof g.process?.versions?.node === "string") return "node";
42
+ return "unknown";
43
+ }
44
+ //#endregion
45
+ export { RUNTIMES, detectRuntime };
@@ -1,7 +1,6 @@
1
- import { ExitError, RuntimeAdapter, TestAdapterOptions, createTestAdapter } from "./adapter.mjs";
1
+ import { ExitError, RuntimeAdapter, TerminalSize, TestAdapterOptions, createTestAdapter } from "./adapter.mjs";
2
2
  import { GlobalForDetect, RUNTIMES, Runtime, detectRuntime } from "./detect.mjs";
3
3
  import { createAdapter } from "./auto.mjs";
4
- import { NodeProcess, createNodeAdapter } from "./node.mjs";
5
- import { createBunAdapter } from "./bun.mjs";
6
4
  import { DenoNamespace, createDenoAdapter } from "./deno.mjs";
7
- export { type DenoNamespace, ExitError, type GlobalForDetect, type NodeProcess, RUNTIMES, type Runtime, type RuntimeAdapter, type TestAdapterOptions, createAdapter, createBunAdapter, createDenoAdapter, createNodeAdapter, createTestAdapter, detectRuntime };
5
+ import { NodeProcess, createNodeAdapter } from "./node.mjs";
6
+ export { type DenoNamespace, ExitError, type GlobalForDetect, type NodeProcess, RUNTIMES, type Runtime, type RuntimeAdapter, type TerminalSize, type TestAdapterOptions, createAdapter, createDenoAdapter, createNodeAdapter, createTestAdapter, detectRuntime };
@@ -1,5 +1,4 @@
1
1
  import { RuntimeAdapter } from "./adapter.mjs";
2
-
3
2
  //#region src/runtime/node.d.ts
4
3
  /**
5
4
  * Minimal subset of the Node.js `process` object needed by the adapter.
@@ -24,12 +23,19 @@ interface NodeProcess {
24
23
  readonly platform: string;
25
24
  /** Standard input stream with TTY detection and async iteration. */
26
25
  readonly stdin: {
27
- readonly isTTY?: boolean; /** Async iterable for reading all of stdin (used by readStdin). */
26
+ readonly isTTY?: boolean;
27
+ /** Async iterable for reading all of stdin (used by readStdin). */
28
28
  [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
29
29
  };
30
30
  /** Standard output stream with TTY detection and write. */
31
31
  readonly stdout: {
32
32
  readonly isTTY?: boolean;
33
+ readonly columns?: number;
34
+ readonly rows?: number;
35
+ getWindowSize?(): readonly [number, number];
36
+ on?(event: 'resize', listener: () => void): unknown;
37
+ off?(event: 'resize', listener: () => void): unknown;
38
+ removeListener?(event: 'resize', listener: () => void): unknown;
33
39
  write(data: string): unknown;
34
40
  };
35
41
  /** Standard error stream with write. */