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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/command-env.ts?version=282&format=json
87 linesFirst import 67% · pinch 16% · groups 7% · speed 7% · readspeed 3%Last change pinch in version 282, 8 versions changed it

You're reading version 282. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1// What every abso command shares: its output, its environment, the folder it opens, and the news it took.
2
3import { createHash } from "node:crypto";
4import { hostname } from "node:os";
5import { basename } from "node:path";
6import { callerHeader } from "../../src/caller.ts";
7import { Api, type News, newsLines, type RunKind, takeSeatNotices } from "./api.ts";
8import { UsageError } from "./args.ts";
9import { type Config, findRoot, readConfig } from "./config.ts";
10import { newsBlockLines, newsShown } from "./core.ts";
11import { logNews } from "./folder.ts";
13export const EXIT = { ok: 0, error: 1, refused: 2 } as const;
15export interface Output {
16 readonly text: string;
17 readonly json: Record<string, unknown>;
18 readonly exit?: number;
21export interface Env {
22 readonly cwd: string;
23 readonly env: Readonly<Record<string, string | undefined>>;
24 /** Where `run` streams the box's output as it arrives. */
25 readonly write: (text: string) => void;
26 /** --token-file: this machine's ~/.abso/token may sign in, where nothing else does. Never read otherwise. */
27 readonly tokenFile?: boolean;
28 /** Where `run` streams the box's stderr; `write` when not given. */
29 readonly writeErr?: (text: string) => void;
30 /** What a box run is for, when a command runs one for its own ends (shot, bisect, publish --check). */
31 readonly runKind?: RunKind;
32 /** What a -file flag of - reads: stdin, unless a test gives it. */
33 readonly readStdin?: () => string;
34 /**
35 * The server --server named, checked (server-choice.ts), when the command was given one. It is used as given,
36 * so no environment setting redirects it (ABSO_ISSUES_SERVER included).
37 */
38 readonly server?: string;
41export function plural(n: number, word: string): string {
42 return `${n} ${word}${n === 1 ? "" : "s"}`;
45export function open(env: Env): { root: string; config: Config; api: Api } {
46 const root = findRoot(env.cwd);
47 if (root === undefined)
48 throw new UsageError(
49 `You're not in an abso folder: ${env.cwd} has no .abso/config.json, nor does any folder above it. abso join <project> makes one, or abso init a new project.`,
50 );
51 const config = readConfig(root, env.env, env.tokenFile === true);
52 const api = new Api(config);
53 api.caller = callerFor(env.env.CLAUDE_CODE_SESSION_ID, hostname(), root);
54 return { root, config, api };
57/**
58 * The caller header for this chat, computer and folder. The chat's session id goes as a short SHA-256 of it and the
59 * folder as its last part, so neither the raw id nor the path (which names the person) leaves the machine.
60 */
61export function callerFor(session: string | undefined, machine: string, root: string): string | undefined {
62 const hashed = session ? createHash("sha256").update(session).digest("hex").slice(0, 16) : undefined;
63 return callerHeader({ session: hashed, machine, folder: basename(root) });
66/**
67 * News a command took from the server while recording first. main() prints it
68 * after whatever the command says, so every command that takes news shows it
69 * (#37, News Report: sync, run and diff took it, wrote it to .avcs/news.log and
70 * printed nothing; 94 of the game's 613 items, 54 of them announcements).
71 */
72const takenNews: string[] = [];
73export function takeNews(): string[] {
74 return [...takeSeatNotices(), ...takenNews.splice(0)];
77/** News a record answered with: kept in .avcs/news.log, and printed by main(). */
78export function heard(root: string, news: News | undefined): void {
79 const lines = newsLines(news);
80 logNews(root, lines);
81 takenNews.push(...lines);
84export function newsText(news: News): string[] {
85 const lines = newsLines(news);
86 return newsBlockLines(lines.map((n) => newsShown(n)));