prisma-next 0.10.0-dev.2 → 0.10.0-dev.21
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/cli.mjs +150 -10
- package/dist/cli.mjs.map +1 -1
- package/dist/{command-helpers-D3vL5yi8.mjs → command-helpers-Dvgul7UA.mjs} +3 -3
- package/dist/command-helpers-Dvgul7UA.mjs.map +1 -0
- package/dist/commands/contract-emit.mjs +1 -1
- package/dist/commands/contract-infer.mjs +1 -1
- package/dist/commands/db-init.mjs +4 -4
- package/dist/commands/db-schema.mjs +4 -4
- package/dist/commands/db-sign.mjs +3 -3
- package/dist/commands/db-update.mjs +4 -4
- package/dist/commands/db-verify.mjs +1 -1
- package/dist/commands/migrate.mjs +3 -3
- package/dist/commands/migration-check.mjs +1 -1
- package/dist/commands/migration-graph.mjs +2 -2
- package/dist/commands/migration-list.mjs +2 -2
- package/dist/commands/migration-log.mjs +2 -2
- package/dist/commands/migration-new.mjs +2 -2
- package/dist/commands/migration-plan.mjs +1 -1
- package/dist/commands/migration-show.mjs +3 -3
- package/dist/commands/migration-status.mjs +3 -3
- package/dist/commands/ref.mjs +2 -2
- package/dist/{contract-emit-C3STUIBg.mjs → contract-emit-BDBzHlaC.mjs} +4 -4
- package/dist/{contract-emit-C3STUIBg.mjs.map → contract-emit-BDBzHlaC.mjs.map} +1 -1
- package/dist/{contract-infer-Cnj8G1E2.mjs → contract-infer-Dm8pBZMR.mjs} +4 -4
- package/dist/{contract-infer-Cnj8G1E2.mjs.map → contract-infer-Dm8pBZMR.mjs.map} +1 -1
- package/dist/{db-verify-D7cyH_zz.mjs → db-verify-CW8DR5Ei.mjs} +4 -4
- package/dist/{db-verify-D7cyH_zz.mjs.map → db-verify-CW8DR5Ei.mjs.map} +1 -1
- package/dist/{errors-Cw6kyTyV.mjs → errors-BYAXmyRJ.mjs} +2 -2
- package/dist/{errors-Cw6kyTyV.mjs.map → errors-BYAXmyRJ.mjs.map} +1 -1
- package/dist/exports/index.mjs +2 -2
- package/dist/global-flags-DGmw6Kqg.d.mts.map +1 -1
- package/dist/{init-DBRWZlFU.mjs → init-n7JaaCgD.mjs} +447 -367
- package/dist/init-n7JaaCgD.mjs.map +1 -0
- package/dist/{inspect-live-schema-CWLK_lgs.mjs → inspect-live-schema-iETRZ_59.mjs} +2 -2
- package/dist/{inspect-live-schema-CWLK_lgs.mjs.map → inspect-live-schema-iETRZ_59.mjs.map} +1 -1
- package/dist/is-ci-YyvQBBke.mjs +44 -0
- package/dist/is-ci-YyvQBBke.mjs.map +1 -0
- package/dist/{migration-command-scaffold-CmXXC1UZ.mjs → migration-command-scaffold-BlgVj_Pn.mjs} +2 -2
- package/dist/{migration-command-scaffold-CmXXC1UZ.mjs.map → migration-command-scaffold-BlgVj_Pn.mjs.map} +1 -1
- package/dist/{migration-plan-CHyUlBV0.mjs → migration-plan-BSzcWsvm.mjs} +3 -3
- package/dist/{migration-plan-CHyUlBV0.mjs.map → migration-plan-BSzcWsvm.mjs.map} +1 -1
- package/dist/{migrations-DyUf5lTt.mjs → migrations-CgANWI0w.mjs} +2 -2
- package/dist/{migrations-DyUf5lTt.mjs.map → migrations-CgANWI0w.mjs.map} +1 -1
- package/dist/output-B60Gw5fu.mjs.map +1 -1
- package/dist/{result-handler-Bm_6dDYg.mjs → result-handler-CG3vVoKf.mjs} +2 -2
- package/dist/{result-handler-Bm_6dDYg.mjs.map → result-handler-CG3vVoKf.mjs.map} +1 -1
- package/dist/{verify-D7ypCCe6.mjs → verify-nlzO0uIY.mjs} +2 -2
- package/dist/{verify-D7ypCCe6.mjs.map → verify-nlzO0uIY.mjs.map} +1 -1
- package/package.json +12 -10
- package/dist/command-helpers-D3vL5yi8.mjs.map +0 -1
- package/dist/helpers-eqdN8tH6.mjs +0 -25
- package/dist/helpers-eqdN8tH6.mjs.map +0 -1
- package/dist/init-DBRWZlFU.mjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as CliStructuredError } from "./cli-errors-CF60g2cG.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { t as isCI } from "./is-ci-YyvQBBke.mjs";
|
|
3
|
+
import { n as formatErrorOutput, t as formatErrorJson } from "./errors-BYAXmyRJ.mjs";
|
|
3
4
|
import { t as TerminalUI } from "./terminal-ui-XtOQsqe9.mjs";
|
|
4
5
|
import { t as version } from "./cli.mjs";
|
|
5
6
|
import { i as renderInitOutro, n as buildNextSteps, r as formatInitJson, t as InitOutputSchema } from "./output-B60Gw5fu.mjs";
|
|
@@ -7,10 +8,164 @@ import { createRequire } from "node:module";
|
|
|
7
8
|
import { basename, dirname, extname, isAbsolute, join, normalize } from "pathe";
|
|
8
9
|
import * as clack from "@clack/prompts";
|
|
9
10
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { readUserConfig, resolveGating, writeUserConfig } from "@prisma-next/cli-telemetry";
|
|
10
12
|
import { execFile } from "node:child_process";
|
|
11
13
|
import { promisify } from "node:util";
|
|
12
14
|
import { detect, getUserAgent } from "package-manager-detector/detect";
|
|
13
15
|
import { applyEdits, modify, parse, printParseErrorCode } from "jsonc-parser";
|
|
16
|
+
//#region src/commands/init/detect-package-manager.ts
|
|
17
|
+
const KNOWN = new Set([
|
|
18
|
+
"pnpm",
|
|
19
|
+
"npm",
|
|
20
|
+
"yarn",
|
|
21
|
+
"bun",
|
|
22
|
+
"deno"
|
|
23
|
+
]);
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the package manager `init` should drive for `add` / `install`
|
|
26
|
+
* commands. Tries, in order:
|
|
27
|
+
*
|
|
28
|
+
* 1. **`detect()`** — walks up from `cwd` looking for a lockfile, the
|
|
29
|
+
* `packageManager` field, the `devEngines.packageManager` field, or
|
|
30
|
+
* install metadata. This is the right answer whenever the user is
|
|
31
|
+
* anywhere inside an existing project, including a deep workspace
|
|
32
|
+
* subdirectory.
|
|
33
|
+
*
|
|
34
|
+
* 2. **`getUserAgent()`** — parses `npm_config_user_agent`, the env var
|
|
35
|
+
* every PM sets when it spawns a script. This catches the
|
|
36
|
+
* bare-directory case where there's no project to walk up to but the
|
|
37
|
+
* user invoked us via `pnpm dlx prisma-next init` / `bunx
|
|
38
|
+
* prisma-next init` / `yarn dlx …`. Same signal used by every
|
|
39
|
+
* `create-*` tool in the ecosystem (`create-vite`, `create-next-app`,
|
|
40
|
+
* `create-astro`, `@antfu/ni`, …).
|
|
41
|
+
*
|
|
42
|
+
* 3. **`npm`** — final fallback. Always present alongside Node.
|
|
43
|
+
*/
|
|
44
|
+
async function detectPackageManager(cwd) {
|
|
45
|
+
const detected = await detect({ cwd });
|
|
46
|
+
if (detected && KNOWN.has(detected.name)) return detected.name;
|
|
47
|
+
const userAgent = getUserAgent();
|
|
48
|
+
if (userAgent !== null && KNOWN.has(userAgent)) return userAgent;
|
|
49
|
+
return "npm";
|
|
50
|
+
}
|
|
51
|
+
function hasProjectManifest(cwd) {
|
|
52
|
+
return existsSync(join(cwd, "package.json")) || existsSync(join(cwd, "deno.json")) || existsSync(join(cwd, "deno.jsonc"));
|
|
53
|
+
}
|
|
54
|
+
function formatRunCommand(pm, bin, args) {
|
|
55
|
+
if (pm === "npm") return `npx ${bin} ${args}`;
|
|
56
|
+
if (pm === "deno") return `deno run npm:${bin} ${args}`;
|
|
57
|
+
return `${pm} ${bin} ${args}`;
|
|
58
|
+
}
|
|
59
|
+
function formatAddArgs(pm, packages) {
|
|
60
|
+
if (pm === "deno") return ["add", ...packages.map((p) => `npm:${p}`)];
|
|
61
|
+
return ["add", ...packages];
|
|
62
|
+
}
|
|
63
|
+
function formatAddDevArgs(pm, packages) {
|
|
64
|
+
if (pm === "deno") return [
|
|
65
|
+
"add",
|
|
66
|
+
"--dev",
|
|
67
|
+
...packages.map((p) => `npm:${p}`)
|
|
68
|
+
];
|
|
69
|
+
return [
|
|
70
|
+
"add",
|
|
71
|
+
"-D",
|
|
72
|
+
...packages
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/commands/init/detect-pnpm-catalog.ts
|
|
77
|
+
/**
|
|
78
|
+
* Walks up from `baseDir` looking for `pnpm-workspace.yaml`, then scans
|
|
79
|
+
* its top-level `catalog:` block for entries that match any of `packages`.
|
|
80
|
+
*
|
|
81
|
+
* Implements FR7.3 / Spec Decision 8 (honour-and-warn): when `init` runs
|
|
82
|
+
* inside a pnpm workspace whose catalog overrides one of the packages it
|
|
83
|
+
* installs, surface a structured warning so the user knows the catalog
|
|
84
|
+
* version (not the published `latest`) is what ended up in their
|
|
85
|
+
* `node_modules`. pnpm itself does this silently; the warning closes the
|
|
86
|
+
* "looks fine, must be wrong version six months later" gap.
|
|
87
|
+
*
|
|
88
|
+
* Notes / scope:
|
|
89
|
+
*
|
|
90
|
+
* - We only inspect the unnamed top-level `catalog:` block. pnpm also
|
|
91
|
+
* supports `catalogs:` (plural — *named* catalogs referenced via
|
|
92
|
+
* `catalog:foo` specifiers); those don't apply to a vanilla
|
|
93
|
+
* `pnpm add prisma-next` invocation, so we skip them.
|
|
94
|
+
* - We don't validate YAML syntax exhaustively. The file format pnpm
|
|
95
|
+
* ships is line-oriented and well-known; a minimal regex is more
|
|
96
|
+
* robust than depending on a YAML parser for one warning.
|
|
97
|
+
* - We don't compare against the registry's `latest` — pnpm uses the
|
|
98
|
+
* catalog version regardless, so the warning fires whenever a match
|
|
99
|
+
* exists. The user-facing copy explains how to opt out.
|
|
100
|
+
*/
|
|
101
|
+
function detectPnpmCatalogOverrides(baseDir, packages) {
|
|
102
|
+
const workspaceFile = findNearestPnpmWorkspaceFile(baseDir);
|
|
103
|
+
if (workspaceFile === null) return null;
|
|
104
|
+
const catalog = extractCatalogBlock(readFileSync(workspaceFile, "utf-8"));
|
|
105
|
+
if (catalog === null) return {
|
|
106
|
+
workspaceFile,
|
|
107
|
+
entries: []
|
|
108
|
+
};
|
|
109
|
+
const wanted = new Set(packages);
|
|
110
|
+
const entries = [];
|
|
111
|
+
for (const [name, version] of catalog) if (wanted.has(name)) entries.push({
|
|
112
|
+
name,
|
|
113
|
+
version
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
workspaceFile,
|
|
117
|
+
entries
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function findNearestPnpmWorkspaceFile(baseDir) {
|
|
121
|
+
let dir = baseDir;
|
|
122
|
+
let prev = "";
|
|
123
|
+
while (dir !== prev) {
|
|
124
|
+
const candidate = join(dir, "pnpm-workspace.yaml");
|
|
125
|
+
if (existsSync(candidate)) return candidate;
|
|
126
|
+
prev = dir;
|
|
127
|
+
dir = dirname(dir);
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns the entries inside the top-level `catalog:` block as `[name, version]`
|
|
133
|
+
* pairs in document order, or `null` when no `catalog:` block exists.
|
|
134
|
+
*
|
|
135
|
+
* The parser is intentionally minimal: it reads line-by-line, locates the
|
|
136
|
+
* top-level `catalog:` line (no leading whitespace), then collects every
|
|
137
|
+
* subsequent indented line of the form `<key>: <value>` until the next
|
|
138
|
+
* top-level key (or end of file). Quotes around `<key>` and `<value>`
|
|
139
|
+
* are stripped; comments (`#…`) are ignored.
|
|
140
|
+
*/
|
|
141
|
+
function extractCatalogBlock(contents) {
|
|
142
|
+
const lines = contents.split(/\r?\n/);
|
|
143
|
+
const startIdx = lines.findIndex((line) => /^catalog\s*:\s*$/.test(line));
|
|
144
|
+
if (startIdx === -1) return null;
|
|
145
|
+
const entries = [];
|
|
146
|
+
for (let i = startIdx + 1; i < lines.length; i++) {
|
|
147
|
+
const raw = lines[i] ?? "";
|
|
148
|
+
if (raw.trim() === "" || /^\s*#/.test(raw)) continue;
|
|
149
|
+
if (!/^\s/.test(raw)) break;
|
|
150
|
+
const match = raw.match(/^\s+(?:'([^']+)'|"([^"]+)"|([^:\s'"]+))\s*:\s*(.*?)\s*(?:#.*)?$/);
|
|
151
|
+
if (!match) continue;
|
|
152
|
+
const name = match[1] ?? match[2] ?? match[3];
|
|
153
|
+
if (name === void 0) continue;
|
|
154
|
+
const version = stripQuotes((match[4] ?? "").trim());
|
|
155
|
+
if (version === "") continue;
|
|
156
|
+
entries.push([name, version]);
|
|
157
|
+
}
|
|
158
|
+
return entries;
|
|
159
|
+
}
|
|
160
|
+
function stripQuotes(value) {
|
|
161
|
+
if (value.length >= 2) {
|
|
162
|
+
const first = value[0];
|
|
163
|
+
const last = value[value.length - 1];
|
|
164
|
+
if (first === "\"" && last === "\"" || first === "'" && last === "'") return value.slice(1, -1);
|
|
165
|
+
}
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
14
169
|
//#region src/commands/init/errors.ts
|
|
15
170
|
/**
|
|
16
171
|
* Re-init in non-interactive mode without `--force`. Distinct from the
|
|
@@ -70,6 +225,26 @@ function errorInitInvalidFlagValue(options) {
|
|
|
70
225
|
});
|
|
71
226
|
}
|
|
72
227
|
/**
|
|
228
|
+
* `--authoring` and `--schema-path` disagree on file extension (e.g. PSL
|
|
229
|
+
* authoring with a `.ts` path). Surfaces before any scaffold files are
|
|
230
|
+
* written so the project tree stays untouched.
|
|
231
|
+
*/
|
|
232
|
+
function errorInitAuthoringSchemaPathMismatch(options) {
|
|
233
|
+
const expectedAuthoring = options.expectedExtension === ".ts" ? "typescript" : "psl";
|
|
234
|
+
return new CliStructuredError("5014", "Authoring and schema path do not match", {
|
|
235
|
+
domain: "CLI",
|
|
236
|
+
why: `\`--authoring ${options.authoring}\` requires a schema file ending in ${options.expectedExtension}, but \`--schema-path ${options.schemaPath}\` ends in ${options.actualExtension}.`,
|
|
237
|
+
fix: `Use a matching pair, for example \`--authoring ${expectedAuthoring} --schema-path <path>${options.expectedExtension}\`, or change \`--authoring\` to match the path you supplied. You can also omit \`--schema-path\` to use the default for the chosen authoring.`,
|
|
238
|
+
docsUrl: "https://prisma-next.dev/docs/cli/init",
|
|
239
|
+
meta: {
|
|
240
|
+
authoring: options.authoring,
|
|
241
|
+
schemaPath: options.schemaPath,
|
|
242
|
+
actualExtension: options.actualExtension,
|
|
243
|
+
expectedExtension: options.expectedExtension
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
73
248
|
* The user cancelled an interactive prompt (Ctrl-C, escape, declined a
|
|
74
249
|
* selection). Distinct from `errorInitReinitNeedsForce` because that path
|
|
75
250
|
* applies to non-interactive mode where the user was never given the
|
|
@@ -208,365 +383,35 @@ function errorInitEmitFailed(options) {
|
|
|
208
383
|
fix: `Inspect your contract file, fix the underlying issue, then re-run \`${options.emitCommand}\`. Pass \`-v\` for the full error envelope.`,
|
|
209
384
|
docsUrl: "https://prisma-next.dev/docs/cli/contract-emit",
|
|
210
385
|
meta: {
|
|
211
|
-
filesWritten: options.filesWritten,
|
|
212
|
-
cause: options.cause
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* The project-level agent-skill install (`npx skills add
|
|
218
|
-
* prisma/prisma-next#v<version>`) failed after a successful dependency
|
|
219
|
-
* install + emit. The project's scaffold remains on disk; the user
|
|
220
|
-
* can either fix the underlying issue (network, registry, PATH) and
|
|
221
|
-
* run the install command manually, or re-run `init --no-skill` to
|
|
222
|
-
* proceed without the skill.
|
|
223
|
-
*
|
|
224
|
-
* Non-rolling-back, matching the existing install/emit failure
|
|
225
|
-
* semantics. Maps to exit code `6 = SKILL_INSTALL_FAILED`.
|
|
226
|
-
*/
|
|
227
|
-
function errorInitSkillInstallFailed(options) {
|
|
228
|
-
return new CliStructuredError("5013", "Failed to install Prisma Next skills", {
|
|
229
|
-
domain: "CLI",
|
|
230
|
-
why: `\`${options.skillInstallCommand}\` exited with an error: ${options.cause}`,
|
|
231
|
-
fix: `Either:
|
|
232
|
-
- Re-run \`prisma-next init --no-skill${options.filesWritten.length > 0 ? " --force" : ""}\` to skip the skill install for this run, or\n - Fix the underlying issue (network, npm registry, \`npx skills\` on PATH) and install manually:\n ${options.skillInstallCommand}`,
|
|
233
|
-
docsUrl: "https://prisma-next.dev/docs/cli/init#agent-skill",
|
|
234
|
-
meta: {
|
|
235
|
-
filesWritten: options.filesWritten,
|
|
236
|
-
skillInstallCommand: options.skillInstallCommand,
|
|
237
|
-
cause: options.cause
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/commands/init/agent-skill-install.ts
|
|
243
|
-
const exec = promisify(execFile);
|
|
244
|
-
/**
|
|
245
|
-
* Default base for the GitHub-URL form `<owner>/<repo>` consumed by
|
|
246
|
-
* upstream `skills add`. Each `SkillSource` joins this base with its
|
|
247
|
-
* own subpath (and optional `#ref` for version-pinned clusters).
|
|
248
|
-
*/
|
|
249
|
-
const DEFAULT_AGENT_SKILL_BASE = "prisma/prisma-next";
|
|
250
|
-
const DEFAULT_AGENT_SKILL_SOURCES = [
|
|
251
|
-
{
|
|
252
|
-
subpath: "skills",
|
|
253
|
-
ref: "cli",
|
|
254
|
-
description: "usage skills (version-locked to installed Prisma Next)"
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
subpath: "skills/upgrade",
|
|
258
|
-
ref: null,
|
|
259
|
-
description: "upgrade skill (always tracks `main`)"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
subpath: "skills/extension-author",
|
|
263
|
-
ref: null,
|
|
264
|
-
description: "extension-author skill (always tracks `main`)"
|
|
265
|
-
}
|
|
266
|
-
];
|
|
267
|
-
/**
|
|
268
|
-
* Test-only escape hatch for pinning the install base to a local
|
|
269
|
-
* checkout. Production runs leave this unset, so installs always use
|
|
270
|
-
* `DEFAULT_AGENT_SKILL_BASE`.
|
|
271
|
-
*
|
|
272
|
-
* When set to an absolute filesystem path (typical for tests), the
|
|
273
|
-
* `#ref` fragment is dropped — local-path mode in upstream's CLI does
|
|
274
|
-
* not accept refs, and the local clone has whatever content the test
|
|
275
|
-
* checked into it anyway. When set to anything else (e.g. a fork name
|
|
276
|
-
* `myuser/prisma-next`), the ref policy is preserved.
|
|
277
|
-
*/
|
|
278
|
-
function resolveAgentSkillBase() {
|
|
279
|
-
const override = process.env["PRISMA_NEXT_SKILLS_BASE"]?.trim();
|
|
280
|
-
return override && override.length > 0 ? override : DEFAULT_AGENT_SKILL_BASE;
|
|
281
|
-
}
|
|
282
|
-
function isLocalPath(base) {
|
|
283
|
-
return base.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(base);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Build the `<base>/<subpath>[#ref]` URL the `skills` CLI will
|
|
287
|
-
* resolve. Exported for unit tests so the per-source format can be
|
|
288
|
-
* asserted without going through the full install loop.
|
|
289
|
-
*/
|
|
290
|
-
function formatSkillSourceUrl(source) {
|
|
291
|
-
const base = resolveAgentSkillBase();
|
|
292
|
-
const url = `${base}/${source.subpath}`;
|
|
293
|
-
if (source.ref === null) return url;
|
|
294
|
-
if (isLocalPath(base)) return url;
|
|
295
|
-
if (source.ref === "cli") return `${url}#v${version}`;
|
|
296
|
-
return url;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* The skill-install command for one source, formatted for the
|
|
300
|
-
* project's detected package manager. `npx`/`pnpm dlx`/`bunx` are
|
|
301
|
-
* interchangeable to the user; we pick the variant that matches the
|
|
302
|
-
* rest of the install step so a single project consistently uses one
|
|
303
|
-
* runner.
|
|
304
|
-
*
|
|
305
|
-
* `--all` auto-selects every skill in the cluster and every detected
|
|
306
|
-
* agent runtime, skipping the multi-select prompts the `skills` CLI
|
|
307
|
-
* shows by default. A non-interactive scaffold step cannot present
|
|
308
|
-
* prompts.
|
|
309
|
-
*
|
|
310
|
-
* Exported for unit tests so the per-PM dispatch can be asserted
|
|
311
|
-
* without a live subprocess.
|
|
312
|
-
*/
|
|
313
|
-
function formatSkillInstallCommand(pm, source) {
|
|
314
|
-
return formatPackageManagerCommand(pm, [
|
|
315
|
-
"skills@latest",
|
|
316
|
-
"add",
|
|
317
|
-
formatSkillSourceUrl(source),
|
|
318
|
-
"--all"
|
|
319
|
-
]);
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* `skills add --all` should cover Claude Code, but upstream currently skips
|
|
323
|
-
* project-local Claude symlinks when `.claude/` does not already exist. Run
|
|
324
|
-
* the explicit Claude Code install as well so fresh projects get
|
|
325
|
-
* `.claude/skills` without asking users to create that folder first.
|
|
326
|
-
*/
|
|
327
|
-
function formatClaudeSkillInstallCommand(pm, source) {
|
|
328
|
-
return formatPackageManagerCommand(pm, [
|
|
329
|
-
"skills@latest",
|
|
330
|
-
"add",
|
|
331
|
-
formatSkillSourceUrl(source),
|
|
332
|
-
"--agent",
|
|
333
|
-
"claude-code",
|
|
334
|
-
"--skill",
|
|
335
|
-
"'*'",
|
|
336
|
-
"-y"
|
|
337
|
-
]);
|
|
338
|
-
}
|
|
339
|
-
function formatPackageManagerCommand(pm, args) {
|
|
340
|
-
switch (pm) {
|
|
341
|
-
case "pnpm": return `pnpm dlx ${args.join(" ")}`;
|
|
342
|
-
case "yarn": return `yarn dlx ${args.join(" ")}`;
|
|
343
|
-
case "bun": return `bunx ${args.join(" ")}`;
|
|
344
|
-
case "deno": return `deno run -A npm:${args.join(" ")}`;
|
|
345
|
-
case "npm": return `npx ${args.join(" ")}`;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Parse the project-pm-formatted command into an exec call. The
|
|
350
|
-
* format-then-parse split keeps the user-facing command string the same
|
|
351
|
-
* as the surface the structured error advertises, so a user who copies
|
|
352
|
-
* the error's `fix` line gets the same invocation that init just
|
|
353
|
-
* attempted. Single quotes are preserved in the display form so `*` is
|
|
354
|
-
* safe to copy into a shell, then stripped before `execFile`.
|
|
355
|
-
*/
|
|
356
|
-
function commandToExec(command) {
|
|
357
|
-
const tokens = (command.match(/'[^']*'|\S+/g) ?? []).map((token) => token.startsWith("'") && token.endsWith("'") ? token.slice(1, -1) : token);
|
|
358
|
-
return {
|
|
359
|
-
file: tokens[0] ?? "npx",
|
|
360
|
-
args: tokens.slice(1)
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Runs the project-level skill install for every source in
|
|
365
|
-
* `DEFAULT_AGENT_SKILL_SOURCES`, in order. Returns
|
|
366
|
-
* `{ ok: true, commands }` on success; throws a structured
|
|
367
|
-
* `errorInitSkillInstallFailed` on the first failure (subsequent
|
|
368
|
-
* sources are not attempted — the user opted into Prisma Next by
|
|
369
|
-
* running `init` and a partial install would leave the project in an
|
|
370
|
-
* ambiguous state). The throw is intentionally fatal — project-level
|
|
371
|
-
* skill install is unconditional (modulo `--no-skill`).
|
|
372
|
-
*/
|
|
373
|
-
async function runProjectLevelSkillInstall(ctx) {
|
|
374
|
-
const commands = [];
|
|
375
|
-
const installCommands = DEFAULT_AGENT_SKILL_SOURCES.flatMap((source) => [formatSkillInstallCommand(ctx.pm, source), formatClaudeSkillInstallCommand(ctx.pm, source)]);
|
|
376
|
-
for (const command of installCommands) {
|
|
377
|
-
const { file, args } = commandToExec(command);
|
|
378
|
-
try {
|
|
379
|
-
await exec(file, args, { cwd: ctx.baseDir });
|
|
380
|
-
commands.push(command);
|
|
381
|
-
} catch (err) {
|
|
382
|
-
throw errorInitSkillInstallFailed({
|
|
383
|
-
skillInstallCommand: command,
|
|
384
|
-
filesWritten: ctx.filesWritten,
|
|
385
|
-
cause: redactSecrets$1(readChildStderr$1(err)) || (err instanceof Error ? err.message : String(err))
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
return {
|
|
390
|
-
ok: true,
|
|
391
|
-
commands
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
function readChildStderr$1(err) {
|
|
395
|
-
if (err instanceof Error && "stderr" in err) return String(err.stderr ?? "");
|
|
396
|
-
return "";
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Strips credentials from a `scheme://user:pass@host/...` URL anywhere
|
|
400
|
-
* in `stderr`. Package-manager stderr regularly contains credentialed
|
|
401
|
-
* registry URLs (private npm registries, GitHub Packages tokens), and
|
|
402
|
-
* those bubble into the structured `errorInitSkillInstallFailed`
|
|
403
|
-
* envelope, which ends up in logs and CI output. Redact at the
|
|
404
|
-
* boundary so we never re-emit a secret.
|
|
405
|
-
*
|
|
406
|
-
* Exported for unit tests.
|
|
407
|
-
*/
|
|
408
|
-
function redactSecrets$1(stderr) {
|
|
409
|
-
if (!stderr) return stderr;
|
|
410
|
-
return stderr.replace(/([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)([^/@\s]+)@/g, "$1***@");
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Hand-rolled skill stub path that init must not leave behind. Removed
|
|
414
|
-
* on every init run so a project's `.agents/skills/prisma-next/` does
|
|
415
|
-
* not shadow the installed Prisma Next skill cluster.
|
|
416
|
-
*/
|
|
417
|
-
const LEGACY_SKILL_FILE = ".agents/skills/prisma-next/SKILL.md";
|
|
418
|
-
//#endregion
|
|
419
|
-
//#region src/commands/init/detect-package-manager.ts
|
|
420
|
-
const KNOWN = new Set([
|
|
421
|
-
"pnpm",
|
|
422
|
-
"npm",
|
|
423
|
-
"yarn",
|
|
424
|
-
"bun",
|
|
425
|
-
"deno"
|
|
426
|
-
]);
|
|
427
|
-
/**
|
|
428
|
-
* Resolves the package manager `init` should drive for `add` / `install`
|
|
429
|
-
* commands. Tries, in order:
|
|
430
|
-
*
|
|
431
|
-
* 1. **`detect()`** — walks up from `cwd` looking for a lockfile, the
|
|
432
|
-
* `packageManager` field, the `devEngines.packageManager` field, or
|
|
433
|
-
* install metadata. This is the right answer whenever the user is
|
|
434
|
-
* anywhere inside an existing project, including a deep workspace
|
|
435
|
-
* subdirectory.
|
|
436
|
-
*
|
|
437
|
-
* 2. **`getUserAgent()`** — parses `npm_config_user_agent`, the env var
|
|
438
|
-
* every PM sets when it spawns a script. This catches the
|
|
439
|
-
* bare-directory case where there's no project to walk up to but the
|
|
440
|
-
* user invoked us via `pnpm dlx prisma-next init` / `bunx
|
|
441
|
-
* prisma-next init` / `yarn dlx …`. Same signal used by every
|
|
442
|
-
* `create-*` tool in the ecosystem (`create-vite`, `create-next-app`,
|
|
443
|
-
* `create-astro`, `@antfu/ni`, …).
|
|
444
|
-
*
|
|
445
|
-
* 3. **`npm`** — final fallback. Always present alongside Node.
|
|
446
|
-
*/
|
|
447
|
-
async function detectPackageManager(cwd) {
|
|
448
|
-
const detected = await detect({ cwd });
|
|
449
|
-
if (detected && KNOWN.has(detected.name)) return detected.name;
|
|
450
|
-
const userAgent = getUserAgent();
|
|
451
|
-
if (userAgent !== null && KNOWN.has(userAgent)) return userAgent;
|
|
452
|
-
return "npm";
|
|
453
|
-
}
|
|
454
|
-
function hasProjectManifest(cwd) {
|
|
455
|
-
return existsSync(join(cwd, "package.json")) || existsSync(join(cwd, "deno.json")) || existsSync(join(cwd, "deno.jsonc"));
|
|
456
|
-
}
|
|
457
|
-
function formatRunCommand(pm, bin, args) {
|
|
458
|
-
if (pm === "npm") return `npx ${bin} ${args}`;
|
|
459
|
-
if (pm === "deno") return `deno run npm:${bin} ${args}`;
|
|
460
|
-
return `${pm} ${bin} ${args}`;
|
|
461
|
-
}
|
|
462
|
-
function formatAddArgs(pm, packages) {
|
|
463
|
-
if (pm === "deno") return ["add", ...packages.map((p) => `npm:${p}`)];
|
|
464
|
-
return ["add", ...packages];
|
|
465
|
-
}
|
|
466
|
-
function formatAddDevArgs(pm, packages) {
|
|
467
|
-
if (pm === "deno") return [
|
|
468
|
-
"add",
|
|
469
|
-
"--dev",
|
|
470
|
-
...packages.map((p) => `npm:${p}`)
|
|
471
|
-
];
|
|
472
|
-
return [
|
|
473
|
-
"add",
|
|
474
|
-
"-D",
|
|
475
|
-
...packages
|
|
476
|
-
];
|
|
477
|
-
}
|
|
478
|
-
//#endregion
|
|
479
|
-
//#region src/commands/init/detect-pnpm-catalog.ts
|
|
480
|
-
/**
|
|
481
|
-
* Walks up from `baseDir` looking for `pnpm-workspace.yaml`, then scans
|
|
482
|
-
* its top-level `catalog:` block for entries that match any of `packages`.
|
|
483
|
-
*
|
|
484
|
-
* Implements FR7.3 / Spec Decision 8 (honour-and-warn): when `init` runs
|
|
485
|
-
* inside a pnpm workspace whose catalog overrides one of the packages it
|
|
486
|
-
* installs, surface a structured warning so the user knows the catalog
|
|
487
|
-
* version (not the published `latest`) is what ended up in their
|
|
488
|
-
* `node_modules`. pnpm itself does this silently; the warning closes the
|
|
489
|
-
* "looks fine, must be wrong version six months later" gap.
|
|
490
|
-
*
|
|
491
|
-
* Notes / scope:
|
|
492
|
-
*
|
|
493
|
-
* - We only inspect the unnamed top-level `catalog:` block. pnpm also
|
|
494
|
-
* supports `catalogs:` (plural — *named* catalogs referenced via
|
|
495
|
-
* `catalog:foo` specifiers); those don't apply to a vanilla
|
|
496
|
-
* `pnpm add prisma-next` invocation, so we skip them.
|
|
497
|
-
* - We don't validate YAML syntax exhaustively. The file format pnpm
|
|
498
|
-
* ships is line-oriented and well-known; a minimal regex is more
|
|
499
|
-
* robust than depending on a YAML parser for one warning.
|
|
500
|
-
* - We don't compare against the registry's `latest` — pnpm uses the
|
|
501
|
-
* catalog version regardless, so the warning fires whenever a match
|
|
502
|
-
* exists. The user-facing copy explains how to opt out.
|
|
503
|
-
*/
|
|
504
|
-
function detectPnpmCatalogOverrides(baseDir, packages) {
|
|
505
|
-
const workspaceFile = findNearestPnpmWorkspaceFile(baseDir);
|
|
506
|
-
if (workspaceFile === null) return null;
|
|
507
|
-
const catalog = extractCatalogBlock(readFileSync(workspaceFile, "utf-8"));
|
|
508
|
-
if (catalog === null) return {
|
|
509
|
-
workspaceFile,
|
|
510
|
-
entries: []
|
|
511
|
-
};
|
|
512
|
-
const wanted = new Set(packages);
|
|
513
|
-
const entries = [];
|
|
514
|
-
for (const [name, version] of catalog) if (wanted.has(name)) entries.push({
|
|
515
|
-
name,
|
|
516
|
-
version
|
|
386
|
+
filesWritten: options.filesWritten,
|
|
387
|
+
cause: options.cause
|
|
388
|
+
}
|
|
517
389
|
});
|
|
518
|
-
return {
|
|
519
|
-
workspaceFile,
|
|
520
|
-
entries
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
function findNearestPnpmWorkspaceFile(baseDir) {
|
|
524
|
-
let dir = baseDir;
|
|
525
|
-
let prev = "";
|
|
526
|
-
while (dir !== prev) {
|
|
527
|
-
const candidate = join(dir, "pnpm-workspace.yaml");
|
|
528
|
-
if (existsSync(candidate)) return candidate;
|
|
529
|
-
prev = dir;
|
|
530
|
-
dir = dirname(dir);
|
|
531
|
-
}
|
|
532
|
-
return null;
|
|
533
390
|
}
|
|
534
391
|
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
392
|
+
* The project-level skills install (`npx skills add
|
|
393
|
+
* prisma/prisma-next#v<version>`) failed after a successful dependency
|
|
394
|
+
* install + emit. The project's scaffold remains on disk; the user
|
|
395
|
+
* can either fix the underlying issue (network, registry, PATH) and
|
|
396
|
+
* run the install command manually, or re-run `init --no-skill` to
|
|
397
|
+
* proceed without the skill.
|
|
537
398
|
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
* subsequent indented line of the form `<key>: <value>` until the next
|
|
541
|
-
* top-level key (or end of file). Quotes around `<key>` and `<value>`
|
|
542
|
-
* are stripped; comments (`#…`) are ignored.
|
|
399
|
+
* Non-rolling-back, matching the existing install/emit failure
|
|
400
|
+
* semantics. Maps to exit code `6 = SKILL_INSTALL_FAILED`.
|
|
543
401
|
*/
|
|
544
|
-
function
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const version = stripQuotes((match[4] ?? "").trim());
|
|
558
|
-
if (version === "") continue;
|
|
559
|
-
entries.push([name, version]);
|
|
560
|
-
}
|
|
561
|
-
return entries;
|
|
562
|
-
}
|
|
563
|
-
function stripQuotes(value) {
|
|
564
|
-
if (value.length >= 2) {
|
|
565
|
-
const first = value[0];
|
|
566
|
-
const last = value[value.length - 1];
|
|
567
|
-
if (first === "\"" && last === "\"" || first === "'" && last === "'") return value.slice(1, -1);
|
|
568
|
-
}
|
|
569
|
-
return value;
|
|
402
|
+
function errorInitSkillInstallFailed(options) {
|
|
403
|
+
return new CliStructuredError("5013", "Failed to install Prisma Next skills", {
|
|
404
|
+
domain: "CLI",
|
|
405
|
+
why: `\`${options.skillInstallCommand}\` exited with an error: ${options.cause}`,
|
|
406
|
+
fix: `Either:
|
|
407
|
+
- Re-run \`prisma-next init --no-skill${options.filesWritten.length > 0 ? " --force" : ""}\` to skip the skill install for this run, or\n - Fix the underlying issue (network, npm registry, \`npx skills\` on PATH) and install manually:\n ${options.skillInstallCommand}`,
|
|
408
|
+
docsUrl: "https://prisma-next.dev/docs/cli/init#skills",
|
|
409
|
+
meta: {
|
|
410
|
+
filesWritten: options.filesWritten,
|
|
411
|
+
skillInstallCommand: options.skillInstallCommand,
|
|
412
|
+
cause: options.cause
|
|
413
|
+
}
|
|
414
|
+
});
|
|
570
415
|
}
|
|
571
416
|
//#endregion
|
|
572
417
|
//#region src/commands/init/hygiene-gitattributes.ts
|
|
@@ -1050,6 +895,11 @@ const AUTHORING_VALUES = new Map([
|
|
|
1050
895
|
["typescript", "typescript"],
|
|
1051
896
|
["ts", "typescript"]
|
|
1052
897
|
]);
|
|
898
|
+
const TELEMETRY_CONSENT_MESSAGE = [
|
|
899
|
+
"Help us prioritize features by sharing anonymous CLI usage data?",
|
|
900
|
+
"The telemetry implementation is open source and fully transparent.",
|
|
901
|
+
"(packages/1-framework/3-tooling/cli-telemetry and apps/telemetry-backend)."
|
|
902
|
+
].join(" ");
|
|
1053
903
|
/**
|
|
1054
904
|
* Resolves every required input for `runInit`. In interactive mode, missing
|
|
1055
905
|
* inputs are prompted via clack; in non-interactive mode, missing required
|
|
@@ -1097,6 +947,10 @@ async function resolveInitInputs(ctx) {
|
|
|
1097
947
|
canPrompt,
|
|
1098
948
|
autoAcceptPrompts
|
|
1099
949
|
});
|
|
950
|
+
const enableTelemetry = await resolveTelemetryConsent({
|
|
951
|
+
canPrompt,
|
|
952
|
+
autoAcceptPrompts
|
|
953
|
+
});
|
|
1100
954
|
const installProjectSkill = options.skill !== false;
|
|
1101
955
|
return {
|
|
1102
956
|
target: finalTarget,
|
|
@@ -1108,9 +962,49 @@ async function resolveInitInputs(ctx) {
|
|
|
1108
962
|
strictProbe: Boolean(options.strictProbe),
|
|
1109
963
|
reinit,
|
|
1110
964
|
removePreviousFacade,
|
|
965
|
+
enableTelemetry,
|
|
1111
966
|
installProjectSkill
|
|
1112
967
|
};
|
|
1113
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* The interactive telemetry consent prompt. Shown as the last
|
|
971
|
+
* question of the `init` sequence iff:
|
|
972
|
+
* 1. `canPrompt === true` (interactive stdin / stdout combo),
|
|
973
|
+
* 2. `autoAcceptPrompts === false` (the user did not pass `--yes`),
|
|
974
|
+
* 3. neither telemetry env opt-out is active,
|
|
975
|
+
* 4. the process is not running in CI,
|
|
976
|
+
* 5. the stored `enableTelemetry` value is `undefined` (the user
|
|
977
|
+
* has never been asked, or skipped the prompt previously).
|
|
978
|
+
*
|
|
979
|
+
* Outside that intersection the function returns `null` and leaves the
|
|
980
|
+
* stored preference untouched. Inside it, the user's answer is
|
|
981
|
+
* persisted via `writeUserConfig({ enableTelemetry })` before this
|
|
982
|
+
* function returns; on an affirmative answer `writeUserConfig`
|
|
983
|
+
* generates and stores the v4 `installationId` in the same write.
|
|
984
|
+
*
|
|
985
|
+
* The wording names CLI usage data and points to the open-source
|
|
986
|
+
* client/backend paths. Default value is `true` to match precedent
|
|
987
|
+
* and to make the consent answer a single keystroke once it's been
|
|
988
|
+
* disclosed.
|
|
989
|
+
*/
|
|
990
|
+
async function resolveTelemetryConsent(opts) {
|
|
991
|
+
if (!opts.canPrompt || opts.autoAcceptPrompts || isCI()) return null;
|
|
992
|
+
const config = readUserConfig();
|
|
993
|
+
const gating = resolveGating({
|
|
994
|
+
env: process.env,
|
|
995
|
+
config
|
|
996
|
+
});
|
|
997
|
+
if (!gating.enabled && gating.reason === "env-override") return null;
|
|
998
|
+
if (config.enableTelemetry !== void 0) return null;
|
|
999
|
+
const result = await clack.confirm({
|
|
1000
|
+
message: TELEMETRY_CONSENT_MESSAGE,
|
|
1001
|
+
initialValue: true,
|
|
1002
|
+
output: process.stderr
|
|
1003
|
+
});
|
|
1004
|
+
if (clack.isCancel(result)) throw errorInitUserAborted();
|
|
1005
|
+
writeUserConfig({ enableTelemetry: Boolean(result) });
|
|
1006
|
+
return Boolean(result);
|
|
1007
|
+
}
|
|
1114
1008
|
async function resolveWriteEnv(opts) {
|
|
1115
1009
|
if (opts.flag !== void 0) return Boolean(opts.flag);
|
|
1116
1010
|
if (!opts.canPrompt || opts.autoAcceptPrompts) return false;
|
|
@@ -1222,10 +1116,11 @@ function validateSchemaPath(value, authoring) {
|
|
|
1222
1116
|
});
|
|
1223
1117
|
const ext = extname(trimmed).toLowerCase();
|
|
1224
1118
|
const expected = authoring === "typescript" ? ".ts" : ".prisma";
|
|
1225
|
-
if (ext !== expected) throw
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1119
|
+
if (ext !== expected) throw errorInitAuthoringSchemaPathMismatch({
|
|
1120
|
+
authoring,
|
|
1121
|
+
schemaPath: trimmed,
|
|
1122
|
+
actualExtension: ext.length > 0 ? ext : "(none)",
|
|
1123
|
+
expectedExtension: expected
|
|
1229
1124
|
});
|
|
1230
1125
|
return normalize(trimmed);
|
|
1231
1126
|
}
|
|
@@ -1519,6 +1414,183 @@ function removeDependency(existing, depName) {
|
|
|
1519
1414
|
return `${JSON.stringify(parsed, null, 2)}${trailingNewline}`;
|
|
1520
1415
|
}
|
|
1521
1416
|
//#endregion
|
|
1417
|
+
//#region src/commands/init/skill-install.ts
|
|
1418
|
+
const exec = promisify(execFile);
|
|
1419
|
+
/**
|
|
1420
|
+
* Default base for the GitHub-URL form `<owner>/<repo>` consumed by
|
|
1421
|
+
* upstream `skills add`. Each `SkillSource` joins this base with its
|
|
1422
|
+
* own subpath (and optional `#ref` for version-pinned clusters).
|
|
1423
|
+
*/
|
|
1424
|
+
const DEFAULT_SKILL_BASE = "prisma/prisma-next";
|
|
1425
|
+
const DEFAULT_SKILL_SOURCES = [
|
|
1426
|
+
{
|
|
1427
|
+
subpath: "skills",
|
|
1428
|
+
ref: "cli",
|
|
1429
|
+
description: "usage skills (version-locked to installed Prisma Next)"
|
|
1430
|
+
},
|
|
1431
|
+
{
|
|
1432
|
+
subpath: "skills/upgrade",
|
|
1433
|
+
ref: null,
|
|
1434
|
+
description: "upgrade skill (always tracks `main`)"
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
subpath: "skills/extension-author",
|
|
1438
|
+
ref: null,
|
|
1439
|
+
description: "extension-author skill (always tracks `main`)"
|
|
1440
|
+
}
|
|
1441
|
+
];
|
|
1442
|
+
/**
|
|
1443
|
+
* Test-only escape hatch for pinning the install base to a local
|
|
1444
|
+
* checkout. Production runs leave this unset, so installs always use
|
|
1445
|
+
* `DEFAULT_SKILL_BASE`.
|
|
1446
|
+
*
|
|
1447
|
+
* When set to an absolute filesystem path (typical for tests), the
|
|
1448
|
+
* `#ref` fragment is dropped — local-path mode in upstream's CLI does
|
|
1449
|
+
* not accept refs, and the local clone has whatever content the test
|
|
1450
|
+
* checked into it anyway. When set to anything else (e.g. a fork name
|
|
1451
|
+
* `myuser/prisma-next`), the ref policy is preserved.
|
|
1452
|
+
*/
|
|
1453
|
+
function resolveAgentSkillBase() {
|
|
1454
|
+
const override = process.env["PRISMA_NEXT_SKILLS_BASE"]?.trim();
|
|
1455
|
+
return override && override.length > 0 ? override : DEFAULT_SKILL_BASE;
|
|
1456
|
+
}
|
|
1457
|
+
function isLocalPath(base) {
|
|
1458
|
+
return base.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(base);
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* Build the `<base>/<subpath>[#ref]` URL the `skills` CLI will
|
|
1462
|
+
* resolve. Exported for unit tests so the per-source format can be
|
|
1463
|
+
* asserted without going through the full install loop.
|
|
1464
|
+
*/
|
|
1465
|
+
function formatSkillSourceUrl(source) {
|
|
1466
|
+
const base = resolveAgentSkillBase();
|
|
1467
|
+
const url = `${base}/${source.subpath}`;
|
|
1468
|
+
if (source.ref === null) return url;
|
|
1469
|
+
if (isLocalPath(base)) return url;
|
|
1470
|
+
if (source.ref === "cli") return `${url}#v${version}`;
|
|
1471
|
+
return url;
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* The skill-install command for one source, formatted for the
|
|
1475
|
+
* project's detected package manager. `npx`/`pnpm dlx`/`bunx` are
|
|
1476
|
+
* interchangeable to the user; we pick the variant that matches the
|
|
1477
|
+
* rest of the install step so a single project consistently uses one
|
|
1478
|
+
* runner.
|
|
1479
|
+
*
|
|
1480
|
+
* `--all` auto-selects every skill in the cluster and every detected
|
|
1481
|
+
* agent runtime, skipping the multi-select prompts the `skills` CLI
|
|
1482
|
+
* shows by default. A non-interactive scaffold step cannot present
|
|
1483
|
+
* prompts.
|
|
1484
|
+
*
|
|
1485
|
+
* Exported for unit tests so the per-PM dispatch can be asserted
|
|
1486
|
+
* without a live subprocess.
|
|
1487
|
+
*/
|
|
1488
|
+
function formatSkillInstallCommand(pm, source) {
|
|
1489
|
+
return formatPackageManagerCommand(pm, [
|
|
1490
|
+
"skills@latest",
|
|
1491
|
+
"add",
|
|
1492
|
+
formatSkillSourceUrl(source),
|
|
1493
|
+
"--all"
|
|
1494
|
+
]);
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* `skills add --all` should cover Claude Code, but upstream currently skips
|
|
1498
|
+
* project-local Claude symlinks when `.claude/` does not already exist. Run
|
|
1499
|
+
* the explicit Claude Code install as well so fresh projects get
|
|
1500
|
+
* `.claude/skills` without asking users to create that folder first.
|
|
1501
|
+
*/
|
|
1502
|
+
function formatClaudeSkillInstallCommand(pm, source) {
|
|
1503
|
+
return formatPackageManagerCommand(pm, [
|
|
1504
|
+
"skills@latest",
|
|
1505
|
+
"add",
|
|
1506
|
+
formatSkillSourceUrl(source),
|
|
1507
|
+
"--agent",
|
|
1508
|
+
"claude-code",
|
|
1509
|
+
"--skill",
|
|
1510
|
+
"'*'",
|
|
1511
|
+
"-y"
|
|
1512
|
+
]);
|
|
1513
|
+
}
|
|
1514
|
+
function formatPackageManagerCommand(pm, args) {
|
|
1515
|
+
switch (pm) {
|
|
1516
|
+
case "pnpm": return `pnpm dlx ${args.join(" ")}`;
|
|
1517
|
+
case "yarn": return `yarn dlx ${args.join(" ")}`;
|
|
1518
|
+
case "bun": return `bunx ${args.join(" ")}`;
|
|
1519
|
+
case "deno": return `deno run -A npm:${args.join(" ")}`;
|
|
1520
|
+
case "npm": return `npx ${args.join(" ")}`;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Parse the project-pm-formatted command into an exec call. The
|
|
1525
|
+
* format-then-parse split keeps the user-facing command string the same
|
|
1526
|
+
* as the surface the structured error advertises, so a user who copies
|
|
1527
|
+
* the error's `fix` line gets the same invocation that init just
|
|
1528
|
+
* attempted. Single quotes are preserved in the display form so `*` is
|
|
1529
|
+
* safe to copy into a shell, then stripped before `execFile`.
|
|
1530
|
+
*/
|
|
1531
|
+
function commandToExec(command) {
|
|
1532
|
+
const tokens = (command.match(/'[^']*'|\S+/g) ?? []).map((token) => token.startsWith("'") && token.endsWith("'") ? token.slice(1, -1) : token);
|
|
1533
|
+
return {
|
|
1534
|
+
file: tokens[0] ?? "npx",
|
|
1535
|
+
args: tokens.slice(1)
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Runs the project-level skill install for every source in
|
|
1540
|
+
* `DEFAULT_SKILL_SOURCES`, in order. Returns
|
|
1541
|
+
* `{ ok: true, commands }` on success; throws a structured
|
|
1542
|
+
* `errorInitSkillInstallFailed` on the first failure (subsequent
|
|
1543
|
+
* sources are not attempted — the user opted into Prisma Next by
|
|
1544
|
+
* running `init` and a partial install would leave the project in an
|
|
1545
|
+
* ambiguous state). The throw is intentionally fatal — project-level
|
|
1546
|
+
* skill install is unconditional (modulo `--no-skill`).
|
|
1547
|
+
*/
|
|
1548
|
+
async function runProjectLevelSkillInstall(ctx) {
|
|
1549
|
+
const commands = [];
|
|
1550
|
+
const installCommands = DEFAULT_SKILL_SOURCES.flatMap((source) => [formatSkillInstallCommand(ctx.pm, source), formatClaudeSkillInstallCommand(ctx.pm, source)]);
|
|
1551
|
+
for (const command of installCommands) {
|
|
1552
|
+
const { file, args } = commandToExec(command);
|
|
1553
|
+
try {
|
|
1554
|
+
await exec(file, args, { cwd: ctx.baseDir });
|
|
1555
|
+
commands.push(command);
|
|
1556
|
+
} catch (err) {
|
|
1557
|
+
throw errorInitSkillInstallFailed({
|
|
1558
|
+
skillInstallCommand: command,
|
|
1559
|
+
filesWritten: ctx.filesWritten,
|
|
1560
|
+
cause: redactSecrets$1(readChildStderr$1(err)) || (err instanceof Error ? err.message : String(err))
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
ok: true,
|
|
1566
|
+
commands
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
function readChildStderr$1(err) {
|
|
1570
|
+
if (err instanceof Error && "stderr" in err) return String(err.stderr ?? "");
|
|
1571
|
+
return "";
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Strips credentials from a `scheme://user:pass@host/...` URL anywhere
|
|
1575
|
+
* in `stderr`. Package-manager stderr regularly contains credentialed
|
|
1576
|
+
* registry URLs (private npm registries, GitHub Packages tokens), and
|
|
1577
|
+
* those bubble into the structured `errorInitSkillInstallFailed`
|
|
1578
|
+
* envelope, which ends up in logs and CI output. Redact at the
|
|
1579
|
+
* boundary so we never re-emit a secret.
|
|
1580
|
+
*
|
|
1581
|
+
* Exported for unit tests.
|
|
1582
|
+
*/
|
|
1583
|
+
function redactSecrets$1(stderr) {
|
|
1584
|
+
if (!stderr) return stderr;
|
|
1585
|
+
return stderr.replace(/([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)([^/@\s]+)@/g, "$1***@");
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Hand-rolled skill stub path that init must not leave behind. Removed
|
|
1589
|
+
* on every init run so a project's `.agents/skills/prisma-next/` does
|
|
1590
|
+
* not shadow the installed Prisma Next skill cluster.
|
|
1591
|
+
*/
|
|
1592
|
+
const LEGACY_SKILL_FILE = ".agents/skills/prisma-next/SKILL.md";
|
|
1593
|
+
//#endregion
|
|
1522
1594
|
//#region src/commands/init/templates/env.ts
|
|
1523
1595
|
/**
|
|
1524
1596
|
* The minimum supported server version for each target (FR8.1). The
|
|
@@ -1556,7 +1628,12 @@ function envPlaceholderBody(target) {
|
|
|
1556
1628
|
lines.push(`# Requires ${label} >= ${minVersion}.`);
|
|
1557
1629
|
lines.push("");
|
|
1558
1630
|
if (target === "postgres") lines.push("DATABASE_URL=\"postgresql://user:password@localhost:5432/mydb\"");
|
|
1559
|
-
else
|
|
1631
|
+
else {
|
|
1632
|
+
lines.push("# Standalone local mongod / `docker run mongo:7` — no replica set required for first-run queries.");
|
|
1633
|
+
lines.push("# Transactions and change streams need a replica set; add ?replicaSet=... only after initiating one.");
|
|
1634
|
+
lines.push("");
|
|
1635
|
+
lines.push("DATABASE_URL=\"mongodb://user:password@localhost:27017/mydb\"");
|
|
1636
|
+
}
|
|
1560
1637
|
lines.push("");
|
|
1561
1638
|
return lines.join("\n");
|
|
1562
1639
|
}
|
|
@@ -1790,7 +1867,7 @@ function mergeTypesArray(existing) {
|
|
|
1790
1867
|
* structured CLI errors raised at every phase (input resolution, install,
|
|
1791
1868
|
* emit) and renders them via the same UI surface as success output
|
|
1792
1869
|
* (`--json` to stdout, human to stderr). Exit codes follow the documented
|
|
1793
|
-
* stable set in `./exit-codes.ts`
|
|
1870
|
+
* stable set in `./exit-codes.ts` and the
|
|
1794
1871
|
* [Style Guide § Exit Codes](../../../../../../../docs/CLI%20Style%20Guide.md#exit-codes).
|
|
1795
1872
|
*
|
|
1796
1873
|
* Layered for testability: the action handler in `./index.ts` is
|
|
@@ -1798,7 +1875,7 @@ function mergeTypesArray(existing) {
|
|
|
1798
1875
|
* function does no flag parsing of its own.
|
|
1799
1876
|
*/
|
|
1800
1877
|
async function runInit(baseDir, runOptions) {
|
|
1801
|
-
const { options, flags, canPrompt, probeOverrides } = runOptions;
|
|
1878
|
+
const { options, flags, canPrompt, probeOverrides, afterFirstTelemetryConsent } = runOptions;
|
|
1802
1879
|
const ui = new TerminalUI({
|
|
1803
1880
|
color: flags.color,
|
|
1804
1881
|
interactive: flags.interactive
|
|
@@ -1819,6 +1896,9 @@ async function runInit(baseDir, runOptions) {
|
|
|
1819
1896
|
if (CliStructuredError.is(error)) return emitError(ui, flags, error);
|
|
1820
1897
|
throw error;
|
|
1821
1898
|
}
|
|
1899
|
+
if (inputs.enableTelemetry === true && afterFirstTelemetryConsent !== void 0) try {
|
|
1900
|
+
await afterFirstTelemetryConsent(inputs);
|
|
1901
|
+
} catch {}
|
|
1822
1902
|
const pm = await detectPackageManager(baseDir);
|
|
1823
1903
|
const pkgRun = formatRunCommand(pm, "prisma-next", "").trimEnd();
|
|
1824
1904
|
const schemaDir = dirname(inputs.schemaPath);
|
|
@@ -1991,10 +2071,9 @@ async function runInit(baseDir, runOptions) {
|
|
|
1991
2071
|
filesWritten
|
|
1992
2072
|
}));
|
|
1993
2073
|
}
|
|
1994
|
-
const manualProjectSkillSummary =
|
|
2074
|
+
const manualProjectSkillSummary = DEFAULT_SKILL_SOURCES.flatMap((source) => [formatSkillInstallCommand(install.effectivePm, source), formatClaudeSkillInstallCommand(install.effectivePm, source)]).map((c) => `\`${c}\``).join(" && ");
|
|
1995
2075
|
let skillRegistered = false;
|
|
1996
|
-
if (!inputs.installProjectSkill) warnings.push(`Skipped Prisma Next
|
|
1997
|
-
else if (install.skipped) warnings.push(`Skipped Prisma Next agent-skill install because --no-install was passed. After you run install manually, install the skills with: ${manualProjectSkillSummary}`);
|
|
2076
|
+
if (!inputs.installProjectSkill) warnings.push(`Skipped Prisma Next skills install (--no-skill). To install the skills later, run: ${manualProjectSkillSummary}`);
|
|
1998
2077
|
else {
|
|
1999
2078
|
const spinner = ui.spinner();
|
|
2000
2079
|
spinner.start("Registering Prisma Next skills with the agent runtime...");
|
|
@@ -2085,7 +2164,8 @@ function exitCodeForError(error) {
|
|
|
2085
2164
|
case "5005":
|
|
2086
2165
|
case "5010":
|
|
2087
2166
|
case "5011":
|
|
2088
|
-
case "5012":
|
|
2167
|
+
case "5012":
|
|
2168
|
+
case "5014": return 2;
|
|
2089
2169
|
case "5006": return 3;
|
|
2090
2170
|
case "5007": return 4;
|
|
2091
2171
|
case "5008": return 5;
|
|
@@ -2360,4 +2440,4 @@ function sanitisePackageName(raw) {
|
|
|
2360
2440
|
//#endregion
|
|
2361
2441
|
export { runInit };
|
|
2362
2442
|
|
|
2363
|
-
//# sourceMappingURL=init-
|
|
2443
|
+
//# sourceMappingURL=init-n7JaaCgD.mjs.map
|