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

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 (137) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/dist/core/cli/dispatch.mjs +214 -1
  3. package/dist/core/cli/help-links.mjs +41 -1
  4. package/dist/core/cli/index.mjs +901 -1
  5. package/dist/core/cli/planner.mjs +300 -1
  6. package/dist/core/cli/plugin.mjs +41 -1
  7. package/dist/core/cli/propagate.mjs +57 -1
  8. package/dist/core/cli/root-help.mjs +208 -4
  9. package/dist/core/cli/root-surface.mjs +27 -1
  10. package/dist/core/cli/runtime-preflight.mjs +168 -1
  11. package/dist/core/completion/index.mjs +90 -1
  12. package/dist/core/completion/shells/bash.mjs +304 -3
  13. package/dist/core/completion/shells/fish.mjs +159 -2
  14. package/dist/core/completion/shells/powershell.mjs +353 -2
  15. package/dist/core/completion/shells/shared.mjs +154 -1
  16. package/dist/core/completion/shells/zsh.mjs +244 -2
  17. package/dist/core/config/index.mjs +246 -1
  18. package/dist/core/config/package-json.mjs +385 -3
  19. package/dist/core/errors/index.mjs +87 -1
  20. package/dist/core/execution/index.mjs +189 -1
  21. package/dist/core/help/ansi.mjs +122 -2
  22. package/dist/core/help/index.mjs +329 -7
  23. package/dist/core/json-schema/index.mjs +487 -9
  24. package/dist/core/json-schema/meta-descriptions.generated.mjs +93 -28
  25. package/dist/core/output/activity.mjs +452 -1
  26. package/dist/core/output/bind.mjs +56 -1
  27. package/dist/core/output/contracts.mjs +57 -1
  28. package/dist/core/output/display-value.mjs +32 -1
  29. package/dist/core/output/index.d.mts +21 -0
  30. package/dist/core/output/index.mjs +442 -2
  31. package/dist/core/output/renderers.mjs +46 -1
  32. package/dist/core/output/writer.mjs +12 -1
  33. package/dist/core/parse/index.mjs +555 -1
  34. package/dist/core/prompt/index.d.mts +0 -1
  35. package/dist/core/prompt/index.mjs +348 -6
  36. package/dist/core/resolve/args.mjs +105 -1
  37. package/dist/core/resolve/coerce.mjs +279 -1
  38. package/dist/core/resolve/config.mjs +19 -1
  39. package/dist/core/resolve/errors.mjs +140 -2
  40. package/dist/core/resolve/flags.mjs +196 -1
  41. package/dist/core/resolve/index.mjs +85 -1
  42. package/dist/core/resolve/property.d.mts +0 -1
  43. package/dist/core/resolve/property.mjs +45 -1
  44. package/dist/core/schema/arg.mjs +463 -1
  45. package/dist/core/schema/command.d.mts +18 -0
  46. package/dist/core/schema/command.mjs +712 -1
  47. package/dist/core/schema/flag.mjs +453 -1
  48. package/dist/core/schema/middleware.mjs +41 -1
  49. package/dist/core/schema/number-constraints.mjs +60 -1
  50. package/dist/core/schema-dsl/runtime.mjs +271 -2
  51. package/dist/core/schema-dsl/to-json-schema.mjs +74 -1
  52. package/dist/core/testkit/index.mjs +83 -1
  53. package/dist/index.d.mts +2 -1
  54. package/dist/index.mjs +22 -1
  55. package/dist/runtime/adapter.mjs +82 -1
  56. package/dist/runtime/auto.mjs +46 -1
  57. package/dist/runtime/bun.mjs +28 -1
  58. package/dist/runtime/deno.mjs +217 -2
  59. package/dist/runtime/detect.mjs +45 -1
  60. package/dist/runtime/node.mjs +169 -2
  61. package/dist/runtime/paths.mjs +48 -1
  62. package/dist/runtime.mjs +7 -1
  63. package/dist/strings.mjs +22 -1
  64. package/dist/testkit.mjs +5 -1
  65. package/dist/version.d.mts +7 -3
  66. package/dist/version.mjs +7 -1
  67. package/package.json +21 -26
  68. package/src/core/cli/dispatch.ts +0 -355
  69. package/src/core/cli/help-links.ts +0 -82
  70. package/src/core/cli/index.ts +0 -1614
  71. package/src/core/cli/planner.ts +0 -656
  72. package/src/core/cli/plugin.ts +0 -117
  73. package/src/core/cli/propagate.ts +0 -97
  74. package/src/core/cli/root-help.ts +0 -342
  75. package/src/core/cli/root-surface.ts +0 -87
  76. package/src/core/cli/runtime-preflight.ts +0 -456
  77. package/src/core/completion/index.ts +0 -138
  78. package/src/core/completion/shells/bash.ts +0 -459
  79. package/src/core/completion/shells/fish.ts +0 -259
  80. package/src/core/completion/shells/powershell.ts +0 -439
  81. package/src/core/completion/shells/shared.ts +0 -310
  82. package/src/core/completion/shells/zsh.ts +0 -381
  83. package/src/core/config/index.ts +0 -417
  84. package/src/core/config/package-json.ts +0 -560
  85. package/src/core/errors/index.ts +0 -193
  86. package/src/core/execution/index.ts +0 -265
  87. package/src/core/help/ansi.ts +0 -144
  88. package/src/core/help/index.ts +0 -563
  89. package/src/core/json-schema/index.ts +0 -910
  90. package/src/core/json-schema/meta-descriptions.generated.ts +0 -202
  91. package/src/core/output/activity.ts +0 -575
  92. package/src/core/output/bind.ts +0 -59
  93. package/src/core/output/contracts.ts +0 -194
  94. package/src/core/output/display-value.ts +0 -48
  95. package/src/core/output/index.ts +0 -704
  96. package/src/core/output/renderers.ts +0 -125
  97. package/src/core/output/writer.ts +0 -46
  98. package/src/core/parse/index.ts +0 -742
  99. package/src/core/prompt/index.ts +0 -623
  100. package/src/core/resolve/args.ts +0 -144
  101. package/src/core/resolve/coerce.ts +0 -500
  102. package/src/core/resolve/config.ts +0 -26
  103. package/src/core/resolve/contracts.ts +0 -135
  104. package/src/core/resolve/errors.ts +0 -227
  105. package/src/core/resolve/flags.ts +0 -269
  106. package/src/core/resolve/index.ts +0 -108
  107. package/src/core/resolve/property.ts +0 -99
  108. package/src/core/schema/activity.ts +0 -240
  109. package/src/core/schema/arg.ts +0 -841
  110. package/src/core/schema/command.ts +0 -1500
  111. package/src/core/schema/flag.ts +0 -917
  112. package/src/core/schema/index.ts +0 -96
  113. package/src/core/schema/middleware.ts +0 -171
  114. package/src/core/schema/number-constraints.ts +0 -153
  115. package/src/core/schema/prompt.ts +0 -171
  116. package/src/core/schema/run.ts +0 -198
  117. package/src/core/schema-dsl/index.ts +0 -109
  118. package/src/core/schema-dsl/parse.ts +0 -262
  119. package/src/core/schema-dsl/runtime.ts +0 -609
  120. package/src/core/schema-dsl/to-json-schema.ts +0 -102
  121. package/src/core/testkit/index.ts +0 -147
  122. package/src/index.ts +0 -181
  123. package/src/runtime/adapter.ts +0 -303
  124. package/src/runtime/auto.ts +0 -86
  125. package/src/runtime/bun.ts +0 -48
  126. package/src/runtime/deno.ts +0 -367
  127. package/src/runtime/detect.ts +0 -105
  128. package/src/runtime/index.ts +0 -21
  129. package/src/runtime/node-builtins.d.ts +0 -27
  130. package/src/runtime/node.ts +0 -289
  131. package/src/runtime/paths.ts +0 -64
  132. package/src/runtime/support.ts +0 -77
  133. package/src/runtime.ts +0 -31
  134. package/src/schema.ts +0 -16
  135. package/src/strings.ts +0 -34
  136. package/src/testkit.ts +0 -25
  137. 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';