Skip to content
Merged
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
5 changes: 4 additions & 1 deletion docs/features/integrations/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ chosen so, when it is a range of more than 200 lines, gives way to the first-ran
definition the answer holds inside it, which is the part of it the search matched, so a
long class the prompt names is sent as that method; with none inside it, it is sent as
its first line, the definition's signature, with its length
(`path:643 Permutation (372 lines)`). The low-risk label says the index holds code about
(`path:643 Permutation (372 lines)`). The highest-ranked place in the file of the answer's
first result is listed first, also when that result is no place itself or is sent as a
definition ranked below another file's; the other places keep the index's order, as all
do when that file has no place. The low-risk label says the index holds code about
the prompt, not that the pointers are where a fix is made, and no field of the answer
tells the two apart. The place test reads a unit's path and kind and does not tell them
apart either: an answer that holds only other places is sent.
Expand Down
5 changes: 4 additions & 1 deletion docs/guides/issue-code-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ lists the answer's places to edit:
class when the prompt names it, else the one the index ranked first. A range over 200
lines gives way to a definition the answer holds inside it, and is otherwise listed as
its first line and its length.
- Entries keep the index's order, and a span is listed once.
- The highest-ranked place in the file of the answer's first result is listed first,
also when that result is no place itself or is sent as a definition ranked below
another file's. The other entries keep the index's order, as all do when that file has
no place. A span is listed once.
- Paths are relative to the repository root, after the checkout prefix when one is
given, and the lines are those of the indexed commit.

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.162",
"version": "1.2.165",
"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
6 changes: 5 additions & 1 deletion integrations/claude-code-plugin/hooks/HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,11 @@ in.
part of it the search matched, so a long class the prompt names is sent as
that method; with none inside it, it is sent as its first line, the
definition's signature, with its length
(`path:643 Permutation (372 lines)`). For a
(`path:643 Permutation (372 lines)`).
**The first result's file leads.** The highest-ranked place in the file of
the answer's first result is listed first, also when that result is no place
itself or is sent as a definition ranked below another file's. The other
places keep the index's order, as all do when that file has no place. For a
picked answer (`LOOM_PROMPT_PACK_PICK`) the model's confidence is in its
first result, and the pick was measured on its first three: when the first is no place nothing is sent, and no result below the third is. The low-risk label
says the index holds code about the prompt, not that the pointers are where
Expand Down
19 changes: 13 additions & 6 deletions integrations/claude-code-plugin/lib/prompt-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,16 @@ export const LONG_RANGE_LINES = 200;

/**
* The pointers a search answer sends: the units that pass the place test
* (`isPlace`), in rank order, at most `cap`, and no range inside another. The
* model re-reads the pointers on every later request, so a unit that fails
* the test is not carried by one that passes. The test reads a unit's path
* and kind: it does not say the fix is made there, and no rule here drops an
* answer that holds only other places.
* (`isPlace`), at most `cap`, and no range inside another. The model re-reads
* the pointers on every later request, so a unit that fails the test is not
* carried by one that passes. The test reads a unit's path and kind: it does
* not say the fix is made there, and no rule here drops an answer that holds
* only other places.
*
* The first-ranked result's file leads: the highest-ranked of the pointers
* in that file is listed first, also when the unit sent for it ranks below
* another file's (a class sent as a method, a first result that is no place).
* The others keep rank order, as all do when that file has no pointer.
*
* A range and the ranges inside it (a class and its own methods) send one
* pointer, chosen in two steps:
Expand Down Expand Up @@ -623,7 +628,9 @@ export function places(res, { query, text = query, cap = 3, picked = false } = {
const sent = new Set(outermost.flatMap(byName).map(byLength));
// No range inside another: two ranges that overlap without one holding the other can each choose a unit inside both.
const apart = (unit) => ![...sent].some((other) => other !== unit && within(unit, other));
return ranked.filter((unit) => sent.has(unit) && apart(unit)).slice(0, cap);
const chosen = ranked.filter((unit) => sent.has(unit) && apart(unit));
const lead = chosen.find((unit) => unit.path === results[0].path);
return (lead ? [lead, ...chosen.filter((unit) => unit !== lead)] : chosen).slice(0, cap);
}

export function pointerOf(unit) {
Expand Down
198 changes: 198 additions & 0 deletions integrations/claude-code-plugin/tests/fixtures/pointer-block.json
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,204 @@
},
"block": "Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n- src/parser.c:10-60 parse_record\n- src/parser.c:40-90 parse_tail"
},
{
"name": "the first place is one of the first-ranked file, also when its class is sent as a method ranked below another file",
"prompt": "objects are written twice when memory runs low",
"query": "objects are written twice when memory runs low",
"reply": {
"abstain": false,
"retrieval_risk": "low",
"retrieval_confidence": 0.82,
"results": [
{
"path": "src/store.py",
"start_line": 10,
"end_line": 300,
"kind": "class_skeleton",
"symbol": "store::Store"
},
{
"path": "src/cache.py",
"start_line": 12,
"end_line": 20,
"kind": "function",
"symbol": "cache::Cache::evict"
},
{
"path": "src/store.py",
"start_line": 50,
"end_line": 90,
"kind": "function",
"symbol": "store::Store::put_object"
}
]
},
"block": "Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n- src/store.py:50-90 store::Store::put_object\n- src/cache.py:12-20 cache::Cache::evict"
},
{
"name": "a first-ranked unit that is no place gives the first slot to a place of its file",
"prompt": "the transfer is never tried again after the bucket answers slowly once",
"query": "the transfer is never tried again after the bucket answers slowly once",
"reply": {
"abstain": false,
"retrieval_risk": "low",
"retrieval_confidence": 0.82,
"results": [
{
"path": "src/uploads/retry.py",
"start_line": 1,
"end_line": 3,
"kind": "file_header",
"symbol": ""
},
{
"path": "src/uploads/client.py",
"start_line": 20,
"end_line": 23,
"kind": "function",
"symbol": "uploads.client::Client::put"
},
{
"path": "src/uploads/retry.py",
"start_line": 6,
"end_line": 15,
"kind": "function",
"symbol": "uploads.retry::retry_upload"
}
]
},
"block": "Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n- src/uploads/retry.py:6-15 uploads.retry::retry_upload\n- src/uploads/client.py:20-23 uploads.client::Client::put"
},
{
"name": "a first-ranked file with no place leaves the places in rank order",
"prompt": "objects are written twice when memory runs low",
"query": "objects are written twice when memory runs low",
"reply": {
"abstain": false,
"retrieval_risk": "low",
"retrieval_confidence": 0.82,
"results": [
{
"path": "src/uploads/settings.py",
"start_line": 1,
"end_line": 2,
"kind": "file_header",
"symbol": ""
},
{
"path": "src/store.py",
"start_line": 10,
"end_line": 300,
"kind": "class_skeleton",
"symbol": "store::Store"
},
{
"path": "src/cache.py",
"start_line": 12,
"end_line": 20,
"kind": "function",
"symbol": "cache::Cache::evict"
},
{
"path": "src/store.py",
"start_line": 50,
"end_line": 90,
"kind": "function",
"symbol": "store::Store::put_object"
}
]
},
"block": "Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n- src/cache.py:12-20 cache::Cache::evict\n- src/store.py:50-90 store::Store::put_object"
},
{
"name": "a place of the first-ranked file ranked below the count is listed first, and the last of the others is not listed",
"prompt": "objects are written twice when memory runs low",
"query": "objects are written twice when memory runs low",
"reply": {
"abstain": false,
"retrieval_risk": "low",
"retrieval_confidence": 0.82,
"results": [
{
"path": "src/store.py",
"start_line": 10,
"end_line": 300,
"kind": "class_skeleton",
"symbol": "store::Store"
},
{
"path": "src/cache.py",
"start_line": 12,
"end_line": 20,
"kind": "function",
"symbol": "cache::Cache::evict"
},
{
"path": "src/uploads/client.py",
"start_line": 20,
"end_line": 23,
"kind": "function",
"symbol": "uploads.client::Client::put"
},
{
"path": "src/uploads/retry.py",
"start_line": 6,
"end_line": 15,
"kind": "function",
"symbol": "uploads.retry::retry_upload"
},
{
"path": "src/store.py",
"start_line": 50,
"end_line": 90,
"kind": "function",
"symbol": "store::Store::put_object"
}
]
},
"block": "Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n- src/store.py:50-90 store::Store::put_object\n- src/cache.py:12-20 cache::Cache::evict\n- src/uploads/client.py:20-23 uploads.client::Client::put"
},
{
"name": "of two places in the first-ranked file the higher-ranked is listed first, not the one on the earlier line",
"prompt": "the transfer is never tried again after the bucket answers slowly once",
"query": "the transfer is never tried again after the bucket answers slowly once",
"reply": {
"abstain": false,
"retrieval_risk": "low",
"retrieval_confidence": 0.82,
"results": [
{
"path": "src/uploads/retry.py",
"start_line": 1,
"end_line": 3,
"kind": "file_header",
"symbol": ""
},
{
"path": "src/uploads/client.py",
"start_line": 20,
"end_line": 23,
"kind": "function",
"symbol": "uploads.client::Client::put"
},
{
"path": "src/uploads/retry.py",
"start_line": 40,
"end_line": 52,
"kind": "function",
"symbol": "uploads.retry::backoff_delay"
},
{
"path": "src/uploads/retry.py",
"start_line": 6,
"end_line": 15,
"kind": "function",
"symbol": "uploads.retry::retry_upload"
}
]
},
"block": "Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n- src/uploads/retry.py:40-52 uploads.retry::backoff_delay\n- src/uploads/client.py:20-23 uploads.client::Client::put\n- src/uploads/retry.py:6-15 uploads.retry::retry_upload"
},
{
"name": "a line carries the name and the signature cut at 80 characters; a span is listed once",
"prompt": "the handler ignores the strict flag for uploads",
Expand Down
30 changes: 26 additions & 4 deletions integrations/claude-code-plugin/tests/prompt-pack-hook.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,14 @@ const context = (result) => (result.out ? JSON.parse(result.out).hookSpecificOut
const POINTERS =
"Loom index pointers for this prompt, candidates: Read a line range to check one, search if none fits:\n" +
"- src/parser.py:10-14 Parser.parse_record — (value)";
/** The test line for the fixture's file, behind the interpreter `parserCheckout` left in `dir`. */
const testLine = (dir) =>
`Loom test for src/parser.py: ${path
/** The test line for `src/<stem>.py`, by default the fixture's file, behind the interpreter
* `parserCheckout` left in `dir`. */
const testLine = (dir, stem = "parser") =>
`Loom test for src/${stem}.py: ${path
.relative(dir, venvPython(path.join(dir, ".venv")))
.split(path.sep)
.join("/")} ` +
"-m pytest -q -rf tests/test_parser.py\n" +
`-m pytest -q -rf tests/test_${stem}.py\n` +
"It is the one test file named for that file. With -q -rf the last lines are one " +
"`FAILED <file>::<test>` line per failing test, then the totals.";
// The fixture's pointer is Parser.parse_record in src/parser.py: this prompt names it.
Expand Down Expand Up @@ -1061,6 +1062,27 @@ test("the test line runs pytest the way the checkout does: its options and its -
);
});

test("the test line is for the first listed pointer the prompt names: the first result's file", async (t) => {
const { ask, dir, replies } = await contractFixture(t, structuredClone(REPLIES));
parserCheckout(dir, {
tests: ["tests/test_parser.py", "tests/test_records.py"],
files: { "pytest.ini": "", "src/records.py": "def merge_prefixes(parts):\n return parts\n" },
});
const [parser] = replies["code.search"].results;
const header = { path: "src/parser.py", start_line: 1, end_line: 3, kind: "file_header", symbol: "" };
const records = { path: "src/records.py", start_line: 1, end_line: 2, kind: "function", symbol: "merge_prefixes" };
const recordsLine = "- src/records.py:1-2 merge_prefixes";
const [lead, parserLine] = POINTERS.split("\n");
// The prompt names a definition of each file, and each file has one test named after it.
const both = "Why does parse_record drop the prefix that merge_prefixes built?";
// The first result is no place: its file's function is listed first, and the line is for that file.
replies["code.search"].results = [header, records, parser];
assert.equal(context(await ask(both, "one")), `${POINTERS}\n${recordsLine}\n${testLine(dir)}`);
// The other file's function ranked first is listed first, and the line is for its file.
replies["code.search"].results = [records, parser];
assert.equal(context(await ask(both, "two")), `${lead}\n${recordsLine}\n${parserLine}\n${testLine(dir, "records")}`);
});

test("a prompt carries no test line where the checkout shows no single test or no pytest", async (t) => {
for (const [why, shape] of [
["no pytest configuration", { files: { "setup.cfg": "[flake8]\nexclude = build\n" } }],
Expand Down
9 changes: 9 additions & 0 deletions integrations/claude-code-plugin/tests/prompt-pack.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ test("a picked answer is sent only when its first result is a place", () => {
assert.deepEqual(places({ results: ranked }, { query, cap: 2 }), [second, third]);
});

test("a picked answer lists the first pick's file first", () => {
// A long first pick is sent as its method, ahead of another file's function ranked between them.
const long = { path: "pkg/store.py", start_line: 10, end_line: 300, symbol: "Store", kind: "class_skeleton" };
const other = { path: "pkg/solvers/other.py", start_line: 1, end_line: 9, symbol: "later", kind: "function" };
const method = { path: "pkg/store.py", start_line: 50, end_line: 90, symbol: "Store::put_object", kind: "function" };
const query = "objects are written twice when memory runs low";
assert.deepEqual(places({ results: [long, other, method] }, { query, picked: true }), [method, other]);
});

test("a range over the stated length is pointed at by its first line and its length", () => {
assert.equal(LONG_RANGE_LINES, 200);
const line = (unit) => renderPack({ results: [unit] }).text.split("\n")[1];
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.165",
"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
19 changes: 13 additions & 6 deletions integrations/codex-plugin/lib/prompt-pack.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,16 @@ export const LONG_RANGE_LINES = 200;

/**
* The pointers a search answer sends: the units that pass the place test
* (`isPlace`), in rank order, at most `cap`, and no range inside another. The
* model re-reads the pointers on every later request, so a unit that fails
* the test is not carried by one that passes. The test reads a unit's path
* and kind: it does not say the fix is made there, and no rule here drops an
* answer that holds only other places.
* (`isPlace`), at most `cap`, and no range inside another. The model re-reads
* the pointers on every later request, so a unit that fails the test is not
* carried by one that passes. The test reads a unit's path and kind: it does
* not say the fix is made there, and no rule here drops an answer that holds
* only other places.
*
* The first-ranked result's file leads: the highest-ranked of the pointers
* in that file is listed first, also when the unit sent for it ranks below
* another file's (a class sent as a method, a first result that is no place).
* The others keep rank order, as all do when that file has no pointer.
*
* A range and the ranges inside it (a class and its own methods) send one
* pointer, chosen in two steps:
Expand Down Expand Up @@ -623,7 +628,9 @@ export function places(res, { query, text = query, cap = 3, picked = false } = {
const sent = new Set(outermost.flatMap(byName).map(byLength));
// No range inside another: two ranges that overlap without one holding the other can each choose a unit inside both.
const apart = (unit) => ![...sent].some((other) => other !== unit && within(unit, other));
return ranked.filter((unit) => sent.has(unit) && apart(unit)).slice(0, cap);
const chosen = ranked.filter((unit) => sent.has(unit) && apart(unit));
const lead = chosen.find((unit) => unit.path === results[0].path);
return (lead ? [lead, ...chosen.filter((unit) => unit !== lead)] : chosen).slice(0, cap);
}

export function pointerOf(unit) {
Expand Down
Loading
Loading