@agentclientprotocol/claude-agent-acp 0.94.1-preview.1 → 0.94.1-preview.10

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.
Files changed (47) hide show
  1. package/README.md +21 -9
  2. package/dist/acp-agent.d.ts +39 -3
  3. package/dist/acp-agent.d.ts.map +1 -1
  4. package/dist/acp-agent.js +145 -66
  5. package/dist/acp-subagents.d.ts +2 -1
  6. package/dist/acp-subagents.d.ts.map +1 -1
  7. package/dist/air-extension.d.ts +5 -0
  8. package/dist/air-extension.d.ts.map +1 -1
  9. package/dist/air-extension.js +5 -0
  10. package/dist/clear-context-coordinator.d.ts +1 -0
  11. package/dist/clear-context-coordinator.d.ts.map +1 -1
  12. package/dist/clear-context-coordinator.js +1 -0
  13. package/dist/index.js +2 -3
  14. package/dist/native-subagents.d.ts +64 -0
  15. package/dist/native-subagents.d.ts.map +1 -1
  16. package/dist/native-subagents.js +224 -9
  17. package/dist/permissions/options/shared.d.ts +3 -0
  18. package/dist/permissions/options/shared.d.ts.map +1 -1
  19. package/dist/permissions/options/tools.js +1 -1
  20. package/dist/serve.d.ts +19 -11
  21. package/dist/serve.d.ts.map +1 -1
  22. package/dist/serve.js +26 -18
  23. package/dist/session-index/activity.d.ts +4 -0
  24. package/dist/session-index/activity.d.ts.map +1 -1
  25. package/dist/session-index/activity.js +16 -0
  26. package/dist/session-index/background-tasks.d.ts +69 -0
  27. package/dist/session-index/background-tasks.d.ts.map +1 -0
  28. package/dist/session-index/background-tasks.js +173 -0
  29. package/dist/session-index/service.d.ts +2 -0
  30. package/dist/session-index/service.d.ts.map +1 -1
  31. package/dist/session-index/service.js +6 -1
  32. package/dist/session-index/session-index.d.ts +14 -0
  33. package/dist/session-index/session-index.d.ts.map +1 -1
  34. package/dist/session-index/session-index.js +25 -2
  35. package/dist/session-index/transcript-scan.d.ts +8 -1
  36. package/dist/session-index/transcript-scan.d.ts.map +1 -1
  37. package/dist/session-index/transcript-scan.js +22 -1
  38. package/dist/session-titles.d.ts +44 -16
  39. package/dist/session-titles.d.ts.map +1 -1
  40. package/dist/session-titles.js +89 -27
  41. package/dist/subagent-replay.d.ts +21 -1
  42. package/dist/subagent-replay.d.ts.map +1 -1
  43. package/dist/subagent-replay.js +51 -3
  44. package/dist/task-notifications.d.ts +30 -0
  45. package/dist/task-notifications.d.ts.map +1 -0
  46. package/dist/task-notifications.js +62 -0
  47. package/package.json +1 -1
@@ -0,0 +1,173 @@
1
+ /**
2
+ * The background tasks of a session that did not end yet, from its transcript.
3
+ *
4
+ * A Claude Code session can start a background shell command or a background
5
+ * sub-agent and end its turn at once. When the task ends, Claude Code wakes
6
+ * the session with a `<task-notification>` input for a short turn. So a turn
7
+ * end with an open task is no end of the work: the session list keeps such a
8
+ * session `running` (see `activity.ts`).
9
+ *
10
+ * The records, as Claude Code 2.1.299 writes them, in the rules of AIR's
11
+ * native Claude provider:
12
+ *
13
+ * - a tool result opens a task when its `toolUseResult` has a
14
+ * `backgroundTaskId` (a shell command), or `isAsync: true` with an
15
+ * `agentId` (a sub-agent);
16
+ * - a task closes when its notification reaches the session: as a user
17
+ * record, or as a `queue-operation` `remove` when a running turn takes it
18
+ * in. A notification that waits in the queue (`enqueue`) keeps the task
19
+ * open, because the session still runs a turn for it;
20
+ * - only a notification with a `<status>` closes a task. A notification
21
+ * without one comes while the task still runs: the check-in of a quiet
22
+ * shell ("is still running after …", since Claude Code 2.1.303) or a
23
+ * `Monitor` event;
24
+ * - a `TaskStop` result closes the task of its `toolUseResult.task_id`:
25
+ * Claude Code writes no notification for it. The result does not name its
26
+ * tool, so its `tool_use_id` must match a `TaskStop` call. A `task_id` in
27
+ * the result of another tool keeps the task open;
28
+ * - a resumed CLI writes a `stopped` notification for each task of the
29
+ * previous process;
30
+ * - a sidechain record belongs to a sub-agent and opens or closes no task of
31
+ * the session.
32
+ *
33
+ * A background shell that does not end, for example a dev server, keeps its
34
+ * task open, so its session stays `running` while the CLI holds it.
35
+ *
36
+ * A task that a sub-agent starts is not seen. Its start record is only in the
37
+ * transcript of the sub-agent, so the session can be `idle` while the
38
+ * sub-agent waits for it.
39
+ */
40
+ import { createReadStream } from "node:fs";
41
+ import { createInterface } from "node:readline";
42
+ import { TASK_NOTIFICATION_TAG, taskNotificationsOf } from "../task-notifications.js";
43
+ const NOTIFICATION_TAG = `<${TASK_NOTIFICATION_TAG}>`;
44
+ /** Text that a line must hold to bear on a task, so that the other lines
45
+ * are not parsed. */
46
+ const TASK_MARKERS = ["backgroundTaskId", '"isAsync"', NOTIFICATION_TAG, "TaskStop", "task_id"];
47
+ function parseRecord(line) {
48
+ try {
49
+ return JSON.parse(line);
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
55
+ function blocksOf(record) {
56
+ const content = record.message?.content;
57
+ return Array.isArray(content) ? content : [];
58
+ }
59
+ /** The input of a user record: its string content, else its first text
60
+ * block. */
61
+ function inputTextOf(record) {
62
+ const content = record.message?.content;
63
+ if (typeof content === "string")
64
+ return content;
65
+ return blocksOf(record).find((block) => block.type === "text")?.text;
66
+ }
67
+ /** The task that a `<task-notification>` input ends: only an input that
68
+ * starts with the tag, after whitespace, as AIR's `TaskNotification` reads
69
+ * it. Only a notification with a `<status>` ends a task (see
70
+ * `taskNotificationsOf`). */
71
+ export function endedTaskId(input) {
72
+ if (!input?.trimStart().startsWith(NOTIFICATION_TAG))
73
+ return undefined;
74
+ return taskNotificationsOf(input)[0]?.task_id;
75
+ }
76
+ /** The task that a tool result started: a background shell command, or an
77
+ * async sub-agent. */
78
+ function startedTaskId(record) {
79
+ if (record.type !== "user")
80
+ return undefined;
81
+ const result = record.toolUseResult;
82
+ if (result?.backgroundTaskId)
83
+ return result.backgroundTaskId;
84
+ if (result?.isAsync)
85
+ return result.agentId;
86
+ return undefined;
87
+ }
88
+ /** The task whose notification reached the session: as a user record, or
89
+ * as a queue `remove` when a running turn takes it in. */
90
+ function deliveredTaskId(record) {
91
+ if (record.type === "user")
92
+ return endedTaskId(inputTextOf(record));
93
+ if (record.type === "queue-operation" && record.operation === "remove") {
94
+ return endedTaskId(record.content);
95
+ }
96
+ return undefined;
97
+ }
98
+ /** Collects the tasks of the lines it is given, in file order. */
99
+ class TaskTracker {
100
+ open;
101
+ stopCalls;
102
+ constructor(after) {
103
+ this.open = new Set(after?.open);
104
+ this.stopCalls = new Set(after?.stopCalls);
105
+ }
106
+ add(line) {
107
+ const mayBearOnTask = TASK_MARKERS.some((marker) => line.includes(marker));
108
+ if (!mayBearOnTask)
109
+ return;
110
+ const record = parseRecord(line);
111
+ // A sidechain record belongs to a sub-agent, which receives the
112
+ // notifications of its own tasks.
113
+ if (!record || record.isSidechain)
114
+ return;
115
+ this.apply(record);
116
+ }
117
+ result({ complete }) {
118
+ return { open: [...this.open], stopCalls: [...this.stopCalls], complete };
119
+ }
120
+ apply(record) {
121
+ const started = startedTaskId(record);
122
+ if (started)
123
+ this.open.add(started);
124
+ const delivered = deliveredTaskId(record);
125
+ if (delivered)
126
+ this.open.delete(delivered);
127
+ this.applyTaskStop(record);
128
+ }
129
+ /** A `task_id` stops its task only in the result of a `TaskStop` call:
130
+ * another tool can give a `task_id` too. */
131
+ applyTaskStop(record) {
132
+ let isTaskStopResult = false;
133
+ for (const block of blocksOf(record)) {
134
+ if (block.type === "tool_use" && block.name === "TaskStop" && block.id) {
135
+ this.stopCalls.add(block.id);
136
+ }
137
+ const resultId = block.tool_use_id;
138
+ if (resultId && this.stopCalls.has(resultId)) {
139
+ this.stopCalls.delete(resultId);
140
+ isTaskStopResult = true;
141
+ }
142
+ }
143
+ const stopped = record.toolUseResult?.task_id;
144
+ if (isTaskStopResult && stopped)
145
+ this.open.delete(stopped);
146
+ }
147
+ }
148
+ /**
149
+ * The tasks of the lines of `text`, applied on the tasks `after`.
150
+ *
151
+ * `after` can be what an earlier scan found for a shorter copy of the file,
152
+ * and `text` can repeat records of that copy. The result is still the same:
153
+ * the last record that opens or closes a task decides, and `text` holds the
154
+ * last records.
155
+ */
156
+ export function backgroundTasksOf(text, options) {
157
+ const tracker = new TaskTracker(options.after);
158
+ for (const line of text.split("\n"))
159
+ tracker.add(line);
160
+ return tracker.result({ complete: options.complete });
161
+ }
162
+ /** The tasks of the first `size` bytes of `filePath`, from all its records.
163
+ * Reads the whole file, so only for a session that a live process holds. */
164
+ export async function searchBackgroundTasks(filePath, size) {
165
+ const tracker = new TaskTracker();
166
+ if (size === 0)
167
+ return tracker.result({ complete: true });
168
+ const stream = createReadStream(filePath, { start: 0, end: size - 1, encoding: "utf8" });
169
+ const lines = createInterface({ input: stream, crlfDelay: Infinity });
170
+ for await (const line of lines)
171
+ tracker.add(line);
172
+ return tracker.result({ complete: true });
173
+ }
@@ -121,6 +121,8 @@ export declare class SessionIndexService {
121
121
  private readonly now;
122
122
  private readonly deleteSession;
123
123
  constructor(deps: SessionIndexDeps);
124
+ /** Whether a live process holds the session, by the live registry. */
125
+ private isLive;
124
126
  /** `session/list` of a `sessionIndex` client. `own` reports the sessions
125
127
  * that this connection runs. */
126
128
  list(params: ListSessionsRequest, own: (sessionId: string) => OwnSessionState | undefined): Promise<ListSessionsResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/session-index/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAC1B,MAAM,mCAAmC,CAAC;AAI3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAQrD,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAiBzD,OAAO,EAKL,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAG5B,eAAO,MAAM,qBAAqB,oBAAoB,CA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AO,GAAG,OAAO,CAAC,IAAI,CAAC;IA+C9D;2EACuE;IACvE,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAgB1D,+CAA+C;IAC/C,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAI7C,iEAAiE;IACjE,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI1C,sEAAsE;IACtE,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAInC,4EAA4E;IAC5E,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAInD;sDACkD;IAClD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIpC,OAAO,IAAI,IAAI;CAKhB"}
@@ -327,11 +327,16 @@ export class SessionIndexService {
327
327
  deleteSession;
328
328
  constructor(deps) {
329
329
  this.deps = deps;
330
- this.index = new SessionIndex();
331
330
  this.registry = deps.registry ?? new LiveSessionRegistry();
331
+ this.index = new SessionIndex({ isLive: (sessionId) => this.isLive(sessionId) });
332
332
  this.now = deps.now ?? Date.now;
333
333
  this.deleteSession = deps.deleteSession ?? ((id) => sdkDeleteSession(id));
334
334
  }
335
+ /** Whether a live process holds the session, by the live registry. */
336
+ async isLive(sessionId) {
337
+ const live = await this.registry.snapshot();
338
+ return live.has(sessionId);
339
+ }
335
340
  /** `session/list` of a `sessionIndex` client. `own` reports the sessions
336
341
  * that this connection runs. */
337
342
  async list(params, own) {
@@ -72,7 +72,14 @@ export type ListQuery = {
72
72
  };
73
73
  /** The title of the CLI's `custom-title.json` sidecar of a transcript. */
74
74
  export declare function readSidecarTitle(filePath: string, sessionId: string): Promise<string | undefined>;
75
+ export type SessionIndexOptions = {
76
+ /** Whether a live process holds the session. Only for such a session the
77
+ * whole transcript is searched for its background tasks. */
78
+ isLive?: (sessionId: string) => Promise<boolean>;
79
+ };
75
80
  export declare class SessionIndex {
81
+ private readonly options;
82
+ constructor(options?: SessionIndexOptions);
76
83
  private readonly listings;
77
84
  private readonly metadata;
78
85
  /** The metadata reads in flight, by path: a list and a subscription that
@@ -212,6 +219,13 @@ export declare class SessionIndex {
212
219
  private metadataOf;
213
220
  private readAndCache;
214
221
  private readMetadata;
222
+ /**
223
+ * `facts` with the background tasks of the whole transcript, when the
224
+ * tasks of its tail are not complete: a task can start before the tail.
225
+ * Only a finished turn of a live session waits for the tasks, so only
226
+ * then the whole transcript is read.
227
+ */
228
+ private withAllBackgroundTasks;
215
229
  /**
216
230
  * The titles the SDK gives the listed transcript (`customTitle` and
217
231
  * `summary` of its `getSessionInfo`), by the SDK's rule from the head and
@@ -1 +1 @@
1
- {"version":3,"file":"session-index.d.ts","sourceRoot":"","sources":["../../src/session-index/session-index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAkBH,OAAO,EAeL,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAI9B,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,cAAc,MAAM,CAAC;AAelC;;aAEa;AACb,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;AAE/D,eAAO,MAAM,gBAAgB,EAAE,SAAS,cAAc,EAAsC,CAAC;AAE7F,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAEtF;AAED,oDAAoD;AACpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAmBF,MA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,SAAS,MAAM,EAAE,EACxB,UAAU,EAAE,SAAS,mBAAmB,EAAE,EAC1C,EAAE,IAAW,EAAE,GAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAO,GACvC,OAAO,CAAC;QAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IAkCtD;;;;;;;;;;;;OAYG;YACW,WAAW;IAiGzB;iCAC6B;IAC7B,OAAO,CAAC,YAAY;IAkBpB;;;uDAGmD;YACrC,YAAY;IAsC1B,iEAAiE;IACjE,OAAO,CAAC,WAAW;YAaL,UAAU;YAwBV,YAAY;YA2BZ,YAAY;IAgD1B;;;;;OAKG;YACW,sBAAsB;IAYpC;;;;;;;;OAQG;YACW,QAAQ;IAQtB;2CACuC;YACzB,kBAAkB;IAKhC;;yDAEqD;YACvC,UAAU;CAazB"}
@@ -24,6 +24,7 @@ import { sanitizeTitle } from "../session-titles.js";
24
24
  import { effectiveTitle, visibleTitle } from "./archive-title.js";
25
25
  import { canonicalPath, encodeProjectPath, isExactProjectDir, isSessionId, normalizePath, pathAndAncestors, projectDirMatches, projectDirsOf, projectsRoot, sameProjectPath, } from "./project-dirs.js";
26
26
  import { continuedInSessionId, hasHistory, isSidechainTranscript, lastTimestamp, readHeadTail, relocatedCwd, scanTranscriptFile, sdkTitles, tailCustomTitle, transcriptAgentName, transcriptProjectCwd, } from "./transcript-scan.js";
27
+ import { searchBackgroundTasks } from "./background-tasks.js";
27
28
  import { DirListings, statFiles } from "./dir-listing.js";
28
29
  import { isInLinkedWorktree, worktreeCounterparts } from "./worktrees.js";
29
30
  export const DEFAULT_LIST_LIMIT = 50;
@@ -260,6 +261,10 @@ function scopeOf(paths) {
260
261
  };
261
262
  }
262
263
  export class SessionIndex {
264
+ options;
265
+ constructor(options = {}) {
266
+ this.options = options;
267
+ }
263
268
  listings = new DirListings();
264
269
  metadata = new Lru(METADATA_CACHE_SIZE);
265
270
  /** The metadata reads in flight, by path: a list and a subscription that
@@ -776,9 +781,10 @@ export class SessionIndex {
776
781
  const headTail = await readHeadTail(candidate.filePath, candidate.size);
777
782
  if (isSidechainTranscript(headTail.head))
778
783
  return null;
779
- const facts = await scanTranscriptFile(candidate.filePath, candidate.size, headTail, previous, candidate.ino);
780
- if (!facts.hasMessages)
784
+ const scanned = await scanTranscriptFile(candidate.filePath, candidate.size, headTail, previous, candidate.ino);
785
+ if (!scanned.hasMessages)
781
786
  return null;
787
+ const facts = await this.withAllBackgroundTasks(candidate, scanned);
782
788
  // The last relocation names the session's cwd, as the SDK reads it; the
783
789
  // messages before it keep the old one.
784
790
  const fileCwd = await this.recoverCwd(candidate.dirName, [
@@ -811,6 +817,23 @@ export class SessionIndex {
811
817
  facts,
812
818
  };
813
819
  }
820
+ /**
821
+ * `facts` with the background tasks of the whole transcript, when the
822
+ * tasks of its tail are not complete: a task can start before the tail.
823
+ * Only a finished turn of a live session waits for the tasks, so only
824
+ * then the whole transcript is read.
825
+ */
826
+ async withAllBackgroundTasks(candidate, facts) {
827
+ if (facts.turnState !== "finished")
828
+ return facts;
829
+ if (facts.backgroundTasks?.complete)
830
+ return facts;
831
+ const isLive = await this.options.isLive?.(candidate.sessionId);
832
+ if (!isLive)
833
+ return facts;
834
+ const backgroundTasks = await searchBackgroundTasks(candidate.filePath, candidate.size);
835
+ return { ...facts, backgroundTasks };
836
+ }
814
837
  /**
815
838
  * The titles the SDK gives the listed transcript (`customTitle` and
816
839
  * `summary` of its `getSessionInfo`), by the SDK's rule from the head and
@@ -7,8 +7,12 @@
7
7
  *
8
8
  * A last message longer than the tail window leaves no message in it: then
9
9
  * the tail window grows, up to {@link MAX_TAIL_SIZE}, until it holds one.
10
+ *
11
+ * The open background tasks come from the tail, on top of the tasks of an
12
+ * earlier scan (see `background-tasks.ts`).
10
13
  */
11
14
  import * as fs from "node:fs/promises";
15
+ import { type BackgroundTasks } from "./background-tasks.js";
12
16
  export type TurnState = "finished" | "unfinished";
13
17
  export type TranscriptFacts = {
14
18
  /** Time of the last user or assistant message in the tail, epoch ms. */
@@ -41,6 +45,9 @@ export type TranscriptFacts = {
41
45
  * worktree and the session is in it), false when it says otherwise.
42
46
  * Undefined when no such record was read. See {@link agentWorktreeOf}. */
43
47
  agentWorktree?: boolean;
48
+ /** The background tasks that did not end. From the tail, on top of what
49
+ * an earlier scan found when the file only grew within the tail. */
50
+ backgroundTasks?: BackgroundTasks;
44
51
  /** Whether the head or the tail holds a user or an assistant message. A
45
52
  * transcript without one is a metadata-only stub. */
46
53
  hasMessages: boolean;
@@ -59,7 +66,7 @@ declare const INHERITED_FACTS: readonly ["model", "tailCwd", "lastTurnEndedAt",
59
66
  /** What an earlier scan of the same file found, at `size`. */
60
67
  export type PreviousScan = {
61
68
  size: number;
62
- } & Pick<TranscriptFacts, "lastPromptAt" | "promptSearched" | (typeof INHERITED_FACTS)[number]>;
69
+ } & Pick<TranscriptFacts, "lastPromptAt" | "promptSearched" | "backgroundTasks" | (typeof INHERITED_FACTS)[number]>;
63
70
  /** The first and the last 64 KB of the first `size` bytes of `filePath`:
64
71
  * what was appended after the file was stat'ed is not read, so the result
65
72
  * matches the size it is cached by. The tail is the head for a file that
@@ -1 +1 @@
1
- {"version":3,"file":"transcript-scan.d.ts","sourceRoot":"","sources":["../../src/session-index/transcript-scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAcvC,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG;IAC5B,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;0BACsB;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gDAAgD;IAChD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;8EAC0E;IAC1E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mCAAmC;IACnC,OAAO,C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,MAAM,CAAC;IACrB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,QAAQ,EAC7C,YAAY,CAAC,EAAE,MAAM,GACpB,SAAS,CASX;AAED;iDACiD;AACjD,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAQ3E;AAED;6EAC6E;AAC7E,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB/F;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAsBrE;AAOD;0EAC0E;AAC1E,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA2BnE"}
@@ -7,8 +7,12 @@
7
7
  *
8
8
  * A last message longer than the tail window leaves no message in it: then
9
9
  * the tail window grows, up to {@link MAX_TAIL_SIZE}, until it holds one.
10
+ *
11
+ * The open background tasks come from the tail, on top of the tasks of an
12
+ * earlier scan (see `background-tasks.ts`).
10
13
  */
11
14
  import * as fs from "node:fs/promises";
15
+ import { backgroundTasksOf } from "./background-tasks.js";
12
16
  import { firstPrompt, isUserPrompt, mediaPrompt, promptOf } from "./first-prompt.js";
13
17
  const CHUNK_SIZE = 64 * 1024;
14
18
  /** The largest tail window read to find the last message. */
@@ -88,6 +92,8 @@ identity) {
88
92
  }
89
93
  }
90
94
  }
95
+ const previousTasks = grownWithinTail ? previous.backgroundTasks : undefined;
96
+ facts.backgroundTasks = tailBackgroundTasks(read.tail, size, previousTasks);
91
97
  // No worktree record in the tail (or before it, by an earlier scan): the
92
98
  // one `claude --worktree` writes at the start may still be in the head.
93
99
  if (facts.agentWorktree === undefined) {
@@ -107,8 +113,9 @@ identity) {
107
113
  return facts;
108
114
  const key = `${filePath}\0${size}\0${identity ?? ""}`;
109
115
  const searched = fullySearched.get(key);
116
+ // The tasks can differ by the earlier scan.
110
117
  if (searched)
111
- return searched;
118
+ return { ...searched, backgroundTasks: facts.backgroundTasks };
112
119
  let result = facts;
113
120
  const handle = await fs.open(filePath, "r");
114
121
  try {
@@ -150,6 +157,7 @@ identity) {
150
157
  // A turn end the wider tail lacks may lie before it: the
151
158
  // narrow scan inherited it from an earlier scan of this file.
152
159
  lastTurnEndedAt: wider.lastTurnEndedAt ?? facts.lastTurnEndedAt,
160
+ backgroundTasks: facts.backgroundTasks,
153
161
  hasMessages: facts.hasMessages,
154
162
  lastPromptAt,
155
163
  // Searched to the start of the file, or found.
@@ -170,6 +178,19 @@ identity) {
170
178
  }
171
179
  return result;
172
180
  }
181
+ /**
182
+ * The background tasks of the tail of a file of `size` bytes. `previous`:
183
+ * the tasks of an earlier scan, when the file only grew within the tail
184
+ * since. The set is complete when the tail is the whole file, or when it
185
+ * holds all records after a complete earlier set.
186
+ */
187
+ function tailBackgroundTasks(tail, size, previous) {
188
+ if (size <= CHUNK_SIZE)
189
+ return backgroundTasksOf(tail, { complete: true });
190
+ if (previous?.complete)
191
+ return backgroundTasksOf(tail, { complete: true, after: previous });
192
+ return backgroundTasksOf(tail, { complete: false });
193
+ }
173
194
  const RELOCATED_MARKER = '"relocated"';
174
195
  /** The cwd of the last `relocated` record of the tail: where the session
175
196
  * was moved, whatever cwd its earlier messages carry. */
@@ -1,15 +1,20 @@
1
1
  /**
2
2
  * AI-generated session titles.
3
3
  *
4
- * Claude Code's own auto-title generation never runs under the Agent SDK — the
5
- * latch that arms it is pre-set in the headless path — so `SDKSessionInfo.summary`
6
- * degrades to the raw first prompt. This module asks the CLI for a real title
7
- * instead, via the `generate_session_title` control request, and publishes it
8
- * over ACP as a `session_info_update`.
4
+ * Claude Code titles a new SDK session itself: when it reads the first prompt,
5
+ * it asks a small model for a title and stores it in the transcript as an
6
+ * `ai-title` entry, a few seconds in. It sends no message when it does. This
7
+ * module asks for the title with the `generate_session_title` control request,
8
+ * which returns the stored title or waits for the one being generated, and
9
+ * publishes it over ACP as a `session_info_update`. Where the CLI does not
10
+ * title the session itself (a resumed session, or one with
11
+ * `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` or
12
+ * `CLAUDE_CODE_DISABLE_TERMINAL_TITLE` set), the same request generates it.
9
13
  *
10
14
  * {@link SessionTitles} holds the per-session state and is owned by `Session`.
11
- * `acp-agent.ts` drives it from four places: {@link SessionTitles.onPrompt} and
15
+ * `acp-agent.ts` drives it from five places: {@link SessionTitles.onPrompt} and
12
16
  * {@link SessionTitles.onAssistantText} to collect text,
17
+ * {@link SessionTitles.onPromptQueued} once a prompt is sent to the CLI,
13
18
  * {@link SessionTitles.onTurnEnd} at `session_state_changed: idle`, and
14
19
  * {@link SessionTitles.reset} on `conversation_reset`.
15
20
  */
@@ -36,6 +41,10 @@ export declare class SessionTitles {
36
41
  * the same field as a user `/rename`, so re-titling could silently overwrite
37
42
  * one. Released by {@link reset}, and when generation yields nothing. */
38
43
  private settled;
44
+ /** Whether {@link onPromptQueued} asked for a title from the latest prompt.
45
+ * A turn end then does not ask again: like the CLI, a prompt that yields
46
+ * no title gets one try, and the next prompt tries again. */
47
+ private askedAtPrompt;
39
48
  /** The title a client set, which no generated title replaces. */
40
49
  private readonly explicit;
41
50
  /** The title last stored through {@link setExplicitTitle}, as stored
@@ -52,6 +61,15 @@ export declare class SessionTitles {
52
61
  /** Collect a prompt's own text for the title, skipping openers not worth
53
62
  * titling after. No-op once the title is settled. */
54
63
  onPrompt(prompt: PromptRequest["prompt"]): void;
64
+ /** Ask for the title as soon as a prompt is sent to the CLI, instead of
65
+ * waiting for `idle`: `idle` comes only after the whole turn and its
66
+ * background tasks, often minutes after the CLI stored its title. The CLI
67
+ * answers `generate_session_title` while the turn runs, and with the title
68
+ * it stored or is generating, so this makes no second model call. The
69
+ * prompt alone is the description, because the CLI titles from the prompt
70
+ * alone. When this yields no title, the stored summary is published and
71
+ * the next prompt tries again. */
72
+ onPromptQueued(session: Session, prompt: PromptRequest["prompt"]): void;
55
73
  /** Collect the assistant's own answer for the title. Chunks are appended
56
74
  * verbatim so streamed text reassembles. No-op once the title is settled. */
57
75
  onAssistantText(content: ContentBlock): void;
@@ -65,10 +83,12 @@ export declare class SessionTitles {
65
83
  * title — a user `/rename` or one generated earlier; the SDK folds both into
66
84
  * that one field. Adopt it and latch, so neither is ever titled over.
67
85
  *
68
- * With no title yet, ask the SDK to generate one in the background: it is a
69
- * ~2s small-model call and turn-end must not wait on it. Only when that is
70
- * not possible do we fall back to `summary`, which for an SDK-driven session
71
- * is just the raw first prompt. */
86
+ * With no title yet, and none asked for at the latest prompt (see
87
+ * {@link onPromptQueued}), ask the SDK to generate one in the background
88
+ * from the prompts and replies so far: it is a ~2s small-model call and
89
+ * turn-end must not wait on it. That covers a prompt too short to title
90
+ * from, such as "hi". Only when that is not possible do we fall back to
91
+ * `summary`, which for an SDK-driven session is just the raw first prompt. */
72
92
  onTurnEnd(session: Session): Promise<void>;
73
93
  /** Applies a title that the client chose (a rename, an archive or an
74
94
  * unarchive). Settles the title for good, waits for a generation in flight
@@ -87,12 +107,20 @@ export declare class SessionTitles {
87
107
  /** Whether to ask the SDK for a generated title now: once per session, on a
88
108
  * live query, with enough collected text for the generator to work with. */
89
109
  private canRequest;
90
- /** Generate a title from the session's own text and publish it. `persist`
91
- * writes it to the session file, which is what carries it into
92
- * `session/list` and `session/load`. A null or failed generation releases the
93
- * latch so a later turn retries, and publishes `fallback` (the stored
94
- * summary) so a backend that can't generate titles is no worse off than
95
- * before. */
110
+ /** Latch the title and run `generation` in the background, so neither the
111
+ * prompt nor turn-end waits on a model call. A client title change waits
112
+ * for it to finish (see {@link ExplicitTitle.track}). */
113
+ private startGeneration;
114
+ /** The prompt-time title: the one the session file already holds (a resumed
115
+ * session's title, or a `/rename`), else one generated from `description`.
116
+ * The file is read first because the CLI checks only the titles it holds in
117
+ * memory before generating one. */
118
+ private titleFromPrompt;
119
+ /** Generate a title from `description` and publish it. `persist` writes it
120
+ * to the session file, which is what carries it into `session/list` and
121
+ * `session/load`. A null or failed generation releases the latch so a later
122
+ * prompt or turn end retries, and publishes `fallback` (the stored summary)
123
+ * so a backend that can't generate titles is no worse off than before. */
96
124
  private requestGenerateTitle;
97
125
  }
98
126
  //# sourceMappingURL=session-titles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session-titles.d.ts","sourceRoot":"","sources":["../src/session-titles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAErF,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA+B9D,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBlD;AAED;gEACgE;AAChE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrF;AAOD;;iDAEiD;AACjD,qBAAa,aAAa;IAqCtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IArC5B;sEACkE;IAClE,OAAO,CAAC,SAAS,CAAC,CAAS;IAE3B;yEACqE;IACrE,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB;;;8EAG0E;IAC1E,OAAO,CAAC,OAAO,CAAS;IAExB,iEAAiE;IACjE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAEhD;;iBAEa;IACb,OAAO,CAAC,cAAc,CAAC,CAAS;IAEhC,4EAA4E;IAC5E,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,cAAc,CAAC,CAAoD;IAE3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