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

Compare

+347 −40 in 31 places
Lines 2–10 at 318 (were 2–8 at 17)
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 17)
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–56 at 17)
4953 Where,
5054 WhereAnswer,
5155 WhyAnswer,
56+ WithoutAnswer,
5257} from "./history-answers.ts";
53−import type { Ask, Attachment, Draft, DraftBody, News as IssueNews, IssuePage, IssueRow } from "./issues-wire.ts";
58+import type {
59+ Ask,
60+ Attachment,
61+ Draft,
62+ DraftBody,
63+ GroupEvent,
64+ GroupShown,
65+ GroupSummary,
66+ GroupWrite,
67+ News as IssueNews,
68+ IssuePage,
69+ IssueRow,
70+ IssueSearchHit,
71+} from "./issues-wire.ts";
72+import { isLocal, LOCAL_BASE, localFetch, NO_STORE } from "./local-store.ts";
5473import type { Modes } from "./modes.ts";
5574
5675export * from "./api-answers.ts";
Lines 84–90 at 318 (were 65–71 at 17)
6584} from "./box-run.ts";
6685export * from "./ci-answers.ts";
6786export * from "./history-answers.ts";
68−export type { Ask, Attachment, Draft, DraftBody, IssueNews, IssuePage, IssueRow };
87+export type { Ask, Attachment, Draft, DraftBody, IssueNews, IssuePage, IssueRow, IssueSearchHit };
6988
7089/**
7190 * How long a call may take: the base, plus 1 s for each 100 KB it sends
Lines 95–111 at 318 (were 76–81 at 17)
7695 return sent === undefined ? baseMs : baseMs + Math.floor(Buffer.byteLength(sent) / 100_000) * 1000;
7796}
7897
98+/**
99+ * How long a publish or a land may take before the client stops waiting: the
100+ * server gives one request up to 2 minutes of work, so a small body can still
101+ * take that long (a large merge). Waiting less reported publishes as failed
102+ * that went on to land.
103+ */
104+export const PUBLISH_TIMEOUT_MS = 150_000;
106+/** The most versions the server's log sends at once. */
107+export const LOG_PAGE = 200;
79109/** A query string from the values that are set (null and undefined are left out). */
80110function query(values: Record<string, string | number | null | undefined>): URLSearchParams {
81111 const q = new URLSearchParams();
Lines 118–166 at 318 (were 88–93 at 17)
88118 return (typeof news === "string" ? [news] : [...news]).filter((s) => typeof s === "string" && s.trim() !== "");
89119}
90120
121+/** An issue copy's request: the source, and any texts given cleaned, by their source ids. */
122+export interface CopyBody {
123+ from: string;
124+ issue: number;
125+ title?: string;
126+ description?: string;
127+ comments?: { id: number; text?: string }[];
128+ asks?: { id: number; question?: string; answer?: string }[];
129+}
131+/** What a copy writes, as a dry run answers it. */
132+export interface CopyPlan {
133+ from: { project: string; issue: number };
134+ title: string;
135+ edited: ("title" | "description")[];
136+ labels: string[];
137+ closed: { how: "done" | "dropped" } | null;
138+ comments: { edited: boolean }[];
139+ asks: { edited: boolean }[];
140+ skipped: { comments: number[]; asks: number[] };
141+}
143+export type CopyAnswer =
144+ | { dryRun: true; plan: CopyPlan }
145+ | { ok: true; id: number; from: { project: string; issue: number }; skipped: { comments: number[]; asks: number[] } };
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+}
91164export class Api {
92165 readonly config: Config;
93166 readonly timeoutMs: number;
Lines 168–174 at 318 (were 95–101 at 17)
95168 /** Waits between tries when a run's stream breaks; tests shorten them. */
96169 readonly reconnectDelaysMs: readonly number[];
97170 readonly startRetryDelaysMs: readonly number[];
98− /** Another box of this agent for run, logs and fetch (--box or AVCS_BOX, #37); undefined is its own box. */
171+ /** Another box of this agent for run, logs and fetch (--box or ABSO_BOX, #37); undefined is its own box. */
99172 box: string | undefined;
100173
101174 constructor(
Lines 183–205 at 318 (were 110–125 at 17)
110183 this.startRetryDelaysMs = startRetryDelaysMs;
111184 }
112185
113− /** What a box run is for, for the server's box-run records (#39): X-Avcs-Kind on POST /run. */
186+ /** What a box run is for, for the server's box-run records (#39): X-Abso-Kind on POST /run. */
114187 runKind: RunKind = "run";
115188
116189 /** The Issues Worker (#54) this folder's issues calls go to; set by the issues commands (issues.ts). */
117190 issuesServer: string | undefined;
118191
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;
119195 url(path: string, server = this.config.server): string {
120− 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}`;
121198 }
122199
200+ /** A local project's calls: answered in this process (local-store.ts). */
201+ private local: ((input: string, init?: RequestInit) => Promise<Response>) | undefined;
123203 agentPath(action: string): string {
124204 return `/a/${encodeURIComponent(this.config.agent)}/${action}`;
125205 }
Lines 207–267 at 318 (were 127–154 at 17)
127207 headers(contentType?: string): Record<string, string> {
128208 return {
129209 // Which client made the call (#29); the mods send theirs too.
130− "x-avcs-client": `abso-cli/${clientVersion()}`,
131− ...(this.config.token ? { authorization: `Bearer ${this.config.token}` } : {}),
210+ "x-abso-client": `abso-cli/${clientVersion()}`,
211+ ...(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 } : {}),
132214 ...(contentType ? { "content-type": contentType } : {}),
133215 };
134216 }
135217
136− async json<T>(method: "GET" | "POST", path: string, body?: unknown, server = this.config.server): Promise<T> {
218+ /**
219+ * Every request this Api makes goes through here. In a visitor folder it never sends anything but a GET,
220+ * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).
221+ */
222+ 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+ }
229+ if (!this.config.visitor) return fetch(url, init);
230+ if ((init.method ?? "GET") !== "GET")
231+ return Promise.reject(new ApiError("a folder that reads signed out sends only reads"));
232+ return fetch(url, { ...init, redirect: "error" });
233+ }
235+ async json<T>(
236+ method: "GET" | "POST",
237+ path: string,
238+ body?: unknown,
239+ server = this.config.server,
240+ atLeastMs = 0,
241+ ): Promise<T> {
137242 let res: Response | undefined;
243+ if (this.config.visitor && method !== "GET")
244+ throw new ApiError(`${path}: a folder that reads signed out sends only reads`);
138245 const sent = body === undefined ? undefined : JSON.stringify(body);
139− const timeoutMs = timeoutFor(this.timeoutMs, sent);
246+ const requestId = method === "POST" ? randomUUID() : undefined;
247+ const timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent));
140248 // A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6
141249 // address timed out, and the same command went through seconds later). Nothing went out, so
142250 // a POST is as safe to send again as a GET.
143251 for (let attempt = 0; res === undefined; attempt++) {
144252 try {
145− res = await fetch(this.url(path, server), {
253+ res = await this.send(this.url(path, server), {
146254 method,
147− headers: this.headers(sent === undefined ? undefined : "application/json"),
255+ headers: {
256+ ...this.headers(sent === undefined ? undefined : "application/json"),
257+ ...(requestId ? { "Idempotency-Key": requestId } : {}),
258+ },
148259 ...(sent === undefined ? {} : { body: sent }),
149260 signal: AbortSignal.timeout(timeoutMs),
150261 });
151262 } catch (err) {
263+ // A local project's refusal (no store, a Node without SQLite) says itself.
264+ if (err instanceof UsageError) throw err;
152265 const e = err as Error;
153266 const why =
154267 e.name === "TimeoutError"
Lines 279–291 at 318 (were 166–172 at 17)
166279 await new Promise((ok) => setTimeout(ok, 500));
167280 }
168281 }
169− const text = await res.text();
282+ let text: string;
283+ try {
284+ text = await res.text();
285+ } catch (err) {
286+ const reason = err instanceof Error ? err.message : String(err);
287+ throw new ApiError(`${method} ${path} response body ended unexpectedly: ${reason}`, res.status);
288+ }
170289 // 409 is a refusal that says what to do (a drop took out lines your work builds on): print it as it is.
171290 if (!res.ok)
172291 throw new ApiError(
Lines 295–303 at 318 (were 176–182 at 17)
176295 res.status,
177296 );
178297 try {
179− return JSON.parse(text) as T;
298+ const parsed = JSON.parse(text) as T;
299+ noteSeat(parsed);
300+ return parsed;
180301 } catch {
181302 throw new ApiError(
182303 `${method} ${path} answered with something that isn't JSON: ${text.slice(0, 300)}`,
Lines 355–361 at 318 (were 234–240 at 17)
234355 });
235356 let res: Response;
236357 try {
237− res = await fetch(`${this.url("/serve")}?${q}`, {
358+ res = await this.send(`${this.url("/serve")}?${q}`, {
238359 method: "POST",
239360 headers: this.headers(),
240361 signal: AbortSignal.timeout(20 * 60_000),
Lines 376–391 at 318 (were 255–267 at 17)
255376 async prep(command: string, tarGz: Uint8Array<ArrayBuffer>): Promise<PrepAnswer> {
256377 let res: Response;
257378 try {
258− res = await fetch(`${this.url(this.agentPath("prep"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`, {
259− method: "POST",
260− headers: this.headers("application/gzip"),
261− body: tarGz,
262− // A setup command can take minutes (npm ci, a browser download).
263− signal: AbortSignal.timeout(30 * 60_000),
264− });
379+ res = await this.send(
380+ `${this.url(this.agentPath("prep"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`,
381+ {
382+ method: "POST",
383+ headers: this.headers("application/gzip"),
384+ body: tarGz,
385+ // A setup command can take minutes (npm ci, a browser download).
386+ signal: AbortSignal.timeout(30 * 60_000),
387+ },
388+ );
265389 } catch (err) {
266390 const e = err as Error;
267391 throw new ApiError(
Lines 401–407 at 318 (were 277–283 at 17)
277401 async unprep(): Promise<boolean> {
278402 let res: Response;
279403 try {
280− res = await fetch(
404+ res = await this.send(
281405 `${this.url(this.agentPath("prep"))}${this.box ? `?box=${encodeURIComponent(this.box)}` : ""}`,
282406 { method: "DELETE", headers: this.headers(), signal: AbortSignal.timeout(this.timeoutMs) },
283407 );
Lines 437–443 at 318 (were 313–319 at 17)
313437 async bytes(method: "GET" | "PUT", path: string, body?: Uint8Array): Promise<Uint8Array> {
314438 let res: Response;
315439 try {
316− res = await fetch(this.url(path), {
440+ res = await this.send(this.url(path), {
317441 method,
318442 headers: this.headers(body === undefined ? undefined : "application/octet-stream"),
319443 ...(body === undefined ? {} : { body: body as Uint8Array<ArrayBuffer> }),
Lines 464–476 at 318 (were 340–346 at 17)
340464 }
341465
342466 publish(message: string, asIs = false): Promise<PublishAnswer> {
343− return this.json("POST", this.agentPath("publish"), { message, ...(asIs ? { asIs: true } : {}) });
467+ return this.json(
468+ "POST",
469+ this.agentPath("publish"),
470+ { message, ...(asIs ? { asIs: true } : {}) },
471+ undefined,
472+ PUBLISH_TIMEOUT_MS,
473+ );
344474 }
345475
346476 /** One change (#44). */
Lines 491–511 at 318 (were 361–370 at 17)
361491 /** A call to the Issues Worker (#54), with the same token. */
362492 #issues<T>(method: "GET" | "POST", path: string, body?: unknown): Promise<T> {
363493 if (this.issuesServer === undefined)
364− throw new ApiError(`${this.config.server} has no Issues Worker beside it; AVCS_ISSUES_SERVER names one`);
494+ throw new ApiError(`${this.config.server} has no Issues Worker beside it; ABSO_ISSUES_SERVER names one`);
365495 return this.json(method, path, body, this.issuesServer);
366496 }
367497
498+ /** An ask-thread call, with a server from before ask threads named as that rather than a bare 404. */
499+ async #threads<T>(call: Promise<T>): Promise<T> {
500+ try {
501+ return await call;
502+ } catch (err) {
503+ if (err instanceof ApiError && err.status === 404 && /no such issues route/.test(err.message))
504+ throw new ApiError(`${this.config.server} doesn't have ask threads yet`, 404);
505+ throw err;
506+ }
507+ }
368509 /** Issues, most recently updated first. */
369510 issues(
370511 q: { status?: string; agent?: string; parent?: number; open?: boolean; labels?: readonly string[] } = {},
Lines 516–529 at 318 (were 375–380 at 17)
375516 );
376517 }
377518
519+ /**
520+ * The project's issues matching q, best first: by its words and, where
521+ * the server has it on, by what it means.
522+ */
523+ issueSearch(q: string, limit?: number): Promise<{ hits: readonly IssueSearchHit[] }> {
524+ return this.#issues("GET", `/search?${query({ q, limit })}`);
525+ }
378527 /** Every label in use, with how many issues have it and how many of those are open. */
379528 issueLabels(): Promise<{ labels: readonly { label: string; open: number; total: number }[] }> {
380529 return this.#issues("GET", "/labels");
Lines 533–548 at 318 (were 384–389 at 17)
384533 return this.#issues("GET", `/issue/${id}`);
385534 }
386535
536+ /** The asks this agent sent: the open ones, then the latest answered, each with its thread. */
537+ asked(): Promise<{ asks: readonly (Ask & { title: string | null })[] }> {
538+ return this.#threads(this.#issues("GET", this.agentPath("asked")));
539+ }
541+ /** One ask, open or closed, with its thread and who it waits on. */
542+ askThread(id: number): Promise<{ ask: Ask & { title: string | null } }> {
543+ return this.#threads(this.#issues("GET", `/ask/${id}`));
544+ }
387546 /** Open asks of someone (an agent, or person:<id>), soonest due first; every open ask without `of`. */
388547 waiting(of?: string): Promise<{ asks: readonly (Ask & { title: string | null })[] }> {
389548 return this.#issues("GET", `/waiting?${query({ of })}`);
Lines 566–578 at 318 (were 407–419 at 17)
407566 /** Uploads an image to the Issues Worker (abso issue 171): it checks the type by the bytes, strips metadata and answers its id. */
408567 async attachmentUpload(bytes: Uint8Array, name: string): Promise<Attachment> {
409568 if (this.issuesServer === undefined)
410− throw new ApiError(`${this.config.server} has no Issues Worker beside it; AVCS_ISSUES_SERVER names one`);
569+ throw new ApiError(`${this.config.server} has no Issues Worker beside it; ABSO_ISSUES_SERVER names one`);
411570 const path = this.agentPath("attachments");
412571 let res: Response;
413572 try {
414− res = await fetch(this.url(path, this.issuesServer), {
573+ res = await this.send(this.url(path, this.issuesServer), {
415574 method: "POST",
416− headers: { ...this.headers("application/octet-stream"), "x-avcs-name": encodeURIComponent(name) },
575+ headers: { ...this.headers("application/octet-stream"), "x-abso-name": encodeURIComponent(name) },
417576 body: bytes as Uint8Array<ArrayBuffer>,
418577 signal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),
419578 });
Lines 594–638 at 318 (were 435–445 at 17)
435594 return JSON.parse(text) as Attachment;
436595 }
437596
597+ /**
598+ * Copies issue `body.issue` of this project into project `to`, keeping
599+ * authors and times: the Issues server reads the source itself, and only
600+ * texts may be given cleaned. A dry run answers the plan and writes nothing.
601+ */
602+ issueCopy(to: string, body: CopyBody & { dryRun?: boolean }): Promise<CopyAnswer> {
603+ const there = new Api({ ...this.config, project: to }, this.timeoutMs);
604+ there.issuesServer = this.issuesServer;
605+ return there.#issues("POST", there.agentPath("copy"), body);
606+ }
438608 /** Where an attachment is served. */
439609 attachmentUrl(id: string): string {
440610 return this.url(`/attachments/${id}`, this.issuesServer);
441611 }
442612
613+ /** An attachment's bytes, or with `source` the svg it was drawn from; refused past `max` bytes. */
614+ async attachmentBytes(id: string, source: boolean, max: number): Promise<Uint8Array> {
615+ if (this.issuesServer === undefined)
616+ throw new ApiError(`${this.config.server} has no Issues Worker beside it; ABSO_ISSUES_SERVER names one`);
617+ const url = `${this.attachmentUrl(id)}${source ? "/source" : ""}`;
618+ let res: Response;
619+ try {
620+ res = await this.send(url, {
621+ headers: this.headers(),
622+ signal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),
623+ });
624+ } catch (err) {
625+ const e = err as Error;
626+ throw new ApiError(
627+ `could not reach ${this.issuesServer}: ${(e.cause as Error | undefined)?.message ?? e.message}`,
628+ );
629+ }
630+ if (!res.ok) throw new ApiError(`${url} answered ${res.status}: ${errorSentence(await res.text())}`, res.status);
631+ const bytes = new Uint8Array(await res.arrayBuffer());
632+ if (bytes.length > max) throw new ApiError(`${url} sent ${bytes.length} bytes, more than an attachment may be`);
633+ return bytes;
634+ }
443636 /** An edit (abso issue 3): it tells the issue's watchers, and `also`, unless `notify` is false. null clears a parent or Agent. */
444637 issueEdit(
445638 id: number,
Lines 706–775 at 318 (were 513–529 at 17)
513706 due?: string;
514707 blocks?: number[];
515708 options?: string[];
516− }): Promise<{ id: number; news?: IssueNews }> {
709+ attachments?: string[];
710+ }): Promise<{ id: number; news?: IssueNews; attachments?: string[] }> {
517711 return this.#issues("POST", this.agentPath("ask"), body);
518712 }
519713
520714 answer(
521715 id: number,
522− body: { words?: string; option?: number | string; note?: string; done?: boolean },
716+ body: { words?: string; option?: number | string; note?: string; done?: boolean; attachments?: string[] },
523717 ): Promise<{ ask: Ask; news?: IssueNews }> {
524718 return this.#issues("POST", this.agentPath(`answer/${id}`), body);
525719 }
526720
721+ /** Acknowledges an ask of this agent without answering it: the asker hears it, and the ask stays open. */
722+ ack(id: number, body: { note?: string }): Promise<{ ask: Ask; news?: IssueNews }> {
723+ return this.#issues("POST", this.agentPath(`ack/${id}`), body);
724+ }
726+ /** Adds to an ask's thread, as its asker or the one asked; the other side hears it, and the ask stays as it is. */
727+ reply(id: number, body: { text: string; question?: boolean }): Promise<{ ask: Ask; news?: IssueNews }> {
728+ return this.#threads(this.#issues("POST", this.agentPath(`reply/${id}`), body));
729+ }
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+ }
527773 /** Takes back an ask this agent made, with a note on why; the one asked hears it. */
528774 withdraw(id: number, body: { note?: string }): Promise<{ ask: Ask; news?: IssueNews }> {
529775 return this.#issues("POST", this.agentPath(`withdraw/${id}`), body);
Lines 803–828 at 318 (were 557–562 at 17)
557803 return this.json("POST", `/visibility?visibility=${v}`, {});
558804 }
559805
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+ }
560826 /** Take back this agent's queued publishes (#39); refused while one is being checked. */
561827 unqueue(): Promise<{ pulled: readonly number[] }> {
562828 return this.json("POST", this.agentPath("unqueue"), {});
Lines 904–914 at 318 (were 638–643 at 17)
638904 return this.json("GET", version === undefined ? "/ci" : `/ci?${query({ version })}`);
639905 }
640906
907+ /** The project's pipeline runs, newest first; one run with its jobs; or one job's log (`log` is pipeline.job). */
908+ pipelineRuns(run?: number, log?: string): Promise<unknown> {
909+ return this.json("GET", run === undefined ? "/pipelines" : `/pipelines?${query({ run, log })}`);
910+ }
641912 /** Ends every /latest link handed out so far; answers CI's state with the new link. */
642913 ciRevoke(): Promise<CiStatus> {
643914 return this.json("POST", "/ci/revoke", {});
Lines 926–932 at 318 (were 655–661 at 17)
655926
656927 /** Land never queues: with the merge queue on, the server refuses it (#39). */
657928 land(message: string): Promise<Exclude<PublishAnswer, { queued: number }>> {
658− return this.json("POST", this.agentPath("land"), { message });
929+ return this.json("POST", this.agentPath("land"), { message }, undefined, PUBLISH_TIMEOUT_MS);
659930 }
660931
661932 draftSync(): Promise<DraftSyncAnswer> {
Lines 948–978 at 318 (were 677–686 at 17)
677948 }
678949
679950 /** The versions of a space, newest first; with `path`, only those that changed it. */
680− log(where: Where, limit?: number, path?: string): Promise<LogAnswer> {
681− return this.json("GET", `/log?${query({ ...where, limit, path })}`);
951+ /**
952+ * The versions newest first, below `before` when it's given. The server
953+ * sends at most LOG_PAGE at a time, so a longer log is read page by page,
954+ * following each page's next. `next` on the answer says older ones are left.
955+ */
956+ async log(where: Where, limit?: number, path?: string, before?: number): Promise<LogAnswer> {
957+ let page = await this.#logPage(where, limit === undefined ? undefined : Math.min(limit, LOG_PAGE), path, before);
958+ const versions = [...page.versions];
959+ while (limit !== undefined && versions.length < limit && page.next !== undefined) {
960+ page = await this.#logPage(where, Math.min(limit - versions.length, LOG_PAGE), path, page.next);
961+ versions.push(...page.versions);
962+ }
963+ const { next, ...rest } = page;
964+ return { ...rest, versions, ...(next !== undefined ? { next } : {}) };
682965 }
683966
967+ #logPage(
968+ where: Where,
969+ limit: number | undefined,
970+ path: string | undefined,
971+ before: number | undefined,
972+ ): Promise<LogAnswer> {
973+ return this.json("GET", `/log?${query({ ...where, limit, path, before })}`);
974+ }
684976 show(version: number, where: Where): Promise<ShowAnswer> {
685977 return this.json("GET", `/show?${query({ version, ...where })}`);
686978 }
Lines 985–995 at 318 (were 693–698 at 17)
693985 return this.json("GET", `/compare?${query({ from, to, ...where })}`);
694986 }
695987
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+ }
696993 /** A message to the project's other agents (or those named), delivered once as news. */
697994 starting(
698995 text: string | null,
Lines 1016–1043 at 318 (were 719–736 at 17)
7191016 return this.json("POST", this.agentPath("news"), {});
7201017 }
7211018
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+ }
7221024 /** This agent's unpublished changes, file by file. */
7231025 diff(): Promise<DiffAnswer> {
7241026 return this.json("POST", this.agentPath("diff"), {});
7251027 }
7261028
1029+ /** Another agent's recorded, unpublished changes, file by file: read only, as the website's drafts show them. */
1030+ diffOf(agent: string): Promise<DiffAnswer> {
1031+ return this.json("GET", `/diff?${query({ agent })}`);
1032+ }
7271034 /** Discard this agent's unpublished changes to `files` (null: all of them). */
7281035 restore(files: readonly string[] | null): Promise<RestoreAnswer> {
7291036 return this.json("POST", this.agentPath("restore"), files === null ? { all: true } : { files });
7301037 }
7311038
732− why(file: string, line: number, view: View = {}): Promise<WhyAnswer> {
733− 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 })}`);
7341041 }
7351042
7361043 where(): Promise<WhereAnswer> {
Lines 1057–1065 at 318 (were 750–758 at 17)
7501057 */
7511058 async run(command: string, tarGz: Uint8Array<ArrayBuffer>, io: RunIO): Promise<number> {
7521059 const res = await postRun(this, command, tarGz, io.onRetry, io.replace, io.fresh);
753− // X-Avcs-Box: cold means the box started for this run; X-Avcs-Prep says whether it started from the prep (#37).
754− io.onBox?.(res.headers.get("x-avcs-box") === "cold", res.headers.get("x-avcs-prep") ?? undefined);
755− return follow(this, res, res.headers.get("x-avcs-run"), { at: 0, errAt: 0 }, io);
1060+ // X-Abso-Box: cold means the box started for this run; X-Abso-Prep says whether it started from the prep (#37).
1061+ io.onBox?.(res.headers.get("x-abso-box") === "cold", res.headers.get("x-abso-prep") ?? undefined);
1062+ return follow(this, res, res.headers.get("x-abso-run"), { at: 0, errAt: 0 }, io);
7561063 }
7571064
7581065 /**
Lines 1073–1079 at 318 (were 766–772 at 17)
7661073 replace = false,
7671074 ): Promise<string> {
7681075 const res = await postRun(this, command, tarGz, onRetry, replace);
769− const id = res.headers.get("x-avcs-run");
1076+ const id = res.headers.get("x-abso-run");
7701077 if (id === null) {
7711078 // No id: the box failed before the job started ({"error"} in the body), or the server can't detach.
7721079 await consumeRun(res, { out: () => {} }, { at: 0, errAt: 0 });
Lines 1087–1093 at 318 (were 780–786 at 17)
7801087 async logs(id: string, io: RunIO): Promise<number> {
7811088 let res: Response;
7821089 try {
783− res = await fetch(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });
1090+ res = await this.send(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });
7841091 } catch (err) {
7851092 const e = err as Error;
7861093 throw new ApiError(
MCP
compare on this site's /mcp
CLI
abso diff 17 318 client/src/api.ts --json
JSON
/christopher/abso-core/compare/17..318?file=client%2Fsrc%2Fapi.ts&format=json