@parcha/agentrun-harness-acp 0.1.0-beta.64 → 0.1.0-beta.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/calls.d.ts +9 -7
- package/dist/calls.js +9 -7
- package/dist/goose-facts.js +8 -4
- package/dist/harness.js +27 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/recipe.d.ts +12 -0
- package/dist/recipe.js +16 -0
- 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 +12 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
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
|
+
|
|
5
11
|
## 0.1.0-beta.64 (2026-11-26)
|
|
6
12
|
|
|
7
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 -->
|
package/dist/calls.d.ts
CHANGED
|
@@ -42,17 +42,19 @@ export declare function joinsByOne(announces: AcpAnnounces | undefined): boolean
|
|
|
42
42
|
* configuration) would say the same there. */
|
|
43
43
|
export declare function namesServer(announces: AcpAnnounces | undefined): boolean;
|
|
44
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
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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`. */
|
|
50
51
|
export declare function mcpServerName(announces: AcpAnnounces | undefined, tie?: string): string;
|
|
51
52
|
/** Whether a recipe gives our MCP server a name of each start's own (mcpServerName): one that declares the title tie
|
|
52
53
|
* (`tie`, quirks.permissionTie: the tie answers a request for one of our tools' calls without the host's gate, so
|
|
53
54
|
* another server must never pass for ours), whose prefix joins by one character (joinsByOne) or that reads the
|
|
54
|
-
* server's name from a field (namesServer). A title an earlier start's agent wrote names that start
|
|
55
|
-
* this one's
|
|
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). */
|
|
56
58
|
export declare function namedPerStart(announces: AcpAnnounces | undefined, tie?: string): boolean;
|
|
57
59
|
/** The most characters a tool's name may hold where the agent names it (agy's, as the model APIs' tool names: 64). */
|
|
58
60
|
export declare const TOOL_NAME_CAP = 64;
|
package/dist/calls.js
CHANGED
|
@@ -102,19 +102,21 @@ export function namesServer(announces) {
|
|
|
102
102
|
return announces?.server !== undefined;
|
|
103
103
|
}
|
|
104
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
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
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`. */
|
|
110
111
|
export function mcpServerName(announces, tie) {
|
|
111
112
|
return namedPerStart(announces, tie) ? `ar${randomBytes(3).toString("hex")}` : MCP_SERVER;
|
|
112
113
|
}
|
|
113
114
|
/** Whether a recipe gives our MCP server a name of each start's own (mcpServerName): one that declares the title tie
|
|
114
115
|
* (`tie`, quirks.permissionTie: the tie answers a request for one of our tools' calls without the host's gate, so
|
|
115
116
|
* another server must never pass for ours), whose prefix joins by one character (joinsByOne) or that reads the
|
|
116
|
-
* server's name from a field (namesServer). A title an earlier start's agent wrote names that start
|
|
117
|
-
* this one's
|
|
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). */
|
|
118
120
|
export function namedPerStart(announces, tie) {
|
|
119
121
|
return tie === "title" || joinsByOne(announces) || namesServer(announces);
|
|
120
122
|
}
|
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.js
CHANGED
|
@@ -23,6 +23,7 @@ import { announceCall, announcedField, announcesAt, CallIds, declaresProperty, j
|
|
|
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";
|
|
@@ -561,13 +562,6 @@ export function acpHarness(options, control) {
|
|
|
561
562
|
}
|
|
562
563
|
if (absent.length)
|
|
563
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`);
|
|
564
|
-
// A tool of ours the agent would name past its cap is not listed (capped); the run is told which, and goes on.
|
|
565
|
-
const serverName = mcpServerName(recipe.announces, recipe.quirks?.permissionTie);
|
|
566
|
-
if (capped.length) {
|
|
567
|
-
const words = toolsLeftOut(recipe.label ?? recipe.id, announcesAt(recipe.announces, serverName)?.prefix ?? "", capped);
|
|
568
|
-
log("acp: tools left out of the agent's listing, named past its cap", { tools: capped });
|
|
569
|
-
ctx.live({ type: "notice", text: words });
|
|
570
|
-
}
|
|
571
565
|
mkdirSync(base, { recursive: true, mode: 0o700 });
|
|
572
566
|
// Everything the agent kept goes: what it starts with is the session's records, never an earlier process's files.
|
|
573
567
|
for (const dir of [home, tmp]) {
|
|
@@ -577,6 +571,32 @@ export function acpHarness(options, control) {
|
|
|
577
571
|
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
578
572
|
const records = (await journal.read(STATE_STREAM)).map((r) => r.data);
|
|
579
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
|
+
}
|
|
580
600
|
const own = new Set();
|
|
581
601
|
// The recipe's allowFile (Goose's permission file): the tools this start lists, in the agent's own form, and nothing
|
|
582
602
|
// else, so the agent runs them unasked and our gate asks at the MCP call.
|
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
|
@@ -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
|
@@ -26,6 +26,15 @@ export const ALLOW_FILE_FORMS = Object.freeze(Object.keys(ALLOW_FORMS));
|
|
|
26
26
|
export function allowFileText(form, tools, server = MCP_SERVER) {
|
|
27
27
|
return ALLOW_FORMS[form](tools, server);
|
|
28
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;
|
|
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) {
|
|
31
40
|
const bare = path.startsWith("$HOME/") ? path.slice("$HOME/".length) : 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.66",
|
|
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.66",
|
|
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
|
{
|
|
@@ -50,6 +50,10 @@
|
|
|
50
50
|
// elsewhere would: "key" the CURSOR_API_KEY as is, "base64" it in base64, "token" a JWT-shaped token (made
|
|
51
51
|
// here, no real one). For the key walk's red: a leak its guard must see;
|
|
52
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`;
|
|
53
57
|
// cursorDirs: keep sessions and read the CLI config where Cursor 2026.11.13 does (cursor-config/dist/paths.js): its
|
|
54
58
|
// config directory is $CURSOR_CONFIG_DIR, else $XDG_CONFIG_HOME/cursor, else $HOME/.cursor; sessions in
|
|
55
59
|
// <dir>/acp-sessions, and an edit, write, delete or move refused unasked when <dir>/cli-config.json denies
|
|
@@ -113,7 +117,7 @@ const said = (event) => config.countFile && appendFileSync(config.countFile, `${
|
|
|
113
117
|
const save = (session) => {
|
|
114
118
|
if (!loads) return;
|
|
115
119
|
mkdirSync(store, { recursive: true });
|
|
116
|
-
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 } : {}) }));
|
|
117
121
|
if (config.grow) {
|
|
118
122
|
// A store that grows by appending, as SQLite's WAL does: `bytes` more at each save, and its shared-memory index
|
|
119
123
|
// rewritten beside it.
|
|
@@ -257,11 +261,14 @@ async function mcpClient(server) {
|
|
|
257
261
|
return { request, close: () => child.kill() };
|
|
258
262
|
}
|
|
259
263
|
|
|
260
|
-
async function openSession(id, params, history) {
|
|
264
|
+
async function openSession(id, params, history, kept) {
|
|
261
265
|
const servers = params.mcpServers ?? [];
|
|
262
266
|
const server = servers.find((s) => s.name === "agentrun") ?? servers[0];
|
|
263
267
|
const mcp = server ? await mcpClient(server) : undefined;
|
|
264
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;
|
|
265
272
|
sessions.set(id, session);
|
|
266
273
|
return session;
|
|
267
274
|
}
|
|
@@ -474,9 +481,9 @@ const app = agent({ name: "fake-acp" })
|
|
|
474
481
|
needsSignIn();
|
|
475
482
|
const file = join(store, `${params.sessionId}.json`);
|
|
476
483
|
if (!loads || !existsSync(file)) throw RequestError.resourceNotFound(params.sessionId);
|
|
477
|
-
const { history } = JSON.parse(readFileSync(file, "utf8"));
|
|
478
|
-
const session = await openSession(params.sessionId, params, history);
|
|
479
|
-
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) });
|
|
480
487
|
// The history goes back to the client as it happened: a client keeps it off its timeline.
|
|
481
488
|
for (const h of history) {
|
|
482
489
|
if (h.kind === "user") await client.notify("session/update", { sessionId: session.id, update: { sessionUpdate: "user_message_chunk", content: { type: "text", text: h.text } } });
|