@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
package/CHANGELOG.md CHANGED
@@ -7,6 +7,65 @@ and the measurements. Evidence lives in the LLP, not here. A release groups
7
7
  its bullets under Breaking, Added, Changed and Fixed, breaking first. The
8
8
  released sections below that predate this convention are kept as written.
9
9
 
10
+ ## 0.3.31
11
+
12
+ ### Breaking
13
+
14
+ - `send_message` defaults to `steer` where offered and to `queue` elsewhere. Replace
15
+ `when: "idle"` with `when: "queue"`. On a host without `steer`, only the name changes;
16
+ a caller that sends `idle` is refused `invalid_input` (LLP 0019).
17
+
18
+ ### Added
19
+
20
+ - `OperatorHost.steer` takes `SteerInput` and answers `accepted`, `queued`, `no_active_turn`
21
+ or `unsupported`. Senders learn whether their message was read, is pending, was kept in
22
+ the queue, or never reached the agent (LLP 0019).
23
+ - `OperatorHost.queue` takes a separate task even when the session is idle or stopped.
24
+ A host with `queue` must keep unread steers as separate tasks and report `queued` in
25
+ the first ended turn facts (LLP 0019).
26
+ - `message.started.steerId` survives the fold as `ConversationMessage.steerId`. The
27
+ `steers` map on `ViewTurn`, `TurnEnded` and `TurnFact` carries receipts by id.
28
+ `viewOf` and `turnOf` give the fold's `read` and `undelivered` ids (LLP 0002, LLP 0019).
29
+ - `OperatorHost.agents` supplies `AgentEntry` readiness and detail for `list_models`.
30
+ Agents with an empty model list are shown too (LLP 0019).
31
+ - Host tools can import `json` from `@zvada/agent-server/operator` to render values
32
+ losslessly on one line (LLP 0014, LLP 0019).
33
+
34
+ ### Changed
35
+
36
+ - `send_message` and `OPERATOR_GUIDANCE` explain when to steer and when to queue.
37
+ A queue send that starts at once follows its own turn. Refused sends retain the
38
+ host's reason (LLP 0019).
39
+ - `SessionView.note` carries the same state as `Entry.note` into reads, waits and send
40
+ replies. Standalone `describe` and `outcome` lines also begin with `note: ` (LLP 0019).
41
+ - Reads and waits report how many messages sent into a turn were never read. Steers
42
+ kept in the host's queue do not count (LLP 0019).
43
+ - If one `list_models` source fails, the other source's rows remain and the failed
44
+ read is reported once after them (LLP 0019).
45
+
46
+ ## 0.3.30
47
+
48
+ ### Fixed
49
+
50
+ - Dismissing a Claude tool or plan approval ends the turn `cancelled`. Steers Claude has not
51
+ read are returned in `turn.ended.undeliveredSteers` and never run later. Dismissing a question
52
+ still lets the turn continue (LLP 0001, D4 and D13).
53
+ - Operator `onError` receives unexpected write errors, including failed send attempts and
54
+ writes that reject after the call has answered. A write whose outcome is unknown still
55
+ answers `not confirmed` (LLP 0019, Errors).
56
+ - When workspace setup fails before its first task, `start_session` reports the host's
57
+ reason in its own answer (LLP 0019, One call, one message).
58
+ - Session reads and wait replies put a blank line between non-empty text parts (LLP 0019).
59
+
60
+ ## 0.3.29
61
+
62
+ ### Changed
63
+
64
+ - In `bypass_permissions`, Gemini runs outside Antigravity's terminal sandbox, as Claude and Codex do:
65
+ network, git in a worktree, writes outside the folder. A product that relied on that sandbox supplies
66
+ its own: in `default` an approved command is not sandboxed either, unless the person set
67
+ `enableTerminalSandbox`. A switch into or out of the mode restarts agy and resumes (LLP 0020).
68
+
10
69
  ## 0.3.28
11
70
 
12
71
  ### Changed
@@ -164,7 +164,9 @@ export class ProfiledAcpAgent extends SessionAgent {
164
164
  }
165
165
  async resolveSession(options, signal) {
166
166
  // A cancel ends the wait: the operator's resolution goes on for the next turn.
167
- const launch = await launchOf(this.profile, signal);
167
+ const base = await launchOf(this.profile, signal);
168
+ const modeArgs = this.profile.modeArgs?.[options.permissionMode ?? "default"];
169
+ const launch = modeArgs ? { ...base, args: [...(base.args ?? []), ...modeArgs] } : base;
168
170
  const host = await untilAborted(Promise.resolve(this.host?.lease(options.sessionId, options.cwd)), signal);
169
171
  if (host)
170
172
  refuseHostName(options.mcpServers, host.source.name);
@@ -10,11 +10,6 @@ import { ClaudeCliLogin } from "./login.js";
10
10
  import { claudeModelDescriptors, fitClaudeThinking, readClaudeModels } from "./models.js";
11
11
  import { claudeSessionConfig } from "./options.js";
12
12
  import { claudeSessionPool, } from "./session.js";
13
- /**
14
- * How long after a cancel a turn Claude has not ended has its process ended,
15
- * unless `cancelGraceMs` says otherwise (LLP 0001, D9).
16
- */
17
- const CANCEL_GRACE_MS = 10_000;
18
13
  const CAPABILITIES = {
19
14
  multiTurn: true,
20
15
  sessionResume: true,
@@ -95,12 +90,10 @@ export class ClaudeCodeAgent extends SessionAgent {
95
90
  login;
96
91
  pool;
97
92
  credentials;
98
- cancelGraceMs;
99
93
  host;
100
94
  constructor(agentOptions = {}) {
101
95
  super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
102
96
  this.agentOptions = agentOptions;
103
- this.cancelGraceMs = agentOptions.cancelGraceMs ?? CANCEL_GRACE_MS;
104
97
  this.processes = agentOptions.processes ?? sharedNativeProcesses();
105
98
  this.host = hostToolSessions(agentOptions.hostTools, this.harness);
106
99
  this.pool = claudeSessionPool({ ...agentOptions, processes: this.processes, host: this.host });
@@ -193,10 +186,7 @@ export class ClaudeCodeAgent extends SessionAgent {
193
186
  await this.openSteering(options, (request) => session.steer(toClaudeContent(request.input), request.steerId)
194
187
  ? "steered"
195
188
  : "no_active_turn");
196
- removeInterrupt = onAbort(controller.signal, () => {
197
- void session.interruptTurn();
198
- void session.endUnstopped(turn, this.cancelGraceMs);
199
- });
189
+ removeInterrupt = onAbort(controller.signal, () => void session.cancelTurn(turn));
200
190
  const mcpServers = session.mcp.names;
201
191
  if (mcpServers.length)
202
192
  yield { type: "agentServer/mcpServers", names: mcpServers };
@@ -294,7 +284,7 @@ export class ClaudeCodeAgent extends SessionAgent {
294
284
  * before the SDK interrupt lands (the abort-order race that could surface
295
285
  * a clean user cancel as `error`/`end_turn`). The SDK interrupt's
296
286
  * round-trip confirms the cancel, and so does the turn's end, whoever ended
297
- * it: Claude, or the grace that ended its process (`endUnstopped`). An
287
+ * it: Claude, or the grace that ended its process (`cancelTurn`). An
298
288
  * interrupt that fails while the turn runs is unconfirmed at once.
299
289
  */
300
290
  async interrupt(session, turn, sessionId) {
@@ -12,6 +12,8 @@ import { planUsedUp } from "./outcome.js";
12
12
  import { notePairedReleases } from "./sdk-pair.js";
13
13
  import { ClaudeSpend } from "./spend.js";
14
14
  import { ClaudeTurn } from "./turn.js";
15
+ /** How long a cancelled turn has to end before its process is replaced (LLP 0001, D9). */
16
+ const CANCEL_GRACE_MS = 10_000;
15
17
  /** Claude repeats a message it was sent, where it reads it (`--replay-user-messages`). */
16
18
  function isReplay(event) {
17
19
  return event.type === "user" && "isReplay" in event && event.isReplay === true;
@@ -272,7 +274,7 @@ export class ClaudeSession {
272
274
  }
273
275
  this.state = "busy";
274
276
  const prompt = this.userMessage(content);
275
- const turn = new ClaudeTurn(start, prompt.uuid);
277
+ const turn = new ClaudeTurn(start, prompt.uuid, () => void this.cancelTurn(turn));
276
278
  this.turn = turn;
277
279
  for (const report of this.rejectedWindowReports())
278
280
  turn.events.push(report);
@@ -287,7 +289,7 @@ export class ClaudeSession {
287
289
  * False when no turn takes input.
288
290
  */
289
291
  steer(content, steerId) {
290
- if (this.state !== "busy" || !this.turn)
292
+ if (this.state !== "busy" || !this.turn || this.turn.cancelled)
291
293
  return false;
292
294
  const message = this.userMessage(content);
293
295
  this.turn.sendSteer(message.uuid, steerId);
@@ -354,13 +356,15 @@ export class ClaudeSession {
354
356
  }
355
357
  // @ref LLP 0001#d9--the-wire-is-quick-ack-json-rpc-requests-flow-one-way — cancelGraceMs: an agent that has not stopped is ended
356
358
  /**
357
- * End the process of a cancelled `turn` that has not ended within
358
- * `graceMs`: Claude did not stop it (a frozen or hung CLI), and nothing
359
- * else would. The turn's events end, so it ends cancelled, and the pool
360
- * hears `replaced` (`onSessionEnd`); the next turn resumes on a new
361
- * process. A turn that ended, and any turn after it, is left alone.
359
+ * Interrupt this turn. If Claude still hasn't stopped it at `cancelGraceMs`,
360
+ * end the process. The turn's events end and the next turn resumes on a
361
+ * new process. A request answered after its turn ended stops nothing.
362
362
  */
363
- async endUnstopped(turn, graceMs) {
363
+ async cancelTurn(turn) {
364
+ if (this.turn !== turn)
365
+ return;
366
+ void this.interruptTurn();
367
+ const graceMs = this.settings.cancelGraceMs ?? CANCEL_GRACE_MS;
364
368
  if ((await withTimeout(turn.ended, graceMs)) === undefined && this.turn === turn)
365
369
  await this.terminate("replaced");
366
370
  }
@@ -12,6 +12,7 @@ const STEER_QUERY_TIMEOUT_MS = 60_000;
12
12
  * next turn. Its methods say what the session does next.
13
13
  */
14
14
  export class ClaudeTurn {
15
+ dropUnread;
15
16
  id;
16
17
  signal;
17
18
  permissions;
@@ -47,7 +48,8 @@ export class ClaudeTurn {
47
48
  heldResult = false;
48
49
  /** Set while Claude is between queries, about to run the unread steers. */
49
50
  watchdog;
50
- constructor(start, prompt) {
51
+ constructor(start, prompt, dropUnread) {
52
+ this.dropUnread = dropUnread;
51
53
  this.id = start.turnId;
52
54
  this.signal = start.signal;
53
55
  this.permissions = start.permissions;
@@ -59,9 +61,11 @@ export class ClaudeTurn {
59
61
  this.settleEnded = resolve;
60
62
  });
61
63
  }
62
- /** A request of the turn was answered `cancelled`: Claude stops the turn, which ends cancelled. */
64
+ /** Drop unread steers before the SDK's denial lets Claude start their query. */
63
65
  cancelByRequest() {
64
66
  this.stoppedByRequest = true;
67
+ if (this.unread.size)
68
+ this.dropUnread();
65
69
  }
66
70
  /** Whether a cancelled request stopped the turn (Claude interrupts on it). */
67
71
  get cancelled() {
@@ -107,8 +107,9 @@ export function geminiProfile(options) {
107
107
  accept,
108
108
  // It takes HTTP servers, though its `initialize` says so only for `--process-per-session`.
109
109
  httpMcp: true,
110
- // Its `auto` asks only for MCP calls, which the engine allows in this mode.
110
+ // Map agy's `auto` back to `bypass_permissions` on the stream. The flag lifts its terminal sandbox.
111
111
  modeIds: { bypass_permissions: "auto" },
112
+ modeArgs: { bypass_permissions: ["--dangerously-skip-permissions"] },
112
113
  // A system prompt given again on resume is added on top: given once, at the start.
113
114
  newSession: {
114
115
  settings: ["systemPromptAppend"],
@@ -82,7 +82,7 @@ export class EventProcessor {
82
82
  * whole echo instead of reconciling a look-alike against it.
83
83
  */
84
84
  *echoUserMessage(input, origin) {
85
- yield* this.openMessage("user", undefined, echoMessageId(this.turnId), undefined, origin);
85
+ yield* this.openMessage("user", undefined, { id: echoMessageId(this.turnId), origin });
86
86
  for (const part of createUserEchoParts(input, this.turnId)) {
87
87
  yield* this.emitPart(part);
88
88
  }
@@ -99,7 +99,11 @@ export class EventProcessor {
99
99
  const steer = this.steers.read(steerId);
100
100
  if (steer === undefined)
101
101
  return;
102
- yield* this.openMessage("user", undefined, steerMessageId(steerId), undefined, steer.origin);
102
+ yield* this.openMessage("user", undefined, {
103
+ id: steerMessageId(steerId),
104
+ steerId,
105
+ origin: steer.origin,
106
+ });
103
107
  for (const part of createSteerEchoParts(steer.input, steerId)) {
104
108
  yield* this.emitPart(part);
105
109
  }
@@ -115,7 +119,7 @@ export class EventProcessor {
115
119
  // sub-agent's output cut in), are this model's too.
116
120
  if (ev.role === "assistant" && ev.model)
117
121
  this.writtenBy.set("", ev.model);
118
- yield* this.openMessage(ev.role, undefined, undefined, ev.model);
122
+ yield* this.openMessage(ev.role, undefined, { model: ev.model });
119
123
  return;
120
124
  case "model": {
121
125
  const scope = ev.parentToolCallId ?? "";
@@ -254,13 +258,7 @@ export class EventProcessor {
254
258
  return { events, ended };
255
259
  }
256
260
  /** Opens a message, closing any open one first; returns its id. */
257
- *openMessage(role, parentToolCallId,
258
- /** Derived id for the user echo; harness messages get a fresh UUIDv7. */
259
- id,
260
- /** The model the harness said produced it. */
261
- model,
262
- /** A user message's sender, when not the person. */
263
- origin) {
261
+ *openMessage(role, parentToolCallId, { id, model, origin, steerId, } = {}) {
264
262
  if (this.openMessageId)
265
263
  yield* this.closeMessage();
266
264
  if (role === "assistant")
@@ -293,6 +291,7 @@ export class EventProcessor {
293
291
  ...named,
294
292
  // A copy: what a sink does to the event never reaches the request or the model's line.
295
293
  ...(role === "user" && sender && { origin: { ...sender } }),
294
+ ...(steerId !== undefined && { steerId }),
296
295
  timestamp: startedAt,
297
296
  };
298
297
  return messageId;
@@ -4,7 +4,7 @@
4
4
  * words, then the next call, which names only a tool that is installed.
5
5
  */
6
6
  // @ref LLP 0019#errors — one sentence per code, and a next call that exists
7
- import { json } from "./render.js";
7
+ import { json, oneLine } from "./render.js";
8
8
  /**
9
9
  * A host's refusal at its own commit (`start`, `archive`, `send`): the code
10
10
  * and the sessions it is about, by id; the package words it as its own
@@ -48,6 +48,13 @@ export class OperatorError extends Error {
48
48
  }
49
49
  }
50
50
  const NOTHING = "Nothing was done.";
51
+ const NO_ACCESS = `You may not do this here. ${NOTHING}`;
52
+ /** A host may refuse one read while another source still supplies rows. */
53
+ export function readRefusal({ code, detail, retryAfter }) {
54
+ const why = code === "access" ? NO_ACCESS : "The host refused this read.";
55
+ const retry = retryAfter === undefined ? "" : ` Try again in ${retryAfter}s.`;
56
+ return new OperatorError(code, why + retry, { detail: oneLine(detail ?? ""), retryAfter });
57
+ }
51
58
  /** Every value a refusal names: one JSON line, nothing raw (a repository's name, a setup's error). */
52
59
  const q = (text) => json(text);
53
60
  const list = (refs) => refs.map(q).join(", ") || "(none)";
@@ -64,7 +71,7 @@ export const refuse = {
64
71
  }),
65
72
  self: (what) => new OperatorError("self", `That is your own ${what}: a session cannot send to, stop, answer or archive itself. ${NOTHING}`),
66
73
  readOnly: () => new OperatorError("read_only", `You are in plan mode, so you may only list, read and wait. ${NOTHING} Put this step in your plan.`),
67
- access: (detail) => new OperatorError("access", `You may not do this here. ${NOTHING}`, { detail }),
74
+ access: (detail) => new OperatorError("access", NO_ACCESS, { detail }),
68
75
  notYoursArchive: (ref, busy) => new OperatorError("not_yours", `${q(ref)} has sessions you did not start working or waiting (${list(busy)}). Nothing was archived. Ask the person.`),
69
76
  notYoursAnswer: (ref) => new OperatorError("not_yours", `${q(ref)} was not started by you or a session you started, so its answer is the person's. Nothing was sent. Tell the person what it waits on.`),
70
77
  notYoursPermission: () => new OperatorError("not_yours", "Only a session with full access answers a permission. Nothing was sent. Tell the person."),
@@ -10,6 +10,6 @@ export { createMcpHandler, } from "./mcp.js";
10
10
  export { DEFAULT_LIMITS, DEFAULT_WAITS, createOperator, tool } from "./operator.js";
11
11
  export { refOf } from "./refs.js";
12
12
  export { OPERATOR_GUIDANCE, operatorSessionTools, } from "./session-tools.js";
13
- export { callHint, oneLine, quote, quoted } from "./render.js";
13
+ export { callHint, json, oneLine, quote, quoted } from "./render.js";
14
14
  export * from "./types.js";
15
15
  export { settledStatus, turnOf, viewOf, waitingOf, } from "./view.js";