- 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=277&format=json
76 linesFirst import 76% · groups 9% · speed 8% · readspeed 4% · pinch 3%Last change groups in version 277, 7 versions changed it
You're reading version 277. The newest is 318, and 2 versions since then changed this file.
1// What every abso command shares: its output, its environment, the folder it opens, and the news it took.
3import { hostname } from "node:os";
4import { callerHeader } from "../../src/caller.ts";
5import { Api, type News, newsLines, type RunKind, takeSeatNotices } from "./api.ts";
6import { UsageError } from "./args.ts";
7import { type Config, findRoot, readConfig } from "./config.ts";
8import { newsBlockLines, newsShown } from "./core.ts";
9import { logNews } from "./folder.ts";
11export const EXIT = { ok: 0, error: 1, refused: 2 } as const;
13export interface Output {
14 readonly text: string;
15 readonly json: Record<string, unknown>;
16 readonly exit?: number;
17}
19export interface Env {
20 readonly cwd: string;
21 readonly env: Readonly<Record<string, string | undefined>>;
22 /** Where `run` streams the box's output as it arrives. */
23 readonly write: (text: string) => void;
24 /** --token-file: this machine's ~/.abso/token may sign in, where nothing else does. Never read otherwise. */
25 readonly tokenFile?: boolean;
26 /** Where `run` streams the box's stderr; `write` when not given. */
27 readonly writeErr?: (text: string) => void;
28 /** What a box run is for, when a command runs one for its own ends (shot, bisect, publish --check). */
29 readonly runKind?: RunKind;
30 /** What a -file flag of - reads: stdin, unless a test gives it. */
31 readonly readStdin?: () => string;
32 /**
33 * The server --server named, checked (server-choice.ts), when the command was given one. It is used as given,
34 * so no environment setting redirects it (ABSO_ISSUES_SERVER included).
35 */
36 readonly server?: string;
37}
39export function plural(n: number, word: string): string {
40 return `${n} ${word}${n === 1 ? "" : "s"}`;
41}
43export function open(env: Env): { root: string; config: Config; api: Api } {
44 const root = findRoot(env.cwd);
45 if (root === undefined)
46 throw new UsageError(
47 `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.`,
48 );
49 const config = readConfig(root, env.env, env.tokenFile === true);
50 const api = new Api(config);
51 api.caller = callerHeader({ session: env.env.CLAUDE_CODE_SESSION_ID, machine: hostname(), folder: root });
52 return { root, config, api };
53}
55/**
56 * News a command took from the server while recording first. main() prints it
57 * after whatever the command says, so every command that takes news shows it
58 * (#37, News Report: sync, run and diff took it, wrote it to .avcs/news.log and
59 * printed nothing; 94 of the game's 613 items, 54 of them announcements).
60 */
61const takenNews: string[] = [];
62export function takeNews(): string[] {
63 return [...takeSeatNotices(), ...takenNews.splice(0)];
64}
66/** News a record answered with: kept in .avcs/news.log, and printed by main(). */
67export function heard(root: string, news: News | undefined): void {
68 const lines = newsLines(news);
69 logNews(root, lines);
70 takenNews.push(...lines);
71}
73export function newsText(news: News): string[] {
74 const lines = newsLines(news);
75 return newsBlockLines(lines.map((n) => newsShown(n)));
76}