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

abso 690: while a seat holds its news stream, the abso-hooks mod's 30-second news poll stands down. abso news --stream marks the folder (.abso/news-stream.json) for the Monitor's 30 minutes plus the ticket's minute; --follow renews the mark on open and at each 45-second ping. The poll asks again once the mark runs out. Tests: client/test/news-stream.test.ts, client/hooks/register.test.ts (node client/test-mods.ts).

of shared·box-grants··Not checked

Version 269 · Files at version 270

5 files, 58 lines added, 2 removed.

--- a/client/hooks/register.test.ts
+++ b/client/hooks/register.test.ts
@@ -62,6 +62,16 @@
6262 expect(log.split("\n").filter((l) => l.includes("Announcement from lead"))).toHaveLength(1);
6363});
6464
65+test("while the seat holds its news stream (abso 690), the poll stands down, and asks again once the mark runs out", async ($, on) => {
66+ const w = world(on, true, [[], []]);
67+ w.written.set("/w/p/.abso/news-stream.json", JSON.stringify({ until: 1_000_000 + 95_000 }));
68+ await $.session.start({ cwd: "/w/p" });
69+ await w.clock.advance(90_000);
70+ expect(w.asked).toEqual([]);
71+ await w.clock.advance(30_000);
72+ expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]);
73+});
6575test("outside an abso folder it never asks", async ($, on) => {
6676 const w = world(on, false, [["should not arrive"]]);
6777 await $.session.start({ cwd: "/w/p" });
--- a/client/hooks/register.ts
+++ b/client/hooks/register.ts
@@ -217,6 +217,12 @@
217217/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */
218218async function pollNews($: Engine, root: string): Promise<void> {
219219 try {
220+ // While this seat holds its news stream (abso news --stream or --follow, abso 690), the stream wakes the chat.
221+ const mark = await readOr($, `${await stateOf($, root)}/news-stream.json`);
222+ if (mark !== undefined) {
223+ const until = Number((JSON.parse(mark) as { until?: unknown }).until);
224+ if (Number.isFinite(until) && until > (await $.clock.now())) return;
225+ }
220226 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
221227 server: string;
222228 project: string;
--- a/client/src/announce.ts
+++ b/client/src/announce.ts
@@ -2,11 +2,14 @@
22// delivered once as news on each one's next edit (or the mod's next poll),
33// and the news waiting for this agent.
44
5+import { writeFileSync } from "node:fs";
6+import { join } from "node:path";
57import { newsLines } from "./api.ts";
68import { bool, type Parsed, str, UsageError } from "./args.ts";
79import { type Env, type Output, open, plural } from "./commands.ts";
810import { logNews } from "./folder.ts";
9−import { follow, monitorArgs, type Socket, streamText } from "./news-stream.ts";
11+import { follow, monitorArgs, type Socket, STREAM_MARK, streamMarkUntil, streamText } from "./news-stream.ts";
12+import { stateDir } from "./state-dir.ts";
1013import { newsWithTime } from "./times.ts";
1114
1215export async function runAnnounce(args: Parsed, env: Env): Promise<Output> {
@@ -74,12 +77,22 @@
7477 return { text: lines.join("\n"), json: { ...answer } };
7578}
7679
80+/** Says this folder's seat holds its news stream until `until`, so the abso-hooks mod's poll stands down. Best effort. */
81+function markStream(root: string, until: number): void {
82+ try {
83+ writeFileSync(join(stateDir(root), STREAM_MARK), JSON.stringify({ until }));
84+ } catch {
85+ // The mod keeps polling; nothing is lost.
86+ }
87+}
7789export async function runNews(args: Parsed, env: Env): Promise<Output> {
7890 const { root, config, api } = open(env);
7991 if (bool(args, "stream") && bool(args, "follow"))
8092 throw new UsageError("abso news takes --stream or --follow, not both");
8193 if (bool(args, "stream")) {
8294 const ticket = await api.newsTicket();
95+ markStream(root, streamMarkUntil(ticket, Date.now()));
8396 return {
8497 text: streamText(ticket, config.project, config.agent),
8598 json: { monitor: monitorArgs(ticket, config.project, config.agent), expiresAt: ticket.expiresAt },
@@ -99,6 +112,7 @@
99112 logNews(root, [line]);
100113 env.write(`${line.replace(/\r?\n/g, " ")}\n`);
101114 },
115+ held: (until) => markStream(root, until),
102116 note: (line) =>
103117 env.write(`${line}
104118`),
--- a/client/src/news-stream.ts
+++ b/client/src/news-stream.ts
@@ -43,6 +43,14 @@
4343 ].join("\n");
4444}
4545
46+/** The file that says this folder's seat holds its stream, until when: the abso-hooks mod's news poll skips meanwhile. */
47+export const STREAM_MARK = "news-stream.json";
49+/** How long --stream's mark holds: the Monitor's 30 minutes, and the minute the ticket waits to be used. */
50+export function streamMarkUntil(ticket: NewsTicket, now: number): number {
51+ return Math.max(now, ticket.expiresAt) + MONITOR_TIMEOUT_MS;
52+}
4654/** The part of a WebSocket --follow uses: the platform's own, or a test's. */
4755export interface Socket {
4856 onopen: (() => void) | null;
@@ -79,6 +87,8 @@
7987 sleep(ms: number): Promise<void>;
8088 now(): number;
8189 every(ms: number, fn: () => void): () => void;
90+ /** Called when a socket opens and at each ping: the stream is held until the next ping is due, and a little more. */
91+ held?(until: number): void;
8292 /** Set when --follow should stop (Ctrl-C, or a test). */
8393 readonly stopped: () => boolean;
8494}
@@ -111,9 +121,13 @@
111121 const socket = deps.connect(ticket.url, ticket.protocols);
112122 let stopPing = () => {};
113123 socket.onopen = () => {
124+ deps.held?.(deps.now() + 2 * PING_MS);
114125 stopPing = deps.every(PING_MS, () => {
115126 if (deps.stopped()) socket.close(1000);
116− else socket.send(PING);
127+ else {
128+ socket.send(PING);
129+ deps.held?.(deps.now() + 2 * PING_MS);
130+ }
117131 });
118132 };
119133 socket.onmessage = (e) => {
--- a/client/test/news-stream.test.ts
+++ b/client/test/news-stream.test.ts
@@ -15,6 +15,8 @@
1515 PING_MS,
1616 PONG,
1717 type Socket,
18+ STREAM_MARK,
19+ streamMarkUntil,
1820 streamText,
1921} from "../src/news-stream.ts";
2022
@@ -127,10 +129,20 @@
127129
128130test("--follow keeps an idle socket open with a ping the object answers without waking", async () => {
129131 const w = world([{ frames: [], close: { code: 1006 } }]);
132+ const held: number[] = [];
133+ w.deps.held = (until) => held.push(until);
130134 await follow(w.deps);
131135 assert.deepEqual(w.sent, [PING]);
136+ // The stream mark is renewed on open and at each ping, two pings ahead, so the mod's poll stands down meanwhile.
137+ // The first socket opens and pings; the second opens a second later.
138+ assert.deepEqual(held, [NOW + 2 * PING_MS, NOW + 2 * PING_MS, NOW + 1_000 + 2 * PING_MS]);
132139});
133140
141+test("--stream's mark holds for the Monitor's 30 minutes after the ticket's minute", () => {
142+ assert.equal(streamMarkUntil(ticket(1), NOW), NOW + 60_000 + MONITOR_TIMEOUT_MS);
143+ assert.equal(STREAM_MARK, "news-stream.json");
144+});
134146test("a refused ticket or a refusal close ends --follow; a ticket that can't be had is tried again", async () => {
135147 const refusedClose = world([{ frames: ["one item"], close: { code: 4401, reason: "the key was revoked" } }]);
136148 assert.deepEqual(await follow(refusedClose.deps), { ended: "refused", reason: "the key was revoked" });