create-ailk 0.41.0 → 0.42.1
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.
- package/README.md +31 -1
- package/component-catalog.json +6 -0
- package/dist/add-route.d.ts +2 -6
- package/dist/add-route.js +2 -43
- package/dist/export-content.d.ts +10 -3
- package/dist/export-content.js +61 -9
- package/dist/language-import.js +5 -2
- package/dist/lib/env-catalog.js +4 -0
- package/dist/lib/import-mdx.d.ts +2 -0
- package/dist/lib/import-mdx.js +46 -22
- package/dist/magnet-page.d.ts +36 -0
- package/dist/magnet-page.js +70 -0
- package/dist/migrate-content.d.ts +12 -3
- package/dist/migrate-content.js +62 -11
- package/dist/routes.d.ts +38 -2
- package/dist/routes.js +586 -27
- package/dist/surfaces.d.ts +16 -0
- package/dist/surfaces.js +36 -0
- package/dist/update.d.ts +1 -1
- package/dist/update.js +24 -2
- package/package.json +3 -3
- package/templates/.claude/hooks/template-guard.sh +145 -36
- package/templates/CLAUDE.md +1 -1
- package/templates/apps/api/CLAUDE.md +2 -0
- package/templates/apps/mcp/CLAUDE.md +9 -3
- package/templates/apps/web/CLAUDE.md +16 -2
- package/templates/apps/web/app/[locale]/layout.tsx +6 -3
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +28 -0
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +28 -0
- package/templates/apps/web/lib/__tests__/page-chrome.test.ts +24 -0
- package/templates/apps/web/lib/__tests__/route-paths.test.ts +57 -0
- package/templates/apps/web/lib/mcp-oauth.ts +14 -10
- package/templates/apps/web/lib/page-chrome.ts +8 -5
- package/templates/apps/web/lib/route-paths.ts +22 -0
- package/templates/apps/web/lib/services-path.ts +27 -18
- package/templates/apps/web/middleware.ts +2 -1
- package/templates/apps/web/next.config.mjs +123 -2
- package/templates/apps/web/src/lib/routes.ts +4 -2
- package/versions.json +51 -51
package/README.md
CHANGED
|
@@ -398,7 +398,7 @@ every such package:
|
|
|
398
398
|
```bash
|
|
399
399
|
# write the generated files (run after `pnpm install` — the manifests are read from the installed packages)
|
|
400
400
|
create-ailk routes --write ./my-site
|
|
401
|
-
# check them — exit 1 naming each missing, stale or
|
|
401
|
+
# check them — exit 1 naming each missing, stale, stray or undecided file; the scaffold's preflight runs this as `pnpm routes:check`
|
|
402
402
|
create-ailk routes --check ./my-site
|
|
403
403
|
```
|
|
404
404
|
|
|
@@ -484,6 +484,36 @@ re-creates it. A replaced page stops receiving upgrades, visibly, as one
|
|
|
484
484
|
recorded file. There is no command that copies a shipped page's source into
|
|
485
485
|
a site.
|
|
486
486
|
|
|
487
|
+
**Every other page is a decided one.** A routing file under
|
|
488
|
+
`app/[locale]/` that no installed page package generated is a **site page**
|
|
489
|
+
unless the template shipped it (a `.ailk-template-files.json` key or an
|
|
490
|
+
`architecture.yaml` `customizations.scaffold_paths` match) or
|
|
491
|
+
`add-route magnet` wrote it byte for byte. A site page, and a replaced or
|
|
492
|
+
removed package route, needs a **decided** `customizations.yaml` entry —
|
|
493
|
+
`build-in: site — <decider>, <YYYY-MM-DD>, <reason>` or `build-in: ailk#<N>`.
|
|
494
|
+
`--check` fails each one with no entry, or whose entry is `undecided`
|
|
495
|
+
(`undecided_ok_until` does not apply to a page), and lists a decided one as
|
|
496
|
+
`kept by the site (decided)`:
|
|
497
|
+
|
|
498
|
+
```text
|
|
499
|
+
undecided: apps/web/app/[locale]/talk-to-sam/page.tsx — no customizations.yaml entry → regenerate it: `create-ailk add-route magnet --path /talk-to-sam --flow talk-to-sam`
|
|
500
|
+
stray: apps/web/app/[locale]/meet/intro/page.tsx → @working-theory/ui-scheduling's meet/[slug]/page.tsx serves this address (from a content file) — delete this file, then run `create-ailk routes --write`
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
Each reported `page.tsx` names what already serves its address: the
|
|
504
|
+
`add-route magnet` command for a magnet page (one whose renderer is a
|
|
505
|
+
site-local copy, or that was edited, included), else the installed package
|
|
506
|
+
page whose route matches it — a static match before a dynamic one. Before you
|
|
507
|
+
add a page, look up its page type and the package route that serves it, and
|
|
508
|
+
use that package page when it exists. Otherwise record the decision in
|
|
509
|
+
customizations.yaml (build-in: site — <decider>, <YYYY-MM-DD>, <reason>)
|
|
510
|
+
before you write the file. The scaffold's `template-guard.sh` hook refuses a
|
|
511
|
+
new routing file with no decided entry. A site with no
|
|
512
|
+
`.ailk-template-files.json` cannot tell a template page from a site page, so
|
|
513
|
+
pages outside every prefix are not checked and the report prints
|
|
514
|
+
`site pages not checked`. `create-ailk update` lists each page the check
|
|
515
|
+
fails on under **Needs review**, so a consumer's bump PR carries the list.
|
|
516
|
+
|
|
487
517
|
**Where it runs.** At scaffold time after `--install` (a scaffold without
|
|
488
518
|
`--install` names the command in its next steps), and inside `create-ailk
|
|
489
519
|
update` after the pins move (below). The scaffold's `preflight` script runs
|
package/component-catalog.json
CHANGED
|
@@ -6412,6 +6412,9 @@
|
|
|
6412
6412
|
"items": {
|
|
6413
6413
|
"type": "string"
|
|
6414
6414
|
}
|
|
6415
|
+
},
|
|
6416
|
+
"namedOnly": {
|
|
6417
|
+
"type": "boolean"
|
|
6415
6418
|
}
|
|
6416
6419
|
}
|
|
6417
6420
|
},
|
|
@@ -10336,6 +10339,9 @@
|
|
|
10336
10339
|
"items": {
|
|
10337
10340
|
"type": "string"
|
|
10338
10341
|
}
|
|
10342
|
+
},
|
|
10343
|
+
"namedOnly": {
|
|
10344
|
+
"type": "boolean"
|
|
10339
10345
|
}
|
|
10340
10346
|
},
|
|
10341
10347
|
"required": [
|
package/dist/add-route.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type InstallReportRow } from "./lib/extract-module-bundle.js";
|
|
2
|
+
import { MAGNET_PAGE_MARKER } from "./magnet-page.js";
|
|
2
3
|
import type { MarkerMap, WorkspaceVersionMap } from "./substitute.js";
|
|
3
4
|
import { type SyncRoutesResult } from "./sync-routes.js";
|
|
4
5
|
/** A refusal the CLI exits 2 on, thrown before anything is written. */
|
|
@@ -47,12 +48,7 @@ export declare function addRouteToScaffold(opts: AddRouteOptions): AddRouteResul
|
|
|
47
48
|
export declare function formatAddRouteReport(result: AddRouteResult): string;
|
|
48
49
|
/** The route word that selects the magnet mode. */
|
|
49
50
|
export declare const MAGNET_ROUTE = "magnet";
|
|
50
|
-
|
|
51
|
-
* The header-comment marker every standard magnet page carries — the same
|
|
52
|
-
* string the package's `flows/[slug]/magnet-page.tsx` exports, which the site's
|
|
53
|
-
* `structured-data.test.tsx` reads to exempt the pair (#8840 D13).
|
|
54
|
-
*/
|
|
55
|
-
export declare const MAGNET_PAGE_MARKER = "Standard magnet page (#8840)";
|
|
51
|
+
export { MAGNET_PAGE_MARKER };
|
|
56
52
|
/** Whether `slug` passes `flowSlugSchema`'s rule. */
|
|
57
53
|
export declare function isMagnetFlowSlug(slug: string): boolean;
|
|
58
54
|
export interface AddMagnetOptions {
|
package/dist/add-route.js
CHANGED
|
@@ -47,6 +47,7 @@ import { deriveArchitecture } from "./derive-architecture.js";
|
|
|
47
47
|
import { appendEnvRows } from "./lib/declared-env.js";
|
|
48
48
|
import { ENV_CATALOG } from "./lib/env-catalog.js";
|
|
49
49
|
import { diffTwoStrings, } from "./lib/extract-module-bundle.js";
|
|
50
|
+
import { MAGNET_PAGE_MARKER, renderMagnetPage } from "./magnet-page.js";
|
|
50
51
|
import { ParseError } from "./parse-args.js";
|
|
51
52
|
import { RoutesRefusedError, writeRoutes } from "./routes.js";
|
|
52
53
|
import { substituteMarkers } from "./substitute.js";
|
|
@@ -325,12 +326,7 @@ export function formatAddRouteReport(result) {
|
|
|
325
326
|
// ── add-route magnet (#8840 D12) ───────────────────────────────────────────
|
|
326
327
|
/** The route word that selects the magnet mode. */
|
|
327
328
|
export const MAGNET_ROUTE = "magnet";
|
|
328
|
-
|
|
329
|
-
* The header-comment marker every standard magnet page carries — the same
|
|
330
|
-
* string the package's `flows/[slug]/magnet-page.tsx` exports, which the site's
|
|
331
|
-
* `structured-data.test.tsx` reads to exempt the pair (#8840 D13).
|
|
332
|
-
*/
|
|
333
|
-
export const MAGNET_PAGE_MARKER = "Standard magnet page (#8840)";
|
|
329
|
+
export { MAGNET_PAGE_MARKER };
|
|
334
330
|
/** The module whose renderers and flow routes a magnet pair mounts. */
|
|
335
331
|
const MAGNET_MODULE = "signal-collectors";
|
|
336
332
|
/**
|
|
@@ -539,43 +535,6 @@ function staticPageServing(targetAbs, dirs, { ownPages }) {
|
|
|
539
535
|
};
|
|
540
536
|
return walk(root);
|
|
541
537
|
}
|
|
542
|
-
/**
|
|
543
|
-
* The renderer's package subpath (#11251 D7), interpolated into the emitted
|
|
544
|
-
* import so create-ailk's own dist carries no `@working-theory/*` import
|
|
545
|
-
* statement (#8412).
|
|
546
|
-
*/
|
|
547
|
-
const MAGNET_RENDERER = "@working-theory/ui-signal-collectors/pages/flows/[slug]/magnet-page";
|
|
548
|
-
/**
|
|
549
|
-
* One page of the pair, importing the renderer from its package subpath,
|
|
550
|
-
* `@working-theory/ui-signal-collectors/pages/flows/[slug]/magnet-page`
|
|
551
|
-
* (#11251 D7). Every interpolated value has passed `MAGNET_PATH_RE` or
|
|
552
|
-
* `FLOW_SLUG_RE`, so none can leave its string literal (SEC-8840-V5).
|
|
553
|
-
*/
|
|
554
|
-
function renderMagnetPage(kind, path, flow) {
|
|
555
|
-
const [page, metadata, role] = kind === "landing"
|
|
556
|
-
? [
|
|
557
|
-
"magnetLanding",
|
|
558
|
-
"magnetLandingMetadata",
|
|
559
|
-
`the landing of the ${path} magnet pair, its copy from the ${flow} flow's record`,
|
|
560
|
-
]
|
|
561
|
-
: [
|
|
562
|
-
"magnetStart",
|
|
563
|
-
"magnetStartMetadata",
|
|
564
|
-
`the walk of the ${path} magnet pair, its back arrow to ${path}`,
|
|
565
|
-
];
|
|
566
|
-
return [
|
|
567
|
-
`// Generated by \`create-ailk add-route magnet --path ${path} --flow ${flow}\`.`,
|
|
568
|
-
`// ${MAGNET_PAGE_MARKER} — ${role}.`,
|
|
569
|
-
`import { ${page}, ${metadata} } from "${MAGNET_RENDERER}";`,
|
|
570
|
-
"",
|
|
571
|
-
`const MAGNET = { slug: "${flow}", path: "${path}" } as const;`,
|
|
572
|
-
"",
|
|
573
|
-
'export const dynamic = "force-dynamic";',
|
|
574
|
-
`export const generateMetadata = ${metadata}(MAGNET);`,
|
|
575
|
-
`export default ${page}(MAGNET);`,
|
|
576
|
-
"",
|
|
577
|
-
].join("\n");
|
|
578
|
-
}
|
|
579
538
|
/** The report `add-route magnet` prints. */
|
|
580
539
|
export function formatAddMagnetReport(result) {
|
|
581
540
|
const written = result.report.filter((row) => row.action === "written");
|
package/dist/export-content.d.ts
CHANGED
|
@@ -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:
|
|
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?:
|
|
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\
|
|
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 {};
|
package/dist/export-content.js
CHANGED
|
@@ -52,13 +52,27 @@ 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";
|
|
63
|
+
/**
|
|
64
|
+
* The hub's written-from record (#11707 D9, `WRITTEN_FROM_KEY` in
|
|
65
|
+
* api-content-write `content.ts`, restated: no runtime dep): what the words
|
|
66
|
+
* were written from, never a file's key — dropped here too, for a hub that
|
|
67
|
+
* still answers it in the draft's content.
|
|
68
|
+
*/
|
|
69
|
+
const WRITTEN_FROM_KEY = "writtenFrom";
|
|
57
70
|
/**
|
|
58
71
|
* Never written from `siteFields` (#10806 D6): a mapped fumadocs key, an
|
|
59
|
-
* address key, the strip marker, the live-source mark,
|
|
72
|
+
* address key, the strip marker, the live-source mark, the written-from
|
|
73
|
+
* record, the stored tags (#11750 D3), or a prototype name.
|
|
60
74
|
*/
|
|
61
|
-
const NOT_SITE_FIELDS = new Set(["date", "updated", "type", "slug", "oss", "siteFields", LIVE_SOURCE_KEY, "__proto__"]);
|
|
75
|
+
const NOT_SITE_FIELDS = new Set(["date", "updated", "type", "slug", "oss", "siteFields", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY, "tags", "__proto__"]);
|
|
62
76
|
const INDEX_SLUG = "index";
|
|
63
77
|
/** The store's address shapes, restated (create-ailk has no runtime dep): a path built from them stays in the site. */
|
|
64
78
|
const TYPE_SHAPE = /^[A-Z][A-Za-z]*$/;
|
|
@@ -66,8 +80,15 @@ const SLUG_SHAPE = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
|
66
80
|
const LOCALE_SHAPE = /^[a-z]{2}(-[A-Z]{2})?$/;
|
|
67
81
|
/** A blog series' shape (`PARENT` in `lib/import-mdx.ts`), restated: a directory built from it stays in the blog. */
|
|
68
82
|
const SERIES_SHAPE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
69
|
-
/**
|
|
70
|
-
const
|
|
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;
|
|
71
92
|
export const SPOKE_HINT = "the site's read does not serve this workspace's published version — is the spoke at --store database?";
|
|
72
93
|
// ── File addressing (D6) ────────────────────────────────────────────────────
|
|
73
94
|
/**
|
|
@@ -103,8 +124,18 @@ export function recombine(content, sections, codec, editorial, pinned) {
|
|
|
103
124
|
const frontmatter = {};
|
|
104
125
|
const { siteFields, ...stored } = rest;
|
|
105
126
|
for (const [key, value] of Object.entries(editorial ? stored : rest)) {
|
|
106
|
-
if (key === LIVE_SOURCE_KEY || (editorial && EDITORIAL_DROPPED.has(key)))
|
|
127
|
+
if (key === LIVE_SOURCE_KEY || key === WRITTEN_FROM_KEY || (editorial && EDITORIAL_DROPPED.has(key)))
|
|
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;
|
|
107
137
|
continue;
|
|
138
|
+
}
|
|
108
139
|
frontmatter[editorial ? (EDITORIAL_RENAMES[key] ?? key) : key] = value;
|
|
109
140
|
}
|
|
110
141
|
// #10806 D6 — an editorial page's site fields are its file's own keys, after
|
|
@@ -146,7 +177,7 @@ export async function exportContent(opts) {
|
|
|
146
177
|
const targetDir = resolve(opts.targetDir);
|
|
147
178
|
const env = opts.env ?? process.env;
|
|
148
179
|
const onLine = opts.onLine ?? (() => undefined);
|
|
149
|
-
const fetch = opts.fetch ?? globalThis.fetch;
|
|
180
|
+
const fetch = rateLimited(opts.fetch ?? globalThis.fetch, opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))), onLine);
|
|
150
181
|
const dryRun = opts.dryRun === true;
|
|
151
182
|
const refuse = (message) => {
|
|
152
183
|
throw new ExportContentRefusedError(`export-content: ${message} Nothing was written.`);
|
|
@@ -289,7 +320,7 @@ export async function exportContent(opts) {
|
|
|
289
320
|
headers: { authorization: `Bearer ${access.apiKey}` },
|
|
290
321
|
// A redirect would re-send the key to another URL.
|
|
291
322
|
redirect: "error",
|
|
292
|
-
signal: AbortSignal.timeout(
|
|
323
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
293
324
|
});
|
|
294
325
|
status = response.status;
|
|
295
326
|
body = (await response.json().catch(() => undefined));
|
|
@@ -311,6 +342,25 @@ export async function exportContent(opts) {
|
|
|
311
342
|
return any ? items : undefined;
|
|
312
343
|
}
|
|
313
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
|
+
}
|
|
314
364
|
export const EXPORT_CONTENT_HELP = `create-ailk export-content — write every published page back to its content file.
|
|
315
365
|
|
|
316
366
|
Usage:
|
|
@@ -334,8 +384,10 @@ apps/web/content/en/blog/<series>/<slug>.mdx for a post in a series and the
|
|
|
334
384
|
same under docs for a docs page; a post or doc goes to whichever of
|
|
335
385
|
<slug>.mdx or <slug>/index.mdx is on disk, <slug>.mdx when neither is — with
|
|
336
386
|
its words moved back into its sections, so a re-run of migrate-content
|
|
337
|
-
reports every page unchanged. Published edits are
|
|
338
|
-
|
|
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:
|
|
339
391
|
publish or revert it in Admin, then re-run. The site's own API read must
|
|
340
392
|
serve the workspace's published version (on a spoke, the hub's row at
|
|
341
393
|
--store database). Each page prints created, written, unchanged or failed.
|
package/dist/language-import.js
CHANGED
|
@@ -319,16 +319,19 @@ export function withLanguage(adapters, options) {
|
|
|
319
319
|
// `GlossaryIndexDataSchema` requires `terms`, so a pinned glossary-index carries `[]`.
|
|
320
320
|
rewritten.push({ ...rest, data: { ...kept, ...(kind === "term" && { terms: [] }), pinned: pins } });
|
|
321
321
|
}
|
|
322
|
+
const dataOf = (s) => s.data ?? {};
|
|
322
323
|
for (const kind of ["faq", "term"]) {
|
|
323
324
|
if (type !== HOME_TYPE[kind])
|
|
324
325
|
continue;
|
|
325
326
|
const own = rewritten.filter((s) => s.type === SECTION_TYPE[kind]);
|
|
326
327
|
if (own.length === 0)
|
|
327
328
|
continue;
|
|
329
|
+
// An opted-out page takes no other Live item, so it has no top-ups (#11738 D4).
|
|
330
|
+
if (own.some((s) => dataOf(s)["namedOnly"] === true))
|
|
331
|
+
continue;
|
|
328
332
|
const shown = new Set();
|
|
329
333
|
for (const s of own) {
|
|
330
|
-
const
|
|
331
|
-
for (const pin of data["pinned"] ?? [])
|
|
334
|
+
for (const pin of dataOf(s)["pinned"] ?? [])
|
|
332
335
|
shown.add(pin);
|
|
333
336
|
}
|
|
334
337
|
homes.push({ kind, slug, shown });
|
package/dist/lib/env-catalog.js
CHANGED
|
@@ -195,6 +195,10 @@ export const ENV_CATALOG = {
|
|
|
195
195
|
description: "The services' public base, baked at build from content/_site.mdx's services.path; do not set by hand.",
|
|
196
196
|
secret: false,
|
|
197
197
|
},
|
|
198
|
+
NEXT_PUBLIC_AILK_ROUTE_PATHS: {
|
|
199
|
+
description: "The route family renames, baked at build from content/_site.mdx's route family paths; do not set by hand.",
|
|
200
|
+
secret: false,
|
|
201
|
+
},
|
|
198
202
|
NEXT_PUBLIC_AILK_LISTING_SITE_KEY: {
|
|
199
203
|
description: "The site's public listing key, inlined at build; it switches the listicle directory on. Public by design.",
|
|
200
204
|
secret: false,
|
package/dist/lib/import-mdx.d.ts
CHANGED
|
@@ -107,6 +107,8 @@ export type ImportMdxOutcome = {
|
|
|
107
107
|
slug: string;
|
|
108
108
|
/** With `liveSource` and `publishCheck`: what the hub's publish gate will answer (#10898 D6). */
|
|
109
109
|
publishVerdict?: PublishVerdict;
|
|
110
|
+
/** `updated` with the words already matching the hub: only the layout changed (#11749 D5). */
|
|
111
|
+
layoutOnly?: true;
|
|
110
112
|
} | {
|
|
111
113
|
root: ImportMdxRoot;
|
|
112
114
|
path: string;
|
package/dist/lib/import-mdx.js
CHANGED
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
* sections — layout and data — go to the structure layer through
|
|
17
17
|
* `PUT …/structure` under the draft's structure token (#10643), never into the
|
|
18
18
|
* stored content. An unchanged layout writes nothing, so a re-run still
|
|
19
|
-
* reports `unchanged
|
|
20
|
-
*
|
|
19
|
+
* reports `unchanged`. A changed layout on a page whose words did not change
|
|
20
|
+
* and whose draft is its live version is refused `draft_is_live`; the
|
|
21
|
+
* importer then saves a draft with the same words under the version it read
|
|
22
|
+
* and sends the layout once more (#11749 D2), so the live page does not change
|
|
23
|
+
* until it is published. A second refusal fails the page with that reason.
|
|
21
24
|
*
|
|
22
25
|
* A section string that holds inline HTML is converted first (#10804) — a
|
|
23
26
|
* link to `[label](href)`, a line break to a newline, a block to a blank
|
|
@@ -79,6 +82,8 @@ const FRONTMATTER_PACKAGE = "gray-matter";
|
|
|
79
82
|
const PAGE_TYPES_PACKAGE = "@working-theory/schema/page-types";
|
|
80
83
|
/** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated: no runtime dep. */
|
|
81
84
|
const LIVE_SOURCE_KEY = "liveSource";
|
|
85
|
+
/** The hub's written-from record (`WRITTEN_FROM_KEY`, same file), restated: never taken from a file (#11707 D9). */
|
|
86
|
+
const WRITTEN_FROM_KEY = "writtenFrom";
|
|
82
87
|
/** `EDITORIAL_FIELDS` (api-content-write `derive-publish.ts`): the editorial structure publish's repair builds. */
|
|
83
88
|
const EDITORIAL_STRUCTURE_FIELDS = ["author", "tags", "order", "parent"];
|
|
84
89
|
/** The adapter's locale shape (`BCP47_RE` in its `mdx/adapter.ts`). */
|
|
@@ -117,7 +122,7 @@ const EDITORIAL_FIELDS = {
|
|
|
117
122
|
sections: "sections",
|
|
118
123
|
};
|
|
119
124
|
/** Keys not sent and not reported: the path decides both, and a strip marker. */
|
|
120
|
-
const EDITORIAL_IGNORED = new Set(["type", "slug", "oss", LIVE_SOURCE_KEY]);
|
|
125
|
+
const EDITORIAL_IGNORED = new Set(["type", "slug", "oss", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY]);
|
|
121
126
|
/** Why a key is not sent (#10806 D4); `siteFieldRefusal`'s own reasons are the rest. */
|
|
122
127
|
const NOT_SENT = {
|
|
123
128
|
parent: "the path decides a blog post's parent",
|
|
@@ -601,11 +606,11 @@ function wrongLocale(at, answer, locale) {
|
|
|
601
606
|
}
|
|
602
607
|
return failed(at, `the API does not serve locale ${locale}`, `not sent: the API does not serve locale ${locale}`);
|
|
603
608
|
}
|
|
604
|
-
/** `value` without the live-source mark. */
|
|
605
|
-
function
|
|
609
|
+
/** `value` without the hub's own records: the live-source mark and the written-from record. */
|
|
610
|
+
function withoutHubRecords(value) {
|
|
606
611
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
607
612
|
return value;
|
|
608
|
-
const { [LIVE_SOURCE_KEY]: _mark, ...rest } = value;
|
|
613
|
+
const { [LIVE_SOURCE_KEY]: _mark, [WRITTEN_FROM_KEY]: _record, ...rest } = value;
|
|
609
614
|
return rest;
|
|
610
615
|
}
|
|
611
616
|
async function writePage(t, page, locale, content, layout, publicTags) {
|
|
@@ -617,31 +622,49 @@ async function writePage(t, page, locale, content, layout, publicTags) {
|
|
|
617
622
|
let live = false;
|
|
618
623
|
let stored;
|
|
619
624
|
let sent = false;
|
|
620
|
-
const outcome = (result) => ({
|
|
621
|
-
outcome: { root, path, result, type, slug },
|
|
625
|
+
const outcome = (result, layoutOnly = false) => ({
|
|
626
|
+
outcome: { root, path, result, type, slug, ...(layoutOnly && { layoutOnly: true }) },
|
|
622
627
|
live,
|
|
623
628
|
stored,
|
|
624
629
|
sent,
|
|
625
630
|
});
|
|
626
631
|
// The words are written; now the layout, under the token the draft holds
|
|
627
|
-
// (`null` for a page that has none yet).
|
|
628
|
-
|
|
632
|
+
// (`null` for a page that has none yet). `version` is the read's, given
|
|
633
|
+
// only when the words compared equal and were not saved (#11749 D2).
|
|
634
|
+
const done = async (result, structureToken = null, version) => {
|
|
629
635
|
if (layout === undefined)
|
|
630
636
|
return outcome(result);
|
|
631
|
-
const
|
|
637
|
+
const writeLayout = () => call(t, "PUT", `${pagePath}/structure${query}`, {
|
|
632
638
|
structureToken,
|
|
633
639
|
structure: layout,
|
|
634
640
|
});
|
|
641
|
+
let put = await writeLayout();
|
|
642
|
+
// #11749 D2 — the hub refuses a layout on a live tip and names the remedy:
|
|
643
|
+
// save a draft (the same words, under the version read), then write the
|
|
644
|
+
// layout once more. A save carries the structure token forward (§1).
|
|
645
|
+
const redraft = version !== undefined &&
|
|
646
|
+
!("network" in put) &&
|
|
647
|
+
put.status === 409 &&
|
|
648
|
+
put.code === "draft_is_live";
|
|
649
|
+
if (redraft) {
|
|
650
|
+
const saved = await call(t, "PATCH", address, content, version);
|
|
651
|
+
if ("network" in saved || saved.status !== 200)
|
|
652
|
+
return refusedAnswer(page, saved);
|
|
653
|
+
stored = saved.data["content"];
|
|
654
|
+
sent = true;
|
|
655
|
+
const mismatch = wrongLocale(page, saved, locale);
|
|
656
|
+
if (mismatch !== undefined)
|
|
657
|
+
return mismatch;
|
|
658
|
+
put = await writeLayout();
|
|
659
|
+
}
|
|
635
660
|
if ("network" in put || put.status !== 200)
|
|
636
661
|
return refusedAnswer(page, put);
|
|
662
|
+
// #10804 D6 — with no token the hub writes the layout (or refuses a
|
|
663
|
+
// live tip), so a dry run's `written: false` never makes it unchanged.
|
|
664
|
+
const layoutOnly = result === "unchanged" &&
|
|
665
|
+
(redraft || structureToken === null || put.data["written"] === true);
|
|
637
666
|
return (wrongLocale(page, put, locale) ??
|
|
638
|
-
outcome(
|
|
639
|
-
// #10804 D6 — with no token the hub writes the layout (or refuses a
|
|
640
|
-
// live tip), so a dry run's `written: false` never makes it unchanged.
|
|
641
|
-
result === "unchanged" &&
|
|
642
|
-
(structureToken === null || put.data["written"] === true)
|
|
643
|
-
? "updated"
|
|
644
|
-
: result));
|
|
667
|
+
outcome(layoutOnly ? "updated" : result, layoutOnly));
|
|
645
668
|
};
|
|
646
669
|
for (let reread = false;; reread = true) {
|
|
647
670
|
const read = await call(t, "GET", address);
|
|
@@ -660,9 +683,9 @@ async function writePage(t, page, locale, content, layout, publicTags) {
|
|
|
660
683
|
stored = read.data["content"];
|
|
661
684
|
// #10898 D5 — a live tip is never re-drafted for the mark alone.
|
|
662
685
|
const liveTip = read.data["status"] === "published";
|
|
663
|
-
if (canonical(compared(liveTip ?
|
|
664
|
-
canonical(compared(liveTip ?
|
|
665
|
-
return done("unchanged", structureToken);
|
|
686
|
+
if (canonical(compared(liveTip ? withoutHubRecords(stored) : stored, content, publicTags)) ===
|
|
687
|
+
canonical(compared(liveTip ? withoutHubRecords(content) : content, content, publicTags))) {
|
|
688
|
+
return done("unchanged", structureToken, version);
|
|
666
689
|
}
|
|
667
690
|
// The token is the version just compared against, so a draft saved
|
|
668
691
|
// since the read is a 409, never a silent overwrite.
|
|
@@ -1187,7 +1210,8 @@ export async function importMdx(opts) {
|
|
|
1187
1210
|
continue;
|
|
1188
1211
|
}
|
|
1189
1212
|
// #10898 D5 — a file never supplies the mark; the importer computes it.
|
|
1190
|
-
|
|
1213
|
+
// #11707 D9 — nor the written-from record: a file is never its source.
|
|
1214
|
+
const { [LIVE_SOURCE_KEY]: _fileMark, [WRITTEN_FROM_KEY]: _fileRecord, ...words } = converted.content;
|
|
1191
1215
|
const body = words["body"];
|
|
1192
1216
|
converted.content =
|
|
1193
1217
|
opts.liveSource === true && typeof body === "string"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The magnet page pair `create-ailk add-route magnet` writes (#8840 D12,
|
|
3
|
+
* #11251 D7), and how `routes --check` recognises one it wrote (#11700 D5).
|
|
4
|
+
*
|
|
5
|
+
* No imports: `add-route.ts` imports `routes.ts`, so the renderer lives here,
|
|
6
|
+
* where both can read it without a cycle.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The header-comment marker every standard magnet page carries — the same
|
|
10
|
+
* string the package's `flows/[slug]/magnet-page.tsx` exports, which the site's
|
|
11
|
+
* `structured-data.test.tsx` reads to exempt the pair (#8840 D13).
|
|
12
|
+
*/
|
|
13
|
+
export declare const MAGNET_PAGE_MARKER = "Standard magnet page (#8840)";
|
|
14
|
+
/**
|
|
15
|
+
* The renderer's package subpath (#11251 D7), interpolated into the emitted
|
|
16
|
+
* import so create-ailk's own dist carries no `@working-theory/*` import
|
|
17
|
+
* statement (#8412).
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAGNET_RENDERER = "@working-theory/ui-signal-collectors/pages/flows/[slug]/magnet-page";
|
|
20
|
+
/**
|
|
21
|
+
* One page of the pair, importing the renderer from its package subpath,
|
|
22
|
+
* `@working-theory/ui-signal-collectors/pages/flows/[slug]/magnet-page`
|
|
23
|
+
* (#11251 D7). Every interpolated value has passed `MAGNET_PATH_RE` or
|
|
24
|
+
* `FLOW_SLUG_RE`, so none can leave its string literal (SEC-8840-V5).
|
|
25
|
+
*/
|
|
26
|
+
export declare function renderMagnetPage(kind: "landing" | "walk", path: string, flow: string): string;
|
|
27
|
+
/** Line 1 of a generated magnet page: the exact command that wrote it. */
|
|
28
|
+
export declare const MAGNET_COMMAND_RE: RegExp;
|
|
29
|
+
/**
|
|
30
|
+
* Whether `text`, at `sitePath`, is a page `add-route magnet` wrote and the
|
|
31
|
+
* site has not touched: line 1 names the command, the file sits at that
|
|
32
|
+
* command's landing (`<path>/page.tsx`) or walk (`<path>/start/page.tsx`)
|
|
33
|
+
* under `apps/web/app/[locale]/`, and its bytes are exactly what the command
|
|
34
|
+
* renders. An edited pair, or one importing a site-local renderer, is not.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isGeneratedMagnetPage(sitePath: string, text: string): boolean;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The magnet page pair `create-ailk add-route magnet` writes (#8840 D12,
|
|
3
|
+
* #11251 D7), and how `routes --check` recognises one it wrote (#11700 D5).
|
|
4
|
+
*
|
|
5
|
+
* No imports: `add-route.ts` imports `routes.ts`, so the renderer lives here,
|
|
6
|
+
* where both can read it without a cycle.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The header-comment marker every standard magnet page carries — the same
|
|
10
|
+
* string the package's `flows/[slug]/magnet-page.tsx` exports, which the site's
|
|
11
|
+
* `structured-data.test.tsx` reads to exempt the pair (#8840 D13).
|
|
12
|
+
*/
|
|
13
|
+
export const MAGNET_PAGE_MARKER = "Standard magnet page (#8840)";
|
|
14
|
+
/**
|
|
15
|
+
* The renderer's package subpath (#11251 D7), interpolated into the emitted
|
|
16
|
+
* import so create-ailk's own dist carries no `@working-theory/*` import
|
|
17
|
+
* statement (#8412).
|
|
18
|
+
*/
|
|
19
|
+
export const MAGNET_RENDERER = "@working-theory/ui-signal-collectors/pages/flows/[slug]/magnet-page";
|
|
20
|
+
/**
|
|
21
|
+
* One page of the pair, importing the renderer from its package subpath,
|
|
22
|
+
* `@working-theory/ui-signal-collectors/pages/flows/[slug]/magnet-page`
|
|
23
|
+
* (#11251 D7). Every interpolated value has passed `MAGNET_PATH_RE` or
|
|
24
|
+
* `FLOW_SLUG_RE`, so none can leave its string literal (SEC-8840-V5).
|
|
25
|
+
*/
|
|
26
|
+
export function renderMagnetPage(kind, path, flow) {
|
|
27
|
+
const [page, metadata, role] = kind === "landing"
|
|
28
|
+
? [
|
|
29
|
+
"magnetLanding",
|
|
30
|
+
"magnetLandingMetadata",
|
|
31
|
+
`the landing of the ${path} magnet pair, its copy from the ${flow} flow's record`,
|
|
32
|
+
]
|
|
33
|
+
: [
|
|
34
|
+
"magnetStart",
|
|
35
|
+
"magnetStartMetadata",
|
|
36
|
+
`the walk of the ${path} magnet pair, its back arrow to ${path}`,
|
|
37
|
+
];
|
|
38
|
+
return [
|
|
39
|
+
`// Generated by \`create-ailk add-route magnet --path ${path} --flow ${flow}\`.`,
|
|
40
|
+
`// ${MAGNET_PAGE_MARKER} — ${role}.`,
|
|
41
|
+
`import { ${page}, ${metadata} } from "${MAGNET_RENDERER}";`,
|
|
42
|
+
"",
|
|
43
|
+
`const MAGNET = { slug: "${flow}", path: "${path}" } as const;`,
|
|
44
|
+
"",
|
|
45
|
+
'export const dynamic = "force-dynamic";',
|
|
46
|
+
`export const generateMetadata = ${metadata}(MAGNET);`,
|
|
47
|
+
`export default ${page}(MAGNET);`,
|
|
48
|
+
"",
|
|
49
|
+
].join("\n");
|
|
50
|
+
}
|
|
51
|
+
/** Line 1 of a generated magnet page: the exact command that wrote it. */
|
|
52
|
+
export const MAGNET_COMMAND_RE = /^\/\/ Generated by `create-ailk add-route magnet --path (\S+) --flow (\S+)`\.$/;
|
|
53
|
+
/**
|
|
54
|
+
* Whether `text`, at `sitePath`, is a page `add-route magnet` wrote and the
|
|
55
|
+
* site has not touched: line 1 names the command, the file sits at that
|
|
56
|
+
* command's landing (`<path>/page.tsx`) or walk (`<path>/start/page.tsx`)
|
|
57
|
+
* under `apps/web/app/[locale]/`, and its bytes are exactly what the command
|
|
58
|
+
* renders. An edited pair, or one importing a site-local renderer, is not.
|
|
59
|
+
*/
|
|
60
|
+
export function isGeneratedMagnetPage(sitePath, text) {
|
|
61
|
+
const command = MAGNET_COMMAND_RE.exec(text.split("\n", 1)[0] ?? "");
|
|
62
|
+
if (command === null)
|
|
63
|
+
return false;
|
|
64
|
+
const path = command[1];
|
|
65
|
+
const flow = command[2];
|
|
66
|
+
const landing = `apps/web/app/[locale]${path}/page.tsx`;
|
|
67
|
+
const walk = `apps/web/app/[locale]${path}/start/page.tsx`;
|
|
68
|
+
const kind = sitePath === landing ? "landing" : sitePath === walk ? "walk" : undefined;
|
|
69
|
+
return kind !== undefined && text === renderMagnetPage(kind, path, flow);
|
|
70
|
+
}
|