Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
cc3cbee
Automatic hooks retain bound session privacy
zlareb1 Nov 19, 2026
86a9a54
Keep plugin tests isolated and formatted
zlareb1 Nov 19, 2026
1956c23
Retain Cline hooks for established session families
zlareb1 Nov 19, 2026
f142434
Sender inventory tracks protected plugin delivery
zlareb1 Nov 19, 2026
3f72184
Cline retains producer privacy through capture and publication
zlareb1 Nov 19, 2026
583ab86
Withhold automatic context after its family becomes private
zlareb1 Nov 19, 2026
6676bea
Assert that nested automatic responses withhold private content
zlareb1 Nov 19, 2026
b524ddb
Stop primer publication when parallel work protects its family
zlareb1 Nov 19, 2026
08d47c8
Protected sessions suppress shunt denials after symbol lookup
zlareb1 Nov 19, 2026
2fb02a5
Windows session families use checked native file authority
zlareb1 Nov 19, 2026
a8a8a7f
Windows session failures retain bounded startup diagnostics
zlareb1 Nov 19, 2026
a15cf46
Windows diagnostics distinguish entry from missing output
zlareb1 Nov 19, 2026
708020c
Windows diagnostics separate encoding creation from assignment
zlareb1 Nov 19, 2026
c7c08cc
Construct Windows protection objects without the cmdlet layer
zlareb1 Nov 19, 2026
13b722c
Codex startup establishes one durable session family
zlareb1 Nov 19, 2026
e23db03
Preserve alias corruption checks with permanent claims
zlareb1 Nov 19, 2026
c86ea6a
Bind native Claude startup before automatic hooks
zlareb1 Nov 19, 2026
9f8dcd7
Pin existing Windows compiler ancestors before creation
zlareb1 Nov 19, 2026
aefe53b
Report bounded phase timing from Windows lifetime witnesses
zlareb1 Nov 19, 2026
9b45ba7
Windows authority uses one PowerShell guardian
zlareb1 Nov 19, 2026
a072d70
Windows compiler environment follows ordinal ordering
zlareb1 Nov 19, 2026
a57431a
Session privacy retains bounded coding-context changes
zlareb1 Nov 19, 2026
07d4fd0
Prompt hook fixtures retain their existing session families
zlareb1 Nov 19, 2026
f088b36
Windows deadline diagnostics separate request phases
zlareb1 Nov 19, 2026
6a57681
Retain Windows session alias history claims
zlareb1 Nov 19, 2026
21aae66
Decode Windows helper requests in the compiled assembly
zlareb1 Nov 19, 2026
c3d6c47
Give each code-result lesson test its own org
zlareb1 Nov 19, 2026
22f4bb7
Isolate code-result lesson fixtures
zlareb1 Nov 19, 2026
c22e201
Report bounded compiler and queue failure stages
zlareb1 Nov 19, 2026
c7b94da
Merge commit '933235c60d0b4c1d3ebfb432a653ea259dbe7f93' into fix/plug…
zlareb1 Nov 19, 2026
979db71
Compiler sample observations preserve failure codes
zlareb1 Nov 19, 2026
14abd41
Windows root diagnostics distinguish entry and flushed records
zlareb1 Nov 19, 2026
39852c0
End completed Windows helpers with their checked exit status
zlareb1 Nov 19, 2026
4063247
Create root records only inside their retained parents
zlareb1 Nov 19, 2026
e0a1bb1
Report retained shunt control counts after a failed fixture
zlareb1 Nov 19, 2026
bd713df
Retain numeric codes from fatal compiler diagnostics
zlareb1 Nov 19, 2026
50e5dd1
Report fixed scanner child error categories
zlareb1 Nov 19, 2026
13c87be
Serialize fixed scanner observations without a cmdlet
zlareb1 Nov 19, 2026
c52ac77
Observe the expected operand after compiler refusal
zlareb1 Nov 19, 2026
bef21f1
Locate checked protection writes in native diagnostics
zlareb1 Nov 19, 2026
34f6299
Separate compiler startup containment from compilation control
zlareb1 Nov 19, 2026
869a2c2
Locate compiler witness announcement boundaries
zlareb1 Nov 19, 2026
26624c2
Format the fixed compiler witness receipt directly
zlareb1 Nov 19, 2026
d507070
Keep lifetime failures visible when cleanup also fails
zlareb1 Nov 19, 2026
188517b
Windows lifetime tests identify observer boundaries
zlareb1 Nov 19, 2026
2ff26b9
Windows lifetime diagnostics separate read and path checks
zlareb1 Nov 19, 2026
0d36276
Windows lifetime fixtures resolve their temporary base
zlareb1 Nov 19, 2026
dedf8df
Use native realpath for the Windows lifetime fixture
zlareb1 Nov 19, 2026
bd33cee
Classify the existing Windows liveness observations
zlareb1 Nov 19, 2026
c6185d0
Locate Windows process reads against their compiler cutoff
zlareb1 Nov 19, 2026
7f2afd2
Observe Windows parent death before the compiler cutoff
zlareb1 Nov 20, 2026
b312cd0
Retain guardian diagnostics after the test parent exits
zlareb1 Nov 20, 2026
32a9bf5
Report when the witness compiler wait returns
zlareb1 Nov 20, 2026
0cb225f
Merge current main into session privacy work
zlareb1 Nov 20, 2026
67bf945
Compose session privacy clients with current plugin fixes
zlareb1 Nov 20, 2026
11c69ad
Give session privacy clients a distinct plugin version
zlareb1 Nov 20, 2026
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 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.45",
"version": "1.2.47",
"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
23 changes: 21 additions & 2 deletions integrations/claude-code-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ tokens per `tools/list`; every other op runs through `loom_op {op, arguments}`.

> **Bare mode skips hooks.** `claude --bare` (chosen by some agent harnesses for prompt-cache and cost reasons) does not run PreToolUse hooks, so the token shunt and the outcome capture in this plugin do not fire there. A harness that wants the shunt under bare mode needs the SDK backend's hook path instead.

A `SessionStart` event with `source: startup` establishes one durable session
family before automatic hook work. Concurrent startup hooks use that same
family; existing privacy marks never reset. Other lifecycle events resolve an
existing family. Unknown, damaged or protected families stay silent, including
automatic signup and the session primer. Binding uses the hook's raw
`session_id`; a payload containing only `sessionId` stays silent. The hooks do
not declare protection for direct MCP responses. Native startup, response
observation and private-content publication remain unqualified.

On Windows, the local authority uses the process token owner and protected
owner-only access controls on NTFS. A bounded helper checks record handles and
contains its compiler children. Unsupported storage or unverifiable authority
stays silent. Native execution, startup timing and failure cleanup remain
unqualified.

## Data handling

The hooks and scripts send data only to the Loom server the plugin is configured
Expand Down Expand Up @@ -104,8 +119,12 @@ Its files in the system temp directory, which can hold prompt and reply text,
are also mode 0600. A queued write whose delivery process stopped before sending
it stays until you replay or delete it; `loom-status` counts these and names the
directory. A write the server refuses, or that cannot reach the server, is
discarded. A batch of the per-file read and grep records above that fails to
send is discarded too. Chat turns that fail are sent again at the end of the
discarded. Per-file read and grep reports retain their original producer's
privacy roots. A report with unknown or protected producer state is not sent.
Those reports and failed delivery claims stay on disk without acknowledgement;
failed claims are not replayed automatically. Pending and claimed shunt reports
are excluded from the current plugin's cleanup. Older plugin versions can still
expire older-format files. Chat turns that fail are sent again at the end of the
next reply, and a brief's events at the next brief save. At session start the
plugin tries to remove other state files untouched for a day. They can remain
longer, especially when no new session starts. The log of which tool calls the plugin redirected
Expand Down
3 changes: 2 additions & 1 deletion integrations/claude-code-plugin/hooks/loom-blast-radius.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
gitToplevel,
postBounded,
readStdinJson,
runHookMain,
DIFF_ARGS,
diffHeaders,
resolveServerUrl,
Expand Down Expand Up @@ -122,4 +123,4 @@ async function main() {
scheduleExit(0);
}

main().catch(() => scheduleExit(0));
runHookMain(main);
172 changes: 113 additions & 59 deletions integrations/claude-code-plugin/hooks/loom-code-shunt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// user's decision log (tmpStatePath "shunt-log") and its unflushed copy, one
// batch per reporting scope and session (repo.pending, named by batchKind in
// lib/shunt-ledger.mjs), all through lib/tmp-state.mjs's private-file helpers,
// flushed as code.outcome rows (fire-and-forget, 300 ms) on a deny or every
// flushed as code.outcome rows (300 ms per request) on a deny or every
// SHUNT_FLUSH_EVERY lines (lib/shunt-ledger.mjs).
import fs from "node:fs";
import path from "node:path";
Expand All @@ -31,8 +31,8 @@ import {
gitToplevel,
pathUnder,
postBounded,
postFireAndForget,
readStdinJson,
runHookMain,
resolveServerUrl,
resolveToken,
redactSecrets,
Expand Down Expand Up @@ -69,6 +69,8 @@ import {
estimateTokensRead,
estimateTokensSaved,
formatShuntLine,
formatShuntBatchLine,
parseShuntBatch,
shouldFlushShunt,
} from "../lib/shunt-ledger.mjs";
import { repoLookupOutcome, resolveIndexedRepo, resolveTimeoutMs } from "../lib/repo-scope.mjs";
Expand All @@ -82,6 +84,13 @@ import {
writeSessionState,
} from "../lib/tmp-state.mjs";

import { sessionIsProtected } from "../lib/session-protection.mjs";
import {
automaticSessionIsProtected,
sessionProtectionContext,
withCapturedSessionProtection,
} from "../lib/session-response.mjs";

const ENABLED = envSwitch("LOOM_CODE_SHUNT", true);
const MAX_LINES = Number(process.env.LOOM_SHUNT_MAX_LINES || DEFAULT_MAX_LINES);
const READ_CAP = Math.max(0, Number(process.env.LOOM_SHUNT_READ_CAP || DEFAULT_READ_CAP) || 0);
Expand All @@ -101,8 +110,7 @@ const LOG_PATH = tmpStatePath("shunt-log", UID, { ext: ".log" });

/** The unflushed batch, set on `repo` in main: `kind` names the reporting scope
* (server, token, repository) every batch of it shares, `path` this session's
* batch, a name nobody can create ahead of the session. Batches and claimed
* batches are swept with the other state files. A flush also claims the
* batch. Unacknowledged batches and claims do not expire. A flush also claims the
* scope's other batches: those ended or crashed sessions left, and those of
* sessions still running. */
function pendingFor(repo, sessionId) {
Expand All @@ -112,7 +120,7 @@ function pendingFor(repo, sessionId) {
org: repo.org || "",
namespace: repo.namespace || "",
});
return { kind, path: sessionStatePath(kind, sessionId, { ext: ".log" }) };
return { kind, path: sessionStatePath(kind, sessionId, { ext: ".log.control" }) };
}

function countLines(abs) {
Expand Down Expand Up @@ -183,32 +191,59 @@ function fileBytes(abs) {
}
}

/** Append one decision locally; returns the number of unflushed lines. Sync
* appends of one short line — microseconds, and never on the network. */
function logDecision(pending, { decision, tool, tokensSaved, reason, passReason, path, startLine, endLine }) {
if (!LOG_ON) return 0;
const line = formatShuntLine({
decision,
tool,
tokensSaved,
reason,
passReason,
path,
startLine,
endLine,
});
/** Only a newly created lock may be released. A crashed producer leaves evidence. */
function withBatchLock(file, callback) {
const lock = `${file}.lock`;
try {
writePrivateFile(LOG_PATH, line, { append: true });
fs.mkdirSync(lock, { mode: 0o700 });
} catch {
/* tmp not writable, or a file we do not own: fine */
return undefined;
}
try {
writePrivateFile(pending.path, line, { append: true });
const text = readPrivateFile(pending.path);
return text.split("\n").length - 1;
return callback();
} finally {
try {
fs.rmdirSync(lock);
} catch {
/* Leave a lock we cannot release; never force another writer's state. */
}
}
}

function rootsAreClean(roots) {
try {
return Boolean(roots?.length) && roots.every((root) => !sessionIsProtected(root));
} catch {
return 0;
return false;
}
}

/** The diagnostic TSV stays readable; only the separate queue carries control. */
function logDecision(pending, { decision, tool, tokensSaved, reason, passReason, path, startLine, endLine }) {
if (!LOG_ON || automaticSessionIsProtected()) return 0;
const roots = sessionProtectionContext()?.roots;
const line = formatShuntLine({ decision, tool, tokensSaved, reason, passReason, path, startLine, endLine });
const row = formatShuntBatchLine(line, roots);
if (!row || !rootsAreClean(roots)) return 0;
try {
if (automaticSessionIsProtected()) return 0;
writePrivateFile(LOG_PATH, line, { append: true });
} catch {
/* tmp not writable, or a file we do not own: fine */
}
return (
withBatchLock(pending.path, () => {
try {
// Do not append over damaged or unattributed evidence.
if (fs.existsSync(pending.path) && !parseShuntBatch(readPrivateFile(pending.path))) return 0;
if (automaticSessionIsProtected()) return 0;
writePrivateFile(pending.path, row, { append: true });
return parseShuntBatch(readPrivateFile(pending.path))?.lines || 0;
} catch {
return 0;
}
}) || 0
);
}

/** The batch files of this reporting scope that this user owns: this
Expand All @@ -224,7 +259,7 @@ function scopeBatches(pending) {
return [];
}
return names
.filter((n) => n.startsWith(prefix) && n.endsWith(".log"))
.filter((n) => n.startsWith(prefix) && n.endsWith(".log.control"))
.map((n) => path.join(dir, n))
.filter((file) => {
try {
Expand All @@ -236,46 +271,67 @@ function scopeBatches(pending) {
});
}

/** Claim one batch by renaming it to a name of this process, read it with the
* private-file checks, and remove it: of two hooks flushing at once only one
* gets each batch. "" when another hook claimed it first, or it is not ours. */
/** Locking serializes appends and rename, so a claimed file has no producer writer. */
function claimBatch(file) {
const claimed = tmpStatePath("shunt-claim", `${file}:${process.pid}:${crypto.randomBytes(8).toString("hex")}`, {
ext: ".log",
return withBatchLock(file, () => {
let claimed;
try {
const before = parseShuntBatch(readPrivateFile(file));
if (!before || !rootsAreClean(before.roots)) return null;
claimed = tmpStatePath(
"shunt-protected-claim",
`${file}:${process.pid}:${crypto.randomBytes(8).toString("hex")}`,
{
ext: ".log.control",
},
);
fs.renameSync(file, claimed);
// Re-read after claim: a changed control record is never sent as the old one.
const batch = parseShuntBatch(readPrivateFile(claimed));
return { claimed, batch };
} catch {
return claimed ? { claimed, batch: null } : null;
}
});
}

/** Acknowledge only after every bounded post and the final producer-root check. */
async function flushPending(repo) {
if (!REPORT_ON || automaticSessionIsProtected()) return;
const claims = scopeBatches(repo.pending).map(claimBatch).filter(Boolean);
if (!claims.length) return;
const ready = claims.filter(({ batch }) => batch && rootsAreClean(batch.roots));
const roots = ready.flatMap(({ batch }) => batch.roots);
let acknowledged = false;
try {
fs.renameSync(file, claimed);
} catch {
return "";
}
let text = "";
try {
text = readPrivateFile(claimed);
await withCapturedSessionProtection(roots, async () => {
const agg = aggregateShuntLog(ready.map(({ batch }) => batch.text).join(""));
const bodies = [agg.hit, ...agg.passes].filter(Boolean);
if (!bodies.length) return;
const scope = { org: repo.org || "", namespace: repo.namespace || "", consumer: "claude-code-shunt" };
for (const body of bodies) {
if (automaticSessionIsProtected()) return;
const answer = await postBounded("code.outcome", { ...scope, ...body }, { timeoutMs: FLUSH_TIMEOUT_MS });
if (!answer || automaticSessionIsProtected()) return;
}
acknowledged = !automaticSessionIsProtected();
});
} catch {
/* replaced between the check and the rename: not ours to post */
// Observer or control failure withholds acknowledgment; claims retain their evidence.
} finally {
for (const claim of claims) {
if (acknowledged && ready.includes(claim) && rootsAreClean(roots)) removeFile(claim.claimed);
// Refusals and ambiguous outcomes stay outside the automatic queue.
// Keeping the claim avoids replaying an unchanged protected operation.
}
}
removeFile(claimed);
return text;
}

/** Ship the scope's pending batches as code.outcome rows. Fire-and-forget with
* a 300 ms ceiling; a lost batch costs a few counter ticks. Each batch is
* claimed before it is read, so it is posted at most once. */
function flushPending(repo) {
if (!REPORT_ON) return;
const text = scopeBatches(repo.pending).map(claimBatch).join("");
if (!text) return;
const agg = aggregateShuntLog(text);
const opts = { timeoutMs: FLUSH_TIMEOUT_MS };
const scope = { org: repo.org || "", namespace: repo.namespace || "", consumer: "claude-code-shunt" };
if (agg.hit) postFireAndForget("code.outcome", { ...scope, ...agg.hit }, opts);
for (const body of agg.passes) postFireAndForget("code.outcome", { ...scope, ...body }, opts);
}

/** Every decision funnels through here: deny + log + maybe flush.
* `verdict` is classifyRead/classifyGrep's {deny, reason}; `tokens` is the
* estimate kept out (hit) or let in (pass); `span` the lines covered. */
function settle(repo, { tool, verdict, tokens, path = "", span = { start: 0, end: 0 } }) {
if (automaticSessionIsProtected()) return;
const denied = Boolean(verdict.deny);
if (denied) deny(verdict.deny);
const unflushed = logDecision(repo.pending, {
Expand All @@ -288,7 +344,7 @@ function settle(repo, { tool, verdict, tokens, path = "", span = { start: 0, end
startLine: span.start,
endLine: span.end,
});
if (shouldFlushShunt({ denied, pending: unflushed })) flushPending(repo);
if (shouldFlushShunt({ denied, pending: unflushed })) void flushPending(repo);
return denied;
}

Expand Down Expand Up @@ -575,6 +631,4 @@ async function settleBashBulk(repo, { bulk, cwd, sessionId, ctxBase }) {
return settle(repo, { tool: "Bash:grep", verdict, tokens: 0, path: rel || "" });
}

main()
.catch(() => {})
.finally(() => scheduleExit(0));
runHookMain(main).finally(() => scheduleExit(0));
8 changes: 7 additions & 1 deletion integrations/claude-code-plugin/hooks/loom-conversation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "../lib/loom-client.mjs";
import { dispatchFlush } from "../lib/flush-job.mjs";
import { readRecording } from "../lib/recording.mjs";
import { automaticSessionIsProtected } from "../lib/session-response.mjs";
import { readCursor, writeCursor } from "../lib/tmp-state.mjs";
import { fileSize, readLinesFrom } from "../lib/transcript.mjs";
import { appendTurn, journalCursorPath, readJournal, readJournalCursor, rowsSince } from "../lib/turn-journal.mjs";
Expand Down Expand Up @@ -82,6 +83,7 @@ function turnFrom(obj) {
* only when all land. Falls back to inline fire-and-forget without
* advancing the cursor, so the next Stop retries. */
function dispatch(appends, cursorFile, advanceTo) {
if (automaticSessionIsProtected()) return;
// The owner switched recording off for this namespace (the
// server said so on a recent append): nothing would be kept, so send
// nothing and move the cursor past these turns. Re-asked after the cache's
Expand All @@ -91,7 +93,7 @@ function dispatch(appends, cursorFile, advanceTo) {
writeCursor(cursorFile, advanceTo);
return;
}
if (!dispatchFlush({ appends, cursorPath: cursorFile, advanceTo })) {
if (!dispatchFlush({ appends, cursorPath: cursorFile, advanceTo }) && !automaticSessionIsProtected()) {
for (const a of appends) postFireAndForget("conversation.append", a);
}
}
Expand All @@ -103,6 +105,7 @@ function dispatch(appends, cursorFile, advanceTo) {
* on, so a Stop carries the prompt(s) since the last Stop plus the reply.
* Returns true when it handled the event. */
function fromEvents(payload, sessionId, scope) {
if (automaticSessionIsProtected()) return true;
const reply = typeof payload.last_assistant_message === "string" ? payload.last_assistant_message.trim() : "";
if (!reply) return false;
appendTurn(sessionId, "assistant", reply);
Expand Down Expand Up @@ -130,6 +133,7 @@ async function main() {
return scheduleExit(0);
}
const payload = await readStdinJson();
if (automaticSessionIsProtected()) return scheduleExit(0);
const sessionId = String(payload.session_id || "");
const transcript = String(payload.transcript_path || "");
if (!sessionId) return scheduleExit(0);
Expand All @@ -141,6 +145,7 @@ async function main() {

// Let a just-finished assistant message flush before we read (see SETTLE_MS).
if (SETTLE_MS > 0) await new Promise((r) => setTimeout(r, SETTLE_MS));
if (automaticSessionIsProtected()) return scheduleExit(0);

if (!fileSize(transcript)) {
fromEvents(payload, sessionId, scope); // transcript named but unreadable
Expand Down Expand Up @@ -179,6 +184,7 @@ async function main() {
});
}

if (automaticSessionIsProtected()) return scheduleExit(0);
if (appends.length === 0) {
// Nothing new — advance past scanned lines and exit. A transcript in a
// shape this script does not parse yields nothing every time; the
Expand Down
Loading
Loading