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, not even a bound Return
jeffrey0d7a68229ab6
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.mdindex e2f4c423..ffe80145 100644--- a/apps/computer/local-daemon/README.md+++ b/apps/computer/local-daemon/README.md@@ -350,12 +350,11 @@ executable wherever the app is installed. The user's Chrome takes no keys fromthe Computer (`COMPUTER_KEYS_REFUSED`), in any of its windows, in tool calls,`run_actions` steps, paged `recognize_text` reads and scripts: a shortcutruns 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, 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. It refuses a key whose arguments+types text as keys that all read as the A key. A key named by its+`element_token` goes to the app the token was read from, and a key that names+no app is refused while that Chrome runs. Not even Return bound to a search box goes: Cua refuses a+background key while its app has another window, and the user's Chrome always+has one. A script's guard refuses a key whose argumentsname an app or window of their own, and no script opens an app or URL, so thekey rule knows every app a script reaches.The Agent fills fields withdiff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.goindex c1dad55a..0a2bc5ba 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go@@ -614,87 +614,55 @@ func (m *Manager) sharedWindowOf(pid int) (sharedWindow, bool) {return sharedWindow{}, false}-// userChromeWindow returns the pid of the user's everyday Chrome, or 0 when-// it does not run, and the windows the Computer opened as its own there.-// Chrome is looked up on each call, so the key rule holds before the-// Computer opened a window and after Chrome restarts.-func (c *cuaSession) userChromeWindow(ctx context.Context) (sharedWindow, error) {+// userChromePID returns the pid of the user's everyday Chrome, or 0 when it+// does not run. Chrome is looked up on each call, so the key rule holds before+// the Computer opened a window and after Chrome restarts.+func userChromePID(ctx context.Context) (int, error) {if runtime.GOOS != "darwin" {- return sharedWindow{}, nil+ return 0, nil}pid, _, err := everydayChromePID(ctx)if err != nil {- return sharedWindow{}, fmt.Errorf("COMPUTER_INPUT_NOT_SENT: could not tell whether the user's Chrome runs: %w: %w", err, errNotSent)+ return 0, fmt.Errorf("COMPUTER_INPUT_NOT_SENT: could not tell whether the user's Chrome runs: %w: %w", err, errNotSent)}- m := c.op.manager- m.mu.Lock()- own := m.sharedWindows["com.google.Chrome"]- m.mu.Unlock()- if pid == 0 || own.PID != pid {- own.Windows = nil- }- own.PID = pid- return own, nil+ return pid, nil}// userChromeKeys refuses a key tool, or a paged read, that reaches the user's-// everyday Chrome. A key goes to the Chrome window that has the keyboard, so-// the window is the one the element_token was read from, not the one named,-// and a key that names no app is refused while that Chrome runs.-func (c *cuaSession) userChromeKeys(ctx context.Context, name string, arguments map[string]any, paged bool) error {- chrome, err := c.userChromeWindow(ctx)- if err != nil || chrome.PID == 0 {+// everyday Chrome, in any of its windows. A key named by its element_token+// goes to the app the token was read from, and a key that names no app is+// refused while that Chrome runs.+func (c *cuaSession) userChromeKeys(ctx context.Context, arguments map[string]any) error {+ chrome, err := userChromePID(ctx)+ if err != nil || chrome == 0 {return err}- pid, window := arguments["pid"], arguments["window_id"]+ pid := arguments["pid"]if token, ok := arguments["element_token"].(string); ok {- // A token the Computer did not see read cannot be placed in a- // window, so it is not taken for one in the Computer's window. Cua- // refuses a token read from another pid than the one named, so a- // token cannot carry a key into another app.- window = nil+ // Cua refuses a token read from another pid than the one named, so+ // the token's own app is the one the key reaches.if key, found := c.op.reads.window(token); found {- pid, window = float64(key.pid), float64(key.window)+ pid = float64(key.pid)}}number, ok := pid.(float64)if !ok {return fmt.Errorf("COMPUTER_TARGET_REQUIRED: while the user's Chrome runs, a key names its app by pid, so it cannot reach Chrome unseen: %w", errNotSent)}- if int(number) != chrome.PID {+ if int(number) != chrome {return nil}- if paged {- return fmt.Errorf("%s: %w", everydayChromeKeysRefused, errNotSent)- }- id, named := window.(float64)- return everydayChromeKeys(name, arguments, named && slices.Contains(chrome.Windows, id))+ return fmt.Errorf("%s: %w", everydayChromeKeysRefused, errNotSent)}// everydayChromeKeysRefused tells the Agent how to work without keys in the-// user's everyday Chrome.+// user's everyday Chrome. Shortcuts are menu commands, which Chrome runs in+// the window that has the keyboard, typed text arrives as keys that all read+// as the A key, and Cua refuses even a key bound to an element while Chrome+// has another window, which the user's Chrome always has. The script guard+// (keyed in guardedScript) applies the same rule.const everydayChromeKeysRefused = "COMPUTER_KEYS_REFUSED: the user's everyday Chrome takes no keys from the Computer: a key or shortcut goes to the Chrome window that has the keyboard, which may be the one the user is typing in; nothing was sent. Fill a field with set_value, press the page's own buttons, such as its search button, and go back through the page's links"-// everydayChromeKeys refuses keys to the user's everyday Chrome. Only one-// plain key bound to an element, such as Return in a search box, may go:-// Cua delivers it only when no other Chrome window could receive it.-// Shortcuts are menu commands, which Chrome runs in the window that has the-// keyboard, and typed text arrives as keys that all read as the A key. own-// says the key names the Computer's window; one of the user's windows takes-// none. The script guard (keyed in guardedScript) applies the same rule.-func everydayChromeKeys(name string, arguments map[string]any, own bool) error {- if name != "hotkey" && name != "type_text" && name != "press_key" {- return nil- }- _, bound := arguments["element_token"].(string)- _, modified := arguments["modifiers"]- key, plain := arguments["key"].(string)- if own && name == "press_key" && bound && !modified && plain && !strings.Contains(key, "+") {- return nil- }- return fmt.Errorf("%s: %w", everydayChromeKeysRefused, errNotSent)-}-// everydayChromeData is the user's Chrome data folder, whose Local State// names the profile Chrome last used.var everydayChromeData = func() string {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.goindex 251334b8..343877de 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@@ -65,32 +65,6 @@ func TestEverydayChromeProcessFindsChromeInAnyFolder(t *testing.T) {}}-func TestEverydayChromeKeysAllowOnlyOnePlainBoundKey(t *testing.T) {- for _, tc := range []struct {- name string- arguments map[string]any- allowed bool- }{- {"press_key", map[string]any{"key": "return", "element_token": "s1:1"}, true},- {"set_value", map[string]any{"value": "kettle", "element_token": "s1:1"}, true},- {"press_key", map[string]any{"key": "return"}, false},- {"press_key", map[string]any{"key": "return", "element_token": "s1:1", "modifiers": []any{}}, false},- {"press_key", map[string]any{"key": "return", "element_token": "s1:1", "modifiers": "cmd"}, false},- {"press_key", map[string]any{"key": "cmd+r", "element_token": "s1:1"}, false},- {"press_key", map[string]any{"key": 13.0, "element_token": "s1:1"}, false},- {"hotkey", map[string]any{"keys": []any{"cmd", "["}}, false},- {"type_text", map[string]any{"text": "kettle", "element_token": "s1:1"}, false},- } {- if err := everydayChromeKeys(tc.name, tc.arguments, true); (err == nil) != tc.allowed {- t.Errorf("%s %v: err=%v, want allowed=%v", tc.name, tc.arguments, err, tc.allowed)- }- }- // One of the user's windows takes no key at all.- if err := everydayChromeKeys("press_key", map[string]any{"key": "return", "element_token": "s1:1"}, false); err == nil {- t.Error("a bound Return went to one of the user's windows")- }-}-func TestSharedWindowsKeepEveryWindowOfTheBrowser(t *testing.T) {m := &Manager{}m.setSharedWindow("com.google.Chrome", 42, 11)diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.goindex 089debe6..afc52b4a 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, and never from run_script. Fill fields with set_value, press the page's buttons, and go back through its links. In Safari, 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 key in any window, not even Return in a search box. Fill fields with set_value, press the page's buttons, and go back through its links. In Safari, 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@@ -398,7 +398,7 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage// A key to the user's Chrome reaches the window that has the keyboard,// whichever window it names, so it is refused before anything is taken.if name == "hotkey" || name == "type_text" || name == "press_key" || paged {- if err := c.userChromeKeys(ctx, name, arguments, paged); err != nil {+ if err := c.userChromeKeys(ctx, arguments); err != nil {return nil, err}}@@ -448,11 +448,11 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessageif name == "run_script" {// A script's body may reach any app, so its guard checks every key// against the user's Chrome, whatever window args names.- chrome, err := c.userChromeWindow(ctx)+ chrome, err := userChromePID(ctx)if err != nil {return nil, err}- if err := scriptArguments(ctx, arguments, c.reviewScope(), scriptInputs, chrome.PID); err != nil {+ if err := scriptArguments(ctx, arguments, c.reviewScope(), scriptInputs, chrome); err != nil {return nil, err}}diff --git a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.goindex 480c9f8a..3bfbe612 100644--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go@@ -1950,16 +1950,10 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *tt.Fatalf("the user's own Chrome window %v read as the Computer's", user)}}- // Token s1 was read from the Computer's window 12, so only the rule for- // keys refuses what follows with it.- c.op.reads.mu.Lock()- if c.op.reads.snapshots == nil {- c.op.reads.windows, c.op.reads.snapshots = map[windowKey]*windowRows{}, map[string]windowKey{}- }- c.op.reads.snapshots["s1"] = windowKey{pid: 42, window: 12}- c.op.reads.mu.Unlock()- // No key reaches the user's Chrome, in the Computer's window or theirs.+ // No key reaches the user's Chrome, in the Computer's window or theirs,+ // not even Return bound to a field of the Computer's window.for _, call := range []struct{ name, args string }{+ {"press_key", `{"pid":42,"window_id":12,"key":"return","element_token":"s1:1"}`},{"hotkey", `{"pid":42,"window_id":12,"keys":["cmd","["]}`},{"hotkey", `{"pid":42,"window_id":9,"keys":["cmd","w"]}`},{"type_text", `{"pid":42,"window_id":12,"text":"kettle","element_token":"s1:1"}`},@@ -1968,9 +1962,7 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *t{"press_key", `{"pid":42,"window_id":12,"key":"cmd+r","element_token":"s1:1"}`},{"press_key", `{"pid":42,"window_id":9,"key":"return","element_token":"s9:1"}`},{"recognize_text", `{"pid":42,"window_id":12,"pages":2,"next_key":"pagedown"}`},- // A token read from the user's window 9 places the key there,- // whatever window_id names; one never read places it nowhere.- {"press_key", `{"pid":42,"window_id":12,"key":"return","element_token":"s9:1"}`},+ // A token never read leaves the named pid.{"press_key", `{"pid":42,"key":"return","element_token":"s7:1"}`},} {c.op.reads.mu.Lock()@@ -1990,9 +1982,6 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *tif _, err := c.call(t.Context(), "hotkey", json.RawMessage(`{"keys":["cmd","w"],"element_token":"s7:1"}`)); !strings.Contains(fmt.Sprint(err), "COMPUTER_TARGET_REQUIRED") {t.Fatalf("hotkey with no pid: err=%v, want refused", err)}- if _, err := c.call(t.Context(), "press_key", json.RawMessage(`{"pid":42,"window_id":12,"key":"return","element_token":"s1:1"}`)); err != nil {- t.Fatalf("Return bound to a field: %v", err)- }if _, err := c.call(t.Context(), "set_value", json.RawMessage(`{"pid":42,"window_id":12,"value":"kettle","element_token":"s1:1"}`)); err != nil {t.Fatalf("set_value: %v", err)}diff --git a/skills/builtin/humanlike-browse/1.0.5/SKILL.md b/skills/builtin/humanlike-browse/1.0.5/SKILL.mdindex 4fd77b2f..2d5e043c 100644--- a/skills/builtin/humanlike-browse/1.0.5/SKILL.md+++ b/skills/builtin/humanlike-browse/1.0.5/SKILL.md@@ -32,7 +32,7 @@ The user watches the window, and each turn of yours costs seconds. The Computer- Browse in this conversation yourself. Do not hand the browsing to a background Task: starting one adds a minute, and the user watches this Room.- Put each page visit in one `run_script`: search, wait, read what you need, open the item, wait, read it, go back. Return to the model only to choose something, such as which items to open.- Fill a search box with `setValue`, then click the site's search button. Return on the box also works in Safari, Edge and Firefox.-- The user's Chrome takes no keys from the Computer: a key could reach the Chrome window the user is typing in. There, never use `typeText`, `hotkey` or a key without an element; only Return bound to the search box of the Computer's window goes, as its own `press_key` call and never inside `run_script`, and only while no other Chrome window could take it.+- The user's Chrome takes no keys from the Computer: a key could reach the Chrome window the user is typing in. There, never use `typeText`, `hotkey` or `pressKey`, not even Return in the search box.- After a click that loads something, wait with `app.waitFor` for what the next page shows, such as a heading or a button, with `timeout_ms` about 8000. Never wait with `cua.sleep`; one sleep lasts at most 1.5 s there.- Read only what you need: `app.query({role, name})`, `getState({query})` or `get_window_state` with `query`. Read the whole tree only to find your way on a page you have not seen.