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
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/feed.ts?format=json
140 linesFirst import 100%Last change First import in version 0, 1 version changed it
1// The project's feed for readers (#41, the website): what happened, by log
2// position, built from the log itself. An agent's `news` is a queue that
3// reading empties; this reads the log, so any number of watchers can read it
4// and nothing changes. Events carry who and what, never file contents, and
5// news addressed to one agent shows only that it came, unless it's an
6// announcement (which is sent to be read).
7import type { Entry } from "./project.ts";
8
9export interface FeedEvent {
10 /** The entry's position in the log. */
11 seq: number;
12 type: Entry["type"];
13 time?: number;
14 agent?: string;
15 /** The named draft, for a publish or switch there; null for shared. */
16 draft?: string | null;
17 version?: number;
18 message?: string;
19 /** Files a recording touched, a refusal named, or a starting note names. */
20 files?: string[];
21 /** A starting note's or an announcement's text. */
22 text?: string;
23 /** A refusal's collision kinds; a publish's settles (file, kept, whose version). */
24 kinds?: string[];
25 settled?: { file: string; kept: string; theirs: { agent: string; version: number } }[];
26 /** How many marker blocks a sync wrote, and how many news items reached an agent. */
27 blocks?: number;
28 items?: number;
29 /** A label's name, and whether it was taken off (#43, the website's timeline). */
30 label?: string;
31 remove?: boolean;
32 /** The versions a drop took out: those asked for and their dependents. */
33 drops?: number[];
34 /** The files the drop's version changed (added by the Worker, which has the project). */
35 dropped?: string[];
36 /** A note's id (#44), its kind (comment, objection, read), the note it answers, its change, and how it was closed. */
37 note?: number;
38 noteKind?: string;
39 reply?: number;
40 change?: number;
41 how?: string;
42 /** The merge queue's id (#39), for a queued or pulled publish, and why it was pulled. */
43 queued?: number;
44 reason?: string;
47const ANNOUNCED = /^Announcement from /;
49/** The events for log entries `entries`, the first of which is at position `from`. */
50export function feedEvents(entries: readonly Entry[], from: number): FeedEvent[] {
51 return entries.map((e, i) => event(e, from + i));
54function event(e: Entry, seq: number): FeedEvent {
55 const base = { seq, type: e.type, ...("time" in e && typeof e.time === "number" ? { time: e.time } : {}) };
56 switch (e.type) {
57 case "init":
58 return { ...base, time: e.time, version: 0, files: [...new Set(e.atom.inserts.map((r) => r.file))].sort() };
59 case "draft":
60 return {
61 ...base,
62 time: e.atom.time,
63 agent: e.agent,
64 files: [...new Set(e.atom.inserts.map((r) => r.file).filter(Boolean))].sort(),
65 };
66 case "publish":
67 return {
68 ...base,
69 agent: e.agent,
70 draft: e.space ?? null,
71 version: e.version,
72 message: e.message,
73 ...(e.settled ? { settled: e.settled.map((s) => ({ file: s.file, kept: s.kept, theirs: s.theirs })) } : {}),
74 };
75 case "land":
76 return { ...base, agent: e.agent, draft: null, version: e.version, message: e.message };
77 case "sync":
78 case "join":
79 return { ...base, agent: e.agent, version: e.version };
80 case "switch":
81 return { ...base, agent: e.agent, draft: e.space === "" ? null : e.space, version: e.version };
82 case "discard":
83 return {
84 ...base,
85 agent: e.agent,
86 ...(e.markers ? { blocks: e.markers.length, files: [...new Set(e.markers.map((m) => m.file))].sort() } : {}),
87 };
88 case "refused":
89 return {
90 ...base,
91 agent: e.agent,
92 kinds: [...new Set(e.collisions.map((c) => c.kind))].sort(),
93 files: [...new Set(e.collisions.map((c) => c.file))].sort(),
94 };
95 case "starting":
96 return { ...base, agent: e.agent, ...(e.text !== null ? { text: e.text, files: [...(e.files ?? [])] } : {}) };
97 case "news": {
98 // Announcements are meant to be read; other news is the agent's own.
99 const said = e.text.filter((t) => ANNOUNCED.test(t));
100 return {
101 ...base,
102 agent: e.agent,
103 items: e.pairs.length,
104 ...(said.length > 0 && said.length === e.text.length ? { text: said.join("\n") } : {}),
105 };
106 }
107 case "note":
108 return {
109 ...base,
110 agent: e.agent,
111 note: e.id,
112 noteKind: e.kind,
113 files: [e.file],
114 text: e.text,
115 ...(e.reply !== undefined ? { reply: e.reply } : {}),
116 ...(e.change !== undefined ? { change: e.change } : {}),
117 };
118 case "note-closed":
119 return { ...base, agent: e.agent, note: e.id, how: e.how };
120 case "queued":
121 return { ...base, agent: e.agent, queued: e.id, message: e.message, items: e.changes.length };
122 case "pulled":
123 return { ...base, queued: e.id, reason: e.reason };
124 case "label":
125 return { ...base, agent: e.agent, version: e.version, label: e.name, ...(e.remove ? { remove: true } : {}) };
126 case "drop":
127 return { ...base, agent: e.agent, version: e.version, message: e.message, drops: [...e.versions] };
128 case "amend":
129 case "space":
130 case "space-sync":
131 return {
132 ...base,
133 agent: e.agent,
134 ...("version" in e ? { version: e.version } : {}),
135 ...("message" in e ? { message: e.message } : {}),
136 };
137 default:
138 return { ...base, ...("agent" in e ? { agent: (e as { agent: string }).agent } : {}) };
139 }