@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.
- package/CHANGELOG.md +61 -0
- package/README.md +6 -4
- package/dist/core/agents/acp/account.js +111 -0
- package/dist/core/agents/acp/acp-agent.js +249 -158
- package/dist/core/agents/acp/adapter.js +103 -34
- package/dist/core/agents/acp/client.js +169 -42
- package/dist/core/agents/acp/known-agents.js +12 -5
- package/dist/core/agents/acp/mappings.js +84 -20
- package/dist/core/agents/acp/models.js +59 -0
- package/dist/core/agents/acp/profile.js +36 -0
- package/dist/core/agents/acp/prompts.js +248 -0
- package/dist/core/agents/acp/requests.js +4 -4
- package/dist/core/agents/claude-code/claude-agent.js +2 -12
- package/dist/core/agents/claude-code/login.js +4 -1
- package/dist/core/agents/claude-code/session.js +50 -18
- package/dist/core/agents/claude-code/spawn.js +0 -26
- package/dist/core/agents/claude-code/turn.js +6 -2
- package/dist/core/agents/codex-app-server/client.js +12 -13
- package/dist/core/agents/codex-app-server/login.js +4 -1
- package/dist/core/agents/gemini/failures.js +133 -0
- package/dist/core/agents/gemini/login.js +173 -0
- package/dist/core/agents/gemini/profile.js +138 -0
- package/dist/core/agents/gemini/tools.js +91 -0
- package/dist/core/agents/login.js +8 -6
- package/dist/core/agents/stderr-tail.js +5 -2
- package/dist/core/presets.js +13 -0
- package/dist/core/processes/native-processes.js +23 -1
- package/dist/core/provision/install-build.js +70 -26
- package/dist/core/provision/pins.js +5 -0
- package/dist/core/provision/provisioner.js +39 -16
- package/dist/core/provision/releases.js +39 -1
- package/dist/core/provision/tools.js +87 -28
- package/dist/operator/errors.js +2 -2
- package/dist/operator/operator.js +201 -90
- package/dist/operator/render.js +34 -28
- package/dist/operator/session-tools.js +2 -1
- package/dist/protocol/account.js +5 -1
- package/dist/protocol/auth.js +5 -1
- package/dist/protocol/config.js +4 -2
- package/dist/protocol/credentials.js +9 -1
- package/dist/protocol/harness.js +9 -1
- package/dist/protocol/part-input.js +2 -6
- package/dist/protocol/text-parts.js +10 -0
- package/dist/server/bin.js +22 -7
- package/dist/server/install.js +6 -4
- package/dist/types/core/agents/acp/account.d.ts +55 -0
- package/dist/types/core/agents/acp/account.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts +28 -3
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +66 -4
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +53 -7
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/acp/models.d.ts +22 -0
- package/dist/types/core/agents/acp/models.d.ts.map +1 -0
- package/dist/types/core/agents/acp/profile.d.ts +97 -0
- package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
- package/dist/types/core/agents/acp/prompts.d.ts +108 -0
- package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +7 -1
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -2
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/session.d.ts +7 -6
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/turn.d.ts +3 -2
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/gemini/failures.d.ts +25 -0
- package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/login.d.ts +28 -0
- package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/profile.d.ts +30 -0
- package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
- package/dist/types/core/agents/gemini/tools.d.ts +18 -0
- package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +15 -5
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/stderr-tail.d.ts +1 -1
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +2 -2
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/native-processes.d.ts +6 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -1
- package/dist/types/core/provision/checksums.d.ts +7 -1
- package/dist/types/core/provision/checksums.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +32 -6
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/pins.d.ts +4 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +18 -7
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/releases.d.ts +2 -1
- package/dist/types/core/provision/releases.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +36 -7
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/operator/errors.d.ts +5 -1
- package/dist/types/operator/errors.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +11 -6
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts.map +1 -1
- package/dist/types/operator/types.d.ts +5 -4
- package/dist/types/operator/types.d.ts.map +1 -1
- package/dist/types/protocol/account.d.ts +4 -2
- package/dist/types/protocol/account.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +10 -7
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +4 -3
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +6 -2
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +3 -3
- package/dist/types/protocol/credentials.d.ts +8 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +1 -1
- package/dist/types/protocol/harness.d.ts +5 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +8 -8
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/part-input.d.ts.map +1 -1
- package/dist/types/protocol/text-parts.d.ts +10 -0
- package/dist/types/protocol/text-parts.d.ts.map +1 -0
- package/dist/types/protocol/wire-api.d.ts +39 -29
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +13 -10
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +2 -1
- package/dist/types/server/install.d.ts.map +1 -1
- package/docs/consuming.md +8 -1
- package/docs/deploy.md +17 -8
- package/docs/harnesses.md +173 -44
- package/package.json +1 -1
- package/src/core/agents/acp/account.ts +158 -0
- package/src/core/agents/acp/acp-agent.ts +290 -178
- package/src/core/agents/acp/adapter.ts +126 -35
- package/src/core/agents/acp/client.ts +196 -49
- package/src/core/agents/acp/known-agents.ts +14 -5
- package/src/core/agents/acp/mappings.ts +112 -21
- package/src/core/agents/acp/models.ts +72 -0
- package/src/core/agents/acp/profile.ts +133 -0
- package/src/core/agents/acp/prompts.ts +287 -0
- package/src/core/agents/acp/requests.ts +16 -9
- package/src/core/agents/claude-code/claude-agent.ts +2 -13
- package/src/core/agents/claude-code/login.ts +4 -1
- package/src/core/agents/claude-code/options.ts +1 -1
- package/src/core/agents/claude-code/session.ts +50 -16
- package/src/core/agents/claude-code/spawn.ts +0 -26
- package/src/core/agents/claude-code/turn.ts +7 -2
- package/src/core/agents/codex-app-server/client.ts +11 -18
- package/src/core/agents/codex-app-server/login.ts +4 -5
- package/src/core/agents/gemini/failures.ts +148 -0
- package/src/core/agents/gemini/login.ts +188 -0
- package/src/core/agents/gemini/profile.ts +163 -0
- package/src/core/agents/gemini/tools.ts +99 -0
- package/src/core/agents/login.ts +14 -8
- package/src/core/agents/stderr-tail.ts +5 -2
- package/src/core/presets.ts +15 -2
- package/src/core/processes/native-processes.ts +32 -1
- package/src/core/provision/checksums.ts +12 -2
- package/src/core/provision/install-build.ts +122 -55
- package/src/core/provision/pins.ts +5 -0
- package/src/core/provision/provisioner.ts +62 -27
- package/src/core/provision/releases.ts +47 -1
- package/src/core/provision/tools.ts +124 -31
- package/src/operator/errors.ts +5 -2
- package/src/operator/operator.ts +208 -91
- package/src/operator/render.ts +61 -33
- package/src/operator/session-tools.ts +2 -1
- package/src/operator/types.ts +5 -4
- package/src/protocol/account.ts +5 -2
- package/src/protocol/auth.ts +5 -1
- package/src/protocol/config.ts +4 -2
- package/src/protocol/credentials.ts +11 -2
- package/src/protocol/harness.ts +9 -1
- package/src/protocol/part-input.ts +2 -5
- package/src/protocol/text-parts.ts +10 -0
- package/src/server/bin.ts +20 -6
- package/src/server/install.ts +6 -3
package/src/operator/render.ts
CHANGED
|
@@ -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
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
.
|
|
358
|
-
|
|
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)
|
|
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"
|
|
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
|
-
|
|
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.
|
|
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 =
|
|
500
|
+
const text = joinTextParts(message.parts);
|
|
490
501
|
if (message.role === "user") {
|
|
491
|
-
lines.push(
|
|
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)
|
|
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
|
|
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",
|
package/src/operator/types.ts
CHANGED
|
@@ -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
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
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
|
}
|
package/src/protocol/account.ts
CHANGED
|
@@ -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
|
|
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);
|
package/src/protocol/auth.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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(),
|
package/src/protocol/config.ts
CHANGED
|
@@ -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`
|
|
10
|
-
*
|
|
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 (!
|
|
89
|
+
if (!takesHeldCredential(harness))
|
|
81
90
|
return { ok: false, error: `${harness} runs on no credential a product holds.` };
|
|
82
|
-
const parsed = RUNS_ON[harness
|
|
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
|
package/src/protocol/harness.ts
CHANGED
|
@@ -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 = [
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
package/src/server/install.ts
CHANGED
|
@@ -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
|
-
|
|
100
|
-
if (
|
|
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
|
}
|