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.

refactor(computer): remove recognize_text

jeffreye5beca3cc80b
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index 0a7d3b22..8582e206 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -348,7 +348,7 @@ the tabs are found by role and place in the window, not by their names, which
follow the user's language. The Daemon finds the running Chrome by its
executable wherever the app is installed. The user's Chrome takes no keys from
the Computer (`COMPUTER_KEYS_REFUSED`), in any of its windows, in tool calls,
-`run_actions` steps, paged `recognize_text` reads and scripts: a shortcut
+`run_actions` steps and scripts: a shortcut
runs as a menu command in the Chrome window that has the keyboard, and Cua
types text as keys that all read as the A key. A key named by its
`element_token` goes to the app the token was read from, and a key that names
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
index 0a2bc5ba..0102fe34 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_browser.go
@@ -628,7 +628,7 @@ func userChromePID(ctx context.Context) (int, error) {
return pid, nil
}
-// userChromeKeys refuses a key tool, or a paged read, that reaches the user's
+// userChromeKeys refuses a key tool that reaches the user's
// everyday Chrome, in any of its windows. A key named by its element_token
// goes to the app the token was read from, and a key that names no app is
// refused while that Chrome runs.
diff --git a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome_pace.go b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome_pace.go
index 1c736822..20ad7b36 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/agent_chrome_pace.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/agent_chrome_pace.go
@@ -20,7 +20,7 @@ import (
// The Computer's own browser is where Agents use sites that watch for
// automated browsing. Every input it receives, from a tool call, a batch step,
-// a script or a paged text read, passes the same pace: a pause like a person's
+// or a script, passes the same pace: a pause like a person's
// between inputs, a budget per task and per day, and a stop once the Agent
// reports a check that only the user may pass. The model decides what a page
// shows; the Computer only enforces what follows from that decision.
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua.go b/apps/computer/local-daemon/internal/linger/localtools/cua.go
index 7147f9ec..3e0eca62 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/cua.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/cua.go
@@ -190,7 +190,6 @@ func (m *Manager) openCua(ctx context.Context, op *operation) (*cuaSession, []to
}
tools = append(tools, tool{Name: "run_actions", Description: batchDescription, InputSchema: schema(batchProperties, "actions")})
if runtime.GOOS == "darwin" {
- tools = append(tools, tool{Name: "recognize_text", Description: recognizeTextDescription, InputSchema: recognizeTextSchema()})
tools = append(tools, tool{Name: "report_blocker", Description: reportBlockerDescription, InputSchema: reportBlockerSchema()})
}
tools = append(tools, tool{Name: checkPermissionsTool, Description: "Read Cua application permissions without prompting. Also reports an unresolved prior action.", InputSchema: schema(map[string]any{})})
@@ -219,7 +218,6 @@ const MacToolGuide = `Computer tools on this Mac (MCP server "computer"):
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.
- 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.
-- recognize_text({pid, window_id, region?, pages?, next_key?}) reads the text in a window's pixels, such as words inside a picture, in any language; it types nothing. pages with next_key reads a picture viewer page by page in one call.
- 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.
The Computer's own browser takes input at a person's pace, within a budget per task and per day, and a script there sends at most 20 inputs: return what you have and look at the window before the next script. A tab that a link in the script opens is the task's and is in front afterwards. The browser tools stay off every site a task opened in that browser.
Plan as many steps as you can in one run_actions call, as in one script; its read shows their effect, so do not read again before the next input unless you need another window. Keys are often shorter than clicks: in Finder, cmd+shift+g then a path and Return opens a folder, cmd+down opens the selected item, and in the Trash cmd+delete puts the selected item back.
@@ -374,12 +372,6 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
return c.reportBlocker(args)
}
}
- // A one-page read sends nothing. A paged read presses keys, so it takes
- // the lease and the action journal below as other input does.
- paged := name == "recognize_text" && runtime.GOOS == "darwin" && pagedRead(args)
- if name == "recognize_text" && runtime.GOOS == "darwin" && !paged {
- return c.recognizeText(ctx, args, false)
- }
arguments, err := cuaCallArguments(args)
if err != nil {
return nil, err
@@ -397,12 +389,12 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
}
// A key to the user's Chrome reaches the window that has the keyboard,
// whichever window it names, so it is refused before anything is taken.
- if name == "hotkey" || name == "type_text" || name == "press_key" || paged {
+ if name == "hotkey" || name == "type_text" || name == "press_key" {
if err := c.userChromeKeys(ctx, arguments); err != nil {
return nil, err
}
}
- agentChrome, err := c.claimAgentChromeInput(ctx, name, arguments, paged)
+ agentChrome, err := c.claimAgentChromeInput(ctx, name, arguments)
if err != nil {
return nil, err
}
@@ -420,7 +412,7 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
return nil, err
}
}
- paced := agentChrome && (inputTools[name] || paged || ownScript)
+ paced := agentChrome && (inputTools[name] || ownScript)
scriptInputs := 0
if paced {
// A script reserves nothing: its own pause runs inside it, and its
@@ -495,12 +487,6 @@ func (c *cuaSession) call(ctx context.Context, name string, args json.RawMessage
if err := c.requirePermissions(ctx); err != nil {
return nil, err
}
- if paged {
- result, err := c.recognizeText(ctx, args, agentChrome)
- confirmed = !errors.Is(err, errOutcomeUnknown)
- c.stampInput(arguments["pid"])
- return result, err
- }
// Only a script to the Computer's own browser wakes it first.
wake := scriptTarget
if !ownScript {
@@ -589,9 +575,6 @@ func (c *cuaSession) needsFocus(ctx context.Context, name string, args json.RawM
switch {
case cuaReadTools[name]:
return false
- case name == "recognize_text":
- // A paged read presses keys in the window.
- return runtime.GOOS != "darwin" || pagedRead(args)
case runtime.GOOS != "darwin" || !backgroundTools[name]:
return true
}
@@ -652,13 +635,13 @@ func cuaCallArguments(args json.RawMessage) (map[string]any, error) {
// claimAgentChromeInput reports whether the call reaches the Computer's own
// Chrome and, if so, claims it for this Operation.
-func (c *cuaSession) claimAgentChromeInput(ctx context.Context, name string, arguments map[string]any, paged bool) (bool, error) {
+func (c *cuaSession) claimAgentChromeInput(ctx context.Context, name string, arguments map[string]any) (bool, error) {
// The Computer's own browser takes input and window changes from one
// Operation at a time. A script may reach any app from its body, and an
// input without a pid may reach it by its element_token alone, so both
// take the lease while that Chrome runs.
agentChrome := false
- leased := inputTools[name] || windowTools[name] || paged
+ leased := inputTools[name] || windowTools[name]
if _, pid := arguments["pid"]; runtime.GOOS == "darwin" && (name == "run_script" || leased && !pid) {
own, err := c.agentChromeRunning(ctx)
if err != nil {
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_text.go b/apps/computer/local-daemon/internal/linger/localtools/cua_text.go
deleted file mode 100644
index 1ebf1afd..00000000
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_text.go
+++ /dev/null
@@ -1,352 +0,0 @@
-package localtools
-
-import (
- "bytes"
- "context"
- "encoding/base64"
- "encoding/json"
- "errors"
- "fmt"
- "image"
- "image/png"
- "os"
- "os/exec"
- "path/filepath"
- "strings"
- "time"
-
- // The window screenshot is PNG or JPEG.
- _ "image/jpeg"
-)
-
-// recognizeTextDescription describes the macOS text recognition tool.
-const recognizeTextDescription = "Read the text in a window's pixels, such as words inside a picture that the accessibility tree does not have. It recognizes the languages macOS knows, without being told which, and returns one line per run of text with its position as fractions of the window or region: x from the left, y from the top. region crops the window first, in pixels of the window's screenshot. pages reads a picture viewer page by page: after each page it presses next_key (right, down or pagedown) to the window in the background, and reads only the part of the window that changed between pages. It stops early, returning the pages read and why, when a key changes nothing or is refused, or the call's time runs out. It types nothing and keeps the element tokens of your last read."
-
-// recognizePagesMax bounds how many pages one call reads.
-const recognizePagesMax = 20
-
-// recognizeNextKeys are the keys that turn a page: they move, never submit.
-var recognizeNextKeys = map[string]bool{"right": true, "down": true, "pagedown": true}
-
-// recognizeTextFields are the arguments recognize_text takes.
-var recognizeTextFields = map[string]bool{"pid": true, "window_id": true, "region": true, "pages": true, "next_key": true}
-
-// recognizePageSettle is how long a viewer gets to show the next page.
-var recognizePageSettle = 700 * time.Millisecond
-
-func recognizeTextSchema() json.RawMessage {
- encoded, _ := json.Marshal(schema(map[string]any{
- "pid": macPID,
- "window_id": map[string]any{"type": "integer"},
- "region": map[string]any{"type": "object", "description": "Optional part of the window, in screenshot pixels.", "properties": map[string]any{
- "x": map[string]any{"type": "number"}, "y": map[string]any{"type": "number"}, "width": map[string]any{"type": "number"}, "height": map[string]any{"type": "number"}}},
- "pages": map[string]any{"type": "integer", "minimum": 1, "maximum": recognizePagesMax, "description": "How many pages of a picture viewer to read, from the one shown. Needs next_key."},
- "next_key": map[string]any{"type": "string", "enum": []string{"right", "down", "pagedown"}, "description": "The key that shows the next page."},
- }, "pid", "window_id"))
- return encoded
-}
-
-// visionScript runs macOS Vision text recognition on each image file named
-// by its arguments and prints one JSON object per recognized line, top first,
-// with the index of its file. One process loads the recognizer once.
-const visionScript = `ObjC.import('Vision');
-function run(argv) {
- const lines = [];
- for (let f = 0; f < argv.length; f++) {
- const handler = $.VNImageRequestHandler.alloc.initWithURLOptions($.NSURL.fileURLWithPath(argv[f]), $({}));
- const request = $.VNRecognizeTextRequest.alloc.init;
- request.recognitionLevel = 0;
- request.usesLanguageCorrection = true;
- request.automaticallyDetectsLanguage = true;
- if (!handler.performRequestsError($([request]), null)) throw new Error('text recognition failed');
- for (let i = 0; i < request.results.count; i++) {
- const observation = request.results.objectAtIndex(i);
- const candidate = observation.topCandidates(1).objectAtIndex(0);
- const box = observation.boundingBox;
- lines.push(JSON.stringify({file: f, text: ObjC.unwrap(candidate.string), x: box.origin.x, y: 1 - box.origin.y - box.size.height, confidence: candidate.confidence}));
- }
- }
- return lines.join('\n');
-}`
-
-// recognizedLine is one line that Vision returned.
-type recognizedLine struct {
- File int `json:"file"`
- Text string `json:"text"`
- X float64 `json:"x"`
- Y float64 `json:"y"`
- Confidence float64 `json:"confidence"`
-}
-
-// recognizePagingBudget bounds the time one call spends turning pages, so
-// the pages it read come back before the Runtime gives up on the call.
-var recognizePagingBudget = 30 * time.Second
-
-// recognizeText captures a window as Cua shows it, also while it is covered
-// or on another Space, and reads its text with macOS Vision. The capture is a
-// display-only read, so the Agent's element tokens stay valid. With pages, a
-// movement key between captures turns the pages of a picture viewer, and only
-// the part of the window that changed is read, so the text around the viewer
-// is not repeated for every page. A paged read sends keys, so the call path
-// treats it as input (see paged); a one-page read is a read.
-func (c *cuaSession) recognizeText(ctx context.Context, args json.RawMessage, agentChrome bool) (output json.RawMessage, callErr error) {
- // The lease and the review read these fields by their exact names, so a
- // field they would not see is refused rather than decoded.
- var fields map[string]json.RawMessage
- if json.Unmarshal(args, &fields) != nil {
- return nil, fmt.Errorf("recognize_text: arguments are not an object: %w", errNotSent)
- }
- for field := range fields {
- if !recognizeTextFields[field] {
- return nil, fmt.Errorf("recognize_text: unknown argument %q: %w", field, errNotSent)
- }
- }
- var params struct {
- PID *float64 `json:"pid"`
- Window *float64 `json:"window_id"`
- Region *struct {
- X, Y, Width, Height float64
- } `json:"region"`
- Pages int `json:"pages"`
- NextKey string `json:"next_key"`
- }
- if json.Unmarshal(args, &params) != nil || params.PID == nil || params.Window == nil {
- return nil, fmt.Errorf("COMPUTER_TARGET_REQUIRED: recognize_text needs pid and window_id: %w", errNotSent)
- }
- pages := max(params.Pages, 1)
- if pages > recognizePagesMax || (pages > 1 && !recognizeNextKeys[params.NextKey]) {
- return nil, fmt.Errorf("recognize_text: pages is 1 to %d, and more than one page needs next_key right, down or pagedown: %w", recognizePagesMax, errNotSent)
- }
- if err := c.checkDesktop(); err != nil {
- return nil, err
- }
- if err := c.startSession(ctx, "auto"); err != nil {
- return nil, err
- }
- first, refused, err := c.windowPixels(ctx, *params.PID, *params.Window)
- if err != nil || refused != nil {
- return refused, err
- }
- // The region is checked on the first page, before any key is sent.
- region := image.Rectangle{}
- if params.Region != nil {
- region = image.Rect(int(params.Region.X), int(params.Region.Y), int(params.Region.X+params.Region.Width), int(params.Region.Y+params.Region.Height)).Intersect(first.Bounds())
- if region.Empty() {
- return nil, fmt.Errorf("recognize_text: region is outside the %dx%d screenshot: %w", first.Bounds().Dx(), first.Bounds().Dy(), errNotSent)
- }
- }
- shots, changed, note, sent := []image.Image{first}, image.Rectangle{}, "", 0
- defer func() {
- if callErr != nil && sent > 0 {
- callErr = fmt.Errorf("recognize_text: %d %s key(s) were sent, so the viewer may now show page %d: %w", sent, params.NextKey, sent+1, callErr)
- }
- }()
- budget := time.Now().Add(recognizePagingBudget)
- if deadline, ok := ctx.Deadline(); ok && deadline.Add(-10*time.Second).Before(budget) {
- budget = deadline.Add(-10 * time.Second)
- }
- for page := 1; page < pages; page++ {
- if time.Now().Add(recognizePageSettle).After(budget) {
- note = fmt.Sprintf("\nStopped after page %d: the time for one call ran out; read the next pages in another call.", page)
- break
- }
- var pressed json.RawMessage
- if agentChrome {
- pressed, err = c.agentChromeKey(ctx, int(*params.PID), *params.Window, "press_key", map[string]any{"key": params.NextKey})
- } else {
- pressed, err = c.client.request(ctx, "tools/call", map[string]any{"name": "press_key", "arguments": map[string]any{
- "pid": *params.PID, "window_id": *params.Window, "key": params.NextKey, "session": c.label}})
- }
- if err != nil {
- sent++
- return nil, err
- }
- if failed(pressed) {
- note = fmt.Sprintf("\nStopped after page %d: the %s key was refused: %s", page, params.NextKey, strings.TrimSpace(string(pressed)))
- break
- }
- sent++
- if err := sleepContext(ctx, recognizePageSettle); err != nil {
- return nil, err
- }
- shot, refused, err := c.windowPixels(ctx, *params.PID, *params.Window)
- if err != nil {
- return nil, err
- }
- if refused != nil {
- note = fmt.Sprintf("\nStopped after page %d: the window could not be read after the %s key: %s", page, params.NextKey, strings.TrimSpace(string(refused)))
- break
- }
- if shot.Bounds() != first.Bounds() {
- note = fmt.Sprintf("\nStopped after page %d: the window changed size after the %s key, so its pages cannot be compared.", page, params.NextKey)
- break
- }
- area := changedArea(shots[len(shots)-1], shot)
- if area.Empty() {
- note = fmt.Sprintf("\nStopped after page %d: the %s key changed nothing.", page, params.NextKey)
- break
- }
- changed = changed.Union(area)
- shots = append(shots, shot)
- }
- area := region
- if area.Empty() && len(shots) > 1 {
- area = changed
- }
- encoded := make([][]byte, len(shots))
- for i, shot := range shots {
- if encoded[i], err = encodeArea(shot, area); err != nil {
- return nil, err
- }
- }
- lines, err := visionText(ctx, encoded)
- if err != nil {
- return nil, err
- }
- var text strings.Builder
- switch {
- case len(shots) == 1:
- fmt.Fprintf(&text, "%d line(s) of text in window %v:", len(lines), *params.Window)
- case params.Region != nil:
- fmt.Fprintf(&text, "%d page(s) of window %v, read in the given region:", len(shots), *params.Window)
- default:
- fmt.Fprintf(&text, "%d page(s) of window %v, read in the area that changed between pages (x=%d y=%d %dx%d screenshot pixels):", len(shots), *params.Window, area.Min.X, area.Min.Y, area.Dx(), area.Dy())
- }
- for page := range shots {
- if len(shots) > 1 {
- fmt.Fprintf(&text, "\n## Page %d", page+1)
- }
- for _, line := range lines {
- if line.File != page {
- continue
- }
- fmt.Fprintf(&text, "\n- x=%.2f y=%.2f %q", line.X, line.Y, line.Text)
- if line.Confidence < 0.5 {
- text.WriteString(" (unsure)")
- }
- }
- }
- text.WriteString(note)
- return json.Marshal(map[string]any{"content": []any{map[string]string{"type": "text", "text": text.String()}}})
-}
-
-// pagedRead reports whether a recognize_text call turns pages, and so sends
-// keys to the window.
-func pagedRead(args json.RawMessage) bool {
- var params struct {
- Pages int `json:"pages"`
- }
- return json.Unmarshal(args, &params) == nil && params.Pages > 1
-}
-
-// windowPixels captures window as a display-only read and decodes it. A
-// refusal from Cua comes back as the result to return.
-func (c *cuaSession) windowPixels(ctx context.Context, pid, window float64) (image.Image, json.RawMessage, error) {
- shot, err := c.client.request(ctx, "tools/call", map[string]any{"name": "get_window_state", "arguments": map[string]any{
- "pid": pid, "window_id": window, "include_accessibility_tree": false, "display_only": true, "session": c.label}})
- if err != nil {
- return nil, nil, err
- }
- var reply struct {
- IsError bool `json:"isError"`
- Content []struct {
- Type string `json:"type"`
- Data string `json:"data"`
- } `json:"content"`
- }
- if err := json.Unmarshal(shot, &reply); err != nil {
- return nil, nil, fmt.Errorf("recognize_text: unreadable window state: %w", err)
- }
- if reply.IsError {
- return nil, shot, nil
- }
- for _, item := range reply.Content {
- if item.Type == "image" {
- pixels, err := base64.StdEncoding.DecodeString(item.Data)
- if err != nil {
- return nil, nil, errors.New("recognize_text: the window screenshot is not base64")
- }
- picture, _, err := image.Decode(bytes.NewReader(pixels))
- if err != nil {
- return nil, nil, fmt.Errorf("recognize_text: decode the screenshot: %w", err)
- }
- return picture, nil, nil
- }
- }
- return nil, nil, errors.New("COMPUTER_WINDOW_UNREADABLE: the window has no screenshot to read")
-}
-
-// changedArea returns the bounding box of the pixels that differ between two
-// screenshots of one size, or an empty rectangle when they match. Small color
-// noise does not count as a change.
-func changedArea(before, after image.Image) image.Rectangle {
- area := image.Rectangle{}
- bounds := before.Bounds()
- for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
- for x := bounds.Min.X; x < bounds.Max.X; x++ {
- r1, g1, b1, _ := before.At(x, y).RGBA()
- r2, g2, b2, _ := after.At(x, y).RGBA()
- if absDiff(r1, r2)+absDiff(g1, g2)+absDiff(b1, b2) > 3*0x1800 {
- area = area.Union(image.Rect(x, y, x+1, y+1))
- }
- }
- }
- return area
-}
-
-func absDiff(a, b uint32) uint32 {
- if a > b {
- return a - b
- }
- return b - a
-}
-
-// encodeArea returns the part of picture inside area as PNG, or all of it
-// when area is empty.
-func encodeArea(picture image.Image, area image.Rectangle) ([]byte, error) {
- if !area.Empty() {
- part, ok := picture.(interface {
- SubImage(image.Rectangle) image.Image
- })
- if !ok {
- return nil, errors.New("recognize_text: the screenshot cannot be cropped")
- }
- picture = part.SubImage(area)
- }
- var out bytes.Buffer
- if err := png.Encode(&out, picture); err != nil {
- return nil, err
- }
- return out.Bytes(), nil
-}
-
-// visionText runs visionScript on each image in a private temporary
-// directory that is removed afterwards. A line's File is the index of its
-// image.
-var visionText = func(ctx context.Context, images [][]byte) ([]recognizedLine, error) {
- directory, err := os.MkdirTemp("", "linger-text-")
- if err != nil {
- return nil, err
- }
- defer os.RemoveAll(directory)
- arguments := []string{"-l", "JavaScript", "-e", visionScript}
- for i, pixels := range images {
- path := filepath.Join(directory, fmt.Sprintf("page-%d.png", i))
- if err := os.WriteFile(path, pixels, 0o600); err != nil {
- return nil, err
- }
- arguments = append(arguments, path)
- }
- output, err := exec.CommandContext(ctx, "/usr/bin/osascript", arguments...).Output()
- if err != nil {
- return nil, fmt.Errorf("recognize_text: macOS text recognition failed: %w", err)
- }
- var lines []recognizedLine
- for _, row := range strings.Split(strings.TrimSpace(string(output)), "\n") {
- var line recognizedLine
- if row != "" && json.Unmarshal([]byte(row), &line) == nil && line.Text != "" {
- lines = append(lines, line)
- }
- }
- return lines, nil
-}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_text_darwin_test.go b/apps/computer/local-daemon/internal/linger/localtools/cua_text_darwin_test.go
deleted file mode 100644
index 113c9ce2..00000000
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_text_darwin_test.go
+++ /dev/null
@@ -1,126 +0,0 @@
-package localtools
-
-import (
- "bytes"
- "context"
- "encoding/json"
- "errors"
- "image"
- "image/png"
- "path/filepath"
- "strings"
- "testing"
- "time"
-)
-
-// pagedReadSession stubs the lock screen check and Vision, and reports the
-// size of each image Vision was given.
-func pagedReadSession(t *testing.T, mode string) (*cuaSession, string, *[]image.Rectangle) {
- t.Helper()
- locked, vision, settle := screenLocked, visionText, recognizePageSettle
- t.Cleanup(func() { screenLocked, visionText, recognizePageSettle = locked, vision, settle })
- screenLocked = func() bool { return false }
- recognizePageSettle = 0
- var sizes []image.Rectangle
- visionText = func(_ context.Context, images [][]byte) ([]recognizedLine, error) {
- lines := []recognizedLine{}
- for i, encoded := range images {
- picture, err := png.Decode(bytes.NewReader(encoded))
- if err != nil {
- return nil, err
- }
- sizes = append(sizes, picture.Bounds())
- lines = append(lines, recognizedLine{File: i, Text: "page text", Confidence: 1})
- }
- return lines, nil
- }
- marker := filepath.Join(t.TempDir(), "calls.jsonl")
- return cuaFixtureSession(t, mode, marker), marker, &sizes
-}
-
-func TestRecognizeTextReadsPagesUntilAKeyChangesNothing(t *testing.T) {
- c, marker, sizes := pagedReadSession(t, "pages")
- result, err := c.call(t.Context(), "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":5,"next_key":"right"}`))
- if err != nil {
- t.Fatal(err)
- }
- text := string(result)
- // Pages 1-3 differ; the third key changes nothing, so a fourth is never read.
- if !strings.Contains(text, "3 page(s)") || !strings.Contains(text, "## Page 3") || !strings.Contains(text, "Stopped after page 3: the right key changed nothing") {
- t.Fatalf("result = %s", text)
- }
- // Only the changed pixels, from (10,6) to (14,6), are read on each page.
- if len(*sizes) != 3 || (*sizes)[0].Dx() != 5 || (*sizes)[0].Dy() != 1 || !strings.Contains(text, "x=10 y=6 5x1") {
- t.Fatalf("Vision images = %v", *sizes)
- }
- if calls := fixtureCalls(t, marker); len(calls) != 3 {
- t.Fatalf("keys sent = %v, want 3", calls)
- }
-}
-
-func TestRecognizeTextKeepsThePagesReadBeforeARefusedKey(t *testing.T) {
- c, _, sizes := pagedReadSession(t, "pages-refused")
- result, err := c.call(t.Context(), "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":5,"next_key":"right"}`))
- if err != nil {
- t.Fatal(err)
- }
- if text := string(result); !strings.Contains(text, "2 page(s)") || !strings.Contains(text, "Stopped after page 2: the right key was refused") || len(*sizes) != 2 {
- t.Fatalf("result = %s, images %v", text, *sizes)
- }
-}
-
-func TestRecognizeTextChecksTheRegionBeforeAnyKey(t *testing.T) {
- c, marker, _ := pagedReadSession(t, "pages")
- _, err := c.call(t.Context(), "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":5,"next_key":"right","region":{"x":100,"y":100,"width":5,"height":5}}`))
- if !errors.Is(err, errNotSent) || len(fixtureCalls(t, marker)) != 0 {
- t.Fatalf("err = %v, keys %v", err, fixtureCalls(t, marker))
- }
- // A region inside the window is read as given on every page.
- c, _, sizes := pagedReadSession(t, "pages")
- result, err := c.call(t.Context(), "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":2,"next_key":"right","region":{"x":0,"y":0,"width":20,"height":10}}`))
- if err != nil || !strings.Contains(string(result), "read in the given region") || len(*sizes) != 2 || (*sizes)[1] != image.Rect(0, 0, 20, 10) {
- t.Fatalf("result = %s err=%v images %v", result, err, *sizes)
- }
-}
-
-func TestRecognizeTextStopsPagingWhenTheBudgetRunsOut(t *testing.T) {
- c, marker, _ := pagedReadSession(t, "pages")
- budget := recognizePagingBudget
- t.Cleanup(func() { recognizePagingBudget = budget })
- recognizePagingBudget = -time.Second
- result, err := c.call(t.Context(), "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":5,"next_key":"right"}`))
- if err != nil || !strings.Contains(string(result), "the time for one call ran out") || len(fixtureCalls(t, marker)) != 0 {
- t.Fatalf("result = %s err=%v", result, err)
- }
-}
-
-func TestRecognizeTextRecordsAnUnknownKeyOutcome(t *testing.T) {
- c, marker, _ := pagedReadSession(t, "pages-hang")
- ctx, cancel := context.WithCancel(t.Context())
- done := make(chan error, 1)
- go func() {
- _, err := c.call(ctx, "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":3,"next_key":"right"}`))
- done <- err
- }()
- for deadline := time.Now().Add(5 * time.Second); len(fixtureCalls(t, marker)) == 0; time.Sleep(time.Millisecond) {
- if time.Now().After(deadline) {
- t.Fatal("the key was not sent")
- }
- }
- cancel()
- err := <-done
- if !errors.Is(err, errOutcomeUnknown) || !strings.Contains(err.Error(), "1 right key(s) were sent") {
- t.Fatalf("err = %v, want an unknown outcome that names the key sent", err)
- }
- if !c.op.manager.journal.blocked() {
- t.Fatal("a key with an unknown outcome left the journal open for new input")
- }
-}
-
-func TestRecognizeTextRefusesFieldsTheReviewDoesNotRead(t *testing.T) {
- c, marker, _ := pagedReadSession(t, "pages")
- _, err := c.call(t.Context(), "recognize_text", json.RawMessage(`{"pid":42,"window_id":9,"pages":3,"next_key":"right","PID":7}`))
- if !errors.Is(err, errNotSent) || len(fixtureCalls(t, marker)) != 0 {
- t.Fatalf("err = %v, keys %v", err, fixtureCalls(t, marker))
- }
-}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/cua_text_test.go b/apps/computer/local-daemon/internal/linger/localtools/cua_text_test.go
deleted file mode 100644
index ce673f5a..00000000
--- a/apps/computer/local-daemon/internal/linger/localtools/cua_text_test.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package localtools
-
-import (
- "bytes"
- "image"
- "image/color"
- "image/png"
- "testing"
-)
-
-func TestEncodeAreaCropsToTheArea(t *testing.T) {
- picture := image.NewRGBA(image.Rect(0, 0, 40, 30))
- for _, test := range []struct {
- area image.Rectangle
- width, height int
- }{
- {image.Rect(30, 20, 40, 30), 10, 10},
- {image.Rectangle{}, 40, 30},
- } {
- encoded, err := encodeArea(picture, test.area)
- if err != nil {
- t.Fatal(err)
- }
- part, err := png.Decode(bytes.NewReader(encoded))
- if err != nil || part.Bounds().Dx() != test.width || part.Bounds().Dy() != test.height {
- t.Fatalf("%v: bounds=%v err=%v", test.area, part.Bounds(), err)
- }
- }
-}
-
-func TestChangedAreaBoundsTheDifferingPixels(t *testing.T) {
- blank := image.NewRGBA(image.Rect(0, 0, 40, 30))
- page := image.NewRGBA(blank.Bounds())
- page.Set(5, 6, color.White)
- page.Set(20, 12, color.White)
- if got := changedArea(blank, page); got != image.Rect(5, 6, 21, 13) {
- t.Fatalf("area = %v", got)
- }
- // Faint noise is not a new page.
- noise := image.NewRGBA(blank.Bounds())
- noise.Set(5, 6, color.RGBA{8, 8, 8, 255})
- if got := changedArea(blank, noise); !got.Empty() {
- t.Fatalf("noise area = %v", got)
- }
-}
diff --git a/apps/computer/local-daemon/internal/linger/localtools/lanes_test.go b/apps/computer/local-daemon/internal/linger/localtools/lanes_test.go
index 4ddccc52..d6ef1480 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/lanes_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/lanes_test.go
@@ -425,8 +425,6 @@ func TestCuaInputNeedsFocusUnlessBackgroundToAnotherApp(t *testing.T) {
darwin bool
}{
{"get_window_state", `{"pid":42}`, false},
- {"recognize_text", `{"pid":42}`, false},
- {"recognize_text", `{"pid":42,"pages":3}`, true},
{"click", `{"pid":42,"window_id":3,"element_token":"s1:5"}`, false},
{"double_click", `{"element_token":"s1:5"}`, true},
{"scroll", `{"pid":9}`, false},
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 3bfbe612..2c4308c0 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
@@ -1002,7 +1002,6 @@ func TestLocalToolCuaMacAgentChromeServesOneTaskAndNeverComesForward(t *testing.
{"launch_app", `{"bundle_id":"com.google.Chrome","urls":["https://example.com/"]}`},
{"launch_app", `{"name":"Google Chrome","urls":["https://example.com/"]}`},
{"run_script", `{"script":"return 1"}`},
- {"recognize_text", `{"pid":42,"window_id":9,"pages":3,"next_key":"right"}`},
} {
if _, err := c.call(t.Context(), call.name, json.RawMessage(call.args)); err == nil || !strings.Contains(err.Error(), "COMPUTER_BUSY") {
t.Fatalf("%s err=%v, want busy", call.name, err)
@@ -1961,7 +1960,6 @@ func TestLocalToolCuaMacEverydayChromeOpensTheComputersWindowAndTakesNoKeys(t *t
{"press_key", `{"pid":42,"window_id":12,"key":"return","element_token":"s1:1","modifiers":[]}`},
{"press_key", `{"pid":42,"window_id":12,"key":"cmd+r","element_token":"s1:1"}`},
{"press_key", `{"pid":42,"window_id":9,"key":"return","element_token":"s9:1"}`},
- {"recognize_text", `{"pid":42,"window_id":12,"pages":2,"next_key":"pagedown"}`},
// A token never read leaves the named pid.
{"press_key", `{"pid":42,"key":"return","element_token":"s7:1"}`},
} {
diff --git a/apps/computer/local-daemon/internal/permission/allowlist.go b/apps/computer/local-daemon/internal/permission/allowlist.go
index 73c3e584..1222b0c6 100644
--- a/apps/computer/local-daemon/internal/permission/allowlist.go
+++ b/apps/computer/local-daemon/internal/permission/allowlist.go
@@ -13,8 +13,7 @@ import (
// effect stays on this screen: reading it, or moving the pointer, scrolling,
// hovering, going back a page, and arranging windows. Clicking, typing, keys,
// dragging, navigation to a new address, uploads, and dialogs are judged.
-// recognize_text is read-only only for one page: a paged read presses its
-// next_key between pages. report_blocker stops the task's own input to the
+// report_blocker stops the task's own input to the
// Computer's own browser, and rate_limited also cools the site down there for
// every task on this Computer.
var readOnlyLocalTools = map[string]bool{
@@ -55,12 +54,6 @@ func ReadOnlyLocalTool(tool, input string) bool {
if readOnlyLocalTools[tool] {
return true
}
- if tool == "mcp__computer__recognize_text" {
- var arguments struct {
- Pages int `json:"pages"`
- }
- return json.Unmarshal([]byte(input), &arguments) == nil && arguments.Pages <= 1
- }
if tool == "mcp__browser__browser_tabs" {
// Listing tabs and switching to an open one change nothing; opening
// and closing tabs are judged.
diff --git a/apps/computer/local-daemon/internal/permission/allowlist_test.go b/apps/computer/local-daemon/internal/permission/allowlist_test.go
index d0a2bc89..6b8c115f 100644
--- a/apps/computer/local-daemon/internal/permission/allowlist_test.go
+++ b/apps/computer/local-daemon/internal/permission/allowlist_test.go
@@ -21,9 +21,6 @@ func TestLocalWriteToolJudgesEveryNonReadOnlyLocalAction(t *testing.T) {
{"mcp__computer__click", `{"x":1,"y":2}`, true},
{"mcp__computer__type_text", `{"text":"hi"}`, true},
{"mcp__computer__scroll", `{}`, false},
- {"mcp__computer__recognize_text", `{"pid":1,"window_id":2}`, false},
- {"mcp__computer__recognize_text", `{"pid":1,"window_id":2,"pages":1}`, false},
- {"mcp__computer__recognize_text", `{"pid":1,"window_id":2,"pages":4,"next_key":"right"}`, true},
{"mcp__linger__send_message", `{}`, false},
{"Bash", `{"command":"ls"}`, false},
}
diff --git a/apps/computer/local-daemon/internal/permission/gui_reuse.go b/apps/computer/local-daemon/internal/permission/gui_reuse.go
index cab7d854..83191a2d 100644
--- a/apps/computer/local-daemon/internal/permission/gui_reuse.go
+++ b/apps/computer/local-daemon/internal/permission/gui_reuse.go
@@ -32,9 +32,8 @@ var reusableHotkeys = map[string]bool{
}
// GUIReuseKey names the shape of a desktop navigation call: a movement or
-// dismissal key, a tab or history shortcut, a scroll, a paged recognize_text
-// (which has the shape of its next_key), or a run_actions batch made only of
-// those. Calls of one shape share an allow verdict within a Run
+// dismissal key, a tab or history shortcut, a scroll, or a run_actions batch
+// made only of those. Calls of one shape share an allow verdict within a Run
// (see Reviewer). Clicks, typing, dragging, scripts and other shortcuts have
// no shape: each is judged on its own.
func GUIReuseKey(tool, input string) (string, bool) {
@@ -63,25 +62,6 @@ func GUIReuseKey(tool, input string) (string, bool) {
if !ok {
return "", false
}
- if name == "recognize_text" {
- // The read itself is display-only; the keys between pages are what
- // is judged, so the call shares the verdict of that key.
- for field := range arguments {
- switch field {
- case "pid", "window_id", "region", "pages", "next_key":
- default:
- return "", false
- }
- }
- key, _ := arguments["next_key"].(string)
- step := map[string]any{"key": key}
- for _, field := range []string{"pid", "window_id"} {
- if value, present := arguments[field]; present {
- step[field] = value
- }
- }
- return stepReuseKey("press_key", step)
- }
return stepReuseKey(name, arguments)
}
diff --git a/apps/computer/local-daemon/internal/permission/gui_reuse_test.go b/apps/computer/local-daemon/internal/permission/gui_reuse_test.go
index e5fb6257..67e6b831 100644
--- a/apps/computer/local-daemon/internal/permission/gui_reuse_test.go
+++ b/apps/computer/local-daemon/internal/permission/gui_reuse_test.go
@@ -29,9 +29,6 @@ func TestGUIReuseKeyNamesNavigationShapesOnly(t *testing.T) {
{"no pid", "mcp__computer__click", `{"x":1,"y":2}`, ""},
{"foreground scroll", "mcp__computer__scroll", `{"pid":719,"window_id":433,"direction":"down","delivery_mode":"foreground"}`, ""},
{"batch with a foreground scroll", "mcp__computer__run_actions", `{"actions":[{"tool":"scroll","pid":719,"window_id":433,"direction":"down"},{"tool":"scroll","pid":719,"window_id":433,"direction":"down","delivery_mode":"foreground"}]}`, ""},
- {"paged text read has its key's shape", "mcp__computer__recognize_text", `{"pid":719,"window_id":433,"pages":4,"next_key":"right","region":{"x":1,"y":2,"width":3,"height":4}}`, "press_key:right@719/433"},
- {"paged text read with another field", "mcp__computer__recognize_text", `{"pid":719,"window_id":433,"pages":4,"next_key":"right","PID":999}`, ""},
- {"paged text read without a known key", "mcp__computer__recognize_text", `{"pid":719,"window_id":433,"pages":4,"next_key":"return"}`, ""},
{"background scroll", "mcp__computer__scroll", `{"pid":719,"window_id":433,"direction":"down","delivery_mode":"background"}`, "scroll@719/433"},
} {
t.Run(test.name, func(t *testing.T) {
diff --git a/skills/builtin/humanlike-browse/1.0.6/SKILL.md b/skills/builtin/humanlike-browse/1.0.6/SKILL.md
index 352bf591..9d2e0515 100644
--- a/skills/builtin/humanlike-browse/1.0.6/SKILL.md
+++ b/skills/builtin/humanlike-browse/1.0.6/SKILL.md
@@ -55,8 +55,7 @@ return {title: first.label, rating: page.tree_markdown};
## Read
- Read with `get_window_state`. It returns the whole page the browser has loaded, including the part below the window, so text already on the page needs no scrolling. Pass `query` to narrow a long page. If a read says it was cut, read again narrower instead of guessing.
-- Text inside pictures: `recognize_text`; in a picture viewer, `pages` with `next_key`.
-- A state the tree does not show, such as liked or followed: look with `include_screenshot: true`.
+- Text inside pictures, or a state the tree does not show, such as liked or followed: look with `include_screenshot: true`.
- To repeat a flow over items, use `run_script`. A script there sends at most 20 inputs: return what it extracted, look at the window, then continue. Many sites open a result in a new tab; the script then reads that tab, so read the tab in front before the next step.
- Stop scrolling when two reads add no new items. Read only what the task needs: one search per keyword, and never reopen an item already read.
- Act only in the tabs this task opened. A click that opens a new tab is the task's tab. Close each item's tab with its tab's Close button after reading it, and the task's last tab when done. If a tab the task did not open is in front, stop and tell the user.