{"draft":null,"from":2,"to":318,"files":[{"path":"client/src/announce.ts","added":69,"removed":8,"diff":"--- a/client/src/announce.ts\n+++ b/client/src/announce.ts\n@@ -2,10 +2,14 @@\n // delivered once as news on each one's next edit (or the mod's next poll),\n // and the news waiting for this agent.\n \n+import { writeFileSync } from \"node:fs\";\n+import { join } from \"node:path\";\n import { newsLines } from \"./api.ts\";\n import { bool, type Parsed, str, UsageError } from \"./args.ts\";\n import { type Env, type Output, open, plural } from \"./commands.ts\";\n import { logNews } from \"./folder.ts\";\n+import { follow, monitorArgs, type Socket, STREAM_MARK, streamMarkUntil, streamText } from \"./news-stream.ts\";\n+import { stateDir } from \"./state-dir.ts\";\n import { newsWithTime } from \"./times.ts\";\n \n export async function runAnnounce(args: Parsed, env: Env): Promise<Output> {\n@@ -24,7 +28,7 @@\n \tconst answer = await api.announce(text, to);\n \tconst who = answer.to.length === 0 ? \"nobody (no other agents yet)\" : answer.to.join(\", \");\n \treturn {\n-\t\ttext: `Announced to ${who}. Each gets it once, as news on their next edit, or within about 30 seconds where the abso mod runs.`,\n+\t\ttext: `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.`,\n \t\tjson: { id: answer.id, to: answer.to },\n \t};\n }\n@@ -46,21 +50,21 @@\n \t\tthrow new UsageError('--issue takes an issue number: abso start \"<what>\" --issue 12');\n \tconst answer = await api.starting(text, files, issue !== undefined ? { issue } : {});\n \tconst lines = [\n-\t\t`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).` +\n-\t\t\t(issue !== undefined ? ` abso publish --done closes issue ${issue}.` : \"\"),\n+\t\t`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).` +\n+\t\t\t(issue !== undefined ? ` abso push --done closes issue ${issue}.` : \"\"),\n \t];\n \tif (answer.overlaps.length > 0) {\n \t\tlines.push(\"Already there:\");\n \t\tfor (const o of answer.overlaps) {\n \t\t\tconst what = [\n-\t\t\t\to.changes ? plural(o.changes, \"unpublished change\") : \"\",\n+\t\t\t\to.changes ? plural(o.changes, \"unpushed change\") : \"\",\n \t\t\t\to.starting ? `starting on \"${o.starting}\"` : \"\",\n \t\t\t]\n \t\t\t\t.filter((w) => w !== \"\")\n \t\t\t\t.join(\", \");\n \t\t\tlines.push(`  ${o.file}: ${o.agent}${what === \"\" ? \"\" : ` (${what})`}`);\n \t\t}\n-\t\t// The sentence people act on names who, and their note (#37, Builder 5 had to run abso where to learn it).\n+\t\t// The sentence people act on names who, and their note (#37: without it, an agent had to run abso where to learn it).\n \t\tconst agents = [...new Set(answer.overlaps.map((o) => o.agent))];\n \t\tconst notes = agents.flatMap((a) => {\n \t\t\tconst note = answer.overlaps.find((o) => o.agent === a && o.starting)?.starting;\n@@ -73,8 +77,62 @@\n \treturn { text: lines.join(\"\\n\"), json: { ...answer } };\n }\n \n-export async function runNews(_args: Parsed, env: Env): Promise<Output> {\n-\tconst { root, api } = open(env);\n+/** Says this folder's seat holds its news stream until `until`, so the abso-hooks mod's poll stands down. Best effort. */\n+function markStream(root: string, until: number): void {\n+\ttry {\n+\t\twriteFileSync(join(stateDir(root), STREAM_MARK), JSON.stringify({ until }));\n+\t} catch {\n+\t\t// The mod keeps polling; nothing is lost.\n+\t}\n+}\n+\n+export async function runNews(args: Parsed, env: Env): Promise<Output> {\n+\tconst { root, config, api } = open(env);\n+\tif (bool(args, \"stream\") && bool(args, \"follow\"))\n+\t\tthrow new UsageError(\"abso news takes --stream or --follow, not both\");\n+\tif (bool(args, \"stream\")) {\n+\t\tconst ticket = await api.newsTicket();\n+\t\tmarkStream(root, streamMarkUntil(ticket, Date.now()));\n+\t\treturn {\n+\t\t\ttext: streamText(ticket, config.project, config.agent),\n+\t\t\tjson: { monitor: monitorArgs(ticket, config.project, config.agent), expiresAt: ticket.expiresAt },\n+\t\t};\n+\t}\n+\tif (bool(args, \"follow\")) {\n+\t\tlet stop = false;\n+\t\tconst onInt = () => {\n+\t\t\tstop = true;\n+\t\t};\n+\t\tprocess.once(\"SIGINT\", onInt);\n+\t\ttry {\n+\t\t\tconst ended = await follow({\n+\t\t\t\tmint: () => api.newsTicket(),\n+\t\t\t\t// A frame is a wake: read the news, which marks it heard, and print that (news-stream.ts).\n+\t\t\t\ttake: async () => newsLines((await api.news()).news),\n+\t\t\t\tconnect: (url, protocols) => new WebSocket(url, [...protocols]) as unknown as Socket,\n+\t\t\t\twrite: (line) => {\n+\t\t\t\t\tlogNews(root, [line]);\n+\t\t\t\t\tenv.write(`${line.replace(/\\r?\\n/g, \" \")}\\n`);\n+\t\t\t\t},\n+\t\t\t\theld: (until) => markStream(root, until),\n+\t\t\t\tnote: (line) =>\n+\t\t\t\t\tenv.write(`${line}\n+`),\n+\t\t\t\tsleep: (ms) => new Promise((ok) => setTimeout(ok, ms)),\n+\t\t\t\tnow: () => Date.now(),\n+\t\t\t\tevery: (ms, fn) => {\n+\t\t\t\t\tconst t = setInterval(fn, ms);\n+\t\t\t\t\treturn () => clearInterval(t);\n+\t\t\t\t},\n+\t\t\t\tstopped: () => stop,\n+\t\t\t});\n+\t\t\treturn ended.ended === \"refused\"\n+\t\t\t\t? { text: `The news stream refused this seat: ${ended.reason}`, json: ended, exit: 2 }\n+\t\t\t\t: { text: \"\", json: ended };\n+\t\t} finally {\n+\t\t\tprocess.off(\"SIGINT\", onInt);\n+\t\t}\n+\t}\n \tconst answer = await api.news();\n \tconst news = newsLines(answer.news);\n \tlogNews(root, news);\n@@ -82,7 +140,10 @@\n \tconst at = new Map((answer.items ?? []).map((i) => [i.text, i.at]));\n \tconst items = news.map((text) => ({ text, at: at.get(text) ?? null }));\n \treturn {\n-\t\ttext: [`${plural(news.length, \"news item\")}:`, ...items.map((i) => `  ${newsWithTime(i.text, i.at)}`)].join(\"\\n\"),\n+\t\ttext: [\n+\t\t\t`${plural(news.length, \"news item\")}:`,\n+\t\t\t...items.map((i) => `  ${newsWithTime(i.text, i.at).replace(/\\r?\\n/g, \"\\n    \")}`),\n+\t\t].join(\"\\n\"),\n \t\tjson: { news, items, delivered: Date.now() },\n \t};\n }"}],"unmatched":[]}