@prisma/cli 3.0.0-dev.97.1 → 8.0.0-rc.1

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 (99) hide show
  1. package/README.md +3 -14
  2. package/dist/adapters/local-state.js +14 -3
  3. package/dist/{lib/auth → auth}/client.js +11 -3
  4. package/dist/auth/errors.js +50 -0
  5. package/dist/{lib/auth → auth}/guard.js +7 -6
  6. package/dist/{lib/auth → auth}/login.js +147 -6
  7. package/dist/{lib/auth/auth-ops.js → auth/operations.js} +63 -13
  8. package/dist/auth/recipient.js +42 -0
  9. package/dist/{adapters → auth}/token-storage.js +28 -7
  10. package/dist/auth/workspaces.js +171 -0
  11. package/dist/cli-command.js +14 -0
  12. package/dist/cli-name.js +12 -0
  13. package/dist/cli.js +1 -1
  14. package/dist/cli2.js +25 -8
  15. package/dist/command-arguments.js +12 -0
  16. package/dist/commands/agent/index.js +60 -0
  17. package/dist/commands/app/index.js +11 -6
  18. package/dist/commands/auth/index.js +2 -3
  19. package/dist/commands/bucket/index.js +123 -0
  20. package/dist/commands/build/index.js +29 -0
  21. package/dist/commands/database/index.js +92 -2
  22. package/dist/commands/feedback/index.js +20 -0
  23. package/dist/commands/git/index.js +1 -1
  24. package/dist/commands/init/index.js +33 -0
  25. package/dist/commands/project/index.js +54 -5
  26. package/dist/controllers/agent-setup.js +52 -0
  27. package/dist/controllers/agent.js +228 -0
  28. package/dist/controllers/app-env-api.js +3 -2
  29. package/dist/controllers/app-env-file.js +1 -1
  30. package/dist/controllers/app-env.js +5 -5
  31. package/dist/controllers/app.js +423 -358
  32. package/dist/controllers/auth.js +62 -254
  33. package/dist/controllers/branch.js +5 -16
  34. package/dist/controllers/bucket.js +184 -0
  35. package/dist/controllers/build.js +88 -0
  36. package/dist/controllers/database.js +230 -85
  37. package/dist/controllers/feedback.js +90 -0
  38. package/dist/controllers/init.js +814 -0
  39. package/dist/controllers/project.js +345 -184
  40. package/dist/controllers/select-prompt-port.js +1 -0
  41. package/dist/{shell/errors.js → errors.js} +8 -40
  42. package/dist/lib/agent/cli-command.js +20 -0
  43. package/dist/lib/agent/constants.js +12 -0
  44. package/dist/lib/agent/package-manager.js +99 -0
  45. package/dist/lib/agent/setup-status.js +83 -0
  46. package/dist/lib/app/app-provider.js +168 -95
  47. package/dist/lib/app/branch-database-deploy.js +70 -42
  48. package/dist/lib/app/branch-database.js +39 -20
  49. package/dist/lib/app/build-settings.js +8 -3
  50. package/dist/lib/app/build.js +16 -14
  51. package/dist/lib/app/bun-project.js +1 -1
  52. package/dist/lib/app/compute-config.js +29 -31
  53. package/dist/lib/app/deploy-plan.js +1 -0
  54. package/dist/lib/app/deploy-progress.js +7 -7
  55. package/dist/lib/app/env-config.js +1 -1
  56. package/dist/lib/app/env-file.js +2 -2
  57. package/dist/lib/app/env-vars.js +1 -1
  58. package/dist/lib/app/local-dev.js +1 -1
  59. package/dist/lib/app/production-deploy-gate.js +3 -2
  60. package/dist/lib/bucket/provider.js +139 -0
  61. package/dist/lib/database/provider.js +235 -17
  62. package/dist/lib/diagnostics.js +2 -1
  63. package/dist/lib/feedback.js +15 -0
  64. package/dist/lib/git/local-branch.js +1 -1
  65. package/dist/lib/project/interactive-setup.js +6 -5
  66. package/dist/lib/project/local-pin.js +1 -1
  67. package/dist/lib/project/provider.js +93 -0
  68. package/dist/lib/project/resolution.js +11 -8
  69. package/dist/lib/project/setup.js +9 -6
  70. package/dist/lib/version.js +3 -2
  71. package/dist/lib/workspace-id.js +18 -0
  72. package/dist/payload-B88Qvzxk-CrtTXSOe.js +34 -0
  73. package/dist/presenters/agent.js +74 -0
  74. package/dist/presenters/app.js +33 -7
  75. package/dist/presenters/auth.js +3 -2
  76. package/dist/presenters/bucket.js +174 -0
  77. package/dist/presenters/database.js +193 -5
  78. package/dist/presenters/feedback.js +26 -0
  79. package/dist/presenters/init.js +30 -0
  80. package/dist/presenters/project.js +98 -4
  81. package/dist/shell/cli-command.js +2 -0
  82. package/dist/shell/command-meta.js +303 -4
  83. package/dist/shell/command-runner.js +13 -6
  84. package/dist/shell/help.js +6 -5
  85. package/dist/shell/output.js +65 -3
  86. package/dist/shell/prompt.js +12 -5
  87. package/dist/shell/runtime.js +4 -21
  88. package/dist/state-dir.js +12 -0
  89. package/dist/{shell/update-check.js → update-check.js} +6 -5
  90. package/dist/v8/cli.js +14699 -0
  91. package/dist/v8/sender.js +192 -0
  92. package/package.json +21 -13
  93. package/dist/adapters/mock-api.js +0 -136
  94. package/dist/lib/app/app-interaction.js +0 -5
  95. package/dist/shell/command-arguments.js +0 -6
  96. package/dist/use-cases/auth.js +0 -145
  97. package/dist/use-cases/branch.js +0 -47
  98. package/dist/use-cases/create-cli-gateways.js +0 -68
  99. package/dist/use-cases/project.js +0 -30
@@ -4,6 +4,7 @@ function createSelectPromptPort(context) {
4
4
  return { select: ({ message, choices }) => selectPrompt({
5
5
  input: context.runtime.stdin,
6
6
  output: context.runtime.stderr,
7
+ signal: context.runtime.signal,
7
8
  message,
8
9
  choices
9
10
  }) };
@@ -1,4 +1,4 @@
1
- //#region src/shell/errors.ts
1
+ //#region src/errors.ts
2
2
  var CliError = class extends Error {
3
3
  code;
4
4
  domain;
@@ -44,6 +44,12 @@ function usageError(summary, why, fix, nextSteps = [], domain = "cli") {
44
44
  nextSteps
45
45
  });
46
46
  }
47
+ function isUsageError(error, summary) {
48
+ return isErrorRecord(error) && error.code === "USAGE_ERROR" && (summary === void 0 || error.summary === summary);
49
+ }
50
+ function isErrorRecord(error) {
51
+ return typeof error === "object" && error !== null;
52
+ }
47
53
  function authRequiredError(nextSteps = ["prisma-cli auth login"], options = {}) {
48
54
  return new CliError({
49
55
  code: "AUTH_REQUIRED",
@@ -81,44 +87,6 @@ function commandCanceledError() {
81
87
  function workspaceRequiredError() {
82
88
  return usageError("Workspace required", "This command needs an active workspace, but the authenticated session does not have one.", "Run prisma-cli auth login and choose a workspace.", ["prisma-cli auth login"], "auth");
83
89
  }
84
- function workspaceSwitchUnavailableError() {
85
- return new CliError({
86
- code: "WORKSPACE_SWITCH_UNAVAILABLE",
87
- domain: "auth",
88
- summary: "Workspace switching is unavailable",
89
- why: "PRISMA_SERVICE_TOKEN is set, so authenticated commands use that token instead of local OAuth workspaces.",
90
- fix: "Unset PRISMA_SERVICE_TOKEN to switch between local OAuth workspaces, or use a token for the workspace you want.",
91
- exitCode: 1,
92
- nextSteps: ["unset PRISMA_SERVICE_TOKEN", "prisma-cli auth workspace list"]
93
- });
94
- }
95
- function workspaceNotAuthenticatedError(workspaceRef) {
96
- return new CliError({
97
- code: "WORKSPACE_NOT_AUTHENTICATED",
98
- domain: "auth",
99
- summary: "Workspace is not authenticated",
100
- why: `No stored OAuth session matched "${workspaceRef}".`,
101
- fix: "Run prisma-cli auth login and authorize that workspace, then switch to it.",
102
- meta: { workspaceRef },
103
- exitCode: 1,
104
- nextSteps: ["prisma-cli auth workspace list", "prisma-cli auth login"]
105
- });
106
- }
107
- function workspaceAmbiguousError(workspaceRef, matches) {
108
- return new CliError({
109
- code: "WORKSPACE_AMBIGUOUS",
110
- domain: "auth",
111
- summary: "Workspace name is ambiguous",
112
- why: `Multiple authenticated workspaces matched "${workspaceRef}".`,
113
- fix: "Run prisma-cli auth workspace list and switch by workspace id.",
114
- meta: {
115
- workspaceRef,
116
- matches
117
- },
118
- exitCode: 2,
119
- nextSteps: ["prisma-cli auth workspace list"]
120
- });
121
- }
122
90
  function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cli") {
123
91
  return new CliError({
124
92
  code: "FEATURE_UNAVAILABLE",
@@ -131,4 +99,4 @@ function featureUnavailableError(summary, why, fix, nextSteps = [], domain = "cl
131
99
  });
132
100
  }
133
101
  //#endregion
134
- export { CliError, authConfigInvalidError, authRequiredError, commandCanceledError, featureUnavailableError, usageError, workspaceAmbiguousError, workspaceNotAuthenticatedError, workspaceRequiredError, workspaceSwitchUnavailableError };
102
+ export { CliError, authConfigInvalidError, authRequiredError, commandCanceledError, featureUnavailableError, isUsageError, usageError, workspaceRequiredError };
@@ -0,0 +1,20 @@
1
+ import { formatPrismaCliCommand } from "../../cli-command.js";
2
+ import { resolvePackageRunner, resolvePackageRunnerSync } from "./package-manager.js";
3
+ //#region src/lib/agent/cli-command.ts
4
+ async function resolvePrismaCliPackageCommandFormatter(options) {
5
+ return createPrismaCliPackageCommandFormatter(await resolvePackageRunner(options));
6
+ }
7
+ async function resolvePrismaCliPackageCommand(options) {
8
+ return (await resolvePrismaCliPackageCommandFormatter(options))(options.args);
9
+ }
10
+ function resolvePrismaCliPackageCommandFormatterSync(cwd) {
11
+ return createPrismaCliPackageCommandFormatter(resolvePackageRunnerSync(cwd));
12
+ }
13
+ function resolvePrismaCliPackageCommandSync(cwd, args) {
14
+ return resolvePrismaCliPackageCommandFormatterSync(cwd)(args);
15
+ }
16
+ function createPrismaCliPackageCommandFormatter(packageRunner) {
17
+ return (args) => formatPrismaCliCommand(args, { packageRunner });
18
+ }
19
+ //#endregion
20
+ export { resolvePrismaCliPackageCommand, resolvePrismaCliPackageCommandFormatterSync, resolvePrismaCliPackageCommandSync };
@@ -0,0 +1,12 @@
1
+ //#region src/lib/agent/constants.ts
2
+ const PRISMA_SKILLS_SOURCE = "prisma/skills";
3
+ const PRISMA_SKILLS_LOCK_FILENAME = "skills-lock.json";
4
+ const SKILLS_CLI_PACKAGE = "skills@latest";
5
+ const DEFAULT_PRISMA_AGENT_SKILLS = ["*"];
6
+ const PRISMA_COMPUTE_AGENT_SKILL = "prisma-compute";
7
+ const DEFAULT_PRISMA_AGENT_TARGETS = ["codex", "claude-code"];
8
+ const PRISMA_AGENT_INSTALL_ARGS = ["agent", "install"];
9
+ const PRISMA_AGENT_UPDATE_ARGS = ["agent", "update"];
10
+ const PRISMA_AGENT_STATUS_ARGS = ["agent", "status"];
11
+ //#endregion
12
+ export { DEFAULT_PRISMA_AGENT_SKILLS, DEFAULT_PRISMA_AGENT_TARGETS, PRISMA_AGENT_INSTALL_ARGS, PRISMA_AGENT_STATUS_ARGS, PRISMA_AGENT_UPDATE_ARGS, PRISMA_COMPUTE_AGENT_SKILL, PRISMA_SKILLS_LOCK_FILENAME, PRISMA_SKILLS_SOURCE, SKILLS_CLI_PACKAGE };
@@ -0,0 +1,99 @@
1
+ import { readFileSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
+ //#region src/lib/agent/package-manager.ts
4
+ const LOCKFILE_PACKAGE_MANAGERS = [
5
+ {
6
+ packageManager: "bun",
7
+ fileNames: ["bun.lock", "bun.lockb"]
8
+ },
9
+ {
10
+ packageManager: "pnpm",
11
+ fileNames: ["pnpm-lock.yaml", "pnpm-workspace.yaml"]
12
+ },
13
+ {
14
+ packageManager: "yarn",
15
+ fileNames: ["yarn.lock"]
16
+ },
17
+ {
18
+ packageManager: "npm",
19
+ fileNames: ["package-lock.json", "npm-shrinkwrap.json"]
20
+ }
21
+ ];
22
+ async function resolveSkillsPackageRunner(options) {
23
+ return resolvePackageRunner(options);
24
+ }
25
+ async function resolvePackageRunner(options) {
26
+ options.signal.throwIfAborted();
27
+ const packageManager = detectPackageManagerSync(options.cwd, options.signal) ?? "npm";
28
+ options.signal.throwIfAborted();
29
+ return packageRunnerForPackageManager(packageManager);
30
+ }
31
+ function resolvePackageRunnerSync(cwd) {
32
+ return packageRunnerForPackageManager(detectPackageManagerSync(cwd) ?? "npm");
33
+ }
34
+ function detectPackageManagerSync(cwd, signal) {
35
+ let directory = path.resolve(cwd);
36
+ while (true) {
37
+ signal?.throwIfAborted();
38
+ const packageJsonManager = readPackageJsonPackageManager(directory);
39
+ if (packageJsonManager) return packageJsonManager;
40
+ const lockfileManager = readLockfilePackageManager(directory, signal);
41
+ if (lockfileManager) return lockfileManager;
42
+ const parent = path.dirname(directory);
43
+ if (parent === directory) return null;
44
+ directory = parent;
45
+ }
46
+ }
47
+ function readPackageJsonPackageManager(directory) {
48
+ const packageJsonPath = path.join(directory, "package.json");
49
+ let content;
50
+ try {
51
+ content = readFileSync(packageJsonPath, "utf8");
52
+ } catch (error) {
53
+ if (isMissingFileError(error)) return null;
54
+ throw error;
55
+ }
56
+ try {
57
+ return parsePackageManager(JSON.parse(content).packageManager);
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+ function readLockfilePackageManager(directory, signal) {
63
+ for (const candidate of LOCKFILE_PACKAGE_MANAGERS) for (const fileName of candidate.fileNames) {
64
+ signal?.throwIfAborted();
65
+ if (fileExists(path.join(directory, fileName))) return candidate.packageManager;
66
+ }
67
+ return null;
68
+ }
69
+ function fileExists(filePath) {
70
+ try {
71
+ return statSync(filePath).isFile();
72
+ } catch (error) {
73
+ if (isMissingFileError(error)) return false;
74
+ throw error;
75
+ }
76
+ }
77
+ function parsePackageManager(value) {
78
+ if (typeof value !== "string") return null;
79
+ const normalized = value.trim().toLowerCase();
80
+ if (normalized === "bun" || normalized.startsWith("bun@")) return "bun";
81
+ if (normalized === "pnpm" || normalized.startsWith("pnpm@")) return "pnpm";
82
+ if (normalized === "yarn" || normalized.startsWith("yarn@")) return "yarn";
83
+ if (normalized === "npm" || normalized.startsWith("npm@")) return "npm";
84
+ return null;
85
+ }
86
+ function packageRunnerForPackageManager(packageManager) {
87
+ switch (packageManager) {
88
+ case "bun": return ["bunx"];
89
+ case "pnpm": return ["pnpm", "dlx"];
90
+ case "yarn": return ["yarn", "dlx"];
91
+ case "npm": return ["npx", "-y"];
92
+ }
93
+ }
94
+ function isMissingFileError(error) {
95
+ const code = error.code;
96
+ return code === "ENOENT" || code === "ENOTDIR";
97
+ }
98
+ //#endregion
99
+ export { detectPackageManagerSync, resolvePackageRunner, resolvePackageRunnerSync, resolveSkillsPackageRunner };
@@ -0,0 +1,83 @@
1
+ import { PRISMA_SKILLS_LOCK_FILENAME } from "./constants.js";
2
+ import path from "node:path";
3
+ import { readFile, stat } from "node:fs/promises";
4
+ import { findComputeConfigDir } from "@prisma/compute-sdk/config";
5
+ //#region src/lib/agent/setup-status.ts
6
+ async function readPrismaAgentSetupStatus(options) {
7
+ const setupCwd = await resolvePrismaAgentSetupCwd(options);
8
+ const skillsLockPath = path.join(setupCwd, PRISMA_SKILLS_LOCK_FILENAME);
9
+ const [skillsInstalled, promptDismissedAt] = await Promise.all([hasPrismaSkillsLock(skillsLockPath, options.signal, options.requiredSkill), options.stateStore?.readAgentSetupPromptDismissedAt() ?? null]);
10
+ return {
11
+ skillsLockPath: path.basename(skillsLockPath),
12
+ skillsInstalled,
13
+ promptDismissedAt
14
+ };
15
+ }
16
+ async function resolvePrismaAgentSetupCwd(options) {
17
+ options.signal.throwIfAborted();
18
+ const configDir = await findComputeConfigDir(options.cwd, options.signal);
19
+ options.signal.throwIfAborted();
20
+ return configDir ?? options.cwd;
21
+ }
22
+ function isPrismaAgentSetupComplete(status) {
23
+ return status.skillsInstalled;
24
+ }
25
+ function shouldOfferPrismaAgentSetup(status) {
26
+ return !isPrismaAgentSetupComplete(status) && !status.promptDismissedAt;
27
+ }
28
+ async function isLikelyProjectDirectory(options) {
29
+ return (await Promise.all([
30
+ "package.json",
31
+ "prisma.compute.ts",
32
+ "prisma.config.ts",
33
+ ".git"
34
+ ].map((fileName) => pathExists(path.join(options.cwd, fileName), options.signal)))).some(Boolean);
35
+ }
36
+ async function hasPrismaSkillsLock(filePath, signal, requiredSkill) {
37
+ try {
38
+ const raw = await readFile(filePath, {
39
+ encoding: "utf8",
40
+ signal
41
+ });
42
+ return hasPrismaSkillsLockEntry(JSON.parse(raw), requiredSkill);
43
+ } catch (error) {
44
+ if (isNotFoundError(error) || error instanceof SyntaxError) return false;
45
+ throw error;
46
+ }
47
+ }
48
+ function hasPrismaSkillsLockEntry(value, requiredSkill) {
49
+ if (!isRecord(value)) return false;
50
+ if (requiredSkill) return skillLockEntryUsesPrismaSource(readSkillLockEntries(value)[requiredSkill]);
51
+ if (readLegacySources(value).includes("prisma/skills")) return true;
52
+ return Object.values(readSkillLockEntries(value)).some(skillLockEntryUsesPrismaSource);
53
+ }
54
+ function readLegacySources(value) {
55
+ return Array.isArray(value.sources) ? value.sources.filter((source) => typeof source === "string") : [];
56
+ }
57
+ function readSkillLockEntries(value) {
58
+ return isRecord(value.skills) ? value.skills : {};
59
+ }
60
+ function skillLockEntryUsesPrismaSource(value) {
61
+ return isRecord(value) && value.source === "prisma/skills";
62
+ }
63
+ function isRecord(value) {
64
+ return typeof value === "object" && value !== null;
65
+ }
66
+ async function pathExists(filePath, signal) {
67
+ signal.throwIfAborted();
68
+ try {
69
+ await stat(filePath);
70
+ signal.throwIfAborted();
71
+ return true;
72
+ } catch (error) {
73
+ if (signal.aborted) throw error;
74
+ if (isNotFoundError(error)) return false;
75
+ throw error;
76
+ }
77
+ }
78
+ function isNotFoundError(error) {
79
+ const code = error.code;
80
+ return code === "ENOENT" || code === "ENOTDIR";
81
+ }
82
+ //#endregion
83
+ export { isLikelyProjectDirectory, readPrismaAgentSetupStatus, resolvePrismaAgentSetupCwd, shouldOfferPrismaAgentSetup };