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): address review of humanlike browsing
jeffreyeda427a9e015
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.goindex aab1da8a..d244b4b5 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go@@ -28,6 +28,12 @@ func (c *cuaSession) agentBrowserDirectory(b agentBrowser) string {return filepath.Join(c.op.manager.options.StateDirectory, "computer-tools", b.Directory)}+// agentChromeOpen runs macOS open with args to start the browser or open a+// window of it.+var agentChromeOpen = func(ctx context.Context, args []string) ([]byte, error) {+ return exec.CommandContext(ctx, "/usr/bin/open", args...).CombinedOutput()+}+// agentChromePID finds the main process of the browser whose profile is// directory and returns its pid and command line, or 0 when none runs. Its// helper and content processes name the profile too, with a process type.@@ -107,7 +113,7 @@ func (c *cuaSession) launchAgentChrome(ctx context.Context, b agentBrowser, urls// so each URL opens below as a new tab, the last one in front.openWindow := func() error {args := append([]string{"-g", "-n", "-b", b.Bundle, "--args"}, b.Args(directory)...)- if output, err := exec.CommandContext(ctx, "/usr/bin/open", args...).CombinedOutput(); err != nil {+ if output, err := agentChromeOpen(ctx, args); err != nil {return fmt.Errorf("launch_app: %s: %w", strings.TrimSpace(string(output)), err)}return nildiff --git a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.goindex 39713581..5c9f37b9 100644--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go@@ -182,6 +182,12 @@ func runToolFixture(mode string) {tabs = max(1, tabs-1)case "tabs-unreadable":tabs = 0+ case "tabs-reopen":+ // The listed window has left the accessibility tree; only+ // the window open starts shows tabs.+ if !strings.Contains(string(data), `"name":"open"`) {+ tabs = 0+ }}if request.Params.Name != "get_window_state" && request.Params.Name != "list_windows" {f, _ := os.OpenFile(marker, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600)@@ -1847,6 +1853,64 @@ func TestLocalToolCuaDeltaCountFailureReadsFullWindowOnlyOnce(t *testing.T) {// A starting Chrome may list a larger surface that has no accessibility// window; the browser window is the largest one whose tab strip reads.+func TestLocalToolCuaMacAgentChromeOpensAFreshWindowForAnUnreadableOne(t *testing.T) {+ if runtime.GOOS != "darwin" {+ t.Skip("the Computer's own Chrome is macOS only")+ }+ inputSettle = 0+ t.Cleanup(func() { inputSettle = 300 * time.Millisecond })+ wait := agentChromeWait+ agentChromeWait = 300 * time.Millisecond+ t.Cleanup(func() { agentChromeWait = wait })+ pause := agentChromePause+ agentChromePause = func() time.Duration { return 0 }+ t.Cleanup(func() { agentChromePause = pause })+ marker := filepath.Join(t.TempDir(), "calls.jsonl")+ c := cuaFixtureSession(t, "tabs-reopen", marker)+ pid := agentChromePID+ agentChromePID = func(context.Context, string) (int, string, error) { return 42, "", nil }+ t.Cleanup(func() { agentChromePID = pid })+ open := agentChromeOpen+ agentChromeOpen = func(context.Context, []string) ([]byte, error) {+ 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 })+ 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/"})+ if err != nil {+ t.Fatal(err)+ }+ // The fresh window's first tab takes the URL in place, with no new tab.+ var got []string+ for _, call := range fixtureCalls(t, marker) {+ got = append(got, call.Name)+ }+ if want := []string{"open", "set_value", "press_key"}; !slices.Equal(got, want) {+ t.Fatalf("calls=%v, want %v", got, want)+ }+ if !strings.Contains(string(result), "Started the Computer's own Chrome") {+ t.Fatalf("result=%s, want the note for a started browser", result)+ }+ // Typing there is paced at the default speed unless the Agent sets one.+ c.op.chromeTabs, c.op.chromePID, c.op.chromeWindow = 1, 42, 9+ if _, err := c.call(t.Context(), "type_text", json.RawMessage(`{"pid":42,"window_id":9,"text":"kettle","element_token":"s1:1"}`)); err != nil {+ t.Fatal(err)+ }+ calls := fixtureCalls(t, marker)+ if last := calls[len(calls)-1]; last.Name != "type_text" || last.Arguments["delay_ms"] != float64(agentChromeTypeDelay) {+ t.Fatalf("last call=%+v, want type_text with delay_ms %d", last, agentChromeTypeDelay)+ }+ if err := c.drain(); err != nil {+ t.Fatal(err)+ }+}+func TestLocalToolCuaMacAgentChromePicksTheWindowWithTabs(t *testing.T) {if runtime.GOOS != "darwin" {t.Skip("the Computer's own Chrome is macOS only")diff --git a/skills/builtin/humanlike-browse/1.0.4/SKILL.md b/skills/builtin/humanlike-browse/1.0.4/SKILL.mdindex f7c8095b..e832eb7b 100644--- a/skills/builtin/humanlike-browse/1.0.4/SKILL.md+++ b/skills/builtin/humanlike-browse/1.0.4/SKILL.md@@ -21,6 +21,7 @@ These sites watch how a visitor moves, and the user may watch the window. Every- Open each site once with `launch_app`, at its home page, such as `https://www.reddit.com/`. 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 with the page's own back link or with the `cmd+[` hotkey to the window. If the item opened in a new tab, close that tab with its Close button instead.- 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.@@ -30,7 +31,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` and then press Return: it is instant. Use `typeText` only where the box ignores `setValue`.+- Fill a search box with `setValue`, then press Return on that box: it is instant. Use `typeText` only where the box ignores `setValue`.- After a click or a key 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.@@ -39,7 +40,7 @@ A visit to a result, in one script:```jsconst app = await cua.getApp({pid, windowId});await app.setValue({role: "AXTextField", name: "Search"}, "camping kettle");-await app.pressKey("return");+await app.pressKey("return", {role: "AXTextField", 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));