{"draft":null,"from":16,"to":318,"files":[{"path":"client/src/mcp.ts","added":83,"removed":16,"diff":"--- a/client/src/mcp.ts\n+++ b/client/src/mcp.ts\n@@ -2,14 +2,15 @@\n // command, run by the same code as the command line and answering with the\n // same text, so the CLI and the tools can't drift apart and an agent learns\n // one set of words. The folder and the token come from where the server runs,\n-// as for the CLI: .avcs/config.json, and AVCS_TOKEN or ~/.avcs/token.\n+// as for the CLI: .avcs/config.json, and ABSO_TOKEN or ~/.abso/token.\n //\n-//   claude mcp add avcs -- node <repo>/client/avcs.ts mcp\n+//   claude mcp add abso -- abso mcp\n //\n // The protocol is JSON-RPC 2.0, one message per line, with no library: the\n // client uses nothing outside Node.\n \n-import { resolve } from \"node:path\";\n+import { realpathSync } from \"node:fs\";\n+import { isAbsolute, relative, resolve, sep } from \"node:path\";\n import { clientVersion } from \"./client-version.ts\";\n import { commandTable, main } from \"./main.ts\";\n \n@@ -34,8 +35,8 @@\n \t\"announce\",\n \t\"start\",\n \t\"record\",\n-\t\"sync\",\n-\t\"publish\",\n+\t\"pull\",\n+\t\"push\",\n \t\"unqueue\",\n \t\"restore\",\n \t\"settle\",\n@@ -47,9 +48,18 @@\n \t\"notes\",\n \t\"issues\",\n \t\"issue\",\n+\t\"search\",\n \t\"ask\",\n \t\"waiting\",\n \t\"answer\",\n+\t\"ack\",\n+\t\"reply\",\n+\t\"groups\",\n+\t\"group\",\n+\t\"orgs\",\n+\t\"org\",\n+\t\"whoami\",\n+\t\"doctor\",\n ] as const;\n \n const PROTOCOLS = [\"2025-06-18\", \"2025-03-26\", \"2024-11-05\"];\n@@ -68,15 +78,19 @@\n \treturn MCP_COMMANDS.map((command) => {\n \t\tconst def = table[command]!;\n \t\tconst flags = Object.fromEntries(\n-\t\t\tObject.entries(def.flags).map(([flag, kind]) => [\n-\t\t\t\tflag,\n-\t\t\t\tkind === \"boolean\"\n-\t\t\t\t\t? { type: \"boolean\", description: `--${flag}` }\n-\t\t\t\t\t: {\n-\t\t\t\t\t\t\ttype: \"string\",\n-\t\t\t\t\t\t\tdescription: kind === \"optional\" ? `--${flag} \"<value>\"; \"\" gives --${flag} alone` : `--${flag} <value>`,\n-\t\t\t\t\t\t},\n-\t\t\t]),\n+\t\t\t// No --token-file: a tool signs in with its folder's key, never this machine's token file.\n+\t\t\tObject.entries(def.flags)\n+\t\t\t\t.filter(([flag]) => flag !== \"token-file\")\n+\t\t\t\t.map(([flag, kind]) => [\n+\t\t\t\t\tflag,\n+\t\t\t\t\tkind === \"boolean\"\n+\t\t\t\t\t\t? { type: \"boolean\", description: `--${flag}` }\n+\t\t\t\t\t\t: {\n+\t\t\t\t\t\t\t\ttype: \"string\",\n+\t\t\t\t\t\t\t\tdescription:\n+\t\t\t\t\t\t\t\t\tkind === \"optional\" ? `--${flag} \"<value>\"; \"\" gives --${flag} alone` : `--${flag} <value>`,\n+\t\t\t\t\t\t\t},\n+\t\t\t\t]),\n \t\t);\n \t\treturn {\n \t\t\tname: toolName(command),\n@@ -91,7 +105,8 @@\n \t\t\t\t\t},\n \t\t\t\t\tfolder: {\n \t\t\t\t\t\ttype: \"string\",\n-\t\t\t\t\t\tdescription: \"The abso folder to run in (default: the folder this server started in).\",\n+\t\t\t\t\t\tdescription:\n+\t\t\t\t\t\t\t\"The abso folder to run in: the folder this server started in (the default), or one inside it.\",\n \t\t\t\t\t},\n \t\t\t\t\tjson: { type: \"boolean\", description: \"Answer with the command's JSON (as --json) instead of its text.\" },\n \t\t\t\t\t...flags,\n@@ -102,6 +117,56 @@\n \t});\n }\n \n+/** A path as it really is (through links), or as given when it doesn't exist. */\n+function real(path: string): string {\n+\ttry {\n+\t\treturn realpathSync.native(path);\n+\t} catch {\n+\t\treturn path;\n+\t}\n+}\n+\n+/** Whether `path` is `start` or inside it, after links are followed. */\n+function inside(start: string, path: string): boolean {\n+\tconst rel = relative(real(start), real(path));\n+\treturn rel === \"\" || (rel !== \"..\" && !rel.startsWith(`..${sep}`) && !isAbsolute(rel));\n+}\n+\n+/** The tool inputs that name files or folders on this machine to read or write, comma-separated: each is confined like the folder. */\n+export const FILE_INPUTS = [\"attach\", \"clean\", \"save-attachments\"] as const;\n+\n+/**\n+ * Where a tool call runs, and what it may read: its folder and\n+ * every file a FILE_INPUTS input names stay inside the folder the server\n+ * started in. A relative path that climbs out (..), an absolute one elsewhere,\n+ * or a link out is refused, so no tool reads a file outside the project.\n+ * Answers the folder, or why the call is refused.\n+ */\n+export function confineCall(\n+\tstart: string,\n+\tinput: Readonly<Record<string, unknown>>,\n+): { folder: string } | { refused: string } {\n+\tconst named = typeof input.folder === \"string\" && input.folder !== \"\" ? input.folder : undefined;\n+\tconst folder = named === undefined ? start : resolve(start, named);\n+\tif (!inside(start, folder))\n+\t\treturn {\n+\t\t\trefused: `folder ${JSON.stringify(named)} is outside ${start}, the folder this server started in; tools run there or below`,\n+\t\t};\n+\tfor (const flag of FILE_INPUTS) {\n+\t\tconst value = input[flag];\n+\t\tif (typeof value !== \"string\") continue;\n+\t\tfor (const p of value\n+\t\t\t.split(\",\")\n+\t\t\t.map((x) => x.trim())\n+\t\t\t.filter((x) => x !== \"\"))\n+\t\t\tif (!inside(start, resolve(folder, p)))\n+\t\t\t\treturn {\n+\t\t\t\t\trefused: `--${flag} ${p} is outside ${start}, the folder this server started in; a tool reads and writes files only there or below`,\n+\t\t\t\t};\n+\t}\n+\treturn { folder };\n+}\n+\n /** The command line a tool call stands for: flags as --name=value, then the words after --. */\n export function argvFor(command: string, input: Readonly<Record<string, unknown>>): string[] {\n \tconst def = commandTable()[command]!;\n@@ -157,7 +222,9 @@\n \t\t\t\tconst command = MCP_COMMANDS.find((c) => toolName(c) === name);\n \t\t\t\tif (command === undefined) return fail(id, -32602, `no tool ${JSON.stringify(name)}; tools/list names them`);\n \t\t\t\tconst args = (params.arguments ?? {}) as Record<string, unknown>;\n-\t\t\t\tconst folder = typeof args.folder === \"string\" && args.folder !== \"\" ? resolve(cwd, args.folder) : cwd;\n+\t\t\t\tconst where = confineCall(cwd, args);\n+\t\t\t\tif (\"refused\" in where) return reply(id, { content: [{ type: \"text\", text: where.refused }], isError: true });\n+\t\t\t\tconst folder = where.folder;\n \t\t\t\tlet streamed = \"\";\n \t\t\t\tconst result = await main(argvFor(command, args), {\n \t\t\t\t\tcwd: folder,"}],"unmatched":[]}