- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/avcs.ts?format=json
55 linespinch 53% · First import 47%Last change pinch in version 289, 4 versions changed it
1// The abso client. Run it as:
2// node client/avcs.ts <command> [options]
3// `abso help` lists the commands. `abso hook` is the Claude Code hook; it
4// loads only what it needs, since every edit pays for its start-up.
6import { readFileSync } from "node:fs";
7import * as nodeModule from "node:module";
8import { dirname, join } from "node:path";
10const argv = process.argv.slice(2);
12/**
13 * Whether this command opens a local project (abso init --local): --local, or a folder whose config names the server
14 * "local". Those load the open server's code through a module hook, and with the compile cache on Node 24 crashes.
15 */
16function opensLocal(): boolean {
17 if (argv.includes("--local")) return true;
18 for (let dir = process.cwd(); ; dir = dirname(dir)) {
19 for (const state of [".abso", ".avcs"]) {
20 try {
21 return /"server"\s*:\s*"local"/.test(readFileSync(join(dir, state, "config.json"), "utf8"));
22 } catch {}
23 }
24 if (dirname(dir) === dir) return false;
25 }
26}
28// Node keeps the compiled modules (TypeScript already stripped) in a cache in
29// the temp folder. Loading the hook's modules drops from about 55 ms to 11 ms.
30// Node 20 has no compile cache, and the built client runs there without one.
31if (!opensLocal()) (nodeModule as { enableCompileCache?: () => unknown }).enableCompileCache?.();
33if (argv[0] === "hook") {
34 const { runHook } = await import("./src/hook.ts");
35 const chunks: Buffer[] = [];
36 for await (const chunk of process.stdin) chunks.push(chunk as Buffer);
37 const result = await runHook(Buffer.concat(chunks).toString("utf8"));
38 if (result.stdout) process.stdout.write(result.stdout);
39 // Always 0: the hook never stops the agent.
40 process.exitCode = 0;
41} else if (argv[0] === "mcp") {
42 // An MCP server on stdin and stdout, for as long as the client keeps it open.
43 const { serveMcp } = await import("./src/mcp.ts");
44 await serveMcp(process.stdin, (line) => process.stdout.write(`${line}\n`), process.cwd(), process.env);
45} else {
46 const { main } = await import("./src/main.ts");
47 // Everything printed goes through terminalText: most of it is a server's text (abso-core's terminal-text.ts).
48 const { colorsPass, terminalText } = await import("./src/terminal-text.ts");
49 const out = (text: string) => process.stdout.write(terminalText(text, colorsPass(process.stdout, process.env)));
50 const err = (text: string) => process.stderr.write(terminalText(text, colorsPass(process.stderr, process.env)));
51 const result = await main(argv, { cwd: process.cwd(), env: process.env, write: out, writeErr: err });
52 if (result.stdout) out(result.stdout);
53 if (result.stderr) err(result.stderr);
54 process.exitCode = result.exit;
55}