@agentclientprotocol/claude-agent-acp 0.111.1-preview.1 → 0.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/dist/air-extension.d.ts +7 -0
- package/dist/air-extension.d.ts.map +1 -1
- package/dist/air-extension.js +7 -0
- package/dist/fork-session.d.ts.map +1 -1
- package/dist/fork-session.js +12 -6
- package/dist/session-cursors.d.ts +88 -4
- package/dist/session-cursors.d.ts.map +1 -1
- package/dist/session-cursors.js +128 -3
- package/dist/session-rewind.d.ts +160 -0
- package/dist/session-rewind.d.ts.map +1 -0
- package/dist/session-rewind.js +454 -0
- package/dist/v1/acp-agent.d.ts +39 -0
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +275 -13
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,7 +87,14 @@ local command, keeps its key until `session/close` or the end of the connection.
|
|
|
87
87
|
The adapter announces a session cursor (`cursor_update`) before each user message that follows
|
|
88
88
|
another entry of the conversation, live and in a replay. `session/fork` with its `cursorId` copies
|
|
89
89
|
the history before that message, and fails with `-32602` for any other `cursorId`. A v1 client gets
|
|
90
|
-
|
|
90
|
+
cursors only when it declares `clientCapabilities.session.cursors`. A v1 replay (`session/load`)
|
|
91
|
+
anchors each cursor `before` its replayed user message. A live v1 prompt is not reported to the
|
|
92
|
+
client that sent it, so its cursor is anchored `after` the last agent message, thought, tool call or
|
|
93
|
+
compaction before it, with the same `cursorId` that a later replay issues. A session that was
|
|
94
|
+
resumed without a replay has no such entity, so its live prompts get no cursor until it replays.
|
|
95
|
+
When a v1 turn reports no entity (it was cancelled or failed before any output, or it was a slash
|
|
96
|
+
command), the next prompt's cursor has the same `after <entity>` anchor as the previous prompt's
|
|
97
|
+
cursor, with a different `cursorId`: the client uses the latest.
|
|
91
98
|
|
|
92
99
|
v2 is served by the v2 agent in `src/v2/`, which runs straight on Claude
|
|
93
100
|
Code instead of translating to v1. A v2 client that declares JetBrains AIR
|
package/dist/air-extension.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ export declare const AIR_SESSION_LIST_SUBSCRIBE_CAPABILITY = "sessionListSubscri
|
|
|
48
48
|
* {@link AIR_SESSION_INDEX_CAPABILITY} is; the client does not declare it.
|
|
49
49
|
*/
|
|
50
50
|
export declare const AIR_SESSION_WORKTREES_CAPABILITY = "sessionWorktrees";
|
|
51
|
+
/**
|
|
52
|
+
* `_session/rewind`: removes a user message and everything after it from the
|
|
53
|
+
* context of the same session (see `docs/air-extensions.md#session-rewind`).
|
|
54
|
+
* The client declares it; the agent advertises it only to such a client, and
|
|
55
|
+
* then announces its session cursors with the `rewind` capability.
|
|
56
|
+
*/
|
|
57
|
+
export declare const AIR_SESSION_REWIND_CAPABILITY = "sessionRewind";
|
|
51
58
|
/**
|
|
52
59
|
* The client wants to know when the history replay of a loaded session is
|
|
53
60
|
* whole. After the last replayed update, the agent sends one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"air-extension.d.ts","sourceRoot":"","sources":["../src/air-extension.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uCAAuC,2BAA2B,CAAC;AAChF,eAAO,MAAM,0BAA0B,eAAe,CAAC;AACvD;;;GAGG;AACH,eAAO,MAAM,mCAAmC,wBAAwB,CAAC;AACzE,eAAO,MAAM,8BAA8B,mBAAmB,CAAC;AAC/D,eAAO,MAAM,uCAAuC,qBAAqB,CAAC;AAC1E,eAAO,MAAM,kCAAkC,uBAAuB,CAAC;AACvE,eAAO,MAAM,yBAAyB,cAAc,CAAC;AACrD,4EAA4E;AAC5E,eAAO,MAAM,kCAAkC,sBAAsB,CAAC;AACtE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,aAAa,CAAC;AACnD;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,iBAAiB,CAAC;AAC3D;uEACuE;AACvE,eAA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ClB,OAAO,EAAE,OAAO,GACf,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAczB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,OAAO,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACpC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAErC;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAKnF;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAY9F;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIvE"}
|
package/dist/air-extension.js
CHANGED
|
@@ -48,6 +48,13 @@ export const AIR_SESSION_LIST_SUBSCRIBE_CAPABILITY = "sessionListSubscribe";
|
|
|
48
48
|
* {@link AIR_SESSION_INDEX_CAPABILITY} is; the client does not declare it.
|
|
49
49
|
*/
|
|
50
50
|
export const AIR_SESSION_WORKTREES_CAPABILITY = "sessionWorktrees";
|
|
51
|
+
/**
|
|
52
|
+
* `_session/rewind`: removes a user message and everything after it from the
|
|
53
|
+
* context of the same session (see `docs/air-extensions.md#session-rewind`).
|
|
54
|
+
* The client declares it; the agent advertises it only to such a client, and
|
|
55
|
+
* then announces its session cursors with the `rewind` capability.
|
|
56
|
+
*/
|
|
57
|
+
export const AIR_SESSION_REWIND_CAPABILITY = "sessionRewind";
|
|
51
58
|
/**
|
|
52
59
|
* The client wants to know when the history replay of a loaded session is
|
|
53
60
|
* whole. After the last replayed update, the agent sends one
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fork-session.d.ts","sourceRoot":"","sources":["../src/fork-session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EAEpB,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"fork-session.d.ts","sourceRoot":"","sources":["../src/fork-session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EAEpB,MAAM,mCAAmC,CAAC;AAgC3C,KAAK,uBAAuB,GAAG;IAC7B,mBAAmB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;KAAE,CAAC;IAC/C,oBAAoB,EAAE,CAAC,OAAO,EAAE;QAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,KAAK,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AA6IF;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,kBAAkB,EAC1B,YAAY,EAAE,uBAAuB,GACpC,OAAO,CAAC,mBAAmB,CAAC,CAS9B"}
|
package/dist/fork-session.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { RequestError, } from "@agentclientprotocol/sdk/unstable";
|
|
2
2
|
import { forkSession as forkClaudeSession, getSessionMessages, } from "@anthropic-ai/claude-agent-sdk";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { loadFullSessionHistory
|
|
4
|
+
import { loadFullSessionHistory } from "./resumed-session.js";
|
|
5
5
|
import { forkPointOf } from "./session-cursors.js";
|
|
6
|
+
import { cutAtRewindPoint, loadRewindableHistory, pendingRewindEnd, withoutRewoundBranch, } from "./session-rewind.js";
|
|
6
7
|
import { assistantMessageText } from "./session-failure-extension.js";
|
|
7
8
|
import { SessionTiming } from "./session-timing.js";
|
|
8
9
|
function forkPoint(meta) {
|
|
@@ -129,8 +130,9 @@ export async function forkSession(params, dependencies) {
|
|
|
129
130
|
async function forkTranscript(params, dependencies) {
|
|
130
131
|
const timing = new SessionTiming(dependencies.logger, "fork", params.sessionId);
|
|
131
132
|
if (params.cursorId != null) {
|
|
132
|
-
// The history as a replay reads it, which announces the cursors
|
|
133
|
-
|
|
133
|
+
// The history as a replay reads it, which announces the cursors: cut at a
|
|
134
|
+
// pending rewind, so a cursor of a dropped turn is no cursor.
|
|
135
|
+
const { visible: history } = await loadRewindableHistory(params.sessionId);
|
|
134
136
|
const upToMessageId = forkPointOf(params.cursorId, history);
|
|
135
137
|
timing.phase("cursor", ` resolution=${upToMessageId ? "found" : "missing"}`);
|
|
136
138
|
if (upToMessageId === undefined) {
|
|
@@ -144,7 +146,9 @@ async function forkTranscript(params, dependencies) {
|
|
|
144
146
|
// SDK `dir` scopes source lookup, not the fork's working directory. Search
|
|
145
147
|
// all projects: params.cwd can name a different workspace for the new session.
|
|
146
148
|
if (!point) {
|
|
147
|
-
|
|
149
|
+
// A pending rewind ends the conversation at its point, not at the newest leaf.
|
|
150
|
+
const rewoundEnd = await pendingRewindEnd(params.sessionId);
|
|
151
|
+
const forked = await forkClaudeSession(params.sessionId, ...(rewoundEnd ? [{ upToMessageId: rewoundEnd }] : []));
|
|
148
152
|
timing.phase("sdk-fork", " resolution=latest");
|
|
149
153
|
return { sessionId: forked.sessionId };
|
|
150
154
|
}
|
|
@@ -152,7 +156,9 @@ async function forkTranscript(params, dependencies) {
|
|
|
152
156
|
const liveUuid = candidateIds
|
|
153
157
|
.map((candidateId) => dependencies.liveMessageIdToUuid?.get(candidateId))
|
|
154
158
|
.find(Boolean);
|
|
155
|
-
const history = liveUuid
|
|
159
|
+
const history = liveUuid
|
|
160
|
+
? undefined
|
|
161
|
+
: await cutAtRewindPoint(params.sessionId, await getSessionMessages(params.sessionId));
|
|
156
162
|
timing.phase("active-history", ` resolution=${liveUuid ? "live" : "pending"}`);
|
|
157
163
|
const messageUuid = liveUuid ??
|
|
158
164
|
candidateIds
|
|
@@ -164,7 +170,7 @@ async function forkTranscript(params, dependencies) {
|
|
|
164
170
|
// getSessionMessages returns only the active parentUuid chain. The full history keeps inactive branches that AIR can still reference.
|
|
165
171
|
const fullHistoryUuid = messageUuid
|
|
166
172
|
? undefined
|
|
167
|
-
: resolveFromFullHistory(await loadFullSessionHistory(params.sessionId), candidateIds, point, dependencies.messageIdForGrouping);
|
|
173
|
+
: resolveFromFullHistory(await withoutRewoundBranch(params.sessionId, await loadFullSessionHistory(params.sessionId)), candidateIds, point, dependencies.messageIdForGrouping);
|
|
168
174
|
timing.phase("full-history", ` resolution=${liveUuid ? "live" : messageUuid ? "active" : fullHistoryUuid ? "full" : "missing"}`);
|
|
169
175
|
if (!messageUuid && !fullHistoryUuid) {
|
|
170
176
|
throw RequestError.invalidParams({ messageId: point.messageId }, `Fork point message ${point.messageId} was not found in session ${params.sessionId}`);
|
|
@@ -15,19 +15,103 @@
|
|
|
15
15
|
* stored history.
|
|
16
16
|
*/
|
|
17
17
|
import type { SessionMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
18
|
+
/** The entity that a cursor is anchored to. */
|
|
19
|
+
export type CursorEntity = {
|
|
20
|
+
type: "user_message" | "agent_message" | "agent_thought";
|
|
21
|
+
messageId: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "tool_call";
|
|
24
|
+
toolCallId: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: "compaction";
|
|
27
|
+
compactionId: string;
|
|
28
|
+
};
|
|
29
|
+
/** The side of its {@link CursorEntity} that a cursor lies on. */
|
|
30
|
+
export type CursorAnchor = CursorEntity & {
|
|
31
|
+
position: "before" | "after";
|
|
32
|
+
};
|
|
18
33
|
/** The `cursor_update` of the cursor before the user message `messageId`. */
|
|
19
34
|
export declare function forkCursorUpdate(messageId: string): {
|
|
35
|
+
anchor: {
|
|
36
|
+
type: "user_message";
|
|
37
|
+
messageId: string;
|
|
38
|
+
position: "before";
|
|
39
|
+
};
|
|
20
40
|
sessionUpdate: "cursor_update";
|
|
21
41
|
cursorId: string;
|
|
22
42
|
capabilities: {
|
|
23
43
|
fork: {};
|
|
24
44
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The cursor before the user message `messageId` for a client that holds no
|
|
48
|
+
* such user message: `anchor` places it (see {@link LastReportedEntity}), and the
|
|
49
|
+
* `cursorId` stays that of the message.
|
|
50
|
+
*/
|
|
51
|
+
export declare function anchoredForkCursorUpdate(messageId: string, anchor: CursorAnchor): {
|
|
52
|
+
anchor: CursorAnchor;
|
|
53
|
+
sessionUpdate: "cursor_update";
|
|
54
|
+
cursorId: string;
|
|
55
|
+
capabilities: {
|
|
56
|
+
fork: {};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* `update` with the `rewind` capability added: the cursor is also a position
|
|
61
|
+
* that `_session/rewind` accepts. For a client that declared `sessionRewind`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function withRewindCapability<U extends {
|
|
64
|
+
capabilities: {
|
|
65
|
+
fork: object;
|
|
66
|
+
};
|
|
67
|
+
}>(update: U): U & {
|
|
68
|
+
capabilities: {
|
|
69
|
+
fork: object;
|
|
70
|
+
rewind: object;
|
|
29
71
|
};
|
|
30
72
|
};
|
|
73
|
+
/** The uuid of the user message that `cursorId` lies before, or undefined for an id that is no cursor. */
|
|
74
|
+
export declare function cursorMessageId(cursorId: string): string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* The last entity per session that a client can anchor a cursor to: an agent
|
|
77
|
+
* message or thought with a `messageId`, a tool call, a compaction or a user
|
|
78
|
+
* message with a `messageId`. v1 does not report a prompt that the client
|
|
79
|
+
* sent, so its cursor lies `after` the entity before it. Each session update
|
|
80
|
+
* that goes to the client passes through {@link sending}, a replay too.
|
|
81
|
+
* Output of a subagent (a `parentToolUseId` in its `_meta`) is not on the
|
|
82
|
+
* session's own timeline and is left out.
|
|
83
|
+
*
|
|
84
|
+
* It also records, for each cursor that the agent announces, the entity that
|
|
85
|
+
* the client held right before that position ({@link recordCursor}). A rewind
|
|
86
|
+
* to the cursor leaves the client with exactly that entity.
|
|
87
|
+
*/
|
|
88
|
+
export declare class LastReportedEntity {
|
|
89
|
+
private readonly bySession;
|
|
90
|
+
/** Per session, in announcement order: the entity before each announced cursor. */
|
|
91
|
+
private readonly beforeCursor;
|
|
92
|
+
sending(notification: {
|
|
93
|
+
sessionId: string;
|
|
94
|
+
update: {
|
|
95
|
+
sessionUpdate: string;
|
|
96
|
+
_meta?: unknown;
|
|
97
|
+
} & Record<string, unknown>;
|
|
98
|
+
}): void;
|
|
99
|
+
/** The position after the last entity of the session, if the client holds one. */
|
|
100
|
+
after(sessionId: string): CursorAnchor | undefined;
|
|
101
|
+
/** The last entity of the session that the client holds, if any. */
|
|
102
|
+
last(sessionId: string): CursorEntity | undefined;
|
|
103
|
+
/** The agent announces `cursorId`; `before` is the entity the client holds right before it. */
|
|
104
|
+
recordCursor(sessionId: string, cursorId: string, before: CursorEntity | undefined): void;
|
|
105
|
+
/**
|
|
106
|
+
* The session is rewound to `cursorId`: the client drops the entities from
|
|
107
|
+
* there on, so the entity recorded for the cursor is its last one (none for
|
|
108
|
+
* a cursor that has no record: the next prompt then gets no cursor). The
|
|
109
|
+
* records of the cursors at and after the cut go too.
|
|
110
|
+
*/
|
|
111
|
+
rewind(sessionId: string, cursorId: string): void;
|
|
112
|
+
/** The client no longer holds the session's entities: it closed, or a replay rebuilds them. */
|
|
113
|
+
forget(sessionId: string): void;
|
|
114
|
+
}
|
|
31
115
|
/**
|
|
32
116
|
* Whether a prompt with this content gets a cursor when it is inserted live.
|
|
33
117
|
* A slash command does not: Claude Code stores a command as command metadata
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-cursors.d.ts","sourceRoot":"","sources":["../src/session-cursors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAOrE,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"session-cursors.d.ts","sourceRoot":"","sources":["../src/session-cursors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAOrE,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,eAAe,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC/E;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD,kEAAkE;AAClE,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG;IAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAA;CAAE,CAAC;AAE3E,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;EAKjD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY;;;;;;;EAE/E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS;IAAE,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EAC/E,MAAM,EAAE,CAAC,GACR,CAAC,GAAG;IAAE,YAAY,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AAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAIzF;AAmBD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,SAAS,cAAc,EAAE,GAClC,MAAM,GAAG,SAAS,CAKpB"}
|
package/dist/session-cursors.js
CHANGED
|
@@ -4,13 +4,134 @@ import { isReplayHiddenMetaMessage, stripLocalCommandMetadata } from "./message-
|
|
|
4
4
|
const BEFORE_MESSAGE = "before:";
|
|
5
5
|
/** The `cursor_update` of the cursor before the user message `messageId`. */
|
|
6
6
|
export function forkCursorUpdate(messageId) {
|
|
7
|
+
return {
|
|
8
|
+
...forkCursorBase(messageId),
|
|
9
|
+
anchor: { type: "user_message", messageId, position: "before" },
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The cursor before the user message `messageId` for a client that holds no
|
|
14
|
+
* such user message: `anchor` places it (see {@link LastReportedEntity}), and the
|
|
15
|
+
* `cursorId` stays that of the message.
|
|
16
|
+
*/
|
|
17
|
+
export function anchoredForkCursorUpdate(messageId, anchor) {
|
|
18
|
+
return { ...forkCursorBase(messageId), anchor };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `update` with the `rewind` capability added: the cursor is also a position
|
|
22
|
+
* that `_session/rewind` accepts. For a client that declared `sessionRewind`.
|
|
23
|
+
*/
|
|
24
|
+
export function withRewindCapability(update) {
|
|
25
|
+
return { ...update, capabilities: { ...update.capabilities, rewind: {} } };
|
|
26
|
+
}
|
|
27
|
+
/** The uuid of the user message that `cursorId` lies before, or undefined for an id that is no cursor. */
|
|
28
|
+
export function cursorMessageId(cursorId) {
|
|
29
|
+
return cursorId.startsWith(BEFORE_MESSAGE) ? cursorId.slice(BEFORE_MESSAGE.length) : undefined;
|
|
30
|
+
}
|
|
31
|
+
function forkCursorBase(messageId) {
|
|
7
32
|
return {
|
|
8
33
|
sessionUpdate: "cursor_update",
|
|
9
34
|
cursorId: `${BEFORE_MESSAGE}${messageId}`,
|
|
10
35
|
capabilities: { fork: {} },
|
|
11
|
-
anchor: { type: "user_message", messageId, position: "before" },
|
|
12
36
|
};
|
|
13
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The last entity per session that a client can anchor a cursor to: an agent
|
|
40
|
+
* message or thought with a `messageId`, a tool call, a compaction or a user
|
|
41
|
+
* message with a `messageId`. v1 does not report a prompt that the client
|
|
42
|
+
* sent, so its cursor lies `after` the entity before it. Each session update
|
|
43
|
+
* that goes to the client passes through {@link sending}, a replay too.
|
|
44
|
+
* Output of a subagent (a `parentToolUseId` in its `_meta`) is not on the
|
|
45
|
+
* session's own timeline and is left out.
|
|
46
|
+
*
|
|
47
|
+
* It also records, for each cursor that the agent announces, the entity that
|
|
48
|
+
* the client held right before that position ({@link recordCursor}). A rewind
|
|
49
|
+
* to the cursor leaves the client with exactly that entity.
|
|
50
|
+
*/
|
|
51
|
+
export class LastReportedEntity {
|
|
52
|
+
bySession = new Map();
|
|
53
|
+
/** Per session, in announcement order: the entity before each announced cursor. */
|
|
54
|
+
beforeCursor = new Map();
|
|
55
|
+
sending(notification) {
|
|
56
|
+
const { sessionId, update } = notification;
|
|
57
|
+
const meta = update._meta;
|
|
58
|
+
if (meta?.claudeCode?.parentToolUseId)
|
|
59
|
+
return;
|
|
60
|
+
const messageId = typeof update.messageId === "string" ? update.messageId : undefined;
|
|
61
|
+
switch (update.sessionUpdate) {
|
|
62
|
+
case "user_message_chunk":
|
|
63
|
+
if (messageId)
|
|
64
|
+
this.bySession.set(sessionId, { type: "user_message", messageId });
|
|
65
|
+
break;
|
|
66
|
+
case "agent_message_chunk":
|
|
67
|
+
if (messageId)
|
|
68
|
+
this.bySession.set(sessionId, { type: "agent_message", messageId });
|
|
69
|
+
break;
|
|
70
|
+
case "agent_thought_chunk":
|
|
71
|
+
if (messageId)
|
|
72
|
+
this.bySession.set(sessionId, { type: "agent_thought", messageId });
|
|
73
|
+
break;
|
|
74
|
+
case "tool_call":
|
|
75
|
+
if (typeof update.toolCallId === "string") {
|
|
76
|
+
this.bySession.set(sessionId, { type: "tool_call", toolCallId: update.toolCallId });
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "compaction_update":
|
|
80
|
+
if (typeof update.compactionId === "string") {
|
|
81
|
+
this.bySession.set(sessionId, { type: "compaction", compactionId: update.compactionId });
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** The position after the last entity of the session, if the client holds one. */
|
|
88
|
+
after(sessionId) {
|
|
89
|
+
const entity = this.bySession.get(sessionId);
|
|
90
|
+
return entity && { ...entity, position: "after" };
|
|
91
|
+
}
|
|
92
|
+
/** The last entity of the session that the client holds, if any. */
|
|
93
|
+
last(sessionId) {
|
|
94
|
+
return this.bySession.get(sessionId);
|
|
95
|
+
}
|
|
96
|
+
/** The agent announces `cursorId`; `before` is the entity the client holds right before it. */
|
|
97
|
+
recordCursor(sessionId, cursorId, before) {
|
|
98
|
+
let records = this.beforeCursor.get(sessionId);
|
|
99
|
+
if (!records)
|
|
100
|
+
this.beforeCursor.set(sessionId, (records = new Map()));
|
|
101
|
+
records.set(cursorId, before);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The session is rewound to `cursorId`: the client drops the entities from
|
|
105
|
+
* there on, so the entity recorded for the cursor is its last one (none for
|
|
106
|
+
* a cursor that has no record: the next prompt then gets no cursor). The
|
|
107
|
+
* records of the cursors at and after the cut go too.
|
|
108
|
+
*/
|
|
109
|
+
rewind(sessionId, cursorId) {
|
|
110
|
+
const records = this.beforeCursor.get(sessionId);
|
|
111
|
+
const before = records?.get(cursorId);
|
|
112
|
+
if (before)
|
|
113
|
+
this.bySession.set(sessionId, before);
|
|
114
|
+
else
|
|
115
|
+
this.bySession.delete(sessionId);
|
|
116
|
+
if (!records?.has(cursorId))
|
|
117
|
+
return;
|
|
118
|
+
let cut = false;
|
|
119
|
+
for (const id of [...records.keys()]) {
|
|
120
|
+
cut ||= id === cursorId;
|
|
121
|
+
if (cut)
|
|
122
|
+
records.delete(id);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** The client no longer holds the session's entities: it closed, or a replay rebuilds them. */
|
|
126
|
+
forget(sessionId) {
|
|
127
|
+
for (const map of [this.bySession, this.beforeCursor]) {
|
|
128
|
+
for (const id of map.keys()) {
|
|
129
|
+
if (id === sessionId || id.startsWith(`${sessionId}:`))
|
|
130
|
+
map.delete(id);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
14
135
|
/**
|
|
15
136
|
* Whether a prompt with this content gets a cursor when it is inserted live.
|
|
16
137
|
* A slash command does not: Claude Code stores a command as command metadata
|
|
@@ -31,9 +152,13 @@ export function promptGetsCursor(prompt) {
|
|
|
31
152
|
*/
|
|
32
153
|
export function hasForkCursor(messages, index) {
|
|
33
154
|
const message = messages[index];
|
|
34
|
-
if (!message ||
|
|
155
|
+
if (!message || !messages[index - 1]?.uuid)
|
|
35
156
|
return false;
|
|
36
|
-
|
|
157
|
+
return isShownUserMessage(message);
|
|
158
|
+
}
|
|
159
|
+
/** Whether a replay shows `message` as a user message of the session's own conversation. */
|
|
160
|
+
function isShownUserMessage(message) {
|
|
161
|
+
if (message.type !== "user" || !message.uuid)
|
|
37
162
|
return false;
|
|
38
163
|
if (message.parent_tool_use_id !== null)
|
|
39
164
|
return false;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type SessionMessage, type SessionStoreEntry } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
export declare const SESSION_REWIND_METHOD = "_session/rewind";
|
|
3
|
+
export type SessionRewindRequest = {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
/** A cursor that the session announced, before the user message to drop. */
|
|
6
|
+
cursorId: string;
|
|
7
|
+
};
|
|
8
|
+
/** Why the conversation was left as it was. */
|
|
9
|
+
export type SessionRewindRefusal =
|
|
10
|
+
/** Claude is working, or a prompt is queued. */
|
|
11
|
+
"busy"
|
|
12
|
+
/** A background task or subagent is running. */
|
|
13
|
+
| "backgroundWork"
|
|
14
|
+
/** The message is before the newest compaction of the conversation. */
|
|
15
|
+
| "beforeCompaction"
|
|
16
|
+
/** The session's context was cleared into another Claude session. */
|
|
17
|
+
| "clearedContext"
|
|
18
|
+
/** Claude Code refused the cut. The session goes on as it was. */
|
|
19
|
+
| "providerRefused"
|
|
20
|
+
/** The rewind point could not be written. Nothing changed. */
|
|
21
|
+
| "persistFailed";
|
|
22
|
+
export type SessionRewindResponse = {
|
|
23
|
+
rewound: boolean;
|
|
24
|
+
reason?: SessionRewindRefusal;
|
|
25
|
+
};
|
|
26
|
+
export declare function parseSessionRewindRequest(params: unknown): SessionRewindRequest;
|
|
27
|
+
type Logger = {
|
|
28
|
+
log: (...args: unknown[]) => void;
|
|
29
|
+
error: (...args: unknown[]) => void;
|
|
30
|
+
};
|
|
31
|
+
/** The stored history of a session, as a replay shows it. */
|
|
32
|
+
export type RewindableHistory = {
|
|
33
|
+
/** Every message of the conversation the session continues, from its first
|
|
34
|
+
* prompt on, across compactions. A rewind cursor is one of this list. */
|
|
35
|
+
visible: readonly SessionMessage[];
|
|
36
|
+
/** The part of `visible` that the newest compaction left: where Claude Code
|
|
37
|
+
* can resume. */
|
|
38
|
+
current: readonly SessionMessage[];
|
|
39
|
+
};
|
|
40
|
+
/** What the rewind needs from the agent that holds the session. */
|
|
41
|
+
export type SessionRewindHost = {
|
|
42
|
+
logger: Logger;
|
|
43
|
+
/** The context of the session was cleared into another Claude session. */
|
|
44
|
+
clearedContext: boolean;
|
|
45
|
+
/** Whether Claude works, or a prompt is queued: `startTurn`'s check. */
|
|
46
|
+
claudeIsWorking(): boolean;
|
|
47
|
+
/** Whether a background task or subagent runs. Closing the query ends it. */
|
|
48
|
+
hasBackgroundWork(): boolean;
|
|
49
|
+
loadHistory(): Promise<RewindableHistory>;
|
|
50
|
+
/**
|
|
51
|
+
* Closes the query and recreates the same session by resuming its
|
|
52
|
+
* conversation, stopped at `resumeAt.resumeSessionAt` when it is set. Restores
|
|
53
|
+
* the user's model, mode, agent, effort and Fast mode, and starts the reader.
|
|
54
|
+
*/
|
|
55
|
+
replaceQuery(resumeAt?: {
|
|
56
|
+
resumeSessionAt: string;
|
|
57
|
+
resumeDropsTurn?: string;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* The session is rewound to `cursorId`. The next prompt's cursor anchors to
|
|
61
|
+
* the entity that the client held before that cursor.
|
|
62
|
+
*/
|
|
63
|
+
rewound(cursorId: string): void;
|
|
64
|
+
/** Deals with a session whose query is closed and could not be resumed,
|
|
65
|
+
* and returns the error the rewind fails with. */
|
|
66
|
+
abandon(error: unknown): Promise<unknown>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Drops the user message of `request.cursorId` and everything after it.
|
|
70
|
+
*
|
|
71
|
+
* `{ rewound: true }` means that the cut is live and recorded in `rewind.json`;
|
|
72
|
+
* `{ rewound: false, reason }` means that the conversation and the rewind point
|
|
73
|
+
* are unchanged. The transcript can still gain the `last-prompt` line that any
|
|
74
|
+
* resume writes: `prepareRewoundResume` runs before the refusals that follow
|
|
75
|
+
* it, and with a stale point that is not pending it also deletes `rewind.json`,
|
|
76
|
+
* as any resume does. A cursor that the session's history does not hold is a
|
|
77
|
+
* bad request (-32602): the rewind never acts at another position.
|
|
78
|
+
*
|
|
79
|
+
* The point is written before the query is replaced, and restored to what it
|
|
80
|
+
* was when the cut does not happen. A crash between the write and the cut
|
|
81
|
+
* leaves a point that the next resume applies. When the restore fails too, the
|
|
82
|
+
* request fails with an internal error instead of `rewound: false`, since the
|
|
83
|
+
* next resume applies a cut that was reported as not made.
|
|
84
|
+
*/
|
|
85
|
+
export declare function rewindSession(request: SessionRewindRequest, host: SessionRewindHost): Promise<SessionRewindResponse>;
|
|
86
|
+
/** Whether Claude Code refused the cut (see `resumeDropsTurn` of the SDK options). */
|
|
87
|
+
export declare function isRewindRefusal(error: unknown): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* The history of `sessionId` that a cursor of it is resolved against: the
|
|
90
|
+
* conversation the session continues, cut at its rewind point.
|
|
91
|
+
*/
|
|
92
|
+
export declare function loadRewindableHistory(sessionId: string, logger?: Logger): Promise<RewindableHistory>;
|
|
93
|
+
/**
|
|
94
|
+
* `stored`, the `getSessionMessages` chain of `sessionId`, without the branch
|
|
95
|
+
* that a pending rewind dropped. Cut before reading across compactions: the
|
|
96
|
+
* newest leaf is the last retained message.
|
|
97
|
+
*/
|
|
98
|
+
export declare function cutAtRewindPoint<M extends {
|
|
99
|
+
uuid?: string | null;
|
|
100
|
+
}>(sessionId: string, stored: readonly M[], logger?: Logger): Promise<M[]>;
|
|
101
|
+
/**
|
|
102
|
+
* The entry that a fork of the whole of `sessionId` ends at while a rewind is
|
|
103
|
+
* pending, or undefined when there is none: the newest leaf then still lies in
|
|
104
|
+
* the dropped branch.
|
|
105
|
+
*/
|
|
106
|
+
export declare function pendingRewindEnd(sessionId: string, logger?: Logger): Promise<string | undefined>;
|
|
107
|
+
/**
|
|
108
|
+
* `entries`, the records of the whole transcript of `sessionId` with its
|
|
109
|
+
* inactive branches, without the dropped prompt of a rewind and the records
|
|
110
|
+
* that descend from it. A record comes after its parent in the transcript.
|
|
111
|
+
*/
|
|
112
|
+
export declare function withoutRewoundBranch(sessionId: string, entries: SessionStoreEntry[], logger?: Logger): Promise<SessionStoreEntry[]>;
|
|
113
|
+
/**
|
|
114
|
+
* The messages of the conversation that a session continues, given its stored
|
|
115
|
+
* `history` and its `rewindPoint`. A rewind leaves the dropped branch in the
|
|
116
|
+
* transcript, and until the next prompt writes a branch from the point,
|
|
117
|
+
* `history` still ends in the dropped branch: it is cut before the dropped
|
|
118
|
+
* prompt. Once a branch descends from the point, `history` no longer holds the
|
|
119
|
+
* dropped prompt and is returned as it is.
|
|
120
|
+
*/
|
|
121
|
+
export declare function activeSessionMessages<M extends {
|
|
122
|
+
uuid?: string | null;
|
|
123
|
+
}>(history: readonly M[], rewindPoint: RewindPoint | undefined): M[];
|
|
124
|
+
/** A rewind: the entry the session resumes at, and the prompt it dropped. */
|
|
125
|
+
export type RewindPoint = {
|
|
126
|
+
/** The last retained entry, for `resumeSessionAt`. */
|
|
127
|
+
resumeSessionAt: string;
|
|
128
|
+
/** The first entry of the dropped branch: the user prompt the rewind removed. */
|
|
129
|
+
droppedPromptUuid: string;
|
|
130
|
+
};
|
|
131
|
+
/** Records the last rewind of a session. */
|
|
132
|
+
export declare function writeRewindPoint(sessionId: string, point: RewindPoint): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* The last rewind of a session, or undefined for one that has none (no
|
|
135
|
+
* `rewind.json`, ENOENT). A record that cannot be read (EACCES, EISDIR) or
|
|
136
|
+
* parsed fails with an internal error: reading it as "no rewind" would show or
|
|
137
|
+
* resume the dropped turns. The file stays, so the client can retry.
|
|
138
|
+
*/
|
|
139
|
+
export declare function readRewindPoint(sessionId: string, logger?: Logger): Promise<RewindPoint | undefined>;
|
|
140
|
+
/** Removes the record of the last rewind. */
|
|
141
|
+
export declare function clearRewindPoint(sessionId: string): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Prepares the transcript of `sessionId` for a resume, and returns the entry
|
|
144
|
+
* that a pending rewind point makes the resume stop at, if any.
|
|
145
|
+
*
|
|
146
|
+
* Claude Code resumes the branch of the leaf that the last `last-prompt` line
|
|
147
|
+
* of the transcript names, and looks up `resumeSessionAt` on that branch only.
|
|
148
|
+
* A process that resumed at a rewind point keeps writing that line with the
|
|
149
|
+
* leaf it loaded until it exits, and a query restart starts the next process
|
|
150
|
+
* before the closed one has exited, so the line can name the branch that the
|
|
151
|
+
* rewind dropped. A second rewind then fails with "No message found with
|
|
152
|
+
* message.uuid of ...", and a plain resume brings the dropped turns back. So
|
|
153
|
+
* the line is written for the leaf of the session's conversation: explicit at
|
|
154
|
+
* a pending rewind point, whose dropped branch descends from it, and plain at
|
|
155
|
+
* the newest entry otherwise. Once the point is no longer pending, the plain
|
|
156
|
+
* line is all the next process needs, and `rewind.json` is removed.
|
|
157
|
+
*/
|
|
158
|
+
export declare function prepareRewoundResume(sessionId: string, logger?: Logger): Promise<string | undefined>;
|
|
159
|
+
export {};
|
|
160
|
+
//# sourceMappingURL=session-rewind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-rewind.d.ts","sourceRoot":"","sources":["../src/session-rewind.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,gCAAgC,CAAC;AAaxC,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,oBAAoB;AAC9B,gDAAgD;AAC9C,MAAM;AACR,gDAAgD;GAC9C,gBAAgB;AAClB,uEAAuE;GACrE,kBAAkB;AACpB,qEAAqE;GACnE,gBAAgB;AAClB,kEAAkE;GAChE,iBAAiB;AACnB,8DAA8D;GAC5D,eAAe,CAAC;AAEpB,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,OAAO,GAAG,oBAAoB,CAY/E;AAED,KAAK,MAAM,GAAG;IAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CAAE,CAAC;AAEzF,6DAA6D;AAC7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B;8EAC0E;IAC1E,OAAO,EAAE,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