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): tell the Agent what an input changed in its browser

jeffrey8b1422fecff0
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index 8582e206..9a1d7be0 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -312,7 +312,7 @@ changes in the same result. By default it reads the last step's window, or the
application's focused window when that step gave no `window_id`; pass `read` to
read another window or add a `query`. When a step is refused or its result is
unknown, the result lists the completed, unsent and possibly applied steps.
-An `element_token` from an older read is refused, never rebound to another element with the same role and label. A step can name its target by role and name instead; the Daemon finds it when the step runs.
+An `element_token` from an older read is refused, never rebound to another element with the same role and label. A step can name its target by role and name instead; the Daemon finds it when the step runs, and white space in a label, such as a no-break space, matches any white space.
On Windows, after a successful input the Daemon waits 100 ms before reading the
window diff, because Cua already waits for its own read-back after input. The MCP
initialize result carries no usage instructions, because Codex prepends them to
@@ -379,7 +379,11 @@ A change in the number of tabs between the task's inputs stops the task with
`COMPUTER_TAB_CHANGED`, because the next input could reach another page. A
tab that the task's own input or script opens or closes is the task's: the
task holds the browser's input lease, and the count is kept once the tab strip
-settles, since the browser shows such a tab a moment later. Reading the tab
+settles, since the browser shows such a tab a moment later. The input's
+result 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
strip replaces Cua's snapshot of the window, so the Daemon remembers the rows
of recent reads and moves an Agent's element token, in an input or written
into 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_test.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go
index 343877de..7e1a0556 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser_test.go
@@ -15,8 +15,9 @@ func TestCountTabsReadsChromeEdgeAndFirefoxStrips(t *testing.T) {
"safari": " - [17] AXRadioButton \"Trail checklist - Pinboard\" [id=TabBarTab?isPinned=false&isNarrow=false&isActive=false actions=[press,name:close tab]]\n" +
" - [18] AXRadioButton \"Start Page\" [id=TabBarTab?isPinned=false&isNarrow=false&isActive=true actions=[press,name:close tab]]",
} {
- if got := countTabs(tree); got != 2 {
- t.Errorf("%s: %d tabs, want 2", name, got)
+ want := map[string]string{"chrome": "Close", "edge": "Close tab", "firefox": "Close tab"}[name]
+ if got, close := tabStrip(tree); got != 2 || close != want {
+ t.Errorf("%s: %d tabs closed by %q, want 2 closed by %q", name, got, close, want)
}
}
// A page's own radio buttons are not tabs.
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 ff2cc341..36c8f9b9 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome.go
@@ -577,24 +577,32 @@ func (c *cuaSession) agentChromeKeys(ctx context.Context, arguments map[string]a
// It returns 0 when the read fails or is cut short: the tab strip follows the
// page in the tree, so a cut read may miss it.
func (c *cuaSession) agentChromeTabs(ctx context.Context, pid int, window float64) int {
+ count, _, _ := c.agentChromeTabsAndTitle(ctx, pid, window)
+ return count
+}
+
+// agentChromeTabsAndTitle is agentChromeTabs with the title of the window's
+// front tab and the label of a tab's Close button, from the same read.
+func (c *cuaSession) agentChromeTabsAndTitle(ctx context.Context, pid int, window float64) (int, string, string) {
read, err := c.client.request(ctx, "tools/call", map[string]any{"name": "get_window_state", "arguments": map[string]any{
"pid": pid, "window_id": window, "include_screenshot": false, "max_elements": 6000, "timeout_ms": 6000, "session": c.label}})
if err != nil {
slog.Warn("agent_browser.tabs_unread", "pid", pid, "window_id", window, "error", err)
- return 0
+ return 0, "", ""
}
var state struct {
Structured struct {
Tree string `json:"tree_markdown"`
+ Title string `json:"window_title"`
Truncated bool `json:"truncated"`
Degraded string `json:"degraded_reason"`
} `json:"structuredContent"`
}
if err := json.Unmarshal(read, &state); err != nil || state.Structured.Truncated {
slog.Warn("agent_browser.tabs_unread", "pid", pid, "window_id", window, "truncated", state.Structured.Truncated, "error", err)
- return 0
+ return 0, "", ""
}
- count := countTabs(state.Structured.Tree)
+ count, close := tabStrip(state.Structured.Tree)
if count == 0 && strings.Contains(state.Structured.Tree, "id=WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD") {
// Safari hides its tab strip while a window has one tab.
count = 1
@@ -602,15 +610,21 @@ func (c *cuaSession) agentChromeTabs(ctx context.Context, pid int, window float6
if count == 0 && state.Structured.Degraded != "" {
slog.Warn("agent_browser.tabs_unread", "pid", pid, "window_id", window, "reason", state.Structured.Degraded)
}
- return count
+ return count, state.Structured.Title, close
}
// countTabs counts the tab rows of a browser window's tree: a radio button
// outside the page that holds a button, its Close button.
func countTabs(tree string) int {
+ count, _ := tabStrip(tree)
+ return count
+}
+
+// tabStrip is countTabs with the label of a tab's Close button, which follows
+// the user's language; it is empty for a Safari tab, which has none.
+func tabStrip(tree string) (count int, close string) {
rows := strings.Split(tree, "\n")
indent := func(row string) int { return len(row) - len(strings.TrimLeft(row, " ")) }
- count := 0
// web is the indent of the page being skipped, or -1: a radio button
// in a page is not a tab.
web := -1
@@ -641,11 +655,14 @@ func countTabs(tree string) int {
}
if trimmed := strings.TrimSpace(next); strings.Contains(trimmed, "] AXButton") && strings.HasSuffix(trimmed, "[actions=[press]]") {
count++
+ if _, label, ok := strings.Cut(trimmed, "] AXButton \""); ok && close == "" {
+ close, _, _ = strings.Cut(label, "\"")
+ }
break
}
}
}
- return count
+ return count, close
}
// agentChromeTabWindow names the window whose tabs hold the task: the one
@@ -697,40 +714,59 @@ func (c *cuaSession) checkAgentChromeTabs(ctx context.Context, pid, window any)
// script, so a tab it opened or closed, such as a link to a new tab, is the
// task's. While it runs, the task holds this browser's input lease, so no
// other task changes the tabs. Only a task that opened its tab with
-// launch_app holds a count.
-func (c *cuaSession) recordAgentChromeTabs(ctx context.Context, pid, window any) {
+// launch_app holds a count. It returns a note on what the input changed in
+// the window, from the same read: a click result says nothing of where the
+// page went, and the Agent read the window only to learn that.
+func (c *cuaSession) recordAgentChromeTabs(ctx context.Context, pid, window any) string {
c.op.mu.Lock()
- held := c.op.chromeTabs > 0
+ before, title := c.op.chromeTabs, c.op.chromeTitle
c.op.mu.Unlock()
- if !held {
- return
+ if before == 0 {
+ return ""
}
- if got := c.settledAgentChromeTabs(ctx, pid, window); got > 0 {
- c.op.mu.Lock()
- c.op.chromeTabs = got
- c.op.mu.Unlock()
+ got, front, close := c.settledAgentChromeTabs(ctx, pid, window)
+ if got == 0 {
+ return ""
}
+ c.op.mu.Lock()
+ c.op.chromeTabs, c.op.chromeTitle = got, front
+ c.op.mu.Unlock()
+ switch {
+ case got > before && close != "":
+ // The tab strip follows the page in the tree, past the default
+ // walk, so the Agent's search for the button came back empty.
+ return fmt.Sprintf("This input opened %d new tab(s); the one in front shows %q. To go back, close it with the %q button inside its tab: the tab strip follows the page in the tree, so read it with get_window_state query %q and max_elements 6000, or app.getState with the same in a script.", got-before, front, close, close)
+ case got > before:
+ return fmt.Sprintf("This input opened %d new tab(s); the one in front shows %q.", got-before, front)
+ case got < before:
+ return fmt.Sprintf("This input closed %d tab(s); the tab in front shows %q.", before-got, front)
+ case front != title:
+ return fmt.Sprintf("The tab in front now shows %q.", front)
+ }
+ return ""
}
-// settledAgentChromeTabs reads the window's tab count once two reads a
-// settle apart agree: the browser adds or drops a tab a moment after the
-// input that opened or closed it returns, and the next input's pause already
-// covers that wait. It is 0 when the strip cannot be read.
-func (c *cuaSession) settledAgentChromeTabs(ctx context.Context, pid, window any) int {
+// settledAgentChromeTabs reads the window's tab count, its front tab's title
+// and the label of a tab's Close button once two reads a settle apart agree: the browser adds or drops a tab
+// 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) (int, string, string) {
number, id, ok := c.agentChromeTabWindow(pid, window)
if !ok {
- return 0
+ return 0, "", ""
}
- got := c.agentChromeTabs(ctx, number, id)
+ got, title, close := c.agentChromeTabsAndTitle(ctx, number, id)
for range 3 {
if got == 0 || sleepContext(ctx, inputSettle) != nil {
break
}
- next := c.agentChromeTabs(ctx, number, id)
+ next, nextTitle, nextClose := c.agentChromeTabsAndTitle(ctx, number, id)
+ title, close = nextTitle, nextClose
if next == got {
break
}
got = next
}
- return got
+ return got, title, close
}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.go
index 3e0eca62..121910ea 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua.go
@@ -215,7 +215,7 @@ const MacToolGuide = `Computer tools on this Mac (MCP server "computer"):
{tool: "click" | "double_click" | "right_click", pid, window_id, element_token, modifier?: ["cmd"]} on a row of the latest read; cmd-clicks add rows to a selection, so one cmd+c copies several files;
{tool: "hotkey", pid, keys: ["cmd", "s"]}, {tool: "press_key", pid, key: "return"}, {tool: "type_text", pid, text} go to the app's focused field, such as a sheet, panel or rename field; a new Save sheet's name field already has focus with its text selected, so type the name without clicking, and text fields refuse click;
{tool: "scroll", pid, window_id, direction}.
- A click, scroll or type_text, in a step or alone, can name its target with role and name instead of element_token: the one element with that role whose label or value is exactly name, or nth (from 0) when several match. It is found when it runs, so one batch can cross pages; finding it reads the window, which stales the tokens of your earlier read, so later steps name their targets the same way.
+ A click, scroll or type_text, in a step or alone, can name its target with role and name instead of element_token: the one element with that role whose label or value is exactly name, apart from white space, or nth (from 0) when several match. It is found when it runs, so one batch can cross pages; finding it reads the window, which stales the tokens of your earlier read, so later steps name their targets the same way.
- run_script({script}) runs JavaScript that loops, waits and reads between inputs and returns only what you extract. Use it to repeat a flow over several items, such as open each result, read it and close it, in one call instead of a turn per item.
- bring_to_front({pid, window_id}) raises one window.
- 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.
@@ -526,8 +526,16 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
// check, replaced the snapshot the Agent's token names.
c.snapshots.remap(arguments)
}
+ token, _ := arguments["element_token"].(string)
+ pagePress := agentChrome && name == "click" && c.snapshots != nil && c.snapshots.unpressable(token)
driverStarted := time.Now()
result, err := c.sendInput(ctx, name, arguments, appKeys, agentChrome)
+ if err == nil && pagePress && !failed(result) {
+ // 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.")
+ }
var scriptReads []windowRead
if err == nil && name == "run_script" {
result, scriptReads = scriptResultReads(result)
@@ -551,7 +559,9 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
}
// A script that throws has still sent the inputs before the throw.
if paced && (err == nil || name == "run_script") {
- c.recordAgentChromeTabs(ctx, target["pid"], target["window_id"])
+ if note := c.recordAgentChromeTabs(ctx, target["pid"], target["window_id"]); note != "" && result != nil {
+ result = withNote(result, note)
+ }
}
return c.finishInput(ctx, name, arguments, appKeys, result, err)
}
@@ -1333,8 +1343,10 @@ func (c *cuaSession) locate(ctx context.Context, name string, arguments map[stri
return 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 {
- if element.Role == role && (element.Label == label || element.Value == label) {
+ value, _ := element.Value.(string)
+ if element.Role == role && (sameSpaces(element.Label) == label || sameSpaces(value) == label) {
matches = append(matches, element.Token)
}
}
@@ -1354,6 +1366,12 @@ func (c *cuaSession) locate(ctx context.Context, name string, arguments map[stri
return nil
}
+// sameSpaces writes every run of white space as one space: a page label may
+// hold a no-break space, which reads the same as the space the Agent writes.
+func sameSpaces(text string) string {
+ return strings.Join(strings.Fields(text), " ")
+}
+
// listedWindow is one window from Cua list_windows.
type listedWindow struct {
WindowID float64 `json:"window_id"`
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 eea19e6d..d6090661 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_script.go
@@ -18,8 +18,8 @@ import (
const macScriptDescription = "Run a JavaScript program that drives apps on this Mac in ONE call: loops, waits, reads and checks between inputs, and only its return value comes back. Use it to repeat a flow over several items, such as open each result, read it and close it, instead of one model turn per input. The script is the body of an async function: use await and return a JSON value. The only API is cua:\n" +
"- const app = await cua.getApp({pid, windowId}) or cua.getApp(\"Google Chrome\"); cua.sleep(ms), where ms must be a whole number: a fraction returns at once without waiting, and in the Computer's own browser one sleep lasts at most 1.5 s: wait for a page with app.waitFor; cua.listWindows({pid})\n" +
"- app.getState({query?, max_elements?, timeout_ms?, since?: \"latest\", tree_format?: \"elements\"}) returns {tree_markdown, window_title, snapshot_id, pid, window_id, truncated?, elements?}; rows read as in get_window_state. It takes no screenshot, which costs seconds on a busy page, unless you pass include_screenshot: true. In a script the walk stops after 250 nodes and 1000 ms unless you pass max_elements and timeout_ms, which cuts a browser page: pass about 3000 and 4000 there\n" +
- "- app.query({role?, name?}) finds named elements {element_token, role, label, frame}; app.waitFor({role?, name?, text?, gone?, timeout_ms?}) waits, at most 10000 ms, until the window shows (or no longer shows) them; text also matches static text\n" +
- "- app.click(t), doubleClick(t), typeText(text, t?), pressKey(\"escape\", t?), hotkey([\"cmd\",\"s\"]), scroll(t, \"down\", amount?), setValue(t, value), where t is {role, name, nth?}, an element_token, a row number of this app's last getState(), or [x, y] pixels of its last screenshot\n" +
+ "- app.query({role?, name?}) finds the elements whose label holds name, ignoring case, {element_token, role, label, frame}; app.waitFor({role?, name?, text?, gone?, timeout_ms?}) waits, at most 10000 ms, until the window shows (or no longer shows) them; text also matches static text\n" +
+ "- app.click(t), doubleClick(t), typeText(text, t?), pressKey(\"escape\", t?), hotkey([\"cmd\",\"s\"]), scroll(t, \"down\", amount?), setValue(t, value), where t is {role, name, nth?}, whose name must equal the label exactly, spaces included (for a long label, query a short part of it and click the element_token it returns), an element_token, a row number of a getState() earlier in this same script (a row of a get_window_state call is its element_token string), or [x, y] pixels of its last screenshot\n" +
"- cua.call(tool, args) for click, press_key, type_text, scroll, get_window_state or list_windows with their usual arguments. A script opens no app or URL: call launch_app as its own tool first.\n" +
"Inputs go to the app in the background, as the other computer tools do; a control that reacts only to a real pointer needs the click tool with delivery_mode \"foreground\". A failed call throws (catch it to recover), and the error names the line. timeout_ms is the wall-time limit (default 60000, at most 100000); max_calls bounds driver calls (default 100, at most 500). A Skill that ships a script names it with script_file and passes its inputs as args, read in the script as the constant args. Return only what you need, such as extracted text; the result is cut at 40000 characters and carries no screenshots: call get_window_state to look at the window."
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go b/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go
index e0ea73d3..8901a527 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go
@@ -174,6 +174,24 @@ func (s *snapshotRows) sent(name string) {
s.mu.Unlock()
}
+// unpressable reports whether token names a remembered row that lists no
+// press action, such as a web page's static text, which lists none; Cua then
+// warns that the press may not have taken.
+func (s *snapshotRows) unpressable(token string) bool {
+ snapshot, index, ok := strings.Cut(token, ":")
+ if !ok {
+ return false
+ }
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ row, ok := s.reads[snapshot].rows[index]
+ if !ok {
+ return false
+ }
+ _, actions, _ := strings.Cut(row, "[actions=[")
+ return !strings.Contains(actions, "press")
+}
+
// carry returns the token on the current snapshot of its window, or the
// token itself.
func (s *snapshotRows) carry(token string) string {
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots_test.go b/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots_test.go
index 955beff3..618066f1 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots_test.go
@@ -157,3 +157,15 @@ func mustJSON(t *testing.T, value any) []byte {
}
return encoded
}
+
+// A row that lists no press, such as a page's static text, is told apart
+// from a link that lists one; a token the Computer does not remember is not.
+func TestSnapshotRowsTellsTextFromAPressableRow(t *testing.T) {
+ rows := newSnapshotRows()
+ rows.record(windowRead{Snapshot: "s00000001", PID: 42, Window: 9, Tree: "- [2] AXWebArea \"Shop\"\n - [3] AXStaticText = \"Sort by time\"\n - [4] AXLink \"Kettle\" [actions=[press]]\n - [5] AXGroup [actions=[show_menu]]"})
+ for token, want := range map[string]bool{"s00000001:3": true, "s00000001:5": true, "s00000001:4": false, "s00000001:9": false, "s00000002:3": false, "bad": false} {
+ if got := rows.unpressable(token); got != want {
+ t.Fatalf("unpressable(%s)=%v, want %v", token, got, want)
+ }
+ }
+}
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 2c4308c0..8c7f8928 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
@@ -248,7 +248,7 @@ func runToolFixture(mode string) {
if address == "" {
address = "news.example.org/today"
}
- result = map[string]any{"content": []any{}, "structuredContent": map[string]any{"tree_markdown": tree.String(), "elements": []any{
+ result = map[string]any{"content": []any{}, "structuredContent": map[string]any{"tree_markdown": tree.String(), "window_title": fmt.Sprintf("Tab %d", tabs-1), "elements": []any{
map[string]any{"element_token": "s1:1", "role": "AXTextField", "label": "Address and search bar", "value": address},
}}}
}
@@ -339,6 +339,7 @@ func runToolFixture(mode string) {
map[string]any{"element_token": "s2:4", "role": "AXButton", "label": "Delete all"},
map[string]any{"element_token": "s2:5", "role": "AXButton", "label": "Send"},
map[string]any{"element_token": "s2:6", "role": "AXButton", "label": "Send"},
+ map[string]any{"element_token": "s2:7", "role": "AXLink", "label": "Kettle\u00a0[snapshot]"},
}}}
}
break
@@ -1135,21 +1136,34 @@ func TestLocalToolCuaMacAgentChromeKeepsTabsItsOwnInputChangesLate(t *testing.T)
t.Cleanup(func() { agentChromePID = original })
c.op.manager.agentChromeOwner = c.op
c.op.chromeTabs, c.op.chromePID, c.op.chromeWindow = 1, 42, 9
+ // The click below presses a row of page text, which lists no press.
+ c.snapshots = newSnapshotRows()
+ c.snapshots.record(windowRead{Snapshot: "s1", PID: 42, Window: 9, Tree: `- [1] AXStaticText = "Sort by time"`})
// A tab the task's own input opens or closes may show only after the
// input returns; the task keeps the count the strip settles on.
+ // The input's result says what it changed in the window, and nothing
+ // when it changed neither the tabs nor the front tab.
for _, step := range []struct {
- keys string
- want int
- }{{`["cmd","t"]`, 2}, {`["cmd","w"]`, 1}} {
- if _, err := c.call(t.Context(), "hotkey", json.RawMessage(`{"pid":42,"window_id":9,"keys":`+step.keys+`}`)); err != nil {
+ keys, note string
+ want int
+ }{{`["cmd","t"]`, `This input opened 1 new tab(s); the one in front shows \"Tab 1\". To go back, close it with the \"Close\" button`, 2}, {`["cmd","w"]`, `This input closed 1 tab(s); the tab in front shows \"Tab 0\".`, 1}} {
+ result, err := c.call(t.Context(), "hotkey", json.RawMessage(`{"pid":42,"window_id":9,"keys":`+step.keys+`}`))
+ if err != nil {
t.Fatal(err)
}
if c.op.chromeTabs != step.want {
t.Fatalf("tabs after the task's own %s=%d, want %d", step.keys, c.op.chromeTabs, step.want)
}
- if _, err := c.call(t.Context(), "click", json.RawMessage(`{"pid":42,"window_id":9,"element_token":"s1:1"}`)); err != nil {
+ if !strings.Contains(string(result), step.note) {
+ t.Fatalf("result after the task's own %s=%s, want note %s", step.keys, result, step.note)
+ }
+ result, err = c.call(t.Context(), "click", json.RawMessage(`{"pid":42,"window_id":9,"element_token":"s1:1"}`))
+ 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") {
+ t.Fatalf("result of a click on page text that changed no tab=%s", result)
+ }
}
if err := c.drain(); err != nil {
t.Fatal(err)
@@ -1538,6 +1552,10 @@ func TestLocalToolCuaMacInputsFindTheirTargetWhenTheyRun(t *testing.T) {
if result, err := c.call(t.Context(), "type_text", json.RawMessage(`{"pid":42,"window_id":9,"role":"AXTextArea","name":"Comment","text":"hi"}`)); err != nil || failed(result) {
t.Fatalf("located type_text result=%s err=%v", result, err)
}
+ // A page label's no-break space matches the space the Agent writes.
+ 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)
+ }
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)
}
@@ -1569,7 +1587,7 @@ func TestLocalToolCuaMacInputsFindTheirTargetWhenTheyRun(t *testing.T) {
}
sent = append(sent, call.Name+" "+fmt.Sprint(call.Arguments["element_token"]))
}
- if want := []string{"click s1:15", "click s1:15", "type_text s2:3", "click s2:6"}; !slices.Equal(sent, want) {
+ if want := []string{"click s1:15", "click s1:15", "type_text s2:3", "click s2:7", "click s2:6"}; !slices.Equal(sent, want) {
t.Fatalf("sent=%v, want %v", sent, want)
}
if err := c.drain(); err != nil {
diff --git a/apps/computer/local-daemon/internal/linger/localtools/manager.go b/apps/computer/local-daemon/internal/linger/localtools/manager.go
index 9ea9d4f6..e031fe87 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/manager.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/manager.go
@@ -232,8 +232,10 @@ type operation struct {
// chromeTabs is the tab count of the Computer's own browser after this
// task's last input there, and chromePID and chromeWindow the browser
// and window this task opened with launch_app; see checkAgentChromeTabs.
- // Guarded by mu.
+ // chromeTitle is the front tab's title read with chromeTabs, empty until
+ // the task's first input there. Guarded by mu.
chromeTabs int
+ chromeTitle string
chromePID int
chromeWindow float64
closeOnce sync.Once