@agentclientprotocol/claude-agent-acp 0.109.1-preview.5 → 0.109.1-preview.7
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 +6 -5
- package/dist/acp-subagents.d.ts +39 -0
- package/dist/acp-subagents.d.ts.map +1 -1
- package/dist/acp-subagents.js +47 -0
- package/dist/client-system-prompt.d.ts +6 -4
- package/dist/client-system-prompt.d.ts.map +1 -1
- package/dist/client-system-prompt.js +7 -2
- package/dist/context-compaction.d.ts.map +1 -1
- package/dist/context-compaction.js +4 -3
- package/dist/native-subagents.d.ts +16 -6
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +72 -13
- package/dist/plans.d.ts +4 -4
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +1 -1
- package/dist/subagent-replay.d.ts +49 -33
- package/dist/subagent-replay.d.ts.map +1 -1
- package/dist/subagent-replay.js +49 -52
- package/dist/tool-calls/reporters/search.d.ts +7 -3
- package/dist/tool-calls/reporters/search.d.ts.map +1 -1
- package/dist/tool-calls/reporters/search.js +9 -4
- package/dist/v1/acp-agent.d.ts +29 -9
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +50 -28
- package/dist/v1/client-connection.d.ts +4 -2
- package/dist/v1/client-connection.d.ts.map +1 -1
- package/dist/v1/client-connection.js +6 -2
- package/dist/v2/agent.js +41 -19
- package/dist/v2/permissions.d.ts +1 -1
- package/dist/v2/permissions.js +1 -1
- package/dist/v2/replay-hold.d.ts +15 -5
- package/dist/v2/replay-hold.d.ts.map +1 -1
- package/dist/v2/replay-hold.js +21 -7
- package/dist/v2/reports.d.ts +4 -0
- package/dist/v2/reports.d.ts.map +1 -1
- package/dist/v2/reports.js +10 -1
- package/dist/v2/session-update.js +3 -3
- package/dist/v2/subagent-replay.d.ts +20 -18
- package/dist/v2/subagent-replay.d.ts.map +1 -1
- package/dist/v2/subagent-replay.js +16 -31
- package/dist/v2/tasks.d.ts +27 -2
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +40 -4
- package/dist/v2/tool-call.d.ts.map +1 -1
- package/dist/v2/tool-call.js +23 -1
- package/package.json +2 -2
|
@@ -49,7 +49,8 @@ export class ClientConnection {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* The client that the agent talks to.
|
|
52
|
+
* The client that the agent talks to. `sending` takes every session update
|
|
53
|
+
* first, before it goes to the client. For an AIR client, every session update
|
|
53
54
|
* passes the {@link ChangedMetaFilter} last, after the native subagent routing,
|
|
54
55
|
* so a `tool_call_update` carries only the `_meta` keys that changed. ACP
|
|
55
56
|
* merges only the top-level tool call fields, not the `_meta` keys. So another
|
|
@@ -58,12 +59,15 @@ export class ClientConnection {
|
|
|
58
59
|
export class ChangedMetaClient {
|
|
59
60
|
inner;
|
|
60
61
|
airClient;
|
|
62
|
+
sending;
|
|
61
63
|
filter = new ChangedMetaFilter();
|
|
62
|
-
constructor(inner, airClient) {
|
|
64
|
+
constructor(inner, airClient, sending = () => { }) {
|
|
63
65
|
this.inner = inner;
|
|
64
66
|
this.airClient = airClient;
|
|
67
|
+
this.sending = sending;
|
|
65
68
|
}
|
|
66
69
|
async sessionUpdate(params) {
|
|
70
|
+
this.sending(params);
|
|
67
71
|
if (!this.airClient())
|
|
68
72
|
return this.inner.sessionUpdate(params);
|
|
69
73
|
const update = this.filter.apply(params.update);
|
package/dist/v2/agent.js
CHANGED
|
@@ -18,7 +18,7 @@ import { deleteSession, getSessionMessages, listSessions, query, } from "@anthro
|
|
|
18
18
|
import packageJson from "../../package.json" with { type: "json" };
|
|
19
19
|
import { messageIdForGrouping } from "../sdk-to-acp.js";
|
|
20
20
|
import { customAgents } from "../session-config-options.js";
|
|
21
|
-
import { restrictedChild } from "../acp-subagents.js";
|
|
21
|
+
import { AnnouncedChildren, restrictedChild } from "../acp-subagents.js";
|
|
22
22
|
import { claudeCliPath, cliDelivery } from "../claude-cli.js";
|
|
23
23
|
import { clientSystemPrompt, sessionSystemPrompt } from "../client-system-prompt.js";
|
|
24
24
|
import { forkSession } from "../fork-session.js";
|
|
@@ -126,6 +126,12 @@ class V2Agent {
|
|
|
126
126
|
* session whose query ended, keep the record.
|
|
127
127
|
*/
|
|
128
128
|
promptKeys = new Map();
|
|
129
|
+
/**
|
|
130
|
+
* The subagent sessions that the sessions announced, from each one's
|
|
131
|
+
* `subagent_update` to the `session/close` of its root or the end of the
|
|
132
|
+
* connection (see `AnnouncedChildren`).
|
|
133
|
+
*/
|
|
134
|
+
children = new AnnouncedChildren();
|
|
129
135
|
translator = new V2UpdateTranslator();
|
|
130
136
|
auth;
|
|
131
137
|
/** The `--hide-claude-auth` subscription guard (see `subscription-guard.ts`). */
|
|
@@ -171,6 +177,8 @@ class V2Agent {
|
|
|
171
177
|
// --- SessionConnection ---------------------------------------------------
|
|
172
178
|
/** Sends the update, after the `replay_complete` of a replay that holds it (see {@link heldBy}). */
|
|
173
179
|
send(notification) {
|
|
180
|
+
// Before the client can name the child that a `subagent_update` announces.
|
|
181
|
+
this.children.sending(notification);
|
|
174
182
|
const send = () => {
|
|
175
183
|
this.ctx.notify(v2.methods.client.session.update, notification).catch((error) => {
|
|
176
184
|
this.logger.error(`Failed to send a ${notification.update.sessionUpdate} update:`, error);
|
|
@@ -180,7 +188,7 @@ class V2Agent {
|
|
|
180
188
|
if (held === undefined)
|
|
181
189
|
send();
|
|
182
190
|
else
|
|
183
|
-
this.replays.defer(held, send);
|
|
191
|
+
this.replays.defer(held, send, notification.sessionId);
|
|
184
192
|
}
|
|
185
193
|
/**
|
|
186
194
|
* The session whose replay holds what the session `sessionId` sends now
|
|
@@ -202,14 +210,14 @@ class V2Agent {
|
|
|
202
210
|
*/
|
|
203
211
|
afterReplay(sessionId, signal, send) {
|
|
204
212
|
const held = sessionId === undefined ? undefined : this.heldBy(sessionId);
|
|
205
|
-
if (held === undefined)
|
|
213
|
+
if (sessionId === undefined || held === undefined)
|
|
206
214
|
return send();
|
|
207
215
|
return new Promise((resolve, reject) => this.replays.defer(held, () => {
|
|
208
216
|
if (signal.aborted)
|
|
209
217
|
reject(new Error("The request was withdrawn"));
|
|
210
218
|
else
|
|
211
219
|
send().then(resolve, reject);
|
|
212
|
-
}));
|
|
220
|
+
}, sessionId));
|
|
213
221
|
}
|
|
214
222
|
requestPermission(request, signal) {
|
|
215
223
|
// Aborting `signal` sends `$/cancel_request`, and stops waiting for the answer.
|
|
@@ -322,7 +330,7 @@ class V2Agent {
|
|
|
322
330
|
* with.
|
|
323
331
|
*/
|
|
324
332
|
async forkSession(params) {
|
|
325
|
-
if (this.
|
|
333
|
+
if (this.children.has(params.sessionId))
|
|
326
334
|
throw restrictedChild(params.sessionId, "fork");
|
|
327
335
|
// Rejects bad `configOptions`, a bad `cwd` or MCP server before the transcript is copied.
|
|
328
336
|
const initial = initialConfigRequests(params.sessionId, params.configOptions);
|
|
@@ -373,7 +381,7 @@ class V2Agent {
|
|
|
373
381
|
if (replayFrom != null && replayFrom.type !== "start") {
|
|
374
382
|
throw RequestError.invalidParams({ replayFrom }, `Replaying from a ${replayFrom.type} cursor is not supported`);
|
|
375
383
|
}
|
|
376
|
-
if (this.
|
|
384
|
+
if (this.children.has(sessionId))
|
|
377
385
|
throw restrictedChild(sessionId, "resume");
|
|
378
386
|
const initial = initialConfigRequests(sessionId, params.configOptions);
|
|
379
387
|
// No await before it: nothing of the session goes out between the request and the hold.
|
|
@@ -466,7 +474,10 @@ class V2Agent {
|
|
|
466
474
|
* subagents (`subagents`), and ends the replay: each replayed child's
|
|
467
475
|
* `replay_complete` (see `SubagentReplay.finish`), then the session's. An
|
|
468
476
|
* AIR client that declared `loadReplayEnd` gets AIR's own mark after it.
|
|
469
|
-
*
|
|
477
|
+
* Then each live child that the history did not have is announced again and
|
|
478
|
+
* gets its `replay_complete` (see `SessionTasks.unreplayedChildren`), ahead
|
|
479
|
+
* of what the replay held of it. All in one synchronous step, as
|
|
480
|
+
* `ReplayHolds.replay` requires.
|
|
470
481
|
*/
|
|
471
482
|
replay(session, messages, subagents) {
|
|
472
483
|
const { sessionId } = session;
|
|
@@ -477,6 +488,9 @@ class V2Agent {
|
|
|
477
488
|
const end = replayEndUpdate(this.clientCapabilities);
|
|
478
489
|
if (end)
|
|
479
490
|
this.send({ sessionId, update: end });
|
|
491
|
+
const unreplayed = session.tasks.unreplayedChildren((child) => subagents?.announced(child) === true, this.replays.senders(sessionId));
|
|
492
|
+
for (const notification of unreplayed)
|
|
493
|
+
this.send(notification);
|
|
480
494
|
});
|
|
481
495
|
}
|
|
482
496
|
async listSessions(params) {
|
|
@@ -521,7 +535,7 @@ class V2Agent {
|
|
|
521
535
|
const session = this.sessions.get(sessionId);
|
|
522
536
|
if (session)
|
|
523
537
|
return { status: "open", state: session.statusState() };
|
|
524
|
-
if (this.
|
|
538
|
+
if (this.children.has(sessionId))
|
|
525
539
|
throw restrictedChild(sessionId, "ask the status of");
|
|
526
540
|
return savedSessionStatus(sessionId);
|
|
527
541
|
}
|
|
@@ -550,7 +564,7 @@ class V2Agent {
|
|
|
550
564
|
};
|
|
551
565
|
let session;
|
|
552
566
|
if (sessionId != null) {
|
|
553
|
-
if (this.
|
|
567
|
+
if (this.children.has(sessionId))
|
|
554
568
|
throw restrictedChild(sessionId, "read the options of");
|
|
555
569
|
// A restart or a resume that runs makes the session active.
|
|
556
570
|
await this.restarts.settled(sessionId);
|
|
@@ -559,7 +573,7 @@ class V2Agent {
|
|
|
559
573
|
}
|
|
560
574
|
const fields = (config, commands) => ({
|
|
561
575
|
configOptions: config.options(),
|
|
562
|
-
//
|
|
576
|
+
// An omitted list means none, like an empty one.
|
|
563
577
|
...(commands.length > 0 ? { availableCommands: commands } : {}),
|
|
564
578
|
});
|
|
565
579
|
const listed = (commands) => commands.list().catch((error) => {
|
|
@@ -587,7 +601,7 @@ class V2Agent {
|
|
|
587
601
|
}
|
|
588
602
|
/** Closing is idempotent: a session that is not active closes at once. */
|
|
589
603
|
async closeSession({ sessionId }) {
|
|
590
|
-
if (this.
|
|
604
|
+
if (this.children.has(sessionId))
|
|
591
605
|
throw restrictedChild(sessionId, "close");
|
|
592
606
|
// A restart that runs ends first, so the close ends the session it started.
|
|
593
607
|
await this.restarts.closing(sessionId);
|
|
@@ -607,11 +621,13 @@ class V2Agent {
|
|
|
607
621
|
this.guard.sessionEnded(sessionId);
|
|
608
622
|
}
|
|
609
623
|
this.restarts.closed(sessionId);
|
|
624
|
+
// After the close's last updates, which name the session's children.
|
|
625
|
+
this.children.rootClosed(sessionId);
|
|
610
626
|
return {};
|
|
611
627
|
}
|
|
612
628
|
/** Deleting a session that does not exist succeeds, as v2 asks. */
|
|
613
629
|
async deleteSession({ sessionId }) {
|
|
614
|
-
if (this.
|
|
630
|
+
if (this.children.has(sessionId))
|
|
615
631
|
throw restrictedChild(sessionId, "delete");
|
|
616
632
|
// A resume that runs, or its start, may make the session live.
|
|
617
633
|
await this.setupSettled(sessionId);
|
|
@@ -639,7 +655,7 @@ class V2Agent {
|
|
|
639
655
|
async setTitle(params) {
|
|
640
656
|
const request = parseRenameSessionRequest(params);
|
|
641
657
|
const { sessionId } = request;
|
|
642
|
-
if (this.
|
|
658
|
+
if (this.children.has(sessionId))
|
|
643
659
|
throw restrictedChild(sessionId, "retitle");
|
|
644
660
|
// Renamed through the query that runs once a restart or resume settled.
|
|
645
661
|
await this.restarts.settled(sessionId);
|
|
@@ -671,7 +687,7 @@ class V2Agent {
|
|
|
671
687
|
const session = this.sessions.get(sessionId);
|
|
672
688
|
if (session)
|
|
673
689
|
return session;
|
|
674
|
-
if (this.
|
|
690
|
+
if (this.children.has(sessionId))
|
|
675
691
|
throw restrictedChild(sessionId, method);
|
|
676
692
|
throw this.inactive(sessionId);
|
|
677
693
|
}
|
|
@@ -694,18 +710,24 @@ class V2Agent {
|
|
|
694
710
|
/** `terminal/cancel` and `tool_call/cancel`: stops a listed item of a session or a child. */
|
|
695
711
|
async cancelItem(sessionId, target) {
|
|
696
712
|
const root = this.sessions.get(sessionId) ?? this.ownerOfChild(sessionId);
|
|
697
|
-
|
|
713
|
+
// A subagent's session is known to the client also when its root's query
|
|
714
|
+
// ended: it lists nothing then.
|
|
715
|
+
if (!root && !this.children.has(sessionId))
|
|
698
716
|
throw this.inactive(sessionId);
|
|
699
|
-
if (!(await root.tasks.cancelItem(sessionId, target))) {
|
|
717
|
+
if (!root || !(await root.tasks.cancelItem(sessionId, target))) {
|
|
700
718
|
throw "terminalId" in target
|
|
701
719
|
? RequestError.invalidParams({ sessionId, terminalId: target.terminalId }, `Terminal ${target.terminalId} is not a command running in the background, so it cannot be cancelled.`)
|
|
702
720
|
: RequestError.invalidParams({ sessionId, toolCallId: target.toolCallId }, `Tool call ${target.toolCallId} is not running in the background, so it cannot be cancelled.`);
|
|
703
721
|
}
|
|
704
722
|
return {};
|
|
705
723
|
}
|
|
706
|
-
/**
|
|
724
|
+
/**
|
|
725
|
+
* The active root session that `sessionId` is a subagent session of.
|
|
726
|
+
* Undefined also for a child whose root's query ended.
|
|
727
|
+
*/
|
|
707
728
|
ownerOfChild(sessionId) {
|
|
708
|
-
|
|
729
|
+
const root = this.children.rootOf(sessionId);
|
|
730
|
+
return root === undefined ? undefined : this.sessions.get(root);
|
|
709
731
|
}
|
|
710
732
|
async dispose() {
|
|
711
733
|
await this.restarts.dispose();
|
|
@@ -752,7 +774,7 @@ class V2Agent {
|
|
|
752
774
|
});
|
|
753
775
|
return {
|
|
754
776
|
configOptions: session.config.options(),
|
|
755
|
-
//
|
|
777
|
+
// An omitted list means none, like an empty one.
|
|
756
778
|
...(commands.length > 0 ? { availableCommands: commands } : {}),
|
|
757
779
|
};
|
|
758
780
|
}
|
package/dist/v2/permissions.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ export declare function v2PermissionRequest(request: AcpPermissionRequest): v2.R
|
|
|
82
82
|
/**
|
|
83
83
|
* The v1 form of the answer to a permission request.
|
|
84
84
|
*
|
|
85
|
-
* v2 adds outcomes that v1 does not know, which
|
|
85
|
+
* v2 adds outcomes that v1 does not know, which v2 says are no
|
|
86
86
|
* approval. They become `cancelled`. In v2, `cancelled` also means that the
|
|
87
87
|
* user dismissed the prompt or the client declined it by policy. So the v2
|
|
88
88
|
* core reads a `cancelled` outcome as the user refusing the tool, unless a
|
package/dist/v2/permissions.js
CHANGED
|
@@ -145,7 +145,7 @@ export function v2PermissionRequest(request) {
|
|
|
145
145
|
/**
|
|
146
146
|
* The v1 form of the answer to a permission request.
|
|
147
147
|
*
|
|
148
|
-
* v2 adds outcomes that v1 does not know, which
|
|
148
|
+
* v2 adds outcomes that v1 does not know, which v2 says are no
|
|
149
149
|
* approval. They become `cancelled`. In v2, `cancelled` also means that the
|
|
150
150
|
* user dismissed the prompt or the client declined it by policy. So the v2
|
|
151
151
|
* core reads a `cancelled` outcome as the user refusing the tool, unless a
|
package/dist/v2/replay-hold.d.ts
CHANGED
|
@@ -7,11 +7,16 @@
|
|
|
7
7
|
* permission request or an elicitation.
|
|
8
8
|
*
|
|
9
9
|
* The replay itself runs in one synchronous step ({@link ReplayHolds.replay}),
|
|
10
|
-
* so what a session sends during that step is its replayed history
|
|
11
|
-
* else tells
|
|
10
|
+
* so what a session sends during that step is not held: its replayed history
|
|
11
|
+
* and the `replay_complete` updates that end it. Nothing else tells that from
|
|
12
|
+
* what waits.
|
|
12
13
|
*/
|
|
13
14
|
export declare class ReplayHolds {
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* What each session with a replay in flight holds, in send order, with the
|
|
17
|
+
* count of its replays and the sessions that sent what it holds: itself and
|
|
18
|
+
* its subagent sessions.
|
|
19
|
+
*/
|
|
15
20
|
private readonly sessions;
|
|
16
21
|
/** Whether {@link replay} runs. */
|
|
17
22
|
private replaying;
|
|
@@ -27,8 +32,13 @@ export declare class ReplayHolds {
|
|
|
27
32
|
* Calling it again does nothing.
|
|
28
33
|
*/
|
|
29
34
|
begin(sessionId: string): () => void;
|
|
30
|
-
/**
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Runs `send`, an update or a request of the session `sender`, once the
|
|
37
|
+
* session `sessionId` no longer holds its sends (see {@link holds}).
|
|
38
|
+
*/
|
|
39
|
+
defer(sessionId: string, send: () => void, sender: string): void;
|
|
40
|
+
/** The sessions whose updates or requests the session `sessionId` holds now. */
|
|
41
|
+
senders(sessionId: string): ReadonlySet<string>;
|
|
32
42
|
/** Runs `replay`, which must send the history and its `replay_complete` before it returns. */
|
|
33
43
|
replay(replay: () => void): void;
|
|
34
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replay-hold.d.ts","sourceRoot":"","sources":["../../src/v2/replay-hold.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"replay-hold.d.ts","sourceRoot":"","sources":["../../src/v2/replay-hold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAW;IACtB;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAGrB;IACJ,mCAAmC;IACnC,OAAO,CAAC,SAAS,CAAS;IAE1B,2CAA2C;IAC3C,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED,mHAAmH;IACnH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;;;OAMG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,IAAI;IAcpC;;;OAGG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAMhE,gFAAgF;IAChF,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC;IAI/C,8FAA8F;IAC9F,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI;CAQjC"}
|
package/dist/v2/replay-hold.js
CHANGED
|
@@ -7,11 +7,16 @@
|
|
|
7
7
|
* permission request or an elicitation.
|
|
8
8
|
*
|
|
9
9
|
* The replay itself runs in one synchronous step ({@link ReplayHolds.replay}),
|
|
10
|
-
* so what a session sends during that step is its replayed history
|
|
11
|
-
* else tells
|
|
10
|
+
* so what a session sends during that step is not held: its replayed history
|
|
11
|
+
* and the `replay_complete` updates that end it. Nothing else tells that from
|
|
12
|
+
* what waits.
|
|
12
13
|
*/
|
|
13
14
|
export class ReplayHolds {
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* What each session with a replay in flight holds, in send order, with the
|
|
17
|
+
* count of its replays and the sessions that sent what it holds: itself and
|
|
18
|
+
* its subagent sessions.
|
|
19
|
+
*/
|
|
15
20
|
sessions = new Map();
|
|
16
21
|
/** Whether {@link replay} runs. */
|
|
17
22
|
replaying = false;
|
|
@@ -31,7 +36,7 @@ export class ReplayHolds {
|
|
|
31
36
|
* Calling it again does nothing.
|
|
32
37
|
*/
|
|
33
38
|
begin(sessionId) {
|
|
34
|
-
const hold = this.sessions.get(sessionId) ?? { resumes: 0, sends: [] };
|
|
39
|
+
const hold = this.sessions.get(sessionId) ?? { resumes: 0, sends: [], senders: new Set() };
|
|
35
40
|
hold.resumes++;
|
|
36
41
|
this.sessions.set(sessionId, hold);
|
|
37
42
|
let released = false;
|
|
@@ -46,9 +51,18 @@ export class ReplayHolds {
|
|
|
46
51
|
send();
|
|
47
52
|
};
|
|
48
53
|
}
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Runs `send`, an update or a request of the session `sender`, once the
|
|
56
|
+
* session `sessionId` no longer holds its sends (see {@link holds}).
|
|
57
|
+
*/
|
|
58
|
+
defer(sessionId, send, sender) {
|
|
59
|
+
const hold = this.sessions.get(sessionId);
|
|
60
|
+
hold.sends.push(send);
|
|
61
|
+
hold.senders.add(sender);
|
|
62
|
+
}
|
|
63
|
+
/** The sessions whose updates or requests the session `sessionId` holds now. */
|
|
64
|
+
senders(sessionId) {
|
|
65
|
+
return this.sessions.get(sessionId)?.senders ?? new Set();
|
|
52
66
|
}
|
|
53
67
|
/** Runs `replay`, which must send the history and its `replay_complete` before it returns. */
|
|
54
68
|
replay(replay) {
|
package/dist/v2/reports.d.ts
CHANGED
|
@@ -87,6 +87,8 @@ export declare class SessionReports {
|
|
|
87
87
|
private lastModel;
|
|
88
88
|
/** A `rate_limit_event` that came before the turn had usage to report it with. */
|
|
89
89
|
private pendingRateLimit;
|
|
90
|
+
/** The last result's `usage_update` carried `_claude/origin`, so the client holds it. */
|
|
91
|
+
private originReported;
|
|
90
92
|
/** The normalized texts of the turn's notices (see {@link repeats}). */
|
|
91
93
|
private noticeTexts;
|
|
92
94
|
/** The context window of the session's model (see `context-window.ts`). */
|
|
@@ -214,6 +216,8 @@ export declare class SessionReports {
|
|
|
214
216
|
/**
|
|
215
217
|
* Sends a `usage_update` with the model the usage belongs to and any
|
|
216
218
|
* pending rate limit in `_meta`, as ACP's usage_update has no field for them.
|
|
219
|
+
* A v2 client keeps each `_meta` key until an update replaces or removes it,
|
|
220
|
+
* so `_claude/model` and `_claude/rateLimit` are the last ones reported.
|
|
217
221
|
*/
|
|
218
222
|
private sendUsage;
|
|
219
223
|
}
|
package/dist/v2/reports.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reports.d.ts","sourceRoot":"","sources":["../../src/v2/reports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,KAAK,EACV,SAAS,EAET,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,UAAU,EACV,0BAA0B,EAC1B,gBAAgB,EAChB,QAAQ,EACT,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAYlE,OAAO,KAAK,EA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MAAM,EAAE,aAAa,CAAC;CAChC,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAqBhC"}
|
package/dist/v2/reports.js
CHANGED
|
@@ -25,6 +25,8 @@ export class SessionReports {
|
|
|
25
25
|
lastModel = null;
|
|
26
26
|
/** A `rate_limit_event` that came before the turn had usage to report it with. */
|
|
27
27
|
pendingRateLimit = null;
|
|
28
|
+
/** The last result's `usage_update` carried `_claude/origin`, so the client holds it. */
|
|
29
|
+
originReported = false;
|
|
28
30
|
/** The normalized texts of the turn's notices (see {@link repeats}). */
|
|
29
31
|
noticeTexts = [];
|
|
30
32
|
/** The context window of the session's model (see `context-window.ts`). */
|
|
@@ -330,12 +332,17 @@ export class SessionReports {
|
|
|
330
332
|
}
|
|
331
333
|
if (this.lastTotal === null)
|
|
332
334
|
return;
|
|
335
|
+
// `_meta` on a v2 `usage_update` patches what the client stores, key by
|
|
336
|
+
// key. `null` removes the origin that an earlier result left, such as
|
|
337
|
+
// `{ kind: "task-notification" }`, when this result has none.
|
|
338
|
+
const origin = message.origin ?? (this.originReported ? null : undefined);
|
|
339
|
+
this.originReported = message.origin != null;
|
|
333
340
|
this.sendUsage({
|
|
334
341
|
sessionUpdate: "usage_update",
|
|
335
342
|
used: this.lastTotal,
|
|
336
343
|
size: this.contextWindow,
|
|
337
344
|
cost: { amount: message.total_cost_usd, currency: "USD" },
|
|
338
|
-
...(
|
|
345
|
+
...(origin !== undefined ? { _meta: { "_claude/origin": origin } } : {}),
|
|
339
346
|
});
|
|
340
347
|
}
|
|
341
348
|
/**
|
|
@@ -483,6 +490,8 @@ export class SessionReports {
|
|
|
483
490
|
/**
|
|
484
491
|
* Sends a `usage_update` with the model the usage belongs to and any
|
|
485
492
|
* pending rate limit in `_meta`, as ACP's usage_update has no field for them.
|
|
493
|
+
* A v2 client keeps each `_meta` key until an update replaces or removes it,
|
|
494
|
+
* so `_claude/model` and `_claude/rateLimit` are the last ones reported.
|
|
486
495
|
*/
|
|
487
496
|
sendUsage(update) {
|
|
488
497
|
let meta = { ...(update._meta ?? {}) };
|
|
@@ -34,17 +34,17 @@ export function v2SessionUpdate(update) {
|
|
|
34
34
|
case "tool_call_update":
|
|
35
35
|
return v2ToolCallUpdate(update);
|
|
36
36
|
case "plan": {
|
|
37
|
-
//
|
|
37
|
+
// v2 has plan operations without a capability, so the agent sends the
|
|
38
38
|
// checklist as `plan_update`; a legacy plan converts the same way.
|
|
39
39
|
const converted = checklistPlanOperation(update.entries);
|
|
40
40
|
return update._meta != null ? { ...converted, _meta: update._meta } : converted;
|
|
41
41
|
}
|
|
42
42
|
case "plan_update":
|
|
43
43
|
case "plan_removed":
|
|
44
|
-
// v1's
|
|
44
|
+
// v1's plan operations have v2's shape.
|
|
45
45
|
return update;
|
|
46
46
|
case "subagent_update": {
|
|
47
|
-
//
|
|
47
|
+
// It has the same shape in v1 and v2.
|
|
48
48
|
const { state, ...association } = update;
|
|
49
49
|
return { ...association, ...(state != null ? { state: v2SubagentState(state) } : {}) };
|
|
50
50
|
}
|
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
* metadata file names the Agent or Task call that launched it (see
|
|
7
7
|
* `subagentHistory`). The replay announces each child right after that call,
|
|
8
8
|
* under its live session id (the agent id), with no capabilities: it cannot
|
|
9
|
-
* run again in this process. Then it sends the child's
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* a child that handed back any report gets no reply from its launch's result.
|
|
9
|
+
* run again in this process. Then it sends the child's history to the child
|
|
10
|
+
* session. As live, the parent is not shown the launch call: its prompt is
|
|
11
|
+
* the parent's outgoing message, and a foreground child's answer its reply. A
|
|
12
|
+
* child's successful SubagentHandback call is its message to the parent
|
|
13
|
+
* instead. Unlike live, the replay does not tell runs apart, so a child that
|
|
14
|
+
* handed back any report gets no reply from its launch's result.
|
|
16
15
|
*
|
|
17
16
|
* A SendMessage call whose message the replay delivered to a child before it
|
|
18
17
|
* reached the call is that message too: the sender's outgoing view, at the
|
|
@@ -32,9 +31,12 @@
|
|
|
32
31
|
* ({@link currentStates}): on its parent and on its own stream. A child that
|
|
33
32
|
* works in the live session, on a resume of the active session, gets its
|
|
34
33
|
* current state from the resume snapshot instead
|
|
35
|
-
* (`SessionTasks.currentState`).
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* (`SessionTasks.currentState`).
|
|
35
|
+
*
|
|
36
|
+
* The replay sends no `config_option_update` of a child: v2 asks an agent not
|
|
37
|
+
* to replay a past one. Each child's configuration goes out after the root's
|
|
38
|
+
* `replay_complete` too, following the child's current state (see
|
|
39
|
+
* `currentChildConfiguration`).
|
|
38
40
|
*
|
|
39
41
|
* A launch without metadata has no known id, so it is not announced: the RFD
|
|
40
42
|
* forbids inventing one. Its Agent call stays an ordinary tool call of the
|
|
@@ -83,6 +85,8 @@ export declare class SubagentReplay {
|
|
|
83
85
|
static load(host: ReplayHost, messages: SessionMessage[], live?: LiveChildren): Promise<SubagentReplay | undefined>;
|
|
84
86
|
/** The hooks of the replay of the root session's history (`messages`). */
|
|
85
87
|
hooks(output: SessionOutput, messages: SessionMessage[]): ReplayHooks;
|
|
88
|
+
/** Whether the replay announced the child session `sessionId`. */
|
|
89
|
+
announced(sessionId: string): boolean;
|
|
86
90
|
/**
|
|
87
91
|
* Ends the replay of the children. Every child's end goes out on its
|
|
88
92
|
* parent, whose history it is. Then each announced child gets its
|
|
@@ -104,9 +108,8 @@ export declare class SubagentReplay {
|
|
|
104
108
|
* session: its work ended, or its process is gone, so its replayed end, on
|
|
105
109
|
* its parent and on its own stream. A `cwd` that is gone, such as a
|
|
106
110
|
* worktree that Claude Code removed, is cleared. Then each replayed child's
|
|
107
|
-
* configuration
|
|
108
|
-
*
|
|
109
|
-
* list.
|
|
111
|
+
* configuration (see `currentChildConfiguration`): the live child's, else
|
|
112
|
+
* the model of its latest response, by the session's model list.
|
|
110
113
|
*
|
|
111
114
|
* The v1 core sends the same after the response (`currentStates`): on v1
|
|
112
115
|
* the response is what separates a replayed child state from a current one.
|
|
@@ -129,16 +132,15 @@ export declare class SubagentReplay {
|
|
|
129
132
|
*/
|
|
130
133
|
private route;
|
|
131
134
|
/**
|
|
132
|
-
* Before a message of `owner`'s history (the root's when undefined):
|
|
133
|
-
* child's response
|
|
134
|
-
* persisted task notification of a child is the state its work ended
|
|
135
|
+
* Before a message of `owner`'s history (the root's when undefined): the
|
|
136
|
+
* model of a child's response is its latest one (see `trackResponseModel`),
|
|
137
|
+
* and a persisted task notification of a child is the state its work ended
|
|
138
|
+
* in.
|
|
135
139
|
*/
|
|
136
140
|
private replaying;
|
|
137
141
|
/** After a message that launched children: each is announced, and its history replays. */
|
|
138
142
|
private replayed;
|
|
139
143
|
private announce;
|
|
140
|
-
/** The `model` of a response of `child`, when it is not the one the client holds. */
|
|
141
|
-
private sendModel;
|
|
142
144
|
/**
|
|
143
145
|
* The rest of a child's user message to replay, or `null` when nothing is
|
|
144
146
|
* left, after its text went out as the child's incoming `session_message`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-replay.d.ts","sourceRoot":"","sources":["../../src/v2/subagent-replay.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"subagent-replay.d.ts","sourceRoot":"","sources":["../../src/v2/subagent-replay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,mDAAmD,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAoBhC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAA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MAAM,GAAG,OAAO;IAIrC;;;;;OAKG;IACH,MAAM,IAAI,IAAI;IAiBd;;;OAGG;IACH,oBAAoB,IAAI,IAAI;IAS5B;;;;;;;;;;;;;;OAcG;IACH,aAAa,IAAI,IAAI;IAQrB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,UAAU;IAWlB;;;OAGG;IACH;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK;IAyDb;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAcjB,0FAA0F;IAC1F,OAAO,CAAC,QAAQ;IAgBhB,OAAO,CAAC,QAAQ;IAiChB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAgBpB;;;;;;;OAOG;IACH,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,KAAK;CAKd"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { launchReply, linkedSessionMessages, nativeSubagentState, rfdLabels, } from "../native-subagents.js";
|
|
2
2
|
import { readSubagentMessages, subagentHistory, subagentLaunchIds, } from "../subagent-history.js";
|
|
3
|
-
import {
|
|
3
|
+
import { currentChildConfiguration, deliveredCall, isDelivery, isDirectory, missingHistoryNotice, ReplayTranscript, replayEndState, textOf, trackResponseModel, } from "../subagent-replay.js";
|
|
4
4
|
import { taskNotificationsOf } from "../task-notifications.js";
|
|
5
5
|
import { REPLAY_COMPLETE } from "./setup.js";
|
|
6
6
|
import { SessionOutput } from "./stream.js";
|
|
@@ -50,6 +50,10 @@ export class SubagentReplay {
|
|
|
50
50
|
this.transcript.scan(messages, output.sessionId);
|
|
51
51
|
return this.ownerHooks(output, undefined);
|
|
52
52
|
}
|
|
53
|
+
/** Whether the replay announced the child session `sessionId`. */
|
|
54
|
+
announced(sessionId) {
|
|
55
|
+
return this.transcript.byAgentId.get(sessionId)?.announced === true;
|
|
56
|
+
}
|
|
53
57
|
/**
|
|
54
58
|
* Ends the replay of the children. Every child's end goes out on its
|
|
55
59
|
* parent, whose history it is. Then each announced child gets its
|
|
@@ -93,9 +97,8 @@ export class SubagentReplay {
|
|
|
93
97
|
* session: its work ended, or its process is gone, so its replayed end, on
|
|
94
98
|
* its parent and on its own stream. A `cwd` that is gone, such as a
|
|
95
99
|
* worktree that Claude Code removed, is cleared. Then each replayed child's
|
|
96
|
-
* configuration
|
|
97
|
-
*
|
|
98
|
-
* list.
|
|
100
|
+
* configuration (see `currentChildConfiguration`): the live child's, else
|
|
101
|
+
* the model of its latest response, by the session's model list.
|
|
99
102
|
*
|
|
100
103
|
* The v1 core sends the same after the response (`currentStates`): on v1
|
|
101
104
|
* the response is what separates a replayed child state from a current one.
|
|
@@ -110,15 +113,13 @@ export class SubagentReplay {
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
sendConfiguration(child) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
const replayed = child.model ? JSON.stringify([childModelOption(child.model)]) : undefined;
|
|
116
|
-
if (!current || JSON.stringify(current) === replayed)
|
|
116
|
+
const configOptions = currentChildConfiguration(child, this.live.configuration(child.sessionId), this.host.models());
|
|
117
|
+
if (!configOptions)
|
|
117
118
|
return;
|
|
118
119
|
child.output.emitV1([
|
|
119
120
|
{
|
|
120
121
|
sessionId: child.sessionId,
|
|
121
|
-
update: { sessionUpdate: "config_option_update", configOptions
|
|
122
|
+
update: { sessionUpdate: "config_option_update", configOptions },
|
|
122
123
|
},
|
|
123
124
|
]);
|
|
124
125
|
}
|
|
@@ -203,15 +204,16 @@ export class SubagentReplay {
|
|
|
203
204
|
return [];
|
|
204
205
|
}
|
|
205
206
|
/**
|
|
206
|
-
* Before a message of `owner`'s history (the root's when undefined):
|
|
207
|
-
* child's response
|
|
208
|
-
* persisted task notification of a child is the state its work ended
|
|
207
|
+
* Before a message of `owner`'s history (the root's when undefined): the
|
|
208
|
+
* model of a child's response is its latest one (see `trackResponseModel`),
|
|
209
|
+
* and a persisted task notification of a child is the state its work ended
|
|
210
|
+
* in.
|
|
209
211
|
*/
|
|
210
212
|
replaying(message, owner) {
|
|
211
213
|
const inner = message.message;
|
|
212
214
|
if (message.type === "assistant") {
|
|
213
215
|
if (owner)
|
|
214
|
-
|
|
216
|
+
trackResponseModel(owner, inner?.model);
|
|
215
217
|
return;
|
|
216
218
|
}
|
|
217
219
|
for (const notification of taskNotificationsOf(inner?.content)) {
|
|
@@ -232,7 +234,6 @@ export class SubagentReplay {
|
|
|
232
234
|
if (messages.length === 0)
|
|
233
235
|
this.withoutHistory++;
|
|
234
236
|
this.announce(child);
|
|
235
|
-
this.sendModel(child, firstResponseModel(messages));
|
|
236
237
|
this.transcript.scan(messages, child.sessionId);
|
|
237
238
|
child.output.replay(messages, this.ownerHooks(child.output, child));
|
|
238
239
|
if (!child.promptSent && typeof child.input.prompt === "string") {
|
|
@@ -261,22 +262,6 @@ export class SubagentReplay {
|
|
|
261
262
|
});
|
|
262
263
|
child.output = new SessionOutput(child.sessionId, child.cwd ?? parentCwd, this.host.translator, (update) => this.host.send({ sessionId: child.sessionId, update }), this.host.logger, true);
|
|
263
264
|
}
|
|
264
|
-
/** The `model` of a response of `child`, when it is not the one the client holds. */
|
|
265
|
-
sendModel(child, model) {
|
|
266
|
-
const entry = responseModelEntry(model, this.host.models());
|
|
267
|
-
if (!entry || !child.output)
|
|
268
|
-
return;
|
|
269
|
-
child.responseModel = model;
|
|
270
|
-
if (child.model?.value === entry.value && child.model.name === entry.name)
|
|
271
|
-
return;
|
|
272
|
-
child.model = entry;
|
|
273
|
-
child.output.emitV1([
|
|
274
|
-
{
|
|
275
|
-
sessionId: child.sessionId,
|
|
276
|
-
update: { sessionUpdate: "config_option_update", configOptions: [childModelOption(entry)] },
|
|
277
|
-
},
|
|
278
|
-
]);
|
|
279
|
-
}
|
|
280
265
|
/**
|
|
281
266
|
* The rest of a child's user message to replay, or `null` when nothing is
|
|
282
267
|
* left, after its text went out as the child's incoming `session_message`.
|