@howaboua/pi-shepherdr 0.2.12 → 0.2.14

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.
@@ -104,11 +104,13 @@ export function parseMonitoredAgent(
104
104
  }
105
105
  const cwd = optionalString(record, "cwd");
106
106
  const lastAssistantId = optionalString(record, "lastAssistantId");
107
+ const lastQuestionId = optionalString(record, "lastQuestionId");
107
108
  const name = optionalString(record, "name");
108
109
  const activity = parsedActivity(record["activity"]);
109
110
  if (
110
111
  cwd === false ||
111
112
  lastAssistantId === false ||
113
+ lastQuestionId === false ||
112
114
  name === false ||
113
115
  !activity
114
116
  ) {
@@ -123,6 +125,7 @@ export function parseMonitoredAgent(
123
125
  tabId: record["tabId"],
124
126
  ...(cwd ? { cwd } : {}),
125
127
  ...(lastAssistantId ? { lastAssistantId } : {}),
128
+ ...(lastQuestionId ? { lastQuestionId } : {}),
126
129
  ...(name ? { name } : {}),
127
130
  };
128
131
  }
@@ -132,6 +135,7 @@ export function recordForPanel(
132
135
  activity: AgentActivity,
133
136
  scope: MonitoredAgent["scope"],
134
137
  lastAssistantId?: string,
138
+ lastQuestionId?: string,
135
139
  ): MonitoredAgent {
136
140
  const cwd = panel.foreground_cwd ?? panel.cwd;
137
141
  return {
@@ -144,6 +148,7 @@ export function recordForPanel(
144
148
  ...(panel.name ? { name: panel.name } : {}),
145
149
  ...(cwd ? { cwd } : {}),
146
150
  ...(lastAssistantId ? { lastAssistantId } : {}),
151
+ ...(lastQuestionId ? { lastQuestionId } : {}),
147
152
  };
148
153
  }
149
154
 
@@ -160,6 +165,7 @@ export function sameMonitorRecord(
160
165
  left.cwd === right.cwd &&
161
166
  left.name === right.name &&
162
167
  left.lastAssistantId === right.lastAssistantId &&
168
+ left.lastQuestionId === right.lastQuestionId &&
163
169
  sameAgentActivity(left.activity, right.activity)
164
170
  );
165
171
  }
@@ -81,6 +81,13 @@ export class MonitorState {
81
81
  return this.agents.get(terminalId);
82
82
  }
83
83
 
84
+ markQuestion(terminalId: string, id: string): boolean {
85
+ const record = this.byTerminal(terminalId);
86
+ if (!record || record.lastQuestionId === id) return false;
87
+ this.agents.set(terminalId, { ...record, lastQuestionId: id });
88
+ return true;
89
+ }
90
+
84
91
  watch(
85
92
  panel: PaneInfo,
86
93
  lastAssistantId?: string,
@@ -102,6 +109,7 @@ export class MonitorState {
102
109
  reportCurrent
103
110
  ? undefined
104
111
  : (existing?.lastAssistantId ?? lastAssistantId),
112
+ existing?.lastQuestionId,
105
113
  );
106
114
  if (existing && existing.terminalId !== record.terminalId) {
107
115
  this.agents.delete(existing.terminalId);
@@ -348,6 +356,7 @@ export class MonitorState {
348
356
  activity,
349
357
  record.scope,
350
358
  record.lastAssistantId,
359
+ record.lastQuestionId,
351
360
  );
352
361
  if (!sameMonitorRecord(record, updated)) changed = true;
353
362
  if (record.terminalId !== updated.terminalId) {
@@ -382,12 +391,9 @@ export class MonitorState {
382
391
  ): boolean {
383
392
  const record = this.byTerminal(terminalId);
384
393
  if (!record || activityTask(record.activity) !== task) return false;
385
- if (record.scope === "task" && status !== "blocked") {
386
- this.agents.delete(terminalId);
387
- return true;
388
- }
389
394
  this.agents.set(terminalId, {
390
395
  ...record,
396
+ scope: "persistent",
391
397
  activity: { phase: "settled", status },
392
398
  ...(lastAssistantId ? { lastAssistantId } : {}),
393
399
  });
package/src/monitor.ts CHANGED
@@ -5,10 +5,12 @@ import type {
5
5
  import { isSettledStatus } from "./activity.js";
6
6
  import { getSnapshot } from "./herdr.js";
7
7
  import { type HerdrConnection, isDispatchRejected } from "./herdr-client.js";
8
+ import { injectAgentEvent } from "./messages.js";
8
9
  import { parseMonitorEvent } from "./monitor-event.js";
9
10
  import { MonitorEvents } from "./monitor-events.js";
11
+ import { MonitorQuestions } from "./monitor-questions.js";
10
12
  import { MonitorState, type WorkAttempt } from "./monitor-state.js";
11
- import type { AssistantReader } from "./session-reader.js";
13
+ import { type AssistantReader, SessionReader } from "./session-reader.js";
12
14
  import {
13
15
  type ClaimedSettlement,
14
16
  SettlementReporter,
@@ -45,6 +47,7 @@ export class AgentMonitor {
45
47
  private readonly state = new MonitorState();
46
48
  private readonly events: MonitorEvents;
47
49
  private readonly settlements: SettlementReporter;
50
+ private readonly questions: MonitorQuestions;
48
51
  private context: ExtensionContext | undefined;
49
52
  private activationGeneration = 0;
50
53
 
@@ -54,6 +57,26 @@ export class AgentMonitor {
54
57
  this.onChange = options.onChange;
55
58
  this.onRefresh = options.onRefresh;
56
59
  this.selfPaneId = options.selfPaneId;
60
+ const reader = options.reader ?? new SessionReader();
61
+ this.questions = new MonitorQuestions({
62
+ client: this.client,
63
+ reader,
64
+ state: this.state,
65
+ notify: (ctx, record, agent, ask) => {
66
+ injectAgentEvent(pi, ctx, {
67
+ agent,
68
+ ask,
69
+ record,
70
+ status: "question",
71
+ labels: {},
72
+ agentToolName: "agents",
73
+ machine: this.machine,
74
+ machineLabel: options.machineLabel(),
75
+ operatorPrefix: options.operatorPrefix,
76
+ });
77
+ },
78
+ persist: () => this.persist(),
79
+ });
57
80
  this.settlements = new SettlementReporter(
58
81
  pi,
59
82
  this.client,
@@ -62,7 +85,7 @@ export class AgentMonitor {
62
85
  this.persist();
63
86
  this.refreshAfterEvent();
64
87
  },
65
- options.reader,
88
+ reader,
66
89
  {
67
90
  machine: this.machine,
68
91
  label: options.machineLabel,
@@ -87,6 +110,7 @@ export class AgentMonitor {
87
110
  this.deactivate();
88
111
  const generation = this.activationGeneration;
89
112
  this.context = ctx;
113
+ this.questions.start(ctx);
90
114
  const dropped = this.state.restore(restored, this.selfPaneId);
91
115
  if (dropped > 0) {
92
116
  ctx.ui.notify(
@@ -105,6 +129,7 @@ export class AgentMonitor {
105
129
  this.activationGeneration += 1;
106
130
  this.context = undefined;
107
131
  this.events.stop();
132
+ this.questions.stop();
108
133
  this.settlements.stop();
109
134
  }
110
135
 
@@ -149,6 +174,7 @@ export class AgentMonitor {
149
174
  new Error(`${paneId} was unwatched before its work settled`),
150
175
  );
151
176
  this.persist();
177
+ if (this.list().length === 0) await this.questions.refresh([]);
152
178
  await this.events.refresh();
153
179
  return true;
154
180
  }
@@ -179,6 +205,15 @@ export class AgentMonitor {
179
205
  return this.settlements.view(panel);
180
206
  }
181
207
 
208
+ submitAskAnswer(
209
+ panel: PaneInfo,
210
+ askId: string,
211
+ submit: (signal: AbortSignal) => Promise<void>,
212
+ signal: AbortSignal,
213
+ ) {
214
+ return this.questions.submitAnswer(panel, askId, submit, signal);
215
+ }
216
+
182
217
  acceptWork(attempt: WorkAttempt | undefined): void {
183
218
  if (this.state.acceptWork(attempt)) this.persist();
184
219
  }
@@ -232,6 +267,7 @@ export class AgentMonitor {
232
267
  return;
233
268
  }
234
269
  if (this.list().length === 0) {
270
+ await this.questions.refresh([]);
235
271
  if (persistRestoration) this.persist();
236
272
  else this.onRefresh();
237
273
  return;
@@ -251,6 +287,7 @@ export class AgentMonitor {
251
287
  }
252
288
  if (changed || persistRestoration) this.persist();
253
289
  else this.onRefresh();
290
+ await this.questions.refresh(snapshot.agents);
254
291
  for (const completion of completions) {
255
292
  void this.report(completion);
256
293
  }
@@ -290,6 +327,7 @@ export class AgentMonitor {
290
327
  }
291
328
 
292
329
  private refreshAfterEvent(): void {
330
+ if (this.list().length === 0) void this.questions.refresh([]);
293
331
  // MonitorEvents reports failures through onWarning before rejecting awaited updates.
294
332
  void this.events.refresh().catch(() => undefined);
295
333
  }
@@ -0,0 +1,72 @@
1
+ // @howaboua/pi-shepherdr managed bridge
2
+ import { watch } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { basename, dirname, join } from "node:path";
5
+
6
+ /**
7
+ * Watch only named sessions' directories, including file replacement.
8
+ * @param {string[]} paths
9
+ * @param {(path: string) => void} onChange
10
+ * @param {(error: Error) => void} onError
11
+ * @param {AbortSignal} [signal]
12
+ */
13
+ export function watchSessions(paths, onChange, onError, signal) {
14
+ /** @type {import('node:fs').FSWatcher[]} */
15
+ const watchers = [];
16
+ /** @type {Map<string, NodeJS.Timeout>} */
17
+ const timers = new Map();
18
+ /** @type {Map<string, Map<string, string>>} */
19
+ const directories = new Map();
20
+ let closed = false;
21
+ const close = () => {
22
+ if (closed) return;
23
+ closed = true;
24
+ signal?.removeEventListener("abort", close);
25
+ for (const watcher of watchers) watcher.close();
26
+ for (const timer of timers.values()) clearTimeout(timer);
27
+ timers.clear();
28
+ };
29
+ try {
30
+ for (const path of new Set(paths)) {
31
+ const expanded =
32
+ path === "~"
33
+ ? homedir()
34
+ : path.startsWith("~/")
35
+ ? join(homedir(), path.slice(2))
36
+ : path;
37
+ const directory = dirname(expanded);
38
+ const files = directories.get(directory) ?? new Map();
39
+ files.set(basename(expanded), path);
40
+ directories.set(directory, files);
41
+ }
42
+ for (const [directory, files] of directories) {
43
+ const watcher = watch(
44
+ directory,
45
+ { persistent: false },
46
+ (_event, filename) => {
47
+ for (const [name, path] of files) {
48
+ if (filename !== null && filename.toString() !== name) continue;
49
+ if (timers.has(path) || closed) continue;
50
+ const timer = setTimeout(() => {
51
+ timers.delete(path);
52
+ if (!closed) onChange(path);
53
+ }, 25);
54
+ timer.unref();
55
+ timers.set(path, timer);
56
+ }
57
+ },
58
+ );
59
+ watcher.on("error", (error) => {
60
+ close();
61
+ onError(error);
62
+ });
63
+ watchers.push(watcher);
64
+ }
65
+ signal?.addEventListener("abort", close, { once: true });
66
+ if (signal?.aborted) close();
67
+ return close;
68
+ } catch (error) {
69
+ close();
70
+ throw error;
71
+ }
72
+ }
@@ -1,4 +1,5 @@
1
1
  // @howaboua/pi-shepherdr managed bridge
2
+
2
3
  import { open, stat } from "node:fs/promises";
3
4
  import { homedir } from "node:os";
4
5
  import { join } from "node:path";
@@ -105,6 +106,7 @@ function askFromInput(toolCallId, input) {
105
106
  return {
106
107
  toolCallId,
107
108
  handoff: input.handoff === true,
109
+ ...(input.delivery === "steer" ? { delivery: "steer" } : {}),
108
110
  prompts,
109
111
  };
110
112
  }
@@ -114,6 +116,7 @@ function askResult(message) {
114
116
  return undefined;
115
117
  const id = message.toolCallId ?? message.tool_call_id;
116
118
  if (typeof id !== "string") return undefined;
119
+ if (message.details?.pending === true) return undefined;
117
120
  if (message.isError === true) return [id, { status: "rejected" }];
118
121
  if (message.isError !== false) return [id, { status: "unknown" }];
119
122
  if (message.details?.dismissed === true) return [id, { status: "rejected" }];
@@ -147,7 +150,12 @@ function askResult(message) {
147
150
  return [
148
151
  id,
149
152
  {
150
- status: "accepted",
153
+ status:
154
+ responses &&
155
+ responses.length > 0 &&
156
+ responses.length === rawResponseCount
157
+ ? "accepted"
158
+ : "unknown",
151
159
  ...(responses && responses.length === rawResponseCount
152
160
  ? { responses }
153
161
  : {}),
@@ -203,6 +211,24 @@ async function sessionView(path, size) {
203
211
  }
204
212
  }
205
213
  }
214
+ if (entry.type === "custom" && entry.customType === "pi-ask-pending") {
215
+ const update = entry.data;
216
+ if (
217
+ update?.version === 1 &&
218
+ update.state === "closed" &&
219
+ typeof update.id === "string"
220
+ ) {
221
+ resolved.add(update.id);
222
+ const result = askResult({
223
+ role: "toolResult",
224
+ toolName: "ask",
225
+ toolCallId: update.id,
226
+ isError: false,
227
+ details: update,
228
+ });
229
+ if (result && !askResults.has(result[0])) askResults.set(...result);
230
+ }
231
+ }
206
232
  if (
207
233
  !input &&
208
234
  entry.type === "custom_message" &&
@@ -219,6 +245,7 @@ async function sessionView(path, size) {
219
245
  if (result && !askResults.has(result[0])) askResults.set(...result);
220
246
  if (
221
247
  (message.role === "toolResult" || message.role === "tool") &&
248
+ message.details?.pending !== true &&
222
249
  typeof (message.toolCallId ?? message.tool_call_id) === "string"
223
250
  )
224
251
  resolved.add(message.toolCallId ?? message.tool_call_id);
@@ -239,7 +266,10 @@ async function sessionView(path, size) {
239
266
  .reverse()
240
267
  .map(askCall)
241
268
  .find(
242
- (candidate) => candidate && !resolved.has(candidate.toolCallId),
269
+ (candidate) =>
270
+ candidate &&
271
+ candidate.delivery !== "steer" &&
272
+ !resolved.has(candidate.toolCallId),
243
273
  );
244
274
  }
245
275
  if (typeof entry.parentId !== "string") return true;
@@ -10,8 +10,9 @@ import {
10
10
  } from "./shepherdr-context.mjs";
11
11
  import { sendPeerMessage } from "./shepherdr-peer.mjs";
12
12
  import { readSessionView } from "./shepherdr-session.mjs";
13
+ import { watchSessions } from "./shepherdr-session-watch.mjs";
13
14
 
14
- const BRIDGE_VERSION = 13;
15
+ const BRIDGE_VERSION = 14;
15
16
  const MAX_FRAME_BYTES = 8 * 1024 * 1024;
16
17
  const subscriptions = new Map();
17
18
  const contextRelays = new Map();
@@ -344,6 +345,25 @@ async function handle(message) {
344
345
  await subscribe(message.id, message.subscriptions ?? []);
345
346
  return { subscribed: true };
346
347
  }
348
+ if (message.op === "session_subscribe") {
349
+ const close = watchSessions(
350
+ message.paths ?? [],
351
+ (path) =>
352
+ send({
353
+ subscription: message.id,
354
+ event: { event: "session.changed", data: { path } },
355
+ }),
356
+ (error) => {
357
+ process.stderr.write(
358
+ `Session monitoring disconnected: ${error.message}\n`,
359
+ );
360
+ process.exitCode = 1;
361
+ setTimeout(() => process.exit(), 0);
362
+ },
363
+ );
364
+ subscriptions.set(message.id, close);
365
+ return { subscribed: true };
366
+ }
347
367
  if (message.op === "unsubscribe") {
348
368
  subscriptions.get(message.subscription)?.();
349
369
  subscriptions.delete(message.subscription);
@@ -14,10 +14,11 @@ import type {
14
14
  SessionView,
15
15
  } from "./types.js";
16
16
 
17
- const BRIDGE_VERSION = 13;
17
+ const BRIDGE_VERSION = 14;
18
18
  const REMOTE_HELPER = "~/.pi/agent/shepherdr.mjs";
19
19
  const REMOTE_PEER_HELPER = "~/.pi/agent/shepherdr-peer.mjs";
20
20
  const REMOTE_SESSION_HELPER = "~/.pi/agent/shepherdr-session.mjs";
21
+ const REMOTE_SESSION_WATCH_HELPER = "~/.pi/agent/shepherdr-session-watch.mjs";
21
22
  const REMOTE_CHECKPOINT_HELPER = "~/.pi/agent/shepherdr-checkpoints.mjs";
22
23
  const REMOTE_CONTEXT_HELPER = "~/.pi/agent/shepherdr-context.mjs";
23
24
  const MAX_FRAME_BYTES = 8 * 1024 * 1024;
@@ -202,34 +203,44 @@ export class RemoteHerdrClient implements HerdrConnection, AssistantReader {
202
203
  config: SshMachine,
203
204
  onClose: (error: Error) => void,
204
205
  ): Promise<RemoteHerdrClient> {
205
- const [source, peerSource, sessionSource, contextSource, checkpointSource] =
206
- await Promise.all([
207
- readFile(
208
- fileURLToPath(new URL("./remote/shepherdr.mjs", import.meta.url)),
206
+ const [
207
+ source,
208
+ peerSource,
209
+ sessionSource,
210
+ contextSource,
211
+ checkpointSource,
212
+ sessionWatchSource,
213
+ ] = await Promise.all([
214
+ readFile(
215
+ fileURLToPath(new URL("./remote/shepherdr.mjs", import.meta.url)),
216
+ ),
217
+ readFile(
218
+ fileURLToPath(new URL("./remote/shepherdr-peer.mjs", import.meta.url)),
219
+ ),
220
+ readFile(
221
+ fileURLToPath(
222
+ new URL("./remote/shepherdr-session.mjs", import.meta.url),
209
223
  ),
210
- readFile(
211
- fileURLToPath(
212
- new URL("./remote/shepherdr-peer.mjs", import.meta.url),
213
- ),
224
+ ),
225
+ readFile(
226
+ fileURLToPath(
227
+ new URL("./remote/shepherdr-context.mjs", import.meta.url),
214
228
  ),
215
- readFile(
216
- fileURLToPath(
217
- new URL("./remote/shepherdr-session.mjs", import.meta.url),
218
- ),
229
+ ),
230
+ readFile(
231
+ fileURLToPath(
232
+ new URL("./remote/shepherdr-checkpoints.mjs", import.meta.url),
219
233
  ),
220
- readFile(
221
- fileURLToPath(
222
- new URL("./remote/shepherdr-context.mjs", import.meta.url),
223
- ),
234
+ ),
235
+ readFile(
236
+ fileURLToPath(
237
+ new URL("./remote/shepherdr-session-watch.mjs", import.meta.url),
224
238
  ),
225
- readFile(
226
- fileURLToPath(
227
- new URL("./remote/shepherdr-checkpoints.mjs", import.meta.url),
228
- ),
229
- ),
230
- ]);
239
+ ),
240
+ ]);
231
241
  await deploy(config, peerSource, REMOTE_PEER_HELPER);
232
242
  await deploy(config, sessionSource, REMOTE_SESSION_HELPER);
243
+ await deploy(config, sessionWatchSource, REMOTE_SESSION_WATCH_HELPER);
233
244
  await deploy(config, checkpointSource, REMOTE_CHECKPOINT_HELPER);
234
245
  await deploy(config, contextSource, REMOTE_CONTEXT_HELPER);
235
246
  await deploy(config, source, REMOTE_HELPER);
@@ -306,6 +317,37 @@ export class RemoteHerdrClient implements HerdrConnection, AssistantReader {
306
317
  onEvent: (event: HerdrEvent) => void,
307
318
  onDisconnect: (error?: Error) => void,
308
319
  signal?: AbortSignal,
320
+ ): Promise<() => void> {
321
+ return this.subscribeTo(
322
+ { op: "subscribe", subscriptions },
323
+ onEvent,
324
+ onDisconnect,
325
+ signal,
326
+ );
327
+ }
328
+
329
+ async watch(
330
+ paths: string[],
331
+ onChange: (path: string) => void,
332
+ onError: (error: Error) => void,
333
+ signal: AbortSignal,
334
+ ): Promise<() => void> {
335
+ return this.subscribeTo(
336
+ { op: "session_subscribe", paths },
337
+ (event) => {
338
+ if (typeof event.data["path"] === "string")
339
+ onChange(event.data["path"]);
340
+ },
341
+ (error) => onError(error ?? new Error("Session activity stream closed")),
342
+ signal,
343
+ );
344
+ }
345
+
346
+ private async subscribeTo(
347
+ request: Record<string, unknown>,
348
+ onEvent: (event: HerdrEvent) => void,
349
+ onDisconnect: (error?: Error) => void,
350
+ signal?: AbortSignal,
309
351
  ): Promise<() => void> {
310
352
  signal?.throwIfAborted();
311
353
  const id = randomUUID();
@@ -318,7 +360,7 @@ export class RemoteHerdrClient implements HerdrConnection, AssistantReader {
318
360
  );
319
361
  };
320
362
  try {
321
- const ready = this.call({ id, op: "subscribe", subscriptions }, 11_000);
363
+ const ready = this.call({ ...request, id }, 11_000);
322
364
  signal?.addEventListener("abort", unsubscribe, { once: true });
323
365
  if (signal?.aborted) unsubscribe();
324
366
  await ready;
@@ -1,4 +1,5 @@
1
1
  import { open, stat } from "node:fs/promises";
2
+ import { watchSessions } from "./remote/shepherdr-session-watch.mjs";
2
3
  import type {
3
4
  AskResult,
4
5
  LatestAssistant,
@@ -118,6 +119,7 @@ function askFromInput(
118
119
  return {
119
120
  toolCallId,
120
121
  handoff: args["handoff"] === true,
122
+ ...(args["delivery"] === "steer" ? { delivery: "steer" as const } : {}),
121
123
  prompts,
122
124
  };
123
125
  }
@@ -143,6 +145,7 @@ function askResult(
143
145
  if (message["isError"] === true) return [id, { status: "rejected" }];
144
146
  if (message["isError"] !== false) return [id, { status: "unknown" }];
145
147
  const details = record(message["details"]);
148
+ if (details?.["pending"] === true) return undefined;
146
149
  if (details?.["dismissed"] === true) return [id, { status: "rejected" }];
147
150
  const rawResponses = details?.["responses"];
148
151
  const rawResponseCount = Array.isArray(rawResponses)
@@ -175,7 +178,12 @@ function askResult(
175
178
  return [
176
179
  id,
177
180
  {
178
- status: "accepted",
181
+ status:
182
+ responses &&
183
+ responses.length > 0 &&
184
+ responses.length === rawResponseCount
185
+ ? "accepted"
186
+ : "unknown",
179
187
  ...(responses && responses.length === rawResponseCount
180
188
  ? { responses }
181
189
  : {}),
@@ -236,6 +244,27 @@ async function readSessionView(
236
244
  }
237
245
  }
238
246
  }
247
+ if (
248
+ entry["type"] === "custom" &&
249
+ entry["customType"] === "pi-ask-pending"
250
+ ) {
251
+ const update = record(entry["data"]);
252
+ if (
253
+ update?.["version"] === 1 &&
254
+ update["state"] === "closed" &&
255
+ typeof update["id"] === "string"
256
+ ) {
257
+ resolved.add(update["id"]);
258
+ const result = askResult({
259
+ role: "toolResult",
260
+ toolName: "ask",
261
+ toolCallId: update["id"],
262
+ isError: false,
263
+ details: update,
264
+ });
265
+ if (result && !askResults.has(result[0])) askResults.set(...result);
266
+ }
267
+ }
239
268
  if (
240
269
  !input &&
241
270
  entry["type"] === "custom_message" &&
@@ -251,7 +280,8 @@ async function readSessionView(
251
280
  const result = askResult(message);
252
281
  if (result && !askResults.has(result[0])) askResults.set(...result);
253
282
  const resolvedId = resolvedToolCallId(message);
254
- if (resolvedId) resolved.add(resolvedId);
283
+ if (resolvedId && record(message["details"])?.["pending"] !== true)
284
+ resolved.add(resolvedId);
255
285
  if (!assistant) {
256
286
  assistant = assistantFromMessage(id, message);
257
287
  if (assistant) assistantDepth = currentDepth;
@@ -270,7 +300,9 @@ async function readSessionView(
270
300
  .map(askCall)
271
301
  .find(
272
302
  (candidate) =>
273
- candidate !== undefined && !resolved.has(candidate.toolCallId),
303
+ candidate !== undefined &&
304
+ candidate.delivery !== "steer" &&
305
+ !resolved.has(candidate.toolCallId),
274
306
  );
275
307
  }
276
308
  }
@@ -307,6 +339,14 @@ async function readSessionView(
307
339
  }
308
340
 
309
341
  export class SessionReader {
342
+ async watch(
343
+ paths: string[],
344
+ onChange: (path: string) => void,
345
+ onError: (error: Error) => void,
346
+ signal: AbortSignal,
347
+ ): Promise<() => void> {
348
+ return watchSessions(paths, onChange, onError, signal);
349
+ }
310
350
  private readonly cache = new Map<
311
351
  string,
312
352
  { mtimeMs: number; result: SessionView; size: number }
@@ -340,6 +380,12 @@ export class SessionReader {
340
380
  }
341
381
 
342
382
  export interface AssistantReader {
383
+ watch(
384
+ paths: string[],
385
+ onChange: (path: string) => void,
386
+ onError: (error: Error) => void,
387
+ signal: AbortSignal,
388
+ ): Promise<() => void>;
343
389
  latest(path?: string): Promise<LatestAssistant | undefined>;
344
390
  view(path?: string): Promise<SessionView>;
345
391
  }