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 291 of shared· box-grants· Oct 16 (2026-10-16 03:26 UTC) · 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 @@
108 108 const ended = await follow({ 109 109 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), 110 112 connect: (url, protocols) => new WebSocket(url, [...protocols]) as unknown as Socket, 111 113 write: (line) => { 112 114 logNews(root, [line]); --- a/client/src/news-stream.ts
+++ b/client/src/news-stream.ts
@@ -94,6 +94,8 @@
94 94 sleep(ms: number): Promise<void>; 96 96 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[]>; 97 99 /** Called when a socket opens and at each ping: the stream is held until the next ping is due, and a little more. */ 98 100 held?(until: number): void; 99 101 /** Set when --follow should stop (Ctrl-C, or a test). */ @@ -107,10 +109,53 @@
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. 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) => { 123 + if (shown.length > 200) shown.shift(); 125 + let running: Promise<void> | undefined; 127 + const pass = async () => { 130 + const these = frames; 132 + let items: readonly string[] = []; 134 + items = await deps.take!(); 136 + deps.note(`(abso news --follow: couldn't read the news: ${(err as Error).message}; showing the frames)`); 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); 141 + running = undefined; 146 + if (running !== undefined) again = true; 147 + else running = pass(); 149 + idle: () => running ?? Promise.resolve(), 110 154 * Holds the seat's stream, printing one line per item, until the key is refused or `stopped()`. 111 155 * Returns why it ended. 113 157 export async function follow(deps: FollowDeps): Promise<{ ended: "refused" | "stopped"; reason: string }> { 158 + const reads = frameReads(deps); 115 160 while (!deps.stopped()) { 116 161 let ticket: NewsTicket; @@ -139,12 +184,13 @@
140 185 socket.onmessage = (e) => { 141 186 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); 144 190 socket.onerror = () => {}; 145 191 socket.onclose = (e) => { 147 − done({ code: e.code, reason: e.reason });
193 + void reads.idle().then(() => done({ code: e.code, reason: e.reason })); 150 196 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 @@
134 134 assert.equal(w.notes.length, 0); 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?"], []]; 142 + w.deps.take = async () => { 144 + return reads.shift() ?? []; 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"); 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/); 137 168 test("--follow keeps an idle socket open with a ping the object answers without waking", async () => { 138 169 const w = world([{ frames: [], close: { code: 1006 } }]); 139 170 const held: number[] = [];