@prisma/cli-engine 0.0.1

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.
@@ -0,0 +1,787 @@
1
+ import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-DGUfR-Ni.js";
2
+ import { ManagementApiClient } from "@prisma/management-api-sdk";
3
+
4
+ //#region src/args.d.ts
5
+ /**
6
+ * Single-character alias, enforced at the type level: `Char<'q'>` is
7
+ * 'q'; `Char<'ab'>` is never.
8
+ */
9
+ type Char<S extends string> = S extends `${string}${infer Rest}` ? Rest extends "" ? S : never : never;
10
+ interface FlagSpec<T> {
11
+ /** Phantom type carrier for inference; never present at runtime. */
12
+ readonly __flag?: T;
13
+ }
14
+ /**
15
+ * Command-declared flags. The shared family (--format/--json,
16
+ * --log-level/--verbose, --quiet, --yes, --interactive, --color) is
17
+ * engine-injected and reserved. Flags are optional by default
18
+ * (requiredString is the exception); positionals are required by
19
+ * default (optionalString is the exception).
20
+ */
21
+ declare const flag: {
22
+ string<A extends string = never>(spec: {
23
+ brief: string;
24
+ placeholder?: string;
25
+ alias?: A & Char<A>;
26
+ default?: string;
27
+ }): FlagSpec<string | undefined>;
28
+ requiredString<A extends string = never>(spec: {
29
+ brief: string;
30
+ placeholder?: string;
31
+ alias?: A & Char<A>;
32
+ }): FlagSpec<string>;
33
+ number<A extends string = never>(spec: {
34
+ brief: string;
35
+ placeholder?: string;
36
+ alias?: A & Char<A>;
37
+ default?: number;
38
+ }): FlagSpec<number | undefined>;
39
+ boolean<A extends string = never>(spec: {
40
+ brief: string;
41
+ alias?: A & Char<A>;
42
+ }): FlagSpec<boolean>;
43
+ enum<const T extends readonly string[], A extends string = never>(spec: {
44
+ brief: string;
45
+ values: T;
46
+ alias?: A & Char<A>;
47
+ default?: T[number];
48
+ }): FlagSpec<T[number] | undefined>;
49
+ repeated<A extends string = never>(spec: {
50
+ brief: string;
51
+ placeholder?: string;
52
+ alias?: A & Char<A>;
53
+ }): FlagSpec<readonly string[]>;
54
+ };
55
+ interface PositionalSpec<T> {
56
+ /** Phantom type carrier for inference; never present at runtime. */
57
+ readonly __positional?: T;
58
+ }
59
+ declare const positional: {
60
+ string(spec: {
61
+ brief: string;
62
+ placeholder: string;
63
+ }): PositionalSpec<string>;
64
+ optionalString(spec: {
65
+ brief: string;
66
+ placeholder: string;
67
+ }): PositionalSpec<string | undefined>;
68
+ /**
69
+ * Zero or more trailing values; at most one, declared last (order =
70
+ * declaration order; keys must not be integer-like).
71
+ */
72
+ variadic(spec: {
73
+ brief: string;
74
+ placeholder: string;
75
+ }): PositionalSpec<readonly string[]>;
76
+ };
77
+ /** The parse SPI: a command's argument surface, one property. */
78
+ interface ArgsSpec<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
79
+ readonly flags?: TFlags;
80
+ readonly positionals?: TPositionals;
81
+ }
82
+ /**
83
+ * The normalized argument surface a definition carries: both namespaces
84
+ * always present, empty when the command declares none.
85
+ */
86
+ interface CommandArgs<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
87
+ readonly flags: TFlags;
88
+ readonly positionals: TPositionals;
89
+ }
90
+ /**
91
+ * What a handler receives: separate namespaces, symmetric access —
92
+ * `args.flags.to`, `args.positionals.name`. Declared flag keys are
93
+ * camelCase and transliterate to --kebab-case on the CLI.
94
+ */
95
+ interface Args<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>> {
96
+ readonly flags: { readonly [K in keyof TFlags]: TFlags[K] extends FlagSpec<infer T> ? T : never };
97
+ readonly positionals: { readonly [K in keyof TPositionals]: TPositionals[K] extends PositionalSpec<infer T> ? T : never };
98
+ }
99
+ //#endregion
100
+ //#region src/config-section.d.ts
101
+ /**
102
+ * A command family's named slice of prisma.config.ts. The token couples
103
+ * the section name, its validated type, and its total validator. The
104
+ * validator owns absence: its input is the raw section value, or
105
+ * undefined when the config file has no such section. It returns
106
+ * findings; it never throws.
107
+ */
108
+ interface ConfigSection<T> {
109
+ readonly name: string;
110
+ readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
111
+ }
112
+ /**
113
+ * Diagnostics on an OK validation are warnings: the engine writes them
114
+ * to stderr as commentary (log-level filtered, human and json alike);
115
+ * they never enter the stream or the envelope.
116
+ */
117
+ type SectionValidation<T> = {
118
+ readonly ok: true;
119
+ readonly value: T;
120
+ readonly diagnostics: readonly Diagnostic[];
121
+ } | {
122
+ readonly ok: false;
123
+ readonly diagnostics: readonly Diagnostic[];
124
+ };
125
+ declare function defineConfigSection<T>(spec: {
126
+ readonly name: string;
127
+ readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
128
+ }): ConfigSection<T>;
129
+ //#endregion
130
+ //#region src/events.d.ts
131
+ /**
132
+ * The commentary severity scale; also the log-level axis. Distinct from
133
+ * Diagnostic severity: 'verbose' grades commentary, which never enters
134
+ * the envelope.
135
+ */
136
+ type Severity = "error" | "warn" | "info" | "verbose";
137
+ /**
138
+ * The engine event envelope. `kind`-specific fields are the common
139
+ * vocabulary the engine renders (human mode) and streams (json mode);
140
+ * `data` is the command family's extension, passed through untouched.
141
+ * Events are transcript, never aggregated into any envelope. Follow-ups
142
+ * are handler-owned: completed via `presentations.next`, errored via the
143
+ * error's own `nextActions`.
144
+ */
145
+ type EngineEvent = {
146
+ readonly kind: "step-started";
147
+ readonly step: string;
148
+ readonly id?: string;
149
+ readonly parentId?: string;
150
+ readonly data?: unknown;
151
+ } | {
152
+ readonly kind: "step-finished";
153
+ readonly step: string;
154
+ readonly id?: string;
155
+ readonly outcome: "ok" | "failed" | "skipped" | "warning";
156
+ readonly data?: unknown;
157
+ } | {
158
+ readonly kind: "progress";
159
+ readonly step?: string;
160
+ readonly completed: number;
161
+ readonly total?: number;
162
+ readonly data?: unknown;
163
+ }
164
+ /**
165
+ * Commentary at a severity; display-filtered by log level. 'error' is
166
+ * not valid here: fatal problems are the Result's error;
167
+ * envelope-worthy findings are diagnostics.
168
+ */
169
+ | {
170
+ readonly kind: "message";
171
+ readonly severity: Exclude<Severity, "error">;
172
+ readonly text: string;
173
+ readonly data?: unknown;
174
+ } | {
175
+ readonly kind: "output";
176
+ readonly source: string;
177
+ readonly channel: "data" | "diagnostic";
178
+ readonly line: string;
179
+ readonly data?: unknown;
180
+ }
181
+ /**
182
+ * Transcript-only: framed in json mode, never rendered in human mode,
183
+ * never aggregated into any envelope.
184
+ */
185
+ | {
186
+ readonly kind: "remediation";
187
+ readonly action: NextAction;
188
+ readonly data?: unknown;
189
+ } | {
190
+ readonly kind: "endpoint";
191
+ readonly name: string;
192
+ readonly url: string;
193
+ readonly data?: unknown;
194
+ } | {
195
+ readonly kind: "status";
196
+ readonly subject: string;
197
+ readonly status: string;
198
+ readonly from?: string;
199
+ readonly data?: unknown;
200
+ } | {
201
+ readonly kind: "artifact";
202
+ readonly path: string;
203
+ readonly description?: string;
204
+ readonly data?: unknown;
205
+ };
206
+ /**
207
+ * json mode emits one StreamEvent per line: the handler's events,
208
+ * flattened with the stream metadata, then exactly one terminal
209
+ * 'result' member carrying the envelope.
210
+ */
211
+ type StreamEvent = (EngineEvent & StreamMeta) | ({
212
+ readonly kind: "result";
213
+ readonly envelope: CompletedEnvelope | ErroredEnvelope;
214
+ } & StreamMeta);
215
+ interface StreamMeta {
216
+ readonly commandId: string;
217
+ /** ISO 8601 UTC. Injectable clock in tests. */
218
+ readonly timestamp: string;
219
+ }
220
+ //#endregion
221
+ //#region src/management-api.d.ts
222
+ /**
223
+ * The SDK's typed client, re-exported so consumers never import
224
+ * @prisma/management-api-sdk directly.
225
+ */
226
+ type ManagementApiClient$1 = ManagementApiClient;
227
+ //#endregion
228
+ //#region src/presentation.d.ts
229
+ type Format = "human" | "json";
230
+ /**
231
+ * What a command concluded, stated at the return site. `exitCode` is
232
+ * required at every return site iff the command documents exit codes,
233
+ * and forbidden otherwise. `diagnostics` may be omitted at the call
234
+ * site; the presented result always carries an array.
235
+ */
236
+ type Outcome<T, TCode extends number = never> = [TCode] extends [never] ? {
237
+ readonly data: T;
238
+ readonly diagnostics?: readonly Diagnostic[];
239
+ } : {
240
+ readonly data: T;
241
+ readonly exitCode: TCode | 0;
242
+ readonly diagnostics?: readonly Diagnostic[];
243
+ };
244
+ declare const PRESENTED: unique symbol;
245
+ /**
246
+ * What a completed command's handler returns inside `ok(...)`: the
247
+ * outcome plus the presentation the active format already materialized.
248
+ * Built exclusively by ctx.present — the brand makes hand-construction
249
+ * a type error. Human rendering writes the blocks, next-action lines,
250
+ * and diagnostics to stderr and the `stdout` lines to stdout — human
251
+ * mode is pipe-clean (operator ruling, 2026-08-09).
252
+ */
253
+ interface PresentedResult<T> {
254
+ readonly [PRESENTED]: true;
255
+ readonly data: T;
256
+ /** 0 unless the outcome selected a documented code. */
257
+ readonly exitCode: number;
258
+ /** Never undefined; empty when the outcome recorded no findings. */
259
+ readonly diagnostics: readonly Diagnostic[];
260
+ /**
261
+ * Only the active format's presentation is materialized; the other
262
+ * format's fields are normalized to empty. `json` stays undefined
263
+ * when the handler supplied no json presentation — the envelope's
264
+ * `result` then falls back to `data`.
265
+ */
266
+ readonly presentation: {
267
+ readonly human: readonly Block[];
268
+ readonly stdout: readonly string[];
269
+ readonly json: unknown;
270
+ readonly next: readonly NextAction[];
271
+ };
272
+ }
273
+ /**
274
+ * The per-format presentation functions a handler supplies to
275
+ * ctx.present. Only the active format's functions are invoked, at the
276
+ * return site. `human` composes engine primitives, rendered to stderr;
277
+ * `stdout` is the machine-consumable data lines — what a pipe
278
+ * receives, the human mode's only stdout writes.
279
+ */
280
+ interface Presentations {
281
+ readonly human: (ui: Ui) => readonly Block[];
282
+ readonly stdout?: () => readonly string[];
283
+ readonly json?: () => unknown;
284
+ readonly next?: () => readonly NextAction[];
285
+ }
286
+ /**
287
+ * Deliberately small; grows by the same evidence rule as events.
288
+ * Recorded findings are NOT a Block — they are the outcome's
289
+ * diagnostics; the engine renders them and carries them into the
290
+ * envelope, so the two surfaces cannot diverge.
291
+ */
292
+ type Block = {
293
+ readonly kind: "summary";
294
+ readonly tone: "ok" | "error" | "warn" | "info";
295
+ readonly text: string;
296
+ } | {
297
+ readonly kind: "fields";
298
+ readonly rows: ReadonlyArray<{
299
+ readonly label: string;
300
+ readonly value: string;
301
+ readonly sensitive?: boolean;
302
+ }>;
303
+ } | {
304
+ readonly kind: "table";
305
+ readonly columns: readonly string[];
306
+ readonly rows: ReadonlyArray<readonly string[]>;
307
+ } | {
308
+ readonly kind: "list";
309
+ readonly items: readonly string[];
310
+ } | {
311
+ readonly kind: "tree";
312
+ readonly roots: readonly TreeNode[];
313
+ };
314
+ interface TreeNode {
315
+ readonly label: string;
316
+ readonly children?: readonly TreeNode[];
317
+ }
318
+ /** Styling helpers usable inside block text; no direct writing. */
319
+ interface Ui {
320
+ readonly emphasize: (text: string) => string;
321
+ readonly dim: (text: string) => string;
322
+ readonly code: (text: string) => string;
323
+ }
324
+ //#endregion
325
+ //#region src/context.d.ts
326
+ interface Credentials {
327
+ /** Opaque to the engine; shape owned by the Cloud auth library. */
328
+ readonly token: string;
329
+ }
330
+ /** The handler context — the whole world arrives as one argument. */
331
+ interface CommandContext<TConfig = undefined, TCode extends number = never> {
332
+ /**
333
+ * The validated value of the command's needed config section —
334
+ * exactly TConfig; absence semantics belong to the section's
335
+ * validator. Commands with no config need get undefined.
336
+ */
337
+ readonly config: TConfig;
338
+ /**
339
+ * Builds the PresentedResult for the active format. The only
340
+ * constructor of PresentedResult.
341
+ */
342
+ readonly present: <T>(outcome: Outcome<T, TCode>, presentations: Presentations) => PresentedResult<T>;
343
+ /**
344
+ * Management-API credentials, resolved at call time. Undefined when
345
+ * unauthenticated; commands with needs.credentials never see
346
+ * undefined — the engine fails them early.
347
+ */
348
+ readonly getCredentials: () => Promise<Credentials | undefined>;
349
+ /**
350
+ * The Management API client. Constructed lazily on first access, once
351
+ * per run, with its token source backed by ctx.getCredentials so
352
+ * refresh during long runs is picked up per request. A request made
353
+ * while getCredentials() resolves undefined throws the structured
354
+ * CLI.CREDENTIALS_REQUIRED error.
355
+ */
356
+ readonly api: ManagementApiClient$1;
357
+ /** The one way to emit while running. */
358
+ readonly report: (event: EngineEvent) => void;
359
+ /** Interactive input. */
360
+ readonly prompt: PromptSurface;
361
+ /**
362
+ * Fires on Ctrl-C/SIGTERM (engine-owned; a second signal force-exits
363
+ * through the runtime's exit proxy). Session commands run until it
364
+ * fires.
365
+ */
366
+ readonly signal: AbortSignal;
367
+ /** Where the user invoked the CLI. Handlers never read process.cwd(). */
368
+ readonly cwd: string;
369
+ /**
370
+ * The invocation's environment, from Runtime.env. Handlers read env
371
+ * via ctx.env, never process.env.
372
+ */
373
+ readonly env: Readonly<Record<string, string | undefined>>;
374
+ /**
375
+ * Conditional optional-dependency need. Resolves when the
376
+ * optional peer dependency is importable from the user's project;
377
+ * otherwise returns the engine's structured missing-dependency error
378
+ * for the handler to pass to notOk.
379
+ */
380
+ readonly requireDependency: (specifier: string) => Promise<Result<void, CliStructuredError>>;
381
+ }
382
+ /**
383
+ * Prompts. Every prompt resolves to its answered value directly.
384
+ * Failures THROW engine-internal structured errors the engine catches
385
+ * and settles: cancellation exits 3; a prompt that cannot be operated
386
+ * (no default under --yes or non-interactive, an invalid answer) exits
387
+ * 2. A handler that does not catch simply propagates; one that catches
388
+ * cannot swallow the settlement — rethrow or return notOk.
389
+ *
390
+ * Every prompt except `consent` may carry a declared `default`. Under
391
+ * --yes and in non-interactive contexts (no TTY stdin, CI,
392
+ * --no-interactive — format never decides interactivity) a prompt with
393
+ * a default resolves to it; one without a default throws. The prompt UI
394
+ * writes to stderr, so an interactive json run prompts without touching
395
+ * the stdout stream.
396
+ */
397
+ interface PromptSurface {
398
+ readonly confirm: (question: string, opts?: {
399
+ readonly default?: boolean;
400
+ }) => Promise<boolean>;
401
+ /**
402
+ * A question requiring explicit consent — never inferable.
403
+ * Structurally undefaultable: no default parameter exists, so --yes,
404
+ * Enter-through, and non-interactive contexts can never satisfy it.
405
+ */
406
+ readonly consent: (question: string) => Promise<boolean>;
407
+ readonly select: <T extends string>(question: string, options: ReadonlyArray<{
408
+ value: T;
409
+ label: string;
410
+ }>, opts?: {
411
+ readonly default?: T;
412
+ }) => Promise<T>;
413
+ readonly text: (question: string, opts?: {
414
+ readonly placeholder?: string;
415
+ readonly default?: string;
416
+ }) => Promise<string>;
417
+ }
418
+ //#endregion
419
+ //#region src/runtime.d.ts
420
+ /** Minimal structural stream types; no NodeJS.* in the public surface. */
421
+ interface OutputStream {
422
+ write(text: string): void;
423
+ }
424
+ /**
425
+ * Byte-oriented, so server commands can implement byte-counted
426
+ * protocols (lsp's Content-Length framing). setRawMode is present
427
+ * where the platform supports keypress input.
428
+ */
429
+ interface InputStream extends AsyncIterable<Uint8Array> {
430
+ readonly setRawMode?: (enabled: boolean) => void;
431
+ }
432
+ /** Everything environmental, injected once by the bin (or by a test). */
433
+ interface Runtime {
434
+ readonly stdout: OutputStream;
435
+ readonly stderr: OutputStream;
436
+ readonly stdin: InputStream;
437
+ readonly cwd: string;
438
+ readonly env: Readonly<Record<string, string | undefined>>;
439
+ readonly isTty: {
440
+ readonly stdin: boolean;
441
+ readonly stdout: boolean;
442
+ readonly stderr: boolean;
443
+ };
444
+ /**
445
+ * Ends the process. The bin passes process.exit; the engine is the
446
+ * only caller (second-signal force exit, 130/143).
447
+ */
448
+ readonly exit: (code: number) => never;
449
+ /**
450
+ * Subscribes to delivered SIGINT/SIGTERM; returns the unsubscribe.
451
+ * The bin is dumb wiring — the engine owns the whole signal policy:
452
+ * the first signal aborts ctx.signal and awaits teardown; a second
453
+ * calls exit(130|143) immediately.
454
+ */
455
+ readonly onSignal: (cb: (signal: "SIGINT" | "SIGTERM") => void) => () => void;
456
+ /**
457
+ * Loaded config + file-level diagnostics; the shell builds this via
458
+ * the unified loader. Tests hand in fixtures.
459
+ */
460
+ readonly config: LoadedConfig;
461
+ readonly getCredentials: () => Promise<Credentials | undefined>;
462
+ /** Management API endpoint config; the bin derives baseUrl from env. */
463
+ readonly managementApi: {
464
+ readonly baseUrl: string;
465
+ };
466
+ /**
467
+ * Used by the ENGINE to phrase install commands (handlers never do —
468
+ * see needs.dependencies and ctx.requireDependency).
469
+ */
470
+ readonly packageManager: "npm" | "pnpm" | "yarn" | "bun" | "unknown";
471
+ }
472
+ /**
473
+ * The minimal process surface a bin adapts a Runtime from — Node's
474
+ * `process` satisfies it structurally. The engine never reads it; it
475
+ * exists so bins and their tests share one adapter shape.
476
+ */
477
+ interface HostProcess {
478
+ readonly argv: readonly string[];
479
+ readonly env: Readonly<Record<string, string | undefined>>;
480
+ cwd(): string;
481
+ readonly stdout: {
482
+ write(text: string): unknown;
483
+ isTTY?: boolean;
484
+ };
485
+ readonly stderr: {
486
+ write(text: string): unknown;
487
+ isTTY?: boolean;
488
+ };
489
+ readonly stdin: {
490
+ isTTY?: boolean;
491
+ setRawMode?(enabled: boolean): unknown;
492
+ [Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
493
+ };
494
+ on(event: "SIGINT" | "SIGTERM", listener: () => void): unknown;
495
+ off(event: "SIGINT" | "SIGTERM", listener: () => void): unknown;
496
+ exit(code: number): never;
497
+ }
498
+ interface LoadedConfig {
499
+ /**
500
+ * Raw section values by name; validation happens per command via its
501
+ * command family's section token.
502
+ */
503
+ readonly sections: Readonly<Record<string, unknown>>;
504
+ /**
505
+ * File-level problems (unevaluable module, missing version marker)
506
+ * carry section: null and fail only commands with a needs.config
507
+ * section; commands with no config need run normally.
508
+ */
509
+ readonly diagnostics: ReadonlyArray<{
510
+ readonly section: string | null;
511
+ readonly diagnostic: Diagnostic;
512
+ }>;
513
+ }
514
+ /**
515
+ * The config contract version defineConfig writes as the structural
516
+ * `$prismaConfig` marker; the loader checks it before interpreting
517
+ * anything.
518
+ */
519
+ declare const PRISMA_CONFIG_VERSION = 1;
520
+ //#endregion
521
+ //#region src/commands.d.ts
522
+ /**
523
+ * Command definitions carry no mount path and are runtime-discriminated
524
+ * by `kind`. Definitions load their handler's import graph at startup;
525
+ * handler bodies defer heavy work to execution time.
526
+ *
527
+ * The define* constructors accept ergonomic specs (optional help
528
+ * details, args, needs, exitCodes) and normalize them: every definition
529
+ * field is always present, with empty collections and explicit
530
+ * undefined instead of conditional properties.
531
+ */
532
+ /** The help SPI: words only — the engine formats. */
533
+ interface HelpSpec {
534
+ /** One line, imperative, shown in listings. */
535
+ readonly summary: string;
536
+ readonly description?: string;
537
+ /**
538
+ * Invocations WITHOUT the binary name: at help render time every
539
+ * `{bin}` is substituted with createCli's `name`; an example
540
+ * containing no `{bin}` gets the name prepended.
541
+ */
542
+ readonly examples?: readonly string[];
543
+ }
544
+ /** The normalized help a definition carries. */
545
+ interface CommandHelp {
546
+ readonly summary: string;
547
+ readonly description: string | undefined;
548
+ readonly examples: readonly string[];
549
+ }
550
+ /**
551
+ * The preconditions SPI: everything the engine enforces BEFORE the
552
+ * handler runs. Each unmet need fails the command early with the
553
+ * engine's own structured error.
554
+ */
555
+ interface NeedsSpec<TConfig> {
556
+ /**
557
+ * The command family's config section token: validate it, fail me on
558
+ * its error diagnostics, hand me the value as ctx.config.
559
+ */
560
+ readonly config?: ConfigSection<TConfig>;
561
+ /** Fail early with the sign-in error when unauthenticated. */
562
+ readonly credentials?: true;
563
+ /**
564
+ * Optional peer dependencies this command cannot run without; the
565
+ * engine probes resolvability and phrases the install error.
566
+ * (Conditional needs use ctx.requireDependency instead.)
567
+ */
568
+ readonly dependencies?: readonly string[];
569
+ /**
570
+ * Fail early in non-interactive contexts (no TTY stdin, CI, or
571
+ * --no-interactive; format never decides interactivity). This is a
572
+ * MECHANICAL precondition — "an interactive terminal is required" —
573
+ * and deliberately NOT an agent barrier: the client's nature is
574
+ * unverifiable, and a flag claiming to exclude agents would be a
575
+ * false guarantee. Anything requiring a verified human belongs
576
+ * server-side, where identity actually exists.
577
+ */
578
+ readonly interaction?: true;
579
+ }
580
+ /** The normalized preconditions a definition carries. */
581
+ interface CommandNeeds<TConfig> {
582
+ readonly config: ConfigSection<TConfig> | undefined;
583
+ readonly credentials: boolean;
584
+ readonly dependencies: readonly string[];
585
+ readonly interaction: boolean;
586
+ }
587
+ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never> {
588
+ readonly kind: "result-command";
589
+ readonly help: CommandHelp;
590
+ readonly args: CommandArgs<TFlags, TPositionals>;
591
+ readonly needs: CommandNeeds<TConfig>;
592
+ /**
593
+ * The command's documented exit codes (4–99): code → meaning. The
594
+ * keys type the outcome's exitCode, making it REQUIRED at every
595
+ * return site (`0` or a documented code). Empty = the command only
596
+ * exits 0/1/2/3 and the outcome carries no exitCode.
597
+ */
598
+ readonly exitCodes: Readonly<Record<TCode, string>>;
599
+ /**
600
+ * The handler function, referenced directly — never a dynamic import
601
+ * (operator ruling, 2026-08-09). A handler that needs heavy
602
+ * dependencies imports them at execution time, inside its body. A
603
+ * handler defined in another file is imported statically and
604
+ * annotated CommandHandler<typeof def>.
605
+ */
606
+ readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
607
+ }
608
+ type Handler<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>, TConfig, TCode extends number = never> = (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig, TCode>) => Promise<Result<PresentedResult<unknown>, CliStructuredError>>;
609
+ /** For impl files: `const run: CommandHandler<typeof migrateCommand> = …` */
610
+ type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K> ? Handler<F, P, C, K> : never;
611
+ declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never>(def: {
612
+ readonly help: HelpSpec;
613
+ readonly args?: ArgsSpec<TFlags, TPositionals>;
614
+ readonly needs?: NeedsSpec<TConfig>;
615
+ readonly exitCodes?: Readonly<Record<TCode, string>>;
616
+ readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
617
+ }): CommandDefinition<TFlags, TPositionals, TConfig, TCode>;
618
+ /**
619
+ * A session command (dev, log tail): runs until the signal fires,
620
+ * speaks entirely through events, returns Result<void>. No
621
+ * presentation, no exit-code set. A session always supports json mode:
622
+ * the event stream is its json surface.
623
+ */
624
+ interface SessionCommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined> {
625
+ readonly kind: "session-command";
626
+ readonly help: CommandHelp;
627
+ readonly args: CommandArgs<TFlags, TPositionals>;
628
+ readonly needs: CommandNeeds<TConfig>;
629
+ readonly handler: (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig>) => Promise<Result<void, CliStructuredError>>;
630
+ }
631
+ declare function defineSessionCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined>(def: {
632
+ readonly help: HelpSpec;
633
+ readonly args?: ArgsSpec<TFlags, TPositionals>;
634
+ readonly needs?: NeedsSpec<TConfig>;
635
+ readonly handler: SessionCommandDefinition<TFlags, TPositionals, TConfig>["handler"];
636
+ }): SessionCommandDefinition<TFlags, TPositionals, TConfig>;
637
+ /**
638
+ * A server command (lsp): a foreign client on the other end of stdio
639
+ * owns the conversation, so the engine hands over the streams. Events,
640
+ * presentation, formats, and prompts do not apply; the handler returns
641
+ * the exit code directly. The shared flag family is NOT injected.
642
+ */
643
+ interface ServerCommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TConfig = undefined> {
644
+ readonly kind: "server-command";
645
+ readonly help: CommandHelp;
646
+ readonly args: CommandArgs<TFlags, Record<never, PositionalSpec<unknown>>>;
647
+ readonly needs: CommandNeeds<TConfig>;
648
+ readonly handler: (args: Args<TFlags, Record<never, PositionalSpec<unknown>>>, io: {
649
+ readonly stdin: InputStream;
650
+ readonly stdout: OutputStream;
651
+ readonly stderr: OutputStream;
652
+ readonly signal: AbortSignal;
653
+ readonly cwd: string;
654
+ readonly env: Readonly<Record<string, string | undefined>>;
655
+ readonly config: TConfig;
656
+ }) => Promise<number>;
657
+ }
658
+ declare function defineServerCommand<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TConfig = undefined>(def: {
659
+ readonly help: HelpSpec;
660
+ readonly args?: ArgsSpec<TFlags, Record<never, PositionalSpec<unknown>>>;
661
+ readonly needs?: NeedsSpec<TConfig>;
662
+ readonly handler: ServerCommandDefinition<TFlags, TConfig>["handler"];
663
+ }): ServerCommandDefinition<TFlags, TConfig>;
664
+ /**
665
+ * Erased union for command families and mount maps; `kind`
666
+ * discriminates. Handler functions are erased to `unknown` here — the
667
+ * concrete types travel through each definition's generics, not through
668
+ * this union.
669
+ */
670
+ type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number>, "handler"> & {
671
+ readonly handler: unknown;
672
+ }) | (Omit<SessionCommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown>, "handler"> & {
673
+ readonly handler: unknown;
674
+ }) | (Omit<ServerCommandDefinition<Record<string, FlagSpec<unknown>>, unknown>, "handler"> & {
675
+ readonly handler: unknown;
676
+ });
677
+ interface CompletedEnvelope<T = unknown> {
678
+ /**
679
+ * ok = COMPLETED (the command executed to its end). A completed
680
+ * result may still carry findings and a non-zero exit code — bad
681
+ * news is a result, not an error.
682
+ */
683
+ readonly ok: true;
684
+ /**
685
+ * The command's stable dotted identity — its full command path
686
+ * ('project.env.add'). The schema-dispatch key for machine consumers.
687
+ */
688
+ readonly commandId: string;
689
+ readonly result: T;
690
+ readonly exitCode: number;
691
+ /** The recorded findings, verbatim from the presented outcome. */
692
+ readonly diagnostics: readonly Diagnostic[];
693
+ readonly nextActions: readonly NextAction[];
694
+ }
695
+ interface ErroredEnvelope {
696
+ /** ok = false: the command did NOT complete. */
697
+ readonly ok: false;
698
+ readonly commandId: string;
699
+ /**
700
+ * The PRIMARY error — what aborted the command. Severity 'error' by
701
+ * definition. A thrown CliStructuredError serializes to exactly this
702
+ * shape.
703
+ */
704
+ readonly error: Diagnostic;
705
+ /** Accompanying findings when the abort had several. */
706
+ readonly diagnostics: readonly Diagnostic[];
707
+ /**
708
+ * Copied from the error's own nextActions — the uniform consumer
709
+ * read path (envelope.nextActions) on both settlement paths.
710
+ */
711
+ readonly nextActions: readonly NextAction[];
712
+ }
713
+ //#endregion
714
+ //#region src/command-family.d.ts
715
+ /**
716
+ * The unit of contribution and ownership a package exports for CLI
717
+ * purposes: its config section (declared once — a family-level fact)
718
+ * and its commands by NAME. A command whose needs.config token is not
719
+ * its command family's section is a construction error. The shell owns
720
+ * the tree; a command family owns its section.
721
+ */
722
+ interface CommandFamily {
723
+ readonly configSection: ConfigSection<unknown> | undefined;
724
+ readonly commands: Readonly<Record<string, AnyCommand>>;
725
+ /**
726
+ * The family's documentation base URL. The engine derives each
727
+ * diagnostic's docs link from base + code.
728
+ */
729
+ readonly docsBaseUrl: string | undefined;
730
+ }
731
+ declare function defineCommandFamily(spec: {
732
+ readonly configSection?: ConfigSection<unknown>;
733
+ readonly commands: Readonly<Record<string, AnyCommand>>;
734
+ readonly docsBaseUrl?: string;
735
+ }): CommandFamily;
736
+ /** What the shell builds: commands by PATH (space-separated, 'db migrate'). */
737
+ type MountedTree = Readonly<Record<string, AnyCommand>>;
738
+ //#endregion
739
+ //#region src/run-summary.d.ts
740
+ /**
741
+ * The value-free command snapshot the engine records at parse time and
742
+ * hands to `RunHooks.onSettled`. Consumed by the shell's telemetry
743
+ * wiring; carries NO user data — command-path segments, flag names
744
+ * with their value source, and a bare count of positionals. Flag
745
+ * values, positional values, and raw argv never appear here.
746
+ */
747
+ interface EngineCommandSnapshot {
748
+ /** Mount-path segments of the executed command ('telemetry status'
749
+ * → ['telemetry', 'status']). Never includes the binary name. */
750
+ readonly commandPath: readonly string[];
751
+ /**
752
+ * One entry per flag the command accepts (the engine-injected shared
753
+ * family first, then the command's own declarations), named in the
754
+ * user-facing kebab-case spelling. `source` is what the engine knows
755
+ * at parse time: flags explicitly present on argv are 'cli'; the
756
+ * engine reads no flags from the environment today, so everything
757
+ * else is 'default'. 'env' is reserved for a future env-sourced
758
+ * flag mechanism.
759
+ */
760
+ readonly flags: ReadonlyArray<{
761
+ readonly name: string;
762
+ readonly source: "cli" | "env" | "default";
763
+ }>;
764
+ /** How many positional arguments the run supplied — a count only. */
765
+ readonly positionalCount: number;
766
+ }
767
+ /**
768
+ * What `RunHooks.onSettled` receives, exactly once per run, after the
769
+ * run has settled (exit code determined, terminal output written).
770
+ * Never fired for `--help` or `--version`, and never for a run that
771
+ * failed before a mounted command was reached (nothing executed, so
772
+ * there is no snapshot to report). `durationMs` comes from the
773
+ * engine's injectable clock.
774
+ */
775
+ interface RunSummary {
776
+ /** The mounted command's dotted id ('telemetry.status'). Derived
777
+ * from the same mount entry as `snapshot.commandPath` — it always
778
+ * equals `snapshot.commandPath.join('.')`. Both are kept: consumers
779
+ * addressing the command use the id; the snapshot is the value-free
780
+ * wire projection. */
781
+ readonly commandId: string;
782
+ readonly exitCode: number;
783
+ readonly durationMs: number;
784
+ readonly snapshot: EngineCommandSnapshot;
785
+ }
786
+ //#endregion
787
+ export { positional as $, Block as A, Severity as B, LoadedConfig as C, CommandContext as D, Runtime as E, PresentedResult as F, defineConfigSection as G, StreamMeta as H, TreeNode as I, Char as J, Args as K, Ui as L, Outcome as M, PRESENTED as N, Credentials as O, Presentations as P, flag as Q, ManagementApiClient$1 as R, InputStream as S, PRISMA_CONFIG_VERSION as T, ConfigSection as U, StreamEvent as V, SectionValidation as W, FlagSpec as X, CommandArgs as Y, PositionalSpec as Z, SessionCommandDefinition as _, defineCommandFamily as a, defineSessionCommand as b, CommandHandler as c, CompletedEnvelope as d, ErroredEnvelope as f, ServerCommandDefinition as g, NeedsSpec as h, MountedTree as i, Format as j, PromptSurface as k, CommandHelp as l, HelpSpec as m, RunSummary as n, AnyCommand as o, Handler as p, ArgsSpec as q, CommandFamily as r, CommandDefinition as s, EngineCommandSnapshot as t, CommandNeeds as u, defineCommand as v, OutputStream as w, HostProcess as x, defineServerCommand as y, EngineEvent as z };