@parcha/agentrun-harness-claude 0.1.0-beta.39 → 0.1.0-beta.41

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,15 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.41 (2026-11-16)
6
+
7
+ - A message sent to a working `claude-agent` run now steers it mid-turn. Before, it waited for the turn's end, and a run whose whole job is one turn read it only after the work was done. The model now reads it at its next step, after the tool calls in flight finish, in the same turn. `POST /v2/runs/{id}/messages` answers mode `steer` for a working claude-agent run (it answered `follow_up`), and `GET /v2/capabilities` lists `claude-agent` with `steer: true`.
8
+ - The Timeline shows the message where the model read it: after the tool call it was sent during, never where it waited in the queue. Its command row is taken in that commit.
9
+ - A message sent as the turn ends starts the next turn, and the run ends only after that turn.
10
+ - A runner lost after it placed the message, before the model took it, neither loses it nor sends it twice. The next runner places nothing again, its resumed turn carries the message if the CLI never had it, and the message is on the Timeline once.
11
+ - A trigger's message that answers nothing (`answers: false`), and the answer to a question the run's last turn ended on, still run as turns of their own, as before.
12
+ - Adapters: `AdapterEvent` gains `message_taken` (`ids`): the submissions the model was given, for a host that keeps the run's record itself. `@parcha/agentrun-harness-claude`'s session implements `steer()`, places nothing again for an id it already holds, and says `message_taken`.
13
+
5
14
  ## 0.1.0-beta.39 (2026-11-16)
6
15
 
7
16
  - A capped Claude Agent run on a Claude model reached through a gateway (Sonnet 5.5 through OpenRouter) no longer stops at its second step with most of its cap left. The provider's count is asked for only at Anthropic, and no local tokenizer counts Claude, so each request was bounded by its bytes: about four times its tokens. An inbox agent's second request read as about 32,000 tokens, so at a $0.10 cap the step after one that cost $0.01-0.02 "needs at least $0.10" and the run paused, where a real step costs about $0.03. The model proxy now keeps each model's last request whose answer reported its whole input, and bounds a later request that carries it unchanged by that billed input plus the bytes of the messages it adds, when that is lower. That request must match the earlier one in everything that bills input apart from the added messages (system, tools, thinking, effort, model); a moved cache marker (a `cache_control` key on a tool, a system or message content block, or a block of a tool result's content) does not count as a change, and a `cache_control` key anywhere else is compared as text. The wrap-up note is asked for on that bound. A first request, a request that changes its tools or prompt, one that adds a document, or one that offers the hosted search keeps its byte bound, and a step that does not fit is still refused.
package/README.md CHANGED
@@ -50,6 +50,10 @@ const runNode = createHarnessRunner(
50
50
  allowlist (`PATH`, `LANG`, `TZ`, its own homes and the proxy's address and key).
51
51
  - **Durable.** The CLI's transcript is mirrored into the session's records (the SDK's session store), so a session a
52
52
  process died inside resumes from them on any machine.
53
+ - **Steers mid-turn.** A message `steer()` places while a turn runs goes to the CLI at once, at priority `next`; the CLI
54
+ hands it to the model at its next step, after the tool calls in flight finish, in the same turn. The session's
55
+ `message_taken` event says when the transcript holds it. One placed as the turn ends starts the next turn, and one
56
+ placed again under the same id places nothing.
53
57
 
54
58
  `./testing` has a scripted Agent SDK (no CLI, key or network) and a scripted Anthropic Messages API for the real CLI.
55
59
 
package/dist/adapter.js CHANGED
@@ -375,6 +375,14 @@ export function claudeAgentAdapter(options) {
375
375
  // The model's message ended inside the turn (the CLI resumes a cut answer itself): what it said so far is one message.
376
376
  if (e?.type === "text_end")
377
377
  io.onEvent({ type: "text_end" });
378
+ // The CLI took these submissions (its transcript holds the message that carried them): a steer reached the model.
379
+ if (e?.type === "message_taken" && Array.isArray(e.ids))
380
+ io.onEvent({ type: "message_taken", ids: e.ids.filter((id) => typeof id === "string") });
381
+ // The harness handed these submissions to the CLI: a steer() waiting on one returns. Not the host's to hear.
382
+ if (e?.type === "message_sent" && Array.isArray(e.ids))
383
+ for (const id of e.ids)
384
+ if (typeof id === "string")
385
+ sentWaiters.get(id)?.();
378
386
  // The tool bridge's `tool_end` comes once the call's outcome is in the session's records: only then does the host
379
387
  // hear the call ended, with the text recorded.
380
388
  if (e?.type === "tool_end" && typeof e.callId === "string" && typeof e.name === "string") {
@@ -402,9 +410,20 @@ export function claudeAgentAdapter(options) {
402
410
  : initial.submissions.length === 0 && turnsIn(drive).length === 0 ? "new" : "idle";
403
411
  let running;
404
412
  let closed = false;
413
+ // A turn is in flight: set as run() starts it, cleared only right after the drive's last look at the inbox (below),
414
+ // with nothing awaited between, so a submission written meanwhile is either sent by this turn or starts the next.
415
+ let turning = false;
416
+ /** steer() calls waiting for the harness to hand their message to the CLI, by submission id. */
417
+ const sentWaiters = new Map();
418
+ /** A submission written while no turn was in flight, still unsent: it starts one. */
419
+ const kick = () => {
420
+ if (!turning && !closed && pendingSubmissions(drive.state()).length > 0)
421
+ void run();
422
+ };
405
423
  const run = () => {
406
424
  const before = turnsIn(drive).length;
407
425
  state = "idle";
426
+ turning = true;
408
427
  running = (async () => {
409
428
  let outcome;
410
429
  // A turn whose final answer the model cut at its output limit, the CLI's recovery of it spent, says so on its
@@ -414,6 +433,10 @@ export function claudeAgentAdapter(options) {
414
433
  const current = drive;
415
434
  try {
416
435
  await harness.drive(current);
436
+ // A steer written as the drive's inbox closed (the turn was ending) is pending, and no turn of the drive
437
+ // sends it: the turn goes on with it, as the harness's own steer placed while a turn ends does.
438
+ while (!current.signal.aborted && pendingSubmissions(current.state()).length > 0)
439
+ await harness.drive(current);
417
440
  const ended = turnsIn(current).slice(before).at(-1)?.data;
418
441
  if (ended?.stopReason === "length")
419
442
  stop = { stopReason: "length", ...(typeof ended.outputTokens === "number" ? { outputTokens: ended.outputTokens } : {}) };
@@ -435,9 +458,13 @@ export function claudeAgentAdapter(options) {
435
458
  outcome = { status: "failed", error: String(error?.message ?? error).slice(0, 500) };
436
459
  }
437
460
  }
461
+ turning = false;
438
462
  io.onEvent({ type: "turn_end", status: outcome.status, ...stop });
439
463
  return outcome;
440
- })();
464
+ })().catch((error) => {
465
+ turning = false;
466
+ throw error;
467
+ });
441
468
  return running;
442
469
  };
443
470
  // A drive that was halted (an interrupt) holds the session no more: the next turn opens a fresh one, on the same
@@ -445,7 +472,8 @@ export function claudeAgentAdapter(options) {
445
472
  const ready = async () => {
446
473
  if (closed)
447
474
  throw new Error("agentrun-harness-claude: the session is closed");
448
- if (running)
475
+ // A turn a steer started meanwhile is waited for too.
476
+ while (turning && running)
449
477
  await running;
450
478
  if (drive.signal.aborted && !io.signal.aborted)
451
479
  drive = await open();
@@ -492,7 +520,47 @@ export function claudeAgentAdapter(options) {
492
520
  throw new Error("agentrun-harness-claude: the session is pausing; no new turn");
493
521
  await ready();
494
522
  await drive.submit({ id: randomUUID(), kind: "prompt", text });
495
- void run();
523
+ // Sent by the turn a steer started meanwhile, if one did; else a turn of its own.
524
+ kick();
525
+ },
526
+ // A person's message: mid-turn, sent by the harness's steering loop at priority `next`, so the CLI hands it to the
527
+ // model at its next step (after the tool calls in flight finish), in the same turn; with no turn in flight, a turn of
528
+ // its own. Placed under the host's id once: the same id again (a runner lost after the placement hands the row on
529
+ // again) places nothing, and says the model has it when the transcript already does.
530
+ async steer(text, id, mode = "steer", _options) {
531
+ if (closed)
532
+ throw new Error("agentrun-harness-claude: the session is closed");
533
+ if (calls.draining)
534
+ throw new Error("agentrun-harness-claude: the session is pausing; no new message");
535
+ const submissionId = id ?? randomUUID();
536
+ if (drive.state().submissions.some((s) => s.id === submissionId)) {
537
+ const folded = drive.state();
538
+ const placed = folded.effectOrder.some((e) => e.name === "place" && e.placed.includes(submissionId));
539
+ if (placed) {
540
+ const transcript = new JournalSessionStore(new NativeJournal(drive), { records: await new NativeJournal(drive).read() });
541
+ if (lostPrompts(folded, [submissionId], transcript).length === 0)
542
+ io.onEvent({ type: "message_taken", ids: [submissionId] });
543
+ }
544
+ kick();
545
+ return;
546
+ }
547
+ // A drive an interrupt halted is opened again before anything is written through it.
548
+ if (!turning)
549
+ await ready();
550
+ // steer() returns once the CLI has the message (the turn in flight then takes it at its next step), or once the
551
+ // turn that would have sent it is over: a host that lets the work go on after steer() returns has not raced it.
552
+ let wake;
553
+ const sent = new Promise((resolve) => (wake = resolve));
554
+ sentWaiters.set(submissionId, wake);
555
+ try {
556
+ await drive.submit({ id: submissionId, kind: mode === "followUp" ? "followUp" : "steer", text });
557
+ kick();
558
+ const turn = running;
559
+ await Promise.race([sent, ...(turn ? [turn.then(() => undefined, () => undefined)] : [])]);
560
+ }
561
+ finally {
562
+ sentWaiters.delete(submissionId);
563
+ }
496
564
  },
497
565
  async recover() {
498
566
  if (state !== "open_turn")
@@ -517,9 +585,14 @@ export function claudeAgentAdapter(options) {
517
585
  state = "idle";
518
586
  },
519
587
  async turnEnd() {
520
- if (!running)
521
- throw new Error("agentrun-harness-claude: no turn is in flight");
522
- return running;
588
+ if (running)
589
+ return running;
590
+ // No turn ran in this session: the last turn the session's records hold, ended before it opened (a lost runner's
591
+ // steer the model already answered, placed again here, starts no turn). None at all: there is no turn to wait for.
592
+ const last = turnsIn(drive).at(-1)?.data;
593
+ if (last?.status && !holdsTurn(drive.state()))
594
+ return { status: last.status, ...(last.error ? { error: last.error } : {}) };
595
+ throw new Error("agentrun-harness-claude: no turn is in flight");
523
596
  },
524
597
  async interrupt(interruptOptions = {}) {
525
598
  const drainMs = interruptOptions.drainMs ?? 0;
package/dist/facts.js CHANGED
@@ -8,8 +8,10 @@ export const facts = Object.freeze({
8
8
  id: "claude-agent",
9
9
  label: "Claude",
10
10
  wire: "anthropic-messages",
11
- // A message that comes mid-turn waits for the turn's end.
12
- steer: false,
11
+ // A message that comes mid-turn reaches the model at its next step, after the tool calls in flight finish, in the same
12
+ // turn: the session's steer() places it, the harness sends it to the CLI at priority `next`, and the CLI takes it as a
13
+ // queued command. One that comes as the turn ends starts the next turn.
14
+ steer: true,
13
15
  // A call that started is never run again (one cut off the CLI answers "[Tool call interrupted]"; one that ended gets its
14
16
  // recorded result); only the model calls again.
15
17
  rerunsStarted: false,
package/dist/harness.js CHANGED
@@ -608,6 +608,12 @@ export function claudeCodeHarness(options = {}) {
608
608
  text = `${dateLine(at, options.zone)}\n\n${text}`;
609
609
  await ctx.effect(`${DATE_EFFECT}:${uuid}`, { name: DATE_EFFECT, replay: 'safe', input: { day } }, async () => day);
610
610
  }
611
+ // Once the transcript holds the message (its own user entry, or the `queued_command` attachment a steer becomes
612
+ // when the CLI takes it at its next step), the host hears which submissions reached the model: a steer's record is
613
+ // written there, after the tool call it was sent during, never when it was only queued.
614
+ const carried = [...placed.map((p) => p.id), ...(how.covers ?? [])];
615
+ if (carried.length)
616
+ void store.whenUser(uuid).then(() => ctx.live({ type: 'message_taken', ids: carried }));
611
617
  outstanding.add(uuid);
612
618
  input.push({
613
619
  type: 'user',
@@ -616,6 +622,9 @@ export function claudeCodeHarness(options = {}) {
616
622
  uuid: uuid,
617
623
  ...(how.priority ? { priority: how.priority } : {}),
618
624
  });
625
+ // The CLI has the message now: a steer() waiting on it returns (the session keeps this to itself).
626
+ if (placed.length)
627
+ ctx.live({ type: 'message_sent', ids: placed.map((p) => p.id) });
619
628
  };
620
629
  /**
621
630
  * The CLI exited mid-turn, not because the drive stopped: the link to
package/dist/store.d.ts CHANGED
@@ -67,6 +67,7 @@ export declare class JournalSessionStore {
67
67
  private readonly loaded;
68
68
  private readonly calls;
69
69
  private readonly users;
70
+ private readonly userWaiters;
70
71
  private readonly waiters;
71
72
  private readonly results;
72
73
  private readonly resultWaiters;
@@ -89,6 +90,11 @@ export declare class JournalSessionStore {
89
90
  * `queued_command` attachment a mid-turn message becomes.
90
91
  */
91
92
  hasUser(uuid: string): boolean;
93
+ /**
94
+ * Resolve once the user message sent with this `uuid` is in the transcript (`hasUser`): the CLI took it, as a turn's
95
+ * own message or, mid-turn, as a `queued_command` attachment. Never rejects; it waits as long as the store lives.
96
+ */
97
+ whenUser(uuid: string): Promise<void>;
92
98
  /** Whether an assistant entry that made this tool call is in the transcript. */
93
99
  hasCall(toolUseId: string): boolean;
94
100
  append(key: SessionKey, entries: TranscriptLine[]): Promise<void>;
@@ -118,6 +124,7 @@ export declare class JournalSessionStore {
118
124
  */
119
125
  barrier(toolUseId: string, timeoutMs: number): Promise<void>;
120
126
  private note;
127
+ private user;
121
128
  /**
122
129
  * Resolve once the user entry that answers `toolUseId` (its `tool_result`) is committed: a call the CLI answered
123
130
  * itself (a refusal) is told to the host only once the log holds the answer. Rejects after `timeoutMs`.
package/dist/store.js CHANGED
@@ -41,6 +41,7 @@ export class JournalSessionStore {
41
41
  loaded = new Map();
42
42
  calls = new Set();
43
43
  users = new Set();
44
+ userWaiters = new Map();
44
45
  waiters = new Map();
45
46
  results = new Set();
46
47
  resultWaiters = new Map();
@@ -82,6 +83,15 @@ export class JournalSessionStore {
82
83
  hasUser(uuid) {
83
84
  return this.users.has(uuid);
84
85
  }
86
+ /**
87
+ * Resolve once the user message sent with this `uuid` is in the transcript (`hasUser`): the CLI took it, as a turn's
88
+ * own message or, mid-turn, as a `queued_command` attachment. Never rejects; it waits as long as the store lives.
89
+ */
90
+ whenUser(uuid) {
91
+ if (this.users.has(uuid))
92
+ return Promise.resolve();
93
+ return new Promise((resolve) => this.userWaiters.set(uuid, [...(this.userWaiters.get(uuid) ?? []), resolve]));
94
+ }
85
95
  /** Whether an assistant entry that made this tool call is in the transcript. */
86
96
  hasCall(toolUseId) {
87
97
  return this.calls.has(toolUseId);
@@ -172,10 +182,10 @@ export class JournalSessionStore {
172
182
  }
173
183
  note(entry) {
174
184
  if (entry.type === 'user' && entry.uuid)
175
- this.users.add(entry.uuid);
185
+ this.user(entry.uuid);
176
186
  const attachment = entry.type === 'attachment' ? entry.attachment : undefined;
177
187
  if (attachment?.type === 'queued_command' && typeof attachment.source_uuid === 'string')
178
- this.users.add(attachment.source_uuid);
188
+ this.user(attachment.source_uuid);
179
189
  for (const id of toolUseIds(entry)) {
180
190
  this.calls.add(id);
181
191
  for (const w of this.waiters.get(id) ?? [])
@@ -189,6 +199,12 @@ export class JournalSessionStore {
189
199
  this.resultWaiters.delete(id);
190
200
  }
191
201
  }
202
+ user(uuid) {
203
+ this.users.add(uuid);
204
+ for (const w of this.userWaiters.get(uuid) ?? [])
205
+ w();
206
+ this.userWaiters.delete(uuid);
207
+ }
192
208
  /**
193
209
  * Resolve once the user entry that answers `toolUseId` (its `tool_result`) is committed: a call the CLI answered
194
210
  * itself (a refusal) is told to the host only once the log holds the answer. Rejects after `timeoutMs`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-harness-claude",
3
- "version": "0.1.0-beta.39",
3
+ "version": "0.1.0-beta.41",
4
4
  "description": "The Claude Agent SDK as an AgentRun harness: the host's tools as its only tools, its model behind a loopback proxy, durable in AgentRun's own store.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -48,7 +48,7 @@
48
48
  "test": "node --test --test-concurrency=8 'test/*.test.mjs'"
49
49
  },
50
50
  "dependencies": {
51
- "@parcha/agentrun-kernel": "0.1.0-beta.39"
51
+ "@parcha/agentrun-kernel": "0.1.0-beta.41"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@anthropic-ai/claude-agent-sdk": "0.3.286",
@@ -77,6 +77,6 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@anthropic-ai/claude-agent-sdk": "0.3.286",
80
- "@parcha/agentrun-dsl": "0.1.0-beta.39"
80
+ "@parcha/agentrun-dsl": "0.1.0-beta.41"
81
81
  }
82
82
  }