@prisma/cli-engine 8.0.0-rc.1 → 8.0.0-rc.2

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.
@@ -40,6 +40,15 @@ declare const flag: {
40
40
  brief: string;
41
41
  alias?: A & Char<A>;
42
42
  }): FlagSpec<boolean>;
43
+ /**
44
+ * A boolean the user can leave unsaid: `--flag`, `--no-flag`, or
45
+ * neither, which arrives as undefined. Use it when absence means
46
+ * something of its own — "ask me" rather than "no".
47
+ */
48
+ optionalBoolean<A extends string = never>(spec: {
49
+ brief: string;
50
+ alias?: A & Char<A>;
51
+ }): FlagSpec<boolean | undefined>;
43
52
  enum<const T extends readonly string[], A extends string = never>(spec: {
44
53
  brief: string;
45
54
  values: T;
@@ -415,9 +424,8 @@ interface PresentedResult<T> {
415
424
  readonly diagnostics: readonly Diagnostic[];
416
425
  /**
417
426
  * Only the active format's presentation is materialized; the other
418
- * format's fields are normalized to empty. `json` stays undefined
419
- * when the handler supplied no json presentation — the envelope's
420
- * `result` then falls back to `data`.
427
+ * format's fields are normalized to empty. In human mode `json` is
428
+ * undefined because the json presentation was never invoked.
421
429
  */
422
430
  readonly presentation: {
423
431
  readonly human: readonly Block[];
@@ -428,16 +436,19 @@ interface PresentedResult<T> {
428
436
  }
429
437
  /**
430
438
  * The per-format presentation functions a handler supplies to
431
- * ctx.present. Only the active format's functions are invoked, at the
432
- * return site. `human` composes engine primitives, rendered to stderr;
433
- * `stdout` is the machine-consumable data lines — what a pipe
434
- * receives, the human mode's only stdout writes.
439
+ * ctx.present. Every one is required: a command states each output
440
+ * surface it publishes rather than inheriting one by omission. Only the
441
+ * active format's functions are invoked, at the return site. `human`
442
+ * composes engine primitives, rendered to stderr; `stdout` is the
443
+ * machine-consumable data lines — what a pipe receives, the human
444
+ * mode's only stdout writes; `json` is the `--json` envelope's
445
+ * `result`; `next` is the suggested follow-up actions.
435
446
  */
436
447
  interface Presentations {
437
448
  readonly human: (ui: Ui) => readonly Block[];
438
- readonly stdout?: () => readonly string[];
439
- readonly json?: () => unknown;
440
- readonly next?: () => readonly NextAction[];
449
+ readonly stdout: () => readonly string[];
450
+ readonly json: () => unknown;
451
+ readonly next: () => readonly NextAction[];
441
452
  }
442
453
  /**
443
454
  * What happened: it selects the glyph (✔ ✘ ⚠ ℹ) and carries a default
@@ -535,6 +546,57 @@ interface Ui {
535
546
  readonly tone: (tone: Tone, text: string) => string;
536
547
  }
537
548
  //#endregion
549
+ //#region src/package-manager.d.ts
550
+ /** The package managers the engine knows how to drive. */
551
+ type PackageManagerId = "npm" | "pnpm" | "yarn" | "bun" | "deno";
552
+ /**
553
+ * ctx.packages: what a command declaring `installsPackages` may do to
554
+ * the user's project. Both operations resolve — a manager that failed
555
+ * is a value, not a throw — except under cancellation, which throws the
556
+ * abort reason so the run settles the way Ctrl-C settles everywhere
557
+ * else. Neither may be called while the other is still running.
558
+ *
559
+ * Success carries nothing back: the command line stays with the engine,
560
+ * which announces it, streams the manager's output under it, and puts
561
+ * the redacted spelling on a failure's next action.
562
+ */
563
+ interface PackageOperations {
564
+ /** Adds dependencies to the project. */
565
+ install(request: {
566
+ /** Specifiers as the user would type them, e.g. "prisma@latest". */readonly packages: readonly string[];
567
+ readonly dev?: boolean; /** Defaults to ctx.cwd. */
568
+ readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
569
+ readonly manager?: PackageManagerId;
570
+ }): Promise<Result<void, CliStructuredError>>;
571
+ /** Runs a package's bin once, without adding a dependency. */
572
+ run(request: {
573
+ /** The package whose bin to execute, e.g. "skills". */readonly package: string;
574
+ readonly args: readonly string[]; /** Defaults to ctx.cwd. */
575
+ readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
576
+ readonly manager?: PackageManagerId;
577
+ }): Promise<Result<void, CliStructuredError>>;
578
+ }
579
+ /** One package-manager execution, handed to the host to spawn. */
580
+ interface PackageManagerRunRequest {
581
+ readonly file: string;
582
+ readonly args: readonly string[];
583
+ readonly cwd: string;
584
+ readonly signal: AbortSignal;
585
+ /** Called with each chunk as the child writes it, so the engine can
586
+ * emit `output` events while the operation runs. */
587
+ readonly onOutput: (channel: "data" | "diagnostic", chunk: string) => void;
588
+ }
589
+ /** What the child produced: its exit code — non-zero covers a manager
590
+ * that failed and an executable that was not there — and its stderr,
591
+ * bounded to the last 64 KiB. */
592
+ interface PackageManagerRunResult {
593
+ readonly exitCode: number;
594
+ readonly stderr: string;
595
+ }
596
+ /** Spawns a package manager on the engine's behalf. A manager that
597
+ * fails is a resolved result, never a rejection. */
598
+ type PackageManagerRunner = (request: PackageManagerRunRequest) => Promise<PackageManagerRunResult>;
599
+ //#endregion
538
600
  //#region src/spawn.d.ts
539
601
  /** A fully composed child invocation. `env` is the child's COMPLETE
540
602
  * environment: the engine has already merged the invocation
@@ -611,399 +673,160 @@ interface ExitWithChildStatusOptions {
611
673
  */
612
674
  declare function exitWithChildStatus(options?: ExitWithChildStatusOptions): ChildStatusSettlement;
613
675
  //#endregion
614
- //#region src/context.d.ts
615
- /** The handler context — the whole world arrives as one argument. */
616
- interface CommandContext<TConfig = undefined, TCode extends number = never> {
676
+ //#region src/run-summary.d.ts
677
+ /**
678
+ * The value-free command snapshot the engine records at parse time.
679
+ * The engine's own telemetry composes its payload from it at command
680
+ * start, and it rides along on the RunSummary a bin may observe.
681
+ * Carries NO user data — command-path segments, flag names with their
682
+ * value source, and a bare count of positionals. Flag values,
683
+ * positional values, and raw argv never appear here.
684
+ */
685
+ interface EngineCommandSnapshot {
686
+ /** Mount-path segments of the executed command ('telemetry status'
687
+ * → ['telemetry', 'status']). Never includes the binary name. */
688
+ readonly commandPath: readonly string[];
617
689
  /**
618
- * The validated value of the command's needed config section —
619
- * exactly TConfig; absence semantics belong to the section's
620
- * validator. Commands with no config need get undefined.
690
+ * One entry per flag the command accepts (the engine-injected shared
691
+ * family first, then the command's own declarations), named in the
692
+ * user-facing kebab-case spelling. `source` is what the engine knows
693
+ * at parse time: flags explicitly present on argv are 'cli'; the
694
+ * engine reads no flags from the environment today, so everything
695
+ * else is 'default'. 'env' is reserved for a future env-sourced
696
+ * flag mechanism.
621
697
  */
622
- readonly config: TConfig;
698
+ readonly flags: ReadonlyArray<{
699
+ readonly name: string;
700
+ readonly source: "cli" | "env" | "default";
701
+ }>;
702
+ /** How many positional arguments the run supplied — a count only. */
703
+ readonly positionalCount: number;
704
+ }
705
+ /**
706
+ * What `RunHooks.onSettled` receives, exactly once per run, after the
707
+ * run has settled (exit code determined, terminal output written).
708
+ * Never fired for `--help` or `--version`, and never for a run that
709
+ * failed before a mounted command was reached (nothing executed, so
710
+ * there is no snapshot to report). `durationMs` comes from the
711
+ * engine's injectable clock.
712
+ */
713
+ interface RunSummary {
714
+ /** The mounted command's dotted id ('telemetry.status'). Derived
715
+ * from the same mount entry as `snapshot.commandPath` — it always
716
+ * equals `snapshot.commandPath.join('.')`. Both are kept: consumers
717
+ * addressing the command use the id; the snapshot is the value-free
718
+ * wire projection. */
719
+ readonly commandId: string;
720
+ readonly exitCode: number;
721
+ readonly durationMs: number;
722
+ readonly snapshot: EngineCommandSnapshot;
723
+ }
724
+ //#endregion
725
+ //#region src/telemetry/payload.d.ts
726
+ /**
727
+ * The payload the engine composes at command start and hands to
728
+ * `Runtime.spawnTelemetry`. The host forwards it to its own sender,
729
+ * which probes its process (runtime/os/arch, package manager, ts
730
+ * version, agent) for the rest of the event and POSTs it.
731
+ *
732
+ * Both sides version-couple on this shape: the carrier is Node's
733
+ * structured clone over IPC, so there is no on-wire compat to maintain.
734
+ */
735
+ interface TelemetryPayload {
736
+ readonly installationId: string;
737
+ readonly version: string;
738
+ /** The command path joined with spaces — `postgres create`. */
739
+ readonly command: string;
740
+ /** Names only, of the flags the user typed. Never values. */
741
+ readonly flags: readonly string[];
623
742
  /**
624
- * Builds the PresentedResult for the active format. The only
625
- * constructor of PresentedResult.
743
+ * Absolute path of the user's project. The sender reads
744
+ * `<projectRoot>/package.json` for `tsVersion`.
626
745
  */
627
- readonly present: <T>(outcome: Outcome<T, TCode>, presentations: Presentations) => PresentedResult<T>;
746
+ readonly projectRoot: string;
747
+ /** Resolved endpoint URL (already includes the `/events` path). */
748
+ readonly endpoint: string;
628
749
  /**
629
- * What this process authenticates as (the manager's pinned
630
- * credential), or null when signed out. Carries no token material.
631
- * Read-only and local-only — safe to call anywhere; never touches
632
- * the network. Throws the same structured errors the needs check
633
- * raises for broken-but-not-signed-out states (sessions held, none
634
- * selected).
750
+ * Kept for wire compatibility with the ORM CLI's first-`init` flow,
751
+ * where the chosen target is known before the config file exists. The
752
+ * engine never populates it; the wire-format event keeps `null` as its
753
+ * "no target known" marker, but this channel needs only two states so
754
+ * the field is `string | undefined`.
635
755
  */
636
- readonly activeCredential: () => Promise<ActiveCredential | null>;
756
+ readonly databaseTarget?: string;
757
+ }
758
+ //#endregion
759
+ //#region src/runtime.d.ts
760
+ /** Minimal structural stream types; no NodeJS.* in the public surface. */
761
+ interface OutputStream {
762
+ write(text: string): void;
763
+ /** The stream's terminal width, absent when it is not a terminal.
764
+ * The engine reads it at render time rather than caching it, so a
765
+ * terminal resized mid-run is respected by the next thing drawn. */
766
+ readonly columns?: number;
767
+ }
768
+ /**
769
+ * Byte-oriented, so server commands can implement byte-counted
770
+ * protocols (lsp's Content-Length framing). setRawMode is present
771
+ * where the platform supports keypress input.
772
+ */
773
+ interface InputStream extends AsyncIterable<Uint8Array> {
774
+ readonly setRawMode?: (enabled: boolean) => void;
775
+ }
776
+ /** Everything environmental, injected once by the bin (or by a test). */
777
+ interface Runtime {
778
+ readonly stdout: OutputStream;
779
+ readonly stderr: OutputStream;
780
+ readonly stdin: InputStream;
781
+ readonly cwd: string;
782
+ readonly env: Readonly<Record<string, string | undefined>>;
783
+ readonly isTty: {
784
+ readonly stdin: boolean;
785
+ readonly stdout: boolean;
786
+ readonly stderr: boolean;
787
+ };
637
788
  /**
638
- * The Management API client, constructed and owned by the ENGINE:
639
- * the pinned credential's client, built on first method call, once
640
- * per run. A request made while signed out throws the structured
641
- * CLI.CREDENTIALS_REQUIRED error (the same constructor the
642
- * needs.credentials check uses).
789
+ * Whether stdout and stderr are the same open device — the case where
790
+ * human blocks and the machine stdout mirror would draw on one screen
791
+ * as visible duplication. Consulted only when both streams are TTYs:
792
+ * `false` there means two separate terminals, so the mirror is kept
793
+ * for whatever is reading stdout. Absent means the host cannot tell,
794
+ * which is treated as "same" — the overwhelmingly common case for two
795
+ * TTYs is one terminal.
643
796
  */
644
- readonly api: ManagementApiClient$1;
797
+ readonly outputStreamsShareDevice?: boolean;
645
798
  /**
646
- * Hands the terminal to a child process and resolves when it ends.
647
- * The child inherits stdio and runs in this process's own group
648
- * (POSIX) or console (Windows), so Ctrl-C reaches it natively.
649
- *
650
- * While a child is live the engine neither aborts nor exits on a
651
- * delivered signal: it records signals and replays them into its
652
- * normal ladder once the child has ended, so the engine always
653
- * outlives the child. SIGTERM, which has no native path to the child,
654
- * is forwarded to it. A programmatic abort of ctx.signal terminates
655
- * the child with SIGTERM, a grace period, then SIGKILL.
656
- *
657
- * ctx.report is buffered for the duration and flushed in order when
658
- * the child ends; ctx.present during a live child, and a second
659
- * concurrent ctx.spawn, are engine-internal errors. A launch failure
660
- * (no such command) throws CLI.SPAWN_FAILED.
661
- *
662
- * Only commands declaring `maySpawn` may call it. Branch on `signal`
663
- * before `exitCode`: a signal-killed child is an abort, not a
664
- * failure.
799
+ * Forces the answer to "is this CI", where telemetry never reports.
800
+ * Absent — the normal case — means the engine detects CI from `env`
801
+ * using ci-info's vendor table, which is why no host has to answer:
802
+ * unlike a TTY, CI-ness is derivable from the environment the host
803
+ * already injects, and every host computing the same boolean was the
804
+ * same detection table forked N ways. Set it only where detection
805
+ * cannot be right — an exotic platform, or a test that needs both
806
+ * sides of the branch. Absence means detected, never false, so a host
807
+ * that says nothing still stays silent in CI.
665
808
  */
666
- readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
809
+ readonly isCIOverride?: boolean;
667
810
  /**
668
- * How the run's most recent completed child ended, or undefined when
669
- * none has run. The engine records every child ctx.spawn returns, so
670
- * a handler whose spawn happens deep in its own layering can still
671
- * ask "did my child fail?" where it settles, without threading the
672
- * result back by hand. This is the same record exitWithChildStatus
673
- * settles from.
811
+ * Ends the process. The bin passes process.exit; the engine is the
812
+ * only caller (second-signal force exit, 130/143).
674
813
  */
675
- readonly lastChild: () => ChildResult | undefined;
676
- /** The one way to emit while running. */
677
- readonly report: (event: EngineEvent) => void;
678
- /** Interactive input. */
679
- readonly prompt: PromptSurface;
814
+ readonly exit: (code: number) => never;
680
815
  /**
681
- * Shows the user a URL and, in an interactive session, opens it in
682
- * their browser. Always announces the URL on the commentary channel
683
- * (an `endpoint` event: a stderr line in human mode, a frame in json
684
- * mode), so a non-interactive run — which never opens anything — can
685
- * still be completed by hand. Never fails: a browser that could not
686
- * be opened reports `opened: false`. To wait for the user to finish
687
- * something in that browser, use prompt.browserWait.
816
+ * Subscribes to delivered SIGINT/SIGTERM; returns the unsubscribe.
817
+ * The bin is dumb wiring — the engine owns the whole signal policy:
818
+ * the first signal aborts ctx.signal and awaits teardown; a second
819
+ * calls exit(130|143) immediately.
688
820
  */
689
- readonly openUrl: (request: OpenUrlRequest) => Promise<OpenUrlOutcome>;
821
+ readonly onSignal: (cb: (signal: "SIGINT" | "SIGTERM") => void) => () => void;
690
822
  /**
691
- * Fires on Ctrl-C/SIGTERM (engine-owned; a second signal force-exits
692
- * through the runtime's exit proxy). Session commands run until it
693
- * fires.
694
- *
695
- * Once it has fired the engine settles the run at 130/143 from its
696
- * own record of the signal, whatever the handler goes on to return —
697
- * so cleanup code never states an exit code of its own.
698
- */
699
- readonly signal: AbortSignal;
700
- /** Where the user invoked the CLI. Handlers never read process.cwd(). */
701
- readonly cwd: string;
702
- /**
703
- * The invocation's environment, from Runtime.env. Handlers read env
704
- * via ctx.env, never process.env.
705
- */
706
- readonly env: Readonly<Record<string, string | undefined>>;
707
- /**
708
- * Whether this run is in CI: detected from the environment the host
709
- * injected, or forced by Runtime.isCIOverride. This is what telemetry
710
- * gates on. It is one input to the engine's interactivity decision
711
- * rather than the whole of it (which also weighs a TTY stdin and
712
- * --interactive/--no-interactive), so prompts and spinners follow
713
- * ctx.prompt and the engine's interaction handling, not this.
714
- */
715
- readonly isCI: boolean;
716
- /**
717
- * Conditional optional-dependency need. Resolves when the
718
- * optional peer dependency is importable from the user's project;
719
- * otherwise returns the engine's structured missing-dependency error
720
- * for the handler to pass to notOk.
721
- */
722
- readonly requireDependency: (specifier: string) => Promise<Result<void, CliStructuredError>>;
723
- }
724
- interface OpenUrlRequest {
725
- readonly url: string;
726
- /** The announcement label — what the URL is for, in the user's
727
- * terms ("Finish signing in"). */
728
- readonly message: string;
729
- }
730
- interface OpenUrlOutcome {
731
- /** False whenever the browser was not launched: a non-interactive
732
- * session, a host with no opener wired, or an opener that failed. */
733
- readonly opened: boolean;
734
- }
735
- interface BrowserWaitRequest {
736
- readonly url: string;
737
- /** The announcement label — what the user is being sent to do. */
738
- readonly message: string;
739
- /**
740
- * Asks whether the user has finished. The engine calls it on its own
741
- * interval and passes ctx.signal, so a poll that makes a request can
742
- * abort with the command.
743
- */
744
- readonly poll: (signal: AbortSignal) => Promise<boolean>;
745
- /** Milliseconds to keep polling before giving up. */
746
- readonly timeout: number;
747
- /** Milliseconds between polls. Defaults to the engine's own
748
- * interval; a command with its own configurable cadence passes it. */
749
- readonly interval?: number;
750
- }
751
- /**
752
- * Prompts. Every prompt resolves to its answered value directly.
753
- * Failures THROW engine-internal structured errors the engine catches
754
- * and settles: cancellation exits 3; a prompt that cannot be operated
755
- * (no default under --yes or non-interactive, an invalid answer) exits
756
- * 2. A handler that does not catch simply propagates; one that catches
757
- * cannot swallow the settlement — rethrow or return notOk.
758
- *
759
- * Every prompt except `consent` may carry a declared `default`. Under
760
- * --yes and in non-interactive contexts (no TTY stdin, CI,
761
- * --no-interactive — format never decides interactivity) a prompt with
762
- * a default resolves to it; one without a default throws. The prompt UI
763
- * writes to stderr, so an interactive json run prompts without touching
764
- * the stdout stream.
765
- */
766
- interface PromptSurface {
767
- readonly confirm: (question: string, opts?: {
768
- readonly default?: boolean;
769
- }) => Promise<boolean>;
770
- /**
771
- * A question requiring explicit consent — never inferable.
772
- * Structurally undefaultable: no default parameter exists, so --yes
773
- * and Enter-through can never satisfy it.
774
- *
775
- * `token` is the natural noun of what is being consented to — an app
776
- * name, a hostname. Supplying one changes both halves of the prompt:
777
- * interactively the user must type the token exactly instead of
778
- * answering yes/no, and non-interactively the consent is granted by
779
- * `--confirm <token>` on the command line (one `--confirm` value per
780
- * consent). Without a token there is no non-interactive way to
781
- * consent at all.
782
- */
783
- readonly consent: (question: string, opts?: {
784
- readonly token?: string;
785
- }) => Promise<boolean>;
786
- readonly select: <T extends string>(question: string, options: ReadonlyArray<{
787
- value: T;
788
- label: string;
789
- }>, opts?: {
790
- readonly default?: T;
791
- }) => Promise<T>;
792
- readonly text: (question: string, opts?: {
793
- readonly placeholder?: string;
794
- readonly default?: string;
795
- }) => Promise<string>;
796
- /**
797
- * Sends the user to a URL and waits for them to finish there:
798
- * announces the URL, opens the browser, then polls until `poll`
799
- * returns true. Resolves when it does; throws the structured timeout
800
- * error when `timeout` elapses first, and the usual prompt-cancelled
801
- * error (exit 3) on Ctrl-C.
802
- *
803
- * Non-interactively it throws the interaction-required error before
804
- * opening or polling anything, with the URL in the message so the
805
- * user can finish by hand. A command that cannot do anything useful
806
- * without an interactive terminal should declare `needs.interaction`
807
- * instead and fail before it starts.
808
- */
809
- readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
810
- }
811
- //#endregion
812
- //#region src/package-manager.d.ts
813
- /** The package managers the engine knows how to drive. */
814
- type PackageManagerId = "npm" | "pnpm" | "yarn" | "bun" | "deno";
815
- /**
816
- * ctx.packages: what a command declaring `installsPackages` may do to
817
- * the user's project. Both operations resolve — a manager that failed
818
- * is a value, not a throw — except under cancellation, which throws the
819
- * abort reason so the run settles the way Ctrl-C settles everywhere
820
- * else. Neither may be called while the other is still running.
821
- *
822
- * Success carries nothing back: the command line stays with the engine,
823
- * which announces it, streams the manager's output under it, and puts
824
- * the redacted spelling on a failure's next action.
825
- */
826
- interface PackageOperations {
827
- /** Adds dependencies to the project. */
828
- install(request: {
829
- /** Specifiers as the user would type them, e.g. "prisma@latest". */readonly packages: readonly string[];
830
- readonly dev?: boolean; /** Defaults to ctx.cwd. */
831
- readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
832
- readonly manager?: PackageManagerId;
833
- }): Promise<Result<void, CliStructuredError>>;
834
- /** Runs a package's bin once, without adding a dependency. */
835
- run(request: {
836
- /** The package whose bin to execute, e.g. "skills". */readonly package: string;
837
- readonly args: readonly string[]; /** Defaults to ctx.cwd. */
838
- readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
839
- readonly manager?: PackageManagerId;
840
- }): Promise<Result<void, CliStructuredError>>;
841
- }
842
- /** One package-manager execution, handed to the host to spawn. */
843
- interface PackageManagerRunRequest {
844
- readonly file: string;
845
- readonly args: readonly string[];
846
- readonly cwd: string;
847
- readonly signal: AbortSignal;
848
- /** Called with each chunk as the child writes it, so the engine can
849
- * emit `output` events while the operation runs. */
850
- readonly onOutput: (channel: "data" | "diagnostic", chunk: string) => void;
851
- }
852
- /** What the child produced: its exit code — non-zero covers a manager
853
- * that failed and an executable that was not there — and its stderr,
854
- * bounded to the last 64 KiB. */
855
- interface PackageManagerRunResult {
856
- readonly exitCode: number;
857
- readonly stderr: string;
858
- }
859
- /** Spawns a package manager on the engine's behalf. A manager that
860
- * fails is a resolved result, never a rejection. */
861
- type PackageManagerRunner = (request: PackageManagerRunRequest) => Promise<PackageManagerRunResult>;
862
- //#endregion
863
- //#region src/run-summary.d.ts
864
- /**
865
- * The value-free command snapshot the engine records at parse time.
866
- * The engine's own telemetry composes its payload from it at command
867
- * start, and it rides along on the RunSummary a bin may observe.
868
- * Carries NO user data — command-path segments, flag names with their
869
- * value source, and a bare count of positionals. Flag values,
870
- * positional values, and raw argv never appear here.
871
- */
872
- interface EngineCommandSnapshot {
873
- /** Mount-path segments of the executed command ('telemetry status'
874
- * → ['telemetry', 'status']). Never includes the binary name. */
875
- readonly commandPath: readonly string[];
876
- /**
877
- * One entry per flag the command accepts (the engine-injected shared
878
- * family first, then the command's own declarations), named in the
879
- * user-facing kebab-case spelling. `source` is what the engine knows
880
- * at parse time: flags explicitly present on argv are 'cli'; the
881
- * engine reads no flags from the environment today, so everything
882
- * else is 'default'. 'env' is reserved for a future env-sourced
883
- * flag mechanism.
884
- */
885
- readonly flags: ReadonlyArray<{
886
- readonly name: string;
887
- readonly source: "cli" | "env" | "default";
888
- }>;
889
- /** How many positional arguments the run supplied — a count only. */
890
- readonly positionalCount: number;
891
- }
892
- /**
893
- * What `RunHooks.onSettled` receives, exactly once per run, after the
894
- * run has settled (exit code determined, terminal output written).
895
- * Never fired for `--help` or `--version`, and never for a run that
896
- * failed before a mounted command was reached (nothing executed, so
897
- * there is no snapshot to report). `durationMs` comes from the
898
- * engine's injectable clock.
899
- */
900
- interface RunSummary {
901
- /** The mounted command's dotted id ('telemetry.status'). Derived
902
- * from the same mount entry as `snapshot.commandPath` — it always
903
- * equals `snapshot.commandPath.join('.')`. Both are kept: consumers
904
- * addressing the command use the id; the snapshot is the value-free
905
- * wire projection. */
906
- readonly commandId: string;
907
- readonly exitCode: number;
908
- readonly durationMs: number;
909
- readonly snapshot: EngineCommandSnapshot;
910
- }
911
- //#endregion
912
- //#region src/telemetry/payload.d.ts
913
- /**
914
- * The payload the engine composes at command start and hands to
915
- * `Runtime.spawnTelemetry`. The host forwards it to its own sender,
916
- * which probes its process (runtime/os/arch, package manager, ts
917
- * version, agent) for the rest of the event and POSTs it.
918
- *
919
- * Both sides version-couple on this shape: the carrier is Node's
920
- * structured clone over IPC, so there is no on-wire compat to maintain.
921
- */
922
- interface TelemetryPayload {
923
- readonly installationId: string;
924
- readonly version: string;
925
- /** The command path joined with spaces — `postgres create`. */
926
- readonly command: string;
927
- /** Names only, of the flags the user typed. Never values. */
928
- readonly flags: readonly string[];
929
- /**
930
- * Absolute path of the user's project. The sender reads
931
- * `<projectRoot>/package.json` for `tsVersion`.
932
- */
933
- readonly projectRoot: string;
934
- /** Resolved endpoint URL (already includes the `/events` path). */
935
- readonly endpoint: string;
936
- /**
937
- * Kept for wire compatibility with the ORM CLI's first-`init` flow,
938
- * where the chosen target is known before the config file exists. The
939
- * engine never populates it; the wire-format event keeps `null` as its
940
- * "no target known" marker, but this channel needs only two states so
941
- * the field is `string | undefined`.
942
- */
943
- readonly databaseTarget?: string;
944
- }
945
- //#endregion
946
- //#region src/runtime.d.ts
947
- /** Minimal structural stream types; no NodeJS.* in the public surface. */
948
- interface OutputStream {
949
- write(text: string): void;
950
- /** The stream's terminal width, absent when it is not a terminal.
951
- * The engine reads it at render time rather than caching it, so a
952
- * terminal resized mid-run is respected by the next thing drawn. */
953
- readonly columns?: number;
954
- }
955
- /**
956
- * Byte-oriented, so server commands can implement byte-counted
957
- * protocols (lsp's Content-Length framing). setRawMode is present
958
- * where the platform supports keypress input.
959
- */
960
- interface InputStream extends AsyncIterable<Uint8Array> {
961
- readonly setRawMode?: (enabled: boolean) => void;
962
- }
963
- /** Everything environmental, injected once by the bin (or by a test). */
964
- interface Runtime {
965
- readonly stdout: OutputStream;
966
- readonly stderr: OutputStream;
967
- readonly stdin: InputStream;
968
- readonly cwd: string;
969
- readonly env: Readonly<Record<string, string | undefined>>;
970
- readonly isTty: {
971
- readonly stdin: boolean;
972
- readonly stdout: boolean;
973
- readonly stderr: boolean;
974
- };
975
- /**
976
- * Forces the answer to "is this CI", where telemetry never reports.
977
- * Absent — the normal case — means the engine detects CI from `env`
978
- * using ci-info's vendor table, which is why no host has to answer:
979
- * unlike a TTY, CI-ness is derivable from the environment the host
980
- * already injects, and every host computing the same boolean was the
981
- * same detection table forked N ways. Set it only where detection
982
- * cannot be right — an exotic platform, or a test that needs both
983
- * sides of the branch. Absence means detected, never false, so a host
984
- * that says nothing still stays silent in CI.
985
- */
986
- readonly isCIOverride?: boolean;
987
- /**
988
- * Ends the process. The bin passes process.exit; the engine is the
989
- * only caller (second-signal force exit, 130/143).
990
- */
991
- readonly exit: (code: number) => never;
992
- /**
993
- * Subscribes to delivered SIGINT/SIGTERM; returns the unsubscribe.
994
- * The bin is dumb wiring — the engine owns the whole signal policy:
995
- * the first signal aborts ctx.signal and awaits teardown; a second
996
- * calls exit(130|143) immediately.
997
- */
998
- readonly onSignal: (cb: (signal: "SIGINT" | "SIGTERM") => void) => () => void;
999
- /**
1000
- * Reads prisma.config.ts, on demand. The engine calls it only when
1001
- * the command it is about to run declares a config section, so a run
1002
- * that needs no config never touches the file. `configPath` is the
1003
- * file `--config` named: the loader resolves it against the runtime's
1004
- * cwd and reports its absence. Absent means look for prisma.config.ts
1005
- * in cwd, where absence is not an error. The bin wires the real disk
1006
- * loader; tests hand in fixtures.
823
+ * Reads prisma.config.ts, on demand. The engine calls it only when
824
+ * the command it is about to run declares a config section, so a run
825
+ * that needs no config never touches the file. `configPath` is the
826
+ * file `--config` named: the loader resolves it against the runtime's
827
+ * cwd and reports its absence. Absent means look for prisma.config.ts
828
+ * in cwd, where absence is not an error. The bin wires the real disk
829
+ * loader; tests hand in fixtures.
1007
830
  */
1008
831
  readonly loadConfig: (configPath?: string) => Promise<LoadedConfig>;
1009
832
  /**
@@ -1062,6 +885,25 @@ interface Runtime {
1062
885
  * operation at all.
1063
886
  */
1064
887
  readonly runPackageManager?: PackageManagerRunner;
888
+ /** What this process is running on. The bin reads it once; commands
889
+ * take it from ctx.host rather than from process. */
890
+ readonly host: Host;
891
+ }
892
+ /**
893
+ * The facts a command may legitimately need about the machine it runs
894
+ * on: what to put in a bug report, and the rare genuine behavioural
895
+ * difference (symlinks need a privilege on Windows).
896
+ *
897
+ * Deliberately not node-shaped. Products are runtime-agnostic (R4), so
898
+ * the runtime names itself rather than the field naming it.
899
+ */
900
+ interface Host {
901
+ readonly runtime: {
902
+ readonly name: string;
903
+ readonly version: string;
904
+ };
905
+ readonly platform: string;
906
+ readonly arch: string;
1065
907
  }
1066
908
  /**
1067
909
  * The minimal process surface a bin adapts a Runtime from — Node's
@@ -1071,6 +913,10 @@ interface Runtime {
1071
913
  interface HostProcess {
1072
914
  readonly argv: readonly string[];
1073
915
  readonly env: Readonly<Record<string, string | undefined>>;
916
+ readonly version: string;
917
+ readonly versions: Readonly<Record<string, string | undefined>>;
918
+ readonly platform: string;
919
+ readonly arch: string;
1074
920
  cwd(): string;
1075
921
  readonly stdout: {
1076
922
  write(text: string): unknown;
@@ -1123,6 +969,211 @@ interface LoadedConfig {
1123
969
  */
1124
970
  declare const PRISMA_CONFIG_VERSION = 1;
1125
971
  //#endregion
972
+ //#region src/context.d.ts
973
+ /** The handler context — the whole world arrives as one argument. */
974
+ interface CommandContext<TConfig = undefined, TCode extends number = never> {
975
+ /**
976
+ * The validated value of the command's needed config section —
977
+ * exactly TConfig; absence semantics belong to the section's
978
+ * validator. Commands with no config need get undefined.
979
+ */
980
+ readonly config: TConfig;
981
+ /**
982
+ * Builds the PresentedResult for the active format. The only
983
+ * constructor of PresentedResult.
984
+ */
985
+ readonly present: <T>(outcome: Outcome<T, TCode>, presentations: Presentations) => PresentedResult<T>;
986
+ /**
987
+ * What this process authenticates as (the manager's pinned
988
+ * credential), or null when signed out. Carries no token material.
989
+ * Read-only and local-only — safe to call anywhere; never touches
990
+ * the network. Throws the same structured errors the needs check
991
+ * raises for broken-but-not-signed-out states (sessions held, none
992
+ * selected).
993
+ */
994
+ readonly activeCredential: () => Promise<ActiveCredential | null>;
995
+ /**
996
+ * The Management API client, constructed and owned by the ENGINE:
997
+ * the pinned credential's client, built on first method call, once
998
+ * per run. A request made while signed out throws the structured
999
+ * CLI.CREDENTIALS_REQUIRED error (the same constructor the
1000
+ * needs.credentials check uses).
1001
+ */
1002
+ readonly api: ManagementApiClient$1;
1003
+ /**
1004
+ * Hands the terminal to a child process and resolves when it ends.
1005
+ * The child inherits stdio and runs in this process's own group
1006
+ * (POSIX) or console (Windows), so Ctrl-C reaches it natively.
1007
+ *
1008
+ * While a child is live the engine neither aborts nor exits on a
1009
+ * delivered signal: it records signals and replays them into its
1010
+ * normal ladder once the child has ended, so the engine always
1011
+ * outlives the child. SIGTERM, which has no native path to the child,
1012
+ * is forwarded to it. A programmatic abort of ctx.signal terminates
1013
+ * the child with SIGTERM, a grace period, then SIGKILL.
1014
+ *
1015
+ * ctx.report is buffered for the duration and flushed in order when
1016
+ * the child ends; ctx.present during a live child, and a second
1017
+ * concurrent ctx.spawn, are engine-internal errors. A launch failure
1018
+ * (no such command) throws CLI.SPAWN_FAILED.
1019
+ *
1020
+ * Only commands declaring `maySpawn` may call it. Branch on `signal`
1021
+ * before `exitCode`: a signal-killed child is an abort, not a
1022
+ * failure.
1023
+ */
1024
+ readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
1025
+ /**
1026
+ * How the run's most recent completed child ended, or undefined when
1027
+ * none has run. The engine records every child ctx.spawn returns, so
1028
+ * a handler whose spawn happens deep in its own layering can still
1029
+ * ask "did my child fail?" where it settles, without threading the
1030
+ * result back by hand. This is the same record exitWithChildStatus
1031
+ * settles from.
1032
+ */
1033
+ readonly lastChild: () => ChildResult | undefined;
1034
+ /** The one way to emit while running. */
1035
+ readonly report: (event: EngineEvent) => void;
1036
+ /** Interactive input. */
1037
+ readonly prompt: PromptSurface;
1038
+ /**
1039
+ * Shows the user a URL and, in an interactive session, opens it in
1040
+ * their browser. Always announces the URL on the commentary channel
1041
+ * (an `endpoint` event: a stderr line in human mode, a frame in json
1042
+ * mode), so a non-interactive run — which never opens anything — can
1043
+ * still be completed by hand. Never fails: a browser that could not
1044
+ * be opened reports `opened: false`. To wait for the user to finish
1045
+ * something in that browser, use prompt.browserWait.
1046
+ */
1047
+ readonly openUrl: (request: OpenUrlRequest) => Promise<OpenUrlOutcome>;
1048
+ /**
1049
+ * Fires on Ctrl-C/SIGTERM (engine-owned; a second signal force-exits
1050
+ * through the runtime's exit proxy). Session commands run until it
1051
+ * fires.
1052
+ *
1053
+ * Once it has fired the engine settles the run at 130/143 from its
1054
+ * own record of the signal, whatever the handler goes on to return —
1055
+ * so cleanup code never states an exit code of its own.
1056
+ */
1057
+ readonly signal: AbortSignal;
1058
+ /** Where the user invoked the CLI. Handlers never read process.cwd(). */
1059
+ readonly cwd: string;
1060
+ /**
1061
+ * The invocation's environment, from Runtime.env. Handlers read env
1062
+ * via ctx.env, never process.env.
1063
+ */
1064
+ readonly env: Readonly<Record<string, string | undefined>>;
1065
+ /**
1066
+ * What this process runs on, from Runtime.host. Handlers read the
1067
+ * runtime version, platform and architecture here — never from
1068
+ * `process` — so a bug-report payload and the occasional real
1069
+ * platform difference do not each reinvent the lookup.
1070
+ */
1071
+ readonly host: Host;
1072
+ /**
1073
+ * Whether this run is in CI: detected from the environment the host
1074
+ * injected, or forced by Runtime.isCIOverride. This is what telemetry
1075
+ * gates on. It is one input to the engine's interactivity decision
1076
+ * rather than the whole of it (which also weighs a TTY stdin and
1077
+ * --interactive/--no-interactive), so prompts and spinners follow
1078
+ * ctx.prompt and the engine's interaction handling, not this.
1079
+ */
1080
+ readonly isCI: boolean;
1081
+ /**
1082
+ * Conditional optional-dependency need. Resolves when the
1083
+ * optional peer dependency is importable from the user's project;
1084
+ * otherwise returns the engine's structured missing-dependency error
1085
+ * for the handler to pass to notOk.
1086
+ */
1087
+ readonly requireDependency: (specifier: string) => Promise<Result<void, CliStructuredError>>;
1088
+ }
1089
+ interface OpenUrlRequest {
1090
+ readonly url: string;
1091
+ /** The announcement label — what the URL is for, in the user's
1092
+ * terms ("Finish signing in"). */
1093
+ readonly message: string;
1094
+ }
1095
+ interface OpenUrlOutcome {
1096
+ /** False whenever the browser was not launched: a non-interactive
1097
+ * session, a host with no opener wired, or an opener that failed. */
1098
+ readonly opened: boolean;
1099
+ }
1100
+ interface BrowserWaitRequest {
1101
+ readonly url: string;
1102
+ /** The announcement label — what the user is being sent to do. */
1103
+ readonly message: string;
1104
+ /**
1105
+ * Asks whether the user has finished. The engine calls it on its own
1106
+ * interval and passes ctx.signal, so a poll that makes a request can
1107
+ * abort with the command.
1108
+ */
1109
+ readonly poll: (signal: AbortSignal) => Promise<boolean>;
1110
+ /** Milliseconds to keep polling before giving up. */
1111
+ readonly timeout: number;
1112
+ /** Milliseconds between polls. Defaults to the engine's own
1113
+ * interval; a command with its own configurable cadence passes it. */
1114
+ readonly interval?: number;
1115
+ }
1116
+ /**
1117
+ * Prompts. Every prompt resolves to its answered value directly.
1118
+ * Failures THROW engine-internal structured errors the engine catches
1119
+ * and settles: cancellation exits 3; a prompt that cannot be operated
1120
+ * (no default under --yes or non-interactive, an invalid answer) exits
1121
+ * 2. A handler that does not catch simply propagates; one that catches
1122
+ * cannot swallow the settlement — rethrow or return notOk.
1123
+ *
1124
+ * Every prompt except `consent` may carry a declared `default`. Under
1125
+ * --yes and in non-interactive contexts (no TTY stdin, CI,
1126
+ * --no-interactive — format never decides interactivity) a prompt with
1127
+ * a default resolves to it; one without a default throws. The prompt UI
1128
+ * writes to stderr, so an interactive json run prompts without touching
1129
+ * the stdout stream.
1130
+ */
1131
+ interface PromptSurface {
1132
+ readonly confirm: (question: string, opts?: {
1133
+ readonly default?: boolean;
1134
+ }) => Promise<boolean>;
1135
+ /**
1136
+ * A question requiring explicit consent — never inferable.
1137
+ * Structurally undefaultable: no default parameter exists, so --yes
1138
+ * and Enter-through can never satisfy it.
1139
+ *
1140
+ * `token` is the natural noun of what is being consented to — an app
1141
+ * name, a hostname. Supplying one changes both halves of the prompt:
1142
+ * interactively the user must type the token exactly instead of
1143
+ * answering yes/no, and non-interactively the consent is granted by
1144
+ * `--confirm <token>` on the command line (one `--confirm` value per
1145
+ * consent). Without a token there is no non-interactive way to
1146
+ * consent at all.
1147
+ */
1148
+ readonly consent: (question: string, opts?: {
1149
+ readonly token?: string;
1150
+ }) => Promise<boolean>;
1151
+ readonly select: <T extends string>(question: string, options: ReadonlyArray<{
1152
+ value: T;
1153
+ label: string;
1154
+ }>, opts?: {
1155
+ readonly default?: T;
1156
+ }) => Promise<T>;
1157
+ readonly text: (question: string, opts?: {
1158
+ readonly placeholder?: string;
1159
+ readonly default?: string;
1160
+ }) => Promise<string>;
1161
+ /**
1162
+ * Sends the user to a URL and waits for them to finish there:
1163
+ * announces the URL, opens the browser, then polls until `poll`
1164
+ * returns true. Resolves when it does; throws the structured timeout
1165
+ * error when `timeout` elapses first, and the usual prompt-cancelled
1166
+ * error (exit 3) on Ctrl-C.
1167
+ *
1168
+ * Non-interactively it throws the interaction-required error before
1169
+ * opening or polling anything, with the URL in the message so the
1170
+ * user can finish by hand. A command that cannot do anything useful
1171
+ * without an interactive terminal should declare `needs.interaction`
1172
+ * instead and fail before it starts.
1173
+ */
1174
+ readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
1175
+ }
1176
+ //#endregion
1126
1177
  //#region src/commands.d.ts
1127
1178
  /**
1128
1179
  * Command definitions carry no mount path and are runtime-discriminated
@@ -1450,4 +1501,4 @@ interface TelemetryDeclaration {
1450
1501
  readonly docsUrl: string;
1451
1502
  }
1452
1503
  //#endregion
1453
- export { PRESENTED as $, EngineCommandSnapshot as A, FlagSpec as At, OpenUrlRequest as B, HostProcess as C, ConfigSection as Ct, PRISMA_CONFIG_VERSION as D, ArgsSpec as Dt, OutputStream as E, Args as Et, PackageManagerRunner as F, SpawnChild as G, ChildResult as H, PackageOperations as I, SpawnedChild as J, SpawnOptions as K, BrowserWaitRequest as L, PackageManagerId as M, flag as Mt, PackageManagerRunRequest as N, positional as Nt, Runtime as O, Char as Ot, PackageManagerRunResult as P, Outcome as Q, CommandContext as R, defineSessionCommand as S, TokenStorage$1 as St, LoadedConfig as T, defineConfigSection as Tt, ChildStatusSettlement as U, PromptSurface as V, ExitWithChildStatusOptions as W, Block as X, exitWithChildStatus as Y, Format as Z, ServerCommandDefinition as _, SERVICE_TOKEN_ENV_VAR as _t, RedirectSpec as a, Tone as at, defineCommand as b, ManagementApiClient$1 as bt, CommandDefinition as c, EngineEvent as ct, CommandNeeds as d, StreamMeta as dt, Presentations as et, CompletedEnvelope as f, ActiveCredential as ft, NeedsSpec as g, CredentialOrigin as gt, HelpSpec as h, CredentialManager as ht, MountedTree as i, Text as it, RunSummary as j, PositionalSpec as jt, TelemetryPayload as k, CommandArgs as kt, CommandHandler as l, Severity as lt, Handler as m, CredentialIdentity as mt, CommandFamily as n, Span as nt, defineCommandFamily as o, TreeNode as ot, ErroredEnvelope as p, Credential as pt, SpawnRequest as q, CommandRedirect as r, Status as rt, AnyCommand as s, Ui as st, TelemetryDeclaration as t, PresentedResult as tt, CommandHelp as u, StreamEvent as ut, SessionCommandDefinition as v, Session as vt, InputStream as w, SectionValidation as wt, defineServerCommand as x, ManagementApiClientConfig as xt, SpawnDeclarations as y, StoredSessions as yt, OpenUrlOutcome as z };
1504
+ export { Outcome as $, InputStream as A, CommandArgs as At, ExitWithChildStatusOptions as B, BrowserWaitRequest as C, TokenStorage$1 as Ct, PromptSurface as D, Args as Dt, OpenUrlRequest as E, defineConfigSection as Et, TelemetryPayload as F, exitWithChildStatus as G, SpawnOptions as H, EngineCommandSnapshot as I, PackageManagerRunResult as J, PackageManagerId as K, RunSummary as L, OutputStream as M, PositionalSpec as Mt, PRISMA_CONFIG_VERSION as N, flag as Nt, Host as O, ArgsSpec as Ot, Runtime as P, positional as Pt, Format as Q, ChildResult as R, defineSessionCommand as S, ManagementApiClientConfig as St, OpenUrlOutcome as T, SectionValidation as Tt, SpawnRequest as U, SpawnChild as V, SpawnedChild as W, PackageOperations as X, PackageManagerRunner as Y, Block as Z, ServerCommandDefinition as _, CredentialOrigin as _t, RedirectSpec as a, Text as at, defineCommand as b, StoredSessions as bt, CommandDefinition as c, Ui as ct, CommandNeeds as d, StreamEvent as dt, PRESENTED as et, CompletedEnvelope as f, StreamMeta as ft, NeedsSpec as g, CredentialManager as gt, HelpSpec as h, CredentialIdentity as ht, MountedTree as i, Status as it, LoadedConfig as j, FlagSpec as jt, HostProcess as k, Char as kt, CommandHandler as l, EngineEvent as lt, Handler as m, Credential as mt, CommandFamily as n, PresentedResult as nt, defineCommandFamily as o, Tone as ot, ErroredEnvelope as p, ActiveCredential as pt, PackageManagerRunRequest as q, CommandRedirect as r, Span as rt, AnyCommand as s, TreeNode as st, TelemetryDeclaration as t, Presentations as tt, CommandHelp as u, Severity as ut, SessionCommandDefinition as v, SERVICE_TOKEN_ENV_VAR as vt, CommandContext as w, ConfigSection as wt, defineServerCommand as x, ManagementApiClient$1 as xt, SpawnDeclarations as y, Session as yt, ChildStatusSettlement as z };