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): carry the Agent's read tokens over the Computer's own reads
jeffrey9f9ab481daf6
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.goindex 1f094656..089debe6 100644--- a/apps/computer/local-daemon/internal/linger/localtools/cua.go+++ b/apps/computer/local-daemon/internal/linger/localtools/cua.go@@ -543,7 +543,7 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessagedriverStarted := time.Now()result, err := c.sendInput(ctx, name, arguments, appKeys, agentChrome)if c.snapshots != nil {- c.snapshots.sent()+ c.snapshots.sent(name)}driverMs = time.Since(driverStarted).Milliseconds()if err == nil {diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go b/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.goindex dd92f290..5b14ece6 100644--- a/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go+++ b/apps/computer/local-daemon/internal/linger/localtools/cua_snapshots.go@@ -153,13 +153,20 @@ func (s *snapshotRows) remap(arguments map[string]any) {// sent fences off every read so far: the input just sent may have changed// the page, so a token of an earlier read must not land on a row that only-// reads the same.-func (s *snapshotRows) sent() {+// reads the same. A read changes nothing, so it fences nothing: the Agent's+// own read must still carry over the Computer's reads before its next input.+func (s *snapshotRows) sent(name string) {+ if readTools[name] {+ return+ }s.mu.Lock()s.fence = s.seqs.mu.Unlock()}+// readTools only read the screen, so the page a token names stays as it was.+var readTools = map[string]bool{"list_windows": true, "get_window_state": true, "get_desktop_state": true, "get_screen_size": true, "get_cursor_position": true, "clipboard_read": true}+// 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.goindex 19751534..7cf14f81 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@@ -56,23 +56,33 @@ func TestSnapshotRowsCarriesTokensOverTheComputersOwnReads(t *testing.T) {t.Fatalf("script = %v, want %s", script["script"], want)}+ // The Agent's own read is no input: its tokens still carry over the+ // tab check that follows it.+ s.sent("get_window_state")+ s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000005", "pid": 7, "window_id": 9, "tree_markdown": ownTree}))+ read := map[string]any{"element_token": "s00000004:4"}+ s.remap(read)+ if read["element_token"] != "s00000005:4" {+ t.Fatalf("token of the Agent's read = %v, want s00000005:4", read["element_token"])+ }+// After an input, an older read is never carried over: the page may// have changed under a row that reads the same.- s.sent()- s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000005", "pid": 7, "window_id": 9, "tree_markdown": agentTree}))- before := map[string]any{"element_token": "s00000004:4"}+ s.sent("click")+ s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000006", "pid": 7, "window_id": 9, "tree_markdown": agentTree}))+ before := map[string]any{"element_token": "s00000005:4"}s.remap(before)- if before["element_token"] != "s00000004:4" {+ if before["element_token"] != "s00000005:4" {t.Fatalf("read before an input = %v, want its own stale token", before["element_token"])}// A diff that says the indices shifted keeps only the rows it lists.- s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000006", "pid": 7, "window_id": 9, "since": "s00000005", "since_status": "diff",- "tree_diff": "since s00000005: 1 added.\nreindexed: rows after 3 moved by 1\n+ [5] AXLink \"Kettle\" [actions=[press]]"}))- s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000007", "pid": 7, "window_id": 9, "tree_markdown": agentTree}))- shifted := map[string]any{"element_token": "s00000006:4"}+ s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000007", "pid": 7, "window_id": 9, "since": "s00000006", "since_status": "diff",+ "tree_diff": "since s00000006: 1 added.\nreindexed: rows after 3 moved by 1\n+ [5] AXLink \"Kettle\" [actions=[press]]"}))+ s.observe(readCall(nil), readResult(t, map[string]any{"snapshot_id": "s00000008", "pid": 7, "window_id": 9, "tree_markdown": agentTree}))+ shifted := map[string]any{"element_token": "s00000007:4"}s.remap(shifted)- if shifted["element_token"] != "s00000006:4" {+ if shifted["element_token"] != "s00000007:4" {t.Fatalf("row of a reindexed diff = %v, want its own stale token", shifted["element_token"])}