@prisma/cli 8.0.0-rc.15-dev.108 → 8.0.0-rc.15-dev.110

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.
Files changed (2) hide show
  1. package/dist/cli.js +120 -53
  2. package/package.json +8 -8
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
3
  import process$1 from "node:process";
4
- import { SERVICE_TOKEN_ENV_VAR, claimedExpiresAt, claimedIdentity, createCli, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfigSection, defineSessionCommand, detectCI, emptyServiceTokenError, flag, loadConfig, noSessionForWorkspaceError, positional, readActiveAccessToken, telemetryCommandGroup } from "@prisma/cli-engine";
4
+ import { SERVICE_TOKEN_ENV_VAR, claimedExpiresAt, claimedIdentity, createCli, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfigSection, defineSessionCommand, detectCI, emptyServiceTokenError, flag, loadConfig, noSessionForWorkspaceError, positional, readActiveAccessToken, realpathOr, resolveSectionOverChain, telemetryCommandGroup } from "@prisma/cli-engine";
5
5
  import { createComposerFamily } from "@prisma/composer-cli/family";
6
6
  import { ormCommandFamily } from "@prisma/orm-toolchain/cli";
7
7
  import { CliStructuredError, notOk, ok } from "@prisma/cli-engine/protocol";
@@ -16,7 +16,7 @@ import events from "node:events";
16
16
  import http from "node:http";
17
17
  import readline from "node:readline/promises";
18
18
  import open from "open";
19
- import { existsSync, fstatSync, readFileSync, statSync } from "node:fs";
19
+ import { fstatSync, readFileSync, statSync } from "node:fs";
20
20
  import { PnpmTool, YarnTool } from "@manypkg/tools";
21
21
  import { Result, TaggedError, UnhandledException, matchError } from "better-result";
22
22
  import { execFile, fork, spawn } from "node:child_process";
@@ -1238,6 +1238,7 @@ async function tryCompletePastedCallback(url, options) {
1238
1238
  await options.complete(url);
1239
1239
  return true;
1240
1240
  } catch (error) {
1241
+ if (error instanceof CliStructuredError) throw error;
1241
1242
  const message = error instanceof Error ? error.message : String(error);
1242
1243
  options.output.write(`Sign-in didn't complete (${message}). Paste the callback URL to try again.\n`);
1243
1244
  return false;
@@ -1296,6 +1297,11 @@ var LoginState = class {
1296
1297
  if (url.pathname !== "/auth/callback") throw new AuthError$1("Not a callback URL");
1297
1298
  const params = url.searchParams;
1298
1299
  const error = params.get("error");
1300
+ if (error === "access_denied") throw new CliStructuredError("AUTH.LOGIN_DENIED", "Sign-in was not authorized.", { nextActions: [{
1301
+ kind: "run-command",
1302
+ label: "Sign in again if you want to grant access",
1303
+ command: `${CLI_NAME} auth login`
1304
+ }] });
1299
1305
  if (error) {
1300
1306
  const desc = params.get("error_description");
1301
1307
  throw new AuthError$1(desc ? `${error}: ${desc}` : error);
@@ -2206,6 +2212,28 @@ async function isFile(target) {
2206
2212
  }
2207
2213
  }
2208
2214
  //#endregion
2215
+ //#region src/lib/version.ts
2216
+ const requireFromHere = createRequire(import.meta.url);
2217
+ /** The bundled entry sits one directory below the package root
2218
+ * (`dist/cli.js`); this source file sits two below (`src/lib/`). Both
2219
+ * are tried, nearest first, so the same code serves either. */
2220
+ const PACKAGE_JSON_CANDIDATES = ["../package.json", "../../package.json"];
2221
+ function readPackageMetadata() {
2222
+ for (const candidate of PACKAGE_JSON_CANDIDATES) try {
2223
+ const metadata = requireFromHere(candidate);
2224
+ if (metadata.version) return metadata;
2225
+ } catch {}
2226
+ return {};
2227
+ }
2228
+ function getCliVersion() {
2229
+ const pkg = readPackageMetadata();
2230
+ if (!pkg.version) throw new Error("CLI version metadata is missing from the installed package: the bundled package.json could not be read or did not contain a version field. Reinstall the CLI from the npm registry, or check your install path is intact.");
2231
+ return pkg.version;
2232
+ }
2233
+ function getCliName() {
2234
+ return CLI_NAME;
2235
+ }
2236
+ //#endregion
2209
2237
  //#region src/commands/skills/config.ts
2210
2238
  const DEFAULT = {
2211
2239
  check: true,
@@ -2282,31 +2310,34 @@ function validateAgents(raw) {
2282
2310
  agents
2283
2311
  };
2284
2312
  }
2313
+ /** The disk loader bound the way the bin's Runtime binds it, for
2314
+ * callers with no Runtime in scope (the post-login tip). */
2315
+ function projectConfigLoader(cwd) {
2316
+ return (configPath) => loadConfig(cwd, configPath, getCliVersion());
2317
+ }
2285
2318
  /**
2286
- * The validated skills section of an already-loaded config, or null
2287
- * when the section does not validate. Used by code that runs outside a
2288
- * command handler (the staleness check, the post-login tip), which has
2289
- * no ctx.config.
2319
+ * The project's skills settings, resolved per key over the discovered
2320
+ * config chain exactly as the skills commands resolve them, so callers
2321
+ * that run outside a command handler (the staleness check, the
2322
+ * post-login tip) agree with the commands on the governing config from
2323
+ * any directory. `load` is Runtime.loadConfig wherever a Runtime is in
2324
+ * scope, so a host-supplied loader governs these reads too. Chain
2325
+ * discovery is stat-only until a file exists, so a project without a
2326
+ * config never pays a TypeScript transpile.
2290
2327
  *
2291
- * Null deliberately collapses "no config" and "config invalid": both
2292
- * callers fall back to the default agent set, so a broken config never
2293
- * silences the check. The commands that consume the config surface the
2294
- * validation error themselves.
2328
+ * Null deliberately collapses "no config" and "config broken or
2329
+ * invalid": both callers fall back to the default agent set, so a
2330
+ * broken config never silences the check. The commands that consume
2331
+ * the config surface the error themselves.
2295
2332
  */
2296
- function readSkillsConfig(loaded) {
2297
- const section = skillsConfigSection.validate(loaded.sections[SKILLS_CONFIG_SECTION_NAME]);
2333
+ async function readProjectSkillsConfig(load, configPath) {
2334
+ const loaded = await load(configPath);
2335
+ if (loaded.diagnostics.some((entry) => entry.diagnostic.severity === "error") || loaded.files.length === 0) return null;
2336
+ const resolved = resolveSectionOverChain(skillsConfigSection, loaded.files);
2337
+ if (!resolved.ok) return null;
2338
+ const section = skillsConfigSection.validate(resolved.value, resolved.provenance);
2298
2339
  return section.ok ? section.value : null;
2299
2340
  }
2300
- /**
2301
- * The project's skills settings from prisma.config.ts, or null when no
2302
- * config file exists — decided with one stat, so a project without a
2303
- * config never pays the file's TypeScript transpile — or the section
2304
- * does not validate.
2305
- */
2306
- async function readProjectSkillsConfig(cwd, configPath) {
2307
- if (!existsSync(configPath === void 0 ? path.join(cwd, "prisma.config.ts") : path.resolve(cwd, configPath))) return null;
2308
- return readSkillsConfig(await loadConfig(cwd, configPath));
2309
- }
2310
2341
  const skillsConfigSection = defineConfigSection({
2311
2342
  name: SKILLS_CONFIG_SECTION_NAME,
2312
2343
  validate: (raw) => {
@@ -2363,7 +2394,7 @@ const SKILLS_SYNC_ARGS = ["skills", "sync"];
2363
2394
  async function resolveAgentSetupTipCommand(ctx) {
2364
2395
  if (ctx.env.CI) return null;
2365
2396
  try {
2366
- const config = await readProjectSkillsConfig(ctx.cwd);
2397
+ const config = await readProjectSkillsConfig(projectConfigLoader(ctx.cwd), ctx.configPath);
2367
2398
  if (config !== null && !config.check) return null;
2368
2399
  const status = await readSkillsStatus(ctx.cwd, {
2369
2400
  orphans: false,
@@ -5047,28 +5078,6 @@ function unreadableBodyDetail(error) {
5047
5078
  return isTimeout(error) ? TIMEOUT_DETAIL : "The feedback service response could not be read.";
5048
5079
  }
5049
5080
  //#endregion
5050
- //#region src/lib/version.ts
5051
- const requireFromHere = createRequire(import.meta.url);
5052
- /** The bundled entry sits one directory below the package root
5053
- * (`dist/cli.js`); this source file sits two below (`src/lib/`). Both
5054
- * are tried, nearest first, so the same code serves either. */
5055
- const PACKAGE_JSON_CANDIDATES = ["../package.json", "../../package.json"];
5056
- function readPackageMetadata() {
5057
- for (const candidate of PACKAGE_JSON_CANDIDATES) try {
5058
- const metadata = requireFromHere(candidate);
5059
- if (metadata.version) return metadata;
5060
- } catch {}
5061
- return {};
5062
- }
5063
- function getCliVersion() {
5064
- const pkg = readPackageMetadata();
5065
- if (!pkg.version) throw new Error("CLI version metadata is missing from the installed package: the bundled package.json could not be read or did not contain a version field. Reinstall the CLI from the npm registry, or check your install path is intact.");
5066
- return pkg.version;
5067
- }
5068
- function getCliName() {
5069
- return CLI_NAME;
5070
- }
5071
- //#endregion
5072
5081
  //#region src/commands/feedback.ts
5073
5082
  const DEFAULT_FEEDBACK_ENDPOINT = "https://hiieirp2pwqnjvq9axzyg6d0.fra.prisma.build/feedback";
5074
5083
  const MAX_MESSAGE_LENGTH = 4e3;
@@ -6266,6 +6275,39 @@ async function syncSkillsStep(cwd, agents, checkEnabledByConfig) {
6266
6275
  };
6267
6276
  }
6268
6277
  }
6278
+ /** Whether some file on the resolved chain sits in a strict ancestor
6279
+ * directory of cwd. A config in cwd itself does not count, and neither
6280
+ * does one reached sideways (--config to a file elsewhere) — the spec
6281
+ * defers only to an ancestor config. The chain is the one the needs
6282
+ * check loaded before the handler ran, so init's own scaffold never
6283
+ * counts either. Realpath'd on both sides so symlinked layouts compare
6284
+ * like with like. */
6285
+ function governedByAncestorConfig(files, cwd) {
6286
+ const here = realpathOr(cwd);
6287
+ return files.some((file) => {
6288
+ const relative = path.relative(realpathOr(path.dirname(file.path)), here);
6289
+ return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
6290
+ });
6291
+ }
6292
+ const ANCESTOR_SKIPPED_POSTINSTALL = {
6293
+ report: {
6294
+ outcome: "skipped",
6295
+ reason: "governing-config",
6296
+ script: null,
6297
+ dependency: "skipped"
6298
+ },
6299
+ lines: [summary("info", "Skipped the postinstall hook and the prisma dev dependency: another prisma.config.ts already governs this directory, so both belong at the repository root. Pass --postinstall to add them here anyway.")],
6300
+ diagnostics: []
6301
+ };
6302
+ const ANCESTOR_SKIPPED_SKILLS = {
6303
+ report: {
6304
+ outcome: "skipped",
6305
+ reason: "governing-config",
6306
+ sync: null
6307
+ },
6308
+ lines: [summary("info", "Skipped the skills sync: another prisma.config.ts already governs this directory, so the skills belong at the repository root. Pass --skills with your agents to sync them here anyway.")],
6309
+ diagnostics: []
6310
+ };
6269
6311
  const SKIPPED_POSTINSTALL = {
6270
6312
  report: {
6271
6313
  outcome: "skipped",
@@ -6321,6 +6363,11 @@ function parseSkillsFlag(raw, configured) {
6321
6363
  agents
6322
6364
  };
6323
6365
  }
6366
+ async function postinstallStep(flag, deferToAncestor, cwd) {
6367
+ if (flag === false) return SKIPPED_POSTINSTALL;
6368
+ if (deferToAncestor && flag === void 0) return ANCESTOR_SKIPPED_POSTINSTALL;
6369
+ return addPostinstallHook(cwd);
6370
+ }
6324
6371
  function initPresentations(result, postinstall, config, skills) {
6325
6372
  return {
6326
6373
  json: () => result,
@@ -6339,7 +6386,7 @@ function initPresentations(result, postinstall, config, skills) {
6339
6386
  const initCommand = defineCommand({
6340
6387
  help: {
6341
6388
  summary: "Prepare this repository for Prisma: config file, dev dependency, AI-agent skills",
6342
- description: "Runs locally and calls no platform API. Adds a postinstall script to package.json that keeps the Prisma agent skills in sync on every install, adds prisma to devDependencies at this CLI's exact version when no dependency field declares it, scaffolds a prisma.config.ts recording which agents to install skills for, then syncs the skills once now. Everything lands in the current directory; a prisma.config.ts or postinstall script that already exists is never edited. Rerunning is safe: each step reports what is already done.",
6389
+ description: "Runs locally and calls no platform API. Adds a postinstall script to package.json that keeps the Prisma agent skills in sync on every install, adds prisma to devDependencies at this CLI's exact version when no dependency field declares it, scaffolds a prisma.config.ts recording which agents to install skills for, then syncs the skills once now. Everything lands in the current directory; a prisma.config.ts or postinstall script that already exists is never edited. Rerunning is safe: each step reports what is already done. In a directory another prisma.config.ts already governs, init writes only the prisma.config.ts scaffold — the postinstall hook, the prisma dev dependency, and the skills sync belong at the repository root and are skipped unless --postinstall or --skills asks for them here.",
6343
6390
  examples: [
6344
6391
  "init",
6345
6392
  "init --skills=claude,cursor",
@@ -6358,9 +6405,13 @@ const initCommand = defineCommand({
6358
6405
  handler: async (args, ctx) => {
6359
6406
  const skillsFlag = parseSkillsFlag(args.flags.skills, ctx.config.agents);
6360
6407
  if (skillsFlag.kind === "invalid") return notOk(skillsFlag.error);
6361
- const postinstall = args.flags.postinstall === false ? SKIPPED_POSTINSTALL : await addPostinstallHook(ctx.cwd);
6408
+ const deferToAncestor = governedByAncestorConfig(ctx.configFiles, ctx.cwd);
6409
+ const postinstall = await postinstallStep(args.flags.postinstall, deferToAncestor, ctx.cwd);
6362
6410
  const config = await scaffoldConfigStep(ctx.cwd, skillsFlag.kind === "skip" ? [] : skillsFlag.agents, ctx.config.agentsConfigured);
6363
- const skills = skillsFlag.kind === "skip" ? SKIPPED_SKILLS : await syncSkillsStep(ctx.cwd, skillsFlag.agents, ctx.config.check);
6411
+ let skills;
6412
+ if (skillsFlag.kind === "skip") skills = SKIPPED_SKILLS;
6413
+ else if (deferToAncestor && args.flags.skills === void 0) skills = ANCESTOR_SKIPPED_SKILLS;
6414
+ else skills = await syncSkillsStep(ctx.cwd, skillsFlag.agents, ctx.config.check);
6364
6415
  const result = {
6365
6416
  postinstall: postinstall.report,
6366
6417
  config: config.report,
@@ -14476,6 +14527,21 @@ function outputStreamsShareDevice() {
14476
14527
  return;
14477
14528
  }
14478
14529
  }
14530
+ /** One chain discovery and transpile per config path per process: a
14531
+ * command's needs check and the skills staleness check both load the
14532
+ * config, and the process is single-shot, so nothing invalidates. The
14533
+ * promise is cached, not the value, so concurrent calls coalesce. */
14534
+ function memoizedConfigLoader(proc) {
14535
+ const loads = /* @__PURE__ */ new Map();
14536
+ return (configPath) => {
14537
+ let load = loads.get(configPath);
14538
+ if (load === void 0) {
14539
+ load = loadConfig(proc.cwd(), configPath, getCliVersion());
14540
+ loads.set(configPath, load);
14541
+ }
14542
+ return load;
14543
+ };
14544
+ }
14479
14545
  async function assembleRuntime(proc) {
14480
14546
  const stdin = {
14481
14547
  setRawMode: proc.stdin.isTTY === true && proc.stdin.setRawMode !== void 0 ? (enabled) => {
@@ -14509,7 +14575,7 @@ async function assembleRuntime(proc) {
14509
14575
  outputStreamsShareDevice: outputStreamsShareDevice(),
14510
14576
  exit: (code) => proc.exit(code),
14511
14577
  onSignal: makeOnSignal(proc),
14512
- loadConfig: (configPath) => loadConfig(proc.cwd(), configPath, getCliVersion()),
14578
+ loadConfig: memoizedConfigLoader(proc),
14513
14579
  credentialManager: new FileCredentialManager({
14514
14580
  env: proc.env,
14515
14581
  fetchWorkspaceName: fetchWorkspaceName(apiBaseUrl),
@@ -14548,7 +14614,7 @@ async function maybeWriteSkillsStaleNotice(runtime) {
14548
14614
  checkDisabled: false
14549
14615
  });
14550
14616
  if (status.upToDate) return;
14551
- const config = await readProjectSkillsConfig(runtime.cwd, configPathFromArgv(runtime.argv));
14617
+ const config = await readProjectSkillsConfig(runtime.loadConfig, configPathFromArgv(runtime.argv));
14552
14618
  if (config !== null && !config.check) return;
14553
14619
  const agents = config?.agents ?? DEFAULT_AGENTS;
14554
14620
  if (agents.length === 0) return;
@@ -14625,8 +14691,8 @@ function isSuppressedByInvocation(runtime) {
14625
14691
  function isFormat(tokens, format) {
14626
14692
  return tokens.some((token, index) => token === `--format=${format}` || token === "--format" && tokens[index + 1] === format);
14627
14693
  }
14628
- /** The file an explicit --config names, so the check reads the same
14629
- * config the command did. Discovery is otherwise cwd-only. */
14694
+ /** The file an explicit --config names, so the check anchors the same
14695
+ * chain the command did. Discovery otherwise anchors at cwd. */
14630
14696
  function configPathFromArgv(argv) {
14631
14697
  const tokens = flagTokens(argv);
14632
14698
  for (let index = 0; index < tokens.length; index += 1) {
@@ -14857,7 +14923,8 @@ async function main(proc, buildCliForRun = buildCli) {
14857
14923
  argv: proc.argv.slice(2),
14858
14924
  cwd: proc.cwd(),
14859
14925
  stdout: proc.stdout,
14860
- stderr: proc.stderr
14926
+ stderr: proc.stderr,
14927
+ loadConfig: runtime.loadConfig
14861
14928
  });
14862
14929
  return exitCode;
14863
14930
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli",
3
- "version": "8.0.0-rc.15-dev.108",
3
+ "version": "8.0.0-rc.15-dev.110",
4
4
  "description": "Command-line interface for the Prisma Developer Platform.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,11 +40,11 @@
40
40
  "license": "Apache-2.0",
41
41
  "dependencies": {
42
42
  "@manypkg/tools": "^2.1.2",
43
- "@prisma/cli-engine": "0.4.0",
44
- "@prisma/composer-cli": "0.20.0-dev.5",
43
+ "@prisma/cli-engine": "0.5.0",
44
+ "@prisma/composer-cli": "0.21.0-dev.1",
45
45
  "@prisma/compute-sdk": "0.42.0",
46
46
  "@prisma/management-api-sdk": "1.69.0",
47
- "@prisma/orm-toolchain": "8.0.0-rc.11-dev.16",
47
+ "@prisma/orm-toolchain": "8.0.0-rc.11-dev.37",
48
48
  "@vercel/detect-agent": "^1.2.3",
49
49
  "better-result": "^2.9.2",
50
50
  "cross-spawn": "^7.0.6",
@@ -53,11 +53,11 @@
53
53
  "open": "^11.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@prisma/composer": "0.20.0-dev.5",
56
+ "@prisma/composer": "0.21.0-dev.1",
57
57
  "@prisma/credentials-store": "^7.8.0",
58
- "@repo/cli-conformance": "8.0.0-rc.15-dev.108",
59
- "@repo/cli-telemetry": "8.0.0-rc.15-dev.108",
60
- "@repo/tsconfig": "8.0.0-rc.15-dev.108",
58
+ "@repo/cli-conformance": "8.0.0-rc.15-dev.110",
59
+ "@repo/cli-telemetry": "8.0.0-rc.15-dev.110",
60
+ "@repo/tsconfig": "8.0.0-rc.15-dev.110",
61
61
  "@types/node": "^22.19.19",
62
62
  "@types/cross-spawn": "^6.0.6",
63
63
  "tsdown": "^0.21.10",