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): prove fewer tabs and keep locate and click notes exact
jeffreyd1baa19a629d
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.mdindex 06b1a47e..8dc19f0b 100644--- a/apps/computer/local-daemon/README.md+++ b/apps/computer/local-daemon/README.md@@ -384,13 +384,15 @@ does not stop the task: the input still reaches the task's page, and itsresult reports the new count without saying the input changed it; afteran input it reads the strip only to its depth, unless a script returned readsthe Agent may act on, and not at all after a script that sent no input. A+bounded read that shows no tabs or fewer than before is read again in full. Atab that the task's own input or script opens or closes is the task's: thetask holds the browser's input lease, and the count is kept once the tab stripsettles, since the browser shows such a tab a moment later. The input'sresult then says, from that same read, when it opened or closed a tab or-changed the title of the tab in front. A click there on page text whose row-lists no press notes that Chrome clicks it anyway, since Cua warns that such-a press may have done nothing. Reading the tab+changed the title of the tab in front. A click there on an element whose row+lists no press notes that the press reaches it anyway, since Cua warns that+such a press may have done nothing; a repeat by x,y waits for a read that+shows no effect. Reading the tabstrip replaces Cua's snapshot of the window, so the Daemon remembers the rowsof recent reads and moves an Agent's element token, in an input or writteninto a script, to the current snapshot when its row reads the same there.diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.goindex 422d88a3..8431fbb6 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go@@ -413,11 +413,11 @@ func (c *cuaSession) launchEverydayChrome(ctx context.Context, b agentBrowser, ureturn nil, err}m.setSharedWindow(b.Bundle, pid, window.WindowID)- // The front tab's title, so the first input reports only a change it- // made; the window search above keeps no title.- _, title, _ := c.agentChromeTabsAndTitle(ctx, pid, window.WindowID, 0)+ // list_windows gives the front tab's title, so the first input reports+ // only a change it made. A title that moved on since then costs the+ // first input's check one read of the strip.c.op.mu.Lock()- c.op.chromeTabs, c.op.chromeTitle, c.op.chromePID, c.op.chromeWindow = tabs, title, pid, window.WindowID+ c.op.chromeTabs, c.op.chromeTitle, c.op.chromePID, c.op.chromeWindow = tabs, window.Title, pid, window.WindowIDc.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 restored {diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.goindex 07b6854e..2c563153 100644--- a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go@@ -769,7 +769,7 @@ func (c *cuaSession) recordAgentChromeTabs(ctx context.Context, pid, window any,if before == 0 {return ""}- got, front, close := c.settledAgentChromeTabs(ctx, pid, window, full)+ got, front, close := c.settledAgentChromeTabs(ctx, pid, window, full, before)if got == 0 {return ""}@@ -801,7 +801,7 @@ func (c *cuaSession) recordAgentChromeTabs(ctx context.Context, pid, window any,// a moment after the input that opened or closed it returns, and the next// input's pause already covers that wait. The count is 0 when the strip// cannot be read.-func (c *cuaSession) settledAgentChromeTabs(ctx context.Context, pid, window any, full bool) (int, string, string) {+func (c *cuaSession) settledAgentChromeTabs(ctx context.Context, pid, window any, full bool, before int) (int, string, string) {number, id, ok := c.agentChromeTabWindow(pid, window)if !ok {return 0, "", ""@@ -811,8 +811,10 @@ func (c *cuaSession) settledAgentChromeTabs(ctx context.Context, pid, window anydepth = 0}got, title, close := c.agentChromeTabsAndTitle(ctx, number, id, depth)- if got == 0 && depth > 0 {- // A strip deeper than the bound, as in a browser laid out otherwise.+ if (got == 0 || got < before) && depth > 0 {+ // A strip deeper than the bound, as in a browser laid out otherwise,+ // reads as no tabs, and one split across the bound as fewer. A+ // closed tab is rare, so proving it with a whole read costs little.depth = 0got, title, close = c.agentChromeTabsAndTitle(ctx, number, id, depth)}diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.goindex 45191934..5eb31dfd 100644--- a/apps/computer/local-daemon/internal/linger/localtools/cua.go+++ b/apps/computer/local-daemon/internal/linger/localtools/cua.go@@ -534,7 +534,7 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage// Chrome clicks a page element on a press even where the element// lists no press, as the sort menu of a review list did; the Agent// took Cua's warning as a miss and clicked by x,y, which missed.- result = withNote(result, "In the Computer's own browser, a press on page text clicks it as a person would, even where the row lists no press: check its effect in the next read, and do not repeat it by x,y.")+ result = withNote(result, "In the Computer's own browser, a press goes to the element as a person's click would, even where its row lists no press. Check its effect in the next read; repeat it by x,y only if that read shows no effect.")}var scriptReads []windowReadif err == nil && name == "run_script" {@@ -1320,6 +1320,8 @@ func (c *cuaSession) locate(ctx context.Context, name string, arguments map[stri}role, _ := arguments["role"].(string)label, _ := arguments["name"].(string)+ // A name of only white space would match every element without a label.+ label = sameSpaces(label)if role == "" || label == "" || arguments["pid"] == nil || arguments["window_id"] == nil {return fmt.Errorf("COMPUTER_TARGET_REQUIRED: a role and name target needs pid, window_id, role and name: %w", errNotSent)}@@ -1350,7 +1352,6 @@ func (c *cuaSession) locate(ctx context.Context, name string, arguments map[strireturn fmt.Errorf("COMPUTER_TARGET_UNREADABLE: window %v was read only in part, so a %s labeled %q cannot be proven to be the only one; use an element_token from a read: %w", arguments["window_id"], role, label, errNotSent)}var matches []string- label = sameSpaces(label)for _, element := range state.Structured.Elements {value, _ := element.Value.(string)if element.Role == role && (sameSpaces(element.Label) == label || sameSpaces(value) == label) {diff --git a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.goindex 82db818d..b5335305 100644--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go@@ -234,7 +234,8 @@ func runToolFixture(mode string) {// the user's that Chrome restored late lists before// the Computer's window.for _, id := range []int{11, 12} {- windows = append(windows, map[string]any{"pid": 42, "window_id": id, "title": "Home", "z_index": 2, "is_on_screen": true, "bounds": map[string]any{"width": 900, "height": 700}})+ // 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}})}}if mode == "tabs-ghost" {@@ -1182,7 +1183,7 @@ func TestLocalToolCuaMacAgentChromeKeepsTabsItsOwnInputChangesLate(t *testing.T)if err != nil {t.Fatalf("input after the task's own %s: %v", step.keys, err)}- if strings.Contains(string(result), "tab") || !strings.Contains(string(result), "a press on page text clicks it") {+ if strings.Contains(string(result), "tab") || !strings.Contains(string(result), "even where its row lists no press") {t.Fatalf("result of a click on page text that changed no tab=%s", result)}}@@ -1251,12 +1252,18 @@ func TestLocalToolCuaMacAgentChromeReadsTheTabStripOnlyAsFarAsItNeeds(t *testingt.Fatalf("calls for a script that clicked=%v, want two bounded reads after it", got)}// A tab closed behind the front tab does not stop the task, and the- // result reports the count without saying the input closed it.+ // result reports the count without saying the input closed it. Fewer+ // tabs in a bounded read are proven by whole reads, since a strip split+ // across the bound would read as fewer too.c.op.chromeTabs = 2+ before = len(reads())result, err := c.call(t.Context(), "click", json.RawMessage(`{"pid":42,"window_id":9,"element_token":"s1:1"}`))if err != nil {t.Fatal(err)}+ if got := reads()[before:]; !slices.Equal(got, []string{"click", "6", "0", "0"}) {+ t.Fatalf("calls for fewer tabs=%v, want a bounded read, then whole reads", got)+ }if note := `The window now has 1 tab(s), 2 before this input; the tab in front still shows \"Tab 0\".`; !strings.Contains(string(result), note) || strings.Contains(string(result), "This input closed") {t.Fatalf("result=%s, want the neutral note %s", result, note)}@@ -1659,6 +1666,10 @@ func TestLocalToolCuaMacInputsFindTheirTargetWhenTheyRun(t *testing.T) {if _, err := c.call(t.Context(), "click", json.RawMessage(`{"pid":42,"window_id":9,"role":"AXLink","name":"Kettle [snapshot]"}`)); err != nil {t.Fatalf("label with a no-break space: %v", err)}+ // A name of only white space names nothing, not the element without a value.+ if _, err := c.call(t.Context(), "type_text", json.RawMessage(`{"pid":42,"window_id":9,"role":"AXTextArea","name":"\u00a0 ","text":"hi"}`)); err == nil || !strings.Contains(err.Error(), "COMPUTER_TARGET_REQUIRED") {+ t.Fatalf("white space name err=%v, want target required", err)+ }if _, err := c.call(t.Context(), "click", json.RawMessage(`{"pid":42,"window_id":9,"role":"AXButton","name":"Delete"}`)); err == nil || !strings.Contains(err.Error(), "COMPUTER_TARGET_NOT_FOUND") {t.Fatalf("partial label err=%v, want not found", err)}@@ -2101,8 +2112,8 @@ 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)}- // launch_app keeps the front tab's title, so the first input, which- // changes no tab, reports no change.+ // launch_app keeps the front tab's title from list_windows, so the+ // first input, which changes no tab, reports no change.if c.op.chromeTitle != "Tab 0" {t.Fatalf("front title after launch_app=%q, want Tab 0", c.op.chromeTitle)}