@cloudhal/mcp-server 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/entry-list.d.ts +3 -2
- package/dist/src/entry-list.js +26 -8
- package/dist/src/entry-tools.js +6 -5
- package/dist/src/render/cdp.d.ts +0 -1
- package/dist/src/render/cdp.js +3 -0
- package/dist/src/render/checks/components.d.ts +1 -1
- package/dist/src/render/checks/components.js +1 -1
- package/dist/src/render/checks/content.d.ts +1 -1
- package/dist/src/render/checks/content.js +48 -11
- package/dist/src/render/checks/contrast.d.ts +1 -1
- package/dist/src/render/checks/contrast.js +1 -1
- package/dist/src/render/checks/fonts.d.ts +1 -1
- package/dist/src/render/checks/fonts.js +1 -1
- package/dist/src/render/checks/index.js +6 -0
- package/dist/src/render/checks/layout.d.ts +1 -1
- package/dist/src/render/checks/layout.js +1 -1
- package/dist/src/render/checks/motion.d.ts +1 -1
- package/dist/src/render/checks/motion.js +1 -1
- package/dist/src/render/checks/navigation.d.ts +1 -1
- package/dist/src/render/checks/navigation.js +1 -1
- package/dist/src/render/checks/prelude.js +3 -3
- package/dist/src/render/checks/scripts.d.ts +11 -0
- package/dist/src/render/checks/scripts.js +45 -0
- package/dist/src/render/types.d.ts +1 -1
- package/dist/src/render/types.js +4 -0
- package/dist/src/render-tools.js +3 -1
- package/dist/src/render.d.ts +4 -3
- package/dist/src/render.js +4 -3
- package/package.json +11 -11
package/dist/src/entry-list.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RFC-0042 §4 "API and MCP" for `list_entries`: `where` and `orderBy` over a collection's list
|
|
3
|
-
* fields, run by core-ts's shared evaluator (`queryContentEntries
|
|
4
|
-
*
|
|
3
|
+
* fields, run by core-ts's shared evaluator (`queryContentEntries`, in SQL while the collection's
|
|
4
|
+
* list values are ready), and `limit`/`cursor` paging: with `orderBy` the store pages, without it
|
|
5
|
+
* the list keeps its order (last updated first) and is paged here; without `limit` it is unpaged,
|
|
5
6
|
* as before. Problems are refused as `invalid_query` with their paths (`where/0/value`).
|
|
6
7
|
*/
|
|
7
8
|
import type { ContentEntry } from "@cloudhal/core-contracts";
|
package/dist/src/entry-list.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RFC-0042 §4 "API and MCP" for `list_entries`: `where` and `orderBy` over a collection's list
|
|
3
|
-
* fields, run by core-ts's shared evaluator (`queryContentEntries
|
|
4
|
-
*
|
|
3
|
+
* fields, run by core-ts's shared evaluator (`queryContentEntries`, in SQL while the collection's
|
|
4
|
+
* list values are ready), and `limit`/`cursor` paging: with `orderBy` the store pages, without it
|
|
5
|
+
* the list keeps its order (last updated first) and is paged here; without `limit` it is unpaged,
|
|
5
6
|
* as before. Problems are refused as `invalid_query` with their paths (`where/0/value`).
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
9
|
import { SiteSchema } from "@cloudhal/core-contracts";
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ENTRY_PAGE_LIMIT,
|
|
12
|
+
|
|
13
|
+
InvariantError,
|
|
14
|
+
queryContentEntries,
|
|
15
|
+
} from "@cloudhal/core-ts";
|
|
10
16
|
|
|
11
17
|
|
|
12
18
|
const DEFS = SiteSchema.$defs ;
|
|
@@ -79,20 +85,32 @@ export async function listEntries(
|
|
|
79
85
|
const orderBy = a.orderBy ;
|
|
80
86
|
const limit = a.limit ;
|
|
81
87
|
if (a.cursor !== undefined && limit === undefined) refuse("cursor", "a cursor needs limit");
|
|
88
|
+
// List fields belong to one collection; without it they would be silently ignored.
|
|
89
|
+
if (base.collection === undefined && (where !== undefined || orderBy !== undefined))
|
|
90
|
+
refuse("collection", "where and orderBy need the collection whose list fields they use");
|
|
82
91
|
const offset = a.cursor === undefined ? 0 : decodeCursor(a.cursor );
|
|
83
|
-
|
|
92
|
+
// Ordered by a field, the store pages (in SQL once the collection's list values are ready);
|
|
93
|
+
// otherwise the list keeps its last-updated order, sorted here.
|
|
94
|
+
const paged =
|
|
95
|
+
orderBy !== undefined &&
|
|
96
|
+
Number.isInteger(limit) &&
|
|
97
|
+
(limit ) >= 1 &&
|
|
98
|
+
(limit ) <= ENTRY_PAGE_LIMIT;
|
|
99
|
+
const result = await queryContentEntries(ctx.store, siteId, {
|
|
84
100
|
...base,
|
|
85
101
|
...(where ? { where } : {}),
|
|
86
102
|
...(orderBy ? { orderBy } : {}),
|
|
103
|
+
...(paged ? { limit, offset } : {}),
|
|
87
104
|
now: (ctx.now?.() ?? new Date()).getTime(),
|
|
88
105
|
});
|
|
89
|
-
const ordered = orderBy ? entries : entries.sort(byUpdated);
|
|
106
|
+
const ordered = orderBy ? result.entries : result.entries.sort(byUpdated);
|
|
90
107
|
if (limit === undefined) return { entries: ordered };
|
|
91
|
-
const page = ordered.slice(offset, offset + limit);
|
|
108
|
+
const page = paged ? ordered : ordered.slice(offset, offset + limit);
|
|
109
|
+
const total = paged ? result.total : ordered.length;
|
|
92
110
|
const next = offset + page.length;
|
|
93
111
|
return {
|
|
94
112
|
entries: page,
|
|
95
|
-
total
|
|
96
|
-
...(next <
|
|
113
|
+
total,
|
|
114
|
+
...(next < total ? { nextCursor: encodeCursor(next) } : {}),
|
|
97
115
|
};
|
|
98
116
|
}
|
package/dist/src/entry-tools.js
CHANGED
|
@@ -42,11 +42,13 @@ const listEntriesTool = {
|
|
|
42
42
|
name: "list_entries",
|
|
43
43
|
title: "List articles",
|
|
44
44
|
description:
|
|
45
|
-
'Content entries, newest first. `collection`
|
|
45
|
+
'Content entries, newest first. Without `collection` (or a "collection:" filter clause), entries of every collection; each entry carries its `collection`. `filter` selects by terms (RFC-0002 grammar): clauses joined by "+" (AND), "[a,b]" = either, "-" = none of, "primary:category:x" = primary term, "category:x>*" = x or a sub-category, "collection:posts"; values are term slugs (old slugs work) or ids. Example: "category:news+tag:[ai,llm]+-tag:sponsored". `where`/`orderBy` filter and sort by the collection\'s list fields (RFC-0042; list_collections → listFields), e.g. upcoming events: where [{"field":"startsAt","op":"gte","value":"now"}], orderBy {"field":"startsAt","direction":"asc"}; `limit` pages the answer (total, nextCursor → cursor).',
|
|
46
46
|
inputSchema: obj(
|
|
47
47
|
{
|
|
48
48
|
siteId: id,
|
|
49
|
-
collection: str("Collection slug
|
|
49
|
+
collection: str("Collection slug; leave out for every collection", {
|
|
50
|
+
pattern: SLUG_PATTERN,
|
|
51
|
+
}),
|
|
50
52
|
filter: str("Filter over term assignments, e.g. category:news+tag:ai", {
|
|
51
53
|
minLength: 1,
|
|
52
54
|
maxLength: 512,
|
|
@@ -81,9 +83,8 @@ const listEntriesTool = {
|
|
|
81
83
|
handler: async (a, ctx) => {
|
|
82
84
|
await requireSite(ctx, a.siteId );
|
|
83
85
|
const filter = a.filter ;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
(filter && /(^|\+)-?collection:/.test(filter) ? undefined : "posts");
|
|
86
|
+
// Every collection by default: a site whose articles live in `blog` saw none under `posts`.
|
|
87
|
+
const collection = a.collection ;
|
|
87
88
|
const query = {
|
|
88
89
|
...(collection !== undefined ? { collection } : {}),
|
|
89
90
|
...(filter !== undefined ? { filter } : {}),
|
package/dist/src/render/cdp.d.ts
CHANGED
package/dist/src/render/cdp.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** A minimal DevTools client over a browser-level socket (flat sessions), and base64 helpers. */
|
|
2
|
+
import { CSP_LISTENER } from "./checks/scripts.js";
|
|
2
3
|
import { RenderError, } from "./types.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -123,6 +124,8 @@ export async function cdpSession(
|
|
|
123
124
|
},
|
|
124
125
|
],
|
|
125
126
|
});
|
|
127
|
+
// Before the page's own scripts: keep the CSP violations it raises (`script-blocked`).
|
|
128
|
+
await s("Page.addScriptToEvaluateOnNewDocument", { source: CSP_LISTENER });
|
|
126
129
|
const loaded = cdp.waitFor("Page.loadEventFired", sessionId, options.loadTimeoutMs ?? 12_000);
|
|
127
130
|
const nav = await s("Page.navigate", { url });
|
|
128
131
|
if (typeof nav.errorText === "string" && nav.errorText)
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: carousel-label / -lcp / -focus / -autoplay, image-fit, overlay-open; ends at the top of the page.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const COMPONENT_CHECKS
|
|
5
|
+
export declare const COMPONENT_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: carousel-label / -lcp / -focus / -autoplay, image-fit, overlay-open; ends at the top of the page.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const COMPONENT_CHECKS = ` // A static preview runs no scripts (its CSP), so checks of what a module does wait for the site.
|
|
5
|
+
export const COMPONENT_CHECKS = String.raw` // A static preview runs no scripts (its CSP), so checks of what a module does wait for the site.
|
|
6
6
|
const staticPreview = !!document.querySelector('meta[name="generator"][content="Cloudhal preview"]');
|
|
7
7
|
// carousel-label and carousel-lcp: named carousels and slides; a hero's first slide not lazy.
|
|
8
8
|
for (const c of document.querySelectorAll('[aria-roledescription="carousel"], [aria-roledescription="kaydırmalı alan"]')) {
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: empty-section, tap-target, input-label, chart-empty, long-line.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const CONTENT_CHECKS
|
|
5
|
+
export declare const CONTENT_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: empty-section, tap-target, input-label, chart-empty, long-line.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const CONTENT_CHECKS = ` // empty-section
|
|
5
|
+
export const CONTENT_CHECKS = String.raw` // empty-section
|
|
6
6
|
for (const s of document.querySelectorAll("[data-section-id]")) {
|
|
7
7
|
if (getComputedStyle(s).display === "none") continue;
|
|
8
8
|
const text = (s.innerText || "").trim();
|
|
@@ -41,23 +41,60 @@ export const CONTENT_CHECKS = ` // empty-section
|
|
|
41
41
|
if (!visible(el) && !(el.type === "radio" || el.type === "checkbox")) continue;
|
|
42
42
|
const named = [...(el.labels || [])].some((l) => (l.innerText || l.textContent || "").trim()) ||
|
|
43
43
|
(el.getAttribute("aria-label") || "").trim() ||
|
|
44
|
-
(el.getAttribute("aria-labelledby") || "").split(
|
|
44
|
+
(el.getAttribute("aria-labelledby") || "").split(/\s+/).some((id) => id && (document.getElementById(id)?.textContent || "").trim());
|
|
45
45
|
if (!named) add("input-label", el, "no label a screen reader can announce");
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// chart-empty: a chart whose data has no rows.
|
|
49
49
|
for (const el of document.querySelectorAll("[data-ch-chart-empty]")) add("chart-empty", el, "no rows in its data");
|
|
50
50
|
|
|
51
|
-
// long-line:
|
|
51
|
+
// long-line: text columns whose full lines hold more than 90 characters on average. Counted on
|
|
52
|
+
// the rendered lines (each paragraph's last, partly filled one left out) and pooled over every
|
|
53
|
+
// paragraph of the same width and font, so paragraphs of one column get one verdict.
|
|
54
|
+
const range = document.createRange();
|
|
55
|
+
const columns = new Map();
|
|
56
|
+
let measured = 0;
|
|
52
57
|
for (const p of document.querySelectorAll("p,li,dd,blockquote")) {
|
|
53
|
-
if (!visible(p) || p.querySelector("p,li")) continue;
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
if (measured >= 80 || !visible(p) || p.querySelector("p,li")) continue;
|
|
59
|
+
if ((p.innerText || "").trim().length < 180) continue;
|
|
60
|
+
measured++;
|
|
61
|
+
// Characters by the line they are drawn on, in reading order: a character more than half a
|
|
62
|
+
// line below the current line starts the next (inline code in another size stays on its line).
|
|
63
|
+
// A run of spaces counts once, as it is shown.
|
|
56
64
|
const s = getComputedStyle(p);
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
65
|
+
const half = (s.lineHeight === "normal" ? parseFloat(s.fontSize) * 1.2 : parseFloat(s.lineHeight)) / 2;
|
|
66
|
+
const rows = [];
|
|
67
|
+
let top = -Infinity, seen = 0, space = true;
|
|
68
|
+
const tw = document.createTreeWalker(p, NodeFilter.SHOW_TEXT);
|
|
69
|
+
while (tw.nextNode() && seen < 800) {
|
|
70
|
+
const n = tw.currentNode;
|
|
71
|
+
for (let i = 0; i < n.length && seen < 800; i++) {
|
|
72
|
+
const blank = /\s/.test(n.data[i]);
|
|
73
|
+
if (blank && space) continue;
|
|
74
|
+
space = blank;
|
|
75
|
+
seen++;
|
|
76
|
+
range.setStart(n, i);
|
|
77
|
+
range.setEnd(n, i + 1);
|
|
78
|
+
const b = range.getClientRects()[0];
|
|
79
|
+
if (!b) continue;
|
|
80
|
+
if (b.top > top + half) { rows.push(0); top = b.top; }
|
|
81
|
+
rows[rows.length - 1]++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// The last line seen may be partly filled (the paragraph's end, or where counting stopped).
|
|
85
|
+
const full = rows.slice(0, -1);
|
|
86
|
+
if (full.length < 2) continue;
|
|
87
|
+
const width = Math.round(p.getBoundingClientRect().width);
|
|
88
|
+
const key = width + "|" + s.fontSize + "|" + s.fontFamily;
|
|
89
|
+
const col = columns.get(key) || { width, first: p, paragraphs: 0, lines: 0, chars: 0 };
|
|
90
|
+
col.paragraphs++;
|
|
91
|
+
col.lines += full.length;
|
|
92
|
+
col.chars += full.reduce((a, b) => a + b, 0);
|
|
93
|
+
columns.set(key, col);
|
|
94
|
+
}
|
|
95
|
+
for (const col of columns.values()) {
|
|
96
|
+
const per = Math.round(col.chars / col.lines);
|
|
97
|
+
if (per > 90)
|
|
98
|
+
add("long-line", col.first, "about " + per + " characters a line in this " + col.width + " px column" + (col.paragraphs > 1 ? " (" + col.paragraphs + " paragraphs)" : ""));
|
|
62
99
|
}
|
|
63
100
|
`;
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: contrast: text against what is painted beneath it, band by band.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const CONTRAST_CHECKS
|
|
5
|
+
export declare const CONTRAST_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: contrast: text against what is painted beneath it, band by band.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const CONTRAST_CHECKS = ` // contrast: text against what is painted beneath it (elementsFromPoint), band by band.
|
|
5
|
+
export const CONTRAST_CHECKS = String.raw` // contrast: text against what is painted beneath it (elementsFromPoint), band by band.
|
|
6
6
|
const canvas = document.createElement("canvas");
|
|
7
7
|
canvas.width = canvas.height = 1;
|
|
8
8
|
const g = canvas.getContext("2d", { willReadFrequently: true });
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: font-fallback.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const FONT_CHECKS
|
|
5
|
+
export declare const FONT_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: font-fallback.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const FONT_CHECKS = ` // font-fallback (RFC-0023 §2): text set in a web font whose stack has no metric-matched fallback
|
|
5
|
+
export const FONT_CHECKS = String.raw` // font-fallback (RFC-0023 §2): text set in a web font whose stack has no metric-matched fallback
|
|
6
6
|
// right after it (a face with size-adjust or ascent-override). Without one, the text is first
|
|
7
7
|
// drawn in a system font of another size and moves when the web font arrives.
|
|
8
8
|
if (document.fonts) {
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* prelude defines the helpers (`add`, `describe`, `visible`, `imgs`, `W`, `H`); the motion part
|
|
7
7
|
* scrolls the page once and defines `frame`, which the navigation and component parts use; the
|
|
8
8
|
* component part ends back at the top. Keep the order.
|
|
9
|
+
*
|
|
10
|
+
* Every part is a `String.raw` template, so a backslash in the page's code (`/\s/`) reaches the
|
|
11
|
+
* page as written: in a plain template `\s` arrives as `s` and `\b` as a control character, and
|
|
12
|
+
* Biome's useless-escape fix deleted the backslash (test/render-script.test.ts checks this).
|
|
9
13
|
*/
|
|
10
14
|
import { COMPONENT_CHECKS } from "./components.js";
|
|
11
15
|
import { CONTENT_CHECKS } from "./content.js";
|
|
@@ -15,6 +19,7 @@ import { LAYOUT_CHECKS } from "./layout.js";
|
|
|
15
19
|
import { MOTION_CHECKS } from "./motion.js";
|
|
16
20
|
import { NAVIGATION_CHECKS } from "./navigation.js";
|
|
17
21
|
import { PRELUDE } from "./prelude.js";
|
|
22
|
+
import { SCRIPT_CHECKS } from "./scripts.js";
|
|
18
23
|
|
|
19
24
|
export const RENDER_CHECK_SCRIPT = [
|
|
20
25
|
"(async () => {",
|
|
@@ -23,6 +28,7 @@ export const RENDER_CHECK_SCRIPT = [
|
|
|
23
28
|
CONTRAST_CHECKS,
|
|
24
29
|
CONTENT_CHECKS,
|
|
25
30
|
FONT_CHECKS,
|
|
31
|
+
SCRIPT_CHECKS,
|
|
26
32
|
MOTION_CHECKS,
|
|
27
33
|
NAVIGATION_CHECKS,
|
|
28
34
|
COMPONENT_CHECKS,
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: overflow-x, img-alt / img-broken, heading-order.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const LAYOUT_CHECKS
|
|
5
|
+
export declare const LAYOUT_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: overflow-x, img-alt / img-broken, heading-order.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const LAYOUT_CHECKS = ` // overflow-x: the outermost elements that stick out past the screen's right edge.
|
|
5
|
+
export const LAYOUT_CHECKS = String.raw` // overflow-x: the outermost elements that stick out past the screen's right edge.
|
|
6
6
|
const sw = document.documentElement.scrollWidth;
|
|
7
7
|
if (sw > W + 1) {
|
|
8
8
|
const clipped = (el) => {
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: The reader's scroll pass, then motion-cls, reduced-motion, motion-budget, flash; defines `frame`.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const MOTION_CHECKS
|
|
5
|
+
export declare const MOTION_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: The reader's scroll pass, then motion-cls, reduced-motion, motion-budget, flash; defines `frame`.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const MOTION_CHECKS = ` // RFC-0024 §8: scroll through the page once, as a reader would, so reveals play, then measure.
|
|
5
|
+
export const MOTION_CHECKS = String.raw` // RFC-0024 §8: scroll through the page once, as a reader would, so reveals play, then measure.
|
|
6
6
|
let shift = 0;
|
|
7
7
|
let po;
|
|
8
8
|
try {
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: skip-link, landmarks, header-contrast, focus-obscured.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export declare const NAVIGATION_CHECKS
|
|
5
|
+
export declare const NAVIGATION_CHECKS: string;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* In-page checks, part of `RENDER_CHECK_SCRIPT`: skip-link, landmarks, header-contrast, focus-obscured.
|
|
3
3
|
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
4
|
*/
|
|
5
|
-
export const NAVIGATION_CHECKS = ` // skip-link: the first focusable element is a link to the main content (or inside it).
|
|
5
|
+
export const NAVIGATION_CHECKS = String.raw` // skip-link: the first focusable element is a link to the main content (or inside it).
|
|
6
6
|
const shown = (e) => e.getClientRects().length > 0 && getComputedStyle(e).visibility !== "hidden";
|
|
7
7
|
const focusables = [...document.querySelectorAll('a[href],button,input,select,textarea,summary,[tabindex]:not([tabindex="-1"])')]
|
|
8
8
|
.filter((e) => !e.disabled && !e.closest("[inert],dialog:not([open]),[popover]:not(:popover-open)") && shown(e));
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { RENDER_CHECK_IDS } from "../types.js";
|
|
6
6
|
|
|
7
|
-
export const PRELUDE = ` const W = document.documentElement.clientWidth || window.innerWidth, H = window.innerHeight, MAX = 5;
|
|
7
|
+
export const PRELUDE = String.raw` const W = document.documentElement.clientWidth || window.innerWidth, H = window.innerHeight, MAX = 5;
|
|
8
8
|
const ids = ${JSON.stringify(RENDER_CHECK_IDS)};
|
|
9
9
|
const out = Object.fromEntries(ids.map((id) => [id, { id, count: 0, examples: [] }]));
|
|
10
10
|
const clip = (s, n) => (s.length > n ? s.slice(0, n - 1) + "…" : s);
|
|
@@ -22,9 +22,9 @@ export const PRELUDE = ` const W = document.documentElement.clientWidth || wind
|
|
|
22
22
|
let tag = el.tagName.toLowerCase();
|
|
23
23
|
if (el.id) tag += "#" + el.id;
|
|
24
24
|
else if (typeof el.className === "string" && el.className.trim())
|
|
25
|
-
tag += "." + el.className.trim().split(
|
|
25
|
+
tag += "." + el.className.trim().split(/\s+/).slice(0, 2).join(".");
|
|
26
26
|
parts.push(tag);
|
|
27
|
-
const text = ((el.innerText || "").trim() || el.getAttribute("alt") || el.getAttribute("src") || "").replace(
|
|
27
|
+
const text = ((el.innerText || "").trim() || el.getAttribute("alt") || el.getAttribute("src") || "").replace(/\s+/g, " ");
|
|
28
28
|
if (text) parts.push(JSON.stringify(clip(text, 48)));
|
|
29
29
|
return parts.join(" ");
|
|
30
30
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-page checks, part of `RENDER_CHECK_SCRIPT`: surface-broken, script-blocked.
|
|
3
|
+
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Runs in the page before any of its own scripts (`Page.addScriptToEvaluateOnNewDocument`):
|
|
7
|
+
* keeps the Content-Security-Policy violations the page raises while it loads, which the
|
|
8
|
+
* `script-blocked` check reads. Report-only ones (`cloudhal dev`) are kept too.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CSP_LISTENER: string;
|
|
11
|
+
export declare const SCRIPT_CHECKS: string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-page checks, part of `RENDER_CHECK_SCRIPT`: surface-broken, script-blocked.
|
|
3
|
+
* Plain source text, run inside the page; it shares the script's locals (see ./index.ts).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Runs in the page before any of its own scripts (`Page.addScriptToEvaluateOnNewDocument`):
|
|
8
|
+
* keeps the Content-Security-Policy violations the page raises while it loads, which the
|
|
9
|
+
* `script-blocked` check reads. Report-only ones (`cloudhal dev`) are kept too.
|
|
10
|
+
*/
|
|
11
|
+
export const CSP_LISTENER = String.raw`(() => {
|
|
12
|
+
const seen = (window.__chCsp = []);
|
|
13
|
+
window.addEventListener("securitypolicyviolation", (e) => {
|
|
14
|
+
if (seen.length < 50)
|
|
15
|
+
seen.push({ directive: e.effectiveDirective || e.violatedDirective || "", blocked: e.blockedURI || "", sample: e.sample || "", line: e.lineNumber || 0, report: e.disposition === "report", el: e.target instanceof Element ? e.target : null });
|
|
16
|
+
}, true);
|
|
17
|
+
})();`;
|
|
18
|
+
|
|
19
|
+
export const SCRIPT_CHECKS = String.raw` // surface-broken: a body surface the preview could not draw (RFC-0020 §5), or a component in one
|
|
20
|
+
// with an unknown block type or props that do not fit it. Theme blocks the preview leaves to the
|
|
21
|
+
// site are fine.
|
|
22
|
+
for (const el of document.querySelectorAll(".ch-surface-problem")) {
|
|
23
|
+
const why = [...el.querySelectorAll("li")].map((li) => (li.textContent || "").trim()).filter(Boolean);
|
|
24
|
+
add("surface-broken", el, why.length ? why.slice(0, 3).join("; ") : "this interactive block cannot be shown");
|
|
25
|
+
}
|
|
26
|
+
for (const el of document.querySelectorAll(".ch-block--missing")) {
|
|
27
|
+
const text = (el.textContent || "").trim();
|
|
28
|
+
if (!/shown by the theme on the site$/.test(text)) add("surface-broken", el, text);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// script-blocked: scripts the page's Content-Security-Policy refused (the Site Worker sends
|
|
32
|
+
// script-src 'self', so an inline <script> never runs there). A static preview runs none on
|
|
33
|
+
// purpose (its own CSP), so it is not asked.
|
|
34
|
+
const runsScripts = !document.querySelector('meta[name="generator"][content="Cloudhal preview"]');
|
|
35
|
+
for (const v of runsScripts ? window.__chCsp || [] : []) {
|
|
36
|
+
if (!/^(script-src|script-src-elem|script-src-attr|worker-src)$/.test(v.directive)) continue;
|
|
37
|
+
const inline = v.blocked === "inline" || v.blocked === "eval" || !v.blocked;
|
|
38
|
+
const what = inline
|
|
39
|
+
? (v.blocked === "eval" ? "eval" : "an inline script") + (v.sample ? " " + JSON.stringify(clip(v.sample.trim(), 40)) : "") + (v.line ? " at line " + v.line : "")
|
|
40
|
+
: "the script " + v.blocked;
|
|
41
|
+
const fix = inline ? "; ship it as a file (a .js under /_astro or public/)" : "";
|
|
42
|
+
const el = v.el && v.el.isConnected ? v.el : document.body;
|
|
43
|
+
add("script-blocked", el, what + (v.report ? " would be blocked on the site" : " was blocked") + " by " + v.directive + fix);
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
@@ -41,7 +41,7 @@ export interface RenderCheck {
|
|
|
41
41
|
/** The widths it failed at. */
|
|
42
42
|
widths: number[];
|
|
43
43
|
}
|
|
44
|
-
export declare const RENDER_CHECK_IDS: readonly ["overflow-x", "img-alt", "img-broken", "heading-order", "contrast", "empty-section", "tap-target", "long-line", "input-label", "chart-empty", "reduced-motion", "motion-cls", "motion-budget", "flash", "skip-link", "landmarks", "header-contrast", "focus-obscured", "overlay-open", "carousel-label", "carousel-lcp", "carousel-focus", "carousel-autoplay", "image-fit", "font-fallback"];
|
|
44
|
+
export declare const RENDER_CHECK_IDS: readonly ["overflow-x", "img-alt", "img-broken", "heading-order", "contrast", "empty-section", "tap-target", "long-line", "input-label", "chart-empty", "reduced-motion", "motion-cls", "motion-budget", "flash", "skip-link", "landmarks", "header-contrast", "focus-obscured", "overlay-open", "carousel-label", "carousel-lcp", "carousel-focus", "carousel-autoplay", "image-fit", "font-fallback", "surface-broken", "script-blocked"];
|
|
45
45
|
export type RenderCheckId = (typeof RENDER_CHECK_IDS)[number];
|
|
46
46
|
export interface RenderShot {
|
|
47
47
|
width: number;
|
package/dist/src/render/types.js
CHANGED
|
@@ -89,6 +89,10 @@ export const RENDER_CHECK_IDS = [
|
|
|
89
89
|
"image-fit",
|
|
90
90
|
// RFC-0023 §2: a web font with no metric-matched fallback, so its text moves when it loads.
|
|
91
91
|
"font-fallback",
|
|
92
|
+
// RFC-0020 §5: a body surface the page could not draw (an unknown component, props that do not fit).
|
|
93
|
+
"surface-broken",
|
|
94
|
+
// A script the page's Content-Security-Policy refused (the Site Worker's is script-src 'self').
|
|
95
|
+
"script-blocked",
|
|
92
96
|
] ;
|
|
93
97
|
|
|
94
98
|
|
package/dist/src/render-tools.js
CHANGED
|
@@ -73,6 +73,8 @@ const WHAT = {
|
|
|
73
73
|
"carousel-autoplay": "carousel autoplay",
|
|
74
74
|
"image-fit": "image crops",
|
|
75
75
|
"font-fallback": "font swap shift",
|
|
76
|
+
"surface-broken": "interactive blocks that cannot be shown",
|
|
77
|
+
"script-blocked": "scripts blocked by the CSP",
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
function summary(r ) {
|
|
@@ -130,7 +132,7 @@ export function renderTools(previewDoc ) {
|
|
|
130
132
|
name: "render_page",
|
|
131
133
|
title: "Render a page in a browser",
|
|
132
134
|
description:
|
|
133
|
-
"Look at a page's draft as people will see it: renders it in a real browser at desktop (1440), tablet (768) and phone (390) widths and returns screenshots plus automatic checks (sideways scrolling, alt text, broken images, heading order, text contrast, empty sections, tap targets, line length, motion under reduced motion, layout shift) that name the section and component behind each problem. Use it after building or changing a page and before asking a person to publish; fix what it finds and render again. Read-only. Rate-limited (about 10 a minute); when no browser is available, use preview_page.",
|
|
135
|
+
"Look at a page's draft as people will see it: renders it in a real browser at desktop (1440), tablet (768) and phone (390) widths and returns screenshots plus automatic checks (sideways scrolling, alt text, broken images, heading order, text contrast, empty sections, tap targets, line length, motion under reduced motion, layout shift, interactive blocks that cannot be shown, scripts the site's Content-Security-Policy blocks) that name the section and component behind each problem. Use it after building or changing a page and before asking a person to publish; fix what it finds and render again. Read-only. Rate-limited (about 10 a minute); when no browser is available, use preview_page.",
|
|
134
136
|
inputSchema: obj(
|
|
135
137
|
{
|
|
136
138
|
siteId: id,
|
package/dist/src/render.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sight for agents (RFC-0021 §4): renders a page in a real browser at a few widths and returns
|
|
3
3
|
* screenshots plus automatic checks (overflow, alt text, broken images, heading order, contrast,
|
|
4
|
-
* empty sections, tap targets, line length). The browser is a
|
|
5
|
-
* Node (`@cloudhal/cli`), Cloudflare Browser Rendering on
|
|
6
|
-
* small DevTools client serves both, so there is no browser
|
|
4
|
+
* empty sections, tap targets, line length, broken surfaces, blocked scripts, …). The browser is a
|
|
5
|
+
* DevTools socket: local Chrome under Node (`@cloudhal/cli`), Cloudflare Browser Rendering on
|
|
6
|
+
* Workers (`@cloudhal/cloudflare`). One small DevTools client serves both, so there is no browser
|
|
7
|
+
* library to bundle.
|
|
7
8
|
*
|
|
8
9
|
* Worker-safe: no Node imports.
|
|
9
10
|
*/
|
package/dist/src/render.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sight for agents (RFC-0021 §4): renders a page in a real browser at a few widths and returns
|
|
3
3
|
* screenshots plus automatic checks (overflow, alt text, broken images, heading order, contrast,
|
|
4
|
-
* empty sections, tap targets, line length). The browser is a
|
|
5
|
-
* Node (`@cloudhal/cli`), Cloudflare Browser Rendering on
|
|
6
|
-
* small DevTools client serves both, so there is no browser
|
|
4
|
+
* empty sections, tap targets, line length, broken surfaces, blocked scripts, …). The browser is a
|
|
5
|
+
* DevTools socket: local Chrome under Node (`@cloudhal/cli`), Cloudflare Browser Rendering on
|
|
6
|
+
* Workers (`@cloudhal/cloudflare`). One small DevTools client serves both, so there is no browser
|
|
7
|
+
* library to bundle.
|
|
7
8
|
*
|
|
8
9
|
* Worker-safe: no Node imports.
|
|
9
10
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/mcp-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Cloudhal MCP server: semantic site tools (pages, articles, snapshots, preview, publish) governed by the policy engine",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://cloudhal.dev",
|
|
@@ -56,24 +56,24 @@
|
|
|
56
56
|
"README.md"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@cloudhal/analytics": "0.6.
|
|
60
|
-
"@cloudhal/agent-runtime": "0.6.
|
|
61
|
-
"@cloudhal/astro-renderer": "0.6.
|
|
62
|
-
"@cloudhal/comments": "0.6.
|
|
63
|
-
"@cloudhal/core-contracts": "0.6.
|
|
64
|
-
"@cloudhal/core-ts": "0.6.
|
|
65
|
-
"@cloudhal/storage": "0.6.
|
|
59
|
+
"@cloudhal/analytics": "0.6.2",
|
|
60
|
+
"@cloudhal/agent-runtime": "0.6.2",
|
|
61
|
+
"@cloudhal/astro-renderer": "0.6.2",
|
|
62
|
+
"@cloudhal/comments": "0.6.2",
|
|
63
|
+
"@cloudhal/core-contracts": "0.6.2",
|
|
64
|
+
"@cloudhal/core-ts": "0.6.2",
|
|
65
|
+
"@cloudhal/storage": "0.6.2",
|
|
66
66
|
"@modelcontextprotocol/server": "2.3.1",
|
|
67
|
-
"@cloudhal/schedules": "0.6.
|
|
67
|
+
"@cloudhal/schedules": "0.6.2"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@cloudflare/workers-types": "^5.20261007.1",
|
|
71
71
|
"@modelcontextprotocol/client": "2.3.1",
|
|
72
72
|
"@types/node": "^26.6.5",
|
|
73
73
|
"better-sqlite3": "13.0.3",
|
|
74
|
-
"happy-dom": "^21.0.
|
|
74
|
+
"happy-dom": "^21.0.4",
|
|
75
75
|
"typescript": "7.0.2",
|
|
76
|
-
"vitest": "5.0.
|
|
76
|
+
"vitest": "5.0.5"
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|
|
79
79
|
"node": ">=24"
|