create-ailk 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +22 -0
  2. package/dist/cli.js +34 -0
  3. package/dist/compare-renders.d.ts +67 -0
  4. package/dist/compare-renders.js +274 -0
  5. package/dist/export-content.d.ts +10 -3
  6. package/dist/export-content.js +52 -8
  7. package/dist/lib/import-mdx.d.ts +22 -0
  8. package/dist/lib/import-mdx.js +73 -18
  9. package/dist/lib/render-capture.d.ts +22 -0
  10. package/dist/lib/render-capture.js +125 -0
  11. package/dist/migrate-content.d.ts +12 -3
  12. package/dist/migrate-content.js +65 -12
  13. package/package.json +3 -3
  14. package/site-templates/shapes/local-business-service/content/en/Service/first-job.mdx +49 -26
  15. package/site-templates/shapes/local-business-service/content/en/Service/second-job.mdx +49 -26
  16. package/site-templates/shapes/local-business-service/content/en/Service/third-job.mdx +49 -26
  17. package/site-templates/shapes/organization-service/content/en/Service/first-engagement.mdx +49 -26
  18. package/site-templates/shapes/organization-service/content/en/Service/second-engagement.mdx +49 -26
  19. package/site-templates/shapes/organization-service/content/en/Service/third-engagement.mdx +49 -26
  20. package/site-templates/shapes/person-service/content/en/Service/first-engagement.mdx +49 -26
  21. package/site-templates/shapes/person-service/content/en/Service/second-engagement.mdx +49 -26
  22. package/site-templates/shapes/person-service/content/en/Service/third-engagement.mdx +49 -26
  23. package/templates/apps/api/CLAUDE.md +18 -4
  24. package/templates/apps/mcp/CLAUDE.md +31 -4
  25. package/templates/apps/web/CLAUDE.md +3 -1
  26. package/versions.json +51 -51
package/README.md CHANGED
@@ -990,6 +990,28 @@ reads it from, with its words moved back into its sections, so a re-run of
990
990
  `migrate-content` reports every page `unchanged`. The full sequence, the
991
991
  evidence each step leaves and each step's rollback are in the cutover runbook.
992
992
 
993
+ ### Comparing pages before and after the heading-form conversion
994
+
995
+ The hub's heading-form conversion (#11794) writes each page still in the
996
+ heading form a new draft in the section form, and its plan lists the
997
+ converted Live pages. No URL serves a draft, so `compare-renders` takes the
998
+ "before" over time: capture the live pages before their drafts are published,
999
+ then compare the same URLs after, with the cutover's own comparison (text,
1000
+ JSON-LD and a full-page screenshot at 1440 and 390 wide) and a sweep of every
1001
+ path for a direct 200.
1002
+
1003
+ ```bash
1004
+ create-ailk compare-renders . --origin https://example.com --plan ~/.ailk-heading-form/plan.json --workspace <wksp_id> --capture .heading-form/example/before
1005
+ # … the drafts are written and published (docs/internal/runbooks/heading-form-conversion.md) …
1006
+ create-ailk compare-renders . --origin https://example.com --plan ~/.ailk-heading-form/plan.json --workspace <wksp_id> --against .heading-form/example/before
1007
+ # → .heading-form/example/before/comparison/{comparison.json,comparison.md,shots/}
1008
+ ```
1009
+
1010
+ It compares the workspace's live, converted rows in `--locale` (default `en`)
1011
+ that have a path, and lists every other live row as not compared. It needs
1012
+ Playwright's Chromium in the site, as `cutover` does. It exits 1 when a page
1013
+ differs or a URL is not 200, and 2 on a refusal.
1014
+
993
1015
  ### A spoke's declared environment
994
1016
 
995
1017
  A spoke scaffold's `pnpm preflight` and CI run `pnpm env:declared`: every
package/dist/cli.js CHANGED
@@ -81,6 +81,7 @@ import { ADD_ROUTE_HELP, AddRouteRefusedError, MAGNET_ROUTE, addMagnetToScaffold
81
81
  import { ADOPT_HELP, AdoptRefusedError, adoptSite, formatAdoptReport, parseAdoptArgs, } from "./adopt.js";
82
82
  import { APPLY_DESIGN_HELP, applyDesign, formatApplyDesignReport, parseApplyDesignArgs, } from "./apply-design.js";
83
83
  import { CLAUDE_MD_CHECK_PATH } from "./claude-md.js";
84
+ import { COMPARE_RENDERS_HELP, CompareRendersRefusedError, compareRenders, parseCompareRendersArgs, } from "./compare-renders.js";
84
85
  import { buildScaffoldMarkers } from "./copy.js";
85
86
  import { CUTOVER_HELP, CutoverRefusedError, cutover, parseCutoverArgs, } from "./cutover.js";
86
87
  import { EXPORT_CONTENT_HELP, ExportContentRefusedError, exportContent, parseExportContentArgs, } from "./export-content.js";
@@ -89,6 +90,7 @@ import { ImportMdxRefusedError } from "./lib/import-mdx.js";
89
90
  import { assertKeyedOrFreeReleased, assertReleased } from "./lib/module-license-gate.js";
90
91
  import { withNpmTokenUserConfig } from "./lib/npm-auth.js";
91
92
  import { FREE_PREREQUISITES_NOTE, LICENSED_PREREQUISITES_NOTE, isLicensedInstall, proCallout, } from "./lib/pro-callout.js";
93
+ import { loadChromium } from "./lib/render-comparison.js";
92
94
  import { LICENSE_SET_HELP, runLicenseSet } from "./license-set.js";
93
95
  import { MIGRATE_CONTENT_HELP, MigrateContentRefusedError, migrateContent, parseMigrateContentArgs, } from "./migrate-content.js";
94
96
  import { PLUGIN_INSTALL_LINES, ParseError, helpText, parseCliArgs, parseModules, resolveCliShape, toScaffoldOptions, } from "./parse-args.js";
@@ -456,6 +458,38 @@ async function main() {
456
458
  process.exit(2);
457
459
  }
458
460
  }
461
+ // `compare-renders [dir]` (#11794): capture the heading-form conversion's
462
+ // converted Live pages before their publish, and compare them after.
463
+ if (argv[0] === "compare-renders") {
464
+ try {
465
+ const args = parseCompareRendersArgs(argv.slice(1));
466
+ if (args.help) {
467
+ process.stdout.write(COMPARE_RENDERS_HELP);
468
+ process.exit(0);
469
+ }
470
+ const { exitCode } = await compareRenders({
471
+ origin: args.origin,
472
+ plan: args.plan,
473
+ workspaceId: args.workspaceId,
474
+ ...(args.locale !== undefined && { locale: args.locale }),
475
+ ...(args.capture !== undefined && { capture: args.capture }),
476
+ ...(args.against !== undefined && { against: args.against }),
477
+ ...(args.out !== undefined && { out: args.out }),
478
+ ...(args.tolerance !== undefined && { tolerance: args.tolerance }),
479
+ chromium: loadChromium([resolve(args.target ?? process.cwd())]),
480
+ fetch: globalThis.fetch,
481
+ onLine: (line) => process.stdout.write(`${line}\n`),
482
+ });
483
+ process.exit(exitCode);
484
+ }
485
+ catch (err) {
486
+ if (!(err instanceof ParseError) && !(err instanceof CompareRendersRefusedError)) {
487
+ throw err;
488
+ }
489
+ process.stderr.write(`[create-ailk] ${err.message}\n`);
490
+ process.exit(2);
491
+ }
492
+ }
459
493
  // `routes --write | --check [dir]` (#11219, ADR 0040 rule 3): the one
460
494
  // route-file generator, over the manifests of the site's installed page
461
495
  // packages. Check mode exits 1 iff a generated file is missing, stale or
@@ -0,0 +1,67 @@
1
+ import { type ChromiumLike } from "./lib/render-comparison.js";
2
+ /** A refusal before anything is rendered: exit 2. */
3
+ export declare class CompareRendersRefusedError extends Error {
4
+ name: string;
5
+ }
6
+ /** One plan row as this command reads it. */
7
+ interface PlanRow {
8
+ workspaceId: string;
9
+ path: string | null;
10
+ locale?: string;
11
+ live: boolean;
12
+ class: string | null;
13
+ outcome: string;
14
+ reason?: string;
15
+ }
16
+ export interface CompareRendersOptions {
17
+ origin: string;
18
+ /** The plan file `convert-heading-form --plan` wrote. */
19
+ plan: string;
20
+ workspaceId: string;
21
+ /** The locale the origin serves at its unprefixed paths. Default `en`. */
22
+ locale?: string;
23
+ /** `--capture <dir>`: record the before renders. */
24
+ capture?: string;
25
+ /** `--against <dir>`: compare the live renders with that capture. */
26
+ against?: string;
27
+ /** Where the comparison's evidence goes; default `<against>/comparison`. */
28
+ out?: string;
29
+ tolerance?: number;
30
+ /** Playwright's `chromium`, from the site's own install; `undefined` refuses. */
31
+ chromium: ChromiumLike | undefined;
32
+ fetch: typeof globalThis.fetch;
33
+ onLine?: (line: string) => void;
34
+ now?: () => Date;
35
+ }
36
+ /**
37
+ * The plan's pages to compare for `workspaceId` (D6): live, in `locale`, with
38
+ * a path, and converted — or held only as `draft-ahead`, compared after the
39
+ * operator's own publish. Every other live row of the workspace is listed as
40
+ * not compared, with why.
41
+ */
42
+ export declare function comparedPaths(rows: readonly PlanRow[], workspaceId: string, locale: string): {
43
+ paths: string[];
44
+ notCompared: {
45
+ path: string | null;
46
+ reason: string;
47
+ }[];
48
+ };
49
+ /** Captures or compares (D6); answers the exit code: 0 all pass, 1 a page or URL failed. */
50
+ export declare function compareRenders(o: CompareRendersOptions): Promise<{
51
+ exitCode: number;
52
+ }>;
53
+ export interface CompareRendersArgs {
54
+ target: string | undefined;
55
+ origin: string | undefined;
56
+ plan: string | undefined;
57
+ workspaceId: string | undefined;
58
+ locale: string | undefined;
59
+ capture: string | undefined;
60
+ against: string | undefined;
61
+ out: string | undefined;
62
+ tolerance: number | undefined;
63
+ help: boolean;
64
+ }
65
+ export declare const COMPARE_RENDERS_HELP = "create-ailk compare-renders \u2014 before-and-after renders of the pages the heading-form conversion changed.\n\nUsage:\n create-ailk compare-renders [<dir>] --origin <url> --plan <file> --workspace <wksp_id> --capture <dir>\n create-ailk compare-renders [<dir>] --origin <url> --plan <file> --workspace <wksp_id> --against <dir> [--out <dir>] [--tolerance <share>]\n\nArguments:\n <dir> The site, whose Playwright runs the browser. Defaults to the current dir.\n\nOptions:\n --origin <url> The live site.\n --plan <file> The plan convert-heading-form --plan wrote.\n --workspace <wksp_id> The site's workspace: only its rows are compared.\n --locale <locale> The locale the site serves at its unprefixed paths. Default en.\n --capture <dir> Record each converted Live page before its draft is published.\n --against <dir> Compare each page now with that capture, then sweep every path for a 200.\n --out <dir> Where comparison.json, comparison.md and shots/ go. Default <against>/comparison.\n --tolerance <share> The share of a screenshot's pixels that may differ. Default 0.\n -h, --help Show this help.\n\nText, JSON-LD and a full-page screenshot are compared at 1440 and 390 wide.\nNeeds Playwright's Chromium in the site: pnpm add -D @playwright/test && pnpm exec playwright install chromium.\nThe runbook is docs/internal/runbooks/heading-form-conversion.md.\nExit 0 when every page is the same and every URL answers 200, 1 when one is\nnot, 2 on a refusal.\n";
66
+ export declare function parseCompareRendersArgs(argv: string[]): CompareRendersArgs;
67
+ export {};
@@ -0,0 +1,274 @@
1
+ /**
2
+ * `create-ailk compare-renders` (#11794 D6, spec
3
+ * docs/specs/11794-convert-the-remaining-heading-form-spec.md): the
4
+ * before-and-after evidence for the heading-form conversion.
5
+ *
6
+ * No URL serves a draft, so "before" is taken over time: `--capture` records
7
+ * each converted Live page of the plan from the live site before its new
8
+ * draft is published, and `--against` replays that capture as the `before`
9
+ * side of the cutover kit's own `comparePage` (text, JSON-LD and pixels at
10
+ * 1440 and 390 wide), with the live site as `after`, then sweeps every path
11
+ * for a direct 200. `render-comparison.ts` is used as it is: the replay is
12
+ * the only new seam (`lib/render-capture.ts`).
13
+ *
14
+ * The plan is the one `convert-heading-form --plan` writes. Its rows hold no
15
+ * words; a row with no path is listed as not compared, never joined to the
16
+ * origin.
17
+ *
18
+ * Pure module: no `import.meta.url`, so jest imports it directly; the browser
19
+ * and `fetch` are injected.
20
+ */
21
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
22
+ import { join } from "node:path";
23
+ import { parseArgs } from "node:util";
24
+ import { recordingPage, replayPage } from "./lib/render-capture.js";
25
+ import { comparePage, comparisonMarkdown, PLAYWRIGHT_INSTALL_HINT, sweep, } from "./lib/render-comparison.js";
26
+ import { ParseError } from "./parse-args.js";
27
+ /** A refusal before anything is rendered: exit 2. */
28
+ export class CompareRendersRefusedError extends Error {
29
+ name = "CompareRendersRefusedError";
30
+ }
31
+ /**
32
+ * The plan's pages to compare for `workspaceId` (D6): live, in `locale`, with
33
+ * a path, and converted — or held only as `draft-ahead`, compared after the
34
+ * operator's own publish. Every other live row of the workspace is listed as
35
+ * not compared, with why.
36
+ */
37
+ export function comparedPaths(rows, workspaceId, locale) {
38
+ const paths = [];
39
+ const notCompared = [];
40
+ for (const row of rows) {
41
+ if (row.workspaceId !== workspaceId || !row.live)
42
+ continue;
43
+ const converted = row.class !== null &&
44
+ (row.outcome === "converted" ||
45
+ row.outcome === "would-convert" ||
46
+ (row.outcome === "held" && row.reason === "draft-ahead"));
47
+ if (!converted)
48
+ notCompared.push({ path: row.path, reason: `${row.outcome}${row.reason ? `: ${row.reason}` : ""}` });
49
+ else if (row.path === null)
50
+ notCompared.push({ path: null, reason: "no path" });
51
+ else if (!isSitePath(row.path))
52
+ notCompared.push({ path: row.path, reason: "not a site path" });
53
+ else if ((row.locale ?? locale) !== locale)
54
+ notCompared.push({ path: row.path, reason: `locale ${row.locale}` });
55
+ else if (!paths.includes(row.path))
56
+ paths.push(row.path);
57
+ }
58
+ return { paths, notCompared };
59
+ }
60
+ /**
61
+ * Whether `path` is a path on any origin it is joined to: `/`-rooted, not
62
+ * `//`, and resolving to itself. The plan is a file on disk, so its paths are
63
+ * checked again here, never joined to the origin as written.
64
+ */
65
+ function isSitePath(path) {
66
+ if (typeof path !== "string" || !/^\/(?!\/)/.test(path))
67
+ return false;
68
+ const probe = "https://origin.invalid";
69
+ try {
70
+ const url = new URL(path, probe);
71
+ return url.origin === probe && url.pathname === path;
72
+ }
73
+ catch {
74
+ return false;
75
+ }
76
+ }
77
+ function readPlan(file) {
78
+ if (!existsSync(file))
79
+ throw new CompareRendersRefusedError(`compare-renders: no plan at ${file}`);
80
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
81
+ if (!Array.isArray(parsed.pages))
82
+ throw new CompareRendersRefusedError(`compare-renders: ${file} is not a plan`);
83
+ return parsed.pages;
84
+ }
85
+ /** A page that never renders: the capture's `after` side, so `comparePage` drives only the recording. */
86
+ const NO_PAGE = {
87
+ async setViewportSize() { },
88
+ async goto() {
89
+ return null;
90
+ },
91
+ url: () => "about:blank",
92
+ async evaluate() {
93
+ return undefined;
94
+ },
95
+ async screenshot() {
96
+ return Buffer.alloc(0);
97
+ },
98
+ };
99
+ /** Captures or compares (D6); answers the exit code: 0 all pass, 1 a page or URL failed. */
100
+ export async function compareRenders(o) {
101
+ const line = o.onLine ?? (() => { });
102
+ if ((o.capture === undefined) === (o.against === undefined)) {
103
+ throw new CompareRendersRefusedError("compare-renders: pass exactly one of --capture <dir> and --against <dir>");
104
+ }
105
+ let origin;
106
+ try {
107
+ origin = new URL(o.origin).origin;
108
+ }
109
+ catch {
110
+ throw new CompareRendersRefusedError(`compare-renders: --origin ${o.origin} is not a URL`);
111
+ }
112
+ if (!/^https?:$/.test(new URL(origin).protocol)) {
113
+ throw new CompareRendersRefusedError("compare-renders: --origin must be an http(s) URL");
114
+ }
115
+ const rows = readPlan(o.plan);
116
+ if (!rows.some((row) => row.workspaceId === o.workspaceId)) {
117
+ throw new CompareRendersRefusedError(`compare-renders: the plan has no page of workspace ${o.workspaceId}`);
118
+ }
119
+ if (o.chromium === undefined) {
120
+ throw new CompareRendersRefusedError(`compare-renders: Playwright's Chromium was not found in the site; install it: ${PLAYWRIGHT_INSTALL_HINT}`);
121
+ }
122
+ const { paths, notCompared } = comparedPaths(rows, o.workspaceId, o.locale ?? "en");
123
+ for (const row of notCompared)
124
+ line(`not compared ${row.path ?? "(no path)"} — ${row.reason}`);
125
+ const browser = await o.chromium.launch();
126
+ try {
127
+ if (o.capture !== undefined) {
128
+ const dir = o.capture;
129
+ mkdirSync(dir, { recursive: true });
130
+ const live = await (await browser.newContext()).newPage();
131
+ const recording = recordingPage(live, { dir, origin, paths });
132
+ let failed = 0;
133
+ for (const [i, path] of paths.entries()) {
134
+ const result = await comparePage({
135
+ path,
136
+ n: i + 1,
137
+ before: { origin, page: recording },
138
+ after: { origin, page: NO_PAGE },
139
+ tolerance: 0,
140
+ screenshots: true,
141
+ writeShot: () => { },
142
+ });
143
+ const rendered = result.viewports.every((v) => v.render.before === "ok");
144
+ if (!rendered)
145
+ failed += 1;
146
+ line(`${rendered ? "captured" : "NOT CAPTURED"} ${path}`);
147
+ }
148
+ writeFileSync(join(dir, "capture.json"), `${JSON.stringify({ origin, paths, at: (o.now ?? (() => new Date()))().toISOString() }, null, 2)}\n`);
149
+ return { exitCode: failed === 0 ? 0 : 1 };
150
+ }
151
+ const dir = o.against;
152
+ const captureFile = join(dir, "capture.json");
153
+ if (!existsSync(captureFile))
154
+ throw new CompareRendersRefusedError(`compare-renders: no capture at ${dir}`);
155
+ const captured = JSON.parse(readFileSync(captureFile, "utf8"));
156
+ const capturedPaths = Array.isArray(captured.paths) ? captured.paths.map(String) : [];
157
+ const out = o.out ?? join(dir, "comparison");
158
+ const shots = join(out, "shots");
159
+ mkdirSync(shots, { recursive: true });
160
+ const before = replayPage({ dir, origin, paths: capturedPaths });
161
+ const after = await (await browser.newContext()).newPage();
162
+ const pages = [];
163
+ for (const [i, path] of paths.entries()) {
164
+ const result = await comparePage({
165
+ path,
166
+ n: i + 1,
167
+ before: { origin, page: before },
168
+ after: { origin, page: after },
169
+ tolerance: o.tolerance ?? 0,
170
+ screenshots: true,
171
+ writeShot: (name, png) => writeFileSync(join(shots, name), png),
172
+ });
173
+ line(`${result.pass ? "same" : "DIFFERS"} ${path}`);
174
+ pages.push(result);
175
+ }
176
+ const swept = await sweep({ origin, paths, fetch: o.fetch });
177
+ const report = { before: `${origin} (captured)`, after: origin, pages, sweep: swept };
178
+ writeFileSync(join(out, "comparison.json"), `${JSON.stringify({ ...report, notCompared }, null, 2)}\n`);
179
+ const unlisted = notCompared.length === 0
180
+ ? ""
181
+ : [
182
+ "",
183
+ `## Not compared: ${notCompared.length} live page(s)`,
184
+ "",
185
+ ...notCompared.map((row) => `- \`${row.path ?? "(no path)"}\` — ${row.reason}`),
186
+ "",
187
+ ].join("\n");
188
+ writeFileSync(join(out, "comparison.md"), comparisonMarkdown(report) + unlisted);
189
+ const pass = swept.pass && pages.every((p) => p.pass);
190
+ line(`${pass ? "PASS" : "FAIL"}: ${pages.filter((p) => p.pass).length}/${pages.length} page(s) the same; evidence in ${out}`);
191
+ return { exitCode: pass ? 0 : 1 };
192
+ }
193
+ finally {
194
+ await browser.close();
195
+ }
196
+ }
197
+ export const COMPARE_RENDERS_HELP = `create-ailk compare-renders — before-and-after renders of the pages the heading-form conversion changed.
198
+
199
+ Usage:
200
+ create-ailk compare-renders [<dir>] --origin <url> --plan <file> --workspace <wksp_id> --capture <dir>
201
+ create-ailk compare-renders [<dir>] --origin <url> --plan <file> --workspace <wksp_id> --against <dir> [--out <dir>] [--tolerance <share>]
202
+
203
+ Arguments:
204
+ <dir> The site, whose Playwright runs the browser. Defaults to the current dir.
205
+
206
+ Options:
207
+ --origin <url> The live site.
208
+ --plan <file> The plan convert-heading-form --plan wrote.
209
+ --workspace <wksp_id> The site's workspace: only its rows are compared.
210
+ --locale <locale> The locale the site serves at its unprefixed paths. Default en.
211
+ --capture <dir> Record each converted Live page before its draft is published.
212
+ --against <dir> Compare each page now with that capture, then sweep every path for a 200.
213
+ --out <dir> Where comparison.json, comparison.md and shots/ go. Default <against>/comparison.
214
+ --tolerance <share> The share of a screenshot's pixels that may differ. Default 0.
215
+ -h, --help Show this help.
216
+
217
+ Text, JSON-LD and a full-page screenshot are compared at 1440 and 390 wide.
218
+ Needs Playwright's Chromium in the site: ${PLAYWRIGHT_INSTALL_HINT}.
219
+ The runbook is docs/internal/runbooks/heading-form-conversion.md.
220
+ Exit 0 when every page is the same and every URL answers 200, 1 when one is
221
+ not, 2 on a refusal.
222
+ `;
223
+ export function parseCompareRendersArgs(argv) {
224
+ let parsed;
225
+ try {
226
+ parsed = parseArgs({
227
+ args: argv,
228
+ strict: true,
229
+ allowPositionals: true,
230
+ options: {
231
+ origin: { type: "string" },
232
+ plan: { type: "string" },
233
+ workspace: { type: "string" },
234
+ locale: { type: "string" },
235
+ capture: { type: "string" },
236
+ against: { type: "string" },
237
+ out: { type: "string" },
238
+ tolerance: { type: "string" },
239
+ help: { type: "boolean", default: false, short: "h" },
240
+ },
241
+ });
242
+ }
243
+ catch (err) {
244
+ throw new ParseError(`compare-renders: ${err.message}`);
245
+ }
246
+ const [target, ...rest] = parsed.positionals;
247
+ if (rest.length > 0) {
248
+ throw new ParseError(`compare-renders takes at most one site directory, got ${parsed.positionals.length} arguments`);
249
+ }
250
+ const raw = parsed.values.tolerance;
251
+ const tolerance = raw === undefined ? undefined : Number(raw);
252
+ if (tolerance !== undefined && (raw.trim() === "" || Number.isNaN(tolerance) || tolerance < 0 || tolerance > 1)) {
253
+ throw new ParseError("compare-renders: --tolerance must be a number from 0 to 1");
254
+ }
255
+ const help = parsed.values.help === true;
256
+ if (!help) {
257
+ for (const name of ["origin", "plan", "workspace"]) {
258
+ if (parsed.values[name] === undefined)
259
+ throw new ParseError(`compare-renders: --${name} is required`);
260
+ }
261
+ }
262
+ return {
263
+ target,
264
+ origin: parsed.values.origin,
265
+ plan: parsed.values.plan,
266
+ workspaceId: parsed.values.workspace,
267
+ locale: parsed.values.locale,
268
+ capture: parsed.values.capture,
269
+ against: parsed.values.against,
270
+ out: parsed.values.out,
271
+ tolerance,
272
+ help,
273
+ };
274
+ }
@@ -5,6 +5,10 @@ export declare class ExportContentRefusedError extends Error {
5
5
  readonly exitCode = 2;
6
6
  constructor(message: string);
7
7
  }
8
+ /** The site's words codec, and the importer's tag rule when the site's validation package carries it. */
9
+ type ExportCodec = WordsCodec & {
10
+ publicPageTags?: (tags: readonly unknown[]) => string[];
11
+ };
8
12
  export declare const SPOKE_HINT = "the site's read does not serve this workspace's published version \u2014 is the spoke at --store database?";
9
13
  /**
10
14
  * The site-relative file a stored page is written to, and whether it is
@@ -18,7 +22,7 @@ export declare function fileFor(targetDir: string, type: string, slug: string, l
18
22
  * The file whose import yields `content` again with `sections` as its layout,
19
23
  * or why there is none.
20
24
  */
21
- export declare function recombine(content: Record<string, unknown>, sections: readonly unknown[] | undefined, codec: WordsCodec, editorial: boolean, pinned?: Record<LanguageItemKind, Map<string, Record<string, string>>>): {
25
+ export declare function recombine(content: Record<string, unknown>, sections: readonly unknown[] | undefined, codec: ExportCodec, editorial: boolean, pinned?: Record<LanguageItemKind, Map<string, Record<string, string>>>): {
22
26
  text: string;
23
27
  } | {
24
28
  reason: string;
@@ -32,7 +36,9 @@ export interface ExportContentOptions {
32
36
  env?: NodeJS.ProcessEnv;
33
37
  fetch?: typeof globalThis.fetch;
34
38
  /** Injectable for tests; defaults to the site's installed codec. */
35
- codec?: WordsCodec;
39
+ codec?: ExportCodec;
40
+ /** Injectable for tests; the wait before a rate-limited retry. */
41
+ sleep?: (ms: number) => Promise<void>;
36
42
  onLine?: (line: string) => void;
37
43
  }
38
44
  export interface ExportedPage {
@@ -54,5 +60,6 @@ export interface ExportContentArgs {
54
60
  workspaceId: string | undefined;
55
61
  help: boolean;
56
62
  }
57
- export declare const EXPORT_CONTENT_HELP = "create-ailk export-content \u2014 write every published page back to its content file.\n\nUsage:\n AILK_AGENT_KEY=<key> create-ailk export-content [<dir>] [--dry-run] [--api-url <origin>] [--workspace <wksp_id>]\n\nArguments:\n <dir> The site. Defaults to the current dir.\n\nOptions:\n --dry-run Print what would be written, and write nothing.\n --api-url <origin> The API origin that holds the workspace \u2014 on a\n spoke, its hub's. Else AILK_API_URL.\n --workspace <wksp_id> The workspace. Else AILK_WORKSPACE_ID.\n -h, --help Show this help.\n\nThe rollback for a cutover: every page the workspace list reports published\nin the default locale is written to the file migrate-content reads it from\n\u2014 content/en/<Type>/<slug>.mdx (or the legacy content/<Type>/<slug>.mdx that\nexists), apps/web/content/en/blog/<slug>.mdx for a post,\napps/web/content/en/blog/<series>/<slug>.mdx for a post in a series and the\nsame under docs for a docs page; a post or doc goes to whichever of\n<slug>.mdx or <slug>/index.mdx is on disk, <slug>.mdx when neither is \u2014 with\nits words moved back into its sections, so a re-run of migrate-content\nreports every page unchanged. Published edits are\nkept. A page with a draft ahead of its published version fails by name:\npublish or revert it in Admin, then re-run. The site's own API read must\nserve the workspace's published version (on a spoke, the hub's row at\n--store database). Each page prints created, written, unchanged or failed.\nThe agent key needs the content-edit grant; on a spoke, AILK_SPOKE_KEY is\nneeded too. Exit 0 when no page failed, 1 when any did, 2 on a refusal.\n";
63
+ export declare const EXPORT_CONTENT_HELP = "create-ailk export-content \u2014 write every published page back to its content file.\n\nUsage:\n AILK_AGENT_KEY=<key> create-ailk export-content [<dir>] [--dry-run] [--api-url <origin>] [--workspace <wksp_id>]\n\nArguments:\n <dir> The site. Defaults to the current dir.\n\nOptions:\n --dry-run Print what would be written, and write nothing.\n --api-url <origin> The API origin that holds the workspace \u2014 on a\n spoke, its hub's. Else AILK_API_URL.\n --workspace <wksp_id> The workspace. Else AILK_WORKSPACE_ID.\n -h, --help Show this help.\n\nThe rollback for a cutover: every page the workspace list reports published\nin the default locale is written to the file migrate-content reads it from\n\u2014 content/en/<Type>/<slug>.mdx (or the legacy content/<Type>/<slug>.mdx that\nexists), apps/web/content/en/blog/<slug>.mdx for a post,\napps/web/content/en/blog/<series>/<slug>.mdx for a post in a series and the\nsame under docs for a docs page; a post or doc goes to whichever of\n<slug>.mdx or <slug>/index.mdx is on disk, <slug>.mdx when neither is \u2014 with\nits words moved back into its sections, so a re-run of migrate-content\nreports every page unchanged. Published edits are kept. The hub's own tags\nare not written: a blog post keeps its public tags, every other page none. A\nrate-limited read waits out its retry-after, up to three times, and\ncontinues. A page with a draft ahead of its published version fails by name:\npublish or revert it in Admin, then re-run. The site's own API read must\nserve the workspace's published version (on a spoke, the hub's row at\n--store database). Each page prints created, written, unchanged or failed.\nThe agent key needs the content-edit grant; on a spoke, AILK_SPOKE_KEY is\nneeded too. Exit 0 when no page failed, 1 when any did, 2 on a refusal.\n";
58
64
  export declare function parseExportContentArgs(argv: string[]): ExportContentArgs;
65
+ export {};
@@ -52,6 +52,12 @@ const EDITORIAL_DIRS = {
52
52
  const EDITORIAL_RENAMES = { publishedAt: "date", updatedAt: "updated" };
53
53
  /** Keys an editorial file does not carry: its path decides both. */
54
54
  const EDITORIAL_DROPPED = new Set(["type", "slug"]);
55
+ /**
56
+ * The blog collection, whose sent `tags` the store keeps (`PAGE_TAG_TYPES`,
57
+ * the validation package's `site-fields.ts`, restated: no runtime dep). Every
58
+ * other page's stored `tags` are the hub's own (#11750 D2).
59
+ */
60
+ const BLOG_TAG_TYPES = new Set(["BlogPosting", "BlogList"]);
55
61
  /** The hub's live-source mark (#10898 D7): evidence about the draft's words, never a file's key. */
56
62
  const LIVE_SOURCE_KEY = "liveSource";
57
63
  /**
@@ -64,9 +70,9 @@ const WRITTEN_FROM_KEY = "writtenFrom";
64
70
  /**
65
71
  * Never written from `siteFields` (#10806 D6): a mapped fumadocs key, an
66
72
  * address key, the strip marker, the live-source mark, the written-from
67
- * record, or a prototype name.
73
+ * record, the stored tags (#11750 D3), or a prototype name.
68
74
  */
69
- const NOT_SITE_FIELDS = new Set(["date", "updated", "type", "slug", "oss", "siteFields", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY, "__proto__"]);
75
+ const NOT_SITE_FIELDS = new Set(["date", "updated", "type", "slug", "oss", "siteFields", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY, "tags", "__proto__"]);
70
76
  const INDEX_SLUG = "index";
71
77
  /** The store's address shapes, restated (create-ailk has no runtime dep): a path built from them stays in the site. */
72
78
  const TYPE_SHAPE = /^[A-Z][A-Za-z]*$/;
@@ -74,8 +80,15 @@ const SLUG_SHAPE = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
74
80
  const LOCALE_SHAPE = /^[a-z]{2}(-[A-Z]{2})?$/;
75
81
  /** A blog series' shape (`PARENT` in `lib/import-mdx.ts`), restated: a directory built from it stays in the blog. */
76
82
  const SERIES_SHAPE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
77
- /** A pinned item's read times out as the kit's other reads do (`inventory.ts`). */
78
- const ITEM_READ_TIMEOUT_MS = 15_000;
83
+ /** Every read, and each retry of it, times out as the kit's other reads do (`inventory.ts`). */
84
+ const REQUEST_TIMEOUT_MS = 15_000;
85
+ /**
86
+ * A 429 is waited out and sent again this many times; the next one is the
87
+ * read's answer. Each wait is the `retry-after` in whole seconds from 1 to the
88
+ * max, else the max (`lib/import-mdx.ts`, restated, as `language-import.ts` does).
89
+ */
90
+ const RATE_LIMIT_RETRIES = 3;
91
+ const RATE_LIMIT_WAIT_MAX_S = 60;
79
92
  export const SPOKE_HINT = "the site's read does not serve this workspace's published version — is the spoke at --store database?";
80
93
  // ── File addressing (D6) ────────────────────────────────────────────────────
81
94
  /**
@@ -113,6 +126,16 @@ export function recombine(content, sections, codec, editorial, pinned) {
113
126
  for (const [key, value] of Object.entries(editorial ? stored : rest)) {
114
127
  if (key === LIVE_SOURCE_KEY || key === WRITTEN_FROM_KEY || (editorial && EDITORIAL_DROPPED.has(key)))
115
128
  continue;
129
+ if (key === "tags") {
130
+ // #11750 D1/D2 — the store writes `tags` itself: a blog page keeps the
131
+ // public subset the importer sends, any other page none of them.
132
+ const own = editorial && BLOG_TAG_TYPES.has(String(content["type"])) && Array.isArray(value) && codec.publicPageTags
133
+ ? codec.publicPageTags(value)
134
+ : [];
135
+ if (own.length > 0)
136
+ frontmatter[key] = own;
137
+ continue;
138
+ }
116
139
  frontmatter[editorial ? (EDITORIAL_RENAMES[key] ?? key) : key] = value;
117
140
  }
118
141
  // #10806 D6 — an editorial page's site fields are its file's own keys, after
@@ -154,7 +177,7 @@ export async function exportContent(opts) {
154
177
  const targetDir = resolve(opts.targetDir);
155
178
  const env = opts.env ?? process.env;
156
179
  const onLine = opts.onLine ?? (() => undefined);
157
- const fetch = opts.fetch ?? globalThis.fetch;
180
+ const fetch = rateLimited(opts.fetch ?? globalThis.fetch, opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))), onLine);
158
181
  const dryRun = opts.dryRun === true;
159
182
  const refuse = (message) => {
160
183
  throw new ExportContentRefusedError(`export-content: ${message} Nothing was written.`);
@@ -297,7 +320,7 @@ export async function exportContent(opts) {
297
320
  headers: { authorization: `Bearer ${access.apiKey}` },
298
321
  // A redirect would re-send the key to another URL.
299
322
  redirect: "error",
300
- signal: AbortSignal.timeout(ITEM_READ_TIMEOUT_MS),
323
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
301
324
  });
302
325
  status = response.status;
303
326
  body = (await response.json().catch(() => undefined));
@@ -319,6 +342,25 @@ export async function exportContent(opts) {
319
342
  return any ? items : undefined;
320
343
  }
321
344
  }
345
+ /**
346
+ * `fetch`, with a 429 waited out by its `retry-after` and sent again, up to
347
+ * `RATE_LIMIT_RETRIES` times (#11750 D4), as `migrate-content` does. A retry
348
+ * carries a fresh timeout: the first attempt's may have fired during the wait.
349
+ */
350
+ function rateLimited(fetch, sleep, onLine) {
351
+ return async (input, init) => {
352
+ for (let retry = 0;; retry++) {
353
+ const response = await fetch(input, retry === 0 ? init : { ...init, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
354
+ if (response.status !== 429 || retry === RATE_LIMIT_RETRIES)
355
+ return response;
356
+ const header = response.headers.get("retry-after");
357
+ const asked = header !== null && /^\d+$/.test(header) ? Number(header) : 0;
358
+ const seconds = asked >= 1 && asked <= RATE_LIMIT_WAIT_MAX_S ? asked : RATE_LIMIT_WAIT_MAX_S;
359
+ onLine(`rate limited — waiting ${seconds}s`);
360
+ await sleep(seconds * 1000);
361
+ }
362
+ };
363
+ }
322
364
  export const EXPORT_CONTENT_HELP = `create-ailk export-content — write every published page back to its content file.
323
365
 
324
366
  Usage:
@@ -342,8 +384,10 @@ apps/web/content/en/blog/<series>/<slug>.mdx for a post in a series and the
342
384
  same under docs for a docs page; a post or doc goes to whichever of
343
385
  <slug>.mdx or <slug>/index.mdx is on disk, <slug>.mdx when neither is — with
344
386
  its words moved back into its sections, so a re-run of migrate-content
345
- reports every page unchanged. Published edits are
346
- kept. A page with a draft ahead of its published version fails by name:
387
+ reports every page unchanged. Published edits are kept. The hub's own tags
388
+ are not written: a blog post keeps its public tags, every other page none. A
389
+ rate-limited read waits out its retry-after, up to three times, and
390
+ continues. A page with a draft ahead of its published version fails by name:
347
391
  publish or revert it in Admin, then re-run. The site's own API read must
348
392
  serve the workspace's published version (on a spoke, the hub's row at
349
393
  --store database). Each page prints created, written, unchanged or failed.
@@ -45,6 +45,13 @@ export interface MdxAdapterModule {
45
45
  * live-source report.
46
46
  */
47
47
  publishCheck?: (type: string, content: Record<string, unknown>, layout: Layout | undefined) => PublishVerdict | undefined;
48
+ /**
49
+ * Whether a page type is laid out in sections (#11793 D7), from the site's
50
+ * own registry and templates (`sectionsRuleOf`); with it, a file of such a
51
+ * type the run would store with no layout fails, naming the reason. Absent
52
+ * when the site's packages cannot say, and the run says so.
53
+ */
54
+ laidOutInSections?: (type: string) => boolean;
48
55
  }
49
56
  /** One issue of the hub's content report, typed structurally. */
50
57
  export interface ContentIssueLike {
@@ -107,6 +114,8 @@ export type ImportMdxOutcome = {
107
114
  slug: string;
108
115
  /** With `liveSource` and `publishCheck`: what the hub's publish gate will answer (#10898 D6). */
109
116
  publishVerdict?: PublishVerdict;
117
+ /** `updated` with the words already matching the hub: only the layout changed (#11749 D5). */
118
+ layoutOnly?: true;
110
119
  } | {
111
120
  root: ImportMdxRoot;
112
121
  path: string;
@@ -200,6 +209,19 @@ export interface PublishCheckMembers {
200
209
  * so only the rest block.
201
210
  */
202
211
  export declare function publishCheckOf(members: PublishCheckMembers): NonNullable<MdxAdapterModule["publishCheck"]>;
212
+ /**
213
+ * #11793 D7 — the rule `laidOutInSections`: a type is laid out in sections
214
+ * when the site's registry names it and its template's kind is `sections`. A
215
+ * registry entry whose template the site's validation package lacks answers
216
+ * false, never throws, so mismatched site packages never stop the run
217
+ * (SEC-11793-06).
218
+ */
219
+ export declare function sectionsRuleOf(registry: readonly {
220
+ key: string;
221
+ template: string;
222
+ }[], templates: Readonly<Record<string, {
223
+ kind: string;
224
+ }>>): (type: string) => boolean;
203
225
  /**
204
226
  * The site's installed adapter package, resolved from its `apps/web` — never
205
227
  * create-ailk's own `node_modules`.