@parcha/agentrun-kernel 0.1.0-beta.45 → 0.1.0-beta.47

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,11 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.47 (2026-11-19)
6
+
7
+ - A pi run's model requests that answer at about the same time are each priced at their own cost. When one turn started several `subagent` calls, the child whose answer asked first was given every child's booking and the others $0, so the run page's Timeline and Dev tools tab and `GET /v2/runs/{id}/trace` showed one request at the sum (three requests of the same tokens at $0.02163, $0.01266 and $0.04326, say) and others at $0. Each answer now reads the bookings of its own conversation's requests. The run's cost was right throughout and does not change; a run already recorded keeps the per-request figures it was written with. <!-- changes/parallel-request-costs.md -->
8
+ The session's model proxy takes a new request header, `x-agentrun-conversation` (`CONVERSATION_HEADER`, exported from `@parcha/agentrun-kernel/host`): a client may name the conversation a request is asked in, an id-shaped label of its own. The proxy tells the host with the request (`ProxyRequest.conversation`, `ModelRequest.conversation`) and never sends the header to the provider. A request that names none is asked as before.
9
+
5
10
  ## 0.1.0-beta.45 (2026-11-18)
6
11
 
7
12
  - Goose 1.59.2 runs as an AgentRun harness on the ACP adapter: `gooseAdapter({ binary, model, provider, price })` checks the binary's sha256 against its pin, starts `goose acp` from the shipped recipe (`recipes/goose.json`, loaded by `recipeFile` and `gooseRecipe`), and points each Goose process at a model proxy of its own (`gooseProxy`) on the session's booking, so the run's cap and books hold as they do for Claude Code. <!-- changes/acp-goose-harness.md -->
@@ -1,6 +1,6 @@
1
1
  export { ANTHROPIC_IMAGE_TOKENS_MAX, ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS, ASSUMED_TOOL_PROMPT_TOKENS, anthropicImageTokens, GEMINI_HIGH_RESOLUTION_TOKENS, geminiImageTokens, imageInputOf, imageProviderOf, imageSizeOf, imageTokens, INPUT_OVERHEAD_APIS, LOCAL_COUNT_MARGIN, messagesImagesIn, messagesInputAfter, messagesLocalInputTokens, OPENAI_IMAGE_TOKENS_MAX, openaiImageTokens, openaiPatchMultiplier, providerInputOverhead, responsesEscapedBytes, responsesImagesIn, responsesInputAfter, responsesInputOverhead, responsesLocalInputTokens, type BilledRequest, type ImageInput, type InputShape } from "./overhead.js";
2
2
  export { O200K_SHA256, O200K_VOCABULARY, o200kModel, o200kTokens } from "./o200k.js";
3
- export { COUNT_TIMEOUT_MS, countedInputOf, CredentialUnavailable, localInputOf, hostHeaderProblems, lastObjectOf, NATIVE_SEARCH_USD, ProxyRefusal, ROUTE_ORIGIN, sameKey, startModelProxy, statesUsageCost, streamErrorOf, usageCostOf } from "./proxy.js";
3
+ export { CONVERSATION_HEADER, conversationLabel, COUNT_TIMEOUT_MS, countedInputOf, CredentialUnavailable, localInputOf, hostHeaderProblems, lastObjectOf, NATIVE_SEARCH_USD, ProxyRefusal, ROUTE_ORIGIN, sameKey, startModelProxy, statesUsageCost, streamErrorOf, usageCostOf } from "./proxy.js";
4
4
  export { OPENROUTER_APP, OPENROUTER_ATTRIBUTION_ENV, onOpenRouter, openRouterApp, openRouterAttribution } from "./openrouter-attribution.js";
5
5
  export type { InputCounter, ModelProxy, ModelProxyHooks, ModelProxyOptions, ModelUsageReport, ProviderPolicy, ProxyRequest, ProxyRequestContext, ProxyRoute, ProxyUsage, ReasoningSeen, StreamError } from "./proxy.js";
6
6
  export { processAlive } from "./alive.js";
@@ -2,7 +2,7 @@
2
2
  // provider's rules in a `ProviderPolicy`. Written for AgentRun.
3
3
  export { ANTHROPIC_IMAGE_TOKENS_MAX, ANTHROPIC_TOOL_USE_SYSTEM_PROMPT_TOKENS, ASSUMED_TOOL_PROMPT_TOKENS, anthropicImageTokens, GEMINI_HIGH_RESOLUTION_TOKENS, geminiImageTokens, imageInputOf, imageProviderOf, imageSizeOf, imageTokens, INPUT_OVERHEAD_APIS, LOCAL_COUNT_MARGIN, messagesImagesIn, messagesInputAfter, messagesLocalInputTokens, OPENAI_IMAGE_TOKENS_MAX, openaiImageTokens, openaiPatchMultiplier, providerInputOverhead, responsesEscapedBytes, responsesImagesIn, responsesInputAfter, responsesInputOverhead, responsesLocalInputTokens } from "./overhead.js";
4
4
  export { O200K_SHA256, O200K_VOCABULARY, o200kModel, o200kTokens } from "./o200k.js";
5
- export { COUNT_TIMEOUT_MS, countedInputOf, CredentialUnavailable, localInputOf, hostHeaderProblems, lastObjectOf, NATIVE_SEARCH_USD, ProxyRefusal, ROUTE_ORIGIN, sameKey, startModelProxy, statesUsageCost, streamErrorOf, usageCostOf } from "./proxy.js";
5
+ export { CONVERSATION_HEADER, conversationLabel, COUNT_TIMEOUT_MS, countedInputOf, CredentialUnavailable, localInputOf, hostHeaderProblems, lastObjectOf, NATIVE_SEARCH_USD, ProxyRefusal, ROUTE_ORIGIN, sameKey, startModelProxy, statesUsageCost, streamErrorOf, usageCostOf } from "./proxy.js";
6
6
  export { OPENROUTER_APP, OPENROUTER_ATTRIBUTION_ENV, onOpenRouter, openRouterApp, openRouterAttribution } from "./openrouter-attribution.js";
7
7
  export { processAlive } from "./alive.js";
8
8
  export { serialWriter } from "./serial.js";
@@ -244,6 +244,8 @@ export interface ProxyRequest {
244
244
  noted?: true;
245
245
  /** The label of the side key it came under (ModelProxy.sideKey): the host's own request, beside the harness's. */
246
246
  host?: string;
247
+ /** The conversation its client says it is asked in (CONVERSATION_HEADER), when it names one: its client's own label. */
248
+ conversation?: string;
247
249
  /** Aborted when its client goes before it is admitted (ModelRequest.signal): a wait for room ends then. */
248
250
  signal?: AbortSignal;
249
251
  }
@@ -354,6 +356,12 @@ export interface ProxyRequestContext {
354
356
  * name inside a JSON string is escaped (`\"usage\"`), so it never reads as one. Undefined when there is none, or the
355
357
  * last one does not close in `text` or does not parse. */
356
358
  export declare function lastObjectOf(text: string, key: string): unknown;
359
+ /** The request header by which a session's client names the conversation a request is asked in: its own label for it,
360
+ * opaque here. The host is told it with the request (ProxyRequest.conversation), so it knows which of several
361
+ * conversations asking at once a booking is; it is never forwarded to the provider. */
362
+ export declare const CONVERSATION_HEADER = "x-agentrun-conversation";
363
+ /** A conversation's label as CONVERSATION_HEADER carries it: id-shaped (ID_VALUE), else undefined (never sent, never told). */
364
+ export declare function conversationLabel(value: unknown): string | undefined;
357
365
  /** The ids a response's headers give its request, by header name, so a run's books can be joined to the provider's (or
358
366
  * a gateway's) request by request; undefined when there are none. Only id-named headers with id-shaped values. */
359
367
  export declare function providerIdsOf(headers: Headers): Record<string, string> | undefined;
@@ -456,6 +456,14 @@ const RETRY_HEADERS = ["retry-after", "retry-after-ms", "x-should-retry"];
456
456
  const ID_HEADER = /^(?:[a-z0-9]+[-_])*(?:request|call)[-_]id$/;
457
457
  /** What an id looks like: nothing else (a cookie, a token, prose) is ever kept. */
458
458
  const ID_VALUE = /^[A-Za-z0-9_.:-]{1,200}$/;
459
+ /** The request header by which a session's client names the conversation a request is asked in: its own label for it,
460
+ * opaque here. The host is told it with the request (ProxyRequest.conversation), so it knows which of several
461
+ * conversations asking at once a booking is; it is never forwarded to the provider. */
462
+ export const CONVERSATION_HEADER = "x-agentrun-conversation";
463
+ /** A conversation's label as CONVERSATION_HEADER carries it: id-shaped (ID_VALUE), else undefined (never sent, never told). */
464
+ export function conversationLabel(value) {
465
+ return typeof value === "string" && ID_VALUE.test(value) ? value : undefined;
466
+ }
459
467
  /** The ids a response's headers give its request, by header name, so a run's books can be joined to the provider's (or
460
468
  * a gateway's) request by request; undefined when there are none. Only id-named headers with id-shaped values. */
461
469
  export function providerIdsOf(headers) {
@@ -965,6 +973,8 @@ export async function startModelProxy(options, key) {
965
973
  const host = sameKey(sentKey, key) ? undefined : sideOf(sentKey);
966
974
  if (host === undefined && !sameKey(sentKey, key))
967
975
  return refuse(res, 401, "this session's key is required", req);
976
+ // The conversation its client names for it, told to the host with its admission; no header sent on carries it.
977
+ const conversation = conversationLabel(req.headers[CONVERSATION_HEADER]);
968
978
  const chunks = [];
969
979
  let size = 0;
970
980
  for await (const chunk of req) {
@@ -1232,6 +1242,7 @@ export async function startModelProxy(options, key) {
1232
1242
  ...(effort === undefined ? {} : { effort }),
1233
1243
  ...(feeUsd > 0 ? { feeUsd } : {}),
1234
1244
  ...(host === undefined ? {} : { host }),
1245
+ ...(conversation === undefined ? {} : { conversation }),
1235
1246
  ...(options.route === undefined ? {} : { route: options.route }),
1236
1247
  });
1237
1248
  }
package/dist/index.d.ts CHANGED
@@ -10,4 +10,4 @@ export type { HarnessRunReason } from "./errors.js";
10
10
  export { CONTENT_FILTERED, HOST_RESULT_MAX_CHARS, hostedTool, PLAN_LIMIT_CODE, PLAN_LIMIT_WORDS } from "./types.js";
11
11
  export { bookRequest, isConnectCode, isGatewayTimeout, rejectionCode } from "./booking.js";
12
12
  export type { Booked, Ended, Priced } from "./booking.js";
13
- export type { AdapterEvent, AdapterSession, AgentAdapter, AdapterFacts, GateAnswer, GateCall, SessionPort, Wire, HarnessEvent, HostTool, McpCallResult, McpTool, NestedCalls, NestedResult, ToolImage, JsonValue, ModelPort, ModelTicket, CapCut, ModelRequest, ModelUsage, NoteRequest, NodeRequest, OwnCalls, SessionIO, SessionRecord, SessionSpec, SessionState, SessionStore, SessionWriter, ToolPermission, TurnStatus, } from "./types.js";
13
+ export type { AdapterEvent, AdapterSession, AgentAdapter, AdapterFacts, GateAnswer, GateCall, SessionPort, HarnessWire, Wire, HarnessEvent, HostTool, McpCallResult, McpTool, NestedCalls, NestedResult, ToolImage, JsonValue, ModelPort, ModelTicket, CapCut, ModelRequest, ModelUsage, NoteRequest, NodeRequest, OwnCalls, SessionIO, SessionRecord, SessionSpec, SessionState, SessionStore, SessionWriter, ToolPermission, TurnStatus, } from "./types.js";
package/dist/types.d.ts CHANGED
@@ -232,6 +232,10 @@ export interface ModelRequest {
232
232
  * the proxy minted for this label: ModelProxy.sideKey): a learned workflow's model node, say. The harness's own
233
233
  * requests carry none, and it cannot send one that does: it holds only the session's key. */
234
234
  host?: string;
235
+ /** The conversation its client says it is asked in (the model proxy's CONVERSATION_HEADER), when it names one: the
236
+ * client's own label, opaque to the booking and not written on its record. A host whose harness runs several
237
+ * conversations at once (pi's subagents) reads it to know whose request a booking is. */
238
+ conversation?: string;
235
239
  /** Which of the session's routes it came by, when the session has more than one (ModelProxyOptions.route: a proxy beside
236
240
  * the session's, for a model of another tier): the host prices it by its model and this route, so one model id two
237
241
  * routes price apart is held at the price its route books it at. Absent: the session's own route. */
@@ -521,6 +525,10 @@ export interface AdapterSession {
521
525
  }
522
526
  /** The API a harness's model proxy speaks: what its provider, its keys and its catalog follow from. */
523
527
  export type Wire = "anthropic-messages" | "openai-responses";
528
+ /** What a harness's facts say its model is reached on: a Wire of the host's proxy, or `plan`: none, its model is its
529
+ * vendor's, billed to its owner's plan on the owner's own key (Cursor), so no request of it reaches a proxy of the host's
530
+ * and no provider, key or catalog of the host's is its. */
531
+ export type HarnessWire = Wire | "plan";
524
532
  /** What a harness is, as its adapter states it: the host reads these and never branches on a harness's name. They
525
533
  * describe the harness; none renames or reshapes what its model sees, and none turns its own built-ins, sandbox or
526
534
  * session machine on. */
@@ -529,8 +537,8 @@ export interface AdapterFacts {
529
537
  readonly id: string;
530
538
  /** Its name in a sentence ("Claude", "Codex", "OpenCode"). */
531
539
  readonly label: string;
532
- /** The API its model proxy speaks. */
533
- readonly wire: Wire;
540
+ /** The API its model proxy speaks, or `plan` where none of the host's is its (HarnessWire). */
541
+ readonly wire: HarnessWire;
534
542
  /** Whether it takes a message mid-turn (else a message waits for the turn's end). */
535
543
  readonly steer: boolean;
536
544
  /** False when a tool call that started is never run again by a restart, replay-safe or not: the harness's own process
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-kernel",
3
- "version": "0.1.0-beta.45",
3
+ "version": "0.1.0-beta.47",
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.45",
65
+ "@parcha/agentrun-dsl": "0.1.0-beta.47",
66
66
  "ajv": "8.18.0",
67
67
  "typebox": "1.3.27"
68
68
  },