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 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.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"
Expand Down
18 changes: 16 additions & 2 deletions integrations/claude-code-plugin/lib/working-memory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`/<skill> <args>`) is a request. */
function isLocalCommandEcho(text) {
if (/^<local-command-(?:stdout|stderr|caveat)>/.test(text)) return true;
// The echo starts with either tag, depending on the client version.
if (!/^<command-(?:name|message)>/.test(text)) return false;
const args = /<command-args>([\s\S]*?)<\/command-args>/.exec(text);
return !args || !args[1].trim();
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

/** 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 "";
Expand Down
37 changes: 37 additions & 0 deletions integrations/claude-code-plugin/tests/working-memory.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<local-command-caveat>Caveat: ...</local-command-caveat>" },
};
const echo = {
type: "user",
message: {
role: "user",
content:
"<command-name>/clear</command-name>\n<command-message>clear</command-message>\n<command-args></command-args>",
},
};
const stdout = {
type: "user",
message: { role: "user", content: "<local-command-stdout>Set model to opus</local-command-stdout>" },
};
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: "<command-message>model</command-message>\n<command-name>/model</command-name>" },
};
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 =
"<command-name>/review</command-name>\n<command-message>review</command-message>\n<command-args>the search PR</command-args>";
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",
Expand Down
2 changes: 1 addition & 1 deletion integrations/codex-plugin/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
18 changes: 16 additions & 2 deletions integrations/codex-plugin/lib/working-memory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`/<skill> <args>`) is a request. */
function isLocalCommandEcho(text) {
if (/^<local-command-(?:stdout|stderr|caveat)>/.test(text)) return true;
// The echo starts with either tag, depending on the client version.
if (!/^<command-(?:name|message)>/.test(text)) return false;
const args = /<command-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 "";
Expand Down
Loading