@nexus-code/remote-protocol 0.1.0 → 0.3.0
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/README.md +5 -1
- package/dist/rpc.d.ts +5164 -229
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +723 -11
- package/dist/rpc.js.map +1 -1
- package/dist/sealed.d.ts +37 -5
- package/dist/sealed.d.ts.map +1 -1
- package/dist/sealed.js +37 -5
- package/dist/sealed.js.map +1 -1
- package/dist/view.d.ts +440 -0
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +73 -0
- package/dist/view.js.map +1 -1
- package/package.json +1 -1
- package/src/rpc.ts +766 -10
- package/src/sealed.ts +38 -5
- package/src/view.ts +83 -0
package/dist/rpc.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* its tab's. The same folder has other ids on another device.
|
|
8
8
|
*/
|
|
9
9
|
import { z } from "zod";
|
|
10
|
-
import { AssistantItemSchema, ChatStatusSchema, ViewItemSchema, ViewTaskSchema, ViewToolCallSchema, } from "./view.js";
|
|
10
|
+
import { AssistantItemSchema, ChatPanelSchema, ChatStatusSchema, ViewItemSchema, ViewTaskSchema, ViewToolCallSchema, } from "./view.js";
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// JSON-RPC 2.0 shapes
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
@@ -62,6 +62,22 @@ export const RemoteWorkspaceSchema = z.object({
|
|
|
62
62
|
name: z.string(),
|
|
63
63
|
/** Its folder, on the serving device. */
|
|
64
64
|
path: z.string(),
|
|
65
|
+
/** A task: a workspace on a git worktree of the workspace `parentId`, on its own branch. */
|
|
66
|
+
parentId: z.string().optional(),
|
|
67
|
+
/** The agent manager's own workspace, where the session that directs the others runs. */
|
|
68
|
+
manager: z.boolean().optional(),
|
|
69
|
+
/**
|
|
70
|
+
* A task's branch and how it stands against its upstream, with how many
|
|
71
|
+
* files it changed and did not commit. Looked at now and then, not live.
|
|
72
|
+
*/
|
|
73
|
+
git: z
|
|
74
|
+
.object({
|
|
75
|
+
branch: z.string().nullable(),
|
|
76
|
+
ahead: z.number().int().nonnegative(),
|
|
77
|
+
behind: z.number().int().nonnegative(),
|
|
78
|
+
uncommitted: z.number().int().nonnegative(),
|
|
79
|
+
})
|
|
80
|
+
.optional(),
|
|
65
81
|
});
|
|
66
82
|
/** Where a session stands, as the agent lists show it. */
|
|
67
83
|
export const SessionStateSchema = z.enum(["needs-you", "running", "new-result", "idle", "ended"]);
|
|
@@ -83,15 +99,239 @@ export const RemoteSessionSchema = z.object({
|
|
|
83
99
|
.object({
|
|
84
100
|
kind: z.enum(["permission", "question", "plan"]),
|
|
85
101
|
text: z.string(),
|
|
102
|
+
/** A terminal's Claude Code asking: the request terminal.answer answers. */
|
|
103
|
+
requestId: z.string().optional(),
|
|
86
104
|
})
|
|
87
105
|
.optional(),
|
|
88
106
|
});
|
|
107
|
+
/** How the user answers a consent prompt: this once, until the serving app restarts, or no. */
|
|
108
|
+
export const ConsentAnswerSchema = z.enum(["once", "session", "deny"]);
|
|
109
|
+
/**
|
|
110
|
+
* A change an agent asks to make that waits on the user's consent on the
|
|
111
|
+
* serving device: an agent of another device of the account, a nexus
|
|
112
|
+
* command changing another workspace there, or its agent manager. The user
|
|
113
|
+
* may answer it there or, when `answerable`, from the device that lists it
|
|
114
|
+
* (consent.answer); unanswered by `expiresAt`, it counts as turned down.
|
|
115
|
+
*/
|
|
116
|
+
export const RemoteConsentSchema = z.object({
|
|
117
|
+
id: z.string(),
|
|
118
|
+
/** When it was asked, by the serving device's clock (Unix ms). */
|
|
119
|
+
at: z.number(),
|
|
120
|
+
/** When it counts as turned down, by the serving device's clock. */
|
|
121
|
+
expiresAt: z.number(),
|
|
122
|
+
/** How long it has left as the list is sent: a countdown that needs no clock in common. */
|
|
123
|
+
expiresInMs: z.number().int().nonnegative(),
|
|
124
|
+
/** Who asks. */
|
|
125
|
+
from: z.object({
|
|
126
|
+
/** An agent of another device of the account; absent: one of the serving device's own. */
|
|
127
|
+
device: z.object({ id: z.string(), name: z.string() }).optional(),
|
|
128
|
+
/** The serving device's agent manager asks. */
|
|
129
|
+
manager: z.boolean().optional(),
|
|
130
|
+
workspaceId: z.string(),
|
|
131
|
+
/** The asking workspace's name, when it is one of the serving device's. */
|
|
132
|
+
workspaceName: z.string().optional(),
|
|
133
|
+
tabId: z.string(),
|
|
134
|
+
/** The asking tab's title. */
|
|
135
|
+
name: z.string().optional(),
|
|
136
|
+
}),
|
|
137
|
+
/** The serving device's workspace it would change. */
|
|
138
|
+
workspaceId: z.string(),
|
|
139
|
+
/**
|
|
140
|
+
* What it would do: `kind` as the serving device names it (chatInput,
|
|
141
|
+
* terminalInput, tabClose, permissionAllow, ...; new ones may come), a
|
|
142
|
+
* line on what to, and the whole of it when a line does not tell it (a
|
|
143
|
+
* command to allow).
|
|
144
|
+
*/
|
|
145
|
+
change: z.object({
|
|
146
|
+
kind: z.string(),
|
|
147
|
+
detail: z.string().optional(),
|
|
148
|
+
body: z.string().optional(),
|
|
149
|
+
}),
|
|
150
|
+
/** It is asked about each time: "session" is not an answer to it. */
|
|
151
|
+
eachTime: z.boolean(),
|
|
152
|
+
/**
|
|
153
|
+
* Whether the device the list goes to may answer it: one that serves it
|
|
154
|
+
* chat.control, and terminal.control too for a change to a terminal; never
|
|
155
|
+
* the device whose agent asks.
|
|
156
|
+
*/
|
|
157
|
+
answerable: z.boolean(),
|
|
158
|
+
});
|
|
89
159
|
const SessionsSchema = z.object({
|
|
90
160
|
workspaces: z.array(RemoteWorkspaceSchema),
|
|
91
161
|
sessions: z.array(RemoteSessionSchema),
|
|
162
|
+
/** The consent prompts waiting on the user, in the order they are asked; absent before 0.3.0. */
|
|
163
|
+
consents: z.array(RemoteConsentSchema).optional(),
|
|
92
164
|
});
|
|
93
165
|
/** A session of the serving device, by its ids there. */
|
|
94
166
|
const TabRef = { workspaceId: z.string(), tabId: z.string() };
|
|
167
|
+
/**
|
|
168
|
+
* The agent that sends a request, when an agent does (nexus chat send on
|
|
169
|
+
* another device): its own tab there, which the receiving chat shows as
|
|
170
|
+
* the reply address. The device is the frame's sender. A control method
|
|
171
|
+
* with `from` takes the `agents` capability, not its own, and the serving
|
|
172
|
+
* device may ask its user first (AGENT_CONSENT_MS) or turn it down.
|
|
173
|
+
*/
|
|
174
|
+
export const AgentSenderSchema = z.object({
|
|
175
|
+
/** tab: a Claude or Codex tab; terminal: an agent in a terminal; manager: the agent manager. */
|
|
176
|
+
kind: z.enum(["tab", "terminal", "manager"]),
|
|
177
|
+
agent: z.string().min(1).max(40).optional(),
|
|
178
|
+
workspaceId: z.string(),
|
|
179
|
+
tabId: z.string(),
|
|
180
|
+
/** Its tab's title, as the receiver shows the sender. */
|
|
181
|
+
name: z.string().max(200).optional(),
|
|
182
|
+
/**
|
|
183
|
+
* How many messages between agents led to this one, the first being 1:
|
|
184
|
+
* a device refuses one past MAX_AGENT_HOPS, so agents on two devices
|
|
185
|
+
* cannot keep each other going without end.
|
|
186
|
+
*/
|
|
187
|
+
hops: z.number().int().positive(),
|
|
188
|
+
});
|
|
189
|
+
/** The keys terminal.input presses by name, as `nexus terminal key` names them. */
|
|
190
|
+
export const TERMINAL_KEYS = [
|
|
191
|
+
"enter",
|
|
192
|
+
"tab",
|
|
193
|
+
"shift-tab",
|
|
194
|
+
"esc",
|
|
195
|
+
"space",
|
|
196
|
+
"backspace",
|
|
197
|
+
"delete",
|
|
198
|
+
"up",
|
|
199
|
+
"down",
|
|
200
|
+
"left",
|
|
201
|
+
"right",
|
|
202
|
+
"home",
|
|
203
|
+
"end",
|
|
204
|
+
"pageup",
|
|
205
|
+
"pagedown",
|
|
206
|
+
"ctrl-a",
|
|
207
|
+
"ctrl-b",
|
|
208
|
+
"ctrl-c",
|
|
209
|
+
"ctrl-d",
|
|
210
|
+
"ctrl-e",
|
|
211
|
+
"ctrl-f",
|
|
212
|
+
"ctrl-g",
|
|
213
|
+
"ctrl-h",
|
|
214
|
+
"ctrl-i",
|
|
215
|
+
"ctrl-j",
|
|
216
|
+
"ctrl-k",
|
|
217
|
+
"ctrl-l",
|
|
218
|
+
"ctrl-m",
|
|
219
|
+
"ctrl-n",
|
|
220
|
+
"ctrl-o",
|
|
221
|
+
"ctrl-p",
|
|
222
|
+
"ctrl-q",
|
|
223
|
+
"ctrl-r",
|
|
224
|
+
"ctrl-s",
|
|
225
|
+
"ctrl-t",
|
|
226
|
+
"ctrl-u",
|
|
227
|
+
"ctrl-v",
|
|
228
|
+
"ctrl-w",
|
|
229
|
+
"ctrl-x",
|
|
230
|
+
"ctrl-y",
|
|
231
|
+
"ctrl-z",
|
|
232
|
+
];
|
|
233
|
+
export const TerminalKeySchema = z.enum(TERMINAL_KEYS);
|
|
234
|
+
/** Most messages between agents one chain may take; past it, `from` requests are refused. */
|
|
235
|
+
export const MAX_AGENT_HOPS = 8;
|
|
236
|
+
/**
|
|
237
|
+
* How long a serving device may ask its user about a request with `from`
|
|
238
|
+
* before it turns it down: a requester waits this long, and a little more.
|
|
239
|
+
*/
|
|
240
|
+
export const AGENT_CONSENT_MS = 90_000;
|
|
241
|
+
/** Most requests with `from` one agent (a device's tab) may make a minute; more are Unavailable. */
|
|
242
|
+
export const MAX_AGENT_REQUESTS_PER_MINUTE = 20;
|
|
243
|
+
/** Longest a chat.wait or terminal.wait holds before it answers that the session is not done yet. */
|
|
244
|
+
export const MAX_WAIT_MS = 10_000;
|
|
245
|
+
/** Where a chat stands for one that waits on it, as `nexus chat wait` tells it. */
|
|
246
|
+
export const ChatWaitStateSchema = z.enum(["working", "asking", "idle", "error", "closed"]);
|
|
247
|
+
/** A session state change, as `nexus events` lists them. */
|
|
248
|
+
export const SessionEventSchema = z.object({
|
|
249
|
+
/** Counts the device's events from 1 since its app started. */
|
|
250
|
+
seq: z.number().int().positive(),
|
|
251
|
+
at: z.number(),
|
|
252
|
+
workspaceId: z.string(),
|
|
253
|
+
tabId: z.string(),
|
|
254
|
+
title: z.string(),
|
|
255
|
+
kind: z.enum(["terminal", "claude", "codex"]),
|
|
256
|
+
agent: z.string().optional(),
|
|
257
|
+
/** The phase it left (null: first seen) and the one it came to ("closed" when the tab went). */
|
|
258
|
+
from: z.string().nullable(),
|
|
259
|
+
to: z.string(),
|
|
260
|
+
message: z.string().optional(),
|
|
261
|
+
});
|
|
262
|
+
/** Most images one message takes. */
|
|
263
|
+
export const MAX_ATTACHMENTS = 4;
|
|
264
|
+
/**
|
|
265
|
+
* Most bytes one image chat.attach takes, before base64: its base64 and the
|
|
266
|
+
* request around it stay inside a frame (MAX_FRAME_BYTES, sealed).
|
|
267
|
+
*/
|
|
268
|
+
export const MAX_ATTACHMENT_BYTES = 560 * 1024;
|
|
269
|
+
/** The image types a chat takes. */
|
|
270
|
+
export const ImageMediaTypeSchema = z.enum(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
271
|
+
/** What a chat runs with, and what it may be set to. */
|
|
272
|
+
export const ChatSettingsSchema = z.object({
|
|
273
|
+
agent: z.enum(["claude", "codex"]),
|
|
274
|
+
/** The model it runs, by the id to give back; null before the program says. */
|
|
275
|
+
model: z.string().nullable(),
|
|
276
|
+
effort: z.string().nullable(),
|
|
277
|
+
permissionMode: z.string(),
|
|
278
|
+
options: z.object({
|
|
279
|
+
models: z.array(z.object({ id: z.string(), label: z.string() })),
|
|
280
|
+
/** The effort levels its model takes; none when it takes none. */
|
|
281
|
+
efforts: z.array(z.string()),
|
|
282
|
+
/** The permission modes; `dangerous` ones ask the serving device's policy first. */
|
|
283
|
+
modes: z.array(z.object({ id: z.string(), label: z.string(), dangerous: z.boolean().optional() })),
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
286
|
+
/**
|
|
287
|
+
* A slash command of a chat, for a "/" picker: the app's own (run with
|
|
288
|
+
* chat.command), the agent's own (sent as a message: chat.send "/name
|
|
289
|
+
* args"), or one that sets what chat.configure sets.
|
|
290
|
+
*/
|
|
291
|
+
export const ChatCommandSchema = z.object({
|
|
292
|
+
name: z.string(),
|
|
293
|
+
description: z.string(),
|
|
294
|
+
/** command: chat.command; send: chat.send its text; settings: chat.configure. */
|
|
295
|
+
runs: z.enum(["command", "send", "settings"]),
|
|
296
|
+
/** With runs "settings": what it sets, so the picker for it opens. */
|
|
297
|
+
sets: z.enum(["model", "effort", "permissionMode"]).optional(),
|
|
298
|
+
/** What it takes after its name, as its help writes it ("<condition>"). */
|
|
299
|
+
args: z.string().optional(),
|
|
300
|
+
});
|
|
301
|
+
/** A chat of the past that can be resumed: Claude Code's sessions, Codex's threads. */
|
|
302
|
+
export const PastSessionSchema = z.object({
|
|
303
|
+
sessionId: z.string(),
|
|
304
|
+
title: z.string(),
|
|
305
|
+
/** When it last changed, in Unix milliseconds. */
|
|
306
|
+
at: z.number(),
|
|
307
|
+
/** Its log's size in bytes, when known. */
|
|
308
|
+
bytes: z.number().int().nonnegative().optional(),
|
|
309
|
+
/** The folder it ran in. */
|
|
310
|
+
cwd: z.string().optional(),
|
|
311
|
+
profile: z.string().optional(),
|
|
312
|
+
});
|
|
313
|
+
/** A file's state in git: a letter as `git status --porcelain` gives it (M, A, D, R, C, U, ?). */
|
|
314
|
+
const GitLetter = z.string().length(1);
|
|
315
|
+
/** A file git sees changed, staged or not. */
|
|
316
|
+
export const GitFileSchema = z.object({
|
|
317
|
+
path: z.string(),
|
|
318
|
+
/** Renamed or copied from. */
|
|
319
|
+
oldPath: z.string().optional(),
|
|
320
|
+
staged: GitLetter.optional(),
|
|
321
|
+
unstaged: GitLetter.optional(),
|
|
322
|
+
});
|
|
323
|
+
/** A piece of a diff, as jsdiff's structuredPatch gives it: lines starting " ", "-" or "+". */
|
|
324
|
+
export const DiffHunkSchema = z.object({
|
|
325
|
+
oldStart: z.number().int().nonnegative(),
|
|
326
|
+
oldLines: z.number().int().nonnegative(),
|
|
327
|
+
newStart: z.number().int().nonnegative(),
|
|
328
|
+
newLines: z.number().int().nonnegative(),
|
|
329
|
+
lines: z.array(z.string()),
|
|
330
|
+
});
|
|
331
|
+
/** Most entries one files.list gives. */
|
|
332
|
+
export const MAX_LIST_ENTRIES = 2000;
|
|
333
|
+
/** Most bytes of text one files.read gives. */
|
|
334
|
+
export const MAX_READ_BYTES = 512 * 1024;
|
|
95
335
|
// ---------------------------------------------------------------------------
|
|
96
336
|
// Chats
|
|
97
337
|
// ---------------------------------------------------------------------------
|
|
@@ -125,6 +365,21 @@ export const ChatUpdateSchema = z.object({
|
|
|
125
365
|
tools: z.record(ViewToolCallSchema),
|
|
126
366
|
tasks: z.record(ViewTaskSchema),
|
|
127
367
|
agentItems: z.record(z.array(AssistantItemSchema)),
|
|
368
|
+
/** The side panel, when it changed. */
|
|
369
|
+
panel: ChatPanelSchema.optional(),
|
|
370
|
+
});
|
|
371
|
+
/**
|
|
372
|
+
* A watched terminal's text changed: the text from `start` (a UTF-16
|
|
373
|
+
* offset into the text as it was) is now `text`. A redraw at the bottom
|
|
374
|
+
* sends only the bottom; a scroll, all of it from 0. A watch with `ansi`
|
|
375
|
+
* counts in the text with its escapes.
|
|
376
|
+
*/
|
|
377
|
+
export const TerminalUpdateSchema = z.object({
|
|
378
|
+
watchId: z.string(),
|
|
379
|
+
/** Counts the watch's updates from 1, so one lost shows. */
|
|
380
|
+
rev: z.number().int().positive(),
|
|
381
|
+
start: z.number().int().nonnegative(),
|
|
382
|
+
text: z.string(),
|
|
128
383
|
});
|
|
129
384
|
/** The sessions' list as it is now, sent whenever it changes during a sessions.watch. */
|
|
130
385
|
export const SessionsUpdateSchema = SessionsSchema.extend({ watchId: z.string() });
|
|
@@ -149,6 +404,49 @@ export const RPC_METHODS = {
|
|
|
149
404
|
params: z.object({ watchId: z.string() }),
|
|
150
405
|
result: Ok,
|
|
151
406
|
},
|
|
407
|
+
/**
|
|
408
|
+
* The session state changes after `since` (the first `limit`, `more` when
|
|
409
|
+
* some were left out), or the last `limit`; `cursor` is the latest seq. A
|
|
410
|
+
* `since` past it (from before the app restarted) reads from the start.
|
|
411
|
+
*/
|
|
412
|
+
"events.read": {
|
|
413
|
+
capability: "sessions",
|
|
414
|
+
params: z.object({
|
|
415
|
+
since: z.number().int().nonnegative().optional(),
|
|
416
|
+
limit: z.number().int().positive().max(500).optional(),
|
|
417
|
+
}),
|
|
418
|
+
result: z.object({
|
|
419
|
+
events: z.array(SessionEventSchema),
|
|
420
|
+
cursor: z.number().int().nonnegative(),
|
|
421
|
+
more: z.boolean(),
|
|
422
|
+
}),
|
|
423
|
+
},
|
|
424
|
+
/** The agent profiles a chat can run with (accounts, config folders). */
|
|
425
|
+
"profiles.list": {
|
|
426
|
+
capability: "sessions",
|
|
427
|
+
params: z.object({ agent: z.enum(["claude", "codex"]).optional() }),
|
|
428
|
+
result: z.object({
|
|
429
|
+
profiles: z.array(z.object({
|
|
430
|
+
id: z.string(),
|
|
431
|
+
name: z.string(),
|
|
432
|
+
agent: z.enum(["claude", "codex"]),
|
|
433
|
+
/** The one a workspace runs with unless told otherwise. */
|
|
434
|
+
isDefault: z.boolean(),
|
|
435
|
+
})),
|
|
436
|
+
}),
|
|
437
|
+
},
|
|
438
|
+
/** The past chats of a workspace's folder that can be resumed, latest first. */
|
|
439
|
+
"history.list": {
|
|
440
|
+
capability: "chat.read",
|
|
441
|
+
params: z.object({
|
|
442
|
+
workspaceId: z.string(),
|
|
443
|
+
agent: z.enum(["claude", "codex"]),
|
|
444
|
+
/** Only those whose title has it. */
|
|
445
|
+
query: z.string().max(200).optional(),
|
|
446
|
+
limit: z.number().int().positive().max(200).optional(),
|
|
447
|
+
}),
|
|
448
|
+
result: z.object({ sessions: z.array(PastSessionSchema) }),
|
|
449
|
+
},
|
|
152
450
|
/** The chat's last `limit` items, or those before `before`. */
|
|
153
451
|
"chat.read": {
|
|
154
452
|
capability: "chat.read",
|
|
@@ -166,18 +464,119 @@ export const RPC_METHODS = {
|
|
|
166
464
|
...TabRef,
|
|
167
465
|
limit: z.number().int().positive().max(MAX_READ_ITEMS).optional(),
|
|
168
466
|
}),
|
|
169
|
-
result: ChatPageSchema.extend({ watchId: z.string() }),
|
|
467
|
+
result: ChatPageSchema.extend({ watchId: z.string(), panel: ChatPanelSchema.optional() }),
|
|
170
468
|
},
|
|
171
469
|
"chat.unwatch": {
|
|
172
470
|
capability: "chat.read",
|
|
173
471
|
params: z.object({ watchId: z.string() }),
|
|
174
472
|
result: Ok,
|
|
175
473
|
},
|
|
176
|
-
/**
|
|
474
|
+
/** What the chat runs with and may be set to (model, effort, permission mode). */
|
|
475
|
+
"chat.settings": {
|
|
476
|
+
capability: "chat.read",
|
|
477
|
+
params: z.object(TabRef),
|
|
478
|
+
result: ChatSettingsSchema,
|
|
479
|
+
},
|
|
480
|
+
/** Its slash commands, the app's and the agent's, for a "/" picker. */
|
|
481
|
+
"chat.commands": {
|
|
482
|
+
capability: "chat.read",
|
|
483
|
+
params: z.object(TabRef),
|
|
484
|
+
result: z.object({ commands: z.array(ChatCommandSchema) }),
|
|
485
|
+
},
|
|
486
|
+
/** Its side panel now; a watch sends it again in chat.update as it changes. */
|
|
487
|
+
"chat.panel": {
|
|
488
|
+
capability: "chat.read",
|
|
489
|
+
params: z.object(TabRef),
|
|
490
|
+
result: ChatPanelSchema,
|
|
491
|
+
},
|
|
492
|
+
/** One tool call with as much of its result as a frame takes. */
|
|
493
|
+
"chat.tool": {
|
|
494
|
+
capability: "chat.read",
|
|
495
|
+
params: z.object({ ...TabRef, toolUseId: z.string() }),
|
|
496
|
+
result: ViewToolCallSchema,
|
|
497
|
+
},
|
|
498
|
+
/**
|
|
499
|
+
* Waits up to `timeoutMs` (at most MAX_WAIT_MS) for the chat to be done
|
|
500
|
+
* with its turn: no longer working (asking, idle, error, or closed). Ask
|
|
501
|
+
* again while `done` is false. `after`: a chat.send's `at`, so a message
|
|
502
|
+
* the chat has not shown yet counts as working.
|
|
503
|
+
*/
|
|
504
|
+
"chat.wait": {
|
|
505
|
+
capability: "chat.read",
|
|
506
|
+
params: z.object({
|
|
507
|
+
...TabRef,
|
|
508
|
+
timeoutMs: z.number().int().positive().max(MAX_WAIT_MS).optional(),
|
|
509
|
+
after: z.number().optional(),
|
|
510
|
+
}),
|
|
511
|
+
result: z.object({
|
|
512
|
+
done: z.boolean(),
|
|
513
|
+
state: ChatWaitStateSchema,
|
|
514
|
+
/** Its last answer; when asking, what it asks; on an error, what went wrong. */
|
|
515
|
+
message: z.string().optional(),
|
|
516
|
+
}),
|
|
517
|
+
},
|
|
518
|
+
/**
|
|
519
|
+
* An image of the chat, made small enough for a frame: a user message's
|
|
520
|
+
* (by its item's key and the image's index) or a tool result's.
|
|
521
|
+
*/
|
|
522
|
+
"chat.image": {
|
|
523
|
+
capability: "chat.read",
|
|
524
|
+
params: z.object({
|
|
525
|
+
...TabRef,
|
|
526
|
+
ref: z.discriminatedUnion("kind", [
|
|
527
|
+
z.object({
|
|
528
|
+
kind: z.literal("user"),
|
|
529
|
+
itemKey: z.string(),
|
|
530
|
+
index: z.number().int().nonnegative(),
|
|
531
|
+
}),
|
|
532
|
+
z.object({
|
|
533
|
+
kind: z.literal("tool"),
|
|
534
|
+
toolUseId: z.string(),
|
|
535
|
+
index: z.number().int().nonnegative(),
|
|
536
|
+
}),
|
|
537
|
+
]),
|
|
538
|
+
}),
|
|
539
|
+
result: z.object({
|
|
540
|
+
mediaType: ImageMediaTypeSchema,
|
|
541
|
+
/** Base64. */
|
|
542
|
+
data: z.string(),
|
|
543
|
+
width: z.number().int().positive().optional(),
|
|
544
|
+
height: z.number().int().positive().optional(),
|
|
545
|
+
}),
|
|
546
|
+
},
|
|
547
|
+
/**
|
|
548
|
+
* Sends a message, as its composer does: during a turn, the turn reads it
|
|
549
|
+
* next. `text` may be empty only with attachments. Sent by an agent
|
|
550
|
+
* (`from`), the chat shows it as that agent's, not the user's.
|
|
551
|
+
*/
|
|
177
552
|
"chat.send": {
|
|
178
553
|
capability: "chat.control",
|
|
179
|
-
params: z.object({
|
|
180
|
-
|
|
554
|
+
params: z.object({
|
|
555
|
+
...TabRef,
|
|
556
|
+
text: z.string(),
|
|
557
|
+
/** Images chat.attach took, at most MAX_ATTACHMENTS. */
|
|
558
|
+
attachments: z.array(z.string()).max(MAX_ATTACHMENTS).optional(),
|
|
559
|
+
from: AgentSenderSchema.optional(),
|
|
560
|
+
}),
|
|
561
|
+
/** `at`: when the serving device took it, by its clock, for chat.wait's `after`. */
|
|
562
|
+
result: z.object({ at: z.number().optional() }),
|
|
563
|
+
},
|
|
564
|
+
/**
|
|
565
|
+
* Takes an image for the next chat.send to this tab: one image a request,
|
|
566
|
+
* small enough for a frame. Kept 10 minutes, for this device only.
|
|
567
|
+
*/
|
|
568
|
+
"chat.attach": {
|
|
569
|
+
capability: "chat.control",
|
|
570
|
+
params: z.object({
|
|
571
|
+
...TabRef,
|
|
572
|
+
mediaType: ImageMediaTypeSchema,
|
|
573
|
+
/** Base64, of at most MAX_ATTACHMENT_BYTES bytes. */
|
|
574
|
+
data: z
|
|
575
|
+
.string()
|
|
576
|
+
.min(1)
|
|
577
|
+
.max(Math.ceil(MAX_ATTACHMENT_BYTES / 3) * 4),
|
|
578
|
+
}),
|
|
579
|
+
result: z.object({ attachmentId: z.string() }),
|
|
181
580
|
},
|
|
182
581
|
/** Answers the permission request `requestId`, as its card's buttons do. */
|
|
183
582
|
"chat.answer": {
|
|
@@ -192,32 +591,345 @@ export const RPC_METHODS = {
|
|
|
192
591
|
updatedInput: z.record(z.unknown()).optional(),
|
|
193
592
|
/** With deny: the turn stops too, as the card's "No, and stop" does. */
|
|
194
593
|
stop: z.boolean().optional(),
|
|
594
|
+
/** With allow: the request's suggestions to keep from now on, by index ("always allow"). */
|
|
595
|
+
always: z.array(z.number().int().nonnegative()).optional(),
|
|
596
|
+
from: AgentSenderSchema.optional(),
|
|
195
597
|
}),
|
|
196
598
|
result: Ok,
|
|
197
599
|
},
|
|
198
|
-
"chat.interrupt": {
|
|
199
|
-
|
|
600
|
+
"chat.interrupt": {
|
|
601
|
+
capability: "chat.control",
|
|
602
|
+
params: z.object({ ...TabRef, from: AgentSenderSchema.optional() }),
|
|
603
|
+
result: Ok,
|
|
604
|
+
},
|
|
605
|
+
/**
|
|
606
|
+
* Sets any of model, effort and permission mode, as the composer's chips
|
|
607
|
+
* do; what it runs with after. A mode the serving device's policy does
|
|
608
|
+
* not allow is refused (Forbidden) with why.
|
|
609
|
+
*/
|
|
610
|
+
"chat.configure": {
|
|
611
|
+
capability: "chat.control",
|
|
612
|
+
params: z.object({
|
|
613
|
+
...TabRef,
|
|
614
|
+
model: z.string().min(1).max(100).optional(),
|
|
615
|
+
effort: z.string().min(1).max(100).optional(),
|
|
616
|
+
permissionMode: z.string().min(1).max(100).optional(),
|
|
617
|
+
from: AgentSenderSchema.optional(),
|
|
618
|
+
}),
|
|
619
|
+
result: ChatSettingsSchema,
|
|
620
|
+
},
|
|
621
|
+
/** Runs one of the app's slash commands (chat.commands' `command` ones), `args` after its name. */
|
|
622
|
+
"chat.command": {
|
|
623
|
+
capability: "chat.control",
|
|
624
|
+
params: z.object({
|
|
625
|
+
...TabRef,
|
|
626
|
+
name: z.string().min(1).max(100),
|
|
627
|
+
args: z.string().max(10_000).optional(),
|
|
628
|
+
}),
|
|
629
|
+
result: z.object({
|
|
630
|
+
/** What it said, when it says something rather than changing the chat. */
|
|
631
|
+
message: z.string().optional(),
|
|
632
|
+
/** The tab it opened, when it opened one. */
|
|
633
|
+
tabId: z.string().optional(),
|
|
634
|
+
}),
|
|
635
|
+
},
|
|
636
|
+
/** Stops a task of the chat's (a background run, a subagent), as the side panel's button does. */
|
|
637
|
+
"chat.stopTask": {
|
|
638
|
+
capability: "chat.control",
|
|
639
|
+
params: z.object({ ...TabRef, taskId: z.string() }),
|
|
640
|
+
result: Ok,
|
|
641
|
+
},
|
|
642
|
+
"chat.rename": {
|
|
643
|
+
capability: "chat.control",
|
|
644
|
+
params: z.object({ ...TabRef, title: z.string().min(1).max(200) }),
|
|
645
|
+
result: z.object({ title: z.string() }),
|
|
646
|
+
},
|
|
647
|
+
/** Opens a past chat (history.list) in a new tab. */
|
|
648
|
+
"chat.resume": {
|
|
649
|
+
capability: "chat.control",
|
|
650
|
+
params: z.object({
|
|
651
|
+
workspaceId: z.string(),
|
|
652
|
+
agent: z.enum(["claude", "codex"]),
|
|
653
|
+
sessionId: z.string(),
|
|
654
|
+
}),
|
|
655
|
+
result: z.object({ tabId: z.string() }),
|
|
656
|
+
},
|
|
657
|
+
/**
|
|
658
|
+
* Opens a chat in one of the serving device's workspaces, sending it
|
|
659
|
+
* `prompt` if given. `model` and `effort` are set before the prompt goes,
|
|
660
|
+
* named as the agent's own menus name them ("haiku", "low"); the tab's
|
|
661
|
+
* profile's own otherwise.
|
|
662
|
+
*/
|
|
200
663
|
"chat.new": {
|
|
201
664
|
capability: "chat.control",
|
|
202
665
|
params: z.object({
|
|
203
666
|
workspaceId: z.string(),
|
|
204
667
|
agent: z.enum(["claude", "codex"]),
|
|
205
668
|
prompt: z.string().optional(),
|
|
669
|
+
model: z.string().min(1).max(100).optional(),
|
|
670
|
+
effort: z.string().min(1).max(100).optional(),
|
|
671
|
+
permissionMode: z.string().min(1).max(100).optional(),
|
|
672
|
+
/** The agent profile, by id or name (profiles.list); the workspace's otherwise. */
|
|
673
|
+
profile: z.string().min(1).max(100).optional(),
|
|
674
|
+
/** A folder inside the workspace to run in; its own folder otherwise. */
|
|
675
|
+
folder: z.string().min(1).max(4096).optional(),
|
|
676
|
+
/** Sent by an agent: the chat shows the prompt as that agent's. */
|
|
677
|
+
from: AgentSenderSchema.optional(),
|
|
678
|
+
}),
|
|
679
|
+
result: z.object({
|
|
680
|
+
tabId: z.string(),
|
|
681
|
+
/** The tab opened, but the model or effort could not be set: the prompt was not sent. */
|
|
682
|
+
error: z.string().optional(),
|
|
206
683
|
}),
|
|
207
|
-
result: z.object({ tabId: z.string() }),
|
|
208
684
|
},
|
|
209
|
-
"chat.close": {
|
|
210
|
-
|
|
685
|
+
"chat.close": {
|
|
686
|
+
capability: "chat.control",
|
|
687
|
+
params: z.object({ ...TabRef, from: AgentSenderSchema.optional() }),
|
|
688
|
+
result: Ok,
|
|
689
|
+
},
|
|
690
|
+
/**
|
|
691
|
+
* A terminal's screen and the lines above it, as text; with `ansi`, with
|
|
692
|
+
* its colors and styles as SGR escapes (no other escapes).
|
|
693
|
+
*/
|
|
211
694
|
"terminal.read": {
|
|
212
695
|
capability: "terminal.read",
|
|
213
|
-
params: z.object({
|
|
696
|
+
params: z.object({
|
|
697
|
+
...TabRef,
|
|
698
|
+
lines: z.number().int().positive().max(5000).optional(),
|
|
699
|
+
ansi: z.boolean().optional(),
|
|
700
|
+
}),
|
|
214
701
|
result: z.object({ text: z.string() }),
|
|
215
702
|
},
|
|
703
|
+
/** The terminal's text now, as terminal.read; then a terminal.update each time it changes, until terminal.unwatch. */
|
|
704
|
+
"terminal.watch": {
|
|
705
|
+
capability: "terminal.read",
|
|
706
|
+
params: z.object({
|
|
707
|
+
...TabRef,
|
|
708
|
+
lines: z.number().int().positive().max(5000).optional(),
|
|
709
|
+
ansi: z.boolean().optional(),
|
|
710
|
+
}),
|
|
711
|
+
result: z.object({ text: z.string(), watchId: z.string() }),
|
|
712
|
+
},
|
|
713
|
+
"terminal.unwatch": {
|
|
714
|
+
capability: "terminal.read",
|
|
715
|
+
params: z.object({ watchId: z.string() }),
|
|
716
|
+
result: Ok,
|
|
717
|
+
},
|
|
718
|
+
/**
|
|
719
|
+
* Types into a terminal: `text` as pasted, then `keys` by name
|
|
720
|
+
* (TERMINAL_KEYS), then Enter when `enter`. Sent by an agent (`from`), the receiving device counts it
|
|
721
|
+
* as that agent's.
|
|
722
|
+
*/
|
|
723
|
+
"terminal.input": {
|
|
724
|
+
capability: "terminal.control",
|
|
725
|
+
params: z.object({
|
|
726
|
+
...TabRef,
|
|
727
|
+
text: z
|
|
728
|
+
.string()
|
|
729
|
+
.max(64 * 1024)
|
|
730
|
+
.optional(),
|
|
731
|
+
keys: z.array(TerminalKeySchema).max(64).optional(),
|
|
732
|
+
enter: z.boolean().optional(),
|
|
733
|
+
from: AgentSenderSchema.optional(),
|
|
734
|
+
}),
|
|
735
|
+
/** `at`: when it was typed, by the serving device's clock, for terminal.wait's `after`. */
|
|
736
|
+
result: z.object({ at: z.number().optional() }),
|
|
737
|
+
},
|
|
738
|
+
/**
|
|
739
|
+
* Waits up to `timeoutMs` (at most MAX_WAIT_MS) as `nexus terminal wait`
|
|
740
|
+
* does: for the terminal's agent to finish its turn, its shell to be back
|
|
741
|
+
* at the prompt, or quiet output; with `exit`, for its program to end;
|
|
742
|
+
* with `match`, for a line to match. Ask again while `done` is false.
|
|
743
|
+
*/
|
|
744
|
+
"terminal.wait": {
|
|
745
|
+
capability: "terminal.read",
|
|
746
|
+
params: z.object({
|
|
747
|
+
...TabRef,
|
|
748
|
+
timeoutMs: z.number().int().positive().max(MAX_WAIT_MS).optional(),
|
|
749
|
+
/** A terminal.input's `at`: a turn must have started after it. */
|
|
750
|
+
after: z.number().optional(),
|
|
751
|
+
exit: z.boolean().optional(),
|
|
752
|
+
match: z.string().min(1).max(1000).optional(),
|
|
753
|
+
/** Quiet for this long counts as idle, for a program that is no agent or shell. */
|
|
754
|
+
quietMs: z.number().int().positive().max(600_000).optional(),
|
|
755
|
+
}),
|
|
756
|
+
result: z.object({
|
|
757
|
+
done: z.boolean(),
|
|
758
|
+
/** idle, completed, needsInput, permissionPending, error, notStarted, notified, exited, matched, or waiting. */
|
|
759
|
+
state: z.string(),
|
|
760
|
+
message: z.string().optional(),
|
|
761
|
+
}),
|
|
762
|
+
},
|
|
763
|
+
/**
|
|
764
|
+
* Answers the permission request a terminal's Claude Code holds for the
|
|
765
|
+
* app (its session's `waiting.requestId`), as the agent list's buttons do.
|
|
766
|
+
* An answer for agents, so chat.control's: no typing goes in.
|
|
767
|
+
*/
|
|
768
|
+
"terminal.answer": {
|
|
769
|
+
capability: "chat.control",
|
|
770
|
+
params: z.object({
|
|
771
|
+
...TabRef,
|
|
772
|
+
requestId: z.string(),
|
|
773
|
+
decision: z.enum(["allow", "allowAlways", "deny", "denyStop"]),
|
|
774
|
+
from: AgentSenderSchema.optional(),
|
|
775
|
+
}),
|
|
776
|
+
result: Ok,
|
|
777
|
+
},
|
|
778
|
+
/** The shells a new terminal can run, as "New terminal with" lists them. */
|
|
779
|
+
"terminal.shells": {
|
|
780
|
+
capability: "terminal.control",
|
|
781
|
+
params: z.object({ workspaceId: z.string() }),
|
|
782
|
+
result: z.object({
|
|
783
|
+
shells: z.array(z.object({ id: z.string(), name: z.string(), isDefault: z.boolean() })),
|
|
784
|
+
}),
|
|
785
|
+
},
|
|
786
|
+
/** Opens a terminal: a shell (by its id), in a folder inside the workspace, running `command`. */
|
|
787
|
+
"terminal.open": {
|
|
788
|
+
capability: "terminal.control",
|
|
789
|
+
params: z.object({
|
|
790
|
+
workspaceId: z.string(),
|
|
791
|
+
shell: z.string().min(1).max(200).optional(),
|
|
792
|
+
folder: z.string().min(1).max(4096).optional(),
|
|
793
|
+
command: z.string().min(1).max(10_000).optional(),
|
|
794
|
+
title: z.string().min(1).max(200).optional(),
|
|
795
|
+
from: AgentSenderSchema.optional(),
|
|
796
|
+
}),
|
|
797
|
+
result: z.object({ tabId: z.string() }),
|
|
798
|
+
},
|
|
799
|
+
"terminal.rename": {
|
|
800
|
+
capability: "terminal.control",
|
|
801
|
+
params: z.object({ ...TabRef, title: z.string().min(1).max(200) }),
|
|
802
|
+
result: z.object({ title: z.string() }),
|
|
803
|
+
},
|
|
804
|
+
/** Closes a terminal; one running a program only with `force`. */
|
|
805
|
+
"terminal.close": {
|
|
806
|
+
capability: "terminal.control",
|
|
807
|
+
params: z.object({
|
|
808
|
+
...TabRef,
|
|
809
|
+
force: z.boolean().optional(),
|
|
810
|
+
from: AgentSenderSchema.optional(),
|
|
811
|
+
}),
|
|
812
|
+
result: Ok,
|
|
813
|
+
},
|
|
814
|
+
/**
|
|
815
|
+
* Answers a consent prompt of sessions.list's `consents`, as the user would
|
|
816
|
+
* on the serving device, where it closes. NotFound when it is no longer
|
|
817
|
+
* waiting (answered there, or timed out); Forbidden when it is not
|
|
818
|
+
* `answerable`, or for "session" to one asked about each time. An
|
|
819
|
+
* agent's request (`from`) is refused: only people answer these.
|
|
820
|
+
*/
|
|
821
|
+
"consent.answer": {
|
|
822
|
+
capability: "chat.control",
|
|
823
|
+
params: z.object({ id: z.string(), answer: ConsentAnswerSchema }),
|
|
824
|
+
result: Ok,
|
|
825
|
+
},
|
|
826
|
+
/**
|
|
827
|
+
* A folder's entries, folders first. `path` is absolute or inside the
|
|
828
|
+
* workspace's folder ("" for it); it must be in the workspace's folders
|
|
829
|
+
* (its own, and those its chats were given).
|
|
830
|
+
*/
|
|
831
|
+
"files.list": {
|
|
832
|
+
capability: "files",
|
|
833
|
+
params: z.object({ workspaceId: z.string(), path: z.string().max(4096) }),
|
|
834
|
+
result: z.object({
|
|
835
|
+
/** The folder, absolute. */
|
|
836
|
+
path: z.string(),
|
|
837
|
+
entries: z.array(z.object({
|
|
838
|
+
name: z.string(),
|
|
839
|
+
kind: z.enum(["file", "dir", "link"]),
|
|
840
|
+
size: z.number().int().nonnegative().optional(),
|
|
841
|
+
})),
|
|
842
|
+
/** More than MAX_LIST_ENTRIES: the rest left out. */
|
|
843
|
+
truncated: z.boolean().optional(),
|
|
844
|
+
}),
|
|
845
|
+
},
|
|
846
|
+
/** A file: text (its start, up to `maxBytes`), an image made small enough for a frame, or that it is binary. */
|
|
847
|
+
"files.read": {
|
|
848
|
+
capability: "files",
|
|
849
|
+
params: z.object({
|
|
850
|
+
workspaceId: z.string(),
|
|
851
|
+
path: z.string().min(1).max(4096),
|
|
852
|
+
maxBytes: z.number().int().positive().max(MAX_READ_BYTES).optional(),
|
|
853
|
+
}),
|
|
854
|
+
result: z.discriminatedUnion("kind", [
|
|
855
|
+
z.object({
|
|
856
|
+
kind: z.literal("text"),
|
|
857
|
+
path: z.string(),
|
|
858
|
+
text: z.string(),
|
|
859
|
+
size: z.number().int().nonnegative(),
|
|
860
|
+
truncated: z.boolean(),
|
|
861
|
+
}),
|
|
862
|
+
z.object({
|
|
863
|
+
kind: z.literal("image"),
|
|
864
|
+
path: z.string(),
|
|
865
|
+
mediaType: ImageMediaTypeSchema,
|
|
866
|
+
data: z.string(),
|
|
867
|
+
size: z.number().int().nonnegative(),
|
|
868
|
+
}),
|
|
869
|
+
z.object({
|
|
870
|
+
kind: z.literal("binary"),
|
|
871
|
+
path: z.string(),
|
|
872
|
+
size: z.number().int().nonnegative(),
|
|
873
|
+
}),
|
|
874
|
+
]),
|
|
875
|
+
},
|
|
876
|
+
/** The workspace's branch, how it stands against its upstream, and its changed files. */
|
|
877
|
+
"git.status": {
|
|
878
|
+
capability: "git",
|
|
879
|
+
params: z.object({ workspaceId: z.string() }),
|
|
880
|
+
result: z.object({
|
|
881
|
+
/** null when no branch is checked out. */
|
|
882
|
+
branch: z.string().nullable(),
|
|
883
|
+
upstream: z.string().optional(),
|
|
884
|
+
ahead: z.number().int().nonnegative(),
|
|
885
|
+
behind: z.number().int().nonnegative(),
|
|
886
|
+
files: z.array(GitFileSchema),
|
|
887
|
+
/** More files than a frame takes: the rest left out. */
|
|
888
|
+
truncated: z.boolean().optional(),
|
|
889
|
+
}),
|
|
890
|
+
},
|
|
891
|
+
/** A file's changes, staged or not, in hunks as an edit's patch has them. */
|
|
892
|
+
"git.diff": {
|
|
893
|
+
capability: "git",
|
|
894
|
+
params: z.object({
|
|
895
|
+
workspaceId: z.string(),
|
|
896
|
+
path: z.string().min(1).max(4096),
|
|
897
|
+
staged: z.boolean().optional(),
|
|
898
|
+
}),
|
|
899
|
+
result: z.object({
|
|
900
|
+
path: z.string(),
|
|
901
|
+
oldPath: z.string().optional(),
|
|
902
|
+
binary: z.boolean().optional(),
|
|
903
|
+
hunks: z.array(DiffHunkSchema),
|
|
904
|
+
/** More than a frame takes: the hunks after left out. */
|
|
905
|
+
truncated: z.boolean().optional(),
|
|
906
|
+
}),
|
|
907
|
+
},
|
|
908
|
+
/** The branch's commits, latest first. */
|
|
909
|
+
"git.log": {
|
|
910
|
+
capability: "git",
|
|
911
|
+
params: z.object({
|
|
912
|
+
workspaceId: z.string(),
|
|
913
|
+
limit: z.number().int().positive().max(200).optional(),
|
|
914
|
+
skip: z.number().int().nonnegative().optional(),
|
|
915
|
+
}),
|
|
916
|
+
result: z.object({
|
|
917
|
+
commits: z.array(z.object({
|
|
918
|
+
hash: z.string(),
|
|
919
|
+
subject: z.string(),
|
|
920
|
+
author: z.string(),
|
|
921
|
+
/** Unix milliseconds. */
|
|
922
|
+
at: z.number(),
|
|
923
|
+
refs: z.array(z.string()).optional(),
|
|
924
|
+
})),
|
|
925
|
+
}),
|
|
926
|
+
},
|
|
216
927
|
};
|
|
217
928
|
/** The notifications a serving device sends, by method. */
|
|
218
929
|
export const RPC_NOTIFICATIONS = {
|
|
219
930
|
"sessions.update": SessionsUpdateSchema,
|
|
220
931
|
"chat.update": ChatUpdateSchema,
|
|
932
|
+
"terminal.update": TerminalUpdateSchema,
|
|
221
933
|
};
|
|
222
934
|
export function isRpcMethod(method) {
|
|
223
935
|
return Object.hasOwn(RPC_METHODS, method);
|