@prisma/cli-engine 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +77 -2
- package/dist/index.js +121 -3
- package/dist/{protocol-DGUfR-Ni.d.ts → protocol-CpZLdxML.d.ts} +5 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/{run-summary-CPpYAYtS.d.ts → run-summary-DMFNIvjx.d.ts} +420 -40
- package/dist/testing.d.ts +137 -5
- package/dist/testing.js +432 -79
- package/dist/{engine-DXE014TZ.js → token-claims-DXO0q52l.js} +1234 -407
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-
|
|
2
|
-
import { ManagementApiClient } from "@prisma/management-api-sdk";
|
|
1
|
+
import { i as NextAction, n as CliStructuredError, r as Diagnostic, s as Result } from "./protocol-CpZLdxML.js";
|
|
2
|
+
import { ManagementApiClient, TokenStorage } from "@prisma/management-api-sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/args.d.ts
|
|
5
5
|
/**
|
|
@@ -127,6 +127,164 @@ declare function defineConfigSection<T>(spec: {
|
|
|
127
127
|
readonly validate: (raw: unknown | undefined) => SectionValidation<T>;
|
|
128
128
|
}): ConfigSection<T>;
|
|
129
129
|
//#endregion
|
|
130
|
+
//#region src/management-api.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* The SDK's typed client, re-exported so consumers never import
|
|
133
|
+
* @prisma/management-api-sdk directly.
|
|
134
|
+
*/
|
|
135
|
+
type ManagementApiClient$1 = ManagementApiClient;
|
|
136
|
+
/**
|
|
137
|
+
* The SDK's token-storage contract, re-exported for the same reason.
|
|
138
|
+
* CredentialManager.activeCredentialStorage returns one; the engine
|
|
139
|
+
* forwards it into SDK client config and reads it only to tell a
|
|
140
|
+
* credential that could never be renewed from one that could.
|
|
141
|
+
*/
|
|
142
|
+
type TokenStorage$1 = TokenStorage;
|
|
143
|
+
/**
|
|
144
|
+
* SDK client construction config, injected by the bin beside the
|
|
145
|
+
* credential manager. All four fields: the SDK's refreshing fetch
|
|
146
|
+
* requires the full config even though only login paths read
|
|
147
|
+
* redirectUri.
|
|
148
|
+
*/
|
|
149
|
+
interface ManagementApiClientConfig {
|
|
150
|
+
readonly clientId: string;
|
|
151
|
+
readonly redirectUri: string;
|
|
152
|
+
readonly apiBaseUrl: string;
|
|
153
|
+
readonly authBaseUrl: string;
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/credential-manager.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* The proof material. Seen by the login flow (which mints it),
|
|
159
|
+
* createSession (which stores it), and the engine (which authenticates
|
|
160
|
+
* with it). Never reaches a command.
|
|
161
|
+
*/
|
|
162
|
+
interface Credential {
|
|
163
|
+
readonly token: string;
|
|
164
|
+
readonly refreshToken: string | undefined;
|
|
165
|
+
readonly expiresAt: Date | undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* A stored logged-in-ness for one workspace — the only thing called a
|
|
169
|
+
* session. It is what `sessions()` lists, what `selectSession` selects,
|
|
170
|
+
* and what `endSession` ends. The credential behind it is internal.
|
|
171
|
+
*/
|
|
172
|
+
interface Session {
|
|
173
|
+
readonly workspaceId: string;
|
|
174
|
+
readonly workspaceName: string | undefined;
|
|
175
|
+
/** The stored ACCESS TOKEN's expiry, which rotation changes — not a
|
|
176
|
+
* deadline on the logged-in-ness. */
|
|
177
|
+
readonly expiresAt: Date | undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The stored sessions and which one is selected, read together: reads
|
|
181
|
+
* take no lock, so two reads could straddle a write and disagree.
|
|
182
|
+
* `selectedWorkspaceId` always names one of the listed sessions or is
|
|
183
|
+
* absent — a dangling selection never escapes the manager.
|
|
184
|
+
*/
|
|
185
|
+
interface StoredSessions {
|
|
186
|
+
readonly sessions: readonly Session[];
|
|
187
|
+
readonly selectedWorkspaceId: string | undefined;
|
|
188
|
+
}
|
|
189
|
+
/** Who the active credential belongs to, decoded from its own claims by
|
|
190
|
+
* the manager so no command ever holds a token to decode. */
|
|
191
|
+
interface CredentialIdentity {
|
|
192
|
+
readonly userId: string | undefined;
|
|
193
|
+
readonly email: string | undefined;
|
|
194
|
+
/** Only an online lookup supplies this; a token's claims do not
|
|
195
|
+
* carry it. */
|
|
196
|
+
readonly name: string | undefined;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Where the active credential came from — a question about the
|
|
200
|
+
* resolution, not about a session.
|
|
201
|
+
*/
|
|
202
|
+
interface CredentialOrigin {
|
|
203
|
+
/** Exists to be PRINTED: it feeds whoami's `source` field verbatim.
|
|
204
|
+
* Outside whoami's renderer and the credential-rejected error,
|
|
205
|
+
* comparing against this is a defect. */
|
|
206
|
+
readonly source: "stored" | "environment";
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* What this process authenticates as. Carries no token material.
|
|
210
|
+
*/
|
|
211
|
+
interface ActiveCredential {
|
|
212
|
+
/** Absent when nothing names it — an environment token whose claims
|
|
213
|
+
* carry no workspace. Never the empty string. */
|
|
214
|
+
readonly workspaceId: string | undefined;
|
|
215
|
+
readonly workspaceName: string | undefined;
|
|
216
|
+
readonly expiresAt: Date | undefined;
|
|
217
|
+
readonly identity: CredentialIdentity | undefined;
|
|
218
|
+
readonly origin: CredentialOrigin;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Manages the credentials this machine holds: the stored per-workspace
|
|
222
|
+
* sessions, which one is selected, and the credential this process
|
|
223
|
+
* authenticates as. Custody only — never opens a browser, never
|
|
224
|
+
* prompts, never talks to the user. Env is a construction input;
|
|
225
|
+
* nothing below the manager reads process.env. It resolves no user
|
|
226
|
+
* input: commands resolve refs against `sessions()` and pass a
|
|
227
|
+
* workspace id.
|
|
228
|
+
*/
|
|
229
|
+
interface CredentialManager {
|
|
230
|
+
/**
|
|
231
|
+
* What this process authenticates as. The DECISION — which
|
|
232
|
+
* credential, and from where — is pinned at first read; the material
|
|
233
|
+
* is read through the storage on every call, so a session replaced by
|
|
234
|
+
* another process still resolves. Local-only: never touches the
|
|
235
|
+
* network.
|
|
236
|
+
*/
|
|
237
|
+
activeCredential(): Promise<ActiveCredential | null>;
|
|
238
|
+
/** The stored sessions and the selection, read fresh. Local-only. */
|
|
239
|
+
sessions(): Promise<StoredSessions>;
|
|
240
|
+
/**
|
|
241
|
+
* Login's write. The caller names the workspace that identifies the
|
|
242
|
+
* session; for workspace-bound credentials the manager verifies the
|
|
243
|
+
* workspace_id claim matches and refuses on mismatch. Upserts by
|
|
244
|
+
* workspaceId and selects it. The workspace name is fetched
|
|
245
|
+
* best-effort after the write — failure leaves it undefined, never
|
|
246
|
+
* fails login.
|
|
247
|
+
*/
|
|
248
|
+
createSession(credential: Credential, workspaceId: string): Promise<Session>;
|
|
249
|
+
/**
|
|
250
|
+
* Select a session. Refuses a workspace with no session: there is no
|
|
251
|
+
* state in which it would afterwards be selected. Never sees the
|
|
252
|
+
* environment credential.
|
|
253
|
+
*/
|
|
254
|
+
selectSession(workspaceId: string): Promise<Session>;
|
|
255
|
+
/**
|
|
256
|
+
* End one workspace's session. Idempotent — a workspace with no
|
|
257
|
+
* session is already in the state this asks for. Clears the selection
|
|
258
|
+
* if it named that session; never auto-promotes another.
|
|
259
|
+
*/
|
|
260
|
+
endSession(workspaceId: string): Promise<void>;
|
|
261
|
+
/** End every session and clear the selection. */
|
|
262
|
+
endAllSessions(): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* ENGINE-FACING. Where the SDK reads and writes the active
|
|
265
|
+
* credential's tokens: file-backed for a stored session, memory-backed
|
|
266
|
+
* for one with no home record. Zero-argument because process pinning
|
|
267
|
+
* already ruled there is one credential per process, and an
|
|
268
|
+
* environment credential may have no workspace id to key on. Only
|
|
269
|
+
* valid once `activeCredential()` has returned non-null.
|
|
270
|
+
*
|
|
271
|
+
* The engine forwards the storage into SDK client config and never
|
|
272
|
+
* calls its methods itself — no exceptions. The engine's own read of
|
|
273
|
+
* token material goes through `activeAccessToken()`.
|
|
274
|
+
*/
|
|
275
|
+
activeCredentialStorage(): Promise<TokenStorage$1>;
|
|
276
|
+
/**
|
|
277
|
+
* ENGINE-FACING. The active credential's ACCESS token, read fresh on
|
|
278
|
+
* every call, for handing to a child process that authenticates as
|
|
279
|
+
* this process does. Never the refresh token: the child gets a
|
|
280
|
+
* snapshot it cannot refresh. Null when the material is gone (the
|
|
281
|
+
* session ended). Single consumer: ctx.spawn's credential injection
|
|
282
|
+
* (credential-manager-design.md §11.5) — the read builds no second
|
|
283
|
+
* API client, so the one-client-per-process invariant holds.
|
|
284
|
+
*/
|
|
285
|
+
activeAccessToken(): Promise<string | null>;
|
|
286
|
+
}
|
|
287
|
+
//#endregion
|
|
130
288
|
//#region src/events.d.ts
|
|
131
289
|
/**
|
|
132
290
|
* The commentary severity scale; also the log-level axis. Distinct from
|
|
@@ -218,13 +376,6 @@ interface StreamMeta {
|
|
|
218
376
|
readonly timestamp: string;
|
|
219
377
|
}
|
|
220
378
|
//#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
379
|
//#region src/presentation.d.ts
|
|
229
380
|
type Format = "human" | "json";
|
|
230
381
|
/**
|
|
@@ -322,11 +473,72 @@ interface Ui {
|
|
|
322
473
|
readonly code: (text: string) => string;
|
|
323
474
|
}
|
|
324
475
|
//#endregion
|
|
325
|
-
//#region src/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
476
|
+
//#region src/spawn.d.ts
|
|
477
|
+
/** A fully composed child invocation. `env` is the child's COMPLETE
|
|
478
|
+
* environment: the engine has already merged the invocation
|
|
479
|
+
* environment, the handler's additions, and the credential variables. */
|
|
480
|
+
interface SpawnRequest {
|
|
481
|
+
readonly command: string;
|
|
482
|
+
readonly args: readonly string[];
|
|
483
|
+
readonly cwd: string;
|
|
484
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
485
|
+
}
|
|
486
|
+
/** How a child ended. A signal-killed child carries `signal` and a null
|
|
487
|
+
* `exitCode`; handlers branch on `signal` first — a signal-killed child
|
|
488
|
+
* is an abort, not a failure. */
|
|
489
|
+
interface ChildResult {
|
|
490
|
+
readonly exitCode: number | null;
|
|
491
|
+
readonly signal: string | null;
|
|
492
|
+
}
|
|
493
|
+
/** The live child an adapter returns. */
|
|
494
|
+
interface SpawnedChild {
|
|
495
|
+
/** Resolves when the child ends. Rejects when it could not be
|
|
496
|
+
* launched at all; the engine phrases that as CLI.SPAWN_FAILED. */
|
|
497
|
+
readonly ended: Promise<ChildResult>;
|
|
498
|
+
readonly kill: (signal: "SIGTERM" | "SIGKILL") => void;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* The Runtime seam. The adapter starts the child with INHERITED stdio,
|
|
502
|
+
* in the caller's own process group (POSIX) / console (Windows) — no
|
|
503
|
+
* `detached`, no new console — so the terminal delivers Ctrl-C to the
|
|
504
|
+
* child natively.
|
|
505
|
+
*/
|
|
506
|
+
type SpawnChild = (request: SpawnRequest) => SpawnedChild;
|
|
507
|
+
/** What a handler passes to ctx.spawn. */
|
|
508
|
+
interface SpawnOptions {
|
|
509
|
+
readonly command: string;
|
|
510
|
+
readonly args?: readonly string[];
|
|
511
|
+
/** Defaults to ctx.cwd. */
|
|
512
|
+
readonly cwd?: string;
|
|
513
|
+
/** Added to, and overriding, the invocation environment. The engine's
|
|
514
|
+
* credential variables are applied last and cannot be overridden. */
|
|
515
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
516
|
+
}
|
|
517
|
+
declare const CHILD_STATUS: unique symbol;
|
|
518
|
+
/**
|
|
519
|
+
* The sanctioned settlement outcome for "exit with the child's status
|
|
520
|
+
* verbatim": no envelope, the same settlement bypass server commands
|
|
521
|
+
* use. Built exclusively by exitWithChildStatus, and only settled by a
|
|
522
|
+
* command that declares maySpawn. `nextActions` render to stderr before
|
|
523
|
+
* the process exits with the child's code.
|
|
524
|
+
*/
|
|
525
|
+
interface ChildStatusSettlement {
|
|
526
|
+
readonly [CHILD_STATUS]: true;
|
|
527
|
+
readonly exitCode: number;
|
|
528
|
+
readonly nextActions: readonly NextAction[];
|
|
529
|
+
}
|
|
530
|
+
interface ExitWithChildStatusOptions {
|
|
531
|
+
/** Engine-styled guidance printed to stderr before the exit — a
|
|
532
|
+
* failed converge's reproduce hint. The envelope stays absent. */
|
|
533
|
+
readonly nextActions?: readonly NextAction[];
|
|
329
534
|
}
|
|
535
|
+
/** A signal-killed child settles 128 + the signal number; otherwise the
|
|
536
|
+
* child's own exit code, verbatim. Unknown is never success: a signal
|
|
537
|
+
* outside the portable table, or an adapter that cannot say how the
|
|
538
|
+
* child ended (exitCode and signal both null), settles 1. */
|
|
539
|
+
declare function exitWithChildStatus(child: ChildResult, options?: ExitWithChildStatusOptions): ChildStatusSettlement;
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/context.d.ts
|
|
330
542
|
/** The handler context — the whole world arrives as one argument. */
|
|
331
543
|
interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
332
544
|
/**
|
|
@@ -341,23 +553,58 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
341
553
|
*/
|
|
342
554
|
readonly present: <T>(outcome: Outcome<T, TCode>, presentations: Presentations) => PresentedResult<T>;
|
|
343
555
|
/**
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
556
|
+
* What this process authenticates as (the manager's pinned
|
|
557
|
+
* credential), or null when signed out. Carries no token material.
|
|
558
|
+
* Read-only and local-only — safe to call anywhere; never touches
|
|
559
|
+
* the network. Throws the same structured errors the needs check
|
|
560
|
+
* raises for broken-but-not-signed-out states (sessions held, none
|
|
561
|
+
* selected).
|
|
347
562
|
*/
|
|
348
|
-
readonly
|
|
563
|
+
readonly activeCredential: () => Promise<ActiveCredential | null>;
|
|
349
564
|
/**
|
|
350
|
-
* The Management API client
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
565
|
+
* The Management API client, constructed and owned by the ENGINE:
|
|
566
|
+
* the pinned credential's client, built on first method call, once
|
|
567
|
+
* per run. A request made while signed out throws the structured
|
|
568
|
+
* CLI.CREDENTIALS_REQUIRED error (the same constructor the
|
|
569
|
+
* needs.credentials check uses).
|
|
355
570
|
*/
|
|
356
571
|
readonly api: ManagementApiClient$1;
|
|
572
|
+
/**
|
|
573
|
+
* Hands the terminal to a child process and resolves when it ends.
|
|
574
|
+
* The child inherits stdio and runs in this process's own group
|
|
575
|
+
* (POSIX) or console (Windows), so Ctrl-C reaches it natively.
|
|
576
|
+
*
|
|
577
|
+
* While a child is live the engine neither aborts nor exits on a
|
|
578
|
+
* delivered signal: it records signals and replays them into its
|
|
579
|
+
* normal ladder once the child has ended, so the engine always
|
|
580
|
+
* outlives the child. SIGTERM, which has no native path to the child,
|
|
581
|
+
* is forwarded to it. A programmatic abort of ctx.signal terminates
|
|
582
|
+
* the child with SIGTERM, a grace period, then SIGKILL.
|
|
583
|
+
*
|
|
584
|
+
* ctx.report is buffered for the duration and flushed in order when
|
|
585
|
+
* the child ends; ctx.present during a live child, and a second
|
|
586
|
+
* concurrent ctx.spawn, are engine-internal errors. A launch failure
|
|
587
|
+
* (no such command) throws CLI.SPAWN_FAILED.
|
|
588
|
+
*
|
|
589
|
+
* Only commands declaring `maySpawn` may call it. Branch on `signal`
|
|
590
|
+
* before `exitCode`: a signal-killed child is an abort, not a
|
|
591
|
+
* failure.
|
|
592
|
+
*/
|
|
593
|
+
readonly spawn: (options: SpawnOptions) => Promise<ChildResult>;
|
|
357
594
|
/** The one way to emit while running. */
|
|
358
595
|
readonly report: (event: EngineEvent) => void;
|
|
359
596
|
/** Interactive input. */
|
|
360
597
|
readonly prompt: PromptSurface;
|
|
598
|
+
/**
|
|
599
|
+
* Shows the user a URL and, in an interactive session, opens it in
|
|
600
|
+
* their browser. Always announces the URL on the commentary channel
|
|
601
|
+
* (an `endpoint` event: a stderr line in human mode, a frame in json
|
|
602
|
+
* mode), so a non-interactive run — which never opens anything — can
|
|
603
|
+
* still be completed by hand. Never fails: a browser that could not
|
|
604
|
+
* be opened reports `opened: false`. To wait for the user to finish
|
|
605
|
+
* something in that browser, use prompt.browserWait.
|
|
606
|
+
*/
|
|
607
|
+
readonly openUrl: (request: OpenUrlRequest) => Promise<OpenUrlOutcome>;
|
|
361
608
|
/**
|
|
362
609
|
* Fires on Ctrl-C/SIGTERM (engine-owned; a second signal force-exits
|
|
363
610
|
* through the runtime's exit proxy). Session commands run until it
|
|
@@ -379,6 +626,33 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
379
626
|
*/
|
|
380
627
|
readonly requireDependency: (specifier: string) => Promise<Result<void, CliStructuredError>>;
|
|
381
628
|
}
|
|
629
|
+
interface OpenUrlRequest {
|
|
630
|
+
readonly url: string;
|
|
631
|
+
/** The announcement label — what the URL is for, in the user's
|
|
632
|
+
* terms ("Finish signing in"). */
|
|
633
|
+
readonly message: string;
|
|
634
|
+
}
|
|
635
|
+
interface OpenUrlOutcome {
|
|
636
|
+
/** False whenever the browser was not launched: a non-interactive
|
|
637
|
+
* session, a host with no opener wired, or an opener that failed. */
|
|
638
|
+
readonly opened: boolean;
|
|
639
|
+
}
|
|
640
|
+
interface BrowserWaitRequest {
|
|
641
|
+
readonly url: string;
|
|
642
|
+
/** The announcement label — what the user is being sent to do. */
|
|
643
|
+
readonly message: string;
|
|
644
|
+
/**
|
|
645
|
+
* Asks whether the user has finished. The engine calls it on its own
|
|
646
|
+
* interval and passes ctx.signal, so a poll that makes a request can
|
|
647
|
+
* abort with the command.
|
|
648
|
+
*/
|
|
649
|
+
readonly poll: (signal: AbortSignal) => Promise<boolean>;
|
|
650
|
+
/** Milliseconds to keep polling before giving up. */
|
|
651
|
+
readonly timeout: number;
|
|
652
|
+
/** Milliseconds between polls. Defaults to the engine's own
|
|
653
|
+
* interval; a command with its own configurable cadence passes it. */
|
|
654
|
+
readonly interval?: number;
|
|
655
|
+
}
|
|
382
656
|
/**
|
|
383
657
|
* Prompts. Every prompt resolves to its answered value directly.
|
|
384
658
|
* Failures THROW engine-internal structured errors the engine catches
|
|
@@ -400,10 +674,20 @@ interface PromptSurface {
|
|
|
400
674
|
}) => Promise<boolean>;
|
|
401
675
|
/**
|
|
402
676
|
* A question requiring explicit consent — never inferable.
|
|
403
|
-
* Structurally undefaultable: no default parameter exists, so --yes
|
|
404
|
-
* Enter-through
|
|
677
|
+
* Structurally undefaultable: no default parameter exists, so --yes
|
|
678
|
+
* and Enter-through can never satisfy it.
|
|
679
|
+
*
|
|
680
|
+
* `token` is the natural noun of what is being consented to — an app
|
|
681
|
+
* name, a hostname. Supplying one changes both halves of the prompt:
|
|
682
|
+
* interactively the user must type the token exactly instead of
|
|
683
|
+
* answering yes/no, and non-interactively the consent is granted by
|
|
684
|
+
* `--confirm <token>` on the command line (one `--confirm` value per
|
|
685
|
+
* consent). Without a token there is no non-interactive way to
|
|
686
|
+
* consent at all.
|
|
405
687
|
*/
|
|
406
|
-
readonly consent: (question: string
|
|
688
|
+
readonly consent: (question: string, opts?: {
|
|
689
|
+
readonly token?: string;
|
|
690
|
+
}) => Promise<boolean>;
|
|
407
691
|
readonly select: <T extends string>(question: string, options: ReadonlyArray<{
|
|
408
692
|
value: T;
|
|
409
693
|
label: string;
|
|
@@ -414,6 +698,20 @@ interface PromptSurface {
|
|
|
414
698
|
readonly placeholder?: string;
|
|
415
699
|
readonly default?: string;
|
|
416
700
|
}) => Promise<string>;
|
|
701
|
+
/**
|
|
702
|
+
* Sends the user to a URL and waits for them to finish there:
|
|
703
|
+
* announces the URL, opens the browser, then polls until `poll`
|
|
704
|
+
* returns true. Resolves when it does; throws the structured timeout
|
|
705
|
+
* error when `timeout` elapses first, and the usual prompt-cancelled
|
|
706
|
+
* error (exit 3) on Ctrl-C.
|
|
707
|
+
*
|
|
708
|
+
* Non-interactively it throws the interaction-required error before
|
|
709
|
+
* opening or polling anything, with the URL in the message so the
|
|
710
|
+
* user can finish by hand. A command that cannot do anything useful
|
|
711
|
+
* without an interactive terminal should declare `needs.interaction`
|
|
712
|
+
* instead and fail before it starts.
|
|
713
|
+
*/
|
|
714
|
+
readonly browserWait: (request: BrowserWaitRequest) => Promise<void>;
|
|
417
715
|
}
|
|
418
716
|
//#endregion
|
|
419
717
|
//#region src/runtime.d.ts
|
|
@@ -458,7 +756,35 @@ interface Runtime {
|
|
|
458
756
|
* the unified loader. Tests hand in fixtures.
|
|
459
757
|
*/
|
|
460
758
|
readonly config: LoadedConfig;
|
|
461
|
-
|
|
759
|
+
/**
|
|
760
|
+
* The credential manager the bin wires. It is the only source of
|
|
761
|
+
* the needs check, ctx.activeCredential, and ctx.api; absent means
|
|
762
|
+
* this host has no credentials at all, and every command that needs
|
|
763
|
+
* them fails as signed out.
|
|
764
|
+
*/
|
|
765
|
+
readonly credentialManager?: CredentialManager;
|
|
766
|
+
/**
|
|
767
|
+
* SDK client construction config the bin injects beside the
|
|
768
|
+
* manager; the engine builds ctx.api from it. Required whenever a
|
|
769
|
+
* credentialManager is wired.
|
|
770
|
+
*/
|
|
771
|
+
readonly managementApiClientConfig?: ManagementApiClientConfig;
|
|
772
|
+
/**
|
|
773
|
+
* Opens a URL in the user's browser, wired by the bin (the login
|
|
774
|
+
* flow's opener). The engine calls it only for interactive sessions,
|
|
775
|
+
* treats a throw as "did not open", and never fails a command over
|
|
776
|
+
* it. Absent means this host cannot open a browser: the engine
|
|
777
|
+
* announces the URL instead.
|
|
778
|
+
*/
|
|
779
|
+
readonly openUrl?: (url: string) => Promise<void> | void;
|
|
780
|
+
/**
|
|
781
|
+
* Starts a child process with inherited stdio, wired by the bin (a
|
|
782
|
+
* node:child_process adapter) so the engine never imports it. Absent
|
|
783
|
+
* means this host cannot hand the terminal to a child: a maySpawn
|
|
784
|
+
* command is refused as an internal error before its needs check and
|
|
785
|
+
* handler run, so ctx.spawn is never reached.
|
|
786
|
+
*/
|
|
787
|
+
readonly spawn?: SpawnChild;
|
|
462
788
|
/** Management API endpoint config; the bin derives baseUrl from env. */
|
|
463
789
|
readonly managementApi: {
|
|
464
790
|
readonly baseUrl: string;
|
|
@@ -558,8 +884,17 @@ interface NeedsSpec<TConfig> {
|
|
|
558
884
|
* its error diagnostics, hand me the value as ctx.config.
|
|
559
885
|
*/
|
|
560
886
|
readonly config?: ConfigSection<TConfig>;
|
|
561
|
-
/**
|
|
562
|
-
|
|
887
|
+
/**
|
|
888
|
+
* Fail early with the sign-in error when unauthenticated. The
|
|
889
|
+
* `"child"` form (S3) additionally makes the engine compose the
|
|
890
|
+
* active credential into every child environment
|
|
891
|
+
* (PRISMA_SERVICE_TOKEN, PRISMA_WORKSPACE_ID) and refuse the run
|
|
892
|
+
* before the handler when that credential expires too soon to hand
|
|
893
|
+
* out — a child cannot refresh the snapshot it is given. It
|
|
894
|
+
* requires `maySpawn` (construction error otherwise) and entails
|
|
895
|
+
* the plain credentials need.
|
|
896
|
+
*/
|
|
897
|
+
readonly credentials?: true | "child";
|
|
563
898
|
/**
|
|
564
899
|
* Optional peer dependencies this command cannot run without; the
|
|
565
900
|
* engine probes resolvability and phrases the install error.
|
|
@@ -580,11 +915,24 @@ interface NeedsSpec<TConfig> {
|
|
|
580
915
|
/** The normalized preconditions a definition carries. */
|
|
581
916
|
interface CommandNeeds<TConfig> {
|
|
582
917
|
readonly config: ConfigSection<TConfig> | undefined;
|
|
583
|
-
readonly credentials: boolean;
|
|
918
|
+
readonly credentials: boolean | "child";
|
|
584
919
|
readonly dependencies: readonly string[];
|
|
585
920
|
readonly interaction: boolean;
|
|
586
921
|
}
|
|
587
|
-
|
|
922
|
+
/**
|
|
923
|
+
* The terminal-handoff declaration, normalized onto every definition
|
|
924
|
+
* (server commands normalize to false: they own stdio already).
|
|
925
|
+
*
|
|
926
|
+
* `maySpawn` unlocks ctx.spawn and makes the command reject `--json`
|
|
927
|
+
* as soon as the command is known, before anything runs: output
|
|
928
|
+
* delegated to a child process cannot be framed. Handing credentials
|
|
929
|
+
* to the child is a precondition, declared as
|
|
930
|
+
* `needs: { credentials: "child" }`.
|
|
931
|
+
*/
|
|
932
|
+
interface SpawnDeclarations {
|
|
933
|
+
readonly maySpawn?: boolean;
|
|
934
|
+
}
|
|
935
|
+
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, TManagesCredentials extends boolean = false> {
|
|
588
936
|
readonly kind: "result-command";
|
|
589
937
|
readonly help: CommandHelp;
|
|
590
938
|
readonly args: CommandArgs<TFlags, TPositionals>;
|
|
@@ -596,6 +944,16 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
596
944
|
* exits 0/1/2/3 and the outcome carries no exitCode.
|
|
597
945
|
*/
|
|
598
946
|
readonly exitCodes: Readonly<Record<TCode, string>>;
|
|
947
|
+
/**
|
|
948
|
+
* A CAPABILITY, not a need: when true, ctx.credentialManager appears
|
|
949
|
+
* on the context. Declaring it never fails a run — this is
|
|
950
|
+
* documentation and testability, not enforcement. Declared by
|
|
951
|
+
* exactly the auth commands that operate ON the credential
|
|
952
|
+
* machinery.
|
|
953
|
+
*/
|
|
954
|
+
readonly managesCredentials: TManagesCredentials;
|
|
955
|
+
/** See SpawnDeclarations. */
|
|
956
|
+
readonly maySpawn: boolean;
|
|
599
957
|
/**
|
|
600
958
|
* The handler function, referenced directly — never a dynamic import
|
|
601
959
|
* (operator ruling, 2026-08-09). A handler that needs heavy
|
|
@@ -603,37 +961,56 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
603
961
|
* handler defined in another file is imported statically and
|
|
604
962
|
* annotated CommandHandler<typeof def>.
|
|
605
963
|
*/
|
|
606
|
-
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
|
|
964
|
+
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials>;
|
|
607
965
|
}
|
|
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>
|
|
966
|
+
type Handler<TFlags extends Record<string, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>>, TConfig, TCode extends number = never, TManagesCredentials extends boolean = false> = (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig, TCode> & (TManagesCredentials extends true ? {
|
|
967
|
+
readonly credentialManager: CredentialManager;
|
|
968
|
+
} : unknown)) => Promise<Result<PresentedResult<unknown> | ChildStatusSettlement, CliStructuredError>>;
|
|
609
969
|
/** 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;
|
|
970
|
+
type CommandHandler<D> = D extends CommandDefinition<infer F, infer P, infer C, infer K, infer M> ? Handler<F, P, C, K, M> : never;
|
|
971
|
+
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: {
|
|
972
|
+
readonly help: HelpSpec;
|
|
973
|
+
readonly args?: ArgsSpec<TFlags, TPositionals>;
|
|
974
|
+
readonly needs?: NeedsSpec<TConfig>;
|
|
975
|
+
readonly exitCodes?: Readonly<Record<TCode, string>>;
|
|
976
|
+
readonly managesCredentials: true;
|
|
977
|
+
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, true>;
|
|
978
|
+
} & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode, true>;
|
|
611
979
|
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
980
|
readonly help: HelpSpec;
|
|
613
981
|
readonly args?: ArgsSpec<TFlags, TPositionals>;
|
|
614
982
|
readonly needs?: NeedsSpec<TConfig>;
|
|
615
983
|
readonly exitCodes?: Readonly<Record<TCode, string>>;
|
|
616
984
|
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode>;
|
|
617
|
-
}): CommandDefinition<TFlags, TPositionals, TConfig, TCode>;
|
|
985
|
+
} & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode>;
|
|
618
986
|
/**
|
|
619
987
|
* A session command (dev, log tail): runs until the signal fires,
|
|
620
988
|
* speaks entirely through events, returns Result<void>. No
|
|
621
|
-
* presentation, no exit-code set.
|
|
622
|
-
*
|
|
989
|
+
* presentation, no exit-code set.
|
|
990
|
+
*
|
|
991
|
+
* A session supports json mode — the event stream is its json surface —
|
|
992
|
+
* UNLESS it declares `maySpawn`, in which case it rejects --json as soon
|
|
993
|
+
* as the command is known, before anything runs (S3): output delegated
|
|
994
|
+
* to a child process cannot be framed. A session that returns
|
|
995
|
+
* ok(undefined) exits 0; one that returns ok(exitWithChildStatus(child))
|
|
996
|
+
* exits with the child's status, which is the only way a session
|
|
997
|
+
* settles non-zero without erroring.
|
|
623
998
|
*/
|
|
624
999
|
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
1000
|
readonly kind: "session-command";
|
|
626
1001
|
readonly help: CommandHelp;
|
|
627
1002
|
readonly args: CommandArgs<TFlags, TPositionals>;
|
|
628
1003
|
readonly needs: CommandNeeds<TConfig>;
|
|
629
|
-
|
|
1004
|
+
/** See SpawnDeclarations. */
|
|
1005
|
+
readonly maySpawn: boolean;
|
|
1006
|
+
readonly handler: (args: Args<TFlags, TPositionals>, ctx: CommandContext<TConfig>) => Promise<Result<undefined | ChildStatusSettlement, CliStructuredError>>;
|
|
630
1007
|
}
|
|
631
1008
|
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
1009
|
readonly help: HelpSpec;
|
|
633
1010
|
readonly args?: ArgsSpec<TFlags, TPositionals>;
|
|
634
1011
|
readonly needs?: NeedsSpec<TConfig>;
|
|
635
1012
|
readonly handler: SessionCommandDefinition<TFlags, TPositionals, TConfig>["handler"];
|
|
636
|
-
}): SessionCommandDefinition<TFlags, TPositionals, TConfig>;
|
|
1013
|
+
} & SpawnDeclarations): SessionCommandDefinition<TFlags, TPositionals, TConfig>;
|
|
637
1014
|
/**
|
|
638
1015
|
* A server command (lsp): a foreign client on the other end of stdio
|
|
639
1016
|
* owns the conversation, so the engine hands over the streams. Events,
|
|
@@ -645,6 +1022,9 @@ interface ServerCommandDefinition<TFlags extends Record<string, FlagSpec<unknown
|
|
|
645
1022
|
readonly help: CommandHelp;
|
|
646
1023
|
readonly args: CommandArgs<TFlags, Record<never, PositionalSpec<unknown>>>;
|
|
647
1024
|
readonly needs: CommandNeeds<TConfig>;
|
|
1025
|
+
/** Always false — a server command owns stdio already. Normalized so
|
|
1026
|
+
* every definition carries the field and callers read it directly. */
|
|
1027
|
+
readonly maySpawn: false;
|
|
648
1028
|
readonly handler: (args: Args<TFlags, Record<never, PositionalSpec<unknown>>>, io: {
|
|
649
1029
|
readonly stdin: InputStream;
|
|
650
1030
|
readonly stdout: OutputStream;
|
|
@@ -667,7 +1047,7 @@ declare function defineServerCommand<TFlags extends Record<string, FlagSpec<unkn
|
|
|
667
1047
|
* concrete types travel through each definition's generics, not through
|
|
668
1048
|
* this union.
|
|
669
1049
|
*/
|
|
670
|
-
type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number>, "handler"> & {
|
|
1050
|
+
type AnyCommand = (Omit<CommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown, number, boolean>, "handler"> & {
|
|
671
1051
|
readonly handler: unknown;
|
|
672
1052
|
}) | (Omit<SessionCommandDefinition<Record<string, FlagSpec<unknown>>, Record<string, PositionalSpec<unknown>>, unknown>, "handler"> & {
|
|
673
1053
|
readonly handler: unknown;
|
|
@@ -784,4 +1164,4 @@ interface RunSummary {
|
|
|
784
1164
|
readonly snapshot: EngineCommandSnapshot;
|
|
785
1165
|
}
|
|
786
1166
|
//#endregion
|
|
787
|
-
export {
|
|
1167
|
+
export { ActiveCredential as $, OpenUrlOutcome as A, exitWithChildStatus as B, InputStream as C, Runtime as D, PRISMA_CONFIG_VERSION as E, ExitWithChildStatusOptions as F, Presentations as G, Format as H, SpawnChild as I, Ui as J, PresentedResult as K, SpawnOptions as L, PromptSurface as M, ChildResult as N, BrowserWaitRequest as O, ChildStatusSettlement as P, StreamMeta as Q, SpawnRequest as R, HostProcess as S, OutputStream as T, Outcome as U, Block as V, PRESENTED as W, Severity as X, EngineEvent as Y, StreamEvent as Z, SessionCommandDefinition as _, PositionalSpec as _t, defineCommandFamily as a, StoredSessions as at, defineServerCommand as b, CommandHandler as c, TokenStorage$1 as ct, CompletedEnvelope as d, defineConfigSection as dt, Credential as et, ErroredEnvelope as f, Args as ft, ServerCommandDefinition as g, FlagSpec as gt, NeedsSpec as h, CommandArgs as ht, MountedTree as i, Session as it, OpenUrlRequest as j, CommandContext as k, CommandHelp as l, ConfigSection as lt, HelpSpec as m, Char as mt, RunSummary as n, CredentialManager as nt, AnyCommand as o, ManagementApiClient$1 as ot, Handler as p, ArgsSpec as pt, TreeNode as q, CommandFamily as r, CredentialOrigin as rt, CommandDefinition as s, ManagementApiClientConfig as st, EngineCommandSnapshot as t, CredentialIdentity as tt, CommandNeeds as u, SectionValidation as ut, SpawnDeclarations as v, flag as vt, LoadedConfig as w, defineSessionCommand as x, defineCommand as y, positional as yt, SpawnedChild as z };
|