@roam-agent/roam-computer-use 0.0.0-stage → 0.5.1
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.
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/assets/reference/img.jpg +0 -0
- package/docs/README.md +45 -0
- package/docs/content/docs/explanation/action-pipeline.mdx +36 -0
- package/docs/content/docs/explanation/architecture.mdx +161 -0
- package/docs/content/docs/explanation/index.mdx +19 -0
- package/docs/content/docs/explanation/meta.json +5 -0
- package/docs/content/docs/explanation/observation-pipeline.mdx +37 -0
- package/docs/content/docs/explanation/platform-boundary.mdx +37 -0
- package/docs/content/docs/explanation/state-and-scheduling.mdx +35 -0
- package/docs/content/docs/how-to-guides/develop-and-validate.mdx +112 -0
- package/docs/content/docs/how-to-guides/index.mdx +12 -0
- package/docs/content/docs/how-to-guides/linux.mdx +68 -0
- package/docs/content/docs/how-to-guides/meta.json +1 -0
- package/docs/content/docs/how-to-guides/troubleshooting.mdx +126 -0
- package/docs/content/docs/index.mdx +67 -0
- package/docs/content/docs/meta.json +5 -0
- package/docs/content/docs/reference/agent/contract.mdx +162 -0
- package/docs/content/docs/reference/agent/index.mdx +8 -0
- package/docs/content/docs/reference/agent/meta.json +8 -0
- package/docs/content/docs/reference/agent/tools.mdx +221 -0
- package/docs/content/docs/reference/codebase.mdx +139 -0
- package/docs/content/docs/reference/configuration.mdx +113 -0
- package/docs/content/docs/reference/index.mdx +28 -0
- package/docs/content/docs/reference/meta.json +10 -0
- package/docs/content/docs/reference/platforms/index.mdx +18 -0
- package/docs/content/docs/reference/platforms/macos/accessibility.mdx +61 -0
- package/docs/content/docs/reference/platforms/macos/actions.mdx +63 -0
- package/docs/content/docs/reference/platforms/macos/capture.mdx +58 -0
- package/docs/content/docs/reference/platforms/macos/implementation.mdx +98 -0
- package/docs/content/docs/reference/platforms/macos/index.mdx +16 -0
- package/docs/content/docs/reference/platforms/macos/meta.json +10 -0
- package/docs/content/docs/reference/platforms/macos/root-targeting.mdx +47 -0
- package/docs/content/docs/reference/platforms/meta.json +8 -0
- package/docs/content/docs/reference/platforms/windows.mdx +75 -0
- package/docs/content/docs/tutorials/getting-started.mdx +46 -0
- package/docs/content/docs/tutorials/index.mdx +10 -0
- package/docs/content/docs/tutorials/meta.json +1 -0
- package/extensions/computer-use.ts +235 -0
- package/native/linux/bridge-rs/Cargo.lock +1204 -0
- package/native/linux/bridge-rs/Cargo.toml +21 -0
- package/native/linux/bridge-rs/src/atspi.rs +670 -0
- package/native/linux/bridge-rs/src/error.rs +65 -0
- package/native/linux/bridge-rs/src/lib.rs +11 -0
- package/native/linux/bridge-rs/src/main.rs +1110 -0
- package/native/linux/bridge-rs/src/protocol.rs +49 -0
- package/native/linux/bridge-rs/src/state.rs +293 -0
- package/native/linux/bridge-rs/src/wayland.rs +89 -0
- package/native/linux/bridge-rs/src/x11.rs +909 -0
- package/native/linux/bridge-rs/tests/protocol_tests.rs +73 -0
- package/native/macos/activity_glow.swift +169 -0
- package/native/macos/bridge.swift +3968 -0
- package/native/windows/bridge-rs/Cargo.lock +396 -0
- package/native/windows/bridge-rs/Cargo.toml +30 -0
- package/native/windows/bridge-rs/src/capture.rs +561 -0
- package/native/windows/bridge-rs/src/error.rs +81 -0
- package/native/windows/bridge-rs/src/input.rs +501 -0
- package/native/windows/bridge-rs/src/lib.rs +85 -0
- package/native/windows/bridge-rs/src/main.rs +1683 -0
- package/native/windows/bridge-rs/src/protocol.rs +53 -0
- package/native/windows/bridge-rs/src/refs.rs +237 -0
- package/native/windows/bridge-rs/src/state.rs +55 -0
- package/native/windows/bridge-rs/src/uia.rs +1252 -0
- package/native/windows/bridge-rs/src/window.rs +718 -0
- package/native/windows/bridge-rs/tests/protocol_tests.rs +252 -0
- package/native/windows/bridge-rs/tests/refs_tests.rs +86 -0
- package/native/windows/bridge-rs/tests/state_tests.rs +33 -0
- package/package.json +104 -5
- package/prebuilt/macos/arm64/bridge +0 -0
- package/prebuilt/macos/x64/bridge +0 -0
- package/roam/README.md +52 -0
- package/roam/bridge/macos/arm64/bridge +0 -0
- package/roam/bridge/macos/x64/bridge +0 -0
- package/roam/bridge/manifest.json +20 -0
- package/roam/helper-path.d.mts +9 -0
- package/roam/helper-path.mjs +36 -0
- package/roam/identity.d.mts +16 -0
- package/roam/identity.mjs +64 -0
- package/roam/index.ts +51 -0
- package/roam/redirect.ts +51 -0
- package/roam/repair.ts +120 -0
- package/scripts/build-native.mjs +286 -0
- package/scripts/setup-helper.mjs +635 -0
- package/src/actions.ts +130 -0
- package/src/bridge.ts +2594 -0
- package/src/cdp.ts +658 -0
- package/src/config.ts +226 -0
- package/src/contract.ts +107 -0
- package/src/extension/index.ts +9 -0
- package/src/find-params.ts +21 -0
- package/src/note.ts +195 -0
- package/src/outline.ts +702 -0
- package/src/output.ts +134 -0
- package/src/permissions.ts +111 -0
- package/src/platform/architecture.ts +23 -0
- package/src/platform/coerce.ts +16 -0
- package/src/platform/index.ts +61 -0
- package/src/platform/linux/backend.ts +186 -0
- package/src/platform/linux/helper.ts +238 -0
- package/src/platform/macos/backend.ts +147 -0
- package/src/platform/macos/browser.ts +110 -0
- package/src/platform/macos/helper.ts +369 -0
- package/src/platform/macos/permissions.ts +146 -0
- package/src/platform/types.ts +229 -0
- package/src/platform/windows/backend.ts +142 -0
- package/src/platform/windows/helper.ts +140 -0
- package/src/root-selection.ts +25 -0
- package/src/runtime.ts +129 -0
- package/src/state.ts +146 -0
- package/src/view.ts +147 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Public extension surface. Registers the computer-use tools and the
|
|
2
|
+
// `/computer-use` configuration command through `src/extension/index.ts`, the
|
|
3
|
+
// roam-sdk seam, so an installed copy loads under Roam's resolver instead of a
|
|
4
|
+
// direct `@earendil-works/pi-coding-agent` peer import. `npm run test:registration`
|
|
5
|
+
// loads this file the way the host does and fails when either registration or
|
|
6
|
+
// the seam import regresses.
|
|
7
|
+
import { defineTool, type ExtensionAPI } from "../src/extension/index.ts";
|
|
8
|
+
import { Type } from "typebox";
|
|
9
|
+
import {
|
|
10
|
+
ensureComputerUseSetup,
|
|
11
|
+
executeAct,
|
|
12
|
+
executeEvaluateBrowser,
|
|
13
|
+
executeExpandUi,
|
|
14
|
+
executeInspectUi,
|
|
15
|
+
executeLaunchBrowser,
|
|
16
|
+
executeFind,
|
|
17
|
+
executeNavigateBrowser,
|
|
18
|
+
executeObserve,
|
|
19
|
+
executeReadText,
|
|
20
|
+
executeSearchUi,
|
|
21
|
+
executeWaitFor,
|
|
22
|
+
reconstructStateFromBranch,
|
|
23
|
+
setComputerUseActivity,
|
|
24
|
+
shutdownComputerUseSession,
|
|
25
|
+
} from "../src/bridge.ts";
|
|
26
|
+
import { getComputerUseConfig, getLoadedComputerUseConfig, loadComputerUseConfig } from "../src/config.ts";
|
|
27
|
+
|
|
28
|
+
const stateId = Type.String({ description: "Required state id owning every @e ref used by this operation" });
|
|
29
|
+
const point = { x: Type.Number(), y: Type.Number() };
|
|
30
|
+
const mouseButton = Type.Optional(Type.Union([Type.Literal("left"), Type.Literal("right"), Type.Literal("middle")]));
|
|
31
|
+
const clickByRef = Type.Object({ action: Type.Literal("click"), ref: Type.String(), button: mouseButton, clickCount: Type.Optional(Type.Number({ minimum: 1, maximum: 3 })) });
|
|
32
|
+
const clickByPoint = Type.Object({ action: Type.Literal("click"), ...point, button: mouseButton, clickCount: Type.Optional(Type.Number({ minimum: 1, maximum: 3 })) });
|
|
33
|
+
const uiAction = Type.Union([
|
|
34
|
+
Type.Object({ action: Type.Literal("press"), ref: Type.String({ description: "Actionable outline ref" }) }),
|
|
35
|
+
clickByRef,
|
|
36
|
+
clickByPoint,
|
|
37
|
+
Type.Object({ action: Type.Literal("setText"), ref: Type.String({ description: "Editable outline ref" }), text: Type.String() }),
|
|
38
|
+
Type.Object({ action: Type.Literal("typeText"), ref: Type.Optional(Type.String({ description: "Omit after a click to type into the focus established by that click" })), text: Type.String() }),
|
|
39
|
+
Type.Object({ action: Type.Literal("keypress"), ref: Type.Optional(Type.String({ description: "Omit to send keys to the focused control" })), keys: Type.Array(Type.String(), { minItems: 1 }) }),
|
|
40
|
+
Type.Object({ action: Type.Literal("scroll"), ref: Type.Optional(Type.String()), scrollX: Type.Optional(Type.Number()), scrollY: Type.Optional(Type.Number()) }),
|
|
41
|
+
Type.Object({ action: Type.Literal("drag"), path: Type.Array(Type.Object(point), { minItems: 2 }) }),
|
|
42
|
+
Type.Object({ action: Type.Literal("moveMouse"), ...point }),
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
const conditionProperties = {
|
|
46
|
+
ref: Type.Optional(Type.String({ description: "Specific @e ref to test", maxLength: 128 })),
|
|
47
|
+
scopeRef: Type.Optional(Type.String({ description: "Restrict matching to this @e subtree", maxLength: 128 })),
|
|
48
|
+
text: Type.Optional(Type.String({ description: "Text that must match", maxLength: 512 })),
|
|
49
|
+
role: Type.Optional(Type.String({ description: "Exact normalized role", maxLength: 128 })),
|
|
50
|
+
value: Type.Optional(Type.String({ description: "Exact normalized value; normally pair with ref" })),
|
|
51
|
+
until: Type.Optional(Type.Union([Type.Literal("present"), Type.Literal("absent")], { description: "Desired condition, default present" })),
|
|
52
|
+
timeoutMs: Type.Optional(Type.Number({ description: "Maximum wait, default 10000ms", minimum: 100, maximum: 60000 })),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const findTool = defineTool({
|
|
56
|
+
name: "find_roots",
|
|
57
|
+
label: "Find Roots",
|
|
58
|
+
description: "Find a bounded, ranked set of controllable UI roots with refs, geometry, and focus state.",
|
|
59
|
+
promptSnippet: "Find a target root before observe_ui when needed.",
|
|
60
|
+
parameters: Type.Object({
|
|
61
|
+
text: Type.Optional(Type.String({ description: "Ranked app or title text", maxLength: 256 })),
|
|
62
|
+
app: Type.Optional(Type.String({ description: "Exact normalized app name", maxLength: 256 })),
|
|
63
|
+
bundleId: Type.Optional(Type.String({ description: "Exact bundle id" })),
|
|
64
|
+
pid: Type.Optional(Type.Integer({ minimum: 1, description: "Exact positive process id" })),
|
|
65
|
+
kind: Type.Optional(Type.Union([Type.Literal("window"), Type.Literal("menu"), Type.Literal("sheet"), Type.Literal("popover"), Type.Literal("dialog"), Type.Literal("browser_page")], { description: "Exact root kind" })),
|
|
66
|
+
}),
|
|
67
|
+
execute: executeFind,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const observeTool = defineTool({
|
|
71
|
+
name: "observe_ui",
|
|
72
|
+
label: "Observe UI",
|
|
73
|
+
description: "Capture the current/frontmost root or one exact @r root and return a compact list of actionable @e controls plus stateId.",
|
|
74
|
+
promptSnippet: "Primary UI observation tool. Follow with search_ui, expand_ui, inspect_ui, or act_ui.",
|
|
75
|
+
promptGuidelines: [
|
|
76
|
+
"Use mode=semantic to skip OCR and images, visual to force them, and fused for automatic selection.",
|
|
77
|
+
"Use @e outline refs from observe_ui/search_ui for act_ui; pictureOnly refs are coordinate-only and blocked by UI-tree-only policy.",
|
|
78
|
+
"Use search_ui for unlisted controls; expand_ui on the root ref or detail=outline for structure.",
|
|
79
|
+
],
|
|
80
|
+
parameters: Type.Object({
|
|
81
|
+
root: Type.Optional(Type.String({ description: "Exact @r ref issued by find_roots" })),
|
|
82
|
+
mode: Type.Optional(Type.Union([Type.Literal("semantic"), Type.Literal("visual"), Type.Literal("fused")], { description: "Observation mode, default fused" })),
|
|
83
|
+
detail: Type.Optional(Type.Union([Type.Literal("compact"), Type.Literal("outline")], { description: "compact (default) lists actionable refs; outline returns the folded tree" })),
|
|
84
|
+
}),
|
|
85
|
+
execute: executeObserve,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const searchUiTool = defineTool({
|
|
89
|
+
name: "search_ui",
|
|
90
|
+
label: "Search UI",
|
|
91
|
+
description: "Return a bounded, deterministically ranked search of the cached outline. At least one predicate is required.",
|
|
92
|
+
promptSnippet: "Find targets not shown in the compact observe_ui output; refine broad searches instead of paging matches.",
|
|
93
|
+
parameters: Type.Object({
|
|
94
|
+
text: Type.Optional(Type.String({ description: "Human-readable text or label", maxLength: 256 })),
|
|
95
|
+
role: Type.Optional(Type.String({ description: "Exact normalized role, e.g. button", maxLength: 128 })),
|
|
96
|
+
capability: Type.Optional(Type.String({ description: "Exact capability, e.g. press", maxLength: 128 })),
|
|
97
|
+
stateId,
|
|
98
|
+
}),
|
|
99
|
+
execute: executeSearchUi,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const expandUiTool = defineTool({
|
|
103
|
+
name: "expand_ui",
|
|
104
|
+
label: "Expand UI",
|
|
105
|
+
description: "Unfold bounded local outline context for one @e ref; use the root ref for full structure.",
|
|
106
|
+
promptSnippet: "Expand a specific ref instead of dumping unrelated UI.",
|
|
107
|
+
parameters: Type.Object({ ref: Type.String(), depth: Type.Optional(Type.Number({ minimum: 1, maximum: 8, description: "Subtree depth, default 3" })), stateId }),
|
|
108
|
+
execute: executeExpandUi,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const inspectUiTool = defineTool({
|
|
112
|
+
name: "inspect_ui",
|
|
113
|
+
label: "Inspect UI",
|
|
114
|
+
description: "Inspect one exact outline ref with fields, geometry, capabilities, and annotations.",
|
|
115
|
+
promptSnippet: "Use when a target's evidence or provenance matters.",
|
|
116
|
+
parameters: Type.Object({ ref: Type.String(), stateId }),
|
|
117
|
+
execute: executeInspectUi,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const actTool = defineTool({
|
|
121
|
+
name: "act_ui",
|
|
122
|
+
label: "Act",
|
|
123
|
+
description: "Perform one or more precisely targeted checked actions and return the successor state.",
|
|
124
|
+
promptSnippet: "Pass dependent click/type steps together and use expect for observable completion.",
|
|
125
|
+
promptGuidelines: ["After clicking an editable region, omit ref from typeText/keypress so input follows the established focus."],
|
|
126
|
+
parameters: Type.Object({ stateId, expect: Type.Optional(Type.Object(conditionProperties)), actions: Type.Array(uiAction, { minItems: 1, maxItems: 20 }) }),
|
|
127
|
+
execute: executeAct,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const readTextTool = defineTool({
|
|
131
|
+
name: "read_text",
|
|
132
|
+
label: "Read Text",
|
|
133
|
+
description: "Read a fixed-size page from an @e UI ref or immutable @o truncated-output ref.",
|
|
134
|
+
promptSnippet: "Use @e with its stateId; @o continuation refs don't need stateId.",
|
|
135
|
+
parameters: Type.Object({ ref: Type.String(), offset: Type.Optional(Type.Number({ minimum: 0 })), stateId: Type.Optional(stateId) }),
|
|
136
|
+
execute: executeReadText,
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const waitForTool = defineTool({
|
|
140
|
+
name: "wait_for",
|
|
141
|
+
label: "Wait For",
|
|
142
|
+
description: "Wait for one scoped UI condition and return the successor state.",
|
|
143
|
+
promptSnippet: "Use after asynchronous UI changes instead of polling observe_ui.",
|
|
144
|
+
parameters: Type.Object({ ...conditionProperties, stateId }),
|
|
145
|
+
execute: executeWaitFor,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const launchBrowserTool = defineTool({
|
|
149
|
+
name: "launch_browser",
|
|
150
|
+
label: "Launch Browser Context",
|
|
151
|
+
description: "Launch the configured Pi-managed CDP browser and return an observed browser-page state.",
|
|
152
|
+
promptSnippet: "Use for browser work that needs a managed CDP context.",
|
|
153
|
+
promptGuidelines: ["Prefer curl through bash when the page is directly fetchable."],
|
|
154
|
+
parameters: Type.Object({ url: Type.Optional(Type.String({ maxLength: 8192 })) }),
|
|
155
|
+
execute: executeLaunchBrowser,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const navigateBrowserTool = defineTool({
|
|
159
|
+
name: "navigate_browser",
|
|
160
|
+
label: "Navigate Browser",
|
|
161
|
+
description: "Navigate an observed CDP browser-page state to an HTTP(S) URL.",
|
|
162
|
+
promptSnippet: "Native browser windows use act_ui; this tool is CDP-only.",
|
|
163
|
+
parameters: Type.Object({ url: Type.String({ maxLength: 8192 }), stateId }),
|
|
164
|
+
execute: executeNavigateBrowser,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const evaluateBrowserTool = defineTool({
|
|
168
|
+
name: "evaluate_browser",
|
|
169
|
+
label: "Evaluate Browser",
|
|
170
|
+
description: "Evaluate targeted JavaScript in a CDP browser-page state; returned output is strictly bounded.",
|
|
171
|
+
promptSnippet: "Prefer observe/search/read; return selected fields, aggregates, or bounded slices.",
|
|
172
|
+
parameters: Type.Object({ stateId, expression: Type.String({ maxLength: 65_536 }) }),
|
|
173
|
+
execute: executeEvaluateBrowser,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const COMPUTER_USE_TOOLS = [findTool, observeTool, searchUiTool, expandUiTool, inspectUiTool, actTool, readTextTool, waitForTool, launchBrowserTool, navigateBrowserTool, evaluateBrowserTool];
|
|
177
|
+
const COMPUTER_USE_TOOL_NAMES = new Set(COMPUTER_USE_TOOLS.map((tool) => tool.name));
|
|
178
|
+
|
|
179
|
+
function formatConfigStatus(): string {
|
|
180
|
+
const loaded = getLoadedComputerUseConfig();
|
|
181
|
+
return [
|
|
182
|
+
"pi-computer-use configuration",
|
|
183
|
+
`browser_use: ${loaded.config.browser_use ? "enabled" : "disabled"}`,
|
|
184
|
+
`managed_browser: ${loaded.config.managed_browser}`,
|
|
185
|
+
`headless: ${loaded.config.headless ? "enabled" : "disabled"}`,
|
|
186
|
+
`cursor_overlay: ${loaded.config.cursor_overlay ? "enabled" : "disabled"}`,
|
|
187
|
+
`activity_glow: ${loaded.config.activity_glow ? "enabled" : "disabled"}`,
|
|
188
|
+
"",
|
|
189
|
+
"Sources:",
|
|
190
|
+
...loaded.sources.map((source) => `- ${source.path}: ${source.error ? `error: ${source.error}` : source.exists ? "loaded" : "not found"}`),
|
|
191
|
+
`- env overrides: ${Object.keys(loaded.env).join(", ") || "none"}`,
|
|
192
|
+
].join("\n");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export const COMPUTER_USE_COMMAND_NAME = "computer-use";
|
|
196
|
+
|
|
197
|
+
export default function computerUseExtension(pi: ExtensionAPI): void {
|
|
198
|
+
let activityGlowActive = false;
|
|
199
|
+
|
|
200
|
+
for (const tool of COMPUTER_USE_TOOLS) pi.registerTool(tool);
|
|
201
|
+
|
|
202
|
+
pi.registerCommand(COMPUTER_USE_COMMAND_NAME, {
|
|
203
|
+
description: "Show pi-computer-use configuration",
|
|
204
|
+
handler: async (_args, ctx) => {
|
|
205
|
+
loadComputerUseConfig(ctx.cwd);
|
|
206
|
+
ctx.ui.notify(formatConfigStatus(), "info");
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
211
|
+
loadComputerUseConfig(ctx.cwd);
|
|
212
|
+
reconstructStateFromBranch(ctx);
|
|
213
|
+
if (!ctx.hasUI) return;
|
|
214
|
+
try { await ensureComputerUseSetup(ctx); } catch (error) { ctx.ui.notify(error instanceof Error ? error.message : String(error), "warning"); }
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
pi.on("tool_execution_start", async (event) => {
|
|
218
|
+
const config = getComputerUseConfig();
|
|
219
|
+
if (process.platform !== "darwin" || config.headless || !config.activity_glow || !COMPUTER_USE_TOOL_NAMES.has(event.toolName)) return;
|
|
220
|
+
activityGlowActive = true;
|
|
221
|
+
try { await setComputerUseActivity(true); } catch {}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
pi.on("agent_end", async () => {
|
|
225
|
+
if (!activityGlowActive) return;
|
|
226
|
+
activityGlowActive = false;
|
|
227
|
+
try { await setComputerUseActivity(false); } catch {}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
pi.on("session_shutdown", async () => {
|
|
231
|
+
activityGlowActive = false;
|
|
232
|
+
try { await setComputerUseActivity(false); } catch {}
|
|
233
|
+
await shutdownComputerUseSession();
|
|
234
|
+
});
|
|
235
|
+
}
|