@prisma-next/cli 0.8.0-dev.4 → 0.8.0-dev.5

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.
@@ -1,44 +1,109 @@
1
1
  import { execFile } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
+ import { version as cliVersion } from '../../../package.json' with { type: 'json' };
3
4
  import type { PackageManager } from './detect-package-manager';
4
5
  import { errorInitSkillInstallFailed } from './errors';
5
6
 
6
7
  const exec = promisify(execFile);
7
8
 
8
9
  /**
9
- * The npm package the agent-skill install dispatches to. Version-locked
10
- * to Prisma Next via the consumer project's `package.json`; the install
11
- * subprocess picks up whatever version is resolvable at install time.
10
+ * Default base for the GitHub-URL form `<owner>/<repo>` consumed by
11
+ * upstream `skills add`. Each `SkillSource` joins this base with its
12
+ * own subpath (and optional `#ref` for version-pinned clusters).
13
+ */
14
+ export const DEFAULT_AGENT_SKILL_BASE = 'prisma/prisma-next';
15
+
16
+ /**
17
+ * One discovery scope inside the Prisma Next monorepo. The CLI emits
18
+ * one `skills add <base>/<subpath>[#ref] --all` invocation per source
19
+ * during `init`.
20
+ *
21
+ * `ref` semantics:
22
+ * - `cli`: pin to the CLI's own package version (lockstep with the
23
+ * skills' SPI). Used for the version-locked usage cluster — the
24
+ * skills under `skills/<X>/SKILL.md`, which describe the public
25
+ * package API and are pinned to the version of `@prisma-next/*`
26
+ * currently installed in the consumer's project.
27
+ * - `null`: no ref. The cluster is "always-latest" — the cumulative
28
+ * instruction set is the source of truth, and the latest revision
29
+ * on `main` includes bug fixes for every prior transition. Used
30
+ * for the upgrade and extension-author clusters.
31
+ */
32
+ export interface SkillSource {
33
+ readonly subpath: string;
34
+ readonly ref: 'cli' | null;
35
+ readonly description: string;
36
+ }
37
+
38
+ export const DEFAULT_AGENT_SKILL_SOURCES: readonly SkillSource[] = [
39
+ {
40
+ subpath: 'skills',
41
+ ref: 'cli',
42
+ description: 'usage skills (version-locked to installed Prisma Next)',
43
+ },
44
+ {
45
+ subpath: 'skills/upgrade',
46
+ ref: null,
47
+ description: 'upgrade skill (always tracks `main`)',
48
+ },
49
+ {
50
+ subpath: 'skills/extension-author',
51
+ ref: null,
52
+ description: 'extension-author skill (always tracks `main`)',
53
+ },
54
+ ];
55
+
56
+ /**
57
+ * Test-only escape hatch for pinning the install base to a local
58
+ * checkout. Production runs leave this unset, so installs always use
59
+ * `DEFAULT_AGENT_SKILL_BASE`.
12
60
  *
13
- * The skill is **always** installed at the project level never the
14
- * user level precisely so the skill version tracks the project's
15
- * Prisma Next version. A user-level (global) install of an
16
- * agent-skills CLI package would have to pick a single version for
17
- * every project on the host, which breaks the version-locking invariant
18
- * the rest of the framework relies on (skills, CLI, runtime, and
19
- * extension packs all ship at the same version per release).
61
+ * When set to an absolute filesystem path (typical for tests), the
62
+ * `#ref` fragment is dropped local-path mode in upstream's CLI does
63
+ * not accept refs, and the local clone has whatever content the test
64
+ * checked into it anyway. When set to anything else (e.g. a fork name
65
+ * `myuser/prisma-next`), the ref policy is preserved.
66
+ */
67
+ function resolveAgentSkillBase(): string {
68
+ const override = process.env['PRISMA_NEXT_SKILLS_BASE']?.trim();
69
+ return override && override.length > 0 ? override : DEFAULT_AGENT_SKILL_BASE;
70
+ }
71
+
72
+ function isLocalPath(base: string): boolean {
73
+ return base.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(base);
74
+ }
75
+
76
+ /**
77
+ * Build the `<base>/<subpath>[#ref]` URL the `skills` CLI will
78
+ * resolve. Exported for unit tests so the per-source format can be
79
+ * asserted without going through the full install loop.
20
80
  */
21
- export const AGENT_SKILL_PACKAGE = '@prisma-next/skills';
81
+ export function formatSkillSourceUrl(source: SkillSource): string {
82
+ const base = resolveAgentSkillBase();
83
+ const url = `${base}/${source.subpath}`;
84
+ if (source.ref === null) return url;
85
+ if (isLocalPath(base)) return url;
86
+ if (source.ref === 'cli') return `${url}#v${cliVersion}`;
87
+ return url;
88
+ }
22
89
 
23
90
  /**
24
- * The skill-install command, formatted for the project's detected
25
- * package manager. `npx`/`pnpm dlx`/`bunx` are interchangeable to the
26
- * user; we pick the variant that matches the rest of the install step
27
- * so a single project consistently uses one runner.
91
+ * The skill-install command for one source, formatted for the
92
+ * project's detected package manager. `npx`/`pnpm dlx`/`bunx` are
93
+ * interchangeable to the user; we pick the variant that matches the
94
+ * rest of the install step so a single project consistently uses one
95
+ * runner.
28
96
  *
29
97
  * `--all` auto-selects every skill in the cluster and every detected
30
98
  * agent runtime, skipping the multi-select prompts the `skills` CLI
31
99
  * shows by default. A non-interactive scaffold step cannot present
32
- * prompts, and the cluster is designed to be installed as a unit (the
33
- * router skill routes between the workflow-scoped siblings). Users who
34
- * want a narrower install run `npx skills add @prisma-next/skills`
35
- * themselves after `init` with the flags they want.
100
+ * prompts.
36
101
  *
37
102
  * Exported for unit tests so the per-PM dispatch can be asserted
38
103
  * without a live subprocess.
39
104
  */
40
- export function formatSkillInstallCommand(pm: PackageManager): string {
41
- const args = ['skills', 'add', AGENT_SKILL_PACKAGE, '--all'];
105
+ export function formatSkillInstallCommand(pm: PackageManager, source: SkillSource): string {
106
+ const args = ['skills', 'add', formatSkillSourceUrl(source), '--all'];
42
107
  switch (pm) {
43
108
  case 'pnpm':
44
109
  return `pnpm dlx ${args.join(' ')}`;
@@ -69,31 +134,37 @@ function commandToExec(command: string): {
69
134
  }
70
135
 
71
136
  /**
72
- * Runs the project-level skill install. Returns `{ ok: true, command }`
73
- * on success; throws a structured `errorInitSkillInstallFailed` on
74
- * failure. The throw is intentionally fatal project-level skill
75
- * install is unconditional (modulo `--no-skill`) and the user opted
76
- * into Prisma Next by running `init`. A silent skip would defeat the
77
- * onboarding-to-zero contract.
137
+ * Runs the project-level skill install for every source in
138
+ * `DEFAULT_AGENT_SKILL_SOURCES`, in order. Returns
139
+ * `{ ok: true, commands }` on success; throws a structured
140
+ * `errorInitSkillInstallFailed` on the first failure (subsequent
141
+ * sources are not attempted the user opted into Prisma Next by
142
+ * running `init` and a partial install would leave the project in an
143
+ * ambiguous state). The throw is intentionally fatal — project-level
144
+ * skill install is unconditional (modulo `--no-skill`).
78
145
  */
79
146
  export async function runProjectLevelSkillInstall(ctx: {
80
147
  readonly baseDir: string;
81
148
  readonly pm: PackageManager;
82
149
  readonly filesWritten: readonly string[];
83
- }): Promise<{ readonly ok: true; readonly command: string }> {
84
- const command = formatSkillInstallCommand(ctx.pm);
85
- const { file, args } = commandToExec(command);
86
- try {
87
- await exec(file, args, { cwd: ctx.baseDir });
88
- return { ok: true, command };
89
- } catch (err) {
90
- throw errorInitSkillInstallFailed({
91
- skillInstallCommand: command,
92
- filesWritten: ctx.filesWritten,
93
- cause:
94
- redactSecrets(readChildStderr(err)) || (err instanceof Error ? err.message : String(err)),
95
- });
150
+ }): Promise<{ readonly ok: true; readonly commands: readonly string[] }> {
151
+ const commands: string[] = [];
152
+ for (const source of DEFAULT_AGENT_SKILL_SOURCES) {
153
+ const command = formatSkillInstallCommand(ctx.pm, source);
154
+ const { file, args } = commandToExec(command);
155
+ try {
156
+ await exec(file, args, { cwd: ctx.baseDir });
157
+ commands.push(command);
158
+ } catch (err) {
159
+ throw errorInitSkillInstallFailed({
160
+ skillInstallCommand: command,
161
+ filesWritten: ctx.filesWritten,
162
+ cause:
163
+ redactSecrets(readChildStderr(err)) || (err instanceof Error ? err.message : String(err)),
164
+ });
165
+ }
96
166
  }
167
+ return { ok: true, commands };
97
168
  }
98
169
 
99
170
  function readChildStderr(err: unknown): string {
@@ -125,6 +196,6 @@ export function redactSecrets(stderr: string): string {
125
196
  /**
126
197
  * Hand-rolled skill stub path that init must not leave behind. Removed
127
198
  * on every init run so a project's `.agents/skills/prisma-next/` does
128
- * not shadow the published `@prisma-next/skills` package.
199
+ * not shadow the installed Prisma Next skill cluster.
129
200
  */
130
201
  export const LEGACY_SKILL_FILE = '.agents/skills/prisma-next/SKILL.md';
@@ -239,7 +239,7 @@ export function errorInitEmitFailed(options: {
239
239
 
240
240
  /**
241
241
  * The project-level agent-skill install (`npx skills add
242
- * @prisma-next/skills`) failed after a successful dependency
242
+ * prisma/prisma-next#v<version>`) failed after a successful dependency
243
243
  * install + emit. The project's scaffold remains on disk; the user
244
244
  * can either fix the underlying issue (network, registry, PATH) and
245
245
  * run the install command manually, or re-run `init --no-skill` to
@@ -253,7 +253,7 @@ export function errorInitSkillInstallFailed(options: {
253
253
  readonly filesWritten: readonly string[];
254
254
  readonly cause: string;
255
255
  }): CliStructuredError {
256
- return new CliStructuredError('5013', 'Failed to install @prisma-next/skills', {
256
+ return new CliStructuredError('5013', 'Failed to install Prisma Next skills', {
257
257
  domain: 'CLI',
258
258
  why: `\`${options.skillInstallCommand}\` exited with an error: ${options.cause}`,
259
259
  fix:
@@ -62,8 +62,8 @@ export const INIT_EXIT_INSTALL_FAILED = 4;
62
62
  export const INIT_EXIT_EMIT_FAILED = 5;
63
63
 
64
64
  /**
65
- * The project-level `@prisma-next/skills` install (`npx skills add
66
- * @prisma-next/skills`) failed after a successful dependency
65
+ * The project-level Prisma Next skills install (`npx skills add
66
+ * prisma/prisma-next#v<version>`) failed after a successful dependency
67
67
  * install + emit. The scaffolded project files remain on disk; the
68
68
  * user can fix the underlying issue (network, registry reachability,
69
69
  * `npx skills` not on PATH) and run the install manually, or re-run
@@ -89,7 +89,7 @@ export function createInitCommand(): Command {
89
89
  .option('--no-install', 'Skip dependency installation and contract emission')
90
90
  .option(
91
91
  '--no-skill',
92
- 'Skip the @prisma-next/skills install (air-gapped CI, restricted registries, etc.)',
92
+ 'Skip Prisma Next skills install (air-gapped CI, restricted registries, etc.)',
93
93
  )
94
94
  .action(async (options: InitCommandOptions) => {
95
95
  const { runInit } = await import('./init');
@@ -8,6 +8,7 @@ import { formatErrorJson, formatErrorOutput } from '../../utils/formatters/error
8
8
  import type { GlobalFlags } from '../../utils/global-flags';
9
9
  import { TerminalUI } from '../../utils/terminal-ui';
10
10
  import {
11
+ DEFAULT_AGENT_SKILL_SOURCES,
11
12
  formatSkillInstallCommand,
12
13
  LEGACY_SKILL_FILE,
13
14
  runProjectLevelSkillInstall,
@@ -182,7 +183,7 @@ export async function runInit(
182
183
  // and missing-on-disk-at-write-time is tolerated.
183
184
  const filesToDelete: string[] = inputs.reinit ? [...findStaleArtefacts(baseDir, schemaDir)] : [];
184
185
 
185
- // `init` delegates the skill to `npx skills add @prisma-next/skills`,
186
+ // `init` delegates the skill to `npx skills add prisma/prisma-next#v<version>`,
186
187
  // so a hand-rolled `.agents/skills/prisma-next/SKILL.md` in the project
187
188
  // would shadow the published package. Queue it for deletion on every
188
189
  // run (not gated on `--reinit`).
@@ -449,26 +450,31 @@ export async function runInit(
449
450
  // potentially fails. We skip the install when the user passed
450
451
  // `--no-install` for the same reason — no `node_modules` means the
451
452
  // workspace isn't ready to consume the skill yet anyway.
452
- const manualProjectSkillCommand = formatSkillInstallCommand(install.effectivePm);
453
+ const manualProjectSkillCommands = DEFAULT_AGENT_SKILL_SOURCES.map((source) =>
454
+ formatSkillInstallCommand(install.effectivePm, source),
455
+ );
456
+ const manualProjectSkillSummary = manualProjectSkillCommands.map((c) => `\`${c}\``).join(' && ');
453
457
  let skillRegistered = false;
454
458
  if (!inputs.installProjectSkill) {
455
459
  warnings.push(
456
- `Skipped @prisma-next/skills install (--no-skill). To install later, run \`${manualProjectSkillCommand}\` in this project.`,
460
+ `Skipped Prisma Next agent-skill install (--no-skill). To install the skills later, run: ${manualProjectSkillSummary}`,
457
461
  );
458
462
  } else if (install.skipped) {
459
463
  warnings.push(
460
- `Skipped @prisma-next/skills install because --no-install was passed. Once you run install manually, register the skill with \`${manualProjectSkillCommand}\`.`,
464
+ `Skipped Prisma Next agent-skill install because --no-install was passed. After you run install manually, install the skills with: ${manualProjectSkillSummary}`,
461
465
  );
462
466
  } else {
463
467
  const spinner = ui.spinner();
464
- spinner.start('Registering @prisma-next/skills with the agent runtime...');
468
+ spinner.start('Registering Prisma Next skills with the agent runtime...');
465
469
  try {
466
470
  const project = await runProjectLevelSkillInstall({
467
471
  baseDir,
468
472
  pm: install.effectivePm,
469
473
  filesWritten,
470
474
  });
471
- spinner.stop(`Registered @prisma-next/skills (project level) — ran \`${project.command}\``);
475
+ spinner.stop(
476
+ `Registered Prisma Next skills (project level) — ran ${project.commands.map((c) => `\`${c}\``).join(', ')}`,
477
+ );
472
478
  skillRegistered = true;
473
479
  } catch (error) {
474
480
  spinner.stop('Agent-skill install failed');
@@ -69,7 +69,7 @@ export interface ResolvedInitInputs {
69
69
  */
70
70
  readonly removePreviousFacade: string | null;
71
71
  /**
72
- * Whether to run `npx skills add @prisma-next/skills` at the
72
+ * Whether to run `npx skills add prisma/prisma-next#v<version>` at the
73
73
  * project level after install + emit. True by default; `--no-skill`
74
74
  * sets it to `false`. The skill is always project-level (never
75
75
  * user-level / global) so its version stays locked to the project's
@@ -121,7 +121,7 @@ export function buildNextSteps(options: {
121
121
  readonly emitCommand: string;
122
122
  readonly schemaPath: string;
123
123
  /**
124
- * Whether the project-level `@prisma-next/skills` install actually ran
124
+ * Whether the project-level Prisma Next skills install actually ran
125
125
  * and succeeded during this `init`. When false (the user passed
126
126
  * `--no-skill` or `--no-install`, so the install was skipped), the
127
127
  * "registered with your agent runtime" step is omitted — the skip is
@@ -145,7 +145,7 @@ export function buildNextSteps(options: {
145
145
  push('Open prisma-next.md for a quick reference on how to write your first typed query.');
146
146
  if (options.skillRegistered) {
147
147
  push(
148
- '@prisma-next/skills is registered with your agent runtime — open the project in your IDE and ask the agent to add a model, run a query, or plan a migration.',
148
+ 'Prisma Next skills are registered with your agent runtime — open the project in your IDE and ask the agent to add a model, run a query, or plan a migration.',
149
149
  );
150
150
  }
151
151
  return steps;