@intelligo-dev/cli 1.0.0-beta.1 → 1.0.0-beta.13

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 (103) hide show
  1. package/NOTICE +6 -0
  2. package/README.md +63 -0
  3. package/dist/bin.js +85 -37
  4. package/dist/bin.js.map +1 -1
  5. package/dist/commands/add.d.ts +22 -1
  6. package/dist/commands/add.d.ts.map +1 -1
  7. package/dist/commands/add.js +61 -4
  8. package/dist/commands/add.js.map +1 -1
  9. package/dist/commands/create-flow.d.ts +34 -0
  10. package/dist/commands/create-flow.d.ts.map +1 -0
  11. package/dist/commands/create-flow.js +180 -0
  12. package/dist/commands/create-flow.js.map +1 -0
  13. package/dist/commands/create.d.ts +23 -6
  14. package/dist/commands/create.d.ts.map +1 -1
  15. package/dist/commands/create.js +45 -13
  16. package/dist/commands/create.js.map +1 -1
  17. package/dist/commands/doctor.d.ts +14 -3
  18. package/dist/commands/doctor.d.ts.map +1 -1
  19. package/dist/commands/doctor.js +293 -37
  20. package/dist/commands/doctor.js.map +1 -1
  21. package/dist/commands/migrate-check.d.ts +54 -1
  22. package/dist/commands/migrate-check.d.ts.map +1 -1
  23. package/dist/commands/migrate-check.js +101 -5
  24. package/dist/commands/migrate-check.js.map +1 -1
  25. package/dist/commands/migrate.d.ts +97 -0
  26. package/dist/commands/migrate.d.ts.map +1 -0
  27. package/dist/commands/migrate.js +147 -0
  28. package/dist/commands/migrate.js.map +1 -0
  29. package/dist/commands/upgrade-check.d.ts +5 -5
  30. package/dist/commands/upgrade-check.d.ts.map +1 -1
  31. package/dist/commands/upgrade-check.js +19 -6
  32. package/dist/commands/upgrade-check.js.map +1 -1
  33. package/dist/env-files.d.ts +12 -0
  34. package/dist/env-files.d.ts.map +1 -0
  35. package/dist/env-files.js +29 -0
  36. package/dist/env-files.js.map +1 -0
  37. package/dist/index.d.ts +9 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +9 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/manifest.d.ts +9 -15
  42. package/dist/manifest.d.ts.map +1 -1
  43. package/dist/manifest.js +5 -16
  44. package/dist/manifest.js.map +1 -1
  45. package/dist/migrations.d.ts +3 -6
  46. package/dist/migrations.d.ts.map +1 -1
  47. package/dist/migrations.js +3 -6
  48. package/dist/migrations.js.map +1 -1
  49. package/dist/model-catalogue.d.ts +14 -0
  50. package/dist/model-catalogue.d.ts.map +1 -0
  51. package/dist/model-catalogue.js +34 -0
  52. package/dist/model-catalogue.js.map +1 -0
  53. package/dist/registry-items.d.ts +56 -0
  54. package/dist/registry-items.d.ts.map +1 -0
  55. package/dist/registry-items.js +103 -0
  56. package/dist/registry-items.js.map +1 -0
  57. package/package.json +36 -10
  58. package/src/bin.ts +264 -0
  59. package/src/commands/add.ts +244 -0
  60. package/src/commands/create-flow.ts +228 -0
  61. package/src/commands/create.ts +139 -0
  62. package/src/commands/doctor.ts +487 -0
  63. package/src/commands/migrate-check.ts +257 -0
  64. package/src/commands/migrate.ts +234 -0
  65. package/src/commands/upgrade-check.ts +157 -0
  66. package/src/env-files.ts +31 -0
  67. package/src/index.ts +39 -0
  68. package/src/manifest.ts +93 -0
  69. package/src/migrations-dir.ts +25 -0
  70. package/src/migrations.ts +133 -0
  71. package/src/model-catalogue.ts +35 -0
  72. package/src/registry-items.ts +132 -0
  73. package/templates/admin-page/admin-page.tsx.tpl +2 -3
  74. package/templates/app-scaffold/assistant-route.ts.tpl +2 -2
  75. package/templates/app-scaffold/auth-route.ts.tpl +10 -0
  76. package/templates/app-scaffold/components.json.tpl +6 -2
  77. package/templates/app-scaffold/db-schema.ts.tpl +29 -0
  78. package/templates/app-scaffold/drizzle-journal.json.tpl +5 -0
  79. package/templates/app-scaffold/drizzle.config.ts.tpl +45 -0
  80. package/templates/app-scaffold/env.example.tpl +65 -1
  81. package/templates/app-scaffold/globals.css.tpl +172 -281
  82. package/templates/app-scaffold/i18n-request.ts.tpl +25 -0
  83. package/templates/app-scaffold/instrumentation.ts.tpl +21 -0
  84. package/templates/app-scaffold/intelligo.ts.tpl +104 -9
  85. package/templates/app-scaffold/layout.tsx.tpl +18 -1
  86. package/templates/app-scaffold/lib-utils.ts.tpl +1 -6
  87. package/templates/app-scaffold/next.config.mjs.tpl +2 -0
  88. package/templates/app-scaffold/package.json.tpl +31 -17
  89. package/templates/app-scaffold/page.tsx.tpl +16 -0
  90. package/templates/app-scaffold/plans.ts.tpl +32 -13
  91. package/templates/app-scaffold/{middleware.ts.tpl → proxy.ts.tpl} +6 -0
  92. package/templates/app-scaffold/sonner.tsx.tpl +42 -20
  93. package/templates/app-scaffold/stripe-webhook-route.ts.tpl +24 -0
  94. package/templates/app-scaffold/theme-provider.tsx.tpl +6 -4
  95. package/templates/app-scaffold/tsconfig.json.tpl +20 -4
  96. package/templates/app-scaffold/use-mobile.ts.tpl +19 -0
  97. package/templates/app-scaffold/workspace-bootstrap.ts.tpl +30 -0
  98. package/templates/maintenance/maintenance-route.ts.tpl +119 -0
  99. package/templates/manifest.json +57 -18
  100. package/templates/registry-items.json +116 -0
  101. package/templates/registry-requires.json +156 -0
  102. package/templates/usage-page/usage-page.tsx.tpl +23 -8
  103. package/templates/billing-page/billing-page.tsx.tpl +0 -72
@@ -1,27 +1,206 @@
1
1
  /**
2
2
  * `intelligo doctor` — report the problems that are invisible until
3
3
  * they are an incident.
4
- *
5
- * The checks here were each chosen because something in this codebase
6
- * actually went wrong that way, not because they sounded thorough.
7
4
  */
8
5
  import path from "node:path";
9
- import { existsSync } from "node:fs";
6
+ import { fileURLToPath } from "node:url";
7
+ import { existsSync, readFileSync } from "node:fs";
8
+ import { parseEnv } from "node:util";
10
9
  import { inspectMigrationChain, readMigrationChain } from "../migrations.js";
11
10
  import { readManifest } from "../manifest.js";
11
+ import { MODEL_CATALOGUE_LOCATIONS, readCatalogueModelIds, } from "../model-catalogue.js";
12
12
  import { MIGRATION_LOCATIONS, resolveMigrationsDir, } from "../migrations-dir.js";
13
+ /**
14
+ * Block and line comments removed, so a check cannot be satisfied — or
15
+ * defeated — by prose. The composition root's own doc comment names
16
+ * `registerModels` in several of the templates.
17
+ */
18
+ function stripComments(text) {
19
+ return text
20
+ .replace(/\/\*[\s\S]*?\*\//g, "")
21
+ .replace(/(^|[^:])\/\/.*$/gm, "$1");
22
+ }
23
+ /**
24
+ * templates/registry-requires.json is a build-time copy of
25
+ * packages/registry/requires.json (scripts/sync-registry-requires.mjs),
26
+ * committed so that running from source works too, and shipped so
27
+ * doctor can check an installed app without a registry checkout.
28
+ * `../../templates` resolves from src/ and from dist/commands/ alike.
29
+ */
30
+ function bundledRequires() {
31
+ const file = path.resolve(
32
+ // fileURLToPath, not `.pathname` — see the note in bin.ts.
33
+ path.dirname(fileURLToPath(import.meta.url)), "..", "..", "templates", "registry-requires.json");
34
+ if (!existsSync(file))
35
+ return null;
36
+ return JSON.parse(readFileSync(file, "utf8"));
37
+ }
13
38
  /** Variables the app cannot boot without. */
14
39
  const REQUIRED_ENV = [
15
40
  "DATABASE_URL",
16
41
  "BETTER_AUTH_SECRET",
17
42
  "NEXT_PUBLIC_APP_URL",
18
43
  ];
44
+ /** The app's `assertEnv` refuses a shorter BETTER_AUTH_SECRET. */
45
+ const MIN_AUTH_SECRET_LENGTH = 32;
46
+ /** Env files Next.js reads only for a production build or server. */
47
+ const PRODUCTION_ENV_FILES = [".env.production.local", ".env.production"];
48
+ const LOCAL_URL = /^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::|\/|$)/;
49
+ /**
50
+ * Where a production deployment would get a NEXT_PUBLIC_APP_URL that
51
+ * points at this machine: the environment itself when it says
52
+ * production, or a production env file in the app.
53
+ */
54
+ function localAppUrlInProduction(root, env) {
55
+ if (env.NODE_ENV === "production" &&
56
+ LOCAL_URL.test(env.NEXT_PUBLIC_APP_URL ?? "")) {
57
+ return "NODE_ENV=production";
58
+ }
59
+ for (const name of PRODUCTION_ENV_FILES) {
60
+ const file = path.join(root, name);
61
+ if (!existsSync(file))
62
+ continue;
63
+ const url = parseEnv(readFileSync(file, "utf8")).NEXT_PUBLIC_APP_URL;
64
+ if (url && LOCAL_URL.test(url))
65
+ return name;
66
+ }
67
+ return null;
68
+ }
69
+ /** Files of the chat items that name the models a deployment runs on. */
70
+ const MODEL_ID_FILES = [
71
+ "lib/chat-model.ts",
72
+ "lib/chat-models.ts",
73
+ "lib/chat-server-config.ts",
74
+ ];
75
+ /** A provider-prefixed model id literal, in any of the three quote styles. */
76
+ const MODEL_ID = /["'`]((?:openai|anthropic|google|xai|mistral|meta)\/[a-z0-9._-]+)["'`]/g;
77
+ /** `id: "provider/model"` — a model registered by a literal. */
78
+ const REGISTERED_ID = /\bid:\s*["'`]([a-z0-9-]+\/[a-z0-9._-]+)["'`]/g;
79
+ /**
80
+ * Required environment: present, and strong enough that the app's own
81
+ * startup validation will accept it.
82
+ */
83
+ function checkEnvironment(root, env) {
84
+ const results = [];
85
+ const missing = REQUIRED_ENV.filter((k) => !env[k]);
86
+ const authSecret = env.BETTER_AUTH_SECRET ?? "";
87
+ const weakSecret = authSecret.length > 0 && authSecret.length < MIN_AUTH_SECRET_LENGTH;
88
+ if (missing.length > 0) {
89
+ results.push({
90
+ name: "env",
91
+ status: "error",
92
+ detail: `Missing: ${missing.join(", ")}`,
93
+ });
94
+ }
95
+ if (weakSecret) {
96
+ results.push({
97
+ name: "env",
98
+ status: "error",
99
+ detail: `BETTER_AUTH_SECRET is ${authSecret.length} chars — the app refuses to ` +
100
+ `boot with fewer than ${MIN_AUTH_SECRET_LENGTH}. Generate one with: ` +
101
+ "openssl rand -base64 32",
102
+ });
103
+ }
104
+ if (missing.length === 0 && !weakSecret) {
105
+ results.push({
106
+ name: "env",
107
+ status: "ok",
108
+ detail: `${REQUIRED_ENV.length} required variables present`,
109
+ });
110
+ }
111
+ const localUrlSource = localAppUrlInProduction(root, env);
112
+ if (localUrlSource) {
113
+ results.push({
114
+ name: "env",
115
+ status: "warn",
116
+ detail: `NEXT_PUBLIC_APP_URL points at localhost (${localUrlSource}) — auth ` +
117
+ "callbacks and email links are built from it; production needs the " +
118
+ "public https URL",
119
+ });
120
+ }
121
+ return results;
122
+ }
123
+ /**
124
+ * Model ids. A registered catalogue still refuses an id it does not
125
+ * hold, so a typo in the chat seam is a refused first turn. Every
126
+ * provider-prefixed literal there must be in DEFAULT_MODELS (when the
127
+ * root registers it) or registered by a literal `id` in the root.
128
+ */
129
+ function checkModelIds(root, source) {
130
+ const used = new Map();
131
+ for (const rel of MODEL_ID_FILES) {
132
+ const file = path.join(root, rel);
133
+ if (!existsSync(file))
134
+ continue;
135
+ const text = stripComments(readFileSync(file, "utf8"));
136
+ for (const match of text.matchAll(MODEL_ID)) {
137
+ if (!used.has(match[1]))
138
+ used.set(match[1], rel);
139
+ }
140
+ }
141
+ if (used.size === 0)
142
+ return [];
143
+ const code = stripComments(source);
144
+ const known = new Set([...code.matchAll(REGISTERED_ID)].map((m) => m[1]));
145
+ const usesCatalogue = /\bDEFAULT_MODELS\b/.test(code);
146
+ const catalogue = usesCatalogue ? readCatalogueModelIds(root) : null;
147
+ for (const id of catalogue ?? [])
148
+ known.add(id);
149
+ const unknown = [...used].filter(([id]) => !known.has(id));
150
+ const listed = unknown.map(([id, rel]) => `${id} (${rel})`).join(", ");
151
+ if (unknown.length === 0) {
152
+ return [
153
+ {
154
+ name: "model-ids",
155
+ status: "ok",
156
+ detail: `${used.size} model id(s) in the chat seam, all registered`,
157
+ },
158
+ ];
159
+ }
160
+ else if (usesCatalogue && !catalogue) {
161
+ return [
162
+ {
163
+ name: "model-ids",
164
+ status: "warn",
165
+ detail: `cannot read DEFAULT_MODELS (looked in ${MODEL_CATALOGUE_LOCATIONS.join(", ")}) ` +
166
+ `to check ${listed} — is @intelligo-dev/executions installed?`,
167
+ },
168
+ ];
169
+ }
170
+ else if (OPAQUE_REGISTRATION.test(code)) {
171
+ return [
172
+ {
173
+ name: "model-ids",
174
+ status: "warn",
175
+ detail: `${listed} not found in DEFAULT_MODELS or a literal registerModel({ id }) — ` +
176
+ "the composition root registers a catalogue defined elsewhere, " +
177
+ "so confirm it holds them",
178
+ },
179
+ ];
180
+ }
181
+ else {
182
+ return [
183
+ {
184
+ name: "model-ids",
185
+ status: "error",
186
+ detail: `${listed} not registered — admission refuses an unpriced model ` +
187
+ "with `unknown_model`. Fix the id, or add " +
188
+ "`registerModel({ id, … })` to the composition root",
189
+ },
190
+ ];
191
+ }
192
+ }
193
+ /**
194
+ * A `registerModel(s)` argument that is neither a literal nor
195
+ * `DEFAULT_MODELS`: a catalogue defined in another module, whose ids
196
+ * cannot be read from the composition root.
197
+ */
198
+ const OPAQUE_REGISTRATION = /\bregisterModels?\s*\(\s*(?![\s[{]|DEFAULT_MODELS\s*[,)])/;
19
199
  export function runChecks(options = {}) {
20
200
  const root = options.root ?? process.cwd();
21
201
  const env = options.env ?? process.env;
22
202
  const results = [];
23
- // 1. Migration chain — the journal/disk drift that made the .sql
24
- // files documentation rather than a provisioning mechanism.
203
+ // 1. Migration chain: drift between the journal and the .sql files.
25
204
  const migrationsDir = resolveMigrationsDir(root);
26
205
  if (!migrationsDir) {
27
206
  results.push({
@@ -51,21 +230,10 @@ export function runChecks(options = {}) {
51
230
  }
52
231
  }
53
232
  // 2. Required environment.
54
- const missing = REQUIRED_ENV.filter((k) => !env[k]);
55
- results.push(missing.length === 0
56
- ? {
57
- name: "env",
58
- status: "ok",
59
- detail: `${REQUIRED_ENV.length} required variables present`,
60
- }
61
- : {
62
- name: "env",
63
- status: "error",
64
- detail: `Missing: ${missing.join(", ")}`,
65
- });
66
- // 3. Billing product. The engine has no built-in default since the
67
- // Career catalogue moved out; an unset product means every plan
68
- // lookup returns nothing and quotas silently read as zero.
233
+ results.push(...checkEnvironment(root, env));
234
+ // 3. Billing product. The engine has no built-in default catalogue;
235
+ // an unset product means every plan lookup returns nothing and
236
+ // quotas silently read as zero.
69
237
  results.push(env.INTELLIGO_BILLING_PRODUCT
70
238
  ? {
71
239
  name: "billing",
@@ -78,28 +246,116 @@ export function runChecks(options = {}) {
78
246
  detail: "INTELLIGO_BILLING_PRODUCT unset — the composition root must call " +
79
247
  "setDefaultProductSlug(), or plan lookups resolve to nothing",
80
248
  });
81
- // 4. Chat route's scaffold contract. The registry's chat item ships
82
- // app/api/chat/route.ts, which imports @/lib/intelligo (the
83
- // composition root) and expects @/lib/plans to have registered a
84
- // plan catalogue — both are scaffold-provided consumer files, not
85
- // registry files. Installing chat into a hand-rolled app without
86
- // them is a build error that only shows up at `next build`.
87
- const chatRoute = path.join(root, "app/api/chat/route.ts");
88
- if (existsSync(chatRoute)) {
89
- const missingScaffold = ["lib/intelligo.ts", "lib/plans.ts"].filter((rel) => !existsSync(path.join(root, rel)));
90
- results.push(missingScaffold.length === 0
249
+ // 4. Installed registry items against registry/requires.json: the
250
+ // sibling items they import from, the scaffold files they import,
251
+ // the exports the composition root must provide, and the feature
252
+ // keys they gate on — each a `next build` or a 403 that only shows
253
+ // up later. An item counts as installed when its marker file is.
254
+ const requires = options.requires === undefined ? bundledRequires() : options.requires;
255
+ if (requires) {
256
+ const exists = (rel) => [".ts", ".tsx", ".js", ".jsx", ".json", ""].some((ext) => existsSync(path.join(root, rel + ext)));
257
+ const plansSource = existsSync(path.join(root, "lib/plans.ts"))
258
+ ? readFileSync(path.join(root, "lib/plans.ts"), "utf8")
259
+ : null;
260
+ for (const [name, item] of Object.entries(requires.items)) {
261
+ if (!existsSync(path.join(root, item.marker)))
262
+ continue;
263
+ const problems = [];
264
+ for (const dep of item.items ?? []) {
265
+ const marker = requires.items[dep]?.marker;
266
+ if (marker && !existsSync(path.join(root, marker))) {
267
+ problems.push(`install the ${dep} item first`);
268
+ }
269
+ }
270
+ for (const file of item.files ?? []) {
271
+ if (!exists(file))
272
+ problems.push(`create ${file} (scaffold-provided)`);
273
+ }
274
+ for (const [file, names] of Object.entries(item.exports ?? {})) {
275
+ const abs = [".ts", ".tsx"]
276
+ .map((ext) => path.join(root, file + ext))
277
+ .find((p) => existsSync(p));
278
+ if (!abs)
279
+ continue; // reported above as a missing file
280
+ const source = readFileSync(abs, "utf8");
281
+ const missing = names.filter((n) => !new RegExp(`export\\s+(?:default\\s+)?(?:async\\s+)?(?:const|function\\*?|let|var|class)\\s+${n}\\b`).test(source) &&
282
+ !new RegExp(`export\\s*\\{[^}]*\\b${n}\\b`).test(source));
283
+ if (missing.length) {
284
+ problems.push(`${file} must export ${missing.join(", ")}`);
285
+ }
286
+ }
287
+ for (const feature of item.features ?? []) {
288
+ if (plansSource !== null &&
289
+ !new RegExp(`\\b${feature}\\b\\s*:`).test(plansSource)) {
290
+ problems.push(`register the "${feature}" feature key in lib/plans.ts — an unregistered key is denied (403)`);
291
+ }
292
+ }
293
+ results.push(problems.length === 0
294
+ ? { name: `item:${name}`, status: "ok", detail: "requirements met" }
295
+ : {
296
+ name: `item:${name}`,
297
+ status: "error",
298
+ detail: problems.join("; "),
299
+ });
300
+ }
301
+ }
302
+ // 4b. Maintenance route. It refuses to serve without a strong
303
+ // CRON_SECRET, and a scheduler hitting a 403 every five minutes
304
+ // is easy to miss.
305
+ if (existsSync(path.join(root, "app/api/cron/maintenance/route.ts"))) {
306
+ const cronSecret = env.CRON_SECRET ?? "";
307
+ results.push(cronSecret.length >= 32
308
+ ? { name: "maintenance", status: "ok", detail: "CRON_SECRET set" }
309
+ : {
310
+ name: "maintenance",
311
+ status: "error",
312
+ detail: "app/api/cron/maintenance/route.ts exists but CRON_SECRET is " +
313
+ (cronSecret ? "shorter than 32 chars" : "unset") +
314
+ " — the route answers 403 until it is",
315
+ });
316
+ }
317
+ // 4c. Better-Auth's HTTP mount. Every auth item's form posts to
318
+ // `/api/auth/*` on this origin; without the catch-all route
319
+ // those requests 404 and the pages look broken for no visible
320
+ // reason.
321
+ if (existsSync(path.join(root, "app/[locale]/(auth)/layout.tsx"))) {
322
+ results.push(existsSync(path.join(root, "app/api/auth/[...all]/route.ts"))
323
+ ? { name: "auth-mount", status: "ok", detail: "/api/auth mounted" }
324
+ : {
325
+ name: "auth-mount",
326
+ status: "error",
327
+ detail: "auth pages are installed but app/api/auth/[...all]/route.ts " +
328
+ "is missing — add `export { GET, POST } from " +
329
+ '"@intelligo-dev/next/auth";` there or every sign-in answers 404',
330
+ });
331
+ }
332
+ // 4d. Model prices. The registry is open and nothing self-registers,
333
+ // so a composition root that never calls `registerModels` leaves
334
+ // admission with no price to estimate against: every request is
335
+ // refused with `unknown_model`, at runtime, on a deployment whose
336
+ // only mistake was omitting one line.
337
+ const compositionRoot = ["lib/intelligo.ts", "lib/intelligo.tsx"]
338
+ .map((rel) => path.join(root, rel))
339
+ .find((file) => existsSync(file));
340
+ if (compositionRoot) {
341
+ const source = readFileSync(compositionRoot, "utf8");
342
+ const registers = /\bregisterModels?\s*\(/.test(stripComments(source));
343
+ results.push(registers
91
344
  ? {
92
- name: "chat",
345
+ name: "models",
93
346
  status: "ok",
94
- detail: "app/api/chat/route.ts has lib/intelligo.ts + lib/plans.ts",
347
+ detail: "the composition root registers model prices",
95
348
  }
96
349
  : {
97
- name: "chat",
350
+ name: "models",
98
351
  status: "error",
99
- detail: `app/api/chat/route.ts needs ${missingScaffold.join(" and ")} — ` +
100
- "create them from the CLI's app-scaffold templates " +
101
- "(packages/cli/templates/app-scaffold)",
352
+ detail: "no registerModels() in the composition root — admission cannot " +
353
+ "price any model and refuses every request with `unknown_model`. " +
354
+ "Add `registerModels(DEFAULT_MODELS)` from @intelligo-dev/executions, " +
355
+ "or your own catalogue",
102
356
  });
357
+ if (registers)
358
+ results.push(...checkModelIds(root, source));
103
359
  }
104
360
  // 5. Generated source. A conflict — template and consumer both
105
361
  // moved — is the one state an upgrade cannot resolve on its own.
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,q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C3C,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,gBAAgB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,iDAAiD;SAC7G,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAsB;IAClD,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAW,CAAC;IACzD,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,WAAW,CAAC,OAAsB;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC"}
@@ -15,6 +15,29 @@
15
15
  * schema but no rows there at all, which this reports distinctly:
16
16
  * "unmanaged" is a different problem from "behind", and baselining is
17
17
  * the fix (see the migrations README).
18
+ *
19
+ * The framework's chain is one baseline. A database that ran the pre-1.0
20
+ * chain holds its hashes, which `legacy-chain.json` (next to the
21
+ * journal) lists: they are reported as `legacy`, not as unknown, and a
22
+ * database holding all of them is `adoptable` — its schema is the
23
+ * baseline's, so `migrate` records the baseline without running it.
24
+ *
25
+ * The exit code is 1 whenever anything is pending or the database is
26
+ * ahead, which a brand-new database and a stale one share. A deploy
27
+ * gate that must tell them apart reads `migrate --check --json`: one
28
+ * JSON object on stdout, same exit code, whose `state` is
29
+ *
30
+ * - `up_to_date` — every migration is applied;
31
+ * - `pending` — a migrated database is behind this checkout;
32
+ * - `fresh` — no migration records and none of the framework's
33
+ * tables: an empty database, `migrate` applies the chain;
34
+ * - `unmanaged` — the tables exist with no records (`db:push`);
35
+ * - `ahead` — applied migrations this checkout does not contain;
36
+ * - `legacy` — the pre-1.0 chain; `adoptable` says whether
37
+ * `migrate` can take it over.
38
+ *
39
+ * Beside `state` it carries `exitCode`, `chain`, `applied`, `pending`,
40
+ * `unknown`, `legacy` and `adoptable`.
18
41
  */
19
42
  export type MigrateCheckResult = {
20
43
  /** Journal tags this checkout knows about, in order. */
@@ -30,15 +53,45 @@ export type MigrateCheckResult = {
30
53
  * schema exists — a push-provisioned database that needs baselining.
31
54
  */
32
55
  unmanaged: boolean;
56
+ /** Pre-1.0 migrations the database ran, by tag. */
57
+ legacy: string[];
58
+ /** Length of the pre-1.0 chain (0 when this checkout ships none). */
59
+ legacyChainLength: number;
60
+ /**
61
+ * The database ran the whole pre-1.0 chain and not the baseline:
62
+ * `migrate` records the baseline as applied without running it.
63
+ */
64
+ adoptable: boolean;
33
65
  };
66
+ /** The pre-1.0 chain's tags and hashes, if this checkout ships them. */
67
+ export declare function readLegacyChain(migrationsDir: string): Array<{
68
+ tag: string;
69
+ hash: string;
70
+ }>;
34
71
  /** Drizzle hashes the file contents with sha256. */
35
72
  export declare function hashMigration(sql: string): string;
36
73
  type QueryFn = (sql: string) => Promise<Array<{
37
74
  hash: string;
38
75
  }>>;
39
76
  export declare function migrateCheck(migrationsDir: string, query: QueryFn): Promise<MigrateCheckResult>;
40
- export declare function formatMigrateCheck(r: MigrateCheckResult): string;
77
+ /**
78
+ * `schemaExists` is whether the framework's tables are in the database
79
+ * (`SCHEMA_PROBE_SQL`). When the caller did not probe, a database with
80
+ * no records gets the cautious `db:push` wording.
81
+ */
82
+ export declare function formatMigrateCheck(r: MigrateCheckResult, schemaExists?: boolean): string;
41
83
  /** Non-zero when deploying this code would run against a stale schema. */
42
84
  export declare function migrateCheckExitCode(r: MigrateCheckResult): number;
85
+ /** A partial pre-1.0 chain: neither adoptable nor migratable from here. */
86
+ export declare function isPartialLegacy(r: MigrateCheckResult): boolean;
87
+ export type MigrateState = "up_to_date" | "pending" | "fresh" | "ahead" | "unmanaged" | "legacy";
88
+ /**
89
+ * One word for what the check found, most urgent first: a database that
90
+ * is ahead or on the pre-1.0 chain is that before it is anything else.
91
+ * `schemaExists` separates an empty database from a push-provisioned one.
92
+ */
93
+ export declare function migrateState(r: MigrateCheckResult, schemaExists: boolean): MigrateState;
94
+ /** The `--json` report: `state` first, then the detail behind it. */
95
+ export declare function formatMigrateCheckJson(r: MigrateCheckResult, schemaExists: boolean): string;
43
96
  export {};
44
97
  //# sourceMappingURL=migrate-check.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-check.d.ts","sourceRoot":"","sources":["../../src/commands/migrate-check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAQH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,wDAAwD;IACxD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,iFAAiF;IACjF,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qEAAqE;IACrE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,KAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAAC;AAEjE,wBAAsB,YAAY,CAChC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,kBAAkB,CAAC,CA2C7B;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,kBAAk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AC,EAAE,OAAO,GACrB,MAAM,CAiDR;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAElE;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAE9D;AAED,MAAM,MAAM,YAAY,GACtB,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,CAAC,EAAE,kBAAkB,EACrB,YAAY,EAAE,OAAO,GACpB,YAAY,CAKd;AAED,qEAAqE;AACrE,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,kBAAkB,EACrB,YAAY,EAAE,OAAO,GACpB,MAAM,CAWR"}
@@ -15,11 +15,42 @@
15
15
  * schema but no rows there at all, which this reports distinctly:
16
16
  * "unmanaged" is a different problem from "behind", and baselining is
17
17
  * the fix (see the migrations README).
18
+ *
19
+ * The framework's chain is one baseline. A database that ran the pre-1.0
20
+ * chain holds its hashes, which `legacy-chain.json` (next to the
21
+ * journal) lists: they are reported as `legacy`, not as unknown, and a
22
+ * database holding all of them is `adoptable` — its schema is the
23
+ * baseline's, so `migrate` records the baseline without running it.
24
+ *
25
+ * The exit code is 1 whenever anything is pending or the database is
26
+ * ahead, which a brand-new database and a stale one share. A deploy
27
+ * gate that must tell them apart reads `migrate --check --json`: one
28
+ * JSON object on stdout, same exit code, whose `state` is
29
+ *
30
+ * - `up_to_date` — every migration is applied;
31
+ * - `pending` — a migrated database is behind this checkout;
32
+ * - `fresh` — no migration records and none of the framework's
33
+ * tables: an empty database, `migrate` applies the chain;
34
+ * - `unmanaged` — the tables exist with no records (`db:push`);
35
+ * - `ahead` — applied migrations this checkout does not contain;
36
+ * - `legacy` — the pre-1.0 chain; `adoptable` says whether
37
+ * `migrate` can take it over.
38
+ *
39
+ * Beside `state` it carries `exitCode`, `chain`, `applied`, `pending`,
40
+ * `unknown`, `legacy` and `adoptable`.
18
41
  */
19
42
  import { createHash } from "node:crypto";
20
- import { readFileSync } from "node:fs";
43
+ import { existsSync, readFileSync } from "node:fs";
21
44
  import path from "node:path";
22
45
  import { readMigrationChain } from "../migrations.js";
46
+ /** The pre-1.0 chain's tags and hashes, if this checkout ships them. */
47
+ export function readLegacyChain(migrationsDir) {
48
+ const file = path.join(migrationsDir, "legacy-chain.json");
49
+ if (!existsSync(file))
50
+ return [];
51
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
52
+ return parsed.entries ?? [];
53
+ }
23
54
  /** Drizzle hashes the file contents with sha256. */
24
55
  export function hashMigration(sql) {
25
56
  return createHash("sha256").update(sql).digest("hex");
@@ -45,33 +76,67 @@ export async function migrateCheck(migrationsDir, query) {
45
76
  catch {
46
77
  tableMissing = true;
47
78
  }
79
+ const legacyChain = readLegacyChain(migrationsDir);
80
+ const legacyByHash = new Map(legacyChain.map((e) => [e.hash, e.tag]));
48
81
  const appliedHashes = new Set(rows.map((r) => r.hash));
49
82
  const applied = [];
50
83
  const unknown = [];
84
+ const legacy = [];
51
85
  for (const hash of appliedHashes) {
52
86
  const tag = hashToTag.get(hash);
87
+ const legacyTag = legacyByHash.get(hash);
53
88
  if (tag)
54
89
  applied.push(tag);
90
+ else if (legacyTag)
91
+ legacy.push(legacyTag);
55
92
  else
56
93
  unknown.push(hash.slice(0, 12));
57
94
  }
58
95
  const appliedTags = new Set(applied);
59
96
  const pending = chain.journalTags.filter((t) => !appliedTags.has(t));
97
+ const baseline = chain.journalTags[0];
60
98
  return {
61
99
  chain: chain.journalTags,
62
100
  applied,
63
101
  pending,
64
102
  unknown,
65
103
  unmanaged: tableMissing || appliedHashes.size === 0,
104
+ legacy,
105
+ legacyChainLength: legacyChain.length,
106
+ adoptable: legacyChain.length > 0 &&
107
+ legacy.length === legacyChain.length &&
108
+ baseline !== undefined &&
109
+ !appliedTags.has(baseline),
66
110
  };
67
111
  }
68
- export function formatMigrateCheck(r) {
112
+ /**
113
+ * `schemaExists` is whether the framework's tables are in the database
114
+ * (`SCHEMA_PROBE_SQL`). When the caller did not probe, a database with
115
+ * no records gets the cautious `db:push` wording.
116
+ */
117
+ export function formatMigrateCheck(r, schemaExists) {
69
118
  const lines = [];
70
- if (r.unmanaged) {
119
+ if (r.unmanaged && schemaExists === false) {
120
+ lines.push(`! This database is empty: no migration records and none of the ` +
121
+ `framework's tables. \`intelligo migrate\` applies all ` +
122
+ `${r.chain.length} migration(s).`);
123
+ }
124
+ else if (r.unmanaged) {
71
125
  lines.push(`! This database has no migration records. If it was provisioned with ` +
72
126
  `db:push, baseline it before running migrate — otherwise migrate will ` +
73
- `try to apply all ${r.chain.length} migrations. See ` +
74
- `packages/core/src/db/migrations/README.md`);
127
+ `try to apply all ${r.chain.length} migrations. See README.md in ` +
128
+ `@intelligo-dev/core's src/db/migrations.`);
129
+ }
130
+ if (r.adoptable) {
131
+ lines.push(`! This database ran the framework's pre-1.0 migration chain. migrate ` +
132
+ `records ${r.chain[0]} as applied without running it (the schema is ` +
133
+ `already there), then applies what follows. Tables the old chain ` +
134
+ `created that the framework no longer owns are left untouched.`);
135
+ }
136
+ else if (r.legacy.length > 0 && r.legacy.length < r.legacyChainLength) {
137
+ lines.push(`✗ This database ran ${r.legacy.length} of the ${r.legacyChainLength} ` +
138
+ `pre-1.0 migrations. Finish that chain with @intelligo-dev/core ` +
139
+ `1.0.0-beta.7 (\`intelligo migrate\`) before upgrading.`);
75
140
  }
76
141
  if (r.unknown.length > 0) {
77
142
  lines.push(`✗ Database is ahead: ${r.unknown.length} applied migration(s) are not in ` +
@@ -89,4 +154,35 @@ export function formatMigrateCheck(r) {
89
154
  export function migrateCheckExitCode(r) {
90
155
  return r.pending.length > 0 || r.unknown.length > 0 ? 1 : 0;
91
156
  }
157
+ /** A partial pre-1.0 chain: neither adoptable nor migratable from here. */
158
+ export function isPartialLegacy(r) {
159
+ return r.legacy.length > 0 && r.legacy.length < r.legacyChainLength;
160
+ }
161
+ /**
162
+ * One word for what the check found, most urgent first: a database that
163
+ * is ahead or on the pre-1.0 chain is that before it is anything else.
164
+ * `schemaExists` separates an empty database from a push-provisioned one.
165
+ */
166
+ export function migrateState(r, schemaExists) {
167
+ if (r.unknown.length > 0)
168
+ return "ahead";
169
+ if (r.legacy.length > 0)
170
+ return "legacy";
171
+ if (r.unmanaged)
172
+ return schemaExists ? "unmanaged" : "fresh";
173
+ return r.pending.length > 0 ? "pending" : "up_to_date";
174
+ }
175
+ /** The `--json` report: `state` first, then the detail behind it. */
176
+ export function formatMigrateCheckJson(r, schemaExists) {
177
+ return JSON.stringify({
178
+ state: migrateState(r, schemaExists),
179
+ exitCode: migrateCheckExitCode(r),
180
+ chain: r.chain,
181
+ applied: r.applied,
182
+ pending: r.pending,
183
+ unknown: r.unknown,
184
+ legacy: r.legacy,
185
+ adoptable: r.adoptable,
186
+ });
187
+ }
92
188
  //# sourceMappingURL=migrate-check.js.map