Lines 2–15 at 318 (were 2–11 at 73)
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. 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"; 1115export async function runAnnounce(args: Parsed, env: Env): Promise<Output> { Lines 28–34 at 318 (were 24–30 at 73)
2428 const answer = await api.announce(text, to); 2529 const who = answer.to.length === 0 ? "nobody (no other agents yet)" : answer.to.join(", "); 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 }, Lines 50–63 at 318 (were 46–59 at 73)
4650 throw new UsageError('--issue takes an issue number: abso start "<what>" --issue 12'); 4751 const answer = await api.starting(text, files, issue !== undefined ? { issue } : {}); 49− `Starting on "${text}"${files.length > 0 ? `, naming ${files.join(", ")}` : ""}${issue !== undefined ? ` for issue ${issue}` : ""}. abso where shows it to everyone until you publish (or abso start --done).` +
50− (issue !== undefined ? ` abso publish --done closes issue ${issue}.` : ""),
53+ `Starting on "${text}"${files.length > 0 ? `, naming ${files.join(", ")}` : ""}${issue !== undefined ? ` for issue ${issue}` : ""}. abso where shows it to everyone until you push (or abso start --done).` + 54+ (issue !== undefined ? ` abso push --done closes issue ${issue}.` : ""), 5256 if (answer.overlaps.length > 0) { 5357 lines.push("Already there:"); 5458 for (const o of answer.overlaps) { 56− o.changes ? plural(o.changes, "unpublished change") : "",
60+ o.changes ? plural(o.changes, "unpushed change") : "", 5761 o.starting ? `starting on "${o.starting}"` : "", 5963 .filter((w) => w !== "") Lines 77–138 at 318 (were 73–80 at 73)
7377 return { text: lines.join("\n"), json: { ...answer } }; 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 { 83+ writeFileSync(join(stateDir(root), STREAM_MARK), JSON.stringify({ until })); 85+ // The mod keeps polling; nothing is lost. 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())); 97+ text: streamText(ticket, config.project, config.agent), 98+ json: { monitor: monitorArgs(ticket, config.project, config.agent), expiresAt: ticket.expiresAt }, 101+ if (bool(args, "follow")) { 103+ const onInt = () => { 106+ process.once("SIGINT", onInt); 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, 114+ logNews(root, [line]); 115+ env.write(`${line.replace(/\r?\n/g, " ")}\n`); 117+ held: (until) => markStream(root, until), 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); 127+ stopped: () => stop, 129+ return ended.ended === "refused" 130+ ? { text: `The news stream refused this seat: ${ended.reason}`, json: ended, exit: 2 } 131+ : { text: "", json: ended }; 133+ process.off("SIGINT", onInt); 78136 const answer = await api.news(); 79137 const news = newsLines(answer.news); 80138 logNews(root, news);