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

Compare

+92 −2 in 11 places
Lines 4–10 at 318 (were 4–9 at 228)
44
55import { randomUUID } from "node:crypto";
66import { setDefaultResultOrder } from "node:dns";
7+import { CALLER_HEADER } from "../../src/caller.ts";
78import type {
89 ChangeAnswer,
910 DraftSyncAnswer,
Lines 20–26 at 318 (were 19–24 at 228)
1920 SyncAnswer,
2021} from "./api-answers.ts";
2122import { ApiError, errorSentence, neverSent } from "./api-error.ts";
23+import { UsageError } from "./args.ts";
2224import type { AutosettleAnswer, AutosettleMode } from "./autosettle-commands.ts";
2325import {
2426 boxQuery,
Lines 60–75 at 318 (were 58–68 at 228)
5860 Attachment,
5961 Draft,
6062 DraftBody,
63+ GroupEvent,
64+ GroupShown,
65+ GroupSummary,
66+ GroupWrite,
6167 News as IssueNews,
6268 IssuePage,
6369 IssueRow,
6470 IssueSearchHit,
6571} from "./issues-wire.ts";
72+import { isLocal, LOCAL_BASE, localFetch, NO_STORE } from "./local-store.ts";
6673import type { Modes } from "./modes.ts";
6774
6875export * from "./api-answers.ts";
Lines 144–166 at 318 (were 137–142 at 228)
137144 | { dryRun: true; plan: CopyPlan }
138145 | { ok: true; id: number; from: { project: string; issue: number }; skipped: { comments: number[]; asks: number[] } };
139146
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+}
140164export class Api {
141165 readonly config: Config;
142166 readonly timeoutMs: number;
Lines 189–205 at 318 (were 165–174 at 228)
165189 /** The Issues Worker (#54) this folder's issues calls go to; set by the issues commands (issues.ts). */
166190 issuesServer: string | undefined;
167191
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;
168195 url(path: string, server = this.config.server): string {
169− 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}`;
170198 }
171199
200+ /** A local project's calls: answered in this process (local-store.ts). */
201+ private local: ((input: string, init?: RequestInit) => Promise<Response>) | undefined;
172203 agentPath(action: string): string {
173204 return `/a/${encodeURIComponent(this.config.agent)}/${action}`;
174205 }
Lines 209–216 at 318 (were 178–183 at 228)
178209 // Which client made the call (#29); the mods send theirs too.
179210 "x-abso-client": `abso-cli/${clientVersion()}`,
180211 ...(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 } : {}),
181214 ...(contentType ? { "content-type": contentType } : {}),
182215 };
183216 }
Lines 220–231 at 318 (were 187–192 at 228)
187220 * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).
188221 */
189222 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+ }
190229 if (!this.config.visitor) return fetch(url, init);
191230 if ((init.method ?? "GET") !== "GET")
192231 return Promise.reject(new ApiError("a folder that reads signed out sends only reads"));
Lines 260–267 at 318 (were 221–226 at 228)
221260 signal: AbortSignal.timeout(timeoutMs),
222261 });
223262 } catch (err) {
263+ // A local project's refusal (no store, a Node without SQLite) says itself.
264+ if (err instanceof UsageError) throw err;
224265 const e = err as Error;
225266 const why =
226267 e.name === "TimeoutError"
Lines 295–303 at 318 (were 254–260 at 228)
254295 res.status,
255296 );
256297 try {
257− return JSON.parse(text) as T;
298+ const parsed = JSON.parse(text) as T;
299+ noteSeat(parsed);
300+ return parsed;
258301 } catch {
259302 throw new ApiError(
260303 `${method} ${path} answered with something that isn't JSON: ${text.slice(0, 300)}`,
Lines 728–775 at 318 (were 685–690 at 228)
685728 return this.#threads(this.#issues("POST", this.agentPath(`reply/${id}`), body));
686729 }
687730
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+ }
688773 /** Takes back an ask this agent made, with a note on why; the one asked hears it. */
689774 withdraw(id: number, body: { note?: string }): Promise<{ ask: Ask; news?: IssueNews }> {
690775 return this.#issues("POST", this.agentPath(`withdraw/${id}`), body);
Lines 1016–1026 at 318 (were 931–936 at 228)
9311016 return this.json("POST", this.agentPath("news"), {});
9321017 }
9331018
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+ }
9341024 /** This agent's unpublished changes, file by file. */
9351025 diff(): Promise<DiffAnswer> {
9361026 return this.json("POST", this.agentPath("diff"), {});
MCP
compare on this site's /mcp
CLI
abso diff 228 318 client/src/api.ts --json
JSON
/christopher/abso-core/compare/228..318?file=client%2Fsrc%2Fapi.ts&format=json