@parcha/agentrun-harness-claude 0.1.0-beta.34 → 0.1.0-beta.35
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 +16 -0
- package/dist/host/policy.d.ts +9 -5
- package/dist/host/policy.js +31 -12
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.35 (2026-11-11)
|
|
6
|
+
|
|
7
|
+
- A capped run straight to Anthropic is no longer paused by a cap it could work under. Before each answer request on a route to `https://api.anthropic.com` (pi and claude-agent), the model proxy asks Anthropic's free token count (`POST /v1/messages/count_tokens`). It sends only the credential and version headers, and never goes through a gateway or any other base. The request's input bound is then that count plus the tool-use prompt, where before it was the body's bytes (about two to three times the tokens billed). A count that fails, says nothing or takes over 3 seconds leaves the byte bound, and the request goes on. Through OpenRouter or any other gateway the bound stays the bytes, so the cap still never passes.
|
|
8
|
+
|
|
9
|
+
The serve README's spend-cap section now states the smallest cap that works, by cap mode, measured on a pi desktop run on Sonnet. In `strict` mode (and in `expected`, the default, until the runner prices a step from the previous request's cache, #2504) it is $0.05 for the first request and $0.11 for a five-step run through a gateway, and $0.03 and $0.09 straight to Anthropic. The console's cap fields say it in a line, with a link. A cap below these still pauses with `Not sent: ... the next step needs at least $X`. A policy may count a request through `ProviderPolicy.countInput` (`InputCounter`, `countedInputOf` in the kernel host).
|
|
10
|
+
- A capped run that reads screenshots is no longer refused at its cap after the first one. A model request's input bound counted an image's base64 as one token per byte, and then the image's billed maximum on top. A 1280x720 screenshot (about a megabyte of base64) read as some 1.3 million input tokens, so a Sonnet step under a $1.50 cap "needed at least $4.83" when Claude bills it a few cents.
|
|
11
|
+
|
|
12
|
+
Each image, in every turn, now counts at what the routed model's provider can bill it as, in place of its data's bytes, whatever API carries it. The size comes from the image's own header (PNG, JPEG, GIF or WebP):
|
|
13
|
+
- Anthropic: its 28-pixel patches or its area at 750 pixels a token, whichever is more, at most 4,784.
|
|
14
|
+
- OpenAI: its 512-pixel tiles after resizing (85 + 170 each; 85 at detail low), or for a patch-billed mini or nano model its 32-pixel patches at that model's multiplier when more, at most 73,800.
|
|
15
|
+
- Google: 258 per 768-pixel tile, at least 1,120.
|
|
16
|
+
- Any other provider: the most of the three.
|
|
17
|
+
An image whose size can't be read counts at its provider's per-image maximum, never at its bytes. An image-shaped object outside where the API reads images (a tool call's arguments) is counted at its bytes, as text.
|
|
18
|
+
|
|
19
|
+
`InputShape.images` (the kernel host's `providerInputOverhead`) is now a list of images, each with the bytes its data takes and its size when known; `InputShape.model` names the routed model; the figure can be below 0, and so can a policy's `serverInputOverhead`, never past the body's bytes. Upgrading: pass `images: [{ bytes, width?, height? }]`, built with `imageInputOf`, `messagesImagesIn` or `responsesImagesIn`, and the model, in place of a count.
|
|
20
|
+
|
|
5
21
|
## 0.1.0-beta.34 (2026-11-11)
|
|
6
22
|
|
|
7
23
|
- The server checks a harness's pinned binary (claude-agent's CLI, Codex, OpenCode: its sha256, then the version it reports) without holding its event loop, so requests, timers and store answers go on while a binary of hundreds of MiB is hashed and run. Before, the first check in a process held every request for one to several seconds (GET /v2/capabilities, a server's start, an adapter made for a run). The binary is now hashed off the loop a chunk at a time and run as a child the loop does not wait on. A pass is kept for the adapter's own check, which then reads nothing, and two checks of one binary at once read it once. New: `checkedOnceAsync` and `sha256OfFileAsync` (kernel host), `verifyClaudeAgentCliAsync` (claude-agent), and `verifyCodexAsync` and `verifyCodexBinaryAsync` (Codex). Who breaks: a program that calls the kernel's `checkedOnce` with its own check. A check is now a `BinaryCheck`, a generator that yields each probe (`{ kind: "sha256", path }` or `{ kind: "run", path, args, env, timeoutMs }`) and is given back its answer, so one check runs either way.
|
package/dist/host/policy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ProviderPolicy, type ProxyRequestContext, type ProxyRoute, type ProxyUsage } from "@parcha/agentrun-kernel/host";
|
|
1
|
+
import { type InputCounter, type ProviderPolicy, type ProxyRequestContext, type ProxyRoute, type ProxyUsage } from "@parcha/agentrun-kernel/host";
|
|
2
2
|
/** The prefix of the session's own tools, as the CLI names them (its in-process MCP server, `hands`). */
|
|
3
3
|
export declare const OWN_TOOL_PREFIX = "mcp__hands__";
|
|
4
4
|
export declare const CLAUDE_MESSAGES_ROUTES: readonly ProxyRoute[];
|
|
@@ -99,10 +99,14 @@ export declare function anthropicFiltered(text: string): boolean;
|
|
|
99
99
|
* tools, its own, built-in or remote (a remote MCP server's). The CLI's side calls (a title, a summary, a web search's
|
|
100
100
|
* own request) offer none of them; in a session with no tools no request can be told from one, so each is the turn's. */
|
|
101
101
|
export declare function anthropicAnswers(body: Record<string, unknown>, options: Pick<AnthropicPolicyOptions, "tools" | "builtins" | "mcpTools">): boolean;
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
102
|
+
/**
|
|
103
|
+
* Anthropic's own count of a Messages request's input tokens: POST /v1/messages/count_tokens, free, on api.anthropic.com
|
|
104
|
+
* only ("Token counting", https://platform.claude.com/docs/en/build-with-claude/token-counting). The proxy asks it before
|
|
105
|
+
* each answer request on that origin (never through a gateway). Its `input_tokens` covers the request's
|
|
106
|
+
* system, messages, tools and images; the tool-use system prompt is added beside it (`margin`), in case the count leaves
|
|
107
|
+
* it out, so the bound never falls under what the request is billed.
|
|
108
|
+
*/
|
|
109
|
+
export declare const ANTHROPIC_INPUT_COUNTER: InputCounter;
|
|
106
110
|
export declare function anthropicServerInputOverhead(body: Record<string, unknown>, searchAllowance?: number): number | undefined;
|
|
107
111
|
/** `body` (a Messages body) with `text` as a note the model reads after everything the Claude CLI sent: one text block, in
|
|
108
112
|
* a <system-reminder>, at the end of the last user message (after its tool results), or a user message of its own after
|
package/dist/host/policy.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// is dropped, so the model is offered exactly the host's tools. With `webSearch`, one hosted tool passes: Anthropic's web
|
|
19
19
|
// search, exactly as the pinned CLI asks for it in the request its WebSearch tool makes. Usage is read from the stream's
|
|
20
20
|
// `message_start` (input and cache tokens) and its last `message_delta` (output, and the searches the provider ran).
|
|
21
|
-
import { providerInputOverhead, ProxyRefusal } from "@parcha/agentrun-kernel/host";
|
|
21
|
+
import { messagesImagesIn, providerInputOverhead, ProxyRefusal } from "@parcha/agentrun-kernel/host";
|
|
22
22
|
/** The prefix of the session's own tools, as the CLI names them (its in-process MCP server, `hands`). */
|
|
23
23
|
export const OWN_TOOL_PREFIX = "mcp__hands__";
|
|
24
24
|
const ANTHROPIC_HEADERS = ["anthropic-version", "anthropic-beta"];
|
|
@@ -383,18 +383,34 @@ export function anthropicAnswers(body, options) {
|
|
|
383
383
|
return Array.isArray(body.tools) && body.tools.some((tool) => isPlain(tool) && typeof tool.name === "string" && allowed.has(tool.name));
|
|
384
384
|
}
|
|
385
385
|
/** The Claude Agent CLI's provider policy for one session. */
|
|
386
|
-
/** The
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (!isPlain(value))
|
|
391
|
-
return 0;
|
|
392
|
-
return (value.type === "image" ? 1 : 0) + Object.values(value).reduce((n, item) => n + imagesIn(item), 0);
|
|
393
|
-
}
|
|
394
|
-
/** The input tokens the provider bills for `body` that it does not carry (`providerInputOverhead`, with its sources): the
|
|
395
|
-
* tool-use system prompt when it has tools, and for each image the most it can be billed as, beyond its bytes. None
|
|
386
|
+
/** The input tokens the provider bills for `body` beyond its bytes (`providerInputOverhead`, with its sources): the
|
|
387
|
+
* tool-use system prompt when it has tools, and each image at the most it can be billed as by its size, in place of the
|
|
388
|
+
* bytes its base64 takes in the body (below 0 for a screenshot, whose megabyte of base64 Claude bills as some 1,200
|
|
389
|
+
* tokens). None
|
|
396
390
|
* can be said for a body with the web search tool: the provider bills the pages it finds as input, on each of its
|
|
397
391
|
* searches, so its input is unmeasured (undefined), never bounded by its bytes. */
|
|
392
|
+
/** The fields of a Messages body the token-count endpoint takes (the rest, such as max_tokens and stream, it refuses). */
|
|
393
|
+
const COUNTED_FIELDS = ["model", "messages", "system", "tools", "tool_choice", "thinking"];
|
|
394
|
+
/** The request headers the count is sent with: the credential's and the API's version and betas, nothing else. */
|
|
395
|
+
const COUNT_HEADERS = new Set(["x-api-key", "authorization", "anthropic-version", "anthropic-beta"]);
|
|
396
|
+
/**
|
|
397
|
+
* Anthropic's own count of a Messages request's input tokens: POST /v1/messages/count_tokens, free, on api.anthropic.com
|
|
398
|
+
* only ("Token counting", https://platform.claude.com/docs/en/build-with-claude/token-counting). The proxy asks it before
|
|
399
|
+
* each answer request on that origin (never through a gateway). Its `input_tokens` covers the request's
|
|
400
|
+
* system, messages, tools and images; the tool-use system prompt is added beside it (`margin`), in case the count leaves
|
|
401
|
+
* it out, so the bound never falls under what the request is billed.
|
|
402
|
+
*/
|
|
403
|
+
export const ANTHROPIC_INPUT_COUNTER = Object.freeze({
|
|
404
|
+
origin: "https://api.anthropic.com",
|
|
405
|
+
path: "/v1/messages/count_tokens",
|
|
406
|
+
body: (body) => Object.fromEntries(COUNTED_FIELDS.filter((field) => body[field] !== undefined).map((field) => [field, body[field]])),
|
|
407
|
+
headers: (sent) => Object.fromEntries(Object.entries(sent).filter(([name]) => COUNT_HEADERS.has(name.toLowerCase()))),
|
|
408
|
+
tokensOf: (answer) => (isPlain(answer) && typeof answer.input_tokens === "number" ? answer.input_tokens : undefined),
|
|
409
|
+
margin: (body) => {
|
|
410
|
+
const choice = isPlain(body.tool_choice) ? body.tool_choice.type : undefined;
|
|
411
|
+
return providerInputOverhead("anthropic-messages", { tools: Array.isArray(body.tools) && body.tools.length > 0, ...(choice === "auto" || choice === "none" || choice === "any" || choice === "tool" ? { toolChoice: choice } : {}), images: [] });
|
|
412
|
+
},
|
|
413
|
+
});
|
|
398
414
|
export function anthropicServerInputOverhead(body, searchAllowance) {
|
|
399
415
|
const searches = offersWebSearch(body);
|
|
400
416
|
if (searches && searchAllowance === undefined)
|
|
@@ -403,7 +419,9 @@ export function anthropicServerInputOverhead(body, searchAllowance) {
|
|
|
403
419
|
const shape = {
|
|
404
420
|
tools: Array.isArray(body.tools) && body.tools.length > 0,
|
|
405
421
|
...(choice === "auto" || choice === "none" || choice === "any" || choice === "tool" ? { toolChoice: choice } : {}),
|
|
406
|
-
images:
|
|
422
|
+
images: messagesImagesIn(body.messages),
|
|
423
|
+
// Its images at the routed model's provider's rule (a gateway may route the Messages API to another vendor's model).
|
|
424
|
+
...(typeof body.model === "string" ? { model: body.model } : {}),
|
|
407
425
|
};
|
|
408
426
|
return providerInputOverhead("anthropic-messages", shape) + (searches ? searchAllowance : 0);
|
|
409
427
|
}
|
|
@@ -451,6 +469,7 @@ export function anthropicPolicy(options) {
|
|
|
451
469
|
modelOf: (body) => (typeof body.model === "string" ? body.model : undefined),
|
|
452
470
|
serverInputOverhead: options.webSearchAllowance === undefined ? anthropicServerInputOverhead : (body) => anthropicServerInputOverhead(body, options.webSearchAllowance),
|
|
453
471
|
outputAsked: anthropicOutputAsked,
|
|
472
|
+
countInput: ANTHROPIC_INPUT_COUNTER,
|
|
454
473
|
outputLeast: anthropicOutputLeast,
|
|
455
474
|
reasoningHidden: anthropicReasoningHidden,
|
|
456
475
|
reasoningBytesOf: anthropicReasoningBytes,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-harness-claude",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.35",
|
|
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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "Parcha Labs, Inc.",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=24.
|
|
16
|
+
"node": ">=24.22.3"
|
|
17
17
|
},
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"test": "node --test --test-concurrency=8 'test/*.test.mjs'"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
52
|
-
"@parcha/agentrun-kernel": "0.1.0-beta.
|
|
51
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.35",
|
|
52
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.35"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@anthropic-ai/claude-agent-sdk": "0.3.286",
|