@supacloud/cli 0.127.1 → 0.128.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.
package/README.md CHANGED
@@ -65,6 +65,9 @@ application. See [Application Starter](../../docs/application-starter.md) for th
65
65
  full contract.
66
66
 
67
67
  `app dev` runs the project's `dev` script; `app watch` only compiles and watches.
68
+ `app infer --format json` prints the same structural inference plan consumed by
69
+ generators, `doctor` and AI context. Safe facts may be applied automatically;
70
+ business policy remains explicit.
68
71
  `app dev --profile integration` requires a loopback database and a
69
72
  `dev:integration` script, verifies database identity and the application role, and
70
73
  never automatically migrates or seeds. The command recipe includes a durable host.
package/dist/index.js CHANGED
@@ -16661,7 +16661,7 @@ import { access as access2, lstat as lstat8, mkdtemp as mkdtemp3, opendir as ope
16661
16661
  import { spawn as spawn3 } from "node:child_process";
16662
16662
  import { createHash as createHash14 } from "node:crypto";
16663
16663
  import { tmpdir as tmpdir5 } from "node:os";
16664
- import { basename as basename10, dirname as dirname16, join as join26, relative as relative12, resolve as resolve33, sep as sep7 } from "node:path";
16664
+ import { basename as basename10, dirname as dirname16, join as join26, relative as relative13, resolve as resolve33, sep as sep7 } from "node:path";
16665
16665
  function isPublicBuildEnv2(name) {
16666
16666
  return PUBLIC_BUILD_ENV_PREFIXES2.some((prefix) => name.startsWith(prefix));
16667
16667
  }
@@ -16959,7 +16959,7 @@ async function collectArchiveFiles2(root) {
16959
16959
  bytes += data.byteLength;
16960
16960
  if (bytes > MAX_SOURCE_BYTES2)
16961
16961
  throw new Error(`Frontend output exceeds ${MAX_SOURCE_BYTES2} bytes`);
16962
- const archivePath = relative12(root, path).split(sep7).join("/");
16962
+ const archivePath = relative13(root, path).split(sep7).join("/");
16963
16963
  files.set(archivePath, data);
16964
16964
  digests.push({ path: archivePath, size: data.byteLength, sha256: createHash14("sha256").update(data).digest("hex") });
16965
16965
  }
@@ -17073,7 +17073,7 @@ import { execFile as execFile2 } from "node:child_process";
17073
17073
  import { createHash as createHash15 } from "node:crypto";
17074
17074
  import { constants as constants2 } from "node:fs";
17075
17075
  import { lstat as lstat9, open as open4, readdir as readdir10, realpath as realpath7 } from "node:fs/promises";
17076
- import { isAbsolute as isAbsolute8, join as join27, relative as relative13, resolve as resolve34 } from "node:path";
17076
+ import { isAbsolute as isAbsolute10, join as join27, relative as relative14, resolve as resolve34 } from "node:path";
17077
17077
  import { promisify as promisify2 } from "node:util";
17078
17078
  function isNodeError(error, code) {
17079
17079
  return error instanceof Error && "code" in error && error.code === code;
@@ -17095,8 +17095,8 @@ function safeBuild(command) {
17095
17095
  return !/token|secret|password|passwd|credential|api[_-]?key/i.test(command);
17096
17096
  }
17097
17097
  function inside3(root, candidate) {
17098
- const path = relative13(root, candidate);
17099
- return path === "" || !path.startsWith("..") && !isAbsolute8(path);
17098
+ const path = relative14(root, candidate);
17099
+ return path === "" || !path.startsWith("..") && !isAbsolute10(path);
17100
17100
  }
17101
17101
  function overlaps2(left, right) {
17102
17102
  return left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`);
@@ -17426,7 +17426,7 @@ async function workspaceTracksFile(root, path) {
17426
17426
  }
17427
17427
  async function readWorkspaceChangedList(root, changed) {
17428
17428
  const rootReal = await realpath7(resolve34(root));
17429
- const listRelative = relative13(rootReal, resolve34(rootReal, changed)).replaceAll("\\", "/");
17429
+ const listRelative = relative14(rootReal, resolve34(rootReal, changed)).replaceAll("\\", "/");
17430
17430
  if (!safeRelative(listRelative) || await pathKind(rootReal, listRelative) !== "ok") {
17431
17431
  throw new WorkspacePlanError("invalid-changed-path", "The changed-file list must be a regular file inside the workspace");
17432
17432
  }
@@ -19544,7 +19544,7 @@ var ACTION_POLICY = {
19544
19544
  init: { local: ["init"] },
19545
19545
  env: { local: ["list", "check", "sync"] },
19546
19546
  app: {
19547
- local: ["init", "generate", "dev", "watch", "verify-plan", "compile", "check", "graph", "explain", "export-tools", "context", "lens", "doctor", "fix", "plan", "build"],
19547
+ local: ["init", "generate", "infer", "dev", "watch", "verify-plan", "compile", "check", "graph", "explain", "export-tools", "context", "lens", "doctor", "fix", "plan", "build"],
19548
19548
  read: ["status", "evidence", "logs", "transfer-plan", "promote-plan", "rollback-plan", "history", "deploy-plan", "diff", "promote-status", "preview-plan", "previews", "preview-list", "preview-status"],
19549
19549
  write: ["release", "upload", "configure", "transfer", "promote", "promote-reconcile", "deploy", "rollback", "reconcile", "retire", "preview", "preview-create", "preview-reconcile", "preview-cleanup", "preview-pr"]
19550
19550
  },
@@ -29975,7 +29975,7 @@ init_schema7();
29975
29975
  init_tool_server();
29976
29976
  import { existsSync as existsSync13, readFileSync as readFileSync10 } from "node:fs";
29977
29977
  import { mkdir as mkdir6, readFile as readFile5, readdir as readdir5, writeFile as writeFile5 } from "node:fs/promises";
29978
- import { basename as basename8, dirname as dirname9, join as join15, relative as relative8, resolve as resolve20 } from "node:path";
29978
+ import { basename as basename8, dirname as dirname9, isAbsolute as isAbsolute6, join as join15, relative as relative8, resolve as resolve20 } from "node:path";
29979
29979
  import {
29980
29980
  applyDiagnosticFix,
29981
29981
  buildDeliveryProject,
@@ -29985,6 +29985,8 @@ import {
29985
29985
  createContextPack,
29986
29986
  createExecutionContextPack,
29987
29987
  createDiagnosticRepairPlan,
29988
+ createInferencePlan,
29989
+ formatInferencePlan,
29988
29990
  doctorProject,
29989
29991
  formatDoctorCheck,
29990
29992
  loadSupacloudConfig,
@@ -30120,7 +30122,7 @@ var starter_metadata_default = {
30120
30122
  generatedBy: "supacloud/starter-metadata-v1",
30121
30123
  packages: {
30122
30124
  compiler: {
30123
- version: "0.64.0"
30125
+ version: "0.65.0"
30124
30126
  },
30125
30127
  app: {
30126
30128
  version: "0.39.5",
@@ -37090,9 +37092,54 @@ async function generateScaffold(args) {
37090
37092
  }
37091
37093
  const root = resolve20(args.root || process.cwd());
37092
37094
  const dir = args.dir ?? "src/features";
37095
+ let registerIn = args.register_in;
37096
+ let inferredRegistration;
37097
+ let inferredModule;
37098
+ let existingModuleTarget = false;
37099
+ if (kind === "module" && args.name !== undefined && /^[A-Za-z][A-Za-z0-9_-]*$/.test(args.name.trim())) {
37100
+ try {
37101
+ existingModuleTarget = existsSync13(scaffoldPath(root, join15(dir, args.name.trim(), `${args.name.trim()}.module.ts`)));
37102
+ } catch {}
37103
+ }
37104
+ if (registerIn === undefined && !existingModuleTarget && (kind === "module" || kind === "resource" || kind === "feature")) {
37105
+ try {
37106
+ const project = await projectCompileConfig({ ...args, action: "check" });
37107
+ const inference = createInferencePlan(project.result.graph, {
37108
+ rootDir: project.root,
37109
+ sourceDir: project.sourceDir,
37110
+ generatedDir: project.outDir
37111
+ });
37112
+ const rootModule = inference.rootModuleCandidates.length === 1 ? project.result.graph.modules.find((module) => module.name === inference.rootModuleCandidates[0]) : undefined;
37113
+ if (rootModule !== undefined) {
37114
+ registerIn = projectRelativeSourcePath(project.root, project.sourceDir, rootModule.file);
37115
+ inferredRegistration = {
37116
+ target: registerIn,
37117
+ evidence: ["exactly one top-level application module was found"]
37118
+ };
37119
+ }
37120
+ } catch {}
37121
+ }
37122
+ let moduleName = args.module;
37123
+ if (moduleName === undefined && !["module", "resource", "feature"].includes(kind)) {
37124
+ try {
37125
+ const project = await projectCompileConfig({ ...args, action: "check" });
37126
+ const inference = createInferencePlan(project.result.graph, {
37127
+ rootDir: project.root,
37128
+ sourceDir: project.sourceDir,
37129
+ generatedDir: project.outDir
37130
+ });
37131
+ if (inference.rootModuleCandidates.length === 1) {
37132
+ moduleName = inference.rootModuleCandidates[0];
37133
+ inferredModule = {
37134
+ name: moduleName,
37135
+ evidence: ["exactly one top-level application module was found"]
37136
+ };
37137
+ }
37138
+ } catch {}
37139
+ }
37093
37140
  if (dir !== ".")
37094
37141
  scaffoldPath(root, dir);
37095
- if (args.register_in !== undefined && kind !== "resource" && kind !== "module" && kind !== "feature") {
37142
+ if (registerIn !== undefined && kind !== "resource" && kind !== "module" && kind !== "feature") {
37096
37143
  throw new ScaffoldError("SCAFFOLD_OPTION_INVALID", "--register-in is only supported for a new module, resource or feature");
37097
37144
  }
37098
37145
  if ((kind === "resource" || kind === "feature") && (args.force || args.module !== undefined)) {
@@ -37132,22 +37179,25 @@ async function generateScaffold(args) {
37132
37179
  writes.push({ path: join15(dir, name, file).replaceAll("\\", "/"), content });
37133
37180
  }
37134
37181
  } else {
37135
- const moduleName = requireIdentifier(args.module, "module");
37136
- const name = kind === "controller" ? moduleName : requireIdentifier(args.name, "name");
37182
+ if (!moduleName?.trim()) {
37183
+ throw new ScaffoldError("SCAFFOLD_MODULE_REQUIRED", "app generate requires --module; no unique top-level module was inferred");
37184
+ }
37185
+ const targetModule = requireIdentifier(moduleName, "module");
37186
+ const name = kind === "controller" ? targetModule : requireIdentifier(args.name, "name");
37137
37187
  const subdir = kind === "command" ? "commands" : kind === "query" ? "queries" : kind === "job" ? "jobs" : kind === "contract" ? "contracts" : "";
37138
- const path = join15(dir, moduleName, subdir, `${name}.${kind}.ts`).replaceAll("\\", "/");
37188
+ const path = join15(dir, targetModule, subdir, `${name}.${kind}.ts`).replaceAll("\\", "/");
37139
37189
  if (kind === "controller" && existsSync13(scaffoldPath(root, path))) {
37140
37190
  throw new ScaffoldError("SCAFFOLD_EXISTS", `Controller already exists: ${path}(请手工合并路由到现有 controller)`);
37141
37191
  }
37142
- const content = kind === "command" ? commandScaffold(moduleName, name) : kind === "query" ? queryScaffold(moduleName, name) : kind === "job" ? jobScaffold(moduleName, name) : kind === "contract" ? contractScaffold(moduleName, name) : controllerScaffold(moduleName);
37192
+ const content = kind === "command" ? commandScaffold(targetModule, name) : kind === "query" ? queryScaffold(targetModule, name) : kind === "job" ? jobScaffold(targetModule, name) : kind === "contract" ? contractScaffold(targetModule, name) : controllerScaffold(targetModule);
37143
37193
  writes.push({ path, content, overwrite: args.force === true });
37144
37194
  if (kind === "contract")
37145
37195
  contractName = name;
37146
37196
  }
37147
- if (args.register_in !== undefined && modulePath && moduleSymbol) {
37197
+ if (registerIn !== undefined && modulePath && moduleSymbol) {
37148
37198
  await planScaffoldWrites(root, writes);
37149
- const target = scaffoldPath(root, args.register_in);
37150
- const checked = await planScaffoldWrites(root, [{ path: args.register_in, content: "", overwrite: true }]);
37199
+ const target = scaffoldPath(root, registerIn);
37200
+ const checked = await planScaffoldWrites(root, [{ path: registerIn, content: "", overwrite: true }]);
37151
37201
  const original = checked.writes[0]?.before?.content;
37152
37202
  if (original === undefined)
37153
37203
  throw new ScaffoldError("SCAFFOLD_REGISTRATION_INVALID", "--register-in must name an existing module file");
@@ -37159,14 +37209,14 @@ async function generateScaffold(args) {
37159
37209
  importPath = `./${importPath}`;
37160
37210
  const edit = await applyDiagnosticFix({
37161
37211
  type: "add_module_import",
37162
- targetFile: args.register_in,
37212
+ targetFile: registerIn,
37163
37213
  module: requireIdentifier(args.name, "name"),
37164
37214
  importPath,
37165
37215
  symbol: moduleSymbol
37166
37216
  }, { rootDir: root, dryRun: true });
37167
37217
  if (await readFile5(target, "utf8") !== original)
37168
37218
  throw new ScaffoldError("SCAFFOLD_CHANGED", "Registration source changed during planning");
37169
- writes.push({ path: args.register_in, content: edit.content, expected: original });
37219
+ writes.push({ path: registerIn, content: edit.content, expected: original });
37170
37220
  }
37171
37221
  const plan = await planScaffoldWrites(root, writes);
37172
37222
  if (!args.dry_run)
@@ -37176,6 +37226,10 @@ async function generateScaffold(args) {
37176
37226
  action: write.before ? "overwritten" : "created",
37177
37227
  ...args.dry_run ? { content: write.content } : {}
37178
37228
  }));
37229
+ const inferenceEvidence = {
37230
+ ...inferredRegistration ? { registerIn: inferredRegistration } : {},
37231
+ ...inferredModule ? { module: inferredModule } : {}
37232
+ };
37179
37233
  if (args.format === "json")
37180
37234
  return textResult2(JSON.stringify({
37181
37235
  version: 1,
@@ -37183,13 +37237,18 @@ async function generateScaffold(args) {
37183
37237
  kind,
37184
37238
  root: plan.root,
37185
37239
  written: !args.dry_run,
37186
- changes
37240
+ changes,
37241
+ ...Object.keys(inferenceEvidence).length > 0 ? { inference: inferenceEvidence } : {}
37187
37242
  }, null, 2));
37188
37243
  const lines = changes.map((change) => `${args.dry_run ? "PREVIEW" : "✅"} ${change.action}: ${join15(plan.root, change.path)}`);
37189
37244
  if (args.dry_run)
37190
37245
  lines.push("No files written. Omit --dry-run to apply this generation.");
37246
+ if (inferredRegistration)
37247
+ lines.push(`Inferred registration: ${inferredRegistration.target} (${inferredRegistration.evidence.join("; ")}).`);
37248
+ if (inferredModule)
37249
+ lines.push(`Inferred module: ${inferredModule.name} (${inferredModule.evidence.join("; ")}).`);
37191
37250
  if (kind === "resource")
37192
- lines.push("Service and controller are registered in the generated module. No root module is guessed.", "Use --register-in <module.ts> to add an explicit parent import. Implement the read port before exposing the resource.", "Run app compile, app check --format json and your tests. No writes, permissions or persistence are inferred.");
37251
+ lines.push("Service and controller are registered in the generated module.", "A unique application root module is registered automatically; use --register-in when the project has multiple roots.", "Implement the read port before exposing the resource.", "Run app compile, app check --format json and your tests. No writes, permissions or persistence are inferred.");
37193
37252
  if (kind === "feature")
37194
37253
  lines.push(`Approval feature scaffold ${args.dry_run ? "planned" : "created"}; no database, authorization or job adapter is fabricated.`, "Bind the explicit RPC in compiler capabilities and runtime governance. Review the generated delivery checklist.", "Generate the client through app compile; no handwritten transport or database schema is created.");
37195
37254
  if (contractName) {
@@ -37222,6 +37281,16 @@ function parseInclude(include) {
37222
37281
  const patterns = include?.split(",").map((entry) => entry.trim()).filter(Boolean);
37223
37282
  return patterns && patterns.length > 0 ? patterns : undefined;
37224
37283
  }
37284
+ function projectRelativeSourcePath(root, sourceDir, file) {
37285
+ const normalized = file.replaceAll("\\", "/");
37286
+ if (isAbsolute6(file))
37287
+ return relative8(root, file).replaceAll("\\", "/");
37288
+ const sourcePrefix = relative8(root, resolve20(root, sourceDir)).replaceAll("\\", "/");
37289
+ if (!sourcePrefix || sourcePrefix === "." || normalized === sourcePrefix || normalized.startsWith(`${sourcePrefix}/`)) {
37290
+ return normalized;
37291
+ }
37292
+ return `${sourcePrefix}/${normalized}`;
37293
+ }
37225
37294
  function sourceRoot(args, root, configured) {
37226
37295
  const hasConfig = ["ts", "mts", "js", "mjs"].some((extension) => existsSync13(join15(root, `supacloud.config.${extension}`)));
37227
37296
  return args.root && !hasConfig ? "." : configured;
@@ -37344,6 +37413,7 @@ async function runContext(args) {
37344
37413
  commands: {
37345
37414
  check: "supacloud app check",
37346
37415
  compile: "supacloud app compile",
37416
+ infer: "supacloud app infer --format json",
37347
37417
  context: "supacloud app context --format json",
37348
37418
  doctor: "supacloud app doctor",
37349
37419
  fix: "supacloud app fix --fix <fix.json>",
@@ -37361,7 +37431,12 @@ async function runContext(args) {
37361
37431
  writeRetry: "disabled",
37362
37432
  externalOutcome: "receipt-reconcile",
37363
37433
  databaseSource: "zmodel-append-only"
37364
- }
37434
+ },
37435
+ inference: createInferencePlan(result.graph, {
37436
+ rootDir: root,
37437
+ sourceDir,
37438
+ generatedDir: outDir
37439
+ })
37365
37440
  };
37366
37441
  if (args.format === "json")
37367
37442
  return textResult2(JSON.stringify(project, null, 2));
@@ -37381,6 +37456,30 @@ async function runContext(args) {
37381
37456
  ].join(`
37382
37457
  `));
37383
37458
  }
37459
+ async function runInference(args) {
37460
+ const { root, sourceDir, outDir, result } = await projectCompileConfig(args);
37461
+ const plan = createInferencePlan(result.graph, {
37462
+ rootDir: root,
37463
+ sourceDir,
37464
+ generatedDir: outDir
37465
+ });
37466
+ const blocking = result.diagnostics.some((diagnostic) => diagnostic.severity === "error");
37467
+ if (args.format === "json") {
37468
+ return textResult2(JSON.stringify({
37469
+ ...plan,
37470
+ diagnostics: result.diagnostics,
37471
+ ready: !blocking
37472
+ }, null, 2), blocking);
37473
+ }
37474
+ return textResult2([
37475
+ formatInferencePlan(plan),
37476
+ "",
37477
+ ...result.diagnostics.map(formatDiagnostic),
37478
+ "",
37479
+ blocking ? "Inference is incomplete because the current graph has blocking diagnostics." : "Inference is read-only. Safe items may be applied by generators or reviewed by an agent."
37480
+ ].join(`
37481
+ `), blocking);
37482
+ }
37384
37483
  async function runLens(args) {
37385
37484
  const { root, sourceDir, outDir, result } = await projectCompileConfig(args);
37386
37485
  const graph = { ...result.graph, diagnostics: result.diagnostics };
@@ -37407,11 +37506,22 @@ async function runLens(args) {
37407
37506
  return textResult2(lines.join(`
37408
37507
  `), lens.conflicts.some((conflict) => conflict.severity === "error"));
37409
37508
  }
37410
- function doctorFixPlan(doctor) {
37411
- return createDiagnosticRepairPlan(doctor.diagnostics ?? []).map((repair, index) => ({
37509
+ function doctorFixPlan(doctor, inference) {
37510
+ const diagnostics = createDiagnosticRepairPlan(doctor.diagnostics ?? []).map((repair, index) => ({
37412
37511
  ...repair,
37413
37512
  command: `supacloud app fix --from-doctor <doctor.json> --fix-index ${index}`
37414
37513
  }));
37514
+ const existing = new Set(diagnostics.map((repair) => JSON.stringify(repair.fix)));
37515
+ const inferred = (inference?.items ?? []).filter((item) => item.readiness === "safe" && item.fix !== undefined && !existing.has(JSON.stringify(item.fix))).map((item, index) => ({
37516
+ code: `inference:${item.id}`,
37517
+ type: item.fix.type,
37518
+ targetFile: item.fix.targetFile,
37519
+ fix: item.fix,
37520
+ readiness: "preview",
37521
+ reason: item.evidence.join("; "),
37522
+ command: `supacloud app fix --from-doctor <doctor.json> --fix-index ${diagnostics.length + index}`
37523
+ }));
37524
+ return [...diagnostics, ...inferred];
37415
37525
  }
37416
37526
  async function findUnwiredContracts(rootDir) {
37417
37527
  const files = [];
@@ -37452,7 +37562,12 @@ async function findUnwiredContracts(rootDir) {
37452
37562
  return unwired;
37453
37563
  }
37454
37564
  async function runDoctor(args) {
37455
- const { root, outDir, result } = await projectCompileConfig(args);
37565
+ const { root, sourceDir, outDir, result } = await projectCompileConfig(args);
37566
+ const inference = createInferencePlan(result.graph, {
37567
+ rootDir: root,
37568
+ sourceDir,
37569
+ generatedDir: outDir
37570
+ });
37456
37571
  const target = args.target?.trim();
37457
37572
  const context = target ? createContextPack({ ...result.graph, diagnostics: result.diagnostics }, target) : undefined;
37458
37573
  const doctor = doctorProject(root, outDir, { ...result.graph, ...context ? { modules: context.modules } : {}, diagnostics: [] }, result.upToDate, context?.diagnostics ?? result.diagnostics);
@@ -37471,7 +37586,10 @@ async function runDoctor(args) {
37471
37586
  if (!database.ok)
37472
37587
  doctor.errors += 1;
37473
37588
  }
37474
- const fixPlan = doctorFixPlan(doctor);
37589
+ const fixPlan = doctorFixPlan(doctor, inference);
37590
+ const inferredSafe = inference.items.filter((item) => item.readiness === "safe");
37591
+ const inferredConfirm = inference.items.filter((item) => item.readiness === "confirm");
37592
+ const inferredNever = inference.items.filter((item) => item.readiness === "never");
37475
37593
  const autoFixable = fixPlan.filter((repair) => repair.readiness === "preview").length;
37476
37594
  const inputRequired = fixPlan.filter((repair) => repair.readiness === "input-required").length;
37477
37595
  const manualFixes = fixPlan.filter((repair) => repair.readiness === "manual").length;
@@ -37496,6 +37614,7 @@ async function runDoctor(args) {
37496
37614
  inputRequired,
37497
37615
  manualFixes,
37498
37616
  fixPlan,
37617
+ inference: { safe: inferredSafe.length, confirm: inferredConfirm.length, never: inferredNever.length, plan: inference },
37499
37618
  unwiredContracts,
37500
37619
  secretGap,
37501
37620
  ...scope ? { scope } : {},
@@ -37525,6 +37644,9 @@ async function runDoctor(args) {
37525
37644
  if (unwiredContracts.length > 0) {
37526
37645
  lines.push(`${unwiredContracts.length} unwired contract file(s): ${unwiredContracts.map((contract) => contract.file).join(", ")}. Import their schemas into a controller route or remove them.`);
37527
37646
  }
37647
+ lines.push(`Inference: ${inferredSafe.length} safe, ${inferredConfirm.length} confirm, ${inferredNever.length} explicit/manual.`);
37648
+ if (inferredConfirm.length > 0)
37649
+ lines.push(" Review candidates with `supacloud app infer --format json`.");
37528
37650
  return textResult2(lines.join(`
37529
37651
  `), doctor.errors > 0);
37530
37652
  }
@@ -38571,6 +38693,8 @@ async function runAppTool(request, options = {}) {
38571
38693
  const ready = plan.ready && !result.diagnostics.some((item) => item.severity === "error");
38572
38694
  return textResult2(JSON.stringify({ ...plan, ready, diagnostics: result.diagnostics }, null, 2), !ready);
38573
38695
  }
38696
+ case "infer":
38697
+ return runInference(request);
38574
38698
  case "dev":
38575
38699
  case "watch":
38576
38700
  return runAppDev(request, options);
@@ -38621,6 +38745,7 @@ function registerAppTools(server, options = {}) {
38621
38745
  action: withDescription(stringEnum2([
38622
38746
  "init",
38623
38747
  "generate",
38748
+ "infer",
38624
38749
  "dev",
38625
38750
  "watch",
38626
38751
  "verify-plan",
@@ -38668,7 +38793,7 @@ function registerAppTools(server, options = {}) {
38668
38793
  kind: optional(stringEnum2(["module", "command", "query", "controller", "job", "contract", "resource", "feature"]), "[generate] Scaffold kind"),
38669
38794
  template: optional(stringEnum2(["minimal", "client", "command", "model-command", "app"]), "[init] minimal (default) is the compiler/Effect stack; client is @supabase/supabase-js only; command is the native-SQL reference; model-command adds ZenStack HTTP/worker commands; app is an alias of minimal"),
38670
38795
  name: optional(String2(), "[init/generate] Project or object name"),
38671
- module: optional(String2(), "[generate] Target feature module (required for command/query/controller)"),
38796
+ module: optional(String2(), "[generate] Target feature module; inferred when the project has one top-level module"),
38672
38797
  permission: optional(String2(), "[generate feature] Explicit approval permission; not inferred from name"),
38673
38798
  read_permission: optional(String2(), "[generate feature] Explicit read permission; not inferred from name"),
38674
38799
  rpc: optional(String2(), "[generate feature] Explicit durable RPC capability; must be registered by the host"),
@@ -38705,7 +38830,7 @@ init_build();
38705
38830
  import { createHash as createHash10, randomUUID as randomUUID3 } from "node:crypto";
38706
38831
  import { existsSync as existsSync15 } from "node:fs";
38707
38832
  import { lstat as lstat5, readFile as readFile7, rename as rename4, unlink as unlink2, writeFile as writeFile7 } from "node:fs/promises";
38708
- import { join as join18, resolve as resolve23 } from "node:path";
38833
+ import { isAbsolute as isAbsolute9, join as join18, relative as relative10, resolve as resolve23 } from "node:path";
38709
38834
  import * as ts from "@supacloud/db/typescript";
38710
38835
  import {
38711
38836
  buildDatabaseManifest,
@@ -38722,7 +38847,7 @@ import { databaseSources } from "@supacloud/db/source-contracts";
38722
38847
  import { createHash as createHash9 } from "node:crypto";
38723
38848
  import { lstat as lstat4, mkdir as mkdir7, mkdtemp, readFile as readFile6, readdir as readdir6, rename as rename3, rm as rm2, writeFile as writeFile6 } from "node:fs/promises";
38724
38849
  import { tmpdir as tmpdir3 } from "node:os";
38725
- import { dirname as dirname11, isAbsolute as isAbsolute7, join as join17, relative as relative9, resolve as resolve22 } from "node:path";
38850
+ import { dirname as dirname11, isAbsolute as isAbsolute8, join as join17, relative as relative9, resolve as resolve22 } from "node:path";
38726
38851
  import {
38727
38852
  assertApplicationRoleRestricted,
38728
38853
  readDatabaseRole,
@@ -38737,7 +38862,7 @@ init_build();
38737
38862
  init_schema7();
38738
38863
  init_tool_server();
38739
38864
  import { chmodSync as chmodSync2, existsSync as existsSync14, mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync3 } from "node:fs";
38740
- import { dirname as dirname10, isAbsolute as isAbsolute6, join as join16, resolve as resolve21 } from "node:path";
38865
+ import { dirname as dirname10, isAbsolute as isAbsolute7, join as join16, resolve as resolve21 } from "node:path";
38741
38866
  var SENSITIVE_ENV_KEY2 = /(?:^|_)(?:PASSWORD|PASS|SECRET|TOKEN|KEY|CREDENTIALS?|AUTHORIZATION|AUTH|SESSION|COOKIE|BEARER|DB_URI|DB_URL|DSN|DATABASE_URL|DATABASE_URI|CONNECTION_STRING|CONNECTION_URI)(?:_|$)/i;
38742
38867
  var VALID_VERSION2 = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
38743
38868
  var VALID_MIGRATION_NAME2 = /^[A-Za-z0-9][A-Za-z0-9_-]{0,100}$/;
@@ -38802,7 +38927,7 @@ function workdirArguments2(workdir) {
38802
38927
  function resolveOutputPath2(workdir, file, label) {
38803
38928
  if (!file || /[\r\n\0]/.test(file))
38804
38929
  throw new Error(`${label} file is required`);
38805
- return isAbsolute6(file) ? resolve21(file) : resolve21(workdir, file);
38930
+ return isAbsolute7(file) ? resolve21(file) : resolve21(workdir, file);
38806
38931
  }
38807
38932
  function databaseTargetArguments2(databaseUrl) {
38808
38933
  return databaseUrl ? ["--db-url", requirePostgresUrl2(databaseUrl)] : ["--local"];
@@ -39033,7 +39158,7 @@ var result = (value, isError = false) => ({
39033
39158
  });
39034
39159
  var schemas = (value) => value?.split(",").map((entry) => entry.trim()).filter(Boolean) ?? ["public"];
39035
39160
  async function projectPath3(root, path) {
39036
- if (!path || isAbsolute7(path) || path.includes("\\") || path.split("/").some((part) => !part || part === "." || part === "..")) {
39161
+ if (!path || isAbsolute8(path) || path.includes("\\") || path.split("/").some((part) => !part || part === "." || part === "..")) {
39037
39162
  throw new Error("Use a normalized project-relative path");
39038
39163
  }
39039
39164
  let current = root;
@@ -39544,6 +39669,11 @@ function ownershipSuggestionReport(modules, selected) {
39544
39669
  ...suggestion,
39545
39670
  module: moduleForTable(modules, suggestion.table)?.name ?? null
39546
39671
  }));
39672
+ const blocking = suggestions.filter((suggestion) => suggestion.status === "ambiguous" || suggestion.status === "unknown").map((suggestion) => `${suggestion.table}.${suggestion.operation}: ${suggestion.status}`);
39673
+ const adoptable = suggestions.filter((suggestion) => suggestion.status === "suggested" && suggestion.owner !== null && suggestion.module !== null).length;
39674
+ const unclassified = suggestions.filter((suggestion) => suggestion.status !== "declared").length;
39675
+ const scope = selected.map((module) => module.name).join(", ");
39676
+ const moduleFlag = scope ? ` --module ${scope.split(", ")[0]}` : "";
39547
39677
  return {
39548
39678
  version: 1,
39549
39679
  scope: "operation-ownership",
@@ -39555,7 +39685,17 @@ function ownershipSuggestionReport(modules, selected) {
39555
39685
  suggested: suggestions.filter((suggestion) => suggestion.status === "suggested").length,
39556
39686
  ambiguous: suggestions.filter((suggestion) => suggestion.status === "ambiguous").length,
39557
39687
  unknown: suggestions.filter((suggestion) => suggestion.status === "unknown").length,
39558
- adoptable: suggestions.filter((suggestion) => suggestion.status === "suggested" && suggestion.owner !== null && suggestion.module !== null).length
39688
+ adoptable
39689
+ },
39690
+ enforcement: {
39691
+ ready: unclassified === 0,
39692
+ unclassified,
39693
+ blocking,
39694
+ next: [
39695
+ ...adoptable > 0 ? [`supacloud db operation-ownership adopt${moduleFlag}`, `supacloud db operation-ownership adopt${moduleFlag} --write`] : [],
39696
+ ...blocking.length > 0 ? [`supacloud db operation-ownership adopt --target <table> --operation <operation> --owner <owner> --write`] : [],
39697
+ ...unclassified === 0 ? ['# set databaseGovernance.ownership = "enforce" in supacloud.config.ts', "supacloud app check --format json"] : []
39698
+ ]
39559
39699
  }
39560
39700
  };
39561
39701
  }
@@ -39568,9 +39708,17 @@ async function selectedDatabaseModules(args, root) {
39568
39708
  return {
39569
39709
  modules,
39570
39710
  selected,
39571
- modulePath: resolve23(root, args.module_file ?? "db/modules.ts")
39711
+ modulePath: requireModulePathInsideRoot(root, args.module_file ?? "db/modules.ts")
39572
39712
  };
39573
39713
  }
39714
+ function requireModulePathInsideRoot(root, moduleFile) {
39715
+ const modulePath = resolve23(root, moduleFile);
39716
+ const pathWithinRoot = relative10(root, modulePath);
39717
+ if (pathWithinRoot === "" || isAbsolute9(pathWithinRoot) || pathWithinRoot.startsWith("..")) {
39718
+ throw new Error(`数据库模块文件必须位于项目目录内: ${modulePath}`);
39719
+ }
39720
+ return modulePath;
39721
+ }
39574
39722
  function requireOwnershipAction(args) {
39575
39723
  const action = args.operation_action;
39576
39724
  if (action !== "suggest" && action !== "adopt") {
@@ -39878,7 +40026,13 @@ async function runOperationOwnershipAdopt(args, root) {
39878
40026
  moduleFile: modulePath,
39879
40027
  sourceHash,
39880
40028
  changes,
39881
- skipped
40029
+ skipped,
40030
+ audit: {
40031
+ written: mode === "write" && updated !== original,
40032
+ adopted: changes.length,
40033
+ skipped: skipped.length,
40034
+ entries: changes
40035
+ }
39882
40036
  };
39883
40037
  return textResult3(JSON.stringify(report, null, 2), changes.length === 0 && skipped.length > 0 ? false : undefined);
39884
40038
  }
@@ -40661,7 +40815,7 @@ init_tool_server();
40661
40815
  init_release_contract();
40662
40816
  import { createHash as createHash11 } from "node:crypto";
40663
40817
  import { existsSync as existsSync16, mkdirSync as mkdirSync5, readdirSync as readdirSync5, readFileSync as readFileSync12, writeFileSync as writeFileSync4 } from "node:fs";
40664
- import { dirname as dirname12, join as join19, relative as relative10, resolve as resolve25 } from "node:path";
40818
+ import { dirname as dirname12, join as join19, relative as relative11, resolve as resolve25 } from "node:path";
40665
40819
  var SAFE_PROJECT_REF = /^[A-Za-z0-9_-]{1,64}$/;
40666
40820
  var SAFE_ENVIRONMENT_ID = /^[A-Za-z0-9_-]{1,64}$/;
40667
40821
  var BACKUP_ID = /^logical-full_[A-Za-z0-9_-]{1,64}_[a-f0-9]{32}$/;
@@ -41088,7 +41242,7 @@ function handleScopeRebind(args) {
41088
41242
  writeFileSync4(filePath, formatted, "utf8");
41089
41243
  }
41090
41244
  scopes.push({
41091
- file: relative10(cwd, filePath),
41245
+ file: relative11(cwd, filePath),
41092
41246
  task_id: typeof parsed.taskId === "string" ? parsed.taskId : "",
41093
41247
  target_project_ref: typeof parsed.targetProjectRef === "string" ? parsed.targetProjectRef : "",
41094
41248
  previous_base_commit: previousBaseCommit,
@@ -41148,7 +41302,7 @@ function handleScopeInspect(args) {
41148
41302
  const scopeSha256 = genericScopedReleaseScopeSha256(parsed);
41149
41303
  const git = gitCommitInfo(cwd);
41150
41304
  return releaseControlSuccess("release.scope_inspect", {
41151
- file: relative10(cwd, filePath),
41305
+ file: relative11(cwd, filePath),
41152
41306
  scope: {
41153
41307
  task_id: parsed.taskId,
41154
41308
  target_project_ref: parsed.targetProjectRef,
@@ -41216,7 +41370,7 @@ function handleContractPlan(args, fallbackRef) {
41216
41370
  }, { migration: 0, function: 0, web: 0 });
41217
41371
  return releaseControlSuccess("release.contract_plan", {
41218
41372
  plan_schema: "supacloud.release-plan.v1",
41219
- file: relative10(cwd, filePath),
41373
+ file: relative11(cwd, filePath),
41220
41374
  release_id: scope.releaseId,
41221
41375
  scope_sha256: releaseScopeSha256(scope),
41222
41376
  source_commit: scope.sourceCommit,
@@ -41283,7 +41437,7 @@ function handleScopeCreate(args, fallbackRef) {
41283
41437
  `;
41284
41438
  writeFileSync4(filePath, formatted, "utf8");
41285
41439
  return releaseControlSuccess("release.scope_create", {
41286
- file: relative10(cwd, filePath),
41440
+ file: relative11(cwd, filePath),
41287
41441
  task_id: scope.taskId,
41288
41442
  target_project_ref: projectRef,
41289
41443
  target_environment_id: targetEnvironmentId,
@@ -41528,7 +41682,7 @@ import { access, lstat as lstat6, mkdtemp as mkdtemp2, opendir, readFile as read
41528
41682
  import { spawn as spawn2 } from "node:child_process";
41529
41683
  import { createHash as createHash12 } from "node:crypto";
41530
41684
  import { tmpdir as tmpdir4 } from "node:os";
41531
- import { basename as basename9, dirname as dirname14, join as join21, relative as relative11, resolve as resolve28, sep as sep6 } from "node:path";
41685
+ import { basename as basename9, dirname as dirname14, join as join21, relative as relative12, resolve as resolve28, sep as sep6 } from "node:path";
41532
41686
  var MAX_SOURCE_BYTES = 256 * 1024 * 1024;
41533
41687
  var PUBLIC_BUILD_ENV_PREFIXES = ["PUBLIC_", "VITE_", "NEXT_PUBLIC_", "NUXT_PUBLIC_", "ASTRO_PUBLIC_"];
41534
41688
  var SENSITIVE_BUILD_ENV = /(?:^|_)(?:PASSWORD|PASS|SECRET|TOKEN|KEY|CREDENTIAL|AUTHORIZATION|COOKIE|SESSION)(?:_|$)|(?:DATABASE_URL|DATABASE_URI|CONNECTION_STRING|DSN|PRIVATE_KEY)/i;
@@ -41909,7 +42063,7 @@ async function collectArchiveFiles(root) {
41909
42063
  bytes += data.byteLength;
41910
42064
  if (bytes > MAX_SOURCE_BYTES)
41911
42065
  throw new Error(`Frontend output exceeds ${MAX_SOURCE_BYTES} bytes`);
41912
- const archivePath = relative11(root, path).split(sep6).join("/");
42066
+ const archivePath = relative12(root, path).split(sep6).join("/");
41913
42067
  files.set(archivePath, data);
41914
42068
  digests.push({ path: archivePath, size: data.byteLength, sha256: createHash12("sha256").update(data).digest("hex") });
41915
42069
  }
@@ -43058,7 +43212,7 @@ import { execFile as execFile3 } from "node:child_process";
43058
43212
  import { createHash as createHash17 } from "node:crypto";
43059
43213
  import { constants as constants3 } from "node:fs";
43060
43214
  import { lstat as lstat10, open as open5, readdir as readdir11, realpath as realpath8 } from "node:fs/promises";
43061
- import { isAbsolute as isAbsolute9, join as join29, relative as relative14, resolve as resolve37 } from "node:path";
43215
+ import { isAbsolute as isAbsolute11, join as join29, relative as relative15, resolve as resolve37 } from "node:path";
43062
43216
  import { promisify as promisify3 } from "node:util";
43063
43217
  var execFileAsync3 = promisify3(execFile3);
43064
43218
  var WORKSPACE_CONFIG_FILE2 = "supacloud.workspace.json";
@@ -43146,8 +43300,8 @@ function safeBuild2(command) {
43146
43300
  return !/token|secret|password|passwd|credential|api[_-]?key/i.test(command);
43147
43301
  }
43148
43302
  function inside4(root, candidate) {
43149
- const path = relative14(root, candidate);
43150
- return path === "" || !path.startsWith("..") && !isAbsolute9(path);
43303
+ const path = relative15(root, candidate);
43304
+ return path === "" || !path.startsWith("..") && !isAbsolute11(path);
43151
43305
  }
43152
43306
  function overlaps3(left, right) {
43153
43307
  return left === right || left.startsWith(`${right}/`) || right.startsWith(`${left}/`);
@@ -44080,7 +44234,7 @@ async function runWorkspacePlan(args, cwd = process.cwd()) {
44080
44234
  try {
44081
44235
  if (hasChanged) {
44082
44236
  const rootReal = await realpath8(root);
44083
- const listRelative = relative14(rootReal, resolve37(rootReal, args.changed)).replaceAll("\\", "/");
44237
+ const listRelative = relative15(rootReal, resolve37(rootReal, args.changed)).replaceAll("\\", "/");
44084
44238
  const environment = Check2(ApplicationIdSchema, args.environment) ? args.environment : null;
44085
44239
  if (!safeRelative2(listRelative) || await pathKind2(rootReal, listRelative) !== "ok") {
44086
44240
  return render(blockedPlan2(environment, "invalid-changed-path", "The changed-file list must be a regular file inside the workspace"));
@@ -44260,7 +44414,7 @@ async function runProjectDeployment(http, args) {
44260
44414
  // package.json
44261
44415
  var package_default = {
44262
44416
  name: "@supacloud/cli",
44263
- version: "0.127.1",
44417
+ version: "0.128.1",
44264
44418
  description: "Project-scoped CLI for SupaCloud users",
44265
44419
  type: "module",
44266
44420
  main: "./dist/index.js",
@@ -44312,7 +44466,7 @@ var package_default = {
44312
44466
  directory: "packages/cli"
44313
44467
  },
44314
44468
  dependencies: {
44315
- "@supacloud/compiler": "^0.64.0",
44469
+ "@supacloud/compiler": "^0.65.0",
44316
44470
  "@supacloud/delivery": "0.30.0",
44317
44471
  "@supacloud/db": "0.26.0",
44318
44472
  typebox: "1.4.3"
@@ -44321,7 +44475,7 @@ var package_default = {
44321
44475
  "@supacloud/contracts": "0.16.3",
44322
44476
  "@supacloud/delivery": "0.30.0",
44323
44477
  "@graphql-tools/utils": "^12.0.4",
44324
- "@supacloud/compiler": "^0.64.0",
44478
+ "@supacloud/compiler": "^0.65.0",
44325
44479
  "@supacloud/db": "0.26.0",
44326
44480
  "deepmerge-ts": "8.0.2",
44327
44481
  prisma: "6.19.3"
@@ -44622,6 +44776,7 @@ EXAMPLES
44622
44776
  ${preferredCommand} app logs --ref abc123 --id orders --environment_id test
44623
44777
  ${preferredCommand} app rollback --ref abc123 --id orders --environment_id test --release_id <old-sha256> --configuration_id <uuid> --activation_id <new-uuid> --expected_activation_id <current-uuid>
44624
44778
  ${preferredCommand} app check --root . --strict
44779
+ ${preferredCommand} app infer --root . --format json
44625
44780
  ${preferredCommand} app graph --root . --format json
44626
44781
  ${preferredCommand} app explain --target CaseService
44627
44782
  ${preferredCommand} app context --root . --format json
@@ -0,0 +1 @@
1
+ export {};
@@ -40,7 +40,7 @@ export interface AppToolOptions {
40
40
  onDevProgress?: (result: ToolResult) => void;
41
41
  }
42
42
  export interface AppToolArguments {
43
- action: "init" | "generate" | "dev" | "watch" | "verify-plan" | "compile" | "check" | "graph" | "explain" | "export-tools" | "context" | "lens" | "doctor" | "fix" | "plan" | "build" | "release" | "promote" | keyof typeof REMOTE_APP_ACTIONS;
43
+ action: "init" | "generate" | "infer" | "dev" | "watch" | "verify-plan" | "compile" | "check" | "graph" | "explain" | "export-tools" | "context" | "lens" | "doctor" | "fix" | "plan" | "build" | "release" | "promote" | keyof typeof REMOTE_APP_ACTIONS;
44
44
  ref?: string;
45
45
  id?: string;
46
46
  environment_id?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/cli",
3
- "version": "0.127.1",
3
+ "version": "0.128.1",
4
4
  "description": "Project-scoped CLI for SupaCloud users",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,7 +52,7 @@
52
52
  "directory": "packages/cli"
53
53
  },
54
54
  "dependencies": {
55
- "@supacloud/compiler": "^0.64.0",
55
+ "@supacloud/compiler": "^0.65.0",
56
56
  "@supacloud/delivery": "0.30.0",
57
57
  "@supacloud/db": "0.26.0",
58
58
  "typebox": "1.4.3"
@@ -61,7 +61,7 @@
61
61
  "@supacloud/contracts": "0.16.3",
62
62
  "@supacloud/delivery": "0.30.0",
63
63
  "@graphql-tools/utils": "^12.0.4",
64
- "@supacloud/compiler": "^0.64.0",
64
+ "@supacloud/compiler": "^0.65.0",
65
65
  "@supacloud/db": "0.26.0",
66
66
  "deepmerge-ts": "8.0.2",
67
67
  "prisma": "6.19.3"