{"draft":null,"from":280,"to":318,"files":[{"path":"client/hooks/register.test.ts","added":38,"removed":2,"diff":"--- a/client/hooks/register.test.ts\n+++ b/client/hooks/register.test.ts\n@@ -3,9 +3,10 @@\n \n import type { On } from \"claude-code\";\n import { expect, mock, test } from \"claude-code/testing\";\n+import { HOOK_COMMAND } from \"./stamp.ts\";\n \n /** The world beneath the mod: a chat in /w/p, an abso folder when `inFolder`, and a server with `news` waiting. */\n-function world(on: On, inFolder: boolean, news: string[][]) {\n+function world(on: On, inFolder: boolean, news: string[][], server = \"https://avcs.test\") {\n \tmock.env(on, { AVCS_TOKEN: \"test-token\" });\n \tconst clock = mock.clock(on, { now: 1_000_000 });\n \tconst asked: string[] = [];\n@@ -21,7 +22,7 @@\n \ton(\"fs.read\", (_$, e) => {\n \t\tconst path = norm(e.path);\n \t\tif (inFolder && path === \"/w/p/.abso/config.json\")\n-\t\t\treturn { value: JSON.stringify({ server: \"https://avcs.test\", project: \"p\", agent: \"bob\" }) };\n+\t\t\treturn { value: JSON.stringify({ server, project: \"p\", agent: \"bob\" }) };\n \t\tif (written.has(path)) return { value: written.get(path)! };\n \t\treturn { deny: `ENOENT: ${path}` };\n \t});\n@@ -114,3 +115,38 @@\n \texpect(w.written.get(\"/w/p/.abso/hook.log\") ?? \"\").toContain(\"not sent: a NUL byte at line 3\");\n \texpect(w.asked.filter((u) => !u.endsWith(\"/news\"))).toEqual([]);\n });\n+\n+test(\"a local project's edit goes to abso hook as Claude Code's command hook would get it, and its news to the chat\", async ($, on) => {\n+\tconst w = world(on, true, [], \"local\");\n+\tw.written.set(\"/w/p/notes.md\", \"hello\\n\");\n+\ton(\"fs.stat\", () => ({ value: { realPath: \"/w/p/notes.md\" } }) as never);\n+\ton(\"session.id\", () => ({ value: \"sess\" }));\n+\tconst ran: { argv: readonly string[]; stdin?: string; env?: Record<string, string> }[] = [];\n+\tconst context = \"abso: Announcement from lead: hold pushes\";\n+\ton(\"process.run\", (_$, e) => {\n+\t\tran.push({ argv: e.argv, stdin: e.init?.stdin, env: e.init?.env });\n+\t\tconst stdout = JSON.stringify({ hookSpecificOutput: { hookEventName: \"PostToolUse\", additionalContext: context } });\n+\t\treturn { value: { exitCode: 0, stdout, stderr: \"\" } } as never;\n+\t});\n+\tawait $.session.start({ cwd: \"/w/p\" });\n+\tawait $.tool.call({ tool: \"Write\", tool_use_id: \"t1\", file_path: \"/w/p/notes.md\", content: \"hello\\n\" } as never);\n+\tawait w.clock.advance(1_000);\n+\t// A local project has no server to call: nothing goes over the network.\n+\texpect(w.asked.filter((u) => !u.endsWith(\"/news\"))).toEqual([]);\n+\tconst log = w.written.get(\"/w/p/.abso/hook.log\") ?? \"\";\n+\tif (HOOK_COMMAND === undefined) {\n+\t\t// Loaded from a checkout, the mod has no client to hand it to.\n+\t\texpect(ran).toEqual([]);\n+\t\texpect(log).toContain(\"skipped: a local project\");\n+\t\treturn;\n+\t}\n+\texpect(ran).toHaveLength(1);\n+\texpect(ran[0]!.argv).toEqual(HOOK_COMMAND);\n+\texpect(ran[0]!.env).toEqual({ ABSO_HOOK_FORCE: \"1\" });\n+\tconst input = JSON.parse(ran[0]!.stdin ?? \"{}\") as Record<string, unknown>;\n+\texpect(input.session_id).toBe(\"sess\");\n+\texpect(input.tool_name).toBe(\"Write\");\n+\texpect((input.tool_input as Record<string, unknown>).file_path).toBe(\"/w/p/notes.md\");\n+\texpect(log).toContain(\"handed to abso hook\");\n+\texpect(w.appended).toEqual([context]);\n+});"},{"path":"client/hooks/register.ts","added":50,"removed":3,"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@@ -182,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@@ -211,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@@ -228,6 +237,43 @@\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@@ -242,6 +288,7 @@\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`,"},{"path":"client/hooks/stamp.ts","added":6,"removed":0,"diff":"--- a/client/hooks/stamp.ts\n+++ b/client/hooks/stamp.ts\n@@ -3,3 +3,9 @@\n // this file with the version it installs: plugin.json's, plus the commit\n // (0.1.0+702c616). Loaded straight from a checkout, it stays undefined.\n export const STAMP: string | undefined = undefined;\n+\n+// The command that runs `abso hook` from the checkout the mod was installed\n+// from, as [node, client/abso.ts, \"hook\"]; the installer writes it too. A\n+// local project's history is in a store on this machine that only the abso\n+// command opens, so the mod hands those edits to it.\n+export const HOOK_COMMAND: readonly string[] | undefined = undefined;"}],"unmatched":[]}