From a23a29233c7167d67144681bc76958873df057cd Mon Sep 17 00:00:00 2001 From: Mohammad Lareb Zafar Date: Sat, 5 Dec 2026 00:19:03 +0000 Subject: [PATCH 1/4] The coding-agent plugins' defaults and the memory skill's receipt text agree with the server Three places where the plugins sent or said what the server does not accept or return: - The session-start hook sends LOOM_CONTEXT_TOKEN_BUDGET within 200 to 12,000, the range context.pack takes for token_budget. A value outside it was sent as typed, the op refused it, and the session started with no primer. - The capture hook's default skip list is the server's observe_skip_tools default: it gains mcp__plugin_loom*, which matches the tools of the server the plugin installs. The hook posted an observation of each of those calls and the server stored it with no content. The keys a memory read served are still stashed for the run's close. - The loom-memory skill reads a memory.set receipt by the fields the op answers: a row was written unless noop is true; a merge wrote nothing at the requested key and merged_into_key holds the fact; status: duplicate leaves both rows; a contradiction is conflict_verdict: conflict with peers and next. The skill said memory_id and version mean saved, which a merge also answers, and named a status: conflicted that no receipt carries. tests/unit/test_plugin_agrees_with_server.py compares each of the three with the server's model or setting, so a change on either side fails there. Signed-off-by: Mohammad Lareb Zafar Co-Authored-By: Claude Fable 5.2 --- docs/features/integrations/claude-code.md | 2 +- .../.claude-plugin/plugin.json | 2 +- integrations/claude-code-plugin/README.md | 1 + .../claude-code-plugin/hooks/HOOKS.md | 2 +- .../hooks/loom-session-start.mjs | 4 +- .../claude-code-plugin/lib/after-tool.mjs | 10 +- .../skills/loom-memory/SKILL.md | 6 +- .../skills/loom-memory/reference.md | 20 ++-- .../tests/after-tool.test.mjs | 97 ++++++++++++++++++- .../tests/session-start.test.mjs | 28 ++++++ .../codex-plugin/.codex-plugin/plugin.json | 2 +- .../codex-plugin/hooks/loom-session-start.mjs | 4 +- integrations/codex-plugin/lib/after-tool.mjs | 10 +- .../codex-plugin/skills/loom-memory/SKILL.md | 6 +- .../skills/loom-memory/reference.md | 20 ++-- .../served_skills/loom-memory/SKILL.md | 6 +- .../served_skills/loom-memory/reference.md | 20 ++-- server/transport/served_skills/manifest.json | 8 +- skills/loom-memory/SKILL.md | 6 +- skills/loom-memory/reference.md | 20 ++-- tests/unit/test_plugin_agrees_with_server.py | 89 +++++++++++++++++ 21 files changed, 304 insertions(+), 59 deletions(-) create mode 100644 tests/unit/test_plugin_agrees_with_server.py diff --git a/docs/features/integrations/claude-code.md b/docs/features/integrations/claude-code.md index 5bb4a477a0b..3a90f19d51e 100644 --- a/docs/features/integrations/claude-code.md +++ b/docs/features/integrations/claude-code.md @@ -1436,7 +1436,7 @@ Beyond the off switches in the table: | Variable | Default | Effect | | ---------------------------------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `LOOM_CONTEXT_TOKEN_BUDGET` | `1200` | token budget of the SessionStart primer | +| `LOOM_CONTEXT_TOKEN_BUDGET` | `1200` | token budget of the SessionStart primer, kept within the 200 to 12,000 that `context.pack` takes | | `LOOM_CODE_MAP_TOKEN_BUDGET` | `0` | token budget of the code map in the primer; `0` leaves the map out | | `LOOM_CONTEXT_RUNS` | `false` | include recent runs in the primer; `LOOM_CONTEXT_RUNS_LIMIT` (8) bounds them | | `LOOM_PROMPT_RECALL_MIN_CONF` | `0.5` | minimum `retrieval_confidence` before the prompt recall injects anything | diff --git a/integrations/claude-code-plugin/.claude-plugin/plugin.json b/integrations/claude-code-plugin/.claude-plugin/plugin.json index 2fd806675c8..e656ea8e169 100644 --- a/integrations/claude-code-plugin/.claude-plugin/plugin.json +++ b/integrations/claude-code-plugin/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "loom", "displayName": "ClickHouse Loom", - "version": "1.2.178", + "version": "1.2.182", "description": "Shared long-term memory and code intelligence for Claude Code, self-hosted on ClickHouse. MCP tools to save and recall decisions, preferences and corrections across sessions and teammates; lifecycle hooks that capture each session with no model call; a code index that answers where-is, who-calls and blast-radius questions with line-accurate units instead of whole-file reads.", "author": { "name": "ClickHouse" diff --git a/integrations/claude-code-plugin/README.md b/integrations/claude-code-plugin/README.md index d637b47eb44..4cc964c6687 100644 --- a/integrations/claude-code-plugin/README.md +++ b/integrations/claude-code-plugin/README.md @@ -653,6 +653,7 @@ path. | `LOOM_PROJECT_NAME` | _(git toplevel basename)_ | Override the resolved project. | | `LOOM_MODE` | `both` | Hook mode for Codex and hand-wired clients. The Claude Code plugin uses its `server_url` query. | | `LOOM_INJECT_CONTEXT` | `true` | SessionStart context primer (once per session). Set `false` to disable. | +| `LOOM_CONTEXT_TOKEN_BUDGET` | `1200` | Token budget of the SessionStart primer, kept within the 200 to 12,000 that `context.pack` takes: a value below or above is sent as that bound. | | `LOOM_TASK_INBOX_LINE` | `on` | SessionStart task inbox line: one `task.counts`, cached a minute, and one line when inboxes the namespace owns hold tasks in triage or todo — `Loom task inbox: N in triage, M to do in (oldest 40 min) — pull with the loom `tasks` toolset (task.pull)`. Silent on an empty board or when the server does not answer. Set `off` to disable. | | `LOOM_COLLECTIONS_LINE` | `on` | At session start, one `collection.list` call and a few lines naming up to six shared collections the token can read, with your role and each one's description inside the recalled-data block (their creators' words); how to write one only when you write one and the toolset allows writes. Silent when there are none, when the server does not answer, and under the Claude Code plugin when the endpoint's toolset is `assistant`. Set `off` to disable. | | `LOOM_SETUP_LINE` | `on` | SessionStart setup line: one line, once a day for each checkout, when the instruction file lacks the block `/loom:loom-setup` writes, or holds one where prompts get pointers: any block under `prompt_pack` `on`, and at the default only one that is not the current text or is alone in a `CLAUDE.md` beside an `AGENTS.md` with text of its own. `off` drops it, for a repository that declines the block or a harness that runs each session in a fresh directory. | diff --git a/integrations/claude-code-plugin/hooks/HOOKS.md b/integrations/claude-code-plugin/hooks/HOOKS.md index 3e8cfbe8cee..1e7640042de 100644 --- a/integrations/claude-code-plugin/hooks/HOOKS.md +++ b/integrations/claude-code-plugin/hooks/HOOKS.md @@ -1562,7 +1562,7 @@ Switches read on/true/1/yes and off/false/0/no. Defaults in parentheses. | `LOOM_HOOK_DEBUG` (off) | hooks ending in `runHookMain` | swallowed errors to stderr, redacted | | `LOOM_AUTO_SIGNUP` (on) | session-start, headers helper | first-session sign-up | | `LOOM_INJECT_CONTEXT` (on) | session-start | the primer | -| `LOOM_CONTEXT_TOKEN_BUDGET` (1200), `LOOM_CONTEXT_RUNS` (off), `LOOM_CONTEXT_RUNS_LIMIT` (8) | session-start | primer budget and the runs shortlist | +| `LOOM_CONTEXT_TOKEN_BUDGET` (1200), `LOOM_CONTEXT_RUNS` (off), `LOOM_CONTEXT_RUNS_LIMIT` (8) | session-start | primer budget, kept within the 200 to 12,000 `context.pack` takes, and the runs shortlist | | `LOOM_CODE_MAP` (on), `LOOM_CODE_MAP_TOKEN_BUDGET` (0 = no map) | session-start | the repo map | | `LOOM_TASK_INBOX_LINE` (on) | session-start | the task inbox line | | `LOOM_COLLECTIONS_LINE` (on) | session-start | the collections line | diff --git a/integrations/claude-code-plugin/hooks/loom-session-start.mjs b/integrations/claude-code-plugin/hooks/loom-session-start.mjs index f9b807ba7f7..bef7865c8ae 100755 --- a/integrations/claude-code-plugin/hooks/loom-session-start.mjs +++ b/integrations/claude-code-plugin/hooks/loom-session-start.mjs @@ -141,7 +141,9 @@ async function main() { } const scope = resolveScope(payload.cwd); - const tokenBudget = Math.round(envNumber("LOOM_CONTEXT_TOKEN_BUDGET", 1200, { min: 100 })); + // The range `context.pack` takes: it refuses a budget outside it, and a + // refused pack is a session with no primer. + const tokenBudget = Math.round(envNumber("LOOM_CONTEXT_TOKEN_BUDGET", 1200, { min: 200, max: 12000 })); // One GET /v1/health beside the primer: its round trip sets later hooks' bound, // its `version` feeds the minimum server version line. diff --git a/integrations/claude-code-plugin/lib/after-tool.mjs b/integrations/claude-code-plugin/lib/after-tool.mjs index fb621e21b48..2e1094e5e48 100644 --- a/integrations/claude-code-plugin/lib/after-tool.mjs +++ b/integrations/claude-code-plugin/lib/after-tool.mjs @@ -13,11 +13,13 @@ import { commandText, normalizeToolName, planeEnabled } from "./loom-client.mjs" // A call to loom's own tools is not observed — its input IS a // memory (observing loom_memory_set copies the value outside the key the // user can delete), and the harness's meta tools say nothing about the task. -// The server applies the same rule (setting observe_skip_tools); skipping -// here saves the request. LOOM_OBSERVE_SKIP_TOOLS overrides -// the list (comma-separated names; a trailing * matches a prefix). +// The server applies the same rule, and this list is its default (setting +// observe_skip_tools): the tools of the server this plugin installs arrive as +// `mcp__plugin_loom_loom__*`. Skipping here saves the request. +// LOOM_OBSERVE_SKIP_TOOLS overrides the list (comma-separated names; a +// trailing * matches a prefix). const DEFAULT_SKIP_TOOLS = - "mcp__loom__*,loom_memory_*,loom_knowledge_*,loom_search,loom_observe*,loom_procedure_*," + + "mcp__loom__*,mcp__plugin_loom*,loom_memory_*,loom_knowledge_*,loom_search,loom_observe*,loom_procedure_*," + "loom_context_*,loom_ask,ToolSearch,ListAgents,ListMcpResourcesTool,ReadMcpResourceTool," + "ReadMcpResourceDirTool,AskUserQuestion,TodoWrite,Skill,EnterPlanMode,ExitPlanMode," + "EnterWorktree,ExitWorktree"; diff --git a/integrations/claude-code-plugin/skills/loom-memory/SKILL.md b/integrations/claude-code-plugin/skills/loom-memory/SKILL.md index 3cf2c27f6c4..796b0056da5 100644 --- a/integrations/claude-code-plugin/skills/loom-memory/SKILL.md +++ b/integrations/claude-code-plugin/skills/loom-memory/SKILL.md @@ -64,9 +64,9 @@ file rules" in `reference.md` for removing a wrong one. ## Writing, reading, reviewing -- Read the receipt: `memory_id` and `version` mean it was saved; - `status: duplicate` means `duplicate_of` already holds the fact, so leave - both rows; `status: conflicted` names a row to revise instead. +- Read the receipt: it was saved unless `noop` is true; a merge + (`noop: true`) wrote nothing: `merged_into_key` holds the fact; + `status: duplicate`: leave both rows; a conflict: revise as `next` says. - `abstain` and `below_threshold` are answers; `verified: false` or a stale `valid_at` means say so; a moved key answers with `canonical_key`. - `code_state: changed` means the code the memory is about changed after it diff --git a/integrations/claude-code-plugin/skills/loom-memory/reference.md b/integrations/claude-code-plugin/skills/loom-memory/reference.md index 1aa6c5567b6..8efe792a09e 100644 --- a/integrations/claude-code-plugin/skills/loom-memory/reference.md +++ b/integrations/claude-code-plugin/skills/loom-memory/reference.md @@ -64,12 +64,18 @@ naming the critical codes — both point at `/loom-optimize`. ## Reading what Loom hands back -- **Persisted means the response says so.** A `memory.set` reply carries a - `memory_id` and `version`. If you did not get one, the fact is not saved — - say so; never tell the user something was remembered when the call failed - or you skipped it. -- **`conflict` / `status: conflicted`.** Your write semantically collides - with an existing fact. Tell the user both values in one sentence and ask +- **Persisted means the response says so.** A `memory.set` reply wrote a + row unless its `noop` is true. If you did not get one, the fact is not + saved — say so; never tell the user something was remembered when the + call failed or you skipped it. +- **`conflict_verdict: merge` with `noop: true`.** The store already held + the fact, under `merged_into_key` when that is set, and nothing was + written at your key. +- **`status: duplicate`.** `duplicate_of` already holds the fact; leave + both rows. +- **`conflict_verdict: conflict`.** Your write semantically collides + with an existing fact: `peers` lists the rows, `next` names the op to + revise with. Tell the user both values in one sentence and ask which is current; do not silently overwrite and do not pick for them. `409 PINNED_CONFLICT` means a human protected the existing fact: report it, do not retry with a new key. @@ -121,7 +127,7 @@ A claim about memory is only as good as the check behind it. Before you tell the user something *is* remembered, verified, or clean, run the check that proves it — the same way a compiler gate is not optional: -- "Saved" → the `memory.set` reply carried `memory_id` + `version`. +- "Saved" → the `memory.set` reply came back and its `noop` is not true. - "Verified" → `verification` on the read-back row says `human` or `process` and is not `stale` (you do not verify your own writes). - "The namespace is clean" → `namespace.validate` ran and returned no finding diff --git a/integrations/claude-code-plugin/tests/after-tool.test.mjs b/integrations/claude-code-plugin/tests/after-tool.test.mjs index 2846936ffbd..4435f3fd790 100644 --- a/integrations/claude-code-plugin/tests/after-tool.test.mjs +++ b/integrations/claude-code-plugin/tests/after-tool.test.mjs @@ -4,11 +4,16 @@ import "./temp-home.mjs"; import { test } from "node:test"; import assert from "node:assert/strict"; +import { spawn } from "node:child_process"; import fs from "node:fs"; +import http from "node:http"; import os from "node:os"; import path from "node:path"; +import { fileURLToPath } from "node:url"; -import { codeStashPath, followsCodeAnswer, recordsToolCall } from "../lib/after-tool.mjs"; +import { hostEnv } from "./host-env.mjs"; +import { codeStashPath, followsCodeAnswer, recordsToolCall, shouldObserve } from "../lib/after-tool.mjs"; +import { readRecalledStash } from "../lib/run-hook.mjs"; const SESSION = "after-tool-1"; const LOOM = "mcp__plugin_loom_loom__"; @@ -71,6 +76,96 @@ test("a Loom memory read is recorded for its served keys, whatever the skip list }); }); +const CAPTURE = fileURLToPath(new URL("../hooks/loom-capture.mjs", import.meta.url)); +const claims = (value) => Buffer.from(JSON.stringify(value)).toString("base64url"); +const TOKEN = `${claims({ alg: "none" })}.${claims({ org: "o", namespaces: ["coding"], sub: "sa:t" })}.sig`; +const SERVED_KEY = "repo/decision/parser"; + +/** Run the capture hook after the tool call `c` in memory mode, with `tmp` as + * its home and temp directory; resolves when it exits. */ +function capture(url, tmp, c) { + return new Promise((resolve) => { + const child = spawn(process.execPath, [CAPTURE, "PostToolUse"], { + env: hostEnv({ + PATH: process.env.PATH, + HOME: tmp, + TMPDIR: tmp, + LOOM_BASE_URL: url, + LOOM_API_KEY: TOKEN, + LOOM_MODE: "memory", + }), + stdio: ["pipe", "ignore", "ignore"], + }); + child.on("close", resolve); + child.stdin.end(JSON.stringify({ hook_event_name: "PostToolUse", cwd: tmp, ...c })); + }); +} + +/** What the capture hook leaves of a memory search on the plugin-installed + * server, under the default skip list: the tool of each observation the + * server was sent, and the keys stashed for the session. A Read follows the + * search and its observation is waited for, so one of the search has had its + * time to arrive. */ +async function afterPluginSearch(t) { + const tmp = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "loom-after-tool-"))); + const observed = []; + const srv = http.createServer((req, res) => { + let sent = ""; + req.on("data", (chunk) => (sent += chunk)); + req.on("end", () => { + if (req.url === "/v1/observe.record") observed.push(JSON.parse(sent).tool_name); + res.writeHead(200, { "content-type": "application/json" }); + res.end("{}"); + }); + }); + await new Promise((r) => srv.listen(0, "127.0.0.1", r)); + t.after(() => { + srv.closeAllConnections(); + srv.close(); + fs.rmSync(tmp, { recursive: true, force: true }); + }); + const url = `http://127.0.0.1:${srv.address().port}`; + await capture(url, tmp, { + ...call(`${LOOM}loom_search`, { query: "parser" }), + tool_response: { structuredContent: { memory: { results: [{ memory_key: SERVED_KEY }] } } }, + }); + await capture(url, tmp, call("Read", { file_path: path.join(tmp, "parser.py") })); + for (let waited = 0; waited < 10000 && !observed.includes("Read"); waited += 20) { + await new Promise((r) => setTimeout(r, 20)); + } + return { observed, stashed: readRecalledStash(SESSION, tmp) }; +} + +test("a tool of the plugin-installed server is not observed", async (t) => { + // The server stores an observation of one with no content (its + // `observe_skip_tools` default), so the request carries nothing a session reads. + assert.deepEqual((await afterPluginSearch(t)).observed, ["Read"]); + for (const tool of ["loom_search", "loom_memory_set", "loom_code_search", "loom_op"]) { + assert.equal(shouldObserve(LOOM + tool, ""), false, tool); + } + // A call that serves no keys either is handed to no copy of the hook. + withTmp((tmp) => { + for (const LOOM_MODE of ["memory", "both"]) { + for (const tool of ["loom_memory_set", "loom_op"]) { + assert.equal(recordsToolCall(call(LOOM + tool), { LOOM_MODE }, tmp), false, `${LOOM_MODE} ${tool}`); + } + } + }); +}); + +test("its served keys are still stashed", async (t) => { + // Skipping the observation must not skip the hook: the run's close reports + // the keys a memory read served from this stash. + withTmp((tmp) => { + for (const LOOM_MODE of ["memory", "both"]) { + for (const tool of ["loom_search", "loom_memory_get"]) { + assert.equal(recordsToolCall(call(LOOM + tool), { LOOM_MODE }, tmp), true, `${LOOM_MODE} ${tool}`); + } + } + }); + assert.deepEqual((await afterPluginSearch(t)).stashed, [SERVED_KEY]); +}); + test("in code mode a session that asked the index nothing records no tool call", () => { withTmp((tmp) => { const env = { LOOM_MODE: "code" }; diff --git a/integrations/claude-code-plugin/tests/session-start.test.mjs b/integrations/claude-code-plugin/tests/session-start.test.mjs index 680d322230a..b7d40f7ab9b 100644 --- a/integrations/claude-code-plugin/tests/session-start.test.mjs +++ b/integrations/claude-code-plugin/tests/session-start.test.mjs @@ -1493,3 +1493,31 @@ test("a plugin's new session asks the pack for no search and prints the memories assert.equal(bodies[0].only_sections, undefined, JSON.stringify(opts)); } }); + +/** The `token_budget` of every `context.pack` a memory-mode session sends with + * LOOM_CONTEXT_TOKEN_BUDGET set to `value`; undefined leaves it unset. */ +async function sentBudgets(t, value) { + const { home, dir } = checkout(t, null); + const loom = await fakeLoom(); + t.after(loom.close); + await startSession(loom.url, dir, home, { + env: { + LOOM_MODE: "memory", + // A checkout above the temporary folder does not answer for it. + GIT_CEILING_DIRECTORIES: path.dirname(dir), + ...(value === undefined ? {} : { LOOM_CONTEXT_TOKEN_BUDGET: value }), + }, + }); + return loom.packs.map((body) => body.token_budget); +} + +// `context.pack` takes a `token_budget` of 200 to 12,000 and refuses any +// other: a budget sent as typed outside that range is a session with no primer. +test("a budget below the server's floor is sent as the floor", async (t) => { + assert.deepEqual(await sentBudgets(t, "150"), [200]); + assert.deepEqual(await sentBudgets(t, undefined), [1200]); +}); + +test("a budget above its ceiling is sent as the ceiling", async (t) => { + assert.deepEqual(await sentBudgets(t, "20000"), [12000]); +}); diff --git a/integrations/codex-plugin/.codex-plugin/plugin.json b/integrations/codex-plugin/.codex-plugin/plugin.json index c23952753bc..61870f95cc9 100644 --- a/integrations/codex-plugin/.codex-plugin/plugin.json +++ b/integrations/codex-plugin/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "loom", - "version": "1.2.178", + "version": "1.2.182", "description": "Shared long-term memory and code intelligence for Codex, self-hosted on ClickHouse. MCP tools to save and recall decisions, preferences and corrections across sessions and teammates; lifecycle hooks that capture each session with no model call; a code index that answers where-is, who-calls and blast-radius questions with line-accurate units instead of whole-file reads.", "author": { "name": "ClickHouse" diff --git a/integrations/codex-plugin/hooks/loom-session-start.mjs b/integrations/codex-plugin/hooks/loom-session-start.mjs index f9b807ba7f7..bef7865c8ae 100755 --- a/integrations/codex-plugin/hooks/loom-session-start.mjs +++ b/integrations/codex-plugin/hooks/loom-session-start.mjs @@ -141,7 +141,9 @@ async function main() { } const scope = resolveScope(payload.cwd); - const tokenBudget = Math.round(envNumber("LOOM_CONTEXT_TOKEN_BUDGET", 1200, { min: 100 })); + // The range `context.pack` takes: it refuses a budget outside it, and a + // refused pack is a session with no primer. + const tokenBudget = Math.round(envNumber("LOOM_CONTEXT_TOKEN_BUDGET", 1200, { min: 200, max: 12000 })); // One GET /v1/health beside the primer: its round trip sets later hooks' bound, // its `version` feeds the minimum server version line. diff --git a/integrations/codex-plugin/lib/after-tool.mjs b/integrations/codex-plugin/lib/after-tool.mjs index fb621e21b48..2e1094e5e48 100644 --- a/integrations/codex-plugin/lib/after-tool.mjs +++ b/integrations/codex-plugin/lib/after-tool.mjs @@ -13,11 +13,13 @@ import { commandText, normalizeToolName, planeEnabled } from "./loom-client.mjs" // A call to loom's own tools is not observed — its input IS a // memory (observing loom_memory_set copies the value outside the key the // user can delete), and the harness's meta tools say nothing about the task. -// The server applies the same rule (setting observe_skip_tools); skipping -// here saves the request. LOOM_OBSERVE_SKIP_TOOLS overrides -// the list (comma-separated names; a trailing * matches a prefix). +// The server applies the same rule, and this list is its default (setting +// observe_skip_tools): the tools of the server this plugin installs arrive as +// `mcp__plugin_loom_loom__*`. Skipping here saves the request. +// LOOM_OBSERVE_SKIP_TOOLS overrides the list (comma-separated names; a +// trailing * matches a prefix). const DEFAULT_SKIP_TOOLS = - "mcp__loom__*,loom_memory_*,loom_knowledge_*,loom_search,loom_observe*,loom_procedure_*," + + "mcp__loom__*,mcp__plugin_loom*,loom_memory_*,loom_knowledge_*,loom_search,loom_observe*,loom_procedure_*," + "loom_context_*,loom_ask,ToolSearch,ListAgents,ListMcpResourcesTool,ReadMcpResourceTool," + "ReadMcpResourceDirTool,AskUserQuestion,TodoWrite,Skill,EnterPlanMode,ExitPlanMode," + "EnterWorktree,ExitWorktree"; diff --git a/integrations/codex-plugin/skills/loom-memory/SKILL.md b/integrations/codex-plugin/skills/loom-memory/SKILL.md index 3cf2c27f6c4..796b0056da5 100644 --- a/integrations/codex-plugin/skills/loom-memory/SKILL.md +++ b/integrations/codex-plugin/skills/loom-memory/SKILL.md @@ -64,9 +64,9 @@ file rules" in `reference.md` for removing a wrong one. ## Writing, reading, reviewing -- Read the receipt: `memory_id` and `version` mean it was saved; - `status: duplicate` means `duplicate_of` already holds the fact, so leave - both rows; `status: conflicted` names a row to revise instead. +- Read the receipt: it was saved unless `noop` is true; a merge + (`noop: true`) wrote nothing: `merged_into_key` holds the fact; + `status: duplicate`: leave both rows; a conflict: revise as `next` says. - `abstain` and `below_threshold` are answers; `verified: false` or a stale `valid_at` means say so; a moved key answers with `canonical_key`. - `code_state: changed` means the code the memory is about changed after it diff --git a/integrations/codex-plugin/skills/loom-memory/reference.md b/integrations/codex-plugin/skills/loom-memory/reference.md index 1aa6c5567b6..8efe792a09e 100644 --- a/integrations/codex-plugin/skills/loom-memory/reference.md +++ b/integrations/codex-plugin/skills/loom-memory/reference.md @@ -64,12 +64,18 @@ naming the critical codes — both point at `/loom-optimize`. ## Reading what Loom hands back -- **Persisted means the response says so.** A `memory.set` reply carries a - `memory_id` and `version`. If you did not get one, the fact is not saved — - say so; never tell the user something was remembered when the call failed - or you skipped it. -- **`conflict` / `status: conflicted`.** Your write semantically collides - with an existing fact. Tell the user both values in one sentence and ask +- **Persisted means the response says so.** A `memory.set` reply wrote a + row unless its `noop` is true. If you did not get one, the fact is not + saved — say so; never tell the user something was remembered when the + call failed or you skipped it. +- **`conflict_verdict: merge` with `noop: true`.** The store already held + the fact, under `merged_into_key` when that is set, and nothing was + written at your key. +- **`status: duplicate`.** `duplicate_of` already holds the fact; leave + both rows. +- **`conflict_verdict: conflict`.** Your write semantically collides + with an existing fact: `peers` lists the rows, `next` names the op to + revise with. Tell the user both values in one sentence and ask which is current; do not silently overwrite and do not pick for them. `409 PINNED_CONFLICT` means a human protected the existing fact: report it, do not retry with a new key. @@ -121,7 +127,7 @@ A claim about memory is only as good as the check behind it. Before you tell the user something *is* remembered, verified, or clean, run the check that proves it — the same way a compiler gate is not optional: -- "Saved" → the `memory.set` reply carried `memory_id` + `version`. +- "Saved" → the `memory.set` reply came back and its `noop` is not true. - "Verified" → `verification` on the read-back row says `human` or `process` and is not `stale` (you do not verify your own writes). - "The namespace is clean" → `namespace.validate` ran and returned no finding diff --git a/server/transport/served_skills/loom-memory/SKILL.md b/server/transport/served_skills/loom-memory/SKILL.md index 431b49039d3..90f9d21f53c 100644 --- a/server/transport/served_skills/loom-memory/SKILL.md +++ b/server/transport/served_skills/loom-memory/SKILL.md @@ -52,9 +52,9 @@ one of those conventions, update it: "Namespace guide" in `reference.md`. ## Writing, reading, reviewing -- Read the receipt: `memory_id` and `version` mean it was saved; - `status: duplicate` means `duplicate_of` already holds the fact, so leave - both rows; `status: conflicted` names a row to revise instead. +- Read the receipt: it was saved unless `noop` is true; a merge + (`noop: true`) wrote nothing: `merged_into_key` holds the fact; + `status: duplicate`: leave both rows; a conflict: revise as `next` says. - `abstain` and `below_threshold` are answers; `verified: false` or a stale `valid_at` means say so; a moved key answers with `canonical_key`. - `code_state: changed` means the code the memory is about changed after it diff --git a/server/transport/served_skills/loom-memory/reference.md b/server/transport/served_skills/loom-memory/reference.md index 9b138fcfbc5..99135a5bbd3 100644 --- a/server/transport/served_skills/loom-memory/reference.md +++ b/server/transport/served_skills/loom-memory/reference.md @@ -60,12 +60,18 @@ a `namespace_health` block. ## Reading what Loom hands back -- **Persisted means the response says so.** A `memory.set` reply carries a - `memory_id` and `version`. If you did not get one, the fact is not saved — - say so; never tell the user something was remembered when the call failed - or you skipped it. -- **`conflict` / `status: conflicted`.** Your write semantically collides - with an existing fact. Tell the user both values in one sentence and ask +- **Persisted means the response says so.** A `memory.set` reply wrote a + row unless its `noop` is true. If you did not get one, the fact is not + saved — say so; never tell the user something was remembered when the + call failed or you skipped it. +- **`conflict_verdict: merge` with `noop: true`.** The store already held + the fact, under `merged_into_key` when that is set, and nothing was + written at your key. +- **`status: duplicate`.** `duplicate_of` already holds the fact; leave + both rows. +- **`conflict_verdict: conflict`.** Your write semantically collides + with an existing fact: `peers` lists the rows, `next` names the op to + revise with. Tell the user both values in one sentence and ask which is current; do not silently overwrite and do not pick for them. `409 PINNED_CONFLICT` means a human protected the existing fact: report it, do not retry with a new key. @@ -106,7 +112,7 @@ A claim about memory is only as good as the check behind it. Before you tell the user something *is* remembered, verified, or clean, run the check that proves it — the same way a compiler gate is not optional: -- "Saved" → the `memory.set` reply carried `memory_id` + `version`. +- "Saved" → the `memory.set` reply came back and its `noop` is not true. - "Verified" → `verification` on the read-back row says `human` or `process` and is not `stale` (you do not verify your own writes). - "The namespace is clean" → `namespace.validate` ran and returned no finding diff --git a/server/transport/served_skills/manifest.json b/server/transport/served_skills/manifest.json index 2651f0712c4..6175c7eaa3d 100644 --- a/server/transport/served_skills/manifest.json +++ b/server/transport/served_skills/manifest.json @@ -8,13 +8,13 @@ "files": [ { "path": "SKILL.md", - "digest": "sha256:6b01c06c4a051e82caed3fd80ac0dc0728a5133091a18d8ba97a2a0c27b0f355", - "size": 4211 + "digest": "sha256:c60a13a71cc5c909ce8d3f9ec92c8583f267e40380ffd15e4d4e32f4e4ee6324", + "size": 4210 }, { "path": "reference.md", - "digest": "sha256:0a09390008a2261317c926910ceac9e7d35e1d41d3e641978f1a7fe288853404", - "size": 8356 + "digest": "sha256:73732b9c0c54e520243bab631a2e1b884402e94f3b300c36b7e5d109a655ea42", + "size": 8672 } ] }, diff --git a/skills/loom-memory/SKILL.md b/skills/loom-memory/SKILL.md index 14046725f0f..01073e6316b 100644 --- a/skills/loom-memory/SKILL.md +++ b/skills/loom-memory/SKILL.md @@ -72,9 +72,9 @@ file rules" in `reference.md` for removing a wrong one. ## Writing, reading, reviewing -- Read the receipt: `memory_id` and `version` mean it was saved; - `status: duplicate` means `duplicate_of` already holds the fact, so leave - both rows; `status: conflicted` names a row to revise instead. +- Read the receipt: it was saved unless `noop` is true; a merge + (`noop: true`) wrote nothing: `merged_into_key` holds the fact; + `status: duplicate`: leave both rows; a conflict: revise as `next` says. - `abstain` and `below_threshold` are answers; `verified: false` or a stale `valid_at` means say so; a moved key answers with `canonical_key`. - `code_state: changed` means the code the memory is about changed after it diff --git a/skills/loom-memory/reference.md b/skills/loom-memory/reference.md index 81ebe115b16..6bb7206a73f 100644 --- a/skills/loom-memory/reference.md +++ b/skills/loom-memory/reference.md @@ -61,12 +61,18 @@ through a redirect. When the namespace is being used as an object store, ## Reading what Loom hands back -- **Persisted means the response says so.** A `memory.set` reply carries a - `memory_id` and `version`. If you did not get one, the fact is not saved — - say so; never tell the user something was remembered when the call failed - or you skipped it. -- **`conflict` / `status: conflicted`.** Your write semantically collides - with an existing fact. Tell the user both values in one sentence and ask +- **Persisted means the response says so.** A `memory.set` reply wrote a + row unless its `noop` is true. If you did not get one, the fact is not + saved — say so; never tell the user something was remembered when the + call failed or you skipped it. +- **`conflict_verdict: merge` with `noop: true`.** The store already held + the fact, under `merged_into_key` when that is set, and nothing was + written at your key. +- **`status: duplicate`.** `duplicate_of` already holds the fact; leave + both rows. +- **`conflict_verdict: conflict`.** Your write semantically collides + with an existing fact: `peers` lists the rows, `next` names the op to + revise with. Tell the user both values in one sentence and ask which is current; do not silently overwrite and do not pick for them. `409 PINNED_CONFLICT` means a human protected the existing fact: report it, do not retry with a new key. @@ -112,7 +118,7 @@ A claim about memory is only as good as the check behind it. Before you tell the user something *is* remembered, verified, or clean, run the check that proves it — the same way a compiler gate is not optional: -- "Saved" → the `memory.set` reply carried `memory_id` + `version`. +- "Saved" → the `memory.set` reply came back and its `noop` is not true. - "Verified" → `verification` on the read-back row says `human` or `process` and is not `stale` (you do not verify your own writes). - "The namespace is clean" → `namespace.validate` ran and returned no finding diff --git a/tests/unit/test_plugin_agrees_with_server.py b/tests/unit/test_plugin_agrees_with_server.py new file mode 100644 index 00000000000..5470a7eda1a --- /dev/null +++ b/tests/unit/test_plugin_agrees_with_server.py @@ -0,0 +1,89 @@ +"""The coding-agent plugin's own defaults and its memory skill's receipt text, +against the server they talk to. + +The plugin holds two of the server's constants on its side, to save a request +the server would refuse or store empty, and its `loom-memory` skill tells an +agent how to read a `memory.set` receipt. The server is the reference for all +three: each test reads the plugin's file and the server's model or setting. +""" + +from __future__ import annotations + +import re +from pathlib import Path + +from server.memory.api.models_context import ContextPackInput +from server.memory.api.models_crud import MemorySetOutput +from server.settings import Settings + +PLUGIN = Path(__file__).resolve().parents[2] / "integrations" / "claude-code-plugin" +SKILL = PLUGIN / "skills" / "loom-memory" +# The values `MemorySetOutput.status` takes where the write path sets it. +RECEIPT_STATUSES = {"active", "duplicate", "proposed"} +# `name` or `name: value`, as the skill writes a field of the receipt. +_FIELD = re.compile(r"([a-z_]+)(?:: (\w+))?") + + +def test_the_plugin_skip_list_is_the_servers_default() -> None: + """Fails when the tools the capture hook does not observe differ from the + server's `observe_skip_tools` default: a tool only the server skips costs a + request whose observation is stored with no content.""" + source = (PLUGIN / "lib" / "after-tool.mjs").read_text(encoding="utf-8") + constant = re.search(r"const DEFAULT_SKIP_TOOLS =(.*?);", source, re.DOTALL) + assert constant, "lib/after-tool.mjs no longer defines DEFAULT_SKIP_TOOLS" + plugin = "".join(re.findall(r'"([^"]*)"', constant.group(1))).split(",") + + assert plugin == Settings.model_fields["observe_skip_tools"].default.split(",") + + +def test_the_plugin_budget_bounds_are_the_ops() -> None: + """Fails when the session-start hook clamps `LOOM_CONTEXT_TOKEN_BUDGET` to + another range than `context.pack` takes for `token_budget`: the op refuses + a value outside its range, and the session starts with no primer.""" + source = (PLUGIN / "hooks" / "loom-session-start.mjs").read_text(encoding="utf-8") + clamp = re.search(r'envNumber\(\s*"LOOM_CONTEXT_TOKEN_BUDGET",\s*(\d+),\s*\{([^}]*)\}', source) + assert clamp, "the session-start hook no longer clamps LOOM_CONTEXT_TOKEN_BUDGET" + fallback = int(clamp.group(1)) + bounds = {name: int(value) for name, value in re.findall(r"(\w+):\s*(\d+)", clamp.group(2))} + + limits = ContextPackInput.model_fields["token_budget"].metadata + ge = next(m.ge for m in limits if hasattr(m, "ge")) + le = next(m.le for m in limits if hasattr(m, "le")) + assert bounds == {"min": ge, "max": le} + # An unset variable is sent as the fallback, which nothing clamps. + assert ge <= fallback <= le + + +def _receipt_passages() -> dict[str, str]: + """The passages of the memory skill that say how to read a `memory.set` receipt.""" + skill = (SKILL / "SKILL.md").read_text(encoding="utf-8") + reference = (SKILL / "reference.md").read_text(encoding="utf-8") + found = { + "SKILL.md, the receipt bullet": re.search( + r"^- Read the receipt:.*?(?=^- )", skill, re.DOTALL | re.MULTILINE + ), + "reference.md, the receipt bullets": re.search( + r"^## Reading what Loom hands back\n(.*?)(?=^- \*\*A moved key)", + reference, + re.DOTALL | re.MULTILINE, + ), + 'reference.md, the "Saved" line': re.search(r'^- "Saved" → .*$', reference, re.MULTILINE), + } + missing = [name for name, match in found.items() if match is None] + assert not missing, f"the memory skill no longer has: {missing}" + return {name: match.group(0) for name, match in found.items() if match} + + +def test_the_memory_skill_names_only_receipt_fields_and_statuses() -> None: + """Fails when the skill's receipt text names a field `MemorySetOutput` does + not have, or a `status` no receipt carries (`conflicted` is a row's later + state, never a receipt's): an agent then reads a write as saved, or waits + for a status that never comes.""" + for where, text in _receipt_passages().items(): + named = [m for token in re.findall(r"`([^`]+)`", text) if (m := _FIELD.fullmatch(token))] + assert named, f"{where} names no field of the receipt" + for field in named: + name, value = field.groups() + assert name in MemorySetOutput.model_fields, f"{where}: `{field.group(0)}`" + if name == "status" and value: + assert value in RECEIPT_STATUSES, f"{where}: `{field.group(0)}`" From 364be31688a2c8a3190949c8af575e0356851f62 Mon Sep 17 00:00:00 2001 From: Mohammad Lareb Zafar Date: Sat, 5 Dec 2026 00:47:08 +0000 Subject: [PATCH 2/4] The memory skill's receipt test fails when a passage does not read saved from noop test_the_memory_skill_names_only_receipt_fields_and_statuses checked that each field the loom-memory skill's receipt text names is a field of MemorySetOutput and that a named status is one a receipt carries. memory_id and version are fields of the model, so a passage saying that those two mean a write was saved passed every assertion. A merge answers both and writes nothing at the requested key, which is the defect the skill text fixes. Each of the three passages (the receipt bullet of SKILL.md, the receipt bullets of reference.md and its "Saved" line) must now name noop, the field the saved rule reads. The test passes on the skill as it is and fails when any one of the three reads saved from memory_id and version. Signed-off-by: Mohammad Lareb Zafar Co-Authored-By: Claude Fable 5.2 --- tests/unit/test_plugin_agrees_with_server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_plugin_agrees_with_server.py b/tests/unit/test_plugin_agrees_with_server.py index 5470a7eda1a..708741126ec 100644 --- a/tests/unit/test_plugin_agrees_with_server.py +++ b/tests/unit/test_plugin_agrees_with_server.py @@ -78,10 +78,13 @@ def test_the_memory_skill_names_only_receipt_fields_and_statuses() -> None: """Fails when the skill's receipt text names a field `MemorySetOutput` does not have, or a `status` no receipt carries (`conflicted` is a row's later state, never a receipt's): an agent then reads a write as saved, or waits - for a status that never comes.""" + for a status that never comes. Fails too when a passage does not name + `noop`: a merge answers `memory_id` and `version` and writes nothing at + the requested key, so those two fields do not say a row was saved.""" for where, text in _receipt_passages().items(): named = [m for token in re.findall(r"`([^`]+)`", text) if (m := _FIELD.fullmatch(token))] assert named, f"{where} names no field of the receipt" + assert "noop" in {m.group(1) for m in named}, f"{where} does not read saved from noop" for field in named: name, value = field.groups() assert name in MemorySetOutput.model_fields, f"{where}: `{field.group(0)}`" From 8db4c386f6b4c480717c804f7d816db3d138c798 Mon Sep 17 00:00:00 2001 From: Mohammad Lareb Zafar Date: Sat, 5 Dec 2026 01:12:50 +0000 Subject: [PATCH 3/4] The reviewed pins of the session-start hook are the sha256 of the hook as it is tests/unit/session_content_senders.json pins the sha256 of each source that holds a reviewed sender, and test_shipped_automatic_senders_have_an_admission_class_or_reviewed_exception fails when a pinned source changes. The session-start hook is pinned, in the Claude Code plugin and in its Codex copy, and the clamp of LOOM_CONTEXT_TOKEN_BUDGET changed its bytes, so that test failed. The hook's diff is the two bounds passed to envNumber: it sends no new op and no new field, and the budget still goes only to context.pack. Both pins are renewed to the hook's sha256. Signed-off-by: Mohammad Lareb Zafar Co-Authored-By: Claude Fable 5.2 --- tests/unit/session_content_senders.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/session_content_senders.json b/tests/unit/session_content_senders.json index 5ff93acde62..ba362f74712 100644 --- a/tests/unit/session_content_senders.json +++ b/tests/unit/session_content_senders.json @@ -391,7 +391,7 @@ "integrations/claude-code-plugin/hooks/loom-flush.mjs": "a7634c8a3115aa98f0d7f5d098469cc3a87af4018fb2737c1a90fd27fc19c6e0", "integrations/claude-code-plugin/hooks/loom-namespace-health.mjs": "5f2bd718a88587c5f66b9823317bc77c18ce6a124f0602368b254d2c8c733ddb", "integrations/claude-code-plugin/hooks/loom-prompt-pack.mjs": "f9bf11cd98b0ca8ad110fe2db631f7af9ab9ce94ca07ab88a603128f0bdebdc6", - "integrations/claude-code-plugin/hooks/loom-session-start.mjs": "31ba0130495c6cbd40a3e4e673d9709deafb0cefb0b655b117d22a2437502b78", + "integrations/claude-code-plugin/hooks/loom-session-start.mjs": "4394ac465b4efc5898f03143b38112aaa8015489ac7dc03fa458966bb46b9f16", "integrations/claude-code-plugin/lib/collections-line.mjs": "4415df00d8af1cbb64f5bc25fa1ba1176433b122c1ae35f809b3981f4439c8c9", "integrations/claude-code-plugin/lib/first-session.mjs": "ea5c41ac14f173aa81c8fefc894d72a6661be66e242d0b614f502a0de98b8646", "integrations/claude-code-plugin/lib/flush-job.mjs": "e6c4ae5e42a54cba0e171b727688be621a81245023bf85a8ac093d334bc9bfd5", @@ -406,7 +406,7 @@ "integrations/codex-plugin/hooks/loom-flush.mjs": "a7634c8a3115aa98f0d7f5d098469cc3a87af4018fb2737c1a90fd27fc19c6e0", "integrations/codex-plugin/hooks/loom-namespace-health.mjs": "5f2bd718a88587c5f66b9823317bc77c18ce6a124f0602368b254d2c8c733ddb", "integrations/codex-plugin/hooks/loom-prompt-pack.mjs": "f9bf11cd98b0ca8ad110fe2db631f7af9ab9ce94ca07ab88a603128f0bdebdc6", - "integrations/codex-plugin/hooks/loom-session-start.mjs": "31ba0130495c6cbd40a3e4e673d9709deafb0cefb0b655b117d22a2437502b78", + "integrations/codex-plugin/hooks/loom-session-start.mjs": "4394ac465b4efc5898f03143b38112aaa8015489ac7dc03fa458966bb46b9f16", "integrations/codex-plugin/lib/collections-line.mjs": "4415df00d8af1cbb64f5bc25fa1ba1176433b122c1ae35f809b3981f4439c8c9", "integrations/codex-plugin/lib/first-session.mjs": "ea5c41ac14f173aa81c8fefc894d72a6661be66e242d0b614f502a0de98b8646", "integrations/codex-plugin/lib/flush-job.mjs": "e6c4ae5e42a54cba0e171b727688be621a81245023bf85a8ac093d334bc9bfd5", From 52e51fb149cbacdd1891efaacc05f25cc53d1b5e Mon Sep 17 00:00:00 2001 From: Mohammad Lareb Zafar Date: Sat, 5 Dec 2026 01:12:57 +0000 Subject: [PATCH 4/4] The memory skill's receipt test fails a passage that names memory_id or version test_the_memory_skill_names_only_receipt_fields_and_statuses required each receipt passage to name noop. The receipt bullet of SKILL.md and the receipt bullets of reference.md name noop in their merge clause as well, so the rule "memory_id and version mean it was saved" put back beside that clause passed the test. The test also fails a passage that names memory_id or version, the two fields a merge answers while it writes nothing at the requested key. None of the three passages names them. With the old rule put back in one passage at a time, the test fails for each of the three. Signed-off-by: Mohammad Lareb Zafar Co-Authored-By: Claude Fable 5.2 --- tests/unit/test_plugin_agrees_with_server.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_plugin_agrees_with_server.py b/tests/unit/test_plugin_agrees_with_server.py index 708741126ec..80a29ea0b1b 100644 --- a/tests/unit/test_plugin_agrees_with_server.py +++ b/tests/unit/test_plugin_agrees_with_server.py @@ -20,6 +20,9 @@ SKILL = PLUGIN / "skills" / "loom-memory" # The values `MemorySetOutput.status` takes where the write path sets it. RECEIPT_STATUSES = {"active", "duplicate", "proposed"} +# A merge answers these too and writes nothing at the requested key, so a +# receipt passage that names one reads a merge as a saved row. +MERGE_ALSO_ANSWERS = {"memory_id", "version"} # `name` or `name: value`, as the skill writes a field of the receipt. _FIELD = re.compile(r"([a-z_]+)(?:: (\w+))?") @@ -79,12 +82,18 @@ def test_the_memory_skill_names_only_receipt_fields_and_statuses() -> None: not have, or a `status` no receipt carries (`conflicted` is a row's later state, never a receipt's): an agent then reads a write as saved, or waits for a status that never comes. Fails too when a passage does not name - `noop`: a merge answers `memory_id` and `version` and writes nothing at - the requested key, so those two fields do not say a row was saved.""" + `noop`, or names `memory_id` or `version`: a merge answers both and writes + nothing at the requested key, and a passage can name `noop` for the merge + and still read saved from those two.""" for where, text in _receipt_passages().items(): named = [m for token in re.findall(r"`([^`]+)`", text) if (m := _FIELD.fullmatch(token))] assert named, f"{where} names no field of the receipt" - assert "noop" in {m.group(1) for m in named}, f"{where} does not read saved from noop" + names = {m.group(1) for m in named} + assert "noop" in names, f"{where} does not read saved from noop" + assert not names & MERGE_ALSO_ANSWERS, ( + f"{where} reads saved from a field a merge also answers: " + f"{sorted(names & MERGE_ALSO_ANSWERS)}" + ) for field in named: name, value = field.groups() assert name in MemorySetOutput.model_fields, f"{where}: `{field.group(0)}`"