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

Versions 263 to 318

Compare

+61 −3 in 3 places
Lines 2–15 at 318 (were 2–11 at 263)
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";
11+import { follow, monitorArgs, type Socket, STREAM_MARK, streamMarkUntil, streamText } from "./news-stream.ts";
12+import { stateDir } from "./state-dir.ts";
913import { newsWithTime } from "./times.ts";
1014
1115export async function runAnnounce(args: Parsed, env: Env): Promise<Output> {
Lines 28–34 at 318 (were 24–30 at 263)
2428 const answer = await api.announce(text, to);
2529 const who = answer.to.length === 0 ? "nobody (no other agents yet)" : answer.to.join(", ");
2630 return {
27− text: `Announced to ${who}. Each gets it once, as news on their next edit, or within about 30 seconds where the abso mod runs.`,
31+ text: `Announced to ${who}. Each gets it once, as news on their next edit, within about 5 minutes in a working chat where the abso mod runs, or at once where it holds its news stream.`,
2832 json: { id: answer.id, to: answer.to },
2933 };
3034}
Lines 77–138 at 318 (were 73–80 at 263)
7377 return { text: lines.join("\n"), json: { ...answer } };
7478}
7579
76−export async function runNews(_args: Parsed, env: Env): Promise<Output> {
77− const { root, api } = open(env);
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+}
89+export async function runNews(args: Parsed, env: Env): Promise<Output> {
90+ const { root, config, api } = open(env);
91+ if (bool(args, "stream") && bool(args, "follow"))
92+ throw new UsageError("abso news takes --stream or --follow, not both");
93+ if (bool(args, "stream")) {
94+ const ticket = await api.newsTicket();
95+ markStream(root, streamMarkUntil(ticket, Date.now()));
96+ return {
97+ text: streamText(ticket, config.project, config.agent),
98+ json: { monitor: monitorArgs(ticket, config.project, config.agent), expiresAt: ticket.expiresAt },
99+ };
100+ }
101+ if (bool(args, "follow")) {
102+ let stop = false;
103+ const onInt = () => {
104+ stop = true;
105+ };
106+ process.once("SIGINT", onInt);
107+ try {
108+ const ended = await follow({
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),
112+ connect: (url, protocols) => new WebSocket(url, [...protocols]) as unknown as Socket,
113+ write: (line) => {
114+ logNews(root, [line]);
115+ env.write(`${line.replace(/\r?\n/g, " ")}\n`);
116+ },
117+ held: (until) => markStream(root, until),
118+ note: (line) =>
119+ env.write(`${line}
120+`),
121+ sleep: (ms) => new Promise((ok) => setTimeout(ok, ms)),
122+ now: () => Date.now(),
123+ every: (ms, fn) => {
124+ const t = setInterval(fn, ms);
125+ return () => clearInterval(t);
126+ },
127+ stopped: () => stop,
128+ });
129+ return ended.ended === "refused"
130+ ? { text: `The news stream refused this seat: ${ended.reason}`, json: ended, exit: 2 }
131+ : { text: "", json: ended };
132+ } finally {
133+ process.off("SIGINT", onInt);
134+ }
135+ }
78136 const answer = await api.news();
79137 const news = newsLines(answer.news);
80138 logNews(root, news);
MCP
compare on this site's /mcp
CLI
abso diff 263 318 client/src/announce.ts --json
JSON
/christopher/abso-core/compare/263..318?file=client%2Fsrc%2Fannounce.ts&format=json