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 263 to 318

Compare

+51 −8 in 9 places
Lines 11–17 at 318 (were 11–16 at 263)
1111import { UsageError } from "./args.ts";
1212import { type MachineServers, machineServers, TOKEN_SERVERS, tokenGoesTo, trustedList } from "./core.ts";
1313import { fromEnv } from "./env-names.ts";
14+import { isLocal, storeDir } from "./local-store.ts";
1415import { homeFile, stateDir } from "./state-dir.ts";
1516
1617/** What .avcs/config.json holds. */
Lines 28–41 at 318 (were 27–36 at 263)
2728 * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this.
2829 */
2930 readonly visitor?: boolean;
31+ /** A local project's store (abso init --local --store), when it isn't the machine's own: ABSO_STORE or the OS data folder. */
32+ readonly store?: string;
3033}
3134
3235export interface Config extends Settings {
3336 readonly token?: string;
37+ /** For a local project (server "local"): the store folder its history is in, or undefined when there's none to use. */
38+ readonly localStore?: string;
3439}
3540
3641export function configPath(root: string): string {
Lines 53–63 at 318 (were 48–54 at 263)
4853 }
4954}
5055
51−export function readConfig(root: string, env: Readonly<Record<string, string | undefined>> = process.env): Config {
56+export function readConfig(
57+ root: string,
58+ env: Readonly<Record<string, string | undefined>> = process.env,
59+ tokenFileOk = false,
60+): Config {
5261 const raw = JSON.parse(readFileSync(configPath(root), "utf8")) as Partial<Settings>;
5362 if (raw.visitor === true) {
5463 for (const key of ["server", "project"] as const) {
Lines 69–83 at 318 (were 60–70 at 263)
6069 for (const key of ["server", "project", "agent"] as const) {
6170 if (typeof raw[key] !== "string" || raw[key] === "") throw new Error(`${configPath(root)} has no "${key}"`);
6271 }
63− const token = tokenFor(raw.server!, env, root);
72+ // A local project's calls never leave this process, so no credential goes with them.
73+ const local = isLocal(raw.server);
74+ const token = local ? undefined : tokenFor(raw.server!, env, root, tokenFileOk);
6475 return {
6576 server: raw.server!,
6677 project: raw.project!,
6778 agent: raw.agent!,
79+ ...(typeof raw.store === "string" && raw.store !== "" ? { store: raw.store } : {}),
80+ ...(local ? { localStore: storeDir(env, raw.store, root) } : {}),
6881 ...(typeof raw.follow === "string" && raw.follow !== "" ? { follow: raw.follow } : {}),
6982 ...(raw.reader === true ? { reader: true } : {}),
7083 ...(token ? { token } : {}),
Lines 111–117 at 318 (were 98–103 at 263)
98111 root: string,
99112 server: string,
100113 env: Readonly<Record<string, string | undefined>> = process.env,
114+ tokenFileOk = false,
101115): { kind: "agent key" | "shared token" | "pipeline run key" | "none"; id: string | null } {
102116 const key = readKeyFile(root);
103117 if (key) {
Lines 120–126 at 318 (were 106–112 at 263)
106120 }
107121 if (fromEnv(env, "TOKEN")) return { kind: "shared token", id: null };
108122 if (fromEnv(env, "KEY_FILE")) return { kind: "pipeline run key", id: null };
109− return { kind: readToken(env) ? "shared token" : "none", id: null };
123+ return { kind: tokenFileOk && tokenFile() ? "shared token" : "none", id: null };
110124}
111125
112126interface StoredKey {
Lines 192–226 at 318 (were 178–195 at 263)
178192 server: string,
179193 env: Readonly<Record<string, string | undefined>> = process.env,
180194 root?: string,
195+ tokenFileOk = false,
181196): string | undefined {
182197 if (root) {
183198 const key = readKeyFile(root);
199+ // A folder with a key signs in with that key and nothing else, even when the server refuses it.
200+ if (!key && existsSync(keyPath(root)))
201+ throw new UsageError(
202+ `this folder's key file (${keyPath(root)}) can't be read, so abso sends nothing; abso key install puts a key back`,
203+ );
184204 if (key) {
185205 if (originOf(key.server) !== originOf(server))
186206 throw new UsageError("this folder's key was issued for a different server, so abso will not send it");
187207 return key.key;
188208 }
189209 }
190− const token = fromEnv(env, "TOKEN")?.trim() || runKey(env) || readToken(env);
191− const trusted = trustedServers(env);
192− if (token === undefined || tokenGoesTo(server, trusted)) return token;
210+ return trustedToken(
211+ server,
212+ env,
213+ fromEnv(env, "TOKEN")?.trim() || runKey(env) || (tokenFileOk ? readToken(env) : undefined),
214+ );
215+}
217+/** The token as given, if abso may send it to this server; refused, in words, if not. */
218+export function trustedToken(
219+ server: string,
220+ env: Readonly<Record<string, string | undefined>>,
221+ token: string | undefined,
222+): string | undefined {
223+ if (token === undefined || tokenGoesTo(server, trustedServers(env))) return token;
193224 throw new UsageError(
194225 `this folder's server is ${server}, and abso sends your token only to ${[...TOKEN_SERVERS, "this machine"].join(", ")}, and the servers ~/.abso/servers.json or ABSO_TRUSTED_SERVERS name. ` +
195226 `If ${server} is yours, name it in ~/.abso/servers.json or ABSO_TRUSTED_SERVERS (comma-separated); if you didn't set it, someone else wrote .abso/config.json.`,
Lines 266–276 at 318 (were 235–240 at 263)
235266 return key;
236267}
237268
269+/** This machine's token file (~/.abso/token, else ~/.avcs/token), or none. Read only for a command given --token-file. */
270+export function tokenFile(): string | undefined {
271+ return readToken({});
272+}
238274/** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */
239275export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {
240276 const fromVar = fromEnv(env, "TOKEN");
Lines 284–300 at 318 (were 248–257 at 263)
248284
249285export function writeConfig(root: string, settings: Settings): void {
250286 mkdirSync(stateDir(root), { recursive: true });
251− const { server, project, agent, follow, reader, visitor } = settings;
287+ const { server, project, agent, follow, reader, visitor, store } = settings;
252288 const written = visitor
253289 ? { server, project, visitor: true }
254− : { server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) };
290+ : {
291+ server,
292+ project,
293+ agent,
294+ ...(follow ? { follow } : {}),
295+ ...(reader ? { reader: true } : {}),
296+ ...(store ? { store } : {}),
297+ };
255298 writeFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\n`);
256299 excludeFromGit(root);
257300}
MCP
compare on this site's /mcp
CLI
abso diff 263 318 client/src/config.ts --json
JSON
/christopher/abso-core/compare/263..318?file=client%2Fsrc%2Fconfig.ts&format=json