{"draft":null,"from":175,"to":318,"files":[{"path":"client/hooks/register.ts","added":73,"removed":6,"diff":"--- a/client/hooks/register.ts\n+++ b/client/hooks/register.ts\n@@ -33,7 +33,7 @@\n \tuncomposedText,\n \ttype Who,\n } from \"../src/core.ts\";\n-import { STAMP } from \"./stamp.ts\";\n+import { HOOK_COMMAND, STAMP } from \"./stamp.ts\";\n \n const TOOLS = [\"Edit\", \"MultiEdit\", \"Write\", \"NotebookEdit\"];\n /** A known copy holding a NUL byte reads as no known copy (the client treats it as binary). */\n@@ -89,8 +89,15 @@\n let draining = false;\n const TICK_MS = 150;\n const roots = new Map<string, { root: string | undefined; at: number }>();\n-/** How often to ask for news without an edit (announcements reach an agent that isn't editing). */\n-const NEWS_POLL_MS = 30_000;\n+/**\n+ * How often to ask for news without an edit (announcements reach an agent that isn't editing). Every 5 minutes, and\n+ * 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\n+ * asking every 30 seconds (2026-10-15). abso news --stream (abso 690) wakes a chat without asking.\n+ */\n+const NEWS_POLL_MS = 5 * 60_000;\n+const IDLE_MS = 10 * 60_000;\n+/** When this chat last made a tool call (or started). */\n+let activeAt = 0;\n /** The abso folder this chat works in: the session's folder, or the first edited file's. */\n let newsRoot: string | undefined;\n let polling = false;\n@@ -108,8 +115,10 @@\n \t\t});\n \t\t// Outside an abso folder each tick only reads a variable.\n \t\tnewsRoot = await findRoot($, `${slash(await $.session.cwd())}/.`).catch(() => undefined);\n-\t\t$.clock.every(NEWS_POLL_MS, () => {\n+\t\tactiveAt = await $.clock.now();\n+\t\t$.clock.every(NEWS_POLL_MS, async () => {\n \t\t\tif (polling || newsRoot === undefined) return;\n+\t\t\tif ((await $.clock.now()) - activeAt >= IDLE_MS) return;\n \t\t\tpolling = true;\n \t\t\tvoid pollNews($, newsRoot).finally(() => {\n \t\t\t\tpolling = false;\n@@ -118,6 +127,11 @@\n \t\treturn next(e);\n \t});\n \n+\ton(\"tool.call\", async ($, e, next) => {\n+\t\tactiveAt = await $.clock.now();\n+\t\treturn next(e);\n+\t});\n+\n \ton(\"tool.call\", { tool: TOOLS }, async ($, e, next) => {\n \t\tconst ran = await next(e);\n \t\ttry {\n@@ -168,15 +182,24 @@\n \tfor (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job);\n }\n \n+/** A local project's folder (abso init --local): its config names no server. */\n+const LOCAL_FOLDER = /\"server\"\\s*:\\s*\"local\"/;\n+/** How long abso hook may take on a local project's edit: it waits up to two minutes for the store's lock. */\n+const LOCAL_HOOK_MS = 150_000;\n+\n async function run($: Engine, job: Job): Promise<void> {\n \tconst started = await $.clock.now().catch(() => job.queuedAt);\n \tlet outcome: string;\n \tlet news: readonly string[] = [];\n+\t/** What abso hook handed back for the agent, on a local project's edit (it keeps the news log itself). */\n+\tlet handed: string | undefined;\n \ttry {\n \t\tif ((await readOr($, `${await stateOf($, job.root)}/paused`)) !== undefined) {\n \t\t\toutcome = \"skipped: recording is paused (abso resume)\";\n \t\t} else if (/\"reader\"\\s*:\\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? \"\")) {\n \t\t\toutcome = \"skipped: this folder is a reader\";\n+\t\t} else if (LOCAL_FOLDER.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? \"\")) {\n+\t\t\t({ outcome, context: handed } = await handToClient($, job));\n \t\t} else if (await ignored($, job.root, job.rel)) {\n \t\t\toutcome = \"skipped: ignored path\";\n \t\t} else if (await isLink($, job.root, job.rel)) {\n@@ -197,11 +220,11 @@\n \t\tjob.root,\n \t\t`${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}`,\n \t);\n-\tconst context = newsContext(news);\n+\tconst context = handed ?? newsContext(news);\n \tif (context === undefined) return;\n \t// For anything that shows news later (the avcs-view mod reads it).\n \tconst at = new Date(done).toISOString();\n-\tawait log($, job.root, news.map((n) => `${at}\\t${n}`).join(\"\\n\"), \"news.log\");\n+\tif (news.length > 0) await log($, job.root, news.map((n) => `${at}\\t${n}`).join(\"\\n\"), \"news.log\");\n \ttry {\n \t\tawait $.session.append({\n \t\t\tmessage: { type: \"user\", content: [{ type: \"text\", text: context }] },\n@@ -214,14 +237,58 @@\n \t}\n }\n \n+/**\n+ * A local project's history is in a store on this machine that only the abso command opens, so its edits go to\n+ * `abso hook` from the checkout this mod was installed from, as Claude Code's command hook would run it.\n+ */\n+async function handToClient($: Engine, job: Job): Promise<{ outcome: string; context?: string }> {\n+\tif (HOOK_COMMAND === undefined || HOOK_COMMAND.length === 0)\n+\t\treturn {\n+\t\t\toutcome:\n+\t\t\t\t\"skipped: a local project, and this mod has no abso to hand it to (install-mod.ts adds one); abso record sends it\",\n+\t\t};\n+\tconst hookInput = {\n+\t\tsession_id: await $.session.id(),\n+\t\tcwd: slash(await $.session.cwd()),\n+\t\ttool_name: job.tool,\n+\t\ttool_input: job.input,\n+\t\t...(job.agentId ? { agent_id: job.agentId } : {}),\n+\t};\n+\tconst ran = await $.process.run(HOOK_COMMAND, {\n+\t\tcwd: job.root,\n+\t\tenv: { ABSO_HOOK_FORCE: \"1\" },\n+\t\tstdin: JSON.stringify(hookInput),\n+\t\ttimeoutMs: LOCAL_HOOK_MS,\n+\t});\n+\tif (ran.exitCode !== 0) throw new Error(`abso hook exited ${ran.exitCode}: ${ran.stderr.trim().split(\"\\n\").at(-1)}`);\n+\t// It prints Claude Code's JSON when it has news for the agent, and nothing otherwise.\n+\tconst out = ran.stdout.trim();\n+\tconst context =\n+\t\tout === \"\"\n+\t\t\t? undefined\n+\t\t\t: (JSON.parse(out) as { hookSpecificOutput?: { additionalContext?: unknown } }).hookSpecificOutput\n+\t\t\t\t\t?.additionalContext;\n+\treturn {\n+\t\toutcome: \"handed to abso hook (a local project; its own line is just above)\",\n+\t\t...(typeof context === \"string\" ? { context } : {}),\n+\t};\n+}\n+\n /** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */\n async function pollNews($: Engine, root: string): Promise<void> {\n \ttry {\n+\t\t// While this seat holds its news stream (abso news --stream or --follow, abso 690), the stream wakes the chat.\n+\t\tconst mark = await readOr($, `${await stateOf($, root)}/news-stream.json`);\n+\t\tif (mark !== undefined) {\n+\t\t\tconst until = Number((JSON.parse(mark) as { until?: unknown }).until);\n+\t\t\tif (Number.isFinite(until) && until > (await $.clock.now())) return;\n+\t\t}\n \t\tconst config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {\n \t\t\tserver: string;\n \t\t\tproject: string;\n \t\t\tagent: string;\n \t\t};\n+\t\tif (config.server === \"local\") return;\n \t\tconst bearer = await token($, config.server);\n \t\tconst r = await $.http.fetch(\n \t\t\t`${config.server.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,"}],"unmatched":[]}