@agentclientprotocol/claude-agent-acp 0.112.1-preview.1 → 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/dist/v2/tasks.d.ts +9 -2
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +80 -15
- 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,KAA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AO,CAAC,MAAM;IAwHd;;;OAGG;IACH,OAAO,CAAC,MAAM;IAqBd,OAAO,CAAC,SAAS;IAyCjB;;;;;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,SAAS,EACf,MAAM,EAAE,MAAM;IAC/B,6EAA6E;IAC5D,qBAAqB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI;IAGrE,wDAAwD;IACxD,MAAM,IAAI,OAAO;IAIjB;;;OAGG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAqBhG;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS;IAc7F,6EAA6E;IAC7E,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIlC,oFAAoF;IACpF,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAQlC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAGtC"}
|
package/dist/v2/tasks.d.ts
CHANGED
|
@@ -118,6 +118,12 @@ export declare class SessionTasks {
|
|
|
118
118
|
private readonly toolCalls;
|
|
119
119
|
/** The tool calls that returned: their tasks no longer hold their work. */
|
|
120
120
|
private readonly returned;
|
|
121
|
+
/**
|
|
122
|
+
* The tasks that already ended, by task id. A task can end before the call
|
|
123
|
+
* that started it returns: remembering the end keeps that call from being
|
|
124
|
+
* kept in progress for a task no later level can name.
|
|
125
|
+
*/
|
|
126
|
+
private readonly endedTasks;
|
|
121
127
|
/** What a subagent's hooks reported before the child was announced, by agent id. */
|
|
122
128
|
private readonly startedHooks;
|
|
123
129
|
/** The children's configurations (see `child-config.ts`). */
|
|
@@ -377,8 +383,9 @@ export declare class SessionTasks {
|
|
|
377
383
|
*/
|
|
378
384
|
private taskEnded;
|
|
379
385
|
/**
|
|
380
|
-
* Claude Code's live background task set changed.
|
|
381
|
-
*
|
|
386
|
+
* Claude Code's live background task set changed. Calls whose task it now
|
|
387
|
+
* names are added to the list, and terminals and tool calls whose tasks it no
|
|
388
|
+
* longer holds ended, without saying how.
|
|
382
389
|
*/
|
|
383
390
|
private levelChanged;
|
|
384
391
|
/** A new child, not announced, which runs; the messages of its launch that came wait for it. */
|
package/dist/v2/tasks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/v2/tasks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tasks.d.ts","sourceRoot":"","sources":["../../src/v2/tasks.ts"],"names":[],"mappings":"AAyDA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,cAAc,EACf,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAElE,OAAO,EAKL,KAAK,UAAU,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAqBL,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAUhC,OAAO,KAAK,EAAkB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,iDAAiD;AACjD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAA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QAAQ;IAKhB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAepB,qDAAqD;IACrD,OAAO,CAAC,YAAY;IAepB;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IA4Cb;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,UAAU;IAmBlB,6EAA6E;IAC7E,OAAO,CAAC,UAAU;IAelB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAkBxB,yFAAyF;IACzF,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,OAAO;CAGhB;AAoBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CASlE"}
|
package/dist/v2/tasks.js
CHANGED
|
@@ -42,10 +42,12 @@
|
|
|
42
42
|
* - A task that a tool call started, such as a `Monitor` or `Workflow` call,
|
|
43
43
|
* is that tool call, kept `in_progress` (or `paused`) until the task ends.
|
|
44
44
|
* A workflow's `task_progress` shows on its call (`workflowCard`).
|
|
45
|
-
* - Any other background task, such as one that a hook started
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
45
|
+
* - Any other background task, such as one that a hook started, gets a tool
|
|
46
|
+
* call that the adapter starts for it (`task_<taskId>`), as v2 lists
|
|
47
|
+
* background work only by an entity the client knows. A Monitor or Workflow
|
|
48
|
+
* call, or a call whose `task_started` came before its result, stays its
|
|
49
|
+
* task's entity also when the task joins the live set after the result (see
|
|
50
|
+
* `toolResults` and `levelChanged`).
|
|
49
51
|
*
|
|
50
52
|
* Claude Code's interrupt spares background tasks (`perTaskStopAffordance`),
|
|
51
53
|
* so `session/cancel` leaves listed work running, as v2 asks. A session
|
|
@@ -68,6 +70,19 @@ import { REPLAY_COMPLETE } from "./setup.js";
|
|
|
68
70
|
import { SubagentReplay } from "./subagent-replay.js";
|
|
69
71
|
/** The tools whose structured result names the task that the call started. */
|
|
70
72
|
const TASK_TOOLS = new Set(["Monitor", "Workflow"]);
|
|
73
|
+
/**
|
|
74
|
+
* Whether the call of `toolUseName` is the entity of `task` in the list, rather
|
|
75
|
+
* than the display terminal of a command. Claude Code reports a Monitor's task
|
|
76
|
+
* as `local_bash`, like a shell command's: a command is its terminal, while the
|
|
77
|
+
* call of a tool that starts a task is that task.
|
|
78
|
+
*/
|
|
79
|
+
function keepsTaskCall(toolUseName, taskType) {
|
|
80
|
+
if (taskType === "local_agent")
|
|
81
|
+
return false;
|
|
82
|
+
if (taskType === "local_bash" && !TASK_TOOLS.has(toolUseName))
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
71
86
|
/** The most messages that wait for the announcement of one child. */
|
|
72
87
|
const MAX_PENDING_MESSAGES = 256;
|
|
73
88
|
/** The most children not announced yet whose hooks wait for them. */
|
|
@@ -127,6 +142,12 @@ export class SessionTasks {
|
|
|
127
142
|
toolCalls = new Map();
|
|
128
143
|
/** The tool calls that returned: their tasks no longer hold their work. */
|
|
129
144
|
returned = new Set();
|
|
145
|
+
/**
|
|
146
|
+
* The tasks that already ended, by task id. A task can end before the call
|
|
147
|
+
* that started it returns: remembering the end keeps that call from being
|
|
148
|
+
* kept in progress for a task no later level can name.
|
|
149
|
+
*/
|
|
150
|
+
endedTasks = new Set();
|
|
130
151
|
/** What a subagent's hooks reported before the child was announced, by agent id. */
|
|
131
152
|
startedHooks = new Map();
|
|
132
153
|
/** The children's configurations (see `child-config.ts`). */
|
|
@@ -295,14 +316,31 @@ export class SessionTasks {
|
|
|
295
316
|
}
|
|
296
317
|
const taskId = (TASK_TOOLS.has(toolUse.name) ? structuredTaskId : undefined) ??
|
|
297
318
|
[...this.started].find(([, task]) => task.toolUseId === toolCallId)?.[0];
|
|
298
|
-
|
|
299
|
-
|
|
319
|
+
if (taskId === undefined)
|
|
320
|
+
continue;
|
|
321
|
+
const task = this.level.get(taskId);
|
|
322
|
+
// A call outside TASK_TOOLS finds its task only through `this.started`.
|
|
323
|
+
// When task_started gave the task's type, a call that is not its task's
|
|
324
|
+
// entity ends with its result. Otherwise `levelChanged` ends it once a
|
|
325
|
+
// level gives the type.
|
|
326
|
+
if (!keepsTaskCall(toolUse.name, task?.taskType ?? this.started.get(taskId)?.taskType))
|
|
300
327
|
continue;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
328
|
+
if (!task) {
|
|
329
|
+
// A task that already ended ends its call with the result: no later
|
|
330
|
+
// level can name it. Any other task can join the level after this
|
|
331
|
+
// result, so keep the call unleveled until `levelChanged` names it.
|
|
332
|
+
if (this.endedTasks.has(taskId))
|
|
333
|
+
continue;
|
|
334
|
+
this.toolCalls.set(taskId, {
|
|
335
|
+
toolCallId,
|
|
336
|
+
output,
|
|
337
|
+
toolUse: { name: toolUse.name, input: toolUse.input },
|
|
338
|
+
paused: false,
|
|
339
|
+
unleveled: true,
|
|
340
|
+
});
|
|
341
|
+
runningToolCalls.add(toolCallId);
|
|
305
342
|
continue;
|
|
343
|
+
}
|
|
306
344
|
this.toolCalls.set(taskId, {
|
|
307
345
|
toolCallId,
|
|
308
346
|
output,
|
|
@@ -989,6 +1027,7 @@ export class SessionTasks {
|
|
|
989
1027
|
if (commandToolCall !== undefined)
|
|
990
1028
|
this.foreground.get(commandToolCall)?.stop();
|
|
991
1029
|
this.started.delete(taskId);
|
|
1030
|
+
this.endedTasks.add(taskId);
|
|
992
1031
|
const terminal = this.terminals.get(taskId);
|
|
993
1032
|
if (terminal && !terminal.ending) {
|
|
994
1033
|
terminal.ending = true;
|
|
@@ -1004,10 +1043,12 @@ export class SessionTasks {
|
|
|
1004
1043
|
this.publish();
|
|
1005
1044
|
}
|
|
1006
1045
|
/**
|
|
1007
|
-
* Claude Code's live background task set changed.
|
|
1008
|
-
*
|
|
1046
|
+
* Claude Code's live background task set changed. Calls whose task it now
|
|
1047
|
+
* names are added to the list, and terminals and tool calls whose tasks it no
|
|
1048
|
+
* longer holds ended, without saying how.
|
|
1009
1049
|
*/
|
|
1010
1050
|
levelChanged(tasks) {
|
|
1051
|
+
const previous = this.level;
|
|
1011
1052
|
this.level = new Map(tasks.map((task) => [
|
|
1012
1053
|
task.task_id,
|
|
1013
1054
|
{
|
|
@@ -1018,11 +1059,35 @@ export class SessionTasks {
|
|
|
1018
1059
|
progress: this.level.get(task.task_id)?.progress,
|
|
1019
1060
|
},
|
|
1020
1061
|
]));
|
|
1062
|
+
// A task that left the live set ended, also when no task event said so: a
|
|
1063
|
+
// call whose task leaves the level before its result must not be kept.
|
|
1064
|
+
for (const taskId of previous.keys()) {
|
|
1065
|
+
if (!this.level.has(taskId))
|
|
1066
|
+
this.endedTasks.add(taskId);
|
|
1067
|
+
}
|
|
1021
1068
|
for (const [taskId, terminal] of this.terminals) {
|
|
1022
1069
|
if (this.level.get(taskId)?.ambient === false)
|
|
1023
1070
|
terminal.leveled = true;
|
|
1024
1071
|
}
|
|
1072
|
+
// A call whose task joined the level after its result is part of that task
|
|
1073
|
+
// again: it stays in progress (or paused, as a task update already set it)
|
|
1074
|
+
// and the next list names it. When the task is not the call's, the call ends
|
|
1075
|
+
// completed, as its result reported it.
|
|
1076
|
+
for (const [taskId, call] of this.toolCalls) {
|
|
1077
|
+
if (!call.unleveled)
|
|
1078
|
+
continue;
|
|
1079
|
+
const task = this.level.get(taskId);
|
|
1080
|
+
if (!task)
|
|
1081
|
+
continue;
|
|
1082
|
+
call.unleveled = false;
|
|
1083
|
+
if (call.toolUse === undefined || !keepsTaskCall(call.toolUse.name, task.taskType)) {
|
|
1084
|
+
this.endToolCall(taskId, "completed");
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1025
1087
|
for (const taskId of [...this.terminals.keys(), ...this.toolCalls.keys()]) {
|
|
1088
|
+
// A kept call waits for a later level that names its task.
|
|
1089
|
+
if (this.toolCalls.get(taskId)?.unleveled)
|
|
1090
|
+
continue;
|
|
1026
1091
|
if (!this.level.has(taskId))
|
|
1027
1092
|
this.taskEnded(taskId, "completed");
|
|
1028
1093
|
}
|
|
@@ -1867,9 +1932,9 @@ export class SessionTasks {
|
|
|
1867
1932
|
// A subagent is listed as its session.
|
|
1868
1933
|
if (task.taskType === "local_bash" || task.taskType === "local_agent")
|
|
1869
1934
|
continue;
|
|
1870
|
-
// A task joins the level before its `task_started
|
|
1871
|
-
// call that starts it returns
|
|
1872
|
-
//
|
|
1935
|
+
// A task usually joins the level before its `task_started` and the tool
|
|
1936
|
+
// call that starts it returns, but not always: a call that arrived before
|
|
1937
|
+
// its task joined the level is kept unleveled (see `toolResults`).
|
|
1873
1938
|
const started = this.started.get(taskId);
|
|
1874
1939
|
if (!started || (started.toolUseId && !this.returned.has(started.toolUseId)))
|
|
1875
1940
|
continue;
|