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

Compare

+127 −5 in 15 places
Lines 2–10 at 318 (were 2–8 at 108)
22// except `run`, which sends a tar.gz and reads the answer as a stream of JSON
33// lines (box-run.ts).
44
5+import { randomUUID } from "node:crypto";
56import { setDefaultResultOrder } from "node:dns";
7+import { CALLER_HEADER } from "../../src/caller.ts";
68import type {
79 ChangeAnswer,
810 DraftSyncAnswer,
Lines 20–27 at 318 (were 18–23 at 108)
1820 SyncAnswer,
1921} from "./api-answers.ts";
2022import { ApiError, errorSentence, neverSent } from "./api-error.ts";
23+import { UsageError } from "./args.ts";
24+import type { AutosettleAnswer, AutosettleMode } from "./autosettle-commands.ts";
2125import {
2226 boxQuery,
2327 consumeRun,
Lines 53–75 at 318 (were 49–65 at 108)
4953 Where,
5054 WhereAnswer,
5155 WhyAnswer,
56+ WithoutAnswer,
5257} from "./history-answers.ts";
5358import type {
5459 Ask,
5560 Attachment,
5661 Draft,
5762 DraftBody,
63+ GroupEvent,
64+ GroupShown,
65+ GroupSummary,
66+ GroupWrite,
5867 News as IssueNews,
5968 IssuePage,
6069 IssueRow,
6170 IssueSearchHit,
6271} from "./issues-wire.ts";
72+import { isLocal, LOCAL_BASE, localFetch, NO_STORE } from "./local-store.ts";
6373import type { Modes } from "./modes.ts";
6474
6575export * from "./api-answers.ts";
Lines 144–166 at 318 (were 134–139 at 108)
134144 | { dryRun: true; plan: CopyPlan }
135145 | { ok: true; id: number; from: { project: string; issue: number }; skipped: { comments: number[]; asks: number[] } };
136146
147+/**
148+ * The server's line when another chat just used this seat (seatNotice on an answer): kept until main() prints it with
149+ * the news, once however many answers carried it.
150+ */
151+const seatNotices = new Set<string>();
152+function noteSeat(answer: unknown): void {
153+ if (typeof answer !== "object" || answer === null || Array.isArray(answer)) return;
154+ const line = (answer as { seatNotice?: unknown }).seatNotice;
155+ if (typeof line === "string" && line !== "" && line.length <= 300 && !/[\u0000-\u001f]/.test(line))
156+ seatNotices.add(line);
157+}
158+export function takeSeatNotices(): string[] {
159+ const out = [...seatNotices];
160+ seatNotices.clear();
161+ return out;
162+}
137164export class Api {
138165 readonly config: Config;
139166 readonly timeoutMs: number;
Lines 189–205 at 318 (were 162–171 at 108)
162189 /** The Issues Worker (#54) this folder's issues calls go to; set by the issues commands (issues.ts). */
163190 issuesServer: string | undefined;
164191
192+ /** Who is calling this seat (src/caller.ts): this chat's session, this computer and this folder. Set by open(). */
193+ caller: string | undefined;
165195 url(path: string, server = this.config.server): string {
166− return `${server.replace(/\/+$/, "")}/p/${encodeURIComponent(this.config.project)}${path}`;
196+ const base = isLocal(server) ? LOCAL_BASE : server;
197+ return `${base.replace(/\/+$/, "")}/p/${encodeURIComponent(this.config.project)}${path}`;
167198 }
168199
200+ /** A local project's calls: answered in this process (local-store.ts). */
201+ private local: ((input: string, init?: RequestInit) => Promise<Response>) | undefined;
169203 agentPath(action: string): string {
170204 return `/a/${encodeURIComponent(this.config.agent)}/${action}`;
171205 }
Lines 209–216 at 318 (were 175–180 at 108)
175209 // Which client made the call (#29); the mods send theirs too.
176210 "x-abso-client": `abso-cli/${clientVersion()}`,
177211 ...(this.config.token && !this.config.visitor ? { authorization: `Bearer ${this.config.token}` } : {}),
212+ // A visitor says nothing about where it's reading from.
213+ ...(this.caller !== undefined && !this.config.visitor ? { [CALLER_HEADER]: this.caller } : {}),
178214 ...(contentType ? { "content-type": contentType } : {}),
179215 };
180216 }
Lines 220–231 at 318 (were 184–189 at 108)
184220 * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).
185221 */
186222 send(url: string, init: RequestInit = {}): Promise<Response> {
223+ if (isLocal(this.config.server)) {
224+ const dir = this.config.localStore;
225+ if (dir === undefined) return Promise.reject(new UsageError(NO_STORE));
226+ this.local ??= localFetch(dir);
227+ return this.local(url, init);
228+ }
187229 if (!this.config.visitor) return fetch(url, init);
188230 if ((init.method ?? "GET") !== "GET")
189231 return Promise.reject(new ApiError("a folder that reads signed out sends only reads"));
Lines 243–249 at 318 (were 201–206 at 108)
201243 if (this.config.visitor && method !== "GET")
202244 throw new ApiError(`${path}: a folder that reads signed out sends only reads`);
203245 const sent = body === undefined ? undefined : JSON.stringify(body);
246+ const requestId = method === "POST" ? randomUUID() : undefined;
204247 const timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent));
205248 // A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6
206249 // address timed out, and the same command went through seconds later). Nothing went out, so
Lines 252–267 at 318 (were 209–219 at 108)
209252 try {
210253 res = await this.send(this.url(path, server), {
211254 method,
212− headers: this.headers(sent === undefined ? undefined : "application/json"),
255+ headers: {
256+ ...this.headers(sent === undefined ? undefined : "application/json"),
257+ ...(requestId ? { "Idempotency-Key": requestId } : {}),
258+ },
213259 ...(sent === undefined ? {} : { body: sent }),
214260 signal: AbortSignal.timeout(timeoutMs),
215261 });
216262 } catch (err) {
263+ // A local project's refusal (no store, a Node without SQLite) says itself.
264+ if (err instanceof UsageError) throw err;
217265 const e = err as Error;
218266 const why =
219267 e.name === "TimeoutError"
Lines 295–303 at 318 (were 247–253 at 108)
247295 res.status,
248296 );
249297 try {
250− return JSON.parse(text) as T;
298+ const parsed = JSON.parse(text) as T;
299+ noteSeat(parsed);
300+ return parsed;
251301 } catch {
252302 throw new ApiError(
253303 `${method} ${path} answered with something that isn't JSON: ${text.slice(0, 300)}`,
Lines 728–775 at 318 (were 678–683 at 108)
678728 return this.#threads(this.#issues("POST", this.agentPath(`reply/${id}`), body));
679729 }
680730
731+ /** A groups call, with a server from before groups named as that rather than a bare 404. */
732+ async #groups<T>(call: Promise<T>): Promise<T> {
733+ try {
734+ return await call;
735+ } catch (err) {
736+ if (err instanceof ApiError && err.status === 404 && /no such issues route|reads have no/.test(err.message))
737+ throw new ApiError(`${this.config.server} doesn't have groups yet`, 404);
738+ throw err;
739+ }
740+ }
742+ /** The project's groups this agent can see. */
743+ groupList(): Promise<{ groups: readonly GroupSummary[] }> {
744+ return this.#groups(this.#issues("GET", this.agentPath("groups")));
745+ }
747+ /** One group's settings and roster, by name or id. */
748+ group(ref: string): Promise<GroupShown> {
749+ return this.#groups(this.#issues("GET", this.agentPath(`group/${encodeURIComponent(ref)}`)));
750+ }
752+ /** A page of a group's history, newest first, and the `before` that reads further back (null at the start). */
753+ groupEvents(
754+ ref: string,
755+ q: { before?: number; limit?: number; kind?: string } = {},
756+ ): Promise<{ events: readonly GroupEvent[]; before: number | null }> {
757+ const qs = query({ before: q.before, limit: q.limit, kind: q.kind }).toString();
758+ return this.#groups(
759+ this.#issues("GET", this.agentPath(`group/${encodeURIComponent(ref)}/events${qs ? `?${qs}` : ""}`)),
760+ );
761+ }
763+ /** Make a group (ref undefined), or post, join, leave, add, remove or change settings in one. */
764+ groupWrite(
765+ ref: string | undefined,
766+ action: "post" | "join" | "leave" | "add" | "remove" | "settings" | undefined,
767+ body: Record<string, unknown>,
768+ ): Promise<GroupWrite> {
769+ const path = ref === undefined ? "groups" : `group/${encodeURIComponent(ref)}/${action}`;
770+ return this.#groups(this.#issues("POST", this.agentPath(path), body));
771+ }
681773 /** Takes back an ask this agent made, with a note on why; the one asked hears it. */
682774 withdraw(id: number, body: { note?: string }): Promise<{ ask: Ask; news?: IssueNews }> {
683775 return this.#issues("POST", this.agentPath(`withdraw/${id}`), body);
Lines 803–828 at 318 (were 711–716 at 108)
711803 return this.json("POST", `/visibility?visibility=${v}`, {});
712804 }
713805
806+ /** The project's auto-settle choice (abso-core 23): off, advise or settle, and how sure before abso settles. */
807+ autosettle(): Promise<AutosettleAnswer> {
808+ return this.json("GET", "/autosettle");
809+ }
811+ /** Change it (abso-core 23): an owner's key, or the shared token on staging. Without `at`, the server keeps its own. */
812+ setAutosettle(mode: AutosettleMode, at?: number): Promise<AutosettleAnswer> {
813+ return this.json("POST", `/autosettle?mode=${mode}${at === undefined ? "" : `&at=${at}`}`, {});
814+ }
816+ /** Auto-settle's history (abso-core 23): held pushes the model advised on, newest first. */
817+ autosettleHistory(): Promise<unknown> {
818+ return this.json("GET", "/autosettle/history");
819+ }
821+ /** One held push from the history, with each collision's calls to the model. */
822+ autosettleHold(id: number): Promise<unknown> {
823+ return this.json("GET", `/autosettle/history/${id}`);
824+ }
714826 /** Take back this agent's queued publishes (#39); refused while one is being checked. */
715827 unqueue(): Promise<{ pulled: readonly number[] }> {
716828 return this.json("POST", this.agentPath("unqueue"), {});
Lines 985–995 at 318 (were 873–878 at 108)
873985 return this.json("GET", `/compare?${query({ from, to, ...where })}`);
874986 }
875987
988+ /** Version `version` of shared with `versions` left out, or the refusal naming what builds on them. */
989+ without(version: number, versions: readonly number[]): Promise<WithoutAnswer> {
990+ return this.json("GET", `/without?${query({ version, versions: versions.join(",") })}`);
991+ }
876993 /** A message to the project's other agents (or those named), delivered once as news. */
877994 starting(
878995 text: string | null,
Lines 1016–1026 at 318 (were 899–904 at 108)
8991016 return this.json("POST", this.agentPath("news"), {});
9001017 }
9011018
1019+ /** A ticket that opens this agent's news stream once, within a minute (abso 690; news-stream.ts). */
1020+ newsTicket(): Promise<{ url: string; protocols: string[]; expiresAt: number | string }> {
1021+ return this.json("POST", this.agentPath("news/ticket"), {});
1022+ }
9021024 /** This agent's unpublished changes, file by file. */
9031025 diff(): Promise<DiffAnswer> {
9041026 return this.json("POST", this.agentPath("diff"), {});
Lines 1036–1043 at 318 (were 914–921 at 108)
9141036 return this.json("POST", this.agentPath("restore"), files === null ? { all: true } : { files });
9151037 }
9161038
917− why(file: string, line: number, view: View = {}): Promise<WhyAnswer> {
918− return this.json("GET", `/why?${query({ file, line, ...view })}`);
1039+ why(file: string, line: number, view: View = {}, version?: number): Promise<WhyAnswer> {
1040+ return this.json("GET", `/why?${query({ file, line, version, ...view })}`);
9191041 }
9201042
9211043 where(): Promise<WhereAnswer> {
MCP
compare on this site's /mcp
CLI
abso diff 108 318 client/src/api.ts --json
JSON
/christopher/abso-core/compare/108..318?file=client%2Fsrc%2Fapi.ts&format=json