From 9401e5070e7f114aa1bfc5f4a0b2b9537c678724 Mon Sep 17 00:00:00 2001 From: akx-vishnu Date: Thu, 3 Dec 2026 20:31:54 +0530 Subject: [PATCH 1/3] fix(plugins): skip the slash-command caveat and echoes when picking the session goal The working-memory bookmark took the first user row of the transcript as the session's goal. A session that starts with a local slash command such as /clear begins with the client's isMeta caveat row and the command's echo, so the bookmark recorded the caveat as the goal and the next session's primer showed it. firstUserPrompt now skips isMeta rows, the echo of a command run with no arguments, and local-command output. A command with arguments is a request and still stands as the goal. Both plugins move to 1.2.163. Closes #2075 Signed-off-by: akx-vishnu --- .../.claude-plugin/plugin.json | 2 +- .../claude-code-plugin/lib/working-memory.mjs | 17 +++++++++-- .../tests/working-memory.test.mjs | 28 +++++++++++++++++++ .../codex-plugin/.codex-plugin/plugin.json | 2 +- .../codex-plugin/lib/working-memory.mjs | 17 +++++++++-- 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/integrations/claude-code-plugin/.claude-plugin/plugin.json b/integrations/claude-code-plugin/.claude-plugin/plugin.json index f882a34cba1..7ea2779de99 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.158", + "version": "1.2.163", "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/lib/working-memory.mjs b/integrations/claude-code-plugin/lib/working-memory.mjs index 94019a6229f..59a0a86752e 100644 --- a/integrations/claude-code-plugin/lib/working-memory.mjs +++ b/integrations/claude-code-plugin/lib/working-memory.mjs @@ -36,14 +36,27 @@ export function blockKeyFor(project) { return `session:${p || "project"}`; } -/** First user prompt in transcript JSONL objects (sidechains skipped); "". */ +/** A row the client wrote for a local slash command, not a request: the + * command's echo when it ran with no arguments (`/clear`, `/model`) and its + * output. A command with arguments (`/ `) is a request. */ +function isLocalCommandEcho(text) { + if (/^/.test(text)) return true; + if (!text.startsWith("")) return false; + const args = /([\s\S]*?)<\/command-args>/.exec(text); + return !args || !args[1].trim(); +} + +/** First user prompt in transcript JSONL objects (sidechains, rows the client + * injected and local-command echoes skipped); "". */ export function firstUserPrompt(objs) { for (const o of objs || []) { - if (!o || o.type !== "user" || o.isSidechain) continue; + // isMeta rows are text the client injected (the local-command caveat). + if (!o || o.type !== "user" || o.isSidechain || o.isMeta) continue; const content = o.message && o.message.content; const text = contentText(content).trim(); // Tool results also arrive as `user` rows; skip those and empty rows. if (!text || (Array.isArray(content) && content.some((b) => b && b.type === "tool_result"))) continue; + if (isLocalCommandEcho(text)) continue; return text; } return ""; diff --git a/integrations/claude-code-plugin/tests/working-memory.test.mjs b/integrations/claude-code-plugin/tests/working-memory.test.mjs index e147d0f0296..fd8e599dcfb 100644 --- a/integrations/claude-code-plugin/tests/working-memory.test.mjs +++ b/integrations/claude-code-plugin/tests/working-memory.test.mjs @@ -57,6 +57,34 @@ test("firstUserPrompt skips tool_result rows and sidechains", () => { assert.equal(firstUserPrompt([]), ""); }); +test("firstUserPrompt skips the local-command caveat and the echo of a command run with no arguments", () => { + const caveat = { + type: "user", + isMeta: true, + message: { role: "user", content: "Caveat: ..." }, + }; + const echo = { + type: "user", + message: { + role: "user", + content: "/clear\nclear\n", + }, + }; + const stdout = { type: "user", message: { role: "user", content: "Set model to opus" } }; + const request = { type: "user", message: { role: "user", content: "fix the failing search test" } }; + assert.equal(firstUserPrompt([caveat, echo, request]), "fix the failing search test"); + assert.equal(firstUserPrompt([echo, request]), "fix the failing search test"); + assert.equal(firstUserPrompt([caveat, echo, stdout, request]), "fix the failing search test"); + // Only client rows: no typed request, so no goal (the caller falls back to the journal). + assert.equal(firstUserPrompt([caveat, echo, stdout]), ""); +}); + +test("firstUserPrompt keeps a slash command run with arguments as the goal", () => { + const skill = + "/review\nreview\nthe search PR"; + assert.equal(firstUserPrompt([{ type: "user", message: { role: "user", content: skill } }]), skill); +}); + test("editedFiles lists edit tools only, first-touch order, deduped, sidechains skipped", () => { assert.deepEqual(editedFiles(transcript), [ "/repo/server/workers/usage_fold.py", diff --git a/integrations/codex-plugin/.codex-plugin/plugin.json b/integrations/codex-plugin/.codex-plugin/plugin.json index 33322e89d60..eb4f3d0f24f 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.158", + "version": "1.2.163", "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/lib/working-memory.mjs b/integrations/codex-plugin/lib/working-memory.mjs index 94019a6229f..59a0a86752e 100644 --- a/integrations/codex-plugin/lib/working-memory.mjs +++ b/integrations/codex-plugin/lib/working-memory.mjs @@ -36,14 +36,27 @@ export function blockKeyFor(project) { return `session:${p || "project"}`; } -/** First user prompt in transcript JSONL objects (sidechains skipped); "". */ +/** A row the client wrote for a local slash command, not a request: the + * command's echo when it ran with no arguments (`/clear`, `/model`) and its + * output. A command with arguments (`/ `) is a request. */ +function isLocalCommandEcho(text) { + if (/^/.test(text)) return true; + if (!text.startsWith("")) return false; + const args = /([\s\S]*?)<\/command-args>/.exec(text); + return !args || !args[1].trim(); +} + +/** First user prompt in transcript JSONL objects (sidechains, rows the client + * injected and local-command echoes skipped); "". */ export function firstUserPrompt(objs) { for (const o of objs || []) { - if (!o || o.type !== "user" || o.isSidechain) continue; + // isMeta rows are text the client injected (the local-command caveat). + if (!o || o.type !== "user" || o.isSidechain || o.isMeta) continue; const content = o.message && o.message.content; const text = contentText(content).trim(); // Tool results also arrive as `user` rows; skip those and empty rows. if (!text || (Array.isArray(content) && content.some((b) => b && b.type === "tool_result"))) continue; + if (isLocalCommandEcho(text)) continue; return text; } return ""; From 501a5b3a845bc0b1756fa192f0d9e2422695ae27 Mon Sep 17 00:00:00 2001 From: akx-vishnu Date: Thu, 3 Dec 2026 20:41:30 +0530 Subject: [PATCH 2/3] fix(plugins): also skip a command echo that starts with its message tag Claude Code writes a local command's echo with first in some versions, so those echoes still became the session goal. Signed-off-by: akx-vishnu --- integrations/claude-code-plugin/lib/working-memory.mjs | 3 ++- .../claude-code-plugin/tests/working-memory.test.mjs | 5 +++++ integrations/codex-plugin/lib/working-memory.mjs | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/integrations/claude-code-plugin/lib/working-memory.mjs b/integrations/claude-code-plugin/lib/working-memory.mjs index 59a0a86752e..6484d774bc9 100644 --- a/integrations/claude-code-plugin/lib/working-memory.mjs +++ b/integrations/claude-code-plugin/lib/working-memory.mjs @@ -41,7 +41,8 @@ export function blockKeyFor(project) { * output. A command with arguments (`/ `) is a request. */ function isLocalCommandEcho(text) { if (/^/.test(text)) return true; - if (!text.startsWith("")) return false; + // The echo starts with either tag, depending on the client version. + if (!/^/.test(text)) return false; const args = /([\s\S]*?)<\/command-args>/.exec(text); return !args || !args[1].trim(); } diff --git a/integrations/claude-code-plugin/tests/working-memory.test.mjs b/integrations/claude-code-plugin/tests/working-memory.test.mjs index fd8e599dcfb..e2e81e7c876 100644 --- a/integrations/claude-code-plugin/tests/working-memory.test.mjs +++ b/integrations/claude-code-plugin/tests/working-memory.test.mjs @@ -75,6 +75,11 @@ test("firstUserPrompt skips the local-command caveat and the echo of a command r assert.equal(firstUserPrompt([caveat, echo, request]), "fix the failing search test"); assert.equal(firstUserPrompt([echo, request]), "fix the failing search test"); assert.equal(firstUserPrompt([caveat, echo, stdout, request]), "fix the failing search test"); + const messageFirst = { + type: "user", + message: { role: "user", content: "model\n/model" }, + }; + assert.equal(firstUserPrompt([messageFirst, request]), "fix the failing search test"); // Only client rows: no typed request, so no goal (the caller falls back to the journal). assert.equal(firstUserPrompt([caveat, echo, stdout]), ""); }); diff --git a/integrations/codex-plugin/lib/working-memory.mjs b/integrations/codex-plugin/lib/working-memory.mjs index 59a0a86752e..6484d774bc9 100644 --- a/integrations/codex-plugin/lib/working-memory.mjs +++ b/integrations/codex-plugin/lib/working-memory.mjs @@ -41,7 +41,8 @@ export function blockKeyFor(project) { * output. A command with arguments (`/ `) is a request. */ function isLocalCommandEcho(text) { if (/^/.test(text)) return true; - if (!text.startsWith("")) return false; + // The echo starts with either tag, depending on the client version. + if (!/^/.test(text)) return false; const args = /([\s\S]*?)<\/command-args>/.exec(text); return !args || !args[1].trim(); } From 138b99fa022301715bf7a1af50620a27b48a6692 Mon Sep 17 00:00:00 2001 From: akx-vishnu Date: Thu, 3 Dec 2026 22:50:33 +0530 Subject: [PATCH 3/3] style(plugins): apply Biome formatting to the working-memory test fixtures Signed-off-by: akx-vishnu --- .../claude-code-plugin/tests/working-memory.test.mjs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/integrations/claude-code-plugin/tests/working-memory.test.mjs b/integrations/claude-code-plugin/tests/working-memory.test.mjs index e2e81e7c876..d48181a2d6b 100644 --- a/integrations/claude-code-plugin/tests/working-memory.test.mjs +++ b/integrations/claude-code-plugin/tests/working-memory.test.mjs @@ -67,10 +67,14 @@ test("firstUserPrompt skips the local-command caveat and the echo of a command r type: "user", message: { role: "user", - content: "/clear\nclear\n", + content: + "/clear\nclear\n", }, }; - const stdout = { type: "user", message: { role: "user", content: "Set model to opus" } }; + const stdout = { + type: "user", + message: { role: "user", content: "Set model to opus" }, + }; const request = { type: "user", message: { role: "user", content: "fix the failing search test" } }; assert.equal(firstUserPrompt([caveat, echo, request]), "fix the failing search test"); assert.equal(firstUserPrompt([echo, request]), "fix the failing search test");