create-ailk 0.43.0 → 0.45.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.
@@ -28,24 +28,17 @@ export interface MigrateContentOptions {
28
28
  onLine?: (line: string) => void;
29
29
  }
30
30
  /**
31
- * A fetch that sends `GET`s through `inner` and never sends a write: a `POST`
32
- * is answered `201` and a `PATCH` `200` locally, with the one member of a
33
- * write's answer `importMdx` reads (`data.locale`), and the structure write's
34
- * `PUT` (#10534) `200`. Any other method throws.
35
- *
36
- * The `PUT` answers `data.written` from the layout the hub's draft read
37
- * returned (#11749 D4): each 200 `GET`'s `data.structure` is kept per page
38
- * address, and a `PUT` to that address's `/structure` URL answers
39
- * `written: true` when its body's `structure` is not `isDeepStrictEqual` to
40
- * it — the hub's own comparison. Any other `PUT` (an equal layout, an address
41
- * never read, a read with no `structure` member, no string body, a `Request`
42
- * input) answers `written: false`. It never answers 409: a live tip with a
43
- * changed layout is planned `update`, what `--apply` reports after its
44
- * re-draft. The memory lasts one run, as the transport does.
31
+ * A fetch that sends `GET`s through `inner` and never sends a write (#11843
32
+ * D9): a `PUT` or `POST` is answered locally — `201` when its JSON body's
33
+ * `version` is `null`, else `200` — with the members of a save's answer the
34
+ * importer reads (`data.address.locale`, and `data.locale` for the Language
35
+ * pass). A `PATCH`, or any other method, throws, so a stray call on a retired
36
+ * route is visible in a dry run too. The importer decides `created`,
37
+ * `updated` and `unchanged` from its read alone, before it writes.
45
38
  */
46
39
  export declare function readOnlyFetch(inner: typeof globalThis.fetch, locale: string): typeof globalThis.fetch;
47
40
  /** What a dry run prints when the site's contract cannot give a verdict. */
48
- export declare const PUBLISH_NOT_CHECKED = "publish: not checked \u2014 the site's @working-theory/validation has no live-source report; update the site's dependencies and re-run";
41
+ export declare const PUBLISH_NOT_CHECKED = "publish: not checked \u2014 the site's @working-theory/validation has no content check; update the site's dependencies and re-run";
49
42
  export declare function migrateContent(opts: MigrateContentOptions): Promise<{
50
43
  result: ImportMdxResult;
51
44
  exitCode: 0 | 1;
@@ -60,5 +53,5 @@ export interface MigrateContentArgs {
60
53
  languageSeed: string | undefined;
61
54
  help: boolean;
62
55
  }
63
- export declare const MIGRATE_CONTENT_HELP = "create-ailk migrate-content \u2014 import an existing site's pages into its workspace.\n\nUsage:\n AILK_AGENT_KEY=<key> create-ailk migrate-content [<dir>] [--apply] [--api-url <origin>] [--workspace <wksp_id>] [--language-seed <file>]\n\nArguments:\n <dir> The site. Defaults to the current dir.\n\nOptions:\n --apply Write the pages. Without it the command reads the\n workspace, prints what it would do, and writes\n nothing.\n --api-url <origin> The API origin that holds the workspace \u2014 on a\n spoke, its hub's. Else AILK_API_URL. https: only\n (http: on localhost or 127.0.0.1).\n --workspace <wksp_id> The workspace the pages are written to. Else\n AILK_WORKSPACE_ID.\n --language-seed <file> A Language seed file (language/<entity>.json).\n Each of its topics becomes one Topic holding all\n its keywords. Its items are not read.\n -h, --help Show this help.\n\nEach content/en/<Type>/<slug>.mdx page (and each legacy\ncontent/<Type>/<slug>.mdx) is written to the workspace as a draft through\nthe API's content routes, with the agent key, which is read from\nAILK_AGENT_KEY only and needs the content-edit grant. Nothing is published,\nso the live site does not change. The site needs no .ailk-site-manifest.json\nand may be a spoke; its dependencies must be installed. A page whose\nfrontmatter carries sections is converted: its words are written to the\npage's Markdown and its sections to its layout.\n\nEach FAQ item and glossary-index term becomes one Language item of its kind,\nset Live when the run creates it, and its section pins the items in the\norder the file lists them. A question on several pages is one item, with\nthe FAQ page's words (the glossary page's, for a term). Lines prefixed\nlanguage: report each item, and each page the database read will not show\nas its file does. An API with no Language collection leaves them inline.\n\nWith --language-seed, each topic in the seed file is written after the\npages as one Topic: its name, its pillar page, and every keyword with its\nmonthly searches and as-of date, its primary marked. A Topic the workspace\nalready holds keeps its spelling, notes and newer numbers, and gains what it\nlacks. Lines prefixed language: topic/ report each one; a second --apply\nreports every topic unchanged. A seed file that is not readable, or whose\ntopics the hub would refuse, is refused before anything is sent.\n\nWhen the site has apps/web/content, each blog post and docs page in it is\nwritten too: apps/web/content/en/blog/<slug>.mdx (or <slug>/index.mdx) as a\nBlogPosting, or one series down, blog/<series>/<post>.mdx, as a BlogPosting\nwhose parent is the series; the same under docs as a DocsDetail, and each\ndirectory's own index.mdx as its BlogList or DocsList index. A file the walk\nskips is listed with the rule it failed. Their lines are prefixed\neditorial: \u2014 each outcome's root is content or editorial.\n\nA dry run prints create, update, unchanged, skipped or failed per page. It\ncannot see a write the API would refuse at --apply (a conflict or a server\nerror), and a page whose content fails its page type is planned and saved\nwith errors the editor shows, not failed. An update whose words already\nmatch the workspace prints \"update \u2014 layout only\". A layout change to a page\nwhose draft is its live version is saved as a new draft with the same words,\nso the live site does not change until the page is published. --apply prints created, updated,\nunchanged, skipped or failed per page, so a re-run is safe. Exit 0 when no\npage failed, 1 when any did, 2 on a refusal (nothing is sent).\n\nEvery page is written with a live-source mark: its words already ship on the\nlive site, so the hub lists a heading the page type's template asks for and\nthe page lacks as advisory, and publish takes the page. Editing the page's\nwords in the hub drops the mark. A dry run prints a publish line after each\npage: publishable, the advisory headings the hub will list, or the status and\nfindings that will stop the publish. The verdict is the site's installed\n@working-theory/validation's, not the hub's; it sees no library-file finding\nand no layout the hub repairs differently. A site whose validation predates\nthe live-source report prints one \"publish: not checked\" line instead.\n";
56
+ export declare const MIGRATE_CONTENT_HELP = "create-ailk migrate-content \u2014 import an existing site's pages into its workspace.\n\nUsage:\n AILK_AGENT_KEY=<key> create-ailk migrate-content [<dir>] [--apply] [--api-url <origin>] [--workspace <wksp_id>] [--language-seed <file>]\n\nArguments:\n <dir> The site. Defaults to the current dir.\n\nOptions:\n --apply Write the pages. Without it the command reads the\n workspace, prints what it would do, and writes\n nothing.\n --api-url <origin> The API origin that holds the workspace \u2014 on a\n spoke, its hub's. Else AILK_API_URL. https: only\n (http: on localhost or 127.0.0.1).\n --workspace <wksp_id> The workspace the pages are written to. Else\n AILK_WORKSPACE_ID.\n --language-seed <file> A Language seed file (language/<entity>.json).\n Each of its topics becomes one Topic holding all\n its keywords. Its items are not read.\n -h, --help Show this help.\n\nEach content/en/<Type>/<slug>.mdx page (and each legacy\ncontent/<Type>/<slug>.mdx) is written to the workspace as a draft through\nthe API's content routes, with the agent key, which is read from\nAILK_AGENT_KEY only and needs the content-edit grant. Nothing is published,\nso the live site does not change. The site needs no .ailk-site-manifest.json\nand may be a spoke; its dependencies must be installed. A page whose\nfrontmatter carries sections is converted: its words are written to the\npage's Markdown and its sections to its layout.\n\nEach FAQ item and glossary-index term becomes one Language item of its kind,\nset Live when the run creates it, and its section pins the items in the\norder the file lists them. A question on several pages is one item, with\nthe FAQ page's words (the glossary page's, for a term). Lines prefixed\nlanguage: report each item, and each page the database read will not show\nas its file does. An API with no Language collection leaves them inline.\n\nWith --language-seed, each topic in the seed file is written after the\npages as one Topic: its name, its pillar page, and every keyword with its\nmonthly searches and as-of date, its primary marked. A Topic the workspace\nalready holds keeps its spelling, notes and newer numbers, and gains what it\nlacks. Lines prefixed language: topic/ report each one; a second --apply\nreports every topic unchanged. A seed file that is not readable, or whose\ntopics the hub would refuse, is refused before anything is sent.\n\nWhen the site has apps/web/content, each blog post and docs page in it is\nwritten too: apps/web/content/en/blog/<slug>.mdx (or <slug>/index.mdx) as a\nBlogPosting, or one series down, blog/<series>/<post>.mdx, as a BlogPosting\nwhose parent is the series; the same under docs as a DocsDetail, and each\ndirectory's own index.mdx as its BlogList or DocsList index. A file the walk\nskips is listed with the rule it failed. Their lines are prefixed\neditorial: \u2014 each outcome's root is content or editorial.\n\nA dry run prints create, update, unchanged, skipped or failed per page. It\ncannot see a write the API would refuse at --apply (a conflict, a server\nerror, or a page whose content fails its page type, which the save refuses\n422 invalid and stores nothing; fix its file and re-run). An update whose\nwords already match the workspace prints \"update \u2014 layout only\". A change to\na page that is live is saved as a new draft, so the live site does not\nchange until the page is published. --apply prints created, updated,\nunchanged, skipped or failed per page, so a re-run is safe. Exit 0 when no\npage failed, 1 when any did, 2 on a refusal (nothing is sent).\n\nNo page is written with a live-source mark, so a heading the page type's\ntemplate asks for and the page lacks stops its publish, as on any page. A\ndry run prints a publish line after each page: publishable, the advisory\nfindings the hub will list, or the status and findings that will stop the\npublish. The verdict is the site's installed @working-theory/validation's,\nnot the hub's; it sees no library-file finding and no layout the hub repairs\ndifferently. A site whose validation has no content check prints one\n\"publish: not checked\" line instead.\n";
64
57
  export declare function parseMigrateContentArgs(argv: string[]): MigrateContentArgs;
@@ -12,16 +12,16 @@
12
12
  * origin and the workspace, which is all the topology would decide.
13
13
  *
14
14
  * A dry run is the default (D3): the importer runs over `readOnlyFetch`, which
15
- * passes each `GET` through and answers a `POST`, `PATCH` or `PUT` locally
16
- * without sending it, so the plan — create · update · unchanged · skipped · failed — is
15
+ * passes each `GET` through and answers a `PUT` or `POST` locally without
16
+ * sending it, so the plan — create · update · unchanged · skipped · failed — is
17
17
  * decided by the importer itself against the live workspace, and no write can
18
18
  * leave the process. `--apply` writes; a second `--apply` reports every page
19
19
  * `unchanged`.
20
20
  *
21
- * Every page carries the hub's live-source mark (#10898 D5): its words already
22
- * ship on a live site, so the template's missing headings are advisory, not a
23
- * reason publish refuses it. The dry run prints, per planned page, whether
24
- * publish will take it and which headings the hub will list (D6).
21
+ * No page carries the hub's live-source mark (#11843 D7): `save_page` never
22
+ * keeps it, so a template's missing heading is blocking, as on any page. The
23
+ * dry run prints, per planned page, whether publish will take it and what the
24
+ * hub will list (#10898 D6), computed as publish will compute it.
25
25
  *
26
26
  * Credentials follow `seed-workspace` (#10204 D2): the origin from
27
27
  * `--api-url`, else `AILK_API_URL`; the workspace id from `--workspace`, else
@@ -34,7 +34,7 @@
34
34
  */
35
35
  import { readFileSync } from "node:fs";
36
36
  import { join, resolve } from "node:path";
37
- import { isDeepStrictEqual, parseArgs } from "node:util";
37
+ import { parseArgs } from "node:util";
38
38
  import { languageLines, languageOffLine, seedTopics, seedTopicsOf, topicSeedLines, withLanguage, } from "./language-import.js";
39
39
  import { formatImportMdxReport, importMdx, isDirectory, loadSiteMdxAdapter, outcomePath, } from "./lib/import-mdx.js";
40
40
  import { ParseError } from "./parse-args.js";
@@ -60,69 +60,33 @@ function given(value) {
60
60
  }
61
61
  // ── The dry run's transport (D3) ────────────────────────────────────────────
62
62
  /**
63
- * A fetch that sends `GET`s through `inner` and never sends a write: a `POST`
64
- * is answered `201` and a `PATCH` `200` locally, with the one member of a
65
- * write's answer `importMdx` reads (`data.locale`), and the structure write's
66
- * `PUT` (#10534) `200`. Any other method throws.
67
- *
68
- * The `PUT` answers `data.written` from the layout the hub's draft read
69
- * returned (#11749 D4): each 200 `GET`'s `data.structure` is kept per page
70
- * address, and a `PUT` to that address's `/structure` URL answers
71
- * `written: true` when its body's `structure` is not `isDeepStrictEqual` to
72
- * it — the hub's own comparison. Any other `PUT` (an equal layout, an address
73
- * never read, a read with no `structure` member, no string body, a `Request`
74
- * input) answers `written: false`. It never answers 409: a live tip with a
75
- * changed layout is planned `update`, what `--apply` reports after its
76
- * re-draft. The memory lasts one run, as the transport does.
63
+ * A fetch that sends `GET`s through `inner` and never sends a write (#11843
64
+ * D9): a `PUT` or `POST` is answered locally — `201` when its JSON body's
65
+ * `version` is `null`, else `200` — with the members of a save's answer the
66
+ * importer reads (`data.address.locale`, and `data.locale` for the Language
67
+ * pass). A `PATCH`, or any other method, throws, so a stray call on a retired
68
+ * route is visible in a dry run too. The importer decides `created`,
69
+ * `updated` and `unchanged` from its read alone, before it writes.
77
70
  */
78
71
  export function readOnlyFetch(inner, locale) {
79
- const layouts = new Map();
80
- /** Whether the hub would write a dry run's layout `PUT` (#11749 D4). */
81
- function layoutWritten(input, init) {
82
- if (input instanceof Request || typeof init?.body !== "string")
83
- return false;
84
- const url = String(input);
85
- const address = url.replace(/\/structure(?=\?|$)/, "");
86
- if (address === url || !layouts.has(address))
87
- return false;
88
- let sent;
89
- try {
90
- sent = JSON.parse(init.body)?.structure;
91
- }
92
- catch {
93
- return false;
94
- }
95
- return !isDeepStrictEqual(sent, layouts.get(address));
96
- }
97
72
  return (async (input, init) => {
98
73
  const method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
99
- if (method === "GET") {
100
- const response = await inner(input, init);
101
- if (response.status === 200) {
102
- const url = input instanceof Request ? input.url : String(input);
103
- try {
104
- // Parsed here, never by `Response.json()`, so both sides of the
105
- // comparison are this module's plain objects.
106
- const data = JSON.parse(await response.clone().text())?.data;
107
- if (data !== null && typeof data === "object" && "structure" in data) {
108
- layouts.set(url, data.structure);
109
- }
110
- else {
111
- layouts.delete(url);
112
- }
113
- }
114
- catch {
115
- // Not JSON: nothing is recorded; the response goes back as it came.
116
- }
117
- }
118
- return response;
119
- }
120
- if (method !== "POST" && method !== "PATCH" && method !== "PUT") {
74
+ if (method === "GET")
75
+ return inner(input, init);
76
+ if (method !== "POST" && method !== "PUT") {
121
77
  throw new Error(`a dry run sends no ${method} request`);
122
78
  }
123
- const data = method === "PUT" ? { locale, written: layoutWritten(input, init) } : { locale };
124
- return new Response(JSON.stringify({ ok: true, data }), {
125
- status: method === "POST" ? 201 : 200,
79
+ let created = false;
80
+ try {
81
+ created =
82
+ typeof init?.body === "string" &&
83
+ JSON.parse(init.body)?.version === null;
84
+ }
85
+ catch {
86
+ // Not JSON: answered as an edit.
87
+ }
88
+ return new Response(JSON.stringify({ ok: true, data: { locale, address: { locale } } }), {
89
+ status: created ? 201 : 200,
126
90
  headers: { "content-type": "application/json" },
127
91
  });
128
92
  });
@@ -166,7 +130,7 @@ function verdictText(verdict) {
166
130
  : `publishable · advisory: ${verdict.advisory.map((issue) => issueText(issue, true)).join(", ")}`;
167
131
  }
168
132
  /** What a dry run prints when the site's contract cannot give a verdict. */
169
- export const PUBLISH_NOT_CHECKED = "publish: not checked — the site's @working-theory/validation has no live-source report; update the site's dependencies and re-run";
133
+ export const PUBLISH_NOT_CHECKED = "publish: not checked — the site's @working-theory/validation has no content check; update the site's dependencies and re-run";
170
134
  // ── The command (D1–D4) ─────────────────────────────────────────────────────
171
135
  export async function migrateContent(opts) {
172
136
  const targetDir = resolve(opts.targetDir);
@@ -227,7 +191,6 @@ export async function migrateContent(opts) {
227
191
  defaultLocale: LOCALE,
228
192
  fetch: transport,
229
193
  ...(opts.sleep !== undefined && { sleep: opts.sleep }),
230
- liveSource: true,
231
194
  // A dry run's importer lines say `created`/`updated`, which nothing was.
232
195
  ...(apply && { onLine }),
233
196
  });
@@ -371,24 +334,23 @@ skips is listed with the rule it failed. Their lines are prefixed
371
334
  editorial: — each outcome's root is content or editorial.
372
335
 
373
336
  A dry run prints create, update, unchanged, skipped or failed per page. It
374
- cannot see a write the API would refuse at --apply (a conflict or a server
375
- error), and a page whose content fails its page type is planned and saved
376
- with errors the editor shows, not failed. An update whose words already
377
- match the workspace prints "update — layout only". A layout change to a page
378
- whose draft is its live version is saved as a new draft with the same words,
379
- so the live site does not change until the page is published. --apply prints created, updated,
337
+ cannot see a write the API would refuse at --apply (a conflict, a server
338
+ error, or a page whose content fails its page type, which the save refuses
339
+ 422 invalid and stores nothing; fix its file and re-run). An update whose
340
+ words already match the workspace prints "update — layout only". A change to
341
+ a page that is live is saved as a new draft, so the live site does not
342
+ change until the page is published. --apply prints created, updated,
380
343
  unchanged, skipped or failed per page, so a re-run is safe. Exit 0 when no
381
344
  page failed, 1 when any did, 2 on a refusal (nothing is sent).
382
345
 
383
- Every page is written with a live-source mark: its words already ship on the
384
- live site, so the hub lists a heading the page type's template asks for and
385
- the page lacks as advisory, and publish takes the page. Editing the page's
386
- words in the hub drops the mark. A dry run prints a publish line after each
387
- page: publishable, the advisory headings the hub will list, or the status and
388
- findings that will stop the publish. The verdict is the site's installed
389
- @working-theory/validation's, not the hub's; it sees no library-file finding
390
- and no layout the hub repairs differently. A site whose validation predates
391
- the live-source report prints one "publish: not checked" line instead.
346
+ No page is written with a live-source mark, so a heading the page type's
347
+ template asks for and the page lacks stops its publish, as on any page. A
348
+ dry run prints a publish line after each page: publishable, the advisory
349
+ findings the hub will list, or the status and findings that will stop the
350
+ publish. The verdict is the site's installed @working-theory/validation's,
351
+ not the hub's; it sees no library-file finding and no layout the hub repairs
352
+ differently. A site whose validation has no content check prints one
353
+ "publish: not checked" line instead.
392
354
  `;
393
355
  export function parseMigrateContentArgs(argv) {
394
356
  let parsed;
@@ -1,3 +1,5 @@
1
+ import { type Level } from "./lib/module-tier.js";
2
+ import type { WorkspaceVersionMap } from "./substitute.js";
1
3
  /** Scaffold-relative path of the generated registry. */
2
4
  export declare const PAID_SECTIONS_PATH = "apps/web/lib/paid-sections.generated.ts";
3
5
  /** Scaffold-relative path of the generated module-presence flags (#8843 D10). */
@@ -58,6 +60,23 @@ export declare function writeModuleFlags(targetDir: string): "added" | "updated"
58
60
  * appearance, so a package two modules deliver is one row.
59
61
  */
60
62
  export declare function paidMcpToolRows(): string[];
63
+ /**
64
+ * #11952 D1 — the paid MCP tool packs a licence level ships: every pack a
65
+ * module of `LEVEL_MODULES[level]` lists, in `paidMcpToolRows()` order.
66
+ * Free ships none; Pro and Pro Plus ship the same three today.
67
+ */
68
+ export declare function levelMcpPackages(level: Level): string[];
69
+ /**
70
+ * #11952 D2 — `text` (an apps/mcp/package.json) with every
71
+ * `levelMcpPackages(level)` pack its `dependencies` lacks added at
72
+ * `^<versions[pack]>`, dependency keys sorted. `added` is sorted; when it is
73
+ * empty, `text` comes back byte-identical. Throws, naming the pack, when
74
+ * `versions` has none for a pack it must add.
75
+ */
76
+ export declare function withLevelMcpPackages(text: string, level: Level, versions: WorkspaceVersionMap): {
77
+ text: string;
78
+ added: string[];
79
+ };
61
80
  /**
62
81
  * Render the MCP registry: one `() => import("<package>")` per carried
63
82
  * package, `[]` when none is carried. Line 1 is `// oss: false` exactly when
@@ -30,6 +30,7 @@
30
30
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
31
31
  import { dirname, join } from "node:path";
32
32
  import { readArchitectureHeader } from "./add-module-core.js";
33
+ import { LEVEL_MODULES } from "./lib/module-tier.js";
33
34
  import { readSiteManifestModules } from "./lib/site-modules.js";
34
35
  import { MODULE_SLICES } from "./module-architecture.js";
35
36
  import { RECOGNIZED_MODULES } from "./parse-args.js";
@@ -222,6 +223,46 @@ export function paidMcpToolRows() {
222
223
  }
223
224
  return rows;
224
225
  }
226
+ /**
227
+ * #11952 D1 — the paid MCP tool packs a licence level ships: every pack a
228
+ * module of `LEVEL_MODULES[level]` lists, in `paidMcpToolRows()` order.
229
+ * Free ships none; Pro and Pro Plus ship the same three today.
230
+ */
231
+ export function levelMcpPackages(level) {
232
+ const shipped = LEVEL_MODULES[level];
233
+ return paidMcpToolRows().filter((pkg) => shipped.some((m) => (MODULE_SLICES[m].paidMcpToolPackages ?? []).includes(pkg)));
234
+ }
235
+ /**
236
+ * #11952 D2 — `text` (an apps/mcp/package.json) with every
237
+ * `levelMcpPackages(level)` pack its `dependencies` lacks added at
238
+ * `^<versions[pack]>`, dependency keys sorted. `added` is sorted; when it is
239
+ * empty, `text` comes back byte-identical. Throws, naming the pack, when
240
+ * `versions` has none for a pack it must add.
241
+ */
242
+ export function withLevelMcpPackages(text, level, versions) {
243
+ let pkg;
244
+ try {
245
+ pkg = JSON.parse(text);
246
+ }
247
+ catch (err) {
248
+ throw new Error(`apps/mcp/package.json is not valid JSON: ${err.message}`, { cause: err });
249
+ }
250
+ const deps = { ...(pkg.dependencies ?? {}) };
251
+ const added = levelMcpPackages(level)
252
+ .filter((name) => !Object.hasOwn(deps, name))
253
+ .sort();
254
+ if (added.length === 0)
255
+ return { text, added };
256
+ for (const name of added) {
257
+ const version = versions[name];
258
+ if (version === undefined) {
259
+ throw new Error(`apps/mcp/package.json needs a version for ${name}, and this create-ailk's versions.json has none`);
260
+ }
261
+ deps[name] = `^${version}`;
262
+ }
263
+ pkg.dependencies = Object.fromEntries(Object.keys(deps).sort().map((key) => [key, deps[key]]));
264
+ return { text: `${JSON.stringify(pkg, null, 2)}\n`, added };
265
+ }
225
266
  const PAID_MCP_TOOLS_HEADER = `// paid-tools.generated.ts — the paid MCP tool packages this site carries.
226
267
  //
227
268
  // GENERATED by create-ailk from MODULE_SLICES (\`paidMcpToolPackages\`) and
@@ -37,7 +37,7 @@ import { assertLicenseKeyShape, writeLicenseKeyFiles, } from "./lib/license-key-
37
37
  import { assertDesignAllowed, assertReleased, deriveDesignLevel, deriveLevel, resolveModuleSet, resolvePaidModules, } from "./lib/module-license-gate.js";
38
38
  import { classifyModules, isAddition } from "./lib/module-tier.js";
39
39
  import { normalizeModules } from "./module-architecture.js";
40
- import { writePaidSections } from "./paid-sections.js";
40
+ import { withLevelMcpPackages, writePaidSections } from "./paid-sections.js";
41
41
  import { RECOGNIZED_SHAPES, RESERVED_SHAPES, } from "./parse-args.js";
42
42
  import { RemoveModuleRefusedError, removeModuleFromScaffold, } from "./remove-module.js";
43
43
  import { scaffoldSeamRows } from "./seam-refresh.js";
@@ -481,6 +481,37 @@ export async function scaffold(opts) {
481
481
  // (#6813 D7) — and `chosen.free` decides Free-ness by identity (D2), never
482
482
  // by `FREE_DESIGNS.includes(name)` alone (a path is never in that list).
483
483
  assertDesignAllowed(chosenDesign?.display, level ?? "free", chosenDesign?.free);
484
+ // #11952 D3 — the MCP build installs its level's packs (D1), so a run that
485
+ // composed no level (a `--modules` keep run, a `--template` alias run)
486
+ // derives one here, from the key alone. Kept apart from `level`: the
487
+ // manifest records what it did before (#6944), and the design gate above is
488
+ // already decided. Fail closed: a probe that cannot answer installs today's
489
+ // packs and never refuses the run. A `--without-mcp` spoke has nothing to
490
+ // install, so it never probes.
491
+ let mcpLevel = level ?? "free";
492
+ if (level === undefined && !(spoke !== undefined && opts.mcp === false)) {
493
+ try {
494
+ mcpLevel = await deriveDesignLevel({
495
+ licenseKey,
496
+ ...(opts.moduleRegistryUrl !== undefined
497
+ ? { registryUrl: opts.moduleRegistryUrl }
498
+ : {}),
499
+ ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),
500
+ });
501
+ }
502
+ catch {
503
+ mcpLevel = "free";
504
+ }
505
+ }
506
+ // Threaded to extractModuleBundle for `package.json` patch targets'
507
+ // `workspace:*` substitution (spec 5418 § 3 D2) — the same version map
508
+ // `scaffoldSync` already reads for `copyTemplate`, re-read here since
509
+ // `scaffold()` doesn't share `scaffoldSync`'s call frame. Read before the
510
+ // target exists, so a level pack it lacks refuses first (#11952 NFR4).
511
+ const versions = readVersionMap();
512
+ // Throws, naming the pack, when `versions` lacks one the level ships — the
513
+ // same check the write below makes, run here against an empty dependency set.
514
+ withLevelMcpPackages(`{"dependencies":{}}`, mcpLevel, versions);
484
515
  // The template's OWN bundle, fetched here — before `scaffoldSync` — so the
485
516
  // fourth refusal (the template's bundle unpublished, parent record D17 /
486
517
  // spec 5481 § 3 DD5 row 4) throws with the target still non-existent, like
@@ -543,11 +574,6 @@ export async function scaffold(opts) {
543
574
  // `resolveSiteChrome` reads a layout object now, not a `StarterDesign`.
544
575
  ...(resolvedDesign !== undefined ? { designLayout: resolvedDesign.pkg.layout } : {}),
545
576
  }, copied);
546
- // Threaded to extractModuleBundle for `package.json` patch targets'
547
- // `workspace:*` substitution (spec 5418 § 3 D2) — the same version map
548
- // `scaffoldSync` already reads for `copyTemplate`, re-read here since
549
- // `scaffold()` doesn't share `scaffoldSync`'s call frame.
550
- const versions = readVersionMap();
551
577
  // #6460 — the SAME marker map `scaffoldSync` just substituted the base
552
578
  // `templates/` copy with, rebuilt here from the same inputs (`scaffold()`
553
579
  // does not share `scaffoldSync`'s call frame, exactly as `versions` above
@@ -875,6 +901,13 @@ export async function scaffold(opts) {
875
901
  }));
876
902
  }
877
903
  }
904
+ // #11952 D2 — every pack the level ships, after the bundles' own patches.
905
+ const mcpPkgPath = join(result.targetDir, "apps", "mcp", "package.json");
906
+ if (existsSync(mcpPkgPath)) {
907
+ const next = withLevelMcpPackages(readFileSync(mcpPkgPath, "utf8"), mcpLevel, versions);
908
+ if (next.added.length > 0)
909
+ writeFileSync(mcpPkgPath, next.text);
910
+ }
878
911
  // #7536 D3 — the registry follows `apps/web/package.json`, which a module
879
912
  // bundle's `patches` (and the template layer) just finished editing.
880
913
  writePaidSections(result.targetDir);
@@ -1259,6 +1292,22 @@ export async function addModule(opts) {
1259
1292
  if (bundleBytes === undefined) {
1260
1293
  throw new Error(`module "${opts.moduleName}": no bundle was resolved`);
1261
1294
  }
1295
+ // #11952 D3 — the MCP build installs its level's packs, so add-module reads
1296
+ // the level from the same key, as `scaffold()` and `update` do. A read that
1297
+ // fails adds no packs and never refuses the run.
1298
+ let mcpLevel;
1299
+ try {
1300
+ ({ level: mcpLevel } = await deriveLevel({
1301
+ licenseKey: opts.licenseKey,
1302
+ ...(opts.moduleRegistryUrl !== undefined
1303
+ ? { registryUrl: opts.moduleRegistryUrl }
1304
+ : {}),
1305
+ ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),
1306
+ }));
1307
+ }
1308
+ catch {
1309
+ mcpLevel = undefined;
1310
+ }
1262
1311
  return applyModuleToScaffold({
1263
1312
  targetDir: targetAbs,
1264
1313
  moduleName: opts.moduleName,
@@ -1267,6 +1316,7 @@ export async function addModule(opts) {
1267
1316
  markers: buildScaffoldMarkers(basename(targetAbs)),
1268
1317
  templatesDir: TEMPLATES_DIR,
1269
1318
  siteTemplatesDir: SITE_TEMPLATES_DIR,
1319
+ ...(mcpLevel !== undefined ? { mcpLevel } : {}),
1270
1320
  });
1271
1321
  }
1272
1322
  /**
package/dist/update.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { type Level } from "./lib/module-tier.js";
1
2
  import { type MdxParse } from "./mdx-braces.js";
2
3
  import { type ModuleName } from "./parse-args.js";
3
- import type { WorkspaceVersionMap } from "./substitute.js";
4
+ import { type WorkspaceVersionMap } from "./substitute.js";
4
5
  /** A refusal the CLI exits 2 on, thrown before anything is written. */
5
6
  export declare class UpdateRefusedError extends Error {
6
7
  readonly exitCode = 2;
@@ -33,6 +34,10 @@ export interface UpdateSiteOptions {
33
34
  * `null` acts as "not installed". Absent: `loadSiteMdxParse(targetDir)`.
34
35
  */
35
36
  mdxParse?: MdxParse | null;
37
+ /** #11952 D4 — read for AILK_LICENSE_KEY only. Default process.env. */
38
+ env?: NodeJS.ProcessEnv;
39
+ /** #11952 D4 — forwarded to deriveLevel as registryUrl. Default: AILK_MODULE_REGISTRY_URL / fetchModule's default. */
40
+ moduleRegistryUrl?: string;
36
41
  }
37
42
  export interface UpdateResult {
38
43
  targetDir: string;
@@ -101,6 +106,20 @@ export interface UpdateResult {
101
106
  path: string;
102
107
  version: string;
103
108
  }>;
109
+ /** The `apps/web/package.json` scripts set to the running template's, with the published template version each was (#11940). */
110
+ scriptsCarried?: Array<{
111
+ script: string;
112
+ version: string;
113
+ }>;
114
+ /** The dependencies added to `apps/web/package.json` this run (#9889 D9, #11392), sorted. */
115
+ webDependenciesAdded?: string[];
116
+ /** #11952 D4 — the packs added to apps/mcp/package.json for the site's level. */
117
+ mcpPackagesAdded?: {
118
+ level: Level;
119
+ packages: string[];
120
+ };
121
+ /** #11952 D4 — why the level's packs were not checked, when they were not. */
122
+ mcpLevelUnchecked?: string;
104
123
  /** The `project.yaml` `env_contract` rows added for env vars the written files read (#10172). */
105
124
  envRowsAdded?: string[];
106
125
  /** Record rows dropped because the path is no longer recordable (#10173). */
@@ -183,6 +202,6 @@ export interface UpdateArgs {
183
202
  target: string | undefined;
184
203
  help: boolean;
185
204
  }
186
- export declare const UPDATE_HELP = "create-ailk update \u2014 bring template fixes into a site's copied app code.\n\nUsage:\n create-ailk update [<target-dir>]\n\nArguments:\n <target-dir> The existing site. Defaults to the current dir.\n\nOptions:\n --help, -h Print this message.\n\nReads .ailk-template-files.json (written beside .ailk-site-manifest.json by\nevery template scaffold) to tell an untouched copy from an edit. An\nuntouched apps/web, apps/api or apps/mcp file, or a root tools/jest file the\napp jest configs require, whose template copy changed is overwritten. An\nedited file whose template copy also changed is three-way merged with\n`git` (git must be on PATH); a conflict leaves the file alone and is\nlisted under \"Needs review\"; an apps/web/messages catalog instead gains the\ntemplate's new keys and keeps every value it has \u2014 also when its recorded\nversion's copy cannot be read \u2014 and is reviewed only when a key is an object\non one side and a value on the other; a written apps/web file that uses\nthrough t(...) a key the catalog then lacks is held with it, listed under\n\"Held back with <catalog>\". Each @working-theory/* package a written apps/web\nfile imports that apps/web/package.json does not declare is added to its\ndependencies at this release's version. An edited file whose\nbytes are another published create-ailk version's copy is a stale copy, not\nan edit: it is overwritten or removed as an untouched file is, listed with\nthe version it matched. An edit that touches only comment lines is listed as\n\"comment-only edit\"; on a conflict the template's copy lands. A file at a\ntemplate path that is not in the record (one an earlier sync-routes --apply\nor add-route copied without recording it) whose bytes are a published\ncreate-ailk version's copy \u2014 from the version the site was scaffolded at to\nthis one \u2014 is adopted: recorded and moved forward as an untouched file is,\nlisted under \"Adopted\" with the version it matched. One whose bytes are the\nrunning copy with this site's modules' patches applied (a module's\njest.config.cjs or next.config.mjs edit) is left as it is and not listed.\nOne whose bytes match no published copy is a site edit: skipped, never overwritten, and counted under\n\"Held as site edits, not in the record\". No file under a route the site\nlists in customizations.yaml declined_routes is written: each is listed under\n\"Skipped\" naming the declined route. Every template\ntest, and every site-edited template file, that imports a file left under\n\"Needs review\" (by a relative or @/ import, transitively) is held\nat the site's version with it, its record entry is not advanced, and it is\nlisted under \"Held back with <file>\" \u2014 reconcile the file, then run update\nagain to bring it forward. A skipped file never holds another. A file whose\nown bytes are the record's is not held by what it imports: it moves, unless\nit names an export the held copy lacks, and the held file is listed as\n\"Held back: <file> \u2014 imported by N moved files; the site edit is <hunk\nsummary>\". A written file whose import names a file the site lacks gets it\nadded when this template supplies it; otherwise it is held the same way,\nunder \"Held back with <file> (not in this site)\", unless its own copy\nalready named the file \u2014 then it moves and the path is listed under \"Not in\nthis site or the template: <file>\". A file the template removed is kept\nwhile any file still in the site imports it. A file a customizations.yaml\nentry records is never removed, nor anything it imports: it keeps its record\nrow and is listed under \"Skipped\" as kept. Every other file in the run\nstill updates. When project.yaml has an env_contract block, each\nenv var the written files read that has no row gains one; no row is edited.\nA record row at a path create-ailk no longer records is dropped and listed.\nA surface the site's .ailk-site-manifest.json names a page on but\narchitecture.yaml does not declare (one no module owns, such as projects)\ngets its route files added and is declared, listed under \"Surfaces declared\nfrom the roster\". A code-route row of that roster no page file serves is\ndropped, listed under \"Roster rows dropped, no route serves them\".\nA site with no record gets one on its first run, from the version its\n.ailk-site-manifest.json already records. A site scaffolded before\n@working-theory/mcp-server has its copied apps/mcp moved to the boot set:\nthe server and each module's paid MCP pack join apps/mcp/package.json, the\ncopied server files go, and apps/mcp/src/lib/paid-tools.generated.ts is\nrewritten on every run. A site scaffolded before @working-theory/api has its\ncopied apps/api moved to the boot file: the app becomes @working-theory/app-api,\nthe package and the six @working-theory/api-<module> packages join\napps/api/package.json, its bins and build:vercel delegate to the package, and\nthe copied server files go. Run `pnpm install` after either move, since the\napp's package.json gained dependencies. Each mdx-body page in content/ with no\n'# ' heading gets its title and description written into its body as its\nheading and intro, listed under \"Page heading added\"; a page with one heading\nis left as it is, and one with several, or one whose frontmatter it cannot\nread, is listed under \"Needs review\". Each bare { on an mdx-body page is\nescaped as \\{ when the site's own MDX parser then reads the page clean, listed\nunder \"Placeholder brace escaped\"; a page it cannot escape safely, or any page\nwith one while the site's dependencies are not installed, is listed under\n\"Needs review\". Each topology seam (*.generated.* \u2014 the web seam, the\n(authed) gate, the API origin and the MCP seam) is rendered again for the\ntopology and sign-in mode .ailk-site-manifest.json records and listed under\n\"Regenerated\", when its bytes are still the render .ailk-template-files.json\nrecords; one edited by hand, or with no recorded render, is listed under\n\"Needs review\" and left as it is. Last, the generated route files of every installed page\npackage (one whose package.json declares \"ailk\": { \"routes\" }) are rewritten\nfrom its manifest, listed under \"Route files regenerated\"; run\n`create-ailk routes --write` after the install when the packages were not\ninstalled yet. Each hand-written page `routes --check` then fails on \u2014 no\ndecided customizations.yaml entry, under a package's prefix, or at a\npackage's own route \u2014 is listed under \"Needs review\". Commit before running,\nand review the diff after.\n";
205
+ export declare const UPDATE_HELP = "create-ailk update \u2014 bring template fixes into a site's copied app code.\n\nUsage:\n create-ailk update [<target-dir>]\n\nArguments:\n <target-dir> The existing site. Defaults to the current dir.\n\nOptions:\n --help, -h Print this message.\n\nReads .ailk-template-files.json (written beside .ailk-site-manifest.json by\nevery template scaffold) to tell an untouched copy from an edit. An\nuntouched apps/web, apps/api or apps/mcp file, or a root tools/jest file the\napp jest configs require, whose template copy changed is overwritten. An\nedited file whose template copy also changed is three-way merged with\n`git` (git must be on PATH); a conflict leaves the file alone and is\nlisted under \"Needs review\"; an apps/web/messages catalog instead gains the\ntemplate's new keys and keeps every value it has \u2014 also when its recorded\nversion's copy cannot be read \u2014 and is reviewed only when a key is an object\non one side and a value on the other; a written apps/web file that uses\nthrough t(...) a key the catalog then lacks is held with it, listed under\n\"Held back with <catalog>\". Each @working-theory/* package a written apps/web\nfile imports that apps/web/package.json does not declare is added to its\ndependencies at this release's version. A site missing a paid MCP package\nits licence level ships gets it in apps/mcp/package.json; the level is read\nfrom the site's key (ailk.key, else AILK_LICENSE_KEY) through the module\nregistry, and a run with no key adds none. apps/web/package.json's\nscripts.build is set to this template's when it is a published create-ailk\ntemplate's, listed under \"Build scripts carried\"; a build script matching no\ntemplate's is left as it is and listed under \"Needs review\". An edited file whose\nbytes are another published create-ailk version's copy is a stale copy, not\nan edit: it is overwritten or removed as an untouched file is, listed with\nthe version it matched. An edit that touches only comment lines is listed as\n\"comment-only edit\"; on a conflict the template's copy lands. A file at a\ntemplate path that is not in the record (one an earlier sync-routes --apply\nor add-route copied without recording it) whose bytes are a published\ncreate-ailk version's copy \u2014 from the version the site was scaffolded at to\nthis one \u2014 is adopted: recorded and moved forward as an untouched file is,\nlisted under \"Adopted\" with the version it matched. One whose bytes are the\nrunning copy with this site's modules' patches applied (a module's\njest.config.cjs or next.config.mjs edit) is left as it is and not listed.\nOne whose bytes match no published copy is a site edit: skipped, never overwritten, and counted under\n\"Held as site edits, not in the record\". No file under a route the site\nlists in customizations.yaml declined_routes is written: each is listed under\n\"Skipped\" naming the declined route. Every template\ntest, and every site-edited template file, that imports a file left under\n\"Needs review\" (by a relative or @/ import, transitively) is held\nat the site's version with it, its record entry is not advanced, and it is\nlisted under \"Held back with <file>\" \u2014 reconcile the file, then run update\nagain to bring it forward. A skipped file never holds another. A file whose\nown bytes are the record's is not held by what it imports: it moves, unless\nit names an export the held copy lacks, and the held file is listed as\n\"Held back: <file> \u2014 imported by N moved files; the site edit is <hunk\nsummary>\". A written file whose import names a file the site lacks gets it\nadded when this template supplies it; otherwise it is held the same way,\nunder \"Held back with <file> (not in this site)\", unless its own copy\nalready named the file \u2014 then it moves and the path is listed under \"Not in\nthis site or the template: <file>\". A file the template removed is kept\nwhile any file still in the site imports it. A file a customizations.yaml\nentry records is never removed, nor anything it imports: it keeps its record\nrow and is listed under \"Skipped\" as kept. Every other file in the run\nstill updates. When project.yaml has an env_contract block, each\nenv var the written files read that has no row gains one; no row is edited.\nA record row at a path create-ailk no longer records is dropped and listed.\nA surface the site's .ailk-site-manifest.json names a page on but\narchitecture.yaml does not declare (one no module owns, such as projects)\ngets its route files added and is declared, listed under \"Surfaces declared\nfrom the roster\". A code-route row of that roster no page file serves is\ndropped, listed under \"Roster rows dropped, no route serves them\".\nA site with no record gets one on its first run, from the version its\n.ailk-site-manifest.json already records. A site scaffolded before\n@working-theory/mcp-server has its copied apps/mcp moved to the boot set:\nthe server and each module's paid MCP pack join apps/mcp/package.json, the\ncopied server files go, and apps/mcp/src/lib/paid-tools.generated.ts is\nrewritten on every run. A site scaffolded before @working-theory/api has its\ncopied apps/api moved to the boot file: the app becomes @working-theory/app-api,\nthe package and the six @working-theory/api-<module> packages join\napps/api/package.json, its bins and build:vercel delegate to the package, and\nthe copied server files go. Run `pnpm install` after either move, since the\napp's package.json gained dependencies. Each mdx-body page in content/ with no\n'# ' heading gets its title and description written into its body as its\nheading and intro, listed under \"Page heading added\"; a page with one heading\nis left as it is, and one with several, or one whose frontmatter it cannot\nread, is listed under \"Needs review\". Each bare { on an mdx-body page is\nescaped as \\{ when the site's own MDX parser then reads the page clean, listed\nunder \"Placeholder brace escaped\"; a page it cannot escape safely, or any page\nwith one while the site's dependencies are not installed, is listed under\n\"Needs review\". Each topology seam (*.generated.* \u2014 the web seam, the\n(authed) gate, the API origin and the MCP seam) is rendered again for the\ntopology and sign-in mode .ailk-site-manifest.json records and listed under\n\"Regenerated\", when its bytes are still the render .ailk-template-files.json\nrecords; one edited by hand, or with no recorded render, is listed under\n\"Needs review\" and left as it is. Last, the generated route files of every installed page\npackage (one whose package.json declares \"ailk\": { \"routes\" }) are rewritten\nfrom its manifest, listed under \"Route files regenerated\"; run\n`create-ailk routes --write` after the install when the packages were not\ninstalled yet. Each hand-written page `routes --check` then fails on \u2014 no\ndecided customizations.yaml entry, under a package's prefix, or at a\npackage's own route \u2014 is listed under \"Needs review\". Commit before running,\nand review the diff after.\n";
187
206
  /** Parse the argv AFTER the `update` word. Strict `node:util` parseArgs, like `parseAdoptArgs`. */
188
207
  export declare function parseUpdateArgs(argv: string[]): UpdateArgs;