{"version":269,"agent":"box-grants","message":"abso news --stream and --follow (abso 690, news wakes agents): --stream mints a ticket and prints the Monitor call (ws URL plus subprotocols, 30-minute timeout) so a Claude Code chat wakes the moment news arrives, with no polling. --follow holds the seat's stream itself, a line per item, a new ticket per socket, a ping every 45 s, waits 1 s doubling to a minute between sockets, and stops on a refused key or a server without the stream (404). The key never goes in a URL or a Monitor call. Needs the server's news/ticket and news/stream routes (Read Speed, next). Tests: client/test/news-stream.test.ts.","time":1792101553240,"timeIso":"2026-10-15T21:59:13.240Z","changes":7,"change":4087,"files":["client/src/announce.ts","client/src/api.ts","client/src/main.ts","client/src/news-stream.ts","client/test/news-stream.test.ts"],"draft":null,"diff":[{"path":"client/src/announce.ts","added":44,"removed":2,"diff":"--- a/client/src/announce.ts\n+++ b/client/src/announce.ts\n@@ -6,6 +6,7 @@\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, streamText } from \"./news-stream.ts\";\n import { newsWithTime } from \"./times.ts\";\n \n export async function runAnnounce(args: Parsed, env: Env): Promise<Output> {\n@@ -73,8 +74,49 @@\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+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\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\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\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);"},{"path":"client/src/api.ts","added":5,"removed":0,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -977,6 +977,11 @@\n \t\treturn this.json(\"POST\", this.agentPath(\"news\"), {});\n \t}\n \n+\t/** A ticket that opens this agent's news stream once, within a minute (abso 690; news-stream.ts). */\n+\tnewsTicket(): Promise<{ url: string; protocols: string[]; expiresAt: number }> {\n+\t\treturn this.json(\"POST\", this.agentPath(\"news/ticket\"), {});\n+\t}\n+\n \t/** This agent's unpublished changes, file by file. */\n \tdiff(): Promise<DiffAnswer> {\n \t\treturn this.json(\"POST\", this.agentPath(\"diff\"), {});"},{"path":"client/src/main.ts","added":3,"removed":3,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -762,10 +762,10 @@\n \t\trun: runStart,\n \t},\n \tnews: {\n-\t\tflags: {},\n-\t\tusage: \"abso news\",\n+\t\tflags: { stream: \"boolean\", follow: \"boolean\" },\n+\t\tusage: \"abso news [--stream | --follow]\",\n \t\tabout:\n-\t\t\t\"The news waiting for you: collisions, changed definitions, moved lines and announcements. Each item comes once.\",\n+\t\t\t\"The news waiting for you: collisions, changed definitions, moved lines and announcements. Each item comes once. --stream prints a Monitor call that wakes a Claude Code chat the moment news arrives (a ticket that opens the stream once, within a minute); --follow holds the stream itself and prints a line per item until stopped.\",\n \t\trun: runNews,\n \t},\n \t\"fix-eol\": {"},{"path":"client/src/news-stream.ts","added":135,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/news-stream.ts\n@@ -0,0 +1,135 @@\n+// abso news --stream and --follow (abso 690): news the moment it arrives, with no polling.\n+//\n+// The server holds a WebSocket per seat on the project's object. Opening one takes a ticket, minted with the seat's\n+// key: it opens that seat's stream once, within a minute, and rides as a subprotocol, never in the URL. A Claude Code\n+// Monitor can't send headers, and whatever its call names is written into the chat, so the key never goes there.\n+//\n+// --stream prints the Monitor's arguments with a fresh ticket. --follow holds the socket itself and prints a line per\n+// item, opening a new one (with a new ticket) whenever it closes; the ticket is never printed. On connect the server\n+// sends what arrived since the seat last heard its news, so nothing is lost between sockets.\n+\n+/** The subprotocol a news stream speaks; the ticket rides beside it as `abso-ticket.<ticket>`. */\n+export const NEWS_PROTOCOL = \"abso-news.1\";\n+\n+/** What the server answers a ticket request with. */\n+export interface NewsTicket {\n+\treadonly url: string;\n+\treadonly protocols: readonly string[];\n+\treadonly expiresAt: number;\n+}\n+\n+/** A Monitor lasts at most 30 minutes; the skill re-arms it when it ends. */\n+export const MONITOR_TIMEOUT_MS = 30 * 60_000;\n+\n+/** The Monitor call that holds a seat's stream: `Monitor({ ws, description, timeout_ms })`. */\n+export function monitorArgs(\n+\tticket: NewsTicket,\n+\tproject: string,\n+\tagent: string,\n+): { ws: { url: string; protocols: string[] }; description: string; timeout_ms: number } {\n+\treturn {\n+\t\tws: { url: ticket.url, protocols: [...ticket.protocols] },\n+\t\tdescription: `abso news for ${agent} in ${project}`,\n+\t\ttimeout_ms: MONITOR_TIMEOUT_MS,\n+\t};\n+}\n+\n+/** The text --stream prints: the call to make, then the arguments as one line of JSON. */\n+export function streamText(ticket: NewsTicket, project: string, agent: string, now = Date.now()): string {\n+\tconst seconds = Math.max(0, Math.round((ticket.expiresAt - now) / 1000));\n+\treturn [\n+\t\t`Open this with Monitor within ${seconds} seconds (the ticket opens ${agent}'s news stream once). When the Monitor ends or the socket closes, run abso news --stream again; the new socket sends what arrived in between.`,\n+\t\tJSON.stringify(monitorArgs(ticket, project, agent)),\n+\t].join(\"\\n\");\n+}\n+\n+/** The part of a WebSocket --follow uses: the platform's own, or a test's. */\n+export interface Socket {\n+\tonopen: (() => void) | null;\n+\tonmessage: ((e: { data: unknown }) => void) | null;\n+\tonclose: ((e: { code: number; reason: string }) => void) | null;\n+\tonerror: ((e: unknown) => void) | null;\n+\tsend(text: string): void;\n+\tclose(code?: number): void;\n+}\n+\n+/** A close the server sends when the ticket or key is refused: --follow stops instead of trying again. */\n+export function isRefusal(code: number): boolean {\n+\treturn code === 4401 || code === 4403;\n+}\n+\n+/** How long --follow waits before opening a socket again: 1 s doubling to a minute; a socket that lived a minute resets it. */\n+export function nextWait(previous: number, livedMs: number): number {\n+\tif (livedMs >= 60_000) return 1_000;\n+\treturn Math.min(60_000, Math.max(1_000, previous * 2));\n+}\n+\n+/** The client sends this every PING_MS so an idle socket stays open; the object answers it without waking. */\n+export const PING = \"ping\";\n+export const PONG = \"pong\";\n+export const PING_MS = 45_000;\n+\n+export interface FollowDeps {\n+\tmint(): Promise<NewsTicket>;\n+\tconnect(url: string, protocols: readonly string[]): Socket;\n+\t/** One news item, as the server sent it. */\n+\twrite(line: string): void;\n+\t/** A line about the stream itself, not news. */\n+\tnote(line: string): void;\n+\tsleep(ms: number): Promise<void>;\n+\tnow(): number;\n+\tevery(ms: number, fn: () => void): () => void;\n+\t/** Set when --follow should stop (Ctrl-C, or a test). */\n+\treadonly stopped: () => boolean;\n+}\n+\n+/** Why a mint failed: a refused key, or a server with no news stream (404), stops --follow; anything else is tried again. */\n+function refusedMint(err: unknown): boolean {\n+\tconst status = (err as { status?: number }).status;\n+\treturn status === 401 || status === 403 || status === 404;\n+}\n+\n+/**\n+ * Holds the seat's stream, printing one line per item, until the key is refused or `stopped()`.\n+ * Returns why it ended.\n+ */\n+export async function follow(deps: FollowDeps): Promise<{ ended: \"refused\" | \"stopped\"; reason: string }> {\n+\tlet wait = 1_000;\n+\twhile (!deps.stopped()) {\n+\t\tlet ticket: NewsTicket;\n+\t\ttry {\n+\t\t\tticket = await deps.mint();\n+\t\t} catch (err) {\n+\t\t\tif (refusedMint(err)) return { ended: \"refused\", reason: (err as Error).message };\n+\t\t\tdeps.note(`(abso news --follow: no ticket: ${(err as Error).message}; trying again in ${wait / 1000} s)`);\n+\t\t\tawait deps.sleep(wait);\n+\t\t\twait = nextWait(wait, 0);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tconst opened = deps.now();\n+\t\tconst closed = await new Promise<{ code: number; reason: string }>((done) => {\n+\t\t\tconst socket = deps.connect(ticket.url, ticket.protocols);\n+\t\t\tlet stopPing = () => {};\n+\t\t\tsocket.onopen = () => {\n+\t\t\t\tstopPing = deps.every(PING_MS, () => {\n+\t\t\t\t\tif (deps.stopped()) socket.close(1000);\n+\t\t\t\t\telse socket.send(PING);\n+\t\t\t\t});\n+\t\t\t};\n+\t\t\tsocket.onmessage = (e) => {\n+\t\t\t\tif (typeof e.data !== \"string\" || e.data === PONG) return;\n+\t\t\t\tdeps.write(e.data);\n+\t\t\t};\n+\t\t\tsocket.onerror = () => {};\n+\t\t\tsocket.onclose = (e) => {\n+\t\t\t\tstopPing();\n+\t\t\t\tdone({ code: e.code, reason: e.reason });\n+\t\t\t};\n+\t\t});\n+\t\tif (isRefusal(closed.code)) return { ended: \"refused\", reason: closed.reason || `closed ${closed.code}` };\n+\t\tif (deps.stopped()) break;\n+\t\twait = nextWait(wait, deps.now() - opened);\n+\t\tawait deps.sleep(wait);\n+\t}\n+\treturn { ended: \"stopped\", reason: \"stopped\" };\n+}"},{"path":"client/test/news-stream.test.ts","added":163,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/news-stream.test.ts\n@@ -0,0 +1,163 @@\n+// abso news --stream and --follow (abso 690): the Monitor call, and holding the stream through closes and refusals.\n+\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import {\n+\ttype FollowDeps,\n+\tfollow,\n+\tisRefusal,\n+\tMONITOR_TIMEOUT_MS,\n+\tmonitorArgs,\n+\tNEWS_PROTOCOL,\n+\ttype NewsTicket,\n+\tnextWait,\n+\tPING,\n+\tPING_MS,\n+\tPONG,\n+\ttype Socket,\n+\tstreamText,\n+} from \"../src/news-stream.ts\";\n+\n+const NOW = 1_800_000_000_000;\n+const ticket = (n: number): NewsTicket => ({\n+\turl: \"wss://api.abso.dev/p/abso/a/fe/news/stream\",\n+\tprotocols: [NEWS_PROTOCOL, `abso-ticket.t${n}`],\n+\texpiresAt: NOW + 60_000,\n+});\n+\n+test(\"--stream prints the Monitor call: the URL and protocols as the server gave them, 30 minutes, named for the seat\", () => {\n+\tconst args = monitorArgs(ticket(1), \"abso\", \"fe\");\n+\tassert.deepEqual(args, {\n+\t\tws: { url: \"wss://api.abso.dev/p/abso/a/fe/news/stream\", protocols: [\"abso-news.1\", \"abso-ticket.t1\"] },\n+\t\tdescription: \"abso news for fe in abso\",\n+\t\ttimeout_ms: MONITOR_TIMEOUT_MS,\n+\t});\n+\tassert.equal(MONITOR_TIMEOUT_MS, 30 * 60_000);\n+\t// The ticket never goes in the URL.\n+\tassert.doesNotMatch(args.ws.url, /t1/);\n+\tconst text = streamText(ticket(1), \"abso\", \"fe\", NOW + 15_000).split(\"\\n\");\n+\tassert.match(text[0]!, /within 45 seconds/);\n+\tassert.match(text[0]!, /run abso news --stream again/);\n+\tassert.deepEqual(JSON.parse(text[1]!), args);\n+});\n+\n+test(\"a refusal close stops --follow; any other close opens again, waiting 1 s doubling to a minute\", () => {\n+\tassert.equal(isRefusal(4401), true);\n+\tassert.equal(isRefusal(4403), true);\n+\tassert.equal(isRefusal(1006), false);\n+\tassert.equal(isRefusal(1001), false);\n+\tassert.equal(nextWait(1_000, 0), 2_000);\n+\tassert.equal(nextWait(32_000, 5_000), 60_000);\n+\tassert.equal(nextWait(60_000, 5_000), 60_000);\n+\t// A socket that lived a minute starts the wait over.\n+\tassert.equal(nextWait(60_000, 60_000), 1_000);\n+});\n+\n+/** A world for follow(): each connect gets the next script of frames and a close. */\n+function world(scripts: { frames: string[]; close: { code: number; reason?: string }; livedMs?: number }[]) {\n+\tlet now = NOW;\n+\tlet n = 0;\n+\tconst lines: string[] = [];\n+\tconst notes: string[] = [];\n+\tconst sent: string[] = [];\n+\tconst slept: number[] = [];\n+\tconst opened: { url: string; protocols: readonly string[] }[] = [];\n+\tconst pings: (() => void)[] = [];\n+\tlet stop = false;\n+\tconst deps: FollowDeps = {\n+\t\tmint: async () => ticket(++n),\n+\t\tconnect: (url, protocols) => {\n+\t\t\topened.push({ url, protocols });\n+\t\t\tconst script = scripts[opened.length - 1];\n+\t\t\tconst socket: Socket = {\n+\t\t\t\tonopen: null,\n+\t\t\t\tonmessage: null,\n+\t\t\t\tonclose: null,\n+\t\t\t\tonerror: null,\n+\t\t\t\tsend: (text) => sent.push(text),\n+\t\t\t\tclose: () => {},\n+\t\t\t};\n+\t\t\tqueueMicrotask(() => {\n+\t\t\t\tsocket.onopen?.();\n+\t\t\t\tif (script === undefined) {\n+\t\t\t\t\tstop = true;\n+\t\t\t\t\tsocket.onclose?.({ code: 1000, reason: \"\" });\n+\t\t\t\t\treturn;\n+\t\t\t\t}\n+\t\t\t\tfor (const pinged of pings.splice(0)) pinged();\n+\t\t\t\tfor (const data of script.frames) socket.onmessage?.({ data });\n+\t\t\t\tnow += script.livedMs ?? 1_000;\n+\t\t\t\tsocket.onclose?.({ code: script.close.code, reason: script.close.reason ?? \"\" });\n+\t\t\t});\n+\t\t\treturn socket;\n+\t\t},\n+\t\twrite: (line) => lines.push(line),\n+\t\tnote: (line) => notes.push(line),\n+\t\tsleep: async (ms) => {\n+\t\t\tslept.push(ms);\n+\t\t},\n+\t\tnow: () => now,\n+\t\tevery: (ms, fn) => {\n+\t\t\tassert.equal(ms, PING_MS);\n+\t\t\tpings.push(fn);\n+\t\t\treturn () => {};\n+\t\t},\n+\t\tstopped: () => stop,\n+\t};\n+\treturn { deps, lines, notes, sent, slept, opened };\n+}\n+\n+test(\"--follow prints each item once, skips the server's pongs, and opens a new socket with a new ticket after a close\", async () => {\n+\tconst w = world([\n+\t\t{ frames: [\"fe told you: hello\", PONG, \"an ask from cloud: ship it?\"], close: { code: 1006 } },\n+\t\t{ frames: [\"second socket's item\"], close: { code: 1001 }, livedMs: 120_000 },\n+\t]);\n+\tconst ended = await follow(w.deps);\n+\tassert.deepEqual(ended, { ended: \"stopped\", reason: \"stopped\" });\n+\tassert.deepEqual(w.lines, [\"fe told you: hello\", \"an ask from cloud: ship it?\", \"second socket's item\"]);\n+\t// Each socket used its own ticket; each ticket was used once.\n+\tassert.deepEqual(\n+\t\tw.opened.map((o) => o.protocols[1]),\n+\t\t[\"abso-ticket.t1\", \"abso-ticket.t2\", \"abso-ticket.t3\"],\n+\t);\n+\t// The first socket lived a second: wait 2 s. The second lived two minutes: start over at 1 s.\n+\tassert.deepEqual(w.slept, [2_000, 1_000]);\n+\tassert.equal(w.notes.length, 0);\n+});\n+\n+test(\"--follow keeps an idle socket open with a ping the object answers without waking\", async () => {\n+\tconst w = world([{ frames: [], close: { code: 1006 } }]);\n+\tawait follow(w.deps);\n+\tassert.deepEqual(w.sent, [PING]);\n+});\n+\n+test(\"a refused ticket or a refusal close ends --follow; a ticket that can't be had is tried again\", async () => {\n+\tconst refusedClose = world([{ frames: [\"one item\"], close: { code: 4401, reason: \"the key was revoked\" } }]);\n+\tassert.deepEqual(await follow(refusedClose.deps), { ended: \"refused\", reason: \"the key was revoked\" });\n+\tassert.deepEqual(refusedClose.lines, [\"one item\"]);\n+\n+\tconst w = world([{ frames: [], close: { code: 1000 } }]);\n+\tlet tries = 0;\n+\tconst mint = w.deps.mint;\n+\tw.deps.mint = async () => {\n+\t\ttries++;\n+\t\tif (tries === 1) throw Object.assign(new Error(\"could not reach the server\"), { status: undefined });\n+\t\tif (tries === 3)\n+\t\t\tthrow Object.assign(new Error(\"POST /a/fe/news/ticket answered 401: no such key\"), { status: 401 });\n+\t\treturn mint();\n+\t};\n+\tconst ended = await follow(w.deps);\n+\tassert.equal(ended.ended, \"refused\");\n+\tassert.match(ended.reason, /401/);\n+\tassert.equal(w.notes.length, 1);\n+\tassert.match(w.notes[0]!, /no ticket: could not reach the server; trying again in 1 s/);\n+\tassert.deepEqual(w.lines, []);\n+\n+\t// A server without the stream (before abso 690) answers the ticket 404: stop, don't retry.\n+\tconst old = world([]);\n+\told.deps.mint = async () => {\n+\t\tthrow Object.assign(new Error(\"POST /a/fe/news/ticket answered 404: not found\"), { status: 404 });\n+\t};\n+\tassert.equal((await follow(old.deps)).ended, \"refused\");\n+\tassert.deepEqual(old.slept, []);\n+});"}],"ci":null}