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 277 --json
JSON
/christopher/abso-core/versions/277?format=json

Seats say who is calling, and a seat's earlier chat can hear that another chat picked it up.

of shared·groups··Not checked

The CLI sends X-Abso-Caller on every call: the chat's session id (CLAUDE_CODE_SESSION_ID, when abso runs in a Claude Code chat), the computer's name and the folder, base64url JSON, at most 512 bytes. A folder that reads signed out sends none. src/caller.ts reads it back exactly or not at all. It's information only; the agent key still decides who is calling.

The engine's seatNotice(agent, place, key) queues one fixed-wording news line to that seat, once per key. An answer carrying seatNotice is printed once with the news.

Tests: client caller and visitor, worker/project seat-notice, announce-person, news-*, tells (29 pass); tsc clean.

Version 276 · Files at version 277

8 files, 265 lines added, 5 removed.

--- a/client/src/api.ts
+++ b/client/src/api.ts
@@ -4,6 +4,7 @@
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,
@@ -141,6 +142,23 @@
141142 | { dryRun: true; plan: CopyPlan }
142143 | { ok: true; id: number; from: { project: string; issue: number }; skipped: { comments: number[]; asks: number[] } };
143144
145+/**
146+ * The server's line when another chat just used this seat (seatNotice on an answer): kept until main() prints it with
147+ * the news, once however many answers carried it.
148+ */
149+const seatNotices = new Set<string>();
150+function noteSeat(answer: unknown): void {
151+ if (typeof answer !== "object" || answer === null || Array.isArray(answer)) return;
152+ const line = (answer as { seatNotice?: unknown }).seatNotice;
153+ if (typeof line === "string" && line !== "" && line.length <= 300 && !/[\u0000-\u001f]/.test(line))
154+ seatNotices.add(line);
155+}
156+export function takeSeatNotices(): string[] {
157+ const out = [...seatNotices];
158+ seatNotices.clear();
159+ return out;
160+}
144162export class Api {
145163 readonly config: Config;
146164 readonly timeoutMs: number;
@@ -169,6 +187,9 @@
169187 /** The Issues Worker (#54) this folder's issues calls go to; set by the issues commands (issues.ts). */
170188 issuesServer: string | undefined;
171189
190+ /** Who is calling this seat (src/caller.ts): this chat's session, this computer and this folder. Set by open(). */
191+ caller: string | undefined;
172193 url(path: string, server = this.config.server): string {
173194 return `${server.replace(/\/+$/, "")}/p/${encodeURIComponent(this.config.project)}${path}`;
174195 }
@@ -182,6 +203,8 @@
182203 // Which client made the call (#29); the mods send theirs too.
183204 "x-abso-client": `abso-cli/${clientVersion()}`,
184205 ...(this.config.token && !this.config.visitor ? { authorization: `Bearer ${this.config.token}` } : {}),
206+ // A visitor says nothing about where it's reading from.
207+ ...(this.caller !== undefined && !this.config.visitor ? { [CALLER_HEADER]: this.caller } : {}),
185208 ...(contentType ? { "content-type": contentType } : {}),
186209 };
187210 }
@@ -258,7 +281,9 @@
258281 res.status,
259282 );
260283 try {
261− return JSON.parse(text) as T;
284+ const parsed = JSON.parse(text) as T;
285+ noteSeat(parsed);
286+ return parsed;
262287 } catch {
263288 throw new ApiError(
264289 `${method} ${path} answered with something that isn't JSON: ${text.slice(0, 300)}`,
--- a/client/src/command-env.ts
+++ b/client/src/command-env.ts
@@ -1,6 +1,8 @@
11// What every abso command shares: its output, its environment, the folder it opens, and the news it took.
22
3−import { Api, type News, newsLines, type RunKind } from "./api.ts";
3+import { hostname } from "node:os";
4+import { callerHeader } from "../../src/caller.ts";
5+import { Api, type News, newsLines, type RunKind, takeSeatNotices } from "./api.ts";
46import { UsageError } from "./args.ts";
57import { type Config, findRoot, readConfig } from "./config.ts";
68import { newsBlockLines, newsShown } from "./core.ts";
@@ -45,7 +47,9 @@
4547 `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.`,
4648 );
4749 const config = readConfig(root, env.env, env.tokenFile === true);
48− return { root, config, api: new Api(config) };
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 };
4953}
5054
5155/**
@@ -56,7 +60,7 @@
5660 */
5761const takenNews: string[] = [];
5862export function takeNews(): string[] {
59− return takenNews.splice(0);
63+ return [...takeSeatNotices(), ...takenNews.splice(0)];
6064}
6165
6266/** News a record answered with: kept in .avcs/news.log, and printed by main(). */
--- /dev/null
+++ b/client/test/caller.test.ts
@@ -0,0 +1,90 @@
1+// Who is calling a seat: one header with the chat's session, the computer and the folder, read back exactly or not at all.
2+import assert from "node:assert/strict";
3+import { test } from "node:test";
4+import { CALLER_HEADER, CALLER_MAX, callerHeader, callerPlace, parseCaller } from "../../src/caller.ts";
5+import { Api } from "../src/api.ts";
6+
7+const session = "0da5c2b7-ab07-4249-b868-e8f09b6ec7b6";
8+
9+test("a caller goes out and comes back as it was", () => {
10+ const header = callerHeader({ session, machine: "DESKTOP-1", folder: "C:\\Users\\sam\\repos\\abso\\groups" })!;
11+ assert.match(header, /^[A-Za-z0-9_-]+$/);
12+ assert.deepEqual(parseCaller(header), {
13+ session,
14+ machine: "DESKTOP-1",
15+ folder: "C:\\Users\\sam\\repos\\abso\\groups",
16+ });
17+ assert.equal(callerPlace(parseCaller(header)!), "groups on DESKTOP-1");
18+ // Outside a chat there's no session, and that's still a caller.
19+ assert.deepEqual(parseCaller(callerHeader({ machine: "box", folder: "/work/über" })), {
20+ machine: "box",
21+ folder: "/work/über",
22+ });
23+});
25+test("a session that isn't an id is left out, and a long folder keeps its end", () => {
26+ assert.deepEqual(parseCaller(callerHeader({ session: "not a session!", machine: "m", folder: "/a" })), {
27+ machine: "m",
28+ folder: "/a",
29+ });
30+ const deep = `/${"very-long-folder-name/".repeat(40)}groups`;
31+ const header = callerHeader({ session, machine: "m", folder: deep })!;
32+ assert.ok(header.length <= CALLER_MAX);
33+ assert.ok(parseCaller(header)!.folder.endsWith("/groups"));
34+});
36+test("a header that isn't a caller is refused, never guessed at", () => {
37+ const enc = (v: unknown) => Buffer.from(JSON.stringify(v)).toString("base64url");
38+ for (const bad of [
39+ undefined,
40+ "",
41+ "not base64!",
42+ enc("text"),
43+ enc([1]),
44+ enc({ machine: "m" }),
45+ enc({ machine: "has space", folder: "/a" }),
46+ enc({ machine: "m", folder: "/a", session: "bad id!" }),
47+ enc({ machine: "m", folder: "/a", token: "x" }),
48+ enc({ machine: "m", folder: "/a\nb" }),
49+ "A".repeat(CALLER_MAX + 1),
50+ ])
51+ assert.equal(parseCaller(bad), null, String(bad));
52+});
54+test("the Api sends the caller with its calls, except from a visitor folder", () => {
55+ const config = {
56+ server: "https://abso.test",
57+ project: "p",
58+ agent: "ann",
59+ token: "abso_sk_x",
60+ } as ConstructorParameters<typeof Api>[0];
61+ const api = new Api(config);
62+ assert.equal(api.headers()[CALLER_HEADER], undefined);
63+ api.caller = callerHeader({ session, machine: "m", folder: "/a" });
64+ assert.equal(api.headers()[CALLER_HEADER], api.caller);
65+ const visitor = new Api({ ...config, visitor: true } as ConstructorParameters<typeof Api>[0]);
66+ visitor.caller = api.caller;
67+ assert.equal(visitor.headers()[CALLER_HEADER], undefined);
68+});
70+test("a seat notice on any answer is printed once with the news", async () => {
71+ const { takeNews } = await import("../src/command-env.ts");
72+ takeNews();
73+ const real = globalThis.fetch;
74+ const line = "ann was used from another chat (groups on DESKTOP-2) in the last 30 minutes";
75+ globalThis.fetch = (async () => Response.json({ ok: true, seatNotice: line })) as typeof fetch;
76+ try {
77+ const api = new Api({
78+ server: "https://abso.test",
79+ project: "p",
80+ agent: "ann",
81+ token: "abso_sk_x",
82+ } as ConstructorParameters<typeof Api>[0]);
83+ await api.json("GET", "/status");
84+ await api.json("GET", "/status");
85+ assert.deepEqual(takeNews(), [line]);
86+ assert.deepEqual(takeNews(), []);
87+ } finally {
88+ globalThis.fetch = real;
89+ }
90+});
--- /dev/null
+++ b/src/caller.ts
@@ -0,0 +1,72 @@
1+// Who is calling a seat: the chat's session, the computer and the folder, so a seat can tell its callers when
2+// someone else picks it up. It is information, never authority: the agent key decides who the caller is, and nothing
3+// secret goes in it. Sent as one header, base64url of its JSON.
4+
5+export const CALLER_HEADER = "x-abso-caller";
6+/** The header's most bytes. A folder that would go over keeps its end, which is the part that tells folders apart. */
7+export const CALLER_MAX = 512;
8+
9+export interface Caller {
10+ /** The chat's session id, when abso runs in one (Claude Code's CLAUDE_CODE_SESSION_ID, or the mod's own). */
11+ readonly session?: string;
12+ readonly machine: string;
13+ readonly folder: string;
14+}
16+const SESSION = /^[A-Za-z0-9_-]{1,64}$/;
17+const MACHINE = /^[\w.-]{1,64}$/;
18+const FOLDER_MAX = 300;
20+const b64u = (text: string): string =>
21+ btoa(String.fromCodePoint(...new TextEncoder().encode(text)))
22+ .replace(/\+/g, "-")
23+ .replace(/\//g, "_")
24+ .replace(/=+$/, "");
26+function fromB64u(text: string): string {
27+ const bin = atob(text.replace(/-/g, "+").replace(/_/g, "/"));
28+ return new TextDecoder("utf-8", { fatal: true, ignoreBOM: false }).decode(Uint8Array.from(bin, (c) => c.codePointAt(0)!));
29+}
31+/** The header for this caller, or undefined when there's nothing usable to say. */
32+export function callerHeader(caller: {
33+ session?: string | undefined;
34+ machine: string;
35+ folder: string;
36+}): string | undefined {
37+ const machine = caller.machine.replace(/[^\w.-]/g, "-").slice(0, 64);
38+ if (!MACHINE.test(machine)) return undefined;
39+ const session = caller.session !== undefined && SESSION.test(caller.session) ? caller.session : undefined;
40+ let folder = caller.folder.slice(-FOLDER_MAX);
41+ for (;;) {
42+ const out = b64u(JSON.stringify({ ...(session === undefined ? {} : { session }), machine, folder }));
43+ if (out.length <= CALLER_MAX) return out;
44+ if (folder.length === 0) return undefined;
45+ folder = folder.slice(Math.ceil(folder.length / 4));
46+ }
47+}
49+/** The caller a header names, or null when it is missing or isn't one (a bad header never guesses). */
50+export function parseCaller(header: string | null | undefined): Caller | null {
51+ if (header === null || header === undefined || header === "" || header.length > CALLER_MAX) return null;
52+ if (!/^[A-Za-z0-9_-]+$/.test(header)) return null;
53+ let raw: unknown;
54+ try {
55+ raw = JSON.parse(fromB64u(header));
56+ } catch {
57+ return null;
58+ }
59+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return null;
60+ const { session, machine, folder, ...rest } = raw as Record<string, unknown>;
61+ if (Object.keys(rest).length > 0) return null;
62+ if (typeof machine !== "string" || !MACHINE.test(machine)) return null;
63+ if (typeof folder !== "string" || folder.length > FOLDER_MAX || /[\u0000-\u001f]/.test(folder)) return null;
64+ if (session !== undefined && (typeof session !== "string" || !SESSION.test(session))) return null;
65+ return { ...(session === undefined ? {} : { session }), machine, folder };
66+}
68+/** How a caller reads in a sentence: "<folder> on <machine>", with only the folder's last part. */
69+export function callerPlace(caller: Caller): string {
70+ const parts = caller.folder.split(/[\\/]+/).filter((p) => p !== "");
71+ return `${parts.at(-1) ?? "a folder"} on ${caller.machine}`;
72+}
--- a/worker/project/announce.ts
+++ b/worker/project/announce.ts
@@ -101,3 +101,22 @@
101101 return how as `key ${string}`;
102102 return "as claimed";
103103}
105+/**
106+ * A seat's earlier chat hears that another chat just used the seat (seats notice when someone else picks them up):
107+ * "<agent> was just used from another chat (<place>)". The Worker says where, from the caller it checked; the wording
108+ * is this one only. `key` keeps it to once per pair of chats per window: the same key again adds nothing.
109+ */
110+export function seatNotice(host: AnnounceHost, agentName: string, place: string, key: string): boolean {
111+ const agent = host.agents.get(agentName);
112+ if (agent === undefined) return false;
113+ const where = place
114+ .replace(/[\u0000-\u001f\u007f]+/g, " ")
115+ .trim()
116+ .slice(0, 120);
117+ if (where === "" || !/^seat [\w:.-]{1,200}$/.test(key) || agent.told.has(key)) return false;
118+ const entries: Entry[] = [];
119+ host.queueNews(agent, [{ key, text: `${agent.name} was just used from another chat (${where})` }], entries);
120+ host.flush(entries);
121+ return entries.length > 0;
122+}
--- a/worker/project/project-api.ts
+++ b/worker/project/project-api.ts
@@ -185,6 +185,8 @@
185185 announce(agent: string, text: string, to?: string[], how?: string): { id: number; to: string[] };
186186 /** A signed-in person's announcement from the website (#41): the Worker has checked the sender. */
187187 announcePerson(person: { id: string; name: string }, text: string, to?: string[]): { id: number; to: string[] };
188+ /** A seat's earlier chat hears that another chat just used the seat; the Worker says where. Once per key. */
189+ seatNotice(agent: string, place: string, key: string): boolean;
188190 /** What the agent is starting on (#37, #13), or null to take it back; answers who already works on those files. */
189191 starting(
190192 agent: string,
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -36,7 +36,12 @@
3636} from "../../src/engine/state-source.ts";
3737import { type AddDraftHost, addDraft as hostedAddDraft } from "./add-draft.ts";
3838import { type AmendHost, amend as hostedAmend } from "./amend.ts";
39−import { type AnnounceHost, announce as hostedAnnounce, announcePerson as hostedAnnouncePerson } from "./announce.ts";
39+import {
40+ type AnnounceHost,
41+ announce as hostedAnnounce,
42+ announcePerson as hostedAnnouncePerson,
43+ seatNotice as hostedSeatNotice,
44+} from "./announce.ts";
4045import { type ApplyEntryHost, applyEntry as hostedApplyEntry } from "./apply-entry.ts";
4146import {
4247 type ChangeHost,
@@ -1327,6 +1332,11 @@
13271332 return hostedAnnouncePerson(this.#announceHost, ...args);
13281333 }
13291334
1335+ /** A seat's earlier chat hears that another chat just used the seat (announce.ts seatNotice). */
1336+ seatNotice(...args: Tail<Parameters<typeof hostedSeatNotice>>): ReturnType<typeof hostedSeatNotice> {
1337+ return hostedSeatNotice(this.#announceHost, ...args);
1338+ }
13301340 /**
13311341 * Say what the agent is starting on (#37, #13), before any edit lands:
13321342 * `text`, and the files it expects to change if it knows them. Nothing is
--- /dev/null
+++ b/worker/project/test/seat-notice.test.ts
@@ -0,0 +1,38 @@
1+// A seat's earlier chat hears that another chat just used the seat: one line, worded here, once per key, to that seat only.
2+import assert from "node:assert/strict";
3+import { test } from "node:test";
4+import { MemoryStore, Project } from "../project.ts";
5+
6+function setup() {
7+ const store = new MemoryStore();
8+ const project = new Project(store);
9+ project.init({ "a.txt": "a\n" }, 0);
10+ for (const a of ["ann", "bob"]) project.sync(a);
11+ project.news("ann");
12+ project.news("bob");
13+ return { project, store };
14+}
16+test("the seat hears it once, as news, and the history keeps it", () => {
17+ const { project, store } = setup();
18+ assert.equal(project.seatNotice("ann", "groups on DESKTOP-1", "seat ann:s1:s2:0"), true);
19+ assert.equal(
20+ project.seatNotice("ann", "groups on DESKTOP-1", "seat ann:s1:s2:0"),
21+ false,
22+ "the same key adds nothing",
23+ );
24+ assert.deepEqual(project.news("bob").news, [], "only that seat");
25+ assert.deepEqual(project.news("ann").news, ["ann was just used from another chat (groups on DESKTOP-1)"]);
26+ const replayed = Project.load(store.entries, new MemoryStore());
27+ assert.deepEqual(replayed.news("ann").news, [], "replay knows it was heard");
28+ assert.equal(replayed.seatNotice("ann", "groups on DESKTOP-1", "seat ann:s1:s2:0"), false, "and that it was sent");
29+});
31+test("no seat, no place or a key that isn't a seat's adds nothing; the place stays one line", () => {
32+ const { project } = setup();
33+ assert.equal(project.seatNotice("cal", "x on m", "seat cal:a:b:0"), false);
34+ assert.equal(project.seatNotice("ann", " \n ", "seat ann:a:b:0"), false);
35+ assert.equal(project.seatNotice("ann", "x on m", "announce 1"), false);
36+ assert.equal(project.seatNotice("ann", "two\nlines on m", "seat ann:a:b:1"), true);
37+ assert.deepEqual(project.news("ann").news, ["ann was just used from another chat (two lines on m)"]);
38+});