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
package/dist/update.js CHANGED
@@ -57,8 +57,11 @@
57
57
  * its bytes are that path's template copy in any published version from
58
58
  * the record's oldest (the manifest's `patternVersion`) to the running one:
59
59
  * recorded, and moved forward as an untouched copy is, named with the
60
- * version it matched. One matching no published copy is the site's own:
61
- * held as a site edit, never overwritten, and counted in the report.
60
+ * version it matched. One whose bytes are the running copy with the site's
61
+ * own modules' patches applied (a module's `jest.config.cjs` or
62
+ * `next.config.mjs` edit, #11591) is left as it is and not listed. One
63
+ * matching no published copy is the site's own: held as a site edit, never
64
+ * overwritten, and counted in the report.
62
65
  *
63
66
  * A skipped file never holds another (#11216): the run has decided not to
64
67
  * manage it, so only a file under review, and what is held with it, holds.
@@ -102,6 +105,7 @@ import { headingViolations, mdxBodyPages, mdxBodyRule, migrateBodyHeadings } fro
102
105
  import { buildScaffoldMarkers, isExcluded, isTextFile, renderTemplateFile, templateDestination } from "./copy.js";
103
106
  import { declinedRouteOfPath, readDeclinedRoutes } from "./declined-routes.js";
104
107
  import { deriveArchitecture } from "./derive-architecture.js";
108
+ import { computeModulePatches } from "./lib/apply-module-patches.js";
105
109
  import { EnvContractError, planEnvRows, readEnvContract, readManifestTopology, } from "./lib/declared-env.js";
106
110
  import { ENV_CATALOG } from "./lib/env-catalog.js";
107
111
  import { assertContentLengthWithinLimit, assertHttpsRegistryUrl, fetchTimeoutSignal, } from "./lib/fetch-guard.js";
@@ -114,11 +118,12 @@ import { MODULE_SLICES } from "./module-architecture.js";
114
118
  import { MODULE_FLAGS_PATH, PAID_MCP_TOOLS_PATH, PAID_SECTIONS_PATH, renderSitePaidSections, writeModuleFlags, writePaidMcpTools, writePaidSectionsRegistry, } from "./paid-sections.js";
115
119
  import { ParseError } from "./parse-args.js";
116
120
  import { RoutesRefusedError, writeRoutes } from "./routes.js";
121
+ import { planSeamRefresh, seamRow, siteSeamRenders } from "./seam-refresh.js";
117
122
  import { SITE_LISTING_PATH } from "./site-listing-path.js";
118
123
  import { SITE_ROSTER_PATH, planServedRoster, readRosterPageRoutes } from "./site-roster.js";
119
124
  import { GATEABLE_SURFACES, excludedRoutePaths, isRemovedPublicRoutePath, resolveSurfaces, surfacesNamedByRoutes, } from "./surfaces.js";
120
125
  import { DATABASE_BOOT_FILES, ROOT_TOOL_FILES, TEMPLATE_RECORD_PATH, isRecordable, parseTemplateRecord, serializeTemplateRecord, sha256Hex, } from "./template-record.js";
121
- import { MCP_SEAM_PATH, MCP_SERVER_HUB, TopologyError, isSpokeExcluded, readSpokeShape, spokeExclusions, } from "./topology.js";
126
+ import { MCP_SEAM_PATH, MCP_SERVER_HUB, SPOKE_SEAM_FILES, TopologyError, isSpokeExcluded, readSpokeShape, spokeExclusions, } from "./topology.js";
122
127
  /** A refusal the CLI exits 2 on, thrown before anything is written. */
123
128
  export class UpdateRefusedError extends Error {
124
129
  exitCode = 2;
@@ -127,6 +132,38 @@ export class UpdateRefusedError extends Error {
127
132
  this.name = "UpdateRefusedError";
128
133
  }
129
134
  }
135
+ /** Every order of `items` — only the given order past 4, where the count would grow past 24 (#11591 D2). */
136
+ function orders(items) {
137
+ if (items.length <= 1 || items.length > 4)
138
+ return [[...items]];
139
+ return items.flatMap((first, i) => orders([...items.slice(0, i), ...items.slice(i + 1)]).map((rest) => [first, ...rest]));
140
+ }
141
+ /**
142
+ * Whether `diskBytes` is `templateBytes` with the `jest-config` /
143
+ * `next-config` patches of the site's `modules` for `path` applied, in some
144
+ * order the modules could have been installed (#11591 D2): the copy a
145
+ * scaffold or `add-module` left, which `planTemplateRecord` keeps out of the
146
+ * record, never a site edit. `false` when no module patches `path`; an order
147
+ * whose patch no longer applies matches nothing.
148
+ */
149
+ export function isModulePatchedCopy(path, templateBytes, diskBytes, modules) {
150
+ const patching = modules
151
+ .map((name) => (MODULE_SLICES[name].patches ?? []).filter((p) => p.target === path && (p.kind === "jest-config" || p.kind === "next-config")))
152
+ .filter((patches) => patches.length > 0);
153
+ if (patching.length === 0)
154
+ return false;
155
+ const template = Buffer.from(templateBytes).toString("utf8");
156
+ const disk = Buffer.from(diskBytes).toString("utf8");
157
+ return orders(patching).some((order) => {
158
+ try {
159
+ const folded = order.reduce((text, patches) => computeModulePatches(patches, { versions: {}, readTarget: () => text })[0]?.content ?? text, template);
160
+ return folded === disk;
161
+ }
162
+ catch {
163
+ return false;
164
+ }
165
+ });
166
+ }
130
167
  /** `buildScaffoldMarkers`, with `CREATE_AILK_VERSION` set to the version being rendered (D3). */
131
168
  function markersForVersion(projectName, version) {
132
169
  return { ...buildScaffoldMarkers(projectName), CREATE_AILK_VERSION: version };
@@ -1604,6 +1641,9 @@ export async function updateSite(opts) {
1604
1641
  adopted.push({ path, version: stale });
1605
1642
  continue;
1606
1643
  }
1644
+ // #11591 — the copy the site's own module patches left: unrecorded and unreported.
1645
+ if (isModulePatchedCopy(path, newBytes, readFileSync(abs), header.modules))
1646
+ continue;
1607
1647
  skipped.push({ path, reason: UNRECORDED_SITE_EDIT });
1608
1648
  continue;
1609
1649
  }
@@ -1689,6 +1729,21 @@ export async function updateSite(opts) {
1689
1729
  if (listingRaw !== undefined && !existsSync(join(targetDir, ...SITE_LISTING_PATH.split("/")))) {
1690
1730
  renders.set(SITE_LISTING_PATH, Buffer.from(renderTemplateFile(listingRaw, SITE_LISTING_PATH, {}, markersForVersion(record.projectName, version))).toString("utf8"));
1691
1731
  }
1732
+ // #11148 — the topology seams still at their recorded render are rendered
1733
+ // again for the site's recorded topology and sign-in mode, so a written
1734
+ // file's import of one reads the new render. The MCP move rewrites a hub's
1735
+ // pre-move MCP seam itself, so that seam is left to it.
1736
+ let seamPlan;
1737
+ try {
1738
+ seamPlan = planSeamRefresh(targetDir, record.seams ?? {}, version, mcpMove?.seam !== undefined ? SPOKE_SEAM_FILES.filter((path) => path !== MCP_SEAM_PATH) : undefined);
1739
+ }
1740
+ catch (err) {
1741
+ if (err instanceof TopologyError)
1742
+ throw new UpdateRefusedError(err.message);
1743
+ throw err;
1744
+ }
1745
+ for (const [path, render] of seamPlan.writes)
1746
+ renders.set(path, render);
1692
1747
  // What the run rewrites after the record's writes, never from the template.
1693
1748
  const rewrittenLater = new Set([
1694
1749
  MODULE_FLAGS_PATH,
@@ -2157,6 +2212,29 @@ export async function updateSite(opts) {
2157
2212
  for (const path of deletes.filter(notHeld)) {
2158
2213
  rmSync(join(targetDir, ...path.split("/")));
2159
2214
  }
2215
+ // #11148 — each planned seam the import pass did not hold, written before
2216
+ // the record that names its render; a seam held there keeps its row.
2217
+ const regenerated = [];
2218
+ const nextSeams = { ...seamPlan.rows };
2219
+ // The MCP move's seam, when it lands as this version's render, is recorded
2220
+ // as one, so the run after the move changes no byte.
2221
+ if (mcpMove?.seam !== undefined && mcpMove.seam === siteSeamRenders(targetDir).get(MCP_SEAM_PATH)) {
2222
+ nextSeams[MCP_SEAM_PATH] = seamRow(mcpMove.seam, version);
2223
+ }
2224
+ for (const [path, render] of seamPlan.writes) {
2225
+ if (renders.get(path) !== render) {
2226
+ const row = record.seams?.[path];
2227
+ if (row !== undefined)
2228
+ nextSeams[path] = row;
2229
+ continue;
2230
+ }
2231
+ const abs = join(targetDir, ...path.split("/"));
2232
+ mkdirSync(dirname(abs), { recursive: true });
2233
+ writeFileSync(abs, render);
2234
+ nextSeams[path] = seamRow(render, version);
2235
+ regenerated.push(path);
2236
+ }
2237
+ const seamsChanged = serializeTemplateRecord({ ...record, seams: nextSeams }) !== serializeTemplateRecord(record);
2160
2238
  const backfilled = backfillPatternVersion !== undefined
2161
2239
  ? { version: backfillPatternVersion, files: Object.keys(record.files).length }
2162
2240
  : undefined;
@@ -2167,11 +2245,12 @@ export async function updateSite(opts) {
2167
2245
  removed: removed.filter(notHeld),
2168
2246
  current: current.filter(notHeld),
2169
2247
  };
2170
- const recordChanged = backfilled !== undefined ||
2248
+ const recordChanged = seamsChanged ||
2249
+ backfilled !== undefined ||
2171
2250
  droppedRows.length > 0 ||
2172
2251
  Object.values(moved).some((paths) => paths.length > 0);
2173
2252
  if (recordChanged) {
2174
- writeFileSync(recordPath, serializeTemplateRecord({ schema: 1, projectName: record.projectName, files: nextFiles }));
2253
+ writeFileSync(recordPath, serializeTemplateRecord({ schema: 1, projectName: record.projectName, files: nextFiles, seams: nextSeams }));
2175
2254
  }
2176
2255
  // #10774 D3 — the surfaces the roster named are declared, as add-route
2177
2256
  // declares one: the whole generated file, re-derived.
@@ -2287,6 +2366,9 @@ export async function updateSite(opts) {
2287
2366
  for (const { path, reason } of headings.refused) {
2288
2367
  review.push({ path: sitePath(path), reason: `no '# ' heading added: ${reason}` });
2289
2368
  }
2369
+ // #11148 — a seam left as the site keeps it, with why; joins `review` after
2370
+ // `heldFiles` was computed, as the heading rows do.
2371
+ review.push(...seamPlan.held);
2290
2372
  // #10773 D6 — a bare `{` on an mdx-body page is MDX code: the page fails or
2291
2373
  // drops it. Escape every one, after the heading pass so its writes are read
2292
2374
  // too, keeping a page's write only when the site's own parser reads it clean.
@@ -2352,6 +2434,7 @@ export async function updateSite(opts) {
2352
2434
  : {}),
2353
2435
  headingsAdded: headings.written.map(sitePath),
2354
2436
  bracesEscaped,
2437
+ ...(regenerated.length > 0 ? { regenerated: regenerated.sort() } : {}),
2355
2438
  ...(routesWritten.length > 0 ? { routesWritten } : {}),
2356
2439
  ...(cliPin !== undefined ? { cliPin } : {}),
2357
2440
  ...(backfilled !== undefined ? { backfilled } : {}),
@@ -2435,6 +2518,7 @@ export function formatUpdateReport(result) {
2435
2518
  ["Already current", result.current],
2436
2519
  ["Page heading added", result.headingsAdded],
2437
2520
  ["Placeholder brace escaped", result.bracesEscaped],
2521
+ ["Regenerated", result.regenerated ?? []],
2438
2522
  ["Route files regenerated", result.routesWritten ?? []],
2439
2523
  ];
2440
2524
  if (result.cliPin !== undefined) {
@@ -2516,6 +2600,7 @@ export function formatUpdateReport(result) {
2516
2600
  result.current.length === 0 &&
2517
2601
  result.headingsAdded.length === 0 &&
2518
2602
  result.bracesEscaped.length === 0 &&
2603
+ result.regenerated === undefined &&
2519
2604
  result.routesWritten === undefined &&
2520
2605
  result.cliPin === undefined &&
2521
2606
  result.review.length === 0 &&
@@ -2571,8 +2656,10 @@ template path that is not in the record (one an earlier sync-routes --apply
2571
2656
  or add-route copied without recording it) whose bytes are a published
2572
2657
  create-ailk version's copy — from the version the site was scaffolded at to
2573
2658
  this one — is adopted: recorded and moved forward as an untouched file is,
2574
- listed under "Adopted" with the version it matched. One whose bytes match no
2575
- published copy is a site edit: skipped, never overwritten, and counted under
2659
+ listed under "Adopted" with the version it matched. One whose bytes are the
2660
+ running copy with this site's modules' patches applied (a module's
2661
+ jest.config.cjs or next.config.mjs edit) is left as it is and not listed.
2662
+ One whose bytes match no published copy is a site edit: skipped, never overwritten, and counted under
2576
2663
  "Held as site edits, not in the record". No file under a route the site
2577
2664
  lists in customizations.yaml declined_routes is written: each is listed under
2578
2665
  "Skipped" naming the declined route. Every template
@@ -2616,7 +2703,12 @@ read, is listed under "Needs review". Each bare { on an mdx-body page is
2616
2703
  escaped as \\{ when the site's own MDX parser then reads the page clean, listed
2617
2704
  under "Placeholder brace escaped"; a page it cannot escape safely, or any page
2618
2705
  with one while the site's dependencies are not installed, is listed under
2619
- "Needs review". Last, the generated route files of every installed page
2706
+ "Needs review". Each topology seam (*.generated.* — the web seam, the
2707
+ (authed) gate, the API origin and the MCP seam) is rendered again for the
2708
+ topology and sign-in mode .ailk-site-manifest.json records and listed under
2709
+ "Regenerated", when its bytes are still the render .ailk-template-files.json
2710
+ records; one edited by hand, or with no recorded render, is listed under
2711
+ "Needs review" and left as it is. Last, the generated route files of every installed page
2620
2712
  package (one whose package.json declares "ailk": { "routes" }) are rewritten
2621
2713
  from its manifest, listed under "Route files regenerated"; run
2622
2714
  \`create-ailk routes --write\` after the install when the packages were not
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ailk",
3
- "version": "0.40.0",
3
+ "version": "0.40.2",
4
4
  "description": "Scaffolder for AI Launch Kit — `pnpm create ailk@latest <dir>` produces a starter repo consuming @working-theory/* from npm (per ADR 0007).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "tar": "^7.5.21"
29
29
  },
30
30
  "devDependencies": {
31
- "@working-theory/schema": "0.64.0",
32
- "@working-theory/templates": "0.64.0"
31
+ "@working-theory/schema": "0.66.0",
32
+ "@working-theory/templates": "0.66.0"
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
@@ -195,6 +195,12 @@ CONTENT_ADAPTER=mdx
195
195
  # start at FRONTEND_URL (https only outside development).
196
196
  # AILK_INBOX_FROM=
197
197
  #
198
+ # The hub Admin's absolute https URL (admin-team-invitation-accept). Optional:
199
+ # a team invitation's link opens its sign-in, then /invitations/<id>. Unset,
200
+ # or invalid (logged once), the link uses admin.<FRONTEND_URL host>. apps/web
201
+ # reads it too, to send a retired /account/invitations/<id> link on.
202
+ # AILK_ADMIN_URL=https://admin.example.com
203
+ #
198
204
  # The Resend Contacts audience the #4732 follow-up sweep checks before
199
205
  # sending — a lead found unsubscribed in this audience is suppressed.
200
206
  # Optional: unset degrades to "cannot verify — proceed" (never to "block all
@@ -71,6 +71,9 @@ jobs:
71
71
  - run: pnpm content-source:check
72
72
  # A bare { on an mdx-body page, which fails the page or drops it (#10773).
73
73
  - run: pnpm mdx-body:check
74
+ # apps/web's generated route files match the installed page packages
75
+ # (#11219) — the same check `pnpm preflight` runs locally.
76
+ - run: pnpm routes:check
74
77
 
75
78
  - run: pnpm test
76
79
 
@@ -26,6 +26,9 @@ FRONTEND_URL=http://localhost:3000
26
26
  # One Tap ID token against Google's keys with this as its audience, and client
27
27
  # info names it to the spoke. List each One Tap spoke's origin on that Google
28
28
  # client's authorized JavaScript origins. Unset: the route answers 404.
29
+ # List only spokes you trust with each other's One Tap sign-ins: every One Tap
30
+ # spoke shares this one audience, so any listed One Tap spoke can replay a
31
+ # person's One Tap token to another (#11109, SEC-11109-1).
29
32
  # AILK_GOOGLE_ONE_TAP_CLIENT_ID=
30
33
 
31
34
  # =============================================================================
@@ -39,6 +42,15 @@ FRONTEND_URL=http://localhost:3000
39
42
  # any other value fails closed: every OAuth token is refused.
40
43
  # MCP_OAUTH_ISSUER=admin
41
44
 
45
+ # =============================================================================
46
+ # Admin URL (admin-team-invitation-accept)
47
+ # =============================================================================
48
+ # Optional. The hub Admin's absolute https URL (http only on a loopback host).
49
+ # A team invitation's email and copied link open its sign-in, which leads to
50
+ # /invitations/<id>. Unset — or not a valid https URL, which is logged once —
51
+ # the link uses admin.<FRONTEND_URL host>, with a leading www. dropped.
52
+ # AILK_ADMIN_URL=https://admin.example.com
53
+
42
54
  # =============================================================================
43
55
  # Local Database (required in production)
44
56
  # =============================================================================