Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/features/integrations/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion integrations/claude-code-plugin/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions integrations/claude-code-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <inbox> (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. |
Expand Down
2 changes: 1 addition & 1 deletion integrations/claude-code-plugin/hooks/HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 3 additions & 1 deletion integrations/claude-code-plugin/hooks/loom-session-start.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions integrations/claude-code-plugin/lib/after-tool.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions integrations/claude-code-plugin/skills/loom-memory/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions integrations/claude-code-plugin/skills/loom-memory/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
97 changes: 96 additions & 1 deletion integrations/claude-code-plugin/tests/after-tool.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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__";
Expand Down Expand Up @@ -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" };
Expand Down
Loading
Loading