@parcha/agentrun-harness-acp 0.1.0-beta.61 → 0.1.0-beta.62
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 +6 -0
- package/dist/calls.d.ts +30 -9
- package/dist/calls.js +128 -61
- package/dist/harness.js +12 -8
- package/package.json +2 -2
- package/testing/fake-acp-agent.mjs +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.62 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
- 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 -->
|
|
8
|
+
- 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 -->
|
|
9
|
+
- 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 -->
|
|
10
|
+
|
|
5
11
|
## 0.1.0-beta.61 (2026-11-26)
|
|
6
12
|
|
|
7
13
|
- 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/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.js
CHANGED
|
@@ -19,7 +19,7 @@ import { dirname, isAbsolute, join, normalize } from "node:path";
|
|
|
19
19
|
import { fileURLToPath } from "node:url";
|
|
20
20
|
import { PROTOCOL_VERSION } from "@agentclientprotocol/sdk";
|
|
21
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,
|
|
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";
|
|
@@ -165,7 +165,11 @@ export function acpHarness(options, control) {
|
|
|
165
165
|
const log = options.log ?? (() => { });
|
|
166
166
|
const recipe = options.recipe;
|
|
167
167
|
const plan = recipe.billing.kind === "plan" ? recipe.billing : undefined;
|
|
168
|
-
const
|
|
168
|
+
const offered = options.tools.filter((tool) => !tool.deferred);
|
|
169
|
+
/** Those the agent names past its cap under our server's name (namesTooLong), which it could never call: never listed,
|
|
170
|
+
* and each start says so (toolsLeftOut). The name's length is the same at every start (mcpServerName). */
|
|
171
|
+
const capped = joinsByOne(recipe.announces) ? namesTooLong(announcesAt(recipe.announces, mcpServerName(recipe.announces)), offered.map((tool) => tool.name)) : [];
|
|
172
|
+
const listed = offered.filter((tool) => !capped.includes(tool.name));
|
|
169
173
|
const names = new Set(listed.map((tool) => tool.name));
|
|
170
174
|
/** For each tool, the recipe's announces.extras its own input schema declares: kept in its arguments (announceCall). */
|
|
171
175
|
const declared = new Map(listed.map((tool) => [tool.name, new Set((recipe.announces?.extras ?? []).filter((name) => declaresProperty(tool.inputSchema, name)))]));
|
|
@@ -508,13 +512,13 @@ export function acpHarness(options, control) {
|
|
|
508
512
|
}
|
|
509
513
|
if (absent.length)
|
|
510
514
|
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.
|
|
515
|
+
// A tool of ours the agent would name past its cap is not listed (capped); the run is told which, and goes on.
|
|
513
516
|
const serverName = mcpServerName(recipe.announces);
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
517
|
+
if (capped.length) {
|
|
518
|
+
const words = toolsLeftOut(recipe.label ?? recipe.id, announcesAt(recipe.announces, serverName)?.prefix ?? "", capped);
|
|
519
|
+
log("acp: tools left out of the agent's listing, named past its cap", { tools: capped });
|
|
520
|
+
ctx.live({ type: "notice", text: words });
|
|
521
|
+
}
|
|
518
522
|
mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
519
523
|
// Everything the agent kept goes: what it starts with is the session's records, never an earlier process's files.
|
|
520
524
|
for (const dir of [home, tmp]) {
|
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.62",
|
|
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.62",
|
|
53
53
|
"zod": "4.6.6"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
@@ -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 });
|