@kjanat/dreamcli 2.5.0 → 3.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CHANGELOG.md +153 -1
  2. package/README.md +9 -2
  3. package/dist/core/cli/dispatch.mjs +214 -1
  4. package/dist/core/cli/help-links.mjs +41 -1
  5. package/dist/core/cli/index.d.mts +109 -16
  6. package/dist/core/cli/index.mjs +901 -1
  7. package/dist/core/cli/planner.d.mts +27 -5
  8. package/dist/core/cli/planner.mjs +300 -1
  9. package/dist/core/cli/plugin.mjs +41 -1
  10. package/dist/core/cli/propagate.mjs +57 -1
  11. package/dist/core/cli/root-help.d.mts +16 -2
  12. package/dist/core/cli/root-help.mjs +208 -6
  13. package/dist/core/cli/root-surface.d.mts +18 -3
  14. package/dist/core/cli/root-surface.mjs +27 -1
  15. package/dist/core/cli/runtime-preflight.d.mts +16 -1
  16. package/dist/core/cli/runtime-preflight.mjs +168 -1
  17. package/dist/core/completion/index.d.mts +32 -1
  18. package/dist/core/completion/index.mjs +90 -1
  19. package/dist/core/completion/shells/bash.mjs +304 -3
  20. package/dist/core/completion/shells/fish.mjs +159 -2
  21. package/dist/core/completion/shells/powershell.mjs +353 -2
  22. package/dist/core/completion/shells/shared.d.mts +10 -0
  23. package/dist/core/completion/shells/shared.mjs +154 -1
  24. package/dist/core/completion/shells/zsh.mjs +244 -2
  25. package/dist/core/config/index.mjs +246 -1
  26. package/dist/core/config/package-json.mjs +385 -3
  27. package/dist/core/errors/index.mjs +87 -1
  28. package/dist/core/execution/index.mjs +189 -1
  29. package/dist/core/help/ansi.mjs +122 -2
  30. package/dist/core/help/index.d.mts +45 -1
  31. package/dist/core/help/index.mjs +329 -7
  32. package/dist/core/json-schema/index.mjs +487 -9
  33. package/dist/core/json-schema/meta-descriptions.generated.d.mts +38 -38
  34. package/dist/core/json-schema/meta-descriptions.generated.mjs +93 -28
  35. package/dist/core/output/activity.mjs +452 -1
  36. package/dist/core/output/bind.mjs +56 -1
  37. package/dist/core/output/contracts.mjs +57 -1
  38. package/dist/core/output/display-value.mjs +32 -1
  39. package/dist/core/output/index.d.mts +21 -0
  40. package/dist/core/output/index.mjs +442 -2
  41. package/dist/core/output/renderers.mjs +46 -1
  42. package/dist/core/output/writer.mjs +12 -1
  43. package/dist/core/parse/index.d.mts +15 -1
  44. package/dist/core/parse/index.mjs +555 -1
  45. package/dist/core/prompt/index.d.mts +11 -4
  46. package/dist/core/prompt/index.mjs +348 -6
  47. package/dist/core/resolve/args.mjs +105 -1
  48. package/dist/core/resolve/coerce.mjs +279 -1
  49. package/dist/core/resolve/config.mjs +19 -1
  50. package/dist/core/resolve/errors.mjs +140 -2
  51. package/dist/core/resolve/flags.mjs +196 -1
  52. package/dist/core/resolve/index.mjs +85 -1
  53. package/dist/core/resolve/property.d.mts +2 -1
  54. package/dist/core/resolve/property.mjs +45 -1
  55. package/dist/core/schema/arg.d.mts +90 -10
  56. package/dist/core/schema/arg.mjs +463 -1
  57. package/dist/core/schema/command.d.mts +21 -1
  58. package/dist/core/schema/command.mjs +712 -1
  59. package/dist/core/schema/flag.d.mts +92 -2
  60. package/dist/core/schema/flag.mjs +453 -1
  61. package/dist/core/schema/index.d.mts +2 -1
  62. package/dist/core/schema/middleware.mjs +41 -1
  63. package/dist/core/schema/number-constraints.d.mts +96 -0
  64. package/dist/core/schema/number-constraints.mjs +60 -0
  65. package/dist/core/schema/prompt.d.mts +15 -0
  66. package/dist/core/schema/run.d.mts +4 -4
  67. package/dist/core/schema-dsl/runtime.mjs +271 -2
  68. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  69. package/dist/core/testkit/index.d.mts +9 -5
  70. package/dist/core/testkit/index.mjs +83 -1
  71. package/dist/index.d.mts +3 -1
  72. package/dist/index.mjs +22 -1
  73. package/dist/runtime/adapter.mjs +82 -1
  74. package/dist/runtime/auto.mjs +46 -1
  75. package/dist/runtime/bun.mjs +28 -1
  76. package/dist/runtime/deno.mjs +217 -2
  77. package/dist/runtime/detect.mjs +45 -1
  78. package/dist/runtime/node.mjs +169 -2
  79. package/dist/runtime/paths.mjs +48 -1
  80. package/dist/runtime.mjs +7 -1
  81. package/dist/strings.mjs +22 -1
  82. package/dist/testkit.mjs +5 -1
  83. package/dist/version.mjs +7 -1
  84. package/examples/basic.ts +5 -1
  85. package/examples/gh/package.json +2 -7
  86. package/examples/pwsh-demo/package.json +1 -7
  87. package/examples/pwsh-demo/src/main.test.ts +1 -4
  88. package/examples/pwsh-demo/src/main.ts +14 -4
  89. package/examples/transport-launcher.ts +85 -0
  90. package/package.json +23 -41
  91. package/dist/runtime/support.d.mts +0 -42
  92. package/dist/runtime/support.mjs +0 -1
  93. package/src/core/cli/dispatch.ts +0 -349
  94. package/src/core/cli/help-links.ts +0 -82
  95. package/src/core/cli/index.ts +0 -1413
  96. package/src/core/cli/planner.ts +0 -487
  97. package/src/core/cli/plugin.ts +0 -117
  98. package/src/core/cli/propagate.ts +0 -97
  99. package/src/core/cli/root-help.ts +0 -252
  100. package/src/core/cli/root-surface.ts +0 -74
  101. package/src/core/cli/runtime-preflight.ts +0 -438
  102. package/src/core/completion/index.ts +0 -88
  103. package/src/core/completion/shells/bash.ts +0 -459
  104. package/src/core/completion/shells/fish.ts +0 -259
  105. package/src/core/completion/shells/powershell.ts +0 -439
  106. package/src/core/completion/shells/shared.ts +0 -283
  107. package/src/core/completion/shells/zsh.ts +0 -381
  108. package/src/core/config/index.ts +0 -417
  109. package/src/core/config/package-json.ts +0 -560
  110. package/src/core/errors/index.ts +0 -193
  111. package/src/core/execution/index.ts +0 -268
  112. package/src/core/help/ansi.ts +0 -144
  113. package/src/core/help/index.ts +0 -516
  114. package/src/core/json-schema/index.ts +0 -891
  115. package/src/core/json-schema/meta-descriptions.generated.ts +0 -185
  116. package/src/core/output/activity.ts +0 -575
  117. package/src/core/output/bind.ts +0 -59
  118. package/src/core/output/contracts.ts +0 -194
  119. package/src/core/output/display-value.ts +0 -48
  120. package/src/core/output/index.ts +0 -704
  121. package/src/core/output/renderers.ts +0 -125
  122. package/src/core/output/writer.ts +0 -46
  123. package/src/core/parse/index.ts +0 -681
  124. package/src/core/prompt/index.ts +0 -583
  125. package/src/core/resolve/args.ts +0 -144
  126. package/src/core/resolve/coerce.ts +0 -432
  127. package/src/core/resolve/config.ts +0 -26
  128. package/src/core/resolve/contracts.ts +0 -135
  129. package/src/core/resolve/errors.ts +0 -227
  130. package/src/core/resolve/flags.ts +0 -255
  131. package/src/core/resolve/index.ts +0 -108
  132. package/src/core/resolve/property.ts +0 -99
  133. package/src/core/schema/activity.ts +0 -240
  134. package/src/core/schema/arg.ts +0 -719
  135. package/src/core/schema/command.ts +0 -1498
  136. package/src/core/schema/flag.ts +0 -801
  137. package/src/core/schema/index.ts +0 -91
  138. package/src/core/schema/middleware.ts +0 -171
  139. package/src/core/schema/prompt.ts +0 -156
  140. package/src/core/schema/run.ts +0 -198
  141. package/src/core/schema-dsl/index.ts +0 -109
  142. package/src/core/schema-dsl/parse.ts +0 -262
  143. package/src/core/schema-dsl/runtime.ts +0 -609
  144. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  145. package/src/core/testkit/index.ts +0 -123
  146. package/src/index.ts +0 -179
  147. package/src/runtime/adapter.ts +0 -303
  148. package/src/runtime/auto.ts +0 -110
  149. package/src/runtime/bun.ts +0 -55
  150. package/src/runtime/deno.ts +0 -369
  151. package/src/runtime/detect.ts +0 -105
  152. package/src/runtime/index.ts +0 -21
  153. package/src/runtime/node-builtins.d.ts +0 -27
  154. package/src/runtime/node.ts +0 -300
  155. package/src/runtime/paths.ts +0 -64
  156. package/src/runtime/support.ts +0 -135
  157. package/src/runtime.ts +0 -31
  158. package/src/strings.ts +0 -34
  159. package/src/testkit.ts +0 -25
  160. package/src/version.ts +0 -20
@@ -1,300 +0,0 @@
1
- /**
2
- * Node.js runtime adapter implementation.
3
- *
4
- * Bridges the platform-agnostic {@linkcode RuntimeAdapter} interface to Node.js's
5
- * `globalThis.process` object. This adapter is also compatible with Bun,
6
- * which provides a Node-compatible `process` global.
7
- *
8
- * The adapter reads process state once at creation time and exposes it
9
- * through the immutable {@linkcode RuntimeAdapter} interface. I/O writers wrap
10
- * `process.stdout.write` and `process.stderr.write`.
11
- *
12
- * @module @kjanat/dreamcli/runtime/node
13
- */
14
-
15
- import type { WriteFn } from '#internals/core/output/index.ts';
16
- import type { ReadFn } from '#internals/core/prompt/index.ts';
17
- import type { RuntimeAdapter } from './adapter.ts';
18
- import { resolveConfigDirectory, resolveHomeDirectory } from './paths.ts';
19
- import { assertRuntimeVersionSupported } from './support.ts';
20
-
21
- // --- Node.js error shape — for ENOENT detection without @types/node
22
-
23
- /**
24
- * Minimal shape for Node.js system errors (e.g. `ENOENT`, `EACCES`).
25
- *
26
- * Used to detect file-not-found when reading config files.
27
- * Only the `code` property is needed; other fields are ignored.
28
- *
29
- * @internal
30
- */
31
- interface NodeSystemError {
32
- readonly code: string;
33
- }
34
-
35
- // --- Minimal process shape — avoids @types/node dependency
36
-
37
- /**
38
- * Minimal subset of the Node.js `process` object needed by the adapter.
39
- *
40
- * We avoid importing `@types/node` to keep the core runtime-agnostic
41
- * at the type level. This interface declares only what `createNodeAdapter`
42
- * actually reads from the global.
43
- */
44
- interface NodeProcess {
45
- /** Raw process arguments (`[binary, script, ...userArgs]`). */
46
- readonly argv: readonly string[];
47
- /** Environment variables (values are `undefined` for unset keys). */
48
- readonly env: Readonly<Record<string, string | undefined>>;
49
- /** Runtime version strings — used for version-guard checks. */
50
- readonly versions?: {
51
- readonly node?: string;
52
- readonly bun?: string;
53
- };
54
- /** Return the current working directory. */
55
- cwd(): string;
56
- /** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */
57
- readonly platform: string;
58
- /** Standard input stream with TTY detection and async iteration. */
59
- readonly stdin: {
60
- readonly isTTY?: boolean;
61
- /** Async iterable for reading all of stdin (used by readStdin). */
62
- [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
63
- };
64
- /** Standard output stream with TTY detection and write. */
65
- readonly stdout: {
66
- readonly isTTY?: boolean;
67
- write(data: string): unknown;
68
- };
69
- /** Standard error stream with write. */
70
- readonly stderr: {
71
- write(data: string): unknown;
72
- };
73
- /** Terminate the process with the given exit code. */
74
- exit(code: number): never;
75
- }
76
-
77
- // --- Process access — isolated for testability
78
-
79
- /**
80
- * Access the global `process` object without importing `@types/node`.
81
- *
82
- * Cast through `unknown` to avoid TypeScript errors when `@types/node`
83
- * isn't installed. Safe because this adapter is only used on Node/Bun
84
- * where `globalThis.process` is always defined.
85
- *
86
- * @internal
87
- */
88
- function getNodeProcess(): NodeProcess {
89
- return (globalThis as unknown as { process: NodeProcess }).process;
90
- }
91
-
92
- // --- Filesystem & path helpers — config discovery primitives
93
-
94
- /**
95
- * Detect whether an unknown thrown value is a Node.js system error
96
- * with a string `code` property (e.g. `'ENOENT'`, `'EACCES'`).
97
- *
98
- * @internal
99
- */
100
- function isNodeSystemError(err: unknown): err is NodeSystemError {
101
- if (typeof err !== 'object' || err === null || !('code' in err)) return false;
102
- // After the `in` check, TS narrows err to `object & Record<'code', unknown>`.
103
- const candidate: { code: unknown } = err;
104
- return typeof candidate.code === 'string';
105
- }
106
-
107
- /**
108
- * Resolve the user's home directory from environment variables.
109
- *
110
- * **Windows** (`win32`): `USERPROFILE` → `HOMEDRIVE`+`HOMEPATH` (both required) → `HOME` → `C:\`
111
- * **Unix**: `HOME` → `/`
112
- *
113
- * `HOMEPATH` alone is never used — it is a relative fragment (e.g. `\Users\alice`) that only
114
- * makes sense when combined with `HOMEDRIVE` (e.g. `C:`). Using `HOMEPATH` without `HOMEDRIVE`
115
- * could resolve against the working drive, producing an incorrect path.
116
- *
117
- * We avoid importing `node:os` to keep the factory synchronous and
118
- * to maintain the pattern of deriving everything from the process object.
119
- *
120
- * @internal
121
- */
122
- function resolveHomedir(
123
- env: Readonly<Record<string, string | undefined>>,
124
- platform: string,
125
- ): string {
126
- return resolveHomeDirectory(env, platform === 'win32');
127
- }
128
-
129
- /**
130
- * Resolve the platform-specific user configuration directory.
131
- *
132
- * - Unix: `$XDG_CONFIG_HOME` (if set), otherwise `~/.config`
133
- * - Windows: `%APPDATA%` (if set), otherwise `~\AppData\Roaming`
134
- *
135
- * @internal
136
- */
137
- function resolveConfigDir(
138
- env: Readonly<Record<string, string | undefined>>,
139
- platform: string,
140
- homedir: string,
141
- ): string {
142
- return resolveConfigDirectory(env, platform === 'win32', homedir);
143
- }
144
-
145
- function assertProcessRuntimeSupported(proc: NodeProcess): void {
146
- if (proc.versions?.bun !== undefined) {
147
- assertRuntimeVersionSupported('bun', proc.versions.bun);
148
- return;
149
- }
150
-
151
- assertRuntimeVersionSupported('node', proc.versions?.node);
152
- }
153
-
154
- // --- Node adapter factory
155
-
156
- /**
157
- * Create a runtime adapter backed by Node.js `process` globals.
158
- *
159
- * Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
160
- * `process.stdout.write`/`process.stderr.write` as {@linkcode WriteFn} functions.
161
- *
162
- * Also works on Bun, which provides a Node-compatible `process` global.
163
- *
164
- * @param proc - Override the process object (useful for testing the adapter itself).
165
- * @returns A {@linkcode RuntimeAdapter} backed by Node.js process state.
166
- *
167
- * @example
168
- * ```ts
169
- * import { cli } from '@kjanat/dreamcli';
170
- * import { createNodeAdapter } from '@kjanat/dreamcli/runtime/node';
171
- *
172
- * cli('mycli')
173
- * .command(deploy)
174
- * .run({ adapter: createNodeAdapter() });
175
- * ```
176
- */
177
- function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter {
178
- const p = proc ?? getNodeProcess();
179
- assertProcessRuntimeSupported(p);
180
-
181
- const stdoutWrite: WriteFn = (data) => {
182
- p.stdout.write(data);
183
- };
184
- const stderrWrite: WriteFn = (data) => {
185
- p.stderr.write(data);
186
- };
187
-
188
- // Stdin line reading via readline — created lazily on first call.
189
- // This avoids importing readline unless prompting actually occurs.
190
- const stdinRead = createNodeReadLine(p);
191
-
192
- // --- Filesystem primitives for config discovery ---
193
-
194
- const readFile = async (path: string): Promise<string | null> => {
195
- const fs = await import('node:fs/promises');
196
- try {
197
- return await fs.readFile(path, 'utf8');
198
- } catch (err: unknown) {
199
- // ENOENT = file not found → null (expected for config discovery probing)
200
- if (isNodeSystemError(err) && err.code === 'ENOENT') {
201
- return null;
202
- }
203
- throw err; // Permission denied, is-directory, etc. → caller handles
204
- }
205
- };
206
-
207
- const homedir = resolveHomedir(p.env, p.platform);
208
- const configDir = resolveConfigDir(p.env, p.platform, homedir);
209
-
210
- const stdinIsTTY = p.stdin.isTTY === true;
211
-
212
- return {
213
- argv: p.argv,
214
- env: p.env,
215
- cwd: p.cwd(),
216
- stdout: stdoutWrite,
217
- stderr: stderrWrite,
218
- stdin: stdinRead,
219
- readStdin: () => readNodeStdinAll(p, stdinIsTTY),
220
- isTTY: p.stdout.isTTY === true,
221
- stdinIsTTY,
222
- exit: (code) => p.exit(code),
223
- readFile,
224
- homedir,
225
- configDir,
226
- };
227
- }
228
-
229
- /**
230
- * Read all of stdin as a single string (for piped data).
231
- *
232
- * Returns `null` immediately if stdin is a TTY — the user is typing
233
- * interactively, so there's no piped data to consume. When stdin is
234
- * piped, collects all chunks via the async iterator until EOF and
235
- * returns the decoded string, which may be empty for an empty pipe.
236
- *
237
- * @internal
238
- */
239
- async function readNodeStdinAll(proc: NodeProcess, stdinIsTTY: boolean): Promise<string | null> {
240
- if (stdinIsTTY) return null;
241
-
242
- const chunks: string[] = [];
243
- const decoder = new TextDecoder();
244
-
245
- for await (const chunk of proc.stdin) {
246
- chunks.push(decoder.decode(chunk, { stream: true }));
247
- }
248
- // Flush any remaining bytes held by the streaming decoder
249
- chunks.push(decoder.decode());
250
-
251
- return chunks.join('');
252
- }
253
-
254
- /**
255
- * Read a single line from Node's stdin via its async iterator.
256
- *
257
- * Iterates stdin chunks manually (without `for-await` to avoid calling
258
- * `iterator.return()` which would close the stream). Returns `null`
259
- * on EOF.
260
- *
261
- * @internal
262
- */
263
- function createNodeReadLine(proc: NodeProcess): ReadFn {
264
- const iter = proc.stdin[Symbol.asyncIterator]();
265
- const decoder = new TextDecoder();
266
- let buffer = '';
267
- let done = false;
268
-
269
- return async (): Promise<string | null> => {
270
- for (;;) {
271
- const nlIndex = buffer.indexOf('\n');
272
- if (nlIndex !== -1) {
273
- const line = buffer.slice(0, nlIndex).replace(/\r$/, '');
274
- buffer = buffer.slice(nlIndex + 1);
275
- return line;
276
- }
277
-
278
- if (done) {
279
- if (buffer.length === 0) return null;
280
- const line = buffer;
281
- buffer = '';
282
- return line;
283
- }
284
-
285
- const result = await iter.next();
286
- if (result.done) {
287
- buffer += decoder.decode();
288
- done = true;
289
- continue;
290
- }
291
-
292
- buffer += decoder.decode(result.value, { stream: true });
293
- }
294
- };
295
- }
296
-
297
- // --- Exports
298
-
299
- export type { NodeProcess };
300
- export { createNodeAdapter };
@@ -1,64 +0,0 @@
1
- /**
2
- * Shared env-based path resolution for runtime adapters.
3
- *
4
- * Node, Bun, and Deno all need the same user home/config directory behavior.
5
- * These helpers keep the fallback chain identical across runtimes while
6
- * letting each adapter supply its own platform detection.
7
- *
8
- * @module @kjanat/dreamcli/runtime/paths
9
- */
10
-
11
- import { BACKSLASH, SLASH, stripTrailing } from '#internals/strings.ts';
12
-
13
- /**
14
- * Resolve the user's home directory from environment variables.
15
- *
16
- * @param env - Environment variable map.
17
- * @param isWindows - Whether the platform is Windows.
18
- * @returns Absolute path to the home directory.
19
- * @internal
20
- */
21
- function resolveHomeDirectory(
22
- env: Readonly<Record<string, string | undefined>>,
23
- isWindows: boolean,
24
- ): string {
25
- if (isWindows) {
26
- if (env.USERPROFILE) return env.USERPROFILE;
27
- if (env.HOMEDRIVE && env.HOMEPATH) {
28
- return env.HOMEDRIVE + env.HOMEPATH;
29
- }
30
- return env.HOME || 'C:\\';
31
- }
32
- return env.HOME || '/';
33
- }
34
-
35
- /**
36
- * Resolve the user's config directory (`XDG_CONFIG_HOME` / `APPDATA`).
37
- *
38
- * @param env - Environment variable map.
39
- * @param isWindows - Whether the platform is Windows.
40
- * @param homedir - Pre-resolved home directory (from {@link resolveHomeDirectory}).
41
- * @returns Absolute path to the config directory.
42
- * @internal
43
- */
44
- function resolveConfigDirectory(
45
- env: Readonly<Record<string, string | undefined>>,
46
- isWindows: boolean,
47
- homedir: string,
48
- ): string {
49
- if (isWindows) {
50
- if (env.APPDATA !== undefined && env.APPDATA !== '') return env.APPDATA;
51
- const normalizedHome = stripTrailing(homedir, [SLASH, BACKSLASH]) || homedir;
52
- return `${normalizedHome}\\AppData\\Roaming`;
53
- }
54
- const normalizedHome = stripTrailing(homedir, [SLASH]);
55
- if (env.XDG_CONFIG_HOME !== undefined && env.XDG_CONFIG_HOME !== '') {
56
- return env.XDG_CONFIG_HOME;
57
- }
58
- if (normalizedHome.length === 0) {
59
- return '/.config';
60
- }
61
- return `${normalizedHome}/.config`;
62
- }
63
-
64
- export { resolveConfigDirectory, resolveHomeDirectory };
@@ -1,135 +0,0 @@
1
- /**
2
- * Runtime compatibility matrix and version guard helpers.
3
- *
4
- * Keeps the supported runtime story in one place so adapter guards,
5
- * package engines, and docs can stay aligned.
6
- *
7
- * @internal
8
- * @module @kjanat/dreamcli/runtime/support
9
- */
10
-
11
- type SupportedRuntime = 'node' | 'bun' | 'deno';
12
-
13
- /**
14
- * Support entry for a single runtime: version bounds, display names, and adapter mapping.
15
- *
16
- * @internal
17
- */
18
- interface RuntimeSupportEntry {
19
- /** Runtime identifier key. */
20
- readonly runtime: SupportedRuntime;
21
- /** Human-readable name (e.g. `'Node.js'`, `'Bun'`). */
22
- readonly displayName: string;
23
- /** Minimum supported version (semver, e.g. `'22.22.2'`). */
24
- readonly minimum: string;
25
- /** `engines` range string for package.json (e.g. `'>=22.22.2'`). */
26
- readonly engineRange: string;
27
- /** npm/JSR package name that ships this adapter. */
28
- readonly packageName: string;
29
- /** Adapter factory function name (e.g. `'NodeAdapter'`). */
30
- readonly adapterName: string;
31
- }
32
-
33
- /** All supported runtimes with their version bounds and adapter metadata. @internal */
34
- const SUPPORTED_RUNTIMES: readonly RuntimeSupportEntry[] = [
35
- {
36
- runtime: 'node',
37
- displayName: 'Node.js',
38
- minimum: '22.22.2',
39
- engineRange: '>=22.22.2',
40
- packageName: '@kjanat/dreamcli',
41
- adapterName: 'NodeAdapter',
42
- },
43
- {
44
- runtime: 'bun',
45
- displayName: 'Bun',
46
- minimum: '1.3',
47
- engineRange: '>=1.3',
48
- packageName: '@kjanat/dreamcli',
49
- adapterName: 'BunAdapter',
50
- },
51
- {
52
- runtime: 'deno',
53
- displayName: 'Deno',
54
- minimum: '2.6.0',
55
- engineRange: '>=2.6.0',
56
- packageName: '@kjanat/dreamcli',
57
- adapterName: 'DenoAdapter',
58
- },
59
- ];
60
-
61
- interface ParsedVersion {
62
- readonly major: number;
63
- readonly minor: number;
64
- readonly patch: number;
65
- }
66
-
67
- const VERSION_PATTERN = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?/;
68
-
69
- /** Look up the support entry for a given runtime. Throws on unknown runtime. @internal */
70
- function getRuntimeSupport(runtime: SupportedRuntime): RuntimeSupportEntry {
71
- for (const entry of SUPPORTED_RUNTIMES) {
72
- if (entry.runtime === runtime) return entry;
73
- }
74
-
75
- throw new Error(`Unknown supported runtime '${runtime}'`);
76
- }
77
-
78
- function parseVersion(version: string): ParsedVersion | undefined {
79
- const match = VERSION_PATTERN.exec(version);
80
- if (match === null) return undefined;
81
-
82
- const major = Number.parseInt(match[1] ?? '', 10);
83
- const minorText = match[2];
84
- const minor = minorText === undefined ? 0 : Number.parseInt(minorText, 10);
85
- const patchText = match[3];
86
- const patch = patchText === undefined ? 0 : Number.parseInt(patchText, 10);
87
-
88
- if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) {
89
- return undefined;
90
- }
91
-
92
- return { major, minor, patch };
93
- }
94
-
95
- function compareVersions(left: ParsedVersion, right: ParsedVersion): number {
96
- if (left.major !== right.major) return left.major - right.major;
97
- if (left.minor !== right.minor) return left.minor - right.minor;
98
- return left.patch - right.patch;
99
- }
100
-
101
- /** Format a human-readable version requirement string (e.g. `'Node.js >= 22.22.2'`). @internal */
102
- function formatRuntimeRequirement(runtime: SupportedRuntime): string {
103
- const support = getRuntimeSupport(runtime);
104
- return `${support.displayName} >= ${support.minimum}`;
105
- }
106
-
107
- /** Check whether a version string meets the minimum for the given runtime. @internal */
108
- function isRuntimeVersionSupported(runtime: SupportedRuntime, version: string): boolean {
109
- const parsedVersion = parseVersion(version);
110
- const minimumVersion = parseVersion(getRuntimeSupport(runtime).minimum);
111
- if (parsedVersion === undefined || minimumVersion === undefined) return false;
112
- return compareVersions(parsedVersion, minimumVersion) >= 0;
113
- }
114
-
115
- /** Throw if the detected version is below the minimum. No-op when version is undefined. @internal */
116
- function assertRuntimeVersionSupported(
117
- runtime: SupportedRuntime,
118
- version: string | undefined,
119
- ): void {
120
- if (version === undefined) return;
121
- if (isRuntimeVersionSupported(runtime, version)) return;
122
-
123
- throw new Error(
124
- `@kjanat/dreamcli requires ${formatRuntimeRequirement(runtime)}. Detected ${getRuntimeSupport(runtime).displayName} ${version}.`,
125
- );
126
- }
127
-
128
- export type { RuntimeSupportEntry, SupportedRuntime };
129
- export {
130
- assertRuntimeVersionSupported,
131
- formatRuntimeRequirement,
132
- getRuntimeSupport,
133
- isRuntimeVersionSupported,
134
- SUPPORTED_RUNTIMES,
135
- };
package/src/runtime.ts DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * Runtime adapters for platform portability (Node, Bun, Deno).
3
- *
4
- * Provides the {@link RuntimeAdapter} interface and concrete adapter
5
- * factories for each supported platform.
6
- *
7
- * Start here when embedding DreamCLI in a real host runtime:
8
- * - {@link createAdapter} for normal auto-detected production use
9
- * - {@link createNodeAdapter}, {@link createDenoAdapter}, or
10
- * {@link createBunAdapter} when the runtime must be selected explicitly
11
- *
12
- * Most applications do not need this subpath unless they are wiring DreamCLI
13
- * into a custom host, testing runtime behavior directly, or building their own
14
- * process/bootstrap layer.
15
- *
16
- * @module @kjanat/dreamcli/runtime
17
- */
18
-
19
- export type {
20
- Runtime,
21
- RuntimeAdapter,
22
- } from './runtime/index.ts';
23
- export {
24
- createAdapter,
25
- createBunAdapter,
26
- createDenoAdapter,
27
- createNodeAdapter,
28
- detectRuntime,
29
- ExitError,
30
- RUNTIMES,
31
- } from './runtime/index.ts';
package/src/strings.ts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * Internal string utilities shared across runtime and core modules.
3
- *
4
- * @module dreamcli/strings
5
- */
6
-
7
- /** Character code for `/` (forward slash). */
8
- const SLASH = 0x2f;
9
- /** Character code for `\` (backslash). */
10
- const BACKSLASH = 0x5c;
11
-
12
- /**
13
- * Remove trailing characters whose code points appear in `codes`.
14
- *
15
- * Linear-time replacement for trailing-character regexes such as
16
- * `/[\\/]+$/`. Those patterns are polynomial-ReDoS prone: the engine
17
- * greedily consumes the run, fails the end anchor, backtracks one
18
- * character at a time, and repeats that work from every start position —
19
- * O(n²) on adversarial input. This scan is O(n) with no backtracking.
20
- *
21
- * @param input - Source string.
22
- * @param codes - Character codes to strip from the end of `input`.
23
- * @returns `input` with all trailing matching characters removed.
24
- * @internal
25
- */
26
- function stripTrailing(input: string, codes: readonly number[]): string {
27
- let end = input.length;
28
- while (end > 0 && codes.includes(input.charCodeAt(end - 1))) {
29
- end -= 1;
30
- }
31
- return end === input.length ? input : input.slice(0, end);
32
- }
33
-
34
- export { BACKSLASH, SLASH, stripTrailing };
package/src/testkit.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * Test utilities for DreamCLI commands.
3
- *
4
- * Provides {@linkcode runCommand | runCommand()} — the in-process test harness — plus test doubles
5
- * for output capture, prompt simulation, and runtime adaptation.
6
- *
7
- * Start here for most tests:
8
- * - {@link runCommand} to execute a command in-process
9
- * - {@link createCaptureOutput} to assert on raw output behavior
10
- * - {@link createTestPrompter} to script interactive answers
11
- * - {@link createTestAdapter} when you need adapter-level control
12
- *
13
- * @module @kjanat/dreamcli/testkit
14
- */
15
-
16
- export { type CapturedOutput, createCaptureOutput } from './core/output/index.ts';
17
- export {
18
- createTestPrompter,
19
- PROMPT_CANCEL,
20
- type TestAnswer,
21
- type TestPrompterOptions,
22
- } from './core/prompt/index.ts';
23
- export type { RunOptions, RunResult } from './core/testkit/index.ts';
24
- export { runCommand } from './core/testkit/index.ts';
25
- export { createTestAdapter, type TestAdapterOptions } from './runtime/index.ts';
package/src/version.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Build-time version constants.
3
- *
4
- * Replaced by tsdown `define` during bundling. In development (unbundled),
5
- * the declared globals resolve to the `'dev'` fallback.
6
- *
7
- * @module dreamcli/version
8
- * @internal
9
- */
10
-
11
- declare const __DREAMCLI_VERSION__: string;
12
- declare const __DREAMCLI_REVISION__: string;
13
-
14
- /** Package version (e.g. `"0.9.1"`). `"dev"` when running unbundled. */
15
- export const DREAMCLI_VERSION: string =
16
- typeof __DREAMCLI_VERSION__ !== 'undefined' ? __DREAMCLI_VERSION__ : 'dev';
17
-
18
- /** Git short SHA (e.g. `"f9b5f1a"`). `"dev"` when running unbundled. */
19
- export const DREAMCLI_REVISION: string =
20
- typeof __DREAMCLI_REVISION__ !== 'undefined' ? __DREAMCLI_REVISION__ : 'dev';