@kjanat/dreamcli 0.0.0 → 1.0.0

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 (101) hide show
  1. package/CHANGELOG.md +667 -0
  2. package/LICENSE +22 -0
  3. package/README.md +370 -0
  4. package/dist/adapter-B37d9oia.mjs +1 -0
  5. package/dist/adapter-CCSh5juX.cjs +1 -0
  6. package/dist/adapter-DIwO-q7K.d.mts +3447 -0
  7. package/dist/adapter-DQnxxLiE.d.cts +3447 -0
  8. package/dist/auto-5cjZaF9V.mjs +3 -0
  9. package/dist/auto-B0eSgoDw.cjs +3 -0
  10. package/dist/index.cjs +10 -0
  11. package/dist/index.d.cts +920 -0
  12. package/dist/index.d.mts +920 -0
  13. package/dist/index.mjs +10 -0
  14. package/dist/runtime.cjs +1 -0
  15. package/dist/runtime.d.cts +253 -0
  16. package/dist/runtime.d.mts +253 -0
  17. package/dist/runtime.mjs +1 -0
  18. package/dist/testkit-CEDYPvhF.mjs +14 -0
  19. package/dist/testkit-ClIKijxC.cjs +14 -0
  20. package/dist/testkit.cjs +1 -0
  21. package/dist/testkit.d.cts +25 -0
  22. package/dist/testkit.d.mts +25 -0
  23. package/dist/testkit.mjs +1 -0
  24. package/examples/basic.ts +33 -0
  25. package/examples/gh/package.json +48 -0
  26. package/examples/gh/src/commands/auth.ts +66 -0
  27. package/examples/gh/src/commands/issue.ts +120 -0
  28. package/examples/gh/src/commands/pr.ts +125 -0
  29. package/examples/gh/src/data/issues.yaml +5 -0
  30. package/examples/gh/src/data/issues.yaml.d.ts +17 -0
  31. package/examples/gh/src/data/pull-requests.yaml +7 -0
  32. package/examples/gh/src/data/pull-requests.yaml.d.ts +18 -0
  33. package/examples/gh/src/lib/auth.ts +37 -0
  34. package/examples/gh/src/lib/utils.ts +17 -0
  35. package/examples/gh/src/main.test.ts +306 -0
  36. package/examples/gh/src/main.ts +38 -0
  37. package/examples/gh/tsconfig.json +37 -0
  38. package/examples/interactive.ts +66 -0
  39. package/examples/json-mode.ts +93 -0
  40. package/examples/middleware.ts +71 -0
  41. package/examples/multi-command.ts +66 -0
  42. package/examples/spinner-progress.ts +49 -0
  43. package/examples/testing.ts +145 -0
  44. package/examples/tsconfig.json +17 -0
  45. package/package.json +123 -2
  46. package/src/core/cli/AGENTS.md +72 -0
  47. package/src/core/cli/dispatch.ts +282 -0
  48. package/src/core/cli/index.ts +1425 -0
  49. package/src/core/cli/plugin.ts +111 -0
  50. package/src/core/cli/propagate.ts +97 -0
  51. package/src/core/cli/root-help.ts +269 -0
  52. package/src/core/cli/root-surface.ts +74 -0
  53. package/src/core/completion/AGENTS.md +72 -0
  54. package/src/core/completion/completion-test-helpers.ts +48 -0
  55. package/src/core/completion/index.ts +82 -0
  56. package/src/core/completion/shells/bash.ts +456 -0
  57. package/src/core/completion/shells/fish.ts +24 -0
  58. package/src/core/completion/shells/powershell.ts +24 -0
  59. package/src/core/completion/shells/shared.ts +283 -0
  60. package/src/core/completion/shells/zsh.ts +376 -0
  61. package/src/core/config/index.ts +404 -0
  62. package/src/core/config/package-json.ts +216 -0
  63. package/src/core/errors/index.ts +178 -0
  64. package/src/core/help/index.ts +559 -0
  65. package/src/core/json-schema/index.ts +705 -0
  66. package/src/core/output/AGENTS.md +69 -0
  67. package/src/core/output/activity.ts +568 -0
  68. package/src/core/output/display-value.ts +48 -0
  69. package/src/core/output/index.ts +704 -0
  70. package/src/core/output/writer.ts +46 -0
  71. package/src/core/parse/index.ts +643 -0
  72. package/src/core/prompt/index.ts +566 -0
  73. package/src/core/resolve/AGENTS.md +69 -0
  74. package/src/core/resolve/index.ts +1331 -0
  75. package/src/core/schema/AGENTS.md +61 -0
  76. package/src/core/schema/activity.ts +237 -0
  77. package/src/core/schema/arg.ts +707 -0
  78. package/src/core/schema/command.ts +1263 -0
  79. package/src/core/schema/flag.ts +651 -0
  80. package/src/core/schema/index.ts +82 -0
  81. package/src/core/schema/middleware.ts +171 -0
  82. package/src/core/schema/prompt.ts +148 -0
  83. package/src/core/schema/run.ts +187 -0
  84. package/src/core/testkit/AGENTS.md +55 -0
  85. package/src/core/testkit/index.ts +365 -0
  86. package/src/index.ts +164 -0
  87. package/src/runtime/AGENTS.md +74 -0
  88. package/src/runtime/adapter.ts +300 -0
  89. package/src/runtime/auto.ts +110 -0
  90. package/src/runtime/bun.ts +55 -0
  91. package/src/runtime/deno.ts +355 -0
  92. package/src/runtime/detect.ts +102 -0
  93. package/src/runtime/index.ts +21 -0
  94. package/src/runtime/node-builtins.d.ts +23 -0
  95. package/src/runtime/node.ts +278 -0
  96. package/src/runtime/paths.ts +56 -0
  97. package/src/runtime/support.ts +119 -0
  98. package/src/runtime/test-helpers.ts +40 -0
  99. package/src/runtime.ts +31 -0
  100. package/src/testkit.ts +23 -0
  101. package/src/version.ts +20 -0
@@ -0,0 +1,278 @@
1
+ /**
2
+ * Node.js runtime adapter implementation.
3
+ *
4
+ * Bridges the platform-agnostic `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 `RuntimeAdapter` interface. I/O writers wrap
10
+ * `process.stdout.write` and `process.stderr.write`.
11
+ *
12
+ * @module 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
+ readonly argv: readonly string[];
46
+ readonly env: Readonly<Record<string, string | undefined>>;
47
+ readonly versions?: {
48
+ readonly node?: string;
49
+ readonly bun?: string;
50
+ };
51
+ cwd(): string;
52
+ /** Platform identifier (e.g. `'linux'`, `'darwin'`, `'win32'`). */
53
+ readonly platform: string;
54
+ readonly stdin: {
55
+ readonly isTTY?: boolean;
56
+ /** Async iterable for reading all of stdin (used by readStdin). */
57
+ [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
58
+ };
59
+ readonly stdout: {
60
+ readonly isTTY?: boolean;
61
+ write(data: string): unknown;
62
+ };
63
+ readonly stderr: {
64
+ write(data: string): unknown;
65
+ };
66
+ exit(code: number): never;
67
+ }
68
+
69
+ // --- Process access — isolated for testability
70
+
71
+ /**
72
+ * Access the global `process` object without importing `@types/node`.
73
+ *
74
+ * Cast through `unknown` to avoid TypeScript errors when `@types/node`
75
+ * isn't installed. Safe because this adapter is only used on Node/Bun
76
+ * where `globalThis.process` is always defined.
77
+ *
78
+ * @internal
79
+ */
80
+ function getNodeProcess(): NodeProcess {
81
+ return (globalThis as unknown as { process: NodeProcess }).process;
82
+ }
83
+
84
+ // --- Filesystem & path helpers — config discovery primitives
85
+
86
+ /**
87
+ * Detect whether an unknown thrown value is a Node.js system error
88
+ * with a string `code` property (e.g. `'ENOENT'`, `'EACCES'`).
89
+ *
90
+ * @internal
91
+ */
92
+ function isNodeSystemError(err: unknown): err is NodeSystemError {
93
+ if (typeof err !== 'object' || err === null || !('code' in err)) return false;
94
+ // After the `in` check, TS narrows err to `object & Record<'code', unknown>`.
95
+ const candidate: { code: unknown } = err;
96
+ return typeof candidate.code === 'string';
97
+ }
98
+
99
+ /**
100
+ * Resolve the user's home directory from environment variables.
101
+ *
102
+ * **Windows** (`win32`): `USERPROFILE` → `HOMEDRIVE`+`HOMEPATH` (both required) → `HOME` → `C:\`
103
+ * **Unix**: `HOME` → `/`
104
+ *
105
+ * `HOMEPATH` alone is never used — it is a relative fragment (e.g. `\Users\alice`) that only
106
+ * makes sense when combined with `HOMEDRIVE` (e.g. `C:`). Using `HOMEPATH` without `HOMEDRIVE`
107
+ * could resolve against the working drive, producing an incorrect path.
108
+ *
109
+ * We avoid importing `node:os` to keep the factory synchronous and
110
+ * to maintain the pattern of deriving everything from the process object.
111
+ *
112
+ * @internal
113
+ */
114
+ function resolveHomedir(
115
+ env: Readonly<Record<string, string | undefined>>,
116
+ platform: string,
117
+ ): string {
118
+ return resolveHomeDirectory(env, platform === 'win32');
119
+ }
120
+
121
+ /**
122
+ * Resolve the platform-specific user configuration directory.
123
+ *
124
+ * - Unix: `$XDG_CONFIG_HOME` (if set), otherwise `~/.config`
125
+ * - Windows: `%APPDATA%` (if set), otherwise `~\AppData\Roaming`
126
+ *
127
+ * @internal
128
+ */
129
+ function resolveConfigDir(
130
+ env: Readonly<Record<string, string | undefined>>,
131
+ platform: string,
132
+ homedir: string,
133
+ ): string {
134
+ return resolveConfigDirectory(env, platform === 'win32', homedir);
135
+ }
136
+
137
+ function assertProcessRuntimeSupported(proc: NodeProcess): void {
138
+ if (proc.versions?.bun !== undefined) {
139
+ assertRuntimeVersionSupported('bun', proc.versions.bun);
140
+ return;
141
+ }
142
+
143
+ assertRuntimeVersionSupported('node', proc.versions?.node);
144
+ }
145
+
146
+ // --- Node adapter factory
147
+
148
+ /**
149
+ * Create a runtime adapter backed by Node.js `process` globals.
150
+ *
151
+ * Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
152
+ * `process.stdout.write`/`process.stderr.write` as `WriteFn` functions.
153
+ *
154
+ * Also works on Bun, which provides a Node-compatible `process` global.
155
+ *
156
+ * @param proc - Override the process object (useful for testing the adapter itself).
157
+ * @returns A `RuntimeAdapter` backed by Node.js process state.
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * import { cli } from 'dreamcli';
162
+ * import { createNodeAdapter } from 'dreamcli/runtime/node';
163
+ *
164
+ * cli('mycli')
165
+ * .command(deploy)
166
+ * .run({ adapter: createNodeAdapter() });
167
+ * ```
168
+ */
169
+ function createNodeAdapter(proc?: NodeProcess): RuntimeAdapter {
170
+ const p = proc ?? getNodeProcess();
171
+ assertProcessRuntimeSupported(p);
172
+
173
+ const stdoutWrite: WriteFn = (data) => {
174
+ p.stdout.write(data);
175
+ };
176
+ const stderrWrite: WriteFn = (data) => {
177
+ p.stderr.write(data);
178
+ };
179
+
180
+ // Stdin line reading via readline — created lazily on first call.
181
+ // This avoids importing readline unless prompting actually occurs.
182
+ const stdinRead: ReadFn = () => createNodeReadLine(p);
183
+
184
+ // --- Filesystem primitives for config discovery ---
185
+
186
+ const readFile = async (path: string): Promise<string | null> => {
187
+ const fs = await import('node:fs/promises');
188
+ try {
189
+ return await fs.readFile(path, 'utf8');
190
+ } catch (err: unknown) {
191
+ // ENOENT = file not found → null (expected for config discovery probing)
192
+ if (isNodeSystemError(err) && err.code === 'ENOENT') {
193
+ return null;
194
+ }
195
+ throw err; // Permission denied, is-directory, etc. → caller handles
196
+ }
197
+ };
198
+
199
+ const homedir = resolveHomedir(p.env, p.platform);
200
+ const configDir = resolveConfigDir(p.env, p.platform, homedir);
201
+
202
+ const stdinIsTTY = p.stdin.isTTY === true;
203
+
204
+ return {
205
+ argv: p.argv,
206
+ env: p.env,
207
+ cwd: p.cwd(),
208
+ stdout: stdoutWrite,
209
+ stderr: stderrWrite,
210
+ stdin: stdinRead,
211
+ readStdin: () => readNodeStdinAll(p, stdinIsTTY),
212
+ isTTY: p.stdout.isTTY === true,
213
+ stdinIsTTY,
214
+ exit: (code) => p.exit(code),
215
+ readFile,
216
+ homedir,
217
+ configDir,
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Read all of stdin as a single string (for piped data).
223
+ *
224
+ * Returns `null` immediately if stdin is a TTY — the user is typing
225
+ * interactively, so there's no piped data to consume. When stdin is
226
+ * piped, collects all chunks via the async iterator until EOF and
227
+ * returns the decoded string, which may be empty for an empty pipe.
228
+ *
229
+ * @internal
230
+ */
231
+ async function readNodeStdinAll(proc: NodeProcess, stdinIsTTY: boolean): Promise<string | null> {
232
+ if (stdinIsTTY) return null;
233
+
234
+ const chunks: string[] = [];
235
+ const decoder = new TextDecoder();
236
+
237
+ for await (const chunk of proc.stdin) {
238
+ chunks.push(decoder.decode(chunk, { stream: true }));
239
+ }
240
+ // Flush any remaining bytes held by the streaming decoder
241
+ chunks.push(decoder.decode());
242
+
243
+ return chunks.join('');
244
+ }
245
+
246
+ /**
247
+ * Read a single line from Node's stdin via its async iterator.
248
+ *
249
+ * Iterates stdin chunks manually (without `for-await` to avoid calling
250
+ * `iterator.return()` which would close the stream). Returns `null`
251
+ * on EOF.
252
+ *
253
+ * @internal
254
+ */
255
+ async function createNodeReadLine(proc: NodeProcess): Promise<string | null> {
256
+ const iter = proc.stdin[Symbol.asyncIterator]();
257
+ const decoder = new TextDecoder();
258
+ let buffer = '';
259
+ let result = await iter.next();
260
+
261
+ while (!result.done) {
262
+ buffer += decoder.decode(result.value, { stream: true });
263
+ const nlIndex = buffer.indexOf('\n');
264
+ if (nlIndex !== -1) {
265
+ return buffer.slice(0, nlIndex).replace(/\r$/, '');
266
+ }
267
+ result = await iter.next();
268
+ }
269
+
270
+ // Flush remaining bytes after stream end
271
+ buffer += decoder.decode();
272
+ return buffer.length > 0 ? buffer : null;
273
+ }
274
+
275
+ // --- Exports
276
+
277
+ export type { NodeProcess };
278
+ export { createNodeAdapter };
@@ -0,0 +1,56 @@
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 dreamcli/runtime/paths
9
+ */
10
+
11
+ /**
12
+ * Resolve the user's home directory from environment variables.
13
+ *
14
+ * @param env - Environment variable map.
15
+ * @param isWindows - Whether the platform is Windows.
16
+ * @returns Absolute path to the home directory.
17
+ * @internal
18
+ */
19
+ function resolveHomeDirectory(
20
+ env: Readonly<Record<string, string | undefined>>,
21
+ isWindows: boolean,
22
+ ): string {
23
+ if (isWindows) {
24
+ if (env.USERPROFILE) return env.USERPROFILE;
25
+ if (env.HOMEDRIVE && env.HOMEPATH) {
26
+ return env.HOMEDRIVE + env.HOMEPATH;
27
+ }
28
+ return env.HOME || 'C:\\';
29
+ }
30
+ return env.HOME || '/';
31
+ }
32
+
33
+ /**
34
+ * Resolve the user's config directory (`XDG_CONFIG_HOME` / `APPDATA`).
35
+ *
36
+ * @param env - Environment variable map.
37
+ * @param isWindows - Whether the platform is Windows.
38
+ * @param homedir - Pre-resolved home directory (from {@link resolveHomeDirectory}).
39
+ * @returns Absolute path to the config directory.
40
+ * @internal
41
+ */
42
+ function resolveConfigDirectory(
43
+ env: Readonly<Record<string, string | undefined>>,
44
+ isWindows: boolean,
45
+ homedir: string,
46
+ ): string {
47
+ if (isWindows) {
48
+ if (env.APPDATA !== undefined && env.APPDATA !== '') return env.APPDATA;
49
+ const normalizedHome = homedir.replace(/[\\/]+$/, '') || homedir;
50
+ return `${normalizedHome}\\AppData\\Roaming`;
51
+ }
52
+ const normalizedHome = homedir.replace(/\/+$/, '') || homedir;
53
+ return env.XDG_CONFIG_HOME || `${normalizedHome}/.config`;
54
+ }
55
+
56
+ export { resolveConfigDirectory, resolveHomeDirectory };
@@ -0,0 +1,119 @@
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 dreamcli/runtime/support
9
+ */
10
+
11
+ type SupportedRuntime = 'node' | 'bun' | 'deno';
12
+
13
+ interface RuntimeSupportEntry {
14
+ readonly runtime: SupportedRuntime;
15
+ readonly displayName: string;
16
+ readonly minimum: string;
17
+ readonly engineRange: string;
18
+ readonly packageName: string;
19
+ readonly adapterName: string;
20
+ }
21
+
22
+ const SUPPORTED_RUNTIMES: readonly RuntimeSupportEntry[] = [
23
+ {
24
+ runtime: 'node',
25
+ displayName: 'Node.js',
26
+ minimum: '22.22.2',
27
+ engineRange: '>=22.22.2',
28
+ packageName: 'dreamcli',
29
+ adapterName: 'NodeAdapter',
30
+ },
31
+ {
32
+ runtime: 'bun',
33
+ displayName: 'Bun',
34
+ minimum: '1.3.11',
35
+ engineRange: '>=1.3.11',
36
+ packageName: 'dreamcli',
37
+ adapterName: 'BunAdapter',
38
+ },
39
+ {
40
+ runtime: 'deno',
41
+ displayName: 'Deno',
42
+ minimum: '2.6.0',
43
+ engineRange: '>=2.6.0',
44
+ packageName: '@kjanat/dreamcli',
45
+ adapterName: 'DenoAdapter',
46
+ },
47
+ ];
48
+
49
+ interface ParsedVersion {
50
+ readonly major: number;
51
+ readonly minor: number;
52
+ readonly patch: number;
53
+ }
54
+
55
+ const VERSION_PATTERN = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?/;
56
+
57
+ function getRuntimeSupport(runtime: SupportedRuntime): RuntimeSupportEntry {
58
+ for (const entry of SUPPORTED_RUNTIMES) {
59
+ if (entry.runtime === runtime) return entry;
60
+ }
61
+
62
+ throw new Error(`Unknown supported runtime '${runtime}'`);
63
+ }
64
+
65
+ function parseVersion(version: string): ParsedVersion | undefined {
66
+ const match = VERSION_PATTERN.exec(version);
67
+ if (match === null) return undefined;
68
+
69
+ const major = Number.parseInt(match[1] ?? '', 10);
70
+ const minorText = match[2];
71
+ const minor = minorText === undefined ? 0 : Number.parseInt(minorText, 10);
72
+ const patchText = match[3];
73
+ const patch = patchText === undefined ? 0 : Number.parseInt(patchText, 10);
74
+
75
+ if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) {
76
+ return undefined;
77
+ }
78
+
79
+ return { major, minor, patch };
80
+ }
81
+
82
+ function compareVersions(left: ParsedVersion, right: ParsedVersion): number {
83
+ if (left.major !== right.major) return left.major - right.major;
84
+ if (left.minor !== right.minor) return left.minor - right.minor;
85
+ return left.patch - right.patch;
86
+ }
87
+
88
+ function formatRuntimeRequirement(runtime: SupportedRuntime): string {
89
+ const support = getRuntimeSupport(runtime);
90
+ return `${support.displayName} >= ${support.minimum}`;
91
+ }
92
+
93
+ function isRuntimeVersionSupported(runtime: SupportedRuntime, version: string): boolean {
94
+ const parsedVersion = parseVersion(version);
95
+ const minimumVersion = parseVersion(getRuntimeSupport(runtime).minimum);
96
+ if (parsedVersion === undefined || minimumVersion === undefined) return false;
97
+ return compareVersions(parsedVersion, minimumVersion) >= 0;
98
+ }
99
+
100
+ function assertRuntimeVersionSupported(
101
+ runtime: SupportedRuntime,
102
+ version: string | undefined,
103
+ ): void {
104
+ if (version === undefined) return;
105
+ if (isRuntimeVersionSupported(runtime, version)) return;
106
+
107
+ throw new Error(
108
+ `dreamcli requires ${formatRuntimeRequirement(runtime)}. Detected ${getRuntimeSupport(runtime).displayName} ${version}.`,
109
+ );
110
+ }
111
+
112
+ export type { RuntimeSupportEntry, SupportedRuntime };
113
+ export {
114
+ assertRuntimeVersionSupported,
115
+ formatRuntimeRequirement,
116
+ getRuntimeSupport,
117
+ isRuntimeVersionSupported,
118
+ SUPPORTED_RUNTIMES,
119
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Shared test helpers for runtime adapter tests.
3
+ *
4
+ * @internal — test-only, not exported from any public barrel.
5
+ * @module dreamcli/runtime/test-helpers
6
+ */
7
+
8
+ import { vi } from 'vitest';
9
+
10
+ /**
11
+ * Create a minimal mock Deno namespace for adapter tests.
12
+ *
13
+ * Tests that exercise the Deno adapter path through `createAdapter()`
14
+ * can pass this namespace via the injected `globals` parameter instead
15
+ * of mutating `globalThis.Deno`.
16
+ *
17
+ * @returns A mock Deno namespace with stubbed I/O, env, and exit.
18
+ */
19
+ export function createMockDenoNamespace() {
20
+ return {
21
+ build: { os: 'linux' as const },
22
+ args: [],
23
+ env: { get: () => undefined, toObject: () => ({}) },
24
+ cwd: () => '/deno/mock',
25
+ stdout: { writeSync: vi.fn(() => 0), isTerminal: () => false },
26
+ stderr: { writeSync: vi.fn(() => 0) },
27
+ stdin: {
28
+ isTerminal: () => false,
29
+ readable: {
30
+ getReader: () => ({
31
+ read: () => Promise.resolve({ done: true, value: undefined }),
32
+ releaseLock: () => {},
33
+ }),
34
+ },
35
+ },
36
+ exit: vi.fn() as unknown as (code: number) => never,
37
+ readTextFile: () => Promise.reject(Object.assign(new Error('not found'), { name: 'NotFound' })),
38
+ version: { deno: '2.6.0' },
39
+ };
40
+ }
package/src/runtime.ts ADDED
@@ -0,0 +1,31 @@
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 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/testkit.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Test utilities for DreamCLI commands.
3
+ *
4
+ * Provides `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 dreamcli/testkit
14
+ */
15
+
16
+ export type { CapturedOutput } from './core/output/index.ts';
17
+ export { createCaptureOutput } from './core/output/index.ts';
18
+ export type { TestAnswer, TestPrompterOptions } from './core/prompt/index.ts';
19
+ export { createTestPrompter, PROMPT_CANCEL } from './core/prompt/index.ts';
20
+ export type { RunOptions, RunResult } from './core/testkit/index.ts';
21
+ export { runCommand } from './core/testkit/index.ts';
22
+ export type { TestAdapterOptions } from './runtime/index.ts';
23
+ export { createTestAdapter } from './runtime/index.ts';
package/src/version.ts ADDED
@@ -0,0 +1,20 @@
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';