YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat(browser-api): add /navigate + /snapshot + clean auth resolver — release-app
Louis Beaumont27e7a28c986b
diff --git a/Cargo.lock b/Cargo.lockindex ee0dff946..6a64db179 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -7131,6 +7131,7 @@ dependencies = ["tracing-appender","tracing-oslog","tracing-subscriber",+ "url","uuid","windows 0.58.0",]diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex d122cc95c..0b90181d5 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -467,7 +467,7 @@ let DEFAULT_SETTINGS: Settings = {experimentalCoreaudioSystemAudio: false,recordWhileLocked: false,appendTypedTextToMeetingNotes: true,- localRetentionEnabled: true,+ localRetentionEnabled: false,localRetentionDays: 14,localRetentionMode: "media",};diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 911342584..4d456f655 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -9726,7 +9726,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.4.119"+version = "2.4.120"dependencies = ["anyhow","arboard",@@ -10064,6 +10064,7 @@ dependencies = ["tracing-appender","tracing-oslog","tracing-subscriber",+ "url","uuid","windows 0.58.0",]diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 778a0cd6f..bfd199cc2 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "2.4.119"+version = "2.4.120"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs b/apps/screenpipe-app-tauri/src-tauri/src/sync.rsindex fa2d2271f..ecb7bb1b6 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/sync.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/sync.rs@@ -731,13 +731,17 @@ pub async fn auto_start_retention(app: &AppHandle) {_ => return,};- // Default to enabled+media for users on stores that haven't seen the- // setting yet — matches the default in createDefaultSettingsObject.+ // Off until explicitly enabled. Legacy stores that pre-date this field+ // must NOT silently start deleting media — the retention-settings UI+ // reads `localRetentionEnabled ?? false`, so the toggle visibly shows+ // "off" for those users; defaulting to `true` here would run retention+ // behind their back. Users who want auto-delete enable it via Settings →+ // Storage, which writes the field to the store.let enabled = settings.extra.get("localRetentionEnabled").and_then(|v| v.as_bool())- .unwrap_or(true);+ .unwrap_or(false);if !enabled {return;diff --git a/crates/screenpipe-connect/src/connections/browser/owned.rs b/crates/screenpipe-connect/src/connections/browser/owned.rsindex 4f94d67ef..da48b1e83 100644--- a/crates/screenpipe-connect/src/connections/browser/owned.rs+++ b/crates/screenpipe-connect/src/connections/browser/owned.rs@@ -78,9 +78,8 @@ impl OwnedBrowser {sessions. Use this for: scraping, signups under screenpipe's \own accounts, scheduled background tasks, navigating to a public \URL the user asked you to open. \- Calling eval with a `url` field auto-opens the embedded sidebar \- in the user's chat — no separate show/hide call. The `code` field \- is JS run in the page; use `return <expr>` to send a value back.",+ Navigating auto-opens the embedded sidebar in the user's chat — \+ no separate show/hide call.",)}diff --git a/crates/screenpipe-core/assets/skills/screenpipe-api/SKILL.md b/crates/screenpipe-core/assets/skills/screenpipe-api/SKILL.mdindex 92a167fe2..95131270d 100644--- a/crates/screenpipe-core/assets/skills/screenpipe-api/SKILL.md+++ b/crates/screenpipe-core/assets/skills/screenpipe-api/SKILL.md@@ -285,31 +285,46 @@ the exact endpoint and body shape. Read it before guessing.### Browser Control — `owned-default`-You have an embedded browser you can drive directly. Don't curl `/connections`-to discover it — just hit these endpoints:+You have an embedded browser you can drive directly. Three intent verbs;+reach for `/eval` only when the first two aren't enough.```bash-# Navigate (slides the browser sidebar in for the user)+# 1. Navigate — opens the URL in the embedded browser sidebar.curl -X POST -H "Authorization: Bearer $SCREENPIPE_LOCAL_API_KEY" \-H "Content-Type: application/json" \- -d '{"url": "https://example.com"}' \- http://localhost:3030/connections/browsers/owned-default/eval--# Run JS on the current page and read the result+ -d '{"url": "https://en.wikipedia.org/wiki/Giraffe"}' \+ http://localhost:3030/connections/browsers/owned-default/navigate+# → {"ok": true, "url": "<final-url-after-redirects>"}++# 2. Snapshot — read the page WITHOUT writing JS. Returns title, url, and+# a compact accessibility-style outline (headings, links, buttons,+# form fields). This is almost always what you want for "what's on+# the page?" / "is this still loading?" / "what links are visible?".+curl -H "Authorization: Bearer $SCREENPIPE_LOCAL_API_KEY" \+ http://localhost:3030/connections/browsers/owned-default/snapshot+# → {+# "title": "Giraffe - Wikipedia",+# "url": "https://en.wikipedia.org/wiki/Giraffe",+# "tree": "[h1] Giraffe\n [a] Article → /wiki/Giraffe\n [a] Talk → /wiki/Talk:Giraffe\n ...",+# "truncated": false+# }++# 3. Eval (escape hatch) — run arbitrary JS, get the return value back.+# Use this when navigate + snapshot can't express what you need+# (e.g. clicking a specific button, reading a table you can't see in+# the snapshot tree, scraping with custom selectors).curl -X POST -H "Authorization: Bearer $SCREENPIPE_LOCAL_API_KEY" \-H "Content-Type: application/json" \- -d '{"code": "document.title"}' \- http://localhost:3030/connections/browsers/owned-default/eval--# Navigate AND run JS in one call-curl -X POST -H "Authorization: Bearer $SCREENPIPE_LOCAL_API_KEY" \- -H "Content-Type: application/json" \- -d '{"url": "https://news.ycombinator.com", "code": "[...document.querySelectorAll(\".titleline > a\")].slice(0,5).map(a => a.innerText)"}' \+ -d '{"code": "return [...document.querySelectorAll(\".title > a\")].slice(0,5).map(a => a.innerText)"}' \http://localhost:3030/connections/browsers/owned-default/eval+# → {"success": true, "result": [...]}```-Response: `{"ok": true, "result": <whatever your code returned>}` or-`{"ok": false, "error": "..."}`. Cookies persist across calls (own profile).+Default rule: try snapshot first. Switch to eval only when you need a+specific value the snapshot tree doesn't surface.++Cookies persist across calls (own profile, isolated from the user's+real browser). Password fields are stripped from snapshot output.---diff --git a/crates/screenpipe-engine/Cargo.toml b/crates/screenpipe-engine/Cargo.tomlindex 786329629..df7ab1742 100644--- a/crates/screenpipe-engine/Cargo.toml+++ b/crates/screenpipe-engine/Cargo.toml@@ -91,6 +91,11 @@ base64 = "0.22.1"uuid = { version = "1.5.0", features = ["v4"] }+# Used by /connections/browsers/:id/navigate to validate URLs up-front so+# clients get 400 (client error) on malformed input rather than 502 from+# the upstream eval transport.+url = "2"+# Cloud sync utilitieshostname = "0.4"md5 = "0.7"diff --git a/crates/screenpipe-engine/src/connections_api.rs b/crates/screenpipe-engine/src/connections_api.rsindex df1fed795..cddb55aab 100644--- a/crates/screenpipe-engine/src/connections_api.rs+++ b/crates/screenpipe-engine/src/connections_api.rs@@ -122,13 +122,7 @@ async fn list_connections(State(state): State<ConnectionsState>) -> Json<Value>"name": b.name(),"icon": b.id(),"category": "browser",- "description": format!(- "{}\n\nControl: GET /connections/browsers/{}/status, \- POST /connections/browsers/{}/eval {{\"code\":\"...\",\"url\":\"...\"}}.",- b.description(),- b.id(),- b.id(),- ),+ "description": format_browser_description(b.description(), b.id()),"fields": [],"connected": b.is_ready().await,}));@@ -160,13 +154,7 @@ async fn get_connection("name": b.name(),"category": "browser","connected": b.is_ready().await,- "description": format!(- "{}\n\nControl: GET /connections/browsers/{}/status, \- POST /connections/browsers/{}/eval {{\"code\":\"...\",\"url\":\"...\"}}.",- b.description(),- b.id(),- b.id(),- ),+ "description": format_browser_description(b.description(), b.id()),});return (StatusCode::OK, Json(body)).into_response();}@@ -1394,11 +1382,26 @@ async fn browser_status(// ---------------------------------------------------------------------------// Browser registry — uniform API for every kind of browser the agent can// drive. The agent reads `GET /connections/browsers`, picks one by id, and-// calls `POST /connections/browsers/:id/eval`. Same shape regardless of+// calls `/navigate`, `/snapshot`, or `/eval`. Same shape regardless of// whether the underlying browser is the user's real Chrome (via the// extension) or an app-managed owned webview.// ---------------------------------------------------------------------------+/// Compose the LLM-facing description for a browser registry entry. Leads+/// with the high-intent verbs (navigate, snapshot) so an agent reading a+/// `GET /connections` listing reaches for them before /eval — the+/// transcript-eaten failure mode of a model writing JS by hand.+fn format_browser_description(natural_desc: &str, id: &str) -> String {+ format!(+ "{natural_desc}\n\n\+ Control:\n\+ - POST /connections/browsers/{id}/navigate {{\"url\": \"https://...\"}} → open a URL.\n\+ - GET /connections/browsers/{id}/snapshot → accessibility outline of the page (title, url, headings, links, buttons, form fields). Use this to read the page; almost always preferable to writing your own JS.\n\+ - GET /connections/browsers/{id}/status → ready check.\n\+ - POST /connections/browsers/{id}/eval {{\"code\": \"...\"}} → escape hatch: run JS when navigate + snapshot aren't enough."+ )+}+#[derive(Deserialize)]struct BrowserEvalBody {code: String,@@ -1445,6 +1448,243 @@ async fn browser_get_status(}}+/// POST /connections/browsers/:id/navigate — open `url` in the named browser.+/// High-level intent verb so the agent doesn't have to know that under the+/// hood this is `eval(code: "return location.href", url: <target>)`.+/// Returns `{ "ok": true, "url": <final-url> }` on success.+#[derive(Deserialize)]+struct BrowserNavigateBody {+ url: String,+ #[serde(default)]+ timeout_secs: Option<u64>,+}++async fn browser_run_navigate(+ State(state): State<ConnectionsState>,+ Path(id): Path<String>,+ Json(body): Json<BrowserNavigateBody>,+) -> (StatusCode, Json<Value>) {+ // Validate the URL up front so a malformed input returns 400 (client+ // error), not 502 (the upstream eval transport's catch-all). Same+ // parser the Tauri shell uses internally — keeps semantics consistent.+ if let Err(e) = url::Url::parse(&body.url) {+ return (+ StatusCode::BAD_REQUEST,+ Json(json!({ "ok": false, "error": format!("invalid url: {e}") })),+ );+ }++ let browser = match state.browser_registry.get(&id).await {+ Some(b) => b,+ None => {+ return (+ StatusCode::NOT_FOUND,+ Json(json!({ "error": format!("no browser registered with id '{id}'") })),+ );+ }+ };++ let timeout = std::time::Duration::from_secs(body.timeout_secs.unwrap_or(30).min(120));+ // We pass `return location.href` so the response includes the URL the+ // page actually settled on (after redirects). The user-visible side+ // effect — the navigation itself — is driven by the `url` argument.+ // The Tauri eval impl already waits for the page to start loading+ // before reading; further redirect-stability detection would need a+ // mutation observer in the page and isn't worth the complexity here.+ match browser+ .eval("return location.href", Some(&body.url), timeout)+ .await+ {+ Ok(r) if r.ok => (+ StatusCode::OK,+ Json(json!({+ "ok": true,+ "url": r.result,+ })),+ ),+ Ok(r) => (+ StatusCode::UNPROCESSABLE_ENTITY,+ Json(json!({ "ok": false, "error": r.error })),+ ),+ Err(EvalError::NotConnected) => (+ StatusCode::SERVICE_UNAVAILABLE,+ Json(json!({ "ok": false, "error": EvalError::NotConnected.to_string() })),+ ),+ Err(e @ EvalError::SendFailed(_)) | Err(e @ EvalError::Disconnected) => (+ StatusCode::BAD_GATEWAY,+ Json(json!({ "ok": false, "error": e.to_string() })),+ ),+ Err(e @ EvalError::Timeout(_)) => (+ StatusCode::GATEWAY_TIMEOUT,+ Json(json!({ "ok": false, "error": e.to_string() })),+ ),+ }+}++/// JS injected by /snapshot. Walks the live DOM and produces a compact,+/// accessibility-style outline of the page — the kind of thing the agent+/// can reason about without writing its own selector-based scraper.+///+/// Output: `{ title, url, tree, truncated }`. `tree` is plain text, capped+/// at MAX_LINES so a giant page doesn't blow the agent's context.+///+/// Skip rules: hidden elements (display:none / visibility:hidden / aria-+/// hidden), script/style/noscript, presentation-only roles, password+/// inputs (the value field would leak the user's secret), `<label>` (its+/// text gets duplicated on the associated input — extra noise), anchors+/// with non-navigable hrefs (`javascript:`, empty, `#`).+///+/// Page-load race: if the user calls /snapshot right after /navigate,+/// `document.readyState` may still be `loading`; we wait up to 5s for it+/// to flip to interactive/complete before walking the DOM, so the agent+/// gets the new page's outline rather than `about:blank`.+const SNAPSHOT_SCRIPT: &str = r#"+async function waitReady(maxMs) {+ if (document.readyState !== 'loading') return;+ await new Promise((resolve) => {+ let done = false;+ const finish = () => { if (!done) { done = true; resolve(); } };+ document.addEventListener('DOMContentLoaded', finish, { once: true });+ setTimeout(finish, maxMs);+ });+}+await waitReady(5000);++const MAX_LINES = 250;+const MAX_DEPTH = 8;+const out = [];+const interesting = new Set([+ 'h1','h2','h3','h4','h5','h6','a','button','input','textarea','select',+ 'nav','main','article','section','form','fieldset','legend',+ 'summary','dialog','header','footer','aside'+]);+const interactiveRoles = new Set([+ 'button','link','checkbox','menuitem','option','radio','switch','tab','textbox','combobox'+]);++function clip(s, n) {+ s = (s || '').replace(/\s+/g, ' ').trim();+ return s.length > n ? s.slice(0, n) + '…' : s;+}++function navigableHref(el) {+ const h = el.getAttribute('href');+ if (!h) return '';+ const trimmed = h.trim();+ if (!trimmed) return '';+ if (trimmed === '#') return '';+ if (trimmed.toLowerCase().startsWith('javascript:')) return '';+ return h;+}++function walk(el, depth) {+ if (out.length >= MAX_LINES) return true; // signal: caller can stop+ if (!el || el.nodeType !== 1) return false;+ const tag = el.tagName.toLowerCase();+ if (tag === 'script' || tag === 'style' || tag === 'noscript' || tag === 'template') return false;+ if (el.getAttribute('aria-hidden') === 'true') return false;+ let style;+ try { style = getComputedStyle(el); } catch (_) { style = null; }+ if (style && (style.display === 'none' || style.visibility === 'hidden')) return false;+ const role = el.getAttribute('role');+ if (role === 'presentation' || role === 'none') return false;+ // Password inputs: a row with a value would leak the user's secret.+ // Skip the input entirely — even an empty-value row implies "there's a+ // password field here" which is fine, but emitting `el.value` is not.+ if (tag === 'input' && (el.type === 'password' || el.type === 'hidden')) return false;+ // <label> duplicates its associated input's text; the input row already+ // surfaces it via aria-labelledby/innerText. Drop the label rows to+ // keep the tree compact.+ if (tag === 'label') {+ for (const child of el.children) {+ if (walk(child, depth)) return true;+ }+ return false;+ }+ const aria = el.getAttribute('aria-label');+ const isInteractive = interactiveRoles.has(role) || aria;+ const include = interesting.has(tag) || isInteractive;+ if (include) {+ // Anchors without a navigable href aren't useful as links — but+ // they CAN be interactive (onclick handlers). Surface them as+ // [button] in that case so the agent knows they're clickable.+ let tagOrRole;+ if (tag === 'a') {+ const h = navigableHref(el);+ tagOrRole = role || (h ? 'a' : 'button');+ } else {+ tagOrRole = role || tag;+ }+ let label = aria || '';+ if (!label) {+ if (tag === 'input') label = el.getAttribute('placeholder') || el.type || 'input';+ else if (tag === 'a' || tag === 'button') label = clip(el.innerText, 80);+ else if (/^h[1-6]$/.test(tag)) label = clip(el.innerText, 120);+ else label = clip(el.getAttribute('name') || el.getAttribute('title') || '', 60);+ }+ const href = tag === 'a' ? navigableHref(el) : '';+ const isFormField = tag === 'input' || tag === 'textarea' || tag === 'select';+ const value = isFormField ? clip(el.value, 60) : '';+ let line = ' '.repeat(Math.min(depth, MAX_DEPTH)) + '[' + tagOrRole + ']';+ if (label) line += ' ' + clip(label, 100);+ if (href) line += ' → ' + clip(href, 80);+ if (value) line += ' = ' + value;+ out.push(line);+ }+ for (const child of el.children) {+ if (walk(child, depth + 1)) return true; // bubble the stop-signal up+ }+ return false;+}+walk(document.body, 0);++return {+ title: document.title || '',+ url: location.href,+ tree: out.join('\n'),+ truncated: out.length >= MAX_LINES+};+"#;++/// GET /connections/browsers/:id/snapshot — return a compact accessibility+/// outline of the current page. Lets the agent answer "what's on the page?"+/// without writing JS. See SNAPSHOT_SCRIPT for the output shape.+async fn browser_run_snapshot(+ State(state): State<ConnectionsState>,+ Path(id): Path<String>,+) -> (StatusCode, Json<Value>) {+ let browser = match state.browser_registry.get(&id).await {+ Some(b) => b,+ None => {+ return (+ StatusCode::NOT_FOUND,+ Json(json!({ "error": format!("no browser registered with id '{id}'") })),+ );+ }+ };++ let timeout = std::time::Duration::from_secs(15);+ match browser.eval(SNAPSHOT_SCRIPT, None, timeout).await {+ Ok(r) if r.ok => (StatusCode::OK, Json(r.result.unwrap_or(json!({})))),+ Ok(r) => (+ StatusCode::UNPROCESSABLE_ENTITY,+ Json(json!({ "error": r.error })),+ ),+ Err(EvalError::NotConnected) => (+ StatusCode::SERVICE_UNAVAILABLE,+ Json(json!({ "error": EvalError::NotConnected.to_string() })),+ ),+ Err(e @ EvalError::SendFailed(_)) | Err(e @ EvalError::Disconnected) => (+ StatusCode::BAD_GATEWAY,+ Json(json!({ "error": e.to_string() })),+ ),+ Err(e @ EvalError::Timeout(_)) => (+ StatusCode::GATEWAY_TIMEOUT,+ Json(json!({ "error": e.to_string() })),+ ),+ }+}+/// POST /connections/browsers/:id/eval — run JS in the named browser.async fn browser_run_eval(State(state): State<ConnectionsState>,@@ -1516,6 +1756,8 @@ where// (Must be before /:id to avoid conflict with generic integration routes.).route("/browsers", get(list_browsers)).route("/browsers/:id/status", get(browser_get_status))+ .route("/browsers/:id/navigate", post(browser_run_navigate))+ .route("/browsers/:id/snapshot", get(browser_run_snapshot)).route("/browsers/:id/eval", post(browser_run_eval))// Legacy single-instance browser routes — deployed extensions// (Chrome v0.2.x and v0.3.0) hardcode these. Keep until usage drops.@@ -1789,4 +2031,117 @@ mod tests {}}}++ // -- format_browser_description ----------------------------------------+ //+ // The description text is the LLM-facing surface that determines whether+ // the agent reaches for /navigate or open-codes a JS eval. The earlier+ // version led with /eval and the agents we observed defaulted to writing+ // JS by hand, then giving up. These tests pin the order and content so a+ // refactor doesn't silently regress the wording.++ #[test]+ fn browser_description_leads_with_navigate() {+ let s = format_browser_description("base", "owned-default");+ let nav = s.find("/navigate").expect("navigate must appear");+ let snap = s.find("/snapshot").expect("snapshot must appear");+ let eval_pos = s.find("/eval").expect("eval must appear");+ assert!(+ nav < snap && snap < eval_pos,+ "navigate → snapshot → eval order regressed: {s}"+ );+ }++ #[test]+ fn browser_description_includes_natural_prefix() {+ let s = format_browser_description("isolated webview", "x");+ assert!(s.starts_with("isolated webview"));+ }++ #[test]+ fn browser_description_calls_eval_an_escape_hatch() {+ // If the agent reads /eval as just another option it's free to skip+ // straight to JS; "escape hatch" makes it explicit that snapshot is+ // the default for reading the page.+ let s = format_browser_description("x", "y");+ assert!(s.contains("escape hatch"), "lost escape-hatch framing: {s}");+ }++ // -- BrowserNavigateBody URL validation --------------------------------++ #[test]+ fn navigate_rejects_malformed_url() {+ // Status code semantics: 400 client error, not 502 from upstream.+ // Test the parser directly since the route is async + needs state.+ assert!(url::Url::parse("not a url").is_err());+ assert!(url::Url::parse("").is_err());+ }++ #[test]+ fn navigate_accepts_normal_https_url() {+ assert!(url::Url::parse("https://en.wikipedia.org/wiki/Giraffe").is_ok());+ }++ // -- SNAPSHOT_SCRIPT invariants ----------------------------------------+ //+ // The script runs in untrusted page context, so it has to be defensive.+ // We don't have a JS runtime in test, but we can verify the script+ // text for the safety properties we care about.++ #[test]+ fn snapshot_script_strips_password_inputs() {+ // If this regresses, an agent calling /snapshot on a login page+ // would see the user's password in the response.+ assert!(+ SNAPSHOT_SCRIPT.contains("type === 'password'"),+ "snapshot script no longer guards against password inputs"+ );+ }++ #[test]+ fn snapshot_script_waits_for_dom_ready() {+ // Snapshot called right after navigate races against the page load.+ // The script must wait for `DOMContentLoaded` (or readyState change)+ // before walking the DOM.+ assert!(+ SNAPSHOT_SCRIPT.contains("waitReady"),+ "snapshot script lost the readyState-wait shim"+ );+ assert!(SNAPSHOT_SCRIPT.contains("DOMContentLoaded"));+ }++ #[test]+ fn snapshot_script_caps_output_size() {+ // Large pages (e.g. Wikipedia category indexes) would otherwise+ // blow the agent's context. The cap + truncated flag are part of+ // the contract.+ assert!(SNAPSHOT_SCRIPT.contains("MAX_LINES"));+ assert!(SNAPSHOT_SCRIPT.contains("truncated"));+ }++ #[test]+ fn snapshot_script_skips_javascript_hrefs() {+ // `javascript:` and `#` hrefs aren't navigable; emitting them as+ // links misleads the agent.+ assert!(SNAPSHOT_SCRIPT.contains("javascript:"));+ }++ #[test]+ fn snapshot_script_skips_aria_hidden() {+ // ARIA-hidden subtrees are explicitly not part of the accessible+ // tree — surfacing them defeats the point of the snapshot.+ assert!(SNAPSHOT_SCRIPT.contains("aria-hidden"));+ }++ #[test]+ fn snapshot_script_returns_structured_payload() {+ // Contract with the agent: { title, url, tree, truncated }. The+ // SKILL.md examples and any pipe code rely on these field names.+ for field in ["title", "url", "tree", "truncated"] {+ assert!(+ SNAPSHOT_SCRIPT.contains(field),+ "snapshot script lost field '{field}' from return shape"+ );+ }+ }}