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
show on this site's /mcp
CLI
abso show 88 --json
JSON
/christopher/abso-core/versions/88?format=json

Every request a folder's Api makes goes through one send(): a folder that reads signed out sends only GETs and follows no redirect on every path, box runs and serve included.

of shared·pinch··Not checked

Version 87 · Files at version 88

3 files, 56 lines added, 20 removed.

--- a/client/src/api.ts
+++ b/client/src/api.ts
@@ -179,6 +179,17 @@
179179 };
180180 }
181181
182+ /**
183+ * Every request this Api makes goes through here. In a visitor folder it never sends anything but a GET,
184+ * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).
185+ */
186+ send(url: string, init: RequestInit = {}): Promise<Response> {
187+ if (!this.config.visitor) return fetch(url, init);
188+ if ((init.method ?? "GET") !== "GET")
189+ return Promise.reject(new ApiError("a folder that reads signed out sends only reads"));
190+ return fetch(url, { ...init, redirect: "error" });
191+ }
182193 async json<T>(
183194 method: "GET" | "POST",
184195 path: string,
@@ -187,9 +198,8 @@
187198 atLeastMs = 0,
188199 ): Promise<T> {
189200 let res: Response | undefined;
190− // A visitor folder only reads, and follows no redirect, so nothing it sends goes anywhere it didn't name.
191− const visitor = this.config.visitor === true;
192− if (visitor && method !== "GET") throw new ApiError(`${path}: a folder that reads signed out sends only reads`);
201+ if (this.config.visitor && method !== "GET")
202+ throw new ApiError(`${path}: a folder that reads signed out sends only reads`);
193203 const sent = body === undefined ? undefined : JSON.stringify(body);
194204 const timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent));
195205 // A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6
@@ -197,11 +207,10 @@
197207 // a POST is as safe to send again as a GET.
198208 for (let attempt = 0; res === undefined; attempt++) {
199209 try {
200− res = await fetch(this.url(path, server), {
210+ res = await this.send(this.url(path, server), {
201211 method,
202212 headers: this.headers(sent === undefined ? undefined : "application/json"),
203213 ...(sent === undefined ? {} : { body: sent }),
204− ...(visitor ? { redirect: "error" as const } : {}),
205214 signal: AbortSignal.timeout(timeoutMs),
206215 });
207216 } catch (err) {
@@ -290,7 +299,7 @@
290299 });
291300 let res: Response;
292301 try {
293− res = await fetch(`${this.url("/serve")}?${q}`, {
302+ res = await this.send(`${this.url("/serve")}?${q}`, {
294303 method: "POST",
295304 headers: this.headers(),
296305 signal: AbortSignal.timeout(20 * 60_000),
@@ -311,13 +320,16 @@
311320 async prep(command: string, tarGz: Uint8Array<ArrayBuffer>): Promise<PrepAnswer> {
312321 let res: Response;
313322 try {
314− res = await fetch(`${this.url(this.agentPath("prep"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`, {
315− method: "POST",
316− headers: this.headers("application/gzip"),
317− body: tarGz,
318− // A setup command can take minutes (npm ci, a browser download).
319− signal: AbortSignal.timeout(30 * 60_000),
320− });
323+ res = await this.send(
324+ `${this.url(this.agentPath("prep"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`,
325+ {
326+ method: "POST",
327+ headers: this.headers("application/gzip"),
328+ body: tarGz,
329+ // A setup command can take minutes (npm ci, a browser download).
330+ signal: AbortSignal.timeout(30 * 60_000),
331+ },
332+ );
321333 } catch (err) {
322334 const e = err as Error;
323335 throw new ApiError(
@@ -333,7 +345,7 @@
333345 async unprep(): Promise<boolean> {
334346 let res: Response;
335347 try {
336− res = await fetch(
348+ res = await this.send(
337349 `${this.url(this.agentPath("prep"))}${this.box ? `?box=${encodeURIComponent(this.box)}` : ""}`,
338350 { method: "DELETE", headers: this.headers(), signal: AbortSignal.timeout(this.timeoutMs) },
339351 );
@@ -369,7 +381,7 @@
369381 async bytes(method: "GET" | "PUT", path: string, body?: Uint8Array): Promise<Uint8Array> {
370382 let res: Response;
371383 try {
372− res = await fetch(this.url(path), {
384+ res = await this.send(this.url(path), {
373385 method,
374386 headers: this.headers(body === undefined ? undefined : "application/octet-stream"),
375387 ...(body === undefined ? {} : { body: body as Uint8Array<ArrayBuffer> }),
@@ -491,7 +503,7 @@
491503 const path = this.agentPath("attachments");
492504 let res: Response;
493505 try {
494− res = await fetch(this.url(path, this.issuesServer), {
506+ res = await this.send(this.url(path, this.issuesServer), {
495507 method: "POST",
496508 headers: { ...this.headers("application/octet-stream"), "x-abso-name": encodeURIComponent(name) },
497509 body: bytes as Uint8Array<ArrayBuffer>,
@@ -538,7 +550,7 @@
538550 const url = `${this.attachmentUrl(id)}${source ? "/source" : ""}`;
539551 let res: Response;
540552 try {
541− res = await fetch(url, {
553+ res = await this.send(url, {
542554 headers: this.headers(),
543555 signal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),
544556 });
@@ -936,7 +948,7 @@
936948 async logs(id: string, io: RunIO): Promise<number> {
937949 let res: Response;
938950 try {
939− res = await fetch(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });
951+ res = await this.send(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });
940952 } catch (err) {
941953 const e = err as Error;
942954 throw new ApiError(
--- a/client/src/box-run.ts
+++ b/client/src/box-run.ts
@@ -150,7 +150,7 @@
150150 try {
151151 // stderr=split: the box's stderr comes apart from stdout (7a5a111); older servers ignore it.
152152 // replace=1: stop the runs still going in the box first; without it the server answers 409 (#25).
153− const answer = await fetch(
153+ const answer = await api.send(
154154 `${api.url(api.agentPath("run"))}?cmd=${encodeURIComponent(command)}&stderr=split${replace ? "&replace=1" : ""}${fresh ? "&fresh=1" : ""}${boxQuery(api.box)}`,
155155 {
156156 method: "POST",
@@ -216,7 +216,7 @@
216216 onReconnect?.(last, attempt + 1);
217217 await new Promise((ok) => setTimeout(ok, delay));
218218 try {
219− const res = await fetch(followUrl(api, id, seen), { headers: api.headers() });
219+ const res = await api.send(followUrl(api, id, seen), { headers: api.headers() });
220220 if (res.status === 404)
221221 throw new ApiError(
222222 `the run broke off (${why}) and is gone from the box: ${errorSentence(await res.text())}`,
--- a/client/test/visitor.test.ts
+++ b/client/test/visitor.test.ts
@@ -16,6 +16,7 @@
1616import { tmpdir } from "node:os";
1717import { join, resolve } from "node:path";
1818import { after, before, describe, it } from "node:test";
19+import { Api } from "../src/api.ts";
1920import { writeBox } from "../src/box.ts";
2021import { writeConfig } from "../src/config.ts";
2122import { isPublic } from "../src/join-commands.ts";
@@ -257,6 +258,29 @@
257258 assert.match(runs[0]!.stderr, /isn't signed in to .*abso login signs it in/);
258259 });
259260
261+ it("every request its Api makes goes through one send: reads only, no redirect, no sign-in", async () => {
262+ const real = globalThis.fetch;
263+ const calls: RequestInit[] = [];
264+ globalThis.fetch = (async (_input: unknown, init?: RequestInit) => {
265+ calls.push(init ?? {});
266+ return new Response("{}", { status: 200 });
267+ }) as typeof fetch;
268+ try {
269+ const visitor = new Api({ server: url, project: "abso-core", agent: "", visitor: true, token: TOKEN });
270+ await visitor.send(`${url}/p/abso-core/serve`, { headers: visitor.headers() });
271+ await assert.rejects(visitor.send(`${url}/p/abso-core/a/x/run`, { method: "POST" }), /sends only reads/);
272+ const member = new Api({ server: url, project: "abso-core", agent: "x", token: TOKEN });
273+ await member.send(`${url}/p/abso-core/serve`, { headers: member.headers() });
274+ } finally {
275+ globalThis.fetch = real;
276+ }
277+ assert.equal(calls.length, 2);
278+ assert.equal(calls[0]!.redirect, "error");
279+ assert.equal(new Headers(calls[0]!.headers).get("authorization"), null);
280+ assert.equal(calls[1]!.redirect, undefined);
281+ assert.equal(new Headers(calls[1]!.headers).get("authorization"), `Bearer ${TOKEN}`);
282+ });
260284 it("runs only its reads: every other command is refused before any call, and a new command fails here", async () => {
261285 const sorted = new Set([...Object.keys(VISITOR_READS), ...VISITOR_ELSEWHERE, ...REFUSED]);
262286 for (const name of Object.keys(commandTable()))