@glw907/cairn-cms 0.50.0 → 0.51.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 (66) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/components/EditPage.svelte +94 -16
  3. package/dist/components/EditPage.svelte.d.ts +4 -1
  4. package/dist/components/EditorToolbar.svelte +79 -8
  5. package/dist/components/EditorToolbar.svelte.d.ts +10 -2
  6. package/dist/components/MarkdownEditor.svelte +20 -2
  7. package/dist/components/cairn-admin.css +57 -9
  8. package/dist/components/editor-highlight.d.ts +1 -0
  9. package/dist/components/editor-highlight.js +31 -8
  10. package/dist/components/markdown-directives.d.ts +10 -0
  11. package/dist/components/markdown-directives.js +54 -1
  12. package/dist/components/preview-doc.d.ts +27 -0
  13. package/dist/components/preview-doc.js +64 -0
  14. package/dist/content/compose.js +1 -0
  15. package/dist/content/types.d.ts +33 -0
  16. package/dist/diagnostics/conditions.js +24 -0
  17. package/dist/doctor/bin.js +30 -12
  18. package/dist/doctor/check-floors.d.ts +15 -0
  19. package/dist/doctor/check-floors.js +107 -0
  20. package/dist/doctor/check-probe.d.ts +3 -0
  21. package/dist/doctor/check-probe.js +123 -0
  22. package/dist/doctor/checks-github.js +1 -1
  23. package/dist/doctor/checks-local.d.ts +1 -0
  24. package/dist/doctor/checks-local.js +28 -2
  25. package/dist/doctor/cloudflare-api.js +2 -2
  26. package/dist/doctor/index.d.ts +28 -3
  27. package/dist/doctor/index.js +47 -6
  28. package/dist/doctor/types.d.ts +2 -0
  29. package/dist/doctor/wrangler-config.d.ts +4 -0
  30. package/dist/doctor/wrangler-config.js +11 -0
  31. package/dist/env.d.ts +2 -1
  32. package/dist/env.js +9 -4
  33. package/dist/index.d.ts +1 -1
  34. package/dist/sveltekit/content-routes.d.ts +5 -1
  35. package/dist/sveltekit/content-routes.js +25 -17
  36. package/dist/sveltekit/guard.d.ts +8 -2
  37. package/dist/sveltekit/guard.js +3 -1
  38. package/dist/sveltekit/nav-routes.js +3 -9
  39. package/dist/vite/index.d.ts +16 -0
  40. package/dist/vite/index.js +57 -13
  41. package/package.json +2 -2
  42. package/src/lib/components/EditPage.svelte +94 -16
  43. package/src/lib/components/EditorToolbar.svelte +79 -8
  44. package/src/lib/components/MarkdownEditor.svelte +20 -2
  45. package/src/lib/components/cairn-admin.css +59 -0
  46. package/src/lib/components/editor-highlight.ts +32 -7
  47. package/src/lib/components/markdown-directives.ts +51 -1
  48. package/src/lib/components/preview-doc.ts +82 -0
  49. package/src/lib/content/compose.ts +1 -0
  50. package/src/lib/content/types.ts +32 -0
  51. package/src/lib/diagnostics/conditions.ts +24 -0
  52. package/src/lib/doctor/bin.ts +35 -10
  53. package/src/lib/doctor/check-floors.ts +124 -0
  54. package/src/lib/doctor/check-probe.ts +138 -0
  55. package/src/lib/doctor/checks-github.ts +3 -1
  56. package/src/lib/doctor/checks-local.ts +28 -2
  57. package/src/lib/doctor/cloudflare-api.ts +4 -2
  58. package/src/lib/doctor/index.ts +67 -6
  59. package/src/lib/doctor/types.ts +2 -0
  60. package/src/lib/doctor/wrangler-config.ts +11 -0
  61. package/src/lib/env.ts +9 -4
  62. package/src/lib/index.ts +2 -0
  63. package/src/lib/sveltekit/content-routes.ts +29 -17
  64. package/src/lib/sveltekit/guard.ts +4 -2
  65. package/src/lib/sveltekit/nav-routes.ts +3 -10
  66. package/src/lib/vite/index.ts +71 -17
@@ -5,7 +5,7 @@ import { HighlightStyle } from '@codemirror/language';
5
5
  import { tags } from '@lezer/highlight';
6
6
  import { Decoration, ViewPlugin } from '@codemirror/view';
7
7
  import { RangeSetBuilder } from '@codemirror/state';
8
- import { directiveLineKind, findInlineDirectives } from './markdown-directives.js';
8
+ import { directiveLineKind, fenceDepths, findInlineDirectives } from './markdown-directives.js';
9
9
  /** Markdown token colors over the admin theme variables. */
10
10
  export function cairnHighlightStyle() {
11
11
  return HighlightStyle.define([
@@ -24,20 +24,39 @@ export function cairnHighlightStyle() {
24
24
  // The machinery lines explain themselves on hover, so an editor who has never seen ::: syntax
25
25
  // learns what the line is without leaving the page.
26
26
  const MACHINERY_HINT = 'Layout marker. Edit the text between these lines and leave this line as it is.';
27
- const fenceLine = Decoration.line({ class: 'cm-cairn-directive-fence', attributes: { title: MACHINERY_HINT } });
27
+ // Nesting deeper than three steps shares the third visual step; the depth model itself is unbounded.
28
+ const DEPTH_STEPS = [1, 2, 3];
29
+ const fenceLines = DEPTH_STEPS.map((d) => Decoration.line({ class: `cm-cairn-directive-fence cm-cairn-depth-${d}`, attributes: { title: MACHINERY_HINT } }));
30
+ const contentLines = DEPTH_STEPS.map((d) => Decoration.line({ class: `cm-cairn-directive-content cm-cairn-depth-${d}` }));
28
31
  const leafLine = Decoration.line({ class: 'cm-cairn-directive-leaf', attributes: { title: MACHINERY_HINT } });
29
32
  const inlineMark = Decoration.mark({ class: 'cm-cairn-directive-inline' });
30
- function buildDirectiveDecorations(view) {
33
+ // Depth needs the whole document, since a visible line's containers can open above the viewport.
34
+ // One regex pass per line, linear in the document; at admin entry sizes (tens of kilobytes) that
35
+ // is well under a millisecond. The plugin caches the result, so the scan reruns only when the
36
+ // document changes and a scroll rebuilds the viewport decorations from the cached array.
37
+ function docDepths(view) {
38
+ const doc = view.state.doc;
39
+ const lines = [];
40
+ for (let n = 1; n <= doc.lines; n++)
41
+ lines.push(doc.line(n).text);
42
+ return fenceDepths(lines);
43
+ }
44
+ function buildDirectiveDecorations(view, depths) {
31
45
  const builder = new RangeSetBuilder();
32
46
  for (const { from, to } of view.visibleRanges) {
33
47
  for (let pos = from; pos <= to;) {
34
48
  const line = view.state.doc.lineAt(pos);
35
49
  const kind = directiveLineKind(line.text);
36
- if (kind === 'fence')
37
- builder.add(line.from, line.from, fenceLine);
50
+ const depth = Math.min(depths[line.number - 1] ?? 0, DEPTH_STEPS.length);
51
+ // A fence-shaped line at depth 0 is one the depth scan disowned (a documented example
52
+ // inside a code block, outside any container); it gets no machinery treatment.
53
+ if (kind === 'fence' && depth > 0)
54
+ builder.add(line.from, line.from, fenceLines[depth - 1]);
38
55
  else if (kind === 'leaf')
39
56
  builder.add(line.from, line.from, leafLine);
40
- else {
57
+ else if (kind === null) {
58
+ if (depth > 0)
59
+ builder.add(line.from, line.from, contentLines[depth - 1]);
41
60
  for (const r of findInlineDirectives(line.text)) {
42
61
  builder.add(line.from + r.from, line.from + r.to, inlineMark);
43
62
  }
@@ -51,12 +70,16 @@ function buildDirectiveDecorations(view) {
51
70
  export function cairnDirectivePlugin() {
52
71
  return ViewPlugin.fromClass(class {
53
72
  decorations;
73
+ depths;
54
74
  constructor(view) {
55
- this.decorations = buildDirectiveDecorations(view);
75
+ this.depths = docDepths(view);
76
+ this.decorations = buildDirectiveDecorations(view, this.depths);
56
77
  }
57
78
  update(update) {
79
+ if (update.docChanged)
80
+ this.depths = docDepths(update.view);
58
81
  if (update.docChanged || update.viewportChanged)
59
- this.decorations = buildDirectiveDecorations(update.view);
82
+ this.decorations = buildDirectiveDecorations(update.view, this.depths);
60
83
  }
61
84
  }, { decorations: (v) => v.decorations });
62
85
  }
@@ -1,5 +1,15 @@
1
1
  /** Classify a whole line as a container fence, a leaf directive, or neither. */
2
2
  export declare function directiveLineKind(line: string): 'fence' | 'leaf' | null;
3
+ /**
4
+ * The 1-based container depth each line sits at, or null outside any container. A named fence
5
+ * opens a container; a bare fence closes the most recent one (colon counts are not trusted for
6
+ * pairing, since authors vary them). An opener and its closer share the opener's depth, and a
7
+ * line between them carries the depth of its innermost container. Lines inside a fenced code
8
+ * block are plain content, so a documented ::: example cannot open a phantom container running
9
+ * to end of document. Author errors are tolerated: an unmatched closer reads as depth 1 and the
10
+ * count never goes below zero.
11
+ */
12
+ export declare function fenceDepths(lines: string[]): (number | null)[];
3
13
  /** Inline directive ranges (`:name[...]{...}`) within a line of text. */
4
14
  export declare function findInlineDirectives(text: string): {
5
15
  from: number;
@@ -1,9 +1,17 @@
1
1
  // Remark-directive detection for the editor's machinery highlighting (spec: directive syntax is
2
2
  // styled distinctly so an editor can tell component scaffolding from prose). Pure functions; the
3
3
  // CodeMirror decoration plugin wraps them.
4
- const FENCE = /^\s{0,3}:::+\s*[\w-]*\s*(\{[^}]*\})?\s*$/;
4
+ // A container fence: three or more colons, then an optional name, an optional [label], and
5
+ // optional {attrs}, in remark-directive order. The name is captured so the depth scan below can
6
+ // tell an opener (named) from a closer (bare colons). Matching is tolerant of stray whitespace,
7
+ // the same posture as the leaf form: a slightly off fence should still read as machinery.
8
+ const FENCE = /^\s{0,3}:{3,}\s*([\w-]*)\s*(\[[^\]]*\])?\s*(\{[^}]*\})?\s*$/;
5
9
  const LEAF = /^\s{0,3}::[\w-]+(\[[^\]]*\])?(\{[^}]*\})?\s*$/;
6
10
  const INLINE = /(?<![:\w]):[\w-]+\[[^\]]*\](\{[^}]*\})?/g;
11
+ // A fenced code block's delimiter: three or more backticks or tildes, indent-tolerant like the
12
+ // directive forms. The depth scan tracks these so a documented ::: example inside a code block
13
+ // never opens a real container.
14
+ const CODE_FENCE = /^\s{0,3}(`{3,}|~{3,})/;
7
15
  /** Classify a whole line as a container fence, a leaf directive, or neither. */
8
16
  export function directiveLineKind(line) {
9
17
  if (FENCE.test(line))
@@ -12,6 +20,51 @@ export function directiveLineKind(line) {
12
20
  return 'leaf';
13
21
  return null;
14
22
  }
23
+ /**
24
+ * The 1-based container depth each line sits at, or null outside any container. A named fence
25
+ * opens a container; a bare fence closes the most recent one (colon counts are not trusted for
26
+ * pairing, since authors vary them). An opener and its closer share the opener's depth, and a
27
+ * line between them carries the depth of its innermost container. Lines inside a fenced code
28
+ * block are plain content, so a documented ::: example cannot open a phantom container running
29
+ * to end of document. Author errors are tolerated: an unmatched closer reads as depth 1 and the
30
+ * count never goes below zero.
31
+ */
32
+ export function fenceDepths(lines) {
33
+ const depths = [];
34
+ let open = 0;
35
+ // The marker character that opened the current code block, or null outside one. Only a line
36
+ // opening with the same character closes it, so tildes inside a backtick block stay literal.
37
+ let codeMarker = null;
38
+ for (const line of lines) {
39
+ const code = CODE_FENCE.exec(line);
40
+ if (code) {
41
+ if (codeMarker === null)
42
+ codeMarker = code[1][0];
43
+ else if (code[1][0] === codeMarker)
44
+ codeMarker = null;
45
+ depths.push(open > 0 ? open : null);
46
+ continue;
47
+ }
48
+ if (codeMarker !== null) {
49
+ depths.push(open > 0 ? open : null);
50
+ continue;
51
+ }
52
+ const fence = FENCE.exec(line);
53
+ if (!fence) {
54
+ depths.push(open > 0 ? open : null);
55
+ }
56
+ else if (fence[1]) {
57
+ open += 1;
58
+ depths.push(open);
59
+ }
60
+ else {
61
+ depths.push(Math.max(open, 1));
62
+ if (open > 0)
63
+ open -= 1;
64
+ }
65
+ }
66
+ return depths;
67
+ }
15
68
  /** Inline directive ranges (`:name[...]{...}`) within a line of text. */
16
69
  export function findInlineDirectives(text) {
17
70
  const out = [];
@@ -0,0 +1,27 @@
1
+ import type { ResolvedPreview } from '../content/types.js';
2
+ /** One width the preview frame can take. */
3
+ export interface PreviewDevice {
4
+ id: 'desktop' | 'tablet' | 'phone' | 'small';
5
+ /** The device menu label, also the frame caption's first half. */
6
+ label: string;
7
+ /** Frame width in CSS pixels; null fills the pane (Desktop). */
8
+ width: number | null;
9
+ }
10
+ /** A preview device's id, the value the page persists. */
11
+ export type PreviewDeviceId = PreviewDevice['id'];
12
+ /** The four widths the device menu offers, in menu order. Desktop leads as the default. */
13
+ export declare const previewDevices: PreviewDevice[];
14
+ /** The table row for a device id. The id type makes a miss impossible; the fallback satisfies find. */
15
+ export declare function previewDevice(id: PreviewDeviceId): PreviewDevice;
16
+ /** A device's user-facing text, shared by the toolbar's menu items and the frame caption: the
17
+ * label with its width when one is fixed, so the value reaches assistive tech at pick time. */
18
+ export declare function deviceLabel(d: PreviewDevice): string;
19
+ /**
20
+ * Build the preview iframe's srcdoc: a complete document linking the site's stylesheets around
21
+ * the rendered entry html. The html comes from the site's floored render pipeline, which already
22
+ * stripped scripts and event handlers, so it embeds unescaped; the frame's empty `sandbox` is
23
+ * belt and braces over that floor. The parameter is the flat `ResolvedPreview` shape `editLoad`
24
+ * ships, so the per-concept map can never reach the frame document by construction.
25
+ * `preview` null (a site without the adapter knob) yields a styleless but complete document.
26
+ */
27
+ export declare function buildPreviewDoc(html: string, preview: ResolvedPreview | null): string;
@@ -0,0 +1,64 @@
1
+ // cairn-cms: the edit page's preview-frame document. The admin's chrome isolation keeps the
2
+ // site's CSS out of the admin document, so EditPage renders the preview inside a sandboxed
3
+ // iframe whose document links the site's own stylesheets from the adapter's preview knob. This
4
+ // module builds that iframe's srcdoc as one pure string, so its shape is unit-testable, and it
5
+ // carries the device table the frame's width control offers.
6
+ import { escapeHtml } from '../escape.js';
7
+ /** The four widths the device menu offers, in menu order. Desktop leads as the default. */
8
+ export const previewDevices = [
9
+ { id: 'desktop', label: 'Desktop', width: null },
10
+ { id: 'tablet', label: 'Tablet', width: 768 },
11
+ { id: 'phone', label: 'Phone', width: 390 },
12
+ { id: 'small', label: 'Small phone', width: 320 },
13
+ ];
14
+ /** The table row for a device id. The id type makes a miss impossible; the fallback satisfies find. */
15
+ export function previewDevice(id) {
16
+ return previewDevices.find((d) => d.id === id) ?? previewDevices[0];
17
+ }
18
+ /** A device's user-facing text, shared by the toolbar's menu items and the frame caption: the
19
+ * label with its width when one is fixed, so the value reaches assistive tech at pick time. */
20
+ export function deviceLabel(d) {
21
+ return d.width === null ? d.label : `${d.label} · ${d.width} px`;
22
+ }
23
+ /**
24
+ * Build the preview iframe's srcdoc: a complete document linking the site's stylesheets around
25
+ * the rendered entry html. The html comes from the site's floored render pipeline, which already
26
+ * stripped scripts and event handlers, so it embeds unescaped; the frame's empty `sandbox` is
27
+ * belt and braces over that floor. The parameter is the flat `ResolvedPreview` shape `editLoad`
28
+ * ships, so the per-concept map can never reach the frame document by construction.
29
+ * `preview` null (a site without the adapter knob) yields a styleless but complete document.
30
+ */
31
+ export function buildPreviewDoc(html, preview) {
32
+ const links = (preview?.stylesheets ?? [])
33
+ .map((href) => `<link rel="stylesheet" href="${escapeHtml(href)}">`)
34
+ .join('\n');
35
+ const bodyAttrs = preview?.bodyClass ? ` class="${escapeHtml(preview.bodyClass)}"` : '';
36
+ const content = preview?.containerClass
37
+ ? `<div class="${escapeHtml(preview.containerClass)}">${html}</div>`
38
+ : html;
39
+ // The reset sits BEFORE the site links so the site's CSS wins every collision: it only clears
40
+ // the default body margin and pins a white ground for sheets that assume one.
41
+ //
42
+ // The base tag is what makes links inert. The empty sandbox alone does not: a sandboxed
43
+ // context may still navigate itself, and a srcdoc document resolves relative hrefs against the
44
+ // parent's base URL, so a clicked fragment or root link could render the admin login inside
45
+ // the frame. Targeting every link at a new tab turns each click into a popup, and the sandbox
46
+ // (which grants no allow-popups) blocks it, so a proofing click goes nowhere.
47
+ return [
48
+ '<!doctype html>',
49
+ '<html>',
50
+ '<head>',
51
+ '<meta charset="utf-8">',
52
+ '<meta name="viewport" content="width=device-width, initial-scale=1">',
53
+ '<base target="_blank">',
54
+ '<style>body{margin:0;background:#fff}</style>',
55
+ links,
56
+ '</head>',
57
+ `<body${bodyAttrs}>`,
58
+ content,
59
+ '</body>',
60
+ '</html>',
61
+ ]
62
+ .filter((line) => line !== '')
63
+ .join('\n');
64
+ }
@@ -31,6 +31,7 @@ export function composeRuntime({ adapter, siteConfig, extensions = [] }) {
31
31
  registry: adapter.registry,
32
32
  icons: adapter.icons,
33
33
  navMenu: adapter.navMenu,
34
+ preview: adapter.preview,
34
35
  assets: adapter.assets,
35
36
  adminPanels,
36
37
  fieldTypes,
@@ -133,6 +133,34 @@ export interface NavMenuConfig {
133
133
  /** Max nesting depth allowed in the editor; defaults to 2. */
134
134
  maxDepth?: number;
135
135
  }
136
+ /**
137
+ * How the edit page's preview frame reproduces the live site's content styling. The admin
138
+ * deliberately never loads the site's CSS (chrome isolation), so a design-accurate preview needs
139
+ * the site to name its stylesheets for the preview frame; without this knob the preview renders
140
+ * unstyled markup. The frame's srcdoc pins a white body background as a deliberately overridable
141
+ * default, so a site whose ground is not white should state its body background in its own
142
+ * stylesheet.
143
+ */
144
+ export interface PreviewConfig {
145
+ /** Absolute or root-relative URLs of the site's compiled stylesheets, linked inside the
146
+ * preview document. A Vite `?url` import of the site's CSS resolves the hashed asset URL. */
147
+ stylesheets: string[];
148
+ /** Class list applied to the preview document's body, for theme or typography roots. */
149
+ bodyClass?: string;
150
+ /** Class list for a wrapper element around the rendered content, reproducing the site's
151
+ * content container (a prose or measure class). Omitted renders the content bare. */
152
+ containerClass?: string;
153
+ /** Per-concept overrides of bodyClass and containerClass, keyed by concept id. An entry's
154
+ * preview resolves the override for its concept over the top-level values; stylesheets are
155
+ * always shared. */
156
+ byConcept?: Record<string, {
157
+ bodyClass?: string;
158
+ containerClass?: string;
159
+ }>;
160
+ }
161
+ /** The flat preview shape `editLoad` ships to the edit page: the top-level `PreviewConfig`
162
+ * values with the entry's concept override applied, and no `byConcept` map. */
163
+ export type ResolvedPreview = Omit<PreviewConfig, 'byConcept'>;
136
164
  /** Reserved asset slot (seam 4). Typed and unused in the rebuild; R7/R9 read it later with no contract change. */
137
165
  export interface AssetConfig {
138
166
  /** Repo-relative asset roots, e.g. ["static/images"]. */
@@ -168,6 +196,9 @@ export interface CairnAdapter {
168
196
  /** The site's glyph name to SVG path-data map, for the admin icon picker and the renderer. */
169
197
  icons?: IconSet;
170
198
  navMenu?: NavMenuConfig;
199
+ /** The live site's content styling for the preview frame. The admin's chrome isolation keeps
200
+ * the site's CSS out of the admin document, so the preview frame links these instead. */
201
+ preview?: PreviewConfig;
171
202
  assets?: AssetConfig;
172
203
  }
173
204
  /**
@@ -263,6 +294,8 @@ export interface CairnRuntime {
263
294
  /** The site's glyph name to SVG path-data map, for the admin icon picker and the renderer. */
264
295
  icons?: IconSet;
265
296
  navMenu?: NavMenuConfig;
297
+ /** The live site's content styling for the preview frame; passed through from the adapter. */
298
+ preview?: PreviewConfig;
266
299
  assets?: AssetConfig;
267
300
  /** Admin panels contributed by extensions (Mode 2). Empty until Plan 09 wires the dispatch route. */
268
301
  adminPanels?: AdminPanel[];
@@ -69,6 +69,14 @@ export const REGISTRY = {
69
69
  remediation: "Set csrf: { checkOrigin: false } in svelte.config.js and wire createAuthGuard into src/hooks.server.ts; cairn's guard owns the Origin and double-submit token checks.",
70
70
  docsAnchor: 'cloudflare-readiness.md#hand-cairn-the-csrf-authority',
71
71
  },
72
+ 'config.public-origin-invalid': {
73
+ id: 'config.public-origin-invalid',
74
+ severity: 'blocker',
75
+ title: 'PUBLIC_ORIGIN is missing or invalid',
76
+ why: 'PUBLIC_ORIGIN is unset, does not parse as a URL, or uses http on a non-local host. The magic-link confirmation links and the absolute feed URLs derive from it, config-only so a forged Host header cannot redirect a link, and sign-in cannot mint a usable link without it.',
77
+ remediation: "Set PUBLIC_ORIGIN to the site's canonical https origin in the wrangler config vars (with .dev.vars carrying the local http override), then re-deploy; http passes only on localhost or 127.0.0.1.",
78
+ docsAnchor: 'cloudflare-readiness.md#set-the-public-origin',
79
+ },
72
80
  'config.site-config-invalid': {
73
81
  id: 'config.site-config-invalid',
74
82
  severity: 'blocker',
@@ -77,6 +85,14 @@ export const REGISTRY = {
77
85
  remediation: 'Correct site.config.yaml; the parse or validation error names the failing field or URL-policy rule.',
78
86
  docsAnchor: 'cloudflare-readiness.md#validate-the-site-config',
79
87
  },
88
+ 'config.dependency-floors-unmet': {
89
+ id: 'config.dependency-floors-unmet',
90
+ severity: 'blocker',
91
+ title: 'A framework dependency sits below the engine floor',
92
+ why: 'The lockfile resolves svelte or @sveltejs/kit below the range the engine declares as a peer. Consumer sites compile the shipped .svelte sources, so a below-floor compiler bites silently at build time; svelte 5.56.1 miscompiles parenthesized boolean groupings, which is why the svelte floor is ^5.56.3.',
93
+ remediation: "Raise the devDependency range in the site's package.json to the engine peer range and reinstall so the lockfile re-resolves, for example `npm install --save-dev svelte@^5.56.3`.",
94
+ docsAnchor: 'cloudflare-readiness.md#meet-the-dependency-floors',
95
+ },
80
96
  'edge.hsts-off': {
81
97
  id: 'edge.hsts-off',
82
98
  severity: 'warning',
@@ -102,6 +118,14 @@ export const REGISTRY = {
102
118
  docsAnchor: 'cloudflare-readiness.md#install-the-github-app',
103
119
  logEvent: 'github.unreachable',
104
120
  },
121
+ 'admin.login-probe-failed': {
122
+ id: 'admin.login-probe-failed',
123
+ severity: 'blocker',
124
+ title: 'Live admin login probe failed',
125
+ why: 'A live request to the deployed admin did not answer with the working sign-in envelope (the login page, its CSRF cookie and hidden field, and the request action), so a real editor cannot sign in either. A probe failure has many possible causes; the detail line names the assertion that failed.',
126
+ remediation: 'Read the failed assertion in the detail line, run the full doctor against the same site, and work through the deploy guide; the other checks narrow the cause.',
127
+ docsAnchor: 'cloudflare-readiness.md#probe-the-deployed-admin',
128
+ },
105
129
  };
106
130
  // The registry is shared identity, never working state; freeze every entry and the map itself.
107
131
  for (const entry of Object.values(REGISTRY))
@@ -7,8 +7,10 @@
7
7
  // before the process ends.
8
8
  import { readFile } from 'node:fs/promises';
9
9
  import { resolve } from 'node:path';
10
+ import { liveProbeCheck } from './check-probe.js';
10
11
  import { liveSendCheck } from './check-send.js';
11
- import { contextFromEnv, defaultChecks, formatReport, parseArgs, runDoctor } from './index.js';
12
+ import { readWranglerConfig } from './wrangler-config.js';
13
+ import { contextFromEnv, defaultChecks, deriveMissingInputs, formatReport, parseArgs, runDoctor, } from './index.js';
12
14
  async function main() {
13
15
  let args;
14
16
  try {
@@ -20,23 +22,39 @@ async function main() {
20
22
  return;
21
23
  }
22
24
  const cwd = process.cwd();
25
+ const readFileUnderCwd = async (relPath) => {
26
+ try {
27
+ return await readFile(resolve(cwd, relPath), 'utf8');
28
+ }
29
+ catch (err) {
30
+ if (err.code === 'ENOENT')
31
+ return null;
32
+ throw err;
33
+ }
34
+ };
35
+ // Fill inputs the flags and env left missing from the repo itself: from and repo off the
36
+ // adapter (through the vite arm, which exists only on this bin path, never in a Worker)
37
+ // and the account id off the wrangler config. The API token stays env-only.
38
+ const derived = await deriveMissingInputs(contextFromEnv(process.env, args, cwd), {
39
+ adapterFacts: async () => {
40
+ const { readAdapterFacts } = await import('../vite/index.js');
41
+ return readAdapterFacts(cwd);
42
+ },
43
+ wranglerAccountId: async () => (await readWranglerConfig(readFileUnderCwd))?.accountId,
44
+ });
23
45
  const ctx = {
24
- ...contextFromEnv(process.env, args, cwd),
46
+ ...derived,
25
47
  fetch: globalThis.fetch,
26
- readFile: async (relPath) => {
27
- try {
28
- return await readFile(resolve(cwd, relPath), 'utf8');
29
- }
30
- catch (err) {
31
- if (err.code === 'ENOENT')
32
- return null;
33
- throw err;
34
- }
35
- },
48
+ readFile: readFileUnderCwd,
36
49
  };
37
50
  const checks = defaultChecks();
38
51
  if (args.sendTest)
39
52
  checks.push(liveSendCheck(args.sendTest));
53
+ // The probe is an opt-in network POST against a live site, so it joins only on --probe;
54
+ // the bare flag hands the URL resolution (the PUBLIC_ORIGIN input) to the check itself.
55
+ if (args.probe !== undefined) {
56
+ checks.push(liveProbeCheck(args.probe === true ? undefined : args.probe));
57
+ }
40
58
  const { results, failed } = await runDoctor(checks, ctx);
41
59
  console.log(formatReport(results));
42
60
  process.exitCode = failed > 0 ? 1 : 0;
@@ -0,0 +1,15 @@
1
+ import type { CheckResult, DoctorCheck } from './types.js';
2
+ /**
3
+ * Judge a lockfile's resolved framework versions against the engine's peer ranges. Pure, so the
4
+ * tests drive it table-style; the check object wires in the real lockfile and the real peers.
5
+ * A below-range version fails; a lockfile or entry the check cannot read skips, since a pnpm or
6
+ * yarn consumer carries no package-lock.json at all.
7
+ */
8
+ export declare function dependencyFloorsResult(lockText: string | null, peers: Record<string, string>): CheckResult;
9
+ /**
10
+ * The engine's own declared peer ranges, read from the installed package.json at runtime so the
11
+ * floors are declared exactly once. The self-reference resolves through the consumer's
12
+ * node_modules in a real install and through the repo root during development.
13
+ */
14
+ export declare function readEnginePeers(): Record<string, string>;
15
+ export declare const configDependencyFloors: DoctorCheck;
@@ -0,0 +1,107 @@
1
+ // The dependency-floors check. The engine's peer ranges have teeth only when something reads
2
+ // the consumer's lockfile, where a transitively pinned svelte can sit below the floor while
3
+ // package.json looks fine (the ecxc retrofit shipped svelte 5.56.0 that way). The check compares
4
+ // the resolved svelte and @sveltejs/kit versions in package-lock.json against the peer ranges
5
+ // the installed @glw907/cairn-cms declares, read at runtime so the floors live in one place.
6
+ import { createRequire } from 'node:module';
7
+ import { fail, pass, skip } from './types.js';
8
+ // Plain x.y.z only. A prerelease or build tag returns null, so the check skips rather than
9
+ // guessing how a tagged build orders against the floor.
10
+ function parseVersion(text) {
11
+ const m = text.match(/^(\d+)\.(\d+)\.(\d+)$/);
12
+ if (!m)
13
+ return null;
14
+ return { major: Number(m[1]), minor: Number(m[2]), patch: Number(m[3]) };
15
+ }
16
+ // The engine's peers are simple caret ranges (^x.y.z, or ^x.y like the kit floor ^2.12), so
17
+ // this handles the caret form only; anything else returns null and the check skips for that
18
+ // dependency instead of approximating a full semver implementation.
19
+ function caretFloor(range) {
20
+ const m = range.match(/^\^(\d+)(?:\.(\d+))?(?:\.(\d+))?$/);
21
+ if (!m)
22
+ return null;
23
+ return { major: Number(m[1]), minor: Number(m[2] ?? 0), patch: Number(m[3] ?? 0) };
24
+ }
25
+ function compareVersions(a, b) {
26
+ return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
27
+ }
28
+ function lockedVersion(lock, dep) {
29
+ const version = lock.packages?.[`node_modules/${dep}`]?.version;
30
+ return typeof version === 'string' ? version : undefined;
31
+ }
32
+ /**
33
+ * Judge a lockfile's resolved framework versions against the engine's peer ranges. Pure, so the
34
+ * tests drive it table-style; the check object wires in the real lockfile and the real peers.
35
+ * A below-range version fails; a lockfile or entry the check cannot read skips, since a pnpm or
36
+ * yarn consumer carries no package-lock.json at all.
37
+ */
38
+ export function dependencyFloorsResult(lockText, peers) {
39
+ if (lockText === null) {
40
+ return skip('no package-lock.json found (a pnpm or yarn lockfile is not read)');
41
+ }
42
+ let lock;
43
+ try {
44
+ lock = JSON.parse(lockText);
45
+ }
46
+ catch {
47
+ // Like the wrangler reader: never echo file content into the report.
48
+ return fail('package-lock.json did not parse');
49
+ }
50
+ if (lock.packages === undefined) {
51
+ return skip('package-lock.json carries no packages map (lockfile v1; reinstall with a current npm)');
52
+ }
53
+ const failures = [];
54
+ const skips = [];
55
+ const passes = [];
56
+ for (const [dep, range] of Object.entries(peers)) {
57
+ const floor = caretFloor(range);
58
+ if (floor === null) {
59
+ skips.push(`${dep}: the engine range ${range} is not a simple caret range`);
60
+ continue;
61
+ }
62
+ const resolved = lockedVersion(lock, dep);
63
+ if (resolved === undefined) {
64
+ skips.push(`${dep}: no node_modules/${dep} entry in package-lock.json`);
65
+ continue;
66
+ }
67
+ const version = parseVersion(resolved);
68
+ if (version === null) {
69
+ skips.push(`${dep}: resolved ${resolved} is not a plain x.y.z version`);
70
+ continue;
71
+ }
72
+ // The caret bounds both ends: at or above the floor, same major. The engine's peers
73
+ // start at major 1 or higher, so the 0.x caret nuance never applies here.
74
+ if (compareVersions(version, floor) < 0) {
75
+ failures.push(`${dep} resolves to ${resolved}, below the engine floor ${range}`);
76
+ }
77
+ else if (version.major !== floor.major) {
78
+ failures.push(`${dep} resolves to ${resolved}, outside the engine peer range ${range}`);
79
+ }
80
+ else {
81
+ passes.push(`${dep} ${resolved}`);
82
+ }
83
+ }
84
+ if (failures.length > 0)
85
+ return fail(failures.join('; '));
86
+ if (skips.length > 0)
87
+ return skip(skips.join('; '));
88
+ return pass(`${passes.join(' and ')} satisfy the engine peer ranges`);
89
+ }
90
+ /**
91
+ * The engine's own declared peer ranges, read from the installed package.json at runtime so the
92
+ * floors are declared exactly once. The self-reference resolves through the consumer's
93
+ * node_modules in a real install and through the repo root during development.
94
+ */
95
+ export function readEnginePeers() {
96
+ const require = createRequire(import.meta.url);
97
+ const pkg = require('@glw907/cairn-cms/package.json');
98
+ return pkg.peerDependencies ?? {};
99
+ }
100
+ export const configDependencyFloors = {
101
+ id: 'config.dependency-floors',
102
+ conditionId: 'config.dependency-floors-unmet',
103
+ title: 'Dependency floors',
104
+ async run(ctx) {
105
+ return dependencyFloorsResult(await ctx.readFile('package-lock.json'), readEnginePeers());
106
+ },
107
+ };
@@ -0,0 +1,3 @@
1
+ import type { DoctorCheck } from './types.js';
2
+ /** Build the live-probe check. A missing url falls back to the PUBLIC_ORIGIN input at run time. */
3
+ export declare function liveProbeCheck(url?: string): DoctorCheck;