@zvada/agent-server 0.3.28 → 0.3.31

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 (82) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/core/agents/acp/acp-agent.js +3 -1
  3. package/dist/core/agents/claude-code/claude-agent.js +2 -12
  4. package/dist/core/agents/claude-code/session.js +12 -8
  5. package/dist/core/agents/claude-code/turn.js +6 -2
  6. package/dist/core/agents/gemini/profile.js +2 -1
  7. package/dist/core/runtime/event-processor.js +9 -10
  8. package/dist/operator/errors.js +9 -2
  9. package/dist/operator/index.js +1 -1
  10. package/dist/operator/operator.js +403 -152
  11. package/dist/operator/render.js +31 -15
  12. package/dist/operator/session-tools.js +9 -12
  13. package/dist/operator/view.js +16 -4
  14. package/dist/protocol/config.js +4 -2
  15. package/dist/protocol/conversation.js +2 -0
  16. package/dist/protocol/lifecycle.js +2 -0
  17. package/dist/protocol/part-input.js +2 -6
  18. package/dist/protocol/reduce.js +1 -0
  19. package/dist/protocol/text-parts.js +10 -0
  20. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  21. package/dist/types/core/agents/acp/profile.d.ts +6 -1
  22. package/dist/types/core/agents/acp/profile.d.ts.map +1 -1
  23. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -2
  24. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  25. package/dist/types/core/agents/claude-code/options.d.ts +1 -1
  26. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  27. package/dist/types/core/agents/claude-code/session.d.ts +4 -6
  28. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  29. package/dist/types/core/agents/claude-code/turn.d.ts +3 -2
  30. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  31. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -1
  32. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  33. package/dist/types/operator/errors.d.ts +3 -1
  34. package/dist/types/operator/errors.d.ts.map +1 -1
  35. package/dist/types/operator/index.d.ts +1 -1
  36. package/dist/types/operator/index.d.ts.map +1 -1
  37. package/dist/types/operator/operator.d.ts.map +1 -1
  38. package/dist/types/operator/render.d.ts +2 -0
  39. package/dist/types/operator/render.d.ts.map +1 -1
  40. package/dist/types/operator/session-tools.d.ts +1 -4
  41. package/dist/types/operator/session-tools.d.ts.map +1 -1
  42. package/dist/types/operator/types.d.ts +77 -17
  43. package/dist/types/operator/types.d.ts.map +1 -1
  44. package/dist/types/operator/view.d.ts.map +1 -1
  45. package/dist/types/protocol/config.d.ts +4 -2
  46. package/dist/types/protocol/config.d.ts.map +1 -1
  47. package/dist/types/protocol/conversation.d.ts +3 -0
  48. package/dist/types/protocol/conversation.d.ts.map +1 -1
  49. package/dist/types/protocol/lifecycle.d.ts +2 -0
  50. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  51. package/dist/types/protocol/part-input.d.ts.map +1 -1
  52. package/dist/types/protocol/reduce.d.ts.map +1 -1
  53. package/dist/types/protocol/text-parts.d.ts +10 -0
  54. package/dist/types/protocol/text-parts.d.ts.map +1 -0
  55. package/dist/types/protocol/wire-api.d.ts +1 -0
  56. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  57. package/dist/types/protocol/wire.d.ts +2 -0
  58. package/dist/types/protocol/wire.d.ts.map +1 -1
  59. package/docs/consuming.md +57 -14
  60. package/docs/harnesses.md +14 -7
  61. package/package.json +1 -1
  62. package/src/core/agents/acp/acp-agent.ts +3 -1
  63. package/src/core/agents/acp/profile.ts +6 -0
  64. package/src/core/agents/claude-code/claude-agent.ts +2 -13
  65. package/src/core/agents/claude-code/options.ts +1 -1
  66. package/src/core/agents/claude-code/session.ts +12 -8
  67. package/src/core/agents/claude-code/turn.ts +7 -2
  68. package/src/core/agents/gemini/profile.ts +2 -1
  69. package/src/core/runtime/event-processor.ts +14 -9
  70. package/src/operator/errors.ts +12 -4
  71. package/src/operator/index.ts +1 -1
  72. package/src/operator/operator.ts +508 -152
  73. package/src/operator/render.ts +32 -15
  74. package/src/operator/session-tools.ts +9 -12
  75. package/src/operator/types.ts +81 -16
  76. package/src/operator/view.ts +26 -9
  77. package/src/protocol/config.ts +4 -2
  78. package/src/protocol/conversation.ts +2 -0
  79. package/src/protocol/lifecycle.ts +2 -0
  80. package/src/protocol/part-input.ts +2 -5
  81. package/src/protocol/reduce.ts +2 -0
  82. package/src/protocol/text-parts.ts +10 -0
@@ -10,6 +10,7 @@ import type { ElicitationOutcome, PermissionOutcome } from "../protocol/lifecycl
10
10
  import type { Origin, ReportedOrigin } from "../protocol/origin.ts";
11
11
  import type { Part, UnknownPart } from "../protocol/parts.ts";
12
12
  import { PLAN_OPTION_IDS } from "../protocol/plan.ts";
13
+ import { joinTextParts } from "../protocol/text-parts.ts";
13
14
  import type { Hint } from "./errors.ts";
14
15
  import type { SessionView, ViewTurn, Waiting } from "./types.ts";
15
16
  import type { DecisionRequest, ViewMessage } from "./view.ts";
@@ -43,6 +44,12 @@ export function oneLine(text: string): string {
43
44
  return text.replace(BREAKS, " ").replace(CONTROLS, "").replace(/\s+/g, " ").trim();
44
45
  }
45
46
 
47
+ /** Each distinct line the host gives about the session or its settled turn. */
48
+ export function noteLines(...notes: (string | undefined)[]): string {
49
+ const lines = new Set(notes.map((note) => oneLine(note ?? "")).filter(Boolean));
50
+ return Array.from(lines, (note) => `\nnote: ${note}`).join("");
51
+ }
52
+
46
53
  /** Untrusted text as a block: each of its lines carried after `QUOTE`. */
47
54
  export function quote(text: string): string {
48
55
  return QUOTE + text.replace(CONTROLS, "").replace(BREAKS, `\n${QUOTE}`);
@@ -54,11 +61,6 @@ export const quoted = (text: string) => JSON.stringify(oneLine(text));
54
61
  /** A label, then the untrusted text as a quoted block under it. */
55
62
  const block = (label: string, text: string) => `${label}\n${quote(text)}`;
56
63
 
57
- const textOf = (parts: readonly (Part | UnknownPart)[]) =>
58
- parts
59
- .flatMap((part) => (part.type === "text" && "text" in part ? [String(part.text)] : []))
60
- .join("");
61
-
62
64
  /**
63
65
  * The next step, as the tool call that takes it:
64
66
  * `-> answer_request(session: "voyager", answer: "<your answer>")`.
@@ -368,7 +370,7 @@ function lastReply(messages: readonly ViewMessage[], newer: number) {
368
370
  const message = messages[i];
369
371
  if (message?.role !== "assistant") break;
370
372
  if (message.nested) continue;
371
- const text = textOf(message.parts);
373
+ const text = joinTextParts(message.parts);
372
374
  if (text.trim()) return { text, last: newer + messages.length - i };
373
375
  }
374
376
  }
@@ -386,6 +388,12 @@ const STATUS_WORDS: Record<string, string> = {
386
388
  archived: "archived",
387
389
  };
388
390
 
391
+ function unreadLine(steers: ViewTurn["steers"]): string | undefined {
392
+ const unread = steers && Object.values(steers).filter((s) => s === "undelivered").length;
393
+ if (unread === 1) return "1 message sent into this turn was never read.";
394
+ if (unread) return `${unread} messages sent into this turn were never read.`;
395
+ }
396
+
389
397
  /** How the waits and outcomes word a view; `waited` is how long the call waited. */
390
398
  export interface OutcomeContext extends WaitingContext {
391
399
  waited?: number;
@@ -412,7 +420,8 @@ export function renderOutcome(view: SessionView, context: OutcomeContext): strin
412
420
  context.waited ? `still running after ${context.waited}s` : "",
413
421
  ].filter(Boolean);
414
422
  const next = hint("wait_for_sessions", { sessions: [ref] });
415
- return `status: working${detail.length ? ` (${detail.join("; ")})` : ""}${next ? `\n ${next}` : ""}`;
423
+ const status = `status: working${detail.length ? ` (${detail.join("; ")})` : ""}`;
424
+ return status + noteLines(view.note) + (next ? `\n ${next}` : "");
416
425
  }
417
426
  const messages = messagesOf(view);
418
427
  const fresh = view.status === "idle" && !messages.length;
@@ -428,12 +437,16 @@ export function renderOutcome(view: SessionView, context: OutcomeContext): strin
428
437
  const failed = view.turns.at(-1)?.error;
429
438
  lines.push(block("error:", failed ?? "the turn failed"));
430
439
  }
431
- if (context.note) lines.push(oneLine(context.note));
432
- if (view.status === "error") {
433
- const read = hint("read_session", { session: ref });
434
- if (read) lines.push(` ${read}`);
435
- }
436
- return lines.join("\n");
440
+ const ended = view.lastEnded ?? view.turns.at(-1);
441
+ const unread =
442
+ !view.running &&
443
+ view.status !== "needs_input" &&
444
+ ended &&
445
+ unreadLine(ended.steers ?? view.turns.find((turn) => turn.turnId === ended.turnId)?.steers);
446
+ if (unread) lines.push(unread);
447
+ const outcome = lines.join("\n") + noteLines(context.note, view.note);
448
+ const read = view.status === "error" && hint("read_session", { session: ref });
449
+ return outcome + (read ? `\n ${read}` : "");
437
450
  }
438
451
 
439
452
  /** Who a user message is from, as `read_session` labels it; `you` is the caller's own origin. */
@@ -501,7 +514,7 @@ export function renderConversation(view: SessionView, options: RenderOptions): s
501
514
  const working = view.status === "working" || view.status === "needs_input";
502
515
  for (const { turn, messages } of shownTurns) {
503
516
  for (const message of messages) {
504
- const text = textOf(message.parts);
517
+ const text = joinTextParts(message.parts);
505
518
  if (message.role === "user") {
506
519
  lines.push(
507
520
  messageBlock(
@@ -533,9 +546,13 @@ export function renderConversation(view: SessionView, options: RenderOptions): s
533
546
  }
534
547
  const end = endOf(turn, you);
535
548
  if (end) lines.push(end);
549
+ const unread = unreadLine(
550
+ turn.steers ?? (view.lastEnded?.turnId === turn.turnId ? view.lastEnded.steers : undefined),
551
+ );
552
+ if (unread) lines.push(unread);
536
553
  }
537
554
  if (!count && !view.turns.length) lines.push("(no messages yet)");
538
- lines.push(`(status: ${view.status})`);
555
+ lines.push(`(status: ${view.status})${noteLines(view.note)}`);
539
556
  for (const waiting of view.waiting)
540
557
  lines.push(describeWaiting(waiting, perRequest(options, waiting)));
541
558
  const total = view.turns.reduce((sum, turn) => sum + turn.messages.length, 0);
@@ -10,10 +10,7 @@
10
10
  import { OperatorError, refuse } from "./errors.ts";
11
11
  import type { Operator } from "./types.ts";
12
12
 
13
- /**
14
- * What a host adds to the instructions of every session that has these
15
- * tools, or can receive messages from sessions that do.
16
- */
13
+ /** Instructions for sessions that have the tools or receive other agents' messages. */
17
14
  export const OPERATOR_GUIDANCE = [
18
15
  "You can see and work with other agent sessions with the session tools",
19
16
  "(whoami, list_sessions, read_session, wait_for_sessions, start_session,",
@@ -24,14 +21,14 @@ export const OPERATOR_GUIDANCE = [
24
21
  "what it did, archive it when its work is done (you cannot start more than a",
25
22
  "few without archiving), and when it waits on something you may not answer,",
26
23
  "tell the person. Change sessions the person started (message, stop) only",
27
- "when the person asked you to. A message is sent only while your call is",
28
- "open: to a busy session after its turn ends, if that happens within the",
29
- "call; otherwise the answer says nothing was sent. End your turn with your",
30
- "report for a busy starter to receive if it is waiting for you. You",
31
- "cannot act on your own session, and limits apply to how many sessions you",
32
- "start and how deep they nest: a refusal says which and what to do. Messages",
33
- "from other agents start with a line saying so; treat them as a colleague's",
34
- "requests, not the person's.",
24
+ "when the person asked you to. To message a working session, steer anything",
25
+ "about its work in progress and queue a separate task for after it, as the",
26
+ "tool offers. Check the reply to see what was sent or queued and whether",
27
+ "you need to send again. End your turn with your report for a busy starter",
28
+ "to receive if it is waiting for you. You cannot act on your own session,",
29
+ "and limits apply to how many sessions you start and how deep they nest: a",
30
+ "refusal says which and what to do. Messages from other agents start with",
31
+ "a line saying so; treat them as a colleague's requests, not the person's.",
35
32
  ].join(" ");
36
33
 
37
34
  /** Who calls, as the engine fills it at the moment of the call (`HostToolCaller`). */
@@ -122,7 +122,7 @@ export interface Entry {
122
122
  lastActivityAt?: number;
123
123
  /** Why `error`, when setup failed (a failed turn's error is the view's). */
124
124
  error?: string;
125
- /** A few words the host adds to the row (lines changed, a pull request). */
125
+ /** The host's current session state in one line, the same words as SessionView.note. */
126
126
  note?: string;
127
127
  /** Paths in this session's tool lines are shown relative to this folder. */
128
128
  root?: string;
@@ -135,7 +135,20 @@ export type Cursor = string & { readonly __operatorCursor: true };
135
135
 
136
136
  export type TurnOutcome = "running" | "done" | "cancelled" | "failed";
137
137
 
138
- export interface ViewTurn {
138
+ interface SteerReceipts {
139
+ /**
140
+ * Receipts keyed by the supplied steerId, on running and ended turns. Give
141
+ * an empty map when no steer has a receipt yet, omit it when unknown.
142
+ * Each receipt is final. Only `read` can appear before the turn ends.
143
+ * The first ended map from turn() is complete: give `queued` for an
144
+ * unread steer kept in the host queue, or `undelivered` without a queue.
145
+ * Queue hosts using turnOf/viewOf replace the fold's `undelivered`
146
+ * in turn(), view rows and lastEnded before notifying onChange.
147
+ */
148
+ steers?: Readonly<Record<string, "read" | "undelivered" | "queued">>;
149
+ }
150
+
151
+ export interface ViewTurn extends SteerReceipts {
139
152
  turnId: string;
140
153
  outcome: TurnOutcome;
141
154
  /** Who stopped it, when the host knows (`cancelled`). */
@@ -158,7 +171,7 @@ export type Waiting =
158
171
  | { kind: "plan" | "permission"; request: DecisionRequest };
159
172
 
160
173
  /** How a turn ended, by its id, whatever page of the transcript is read. */
161
- export interface TurnEnded {
174
+ export interface TurnEnded extends SteerReceipts {
162
175
  turnId: string;
163
176
  outcome: "done" | "cancelled" | "failed";
164
177
  /** Who stopped it, when the host knows. */
@@ -167,12 +180,14 @@ export interface TurnEnded {
167
180
 
168
181
  /** One turn, looked up by id. */
169
182
  export type TurnFact =
170
- | { state: "running" }
183
+ | ({ state: "running" } & SteerReceipts)
171
184
  | ({ state: "ended" } & Omit<TurnEnded, "turnId">)
172
185
  | { state: "unknown" };
173
186
 
174
187
  export interface SessionView {
175
188
  status: SessionStatus;
189
+ /** The host's current state line, as on Entry.note (for example, how many tasks wait and why). */
190
+ note?: string;
176
191
  /** The running turn's id, if one runs: independent of `turns`' page. */
177
192
  running?: string;
178
193
  /** The last turn that ended, and how: independent of `turns`' page. */
@@ -225,6 +240,13 @@ export interface SendInput {
225
240
  origin: Origin;
226
241
  }
227
242
 
243
+ export interface SteerInput extends Pick<SendInput, "message" | "origin"> {
244
+ /** The turn the host reported running. */
245
+ turnId: string;
246
+ /** Minted for this message and reused when retrying it in the same turn. */
247
+ steerId: string;
248
+ }
249
+
228
250
  /**
229
251
  * What a cancel did: the turn stopped (it has ended: a host whose stop is
230
252
  * asynchronous waits for the end, briefly, before saying so), there was none,
@@ -235,6 +257,15 @@ export type CancelOutcome = "stopped" | "not_running" | "unconfirmed" | "first_t
235
257
 
236
258
  export type ArchiveTarget = { kind: "session"; id: string } | { kind: "workspace"; id: string };
237
259
 
260
+ /** Whether a new session can run on this agent, as the host last saw it. */
261
+ export interface AgentEntry {
262
+ harness: AgentHarness;
263
+ /** Open: a state this build does not know reads as unknown. */
264
+ state: "ready" | "not_installed" | "signed_out" | "unknown" | (string & {});
265
+ /** The host's words on what to do, or why it could not tell. */
266
+ detail?: string;
267
+ }
268
+
238
269
  export interface ModelEntry {
239
270
  harness: AgentHarness;
240
271
  id: string;
@@ -355,13 +386,41 @@ export interface OperatorHost<Auth = unknown> {
355
386
  view(caller: Caller<Auth>, sessionId: string, options: ViewOptions): Promise<SessionView>;
356
387
  /**
357
388
  * Start the turn `input.turnId` now, carrying `origin` to the wire. The
358
- * same turn id again converges on the first (the engine's rule). A host
359
- * that finds the session busy refuses `busy` (an `OperatorError`, or
360
- * `Refused`), any other definite refusal is one of those too, and a
361
- * failure whose outcome is unknown throws a plain error: the package tries
362
- * again with the same turn id.
389
+ * same turn id again converges on the first (the engine's rule). Throw
390
+ * `new Refused({ code: "busy" })` for a bare busy. A `busy` with `detail`,
391
+ * `retryAfter`, `state` or `sessions` is a host refusal. An `OperatorError`
392
+ * supplies the host's own refusal. If the outcome is unknown, throw a
393
+ * plain error so the package tries again with the same turn id.
363
394
  */
364
395
  send(caller: Caller<Auth>, sessionId: string, input: SendInput): Promise<void>;
396
+ /**
397
+ * Pass input.steerId to the engine for exactly input.turnId. A repeat of
398
+ * that id and input converges on the first dispatch, as for send. Report
399
+ * each receipt through turn() once known. It is final, and the first
400
+ * ended map is complete. A host with queue keeps an unread steer as
401
+ * its own turn. Before onChange, replace the fold's `undelivered` with
402
+ * `queued` in turn(), view rows and lastEnded. The host can also answer
403
+ * `queued` here if the named turn cannot take the steer. Without queue,
404
+ * an unread steer ends with its turn.
405
+ * Throw Refused with the host's reason for a definite refusal.
406
+ */
407
+ steer?(
408
+ caller: Caller<Auth>,
409
+ sessionId: string,
410
+ input: SteerInput,
411
+ ): Promise<{
412
+ outcome: "accepted" | "queued" | "no_active_turn" | "unsupported";
413
+ }>;
414
+ /**
415
+ * Take every queue send, even when the session is idle or stopped.
416
+ * If it starts at once, the view names input.turnId in running or,
417
+ * if it has already finished, in lastEnded.turnId.
418
+ * Keep the task as turn input.turnId. A repeated input.turnId converges
419
+ * while the host still knows it. Return its position if known.
420
+ * The host owns delivery and can refuse a full queue with busy or
421
+ * limit_resources. As for send, a lost answer gets one retry.
422
+ */
423
+ queue?(caller: Caller<Auth>, sessionId: string, input: SendInput): Promise<{ position?: number }>;
365
424
  /** One turn by id: running, ended (how, and by whom when stopped), or unknown. */
366
425
  turn(caller: Caller<Auth>, sessionId: string, turnId: string): Promise<TurnFact>;
367
426
  /**
@@ -410,10 +469,12 @@ export interface OperatorHost<Auth = unknown> {
410
469
  archive?(caller: Caller<Auth>, target: ArchiveTarget): Promise<{ note?: string }>;
411
470
  /** The models a new session can run. Enables `list_models`. */
412
471
  models?(caller: Caller<Auth>): Promise<ModelEntry[]>;
472
+ /** The agents this caller can choose, including those without models. Enables `list_models`. */
473
+ agents?(caller: Caller<Auth>): Promise<AgentEntry[]>;
413
474
  /**
414
475
  * Whether this outside caller may run this tool now, read from the host's
415
476
  * store at the call: asked before every tool and again just before every
416
- * write the package makes (each send, cancel, answer, start, archive). The tool's
477
+ * write the package makes (each send, steer, queue, cancel, answer, start, archive). The tool's
417
478
  * name lets a host allow one write tool to a low-access caller.
418
479
  */
419
480
  authorize?(
@@ -426,7 +487,7 @@ export interface OperatorHost<Auth = unknown> {
426
487
  admit?(caller: Caller<Auth>, request: AdmitRequest): Promise<Refusal | undefined>;
427
488
  /** One line of host facts once a turn settles ("changes: a.ts (+4 -0)"). */
428
489
  outcome?(caller: Caller<Auth>, entry: Entry): Promise<string | undefined>;
429
- /** One line `whoami` adds for this caller ("access: read"). */
490
+ /** One line `whoami` adds as a note for this caller ("access: read"). */
430
491
  describe?(caller: Caller<Auth>): Promise<string | undefined>;
431
492
  }
432
493
 
@@ -435,7 +496,11 @@ export interface OperatorHost<Auth = unknown> {
435
496
  /**
436
497
  * A tool the host adds beside the package's. It declares only its effect;
437
498
  * the package applies plan mode and `authorize` (with its name) to it and
438
- * nothing else. It may not change sessions: that is the package's tools'.
499
+ * nothing else. It may not start, message, stop or archive sessions: those
500
+ * are the package's tools'. It may manage what the host itself holds for
501
+ * a session, such as its queue. A tool that releases, reorders or removes
502
+ * queued work enforces the self and person-session rules itself. It
503
+ * declares `destructive` when it removes tasks.
439
504
  */
440
505
  export interface ExtraTool<Auth = unknown> {
441
506
  name: string;
@@ -488,10 +553,10 @@ export interface OperatorOptions<Auth = unknown> {
488
553
  extra?: ExtraTool<Auth>[];
489
554
  clock?: OperatorClock;
490
555
  /**
491
- * Shown each unexpected failure a call answers without (a `refused (failed)`,
492
- * an outcome that could not be read), once, with the tool and the caller:
493
- * for the host's reports. Never a refusal. It cannot change the answer,
494
- * and a throw inside it is swallowed.
556
+ * Receives each unexpected failure once per call, with the tool and caller.
557
+ * This includes failed send attempts and writes that reject after the call
558
+ * has answered. Refusals, caller abort reasons (even when wrapped) and the
559
+ * call's own deadline are silent. A throw or rejection in the hook is swallowed.
495
560
  */
496
561
  onError?: (error: unknown, tool: string, caller: Caller<Auth>) => void;
497
562
  }
@@ -7,8 +7,10 @@
7
7
 
8
8
  import {
9
9
  type ConversationElicitation,
10
+ type ConversationMessage,
10
11
  type ConversationPermission,
11
12
  type ConversationState,
13
+ type ConversationTurn,
12
14
  conversationMessages,
13
15
  pendingElicitations,
14
16
  pendingPermissions,
@@ -62,14 +64,28 @@ export function viewOf(state: ConversationState): SessionView {
62
64
  return viewWithFacts(state);
63
65
  }
64
66
 
67
+ function steersOf(turn: ConversationTurn, messages: readonly ConversationMessage[]) {
68
+ const receipts: [string, "read" | "undelivered"][] = [];
69
+ for (const message of messages)
70
+ if (message.role === "user" && message.steerId !== undefined)
71
+ receipts.push([message.steerId, "read"]);
72
+ for (const id of turn.undeliveredSteers ?? []) receipts.push([id, "undelivered"]);
73
+ return Object.fromEntries(receipts);
74
+ }
75
+
65
76
  /** One turn of a folded state, by id: the host's `turn`, for a host that folds. */
66
77
  export function turnOf(state: ConversationState, turnId: string): TurnFact {
67
78
  const turn = state.turns.find((t) => t.turnId === turnId);
68
79
  if (!turn) return { state: "unknown" };
69
- if (turn.status === "active") return { state: "running" };
80
+ const steers = steersOf(
81
+ turn,
82
+ conversationMessages(state).filter((m) => m.turnId === turnId),
83
+ );
84
+ if (turn.status === "active") return { state: "running", steers };
70
85
  return {
71
86
  state: "ended",
72
87
  outcome: turn.error ? "failed" : turn.stopReason === "cancelled" ? "cancelled" : "done",
88
+ steers,
73
89
  };
74
90
  }
75
91
 
@@ -88,18 +104,18 @@ function viewWithFacts(state: ConversationState): SessionView {
88
104
  : turn.stopReason === "cancelled"
89
105
  ? "cancelled"
90
106
  : "done";
107
+ const mine = messages.filter((message) => message.turnId === turn.turnId);
91
108
  return {
92
109
  turnId: turn.turnId,
93
110
  outcome,
111
+ steers: steersOf(turn, mine),
94
112
  ...(turn.error ? { error: turn.error.message } : {}),
95
- messages: messages
96
- .filter((message) => message.turnId === turn.turnId)
97
- .map((message) => ({
98
- role: message.role,
99
- parts: message.parts,
100
- ...(message.parentToolCallId ? { nested: true } : {}),
101
- ...(message.origin ? { origin: message.origin } : {}),
102
- })),
113
+ messages: mine.map((message) => ({
114
+ role: message.role,
115
+ parts: message.parts,
116
+ ...(message.parentToolCallId ? { nested: true } : {}),
117
+ ...(message.origin ? { origin: message.origin } : {}),
118
+ })),
103
119
  startedAt: turn.startedAt,
104
120
  ...(turn.endedAt !== undefined ? { endedAt: turn.endedAt } : {}),
105
121
  };
@@ -126,6 +142,7 @@ function viewWithFacts(state: ConversationState): SessionView {
126
142
  lastEnded: {
127
143
  turnId: ended.turnId,
128
144
  outcome: ended.outcome as "done" | "cancelled" | "failed",
145
+ steers: ended.steers,
129
146
  },
130
147
  }
131
148
  : {}),
@@ -6,8 +6,10 @@ import { ThinkingLevelSchema } from "./thinking.ts";
6
6
  import { openVocabulary } from "./vocabulary.ts";
7
7
 
8
8
  /**
9
- * Permission posture for a turn. `bypass_permissions` auto-approves every
10
- * tool (the right default inside a sandbox); `plan` is read-only planning;
9
+ * Permission posture for a turn. In `bypass_permissions` the engine allows every call it is
10
+ * asked about and starts Claude, Codex and Gemini with their own sandbox off; another ACP
11
+ * agent's is its own (LLP 0001, D4). This is the right default inside a product's own
12
+ * sandbox. `plan` is read-only planning;
11
13
  * `dont_ask` never prompts — unapproved tools are denied, sandboxes stay at
12
14
  * their normal (non-dangerous) level. Values are snake_case (LLP 0002, Casing);
13
15
  * adapters map to provider vocabulary at the edge (Claude SDK: acceptEdits,
@@ -42,6 +42,8 @@ export const ConversationMessageSchema = z.object({
42
42
  model: z.string().optional(),
43
43
  /** A user message's sender when it is not the person (`message.started`'s `origin`). */
44
44
  origin: ReportedOriginSchema.optional(),
45
+ /** A steer's read receipt, from its user message's `message.started`. */
46
+ steerId: z.string().optional(),
45
47
  parts: z.array(z.union([PartSchema, UnknownPartSchema])),
46
48
  startedAt: EpochMsSchema,
47
49
  endedAt: EpochMsSchema.optional(),
@@ -285,6 +285,8 @@ export const MessageStartedEventSchema = z.object({
285
285
  * messages and on every assistant message.
286
286
  */
287
287
  origin: ReportedOriginSchema.optional(),
288
+ /** On a steer's user echo, the id of the steer the agent read. Absent on older streams. */
289
+ steerId: z.string().optional(),
288
290
  ...stamped,
289
291
  });
290
292
  export type MessageStartedEvent = z.infer<typeof MessageStartedEventSchema>;
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { joinTextParts } from "./text-parts.ts";
2
3
 
3
4
  /**
4
5
  * A UI-authored span over the text (mentions, pills, inline references) that
@@ -100,9 +101,5 @@ export function parseAgentInput(value: unknown): AgentInput {
100
101
 
101
102
  /** Collapse an AgentInput down to the text the model sees first. */
102
103
  export function inputToText(input: AgentInput): string {
103
- if (typeof input === "string") return input;
104
- return input
105
- .filter((p): p is TextPartInput => p.type === "text")
106
- .map((p) => p.text)
107
- .join("\n\n");
104
+ return typeof input === "string" ? input : joinTextParts(input);
108
105
  }
@@ -120,6 +120,7 @@ function openMessage(
120
120
  parentToolCallId?: string;
121
121
  model?: string;
122
122
  origin?: ReportedOrigin;
123
+ steerId?: string;
123
124
  },
124
125
  record: ChangeRecorder,
125
126
  ): ConversationState {
@@ -142,6 +143,7 @@ function openMessage(
142
143
  ...(init.role === "assistant" && init.model !== undefined && { model: init.model }),
143
144
  // Who sent a user message, when not the person; never on the agent's own.
144
145
  ...(init.role === "user" && init.origin !== undefined && { origin: init.origin }),
146
+ ...(init.role === "user" && init.steerId !== undefined && { steerId: init.steerId }),
145
147
  parts: [],
146
148
  startedAt: init.timestamp,
147
149
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A part boundary can fall inside a sentence (an ACP thought or tool call
3
+ * between two chunks, a mention in an input). It then shows as a break with
4
+ * no words lost: nothing on the stream tells it from two passages.
5
+ */
6
+ export function joinTextParts(parts: readonly { type: string; text?: string }[]): string {
7
+ return parts
8
+ .flatMap((part) => (part.type === "text" && part.text ? [part.text] : []))
9
+ .join("\n\n");
10
+ }