@parcha/agentrun-harness-acp 0.1.0-beta.46 → 0.1.0-beta.47
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 +20 -0
- package/NOTICE +2 -0
- package/dist/adapter.d.ts +43 -0
- package/dist/adapter.js +198 -0
- package/dist/calls.d.ts +39 -0
- package/dist/calls.js +138 -0
- package/dist/cursor-facts.d.ts +27 -0
- package/dist/cursor-facts.js +55 -0
- package/dist/cursor.d.ts +36 -0
- package/dist/cursor.js +80 -0
- package/dist/facts.d.ts +39 -0
- package/dist/facts.js +34 -0
- package/dist/goose-facts.d.ts +6 -0
- package/dist/goose-facts.js +32 -0
- package/dist/goose.d.ts +29 -0
- package/dist/goose.js +67 -0
- package/dist/harness.d.ts +80 -0
- package/dist/harness.js +779 -0
- package/dist/host/agent.d.ts +32 -0
- package/dist/host/agent.js +57 -0
- package/dist/host/child.d.ts +14 -0
- package/dist/host/child.js +32 -0
- package/dist/host/goose-proxy.d.ts +57 -0
- package/dist/host/goose-proxy.js +332 -0
- package/dist/host/mcp-stdio.d.ts +1 -0
- package/dist/host/mcp-stdio.js +76 -0
- package/dist/host/mcp.d.ts +40 -0
- package/dist/host/mcp.js +210 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/pinned-binary.d.ts +63 -0
- package/dist/pinned-binary.js +152 -0
- package/dist/recipe.d.ts +75 -0
- package/dist/recipe.js +71 -0
- package/dist/state.d.ts +33 -0
- package/dist/state.js +157 -0
- package/package.json +2 -2
- package/recipes/cursor.json +21 -0
package/dist/host/mcp.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// The session's host tools as an MCP server on the loopback interface, for the ACP agent's MCP client. Copied from
|
|
2
|
+
// OpenCode's (packages/serve/src/harness-opencode/host/mcp.ts), not shared. Written for AgentRun.
|
|
3
|
+
//
|
|
4
|
+
// An ACP agent reaches a tool that is not its own only through MCP. The adapter gives it this one server, `agentrun`, on
|
|
5
|
+
// session/new, so the model is offered the host's tools under the agent's own name for an MCP tool (Goose's
|
|
6
|
+
// `agentrun__<name>`, Cursor's `agentrun-<name>: <name>`). The transport is MCP's streamable HTTP, the subset an agent's
|
|
7
|
+
// client uses (an agent that takes MCP over stdio only reaches it through the adapter's bridge, mcp-stdio.ts):
|
|
8
|
+
// - `POST /mcp` with one JSON-RPC message and the session's own key as a bearer token (compared in constant time):
|
|
9
|
+
// `initialize`, `ping` and `tools/list` are answered as JSON, a notification gets 202, and `tools/call` is answered as
|
|
10
|
+
// an event stream that carries a progress notification every `progressMs` while the call runs, then its result. A call
|
|
11
|
+
// may wait on a person (`ask_person`) far longer than an MCP client's request timeout, and a client that honours
|
|
12
|
+
// progress resets that timeout on each notification.
|
|
13
|
+
// - `GET /mcp` (a stream of the server's own notifications, which this server never sends) is 405, as the
|
|
14
|
+
// specification allows; any other path or method is 404.
|
|
15
|
+
// The server never runs a tool itself: `call` does, through the kernel's tool bridge, so each call is an effect whose
|
|
16
|
+
// intent is durable before it runs. A client that goes away before the answer aborts the call's signal.
|
|
17
|
+
import { createServer } from "node:http";
|
|
18
|
+
import { sameKey } from "@parcha/agentrun-kernel/host";
|
|
19
|
+
/** How long close() waits for the calls it aborted to settle. */
|
|
20
|
+
export const CLOSE_SETTLE_MS = 5_000;
|
|
21
|
+
/** The MCP protocol versions this server speaks; a client's own is answered in kind when it is one of them. */
|
|
22
|
+
const VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
|
|
23
|
+
const MAX_BODY = 8 * 1024 * 1024;
|
|
24
|
+
/** Where the server listens and the agent connects to it: this machine only, on the port the system chose. */
|
|
25
|
+
const ADDRESS = "http://127.0.0.1/mcp"; // key-gate: loopback-rule the MCP server of the ACP adapter listens here and the agent connects here, 127.0.0.1 only
|
|
26
|
+
const isPlain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
function json(res, status, body) {
|
|
28
|
+
if (body === undefined)
|
|
29
|
+
return void res.writeHead(status).end();
|
|
30
|
+
const text = JSON.stringify(body);
|
|
31
|
+
res.writeHead(status, { "content-type": "application/json", "content-length": Buffer.byteLength(text) }).end(text);
|
|
32
|
+
}
|
|
33
|
+
const error = (id, code, message) => ({ jsonrpc: "2.0", id: id ?? null, error: { code, message } });
|
|
34
|
+
async function bodyOf(req) {
|
|
35
|
+
let size = 0;
|
|
36
|
+
const chunks = [];
|
|
37
|
+
for await (const chunk of req) {
|
|
38
|
+
size += chunk.length;
|
|
39
|
+
if (size > MAX_BODY)
|
|
40
|
+
return undefined;
|
|
41
|
+
chunks.push(chunk);
|
|
42
|
+
}
|
|
43
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
44
|
+
}
|
|
45
|
+
/** Start the server on the loopback interface, on a port of the system's choosing. */
|
|
46
|
+
export async function startMcpServer(options) {
|
|
47
|
+
if (!options.key)
|
|
48
|
+
throw new Error("acp: the MCP server needs the session's key");
|
|
49
|
+
const tools = options.tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.inputSchema }));
|
|
50
|
+
const known = new Set(tools.map((t) => t.name));
|
|
51
|
+
const progressMs = options.progressMs ?? 15_000;
|
|
52
|
+
// Each call under way: its abort, and what stops its progress timer.
|
|
53
|
+
const open = new Set();
|
|
54
|
+
// Each call's own run (options.call), until it settles: what settle() and close() wait for.
|
|
55
|
+
const running = new Set();
|
|
56
|
+
const settle = async (ms) => {
|
|
57
|
+
if (running.size === 0)
|
|
58
|
+
return true;
|
|
59
|
+
let timer;
|
|
60
|
+
const done = await Promise.race([Promise.allSettled([...running]).then(() => true), new Promise((resolve) => (timer = setTimeout(() => resolve(false), ms)))]);
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
return done && running.size === 0;
|
|
63
|
+
};
|
|
64
|
+
let closed = false;
|
|
65
|
+
const server = createServer((req, res) => {
|
|
66
|
+
void handle(req, res).catch((err) => {
|
|
67
|
+
options.log?.("acp: the MCP server failed a request", { error: String(err?.message ?? err).slice(0, 200) });
|
|
68
|
+
if (!res.headersSent)
|
|
69
|
+
json(res, 500, error(null, -32603, "internal error"));
|
|
70
|
+
else
|
|
71
|
+
res.end();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
async function handle(req, res) {
|
|
75
|
+
const path = (req.url ?? "").split("?")[0];
|
|
76
|
+
if (path !== "/mcp")
|
|
77
|
+
return json(res, 404);
|
|
78
|
+
const auth = String(req.headers.authorization ?? "");
|
|
79
|
+
if (!sameKey(auth.startsWith("Bearer ") ? auth.slice(7) : "", options.key))
|
|
80
|
+
return json(res, 401);
|
|
81
|
+
if (req.method === "GET")
|
|
82
|
+
return void res.writeHead(405, { allow: "POST" }).end();
|
|
83
|
+
if (req.method === "DELETE")
|
|
84
|
+
return json(res, 200);
|
|
85
|
+
if (req.method !== "POST")
|
|
86
|
+
return json(res, 404);
|
|
87
|
+
if (closed)
|
|
88
|
+
return json(res, 503);
|
|
89
|
+
const text = await bodyOf(req);
|
|
90
|
+
if (text === undefined)
|
|
91
|
+
return json(res, 413, error(null, -32600, "the request is too large"));
|
|
92
|
+
let message;
|
|
93
|
+
try {
|
|
94
|
+
message = JSON.parse(text);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return json(res, 400, error(null, -32700, "the body is not JSON"));
|
|
98
|
+
}
|
|
99
|
+
if (!isPlain(message) || message.jsonrpc !== "2.0" || typeof message.method !== "string") {
|
|
100
|
+
// A response or a batch: this server sends no requests and takes one message at a time.
|
|
101
|
+
return json(res, 400, error(isPlain(message) ? message.id : null, -32600, "one JSON-RPC request or notification at a time"));
|
|
102
|
+
}
|
|
103
|
+
const { id, method } = message;
|
|
104
|
+
const params = isPlain(message.params) ? message.params : {};
|
|
105
|
+
if (id === undefined)
|
|
106
|
+
return json(res, 202);
|
|
107
|
+
switch (method) {
|
|
108
|
+
case "initialize": {
|
|
109
|
+
const asked = typeof params.protocolVersion === "string" ? params.protocolVersion : "";
|
|
110
|
+
const protocolVersion = VERSIONS.includes(asked) ? asked : VERSIONS[1];
|
|
111
|
+
return json(res, 200, { jsonrpc: "2.0", id, result: { protocolVersion, capabilities: { tools: { listChanged: false } }, serverInfo: { name: "agentrun", version: "1" } } });
|
|
112
|
+
}
|
|
113
|
+
case "ping":
|
|
114
|
+
return json(res, 200, { jsonrpc: "2.0", id, result: {} });
|
|
115
|
+
case "tools/list":
|
|
116
|
+
return json(res, 200, { jsonrpc: "2.0", id, result: { tools } });
|
|
117
|
+
case "tools/call":
|
|
118
|
+
return call(id, params, req, res);
|
|
119
|
+
default:
|
|
120
|
+
return json(res, 200, error(id, -32601, `no method ${method.slice(0, 80)}`));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async function call(id, params, req, res) {
|
|
124
|
+
const name = typeof params.name === "string" ? params.name : "";
|
|
125
|
+
if (!known.has(name))
|
|
126
|
+
return json(res, 200, { jsonrpc: "2.0", id, result: { content: [{ type: "text", text: `unknown tool: ${name.slice(0, 80)}` }], isError: true } });
|
|
127
|
+
const args = isPlain(params.arguments) ? params.arguments : {};
|
|
128
|
+
const meta = isPlain(params._meta) ? params._meta : {};
|
|
129
|
+
const token = typeof meta.progressToken === "string" || typeof meta.progressToken === "number" ? meta.progressToken : undefined;
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
let timer;
|
|
132
|
+
// Its progress stops, and nothing more is written, once its client is gone or the server has let it go. The call
|
|
133
|
+
// itself still runs until it settles (`running`), so the drive's settle waits for its real outcome.
|
|
134
|
+
let gone = false;
|
|
135
|
+
const release = () => {
|
|
136
|
+
gone = true;
|
|
137
|
+
if (timer)
|
|
138
|
+
clearInterval(timer);
|
|
139
|
+
timer = undefined;
|
|
140
|
+
};
|
|
141
|
+
const entry = { controller, release };
|
|
142
|
+
open.add(entry);
|
|
143
|
+
// The client going away (its abort, its process ending) stops the call; a finished answer does not.
|
|
144
|
+
let answered = false;
|
|
145
|
+
res.on("close", () => {
|
|
146
|
+
release();
|
|
147
|
+
if (!answered)
|
|
148
|
+
controller.abort(new Error("the MCP client went away before the answer"));
|
|
149
|
+
});
|
|
150
|
+
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", connection: "keep-alive" });
|
|
151
|
+
const send = (body) => void (gone || res.write(`event: message\ndata: ${JSON.stringify(body)}\n\n`));
|
|
152
|
+
let progress = 0;
|
|
153
|
+
if (token !== undefined)
|
|
154
|
+
timer = setInterval(() => {
|
|
155
|
+
progress += 1;
|
|
156
|
+
send({ jsonrpc: "2.0", method: "notifications/progress", params: { progressToken: token, progress } });
|
|
157
|
+
}, progressMs);
|
|
158
|
+
try {
|
|
159
|
+
const work = options.call(name, args, controller.signal);
|
|
160
|
+
running.add(work);
|
|
161
|
+
void work.then(() => running.delete(work), () => running.delete(work));
|
|
162
|
+
const answer = await work;
|
|
163
|
+
const content = [{ type: "text", text: answer.text }, ...(answer.images ?? []).map((image) => ({ type: "image", data: image.data, mimeType: image.mimeType }))];
|
|
164
|
+
answered = true;
|
|
165
|
+
send({ jsonrpc: "2.0", id, result: { content, isError: answer.isError } });
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
answered = true;
|
|
169
|
+
// The drive is stopping (an interrupt, a halt): the call has no answer the log holds, so none is given.
|
|
170
|
+
send(error(id, -32603, String(err?.message ?? err).slice(0, 500)));
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
// A call the server let go (close()) settles here to nothing: its entry is gone, and so is its response.
|
|
174
|
+
const ended = gone;
|
|
175
|
+
release();
|
|
176
|
+
open.delete(entry);
|
|
177
|
+
if (!ended)
|
|
178
|
+
res.end();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
await new Promise((resolve, reject) => {
|
|
182
|
+
server.once("error", reject);
|
|
183
|
+
server.listen(0, new URL(ADDRESS).hostname, () => resolve());
|
|
184
|
+
});
|
|
185
|
+
const address = server.address();
|
|
186
|
+
if (!address || typeof address === "string")
|
|
187
|
+
throw new Error("acp: the MCP server has no port");
|
|
188
|
+
const url = new URL(ADDRESS);
|
|
189
|
+
url.port = String(address.port);
|
|
190
|
+
return {
|
|
191
|
+
url: url.href,
|
|
192
|
+
settle,
|
|
193
|
+
async close() {
|
|
194
|
+
if (closed)
|
|
195
|
+
return;
|
|
196
|
+
closed = true;
|
|
197
|
+
for (const { controller } of open)
|
|
198
|
+
controller.abort(new Error("the session's MCP server closed"));
|
|
199
|
+
if (!(await settle(CLOSE_SETTLE_MS)))
|
|
200
|
+
options.log?.("acp: a host tool call was still running when the MCP server closed", { running: running.size });
|
|
201
|
+
// Past the window, a call that ignores its abort is let go: nothing of it stays live in this process.
|
|
202
|
+
for (const { release } of open)
|
|
203
|
+
release();
|
|
204
|
+
open.clear();
|
|
205
|
+
running.clear();
|
|
206
|
+
server.closeAllConnections?.();
|
|
207
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { acpAdapter, type AcpAdapterOptions, type AcpProxy, type AcpProxySession } from "./adapter.js";
|
|
2
|
+
export { ACP_CODES, acpFacts, type AcpFacts } from "./facts.js";
|
|
3
|
+
export { homePath, MODEL_ID, recipeProblems, RESERVED_ENV, type AcpBilling, type AcpRecipe, type AcpRefusal } from "./recipe.js";
|
|
4
|
+
export { CALL_STREAM, contextNote, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
5
|
+
export { STATE_STREAM, type StateRecord } from "./state.js";
|
|
6
|
+
export type { ConfineChild } from "./host/child.js";
|
|
7
|
+
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
|
8
|
+
export { gooseAdapter, gooseRecipe, recipeFile, type AcpRecipeFile, type AcpRecipeName, type GooseAdapterOptions, type GooseRecipeOptions } from "./goose.js";
|
|
9
|
+
export { applyGoose, GOOSE_BETAS, GOOSE_OWN_TOOLS, gooseProxy, goosePolicy, gooseRoutes, gooseToolName, gooseUsage, limitGooseOutput, type GoosePolicyOptions, type GooseProvider, type GooseProxyOptions } from "./host/goose-proxy.js";
|
|
10
|
+
export { acpPlatform, AcpBinaryRefused, CURSOR_PIN, GOOSE_PIN, treeDigest, verifyPinnedBinary, verifyPinnedBinaryAsync, verifyPinnedTree, type AcpArchivePin, type AcpBinaryPin, type AcpPlatform } from "./pinned-binary.js";
|
|
11
|
+
export { CURSOR_CODES, CURSOR_INSTALL, CURSOR_LIMITS, cursorCard, cursorFacts, type CursorLimits } from "./cursor-facts.js";
|
|
12
|
+
export { cursorAdapter, cursorRecipe, cursorRelease, cursorRootOf, type CursorAdapterOptions, type CursorRecipeOptions, type CursorRelease } from "./cursor.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Any Agent Client Protocol agent as an AgentRun harness. Written for AgentRun.
|
|
2
|
+
export { acpAdapter } from "./adapter.js";
|
|
3
|
+
export { ACP_CODES, acpFacts } from "./facts.js";
|
|
4
|
+
export { homePath, MODEL_ID, recipeProblems, RESERVED_ENV } from "./recipe.js";
|
|
5
|
+
export { CALL_STREAM, contextNote, MODEL_STREAM, PERMISSION_STREAM, PROMPT_STREAM, SESSION_STREAM, sentSubmissions, TOOLS_STREAM } from "./harness.js";
|
|
6
|
+
export { STATE_STREAM } from "./state.js";
|
|
7
|
+
export { GOOSE_INSTALL, GOOSE_NOT_INSTALLED, gooseFacts } from "./goose-facts.js";
|
|
8
|
+
export { gooseAdapter, gooseRecipe, recipeFile } from "./goose.js";
|
|
9
|
+
export { applyGoose, GOOSE_BETAS, GOOSE_OWN_TOOLS, gooseProxy, goosePolicy, gooseRoutes, gooseToolName, gooseUsage, limitGooseOutput } from "./host/goose-proxy.js";
|
|
10
|
+
export { acpPlatform, AcpBinaryRefused, CURSOR_PIN, GOOSE_PIN, treeDigest, verifyPinnedBinary, verifyPinnedBinaryAsync, verifyPinnedTree } from "./pinned-binary.js";
|
|
11
|
+
export { CURSOR_CODES, CURSOR_INSTALL, CURSOR_LIMITS, cursorCard, cursorFacts } from "./cursor-facts.js";
|
|
12
|
+
export { cursorAdapter, cursorRecipe, cursorRelease, cursorRootOf } from "./cursor.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** A platform as the ACP registry names it (`distribution.binary.<platform>`). */
|
|
2
|
+
export type AcpPlatform = "darwin-aarch64" | "darwin-x86_64" | "linux-aarch64" | "linux-x86_64" | "windows-aarch64" | "windows-x86_64";
|
|
3
|
+
/** One platform's release of a pinned agent. */
|
|
4
|
+
export interface AcpArchivePin {
|
|
5
|
+
/** The archive's URL, as the registry lists it. */
|
|
6
|
+
readonly url: string;
|
|
7
|
+
/** How it is packed. */
|
|
8
|
+
readonly format: "tar.bz2" | "tar.gz" | "zip";
|
|
9
|
+
/** The archive's sha256, as the registry lists it. */
|
|
10
|
+
readonly sha256: string;
|
|
11
|
+
/** The binary's path inside the archive (the registry's `cmd`). */
|
|
12
|
+
readonly cmd: string;
|
|
13
|
+
/** The sha256 of the binary the archive unpacks to, where it was measured. Absent: unmeasured on this platform, so an
|
|
14
|
+
* installer records the first one it unpacks from the verified archive (agentrun-serve's binaryRecord). */
|
|
15
|
+
readonly binarySha256?: string;
|
|
16
|
+
/** The digest of every file the archive unpacks to (treeDigest), for an agent whose binary is a launcher of the code
|
|
17
|
+
* beside it (Cursor's `cursor-agent` runs its own `node` on `index.js` and a hundred chunks): checked by the installer
|
|
18
|
+
* and again before every start, so no file of it changes unseen. */
|
|
19
|
+
readonly treeSha256?: string;
|
|
20
|
+
}
|
|
21
|
+
/** A pinned release of an ACP agent. */
|
|
22
|
+
export interface AcpBinaryPin {
|
|
23
|
+
/** The agent's id in the registry. */
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly version: string;
|
|
26
|
+
/** Where its digests were read, and when (ISO 8601). */
|
|
27
|
+
readonly source: {
|
|
28
|
+
readonly url: string;
|
|
29
|
+
readonly readAt: string;
|
|
30
|
+
};
|
|
31
|
+
readonly archives: Readonly<Partial<Record<AcpPlatform, AcpArchivePin>>>;
|
|
32
|
+
}
|
|
33
|
+
/** Goose 1.59.2, as the registry listed it when read (`source`). The linux-x86_64 binary's digest was measured on the
|
|
34
|
+
* binary its verified archive unpacked to; the darwin-aarch64 archive is pinned by the registry's digest alone. */
|
|
35
|
+
export declare const GOOSE_PIN: AcpBinaryPin;
|
|
36
|
+
/** Cursor's CLI 2026.11.13 (build eacade1), the release its ACP registry entry pointed to when read (`source`). The
|
|
37
|
+
* registry lists no digest for Cursor, so the archive is pinned by the first sha256 seen for it (2026-11-16, harness S0;
|
|
38
|
+
* downloaded again 2026-11-19 and the same), its launcher and its whole tree by what that archive unpacked to. A drift
|
|
39
|
+
* of any of them is refused. A new pin takes the key walk on it (test/cursor-key-walk.test.mjs, on the real binary and
|
|
40
|
+
* the owner's key, AGENTRUN_RECORD_CURSOR_WALK=1): Cursor's credential design rests on Cursor tolerating a failed save,
|
|
41
|
+
* and CI refuses a pin cursor-walk.json does not name. */
|
|
42
|
+
export declare const CURSOR_PIN: AcpBinaryPin;
|
|
43
|
+
/** This host's platform as the registry names it, or undefined for one it does not list. */
|
|
44
|
+
export declare function acpPlatform(platform?: string, arch?: string): AcpPlatform | undefined;
|
|
45
|
+
/** A binary the adapter will not start: its code says why (ACP_CODES.binaryMismatch, binaryUnreadable). */
|
|
46
|
+
export declare class AcpBinaryRefused extends Error {
|
|
47
|
+
readonly code: string;
|
|
48
|
+
constructor(code: string, message: string);
|
|
49
|
+
}
|
|
50
|
+
/** Refuses the binary at `path` unless its sha256 is `sha256`. Reads it (once per file identity in this process),
|
|
51
|
+
* never runs it. */
|
|
52
|
+
export declare function verifyPinnedBinary(path: string, sha256: string): void;
|
|
53
|
+
/** verifyPinnedBinary without holding the event loop: the host's own check, while it goes on answering. */
|
|
54
|
+
export declare function verifyPinnedBinaryAsync(path: string, sha256: string): Promise<void>;
|
|
55
|
+
/** The digest of the tree at `root`: the sha256 of one line per entry under it, in byte order of its path from `root`
|
|
56
|
+
* (`/`-separated): `<path>\0file\0<sha256>\n` for a file, `<path>\0link\0<target>\n` for a symbolic link, and
|
|
57
|
+
* `<path>\0dir\n` for a directory. Modes and times are not in it. Each file's sha256 is the kernel's, kept once per
|
|
58
|
+
* file identity in this process, so a tree checked before is read again only where a file changed. Off the event loop;
|
|
59
|
+
* rejects on anything else under `root` (a socket, a device). */
|
|
60
|
+
export declare function treeDigest(root: string): Promise<string>;
|
|
61
|
+
/** Refuses the tree at `root` unless its digest (treeDigest) is `sha256`: ACP_CODES.binaryMismatch, or binaryUnreadable
|
|
62
|
+
* when it cannot be read. Never runs anything in it. */
|
|
63
|
+
export declare function verifyPinnedTree(root: string, sha256: string): Promise<void>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// An ACP agent's binary, checked against what the adapter was tested with, before it is ever started. Written for
|
|
2
|
+
// AgentRun.
|
|
3
|
+
// - A pin is a release as the public ACP registry lists it (https://cdn.agentclientprotocol.com/registry/v1/latest/
|
|
4
|
+
// registry.json): its version and, per platform, its archive's URL and sha256, and the sha256 of the binary the archive
|
|
5
|
+
// unpacks to where it was measured. An installer verifies the archive, then the binary; a host checks the binary
|
|
6
|
+
// again at each start (`verifyPinnedBinary`).
|
|
7
|
+
// - An agent the registry lists with no digest (Cursor) is pinned here by what its first download held; a binary no
|
|
8
|
+
// pin names has its first digest recorded by the server's installer alone (agentrun-serve, harness-archive.ts
|
|
9
|
+
// installArchive's binaryRecord), the one first-seen path.
|
|
10
|
+
// Every check reads the file's bytes (the kernel's chunked sha256, kept once per file identity) and never executes it.
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import { lstat, readdir, readlink } from "node:fs/promises";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { checkedOnce, checkedOnceAsync } from "@parcha/agentrun-kernel/host";
|
|
15
|
+
import { ACP_CODES } from "./facts.js";
|
|
16
|
+
/** Goose 1.59.2, as the registry listed it when read (`source`). The linux-x86_64 binary's digest was measured on the
|
|
17
|
+
* binary its verified archive unpacked to; the darwin-aarch64 archive is pinned by the registry's digest alone. */
|
|
18
|
+
export const GOOSE_PIN = Object.freeze({
|
|
19
|
+
id: "goose",
|
|
20
|
+
version: "1.59.2",
|
|
21
|
+
source: Object.freeze({ url: "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json", readAt: "2026-11-17T22:28:02Z" }),
|
|
22
|
+
archives: Object.freeze({
|
|
23
|
+
"linux-x86_64": Object.freeze({
|
|
24
|
+
url: "https://github.com/block/goose/releases/download/v1.59.2/goose-x86_64-unknown-linux-gnu.tar.bz2",
|
|
25
|
+
format: "tar.bz2",
|
|
26
|
+
sha256: "36efe207ae4f8de3030ed8fdcfe3b7c5d13f23d6cb73d6fde747543f022ce218",
|
|
27
|
+
cmd: "./goose",
|
|
28
|
+
binarySha256: "b90833d7f1e8f9aa36e163a8f3d27fdd69d462ac9b4a68105a091e1a2da56993",
|
|
29
|
+
}),
|
|
30
|
+
"darwin-aarch64": Object.freeze({
|
|
31
|
+
url: "https://github.com/block/goose/releases/download/v1.59.2/goose-aarch64-apple-darwin.tar.bz2",
|
|
32
|
+
format: "tar.bz2",
|
|
33
|
+
sha256: "a4eac98999639741ee5a4cc7a3043952a4a22fc2004b7340e34ec927df0e8257",
|
|
34
|
+
cmd: "./goose",
|
|
35
|
+
}),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
/** Cursor's CLI 2026.11.13 (build eacade1), the release its ACP registry entry pointed to when read (`source`). The
|
|
39
|
+
* registry lists no digest for Cursor, so the archive is pinned by the first sha256 seen for it (2026-11-16, harness S0;
|
|
40
|
+
* downloaded again 2026-11-19 and the same), its launcher and its whole tree by what that archive unpacked to. A drift
|
|
41
|
+
* of any of them is refused. A new pin takes the key walk on it (test/cursor-key-walk.test.mjs, on the real binary and
|
|
42
|
+
* the owner's key, AGENTRUN_RECORD_CURSOR_WALK=1): Cursor's credential design rests on Cursor tolerating a failed save,
|
|
43
|
+
* and CI refuses a pin cursor-walk.json does not name. */
|
|
44
|
+
export const CURSOR_PIN = Object.freeze({
|
|
45
|
+
id: "cursor",
|
|
46
|
+
version: "2026.11.13-eacade1",
|
|
47
|
+
source: Object.freeze({ url: "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json", readAt: "2026-11-16T21:22:32Z" }),
|
|
48
|
+
archives: Object.freeze({
|
|
49
|
+
"linux-x86_64": Object.freeze({
|
|
50
|
+
url: "https://downloads.cursor.com/lab/2026.11.13-eacade1/linux/x64/agent-cli-package.tar.gz",
|
|
51
|
+
format: "tar.gz",
|
|
52
|
+
sha256: "c02e4321f20d691ee03af94d29948dc3a81c6c34e7328da7bb1afade4c75812f",
|
|
53
|
+
cmd: "./dist-package/cursor-agent",
|
|
54
|
+
binarySha256: "2ccc9a8e167797641448b5e5c936f006ba137a2555f117f38c5eb76a5238a233",
|
|
55
|
+
treeSha256: "b224cfc7d2aa702ae4c9335fba6a4fc4b04250584bf615a8dcefa946ac5e64f6",
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
/** This host's platform as the registry names it, or undefined for one it does not list. */
|
|
60
|
+
export function acpPlatform(platform = process.platform, arch = process.arch) {
|
|
61
|
+
const os = platform === "darwin" ? "darwin" : platform === "linux" ? "linux" : platform === "win32" ? "windows" : undefined;
|
|
62
|
+
const cpu = arch === "arm64" ? "aarch64" : arch === "x64" ? "x86_64" : undefined;
|
|
63
|
+
return os && cpu ? `${os}-${cpu}` : undefined;
|
|
64
|
+
}
|
|
65
|
+
/** A binary the adapter will not start: its code says why (ACP_CODES.binaryMismatch, binaryUnreadable). */
|
|
66
|
+
export class AcpBinaryRefused extends Error {
|
|
67
|
+
code;
|
|
68
|
+
constructor(code, message) {
|
|
69
|
+
super(`${code}: ${message}`);
|
|
70
|
+
this.code = code;
|
|
71
|
+
this.name = "AcpBinaryRefused";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
75
|
+
/** The check's one step: the file's sha256. */
|
|
76
|
+
const digestOf = (path) => function* () {
|
|
77
|
+
return yield { kind: "sha256", path };
|
|
78
|
+
};
|
|
79
|
+
/** Why reading `path` failed, as a refusal. */
|
|
80
|
+
const unreadable = (path, error) => new AcpBinaryRefused(ACP_CODES.binaryUnreadable, `the binary at ${path} cannot be read (${String(error?.code ?? error?.message ?? error)})`);
|
|
81
|
+
/** Refuses the binary at `path` unless its sha256 is `sha256`. Reads it (once per file identity in this process),
|
|
82
|
+
* never runs it. */
|
|
83
|
+
export function verifyPinnedBinary(path, sha256) {
|
|
84
|
+
if (!SHA256.test(sha256))
|
|
85
|
+
throw new Error(`acp: the pinned sha256 ${JSON.stringify(sha256)} is not 64 lowercase hex digits`);
|
|
86
|
+
let found;
|
|
87
|
+
try {
|
|
88
|
+
found = checkedOnce(path, sha256, digestOf(path), (d) => d === sha256);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw unreadable(path, error);
|
|
92
|
+
}
|
|
93
|
+
if (found !== sha256)
|
|
94
|
+
throw new AcpBinaryRefused(ACP_CODES.binaryMismatch, `the binary at ${path} has sha256 ${found}, and the pin is ${sha256}`);
|
|
95
|
+
}
|
|
96
|
+
/** verifyPinnedBinary without holding the event loop: the host's own check, while it goes on answering. */
|
|
97
|
+
export async function verifyPinnedBinaryAsync(path, sha256) {
|
|
98
|
+
if (!SHA256.test(sha256))
|
|
99
|
+
throw new Error(`acp: the pinned sha256 ${JSON.stringify(sha256)} is not 64 lowercase hex digits`);
|
|
100
|
+
let found;
|
|
101
|
+
try {
|
|
102
|
+
found = await checkedOnceAsync(path, sha256, digestOf(path), (d) => d === sha256);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw unreadable(path, error);
|
|
106
|
+
}
|
|
107
|
+
if (found !== sha256)
|
|
108
|
+
throw new AcpBinaryRefused(ACP_CODES.binaryMismatch, `the binary at ${path} has sha256 ${found}, and the pin is ${sha256}`);
|
|
109
|
+
}
|
|
110
|
+
/** The digest of the tree at `root`: the sha256 of one line per entry under it, in byte order of its path from `root`
|
|
111
|
+
* (`/`-separated): `<path>\0file\0<sha256>\n` for a file, `<path>\0link\0<target>\n` for a symbolic link, and
|
|
112
|
+
* `<path>\0dir\n` for a directory. Modes and times are not in it. Each file's sha256 is the kernel's, kept once per
|
|
113
|
+
* file identity in this process, so a tree checked before is read again only where a file changed. Off the event loop;
|
|
114
|
+
* rejects on anything else under `root` (a socket, a device). */
|
|
115
|
+
export async function treeDigest(root) {
|
|
116
|
+
const lines = [];
|
|
117
|
+
const walk = async (dir, prefix) => {
|
|
118
|
+
for (const name of (await readdir(dir)).sort()) {
|
|
119
|
+
const path = join(dir, name);
|
|
120
|
+
const rel = prefix ? `${prefix}/${name}` : name;
|
|
121
|
+
const entry = await lstat(path);
|
|
122
|
+
if (entry.isSymbolicLink())
|
|
123
|
+
lines.push(`${rel}\0link\0${await readlink(path)}\n`);
|
|
124
|
+
else if (entry.isDirectory()) {
|
|
125
|
+
lines.push(`${rel}\0dir\n`);
|
|
126
|
+
await walk(path, rel);
|
|
127
|
+
}
|
|
128
|
+
else if (entry.isFile())
|
|
129
|
+
lines.push(`${rel}\0file\0${await checkedOnceAsync(path, "tree", digestOf(path), () => true)}\n`);
|
|
130
|
+
else
|
|
131
|
+
throw new Error(`${path} is neither a file, a directory nor a link`);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
await walk(root, "");
|
|
135
|
+
lines.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
136
|
+
return createHash("sha256").update(lines.join("")).digest("hex");
|
|
137
|
+
}
|
|
138
|
+
/** Refuses the tree at `root` unless its digest (treeDigest) is `sha256`: ACP_CODES.binaryMismatch, or binaryUnreadable
|
|
139
|
+
* when it cannot be read. Never runs anything in it. */
|
|
140
|
+
export async function verifyPinnedTree(root, sha256) {
|
|
141
|
+
if (!SHA256.test(sha256))
|
|
142
|
+
throw new Error(`acp: the pinned tree sha256 ${JSON.stringify(sha256)} is not 64 lowercase hex digits`);
|
|
143
|
+
let found;
|
|
144
|
+
try {
|
|
145
|
+
found = await treeDigest(root);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
throw new AcpBinaryRefused(ACP_CODES.binaryUnreadable, `the files at ${root} cannot be read (${String(error?.code ?? error?.message ?? error)})`);
|
|
149
|
+
}
|
|
150
|
+
if (found !== sha256)
|
|
151
|
+
throw new AcpBinaryRefused(ACP_CODES.binaryMismatch, `the files at ${root} have the tree sha256 ${found}, and the pin is ${sha256}: one of them changed since it was installed`);
|
|
152
|
+
}
|
package/dist/recipe.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Who pays for the agent's model requests. `plan`: the vendor bills the owner's plan (Cursor), no request reaches us, so
|
|
2
|
+
* the adapter itself stops the run at these limits. `proxy`: the agent's model goes through the host's proxy, which the
|
|
3
|
+
* adapter's `proxy` option starts for each agent process (Goose, S3). */
|
|
4
|
+
export type AcpBilling = {
|
|
5
|
+
readonly kind: "plan";
|
|
6
|
+
readonly maxTurns: number;
|
|
7
|
+
readonly maxToolCalls: number;
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: "proxy";
|
|
10
|
+
};
|
|
11
|
+
/** One of the agent's own refusals: the words it says (`says`, matched as they are), the code a host reads, and the
|
|
12
|
+
* words the host says instead. */
|
|
13
|
+
export type AcpRefusal = {
|
|
14
|
+
readonly says: string;
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly words: string;
|
|
17
|
+
};
|
|
18
|
+
/** A model id as an agent lists one (`gpt-5.4-nano[reasoning=medium]`): one line, no spaces, not an option. */
|
|
19
|
+
export declare const MODEL_ID: RegExp;
|
|
20
|
+
export interface AcpRecipe {
|
|
21
|
+
/** The harness's id: the adapter's. */
|
|
22
|
+
readonly id: string;
|
|
23
|
+
/** Its name in a sentence. */
|
|
24
|
+
readonly label?: string;
|
|
25
|
+
/** The agent's binary (absolute) and the arguments that start it as an ACP agent over stdio. */
|
|
26
|
+
readonly command: string;
|
|
27
|
+
readonly args?: readonly string[];
|
|
28
|
+
/** Variables the agent gets beyond the allowlist (PATH, LANG, TZ). */
|
|
29
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
30
|
+
/** The keys the agent runs on (Cursor's CURSOR_API_KEY), by name: each is read from the host's environment at every
|
|
31
|
+
* start and handed to the agent under the same name, never written in the recipe. A start whose host lacks one of
|
|
32
|
+
* them is refused with ACP_CODES.keyMissing before anything starts. */
|
|
33
|
+
readonly keys?: readonly string[];
|
|
34
|
+
/** Files in HOME the agent derives from its keys (Cursor's `.config/cursor/auth.json`): never written, since each
|
|
35
|
+
* start makes every one an empty folder the agent cannot write a file at (an agent named here must run on the key in
|
|
36
|
+
* its env when its save fails, as Cursor 2026.11.13 does), so a hard kill leaves none on disk; never mirrored; and
|
|
37
|
+
* once a recipe names one, the agent's whole private HOME and tmp are also removed when its process ends (the
|
|
38
|
+
* drive's end, the session's close, a stop past the plan's limit). The next start makes them again from the
|
|
39
|
+
* session's records. */
|
|
40
|
+
readonly credentials?: readonly string[];
|
|
41
|
+
/** The agent's own refusals, by words it prints (on stderr, or in an error it answers): a start or a turn that fails
|
|
42
|
+
* saying `says` is said as `<code>: <words>`, so a host tells it apart without reading the agent's words. */
|
|
43
|
+
readonly refusals?: readonly AcpRefusal[];
|
|
44
|
+
/** Words the agent prints on stderr that never say why it failed (Cursor's warning that it could not save the
|
|
45
|
+
* credential the adapter keeps unwritable, and the error line under it): a stderr line holding one is left out of a
|
|
46
|
+
* failure's words, as are the terminal's escapes. Matched as they are. */
|
|
47
|
+
readonly quiet?: readonly string[];
|
|
48
|
+
/** The run's model, by the agent's id (`gpt-5.4-nano[reasoning=medium]`) or its name before the brackets
|
|
49
|
+
* (`gpt-5.4-nano`): chosen with session/set_model among those session/new lists, before the first prompt. One it
|
|
50
|
+
* does not list is refused with ACP_CODES.modelUnlisted. Absent: the agent's own default. */
|
|
51
|
+
readonly model?: string;
|
|
52
|
+
/** Files written into its private HOME before it starts, by their path in HOME (`.config/goose/config.yaml`). */
|
|
53
|
+
readonly files?: Readonly<Record<string, string>>;
|
|
54
|
+
/** Where in HOME the agent keeps its own sessions: mirrored into the session's records, so another runner's agent
|
|
55
|
+
* loads them (session/load). Credential files under them are never mirrored. */
|
|
56
|
+
readonly state?: readonly string[];
|
|
57
|
+
/** What the agent is expected to advertise at initialize: a mismatch refuses with ACP_CODES.capabilityMismatch.
|
|
58
|
+
* `load`: it resumes a session with session/load. `mcp`: the transport our tools go over. */
|
|
59
|
+
readonly declares: {
|
|
60
|
+
readonly load: boolean;
|
|
61
|
+
readonly mcp: "http" | "stdio";
|
|
62
|
+
};
|
|
63
|
+
readonly billing: AcpBilling;
|
|
64
|
+
readonly quirks?: {
|
|
65
|
+
/** How an MCP call finds its id. `match` (default): the agent's own tool_call for it, by tool and arguments; `mint`:
|
|
66
|
+
* an id of the adapter's, for an agent that announces no tool_call for an MCP call. */
|
|
67
|
+
readonly mcpCall?: "match" | "mint";
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** `path` in HOME, normalized, or undefined when it leaves HOME (absolute, `..`, or a `$HOME/` prefix spelled out). */
|
|
71
|
+
export declare function homePath(path: string): string | undefined;
|
|
72
|
+
/** What is wrong with `recipe`, each in words; none when it may run. */
|
|
73
|
+
export declare function recipeProblems(recipe: AcpRecipe): string[];
|
|
74
|
+
/** The variables the adapter sets itself: a recipe never names them. */
|
|
75
|
+
export declare const RESERVED_ENV: Set<string>;
|
package/dist/recipe.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// What the adapter is told about one ACP agent (design TDD §3.3, door 1): how to start it, what it declares, where it
|
|
2
|
+
// keeps its sessions and who bills its model. The loader's own rules (keys, registry archives, owner installs) are S5's;
|
|
3
|
+
// these are the checks the adapter itself needs before it starts anything. Written for AgentRun.
|
|
4
|
+
import { isAbsolute, normalize, sep } from "node:path";
|
|
5
|
+
/** An environment variable's name, as a key's. */
|
|
6
|
+
const KEY_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
7
|
+
/** A model id as an agent lists one (`gpt-5.4-nano[reasoning=medium]`): one line, no spaces, not an option. */
|
|
8
|
+
export const MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:/=,[\]-]{0,199}$/;
|
|
9
|
+
/** A refusal's code: capitals, digits and `_`. */
|
|
10
|
+
const CODE = /^[A-Z][A-Z0-9_]{1,63}$/;
|
|
11
|
+
/** `path` in HOME, normalized, or undefined when it leaves HOME (absolute, `..`, or a `$HOME/` prefix spelled out). */
|
|
12
|
+
export function homePath(path) {
|
|
13
|
+
const bare = path.startsWith("$HOME/") ? path.slice("$HOME/".length) : path;
|
|
14
|
+
if (!bare || isAbsolute(bare))
|
|
15
|
+
return undefined;
|
|
16
|
+
const clean = normalize(bare);
|
|
17
|
+
if (clean === "." || clean === ".." || clean.startsWith(`..${sep}`))
|
|
18
|
+
return undefined;
|
|
19
|
+
return clean;
|
|
20
|
+
}
|
|
21
|
+
/** What is wrong with `recipe`, each in words; none when it may run. */
|
|
22
|
+
export function recipeProblems(recipe) {
|
|
23
|
+
const problems = [];
|
|
24
|
+
if (!/^[a-z][a-z0-9-]{0,62}$/.test(recipe.id ?? ""))
|
|
25
|
+
problems.push(`the id ${JSON.stringify(recipe.id)} is not lowercase letters, digits and dashes`);
|
|
26
|
+
if (typeof recipe.command !== "string" || !isAbsolute(recipe.command))
|
|
27
|
+
problems.push("the command must be an absolute path");
|
|
28
|
+
if (!recipe.declares || typeof recipe.declares.load !== "boolean" || (recipe.declares.mcp !== "http" && recipe.declares.mcp !== "stdio"))
|
|
29
|
+
problems.push('declares needs load (true or false) and mcp ("http" or "stdio")');
|
|
30
|
+
const billing = recipe.billing;
|
|
31
|
+
if (billing?.kind === "plan") {
|
|
32
|
+
if (!Number.isInteger(billing.maxTurns) || billing.maxTurns < 1)
|
|
33
|
+
problems.push("plan billing needs maxTurns, a whole number of turns of at least 1");
|
|
34
|
+
if (!Number.isInteger(billing.maxToolCalls) || billing.maxToolCalls < 0)
|
|
35
|
+
problems.push("plan billing needs maxToolCalls, a whole number of calls");
|
|
36
|
+
}
|
|
37
|
+
else if (billing?.kind !== "proxy")
|
|
38
|
+
problems.push('billing is { kind: "plan", maxTurns, maxToolCalls } or { kind: "proxy" }');
|
|
39
|
+
for (const path of Object.keys(recipe.files ?? {}))
|
|
40
|
+
if (!homePath(path))
|
|
41
|
+
problems.push(`the file ${JSON.stringify(path)} must be inside the private HOME`);
|
|
42
|
+
for (const path of recipe.state ?? [])
|
|
43
|
+
if (!homePath(path))
|
|
44
|
+
problems.push(`the state path ${JSON.stringify(path)} must be inside the private HOME`);
|
|
45
|
+
const reserved = Object.keys(recipe.env ?? {}).filter((name) => RESERVED_ENV.has(name));
|
|
46
|
+
if (reserved.length)
|
|
47
|
+
problems.push(`the env names ${reserved.join(", ")}, which the adapter sets`);
|
|
48
|
+
for (const name of recipe.keys ?? []) {
|
|
49
|
+
if (typeof name !== "string" || !KEY_NAME.test(name))
|
|
50
|
+
problems.push(`the key ${JSON.stringify(name)} is not a variable's name (capitals, digits and _)`);
|
|
51
|
+
else if (RESERVED_ENV.has(name))
|
|
52
|
+
problems.push(`the key ${name} is a variable the adapter sets`);
|
|
53
|
+
else if (Object.hasOwn(recipe.env ?? {}, name))
|
|
54
|
+
problems.push(`the key ${name} is also in env: a key is read from the host by name, never written in the recipe`);
|
|
55
|
+
}
|
|
56
|
+
for (const path of recipe.credentials ?? [])
|
|
57
|
+
if (!homePath(path))
|
|
58
|
+
problems.push(`the credential ${JSON.stringify(path)} must be inside the private HOME`);
|
|
59
|
+
for (const refusal of recipe.refusals ?? []) {
|
|
60
|
+
const ok = typeof refusal?.says === "string" && refusal.says.trim() !== "" && typeof refusal.code === "string" && CODE.test(refusal.code) && typeof refusal.words === "string" && refusal.words.trim() !== "";
|
|
61
|
+
if (!ok)
|
|
62
|
+
problems.push(`the refusal ${JSON.stringify(refusal ?? null).slice(0, 120)} needs says, a code (capitals, digits and _) and words`);
|
|
63
|
+
}
|
|
64
|
+
if (recipe.quiet !== undefined && (!Array.isArray(recipe.quiet) || recipe.quiet.some((words) => typeof words !== "string" || words.trim() === "")))
|
|
65
|
+
problems.push("quiet is a list of words, none empty");
|
|
66
|
+
if (recipe.model !== undefined && (typeof recipe.model !== "string" || !MODEL_ID.test(recipe.model)))
|
|
67
|
+
problems.push(`the model ${JSON.stringify(String(recipe.model).slice(0, 80))} is not a model id`);
|
|
68
|
+
return problems;
|
|
69
|
+
}
|
|
70
|
+
/** The variables the adapter sets itself: a recipe never names them. */
|
|
71
|
+
export const RESERVED_ENV = new Set(["HOME", "TMPDIR", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_STATE_HOME", "GIT_CEILING_DIRECTORIES"]);
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { NativeJournal } from "@parcha/agentrun-kernel/process";
|
|
2
|
+
/** The journal stream that holds the agent's session store. */
|
|
3
|
+
export declare const STATE_STREAM = "acp.state";
|
|
4
|
+
export interface StateRecord {
|
|
5
|
+
path: string;
|
|
6
|
+
sha256?: string;
|
|
7
|
+
data?: string;
|
|
8
|
+
deleted?: true;
|
|
9
|
+
}
|
|
10
|
+
/** A file the mirror never takes: its name says it holds a credential. */
|
|
11
|
+
export declare const CREDENTIAL_FILE: RegExp;
|
|
12
|
+
/** The most bytes one file may have to be mirrored; a larger one is skipped, said in the log. */
|
|
13
|
+
export declare const MAX_STATE_FILE: number;
|
|
14
|
+
/** The newest record of each path, as the records hold them. */
|
|
15
|
+
export declare function foldState(records: readonly StateRecord[]): Map<string, StateRecord>;
|
|
16
|
+
/** Write the mirrored files back into `home`. */
|
|
17
|
+
export declare function restoreState(home: string, records: readonly StateRecord[]): void;
|
|
18
|
+
/** The mirror of one agent process's HOME: what changed since the records' newest, appended to `journal`. */
|
|
19
|
+
export declare class StateMirror {
|
|
20
|
+
private readonly home;
|
|
21
|
+
private readonly paths;
|
|
22
|
+
/** Paths in HOME never mirrored, each a file or a folder: the recipe's own files (written at every start) and the
|
|
23
|
+
* credentials it names. */
|
|
24
|
+
private readonly skip;
|
|
25
|
+
private readonly log;
|
|
26
|
+
private readonly known;
|
|
27
|
+
constructor(home: string, paths: readonly string[],
|
|
28
|
+
/** Paths in HOME never mirrored, each a file or a folder: the recipe's own files (written at every start) and the
|
|
29
|
+
* credentials it names. */
|
|
30
|
+
skip: ReadonlySet<string>, records: readonly StateRecord[], log?: (message: string, fields?: Record<string, unknown>) => void);
|
|
31
|
+
/** Append what changed to `journal` (the caller flushes). Returns how many records it appended. */
|
|
32
|
+
take(journal: NativeJournal, stream?: string): number;
|
|
33
|
+
}
|