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.

feat(computer): browse watched sites in a window of the user's everyday Chrome

jeffrey274c4446fc49
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index 609f66e3..5e3fd806 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -323,13 +323,29 @@ profile directory, stored under `computer-tools/browser-profiles/` in the state
directory. Cua can observe the native Chrome window that Playwright connects to.
On macOS, `launch_app` with `agent_browser: true` opens the Computer's own
-browser for a site that watches for automated browsers. The Agent drives it
-only with the computer tools, never through Playwright or a debugging port.
-Chrome, Edge and Firefox each run as a separate instance with their own
-profile under `computer-tools/agent-<browser>` in the state directory, so the
-user signs in there once. Safari cannot run a second profile; the Computer
-uses its own window in the user's Safari. Without a `bundle_id`, the Daemon
-picks the first installed of Chrome, Edge, Firefox and Safari.
+browser window for a site that watches for automated browsers. The Agent drives
+it only with the computer tools, never through Playwright or a debugging port.
+In Chrome it is a window of the Computer's own in the user's everyday Chrome,
+with the user's sign-ins, history and device trust. The window opens through
+Chrome's command line, one site per call, so no key reaches the user's other
+windows. A covered window keeps working only when Chrome runs with
+`--disable-backgrounding-occluded-windows`: a Chrome that is not running
+starts with it, and one running without it returns
+`COMPUTER_BROWSER_RESTART_REQUIRED` until the Agent passes `restart_browser`
+after the user agreed. The restart quits Chrome as its menu does and reopens it
+with `--restore-last-session`. The user's Chrome takes no keys from the
+Computer (`COMPUTER_KEYS_REFUSED`): 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. Only a plain key bound to an element goes, and Cua sends it only
+when no other Chrome window could take it. The Agent fills fields with
+`set_value`, presses the page's buttons and goes back through its links.
+The separate Chrome profile earlier versions used, `computer-tools/agent-chrome`,
+is removed when the Daemon starts and that Chrome no longer runs.
+Edge and Firefox each run as a separate instance with their own profile under
+`computer-tools/agent-<browser>` in the state directory, so the user signs in
+there once. Safari cannot run a second profile; the Computer uses its own
+window in the user's Safari. Without a `bundle_id`, the Daemon picks the first
+installed of Chrome, Edge, Firefox and Safari.
It opens a site only at its home page and refuses any other web address with
`COMPUTER_HOME_PAGE_ONLY`: the Agent reaches a search, listing or item through
the site's own search box, menus and links, as a person does.
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 fa0d2cdd..fb19efe7 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
@@ -10,7 +10,9 @@ import (
"os/exec"
"path/filepath"
"slices"
+ "strconv"
"strings"
+ "syscall"
"time"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/platform/privatefs"
@@ -44,6 +46,11 @@ type agentBrowser struct {
// Safari does: it has no separate profile, so the Computer works in a
// window of its own there, with the user's sign-ins.
Shared bool
+ // Everyday marks the user's everyday Chrome: the Computer opens each
+ // site in a window of its own there, by command line, and the running
+ // instance must carry Settings, so a covered window keeps working. One
+ // started without them restarts only after the user agreed.
+ Everyday bool
}
// chromiumArgs start a Chromium browser as the Computer's own. Without
@@ -85,9 +92,17 @@ user_pref("browser.translations.automaticallyPopup", false);
user_pref("media.autoplay.default", 5);
`
+// everydayChromeArgs are what the user's everyday Chrome needs for the
+// Computer's window in it: see chromiumArgs for why a covered window stops
+// working without it. Sites see no other difference.
+var everydayChromeArgs = []string{"--disable-backgrounding-occluded-windows"}
+
var agentBrowsers = []agentBrowser{
- {Name: "Chrome", Bundle: "com.google.Chrome", App: "Google Chrome.app", Directory: "agent-chrome", Args: chromium,
- Settings: append(slices.Clone(chromiumArgs), "-AppleLanguages"), AddressRole: "AXTextField", AddressLabel: "Address and search bar"},
+ // Chrome is the user's everyday Chrome, with their sign-ins, history and
+ // device trust: sites that watch for automated browsing trust that
+ // browser most, and the user signs in only once.
+ {Name: "Chrome", Bundle: "com.google.Chrome", App: "Google Chrome.app", Settings: everydayChromeArgs,
+ AddressRole: "AXTextField", AddressLabel: "Address and search bar", Shared: true, Everyday: true},
{Name: "Edge", Bundle: "com.microsoft.edgemac", App: "Microsoft Edge.app", Directory: "agent-edge", Args: chromium,
Settings: append(slices.Clone(chromiumArgs), "-AppleLanguages"), AddressRole: "AXTextField", AddressLabel: "Address and search bar"},
// Firefox keeps its window working while covered without a flag. Its
@@ -179,8 +194,8 @@ func (c *cuaSession) launchAgentSafari(ctx context.Context, b agentBrowser, urls
return nil, err
}
m.mu.Lock()
- own := m.agentSafariWindow
- if m.agentSafariPID != pid {
+ own := m.sharedBrowserWindow
+ if m.sharedBrowserPID != pid {
own = 0
}
m.mu.Unlock()
@@ -224,7 +239,7 @@ func (c *cuaSession) launchAgentSafari(ctx context.Context, b agentBrowser, urls
c.agentChromeTabsUntil(ctx, pid, window.WindowID, agentSafariWindowWait, func(n int) bool { return n > 0 })
}
m.mu.Lock()
- m.agentSafariPID, m.agentSafariWindow = pid, window.WindowID
+ m.sharedBrowserBundle, m.sharedBrowserPID, m.sharedBrowserWindow = b.Bundle, pid, window.WindowID
m.mu.Unlock()
for _, url := range urls {
if err := c.agentChromeOpenTab(ctx, b, pid, window.WindowID, offSpace(window), url); err != nil {
@@ -273,3 +288,216 @@ func (c *cuaSession) waitSafariWindows(ctx context.Context, b agentBrowser, pid
}
}
}
+
+// everydayChromePID finds the user's everyday Chrome: the main process of
+// Google Chrome on its default profile. 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.
+var everydayChromePID = func(ctx context.Context) (int, string, error) {
+ output, err := exec.CommandContext(ctx, "/bin/ps", "-axww", "-o", "pid=,args=").Output()
+ if err != nil {
+ return 0, "", err
+ }
+ for _, line := range strings.Split(string(output), "\n") {
+ pidText, args, _ := strings.Cut(strings.TrimSpace(line), " ")
+ if !strings.HasPrefix(args, everydayChromeExecutable) || strings.Contains(args, "--type=") || strings.Contains(args, "--user-data-dir=") {
+ continue
+ }
+ if pid, err := strconv.Atoi(pidText); err == nil {
+ return pid, args, nil
+ }
+ }
+ return 0, "", nil
+}
+
+const everydayChromeExecutable = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
+
+// stopEverydayChrome asks the user's Chrome to quit, as quitting from its
+// menu does, and waits until it is gone. Chrome saves its session first, so
+// the restart brings back the user's windows and tabs.
+var stopEverydayChrome = func(ctx context.Context, pid int) error {
+ process, err := os.FindProcess(pid)
+ if err != nil {
+ return err
+ }
+ if err := process.Signal(syscall.SIGTERM); err != nil {
+ return err
+ }
+ for deadline := time.Now().Add(everydayChromeQuitWait); ; {
+ if running, _, err := everydayChromePID(ctx); err != nil || running == 0 {
+ return err
+ }
+ if time.Now().After(deadline) {
+ return errors.New("COMPUTER_BROWSER_RESTART_FAILED: the user's Chrome did not quit, so it was not restarted; ask the user to quit Chrome and try again")
+ }
+ if err := sleepContext(ctx, 200*time.Millisecond); err != nil {
+ return err
+ }
+ }
+}
+
+// everydayChromeQuitWait bounds how long the user's Chrome may take to quit.
+var everydayChromeQuitWait = 20 * time.Second
+
+// sharedBrowserRunning returns the pid of the user's own browser named by
+// bundle, or 0.
+func sharedBrowserRunning(ctx context.Context, bundle string) (int, error) {
+ if bundle == "com.google.Chrome" {
+ pid, _, err := everydayChromePID(ctx)
+ return pid, err
+ }
+ return lsappPID(ctx, bundle)
+}
+
+// everydayChromeRestart asks for the user's consent before the Computer
+// restarts their Chrome.
+const everydayChromeRestart = "COMPUTER_BROWSER_RESTART_REQUIRED: the user's Chrome runs without the setting that keeps the Computer's window working while other windows cover it, and Chrome takes it only when it starts; nothing was opened. Ask the user with a question card whether the Computer may restart Chrome now: Chrome quits and reopens with their windows and tabs, but text typed into a page and not yet sent may be lost. If the user agrees, call launch_app again with restart_browser: true; if not, end the task"
+
+// launchEverydayChrome opens url in a new window of the user's everyday
+// Chrome, the Computer's own window there, which the task then works in. The
+// window opens through Chrome's command line, as a link from another app
+// does, so no key reaches the user's other Chrome windows. A Chrome that is
+// not running starts with the setting the window needs; one running without
+// it restarts only when restart says the user agreed.
+func (c *cuaSession) launchEverydayChrome(ctx context.Context, b agentBrowser, urls []string, restart bool) (json.RawMessage, error) {
+ if len(urls) != 1 {
+ return nil, fmt.Errorf("launch_app opens one site at a time in the user's Chrome; call it once for each site: %w", errNotSent)
+ }
+ pid, command, err := everydayChromePID(ctx)
+ if err != nil {
+ return nil, err
+ }
+ restarted := false
+ if pid > 0 && !b.startedWith(command) {
+ if !restart {
+ return nil, fmt.Errorf("%s: %w", everydayChromeRestart, errNotSent)
+ }
+ if err := stopEverydayChrome(ctx, pid); err != nil {
+ return nil, err
+ }
+ pid, restarted = 0, true
+ }
+ if pid == 0 {
+ // Chrome starts with the setting first, bringing back the user's
+ // windows after a restart; the Computer's window opens after them,
+ // so it is the one window that was not there before.
+ args := append([]string{"-g", "-b", b.Bundle, "--args"}, b.Settings...)
+ if restarted {
+ args = append(args, "--restore-last-session")
+ }
+ if output, err := agentChromeOpen(ctx, args); err != nil {
+ return nil, fmt.Errorf("launch_app: %s: %w", strings.TrimSpace(string(output)), err)
+ }
+ if pid, err = c.waitEverydayChrome(ctx); err != nil {
+ return nil, err
+ }
+ }
+ windows, err := c.appWindows(ctx, pid)
+ if err != nil {
+ return nil, err
+ }
+ before := map[float64]bool{}
+ for _, w := range windows {
+ before[w.WindowID] = true
+ }
+ if output, err := agentChromeOpen(ctx, []string{"-n", "-g", "-b", b.Bundle, "--args", "--new-window", urls[0]}); err != nil {
+ return nil, fmt.Errorf("launch_app: %s: %w", strings.TrimSpace(string(output)), err)
+ }
+ var window listedWindow
+ tabs := 0
+ for deadline := time.Now().Add(agentSafariWindowWait); window.WindowID == 0; {
+ windows, err := c.appWindows(ctx, pid)
+ if err != nil {
+ return nil, err
+ }
+ for _, w := range windows {
+ if !before[w.WindowID] {
+ if n := c.agentChromeTabs(ctx, pid, w.WindowID); n > 0 {
+ window, tabs = w, n
+ break
+ }
+ }
+ }
+ if window.WindowID != 0 {
+ break
+ }
+ if time.Now().After(deadline) {
+ return nil, errors.New("launch_app: the user's Chrome did not open a window for the Computer")
+ }
+ if err := sleepContext(ctx, 200*time.Millisecond); err != nil {
+ return nil, err
+ }
+ }
+ m := c.op.manager
+ m.mu.Lock()
+ m.sharedBrowserBundle, m.sharedBrowserPID, m.sharedBrowserWindow = b.Bundle, pid, window.WindowID
+ m.mu.Unlock()
+ c.op.mu.Lock()
+ c.op.chromeTabs, c.op.chromePID, c.op.chromeWindow = tabs, pid, window.WindowID
+ c.op.mu.Unlock()
+ note := "This is the Computer's own window in the user's everyday Chrome, with the user's sign-ins; work only in this window, never in the user's other Chrome windows. It works while other windows cover it, but only on the desktop (Space) the user is on. The user's Chrome takes no keys from the Computer, because a key could reach the window the user is typing in: 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. Close a tab with the Close button of its tab; closing the window's last tab closes the window. If a site asks to sign in, ask the user to sign in once in this window."
+ if restarted {
+ note = "Restarted the user's Chrome with their windows and tabs. " + note
+ }
+ text := fmt.Sprintf("Opened %s in a new window of the user's Chrome (pid %d), window %q [window_id: %v]. The window has %d tab(s).\n%s", urls[0], pid, window.Title, window.WindowID, tabs, note)
+ return json.Marshal(map[string]any{"content": []any{map[string]string{"type": "text", "text": text}},
+ "structuredContent": map[string]any{"browser": b.Name, "pid": pid, "windows": []map[string]any{{"window_id": window.WindowID, "title": window.Title, "on_screen": window.IsOnScreen}}, "tabs": tabs, "note": note}})
+}
+
+// waitEverydayChrome waits until the user's Chrome that just started runs
+// and shows its windows, and returns its pid.
+func (c *cuaSession) waitEverydayChrome(ctx context.Context) (int, error) {
+ for deadline := time.Now().Add(agentSafariWindowWait); ; {
+ pid, _, err := everydayChromePID(ctx)
+ if err != nil {
+ return 0, err
+ }
+ if pid > 0 {
+ if windows, err := c.appWindows(ctx, pid); err != nil {
+ return 0, err
+ } else if len(windows) > 0 {
+ // Restored windows appear one after another; a short settle
+ // keeps a late one from reading as the Computer's.
+ return pid, sleepContext(ctx, everydayChromeSettle)
+ }
+ }
+ if time.Now().After(deadline) {
+ return 0, errors.New("launch_app: the user's Chrome did not start")
+ }
+ if err := sleepContext(ctx, 200*time.Millisecond); err != nil {
+ return 0, err
+ }
+ }
+}
+
+// everydayChromeSettle is how long a just-started Chrome gets to reopen the
+// user's windows.
+var everydayChromeSettle = 2 * time.Second
+
+// everydayChrome reports whether pid is the user's everyday Chrome that the
+// Computer opened its window in.
+func (c *cuaSession) everydayChrome(pid any) bool {
+ number, ok := pid.(float64)
+ m := c.op.manager
+ m.mu.Lock()
+ defer m.mu.Unlock()
+ return ok && m.sharedBrowserPID > 0 && int(number) == m.sharedBrowserPID && m.sharedBrowserBundle == "com.google.Chrome"
+}
+
+// everydayChromeKeysRefused tells the Agent how to work without keys in the
+// user's everyday Chrome.
+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.
+func everydayChromeKeys(name string, arguments map[string]any) error {
+ modifiers, _ := arguments["modifiers"].([]any)
+ _, bound := arguments["element_token"].(string)
+ if name == "hotkey" || name == "type_text" || name == "press_key" && (!bound || len(modifiers) > 0) {
+ return fmt.Errorf("%s: %w", everydayChromeKeysRefused, errNotSent)
+ }
+ return nil
+}
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 d244b4b5..feff01de 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
@@ -58,7 +58,7 @@ var agentChromePID = func(ctx context.Context, directory string) (int, string, e
// brings its first window forward once, where the user is. Later URLs open
// in a new tab through the window's accessibility tree and one Return key to
// that browser alone, so the user's apps, focus and Space stay as they are.
-func (c *cuaSession) launchAgentChrome(ctx context.Context, b agentBrowser, urls []string) (json.RawMessage, error) {
+func (c *cuaSession) launchAgentChrome(ctx context.Context, b agentBrowser, urls []string, restart bool) (json.RawMessage, error) {
var sites []string
for _, address := range urls {
if site := siteOf(address); site != "" {
@@ -78,6 +78,9 @@ func (c *cuaSession) launchAgentChrome(ctx context.Context, b agentBrowser, urls
if _, err := c.paceAgentChrome(ctx, 0); err != nil {
return nil, err
}
+ if b.Everyday {
+ return c.launchEverydayChrome(ctx, b, urls, restart)
+ }
if b.Shared {
return c.launchAgentSafari(ctx, b, urls)
}
@@ -413,8 +416,9 @@ var agentChromeRecheck = 30 * time.Second
// because the Computer's own browser gets a new pid when it restarts. A failed
// lookup refuses the input instead of treating the app as another one.
//
-// In the user's Safari only the window the Computer opened is its own; an
-// input that names no window goes to that window.
+// In the user's own browser, such as their everyday Chrome or Safari, only
+// the window the Computer opened is its own; an input that names no window
+// goes to that window.
func (c *cuaSession) isAgentChrome(ctx context.Context, pid, window any) (bool, error) {
number, ok := pid.(float64)
if !ok || runtime.GOOS != "darwin" {
@@ -423,11 +427,11 @@ func (c *cuaSession) isAgentChrome(ctx context.Context, pid, window any) (bool,
m := c.op.manager
m.mu.Lock()
known, checked := m.agentChromePID, m.agentChromeChecked
- safari, safariWindow := m.agentSafariPID, m.agentSafariWindow
+ shared, sharedWindow := m.sharedBrowserPID, m.sharedBrowserWindow
m.mu.Unlock()
- if safari > 0 && safari == int(number) {
+ if shared > 0 && shared == int(number) {
id, named := window.(float64)
- return !named || id == safariWindow, nil
+ return !named || id == sharedWindow, nil
}
if known > 0 && known == int(number) && time.Since(checked) < agentChromeRecheck {
return true, nil
@@ -483,11 +487,11 @@ func (c *cuaSession) agentChromeRunning(ctx context.Context) (int, error) {
}
m := c.op.manager
m.mu.Lock()
- safari := m.agentSafariPID
+ shared, bundle := m.sharedBrowserPID, m.sharedBrowserBundle
m.mu.Unlock()
- if own == 0 && safari > 0 {
- if running, _ := lsappPID(ctx, "com.apple.Safari"); running == safari {
- return safari, nil
+ if own == 0 && shared > 0 {
+ if running, _ := sharedBrowserRunning(ctx, bundle); running == shared {
+ return shared, nil
}
}
m.mu.Lock()
@@ -546,10 +550,10 @@ func (c *cuaSession) agentChromeKeys(ctx context.Context, arguments map[string]a
}
m := c.op.manager
m.mu.Lock()
- safari, safariWindow := m.agentSafariPID, m.agentSafariWindow
+ shared, sharedWindow := m.sharedBrowserPID, m.sharedBrowserWindow
m.mu.Unlock()
- if pid, ok := arguments["pid"].(float64); ok && safari > 0 && int(pid) == safari {
- arguments["window_id"] = safariWindow
+ if pid, ok := arguments["pid"].(float64); ok && shared > 0 && int(pid) == shared {
+ arguments["window_id"] = sharedWindow
return nil
}
windows, err := c.appWindows(ctx, arguments["pid"])
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.go
index 60d71c98..2533e485 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua.go
@@ -160,7 +160,8 @@ func (m *Manager) openCua(ctx context.Context, op *operation) (*cuaSession, []to
if item.Name == "launch_app" && runtime.GOOS == "darwin" {
item.Description = "Open a macOS app in the background through Launch Services, as `open -g` does, and return its pid and windows. Optional urls are handed to the app; for Finder, pass a folder to open it in a window."
item.InputSchema = schema(map[string]any{"bundle_id": map[string]string{"type": "string", "description": "Preferred, for example com.apple.TextEdit."}, "name": map[string]string{"type": "string", "description": "App name, when the bundle id is unknown."}, "urls": map[string]any{"type": "array", "items": map[string]string{"type": "string"}, "description": "Files or folders to open in the app."},
- "agent_browser": map[string]string{"type": "boolean", "description": "Open the URLs in the Computer's own browser, which keeps working while other windows cover it on the user's desktop and has its own sign-ins, instead of the user's everyday browser. Only a site's home page opens there, such as https://www.example.com/. With no bundle_id it is the first installed of Chrome, Edge, Firefox and Safari; a bundle_id of com.google.Chrome, com.microsoft.edgemac, org.mozilla.firefox or com.apple.Safari picks one. Safari has no separate profile, so there it is a window of its own in the user's Safari, with the user's sign-ins."}})
+ "agent_browser": map[string]string{"type": "boolean", "description": "Open the URLs in the Computer's own browser window, which keeps working while other windows cover it on the user's desktop. Only a site's home page opens there, such as https://www.example.com/. With no bundle_id it is the first installed of Chrome, Edge, Firefox and Safari; a bundle_id of com.google.Chrome, com.microsoft.edgemac, org.mozilla.firefox or com.apple.Safari picks one. In Chrome and Safari it is a window of the Computer's own in the user's everyday browser, with the user's sign-ins; in Chrome it opens one site per call. Edge and Firefox run as separate instances with their own sign-ins."},
+ "restart_browser": map[string]string{"type": "boolean", "description": "With agent_browser in Chrome: restart the user's Chrome so the Computer's window keeps working while covered. Pass it only after the user agreed to a COMPUTER_BROWSER_RESTART_REQUIRED question."}})
}
if item.Name == "get_desktop_state" {
item.Description += " Read-only whole-screen view; act through the window tools with a pid and window_id. A system privacy prompt about CuaDriver belongs to the user: never answer it, and keep working through the window tools."
@@ -223,7 +224,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 instead: it keeps working while covered and has its own sign-ins, but not on another desktop (Space). Chrome's own toolbar, such as Back and the address bar, refuses background input: 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. In the Computer's window of the user's everyday Chrome no key or shortcut is sent: 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
@@ -438,8 +439,14 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
return nil, err
}
}
+ everyday := paced && c.everydayChrome(target["pid"])
+ if everyday && name != "run_script" {
+ if err := everydayChromeKeys(name, arguments); err != nil {
+ return nil, err
+ }
+ }
if name == "run_script" {
- if err := scriptArguments(ctx, arguments, c.reviewScope(), scriptInputs); err != nil {
+ if err := scriptArguments(ctx, arguments, c.reviewScope(), scriptInputs, everyday); err != nil {
return nil, err
}
}
@@ -1951,7 +1958,8 @@ func (c *cuaSession) launchApp(ctx context.Context, arguments map[string]any) (j
if err != nil {
return nil, err
}
- return c.launchAgentChrome(ctx, b, addresses)
+ restart, _ := arguments["restart_browser"].(bool)
+ return c.launchAgentChrome(ctx, b, addresses, restart)
}
app, flag := bundle, "-b"
if app == "" {
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 ebb032fd..e32a1ac1 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
@@ -69,7 +69,7 @@ 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.
-func guardedScript(args, body string, deadline int64, inputLimit int) string {
+func guardedScript(args, body string, deadline int64, inputLimit int, noKeys bool) string {
pattern := make([]string, 0, len(scriptForbidden))
for _, word := range scriptForbidden {
pattern = append(pattern, regexp.QuoteMeta(word))
@@ -80,7 +80,8 @@ 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)+`, rest = real.sleep, random = Math.random, floor = Math.floor; let sent = 0;
+const limit = `+strconv.Itoa(inputLimit)+`, noKeys = `+strconv.FormatBool(noKeys)+`, rest = real.sleep, random = Math.random, floor = Math.floor; let sent = 0;
+const keyed = (k, c) => k === "hotkey" || k === "typeText" || k === "pressKey" && (c.length < 2 || c[1] === null || c[1] === undefined || typeof c[0] !== "string" || c[0].indexOf("+") >= 0) || k === "call" && (c[0] === "hotkey" || c[0] === "type_text" || c[0] === "press_key" && (c[1] === null || typeof c[1] !== "object" || typeof c[1].element_token !== "string" || c[1].modifiers !== undefined));
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;
@@ -97,6 +98,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 (noKeys && keyed(k, c)) 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");
return apply(then, apply(rest, real, [`+strconv.Itoa(scriptInputPauseMin)+` + floor(random() * `+strconv.Itoa(scriptInputPauseSpan)+`)]), [run]); }; }}); } }
@@ -135,7 +137,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) error {
+func scriptArguments(ctx context.Context, arguments map[string]any, reviewScope string, inputLimit int, noKeys bool) error {
for key := range arguments {
switch key {
case "script", "script_file", "args", "timeout_ms", "max_calls":
@@ -194,7 +196,7 @@ func scriptArguments(ctx context.Context, arguments map[string]any, reviewScope
arguments["timeout_ms"] = timeout
delete(arguments, "script_file")
delete(arguments, "args")
- arguments["script"] = guardedScript(string(encoded), script, time.Now().Add(time.Duration(timeout)*time.Millisecond).UnixMilli(), inputLimit)
+ arguments["script"] = guardedScript(string(encoded), script, time.Now().Add(time.Duration(timeout)*time.Millisecond).UnixMilli(), inputLimit, noKeys)
return nil
}
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 7376be87..352d385f 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)), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{"n":1}`, tc.body, 42, 0, false)), 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)), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, 2, false)), 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)), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, 20, false)), 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)), 0o600); err != nil {
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, body, 42, tc.limit, false)), 0o600); err != nil {
t.Fatal(err)
}
out, err := exec.Command(node, harness, script).CombinedOutput()
@@ -157,3 +157,37 @@ func TestScriptGuardRefusesLaunchAppForTheComputersChrome(t *testing.T) {
}
}
}
+
+// In the user's everyday Chrome a script sends no shortcut, typed text or
+// unbound key; a plain key bound to an element and other input still go.
+func TestScriptGuardRefusesKeysForTheEverydayChrome(t *testing.T) {
+ node, err := exec.LookPath("node")
+ if err != nil {
+ t.Skip("node is not installed")
+ }
+ dir := t.TempDir()
+ harness := filepath.Join(dir, "harness.mjs")
+ if err := os.WriteFile(harness, []byte(guardHarness), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ for _, tc := range []struct{ body, want string }{
+ {`return await cua.call("hotkey", {pid: 1, keys: ["cmd", "["]});`, "threw:COMPUTER_KEYS_REFUSED"},
+ {`const app = await cua.getApp({pid: 1}); return app.typeText("kettle", {role: "AXTextField"});`, "threw:COMPUTER_KEYS_REFUSED"},
+ {`return await cua.call("press_key", {pid: 1, key: "return"});`, "threw:COMPUTER_KEYS_REFUSED"},
+ {`return await cua.call("press_key", {pid: 1, key: "return", element_token: "s1:2", modifiers: ["cmd"]});`, "threw:COMPUTER_KEYS_REFUSED"},
+ {`return await cua.call("press_key", {pid: 1, key: "return", element_token: "s1:2"});`, "call:press_key"},
+ {`return await cua.call("click", {pid: 1, element_token: "s1:2"});`, "call:click"},
+ } {
+ script := filepath.Join(dir, "script.js")
+ if err := os.WriteFile(script, []byte(guardedScript(`{}`, tc.body, 42, 20, true)), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ out, err := exec.Command(node, harness, script).CombinedOutput()
+ if err != nil {
+ t.Fatalf("node: %v\n%s", err, out)
+ }
+ if got := string(out); !strings.Contains(got, tc.want) {
+ t.Fatalf("%s: got %s, want %q", tc.body, got, tc.want)
+ }
+ }
+}
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 893d8919..ab2cdb26 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); err != nil || arguments["timeout_ms"] != float64(scriptTimeoutMs) {
+ if err := scriptArguments(context.Background(), arguments, "", 0, false); 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); err != nil || arguments["timeout_ms"] != float64(scriptMaxTimeoutMs) {
+ if err := scriptArguments(context.Background(), arguments, "", 0, false); 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); err != nil || arguments["timeout_ms"].(float64) > 45000 {
+ if err := scriptArguments(ctx, arguments, "", 0, false); 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); !errors.Is(err, errNotSent) {
+ if err := scriptArguments(late, map[string]any{"script": "return 1;"}, "", 0, false); !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); !errors.Is(err, errNotSent) {
+ if err := scriptArguments(context.Background(), refused, "", 0, false); !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); err != nil {
+ if err := scriptArguments(context.Background(), arguments, "", 0, false); 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); !errors.Is(err, errNotSent) {
+ if err := scriptArguments(context.Background(), refused, "", 0, false); !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); err != nil {
+ if err := scriptArguments(context.Background(), map[string]any{"script_file": file, "args": map[string]any{"text": "in the foreground"}}, "", 0, false); 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); !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, false); !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); err != nil {
+ if err := scriptArguments(context.Background(), map[string]any{"script": "return 1;"}, permission.ScriptScope("agent-1", "context-1"), 0, false); 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 8956947b..5c449f97 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
@@ -215,6 +215,13 @@ func runToolFixture(mode string) {
}
case "list_windows":
windows := []any{map[string]any{"pid": 42, "window_id": 9, "title": "b", "z_index": 3, "is_on_screen": true, "bounds": map[string]any{"width": 800, "height": 600}}}
+ if mode == "tabs-everyday" {
+ // Each start or command line of the user's Chrome
+ // shows one more window beside the user's own.
+ for i := range strings.Count(string(data), `"name":"open"`) {
+ windows = append(windows, map[string]any{"pid": 42, "window_id": 11 + i, "title": "Home", "z_index": 2, "is_on_screen": true, "bounds": map[string]any{"width": 900, "height": 700}})
+ }
+ }
if mode == "tabs-ghost" {
// A starting Chrome lists a larger surface with no
// accessibility window beside its browser window.
@@ -1863,6 +1870,101 @@ func TestLocalToolCuaDeltaCountFailureReadsFullWindowOnlyOnce(t *testing.T) {
// A launch opens a fresh window when the listed one has left the
// accessibility tree.
+func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *testing.T) {
+ if runtime.GOOS != "darwin" {
+ t.Skip("the Computer's window in the user's Chrome is macOS only")
+ }
+ inputSettle = 0
+ t.Cleanup(func() { inputSettle = 300 * time.Millisecond })
+ pause := agentChromePause
+ agentChromePause = func() time.Duration { return 0 }
+ t.Cleanup(func() { agentChromePause = pause })
+ marker := filepath.Join(t.TempDir(), "calls.jsonl")
+ c := cuaFixtureSession(t, "tabs-everyday", marker)
+ command := everydayChromeExecutable
+ pid := everydayChromePID
+ everydayChromePID = func(context.Context) (int, string, error) { return 42, command, nil }
+ t.Cleanup(func() { everydayChromePID = pid })
+ stopped := 0
+ stop := stopEverydayChrome
+ stopEverydayChrome = func(context.Context, int) error {
+ stopped++
+ command = everydayChromeExecutable + " --disable-backgrounding-occluded-windows"
+ return nil
+ }
+ t.Cleanup(func() { stopEverydayChrome = stop })
+ var opened [][]string
+ open := agentChromeOpen
+ agentChromeOpen = func(_ context.Context, args []string) ([]byte, error) {
+ opened = append(opened, args)
+ f, err := os.OpenFile(marker, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ _, err = f.WriteString(`{"name":"open"}` + "\n")
+ return nil, err
+ }
+ t.Cleanup(func() { agentChromeOpen = open })
+ settle := everydayChromeSettle
+ everydayChromeSettle = 0
+ t.Cleanup(func() { everydayChromeSettle = settle })
+ b := agentBrowsers[0]
+ // A Chrome started without the setting restarts only with consent.
+ if _, err := c.launchAgentChrome(t.Context(), b, []string{"https://example.com/"}, false); !errors.Is(err, errNotSent) || !strings.Contains(err.Error(), "COMPUTER_BROWSER_RESTART_REQUIRED") || stopped != 0 || len(opened) != 0 {
+ t.Fatalf("err=%v stopped=%d opened=%v, want a refused launch", err, stopped, opened)
+ }
+ result, err := c.launchAgentChrome(t.Context(), b, []string{"https://example.com/"}, true)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if stopped != 1 || len(opened) != 2 || !slices.Contains(opened[0], "--restore-last-session") || !slices.Contains(opened[0], "--disable-backgrounding-occluded-windows") || !slices.Equal(opened[1][len(opened[1])-2:], []string{"--new-window", "https://example.com/"}) {
+ t.Fatalf("stopped=%d opened=%v, want a restart, then the site in a new window", stopped, opened)
+ }
+ if !strings.Contains(string(result), `"window_id":12`) || !strings.Contains(string(result), "takes no keys") {
+ t.Fatalf("result=%s, want the new window 12 after the restored one, and the note", result)
+ }
+ // The new window is the Computer's: input to it is paced and held, and
+ // the user's own window 9 is not the Computer's.
+ if own, err := c.isAgentChrome(t.Context(), float64(42), float64(12)); err != nil || !own {
+ t.Fatalf("own=%v err=%v, want window 12 as the Computer's", own, err)
+ }
+ for _, user := range []float64{9, 11} {
+ if own, _ := c.isAgentChrome(t.Context(), float64(42), user); own {
+ t.Fatalf("the user's own Chrome window %v read as the Computer's", user)
+ }
+ }
+ for _, call := range []string{
+ `{"pid":42,"window_id":12,"keys":["cmd","["]}`,
+ } {
+ if _, err := c.call(t.Context(), "hotkey", json.RawMessage(call)); !strings.Contains(fmt.Sprint(err), "COMPUTER_KEYS_REFUSED") {
+ t.Fatalf("hotkey err=%v, want refused", err)
+ }
+ }
+ if _, err := c.call(t.Context(), "type_text", json.RawMessage(`{"pid":42,"window_id":12,"text":"kettle","element_token":"s1:1"}`)); !strings.Contains(fmt.Sprint(err), "COMPUTER_KEYS_REFUSED") {
+ t.Fatalf("type_text err=%v, want refused", err)
+ }
+ if _, err := c.call(t.Context(), "press_key", json.RawMessage(`{"pid":42,"window_id":12,"key":"return"}`)); !strings.Contains(fmt.Sprint(err), "COMPUTER_KEYS_REFUSED") {
+ t.Fatalf("unbound press_key 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)
+ }
+ // A script there may not send keys either.
+ if _, err := c.call(t.Context(), "run_script", json.RawMessage(`{"script":"return 1"}`)); err != nil {
+ t.Fatal(err)
+ }
+ if calls := fixtureCalls(t, marker); !strings.Contains(fmt.Sprint(calls[len(calls)-1]), "noKeys = true") {
+ t.Fatalf("last call=%v, want a script guarded against keys", calls[len(calls)-1])
+ }
+ if err := c.drain(); err != nil {
+ t.Fatal(err)
+ }
+}
+
func TestLocalToolCuaMacAgentChromeOpensAFreshWindowForAnUnreadableOne(t *testing.T) {
if runtime.GOOS != "darwin" {
t.Skip("the Computer's own Chrome is macOS only")
@@ -1892,7 +1994,7 @@ func TestLocalToolCuaMacAgentChromeOpensAFreshWindowForAnUnreadableOne(t *testin
}
t.Cleanup(func() { agentChromeOpen = open })
b := agentBrowser{Name: "Chrome", Bundle: "com.google.Chrome", Directory: "agent-chrome-test", Args: func(string) []string { return nil }, AddressRole: "AXTextField", AddressLabel: "Address and search bar"}
- result, err := c.launchAgentChrome(t.Context(), b, []string{"https://example.com/"})
+ result, err := c.launchAgentChrome(t.Context(), b, []string{"https://example.com/"}, false)
if err != nil {
t.Fatal(err)
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/manager.go b/apps/computer/local-daemon/internal/linger/localtools/manager.go
index f5c07930..201295ca 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/manager.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/manager.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "log/slog"
"maps"
"os"
"os/exec"
@@ -90,11 +91,13 @@ type Manager struct {
agentChromeOwner *operation
agentChromePID int
agentChromeChecked time.Time
- // agentSafariPID and agentSafariWindow are the user's Safari and the
- // window in it that the Computer opened as its own; see
- // launchAgentSafari.
- agentSafariPID int
- agentSafariWindow float64
+ // sharedBrowserBundle, sharedBrowserPID and sharedBrowserWindow are the
+ // user's own browser the Computer works in, such as their everyday Chrome
+ // or Safari, and the window in it that the Computer opened as its own;
+ // see launchEverydayChrome and launchAgentSafari.
+ sharedBrowserBundle string
+ sharedBrowserPID int
+ sharedBrowserWindow float64
// paceMu guards the persisted pace record of the Computer's own browser
// and paceLast, when that Chrome last received input; see
// paceAgentChrome.
@@ -121,10 +124,29 @@ func New(options Options) (*Manager, error) {
if err := m.openBrowserJournals(); err != nil {
return nil, err
}
+ retireAgentChromeProfile(options.StateDirectory)
}
return m, nil
}
+// retireAgentChromeProfile removes the separate Chrome profile the Computer
+// used before it worked in a window of the user's everyday Chrome. A profile
+// whose Chrome still runs stays until a later start finds it closed.
+func retireAgentChromeProfile(state string) {
+ directory := filepath.Join(state, "computer-tools", "agent-chrome")
+ if _, err := os.Stat(directory); err != nil {
+ return
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+ if pid, _, err := agentChromePID(ctx, directory); err != nil || pid > 0 {
+ return
+ }
+ if err := os.RemoveAll(directory); err != nil {
+ slog.Warn("agent_browser.retire_profile_failed", "error", err)
+ }
+}
+
type operation struct {
manager *Manager
spec provider.OperationSpec
@@ -692,7 +714,7 @@ func describeBrowserMode(tools []tool, userChrome, chromeRequired, connectable b
// siteSkillNote leaves the choice of tools on a site to a Skill written for
// it: sites that block automated browsers are used through the computer
// tools, and this browser leaves automation traces in their pages.
-const siteSkillNote = " When a Skill covers the site, follow its choice of tools, even when it asks for the computer tools instead of these. A social network, a marketplace or another site that watches for automated browsers is used through the computer tools in the Computer's own browser, where the user signs in once, even when the user says they are signed in: never connect their everyday browser for such a site."
+const siteSkillNote = " When a Skill covers the site, follow its choice of tools, even when it asks for the computer tools instead of these. A social network, a marketplace or another site that watches for automated browsers is used through the computer tools, in the Computer's own window of the user's everyday browser, never through these browser tools: they drive the page in a way such sites detect."
func filterBrowserTools(catalog []tool) []tool {
var result []tool
diff --git a/skills/builtin/catalog.yaml b/skills/builtin/catalog.yaml
index 94e33668..c55bb045 100644
--- a/skills/builtin/catalog.yaml
+++ b/skills/builtin/catalog.yaml
@@ -219,11 +219,14 @@ skills:
version: 1.0.0
package_path: builtin/personal-profile/1.0.0
- skill_id: simplexai_humanlike_browse
- bootstrap_manifest_id: skill_manifest_simplexai_humanlike_browse_1_0_4
+ bootstrap_manifest_id: skill_manifest_simplexai_humanlike_browse_1_0_5
default_agent_types:
- anotherme
- general
manifests:
+ - manifest_id: skill_manifest_simplexai_humanlike_browse_1_0_5
+ version: 1.0.5
+ package_path: builtin/humanlike-browse/1.0.5
- manifest_id: skill_manifest_simplexai_humanlike_browse_1_0_4
version: 1.0.4
package_path: builtin/humanlike-browse/1.0.4
diff --git a/skills/builtin/humanlike-browse/1.0.5/SKILL.md b/skills/builtin/humanlike-browse/1.0.5/SKILL.md
new file mode 100644
index 00000000..8c0b3f7a
--- /dev/null
+++ b/skills/builtin/humanlike-browse/1.0.5/SKILL.md
@@ -0,0 +1,80 @@
+---
+name: humanlike-browse
+description: Read, survey, post to or manage a site that watches for automated browsing, such as a social network, a marketplace or any site where the user is signed in, through the computer tools in the Computer's own window of the user's browser. Use whenever a task reads posts, comments, profiles or search results on such a site, or writes there for the user.
+---
+
+# Sites that watch for automated browsing
+
+## Choose the route
+
+- A public page that needs no sign-in and no clicks: read it with the web search or fetch tools.
+- Anything else on a social network, a marketplace or a site where the user is signed in: only the computer tools, through `launch_app({agent_browser: true, urls: [url]})`. In Chrome or Safari this opens a window of the Computer's own in the user's everyday browser, with the user's sign-ins; Edge and Firefox run as separate instances. Pass `bundle_id` only when the user asks for one browser. The browser tools drive a page in a way these sites detect, so never use them on these sites; the Computer keeps them off every site the task opened this way.
+- If `launch_app` has no `agent_browser`, this needs a Mac Computer: tell the user and stop.
+- If a call says a computer tool does not exist, take the tool's exact name from your tool list and call it again before telling the user the tools are unavailable.
+- If `launch_app` answers `COMPUTER_BROWSER_RESTART_REQUIRED`, ask the user with a question card whether the Computer may restart Chrome, saying that their windows and tabs come back. Only if they agree, call `launch_app` again with `restart_browser: true`; otherwise end the task.
+- If the site asks to sign in, ask the user to sign in once in that browser window and stop; the sign-in stays for later tasks.
+
+## Move like a person
+
+These sites watch how a visitor moves, and the user may watch the window. Every page change looks like a person's.
+
+- Open each site once with `launch_app`, at its home page, such as `https://www.reddit.com/`; in Chrome, one site per call. A page the user names or describes, such as a forum, a category, a search or their order list, is reached from the home page through the site's own controls. Never call `launch_app` again for another page of a site already open.
+- After that, reach each page the way a person does: type into the site's own search box, use its menus, filters, sort controls and page links, and click the item you want.
+- Never type or paste an address into the browser's address bar, and never build a search, filter or page address yourself, in a tool call or in a script.
+- If the page the user wants cannot be reached from the home page, such as a private share link, tell the user and stop.
+- Go back through the page's own links, such as the site's logo or its breadcrumb. If the item opened in a new tab, close that tab with its Close button. In Edge or Firefox the `cmd+[` hotkey to the window also goes back.
+- To see more items in a list that grows as it scrolls, scroll the list with `scroll`. Use the site's next-page link for a paged list.
+
+## Keep it quick
+
+The user watches the window, and each turn of yours costs seconds. The Computer already spaces each input like a quick person. Do not add waits of your own.
+
+- 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 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; Return bound to the search box goes only while no other Chrome window could take it.
+- 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.
+
+A visit to a result, in one script:
+
+```js
+const app = await cua.getApp({pid, windowId});
+await app.setValue({role: "AXTextField", name: "Search"}, "camping kettle");
+await app.click({role: "AXButton", name: "Search"});
+await app.waitFor({role: "AXLink", name: "Next", timeout_ms: 8000});
+const links = await app.query({role: "AXLink"});
+const first = links.find((l) => /kettle/i.test(l.label));
+await app.click({role: "AXLink", name: first.label});
+await app.waitFor({text: "out of 5 stars", timeout_ms: 8000});
+const page = await app.getState({query: "out of 5 stars"});
+await app.click({role: "AXLink", name: "Back to results"});
+return {title: first.label, rating: page.tree_markdown};
+```
+
+## Read
+
+- Read with `get_window_state`. It returns the whole page the browser has loaded, including the part below the window, so text already on the page needs no scrolling. Pass `query` to narrow a long page. If a read says it was cut, read again narrower instead of guessing.
+- Text inside pictures: `recognize_text`; in a picture viewer, `pages` with `next_key`.
+- A state the tree does not show, such as liked or followed: look with `include_screenshot: true`.
+- To repeat a flow over items, use `run_script`. A script there sends at most 20 inputs: return what it extracted, look at the window, then continue. Many sites open a result in a new tab; the script then reads that tab, so read the tab in front before the next step.
+- Stop scrolling when two reads add no new items. Read only what the task needs: one search per keyword, and never reopen an item already read.
+- Act only in the tabs this task opened. A click that opens a new tab is the task's tab. Close each item's tab with its tab's Close button after reading it, and the task's last tab when done. If a tab the task did not open is in front, stop and tell the user.
+
+## Write
+
+Write only when the user asked for that action in this task: publish, comment, like, follow or delete. Text to review or a request to draft is not permission.
+
+1. Check on the page that the signed-in account is the one the user meant. If not, stop and tell the user.
+2. Make sure exactly one item matches the target. If several do, ask.
+3. Send once, then read the page again and confirm the result shows, such as the comment under that account.
+4. If the result is unclear, read the page. Never send again blind.
+
+If the user takes over the window, read the page and the account again before the next input.
+
+## Checks and limits
+
+- When a page shows a captcha, a code or QR check, a sign-in wall or a too-many-requests message, call `report_blocker` with that kind and the page's URL at once. Then tell the user in the Room what the page asks for and that they can deal with it in that browser window, report what was done, and end the task.
+- When only one item cannot be viewed, call `report_blocker` with `content_unavailable` and its URL, and skip it.
+- Never pass a check yourself, switch accounts or retry around a limit.
+- When the Computer refuses input with `COMPUTER_INPUT_BUDGET`, `COMPUTER_SITE_COOLDOWN`, `COMPUTER_SITE_BLOCKED` or `COMPUTER_TAB_CHANGED`, report what was done and end the task.