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

abso news --follow (abso 690): a frame is a wake. On one, --follow reads the seat's news (POST news, which marks it heard) and prints that answer, one read at a time; frames arriving meanwhile fold into one more read. When the read is empty (staging 1418 counts a frame as heard already, or another chat took it), it prints the frames it hasn't printed. That's for Read Speed's fix, where frames stop counting as heard so a dead Monitor socket loses nothing, and it works on today's server too. Live on staging: 1.5 s, printed once. Tests: client/test/news-stream.test.ts.

of shared·box-grants··Not checked

abso news --follow (abso 690): a frame is a wake. On one, --follow reads the seat's news (POST news, which marks it heard) and prints that answer, one read at a time; frames arriving meanwhile fold into one more read.

When the read is empty (staging 1418 counts a frame as heard already, or another chat took it), it prints the frames it hasn't printed. That's for Read Speed's fix, where frames stop counting as heard so a dead Monitor socket loses nothing, and it works on today's server too. Live on staging: 1.5 s, printed once. Tests: client/test/news-stream.test.ts.

Version 290 · Files at version 291

3 files, 81 lines added, 2 removed.

--- a/client/src/announce.ts
+++ b/client/src/announce.ts
@@ -107,6 +107,8 @@
107107 try {
108108 const ended = await follow({
109109 mint: () => api.newsTicket(),
110+ // A frame is a wake: read the news, which marks it heard, and print that (news-stream.ts).
111+ take: async () => newsLines((await api.news()).news),
110112 connect: (url, protocols) => new WebSocket(url, [...protocols]) as unknown as Socket,
111113 write: (line) => {
112114 logNews(root, [line]);
--- a/client/src/news-stream.ts
+++ b/client/src/news-stream.ts
@@ -94,6 +94,8 @@
9494 sleep(ms: number): Promise<void>;
9595 now(): number;
9696 every(ms: number, fn: () => void): () => void;
97+ /** Reads the seat's news, marking it heard (POST news); a frame calls it. Without it, frames are printed as they come. */
98+ take?(): Promise<readonly string[]>;
9799 /** Called when a socket opens and at each ping: the stream is held until the next ping is due, and a little more. */
98100 held?(until: number): void;
99101 /** Set when --follow should stop (Ctrl-C, or a test). */
@@ -107,10 +109,53 @@
107109}
108110
109111/**
112+ * A frame is a wake (abso 690): on one, read the seat's news (which marks it heard) and print what that answers, one
113+ * read at a time, with frames that arrive meanwhile folded into one more read. When the read answers nothing (a server
114+ * that counts a frame as heard already, or another chat on the seat took it first), the frames themselves are printed.
115+ */
116+function frameReads(deps: FollowDeps): { frame(text: string): void; idle(): Promise<void> } {
117+ let frames: string[] = [];
118+ /** The lines printed lately, so a frame a read already printed isn't printed again. */
119+ const shown: string[] = [];
120+ const show = (line: string) => {
121+ deps.write(line);
122+ shown.push(line);
123+ if (shown.length > 200) shown.shift();
124+ };
125+ let running: Promise<void> | undefined;
126+ let again = false;
127+ const pass = async () => {
128+ do {
129+ again = false;
130+ const these = frames;
131+ frames = [];
132+ let items: readonly string[] = [];
133+ try {
134+ items = await deps.take!();
135+ } catch (err) {
136+ deps.note(`(abso news --follow: couldn't read the news: ${(err as Error).message}; showing the frames)`);
137+ }
138+ if (items.length > 0) for (const line of items) show(line);
139+ else for (const line of these) if (!shown.includes(line)) show(line);
140+ } while (again);
141+ running = undefined;
142+ };
143+ return {
144+ frame(text) {
145+ frames.push(text);
146+ if (running !== undefined) again = true;
147+ else running = pass();
148+ },
149+ idle: () => running ?? Promise.resolve(),
150+ };
151+}
153+/**
110154 * Holds the seat's stream, printing one line per item, until the key is refused or `stopped()`.
111155 * Returns why it ended.
112156 */
113157export async function follow(deps: FollowDeps): Promise<{ ended: "refused" | "stopped"; reason: string }> {
158+ const reads = frameReads(deps);
114159 let wait = 1_000;
115160 while (!deps.stopped()) {
116161 let ticket: NewsTicket;
@@ -139,12 +184,13 @@
139184 };
140185 socket.onmessage = (e) => {
141186 if (typeof e.data !== "string" || e.data === PONG) return;
142− deps.write(e.data);
187+ if (deps.take === undefined) deps.write(e.data);
188+ else reads.frame(e.data);
143189 };
144190 socket.onerror = () => {};
145191 socket.onclose = (e) => {
146192 stopPing();
147− done({ code: e.code, reason: e.reason });
193+ void reads.idle().then(() => done({ code: e.code, reason: e.reason }));
148194 };
149195 });
150196 if (isRefusal(closed.code)) return { ended: "refused", reason: closed.reason || `closed ${closed.code}` };
--- a/client/test/news-stream.test.ts
+++ b/client/test/news-stream.test.ts
@@ -134,6 +134,37 @@
134134 assert.equal(w.notes.length, 0);
135135});
136136
137+test("a frame is a wake: --follow reads the news and prints that once; an empty read prints the frames", async () => {
138+ // The server's frames don't count as heard (abso 690): the read takes them, so each item prints once.
139+ const w = world([{ frames: ["fe told you: hello", "cloud asks: ship it?"], close: { code: 1006 } }]);
140+ const reads: string[][] = [["fe told you: hello", "cloud asks: ship it?"], []];
141+ let calls = 0;
142+ w.deps.take = async () => {
143+ calls++;
144+ return reads.shift() ?? [];
145+ };
146+ await follow(w.deps);
147+ // Two frames, one read in flight: the second folds into one more read, which finds nothing new; its frame was
148+ // already printed by the first read, so nothing prints twice.
149+ assert.equal(calls, 2);
150+ assert.deepEqual(w.lines, ["fe told you: hello", "cloud asks: ship it?"]);
152+ // A server that counts a frame as heard already (staging 1418): the read is empty, so the frame is what shows.
153+ const old = world([{ frames: ["fe told you: hello"], close: { code: 1006 } }]);
154+ old.deps.take = async () => [];
155+ await follow(old.deps);
156+ assert.deepEqual(old.lines, ["fe told you: hello"]);
158+ // A read that fails shows the frames and says why.
159+ const down = world([{ frames: ["fe told you: hello"], close: { code: 1006 } }]);
160+ down.deps.take = async () => {
161+ throw new Error("could not reach the server");
162+ };
163+ await follow(down.deps);
164+ assert.deepEqual(down.lines, ["fe told you: hello"]);
165+ assert.match(down.notes[0]!, /couldn't read the news: could not reach the server/);
166+});
137168test("--follow keeps an idle socket open with a ping the object answers without waking", async () => {
138169 const w = world([{ frames: [], close: { code: 1006 } }]);
139170 const held: number[] = [];