@parcha/agentrun-harness-acp 0.1.0-beta.61 → 0.1.0-beta.63
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 +17 -0
- package/dist/adapter.d.ts +7 -0
- package/dist/adapter.js +7 -2
- package/dist/calls.d.ts +30 -9
- package/dist/calls.js +128 -61
- package/dist/harness.d.ts +11 -0
- package/dist/harness.js +57 -16
- package/dist/host/goose-proxy.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/recipe.d.ts +4 -0
- package/dist/recipe.js +3 -0
- package/package.json +2 -2
- package/recipes/cursor.json +1 -0
- package/testing/fake-acp-agent.mjs +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.63 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
- Cursor is now told at each session's start that its own Write tool is refused, so it writes a file with a shell command (which asks the person first) and never stops at that refusal without an answer; a shell command the person denies is their answer, not asked again. An ACP recipe can carry `instructions`, given to the agent after the session's own, by the same route. A conversation begun before its recipe had them (or changed them) gets them once, ahead of its next prompt, when an agent with no system prompt loads it. They count as given only once a copy of the agent's history taken after it answered the prompt that carried them is kept, so a runner that stops before that gives them again on the next load; this covers a session's own instructions in its first prompt too. <!-- changes/cursor-write-through-shell.md -->
|
|
8
|
+
- A tool result is held to the model's context window, not only to the fixed 120,000-character bound: a model with a small window (an Ollama model at 65,536 tokens, a 16k one) is never handed a result that fills its context. <!-- changes/tool-result-window-bound.md -->
|
|
9
|
+
- `boundResult(text, budget?)` takes the model's window (`{ contextWindow, baseInputTokens? }`): a result may take at most a quarter of what the window leaves (`RESULT_WINDOW_SHARE`), at three characters a token (`RESULT_CHARS_PER_TOKEN`), and never more than `HOST_RESULT_MAX_CHARS`. Past that it is cut with a note saying it was cut to fit the window and how to read on; a window too small for any cut refuses the result in words, and a result of at most 400 characters (`RESULT_ALWAYS_WHOLE_CHARS`) always stands whole, so bounding a bound changes nothing. With no window the bound is exactly as before. `resultMaxChars(budget)` gives the bound, and `boundTo(text, max)` cuts to a given bound, saying how (`ResultBound`: the characters kept, the whole length, the bound).
|
|
10
|
+
- `SessionSpec.contextWindow` carries the session model's window, and each harness adapter (Claude, Codex, ACP, OpenCode) takes a `contextWindow` option for when the host passes none; Codex and OpenCode are told that window in place of their 272,000 guess. A Codex script cut off by a crash is answered within the same bound (`recoveryMaxChars`), not `EXEC_RECOVERY_MAX_CHARS`.
|
|
11
|
+
- agentrun-serve puts the run's model window from its catalog on every session, and pi now holds every tool result to it too: a host tool's and a pi-native one's (web_fetch, web_search, the browser's), which before reached the model up to pi's own output limits. What a host tool streams while it runs is held to the bound too (`boundedProgress`), since pi writes a call cut off past its restart limit from that text, without its hooks.
|
|
12
|
+
- A turn's results together fit what the window has left (`TurnBudget`, `ResultBudget.turn`): from what the context already holds (the last request's input tokens and its answer's output, else the session's system prompt and tool schemas counted with o200k), less the room kept for the model's answer (`answerReserve`: a quarter of the window, at most `ANSWER_RESERVE_MAX_TOKENS`, 16,384 tokens), each call the model made takes the smaller of its own bound and what is left over the calls still unanswered, so parallel calls split it, and below the least a cut keeps a result is refused in words. The kernel owns the rule; the session's model proxy reports each answer's facts (`ModelProxyOptions.turn`, its calls counted from the stream by `toolCallsIn`) for Claude, Codex, OpenCode and Goose, and pi and Claude Code on a person's login report them from their own hooks (pi's afterResponse, the login's stream booking). `windowBudget(window, system?)` builds the budget with its turn. A call whose result goes to the harness's own tool rather than the model (`ToolBridgeOptions.outsideTurn`: Codex's code-mode script calls) takes the per-result bound alone, outside the turn's split.
|
|
13
|
+
- The bridge records each cut it hands a harness (`bound:<callId>`, `boundKey`), and a replay of the call is cut by that record. Codex compares a nested call's two records on those lengths, never on the note's words; `boundOf` is gone. A session written before the record still agrees where Codex got the host's bound's cut, as before.
|
|
14
|
+
- On Claude, Codex, ACP and OpenCode, a turn's budget outlasts a process that stops in the turn (a park, a crash): each answer's facts and each result's length as it was handed go to the session's journal as they happen (`journalTurn`, `TURN_STREAM`), and a budget that has read no answer yet takes them back before any call claims (`TurnBudget.restore`). The calls a resume answers split what their answer left, and a result handed before the stop keeps its part. Codex's recovered script outputs claim their room in the turn too and are held to that claim (`ResultBudget.maxChars`). pi's turn budget is not journaled yet: a pi session opened again starts a fresh one, and each result there keeps its per-result bound.
|
|
15
|
+
|
|
16
|
+
## 0.1.0-beta.62 (2026-11-26)
|
|
17
|
+
|
|
18
|
+
- A late MCP call of a call that ended first (a cancel can report a call failed while its MCP call is on its way) takes its own announcement again before a live one that names no tool or reports no input, such as the agent's own think, whether that one was announced before the MCP call or while it held. Before, it could take that one's id: on a recipe with no announces field the think's, and on any recipe one announced during the hold. <!-- changes/acp-ended-own-first.md -->
|
|
19
|
+
- Under Antigravity, an MCP call that reaches AgentRun up to half a second before agy's announcement of it no longer takes another call's id. This happens when the call's arguments match another call's except for the `toolSummary` that the other call sent. Such a call now holds for half a second (`ANNOUNCE_GRACE_MS`) before it takes an announcement it matches only without `toolSummary`. So a call of a tool that declares `toolSummary`, where the model left it out and agy added its own, now starts at least half a second after it reaches AgentRun. An announcement that arrives while a call waits is handed to that call only when its arguments match exactly. An announcement whose call ended before its MCP call came is passed over for any live one, so a retry with the same arguments takes its own id, under Antigravity or any other ACP agent. A late MCP call of its own still takes it after half a second, when no other call's announcement matches it. <!-- changes/agy-call-id-early.md -->
|
|
20
|
+
- Under Antigravity, a tool of AgentRun's named 44 to 51 characters no longer refuses the start. The start's own name for AgentRun's MCP server is now `ar` and 6 random hex digits, as long as `agentrun`, so a tool's own name may again be up to 51 characters under agy's 64-character cap. A longer tool is left out of the tools agy is given at that start. The run gets a notice naming it and goes on with the rest. The fake ACP agent (`./testing`) gains a `{ sayTools }` step that answers with the names its MCP server lists. <!-- changes/agy-long-tool-names.md -->
|
|
21
|
+
|
|
5
22
|
## 0.1.0-beta.61 (2026-11-26)
|
|
6
23
|
|
|
7
24
|
- Google Antigravity's recipe ships with the ACP adapter, and every command takes its name where it takes a recipe file: `agentrun harness install antigravity`, `agentrun harness-check --recipe antigravity`, `agentrun harness sign-in --recipe antigravity` and `agentrun-serve --harness-recipe antigravity` (or `AGENTRUN_SERVE_HARNESS_RECIPES=antigravity`). It is still a recipe, with the same pins, check, keys page and sign-in. Each command says which recipe it resolved. A file of that name in the directory is never passed over: the command is refused, saying both, and `./antigravity` names the file. The hints a recipe prints (install, check, sign-in) name a shipped recipe by its name, not by where the package is installed. The recipe file moved from `examples/harness-recipe/antigravity.json` to the package's `recipes/bundled/antigravity.json`. An AgentRun release that changes it asks for a new check and the keys to be saved again, as an edit of your own recipe file would. <!-- changes/antigravity-bundled.md -->
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentAdapter, ModelPort } from "@parcha/agentrun-kernel";
|
|
2
|
+
import { type TurnBudget } from "@parcha/agentrun-kernel/process";
|
|
2
3
|
import { type ParentWatch } from "@parcha/agentrun-kernel/host";
|
|
3
4
|
import { type AcpRecipe } from "./recipe.js";
|
|
4
5
|
import type { ConfineChild } from "./host/child.js";
|
|
@@ -22,6 +23,10 @@ export interface AcpAdapterOptions {
|
|
|
22
23
|
callIdWaitMs?: number;
|
|
23
24
|
/** How long the agent may take to start and open its session. Default 60 s. */
|
|
24
25
|
startMs?: number;
|
|
26
|
+
/** The model's context window, in tokens: the host's bound on one tool result is its share of it (the kernel's
|
|
27
|
+
* resultMaxChars), under HOST_RESULT_MAX_CHARS. A session's own (SessionSpec.contextWindow) wins. Absent, and none on
|
|
28
|
+
* the session: the host's bound alone. */
|
|
29
|
+
contextWindow?: number;
|
|
25
30
|
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
26
31
|
/** Log each call the agent announces, ids and names only (AcpHarnessOptions.debug). */
|
|
27
32
|
debug?: boolean;
|
|
@@ -35,6 +40,8 @@ export interface AcpProxySession {
|
|
|
35
40
|
readonly tools: readonly string[];
|
|
36
41
|
/** Ends the agent's drive: its turn ends failed in `reason`'s words. */
|
|
37
42
|
halt(reason: unknown): void;
|
|
43
|
+
/** The session's turn budget (ResultBudget.turn): a proxy opens it with each answer's facts (ModelProxyOptions.turn). */
|
|
44
|
+
readonly turn?: TurnBudget;
|
|
38
45
|
}
|
|
39
46
|
/** A proxy for one agent process: the variables that point it at the proxy, and the proxy's close. */
|
|
40
47
|
export type AcpProxy = (session: AcpProxySession) => Promise<{
|
package/dist/adapter.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { toolSchemaProblems } from "@parcha/agentrun-kernel";
|
|
12
12
|
import { abortedOutcome, openDrive, pendingSubmissions, SessionHalt } from "@parcha/agentrun-kernel/kernel";
|
|
13
|
-
import { bridgeTool, recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
13
|
+
import { bridgeTool, recoveryNote, settleTurn, transcriptOf, windowBudget } from "@parcha/agentrun-kernel/process";
|
|
14
14
|
import { serialWriter } from "@parcha/agentrun-kernel/host";
|
|
15
15
|
import { acpHarness, sentSubmissions } from "./harness.js";
|
|
16
16
|
import { recipeProblems } from "./recipe.js";
|
|
@@ -74,16 +74,21 @@ export function acpAdapter(options) {
|
|
|
74
74
|
throw new Error("acp: a session needs a private directory: the host lends one (io.dir), or pass sessionsDir");
|
|
75
75
|
const instructions = spec.system.join("\n\n");
|
|
76
76
|
let control;
|
|
77
|
+
// Each tool result held to the model's share of its window (the session's, else this adapter's; none: the host's
|
|
78
|
+
// bound), and a turn's results to what it has left, which a proxy reads from each answer.
|
|
79
|
+
const budget = windowBudget(spec.contextWindow ?? options.contextWindow, spec.system);
|
|
80
|
+
const turn = budget.resultBudget?.turn;
|
|
77
81
|
const harness = acpHarness({
|
|
78
82
|
recipe,
|
|
79
83
|
tools: spec.tools.map((tool) => bridgeTool(tool)),
|
|
84
|
+
...budget,
|
|
80
85
|
...(instructions ? { instructions } : {}),
|
|
81
86
|
dir,
|
|
82
87
|
...(io.cwd ? { cwd: io.cwd } : {}),
|
|
83
88
|
...(options.confine ? { confine: options.confine } : {}),
|
|
84
89
|
...(options.parentWatch ? { parentWatch: options.parentWatch } : {}),
|
|
85
90
|
...(options.env ? { env: options.env } : {}),
|
|
86
|
-
...(options.proxy ? { proxy: (drive) => options.proxy({ models: io.models, tools: spec.tools.map((tool) => tool.name), halt: drive.halt }) } : {}),
|
|
91
|
+
...(options.proxy ? { proxy: (drive) => options.proxy({ models: io.models, tools: spec.tools.map((tool) => tool.name), halt: drive.halt, ...(turn ? { turn } : {}) }) } : {}),
|
|
87
92
|
...(options.beforeStart ? { beforeStart: options.beforeStart } : {}),
|
|
88
93
|
...(options.callIdWaitMs !== undefined ? { callIdWaitMs: options.callIdWaitMs } : {}),
|
|
89
94
|
...(options.startMs !== undefined ? { startMs: options.startMs } : {}),
|
package/dist/calls.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ export declare function ourTool(update: {
|
|
|
23
23
|
* server from a field of its own (Cursor's). */
|
|
24
24
|
export declare function joinsByOne(announces: AcpAnnounces | undefined): boolean;
|
|
25
25
|
/** The name our MCP server is given to the agent under at one start: under a recipe whose prefix joins by one character
|
|
26
|
-
* (joinsByOne), `
|
|
27
|
-
*
|
|
26
|
+
* (joinsByOne), `ar` and 6 random hex digits, no `_` or `-`, which no server set up before the start can spell; under
|
|
27
|
+
* any other, `agentrun`. As long as `agentrun`, no longer: each of our tools is named with it, under the agent's cap
|
|
28
|
+
* (TOOL_NAME_CAP), so a tool fits as it would under `agentrun`. */
|
|
28
29
|
export declare function mcpServerName(announces: AcpAnnounces | undefined): string;
|
|
29
30
|
/** The most characters a tool's name may hold where the agent names it (agy's, as the model APIs' tool names: 64). */
|
|
30
31
|
export declare const TOOL_NAME_CAP = 64;
|
|
@@ -32,6 +33,9 @@ export declare const TOOL_NAME_CAP = 64;
|
|
|
32
33
|
* and the tool's name) is longer than TOOL_NAME_CAP. Only a prefix is counted; a recipe that reads the tool's name
|
|
33
34
|
* from a field of its own with the server beside it (Cursor's) names none. */
|
|
34
35
|
export declare function namesTooLong(announces: AcpAnnounces | undefined, tools: Iterable<string>): string[];
|
|
36
|
+
/** The run's notice for the tools `label` (an agent naming ours `<prefix><tool>`) is not given at a start: those
|
|
37
|
+
* namesTooLong names, which it could never call. */
|
|
38
|
+
export declare function toolsLeftOut(label: string, prefix: string, tools: readonly string[]): string;
|
|
35
39
|
/** The recipe's `announces` as one start reads them, our MCP server given to the agent as `server` (mcpServerName): its
|
|
36
40
|
* prefix names that server (`mcp_agentrun_` reads `mcp_<server>_`). ANNOUNCES_PREFIX ends a prefix at our server's
|
|
37
41
|
* name, so the last `agentrun` in it is that name. */
|
|
@@ -99,8 +103,13 @@ export declare function announceCall(calls: CallIds, update: AcpCallUpdate, anno
|
|
|
99
103
|
* update echoes the model's arguments stays the agent's own. The tool_call's kind was checked before it was held;
|
|
100
104
|
* the update's is checked here: a shell renamed by a later update is never ours. */
|
|
101
105
|
export declare function nameCall(calls: CallIds, update: AcpCallUpdate, announces: AcpAnnounces | undefined, tools: ReadonlySet<string>, declared?: ReadonlyMap<string, ReadonlySet<string>>): void;
|
|
106
|
+
/** How long an MCP call that matches an announcement only without an extra (addAnnounced) holds for its own (take): an
|
|
107
|
+
* MCP call can reach MCP a little before the agent's announcement of it, and in that while the other's may be the only
|
|
108
|
+
* one there. */
|
|
109
|
+
export declare const ANNOUNCE_GRACE_MS = 500;
|
|
102
110
|
/** The agent's announced calls, matched to the MCP calls of our tools that reach the server. */
|
|
103
111
|
export declare class CallIds {
|
|
112
|
+
private readonly grace;
|
|
104
113
|
private readonly seen;
|
|
105
114
|
private readonly waiting;
|
|
106
115
|
private readonly used;
|
|
@@ -124,13 +133,21 @@ export declare class CallIds {
|
|
|
124
133
|
* against a plan's limit and memoized under a key a resume never asks again. Until its call ends (settle). A tool
|
|
125
134
|
* named for an id already announced without one (a call the agent named in a later update) keys it again. `also`:
|
|
126
135
|
* the same call's arguments read another way (addAnnounced: without an extra its tool's schema declares), under
|
|
127
|
-
* which it is kept too; the first MCP call either matches takes it, and it is gone from both.
|
|
136
|
+
* which it is kept too; the first MCP call either matches takes it, and it is gone from both. A call already waiting
|
|
137
|
+
* is handed it only where it is the call's own first key, its tool and its whole arguments. One that matches it only
|
|
138
|
+
* without the extra may be another call's, whose own announcement is on its way, and one naming no tool or reporting
|
|
139
|
+
* no input may come second to the call's own ended one, so for those the call tries again as take says (wake). */
|
|
128
140
|
add(id: string, tool: string | undefined, input: unknown, also?: unknown): void;
|
|
129
141
|
/** `id` out of every list it is kept in (keyOf), waiting for its MCP call no more. */
|
|
130
142
|
private unlist;
|
|
131
143
|
/** The agent's call `id` ended (completed or failed) with no MCP call having taken it: an announcement that names
|
|
132
|
-
* nothing and reports nothing is dropped, so a call of the agent's own never takes a later MCP call's id.
|
|
144
|
+
* nothing and reports nothing is dropped, so a call of the agent's own never takes a later MCP call's id. Any other
|
|
145
|
+
* is `ended`: a live announcement comes before it in every match (take), so a retry with the same arguments takes its
|
|
146
|
+
* own id, and it holds no later MCP call; but it stays for a late MCP call of its own (a cancel can report a call
|
|
147
|
+
* failed while its MCP call is on its way), which takes it after the hold when no live one matches. */
|
|
133
148
|
settle(id: string): void;
|
|
149
|
+
/** The announcements whose call ended with no MCP call (settle), still listed. */
|
|
150
|
+
private readonly ended;
|
|
134
151
|
/** Whether the agent announced `id` (matched or not). */
|
|
135
152
|
has(id: string): boolean;
|
|
136
153
|
/** The tool of ours the agent's tool_call `id` was announced as, or undefined when no tool_call named one. */
|
|
@@ -139,14 +156,18 @@ export declare class CallIds {
|
|
|
139
156
|
* came by then. Of the announcements with the same arguments, the oldest named `tool` first, then the oldest named
|
|
140
157
|
* none; then the oldest of `tool` that reported no input. Then, already there or once the wait is over, never woken
|
|
141
158
|
* by one coming in during it (which may be the agent's own while this call's own announcement is on its way), the
|
|
142
|
-
* oldest that named nothing and reported nothing. Where the arguments match
|
|
143
|
-
*
|
|
159
|
+
* oldest that named nothing and reported nothing. Where the arguments match announcements only read without an extra
|
|
160
|
+
* (addAnnounced), the call holds for `grace` first, and then while one of them may yet be another call's whole
|
|
161
|
+
* arguments. */
|
|
144
162
|
take(tool: string, args: Record<string, unknown>, signal: AbortSignal, ms: number): Promise<string | undefined>;
|
|
145
|
-
/**
|
|
146
|
-
|
|
163
|
+
/** How long an MCP call holds before it takes an announcement it matches only without an extra (take). */
|
|
164
|
+
constructor(grace?: number);
|
|
165
|
+
/** The MCP calls waiting (take): how many under each key, and each one's retry. */
|
|
166
|
+
private readonly pending;
|
|
147
167
|
private readonly retries;
|
|
148
168
|
private waking;
|
|
149
|
-
/** Each
|
|
169
|
+
/** Each waiting call tries again, once the current one is through: an announcement was taken, listed or dropped, or
|
|
170
|
+
* another call waits. */
|
|
150
171
|
private wake;
|
|
151
172
|
}
|
|
152
173
|
/** The gate's id for a permission request of the agent's own tool: the same for the same request after a resume. */
|
package/dist/calls.js
CHANGED
|
@@ -62,10 +62,11 @@ export function joinsByOne(announces) {
|
|
|
62
62
|
return announces !== undefined && announces.server === undefined && announces.prefix !== undefined && new RegExp(`${MCP_SERVER}[_-]$`).test(announces.prefix);
|
|
63
63
|
}
|
|
64
64
|
/** The name our MCP server is given to the agent under at one start: under a recipe whose prefix joins by one character
|
|
65
|
-
* (joinsByOne), `
|
|
66
|
-
*
|
|
65
|
+
* (joinsByOne), `ar` and 6 random hex digits, no `_` or `-`, which no server set up before the start can spell; under
|
|
66
|
+
* any other, `agentrun`. As long as `agentrun`, no longer: each of our tools is named with it, under the agent's cap
|
|
67
|
+
* (TOOL_NAME_CAP), so a tool fits as it would under `agentrun`. */
|
|
67
68
|
export function mcpServerName(announces) {
|
|
68
|
-
return joinsByOne(announces) ?
|
|
69
|
+
return joinsByOne(announces) ? `ar${randomBytes(3).toString("hex")}` : MCP_SERVER;
|
|
69
70
|
}
|
|
70
71
|
/** The most characters a tool's name may hold where the agent names it (agy's, as the model APIs' tool names: 64). */
|
|
71
72
|
export const TOOL_NAME_CAP = 64;
|
|
@@ -78,6 +79,12 @@ export function namesTooLong(announces, tools) {
|
|
|
78
79
|
const prefix = announces.prefix;
|
|
79
80
|
return [...tools].filter((tool) => prefix.length + tool.length > TOOL_NAME_CAP);
|
|
80
81
|
}
|
|
82
|
+
/** The run's notice for the tools `label` (an agent naming ours `<prefix><tool>`) is not given at a start: those
|
|
83
|
+
* namesTooLong names, which it could never call. */
|
|
84
|
+
export function toolsLeftOut(label, prefix, tools) {
|
|
85
|
+
const one = tools.length === 1;
|
|
86
|
+
return `${label} names each of our tools ${prefix}<tool>, at most ${TOOL_NAME_CAP} characters in all, so a tool's own name may be at most ${TOOL_NAME_CAP - prefix.length}; ${tools.map((tool) => JSON.stringify(tool)).join(", ")} ${one ? "is" : "are"} longer, so ${one ? "it is" : "they are"} left out of the tools it is given at this start`;
|
|
87
|
+
}
|
|
81
88
|
/** The recipe's `announces` as one start reads them, our MCP server given to the agent as `server` (mcpServerName): its
|
|
82
89
|
* prefix names that server (`mcp_agentrun_` reads `mcp_<server>_`). ANNOUNCES_PREFIX ends a prefix at our server's
|
|
83
90
|
* name, so the last `agentrun` in it is that name. */
|
|
@@ -229,8 +236,13 @@ export function nameCall(calls, update, announces, tools, declared) {
|
|
|
229
236
|
const NOTHING = "\0*";
|
|
230
237
|
/** take's word for a call torn between announcements its arguments match only without an extra. */
|
|
231
238
|
const TORN = Symbol("torn");
|
|
239
|
+
/** How long an MCP call that matches an announcement only without an extra (addAnnounced) holds for its own (take): an
|
|
240
|
+
* MCP call can reach MCP a little before the agent's announcement of it, and in that while the other's may be the only
|
|
241
|
+
* one there. */
|
|
242
|
+
export const ANNOUNCE_GRACE_MS = 500;
|
|
232
243
|
/** The agent's announced calls, matched to the MCP calls of our tools that reach the server. */
|
|
233
244
|
export class CallIds {
|
|
245
|
+
grace;
|
|
234
246
|
seen = new Map();
|
|
235
247
|
waiting = new Map();
|
|
236
248
|
used = new Set();
|
|
@@ -259,7 +271,10 @@ export class CallIds {
|
|
|
259
271
|
* against a plan's limit and memoized under a key a resume never asks again. Until its call ends (settle). A tool
|
|
260
272
|
* named for an id already announced without one (a call the agent named in a later update) keys it again. `also`:
|
|
261
273
|
* the same call's arguments read another way (addAnnounced: without an extra its tool's schema declares), under
|
|
262
|
-
* which it is kept too; the first MCP call either matches takes it, and it is gone from both.
|
|
274
|
+
* which it is kept too; the first MCP call either matches takes it, and it is gone from both. A call already waiting
|
|
275
|
+
* is handed it only where it is the call's own first key, its tool and its whole arguments. One that matches it only
|
|
276
|
+
* without the extra may be another call's, whose own announcement is on its way, and one naming no tool or reporting
|
|
277
|
+
* no input may come second to the call's own ended one, so for those the call tries again as take says (wake). */
|
|
263
278
|
add(id, tool, input, also) {
|
|
264
279
|
if (this.used.has(id))
|
|
265
280
|
return;
|
|
@@ -274,14 +289,15 @@ export class CallIds {
|
|
|
274
289
|
const before = this.keyOf.get(id);
|
|
275
290
|
if (before && before.length === keys.length && before.every((key, i) => key === keys[i]))
|
|
276
291
|
return;
|
|
292
|
+
// An ended one (settle) keyed again stays ended, and is never handed to a waiting call at once.
|
|
293
|
+
const ended = this.ended.has(id);
|
|
277
294
|
this.unlist(id);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
295
|
+
const waiter = ended ? undefined : this.waiting.get(keys[0])?.shift();
|
|
296
|
+
if (waiter) {
|
|
297
|
+
this.used.add(id);
|
|
298
|
+
waiter(id);
|
|
299
|
+
this.wake();
|
|
300
|
+
return;
|
|
285
301
|
}
|
|
286
302
|
for (const key of keys) {
|
|
287
303
|
const list = this.seen.get(key) ?? [];
|
|
@@ -289,6 +305,9 @@ export class CallIds {
|
|
|
289
305
|
this.seen.set(key, list);
|
|
290
306
|
}
|
|
291
307
|
this.keyOf.set(id, keys);
|
|
308
|
+
if (ended)
|
|
309
|
+
this.ended.add(id);
|
|
310
|
+
this.wake();
|
|
292
311
|
}
|
|
293
312
|
/** `id` out of every list it is kept in (keyOf), waiting for its MCP call no more. */
|
|
294
313
|
unlist(id) {
|
|
@@ -299,14 +318,25 @@ export class CallIds {
|
|
|
299
318
|
list.splice(at, 1);
|
|
300
319
|
}
|
|
301
320
|
this.keyOf.delete(id);
|
|
321
|
+
this.ended.delete(id);
|
|
302
322
|
}
|
|
303
323
|
/** The agent's call `id` ended (completed or failed) with no MCP call having taken it: an announcement that names
|
|
304
|
-
* nothing and reports nothing is dropped, so a call of the agent's own never takes a later MCP call's id.
|
|
324
|
+
* nothing and reports nothing is dropped, so a call of the agent's own never takes a later MCP call's id. Any other
|
|
325
|
+
* is `ended`: a live announcement comes before it in every match (take), so a retry with the same arguments takes its
|
|
326
|
+
* own id, and it holds no later MCP call; but it stays for a late MCP call of its own (a cancel can report a call
|
|
327
|
+
* failed while its MCP call is on its way), which takes it after the hold when no live one matches. */
|
|
305
328
|
settle(id) {
|
|
306
|
-
|
|
329
|
+
const keys = this.keyOf.get(id);
|
|
330
|
+
if (!keys)
|
|
307
331
|
return;
|
|
308
|
-
|
|
332
|
+
if (keys[0] === NOTHING)
|
|
333
|
+
this.unlist(id);
|
|
334
|
+
else
|
|
335
|
+
this.ended.add(id);
|
|
336
|
+
this.wake();
|
|
309
337
|
}
|
|
338
|
+
/** The announcements whose call ended with no MCP call (settle), still listed. */
|
|
339
|
+
ended = new Set();
|
|
310
340
|
/** Whether the agent announced `id` (matched or not). */
|
|
311
341
|
has(id) {
|
|
312
342
|
return this.used.has(id) || this.keyOf.has(id);
|
|
@@ -319,97 +349,134 @@ export class CallIds {
|
|
|
319
349
|
* came by then. Of the announcements with the same arguments, the oldest named `tool` first, then the oldest named
|
|
320
350
|
* none; then the oldest of `tool` that reported no input. Then, already there or once the wait is over, never woken
|
|
321
351
|
* by one coming in during it (which may be the agent's own while this call's own announcement is on its way), the
|
|
322
|
-
* oldest that named nothing and reported nothing. Where the arguments match
|
|
323
|
-
*
|
|
352
|
+
* oldest that named nothing and reported nothing. Where the arguments match announcements only read without an extra
|
|
353
|
+
* (addAnnounced), the call holds for `grace` first, and then while one of them may yet be another call's whole
|
|
354
|
+
* arguments. */
|
|
324
355
|
async take(tool, args, signal, ms) {
|
|
325
356
|
const keys = [`${tool}\0${canonical(args)}`, `\0${canonical(args)}`, `${tool}\0*`];
|
|
326
357
|
const key = keys[0];
|
|
327
358
|
// Under the first of `from` that keeps one: an announcement whose own arguments are these (its first key, the form
|
|
328
|
-
// with the extra)
|
|
329
|
-
//
|
|
330
|
-
//
|
|
331
|
-
//
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
359
|
+
// with the extra) at once. One kept under this call's own key only read without an extra (addAnnounced) is a guess:
|
|
360
|
+
// its call may have sent the extra, its own MCP call on its way with it, and this call's own announcement still on
|
|
361
|
+
// its way (an MCP call can reach MCP before it). So the call takes one only once it is `aged`, past the grace, and
|
|
362
|
+
// while there are no more of them than calls waiting on them (`waiting`, this one among them); then the oldest. When
|
|
363
|
+
// every call left the extra out, which of them takes which, by when its MCP call came, may not be the order they
|
|
364
|
+
// were announced in: their inputs are the same, so it changes nothing a call is given. Every rule here reads the
|
|
365
|
+
// live announcements alone; one whose call ended (settle) is taken only once the call is `aged` and no live one
|
|
366
|
+
// under any of `from` is left: then the oldest whose own arguments are these, else the oldest. One whose own
|
|
367
|
+
// arguments are these (a late MCP call of a call a cancel reported failed) also comes before a live one that matches
|
|
368
|
+
// them less closely, under a later key: one naming no tool, or reporting no input, or neither, whether it was
|
|
369
|
+
// announced before the MCP call or during its hold (add hands a waiting call only its own first key). Only an
|
|
370
|
+
// announcement whose own first key is this one counts as its own: one kept here only read without an extra
|
|
371
|
+
// (addAnnounced) is a guess, and a live one under a later key comes first, as before. So a retry announced with
|
|
372
|
+
// less than its call's whole arguments (no tool, or no input), after a call with these arguments ended, takes the
|
|
373
|
+
// ended one's id after the hold: the same tool with the same arguments, the order the two came in lost. Beyond this: an
|
|
374
|
+
// announcement that comes more than the grace after its own MCP call (that call takes the other's), and a call torn
|
|
375
|
+
// until the wait is over, more than ms behind the other's MCP call (it takes the oldest, which may be the other's);
|
|
376
|
+
// in both the other's MCP call falls back once its wait is over. Two calls with the same arguments, one ended, can
|
|
377
|
+
// swap ids when the ended one's MCP call comes after the other's announcement: their arguments cannot tell them
|
|
378
|
+
// apart. Once the wait is over, loose may take an ended announcement of the tool with other arguments, as it does a
|
|
379
|
+
// live one.
|
|
380
|
+
const pick = (from, waiting, aged) => {
|
|
381
|
+
const take = (id) => {
|
|
340
382
|
this.unlist(id);
|
|
341
383
|
this.used.add(id);
|
|
342
384
|
this.wake();
|
|
343
385
|
return id;
|
|
386
|
+
};
|
|
387
|
+
let gone;
|
|
388
|
+
let own = false;
|
|
389
|
+
for (const at of from) {
|
|
390
|
+
const list = this.seen.get(at);
|
|
391
|
+
if (!list?.length)
|
|
392
|
+
continue;
|
|
393
|
+
const live = list.filter((each) => !this.ended.has(each));
|
|
394
|
+
if (!live.length) {
|
|
395
|
+
if (gone === undefined) {
|
|
396
|
+
const exact = list.find((each) => this.keyOf.get(each)?.[0] === at);
|
|
397
|
+
gone = exact ?? list[0];
|
|
398
|
+
own = exact !== undefined && (at === keys[0] || at === keys[1]);
|
|
399
|
+
}
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (own)
|
|
403
|
+
break;
|
|
404
|
+
const id = live.find((each) => this.keyOf.get(each)?.[0] === at) ?? (at === key && (!aged || live.length > waiting) ? TORN : live[0]);
|
|
405
|
+
return id === TORN ? TORN : take(id);
|
|
344
406
|
}
|
|
345
|
-
|
|
407
|
+
if (gone === undefined)
|
|
408
|
+
return undefined;
|
|
409
|
+
return aged ? take(gone) : TORN;
|
|
346
410
|
};
|
|
347
411
|
// Once the wait is over, the oldest announced call named `tool` whose reported input differs from what reached MCP.
|
|
348
412
|
// Never one named no tool with other arguments: its arguments are all that ties it, and they differ. Then the oldest
|
|
349
413
|
// that named nothing and reported nothing.
|
|
350
|
-
const loose = () => pick([...[...this.seen.keys()].filter((at) => at.startsWith(`${tool}\0`)), NOTHING], Infinity);
|
|
351
|
-
|
|
352
|
-
const queued = this.torn.get(key) ?? 0;
|
|
353
|
-
const now = queued && !this.seen.get(key)?.some((id) => this.keyOf.get(id)?.[0] === key) ? TORN : pick([...keys, NOTHING], 1);
|
|
414
|
+
const loose = () => pick([...[...this.seen.keys()].filter((at) => at.startsWith(`${tool}\0`)), NOTHING], Infinity, true);
|
|
415
|
+
const now = pick([...keys, NOTHING], (this.pending.get(key) ?? 0) + 1, this.grace <= 0);
|
|
354
416
|
if (typeof now === "string")
|
|
355
417
|
return now;
|
|
356
|
-
const torn = now === TORN;
|
|
357
418
|
return new Promise((resolve, reject) => {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
419
|
+
let aged = this.grace <= 0;
|
|
420
|
+
// A call is handed an announcement at once (add) only under its own first key: its own arguments with its tool. One
|
|
421
|
+
// that names no tool or reports no input is listed, and wakes the call, whose retry takes it by pick's rules (its
|
|
422
|
+
// own ended announcement comes first). Never on one that named nothing: those are only kept on a recipe without
|
|
423
|
+
// announces, and an extra (the one cause to wait) needs announces.
|
|
424
|
+
const handed = this.waiting.get(key) ?? [];
|
|
425
|
+
this.waiting.set(key, handed);
|
|
363
426
|
const retry = () => {
|
|
364
|
-
const id = pick(keys, this.
|
|
427
|
+
const id = pick(keys, this.pending.get(key) ?? 0, aged);
|
|
365
428
|
if (typeof id === "string")
|
|
366
429
|
done(id);
|
|
367
430
|
};
|
|
368
431
|
const leave = () => {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
432
|
+
clearTimeout(timer);
|
|
433
|
+
clearTimeout(held);
|
|
434
|
+
const at = handed.indexOf(done);
|
|
435
|
+
if (at >= 0)
|
|
436
|
+
handed.splice(at, 1);
|
|
374
437
|
if (!this.retries.delete(retry))
|
|
375
438
|
return;
|
|
376
|
-
const left = (this.
|
|
439
|
+
const left = (this.pending.get(key) ?? 1) - 1;
|
|
377
440
|
if (left > 0)
|
|
378
|
-
this.
|
|
441
|
+
this.pending.set(key, left);
|
|
379
442
|
else
|
|
380
|
-
this.
|
|
443
|
+
this.pending.delete(key);
|
|
381
444
|
};
|
|
382
445
|
const done = (id) => {
|
|
383
|
-
clearTimeout(timer);
|
|
384
446
|
signal.removeEventListener("abort", stop);
|
|
385
447
|
leave();
|
|
386
448
|
resolve(id);
|
|
387
449
|
};
|
|
388
450
|
const stop = () => {
|
|
389
|
-
clearTimeout(timer);
|
|
390
451
|
leave();
|
|
391
452
|
reject(signal.reason instanceof Error ? signal.reason : new Error("the call was stopped"));
|
|
392
453
|
};
|
|
393
454
|
const timer = setTimeout(() => {
|
|
394
455
|
signal.removeEventListener("abort", stop);
|
|
395
456
|
leave();
|
|
396
|
-
resolve(
|
|
457
|
+
resolve(pick(keys, Infinity, true) ?? loose());
|
|
397
458
|
}, ms);
|
|
459
|
+
const held = setTimeout(() => {
|
|
460
|
+
aged = true;
|
|
461
|
+
retry();
|
|
462
|
+
}, Math.max(this.grace, 0));
|
|
398
463
|
signal.addEventListener("abort", stop, { once: true });
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.retries.add(retry);
|
|
404
|
-
this.wake();
|
|
405
|
-
}
|
|
464
|
+
handed.push(done);
|
|
465
|
+
this.pending.set(key, (this.pending.get(key) ?? 0) + 1);
|
|
466
|
+
this.retries.add(retry);
|
|
467
|
+
this.wake();
|
|
406
468
|
});
|
|
407
469
|
}
|
|
408
|
-
/**
|
|
409
|
-
|
|
470
|
+
/** How long an MCP call holds before it takes an announcement it matches only without an extra (take). */
|
|
471
|
+
constructor(grace = ANNOUNCE_GRACE_MS) {
|
|
472
|
+
this.grace = grace;
|
|
473
|
+
}
|
|
474
|
+
/** The MCP calls waiting (take): how many under each key, and each one's retry. */
|
|
475
|
+
pending = new Map();
|
|
410
476
|
retries = new Set();
|
|
411
477
|
waking = false;
|
|
412
|
-
/** Each
|
|
478
|
+
/** Each waiting call tries again, once the current one is through: an announcement was taken, listed or dropped, or
|
|
479
|
+
* another call waits. */
|
|
413
480
|
wake() {
|
|
414
481
|
if (this.waking || this.retries.size === 0)
|
|
415
482
|
return;
|
package/dist/harness.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GateAnswer, GateCall } from "@parcha/agentrun-kernel";
|
|
2
2
|
import type { DriveContext, HostTool, SessionState } from "@parcha/agentrun-kernel/kernel";
|
|
3
|
+
import { type ResultBudget } from "@parcha/agentrun-kernel/process";
|
|
3
4
|
import type { ParentWatch } from "@parcha/agentrun-kernel/host";
|
|
4
5
|
import { type AcpRecipe } from "./recipe.js";
|
|
5
6
|
import type { ConfineChild } from "./host/child.js";
|
|
@@ -21,6 +22,13 @@ export declare const REASK_LIMIT = 3;
|
|
|
21
22
|
export declare const TOOLS_STREAM = "acp.tools";
|
|
22
23
|
/** The model chosen for the agent's session (recipe.model, as the agent lists it), one record each time one is chosen. */
|
|
23
24
|
export declare const MODEL_STREAM = "acp.model";
|
|
25
|
+
/** Instructions a prompt carried ahead of its words (an agent with no system prompt), one record each time, written only
|
|
26
|
+
* with a copy of the agent's history taken after it answered that prompt: `sessionId` the session, `text` the recipe's
|
|
27
|
+
* part, `whole` when the session's own came too (its first prompt). A loaded session is given the recipe's again when
|
|
28
|
+
* they differ from the last of its records (a recipe that gained or changed them since), and all of them when it was
|
|
29
|
+
* opened to get them in a prompt (SESSION_STREAM `prompted`) and has no `whole` record: a crash before the copy
|
|
30
|
+
* leaves a history without them. */
|
|
31
|
+
export declare const INSTRUCTIONS_STREAM = "acp.instructions";
|
|
24
32
|
/** How long a session waits for the agent to start and answer initialize, or open its session. */
|
|
25
33
|
export declare const START_MS = 60000;
|
|
26
34
|
/** How long an MCP call waits for the agent's tool_call that announces it. */
|
|
@@ -49,6 +57,9 @@ export interface AcpHarnessOptions {
|
|
|
49
57
|
env?: Readonly<Record<string, string | undefined>>;
|
|
50
58
|
/** The host's gate (SessionIO.gate). Absent: every call runs. */
|
|
51
59
|
gate?: (call: GateCall) => Promise<GateAnswer>;
|
|
60
|
+
/** What the session's model can take of one tool result (its context window): the tool bridge holds every result to
|
|
61
|
+
* it (boundResult's budget). Absent: the host's bound alone (HOST_RESULT_MAX_CHARS). */
|
|
62
|
+
resultBudget?: ResultBudget;
|
|
52
63
|
/** Proxy billing: what each agent process gets to reach the host's model proxy (its variables), closed with it.
|
|
53
64
|
* `halt` ends the drive the process serves. */
|
|
54
65
|
proxy?: (drive: {
|
package/dist/harness.js
CHANGED
|
@@ -18,8 +18,8 @@ import { chmodSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
|
18
18
|
import { dirname, isAbsolute, join, normalize } from "node:path";
|
|
19
19
|
import { fileURLToPath } from "node:url";
|
|
20
20
|
import { PROTOCOL_VERSION } from "@agentclientprotocol/sdk";
|
|
21
|
-
import { askGate, journalRecords, NativeJournal, openTurn, placeSubmissions, recoveryNote, resumeUnstartedCalls, toolBridge, toolKey, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
22
|
-
import { announceCall, announcedField, announcesAt, CallIds, declaresProperty, joinsByOne, mcpServerName, nameCall, namesTooLong, ourTool, permissionCallId,
|
|
21
|
+
import { askGate, journalRecords, journalTurn, NativeJournal, openTurn, placeSubmissions, recoveryNote, resumeUnstartedCalls, toolBridge, toolKey, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
22
|
+
import { announceCall, announcedField, announcesAt, CallIds, declaresProperty, joinsByOne, mcpServerName, nameCall, namesTooLong, ourTool, permissionCallId, toolsLeftOut } from "./calls.js";
|
|
23
23
|
import { ACP_CODES } from "./facts.js";
|
|
24
24
|
import { allowFileText, homePath } from "./recipe.js";
|
|
25
25
|
import { restoreState, STATE_STREAM, StateMirror } from "./state.js";
|
|
@@ -44,6 +44,13 @@ export const REASK_LIMIT = 3;
|
|
|
44
44
|
export const TOOLS_STREAM = "acp.tools";
|
|
45
45
|
/** The model chosen for the agent's session (recipe.model, as the agent lists it), one record each time one is chosen. */
|
|
46
46
|
export const MODEL_STREAM = "acp.model";
|
|
47
|
+
/** Instructions a prompt carried ahead of its words (an agent with no system prompt), one record each time, written only
|
|
48
|
+
* with a copy of the agent's history taken after it answered that prompt: `sessionId` the session, `text` the recipe's
|
|
49
|
+
* part, `whole` when the session's own came too (its first prompt). A loaded session is given the recipe's again when
|
|
50
|
+
* they differ from the last of its records (a recipe that gained or changed them since), and all of them when it was
|
|
51
|
+
* opened to get them in a prompt (SESSION_STREAM `prompted`) and has no `whole` record: a crash before the copy
|
|
52
|
+
* leaves a history without them. */
|
|
53
|
+
export const INSTRUCTIONS_STREAM = "acp.instructions";
|
|
47
54
|
/** How long a session waits for the agent to start and answer initialize, or open its session. */
|
|
48
55
|
export const START_MS = 60_000;
|
|
49
56
|
/** How long an MCP call waits for the agent's tool_call that announces it. */
|
|
@@ -165,7 +172,11 @@ export function acpHarness(options, control) {
|
|
|
165
172
|
const log = options.log ?? (() => { });
|
|
166
173
|
const recipe = options.recipe;
|
|
167
174
|
const plan = recipe.billing.kind === "plan" ? recipe.billing : undefined;
|
|
168
|
-
const
|
|
175
|
+
const offered = options.tools.filter((tool) => !tool.deferred);
|
|
176
|
+
/** Those the agent names past its cap under our server's name (namesTooLong), which it could never call: never listed,
|
|
177
|
+
* and each start says so (toolsLeftOut). The name's length is the same at every start (mcpServerName). */
|
|
178
|
+
const capped = joinsByOne(recipe.announces) ? namesTooLong(announcesAt(recipe.announces, mcpServerName(recipe.announces)), offered.map((tool) => tool.name)) : [];
|
|
179
|
+
const listed = offered.filter((tool) => !capped.includes(tool.name));
|
|
169
180
|
const names = new Set(listed.map((tool) => tool.name));
|
|
170
181
|
/** For each tool, the recipe's announces.extras its own input schema declares: kept in its arguments (announceCall). */
|
|
171
182
|
const declared = new Map(listed.map((tool) => [tool.name, new Set((recipe.announces?.extras ?? []).filter((name) => declaresProperty(tool.inputSchema, name)))]));
|
|
@@ -206,17 +217,19 @@ export function acpHarness(options, control) {
|
|
|
206
217
|
/** Why an agent that ended did: its last words on stderr, else the error's, else that it said nothing. On a hushed run,
|
|
207
218
|
* its exit status alone. */
|
|
208
219
|
const whyEnded = (agent, error) => hushed ? `${agent.ended() ?? "its end is not known yet"}; what it printed is kept nowhere on this run` : lastWords(agent.stderrTail()) || lastWords(message(error)) || "it said nothing";
|
|
209
|
-
/** Mirror the agent's session store into `journal` (the caller flushes). A failure is said and never
|
|
210
|
-
* point takes the mirror again, and a turn's outcome is never lost to it. */
|
|
220
|
+
/** Mirror the agent's session store into `journal` (the caller flushes); true once taken. A failure is said and never
|
|
221
|
+
* thrown: the next point takes the mirror again, and a turn's outcome is never lost to it. */
|
|
211
222
|
const mirrorInto = (rt, journal) => {
|
|
212
223
|
// A HOME removed with its process holds nothing to take: read now, it would say the agent deleted its whole store.
|
|
213
224
|
if (rt.wiped)
|
|
214
|
-
return;
|
|
225
|
+
return false;
|
|
215
226
|
try {
|
|
216
227
|
rt.mirror.take(journal);
|
|
228
|
+
return true;
|
|
217
229
|
}
|
|
218
230
|
catch (error) {
|
|
219
231
|
log("acp: the mirror of the agent's session store failed; the next point takes it again", { error: said(error) });
|
|
232
|
+
return false;
|
|
220
233
|
}
|
|
221
234
|
};
|
|
222
235
|
/** The open turn's limit of tool calls, counted from the records: past it, the turn is cancelled with a named reason. */
|
|
@@ -508,13 +521,13 @@ export function acpHarness(options, control) {
|
|
|
508
521
|
}
|
|
509
522
|
if (absent.length)
|
|
510
523
|
throw new Error(`${ACP_CODES.keyMissing}: ${recipe.label ?? recipe.id} runs on ${absent.join(" and ")}, which this host does not hold; the agent was not started`);
|
|
511
|
-
//
|
|
512
|
-
// so the start is refused before anything is made.
|
|
524
|
+
// A tool of ours the agent would name past its cap is not listed (capped); the run is told which, and goes on.
|
|
513
525
|
const serverName = mcpServerName(recipe.announces);
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
526
|
+
if (capped.length) {
|
|
527
|
+
const words = toolsLeftOut(recipe.label ?? recipe.id, announcesAt(recipe.announces, serverName)?.prefix ?? "", capped);
|
|
528
|
+
log("acp: tools left out of the agent's listing, named past its cap", { tools: capped });
|
|
529
|
+
ctx.live({ type: "notice", text: words });
|
|
530
|
+
}
|
|
518
531
|
mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
519
532
|
// Everything the agent kept goes: what it starts with is the session's records, never an earlier process's files.
|
|
520
533
|
for (const dir of [home, tmp]) {
|
|
@@ -665,7 +678,8 @@ export function acpHarness(options, control) {
|
|
|
665
678
|
const server = recipe.declares.mcp === "http"
|
|
666
679
|
? { type: "http", name: rt.server, url: mcp.url, headers: [{ name: "Authorization", value: `Bearer ${key}` }] }
|
|
667
680
|
: { name: rt.server, command: process.execPath, args: [STDIO_BRIDGE], env: [{ name: "AGENTRUN_MCP_URL", value: mcp.url }, { name: "AGENTRUN_MCP_KEY", value: key }] };
|
|
668
|
-
|
|
681
|
+
// The session's own, then the recipe's (how it runs the agent, which the agent cannot see).
|
|
682
|
+
const instructions = [options.instructions, recipe.instructions].filter((each) => !!each?.trim()).join("\n\n") || undefined;
|
|
669
683
|
const systemPrompt = instructions && caps.sessionCapabilities?.systemPrompt ? { mode: "append", content: [{ type: "text", text: instructions }] } : undefined;
|
|
670
684
|
const last = journalRecords(ctx.state(), SESSION_STREAM).map((r) => r.data?.sessionId).filter((id) => typeof id === "string").at(-1);
|
|
671
685
|
/** What session/load or session/new answered: the models it lists, for one. */
|
|
@@ -687,14 +701,33 @@ export function acpHarness(options, control) {
|
|
|
687
701
|
rt.loading = false;
|
|
688
702
|
}
|
|
689
703
|
}
|
|
704
|
+
// session/load carries no instructions for an agent with no system prompt: they are in its history once a copy of
|
|
705
|
+
// it taken after the prompt that carried them says so (INSTRUCTIONS_STREAM). The session's own come again when
|
|
706
|
+
// that prompt was cut (a crash before the copy); the recipe's too, or when they came or changed since (an upgrade).
|
|
707
|
+
const recipeTold = recipe.instructions?.trim() ? recipe.instructions : undefined;
|
|
708
|
+
if (!rt.fresh && instructions && !systemPrompt) {
|
|
709
|
+
const prompted = journalRecords(ctx.state(), SESSION_STREAM).some((r) => r.data?.sessionId === last && r.data?.prompted === true);
|
|
710
|
+
const given = journalRecords(ctx.state(), INSTRUCTIONS_STREAM).map((r) => r.data).filter((d) => d?.sessionId === last);
|
|
711
|
+
if (prompted && !given.some((d) => d?.whole === true)) {
|
|
712
|
+
rt.firstBlocks.push(`Instructions for this session, from the host that runs you:\n\n${instructions}`);
|
|
713
|
+
rt.told = { text: recipeTold, whole: true };
|
|
714
|
+
}
|
|
715
|
+
else if (recipeTold && given.map((d) => d?.text).at(-1) !== recipeTold) {
|
|
716
|
+
rt.firstBlocks.push(`Instructions for this session, from the host that runs you:\n\n${recipeTold}`);
|
|
717
|
+
rt.told = { text: recipeTold };
|
|
718
|
+
}
|
|
719
|
+
}
|
|
690
720
|
if (rt.fresh) {
|
|
691
721
|
const opened = await ask("session/new", () => live.connection.agent.request("session/new", { cwd: root, mcpServers: [server], ...(systemPrompt ? { systemPrompt } : {}) }));
|
|
692
722
|
rt.sessionId = opened.sessionId;
|
|
693
|
-
|
|
723
|
+
// `prompted`: its instructions go in its first prompt, so a load checks they reached its history.
|
|
724
|
+
journal.append(SESSION_STREAM, { sessionId: opened.sessionId, ...(instructions && !systemPrompt ? { prompted: true } : {}) });
|
|
694
725
|
mirrorInto(rt, journal);
|
|
695
726
|
await journal.flush();
|
|
696
|
-
if (instructions && !systemPrompt)
|
|
727
|
+
if (instructions && !systemPrompt) {
|
|
697
728
|
rt.firstBlocks.push(`Instructions for this session, from the host that runs you:\n\n${instructions}`);
|
|
729
|
+
rt.told = { text: recipeTold, whole: true };
|
|
730
|
+
}
|
|
698
731
|
const context = contextNote(ctx.state());
|
|
699
732
|
if (context)
|
|
700
733
|
rt.firstBlocks.push(context);
|
|
@@ -737,11 +770,14 @@ export function acpHarness(options, control) {
|
|
|
737
770
|
};
|
|
738
771
|
async function driveOnce(ctx) {
|
|
739
772
|
const journal = new NativeJournal(ctx);
|
|
773
|
+
// The turn's budget kept on this drive's journal: a resume answers the calls it left on its answer's facts.
|
|
774
|
+
journalTurn(options.resultBudget?.turn, journal);
|
|
740
775
|
const gate = options.gate;
|
|
741
776
|
// The gate is asked once the call's `seen` record is in the log: a call the gate parks is found again on a resume.
|
|
742
777
|
const bridge = toolBridge(ctx, options.tools, {
|
|
743
778
|
...(gate ? { gate: async (call) => (await journal.flush(), gate(call)) } : {}),
|
|
744
779
|
beforeNever: () => journal.flush(),
|
|
780
|
+
...(options.resultBudget ? { budget: options.resultBudget } : {}),
|
|
745
781
|
});
|
|
746
782
|
const cur = { ctx, journal, bridge, signal: ctx.signal, inflight: new Set() };
|
|
747
783
|
// A resumed session: each call of ours the agent made and the records never answered goes through the bridge before
|
|
@@ -814,6 +850,10 @@ export function acpHarness(options, control) {
|
|
|
814
850
|
}
|
|
815
851
|
// The send's mark, in the log first: a crash between the two reads "marked, maybe sent", never sent twice.
|
|
816
852
|
journal.append(PROMPT_STREAM, { submission, ...(covers.length ? { covers: [...covers] } : {}) });
|
|
853
|
+
// The instructions this prompt carries are recorded given only with a copy of the agent's history taken after it
|
|
854
|
+
// answered (below): a crash before that leaves a copy without them, and the next load gives them again.
|
|
855
|
+
const telling = agent.told;
|
|
856
|
+
agent.told = undefined;
|
|
817
857
|
await journal.flush();
|
|
818
858
|
const prompt = [...agent.firstBlocks.splice(0), ...body].map((text) => ({ type: "text", text }));
|
|
819
859
|
let ended;
|
|
@@ -855,7 +895,8 @@ export function acpHarness(options, control) {
|
|
|
855
895
|
}
|
|
856
896
|
if (ctx.signal.aborted)
|
|
857
897
|
throw ctx.signal.reason;
|
|
858
|
-
mirrorInto(agent, journal)
|
|
898
|
+
if (mirrorInto(agent, journal) && telling && answer !== undefined)
|
|
899
|
+
journal.append(INSTRUCTIONS_STREAM, { sessionId: agent.sessionId, ...telling });
|
|
859
900
|
// Cancelled by the session's interrupt: no end is written, the turn stays open (its host settles it).
|
|
860
901
|
if (interrupting) {
|
|
861
902
|
await journal.flush();
|
package/dist/host/goose-proxy.js
CHANGED
|
@@ -318,6 +318,7 @@ export function gooseProxy(options) {
|
|
|
318
318
|
const proxy = await startModelProxy({
|
|
319
319
|
policy: goosePolicy({ model: options.model, tools: session.tools, ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(options.provider.auth ? { auth: options.provider.auth } : {}) }),
|
|
320
320
|
hooks: session.models,
|
|
321
|
+
...(session.turn ? { turn: session.turn } : {}),
|
|
321
322
|
model: options.model,
|
|
322
323
|
origin: options.provider.origin,
|
|
323
324
|
credential: async () => (await options.provider.credential()) ?? "",
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { acpAdapter, type AcpAdapterOptions, type AcpProxy, type AcpProxySession
|
|
|
2
2
|
export { ACP_CODES, acpFacts, type AcpFacts } from "./facts.js";
|
|
3
3
|
export { ALLOW_FILE_FORMS, allowFileText, announcesProblems, AUTH_METHOD, homePath, MODEL_ID, recipeProblems, RESERVED_ENV, type AcpAllowFile, type AcpAllowForm, type AcpBilling, type AcpRecipe, type AcpRefusal } from "./recipe.js";
|
|
4
4
|
export { ANNOUNCES_PATH, type AcpAnnounces } from "./calls.js";
|
|
5
|
-
export { CALL_STREAM, contextNote, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
5
|
+
export { CALL_STREAM, contextNote, INSTRUCTIONS_STREAM, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
6
6
|
export { STATE_BUDGET, STATE_STREAM, stateBudgetPassed, stateFiles, type StateRecord } from "./state.js";
|
|
7
7
|
export type { ConfineChild } from "./host/child.js";
|
|
8
8
|
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { acpAdapter } from "./adapter.js";
|
|
|
3
3
|
export { ACP_CODES, acpFacts } from "./facts.js";
|
|
4
4
|
export { ALLOW_FILE_FORMS, allowFileText, announcesProblems, AUTH_METHOD, homePath, MODEL_ID, recipeProblems, RESERVED_ENV } from "./recipe.js";
|
|
5
5
|
export { ANNOUNCES_PATH } from "./calls.js";
|
|
6
|
-
export { CALL_STREAM, contextNote, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
6
|
+
export { CALL_STREAM, contextNote, INSTRUCTIONS_STREAM, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
7
7
|
export { STATE_BUDGET, STATE_STREAM, stateBudgetPassed, stateFiles } from "./state.js";
|
|
8
8
|
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
|
9
9
|
export { gooseAdapter, gooseRecipe, recipeFile } from "./goose.js";
|
package/dist/recipe.d.ts
CHANGED
|
@@ -85,6 +85,10 @@ export interface AcpRecipe {
|
|
|
85
85
|
* (`gpt-5.4-nano`): chosen with session/set_model among those session/new lists, before the first prompt. One it
|
|
86
86
|
* does not list is refused with ACP_CODES.modelUnlisted. Absent: the agent's own default. */
|
|
87
87
|
readonly model?: string;
|
|
88
|
+
/** What the agent is told at each session's start about how the recipe runs it, which it cannot see for itself
|
|
89
|
+
* (Cursor: its own Write tool is refused, so a file is written with a shell command): after the session's own
|
|
90
|
+
* instructions, by the same route (the system prompt the agent advertises, else ahead of the first prompt). */
|
|
91
|
+
readonly instructions?: string;
|
|
88
92
|
/** Files written into its private HOME before it starts, by their path in HOME (`.config/goose/config.yaml`). */
|
|
89
93
|
readonly files?: Readonly<Record<string, string>>;
|
|
90
94
|
/** A file in HOME, written at each start from the tools that start's MCP server lists, that tells the agent to run
|
package/dist/recipe.js
CHANGED
|
@@ -63,6 +63,9 @@ export function recipeProblems(recipe) {
|
|
|
63
63
|
problems.push("the command must be an absolute path");
|
|
64
64
|
if (!recipe.declares || typeof recipe.declares.load !== "boolean" || (recipe.declares.mcp !== "http" && recipe.declares.mcp !== "stdio"))
|
|
65
65
|
problems.push('declares needs load (true or false) and mcp ("http" or "stdio")');
|
|
66
|
+
const told = recipe.instructions;
|
|
67
|
+
if (told !== undefined && (typeof told !== "string" || !told.trim()))
|
|
68
|
+
problems.push("the instructions must be words, when there are any");
|
|
66
69
|
const billing = recipe.billing;
|
|
67
70
|
if (billing?.kind === "plan") {
|
|
68
71
|
if (!Number.isInteger(billing.maxTurns) || billing.maxTurns < 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-harness-acp",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.63",
|
|
4
4
|
"description": "Any Agent Client Protocol agent as an AgentRun harness: the agent over stdio in a private HOME, the host's tools as one loopback MCP server, its permission asks through the host's gate, durable in AgentRun's own store.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@agentclientprotocol/sdk": "2.7.0",
|
|
52
|
-
"@parcha/agentrun-kernel": "0.1.0-beta.
|
|
52
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.63",
|
|
53
53
|
"zod": "4.6.6"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
package/recipes/cursor.json
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"files": {
|
|
7
7
|
".config/cursor/cli-config.json":"{\"version\":1,\"permissions\":{\"allow\":[],\"deny\":[\"Write(**)\"]},\"approvalMode\":\"allowlist\"}\n"
|
|
8
8
|
},
|
|
9
|
+
"instructions": "Your own file-writing tool (Write) is turned off here: every write with it is refused, and asking does not turn it on. To create or change a file, run a shell command that writes it (a heredoc such as cat > name <<'EOF' ... EOF, or a short script); a shell command asks the person first. When Write refuses a write, write the file with a shell command instead: never stop at that refusal or answer without the file. When the person denies a shell command, that is their answer: do not ask again for the same write; stop and say what you could not do.",
|
|
9
10
|
"state": [".config/cursor/acp-sessions"],
|
|
10
11
|
"credentials": [".config/cursor/auth.json"],
|
|
11
12
|
"refusals": [
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// A stand-in ACP agent for the adapter's tests and the conformance suite: a stdio agent on the official SDK whose "model"
|
|
3
3
|
// is a script. No binary, no model, no network beyond loopback. Its one argument is a JSON config file:
|
|
4
4
|
// script: the model's steps, the conformance suite's ScriptStep ({call, args} | {say, cut} | {sayLastSteer} |
|
|
5
|
-
// {sayLastResult}) plus {native: kind, title, input}, a tool of the agent's own (a shell, an edit)
|
|
5
|
+
// {sayLastResult}) plus {native: kind, title, input}, a tool of the agent's own (a shell, an edit), and
|
|
6
|
+
// {sayTools}, the names its MCP server lists (tools/list), joined by commas;
|
|
6
7
|
// load: advertise session/load and keep sessions in $HOME/.fake-acp/sessions (default true);
|
|
7
8
|
// advertiseLoad / advertiseHttp: what initialize says, when it should differ from what the agent does;
|
|
8
9
|
// http: advertise MCP over HTTP (default true); the client then picks the transport;
|
|
@@ -388,6 +389,7 @@ async function takeTurn(client, session, prompt, signal) {
|
|
|
388
389
|
let words;
|
|
389
390
|
if ("say" in s) words = s.say;
|
|
390
391
|
else if ("sayLastResult" in s) words = lastResult ?? "";
|
|
392
|
+
else if ("sayTools" in s) words = ((await session.mcp?.request("tools/list", {}))?.tools ?? []).map((tool) => tool.name).join(",");
|
|
391
393
|
else if ("sayLastSteer" in s) words = (notes.includes("[Recovery]") ? lastQuote(blocks.find((b) => b.includes("[Recovery]"))) : undefined) ?? said_;
|
|
392
394
|
else words = "";
|
|
393
395
|
session.history.push({ kind: "say", text: words });
|