Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(computer): send the user's Chrome no key from a script and find it by its executable

jeffrey4f7ba23e5c27
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index d335a62a..0464be84 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -346,12 +346,14 @@ the tabs are found by role and place in the window, not by their names, which
follow the user's language. The Daemon finds the running Chrome by its
executable wherever the app is installed. The user's Chrome takes no keys from
the Computer (`COMPUTER_KEYS_REFUSED`), in any of its windows, in tool calls,
-`run_actions` steps, paged `recognize_text` reads and every script: a shortcut
+`run_actions` steps, paged `recognize_text` reads and scripts: a shortcut
runs as a menu command in the Chrome window that has the keyboard, and Cua
types text as keys that all read as the A key. A key goes to the window its
`element_token` was read from, and a key that names no app is refused while
that Chrome runs. Only a plain key bound to an element of the Computer's
-window goes, and Cua sends it only when no other Chrome window could take it.
+window goes, as a tool call, and Cua sends it only when no other Chrome window
+could take it. A script sends that Chrome no key at all, because it cannot
+prove which window a token was read from, and it does not start Chrome.
The Agent fills fields with
`set_value`, presses the page's buttons and goes back through its links.
The Daemon removes the separate Chrome profile `computer-tools/agent-chrome`
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
index 76326860..ee886e8c 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
@@ -291,36 +291,40 @@ func (c *cuaSession) waitSafariWindows(ctx context.Context, b agentBrowser, pid
// Google Chrome on its default profile, wherever the app is installed. Chrome
// instances on a profile of their own, such as a test browser, name
// --user-data-dir and are not it. It returns the pid and command line, or 0
-// when that Chrome is not running.
+// when that Chrome is not running. The executable comes from its own ps
+// column, because a path with spaces cannot be split from the arguments.
var everydayChromePID = func(ctx context.Context) (int, string, error) {
- output, err := exec.CommandContext(ctx, "/bin/ps", "-axww", "-o", "pid=,args=").Output()
+ paths, err := exec.CommandContext(ctx, "/bin/ps", "-axww", "-o", "pid=,comm=").Output()
if err != nil {
return 0, "", err
}
- for _, line := range strings.Split(string(output), "\n") {
+ lines, err := exec.CommandContext(ctx, "/bin/ps", "-axww", "-o", "pid=,args=").Output()
+ if err != nil {
+ return 0, "", err
+ }
+ commands := map[string]string{}
+ for _, line := range strings.Split(string(lines), "\n") {
pidText, args, _ := strings.Cut(strings.TrimSpace(line), " ")
- if !everydayChromeCommand(args) {
+ commands[pidText] = args
+ }
+ for _, line := range strings.Split(string(paths), "\n") {
+ pidText, path, _ := strings.Cut(strings.TrimSpace(line), " ")
+ if !everydayChromeProcess(path, commands[pidText]) {
continue
}
if pid, err := strconv.Atoi(pidText); err == nil {
- return pid, args, nil
+ return pid, commands[pidText], nil
}
}
return 0, "", nil
}
-// everydayChromeCommand reports whether args starts Google Chrome's own
-// executable on the default profile. The executable path has spaces, so it
-// ends where the first argument starts.
-func everydayChromeCommand(args string) bool {
- index := strings.Index(args, everydayChromeExecutable)
- // A command that only names Chrome's path as an argument has an option
- // or another path before it.
- if !strings.HasPrefix(args, "/") || index < 0 || strings.Contains(args[:index], " -") || strings.Contains(args[:index], " /") {
- return false
- }
- rest := args[index+len(everydayChromeExecutable):]
- return (rest == "" || rest[0] == ' ') && !strings.Contains(args, "--type=") && !strings.Contains(args, "--user-data-dir=")
+// everydayChromeProcess reports whether the process with executable path
+// and command line args is Google Chrome's main process on the default
+// profile.
+func everydayChromeProcess(path, args string) bool {
+ return strings.HasPrefix(path, "/") && strings.HasSuffix(path, everydayChromeExecutable) &&
+ !strings.Contains(args, "--type=") && !strings.Contains(args, "--user-data-dir=")
}
const everydayChromeExecutable = "/Google Chrome.app/Contents/MacOS/Google Chrome"
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go
index abcbb537..6c8208de 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go
@@ -47,17 +47,20 @@ func TestPickAgentBrowserTakesTheFirstInstalledOrTheNamedOne(t *testing.T) {
}
}
-func TestEverydayChromeCommandFindsChromeInAnyFolder(t *testing.T) {
- for args, want := range map[string]bool{
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome": true,
- "/Users/a/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --disable-backgrounding-occluded-windows": true,
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/tmp/test": false,
- "/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=renderer": false,
- "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary": false,
- "tail -f /Applications/Google Chrome.app/Contents/MacOS/Google Chrome": false,
+func TestEverydayChromeProcessFindsChromeInAnyFolder(t *testing.T) {
+ for _, tc := range []struct {
+ path, args string
+ want bool
+ }{
+ {"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", true},
+ {"/Users/a/Applications/Work - Apps/Google Chrome.app/Contents/MacOS/Google Chrome", "/Users/a/Applications/Work - Apps/Google Chrome.app/Contents/MacOS/Google Chrome --disable-backgrounding-occluded-windows", true},
+ {"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/tmp/test", false},
+ {"/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper", "Google Chrome Helper --type=renderer", false},
+ {"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary", "", false},
+ {"/usr/bin/tail", "/usr/bin/tail -f /Applications/Google Chrome.app/Contents/MacOS/Google Chrome", false},
} {
- if got := everydayChromeCommand(args); got != want {
- t.Errorf("%q: %v, want %v", args, got, want)
+ if got := everydayChromeProcess(tc.path, tc.args); got != tc.want {
+ t.Errorf("%q %q: %v, want %v", tc.path, tc.args, got, tc.want)
}
}
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
index 575ba505..069f6291 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
@@ -634,7 +634,9 @@ func countTabs(tree string) int {
// A tab holds its Close button, whose name follows the user's
// language, so any button inside it counts.
for j, next := range rows[i+1:] {
- if j > 0 && indent(next) <= indent(row) {
+ // The next row may be the button beside the tab, at its
+ // level; a row above that level, such as New Tab, is not.
+ if j > 0 && indent(next) <= indent(row) || indent(next) < indent(row) {
break
}
if trimmed := strings.TrimSpace(next); strings.Contains(trimmed, "] AXButton") && strings.HasSuffix(trimmed, "[actions=[press]]") {
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.go
index 86fb750f..8a2fc9d0 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua.go
@@ -223,7 +223,7 @@ const MacToolGuide = `Computer tools on this Mac (MCP server "computer"):
- report_blocker({kind, url}) as soon as a page in the Computer's own browser shows a check only the user may pass (captcha, verification, login_required, rate_limited) or one item that cannot be viewed (content_unavailable). Never try to pass the check.
The Computer's own browser takes input at a person's pace, within a budget per task and per day, and a script there sends at most 20 inputs: return what you have and look at the window before the next script. A tab that a link in the script opens is the task's and is in front afterwards. The browser tools stay off every site a task opened in that browser.
Plan as many steps as you can in one run_actions call, as in one script; its read shows their effect, so do not read again before the next input unless you need another window. Keys are often shorter than clicks: in Finder, cmd+shift+g then a path and Return opens a folder, cmd+down opens the selected item, and in the Trash cmd+delete puts the selected item back.
-In Chrome, launch_app({bundle_id: "com.google.Chrome", urls: [url]}) opens a URL in a new tab without bringing Chrome forward; its pages read as empty while the window is covered or on another Space. Add agent_browser: true to use the Computer's own browser window instead: it keeps working while covered, but not on another desktop (Space). Chrome's own toolbar, such as Back and the address bar, refuses background input. The user's everyday Chrome takes no shortcut, typed text or unbound key in any window; only one plain key bound to an element of the Computer's window, such as Return in its search box, goes. Fill fields with set_value, press the page's buttons, and go back through its links. In Edge or Firefox press escape to close a page overlay, or hotkey cmd+[ to go back. A web control that ignores a background click, such as an option in a menu that opens on hover, takes one click with delivery_mode "foreground" at x,y of a screenshot.
+In Chrome, launch_app({bundle_id: "com.google.Chrome", urls: [url]}) opens a URL in a new tab without bringing Chrome forward; its pages read as empty while the window is covered or on another Space. Add agent_browser: true to use the Computer's own browser window instead: it keeps working while covered, but not on another desktop (Space). Chrome's own toolbar, such as Back and the address bar, refuses background input. The user's everyday Chrome takes no shortcut, typed text or unbound key in any window; only one plain key bound to an element of the Computer's window, such as Return in its search box, goes, and never from run_script. Fill fields with set_value, press the page's buttons, and go back through its links. In Edge or Firefox press escape to close a page overlay, or hotkey cmd+[ to go back. A web control that ignores a background click, such as an option in a menu that opens on hover, takes one click with delivery_mode "foreground" at x,y of a screenshot.
A menu item in the read, such as File > Put Back, can be clicked directly; do not click a menu bar title first, because an open menu holds the app until it closes. A right_click menu does not show in the read, so select the row with click and use the menu bar item or its keyboard shortcut.
Before the first shell screenshot, or when one fails or comes back blank, run ` + "`teamhub computer permissions status`" + `; if Screen Recording is missing for Linger, run ` + "`teamhub computer permissions request --permissions screen_recording`" + ` and end your turn — the card wakes you. Never operate System Settings or privacy prompts yourself.
` + browserToolGuide
@@ -452,7 +452,7 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
if err != nil {
return nil, err
}
- if err := scriptArguments(ctx, arguments, c.reviewScope(), scriptInputs, chrome); err != nil {
+ if err := scriptArguments(ctx, arguments, c.reviewScope(), scriptInputs, chrome.PID); err != nil {
return nil, err
}
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_script.go b/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
index d36768b4..460938d6 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
@@ -69,11 +69,12 @@ var scriptForbidden = []string{"delivery_mode", "foreground", "screenshot_out_fi
// Computer's own browser: the guard waits a person's pause before each input,
// throws once the script tries to send more than inputLimit inputs, and
// refuses launch_app, whose site checks run only in the Daemon's own call.
-// While the user's everyday Chrome runs as chrome.PID, the guard refuses
-// every key to it, and a key that names no app, by the rule of
-// everydayChromeKeys: only one plain press_key bound to an element token in
-// the Computer's window chrome.Window goes.
-func guardedScript(args, body string, deadline int64, inputLimit int, chrome sharedWindow) string {
+// While the user's everyday Chrome runs as chrome, the guard refuses every
+// key to it and every key that names no app: a script cannot prove which
+// window an element token was read from, so even the one key a tool call
+// may send there (see everydayChromeKeys) is refused. It also refuses to
+// start Chrome, whose pid the guard would not know.
+func guardedScript(args, body string, deadline int64, inputLimit int, chrome int) string {
pattern := make([]string, 0, len(scriptForbidden))
for _, word := range scriptForbidden {
pattern = append(pattern, regexp.QuoteMeta(word))
@@ -84,12 +85,11 @@ const keys = Object.keys, names = Object.getOwnPropertyNames, proto = Object.get
const apply = Reflect.apply, stringify = JSON.stringify, parse = JSON.parse, test = RegExp.prototype.test, then = Promise.prototype.then;
const plainProtos = [Object.prototype, Array.prototype, null], real = globalThis.cua;
const bad = /`+strings.Join(pattern, "|")+`/;
-const limit = `+strconv.Itoa(inputLimit)+`, chrome = `+strconv.Itoa(chrome.PID)+`, own = `+strconv.FormatFloat(chrome.Window, 'f', -1, 64)+`, rest = real.sleep, random = Math.random, floor = Math.floor; let sent = 0;
-const plainKey = (key, token, win) => typeof key === "string" && key.indexOf("+") < 0 && typeof token === "string" && own !== 0 && win === own;
-const keyed = (k, c, o) => { if (chrome === 0) return false;
-if (k === "call") { if (c[0] !== "hotkey" && c[0] !== "type_text" && c[0] !== "press_key") return false; const a = c[1] !== null && typeof c[1] === "object" ? c[1] : {};
-if (typeof a.pid !== "number") return true; if (a.pid !== chrome) return false; return !(c[0] === "press_key" && a.modifiers === undefined && plainKey(a.key, a.element_token, a.window_id)); }
-if (k !== "hotkey" && k !== "typeText" && k !== "pressKey") return false; if (o.pid !== chrome) return false; return !(k === "pressKey" && c.length === 2 && plainKey(c[0], c[1], o.windowId)); };
+const limit = `+strconv.Itoa(inputLimit)+`, chrome = `+strconv.Itoa(chrome)+`, rest = real.sleep, random = Math.random, floor = Math.floor; let sent = 0;
+const keyOps = {__proto__: null, hotkey: true, type_text: true, press_key: true}, keyMethods = {__proto__: null, hotkey: true, typeText: true, pressKey: true};
+const keyed = (k, c, o) => chrome > 0 && (k === "call" ? keyOps[c[0]] === true && (c[1] === null || typeof c[1] !== "object" || typeof c[1].pid !== "number" || c[1].pid === chrome) : keyMethods[k] === true && o.pid === chrome);
+const namesChrome = v => v === "Google Chrome" || v === "com.google.Chrome" || v !== null && typeof v === "object" && (v.name === "Google Chrome" || v.bundle_id === "com.google.Chrome" || v.bundleId === "com.google.Chrome");
+const startsChrome = (k, c) => k === "launchApp" && namesChrome(c[0]) || k === "call" && c[0] === "launch_app" && namesChrome(c[1]);
const inputMethods = {__proto__: null, click: true, doubleClick: true, rightClick: true, drag: true, scroll: true, typeText: true, pressKey: true, hotkey: true, setValue: true};
const inputOps = {__proto__: null, click: true, double_click: true, right_click: true, drag: true, scroll: true, type_text: true, press_key: true, hotkey: true, set_value: true};
const input = (k, c) => inputMethods[k] === true || k === "call" && typeof c[0] === "string" && inputOps[c[0]] === true;
@@ -106,6 +106,7 @@ if (limit > 0 && k === "typeText") { const given = c.length > 2 && c[2] !== null
if (limit > 0 && k === "sleep" && o === real && typeof c[0] === "number" && c[0] > `+strconv.Itoa(scriptSleepLimit)+`) { const t = {length: 1}; define(t, 0, {value: `+strconv.Itoa(scriptSleepLimit)+`}); c = t; }
const run = () => { const r = apply(v, o, c); return r !== null && typeof r === "object" && typeof r.then === "function" ? apply(then, r, [out]) : out(r); };
if (limit > 0 && (k === "launchApp" || k === "call" && c[0] === "launch_app")) throw new Error("COMPUTER_SCRIPT_REFUSED: a script in the Computer's own browser opens no app or URL, so the site checks of launch_app hold; call launch_app as its own tool");
+if (startsChrome(k, c)) throw new Error("COMPUTER_SCRIPT_REFUSED: a script does not start Google Chrome; call launch_app as its own tool");
if (keyed(k, c, o)) throw new Error(`+strconv.Quote(everydayChromeKeysRefused)+`);
if (limit <= 0 || !input(k, c)) return run();
if (++sent > limit) throw new Error("COMPUTER_SCRIPT_INPUT_LIMIT: a script sends at most " + limit + " inputs to the Computer's own browser; return what you have, look at the window, then continue in a new script");
@@ -145,7 +146,7 @@ func forbiddenKey(value any, word string) bool {
// into what remains of the call after waiting for the desktop lane. In a
// reviewed Run, whose review scope is not empty, a script file runs only as
// the judge allowed it in that scope: the body it read and the args it saw.
-func scriptArguments(ctx context.Context, arguments map[string]any, reviewScope string, inputLimit int, chrome sharedWindow) error {
+func scriptArguments(ctx context.Context, arguments map[string]any, reviewScope string, inputLimit int, chrome int) error {
for key := range arguments {
switch key {
case "script", "script_file", "args", "timeout_ms", "max_calls":
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_script_guard_test.go b/apps/computer/local-daemon/internal/linger/localtools/cua_script_guard_test.go
index 361045f9..970663b8 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_script_guard_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_script_guard_test.go
@@ -55,7 +55,7 @@ func TestScriptGuardRefusesForbiddenInputInAJSEngine(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
script := filepath.Join(dir, "script.js")
- if err := os.WriteFile(script, []byte(guardedScript(`{"n":1}`, tc.body, 42, 0, sharedWindow{})), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{"n":1}`, tc.body, 42, 0, 0)), 0o600); err != nil {
t.Fatal(err)
}
out, err := exec.Command(node, harness, script).CombinedOutput()
@@ -84,7 +84,7 @@ func TestScriptGuardPacesInputsForTheComputersChrome(t *testing.T) {
if err := os.WriteFile(harness, []byte(guardHarness), 0o600); err != nil {
t.Fatal(err)
}
- if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, 2, sharedWindow{})), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, 2, 0)), 0o600); err != nil {
t.Fatal(err)
}
out, err := exec.Command(node, harness, script).CombinedOutput()
@@ -112,7 +112,7 @@ func TestScriptGuardSpeedsTypingAndCapsWaits(t *testing.T) {
if err := os.WriteFile(harness, []byte(guardHarness), 0o600); err != nil {
t.Fatal(err)
}
- if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, 20, sharedWindow{})), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, 20, 0)), 0o600); err != nil {
t.Fatal(err)
}
out, err := exec.Command(node, harness, script).CombinedOutput()
@@ -145,7 +145,7 @@ func TestScriptGuardRefusesLaunchAppForTheComputersChrome(t *testing.T) {
want string
}{{2, "threw:COMPUTER_SCRIPT_REFUSED"}, {0, "call:launch_app"}} {
script := filepath.Join(dir, "script.js")
- if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, tc.limit, sharedWindow{})), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, tc.limit, 0)), 0o600); err != nil {
t.Fatal(err)
}
out, err := exec.Command(node, harness, script).CombinedOutput()
@@ -170,7 +170,8 @@ func TestScriptGuardRefusesKeysForTheEverydayChrome(t *testing.T) {
if err := os.WriteFile(harness, []byte(guardHarness), 0o600); err != nil {
t.Fatal(err)
}
- // The user's Chrome runs as pid 1, and the Computer's window there is 12.
+ // The user's Chrome runs as pid 1. A script cannot tell which window a
+ // token was read from, so it sends that Chrome no key at all.
for _, tc := range []struct{ body, want string }{
{`return await cua.call("hotkey", {pid: 1, window_id: 12, keys: ["cmd", "["]});`, "threw:COMPUTER_KEYS_REFUSED"},
{`return await cua.call("hotkey", {keys: ["cmd", "w"]});`, "threw:COMPUTER_KEYS_REFUSED"},
@@ -178,21 +179,14 @@ func TestScriptGuardRefusesKeysForTheEverydayChrome(t *testing.T) {
{`const app = await cua.getApp({pid: 1, windowId: 12}); return app.typeText("kettle", "s1:2");`, "threw:COMPUTER_KEYS_REFUSED"},
{`const app = await cua.getApp({pid: 1, windowId: 9}); return app.hotkey(["cmd", "w"]);`, "threw:COMPUTER_KEYS_REFUSED"},
{`const app = await cua.getApp({pid: 2, windowId: 5}); return app.hotkey(["cmd", "s"]);`, "hotkeyed"},
- {`return await cua.call("press_key", {pid: 1, window_id: 12, key: "return"});`, "threw:COMPUTER_KEYS_REFUSED"},
- {`return await cua.call("press_key", {pid: 1, window_id: 12, key: "return", element_token: "s1:2", modifiers: ["cmd"]});`, "threw:COMPUTER_KEYS_REFUSED"},
- {`return await cua.call("press_key", {pid: 1, window_id: 12, key: "return", element_token: "s1:2", modifiers: []});`, "threw:COMPUTER_KEYS_REFUSED"},
- {`return await cua.call("press_key", {pid: 1, window_id: 12, key: "cmd+r", element_token: "s1:2"});`, "threw:COMPUTER_KEYS_REFUSED"},
- {`return await cua.call("press_key", {pid: 1, window_id: 9, key: "return", element_token: "s1:2"});`, "threw:COMPUTER_KEYS_REFUSED"},
- {`return await cua.call("press_key", {pid: 1, window_id: 12, key: "return", element_token: "s1:2"});`, "call:press_key"},
- {`const app = await cua.getApp({pid: 1, windowId: 12}); return app.pressKey("cmd+r", "s1:2");`, "threw:COMPUTER_KEYS_REFUSED"},
- {`const app = await cua.getApp({pid: 1, windowId: 12}); return app.pressKey("return");`, "threw:COMPUTER_KEYS_REFUSED"},
- {`const app = await cua.getApp({pid: 1, windowId: 12}); return app.pressKey("return", [3, 4]);`, "threw:COMPUTER_KEYS_REFUSED"},
- {`const app = await cua.getApp({pid: 1, windowId: 9}); return app.pressKey("return", "s1:2");`, "threw:COMPUTER_KEYS_REFUSED"},
- {`const app = await cua.getApp({pid: 1, windowId: 12}); return app.pressKey("return", "s1:2");`, "pressed"},
+ {`return await cua.call("press_key", {pid: 1, window_id: 12, key: "return", element_token: "s1:2"});`, "threw:COMPUTER_KEYS_REFUSED"},
+ {`const app = await cua.getApp({pid: 1, windowId: 12}); return app.pressKey("return", "s1:2");`, "threw:COMPUTER_KEYS_REFUSED"},
+ {`const app = await cua.getApp({pid: 2, windowId: 5}); return app.pressKey("return", "s1:2");`, "pressed"},
{`return await cua.call("click", {pid: 1, element_token: "s1:2"});`, "call:click"},
+ {`return await cua.call("launch_app", {bundle_id: "com.google.Chrome"});`, "threw:COMPUTER_SCRIPT_REFUSED"},
} {
script := filepath.Join(dir, "script.js")
- if err := os.WriteFile(script, []byte(guardedScript(`{}`, tc.body, 42, 20, sharedWindow{PID: 1, Window: 12})), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, tc.body, 42, 20, 1)), 0o600); err != nil {
t.Fatal(err)
}
out, err := exec.Command(node, harness, script).CombinedOutput()
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_script_test.go b/apps/computer/local-daemon/internal/linger/localtools/cua_script_test.go
index 68c9ff1b..850abd6a 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_script_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_script_test.go
@@ -16,22 +16,22 @@ import (
func TestScriptArgumentsBoundTheScript(t *testing.T) {
arguments := map[string]any{"script": "return 1;"}
- if err := scriptArguments(context.Background(), arguments, "", 0, sharedWindow{}); err != nil || arguments["timeout_ms"] != float64(scriptTimeoutMs) {
+ if err := scriptArguments(context.Background(), arguments, "", 0, 0); err != nil || arguments["timeout_ms"] != float64(scriptTimeoutMs) {
t.Fatalf("default: %v %v", err, arguments)
}
arguments = map[string]any{"script": "return 1;", "timeout_ms": float64(500000)}
- if err := scriptArguments(context.Background(), arguments, "", 0, sharedWindow{}); err != nil || arguments["timeout_ms"] != float64(scriptMaxTimeoutMs) {
+ if err := scriptArguments(context.Background(), arguments, "", 0, 0); err != nil || arguments["timeout_ms"] != float64(scriptMaxTimeoutMs) {
t.Fatalf("cap: %v %v", err, arguments)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
arguments = map[string]any{"script": "return 1;", "timeout_ms": float64(90000)}
- if err := scriptArguments(ctx, arguments, "", 0, sharedWindow{}); err != nil || arguments["timeout_ms"].(float64) > 45000 {
+ if err := scriptArguments(ctx, arguments, "", 0, 0); err != nil || arguments["timeout_ms"].(float64) > 45000 {
t.Fatalf("deadline: %v %v", err, arguments)
}
late, stop := context.WithTimeout(context.Background(), 10*time.Second)
defer stop()
- if err := scriptArguments(late, map[string]any{"script": "return 1;"}, "", 0, sharedWindow{}); !errors.Is(err, errNotSent) {
+ if err := scriptArguments(late, map[string]any{"script": "return 1;"}, "", 0, 0); !errors.Is(err, errNotSent) {
t.Fatalf("late: %v", err)
}
for _, refused := range []map[string]any{
@@ -40,7 +40,7 @@ func TestScriptArgumentsBoundTheScript(t *testing.T) {
{"script": `await cua.call("click", {pid: 1, x: 2, y: 3, delivery_mode: "foreground"})`},
{"script": `await app.getState({screenshot_out_file: "/tmp/a.png"})`},
} {
- if err := scriptArguments(context.Background(), refused, "", 0, sharedWindow{}); !errors.Is(err, errNotSent) {
+ if err := scriptArguments(context.Background(), refused, "", 0, 0); !errors.Is(err, errNotSent) {
t.Fatalf("%v: got %v", refused, err)
}
}
@@ -56,7 +56,7 @@ func TestScriptArgumentsReadASkillScriptWithArgs(t *testing.T) {
t.Fatal(err)
}
arguments := map[string]any{"script_file": file, "args": map[string]any{"pid": float64(7)}}
- if err := scriptArguments(context.Background(), arguments, "", 0, sharedWindow{}); err != nil {
+ if err := scriptArguments(context.Background(), arguments, "", 0, 0); err != nil {
t.Fatal(err)
}
script, _ := arguments["script"].(string)
@@ -70,19 +70,19 @@ func TestScriptArgumentsReadASkillScriptWithArgs(t *testing.T) {
{"script": `return cua.call("click", {delivery_mode: "foreground"});`},
{"script_file": file, "args": map[string]any{"click": []any{map[string]any{"delivery_mode": "foreground"}}}},
} {
- if err := scriptArguments(context.Background(), refused, "", 0, sharedWindow{}); !errors.Is(err, errNotSent) {
+ if err := scriptArguments(context.Background(), refused, "", 0, 0); !errors.Is(err, errNotSent) {
t.Fatalf("%v: got %v", refused, err)
}
}
// args carry page and user text, which may name a forbidden option.
- if err := scriptArguments(context.Background(), map[string]any{"script_file": file, "args": map[string]any{"text": "in the foreground"}}, "", 0, sharedWindow{}); err != nil {
+ if err := scriptArguments(context.Background(), map[string]any{"script_file": file, "args": map[string]any{"text": "in the foreground"}}, "", 0, 0); err != nil {
t.Fatalf("user text in args: %v", err)
}
// A reviewed Run runs a script file only as a review allowed it.
- if err := scriptArguments(context.Background(), map[string]any{"script_file": file, "args": map[string]any{"pid": float64(7)}}, permission.ScriptScope("agent-1", "context-1"), 0, sharedWindow{}); !errors.Is(err, errNotSent) || !strings.Contains(err.Error(), "COMPUTER_SCRIPT_REFUSED") {
+ if err := scriptArguments(context.Background(), map[string]any{"script_file": file, "args": map[string]any{"pid": float64(7)}}, permission.ScriptScope("agent-1", "context-1"), 0, 0); !errors.Is(err, errNotSent) || !strings.Contains(err.Error(), "COMPUTER_SCRIPT_REFUSED") {
t.Fatalf("unreviewed script file in a reviewed Run: %v", err)
}
- if err := scriptArguments(context.Background(), map[string]any{"script": "return 1;"}, permission.ScriptScope("agent-1", "context-1"), 0, sharedWindow{}); err != nil {
+ if err := scriptArguments(context.Background(), map[string]any{"script": "return 1;"}, permission.ScriptScope("agent-1", "context-1"), 0, 0); err != nil {
t.Fatalf("inline script in a reviewed Run: %v", err)
}
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
index c671c5a2..94ebf538 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
@@ -1993,12 +1993,12 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *t
t.Fatalf("set_value: %v", err)
}
// Any script, whatever it targets, is guarded against keys to the
- // user's Chrome, with the Computer's window 12 as the one exception.
+ // user's Chrome.
for _, script := range []string{`{"script":"return 1"}`, `{"script":"return 1","args":{"pid":42,"window_id":9}}`, `{"script":"return 1","args":{"pid":7}}`} {
if _, err := c.call(t.Context(), "run_script", json.RawMessage(script)); err != nil {
t.Fatal(err)
}
- if calls := fixtureCalls(t, marker); !strings.Contains(fmt.Sprint(calls[len(calls)-1]), "chrome = 42, own = 12") {
+ if calls := fixtureCalls(t, marker); !strings.Contains(fmt.Sprint(calls[len(calls)-1]), "chrome = 42,") {
t.Fatalf("%s: last call=%v, want a script guarded against keys", script, calls[len(calls)-1])
}
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/manager.go b/apps/computer/local-daemon/internal/linger/localtools/manager.go
index 578e1788..9ea9d4f6 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/manager.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/manager.go
@@ -122,7 +122,9 @@ func New(options Options) (*Manager, error) {
if err := m.openBrowserJournals(); err != nil {
return nil, err
}
- retireAgentChromeProfile(options.StateDirectory)
+ // Quitting a Chrome still on the old profile may take seconds, so
+ // it does not hold up the start.
+ go retireAgentChromeProfile(options.StateDirectory)
}
return m, nil
}