mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix ltl semantics and unify action enumeration (#71)
* fix(ltl): give every thunk a construction identity Two distinct unnamed predicates both described as "Thunk(...)", so obligation collapse merged their residuals and could drop a live violation. Identity is assigned at construction and the fields are unexported, so a thunk cannot be built without one. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): reduce a thrown-predicate residual instead of panicking The verifier substitutes an ErrorFormula for the residual of a property whose predicate threw, and that residual is fed back in on the next step. reduce had no case for it, so the run crashed. It re-reports the same failure now. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): make a bounded always the dual of a bounded eventually G<=n(f) and not F<=n(not f) disagreed on traces where the inner was still pending when the window closed, so nnf's negation normal form was not semantics preserving. Both sides now range over the observations at which their inner can definitely resolve: the eventually keeps a pending inner as a disjunct, and the always discharges vacuously at window close. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): arm a one-shot root once per run A root that carries its own horizon is one obligation for the whole run, not one per observation. Re-instantiating a top-level eventually monitored G F<=n(p) instead of F<=n(p) and left one live obligation per step behind; a bounded always restarted its window every step and never closed. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): stop wrapping a top-level eventually in always `eventually(p).within(300, "seconds")` as a property meant "within 300 seconds of every step", which spawned an obligation per step with its own resolved deadline. A 553-step run carried 553 of them and serialized a 75 KB residual. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(ltl): serialize the resolved deadline of a bounded window Two obligations spawned at different steps from one duration-bounded formula differ only in the deadline the evaluator resolved for them, so they serialized identically and the trace erased a distinction the evaluator makes. The authored window stays in amount/unit; the resolved deadline rides alongside. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): split a witness's origin step from its detection step A deferred obligation spans two steps: the one that armed it and the one whose reduction failed. They were conflated under one index, so the extractor snapshot (which is the detecting step's state) was reported against the origin step. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(runner): record a witness's detection step in the trace Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * feat(replay-ui): show the step a violation was detected at The witness evidence is the detecting step's state, so say which step that is and let a reader jump to it. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(verifier): record the extractor state the predicates actually read On the web path extractor bodies are evaluated in V8 and injected here, but only the goja value was replaced. The trace diff and the violation witness therefore described a state no property ever saw. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * refactor(spec): one candidate producer over one target-eligibility rule Both hosts routed verbs themselves and both policies enumerated their own actions, and all four drifted. Web sent `swipes` to scrollable containers only, so swipe-to-dismiss on a list row was reachable on native and unreachable on web; the model policy folded gestures its own way and could not reach what the seeded picker drew. A host now reports facts about every element and never decides which verb may act on it: targets.ts acceptsTarget owns that for both. pick.ts builtinCandidates is the single enumeration, and the model policy reads it through __sanderlingEnumerateBuiltin__ instead of reimplementing it in Go. Gesture verbs change with it: scrolls stay vertical over scrollable containers, swipes go free-form in all four directions from any element with real bounds. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(runner): name a builtin scroll by its drag origin A builtin gesture carries endpoints and no selector, so every scroll rendered as "Scroll down " in the prompt's recent-action memory and two scrollable regions were indistinguishable. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(chrome): clear storage over cdp instead of scripting an opaque origin Launch runs while the tab is still on about:blank, whose opaque origin denies storage access, so localStorage.clear() threw SecurityError and every web run died at launch. Storage.clearDataForOrigin needs no navigation. The exception helper lands here because "Uncaught" is what hid this for so long. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(chrome): enable the swiftshader webgl fallback Headless Chrome runs with --disable-gpu, and without this flag it refuses the software WebGL backend: getContext returns null, so a canvas-rendered app paints nothing and every screenshot is identical black. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * fix(web): resolve testTag through data-testid or id Compose Multiplatform emits its testTag into the element id, which the native table already accepts via the resource-id alias. The two web selector tables were the only place that rejected it. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * test(spec): type-check the spec api as part of make test The fake runtime in api.test.ts did not return a chainable handle from extract, so the file had not type-checked since named() was added. Wiring the check into make test stops it drifting again. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J * docs(manual): one-shot eventually and the gesture verbs Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J
This commit is contained in:
48 files changed
+2604
-712
No files matched your search
+56
-73
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// This file is the WEB Host. It installs globalThis.__sanderling__ (extract +
|
||||
// LTL formula binds) before the spec evaluates, implements the Host interface
|
||||
// (platform/seed/queryCandidates/reportUnsupported) over the live DOM, and then
|
||||
// (platform/seed/queryTargets/reportUnsupported) over the live DOM, and then
|
||||
// delegates ALL action generation to the shared picker via installRuntime
|
||||
// (runtime-entry.ts -> pick.ts). The goja verifier runs the SAME picker over the
|
||||
// SAME Pcg, so a given seed yields an identical action stream by construction.
|
||||
@@ -13,11 +13,11 @@
|
||||
// window.__sanderlingNextAction__() over CDP each tick. LTL predicates are
|
||||
// stubbed: properties run host-side in goja, which loads its own bundle.
|
||||
//
|
||||
// Element references never cross V8/host. queryCandidates resolves each element
|
||||
// to a {x, y} Point via getBoundingClientRect before the picker sees it.
|
||||
// Element references never cross V8/host. queryTargets resolves each element to
|
||||
// a {x, y} Point via getBoundingClientRect before the picker sees it.
|
||||
|
||||
import { installRuntime } from "./runtime-entry.ts";
|
||||
import type { BuiltinVerb, Candidate, Host } from "./action-tree.ts";
|
||||
import type { BuiltinVerb, Candidate, Host, TargetElement } from "./action-tree.ts";
|
||||
|
||||
interface Handle {
|
||||
readonly current: unknown;
|
||||
@@ -85,7 +85,12 @@ function noopFormula(): unknown {
|
||||
const KNOWN_KEY_TO_CSS: Record<string, (value: string) => string> = {
|
||||
id: (v) => `[id="${cssEscape(v)}"]`,
|
||||
"resource-id": (v) => `[id="${cssEscape(v)}"]`,
|
||||
testTag: (v) => `[data-testid="${cssEscape(v)}"]`,
|
||||
// The native table aliases testTag onto resource-id, which the host DOM walk
|
||||
// fills from el.id, so the native path already accepts a testTag emitted as
|
||||
// an id (what Compose Multiplatform does on web). Accept both here so the
|
||||
// tables agree. `:is()` keeps this one compound, since a multi-key selector
|
||||
// concatenates the parts.
|
||||
testTag: (v) => `:is([data-testid="${cssEscape(v)}"], [id="${cssEscape(v)}"])`,
|
||||
testID: (v) => `[data-testid="${cssEscape(v)}"]`,
|
||||
"data-testid": (v) => `[data-testid="${cssEscape(v)}"]`,
|
||||
className: (v) => `[class~="${cssEscape(v)}"]`,
|
||||
@@ -467,9 +472,12 @@ function sanitizeAt(value: unknown, depth: number, seen: WeakSet<object>): unkno
|
||||
return out;
|
||||
}
|
||||
|
||||
// Per-verb DOM selector sets. The tappable set backs taps/doubleTaps/longPresses
|
||||
// (every tappable element is also a valid long-press target); the editable set
|
||||
// backs typing; swipes/scrolls target the scrollable element.
|
||||
// The DOM half of the fact mapping. Which verb may act on which target is NOT
|
||||
// decided here: queryTargets reports facts and targets.ts acceptsTarget applies
|
||||
// them, the same rule the native host's targets run through. These selectors are
|
||||
// only how the DOM answers "is this clickable" / "is this editable", the two
|
||||
// facts with no direct DOM equivalent of the accessibility attributes native
|
||||
// platforms expose.
|
||||
const TAPPABLE_SELECTOR = 'a, button, input, select, textarea, [role="button"], [onclick]';
|
||||
const EDITABLE_SELECTOR = "input, textarea, [contenteditable]";
|
||||
|
||||
@@ -477,12 +485,6 @@ const NON_TEXT_INPUT_TYPES = [
|
||||
"button", "submit", "checkbox", "radio", "range", "color", "file", "image", "reset",
|
||||
];
|
||||
|
||||
function isVisible(element: HTMLElement): boolean {
|
||||
if ((element as HTMLButtonElement).disabled) return false;
|
||||
const rect = element.getBoundingClientRect();
|
||||
return rect.width > 0 && rect.height > 0;
|
||||
}
|
||||
|
||||
function isEditableElement(element: HTMLElement): boolean {
|
||||
if (element.isContentEditable) return true;
|
||||
const tag = element.tagName.toLowerCase();
|
||||
@@ -494,6 +496,14 @@ function isEditableElement(element: HTMLElement): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
// isScrollable mirrors the native `scrollable` accessibility attribute: the
|
||||
// container can actually scroll, i.e. its content overflows its box. The
|
||||
// document scrolling root is not special-cased in: when the page does not
|
||||
// overflow there is no scroll to perform, and native would offer none either.
|
||||
function isScrollable(element: HTMLElement): boolean {
|
||||
return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth;
|
||||
}
|
||||
|
||||
function pointOf(element: Element): Candidate {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return {
|
||||
@@ -504,41 +514,33 @@ function pointOf(element: Element): Candidate {
|
||||
};
|
||||
}
|
||||
|
||||
function tappableCandidates(): Candidate[] {
|
||||
return Array.from(document.querySelectorAll<HTMLElement>(TAPPABLE_SELECTOR))
|
||||
.filter(isVisible)
|
||||
.map(pointOf);
|
||||
// collectTargets walks the document ONCE and reports every element with the facts
|
||||
// the shared eligibility rule reads. The tappable/editable membership sets are
|
||||
// resolved by selector first so the DOM's answer to "clickable" and "editable"
|
||||
// stays expressed in CSS, as it always was.
|
||||
function collectTargets(): TargetElement[] {
|
||||
const clickable = new Set<Element>(Array.from(document.querySelectorAll(TAPPABLE_SELECTOR)));
|
||||
const editable = new Set<Element>(
|
||||
Array.from(document.querySelectorAll<HTMLElement>(EDITABLE_SELECTOR)).filter(
|
||||
isEditableElement,
|
||||
),
|
||||
);
|
||||
return Array.from(document.querySelectorAll<HTMLElement>("*")).map((element) => ({
|
||||
...pointOf(element),
|
||||
clickable: clickable.has(element),
|
||||
enabled: !(element as HTMLButtonElement).disabled,
|
||||
editable: editable.has(element),
|
||||
scrollable: isScrollable(element),
|
||||
}));
|
||||
}
|
||||
|
||||
function editableCandidates(): Candidate[] {
|
||||
return Array.from(document.querySelectorAll<HTMLElement>(EDITABLE_SELECTOR))
|
||||
.filter((element) => isEditableElement(element) && isVisible(element))
|
||||
.map(pointOf);
|
||||
}
|
||||
|
||||
// Scrollable candidates back swipe/scroll: elements that overflow their box,
|
||||
// plus the scrolling root so a page-level scroll always has a target.
|
||||
function scrollableCandidates(): Candidate[] {
|
||||
const root = document.scrollingElement ?? document.documentElement;
|
||||
const candidates: Candidate[] = root ? [pointOf(root)] : [];
|
||||
for (const element of Array.from(document.querySelectorAll<HTMLElement>("*"))) {
|
||||
if (element === root) continue;
|
||||
if (element.scrollHeight <= element.clientHeight && element.scrollWidth <= element.clientWidth) {
|
||||
continue;
|
||||
}
|
||||
if (!isVisible(element)) continue;
|
||||
candidates.push(pointOf(element));
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
// Per-tick candidate cache: the picker's 16-attempt retry re-queries the same
|
||||
// verb, so we avoid re-walking the DOM and re-flushing layout within one tick.
|
||||
// Per-tick target cache: the picker's 16-attempt retry re-queries every tick, so
|
||||
// we avoid re-walking the DOM and re-flushing layout within one tick.
|
||||
// installRuntime resets it before each __sanderlingNextAction__ invocation.
|
||||
const candidateCache = new Map<BuiltinVerb, Candidate[]>();
|
||||
let cachedTargets: TargetElement[] | null = null;
|
||||
|
||||
function resetCandidateCache(): void {
|
||||
candidateCache.clear();
|
||||
function resetTargetCache(): void {
|
||||
cachedTargets = null;
|
||||
}
|
||||
|
||||
const host: Host = {
|
||||
@@ -546,28 +548,9 @@ const host: Host = {
|
||||
seedHi: () => SEED_HI,
|
||||
// lo = 0 matches the goja side's rand.NewPCG(seed, 0).
|
||||
seedLo: () => 0n,
|
||||
queryCandidates(verb: BuiltinVerb): Candidate[] {
|
||||
const cached = candidateCache.get(verb);
|
||||
if (cached) return cached;
|
||||
let candidates: Candidate[];
|
||||
switch (verb) {
|
||||
case "taps":
|
||||
case "doubleTaps":
|
||||
case "longPresses":
|
||||
candidates = tappableCandidates();
|
||||
break;
|
||||
case "typing":
|
||||
candidates = editableCandidates();
|
||||
break;
|
||||
case "swipes":
|
||||
case "scrolls":
|
||||
candidates = scrollableCandidates();
|
||||
break;
|
||||
default:
|
||||
candidates = [];
|
||||
}
|
||||
candidateCache.set(verb, candidates);
|
||||
return candidates;
|
||||
queryTargets(): TargetElement[] {
|
||||
if (!cachedTargets) cachedTargets = collectTargets();
|
||||
return cachedTargets;
|
||||
},
|
||||
reportUnsupported(verb: BuiltinVerb): void {
|
||||
console.warn(`[sanderling] verb ${verb} is unsupported on web`);
|
||||
@@ -578,11 +561,11 @@ const host: Host = {
|
||||
// this module (the web bundle imports the runtime first). Resolve the root
|
||||
// lazily so installRuntime captures it once the spec has evaluated. The root
|
||||
// resolver runs once per __sanderlingNextAction__ tick (before the retry loop),
|
||||
// so it is also where we reset the per-tick candidate cache.
|
||||
// so it is also where we reset the per-tick target cache.
|
||||
installRuntime(
|
||||
host,
|
||||
() => {
|
||||
resetCandidateCache();
|
||||
resetTargetCache();
|
||||
return (globalThis as { actions?: import("./action-tree.ts").GeneratorNode }).actions ?? null;
|
||||
},
|
||||
evaluateExtractors,
|
||||
@@ -593,10 +576,10 @@ installRuntime(
|
||||
export const __testing__ = {
|
||||
host,
|
||||
seedBigInt,
|
||||
tappableCandidates,
|
||||
editableCandidates,
|
||||
scrollableCandidates,
|
||||
resetCandidateCache,
|
||||
collectTargets,
|
||||
TAPPABLE_SELECTOR,
|
||||
EDITABLE_SELECTOR,
|
||||
resetTargetCache,
|
||||
runtime,
|
||||
extractors,
|
||||
evaluateExtractors,
|
||||
|
||||
Reference in new issue
Block a user