@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.
- package/CHANGELOG.md +59 -0
- package/dist/core/agents/acp/acp-agent.js +3 -1
- package/dist/core/agents/claude-code/claude-agent.js +2 -12
- package/dist/core/agents/claude-code/session.js +12 -8
- package/dist/core/agents/claude-code/turn.js +6 -2
- package/dist/core/agents/gemini/profile.js +2 -1
- package/dist/core/runtime/event-processor.js +9 -10
- package/dist/operator/errors.js +9 -2
- package/dist/operator/index.js +1 -1
- package/dist/operator/operator.js +403 -152
- package/dist/operator/render.js +31 -15
- package/dist/operator/session-tools.js +9 -12
- package/dist/operator/view.js +16 -4
- package/dist/protocol/config.js +4 -2
- package/dist/protocol/conversation.js +2 -0
- package/dist/protocol/lifecycle.js +2 -0
- package/dist/protocol/part-input.js +2 -6
- package/dist/protocol/reduce.js +1 -0
- package/dist/protocol/text-parts.js +10 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/profile.d.ts +6 -1
- package/dist/types/core/agents/acp/profile.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/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 +4 -6
- package/dist/types/core/agents/claude-code/session.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/gemini/profile.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/operator/errors.d.ts +3 -1
- package/dist/types/operator/errors.d.ts.map +1 -1
- package/dist/types/operator/index.d.ts +1 -1
- package/dist/types/operator/index.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +2 -0
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/operator/session-tools.d.ts +1 -4
- package/dist/types/operator/session-tools.d.ts.map +1 -1
- package/dist/types/operator/types.d.ts +77 -17
- package/dist/types/operator/types.d.ts.map +1 -1
- package/dist/types/operator/view.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +4 -2
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +3 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +2 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/part-input.d.ts.map +1 -1
- package/dist/types/protocol/reduce.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 +1 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +2 -0
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/docs/consuming.md +57 -14
- package/docs/harnesses.md +14 -7
- package/package.json +1 -1
- package/src/core/agents/acp/acp-agent.ts +3 -1
- package/src/core/agents/acp/profile.ts +6 -0
- package/src/core/agents/claude-code/claude-agent.ts +2 -13
- package/src/core/agents/claude-code/options.ts +1 -1
- package/src/core/agents/claude-code/session.ts +12 -8
- package/src/core/agents/claude-code/turn.ts +7 -2
- package/src/core/agents/gemini/profile.ts +2 -1
- package/src/core/runtime/event-processor.ts +14 -9
- package/src/operator/errors.ts +12 -4
- package/src/operator/index.ts +1 -1
- package/src/operator/operator.ts +508 -152
- package/src/operator/render.ts +32 -15
- package/src/operator/session-tools.ts +9 -12
- package/src/operator/types.ts +81 -16
- package/src/operator/view.ts +26 -9
- package/src/protocol/config.ts +4 -2
- package/src/protocol/conversation.ts +2 -0
- package/src/protocol/lifecycle.ts +2 -0
- package/src/protocol/part-input.ts +2 -5
- package/src/protocol/reduce.ts +2 -0
- package/src/protocol/text-parts.ts +10 -0
package/docs/harnesses.md
CHANGED
|
@@ -320,7 +320,7 @@ ends "(not applied: …)" is a case a harness finds as the turn runs, named in
|
|
|
320
320
|
| `systemPromptAppend` | applied, appended to Claude Code's system prompt | another meaning: a developer message (`developerInstructions`) | applied once, at `session/new` (`_meta.antigravity.systemPrompt.append`); a later different one: not applied: `systemPromptAppend` | ignored: ACP v1 has no system prompt | ignored: `echo: "config"` says it |
|
|
321
321
|
| `maxTurns` | applied (unset is 100) | ignored | ignored | ignored | ignored |
|
|
322
322
|
| `subagentMode` | applied | another meaning: Codex's `multi_agent` on, an instruction to collect every sub-agent, a native cleanup at the end | refused | refused | refused |
|
|
323
|
-
| `permissionMode` | applied (SDK modes) | another meaning: a sandbox and an approval policy (the table below) | another meaning: Antigravity's modes, `auto` for `bypass_permissions`, its `default` for `dont_ask` (the table below) | applied: the agent's own mode for it (`session/set_mode`; `default` when the turn names none), else its `default` with the engine answering its requests by the mode; `plan` there, or any mode on an agent with no `default`, is not applied (`permissionMode`) | ignored: the script says which calls ask (`ask: true`); `echo: "config"` says it |
|
|
323
|
+
| `permissionMode` | applied (SDK modes) | another meaning: a sandbox and an approval policy (the table below) | another meaning: Antigravity's modes, `auto` with `--dangerously-skip-permissions` for `bypass_permissions`, its `default` for `dont_ask` (the table below) | applied: the agent's own mode for it (`session/set_mode`; `default` when the turn names none), else its `default` with the engine answering its requests by the mode; `plan` there, or any mode on an agent with no `default`, is not applied (`permissionMode`) | ignored: the script says which calls ask (`ask: true`); `echo: "config"` says it |
|
|
324
324
|
| `elicitation` | applied | applied | applied: the agent's form and URL requests | applied: the agent's form and URL requests (ACP v1 has no question tool) | applied: an `ask` step asks the person, else the agent is told no one can answer |
|
|
325
325
|
| `requestTimeoutMs` | the engine | the engine | the engine | the engine | the engine |
|
|
326
326
|
| `resumeSessionId` | applied | applied (`thread/resume`) | applied (`session/resume`) | the agent's: `session/resume`, else `session/load`; refused for an agent with neither | applied: reported as the native id, resumed |
|
|
@@ -419,20 +419,27 @@ other:
|
|
|
419
419
|
`default`, `gpt-6-luna` did not retry: no request came, and no tool part
|
|
420
420
|
reached the stream.
|
|
421
421
|
|
|
422
|
-
The `gemini`
|
|
423
|
-
|
|
424
|
-
|
|
422
|
+
The `gemini` modes were measured through the engine on Antigravity 1.5.13
|
|
423
|
+
on 2026-11-21. On that build, `auto` alone still asked for an MCP call and
|
|
424
|
+
the engine allowed it. The full-access row below was measured with the
|
|
425
|
+
start flag on 1.5.14 on 2026-11-24 (LLP 0020.000, Modes). Gemini is
|
|
426
|
+
not in the `permission-modes` scenario's tables. The `full-access` scenario
|
|
427
|
+
checks its worktree commit, network access and write outside the worktree.
|
|
425
428
|
|
|
426
429
|
| Engine mode | Antigravity's | A write in the folder | A command | An MCP tool |
|
|
427
430
|
| --- | --- | --- | --- | --- |
|
|
428
431
|
| `default` | `default` | asks | asks | asks |
|
|
429
432
|
| `accept_edits` | `accept-edits` | runs | asks | asks |
|
|
430
433
|
| `plan` | `plan` | writes a plan file and stops, asking nothing | not run | not run |
|
|
431
|
-
| `bypass_permissions` | `auto` | runs | runs
|
|
434
|
+
| `bypass_permissions` | `auto` with `--dangerously-skip-permissions` | runs | runs outside the terminal sandbox | runs unasked |
|
|
432
435
|
| `dont_ask` | `default` | refused by the engine | refused by the engine | refused by the engine |
|
|
433
436
|
|
|
434
|
-
A later turn in another mode carries a plan out
|
|
435
|
-
|
|
437
|
+
A later turn in another mode carries a plan out. Switching into or out of
|
|
438
|
+
`bypass_permissions` resumes the conversation in a new agy process, ending
|
|
439
|
+
commands left in the background. With `enableTerminalSandbox` unset, an
|
|
440
|
+
approved command ran outside the terminal sandbox in `default` and
|
|
441
|
+
`accept_edits`. In `default`, enabling the setting sandboxed the approved
|
|
442
|
+
command.
|
|
436
443
|
|
|
437
444
|
## Model lists
|
|
438
445
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zvada/agent-server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
4
4
|
"description": "Harness-agnostic agent execution engine: run Claude Code, Codex (app-server), and any ACP agent behind one interface with a normalized event stream, multi-turn sessions, and resume. Root export is the wire contract; /core, /server, /client are the seats.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -319,7 +319,9 @@ export class ProfiledAcpAgent extends SessionAgent {
|
|
|
319
319
|
signal: AbortSignal,
|
|
320
320
|
): Promise<AcpSession> {
|
|
321
321
|
// A cancel ends the wait: the operator's resolution goes on for the next turn.
|
|
322
|
-
const
|
|
322
|
+
const base = await launchOf(this.profile, signal);
|
|
323
|
+
const modeArgs = this.profile.modeArgs?.[options.permissionMode ?? "default"];
|
|
324
|
+
const launch = modeArgs ? { ...base, args: [...(base.args ?? []), ...modeArgs] } : base;
|
|
323
325
|
|
|
324
326
|
const host = await untilAborted(
|
|
325
327
|
Promise.resolve(this.host?.lease(options.sessionId, options.cwd)),
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
AgentCapabilities,
|
|
4
4
|
AgentHarness,
|
|
5
5
|
McpTool,
|
|
6
|
+
PermissionMode,
|
|
6
7
|
RunConfig,
|
|
7
8
|
} from "../../../protocol/index.ts";
|
|
8
9
|
import type { AgentExecuteOptions } from "../base.ts";
|
|
@@ -64,6 +65,11 @@ export interface AcpProfile {
|
|
|
64
65
|
readonly httpMcp?: boolean;
|
|
65
66
|
/** The agent's own id for an engine mode, where its ids name none (`permissionModeOf`). */
|
|
66
67
|
readonly modeIds?: ModeIds;
|
|
68
|
+
/**
|
|
69
|
+
* Appended after the launch's own arguments. A turn in a mode with different
|
|
70
|
+
* arguments gets its own process, which resumes the conversation.
|
|
71
|
+
*/
|
|
72
|
+
readonly modeArgs?: Partial<Record<PermissionMode, readonly string[]>>;
|
|
67
73
|
/**
|
|
68
74
|
* What a new conversation starts with and keeps for its life: `meta(options)`
|
|
69
75
|
* goes with `session/new`, never with a resume or a load. A later turn on
|
|
@@ -33,12 +33,6 @@ import type { ClaudeTurn } from "./turn.ts";
|
|
|
33
33
|
|
|
34
34
|
type ClaudeContent = SDKUserMessage["message"]["content"];
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* How long after a cancel a turn Claude has not ended has its process ended,
|
|
38
|
-
* unless `cancelGraceMs` says otherwise (LLP 0001, D9).
|
|
39
|
-
*/
|
|
40
|
-
const CANCEL_GRACE_MS = 10_000;
|
|
41
|
-
|
|
42
36
|
const CAPABILITIES: AgentCapabilities = {
|
|
43
37
|
multiTurn: true,
|
|
44
38
|
sessionResume: true,
|
|
@@ -125,12 +119,10 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
125
119
|
readonly login: ClaudeCliLogin;
|
|
126
120
|
private readonly pool: ClaudeSessionPool;
|
|
127
121
|
private readonly credentials?: ClaudeCredentials;
|
|
128
|
-
private readonly cancelGraceMs: number;
|
|
129
122
|
private readonly host?: HostToolSessions;
|
|
130
123
|
|
|
131
124
|
constructor(private readonly agentOptions: ClaudeCodeAgentOptions = {}) {
|
|
132
125
|
super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
|
|
133
|
-
this.cancelGraceMs = agentOptions.cancelGraceMs ?? CANCEL_GRACE_MS;
|
|
134
126
|
this.processes = agentOptions.processes ?? sharedNativeProcesses();
|
|
135
127
|
this.host = hostToolSessions(agentOptions.hostTools, this.harness);
|
|
136
128
|
this.pool = claudeSessionPool({ ...agentOptions, processes: this.processes, host: this.host });
|
|
@@ -241,10 +233,7 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
241
233
|
? "steered"
|
|
242
234
|
: "no_active_turn",
|
|
243
235
|
);
|
|
244
|
-
removeInterrupt = onAbort(controller.signal, () =>
|
|
245
|
-
void session.interruptTurn();
|
|
246
|
-
void session.endUnstopped(turn, this.cancelGraceMs);
|
|
247
|
-
});
|
|
236
|
+
removeInterrupt = onAbort(controller.signal, () => void session.cancelTurn(turn));
|
|
248
237
|
const mcpServers = session.mcp.names;
|
|
249
238
|
if (mcpServers.length) yield { type: "agentServer/mcpServers", names: mcpServers };
|
|
250
239
|
let sawOutput = false;
|
|
@@ -352,7 +341,7 @@ export class ClaudeCodeAgent extends SessionAgent {
|
|
|
352
341
|
* before the SDK interrupt lands (the abort-order race that could surface
|
|
353
342
|
* a clean user cancel as `error`/`end_turn`). The SDK interrupt's
|
|
354
343
|
* round-trip confirms the cancel, and so does the turn's end, whoever ended
|
|
355
|
-
* it: Claude, or the grace that ended its process (`
|
|
344
|
+
* it: Claude, or the grace that ended its process (`cancelTurn`). An
|
|
356
345
|
* interrupt that fails while the turn runs is unconfirmed at once.
|
|
357
346
|
*/
|
|
358
347
|
private async interrupt(
|
|
@@ -204,7 +204,7 @@ export type ClaudeSessionExtras = Pick<
|
|
|
204
204
|
|
|
205
205
|
/** What every session of an agent runs with: fixed when the agent is made. */
|
|
206
206
|
export type ClaudeSessionSettings = ClaudeSessionExtras &
|
|
207
|
-
Pick<ClaudeCodeAgentOptions, "idleTimeoutMs" | "cancelConfirmMs"> & {
|
|
207
|
+
Pick<ClaudeCodeAgentOptions, "idleTimeoutMs" | "cancelConfirmMs" | "cancelGraceMs"> & {
|
|
208
208
|
/** The agent's: where its sessions' `claude` processes start. */
|
|
209
209
|
processes: NativeProcesses;
|
|
210
210
|
/** The agent's: its sessions' host tools. */
|
|
@@ -42,6 +42,9 @@ import { notePairedReleases } from "./sdk-pair.ts";
|
|
|
42
42
|
import { ClaudeSpend } from "./spend.ts";
|
|
43
43
|
import { ClaudeTurn, type ClaudeTurnStart } from "./turn.ts";
|
|
44
44
|
|
|
45
|
+
/** How long a cancelled turn has to end before its process is replaced (LLP 0001, D9). */
|
|
46
|
+
const CANCEL_GRACE_MS = 10_000;
|
|
47
|
+
|
|
45
48
|
type SessionState = "starting" | "idle" | "busy" | "terminated";
|
|
46
49
|
type ClaudeContent = SDKUserMessage["message"]["content"];
|
|
47
50
|
|
|
@@ -325,7 +328,7 @@ export class ClaudeSession implements PooledProcess, PooledClient {
|
|
|
325
328
|
}
|
|
326
329
|
this.state = "busy";
|
|
327
330
|
const prompt = this.userMessage(content);
|
|
328
|
-
const turn = new ClaudeTurn(start, prompt.uuid);
|
|
331
|
+
const turn = new ClaudeTurn(start, prompt.uuid, () => void this.cancelTurn(turn));
|
|
329
332
|
this.turn = turn;
|
|
330
333
|
for (const report of this.rejectedWindowReports()) turn.events.push(report);
|
|
331
334
|
this.promptQueue.push(prompt);
|
|
@@ -340,7 +343,7 @@ export class ClaudeSession implements PooledProcess, PooledClient {
|
|
|
340
343
|
* False when no turn takes input.
|
|
341
344
|
*/
|
|
342
345
|
steer(content: ClaudeContent, steerId: string): boolean {
|
|
343
|
-
if (this.state !== "busy" || !this.turn) return false;
|
|
346
|
+
if (this.state !== "busy" || !this.turn || this.turn.cancelled) return false;
|
|
344
347
|
const message = this.userMessage(content);
|
|
345
348
|
this.turn.sendSteer(message.uuid, steerId);
|
|
346
349
|
this.promptQueue.push(message);
|
|
@@ -406,13 +409,14 @@ export class ClaudeSession implements PooledProcess, PooledClient {
|
|
|
406
409
|
|
|
407
410
|
// @ref LLP 0001#d9--the-wire-is-quick-ack-json-rpc-requests-flow-one-way — cancelGraceMs: an agent that has not stopped is ended
|
|
408
411
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* hears `replaced` (`onSessionEnd`); the next turn resumes on a new
|
|
413
|
-
* process. A turn that ended, and any turn after it, is left alone.
|
|
412
|
+
* Interrupt this turn. If Claude still hasn't stopped it at `cancelGraceMs`,
|
|
413
|
+
* end the process. The turn's events end and the next turn resumes on a
|
|
414
|
+
* new process. A request answered after its turn ended stops nothing.
|
|
414
415
|
*/
|
|
415
|
-
async
|
|
416
|
+
async cancelTurn(turn: ClaudeTurn): Promise<void> {
|
|
417
|
+
if (this.turn !== turn) return;
|
|
418
|
+
void this.interruptTurn();
|
|
419
|
+
const graceMs = this.settings.cancelGraceMs ?? CANCEL_GRACE_MS;
|
|
416
420
|
if ((await withTimeout(turn.ended, graceMs)) === undefined && this.turn === turn)
|
|
417
421
|
await this.terminate("replaced");
|
|
418
422
|
}
|
|
@@ -72,7 +72,11 @@ export class ClaudeTurn {
|
|
|
72
72
|
/** Set while Claude is between queries, about to run the unread steers. */
|
|
73
73
|
private watchdog?: ReturnType<typeof setTimeout>;
|
|
74
74
|
|
|
75
|
-
constructor(
|
|
75
|
+
constructor(
|
|
76
|
+
start: ClaudeTurnStart,
|
|
77
|
+
prompt: string,
|
|
78
|
+
private readonly dropUnread: () => void,
|
|
79
|
+
) {
|
|
76
80
|
this.id = start.turnId;
|
|
77
81
|
this.signal = start.signal;
|
|
78
82
|
this.permissions = start.permissions;
|
|
@@ -85,9 +89,10 @@ export class ClaudeTurn {
|
|
|
85
89
|
});
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
/**
|
|
92
|
+
/** Drop unread steers before the SDK's denial lets Claude start their query. */
|
|
89
93
|
cancelByRequest(): void {
|
|
90
94
|
this.stoppedByRequest = true;
|
|
95
|
+
if (this.unread.size) this.dropUnread();
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
/** Whether a cancelled request stopped the turn (Claude interrupts on it). */
|
|
@@ -128,8 +128,9 @@ export function geminiProfile(options: GeminiOptions): AcpProfile {
|
|
|
128
128
|
accept,
|
|
129
129
|
// It takes HTTP servers, though its `initialize` says so only for `--process-per-session`.
|
|
130
130
|
httpMcp: true,
|
|
131
|
-
//
|
|
131
|
+
// Map agy's `auto` back to `bypass_permissions` on the stream. The flag lifts its terminal sandbox.
|
|
132
132
|
modeIds: { bypass_permissions: "auto" },
|
|
133
|
+
modeArgs: { bypass_permissions: ["--dangerously-skip-permissions"] },
|
|
133
134
|
// A system prompt given again on resume is added on top: given once, at the start.
|
|
134
135
|
newSession: {
|
|
135
136
|
settings: ["systemPromptAppend"],
|
|
@@ -132,7 +132,7 @@ export class EventProcessor {
|
|
|
132
132
|
* whole echo instead of reconciling a look-alike against it.
|
|
133
133
|
*/
|
|
134
134
|
*echoUserMessage(input: AgentInput, origin?: Origin): Generator<LifecycleEvent> {
|
|
135
|
-
yield* this.openMessage("user", undefined, echoMessageId(this.turnId),
|
|
135
|
+
yield* this.openMessage("user", undefined, { id: echoMessageId(this.turnId), origin });
|
|
136
136
|
for (const part of createUserEchoParts(input, this.turnId)) {
|
|
137
137
|
yield* this.emitPart(part);
|
|
138
138
|
}
|
|
@@ -149,7 +149,11 @@ export class EventProcessor {
|
|
|
149
149
|
private *echoSteer(steerId: string): Generator<LifecycleEvent> {
|
|
150
150
|
const steer = this.steers.read(steerId);
|
|
151
151
|
if (steer === undefined) return;
|
|
152
|
-
yield* this.openMessage("user", undefined,
|
|
152
|
+
yield* this.openMessage("user", undefined, {
|
|
153
|
+
id: steerMessageId(steerId),
|
|
154
|
+
steerId,
|
|
155
|
+
origin: steer.origin,
|
|
156
|
+
});
|
|
153
157
|
for (const part of createSteerEchoParts(steer.input, steerId)) {
|
|
154
158
|
yield* this.emitPart(part);
|
|
155
159
|
}
|
|
@@ -165,7 +169,7 @@ export class EventProcessor {
|
|
|
165
169
|
// The turn's own messages after it, opened by their parts (after a
|
|
166
170
|
// sub-agent's output cut in), are this model's too.
|
|
167
171
|
if (ev.role === "assistant" && ev.model) this.writtenBy.set("", ev.model);
|
|
168
|
-
yield* this.openMessage(ev.role, undefined,
|
|
172
|
+
yield* this.openMessage(ev.role, undefined, { model: ev.model });
|
|
169
173
|
return;
|
|
170
174
|
case "model": {
|
|
171
175
|
const scope = ev.parentToolCallId ?? "";
|
|
@@ -318,12 +322,12 @@ export class EventProcessor {
|
|
|
318
322
|
private *openMessage(
|
|
319
323
|
role: "assistant" | "user",
|
|
320
324
|
parentToolCallId?: string,
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
origin?: Origin,
|
|
325
|
+
{
|
|
326
|
+
id,
|
|
327
|
+
model,
|
|
328
|
+
origin,
|
|
329
|
+
steerId,
|
|
330
|
+
}: { id?: string; model?: string; origin?: Origin; steerId?: string } = {},
|
|
327
331
|
): Generator<LifecycleEvent, string> {
|
|
328
332
|
if (this.openMessageId) yield* this.closeMessage();
|
|
329
333
|
if (role === "assistant") this.answered = true;
|
|
@@ -355,6 +359,7 @@ export class EventProcessor {
|
|
|
355
359
|
...named,
|
|
356
360
|
// A copy: what a sink does to the event never reaches the request or the model's line.
|
|
357
361
|
...(role === "user" && sender && { origin: { ...sender } }),
|
|
362
|
+
...(steerId !== undefined && { steerId }),
|
|
358
363
|
timestamp: startedAt,
|
|
359
364
|
};
|
|
360
365
|
return messageId;
|
package/src/operator/errors.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// @ref LLP 0019#errors — one sentence per code, and a next call that exists
|
|
8
8
|
|
|
9
|
-
import { json } from "./render.ts";
|
|
9
|
+
import { json, oneLine } from "./render.ts";
|
|
10
10
|
import type { OperatorErrorCode, Refusal } from "./types.ts";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -76,6 +76,15 @@ export class OperatorError extends Error {
|
|
|
76
76
|
export type Hint = (tool: string, args?: Record<string, unknown>) => string | undefined;
|
|
77
77
|
|
|
78
78
|
const NOTHING = "Nothing was done.";
|
|
79
|
+
const NO_ACCESS = `You may not do this here. ${NOTHING}`;
|
|
80
|
+
|
|
81
|
+
/** A host may refuse one read while another source still supplies rows. */
|
|
82
|
+
export function readRefusal({ code, detail, retryAfter }: Refusal): OperatorError {
|
|
83
|
+
const why = code === "access" ? NO_ACCESS : "The host refused this read.";
|
|
84
|
+
const retry = retryAfter === undefined ? "" : ` Try again in ${retryAfter}s.`;
|
|
85
|
+
return new OperatorError(code, why + retry, { detail: oneLine(detail ?? ""), retryAfter });
|
|
86
|
+
}
|
|
87
|
+
|
|
79
88
|
/** Every value a refusal names: one JSON line, nothing raw (a repository's name, a setup's error). */
|
|
80
89
|
const q = (text: string) => json(text);
|
|
81
90
|
const list = (refs: readonly string[]) => refs.map(q).join(", ") || "(none)";
|
|
@@ -112,8 +121,7 @@ export const refuse = {
|
|
|
112
121
|
"read_only",
|
|
113
122
|
`You are in plan mode, so you may only list, read and wait. ${NOTHING} Put this step in your plan.`,
|
|
114
123
|
),
|
|
115
|
-
access: (detail?: string) =>
|
|
116
|
-
new OperatorError("access", `You may not do this here. ${NOTHING}`, { detail }),
|
|
124
|
+
access: (detail?: string) => new OperatorError("access", NO_ACCESS, { detail }),
|
|
117
125
|
notYoursArchive: (ref: string, busy: readonly string[]) =>
|
|
118
126
|
new OperatorError(
|
|
119
127
|
"not_yours",
|
|
@@ -139,7 +147,7 @@ export const refuse = {
|
|
|
139
147
|
hint: Hint,
|
|
140
148
|
ref: string,
|
|
141
149
|
state: "working" | "waiting on an answer" | "being set up",
|
|
142
|
-
undone: "archived" | "started in it" | "sent",
|
|
150
|
+
undone: "archived" | "started in it" | "sent" | "queued",
|
|
143
151
|
) =>
|
|
144
152
|
new OperatorError("busy", `${q(ref)} is ${state}, so nothing was ${undone}.`, {
|
|
145
153
|
next:
|
package/src/operator/index.ts
CHANGED
|
@@ -22,7 +22,7 @@ export {
|
|
|
22
22
|
type SessionToolSource,
|
|
23
23
|
operatorSessionTools,
|
|
24
24
|
} from "./session-tools.ts";
|
|
25
|
-
export { type Answer, callHint, oneLine, quote, quoted } from "./render.ts";
|
|
25
|
+
export { type Answer, callHint, json, oneLine, quote, quoted } from "./render.ts";
|
|
26
26
|
export * from "./types.ts";
|
|
27
27
|
export {
|
|
28
28
|
type DecisionRequest,
|