@agentclientprotocol/claude-agent-acp 0.114.1-preview.3 → 0.115.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.
@@ -45,6 +45,22 @@ export declare function readHistoryAcrossCompactions(sessionId: string, messages
45
45
  * and the history before a compaction that `getSessionMessages` leaves out.
46
46
  * Without `dir`, all project directories are searched. */
47
47
  export declare function loadFullSessionHistory(sessionId: string, dir?: string): Promise<SessionStoreEntry[]>;
48
+ /** The position of each record of a transcript, by its uuid. */
49
+ export declare function recordPositions(entries: readonly SessionStoreEntry[]): Map<unknown, number>;
50
+ /**
51
+ * The uuid of the record that `entry` follows, given the `positions` of the
52
+ * records of its transcript: its `parentUuid`, or for a compaction boundary,
53
+ * the message before the compaction.
54
+ *
55
+ * Claude Code can write a boundary whose `logicalParentUuid` is not in the
56
+ * transcript: it lists the message in `compactMetadata.preservedMessages`, but
57
+ * does not write it. Such a boundary follows
58
+ * `compactMetadata.preservedSegment.tailUuid`, the `logicalParentUuid` of the
59
+ * other boundaries, when that message comes before the boundary in the file.
60
+ * In a fork, the boundary is the first record and the preserved messages come
61
+ * after it: the boundary then keeps its `logicalParentUuid`.
62
+ */
63
+ export declare function recordParentUuid(entry: SessionStoreEntry, positions: ReadonlyMap<unknown, number>): string | undefined;
48
64
  /** What a resume restores from the end of the local transcript. */
49
65
  export type ResumedTail = {
50
66
  model?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"resumed-session.d.ts","sourceRoot":"","sources":["../src/resumed-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAEnB,KAAK,iBAAiB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAyB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAW1E,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAClC,KAAK,EAAE,CAAC,GAAG,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oryAcrossCompactions(sessionId, messages, logger,
82
82
  if (!isCompactSummaryMessage(messages[0]))
83
83
  return messages;
84
84
  try {
85
- const entries = (snapshot ?? (await loadFullSessionHistory(sessionId, dir))).map(linkCompactBoundary);
85
+ const records = snapshot ?? (await loadFullSessionHistory(sessionId, dir));
86
+ const positions = recordPositions(records);
87
+ const entries = records.map((entry) => linkCompactBoundary(entry, positions, sessionId, logger));
86
88
  const read = (records) => getSessionMessages(sessionId, {
87
89
  dir,
88
90
  sessionStore: { append: async () => { }, load: async () => records },
@@ -123,19 +125,65 @@ export async function loadFullSessionHistory(sessionId, dir) {
123
125
  await importSessionToStore(sessionId, store, { dir, includeSubagents: false });
124
126
  return entries;
125
127
  }
126
- /** The record unchanged, or a compaction boundary linked to the message before it. */
127
- function linkCompactBoundary(entry) {
128
+ /** The position of each record of a transcript, by its uuid. */
129
+ export function recordPositions(entries) {
130
+ return new Map(entries.flatMap((entry, index) => typeof entry.uuid === "string" ? [[entry.uuid, index]] : []));
131
+ }
132
+ /**
133
+ * The uuid of the record that `entry` follows, given the `positions` of the
134
+ * records of its transcript: its `parentUuid`, or for a compaction boundary,
135
+ * the message before the compaction.
136
+ *
137
+ * Claude Code can write a boundary whose `logicalParentUuid` is not in the
138
+ * transcript: it lists the message in `compactMetadata.preservedMessages`, but
139
+ * does not write it. Such a boundary follows
140
+ * `compactMetadata.preservedSegment.tailUuid`, the `logicalParentUuid` of the
141
+ * other boundaries, when that message comes before the boundary in the file.
142
+ * In a fork, the boundary is the first record and the preserved messages come
143
+ * after it: the boundary then keeps its `logicalParentUuid`.
144
+ */
145
+ export function recordParentUuid(entry, positions) {
146
+ if (typeof entry.parentUuid === "string" && entry.parentUuid)
147
+ return entry.parentUuid;
148
+ const logical = entry.logicalParentUuid;
149
+ if (typeof logical !== "string")
150
+ return undefined;
151
+ if (positions.has(logical) || entry.type !== "system" || entry.subtype !== "compact_boundary") {
152
+ return logical;
153
+ }
154
+ const tail = preservedTail(entry);
155
+ const tailAt = tail === undefined ? undefined : positions.get(tail);
156
+ const at = positions.get(entry.uuid);
157
+ return tailAt !== undefined && at !== undefined && tailAt < at ? tail : logical;
158
+ }
159
+ function preservedTail(entry) {
160
+ const segment = entry.compactMetadata
161
+ ?.preservedSegment;
162
+ const tail = segment?.tailUuid;
163
+ return typeof tail === "string" ? tail : undefined;
164
+ }
165
+ /** The record unchanged, or a compaction boundary linked to the message
166
+ * before it (see {@link recordParentUuid}). */
167
+ function linkCompactBoundary(entry, positions, sessionId, logger) {
128
168
  if (entry.type !== "system" ||
129
169
  entry.subtype !== "compact_boundary" ||
130
170
  typeof entry.logicalParentUuid !== "string") {
131
171
  return entry;
132
172
  }
173
+ const logical = entry.logicalParentUuid;
174
+ const parentUuid = recordParentUuid({ ...entry, parentUuid: null }, positions) ?? logical;
175
+ if (parentUuid !== logical) {
176
+ logger?.log(`The compaction ${entry.uuid} of session ${sessionId} follows message ${logical}, which is not in the transcript: linking it to the last preserved message ${parentUuid}`);
177
+ }
178
+ else if (!positions.has(logical) && !positions.has(preservedTail(entry))) {
179
+ logger?.error(`The compaction ${entry.uuid} of session ${sessionId} follows message ${logical}, which is not in the transcript: leaving out the history before it`);
180
+ }
133
181
  const compactMetadata = typeof entry.compactMetadata === "object" && entry.compactMetadata !== null
134
182
  ? { ...entry.compactMetadata }
135
183
  : {};
136
184
  delete compactMetadata.preservedSegment;
137
185
  delete compactMetadata.preservedMessages;
138
- return { ...entry, parentUuid: entry.logicalParentUuid, compactMetadata };
186
+ return { ...entry, parentUuid, compactMetadata };
139
187
  }
140
188
  /**
141
189
  * Read the resume model and the permission mode of a session from the end
@@ -95,7 +95,9 @@ export declare class LastReportedEntity {
95
95
  sessionUpdate: string;
96
96
  _meta?: unknown;
97
97
  } & Record<string, unknown>;
98
- }, protocol?: 1 | 2): void;
98
+ }, protocol?: 1 | 2,
99
+ /** The session is a child's own stream, whose entities name their launch. */
100
+ child?: boolean): void;
99
101
  /** The position after the last entity of the session, if the client holds one. */
100
102
  after(sessionId: string): CursorAnchor | undefined;
101
103
  /** The last entity of the session that the client holds, if any. */
@@ -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,+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,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAExD;AAED,0GAA0G;AAC1G,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEpE;AAUD;;;;;;;;;;;;GAYG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,Q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AY,EAAE;QACZ,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,CAAA;SAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC9E,EACD,QAAQ,GAAE,CAAC,GAAG,CAAK;IACnB,6EAA6E;IAC7E,KAAK,UAAQ,GACZ,IAAI;IAqCP,kFAAkF;IAClF,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAKlD,oEAAoE;IACpE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIjD,+FAA+F;IAC/F,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI;IAMzF;;;;;OAKG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAajD,+FAA+F;IAC/F,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAOhC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,OAAO,CAGjG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,EAAE,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"}
@@ -52,10 +52,12 @@ export class LastReportedEntity {
52
52
  bySession = new Map();
53
53
  /** Per session, in announcement order: the entity before each announced cursor. */
54
54
  beforeCursor = new Map();
55
- sending(notification, protocol = 1) {
55
+ sending(notification, protocol = 1,
56
+ /** The session is a child's own stream, whose entities name their launch. */
57
+ child = false) {
56
58
  const { sessionId, update } = notification;
57
59
  const meta = update._meta;
58
- if (meta?.claudeCode?.parentToolUseId)
60
+ if (!child && meta?.claudeCode?.parentToolUseId)
59
61
  return;
60
62
  const messageId = typeof update.messageId === "string" ? update.messageId : undefined;
61
63
  switch (update.sessionUpdate) {
@@ -1,7 +1,17 @@
1
+ import { type SubagentHistory } from "./subagent-history.js";
2
+ import { SubagentStatus } from "./subagent-status.js";
1
3
  export declare const SESSION_READ_METHOD = "_session/read";
2
4
  export declare const SESSION_READ_CAPABILITY: {
3
5
  readonly supported: true;
4
6
  };
7
+ /** The capability of a connection that can read subagents lazily (see `docs/session-read.md`). */
8
+ export declare const SESSION_READ_SUBAGENTS_CAPABILITY: {
9
+ readonly supported: true;
10
+ readonly subagents: {};
11
+ readonly filters: {
12
+ readonly subagents: {};
13
+ };
14
+ };
5
15
  export type SessionReadFrame = {
6
16
  sessionId: string;
7
17
  update: {
@@ -10,42 +20,107 @@ export type SessionReadFrame = {
10
20
  };
11
21
  [key: string]: unknown;
12
22
  };
23
+ /**
24
+ * What a read renders besides the root: every subagent transcript (the
25
+ * default), only the status of each subagent (`filters.subagents: "status"`), or
26
+ * only the stream of the child `subagentSessionId`.
27
+ */
28
+ export type SessionReadScope = {
29
+ subagents?: "status";
30
+ subagentSessionId?: string;
31
+ };
13
32
  type ReadOptions = {
14
33
  protocol: 1 | 2;
15
34
  capabilities: unknown;
16
35
  cursors: boolean;
36
+ /** Whether the client has native subagent sessions, which the status and child reads need. */
37
+ subagents?: boolean;
17
38
  signal?: AbortSignal;
18
39
  isOpen(sessionId: string): boolean;
19
40
  assertRoot?(sessionId: string): void;
20
- replay(sessionId: string, cwd: string | undefined, observeStorage: boolean): Promise<{
41
+ replay(sessionId: string, cwd: string | undefined, observeStorage: boolean, scope: SessionReadScope): Promise<{
21
42
  frames: SessionReadFrame[];
22
43
  cwd: string;
23
44
  historyEnd?: number;
24
45
  title?: string;
25
46
  storage?: SessionReadStorage;
47
+ /** For a status read: the status, whose update goes out outside the cursor. */
48
+ status?: SubagentStatus;
49
+ /** For a child read: the session id of the child's stream in `frames`. */
50
+ stream?: string;
26
51
  }>;
27
52
  send(frame: SessionReadFrame): Promise<void> | void;
28
53
  };
29
54
  export type SessionReadStorage = {
30
55
  transcript: string;
31
- version: string;
56
+ /** The root transcript's version; undefined for a child read, which checks `files`. */
57
+ version?: string;
58
+ /** Subagent transcripts that the replay depends on, with their version, `null` for a missing one. */
59
+ files?: [path: string, version: string | null][];
60
+ /** The metadata of the session's subagents, when the replay depends on it (see {@link subagentRecords}). */
61
+ subagents?: string;
32
62
  /** Undefined when replay skipped the sidecar, null when it had no title. */
33
63
  sidecarTitle?: string | null;
64
+ /** The SKILL.md of each skill of the root's Skill calls (see {@link skillPaths}). */
65
+ skills?: {
66
+ cwd: string;
67
+ paths: [name: string, path: string | null][];
68
+ };
34
69
  };
70
+ /** The child that a child read selects (see {@link findChild}). */
71
+ export declare class SessionReadChild {
72
+ readonly agentId: string;
73
+ private readonly launchId;
74
+ readonly history: SubagentHistory;
75
+ private readonly rootSessionId;
76
+ /** The agents whose transcripts the replay reads; undefined for every agent. */
77
+ private readonly lineage;
78
+ /** The version of the child's transcript, read before the replay. */
79
+ private readonly files;
80
+ /** The messages of the child's transcript, once the replay read them. */
81
+ private messages;
82
+ constructor(agentId: string, launchId: string, history: SubagentHistory, rootSessionId: string,
83
+ /** The agents whose transcripts the replay reads; undefined for every agent. */
84
+ lineage: Set<string> | undefined,
85
+ /** The version of the child's transcript, read before the replay. */
86
+ files: [string, string | null][] | undefined);
87
+ /** Whether the replay reads the transcript of the agent `agentId`. Others keep their association only. */
88
+ expand(agentId: string): boolean;
89
+ /** Takes each child transcript that the replay read. */
90
+ read(agentId: string, messages: readonly {
91
+ message?: unknown;
92
+ }[]): void;
93
+ /** The session id of the child's stream: AIR's replay id, or the agent id. */
94
+ streamId(form: "air" | "rfd"): string;
95
+ /** The storage of a checkpoint, when the child's stream renders from its own files alone. */
96
+ storage(transcript: string, rewound: boolean): SessionReadStorage | undefined;
97
+ }
35
98
  /** The SDK follows parent links in these records, including the branch selected by rewind.json. */
36
- export declare function readSessionTranscript(sessionId: string, cwd?: string, observeStorage?: boolean): Promise<{
99
+ export declare function readSessionTranscript(sessionId: string, cwd?: string, observeStorage?: boolean, scope?: SessionReadScope,
100
+ /** Whether the render links each Skill call to its SKILL.md, as for AIR clients (see `toolUseMeta`). */
101
+ skillLinks?: boolean): Promise<{
37
102
  messages: import("@anthropic-ai/claude-agent-sdk").SessionMessage[];
38
103
  cwd: string;
39
104
  transcript: string;
105
+ child: SessionReadChild | undefined;
106
+ rewound: boolean;
107
+ subagentStatus: SubagentStatus | undefined;
40
108
  title: string | undefined;
41
109
  storage: {
110
+ skills?: {
111
+ cwd: string;
112
+ paths: [string, string | null][];
113
+ } | undefined;
114
+ files?: [string, string | null][] | undefined;
115
+ subagents?: string | undefined;
42
116
  transcript: string;
43
- version: string;
117
+ version: string | undefined;
44
118
  sidecarTitle: string | null | undefined;
45
119
  } | undefined;
46
120
  }>;
47
121
  /** A read owns only a replay on this connection. Closing it invalidates the pending delivery. */
48
122
  export declare class SessionReads {
123
+ /** Reads by root session, or by root, child and mode for the other scopes. */
49
124
  private readonly active;
50
125
  private readonly transitions;
51
126
  private readonly checkpoints;
@@ -1 +1 @@
1
- {"version":3,"file":"session-read.d.ts","sourceRoot":"","sources":["../src/session-read.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,uBAAuB;;CAA+B,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC1D,CAAC,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