@cloudhal/mcp-server 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/src/collection-fields.d.ts +2 -0
- package/dist/src/collection-fields.js +1 -1
- package/dist/src/collection-listings.d.ts +48 -0
- package/dist/src/collection-listings.js +280 -0
- package/dist/src/collection-tools.js +34 -12
- package/dist/src/entry-fields.js +12 -57
- package/dist/src/entry-list.d.ts +17 -0
- package/dist/src/entry-list.js +101 -0
- package/dist/src/entry-tools.js +17 -10
- package/dist/src/field-hints.d.ts +2 -1
- package/dist/src/field-hints.js +18 -1
- package/dist/src/page-tools.js +7 -0
- package/dist/src/release-risk.d.ts +22 -0
- package/dist/src/release-risk.js +95 -0
- package/dist/src/render/cdp.d.ts +0 -1
- package/dist/src/render/cdp.js +3 -0
- package/dist/src/render/checks/content.d.ts +1 -1
- package/dist/src/render/checks/content.js +46 -9
- package/dist/src/render/checks/index.js +2 -0
- 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/dist/src/schedules.d.ts +2 -5
- package/dist/src/schedules.js +5 -38
- package/dist/src/section-queries.d.ts +10 -0
- package/dist/src/section-queries.js +52 -0
- package/dist/src/server-instructions.js +3 -1
- package/dist/src/structured-data-tools.d.ts +8 -0
- package/dist/src/structured-data-tools.js +111 -0
- package/dist/src/tools.js +15 -4
- package/dist/src/translation-fields.d.ts +32 -0
- package/dist/src/translation-fields.js +68 -0
- package/dist/src/translation-tools.js +56 -6
- package/package.json +9 -9
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
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`), and `limit`/`cursor` paging.
|
|
4
|
+
* Without `orderBy` the list keeps its order (last updated first); without `limit` it is unpaged,
|
|
5
|
+
* as before. Problems are refused as `invalid_query` with their paths (`where/0/value`).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SiteSchema } from "@cloudhal/core-contracts";
|
|
9
|
+
import { InvariantError, queryContentEntries } from "@cloudhal/core-ts";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const DEFS = SiteSchema.$defs ;
|
|
13
|
+
|
|
14
|
+
export const ENTRY_QUERY_INPUT = {
|
|
15
|
+
where: {
|
|
16
|
+
type: "array",
|
|
17
|
+
minItems: 1,
|
|
18
|
+
maxItems: 4,
|
|
19
|
+
items: { $ref: "#/$defs/FieldCondition" },
|
|
20
|
+
description:
|
|
21
|
+
'Conditions on the collection\'s list fields (list_collections → listFields, with each field\'s ops), ANDed, e.g. [{"field":"startsAt","op":"gte","value":"now"},{"field":"format","op":"in","values":["talk"]}]. Values are strings read by the field\'s type: a number, YYYY-MM-DD, an RFC 3339 instant, true/false, an option value, or now',
|
|
22
|
+
$defs: { FieldCondition: DEFS.FieldCondition },
|
|
23
|
+
},
|
|
24
|
+
orderBy: {
|
|
25
|
+
$ref: "#/$defs/FieldOrder",
|
|
26
|
+
description:
|
|
27
|
+
'Order by a number, date or datetime list field, e.g. {"field":"startsAt","direction":"asc"}; entries without a value come last',
|
|
28
|
+
$defs: { FieldOrder: DEFS.FieldOrder },
|
|
29
|
+
},
|
|
30
|
+
limit: {
|
|
31
|
+
type: "integer",
|
|
32
|
+
minimum: 1,
|
|
33
|
+
maximum: 100,
|
|
34
|
+
description: "Page size; the answer then has total and, when more follow, nextCursor",
|
|
35
|
+
},
|
|
36
|
+
cursor: {
|
|
37
|
+
type: "string",
|
|
38
|
+
minLength: 1,
|
|
39
|
+
maxLength: 32,
|
|
40
|
+
description: "nextCursor from the previous page (same arguments otherwise)",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const refuse = (path , message ) => {
|
|
45
|
+
throw new InvariantError("invalid_query", `${path}: ${message}`, {
|
|
46
|
+
issues: [{ path, code: "invalid_query", message }],
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** An opaque cursor: the offset of the next page (the API's form). */
|
|
51
|
+
const encodeCursor = (offset ) => btoa(`o:${offset}`).replace(/=+$/, "");
|
|
52
|
+
function decodeCursor(raw ) {
|
|
53
|
+
let text = "";
|
|
54
|
+
try {
|
|
55
|
+
text = atob(raw);
|
|
56
|
+
} catch {
|
|
57
|
+
// refused below
|
|
58
|
+
}
|
|
59
|
+
const m = /^o:(\d{1,9})$/.exec(text);
|
|
60
|
+
return m ? Number(m[1]) : refuse("cursor", "not a cursor this list returned");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const byUpdated = (x , y ) => y.updatedAt.localeCompare(x.updatedAt);
|
|
70
|
+
|
|
71
|
+
/** The entries of `base` matching the call's field query, ordered and paged. */
|
|
72
|
+
export async function listEntries(
|
|
73
|
+
ctx ,
|
|
74
|
+
siteId ,
|
|
75
|
+
base ,
|
|
76
|
+
a ,
|
|
77
|
+
) {
|
|
78
|
+
const where = a.where ;
|
|
79
|
+
const orderBy = a.orderBy ;
|
|
80
|
+
const limit = a.limit ;
|
|
81
|
+
if (a.cursor !== undefined && limit === undefined) refuse("cursor", "a cursor needs limit");
|
|
82
|
+
// List fields belong to one collection; without it they would be silently ignored.
|
|
83
|
+
if (base.collection === undefined && (where !== undefined || orderBy !== undefined))
|
|
84
|
+
refuse("collection", "where and orderBy need the collection whose list fields they use");
|
|
85
|
+
const offset = a.cursor === undefined ? 0 : decodeCursor(a.cursor );
|
|
86
|
+
const { entries } = await queryContentEntries(ctx.store, siteId, {
|
|
87
|
+
...base,
|
|
88
|
+
...(where ? { where } : {}),
|
|
89
|
+
...(orderBy ? { orderBy } : {}),
|
|
90
|
+
now: (ctx.now?.() ?? new Date()).getTime(),
|
|
91
|
+
});
|
|
92
|
+
const ordered = orderBy ? entries : entries.sort(byUpdated);
|
|
93
|
+
if (limit === undefined) return { entries: ordered };
|
|
94
|
+
const page = ordered.slice(offset, offset + limit);
|
|
95
|
+
const next = offset + page.length;
|
|
96
|
+
return {
|
|
97
|
+
entries: page,
|
|
98
|
+
total: ordered.length,
|
|
99
|
+
...(next < ordered.length ? { nextCursor: encodeCursor(next) } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
package/dist/src/entry-tools.js
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
FIELDS_PATCH,
|
|
34
34
|
mergeFields,
|
|
35
35
|
} from "./entry-fields.js";
|
|
36
|
+
import { ENTRY_QUERY_INPUT, listEntries } from "./entry-list.js";
|
|
36
37
|
import { entryTerms, reportDeltas } from "./entry-terms.js";
|
|
37
38
|
import { menuHint, menuItemsHiddenBy } from "./menu-tools.js";
|
|
38
39
|
import { assignmentDeltas, describeDeltas, TAGS_INPUT, TERMS_INPUT, termLookup } from "./terms.js";
|
|
@@ -41,11 +42,13 @@ const listEntriesTool = {
|
|
|
41
42
|
name: "list_entries",
|
|
42
43
|
title: "List articles",
|
|
43
44
|
description:
|
|
44
|
-
'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).',
|
|
45
46
|
inputSchema: obj(
|
|
46
47
|
{
|
|
47
48
|
siteId: id,
|
|
48
|
-
collection: str("Collection slug
|
|
49
|
+
collection: str("Collection slug; leave out for every collection", {
|
|
50
|
+
pattern: SLUG_PATTERN,
|
|
51
|
+
}),
|
|
49
52
|
filter: str("Filter over term assignments, e.g. category:news+tag:ai", {
|
|
50
53
|
minLength: 1,
|
|
51
54
|
maxLength: 512,
|
|
@@ -58,10 +61,18 @@ const listEntriesTool = {
|
|
|
58
61
|
minItems: 1,
|
|
59
62
|
uniqueItems: true,
|
|
60
63
|
},
|
|
64
|
+
...ENTRY_QUERY_INPUT,
|
|
61
65
|
},
|
|
62
66
|
["siteId"],
|
|
63
67
|
),
|
|
64
|
-
outputSchema: obj(
|
|
68
|
+
outputSchema: obj(
|
|
69
|
+
{
|
|
70
|
+
entries: { type: "array", items: ENTRY },
|
|
71
|
+
total: { type: "integer" },
|
|
72
|
+
nextCursor: { type: "string" },
|
|
73
|
+
},
|
|
74
|
+
["entries"],
|
|
75
|
+
),
|
|
65
76
|
annotations: {
|
|
66
77
|
readOnlyHint: true,
|
|
67
78
|
destructiveHint: false,
|
|
@@ -72,9 +83,8 @@ const listEntriesTool = {
|
|
|
72
83
|
handler: async (a, ctx) => {
|
|
73
84
|
await requireSite(ctx, a.siteId );
|
|
74
85
|
const filter = a.filter ;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
(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 ;
|
|
78
88
|
const query = {
|
|
79
89
|
...(collection !== undefined ? { collection } : {}),
|
|
80
90
|
...(filter !== undefined ? { filter } : {}),
|
|
@@ -82,10 +92,7 @@ const listEntriesTool = {
|
|
|
82
92
|
...(a.status !== undefined ? { status: a.status } : {}),
|
|
83
93
|
};
|
|
84
94
|
try {
|
|
85
|
-
|
|
86
|
-
y.updatedAt.localeCompare(x.updatedAt),
|
|
87
|
-
);
|
|
88
|
-
return { entries };
|
|
95
|
+
return await listEntries(ctx, a.siteId , query, a);
|
|
89
96
|
} catch (e) {
|
|
90
97
|
mapError(e);
|
|
91
98
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RFC-0041: what an agent does next after a typed-field
|
|
2
|
+
* RFC-0041 and RFC-0042: what an agent does next after a typed-field, listing, expiry or
|
|
3
|
+
* structured-data refusal. Every refusal keeps its issues in
|
|
3
4
|
* `details.issues`, each at its slash path (`fields/startsAt/at`), so the hint only names the tool.
|
|
4
5
|
*/
|
|
5
6
|
import type { InvariantCode } from "@cloudhal/core-ts";
|
package/dist/src/field-hints.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RFC-0041: what an agent does next after a typed-field
|
|
2
|
+
* RFC-0041 and RFC-0042: what an agent does next after a typed-field, listing, expiry or
|
|
3
|
+
* structured-data refusal. Every refusal keeps its issues in
|
|
3
4
|
* `details.issues`, each at its slash path (`fields/startsAt/at`), so the hint only names the tool.
|
|
4
5
|
*/
|
|
5
6
|
|
|
@@ -29,10 +30,26 @@ const HINTS = {
|
|
|
29
30
|
'details.report.samples shows the values; change them first (update_entry), or call again with onInvalid: "clear" to drop them (the person approving sees how many)',
|
|
30
31
|
field_operation_incomplete:
|
|
31
32
|
"call the operation tool again with its operationId to finish it (a new approval), or ask a person to continue it in Studio",
|
|
33
|
+
// RFC-0042 (listings, expiry, structured data)
|
|
34
|
+
invalid_query:
|
|
35
|
+
"fix the conditions at the paths in details.issues: only the collection's listFields may be queried, with the operators list_collections shows per field (listFields[].ops); dates are YYYY-MM-DD, instants RFC 3339, or now",
|
|
36
|
+
structured_data_invalid:
|
|
37
|
+
"fix the mappings at the paths in details.issues: list_collections shows a preset's paths, which are required and the sources each takes (structuredData.paths); field sources need a field of a fitting type, and required values come from the entry, never a constant",
|
|
38
|
+
invalid_expiry:
|
|
39
|
+
"expiry.field must be a date or datetime field of the collection (list_collections → fields)",
|
|
40
|
+
list_field_in_use:
|
|
41
|
+
"contentList sections on the pages in details.pages still filter or sort by that field: change their where/orderBy first (update_page), then try again",
|
|
32
42
|
};
|
|
33
43
|
|
|
44
|
+
const GATES_EXPIRY =
|
|
45
|
+
"a collection expiry needs a site Worker that enforces derived gates: ask a person to deploy the current site (cloudhal deploy), then try again; until then leave expiry out (the rest of the change can go ahead without it)";
|
|
46
|
+
const GATES_AVAILABILITY =
|
|
47
|
+
"the site's renderer has not confirmed it enforces time gates: ask a person to deploy the current site (cloudhal deploy) before setting embargoes or expiries";
|
|
48
|
+
|
|
34
49
|
/** The next step for a field refusal; undefined for codes that are not about fields. */
|
|
35
50
|
export function fieldHint(code , details ) {
|
|
51
|
+
if (code === "gates_unsupported")
|
|
52
|
+
return Array.isArray(details.collections) ? GATES_EXPIRY : GATES_AVAILABILITY;
|
|
36
53
|
if (code === "too_large" && Array.isArray(details.issues))
|
|
37
54
|
return "field values are at most 256 KB per entry and collection settings 256 KB per site; shorten or drop values";
|
|
38
55
|
return HINTS[code];
|
package/dist/src/page-tools.js
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
unknownBlocksOf,
|
|
27
27
|
} from "./content-shared.js";
|
|
28
28
|
import { menuHint, menuItemsHiddenBy } from "./menu-tools.js";
|
|
29
|
+
import { checkSectionQueries } from "./section-queries.js";
|
|
29
30
|
|
|
30
31
|
const listSitesTool = {
|
|
31
32
|
name: "list_sites",
|
|
@@ -141,6 +142,7 @@ const createPageTool = {
|
|
|
141
142
|
openWorldHint: false,
|
|
142
143
|
},
|
|
143
144
|
scopes: ["content:write"],
|
|
145
|
+
precheck: (a, ctx) => checkSectionQueries(ctx, a.siteId , a.sections),
|
|
144
146
|
handler: async (a, ctx) => {
|
|
145
147
|
assertNoHtmlSections(a.sections);
|
|
146
148
|
const site = await requireSite(ctx, a.siteId );
|
|
@@ -216,6 +218,11 @@ const updatePageTool = {
|
|
|
216
218
|
openWorldHint: false,
|
|
217
219
|
},
|
|
218
220
|
scopes: ["content:write"],
|
|
221
|
+
precheck: async (a, ctx) => {
|
|
222
|
+
const page = await ctx.store.getPage(a.pageId );
|
|
223
|
+
if (!page || page.siteId !== a.siteId) return;
|
|
224
|
+
await checkSectionQueries(ctx, page.siteId, a.sections, page.sections);
|
|
225
|
+
},
|
|
219
226
|
handler: async (a, ctx) => {
|
|
220
227
|
assertNoHtmlSections(a.sections);
|
|
221
228
|
const page = await ctx.store.getPage(a.pageId );
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The items of a release as the `auto`-mode low-risk check sees them (RFC-0008 §10.3): what each
|
|
3
|
+
* item does, the assets riding with articles, corrections (RFC-0019 §2.4) and derived gates added
|
|
4
|
+
* or moved earlier on live articles (RFC-0042 §3.5, classed like `schedule_unpublish`).
|
|
5
|
+
*/
|
|
6
|
+
import type { ReleaseItemRisk } from "@cloudhal/agent-runtime";
|
|
7
|
+
import { type SiteGraphStore } from "@cloudhal/core-ts";
|
|
8
|
+
import type { StoredReleaseItem } from "@cloudhal/schedules";
|
|
9
|
+
type Items = readonly Pick<StoredReleaseItem, "item" | "deps">[];
|
|
10
|
+
/** The items as the low-risk check sees them (§10.3). */
|
|
11
|
+
export declare function releaseRisk(items: Items, corrects?: ReadonlySet<string>, expires?: ReadonlySet<string>): ReleaseItemRisk[];
|
|
12
|
+
/** RFC-0019 §2.4: the release's articles whose target adds a correction to the live version. */
|
|
13
|
+
export declare function releaseCorrections(graph: SiteGraphStore, items: readonly Pick<StoredReleaseItem, "item">[]): Promise<Set<string>>;
|
|
14
|
+
/**
|
|
15
|
+
* RFC-0042 §3.5: the release's live articles whose target adds a derived gate or moves it
|
|
16
|
+
* earlier, under the site's current rules (a release that changes the rules changes the site,
|
|
17
|
+
* which is never low risk anyway).
|
|
18
|
+
*/
|
|
19
|
+
export declare function releaseExpiries(graph: SiteGraphStore, items: readonly Pick<StoredReleaseItem, "item">[]): Promise<Set<string>>;
|
|
20
|
+
/** Every fact the low-risk check of a release needs, read from the graph. */
|
|
21
|
+
export declare function releaseRiskFor(graph: SiteGraphStore, items: Items): Promise<ReleaseItemRisk[]>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The items of a release as the `auto`-mode low-risk check sees them (RFC-0008 §10.3): what each
|
|
3
|
+
* item does, the assets riding with articles, corrections (RFC-0019 §2.4) and derived gates added
|
|
4
|
+
* or moved earlier on live articles (RFC-0042 §3.5, classed like `schedule_unpublish`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { addedCorrections, advancesDerivedGate, } from "@cloudhal/core-ts";
|
|
9
|
+
import { hasExpiryRules } from "@cloudhal/core-ts/fields";
|
|
10
|
+
|
|
11
|
+
import { nodeVersion } from "./schedules.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/** The items as the low-risk check sees them (§10.3). */
|
|
16
|
+
export function releaseRisk(
|
|
17
|
+
items ,
|
|
18
|
+
corrects = new Set(),
|
|
19
|
+
expires = new Set(),
|
|
20
|
+
) {
|
|
21
|
+
return items.map(
|
|
22
|
+
(p) => ({
|
|
23
|
+
kind: p.item.kind,
|
|
24
|
+
nodeId: p.item.nodeId,
|
|
25
|
+
nodeKind: p.item.nodeKind,
|
|
26
|
+
live: p.item.base !== undefined,
|
|
27
|
+
deps: p.deps,
|
|
28
|
+
...(corrects.has(p.item.nodeId) ? { corrects: true } : {}),
|
|
29
|
+
...(expires.has(p.item.nodeId) ? { expires: true } : {}),
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A live article item's two versions: the one live now and the one the release publishes. */
|
|
35
|
+
async function versions(graph , item ) {
|
|
36
|
+
if (item.kind !== "set" || item.nodeKind !== "contentEntry" || !item.base) return undefined;
|
|
37
|
+
const ref = { id: item.nodeId, kind: item.nodeKind };
|
|
38
|
+
const after = await nodeVersion (graph, { ...ref, ...item.target });
|
|
39
|
+
const before = await nodeVersion (graph, { ...ref, ...item.base });
|
|
40
|
+
return after && before ? { before, after } : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** RFC-0019 §2.4: the release's articles whose target adds a correction to the live version. */
|
|
44
|
+
export async function releaseCorrections(
|
|
45
|
+
graph ,
|
|
46
|
+
items ,
|
|
47
|
+
) {
|
|
48
|
+
const out = new Set ();
|
|
49
|
+
for (const { item } of items) {
|
|
50
|
+
if (item.kind !== "set" || item.nodeKind !== "contentEntry") continue;
|
|
51
|
+
const ref = { id: item.nodeId, kind: item.nodeKind };
|
|
52
|
+
const after = await nodeVersion (graph, { ...ref, ...item.target });
|
|
53
|
+
if (!after?.corrections?.length) continue;
|
|
54
|
+
const before = item.base
|
|
55
|
+
? await nodeVersion (graph, { ...ref, ...item.base })
|
|
56
|
+
: undefined;
|
|
57
|
+
if (addedCorrections(before, after).length > 0) out.add(item.nodeId);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* RFC-0042 §3.5: the release's live articles whose target adds a derived gate or moves it
|
|
64
|
+
* earlier, under the site's current rules (a release that changes the rules changes the site,
|
|
65
|
+
* which is never low risk anyway).
|
|
66
|
+
*/
|
|
67
|
+
export async function releaseExpiries(
|
|
68
|
+
graph ,
|
|
69
|
+
items ,
|
|
70
|
+
) {
|
|
71
|
+
const out = new Set ();
|
|
72
|
+
for (const { item } of items) {
|
|
73
|
+
const v = await versions(graph, item);
|
|
74
|
+
if (!v) continue;
|
|
75
|
+
const site = await graph.getSite(v.after.siteId);
|
|
76
|
+
if (!site || !hasExpiryRules(site)) continue;
|
|
77
|
+
const group = v.after.translation?.group;
|
|
78
|
+
const original = group && group !== v.after.id ? await graph.getContentEntry(group) : undefined;
|
|
79
|
+
const side = (entry ) => ({ site, entry, original });
|
|
80
|
+
if (advancesDerivedGate(side(v.before), side(v.after))) out.add(item.nodeId);
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Every fact the low-risk check of a release needs, read from the graph. */
|
|
86
|
+
export async function releaseRiskFor(
|
|
87
|
+
graph ,
|
|
88
|
+
items ,
|
|
89
|
+
) {
|
|
90
|
+
return releaseRisk(
|
|
91
|
+
items,
|
|
92
|
+
await releaseCorrections(graph, items),
|
|
93
|
+
await releaseExpiries(graph, items),
|
|
94
|
+
);
|
|
95
|
+
}
|
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`: 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 = " // empty-section\n for (const s of document.querySelectorAll(\"[data-section-id]\")) {\n if (getComputedStyle(s).display === \"none\") continue;\n const text = (s.innerText || \"\").trim();\n const media = s.querySelector(\"img,video,iframe,svg,canvas,input,select,textarea,picture\");\n const r = s.getBoundingClientRect();\n if (!text && !media) add(\"empty-section\", s, \"no text or media\");\n else if (r.height < 8) add(\"empty-section\", s, Math.round(r.height) + \" px tall\");\n }\n\n // tap-target: on small screens, controls under 24 \u00D7 24 px that sit too close to another one\n // (WCAG 2.5.8: a 24 px circle on each must not touch another target; links inside sentences are exempt).\n if (W < 768) {\n const targets = [...document.querySelectorAll(\"a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button]\")]\n .filter(visible)\n .map((el) => ({ el, r: el.getBoundingClientRect() }))\n // screen-reader-only controls (1 \u00D7 1 px) are not tapped\n .filter((t) => t.r.width > 2 || t.r.height > 2);\n const small = (t) => t.r.width < 24 || t.r.height < 24;\n const centre = (r) => [r.left + r.width / 2, r.top + r.height / 2];\n const toRect = (p, r) => Math.hypot(Math.max(r.left - p[0], 0, p[0] - r.right), Math.max(r.top - p[1], 0, p[1] - r.bottom));\n for (const t of targets) {\n if (!small(t)) continue;\n if (t.el.tagName === \"A\" && getComputedStyle(t.el).display === \"inline\") {\n const block = t.el.closest(\"p,li,td,dd,blockquote,figcaption\");\n if (block && (block.innerText || \"\").trim().length > (t.el.innerText || \"\").trim().length + 20) continue;\n }\n const c = centre(t.r);\n const near = targets.find((o) => o !== t && !o.el.contains(t.el) && !t.el.contains(o.el) &&\n (toRect(c, o.r) < 12 || (small(o) && Math.hypot(c[0] - centre(o.r)[0], c[1] - centre(o.r)[1]) < 24)));\n if (near) add(\"tap-target\", t.el, Math.round(t.r.width) + \" \u00D7 \" + Math.round(t.r.height) + \" px, too close to \" + JSON.stringify(clip((near.el.innerText || near.el.getAttribute(\"aria-label\") || near.el.tagName.toLowerCase()).trim(), 24)));\n }\n }\n\n // input-label: form controls without an accessible name (a label, aria-label or aria-labelledby).\n for (const el of document.querySelectorAll(\"input:not([type=hidden]):not([type=submit]):not([type=button]),select,textarea\")) {\n if (!visible(el) && !(el.type === \"radio\" || el.type === \"checkbox\")) continue;\n const named = [...(el.labels || [])].some((l) => (l.innerText || l.textContent || \"\").trim()) ||\n (el.getAttribute(\"aria-label\") || \"\").trim() ||\n (el.getAttribute(\"aria-labelledby\") || \"\").split(/s+/).some((id) => id && (document.getElementById(id)?.textContent || \"\").trim());\n if (!named) add(\"input-label\", el, \"no label a screen reader can announce\");\n }\n\n // chart-empty: a chart whose data has no rows.\n for (const el of document.querySelectorAll(\"[data-ch-chart-empty]\")) add(\"chart-empty\", el, \"no rows in its data\");\n\n // long-line:
|
|
5
|
+
export declare const CONTENT_CHECKS = " // empty-section\n for (const s of document.querySelectorAll(\"[data-section-id]\")) {\n if (getComputedStyle(s).display === \"none\") continue;\n const text = (s.innerText || \"\").trim();\n const media = s.querySelector(\"img,video,iframe,svg,canvas,input,select,textarea,picture\");\n const r = s.getBoundingClientRect();\n if (!text && !media) add(\"empty-section\", s, \"no text or media\");\n else if (r.height < 8) add(\"empty-section\", s, Math.round(r.height) + \" px tall\");\n }\n\n // tap-target: on small screens, controls under 24 \u00D7 24 px that sit too close to another one\n // (WCAG 2.5.8: a 24 px circle on each must not touch another target; links inside sentences are exempt).\n if (W < 768) {\n const targets = [...document.querySelectorAll(\"a[href],button,input:not([type=hidden]),select,textarea,summary,[role=button]\")]\n .filter(visible)\n .map((el) => ({ el, r: el.getBoundingClientRect() }))\n // screen-reader-only controls (1 \u00D7 1 px) are not tapped\n .filter((t) => t.r.width > 2 || t.r.height > 2);\n const small = (t) => t.r.width < 24 || t.r.height < 24;\n const centre = (r) => [r.left + r.width / 2, r.top + r.height / 2];\n const toRect = (p, r) => Math.hypot(Math.max(r.left - p[0], 0, p[0] - r.right), Math.max(r.top - p[1], 0, p[1] - r.bottom));\n for (const t of targets) {\n if (!small(t)) continue;\n if (t.el.tagName === \"A\" && getComputedStyle(t.el).display === \"inline\") {\n const block = t.el.closest(\"p,li,td,dd,blockquote,figcaption\");\n if (block && (block.innerText || \"\").trim().length > (t.el.innerText || \"\").trim().length + 20) continue;\n }\n const c = centre(t.r);\n const near = targets.find((o) => o !== t && !o.el.contains(t.el) && !t.el.contains(o.el) &&\n (toRect(c, o.r) < 12 || (small(o) && Math.hypot(c[0] - centre(o.r)[0], c[1] - centre(o.r)[1]) < 24)));\n if (near) add(\"tap-target\", t.el, Math.round(t.r.width) + \" \u00D7 \" + Math.round(t.r.height) + \" px, too close to \" + JSON.stringify(clip((near.el.innerText || near.el.getAttribute(\"aria-label\") || near.el.tagName.toLowerCase()).trim(), 24)));\n }\n }\n\n // input-label: form controls without an accessible name (a label, aria-label or aria-labelledby).\n for (const el of document.querySelectorAll(\"input:not([type=hidden]):not([type=submit]):not([type=button]),select,textarea\")) {\n if (!visible(el) && !(el.type === \"radio\" || el.type === \"checkbox\")) continue;\n const named = [...(el.labels || [])].some((l) => (l.innerText || l.textContent || \"\").trim()) ||\n (el.getAttribute(\"aria-label\") || \"\").trim() ||\n (el.getAttribute(\"aria-labelledby\") || \"\").split(/s+/).some((id) => id && (document.getElementById(id)?.textContent || \"\").trim());\n if (!named) add(\"input-label\", el, \"no label a screen reader can announce\");\n }\n\n // chart-empty: a chart whose data has no rows.\n for (const el of document.querySelectorAll(\"[data-ch-chart-empty]\")) add(\"chart-empty\", el, \"no rows in its data\");\n\n // long-line: text columns whose full lines hold more than 90 characters on average. Counted on\n // the rendered lines (each paragraph's last, partly filled one left out) and pooled over every\n // paragraph of the same width and font, so paragraphs of one column get one verdict.\n const range = document.createRange();\n const columns = new Map();\n let measured = 0;\n for (const p of document.querySelectorAll(\"p,li,dd,blockquote\")) {\n if (measured >= 80 || !visible(p) || p.querySelector(\"p,li\")) continue;\n if ((p.innerText || \"\").trim().length < 180) continue;\n measured++;\n // Characters by the line they are drawn on, in reading order: a character more than half a\n // line below the current line starts the next (inline code in another size stays on its line).\n // A run of spaces counts once, as it is shown.\n const s = getComputedStyle(p);\n const half = (s.lineHeight === \"normal\" ? parseFloat(s.fontSize) * 1.2 : parseFloat(s.lineHeight)) / 2;\n const rows = [];\n let top = -Infinity, seen = 0, space = true;\n const tw = document.createTreeWalker(p, NodeFilter.SHOW_TEXT);\n while (tw.nextNode() && seen < 800) {\n const n = tw.currentNode;\n for (let i = 0; i < n.length && seen < 800; i++) {\n const blank = /s/.test(n.data[i]);\n if (blank && space) continue;\n space = blank;\n seen++;\n range.setStart(n, i);\n range.setEnd(n, i + 1);\n const b = range.getClientRects()[0];\n if (!b) continue;\n if (b.top > top + half) { rows.push(0); top = b.top; }\n rows[rows.length - 1]++;\n }\n }\n // The last line seen may be partly filled (the paragraph's end, or where counting stopped).\n const full = rows.slice(0, -1);\n if (full.length < 2) continue;\n const width = Math.round(p.getBoundingClientRect().width);\n const key = width + \"|\" + s.fontSize + \"|\" + s.fontFamily;\n const col = columns.get(key) || { width, first: p, paragraphs: 0, lines: 0, chars: 0 };\n col.paragraphs++;\n col.lines += full.length;\n col.chars += full.reduce((a, b) => a + b, 0);\n columns.set(key, col);\n }\n for (const col of columns.values()) {\n const per = Math.round(col.chars / col.lines);\n if (per > 90)\n add(\"long-line\", col.first, \"about \" + per + \" characters a line in this \" + col.width + \" px column\" + (col.paragraphs > 1 ? \" (\" + col.paragraphs + \" paragraphs)\" : \"\"));\n }\n";
|
|
@@ -48,16 +48,53 @@ export const CONTENT_CHECKS = ` // empty-section
|
|
|
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
|
`;
|
|
@@ -15,6 +15,7 @@ import { LAYOUT_CHECKS } from "./layout.js";
|
|
|
15
15
|
import { MOTION_CHECKS } from "./motion.js";
|
|
16
16
|
import { NAVIGATION_CHECKS } from "./navigation.js";
|
|
17
17
|
import { PRELUDE } from "./prelude.js";
|
|
18
|
+
import { SCRIPT_CHECKS } from "./scripts.js";
|
|
18
19
|
|
|
19
20
|
export const RENDER_CHECK_SCRIPT = [
|
|
20
21
|
"(async () => {",
|
|
@@ -23,6 +24,7 @@ export const RENDER_CHECK_SCRIPT = [
|
|
|
23
24
|
CONTRAST_CHECKS,
|
|
24
25
|
CONTENT_CHECKS,
|
|
25
26
|
FONT_CHECKS,
|
|
27
|
+
SCRIPT_CHECKS,
|
|
26
28
|
MOTION_CHECKS,
|
|
27
29
|
NAVIGATION_CHECKS,
|
|
28
30
|
COMPONENT_CHECKS,
|
|
@@ -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 = "(() => {\n const seen = (window.__chCsp = []);\n window.addEventListener(\"securitypolicyviolation\", (e) => {\n if (seen.length < 50)\n 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 });\n }, true);\n})();";
|
|
11
|
+
export declare const SCRIPT_CHECKS = " // surface-broken: a body surface the preview could not draw (RFC-0020 \u00A75), or a component in one\n // with an unknown block type or props that do not fit it. Theme blocks the preview leaves to the\n // site are fine.\n for (const el of document.querySelectorAll(\".ch-surface-problem\")) {\n const why = [...el.querySelectorAll(\"li\")].map((li) => (li.textContent || \"\").trim()).filter(Boolean);\n add(\"surface-broken\", el, why.length ? why.slice(0, 3).join(\"; \") : \"this interactive block cannot be shown\");\n }\n for (const el of document.querySelectorAll(\".ch-block--missing\")) {\n const text = (el.textContent || \"\").trim();\n if (!/shown by the theme on the site$/.test(text)) add(\"surface-broken\", el, text);\n }\n\n // script-blocked: scripts the page's Content-Security-Policy refused (the Site Worker sends\n // script-src 'self', so an inline <script> never runs there). A static preview runs none on\n // purpose (its own CSP), so it is not asked.\n const runsScripts = !document.querySelector('meta[name=\"generator\"][content=\"Cloudhal preview\"]');\n for (const v of runsScripts ? window.__chCsp || [] : []) {\n if (!/^(script-src|script-src-elem|script-src-attr|worker-src)$/.test(v.directive)) continue;\n const inline = v.blocked === \"inline\" || v.blocked === \"eval\" || !v.blocked;\n const what = inline\n ? (v.blocked === \"eval\" ? \"eval\" : \"an inline script\") + (v.sample ? \" \" + JSON.stringify(clip(v.sample.trim(), 40)) : \"\") + (v.line ? \" at line \" + v.line : \"\")\n : \"the script \" + v.blocked;\n const fix = inline ? \"; ship it as a file (a .js under /_astro or public/)\" : \"\";\n const el = v.el && v.el.isConnected ? v.el : document.body;\n add(\"script-blocked\", el, what + (v.report ? \" would be blocked on the site\" : \" was blocked\") + \" by \" + v.directive + fix);\n }\n";
|
|
@@ -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 = `(() => {
|
|
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 = ` // 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
|
*/
|