Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
chore: stack the open PRs onto main (#220)
Lahfirdcfeb7373442
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex a8fc55e09..e671b639a 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -192,6 +192,11 @@ jobs:with:node-version: '24'+ - name: jev-desktop tests+ run: |+ node scripts/jev/run.test.mjs+ node scripts/jev/act.test.mjs+- name: NPM package contentsrun: |node --test tests/npm/*.test.jsdiff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.ymlindex 0b3eeeaed..56829ac0d 100644--- a/.github/workflows/codeql.yml+++ b/.github/workflows/codeql.yml@@ -31,12 +31,12 @@ jobs:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1- name: Initialize CodeQL- uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9+ uses: github/codeql-action/init@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4.38.1with:languages: ${{ matrix.language }}- name: Perform CodeQL Analysis- uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9+ uses: github/codeql-action/analyze@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4.38.1analyze-rust:name: Analyze (rust)@@ -50,10 +50,10 @@ jobs:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1- name: Initialize CodeQL- uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9+ uses: github/codeql-action/init@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4.38.1with:languages: rustbuild-mode: none- name: Perform CodeQL Analysis- uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9+ uses: github/codeql-action/analyze@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4.38.1diff --git a/.github/workflows/supply-chain.yml b/.github/workflows/supply-chain.ymlindex b95f42732..a587da4ba 100644--- a/.github/workflows/supply-chain.yml+++ b/.github/workflows/supply-chain.yml@@ -63,7 +63,7 @@ jobs:./gitleaks git . --log-opts=HEAD --config .gitleaks.toml --redact --no-banner --exit-code 1- name: Workflow security audit- uses: zizmorcore/zizmor-action@70fb788f84895a7701f5643d103d587e460b5c99 # v0.6.3+ uses: zizmorcore/zizmor-action@cc914d7f3750a2d13d75c7f184a1060aa0e9d482 # v0.6.4with:version: 1.25.2persona: regulardiff --git a/Cargo.lock b/Cargo.lockindex 0c85f69b6..3e0243f1d 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -172,9 +172,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"[[package]]name = "clap"-version = "4.6.6"+version = "4.6.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca"+checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"dependencies = ["clap_builder","clap_derive",@@ -182,9 +182,9 @@ dependencies = [[[package]]name = "clap_builder"-version = "4.6.6"+version = "4.6.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889"+checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"dependencies = ["anstream","anstyle",@@ -194,9 +194,9 @@ dependencies = [[[package]]name = "clap_derive"-version = "4.6.4"+version = "4.6.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061"+checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0"dependencies = ["heck","proc-macro2",diff --git a/crates/core/src/trace_read/mod.rs b/crates/core/src/trace_read/mod.rsindex eaa2cb1a9..ec9da95f2 100644--- a/crates/core/src/trace_read/mod.rs+++ b/crates/core/src/trace_read/mod.rs@@ -54,9 +54,7 @@ fn is_zero(v: &usize) -> bool {pub struct MergedTrace {pub events: Vec<Value>,pub segments: Vec<SegmentInfo>,- pub segments_truncated: bool,pub warnings: Vec<TraceWarning>,- pub warnings_truncated: bool,pub total_events: usize,pub matched_events: Option<usize>,pub returned_events: usize,@@ -154,16 +152,14 @@ pub fn read_merged(trace_dir: &Path, options: &ReadOptions) -> Result<MergedTraclet (returned_events, truncated) = apply_tail_limit(filtered_events, options.limit);- let (segments, segments_truncated) = cap_list(segment_infos, METADATA_LIST_CAP);- let (warnings, warnings_truncated) = cap_list(warnings, METADATA_LIST_CAP);+ let (segments, _) = cap_list(segment_infos, METADATA_LIST_CAP);+ let (warnings, _) = cap_list(warnings, METADATA_LIST_CAP);Ok(MergedTrace {returned_events: returned_events.len(),events: returned_events,segments,- segments_truncated,warnings,- warnings_truncated,total_events,matched_events,truncated,diff --git a/crates/core/src/trace_read/mod_tests.rs b/crates/core/src/trace_read/mod_tests.rsindex 1ca7b1770..16b160ad8 100644--- a/crates/core/src/trace_read/mod_tests.rs+++ b/crates/core/src/trace_read/mod_tests.rs@@ -315,7 +315,6 @@ fn segments_metadata_list_is_capped() {fs::File::create(dir.join(format!("{pid}-0.jsonl"))).unwrap();}let result = read_merged(&dir, &ReadOptions::default()).unwrap();- assert!(result.segments_truncated);assert_eq!(result.segments.len(), METADATA_LIST_CAP);}@@ -327,7 +326,6 @@ fn warnings_list_is_capped() {fs::write(dir.join(format!("junk{i}.txt")), b"").unwrap();}let result = read_merged(&dir, &ReadOptions::default()).unwrap();- assert!(result.warnings_truncated);assert_eq!(result.warnings.len(), METADATA_LIST_CAP);}diff --git a/crates/macos/src/system/process_apps.rs b/crates/macos/src/system/process_apps.rsindex 0a37fb70d..063a4fa74 100644--- a/crates/macos/src/system/process_apps.rs+++ b/crates/macos/src/system/process_apps.rs@@ -47,7 +47,7 @@ fn enrich_process_instances(Ok(enriched)}-fn is_cross_uid_identity_error(error: &AdapterError) -> bool {+pub(crate) fn is_cross_uid_identity_error(error: &AdapterError) -> bool {error.code == ErrorCode::PermDenied&& error.detailsdiff --git a/crates/macos/src/system/workspace_apps.rs b/crates/macos/src/system/workspace_apps.rsindex cc2d982b1..4973882fe 100644--- a/crates/macos/src/system/workspace_apps.rs+++ b/crates/macos/src/system/workspace_apps.rs@@ -92,7 +92,7 @@ impl WindowOwnerSnapshot {}pub(crate) fn list_apps_until(deadline: Instant) -> Result<Vec<AppInfo>, AdapterError> {- list_apps_with(deadline, |_| true)+ list_apps_with(deadline, |_| true, true)}pub(crate) fn list_apps_scoped_until(@@ -100,19 +100,23 @@ pub(crate) fn list_apps_scoped_until(bundle_id: Option<&str>,deadline: Instant,) -> Result<Vec<AppInfo>, AdapterError> {- list_apps_with(deadline, |app| {- (agent_desktop_core::app_name_matches(&app.name, name)- || (bundle_id.is_none()- && app- .bundle_id- .as_deref()- .is_some_and(|candidate| candidate.eq_ignore_ascii_case(name))))- && bundle_id.is_none_or(|bundle| {- app.bundle_id- .as_deref()- .is_some_and(|candidate| candidate.eq_ignore_ascii_case(bundle))- })- })+ list_apps_with(+ deadline,+ |app| {+ (agent_desktop_core::app_name_matches(&app.name, name)+ || (bundle_id.is_none()+ && app+ .bundle_id+ .as_deref()+ .is_some_and(|candidate| candidate.eq_ignore_ascii_case(name))))+ && bundle_id.is_none_or(|bundle| {+ app.bundle_id+ .as_deref()+ .is_some_and(|candidate| candidate.eq_ignore_ascii_case(bundle))+ })+ },+ false,+ )}pub(crate) fn window_owner_snapshot_until(@@ -128,6 +132,7 @@ pub(crate) fn window_owner_snapshot_until(fn list_apps_with(deadline: Instant,include: impl Fn(&BridgedApplication) -> bool,+ skip_cross_uid: bool,) -> Result<Vec<AppInfo>, AdapterError> {ensure_before_deadline(deadline)?;crate::system::cocoa_runtime::ensure_cocoa_multithreaded()?;@@ -137,6 +142,7 @@ fn list_apps_with(&bytes,deadline,include,+ skip_cross_uid,crate::system::process_identity::token_for_pid,)}@@ -147,6 +153,7 @@ fn apps_from_json(bytes: &[u8], deadline: Instant) -> Result<Vec<AppInfo>, Adaptbytes,deadline,|_| true,+ true,crate::system::process_identity::token_for_pid,)}@@ -155,6 +162,7 @@ fn apps_from_json_with(bytes: &[u8],deadline: Instant,include: impl Fn(&BridgedApplication) -> bool,+ skip_cross_uid: bool,mut resolve: impl FnMut(i32) -> Result<Option<String>, AdapterError>,) -> Result<Vec<AppInfo>, AdapterError> {let bridged = bridged_snapshot(bytes)?;@@ -172,8 +180,21 @@ fn apps_from_json_with("AppKit returned invalid running-application identity",));}- let process_instance = resolve(app.pid)?- .ok_or_else(|| inventory_error("Selected application exited during inventory"))?;+ let process_instance = match resolve(app.pid) {+ Ok(Some(instance)) => instance,+ Ok(None) => {+ return Err(inventory_error(+ "Selected application exited during inventory",+ ));+ }+ Err(error)+ if skip_cross_uid+ && crate::system::process_apps::is_cross_uid_identity_error(&error) =>+ {+ continue;+ }+ Err(error) => return Err(error),+ };apps.push(AppInfo {name: app.name,pid: crate::system::process_identity::from_pid_t(app.pid)?,diff --git a/crates/macos/src/system/workspace_apps_tests.rs b/crates/macos/src/system/workspace_apps_tests.rsindex 984685a97..8845387f6 100644--- a/crates/macos/src/system/workspace_apps_tests.rs+++ b/crates/macos/src/system/workspace_apps_tests.rs@@ -226,6 +226,7 @@ fn app_inventory_labels_menu_bar_apps_and_drops_headless_services() {bytes,deadline(),|_| true,+ true,|pid| {probed.push(pid);Ok(Some(format!("instance-{pid}")))@@ -269,6 +270,7 @@ fn scoped_lookup_never_probes_unrelated_applications() {bytes,deadline(),|app| app.name == "Target",+ false,|pid| {probed.push(pid);if pid == 418 {@@ -297,6 +299,7 @@ fn scoped_lookup_propagates_selected_identity_denial() {bytes,deadline(),|_| true,+ false,|_| Err(AdapterError::permission_denied()),).unwrap_err();@@ -319,9 +322,74 @@ fn scoped_lookup_preserves_all_same_name_processes() {bytes,deadline(),|app| app.name.eq_ignore_ascii_case("Target"),+ false,|pid| Ok(Some(format!("instance-{pid}"))),).unwrap();assert_eq!(apps.iter().map(|app| app.pid).collect::<Vec<_>>(), [10, 11]);}++fn cross_uid_identity_denial() -> AdapterError {+ AdapterError::new(+ ErrorCode::PermDenied,+ "Permission denied reading process identity for pid 526",+ )+ .with_details(serde_json::json!({+ "kind": "process_identity_permission",+ "source": "libproc",+ "operation": "PROC_PIDTBSDINFO",+ "pid": 526,+ }))+}++#[test]+fn complete_inventory_skips_apps_owned_by_another_uid() {+ let bytes = br#"{+ "applications":[+ {"name":"Finder","pid":10,"launch_time":100.25,"activation_policy":"regular"},+ {"name":"FoxitPDFReaderUpdateService","pid":526,"launch_time":90.0,"activation_policy":"accessory"},+ {"name":"Safari","pid":12,"launch_time":102.75,"activation_policy":"regular"}+ ],+ "frontmost_pid":10,+ "frontmost_launch_time":100.25+ }"#;+ let apps = apps_from_json_with(+ bytes,+ deadline(),+ |_| true,+ true,+ |pid| {+ if pid == 526 {+ Err(cross_uid_identity_denial())+ } else {+ Ok(Some(format!("instance-{pid}")))+ }+ },+ )+ .unwrap();++ let pids: Vec<u32> = apps.iter().map(|app| u32::from(app.pid)).collect();+ assert_eq!(pids, [10, 12]);+}++#[test]+fn scoped_lookup_still_reports_cross_uid_denial_of_the_selected_app() {+ let bytes = br#"{+ "applications":[+ {"name":"Target","pid":526,"launch_time":100.25,"activation_policy":"regular"}+ ],+ "frontmost_pid":526,+ "frontmost_launch_time":100.25+ }"#;+ let error = apps_from_json_with(+ bytes,+ deadline(),+ |_| true,+ false,+ |_| Err(cross_uid_identity_denial()),+ )+ .unwrap_err();++ assert_eq!(error.code, ErrorCode::PermDenied);+}diff --git a/scripts/jev/act.mjs b/scripts/jev/act.mjsindex e6b098769..555b3d40b 100644--- a/scripts/jev/act.mjs+++ b/scripts/jev/act.mjs@@ -19,11 +19,10 @@ import { dirname, join } from "node:path";import { fileURLToPath } from "node:url";import { collect, describe, label, offerable, overlayRole } from "./screen.mjs";-import { NO_MATCH, route } from "./policy.mjs";+import { NO_MATCH, resolveModel, typesafeApi, route } from "./policy.mjs";export { collect, describe, label, offerable, overlayRole, route };-const API = "https://api.typesafe.ai/v1/systemone";const REPO = join(dirname(fileURLToPath(import.meta.url)), "..", "..");/** A Choice accepts 255 options. One is reserved for the no-match outcome. */@@ -71,7 +70,7 @@ export const buildRequest = (intent, surface, candidates, rich = false) => ({surface: surface.overlay ?? "window",element_count: candidates.length,},- model: "jev-latest",+ model: resolveModel(),questions: {target: {type: "choice",@@ -173,8 +172,9 @@ const run = (bin, argv) => {}};-const ask = async (payload) => {- const res = await fetch(API, {+export const ask = async (payload) => {+ const api = typesafeApi();+ const res = await fetch(api, {method: "POST",headers: {Authorization: `Bearer ${process.env.TYPESAFE_API_KEY}`,@@ -182,7 +182,7 @@ const ask = async (payload) => {},body: JSON.stringify(payload),}).catch((e) => ({ ok: false, status: 0, statusText: String(e) }));- if (!res.ok) throw new Error(`typesafe ${res.status} ${res.statusText}`);+ if (!res.ok) throw new Error(`decision endpoint ${api} ${res.status} ${res.statusText}`);return readAnswers(await res.json());};diff --git a/scripts/jev/act.test.mjs b/scripts/jev/act.test.mjsindex 218abf065..ed25f0b99 100644--- a/scripts/jev/act.test.mjs+++ b/scripts/jev/act.test.mjs@@ -1,5 +1,5 @@import assert from "node:assert/strict";-import { buildRequest, collect, describe, label, offerable, overlayRole, readAnswers, reconcile, route, toArgv } from "./act.mjs";+import { ask, buildRequest, collect, describe, label, offerable, overlayRole, readAnswers, reconcile, route, toArgv } from "./act.mjs";const S = "s8f3k2p9";const screen = collect({@@ -83,4 +83,37 @@ assert.deepEqual(toArgv("set-value", `@${S}:e1`, "poem.txt"), ["set-value", `@${assert.deepEqual(toArgv("scroll", `@${S}:e1`, null), ["scroll", `@${S}:e1`, "--direction", "down"]);assert.deepEqual(toArgv("hover", `@${S}:e3`, null), ["--headed", "hover", `@${S}:e3`]);+{+ const saved = { ...process.env };+ const realFetch = globalThis.fetch;+ const endpoint = "http://127.0.0.1:9/decisions";+ process.env.TYPESAFE_BASE_URL = endpoint;+ process.env.TYPESAFE_API_KEY = "test-key";+ const sent = [];+ globalThis.fetch = async (url, init) => {+ sent.push({ url, auth: init.headers.Authorization, body: JSON.parse(init.body) });+ return {+ ok: true,+ status: 200,+ json: async () => ({+ answers: {+ target: { type: "choice", choice: "1", confidence: 0.9 },+ command: { type: "choice", choice: "CLICK", confidence: 0.9 },+ },+ }),+ };+ };+ try {+ const answer = await ask(req);+ assert.deepEqual(sent.map((call) => call.url), [endpoint], "act asks the configured endpoint");+ assert.equal(sent[0].auth, "Bearer test-key", "the key travels with the question");+ assert.deepEqual(sent[0].body, JSON.parse(JSON.stringify(req)), "act posts the request it built");+ assert.equal(answer.command, "CLICK", "the endpoint's answer is read back");+ } finally {+ globalThis.fetch = realFetch;+ for (const k of Object.keys(process.env)) if (!(k in saved)) delete process.env[k];+ Object.assign(process.env, saved);+ }+}+console.log("ok");diff --git a/scripts/jev/policy.mjs b/scripts/jev/policy.mjsindex 80f61a6f7..fbfc3ec23 100644--- a/scripts/jev/policy.mjs+++ b/scripts/jev/policy.mjs@@ -17,6 +17,21 @@ export const MAX_STEPS = 40;export const MAX_CALLS = 80;const STALLED_TURNS = 3;+/**+ * Where decisions are asked. TypeSafe's native System One API by default; point+ * TYPESAFE_BASE_URL at a compatible decisions router — such as OpenRouter's+ * `https://openrouter.ai/api/alpha/decisions` — to reuse an OpenRouter key.+ * Read lazily so programmatic callers may set the variable after import.+ */+export const typesafeApi = () =>+ process.env.TYPESAFE_BASE_URL ?? "https://api.typesafe.ai/v1/systemone";++/** OpenRouter resolves bare aliases ("jev-latest") and "~typesafe/…" aliases, but+ * "typesafe/jev-latest" (scoped, unregistered) answers 400 — so scope bare names+ * through the tilde form, which is registered. */+export const resolveModel = (model = process.env.TYPESAFE_MODEL ?? "jev-latest", api = typesafeApi()) =>+ !model.includes("/") && api.includes("openrouter.ai") ? `~typesafe/${model}` : model;+/*** Each operation names the one capability a target must advertise. The element* lists are built from that, so an operation is offered only when something on@@ -159,7 +174,7 @@ export const buildRequest = (goal, screen, space, history, { values = true } = {};}return {- model: process.env.TYPESAFE_MODEL ?? "jev-latest",+ model: resolveModel(),state: {goal,app: screen.app,@@ -230,7 +245,7 @@ export const route = (a, { floor = BARS.floor, act = BARS.act, risky = BARS.riskexport const needsRiskCheck = (confidence) => confidence >= BARS.act && confidence < BARS.risky;export const riskRequest = (goal, screen, operation, node, { values = true } = {}) => ({- model: process.env.TYPESAFE_MODEL ?? "jev-latest",+ model: resolveModel(),state: {goal,app: screen.app,diff --git a/scripts/jev/run.mjs b/scripts/jev/run.mjsindex 22fbbdafd..940e67996 100644--- a/scripts/jev/run.mjs+++ b/scripts/jev/run.mjs@@ -13,6 +13,8 @@ import { fileURLToPath } from "node:url";import { describe } from "./screen.mjs";import { clipboardGuard, execute, observe, startCursor, stopCursor } from "./desktop.mjs";import {+ TERMINALS,+ typesafeApi,actionSpace,buildRequest,criterion,@@ -23,10 +25,8 @@ import {shouldStop,textSupply,validateChoice,- TERMINALS,} from "./policy.mjs";-const API = "https://api.typesafe.ai/v1/systemone";const post = async (url, key, body) => {for (let attempt = 0; attempt < 3; attempt += 1) {@@ -49,6 +49,12 @@ const post = async (url, key, body) => {throw new Error("the model stayed unavailable");};+export const decide = (goal, screen, space, history, values) =>+ post(typesafeApi(), process.env.TYPESAFE_API_KEY, buildRequest(goal, screen, space, history, { values }));++export const rateRisk = (goal, screen, operation, node, values) =>+ post(typesafeApi(), process.env.TYPESAFE_API_KEY, riskRequest(goal, screen, operation, node, { values }));+export const run = async function* (goal,app,@@ -68,9 +74,7 @@ export const run = async function* (yield { stop: "nothing on this screen can be acted on", screen };return;}- const answers = (- await post(API, process.env.TYPESAFE_API_KEY, buildRequest(goal, screen, space, state.history, { values }))- ).answers;+ const answers = (await decide(goal, screen, space, state.history, values)).answers;state.calls += 1;const options = [...Object.keys(space.targets),@@ -100,11 +104,7 @@ export const run = async function* (confidence = head.confidence;let destructive = null;if (needsRiskCheck(confidence)) {- const rated = await post(- API,- process.env.TYPESAFE_API_KEY,- riskRequest(goal, screen, state.operation, node, { values }),- );+ const rated = await rateRisk(goal, screen, state.operation, node, values);state.calls += 1;const answer = rated.answers?.destructive?.noul;destructive = typeof answer === "number" ? answer : 1;diff --git a/scripts/jev/run.test.mjs b/scripts/jev/run.test.mjsindex 056490ff7..c5c476407 100644--- a/scripts/jev/run.test.mjs+++ b/scripts/jev/run.test.mjs@@ -1,5 +1,6 @@import assert from "node:assert/strict";import { collect, offerable } from "./act.mjs";+import { decide, rateRisk } from "./run.mjs";import {ARGV,OPS,@@ -13,6 +14,7 @@ import {shouldStop,textSupply,validateChoice,+ resolveModel,} from "./policy.mjs";const S = "s8f3k2p9";@@ -205,4 +207,57 @@ const space = actionSpace(screen());assert.equal(risky.decision, "confirm", "the same confidence is not enough once a step is hard to undo");}+{+ const saved = { ...process.env };+ delete process.env.TYPESAFE_MODEL;+ delete process.env.TYPESAFE_BASE_URL;+ const native = "https://api.typesafe.ai/v1/systemone";+ const router = "https://openrouter.ai/api/alpha/decisions";+ assert.equal(resolveModel(undefined, native), "jev-latest", "the bare alias stays bare on the native API");+ assert.equal(+ resolveModel(undefined, router),+ "~typesafe/jev-latest",+ "OpenRouter scopes the same alias through the tilde form",+ );+ assert.equal(resolveModel("jev-1.13.0", router), "~typesafe/jev-1.13.0", "a bare version scopes the same way");+ process.env.TYPESAFE_MODEL = "jev-1.13";+ assert.equal(resolveModel(), "jev-1.13", "TYPESAFE_MODEL is honoured on the native API");+ assert.equal(resolveModel(undefined, native), "jev-1.13", "an explicit native endpoint honours TYPESAFE_MODEL too");+ for (const k of Object.keys(process.env)) if (!(k in saved)) delete process.env[k];+ Object.assign(process.env, saved);+}++{+ const saved = { ...process.env };+ const realFetch = globalThis.fetch;+ const endpoint = "http://127.0.0.1:9/decisions";+ process.env.TYPESAFE_BASE_URL = endpoint;+ process.env.TYPESAFE_API_KEY = "test-key";+ delete process.env.TYPESAFE_MODEL;+ const sent = [];+ globalThis.fetch = async (url, init) => {+ sent.push({ url, auth: init.headers.Authorization, body: init.body === undefined ? undefined : JSON.parse(init.body) });+ return { ok: true, status: 200, json: async () => ({ answers: {} }) };+ };+ const at = { app: "TextEdit", window: "Untitled" };+ const node = Object.values(space.targets.CLICK)[0];+ const wire = (value) => JSON.parse(JSON.stringify(value));+ try {+ await decide("save the file", at, space, [], true);+ await rateRisk("save the file", at, "CLICK", node, true);+ assert.deepEqual(sent.map((call) => call.url), [endpoint, endpoint], "both decisions go to the configured endpoint");+ assert.ok(sent.every((call) => call.auth === "Bearer test-key"), "the key travels with each decision");+ assert.deepEqual(sent[0].body, wire(buildRequest("save the file", at, space, [], { values: true })), "a turn posts its full request");+ assert.deepEqual(+ sent[1].body,+ wire(riskRequest("save the file", at, "CLICK", node, { values: true })),+ "the risk check posts its own request, never an empty body",+ );+ } finally {+ globalThis.fetch = realFetch;+ for (const k of Object.keys(process.env)) if (!(k in saved)) delete process.env[k];+ Object.assign(process.env, saved);+ }+}+console.log("ok");diff --git a/skills/jev-desktop/SKILL.md b/skills/jev-desktop/SKILL.mdindex 32fb30c63..e12666866 100644--- a/skills/jev-desktop/SKILL.md+++ b/skills/jev-desktop/SKILL.md@@ -58,8 +58,9 @@ does the value go through the clipboard and a paste. The clipboard is put backwhen the run ends. One key press per character is never used: it dropscharacters and loses capitals.-**What leaves the machine.** Every turn posts a description of the screen to-`api.typesafe.ai`: each element's role, its accessible name or description, up+**What leaves the machine.** Every turn posts a description of the screen to the+decision endpoint (TypeSafe's `api.typesafe.ai` by default, or whatever+`TYPESAFE_BASE_URL` points at): each element's role, its accessible name or description, upto sixty characters of the value it holds, its state, the window title, and therecent actions. That is enough to send the contents of a private document or afilled form. Secure text fields are already withheld by agent-desktop and never@@ -178,6 +179,27 @@ A Choice accepts 255 options, so up to 254 elements go in one pass. When thefirst pass lands under 0.70 the top five are re-asked with richer descriptions.A screen with more than 254 elements says so in `notes`; use `--root @ref`.+## Deciding through OpenRouter++The decision endpoint is `TYPESAFE_BASE_URL`, defaulting to TypeSafe's native+`https://api.typesafe.ai/v1/systemone`. Point it at OpenRouter's Decisions+router to reuse an OpenRouter key instead of a TypeSafe one (live-tested+against `typesafe/jev-1.13`):++```sh+TYPESAFE_BASE_URL=https://openrouter.ai/api/alpha/decisions \+TYPESAFE_MODEL=typesafe/jev-1.13 \+TYPESAFE_API_KEY=sk-or-... \+node scripts/jev/run.mjs --app Finder "open the Applications folder"+```++`TYPESAFE_MODEL` may stay at its `jev-latest` default — bare names are scoped+through OpenRouter's registered `~typesafe/…` alias — or pin a routed id such+as `typesafe/jev-1.13`. One live-checked trap: the scoped-but-unregistered+`typesafe/jev-latest` answers `400 Model does not exist`. The wire contract is+otherwise the same, so nothing else changes. OpenRouter's Decisions endpoint+is alpha and may change shape.+## Known limits- One snapshot per call, about 3 s on a dense app. `--root` is far cheaper.