diff --git a/integrations/claude-code-plugin/.claude-plugin/plugin.json b/integrations/claude-code-plugin/.claude-plugin/plugin.json index 5e2cf2fb0e..e40cc20189 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.162", + "version": "1.2.168", "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 94019a6229..6484d774bc 100644 --- a/integrations/claude-code-plugin/lib/working-memory.mjs +++ b/integrations/claude-code-plugin/lib/working-memory.mjs @@ -36,14 +36,28 @@ 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; + // 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(); +} + +/** 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 e147d0f029..d48181a2d6 100644 --- a/integrations/claude-code-plugin/tests/working-memory.test.mjs +++ b/integrations/claude-code-plugin/tests/working-memory.test.mjs @@ -57,6 +57,43 @@ 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"); + 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]), ""); +}); + +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 fe5001afb0..31069a9865 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.162", + "version": "1.2.168", "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 94019a6229..6484d774bc 100644 --- a/integrations/codex-plugin/lib/working-memory.mjs +++ b/integrations/codex-plugin/lib/working-memory.mjs @@ -36,14 +36,28 @@ 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; + // 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(); +} + +/** 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 "";