@sideboard-ai/core 0.1.351 → 0.1.353
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/dist/{abletime-TX7BTTR2.js → abletime-5LEOMLQE.js} +4 -4
- package/dist/{abletime-URSRZW7P.js → abletime-VUPUERE4.js} +4 -4
- package/dist/{abletime-oauth-QS3WPSCC.js → abletime-oauth-65LHLQ7P.js} +3 -3
- package/dist/{abletime-oauth-SL3NMNEC.js → abletime-oauth-JAINJBNY.js} +3 -3
- package/dist/{abletime-rest-JZU6JJCV.js → abletime-rest-4TCWPN7E.js} +3 -3
- package/dist/{abletime-rest-GGQLUO55.js → abletime-rest-HBIK234Y.js} +3 -3
- package/dist/agents/claude-runner.cjs +37 -6
- package/dist/agents/claude-runner.js +16 -1
- package/dist/agents/cursor-runner.cjs +56 -12
- package/dist/agents/cursor-runner.js +2 -2
- package/dist/{agents-INTH7J3F.js → agents-5LFUHPSA.js} +9 -9
- package/dist/{agents-D5CL4CR4.js → agents-6B2HHICJ.js} +8 -8
- package/dist/{app-settings-IA7ZZKWQ.js → app-settings-GM4MJD2E.js} +3 -1
- package/dist/{app-settings-XILTSD6L.js → app-settings-X3UFWRAF.js} +3 -1
- package/dist/{chunk-BZK62VPT.js → chunk-2S7EAUDI.js} +2 -2
- package/dist/{chunk-CCWQ65VD.js → chunk-2SFKLWU5.js} +2 -2
- package/dist/{chunk-YVN7L4KG.js → chunk-AF5K6GQU.js} +6 -1
- package/dist/{chunk-WB3G2LQO.js → chunk-BCNPZ7H2.js} +1 -1
- package/dist/chunk-EAV2ZF5S.js +858 -0
- package/dist/{chunk-SMSD6U3N.js → chunk-GA5MLYVG.js} +1 -1
- package/dist/{chunk-HISSQICH.js → chunk-HBRP2SHA.js} +3 -3
- package/dist/{chunk-7WPQAVS5.js → chunk-HMSXKV53.js} +150 -126
- package/dist/{chunk-DL4OHDBV.js → chunk-I6BKWSCT.js} +3 -3
- package/dist/{chunk-WJURGCBR.js → chunk-KSBJOWVO.js} +1 -1
- package/dist/{chunk-J4EA5SHF.js → chunk-LZ3TAKNJ.js} +3 -3
- package/dist/{chunk-F4RFFE2H.js → chunk-M426EW7O.js} +3 -3
- package/dist/{chunk-C3E2DGDF.js → chunk-MBQU6RE2.js} +6 -6
- package/dist/{chunk-UXAKH4AW.js → chunk-MX2XU4BS.js} +418 -71
- package/dist/{chunk-TCEUNSLX.js → chunk-NRGT7RMO.js} +1 -1
- package/dist/{chunk-M45WGODR.js → chunk-OCCUD5CK.js} +2 -2
- package/dist/{chunk-BDWVBEKN.js → chunk-PKH3DRA6.js} +153 -127
- package/dist/{chunk-YE7Z5WH3.js → chunk-QKNOKO2P.js} +1 -1
- package/dist/{chunk-VL6F2KRE.js → chunk-RMJXFABA.js} +8 -6
- package/dist/{chunk-FQ3JYUKI.js → chunk-SBUR2WCP.js} +2 -2
- package/dist/{chunk-AEEOYLVK.js → chunk-SWU5C3HQ.js} +6 -6
- package/dist/{chunk-UFUAIVNV.js → chunk-TB7SYXXS.js} +8 -6
- package/dist/{chunk-7ZD4OK6G.js → chunk-TDWE7INS.js} +1 -1
- package/dist/{chunk-WFX4ZVSZ.js → chunk-TRUNDXCE.js} +1 -1
- package/dist/{chunk-PXSWVZIL.js → chunk-UPJB6TFI.js} +2 -2
- package/dist/{chunk-37ZBEBP6.js → chunk-VZAICZHU.js} +3 -3
- package/dist/{chunk-FCKTBE26.js → chunk-WJQFWDGH.js} +1 -1
- package/dist/{chunk-SZY23KGS.js → chunk-WTT525MC.js} +3 -3
- package/dist/{chunk-BF6INES4.js → chunk-X52SO3DM.js} +1 -1
- package/dist/{chunk-B4EFQTMP.js → chunk-XB6NCBZK.js} +5 -5
- package/dist/{chunk-5TCMXEYL.js → chunk-YGXUIBIT.js} +3 -3
- package/dist/{chunk-AAKQU4UZ.js → chunk-Z3CGD5HC.js} +28 -10
- package/dist/{chunk-VHQ6OG3U.js → chunk-ZHYFRRPN.js} +2 -2
- package/dist/{chunk-5WF54R3B.js → chunk-ZLPP66IP.js} +5 -5
- package/dist/{conductor-FWYWIHEW.js → conductor-2UOW2XBE.js} +6 -6
- package/dist/{conductor-W2X7QUKZ.js → conductor-6NYG2SZA.js} +6 -6
- package/dist/{coordinator-prompt-J57Q4Z4W.js → coordinator-prompt-K3WT5UVS.js} +4 -4
- package/dist/{coordinator-prompt-KIHNLENN.js → coordinator-prompt-ZP6AEETR.js} +4 -4
- package/dist/{global-workspace-WXDWFZAN.js → global-workspace-EFPSYP4N.js} +4 -4
- package/dist/{global-workspace-CGB5CY4U.js → global-workspace-EPVNFQVC.js} +4 -4
- package/dist/index.cjs +1414 -869
- package/dist/index.d.cts +116 -10
- package/dist/index.d.ts +116 -10
- package/dist/index.js +398 -315
- package/dist/{linear-WG23LBCX.js → linear-4ACCQCWM.js} +2 -2
- package/dist/{linear-E3BX5PX5.js → linear-Q2E6LKJW.js} +2 -2
- package/dist/{linear-list-VU47BNUV.js → linear-list-5A3BAWRZ.js} +1 -1
- package/dist/{linear-list-OINZWVV5.js → linear-list-V3A57XBR.js} +1 -1
- package/dist/mcp/run-stdio.cjs +1227 -802
- package/dist/mcp/run-stdio.js +342 -308
- package/dist/{optional-cli-K6HX2X5O.js → optional-cli-CKQPLY4Q.js} +4 -4
- package/dist/{optional-cli-SA3EQYML.js → optional-cli-WE3ULLFV.js} +5 -5
- package/dist/{orchestrator-MUD4FY7Q.js → orchestrator-UFHS2FOC.js} +12 -12
- package/dist/{orchestrator-DMEE7CEW.js → orchestrator-YCGWSIHF.js} +11 -11
- package/dist/{thread-store-4YTOV2HL.js → thread-store-CDFHHRXB.js} +2 -2
- package/dist/{thread-store-LME2ICZP.js → thread-store-TDGZEGS6.js} +2 -2
- package/dist/{workspaces-ZCTF4ECL.js → workspaces-KL4SZMJE.js} +4 -4
- package/dist/{workspaces-7DPHDXNY.js → workspaces-SQRR67HD.js} +4 -4
- package/dist/{worktree-4ATMCYIE.js → worktree-7KG5N2XL.js} +3 -3
- package/dist/{worktree-DA6SKIU5.js → worktree-IDX7LMBC.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-SUZOPJZC.js +0 -430
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appDataDir
|
|
3
|
+
} from "./chunk-H4UEFJRI.js";
|
|
4
|
+
|
|
5
|
+
// src/agent-rpc/protocol.ts
|
|
6
|
+
var AGENT_RPC_PROTOCOL_VERSION = 1;
|
|
7
|
+
var AGENT_RPC_PATH = "/agent-rpc";
|
|
8
|
+
var AGENT_RPC_JOB_HOLD_MAX_MS = 12e4;
|
|
9
|
+
var AGENT_RPC_JOB_SLICE_MS = 1e4;
|
|
10
|
+
var AGENT_RPC_TOKEN_QUERY = "authToken";
|
|
11
|
+
var AGENT_RPC_NATIVE_ENV = "SIDEBOARD_AGENT_RPC_NATIVE";
|
|
12
|
+
var AGENT_RPC_URL_ENV = "SIDEBOARD_AGENT_RPC_URL";
|
|
13
|
+
var AGENT_RPC_TOKEN_ENV = "SIDEBOARD_AGENT_RPC_TOKEN";
|
|
14
|
+
var AGENT_RPC_CWD_ENV = "SIDEBOARD_AGENT_RPC_CWD";
|
|
15
|
+
var AGENT_RPC_CLAUDE_SDK_SERVER = "sideboard_rpc";
|
|
16
|
+
var RPC_PARSE_ERROR = -32700;
|
|
17
|
+
var RPC_INVALID_REQUEST = -32600;
|
|
18
|
+
var RPC_METHOD_NOT_FOUND = -32601;
|
|
19
|
+
var RPC_UNAUTHORIZED = -32001;
|
|
20
|
+
var RPC_INTERNAL_ERROR = -32603;
|
|
21
|
+
function isJsonRpcRequest(value) {
|
|
22
|
+
if (!value || typeof value !== "object") return false;
|
|
23
|
+
const rec = value;
|
|
24
|
+
if (rec.jsonrpc !== "2.0") return false;
|
|
25
|
+
if (typeof rec.method !== "string" || !rec.method.trim()) return false;
|
|
26
|
+
if (rec.id === void 0 || rec.id === null) return false;
|
|
27
|
+
if (typeof rec.id !== "string" && typeof rec.id !== "number") return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function isJsonRpcNotification(value) {
|
|
31
|
+
if (!value || typeof value !== "object") return false;
|
|
32
|
+
const rec = value;
|
|
33
|
+
if (rec.jsonrpc !== "2.0") return false;
|
|
34
|
+
if (typeof rec.method !== "string" || !rec.method.trim()) return false;
|
|
35
|
+
if ("id" in rec && rec.id !== void 0) return false;
|
|
36
|
+
if ("error" in rec || "result" in rec) return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function rpcError(id, code, message, data) {
|
|
40
|
+
return {
|
|
41
|
+
jsonrpc: "2.0",
|
|
42
|
+
id,
|
|
43
|
+
error: data === void 0 ? { code, message } : { code, message, data }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function rpcResult(id, result) {
|
|
47
|
+
return { jsonrpc: "2.0", id, result };
|
|
48
|
+
}
|
|
49
|
+
function rpcNotify(method, params) {
|
|
50
|
+
return params === void 0 ? { jsonrpc: "2.0", method } : { jsonrpc: "2.0", method, params };
|
|
51
|
+
}
|
|
52
|
+
function parseRpcFrame(raw) {
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(raw);
|
|
55
|
+
} catch {
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/agent-rpc/metadata.ts
|
|
61
|
+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
62
|
+
import { join } from "path";
|
|
63
|
+
function agentRuntimeMetadataPath() {
|
|
64
|
+
return join(appDataDir(), "agent-runtime.json");
|
|
65
|
+
}
|
|
66
|
+
function writeAgentRuntimeMetadata(meta) {
|
|
67
|
+
writeFileSync(agentRuntimeMetadataPath(), `${JSON.stringify(meta)}
|
|
68
|
+
`, {
|
|
69
|
+
encoding: "utf8",
|
|
70
|
+
mode: 384
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function readAgentRuntimeMetadata() {
|
|
74
|
+
try {
|
|
75
|
+
const raw = JSON.parse(readFileSync(agentRuntimeMetadataPath(), "utf8"));
|
|
76
|
+
if (!raw || typeof raw !== "object") return null;
|
|
77
|
+
const rec = raw;
|
|
78
|
+
if (typeof rec.runtimeId !== "string" || !rec.runtimeId.trim()) return null;
|
|
79
|
+
if (typeof rec.authToken !== "string" || !rec.authToken.trim()) return null;
|
|
80
|
+
const pid = Number(rec.pid);
|
|
81
|
+
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
82
|
+
const transports = Array.isArray(rec.transports) ? rec.transports : [];
|
|
83
|
+
const ws = transports.filter((t) => {
|
|
84
|
+
if (!t || typeof t !== "object") return false;
|
|
85
|
+
const row = t;
|
|
86
|
+
return row.kind === "websocket" && typeof row.url === "string" && Boolean(row.url.trim());
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
runtimeId: rec.runtimeId.trim(),
|
|
90
|
+
pid,
|
|
91
|
+
protocolVersion: Number(rec.protocolVersion) || AGENT_RPC_PROTOCOL_VERSION,
|
|
92
|
+
authToken: rec.authToken,
|
|
93
|
+
startedAt: Number(rec.startedAt) || 0,
|
|
94
|
+
transports: ws
|
|
95
|
+
};
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function websocketUrlFromMetadata(meta) {
|
|
101
|
+
const url = meta?.transports.find((t) => t.kind === "websocket")?.url?.trim();
|
|
102
|
+
return url || null;
|
|
103
|
+
}
|
|
104
|
+
function agentRpcConnectFromMetadata(meta = readAgentRuntimeMetadata()) {
|
|
105
|
+
if (!agentRuntimeLooksLive(meta)) return null;
|
|
106
|
+
const url = websocketUrlFromMetadata(meta);
|
|
107
|
+
const authToken = meta?.authToken;
|
|
108
|
+
if (!url || !authToken) return null;
|
|
109
|
+
return { url, authToken };
|
|
110
|
+
}
|
|
111
|
+
function pidAlive(pid) {
|
|
112
|
+
try {
|
|
113
|
+
process.kill(pid, 0);
|
|
114
|
+
return true;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function clearAgentRuntimeMetadataIfOwned(pid = process.pid) {
|
|
120
|
+
const current = readAgentRuntimeMetadata();
|
|
121
|
+
if (!current || current.pid !== pid) return;
|
|
122
|
+
try {
|
|
123
|
+
unlinkSync(agentRuntimeMetadataPath());
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function agentRuntimeLooksLive(meta = readAgentRuntimeMetadata()) {
|
|
128
|
+
if (!meta) return false;
|
|
129
|
+
return pidAlive(meta.pid);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/computer-use/bridge.ts
|
|
133
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
134
|
+
import { join as join2 } from "path";
|
|
135
|
+
function computerUseBridgePath() {
|
|
136
|
+
return join2(appDataDir(), "computer-use-bridge.json");
|
|
137
|
+
}
|
|
138
|
+
var MODIFIERS = /* @__PURE__ */ new Set(["command", "cmd", "shift", "option", "alt", "control", "ctrl"]);
|
|
139
|
+
function readComputerUseBridge(file = computerUseBridgePath()) {
|
|
140
|
+
try {
|
|
141
|
+
const raw = JSON.parse(readFileSync2(file, "utf8"));
|
|
142
|
+
if (typeof raw.port !== "number" || !Number.isInteger(raw.port)) return null;
|
|
143
|
+
if (raw.port < 1 || raw.port > 65535) return null;
|
|
144
|
+
if (typeof raw.token !== "string" || raw.token.length < 16) return null;
|
|
145
|
+
return { port: raw.port, token: raw.token };
|
|
146
|
+
} catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function intIn(value, min, max) {
|
|
151
|
+
if (typeof value !== "number" || !Number.isInteger(value)) return null;
|
|
152
|
+
if (value < min || value > max) return null;
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
function parseComputerUseInput(value) {
|
|
156
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
157
|
+
const rec = value;
|
|
158
|
+
if (rec.type === "click") {
|
|
159
|
+
const x = intIn(rec.x, -8e3, 2e4);
|
|
160
|
+
const y = intIn(rec.y, -8e3, 2e4);
|
|
161
|
+
if (x === null || y === null) return null;
|
|
162
|
+
return { type: "click", x, y };
|
|
163
|
+
}
|
|
164
|
+
if (rec.type === "type") {
|
|
165
|
+
if (typeof rec.text !== "string" || !rec.text || rec.text.length > 2e3) return null;
|
|
166
|
+
return { type: "type", text: rec.text };
|
|
167
|
+
}
|
|
168
|
+
if (rec.type === "key") {
|
|
169
|
+
if (typeof rec.key !== "string" || !rec.key || rec.key.length > 32) return null;
|
|
170
|
+
if (!Array.isArray(rec.modifiers) || rec.modifiers.length > 4) return null;
|
|
171
|
+
const modifiers = [];
|
|
172
|
+
for (const item of rec.modifiers) {
|
|
173
|
+
if (typeof item !== "string" || !MODIFIERS.has(item)) return null;
|
|
174
|
+
modifiers.push(item);
|
|
175
|
+
}
|
|
176
|
+
return { type: "key", key: rec.key, modifiers };
|
|
177
|
+
}
|
|
178
|
+
if (rec.type === "scroll") {
|
|
179
|
+
const x = intIn(rec.x, -8e3, 2e4);
|
|
180
|
+
const y = intIn(rec.y, -8e3, 2e4);
|
|
181
|
+
const dx = intIn(rec.dx, -4e3, 4e3);
|
|
182
|
+
const dy = intIn(rec.dy, -4e3, 4e3);
|
|
183
|
+
if (x === null || y === null || dx === null || dy === null) return null;
|
|
184
|
+
if (dx === 0 && dy === 0) return null;
|
|
185
|
+
return { type: "scroll", x, y, dx, dy };
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
function cgModifierFlags(modifiers) {
|
|
190
|
+
let flags = 0;
|
|
191
|
+
for (const name of modifiers) {
|
|
192
|
+
if (name === "shift") flags |= 131072;
|
|
193
|
+
else if (name === "ctrl" || name === "control") flags |= 262144;
|
|
194
|
+
else if (name === "alt" || name === "option") flags |= 524288;
|
|
195
|
+
else if (name === "cmd" || name === "command") flags |= 1048576;
|
|
196
|
+
}
|
|
197
|
+
return flags;
|
|
198
|
+
}
|
|
199
|
+
function cgScrollWheels(dx, dy) {
|
|
200
|
+
return { wheel1: -dy, wheel2: -dx };
|
|
201
|
+
}
|
|
202
|
+
var MODIFIER_KEY_CODES = {
|
|
203
|
+
command: 55,
|
|
204
|
+
cmd: 55,
|
|
205
|
+
shift: 56,
|
|
206
|
+
option: 58,
|
|
207
|
+
alt: 58,
|
|
208
|
+
control: 59,
|
|
209
|
+
ctrl: 59
|
|
210
|
+
};
|
|
211
|
+
function modifierKeyCode(name) {
|
|
212
|
+
const code = MODIFIER_KEY_CODES[name];
|
|
213
|
+
return code === void 0 ? null : code;
|
|
214
|
+
}
|
|
215
|
+
async function bridgeError(res) {
|
|
216
|
+
try {
|
|
217
|
+
const body = await res.json();
|
|
218
|
+
if (typeof body.error === "string" && body.error) return body.error;
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
return `computer use bridge returned ${res.status}`;
|
|
222
|
+
}
|
|
223
|
+
async function bridgeFetch(info, path, init) {
|
|
224
|
+
try {
|
|
225
|
+
return await fetch(`http://127.0.0.1:${info.port}${path}`, {
|
|
226
|
+
...init,
|
|
227
|
+
headers: {
|
|
228
|
+
authorization: `Bearer ${info.token}`,
|
|
229
|
+
...init.headers
|
|
230
|
+
},
|
|
231
|
+
signal: AbortSignal.timeout(15e3)
|
|
232
|
+
});
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function postComputerUseBridge(event, file = computerUseBridgePath()) {
|
|
238
|
+
const info = readComputerUseBridge(file);
|
|
239
|
+
if (!info) return false;
|
|
240
|
+
const res = await bridgeFetch(info, "/v1/event", {
|
|
241
|
+
method: "POST",
|
|
242
|
+
headers: { "content-type": "application/json" },
|
|
243
|
+
body: JSON.stringify(event)
|
|
244
|
+
});
|
|
245
|
+
if (!res) return false;
|
|
246
|
+
if (!res.ok) throw new Error(await bridgeError(res));
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
async function fetchComputerUseScreenshot(file = computerUseBridgePath()) {
|
|
250
|
+
const info = readComputerUseBridge(file);
|
|
251
|
+
if (!info) return null;
|
|
252
|
+
const res = await bridgeFetch(info, "/v1/screenshot", { method: "POST" });
|
|
253
|
+
if (!res) return null;
|
|
254
|
+
if (!res.ok) throw new Error(await bridgeError(res));
|
|
255
|
+
const png = Buffer.from(await res.arrayBuffer());
|
|
256
|
+
if (png.length < 24) throw new Error("screen capture was empty");
|
|
257
|
+
const header = Number(res.headers.get("x-sideboard-scale"));
|
|
258
|
+
return { png, scale: Number.isFinite(header) && header > 0 ? header : 1 };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/computer-use/computer-use.ts
|
|
262
|
+
import { execFile } from "child_process";
|
|
263
|
+
import { mkdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
264
|
+
import { tmpdir } from "os";
|
|
265
|
+
import { isAbsolute, join as join3 } from "path";
|
|
266
|
+
import { promisify } from "util";
|
|
267
|
+
var execFileAsync = promisify(execFile);
|
|
268
|
+
var COMPUTER_USE_OFF = "Computer use is off. Turn it on in Settings \u2192 Advanced.";
|
|
269
|
+
var COMPUTER_USE_DESCRIPTION = "Drive this Mac to test an app you started. Off unless Settings \u2192 Advanced \u2192 Computer use is on. action is screenshot, click, type, key, or scroll. screenshot writes a PNG of the main display under the worktree .context/cli/ and returns that path plus point width, height, and scale. Read the image. x and y are screen points from the top-left of that image, not PNG pixels: divide a pixel by scale. click and scroll use those points. scroll posts a wheel event at the point (positive dx is right, positive dy is down). type sends text. key is one key (return, tab, escape, arrows, delete, or one character) with optional modifiers command, shift, option, control. Use it to check behavior and visual design (hierarchy, alignment, spacing, type, contrast, fit with the surrounding surface). preview=window means the Electron window, not a browser tab. Clicks, typing, scrolling, and screenshots are posted by Sideboard after macOS allows Sideboard to control this Mac and record the screen. Do not drive an app you did not start for this test.";
|
|
270
|
+
var KEY_CODES = {
|
|
271
|
+
return: 36,
|
|
272
|
+
enter: 36,
|
|
273
|
+
tab: 48,
|
|
274
|
+
escape: 53,
|
|
275
|
+
esc: 53,
|
|
276
|
+
delete: 51,
|
|
277
|
+
backspace: 51,
|
|
278
|
+
forwarddelete: 117,
|
|
279
|
+
left: 123,
|
|
280
|
+
right: 124,
|
|
281
|
+
down: 125,
|
|
282
|
+
up: 126
|
|
283
|
+
};
|
|
284
|
+
var MODIFIERS2 = /* @__PURE__ */ new Set(["command", "cmd", "shift", "option", "alt", "control", "ctrl"]);
|
|
285
|
+
function macKeyCode(key) {
|
|
286
|
+
const code = KEY_CODES[key];
|
|
287
|
+
return code === void 0 ? null : code;
|
|
288
|
+
}
|
|
289
|
+
var PNG_SIG = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
290
|
+
function appleScriptString(text) {
|
|
291
|
+
return `"${text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
292
|
+
}
|
|
293
|
+
function typeScripts(text) {
|
|
294
|
+
const parts = text.split(/\r\n|\n|\r/);
|
|
295
|
+
const scripts = [];
|
|
296
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
297
|
+
if (parts[i]) {
|
|
298
|
+
scripts.push(`tell application "System Events" to keystroke ${appleScriptString(parts[i])}`);
|
|
299
|
+
}
|
|
300
|
+
if (i < parts.length - 1) {
|
|
301
|
+
scripts.push('tell application "System Events" to key code 36');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return scripts;
|
|
305
|
+
}
|
|
306
|
+
function modifierClause(modifiers) {
|
|
307
|
+
const downs = modifiers.map((name) => {
|
|
308
|
+
if (name === "cmd" || name === "command") return "command down";
|
|
309
|
+
if (name === "alt" || name === "option") return "option down";
|
|
310
|
+
if (name === "ctrl" || name === "control") return "control down";
|
|
311
|
+
return "shift down";
|
|
312
|
+
});
|
|
313
|
+
if (!downs.length) return "";
|
|
314
|
+
return ` using {${downs.join(", ")}}`;
|
|
315
|
+
}
|
|
316
|
+
function pngPointSize(bytes) {
|
|
317
|
+
if (bytes.length < 24 || !bytes.subarray(0, 8).equals(PNG_SIG)) {
|
|
318
|
+
throw new Error("screenshot is not a PNG");
|
|
319
|
+
}
|
|
320
|
+
let pixelWidth = 0;
|
|
321
|
+
let pixelHeight = 0;
|
|
322
|
+
let scale = 1;
|
|
323
|
+
let offset = 8;
|
|
324
|
+
while (offset + 8 <= bytes.length) {
|
|
325
|
+
const length = bytes.readUInt32BE(offset);
|
|
326
|
+
const type = bytes.toString("ascii", offset + 4, offset + 8);
|
|
327
|
+
const data = offset + 8;
|
|
328
|
+
if (data + length > bytes.length) break;
|
|
329
|
+
if (type === "IHDR" && length >= 8) {
|
|
330
|
+
pixelWidth = bytes.readUInt32BE(data);
|
|
331
|
+
pixelHeight = bytes.readUInt32BE(data + 4);
|
|
332
|
+
} else if (type === "pHYs" && length >= 9 && bytes[data + 8] === 1) {
|
|
333
|
+
const ppm = bytes.readUInt32BE(data);
|
|
334
|
+
if (ppm > 0) scale = ppm * 0.0254 / 72;
|
|
335
|
+
} else if (type === "IEND") {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
offset = data + length + 4;
|
|
339
|
+
}
|
|
340
|
+
if (pixelWidth <= 0 || pixelHeight <= 0) throw new Error("screenshot PNG has no size");
|
|
341
|
+
return { pixelWidth, pixelHeight, scale };
|
|
342
|
+
}
|
|
343
|
+
function pointGeometry(info) {
|
|
344
|
+
const raw = info.scale > 0 && Number.isFinite(info.scale) ? info.scale : 1;
|
|
345
|
+
const scale = Math.round(raw * 100) / 100;
|
|
346
|
+
return {
|
|
347
|
+
width: Math.round(info.pixelWidth / scale),
|
|
348
|
+
height: Math.round(info.pixelHeight / scale),
|
|
349
|
+
scale
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function scrollWheelSwift(x, y, dx, dy) {
|
|
353
|
+
for (const n of [x, y, dx, dy]) {
|
|
354
|
+
if (!Number.isInteger(n)) throw new Error("scroll coordinates must be integers");
|
|
355
|
+
}
|
|
356
|
+
const { wheel1, wheel2 } = cgScrollWheels(dx, dy);
|
|
357
|
+
return `import CoreGraphics
|
|
358
|
+
let src = CGEventSource(stateID: .hidSystemState)
|
|
359
|
+
let p = CGPoint(x: ${x}, y: ${y})
|
|
360
|
+
if let move = CGEvent(mouseEventSource: src, mouseType: .mouseMoved, mouseCursorPosition: p, mouseButton: .left) {
|
|
361
|
+
move.post(tap: .cghidEventTap)
|
|
362
|
+
}
|
|
363
|
+
if let ev = CGEvent(scrollWheelEvent2Source: src, units: .pixel, wheelCount: 2, wheel1: ${wheel1}, wheel2: ${wheel2}, wheel3: 0) {
|
|
364
|
+
ev.location = p
|
|
365
|
+
ev.post(tap: .cghidEventTap)
|
|
366
|
+
}
|
|
367
|
+
`;
|
|
368
|
+
}
|
|
369
|
+
function asRecord(value) {
|
|
370
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
371
|
+
return value;
|
|
372
|
+
}
|
|
373
|
+
function finite(value) {
|
|
374
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
375
|
+
}
|
|
376
|
+
function point(value) {
|
|
377
|
+
const n = Math.round(value);
|
|
378
|
+
if (n < -8e3 || n > 2e4) return null;
|
|
379
|
+
return n;
|
|
380
|
+
}
|
|
381
|
+
function scrollDelta(value) {
|
|
382
|
+
const n = Math.round(value);
|
|
383
|
+
if (n < -4e3 || n > 4e3) return null;
|
|
384
|
+
return n;
|
|
385
|
+
}
|
|
386
|
+
function screenshotFile(cwd, now) {
|
|
387
|
+
const root = isAbsolute(cwd) ? cwd : tmpdir();
|
|
388
|
+
const dir = join3(root, ".context", "cli");
|
|
389
|
+
mkdirSync(dir, { recursive: true });
|
|
390
|
+
return join3(dir, `computer-use-${now}.png`);
|
|
391
|
+
}
|
|
392
|
+
async function posted(runner, event) {
|
|
393
|
+
if (!runner.postInput) return false;
|
|
394
|
+
return runner.postInput(event);
|
|
395
|
+
}
|
|
396
|
+
function screenshotMessage(width, height, scale) {
|
|
397
|
+
return `Screenshot saved (main display). Read that PNG. x and y are screen points from the top-left of this image, not PNG pixels. Divide a pixel by scale ${scale}. Point size is ${width}\xD7${height}. Judge behavior and visual design: hierarchy, alignment, spacing, type, contrast, and fit with the surrounding surface.`;
|
|
398
|
+
}
|
|
399
|
+
async function performComputerUse(opts) {
|
|
400
|
+
if (!opts.enabled) return { ok: false, error: COMPUTER_USE_OFF };
|
|
401
|
+
const rec = asRecord(opts.input);
|
|
402
|
+
const action = typeof rec.action === "string" ? rec.action : "";
|
|
403
|
+
try {
|
|
404
|
+
if (action === "screenshot") {
|
|
405
|
+
const file = screenshotFile(opts.cwd, opts.now ?? Date.now());
|
|
406
|
+
const captured = await opts.runner.screenshot(file);
|
|
407
|
+
const geo = pointGeometry(captured);
|
|
408
|
+
return {
|
|
409
|
+
ok: true,
|
|
410
|
+
action,
|
|
411
|
+
path: file,
|
|
412
|
+
width: geo.width,
|
|
413
|
+
height: geo.height,
|
|
414
|
+
scale: geo.scale,
|
|
415
|
+
message: screenshotMessage(geo.width, geo.height, geo.scale)
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
if (action === "click") {
|
|
419
|
+
const x = finite(rec.x);
|
|
420
|
+
const y = finite(rec.y);
|
|
421
|
+
if (x === null || y === null) return { ok: false, error: "click requires finite x and y" };
|
|
422
|
+
const px = point(x);
|
|
423
|
+
const py = point(y);
|
|
424
|
+
if (px === null || py === null) return { ok: false, error: "click point is out of range" };
|
|
425
|
+
if (!await posted(opts.runner, { type: "click", x: px, y: py })) {
|
|
426
|
+
await opts.runner.runAppleScript(
|
|
427
|
+
`tell application "System Events" to click at {${px}, ${py}}`
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
return { ok: true, action, message: `Clicked ${px}, ${py}.` };
|
|
431
|
+
}
|
|
432
|
+
if (action === "type") {
|
|
433
|
+
const text = typeof rec.text === "string" ? rec.text : "";
|
|
434
|
+
if (!text) return { ok: false, error: "type requires text" };
|
|
435
|
+
if (text.length > 2e3) return { ok: false, error: "type text is longer than 2000 characters" };
|
|
436
|
+
if (!await posted(opts.runner, { type: "type", text })) {
|
|
437
|
+
for (const script of typeScripts(text)) {
|
|
438
|
+
await opts.runner.runAppleScript(script);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return { ok: true, action, message: `Typed ${text.length} characters.` };
|
|
442
|
+
}
|
|
443
|
+
if (action === "key") {
|
|
444
|
+
const key = typeof rec.key === "string" ? rec.key.trim().toLowerCase() : "";
|
|
445
|
+
const modifiers = Array.isArray(rec.modifiers) ? rec.modifiers.filter((item) => typeof item === "string") : [];
|
|
446
|
+
if (!key) return { ok: false, error: "key requires key" };
|
|
447
|
+
if (modifiers.some((name) => !MODIFIERS2.has(name.toLowerCase()))) {
|
|
448
|
+
return { ok: false, error: "key modifiers are command, shift, option, and control" };
|
|
449
|
+
}
|
|
450
|
+
const mods = modifiers.map((name) => name.toLowerCase());
|
|
451
|
+
const using = modifierClause(mods);
|
|
452
|
+
const code = macKeyCode(key);
|
|
453
|
+
const script = code !== null ? `tell application "System Events" to key code ${code}${using}` : key.length === 1 ? `tell application "System Events" to keystroke ${appleScriptString(key)}${using}` : "";
|
|
454
|
+
if (!script) return { ok: false, error: `unsupported key ${key}` };
|
|
455
|
+
if (!await posted(opts.runner, { type: "key", key, modifiers: mods })) {
|
|
456
|
+
await opts.runner.runAppleScript(script);
|
|
457
|
+
}
|
|
458
|
+
return { ok: true, action, message: `Pressed ${key}.` };
|
|
459
|
+
}
|
|
460
|
+
if (action === "scroll") {
|
|
461
|
+
const x = finite(rec.x);
|
|
462
|
+
const y = finite(rec.y);
|
|
463
|
+
if (x === null || y === null) return { ok: false, error: "scroll requires finite x and y" };
|
|
464
|
+
const px = point(x);
|
|
465
|
+
const py = point(y);
|
|
466
|
+
if (px === null || py === null) return { ok: false, error: "scroll point is out of range" };
|
|
467
|
+
const dx = finite(rec.dx) ?? 0;
|
|
468
|
+
const dy = finite(rec.dy) ?? 0;
|
|
469
|
+
const sdx = scrollDelta(dx);
|
|
470
|
+
const sdy = scrollDelta(dy);
|
|
471
|
+
if (sdx === null || sdy === null) return { ok: false, error: "scroll delta is out of range" };
|
|
472
|
+
if (sdx === 0 && sdy === 0) return { ok: false, error: "scroll requires dx or dy" };
|
|
473
|
+
if (!await posted(opts.runner, { type: "scroll", x: px, y: py, dx: sdx, dy: sdy })) {
|
|
474
|
+
await opts.runner.scroll(px, py, sdx, sdy);
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
ok: true,
|
|
478
|
+
action,
|
|
479
|
+
message: `Scrolled at ${px}, ${py} by ${sdx}, ${sdy}. Positive dx is right, positive dy is down.`
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
return { ok: false, error: "action must be screenshot, click, type, key, or scroll" };
|
|
483
|
+
} catch (err) {
|
|
484
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
485
|
+
return { ok: false, error: message };
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function formatComputerUseHint(enabled) {
|
|
489
|
+
if (!enabled) {
|
|
490
|
+
return "Computer use is off (Settings \u2192 Advanced). Say the visual pass was not seen.";
|
|
491
|
+
}
|
|
492
|
+
return "Computer use is on. Screenshot returns scale; x and y are screen points (divide a PNG pixel by scale). Scroll is a wheel event at that point.";
|
|
493
|
+
}
|
|
494
|
+
var macosComputerUseRunner = {
|
|
495
|
+
async screenshot(file) {
|
|
496
|
+
const via = await fetchComputerUseScreenshot();
|
|
497
|
+
if (via) {
|
|
498
|
+
writeFileSync2(file, via.png);
|
|
499
|
+
const info = pngPointSize(via.png);
|
|
500
|
+
return { ...info, scale: via.scale > 0 ? via.scale : info.scale };
|
|
501
|
+
}
|
|
502
|
+
await execFileAsync("screencapture", ["-x", "-m", file]);
|
|
503
|
+
return pngPointSize(readFileSync3(file));
|
|
504
|
+
},
|
|
505
|
+
async runAppleScript(script) {
|
|
506
|
+
await execFileAsync("osascript", ["-e", script]);
|
|
507
|
+
},
|
|
508
|
+
async scroll(x, y, dx, dy) {
|
|
509
|
+
await execFileAsync("swift", ["-e", scrollWheelSwift(x, y, dx, dy)]);
|
|
510
|
+
},
|
|
511
|
+
postInput(event) {
|
|
512
|
+
return postComputerUseBridge(event);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
// src/agent-rpc/client.ts
|
|
517
|
+
import { WebSocket } from "ws";
|
|
518
|
+
var AgentRpcClient = class {
|
|
519
|
+
ws = null;
|
|
520
|
+
/** In-flight connect. Concurrent call()s must share it or each opens a socket. */
|
|
521
|
+
connecting = null;
|
|
522
|
+
pending = /* @__PURE__ */ new Map();
|
|
523
|
+
nextId = 1;
|
|
524
|
+
url;
|
|
525
|
+
authToken;
|
|
526
|
+
notifyListeners = /* @__PURE__ */ new Set();
|
|
527
|
+
constructor(opts = {}) {
|
|
528
|
+
const connect = opts.url && opts.authToken ? { url: opts.url, authToken: opts.authToken } : agentRpcConnectFromMetadata();
|
|
529
|
+
if (!connect) throw new Error("Agent RPC runtime is not running (no live agent-runtime.json)");
|
|
530
|
+
this.url = connect.url;
|
|
531
|
+
this.authToken = connect.authToken;
|
|
532
|
+
}
|
|
533
|
+
onNotify(fn) {
|
|
534
|
+
this.notifyListeners.add(fn);
|
|
535
|
+
return () => this.notifyListeners.delete(fn);
|
|
536
|
+
}
|
|
537
|
+
async call(method, params) {
|
|
538
|
+
const ws = await this.ensureSocket();
|
|
539
|
+
const id = this.nextId;
|
|
540
|
+
this.nextId += 1;
|
|
541
|
+
const key = String(id);
|
|
542
|
+
const payload = {
|
|
543
|
+
jsonrpc: "2.0",
|
|
544
|
+
id,
|
|
545
|
+
method,
|
|
546
|
+
params,
|
|
547
|
+
authToken: this.authToken
|
|
548
|
+
};
|
|
549
|
+
return new Promise((resolve, reject) => {
|
|
550
|
+
this.pending.set(key, { resolve, reject });
|
|
551
|
+
try {
|
|
552
|
+
ws.send(JSON.stringify(payload));
|
|
553
|
+
} catch (err) {
|
|
554
|
+
this.pending.delete(key);
|
|
555
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
socketUrl() {
|
|
560
|
+
const url = new URL(this.url);
|
|
561
|
+
url.searchParams.set(AGENT_RPC_TOKEN_QUERY, this.authToken);
|
|
562
|
+
return url.toString();
|
|
563
|
+
}
|
|
564
|
+
ensureSocket() {
|
|
565
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) return Promise.resolve(this.ws);
|
|
566
|
+
if (this.connecting) return this.connecting;
|
|
567
|
+
const ws = new WebSocket(this.socketUrl());
|
|
568
|
+
ws.on("message", (data) => this.onFrame(data.toString()));
|
|
569
|
+
ws.on("error", (err) => this.drop(ws, err));
|
|
570
|
+
ws.on("close", () => this.drop(ws, new Error("Agent RPC socket closed")));
|
|
571
|
+
ws.on("unexpected-response", (_req, res) => {
|
|
572
|
+
res.resume();
|
|
573
|
+
this.drop(
|
|
574
|
+
ws,
|
|
575
|
+
new Error(
|
|
576
|
+
res.statusCode === 401 ? "Unauthorized" : `Unexpected server response: ${res.statusCode}`
|
|
577
|
+
)
|
|
578
|
+
);
|
|
579
|
+
});
|
|
580
|
+
let settled = false;
|
|
581
|
+
const pending = new Promise((resolve, reject) => {
|
|
582
|
+
const fail = (err) => {
|
|
583
|
+
if (settled) return;
|
|
584
|
+
settled = true;
|
|
585
|
+
if (this.connecting === pending) this.connecting = null;
|
|
586
|
+
const message = err.message.includes("401") ? "Unauthorized" : err.message;
|
|
587
|
+
reject(message === err.message ? err : new Error(message));
|
|
588
|
+
};
|
|
589
|
+
const failClose = () => fail(new Error("Agent RPC socket closed"));
|
|
590
|
+
ws.once("unexpected-response", (_req, res) => {
|
|
591
|
+
fail(
|
|
592
|
+
new Error(
|
|
593
|
+
res.statusCode === 401 ? "Unauthorized" : `Unexpected server response: ${res.statusCode}`
|
|
594
|
+
)
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
ws.once("error", fail);
|
|
598
|
+
ws.once("close", failClose);
|
|
599
|
+
ws.once("open", () => {
|
|
600
|
+
ws.off("error", fail);
|
|
601
|
+
ws.off("close", failClose);
|
|
602
|
+
settled = true;
|
|
603
|
+
this.ws = ws;
|
|
604
|
+
this.connecting = null;
|
|
605
|
+
resolve(ws);
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
this.connecting = pending;
|
|
609
|
+
return pending;
|
|
610
|
+
}
|
|
611
|
+
drop(ws, err) {
|
|
612
|
+
if (this.ws !== ws) return;
|
|
613
|
+
this.ws = null;
|
|
614
|
+
if (this.pending.size === 0) return;
|
|
615
|
+
this.failAll(err);
|
|
616
|
+
}
|
|
617
|
+
onFrame(raw) {
|
|
618
|
+
const parsed = parseRpcFrame(raw);
|
|
619
|
+
if (parsed === void 0) return;
|
|
620
|
+
if (isJsonRpcNotification(parsed)) {
|
|
621
|
+
for (const fn of this.notifyListeners) fn(parsed);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (!parsed || typeof parsed !== "object") return;
|
|
625
|
+
const rec = parsed;
|
|
626
|
+
if (rec.id === void 0 || rec.id === null) return;
|
|
627
|
+
const key = String(rec.id);
|
|
628
|
+
const waiter = this.pending.get(key);
|
|
629
|
+
if (!waiter) return;
|
|
630
|
+
this.pending.delete(key);
|
|
631
|
+
if (rec.error && typeof rec.error === "object") {
|
|
632
|
+
const err = rec.error;
|
|
633
|
+
waiter.reject(new Error(err.message || "Agent RPC error"));
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
waiter.resolve(rec.result);
|
|
637
|
+
}
|
|
638
|
+
failAll(err) {
|
|
639
|
+
for (const waiter of this.pending.values()) waiter.reject(err);
|
|
640
|
+
this.pending.clear();
|
|
641
|
+
}
|
|
642
|
+
close() {
|
|
643
|
+
const ws = this.ws;
|
|
644
|
+
this.ws = null;
|
|
645
|
+
this.failAll(new Error("Agent RPC client closed"));
|
|
646
|
+
if (ws) {
|
|
647
|
+
try {
|
|
648
|
+
ws.close();
|
|
649
|
+
} catch {
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// src/agent-rpc/pilot-tools.ts
|
|
656
|
+
var PILOT_TOOL_NAMES = [
|
|
657
|
+
"present_artifact",
|
|
658
|
+
"wait_for_job",
|
|
659
|
+
"stop_job",
|
|
660
|
+
"computer_use"
|
|
661
|
+
];
|
|
662
|
+
var PILOT_TOOL_DESCRIPTIONS = {
|
|
663
|
+
present_artifact: "Show a document or live log in Sideboard\u2019s side column. For html/svg/markdown/react, pass the FULL document and do not also fence that same body in chat. For type=log, pass only NEW lines (same artifact_id appends). Prefer type=log for long-running job output \u2014 do not resend HTML. type=react is a single default-export component (JSX/TSX); only react/react-dom imports.",
|
|
664
|
+
wait_for_job: "Wait until a detached long job (tests, pack, deploy, connector CLI) finishes. This call stays open for up to ~2 minutes. stillRunning true means the runtime hit the max hold; call wait_for_job again immediately. If the job is hanging, producing no useful output, or doing the wrong thing, call stop_job instead. Do not end the turn or tell the user you will let them know later.",
|
|
665
|
+
stop_job: "Stop a detached job you started with detached-job.cjs when it is hanging, producing no useful output, buffering forever, or doing the wrong thing (wrong project, infinite watch, huge dump). Do not stop a pack/test/deploy that is clearly making progress.",
|
|
666
|
+
computer_use: COMPUTER_USE_DESCRIPTION
|
|
667
|
+
};
|
|
668
|
+
var WAIT_FOR_TURN_DESCRIPTION = "Wait until the chat finishes its current/queued turn, or return early with a live progress snapshot. This call stays open for up to ~2 minutes. taskState is the A2A-style lifecycle: submitted (queued, not started), working, input-required (ask_user), completed, failed, canceled. stillRunning is true only for submitted/working. If stillRunning, text and usage are empty (they would be the previous turn) \u2014 read progress and call wait_for_turn again. Do not send_to_chat a check-in (that steers / interrupts). On failed, lastError/text is the failure. On canceled, the child did not finish \u2014 resume with send_to_chat or tell the user. On input-required, wait for the user in that chat. When finished, text is this turn\u2019s assistant reply and usage is that turn\u2019s tokens + costUsd (this turn, not the Claude session total; sessionCostUsd is the provider session total when present). lastActivityAt is the latest transcript/live stamp \u2014 present after the turn completes, not only while it is running.";
|
|
669
|
+
var WAIT_FOR_TURN_SCHEMA = {
|
|
670
|
+
type: "object",
|
|
671
|
+
properties: {
|
|
672
|
+
ref: {
|
|
673
|
+
type: "string",
|
|
674
|
+
description: "Worktree thread id or ref to wait on (not the orchestrator)"
|
|
675
|
+
},
|
|
676
|
+
timeoutMs: {
|
|
677
|
+
type: "number",
|
|
678
|
+
description: "Optional cap for this hold (ms). Ignored above the runtime max (~2 minutes)."
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
required: ["ref"]
|
|
682
|
+
};
|
|
683
|
+
var PILOT_TOOL_SCHEMAS = {
|
|
684
|
+
present_artifact: {
|
|
685
|
+
type: "object",
|
|
686
|
+
properties: {
|
|
687
|
+
title: {
|
|
688
|
+
type: "string",
|
|
689
|
+
description: "Short title shown in the artifact pane header"
|
|
690
|
+
},
|
|
691
|
+
type: {
|
|
692
|
+
type: "string",
|
|
693
|
+
enum: ["html", "svg", "markdown", "react", "log"],
|
|
694
|
+
description: "html/svg/markdown/react replace the pane. log appends content to the same artifact_id (new lines only)."
|
|
695
|
+
},
|
|
696
|
+
content: {
|
|
697
|
+
type: "string",
|
|
698
|
+
description: "html/svg/markdown/react: full document. log: only the new lines since the last call (empty is ok for a status-only update)."
|
|
699
|
+
},
|
|
700
|
+
artifact_id: {
|
|
701
|
+
type: "string",
|
|
702
|
+
description: "Stable id. Required for type=log so later calls append to the same pane."
|
|
703
|
+
},
|
|
704
|
+
status: {
|
|
705
|
+
type: "string",
|
|
706
|
+
enum: ["running", "ok", "failed", "idle"]
|
|
707
|
+
},
|
|
708
|
+
phase: { type: "string" },
|
|
709
|
+
mode: { type: "string", enum: ["append", "replace"] }
|
|
710
|
+
},
|
|
711
|
+
required: ["title", "type", "content"]
|
|
712
|
+
},
|
|
713
|
+
wait_for_job: {
|
|
714
|
+
type: "object",
|
|
715
|
+
properties: {
|
|
716
|
+
id: {
|
|
717
|
+
type: "string",
|
|
718
|
+
description: "Detached job id (same kebab-case id passed to detached-job.cjs start)"
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
required: ["id"]
|
|
722
|
+
},
|
|
723
|
+
computer_use: {
|
|
724
|
+
type: "object",
|
|
725
|
+
properties: {
|
|
726
|
+
action: {
|
|
727
|
+
type: "string",
|
|
728
|
+
enum: ["screenshot", "click", "type", "key", "scroll"]
|
|
729
|
+
},
|
|
730
|
+
x: { type: "number", description: "Screen x in points, not PNG pixels" },
|
|
731
|
+
y: { type: "number", description: "Screen y in points, not PNG pixels" },
|
|
732
|
+
text: { type: "string" },
|
|
733
|
+
key: { type: "string" },
|
|
734
|
+
modifiers: {
|
|
735
|
+
type: "array",
|
|
736
|
+
items: { type: "string" },
|
|
737
|
+
description: "command, shift, option, control"
|
|
738
|
+
},
|
|
739
|
+
dx: { type: "number", description: "Horizontal scroll in points. Positive is right" },
|
|
740
|
+
dy: { type: "number", description: "Vertical scroll in points. Positive is down" }
|
|
741
|
+
},
|
|
742
|
+
required: ["action"]
|
|
743
|
+
},
|
|
744
|
+
stop_job: {
|
|
745
|
+
type: "object",
|
|
746
|
+
properties: {
|
|
747
|
+
id: {
|
|
748
|
+
type: "string",
|
|
749
|
+
description: "Detached job id (same kebab-case id passed to detached-job.cjs start)"
|
|
750
|
+
},
|
|
751
|
+
reason: { type: "string" }
|
|
752
|
+
},
|
|
753
|
+
required: ["id"]
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
function jsonToolResult(value) {
|
|
757
|
+
return JSON.stringify(value);
|
|
758
|
+
}
|
|
759
|
+
function jsonToolError(err) {
|
|
760
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
761
|
+
return jsonToolResult({ ok: false, error: message });
|
|
762
|
+
}
|
|
763
|
+
function createPilotRpcExecutors(opts) {
|
|
764
|
+
const client = new AgentRpcClient(opts.rpc);
|
|
765
|
+
let waitToolCallId;
|
|
766
|
+
if (opts.onProgress) {
|
|
767
|
+
const onProgress = opts.onProgress;
|
|
768
|
+
client.onNotify((msg) => {
|
|
769
|
+
if (msg.method === "runtime.progress") onProgress(msg.params, waitToolCallId);
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
const call = async (method, args) => {
|
|
773
|
+
try {
|
|
774
|
+
return jsonToolResult(await client.call(method, args));
|
|
775
|
+
} catch (err) {
|
|
776
|
+
return jsonToolError(err);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
const callJob = (method, args) => call(method, { ...args, cwd: opts.cwd });
|
|
780
|
+
return {
|
|
781
|
+
present_artifact: (args) => call("ui.presentArtifact", args),
|
|
782
|
+
wait_for_job: async (args, context) => {
|
|
783
|
+
const prev = waitToolCallId;
|
|
784
|
+
waitToolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : void 0;
|
|
785
|
+
try {
|
|
786
|
+
return await callJob("job.wait", args);
|
|
787
|
+
} finally {
|
|
788
|
+
waitToolCallId = prev;
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
stop_job: (args) => callJob("job.stop", args),
|
|
792
|
+
computer_use: (args) => callJob("computer.act", args),
|
|
793
|
+
wait_for_turn: async (args, context) => {
|
|
794
|
+
const prev = waitToolCallId;
|
|
795
|
+
waitToolCallId = typeof context?.toolCallId === "string" ? context.toolCallId : void 0;
|
|
796
|
+
try {
|
|
797
|
+
return await call("turn.wait", args);
|
|
798
|
+
} finally {
|
|
799
|
+
waitToolCallId = prev;
|
|
800
|
+
}
|
|
801
|
+
},
|
|
802
|
+
close: () => client.close()
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
export {
|
|
807
|
+
AGENT_RPC_PROTOCOL_VERSION,
|
|
808
|
+
AGENT_RPC_PATH,
|
|
809
|
+
AGENT_RPC_JOB_HOLD_MAX_MS,
|
|
810
|
+
AGENT_RPC_JOB_SLICE_MS,
|
|
811
|
+
AGENT_RPC_TOKEN_QUERY,
|
|
812
|
+
AGENT_RPC_NATIVE_ENV,
|
|
813
|
+
AGENT_RPC_URL_ENV,
|
|
814
|
+
AGENT_RPC_TOKEN_ENV,
|
|
815
|
+
AGENT_RPC_CWD_ENV,
|
|
816
|
+
AGENT_RPC_CLAUDE_SDK_SERVER,
|
|
817
|
+
RPC_PARSE_ERROR,
|
|
818
|
+
RPC_INVALID_REQUEST,
|
|
819
|
+
RPC_METHOD_NOT_FOUND,
|
|
820
|
+
RPC_UNAUTHORIZED,
|
|
821
|
+
RPC_INTERNAL_ERROR,
|
|
822
|
+
isJsonRpcRequest,
|
|
823
|
+
rpcError,
|
|
824
|
+
rpcResult,
|
|
825
|
+
rpcNotify,
|
|
826
|
+
parseRpcFrame,
|
|
827
|
+
writeAgentRuntimeMetadata,
|
|
828
|
+
readAgentRuntimeMetadata,
|
|
829
|
+
agentRpcConnectFromMetadata,
|
|
830
|
+
clearAgentRuntimeMetadataIfOwned,
|
|
831
|
+
computerUseBridgePath,
|
|
832
|
+
readComputerUseBridge,
|
|
833
|
+
parseComputerUseInput,
|
|
834
|
+
cgModifierFlags,
|
|
835
|
+
cgScrollWheels,
|
|
836
|
+
modifierKeyCode,
|
|
837
|
+
postComputerUseBridge,
|
|
838
|
+
fetchComputerUseScreenshot,
|
|
839
|
+
COMPUTER_USE_OFF,
|
|
840
|
+
COMPUTER_USE_DESCRIPTION,
|
|
841
|
+
macKeyCode,
|
|
842
|
+
appleScriptString,
|
|
843
|
+
typeScripts,
|
|
844
|
+
modifierClause,
|
|
845
|
+
pngPointSize,
|
|
846
|
+
pointGeometry,
|
|
847
|
+
scrollWheelSwift,
|
|
848
|
+
performComputerUse,
|
|
849
|
+
formatComputerUseHint,
|
|
850
|
+
macosComputerUseRunner,
|
|
851
|
+
AgentRpcClient,
|
|
852
|
+
PILOT_TOOL_NAMES,
|
|
853
|
+
PILOT_TOOL_DESCRIPTIONS,
|
|
854
|
+
WAIT_FOR_TURN_DESCRIPTION,
|
|
855
|
+
WAIT_FOR_TURN_SCHEMA,
|
|
856
|
+
PILOT_TOOL_SCHEMAS,
|
|
857
|
+
createPilotRpcExecutors
|
|
858
|
+
};
|