@parcha/agentrun-harness-claude 0.1.0-beta.36 → 0.1.0-beta.37
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 +15 -0
- package/dist/adapter.js +1 -1
- package/dist/harness.d.ts +2 -1
- package/dist/harness.js +29 -6
- package/dist/host/process.d.ts +1 -1
- package/dist/host/process.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/resume.d.ts +29 -0
- package/dist/resume.js +71 -12
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.37 (2026-11-13)
|
|
6
|
+
|
|
7
|
+
- A web_search setting of deny or ask now applies to a Claude Agent or Codex run's own web search at its next search, including a run that started while it was allow. Before, the setting was read only when the run started, so a run that started with native search kept searching after the setting changed.
|
|
8
|
+
- Claude Agent: each WebSearch asks the run's gate before it runs, as a host tool's call does. A deny refuses it in the gate's words. An ask parks the run on the person with nothing searched; once they allow it, the model's next search with the same query runs once, with no second card.
|
|
9
|
+
- Codex: its search runs inside the provider's model request, so its proxy reads web_search's setting before each request and offers the provider its search only while the setting is allow. A failed read offers no search.
|
|
10
|
+
- `SessionIO.permission(tool)` (agentrun-kernel) is the host's setting for a harness's own tool at the time of the read. The runner reads it from the store each time. `ProviderPolicy.apply` may return a promise.
|
|
11
|
+
- A runner run whose plane resolves web_search to native now gets the harness's own search (#2458). The runner had built the run's environment without its plane, so Claude Agent and Codex runs on a runner never had it on.
|
|
12
|
+
- A web_search that resolves to the model provider's own search works again on the runner for pi (#2458). It used to answer "web_search has no model to search on" every time:
|
|
13
|
+
- A pi run's own web_search on an Anthropic or OpenAI model. That is what `auto` picks for pi, and `native` too. Each search now goes through the run's model proxy with the provider's search tool, and its searches are booked at the provider's price on top of its tokens.
|
|
14
|
+
- A learned workflow's call node whose web_search resolves native, on any harness.
|
|
15
|
+
|
|
16
|
+
Each run's search uses that run's own model route, never one shared by the whole process. Hand-written workflow agents were not affected: their web_search never resolves native. Both harness packages now export their `withWebSearches` price wrapper, and the Codex one its `webSearchUsd`. A claude-agent or codex run's own search is not switched on by this change.
|
|
17
|
+
|
|
18
|
+
A capped run holds a hosted search's fees with its tokens before the request is sent, at the most searches the request allows, so the fees can't pass the cap. The kernel's model proxy takes a policy's `feeMaxUsd(body)` and holds it as the request's `feeUsd`; a fee it can't bound leaves the request unmeasured. The proxy also hands `usageOf` the sent body as a second argument, so a pi request on OpenAI's Responses that offered no search reads 0 searches from its body, even when its answer names a search call.
|
|
19
|
+
|
|
5
20
|
## 0.1.0-beta.36 (2026-11-13)
|
|
6
21
|
|
|
7
22
|
- Model defaults move to the current models. The OpenAI default (and OpenRouter's, for pi, codex and opencode) is now gpt-6.1-sol, where OpenRouter's was gpt-6-sol. The Claude Agent adapter's default is now claude-sonnet-5-5 (was claude-sonnet-4-5) and the Codex adapter's is openai/gpt-6-luna (was openai/gpt-5.4-mini). A host that relied on a default names its model; the READMEs' examples name the current ones.
|
package/dist/adapter.js
CHANGED
|
@@ -394,7 +394,7 @@ export function claudeAgentAdapter(options) {
|
|
|
394
394
|
...(options.mcp ? { toolServerModules: options.mcp } : {}),
|
|
395
395
|
...(options.log ? { log: options.log } : {}),
|
|
396
396
|
...(options.now ? { now: options.now } : {}),
|
|
397
|
-
// The host's gate, asked about each host-tool call before it is written or run.
|
|
397
|
+
// The host's gate, asked about each host-tool call and each WebSearch before it is written or run.
|
|
398
398
|
...(io.gate ? { gate: (call) => io.gate(call) } : {}),
|
|
399
399
|
});
|
|
400
400
|
const live = (event) => {
|
package/dist/harness.d.ts
CHANGED
|
@@ -236,7 +236,8 @@ export interface ClaudeCodeHarnessOptions {
|
|
|
236
236
|
unsandboxedCommands?: boolean;
|
|
237
237
|
/** Called with the child's stderr tail when it exits mid-turn, the gateway's refusals, and SDK diagnostics. */
|
|
238
238
|
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
239
|
-
/** The host's gate (SessionIO.gate), asked by the tool bridge about each call of `tools` before its intent
|
|
239
|
+
/** The host's gate (SessionIO.gate), asked by the tool bridge about each call of `tools` before its intent, and by the
|
|
240
|
+
* PreToolUse hook about each WebSearch (`providerTools: ['web_search']`) before its intent, by the CLI's name for it. */
|
|
240
241
|
gate?: (call: GateCall) => Promise<GateAnswer>;
|
|
241
242
|
/** The clock a user turn's day is read from (dateLine). Default the system's. */
|
|
242
243
|
now?: () => Date;
|
package/dist/harness.js
CHANGED
|
@@ -7,13 +7,13 @@ import { mkdtemp, rm } from 'node:fs/promises';
|
|
|
7
7
|
import { tmpdir } from 'node:os';
|
|
8
8
|
import { dirname, join, posix } from 'node:path';
|
|
9
9
|
import { Restart, Unavailable } from './host/kernel.js';
|
|
10
|
-
import { BuiltinCalls, CLAUDE_ROUTES, gatewayCredential, gatewayHandler, gatewayUrl, isBrandedMachine, NativeJournal, openTurn, placeSubmissions, recoveryNote, restartEvent, replayBy, toolBridge, waitForSubmissions, } from './host/process.js';
|
|
10
|
+
import { askGate, BuiltinCalls, CLAUDE_ROUTES, gatewayCredential, gatewayHandler, gatewayUrl, isBrandedMachine, NativeJournal, openTurn, placeSubmissions, recoveryNote, restartEvent, replayBy, toolBridge, toolKey, waitForSubmissions, } from './host/process.js';
|
|
11
11
|
import { durableEnv, nativeModelId } from './env.js';
|
|
12
12
|
import { uuidFrom } from './ids.js';
|
|
13
13
|
import { MessageQueue } from './inbox.js';
|
|
14
14
|
import { sandboxSpawn } from './spawn.js';
|
|
15
15
|
import { MCP_OUTPUT_TOKENS, toolServer } from './host/tool-server.js';
|
|
16
|
-
import { resumeDanglingCalls } from './resume.js';
|
|
16
|
+
import { releasedSearches, resumeDanglingCalls, resumeDanglingSearches, searchKey, WEB_SEARCH } from './resume.js';
|
|
17
17
|
import { JournalSessionStore } from './store.js';
|
|
18
18
|
import { MCP_SERVER, TranscriptBuilder } from './transcript.js';
|
|
19
19
|
import { CLAUDE_AGENT_CLI_SKILL_NAMES } from './cli-names.js';
|
|
@@ -292,11 +292,15 @@ export function claudeCodeHarness(options = {}) {
|
|
|
292
292
|
},
|
|
293
293
|
});
|
|
294
294
|
const gate = options.gate;
|
|
295
|
+
// The host's gate before the intent, so a refused or parked call leaves nothing of its own written. The assistant
|
|
296
|
+
// line that made the call is in the log before the gate is asked: a park ends the claim, and the resume finds the
|
|
297
|
+
// call it held dangling in the transcript, under the same id (resumeDanglingCalls, resumeDanglingSearches).
|
|
298
|
+
const gated = gate ? async (call) => (await store.barrier(call.callId, barrierMs), gate(call)) : undefined;
|
|
299
|
+
/** The WebSearch calls the gate held and a person let run that no search has taken up yet (releasedSearches, read
|
|
300
|
+
* from the transcript at the resume): the model's next search with one's input is put to the gate under its id. */
|
|
301
|
+
const released = [];
|
|
295
302
|
const bridge = toolBridge(ctx, tools, {
|
|
296
|
-
|
|
297
|
-
// assistant line that made the call is in the log before the gate is asked: a park ends the claim, and the
|
|
298
|
-
// resume finds the call it held dangling in the transcript, under the same id (resumeDanglingCalls).
|
|
299
|
-
...(gate ? { gate: async (call) => (await store.barrier(call.callId, barrierMs), gate(call)) } : {}),
|
|
303
|
+
...(gated ? { gate: gated } : {}),
|
|
300
304
|
// A `never` tool runs only once the assistant entry that asked for it is in the log.
|
|
301
305
|
beforeNever: ({ callId }) => store.barrier(callId, barrierMs),
|
|
302
306
|
});
|
|
@@ -383,6 +387,19 @@ export function claudeCodeHarness(options = {}) {
|
|
|
383
387
|
return deny("Not run: this session's only tools are its own.");
|
|
384
388
|
if (ctx.signal.aborted)
|
|
385
389
|
return deny('the session stopped');
|
|
390
|
+
// The host's gate decides every native search, as it does a host tool's call, before anything of it
|
|
391
|
+
// is written: a deny refuses it in the gate's words, an ask holds it until the person answers (the
|
|
392
|
+
// run parks), each read at this call, so a setting changed mid-run reaches the next search. The model's
|
|
393
|
+
// search again of one the gate held and a person let run is asked under the held call's id, which their
|
|
394
|
+
// answer covers: no second card, and a deny set since still refuses it.
|
|
395
|
+
if (webSearch && hook.tool_name === WEB_SEARCH && gated && !ctx.isMemoized(toolKey(hook.tool_use_id))) {
|
|
396
|
+
const at = released.findIndex((one) => one.key === searchKey(hook.tool_input));
|
|
397
|
+
const callId = at >= 0 ? released.splice(at, 1)[0].callId : hook.tool_use_id;
|
|
398
|
+
const replayed = ctx.state().effects.has(toolKey(hook.tool_use_id));
|
|
399
|
+
const refused = await askGate(gated, { callId, tool: hook.tool_name, args: (hook.tool_input ?? {}), ...(replayed ? { replayed: true } : {}) }, ctx.signal);
|
|
400
|
+
if (refused)
|
|
401
|
+
return deny(refused.deny);
|
|
402
|
+
}
|
|
386
403
|
let updated;
|
|
387
404
|
const field = FILE_TOOLS[hook.tool_name];
|
|
388
405
|
if (field) {
|
|
@@ -487,6 +504,12 @@ export function claudeCodeHarness(options = {}) {
|
|
|
487
504
|
// One with an intent is left to the CLI's repair and the recovery note, as before; nothing ever runs one twice.
|
|
488
505
|
if (store.hasSession)
|
|
489
506
|
await resumeDanglingCalls(ctx, bridge, store);
|
|
507
|
+
// A WebSearch the gate held (an ask): put to it again, under its own id, before the CLI resumes. Then every release
|
|
508
|
+
// the transcript holds that no search has taken up, this resume's and one a restart cut off before the search.
|
|
509
|
+
if (store.hasSession && webSearch && gated) {
|
|
510
|
+
await resumeDanglingSearches(ctx, store, gated);
|
|
511
|
+
released.push(...releasedSearches(store.lines()));
|
|
512
|
+
}
|
|
490
513
|
// A turn a crash cut off: the harness's own account of it (which calls completed, which may have half-run) goes
|
|
491
514
|
// in this drive's system prompt, not in a user message the model might answer back to the user. A resumed
|
|
492
515
|
// session sends the system prompt recorded at its start (`snapshot`), whatever a later launch passes, so this
|
package/dist/host/process.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DriveContext } from "./kernel.js";
|
|
2
|
-
export { BuiltinCalls, NativeJournal, openTurn, placeSubmissions, recoveryNote, replayBy, restartEvent, resumeUnstartedCalls, toolBridge, waitForSubmissions, zodShapeFromJsonSchema, } from "@parcha/agentrun-kernel/process";
|
|
2
|
+
export { askGate, BuiltinCalls, NativeJournal, openTurn, placeSubmissions, recoveryNote, replayBy, restartEvent, resumeUnstartedCalls, toolBridge, toolKey, unstartedCalls, waitForSubmissions, zodShapeFromJsonSchema, } from "@parcha/agentrun-kernel/process";
|
|
3
3
|
export type { CallOutcome, DanglingCall, JournalRecord, ToolBridge, TranscriptEntry } from "@parcha/agentrun-kernel/process";
|
|
4
4
|
export type KillSignal = "SIGTERM" | "SIGKILL" | "SIGINT";
|
|
5
5
|
/** A running child of the session. */
|
package/dist/host/process.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BuiltinCalls, NativeJournal, openTurn, placeSubmissions, recoveryNote, replayBy, restartEvent, resumeUnstartedCalls, toolBridge, waitForSubmissions, zodShapeFromJsonSchema, } from "@parcha/agentrun-kernel/process";
|
|
1
|
+
export { askGate, BuiltinCalls, NativeJournal, openTurn, placeSubmissions, recoveryNote, replayBy, restartEvent, resumeUnstartedCalls, toolBridge, toolKey, unstartedCalls, waitForSubmissions, zodShapeFromJsonSchema, } from "@parcha/agentrun-kernel/process";
|
|
2
2
|
const BRAND = Symbol.for("agentrun.claude-agent.session-machine");
|
|
3
3
|
/** Mark a machine as made by this package's factory. */
|
|
4
4
|
export function brandMachine(machine) {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { ClaudeAgentPin } from "./errors.js";
|
|
|
4
4
|
export type { ClaudeAgentAdapterOptions, ClaudeAgentProvider, ClaudeAgentSkill, ClaudeAgentThinking } from "./adapter.js";
|
|
5
5
|
export { CLAUDE_AGENT_SDK_INSTALL, CLAUDE_AGENT_SDK_VERSION, CLAUDE_CODE_VERSION as CLAUDE_AGENT_CLI_VERSION } from "./versions.js";
|
|
6
6
|
export { findClaudeExecutable as claudeAgentExecutable, platformSuffix as claudeAgentPlatform } from "./binary.js";
|
|
7
|
-
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, CLAUDE_WEB_SEARCH_USD, OWN_TOOL_PREFIX, thinks } from "./host/policy.js";
|
|
7
|
+
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, CLAUDE_WEB_SEARCH_USD, OWN_TOOL_PREFIX, thinks, withWebSearches } from "./host/policy.js";
|
|
8
8
|
export type { AnthropicPolicyOptions, AnthropicUsage } from "./host/policy.js";
|
|
9
9
|
export type { ChildCommand, ConfineChild } from "./host/machine.js";
|
|
10
10
|
export { listedTools, MCP_OUTPUT_TOKENS, RESULT_SIZE_KEY, toolServer, type ToolServerModules } from "./host/tool-server.js";
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,5 @@ export { CLAUDE_AGENT_ALSO_OFF, CLAUDE_AGENT_CLI_SKILL_NAMES, CLAUDE_AGENT_DIGES
|
|
|
3
3
|
export { CLAUDE_AGENT_PACKAGE, ClaudeAgentNotInstalled, ClaudeAgentPinMismatch, ClaudeAgentThinkingOff } from "./errors.js";
|
|
4
4
|
export { CLAUDE_AGENT_SDK_INSTALL, CLAUDE_AGENT_SDK_VERSION, CLAUDE_CODE_VERSION as CLAUDE_AGENT_CLI_VERSION } from "./versions.js";
|
|
5
5
|
export { findClaudeExecutable as claudeAgentExecutable, platformSuffix as claudeAgentPlatform } from "./binary.js";
|
|
6
|
-
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, CLAUDE_WEB_SEARCH_USD, OWN_TOOL_PREFIX, thinks } from "./host/policy.js";
|
|
6
|
+
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, CLAUDE_WEB_SEARCH_USD, OWN_TOOL_PREFIX, thinks, withWebSearches } from "./host/policy.js";
|
|
7
7
|
export { listedTools, MCP_OUTPUT_TOKENS, RESULT_SIZE_KEY, toolServer } from "./host/tool-server.js";
|
package/dist/resume.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GateAnswer, GateCall } from '@parcha/agentrun-kernel';
|
|
1
2
|
import { type CallOutcome, type DanglingCall, type ToolBridge } from './host/process.js';
|
|
2
3
|
import type { DriveContext } from './host/kernel.js';
|
|
3
4
|
import type { JournalSessionStore, TranscriptLine } from './store.js';
|
|
@@ -8,6 +9,34 @@ import type { JournalSessionStore, TranscriptLine } from './store.js';
|
|
|
8
9
|
* are the CLI's own.
|
|
9
10
|
*/
|
|
10
11
|
export declare function danglingCalls(lines: readonly TranscriptLine[]): DanglingCall[];
|
|
12
|
+
/** The CLI's own WebSearch calls the transcript's last turn left without a result, as `danglingCalls` finds host-tool
|
|
13
|
+
* ones (tool: `WebSearch`). */
|
|
14
|
+
export declare function danglingSearches(lines: readonly TranscriptLine[]): DanglingCall[];
|
|
15
|
+
/** The CLI's name for its own web search. */
|
|
16
|
+
export declare const WEB_SEARCH = "WebSearch";
|
|
17
|
+
/** The answer a held WebSearch gets on the resume once the host's gate lets it run: the CLI ran nothing of it, and the
|
|
18
|
+
* model's next search with the same input runs on that answer (resumeDanglingSearches, releasedSearches). */
|
|
19
|
+
export declare const SEARCH_RELEASED = "Not searched yet: this search was held before it ran, and it may run now. Search again with the same query to run it.";
|
|
20
|
+
/**
|
|
21
|
+
* Before the CLI resumes the transcript: each dangling WebSearch that never started (the host's gate held it: its run
|
|
22
|
+
* parked on a person) is put to the gate again, under the id the model gave it. A deny answers it in the gate's words; an
|
|
23
|
+
* allow answers it SEARCH_RELEASED, since the provider runs a search only inside the CLI's own model request: the
|
|
24
|
+
* model's next search with the same input is then put to the gate under this call's id (releasedSearches), which the
|
|
25
|
+
* person's answer covers, so it asks no second card. A gate that parks again rejects out of here; what it wrote is the
|
|
26
|
+
* same lines again on the next resume.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resumeDanglingSearches(ctx: DriveContext, store: JournalSessionStore, gate: (call: GateCall) => Promise<GateAnswer>): Promise<void>;
|
|
29
|
+
/** The key a WebSearch's input is matched by: the model's next search "with the same query" is one with this input. */
|
|
30
|
+
export declare const searchKey: (input: unknown) => string;
|
|
31
|
+
/**
|
|
32
|
+
* The WebSearch calls the transcript answered SEARCH_RELEASED that no later WebSearch with the same input has taken up
|
|
33
|
+
* yet, oldest first: each `{ callId, key }`, so the model's next search with that input is put to the gate under the held
|
|
34
|
+
* call's id. Read from the transcript, so a release survives a restart between its answer and the model's search.
|
|
35
|
+
*/
|
|
36
|
+
export declare function releasedSearches(lines: readonly TranscriptLine[]): {
|
|
37
|
+
callId: string;
|
|
38
|
+
key: string;
|
|
39
|
+
}[];
|
|
11
40
|
/**
|
|
12
41
|
* The user line that answers `call` with its outcome, as Claude Code writes an MCP tool's result: after the
|
|
13
42
|
* transcript's last line, with the session fields of the assistant line that made the call. Its `uuid` is the call's,
|
package/dist/resume.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// which calls those are, read from the transcript the drive is about to resume, and how one's result is written into
|
|
3
|
-
// it. The decision (run it, or leave it to the CLI's own repair) is the shared one, `resumeUnstartedCalls`: only a call
|
|
4
|
-
// with no effect of its own on the run's journal runs here, through the tool bridge (the host's gate first, then its
|
|
5
|
-
// intent, the call and its result), and only then is its result written here, before the CLI starts again. A call
|
|
6
|
-
// that has an effect is left as before: the CLI answers it "[Tool call interrupted]", and the recovery note says what
|
|
7
|
-
// the log knows of it.
|
|
8
|
-
import { resumeUnstartedCalls } from './host/process.js';
|
|
1
|
+
import { askGate, resumeUnstartedCalls, unstartedCalls } from './host/process.js';
|
|
9
2
|
import { uuidFrom } from './ids.js';
|
|
10
3
|
import { toolResultIds } from './store.js';
|
|
11
4
|
import { MCP_SERVER } from './transcript.js';
|
|
@@ -25,6 +18,72 @@ const isPrompt = (line) => line.type === 'user' && line.isSidechain !== true &&
|
|
|
25
18
|
* are the CLI's own.
|
|
26
19
|
*/
|
|
27
20
|
export function danglingCalls(lines) {
|
|
21
|
+
return danglingOf(lines, (name) => (name.startsWith(BRIDGED) ? name.slice(BRIDGED.length) : undefined));
|
|
22
|
+
}
|
|
23
|
+
/** The CLI's own WebSearch calls the transcript's last turn left without a result, as `danglingCalls` finds host-tool
|
|
24
|
+
* ones (tool: `WebSearch`). */
|
|
25
|
+
export function danglingSearches(lines) {
|
|
26
|
+
return danglingOf(lines, (name) => (name === WEB_SEARCH ? name : undefined));
|
|
27
|
+
}
|
|
28
|
+
/** The CLI's name for its own web search. */
|
|
29
|
+
export const WEB_SEARCH = 'WebSearch';
|
|
30
|
+
/** The answer a held WebSearch gets on the resume once the host's gate lets it run: the CLI ran nothing of it, and the
|
|
31
|
+
* model's next search with the same input runs on that answer (resumeDanglingSearches, releasedSearches). */
|
|
32
|
+
export const SEARCH_RELEASED = 'Not searched yet: this search was held before it ran, and it may run now. Search again with the same query to run it.';
|
|
33
|
+
/**
|
|
34
|
+
* Before the CLI resumes the transcript: each dangling WebSearch that never started (the host's gate held it: its run
|
|
35
|
+
* parked on a person) is put to the gate again, under the id the model gave it. A deny answers it in the gate's words; an
|
|
36
|
+
* allow answers it SEARCH_RELEASED, since the provider runs a search only inside the CLI's own model request: the
|
|
37
|
+
* model's next search with the same input is then put to the gate under this call's id (releasedSearches), which the
|
|
38
|
+
* person's answer covers, so it asks no second card. A gate that parks again rejects out of here; what it wrote is the
|
|
39
|
+
* same lines again on the next resume.
|
|
40
|
+
*/
|
|
41
|
+
export async function resumeDanglingSearches(ctx, store, gate) {
|
|
42
|
+
const held = unstartedCalls(ctx, danglingSearches(store.lines()));
|
|
43
|
+
for (const call of held) {
|
|
44
|
+
const refused = await askGate(gate, { callId: call.callId, tool: call.tool, args: (call.args ?? {}) }, ctx.signal);
|
|
45
|
+
store.extend(resultLine(store.lines(), call, refused ? { text: refused.deny, isError: true } : { text: SEARCH_RELEASED, isError: true }));
|
|
46
|
+
}
|
|
47
|
+
if (held.length)
|
|
48
|
+
await store.flush();
|
|
49
|
+
}
|
|
50
|
+
/** The key a WebSearch's input is matched by: the model's next search "with the same query" is one with this input. */
|
|
51
|
+
export const searchKey = (input) => JSON.stringify(input ?? {});
|
|
52
|
+
/**
|
|
53
|
+
* The WebSearch calls the transcript answered SEARCH_RELEASED that no later WebSearch with the same input has taken up
|
|
54
|
+
* yet, oldest first: each `{ callId, key }`, so the model's next search with that input is put to the gate under the held
|
|
55
|
+
* call's id. Read from the transcript, so a release survives a restart between its answer and the model's search.
|
|
56
|
+
*/
|
|
57
|
+
export function releasedSearches(lines) {
|
|
58
|
+
const inputs = new Map();
|
|
59
|
+
const pending = [];
|
|
60
|
+
for (const line of lines) {
|
|
61
|
+
if (line.isSidechain === true)
|
|
62
|
+
continue;
|
|
63
|
+
for (const block of toolUses(line)) {
|
|
64
|
+
if (block.name !== WEB_SEARCH)
|
|
65
|
+
continue;
|
|
66
|
+
const key = searchKey(block.input);
|
|
67
|
+
inputs.set(block.id, key);
|
|
68
|
+
const taken = pending.findIndex((one) => one.key === key);
|
|
69
|
+
if (taken >= 0)
|
|
70
|
+
pending.splice(taken, 1);
|
|
71
|
+
}
|
|
72
|
+
for (const id of toolResultIds(line))
|
|
73
|
+
if (inputs.has(id) && resultText(line, id) === SEARCH_RELEASED)
|
|
74
|
+
pending.push({ callId: id, key: inputs.get(id) });
|
|
75
|
+
}
|
|
76
|
+
return pending;
|
|
77
|
+
}
|
|
78
|
+
/** The text of the result `line` gives the call `id`. */
|
|
79
|
+
function resultText(line, id) {
|
|
80
|
+
const content = line.message?.content;
|
|
81
|
+
const result = Array.isArray(content) ? content.find((c) => c?.type === 'tool_result' && c.tool_use_id === id) : undefined;
|
|
82
|
+
const body = result?.content;
|
|
83
|
+
return typeof body === 'string' ? body : Array.isArray(body) ? body.map((c) => (typeof c?.text === 'string' ? c.text : '')).join('') : undefined;
|
|
84
|
+
}
|
|
85
|
+
/** The tool uses after the last prompt that no result answers, each named by `named` (undefined: not one of these). */
|
|
86
|
+
function danglingOf(lines, named) {
|
|
28
87
|
let from = 0;
|
|
29
88
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
30
89
|
if (isPrompt(lines[i])) {
|
|
@@ -34,10 +93,10 @@ export function danglingCalls(lines) {
|
|
|
34
93
|
}
|
|
35
94
|
const tail = lines.slice(from).filter((line) => line.isSidechain !== true);
|
|
36
95
|
const answered = new Set(tail.flatMap((line) => toolResultIds(line)));
|
|
37
|
-
return tail
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
96
|
+
return tail.flatMap(toolUses).flatMap((block) => {
|
|
97
|
+
const tool = answered.has(block.id) ? undefined : named(block.name);
|
|
98
|
+
return tool === undefined ? [] : [{ callId: block.id, tool, args: block.input ?? {} }];
|
|
99
|
+
});
|
|
41
100
|
}
|
|
42
101
|
/**
|
|
43
102
|
* The user line that answers `call` with its outcome, as Claude Code writes an MCP tool's result: after the
|
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.37",
|
|
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.
|
|
51
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.37"
|
|
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.
|
|
80
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.37"
|
|
81
81
|
}
|
|
82
82
|
}
|