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): work in a running Chrome and read public pages with browser tools
jeffrey9799e26fb781
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.mdindex cde67479..eab4cb87 100644--- a/apps/computer/local-daemon/README.md+++ b/apps/computer/local-daemon/README.md@@ -502,16 +502,16 @@ 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 throughChrome's command line, one site per call, so no key reaches the user's otherwindows. 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`. The Daemon never quits the user's Chrome,-because a quit loses text typed into a page and not yet sent: the Agent asks-the user to quit Chrome, and the next `launch_app` starts it with the flag and-`--restore-last-session`. The Daemon records that question in-`computer-tools/everyday-chrome-quit` in the state directory, so a Daemon-restart keeps it, and removes the record once Chrome started. Before the-Computer opens its window, it waits until the list of Chrome windows stops-changing, so every restored window is there. The Computer's window is the new+`--disable-backgrounding-occluded-windows`, which Chrome reads only when it+starts. A Chrome that is not running starts with it. A Chrome the user started+without it is used as it runs: Chrome freezes the Computer's window while+another window covers it completely, so `launch_app` sets+`pauses_when_covered` and tells the Agent to ask the user to leave part of the+window uncovered when a page stops changing. The Daemon never quits the user's+Chrome and never asks the user to, because a quit loses text typed into a page+and not yet sent. After a start, before the Computer opens its window, it+waits until the list of Chrome windows stops changing, so every restored+window is there. The Computer's window is the newwindow with one tab: the one whose address bar shows the site just opened, orthe only new window when the home page moved to another site. Two or more newone-tab windows that the site does not tell apart are refused withdiff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.goindex afa9f6a7..676849a2 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go@@ -33,7 +33,7 @@ type agentBrowser struct {Args func(profile string) []string// Settings are what a running instance's command line must carry for// the tools to rely on it. The Computer restarts its own instance that- // lacks them; the user quits their everyday Chrome.+ // lacks them; it works in the user's everyday Chrome without them.Settings []string// AddressRole and AddressLabel find the address bar; an empty label// takes the first element with that role, which in the browser's@@ -49,9 +49,9 @@ type agentBrowser struct {// 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. The- // user quits one started without them; the Computer never does.+ // site in a window of its own there, by command line. It starts Chrome+ // with Settings, so a covered window keeps working; a Chrome the user+ // started without them is used as it runs and never quit.Everyday bool}@@ -340,17 +340,19 @@ func sharedBrowserRunning(ctx context.Context, bundle string) (int, error) {return lsappPID(ctx, bundle)}-// everydayChromeQuit asks the user to quit their Chrome. Only the user-// quits it: a quit loses text typed into a page and not yet sent, and no-// tool call can prove the user agreed to that.-const everydayChromeQuit = "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 to quit Chrome from its menu (Google Chrome > Quit Google Chrome) and leave it closed, then end your turn. When they answer that Chrome is closed, call launch_app again: the Computer starts Chrome with that setting and brings back their windows and tabs. If they decline, end the task"+// everydayChromeCovered is what the model learns about a window in a Chrome+// the user started without Settings. Chrome freezes the page and its+// accessibility tree while another window covers it completely, and takes+// the setting only when it starts. A quit loses text typed into a page and+// not yet sent, so the Computer neither quits Chrome nor asks the user to.+const everydayChromeCovered = " This Chrome started without the setting that keeps a covered window working, so the window updates only while part of it shows on the user's screen. If the page stops changing, ask the user to leave part of this window uncovered; never ask them to quit or restart Chrome. Chrome gets the setting the next time the Computer starts it."// 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 is never quit by the Computer: the user quits it.+// it is used as it runs.func (c *cuaSession) launchEverydayChrome(ctx context.Context, b agentBrowser, urls []string) (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)@@ -364,32 +366,18 @@ func (c *cuaSession) launchEverydayChrome(ctx context.Context, b agentBrowser, uif err != nil {return nil, err}- if pid > 0 && !b.startedWith(command) {- if err := m.everydayChromeQuitAsked(true); err != nil {- return nil, err- }- return nil, fmt.Errorf("%s: %w", everydayChromeQuit, errNotSent)- }- restored := false+ pausesWhenCovered := pid > 0 && !b.startedWith(command)if pid == 0 {- // After the user quit Chrome for the Computer, it reopens their- // windows and tabs, as the question to quit promised. A second- // instance is started (-n) so a Chrome on another profile, such as- // a test browser, cannot take the command and drop the settings.- restored = m.quitAsked()+ // A second instance is started (-n) so a Chrome on another+ // profile, such as a test browser, cannot take the command and drop+ // the settings.args := append([]string{"-n", "-g", "-b", b.Bundle, "--args"}, b.Settings...)- if restored {- 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}- if err := m.everydayChromeQuitAsked(false); err != nil {- return nil, err- }}windows, err := c.appWindows(ctx, pid)if err != nil {@@ -416,12 +404,12 @@ func (c *cuaSession) launchEverydayChrome(ctx context.Context, b agentBrowser, u// first input's check one read of the strip.c.holdAgentChromeWindow(pid, window.WindowID, tabs, window.Title)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 restored {- note = "Started the user's Chrome again with their windows and tabs. " + note+ if pausesWhenCovered {+ note += everydayChromeCovered}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}})+ "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, "pauses_when_covered": pausesWhenCovered}})}// everydayChromeWindow finds the window the command line just opened: a@@ -563,30 +551,6 @@ func (c *cuaSession) waitEverydayChrome(ctx context.Context) (int, error) {}}-// everydayChromeQuitAsked records, in the state directory so a Daemon-// restart keeps it, whether the Computer asked the user to quit their Chrome-// and has not started it again since.-func (m *Manager) everydayChromeQuitAsked(asked bool) error {- path := filepath.Join(m.options.StateDirectory, "computer-tools", "everyday-chrome-quit")- if !asked {- if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {- return err- }- return nil- }- if err := privatefs.EnsureDir(filepath.Dir(path)); err != nil {- return err- }- return os.WriteFile(path, nil, 0o600)-}--// quitAsked reports whether the Computer asked the user to quit their-// Chrome; see everydayChromeQuitAsked.-func (m *Manager) quitAsked() bool {- _, err := os.Stat(filepath.Join(m.options.StateDirectory, "computer-tools", "everyday-chrome-quit"))- return err == nil-}-// sharedWindow is the windows the Computer opened as its own in one of the// user's browsers, latest last, and that browser's pid. A task may open// several, one site each, and every one stays the Computer's.diff --git a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.goindex e44912ca..ba7e4405 100644--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go@@ -195,10 +195,15 @@ func runToolFixture(mode string) {title = fmt.Sprintf("Tab %d", tabs-1)}windows := []any{map[string]any{"pid": 42, "window_id": 9, "title": title, "z_index": 3, "is_on_screen": true, "bounds": map[string]any{"width": 800, "height": 600}}}- if strings.HasPrefix(mode, "tabs-everyday") && strings.Count(string(data), `"name":"open"`) >= 2 {- // After the start and the command line, a window of- // the user's that Chrome restored late lists before- // the Computer's window.+ opens := 2+ if mode == "tabs-everyday-running" {+ opens = 1+ }+ if strings.HasPrefix(mode, "tabs-everyday") && strings.Count(string(data), `"name":"open"`) >= opens {+ // After the start, when Chrome was not running, and+ // the command line, a window of the user's that+ // Chrome restored late lists before the Computer's+ // window.for _, id := range []int{11, 12} {// Its title is its front tab's, as Chrome's is.windows = append(windows, map[string]any{"pid": 42, "window_id": id, "title": fmt.Sprintf("Tab %d", tabs-1), "z_index": 2, "is_on_screen": true, "bounds": map[string]any{"width": 900, "height": 700}})@@ -1988,9 +1993,9 @@ func TestLocalToolCuaDeltaCountFailureReadsFullWindowOnlyOnce(t *testing.T) {}}-// The user quits their Chrome themselves; the Computer then starts it with-// the setting and opens its own window, found by the site it shows, and the-// user's Chrome takes no keys in any of its windows.+// A Chrome that is not running starts with the setting, the Computer opens+// its own window, found by the site it shows, and the user's Chrome takes no+// keys in any of its windows.func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *testing.T) {if runtime.GOOS != "darwin" {t.Skip("the Computer's window in the user's Chrome is macOS only")@@ -2027,25 +2032,18 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *teverydayChromeSettle = 0t.Cleanup(func() { everydayChromeSettle = settle })b := agentBrowsers[0]- // A Chrome started without the setting is never quit by the Computer.- if _, err := c.launchAgentChrome(t.Context(), b, []string{"https://example.com/"}); !errors.Is(err, errNotSent) || !strings.Contains(err.Error(), "COMPUTER_BROWSER_RESTART_REQUIRED") || len(opened) != 0 {- t.Fatalf("err=%v opened=%v, want a refused launch", err, opened)- }- // The user quits it; the Computer starts it with the setting and their- // windows, then opens the site in a new window.+ // A Chrome that is not running starts with the setting before the site+ // opens in a new window.running = 0- if !c.op.manager.quitAsked() {- t.Fatal("the question to quit Chrome was not recorded")- }result, err := c.launchAgentChrome(t.Context(), b, []string{"https://example.com/"})if err != nil {t.Fatal(err)}- if c.op.manager.quitAsked() {- t.Fatal("the question to quit Chrome outlived the start")+ if len(opened) != 2 || opened[0][0] != "-n" || slices.Contains(opened[0], "--restore-last-session") || !slices.Contains(opened[0], "--disable-backgrounding-occluded-windows") || !slices.Equal(opened[1][len(opened[1])-3:], []string{"--profile-directory=Default", "--new-window", "https://example.com/"}) {+ t.Fatalf("opened=%v, want a start with the setting, then the site in a new window", opened)}- if len(opened) != 2 || opened[0][0] != "-n" || !slices.Contains(opened[0], "--restore-last-session") || !slices.Contains(opened[0], "--disable-backgrounding-occluded-windows") || !slices.Equal(opened[1][len(opened[1])-3:], []string{"--profile-directory=Default", "--new-window", "https://example.com/"}) {- t.Fatalf("opened=%v, want a start with the user's windows, then the site in a new window", opened)+ if !strings.Contains(string(result), `"pauses_when_covered":false`) {+ t.Fatalf("result=%s, want a window that keeps working while covered", result)}// Window 11, restored late, lists first, but it shows another site.if !strings.Contains(string(result), `"window_id":12`) || !strings.Contains(string(result), "takes no keys") {@@ -2113,6 +2111,52 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *t}}+// TestLocalToolCuaMacEverydayChromeWorksInAChromeStartedWithoutTheSetting+// proves the Computer opens its window in a Chrome the user started without+// the setting, never quits or starts it, and tells the model the window+// pauses while covered.+func TestLocalToolCuaMacEverydayChromeWorksInAChromeStartedWithoutTheSetting(t *testing.T) {+ if runtime.GOOS != "darwin" {+ t.Skip("the Computer's window in the user's Chrome is macOS only")+ }+ marker := filepath.Join(t.TempDir(), "calls.jsonl")+ c := cuaFixtureSession(t, "tabs-everyday-running", marker)+ pid := everydayChromePID+ everydayChromePID = func(context.Context) (int, string, error) {+ return 42, "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", nil+ }+ t.Cleanup(func() { everydayChromePID = pid })+ 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 })+ data := everydayChromeData+ everydayChromeData = func() string { return t.TempDir() }+ t.Cleanup(func() { everydayChromeData = data })+ settle := everydayChromeSettle+ everydayChromeSettle = 0+ t.Cleanup(func() { everydayChromeSettle = settle })+ result, err := c.launchAgentChrome(t.Context(), agentBrowsers[0], []string{"https://example.com/"})+ if err != nil {+ t.Fatal(err)+ }+ if len(opened) != 1 || !slices.Equal(opened[0][len(opened[0])-3:], []string{"--profile-directory=Default", "--new-window", "https://example.com/"}) {+ t.Fatalf("opened=%v, want only the site in a new window", opened)+ }+ if !strings.Contains(string(result), `"window_id":12`) || !strings.Contains(string(result), `"pauses_when_covered":true`) || !strings.Contains(string(result), "never ask them to quit or restart Chrome") {+ t.Fatalf("result=%s, want window 12 and the covered-window note", result)+ }+}+// A window of the user's that shows the same site and opens beside the// Computer's leaves the Computer unable to tell them apart, so it takes// neither.diff --git a/apps/computer/local-daemon/internal/linger/localtools/manager.go b/apps/computer/local-daemon/internal/linger/localtools/manager.goindex 1ac282b4..0048f82f 100644--- a/apps/computer/local-daemon/internal/linger/localtools/manager.go+++ b/apps/computer/local-daemon/internal/linger/localtools/manager.go@@ -122,6 +122,11 @@ func New(options Options) (*Manager, error) {if err := m.openBrowserJournals(); err != nil {return nil, err}+ // The Computer no longer asks the user to quit their Chrome, so the+ // record of that question is gone too.+ if err := os.Remove(filepath.Join(options.StateDirectory, "computer-tools", "everyday-chrome-quit")); err != nil && !errors.Is(err, os.ErrNotExist) {+ slog.Warn("agent_browser.retire_quit_record_failed", "error", err)+ }// Quitting a Chrome still on the old profile may take seconds, so// it does not hold up the start.go retireAgentChromeProfile(options.StateDirectory)@@ -717,9 +722,12 @@ 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 window of the user's everyday browser, never through these browser tools: they drive the page in a way such sites detect."+// it. Public pages are read with these faster tools from a profile without+// the user's sign-ins, so a site that flags them flags no account of the+// user's; the user's account on a site that blocks automated browsers is+// used through the computer tools, since 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. Pages any visitor can read without signing in, such as listings, search results or public threads, are read with these browser tools on any site, including social networks and marketplaces, while they use the dedicated Agent Chrome profile. The user's signed-in account on a site that watches for automated browsers, and every write for the user there, go 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. If a site answers these tools with a captcha, a block page or a sign-in wall, switch to the computer tools for it."func filterBrowserTools(catalog []tool) []tool {var result []tooldiff --git a/skills/builtin/humanlike-browse/1.0.9/SKILL.md b/skills/builtin/humanlike-browse/1.0.9/SKILL.mdindex 787a4e2c..2b2e04a3 100644--- a/skills/builtin/humanlike-browse/1.0.9/SKILL.md+++ b/skills/builtin/humanlike-browse/1.0.9/SKILL.md@@ -1,6 +1,6 @@---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.+description: Read, survey, post to or manage a site where the user is signed in, or write for the user on a social network or a marketplace, through the computer tools in the Computer's own window of the user's browser. Use whenever a task needs the user's sign-in on such a site or acts there for the user. Pages any visitor can read without signing in use the browser tools instead.---# Sites that watch for automated browsing@@ -8,7 +8,8 @@ description: Read, survey, post to or manage a site that watches for automated b## 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.+- Pages any visitor can read without signing in, such as listings, search results or public threads, on any site, including social networks and marketplaces: read them with the browser tools, which are faster, when their description says they use a dedicated Agent Chrome profile: a block there flags no account of the user's. When they drive the user's own Chrome instead, use the computer tools on social networks and marketplaces. If the site answers the browser tools with a captcha, a block page or a sign-in wall, switch to the computer tools for that site.+- A page that needs the user's sign-in, or any write for the user, such as a post, a message, a purchase or a setting, 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 for the user's signed-in account; 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.- Never ask the user to quit or restart their browser. If `launch_app` says the Chrome window updates only while part of it shows on the user's screen and a page stops changing, ask the user to leave part of that window uncovered.