@metaobjectsdev/cli 0.24.4 → 0.25.0

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 (74) hide show
  1. package/README.md +2 -1
  2. package/dist/src/commands/docs.d.ts +14 -1
  3. package/dist/src/commands/docs.d.ts.map +1 -1
  4. package/dist/src/commands/docs.js +153 -8
  5. package/dist/src/commands/docs.js.map +1 -1
  6. package/dist/src/commands/eject.d.ts +38 -0
  7. package/dist/src/commands/eject.d.ts.map +1 -0
  8. package/dist/src/commands/eject.js +233 -0
  9. package/dist/src/commands/eject.js.map +1 -0
  10. package/dist/src/commands/gen.d.ts.map +1 -1
  11. package/dist/src/commands/gen.js +43 -20
  12. package/dist/src/commands/gen.js.map +1 -1
  13. package/dist/src/commands/init.d.ts +15 -1
  14. package/dist/src/commands/init.d.ts.map +1 -1
  15. package/dist/src/commands/init.js +208 -20
  16. package/dist/src/commands/init.js.map +1 -1
  17. package/dist/src/commands/types.d.ts +2 -1
  18. package/dist/src/commands/types.d.ts.map +1 -1
  19. package/dist/src/commands/types.js +165 -28
  20. package/dist/src/commands/types.js.map +1 -1
  21. package/dist/src/commands/verify.d.ts +9 -1
  22. package/dist/src/commands/verify.d.ts.map +1 -1
  23. package/dist/src/commands/verify.js +299 -51
  24. package/dist/src/commands/verify.js.map +1 -1
  25. package/dist/src/index.d.ts.map +1 -1
  26. package/dist/src/index.js +105 -4
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/src/lib/advisory.d.ts +77 -0
  29. package/dist/src/lib/advisory.d.ts.map +1 -0
  30. package/dist/src/lib/advisory.js +97 -0
  31. package/dist/src/lib/advisory.js.map +1 -0
  32. package/dist/src/lib/anti-patterns.d.ts +27 -3
  33. package/dist/src/lib/anti-patterns.d.ts.map +1 -1
  34. package/dist/src/lib/anti-patterns.js +145 -8
  35. package/dist/src/lib/anti-patterns.js.map +1 -1
  36. package/dist/src/lib/args.d.ts +35 -1
  37. package/dist/src/lib/args.d.ts.map +1 -1
  38. package/dist/src/lib/args.js +32 -1
  39. package/dist/src/lib/args.js.map +1 -1
  40. package/dist/src/lib/detect-stack.d.ts.map +1 -1
  41. package/dist/src/lib/detect-stack.js +4 -13
  42. package/dist/src/lib/detect-stack.js.map +1 -1
  43. package/dist/src/lib/docs-drift.d.ts +31 -0
  44. package/dist/src/lib/docs-drift.d.ts.map +1 -0
  45. package/dist/src/lib/docs-drift.js +195 -0
  46. package/dist/src/lib/docs-drift.js.map +1 -0
  47. package/dist/src/lib/format.d.ts +10 -0
  48. package/dist/src/lib/format.d.ts.map +1 -1
  49. package/dist/src/lib/format.js +15 -0
  50. package/dist/src/lib/format.js.map +1 -1
  51. package/dist/src/lib/output.d.ts +13 -0
  52. package/dist/src/lib/output.d.ts.map +1 -1
  53. package/dist/src/lib/output.js +16 -1
  54. package/dist/src/lib/output.js.map +1 -1
  55. package/dist/src/lib/package-manifest.d.ts +27 -0
  56. package/dist/src/lib/package-manifest.d.ts.map +1 -0
  57. package/dist/src/lib/package-manifest.js +52 -0
  58. package/dist/src/lib/package-manifest.js.map +1 -0
  59. package/package.json +11 -11
  60. package/src/commands/docs.ts +194 -8
  61. package/src/commands/eject.ts +282 -0
  62. package/src/commands/gen.ts +54 -19
  63. package/src/commands/init.ts +217 -19
  64. package/src/commands/types.ts +185 -34
  65. package/src/commands/verify.ts +358 -47
  66. package/src/index.ts +114 -5
  67. package/src/lib/advisory.ts +150 -0
  68. package/src/lib/anti-patterns.ts +163 -8
  69. package/src/lib/args.ts +74 -2
  70. package/src/lib/detect-stack.ts +4 -11
  71. package/src/lib/docs-drift.ts +222 -0
  72. package/src/lib/format.ts +14 -0
  73. package/src/lib/output.ts +33 -2
  74. package/src/lib/package-manifest.ts +58 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eject.js","sourceRoot":"","sources":["../../../src/commands/eject.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,sFAAsF;AACtF,6FAA6F;AAC7F,wFAAwF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AAwD;YACnF,gBAAgB,CACjB,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe;YAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1D,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,KAAK,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;QAClC,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../src/commands/gen.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAyBrD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,YAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyKzG"}
1
+ {"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../src/commands/gen.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA6BrD,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,YAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CA0KzG"}
@@ -8,6 +8,7 @@ import { log } from "../lib/log.js";
8
8
  import { warnIfAgentContextStale } from "../lib/agent-context-staleness.js";
9
9
  import { warnIfManifestIgnored } from "../lib/manifest-ignored-check.js";
10
10
  import { scanSourceForAntiPatterns } from "../lib/anti-patterns.js";
11
+ import { antiPatternRows, ranSection, skippedSection, warnCapped, } from "../lib/advisory.js";
11
12
  import { loadMemory, resolveCollection } from "@metaobjectsdev/sdk";
12
13
  import { runGen, listGenerators } from "@metaobjectsdev/codegen-ts";
13
14
  function mapStatus(s) {
@@ -143,12 +144,20 @@ export async function genCommand(args, cwd, fmt = "text") {
143
144
  }));
144
145
  const targetDirs = Array.from(new Set((forgeConfig.targets ? Object.values(forgeConfig.targets).map((t) => t.outDir) : [])
145
146
  .concat([forgeConfig.outDir])));
147
+ // The advisory verify-as-teacher pass now runs BEFORE the result is rendered,
148
+ // because its findings ride IN the result. It used to run after the payload was
149
+ // printed and write only to stderr as text, so `meta gen --format json` on a run
150
+ // with hundreds of findings emitted a document that mentioned none of them — the
151
+ // structured output being the documented default for an agent on a pipe.
152
+ // Warnings ONLY — nothing here reaches the exit code (bias to under-flagging).
153
+ const antiPatterns = runAntiPatternScan(projectRoot, cliConfig.dryRun, flags.noAntipatterns, forgeConfig.verify?.antiPatternIgnore);
146
154
  const genResult = {
147
155
  files,
148
156
  outDir: targetDirs.length > 1 ? targetDirs.join(", ") : forgeConfig.outDir,
149
157
  dialect: forgeConfig.dialect,
150
158
  dryRun: cliConfig.dryRun,
151
159
  warnings: [],
160
+ antiPatterns,
152
161
  };
153
162
  const output = fmt === "toon" ? formatGenResultToon(genResult)
154
163
  : fmt === "json" ? formatGenResultJson(genResult)
@@ -163,30 +172,44 @@ export async function genCommand(args, cwd, fmt = "text") {
163
172
  log.warn(`meta gen completed with ${result.conflicts.length} conflict(s). ` +
164
173
  `Resolve and re-run to advance the canonical state.\n${list}`);
165
174
  }
166
- // Advisory verify-as-teacher pass (same as `meta verify`): on a real write run,
167
- // surface authored source that hand-rolls what the metadata could model. `gen`
168
- // is the command an agent always runs, so this is where the teaching actually
169
- // reaches it. Warnings ONLY — never affects the exit code. Suppress with
170
- // --no-antipatterns or META_NO_ANTIPATTERNS=1 (both opt-outs work on `meta gen`
171
- // and `meta verify`).
172
- if (!cliConfig.dryRun && !flags.noAntipatterns && process.env.META_NO_ANTIPATTERNS !== "1") {
173
- try {
174
- const findings = scanSourceForAntiPatterns(projectRoot);
175
- if (findings.length > 0) {
176
- const CAP = 10;
177
- log.warn(`\nmeta gen — ${findings.length} place(s) hand-roll what MetaObjects can model ` +
178
- `(advisory — declaring the construct lets codegen own it):`);
179
- for (const f of findings.slice(0, CAP))
180
- log.warn(` ${f.message}`);
181
- if (findings.length > CAP)
182
- log.warn(` …and ${findings.length - CAP} more.`);
183
- }
184
- }
185
- catch { /* never let an advisory scan break gen */ }
175
+ // The human-readable half of the advisory pass, printed after the file listing
176
+ // where a reader expects it. Capped for a terminal; the structured payload above
177
+ // already carried every finding, and the tail line says so.
178
+ if (antiPatterns.total > 0) {
179
+ log.warn(`\nmeta gen ${antiPatterns.total} place(s) hand-roll what MetaObjects can model ` +
180
+ `(advisory declaring the construct lets codegen own it):`);
181
+ warnCapped(antiPatterns.rows.map((r) => ` ${r.message}`), flags.limit, { structured: fmt !== "text" });
186
182
  }
187
183
  const hasFailure = files.some((f) => f.status === "conflict" || f.status === "refused");
188
184
  return hasFailure ? 1 : 0;
189
185
  }
186
+ /**
187
+ * Run the advisory verify-as-teacher scan (same pass `meta verify` runs): surface
188
+ * authored source that hand-rolls what the metadata could model. `gen` is the
189
+ * command an agent always runs, so this is where the teaching actually reaches it.
190
+ *
191
+ * Returns the section EITHER WAY — a skip is reported with its reason rather than
192
+ * dropped, so a reader can tell "found nothing" from "never looked". Warnings only;
193
+ * it can never affect the exit code. Suppress with --no-antipatterns or
194
+ * META_NO_ANTIPATTERNS=1 (both opt-outs work on `meta gen` and `meta verify`).
195
+ */
196
+ function runAntiPatternScan(projectRoot, dryRun, noAntipatterns, ignore) {
197
+ // A --dry-run writes nothing, so it teaches nothing; the scan is skipped, as it
198
+ // always has been. The payload now says that instead of looking clean.
199
+ if (dryRun)
200
+ return skippedSection("skipped on --dry-run (the advisory pass runs on a real write run)");
201
+ if (noAntipatterns)
202
+ return skippedSection("suppressed by --no-antipatterns");
203
+ if (process.env.META_NO_ANTIPATTERNS === "1")
204
+ return skippedSection("suppressed by META_NO_ANTIPATTERNS=1");
205
+ try {
206
+ return ranSection(antiPatternRows(scanSourceForAntiPatterns(projectRoot, ignore !== undefined ? { ignore } : undefined)));
207
+ }
208
+ catch (err) {
209
+ // Never let an advisory scan break gen — but never claim it found nothing either.
210
+ return skippedSection(`the scan failed: ${err.message}`);
211
+ }
212
+ }
190
213
  /**
191
214
  * `meta gen --list` — print the stable-name generator registry (ADR-0021 D3).
192
215
  *
@@ -1 +1 @@
1
- {"version":3,"file":"gen.js","sourceRoot":"","sources":["../../../src/commands/gen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC5I,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAyC,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGpE,SAAS,SAAS,CAAC,CAAc;IAC/B,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,KAAK,CAAC;QACX,KAAK,WAAW,CAAC,CAAC,OAAO,KAAK,CAAC;QAC/B,KAAK,QAAQ,CAAC,CAAI,OAAO,QAAQ,CAAC;QAClC,KAAK,UAAU,CAAC,CAAE,OAAO,UAAU,CAAC;QACpC,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC,CAAG,O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W,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -1,3 +1,5 @@
1
+ import { type ReferenceGeneratorName } from "@metaobjectsdev/codegen-ts";
2
+ export declare const SCAFFOLDED_GENERATOR_NAMES: readonly ReferenceGeneratorName[];
1
3
  export interface InitOptions {
2
4
  cwd: string;
3
5
  force?: boolean;
@@ -23,9 +25,21 @@ export interface InitOptions {
23
25
  export interface InitResult {
24
26
  created: string[];
25
27
  preserved: string[];
28
+ /** agent-context files deleted because this stack no longer assembles them. */
29
+ removed: string[];
26
30
  warnings: string[];
27
31
  }
28
32
  export declare function init(opts: InitOptions): Promise<InitResult>;
29
- export declare function nextStepsBlock(): string;
33
+ /**
34
+ * The post-init message.
35
+ *
36
+ * @param dbStubWritten whether THIS run wrote {@link DB_STUB_REL_PATH}. Required rather
37
+ * than defaulted, because a default would silently restore the bug this parameter
38
+ * exists to close: the note used to be part of one static string and so claimed the
39
+ * stub on every run, including the `meta init --force` in a project keeping its own
40
+ * `metaobjects.config.ts`, where the stub is deliberately not written. Callers pass
41
+ * `result.created.includes(DB_STUB_REL_PATH)` — the same list the message describes.
42
+ */
43
+ export declare function nextStepsBlock(dbStubWritten: boolean): string;
30
44
  export declare function initCommand(args: string[], cwd: string): Promise<number>;
31
45
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AA8HA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OA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AC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4KAA4K;IAC5K,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,+EAA+E;IAC/E,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AA4RD,wBAAsB,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CA8KjE;AA0KD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,OAAO,GAAG,MAAM,CAE7D;AAoBD,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuD9E"}
@@ -1,4 +1,4 @@
1
- import { mkdir, writeFile, readFile, readdir, stat } from "node:fs/promises";
1
+ import { mkdir, writeFile, readFile, readdir, stat, rm } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { basename, dirname } from "node:path";
4
4
  import { existsSync as existsSyncWrap, readFileSync as readFileSyncWrap } from "node:fs";
@@ -8,11 +8,36 @@ import { resolveStack } from "../lib/detect-stack.js";
8
8
  import { parseInitArgs } from "../lib/args.js";
9
9
  import { log } from "../lib/log.js";
10
10
  import { cliVersion } from "../lib/version.js";
11
+ import { declaredDependencyNames } from "../lib/package-manifest.js";
11
12
  import { findWranglerConfig, parseWranglerConfig } from "@metaobjectsdev/migrate-ts";
12
- import { readReferenceTemplate, REFERENCE_GENERATOR_NAMES } from "@metaobjectsdev/codegen-ts";
13
+ import { readReferenceTemplate } from "@metaobjectsdev/codegen-ts";
13
14
  // ADR-0034 scaffold-and-own — `meta init` copies the codegen reference templates into
14
15
  // the consumer's repo so they OWN them; metaobjects.config.ts imports them locally.
15
16
  const OWNED_GENERATORS_DIR = "codegen/generators";
17
+ // The FIVE reference generators `meta init` copies EAGERLY — deliberately an explicit
18
+ // literal, not derived from @metaobjectsdev/codegen-ts's REFERENCE_GENERATOR_NAMES (the
19
+ // full list of everything `meta eject` can copy). Looping over that array unconditionally
20
+ // used to mean init scaffolded whatever it contained: when a later task registered
21
+ // "routes-hono" there, init started writing an unwired Hono generator nothing in the
22
+ // scaffolded config imports, on every fresh project, silently. This constant is the
23
+ // scaffolded metaobjects.config.ts's import list (buildMetaobjectsConfigBody below) made
24
+ // explicit and checkable — anything else is eject-on-demand via `meta eject <name>`, which
25
+ // exists exactly so eager copying isn't the only way to take ownership of a template.
26
+ //
27
+ // "names" joined this list by spec §A5's ruling, not by falling out of the general rule
28
+ // above: TypeScript is opt-in by construction under ADR-0034 (meta gen runs the adopter's
29
+ // copy, so a packaged change to a generator can never reach anyone who has ejected), so
30
+ // the honest maximum for the names artifact is every NEW `meta init` getting it and every
31
+ // existing project adding one config line by hand.
32
+ export const SCAFFOLDED_GENERATOR_NAMES = ["entity", "queries", "routes", "barrel", "names"];
33
+ // The scaffolded config's outDir + dbImport, as named constants so the throwing-stub
34
+ // path below is DERIVED from the same values the config template embeds rather than
35
+ // duplicated as a second literal that could drift from it.
36
+ const SCAFFOLD_OUT_DIR = "src/generated";
37
+ const SCAFFOLD_DB_IMPORT = "../db";
38
+ // "src/generated" + "../db" -> "src/db" -> "src/db.ts" (dbImport resolves relative
39
+ // to outDir, same as the module specifier a generated route file emits).
40
+ const DB_STUB_REL_PATH = `${join(SCAFFOLD_OUT_DIR, SCAFFOLD_DB_IMPORT)}.ts`;
16
41
  const META_COMMON_JSON = JSON.stringify({
17
42
  metadata: {
18
43
  package: "",
@@ -72,18 +97,29 @@ function buildMetaobjectsConfigBody(dialect = "sqlite") {
72
97
  import { entityFile } from "./codegen/generators/entity.js";
73
98
  import { queriesFile } from "./codegen/generators/queries.js";
74
99
  import { routesFile } from "./codegen/generators/routes.js";
100
+ import { namesFile } from "./codegen/generators/names.js";
75
101
  import { barrel } from "./codegen/generators/barrel.js";
76
102
 
77
103
  export default defineConfig({
78
- outDir: "src/generated",
79
- extStyle: "js", // ".js"-extensioned relative imports — safe under Node ESM / tsc nodenext AND bundlers
80
- dbImport: "../db",
104
+ outDir: "${SCAFFOLD_OUT_DIR}",
105
+ extStyle: "js", // ".js"-extensioned relative imports — correct for Node ESM and \`tsc\` with
106
+ // nodenext, which is what a fresh project has. BUNDLERS DISAGREE: this fails
107
+ // outright under Turbopack (even between two generated files, so the whole
108
+ // generated tree goes unresolvable), while Vite and esbuild accept it and
109
+ // webpack needs \`resolve.extensionAlias\`. If a generated import fails to
110
+ // resolve, set "none" and retest — do not assume this line covers your bundler.
111
+ dbImport: "${SCAFFOLD_DB_IMPORT}", // routesFile() below emits \`import { db } from …\` — meta init
112
+ // scaffolded ${DB_STUB_REL_PATH} as a THROWING STUB (types clean, no
113
+ // driver chosen) so meta gen and tsc pass; replace it with your real
114
+ // Drizzle connection before running the app.
115
+ // (queriesFile() takes db as a parameter and never reads this.)
81
116
  dialect: "${dialect}",
82
117
  apiPrefix: "", // set to "/api" if your routes mount under /api
83
118
  generators: [
84
119
  entityFile(),
85
120
  queriesFile(),
86
121
  routesFile(),
122
+ namesFile(), // <Entity>Names — physical table/column constants (spec §A1/§A5)
87
123
  barrel(),
88
124
  ],
89
125
  docs: {
@@ -94,10 +130,73 @@ export default defineConfig({
94
130
  });
95
131
  `;
96
132
  }
97
- const NEXT_STEPS = `
133
+ // The throwing-stub scaffolded at `dbImport`'s resolved path (DB_STUB_REL_PATH,
134
+ // "src/db.ts" by default). It exists so `meta gen` and a fresh project's FIRST
135
+ // `tsc` both succeed with no driver chosen and no dependency added — deliberately
136
+ // NOT a real connection. Every generated route only ever passes `db` straight
137
+ // through to `mountCrudRoutes(...)`; nothing reads a property off it at import
138
+ // time, so a value typed `unknown` (not `any`) satisfies every call site while
139
+ // making a genuine runtime use (mountCrudRoutes calling `db.select()` etc.) throw
140
+ // immediately with an actionable message instead of failing to resolve at all.
141
+ // Built as an array of plain single-quoted lines (not a template literal) so the
142
+ // backticks and quotes inside the comment/message need no escaping.
143
+ const DB_STUB_BODY = [
144
+ "// `meta init` scaffolded this file because the generated Fastify routes",
145
+ '// `import { db } from "../db.js"` (see `dbImport` in metaobjects.config.ts) —',
146
+ "// a module that has to exist for `meta gen` and `tsc` to succeed. MetaObjects",
147
+ "// cannot fill it in for real without choosing a database driver on your",
148
+ "// behalf (better-sqlite3 vs @libsql/client vs pg vs postgres.js) and adding a",
149
+ "// dependency you may not want, so this is a STUB, not a connection.",
150
+ "//",
151
+ "// It type-checks and satisfies every generated import, but throws the first",
152
+ "// time anything actually touches `db` at runtime. Replace the export below",
153
+ "// with your real Drizzle connection, e.g.:",
154
+ "//",
155
+ '// import { drizzle } from "drizzle-orm/better-sqlite3";',
156
+ '// import Database from "better-sqlite3";',
157
+ '// export const db = drizzle(new Database("dev.sqlite"));',
158
+ "//",
159
+ "// (swap the driver import for your dialect — see",
160
+ "// https://github.com/metaobjectsdev/metaobjects/blob/main/docs/recipes/wiring-generated-queries.md",
161
+ "// for SQLite/libsql, Cloudflare D1, Postgres and multi-tenant setups.)",
162
+ "",
163
+ "const UNWIRED_MESSAGE =",
164
+ ' "src/db.ts is still the scaffolded stub meta init wrote — it cannot choose " +',
165
+ " \"a database driver for you. Replace 'export const db = ...' below with \" +",
166
+ ' "your real Drizzle connection, e.g.:\\n\\n" +',
167
+ " \" import { drizzle } from 'drizzle-orm/better-sqlite3';\\n\" +",
168
+ " \" import Database from 'better-sqlite3';\\n\" +",
169
+ " \" export const db = drizzle(new Database('dev.sqlite'));\\n\";",
170
+ "",
171
+ "function unwired(): never {",
172
+ " throw new Error(UNWIRED_MESSAGE);",
173
+ "}",
174
+ "",
175
+ "/**",
176
+ " * Stand-in for your real Drizzle database connection. Generated code only",
177
+ " * ever passes `db` straight through to `mountCrudRoutes(...)` — it never",
178
+ " * reads a property off it at import time — so this typechecks everywhere",
179
+ " * `db` is used, and throws the message above the first time anything really",
180
+ " * touches it.",
181
+ " */",
182
+ "export const db: unknown = new Proxy({}, { get: unwired });",
183
+ "",
184
+ ].join("\n");
185
+ // Printed only when the stub was ACTUALLY written this run. It is gated on having just
186
+ // written the scaffolded config (see the db-stub block in `init`), so a re-run in a
187
+ // project that keeps its own config writes nothing — and a block claiming otherwise is
188
+ // the same "asserting things about its own scaffold that aren't true" defect the rest of
189
+ // this file was corrected for.
190
+ const DB_STUB_NOTE = `Also scaffolded ${DB_STUB_REL_PATH}: a THROWING STUB standing in for your database
191
+ connection, so the generated routes' \`db\` import resolves and the first tsc is clean.
192
+ Replace it with a real connection before running the app — until you do, the first
193
+ request that touches \`db\` throws with instructions.
194
+ `;
195
+ const SCAFFOLD_SUMMARY = `
98
196
  Initialized metaobjects/ + .metaobjects/ + metaobjects.config.ts
99
197
  Codegen generators copied to codegen/generators/ — they're YOURS to edit (ADR-0034 scaffold-and-own).
100
-
198
+ `;
199
+ const NEXT_STEPS = `
101
200
  Next steps:
102
201
  0. Everything here is ESM — package.json needs "type": "module" (init sets it
103
202
  unless the project has CommonJS sources; without it the first tsc fails).
@@ -189,6 +288,12 @@ async function writeUnlessDryRun(cwd, dryRun, path, contents) {
189
288
  await mkdir(dirname(abs), { recursive: true });
190
289
  await writeFile(abs, contents, "utf8");
191
290
  }
291
+ /** Delete twin of writeUnlessDryRun — a dry run must not remove anything either. */
292
+ async function removeUnlessDryRun(cwd, dryRun, path) {
293
+ if (dryRun)
294
+ return;
295
+ await rm(join(cwd, path), { force: true });
296
+ }
192
297
  /** "would be VERBED" during a dry run, plain VERBED otherwise — the one tense
193
298
  * marker every reported write shares, so each call site states only its own
194
299
  * past participle instead of writing out both tenses of the whole sentence. */
@@ -242,8 +347,19 @@ async function writeAgentContext(opts, result) {
242
347
  }
243
348
  await writeUnlessDryRun(opts.cwd, dryRun, AGENT_CONTEXT_MANIFEST_PATH, JSON.stringify(decision.manifest, null, 2) + "\n");
244
349
  result.created.push(AGENT_CONTEXT_MANIFEST_PATH);
350
+ // A fragment this stack no longer assembles. `prunes` are ones we wrote that nobody has
351
+ // touched — deleting is exactly as safe as the overwrite the same hash predicate already
352
+ // authorises above, and leaving them contradicts every SKILL.md footer, which tells the
353
+ // reader to read every references/*.md "one per server language in this project's stack".
354
+ for (const orphan of decision.prunes) {
355
+ await removeUnlessDryRun(opts.cwd, dryRun, orphan);
356
+ result.removed.push(orphan);
357
+ }
358
+ // Hand-edited ones are never deleted — losing an adopter's writing is worse than leaving
359
+ // a stale file behind — so they are named, with the reason and the remedy.
245
360
  for (const orphan of decision.removed) {
246
- result.warnings.push(`${orphan} is no longer part of this stack; orphaned (safe to delete).`);
361
+ result.warnings.push(`${orphan} is no longer part of this stack but appears hand-edited, so it was kept; ` +
362
+ "delete it yourself once you have salvaged anything you want from it.");
247
363
  }
248
364
  if (opts.wireRoot)
249
365
  await wireRootMemory(opts.cwd, result, dryRun);
@@ -279,11 +395,16 @@ async function wireRootMemory(cwd, result, dryRun = false) {
279
395
  * `codegen/generators/<name>.ts` so they own them. Each file is written only if absent,
280
396
  * so a re-run with --force never clobbers a hand-edited generator. The scaffolded
281
397
  * metaobjects.config.ts imports these local copies (not the package `/generators` export).
398
+ *
399
+ * Copies SCAFFOLDED_GENERATOR_NAMES only — the five the scaffolded config actually
400
+ * wires — not every name @metaobjectsdev/codegen-ts happens to register. Anything else
401
+ * (routes-hono, and any UI-tier template from codegen-ts-react/-tanstack) is reached with
402
+ * `meta eject <name>`, not by eager copying.
282
403
  */
283
404
  async function writeOwnedGenerators(opts, result) {
284
405
  const dir = join(opts.cwd, OWNED_GENERATORS_DIR);
285
406
  await mkdir(dir, { recursive: true });
286
- for (const name of REFERENCE_GENERATOR_NAMES) {
407
+ for (const name of SCAFFOLDED_GENERATOR_NAMES) {
287
408
  const rel = `${OWNED_GENERATORS_DIR}/${name}.ts`;
288
409
  const abs = join(dir, `${name}.ts`);
289
410
  if (await fileExists(abs)) {
@@ -355,7 +476,7 @@ async function writeConfigFile(opts, result, agentDir, agentDirExists) {
355
476
  }
356
477
  }
357
478
  export async function init(opts) {
358
- const result = { created: [], preserved: [], warnings: [] };
479
+ const result = { created: [], preserved: [], removed: [], warnings: [] };
359
480
  const agentDir = join(opts.cwd, DEFAULT_METAOBJECTS_DIR);
360
481
  const metaobjectsDir = join(opts.cwd, DEFAULT_METADATA_DIR);
361
482
  const agentDirExists = await dirExists(agentDir);
@@ -405,9 +526,9 @@ export async function init(opts) {
405
526
  result.created.push(d);
406
527
  result.created.push("metaobjects/meta.common.json", ".metaobjects/config.json", ".metaobjects/.gitignore", `.metaobjects/${PACKAGE_MANIFEST_FILE}`);
407
528
  result.created.push(".metaobjects/AGENTS.md", ".metaobjects/CLAUDE.md", ".claude/skills/metaobjects-*", AGENT_CONTEXT_MANIFEST_PATH);
408
- for (const name of REFERENCE_GENERATOR_NAMES)
529
+ for (const name of SCAFFOLDED_GENERATOR_NAMES)
409
530
  result.created.push(`${OWNED_GENERATORS_DIR}/${name}.ts`);
410
- result.created.push("metaobjects.config.ts", ".gitignore");
531
+ result.created.push("metaobjects.config.ts", DB_STUB_REL_PATH, ".gitignore");
411
532
  return result;
412
533
  }
413
534
  for (const d of dirs) {
@@ -450,10 +571,52 @@ export async function init(opts) {
450
571
  await writeOwnedGenerators(opts, result);
451
572
  // Scaffold metaobjects.config.ts at the project root. Never overwrite if it exists.
452
573
  const forgeConfigPath = join(opts.cwd, "metaobjects.config.ts");
453
- if (!(await fileExists(forgeConfigPath))) {
574
+ const wroteScaffoldedConfig = !(await fileExists(forgeConfigPath));
575
+ if (wroteScaffoldedConfig) {
454
576
  await writeFile(forgeConfigPath, buildMetaobjectsConfigBody(opts.d1 ? "d1" : "sqlite"), "utf8");
455
577
  result.created.push("metaobjects.config.ts");
456
578
  }
579
+ // Scaffold the `dbImport` throwing stub at DB_STUB_REL_PATH ("src/db.ts" by
580
+ // default) — ONLY if absent, so a re-run never clobbers a user's real db module
581
+ // (same "write once" precedent as writeOwnedGenerators above). Without this, the
582
+ // scaffolded config declares `dbImport: "../db"` pointing at a module `meta init`
583
+ // never creates, and a fresh project's FIRST `tsc` fails to resolve it.
584
+ //
585
+ // Gated on having just WRITTEN that config, not merely on the stub being absent.
586
+ // DB_STUB_REL_PATH is derived from SCAFFOLD_OUT_DIR + SCAFFOLD_DB_IMPORT — the
587
+ // scaffold's own constants — so it describes where the SCAFFOLDED config points and
588
+ // nowhere else. Re-running `meta init` in a project that already has a config with
589
+ // its own `outDir`/`dbImport` preserves that config (above) and would otherwise still
590
+ // drop a src/db.ts that nothing in the project references: a stray file, in the
591
+ // adopter's application source, answering a question they had already answered.
592
+ const dbStubPath = join(opts.cwd, DB_STUB_REL_PATH);
593
+ const dbStubExists = await fileExists(dbStubPath);
594
+ if (wroteScaffoldedConfig && !dbStubExists) {
595
+ await mkdir(dirname(dbStubPath), { recursive: true });
596
+ await writeFile(dbStubPath, DB_STUB_BODY, "utf8");
597
+ result.created.push(DB_STUB_REL_PATH);
598
+ }
599
+ else if (dbStubExists) {
600
+ // "preserved" means a file we would have written was left alone. Skipping because
601
+ // this project keeps its own config is not preservation — there is nothing there.
602
+ result.preserved.push(DB_STUB_REL_PATH);
603
+ }
604
+ else {
605
+ // Neither written nor preserved: this project keeps its own config AND has no stub.
606
+ // Usually correct — its `dbImport` points at a real module somewhere else. But it is
607
+ // ALSO what a scaffolded project looks like after someone deletes or moves src/db.ts,
608
+ // and `meta init --force` cannot tell those apart: `wroteScaffoldedConfig` is only
609
+ // "no config existed", so it is false for the config init itself wrote. Silently
610
+ // doing nothing there leaves the scaffolded `dbImport: "../db"` and the generated
611
+ // routes' `import { db } from "../db.js"` pointing at nothing, and the adopter meets
612
+ // it as a TS2307 from `tsc` with no word from the command that could have said so.
613
+ // Say it here rather than writing: dropping a file into a project that owns its
614
+ // config is what the branch above deliberately refuses.
615
+ result.warnings.push(`${DB_STUB_REL_PATH} was not scaffolded — this project has its own ` +
616
+ "metaobjects.config.ts, so init leaves the database module to it. If that config's " +
617
+ `\`dbImport\` resolves to ${DB_STUB_REL_PATH}, create it or the generated routes will ` +
618
+ "not resolve.");
619
+ }
457
620
  // Scaffold a minimal root .gitignore ONLY when the project has none — never
458
621
  // clobber a user's existing one (they may have their own rules).
459
622
  const rootGitignorePath = join(opts.cwd, ".gitignore");
@@ -513,6 +676,7 @@ async function ensureEsmPackageType(cwd, result) {
513
676
  "code in a sub-directory with its own package.json declaring `\"type\": \"module\"`.");
514
677
  return;
515
678
  }
679
+ const declaredType = pkg.type; // read BEFORE the mutation below overwrites it
516
680
  pkg.type = "module";
517
681
  const added = addScaffoldDevDependencies(pkg);
518
682
  // Preserve the file's existing indentation rather than reformatting someone's manifest.
@@ -521,8 +685,15 @@ async function ensureEsmPackageType(cwd, result) {
521
685
  // Past tense, deliberately: this reports an edit already made. The imperative
522
686
  // ("set `\"type\": \"module\"`") read as a TODO on the one line a newcomer sees
523
687
  // last, so a scaffold that had just done the right thing looked like it had failed.
524
- result.warnings.push('package.json declared no module system — set `"type": "module"` for you, because ' +
525
- "MetaObjects scaffolds and generates ESM, which a CommonJS project cannot compile.");
688
+ //
689
+ // And it must not claim the manifest was SILENT on the point: `npm init -y` writes
690
+ // `"type": "commonjs"` explicitly (npm 11.x), which is the dominant first-touch path,
691
+ // so "declared no module system" was false exactly where it is read most. Report what
692
+ // was actually there.
693
+ const previous = typeof declaredType === "string" ? declaredType : undefined;
694
+ result.warnings.push(`package.json ${previous === undefined ? "declared no module system" : `declared "type": "${previous}"`} — ` +
695
+ 'set `"type": "module"` for you, because MetaObjects scaffolds and generates ESM, ' +
696
+ "which a CommonJS project cannot compile.");
526
697
  if (added.length > 0) {
527
698
  result.warnings.push(`added ${added.join(" + ")} to devDependencies — the scaffolded ` +
528
699
  "codegen/generators/ are YOUR source now (ADR-0034) and import them. " +
@@ -553,10 +724,17 @@ function addScaffoldDevDependencies(pkg) {
553
724
  "@metaobjectsdev/metadata": `^${version}`,
554
725
  };
555
726
  const dev = (pkg.devDependencies ?? {});
556
- const deps = (pkg.dependencies ?? {});
727
+ // "Already declared" spans all four dependency fields — the shared rule, so this
728
+ // cannot drift from what `meta eject` means by the same words. It used to ask only
729
+ // dependencies + devDependencies, which meant a project declaring codegen-ts as a
730
+ // PEER dependency (correct for a library whose consumer supplies the version) got it
731
+ // added to devDependencies as well: the same package pinned twice in one manifest,
732
+ // and a second physical copy is the class-identity split this repo has been bitten
733
+ // by twice.
734
+ const declared = declaredDependencyNames(pkg);
557
735
  const added = [];
558
736
  for (const [name, range] of Object.entries(wanted)) {
559
- if (dev[name] !== undefined || deps[name] !== undefined)
737
+ if (declared.has(name))
560
738
  continue;
561
739
  dev[name] = range;
562
740
  added.push(name);
@@ -619,8 +797,18 @@ function buildD1MigrateBlock(cwd) {
619
797
  }
620
798
  return block;
621
799
  }
622
- export function nextStepsBlock() {
623
- return NEXT_STEPS;
800
+ /**
801
+ * The post-init message.
802
+ *
803
+ * @param dbStubWritten whether THIS run wrote {@link DB_STUB_REL_PATH}. Required rather
804
+ * than defaulted, because a default would silently restore the bug this parameter
805
+ * exists to close: the note used to be part of one static string and so claimed the
806
+ * stub on every run, including the `meta init --force` in a project keeping its own
807
+ * `metaobjects.config.ts`, where the stub is deliberately not written. Callers pass
808
+ * `result.created.includes(DB_STUB_REL_PATH)` — the same list the message describes.
809
+ */
810
+ export function nextStepsBlock(dbStubWritten) {
811
+ return SCAFFOLD_SUMMARY + (dbStubWritten ? DB_STUB_NOTE : "") + NEXT_STEPS;
624
812
  }
625
813
  async function dirExists(p) {
626
814
  try {
@@ -688,7 +876,7 @@ export async function initCommand(args, cwd) {
688
876
  log.warn(w);
689
877
  }
690
878
  else {
691
- log.info(nextStepsBlock());
879
+ log.info(nextStepsBlock(result.created.includes(DB_STUB_REL_PATH)));
692
880
  // Surface any scaffold warnings (e.g. the #77 monorepo-subdir agent-context
693
881
  // discovery warning) — these are otherwise dropped on the normal init path.
694
882
  for (const w of result.warnings)