Lines 33–39 at 318 (were 33–39 at 116)
3535} from "../src/core.ts"; 36−import { STAMP } from "./stamp.ts";
36+import { HOOK_COMMAND, STAMP } from "./stamp.ts"; 3838const TOOLS = ["Edit", "MultiEdit", "Write", "NotebookEdit"]; 3939/** A known copy holding a NUL byte reads as no known copy (the client treats it as binary). */ Lines 89–103 at 318 (were 89–96 at 116)
8989let draining = false; 9191const roots = new Map<string, { root: string | undefined; at: number }>(); 92−/** How often to ask for news without an edit (announcements reach an agent that isn't editing). */
93−const NEWS_POLL_MS = 30_000;
93+ * How often to ask for news without an edit (announcements reach an agent that isn't editing). Every 5 minutes, and 94+ * not at all in a chat that has made no tool call for IDLE_MS: prod abso's object reset under the load of every chat 95+ * asking every 30 seconds (2026-10-15). abso news --stream (abso 690) wakes a chat without asking. 97+const NEWS_POLL_MS = 5 * 60_000; 98+const IDLE_MS = 10 * 60_000; 99+/** When this chat last made a tool call (or started). */ 94101/** The abso folder this chat works in: the session's folder, or the first edited file's. */ 95102let newsRoot: string | undefined; 96103let polling = false; Lines 115–124 at 318 (were 108–115 at 116)
109116 // Outside an abso folder each tick only reads a variable. 110117 newsRoot = await findRoot($, `${slash(await $.session.cwd())}/.`).catch(() => undefined); 111− $.clock.every(NEWS_POLL_MS, () => {
118+ activeAt = await $.clock.now(); 119+ $.clock.every(NEWS_POLL_MS, async () => { 112120 if (polling || newsRoot === undefined) return; 121+ if ((await $.clock.now()) - activeAt >= IDLE_MS) return; 114123 void pollNews($, newsRoot).finally(() => { Lines 127–137 at 318 (were 118–123 at 116)
130+ on("tool.call", async ($, e, next) => { 131+ activeAt = await $.clock.now(); 121135 on("tool.call", { tool: TOOLS }, async ($, e, next) => { 122136 const ran = await next(e); Lines 182–205 at 318 (were 168–182 at 116)
168182 for (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job); 185+/** A local project's folder (abso init --local): its config names no server. */ 186+const LOCAL_FOLDER = /"server"\s*:\s*"local"/; 187+/** How long abso hook may take on a local project's edit: it waits up to two minutes for the store's lock. */ 188+const LOCAL_HOOK_MS = 150_000; 171190async function run($: Engine, job: Job): Promise<void> { 172191 const started = await $.clock.now().catch(() => job.queuedAt); 173192 let outcome: string; 174193 let news: readonly string[] = []; 194+ /** What abso hook handed back for the agent, on a local project's edit (it keeps the news log itself). */ 195+ let handed: string | undefined; 176197 if ((await readOr($, `${await stateOf($, job.root)}/paused`)) !== undefined) { 177198 outcome = "skipped: recording is paused (abso resume)"; 178199 } else if (/"reader"\s*:\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) { 179200 outcome = "skipped: this folder is a reader"; 201+ } else if (LOCAL_FOLDER.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) { 202+ ({ outcome, context: handed } = await handToClient($, job)); 180203 } else if (await ignored($, job.root, job.rel)) { 181204 outcome = "skipped: ignored path"; 182205 } else if (await isLink($, job.root, job.rel)) { Lines 220–230 at 318 (were 197–207 at 116)
198221 `${new Date(job.queuedAt).toISOString()}\t${job.tool}\t${job.rel}\t${outcome}\t${done - started}ms sending, ${started - job.queuedAt}ms queued (in process, async)\t${CLIENT}`, 200− const context = newsContext(news);
223+ const context = handed ?? newsContext(news); 201224 if (context === undefined) return; 202225 // For anything that shows news later (the avcs-view mod reads it). 203226 const at = new Date(done).toISOString(); 204− await log($, job.root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
227+ if (news.length > 0) await log($, job.root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log"); 206229 await $.session.append({ 207230 message: { type: "user", content: [{ type: "text", text: context }] }, Lines 237–294 at 318 (were 214–227 at 116)
241+ * A local project's history is in a store on this machine that only the abso command opens, so its edits go to 242+ * `abso hook` from the checkout this mod was installed from, as Claude Code's command hook would run it. 244+async function handToClient($: Engine, job: Job): Promise<{ outcome: string; context?: string }> { 245+ if (HOOK_COMMAND === undefined || HOOK_COMMAND.length === 0) 248+ "skipped: a local project, and this mod has no abso to hand it to (install-mod.ts adds one); abso record sends it", 251+ session_id: await $.session.id(), 252+ cwd: slash(await $.session.cwd()), 253+ tool_name: job.tool, 254+ tool_input: job.input, 255+ ...(job.agentId ? { agent_id: job.agentId } : {}), 257+ const ran = await $.process.run(HOOK_COMMAND, { 259+ env: { ABSO_HOOK_FORCE: "1" }, 260+ stdin: JSON.stringify(hookInput), 261+ timeoutMs: LOCAL_HOOK_MS, 263+ if (ran.exitCode !== 0) throw new Error(`abso hook exited ${ran.exitCode}: ${ran.stderr.trim().split("\n").at(-1)}`); 264+ // It prints Claude Code's JSON when it has news for the agent, and nothing otherwise. 265+ const out = ran.stdout.trim(); 269+ : (JSON.parse(out) as { hookSpecificOutput?: { additionalContext?: unknown } }).hookSpecificOutput 270+ ?.additionalContext; 272+ outcome: "handed to abso hook (a local project; its own line is just above)", 273+ ...(typeof context === "string" ? { context } : {}), 217277/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */ 218278async function pollNews($: Engine, root: string): Promise<void> { 280+ // While this seat holds its news stream (abso news --stream or --follow, abso 690), the stream wakes the chat. 281+ const mark = await readOr($, `${await stateOf($, root)}/news-stream.json`); 282+ if (mark !== undefined) { 283+ const until = Number((JSON.parse(mark) as { until?: unknown }).until); 284+ if (Number.isFinite(until) && until > (await $.clock.now())) return; 220286 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as { 291+ if (config.server === "local") return; 225292 const bearer = await token($, config.server); 226293 const r = await $.http.fetch( 227294 `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,