@ouro.bot/cli 0.1.0-alpha.1290 → 0.1.0-alpha.1291

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.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "_note": "This changelog is maintained as part of the PR/version-bump workflow. Agent-curated, not auto-generated. Agents read this file directly via read_file to understand what changed between versions.",
3
3
  "versions": [
4
+ {
5
+ "version": "0.1.0-alpha.1291",
6
+ "changes": [
7
+ "The replay eval has a provider proxy: inside the sandbox the agent's provider forwards every call to the host, which holds the one real provider and its credentials, takes one budget unit per call, and stops the run on the first 402 or 429 without a retry."
8
+ ]
9
+ },
4
10
  {
5
11
  "version": "0.1.0-alpha.1290",
6
12
  "changes": [
@@ -1,5 +1,5 @@
1
1
  {
2
- "runtimeVersion": "0.1.0-alpha.1290",
2
+ "runtimeVersion": "0.1.0-alpha.1291",
3
3
  "bundleSchemaVersion": 3,
4
4
  "lastUpdated": "2026-09-03T00:00:00.000Z"
5
5
  }
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0"?>
2
2
  <Container version="2">
3
3
  <Name>ouro-butler</Name>
4
- <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1290</Repository>
4
+ <Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1291</Repository>
5
5
  <Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
6
6
  <Network>host</Network>
7
7
  <Shell>sh</Shell>
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStreamChannel = createStreamChannel;
4
+ exports.createProxyRuntime = createProxyRuntime;
5
+ exports.serveProxyRuntime = serveProxyRuntime;
6
+ const runtime_1 = require("../../nerves/runtime");
7
+ /** The callback events a provider streams; anything else on the wire is ignored. */
8
+ const CALLBACK_EVENTS = new Set([
9
+ "onModelStart", "onModelStreamStart", "onTextChunk", "onReasoningChunk", "onToolStart", "onToolEnd", "onError", "onClearText", "onKick",
10
+ ]);
11
+ /** Stops the run, never retried: the budget is spent, or the provider says the account is out of credit or rate-limited. */
12
+ const STOPPING_STATUS = new Set([402, 429]);
13
+ const STOPPING_CLASSIFICATION = new Set(["usage-limit", "rate-limit"]);
14
+ class ProxiedProviderError extends Error {
15
+ classification;
16
+ reason;
17
+ retryable = false;
18
+ constructor(error, cause) {
19
+ super(error.message, { cause });
20
+ this.name = "ProxiedProviderError";
21
+ this.classification = error.classification;
22
+ if (error.status !== undefined)
23
+ this.status = error.status;
24
+ this.reason = error.reason;
25
+ }
26
+ }
27
+ const isObject = (value) => typeof value === "object" && value !== null;
28
+ const isTurn = (value) => Number.isInteger(value);
29
+ /** The shape each message type must have; the guest is untrusted, so anything else never reaches a listener. */
30
+ const SHAPES = {
31
+ hello: () => true,
32
+ capabilities: (msg) => typeof msg.id === "string" && typeof msg.model === "string" && Array.isArray(msg.capabilities),
33
+ streamTurn: (msg) => isTurn(msg.turn) && isObject(msg.request) && Array.isArray(msg.request.messages),
34
+ callback: (msg) => isTurn(msg.turn) && typeof msg.event === "string" && Array.isArray(msg.args),
35
+ turnResult: (msg) => isTurn(msg.turn) && isObject(msg.result),
36
+ appendToolOutput: (msg) => typeof msg.callId === "string" && typeof msg.output === "string",
37
+ resetTurnState: (msg) => Array.isArray(msg.messages),
38
+ error: (msg) => isTurn(msg.turn) && isObject(msg.error) && typeof msg.error.message === "string",
39
+ abort: (msg) => isTurn(msg.turn),
40
+ };
41
+ function isMessage(value) {
42
+ return isObject(value) && typeof value.type === "string" && Object.hasOwn(SHAPES, value.type) && SHAPES[value.type](value);
43
+ }
44
+ function parseLine(line) {
45
+ try {
46
+ const value = JSON.parse(line);
47
+ if (isMessage(value))
48
+ return value;
49
+ }
50
+ catch {
51
+ // Not JSON: reported below like any other line that is not a message.
52
+ }
53
+ return { type: "invalid", reason: `not a proxy message: ${line.slice(0, 80)}` };
54
+ }
55
+ /** Far above any real turn's transcript; past it a line is dropped, so a guest cannot grow the host's buffer without bound. */
56
+ const MAX_LINE_LENGTH = 64 * 1024 * 1024;
57
+ /** Newline-delimited JSON over a pair of byte streams, such as a container's stdin and stdout. */
58
+ function createStreamChannel(input, output, maxLineLength = MAX_LINE_LENGTH) {
59
+ const listeners = [];
60
+ const deliver = (msg) => {
61
+ for (const listener of listeners) {
62
+ try {
63
+ listener(msg);
64
+ }
65
+ catch (caught) {
66
+ // A throw here would escape the stream's data handler and end the process.
67
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.proxy_channel_error", message: "a proxy message handler failed", meta: { type: msg.type, error: caught instanceof Error ? caught.message : String(caught) } });
68
+ }
69
+ }
70
+ };
71
+ const tooLong = { type: "invalid", reason: "line too long" };
72
+ let buffered = "";
73
+ let discarding = false;
74
+ let closed = false;
75
+ input.setEncoding("utf8");
76
+ input.on("data", (chunk) => {
77
+ let text = chunk;
78
+ if (discarding) {
79
+ const newline = text.indexOf("\n");
80
+ if (newline < 0)
81
+ return;
82
+ text = text.slice(newline + 1);
83
+ discarding = false;
84
+ }
85
+ buffered += text;
86
+ const lines = buffered.split("\n");
87
+ buffered = lines.pop();
88
+ for (const line of lines.filter(Boolean))
89
+ deliver(line.length > maxLineLength ? tooLong : parseLine(line));
90
+ if (buffered.length > maxLineLength) {
91
+ buffered = "";
92
+ discarding = true;
93
+ deliver(tooLong);
94
+ }
95
+ });
96
+ const close = () => { if (!closed) {
97
+ closed = true;
98
+ deliver({ type: "closed" });
99
+ } };
100
+ input.on("end", close);
101
+ input.on("close", close);
102
+ input.on("error", (error) => deliver({ type: "invalid", reason: `input failed: ${error.message}` }));
103
+ output.on("error", (error) => deliver({ type: "invalid", reason: `output failed: ${error.message}` }));
104
+ return {
105
+ send: (msg) => { output.write(`${JSON.stringify(msg)}\n`); },
106
+ onMessage: (fn) => { listeners.push(fn); },
107
+ };
108
+ }
109
+ /** Guest side: a runtime whose every call is served by the host. Resolves once the host has said what it is. */
110
+ function createProxyRuntime(channel) {
111
+ const turns = new Map();
112
+ let nextTurn = 1;
113
+ return new Promise((resolveRuntime) => {
114
+ channel.onMessage((msg) => {
115
+ if (msg.type === "capabilities") {
116
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.proxy_runtime_ready", message: "proxy provider runtime is ready", meta: { provider: msg.id, model: msg.model } });
117
+ resolveRuntime({
118
+ id: msg.id,
119
+ model: msg.model,
120
+ client: null,
121
+ capabilities: new Set(msg.capabilities),
122
+ ...(msg.supportedReasoningEfforts ? { supportedReasoningEfforts: msg.supportedReasoningEfforts } : {}),
123
+ streamTurn: (request) => new Promise((resolve, reject) => {
124
+ const turn = nextTurn++;
125
+ const { callbacks, signal, ...wire } = request;
126
+ if (signal?.aborted) {
127
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.proxy_guest_turn_error", message: "proxied turn aborted before it started", meta: { turn, reason: "aborted" } });
128
+ return reject(new ProxiedProviderError({ message: "aborted before the provider call", classification: "unknown", reason: "aborted" }));
129
+ }
130
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.proxy_guest_turn_start", message: "sending a turn to the host provider", meta: { turn } });
131
+ const onAbort = () => channel.send({ type: "abort", turn });
132
+ const settle = () => { turns.delete(turn); signal?.removeEventListener("abort", onAbort); };
133
+ turns.set(turn, {
134
+ request,
135
+ resolve: (result) => { settle(); (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.proxy_guest_turn_end", message: "host provider turn finished", meta: { turn } }); resolve(result); },
136
+ reject: (error) => { settle(); (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.proxy_guest_turn_error", message: "host provider turn failed", meta: { turn, error: error.message } }); reject(error); },
137
+ });
138
+ channel.send({ type: "streamTurn", turn, request: { ...wire, ...(callbacks.settleOutputMode ? { settleOutputMode: callbacks.settleOutputMode } : {}) } });
139
+ signal?.addEventListener("abort", onAbort, { once: true });
140
+ }),
141
+ appendToolOutput: (callId, output) => channel.send({ type: "appendToolOutput", callId, output }),
142
+ resetTurnState: (messages) => channel.send({ type: "resetTurnState", messages }),
143
+ ping: async () => undefined,
144
+ classifyError: (error) => error instanceof ProxiedProviderError ? error.classification : "unknown",
145
+ });
146
+ return;
147
+ }
148
+ if (msg.type === "invalid" || msg.type === "closed") {
149
+ const why = msg.type === "closed" ? "input closed" : msg.reason;
150
+ for (const [turn, pending] of [...turns]) {
151
+ channel.send({ type: "abort", turn });
152
+ pending.reject(new ProxiedProviderError({ message: `proxy channel failed: ${why}`, classification: "unknown", reason: "channel" }));
153
+ }
154
+ return;
155
+ }
156
+ const pending = "turn" in msg ? turns.get(msg.turn) : undefined;
157
+ if (!pending)
158
+ return;
159
+ if (msg.type === "callback" && CALLBACK_EVENTS.has(msg.event)) {
160
+ if (pending.callbackError)
161
+ return;
162
+ const args = msg.event === "onError" ? [new Error(String(msg.args[0])), msg.args[1]] : msg.args;
163
+ try {
164
+ ;
165
+ pending.request.callbacks[msg.event]?.(...args);
166
+ }
167
+ catch (caught) {
168
+ // In-process, a throwing callback fails the turn; here the host is told to stop, and the turn fails with it.
169
+ pending.callbackError = new ProxiedProviderError({ message: caught instanceof Error ? caught.message : String(caught), classification: "unknown", reason: "callback" }, caught);
170
+ channel.send({ type: "abort", turn: msg.turn });
171
+ }
172
+ }
173
+ else if (msg.type === "turnResult") {
174
+ if (pending.callbackError)
175
+ pending.reject(pending.callbackError);
176
+ else
177
+ pending.resolve(msg.result);
178
+ }
179
+ else if (msg.type === "error") {
180
+ pending.reject(pending.callbackError ?? new ProxiedProviderError(msg.error));
181
+ }
182
+ });
183
+ channel.send({ type: "hello" });
184
+ });
185
+ }
186
+ function streamingCallbacks(channel, turn, settleOutputMode) {
187
+ const forward = (event) => (...args) => {
188
+ channel.send({ type: "callback", turn, event, args: event === "onError" ? [args[0] instanceof Error ? args[0].message : String(args[0]), args[1]] : args });
189
+ };
190
+ const callbacks = Object.fromEntries([...CALLBACK_EVENTS].map((event) => [event, forward(event)]));
191
+ return settleOutputMode ? { ...callbacks, settleOutputMode } : callbacks;
192
+ }
193
+ /** Host side: serves one real runtime to the guest, taking one budget unit per turn. */
194
+ function serveProxyRuntime(channel, runtime, budget) {
195
+ const aborts = new Map();
196
+ let stopped;
197
+ channel.onMessage((msg) => {
198
+ if (msg.type === "closed") {
199
+ // The guest has gone away: its turn's call is wasted, so stop it.
200
+ for (const abort of aborts.values())
201
+ abort.abort();
202
+ }
203
+ else if (msg.type === "invalid") {
204
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.proxy_channel_error", message: "ignored a line from the guest that is not a proxy message", meta: { reason: msg.reason } });
205
+ }
206
+ else if (msg.type === "hello") {
207
+ channel.send({
208
+ type: "capabilities", id: runtime.id, model: runtime.model, capabilities: [...runtime.capabilities],
209
+ ...(runtime.supportedReasoningEfforts ? { supportedReasoningEfforts: [...runtime.supportedReasoningEfforts] } : {}),
210
+ });
211
+ }
212
+ else if (msg.type === "appendToolOutput") {
213
+ runtime.appendToolOutput(msg.callId, msg.output);
214
+ }
215
+ else if (msg.type === "resetTurnState") {
216
+ runtime.resetTurnState(msg.messages);
217
+ }
218
+ else if (msg.type === "abort") {
219
+ aborts.get(msg.turn)?.abort();
220
+ }
221
+ else if (msg.type === "streamTurn") {
222
+ void serveTurn(msg.turn, msg.request);
223
+ }
224
+ });
225
+ function refuse(turn, error) {
226
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.proxy_turn_error", message: "proxy turn refused without calling the provider", meta: { turn, reason: error.reason } });
227
+ channel.send({ type: "error", turn, error });
228
+ }
229
+ async function serveTurn(turn, request) {
230
+ if (stopped)
231
+ return refuse(turn, { ...stopped, message: `the provider stopped this run earlier: ${stopped.message}`, reason: "stopped" });
232
+ // One runtime keeps one turn's provider state, so a second turn in flight would corrupt the first.
233
+ if (aborts.size > 0)
234
+ return refuse(turn, { message: "another turn is still in flight", classification: "unknown", reason: "busy" });
235
+ if (!budget.take())
236
+ return refuse(turn, { message: "budget exhausted", classification: "usage-limit", reason: "budget" });
237
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.proxy_turn_start", message: "serving a proxied provider turn", meta: { turn, provider: runtime.id, model: runtime.model } });
238
+ const abort = new AbortController();
239
+ aborts.set(turn, abort);
240
+ try {
241
+ const { settleOutputMode, ...rest } = request;
242
+ const result = await runtime.streamTurn({ ...rest, callbacks: streamingCallbacks(channel, turn, settleOutputMode), signal: abort.signal });
243
+ channel.send({ type: "turnResult", turn, result });
244
+ (0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.proxy_turn_end", message: "proxied provider turn finished", meta: { turn } });
245
+ }
246
+ catch (caught) {
247
+ const error = caught instanceof Error ? caught : new Error(String(caught));
248
+ const classification = runtime.classifyError(error);
249
+ const status = error.status;
250
+ const wire = { message: error.message, classification, reason: "provider", ...(typeof status === "number" ? { status } : {}) };
251
+ if ((typeof status === "number" && STOPPING_STATUS.has(status)) || STOPPING_CLASSIFICATION.has(classification))
252
+ stopped = wire;
253
+ (0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.proxy_turn_error", message: "proxied provider turn failed", meta: { turn, classification, status: wire.status ?? null, stopped: Boolean(stopped) } });
254
+ channel.send({ type: "error", turn, error: wire });
255
+ }
256
+ finally {
257
+ aborts.delete(turn);
258
+ }
259
+ }
260
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1290",
3
+ "version": "0.1.0-alpha.1291",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ouro.bot/cli",
9
- "version": "0.1.0-alpha.1290",
9
+ "version": "0.1.0-alpha.1291",
10
10
  "bundleDependencies": [
11
11
  "@ouro.bot/friends"
12
12
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1290",
3
+ "version": "0.1.0-alpha.1291",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },