Skip to content

Commit 2361800

Browse files
Answer Prisma 7 commands with what to run in Prisma 8: engine redirects and the shell's paths (#390)
## Intent When someone runs a Prisma 7 command against the Prisma 8 CLI, they should learn in that same run what replaced it and what to run next. Today they get only `No command registered for '<command>'`. This applies to people and to agents trained on Prisma 7. This PR is the first of four. It extends the engine's redirect mechanism, publishes it as `@prisma/cli-engine@0.10.0`, and covers the Prisma 7 commands and flags the shell owns. orm-toolchain and composer-cli add the Prisma 7 paths they own once this engine version is published. A final PR here then pins those releases and adds one test that covers every Prisma 7 path. ## Changes **Engine (`@prisma/cli-engine` 0.9.0 → 0.10.0)** - `RedirectSpec.replacement` may now be one step, an ordered list of steps, or absent. - A redirect may also set: - its own error `code` (default `CLI.COMMAND_MOVED`) - a `summary` (`{bin}` is substituted) - `help`, a command whose `--help` the error points at - `docsUrl`, rendered as an `open-url` next action - Next actions are ordered: steps, then help, then docs. - A redirect that names none of replacement, help, or docsUrl is a construction error. - A redirect that uses only the old fields renders exactly as before; the existing tests pass unchanged. - The minor version moves because the normalized `CommandRedirect.replacement` changed from `string` to `readonly string[]`. **Shell (`packages/cli/src/v7-redirects.ts`)** - A command family with no commands, holding the shell's Prisma 7 redirects: - **Paths, answered with `CLI.V7_COMMAND`:** `bootstrap`, `postgres link`, `platform status`, `version`, `complete`, `debug`, `mcp`. - **`init` flags, answered with `CLI.V7_FLAG`:** `--db`, `--datasource-provider`, `--generator-provider`, `--preview-feature`, `--output`, `--url`, `--with-model`, `--no-skills`. - Each error names the Prisma 8 equivalent as `run-command` next actions, points at its `--help` (or at the CLI docs when there is no equivalent), and says in `why` what the equivalent does not cover. Prisma 7 is mentioned only in the summary. - `CLI.V7_COMMAND` and `CLI.V7_FLAG` are added to `docs/reference/error-reference.md`. **Conformance** - Two temporary exceptions allow `@prisma/orm-toolchain` and `@prisma/composer-cli` to keep peering engine `0.9.0` until they release against `0.10.0`. These are the same kind of entries #368 removed. ``` $ prisma bootstrap ✘ [CLI.V7_COMMAND] `prisma bootstrap` is a Prisma 7 command and is not available in Prisma 8 why: Setting up a new app takes two commands: `project create` creates a Project, ... → Step 1: prisma project create <name> → Step 2: prisma postgres create <name> → Read its help: prisma project create --help ``` ## Scope **Not in this PR:** - The ORM's Prisma 7 paths (`generate`, `db *`, `migrate *`, `studio`, …) belong to orm-toolchain. It already redirects the six `migrate *` paths, and the engine rejects a second family claiming the same path. - `dev ls/rm/start` and the Prisma 7 flags on `dev` belong to composer-cli. - The test that covers every Prisma 7 path comes in a later PR here, after those releases. ## Verification - `pnpm typecheck`, `pnpm lint` and `pnpm --filter @prisma/cli test` pass. The new `packages/cli/tests/v7-redirects.test.ts` has 57 cases. - `pnpm --filter @prisma/cli-engine test`: one failure, `spawn-real-child` ("child runs in the engine's own process group"). It also fails on main on the machine this was developed on. - `pnpm check:conformance` fails locally with `tarball/pack-failed` for `prisma`. The cause is Node's `fs.cpSync` failing with EACCES on the virtiofs mount the checkout sits on, and it reproduces without this branch's changes. The CI run of `check:conformance` is the result to check. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8285143 commit 2361800

15 files changed

Lines changed: 724 additions & 35 deletions

File tree

‎docs/reference/error-reference.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ The `prisma telemetry status|enable|disable` commands could not resolve the user
248248

249249
The typed path routed to no command (stricli's route failure, mapped at the adapter boundary) and no redirect claims it; next actions carry up to three "did you mean" suggestions ranked by edit distance over command paths and their prefixes, plus a pointer to `--help`. Exits 2. Meta: none.
250250

251+
### CLI.V7_COMMAND
252+
253+
The user typed a Prisma 7 command path that Prisma 8 does not have, such as `prisma bootstrap` or `prisma postgres link`; instead of failing as unknown, the redirect table settles it with the summary "`prisma <path>` is a Prisma 7 command and is not available in Prisma 8". `why` says what the suggested Prisma 8 commands do and what they do not cover. Next actions, in order: the replacement commands as run-command actions (labelled "Use the replacement" for one, "Step 1", "Step 2", … for several), a run-command pointing at the suggested command's `--help`, and an open-url action to the CLI docs when Prisma 8 has no equivalent. Each command family declares the Prisma 7 paths that relate to its own commands. Exits 2. Meta: none.
254+
255+
### CLI.V7_FLAG
256+
257+
The user passed a Prisma 7 flag that the same-named Prisma 8 command does not accept, such as `--datasource-provider` on `prisma init`; instead of failing as an unknown flag, the redirect table settles it with the summary "`--<flag>` on `prisma <command>` is a Prisma 7 flag and is not available in Prisma 8". `why` and the next actions follow `CLI.V7_COMMAND`. Exits 2. Meta: none.
258+
251259
## CONFIG
252260

253261
These codes come from Composer, the command family behind `prisma dev` and `prisma deploy`. They report a problem with the `composer` section of `prisma.config.ts`, or with what its `config` and `secrets` adapters return, and are raised before Composer starts the app.

‎packages/cli-engine/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@prisma/cli-engine",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"description": "The execution engine of the unified Prisma CLI.",
55
"type": "module",
66
"exports": {

‎packages/cli-engine/src/command-family.ts‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import type { AnyCommand } from "./commands";
22
import type { ConfigSection } from "./config-section";
33

44
/**
5-
* A retired invocation and the invocation that replaced it. Redirects
6-
* are metadata, never commands: they stay out of help and out of the
7-
* command tree, and are consulted only when an invocation fails to
8-
* resolve.
5+
* A retired invocation. Redirects are metadata, never commands: they
6+
* stay out of help and out of the command tree, and are consulted only
7+
* when an invocation fails to resolve.
98
*/
109
export interface RedirectSpec {
1110
/**
@@ -21,22 +20,25 @@ export interface RedirectSpec {
2120
* (rendered --kebab-case, as flag declarations are).
2221
*/
2322
readonly flag?: string;
24-
/**
25-
* The replacement invocation, written the way help examples are
26-
* written: no binary name, `{bin}` available when the name has to sit
27-
* mid-string. Placeholder arguments use angle brackets (`<ref>`).
28-
*/
29-
readonly replacement: string;
23+
readonly replacement?: string | readonly string[];
3024
/** One sentence of context, surfaced as the error's `why`. */
3125
readonly reason?: string;
26+
readonly code?: `${string}.${string}`;
27+
readonly summary?: string;
28+
readonly help?: string;
29+
readonly docsUrl?: string;
3230
}
3331

3432
/** The normalized redirect a command family carries. */
3533
export interface CommandRedirect {
3634
readonly from: string;
3735
readonly flag: string | undefined;
38-
readonly replacement: string;
36+
readonly replacement: readonly string[];
3937
readonly reason: string | undefined;
38+
readonly code: `${string}.${string}` | undefined;
39+
readonly summary: string | undefined;
40+
readonly help: string | undefined;
41+
readonly docsUrl: string | undefined;
4042
}
4143

4244
/**
@@ -64,12 +66,26 @@ function normalizePath(from: string): string {
6466
return from.trim().replace(/\s+/g, " ");
6567
}
6668

69+
function replacementSteps(replacement: RedirectSpec["replacement"]): string[] {
70+
if (replacement === undefined) {
71+
return [];
72+
}
73+
if (typeof replacement === "string") {
74+
return [replacement];
75+
}
76+
return [...replacement];
77+
}
78+
6779
function normalizeRedirect(spec: RedirectSpec): CommandRedirect {
6880
return Object.freeze({
6981
from: normalizePath(spec.from),
7082
flag: spec.flag,
71-
replacement: spec.replacement,
83+
replacement: Object.freeze(replacementSteps(spec.replacement)),
7284
reason: spec.reason,
85+
code: spec.code,
86+
summary: spec.summary,
87+
help: spec.help,
88+
docsUrl: spec.docsUrl,
7389
});
7490
}
7591

‎packages/cli-engine/src/execution/command-tree.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ function addFlagRedirect(
392392
table.set(key, redirect);
393393
}
394394

395+
function describeRedirect(redirect: CommandRedirect): string {
396+
return redirect.flag === undefined
397+
? `redirect '${redirect.from}'`
398+
: `redirect for flag '${redirect.flag}' on '${redirect.from}'`;
399+
}
400+
395401
export function buildRedirectTable(spec: EngineSpec): RedirectTable {
396402
const byPath = new Map<string, CommandRedirect>();
397403
const byFlag = new Map<string, CommandRedirect>();
@@ -402,6 +408,15 @@ export function buildRedirectTable(spec: EngineSpec): RedirectTable {
402408
"redirect declares an empty path, so no invocation can produce it",
403409
);
404410
}
411+
if (
412+
redirect.replacement.length === 0 &&
413+
redirect.help === undefined &&
414+
redirect.docsUrl === undefined
415+
) {
416+
throw constructionError(
417+
`${describeRedirect(redirect)} names no replacement, help, or docs URL, so it gives the user nowhere to go`,
418+
);
419+
}
405420
if (redirect.flag === undefined) {
406421
addVerbRedirect(spec, byPath, redirect);
407422
} else {

‎packages/cli-engine/src/execution/engine.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,7 @@ export class EngineImpl implements Engine {
567567
: undefined;
568568
}
569569

570-
/** stricli routed or parsed nothing runnable. When the redirect table
571-
* claims the invocation the user typed, the run names its
572-
* replacement; otherwise it settles as the usage error it is. */
570+
/** stricli routed or parsed nothing runnable. */
573571
private settleRouting(
574572
invocation: Invocation,
575573
stricliExitCode: number | string | null | undefined,

‎packages/cli-engine/src/execution/settlement.ts‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { emitFrame } from "./reporting";
3636
import {
3737
OWN_COMMAND_ROUTE,
3838
resolveExample,
39+
substituteBinName,
3940
usageErrorCode,
4041
} from "./stricli-adapter";
4142

@@ -455,9 +456,36 @@ function retiredInvocation(redirect: CommandRedirect): string {
455456
return `\`--${kebabCase(redirect.flag)}\` on \`${redirect.from}\``;
456457
}
457458

458-
/** A retired invocation the redirect table claims: the run names its
459-
* replacement instead of failing as an unknown command or flag. A
460-
* retired flag can name a server command, whose stdout belongs to a
459+
function redirectNextActions(
460+
redirect: CommandRedirect,
461+
cliName: string,
462+
): NextAction[] {
463+
const steps: NextAction[] = redirect.replacement.map((step, index) => ({
464+
kind: "run-command",
465+
label:
466+
redirect.replacement.length === 1
467+
? "Use the replacement"
468+
: `Step ${index + 1}`,
469+
command: resolveExample(step, cliName),
470+
}));
471+
const help: NextAction[] =
472+
redirect.help === undefined
473+
? []
474+
: [
475+
{
476+
kind: "run-command",
477+
label: "Read its help",
478+
command: resolveExample(`${redirect.help} --help`, cliName),
479+
},
480+
];
481+
const docs: NextAction[] =
482+
redirect.docsUrl === undefined
483+
? []
484+
: [{ kind: "open-url", label: "Read the docs", url: redirect.docsUrl }];
485+
return [...steps, ...help, ...docs];
486+
}
487+
488+
/** A retired flag can name a server command, whose stdout belongs to a
461489
* foreign client — so this settlement renders to stderr for the same
462490
* reason settleUnhandled does. */
463491
export function settleCommandMoved(
@@ -469,23 +497,22 @@ export function settleCommandMoved(
469497
if (spec.commands[redirect.from]?.kind === "server-command") {
470498
invocation.state.format = "human";
471499
}
472-
const useReplacement: NextAction = {
473-
kind: "run-command",
474-
label: "Use the replacement",
475-
command: resolveExample(redirect.replacement, spec.name),
476-
};
500+
const nextActions = redirectNextActions(redirect, spec.name);
477501
emitErrored(invocation, {
478502
ok: false,
479503
commandId,
480504
error: {
481-
code: "CLI.COMMAND_MOVED",
505+
code: redirect.code ?? "CLI.COMMAND_MOVED",
482506
severity: "error",
483-
summary: `${retiredInvocation(redirect)} has been replaced`,
507+
summary:
508+
redirect.summary === undefined
509+
? `${retiredInvocation(redirect)} has been replaced`
510+
: substituteBinName(redirect.summary, spec.name),
484511
...(redirect.reason === undefined ? {} : { why: redirect.reason }),
485-
nextActions: [useReplacement],
512+
nextActions,
486513
},
487514
diagnostics: [],
488-
nextActions: [useReplacement],
515+
nextActions,
489516
});
490517
return 2;
491518
}

‎packages/cli-engine/tests/engine.type-test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,16 @@ export const normalizedRedirectFlag: string | undefined =
393393
familyWithRedirects.redirects[0].flag;
394394
export const normalizedRedirectReason: string | undefined =
395395
familyWithRedirects.redirects[0].reason;
396-
// @ts-expect-error a redirect spec needs a replacement
397-
export const redirectWithoutReplacement: RedirectSpec = { from: "migration" };
396+
export const redirectWithoutReplacement: RedirectSpec = {
397+
from: "migration",
398+
help: "migrate",
399+
};
400+
export const redirectWithSteps: RedirectSpec = {
401+
from: "migration",
402+
replacement: ["migrate plan", "migrate apply"],
403+
};
404+
export const normalizedRedirectReplacement: readonly string[] =
405+
familyWithRedirects.redirects[0].replacement;
398406

399407
// Normalized definitions: every field is always present
400408
export const normalizedHelp: MutuallyAssignable<

0 commit comments

Comments
 (0)