Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(search): push --path down to the backend as a candidate scope (#673)

Ian Hock61b3b6f7d197
diff --git a/ix-cli/src/cli/__tests__/search-path-window.test.ts b/ix-cli/src/cli/__tests__/search-path-window.test.ts
index 28ec48d7..de1866e7 100644
--- a/ix-cli/src/cli/__tests__/search-path-window.test.ts
+++ b/ix-cli/src/cli/__tests__/search-path-window.test.ts
@@ -66,6 +66,25 @@ describe("keyword search path candidate window", () => {
expect(search).toHaveBeenCalledTimes(1);
});
+ it("pushes --path down to the backend as a separator-normalized scope", async () => {
+ // Ix#647: the released /v1/search had no path filter, so a match past the
+ // candidate window was unreachable at any --limit. The backend gained a
+ // `scope` field; the CLI must send it on EVERY widening round, with
+ // Windows separators normalized (the stored side is POSIX) and the case
+ // left alone (the backend lowercases both sides itself).
+ dataset([...Array.from({ length: 70 }, (_, i) => node(i)), node(70, "src/target.ts")]);
+ await run(["--path", "SRC\\Target.ts"]);
+ expect(search.mock.calls.length).toBeGreaterThan(1);
+ expect(search.mock.calls.every(([, opts]) => opts.scope === "SRC/Target.ts")).toBe(true);
+ });
+
+ it("sends no scope when --path is not given", async () => {
+ dataset([node(0)]);
+ await run([]);
+ expect(search).toHaveBeenCalledTimes(1);
+ expect(search.mock.calls[0][1].scope).toBeUndefined();
+ });
+
it("does not widen an unscoped search", async () => {
dataset(Array.from({ length: 100 }, (_, i) => node(i)));
await run([]);
diff --git a/ix-cli/src/cli/commands/search.ts b/ix-cli/src/cli/commands/search.ts
index 335e619d..9003def4 100644
--- a/ix-cli/src/cli/commands/search.ts
+++ b/ix-cli/src/cli/commands/search.ts
@@ -8,6 +8,7 @@ import { scoreCandidate, resolveReadSystemId } from "../resolve.js";
import { applyRoleFilter, roleHint } from "../role-filter.js";
import { stderr } from "../stderr.js";
import { llmLine } from "../llm.js";
+import { normalizePathSeparators } from "../path-match.js";
/** Render `ix search` as llm records: a header line then one `node` row per hit (rank = order). */
export function renderSearchLlm(
@@ -126,7 +127,8 @@ export function registerSearchCommand(program: Command): void {
6. Fuzzy/incidental match
Use --path to filter results from specific directories.
-Keyword searches with --path widen the candidate window up to 2000 nodes.
+Keyword searches send --path to the backend as a candidate filter (backend 1.0.31+)
+and widen the candidate window up to 2000 nodes on older backends.
If that bound is reached, a diagnostic warns that matches may be missing.
Examples:
@@ -168,6 +170,15 @@ Examples:
asOfRev: opts.asOf ? parseInt(opts.asOf, 10) : undefined,
workspaceId,
systemId,
+ // Push --path down as `scope` so a backend that knows the field
+ // (Ix-memory ≥ 1.0.31) filters candidates BEFORE its limit and the
+ // window below holds only matching paths (Ix#647: the target sat
+ // at candidate 71 and 386 and no --limit could reach it). An older
+ // backend ignores the unknown field, and the client-side filter
+ // and widening loop below still apply either way. Separators only:
+ // the backend lowercases both sides itself, and the stored side is
+ // POSIX by construction (see path-match.ts).
+ scope: effectivePathFilter ? normalizePathSeparators(effectivePathFilter) : undefined,
});
let rawNodes = await fetchCandidates(fetchLimit);
const filterPath = (candidates: typeof rawNodes) => effectivePathFilter
diff --git a/ix-cli/src/client/api.ts b/ix-cli/src/client/api.ts
index 3a0b7742..029d8954 100644
--- a/ix-cli/src/client/api.ts
+++ b/ix-cli/src/client/api.ts
@@ -97,7 +97,7 @@ export class IxClient {
async search(
term: string,
- opts?: { limit?: number; kind?: string; language?: string; asOfRev?: number; nameOnly?: boolean; workspaceId?: string; systemId?: string }
+ opts?: { limit?: number; kind?: string; language?: string; asOfRev?: number; nameOnly?: boolean; workspaceId?: string; systemId?: string; scope?: string }
): Promise<GraphNode[]> {
return this.post("/v1/search", {
term,
@@ -108,6 +108,11 @@ export class IxClient {
nameOnly: opts?.nameOnly,
workspaceId: opts?.workspaceId,
systemId: opts?.systemId,
+ // A source_uri substring the backend applies BEFORE its limit
+ // (Ix-memory ≥ 1.0.31, case-insensitive). Older backends decode the
+ // request with a derived circe decoder and drop the unknown field, so
+ // sending it is always safe; callers keep their own filter as well.
+ scope: opts?.scope,
});
}