@prisma/cli-engine 0.0.9 → 0.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.
|
@@ -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`
|
|
419
|
-
*
|
|
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.
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
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
|
|
439
|
-
readonly json
|
|
440
|
-
readonly next
|
|
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,254 +673,6 @@ 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> {
|
|
617
|
-
/**
|
|
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.
|
|
621
|
-
*/
|
|
622
|
-
readonly config: TConfig;
|
|
623
|
-
/**
|
|
624
|
-
* Builds the PresentedResult for the active format. The only
|
|
625
|
-
* constructor of PresentedResult.
|
|
626
|
-
*/
|
|
627
|
-
readonly present: <T>(outcome: Outcome<T, TCode>, presentations: Presentations) => PresentedResult<T>;
|
|
628
|
-
/**
|
|
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).
|
|
635
|
-
*/
|
|
636
|
-
readonly activeCredential: () => Promise<ActiveCredential | null>;
|
|
637
|
-
/**
|
|
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).
|
|
643
|
-
*/
|
|
644
|
-
readonly api: ManagementApiClient$1;
|
|
645
|
-
/**
|
|
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.
|
|
665
|
-
*/
|
|
666
|
-
readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
|
|
667
|
-
/**
|
|
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.
|
|
674
|
-
*/
|
|
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;
|
|
680
|
-
/**
|
|
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.
|
|
688
|
-
*/
|
|
689
|
-
readonly openUrl: (request: OpenUrlRequest) => Promise<OpenUrlOutcome>;
|
|
690
|
-
/**
|
|
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
|
-
* The host's answer to "is this CI", from Runtime.isCI — what
|
|
709
|
-
* telemetry gates on. Not the engine's interactivity decision, which
|
|
710
|
-
* is its own thing (stdin a TTY, no CI in the environment,
|
|
711
|
-
* --interactive/--no-interactive), so prompts and spinners follow
|
|
712
|
-
* ctx.prompt and the engine's interaction handling, not this.
|
|
713
|
-
*/
|
|
714
|
-
readonly isCI: boolean;
|
|
715
|
-
/**
|
|
716
|
-
* Conditional optional-dependency need. Resolves when the
|
|
717
|
-
* optional peer dependency is importable from the user's project;
|
|
718
|
-
* otherwise returns the engine's structured missing-dependency error
|
|
719
|
-
* for the handler to pass to notOk.
|
|
720
|
-
*/
|
|
721
|
-
readonly requireDependency: (specifier: string) => Promise<Result<void, CliStructuredError>>;
|
|
722
|
-
}
|
|
723
|
-
interface OpenUrlRequest {
|
|
724
|
-
readonly url: string;
|
|
725
|
-
/** The announcement label — what the URL is for, in the user's
|
|
726
|
-
* terms ("Finish signing in"). */
|
|
727
|
-
readonly message: string;
|
|
728
|
-
}
|
|
729
|
-
interface OpenUrlOutcome {
|
|
730
|
-
/** False whenever the browser was not launched: a non-interactive
|
|
731
|
-
* session, a host with no opener wired, or an opener that failed. */
|
|
732
|
-
readonly opened: boolean;
|
|
733
|
-
}
|
|
734
|
-
interface BrowserWaitRequest {
|
|
735
|
-
readonly url: string;
|
|
736
|
-
/** The announcement label — what the user is being sent to do. */
|
|
737
|
-
readonly message: string;
|
|
738
|
-
/**
|
|
739
|
-
* Asks whether the user has finished. The engine calls it on its own
|
|
740
|
-
* interval and passes ctx.signal, so a poll that makes a request can
|
|
741
|
-
* abort with the command.
|
|
742
|
-
*/
|
|
743
|
-
readonly poll: (signal: AbortSignal) => Promise<boolean>;
|
|
744
|
-
/** Milliseconds to keep polling before giving up. */
|
|
745
|
-
readonly timeout: number;
|
|
746
|
-
/** Milliseconds between polls. Defaults to the engine's own
|
|
747
|
-
* interval; a command with its own configurable cadence passes it. */
|
|
748
|
-
readonly interval?: number;
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Prompts. Every prompt resolves to its answered value directly.
|
|
752
|
-
* Failures THROW engine-internal structured errors the engine catches
|
|
753
|
-
* and settles: cancellation exits 3; a prompt that cannot be operated
|
|
754
|
-
* (no default under --yes or non-interactive, an invalid answer) exits
|
|
755
|
-
* 2. A handler that does not catch simply propagates; one that catches
|
|
756
|
-
* cannot swallow the settlement — rethrow or return notOk.
|
|
757
|
-
*
|
|
758
|
-
* Every prompt except `consent` may carry a declared `default`. Under
|
|
759
|
-
* --yes and in non-interactive contexts (no TTY stdin, CI,
|
|
760
|
-
* --no-interactive — format never decides interactivity) a prompt with
|
|
761
|
-
* a default resolves to it; one without a default throws. The prompt UI
|
|
762
|
-
* writes to stderr, so an interactive json run prompts without touching
|
|
763
|
-
* the stdout stream.
|
|
764
|
-
*/
|
|
765
|
-
interface PromptSurface {
|
|
766
|
-
readonly confirm: (question: string, opts?: {
|
|
767
|
-
readonly default?: boolean;
|
|
768
|
-
}) => Promise<boolean>;
|
|
769
|
-
/**
|
|
770
|
-
* A question requiring explicit consent — never inferable.
|
|
771
|
-
* Structurally undefaultable: no default parameter exists, so --yes
|
|
772
|
-
* and Enter-through can never satisfy it.
|
|
773
|
-
*
|
|
774
|
-
* `token` is the natural noun of what is being consented to — an app
|
|
775
|
-
* name, a hostname. Supplying one changes both halves of the prompt:
|
|
776
|
-
* interactively the user must type the token exactly instead of
|
|
777
|
-
* answering yes/no, and non-interactively the consent is granted by
|
|
778
|
-
* `--confirm <token>` on the command line (one `--confirm` value per
|
|
779
|
-
* consent). Without a token there is no non-interactive way to
|
|
780
|
-
* consent at all.
|
|
781
|
-
*/
|
|
782
|
-
readonly consent: (question: string, opts?: {
|
|
783
|
-
readonly token?: string;
|
|
784
|
-
}) => Promise<boolean>;
|
|
785
|
-
readonly select: <T extends string>(question: string, options: ReadonlyArray<{
|
|
786
|
-
value: T;
|
|
787
|
-
label: string;
|
|
788
|
-
}>, opts?: {
|
|
789
|
-
readonly default?: T;
|
|
790
|
-
}) => Promise<T>;
|
|
791
|
-
readonly text: (question: string, opts?: {
|
|
792
|
-
readonly placeholder?: string;
|
|
793
|
-
readonly default?: string;
|
|
794
|
-
}) => Promise<string>;
|
|
795
|
-
/**
|
|
796
|
-
* Sends the user to a URL and waits for them to finish there:
|
|
797
|
-
* announces the URL, opens the browser, then polls until `poll`
|
|
798
|
-
* returns true. Resolves when it does; throws the structured timeout
|
|
799
|
-
* error when `timeout` elapses first, and the usual prompt-cancelled
|
|
800
|
-
* error (exit 3) on Ctrl-C.
|
|
801
|
-
*
|
|
802
|
-
* Non-interactively it throws the interaction-required error before
|
|
803
|
-
* opening or polling anything, with the URL in the message so the
|
|
804
|
-
* user can finish by hand. A command that cannot do anything useful
|
|
805
|
-
* without an interactive terminal should declare `needs.interaction`
|
|
806
|
-
* instead and fail before it starts.
|
|
807
|
-
*/
|
|
808
|
-
readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
|
|
809
|
-
}
|
|
810
|
-
//#endregion
|
|
811
|
-
//#region src/package-manager.d.ts
|
|
812
|
-
/** The package managers the engine knows how to drive. */
|
|
813
|
-
type PackageManagerId = "npm" | "pnpm" | "yarn" | "bun" | "deno";
|
|
814
|
-
/**
|
|
815
|
-
* ctx.packages: what a command declaring `installsPackages` may do to
|
|
816
|
-
* the user's project. Both operations resolve — a manager that failed
|
|
817
|
-
* is a value, not a throw — except under cancellation, which throws the
|
|
818
|
-
* abort reason so the run settles the way Ctrl-C settles everywhere
|
|
819
|
-
* else. Neither may be called while the other is still running.
|
|
820
|
-
*
|
|
821
|
-
* Success carries nothing back: the command line stays with the engine,
|
|
822
|
-
* which announces it, streams the manager's output under it, and puts
|
|
823
|
-
* the redacted spelling on a failure's next action.
|
|
824
|
-
*/
|
|
825
|
-
interface PackageOperations {
|
|
826
|
-
/** Adds dependencies to the project. */
|
|
827
|
-
install(request: {
|
|
828
|
-
/** Specifiers as the user would type them, e.g. "prisma@latest". */readonly packages: readonly string[];
|
|
829
|
-
readonly dev?: boolean; /** Defaults to ctx.cwd. */
|
|
830
|
-
readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
|
|
831
|
-
readonly manager?: PackageManagerId;
|
|
832
|
-
}): Promise<Result<void, CliStructuredError>>;
|
|
833
|
-
/** Runs a package's bin once, without adding a dependency. */
|
|
834
|
-
run(request: {
|
|
835
|
-
/** The package whose bin to execute, e.g. "skills". */readonly package: string;
|
|
836
|
-
readonly args: readonly string[]; /** Defaults to ctx.cwd. */
|
|
837
|
-
readonly cwd?: string; /** Overrides detection, so a caller can retry with another manager. */
|
|
838
|
-
readonly manager?: PackageManagerId;
|
|
839
|
-
}): Promise<Result<void, CliStructuredError>>;
|
|
840
|
-
}
|
|
841
|
-
/** One package-manager execution, handed to the host to spawn. */
|
|
842
|
-
interface PackageManagerRunRequest {
|
|
843
|
-
readonly file: string;
|
|
844
|
-
readonly args: readonly string[];
|
|
845
|
-
readonly cwd: string;
|
|
846
|
-
readonly signal: AbortSignal;
|
|
847
|
-
/** Called with each chunk as the child writes it, so the engine can
|
|
848
|
-
* emit `output` events while the operation runs. */
|
|
849
|
-
readonly onOutput: (channel: "data" | "diagnostic", chunk: string) => void;
|
|
850
|
-
}
|
|
851
|
-
/** What the child produced: its exit code — non-zero covers a manager
|
|
852
|
-
* that failed and an executable that was not there — and its stderr,
|
|
853
|
-
* bounded to the last 64 KiB. */
|
|
854
|
-
interface PackageManagerRunResult {
|
|
855
|
-
readonly exitCode: number;
|
|
856
|
-
readonly stderr: string;
|
|
857
|
-
}
|
|
858
|
-
/** Spawns a package manager on the engine's behalf. A manager that
|
|
859
|
-
* fails is a resolved result, never a rejection. */
|
|
860
|
-
type PackageManagerRunner = (request: PackageManagerRunRequest) => Promise<PackageManagerRunResult>;
|
|
861
|
-
//#endregion
|
|
862
676
|
//#region src/run-summary.d.ts
|
|
863
677
|
/**
|
|
864
678
|
* The value-free command snapshot the engine records at parse time.
|
|
@@ -972,12 +786,27 @@ interface Runtime {
|
|
|
972
786
|
readonly stderr: boolean;
|
|
973
787
|
};
|
|
974
788
|
/**
|
|
975
|
-
*
|
|
976
|
-
*
|
|
977
|
-
*
|
|
978
|
-
*
|
|
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.
|
|
979
796
|
*/
|
|
980
|
-
readonly
|
|
797
|
+
readonly outputStreamsShareDevice?: boolean;
|
|
798
|
+
/**
|
|
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.
|
|
808
|
+
*/
|
|
809
|
+
readonly isCIOverride?: boolean;
|
|
981
810
|
/**
|
|
982
811
|
* Ends the process. The bin passes process.exit; the engine is the
|
|
983
812
|
* only caller (second-signal force exit, 130/143).
|
|
@@ -1056,6 +885,25 @@ interface Runtime {
|
|
|
1056
885
|
* operation at all.
|
|
1057
886
|
*/
|
|
1058
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;
|
|
1059
907
|
}
|
|
1060
908
|
/**
|
|
1061
909
|
* The minimal process surface a bin adapts a Runtime from — Node's
|
|
@@ -1065,6 +913,10 @@ interface Runtime {
|
|
|
1065
913
|
interface HostProcess {
|
|
1066
914
|
readonly argv: readonly string[];
|
|
1067
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;
|
|
1068
920
|
cwd(): string;
|
|
1069
921
|
readonly stdout: {
|
|
1070
922
|
write(text: string): unknown;
|
|
@@ -1117,6 +969,211 @@ interface LoadedConfig {
|
|
|
1117
969
|
*/
|
|
1118
970
|
declare const PRISMA_CONFIG_VERSION = 1;
|
|
1119
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
|
|
1120
1177
|
//#region src/commands.d.ts
|
|
1121
1178
|
/**
|
|
1122
1179
|
* Command definitions carry no mount path and are runtime-discriminated
|
|
@@ -1444,4 +1501,4 @@ interface TelemetryDeclaration {
|
|
|
1444
1501
|
readonly docsUrl: string;
|
|
1445
1502
|
}
|
|
1446
1503
|
//#endregion
|
|
1447
|
-
export {
|
|
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 };
|