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

Project tells a host each write's news (newsWritten), and reads an agent's waiting news without taking it (peekNews)

of shared·readspeed··Not checked

A host that wakes a listener the moment news lands, such as a WebSocket per agent, needs two things from the engine: which agents a write just gave news, and a way to show what's waiting without using it up.

  • ProjectOptions.newsWritten(items): after each write that appended "news" entries, it's called once with one item per text: {agent, text, at, seq}, where seq is the entry's place in the log. It runs inside the write, which can still roll back, so the host collects the items and acts only once the call has returned. Taking news (heard) and writes with no news call nothing, so a listener's own reads wake no one. It works on both the in-memory store and openWriter's.
  • peekNews(agent): the agent's waiting news, read only. Nothing is taken, heard or written, and an agent the project hasn't got reads as none, with none made. A listener can catch up on connect while the news stays for the agent's own next read, so a listener that dies loses nothing.
  • hasAgent(agent): whether the project has it, read only.

Tests: worker/project/test/news-written.test.ts (3): one call per write, with each item's agent, text and place in the log; no call for writes without news or for taking news; peekNews takes and writes nothing, and the take still finds the news. All engine tests pass (362).

Version 291 · Files at version 292

3 files, 94 lines added, 0 removed.

--- a/worker/project/project-types.ts
+++ b/worker/project/project-types.ts
@@ -583,7 +583,22 @@
583583export type Blobs = Record<string, string | null>;
584584
585585/** What the project needs from the store of binary files' bytes. */
586+/** One news item a write gave an agent: its text and time, and its entry's place in the log. */
587+export interface NewsWritten {
588+ readonly agent: string;
589+ readonly text: string;
590+ readonly at: number | null;
591+ /** The news entry's place in the log: later news has a higher one. */
592+ readonly seq: number;
593+}
586595export interface ProjectOptions {
596+ /**
597+ * Told after each write that gave agents news, with each item as the write appended it. It runs inside the write,
598+ * which can still roll back, so a host collects the items and acts on them only once the call has returned. A host
599+ * can then wake a listener for exactly the agents that got news, without reading the log.
600+ */
601+ newsWritten?: (items: readonly NewsWritten[]) => void;
587602 /** Optional derived atom indexing within persistent graph acceptance. */
588603 indexAcceptedAtom?: (atom: Atom, files: readonly string[], storage: GraphStateStorage) => void;
589604 /** Private experimental reader route; never falls back for unsupported membership. */
--- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -157,6 +157,7 @@
157157 LandAnswer,
158158 MergedLine,
159159 Modes,
160+ NewsWritten,
160161 NoteAnswer,
161162 NoteBody,
162163 NoteRecord,
@@ -330,6 +331,7 @@
330331 */
331332 checkerReady = false;
332333 readonly #now: (() => number) | undefined;
334+ readonly #newsWritten: ((items: readonly NewsWritten[]) => void) | undefined;
333335 readonly #whole: ProjectOptions["whole"];
334336 readonly #shapes: ProjectOptions["shapes"];
335337 readonly #logLine: ProjectOptions["logLine"];
@@ -452,6 +454,7 @@
452454 }
453455 this.#hasBlob = options.hasBlob ?? (() => false);
454456 this.#now = options.now;
457+ this.#newsWritten = options.newsWritten;
455458 this.#whole = options.whole;
456459 this.#shapes = options.shapes;
457460 this.#logLine = options.logLine;
@@ -1440,6 +1443,17 @@
14401443 return hostedOverlapNews(this.#overlapHost, ...args);
14411444 }
14421445
1446+ /** The news waiting for an agent, read only: nothing is taken, heard or written. None for an agent it hasn't got. */
1447+ peekNews(agentName: string): { text: string; at: number | null }[] {
1448+ const agent = typeof agentName === "string" ? this.#agents.get(agentName) : undefined;
1449+ return agent ? agent.news.map((text, i) => ({ text, at: agent.newsAt[i] ?? null })) : [];
1450+ }
1452+ /** Whether the project has this agent. Read only. */
1453+ hasAgent(agentName: string): boolean {
1454+ return typeof agentName === "string" && this.#agents.get(agentName) !== undefined;
1455+ }
14431457 /** Hand over the news waiting for an agent (collisions, definitions, moves, announcements), once. */
14441458 news(agentName: string): { news: string[]; items: { text: string; at: number | null }[] } {
14451459 const entries: Entry[] = [];
@@ -1719,6 +1733,15 @@
17191733 if (this.#pending.length === 0) return;
17201734 const out = this.#pending;
17211735 this.#store.append(out);
1736+ if (this.#newsWritten) {
1737+ const items: NewsWritten[] = [];
1738+ out.forEach((entry, i) => {
1739+ if (entry.type !== "news") return;
1740+ for (const text of entry.text)
1741+ items.push({ agent: entry.agent, text, at: entry.time ?? null, seq: this.#stored + i });
1742+ });
1743+ if (items.length > 0) this.#newsWritten(items);
1744+ }
17221745 this.#persistMutable();
17231746 // A few more agents' old told lists into their buckets at each write, until every row has moved (writer-agents.ts).
17241747 if (this.#agents instanceof WriterAgents) this.#agents.moveOldTold(OLD_TOLD_PER_WRITE);
--- /dev/null
+++ b/worker/project/test/news-written.test.ts
@@ -0,0 +1,56 @@
1+// A host learns each write's news as the write appends it (newsWritten), and can read an agent's waiting news without
2+// taking it (peekNews), so a listener can be woken for exactly the agents that got news and caught up on connect.
3+
4+import assert from "node:assert/strict";
5+import { test } from "node:test";
6+import { MemoryStore, type NewsWritten, Project } from "../project.ts";
7+
8+function setup() {
9+ const store = new MemoryStore();
10+ const written: NewsWritten[][] = [];
11+ const project = new Project(store, { newsWritten: (items) => written.push([...items]) });
12+ project.init({ "a.txt": "a\n" }, 0);
13+ for (const a of ["builder1", "builder2", "builder3"]) project.sync(a);
14+ written.length = 0;
15+ return { project, store, written };
16+}
18+test("a write's news is told once, per item, with its agent, text and place in the log", () => {
19+ const { project, store, written } = setup();
20+ project.announce("builder1", "Ship it", ["builder2", "builder3"], 1);
21+ assert.equal(written.length, 1, "one call for the write");
22+ const items = written[0]!;
23+ assert.deepEqual(
24+ items.map((i) => i.agent),
25+ ["builder2", "builder3"],
26+ );
27+ for (const item of items) {
28+ assert.match(item.text, /Announcement from builder1.*Ship it/);
29+ assert.equal(store.entries[item.seq]?.type, "news", "seq is the entry's place in the log");
30+ }
31+ assert.ok(items[1]!.seq > items[0]!.seq);
32+});
34+test("writes with no news, and taking news (heard), tell nothing", () => {
35+ const { project, written } = setup();
36+ project.announce("builder1", "Ship it", ["builder2"], 1);
37+ written.length = 0;
38+ project.news("builder2");
39+ project.sync("builder3");
40+ assert.deepEqual(written, []);
41+});
43+test("peekNews reads waiting news and takes nothing; hasAgent reads only", () => {
44+ const { project, store } = setup();
45+ project.announce("builder1", "Ship it", ["builder2"], 1);
46+ const length = store.entries.length;
47+ const peeked = project.peekNews("builder2");
48+ assert.equal(peeked.length, 1);
49+ assert.match(peeked[0]!.text, /Ship it/);
50+ assert.deepEqual(project.peekNews("builder2"), peeked, "still there");
51+ assert.deepEqual(project.peekNews("nobody"), [], "no agent: none, and none made");
52+ assert.equal(project.hasAgent("builder2"), true);
53+ assert.equal(project.hasAgent("nobody"), false);
54+ assert.equal(store.entries.length, length, "nothing written");
55+ assert.equal(project.news("builder2").news.length, 1, "the take still finds it");
56+});