@parcha/agentrun-kernel 0.1.0-beta.58 → 0.1.0-beta.60

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 CHANGED
@@ -2,6 +2,34 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.59 (2026-11-25)
6
+
7
+ **Breaking:**
8
+
9
+ - Ollama models run only on a harness that forwards the route, an output schema beside tools on Ollama is refused, and an ACP agent's permission requests for AgentRun's tools are no longer answered from their titles. What to change on upgrade: <!-- changes/b51-breaking.md -->
10
+ - A harness module on Messages or Responses that should keep running Ollama models must forward its model requests with the `fetch` its launch hands it (`ModuleLaunch.fetch`, given to `startModelProxy`'s `fetch`) and set `forwardsRoute: true` in its facts. Without the fact it is offered no Ollama model, and a run of it that names one is refused before it starts, in words that name these two steps.
11
+ - A claude-agent node with an output schema on an Ollama model now stops with a 400 `invalid_request_error`, since the claude-agent harness sends its tools on every turn and Ollama can't hold an answer to a format and also call tools. Drop the schema, or run the node on a model with a key.
12
+ - A recipe for an agent that asks permission before every tool call needs an `allowFile` in a form its agent reads, or the title tie (`quirks.permissionTie: "title"`). Without either, every request for an AgentRun tool goes to the host's gate as the agent's own call, and its runs stop there.
13
+ - An agent's `tool_call` title no longer names the AgentRun tool it calls. A recipe without `announces` (the new field where its agent's `tool_call` names the tool) has every call matched to its MCP call by its arguments alone, a call with no arguments included. A call announced with no input at all is matched to an MCP call that nothing else matches, the oldest first, until the agent reports it ended, so two such calls in flight can trade ids. Declare `announces` to tie each call to its own.
14
+ - Goose's offer promises `tool_gate: "config"` (was `"permission"`): its calls of AgentRun's tools are held by its permission file and the host's gate at the MCP call.
15
+ - `agentrun harness-check` fails `mcp_tool` for an agent that asks permission for `check_echo` on a recipe with neither field. A recipe whose check passed before can fail its next one.
16
+ - `examples/harness-recipe/antigravity.json` declares `announces` and the title tie (`quirks.permissionTie: "title"`), since agy asks permission for every MCP call: its requests for the AgentRun calls it announced are answered allow once, and the host's gate decides at the MCP call. A copy of the recipe made before this release has neither and needs both, or its runs stop at the gate.
17
+ - The exported test helper `fakeAgentRecipe` (`@parcha/agentrun-harness-acp/testing`) now gives its recipe an `allowFile` (style "goose", the default) or the title tie (style "cursor"), and each style's `announces`, as each shipped recipe does. The fake's style "cursor" now announces its MCP calls late, as Cursor 2026.11.13 does (`announce: "early"` for the old shape). A suite that relied on the fake asking for AgentRun's tools and being answered from the title gets neither by default.
18
+
19
+ **Changes:**
20
+
21
+ - A desktop's or a phone's agent can keep what it sees: `computer_screenshot` takes `save_as`, a path relative to the run's folder ending `.png`, and saves the screenshot there through the run's own files, whatever disk the computer has. The answer is the image as before, plus `saved as <path> in the run's files` (and `saved` in its structured value). A path outside the folder, an absolute one or one not ending `.png` is refused in words before the computer is asked. A screenshot with `save_as` is held to `write`'s setting as well as the computer's: `write` set to deny refuses it before the computer is asked, set to ask puts it to a person. `save_as` needs `write` among the agent's tools: an agent not given `write` is not offered `save_as`, and a screenshot with one anyway is refused in words, whatever `write`'s setting says. Nor is it offered with `write` set to deny, or set to ask on a server where no one can approve. <!-- changes/desktop-screenshot-save-as.md -->
22
+ A desktop or a phone the run's folder is not mounted in (one with `exec: false`, or a provider that mounts none) tells its model once in the run, as the server's note, that the computer's own disk is not the run's files and is deleted at the end, and that the file tools and `save_as` keep what the user should get. A run not given `write`, with `write` set to deny, or with it set to ask where no one can approve, is told instead that screenshots can't be saved to the run's files. The note goes after a due cap wrap-up, never ahead of it, and a resumed claim does not tell it again. The note is part of such a run's first request: on a pi desktop run on Sonnet it needs $0.055 through a gateway (from $0.052; its byte bound 10,445 tokens) and $0.031 straight to Anthropic (from $0.030, so the README's first-request figure there is $0.04); the documented $0.09 minimums for the five-step run do not change.
23
+ - A model the runner's route translates onto a harness's wire (this machine's Ollama models on Anthropic's Messages and OpenAI's Responses) is offered only to a harness whose proxy forwards with the route's `fetch`, and the Messages translation no longer drops what it can't run. Before, any harness on the wire was offered those models, including a module that sends its requests to the network, where nothing answers. <!-- changes/b51-route-hints.md -->
24
+ - `AdapterFacts` gains `forwardsRoute`. claude-agent, Goose, codex and opencode set it, and so does every recipe that builds on Goose's facts. A harness without it is offered none of the route's models, takes none as its default, and its words say to add a key ("No model yet for <harness>: add an OpenRouter or Anthropic key"). A run that names one is refused before it starts.
25
+ - An output schema (`output_config.format` of type `json_schema`) on a Messages request with no tools now reaches Ollama as its `format`. Before, it was dropped and the answer came back unconstrained. Beside tools it is refused with a 400 `invalid_request_error` that says to drop the output schema or use a model route that takes tools with a format, because Ollama holds the whole answer to the format and leaves the model no way to call a tool.
26
+ - The Messages translation answers `POST /v1/messages` and `POST /v1/messages/count_tokens` alone. Any other method or path is a 404 `not_found_error` in Anthropic's error shape, and nothing reaches Ollama.
27
+ - `agentrun harness-check` on a model the route translates (`--model ollama/<tag>`) now reaches it. Its recorder wraps the route's own fetch, so the recipe's agent gets the same route a server's run gets and the check still sees every request. Before, every request went to the route's placeholder origin and `mcp_tool` failed.
28
+ - A run's trace no longer costs or carries what it should not. Under `agentrun-serve runner`, where each run is a process of its own, a run's end waited up to 3 s on the collector, since that process flushed its own spans before it exited: now it sends its trace to its runner, which exports it in the background, and a run's process never holds an `OTEL_*` setting at all. The runner reads that trace as untrusted: every string it carries (a provider, a host, a call id, a request's or turn's end, a failure) is cut of every secret the runner holds, or taken only from values the runner knows, and a call's id, its parent's or a route's name longer than 128 characters is kept as its SHA-256, so a run's process can't hold megabytes of ids open in its runner. A name the model wrote no longer reaches a span as written: a call the harness refused (a tool the session does not have; the kernel's `tool_start` event says `refused: true`, which claude-agent now sets) is `execute_tool` with `error.type=tool_refused` and no tool name, a model the run does not know (not a route's model, nor one its price table names by that same id) is named by its route's model, and every name is cut of every secret the runner holds and at 64 characters. Each value of `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_TRACES_HEADERS` of 8 characters or more is now a secret the server and the runner hold, under any header name, an unknown one too, but a `Content-Type`, `Accept`, `Content-Encoding` or `User-Agent` header's value, and a dataset or tenant header's (`x-honeycomb-dataset`, `x-axiom-dataset`, `x-scope-orgid`), which is only cut from the tracer's `[otel]` lines, so a dataset named `production` refuses no source capture. A credential is held without the word before it too, after a known auth scheme (`Bearer`, `Basic`, `Api-Key`, `Api-Token`, `Token`, `sentry`, `Splunk`, `GenieKey`) or under a credential-named header (`authorization`, `x-sentry-auth`, `x-api-key`); any other header's value is held whole, never its tail alone. So are an OTLP endpoint's user, password and each query parameter named like a credential: a word of its name is a credential word or ends in key, token, secret, password, auth, sig, signature or credential (`api_key`, `access_token`, `apiKey`, `accesstoken`, `writekey`; never `authority` or `keyspace`). A comma inside a header value must be written `%2C`. The tracer's own `[otel]` lines, where an exporter's error may quote a header it sent, are cut of each such value at any length, a short one too, and of what follows any header value's first word; everywhere else (the runner's logs, what a run writes, a served run, a source capture) a held value is still cut at 8 characters or more and a shorter header value is on no held list, on purpose, since a needle of a few characters would cut ordinary text, turn a served number such as `1` into `[redacted]`, or refuse a source capture of any project that holds it. <!-- changes/otel-trace-names-and-child-export.md -->
29
+ - A `codemode` script that stops at a call the run refused (a tool set to deny, a person's deny) now reads Refused on the run's Timeline, as the refused call inside it does. Before, the script's own row read as a call that ran and failed, so the console showed a red Error chip on it and a neutral Refused chip on every other refused step. The same holds for `tools_call` of a refused tool. A host tool that `nests` may now answer `refused: true` with its error; pi marks that result refused, and the other harnesses end the call refused. The console's Refused chip on a script says it stopped at a refused call, its calls before that one having run. The script's text, and what the model reads, are unchanged. <!-- changes/script-refused-reads-refused.md -->
30
+ - A capped run stopped while a model request was out on a provider served through its own route (one that does not speak Anthropic's Messages API) now counts that request as a stop, at what streamed plus the stop's 1,024-token allowance, never at the whole of what its cap held for it. <!-- changes/stop-counts-what-streamed.md -->
31
+ - A model request whose stream opens with the provider's error (a rate limit before any content), and whose client hangs up after reading it, is now booked at $0 as the provider's refusal. Before, the model proxy counted it as a stop the client made and booked the request's hold. A stream that ends in an error only after the client hung up is still a stop. The proxy reads that error from the whole event, so a refusal whose data spans several `data:` lines, or several network chunks, is booked at $0 too. A stream that sends content, then the provider's error, which the client reads before it hangs up, now books the hold, or the usage the provider reported, as it would had the client stayed. Before, it was booked as a stop, by what had streamed. <!-- changes/stream-refusal-before-hang-up.md -->
32
+
5
33
  ## 0.1.0-beta.58 (2026-11-25)
6
34
 
7
35
  - `sessionSpendOf` also answers `chargedUsd`: what a session's answered requests were charged, a request a crash cut counted at its hold, and never one still in flight at its hold (null when one answered has no figure). `spentUsd` is unchanged and still counts the open ones at their holds. A host that checks a run's cap once it has settled reads `chargedUsd` in place of summing `figures` itself. <!-- changes/session-charged-usd.md -->
@@ -221,6 +221,21 @@ export declare function errorCut(mode: "error" | "events" | "as-is", forms: read
221
221
  push(text: string): string;
222
222
  end(): string;
223
223
  };
224
+ /** A whole server-sent event, as the format reads one
225
+ * (https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation): `text`, its lines as they
226
+ * came joined with a line feed (whatever ended them), and `data`, its `data:` lines' values (the one space after the
227
+ * colon dropped), which the format joins with a line feed. An event longer than its reader's limit has no text and no
228
+ * data: it is read past whole, never in part. */
229
+ export interface StreamEvent {
230
+ text?: string;
231
+ data: string[];
232
+ }
233
+ /** Reads a stream's whole events from its pieces as they come: lines end in LF, CRLF or a bare CR (a CRLF split between
234
+ * two pieces is one line end), and a blank line ends an event, never a line alone, so an event whose data spans several
235
+ * lines, or several pieces part way through a line, is read once it is whole. `max`: the most of an event kept. */
236
+ export declare function eventReader(max: number): {
237
+ push(text: string): StreamEvent[];
238
+ };
224
239
  /** A paid request as the host is asked about it, before it leaves. */
225
240
  export interface ProxyRequest {
226
241
  model: string;
@@ -348,29 +348,79 @@ export function errorCut(mode, forms, redact, say, tokens = []) {
348
348
  },
349
349
  };
350
350
  }
351
+ /** Reads a stream's whole events from its pieces as they come: lines end in LF, CRLF or a bare CR (a CRLF split between
352
+ * two pieces is one line end), and a blank line ends an event, never a line alone, so an event whose data spans several
353
+ * lines, or several pieces part way through a line, is read once it is whole. `max`: the most of an event kept. */
354
+ export function eventReader(max) {
355
+ const breaks = /\r\n|\r|\n/g;
356
+ /** The event's whole lines, and their length with their line ends (past `max`: Infinity, and its lines dropped). */
357
+ let lines = [];
358
+ let size = 0;
359
+ /** The line coming: what of it is kept, and its length, which tells a blank line. */
360
+ let line = "";
361
+ let lineChars = 0;
362
+ /** That the last piece ended on a CR: a LF the next one begins with is that CR's line end, not a line of its own. */
363
+ let afterCr = false;
364
+ const ended = () => {
365
+ const blank = lineChars === 0;
366
+ if (!blank && size !== Infinity) {
367
+ lines.push(line);
368
+ size += line.length + 1;
369
+ }
370
+ line = "";
371
+ lineChars = 0;
372
+ if (!blank)
373
+ return undefined;
374
+ const event = size === Infinity ? { data: [] } : lines.length ? { text: lines.join("\n"), data: lines.filter((each) => each.startsWith("data:")).map((each) => each.slice(5).replace(/^ /, "")) } : undefined;
375
+ lines = [];
376
+ size = 0;
377
+ return event;
378
+ };
379
+ return {
380
+ push(text) {
381
+ const out = [];
382
+ let at = afterCr && text.startsWith("\n") ? 1 : 0;
383
+ afterCr = false;
384
+ while (at < text.length) {
385
+ breaks.lastIndex = at;
386
+ const found = breaks.exec(text);
387
+ const end = found ? found.index : text.length;
388
+ lineChars += end - at;
389
+ if (size !== Infinity) {
390
+ line += text.slice(at, end);
391
+ if (size + line.length > max) {
392
+ size = Infinity;
393
+ lines = [];
394
+ line = "";
395
+ }
396
+ }
397
+ if (!found)
398
+ break;
399
+ at = end + found[0].length;
400
+ if (found[0] === "\r" && at === text.length)
401
+ afterCr = true;
402
+ const event = ended();
403
+ if (event)
404
+ out.push(event);
405
+ }
406
+ return out;
407
+ },
408
+ };
409
+ }
351
410
  function eventCounter(readers) {
352
411
  const keys = Object.keys(readers).filter((key) => readers[key] !== undefined);
353
412
  const sums = Object.fromEntries(keys.map((key) => [key, 0]));
354
- let pending = "";
355
- /** A "\r" the last piece ended on: the first half of a "\r\n" the next piece ends. */
356
- let cr = "";
413
+ const events = eventReader(EVENT_MAX_CHARS);
357
414
  return {
358
415
  push(text) {
359
416
  if (!keys.length)
360
417
  return;
361
- // A line end split between pieces ("\r" here, "\n" in the next) is joined before "\r\n" becomes "\n", or the two
362
- // events around a split blank line would read as one, which no policy can parse.
363
- let piece = cr + text;
364
- cr = piece.endsWith("\r") ? "\r" : "";
365
- if (cr)
366
- piece = piece.slice(0, -1);
367
- pending += piece.replace(/\r\n/g, "\n");
368
- for (let at = pending.indexOf("\n\n"); at >= 0; at = pending.indexOf("\n\n")) {
369
- const event = pending.slice(0, at);
370
- pending = pending.slice(at + 2);
418
+ for (const event of events.push(text)) {
419
+ if (event.text === undefined)
420
+ continue;
371
421
  for (const key of keys) {
372
422
  try {
373
- const n = readers[key](event);
423
+ const n = readers[key](event.text);
374
424
  if (typeof n === "number" && Number.isFinite(n) && n > 0)
375
425
  sums[key] += n;
376
426
  }
@@ -379,8 +429,6 @@ function eventCounter(readers) {
379
429
  }
380
430
  }
381
431
  }
382
- if (pending.length > EVENT_MAX_CHARS)
383
- pending = "";
384
432
  },
385
433
  bytes: (of) => sums[of] ?? 0,
386
434
  };
@@ -1417,11 +1465,32 @@ export async function startModelProxy(options, key) {
1417
1465
  say(`model proxy (${policy.id}): onCut threw`, { error: String(error?.message ?? error).slice(0, 200) });
1418
1466
  }
1419
1467
  };
1468
+ /** Whether this proxy had aborted the request when the answer's first error event was read (undefined: none read
1469
+ * yet). Each event is read here whole (eventReader) before its client is written the blank line that ends it, and a
1470
+ * client acts on an event only once that line ends it, so an error read before the abort is the provider's own (a
1471
+ * refusal, an overload) that its client then read and left on: no stop. One read after the abort may be the
1472
+ * abort's own end of the stream (a route's "aborted" event), or a refusal raced by the hang-up: a stop. */
1473
+ let errorReadAborted;
1420
1474
  /** The answer's stops, read from what has come of it so far: its content-filter stop, and its cut. */
1421
1475
  const tellStops = (text) => {
1422
1476
  tellFiltered(text);
1423
1477
  tellCut(text);
1424
1478
  };
1479
+ /** The answer's events, whole, at most a window of each: what tellEvent reads. */
1480
+ const events = eventReader(USAGE_WINDOW);
1481
+ /** One whole event of a successful answer: whether it is the provider's error, read by streamErrorOf as the booking
1482
+ * reads the answer's end, so the two never disagree on an event, and whether this proxy had aborted then. And when its
1483
+ * data came on several lines, its stops, from its data on one `data:` line (a space where the format joins with a
1484
+ * line feed: JSON reads both alike): a policy reads each `data:` line on its own, and no one line of such an event
1485
+ * holds it. */
1486
+ const tellEvent = (event) => {
1487
+ if (event.text === undefined)
1488
+ return;
1489
+ if (errorReadAborted === undefined && event.text.includes("error") && streamErrorOf(event.text) !== undefined)
1490
+ errorReadAborted = controller.signal.aborted;
1491
+ if (event.data.length > 1)
1492
+ tellStops([...event.text.split("\n").filter((each) => !each.startsWith("data:")), `data: ${event.data.join(" ")}`].join("\n"));
1493
+ };
1425
1494
  try {
1426
1495
  // From here a paid request may be paid, so every way out below books it exactly once.
1427
1496
  let upstream = await forward(`${origin}${route.path}${query ? `?${query}` : ""}`, { method: route.method, headers, body: sent, signal: controller.signal });
@@ -1575,6 +1644,10 @@ export async function startModelProxy(options, key) {
1575
1644
  line = "";
1576
1645
  }
1577
1646
  }
1647
+ // Then each event this piece ends, whole: an error event, and a stop whose data spans several lines.
1648
+ if (upstream.ok)
1649
+ for (const event of events.push(text))
1650
+ tellEvent(event);
1578
1651
  // A whole JSON body (no event stream) may be printed across lines, so no one line holds its stop: while it fits the
1579
1652
  // window, it is read whole at each piece that may close it (ends in "}"), which is a few pieces, never one each.
1580
1653
  if (wholeBody === undefined && text.trimStart() !== "")
@@ -1600,13 +1673,19 @@ export async function startModelProxy(options, key) {
1600
1673
  }
1601
1674
  res.end();
1602
1675
  answered = { ok: upstream.ok };
1676
+ // An upstream that ends its answer on this proxy's abort without throwing (a route's own fetch: pi-ai's stream ends
1677
+ // in its "aborted" error event, and the route closes it) is a stop all the same: its client left, and this proxy's
1678
+ // abort, not the provider, ended it. Never one read on past its client (keepReading: the signal was never aborted),
1679
+ // nor one whose error event was read before the abort (errorReadAborted false): the provider ended it, and its
1680
+ // client left after reading that.
1681
+ stoppedByClient = clientLeft && upstream.ok && controller.signal.aborted && errorReadAborted !== false;
1603
1682
  }
1604
1683
  catch (error) {
1605
1684
  // Its client had left before this (a stop): read now, as the proxy's own end below closes the response too.
1606
1685
  // Before any header too: the request left, and the provider may have begun it, as a stop part way. Only this proxy's
1607
1686
  // abort ends a stop: an answer read on after its client left (its content-filter stop) that the provider ends with
1608
- // an error is no stop.
1609
- stoppedByClient = clientLeft && (began === undefined || began.ok) && controller.signal.aborted;
1687
+ // an error is no stop, nor is one whose error event was read before the abort (errorReadAborted false).
1688
+ stoppedByClient = clientLeft && (began === undefined || began.ok) && controller.signal.aborted && errorReadAborted !== false;
1610
1689
  if (!began)
1611
1690
  failedCode = rejectionCode(error);
1612
1691
  say(`model proxy (${policy.id}): the request did not complete`, { error: String(error?.message ?? error).slice(0, 200) });
@@ -1695,8 +1774,9 @@ export async function startModelProxy(options, key) {
1695
1774
  // the model's first token, then a rate limit or an overload as an error event): refused, never run, so it cost
1696
1775
  // nothing. Never once the model's content streamed with no usage said, nor once the stream shows it began its
1697
1776
  // output with none of it streamed (outputBeganIn: hidden reasoning, a block a translation held): that was run,
1698
- // and is booked at an unknown cost as any answer cut short. Missing content is no proof of a refusal.
1699
- if (failed !== undefined && reported === undefined && !(policy.contentBytesOf && sentOf.bytes("content") > 0) && !outputBeganIn(kept)) {
1777
+ // and is booked at an unknown cost as any answer cut short. Missing content is no proof of a refusal, and the error
1778
+ // a stop's abort ends a stream in (stoppedByClient) is ours, never the provider's refusal: the stop counts it.
1779
+ if (!stoppedByClient && failed !== undefined && reported === undefined && !(policy.contentBytesOf && sentOf.bytes("content") > 0) && !outputBeganIn(kept)) {
1700
1780
  refusedIn = wordsOf(failed.words);
1701
1781
  say(`model proxy (${policy.id}): the provider refused the request inside its answer (${failed.rateLimit ? "a rate limit" : "an error"}); booked at nothing`);
1702
1782
  }
@@ -9,6 +9,12 @@ export declare const COMPUTER_TOOLS: readonly ["computer_observe", "computer_act
9
9
  export declare const COMPUTER_OPS: Readonly<Record<string, readonly string[]>>;
10
10
  /** The op of each step tool, as a script's `computer` names it. */
11
11
  export declare const STEP_TOOL_OPS: Readonly<Record<string, string>>;
12
+ /** computer_screenshot's definition `def` for a run whose agent is not given write: the surface's words and parameters,
13
+ * no save_as, which the run's gate refuses there. */
14
+ export declare const unsavedScreenshot: <T extends {
15
+ readonly description: string;
16
+ readonly parameters: object;
17
+ }>(def: T) => T;
12
18
  /** The ops computer_op runs on a computer with `groups`. */
13
19
  export declare function computerOpsFor(groups: readonly string[]): readonly string[];
14
20
  /** The tools a computer with `groups` offers: observe and act with the ui group, or a screen (observe) and input (act)
@@ -1,3 +1,15 @@
1
+ // A desktop's or a phone's tools, the same in both kinds: computer_observe (an app's window as a compact outline of its
2
+ // elements, by ref, and its image when asked), computer_act (steps on an app, each saying how it ran, an expect waited
3
+ // for, the new state), computer_screenshot (the whole screen), computer_op (one of the computer's other ops: its shell,
4
+ // its files, its apps, raw input), and the hand-over (handoff.ts). Each runs on the hands' one computer port
5
+ // (hands.computer), which @parcha/agentrun-computer's surface answers the same for a tool and an MCP client. Many steps
6
+ // in one call are a script: the host's codemode binds the surface's `computer` object over these tools, each of its
7
+ // calls a nested call of its own, gated and recorded (observe, act and screenshot as their own tools, every other op as
8
+ // computer_op, which a host lists to no model that has a codemode of the host's). Their schemas are generated from
9
+ // that surface's api.ts (computer-surface.generated.ts), so the words a model reads can't drift from what answers them.
10
+ // On a computer with no ui group, observe is a screenshot and act's steps are raw input at its pixels: the surface's
11
+ // fallback, said in its answers.
12
+ import { posix } from "node:path";
1
13
  import { ACT_STEPS, COMPUTER_TOOL_SCHEMAS } from "./computer-surface.generated.js";
2
14
  import { answerOf, needsKindWords } from "./hands.js";
3
15
  import { HANDOFF_TOOL, handoffDef, handoffExecutor } from "./handoff.js";
@@ -24,7 +36,31 @@ export const STEP_TOOL_OPS = Object.freeze({ observe: "computer_observe", act: "
24
36
  // phone-computer) teaches how to work; a description says only what its tool does.
25
37
  const OBSERVE = `An app's window as its elements, one line each (@e12 button "Save"), under a head line naming the state (s7). With no ui group: a screenshot.`;
26
38
  const ACT = `Run steps on an app, each on an element's ref or at a point in the window (refused as stale once the window changed under it). The answer says how each step ran and whether the window changed. The first refused step stops the rest. steps: UiStep[]\n\`\`\`ts\n${ACT_STEPS}\n\`\`\``;
27
- const SCREENSHOT = "The whole screen as an image, or a region of it.";
39
+ const SCREENSHOT_ALONE = "The whole screen as an image, or a region of it.";
40
+ const SCREENSHOT = `${SCREENSHOT_ALONE} With save_as, also saved as a PNG in the run's files.`;
41
+ /** save_as's words: the run's files are the run's folder, never the computer's own disk. */
42
+ const SAVE_AS = "A path relative to the run's folder, ending .png (shots/home.png): the screenshot is saved there, in the run's files the user gets. A file saved on the computer itself is not one of them.";
43
+ /** computer_screenshot's parameters in a run: the surface's, and save_as, which the run's hands answer, never the
44
+ * computer. */
45
+ const SCREENSHOT_PARAMETERS = (() => {
46
+ const schema = COMPUTER_TOOL_SCHEMAS.computer_screenshot;
47
+ return { ...schema, properties: { ...schema.properties, save_as: { type: "string", description: SAVE_AS } } };
48
+ })();
49
+ /** computer_screenshot's definition `def` for a run whose agent is not given write: the surface's words and parameters,
50
+ * no save_as, which the run's gate refuses there. */
51
+ export const unsavedScreenshot = (def) => ({ ...def, description: SCREENSHOT_ALONE, parameters: COMPUTER_TOOL_SCHEMAS.computer_screenshot });
52
+ /** `given` as a path in the run's folder a screenshot is saved to (relative, inside it, ending .png), normalized; any
53
+ * other is refused in words. */
54
+ function savePathOf(given) {
55
+ if (typeof given !== "string" || given === "" || posix.isAbsolute(given) || given.includes("\\"))
56
+ throw new Error(`save_as is a path relative to the run's folder (shots/home.png): not ${JSON.stringify(given)}`);
57
+ const path = posix.normalize(given);
58
+ if (path === ".." || path.startsWith("../"))
59
+ throw new Error(`save_as must stay inside the run's folder: ${JSON.stringify(given)} leaves it`);
60
+ if (!/\.png$/i.test(path) || path.endsWith("/.png"))
61
+ throw new Error(`save_as names a .png file: not ${JSON.stringify(given)}`);
62
+ return path;
63
+ }
28
64
  const OP = `One of the computer's ops no other tool runs, as a script's \`computer\` calls it: input.act {actions}, apps.list, apps.open {id, url?, background?}, shell.run {command, cwd?, env?, timeoutMs?}, processes.start {command, cwd?, env?}, files.read {path, encoding?}, files.write {path, data, encoding?}, files.list {path}, files.stat {path}. An op this computer does not offer is refused.`;
29
65
  /** The ops computer_op runs on a computer with `groups`. */
30
66
  export function computerOpsFor(groups) {
@@ -72,7 +108,8 @@ export function computerToolDefs(kind, groups) {
72
108
  // With apps and no ui group, an observe that names an app opens it first: it changes the screen, so it never runs again.
73
109
  def(kind, "computer_observe", OBSERVE, groups.includes("ui") || !groups.includes("apps")),
74
110
  def(kind, "computer_act", ACT, false, groups.includes("ui") ? undefined : ACT_WITHOUT_UI),
75
- def(kind, "computer_screenshot", SCREENSHOT, true),
111
+ // A replay takes the screen again and saves it over the same file of the run's: nothing outside the run changes.
112
+ def(kind, "computer_screenshot", SCREENSHOT, true, SCREENSHOT_PARAMETERS),
76
113
  def(kind, COMPUTER_OP_TOOL, OP, false, OP_PARAMETERS),
77
114
  handoffDef(kind),
78
115
  ]);
@@ -94,6 +131,27 @@ const surfaceExecutor = (kind, tool, op) => (args, call) => answerOf(call, async
94
131
  const answer = await port.call(op, args ?? {}, call.signal);
95
132
  return { text: answer.text, ...(answer.images.length > 0 ? { images: answer.images } : {}), structured: (withoutImageData(answer.value) ?? null) };
96
133
  });
134
+ /** computer_screenshot's run: the surface's screenshot, and with save_as its PNG written into the run's files through
135
+ * the run's hands (whatever disk the computer has), the answer saying where. A bad save_as is refused before the
136
+ * computer is asked. */
137
+ const screenshotExecutor = (kind) => (args, call) => {
138
+ const { save_as: given, ...rest } = (args ?? {});
139
+ if (given === undefined)
140
+ return surfaceExecutor(kind, "computer_screenshot", "screenshot")(rest, call);
141
+ return answerOf(call, async () => {
142
+ const path = savePathOf(given);
143
+ const port = call.hands.computer;
144
+ if (!port)
145
+ throw new Error(needsKindWords("computer_screenshot", kind));
146
+ const answer = await port.call("screenshot", rest, call.signal);
147
+ const image = answer.images.find((one) => one.mimeType === "image/png");
148
+ if (!image)
149
+ throw new Error("the computer's screenshot is no PNG, so it was not saved");
150
+ await call.hands.write(path, Buffer.from(image.data, "base64"));
151
+ const value = withoutImageData(answer.value);
152
+ return { text: `${answer.text}\nsaved as ${path} in the run's files`, images: answer.images, structured: { ...(value !== null && typeof value === "object" && !Array.isArray(value) ? value : {}), saved: path } };
153
+ });
154
+ };
97
155
  /** computer_op's run: `op` with `args` on the hands' computer port. An op a step tool runs is sent to that tool, so each
98
156
  * is held and recorded as that tool's call; any other the port refuses where the computer does not offer it. */
99
157
  const opExecutor = (kind) => (args, call) => {
@@ -109,7 +167,7 @@ const opExecutor = (kind) => (args, call) => {
109
167
  export const computerExecutors = (kind) => ({
110
168
  computer_observe: surfaceExecutor(kind, "computer_observe", "observe"),
111
169
  computer_act: surfaceExecutor(kind, "computer_act", "act"),
112
- computer_screenshot: surfaceExecutor(kind, "computer_screenshot", "screenshot"),
170
+ computer_screenshot: screenshotExecutor(kind),
113
171
  [COMPUTER_OP_TOOL]: opExecutor(kind),
114
172
  [HANDOFF_TOOL]: handoffExecutor(kind),
115
173
  });
@@ -2,7 +2,7 @@ export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from
2
2
  export { boundedBash } from "./bash.js";
3
3
  export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
4
4
  export type { ShellPlace, ToolDef } from "./defs.js";
5
- export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS } from "./computer.js";
5
+ export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS, unsavedScreenshot } from "./computer.js";
6
6
  export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
7
7
  export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
8
8
  export type { Permission } from "./gate.js";
@@ -5,7 +5,7 @@
5
5
  export { BACKGROUND_EXECUTORS, endBackground, NEEDS_A_COMPUTER, NO_SHELL } from "./background.js";
6
6
  export { boundedBash } from "./bash.js";
7
7
  export { bashTimeoutWords, CAPABILITY_KINDS, hostToolDefs } from "./defs.js";
8
- export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS } from "./computer.js";
8
+ export { COMPUTER_OP_TOOL, COMPUTER_OPS, COMPUTER_TOOLS, computerExecutors, computerOpsFor, computerToolDefs, computerToolsFor, STEP_TOOL_OPS, unsavedScreenshot } from "./computer.js";
9
9
  export { COMPUTER_TOOL_SCHEMAS, computerDeclarations } from "./computer-surface.generated.js";
10
10
  export { defaultPermissionOf, SHELL_FAMILY, SHELL_WATCHERS, shellPermission, shellToolOf } from "./gate.js";
11
11
  export { answerOf, exitCodeOf, needsKindWords } from "./hands.js";
package/dist/types.d.ts CHANGED
@@ -71,7 +71,8 @@ export interface HostTool {
71
71
  isError?: boolean;
72
72
  images?: readonly ToolImage[]; /** The answer as a value (a computer tool's), its images' data left out: what a script's nested call reads (Codex's code mode) and an MCP client's structuredContent. */
73
73
  structured?: JsonValue;
74
- parked?: true;
74
+ parked?: true; /** A tool that `nests` ended at a nested call the gate refused (a script that stopped there): an error whose Timeline rows read refused, as the nested call's do, never as a call that ran and failed. */
75
+ refused?: true;
75
76
  }>;
76
77
  /** The tool only calls the session's other tools (tools_call, codemode), each as a call of its own nested in this one
77
78
  * (`context.nested`): each nested call passes the gate as itself and is recorded under its own id, so this call writes
@@ -420,12 +421,16 @@ export type AdapterEvent = {
420
421
  * what it said so far is one message. */
421
422
  | {
422
423
  type: "text_end";
423
- } | {
424
+ }
425
+ /** `refused`: the harness turned the call down itself (a tool the session does not have), so `name` is only the
426
+ * model's words, never a tool of the session's. */
427
+ | {
424
428
  type: "tool_start";
425
429
  callId: string;
426
430
  name: string;
427
431
  args: unknown;
428
432
  parent?: string;
433
+ refused?: true;
429
434
  } | {
430
435
  type: "tool_end";
431
436
  callId: string;
@@ -574,6 +579,10 @@ export interface AdapterFacts {
574
579
  /** It defers a run's MCP tools behind a tool search of its own (Claude Code's ToolSearch), so the host offers no
575
580
  * `tools_search` or `tools_call` beside it. Absent: the host's are offered when a run's catalog tools are deferred. */
576
581
  readonly ownToolSearch?: true;
582
+ /** Its model proxy forwards with the fetch its launch hands it (ModuleLaunch.fetch, a provider's `fetch`), so a model
583
+ * only that fetch reaches (one the host's route translates onto its wire: an Ollama model on Messages or Responses) is
584
+ * its to run. Absent: the host offers it no such model, names none as its default, and refuses one a run names. */
585
+ readonly forwardsRoute?: true;
577
586
  /** The model as the harness names it (Anthropic's id has no dot). */
578
587
  normalizeModel(model: {
579
588
  provider: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-kernel",
3
- "version": "0.1.0-beta.58",
3
+ "version": "0.1.0-beta.60",
4
4
  "description": "Agent harnesses other than Pi, starting with Codex, behind one seam: a DSL node's runNode and an AgentRun run on a harness adapter, durable in AgentRun's own store.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -62,7 +62,7 @@
62
62
  "test": "node --test --test-concurrency=8 'test/*.test.mjs'"
63
63
  },
64
64
  "dependencies": {
65
- "@parcha/agentrun-dsl": "0.1.0-beta.58",
65
+ "@parcha/agentrun-dsl": "0.1.0-beta.60",
66
66
  "ajv": "8.18.0",
67
67
  "typebox": "1.3.27"
68
68
  },