@parcha/agentrun-harness-acp 0.1.0-beta.63 → 0.1.0-beta.65
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 +19 -0
- package/README.md +8 -0
- package/dist/adapter.d.ts +2 -0
- package/dist/adapter.js +1 -1
- package/dist/calls.d.ts +63 -17
- package/dist/calls.js +92 -18
- package/dist/cursor-facts.js +6 -2
- package/dist/goose-facts.js +8 -4
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +78 -18
- package/dist/host/goose-proxy.d.ts +5 -2
- package/dist/host/goose-proxy.js +5 -4
- package/dist/host/mcp.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/recipe.d.ts +17 -5
- package/dist/recipe.js +22 -6
- package/dist/server-name.d.ts +33 -0
- package/dist/server-name.js +94 -0
- package/package.json +2 -2
- package/recipes/cursor.json +1 -0
- package/testing/fake-acp-agent.mjs +32 -20
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.65 (2026-11-27)
|
|
6
|
+
|
|
7
|
+
- Under a recipe that names AgentRun's MCP server per start (`ar` and 6 random hex digits: Cursor's, Antigravity's, any with the title tie), a recipe that lists the MCP configs its agent reads (`mcpConfigs`, new) now has a run keep the name its first start minted and give it again at each later start. Before, a resumed Cursor run asked the host's gate for every call of AgentRun's own tools: Cursor keeps, with its session, the name it was first given and titled the call under it, which the new start no longer spelled, so the title tie read it as another server's. `mcpConfigs` lists the MCP config files the agent reads (`~/path` or `$HOME/path` in its HOME, any other path in its work directory; Cursor's: `~/.cursor/mcp.json` and `.cursor/mcp.json`). A recipe that lists none (Antigravity's) still names the server afresh at each start. One that declares a server under the run's name has that name refused at the start: AgentRun's server gets a fresh name, kept from then on, the run gets a notice naming the file, and a call titled under the old name goes to the host's gate as that server's. A config that is no regular file, too large to read (over 1 MiB) or fails to read, or one that does not parse as JSON but names the run's server or holds a `\u` escape, counts as declaring it. The file is never edited. A run that began before this change keeps no name yet: its first start after it mints one, and a resumed Cursor session's calls under the old name ask the gate for the rest of that session. Owner recipes in serve take `mcpConfigs` too. Recipes on the fixed `agentrun` name (Goose's) are unchanged. <!-- changes/acp-run-server-name.md -->
|
|
8
|
+
|
|
9
|
+
A proxy-billed recipe with the title tie (which takes Goose's facts) now finds its tools in meta `tools_call` under the run's own server name (`ar3f12ab__look_up`); before, only `agentrun__` names were read as AgentRun's.
|
|
10
|
+
|
|
11
|
+
## 0.1.0-beta.64 (2026-11-26)
|
|
12
|
+
|
|
13
|
+
- Under Cursor's recipe, AgentRun's MCP server now goes by a name of each start's own (`ar` and 6 random hex digits), as it already did under Antigravity's, and a call is AgentRun's only when its `providerIdentifier` says that name. Before, the server was named `agentrun`, so a second MCP server named exactly `agentrun` (in a workspace's `.cursor/mcp.json`, or the owner's own Cursor configuration) with a tool named like one of AgentRun's had its call read as AgentRun's: its permission request was answered `allow_once` on the title tie without the host's gate. Such a call is now the agent's own, and the host's gate decides it. A recipe whose `announces` reads the server from a field (`server`) gets the same. Goose's server keeps the name `agentrun`: its configuration is written whole at each start, and its proxy offers its model AgentRun's tools alone. <!-- changes/acp-cursor-own-server-name.md -->
|
|
14
|
+
- Under any recipe that declares the title tie (`quirks.permissionTie`), AgentRun's MCP server now goes by a name of each start's own (`ar` and 6 random hex digits), with the default `agentrun__` prefix, Goose's permission file and the proxy's tool policy (a proxy-billed recipe) reading that name. Before, a recipe of the owner's own with the tie and the default prefix kept `agentrun`, so a second MCP server named exactly `agentrun` with a tool named like one of AgentRun's had its call answered `allow_once` on the tie without the host's gate, or, with Goose's permission file, run unasked. The host gate's question about a call the recipe's server field (Cursor's `providerIdentifier`) names as another server's now carries that server's name (`server`), so a call titled `agentrun-look_up: look_up` can be told from AgentRun's own. Cursor's tool names in events and meta tools now read the start's own server name, not `agentrun`. <!-- changes/acp-tie-own-server-name.md -->
|
|
15
|
+
- On Goose and Cursor, a permission request for a tool the agent is not given is now refused at once, and the run goes on. Before, the request went to the host's gate like any other, and since there is no grant for a person to approve, the run parked (`parked`, with no summary) on a question nobody could answer usefully. Now the ACP adapter answers it `reject_once` without asking the gate or journaling it, and the run's timeline gets a line saying `tool "<name>" isn't granted to this agent`. ACP's permission answer carries no words, so the agent reads its own vendor's refusal; the line is for the person. A run that parked on such a request before this change is answered the same way when it resumes: the waiting request gets a settled deny in those words, the agent's recovery note says it was refused with no person asked, and the gate is not asked. Under Cursor's and agy's recipes, which give our server a new name at each start, the waiting request's title is read against the name of the start that asked, which the adapter now records with it; a request recorded without that name still goes to the gate, since its title cannot be tied to a server of ours. An agent that calls such a tool without asking now gets those same words from the adapter's MCP server, which said `unknown tool: <name>` before. A tool the agent is given whose setting asks (a write behind the gate) still asks a person and parks as before, and a native call with effects of its own (a shell, an edit) still goes to the gate whatever its title says. claude-agent, codex and pi never asked about such a tool: their tool bridge answers a call of a tool it does not hold `unknown tool: <name>` before the gate. serve's computer claim drops its `refuseKind` hook, which nothing called once every CLI harness got the browser. <!-- changes/acp-ungranted-tool-refused.md -->
|
|
16
|
+
- pi's turn budget now outlasts a process that stops in the turn, as Claude's, Codex's, ACP's and OpenCode's do: a pi session opened again takes the turn back from its conversation (its last answer's usage and calls, and each result handed since) before a call claims, so the calls a resume answers split what their answer left instead of each taking its whole bound. A read of the turn that fails runs no call: the call is an error naming why, and the next call reads again. <!-- changes/turn-budget-resume-pi-scripts.md -->
|
|
17
|
+
- A result goes back to the harness only once its length is in the session's journal (`TurnBudget.kept`): a process that stops right after it was handed no longer loses its part of the turn, which a resumed call would claim again. A length the journal could not keep fails the call instead of handing its result.
|
|
18
|
+
- A result settles at the length it was handed: a result of at most 400 characters, whole under any bound, and a refusal's words now hold what they took, so the calls after them split only what is left.
|
|
19
|
+
- A code-mode script's JSON read too large for its bound is handed as a note alone (`[read cut: this result is M characters of JSON, past the N ...]`), since part of a JSON document does not parse: on a 16k-32k window, a script that parses it fails naming the cut instead of on a character in the middle, and the model reads that it should ask for less. A read that is not JSON keeps its start and its note, as before.
|
|
20
|
+
- A failed call's error refused for a window too small to cut it in keeps its first line (as much as fits beside the note in the 400 characters a result always keeps whole), so the model reads what went wrong.
|
|
21
|
+
- A raise that reaches an agentic run's claim while that claim takes a retry of the raise that resumed the run (a raise covering the run's next park, during the retry's commit) waits for the run's next claim too, as one reaching a claim parking the run again does. Before, the claim could take it and park, the run left with nothing to wake it.
|
|
22
|
+
- The run's view shows the cap park a run stands at as its runner reads it: a raise entry clears only the park it names. A raise that names none (checked against the run while it worked) no longer hides a park journaled before it.
|
|
23
|
+
|
|
5
24
|
## 0.1.0-beta.63 (2026-11-26)
|
|
6
25
|
|
|
7
26
|
- Cursor is now told at each session's start that its own Write tool is refused, so it writes a file with a shell command (which asks the person first) and never stops at that refusal without an answer; a shell command the person denies is their answer, not asked again. An ACP recipe can carry `instructions`, given to the agent after the session's own, by the same route. A conversation begun before its recipe had them (or changed them) gets them once, ahead of its next prompt, when an agent with no system prompt loads it. They count as given only once a copy of the agent's history taken after it answered the prompt that carried them is kept, so a runner that stops before that gives them again on the next load; this covers a session's own instructions in its first prompt too. <!-- changes/cursor-write-through-shell.md -->
|
package/README.md
CHANGED
|
@@ -16,6 +16,14 @@ entries.
|
|
|
16
16
|
nothing: a recipe's `allowFile` (Goose's `.config/goose/permission.yaml`) lists them for the agent at each start, and
|
|
17
17
|
the gate asks at the MCP call. A recipe that declares `quirks.permissionTie: "title"` (Cursor's, whose allowlist asks
|
|
18
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
|
+
- A request for a tool of the host's MCP server that the agent is not given (one its start does not list, named in its
|
|
20
|
+
title or name as the agent names the host's tools) is answered `reject_once` at once: no gate, nothing journaled, so
|
|
21
|
+
nothing parks, and the run gets a notice, `tool "<name>" isn't granted to this agent`. ACP's answer carries no words,
|
|
22
|
+
so the agent reads its own refusal; the notice is for the person. Such a request a parked run left waiting is
|
|
23
|
+
refused the same way on the resume, settled, before the agent starts: its title is read against the server name of
|
|
24
|
+
the start that asked, recorded with it, since Cursor's and agy's recipes name the server per start. A native call of a kind with effects (a shell, an
|
|
25
|
+
edit) is the gate's whatever its title. An agent that calls such a tool without asking is answered by the MCP server
|
|
26
|
+
itself, in the same words.
|
|
19
27
|
- 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
28
|
from the field its recipe's `announces` declares (Goose's `_meta.goose.toolCall.toolName`, Cursor's `rawInput`, agy's `name`),
|
|
21
29
|
never from its title; a call that field names as another tool is the agent's own.
|
package/dist/adapter.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export interface AcpProxySession {
|
|
|
38
38
|
readonly models: ModelPort;
|
|
39
39
|
/** The host's tools, by the names the session has them under. */
|
|
40
40
|
readonly tools: readonly string[];
|
|
41
|
+
/** Our MCP server's name at this start (mcpServerName): the agent names each tool `<server>__<tool>`. */
|
|
42
|
+
readonly server?: string;
|
|
41
43
|
/** Ends the agent's drive: its turn ends failed in `reason`'s words. */
|
|
42
44
|
halt(reason: unknown): void;
|
|
43
45
|
/** The session's turn budget (ResultBudget.turn): a proxy opens it with each answer's facts (ModelProxyOptions.turn). */
|
package/dist/adapter.js
CHANGED
|
@@ -88,7 +88,7 @@ export function acpAdapter(options) {
|
|
|
88
88
|
...(options.confine ? { confine: options.confine } : {}),
|
|
89
89
|
...(options.parentWatch ? { parentWatch: options.parentWatch } : {}),
|
|
90
90
|
...(options.env ? { env: options.env } : {}),
|
|
91
|
-
...(options.proxy ? { proxy: (drive) => options.proxy({ models: io.models, tools: spec.tools.map((tool) => tool.name), halt: drive.halt, ...(turn ? { turn } : {}) }) } : {}),
|
|
91
|
+
...(options.proxy ? { proxy: (drive) => options.proxy({ models: io.models, tools: spec.tools.map((tool) => tool.name), server: drive.server, halt: drive.halt, ...(turn ? { turn } : {}) }) } : {}),
|
|
92
92
|
...(options.beforeStart ? { beforeStart: options.beforeStart } : {}),
|
|
93
93
|
...(options.callIdWaitMs !== undefined ? { callIdWaitMs: options.callIdWaitMs } : {}),
|
|
94
94
|
...(options.startMs !== undefined ? { startMs: options.startMs } : {}),
|
package/dist/calls.d.ts
CHANGED
|
@@ -1,32 +1,61 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Our MCP server's name, as the agent is given it under a recipe without the title tie (Goose's); under one with it,
|
|
2
|
+
* or whose announces could take another server's call as ours, the start's own name instead (mcpServerName). */
|
|
2
3
|
export declare const MCP_SERVER = "agentrun";
|
|
4
|
+
/** The pattern of a start's own name for our MCP server (mcpServerName): `ar` and 6 hex digits. */
|
|
5
|
+
export declare const START_SERVER = "ar[0-9a-f]{6}";
|
|
3
6
|
/** JSON text of `value` with every object's keys sorted: two argument objects that say the same are the same text. */
|
|
4
7
|
export declare function canonical(value: unknown): string;
|
|
5
8
|
/** 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
9
|
* our tools, whatever its title says. */
|
|
7
10
|
export declare const NATIVE_EFFECT_KINDS: ReadonlySet<string>;
|
|
8
|
-
/** The host tool a permission request's title or name gives, by a name for our MCP server's tools (
|
|
9
|
-
* Cursor's own title for one (
|
|
10
|
-
* (`
|
|
11
|
+
/** The host tool a permission request's title or name gives, by a name for our MCP server's tools (`<server>__<tool>`),
|
|
12
|
+
* Cursor's own title for one (`<server>-<tool>: <tool>`), or agy's (Antigravity's) name and title for one
|
|
13
|
+
* (`mcp_<server>_<tool>`, titled `Run mcp_<server>_<tool>`, the whole text), when it is one of `tools` and its kind is
|
|
11
14
|
* not one with effects of its own. Read for the title tie alone (quirks.permissionTie: Cursor's and agy's), and only
|
|
12
15
|
* 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
16
|
* recipe's announces field named as the same tool (CallIds.announced). Nothing else reads a title. `server` is the name
|
|
14
|
-
* our MCP server was given to the agent under at this start (mcpServerName)
|
|
17
|
+
* our MCP server was given to the agent under at this start (mcpServerName), which each of these forms carries: under
|
|
18
|
+
* the tie, the start's own. */
|
|
15
19
|
export declare function ourTool(update: {
|
|
16
20
|
title?: string | null;
|
|
17
21
|
name?: string | null;
|
|
18
22
|
kind?: string | null;
|
|
19
23
|
}, tools: ReadonlySet<string>, server?: string): string | undefined;
|
|
24
|
+
/** The tool of our MCP server a permission request names that `tools` does not hold, as the request names it: by any
|
|
25
|
+
* form ourTool reads, or Goose 1.59's title (`<server>: <tool, its underscores as spaces>`, a summary after ` · `), which
|
|
26
|
+
* is matched to a tool of `tools` with its underscores as spaces. Undefined when the request names no tool of our
|
|
27
|
+
* server, names one `tools` holds, or is of a kind with effects of its own (a native call, the gate's whatever its
|
|
28
|
+
* title). The agent could never call such a tool: our server does not list it, so the request is refused at once
|
|
29
|
+
* (harness.ts onPermission), never asked of a person. A title is the agent's text, so this only ever refuses. */
|
|
30
|
+
export declare function ungrantedTool(update: {
|
|
31
|
+
title?: string | null;
|
|
32
|
+
name?: string | null;
|
|
33
|
+
kind?: string | null;
|
|
34
|
+
}, tools: ReadonlySet<string>, server?: string): string | undefined;
|
|
20
35
|
/** Whether a recipe's announces names our server by a prefix that joins it to a tool's name with one `_` or `-` (agy's
|
|
21
36
|
* `mcp_agentrun_`): a join another server's own name may hold, so a server `agentrun_look` with a tool `up`
|
|
22
37
|
* (`mcp_agentrun_look_up`) would spell our `look_up`. Not Goose's default `agentrun__`, nor a recipe that reads the
|
|
23
38
|
* server from a field of its own (Cursor's). */
|
|
24
39
|
export declare function joinsByOne(announces: AcpAnnounces | undefined): boolean;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
/** Whether a recipe's announces read our server's name from a field of the agent's own (Cursor's
|
|
41
|
+
* `rawInput.providerIdentifier`): a second server named exactly `agentrun` (a workspace's or the owner's own MCP
|
|
42
|
+
* configuration) would say the same there. */
|
|
43
|
+
export declare function namesServer(announces: AcpAnnounces | undefined): boolean;
|
|
44
|
+
/** The name our MCP server is given to the agent under at one start: under a recipe that names it per start
|
|
45
|
+
* (namedPerStart), `ar` and 6 random hex digits, no `_` or `-`, which no server set up before it is minted can spell.
|
|
46
|
+
* Under a recipe that also lists the configs its agent reads (mcpConfigs), a run keeps its first start's and gives it
|
|
47
|
+
* again at each later one, unless one of them declares it by then (server-name.ts). It is not secret from the agent:
|
|
48
|
+
* its model reads it in its tool list. Under any other (Goose's `agentrun__`, no tie, whose configuration is all ours
|
|
49
|
+
* and whose proxy offers its model our tools alone), `agentrun`. As long as `agentrun`, no longer: each of our tools is
|
|
50
|
+
* named with it, under the agent's cap (TOOL_NAME_CAP), so a tool fits as it would under `agentrun`. */
|
|
51
|
+
export declare function mcpServerName(announces: AcpAnnounces | undefined, tie?: string): string;
|
|
52
|
+
/** Whether a recipe gives our MCP server a name of each start's own (mcpServerName): one that declares the title tie
|
|
53
|
+
* (`tie`, quirks.permissionTie: the tie answers a request for one of our tools' calls without the host's gate, so
|
|
54
|
+
* another server must never pass for ours), whose prefix joins by one character (joinsByOne) or that reads the
|
|
55
|
+
* server's name from a field (namesServer). A title an earlier start's agent wrote names the server that start was
|
|
56
|
+
* given, which this one's may not be: a run keeps one name only under a recipe that lists mcpConfigs, and even then a
|
|
57
|
+
* name a config declared is refused and minted afresh (server-name.ts). */
|
|
58
|
+
export declare function namedPerStart(announces: AcpAnnounces | undefined, tie?: string): boolean;
|
|
30
59
|
/** The most characters a tool's name may hold where the agent names it (agy's, as the model APIs' tool names: 64). */
|
|
31
60
|
export declare const TOOL_NAME_CAP = 64;
|
|
32
61
|
/** Of `tools`, those whose name as the agent names them at this start (`announces` as announcesAt reads them: its prefix
|
|
@@ -36,10 +65,14 @@ export declare function namesTooLong(announces: AcpAnnounces | undefined, tools:
|
|
|
36
65
|
/** The run's notice for the tools `label` (an agent naming ours `<prefix><tool>`) is not given at a start: those
|
|
37
66
|
* namesTooLong names, which it could never call. */
|
|
38
67
|
export declare function toolsLeftOut(label: string, prefix: string, tools: readonly string[]): string;
|
|
68
|
+
/** The run's notice for a permission request `label` (the agent) made for `tool`, a tool of our server it is not given
|
|
69
|
+
* (ungrantedTool): refused at once, no person asked. */
|
|
70
|
+
export declare function toolNotGranted(label: string, tool: string): string;
|
|
39
71
|
/** The recipe's `announces` as one start reads them, our MCP server given to the agent as `server` (mcpServerName): its
|
|
40
|
-
* prefix names that server (`mcp_agentrun_` reads `mcp_<server>_
|
|
72
|
+
* prefix names that server (`mcp_agentrun_` reads `mcp_<server>_`; no prefix, the default `agentrun__`, reads
|
|
73
|
+
* `<server>__`), and its `server` field must say that name (`named`). ANNOUNCES_PREFIX ends a prefix at our server's
|
|
41
74
|
* name, so the last `agentrun` in it is that name. */
|
|
42
|
-
export declare function announcesAt(announces: AcpAnnounces | undefined, server: string):
|
|
75
|
+
export declare function announcesAt(announces: AcpAnnounces | undefined, server: string): StartAnnounces | undefined;
|
|
43
76
|
/** Whether an input schema may name an argument `name`: in its `properties`, or in those of a schema it composes (allOf,
|
|
44
77
|
* anyOf, oneOf, at any depth), or behind a `$ref` to its own `$defs` or `definitions`. A `$ref` it cannot read (another
|
|
45
78
|
* document's, or a def it lacks) may, so it counts; a `$ref` that comes back to itself adds nothing. */
|
|
@@ -48,7 +81,8 @@ export declare function declaresProperty(schema: unknown, name: string): boolean
|
|
|
48
81
|
* path of field names into the update (`_meta.goose.toolCall.toolName`, `rawInput.toolName`, `name`).
|
|
49
82
|
* - `tool`: the tool's name. With `server`, our tool's own name; without, the name as the model calls it, our server's
|
|
50
83
|
* prefix and the tool's (`prefix`, stripped).
|
|
51
|
-
* - `server`: the MCP server's name, which must be ours (
|
|
84
|
+
* - `server`: the MCP server's name, which must be ours: the name of each start's own (mcpServerName), never
|
|
85
|
+
* `agentrun`, which a second server could be named too.
|
|
52
86
|
* - `prefix`: without `server`, what comes before our tool's name in `tool` (default `agentrun__`; agy's
|
|
53
87
|
* `mcp_agentrun_`). It names our server (ANNOUNCES_PREFIX), so a name without it is never ours. One that joins our
|
|
54
88
|
* server's name to the tool's with one `_` or `-` gives the server a name of each start's own (mcpServerName), which
|
|
@@ -64,6 +98,12 @@ export interface AcpAnnounces {
|
|
|
64
98
|
readonly args?: string;
|
|
65
99
|
readonly extras?: readonly string[];
|
|
66
100
|
}
|
|
101
|
+
/** A recipe's announces as one start reads them (announcesAt): with `named`, the name its `server` field must say, our
|
|
102
|
+
* server's at that start (mcpServerName); without, `agentrun`. Never a recipe's own field (announcesProblems refuses
|
|
103
|
+
* any key but those of AcpAnnounces). */
|
|
104
|
+
export type StartAnnounces = AcpAnnounces & {
|
|
105
|
+
readonly named?: string;
|
|
106
|
+
};
|
|
67
107
|
/** The prefix a recipe's announces.prefix may be: our server's name, with at most one word and a `_` or `-` before it,
|
|
68
108
|
* and one or two `_` or `-` after it (`agentrun__`, `mcp_agentrun_`). */
|
|
69
109
|
export declare const ANNOUNCES_PREFIX: RegExp;
|
|
@@ -82,7 +122,12 @@ export declare function announcedField(update: unknown, announces: AcpAnnounces
|
|
|
82
122
|
/** The tool of ours an agent's update names in the field its recipe declares (`announces`): its name; null when the
|
|
83
123
|
* field names a tool that is not ours (another server's, one without our prefix, or one of our server's that `tools`
|
|
84
124
|
* does not list); undefined when the recipe declares no field or the update does not carry it. A title is never read. */
|
|
85
|
-
export declare function announcedTool(update: unknown, announces:
|
|
125
|
+
export declare function announcedTool(update: unknown, announces: StartAnnounces | undefined, tools: ReadonlySet<string>): string | null | undefined;
|
|
126
|
+
/** The server an agent's update names its call under, in the field its recipe declares (`announces.server`: Cursor's
|
|
127
|
+
* rawInput.providerIdentifier), when it is not ours (`named`): clipped to ANNOUNCED_FIELD_CHARS, for the host gate's
|
|
128
|
+
* question about the call, so the person can tell it is another server's, whatever its title says. Undefined when the
|
|
129
|
+
* recipe declares no such field, the update does not carry a name in it, or it names ours. */
|
|
130
|
+
export declare function otherServer(update: unknown, announces: StartAnnounces | undefined): string | undefined;
|
|
86
131
|
/** An agent's update about one of its calls, as the adapter reads it. */
|
|
87
132
|
export interface AcpCallUpdate {
|
|
88
133
|
readonly toolCallId: string;
|
|
@@ -95,14 +140,14 @@ export interface AcpCallUpdate {
|
|
|
95
140
|
* one with no arguments on a recipe whose field names calls, which waits for the update that names it. On a recipe
|
|
96
141
|
* without the field, one reporting no input at all is kept as a call that names nothing (CallIds.add). `declared`: for
|
|
97
142
|
* each tool, the recipe's extras its input schema declares (declaresProperty), matched with and without (addAnnounced). */
|
|
98
|
-
export declare function announceCall(calls: CallIds, update: AcpCallUpdate, announces:
|
|
143
|
+
export declare function announceCall(calls: CallIds, update: AcpCallUpdate, announces: StartAnnounces | undefined, tools: ReadonlySet<string>, declared?: ReadonlyMap<string, ReadonlySet<string>>): void;
|
|
99
144
|
/** A tool_call_update naming a call its tool_call left unnamed with no input (Cursor's MCP calls: a tool_call titled
|
|
100
145
|
* "MCP: tool" with rawInput {}, then this update with rawInput {providerIdentifier, toolName, args}): kept as that
|
|
101
146
|
* tool, under the id its tool_call already counted, by the recipe's field. Only a call announceCall held for its name
|
|
102
147
|
* (CallIds.held): one whose tool_call reported input, or named a tool, is never named later, so a native read whose
|
|
103
148
|
* update echoes the model's arguments stays the agent's own. The tool_call's kind was checked before it was held;
|
|
104
149
|
* the update's is checked here: a shell renamed by a later update is never ours. */
|
|
105
|
-
export declare function nameCall(calls: CallIds, update: AcpCallUpdate, announces:
|
|
150
|
+
export declare function nameCall(calls: CallIds, update: AcpCallUpdate, announces: StartAnnounces | undefined, tools: ReadonlySet<string>, declared?: ReadonlyMap<string, ReadonlySet<string>>): void;
|
|
106
151
|
/** How long an MCP call that matches an announcement only without an extra (addAnnounced) holds for its own (take): an
|
|
107
152
|
* MCP call can reach MCP a little before the agent's announcement of it, and in that while the other's may be the only
|
|
108
153
|
* one there. */
|
|
@@ -136,7 +181,8 @@ export declare class CallIds {
|
|
|
136
181
|
* which it is kept too; the first MCP call either matches takes it, and it is gone from both. A call already waiting
|
|
137
182
|
* is handed it only where it is the call's own first key, its tool and its whole arguments. One that matches it only
|
|
138
183
|
* without the extra may be another call's, whose own announcement is on its way, and one naming no tool or reporting
|
|
139
|
-
* no input may come second to the call's own ended one,
|
|
184
|
+
* no input may come second to the call's own ended one, or to a live guess under its first key (an `also` form, its
|
|
185
|
+
* own MCP call maybe on its way), so for those the call tries again as take says (wake). */
|
|
140
186
|
add(id: string, tool: string | undefined, input: unknown, also?: unknown): void;
|
|
141
187
|
/** `id` out of every list it is kept in (keyOf), waiting for its MCP call no more. */
|
|
142
188
|
private unlist;
|
package/dist/calls.js
CHANGED
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
// and how many such requests came before it in the drive. Never from the agent's tool call id, which a new agent
|
|
13
13
|
// session (no load) mints afresh.
|
|
14
14
|
import { createHash, randomBytes } from "node:crypto";
|
|
15
|
-
/**
|
|
15
|
+
/** Our MCP server's name, as the agent is given it under a recipe without the title tie (Goose's); under one with it,
|
|
16
|
+
* or whose announces could take another server's call as ours, the start's own name instead (mcpServerName). */
|
|
16
17
|
export const MCP_SERVER = "agentrun";
|
|
18
|
+
/** The pattern of a start's own name for our MCP server (mcpServerName): `ar` and 6 hex digits. */
|
|
19
|
+
export const START_SERVER = "ar[0-9a-f]{6}";
|
|
17
20
|
const isPlain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
18
21
|
/** JSON text of `value` with every object's keys sorted: two argument objects that say the same are the same text. */
|
|
19
22
|
export function canonical(value) {
|
|
@@ -26,13 +29,14 @@ export function canonical(value) {
|
|
|
26
29
|
/** 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
|
|
27
30
|
* our tools, whatever its title says. */
|
|
28
31
|
export const NATIVE_EFFECT_KINDS = new Set(["execute", "edit", "delete", "move", "fetch"]);
|
|
29
|
-
/** The host tool a permission request's title or name gives, by a name for our MCP server's tools (
|
|
30
|
-
* Cursor's own title for one (
|
|
31
|
-
* (`
|
|
32
|
+
/** The host tool a permission request's title or name gives, by a name for our MCP server's tools (`<server>__<tool>`),
|
|
33
|
+
* Cursor's own title for one (`<server>-<tool>: <tool>`), or agy's (Antigravity's) name and title for one
|
|
34
|
+
* (`mcp_<server>_<tool>`, titled `Run mcp_<server>_<tool>`, the whole text), when it is one of `tools` and its kind is
|
|
32
35
|
* not one with effects of its own. Read for the title tie alone (quirks.permissionTie: Cursor's and agy's), and only
|
|
33
36
|
* 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
37
|
* recipe's announces field named as the same tool (CallIds.announced). Nothing else reads a title. `server` is the name
|
|
35
|
-
* our MCP server was given to the agent under at this start (mcpServerName)
|
|
38
|
+
* our MCP server was given to the agent under at this start (mcpServerName), which each of these forms carries: under
|
|
39
|
+
* the tie, the start's own. */
|
|
36
40
|
export function ourTool(update, tools, server = MCP_SERVER) {
|
|
37
41
|
if (typeof update.kind === "string" && NATIVE_EFFECT_KINDS.has(update.kind))
|
|
38
42
|
return undefined;
|
|
@@ -54,6 +58,36 @@ export function ourTool(update, tools, server = MCP_SERVER) {
|
|
|
54
58
|
}
|
|
55
59
|
return candidates.find((name) => tools.has(name));
|
|
56
60
|
}
|
|
61
|
+
/** The tool of our MCP server a permission request names that `tools` does not hold, as the request names it: by any
|
|
62
|
+
* form ourTool reads, or Goose 1.59's title (`<server>: <tool, its underscores as spaces>`, a summary after ` · `), which
|
|
63
|
+
* is matched to a tool of `tools` with its underscores as spaces. Undefined when the request names no tool of our
|
|
64
|
+
* server, names one `tools` holds, or is of a kind with effects of its own (a native call, the gate's whatever its
|
|
65
|
+
* title). The agent could never call such a tool: our server does not list it, so the request is refused at once
|
|
66
|
+
* (harness.ts onPermission), never asked of a person. A title is the agent's text, so this only ever refuses. */
|
|
67
|
+
export function ungrantedTool(update, tools, server = MCP_SERVER) {
|
|
68
|
+
if (typeof update.kind === "string" && NATIVE_EFFECT_KINDS.has(update.kind))
|
|
69
|
+
return undefined;
|
|
70
|
+
const named = [];
|
|
71
|
+
const spaced = [];
|
|
72
|
+
for (const said of [update.name, update.title]) {
|
|
73
|
+
if (typeof said !== "string")
|
|
74
|
+
continue;
|
|
75
|
+
for (const form of [new RegExp(`^${server}__(.+)$`), new RegExp(`^${server}-[^:]*: (.+)$`), new RegExp(`^(?:Run )?mcp_${server}_(.+)$`)]) {
|
|
76
|
+
const hit = form.exec(said);
|
|
77
|
+
if (hit)
|
|
78
|
+
named.push(hit[1].trim());
|
|
79
|
+
}
|
|
80
|
+
const goose = new RegExp(`^${server}: (.+?)(?: · .*)?$`).exec(said);
|
|
81
|
+
if (goose)
|
|
82
|
+
spaced.push(goose[1].trim());
|
|
83
|
+
}
|
|
84
|
+
if (named.some((name) => tools.has(name)))
|
|
85
|
+
return undefined;
|
|
86
|
+
const given = new Set([...tools].map((tool) => tool.replace(/_/g, " ")));
|
|
87
|
+
if (spaced.some((name) => given.has(name)))
|
|
88
|
+
return undefined;
|
|
89
|
+
return named[0] ?? spaced[0];
|
|
90
|
+
}
|
|
57
91
|
/** Whether a recipe's announces names our server by a prefix that joins it to a tool's name with one `_` or `-` (agy's
|
|
58
92
|
* `mcp_agentrun_`): a join another server's own name may hold, so a server `agentrun_look` with a tool `up`
|
|
59
93
|
* (`mcp_agentrun_look_up`) would spell our `look_up`. Not Goose's default `agentrun__`, nor a recipe that reads the
|
|
@@ -61,12 +95,30 @@ export function ourTool(update, tools, server = MCP_SERVER) {
|
|
|
61
95
|
export function joinsByOne(announces) {
|
|
62
96
|
return announces !== undefined && announces.server === undefined && announces.prefix !== undefined && new RegExp(`${MCP_SERVER}[_-]$`).test(announces.prefix);
|
|
63
97
|
}
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
/** Whether a recipe's announces read our server's name from a field of the agent's own (Cursor's
|
|
99
|
+
* `rawInput.providerIdentifier`): a second server named exactly `agentrun` (a workspace's or the owner's own MCP
|
|
100
|
+
* configuration) would say the same there. */
|
|
101
|
+
export function namesServer(announces) {
|
|
102
|
+
return announces?.server !== undefined;
|
|
103
|
+
}
|
|
104
|
+
/** The name our MCP server is given to the agent under at one start: under a recipe that names it per start
|
|
105
|
+
* (namedPerStart), `ar` and 6 random hex digits, no `_` or `-`, which no server set up before it is minted can spell.
|
|
106
|
+
* Under a recipe that also lists the configs its agent reads (mcpConfigs), a run keeps its first start's and gives it
|
|
107
|
+
* again at each later one, unless one of them declares it by then (server-name.ts). It is not secret from the agent:
|
|
108
|
+
* its model reads it in its tool list. Under any other (Goose's `agentrun__`, no tie, whose configuration is all ours
|
|
109
|
+
* and whose proxy offers its model our tools alone), `agentrun`. As long as `agentrun`, no longer: each of our tools is
|
|
110
|
+
* named with it, under the agent's cap (TOOL_NAME_CAP), so a tool fits as it would under `agentrun`. */
|
|
111
|
+
export function mcpServerName(announces, tie) {
|
|
112
|
+
return namedPerStart(announces, tie) ? `ar${randomBytes(3).toString("hex")}` : MCP_SERVER;
|
|
113
|
+
}
|
|
114
|
+
/** Whether a recipe gives our MCP server a name of each start's own (mcpServerName): one that declares the title tie
|
|
115
|
+
* (`tie`, quirks.permissionTie: the tie answers a request for one of our tools' calls without the host's gate, so
|
|
116
|
+
* another server must never pass for ours), whose prefix joins by one character (joinsByOne) or that reads the
|
|
117
|
+
* server's name from a field (namesServer). A title an earlier start's agent wrote names the server that start was
|
|
118
|
+
* given, which this one's may not be: a run keeps one name only under a recipe that lists mcpConfigs, and even then a
|
|
119
|
+
* name a config declared is refused and minted afresh (server-name.ts). */
|
|
120
|
+
export function namedPerStart(announces, tie) {
|
|
121
|
+
return tie === "title" || joinsByOne(announces) || namesServer(announces);
|
|
70
122
|
}
|
|
71
123
|
/** The most characters a tool's name may hold where the agent names it (agy's, as the model APIs' tool names: 64). */
|
|
72
124
|
export const TOOL_NAME_CAP = 64;
|
|
@@ -85,14 +137,23 @@ export function toolsLeftOut(label, prefix, tools) {
|
|
|
85
137
|
const one = tools.length === 1;
|
|
86
138
|
return `${label} names each of our tools ${prefix}<tool>, at most ${TOOL_NAME_CAP} characters in all, so a tool's own name may be at most ${TOOL_NAME_CAP - prefix.length}; ${tools.map((tool) => JSON.stringify(tool)).join(", ")} ${one ? "is" : "are"} longer, so ${one ? "it is" : "they are"} left out of the tools it is given at this start`;
|
|
87
139
|
}
|
|
140
|
+
/** The run's notice for a permission request `label` (the agent) made for `tool`, a tool of our server it is not given
|
|
141
|
+
* (ungrantedTool): refused at once, no person asked. */
|
|
142
|
+
export function toolNotGranted(label, tool) {
|
|
143
|
+
return `tool ${JSON.stringify(tool.slice(0, 80))} isn't granted to this agent: ${label} asked to run it and was refused at once, with no person asked, and the run goes on`;
|
|
144
|
+
}
|
|
88
145
|
/** The recipe's `announces` as one start reads them, our MCP server given to the agent as `server` (mcpServerName): its
|
|
89
|
-
* prefix names that server (`mcp_agentrun_` reads `mcp_<server>_
|
|
146
|
+
* prefix names that server (`mcp_agentrun_` reads `mcp_<server>_`; no prefix, the default `agentrun__`, reads
|
|
147
|
+
* `<server>__`), and its `server` field must say that name (`named`). ANNOUNCES_PREFIX ends a prefix at our server's
|
|
90
148
|
* name, so the last `agentrun` in it is that name. */
|
|
91
149
|
export function announcesAt(announces, server) {
|
|
92
|
-
if (!announces ||
|
|
150
|
+
if (!announces || server === MCP_SERVER)
|
|
93
151
|
return announces;
|
|
94
|
-
|
|
95
|
-
|
|
152
|
+
if (announces.server !== undefined)
|
|
153
|
+
return { ...announces, named: server };
|
|
154
|
+
const prefix = announces.prefix ?? `${MCP_SERVER}__`;
|
|
155
|
+
const at = prefix.lastIndexOf(MCP_SERVER);
|
|
156
|
+
return at < 0 ? announces : { ...announces, prefix: `${prefix.slice(0, at)}${server}${prefix.slice(at + MCP_SERVER.length)}` };
|
|
96
157
|
}
|
|
97
158
|
/** Whether an input schema may name an argument `name`: in its `properties`, or in those of a schema it composes (allOf,
|
|
98
159
|
* anyOf, oneOf, at any depth), or behind a `$ref` to its own `$defs` or `definitions`. A `$ref` it cannot read (another
|
|
@@ -160,7 +221,7 @@ export function announcedTool(update, announces, tools) {
|
|
|
160
221
|
return undefined;
|
|
161
222
|
let tool = said;
|
|
162
223
|
if (announces.server !== undefined) {
|
|
163
|
-
if (at(update, announces.server) !== MCP_SERVER)
|
|
224
|
+
if (at(update, announces.server) !== (announces.named ?? MCP_SERVER))
|
|
164
225
|
return null;
|
|
165
226
|
}
|
|
166
227
|
else {
|
|
@@ -171,6 +232,16 @@ export function announcedTool(update, announces, tools) {
|
|
|
171
232
|
}
|
|
172
233
|
return tools.has(tool) ? tool : null;
|
|
173
234
|
}
|
|
235
|
+
/** The server an agent's update names its call under, in the field its recipe declares (`announces.server`: Cursor's
|
|
236
|
+
* rawInput.providerIdentifier), when it is not ours (`named`): clipped to ANNOUNCED_FIELD_CHARS, for the host gate's
|
|
237
|
+
* question about the call, so the person can tell it is another server's, whatever its title says. Undefined when the
|
|
238
|
+
* recipe declares no such field, the update does not carry a name in it, or it names ours. */
|
|
239
|
+
export function otherServer(update, announces) {
|
|
240
|
+
if (announces?.server === undefined)
|
|
241
|
+
return undefined;
|
|
242
|
+
const said = at(update, announces.server);
|
|
243
|
+
return typeof said === "string" && said !== "" && said !== (announces.named ?? MCP_SERVER) ? said.slice(0, ANNOUNCED_FIELD_CHARS) : undefined;
|
|
244
|
+
}
|
|
174
245
|
/** The arguments an update reports for its call: at the recipe's `announces.args`, or its rawInput, without the
|
|
175
246
|
* recipe's `extras` that hold text (agy's toolSummary), but for those the tool's schema declares (`kept`). */
|
|
176
247
|
function announcedArgs(update, announces, kept) {
|
|
@@ -274,7 +345,8 @@ export class CallIds {
|
|
|
274
345
|
* which it is kept too; the first MCP call either matches takes it, and it is gone from both. A call already waiting
|
|
275
346
|
* is handed it only where it is the call's own first key, its tool and its whole arguments. One that matches it only
|
|
276
347
|
* without the extra may be another call's, whose own announcement is on its way, and one naming no tool or reporting
|
|
277
|
-
* no input may come second to the call's own ended one,
|
|
348
|
+
* no input may come second to the call's own ended one, or to a live guess under its first key (an `also` form, its
|
|
349
|
+
* own MCP call maybe on its way), so for those the call tries again as take says (wake). */
|
|
278
350
|
add(id, tool, input, also) {
|
|
279
351
|
if (this.used.has(id))
|
|
280
352
|
return;
|
|
@@ -370,7 +442,9 @@ export class CallIds {
|
|
|
370
442
|
// announcement whose own first key is this one counts as its own: one kept here only read without an extra
|
|
371
443
|
// (addAnnounced) is a guess, and a live one under a later key comes first, as before. So a retry announced with
|
|
372
444
|
// less than its call's whole arguments (no tool, or no input), after a call with these arguments ended, takes the
|
|
373
|
-
// ended one's id after the hold: the same tool with the same arguments, the order the two came in lost.
|
|
445
|
+
// ended one's id after the hold: the same tool with the same arguments, the order the two came in lost. The retry's
|
|
446
|
+
// own announcement then stays live, under its key with no tool or no input, until its call settles, and a later MCP
|
|
447
|
+
// call of the same tool with the same arguments may take its id meanwhile. Beyond this: an
|
|
374
448
|
// announcement that comes more than the grace after its own MCP call (that call takes the other's), and a call torn
|
|
375
449
|
// until the wait is over, more than ms behind the other's MCP call (it takes the oldest, which may be the other's);
|
|
376
450
|
// in both the other's MCP call falls back once its wait is over. Two calls with the same arguments, one ended, can
|
package/dist/cursor-facts.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { START_SERVER } from "./calls.js";
|
|
1
2
|
import { ACP_CODES } from "./facts.js";
|
|
2
3
|
import { CURSOR_PIN } from "./pinned-binary.js";
|
|
3
4
|
/** The command that installs the pinned Cursor CLI into an AgentRun server's data (`<data>/harnesses/cursor`). */
|
|
@@ -26,6 +27,8 @@ export function cursorCard(limits = CURSOR_LIMITS) {
|
|
|
26
27
|
`If your Cursor team administrator turned headless CLI use off, its runs are refused (${CURSOR_CODES.headlessDisabled}).`,
|
|
27
28
|
].join(" ");
|
|
28
29
|
}
|
|
30
|
+
/** A title Cursor gives one of our tools' calls, our server under its start's own name: the tool's name after it. */
|
|
31
|
+
const HOST_TITLE = new RegExp(`^${START_SERVER}(?:-[^:]*)?: (.+)$`);
|
|
29
32
|
export const cursorFacts = Object.freeze({
|
|
30
33
|
id: "cursor",
|
|
31
34
|
label: "Cursor",
|
|
@@ -47,8 +50,9 @@ export const cursorFacts = Object.freeze({
|
|
|
47
50
|
normalizeModel: (model) => model,
|
|
48
51
|
// Installed by its owner, never on first use: the archive the pin names, its digests checked (serve's harness-archive.ts).
|
|
49
52
|
install: Object.freeze({ npmLine: CURSOR_INSTALL, spec: `cursor@${CURSOR_PIN.version}`, codes: Object.freeze({ install: CURSOR_CODES.notInstalled, pins: ACP_CODES.binaryMismatch }) }),
|
|
50
|
-
// Its MCP calls are titled
|
|
51
|
-
|
|
53
|
+
// Its MCP calls are titled `<server>-<tool>: <tool>` (its permission asks) or `<server>: <tool>` (its updates), our
|
|
54
|
+
// server under its start's own name (calls.ts mcpServerName): one under any other is another server's, and keeps its words.
|
|
55
|
+
hostName: (given) => HOST_TITLE.exec(given)?.[1]?.trim() ?? given,
|
|
52
56
|
policy: () => {
|
|
53
57
|
throw new Error("acp: Cursor is billed to its owner's plan: its model requests never reach a proxy, so it has no proxy policy");
|
|
54
58
|
},
|
package/dist/goose-facts.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { MCP_SERVER, START_SERVER } from "./calls.js";
|
|
1
2
|
import { ACP_CODES } from "./facts.js";
|
|
2
|
-
import { goosePolicy
|
|
3
|
+
import { goosePolicy } from "./host/goose-proxy.js";
|
|
3
4
|
import { GOOSE_PIN } from "./pinned-binary.js";
|
|
4
5
|
/** The command that installs the pinned Goose into an AgentRun server's data (`<data>/harnesses/goose`). */
|
|
5
6
|
export const GOOSE_INSTALL = "agentrun harness install goose";
|
|
6
7
|
/** The code a host's refusal carries when Goose is not installed where it looks. */
|
|
7
8
|
export const GOOSE_NOT_INSTALLED = "HARNESS_NOT_INSTALLED";
|
|
8
|
-
|
|
9
|
+
/** A tool of ours as the agent names it: `<server>__<tool>`, our server `agentrun` or a run's own name (`ar` and 6 hex
|
|
10
|
+
* digits, calls.ts mcpServerName: a proxy-billed recipe with the title tie takes these facts). */
|
|
11
|
+
const OURS = new RegExp(`^(?:${MCP_SERVER}|${START_SERVER})__(.+)$`, "s");
|
|
9
12
|
export const gooseFacts = Object.freeze({
|
|
10
13
|
id: "goose",
|
|
11
14
|
label: "Goose",
|
|
@@ -28,7 +31,8 @@ export const gooseFacts = Object.freeze({
|
|
|
28
31
|
normalizeModel: (model) => (model.provider === "anthropic" ? { ...model, modelId: model.modelId.replaceAll(".", "-") } : model),
|
|
29
32
|
// Installed by its owner, never on first use: the archive the pin names, its digests checked (serve's harness-archive.ts).
|
|
30
33
|
install: Object.freeze({ npmLine: GOOSE_INSTALL, spec: `goose@${GOOSE_PIN.version}`, codes: Object.freeze({ install: GOOSE_NOT_INSTALLED, pins: ACP_CODES.binaryMismatch }) }),
|
|
31
|
-
// Its bundled extensions are off: the model calls only our MCP server's tools, as `agentrun__<host tool
|
|
32
|
-
|
|
34
|
+
// Its bundled extensions are off: the model calls only our MCP server's tools, as `agentrun__<host tool>` (or, under a
|
|
35
|
+
// recipe of these facts that names our server per run, `ar3f12ab__<host tool>`).
|
|
36
|
+
hostName: (given) => OURS.exec(given)?.[1] ?? given,
|
|
33
37
|
policy: (options) => goosePolicy({ model: options.model, tools: options.tools, ...(options.auth ? { auth: options.auth } : {}), ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}) }),
|
|
34
38
|
});
|
package/dist/harness.d.ts
CHANGED
package/dist/harness.js
CHANGED
|
@@ -19,10 +19,11 @@ 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, journalTurn, NativeJournal, openTurn, placeSubmissions, recoveryNote, resumeUnstartedCalls, toolBridge, toolKey, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
22
|
-
import { announceCall, announcedField, announcesAt, CallIds, declaresProperty, joinsByOne, mcpServerName, nameCall, namesTooLong, ourTool, permissionCallId, toolsLeftOut } from "./calls.js";
|
|
22
|
+
import { announceCall, announcedField, announcesAt, CallIds, declaresProperty, joinsByOne, mcpServerName, MCP_SERVER, namedPerStart, nameCall, namesTooLong, otherServer, ourTool, permissionCallId, toolNotGranted, toolsLeftOut, ungrantedTool } from "./calls.js";
|
|
23
23
|
import { ACP_CODES } from "./facts.js";
|
|
24
24
|
import { allowFileText, homePath } from "./recipe.js";
|
|
25
25
|
import { restoreState, STATE_STREAM, StateMirror } from "./state.js";
|
|
26
|
+
import { configDeclaring, KEPT_SERVER, nameRefused, SERVER_STREAM } from "./server-name.js";
|
|
26
27
|
import { startAgent } from "./host/agent.js";
|
|
27
28
|
import { cutKeys, keysToCut } from "./host/key-cut.js";
|
|
28
29
|
import { startMcpServer } from "./host/mcp.js";
|
|
@@ -175,7 +176,7 @@ export function acpHarness(options, control) {
|
|
|
175
176
|
const offered = options.tools.filter((tool) => !tool.deferred);
|
|
176
177
|
/** Those the agent names past its cap under our server's name (namesTooLong), which it could never call: never listed,
|
|
177
178
|
* and each start says so (toolsLeftOut). The name's length is the same at every start (mcpServerName). */
|
|
178
|
-
const capped = joinsByOne(recipe.announces) ? namesTooLong(announcesAt(recipe.announces, mcpServerName(recipe.announces)), offered.map((tool) => tool.name)) : [];
|
|
179
|
+
const capped = joinsByOne(recipe.announces) ? namesTooLong(announcesAt(recipe.announces, mcpServerName(recipe.announces, recipe.quirks?.permissionTie)), offered.map((tool) => tool.name)) : [];
|
|
179
180
|
const listed = offered.filter((tool) => !capped.includes(tool.name));
|
|
180
181
|
const names = new Set(listed.map((tool) => tool.name));
|
|
181
182
|
/** For each tool, the recipe's announces.extras its own input schema declares: kept in its arguments (announceCall). */
|
|
@@ -249,6 +250,13 @@ export function acpHarness(options, control) {
|
|
|
249
250
|
}
|
|
250
251
|
return turn?.limitHit ?? `${ACP_CODES.toolCallLimit}: the plan's limit of ${plan.maxToolCalls} tool calls is reached`;
|
|
251
252
|
};
|
|
253
|
+
/** A call an update names under another server than ours, by the recipe's server field (otherServer): kept for the
|
|
254
|
+
* host gate's question about it (permissionGateCall's `server`). A later update may name it again. */
|
|
255
|
+
const noteServer = (rt, update) => {
|
|
256
|
+
const other = otherServer(update, rt.announces);
|
|
257
|
+
if (other)
|
|
258
|
+
rt.others.set(update.toolCallId, other);
|
|
259
|
+
};
|
|
252
260
|
/** Debug only (serve's AGENTRUN_LOG=debug), on a recipe that declares announces: a call the agent announced, by its
|
|
253
261
|
* 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
|
|
254
262
|
* tool of ours: on Cursor's recipe it sits inside the call's input, so another call's is "native" (null: none).
|
|
@@ -282,6 +290,7 @@ export function acpHarness(options, control) {
|
|
|
282
290
|
countCall(rt, cur, update.toolCallId);
|
|
283
291
|
// Kept for the MCP call it may be, named by the recipe's announces field, never by its title (announceCall).
|
|
284
292
|
announceCall(rt.calls, update, rt.announces, names, declared);
|
|
293
|
+
noteServer(rt, update);
|
|
285
294
|
logAnnounced(rt, update);
|
|
286
295
|
return;
|
|
287
296
|
}
|
|
@@ -291,6 +300,7 @@ export function acpHarness(options, control) {
|
|
|
291
300
|
// A call the agent named only after announcing it with no input (Cursor's): by the recipe's field (nameCall).
|
|
292
301
|
const held = rt.calls.held(update.toolCallId);
|
|
293
302
|
nameCall(rt.calls, update, rt.announces, names, declared);
|
|
303
|
+
noteServer(rt, update);
|
|
294
304
|
if (held && !rt.calls.held(update.toolCallId))
|
|
295
305
|
logAnnounced(rt, update);
|
|
296
306
|
// Its status is the agent's word only: what it changes is the mirror of the agent's session store.
|
|
@@ -311,8 +321,10 @@ export function acpHarness(options, control) {
|
|
|
311
321
|
};
|
|
312
322
|
/** The gate's call for a permission request of the agent's own tool: the same when the agent asks and when a resume
|
|
313
323
|
* asks about it again (settlePermissions), so both reach the one approval. Under its journal id (`callId`); its args
|
|
314
|
-
* carry the toolCallId the agent first asked under, so a host (harness-check) ties the question to the request
|
|
315
|
-
|
|
324
|
+
* carry the toolCallId the agent first asked under, so a host (harness-check) ties the question to the request, and
|
|
325
|
+
* the server another than ours an update named the call under (`server`, otherServer), so the person can tell a call
|
|
326
|
+
* titled as one of our tools (`agentrun-look_up: look_up`) is that server's. */
|
|
327
|
+
const permissionGateCall = (callId, toolCallId, kind, title, input, server) => ({ callId, tool: `acp_${kind.replace(/[^A-Za-z0-9_]/g, "_")}`, args: { title, kind, input, ...(toolCallId ? { toolCallId } : {}), ...(server ? { server } : {}) } });
|
|
316
328
|
/** The recovery note's line for a settled answer: the request as the agent asked it (its kind, title and input, so an
|
|
317
329
|
* agent started without session/load can ask for the same call) and what the person said. */
|
|
318
330
|
const answerLine = (asked, answer) => {
|
|
@@ -320,6 +332,8 @@ export function acpHarness(options, control) {
|
|
|
320
332
|
const input = asked?.input === undefined || asked.input === null ? "" : JSON.stringify(asked.input);
|
|
321
333
|
const shown = input ? ` Its input: ${clip(input, 1500)}${input.length > 1500 ? " (cut here: ask with the whole input you first sent)" : ""}.` : "";
|
|
322
334
|
const named = `${kind} ${JSON.stringify(clip(asked?.title ?? kind, 300))}.${shown}`;
|
|
335
|
+
if (answer.ungranted)
|
|
336
|
+
return `- ${named} Refused, with no person asked: ${clip(answer.words ?? "", 500)}.`;
|
|
323
337
|
return answer.answer === "deny"
|
|
324
338
|
? `- ${named} The person refused it.${answer.words ? ` Their words: ${clip(answer.words, 500).replace(/\n/g, " ")}` : ""}`
|
|
325
339
|
: `- ${named} The person allowed it once. Ask for it again exactly as before (the same kind, title and input) and it runs; any other request waits for the person again.`;
|
|
@@ -346,7 +360,24 @@ export function acpHarness(options, control) {
|
|
|
346
360
|
for (const request of waiting) {
|
|
347
361
|
const kind = request.kind ?? "other";
|
|
348
362
|
const title = request.title ?? kind;
|
|
349
|
-
|
|
363
|
+
// A request for a tool of ours this start does not give the agent (ungrantedTool), left waiting by a run that
|
|
364
|
+
// parked on it: refused here as onPermission refuses a new one, never asked of a person. Settled, so the agent's
|
|
365
|
+
// ask again takes the deny. Its title names our server as the start that asked was given it (`ours`, recorded
|
|
366
|
+
// with it): under a recipe that names the server per start (Cursor's, agy's) a request recorded without that name
|
|
367
|
+
// is the gate's, as its title cannot be tied to a server of ours.
|
|
368
|
+
const ours = request.ours ?? (namedPerStart(recipe.announces, recipe.quirks?.permissionTie) ? undefined : MCP_SERVER);
|
|
369
|
+
const ungranted = ours === undefined ? undefined : ungrantedTool({ title, kind }, names, ours);
|
|
370
|
+
if (ungranted !== undefined) {
|
|
371
|
+
const words = toolNotGranted(recipe.label ?? recipe.id, ungranted);
|
|
372
|
+
const answer = { type: "answered", callId: request.callId, answer: "deny", words, settled: true, turn: turnId, ungranted: true };
|
|
373
|
+
journal.append(PERMISSION_STREAM, answer);
|
|
374
|
+
await journal.flush();
|
|
375
|
+
ctx.live({ type: "notice", text: words });
|
|
376
|
+
said.push(answerLine(request, answer));
|
|
377
|
+
records.push(answer);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const refused = await askGate(gate, permissionGateCall(request.callId, request.toolCallId, kind, title, request.input ?? null, request.server), ctx.signal);
|
|
350
381
|
const answer = { type: "answered", callId: request.callId, answer: refused ? "deny" : "allow", ...(refused?.deny ? { words: refused.deny } : {}), settled: true, turn: turnId };
|
|
351
382
|
journal.append(PERMISSION_STREAM, answer);
|
|
352
383
|
await journal.flush();
|
|
@@ -389,10 +420,19 @@ export function acpHarness(options, control) {
|
|
|
389
420
|
if (mine && rt.calls.announced(request.toolCall.toolCallId) === mine)
|
|
390
421
|
return choose("allow_once");
|
|
391
422
|
}
|
|
423
|
+
// A tool of our server the agent is not given (ungrantedTool): no grant to ask a person for, so it is refused at
|
|
424
|
+
// once, before anything is journaled (a resume has nothing to ask again), and the run is told which tool.
|
|
425
|
+
const ungranted = ungrantedTool(request.toolCall, names, rt.server);
|
|
426
|
+
if (ungranted !== undefined) {
|
|
427
|
+
log("acp: refused a permission request for a tool the agent is not given", { toolCallId: request.toolCall.toolCallId, tool: ungranted.slice(0, 80) });
|
|
428
|
+
cur.ctx.live({ type: "notice", text: toolNotGranted(recipe.label ?? recipe.id, ungranted) });
|
|
429
|
+
return choose("reject_once");
|
|
430
|
+
}
|
|
392
431
|
const call = request.toolCall;
|
|
393
432
|
const kind = typeof call.kind === "string" && call.kind ? call.kind : "other";
|
|
394
433
|
const title = typeof call.title === "string" ? call.title : kind;
|
|
395
434
|
const input = call.rawInput ?? null;
|
|
435
|
+
const server = rt.others.get(call.toolCallId);
|
|
396
436
|
// The request's id is the open turn's: the turn, what it asks, and which of the turn's requests that ask the same it
|
|
397
437
|
// is. Of the ids this process has not taken and no agent was handed an answer for (`given`: an allow-once is used
|
|
398
438
|
// once), it takes the first one answered (a resume took the answer; the agent asks again for it), else the first
|
|
@@ -430,7 +470,7 @@ export function acpHarness(options, control) {
|
|
|
430
470
|
const unasked = all.find((r) => r?.type === "answered" && r.settled && r.turn === turnId && r.answer === "allow" && !givenIds.has(r.callId));
|
|
431
471
|
if (unasked)
|
|
432
472
|
cur.journal.append(PERMISSION_STREAM, { type: "reasked", callId, turn: turnId, instead: unasked.callId });
|
|
433
|
-
cur.journal.append(PERMISSION_STREAM, { type: "asked", callId, toolCallId: call.toolCallId, title, kind, input });
|
|
473
|
+
cur.journal.append(PERMISSION_STREAM, { type: "asked", callId, toolCallId: call.toolCallId, title, kind, input, ours: rt.server, ...(server ? { server } : {}) });
|
|
434
474
|
await cur.journal.flush();
|
|
435
475
|
}
|
|
436
476
|
else if (options.gate) {
|
|
@@ -442,9 +482,10 @@ export function acpHarness(options, control) {
|
|
|
442
482
|
let refused;
|
|
443
483
|
if (options.gate) {
|
|
444
484
|
// The toolCallId the request was first asked under, as the journal has it: the same question a resume asks.
|
|
445
|
-
const
|
|
485
|
+
const askedRecord = records.find((r) => r.type === "asked");
|
|
486
|
+
const askedAs = askedRecord?.toolCallId ?? call.toolCallId;
|
|
446
487
|
try {
|
|
447
|
-
refused = await askGate(options.gate, permissionGateCall(callId, askedAs, kind, title, input), AbortSignal.any([cur.signal, connection, turn.stop.signal]));
|
|
488
|
+
refused = await askGate(options.gate, permissionGateCall(callId, askedAs, kind, title, input, askedRecord?.server ?? server), AbortSignal.any([cur.signal, connection, turn.stop.signal]));
|
|
448
489
|
}
|
|
449
490
|
catch {
|
|
450
491
|
// Parked, and the session let go (or the turn was cancelled): nothing is answered, nothing recorded.
|
|
@@ -521,13 +562,6 @@ export function acpHarness(options, control) {
|
|
|
521
562
|
}
|
|
522
563
|
if (absent.length)
|
|
523
564
|
throw new Error(`${ACP_CODES.keyMissing}: ${recipe.label ?? recipe.id} runs on ${absent.join(" and ")}, which this host does not hold; the agent was not started`);
|
|
524
|
-
// A tool of ours the agent would name past its cap is not listed (capped); the run is told which, and goes on.
|
|
525
|
-
const serverName = mcpServerName(recipe.announces);
|
|
526
|
-
if (capped.length) {
|
|
527
|
-
const words = toolsLeftOut(recipe.label ?? recipe.id, announcesAt(recipe.announces, serverName)?.prefix ?? "", capped);
|
|
528
|
-
log("acp: tools left out of the agent's listing, named past its cap", { tools: capped });
|
|
529
|
-
ctx.live({ type: "notice", text: words });
|
|
530
|
-
}
|
|
531
565
|
mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
532
566
|
// Everything the agent kept goes: what it starts with is the session's records, never an earlier process's files.
|
|
533
567
|
for (const dir of [home, tmp]) {
|
|
@@ -537,10 +571,36 @@ export function acpHarness(options, control) {
|
|
|
537
571
|
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
538
572
|
const records = (await journal.read(STATE_STREAM)).map((r) => r.data);
|
|
539
573
|
restoreState(home, records);
|
|
574
|
+
// Our server's name (server-name.ts): under a per-start name and a recipe that lists the configs its agent reads
|
|
575
|
+
// (mcpConfigs), the one the run kept, unless one of them declares a server under it; then a fresh one, kept from now
|
|
576
|
+
// on, and the run is told once. Under a per-start name and no list, nothing could check a config the agent wrote
|
|
577
|
+
// against a kept name, so each start's own. The fixed name, as it is.
|
|
578
|
+
const minted = mcpServerName(recipe.announces, recipe.quirks?.permissionTie);
|
|
579
|
+
let serverName = minted;
|
|
580
|
+
if (minted !== MCP_SERVER && recipe.mcpConfigs?.length) {
|
|
581
|
+
const kept = journal.records(SERVER_STREAM).map((r) => r.data?.name).filter((name) => typeof name === "string" && KEPT_SERVER.test(name)).at(-1);
|
|
582
|
+
const refusal = kept === undefined ? undefined : configDeclaring(kept, recipe.mcpConfigs, home, root, log);
|
|
583
|
+
if (kept !== undefined && refusal === undefined)
|
|
584
|
+
serverName = kept;
|
|
585
|
+
else {
|
|
586
|
+
journal.append(SERVER_STREAM, { name: minted, ...(refusal !== undefined ? { refused: kept, file: refusal.file, how: refusal.how } : {}) });
|
|
587
|
+
await journal.flush();
|
|
588
|
+
if (refusal !== undefined) {
|
|
589
|
+
log("acp: a config the agent reads has the run's server name refused; this start names ours afresh", { file: refusal.file, how: refusal.how, refused: kept, name: minted });
|
|
590
|
+
ctx.live({ type: "notice", text: nameRefused(recipe.label ?? recipe.id, refusal.file, kept, minted, refusal.how) });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
// A tool of ours the agent would name past its cap is not listed (capped); the run is told which, and goes on.
|
|
595
|
+
if (capped.length) {
|
|
596
|
+
const words = toolsLeftOut(recipe.label ?? recipe.id, announcesAt(recipe.announces, serverName)?.prefix ?? "", capped);
|
|
597
|
+
log("acp: tools left out of the agent's listing, named past its cap", { tools: capped });
|
|
598
|
+
ctx.live({ type: "notice", text: words });
|
|
599
|
+
}
|
|
540
600
|
const own = new Set();
|
|
541
601
|
// The recipe's allowFile (Goose's permission file): the tools this start lists, in the agent's own form, and nothing
|
|
542
602
|
// else, so the agent runs them unasked and our gate asks at the MCP call.
|
|
543
|
-
const allowed = recipe.allowFile ? { [recipe.allowFile.path]: allowFileText(recipe.allowFile.form, listed.map((tool) => tool.name)) } : {};
|
|
603
|
+
const allowed = recipe.allowFile ? { [recipe.allowFile.path]: allowFileText(recipe.allowFile.form, listed.map((tool) => tool.name), serverName) } : {};
|
|
544
604
|
for (const [path, text] of [...Object.entries(recipe.files ?? {}), ...Object.entries(allowed)]) {
|
|
545
605
|
const clean = homePath(path);
|
|
546
606
|
if (!clean)
|
|
@@ -563,7 +623,7 @@ export function acpHarness(options, control) {
|
|
|
563
623
|
const stopped = new AbortController();
|
|
564
624
|
const signal = AbortSignal.any([ctx.signal, stopped.signal]);
|
|
565
625
|
const key = randomBytes(32).toString("base64url");
|
|
566
|
-
const rt = { ctx, loading: false, fresh: true, wiped: false, firstBlocks: [], calls: new CallIds(), server: serverName, announces: announcesAt(recipe.announces, serverName), 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 })) };
|
|
626
|
+
const rt = { ctx, loading: false, fresh: true, wiped: false, firstBlocks: [], calls: new CallIds(), others: new Map(), server: serverName, announces: announcesAt(recipe.announces, serverName), 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 })) };
|
|
567
627
|
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) });
|
|
568
628
|
let proxy;
|
|
569
629
|
let agent;
|
|
@@ -602,7 +662,7 @@ export function acpHarness(options, control) {
|
|
|
602
662
|
if (recipe.billing.kind === "proxy") {
|
|
603
663
|
if (!options.proxy)
|
|
604
664
|
throw new Error("acp: proxy billing needs the adapter's proxy option");
|
|
605
|
-
proxy = await options.proxy({ halt: (reason) => ctx.halt?.(reason) });
|
|
665
|
+
proxy = await options.proxy({ halt: (reason) => ctx.halt?.(reason), server: serverName });
|
|
606
666
|
// A stop while the proxy started: the drive's end ran before there was a proxy to close. It is closed here, and
|
|
607
667
|
// the agent is never started.
|
|
608
668
|
if (signal.aborted) {
|
|
@@ -3,8 +3,9 @@ import type { AcpProxy } from "../adapter.js";
|
|
|
3
3
|
/** Goose's own tools that stay on with every bundled extension off: `load_skill`, which its agent always offers and which
|
|
4
4
|
* reads skill files only. */
|
|
5
5
|
export declare const GOOSE_OWN_TOOLS: readonly string[];
|
|
6
|
-
/** A host tool's name as Goose offers it to its model: the MCP server's name
|
|
7
|
-
|
|
6
|
+
/** A host tool's name as Goose offers it to its model: the MCP server's name at this start (`agentrun` under Goose's own
|
|
7
|
+
* recipe; a start's own under a recipe with the title tie: mcpServerName), two underscores, the tool's. */
|
|
8
|
+
export declare const gooseToolName: (name: string, server?: string) => string;
|
|
8
9
|
/** The `anthropic-beta` value Goose 1.59.2 sends with each Messages request, recorded behind a fake origin (the package's
|
|
9
10
|
* Goose test records it again on every run with the binary). */
|
|
10
11
|
export declare const GOOSE_BETAS: ReadonlySet<string>;
|
|
@@ -15,6 +16,8 @@ export interface GoosePolicyOptions {
|
|
|
15
16
|
model: string;
|
|
16
17
|
/** The session's host tools, by their names (`spec.tools`). */
|
|
17
18
|
tools: readonly string[];
|
|
19
|
+
/** Our MCP server's name at this start (AcpProxySession.server). Default `agentrun`. */
|
|
20
|
+
server?: string;
|
|
18
21
|
/** The most output tokens one request may ask for. Default 128 000, what Goose asks for. */
|
|
19
22
|
maxOutputTokens?: number;
|
|
20
23
|
/** How the provider takes its credential. Default `x-api-key` (Anthropic's API). */
|
package/dist/host/goose-proxy.js
CHANGED
|
@@ -26,8 +26,9 @@ import { MCP_SERVER } from "../calls.js";
|
|
|
26
26
|
/** Goose's own tools that stay on with every bundled extension off: `load_skill`, which its agent always offers and which
|
|
27
27
|
* reads skill files only. */
|
|
28
28
|
export const GOOSE_OWN_TOOLS = Object.freeze(["load_skill"]);
|
|
29
|
-
/** A host tool's name as Goose offers it to its model: the MCP server's name
|
|
30
|
-
|
|
29
|
+
/** A host tool's name as Goose offers it to its model: the MCP server's name at this start (`agentrun` under Goose's own
|
|
30
|
+
* recipe; a start's own under a recipe with the title tie: mcpServerName), two underscores, the tool's. */
|
|
31
|
+
export const gooseToolName = (name, server = MCP_SERVER) => `${server}__${name}`;
|
|
31
32
|
/** The `anthropic-beta` value Goose 1.59.2 sends with each Messages request, recorded behind a fake origin (the package's
|
|
32
33
|
* Goose test records it again on every run with the binary). */
|
|
33
34
|
export const GOOSE_BETAS = new Set(["thinking-binding-controls-2026-08-01"]);
|
|
@@ -104,7 +105,7 @@ export function applyGoose(body, options) {
|
|
|
104
105
|
blocks(message.content, "a message's content");
|
|
105
106
|
}
|
|
106
107
|
blocks(body.system, "system");
|
|
107
|
-
const allowed = new Set([...options.tools.map(gooseToolName), ...GOOSE_OWN_TOOLS]);
|
|
108
|
+
const allowed = new Set([...options.tools.map((name) => gooseToolName(name, options.server)), ...GOOSE_OWN_TOOLS]);
|
|
108
109
|
if (body.tools !== undefined) {
|
|
109
110
|
if (!Array.isArray(body.tools))
|
|
110
111
|
refuse(400, "tools is not a list");
|
|
@@ -316,7 +317,7 @@ export function goosePolicy(options) {
|
|
|
316
317
|
export function gooseProxy(options) {
|
|
317
318
|
return async (session) => {
|
|
318
319
|
const proxy = await startModelProxy({
|
|
319
|
-
policy: goosePolicy({ model: options.model, tools: session.tools, ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(options.provider.auth ? { auth: options.provider.auth } : {}) }),
|
|
320
|
+
policy: goosePolicy({ model: options.model, tools: session.tools, ...(session.server ? { server: session.server } : {}), ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), ...(options.provider.auth ? { auth: options.provider.auth } : {}) }),
|
|
320
321
|
hooks: session.models,
|
|
321
322
|
...(session.turn ? { turn: session.turn } : {}),
|
|
322
323
|
model: options.model,
|
package/dist/host/mcp.js
CHANGED
|
@@ -123,7 +123,7 @@ export async function startMcpServer(options) {
|
|
|
123
123
|
async function call(id, params, req, res) {
|
|
124
124
|
const name = typeof params.name === "string" ? params.name : "";
|
|
125
125
|
if (!known.has(name))
|
|
126
|
-
return json(res, 200, { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: `
|
|
126
|
+
return json(res, 200, { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: `tool ${JSON.stringify(name.slice(0, 80))} isn't granted to this agent` }], isError: true } });
|
|
127
127
|
const args = isPlain(params.arguments) ? params.arguments : {};
|
|
128
128
|
const meta = isPlain(params._meta) ? params._meta : {};
|
|
129
129
|
const token = typeof meta.progressToken === "string" || typeof meta.progressToken === "number" ? meta.progressToken : undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { ALLOW_FILE_FORMS, allowFileText, announcesProblems, AUTH_METHOD, homePa
|
|
|
4
4
|
export { ANNOUNCES_PATH, type AcpAnnounces } from "./calls.js";
|
|
5
5
|
export { CALL_STREAM, contextNote, INSTRUCTIONS_STREAM, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
6
6
|
export { STATE_BUDGET, STATE_STREAM, stateBudgetPassed, stateFiles, type StateRecord } from "./state.js";
|
|
7
|
+
export { SERVER_STREAM, type ServerRecord } from "./server-name.js";
|
|
7
8
|
export type { ConfineChild } from "./host/child.js";
|
|
8
9
|
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
|
9
10
|
export { gooseAdapter, gooseRecipe, recipeFile, type AcpRecipeFile, type AcpRecipeName, type GooseAdapterOptions, type GooseRecipeOptions } from "./goose.js";
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { ALLOW_FILE_FORMS, allowFileText, announcesProblems, AUTH_METHOD, homePa
|
|
|
5
5
|
export { ANNOUNCES_PATH } from "./calls.js";
|
|
6
6
|
export { CALL_STREAM, contextNote, INSTRUCTIONS_STREAM, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, REASK_LIMIT, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
7
7
|
export { STATE_BUDGET, STATE_STREAM, stateBudgetPassed, stateFiles } from "./state.js";
|
|
8
|
+
export { SERVER_STREAM } from "./server-name.js";
|
|
8
9
|
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
|
9
10
|
export { gooseAdapter, gooseRecipe, recipeFile } from "./goose.js";
|
|
10
11
|
export { applyGoose, GOOSE_BETAS, GOOSE_OWN_TOOLS, gooseProxy, goosePolicy, gooseRoutes, gooseToolName, gooseUsage, limitGooseOutput } from "./host/goose-proxy.js";
|
package/dist/recipe.d.ts
CHANGED
|
@@ -26,9 +26,9 @@ export declare const AUTH_METHOD: RegExp;
|
|
|
26
26
|
declare const ALLOW_FORMS: {
|
|
27
27
|
/** Goose 1.59.2's permission file (PermissionConfig under `user`, every field present: none has a default, and a
|
|
28
28
|
* file that does not parse stops Goose at its start): each tool always allowed by the name Goose calls it,
|
|
29
|
-
*
|
|
30
|
-
* not named, so they still ask. */
|
|
31
|
-
"goose-permission": (tools: readonly string[]) => string;
|
|
29
|
+
* `<server>__<tool>` (`server`: our MCP server's name at this start, mcpServerName), nothing asked before or never
|
|
30
|
+
* allowed. Written as JSON, which YAML reads. Goose's own tools are not named, so they still ask. */
|
|
31
|
+
"goose-permission": (tools: readonly string[], server: string) => string;
|
|
32
32
|
};
|
|
33
33
|
/** The forms an allowFile may take, by name: a recipe loader's check (serve's) reads them from here. */
|
|
34
34
|
export declare const ALLOW_FILE_FORMS: readonly string[];
|
|
@@ -39,8 +39,8 @@ export type AcpAllowFile = {
|
|
|
39
39
|
readonly path: string;
|
|
40
40
|
readonly form: AcpAllowForm;
|
|
41
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;
|
|
42
|
+
/** The text of an allowFile in `form` for a start whose MCP server, given to the agent as `server`, lists `tools`. */
|
|
43
|
+
export declare function allowFileText(form: AcpAllowForm, tools: readonly string[], server?: string): string;
|
|
44
44
|
export interface AcpRecipe {
|
|
45
45
|
/** The harness's id: the adapter's. */
|
|
46
46
|
readonly id: string;
|
|
@@ -104,6 +104,12 @@ export interface AcpRecipe {
|
|
|
104
104
|
/** Where in HOME the agent keeps its own sessions: mirrored into the session's records, so another runner's agent
|
|
105
105
|
* loads them (session/load). Credential files under them are never mirrored. */
|
|
106
106
|
readonly state?: readonly string[];
|
|
107
|
+
/** The MCP config files the agent reads, each JSON with an `mcpServers` object: `~/<path>` or `$HOME/<path>` in its
|
|
108
|
+
* private HOME, else a path in the work directory (Cursor 2026.11.13: `~/.cursor/mcp.json` and `.cursor/mcp.json`).
|
|
109
|
+
* Under a per-start server name and at least one of these, the run keeps one name across its starts; one of these
|
|
110
|
+
* that declares a server under it has it refused for that start (a fresh name, the run told which file), and the file
|
|
111
|
+
* is never edited. Without any, each start names the server afresh. */
|
|
112
|
+
readonly mcpConfigs?: readonly string[];
|
|
107
113
|
/** What the agent is expected to advertise at initialize: a mismatch refuses with ACP_CODES.capabilityMismatch.
|
|
108
114
|
* `load`: it resumes a session with session/load. `mcp`: the transport our tools go over. */
|
|
109
115
|
readonly declares: {
|
|
@@ -122,6 +128,12 @@ export interface AcpRecipe {
|
|
|
122
128
|
readonly permissionTie?: "title";
|
|
123
129
|
};
|
|
124
130
|
}
|
|
131
|
+
/** Where an mcpConfigs entry is: `home` (a `~/` or `$HOME/` path, as `files` spells one, made relative to HOME) or
|
|
132
|
+
* `work` (relative to the work directory); undefined when it leaves either or is no path. */
|
|
133
|
+
export declare function mcpConfigPath(path: unknown): {
|
|
134
|
+
readonly in: "home" | "work";
|
|
135
|
+
readonly path: string;
|
|
136
|
+
} | undefined;
|
|
125
137
|
/** `path` in HOME, normalized, or undefined when it leaves HOME (absolute, `..`, or a `$HOME/` prefix spelled out). */
|
|
126
138
|
export declare function homePath(path: string): string | undefined;
|
|
127
139
|
/** What is wrong with a recipe's `announces` field, and with a title tie (quirks.permissionTie) without it, each in
|
package/dist/recipe.js
CHANGED
|
@@ -16,15 +16,24 @@ export const AUTH_METHOD = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
|
16
16
|
const ALLOW_FORMS = {
|
|
17
17
|
/** Goose 1.59.2's permission file (PermissionConfig under `user`, every field present: none has a default, and a
|
|
18
18
|
* file that does not parse stops Goose at its start): each tool always allowed by the name Goose calls it,
|
|
19
|
-
*
|
|
20
|
-
* not named, so they still ask. */
|
|
21
|
-
"goose-permission": (tools) => `${JSON.stringify({ user: { always_allow: tools.map((tool) => `${
|
|
19
|
+
* `<server>__<tool>` (`server`: our MCP server's name at this start, mcpServerName), nothing asked before or never
|
|
20
|
+
* allowed. Written as JSON, which YAML reads. Goose's own tools are not named, so they still ask. */
|
|
21
|
+
"goose-permission": (tools, server) => `${JSON.stringify({ user: { always_allow: tools.map((tool) => `${server}__${tool}`), ask_before: [], never_allow: [] } })}\n`,
|
|
22
22
|
};
|
|
23
23
|
/** The forms an allowFile may take, by name: a recipe loader's check (serve's) reads them from here. */
|
|
24
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);
|
|
25
|
+
/** The text of an allowFile in `form` for a start whose MCP server, given to the agent as `server`, lists `tools`. */
|
|
26
|
+
export function allowFileText(form, tools, server = MCP_SERVER) {
|
|
27
|
+
return ALLOW_FORMS[form](tools, server);
|
|
28
|
+
}
|
|
29
|
+
/** Where an mcpConfigs entry is: `home` (a `~/` or `$HOME/` path, as `files` spells one, made relative to HOME) or
|
|
30
|
+
* `work` (relative to the work directory); undefined when it leaves either or is no path. */
|
|
31
|
+
export function mcpConfigPath(path) {
|
|
32
|
+
if (typeof path !== "string")
|
|
33
|
+
return undefined;
|
|
34
|
+
const inHome = path.startsWith("~/") || path.startsWith("$HOME/");
|
|
35
|
+
const clean = homePath(path.startsWith("~/") ? path.slice(2) : path);
|
|
36
|
+
return clean ? { in: inHome ? "home" : "work", path: clean } : undefined;
|
|
28
37
|
}
|
|
29
38
|
/** `path` in HOME, normalized, or undefined when it leaves HOME (absolute, `..`, or a `$HOME/` prefix spelled out). */
|
|
30
39
|
export function homePath(path) {
|
|
@@ -81,6 +90,13 @@ export function recipeProblems(recipe) {
|
|
|
81
90
|
for (const path of recipe.state ?? [])
|
|
82
91
|
if (!homePath(path))
|
|
83
92
|
problems.push(`the state path ${JSON.stringify(path)} must be inside the private HOME`);
|
|
93
|
+
const configs = recipe.mcpConfigs;
|
|
94
|
+
if (configs !== undefined && !Array.isArray(configs))
|
|
95
|
+
problems.push("mcpConfigs must be a list of paths");
|
|
96
|
+
else
|
|
97
|
+
for (const path of configs ?? [])
|
|
98
|
+
if (!mcpConfigPath(path))
|
|
99
|
+
problems.push(`the mcpConfigs path ${JSON.stringify(path)} must be ~/<a path inside the private HOME> or a path inside the work directory`);
|
|
84
100
|
if (recipe.allowFile !== undefined) {
|
|
85
101
|
const allow = recipe.allowFile;
|
|
86
102
|
const path = typeof allow?.path === "string" ? homePath(allow.path) : undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The native stream a run's kept server name is in: one `{ name }` record per name minted for it, the last the one in
|
|
2
|
+
* use; a record that also says `refused` and `file` minted that name because `file` declared a server under `refused`. */
|
|
3
|
+
export declare const SERVER_STREAM = "acp.server";
|
|
4
|
+
/** How a config has the kept name refused: it declares a server under it (`declares`), it does not parse as JSON but
|
|
5
|
+
* names it or spells a name with `\u` escapes (`names`), or it is there and could not be read through (`unread`: no
|
|
6
|
+
* regular file, past MCP_CONFIG_MAX, or the read failed). */
|
|
7
|
+
export type Refusal = "declares" | "names" | "unread";
|
|
8
|
+
/** A record of SERVER_STREAM. */
|
|
9
|
+
export interface ServerRecord {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly refused?: string;
|
|
12
|
+
readonly file?: string;
|
|
13
|
+
readonly how?: Refusal;
|
|
14
|
+
}
|
|
15
|
+
/** A name a run may keep: mcpServerName's per-start form, and nothing else a record could say. */
|
|
16
|
+
export declare const KEPT_SERVER: RegExp;
|
|
17
|
+
/** The most bytes of an MCP config read for a server's name; a larger one is not read, and has the name refused. */
|
|
18
|
+
export declare const MCP_CONFIG_MAX: number;
|
|
19
|
+
/** The first of `configs` (the recipe's mcpConfigs: `~/<path>` or `$HOME/<path>` in `home`, any other in `work`) that
|
|
20
|
+
* has `name` refused, and how (Refusal): its `mcpServers` object declares a server named `name`, as the recipe spells
|
|
21
|
+
* it; or it does not parse as JSON and its text has `name` or a `\u` escape in it (a JSONC reader decodes one); or it is
|
|
22
|
+
* there and is no regular file (a FIFO, a folder), larger than MCP_CONFIG_MAX, or its read failed. Undefined when none
|
|
23
|
+
* does. One that is not there declares nothing; `log` is told of each one refused unread or unparsed. The file is
|
|
24
|
+
* opened once and what it is checked on is what is read (no stat of one file and a read of another), and it is never
|
|
25
|
+
* opened so as to wait on a writer; nothing is written. */
|
|
26
|
+
export declare function configDeclaring(name: string, configs: readonly string[], home: string, work: string, log: (message: string, fields?: Record<string, unknown>) => void): {
|
|
27
|
+
readonly file: string;
|
|
28
|
+
readonly how: Refusal;
|
|
29
|
+
} | undefined;
|
|
30
|
+
/** The run's notice that `label`'s config `file` has `refused` refused (`how`: it declares a server under it, names it
|
|
31
|
+
* unparsed, or could not be read), the name the run's earlier starts gave ours: this start gives ours `name`, and a
|
|
32
|
+
* call under `refused` is that server's. */
|
|
33
|
+
export declare function nameRefused(label: string, file: string, refused: string, name: string, how?: Refusal): string;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Our MCP server's name across a run's starts. Written for AgentRun.
|
|
2
|
+
// - Under a recipe that names it per start (mcpServerName: `ar` and 6 hex digits) and lists the configs its agent reads
|
|
3
|
+
// (mcpConfigs), the first start's name is kept with the run (SERVER_STREAM) and given again at each later start.
|
|
4
|
+
// Under one that lists none, nothing checks them, so each start still names it afresh. An agent that keeps, with a session, the name it was
|
|
5
|
+
// first given still names our calls under ours after a load: Cursor 2026.11.13 does, titling a resumed run's call
|
|
6
|
+
// `ar7e621c-web_fetch` though that start had named the server `arc50d18`, and the title tie asked it as another's.
|
|
7
|
+
// - A name kept that long could be aimed at: a config the agent reads that declares a server under it (one the agent
|
|
8
|
+
// itself wrote in a turn) would pass for ours. So at each start, a config the recipe lists (mcpConfigs) that declares
|
|
9
|
+
// a server under the kept name has it refused for that start: a fresh name is minted and kept, the run is told which
|
|
10
|
+
// file declared it, and a call titled under the old name is that server's, asked at the host's gate. A config that
|
|
11
|
+
// can't be read through (no regular file, past MCP_CONFIG_MAX, or a read that fails) or that does not parse as JSON but
|
|
12
|
+
// names the kept name or spells a name with `\u` escapes (an agent may read comments or trailing commas) counts as
|
|
13
|
+
// declaring it: the name is never kept on a guess. The
|
|
14
|
+
// file is never edited: what is in it is the run's.
|
|
15
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { START_SERVER } from "./calls.js";
|
|
18
|
+
import { mcpConfigPath } from "./recipe.js";
|
|
19
|
+
/** The native stream a run's kept server name is in: one `{ name }` record per name minted for it, the last the one in
|
|
20
|
+
* use; a record that also says `refused` and `file` minted that name because `file` declared a server under `refused`. */
|
|
21
|
+
export const SERVER_STREAM = "acp.server";
|
|
22
|
+
/** A name a run may keep: mcpServerName's per-start form, and nothing else a record could say. */
|
|
23
|
+
export const KEPT_SERVER = new RegExp(`^${START_SERVER}$`);
|
|
24
|
+
/** The most bytes of an MCP config read for a server's name; a larger one is not read, and has the name refused. */
|
|
25
|
+
export const MCP_CONFIG_MAX = 1024 * 1024;
|
|
26
|
+
/** The first of `configs` (the recipe's mcpConfigs: `~/<path>` or `$HOME/<path>` in `home`, any other in `work`) that
|
|
27
|
+
* has `name` refused, and how (Refusal): its `mcpServers` object declares a server named `name`, as the recipe spells
|
|
28
|
+
* it; or it does not parse as JSON and its text has `name` or a `\u` escape in it (a JSONC reader decodes one); or it is
|
|
29
|
+
* there and is no regular file (a FIFO, a folder), larger than MCP_CONFIG_MAX, or its read failed. Undefined when none
|
|
30
|
+
* does. One that is not there declares nothing; `log` is told of each one refused unread or unparsed. The file is
|
|
31
|
+
* opened once and what it is checked on is what is read (no stat of one file and a read of another), and it is never
|
|
32
|
+
* opened so as to wait on a writer; nothing is written. */
|
|
33
|
+
export function configDeclaring(name, configs, home, work, log) {
|
|
34
|
+
for (const config of configs) {
|
|
35
|
+
const where = mcpConfigPath(config);
|
|
36
|
+
if (!where)
|
|
37
|
+
continue;
|
|
38
|
+
const file = join(where.in === "home" ? home : work, where.path);
|
|
39
|
+
let text;
|
|
40
|
+
let fd;
|
|
41
|
+
try {
|
|
42
|
+
try {
|
|
43
|
+
fd = openSync(file, constants.O_RDONLY | constants.O_NONBLOCK);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error.code === "ENOENT")
|
|
47
|
+
continue;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
const stat = fstatSync(fd);
|
|
51
|
+
if (!stat.isFile()) {
|
|
52
|
+
log("acp: an MCP config the agent reads is no regular file; the name is refused", { config });
|
|
53
|
+
return { file: config, how: "unread" };
|
|
54
|
+
}
|
|
55
|
+
if (stat.size > MCP_CONFIG_MAX) {
|
|
56
|
+
log("acp: an MCP config the agent reads is too large to read for our server's name; the name is refused", { config, bytes: stat.size });
|
|
57
|
+
return { file: config, how: "unread" };
|
|
58
|
+
}
|
|
59
|
+
text = readFileSync(fd, "utf8");
|
|
60
|
+
if (Buffer.byteLength(text) > MCP_CONFIG_MAX) {
|
|
61
|
+
log("acp: an MCP config the agent reads grew past what is read for our server's name; the name is refused", { config });
|
|
62
|
+
return { file: config, how: "unread" };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
log("acp: an MCP config the agent reads could not be read for our server's name; the name is refused", { config, error: error instanceof Error ? error.message : String(error) });
|
|
67
|
+
return { file: config, how: "unread" };
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (fd !== undefined)
|
|
71
|
+
closeSync(fd);
|
|
72
|
+
}
|
|
73
|
+
let servers;
|
|
74
|
+
try {
|
|
75
|
+
servers = JSON.parse(text)?.mcpServers;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
if (!text.includes(name) && !text.includes("\\u"))
|
|
79
|
+
continue;
|
|
80
|
+
log("acp: an MCP config the agent reads does not parse as JSON and names our server or spells a name with \\u escapes; the name is refused", { config });
|
|
81
|
+
return { file: config, how: "names" };
|
|
82
|
+
}
|
|
83
|
+
if (typeof servers === "object" && servers !== null && !Array.isArray(servers) && Object.hasOwn(servers, name))
|
|
84
|
+
return { file: config, how: "declares" };
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
/** The run's notice that `label`'s config `file` has `refused` refused (`how`: it declares a server under it, names it
|
|
89
|
+
* unparsed, or could not be read), the name the run's earlier starts gave ours: this start gives ours `name`, and a
|
|
90
|
+
* call under `refused` is that server's. */
|
|
91
|
+
export function nameRefused(label, file, refused, name, how = "declares") {
|
|
92
|
+
const what = how === "unread" ? `${file} could not be read to see whether it declares an MCP server named ${refused}` : how === "names" ? `${file} does not parse as JSON and names ${refused} or spells a name with \\u escapes` : `${file} declares an MCP server named ${refused}`;
|
|
93
|
+
return `${what}, the name this run gave its own tools' server before, so ${label} could take that server's calls for ours: this start names ours ${name}, and a call ${label} names under ${refused} is that server's, not ours, and asks you first. The file was left as it is.`;
|
|
94
|
+
}
|
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.65",
|
|
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.65",
|
|
53
53
|
"zod": "4.6.6"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
package/recipes/cursor.json
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"instructions": "Your own file-writing tool (Write) is turned off here: every write with it is refused, and asking does not turn it on. To create or change a file, run a shell command that writes it (a heredoc such as cat > name <<'EOF' ... EOF, or a short script); a shell command asks the person first. When Write refuses a write, write the file with a shell command instead: never stop at that refusal or answer without the file. When the person denies a shell command, that is their answer: do not ask again for the same write; stop and say what you could not do.",
|
|
10
10
|
"state": [".config/cursor/acp-sessions"],
|
|
11
|
+
"mcpConfigs": ["~/.cursor/mcp.json", ".cursor/mcp.json"],
|
|
11
12
|
"credentials": [".config/cursor/auth.json"],
|
|
12
13
|
"refusals": [
|
|
13
14
|
{
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// load: advertise session/load and keep sessions in $HOME/.fake-acp/sessions (default true);
|
|
8
8
|
// advertiseLoad / advertiseHttp: what initialize says, when it should differ from what the agent does;
|
|
9
9
|
// http: advertise MCP over HTTP (default true); the client then picks the transport;
|
|
10
|
-
// style: "goose" (titles
|
|
11
|
-
// (titles
|
|
10
|
+
// style: "goose" (titles <server>__<tool>, every tool asks permission, allow_always offered first) or "cursor"
|
|
11
|
+
// (titles <server>-<tool>: <tool>, <server> the name the client gave its MCP server; MCP and execute ask, edits do not; a refused native call still reports
|
|
12
12
|
// completed), or "goose-1.59" (as "goose", but titled as Goose 1.59.2 titles a call of an extension's tool:
|
|
13
13
|
// `agentrun: <tool, its underscores as spaces>`), or "antigravity" (an MCP call as agy 1.5.14 announces and asks
|
|
14
14
|
// about it: named `mcp_<server>_<tool>`, titled `Run mcp_<server>_<tool>`, <server> the name the client gave
|
|
@@ -25,18 +25,21 @@
|
|
|
25
25
|
// ignoreCancel: log session/cancel and go on as if it never came (an agent that keeps spending);
|
|
26
26
|
// keepMcpOnCancel: on session/cancel, answer the prompt `cancelled` at once and leave an MCP call in flight open;
|
|
27
27
|
// announce: with style "cursor", "late" (the default): an MCP call as Cursor 2026.11.13 announces it, a tool_call
|
|
28
|
-
// titled "MCP: tool" with no input, then a tool_call_update titled
|
|
29
|
-
// {providerIdentifier
|
|
30
|
-
//
|
|
28
|
+
// titled "MCP: tool" with no input, then a tool_call_update titled `<server>: <tool>` whose rawInput is
|
|
29
|
+
// {providerIdentifier: <server>, toolName, args}; its permission request is titled `<server>-<tool>: <tool>`,
|
|
30
|
+
// <server> the name the client gave its MCP server.
|
|
31
|
+
// "early": one tool_call titled `<server>-<tool>: <tool>` with the arguments as its rawInput, naming the
|
|
31
32
|
// tool in no field (no Cursor release measured sends this);
|
|
32
33
|
// lateTitle: with announce "late", that update's title instead (a release that words it otherwise);
|
|
33
34
|
// (a call step's `ask`, {kind, title}: what its permission request says instead of the call's own kind and title;)
|
|
34
35
|
// (a native step's `lateInput`: a tool_call_update after its tool_call with that rawInput, a release that echoes the
|
|
35
|
-
// model's arguments in a later update;
|
|
36
|
+
// model's arguments in a later update; in it and in the step's title, `<server>` is the name the client gave its MCP
|
|
37
|
+
// server, so a test can name the start's own server, whatever name the start gave it;)
|
|
36
38
|
// (a native step's `narrate`: text the agent writes after the call's tool_call and before it ends, as Cursor
|
|
37
39
|
// 2026.11.13 does;)
|
|
38
40
|
// (styles "goose" and "goose-1.59": each tool_call names its tool in _meta.goose.toolCall.toolName, as Goose 1.59.2
|
|
39
|
-
// does:
|
|
41
|
+
// does: `<server>__<tool>` for ours, a native step's `toolName` or `developer__<kind>` for the agent's own; a native
|
|
42
|
+
// step whose `toolName` the permission file always allows runs unasked, as Goose's would;)
|
|
40
43
|
// models: the models session/new and session/load list ({modelId, name}), the first current; session/set_model
|
|
41
44
|
// takes one of them and refuses any other;
|
|
42
45
|
// writeAuth: at session/new and session/load, write $HOME/.config/cursor/auth.json holding the sha256 of the
|
|
@@ -47,6 +50,10 @@
|
|
|
47
50
|
// elsewhere would: "key" the CURSOR_API_KEY as is, "base64" it in base64, "token" a JWT-shaped token (made
|
|
48
51
|
// here, no real one). For the key walk's red: a leak its guard must see;
|
|
49
52
|
// failNew: at session/new, print these words on stderr and exit 1 (Cursor's own refusals, the team admin's switch);
|
|
53
|
+
// keepsName: keep, with a session, the name the client gave its MCP server at session/new, and after session/load
|
|
54
|
+
// name and title our calls under that name, whatever name the load gave it (its MCP connection is the
|
|
55
|
+
// load's), as Cursor 2026.11.13 does: after a restart it titled `ar7e621c-web_fetch: web_fetch` though
|
|
56
|
+
// that start named the server `arc50d18`;
|
|
50
57
|
// cursorDirs: keep sessions and read the CLI config where Cursor 2026.11.13 does (cursor-config/dist/paths.js): its
|
|
51
58
|
// config directory is $CURSOR_CONFIG_DIR, else $XDG_CONFIG_HOME/cursor, else $HOME/.cursor; sessions in
|
|
52
59
|
// <dir>/acp-sessions, and an edit, write, delete or move refused unasked when <dir>/cli-config.json denies
|
|
@@ -110,7 +117,7 @@ const said = (event) => config.countFile && appendFileSync(config.countFile, `${
|
|
|
110
117
|
const save = (session) => {
|
|
111
118
|
if (!loads) return;
|
|
112
119
|
mkdirSync(store, { recursive: true });
|
|
113
|
-
writeFileSync(join(store, `${session.id}.json`), JSON.stringify({ id: session.id, history: session.history }));
|
|
120
|
+
writeFileSync(join(store, `${session.id}.json`), JSON.stringify({ id: session.id, history: session.history, ...(session.kept ? { server: session.kept } : {}) }));
|
|
114
121
|
if (config.grow) {
|
|
115
122
|
// A store that grows by appending, as SQLite's WAL does: `bytes` more at each save, and its shared-memory index
|
|
116
123
|
// rewritten beside it.
|
|
@@ -130,7 +137,7 @@ const pgid = (() => {
|
|
|
130
137
|
})();
|
|
131
138
|
said({ type: "start", env: Object.keys(process.env).sort(), home, cwd: process.cwd(), pgid, ...(config.cursorDirs ? { cursorDir, deniesWrite } : {}) });
|
|
132
139
|
/** The title of a call of our `tool`, the client's MCP server given as `server` (agy names it in its title). */
|
|
133
|
-
const titleOf = (tool, server = "agentrun") => (style === "cursor" ?
|
|
140
|
+
const titleOf = (tool, server = "agentrun") => (style === "cursor" ? `${server}-${tool}: ${tool}` : style === "antigravity" ? `Run mcp_${server}_${tool}` : style === "goose-1.59" ? `agentrun: ${tool.replace(/_/g, " ")}${config.titleSummary ? ` · ${config.titleSummary}` : ""}` : `${server}__${tool}`);
|
|
134
141
|
const late = style === "cursor" && config.announce !== "early";
|
|
135
142
|
/** 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
|
|
136
143
|
* builds (conversion.rs:65-91 at v1.59.2): `toolName` the name the model called, `extensionName` the part before `__`
|
|
@@ -254,11 +261,14 @@ async function mcpClient(server) {
|
|
|
254
261
|
return { request, close: () => child.kill() };
|
|
255
262
|
}
|
|
256
263
|
|
|
257
|
-
async function openSession(id, params, history) {
|
|
264
|
+
async function openSession(id, params, history, kept) {
|
|
258
265
|
const servers = params.mcpServers ?? [];
|
|
259
266
|
const server = servers.find((s) => s.name === "agentrun") ?? servers[0];
|
|
260
267
|
const mcp = server ? await mcpClient(server) : undefined;
|
|
261
268
|
const session = { id, history, mcp, server: server?.name ?? "agentrun", turn: undefined, system: params.systemPrompt ? text(params.systemPrompt.content ?? []).join("\n") : undefined };
|
|
269
|
+
// keepsName: the name the session was opened under, kept with it and used again after a load (Cursor's).
|
|
270
|
+
if (config.keepsName) session.kept = kept ?? session.server;
|
|
271
|
+
if (config.keepsName && kept) session.server = kept;
|
|
262
272
|
sessions.set(id, session);
|
|
263
273
|
return session;
|
|
264
274
|
}
|
|
@@ -298,17 +308,17 @@ async function takeTurn(client, session, prompt, signal) {
|
|
|
298
308
|
const reported = "toolSummary" in args ? args : { ...args, toolSummary: `Call ${s.call}` };
|
|
299
309
|
const update = style === "antigravity"
|
|
300
310
|
? { toolCallId: id, name: `mcp_${session.server}_${s.call}`, title: titleOf(s.call, session.server), kind: "other", status: "pending", rawInput: reported, args: reported }
|
|
301
|
-
: { toolCallId: id, title: titleOf(s.call), kind: "other", status: "pending", rawInput: args };
|
|
311
|
+
: { toolCallId: id, title: titleOf(s.call, session.server), kind: "other", status: "pending", rawInput: args };
|
|
302
312
|
const entry = { kind: "call", id, tool: s.call, args, status: "pending" };
|
|
303
313
|
session.history.push(entry);
|
|
304
314
|
save(session);
|
|
305
315
|
if (late) {
|
|
306
316
|
// Cursor 2026.11.13: the call is announced with no name, then named by an update, then asked about by its own title.
|
|
307
317
|
await notify({ sessionUpdate: "tool_call", toolCallId: id, title: "MCP: tool", kind: "other", status: "pending", rawInput: {} });
|
|
308
|
-
await notify({ sessionUpdate: "tool_call_update", toolCallId: id, title: config.lateTitle ??
|
|
318
|
+
await notify({ sessionUpdate: "tool_call_update", toolCallId: id, title: config.lateTitle ?? `${session.server}: ${s.call}`, rawInput: { providerIdentifier: session.server, toolName: s.call, args } });
|
|
309
319
|
await notify({ sessionUpdate: "tool_call_update", toolCallId: id, status: "in_progress" });
|
|
310
|
-
} else await notify({ sessionUpdate: "tool_call", ...update, ...gooseMeta(
|
|
311
|
-
if (askMcp && !alwaysAllowed.has(
|
|
320
|
+
} else await notify({ sessionUpdate: "tool_call", ...update, ...gooseMeta(`${session.server}__${s.call}`) });
|
|
321
|
+
if (askMcp && !alwaysAllowed.has(`${session.server}__${s.call}`) && !(await permitted(client, session, { ...(late ? { toolCallId: id, title: titleOf(s.call, session.server), kind: "other", status: "pending" } : update), ...(s.ask ?? {}) }))) {
|
|
312
322
|
if (signal.aborted) return { stopReason: "cancelled" };
|
|
313
323
|
entry.status = "failed";
|
|
314
324
|
entry.result = "the client refused the call";
|
|
@@ -349,16 +359,18 @@ async function takeTurn(client, session, prompt, signal) {
|
|
|
349
359
|
const id = `native_${step - 1}`;
|
|
350
360
|
// A model that, taking a step again (after a restart), writes another command for it (retitled).
|
|
351
361
|
const again = s.retitled?.length ? tally(step - 1) : 0;
|
|
352
|
-
const
|
|
362
|
+
const named = (value) => JSON.parse(JSON.stringify(value).replaceAll("<server>", session.server));
|
|
363
|
+
const title = again > 0 ? s.retitled[Math.min(again, s.retitled.length) - 1] : named(s.title ?? s.native);
|
|
353
364
|
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 } : {}) };
|
|
354
365
|
const entry = { kind: "native", id, title: update.title, status: "pending" };
|
|
355
366
|
session.history.push(entry);
|
|
356
367
|
save(session);
|
|
357
368
|
// {announce: false}: a permission request for a call no tool_call announced.
|
|
358
369
|
if (s.announce !== false) await notify({ sessionUpdate: "tool_call", ...update, ...gooseMeta(s.toolName ?? `developer__${s.native}`) });
|
|
359
|
-
if (s.lateInput) await notify({ sessionUpdate: "tool_call_update", toolCallId: id, rawInput: s.lateInput });
|
|
370
|
+
if (s.lateInput) await notify({ sessionUpdate: "tool_call_update", toolCallId: id, rawInput: named(s.lateInput) });
|
|
360
371
|
if (s.narrate) await notify({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: s.narrate } });
|
|
361
|
-
|
|
372
|
+
// Goose runs a tool its permission file always allows by the name it calls it (s.toolName), unasked.
|
|
373
|
+
const allowed = deniesWrite && EDITS.has(s.native) ? false : s.toolName !== undefined && alwaysAllowed.has(s.toolName) ? true : askNative.has(s.native) ? await permitted(client, session, update) : true;
|
|
362
374
|
if (signal.aborted) return { stopReason: "cancelled" };
|
|
363
375
|
if (allowed && config.nativeLog) appendFileSync(config.nativeLog, `${update.title}\n`);
|
|
364
376
|
entry.status = allowed ? "completed" : "failed";
|
|
@@ -469,9 +481,9 @@ const app = agent({ name: "fake-acp" })
|
|
|
469
481
|
needsSignIn();
|
|
470
482
|
const file = join(store, `${params.sessionId}.json`);
|
|
471
483
|
if (!loads || !existsSync(file)) throw RequestError.resourceNotFound(params.sessionId);
|
|
472
|
-
const { history } = JSON.parse(readFileSync(file, "utf8"));
|
|
473
|
-
const session = await openSession(params.sessionId, params, history);
|
|
474
|
-
said({ type: "load", sessionId: params.sessionId, steps: steps(history) });
|
|
484
|
+
const { history, server: kept } = JSON.parse(readFileSync(file, "utf8"));
|
|
485
|
+
const session = await openSession(params.sessionId, params, history, typeof kept === "string" ? kept : undefined);
|
|
486
|
+
said({ type: "load", sessionId: params.sessionId, steps: steps(history), names: params.mcpServers.map((s) => s.name) });
|
|
475
487
|
// The history goes back to the client as it happened: a client keeps it off its timeline.
|
|
476
488
|
for (const h of history) {
|
|
477
489
|
if (h.kind === "user") await client.notify("session/update", { sessionId: session.id, update: { sessionUpdate: "user_message_chunk", content: { type: "text", text: h.text } } });
|