create-ailk 0.40.0 → 0.40.2

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 (72) hide show
  1. package/README.md +26 -4
  2. package/component-catalog.json +1 -1
  3. package/component-catalog.md +1 -1
  4. package/dist/add-module.d.ts +2 -1
  5. package/dist/add-module.js +17 -1
  6. package/dist/cutover.d.ts +7 -3
  7. package/dist/cutover.js +8 -3
  8. package/dist/lib/declared-env.d.ts +5 -1
  9. package/dist/lib/declared-env.js +6 -1
  10. package/dist/lib/env-catalog.d.ts +3 -2
  11. package/dist/lib/env-catalog.js +4 -8
  12. package/dist/module-architecture.js +0 -1
  13. package/dist/programmatic.js +18 -9
  14. package/dist/remove-module.js +1 -1
  15. package/dist/seam-refresh.d.ts +60 -0
  16. package/dist/seam-refresh.js +214 -0
  17. package/dist/spoke-checkout.d.ts +12 -3
  18. package/dist/spoke-checkout.js +14 -5
  19. package/dist/sync-routes.d.ts +10 -1
  20. package/dist/sync-routes.js +61 -6
  21. package/dist/template-record.d.ts +14 -2
  22. package/dist/template-record.js +60 -22
  23. package/dist/topology.js +3 -4
  24. package/dist/update.d.ts +13 -1
  25. package/dist/update.js +100 -8
  26. package/package.json +3 -3
  27. package/templates/.env.example +6 -0
  28. package/templates/.github/workflows/ci.yml +3 -0
  29. package/templates/apps/api/.env.example +12 -0
  30. package/templates/apps/api/CLAUDE.md +10 -7
  31. package/templates/apps/mcp/CLAUDE.md +25 -5
  32. package/templates/apps/web/.env.example +7 -1
  33. package/templates/apps/web/CLAUDE.md +40 -13
  34. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  35. package/templates/apps/web/app/[locale]/layout.tsx +41 -24
  36. package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
  37. package/templates/apps/web/app/api/revalidate/route.ts +45 -4
  38. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +60 -0
  39. package/templates/apps/web/app/llms.txt/route.ts +17 -4
  40. package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +15 -7
  41. package/templates/apps/web/auth.config.tsx +2 -0
  42. package/templates/apps/web/auth.ts +28 -4
  43. package/templates/apps/web/jest.config.cjs +1 -1
  44. package/templates/apps/web/lib/__tests__/auth-email.test.ts +21 -0
  45. package/templates/apps/web/lib/__tests__/docs-path.test.ts +20 -2
  46. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +246 -0
  47. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
  48. package/templates/apps/web/lib/__tests__/relay.test.ts +127 -12
  49. package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
  50. package/templates/apps/web/lib/__tests__/server-api.test.ts +72 -7
  51. package/templates/apps/web/lib/__tests__/services-path.test.ts +22 -1
  52. package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
  53. package/templates/apps/web/lib/__tests__/site-contact-lines.test.ts +64 -0
  54. package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +144 -4
  55. package/templates/apps/web/lib/auth-email.ts +19 -0
  56. package/templates/apps/web/lib/docs-path.ts +1 -1
  57. package/templates/apps/web/lib/hub-site-config.ts +154 -0
  58. package/templates/apps/web/lib/mcp-oauth.ts +123 -17
  59. package/templates/apps/web/lib/profile-back-link.ts +49 -12
  60. package/templates/apps/web/lib/relay.ts +48 -9
  61. package/templates/apps/web/lib/served-pages.ts +144 -39
  62. package/templates/apps/web/lib/server-api.ts +37 -4
  63. package/templates/apps/web/lib/services-path.ts +1 -1
  64. package/templates/apps/web/lib/site-brand.tsx +66 -0
  65. package/templates/apps/web/lib/site-contact-email.ts +24 -4
  66. package/templates/apps/web/lib/site-contact-lines.ts +20 -4
  67. package/templates/apps/web/lib/site-identity.ts +38 -2
  68. package/templates/apps/web/messages/en.json +13 -8
  69. package/templates/apps/web/middleware.ts +4 -2
  70. package/templates/apps/web/src/lib/routes.ts +13 -0
  71. package/templates/tools/declared-env.ts +6 -1
  72. package/versions.json +51 -51
@@ -68,17 +68,26 @@ export const SPOKE_CHECKOUT_DECLARED_ENV = Object.freeze([
68
68
  "STRIPE_MODE",
69
69
  ]);
70
70
  /**
71
- * The catalog (and declared names) a spoke's `appendEnvRows` call passes: a
72
- * commerce spoke adds the package's two rows (D9). `ENV_CATALOG` itself is
73
- * unchanged — its test fails on an entry the monorepo's apps never read.
71
+ * The lead-site marker (#11148, from #8487): the `/contact` action
72
+ * `@working-theory/site-pages` ships writes it as `payload.site`. The action
73
+ * reads it from an installed package, out of the declared-env scan's reach,
74
+ * so every spoke declares it, and the scaffold sets it to the site's slug in
75
+ * `apps/web/.env.local`.
76
+ */
77
+ export const LEAD_SITE_ENV_VAR = "AILK_LEAD_SITE";
78
+ /**
79
+ * The catalog (and declared names) a spoke's `appendEnvRows` call passes:
80
+ * every spoke declares `LEAD_SITE_ENV_VAR`, and a commerce spoke adds the
81
+ * package's two rows (D9). `ENV_CATALOG` itself is unchanged — its test
82
+ * fails on an entry the monorepo's apps never read.
74
83
  */
75
84
  export function spokeEnvRowOptions(commerce) {
76
85
  return commerce
77
86
  ? {
78
87
  catalog: { ...ENV_CATALOG, ...SPOKE_CHECKOUT_ENV_CATALOG },
79
- declare: SPOKE_CHECKOUT_DECLARED_ENV,
88
+ declare: [LEAD_SITE_ENV_VAR, ...SPOKE_CHECKOUT_DECLARED_ENV],
80
89
  }
81
- : { catalog: ENV_CATALOG };
90
+ : { catalog: ENV_CATALOG, declare: [LEAD_SITE_ENV_VAR] };
82
91
  }
83
92
  /** `metadata.site` — the package's own pattern. */
84
93
  const SITE_PATTERN = /^[a-z0-9][a-z0-9-]{0,39}$/;
@@ -1,3 +1,4 @@
1
+ import { type SeamRefreshPlan } from "./seam-refresh.js";
1
2
  import type { WorkspaceVersionMap } from "./substitute.js";
2
3
  /** The site test that fails a route neither rendered through `renderPage` nor in its `NO_STRUCTURED_DATA_ROUTES` (#8704). */
3
4
  export declare const STRUCTURED_DATA_TEST_PATH = "apps/web/lib/__tests__/structured-data.test.tsx";
@@ -84,6 +85,14 @@ export interface SyncRoutesResult {
84
85
  * Sorted.
85
86
  */
86
87
  recorded: string[];
88
+ /**
89
+ * The seams the synced routes import — the `(authed)` gate and the web
90
+ * seam — that `--apply` on a spoke rewrote with this version's render, as
91
+ * `update` does (#11148). Empty without `apply`, and on a hub. Sorted.
92
+ */
93
+ regeneratedSeams: string[];
94
+ /** Those seams left as the site keeps them, with why (#11148). Sorted by path. */
95
+ heldSeams: SeamRefreshPlan["held"];
87
96
  /**
88
97
  * `ROUTE_MESSAGE_NAMESPACES` dot-paths, of any route in `missing`, absent
89
98
  * from the target's `messages/en.json`. CHECK-ONLY — never copied (see
@@ -217,7 +226,7 @@ export interface SyncRoutesArgs {
217
226
  apply: boolean;
218
227
  help: boolean;
219
228
  }
220
- export declare const SYNC_ROUTES_HELP = "create-ailk sync-routes \u2014 copy template routes an existing site is missing.\n\nUsage:\n create-ailk sync-routes [<target-dir>] [--apply]\n\nArguments:\n <target-dir> An already-scaffolded repo (contains\n architecture.yaml). Defaults to the current dir.\n\nOptions:\n --apply Copy the missing route directories into the target.\n Without it the command only reports: exit 1 when a\n route is missing, 0 when in sync.\n --help, -h Print this message.\n\nChecks every core route plus the routes of each surface the site carries; a\nsurface gated off at scaffold time is skipped, not drift. A route the site lists\nin customizations.yaml declined_routes is reported as declined and never copied\n(#11260). A route the site has changed locally is reported and never\noverwritten. Nothing is deleted except,\non a spoke, the retired legacy checkout's files that still match create-ailk's\ncopy: --apply removes them and rewrites the generated billing action (#9142).\nEvery file --apply copies is recorded in .ailk-template-files.json, when the\nsite has one, so `create-ailk update` carries it forward (#11213).\n";
229
+ export declare const SYNC_ROUTES_HELP = "create-ailk sync-routes \u2014 copy template routes an existing site is missing.\n\nUsage:\n create-ailk sync-routes [<target-dir>] [--apply]\n\nArguments:\n <target-dir> An already-scaffolded repo (contains\n architecture.yaml). Defaults to the current dir.\n\nOptions:\n --apply Copy the missing route directories into the target.\n Without it the command only reports: exit 1 when a\n route is missing, 0 when in sync.\n --help, -h Print this message.\n\nChecks every core route plus the routes of each surface the site carries; a\nsurface gated off at scaffold time is skipped, not drift. A route the site lists\nin customizations.yaml declined_routes is reported as declined and never copied\n(#11260). A route the site has changed locally is reported and never\noverwritten. Nothing is deleted except,\non a spoke, the retired legacy checkout's files that still match create-ailk's\ncopy: --apply removes them and rewrites the generated billing action (#9142).\nEvery file --apply copies is recorded in .ailk-template-files.json, when the\nsite has one, so `create-ailk update` carries it forward (#11213). On a\nspoke, --apply also renders the web seam and the (authed) gate again when\ntheir bytes are still the recorded render, as `create-ailk update` does; one\nedited by hand is reported and left (#11148).\n";
221
230
  /**
222
231
  * Parse the argv AFTER the `sync-routes` word. Strict `node:util` parseArgs,
223
232
  * like `parseCliArgs`; at most one positional.
@@ -57,12 +57,15 @@ import { appendEnvRows } from "./lib/declared-env.js";
57
57
  import { ENV_CATALOG } from "./lib/env-catalog.js";
58
58
  import { publicTreeRemoved } from "./lib/site-modules.js";
59
59
  import { readRouteManifests } from "./routes.js";
60
+ import { planSeamRefresh, readSeamInputs, seamRow } from "./seam-refresh.js";
60
61
  import { BILLING_ACTION, BILLING_ACTION_MARKER, RETIRED_CHECKOUT_E2E_MARKER, RETIRED_CHECKOUT_E2E_WORKFLOW_PATH, RETIRED_SPOKE_CHECKOUT_PATHS, } from "./spoke-checkout.js";
61
62
  import { GATEABLE_SURFACES, HUB_KEPT_ROUTE_DIRS, NON_ROUTE_DIRS, pagePackageOfRoute, ROUTE_DEPENDENCIES, ROUTE_MESSAGE_NAMESPACES, ROUTE_SINCE, surfaceForRouteDir, } from "./surfaces.js";
62
63
  import { TEMPLATE_RECORD_PATH, parseTemplateRecord, recordCopiedFiles, serializeTemplateRecord, sha256Hex, } from "./template-record.js";
63
- import { SPOKE_SEAM_FILES, isSpokeExcluded, readSpokeShape, spokeExclusions, } from "./topology.js";
64
+ import { AUTHED_GATE_SEAM_PATH, SPOKE_SEAM_FILES, TopologyError, WEB_SEAM_PATH, isSpokeExcluded, readSpokeShape, spokeExclusions, } from "./topology.js";
64
65
  /** Template-relative prefix every `apps/web` route directory sits under. */
65
66
  const ROUTE_ROOT = "apps/web/app/[locale]";
67
+ /** The seams a synced route imports, which `--apply` regenerates on a spoke (#11148). */
68
+ const ROUTE_SEAM_FILES = [AUTHED_GATE_SEAM_PATH, WEB_SEAM_PATH];
66
69
  /** The site test that fails a route neither rendered through `renderPage` nor in its `NO_STRUCTURED_DATA_ROUTES` (#8704). */
67
70
  export const STRUCTURED_DATA_TEST_PATH = "apps/web/lib/__tests__/structured-data.test.tsx";
68
71
  /**
@@ -821,6 +824,8 @@ export function syncRoutes(opts) {
821
824
  const applied = [];
822
825
  const appliedDependencies = [];
823
826
  const recorded = [];
827
+ const regeneratedSeams = [];
828
+ let heldSeams = [];
824
829
  if (opts.apply === true) {
825
830
  // #11213 — the site's record, read before the first write: every
826
831
  // recordable file copied below is recorded at the create-ailk version
@@ -829,6 +834,7 @@ export function syncRoutes(opts) {
829
834
  // refuses the run. A row at a path no longer recorded is dropped, as
830
835
  // `update` drops it (#10173).
831
836
  const recordPath = join(targetAbs, TEMPLATE_RECORD_PATH);
837
+ const version = opts.version ?? buildScaffoldMarkers(markers.PROJECT_NAME)["CREATE_AILK_VERSION"];
832
838
  let recording;
833
839
  if (existsSync(recordPath)) {
834
840
  let record;
@@ -838,12 +844,27 @@ export function syncRoutes(opts) {
838
844
  catch (err) {
839
845
  throw new Error(`${err.message}; nothing copied`, { cause: err });
840
846
  }
841
- const version = opts.version ?? buildScaffoldMarkers(markers.PROJECT_NAME)["CREATE_AILK_VERSION"];
842
847
  if (version === undefined) {
843
848
  throw new Error(`cannot record the copied files in ${TEMPLATE_RECORD_PATH}: no create-ailk version; nothing copied`);
844
849
  }
845
850
  recording = { record, version };
846
851
  }
852
+ // #11148 — the seam renders' inputs, read before the first write: an
853
+ // apps/web/package.json they cannot parse refuses the run with nothing
854
+ // copied (the manifest was already parsed by `readSpokeShape` above). The
855
+ // plan itself runs after the copies, so its dropped-import scan reads the
856
+ // synced routes.
857
+ let seamInputs;
858
+ if (spoke !== undefined && version !== undefined) {
859
+ try {
860
+ seamInputs = readSeamInputs(targetAbs);
861
+ }
862
+ catch (err) {
863
+ if (err instanceof TopologyError)
864
+ throw new TopologyError(`${err.message}; nothing copied`);
865
+ throw err;
866
+ }
867
+ }
847
868
  /** Site-relative path → sha256 of the bytes written, for the record. */
848
869
  const copied = new Map();
849
870
  const writable = missingRoutes.filter((r) => !refusedSet.has(r));
@@ -896,12 +917,32 @@ export function syncRoutes(opts) {
896
917
  copied.set(dep, sha256Hex(bytes));
897
918
  appliedDependencies.push(dep);
898
919
  }
920
+ let nextRecord = recording?.record;
899
921
  if (recording !== undefined) {
900
922
  const next = recordCopiedFiles(recording.record, copied, recording.version);
901
- if (next.recorded.length > 0) {
902
- writeFileSync(recordPath, serializeTemplateRecord(next.record));
903
- recorded.push(...next.recorded);
923
+ nextRecord = next.record;
924
+ recorded.push(...next.recorded);
925
+ }
926
+ // #11148 — on a spoke, the seams a synced route imports are regenerated
927
+ // as `update` regenerates them, written before the record names them.
928
+ if (seamInputs !== undefined && version !== undefined) {
929
+ const plan = planSeamRefresh(targetAbs, nextRecord?.seams ?? {}, version, ROUTE_SEAM_FILES, seamInputs);
930
+ const seams = { ...plan.rows };
931
+ for (const [path, render] of plan.writes) {
932
+ const abs = join(targetAbs, ...path.split("/"));
933
+ mkdirSync(dirname(abs), { recursive: true });
934
+ writeFileSync(abs, render);
935
+ seams[path] = seamRow(render, version);
936
+ regeneratedSeams.push(path);
904
937
  }
938
+ heldSeams = plan.held;
939
+ if (nextRecord !== undefined)
940
+ nextRecord = { ...nextRecord, seams };
941
+ }
942
+ if (recording !== undefined && nextRecord !== undefined) {
943
+ const text = serializeTemplateRecord(nextRecord);
944
+ if (text !== serializeTemplateRecord(recording.record))
945
+ writeFileSync(recordPath, text);
905
946
  }
906
947
  // #7874 D9 — a spoke declares what the copied routes read, as the last
907
948
  // write. A malformed env_contract block throws EnvContractError naming
@@ -921,6 +962,8 @@ export function syncRoutes(opts) {
921
962
  missingDependencies,
922
963
  appliedDependencies,
923
964
  recorded,
965
+ regeneratedSeams: regeneratedSeams.sort(),
966
+ heldSeams,
924
967
  missingMessageNamespaces,
925
968
  skippedSurfaces,
926
969
  declined,
@@ -1065,6 +1108,15 @@ export function formatSyncRoutesReport(result, apply) {
1065
1108
  if (result.recorded.length > 0) {
1066
1109
  lines.push(`[create-ailk] Recorded ${result.recorded.length} copied file(s) in ${TEMPLATE_RECORD_PATH}, so \`create-ailk update\` carries them forward.`);
1067
1110
  }
1111
+ // #11148 — the seams the synced routes import.
1112
+ if (result.regeneratedSeams.length > 0) {
1113
+ lines.push(`[create-ailk] Regenerated ${result.regeneratedSeams.length} seam(s) the synced routes import:`);
1114
+ lines.push(...result.regeneratedSeams.map((path) => ` ${path}`));
1115
+ }
1116
+ if (result.heldSeams.length > 0) {
1117
+ lines.push(`[create-ailk] Held ${result.heldSeams.length} seam(s) the synced routes import:`);
1118
+ lines.push(...result.heldSeams.map(({ path, reason }) => ` ${path} — ${reason}`));
1119
+ }
1068
1120
  if (result.missingMessageNamespaces.length > 0) {
1069
1121
  lines.push(`[create-ailk] Also required — message namespace(s) not found in apps/web/messages/en.json (add manually, not auto-merged):`);
1070
1122
  lines.push(...result.missingMessageNamespaces.map((ns) => ` ${ns}`));
@@ -1123,7 +1175,10 @@ overwritten. Nothing is deleted except,
1123
1175
  on a spoke, the retired legacy checkout's files that still match create-ailk's
1124
1176
  copy: --apply removes them and rewrites the generated billing action (#9142).
1125
1177
  Every file --apply copies is recorded in .ailk-template-files.json, when the
1126
- site has one, so \`create-ailk update\` carries it forward (#11213).
1178
+ site has one, so \`create-ailk update\` carries it forward (#11213). On a
1179
+ spoke, --apply also renders the web seam and the (authed) gate again when
1180
+ their bytes are still the recorded render, as \`create-ailk update\` does; one
1181
+ edited by hand is reported and left (#11148).
1127
1182
  `;
1128
1183
  /**
1129
1184
  * Parse the argv AFTER the `sync-routes` word. Strict `node:util` parseArgs,
@@ -44,6 +44,13 @@ export interface TemplateRecord {
44
44
  schema: 1;
45
45
  projectName: string;
46
46
  files: Record<string, TemplateFileRow>;
47
+ /**
48
+ * The sha256 of each topology seam (`SPOKE_SEAM_FILES`) as create-ailk last
49
+ * rendered it, and that version (#11148): `update` and `sync-routes --apply`
50
+ * regenerate a seam still at its row and hold one the site edited. Absent
51
+ * from a record written before #11148, and when no seam was recorded.
52
+ */
53
+ seams?: Record<string, TemplateFileRow>;
47
54
  }
48
55
  /** Thrown by `parseTemplateRecord` on a malformed or unsafe record. */
49
56
  export declare class TemplateRecordError extends Error {
@@ -63,10 +70,15 @@ export interface ParseTemplateRecordOptions {
63
70
  * JSON that does not parse; `schema !== 1`; an unknown top-level key; an
64
71
  * empty `projectName`; a `files` key that is not a recordable path (unless
65
72
  * `onUnrecordable` takes it); a `sha256` that is not 64 lowercase hex; a
66
- * `version` that is not a semver string (#8522 D1).
73
+ * `version` that is not a semver string (#8522 D1). A record declaring
74
+ * `offTemplate` is refused by name whatever its value or rows (#9559 D2).
67
75
  */
68
76
  export declare function parseTemplateRecord(text: string, opts?: ParseTemplateRecordOptions): TemplateRecord;
69
- /** `record` as `scaffold()` and `update` write it: sorted keys, trailing newline. */
77
+ /**
78
+ * `record` as `scaffold()` and `update` write it: sorted keys, trailing
79
+ * newline; `seams` only when it holds a row, so a record without one is
80
+ * byte-identical to before #11148.
81
+ */
70
82
  export declare function serializeTemplateRecord(record: TemplateRecord): string;
71
83
  export interface PlanTemplateRecordOptions {
72
84
  /** The freshly scaffolded site. */
@@ -15,6 +15,11 @@
15
15
  * only READS the scaffold's own disk to confirm a copied path's final bytes
16
16
  * (a later layer may have rewritten it, D2); every write goes through the
17
17
  * caller.
18
+ *
19
+ * A record carrying `offTemplate` declares the site off-template (#9559):
20
+ * every app file is site-owned and upgrades are hand-ported, so
21
+ * `parseTemplateRecord` refuses it by name and no command that reads the
22
+ * record runs on that site.
18
23
  */
19
24
  import { createHash } from "node:crypto";
20
25
  import { existsSync, readFileSync } from "node:fs";
@@ -105,6 +110,7 @@ export function isRecordable(destRel) {
105
110
  export function sha256Hex(bytes) {
106
111
  return createHash("sha256").update(bytes).digest("hex");
107
112
  }
113
+ const SEAM_SET = new Set(SPOKE_SEAM_FILES);
108
114
  /** Thrown by `parseTemplateRecord` on a malformed or unsafe record. */
109
115
  export class TemplateRecordError extends Error {
110
116
  constructor(message) {
@@ -134,7 +140,8 @@ function isSafeRecordKey(key) {
134
140
  * JSON that does not parse; `schema !== 1`; an unknown top-level key; an
135
141
  * empty `projectName`; a `files` key that is not a recordable path (unless
136
142
  * `onUnrecordable` takes it); a `sha256` that is not 64 lowercase hex; a
137
- * `version` that is not a semver string (#8522 D1).
143
+ * `version` that is not a semver string (#8522 D1). A record declaring
144
+ * `offTemplate` is refused by name whatever its value or rows (#9559 D2).
138
145
  */
139
146
  export function parseTemplateRecord(text, opts = {}) {
140
147
  let doc;
@@ -148,7 +155,10 @@ export function parseTemplateRecord(text, opts = {}) {
148
155
  throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} is not a JSON object`);
149
156
  }
150
157
  const record = doc;
151
- const allowed = new Set(["schema", "projectName", "files"]);
158
+ if ("offTemplate" in record) {
159
+ throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} declares this site off-template (${JSON.stringify(record["offTemplate"])}): every file under apps/ is site-owned and upgrades are hand-ported, so this command does not run on it`);
160
+ }
161
+ const allowed = new Set(["schema", "projectName", "files", "seams"]);
152
162
  for (const key of Object.keys(record)) {
153
163
  if (!allowed.has(key)) {
154
164
  throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} has an unknown top-level key "${key}"`);
@@ -177,30 +187,58 @@ export function parseTemplateRecord(text, opts = {}) {
177
187
  }
178
188
  throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} "files" has a key "${key}" that is not a recordable path`);
179
189
  }
180
- if (typeof value !== "object" || value === null) {
181
- throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} "files"["${key}"] must be an object`);
182
- }
183
- const row = value;
184
- const sha = row["sha256"];
185
- if (typeof sha !== "string" || !SHA256_PATTERN.test(sha)) {
186
- throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} "files"["${key}"].sha256 must be 64 lowercase hex characters`);
187
- }
188
- const version = row["version"];
189
- if (typeof version !== "string" || !VERSION_PATTERN.test(version)) {
190
- throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} "files"["${key}"].version must be a semver string`);
190
+ files[key] = parseRow(`"files"["${key}"]`, value);
191
+ }
192
+ const seamsRaw = record["seams"];
193
+ if (seamsRaw === undefined)
194
+ return { schema: 1, projectName, files };
195
+ if (typeof seamsRaw !== "object" || seamsRaw === null || Array.isArray(seamsRaw)) {
196
+ throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} "seams" must be an object`);
197
+ }
198
+ const seams = {};
199
+ for (const [key, value] of Object.entries(seamsRaw)) {
200
+ if (!SEAM_SET.has(key)) {
201
+ throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} "seams" has a key "${key}" that is not a topology seam`);
191
202
  }
192
- files[key] = { sha256: sha, version };
203
+ seams[key] = parseRow(`"seams"["${key}"]`, value);
193
204
  }
194
- return { schema: 1, projectName, files };
205
+ return { schema: 1, projectName, files, seams };
195
206
  }
196
- /** `record` as `scaffold()` and `update` write it: sorted keys, trailing newline. */
197
- export function serializeTemplateRecord(record) {
198
- const files = {};
199
- for (const key of Object.keys(record.files).sort()) {
200
- files[key] = record.files[key];
207
+ /** One `{ sha256, version }` row, refusing — naming `label` — on either field malformed. */
208
+ function parseRow(label, value) {
209
+ if (typeof value !== "object" || value === null) {
210
+ throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} ${label} must be an object`);
211
+ }
212
+ const row = value;
213
+ const sha = row["sha256"];
214
+ if (typeof sha !== "string" || !SHA256_PATTERN.test(sha)) {
215
+ throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} ${label}.sha256 must be 64 lowercase hex characters`);
201
216
  }
202
- return (JSON.stringify({ schema: record.schema, projectName: record.projectName, files }, null, 2) +
203
- "\n");
217
+ const version = row["version"];
218
+ if (typeof version !== "string" || !VERSION_PATTERN.test(version)) {
219
+ throw new TemplateRecordError(`${TEMPLATE_RECORD_PATH} ${label}.version must be a semver string`);
220
+ }
221
+ return { sha256: sha, version };
222
+ }
223
+ /**
224
+ * `record` as `scaffold()` and `update` write it: sorted keys, trailing
225
+ * newline; `seams` only when it holds a row, so a record without one is
226
+ * byte-identical to before #11148.
227
+ */
228
+ export function serializeTemplateRecord(record) {
229
+ const sorted = (rows) => {
230
+ const out = {};
231
+ for (const key of Object.keys(rows).sort())
232
+ out[key] = rows[key];
233
+ return out;
234
+ };
235
+ const seams = record.seams !== undefined && Object.keys(record.seams).length > 0 ? sorted(record.seams) : undefined;
236
+ return (JSON.stringify({
237
+ schema: record.schema,
238
+ projectName: record.projectName,
239
+ files: sorted(record.files),
240
+ ...(seams !== undefined ? { seams } : {}),
241
+ }, null, 2) + "\n");
204
242
  }
205
243
  /**
206
244
  * The record a fresh scaffold writes (#8522 D2): one row per copied path
package/dist/topology.js CHANGED
@@ -1015,6 +1015,7 @@ const AUTH_CONFIG_HUB = [
1015
1015
  " confirmSignUpEmail,",
1016
1016
  " makeSendAccountOpen,",
1017
1017
  " purchaseCapture,",
1018
+ " senderWorkspace,",
1018
1019
  "} from \"./lib/auth-email\";",
1019
1020
  "import {",
1020
1021
  " getActiveProviderIds,",
@@ -1089,11 +1090,9 @@ const AUTH_CONFIG_HUB = [
1089
1090
  " confirmSignUpEmail: (nonce) => confirmSignUpEmail(nonce),",
1090
1091
  " makeSendAccountOpen: (deps) => makeSendAccountOpen(deps),",
1091
1092
  " buildAuthEmailRequest: (payload, secret) =>",
1092
- " buildAuthEmailRequest(",
1093
- " payload as Parameters<typeof buildAuthEmailRequest>[0],",
1094
- " secret,",
1095
- " ),",
1093
+ " buildAuthEmailRequest(payload, secret),",
1096
1094
  " purchaseCapture,",
1095
+ " senderWorkspace,",
1097
1096
  " },",
1098
1097
  " },",
1099
1098
  "} satisfies AuthSite;",
package/dist/update.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type MdxParse } from "./mdx-braces.js";
2
+ import { type ModuleName } from "./parse-args.js";
2
3
  import type { WorkspaceVersionMap } from "./substitute.js";
3
4
  /** A refusal the CLI exits 2 on, thrown before anything is written. */
4
5
  export declare class UpdateRefusedError extends Error {
@@ -112,6 +113,8 @@ export interface UpdateResult {
112
113
  headingsAdded: string[];
113
114
  /** The mdx-body pages under `content/` whose bare `{` were escaped this run (#10773). */
114
115
  bracesEscaped: string[];
116
+ /** The topology seams rewritten with this version's render for the site's topology and sign-in mode (#11148). */
117
+ regenerated?: string[];
115
118
  /** The generated route files written from the installed page packages' manifests after the pins moved (#11219). */
116
119
  routesWritten?: string[];
117
120
  /** The root `devDependencies["create-ailk"]` pin, moved to the running version so the scaffold's `routes:check` renders with the generator that wrote the files (#11219). */
@@ -124,6 +127,15 @@ export interface UpdateResult {
124
127
  files: number;
125
128
  };
126
129
  }
130
+ /**
131
+ * Whether `diskBytes` is `templateBytes` with the `jest-config` /
132
+ * `next-config` patches of the site's `modules` for `path` applied, in some
133
+ * order the modules could have been installed (#11591 D2): the copy a
134
+ * scaffold or `add-module` left, which `planTemplateRecord` keeps out of the
135
+ * record, never a site edit. `false` when no module patches `path`; an order
136
+ * whose patch no longer applies matches nothing.
137
+ */
138
+ export declare function isModulePatchedCopy(path: string, templateBytes: Uint8Array, diskBytes: Uint8Array, modules: readonly ModuleName[]): boolean;
127
139
  /**
128
140
  * The site's messages catalog with every key the template's copy has and it
129
141
  * lacks (#10173): the site's values always win, nothing is removed, and the
@@ -156,6 +168,6 @@ export interface UpdateArgs {
156
168
  target: string | undefined;
157
169
  help: boolean;
158
170
  }
159
- export declare const UPDATE_HELP = "create-ailk update \u2014 bring template fixes into a site's copied app code.\n\nUsage:\n create-ailk update [<target-dir>]\n\nArguments:\n <target-dir> The existing site. Defaults to the current dir.\n\nOptions:\n --help, -h Print this message.\n\nReads .ailk-template-files.json (written beside .ailk-site-manifest.json by\nevery template scaffold) to tell an untouched copy from an edit. An\nuntouched apps/web, apps/api or apps/mcp file, or a root tools/jest file the\napp jest configs require, whose template copy changed is overwritten. An\nedited file whose template copy also changed is three-way merged with\n`git` (git must be on PATH); a conflict leaves the file alone and is\nlisted under \"Needs review\"; an apps/web/messages catalog instead gains the\ntemplate's new keys and keeps every value it has \u2014 also when its recorded\nversion's copy cannot be read \u2014 and is reviewed only when a key is an object\non one side and a value on the other; a written apps/web file that uses\nthrough t(...) a key the catalog then lacks is held with it, listed under\n\"Held back with <catalog>\". Each @working-theory/* package a written apps/web\nfile imports that apps/web/package.json does not declare is added to its\ndependencies at this release's version. An edited file whose\nbytes are another published create-ailk version's copy is a stale copy, not\nan edit: it is overwritten or removed as an untouched file is, listed with\nthe version it matched. An edit that touches only comment lines is listed as\n\"comment-only edit\"; on a conflict the template's copy lands. A file at a\ntemplate path that is not in the record (one an earlier sync-routes --apply\nor add-route copied without recording it) whose bytes are a published\ncreate-ailk version's copy \u2014 from the version the site was scaffolded at to\nthis one \u2014 is adopted: recorded and moved forward as an untouched file is,\nlisted under \"Adopted\" with the version it matched. One whose bytes match no\npublished copy is a site edit: skipped, never overwritten, and counted under\n\"Held as site edits, not in the record\". No file under a route the site\nlists in customizations.yaml declined_routes is written: each is listed under\n\"Skipped\" naming the declined route. Every template\ntest, and every site-edited template file, that imports a file left under\n\"Needs review\" (by a relative or @/ import, transitively) is held\nat the site's version with it, its record entry is not advanced, and it is\nlisted under \"Held back with <file>\" \u2014 reconcile the file, then run update\nagain to bring it forward. A skipped file never holds another. A file whose\nown bytes are the record's is not held by what it imports: it moves, unless\nit names an export the held copy lacks, and the held file is listed as\n\"Held back: <file> \u2014 imported by N moved files; the site edit is <hunk\nsummary>\". A written file whose import names a file the site lacks gets it\nadded when this template supplies it; otherwise it is held the same way,\nunder \"Held back with <file> (not in this site)\", unless its own copy\nalready named the file \u2014 then it moves and the path is listed under \"Not in\nthis site or the template: <file>\". A file the template removed is kept\nwhile any file still in the site imports it. Every other file in the run\nstill updates. When project.yaml has an env_contract block, each\nenv var the written files read that has no row gains one; no row is edited.\nA record row at a path create-ailk no longer records is dropped and listed.\nA surface the site's .ailk-site-manifest.json names a page on but\narchitecture.yaml does not declare (one no module owns, such as projects)\ngets its route files added and is declared, listed under \"Surfaces declared\nfrom the roster\". A code-route row of that roster no page file serves is\ndropped, listed under \"Roster rows dropped, no route serves them\".\nA site with no record gets one on its first run, from the version its\n.ailk-site-manifest.json already records. A site scaffolded before\n@working-theory/mcp-server has its copied apps/mcp moved to the boot set:\nthe server and each module's paid MCP pack join apps/mcp/package.json, the\ncopied server files go, and apps/mcp/src/lib/paid-tools.generated.ts is\nrewritten on every run. A site scaffolded before @working-theory/api has its\ncopied apps/api moved to the boot file: the app becomes @working-theory/app-api,\nthe package and the six @working-theory/api-<module> packages join\napps/api/package.json, its bins and build:vercel delegate to the package, and\nthe copied server files go. Run `pnpm install` after either move, since the\napp's package.json gained dependencies. Each mdx-body page in content/ with no\n'# ' heading gets its title and description written into its body as its\nheading and intro, listed under \"Page heading added\"; a page with one heading\nis left as it is, and one with several, or one whose frontmatter it cannot\nread, is listed under \"Needs review\". Each bare { on an mdx-body page is\nescaped as \\{ when the site's own MDX parser then reads the page clean, listed\nunder \"Placeholder brace escaped\"; a page it cannot escape safely, or any page\nwith one while the site's dependencies are not installed, is listed under\n\"Needs review\". Last, the generated route files of every installed page\npackage (one whose package.json declares \"ailk\": { \"routes\" }) are rewritten\nfrom its manifest, listed under \"Route files regenerated\"; run\n`create-ailk routes --write` after the install when the packages were not\ninstalled yet. Commit before running, and review the diff after.\n";
171
+ export declare const UPDATE_HELP = "create-ailk update \u2014 bring template fixes into a site's copied app code.\n\nUsage:\n create-ailk update [<target-dir>]\n\nArguments:\n <target-dir> The existing site. Defaults to the current dir.\n\nOptions:\n --help, -h Print this message.\n\nReads .ailk-template-files.json (written beside .ailk-site-manifest.json by\nevery template scaffold) to tell an untouched copy from an edit. An\nuntouched apps/web, apps/api or apps/mcp file, or a root tools/jest file the\napp jest configs require, whose template copy changed is overwritten. An\nedited file whose template copy also changed is three-way merged with\n`git` (git must be on PATH); a conflict leaves the file alone and is\nlisted under \"Needs review\"; an apps/web/messages catalog instead gains the\ntemplate's new keys and keeps every value it has \u2014 also when its recorded\nversion's copy cannot be read \u2014 and is reviewed only when a key is an object\non one side and a value on the other; a written apps/web file that uses\nthrough t(...) a key the catalog then lacks is held with it, listed under\n\"Held back with <catalog>\". Each @working-theory/* package a written apps/web\nfile imports that apps/web/package.json does not declare is added to its\ndependencies at this release's version. An edited file whose\nbytes are another published create-ailk version's copy is a stale copy, not\nan edit: it is overwritten or removed as an untouched file is, listed with\nthe version it matched. An edit that touches only comment lines is listed as\n\"comment-only edit\"; on a conflict the template's copy lands. A file at a\ntemplate path that is not in the record (one an earlier sync-routes --apply\nor add-route copied without recording it) whose bytes are a published\ncreate-ailk version's copy \u2014 from the version the site was scaffolded at to\nthis one \u2014 is adopted: recorded and moved forward as an untouched file is,\nlisted under \"Adopted\" with the version it matched. One whose bytes are the\nrunning copy with this site's modules' patches applied (a module's\njest.config.cjs or next.config.mjs edit) is left as it is and not listed.\nOne whose bytes match no published copy is a site edit: skipped, never overwritten, and counted under\n\"Held as site edits, not in the record\". No file under a route the site\nlists in customizations.yaml declined_routes is written: each is listed under\n\"Skipped\" naming the declined route. Every template\ntest, and every site-edited template file, that imports a file left under\n\"Needs review\" (by a relative or @/ import, transitively) is held\nat the site's version with it, its record entry is not advanced, and it is\nlisted under \"Held back with <file>\" \u2014 reconcile the file, then run update\nagain to bring it forward. A skipped file never holds another. A file whose\nown bytes are the record's is not held by what it imports: it moves, unless\nit names an export the held copy lacks, and the held file is listed as\n\"Held back: <file> \u2014 imported by N moved files; the site edit is <hunk\nsummary>\". A written file whose import names a file the site lacks gets it\nadded when this template supplies it; otherwise it is held the same way,\nunder \"Held back with <file> (not in this site)\", unless its own copy\nalready named the file \u2014 then it moves and the path is listed under \"Not in\nthis site or the template: <file>\". A file the template removed is kept\nwhile any file still in the site imports it. Every other file in the run\nstill updates. When project.yaml has an env_contract block, each\nenv var the written files read that has no row gains one; no row is edited.\nA record row at a path create-ailk no longer records is dropped and listed.\nA surface the site's .ailk-site-manifest.json names a page on but\narchitecture.yaml does not declare (one no module owns, such as projects)\ngets its route files added and is declared, listed under \"Surfaces declared\nfrom the roster\". A code-route row of that roster no page file serves is\ndropped, listed under \"Roster rows dropped, no route serves them\".\nA site with no record gets one on its first run, from the version its\n.ailk-site-manifest.json already records. A site scaffolded before\n@working-theory/mcp-server has its copied apps/mcp moved to the boot set:\nthe server and each module's paid MCP pack join apps/mcp/package.json, the\ncopied server files go, and apps/mcp/src/lib/paid-tools.generated.ts is\nrewritten on every run. A site scaffolded before @working-theory/api has its\ncopied apps/api moved to the boot file: the app becomes @working-theory/app-api,\nthe package and the six @working-theory/api-<module> packages join\napps/api/package.json, its bins and build:vercel delegate to the package, and\nthe copied server files go. Run `pnpm install` after either move, since the\napp's package.json gained dependencies. Each mdx-body page in content/ with no\n'# ' heading gets its title and description written into its body as its\nheading and intro, listed under \"Page heading added\"; a page with one heading\nis left as it is, and one with several, or one whose frontmatter it cannot\nread, is listed under \"Needs review\". Each bare { on an mdx-body page is\nescaped as \\{ when the site's own MDX parser then reads the page clean, listed\nunder \"Placeholder brace escaped\"; a page it cannot escape safely, or any page\nwith one while the site's dependencies are not installed, is listed under\n\"Needs review\". Each topology seam (*.generated.* \u2014 the web seam, the\n(authed) gate, the API origin and the MCP seam) is rendered again for the\ntopology and sign-in mode .ailk-site-manifest.json records and listed under\n\"Regenerated\", when its bytes are still the render .ailk-template-files.json\nrecords; one edited by hand, or with no recorded render, is listed under\n\"Needs review\" and left as it is. Last, the generated route files of every installed page\npackage (one whose package.json declares \"ailk\": { \"routes\" }) are rewritten\nfrom its manifest, listed under \"Route files regenerated\"; run\n`create-ailk routes --write` after the install when the packages were not\ninstalled yet. Commit before running, and review the diff after.\n";
160
172
  /** Parse the argv AFTER the `update` word. Strict `node:util` parseArgs, like `parseAdoptArgs`. */
161
173
  export declare function parseUpdateArgs(argv: string[]): UpdateArgs;