@kjanat/dreamcli 4.0.0-rc.3 → 4.1.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 (212) hide show
  1. package/README.md +5 -7
  2. package/dist/{runtime/adapter.d.mts → adapter-YM5QGi3M.d.mts} +4 -4
  3. package/dist/completion-CUMeOnAz.mjs +6 -0
  4. package/dist/completion.d.mts +90 -0
  5. package/dist/completion.mjs +1 -0
  6. package/dist/config-CrlScpYX.mjs +1 -0
  7. package/dist/config.d.mts +2 -0
  8. package/dist/config.mjs +1 -0
  9. package/dist/core-DvXUolc_.mjs +17 -0
  10. package/dist/{core/json-schema/index.d.mts → index-3l8uj16E.d.mts} +43 -34
  11. package/dist/{core/cli/index.d.mts → index-BAj2y70U.d.mts} +116 -57
  12. package/dist/index-BziI2aKc.d.mts +5440 -0
  13. package/dist/index-Cap0MA2V.d.mts +277 -0
  14. package/dist/index-Cp9kt2t-.d.mts +370 -0
  15. package/dist/index-DWsnGZlx.d.mts +831 -0
  16. package/dist/index.d.mts +190 -41
  17. package/dist/index.mjs +1 -26
  18. package/dist/json-schema-DRlrz_IV.mjs +52 -0
  19. package/dist/json-schema.d.mts +2 -0
  20. package/dist/json-schema.mjs +1 -0
  21. package/dist/package-json-BgE9YjjQ.mjs +3 -0
  22. package/dist/prompt.d.mts +48 -0
  23. package/dist/prompt.mjs +1 -0
  24. package/dist/rolldown-runtime-G4Kt5YOX.mjs +1 -0
  25. package/dist/runtime.d.mts +2 -6
  26. package/dist/runtime.mjs +1 -6
  27. package/dist/terminal-C8KTXjv5.mjs +6 -0
  28. package/dist/test-prompter-v__jT2yG.mjs +1 -0
  29. package/dist/testkit.d.mts +54 -6
  30. package/dist/testkit.mjs +1 -5
  31. package/dist/version.mjs +1 -7
  32. package/dreamcli.schema.json +697 -538
  33. package/package.json +29 -7
  34. package/skills/cli-creation/SKILL.md +16 -11
  35. package/CHANGELOG.md +0 -1116
  36. package/dist/core/cli/builtins.d.mts +0 -117
  37. package/dist/core/cli/builtins.mjs +0 -135
  38. package/dist/core/cli/compiled.d.mts +0 -66
  39. package/dist/core/cli/compiled.mjs +0 -76
  40. package/dist/core/cli/dispatch.d.mts +0 -115
  41. package/dist/core/cli/dispatch.mjs +0 -205
  42. package/dist/core/cli/help-links.d.mts +0 -27
  43. package/dist/core/cli/help-links.mjs +0 -41
  44. package/dist/core/cli/index.mjs +0 -1271
  45. package/dist/core/cli/planner.d.mts +0 -174
  46. package/dist/core/cli/planner.mjs +0 -323
  47. package/dist/core/cli/plugin.d.mts +0 -94
  48. package/dist/core/cli/plugin.mjs +0 -41
  49. package/dist/core/cli/propagate.d.mts +0 -39
  50. package/dist/core/cli/propagate.mjs +0 -57
  51. package/dist/core/cli/reserved-flags.d.mts +0 -19
  52. package/dist/core/cli/reserved-flags.mjs +0 -158
  53. package/dist/core/cli/root-help.d.mts +0 -53
  54. package/dist/core/cli/root-help.mjs +0 -221
  55. package/dist/core/cli/root-output-flags.d.mts +0 -74
  56. package/dist/core/cli/root-output-flags.mjs +0 -169
  57. package/dist/core/cli/root-surface.d.mts +0 -64
  58. package/dist/core/cli/root-surface.mjs +0 -28
  59. package/dist/core/cli/runtime-preflight.d.mts +0 -213
  60. package/dist/core/cli/runtime-preflight.mjs +0 -221
  61. package/dist/core/completion/index.d.mts +0 -76
  62. package/dist/core/completion/index.mjs +0 -90
  63. package/dist/core/completion/shells/bash.d.mts +0 -23
  64. package/dist/core/completion/shells/bash.mjs +0 -312
  65. package/dist/core/completion/shells/fish.d.mts +0 -19
  66. package/dist/core/completion/shells/fish.mjs +0 -164
  67. package/dist/core/completion/shells/powershell.d.mts +0 -13
  68. package/dist/core/completion/shells/powershell.mjs +0 -360
  69. package/dist/core/completion/shells/shared.d.mts +0 -164
  70. package/dist/core/completion/shells/shared.mjs +0 -147
  71. package/dist/core/completion/shells/zsh.d.mts +0 -23
  72. package/dist/core/completion/shells/zsh.mjs +0 -256
  73. package/dist/core/config/index.d.mts +0 -191
  74. package/dist/core/config/index.mjs +0 -285
  75. package/dist/core/config/package-json.d.mts +0 -179
  76. package/dist/core/config/package-json.mjs +0 -353
  77. package/dist/core/errors/index.d.mts +0 -125
  78. package/dist/core/errors/index.mjs +0 -87
  79. package/dist/core/execution/index.d.mts +0 -61
  80. package/dist/core/execution/index.mjs +0 -220
  81. package/dist/core/help/ansi.d.mts +0 -84
  82. package/dist/core/help/ansi.mjs +0 -121
  83. package/dist/core/help/index.d.mts +0 -149
  84. package/dist/core/help/index.mjs +0 -418
  85. package/dist/core/help/theme.d.mts +0 -86
  86. package/dist/core/help/theme.mjs +0 -69
  87. package/dist/core/json-schema/index.mjs +0 -1008
  88. package/dist/core/json-schema/meta-descriptions.generated.d.mts +0 -274
  89. package/dist/core/json-schema/meta-descriptions.generated.mjs +0 -136
  90. package/dist/core/output/activity.d.mts +0 -193
  91. package/dist/core/output/activity.mjs +0 -452
  92. package/dist/core/output/bind.d.mts +0 -37
  93. package/dist/core/output/bind.mjs +0 -56
  94. package/dist/core/output/contracts.d.mts +0 -82
  95. package/dist/core/output/contracts.mjs +0 -57
  96. package/dist/core/output/display-value.d.mts +0 -19
  97. package/dist/core/output/display-value.mjs +0 -32
  98. package/dist/core/output/index.d.mts +0 -344
  99. package/dist/core/output/index.mjs +0 -514
  100. package/dist/core/output/renderers.d.mts +0 -45
  101. package/dist/core/output/renderers.mjs +0 -46
  102. package/dist/core/output/writer.d.mts +0 -39
  103. package/dist/core/output/writer.mjs +0 -12
  104. package/dist/core/parse/index.d.mts +0 -178
  105. package/dist/core/parse/index.mjs +0 -850
  106. package/dist/core/parse/occurrences.d.mts +0 -90
  107. package/dist/core/parse/occurrences.mjs +0 -114
  108. package/dist/core/prompt/index.d.mts +0 -213
  109. package/dist/core/prompt/index.mjs +0 -348
  110. package/dist/core/read-flags/index.d.mts +0 -150
  111. package/dist/core/read-flags/index.mjs +0 -217
  112. package/dist/core/resolve/args.d.mts +0 -39
  113. package/dist/core/resolve/args.mjs +0 -182
  114. package/dist/core/resolve/coerce.d.mts +0 -79
  115. package/dist/core/resolve/coerce.mjs +0 -900
  116. package/dist/core/resolve/config.d.mts +0 -10
  117. package/dist/core/resolve/config.mjs +0 -19
  118. package/dist/core/resolve/contracts.d.mts +0 -146
  119. package/dist/core/resolve/errors.d.mts +0 -10
  120. package/dist/core/resolve/errors.mjs +0 -148
  121. package/dist/core/resolve/flags.d.mts +0 -74
  122. package/dist/core/resolve/flags.mjs +0 -246
  123. package/dist/core/resolve/index.d.mts +0 -44
  124. package/dist/core/resolve/index.mjs +0 -123
  125. package/dist/core/resolve/path-checks.d.mts +0 -48
  126. package/dist/core/resolve/path-checks.mjs +0 -102
  127. package/dist/core/resolve/redaction.d.mts +0 -13
  128. package/dist/core/resolve/redaction.mjs +0 -14
  129. package/dist/core/resolve/stages.d.mts +0 -86
  130. package/dist/core/resolve/stages.mjs +0 -170
  131. package/dist/core/resolve/standard.d.mts +0 -26
  132. package/dist/core/resolve/standard.mjs +0 -212
  133. package/dist/core/schema/activity.d.mts +0 -189
  134. package/dist/core/schema/arg.d.mts +0 -1461
  135. package/dist/core/schema/arg.mjs +0 -1139
  136. package/dist/core/schema/brand.d.mts +0 -17
  137. package/dist/core/schema/cardinality.d.mts +0 -302
  138. package/dist/core/schema/cardinality.mjs +0 -514
  139. package/dist/core/schema/command.d.mts +0 -1132
  140. package/dist/core/schema/command.mjs +0 -999
  141. package/dist/core/schema/flag.d.mts +0 -1495
  142. package/dist/core/schema/flag.mjs +0 -1207
  143. package/dist/core/schema/index.d.mts +0 -15
  144. package/dist/core/schema/index.mjs +0 -10
  145. package/dist/core/schema/middleware.d.mts +0 -129
  146. package/dist/core/schema/middleware.mjs +0 -41
  147. package/dist/core/schema/number-constraints.d.mts +0 -96
  148. package/dist/core/schema/number-constraints.mjs +0 -60
  149. package/dist/core/schema/prompt.d.mts +0 -135
  150. package/dist/core/schema/provenance.d.mts +0 -99
  151. package/dist/core/schema/provenance.mjs +0 -28
  152. package/dist/core/schema/run.d.mts +0 -211
  153. package/dist/core/schema/source.d.mts +0 -180
  154. package/dist/core/schema/source.mjs +0 -206
  155. package/dist/core/schema/standard.d.mts +0 -100
  156. package/dist/core/schema/standard.mjs +0 -15
  157. package/dist/core/schema/stdin.d.mts +0 -97
  158. package/dist/core/schema/stdin.mjs +0 -91
  159. package/dist/core/schema/string-constraints.d.mts +0 -108
  160. package/dist/core/schema/string-constraints.mjs +0 -86
  161. package/dist/core/schema/value-parsers.d.mts +0 -150
  162. package/dist/core/schema/value-parsers.mjs +0 -160
  163. package/dist/core/schema/value.d.mts +0 -243
  164. package/dist/core/schema/value.mjs +0 -573
  165. package/dist/core/testkit/index.d.mts +0 -63
  166. package/dist/core/testkit/index.mjs +0 -102
  167. package/dist/runtime/adapter.mjs +0 -92
  168. package/dist/runtime/auto.d.mts +0 -25
  169. package/dist/runtime/auto.mjs +0 -45
  170. package/dist/runtime/deno.d.mts +0 -99
  171. package/dist/runtime/deno.mjs +0 -265
  172. package/dist/runtime/detect.d.mts +0 -86
  173. package/dist/runtime/detect.mjs +0 -45
  174. package/dist/runtime/index.d.mts +0 -6
  175. package/dist/runtime/node.d.mts +0 -71
  176. package/dist/runtime/node.mjs +0 -228
  177. package/dist/runtime/paths.d.mts +0 -31
  178. package/dist/runtime/paths.mjs +0 -48
  179. package/dist/strings.d.mts +0 -27
  180. package/dist/strings.mjs +0 -22
  181. package/examples/basic.ts +0 -37
  182. package/examples/flag-types.ts +0 -79
  183. package/examples/gh/package.json +0 -45
  184. package/examples/gh/src/commands/auth.ts +0 -66
  185. package/examples/gh/src/commands/issue.ts +0 -120
  186. package/examples/gh/src/commands/pr.ts +0 -125
  187. package/examples/gh/src/data/issues.yaml +0 -5
  188. package/examples/gh/src/data/issues.yaml.d.ts +0 -17
  189. package/examples/gh/src/data/pull-requests.yaml +0 -7
  190. package/examples/gh/src/data/pull-requests.yaml.d.ts +0 -18
  191. package/examples/gh/src/docs.ts +0 -11
  192. package/examples/gh/src/lib/auth.ts +0 -37
  193. package/examples/gh/src/lib/utils.ts +0 -17
  194. package/examples/gh/src/main.test.ts +0 -307
  195. package/examples/gh/src/main.ts +0 -46
  196. package/examples/help-config.ts +0 -43
  197. package/examples/interactive.ts +0 -67
  198. package/examples/json-mode.ts +0 -95
  199. package/examples/middleware.ts +0 -71
  200. package/examples/multi-command.ts +0 -66
  201. package/examples/output-extras.ts +0 -46
  202. package/examples/parser-control.ts +0 -40
  203. package/examples/pwsh-demo/README.md +0 -40
  204. package/examples/pwsh-demo/package.json +0 -41
  205. package/examples/pwsh-demo/pwsh-demo.cmd +0 -3
  206. package/examples/pwsh-demo/smoke-powershell.ps1 +0 -218
  207. package/examples/pwsh-demo/src/main.test.ts +0 -45
  208. package/examples/pwsh-demo/src/main.ts +0 -140
  209. package/examples/spinner-progress.ts +0 -49
  210. package/examples/standard-schema.ts +0 -45
  211. package/examples/testing.ts +0 -147
  212. package/examples/transport-launcher.ts +0 -85
@@ -1,514 +0,0 @@
1
- import "../schema/command.mjs";
2
- import { formatDisplayValue } from "./display-value.mjs";
3
- import { bindMethods } from "./bind.mjs";
4
- import { writeLine } from "./writer.mjs";
5
- import { CaptureProgressHandle, CaptureSpinnerHandle } from "./activity.mjs";
6
- import { resolveOutputPolicy, resolveProgressPolicy, resolveSpinnerPolicy, resolveTableFormat, resolveTableTextStream, resolveTextStream, shouldEmitInfo } from "./contracts.mjs";
7
- import { createProgressHandleFromPolicy, createSpinnerHandleFromPolicy, resolveWriterForStream } from "./renderers.mjs";
8
- import { createColors, isColorSupported } from "ansispeck";
9
- //#region src/core/output/index.ts
10
- /**
11
- * Output channel (out object) for command handlers.
12
- *
13
- * Provides a structured output abstraction that handlers use instead of
14
- * raw `console.log`. The channel respects TTY vs piped contexts and
15
- * supports verbosity levels (quiet mode suppresses `info`).
16
- *
17
- * The {@linkcode Out} interface (the contract handlers depend on) lives in
18
- * `src/core/schema/command.ts`. This module provides the implementation.
19
- *
20
- * @module dreamcli/core/output
21
- */
22
- /**
23
- * A noop writer used as fallback when no writer is provided and
24
- * platform defaults aren't available. Silently discards output.
25
- */
26
- const noopWrite = () => {};
27
- const requestedExitCodes = /* @__PURE__ */ new WeakMap();
28
- function validateExitCode(code) {
29
- if (!Number.isInteger(code) || code < 0 || code > 255) throw new RangeError("Exit code must be an integer from 0 to 255");
30
- return code;
31
- }
32
- /** Store the exit code requested through an output channel. @internal */
33
- function setRequestedExitCode(out, code) {
34
- requestedExitCodes.set(out, validateExitCode(code));
35
- }
36
- /** Read the exit code requested through an output channel. @internal */
37
- function getRequestedExitCode(out) {
38
- return requestedExitCodes.get(out);
39
- }
40
- /** Clear a previously requested exit code from an output channel. @internal */
41
- function clearRequestedExitCode(out) {
42
- requestedExitCodes.delete(out);
43
- }
44
- /**
45
- * Forced hyperlink decision from the `--no-hyperlinks`/`--hyperlinks` argv
46
- * flags, then `NO_HYPERLINKS`, then `FORCE_HYPERLINKS`; `undefined` when unset.
47
- *
48
- * Pure over its inputs — callers pass the adapter's `env`/`argv` so the
49
- * output layer never touches `process` directly.
50
- *
51
- * @see https://no-hyperlinks.org/
52
- */
53
- function resolveHyperlinkOverride(env, argv) {
54
- const separator = argv.indexOf("--");
55
- const flags = separator === -1 ? argv : argv.slice(0, separator);
56
- if (flags.includes("--no-hyperlinks")) return false;
57
- if (flags.includes("--hyperlinks")) return true;
58
- if (env.NO_HYPERLINKS) return false;
59
- if (env.FORCE_HYPERLINKS) return true;
60
- }
61
- /** Merge user-supplied options with defaults. */
62
- function resolveOptions(options) {
63
- const isTTY = options?.isTTY ?? false;
64
- const jsonMode = options?.jsonMode ?? false;
65
- return {
66
- stdout: options?.stdout ?? noopWrite,
67
- stderr: options?.stderr ?? noopWrite,
68
- isTTY,
69
- verbosity: options?.verbosity ?? "normal",
70
- jsonMode,
71
- color: options?.color ?? (isTTY && !jsonMode && isColorSupported),
72
- isHyperlinkSupported: options?.hyperlinks ?? isTTY
73
- };
74
- }
75
- /**
76
- * Concrete implementation of the {@linkcode Out} interface.
77
- *
78
- * Routes messages to the appropriate writer (stdout vs stderr) and
79
- * respects the configured verbosity level.
80
- *
81
- * Handlers interact with this via the {@linkcode Out} interface — they never see
82
- * {@linkcode OutputChannel} directly, which keeps the coupling minimal.
83
- * Prefer {@link createOutput} unless you are extending the output layer.
84
- *
85
- * @internal
86
- */
87
- var OutputChannel = class {
88
- /** @internal Resolved configuration. */
89
- options;
90
- /** Semantic output policy snapshot shared by routing helpers. */
91
- policy;
92
- /** Whether JSON output mode is active. */
93
- jsonMode;
94
- /** Active verbosity level for informational output and activity rendering. */
95
- verbosity;
96
- /**
97
- * Whether stdout is connected to a TTY.
98
- *
99
- * When `jsonMode` is active, this reflects the underlying TTY status
100
- * but decorative output should still be suppressed (jsonMode takes
101
- * precedence).
102
- */
103
- isTTY;
104
- /**
105
- * Context-aware ANSI color palette.
106
- *
107
- * Enabled per the resolved `color` option — identity functions when
108
- * colors are off, so handlers can style unconditionally.
109
- */
110
- color;
111
- /**
112
- * Whether OSC 8 hyperlinks should be emitted for this channel.
113
- *
114
- * Honors `NO_HYPERLINKS`/`FORCE_HYPERLINKS` and the
115
- * `--no-hyperlinks`/`--hyperlinks` argv flags, falling back to `isTTY`.
116
- */
117
- isHyperlinkSupported;
118
- constructor(options) {
119
- this.options = options;
120
- this.policy = resolveOutputPolicy(options);
121
- this.jsonMode = options.jsonMode;
122
- this.verbosity = this.policy.verbosity;
123
- this.isTTY = options.isTTY;
124
- this.color = createColors(options.color);
125
- this.isHyperlinkSupported = options.isHyperlinkSupported;
126
- bindMethods(this);
127
- }
128
- /**
129
- * Write to stdout (normal output). Always emitted.
130
- *
131
- * In JSON mode, redirected to stderr so stdout is reserved for
132
- * structured `json()` output only.
133
- */
134
- log(message) {
135
- const writer = resolveWriterForStream(this.options, resolveTextStream(this.policy));
136
- writeLine(writer, message);
137
- }
138
- /**
139
- * Informational message to stdout.
140
- * Suppressed when verbosity is `'quiet'`.
141
- *
142
- * In JSON mode, redirected to stderr.
143
- */
144
- info(message) {
145
- if (!shouldEmitInfo(this.policy)) return;
146
- const writer = resolveWriterForStream(this.options, resolveTextStream(this.policy));
147
- writeLine(writer, message);
148
- }
149
- /**
150
- * Status line to stderr (stdout stays clean for piping).
151
- * Suppressed when verbosity is `'quiet'`.
152
- */
153
- status(message) {
154
- if (!shouldEmitInfo(this.policy)) return;
155
- writeLine(this.options.stderr, message);
156
- }
157
- /** Warning to stderr. Always emitted. */
158
- warn(message) {
159
- writeLine(this.options.stderr, message);
160
- }
161
- /** Error to stderr. Always emitted. */
162
- error(message) {
163
- writeLine(this.options.stderr, message);
164
- }
165
- /** Request a successful-process exit code without writing error output. */
166
- setExitCode(code) {
167
- setRequestedExitCode(this, code);
168
- }
169
- /**
170
- * Emit a structured JSON value to stdout.
171
- *
172
- * Serialises `value` with `JSON.stringify` and writes to stdout
173
- * regardless of JSON mode — `json()` always targets stdout.
174
- */
175
- json(value) {
176
- writeLine(this.options.stdout, JSON.stringify(value));
177
- }
178
- table(rows, columnsOrOptions, options) {
179
- const { columns, options: tableOptions } = resolveTableArgs(columnsOrOptions, options);
180
- const format = resolveTableFormat(this.policy, tableOptions);
181
- const resolved = columns ?? inferColumns(rows);
182
- if (format === "json") {
183
- this.json(projectTableRows(rows, resolved));
184
- return;
185
- }
186
- const text = formatTable(rows, resolved);
187
- if (text.length === 0) return;
188
- writeLine(resolveTextTableWriter(this.options, this.policy, format, tableOptions), text);
189
- }
190
- /**
191
- * Cleanup callback for the currently active spinner/progress handle.
192
- *
193
- * Set to `undefined` when no handle is active. The callback calls the
194
- * appropriate terminal method (`.stop()` for spinners, `.done()` for
195
- * progress) on the previous handle.
196
- *
197
- * @internal
198
- */
199
- activeCleanup;
200
- /**
201
- * Stop the currently active spinner/progress handle (if any).
202
- *
203
- * Called internally before creating a new handle to prevent overlap,
204
- * and externally after handler execution to clean up leaked timers.
205
- * Idempotent (safe to call when no handle is active).
206
- */
207
- stopActive() {
208
- if (this.activeCleanup !== void 0) {
209
- this.activeCleanup();
210
- this.activeCleanup = void 0;
211
- }
212
- }
213
- /**
214
- * Create a spinner handle.
215
- *
216
- * Mode dispatch:
217
- * - quiet or `jsonMode` → noop (informational activity suppressed)
218
- * - `isTTY` → animated TTY spinner (braille frames, ANSI overwrite)
219
- * - `!isTTY && fallback: 'static'` → plain text at lifecycle boundaries
220
- * - `!isTTY && fallback: 'silent'` (default) → noop
221
- *
222
- * All activity output (transient frames, terminal messages) routes to
223
- * stderr so stdout remains clean for structured data and piping.
224
- *
225
- * If another spinner or progress handle is active, it is implicitly
226
- * stopped before the new one starts.
227
- *
228
- * @virtual
229
- */
230
- spinner(text, options) {
231
- const policy = resolveSpinnerPolicy(this.policy, options?.fallback ?? "silent");
232
- const rendered = createSpinnerHandleFromPolicy(policy, text, this.options.stderr);
233
- if (rendered.cleanup === void 0) return rendered.handle;
234
- this.stopActive();
235
- this.activeCleanup = rendered.cleanup;
236
- return rendered.handle;
237
- }
238
- /**
239
- * Create a progress handle.
240
- *
241
- * Mode dispatch:
242
- * - quiet or `jsonMode` → noop (informational activity suppressed)
243
- * - `isTTY` → animated TTY progress bar (determinate or indeterminate)
244
- * - `!isTTY && fallback: 'static'` → plain text at lifecycle boundaries
245
- * - `!isTTY && fallback: 'silent'` (default) → noop
246
- *
247
- * All activity output (transient frames, terminal messages) routes to
248
- * stderr so stdout remains clean for structured data and piping.
249
- *
250
- * If another spinner or progress handle is active, it is implicitly
251
- * stopped before the new one starts.
252
- *
253
- * @virtual
254
- */
255
- progress(opts) {
256
- const policy = resolveProgressPolicy(this.policy, opts.fallback ?? "silent");
257
- const rendered = createProgressHandleFromPolicy(policy, opts, this.options.stderr);
258
- if (rendered.cleanup === void 0) return rendered.handle;
259
- this.stopActive();
260
- this.activeCleanup = rendered.cleanup;
261
- return rendered.handle;
262
- }
263
- };
264
- /**
265
- * Output channel variant that returns capture handles for spinner/progress.
266
- *
267
- * Extends {@linkcode OutputChannel} to override `spinner()` and `progress()`, routing
268
- * activity events into a shared {@linkcode ActivityEvent | ActivityEvent[]} for testkit assertion.
269
- * Text output (log/info/warn/error) is handled by the parent class.
270
- *
271
- * @internal
272
- */
273
- var CaptureOutputChannel = class extends OutputChannel {
274
- activity;
275
- constructor(options, activity) {
276
- super(options);
277
- this.activity = activity;
278
- }
279
- /**
280
- * Return a {@link CaptureSpinnerHandle} that records events into the activity log.
281
- * @override
282
- */
283
- spinner(text, _options) {
284
- return new CaptureSpinnerHandle(text, this.activity);
285
- }
286
- /**
287
- * Return a {@link CaptureProgressHandle} that records events into the activity log.
288
- * @override
289
- */
290
- progress(opts) {
291
- return new CaptureProgressHandle(opts, this.activity);
292
- }
293
- };
294
- /**
295
- * Infer column descriptors from the keys of the first row.
296
- *
297
- * When no explicit columns are provided, all keys from the first row
298
- * become columns in insertion order. This is a convenience — callers
299
- * who need stable ordering should provide explicit columns.
300
- *
301
- * @param rows - Data rows to derive columns from.
302
- * @returns Column descriptors, one per key of the first row (empty if `rows` is empty).
303
- */
304
- function inferColumns(rows) {
305
- const first = rows[0];
306
- if (first === void 0) return [];
307
- return Object.keys(first).map((key) => ({ key }));
308
- }
309
- /**
310
- * Type guard: is `value` a {@link TableColumn} array (not {@link TableOptions})?
311
- *
312
- * @param value - The ambiguous argument to discriminate.
313
- * @returns `true` when `value` is a column descriptor array.
314
- */
315
- function isTableColumns(value) {
316
- return Array.isArray(value);
317
- }
318
- /**
319
- * Disambiguate the overloaded `table()` arguments.
320
- *
321
- * @param columnsOrOptions - Either column descriptors or table options (from the 2-arg overload).
322
- * @param options - Explicit table options (from the 3-arg overload).
323
- * @returns Separated `columns` and `options`, each possibly `undefined`.
324
- */
325
- function resolveTableArgs(columnsOrOptions, options) {
326
- if (options !== void 0) return {
327
- columns: isTableColumns(columnsOrOptions) ? columnsOrOptions : void 0,
328
- options
329
- };
330
- if (isTableColumns(columnsOrOptions)) return {
331
- columns: columnsOrOptions,
332
- options
333
- };
334
- return {
335
- columns: void 0,
336
- options: columnsOrOptions
337
- };
338
- }
339
- /**
340
- * Find the object along a row's prototype chain that carries a key.
341
- *
342
- * @param row - Source data row.
343
- * @param key - Column key to locate.
344
- * @returns The owning object, or `null` when nothing in the chain carries it.
345
- */
346
- function cellKeyHolder(row, key) {
347
- for (let holder = row; holder !== null; holder = Object.getPrototypeOf(holder)) if (Object.hasOwn(holder, key)) return holder;
348
- return null;
349
- }
350
- /**
351
- * Read one cell out of a row.
352
- *
353
- * `Object.prototype` answers a lookup for a column key such as `toString` on
354
- * every row, so a key it alone carries reads as absent. A key held anywhere
355
- * earlier in the chain is the row's own data, which is where a class getter or
356
- * an `Object.create(defaults)` fallback lives.
357
- *
358
- * @param row - Source data row.
359
- * @param key - Column key to read.
360
- * @returns The cell value, or `undefined` when only `Object.prototype` carries the key.
361
- */
362
- function cellValue(row, key) {
363
- const holder = cellKeyHolder(row, key);
364
- return holder === null || holder === Object.prototype ? void 0 : row[key];
365
- }
366
- /**
367
- * Keep only the keys listed in `columns`, preserving column order.
368
- *
369
- * @param rows - Source data rows.
370
- * @param columns - Column descriptors controlling which keys to retain.
371
- * @returns Projected rows containing only the specified keys.
372
- */
373
- function projectTableRows(rows, columns) {
374
- return rows.map((row) => Object.fromEntries(columns.map((c) => [c.key, cellValue(row, c.key)])));
375
- }
376
- /**
377
- * Determine the concrete table format (`'text'` or `'json'`).
378
- *
379
- * Resolves `'auto'` / `undefined` by falling back to the channel's `jsonMode`.
380
- *
381
- * @param jsonMode - Whether the channel is in JSON output mode.
382
- * @param options - Per-call table options (may specify an explicit format).
383
- * @returns `'text'` or `'json'`.
384
- */
385
- /**
386
- * Pick the {@link WriteFn} for a text-mode table.
387
- *
388
- * Respects `tableOptions.stream` when present; otherwise falls back to
389
- * the channel's default policy-owned text stream.
390
- *
391
- * @param options - Resolved channel options.
392
- * @param format - Resolved table format.
393
- * @param tableOptions - Per-call table options (may specify a stream override).
394
- * @returns The writer to use.
395
- */
396
- function resolveTextTableWriter(options, policy, format, tableOptions) {
397
- if (format === "json") return options.stdout;
398
- return resolveWriterForStream(options, resolveTableTextStream(policy, tableOptions));
399
- }
400
- /**
401
- * Convert a cell value to a display string.
402
- *
403
- * - `null` / `undefined` → `''`
404
- * - Primitives → `String(value)`
405
- * - Objects / arrays → JSON
406
- *
407
- * @param value - The raw cell value.
408
- * @returns Display string for the cell.
409
- */
410
- function cellToString(value) {
411
- return formatDisplayValue(value);
412
- }
413
- /**
414
- * Format rows as an aligned text table.
415
- *
416
- * Returns the full table string (without trailing newline — the caller
417
- * adds that via `writeLine`). Returns `''` when rows is empty.
418
- *
419
- * Column widths are computed as the max of header and all cell values.
420
- * Cells are left-aligned, padded with spaces. Columns are separated by
421
- * two spaces.
422
- *
423
- * @param rows - Data rows to render.
424
- * @param columns - Column descriptors controlling key, header, and order.
425
- * @returns The formatted table string, or `''` when there is nothing to render.
426
- */
427
- function formatTable(rows, columns) {
428
- if (rows.length === 0 || columns.length === 0) return "";
429
- const SEPARATOR = " ";
430
- const headers = columns.map((c) => c.header ?? c.key);
431
- const cellGrid = rows.map((row) => columns.map((c) => cellToString(cellValue(row, c.key))));
432
- const widths = headers.map((h, i) => {
433
- let max = h.length;
434
- for (const row of cellGrid) {
435
- const cell = row[i];
436
- if (cell !== void 0 && cell.length > max) max = cell.length;
437
- }
438
- return max;
439
- });
440
- return [
441
- headers.map((h, i) => h.padEnd(widths[i] ?? 0)).join(SEPARATOR),
442
- widths.map((w) => "-".repeat(w)).join(SEPARATOR),
443
- ...cellGrid.map((row) => row.map((cell, i) => cell.padEnd(widths[i] ?? 0)).join(SEPARATOR))
444
- ].join("\n");
445
- }
446
- /**
447
- * Create an output channel.
448
- *
449
- * Low-level factory: action handlers already receive `out` automatically from
450
- * `cli()`, `.execute()`, and `runCommand()`. Call `createOutput()` when you
451
- * are embedding DreamCLI primitives into a custom runtime or need a standalone
452
- * output implementation outside the normal command pipeline.
453
- *
454
- * @param options - Optional configuration. When omitted, output is
455
- * discarded (useful for silent test runs). Pass `stdout`/`stderr`
456
- * writers to direct output somewhere useful.
457
- *
458
- * @returns An {@link Out} instance backed by an {@link OutputChannel}.
459
- *
460
- * @example
461
- * ```ts
462
- * // Production (wired by the runtime adapter)
463
- * const out = createOutput({
464
- * stdout: (s) => process.stdout.write(s),
465
- * stderr: (s) => process.stderr.write(s),
466
- * isTTY: process.stdout.isTTY === true,
467
- * });
468
- *
469
- * // Test (capture output)
470
- * const lines: string[] = [];
471
- * const out = createOutput({
472
- * stdout: (s) => lines.push(s),
473
- * stderr: (s) => lines.push(s),
474
- * });
475
- * ```
476
- */
477
- function createOutput(options) {
478
- return new OutputChannel(resolveOptions(options));
479
- }
480
- /**
481
- * Create an output channel that captures all output into arrays.
482
- *
483
- * Useful in tests to assert on what a handler wrote without touching
484
- * real I/O.
485
- *
486
- * @param options - Optional {@link OutputOptions} (minus `stdout`/`stderr`,
487
- * which are wired to the capture buffers automatically).
488
- *
489
- * @returns A tuple of `[out, captured]` — the {@link Out} channel and the
490
- * {@link CapturedOutput} buffers.
491
- *
492
- * @example
493
- * ```ts
494
- * const [out, captured] = createCaptureOutput();
495
- * out.log('hello');
496
- * out.warn('danger');
497
- * expect(captured.stdout).toEqual(['hello\n']);
498
- * expect(captured.stderr).toEqual(['danger\n']);
499
- * ```
500
- */
501
- function createCaptureOutput(options) {
502
- const captured = {
503
- stdout: [],
504
- stderr: [],
505
- activity: []
506
- };
507
- return [new CaptureOutputChannel(resolveOptions({
508
- ...options,
509
- stdout: (s) => captured.stdout.push(s),
510
- stderr: (s) => captured.stderr.push(s)
511
- }), captured.activity), captured];
512
- }
513
- //#endregion
514
- export { CaptureOutputChannel, OutputChannel, clearRequestedExitCode, createCaptureOutput, createOutput, getRequestedExitCode, resolveHyperlinkOverride, setRequestedExitCode, writeLine };
@@ -1,45 +0,0 @@
1
- import { ProgressHandle, ProgressOptions, SpinnerHandle } from "../schema/activity.mjs";
2
- import { ActivityPolicy, OutputStream } from "./contracts.mjs";
3
- import { WriteFn } from "./writer.mjs";
4
- //#region src/core/output/renderers.d.ts
5
- /**
6
- * Paired write functions for the two standard output streams.
7
- *
8
- * @internal
9
- */
10
- interface OutputWriters {
11
- /** Write function targeting standard output. */
12
- readonly stdout: WriteFn;
13
- /** Write function targeting standard error. */
14
- readonly stderr: WriteFn;
15
- }
16
- /**
17
- * Spinner handle paired with its optional teardown function.
18
- *
19
- * @internal
20
- */
21
- interface SpinnerRenderResult {
22
- /** The spinner handle exposed to command handlers. */
23
- readonly handle: SpinnerHandle;
24
- /** Defined only when the mode requires cleanup (TTY or static); `undefined` for noop. */
25
- readonly cleanup: (() => void) | undefined;
26
- }
27
- /**
28
- * Progress handle paired with its optional teardown function.
29
- *
30
- * @internal
31
- */
32
- interface ProgressRenderResult {
33
- /** The progress handle exposed to command handlers. */
34
- readonly handle: ProgressHandle;
35
- /** Defined only when the mode requires cleanup (TTY or static); `undefined` for noop. */
36
- readonly cleanup: (() => void) | undefined;
37
- }
38
- /** Select the concrete {@linkcode WriteFn} for a given stream label. @internal */
39
- declare function resolveWriterForStream(writers: OutputWriters, stream: OutputStream): WriteFn;
40
- /** Create a spinner handle matching the resolved {@linkcode ActivityPolicy} mode. @internal */
41
- declare function createSpinnerHandleFromPolicy(policy: ActivityPolicy, text: string, stderr: WriteFn): SpinnerRenderResult;
42
- /** Create a progress handle matching the resolved {@linkcode ActivityPolicy} mode. @internal */
43
- declare function createProgressHandleFromPolicy(policy: ActivityPolicy, options: ProgressOptions, stderr: WriteFn): ProgressRenderResult;
44
- //#endregion
45
- export { type OutputWriters, type ProgressRenderResult, type SpinnerRenderResult, createProgressHandleFromPolicy, createSpinnerHandleFromPolicy, resolveWriterForStream };
@@ -1,46 +0,0 @@
1
- import { StaticProgressHandle, StaticSpinnerHandle, TTYProgressHandle, TTYSpinnerHandle, noopProgressHandle, noopSpinnerHandle } from "./activity.mjs";
2
- //#region src/core/output/renderers.ts
3
- /** Select the concrete {@linkcode WriteFn} for a given stream label. @internal */
4
- function resolveWriterForStream(writers, stream) {
5
- return stream === "stderr" ? writers.stderr : writers.stdout;
6
- }
7
- /** Create a spinner handle matching the resolved {@linkcode ActivityPolicy} mode. @internal */
8
- function createSpinnerHandleFromPolicy(policy, text, stderr) {
9
- if (policy.mode === "noop") return {
10
- handle: noopSpinnerHandle,
11
- cleanup: void 0
12
- };
13
- if (policy.mode === "tty") {
14
- const handle = new TTYSpinnerHandle(text, stderr);
15
- return {
16
- handle,
17
- cleanup: () => handle.stop()
18
- };
19
- }
20
- const handle = new StaticSpinnerHandle(text, stderr);
21
- return {
22
- handle,
23
- cleanup: () => handle.stop()
24
- };
25
- }
26
- /** Create a progress handle matching the resolved {@linkcode ActivityPolicy} mode. @internal */
27
- function createProgressHandleFromPolicy(policy, options, stderr) {
28
- if (policy.mode === "noop") return {
29
- handle: noopProgressHandle,
30
- cleanup: void 0
31
- };
32
- if (policy.mode === "tty") {
33
- const handle = new TTYProgressHandle(options, stderr);
34
- return {
35
- handle,
36
- cleanup: () => handle.done()
37
- };
38
- }
39
- const handle = new StaticProgressHandle(options.label, stderr);
40
- return {
41
- handle,
42
- cleanup: () => handle.done()
43
- };
44
- }
45
- //#endregion
46
- export { createProgressHandleFromPolicy, createSpinnerHandleFromPolicy, resolveWriterForStream };
@@ -1,39 +0,0 @@
1
- //#region src/core/output/writer.d.ts
2
- /**
3
- * Minimal I/O seam — the only write primitive the output module depends on.
4
- *
5
- * Extracted to its own file so that both `index.ts` (OutputChannel) and
6
- * `activity.ts` (handle classes) can import it without a circular dependency.
7
- *
8
- * @module dreamcli/core/output/writer
9
- */
10
- /**
11
- * A function that writes a string somewhere.
12
- *
13
- * This is the only write primitive the output layer depends on.
14
- * In production it usually wraps `process.stdout.write` or
15
- * `process.stderr.write`; in tests it is often a simple string accumulator.
16
- *
17
- * The contract is intentionally tiny:
18
- * - writes are synchronous fire-and-forget
19
- * - callers decide whether to append a trailing newline
20
- * - there is no backpressure or flush signal
21
- *
22
- * @example
23
- * ```ts
24
- * const lines: string[] = [];
25
- * const write: WriteFn = (data) => {
26
- * lines.push(data);
27
- * };
28
- * ```
29
- */
30
- type WriteFn = (data: string) => void;
31
- /**
32
- * Write a message followed by a newline.
33
- *
34
- * @param write - The underlying write function.
35
- * @param message - The text to write.
36
- */
37
- declare function writeLine(write: WriteFn, message: string): void;
38
- //#endregion
39
- export { type WriteFn, writeLine };
@@ -1,12 +0,0 @@
1
- //#region src/core/output/writer.ts
2
- /**
3
- * Write a message followed by a newline.
4
- *
5
- * @param write - The underlying write function.
6
- * @param message - The text to write.
7
- */
8
- function writeLine(write, message) {
9
- write(`${message}\n`);
10
- }
11
- //#endregion
12
- export { writeLine };