@botiverse/porthole 0.10.0 → 0.13.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 (68) hide show
  1. package/dist/annotate/types.d.ts +18 -6
  2. package/dist/annotate/validate.d.ts +11 -1
  3. package/dist/annotate/validate.js +18 -1
  4. package/dist/bridge/bridge.d.ts +8 -1
  5. package/dist/bridge/bridge.js +7 -0
  6. package/dist/bridge/unseen.d.ts +8 -0
  7. package/dist/bridge/unseen.js +17 -0
  8. package/dist/check/files.d.ts +2 -0
  9. package/dist/check/files.js +71 -50
  10. package/dist/check/lint.d.ts +8 -1
  11. package/dist/check/lint.js +18 -0
  12. package/dist/check/markup.d.ts +7 -0
  13. package/dist/check/markup.js +49 -0
  14. package/dist/check/page-source.js +1 -1
  15. package/dist/check/scroll.d.ts +116 -0
  16. package/dist/check/scroll.js +1485 -0
  17. package/dist/config/capabilities.d.ts +16 -3
  18. package/dist/config/capabilities.js +1 -0
  19. package/dist/conformance/harness-source.js +1 -1
  20. package/dist/conformance/runtime.js +6 -0
  21. package/dist/guide/guide.js +1 -1
  22. package/dist/guide/runtime.js +2 -2
  23. package/dist/host/create-host.js +30 -3
  24. package/dist/host/types.d.ts +15 -0
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.js +1 -0
  27. package/dist/platform/focus-guard.d.ts +143 -0
  28. package/dist/platform/focus-guard.js +445 -0
  29. package/dist/platform/types.d.ts +18 -0
  30. package/dist/platform/web.js +22 -0
  31. package/dist/react/frame.d.ts +10 -1
  32. package/dist/react/frame.js +4 -0
  33. package/dist/runtime/requests.d.ts +5 -0
  34. package/dist/runtime/requests.js +41 -4
  35. package/dist/runtime/types.generated.js +1 -1
  36. package/dist/shell/annotate.d.ts +2 -1
  37. package/dist/shell/annotate.js +29 -12
  38. package/dist/shell/use.js +9 -1
  39. package/docs/ADOPTING.md +106 -5
  40. package/docs/ARCHITECTURE.md +2 -1
  41. package/docs/DECISIONS.md +741 -2
  42. package/docs/DESIGN.md +38 -9
  43. package/docs/THREAT_MODEL.md +146 -19
  44. package/package.json +1 -1
  45. package/src/annotate/types.ts +19 -6
  46. package/src/annotate/validate.ts +20 -1
  47. package/src/bridge/bridge.ts +17 -1
  48. package/src/bridge/unseen.ts +24 -0
  49. package/src/check/files.ts +72 -54
  50. package/src/check/lint.ts +24 -0
  51. package/src/check/markup.ts +53 -0
  52. package/src/check/scroll.ts +1825 -0
  53. package/src/config/capabilities.ts +16 -3
  54. package/src/conformance/runtime.ts +9 -0
  55. package/src/guide/guide.ts +1 -0
  56. package/src/guide/runtime.ts +2 -2
  57. package/src/host/create-host.ts +38 -3
  58. package/src/host/types.ts +13 -0
  59. package/src/index.ts +2 -0
  60. package/src/platform/focus-guard.ts +572 -0
  61. package/src/platform/types.ts +17 -0
  62. package/src/platform/web.ts +22 -0
  63. package/src/react/frame.tsx +12 -1
  64. package/src/runtime/requests.ts +50 -6
  65. package/src/runtime/types.generated.ts +1 -1
  66. package/src/shell/annotate.ts +29 -12
  67. package/src/shell/use.ts +9 -1
  68. package/types/runtime/v1/comments.d.ts +20 -6
@@ -73,10 +73,21 @@ export interface AnnotationMark {
73
73
  * A marker (P104): with a count, the shell also draws a small bubble with this number (0 to
74
74
  * `ANNOTATION_LIMITS.count`; above 99 it reads "99+", 0 draws the bubble alone) at the end of a
75
75
  * text anchor and the top right of an element. The person can click it: the frame reports
76
- * `activated`. The content can read the number; give one only where the page may know it.
76
+ * `activated`. The content can read the number; give one only where the page may know it. A
77
+ * draft's is dropped (P107): its marker has no number.
77
78
  */
78
79
  readonly count?: number;
80
+ /**
81
+ * What the mark is (P107): `"posted"` (the default, as absent) or `"draft"`, a comment its
82
+ * author hasn't submitted yet. A draft is drawn apart (a dashed line and a hollow marker with no
83
+ * number) and has a marker whether or not it has a count; its count is dropped before the mark
84
+ * goes to the frame. The content can read that a mark is a draft: send drafts only to their
85
+ * author's own frame.
86
+ */
87
+ readonly kind?: AnnotationMarkKind;
79
88
  }
89
+ /** A posted comment's mark, or an unsubmitted draft's (P107). */
90
+ export type AnnotationMarkKind = "posted" | "draft";
80
91
  /** Whether a mark's anchor was found in the content as it is now. */
81
92
  export type AnchorState = "attached" | "orphaned";
82
93
  export interface AnchorResult {
@@ -103,7 +114,8 @@ export type AnnotationReport =
103
114
  }
104
115
  /**
105
116
  * Where the marked anchors are now: every mark after `show`, the focused one after `focus`,
106
- * every mark when the content changed one's state, and, while any mark has a `count`, once a
117
+ * every mark when the content changed one's state, and, while any mark has a marker (a `count`,
118
+ * or a draft, P107), once a
107
119
  * scroll, a resize or a change of the content has settled, only the marks that moved since the
108
120
  * host was last told, at most once a second (P104).
109
121
  */
@@ -112,10 +124,10 @@ export type AnnotationReport =
112
124
  readonly results: readonly AnchorResult[];
113
125
  }
114
126
  /**
115
- * The person clicked the marker of a mark the host shows with a `count` (P104); `rect` is the
116
- * marker's box, to open the host's own UI beside it. The content can fake it for any mark the
117
- * host shows with a count, and can tell a real one happened: open the host's own view of that
118
- * mark, never act on it.
127
+ * The person clicked the marker of a mark the host shows with a `count` (P104), or of a draft
128
+ * (P107); `rect` is the marker's box, to open the host's own UI beside it. The content can fake
129
+ * it for any mark the host shows with a marker, and can tell a real one happened: open the
130
+ * host's own view of that mark, never act on it.
119
131
  */
120
132
  | {
121
133
  readonly type: "activated";
@@ -22,5 +22,15 @@ export declare function clampRect(rect: AnnotationRect, viewport: {
22
22
  export declare function parseReport(value: unknown): AnnotationReport | null;
23
23
  /** What the host may start with: elements, text, or both (default both). */
24
24
  export declare function annotateMode(mode: AnnotateMode | undefined): Required<AnnotateMode>;
25
- /** The host's marks, checked before they go to the frame; throws on the first bad one. */
25
+ /**
26
+ * Whether a mark gets a marker, the one thing a person can click (P104): one with a `count`, and
27
+ * every draft (P107).
28
+ */
29
+ export declare const hasMarker: (mark: AnnotationMark) => boolean;
30
+ /**
31
+ * The host's marks, checked before they go to the frame; throws on the first bad one. Each is
32
+ * rebuilt as the frame gets it: a posted mark as 0.10.0 sent it (no `kind`), a draft with
33
+ * `kind: "draft"` and without its count (P107: a draft's marker shows no number, so the page isn't
34
+ * told one).
35
+ */
26
36
  export declare function checkMarks(marks: readonly AnnotationMark[]): AnnotationMark[];
@@ -166,7 +166,17 @@ export function annotateMode(mode) {
166
166
  }
167
167
  return { elements, text: words };
168
168
  }
169
- /** The host's marks, checked before they go to the frame; throws on the first bad one. */
169
+ /**
170
+ * Whether a mark gets a marker, the one thing a person can click (P104): one with a `count`, and
171
+ * every draft (P107).
172
+ */
173
+ export const hasMarker = (mark) => mark.count !== undefined || mark.kind === "draft";
174
+ /**
175
+ * The host's marks, checked before they go to the frame; throws on the first bad one. Each is
176
+ * rebuilt as the frame gets it: a posted mark as 0.10.0 sent it (no `kind`), a draft with
177
+ * `kind: "draft"` and without its count (P107: a draft's marker shows no number, so the page isn't
178
+ * told one).
179
+ */
170
180
  export function checkMarks(marks) {
171
181
  if (!Array.isArray(marks) || marks.length > LIMITS.marks) {
172
182
  throw new TypeError(`annotations.show: at most ${LIMITS.marks} marks`);
@@ -180,7 +190,14 @@ export function checkMarks(marks) {
180
190
  if (mark.count !== undefined && !count(mark.count, LIMITS.count)) {
181
191
  throw new TypeError(`annotations.show: mark ${index}'s count is a whole number from 0 to ${LIMITS.count}`);
182
192
  }
193
+ const kind = mark.kind;
194
+ if (kind !== undefined && kind !== "posted" && kind !== "draft") {
195
+ throw new TypeError(`annotations.show: mark ${index}'s kind is "posted" or "draft"`);
196
+ }
183
197
  seen.add(mark.id);
198
+ if (kind === "draft") {
199
+ return { id: mark.id, anchor, kind };
200
+ }
184
201
  return { id: mark.id, anchor, ...(mark.count === undefined ? {} : { count: mark.count }) };
185
202
  });
186
203
  }
@@ -13,7 +13,8 @@ import type { CapabilityHandlers, Confirm, ConfirmDisplay, Consent, DataCache, H
13
13
  * every capability its host function's own rate (P091, P095) → arguments well formed and within
14
14
  * their limits → who may (P087: the level of each method the call runs for the viewer, a page's
15
15
  * named data with or without a viewer, db's rules) → not muted, if confirm-gated → the own rate
16
- * of each method it runs (P094: a batch's writes count each) → a user gesture, if gated so → the
16
+ * of each method it runs (P094: a batch's writes count each) → a user gesture, if gated so (and
17
+ * for `comments`, the host page's focus in the calling frame: P109) → the
17
18
  * viewer's consent, if gated so → a person's confirmation, if gated so (at most 10 waiting) →
18
19
  * shown to the person, if gated so (P100) → the handler (or, for a read, a result the host already
19
20
  * gave for it, or for a stale-allowed one the host's cache).
@@ -60,6 +61,12 @@ export interface BridgeOptions {
60
61
  readonly cached?: DataCache;
61
62
  /** Whether the embedding page has user activation now; undefined where it can't tell. */
62
63
  readonly userActivation?: () => boolean | undefined;
64
+ /**
65
+ * Whether the embedding page's focus is in this display's frame now (P109); undefined where it
66
+ * can't tell. A capability whose gesture must be in its frame (`inFrame`: `comments`) is refused
67
+ * without it.
68
+ */
69
+ readonly focused?: () => boolean | undefined;
63
70
  readonly onEvent: (event: BridgeEvent) => void;
64
71
  /** The clock, in milliseconds (tests pass their own). */
65
72
  readonly now?: () => number;
@@ -12,6 +12,8 @@ import { atLeast, higher } from "../runtime/levels.js";
12
12
  import { isCodeAsset, parseArtifactRequest, parseAssetRequest, parseCommentRequest, } from "../runtime/requests.js";
13
13
  import { defaultReason, isRefused, pendingReason, reasonOf, } from "./refusal.js";
14
14
  const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
15
+ /** Whether `capability`'s gesture must be in its own frame (P109: the host page's focus there). */
16
+ const inFrame = (capability) => capabilitySpec(capability).inFrame === true;
15
17
  const MAX_URL = 4_096;
16
18
  /**
17
19
  * The most confirmations one display has waiting at once (P095): past it a call is refused as
@@ -448,6 +450,11 @@ export function createBridge(options) {
448
450
  if (activated === false) {
449
451
  return refuse(capability, "no-user-activation");
450
452
  }
453
+ // A gesture in this frame, not anywhere on the host's page (P109): the person typing in
454
+ // the host's composer gives its page activation, which a frame's call would borrow.
455
+ if (inFrame(capability) && options.focused?.() === false) {
456
+ return refuse(capability, "no-user-activation");
457
+ }
451
458
  }
452
459
  if (gates.includes("consent")) {
453
460
  const consent = options.consent;
@@ -16,3 +16,11 @@ export declare const unseen: (text: string) => boolean;
16
16
  * refuses is left.
17
17
  */
18
18
  export declare function withoutUnseen(text: string): string;
19
+ /**
20
+ * Whether `text` holds what a person can't see, for text a page puts in the person's own words (a
21
+ * comment's draft, P109): `unseen`'s list, with only a joiner or non-joiner between two letters or
22
+ * marks let by (in any script: a person's text needs them, and one that draws as nothing there is
23
+ * a bit at most), and a variation selector right after a pictograph or in a keycap (❤️, 1️⃣). A
24
+ * joiner between pictographs (an emoji sequence) is refused: it can join any two.
25
+ */
26
+ export declare const unseenStrict: (text: string) => boolean;
@@ -69,3 +69,20 @@ const UNSEEN_EACH = new RegExp(UNSEEN.source, "gu");
69
69
  export function withoutUnseen(text) {
70
70
  return text.replace(UNSEEN_EACH, "");
71
71
  }
72
+ /** A variation selector where an emoji has one: after a pictograph, or in a keycap. */
73
+ const EMOJI_SELECTORS = new RegExp("(?<=\\p{Extended_Pictographic})[\\uFE0E\\uFE0F]|(?<=[0-9#*])[\\uFE0E\\uFE0F](?=\\u20E3)", "gu");
74
+ /**
75
+ * A joiner or non-joiner with a letter or mark on each side (P109): how Persian separates its
76
+ * letters (می‌خواهم) and the Indic scripts choose a half form or a conjunct (क्‍ष, എന്‍റെ). Never
77
+ * first or last, doubled, beside a space, punctuation or a pictograph: there it shapes nothing, and
78
+ * hides text or makes a blank-looking draft.
79
+ */
80
+ const LETTER_JOINERS = /(?<=[\p{L}\p{M}])[\u200C\u200D](?=[\p{L}\p{M}])/gu;
81
+ /**
82
+ * Whether `text` holds what a person can't see, for text a page puts in the person's own words (a
83
+ * comment's draft, P109): `unseen`'s list, with only a joiner or non-joiner between two letters or
84
+ * marks let by (in any script: a person's text needs them, and one that draws as nothing there is
85
+ * a bit at most), and a variation selector right after a pictograph or in a keycap (❤️, 1️⃣). A
86
+ * joiner between pictographs (an emoji sequence) is refused: it can join any two.
87
+ */
88
+ export const unseenStrict = (text) => UNSEEN.test(text.replace(LETTER_JOINERS, "").replace(EMOJI_SELECTORS, ""));
@@ -13,6 +13,8 @@ export interface FileFinding extends Omit<Finding, "rule"> {
13
13
  }
14
14
  /** A set's files, by path: text, or bytes. */
15
15
  export type FileContents = Readonly<Record<string, string | Uint8Array>>;
16
+ /** The most pages the scroll-lock rule reads in a version: its entry, and 7 more (P106). */
17
+ export declare const SCROLL_PAGES = 8;
16
18
  /**
17
19
  * Lints a page that comes with files (P081): the set (paths, limits, its entry), each page as
18
20
  * `lintContent` lints a page, each relative reference looked up in the set (a leading `/`, which
@@ -1,7 +1,9 @@
1
1
  import { checkFileSet, DEFAULT_ENTRY, fileLimits, lookupFile, servesFiles, } from "../files/paths.js";
2
2
  import { fileTypeOf, knownType } from "../files/types.js";
3
3
  import { sizeWords } from "../guide/limits.js";
4
- import { lintContent } from "./lint.js";
4
+ import { lintPage } from "./lint.js";
5
+ import { attributesOf } from "./markup.js";
6
+ import { scrollBudget, scrollLock } from "./scroll.js";
5
7
  /** A text's line numbers by offset: its line starts found once, each line then a binary search. */
6
8
  function linesOf(text) {
7
9
  const starts = [0];
@@ -45,54 +47,6 @@ const REFERENCE_ATTRIBUTES = {
45
47
  };
46
48
  /** A tag: its name and its attributes' text. Bounded, and never across another `<`: linear. */
47
49
  const TAG = /<([a-z][a-z0-9-]{0,30})\b([^<>]{0,8192})>/giu;
48
- const isSpace = (code) => code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
49
- /** A tag's attributes, read once from left to right (linear): each name, value and its offset. */
50
- function attributesOf(text) {
51
- const out = [];
52
- let at = 0;
53
- while (at < text.length) {
54
- while (at < text.length && (isSpace(text.charCodeAt(at)) || text[at] === "/")) {
55
- at += 1;
56
- }
57
- const nameStart = at;
58
- while (at < text.length &&
59
- !isSpace(text.charCodeAt(at)) &&
60
- text[at] !== "=" &&
61
- text[at] !== "/") {
62
- at += 1;
63
- }
64
- const name = text.slice(nameStart, at).toLowerCase();
65
- if (name === "") {
66
- at += 1;
67
- continue;
68
- }
69
- while (at < text.length && isSpace(text.charCodeAt(at))) {
70
- at += 1;
71
- }
72
- if (text[at] !== "=") {
73
- continue;
74
- }
75
- at += 1;
76
- while (at < text.length && isSpace(text.charCodeAt(at))) {
77
- at += 1;
78
- }
79
- const quote = text[at];
80
- if (quote === '"' || quote === "'") {
81
- const close = text.indexOf(quote, at + 1);
82
- const end = close < 0 ? text.length : close;
83
- out.push({ name, value: text.slice(at + 1, end), at: at + 1 });
84
- at = end + 1;
85
- }
86
- else {
87
- const start = at;
88
- while (at < text.length && !isSpace(text.charCodeAt(at))) {
89
- at += 1;
90
- }
91
- out.push({ name, value: text.slice(start, at), at: start });
92
- }
93
- }
94
- return out;
95
- }
96
50
  /** What a page's markup loads or links: each element's `src`, `href` or `poster`. */
97
51
  function markupReferences(text) {
98
52
  const found = [];
@@ -179,6 +133,8 @@ function resolve(directory, reference) {
179
133
  return out.join("/");
180
134
  }
181
135
  const directoryOf = (path) => path.slice(0, path.lastIndexOf("/") + 1);
136
+ /** The most pages the scroll-lock rule reads in a version: its entry, and 7 more (P106). */
137
+ export const SCROLL_PAGES = 8;
182
138
  /**
183
139
  * Lints a page that comes with files (P081): the set (paths, limits, its entry), each page as
184
140
  * `lintContent` lints a page, each relative reference looked up in the set (a leading `/`, which
@@ -255,7 +211,34 @@ export function lintFiles(config, files, options = {}) {
255
211
  }
256
212
  }
257
213
  };
214
+ // A stylesheet a page links or a stylesheet imports, found in the set by its path (P106). The
215
+ // fewest characters it may hold first: the rule decodes its text only where it may read it, and
216
+ // nothing keeps it after (P110: kept for the set, one page linking 400 sheets of 240 KB held
217
+ // them all, 200 MB, for the 4 MiB the rule reads).
218
+ const stylesheet = (href, from) => {
219
+ if (href === "" || elsewhere(href) || href.startsWith("/")) {
220
+ return null;
221
+ }
222
+ const target = resolve(directoryOf(from), href);
223
+ const sheet = target === null || !has(target) ? undefined : files[target];
224
+ if (sheet === undefined || target === null) {
225
+ return null;
226
+ }
227
+ // As bytes, at most 3 a character (after a BOM's 3): its fewest characters, and the bytes that
228
+ // hold its first SCANNED.
229
+ return typeof sheet === "string"
230
+ ? { path: target, least: sheet.length, text: () => sheet }
231
+ : {
232
+ path: target,
233
+ least: Math.max(0, Math.ceil(sheet.byteLength / 3) - 1),
234
+ text: () => textOf(sheet.subarray(0, 3 * SCANNED + 3)),
235
+ };
236
+ };
237
+ const it = config.mode === "mcp-app" ? "view" : config.mode === "inline" ? "widget" : "page";
258
238
  const maxPage = config.limits.maxBytes;
239
+ // The version's pages, read, for the scroll-lock rule after the rest (P106). A page over its
240
+ // limit isn't read at all: its error says so.
241
+ const pages = new Set();
259
242
  for (const [path, body] of Object.entries(files)) {
260
243
  const { role } = fileTypeOf(path);
261
244
  if (!knownType(path)) {
@@ -280,9 +263,12 @@ export function lintFiles(config, files, options = {}) {
280
263
  continue;
281
264
  }
282
265
  const text = textOf(body);
283
- for (const finding of lintContent(config, text)) {
266
+ // The scroll-lock rule apart, with the stylesheets the page links (P106).
267
+ for (const finding of lintPage(config, text, { scrollLock: false })) {
284
268
  findings.push({ ...finding, path });
285
269
  }
270
+ // Its path only: the few the rule reads are decoded again there, one at a time.
271
+ pages.add(path);
286
272
  const lines = linesOf(text);
287
273
  check(path, lines, markupReferences(text), directory, "error");
288
274
  check(path, lines, patternReferences(text, CSS_REFERENCES), directory, "warning");
@@ -301,6 +287,41 @@ export function lintFiles(config, files, options = {}) {
301
287
  check(path, lines, patternReferences(text, PAGE_REFERENCES), directoryOf(entry), "warning", directory);
302
288
  }
303
289
  }
290
+ // Its own styles holding a page to one screen (P106): the entry first, then the others in path
291
+ // order, at most SCROLL_PAGES, within one budget for them all. A warning: past either, the pages
292
+ // left aren't checked, and it says how many.
293
+ const budget = scrollBudget();
294
+ const order = [
295
+ ...(pages.has(entry) ? [entry] : []),
296
+ ...[...pages].filter((path) => path !== entry).sort(),
297
+ ];
298
+ let checked = 0;
299
+ for (const path of order.slice(0, SCROLL_PAGES)) {
300
+ const body = files[path];
301
+ const text = body === undefined ? "" : textOf(body);
302
+ const held = scrollLock(text, { noun: it, path, sheet: stylesheet, budget });
303
+ if (budget.spent) {
304
+ break;
305
+ }
306
+ checked += 1;
307
+ if (held !== null) {
308
+ findings.push({
309
+ rule: "scroll-lock",
310
+ severity: "warning",
311
+ message: held.message,
312
+ path: held.path ?? path,
313
+ ...(held.line === undefined ? {} : { line: held.line }),
314
+ });
315
+ }
316
+ }
317
+ const unchecked = pages.size - checked;
318
+ if (unchecked > 0) {
319
+ findings.push({
320
+ rule: "scroll-lock",
321
+ severity: "warning",
322
+ message: `${unchecked} page${unchecked === 1 ? "" : "s"} not checked for scroll lock: the check reads the entry and at most ${SCROLL_PAGES - 1} other pages, within one budget. If one of them holds html, body or its root to one screen (overflow: hidden with height: 100% or 100vh, or position: fixed), let it scroll as a document.`,
323
+ });
324
+ }
304
325
  return findings;
305
326
  }
306
327
  /** Where a finding is, for the agent: `about.html line 3: `. */
@@ -4,7 +4,7 @@ import type { PortholeConfig } from "../config/schema.ts";
4
4
  * the agent fixes it before anyone sees it. Pure: any runtime. Errors are only what certainly
5
5
  * fails or is cut (`refuseOn: "error"` refuses those); the rest are warnings.
6
6
  */
7
- export type LintRule = "size" | "document" | "nested-frame" | "document-write" | "clipboard" | "dialog" | "form" | "egress" | "unpinned" | "position-fixed" | "new-window";
7
+ export type LintRule = "size" | "document" | "nested-frame" | "document-write" | "clipboard" | "dialog" | "form" | "egress" | "unpinned" | "position-fixed" | "scroll-lock" | "new-window";
8
8
  export interface Finding {
9
9
  readonly rule: LintRule;
10
10
  readonly severity: "error" | "warning";
@@ -19,3 +19,10 @@ export interface Finding {
19
19
  */
20
20
  export declare function fragmentOf(content: string): string | null;
21
21
  export declare function lintContent(config: PortholeConfig, content: string): Finding[];
22
+ /**
23
+ * `lintContent`, with or without the scroll-lock rule: `lintFiles` reads that one itself, once,
24
+ * with the stylesheets the page links.
25
+ */
26
+ export declare function lintPage(config: PortholeConfig, content: string, options: {
27
+ readonly scrollLock: boolean;
28
+ }): Finding[];
@@ -1,6 +1,7 @@
1
1
  import { anyHttps, declaredCapabilities, egressOrigins, librarySources, } from "../compile/policy.js";
2
2
  import { sizeWords } from "../guide/limits.js";
3
3
  import { originMatchesSource } from "../isolation/served.js";
4
+ import { scrollLock } from "./scroll.js";
4
5
  const lineOf = (text, index) => text.slice(0, index).split("\n").length;
5
6
  const noun = (config) => config.mode === "artifact" ? "page" : config.mode === "mcp-app" ? "view" : "widget";
6
7
  /** A whole document's markers: what a fragment must not have. */
@@ -71,6 +72,13 @@ const OWN_CDN = [
71
72
  { name: "Plotly", host: /^https:\/\/cdn\.plot\.ly\/plotly/u, pinned: /\d+\.\d+\.\d+/u },
72
73
  ];
73
74
  export function lintContent(config, content) {
75
+ return lintPage(config, content, { scrollLock: true });
76
+ }
77
+ /**
78
+ * `lintContent`, with or without the scroll-lock rule: `lintFiles` reads that one itself, once,
79
+ * with the stylesheets the page links.
80
+ */
81
+ export function lintPage(config, content, options) {
74
82
  if (config.mode === "url") {
75
83
  return [];
76
84
  }
@@ -159,6 +167,16 @@ export function lintContent(config, content) {
159
167
  add("position-fixed", "warning", `No position: fixed: the frame grows with the ${it}'s content, so a fixed element covers it. Use position: sticky or normal flow.`, fixed.index);
160
168
  }
161
169
  }
170
+ // Its own styles holding it to one screen (P106): a warning, as a one-screen app means it.
171
+ const held = options.scrollLock ? scrollLock(content, { noun: it }) : null;
172
+ if (held !== null) {
173
+ findings.push({
174
+ rule: "scroll-lock",
175
+ severity: "warning",
176
+ message: held.message,
177
+ ...(held.line === undefined ? {} : { line: held.line }),
178
+ });
179
+ }
162
180
  const opens = /target\s*=\s*["']?_blank|\bwindow\s*\.\s*open\s*\(/u.exec(content);
163
181
  if (opens !== null && !declared.has("openLink")) {
164
182
  add("new-window", "warning", "Nothing opens a new window here (window.open returns null, target=_blank does nothing): show it inline.", opens.index);
@@ -0,0 +1,7 @@
1
+ /** Reading markup without parsing it: what the checks share. Linear, however it was written. */
2
+ /** A tag's attributes, read once from left to right (linear): each name, value and its offset. */
3
+ export declare function attributesOf(text: string): {
4
+ name: string;
5
+ value: string;
6
+ at: number;
7
+ }[];
@@ -0,0 +1,49 @@
1
+ /** Reading markup without parsing it: what the checks share. Linear, however it was written. */
2
+ const isSpace = (code) => code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
3
+ /** A tag's attributes, read once from left to right (linear): each name, value and its offset. */
4
+ export function attributesOf(text) {
5
+ const out = [];
6
+ let at = 0;
7
+ while (at < text.length) {
8
+ while (at < text.length && (isSpace(text.charCodeAt(at)) || text[at] === "/")) {
9
+ at += 1;
10
+ }
11
+ const nameStart = at;
12
+ while (at < text.length &&
13
+ !isSpace(text.charCodeAt(at)) &&
14
+ text[at] !== "=" &&
15
+ text[at] !== "/") {
16
+ at += 1;
17
+ }
18
+ const name = text.slice(nameStart, at).toLowerCase();
19
+ if (name === "") {
20
+ at += 1;
21
+ continue;
22
+ }
23
+ while (at < text.length && isSpace(text.charCodeAt(at))) {
24
+ at += 1;
25
+ }
26
+ if (text[at] !== "=") {
27
+ continue;
28
+ }
29
+ at += 1;
30
+ while (at < text.length && isSpace(text.charCodeAt(at))) {
31
+ at += 1;
32
+ }
33
+ const quote = text[at];
34
+ if (quote === '"' || quote === "'") {
35
+ const close = text.indexOf(quote, at + 1);
36
+ const end = close < 0 ? text.length : close;
37
+ out.push({ name, value: text.slice(at + 1, end), at: at + 1 });
38
+ at = end + 1;
39
+ }
40
+ else {
41
+ const start = at;
42
+ while (at < text.length && !isSpace(text.charCodeAt(at))) {
43
+ at += 1;
44
+ }
45
+ out.push({ name, value: text.slice(start, at), at: start });
46
+ }
47
+ }
48
+ return out;
49
+ }