@zvada/agent-server 0.3.27 → 0.3.30

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 (190) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +6 -4
  3. package/dist/core/agents/acp/account.js +111 -0
  4. package/dist/core/agents/acp/acp-agent.js +249 -158
  5. package/dist/core/agents/acp/adapter.js +103 -34
  6. package/dist/core/agents/acp/client.js +169 -42
  7. package/dist/core/agents/acp/known-agents.js +12 -5
  8. package/dist/core/agents/acp/mappings.js +84 -20
  9. package/dist/core/agents/acp/models.js +59 -0
  10. package/dist/core/agents/acp/profile.js +36 -0
  11. package/dist/core/agents/acp/prompts.js +248 -0
  12. package/dist/core/agents/acp/requests.js +4 -4
  13. package/dist/core/agents/claude-code/claude-agent.js +2 -12
  14. package/dist/core/agents/claude-code/login.js +4 -1
  15. package/dist/core/agents/claude-code/session.js +50 -18
  16. package/dist/core/agents/claude-code/spawn.js +0 -26
  17. package/dist/core/agents/claude-code/turn.js +6 -2
  18. package/dist/core/agents/codex-app-server/client.js +12 -13
  19. package/dist/core/agents/codex-app-server/login.js +4 -1
  20. package/dist/core/agents/gemini/failures.js +133 -0
  21. package/dist/core/agents/gemini/login.js +173 -0
  22. package/dist/core/agents/gemini/profile.js +138 -0
  23. package/dist/core/agents/gemini/tools.js +91 -0
  24. package/dist/core/agents/login.js +8 -6
  25. package/dist/core/agents/stderr-tail.js +5 -2
  26. package/dist/core/presets.js +13 -0
  27. package/dist/core/processes/native-processes.js +23 -1
  28. package/dist/core/provision/install-build.js +70 -26
  29. package/dist/core/provision/pins.js +5 -0
  30. package/dist/core/provision/provisioner.js +39 -16
  31. package/dist/core/provision/releases.js +39 -1
  32. package/dist/core/provision/tools.js +87 -28
  33. package/dist/operator/errors.js +2 -2
  34. package/dist/operator/operator.js +201 -90
  35. package/dist/operator/render.js +34 -28
  36. package/dist/operator/session-tools.js +2 -1
  37. package/dist/protocol/account.js +5 -1
  38. package/dist/protocol/auth.js +5 -1
  39. package/dist/protocol/config.js +4 -2
  40. package/dist/protocol/credentials.js +9 -1
  41. package/dist/protocol/harness.js +9 -1
  42. package/dist/protocol/part-input.js +2 -6
  43. package/dist/protocol/text-parts.js +10 -0
  44. package/dist/server/bin.js +22 -7
  45. package/dist/server/install.js +6 -4
  46. package/dist/types/core/agents/acp/account.d.ts +55 -0
  47. package/dist/types/core/agents/acp/account.d.ts.map +1 -0
  48. package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
  49. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  50. package/dist/types/core/agents/acp/adapter.d.ts +28 -3
  51. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  52. package/dist/types/core/agents/acp/client.d.ts +66 -4
  53. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  54. package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
  55. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
  56. package/dist/types/core/agents/acp/mappings.d.ts +53 -7
  57. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  58. package/dist/types/core/agents/acp/models.d.ts +22 -0
  59. package/dist/types/core/agents/acp/models.d.ts.map +1 -0
  60. package/dist/types/core/agents/acp/profile.d.ts +97 -0
  61. package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
  62. package/dist/types/core/agents/acp/prompts.d.ts +108 -0
  63. package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
  64. package/dist/types/core/agents/acp/requests.d.ts +7 -1
  65. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  66. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -2
  67. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  68. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  69. package/dist/types/core/agents/claude-code/options.d.ts +1 -1
  70. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  71. package/dist/types/core/agents/claude-code/session.d.ts +7 -6
  72. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  73. package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
  74. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
  75. package/dist/types/core/agents/claude-code/turn.d.ts +3 -2
  76. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  77. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  78. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  79. package/dist/types/core/agents/gemini/failures.d.ts +25 -0
  80. package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
  81. package/dist/types/core/agents/gemini/login.d.ts +28 -0
  82. package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
  83. package/dist/types/core/agents/gemini/profile.d.ts +30 -0
  84. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
  85. package/dist/types/core/agents/gemini/tools.d.ts +18 -0
  86. package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
  87. package/dist/types/core/agents/login.d.ts +15 -5
  88. package/dist/types/core/agents/login.d.ts.map +1 -1
  89. package/dist/types/core/agents/stderr-tail.d.ts +1 -1
  90. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
  91. package/dist/types/core/presets.d.ts +2 -2
  92. package/dist/types/core/presets.d.ts.map +1 -1
  93. package/dist/types/core/processes/native-processes.d.ts +6 -0
  94. package/dist/types/core/processes/native-processes.d.ts.map +1 -1
  95. package/dist/types/core/provision/checksums.d.ts +7 -1
  96. package/dist/types/core/provision/checksums.d.ts.map +1 -1
  97. package/dist/types/core/provision/install-build.d.ts +32 -6
  98. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  99. package/dist/types/core/provision/pins.d.ts +4 -0
  100. package/dist/types/core/provision/pins.d.ts.map +1 -1
  101. package/dist/types/core/provision/provisioner.d.ts +18 -7
  102. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  103. package/dist/types/core/provision/releases.d.ts +2 -1
  104. package/dist/types/core/provision/releases.d.ts.map +1 -1
  105. package/dist/types/core/provision/tools.d.ts +36 -7
  106. package/dist/types/core/provision/tools.d.ts.map +1 -1
  107. package/dist/types/operator/errors.d.ts +5 -1
  108. package/dist/types/operator/errors.d.ts.map +1 -1
  109. package/dist/types/operator/operator.d.ts.map +1 -1
  110. package/dist/types/operator/render.d.ts +11 -6
  111. package/dist/types/operator/render.d.ts.map +1 -1
  112. package/dist/types/operator/session-tools.d.ts.map +1 -1
  113. package/dist/types/operator/types.d.ts +5 -4
  114. package/dist/types/operator/types.d.ts.map +1 -1
  115. package/dist/types/protocol/account.d.ts +4 -2
  116. package/dist/types/protocol/account.d.ts.map +1 -1
  117. package/dist/types/protocol/auth.d.ts +10 -7
  118. package/dist/types/protocol/auth.d.ts.map +1 -1
  119. package/dist/types/protocol/clis.d.ts +4 -3
  120. package/dist/types/protocol/clis.d.ts.map +1 -1
  121. package/dist/types/protocol/config.d.ts +6 -2
  122. package/dist/types/protocol/config.d.ts.map +1 -1
  123. package/dist/types/protocol/conversation.d.ts +3 -3
  124. package/dist/types/protocol/credentials.d.ts +8 -0
  125. package/dist/types/protocol/credentials.d.ts.map +1 -1
  126. package/dist/types/protocol/execution.d.ts +1 -1
  127. package/dist/types/protocol/harness.d.ts +5 -2
  128. package/dist/types/protocol/harness.d.ts.map +1 -1
  129. package/dist/types/protocol/lifecycle.d.ts +8 -8
  130. package/dist/types/protocol/models.d.ts +3 -0
  131. package/dist/types/protocol/models.d.ts.map +1 -1
  132. package/dist/types/protocol/part-input.d.ts.map +1 -1
  133. package/dist/types/protocol/text-parts.d.ts +10 -0
  134. package/dist/types/protocol/text-parts.d.ts.map +1 -0
  135. package/dist/types/protocol/wire-api.d.ts +39 -29
  136. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  137. package/dist/types/protocol/wire.d.ts +13 -10
  138. package/dist/types/protocol/wire.d.ts.map +1 -1
  139. package/dist/types/server/install.d.ts +2 -1
  140. package/dist/types/server/install.d.ts.map +1 -1
  141. package/docs/consuming.md +8 -1
  142. package/docs/deploy.md +17 -8
  143. package/docs/harnesses.md +173 -44
  144. package/package.json +1 -1
  145. package/src/core/agents/acp/account.ts +158 -0
  146. package/src/core/agents/acp/acp-agent.ts +290 -178
  147. package/src/core/agents/acp/adapter.ts +126 -35
  148. package/src/core/agents/acp/client.ts +196 -49
  149. package/src/core/agents/acp/known-agents.ts +14 -5
  150. package/src/core/agents/acp/mappings.ts +112 -21
  151. package/src/core/agents/acp/models.ts +72 -0
  152. package/src/core/agents/acp/profile.ts +133 -0
  153. package/src/core/agents/acp/prompts.ts +287 -0
  154. package/src/core/agents/acp/requests.ts +16 -9
  155. package/src/core/agents/claude-code/claude-agent.ts +2 -13
  156. package/src/core/agents/claude-code/login.ts +4 -1
  157. package/src/core/agents/claude-code/options.ts +1 -1
  158. package/src/core/agents/claude-code/session.ts +50 -16
  159. package/src/core/agents/claude-code/spawn.ts +0 -26
  160. package/src/core/agents/claude-code/turn.ts +7 -2
  161. package/src/core/agents/codex-app-server/client.ts +11 -18
  162. package/src/core/agents/codex-app-server/login.ts +4 -5
  163. package/src/core/agents/gemini/failures.ts +148 -0
  164. package/src/core/agents/gemini/login.ts +188 -0
  165. package/src/core/agents/gemini/profile.ts +163 -0
  166. package/src/core/agents/gemini/tools.ts +99 -0
  167. package/src/core/agents/login.ts +14 -8
  168. package/src/core/agents/stderr-tail.ts +5 -2
  169. package/src/core/presets.ts +15 -2
  170. package/src/core/processes/native-processes.ts +32 -1
  171. package/src/core/provision/checksums.ts +12 -2
  172. package/src/core/provision/install-build.ts +122 -55
  173. package/src/core/provision/pins.ts +5 -0
  174. package/src/core/provision/provisioner.ts +62 -27
  175. package/src/core/provision/releases.ts +47 -1
  176. package/src/core/provision/tools.ts +124 -31
  177. package/src/operator/errors.ts +5 -2
  178. package/src/operator/operator.ts +208 -91
  179. package/src/operator/render.ts +61 -33
  180. package/src/operator/session-tools.ts +2 -1
  181. package/src/operator/types.ts +5 -4
  182. package/src/protocol/account.ts +5 -2
  183. package/src/protocol/auth.ts +5 -1
  184. package/src/protocol/config.ts +4 -2
  185. package/src/protocol/credentials.ts +11 -2
  186. package/src/protocol/harness.ts +9 -1
  187. package/src/protocol/part-input.ts +2 -5
  188. package/src/protocol/text-parts.ts +10 -0
  189. package/src/server/bin.ts +20 -6
  190. package/src/server/install.ts +6 -3
@@ -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";
@@ -35,6 +36,8 @@ const UNSAFE_IN_JSON = new RegExp(`${BREAKS.source}|${CONTROLS.source}`, "g");
35
36
 
36
37
  /** The most messages `read_session` reads. */
37
38
  export const MAX_LAST = 100;
39
+ /** A full read fits in one tool result, its continuation included. */
40
+ export const FULL_READ_LIMIT = 20_000;
38
41
 
39
42
  /** Untrusted text as one line: no line breaks or controls, runs of space collapsed. */
40
43
  export function oneLine(text: string): string {
@@ -43,11 +46,7 @@ export function oneLine(text: string): string {
43
46
 
44
47
  /** Untrusted text as a block: each of its lines carried after `QUOTE`. */
45
48
  export function quote(text: string): string {
46
- return text
47
- .replace(CONTROLS, "")
48
- .split(BREAKS)
49
- .map((line) => `${QUOTE}${line}`.trimEnd())
50
- .join("\n");
49
+ return QUOTE + text.replace(CONTROLS, "").replace(BREAKS, `\n${QUOTE}`);
51
50
  }
52
51
 
53
52
  /** Untrusted text named in prose (a session, a project, an option): one JSON-quoted line. */
@@ -56,12 +55,6 @@ export const quoted = (text: string) => JSON.stringify(oneLine(text));
56
55
  /** A label, then the untrusted text as a quoted block under it. */
57
56
  const block = (label: string, text: string) => `${label}\n${quote(text)}`;
58
57
 
59
- const textOf = (parts: readonly (Part | UnknownPart)[]) =>
60
- parts
61
- .flatMap((part) => (part.type === "text" && "text" in part ? [String(part.text)] : []))
62
- .join("")
63
- .trim();
64
-
65
58
  /**
66
59
  * The next step, as the tool call that takes it:
67
60
  * `-> answer_request(session: "voyager", answer: "<your answer>")`.
@@ -83,6 +76,24 @@ export function callHint(tool: string, args: Record<string, unknown> = {}): stri
83
76
  return `-> ${tool}(${named.join(", ")})`;
84
77
  }
85
78
 
79
+ type Selection = { after?: string; last?: number };
80
+
81
+ /** A message preview and, if clipped, a read selecting its full text. */
82
+ function messageBlock(
83
+ label: string,
84
+ text: string,
85
+ limit: number,
86
+ context: WaitingContext,
87
+ selection: Selection,
88
+ ) {
89
+ const shown = block(label, clip(text, limit));
90
+ if (text.length <= limit) return shown;
91
+ if (selection.last !== undefined && selection.last > MAX_LAST)
92
+ return `${shown}\nmessage clipped. This reply is older than the last ${MAX_LAST} messages read_session can select.`;
93
+ const read = context.hint("read_session", { session: context.ref, ...selection, full: true });
94
+ return `${shown}\nmessage clipped.${read ? `\n ${read}` : ""}`;
95
+ }
96
+
86
97
  /** A choice's labels on one line: `options: "USD", "EUR"`. */
87
98
  const optionsLine = (labels: readonly string[]) => `options: ${labels.map(quoted).join(", ")}`;
88
99
 
@@ -347,17 +358,15 @@ export function describeWaiting(waiting: Waiting, context: WaitingContext): stri
347
358
  return `${block(`permission${named}:`, waiting.request.title)}${about}${options(choices)}${allow}${allow ? ` (or answer: "deny")` : ""}`;
348
359
  }
349
360
 
350
- /** The agent's words since the person last spoke. */
351
- export function lastReply(messages: readonly ViewMessage[]): string {
352
- // A loop, not `findLastIndex`: consumers compile this source with their own `lib`.
353
- let lastUser = messages.length - 1;
354
- while (lastUser >= 0 && messages[lastUser]?.role !== "user") lastUser--;
355
- return messages
356
- .slice(lastUser + 1)
357
- .filter((message) => message.role === "assistant" && !message.nested)
358
- .map((message) => textOf(message.parts))
359
- .filter(Boolean)
360
- .join("\n");
361
+ /** The latest top-level reply since the sender spoke, and its position for a full read. */
362
+ function lastReply(messages: readonly ViewMessage[], newer: number) {
363
+ for (let i = messages.length - 1; i >= 0; i--) {
364
+ const message = messages[i];
365
+ if (message?.role !== "assistant") break;
366
+ if (message.nested) continue;
367
+ const text = joinTextParts(message.parts);
368
+ if (text.trim()) return { text, last: newer + messages.length - i };
369
+ }
361
370
  }
362
371
 
363
372
  /** Every message of a view, oldest first. */
@@ -378,6 +387,8 @@ export interface OutcomeContext extends WaitingContext {
378
387
  waited?: number;
379
388
  /** The host's line of facts for a settled turn. */
380
389
  note?: string;
390
+ /** Messages after the turn this outcome follows, when it already has a successor. */
391
+ newer?: number;
381
392
  }
382
393
 
383
394
  /**
@@ -404,8 +415,9 @@ export function renderOutcome(view: SessionView, context: OutcomeContext): strin
404
415
  const lines = [
405
416
  `status: ${fresh ? "idle (no messages yet)" : (STATUS_WORDS[view.status] ?? view.status)}`,
406
417
  ];
407
- const reply = lastReply(messages);
408
- if (reply) lines.push(block("agent said:", clip(reply, 1500)));
418
+ const reply = lastReply(messages, context.newer ?? 0);
419
+ if (reply)
420
+ lines.push(messageBlock("agent said:", reply.text, 1500, context, { last: reply.last }));
409
421
  for (const waiting of view.waiting)
410
422
  lines.push(describeWaiting(waiting, perRequest(context, waiting)));
411
423
  if (view.status === "error") {
@@ -413,7 +425,7 @@ export function renderOutcome(view: SessionView, context: OutcomeContext): strin
413
425
  lines.push(block("error:", failed ?? "the turn failed"));
414
426
  }
415
427
  if (context.note) lines.push(oneLine(context.note));
416
- if (view.status === "error" || reply.length > 1500) {
428
+ if (view.status === "error") {
417
429
  const read = hint("read_session", { session: ref });
418
430
  if (read) lines.push(` ${read}`);
419
431
  }
@@ -456,10 +468,8 @@ function endOf(turn: ViewTurn, you: Origin): string | undefined {
456
468
  return block("— turn failed:", turn.error ?? "the turn failed");
457
469
  }
458
470
 
459
- export interface RenderOptions extends WaitingContext {
460
- /** How many recent messages (default 10); with `all`, every message the host gave (a cursor's page). */
461
- last?: number;
462
- all?: boolean;
471
+ export interface RenderOptions extends WaitingContext, Selection {
472
+ full?: boolean;
463
473
  /** The caller's own origin: its messages read `[you]`. */
464
474
  you: Origin;
465
475
  /** The header line (the session, its id, who started it). */
@@ -474,7 +484,8 @@ export interface RenderOptions extends WaitingContext {
474
484
  export function renderConversation(view: SessionView, options: RenderOptions): string {
475
485
  const { root, you } = options;
476
486
  const lines: string[] = options.header ? [options.header] : [];
477
- const limit = options.all ? Number.POSITIVE_INFINITY : Math.max(1, options.last ?? 10);
487
+ const limit = options.after ? Number.POSITIVE_INFINITY : (options.last ?? 10);
488
+ const selection = options.after ? { after: options.after } : { last: limit };
478
489
  let count = 0;
479
490
  const shownTurns: { turn: ViewTurn; messages: ViewMessage[] }[] = [];
480
491
  for (let t = view.turns.length - 1; t >= 0 && count < limit; t--) {
@@ -486,9 +497,17 @@ export function renderConversation(view: SessionView, options: RenderOptions): s
486
497
  const working = view.status === "working" || view.status === "needs_input";
487
498
  for (const { turn, messages } of shownTurns) {
488
499
  for (const message of messages) {
489
- const text = textOf(message.parts);
500
+ const text = joinTextParts(message.parts);
490
501
  if (message.role === "user") {
491
- lines.push(block(senderLabel(message.origin, you), clip(text, 800)));
502
+ lines.push(
503
+ messageBlock(
504
+ senderLabel(message.origin, you),
505
+ text,
506
+ options.full ? Number.POSITIVE_INFINITY : 800,
507
+ options,
508
+ selection,
509
+ ),
510
+ );
492
511
  continue;
493
512
  }
494
513
  for (const part of message.parts) {
@@ -497,7 +516,16 @@ export function renderConversation(view: SessionView, options: RenderOptions): s
497
516
  lines.push(` · ${line}`);
498
517
  for (const asked of askedLines(part, root)) lines.push(asked.replace(/^/gm, " "));
499
518
  }
500
- if (text) lines.push(block("[agent]", clip(text, 1200)));
519
+ if (text)
520
+ lines.push(
521
+ messageBlock(
522
+ "[agent]",
523
+ text,
524
+ options.full ? Number.POSITIVE_INFINITY : 1200,
525
+ options,
526
+ selection,
527
+ ),
528
+ );
501
529
  }
502
530
  const end = endOf(turn, you);
503
531
  if (end) lines.push(end);
@@ -26,7 +26,8 @@ export const OPERATOR_GUIDANCE = [
26
26
  "tell the person. Change sessions the person started (message, stop) only",
27
27
  "when the person asked you to. A message is sent only while your call is",
28
28
  "open: to a busy session after its turn ends, if that happens within the",
29
- "call; otherwise the answer says nothing was sent, and you call again. You",
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",
30
31
  "cannot act on your own session, and limits apply to how many sessions you",
31
32
  "start and how deep they nest: a refusal says which and what to do. Messages",
32
33
  "from other agents start with a line saying so; treat them as a colleague's",
@@ -404,6 +404,7 @@ export interface OperatorHost<Auth = unknown> {
404
404
  * caller's own included, since a stop must be confirmed first (`busy`; a
405
405
  * member the caller did not start, `not_yours`), a member that started
406
406
  * sessions not archived, lineage included (`has_children`).
407
+ * Check every condition a stop cannot change before answering `busy`.
407
408
  * Enables `archive`.
408
409
  */
409
410
  archive?(caller: Caller<Auth>, target: ArchiveTarget): Promise<{ note?: string }>;
@@ -487,10 +488,10 @@ export interface OperatorOptions<Auth = unknown> {
487
488
  extra?: ExtraTool<Auth>[];
488
489
  clock?: OperatorClock;
489
490
  /**
490
- * Shown each unexpected failure a call answers without (a `refused (failed)`,
491
- * an outcome that could not be read), once, with the tool and the caller:
492
- * for the host's reports. Never a refusal. It cannot change the answer,
493
- * and a throw inside it is swallowed.
491
+ * Receives each unexpected failure once per call, with the tool and caller.
492
+ * This includes failed send attempts and writes that reject after the call
493
+ * has answered. Refusals, caller abort reasons (even when wrapped) and the
494
+ * call's own deadline are silent. A throw or rejection in the hook is swallowed.
494
495
  */
495
496
  onError?: (error: unknown, tool: string, caller: Caller<Auth>) => void;
496
497
  }
@@ -52,16 +52,19 @@ const CLOUDS: Partial<Record<string, string>> = {
52
52
  /**
53
53
  * What to call a login, the same wherever it lives: `Claude Max`, `ChatGPT
54
54
  * Pro`, `Claude subscription` (plan unknown), `OpenAI API key`, `Amazon
55
- * Bedrock`. A plan this table does not know shows as the provider names it.
55
+ * Bedrock`. A subscription whose login names its own plan (`label`) is
56
+ * called that; otherwise the name is made from its plan, and a plan this
57
+ * table does not know shows as the provider names it.
56
58
  */
57
59
  export function accountLabel(
58
60
  harness: string,
59
- login: Pick<HarnessAuth, "credential" | "plan" | "provider">,
61
+ login: Pick<HarnessAuth, "credential" | "plan" | "provider" | "label">,
60
62
  ): string | undefined {
61
63
  if (login.credential === "api_key") return KEYS[harness] ?? "API key";
62
64
  if (login.credential === "cloud")
63
65
  return login.provider && (CLOUDS[login.provider] ?? login.provider);
64
66
  if (login.credential !== "subscription") return undefined;
67
+ if (login.label) return login.label;
65
68
  const names = PLANS[harness];
66
69
  if (!names) return login.plan;
67
70
  const plan = login.plan && (names.plans[login.plan] ?? login.plan);
@@ -96,7 +96,11 @@ export const HarnessAuthSchema = AccountInfoSchema.extend({
96
96
  state: openVocabulary(AUTH_STATES),
97
97
  credential: openVocabulary(AUTH_CREDENTIALS).optional(),
98
98
  source: openVocabulary(AUTH_SOURCES).optional(),
99
- /** What to show for it (`Claude Max`, `ChatGPT Pro`, `OpenAI API key`): `accountLabel`. */
99
+ /**
100
+ * What to show for it (`Claude Max`, `ChatGPT Pro`, `OpenAI API key`):
101
+ * `accountLabel`, which keeps the name a subscription's login gives its
102
+ * own plan, where it gives one, and otherwise makes one from its plan.
103
+ */
100
104
  label: z.string().optional(),
101
105
  /** When the credential stops working (epoch ms), where known. */
102
106
  expiresAt: z.number().int().optional(),
@@ -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,
@@ -60,6 +60,15 @@ const RUNS_ON = {
60
60
  "codex-app-server": CodexCredentialSchema,
61
61
  } as const;
62
62
 
63
+ /**
64
+ * Whether a product can hold a login for `harness`: it runs on a credential
65
+ * the product hands each turn (LLP 0012). One that runs only on its CLI's own
66
+ * sign-in, or on none (ACP, scripted), cannot.
67
+ */
68
+ export function takesHeldCredential(harness: string): harness is keyof HarnessCredentials {
69
+ return Object.hasOwn(RUNS_ON, harness);
70
+ }
71
+
63
72
  /**
64
73
  * The credential as the kind `harness` runs on, or why that harness cannot
65
74
  * run it. Any harness may be asked, one only known at run time too: one that
@@ -77,9 +86,9 @@ export function credentialRunsOn(
77
86
  harness: AgentHarness,
78
87
  credential: HarnessCredential,
79
88
  ): { ok: true; credential: HarnessCredential } | { ok: false; error: string } {
80
- if (!Object.hasOwn(RUNS_ON, harness))
89
+ if (!takesHeldCredential(harness))
81
90
  return { ok: false, error: `${harness} runs on no credential a product holds.` };
82
- const parsed = RUNS_ON[harness as keyof HarnessCredentials].safeParse(credential);
91
+ const parsed = RUNS_ON[harness].safeParse(credential);
83
92
  if (parsed.success) return { ok: true, credential: parsed.data };
84
93
  const what =
85
94
  credential.type === "api_key" && credential.baseUrl
@@ -5,13 +5,21 @@ import { openVocabulary } from "./vocabulary.ts";
5
5
  * The agent harnesses this engine can drive:
6
6
  * - `claude-code` — Claude Code via @anthropic-ai/claude-agent-sdk (CLI under the hood)
7
7
  * - `codex-app-server` — OpenAI Codex via `codex app-server` (long-lived JSON-RPC subprocess)
8
+ * - `gemini` — Gemini models via Google's Antigravity CLI (`agy acp`, an ACP agent),
9
+ * on the person's own Antigravity sign-in
8
10
  * - `acp` — any Agent Client Protocol v1 agent subprocess (`gemini --acp`,
9
11
  * `claude-code-acp`, `codex-acp`, ACP registry agents); the launch
10
12
  * command is operator-configured, never taken from the wire
11
13
  * - `scripted` — a script the operator gives plays the agent (a product's
12
14
  * free test double); registered only with its script
13
15
  */
14
- export const AGENT_HARNESSES = ["claude-code", "codex-app-server", "acp", "scripted"] as const;
16
+ export const AGENT_HARNESSES = [
17
+ "claude-code",
18
+ "codex-app-server",
19
+ "gemini",
20
+ "acp",
21
+ "scripted",
22
+ ] as const;
15
23
  export type AgentHarness = (typeof AGENT_HARNESSES)[number];
16
24
  export const AgentHarnessSchema = z.enum(AGENT_HARNESSES);
17
25
 
@@ -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
  }
@@ -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
+ }
package/src/server/bin.ts CHANGED
@@ -22,6 +22,7 @@ import { homedir } from "node:os";
22
22
  import { join } from "node:path";
23
23
  import pkg from "../../package.json" with { type: "json" };
24
24
  import {
25
+ CLI_TOOLS,
25
26
  type CredentialSource,
26
27
  type InheritConfig,
27
28
  type ProvisionMode,
@@ -33,6 +34,7 @@ import {
33
34
  resolveHarnessName,
34
35
  scriptedFile,
35
36
  } from "../core/index.ts";
37
+ import { CLI_TOOL_SPECS } from "../core/provision/tools.ts";
36
38
  import { THINKING_LEVELS, type ThinkingLevel } from "../protocol/index.ts";
37
39
  import { AgentServer } from "./agent-server.ts";
38
40
  import { runFeedbackCommand } from "./feedback.ts";
@@ -111,7 +113,7 @@ function usage(exitCode: number): never {
111
113
  " --dial <ws-url> dial out to a consumer (auto-reconnect); its credential:",
112
114
  " $AGENT_SERVER_DIAL_TOKEN, never argv or the URL",
113
115
  " --harness <a,b> restrict harnesses (default: all installed)",
114
- " --acp-agent <spec> ACP agent: known name (pi|gemini) or launch command",
116
+ " --acp-agent <spec> ACP agent: known name (pi|gemini-cli) or launch command",
115
117
  " --script <file> the scripted harness plays this JSONL script, one step a",
116
118
  " line (its only harness unless --harness names others);",
117
119
  " one turn plays at a time, from the start at each start",
@@ -131,7 +133,7 @@ function usage(exitCode: number): never {
131
133
  "env: AGENT_SERVER_TOKEN (the listener's token, if no --token-file),",
132
134
  " AGENT_SERVER_DIAL_TOKEN (what --dial presents: Authorization: Bearer),",
133
135
  " AGENT_SERVER_CREDENTIALS_TOKEN (what --credentials-url presents),",
134
- " CLAUDE_CLI_PATH / CODEX_CLI_PATH (explicit binaries),",
136
+ ` ${CLI_TOOLS.map((tool) => CLI_TOOL_SPECS[tool].overrideEnv).join(" / ")} (explicit binaries),`,
135
137
  " AGENT_SERVER_PROVISION, AGENT_SERVER_CACHE_DIR, AGENT_SERVER_NPM_REGISTRY,",
136
138
  " AGENT_SERVER_BUNDLE_DIR (folders `install --dir` staged, a path list),",
137
139
  " AGENT_SERVER_ACP_SESSION_DIR (--acp: where resumable session ids are kept)",
@@ -216,7 +218,7 @@ function parseArgs(argv: string[]): Args {
216
218
  else if (arg === "--acp-agent") {
217
219
  const spec = inline ?? argv[++i];
218
220
  if (spec === undefined || !spec.trim() || spec.startsWith("-"))
219
- fail("--acp-agent needs a known agent name (pi, gemini) or a launch command");
221
+ fail("--acp-agent needs a known agent name (pi, gemini-cli) or a launch command");
220
222
  args.acpAgent = spec;
221
223
  } else if (arg === "--script") {
222
224
  args.script = next();
@@ -366,7 +368,7 @@ const credential = args.command === "serve" && args.mode === "dial" ? dialToken(
366
368
  const named = args.harnesses?.map((h) => {
367
369
  const choice = resolveHarnessName(h);
368
370
  if (!choice) fail(`unknown harness: ${h}`);
369
- // Friendly ACP agent names ("pi", "gemini") ride the acp harness.
371
+ // Friendly ACP agent names ("pi", "gemini-cli") ride the acp harness.
370
372
  if (choice.acpAgent) args.acpAgent ??= choice.acpAgent;
371
373
  return choice.harness;
372
374
  });
@@ -381,10 +383,22 @@ if (args.command !== "install" && named?.includes("scripted") && args.script ===
381
383
  fail("the scripted harness needs a script: --script <file>");
382
384
  const harnesses = named ?? (args.script !== undefined ? ["scripted" as const] : undefined);
383
385
  const provision = args.provisionMode ? { mode: args.provisionMode } : {};
384
- const acpLaunch = resolveAcpLaunch(args.acpAgent ?? process.env.AGENT_SERVER_ACP_AGENT);
386
+ // The ACP agent setting is read only where the acp harness runs: named, or,
387
+ // with no --harness, turned on by the setting itself. A stale
388
+ // `$AGENT_SERVER_ACP_AGENT` stops no other harness, nor `install`.
389
+ const acpSpec = args.acpAgent ?? process.env.AGENT_SERVER_ACP_AGENT;
390
+ const acpInUse = args.command !== "install" && (harnesses ? harnesses.includes("acp") : !!acpSpec);
391
+ const acpLaunch = (() => {
392
+ if (!acpInUse) return undefined;
393
+ try {
394
+ return resolveAcpLaunch(acpSpec);
395
+ } catch (error) {
396
+ return fail((error as Error).message);
397
+ }
398
+ })();
385
399
  // `install` runs no agent: an acp harness there has nothing to install, and says so.
386
400
  if (args.command !== "install" && harnesses?.includes("acp") && !acpLaunch)
387
- fail('the acp harness needs an agent: --harness pi|gemini or --acp-agent "<spec>"');
401
+ fail('the acp harness needs an agent: --harness pi|gemini-cli or --acp-agent "<spec>"');
388
402
 
389
403
  if (args.command === "install") {
390
404
  // A harness the engine installs nothing for is said, not passed over in silence.
@@ -92,12 +92,15 @@ function claudeCodeVersion(version: string): string | undefined {
92
92
  /**
93
93
  * The line `install` prints for a CLI it installed, saying what its version
94
94
  * is: Claude's is the Claude SDK package's (`0.3.288`), which carries a
95
- * Claude Code of its own number (`2.1.288`), the one `claude --version` says.
95
+ * Claude Code of its own number (`2.1.288`), the one `claude --version` says;
96
+ * every other tool's is its CLI's own.
96
97
  */
97
98
  export function installedLine({ tool, platform, cli }: InstallResult): string {
98
99
  const where = `for ${platform} ready: ${cli.path} (${cli.source})`;
99
- if (tool === "codex") return `codex: Codex CLI ${cli.version ?? "(version not known)"} ${where}`;
100
- if (!cli.version) return `claude: Claude Code (version not known) ${where}`;
100
+ const { title } = CLI_TOOL_SPECS[tool];
101
+ if (tool !== "claude")
102
+ return `${tool}: ${title} ${cli.version ?? "(version not known)"} ${where}`;
103
+ if (!cli.version) return `claude: ${title} (version not known) ${where}`;
101
104
  const code = claudeCodeVersion(cli.version);
102
105
  return `claude: Claude SDK package ${cli.version}${code ? ` (Claude Code ${code})` : ""} ${where}`;
103
106
  }