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

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 +227 -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,289 +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
-
20
- // --- Node.js error shape — for ENOENT detection without @types/node
21
-
22
- /**
23
- * Minimal shape for Node.js system errors (e.g. `ENOENT`, `EACCES`).
24
- *
25
- * Used to detect file-not-found when reading config files.
26
- * Only the `code` property is needed; other fields are ignored.
27
- *
28
- * @internal
29
- */
30
- interface NodeSystemError {
31
- readonly code: string;
32
- }
33
-
34
- // --- Minimal process shape — avoids @types/node dependency
35
-
36
- /**
37
- * Minimal subset of the Node.js `process` object needed by the adapter.
38
- *
39
- * We avoid importing `@types/node` to keep the core runtime-agnostic
40
- * at the type level. This interface declares only what `createNodeAdapter`
41
- * actually reads from the global.
42
- */
43
- interface NodeProcess {
44
- /** Raw process arguments (`[binary, script, ...userArgs]`). */
45
- readonly argv: readonly string[];
46
- /** Environment variables (values are `undefined` for unset keys). */
47
- readonly env: Readonly<Record<string, string | undefined>>;
48
- /** Runtime version strings — used for version-guard checks. */
49
- readonly versions?: {
50
- readonly node?: string;
51
- readonly bun?: string;
52
- };
53
- /** Return the current working directory. */
54
- cwd(): string;
55
- /** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */
56
- readonly platform: string;
57
- /** Standard input stream with TTY detection and async iteration. */
58
- readonly stdin: {
59
- readonly isTTY?: boolean;
60
- /** Async iterable for reading all of stdin (used by readStdin). */
61
- [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
62
- };
63
- /** Standard output stream with TTY detection and write. */
64
- readonly stdout: {
65
- readonly isTTY?: boolean;
66
- write(data: string): unknown;
67
- };
68
- /** Standard error stream with write. */
69
- readonly stderr: {
70
- write(data: string): unknown;
71
- };
72
- /** Terminate the process with the given exit code. */
73
- exit(code: number): never;
74
- }
75
-
76
- // --- Process access — isolated for testability
77
-
78
- /**
79
- * Access the global `process` object without importing `@types/node`.
80
- *
81
- * Cast through `unknown` to avoid TypeScript errors when `@types/node`
82
- * isn't installed. Safe because this adapter is only used on Node/Bun
83
- * where `globalThis.process` is always defined.
84
- *
85
- * @internal
86
- */
87
- function getNodeProcess(): NodeProcess {
88
- return (globalThis as unknown as { process: NodeProcess }).process;
89
- }
90
-
91
- // --- Filesystem & path helpers — config discovery primitives
92
-
93
- /**
94
- * Detect whether an unknown thrown value is a Node.js system error
95
- * with a string `code` property (e.g. `'ENOENT'`, `'EACCES'`).
96
- *
97
- * @internal
98
- */
99
- function isNodeSystemError(err: unknown): err is NodeSystemError {
100
- if (typeof err !== 'object' || err === null || !('code' in err)) return false;
101
- // After the `in` check, TS narrows err to `object & Record<'code', unknown>`.
102
- const candidate: { code: unknown } = err;
103
- return typeof candidate.code === 'string';
104
- }
105
-
106
- /**
107
- * Resolve the user's home directory from environment variables.
108
- *
109
- * **Windows** (`win32`): `USERPROFILE` → `HOMEDRIVE`+`HOMEPATH` (both required) → `HOME` → `C:\`
110
- * **Unix**: `HOME` → `/`
111
- *
112
- * `HOMEPATH` alone is never used — it is a relative fragment (e.g. `\Users\alice`) that only
113
- * makes sense when combined with `HOMEDRIVE` (e.g. `C:`). Using `HOMEPATH` without `HOMEDRIVE`
114
- * could resolve against the working drive, producing an incorrect path.
115
- *
116
- * We avoid importing `node:os` to keep the factory synchronous and
117
- * to maintain the pattern of deriving everything from the process object.
118
- *
119
- * @internal
120
- */
121
- function resolveHomedir(
122
- env: Readonly<Record<string, string | undefined>>,
123
- platform: string,
124
- ): string {
125
- return resolveHomeDirectory(env, platform === 'win32');
126
- }
127
-
128
- /**
129
- * Resolve the platform-specific user configuration directory.
130
- *
131
- * - Unix: `$XDG_CONFIG_HOME` (if set), otherwise `~/.config`
132
- * - Windows: `%APPDATA%` (if set), otherwise `~\AppData\Roaming`
133
- *
134
- * @internal
135
- */
136
- function resolveConfigDir(
137
- env: Readonly<Record<string, string | undefined>>,
138
- platform: string,
139
- homedir: string,
140
- ): string {
141
- return resolveConfigDirectory(env, platform === 'win32', homedir);
142
- }
143
-
144
- // --- Node adapter factory
145
-
146
- /**
147
- * Create a runtime adapter backed by Node.js `process` globals.
148
- *
149
- * Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
150
- * `process.stdout.write`/`process.stderr.write` as {@linkcode WriteFn} functions.
151
- *
152
- * Also works on Bun, which provides a Node-compatible `process` global.
153
- *
154
- * @param proc - Override the process object (useful for testing the adapter itself).
155
- * @returns A {@linkcode RuntimeAdapter} backed by Node.js process state.
156
- *
157
- * @example
158
- * ```ts
159
- * import { cli } from '@kjanat/dreamcli';
160
- * import { createNodeAdapter } from '@kjanat/dreamcli/runtime/node';
161
- *
162
- * cli('mycli')
163
- * .command(deploy)
164
- * .run({ adapter: createNodeAdapter() });
165
- * ```
166
- */
167
- function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter {
168
- const p = proc ?? getNodeProcess();
169
-
170
- const stdoutWrite: WriteFn = (data) => {
171
- p.stdout.write(data);
172
- };
173
- const stderrWrite: WriteFn = (data) => {
174
- p.stderr.write(data);
175
- };
176
-
177
- // Stdin line reading via readline — created lazily on first call.
178
- // This avoids importing readline unless prompting actually occurs.
179
- const stdinRead = createNodeReadLine(p);
180
-
181
- // --- Filesystem primitives for config discovery ---
182
-
183
- const readFile = async (path: string): Promise<string | null> => {
184
- const fs = await import('node:fs/promises');
185
- try {
186
- return await fs.readFile(path, 'utf8');
187
- } catch (err: unknown) {
188
- // ENOENT = file not found → null (expected for config discovery probing)
189
- if (isNodeSystemError(err) && err.code === 'ENOENT') {
190
- return null;
191
- }
192
- throw err; // Permission denied, is-directory, etc. → caller handles
193
- }
194
- };
195
-
196
- const homedir = resolveHomedir(p.env, p.platform);
197
- const configDir = resolveConfigDir(p.env, p.platform, homedir);
198
-
199
- const stdinIsTTY = p.stdin.isTTY === true;
200
-
201
- return {
202
- argv: p.argv,
203
- env: p.env,
204
- cwd: p.cwd(),
205
- stdout: stdoutWrite,
206
- stderr: stderrWrite,
207
- stdin: stdinRead,
208
- readStdin: () => readNodeStdinAll(p, stdinIsTTY),
209
- isTTY: p.stdout.isTTY === true,
210
- stdinIsTTY,
211
- exit: (code) => p.exit(code),
212
- readFile,
213
- homedir,
214
- configDir,
215
- };
216
- }
217
-
218
- /**
219
- * Read all of stdin as a single string (for piped data).
220
- *
221
- * Returns `null` immediately if stdin is a TTY — the user is typing
222
- * interactively, so there's no piped data to consume. When stdin is
223
- * piped, collects all chunks via the async iterator until EOF and
224
- * returns the decoded string, which may be empty for an empty pipe.
225
- *
226
- * @internal
227
- */
228
- async function readNodeStdinAll(proc: NodeProcess, stdinIsTTY: boolean): Promise<string | null> {
229
- if (stdinIsTTY) return null;
230
-
231
- const chunks: string[] = [];
232
- const decoder = new TextDecoder();
233
-
234
- for await (const chunk of proc.stdin) {
235
- chunks.push(decoder.decode(chunk, { stream: true }));
236
- }
237
- // Flush any remaining bytes held by the streaming decoder
238
- chunks.push(decoder.decode());
239
-
240
- return chunks.join('');
241
- }
242
-
243
- /**
244
- * Read a single line from Node's stdin via its async iterator.
245
- *
246
- * Iterates stdin chunks manually (without `for-await` to avoid calling
247
- * `iterator.return()` which would close the stream). Returns `null`
248
- * on EOF.
249
- *
250
- * @internal
251
- */
252
- function createNodeReadLine(proc: NodeProcess): ReadFn {
253
- const iter = proc.stdin[Symbol.asyncIterator]();
254
- const decoder = new TextDecoder();
255
- let buffer = '';
256
- let done = false;
257
-
258
- return async (): Promise<string | null> => {
259
- for (;;) {
260
- const nlIndex = buffer.indexOf('\n');
261
- if (nlIndex !== -1) {
262
- const line = buffer.slice(0, nlIndex).replace(/\r$/, '');
263
- buffer = buffer.slice(nlIndex + 1);
264
- return line;
265
- }
266
-
267
- if (done) {
268
- if (buffer.length === 0) return null;
269
- const line = buffer;
270
- buffer = '';
271
- return line;
272
- }
273
-
274
- const result = await iter.next();
275
- if (result.done) {
276
- buffer += decoder.decode();
277
- done = true;
278
- continue;
279
- }
280
-
281
- buffer += decoder.decode(result.value, { stream: true });
282
- }
283
- };
284
- }
285
-
286
- // --- Exports
287
-
288
- export type { NodeProcess };
289
- 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,77 +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
- /** Look up the support entry for a given runtime. Throws on unknown runtime. @internal */
62
- function getRuntimeSupport(runtime: SupportedRuntime): RuntimeSupportEntry {
63
- for (const entry of SUPPORTED_RUNTIMES) {
64
- if (entry.runtime === runtime) return entry;
65
- }
66
-
67
- throw new Error(`Unknown supported runtime '${runtime}'`);
68
- }
69
-
70
- /** Format a human-readable version requirement string (e.g. `'Node.js >= 22.22.2'`). @internal */
71
- function formatRuntimeRequirement(runtime: SupportedRuntime): string {
72
- const support = getRuntimeSupport(runtime);
73
- return `${support.displayName} >= ${support.minimum}`;
74
- }
75
-
76
- export type { RuntimeSupportEntry, SupportedRuntime };
77
- export { formatRuntimeRequirement, getRuntimeSupport, SUPPORTED_RUNTIMES };
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/schema.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * JSON Schema for DreamCLI definition files.
3
- *
4
- * Re-exports the generated `dreamcli.schema.json` meta-schema so tooling,
5
- * editors, and validation libraries can import it as a typed module.
6
- *
7
- * @example
8
- * ```ts
9
- * import schema from '@kjanat/dreamcli/schema';
10
- *
11
- * console.log(schema.$id); // "dreamcli.schema.json"
12
- * ```
13
- *
14
- * @module @kjanat/dreamcli/schema
15
- */
16
- export { default } from '../dreamcli.schema.json' with { type: 'json' };
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';