@botiverse/porthole 0.9.0 → 0.10.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.
- package/dist/annotate/types.d.ts +3 -1
- package/dist/annotate/validate.d.ts +7 -2
- package/dist/annotate/validate.js +11 -4
- package/dist/bridge/bridge.js +1 -51
- package/dist/bridge/unseen.d.ts +18 -0
- package/dist/bridge/unseen.js +71 -0
- package/dist/check/page-source.js +1 -1
- package/dist/conformance/behavior.js +107 -68
- package/dist/conformance/clipboard.js +16 -14
- package/dist/conformance/harness-source.js +1 -1
- package/dist/conformance/limits.js +117 -64
- package/dist/conformance/probes.js +66 -49
- package/dist/conformance/served.js +66 -63
- package/dist/host/create-host.js +44 -2
- package/dist/platform/types.d.ts +4 -2
- package/dist/shell/annotate.d.ts +5 -3
- package/dist/shell/annotate.js +453 -100
- package/docs/ADOPTING.md +76 -0
- package/docs/DECISIONS.md +374 -13
- package/docs/DESIGN.md +166 -38
- package/docs/THREAT_MODEL.md +72 -25
- package/package.json +1 -1
- package/src/annotate/types.ts +3 -1
- package/src/annotate/validate.ts +12 -5
- package/src/bridge/bridge.ts +1 -60
- package/src/bridge/unseen.ts +82 -0
- package/src/conformance/behavior.ts +221 -69
- package/src/conformance/clipboard.ts +44 -14
- package/src/conformance/limits.ts +169 -76
- package/src/conformance/probes.ts +97 -49
- package/src/conformance/served.ts +112 -63
- package/src/host/create-host.ts +42 -2
- package/src/platform/types.ts +4 -2
- package/src/shell/annotate.ts +453 -100
package/dist/annotate/types.d.ts
CHANGED
|
@@ -44,7 +44,9 @@ export interface AnnotationAnchor {
|
|
|
44
44
|
/**
|
|
45
45
|
* A box in the frame's viewport, CSS px: add the frame element's position to place it on the page.
|
|
46
46
|
* The page's word: the host clamps each it reports to the frame's viewport (P104), so one wholly
|
|
47
|
-
* outside is a box of no size on the nearest edge. A positioning hint only.
|
|
47
|
+
* outside is a box of no size on the nearest edge. A positioning hint only. It is in the frame's
|
|
48
|
+
* own layout px: a host that scales or transforms the frame maps it through that transform too
|
|
49
|
+
* (P105).
|
|
48
50
|
*/
|
|
49
51
|
export interface AnnotationRect {
|
|
50
52
|
readonly x: number;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { type AnnotateMode, type AnnotationAnchor, type AnnotationMark, type AnnotationRect, type AnnotationReport } from "./types.ts";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* An anchor, rebuilt from its known fields; null if any part is malformed or too large. Its label
|
|
4
|
+
* is text for the person, so what they couldn't see is taken out of it (P105: a wordless element's
|
|
5
|
+
* `alt`, `aria-label` or `title`, which the page never shows, can carry bidi controls or zero-width
|
|
6
|
+
* characters); its selectors' words are kept as they are, to be found again.
|
|
7
|
+
*/
|
|
3
8
|
export declare function parseAnchor(value: unknown): AnnotationAnchor | null;
|
|
4
9
|
/** A box in the frame's viewport; null unless every number is finite and sizes aren't negative. */
|
|
5
10
|
export declare function parseRect(value: unknown): AnnotationRect | null;
|
|
@@ -12,7 +17,7 @@ export declare function parseRect(value: unknown): AnnotationRect | null;
|
|
|
12
17
|
export declare function clampRect(rect: AnnotationRect, viewport: {
|
|
13
18
|
readonly width: number;
|
|
14
19
|
readonly height: number;
|
|
15
|
-
} | undefined): AnnotationRect;
|
|
20
|
+
} | null | undefined): AnnotationRect;
|
|
16
21
|
/** A report from the frame, checked; null if malformed (it is then dropped). */
|
|
17
22
|
export declare function parseReport(value: unknown): AnnotationReport | null;
|
|
18
23
|
/** What the host may start with: elements, text, or both (default both). */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ANNOTATION_LIMITS as LIMITS, } from "./types.js";
|
|
2
|
+
import { withoutUnseen } from "../bridge/unseen.js";
|
|
2
3
|
/**
|
|
3
4
|
* The host's checks on what a frame says about annotations (P053), and on anchors a host stores
|
|
4
5
|
* and sends back. Each rebuilds what it accepts from known fields only, within `ANNOTATION_LIMITS`,
|
|
@@ -40,7 +41,12 @@ function selector(value) {
|
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* An anchor, rebuilt from its known fields; null if any part is malformed or too large. Its label
|
|
46
|
+
* is text for the person, so what they couldn't see is taken out of it (P105: a wordless element's
|
|
47
|
+
* `alt`, `aria-label` or `title`, which the page never shows, can carry bidi controls or zero-width
|
|
48
|
+
* characters); its selectors' words are kept as they are, to be found again.
|
|
49
|
+
*/
|
|
44
50
|
export function parseAnchor(value) {
|
|
45
51
|
if (!isRecord(value) || (value.kind !== "element" && value.kind !== "text")) {
|
|
46
52
|
return null;
|
|
@@ -65,7 +71,7 @@ export function parseAnchor(value) {
|
|
|
65
71
|
if (value.kind === "text" ? !quote : !css && !quote) {
|
|
66
72
|
return null;
|
|
67
73
|
}
|
|
68
|
-
return { kind: value.kind, selectors, label: value.label };
|
|
74
|
+
return { kind: value.kind, selectors, label: withoutUnseen(value.label) };
|
|
69
75
|
}
|
|
70
76
|
const coordinate = (value) => typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= LIMITS.coordinate;
|
|
71
77
|
/** A box in the frame's viewport; null unless every number is finite and sizes aren't negative. */
|
|
@@ -89,8 +95,9 @@ export function parseRect(value) {
|
|
|
89
95
|
* box of no size at the frame's corner. The page still chooses any point inside its own frame.
|
|
90
96
|
*/
|
|
91
97
|
export function clampRect(rect, viewport) {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
98
|
+
const known = viewport !== null && typeof viewport === "object";
|
|
99
|
+
const width = known && Number.isFinite(viewport.width) ? viewport.width : 0;
|
|
100
|
+
const height = known && Number.isFinite(viewport.height) ? viewport.height : 0;
|
|
94
101
|
const within = (value, most) => Math.min(Math.max(value, 0), Math.max(0, most));
|
|
95
102
|
const left = within(rect.x, width);
|
|
96
103
|
const top = within(rect.y, height);
|
package/dist/bridge/bridge.js
CHANGED
|
@@ -3,6 +3,7 @@ import { parseReport } from "../annotate/validate.js";
|
|
|
3
3
|
import { callGates, effectiveGates } from "../compile/policy.js";
|
|
4
4
|
import { boundedText } from "./bounded-text.js";
|
|
5
5
|
import { isJsonData } from "./json-data.js";
|
|
6
|
+
import { unseen } from "./unseen.js";
|
|
6
7
|
import { blockedNavigationMessage, cutText, withoutSealedAddresses } from "./navigation.js";
|
|
7
8
|
import { RUNTIME_HOST_FUNCTIONS, familyOf, methodGates, methodLevel, methodOf, methodsOfCall, assetCodeRuns, rosterOf, runtimeCapability, } from "../runtime/contract.js";
|
|
8
9
|
import { declaredMatch, } from "../runtime/declaration.js";
|
|
@@ -45,57 +46,6 @@ function resourceUri(args) {
|
|
|
45
46
|
}
|
|
46
47
|
/** The most text blocks one model context update holds. */
|
|
47
48
|
const MAX_CONTEXT_BLOCKS = 100;
|
|
48
|
-
/**
|
|
49
|
-
* What a person can't see but a model reads (the review of P100): format characters (zero-width
|
|
50
|
-
* ones, bidi controls, the tags U+E0000–E007F, a soft hyphen, a byte-order mark), variation
|
|
51
|
-
* selectors (U+FE00–FE0F, U+E0100–E01EF), private-use characters, lone surrogates, every
|
|
52
|
-
* default-ignorable code point (the re-check: U+034F, Mongolian's free variation selectors, the
|
|
53
|
-
* Hangul fillers, Khmer's inherent vowels), and controls other than a new line and a tab. An update with any is refused, never escaped: an escaped one
|
|
54
|
-
* reads to the model differently from what the person was shown.
|
|
55
|
-
*/
|
|
56
|
-
const UNSEEN = /[\p{Cf}\p{Co}\p{Cs}\p{Default_Ignorable_Code_Point}\u{FE00}-\u{FE0F}\u{E0100}-\u{E01EF}]|[^\P{Cc}\n\t]/u;
|
|
57
|
-
/**
|
|
58
|
-
* The parts of real emoji that draw as nothing alone, allowed only where an emoji has them (the
|
|
59
|
-
* re-review of P100): U+FE0E or U+FE0F directly after a pictograph, or after a keycap base
|
|
60
|
-
* (`[0-9#*]`) that U+20E3 follows; U+200D only between two pictographs, a selector or a skin tone
|
|
61
|
-
* after the first. Each carries at most one choice beside a visible emoji (a selector there or
|
|
62
|
-
* not, a joiner there or not), never letters a model would read. Tag characters stay refused:
|
|
63
|
-
* subdivision flags too.
|
|
64
|
-
*/
|
|
65
|
-
const EMOJI_PARTS = "(?<=\\p{Extended_Pictographic})[\\uFE0E\\uFE0F]|(?<=[0-9#*])[\\uFE0E\\uFE0F](?=\\u20E3)|(?<=\\p{Extended_Pictographic}[\\uFE0F\\p{Emoji_Modifier}]?)\\u200D(?=\\p{Extended_Pictographic})";
|
|
66
|
-
/**
|
|
67
|
-
* The scripts whose letters U+200C and U+200D shape (Unicode's notes on the joiners: the cursive
|
|
68
|
-
* scripts, where they break or make a join, and the Indic ones and Myanmar, where they choose a
|
|
69
|
-
* conjunct, a half form or a ligature), by Script_Extensions.
|
|
70
|
-
*/
|
|
71
|
-
const SHAPING_SCRIPTS = [
|
|
72
|
-
"Arabic",
|
|
73
|
-
"Syriac",
|
|
74
|
-
"Nko",
|
|
75
|
-
"Mongolian",
|
|
76
|
-
"Devanagari",
|
|
77
|
-
"Bengali",
|
|
78
|
-
"Gurmukhi",
|
|
79
|
-
"Gujarati",
|
|
80
|
-
"Oriya",
|
|
81
|
-
"Tamil",
|
|
82
|
-
"Telugu",
|
|
83
|
-
"Kannada",
|
|
84
|
-
"Malayalam",
|
|
85
|
-
"Sinhala",
|
|
86
|
-
"Myanmar",
|
|
87
|
-
];
|
|
88
|
-
const SHAPED = `[${SHAPING_SCRIPTS.map((name) => `\\p{scx=${name}}`).join("")}]`;
|
|
89
|
-
/**
|
|
90
|
-
* A joiner or non-joiner between two letters or marks of those scripts (Persian's میخواهم, a
|
|
91
|
-
* Hindi half form): the shape it chooses is what the person sees. One at a letter boundary, never
|
|
92
|
-
* doubled, first or last, or beside a letter of another script.
|
|
93
|
-
*/
|
|
94
|
-
const SHAPING_JOINERS = `(?<=[\\p{L}\\p{M}])(?<=${SHAPED})[\\u200C\\u200D](?=[\\p{L}\\p{M}])(?=${SHAPED})`;
|
|
95
|
-
/** What may be invisible alone and is allowed where it is seen: one pass, on the text as sent. */
|
|
96
|
-
const SEEN_IN_PLACE = new RegExp(`${EMOJI_PARTS}|${SHAPING_JOINERS}`, "gu");
|
|
97
|
-
/** Whether `text` holds what a person can't see, the parts of emoji and shaped letters aside. */
|
|
98
|
-
const unseen = (text) => UNSEEN.test(text.replace(SEEN_IN_PLACE, ""));
|
|
99
49
|
/** Whether any string in `value`, a key or a value, holds what can't be seen (bounded JSON data). */
|
|
100
50
|
function holdsUnseen(value) {
|
|
101
51
|
if (typeof value === "string") {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a person can't see in text that a model or a host's UI reads (P100; P105 for labels): one
|
|
3
|
+
* definition, for the bridge's check of a model context update and the annotation labels' strip.
|
|
4
|
+
*/
|
|
5
|
+
/** Whether `text` holds what a person can't see, the parts of emoji and shaped letters aside. */
|
|
6
|
+
export declare const unseen: (text: string) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* `text` without anything a person can't see (P105), for text Porthole only shows, never matches,
|
|
9
|
+
* as a wordless element's label is (an `alt`, `aria-label` or `title` the person never sees on the
|
|
10
|
+
* page): every format character (bidi controls and the zero-width ones among them), every
|
|
11
|
+
* default-ignorable code point, variation selector, private-use character and lone surrogate, and
|
|
12
|
+
* every control but a new line and a tab. No exceptions: not the parts of emoji, nor the joiners
|
|
13
|
+
* between shaped letters that `unseen` lets by, whose surroundings a page can fake (the review of
|
|
14
|
+
* P105: a Mongolian variation selector beside each joiner carried 48 of them through, a payload
|
|
15
|
+
* of six bytes). An emoji may lose its joiners (a family shows as its faces). Nothing `unseen`
|
|
16
|
+
* refuses is left.
|
|
17
|
+
*/
|
|
18
|
+
export declare function withoutUnseen(text: string): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a person can't see in text that a model or a host's UI reads (P100; P105 for labels): one
|
|
3
|
+
* definition, for the bridge's check of a model context update and the annotation labels' strip.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* What a person can't see but a model reads (the review of P100): format characters (zero-width
|
|
7
|
+
* ones, bidi controls, the tags U+E0000–E007F, a soft hyphen, a byte-order mark), variation
|
|
8
|
+
* selectors (U+FE00–FE0F, U+E0100–E01EF), private-use characters, lone surrogates, every
|
|
9
|
+
* default-ignorable code point (the re-check: U+034F, Mongolian's free variation selectors, the
|
|
10
|
+
* Hangul fillers, Khmer's inherent vowels), and controls other than a new line and a tab. An update with any is refused, never escaped: an escaped one
|
|
11
|
+
* reads to the model differently from what the person was shown.
|
|
12
|
+
*/
|
|
13
|
+
const UNSEEN = /[\p{Cf}\p{Co}\p{Cs}\p{Default_Ignorable_Code_Point}\u{FE00}-\u{FE0F}\u{E0100}-\u{E01EF}]|[^\P{Cc}\n\t]/u;
|
|
14
|
+
/**
|
|
15
|
+
* The parts of real emoji that draw as nothing alone, allowed only where an emoji has them (the
|
|
16
|
+
* re-review of P100): U+FE0E or U+FE0F directly after a pictograph, or after a keycap base
|
|
17
|
+
* (`[0-9#*]`) that U+20E3 follows; U+200D only between two pictographs, a selector or a skin tone
|
|
18
|
+
* after the first. Each carries at most one choice beside a visible emoji (a selector there or
|
|
19
|
+
* not, a joiner there or not), never letters a model would read. Tag characters stay refused:
|
|
20
|
+
* subdivision flags too.
|
|
21
|
+
*/
|
|
22
|
+
const EMOJI_PARTS = "(?<=\\p{Extended_Pictographic})[\\uFE0E\\uFE0F]|(?<=[0-9#*])[\\uFE0E\\uFE0F](?=\\u20E3)|(?<=\\p{Extended_Pictographic}[\\uFE0F\\p{Emoji_Modifier}]?)\\u200D(?=\\p{Extended_Pictographic})";
|
|
23
|
+
/**
|
|
24
|
+
* The scripts whose letters U+200C and U+200D shape (Unicode's notes on the joiners: the cursive
|
|
25
|
+
* scripts, where they break or make a join, and the Indic ones and Myanmar, where they choose a
|
|
26
|
+
* conjunct, a half form or a ligature), by Script_Extensions.
|
|
27
|
+
*/
|
|
28
|
+
const SHAPING_SCRIPTS = [
|
|
29
|
+
"Arabic",
|
|
30
|
+
"Syriac",
|
|
31
|
+
"Nko",
|
|
32
|
+
"Mongolian",
|
|
33
|
+
"Devanagari",
|
|
34
|
+
"Bengali",
|
|
35
|
+
"Gurmukhi",
|
|
36
|
+
"Gujarati",
|
|
37
|
+
"Oriya",
|
|
38
|
+
"Tamil",
|
|
39
|
+
"Telugu",
|
|
40
|
+
"Kannada",
|
|
41
|
+
"Malayalam",
|
|
42
|
+
"Sinhala",
|
|
43
|
+
"Myanmar",
|
|
44
|
+
];
|
|
45
|
+
const SHAPED = `[${SHAPING_SCRIPTS.map((name) => `\\p{scx=${name}}`).join("")}]`;
|
|
46
|
+
/**
|
|
47
|
+
* A joiner or non-joiner between two letters or marks of those scripts (Persian's میخواهم, a
|
|
48
|
+
* Hindi half form): the shape it chooses is what the person sees. One at a letter boundary, never
|
|
49
|
+
* doubled, first or last, or beside a letter of another script.
|
|
50
|
+
*/
|
|
51
|
+
const SHAPING_JOINERS = `(?<=[\\p{L}\\p{M}])(?<=${SHAPED})[\\u200C\\u200D](?=[\\p{L}\\p{M}])(?=${SHAPED})`;
|
|
52
|
+
/** What may be invisible alone and is allowed where it is seen: one pass, on the text as sent. */
|
|
53
|
+
const SEEN_IN_PLACE = new RegExp(`${EMOJI_PARTS}|${SHAPING_JOINERS}`, "gu");
|
|
54
|
+
/** Whether `text` holds what a person can't see, the parts of emoji and shaped letters aside. */
|
|
55
|
+
export const unseen = (text) => UNSEEN.test(text.replace(SEEN_IN_PLACE, ""));
|
|
56
|
+
/** Every code point `UNSEEN` names, each on its own. */
|
|
57
|
+
const UNSEEN_EACH = new RegExp(UNSEEN.source, "gu");
|
|
58
|
+
/**
|
|
59
|
+
* `text` without anything a person can't see (P105), for text Porthole only shows, never matches,
|
|
60
|
+
* as a wordless element's label is (an `alt`, `aria-label` or `title` the person never sees on the
|
|
61
|
+
* page): every format character (bidi controls and the zero-width ones among them), every
|
|
62
|
+
* default-ignorable code point, variation selector, private-use character and lone surrogate, and
|
|
63
|
+
* every control but a new line and a tab. No exceptions: not the parts of emoji, nor the joiners
|
|
64
|
+
* between shaped letters that `unseen` lets by, whose surroundings a page can fake (the review of
|
|
65
|
+
* P105: a Mongolian variation selector beside each joiner carried 48 of them through, a payload
|
|
66
|
+
* of six bytes). An emoji may lose its joiners (a family shows as its faces). Nothing `unseen`
|
|
67
|
+
* refuses is left.
|
|
68
|
+
*/
|
|
69
|
+
export function withoutUnseen(text) {
|
|
70
|
+
return text.replace(UNSEEN_EACH, "");
|
|
71
|
+
}
|