@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,2 +1,217 @@
1
- import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";function n(e,t){if(typeof e!=`object`||!e||!(`name`in e))return!1;let n=e;return typeof n.name==`string`&&n.name===t}function r(e){try{return e.env.toObject()}catch(e){if(n(e,`PermissionDenied`))return{};throw e}}function i(e){try{return e.cwd()}catch(e){if(n(e,`PermissionDenied`))return`/`;throw e}}function a(e){let t=e??o(),a=new TextEncoder,d=[`deno`,`run`,...t.args],f=r(t),p=i(t),m=e=>{t.stdout.writeSync(a.encode(e))},h=e=>{t.stderr.writeSync(a.encode(e))},g=c(t),_=async e=>{try{return await t.readTextFile(e)}catch(e){if(n(e,`NotFound`)||n(e,`PermissionDenied`))return null;throw e}},v=l(f,t.build.os===`windows`),y=u(f,v,t.build.os===`windows`),b=t.stdin.isTerminal();return{argv:d,env:f,cwd:p,stdout:m,stderr:h,stdin:g,readStdin:()=>s(t,b),isTTY:t.stdout.isTerminal(),stdinIsTTY:b,exit:e=>t.exit(e),readFile:_,homedir:v,configDir:y}}function o(){return globalThis.Deno}async function s(e,t){if(t)return null;let n=e.stdin.readable.getReader(),r=new TextDecoder,i=[];try{for(;;){let{value:e,done:t}=await n.read();if(t){i.push(r.decode());break}i.push(r.decode(e,{stream:!0}))}}finally{n.releaseLock()}return i.join(``)}function c(e){let t=new TextDecoder,n=``,r=!1;return async()=>{let i=e.stdin.readable.getReader();try{for(;;){let e=n.indexOf(`
2
- `);if(e!==-1){let t=n.slice(0,e).replace(/\r$/,``);return n=n.slice(e+1),t}if(r){if(n.length===0)return null;let e=n;return n=``,e}let{value:a,done:o}=await i.read();if(o){n+=t.decode(),r=!0;continue}n+=t.decode(a,{stream:!0})}}finally{i.releaseLock()}}}function l(e,n){return t(e,n)}function u(t,n,r){return e(t,r,n)}export{a as createDenoAdapter};
1
+ import { resolveConfigDirectory, resolveHomeDirectory } from "./paths.mjs";
2
+ //#region src/runtime/deno.ts
3
+ /**
4
+ * Detect whether an unknown thrown value is a Deno error by name.
5
+ *
6
+ * @internal
7
+ */
8
+ function isDenoErrorNamed(err, name) {
9
+ if (typeof err !== "object" || err === null || !("name" in err)) return false;
10
+ const candidate = err;
11
+ return typeof candidate.name === "string" && candidate.name === name;
12
+ }
13
+ /**
14
+ * Safely read all environment variables. Returns empty object if
15
+ * `--allow-env` permission is not granted.
16
+ *
17
+ * @internal
18
+ */
19
+ function safeEnvToObject(deno) {
20
+ try {
21
+ return deno.env.toObject();
22
+ } catch (err) {
23
+ if (isDenoErrorNamed(err, "PermissionDenied")) return {};
24
+ throw err;
25
+ }
26
+ }
27
+ /**
28
+ * Safely get the current working directory. Returns `/` if the cwd is
29
+ * inaccessible due to missing permissions.
30
+ *
31
+ * @internal
32
+ */
33
+ function safeCwd(deno) {
34
+ try {
35
+ return deno.cwd();
36
+ } catch (err) {
37
+ if (isDenoErrorNamed(err, "PermissionDenied")) return "/";
38
+ throw err;
39
+ }
40
+ }
41
+ /**
42
+ * Create a runtime adapter backed by the Deno namespace.
43
+ *
44
+ * Reads `Deno.args`, `Deno.env`, `Deno.cwd()`, and wraps Deno's stream-based
45
+ * I/O into the {@linkcode WriteFn}/{@linkcode ReadFn} functions expected by the framework.
46
+ *
47
+ * Unlike Node/Bun, Deno strips the binary and script path from `Deno.args`.
48
+ * The adapter prepends synthetic entries (`['deno', 'run']`) so the argv
49
+ * shape matches the {@linkcode RuntimeAdapter} contract (binary + script + user args).
50
+ *
51
+ * @param ns - Override the Deno namespace (useful for testing the adapter itself).
52
+ * @returns A {@linkcode RuntimeAdapter} backed by Deno's namespace APIs.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { cli } from '@kjanat/dreamcli';
57
+ * import { createDenoAdapter } from '@kjanat/dreamcli/runtime';
58
+ *
59
+ * cli('mycli')
60
+ * .command(deploy)
61
+ * .run({ adapter: createDenoAdapter() });
62
+ * ```
63
+ */
64
+ function createDenoAdapter(ns) {
65
+ const d = ns ?? getDenoNamespace();
66
+ const encoder = new TextEncoder();
67
+ const argv = [
68
+ "deno",
69
+ "run",
70
+ ...d.args
71
+ ];
72
+ const env = safeEnvToObject(d);
73
+ const cwd = safeCwd(d);
74
+ const stdoutWrite = (data) => {
75
+ d.stdout.writeSync(encoder.encode(data));
76
+ };
77
+ const stderrWrite = (data) => {
78
+ d.stderr.writeSync(encoder.encode(data));
79
+ };
80
+ const stdinRead = createDenoReadLine(d);
81
+ const readFile = async (path) => {
82
+ try {
83
+ return await d.readTextFile(path);
84
+ } catch (err) {
85
+ if (isDenoErrorNamed(err, "NotFound")) return null;
86
+ if (isDenoErrorNamed(err, "PermissionDenied")) return null;
87
+ throw err;
88
+ }
89
+ };
90
+ const homedir = resolveDenoHomedir(env, d.build.os === "windows");
91
+ const configDir = resolveDenoConfigDir(env, homedir, d.build.os === "windows");
92
+ const stdinIsTTY = d.stdin.isTerminal();
93
+ return {
94
+ argv,
95
+ env,
96
+ cwd,
97
+ stdout: stdoutWrite,
98
+ stderr: stderrWrite,
99
+ stdin: stdinRead,
100
+ readStdin: () => readDenoStdinAll(d, stdinIsTTY),
101
+ isTTY: d.stdout.isTerminal(),
102
+ stdinIsTTY,
103
+ exit: (code) => d.exit(code),
104
+ readFile,
105
+ homedir,
106
+ configDir
107
+ };
108
+ }
109
+ /**
110
+ * Access the global `Deno` namespace.
111
+ *
112
+ * Cast through `unknown` to avoid TypeScript errors when Deno types
113
+ * aren't installed. Safe because this adapter is only used on Deno
114
+ * where `globalThis.Deno` is always defined.
115
+ *
116
+ * @internal
117
+ */
118
+ function getDenoNamespace() {
119
+ return globalThis.Deno;
120
+ }
121
+ /**
122
+ * Read all of stdin as a single string (for piped data).
123
+ *
124
+ * Returns `null` immediately if stdin is a TTY — the user is typing
125
+ * interactively, so there's no piped data to consume. When stdin is
126
+ * piped, collects all chunks via the `ReadableStream` until EOF and
127
+ * returns the decoded string, which may be empty for an empty pipe.
128
+ *
129
+ * @internal
130
+ */
131
+ async function readDenoStdinAll(deno, stdinIsTTY) {
132
+ if (stdinIsTTY) return null;
133
+ const reader = deno.stdin.readable.getReader();
134
+ const decoder = new TextDecoder();
135
+ const chunks = [];
136
+ try {
137
+ for (;;) {
138
+ const { value, done } = await reader.read();
139
+ if (done) {
140
+ chunks.push(decoder.decode());
141
+ break;
142
+ }
143
+ chunks.push(decoder.decode(value, { stream: true }));
144
+ }
145
+ } finally {
146
+ reader.releaseLock();
147
+ }
148
+ return chunks.join("");
149
+ }
150
+ /**
151
+ * Read a single line from Deno's stdin.
152
+ *
153
+ * Uses the `ReadableStream` API with a manual buffer to read until
154
+ * a newline character is found. Returns `null` on EOF.
155
+ *
156
+ * This is intentionally simple — the terminal prompter handles retries
157
+ * and validation.
158
+ *
159
+ * @internal
160
+ */
161
+ function createDenoReadLine(deno) {
162
+ const decoder = new TextDecoder();
163
+ let buffer = "";
164
+ let done = false;
165
+ return async () => {
166
+ const reader = deno.stdin.readable.getReader();
167
+ try {
168
+ for (;;) {
169
+ const newlineIndex = buffer.indexOf("\n");
170
+ if (newlineIndex !== -1) {
171
+ const line = buffer.slice(0, newlineIndex).replace(/\r$/, "");
172
+ buffer = buffer.slice(newlineIndex + 1);
173
+ return line;
174
+ }
175
+ if (done) {
176
+ if (buffer.length === 0) return null;
177
+ const line = buffer;
178
+ buffer = "";
179
+ return line;
180
+ }
181
+ const { value, done: readDone } = await reader.read();
182
+ if (readDone) {
183
+ buffer += decoder.decode();
184
+ done = true;
185
+ continue;
186
+ }
187
+ buffer += decoder.decode(value, { stream: true });
188
+ }
189
+ } finally {
190
+ reader.releaseLock();
191
+ }
192
+ };
193
+ }
194
+ /**
195
+ * Resolve the user's home directory from environment variables.
196
+ *
197
+ * Deno doesn't expose `os.homedir()` without `--allow-sys`, so we derive
198
+ * it from env vars — same approach as the Node adapter.
199
+ *
200
+ * @internal
201
+ */
202
+ function resolveDenoHomedir(env, isWindows) {
203
+ return resolveHomeDirectory(env, isWindows);
204
+ }
205
+ /**
206
+ * Resolve the platform-specific user configuration directory.
207
+ *
208
+ * Uses `Deno.build.os` for platform detection, then applies the same fallback
209
+ * chain as the Node adapter.
210
+ *
211
+ * @internal
212
+ */
213
+ function resolveDenoConfigDir(env, homedir, isWindows) {
214
+ return resolveConfigDirectory(env, isWindows, homedir);
215
+ }
216
+ //#endregion
217
+ export { createDenoAdapter };
@@ -1 +1,45 @@
1
- const e=[`node`,`bun`,`deno`,`unknown`];function t(e){let t=e??globalThis;return typeof t.Bun?.version==`string`?`bun`:typeof t.Deno?.version?.deno==`string`?`deno`:typeof t.process?.versions?.node==`string`?`node`:`unknown`}export{e as RUNTIMES,t as detectRuntime};
1
+ //#region src/runtime/detect.ts
2
+ /**
3
+ * All known runtime values as a readonly tuple.
4
+ *
5
+ * Useful for validation, iteration, and exhaustiveness checks.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * if (RUNTIMES.includes(value)) {
10
+ * // value is a valid Runtime
11
+ * }
12
+ * ```
13
+ */
14
+ const RUNTIMES = [
15
+ "node",
16
+ "bun",
17
+ "deno",
18
+ "unknown"
19
+ ];
20
+ /**
21
+ * Detect the current JavaScript runtime.
22
+ *
23
+ * Uses `globalThis` feature detection to identify the host runtime.
24
+ * Detection order is significant: Bun is checked before Node because
25
+ * Bun exposes a Node-compatible `process` global.
26
+ *
27
+ * @param globals - Override `globalThis` for testing. Production callers
28
+ * should omit this parameter.
29
+ * @returns The detected {@link Runtime} identifier.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const rt = detectRuntime();
34
+ * // rt === 'node' | 'bun' | 'deno' | 'unknown'
35
+ * ```
36
+ */
37
+ function detectRuntime(globals) {
38
+ const g = globals ?? globalThis;
39
+ if (typeof g.Bun?.version === "string") return "bun";
40
+ if (typeof g.Deno?.version?.deno === "string") return "deno";
41
+ if (typeof g.process?.versions?.node === "string") return "node";
42
+ return "unknown";
43
+ }
44
+ //#endregion
45
+ export { RUNTIMES, detectRuntime };
@@ -1,2 +1,169 @@
1
- import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";function n(){return globalThis.process}function r(e){return typeof e!=`object`||!e||!(`code`in e)?!1:typeof e.code==`string`}function i(e,n){return t(e,n===`win32`)}function a(t,n,r){return e(t,n===`win32`,r)}function o(e){let t=e??n(),o=e=>{t.stdout.write(e)},l=e=>{t.stderr.write(e)},u=c(t),d=async e=>{let t=await import(`node:fs/promises`);try{return await t.readFile(e,`utf8`)}catch(e){if(r(e)&&e.code===`ENOENT`)return null;throw e}},f=i(t.env,t.platform),p=a(t.env,t.platform,f),m=t.stdin.isTTY===!0;return{argv:t.argv,env:t.env,cwd:t.cwd(),stdout:o,stderr:l,stdin:u,readStdin:()=>s(t,m),isTTY:t.stdout.isTTY===!0,stdinIsTTY:m,exit:e=>t.exit(e),readFile:d,homedir:f,configDir:p}}async function s(e,t){if(t)return null;let n=[],r=new TextDecoder;for await(let t of e.stdin)n.push(r.decode(t,{stream:!0}));return n.push(r.decode()),n.join(``)}function c(e){let t=e.stdin[Symbol.asyncIterator](),n=new TextDecoder,r=``,i=!1;return async()=>{for(;;){let e=r.indexOf(`
2
- `);if(e!==-1){let t=r.slice(0,e).replace(/\r$/,``);return r=r.slice(e+1),t}if(i){if(r.length===0)return null;let e=r;return r=``,e}let a=await t.next();if(a.done){r+=n.decode(),i=!0;continue}r+=n.decode(a.value,{stream:!0})}}}export{o as createNodeAdapter};
1
+ import { resolveConfigDirectory, resolveHomeDirectory } from "./paths.mjs";
2
+ //#region src/runtime/node.ts
3
+ /**
4
+ * Access the global `process` object without importing `@types/node`.
5
+ *
6
+ * Cast through `unknown` to avoid TypeScript errors when `@types/node`
7
+ * isn't installed. Safe because this adapter is only used on Node/Bun
8
+ * where `globalThis.process` is always defined.
9
+ *
10
+ * @internal
11
+ */
12
+ function getNodeProcess() {
13
+ return globalThis.process;
14
+ }
15
+ /**
16
+ * Detect whether an unknown thrown value is a Node.js system error
17
+ * with a string `code` property (e.g. `'ENOENT'`, `'EACCES'`).
18
+ *
19
+ * @internal
20
+ */
21
+ function isNodeSystemError(err) {
22
+ if (typeof err !== "object" || err === null || !("code" in err)) return false;
23
+ return typeof err.code === "string";
24
+ }
25
+ /**
26
+ * Resolve the user's home directory from environment variables.
27
+ *
28
+ * **Windows** (`win32`): `USERPROFILE` → `HOMEDRIVE`+`HOMEPATH` (both required) → `HOME` → `C:\`
29
+ * **Unix**: `HOME` → `/`
30
+ *
31
+ * `HOMEPATH` alone is never used — it is a relative fragment (e.g. `\Users\alice`) that only
32
+ * makes sense when combined with `HOMEDRIVE` (e.g. `C:`). Using `HOMEPATH` without `HOMEDRIVE`
33
+ * could resolve against the working drive, producing an incorrect path.
34
+ *
35
+ * We avoid importing `node:os` to keep the factory synchronous and
36
+ * to maintain the pattern of deriving everything from the process object.
37
+ *
38
+ * @internal
39
+ */
40
+ function resolveHomedir(env, platform) {
41
+ return resolveHomeDirectory(env, platform === "win32");
42
+ }
43
+ /**
44
+ * Resolve the platform-specific user configuration directory.
45
+ *
46
+ * - Unix: `$XDG_CONFIG_HOME` (if set), otherwise `~/.config`
47
+ * - Windows: `%APPDATA%` (if set), otherwise `~\AppData\Roaming`
48
+ *
49
+ * @internal
50
+ */
51
+ function resolveConfigDir(env, platform, homedir) {
52
+ return resolveConfigDirectory(env, platform === "win32", homedir);
53
+ }
54
+ /**
55
+ * Create a runtime adapter backed by Node.js `process` globals.
56
+ *
57
+ * Reads `process.argv`, `process.env`, `process.cwd()`, and wraps
58
+ * `process.stdout.write`/`process.stderr.write` as {@linkcode WriteFn} functions.
59
+ *
60
+ * Also works on Bun, which provides a Node-compatible `process` global.
61
+ *
62
+ * @param proc - Override the process object (useful for testing the adapter itself).
63
+ * @returns A {@linkcode RuntimeAdapter} backed by Node.js process state.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { cli } from '@kjanat/dreamcli';
68
+ * import { createNodeAdapter } from '@kjanat/dreamcli/runtime/node';
69
+ *
70
+ * cli('mycli')
71
+ * .command(deploy)
72
+ * .run({ adapter: createNodeAdapter() });
73
+ * ```
74
+ */
75
+ function createNodeAdapter(proc) {
76
+ const p = proc ?? getNodeProcess();
77
+ const stdoutWrite = (data) => {
78
+ p.stdout.write(data);
79
+ };
80
+ const stderrWrite = (data) => {
81
+ p.stderr.write(data);
82
+ };
83
+ const stdinRead = createNodeReadLine(p);
84
+ const readFile = async (path) => {
85
+ const fs = await import("node:fs/promises");
86
+ try {
87
+ return await fs.readFile(path, "utf8");
88
+ } catch (err) {
89
+ if (isNodeSystemError(err) && err.code === "ENOENT") return null;
90
+ throw err;
91
+ }
92
+ };
93
+ const homedir = resolveHomedir(p.env, p.platform);
94
+ const configDir = resolveConfigDir(p.env, p.platform, homedir);
95
+ const stdinIsTTY = p.stdin.isTTY === true;
96
+ return {
97
+ argv: p.argv,
98
+ env: p.env,
99
+ cwd: p.cwd(),
100
+ stdout: stdoutWrite,
101
+ stderr: stderrWrite,
102
+ stdin: stdinRead,
103
+ readStdin: () => readNodeStdinAll(p, stdinIsTTY),
104
+ isTTY: p.stdout.isTTY === true,
105
+ stdinIsTTY,
106
+ exit: (code) => p.exit(code),
107
+ readFile,
108
+ homedir,
109
+ configDir
110
+ };
111
+ }
112
+ /**
113
+ * Read all of stdin as a single string (for piped data).
114
+ *
115
+ * Returns `null` immediately if stdin is a TTY — the user is typing
116
+ * interactively, so there's no piped data to consume. When stdin is
117
+ * piped, collects all chunks via the async iterator until EOF and
118
+ * returns the decoded string, which may be empty for an empty pipe.
119
+ *
120
+ * @internal
121
+ */
122
+ async function readNodeStdinAll(proc, stdinIsTTY) {
123
+ if (stdinIsTTY) return null;
124
+ const chunks = [];
125
+ const decoder = new TextDecoder();
126
+ for await (const chunk of proc.stdin) chunks.push(decoder.decode(chunk, { stream: true }));
127
+ chunks.push(decoder.decode());
128
+ return chunks.join("");
129
+ }
130
+ /**
131
+ * Read a single line from Node's stdin via its async iterator.
132
+ *
133
+ * Iterates stdin chunks manually (without `for-await` to avoid calling
134
+ * `iterator.return()` which would close the stream). Returns `null`
135
+ * on EOF.
136
+ *
137
+ * @internal
138
+ */
139
+ function createNodeReadLine(proc) {
140
+ const iter = proc.stdin[Symbol.asyncIterator]();
141
+ const decoder = new TextDecoder();
142
+ let buffer = "";
143
+ let done = false;
144
+ return async () => {
145
+ for (;;) {
146
+ const nlIndex = buffer.indexOf("\n");
147
+ if (nlIndex !== -1) {
148
+ const line = buffer.slice(0, nlIndex).replace(/\r$/, "");
149
+ buffer = buffer.slice(nlIndex + 1);
150
+ return line;
151
+ }
152
+ if (done) {
153
+ if (buffer.length === 0) return null;
154
+ const line = buffer;
155
+ buffer = "";
156
+ return line;
157
+ }
158
+ const result = await iter.next();
159
+ if (result.done) {
160
+ buffer += decoder.decode();
161
+ done = true;
162
+ continue;
163
+ }
164
+ buffer += decoder.decode(result.value, { stream: true });
165
+ }
166
+ };
167
+ }
168
+ //#endregion
169
+ export { createNodeAdapter };
@@ -1 +1,48 @@
1
- import{stripTrailing as e}from"../strings.mjs";function t(e,t){return t?e.USERPROFILE?e.USERPROFILE:e.HOMEDRIVE&&e.HOMEPATH?e.HOMEDRIVE+e.HOMEPATH:e.HOME||`C:\\`:e.HOME||`/`}function n(t,n,r){if(n)return t.APPDATA!==void 0&&t.APPDATA!==``?t.APPDATA:`${e(r,[47,92])||r}\\AppData\\Roaming`;let i=e(r,[47]);return t.XDG_CONFIG_HOME!==void 0&&t.XDG_CONFIG_HOME!==``?t.XDG_CONFIG_HOME:i.length===0?`/.config`:`${i}/.config`}export{n as resolveConfigDirectory,t as resolveHomeDirectory};
1
+ import { stripTrailing } from "../strings.mjs";
2
+ //#region src/runtime/paths.ts
3
+ /**
4
+ * Shared env-based path resolution for runtime adapters.
5
+ *
6
+ * Node, Bun, and Deno all need the same user home/config directory behavior.
7
+ * These helpers keep the fallback chain identical across runtimes while
8
+ * letting each adapter supply its own platform detection.
9
+ *
10
+ * @module @kjanat/dreamcli/runtime/paths
11
+ */
12
+ /**
13
+ * Resolve the user's home directory from environment variables.
14
+ *
15
+ * @param env - Environment variable map.
16
+ * @param isWindows - Whether the platform is Windows.
17
+ * @returns Absolute path to the home directory.
18
+ * @internal
19
+ */
20
+ function resolveHomeDirectory(env, isWindows) {
21
+ if (isWindows) {
22
+ if (env.USERPROFILE) return env.USERPROFILE;
23
+ if (env.HOMEDRIVE && env.HOMEPATH) return env.HOMEDRIVE + env.HOMEPATH;
24
+ return env.HOME || "C:\\";
25
+ }
26
+ return env.HOME || "/";
27
+ }
28
+ /**
29
+ * Resolve the user's config directory (`XDG_CONFIG_HOME` / `APPDATA`).
30
+ *
31
+ * @param env - Environment variable map.
32
+ * @param isWindows - Whether the platform is Windows.
33
+ * @param homedir - Pre-resolved home directory (from {@link resolveHomeDirectory}).
34
+ * @returns Absolute path to the config directory.
35
+ * @internal
36
+ */
37
+ function resolveConfigDirectory(env, isWindows, homedir) {
38
+ if (isWindows) {
39
+ if (env.APPDATA !== void 0 && env.APPDATA !== "") return env.APPDATA;
40
+ return `${stripTrailing(homedir, [47, 92]) || homedir}\\AppData\\Roaming`;
41
+ }
42
+ const normalizedHome = stripTrailing(homedir, [47]);
43
+ if (env.XDG_CONFIG_HOME !== void 0 && env.XDG_CONFIG_HOME !== "") return env.XDG_CONFIG_HOME;
44
+ if (normalizedHome.length === 0) return "/.config";
45
+ return `${normalizedHome}/.config`;
46
+ }
47
+ //#endregion
48
+ export { resolveConfigDirectory, resolveHomeDirectory };
package/dist/runtime.mjs CHANGED
@@ -1 +1,7 @@
1
- import{createNodeAdapter as e}from"./runtime/node.mjs";import{createBunAdapter as t}from"./runtime/bun.mjs";import{createDenoAdapter as n}from"./runtime/deno.mjs";import{RUNTIMES as r,detectRuntime as i}from"./runtime/detect.mjs";import{createAdapter as a}from"./runtime/auto.mjs";import{ExitError as o}from"./runtime/adapter.mjs";export{o as ExitError,r as RUNTIMES,a as createAdapter,t as createBunAdapter,n as createDenoAdapter,e as createNodeAdapter,i as detectRuntime};
1
+ import { createNodeAdapter } from "./runtime/node.mjs";
2
+ import { createBunAdapter } from "./runtime/bun.mjs";
3
+ import { createDenoAdapter } from "./runtime/deno.mjs";
4
+ import { RUNTIMES, detectRuntime } from "./runtime/detect.mjs";
5
+ import { createAdapter } from "./runtime/auto.mjs";
6
+ import { ExitError } from "./runtime/adapter.mjs";
7
+ export { ExitError, RUNTIMES, createAdapter, createBunAdapter, createDenoAdapter, createNodeAdapter, detectRuntime };
package/dist/strings.mjs CHANGED
@@ -1 +1,22 @@
1
- function e(e,t){let n=e.length;for(;n>0&&t.includes(e.charCodeAt(n-1));)--n;return n===e.length?e:e.slice(0,n)}export{e as stripTrailing};
1
+ //#region src/strings.ts
2
+ /**
3
+ * Remove trailing characters whose code points appear in `codes`.
4
+ *
5
+ * Linear-time replacement for trailing-character regexes such as
6
+ * `/[\\/]+$/`. Those patterns are polynomial-ReDoS prone: the engine
7
+ * greedily consumes the run, fails the end anchor, backtracks one
8
+ * character at a time, and repeats that work from every start position —
9
+ * O(n²) on adversarial input. This scan is O(n) with no backtracking.
10
+ *
11
+ * @param input - Source string.
12
+ * @param codes - Character codes to strip from the end of `input`.
13
+ * @returns `input` with all trailing matching characters removed.
14
+ * @internal
15
+ */
16
+ function stripTrailing(input, codes) {
17
+ let end = input.length;
18
+ while (end > 0 && codes.includes(input.charCodeAt(end - 1))) end -= 1;
19
+ return end === input.length ? input : input.slice(0, end);
20
+ }
21
+ //#endregion
22
+ export { stripTrailing };
package/dist/testkit.mjs CHANGED
@@ -1 +1,5 @@
1
- import{createCaptureOutput as e}from"./core/output/index.mjs";import{PROMPT_CANCEL as t,createTestPrompter as n}from"./core/prompt/index.mjs";import{runCommand as r}from"./core/testkit/index.mjs";import{createTestAdapter as i}from"./runtime/adapter.mjs";export{t as PROMPT_CANCEL,e as createCaptureOutput,i as createTestAdapter,n as createTestPrompter,r as runCommand};
1
+ import { createCaptureOutput } from "./core/output/index.mjs";
2
+ import { PROMPT_CANCEL, createTestPrompter } from "./core/prompt/index.mjs";
3
+ import { runCommand } from "./core/testkit/index.mjs";
4
+ import { createTestAdapter } from "./runtime/adapter.mjs";
5
+ export { PROMPT_CANCEL, createCaptureOutput, createTestAdapter, createTestPrompter, runCommand };
@@ -1,12 +1,16 @@
1
1
  //#region src/version.d.ts
2
2
  /**
3
- * Build-time version constants.
3
+ * DreamCLI's own build-time version constants.
4
+ *
5
+ * Not the app version configured via `cli().version(...)` — these identify
6
+ * the framework build itself (diagnostics, bug reports, completion-script
7
+ * stamps). Kept on a dedicated subpath so they stay out of root-entrypoint
8
+ * import completions.
4
9
  *
5
10
  * Replaced by tsdown `define` during bundling. In development (unbundled),
6
11
  * the declared globals resolve to the `'dev'` fallback.
7
12
  *
8
- * @module dreamcli/version
9
- * @internal
13
+ * @module @kjanat/dreamcli/version
10
14
  */
11
15
  /** Package version (e.g. `"0.9.1"`). `"dev"` when running unbundled. */
12
16
  declare const DREAMCLI_VERSION: string;
package/dist/version.mjs CHANGED
@@ -1 +1,7 @@
1
- const e=`3.0.0-rc.1`,t=`c3bcd04`;export{t as DREAMCLI_REVISION,e as DREAMCLI_VERSION};
1
+ //#region src/version.ts
2
+ /** Package version (e.g. `"0.9.1"`). `"dev"` when running unbundled. */
3
+ const DREAMCLI_VERSION = "3.0.0-rc.3";
4
+ /** Git short SHA (e.g. `"f9b5f1a"`). `"dev"` when running unbundled. */
5
+ const DREAMCLI_REVISION = "539c625";
6
+ //#endregion
7
+ export { DREAMCLI_REVISION, DREAMCLI_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kjanat/dreamcli",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.3",
4
4
  "description": "Schema-first, fully typed TypeScript CLI framework",
5
5
  "keywords": ["dreamcli", "cli", "typescript", "framework", "schema-first", "command-line"],
6
6
  "homepage": "https://dreamcli.kjanat.dev",
@@ -29,37 +29,29 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/index.d.mts",
32
- "bun": "./src/index.ts",
33
- "deno": "./src/index.ts",
34
32
  "default": "./dist/index.mjs"
35
33
  },
36
34
  "./runtime": {
37
35
  "types": "./dist/runtime.d.mts",
38
- "bun": "./src/runtime.ts",
39
- "deno": "./src/runtime.ts",
40
36
  "default": "./dist/runtime.mjs"
41
37
  },
42
38
  "./testkit": {
43
39
  "types": "./dist/testkit.d.mts",
44
- "bun": "./src/testkit.ts",
45
- "deno": "./src/testkit.ts",
46
40
  "default": "./dist/testkit.mjs"
47
41
  },
48
- "./schema": "./dreamcli.schema.json",
49
- "./package.json": "./package.json"
42
+ "./version": {
43
+ "types": "./dist/version.d.mts",
44
+ "default": "./dist/version.mjs"
45
+ },
46
+ "./package.json": "./package.json",
47
+ "./schema": "./dreamcli.schema.json"
50
48
  },
51
49
  "files": [
52
50
  "CHANGELOG.md",
53
- "LICENSE",
54
- "README.md",
55
51
  "dist",
56
52
  "dreamcli.schema.json",
57
53
  "examples",
58
- "!examples/.cache",
59
- "package.json",
60
- "src",
61
- "!src/**/*.test.ts",
62
- "!src/**/*test-helpers.ts",
54
+ "!**/.cache",
63
55
  "!**/AGENTS.md"
64
56
  ],
65
57
  "workspaces": ["./examples/*"],
@@ -109,30 +101,33 @@
109
101
  "overrides": {
110
102
  "vitepress": "next"
111
103
  },
104
+ "dependencies": {
105
+ "ansispeck": "^0.1.2"
106
+ },
112
107
  "devDependencies": {
113
108
  "@arethetypeswrong/core": "^0.18.4",
114
- "@biomejs/biome": "^2.5.1",
109
+ "@biomejs/biome": "^2.5.2",
115
110
  "@iarna/toml": "^2.2.5",
116
- "@shikijs/transformers": "^4.3.0",
117
- "@shikijs/vitepress-twoslash": "^4.3.0",
111
+ "@shikijs/transformers": "^4.3.1",
112
+ "@shikijs/vitepress-twoslash": "^4.3.1",
118
113
  "@types/bun": "^1.3.14",
119
114
  "@types/deno": "^2.7.0",
120
- "@types/node": ">=26.0.1",
121
- "@typescript/native-preview": "^7.0.0-dev.20260629.1",
115
+ "@types/node": ">=26.1.0",
116
+ "@typescript/native-preview": "^7.0.0-dev.20260705.1",
122
117
  "@vitest/coverage-v8": "^4.1.9",
123
118
  "dprint": "^0.55.1",
124
119
  "floating-vue": "^5.2.2",
125
- "knip": "^6.23.0",
120
+ "knip": "^6.24.0",
126
121
  "mermaid": "^11.16.0",
127
122
  "publint": "^0.3.21",
128
- "runner-run": "0.15.0",
123
+ "runner-run": "0.19.1",
129
124
  "tsdown": "^0.22.3",
130
125
  "typedoc": "^0.28.19",
131
126
  "typescript": "^6.0.3",
132
- "vite": "^8.1.0",
127
+ "vite": "^8.1.3",
133
128
  "vitepress": "^2.0.0-alpha.17",
134
129
  "vitest": "^4.1.9",
135
- "wrangler": "^4.105.0",
130
+ "wrangler": "^4.107.0",
136
131
  "yaml": "^2.9.0"
137
132
  },
138
133
  "packageManager": "bun@1.3.14",
@@ -161,7 +156,7 @@
161
156
  },
162
157
  "catalog": {
163
158
  "@types/bun": "^1.3.14",
164
- "@types/node": ">=26.0.1",
159
+ "@types/node": ">=26.1.0",
165
160
  "typescript": "^6.0.3"
166
161
  }
167
162
  }