Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 20 to 318

Compare

+82 −16 in 7 places
Lines 2–16 at 318 (were 2–15 at 20)
22// command, run by the same code as the command line and answering with the
33// same text, so the CLI and the tools can't drift apart and an agent learns
44// one set of words. The folder and the token come from where the server runs,
5−// as for the CLI: .avcs/config.json, and AVCS_TOKEN or ~/.avcs/token.
5+// as for the CLI: .avcs/config.json, and ABSO_TOKEN or ~/.abso/token.
66//
7−// claude mcp add avcs -- node <repo>/client/avcs.ts mcp
7+// claude mcp add abso -- abso mcp
88//
99// The protocol is JSON-RPC 2.0, one message per line, with no library: the
1010// client uses nothing outside Node.
1111
12−import { resolve } from "node:path";
12+import { realpathSync } from "node:fs";
13+import { isAbsolute, relative, resolve, sep } from "node:path";
1314import { clientVersion } from "./client-version.ts";
1415import { commandTable, main } from "./main.ts";
1516
Lines 35–42 at 318 (were 34–41 at 20)
3435 "announce",
3536 "start",
3637 "record",
37− "sync",
38− "publish",
38+ "pull",
39+ "push",
3940 "unqueue",
4041 "restore",
4142 "settle",
Lines 52–65 at 318 (were 51–56 at 20)
5152 "ask",
5253 "waiting",
5354 "answer",
55+ "ack",
56+ "reply",
57+ "groups",
58+ "group",
59+ "orgs",
60+ "org",
61+ "whoami",
62+ "doctor",
5463] as const;
5564
5665const PROTOCOLS = ["2025-06-18", "2025-03-26", "2024-11-05"];
Lines 78–96 at 318 (were 69–83 at 20)
6978 return MCP_COMMANDS.map((command) => {
7079 const def = table[command]!;
7180 const flags = Object.fromEntries(
72− Object.entries(def.flags).map(([flag, kind]) => [
73− flag,
74− kind === "boolean"
75− ? { type: "boolean", description: `--${flag}` }
76− : {
77− type: "string",
78− description: kind === "optional" ? `--${flag} "<value>"; "" gives --${flag} alone` : `--${flag} <value>`,
79− },
80− ]),
81+ // No --token-file: a tool signs in with its folder's key, never this machine's token file.
82+ Object.entries(def.flags)
83+ .filter(([flag]) => flag !== "token-file")
84+ .map(([flag, kind]) => [
85+ flag,
86+ kind === "boolean"
87+ ? { type: "boolean", description: `--${flag}` }
88+ : {
89+ type: "string",
90+ description:
91+ kind === "optional" ? `--${flag} "<value>"; "" gives --${flag} alone` : `--${flag} <value>`,
92+ },
93+ ]),
8194 );
8295 return {
8396 name: toolName(command),
Lines 105–112 at 318 (were 92–98 at 20)
92105 },
93106 folder: {
94107 type: "string",
95− description: "The abso folder to run in (default: the folder this server started in).",
108+ description:
109+ "The abso folder to run in: the folder this server started in (the default), or one inside it.",
96110 },
97111 json: { type: "boolean", description: "Answer with the command's JSON (as --json) instead of its text." },
98112 ...flags,
Lines 117–172 at 318 (were 103–108 at 20)
103117 });
104118}
105119
120+/** A path as it really is (through links), or as given when it doesn't exist. */
121+function real(path: string): string {
122+ try {
123+ return realpathSync.native(path);
124+ } catch {
125+ return path;
126+ }
127+}
129+/** Whether `path` is `start` or inside it, after links are followed. */
130+function inside(start: string, path: string): boolean {
131+ const rel = relative(real(start), real(path));
132+ return rel === "" || (rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));
133+}
135+/** The tool inputs that name files or folders on this machine to read or write, comma-separated: each is confined like the folder. */
136+export const FILE_INPUTS = ["attach", "clean", "save-attachments"] as const;
138+/**
139+ * Where a tool call runs, and what it may read: its folder and
140+ * every file a FILE_INPUTS input names stay inside the folder the server
141+ * started in. A relative path that climbs out (..), an absolute one elsewhere,
142+ * or a link out is refused, so no tool reads a file outside the project.
143+ * Answers the folder, or why the call is refused.
144+ */
145+export function confineCall(
146+ start: string,
147+ input: Readonly<Record<string, unknown>>,
148+): { folder: string } | { refused: string } {
149+ const named = typeof input.folder === "string" && input.folder !== "" ? input.folder : undefined;
150+ const folder = named === undefined ? start : resolve(start, named);
151+ if (!inside(start, folder))
152+ return {
153+ refused: `folder ${JSON.stringify(named)} is outside ${start}, the folder this server started in; tools run there or below`,
154+ };
155+ for (const flag of FILE_INPUTS) {
156+ const value = input[flag];
157+ if (typeof value !== "string") continue;
158+ for (const p of value
159+ .split(",")
160+ .map((x) => x.trim())
161+ .filter((x) => x !== ""))
162+ if (!inside(start, resolve(folder, p)))
163+ return {
164+ refused: `--${flag} ${p} is outside ${start}, the folder this server started in; a tool reads and writes files only there or below`,
165+ };
166+ }
167+ return { folder };
168+}
106170/** The command line a tool call stands for: flags as --name=value, then the words after --. */
107171export function argvFor(command: string, input: Readonly<Record<string, unknown>>): string[] {
108172 const def = commandTable()[command]!;
Lines 222–230 at 318 (were 158–164 at 20)
158222 const command = MCP_COMMANDS.find((c) => toolName(c) === name);
159223 if (command === undefined) return fail(id, -32602, `no tool ${JSON.stringify(name)}; tools/list names them`);
160224 const args = (params.arguments ?? {}) as Record<string, unknown>;
161− const folder = typeof args.folder === "string" && args.folder !== "" ? resolve(cwd, args.folder) : cwd;
225+ const where = confineCall(cwd, args);
226+ if ("refused" in where) return reply(id, { content: [{ type: "text", text: where.refused }], isError: true });
227+ const folder = where.folder;
162228 let streamed = "";
163229 const result = await main(argvFor(command, args), {
164230 cwd: folder,
MCP
compare on this site's /mcp
CLI
abso diff 20 318 client/src/mcp.ts --json
JSON
/christopher/abso-core/compare/20..318?file=client%2Fsrc%2Fmcp.ts&format=json