@agentclientprotocol/claude-agent-acp 0.112.1-preview.2 → 0.112.1-preview.3
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 +1 -0
- package/dist/adapter-command.d.ts +56 -0
- package/dist/adapter-command.d.ts.map +1 -0
- package/dist/adapter-command.js +74 -0
- package/dist/claude-cli.d.ts +2 -0
- package/dist/claude-cli.d.ts.map +1 -1
- package/dist/claude-cli.js +5 -1
- package/dist/mcp-command.d.ts.map +1 -1
- package/dist/mcp-command.js +1 -14
- package/dist/plugin-command.d.ts +94 -0
- package/dist/plugin-command.d.ts.map +1 -0
- package/dist/plugin-command.js +633 -0
- package/dist/slash-commands.d.ts +1 -1
- package/dist/slash-commands.d.ts.map +1 -1
- package/dist/slash-commands.js +5 -12
- package/dist/usage-markdown.d.ts +4 -0
- package/dist/usage-markdown.d.ts.map +1 -1
- package/dist/usage-markdown.js +13 -0
- package/dist/v1/acp-agent.d.ts +16 -10
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +125 -77
- package/dist/v1/adapter-commands.d.ts +78 -0
- package/dist/v1/adapter-commands.d.ts.map +1 -0
- package/dist/v1/adapter-commands.js +124 -0
- package/dist/v1/remote-control.d.ts +10 -34
- package/dist/v1/remote-control.d.ts.map +1 -1
- package/dist/v1/remote-control.js +6 -26
- package/dist/v2/{remote-control.d.ts → adapter-commands.d.ts} +34 -17
- package/dist/v2/adapter-commands.d.ts.map +1 -0
- package/dist/v2/adapter-commands.js +121 -0
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +3 -2
- package/dist/v2/commands.d.ts +5 -4
- package/dist/v2/commands.d.ts.map +1 -1
- package/dist/v2/commands.js +4 -2
- package/dist/v2/session.d.ts +14 -8
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +68 -38
- package/dist/v2/subscription-guard.d.ts +2 -1
- package/dist/v2/subscription-guard.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/v2/remote-control.d.ts.map +0 -1
- package/dist/v2/remote-control.js +0 -97
package/dist/v2/session.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { StoppedWork } from "./stopped-work.js";
|
|
|
17
17
|
import { SessionReports } from "./reports.js";
|
|
18
18
|
import { SessionElicitations } from "./elicitation.js";
|
|
19
19
|
import { SessionOutput } from "./stream.js";
|
|
20
|
+
import type { AdapterCommandContext } from "../adapter-command.js";
|
|
20
21
|
import { SessionTasks, type RequestTarget, type RequestContext } from "./tasks.js";
|
|
21
22
|
/** What a session needs of its connection. */
|
|
22
23
|
export interface SessionConnection {
|
|
@@ -46,6 +47,8 @@ export declare class V2Session implements RequestTarget {
|
|
|
46
47
|
readonly additionalDirectories: readonly string[];
|
|
47
48
|
private readonly connection;
|
|
48
49
|
private readonly input;
|
|
50
|
+
/** Where the adapter's commands run: the CLI's env, and whether Claude Code is remote. */
|
|
51
|
+
private readonly adapter;
|
|
49
52
|
/** The prompts not inserted yet, by uuid. */
|
|
50
53
|
private readonly pending;
|
|
51
54
|
/** Priority prompts whose reply still belongs to the open foreground work. */
|
|
@@ -127,8 +130,8 @@ export declare class V2Session implements RequestTarget {
|
|
|
127
130
|
* them, also after a resume of the active session.
|
|
128
131
|
*/
|
|
129
132
|
mcpServersRefused: boolean;
|
|
130
|
-
/** The adapter's
|
|
131
|
-
private readonly
|
|
133
|
+
/** The adapter's own commands, and messages typed in other clients. */
|
|
134
|
+
private readonly adapterCommands;
|
|
132
135
|
/** Who waits for {@link turnBoundary}, with whether it waits for a restart. */
|
|
133
136
|
private readonly boundaryWaiters;
|
|
134
137
|
constructor(sessionId: string, cwd: string,
|
|
@@ -141,7 +144,9 @@ export declare class V2Session implements RequestTarget {
|
|
|
141
144
|
* client's `_meta.claudeCode.options`. A file-change report lists paths
|
|
142
145
|
* in them and in `cwd`.
|
|
143
146
|
*/
|
|
144
|
-
workspaceDirectories?: readonly string[]
|
|
147
|
+
workspaceDirectories?: readonly string[],
|
|
148
|
+
/** Where the adapter's commands run: the CLI's env, and whether Claude Code is remote. */
|
|
149
|
+
adapter?: Pick<AdapterCommandContext, "env" | "remoteSession">);
|
|
145
150
|
/**
|
|
146
151
|
* Starts reading the query. Called once, after its initialization.
|
|
147
152
|
* `mcpServers` are the servers the query started with, and `keys` the
|
|
@@ -161,12 +166,12 @@ export declare class V2Session implements RequestTarget {
|
|
|
161
166
|
/**
|
|
162
167
|
* A restart replaced the query of `previous` with this session's: Remote
|
|
163
168
|
* Control that the user turned off there stays off (see
|
|
164
|
-
* `
|
|
169
|
+
* `SessionAdapterCommands.restartedFrom`).
|
|
165
170
|
*/
|
|
166
171
|
remoteControlRestartedFrom(previous: V2Session): void;
|
|
167
172
|
/**
|
|
168
173
|
* Starts Remote Control for a query that Claude Code asked to start with it
|
|
169
|
-
* (see `
|
|
174
|
+
* (see `SessionAdapterCommands.connectAtStartup`), in line with the session's
|
|
170
175
|
* prompts: the prompts after it wait for its notice, as they wait for the
|
|
171
176
|
* adapter's `/remote-control`.
|
|
172
177
|
*/
|
|
@@ -204,7 +209,8 @@ export declare class V2Session implements RequestTarget {
|
|
|
204
209
|
* runs in the prompt's turn among the session's prompts, so they keep their
|
|
205
210
|
* order, and a cancel or close answers a prompt that waits for it with
|
|
206
211
|
* -32800 as any prompt not inserted yet. Its refusal answers the prompt.
|
|
207
|
-
*
|
|
212
|
+
* A prompt that the adapter serves itself (`/remote-control`, `/plugin`) is
|
|
213
|
+
* not guarded; one that it does not serve is, before it goes to Claude Code.
|
|
208
214
|
*
|
|
209
215
|
* A prompt with an `idempotencyKey` inserts at most one message for the
|
|
210
216
|
* key (see `prompt-keys.ts`): a retry of a prompt that is not answered yet
|
|
@@ -231,7 +237,7 @@ export declare class V2Session implements RequestTarget {
|
|
|
231
237
|
* prompt of the session waits to go to Claude Code, which the restart would
|
|
232
238
|
* answer with -32800. No live subagent remains. Background commands and
|
|
233
239
|
* tool tasks end when the old query retires. Without it, for
|
|
234
|
-
*
|
|
240
|
+
* an adapter command such as `/remote-control`, whose own prompt waits for the boundary.
|
|
235
241
|
*/
|
|
236
242
|
atTurnBoundary(restart: boolean): boolean;
|
|
237
243
|
/** Whether a resume can replace roots without ending work or withdrawing an input request. */
|
|
@@ -257,7 +263,7 @@ export declare class V2Session implements RequestTarget {
|
|
|
257
263
|
* human `origin` that `promptToClaude` stamps.
|
|
258
264
|
*
|
|
259
265
|
* These prompts continue the open turn (`clear-context.ts`), so they do not
|
|
260
|
-
* wait on {@link pushes}:
|
|
266
|
+
* wait on {@link pushes}: an adapter command (`/remote-control`) there waits for the turn to
|
|
261
267
|
* end, which needs them. The client's prompts keep their order among
|
|
262
268
|
* themselves on `pushes`.
|
|
263
269
|
*/
|
package/dist/v2/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/v2/session.ts"],"names":[],"mappings":"AAoCA,OAAO,EAEL,KAAK,+BAA+B,EACpC,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAE9B,KAAK,cAAc,EACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,mDAAmD,CAAC;AACxE,OAAO,KAAK,EAGV,cAAc,EACd,gBAAgB,EAChB,KAAK,EAGL,cAAc,EACf,MAAM,gCAAgC,CAAC;AAGxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE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yCjB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAUrB;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ;IAUhB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,MAAM;IA8Ed;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAYf;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAK1B;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAOtB;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAUtB,+EAA+E;IAC/E,OAAO,CAAC,cAAc;IAMtB,8EAA8E;IAC9E,OAAO,CAAC,KAAK;IAwCb,oFAAoF;IACpF,OAAO,CAAC,UAAU;IAQlB;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAmBhB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAoCjB,6EAA6E;IAC7E,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,0BAA0B;IASlC;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,IAAI;IAIZ,gFAAgF;IAChF,OAAO,CAAC,gBAAgB;IAKxB,0EAA0E;YAC5D,cAAc;IAmB5B,OAAO,CAAC,UAAU;IAQlB,yFAAyF;IACzF,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,WAAW;CAKpB"}
|
package/dist/v2/session.js
CHANGED
|
@@ -56,7 +56,7 @@ import { StoppedWork } from "./stopped-work.js";
|
|
|
56
56
|
import { SessionReports } from "./reports.js";
|
|
57
57
|
import { SessionElicitations } from "./elicitation.js";
|
|
58
58
|
import { SessionOutput } from "./stream.js";
|
|
59
|
-
import {
|
|
59
|
+
import { SessionAdapterCommands } from "./adapter-commands.js";
|
|
60
60
|
import { RemoteControlAtStartup } from "../remote-control.js";
|
|
61
61
|
import { SessionTasks } from "./tasks.js";
|
|
62
62
|
export class V2Session {
|
|
@@ -65,6 +65,7 @@ export class V2Session {
|
|
|
65
65
|
additionalDirectories;
|
|
66
66
|
connection;
|
|
67
67
|
input;
|
|
68
|
+
adapter;
|
|
68
69
|
/** The prompts not inserted yet, by uuid. */
|
|
69
70
|
pending = new Map();
|
|
70
71
|
/** Priority prompts whose reply still belongs to the open foreground work. */
|
|
@@ -146,8 +147,8 @@ export class V2Session {
|
|
|
146
147
|
* them, also after a resume of the active session.
|
|
147
148
|
*/
|
|
148
149
|
mcpServersRefused = false;
|
|
149
|
-
/** The adapter's
|
|
150
|
-
|
|
150
|
+
/** The adapter's own commands, and messages typed in other clients. */
|
|
151
|
+
adapterCommands;
|
|
151
152
|
/** Who waits for {@link turnBoundary}, with whether it waits for a restart. */
|
|
152
153
|
boundaryWaiters = [];
|
|
153
154
|
constructor(sessionId, cwd,
|
|
@@ -160,12 +161,18 @@ export class V2Session {
|
|
|
160
161
|
* client's `_meta.claudeCode.options`. A file-change report lists paths
|
|
161
162
|
* in them and in `cwd`.
|
|
162
163
|
*/
|
|
163
|
-
workspaceDirectories = additionalDirectories
|
|
164
|
+
workspaceDirectories = additionalDirectories,
|
|
165
|
+
/** Where the adapter's commands run: the CLI's env, and whether Claude Code is remote. */
|
|
166
|
+
adapter = {
|
|
167
|
+
env: process.env,
|
|
168
|
+
remoteSession: false,
|
|
169
|
+
}) {
|
|
164
170
|
this.sessionId = sessionId;
|
|
165
171
|
this.cwd = cwd;
|
|
166
172
|
this.additionalDirectories = additionalDirectories;
|
|
167
173
|
this.connection = connection;
|
|
168
174
|
this.input = input;
|
|
175
|
+
this.adapter = adapter;
|
|
169
176
|
this.output = new SessionOutput(sessionId, cwd, connection.translator, (update) => this.send(update), connection.logger);
|
|
170
177
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
171
178
|
const session = this;
|
|
@@ -254,9 +261,12 @@ export class V2Session {
|
|
|
254
261
|
target: (agentId) => this.target(agentId),
|
|
255
262
|
query: () => this.query,
|
|
256
263
|
});
|
|
257
|
-
this.
|
|
264
|
+
this.adapterCommands = new SessionAdapterCommands({
|
|
258
265
|
logger: connection.logger,
|
|
259
266
|
sessionId,
|
|
267
|
+
cwd,
|
|
268
|
+
env: adapter.env,
|
|
269
|
+
remoteSession: adapter.remoteSession,
|
|
260
270
|
query: () => this.query,
|
|
261
271
|
terminalCommands: () => this.commands.terminal(),
|
|
262
272
|
idle: () => this.turnBoundary(false),
|
|
@@ -264,8 +274,9 @@ export class V2Session {
|
|
|
264
274
|
this.inserted(uuid);
|
|
265
275
|
this.openTurn(undefined);
|
|
266
276
|
},
|
|
267
|
-
end: (
|
|
268
|
-
|
|
277
|
+
end: (reply) => {
|
|
278
|
+
if (reply)
|
|
279
|
+
this.output.agentMessage(reply.text, reply.messageId);
|
|
269
280
|
this.closeTurn();
|
|
270
281
|
},
|
|
271
282
|
working: () => !this.atTurnBoundary(false),
|
|
@@ -286,7 +297,7 @@ export class V2Session {
|
|
|
286
297
|
this.hasHistory = resumed;
|
|
287
298
|
this.mcpServers = JSON.stringify(mcpServers);
|
|
288
299
|
this.mcpServersRefused = mcpServersRefused;
|
|
289
|
-
this.commands = new SessionCommands(query);
|
|
300
|
+
this.commands = new SessionCommands(query, this.adapter.remoteSession);
|
|
290
301
|
void this.consume(query);
|
|
291
302
|
}
|
|
292
303
|
/**
|
|
@@ -295,19 +306,19 @@ export class V2Session {
|
|
|
295
306
|
* {@link connectRemoteControlAtStartup}.
|
|
296
307
|
*/
|
|
297
308
|
setRemoteControlAtStartup(asked) {
|
|
298
|
-
this.
|
|
309
|
+
this.adapterCommands.atStartup = new RemoteControlAtStartup(asked);
|
|
299
310
|
}
|
|
300
311
|
/**
|
|
301
312
|
* A restart replaced the query of `previous` with this session's: Remote
|
|
302
313
|
* Control that the user turned off there stays off (see
|
|
303
|
-
* `
|
|
314
|
+
* `SessionAdapterCommands.restartedFrom`).
|
|
304
315
|
*/
|
|
305
316
|
remoteControlRestartedFrom(previous) {
|
|
306
|
-
this.
|
|
317
|
+
this.adapterCommands.restartedFrom(previous.adapterCommands);
|
|
307
318
|
}
|
|
308
319
|
/**
|
|
309
320
|
* Starts Remote Control for a query that Claude Code asked to start with it
|
|
310
|
-
* (see `
|
|
321
|
+
* (see `SessionAdapterCommands.connectAtStartup`), in line with the session's
|
|
311
322
|
* prompts: the prompts after it wait for its notice, as they wait for the
|
|
312
323
|
* adapter's `/remote-control`.
|
|
313
324
|
*/
|
|
@@ -316,7 +327,7 @@ export class V2Session {
|
|
|
316
327
|
if (this.closed)
|
|
317
328
|
return;
|
|
318
329
|
try {
|
|
319
|
-
await this.
|
|
330
|
+
await this.adapterCommands.connectAtStartup();
|
|
320
331
|
}
|
|
321
332
|
catch (error) {
|
|
322
333
|
this.connection.logger.error(`Session ${this.sessionId}: failed to start Remote Control with the session`, error);
|
|
@@ -377,7 +388,8 @@ export class V2Session {
|
|
|
377
388
|
* runs in the prompt's turn among the session's prompts, so they keep their
|
|
378
389
|
* order, and a cancel or close answers a prompt that waits for it with
|
|
379
390
|
* -32800 as any prompt not inserted yet. Its refusal answers the prompt.
|
|
380
|
-
*
|
|
391
|
+
* A prompt that the adapter serves itself (`/remote-control`, `/plugin`) is
|
|
392
|
+
* not guarded; one that it does not serve is, before it goes to Claude Code.
|
|
381
393
|
*
|
|
382
394
|
* A prompt with an `idempotencyKey` inserts at most one message for the
|
|
383
395
|
* key (see `prompt-keys.ts`): a retry of a prompt that is not answered yet
|
|
@@ -410,9 +422,12 @@ export class V2Session {
|
|
|
410
422
|
* stored: the client's next retry then gets the `messageId`.
|
|
411
423
|
*/
|
|
412
424
|
submit(params, request, guard, { uuid, stored }, signal) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
425
|
+
// Whether the adapter may serve the prompt itself: `run` decides, and a prompt
|
|
426
|
+
// that it does not serve goes to Claude Code through the guard like any other.
|
|
427
|
+
const adapterCommand = this.adapterCommands.mayRun(request.prompt);
|
|
428
|
+
const guarded = guard && !adapterCommand ? guard : undefined;
|
|
429
|
+
// A prompt that the guard refuses titles nothing and sends no notice: one that
|
|
430
|
+
// may be an adapter command waits for `run` to serve it, or for the guard.
|
|
416
431
|
const sent = () => {
|
|
417
432
|
this.reports.promptSent(request.prompt);
|
|
418
433
|
// The notice of a mode fallback at the session's start, which sends it at once.
|
|
@@ -421,12 +436,12 @@ export class V2Session {
|
|
|
421
436
|
const message = { ...promptToClaude(request), uuid };
|
|
422
437
|
/** What a prompt that is new to the session registers before it goes to Claude Code. */
|
|
423
438
|
const accept = () => {
|
|
424
|
-
if (!
|
|
439
|
+
if (!guard)
|
|
425
440
|
sent();
|
|
426
441
|
// Only a prompt that goes to Claude Code gets a file-change report, as
|
|
427
|
-
// on v1:
|
|
442
|
+
// on v1: a prompt that may be an adapter command registers once it passes
|
|
428
443
|
// the prompt on (below).
|
|
429
|
-
if (!
|
|
444
|
+
if (!adapterCommand)
|
|
430
445
|
this.fileChanges?.requested(uuid, params._meta);
|
|
431
446
|
const localCommand = this.commands.localCommand(request.prompt);
|
|
432
447
|
if (localCommand)
|
|
@@ -455,6 +470,18 @@ export class V2Session {
|
|
|
455
470
|
withdraw();
|
|
456
471
|
// A cancel or close answered it before it went out.
|
|
457
472
|
const answered = () => this.pending.get(uuid) !== pending || this.closed;
|
|
473
|
+
/** Runs the guard. `false` once its refusal or a cancel answered the prompt. */
|
|
474
|
+
const passGuard = async (check) => {
|
|
475
|
+
try {
|
|
476
|
+
// Set by `start`, which runs before the agent lists the session.
|
|
477
|
+
await check(this.query);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
this.failPrompt(uuid, error);
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
return !answered();
|
|
484
|
+
};
|
|
458
485
|
this.pushes = this.pushes
|
|
459
486
|
.then(() => this.interrupting)
|
|
460
487
|
.then(async () => {
|
|
@@ -473,23 +500,20 @@ export class V2Session {
|
|
|
473
500
|
accept();
|
|
474
501
|
}
|
|
475
502
|
if (guarded) {
|
|
476
|
-
|
|
477
|
-
// Set by `start`, which runs before the agent lists the session.
|
|
478
|
-
await guarded(this.query);
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
this.failPrompt(uuid, error);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
if (answered())
|
|
503
|
+
if (!(await passGuard(guarded)))
|
|
485
504
|
return;
|
|
486
505
|
sent();
|
|
487
506
|
}
|
|
488
|
-
// The prompts after
|
|
489
|
-
if (
|
|
507
|
+
// The prompts after an adapter command wait for it.
|
|
508
|
+
if (adapterCommand) {
|
|
490
509
|
try {
|
|
491
|
-
|
|
510
|
+
const outcome = await this.adapterCommands.run(request.prompt, uuid, () => !answered());
|
|
511
|
+
if (outcome !== "not-served") {
|
|
512
|
+
// A prompt that a cancel or close answered titles nothing.
|
|
513
|
+
if (guard && outcome === "ran")
|
|
514
|
+
sent();
|
|
492
515
|
return;
|
|
516
|
+
}
|
|
493
517
|
}
|
|
494
518
|
catch (error) {
|
|
495
519
|
this.failPrompt(uuid, error);
|
|
@@ -497,6 +521,11 @@ export class V2Session {
|
|
|
497
521
|
}
|
|
498
522
|
if (answered())
|
|
499
523
|
return;
|
|
524
|
+
if (guard) {
|
|
525
|
+
if (!(await passGuard(guard)))
|
|
526
|
+
return;
|
|
527
|
+
sent();
|
|
528
|
+
}
|
|
500
529
|
this.fileChanges?.requested(uuid, params._meta);
|
|
501
530
|
}
|
|
502
531
|
if (this.foreground || [...this.pending.values()].some((prompt) => prompt.pushed)) {
|
|
@@ -506,7 +535,7 @@ export class V2Session {
|
|
|
506
535
|
this.steeredPrompts.add(uuid);
|
|
507
536
|
}
|
|
508
537
|
pending.pushed = true;
|
|
509
|
-
this.
|
|
538
|
+
this.adapterCommands.pushed(uuid);
|
|
510
539
|
this.input.push(message);
|
|
511
540
|
this.reports.promptQueued(request.prompt);
|
|
512
541
|
});
|
|
@@ -518,7 +547,7 @@ export class V2Session {
|
|
|
518
547
|
* prompt of the session waits to go to Claude Code, which the restart would
|
|
519
548
|
* answer with -32800. No live subagent remains. Background commands and
|
|
520
549
|
* tool tasks end when the old query retires. Without it, for
|
|
521
|
-
*
|
|
550
|
+
* an adapter command such as `/remote-control`, whose own prompt waits for the boundary.
|
|
522
551
|
*/
|
|
523
552
|
atTurnBoundary(restart) {
|
|
524
553
|
return (!this.closed &&
|
|
@@ -574,7 +603,7 @@ export class V2Session {
|
|
|
574
603
|
resolve();
|
|
575
604
|
return;
|
|
576
605
|
}
|
|
577
|
-
this.
|
|
606
|
+
this.adapterCommands.pushed(message.uuid);
|
|
578
607
|
this.input.push(message);
|
|
579
608
|
});
|
|
580
609
|
});
|
|
@@ -586,7 +615,7 @@ export class V2Session {
|
|
|
586
615
|
* human `origin` that `promptToClaude` stamps.
|
|
587
616
|
*
|
|
588
617
|
* These prompts continue the open turn (`clear-context.ts`), so they do not
|
|
589
|
-
* wait on {@link pushes}:
|
|
618
|
+
* wait on {@link pushes}: an adapter command (`/remote-control`) there waits for the turn to
|
|
590
619
|
* end, which needs them. The client's prompts keep their order among
|
|
591
620
|
* themselves on `pushes`.
|
|
592
621
|
*/
|
|
@@ -600,7 +629,7 @@ export class V2Session {
|
|
|
600
629
|
.then(() => {
|
|
601
630
|
if (this.closed)
|
|
602
631
|
return;
|
|
603
|
-
this.
|
|
632
|
+
this.adapterCommands.pushed(uuid);
|
|
604
633
|
this.input.push(message);
|
|
605
634
|
});
|
|
606
635
|
}
|
|
@@ -664,6 +693,7 @@ export class V2Session {
|
|
|
664
693
|
for (const request of this.requests)
|
|
665
694
|
request.coveredByCancel = true;
|
|
666
695
|
this.turnLocalCommand?.abort.abort();
|
|
696
|
+
this.adapterCommands.abort();
|
|
667
697
|
// The subagents that the work waits on stop with it. Background ones go on.
|
|
668
698
|
this.tasks.cancelForeground();
|
|
669
699
|
if (heldTurn)
|
|
@@ -978,7 +1008,7 @@ export class V2Session {
|
|
|
978
1008
|
return;
|
|
979
1009
|
}
|
|
980
1010
|
// A message typed in another client of the session.
|
|
981
|
-
const remote = this.
|
|
1011
|
+
const remote = this.adapterCommands.remoteMessage(message);
|
|
982
1012
|
if (remote !== undefined)
|
|
983
1013
|
this.output.userMessage(remote, message.uuid);
|
|
984
1014
|
this.promptStarted(message.uuid);
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
* restarts the query at the next prompt that finds the session idle (see
|
|
19
19
|
* `restarts.ts`), so its start judges the current account.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* A command that the adapter serves (`/remote-control`, `/plugin`) is not
|
|
22
|
+
* guarded. One that Claude Code serves is.
|
|
22
23
|
*/
|
|
23
24
|
import type { AccountInfo, Query } from "@anthropic-ai/claude-agent-sdk";
|
|
24
25
|
import type { Logger } from "../logger.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-guard.d.ts","sourceRoot":"","sources":["../../src/v2/subscription-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"subscription-guard.d.ts","sourceRoot":"","sources":["../../src/v2/subscription-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,mBAAmB,CAAC;AASzE,sEAAsE;AACtE,MAAM,WAAW,SAAS;IACxB,gEAAgE;IAChE,cAAc,IAAI,OAAO,CAAC;IAC1B,qEAAqE;IACrE,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;CAC/D;AAQD,qBAAa,iBAAiB;IAI1B,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IANxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAG3C,IAAI,EAAE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* a person types in another client of the session over Remote Control.
|
|
4
|
-
*
|
|
5
|
-
* The command, its listing, and its reply are the v1 core's
|
|
6
|
-
* (`remote-control.ts`). The command
|
|
7
|
-
* runs as a local command of its own turn, as v2 asks of one ("Local handling
|
|
8
|
-
* still uses the foreground lifecycle"): its prompt is inserted as a
|
|
9
|
-
* live-only `user_message`, the turn reports `running`, the reply goes out,
|
|
10
|
-
* and the turn ends `idle` with `end_turn`. It waits until no turn is open
|
|
11
|
-
* and no prompt waits in Claude Code's queue, and the prompts after it wait
|
|
12
|
-
* for it: v2 asks to hold a prompt rather than reject it while Claude works.
|
|
13
|
-
*
|
|
14
|
-
* Remote Control also starts with a query that Claude Code asked to start
|
|
15
|
-
* with it (`remoteControlAtStartup` in the settings, else the policy default or
|
|
16
|
-
* a rollout; see `startsWithRemoteControl`). That is no turn: it reports in a
|
|
17
|
-
* notice, as v1 does.
|
|
18
|
-
*/
|
|
19
|
-
import { randomUUID } from "node:crypto";
|
|
20
|
-
import { adapterRemoteControlCommand, isRemoteHumanMessage, parseRemoteControlCommand, RemoteControlAtStartup, runRemoteControlCommand, } from "../remote-control.js";
|
|
21
|
-
export class SessionRemoteControl {
|
|
22
|
-
host;
|
|
23
|
-
/** The uuids of the prompts that this session sent, until Claude Code echoes them. */
|
|
24
|
-
sent = new Set();
|
|
25
|
-
/**
|
|
26
|
-
* Remote Control at the start of this query, which Claude Code can ask for
|
|
27
|
-
* at `initialize` (see `V2Session.setRemoteControlAtStartup`).
|
|
28
|
-
*/
|
|
29
|
-
atStartup = new RemoteControlAtStartup(false);
|
|
30
|
-
constructor(host) {
|
|
31
|
-
this.host = host;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Starts Remote Control after the setup response of a query that Claude
|
|
35
|
-
* Code asked to start with it, and reports how it went in a notice (see
|
|
36
|
-
* `RemoteControlAtStartup`). It runs once per query, so a later resume of
|
|
37
|
-
* the live session starts nothing, while a restart of the query (see
|
|
38
|
-
* `restarts.ts`), whose new query asks again, starts it again, unless the
|
|
39
|
-
* user turned it off before (see {@link restartedFrom}). The session holds
|
|
40
|
-
* its prompts back until the notice is sent.
|
|
41
|
-
*/
|
|
42
|
-
async connectAtStartup() {
|
|
43
|
-
const notice = this.atStartup.connect(this.host);
|
|
44
|
-
if (notice)
|
|
45
|
-
this.host.notice(await notice);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* A restart replaced the query of `previous` with this one: Remote Control
|
|
49
|
-
* that the user turned off there stays off (see
|
|
50
|
-
* `RemoteControlAtStartup.restartedFrom`).
|
|
51
|
-
*/
|
|
52
|
-
restartedFrom(previous) {
|
|
53
|
-
this.atStartup.restartedFrom(previous.atStartup);
|
|
54
|
-
}
|
|
55
|
-
/** Whether `prompt` may be the adapter's command, which {@link run} then decides. */
|
|
56
|
-
mayRun(prompt) {
|
|
57
|
-
return parseRemoteControlCommand(prompt) !== null;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Runs `prompt` as the adapter's command, as its turn, once the session is
|
|
61
|
-
* idle. Resolves `false` without running it when Claude Code serves the
|
|
62
|
-
* command itself or the query has no Remote Control: the prompt then goes
|
|
63
|
-
* to Claude Code. `stillPending` tells whether a cancel or close answered
|
|
64
|
-
* the prompt meanwhile.
|
|
65
|
-
*/
|
|
66
|
-
async run(prompt, uuid, stillPending) {
|
|
67
|
-
const query = this.host.query();
|
|
68
|
-
if (!query)
|
|
69
|
-
return false;
|
|
70
|
-
const command = await adapterRemoteControlCommand(prompt, query, this.host.terminalCommands());
|
|
71
|
-
if (!command)
|
|
72
|
-
return false;
|
|
73
|
-
if (!(await this.host.idle()) || !stillPending())
|
|
74
|
-
return true;
|
|
75
|
-
this.host.begin(uuid);
|
|
76
|
-
// A restart of the query keeps what the user chose last.
|
|
77
|
-
this.atStartup.commandRan(command.command);
|
|
78
|
-
// The turn is open across the network call, so the session reads as busy.
|
|
79
|
-
const text = await runRemoteControlCommand(command.query, command.command, (message) => this.host.logger.error(message));
|
|
80
|
-
this.host.end(text, randomUUID());
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
/** The session sent the prompt `uuid` to Claude Code. */
|
|
84
|
-
pushed(uuid) {
|
|
85
|
-
this.sent.add(uuid);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* The content of a prompt echo to show as a user message: one that a
|
|
89
|
-
* person typed in another client of the session. `undefined` for the
|
|
90
|
-
* echo of a prompt that this session sent, and for any other echo.
|
|
91
|
-
*/
|
|
92
|
-
remoteMessage(message) {
|
|
93
|
-
if (message.uuid && this.sent.delete(message.uuid))
|
|
94
|
-
return undefined;
|
|
95
|
-
return isRemoteHumanMessage(message) ? message.message.content : undefined;
|
|
96
|
-
}
|
|
97
|
-
}
|