@parcha/agentrun-harness-acp 0.1.0-beta.57 → 0.1.0-beta.59
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 +31 -0
- package/README.md +8 -2
- package/dist/adapter.d.ts +2 -0
- package/dist/adapter.js +1 -0
- package/dist/calls.d.ts +90 -11
- package/dist/calls.js +190 -32
- package/dist/goose-facts.js +2 -0
- package/dist/goose.js +6 -2
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +66 -40
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/recipe.d.ts +41 -0
- package/dist/recipe.js +48 -0
- package/dist/testing.d.ts +7 -3
- package/dist/testing.js +10 -1
- package/package.json +2 -2
- package/recipes/cursor.json +3 -1
- package/recipes/goose.json +2 -0
- package/testing/fake-acp-agent.mjs +52 -13
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.59 (2026-11-25)
|
|
6
|
+
|
|
7
|
+
**Breaking:**
|
|
8
|
+
|
|
9
|
+
- Ollama models run only on a harness that forwards the route, an output schema beside tools on Ollama is refused, and an ACP agent's permission requests for AgentRun's tools are no longer answered from their titles. What to change on upgrade: <!-- changes/b51-breaking.md -->
|
|
10
|
+
- A harness module on Messages or Responses that should keep running Ollama models must forward its model requests with the `fetch` its launch hands it (`ModuleLaunch.fetch`, given to `startModelProxy`'s `fetch`) and set `forwardsRoute: true` in its facts. Without the fact it is offered no Ollama model, and a run of it that names one is refused before it starts, in words that name these two steps.
|
|
11
|
+
- A claude-agent node with an output schema on an Ollama model now stops with a 400 `invalid_request_error`, since the claude-agent harness sends its tools on every turn and Ollama can't hold an answer to a format and also call tools. Drop the schema, or run the node on a model with a key.
|
|
12
|
+
- A recipe for an agent that asks permission before every tool call needs an `allowFile` in a form its agent reads, or the title tie (`quirks.permissionTie: "title"`). Without either, every request for an AgentRun tool goes to the host's gate as the agent's own call, and its runs stop there.
|
|
13
|
+
- An agent's `tool_call` title no longer names the AgentRun tool it calls. A recipe without `announces` (the new field where its agent's `tool_call` names the tool) has every call matched to its MCP call by its arguments alone, a call with no arguments included. A call announced with no input at all is matched to an MCP call that nothing else matches, the oldest first, until the agent reports it ended, so two such calls in flight can trade ids. Declare `announces` to tie each call to its own.
|
|
14
|
+
- Goose's offer promises `tool_gate: "config"` (was `"permission"`): its calls of AgentRun's tools are held by its permission file and the host's gate at the MCP call.
|
|
15
|
+
- `agentrun harness-check` fails `mcp_tool` for an agent that asks permission for `check_echo` on a recipe with neither field. A recipe whose check passed before can fail its next one.
|
|
16
|
+
- `examples/harness-recipe/antigravity.json` declares `announces` and the title tie (`quirks.permissionTie: "title"`), since agy asks permission for every MCP call: its requests for the AgentRun calls it announced are answered allow once, and the host's gate decides at the MCP call. A copy of the recipe made before this release has neither and needs both, or its runs stop at the gate.
|
|
17
|
+
- The exported test helper `fakeAgentRecipe` (`@parcha/agentrun-harness-acp/testing`) now gives its recipe an `allowFile` (style "goose", the default) or the title tie (style "cursor"), and each style's `announces`, as each shipped recipe does. The fake's style "cursor" now announces its MCP calls late, as Cursor 2026.11.13 does (`announce: "early"` for the old shape). A suite that relied on the fake asking for AgentRun's tools and being answered from the title gets neither by default.
|
|
18
|
+
|
|
19
|
+
**Changes:**
|
|
20
|
+
|
|
21
|
+
- Goose 1.59.2 no longer asks permission for a call of one of AgentRun's tools, and the ACP adapter no longer reads Goose's titles. Before, it tied `agentrun: <tool>` (with or without Goose's summary, `agentrun: write · proof.txt`) to our tool and answered `allow_once`, and a title in a form it did not read reached the tool gate as Goose's own call and stopped the run at input_required. <!-- changes/acp-announces.md -->
|
|
22
|
+
- A recipe's new `allowFile` (`{ path, form }`) is written into the private HOME at each start from the tools that start lists. Goose's recipe declares its permission file, `.config/goose/permission.yaml` in the form `goose-permission`, every tool allowed as `agentrun__<tool>` and nothing else, so the gate asks once, at the MCP call.
|
|
23
|
+
- The adapter answers a permission request `allow_once` without the gate only where the recipe declares `quirks.permissionTie: "title"`: Cursor's recipe, since its allowlist asks for every MCP call, and the Antigravity example's, since agy asks for every one too. Every other request goes to the host's gate, journaled, whatever its title says.
|
|
24
|
+
- A recipe's new `announces` field says where the agent's `tool_call` names the tool it calls: Goose 1.59.2's `_meta.goose.toolCall.toolName` (`agentrun__<tool>`), Cursor's late update's `rawInput` (`providerIdentifier`, `toolName`, `args`), agy's `name` (`mcp_agentrun_<tool>`, its `prefix`). Its `extras` names fields an agent writes beside the arguments that the MCP call never carries (agy's `toolSummary`), left out before the two are matched. A path that starts at the `tool_call`'s `title`, `toolCallId`, `kind`, `status`, `rawOutput`, `content`, `locations` or `sessionUpdate` is refused (the agent's text or a tool's output), and a recipe with the title tie and no `announces` is refused. A call is matched to its MCP call by that tool and its arguments, never by a title. A call it names as another tool (Goose's own `load_skill` with the same arguments) never takes our call's id, so the resume memo keys our call under its own id.
|
|
25
|
+
- A title naming our tool on a call of the agent's own (a read titled `agentrun__write`) no longer marks it ours, so Cursor's tie never answers its request; the host's gate does.
|
|
26
|
+
- The host gate's question about an agent's permission request carries the request's `toolCallId` in its `args`. `agentrun harness-check` matches a permission request to `check_echo` by that `toolCallId` or by the check's nonce as its input's `text`, never by its title. Its `mcp_tool` row counts every request (`permissionAsks`) and those for `check_echo` (`ourAsks`); a request for the agent's own call fails no stage. A recipe file passes `allowFile`, `announces` and `quirks` through.
|
|
27
|
+
- `AGENTRUN_LOG=debug` makes serve write into a run's log one line per call an ACP agent announces, on a recipe that declares `announces`: `acp: the agent announced a call`, with the call's `toolCallId`, its `kind`, the tool name the recipe's field holds when it names an AgentRun tool (at most 200 characters; `native` for any other call, since a recipe's field may sit inside the call's input) and the AgentRun tool it named, never the call's input. A call announced with no name (Cursor's) gets the line again when a later update names it. Unset or `quiet`, no such line is written.
|
|
28
|
+
- The Antigravity example recipe names agy's calls of AgentRun's tools by the field agy writes them in, `name` (`mcp_agentrun_<tool>`): `announces` with `prefix: "mcp_agentrun_"`, and `extras: ["toolSummary"]`, so the summary agy adds to the arguments it reports is left out when the call is matched to its MCP call. agy asks permission for every MCP call, so the recipe declares the title tie: a request titled `Run mcp_agentrun_<tool>`, the whole text, for a call `announces` named as that same tool, is answered allow once, with the host's gate asked at the MCP call itself, as for Cursor. The Antigravity example recipe now passes `harness-check` (agy 1.5.14): it declares MCP over stdio, since agy advertises no MCP over HTTP, and names `.gemini/antigravity-cli/conversations` as its state, so a resume after a kill and another runner both load the conversation. <!-- changes/antigravity-recipe-check.md -->
|
|
29
|
+
- A model the runner's route translates onto a harness's wire (this machine's Ollama models on Anthropic's Messages and OpenAI's Responses) is offered only to a harness whose proxy forwards with the route's `fetch`, and the Messages translation no longer drops what it can't run. Before, any harness on the wire was offered those models, including a module that sends its requests to the network, where nothing answers. <!-- changes/b51-route-hints.md -->
|
|
30
|
+
- `AdapterFacts` gains `forwardsRoute`. claude-agent, Goose, codex and opencode set it, and so does every recipe that builds on Goose's facts. A harness without it is offered none of the route's models, takes none as its default, and its words say to add a key ("No model yet for <harness>: add an OpenRouter or Anthropic key"). A run that names one is refused before it starts.
|
|
31
|
+
- An output schema (`output_config.format` of type `json_schema`) on a Messages request with no tools now reaches Ollama as its `format`. Before, it was dropped and the answer came back unconstrained. Beside tools it is refused with a 400 `invalid_request_error` that says to drop the output schema or use a model route that takes tools with a format, because Ollama holds the whole answer to the format and leaves the model no way to call a tool.
|
|
32
|
+
- The Messages translation answers `POST /v1/messages` and `POST /v1/messages/count_tokens` alone. Any other method or path is a 404 `not_found_error` in Anthropic's error shape, and nothing reaches Ollama.
|
|
33
|
+
- `agentrun harness-check` on a model the route translates (`--model ollama/<tag>`) now reaches it. Its recorder wraps the route's own fetch, so the recipe's agent gets the same route a server's run gets and the check still sees every request. Before, every request went to the route's placeholder origin and `mcp_tool` failed.
|
|
34
|
+
- A turn whose agent dies saying a refusal the recipe names now fails as that refusal, even when the agent's stdout closed before its stderr was read. The failure waits up to five seconds for the agent's process to close before it reads the stderr tail. Before, a turn could fail as `ACP_AGENT_EXITED` with "ACP connection closed" while the refusal was still in the pipe. <!-- changes/acp-last-words.md -->
|
|
35
|
+
|
|
5
36
|
## 0.1.0-beta.57 (2026-11-24)
|
|
6
37
|
|
|
7
38
|
- A Goose 1.59.2 call of one of AgentRun's tools whose title carries Goose's summary of its arguments (`agentrun: write · proof.txt`) is now tied to that tool. Before, it reached the tool gate as Goose's own call (`acp_other`) and waited for an approval, so a write the agent was allowed to make stopped the run at input_required. The title alone still ties nothing: the call needs the tool_call Goose announced for it, and a kind with effects of its own (a shell, an edit) is never ours. <!-- changes/acp-goose-title-summary.md -->
|
package/README.md
CHANGED
|
@@ -11,8 +11,14 @@ entries.
|
|
|
11
11
|
- The host's tools are one loopback MCP server, `agentrun`, given on `session/new`: over HTTP when the recipe declares
|
|
12
12
|
it, else over stdio through a small bridge. Every call runs through the kernel's tool bridge: the host's gate, the
|
|
13
13
|
call's intent in the session's records, then the tool.
|
|
14
|
-
- `session/request_permission`
|
|
15
|
-
|
|
14
|
+
- `session/request_permission` goes through the host's gate (allow, deny, park), journaled. The adapter answers
|
|
15
|
+
`allow_once` or `reject_once`, never an `allow_always`, and never trusts the status ACP reports. The host's tools ask
|
|
16
|
+
nothing: a recipe's `allowFile` (Goose's `.config/goose/permission.yaml`) lists them for the agent at each start, and
|
|
17
|
+
the gate asks at the MCP call. A recipe that declares `quirks.permissionTie: "title"` (Cursor's, whose allowlist asks
|
|
18
|
+
for every MCP call, and Antigravity's, since agy asks for every MCP call) has its request for one of the host's announced calls answered `allow_once` without the gate.
|
|
19
|
+
- An agent's `tool_call` is matched to the MCP call it makes by the tool and the arguments. Which tool it names is read
|
|
20
|
+
from the field its recipe's `announces` declares (Goose's `_meta.goose.toolCall.toolName`, Cursor's `rawInput`, agy's `name`),
|
|
21
|
+
never from its title; a call that field names as another tool is the agent's own.
|
|
16
22
|
- `session/load` resumes a session when the recipe declares it and the agent advertises it; the history it replays stays
|
|
17
23
|
off the timeline. With no load, a crash mid-turn restarts the turn on a new agent session with the kernel's recovery
|
|
18
24
|
note, and the conversation so far as a context note.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface AcpAdapterOptions {
|
|
|
23
23
|
/** How long the agent may take to start and open its session. Default 60 s. */
|
|
24
24
|
startMs?: number;
|
|
25
25
|
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
26
|
+
/** Log each call the agent announces, ids and names only (AcpHarnessOptions.debug). */
|
|
27
|
+
debug?: boolean;
|
|
26
28
|
}
|
|
27
29
|
/** What a proxy-billed agent process's proxy is started for: its session's booking and tools, and its drive's stop. */
|
|
28
30
|
export interface AcpProxySession {
|
package/dist/adapter.js
CHANGED
|
@@ -88,6 +88,7 @@ export function acpAdapter(options) {
|
|
|
88
88
|
...(options.callIdWaitMs !== undefined ? { callIdWaitMs: options.callIdWaitMs } : {}),
|
|
89
89
|
...(options.startMs !== undefined ? { startMs: options.startMs } : {}),
|
|
90
90
|
...(options.log ? { log: options.log } : {}),
|
|
91
|
+
...(options.debug ? { debug: true } : {}),
|
|
91
92
|
// The host's gate: asked by the kernel's tool bridge for our tools, and by the harness for the agent's own.
|
|
92
93
|
...(io.gate ? { gate: (call) => io.gate(call) } : {}),
|
|
93
94
|
}, (c) => void (control = c));
|
package/dist/calls.d.ts
CHANGED
|
@@ -5,31 +5,110 @@ export declare function canonical(value: unknown): string;
|
|
|
5
5
|
/** The ACP tool kinds of a call with effects of its own (a shell, a file write, a delete, a move, a fetch): never one of
|
|
6
6
|
* our tools, whatever its title says. */
|
|
7
7
|
export declare const NATIVE_EFFECT_KINDS: ReadonlySet<string>;
|
|
8
|
-
/** The host tool
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* (CallIds.announced). */
|
|
8
|
+
/** The host tool a permission request's title or name gives, by a name for our MCP server's tools (`agentrun__<tool>`),
|
|
9
|
+
* Cursor's own title for one (`agentrun-<tool>: <tool>`), or agy's (Antigravity's) name and title for one
|
|
10
|
+
* (`mcp_agentrun_<tool>`, titled `Run mcp_agentrun_<tool>`, the whole text), when it is one of `tools` and its kind is
|
|
11
|
+
* not one with effects of its own. Read for the title tie alone (quirks.permissionTie: Cursor's and agy's), and only
|
|
12
|
+
* beside the call's announcement: the title is the agent's text, so a request is tied only when it is for a call the
|
|
13
|
+
* recipe's announces field named as the same tool (CallIds.announced). Nothing else reads a title. */
|
|
14
14
|
export declare function ourTool(update: {
|
|
15
15
|
title?: string | null;
|
|
16
16
|
name?: string | null;
|
|
17
17
|
kind?: string | null;
|
|
18
18
|
}, tools: ReadonlySet<string>): string | undefined;
|
|
19
|
-
/**
|
|
19
|
+
/** Where in an agent's tool_call (or the update that names it later) a recipe finds which tool it calls, each a dotted
|
|
20
|
+
* path of field names into the update (`_meta.goose.toolCall.toolName`, `rawInput.toolName`, `name`).
|
|
21
|
+
* - `tool`: the tool's name. With `server`, our tool's own name; without, the name as the model calls it, our server's
|
|
22
|
+
* prefix and the tool's (`prefix`, stripped).
|
|
23
|
+
* - `server`: the MCP server's name, which must be ours (`agentrun`).
|
|
24
|
+
* - `prefix`: without `server`, what comes before our tool's name in `tool` (default `agentrun__`; agy's
|
|
25
|
+
* `mcp_agentrun_`). It names our server (ANNOUNCES_PREFIX), so a name without it is never ours.
|
|
26
|
+
* - `args`: the call's arguments (default `rawInput`).
|
|
27
|
+
* - `extras`: fields the agent writes beside the call's arguments that the MCP call never carries (agy's
|
|
28
|
+
* `toolSummary`, its model's line about the call), left out before the arguments are matched when they hold text. A tool of ours with a
|
|
29
|
+
* text argument of that name loses it too: its call never matches its arguments, waits CALL_ID_WAIT_MS and takes the
|
|
30
|
+
* oldest call of its tool, so two in flight can swap ids (custody only: a call's permission never reads extras). */
|
|
31
|
+
export interface AcpAnnounces {
|
|
32
|
+
readonly tool: string;
|
|
33
|
+
readonly server?: string;
|
|
34
|
+
readonly prefix?: string;
|
|
35
|
+
readonly args?: string;
|
|
36
|
+
readonly extras?: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
/** The prefix a recipe's announces.prefix may be: our server's name, with at most one word and a `_` or `-` before it,
|
|
39
|
+
* and one or two `_` or `-` after it (`agentrun__`, `mcp_agentrun_`). */
|
|
40
|
+
export declare const ANNOUNCES_PREFIX: RegExp;
|
|
41
|
+
/** A field name announces.extras may list. */
|
|
42
|
+
export declare const ANNOUNCES_EXTRA: RegExp;
|
|
43
|
+
/** A path an AcpAnnounces field may hold: field names joined by dots, never starting at the update's title,
|
|
44
|
+
* toolCallId, kind, status, rawOutput, content, locations or sessionUpdate: a path through the title would let the
|
|
45
|
+
* agent's text name a call again, one through rawOutput or content a tool's output. */
|
|
46
|
+
export declare const ANNOUNCES_PATH: RegExp;
|
|
47
|
+
/** The most of the word at a recipe's announces.tool a debug line quotes. */
|
|
48
|
+
export declare const ANNOUNCED_FIELD_CHARS = 200;
|
|
49
|
+
/** The word at the recipe's announces.tool in `update`, clipped to ANNOUNCED_FIELD_CHARS: what the agent said it calls.
|
|
50
|
+
* It may sit inside the call's input (Cursor's rawInput.toolName): the debug line (harness.ts) quotes it only for a call
|
|
51
|
+
* of ours. Null when the recipe declares no field or it holds no string. */
|
|
52
|
+
export declare function announcedField(update: unknown, announces: AcpAnnounces | undefined): string | null;
|
|
53
|
+
/** The tool of ours an agent's update names in the field its recipe declares (`announces`): its name; null when the
|
|
54
|
+
* field names a tool that is not ours (another server's, one without our prefix, or one of our server's that `tools`
|
|
55
|
+
* does not list); undefined when the recipe declares no field or the update does not carry it. A title is never read. */
|
|
56
|
+
export declare function announcedTool(update: unknown, announces: AcpAnnounces | undefined, tools: ReadonlySet<string>): string | null | undefined;
|
|
57
|
+
/** An agent's update about one of its calls, as the adapter reads it. */
|
|
58
|
+
export interface AcpCallUpdate {
|
|
59
|
+
readonly toolCallId: string;
|
|
60
|
+
readonly kind?: string | null;
|
|
61
|
+
readonly rawInput?: unknown;
|
|
62
|
+
}
|
|
63
|
+
/** The agent's tool_call `update`, kept for the MCP call it may be: a call whose kind has effects of its own never is
|
|
64
|
+
* (a shell named as our tool never takes an MCP call's id); one the recipe's field names as another tool is the agent's
|
|
65
|
+
* own; one it names as ours is kept as that tool; one it names nothing for is matched by its arguments alone, except
|
|
66
|
+
* one with no arguments on a recipe whose field names calls, which waits for the update that names it. On a recipe
|
|
67
|
+
* without the field, one reporting no input at all is kept as a call that names nothing (CallIds.add). */
|
|
68
|
+
export declare function announceCall(calls: CallIds, update: AcpCallUpdate, announces: AcpAnnounces | undefined, tools: ReadonlySet<string>): void;
|
|
69
|
+
/** A tool_call_update naming a call its tool_call left unnamed with no input (Cursor's MCP calls: a tool_call titled
|
|
70
|
+
* "MCP: tool" with rawInput {}, then this update with rawInput {providerIdentifier, toolName, args}): kept as that
|
|
71
|
+
* tool, under the id its tool_call already counted, by the recipe's field. Only a call announceCall held for its name
|
|
72
|
+
* (CallIds.held): one whose tool_call reported input, or named a tool, is never named later, so a native read whose
|
|
73
|
+
* update echoes the model's arguments stays the agent's own. The tool_call's kind was checked before it was held;
|
|
74
|
+
* the update's is checked here: a shell renamed by a later update is never ours. */
|
|
75
|
+
export declare function nameCall(calls: CallIds, update: AcpCallUpdate, announces: AcpAnnounces | undefined, tools: ReadonlySet<string>): void;
|
|
76
|
+
/** The agent's announced calls, matched to the MCP calls of our tools that reach the server. */
|
|
20
77
|
export declare class CallIds {
|
|
21
78
|
private readonly seen;
|
|
22
79
|
private readonly waiting;
|
|
23
80
|
private readonly used;
|
|
24
81
|
private readonly tools;
|
|
25
|
-
/** The
|
|
26
|
-
|
|
82
|
+
/** The key each announcement still waiting for its MCP call is kept under. */
|
|
83
|
+
private readonly keyOf;
|
|
84
|
+
/** The calls announced naming no tool and reporting no input, held for the update that names them (hold). */
|
|
85
|
+
private readonly unnamed;
|
|
86
|
+
/** The agent announced call `id` naming no tool and reporting no input, on a recipe whose field names calls: held for
|
|
87
|
+
* the later update that names it (nameCall), and matched to nothing until then. */
|
|
88
|
+
hold(id: string): void;
|
|
89
|
+
/** Whether `id` is held for its name (hold) and no update has named it yet. */
|
|
90
|
+
held(id: string): boolean;
|
|
91
|
+
/** The agent announced call `id` with `input`, its recipe's field naming `tool` of ours, or none (undefined). Input
|
|
92
|
+
* that is not an object (none reported, or a value that is not an argument object) is no input. One with no tool is
|
|
93
|
+
* matched by its input alone, an object ({} included: announceCall holds one back where a later update will name
|
|
94
|
+
* the call); one with no input by its tool alone. One with neither (only on a recipe without announces: announceCall
|
|
95
|
+
* never keeps one elsewhere) is the last an MCP call takes, of any tool, when nothing else matches it: nothing names
|
|
96
|
+
* it and nothing ties it, and its MCP call would otherwise run under an id of the adapter's, counted a second time
|
|
97
|
+
* against a plan's limit and memoized under a key a resume never asks again. Until its call ends (settle). A tool
|
|
98
|
+
* named for an id already announced without one (a call the agent named in a later update) keys it again. */
|
|
99
|
+
add(id: string, tool: string | undefined, input: unknown): void;
|
|
100
|
+
/** The agent's call `id` ended (completed or failed) with no MCP call having taken it: an announcement that names
|
|
101
|
+
* nothing and reports nothing is dropped, so a call of the agent's own never takes a later MCP call's id. */
|
|
102
|
+
settle(id: string): void;
|
|
27
103
|
/** Whether the agent announced `id` (matched or not). */
|
|
28
104
|
has(id: string): boolean;
|
|
29
|
-
/** The tool of ours the agent's tool_call `id` was announced as, or undefined when no
|
|
105
|
+
/** The tool of ours the agent's tool_call `id` was announced as, or undefined when no tool_call named one. */
|
|
30
106
|
announced(id: string): string | undefined;
|
|
31
107
|
/** The id of an MCP call of `tool` with `args`: the agent's announced one, waited for at most `ms`; undefined when none
|
|
32
|
-
* came by then.
|
|
108
|
+
* came by then. Of the announcements with the same arguments, the oldest named `tool` first, then the oldest named
|
|
109
|
+
* none; then the oldest of `tool` that reported no input. Then, already there or once the wait is over, never woken
|
|
110
|
+
* by one coming in during it (which may be the agent's own while this call's own announcement is on its way), the
|
|
111
|
+
* oldest that named nothing and reported nothing. */
|
|
33
112
|
take(tool: string, args: Record<string, unknown>, signal: AbortSignal, ms: number): Promise<string | undefined>;
|
|
34
113
|
}
|
|
35
114
|
/** 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
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// How an ACP agent's calls get their ids. Written for AgentRun.
|
|
2
2
|
// - A call of one of our tools reaches the adapter twice: as the agent's `tool_call` update (its own id, a title, the
|
|
3
3
|
// input it reports) over ACP, and as the MCP call itself over HTTP or stdio, which names no id. The two are matched by
|
|
4
|
-
// the
|
|
5
|
-
//
|
|
4
|
+
// the arguments' canonical JSON, first in first out, as OpenCode's calls are matched to the model's: the call runs
|
|
5
|
+
// under the agent's own id, which is the memo key a resumed session asks under again. Which tool an announcement
|
|
6
|
+
// names is read from the field its recipe declares (AcpAnnounces: Goose's `_meta.goose.toolCall.toolName`, Cursor's
|
|
7
|
+
// rawInput, agy's `name` after its `mcp_agentrun_` prefix, with agy's toolSummary left out of the arguments as an
|
|
8
|
+
// extra), never from its title: a call that field names as another tool is the agent's own and never takes an id.
|
|
9
|
+
// One the field names nothing for is matched by its arguments alone.
|
|
6
10
|
// - A permission request for one of the agent's own tools (a shell, an edit) is the host gate's call. Its id is made from
|
|
7
11
|
// what a second request for the same call after a resume says the same: the open turn, the tool's title, kind and input,
|
|
8
12
|
// and how many such requests came before it in the drive. Never from the agent's tool call id, which a new agent
|
|
@@ -22,81 +26,235 @@ export function canonical(value) {
|
|
|
22
26
|
/** The ACP tool kinds of a call with effects of its own (a shell, a file write, a delete, a move, a fetch): never one of
|
|
23
27
|
* our tools, whatever its title says. */
|
|
24
28
|
export const NATIVE_EFFECT_KINDS = new Set(["execute", "edit", "delete", "move", "fetch"]);
|
|
25
|
-
/** The host tool
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* (CallIds.announced). */
|
|
29
|
+
/** The host tool a permission request's title or name gives, by a name for our MCP server's tools (`agentrun__<tool>`),
|
|
30
|
+
* Cursor's own title for one (`agentrun-<tool>: <tool>`), or agy's (Antigravity's) name and title for one
|
|
31
|
+
* (`mcp_agentrun_<tool>`, titled `Run mcp_agentrun_<tool>`, the whole text), when it is one of `tools` and its kind is
|
|
32
|
+
* not one with effects of its own. Read for the title tie alone (quirks.permissionTie: Cursor's and agy's), and only
|
|
33
|
+
* beside the call's announcement: the title is the agent's text, so a request is tied only when it is for a call the
|
|
34
|
+
* recipe's announces field named as the same tool (CallIds.announced). Nothing else reads a title. */
|
|
31
35
|
export function ourTool(update, tools) {
|
|
32
36
|
if (typeof update.kind === "string" && NATIVE_EFFECT_KINDS.has(update.kind))
|
|
33
37
|
return undefined;
|
|
34
38
|
const candidates = [];
|
|
35
|
-
for (const
|
|
36
|
-
if (typeof
|
|
39
|
+
for (const said of [update.name, update.title]) {
|
|
40
|
+
if (typeof said !== "string")
|
|
37
41
|
continue;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
candidates.push(goose[1]);
|
|
43
|
-
const cursor = new RegExp(`^${MCP_SERVER}(-[^:]*)?: (.+)$`).exec(said);
|
|
42
|
+
const named = new RegExp(`^${MCP_SERVER}__(.+)$`).exec(said);
|
|
43
|
+
if (named)
|
|
44
|
+
candidates.push(named[1]);
|
|
45
|
+
const cursor = new RegExp(`^${MCP_SERVER}-[^:]*: (.+)$`).exec(said);
|
|
44
46
|
if (cursor)
|
|
45
|
-
candidates.push(cursor[
|
|
47
|
+
candidates.push(cursor[1].trim());
|
|
48
|
+
const agy = AGY_NAME.exec(said);
|
|
49
|
+
if (agy)
|
|
50
|
+
candidates.push(agy[1]);
|
|
46
51
|
}
|
|
47
52
|
return candidates.find((name) => tools.has(name));
|
|
48
53
|
}
|
|
49
|
-
/**
|
|
54
|
+
/** agy's (Antigravity's) name or title for a call of our MCP server's tool `<tool>`: `mcp_agentrun_<tool>`, titled
|
|
55
|
+
* `Run mcp_agentrun_<tool>`, the whole text (agy 1.5.14 writes no summary after either). */
|
|
56
|
+
const AGY_NAME = new RegExp(`^(?:Run )?mcp_${MCP_SERVER}_(.+)$`);
|
|
57
|
+
/** The prefix a recipe's announces.prefix may be: our server's name, with at most one word and a `_` or `-` before it,
|
|
58
|
+
* and one or two `_` or `-` after it (`agentrun__`, `mcp_agentrun_`). */
|
|
59
|
+
export const ANNOUNCES_PREFIX = new RegExp(`^(?:[A-Za-z0-9]+[_-])?${MCP_SERVER}[_-]{1,2}$`);
|
|
60
|
+
/** A field name announces.extras may list. */
|
|
61
|
+
export const ANNOUNCES_EXTRA = /^[A-Za-z_$][\w$-]*$/;
|
|
62
|
+
/** A path an AcpAnnounces field may hold: field names joined by dots, never starting at the update's title,
|
|
63
|
+
* toolCallId, kind, status, rawOutput, content, locations or sessionUpdate: a path through the title would let the
|
|
64
|
+
* agent's text name a call again, one through rawOutput or content a tool's output. */
|
|
65
|
+
export const ANNOUNCES_PATH = /^(?!(?:title|toolCallId|kind|status|rawOutput|content|locations|sessionUpdate)(?:\.|$))[A-Za-z_$][\w$-]*(?:\.[A-Za-z_$][\w$-]*)*$/;
|
|
66
|
+
/** The value at a dotted `path` in `value`, own fields only; undefined where any step is missing. */
|
|
67
|
+
function at(value, path) {
|
|
68
|
+
let here = value;
|
|
69
|
+
for (const key of path.split(".")) {
|
|
70
|
+
if (!isPlain(here) || !Object.hasOwn(here, key))
|
|
71
|
+
return undefined;
|
|
72
|
+
here = here[key];
|
|
73
|
+
}
|
|
74
|
+
return here;
|
|
75
|
+
}
|
|
76
|
+
/** The most of the word at a recipe's announces.tool a debug line quotes. */
|
|
77
|
+
export const ANNOUNCED_FIELD_CHARS = 200;
|
|
78
|
+
/** The word at the recipe's announces.tool in `update`, clipped to ANNOUNCED_FIELD_CHARS: what the agent said it calls.
|
|
79
|
+
* It may sit inside the call's input (Cursor's rawInput.toolName): the debug line (harness.ts) quotes it only for a call
|
|
80
|
+
* of ours. Null when the recipe declares no field or it holds no string. */
|
|
81
|
+
export function announcedField(update, announces) {
|
|
82
|
+
const said = announces ? at(update, announces.tool) : undefined;
|
|
83
|
+
return typeof said === "string" ? said.slice(0, ANNOUNCED_FIELD_CHARS) : null;
|
|
84
|
+
}
|
|
85
|
+
/** The tool of ours an agent's update names in the field its recipe declares (`announces`): its name; null when the
|
|
86
|
+
* field names a tool that is not ours (another server's, one without our prefix, or one of our server's that `tools`
|
|
87
|
+
* does not list); undefined when the recipe declares no field or the update does not carry it. A title is never read. */
|
|
88
|
+
export function announcedTool(update, announces, tools) {
|
|
89
|
+
if (!announces)
|
|
90
|
+
return undefined;
|
|
91
|
+
const said = at(update, announces.tool);
|
|
92
|
+
if (typeof said !== "string" || said === "")
|
|
93
|
+
return undefined;
|
|
94
|
+
let tool = said;
|
|
95
|
+
if (announces.server !== undefined) {
|
|
96
|
+
if (at(update, announces.server) !== MCP_SERVER)
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const prefix = announces.prefix ?? `${MCP_SERVER}__`;
|
|
101
|
+
if (!said.startsWith(prefix))
|
|
102
|
+
return null;
|
|
103
|
+
tool = said.slice(prefix.length);
|
|
104
|
+
}
|
|
105
|
+
return tools.has(tool) ? tool : null;
|
|
106
|
+
}
|
|
107
|
+
/** The arguments an update reports for its call: at the recipe's `announces.args`, or its rawInput, without the
|
|
108
|
+
* recipe's `extras` that hold text (agy's toolSummary). */
|
|
109
|
+
function announcedArgs(update, announces) {
|
|
110
|
+
const args = announces?.args !== undefined ? at(update, announces.args) : update.rawInput;
|
|
111
|
+
const extras = announces?.extras ?? [];
|
|
112
|
+
if (!isPlain(args) || !extras.some((name) => typeof args[name] === "string"))
|
|
113
|
+
return args;
|
|
114
|
+
return Object.fromEntries(Object.entries(args).filter(([name, value]) => !(extras.includes(name) && typeof value === "string")));
|
|
115
|
+
}
|
|
116
|
+
const hasEffects = (kind) => typeof kind === "string" && NATIVE_EFFECT_KINDS.has(kind);
|
|
117
|
+
/** The agent's tool_call `update`, kept for the MCP call it may be: a call whose kind has effects of its own never is
|
|
118
|
+
* (a shell named as our tool never takes an MCP call's id); one the recipe's field names as another tool is the agent's
|
|
119
|
+
* own; one it names as ours is kept as that tool; one it names nothing for is matched by its arguments alone, except
|
|
120
|
+
* one with no arguments on a recipe whose field names calls, which waits for the update that names it. On a recipe
|
|
121
|
+
* without the field, one reporting no input at all is kept as a call that names nothing (CallIds.add). */
|
|
122
|
+
export function announceCall(calls, update, announces, tools) {
|
|
123
|
+
if (hasEffects(update.kind))
|
|
124
|
+
return;
|
|
125
|
+
const tool = announcedTool(update, announces, tools);
|
|
126
|
+
if (tool === null)
|
|
127
|
+
return;
|
|
128
|
+
// Named by nothing and reporting no arguments, on a recipe that declares the field (Cursor's untitled `MCP: tool`,
|
|
129
|
+
// rawInput {}, before its late update names it): {} would tie it to any call with no arguments, of any tool, so it
|
|
130
|
+
// is held for the update that names it (nameCall), and only that. On a recipe without the field nothing names it
|
|
131
|
+
// later: it is matched by {} at once, and one with no input at all as a call that names nothing.
|
|
132
|
+
const raw = update.rawInput;
|
|
133
|
+
if (tool === undefined && announces && (raw === undefined || raw === null || (isPlain(raw) && Object.keys(raw).length === 0)))
|
|
134
|
+
return calls.hold(update.toolCallId);
|
|
135
|
+
// Named by nothing, on a recipe that names its calls, with input that is no argument object: its field never named
|
|
136
|
+
// it, so it is the agent's own.
|
|
137
|
+
if (tool === undefined && announces && !isPlain(raw))
|
|
138
|
+
return;
|
|
139
|
+
calls.add(update.toolCallId, tool, tool === undefined ? update.rawInput : announcedArgs(update, announces));
|
|
140
|
+
}
|
|
141
|
+
/** A tool_call_update naming a call its tool_call left unnamed with no input (Cursor's MCP calls: a tool_call titled
|
|
142
|
+
* "MCP: tool" with rawInput {}, then this update with rawInput {providerIdentifier, toolName, args}): kept as that
|
|
143
|
+
* tool, under the id its tool_call already counted, by the recipe's field. Only a call announceCall held for its name
|
|
144
|
+
* (CallIds.held): one whose tool_call reported input, or named a tool, is never named later, so a native read whose
|
|
145
|
+
* update echoes the model's arguments stays the agent's own. The tool_call's kind was checked before it was held;
|
|
146
|
+
* the update's is checked here: a shell renamed by a later update is never ours. */
|
|
147
|
+
export function nameCall(calls, update, announces, tools) {
|
|
148
|
+
if (!calls.held(update.toolCallId) || hasEffects(update.kind))
|
|
149
|
+
return;
|
|
150
|
+
const tool = announcedTool(update, announces, tools);
|
|
151
|
+
if (typeof tool !== "string")
|
|
152
|
+
return;
|
|
153
|
+
calls.add(update.toolCallId, tool, announcedArgs(update, announces));
|
|
154
|
+
}
|
|
155
|
+
/** The key of an announcement that names no tool and reports no input (CallIds.add). */
|
|
156
|
+
const NOTHING = "\0*";
|
|
157
|
+
/** The agent's announced calls, matched to the MCP calls of our tools that reach the server. */
|
|
50
158
|
export class CallIds {
|
|
51
159
|
seen = new Map();
|
|
52
160
|
waiting = new Map();
|
|
53
161
|
used = new Set();
|
|
54
162
|
tools = new Map();
|
|
55
|
-
/** The
|
|
163
|
+
/** The key each announcement still waiting for its MCP call is kept under. */
|
|
164
|
+
keyOf = new Map();
|
|
165
|
+
/** The calls announced naming no tool and reporting no input, held for the update that names them (hold). */
|
|
166
|
+
unnamed = new Set();
|
|
167
|
+
/** The agent announced call `id` naming no tool and reporting no input, on a recipe whose field names calls: held for
|
|
168
|
+
* the later update that names it (nameCall), and matched to nothing until then. */
|
|
169
|
+
hold(id) {
|
|
170
|
+
if (!this.used.has(id) && !this.tools.has(id))
|
|
171
|
+
this.unnamed.add(id);
|
|
172
|
+
}
|
|
173
|
+
/** Whether `id` is held for its name (hold) and no update has named it yet. */
|
|
174
|
+
held(id) {
|
|
175
|
+
return this.unnamed.has(id);
|
|
176
|
+
}
|
|
177
|
+
/** The agent announced call `id` with `input`, its recipe's field naming `tool` of ours, or none (undefined). Input
|
|
178
|
+
* that is not an object (none reported, or a value that is not an argument object) is no input. One with no tool is
|
|
179
|
+
* matched by its input alone, an object ({} included: announceCall holds one back where a later update will name
|
|
180
|
+
* the call); one with no input by its tool alone. One with neither (only on a recipe without announces: announceCall
|
|
181
|
+
* never keeps one elsewhere) is the last an MCP call takes, of any tool, when nothing else matches it: nothing names
|
|
182
|
+
* it and nothing ties it, and its MCP call would otherwise run under an id of the adapter's, counted a second time
|
|
183
|
+
* against a plan's limit and memoized under a key a resume never asks again. Until its call ends (settle). A tool
|
|
184
|
+
* named for an id already announced without one (a call the agent named in a later update) keys it again. */
|
|
56
185
|
add(id, tool, input) {
|
|
57
186
|
if (this.used.has(id))
|
|
58
187
|
return;
|
|
59
|
-
if (
|
|
188
|
+
if (tool !== undefined)
|
|
189
|
+
this.unnamed.delete(id);
|
|
190
|
+
if (tool !== undefined && !this.tools.has(id))
|
|
60
191
|
this.tools.set(id, tool);
|
|
61
|
-
// An announced call with
|
|
62
|
-
//
|
|
63
|
-
const key = input
|
|
192
|
+
// An announced call with input is matched only by that input (and its tool, where the field named one), so it never
|
|
193
|
+
// takes an MCP call with other arguments that is waiting for its own announcement.
|
|
194
|
+
const key = isPlain(input) ? `${tool ?? ""}\0${canonical(input)}` : `${tool ?? ""}\0*`;
|
|
195
|
+
const before = this.keyOf.get(id);
|
|
196
|
+
if (before === key)
|
|
197
|
+
return;
|
|
198
|
+
if (before !== undefined) {
|
|
199
|
+
const list = this.seen.get(before) ?? [];
|
|
200
|
+
const at = list.indexOf(id);
|
|
201
|
+
if (at >= 0)
|
|
202
|
+
list.splice(at, 1);
|
|
203
|
+
}
|
|
64
204
|
const waiter = this.waiting.get(key)?.shift();
|
|
65
205
|
if (waiter) {
|
|
206
|
+
this.keyOf.delete(id);
|
|
66
207
|
this.used.add(id);
|
|
67
208
|
waiter(id);
|
|
68
209
|
return;
|
|
69
210
|
}
|
|
70
211
|
const list = this.seen.get(key) ?? [];
|
|
71
|
-
|
|
72
|
-
list.push(id);
|
|
212
|
+
list.push(id);
|
|
73
213
|
this.seen.set(key, list);
|
|
214
|
+
this.keyOf.set(id, key);
|
|
215
|
+
}
|
|
216
|
+
/** The agent's call `id` ended (completed or failed) with no MCP call having taken it: an announcement that names
|
|
217
|
+
* nothing and reports nothing is dropped, so a call of the agent's own never takes a later MCP call's id. */
|
|
218
|
+
settle(id) {
|
|
219
|
+
if (this.keyOf.get(id) !== NOTHING)
|
|
220
|
+
return;
|
|
221
|
+
const list = this.seen.get(NOTHING) ?? [];
|
|
222
|
+
const at = list.indexOf(id);
|
|
223
|
+
if (at >= 0)
|
|
224
|
+
list.splice(at, 1);
|
|
225
|
+
this.keyOf.delete(id);
|
|
74
226
|
}
|
|
75
227
|
/** Whether the agent announced `id` (matched or not). */
|
|
76
228
|
has(id) {
|
|
77
|
-
return this.used.has(id) ||
|
|
229
|
+
return this.used.has(id) || this.keyOf.has(id);
|
|
78
230
|
}
|
|
79
|
-
/** The tool of ours the agent's tool_call `id` was announced as, or undefined when no
|
|
231
|
+
/** The tool of ours the agent's tool_call `id` was announced as, or undefined when no tool_call named one. */
|
|
80
232
|
announced(id) {
|
|
81
233
|
return this.tools.get(id);
|
|
82
234
|
}
|
|
83
235
|
/** The id of an MCP call of `tool` with `args`: the agent's announced one, waited for at most `ms`; undefined when none
|
|
84
|
-
* came by then.
|
|
236
|
+
* came by then. Of the announcements with the same arguments, the oldest named `tool` first, then the oldest named
|
|
237
|
+
* none; then the oldest of `tool` that reported no input. Then, already there or once the wait is over, never woken
|
|
238
|
+
* by one coming in during it (which may be the agent's own while this call's own announcement is on its way), the
|
|
239
|
+
* oldest that named nothing and reported nothing. */
|
|
85
240
|
async take(tool, args, signal, ms) {
|
|
86
|
-
const keys = [`${tool}\0${canonical(args)}`, `${tool}\0*`];
|
|
241
|
+
const keys = [`${tool}\0${canonical(args)}`, `\0${canonical(args)}`, `${tool}\0*`];
|
|
87
242
|
const ready = (from) => {
|
|
88
243
|
for (const key of from) {
|
|
89
244
|
const id = this.seen.get(key)?.shift();
|
|
90
245
|
if (id) {
|
|
246
|
+
this.keyOf.delete(id);
|
|
91
247
|
this.used.add(id);
|
|
92
248
|
return id;
|
|
93
249
|
}
|
|
94
250
|
}
|
|
95
251
|
return undefined;
|
|
96
252
|
};
|
|
97
|
-
// Once the wait is over, the oldest announced call
|
|
98
|
-
|
|
99
|
-
|
|
253
|
+
// Once the wait is over, the oldest announced call named `tool` whose reported input differs from what reached MCP.
|
|
254
|
+
// Never one named no tool with other arguments: its arguments are all that ties it, and they differ. Then the oldest
|
|
255
|
+
// that named nothing and reported nothing.
|
|
256
|
+
const loose = () => ready([...[...this.seen.keys()].filter((key) => key.startsWith(`${tool}\0`)), NOTHING]);
|
|
257
|
+
const now = ready([...keys, NOTHING]);
|
|
100
258
|
if (now)
|
|
101
259
|
return now;
|
|
102
260
|
return new Promise((resolve, reject) => {
|
package/dist/goose-facts.js
CHANGED
|
@@ -22,6 +22,8 @@ export const gooseFacts = Object.freeze({
|
|
|
22
22
|
thinking: Object.freeze(["high"]),
|
|
23
23
|
// Its model is Anthropic's, on its own settings, never the gateway's default for the other harnesses.
|
|
24
24
|
ownModel: true,
|
|
25
|
+
// Its proxy forwards with the fetch it is handed: a model the route translates onto its wire runs on it.
|
|
26
|
+
forwardsRoute: true,
|
|
25
27
|
// Anthropic's ids hold no dot; OpenRouter names the same models with dots (anthropic/claude-sonnet-5.5).
|
|
26
28
|
normalizeModel: (model) => (model.provider === "anthropic" ? { ...model, modelId: model.modelId.replaceAll(".", "-") } : model),
|
|
27
29
|
// Installed by its owner, never on first use: the archive the pin names, its digests checked (serve's harness-archive.ts).
|
package/dist/goose.js
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
// it on a pinned binary. Written for AgentRun.
|
|
3
3
|
//
|
|
4
4
|
// What the recipe holds was measured on Goose 1.59.2 over ACP:
|
|
5
|
-
// - `goose acp` in a private HOME, provider `anthropic` in approve mode
|
|
6
|
-
//
|
|
5
|
+
// - `goose acp` in a private HOME, provider `anthropic` in approve mode: a call of one of Goose's own tools asks
|
|
6
|
+
// permission (the host's gate answers it, allow_once or reject_once, never an `always`), and a call of ours asks
|
|
7
|
+
// nothing, since `$HOME/.config/goose/permission.yaml`, the recipe's allowFile written at each start, allows each of
|
|
8
|
+
// the run's tools by its name (`agentrun__<name>`), which approve mode reads before it asks; our tools' gate is the
|
|
9
|
+
// host's, at the MCP call. The recipe declares no title tie (quirks.permissionTie), so every request Goose does make
|
|
10
|
+
// goes to the host's gate. Session naming and the keyring off;
|
|
7
11
|
// - every bundled extension off in `$HOME/.config/goose/config.yaml`, which leaves the model our MCP server's tools
|
|
8
12
|
// (`agentrun__<name>`) and `load_skill`, which Goose always offers. ACP's `_meta.enabledExtensions: []` is not used:
|
|
9
13
|
// it drops our MCP server too;
|
package/dist/harness.d.ts
CHANGED
|
@@ -63,6 +63,10 @@ export interface AcpHarnessOptions {
|
|
|
63
63
|
callIdWaitMs?: number;
|
|
64
64
|
startMs?: number;
|
|
65
65
|
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
66
|
+
/** Log each call the agent announces ("acp: the agent announced a call": its toolCallId, kind, the word at the
|
|
67
|
+
* recipe's announces.tool and the tool of ours it named), on a recipe that declares announces, and again when a later
|
|
68
|
+
* update names a call announced with no name. Ids and names only. */
|
|
69
|
+
debug?: boolean;
|
|
66
70
|
}
|
|
67
71
|
/** What the adapter holds of the drive in flight, to stop its turn. */
|
|
68
72
|
export interface DriveControl {
|
package/dist/harness.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// The agent is one process per kernel Drive (one per runner's hold of the session), started at the drive's first turn
|
|
4
4
|
// and ended with it: a turn after another goes to the same agent session, as a person's would. A drive:
|
|
5
5
|
// 1. makes the session's private HOME fresh and gives it back what the records mirrored of the agent's own session
|
|
6
|
-
// store (state.ts), then the recipe's own files;
|
|
6
|
+
// store (state.ts), then the recipe's own files and its allowFile, from the tools this start lists;
|
|
7
7
|
// 2. starts the agent (host/agent.ts: the environment allowlist, its own process group) and the adapter's MCP server
|
|
8
8
|
// (host/mcp.ts: the host's tools, nothing else), and checks initialize against the recipe's declares;
|
|
9
9
|
// 3. gives the agent back its session (session/load, its replayed history kept off the timeline), or a new one, whose
|
|
@@ -19,9 +19,9 @@ 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 { CallIds, MCP_SERVER, ourTool, permissionCallId } from "./calls.js";
|
|
22
|
+
import { announceCall, announcedField, CallIds, MCP_SERVER, nameCall, ourTool, permissionCallId } from "./calls.js";
|
|
23
23
|
import { ACP_CODES } from "./facts.js";
|
|
24
|
-
import { homePath } from "./recipe.js";
|
|
24
|
+
import { allowFileText, homePath } from "./recipe.js";
|
|
25
25
|
import { restoreState, STATE_STREAM, StateMirror } from "./state.js";
|
|
26
26
|
import { startAgent } from "./host/agent.js";
|
|
27
27
|
import { cutKeys, keysToCut } from "./host/key-cut.js";
|
|
@@ -50,6 +50,9 @@ export const START_MS = 60_000;
|
|
|
50
50
|
export const CALL_ID_WAIT_MS = 10_000;
|
|
51
51
|
/** How long a drive's end waits for the agent's process to go. */
|
|
52
52
|
const EXIT_WAIT_MS = 5_000;
|
|
53
|
+
/** How long a failure read off an agent that went waits for its process's close, which comes once its stderr is read to
|
|
54
|
+
* the end: its connection closes at its stdout's end, which can come first. */
|
|
55
|
+
const LAST_WORDS_MS = 5_000;
|
|
53
56
|
/** How long an agent past the plan's limit of tool calls has to end its turn after session/cancel before its process is
|
|
54
57
|
* ended: past the limit, each moment it goes on is spent on the owner's plan. */
|
|
55
58
|
export const LIMIT_STOP_MS = 3_000;
|
|
@@ -61,6 +64,15 @@ export const NOTE_RESULT_CHARS = 2_000;
|
|
|
61
64
|
/** The stdio MCP bridge the agent starts when it takes no MCP over HTTP. */
|
|
62
65
|
const STDIO_BRIDGE = fileURLToPath(new URL("./host/mcp-stdio.js", import.meta.url));
|
|
63
66
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
67
|
+
/** An agent that ended, or whose connection closed: its stderr read to the end (its process's close), for at most
|
|
68
|
+
* LAST_WORDS_MS, so its last words (a refusal it names on its way out) are in its tail. One still running: at once. */
|
|
69
|
+
async function stderrRead(agent) {
|
|
70
|
+
if (agent.alive() && !agent.connection.signal.aborted)
|
|
71
|
+
return;
|
|
72
|
+
let timer;
|
|
73
|
+
await Promise.race([agent.exited, new Promise((resolve) => { timer = setTimeout(resolve, LAST_WORDS_MS); })]);
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
}
|
|
64
76
|
const message = (error) => String(error?.message ?? error);
|
|
65
77
|
const clip = (text, max) => (text.length <= max ? text : `${text.slice(0, max)}… [${text.length - max} more characters]`);
|
|
66
78
|
const indent = (text) => text.split("\n").map((line) => ` ${line}`).join("\n");
|
|
@@ -222,6 +234,17 @@ export function acpHarness(options, control) {
|
|
|
222
234
|
}
|
|
223
235
|
return turn?.limitHit ?? `${ACP_CODES.toolCallLimit}: the plan's limit of ${plan.maxToolCalls} tool calls is reached`;
|
|
224
236
|
};
|
|
237
|
+
/** Debug only (serve's AGENTRUN_LOG=debug), on a recipe that declares announces: a call the agent announced, by its
|
|
238
|
+
* ids and names, never its input or the agent's text. The word at the recipe's field is quoted only when it names a
|
|
239
|
+
* tool of ours: on Cursor's recipe it sits inside the call's input, so another call's is "native" (null: none).
|
|
240
|
+
* Written at its tool_call, and again at the later update that names a call announced with no name (Cursor's). */
|
|
241
|
+
const logAnnounced = (rt, said) => {
|
|
242
|
+
if (!options.debug || !recipe.announces)
|
|
243
|
+
return;
|
|
244
|
+
const ours = rt.calls.announced(said.toolCallId) ?? null;
|
|
245
|
+
const field = announcedField(said, recipe.announces);
|
|
246
|
+
log("acp: the agent announced a call", { toolCallId: said.toolCallId, kind: said.kind ?? null, field: field && (ours === null ? "native" : field), ours });
|
|
247
|
+
};
|
|
225
248
|
const onUpdate = (rt, notification) => {
|
|
226
249
|
if (rt.loading || notification.sessionId !== rt.sessionId)
|
|
227
250
|
return;
|
|
@@ -242,36 +265,24 @@ export function acpHarness(options, control) {
|
|
|
242
265
|
if (cur.turn)
|
|
243
266
|
cur.turn.final = "";
|
|
244
267
|
countCall(rt, cur, update.toolCallId);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
// MCP call's id, and never passes the permission shortcut below.
|
|
249
|
-
const tool = ourTool(update, names);
|
|
250
|
-
if (tool)
|
|
251
|
-
rt.calls.add(update.toolCallId, tool, update.rawInput);
|
|
268
|
+
// Kept for the MCP call it may be, named by the recipe's announces field, never by its title (announceCall).
|
|
269
|
+
announceCall(rt.calls, update, recipe.announces, names);
|
|
270
|
+
logAnnounced(rt, update);
|
|
252
271
|
return;
|
|
253
272
|
}
|
|
254
273
|
case "tool_call_update": {
|
|
255
274
|
if (!cur)
|
|
256
275
|
return;
|
|
257
|
-
// A call the agent named only after announcing it (Cursor's
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// Held to both kinds, the tool_call's and the update's: a shell renamed by a later update is never ours.
|
|
263
|
-
const title = update.title ?? null;
|
|
264
|
-
const announcedAs = ourTool({ title, kind: rt.kinds.get(update.toolCallId) ?? null }, names);
|
|
265
|
-
const tool = announcedAs && ourTool({ title, kind: update.kind ?? null }, names) === announcedAs ? announcedAs : undefined;
|
|
266
|
-
if (tool) {
|
|
267
|
-
const raw = update.rawInput;
|
|
268
|
-
const args = raw && raw.toolName === tool && typeof raw.args === "object" && raw.args !== null && !Array.isArray(raw.args) ? raw.args : raw;
|
|
269
|
-
rt.calls.add(update.toolCallId, tool, args);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
276
|
+
// A call the agent named only after announcing it with no input (Cursor's): by the recipe's field (nameCall).
|
|
277
|
+
const held = rt.calls.held(update.toolCallId);
|
|
278
|
+
nameCall(rt.calls, update, recipe.announces, names);
|
|
279
|
+
if (held && !rt.calls.held(update.toolCallId))
|
|
280
|
+
logAnnounced(rt, update);
|
|
272
281
|
// Its status is the agent's word only: what it changes is the mirror of the agent's session store.
|
|
273
282
|
if (update.status !== "completed" && update.status !== "failed")
|
|
274
283
|
return;
|
|
284
|
+
// An ended call takes no MCP call's id (CallIds.settle).
|
|
285
|
+
rt.calls.settle(update.toolCallId);
|
|
275
286
|
mirrorInto(rt, cur.journal);
|
|
276
287
|
void cur.journal.flush().catch(() => { });
|
|
277
288
|
return;
|
|
@@ -281,8 +292,9 @@ export function acpHarness(options, control) {
|
|
|
281
292
|
}
|
|
282
293
|
};
|
|
283
294
|
/** The gate's call for a permission request of the agent's own tool: the same when the agent asks and when a resume
|
|
284
|
-
* asks about it again (settlePermissions), so both reach the one approval.
|
|
285
|
-
|
|
295
|
+
* asks about it again (settlePermissions), so both reach the one approval. Under its journal id (`callId`); its args
|
|
296
|
+
* carry the toolCallId the agent first asked under, so a host (harness-check) ties the question to the request. */
|
|
297
|
+
const permissionGateCall = (callId, toolCallId, kind, title, input) => ({ callId, tool: `acp_${kind.replace(/[^A-Za-z0-9_]/g, "_")}`, args: { title, kind, input, ...(toolCallId ? { toolCallId } : {}) } });
|
|
286
298
|
/** The recovery note's line for a settled answer: the request as the agent asked it (its kind, title and input, so an
|
|
287
299
|
* agent started without session/load can ask for the same call) and what the person said. */
|
|
288
300
|
const answerLine = (asked, answer) => {
|
|
@@ -316,7 +328,7 @@ export function acpHarness(options, control) {
|
|
|
316
328
|
for (const request of waiting) {
|
|
317
329
|
const kind = request.kind ?? "other";
|
|
318
330
|
const title = request.title ?? kind;
|
|
319
|
-
const refused = await askGate(gate, permissionGateCall(request.callId, kind, title, request.input ?? null), ctx.signal);
|
|
331
|
+
const refused = await askGate(gate, permissionGateCall(request.callId, request.toolCallId, kind, title, request.input ?? null), ctx.signal);
|
|
320
332
|
const answer = { type: "answered", callId: request.callId, answer: refused ? "deny" : "allow", ...(refused?.deny ? { words: refused.deny } : {}), settled: true, turn: turnId };
|
|
321
333
|
journal.append(PERMISSION_STREAM, answer);
|
|
322
334
|
await journal.flush();
|
|
@@ -346,13 +358,19 @@ export function acpHarness(options, control) {
|
|
|
346
358
|
return turn?.limitHit ? choose("reject_once") : cancelled;
|
|
347
359
|
if (turn.limitHit)
|
|
348
360
|
return choose("reject_once");
|
|
349
|
-
// Our own tool
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
361
|
+
// Our own tool, on a recipe that declares the title tie (quirks.permissionTie: Cursor's and Antigravity's): the gate
|
|
362
|
+
// is the bridge's, asked at the MCP call itself, so the request is allowed once, never always. Cursor needs it: its
|
|
363
|
+
// allowlist with allow: [] (which keeps it from writing files unasked) asks for every MCP call, ours included, and
|
|
364
|
+
// agy asks for every MCP call. The
|
|
365
|
+
// title is the agent's text, so the tie takes both: a request whose kind has no effects of its own and whose title
|
|
366
|
+
// names our tool, for a call the recipe's announces field named as that same tool under the request's own id (a
|
|
367
|
+
// title never sets that: CallIds.announced comes from the field alone). Without the
|
|
368
|
+
// quirk (Goose, which asks nothing for our tools: its allowFile) every request is the host gate's, journaled.
|
|
369
|
+
if (recipe.quirks?.permissionTie === "title") {
|
|
370
|
+
const mine = ourTool(request.toolCall, names);
|
|
371
|
+
if (mine && rt.calls.announced(request.toolCall.toolCallId) === mine)
|
|
372
|
+
return choose("allow_once");
|
|
373
|
+
}
|
|
356
374
|
const call = request.toolCall;
|
|
357
375
|
const kind = typeof call.kind === "string" && call.kind ? call.kind : "other";
|
|
358
376
|
const title = typeof call.title === "string" ? call.title : kind;
|
|
@@ -405,8 +423,10 @@ export function acpHarness(options, control) {
|
|
|
405
423
|
}
|
|
406
424
|
let refused;
|
|
407
425
|
if (options.gate) {
|
|
426
|
+
// The toolCallId the request was first asked under, as the journal has it: the same question a resume asks.
|
|
427
|
+
const askedAs = records.find((r) => r.type === "asked")?.toolCallId ?? call.toolCallId;
|
|
408
428
|
try {
|
|
409
|
-
refused = await askGate(options.gate, permissionGateCall(callId, kind, title, input), AbortSignal.any([cur.signal, connection, turn.stop.signal]));
|
|
429
|
+
refused = await askGate(options.gate, permissionGateCall(callId, askedAs, kind, title, input), AbortSignal.any([cur.signal, connection, turn.stop.signal]));
|
|
410
430
|
}
|
|
411
431
|
catch {
|
|
412
432
|
// Parked, and the session let go (or the turn was cancelled): nothing is answered, nothing recorded.
|
|
@@ -493,8 +513,13 @@ export function acpHarness(options, control) {
|
|
|
493
513
|
const records = (await journal.read(STATE_STREAM)).map((r) => r.data);
|
|
494
514
|
restoreState(home, records);
|
|
495
515
|
const own = new Set();
|
|
496
|
-
|
|
516
|
+
// The recipe's allowFile (Goose's permission file): the tools this start lists, in the agent's own form, and nothing
|
|
517
|
+
// else, so the agent runs them unasked and our gate asks at the MCP call.
|
|
518
|
+
const allowed = recipe.allowFile ? { [recipe.allowFile.path]: allowFileText(recipe.allowFile.form, listed.map((tool) => tool.name)) } : {};
|
|
519
|
+
for (const [path, text] of [...Object.entries(recipe.files ?? {}), ...Object.entries(allowed)]) {
|
|
497
520
|
const clean = homePath(path);
|
|
521
|
+
if (!clean)
|
|
522
|
+
throw new Error(`acp: the file ${JSON.stringify(path)} must be inside the private HOME`);
|
|
498
523
|
const file = join(home, clean);
|
|
499
524
|
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
|
|
500
525
|
writeFileSync(file, text, { mode: 0o600 });
|
|
@@ -513,7 +538,7 @@ export function acpHarness(options, control) {
|
|
|
513
538
|
const stopped = new AbortController();
|
|
514
539
|
const signal = AbortSignal.any([ctx.signal, stopped.signal]);
|
|
515
540
|
const key = randomBytes(32).toString("base64url");
|
|
516
|
-
const rt = { ctx, loading: false, fresh: true, wiped: false, firstBlocks: [], calls: new CallIds(), counted: new Set(), claimed: new Set(), ownIds: new Set(),
|
|
541
|
+
const rt = { ctx, loading: false, fresh: true, wiped: false, firstBlocks: [], calls: new CallIds(), counted: new Set(), claimed: new Set(), ownIds: new Set(), sessionId: "", mirror: new StateMirror(home, (recipe.state ?? []).map((p) => homePath(p)), own, records, log, (words) => (rt.current?.ctx ?? ctx).live({ type: "notice", text: words })) };
|
|
517
542
|
const mcp = await startMcpServer({ tools: listed.map((t) => ({ name: t.name, description: t.description, inputSchema: t.inputSchema })), key, log, call: (name, args, callSignal) => onMcpCall(rt, name, args, callSignal) });
|
|
518
543
|
let proxy;
|
|
519
544
|
let agent;
|
|
@@ -592,8 +617,7 @@ export function acpHarness(options, control) {
|
|
|
592
617
|
if (signal.aborted)
|
|
593
618
|
throw signal.reason;
|
|
594
619
|
// An agent that says why on its way out: its stderr is read once it has ended.
|
|
595
|
-
|
|
596
|
-
await Promise.race([live.exited, sleep(500)]);
|
|
620
|
+
await stderrRead(live);
|
|
597
621
|
const named = refusalIn(`${live.stderrTail()}\n${message(error)}`);
|
|
598
622
|
if (named)
|
|
599
623
|
throw new Error(named);
|
|
@@ -829,6 +853,8 @@ export function acpHarness(options, control) {
|
|
|
829
853
|
if (turn.limitHit)
|
|
830
854
|
outcome = { status: "failed", error: turn.limitHit };
|
|
831
855
|
else if (failure !== undefined) {
|
|
856
|
+
// An agent that says why on its way out: its stderr is read once it has ended.
|
|
857
|
+
await stderrRead(agent.agent);
|
|
832
858
|
const named = refusalIn(`${agent.agent.stderrTail()}\n${message(failure)}`);
|
|
833
859
|
outcome = { status: "failed", error: named ?? (agent.agent.alive() && !agent.agent.connection.signal.aborted ? `acp: session/prompt failed: ${agentSaid(failure)}` : `${ACP_CODES.agentExited}: the agent ended during the turn: ${whyEnded(agent.agent, failure)}`) };
|
|
834
860
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { acpAdapter, type AcpAdapterOptions, type AcpProxy, type AcpProxySession } from "./adapter.js";
|
|
2
2
|
export { ACP_CODES, acpFacts, type AcpFacts } from "./facts.js";
|
|
3
|
-
export { AUTH_METHOD, homePath, MODEL_ID, recipeProblems, RESERVED_ENV, type AcpBilling, type AcpRecipe, type AcpRefusal } from "./recipe.js";
|
|
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
|
+
export { ANNOUNCES_PATH, type AcpAnnounces } from "./calls.js";
|
|
4
5
|
export { CALL_STREAM, contextNote, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
5
6
|
export { STATE_BUDGET, STATE_STREAM, stateBudgetPassed, stateFiles, type StateRecord } from "./state.js";
|
|
6
7
|
export type { ConfineChild } from "./host/child.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Any Agent Client Protocol agent as an AgentRun harness. Written for AgentRun.
|
|
2
2
|
export { acpAdapter } from "./adapter.js";
|
|
3
3
|
export { ACP_CODES, acpFacts } from "./facts.js";
|
|
4
|
-
export { AUTH_METHOD, homePath, MODEL_ID, recipeProblems, RESERVED_ENV } from "./recipe.js";
|
|
4
|
+
export { ALLOW_FILE_FORMS, allowFileText, announcesProblems, AUTH_METHOD, homePath, MODEL_ID, recipeProblems, RESERVED_ENV } from "./recipe.js";
|
|
5
|
+
export { ANNOUNCES_PATH } from "./calls.js";
|
|
5
6
|
export { CALL_STREAM, contextNote, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
6
7
|
export { STATE_BUDGET, STATE_STREAM, stateBudgetPassed, stateFiles } from "./state.js";
|
|
7
8
|
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
package/dist/recipe.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AcpAnnounces } from "./calls.js";
|
|
1
2
|
/** Who pays for the agent's model requests. `plan`: the vendor bills the owner's plan (Cursor), no request reaches us, so
|
|
2
3
|
* the adapter itself stops the run at these limits. `proxy`: the agent's model goes through the host's proxy, which the
|
|
3
4
|
* adapter's `proxy` option starts for each agent process (Goose, S3). */
|
|
@@ -20,6 +21,26 @@ export declare const MODEL_ID: RegExp;
|
|
|
20
21
|
/** A sign-in method's id as an agent lists one in authMethods (`gemini-api-key`): the one definition, a serve recipe's
|
|
21
22
|
* keyMethod included. */
|
|
22
23
|
export declare const AUTH_METHOD: RegExp;
|
|
24
|
+
/** The forms an allowFile is written in, by the agent that reads it: each makes the file's text from the names of the
|
|
25
|
+
* tools a start lists. A second agent with another format adds a form here. */
|
|
26
|
+
declare const ALLOW_FORMS: {
|
|
27
|
+
/** Goose 1.59.2's permission file (PermissionConfig under `user`, every field present: none has a default, and a
|
|
28
|
+
* file that does not parse stops Goose at its start): each tool always allowed by the name Goose calls it,
|
|
29
|
+
* `agentrun__<tool>`, nothing asked before or never allowed. Written as JSON, which YAML reads. Goose's own tools are
|
|
30
|
+
* not named, so they still ask. */
|
|
31
|
+
"goose-permission": (tools: readonly string[]) => string;
|
|
32
|
+
};
|
|
33
|
+
/** The forms an allowFile may take, by name: a recipe loader's check (serve's) reads them from here. */
|
|
34
|
+
export declare const ALLOW_FILE_FORMS: readonly string[];
|
|
35
|
+
/** The form of a recipe's allowFile. */
|
|
36
|
+
export type AcpAllowForm = keyof typeof ALLOW_FORMS;
|
|
37
|
+
/** A recipe's allowFile: where in HOME the agent reads which tools run unasked, and in what form. */
|
|
38
|
+
export type AcpAllowFile = {
|
|
39
|
+
readonly path: string;
|
|
40
|
+
readonly form: AcpAllowForm;
|
|
41
|
+
};
|
|
42
|
+
/** The text of an allowFile in `form` for a start whose MCP server lists `tools`. */
|
|
43
|
+
export declare function allowFileText(form: AcpAllowForm, tools: readonly string[]): string;
|
|
23
44
|
export interface AcpRecipe {
|
|
24
45
|
/** The harness's id: the adapter's. */
|
|
25
46
|
readonly id: string;
|
|
@@ -66,6 +87,16 @@ export interface AcpRecipe {
|
|
|
66
87
|
readonly model?: string;
|
|
67
88
|
/** Files written into its private HOME before it starts, by their path in HOME (`.config/goose/config.yaml`). */
|
|
68
89
|
readonly files?: Readonly<Record<string, string>>;
|
|
90
|
+
/** A file in HOME, written at each start from the tools that start's MCP server lists, that tells the agent to run
|
|
91
|
+
* them without asking permission (Goose's `.config/goose/permission.yaml`, form `goose-permission`): our tools'
|
|
92
|
+
* gate is the host's, at the MCP call. Nothing else is in it, so the agent's own tools still ask. */
|
|
93
|
+
readonly allowFile?: AcpAllowFile;
|
|
94
|
+
/** Where the agent's tool_call names which tool it calls (AcpAnnounces): Goose 1.59.2's
|
|
95
|
+
* `{ tool: "_meta.goose.toolCall.toolName" }`, Cursor 2026.11.13's
|
|
96
|
+
* `{ tool: "rawInput.toolName", server: "rawInput.providerIdentifier", args: "rawInput.args" }`. A call it names as
|
|
97
|
+
* another tool is the agent's own; one it names as ours is matched to the MCP call by that tool and its arguments.
|
|
98
|
+
* Absent: every call is matched by its arguments alone. A title is never read for this. */
|
|
99
|
+
readonly announces?: AcpAnnounces;
|
|
69
100
|
/** Where in HOME the agent keeps its own sessions: mirrored into the session's records, so another runner's agent
|
|
70
101
|
* loads them (session/load). Credential files under them are never mirrored. */
|
|
71
102
|
readonly state?: readonly string[];
|
|
@@ -80,11 +111,21 @@ export interface AcpRecipe {
|
|
|
80
111
|
/** How an MCP call finds its id. `match` (default): the agent's own tool_call for it, by tool and arguments; `mint`:
|
|
81
112
|
* an id of the adapter's, for an agent that announces no tool_call for an MCP call. */
|
|
82
113
|
readonly mcpCall?: "match" | "mint";
|
|
114
|
+
/** `title`: a permission request whose title names one of our tools (ourTool), for a call the agent announced as
|
|
115
|
+
* that tool, is answered allow_once without the host's gate, which the bridge asks at the MCP call. For an agent
|
|
116
|
+
* that asks for every MCP call whatever its config says (Cursor 2026.11.13: its allowlist with allow: [], which keeps
|
|
117
|
+
* it from writing files unasked, asks for each). Absent: every permission request goes to the host's gate. */
|
|
118
|
+
readonly permissionTie?: "title";
|
|
83
119
|
};
|
|
84
120
|
}
|
|
85
121
|
/** `path` in HOME, normalized, or undefined when it leaves HOME (absolute, `..`, or a `$HOME/` prefix spelled out). */
|
|
86
122
|
export declare function homePath(path: string): string | undefined;
|
|
123
|
+
/** What is wrong with a recipe's `announces` field, and with a title tie (quirks.permissionTie) without it, each in
|
|
124
|
+
* words; none when both may run. The one rule for both loaders: recipeProblems here, and serve's, which reads it from
|
|
125
|
+
* this package. */
|
|
126
|
+
export declare function announcesProblems(announces: unknown, permissionTie: unknown): string[];
|
|
87
127
|
/** What is wrong with `recipe`, each in words; none when it may run. */
|
|
88
128
|
export declare function recipeProblems(recipe: AcpRecipe): string[];
|
|
89
129
|
/** The variables the adapter sets itself: a recipe never names them. */
|
|
90
130
|
export declare const RESERVED_ENV: Set<string>;
|
|
131
|
+
export {};
|
package/dist/recipe.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// these are the checks the adapter itself needs before it starts anything. Written for AgentRun.
|
|
4
4
|
import { isAbsolute, normalize, sep } from "node:path";
|
|
5
5
|
import { KEY_NAME, launchEnv } from "@parcha/agentrun-kernel";
|
|
6
|
+
import { ANNOUNCES_EXTRA, ANNOUNCES_PATH, ANNOUNCES_PREFIX, MCP_SERVER } from "./calls.js";
|
|
6
7
|
/** A model id as an agent lists one (`gpt-5.4-nano[reasoning=medium]`): one line, no spaces, not an option. */
|
|
7
8
|
export const MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:/=,[\]-]{0,199}$/;
|
|
8
9
|
/** A refusal's code: capitals, digits and `_`. */
|
|
@@ -10,6 +11,21 @@ const CODE = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
|
10
11
|
/** A sign-in method's id as an agent lists one in authMethods (`gemini-api-key`): the one definition, a serve recipe's
|
|
11
12
|
* keyMethod included. */
|
|
12
13
|
export const AUTH_METHOD = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
14
|
+
/** The forms an allowFile is written in, by the agent that reads it: each makes the file's text from the names of the
|
|
15
|
+
* tools a start lists. A second agent with another format adds a form here. */
|
|
16
|
+
const ALLOW_FORMS = {
|
|
17
|
+
/** Goose 1.59.2's permission file (PermissionConfig under `user`, every field present: none has a default, and a
|
|
18
|
+
* file that does not parse stops Goose at its start): each tool always allowed by the name Goose calls it,
|
|
19
|
+
* `agentrun__<tool>`, nothing asked before or never allowed. Written as JSON, which YAML reads. Goose's own tools are
|
|
20
|
+
* not named, so they still ask. */
|
|
21
|
+
"goose-permission": (tools) => `${JSON.stringify({ user: { always_allow: tools.map((tool) => `${MCP_SERVER}__${tool}`), ask_before: [], never_allow: [] } })}\n`,
|
|
22
|
+
};
|
|
23
|
+
/** The forms an allowFile may take, by name: a recipe loader's check (serve's) reads them from here. */
|
|
24
|
+
export const ALLOW_FILE_FORMS = Object.freeze(Object.keys(ALLOW_FORMS));
|
|
25
|
+
/** The text of an allowFile in `form` for a start whose MCP server lists `tools`. */
|
|
26
|
+
export function allowFileText(form, tools) {
|
|
27
|
+
return ALLOW_FORMS[form](tools);
|
|
28
|
+
}
|
|
13
29
|
/** `path` in HOME, normalized, or undefined when it leaves HOME (absolute, `..`, or a `$HOME/` prefix spelled out). */
|
|
14
30
|
export function homePath(path) {
|
|
15
31
|
const bare = path.startsWith("$HOME/") ? path.slice("$HOME/".length) : path;
|
|
@@ -20,6 +36,24 @@ export function homePath(path) {
|
|
|
20
36
|
return undefined;
|
|
21
37
|
return clean;
|
|
22
38
|
}
|
|
39
|
+
/** What is wrong with a recipe's `announces` field, and with a title tie (quirks.permissionTie) without it, each in
|
|
40
|
+
* words; none when both may run. The one rule for both loaders: recipeProblems here, and serve's, which reads it from
|
|
41
|
+
* this package. */
|
|
42
|
+
export function announcesProblems(announces, permissionTie) {
|
|
43
|
+
const problems = [];
|
|
44
|
+
if (announces !== undefined) {
|
|
45
|
+
const said = typeof announces === "object" && announces !== null && !Array.isArray(announces) ? announces : undefined;
|
|
46
|
+
const path = (value) => typeof value === "string" && ANNOUNCES_PATH.test(value);
|
|
47
|
+
const shaped = said !== undefined && Object.keys(said).every((key) => ["tool", "server", "prefix", "args", "extras"].includes(key));
|
|
48
|
+
const prefixed = said?.prefix === undefined || (said.server === undefined && typeof said.prefix === "string" && ANNOUNCES_PREFIX.test(said.prefix));
|
|
49
|
+
const extras = said?.extras === undefined || (Array.isArray(said.extras) && said.extras.length > 0 && said.extras.every((name) => typeof name === "string" && ANNOUNCES_EXTRA.test(name)));
|
|
50
|
+
if (!said || !shaped || !path(said.tool) || (said.server !== undefined && !path(said.server)) || (said.args !== undefined && !path(said.args)) || !prefixed || !extras)
|
|
51
|
+
problems.push('announces is { "tool": a dotted path into the agent\'s tool_call (`_meta.goose.toolCall.toolName`) that does not start at its title, toolCallId, kind, status, rawOutput, content, locations or sessionUpdate, "server"?: one, "prefix"?: our server\'s name as the agent writes it before a tool\'s (`mcp_agentrun_`; the default `agentrun__`, never with "server"), "args"?: one, "extras"?: field names beside the arguments, left out before they are matched }');
|
|
52
|
+
}
|
|
53
|
+
if (permissionTie === "title" && announces === undefined)
|
|
54
|
+
problems.push("the title tie (quirks.permissionTie) needs announces: it answers only a request for a call that field named");
|
|
55
|
+
return problems;
|
|
56
|
+
}
|
|
23
57
|
/** What is wrong with `recipe`, each in words; none when it may run. */
|
|
24
58
|
export function recipeProblems(recipe) {
|
|
25
59
|
const problems = [];
|
|
@@ -44,6 +78,20 @@ export function recipeProblems(recipe) {
|
|
|
44
78
|
for (const path of recipe.state ?? [])
|
|
45
79
|
if (!homePath(path))
|
|
46
80
|
problems.push(`the state path ${JSON.stringify(path)} must be inside the private HOME`);
|
|
81
|
+
if (recipe.allowFile !== undefined) {
|
|
82
|
+
const allow = recipe.allowFile;
|
|
83
|
+
const path = typeof allow?.path === "string" ? homePath(allow.path) : undefined;
|
|
84
|
+
if (!path)
|
|
85
|
+
problems.push(`the allowFile ${JSON.stringify(allow?.path ?? null)} must be a path inside the private HOME`);
|
|
86
|
+
if (typeof allow?.form !== "string" || !Object.hasOwn(ALLOW_FORMS, allow.form))
|
|
87
|
+
problems.push(`the allowFile form ${JSON.stringify(allow?.form ?? null)} is none of ${Object.keys(ALLOW_FORMS).join(", ")}`);
|
|
88
|
+
if (path && Object.keys(recipe.files ?? {}).some((file) => homePath(file) === path))
|
|
89
|
+
problems.push(`the allowFile ${JSON.stringify(allow.path)} is also one of the recipe's files`);
|
|
90
|
+
}
|
|
91
|
+
const quirks = recipe.quirks;
|
|
92
|
+
problems.push(...announcesProblems(recipe.announces, quirks?.permissionTie));
|
|
93
|
+
if (quirks?.permissionTie !== undefined && quirks.permissionTie !== "title")
|
|
94
|
+
problems.push(`the quirk permissionTie ${JSON.stringify(quirks.permissionTie)} is not "title"`);
|
|
47
95
|
const reserved = Object.keys(recipe.env ?? {}).filter((name) => RESERVED_ENV.has(name));
|
|
48
96
|
if (reserved.length)
|
|
49
97
|
problems.push(`the env names ${reserved.join(", ")}, which the adapter sets`);
|
package/dist/testing.d.ts
CHANGED
|
@@ -3,14 +3,18 @@ import type { AcpRecipe } from "./recipe.js";
|
|
|
3
3
|
export declare const FAKE_ACP_AGENT: string;
|
|
4
4
|
/** How the fake plays an agent: `load` it resumes with session/load (else a crash restarts the turn); `http` our tools
|
|
5
5
|
* reach it over HTTP (else stdio); `style` how it names our tools and what it asks permission for ("goose": every tool
|
|
6
|
-
* asks; "cursor": MCP and shell calls ask, edits do not); `askMcp` whether an MCP call asks first (default: the
|
|
6
|
+
* asks; "cursor": MCP and shell calls ask, edits do not; "antigravity": agy's names, every tool asks); `askMcp` whether an MCP call asks first (default: the
|
|
7
7
|
* style's). */
|
|
8
8
|
export interface FakeAgentPlay {
|
|
9
9
|
readonly load?: boolean;
|
|
10
10
|
readonly http?: boolean;
|
|
11
|
-
readonly style?: "goose" | "cursor";
|
|
11
|
+
readonly style?: "goose" | "cursor" | "antigravity";
|
|
12
12
|
readonly askMcp?: boolean;
|
|
13
13
|
}
|
|
14
14
|
/** The fake agent as the recipe of harness `id`, its config written into `dir`, driven by `script` (the conformance
|
|
15
|
-
* suite's ScriptStep list). Billed `plan`: the fake calls no model, so no proxy is started.
|
|
15
|
+
* suite's ScriptStep list). Billed `plan`: the fake calls no model, so no proxy is started. Our tools' permission
|
|
16
|
+
* requests are answered as each style's shipped recipe answers them: "goose" writes Goose's permission file
|
|
17
|
+
* (allowFile), so the fake asks nothing for our tools; "cursor" and "antigravity" declare the title tie
|
|
18
|
+
* (quirks.permissionTie), as the Antigravity example recipe does. Each
|
|
19
|
+
* names its calls by the field its shipped recipe declares (announces). */
|
|
16
20
|
export declare function fakeAgentRecipe(id: string, dir: string, script: readonly unknown[], play?: FakeAgentPlay): AcpRecipe;
|
package/dist/testing.js
CHANGED
|
@@ -8,7 +8,11 @@ import { fileURLToPath } from "node:url";
|
|
|
8
8
|
/** The fake agent's file: `node FAKE_ACP_AGENT <config.json>` starts it (its header says what the config holds). */
|
|
9
9
|
export const FAKE_ACP_AGENT = fileURLToPath(new URL("../testing/fake-acp-agent.mjs", import.meta.url));
|
|
10
10
|
/** The fake agent as the recipe of harness `id`, its config written into `dir`, driven by `script` (the conformance
|
|
11
|
-
* suite's ScriptStep list). Billed `plan`: the fake calls no model, so no proxy is started.
|
|
11
|
+
* suite's ScriptStep list). Billed `plan`: the fake calls no model, so no proxy is started. Our tools' permission
|
|
12
|
+
* requests are answered as each style's shipped recipe answers them: "goose" writes Goose's permission file
|
|
13
|
+
* (allowFile), so the fake asks nothing for our tools; "cursor" and "antigravity" declare the title tie
|
|
14
|
+
* (quirks.permissionTie), as the Antigravity example recipe does. Each
|
|
15
|
+
* names its calls by the field its shipped recipe declares (announces). */
|
|
12
16
|
export function fakeAgentRecipe(id, dir, script, play = {}) {
|
|
13
17
|
const load = play.load ?? true;
|
|
14
18
|
const http = play.http ?? true;
|
|
@@ -22,5 +26,10 @@ export function fakeAgentRecipe(id, dir, script, play = {}) {
|
|
|
22
26
|
state: [".fake-acp"],
|
|
23
27
|
declares: { load, mcp: http ? "http" : "stdio" },
|
|
24
28
|
billing: { kind: "plan", maxTurns: 100, maxToolCalls: 100 },
|
|
29
|
+
...((play.style ?? "goose") === "cursor"
|
|
30
|
+
? { announces: { tool: "rawInput.toolName", server: "rawInput.providerIdentifier", args: "rawInput.args" }, quirks: { permissionTie: "title" } }
|
|
31
|
+
: play.style === "antigravity"
|
|
32
|
+
? { announces: { tool: "name", prefix: "mcp_agentrun_", extras: ["toolSummary"] }, quirks: { permissionTie: "title" } }
|
|
33
|
+
: { announces: { tool: "_meta.goose.toolCall.toolName" }, allowFile: { path: ".config/goose/permission.yaml", form: "goose-permission" } }),
|
|
25
34
|
};
|
|
26
35
|
}
|
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.59",
|
|
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.59",
|
|
53
53
|
"zod": "4.6.6"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
package/recipes/cursor.json
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"quiet": ["couldn't save your credentials", "EISDIR: illegal operation on a directory, open"],
|
|
19
|
+
"announces": { "tool": "rawInput.toolName", "server": "rawInput.providerIdentifier", "args": "rawInput.args" },
|
|
19
20
|
"declares": { "load": true, "mcp": "http" },
|
|
20
|
-
"billing": { "kind": "plan", "maxTurns": 20, "maxToolCalls": 100 }
|
|
21
|
+
"billing": { "kind": "plan", "maxTurns": 20, "maxToolCalls": 100 },
|
|
22
|
+
"quirks": { "permissionTie": "title" }
|
|
21
23
|
}
|
package/recipes/goose.json
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"files": {
|
|
18
18
|
".config/goose/config.yaml": "extensions:\n developer: {enabled: false, type: builtin, name: developer, bundled: true, timeout: 300}\n analyze: {enabled: false, type: builtin, name: analyze, bundled: true, timeout: 300}\n apps: {enabled: false, type: platform, name: apps, bundled: true}\n extensionmanager: {enabled: false, type: platform, name: extensionmanager, bundled: true}\n skills: {enabled: false, type: platform, name: skills, bundled: true}\n summon: {enabled: false, type: platform, name: summon, bundled: true}\n todo: {enabled: false, type: platform, name: todo, bundled: true}\n chatrecall: {enabled: false, type: platform, name: chatrecall, bundled: true}\n"
|
|
19
19
|
},
|
|
20
|
+
"allowFile": { "path": ".config/goose/permission.yaml", "form": "goose-permission" },
|
|
20
21
|
"state": [".local/share/goose/sessions"],
|
|
22
|
+
"announces": { "tool": "_meta.goose.toolCall.toolName" },
|
|
21
23
|
"declares": { "load": true, "mcp": "http" },
|
|
22
24
|
"billing": { "kind": "proxy" }
|
|
23
25
|
}
|
|
@@ -9,18 +9,30 @@
|
|
|
9
9
|
// style: "goose" (titles agentrun__<tool>, every tool asks permission, allow_always offered first) or "cursor"
|
|
10
10
|
// (titles agentrun-<tool>: <tool>; MCP and execute ask, edits do not; a refused native call still reports
|
|
11
11
|
// completed), or "goose-1.59" (as "goose", but titled as Goose 1.59.2 titles a call of an extension's tool:
|
|
12
|
-
// `agentrun: <tool, its underscores as spaces>`)
|
|
12
|
+
// `agentrun: <tool, its underscores as spaces>`), or "antigravity" (an MCP call as agy 1.5.14 announces and asks
|
|
13
|
+
// about it: named `mcp_agentrun_<tool>`, titled `Run mcp_agentrun_<tool>`, its rawInput the call's arguments
|
|
14
|
+
// with agy's own `toolSummary` beside them, which the MCP call itself never carries; options Allow and Deny);
|
|
13
15
|
// titleSummary: with style "goose-1.59", the summary Goose 1.59.2 writes after such a title for a call whose
|
|
14
16
|
// arguments it summarizes (a path): `agentrun: <tool> · <titleSummary>`;
|
|
17
|
+
// (styles "goose" and "goose-1.59" read $HOME/.config/goose/permission.yaml at start, as Goose 1.59.2's permission
|
|
18
|
+
// manager does, here as JSON: a call of a tool its `user.always_allow` names, `agentrun__<tool>`, is never asked about;)
|
|
15
19
|
// askMcp: ask permission before an MCP call (default: by style); askNative: the native kinds that ask;
|
|
16
20
|
// nativeLog: a file each native call that runs appends its title to;
|
|
17
21
|
// countFile: a file each event (new, load, prompt, cancel, mcp, permission) is appended to, one JSON line;
|
|
18
22
|
// systemPrompt: advertise sessionCapabilities.systemPrompt;
|
|
19
23
|
// ignoreCancel: log session/cancel and go on as if it never came (an agent that keeps spending);
|
|
20
24
|
// keepMcpOnCancel: on session/cancel, answer the prompt `cancelled` at once and leave an MCP call in flight open;
|
|
21
|
-
// announce:
|
|
22
|
-
// "MCP: tool" with no input, then a tool_call_update titled `agentrun: <tool>` whose rawInput is
|
|
23
|
-
// {providerIdentifier, toolName, args}; its permission request is titled `agentrun-<tool>: <tool
|
|
25
|
+
// announce: with style "cursor", "late" (the default): an MCP call as Cursor 2026.11.13 announces it, a tool_call
|
|
26
|
+
// titled "MCP: tool" with no input, then a tool_call_update titled `agentrun: <tool>` whose rawInput is
|
|
27
|
+
// {providerIdentifier, toolName, args}; its permission request is titled `agentrun-<tool>: <tool>`.
|
|
28
|
+
// "early": one tool_call titled `agentrun-<tool>: <tool>` with the arguments as its rawInput, naming the
|
|
29
|
+
// tool in no field (no Cursor release measured sends this);
|
|
30
|
+
// lateTitle: with announce "late", that update's title instead (a release that words it otherwise);
|
|
31
|
+
// (a call step's `ask`, {kind, title}: what its permission request says instead of the call's own kind and title;)
|
|
32
|
+
// (a native step's `lateInput`: a tool_call_update after its tool_call with that rawInput, a release that echoes the
|
|
33
|
+
// model's arguments in a later update;)
|
|
34
|
+
// (styles "goose" and "goose-1.59": each tool_call names its tool in _meta.goose.toolCall.toolName, as Goose 1.59.2
|
|
35
|
+
// does: `agentrun__<tool>` for ours, a native step's `toolName` or `developer__<kind>` for the agent's own;)
|
|
24
36
|
// models: the models session/new and session/load list ({modelId, name}), the first current; session/set_model
|
|
25
37
|
// takes one of them and refuses any other;
|
|
26
38
|
// writeAuth: at session/new and session/load, write $HOME/.config/cursor/auth.json holding the sha256 of the
|
|
@@ -47,7 +59,8 @@
|
|
|
47
59
|
// grow: {bytes}: at each save of a session, append `bytes` random bytes to <sessions>/store.db-wal and rewrite a
|
|
48
60
|
// store.db-shm beside it: a store that grows each turn, as Cursor's SQLite WAL does.
|
|
49
61
|
// holdInit: a file; while it exists, initialize is not answered, so the host can send this process nothing.
|
|
50
|
-
// A script step {hang: true} is a model that never answers (until a cancel the agent heeds).
|
|
62
|
+
// A script step {hang: true} is a model that never answers (until a cancel the agent heeds). A step {lastWords, afterMs}
|
|
63
|
+
// closes the agent's stdout, says `lastWords` on stderr `afterMs` later (default 300), then exits 1.
|
|
51
64
|
// The step the model takes is the number it took before: its session's history (calls, native calls, answers), plus the
|
|
52
65
|
// calls a recovery or context note names that its history does not hold, as a resumed model reads its conversation.
|
|
53
66
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -78,6 +91,16 @@ const deniesWrite = (() => {
|
|
|
78
91
|
}
|
|
79
92
|
})();
|
|
80
93
|
const EDITS = new Set(["edit", "delete", "move"]);
|
|
94
|
+
/** The tools Goose's permission file lets run unasked (styles goose and goose-1.59), by their exact names. */
|
|
95
|
+
const alwaysAllowed = (() => {
|
|
96
|
+
if (style === "cursor") return new Set();
|
|
97
|
+
try {
|
|
98
|
+
const allowed = JSON.parse(readFileSync(join(home, ".config", "goose", "permission.yaml"), "utf8"))?.user?.always_allow;
|
|
99
|
+
return new Set(Array.isArray(allowed) ? allowed : []);
|
|
100
|
+
} catch {
|
|
101
|
+
return new Set();
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
81
104
|
|
|
82
105
|
const said = (event) => config.countFile && appendFileSync(config.countFile, `${JSON.stringify({ at: Date.now(), pid: process.pid, ...event })}\n`);
|
|
83
106
|
const save = (session) => {
|
|
@@ -102,8 +125,12 @@ const pgid = (() => {
|
|
|
102
125
|
}
|
|
103
126
|
})();
|
|
104
127
|
said({ type: "start", env: Object.keys(process.env).sort(), home, cwd: process.cwd(), pgid, ...(config.cursorDirs ? { cursorDir, deniesWrite } : {}) });
|
|
105
|
-
const titleOf = (tool) => (style === "cursor" ? `agentrun-${tool}: ${tool}` : style === "goose-1.59" ? `agentrun: ${tool.replace(/_/g, " ")}${config.titleSummary ? ` · ${config.titleSummary}` : ""}` : `agentrun__${tool}`);
|
|
106
|
-
const late = style === "cursor" && config.announce
|
|
128
|
+
const titleOf = (tool) => (style === "cursor" ? `agentrun-${tool}: ${tool}` : style === "antigravity" ? `Run mcp_agentrun_${tool}` : style === "goose-1.59" ? `agentrun: ${tool.replace(/_/g, " ")}${config.titleSummary ? ` · ${config.titleSummary}` : ""}` : `agentrun__${tool}`);
|
|
129
|
+
const late = style === "cursor" && config.announce !== "early";
|
|
130
|
+
/** Goose's field naming a tool_call's tool, on its first tool_call only, in the shape goose-acp's goose_tool_call_meta
|
|
131
|
+
* builds (conversion.rs:65-91 at v1.59.2): `toolName` the name the model called, `extensionName` the part before `__`
|
|
132
|
+
* (left out when there is none). Its permission request carries no _meta. Cursor and agy send none. */
|
|
133
|
+
const gooseMeta = (toolName) => (style === "cursor" || style === "antigravity" ? {} : { _meta: { goose: { toolCall: { toolName, ...(toolName.includes("__") ? { extensionName: toolName.split("__")[0] } : {}) } } } });
|
|
107
134
|
const models = config.models ? { currentModelId: config.models[0].modelId, availableModels: config.models } : undefined;
|
|
108
135
|
/** The credential Cursor derives from its key, in its private HOME: here the key's sha256, never the key. */
|
|
109
136
|
function writeAuth() {
|
|
@@ -235,6 +262,8 @@ async function openSession(id, params, history) {
|
|
|
235
262
|
async function permitted(client, session, update) {
|
|
236
263
|
const options = style === "cursor"
|
|
237
264
|
? [{ optionId: "allow-once", name: "Allow once", kind: "allow_once" }, { optionId: "allow-always", name: "Always allow", kind: "allow_always" }, { optionId: "reject-once", name: "Reject", kind: "reject_once" }]
|
|
265
|
+
: style === "antigravity"
|
|
266
|
+
? [{ optionId: "allow", name: "Allow", kind: "allow_once" }, { optionId: "deny", name: "Deny", kind: "reject_once" }]
|
|
238
267
|
: [{ optionId: "allow_always", name: "Always Allow", kind: "allow_always" }, { optionId: "allow_once", name: "Allow Once", kind: "allow_once" }, { optionId: "reject_once", name: "Deny Once", kind: "reject_once" }, { optionId: "reject_always", name: "Always Deny", kind: "reject_always" }];
|
|
239
268
|
const answer = await client.request("session/request_permission", { sessionId: session.id, toolCall: update, options });
|
|
240
269
|
const chosen = answer.outcome.outcome === "selected" ? options.find((o) => o.optionId === answer.outcome.optionId) : undefined;
|
|
@@ -261,17 +290,19 @@ async function takeTurn(client, session, prompt, signal) {
|
|
|
261
290
|
if ("call" in s) {
|
|
262
291
|
const id = `call_${step - 1}`;
|
|
263
292
|
const args = s.args ?? {};
|
|
264
|
-
const update =
|
|
293
|
+
const update = style === "antigravity"
|
|
294
|
+
? { toolCallId: id, name: `mcp_agentrun_${s.call}`, title: titleOf(s.call), kind: "other", status: "pending", rawInput: { ...args, toolSummary: `Call ${s.call}` }, args: { ...args, toolSummary: `Call ${s.call}` } }
|
|
295
|
+
: { toolCallId: id, title: titleOf(s.call), kind: "other", status: "pending", rawInput: args };
|
|
265
296
|
const entry = { kind: "call", id, tool: s.call, args, status: "pending" };
|
|
266
297
|
session.history.push(entry);
|
|
267
298
|
save(session);
|
|
268
299
|
if (late) {
|
|
269
300
|
// Cursor 2026.11.13: the call is announced with no name, then named by an update, then asked about by its own title.
|
|
270
301
|
await notify({ sessionUpdate: "tool_call", toolCallId: id, title: "MCP: tool", kind: "other", status: "pending", rawInput: {} });
|
|
271
|
-
await notify({ sessionUpdate: "tool_call_update", toolCallId: id, title: `agentrun: ${s.call}`, rawInput: { providerIdentifier: "agentrun", toolName: s.call, args } });
|
|
302
|
+
await notify({ sessionUpdate: "tool_call_update", toolCallId: id, title: config.lateTitle ?? `agentrun: ${s.call}`, rawInput: { providerIdentifier: "agentrun", toolName: s.call, args } });
|
|
272
303
|
await notify({ sessionUpdate: "tool_call_update", toolCallId: id, status: "in_progress" });
|
|
273
|
-
} else await notify({ sessionUpdate: "tool_call", ...update });
|
|
274
|
-
if (askMcp && !(await permitted(client, session, late ? { toolCallId: id, title: titleOf(s.call), kind: "other", status: "pending" } : update))) {
|
|
304
|
+
} else await notify({ sessionUpdate: "tool_call", ...update, ...gooseMeta(`agentrun__${s.call}`) });
|
|
305
|
+
if (askMcp && !alwaysAllowed.has(`agentrun__${s.call}`) && !(await permitted(client, session, { ...(late ? { toolCallId: id, title: titleOf(s.call), kind: "other", status: "pending" } : update), ...(s.ask ?? {}) }))) {
|
|
275
306
|
if (signal.aborted) return { stopReason: "cancelled" };
|
|
276
307
|
entry.status = "failed";
|
|
277
308
|
entry.result = "the client refused the call";
|
|
@@ -313,12 +344,13 @@ async function takeTurn(client, session, prompt, signal) {
|
|
|
313
344
|
// A model that, taking a step again (after a restart), writes another command for it (retitled).
|
|
314
345
|
const again = s.retitled?.length ? tally(step - 1) : 0;
|
|
315
346
|
const title = again > 0 ? s.retitled[Math.min(again, s.retitled.length) - 1] : (s.title ?? s.native);
|
|
316
|
-
const update = { toolCallId: id, title, kind: s.native, status: "pending", rawInput: again > 0 ? { ...(s.input ?? {}), command: title } : (s.input ?? {}) };
|
|
347
|
+
const update = { toolCallId: id, title, kind: s.native, status: "pending", rawInput: again > 0 ? { ...(s.input ?? {}), command: title } : (s.input ?? {}), ...(style === "antigravity" ? { name: s.toolName ?? s.native } : {}) };
|
|
317
348
|
const entry = { kind: "native", id, title: update.title, status: "pending" };
|
|
318
349
|
session.history.push(entry);
|
|
319
350
|
save(session);
|
|
320
351
|
// {announce: false}: a permission request for a call no tool_call announced.
|
|
321
|
-
if (s.announce !== false) await notify({ sessionUpdate: "tool_call", ...update });
|
|
352
|
+
if (s.announce !== false) await notify({ sessionUpdate: "tool_call", ...update, ...gooseMeta(s.toolName ?? `developer__${s.native}`) });
|
|
353
|
+
if (s.lateInput) await notify({ sessionUpdate: "tool_call_update", toolCallId: id, rawInput: s.lateInput });
|
|
322
354
|
const allowed = deniesWrite && EDITS.has(s.native) ? false : askNative.has(s.native) ? await permitted(client, session, update) : true;
|
|
323
355
|
if (signal.aborted) return { stopReason: "cancelled" };
|
|
324
356
|
if (allowed && config.nativeLog) appendFileSync(config.nativeLog, `${update.title}\n`);
|
|
@@ -335,6 +367,13 @@ async function takeTurn(client, session, prompt, signal) {
|
|
|
335
367
|
said({ type: "die" });
|
|
336
368
|
process.kill(process.pid, "SIGKILL");
|
|
337
369
|
}
|
|
370
|
+
if ("lastWords" in s) {
|
|
371
|
+
// Its stdout closed first, its last words on stderr `afterMs` later, then exit 1: an agent whose connection ends
|
|
372
|
+
// before its stderr does, as a dying process's pipes can be read in either order.
|
|
373
|
+
said({ type: "lastWords" });
|
|
374
|
+
process.stdout.end(() => setTimeout(() => process.stderr.write(`${s.lastWords}\n`, () => process.exit(1)), s.afterMs ?? 300));
|
|
375
|
+
await new Promise(() => {});
|
|
376
|
+
}
|
|
338
377
|
if ("hang" in s) {
|
|
339
378
|
said({ type: "hang" });
|
|
340
379
|
await new Promise((resolve) => (signal.aborted ? resolve() : signal.addEventListener("abort", resolve, { once: true })));
|