@parcha/agentrun-kernel 0.1.0-beta.55 → 0.1.0-beta.57

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,14 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.57 (2026-11-24)
6
+
7
+ - A live run shows what it waits on while it waits, not only once it answers (GRE-4835): a model request from the moment it is sent, on every harness, and each tool call until it returns. A slow local model reading a long prompt shows "inkling-2-mini thinking · 2:13" under the run's header, ticking; a slow `web_fetch` shows "web_fetch · 0:41". <!-- changes/in-flight-requests.md -->
8
+ - The kernel stamps each model request's record (`runner.request`) with when it left (`at`) and the input it was admitted with (`inputTokensMax`), written before the request leaves, as the record already was. `ModelPortOptions.now` sets the clock.
9
+ - `GET /v2/runs/{id}/timeline` pages carry `in_flight` (`inflight/1`, this server's own beside the vendored contract): each model request with no answer yet (its model, `started_at`, `input_tokens_max`, and `for_tool` for a tool's own request) and each tool call with no result yet (its tool, `started_at`, `tool_use_id`), oldest first; empty once the run is final. A request sent or answered is a change of the page, so a long poll or the event stream wakes for it.
10
+ - Not yet: tokens counted while a model streams its answer; the Dev tools trace still lists a model request once it answers.
11
+ - `parentWatched` takes a third argument, `{ termGraceMs }`: under the parent-watch shim (where `setpriv --pdeathsig` is not available: macOS, or Linux without it), the shim kills its child with SIGKILL when the child is still running that many milliseconds after a TERM the shim passed on. It reaches the shim as `--term-grace <ms>` before `--`; anything but a positive whole number of milliseconds a timer can wait is a usage error (exit 2). A host that ends a watched child with TERM and later a SIGKILL of its own sends that SIGKILL to the shim alone, so a child that ignored the TERM, or took longer to exit, ran on with no watch while its host lived: such a host asks for a grace shorter than its own wait. The parent-death signal ignores the option, since setpriv execs the child in place and the host's SIGKILL reaches it. A child started without it is ended as before: the shim passes TERM, INT and HUP on with nothing after them. Session machines pass none (their kill reaches the whole process group, the CLI included), so a session's CLI keeps all the time its host gives it after a TERM. <!-- changes/parent-watch-term-grace.md -->
12
+
5
13
  ## 0.1.0-beta.55 (2026-11-23)
6
14
 
7
15
  - The server lists the models of this machine's Ollama itself, as `ollama/<tag>` on pi, with no key and no gateway. Start Ollama and its models are in capabilities, the Model picker and pi's free models within half a minute, with no restart. `OLLAMA_HOST` says where it listens, read as the ollama CLI reads it (plain http to loopback alone). Unset, it is 127.0.0.1:11434 only on one owner's own server on their own machine (the rule `--harness-sign-in` starts under); a shared server asks Ollama only where `OLLAMA_HOST` names it. A refused `OLLAMA_HOST` is said once in the server's log, never its value. Requests go to Ollama's own `/api/chat` with `num_ctx` the least of 65,536, the model's trained context and `OLLAMA_CONTEXT_LENGTH` when it is set. A model without the `tools` capability takes its tools as text. They cost $0 and never count toward `AGENTRUN_FREE_MODEL_REQUESTS`, and the console shows no request limit for them. With no model key held, pi's default is the first Ollama model that calls tools; any key wins. A down or stuck Ollama lists nothing and stalls nothing. <!-- changes/ollama-provider.md -->
@@ -6,7 +6,7 @@ export type { InputCounter, ModelProxy, ModelProxyHooks, ModelProxyOptions, Mode
6
6
  export { processAlive } from "./alive.js";
7
7
  export { serialWriter } from "./serial.js";
8
8
  export { PARENT_WATCH_SHIM, parentWatched, parentWatchHere, SETPRIV } from "./parent-death.js";
9
- export type { LaunchCommand, ParentWatch } from "./parent-death.js";
9
+ export type { LaunchCommand, ParentWatch, ParentWatchOptions } from "./parent-death.js";
10
10
  export { BoxError } from "./box.js";
11
11
  export type { BoxErrorCode, BoxRecord } from "./box.js";
12
12
  export { type BinaryCheck, type BinaryProbe, checkedOnce, checkedOnceAsync, sha256OfFile, sha256OfFileAsync } from "./pinned-binary.js";
@@ -11,5 +11,12 @@ export declare const SETPRIV = "/usr/bin/setpriv";
11
11
  export declare const PARENT_WATCH_SHIM: string;
12
12
  /** The watch this machine supports: pdeathsig on Linux with a setpriv that has `--pdeathsig`, else the shim. Read once. */
13
13
  export declare function parentWatchHere(): ParentWatch;
14
+ /** What a caller asks of the watch. `termGraceMs` (a positive whole number of milliseconds): under the shim, the child is
15
+ * killed (SIGKILL) when it outlasts a TERM the shim passed on by that long, for a host whose own later SIGKILL goes to
16
+ * the shim alone. With none, the shim passes a TERM on and nothing after it. The parent-death signal ignores it: setpriv
17
+ * execs the child in place, so the host's SIGKILL reaches the child itself. */
18
+ export interface ParentWatchOptions {
19
+ termGraceMs?: number;
20
+ }
14
21
  /** `child`, started so that it dies with this process (`how`, default what this machine supports). */
15
- export declare function parentWatched(child: Readonly<LaunchCommand>, how?: ParentWatch): LaunchCommand;
22
+ export declare function parentWatched(child: Readonly<LaunchCommand>, how?: ParentWatch, options?: Readonly<ParentWatchOptions>): LaunchCommand;
@@ -9,7 +9,10 @@
9
9
  // moment the host's spawning thread exits: libuv spawns from the event loop's thread, the main one, so a worker
10
10
  // thread's exit does not trigger it. The signal survives the exec, as the child is not set-user-ID.
11
11
  // - elsewhere (macOS, or no setpriv): `node parent-watch.js <host pid> -- <child>`, a shim that runs the child and
12
- // kills it when the shim is reparented, checked four times a second.
12
+ // kills it when the shim is reparented, checked four times a second. A host's kill of the shim alone (SIGKILL)
13
+ // leaves the child running, so a host that ends its child that way asks for `termGraceMs`: the shim kills a child
14
+ // that outlasts a TERM it passed on, that long later. A host that kills the whole group (a session machine) asks for
15
+ // none: its SIGKILL reaches the child itself.
13
16
  // The watch goes INSIDE the host's confinement (the machine applies its confine prefix to the watched command): the
14
17
  // kernel clears a parent-death signal when credentials change, so it is set after any switch of user the prefix makes.
15
18
  // The child's environment is the machine's: the watch adds nothing to it.
@@ -35,8 +38,9 @@ export function parentWatchHere() {
35
38
  return (here = pdeathsig ? "pdeathsig" : "shim");
36
39
  }
37
40
  /** `child`, started so that it dies with this process (`how`, default what this machine supports). */
38
- export function parentWatched(child, how = parentWatchHere()) {
41
+ export function parentWatched(child, how = parentWatchHere(), options = {}) {
39
42
  if (how === "pdeathsig")
40
43
  return { command: SETPRIV, args: ["--pdeathsig", "KILL", "--", child.command, ...child.args] };
41
- return { command: process.execPath, args: [PARENT_WATCH_SHIM, String(process.pid), "--", child.command, ...child.args] };
44
+ const grace = options.termGraceMs === undefined ? [] : ["--term-grace", String(options.termGraceMs)];
45
+ return { command: process.execPath, args: [PARENT_WATCH_SHIM, String(process.pid), ...grace, "--", child.command, ...child.args] };
42
46
  }
@@ -1,13 +1,24 @@
1
1
  // The parent watch where the kernel's parent-death signal is not available (parent-death.ts). Written for AgentRun.
2
- // node parent-watch.js <parent pid> -- <command> [args...]
2
+ // node parent-watch.js <parent pid> [--term-grace <ms>] -- <command> [args...]
3
3
  // Runs the command with this process's stdio and environment, in this process's group (so a group kill ends both),
4
4
  // passes TERM, INT and HUP on to it, exits as it exits, and kills it when this process is reparented: its parent, the
5
- // host, is gone.
5
+ // host, is gone. With `--term-grace <ms>` it also kills the command (SIGKILL) when it outlasts a TERM passed on by
6
+ // that long.
6
7
  import { spawn } from "node:child_process";
7
- const [parentArg, separator, command, ...args] = process.argv.slice(2);
8
+ // `--term-grace`: a host that ends this child with TERM, and SIGKILL after a wait of its own sent to this process
9
+ // alone (startClaudeLogin's 5 s), asks for a grace shorter than that wait, since its SIGKILL would leave a child still
10
+ // running with no watch while the host lives. A host whose SIGKILL reaches the child too (a session machine's group
11
+ // kill) asks for none, and the child keeps all the time that host gives it. INT and HUP pass on with no kill after
12
+ // them: a session's CLI may take INT as "stop this turn" and go on.
13
+ const [parentArg, ...rest] = process.argv.slice(2);
8
14
  const parent = Number(parentArg);
9
- if (!Number.isSafeInteger(parent) || parent < 1 || separator !== "--" || !command) {
10
- process.stderr.write("usage: parent-watch.js <parent pid> -- <command> [args...]\n");
15
+ const graceAsked = rest[0] === "--term-grace";
16
+ const graceArg = graceAsked ? rest[1] : undefined;
17
+ // A positive whole number of milliseconds a timer can wait (longer ones fire at once).
18
+ const termGraceMs = graceArg !== undefined && /^[1-9]\d*$/.test(graceArg) && Number(graceArg) <= 2_147_483_647 ? Number(graceArg) : undefined;
19
+ const [separator, command, ...args] = graceAsked ? rest.slice(2) : rest;
20
+ if (!Number.isSafeInteger(parent) || parent < 1 || (graceAsked && termGraceMs === undefined) || separator !== "--" || !command) {
21
+ process.stderr.write("usage: parent-watch.js <parent pid> [--term-grace <ms>] -- <command> [args...]\n");
11
22
  process.exit(2);
12
23
  }
13
24
  // Started after the host was already gone: nothing to run for.
@@ -15,8 +26,14 @@ if (process.ppid !== parent)
15
26
  process.exit(1);
16
27
  const child = spawn(command, args, { stdio: "inherit" });
17
28
  const passed = ["SIGTERM", "SIGINT", "SIGHUP"];
18
- for (const signal of passed)
19
- process.on(signal, () => child.kill(signal));
29
+ let grace;
30
+ for (const signal of passed) {
31
+ process.on(signal, () => {
32
+ child.kill(signal);
33
+ if (signal === "SIGTERM" && termGraceMs !== undefined)
34
+ grace ??= setTimeout(() => child.kill("SIGKILL"), termGraceMs);
35
+ });
36
+ }
20
37
  child.on("error", (error) => {
21
38
  process.stderr.write(`parent-watch: ${error.message}\n`);
22
39
  process.exit(127);
@@ -29,6 +46,7 @@ const watch = setInterval(() => {
29
46
  }, 250);
30
47
  child.on("exit", (code, signal) => {
31
48
  clearInterval(watch);
49
+ clearTimeout(grace);
32
50
  if (code !== null)
33
51
  process.exit(code);
34
52
  // Ended by a signal: end the same way, so the host sees what the child saw.
@@ -305,7 +305,8 @@ export interface ModelProxyOptions {
305
305
  * after the client's, so the client can neither set nor override them, and before the credential's. Checked when the
306
306
  * proxy starts (`hostHeaderProblems`). */
307
307
  headers?: Readonly<Record<string, string>>;
308
- /** For tests: the fetch the proxy forwards with. */
308
+ /** The fetch the proxy forwards with: the host's route for a model it translates onto the wire (a test's recorder,
309
+ * too); absent, the network. */
309
310
  fetch?: typeof fetch;
310
311
  /** Told, with CONTENT_FILTERED, once an answer the provider stopped on its content filter has been passed and booked
311
312
  * (`ProviderPolicy.filtered`): the harness halts the turn with it, before its client asks for the answer again. */
package/dist/runner.d.ts CHANGED
@@ -256,6 +256,8 @@ export interface ModelPortOptions {
256
256
  noteReturned?: (note: string) => void;
257
257
  /** The port ends the attempt (the turn limit, the host's refusal, a cost it could not record): the error it throws. */
258
258
  stop?: (reason: "turn_limit" | "refused" | "model_error", message?: string, code?: string) => Error;
259
+ /** The clock a request's record is stamped with (`at`, when it left), in ms since the epoch (default: Date.now). */
260
+ now?: () => number;
259
261
  }
260
262
  /** A session's booking of paid model requests: the adapter's model port, and what it has counted. */
261
263
  export interface ModelBooking {
package/dist/runner.js CHANGED
@@ -346,7 +346,9 @@ function bookingFor(writer, options) {
346
346
  const localRequest = !!verdict && "localRequest" in verdict && verdict.localRequest === true;
347
347
  // A paid tool call (ModelRequest.paid) says so on its record (`paid`), so a later process that books it cut knows its
348
348
  // hold is its fee as admitted, never a bound on what its provider charged (bookCut).
349
- await write([{ kind: RUNNER_RECORDS.request, data: { turn, model, ...(paid ? { paid: true } : {}), ...(hold === undefined ? {} : { heldUsd: hold }), ...(onPlan ? { plan: true } : {}), ...(freeRequest ? { freeRequest: true } : {}), ...(localRequest ? { localRequest: true } : {}), ...(side ? { side } : {}), ...(host === undefined ? {} : { host }), ...(paid?.call === undefined ? {} : { call: paid.call }), ...(paid?.charged_by === undefined ? {} : { charged_by: paid.charged_by }), ...(paid?.tool === undefined ? {} : { tool: paid.tool }), ...(paid?.tag === undefined ? {} : { tag: paid.tag }), ...(paid?.owed ? { owed: true } : {}), ...(paid?.hold ? { hold: true } : {}), ...(paid?.ref === undefined ? {} : { ref: paid.ref }), ...(paid?.reported ? { reported: true } : {}) } }]);
349
+ // `at`: when it left, so a reader shows a request still in flight from its start (a run page's live row), and
350
+ // `inputTokensMax`, the input it was admitted with, beside it.
351
+ await write([{ kind: RUNNER_RECORDS.request, data: { turn, model, at: new Date((options.now ?? Date.now)()).toISOString(), ...(inputTokensMax === undefined ? {} : { inputTokensMax }), ...(paid ? { paid: true } : {}), ...(hold === undefined ? {} : { heldUsd: hold }), ...(onPlan ? { plan: true } : {}), ...(freeRequest ? { freeRequest: true } : {}), ...(localRequest ? { localRequest: true } : {}), ...(side ? { side } : {}), ...(host === undefined ? {} : { host }), ...(paid?.call === undefined ? {} : { call: paid.call }), ...(paid?.charged_by === undefined ? {} : { charged_by: paid.charged_by }), ...(paid?.tool === undefined ? {} : { tool: paid.tool }), ...(paid?.tag === undefined ? {} : { tag: paid.tag }), ...(paid?.owed ? { owed: true } : {}), ...(paid?.hold ? { hold: true } : {}), ...(paid?.ref === undefined ? {} : { ref: paid.ref }), ...(paid?.reported ? { reported: true } : {}) } }]);
350
352
  turns = turn;
351
353
  if (host !== undefined)
352
354
  hosts.set(turn, host);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-kernel",
3
- "version": "0.1.0-beta.55",
3
+ "version": "0.1.0-beta.57",
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.55",
65
+ "@parcha/agentrun-dsl": "0.1.0-beta.57",
66
66
  "ajv": "8.18.0",
67
67
  "typebox": "1.3.27"
68
68
  },