@roam-agent/roam-computer-use 0.0.0-stage → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -2
  3. package/assets/reference/img.jpg +0 -0
  4. package/docs/README.md +45 -0
  5. package/docs/content/docs/explanation/action-pipeline.mdx +36 -0
  6. package/docs/content/docs/explanation/architecture.mdx +161 -0
  7. package/docs/content/docs/explanation/index.mdx +19 -0
  8. package/docs/content/docs/explanation/meta.json +5 -0
  9. package/docs/content/docs/explanation/observation-pipeline.mdx +37 -0
  10. package/docs/content/docs/explanation/platform-boundary.mdx +37 -0
  11. package/docs/content/docs/explanation/state-and-scheduling.mdx +35 -0
  12. package/docs/content/docs/how-to-guides/develop-and-validate.mdx +112 -0
  13. package/docs/content/docs/how-to-guides/index.mdx +12 -0
  14. package/docs/content/docs/how-to-guides/linux.mdx +68 -0
  15. package/docs/content/docs/how-to-guides/meta.json +1 -0
  16. package/docs/content/docs/how-to-guides/troubleshooting.mdx +126 -0
  17. package/docs/content/docs/index.mdx +67 -0
  18. package/docs/content/docs/meta.json +5 -0
  19. package/docs/content/docs/reference/agent/contract.mdx +162 -0
  20. package/docs/content/docs/reference/agent/index.mdx +8 -0
  21. package/docs/content/docs/reference/agent/meta.json +8 -0
  22. package/docs/content/docs/reference/agent/tools.mdx +221 -0
  23. package/docs/content/docs/reference/codebase.mdx +139 -0
  24. package/docs/content/docs/reference/configuration.mdx +113 -0
  25. package/docs/content/docs/reference/index.mdx +28 -0
  26. package/docs/content/docs/reference/meta.json +10 -0
  27. package/docs/content/docs/reference/platforms/index.mdx +18 -0
  28. package/docs/content/docs/reference/platforms/macos/accessibility.mdx +61 -0
  29. package/docs/content/docs/reference/platforms/macos/actions.mdx +63 -0
  30. package/docs/content/docs/reference/platforms/macos/capture.mdx +58 -0
  31. package/docs/content/docs/reference/platforms/macos/implementation.mdx +98 -0
  32. package/docs/content/docs/reference/platforms/macos/index.mdx +16 -0
  33. package/docs/content/docs/reference/platforms/macos/meta.json +10 -0
  34. package/docs/content/docs/reference/platforms/macos/root-targeting.mdx +47 -0
  35. package/docs/content/docs/reference/platforms/meta.json +8 -0
  36. package/docs/content/docs/reference/platforms/windows.mdx +75 -0
  37. package/docs/content/docs/tutorials/getting-started.mdx +46 -0
  38. package/docs/content/docs/tutorials/index.mdx +10 -0
  39. package/docs/content/docs/tutorials/meta.json +1 -0
  40. package/extensions/computer-use.ts +235 -0
  41. package/native/linux/bridge-rs/Cargo.lock +1204 -0
  42. package/native/linux/bridge-rs/Cargo.toml +21 -0
  43. package/native/linux/bridge-rs/src/atspi.rs +670 -0
  44. package/native/linux/bridge-rs/src/error.rs +65 -0
  45. package/native/linux/bridge-rs/src/lib.rs +11 -0
  46. package/native/linux/bridge-rs/src/main.rs +1110 -0
  47. package/native/linux/bridge-rs/src/protocol.rs +49 -0
  48. package/native/linux/bridge-rs/src/state.rs +293 -0
  49. package/native/linux/bridge-rs/src/wayland.rs +89 -0
  50. package/native/linux/bridge-rs/src/x11.rs +909 -0
  51. package/native/linux/bridge-rs/tests/protocol_tests.rs +73 -0
  52. package/native/macos/activity_glow.swift +169 -0
  53. package/native/macos/bridge.swift +3968 -0
  54. package/native/windows/bridge-rs/Cargo.lock +396 -0
  55. package/native/windows/bridge-rs/Cargo.toml +30 -0
  56. package/native/windows/bridge-rs/src/capture.rs +561 -0
  57. package/native/windows/bridge-rs/src/error.rs +81 -0
  58. package/native/windows/bridge-rs/src/input.rs +501 -0
  59. package/native/windows/bridge-rs/src/lib.rs +85 -0
  60. package/native/windows/bridge-rs/src/main.rs +1683 -0
  61. package/native/windows/bridge-rs/src/protocol.rs +53 -0
  62. package/native/windows/bridge-rs/src/refs.rs +237 -0
  63. package/native/windows/bridge-rs/src/state.rs +55 -0
  64. package/native/windows/bridge-rs/src/uia.rs +1252 -0
  65. package/native/windows/bridge-rs/src/window.rs +718 -0
  66. package/native/windows/bridge-rs/tests/protocol_tests.rs +252 -0
  67. package/native/windows/bridge-rs/tests/refs_tests.rs +86 -0
  68. package/native/windows/bridge-rs/tests/state_tests.rs +33 -0
  69. package/package.json +105 -5
  70. package/prebuilt/macos/arm64/bridge +0 -0
  71. package/prebuilt/macos/x64/bridge +0 -0
  72. package/roam/README.md +52 -0
  73. package/roam/bridge/macos/arm64/bridge +0 -0
  74. package/roam/bridge/macos/x64/bridge +0 -0
  75. package/roam/bridge/manifest.json +20 -0
  76. package/roam/helper-path.d.mts +9 -0
  77. package/roam/helper-path.mjs +36 -0
  78. package/roam/identity.d.mts +16 -0
  79. package/roam/identity.mjs +64 -0
  80. package/roam/index.ts +51 -0
  81. package/roam/redirect.ts +51 -0
  82. package/roam/repair.ts +120 -0
  83. package/scripts/build-native.mjs +286 -0
  84. package/scripts/lib/roam-bridge.mjs +98 -0
  85. package/scripts/setup-helper.mjs +635 -0
  86. package/src/actions.ts +130 -0
  87. package/src/bridge.ts +2594 -0
  88. package/src/cdp.ts +658 -0
  89. package/src/config.ts +226 -0
  90. package/src/contract.ts +107 -0
  91. package/src/extension/index.ts +9 -0
  92. package/src/find-params.ts +21 -0
  93. package/src/note.ts +195 -0
  94. package/src/outline.ts +702 -0
  95. package/src/output.ts +134 -0
  96. package/src/permissions.ts +111 -0
  97. package/src/platform/architecture.ts +23 -0
  98. package/src/platform/coerce.ts +16 -0
  99. package/src/platform/index.ts +61 -0
  100. package/src/platform/linux/backend.ts +186 -0
  101. package/src/platform/linux/helper.ts +238 -0
  102. package/src/platform/macos/backend.ts +147 -0
  103. package/src/platform/macos/browser.ts +110 -0
  104. package/src/platform/macos/helper.ts +369 -0
  105. package/src/platform/macos/permissions.ts +146 -0
  106. package/src/platform/types.ts +229 -0
  107. package/src/platform/windows/backend.ts +142 -0
  108. package/src/platform/windows/helper.ts +140 -0
  109. package/src/root-selection.ts +25 -0
  110. package/src/runtime.ts +129 -0
  111. package/src/state.ts +146 -0
  112. package/src/view.ts +147 -0
@@ -0,0 +1,68 @@
1
+ ---
2
+ title: 'Run on Linux'
3
+ description: 'Set up the Linux AT-SPI2 helper and understand its X11, Wayland, headless, and security boundaries.'
4
+ ---
5
+
6
+ Linux uses the same root/state/ref navigation architecture as macOS and Windows. Its per-user Rust helper uses AT-SPI2 semantics first. In an X11 session it can enrich those semantics with EWMH window state, X11 capture, and guarded XTEST physical input.
7
+
8
+ ## Setup
9
+
10
+ Run Pi as the same user and inside the same graphical session as the target applications. The session needs a working D-Bus and AT-SPI2 accessibility bus, and applications must export useful accessibility interfaces. A normal install places the helper at:
11
+
12
+ ```text
13
+ ~/.pi/agent/helpers/pi-computer-use/linux-bridge
14
+ ```
15
+
16
+ The upstream [AT-SPI development guide](https://gnome.pages.gitlab.gnome.org/at-spi2-core/devel-docs/index.html) describes the accessibility stack. Containers, system services, `sudo`, and unrelated SSH sessions do not automatically inherit the graphical user's bus.
17
+
18
+ ## Capability matrix
19
+
20
+ | Capability | X11 | Wayland | Delivery |
21
+ | --- | --- | --- | --- |
22
+ | Discover accessible roots | Yes; EWMH enriches geometry, stacking, focus, and minimized state | Yes, when exported | AT-SPI2, plus EWMH on X11 |
23
+ | Press/click an actionable ref | Capability-gated | Capability-gated | AT-SPI `Action` |
24
+ | Replace editable text | Capability-gated | Capability-gated | AT-SPI `EditableText` |
25
+ | Read/wait on accessible text | Capability-gated | Capability-gated | AT-SPI `Text`/snapshots |
26
+ | Screenshot/visual observation | Yes | No | XComposite PNG; `GetImage` fallback may be stale or obscured |
27
+ | Coordinate pointer, keyboard, scroll, and drag | Non-headless only | No | XTEST after semantic delivery is unavailable/insufficient |
28
+ | Force focus | Non-headless only | No | EWMH `_NET_ACTIVE_WINDOW` |
29
+ | Managed Chromium pages | Yes | Yes | Loopback CDP |
30
+ | Open a URL | Yes | Yes | `xdg-open` |
31
+
32
+ “Capability-gated” means the target must export the corresponding AT-SPI interface. X11 physical fallback reports an `unknown` outcome unless later observation or a postcondition verifies the result. Capture prefers XComposite so covered windows can still be read; the `GetImage` fallback explicitly warns that pixels may be stale or obscured.
33
+
34
+ ## Background and headless guarantees
35
+
36
+ Linux always attempts AT-SPI semantics first. Semantic delivery does not request compositor focus or inject global input; background delivery is not invisible execution, because an application may still update its visible window.
37
+
38
+ With `headless: true` or the `ax_only`/`background` delivery policy, the helper never invokes XTEST or EWMH focus. Unsupported semantic input fails closed. With non-headless `default` or `foreground` policy on X11, actions may fall back to global XTEST input and focus may use EWMH. Those operations can move the real pointer, type into the focused application, and interfere with the user's session. Native Wayland has no such physical fallback.
39
+
40
+ Managed CDP actions also avoid desktop focus, but `launch_browser` starts a normal visible browser; this project's `headless` option is an input-delivery policy, not Chromium's `--headless` switch.
41
+
42
+ ## Wayland portal boundary
43
+
44
+ The standardized [ScreenCast portal](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.ScreenCast.html) can expose user-selected streams through PipeWire. The [RemoteDesktop portal](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.RemoteDesktop.html) can negotiate input devices and may return restore tokens when the desktop grants persistence. Starting a session normally invokes compositor-owned selection/consent, and backend support varies.
45
+
46
+ On Wayland, diagnostics performs only a read-only property probe and reports the RemoteDesktop and ScreenCast interface versions plus advertised device, source, and cursor-mode bitmasks. It does not create a portal request or session and cannot display a chooser.
47
+
48
+ There is no portal session, PipeWire frame, input dispatch, or restore-token implementation. Installing a portal backend therefore does not enable Wayland capture or input.
49
+
50
+ ## Security boundaries
51
+
52
+ - The helper is a local stdin/stdout child process and opens no helper network listener.
53
+ - It can inspect applications exposed on the current user's AT-SPI bus; run only trusted agents and extensions in that session.
54
+ - Password-role values are omitted and explicit reads are rejected, though application mislabeling remains possible.
55
+ - On X11, capture can read window pixels and non-headless physical fallback can control the global pointer/keyboard and request focus. These are broad desktop capabilities; strict headless/background policy blocks XTEST and focus, but does not make AT-SPI or requested X11 observation private.
56
+ - On Wayland, portal diagnostics are read-only; capture and input are not implemented.
57
+ - CDP is separate and gives local processes that can reach its loopback port powerful page access. `launch_browser` uses a fresh non-default temporary profile, matching modern Chrome's [remote-debugging security policy](https://developer.chrome.com/blog/remote-debugging-port), rather than the user's normal profile.
58
+
59
+ ## Browser discovery
60
+
61
+ `launch_browser` searches common Chrome/Chromium or Helium locations and `PATH`. For an AppImage or custom install, set an authoritative executable override:
62
+
63
+ ```bash
64
+ PI_COMPUTER_USE_CHROME_EXECUTABLE=/absolute/path/to/chrome
65
+ PI_COMPUTER_USE_HELIUM_EXECUTABLE=/absolute/path/to/helium.AppImage
66
+ ```
67
+
68
+ Manual CDP launches must use a non-default `--user-data-dir` together with `--remote-debugging-port`; set `PI_COMPUTER_USE_CDP_PORT` to that loopback port.
@@ -0,0 +1 @@
1
+ { "title": "How-to guides", "icon": "Wrench", "pages": ["index", "troubleshooting", "linux", "develop-and-validate"] }
@@ -0,0 +1,126 @@
1
+ ---
2
+ title: 'Troubleshoot setup and runtime failures'
3
+ description: 'Repair helper installation, permissions, capture, stale state, and action delivery problems.'
4
+ ---
5
+
6
+ Start with `/computer-use` in Pi to confirm the active configuration and its source. For macOS implementation details and Apple API citations, use the [macOS reference](../reference/platforms/macos/implementation.mdx).
7
+
8
+ macOS uses an installed helper app and TCC permissions. Windows uses the active desktop session. Linux uses a per-user helper and the graphical session's AT-SPI2 bus.
9
+
10
+ ## Repair Linux accessibility
11
+
12
+ Run Pi as the same user and inside the same graphical session as the target apps. Check the bus with:
13
+
14
+ ```bash
15
+ busctl --user get-property org.a11y.Bus /org/a11y/bus org.a11y.Bus Address
16
+ ```
17
+
18
+ If it is missing, install or enable your distribution's AT-SPI2 services and restart the graphical login session. Reinstall the helper with `node scripts/setup-helper.mjs --platform linux --runtime`; for development use `npm run build:linux` followed by `node scripts/setup-helper.mjs --platform linux`. The installer replaces the helper whenever the build output differs from the installed copy.
19
+
20
+ AT-SPI semantic presses/clicks and editable-text replacement are attempted first on Linux. X11 also supports window capture plus non-headless EWMH focus and XTEST pointer/keyboard/scroll/drag fallback. Strict headless, `ax_only`, and `background` policies block XTEST/focus. Native Wayland remains semantic-only. Diagnostics may read portal version and capability properties, but never creates or starts a portal session. Interactive portal capture and input dispatch are disabled, so installing a portal backend alone does not enable them. The [Linux support guide](./linux.mdx) lists the full capability matrix.
21
+
22
+ ## Repair a missing macOS helper
23
+
24
+ The normal runtime requires this executable inside the resolved helper app:
25
+
26
+ ```text
27
+ ~/Applications/pi-computer-use.app/Contents/MacOS/bridge
28
+ ```
29
+
30
+ Existing writable system-wide installs remain at `/Applications/pi-computer-use.app`. Set `PI_COMPUTER_USE_HELPER_APP_PATH` only when an explicit location is needed for development or testing.
31
+
32
+ Install the packaged, downloaded, or locally buildable helper with:
33
+
34
+ ```bash
35
+ node scripts/setup-helper.mjs --runtime
36
+ ```
37
+
38
+ For source development, rebuild first and then run the same installer:
39
+
40
+ ```bash
41
+ npm run build:native
42
+ node scripts/setup-helper.mjs --runtime
43
+ ```
44
+
45
+ There is no `--force` installer option. If replacement is refused because only an ad-hoc signing identity is available, prefer a signed helper or managed local signing identity. Set `PI_COMPUTER_USE_ALLOW_ADHOC_UPDATE=1` only when intentionally replacing a development helper.
46
+
47
+ ## Grant macOS permissions
48
+
49
+ Grant Accessibility and Screen Recording to the resolved `pi-computer-use.app`, normally `~/Applications/pi-computer-use.app`, then choose Recheck. Recheck restarts the helper before checking again.
50
+
51
+ The helper checks Accessibility with `AXIsProcessTrusted` and Screen Recording with Core Graphics preflight plus a ScreenCaptureKit content query ([macOS permissions reference](../reference/platforms/macos/accessibility.mdx#trust-and-permission)). System Settings labels can vary by macOS version, so identify the app by its name and path rather than relying on one pane label.
52
+
53
+ If setup reports `source.attribution: caller`, the bridge is not running as the installed helper app. Restart Pi and rerun setup so the client launches the installed bundle.
54
+
55
+ If permission checks still disagree after recheck, reset only this bundle's entries and grant them again:
56
+
57
+ ```bash
58
+ tccutil reset Accessibility com.injaneity.pi-computer-use
59
+ tccutil reset ScreenCapture com.injaneity.pi-computer-use
60
+ ```
61
+
62
+ A successful reset command only removes the stored decision; it does not grant permission.
63
+
64
+ ## Fix an empty Accessibility outline
65
+
66
+ Confirm Accessibility is enabled for `pi-computer-use.app`, choose Recheck, and observe again. If one app alone remains sparse, inspect it in fused or visual mode because the target may expose little Accessibility data:
67
+
68
+ ```ts
69
+ observe_ui({ root: "@r1", mode: "fused" })
70
+ ```
71
+
72
+ The helper can only report attributes and actions exposed through the target's Accessibility tree. OCR can add visual text evidence, but OCR-only `pictureOnly` nodes are not semantic action targets.
73
+
74
+ ## Fix a failed or black window capture
75
+
76
+ Confirm that:
77
+
78
+ - Screen Recording is enabled for `pi-computer-use.app`;
79
+ - the target still has an open window;
80
+ - the root has a Core Graphics window ID;
81
+ - the window wasn't closed between discovery and observation.
82
+
83
+ The helper captures with ScreenCaptureKit first and then tries `/usr/sbin/screencapture` for the same window ID. A successful permission readiness check does not guarantee that either method can capture every later window ([capture reference](../reference/platforms/macos/capture.mdx)).
84
+
85
+ If the target is ambiguous, find the exact root by app and window title, then observe it:
86
+
87
+ ```ts
88
+ find_roots({ app: "TextEdit", text: "Untitled" })
89
+ observe_ui({ root: "@r1" })
90
+ ```
91
+
92
+ ## Handle strict headless rejection
93
+
94
+ `headless: true` permits only Accessibility actions on macOS. Coordinate targeting, Accessibility fallbacks that would need synthesized pointer input, every `typeText` and `keypress`, and web text replacement fail with `foreground_required` before the helper activates an app or posts events. The bridge does not retry them in the foreground.
95
+
96
+ Use a current semantic ref when the target exposes the required action. If the workflow genuinely needs synthesized events, run that action without strict headless mode and let the checked fallback policy decide whether foreground delivery is allowed.
97
+
98
+ ## Recover from stale state or refs
99
+
100
+ A mutation must use the `stateId` that owns its refs and must still match the resource epoch. Use the successor state returned by `act_ui`. If another actor changed the app, the state was evicted, or the target identity is uncertain, call `observe_ui` and resolve the target again.
101
+
102
+ The native helper may reacquire an element from stored role, identifier, label, and geometry, but this is best effort and does not override epoch checks.
103
+
104
+ ## Recover from rejected coordinates
105
+
106
+ Coordinates are image pixels owned by one image-bearing state. Observe again if the window moved, resized, changed, or was replaced. Outline-only roots, including unmatched macOS menus, cannot accept coordinate actions.
107
+
108
+ ## Enable browser JavaScript fallback on macOS
109
+
110
+ The macOS browser fallback uses `osascript` for supported browser-window operations. If the returned error specifically says that JavaScript through Apple Events is disabled, enable “Allow JavaScript from Apple Events” in that browser's developer settings and retry. This setting is only relevant when that fallback path reports the error.
111
+
112
+ ## Enable browser windows
113
+
114
+ If browser roots are refused, run `/computer-use`. When `browser_use` is disabled, enable it in the project or global configuration:
115
+
116
+ ```json
117
+ {
118
+ "browser_use": true
119
+ }
120
+ ```
121
+
122
+ If `launch_browser` cannot find the selected browser, set `PI_COMPUTER_USE_CHROME_EXECUTABLE` or `PI_COMPUTER_USE_HELIUM_EXECUTABLE` to an executable absolute path. A manual Chromium CDP launch needs both `--remote-debugging-port` and a non-default `--user-data-dir`.
123
+
124
+ ## Use an interactive desktop
125
+
126
+ When macOS grants are missing, start Pi with its UI available so the setup selector can open System Settings and recheck. After permissions are granted, Pi can run noninteractively, but macOS automation still requires a logged-in graphical user session. On Windows, use an unlocked interactive desktop session. On Linux, run Pi inside the target user's graphical session.
@@ -0,0 +1,67 @@
1
+ ---
2
+ title: 'pi-computer-use documentation'
3
+ description: 'Learn the state-scoped model for observing and controlling macOS, Windows, and Linux interfaces from Pi.'
4
+ full: true
5
+ ---
6
+
7
+ <section className="quiet-docs-intro">
8
+ <div className="quiet-intro-copy">
9
+ <span className="quiet-eyebrow"><span className="signal signal-live" /> technical documentation / pi extension</span>
10
+ <h1>pi-computer-use</h1>
11
+ <p>Learn how an agent discovers, reads, and operates real desktop software through immutable observations and checked actions.</p>
12
+ </div>
13
+ <aside className="quiet-learning-index" aria-label="What this documentation covers">
14
+ <span>in this documentation</span>
15
+ <ol>
16
+ <li><b>01</b><p><strong>set up the runtime</strong>install the extension and grant platform access.</p></li>
17
+ <li><b>02</b><p><strong>understand the model</strong>move from roots to observations to state-scoped actions.</p></li>
18
+ <li><b>03</b><p><strong>operate reliably</strong>inspect exact contracts, limits, and recovery paths.</p></li>
19
+ </ol>
20
+ </aside>
21
+ </section>
22
+
23
+ <section className="quiet-start-panel">
24
+ <div>
25
+ <span>recommended first lesson</span>
26
+ <h2>get one checked desktop action working</h2>
27
+ <p>Install the extension, inspect a controllable root, create an immutable observation, and perform an action against that state.</p>
28
+ </div>
29
+ <a className="quiet-button quiet-button-primary" href="/docs/tutorials/getting-started">open the tutorial <span aria-hidden="true">→</span></a>
30
+ </section>
31
+
32
+ <section className="quiet-model-section">
33
+ <div className="quiet-model-copy">
34
+ <span>core concept / 01</span>
35
+ <h2>the operating model</h2>
36
+ <p>Every action refers to a saved observation. Acting produces a new state, so the agent never has to treat a stale screenshot as current truth.</p>
37
+ <a href="/docs/explanation/architecture">read the architecture explanation →</a>
38
+ </div>
39
+ <div className="system-figure" aria-label="Find, observe, and act workflow">
40
+ <div className="system-figure-label">state-scoped control loop</div>
41
+ <div className="system-node system-node-source"><span>01</span><strong>find roots</strong><small>desktop / browser</small></div>
42
+ <div className="system-connector"><i /></div>
43
+ <div className="system-node system-node-active"><span>02</span><strong>observe</strong><small>immutable state s1</small></div>
44
+ <div className="system-connector"><i /></div>
45
+ <div className="system-node"><span>03</span><strong>act</strong><small>checked transition</small></div>
46
+ <div className="system-return"><span>new state s2</span></div>
47
+ </div>
48
+ </section>
49
+
50
+ <div className="quiet-section-heading">
51
+ <span>browse the manual</span>
52
+ <h2>choose by intent</h2>
53
+ </div>
54
+
55
+ <div className="quiet-route-grid">
56
+ <a href="/docs/tutorials"><span>01 / learn</span><strong>tutorials</strong><p>follow a guided path from installation to a working action.</p></a>
57
+ <a href="/docs/how-to-guides"><span>02 / do</span><strong>how-to guides</strong><p>solve setup, capture, permission, and runtime problems.</p></a>
58
+ <a href="/docs/explanation"><span>03 / understand</span><strong>explanation</strong><p>understand immutable state, scheduling, and checked execution.</p></a>
59
+ <a href="/docs/reference"><span>04 / look up</span><strong>reference</strong><p>inspect exact tools, configuration, platform APIs, and limits.</p></a>
60
+ </div>
61
+
62
+ <div className="quiet-status-line">
63
+ <span><i className="signal signal-live" /> macos 14+</span>
64
+ <span><i className="signal signal-live" /> windows interactive desktop</span>
65
+ <span><i className="signal signal-live" /> linux at-spi2 session</span>
66
+ <span><i className="signal signal-active" /> generated tool schemas</span>
67
+ </div>
@@ -0,0 +1,5 @@
1
+ {
2
+ "title": "pi-computer-use",
3
+ "root": true,
4
+ "pages": ["index", "tutorials", "how-to-guides", "explanation", "reference"]
5
+ }
@@ -0,0 +1,162 @@
1
+ ---
2
+ title: 'Agent state and action contract'
3
+ description: 'Operating contract for refs, immutable state, progressive disclosure, actions, batching, browser roots, and parallel calls.'
4
+ ---
5
+
6
+ {/* This file is generated by scripts/docs-generators/generate-source-references.mjs. Do not edit it directly. */}
7
+
8
+ The normal loop is:
9
+
10
+ 1. Find a desktop or browser root.
11
+ 2. Observe that root and retain its `stateId`.
12
+ 3. Search, expand, or inspect that immutable state.
13
+ 4. Act using the same `stateId` and its `@e` refs.
14
+
15
+ ## Tool surface
16
+
17
+ | Tool | Purpose |
18
+ | --- | --- |
19
+ | `find_roots` | Return a bounded, ranked set of desktop and CDP browser-page roots. |
20
+ | `observe_ui` | Capture the current/frontmost root or one exact `@r` root and return a compact list of actionable `@e` controls plus `stateId`. |
21
+ | `search_ui` | Run a bounded, ranked query over the full cached outline. |
22
+ | `expand_ui` | Show local outline context for one ref. |
23
+ | `inspect_ui` | Show fields, rects, actions, and evidence for one ref. |
24
+ | `act_ui` | Perform checked actions and return the resulting saved state, showing its changes or a full view when needed. |
25
+ | `read_text` | Read fixed pages from state-owned `@e` text or immutable `@o` output. |
26
+ | `wait_for` | Wait for a precise, optionally scoped condition. |
27
+ | `launch_browser` | Start a managed CDP browser and return its observed page state. |
28
+ | `navigate_browser` | Navigate the browser page owned by a state. |
29
+ | `evaluate_browser` | Evaluate JavaScript in the browser page owned by a state. |
30
+
31
+ The exact registered descriptions, prompt guidance, parameters, enums, and constraints are generated from source in [the tool reference](./tools.mdx). This page owns the cross-tool operating contract and examples instead of duplicating those schemas.
32
+
33
+ ## Refs and state
34
+
35
+ `find_roots` returns roots such as `@r1`. Every desktop window, transient surface, and CDP page participates in that same forest. `observe_ui` returns element refs such as `@e12` and a `stateId`.
36
+
37
+ Every tool that consumes an `@e` ref also requires its owning `stateId`. A state remains queryable while it is in the bounded store, but a mutation from an old resource epoch is rejected as stale. `act_ui` returns the next usable `stateId`; consume it directly instead of observing again. Observe again only after an uncertain external mutation or state eviction.
38
+
39
+ Truncated textual output receives an immutable session-local ref such as `@o1`. Continue it with `read_text({ ref: "@o1", offset })`; output refs don't use a UI state id. Tool-provided `@o` offsets are UTF-8 byte offsets, while `@e` text offsets count Unicode characters.
40
+
41
+ Nodes marked `pictureOnly` have visual evidence but no platform accessibility element. Semantic actions cannot target them. Coordinate actions are available only from a current image-bearing desktop state.
42
+
43
+ ## Progressive disclosure
44
+
45
+ Use `observe_ui({ root: "@r1" })` for the compact first view. It lists actionable controls only; containers, static text, tooltips, geometry, and unlabeled non-text controls are omitted and counted:
46
+
47
+ ```text
48
+ Controls (3 of 212 nodes, stateId S7, root @e1):
49
+ @e12 textarea "Message" = "draft" [focused]
50
+ @e18 button "Search the web"
51
+ @e27 link "New chat"
52
+ … 209 other nodes hidden, including 4 unlabeled controls. Use search_ui to find more; expand_ui({ stateId: "S7", ref: "@e1", depth: 2 }) or observe_ui detail "outline" for structure.
53
+ ```
54
+
55
+ The focused control is always listed first, followed by controls inside an open sheet or dialog. If a root exposes no actionable controls, the response falls back to the folded outline and says so. Use `observe_ui({ root: "@r1", detail: "outline" })` to get the folded outline directly. Then query without another capture:
56
+
57
+ ```ts
58
+ search_ui({ stateId, text: "Save" })
59
+ expand_ui({ stateId, ref: "@e7", depth: 3 })
60
+ inspect_ui({ stateId, ref: "@e12" })
61
+ ```
62
+
63
+ `semantic` observation is cheapest, `fused` is the default, and `visual` forces visual text evidence. Search requires at least one of `text`, `role`, or `capability`. It ranks exact, prefix, and substring text before conservative fuzzy matches, returns a fixed top set with the total match count, and asks the caller to refine broad queries. Search can escalate OCR once when the original desktop look omitted it; that refresh is checked against the state's resource epoch.
64
+
65
+ ## Acting and batching
66
+
67
+ The public action shape is always transactional:
68
+
69
+ ```ts
70
+ act_ui({ stateId, actions: [{ action: "press", ref: "@e12" }] })
71
+ ```
72
+
73
+ When an action has an observable completion signal, attach it to the same
74
+ transaction. Pi waits through the platform change-notification path and marks
75
+ the execution `didnt` with `postcondition_failed` if the application swallowed
76
+ the delivered event:
77
+
78
+ ```js
79
+ act_ui({
80
+ stateId,
81
+ actions: [{ action: "press", ref: "@e12" }],
82
+ expect: { text: "Archive completed", until: "present", timeoutMs: 3000 }
83
+ })
84
+ ```
85
+
86
+ Verification reports `verified`, `preexisting`, or `failed`. A preexisting
87
+ condition means the requested end state holds, but is not evidence that the
88
+ action caused it. Use `ref` for one exact element or `scopeRef` for a subtree;
89
+ role-only conditions must be scoped, and value checks require an exact `ref`.
90
+
91
+ Batch steps only when the second step does not need to inspect the result of the first:
92
+
93
+ ```ts
94
+ act_ui({
95
+ stateId,
96
+ actions: [
97
+ { action: "setText", ref: "@e18", text: "hello" },
98
+ { action: "press", ref: "@e22" },
99
+ ],
100
+ })
101
+ ```
102
+
103
+ Steps run sequentially against one resource and retain helper checks. The native helper uses one root baseline and final settle for the transaction, and the bridge returns one final observation. If a transition can change the meaning of later refs or requires a decision, send one action, inspect the returned state, then continue.
104
+
105
+ Clicks into editable regions establish foreground focus for later keyboard steps in the same transaction. Omit `ref` from `typeText` or `keypress` after such a click so input is sent to the editor established by that click:
106
+
107
+ ```ts
108
+ act_ui({
109
+ stateId,
110
+ actions: [
111
+ { action: "click", x: 420, y: 300 },
112
+ { action: "typeText", text: "hello" },
113
+ ],
114
+ expect: { text: "hello" },
115
+ })
116
+ ```
117
+
118
+ The runtime prefers background semantics when they are credible, verifies the result, and escalates side-effect-free failed keyboard input to foreground delivery automatically. Ambiguous pointer actions are never replayed blindly.
119
+
120
+ ### Successor views
121
+
122
+ The initial `observe_ui` response is the compact control list; expand for structure. A normal `act_ui` response saves the complete resulting state but renders only its trustworthy changes:
123
+
124
+ ```text
125
+ Successor diff (1 change, S1 → S2):
126
+ ~ @e9 (@e1 > @e9) value="hello"
127
+ Use stateId S2 for subsequent actions and queries.
128
+ ```
129
+
130
+ Confidently matched elements retain their model-facing refs across resulting states. New nodes receive new refs and removed nodes are named explicitly. The runtime returns the compact control list instead when the root was replaced, identity confidence is low, or the change budget is too large. `search_ui`, `expand_ui`, and `inspect_ui` always query the complete saved state regardless of how it was rendered.
131
+
132
+ Coordinate fallback uses image pixels from the observed state:
133
+
134
+ ```ts
135
+ act_ui({ stateId, actions: [{ action: "click", x: 420, y: 300 }] })
136
+ ```
137
+
138
+ ## Bounded output
139
+
140
+ Every model-visible textual result is limited to 48 KiB or 2,000 lines. Oversized results return a 16 KiB preview, focused-query guidance, and an immutable `@o` continuation. Discovery tools don't page through irrelevant matches: refine `find_roots` and `search_ui` instead. Continuation is intended for concrete long text, evaluation values, and diagnostics.
141
+
142
+ ## Browser use
143
+
144
+ Browser-specific commands operate only on CDP browser-page states. `launch_browser` chooses the configured browser and debugging port internally and immediately returns an observed state:
145
+
146
+ ```ts
147
+ const launched = launch_browser({ url: "https://example.com" })
148
+ act_ui({ stateId: launched.stateId, actions: [{ action: "press", ref: "@e7" }] })
149
+ navigate_browser({ stateId: returnedStateId, url: "https://openai.com" })
150
+ evaluate_browser({ stateId: returnedStateId, expression: "document.title" })
151
+ ```
152
+
153
+ Browser states use the same outline, action, text, and condition contracts as desktop states. Native browser windows remain ordinary desktop UI; use `observe_ui` and `act_ui` rather than `navigate_browser` or `evaluate_browser` on them.
154
+
155
+ ## Parallel calls
156
+
157
+ Pi may issue tool calls concurrently. Cached queries can overlap freely. Live work for different desktop processes or CDP pages can overlap; work for the same physical resource is ordered. Do not intentionally race two mutations derived from the same state: one wins and the other receives a stale-state error by design.
158
+
159
+ <details className="reference-provenance">
160
+ <summary>source provenance</summary>
161
+ <p>Generated from <a href="https://github.com/roam-agent/roam-computer-use/blob/main/src/bridge.ts"><code>src/bridge.ts</code></a>. The evidence check requires <code>find_roots</code>, <code>observe_ui</code>, <code>act_ui</code>, <code>stateId</code>; external API citations remain independently maintained.</p>
162
+ </details>
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: 'Agent reference'
3
+ description: 'Entry point for the public state/action contract and exact tool schemas.'
4
+ ---
5
+
6
+ {/* This file is generated by scripts/docs-generators/generate-source-references.mjs. Do not edit it directly. */}
7
+
8
+ Use the [state and action contract](./contract.mdx) for refs, immutable observations, progressive disclosure, batching, browser roots, and concurrency. Use the [tool schema reference](./tools.mdx) for exact descriptions, parameters, enums, and constraints extracted from `extensions/computer-use.ts`.
@@ -0,0 +1,8 @@
1
+ {
2
+ "title": "Agent",
3
+ "icon": "Bot",
4
+ "pages": [
5
+ "contract",
6
+ "tools"
7
+ ]
8
+ }