Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(diff): `ix diff` passes the workspace, and `--full` asks for a real limit
KageBinary9649593c197e
diff --git a/ix-cli/src/cli/__tests__/diff-scope.test.ts b/ix-cli/src/cli/__tests__/diff-scope.test.tsnew file mode 100644index 00000000..7a846f5f--- /dev/null+++ b/ix-cli/src/cli/__tests__/diff-scope.test.ts@@ -0,0 +1,159 @@+// Copyright 2026 Ix Infrastructure Inc.++import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";+import * as fs from "node:fs";+import * as os from "node:os";+import * as path from "node:path";+import { createServer, type Server } from "node:http";+import { Command } from "commander";++import { saveConfig } from "../config.js";+import { resetReadScope } from "../resolve.js";+import {+ DIFF_MAX_LIMIT,+ diffRequestLimit,+ diffTruncationNote,+ diffWorkspaceScope,+ registerDiffCommand,+} from "../commands/diff.js";++/**+ * `/v1/diff` scopes by `workspace_id` like the backend's other reads+ * (Ix-memory#277, WorkspaceScope), and clamps `limit` to 5000 with a default+ * of 100. `ix diff` sent neither, so every diff was global, and `--full` (no+ * limit) still got 100 changes under "Use --full to see all".+ */++let server: Server;+let endpoint: string;+let bodies: Array<Record<string, unknown>> = [];+let answer: Record<string, unknown> = {};++beforeAll(async () => {+ server = createServer((req, res) => {+ let raw = "";+ req.on("data", (c) => { raw += c; });+ req.on("end", () => {+ if (req.url === "/v1/diff") bodies.push(JSON.parse(raw));+ res.writeHead(200, { "content-type": "application/json" });+ res.end(JSON.stringify(answer));+ });+ });+ await new Promise<void>((r) => server.listen(0, "127.0.0.1", r));+ const addr = server.address();+ endpoint = `http://127.0.0.1:${typeof addr === "object" && addr ? addr.port : 0}`;+});++afterAll(async () => {+ await new Promise<void>((r) => server.close(() => r()));+});++let home: string;+let repo: string;+let elsewhere: string;+let savedCwd: string;+let out: string[];++beforeEach(() => {+ home = fs.realpathSync.native(fs.mkdtempSync(path.join(os.tmpdir(), "ix-diff-scope-")));+ process.env.IX_HOME = path.join(home, ".ix");+ process.env.IX_ENDPOINT = endpoint;+ repo = path.join(home, "repo");+ elsewhere = path.join(home, "elsewhere");+ fs.mkdirSync(repo, { recursive: true });+ fs.mkdirSync(elsewhere, { recursive: true });+ saveConfig({+ endpoint,+ format: "text",+ workspaces: [{ workspace_id: "ws000001", workspace_name: "repo", root_path: repo, default: true }],+ });+ savedCwd = process.cwd();+ resetReadScope();+ bodies = [];+ answer = { fromRev: 3, toRev: 5, changes: [], truncated: false, totalChanges: 0 };+ out = [];+ vi.spyOn(console, "log").mockImplementation((...a: unknown[]) => { out.push(a.join(" ")); });+});++afterEach(() => {+ process.chdir(savedCwd);+ delete process.env.IX_HOME;+ delete process.env.IX_ENDPOINT;+ resetReadScope();+ vi.restoreAllMocks();+ fs.rmSync(home, { recursive: true, force: true });+});++async function diff(...args: string[]): Promise<void> {+ const program = new Command().exitOverride();+ registerDiffCommand(program);+ await program.parseAsync(["diff", ...args], { from: "user" });+}++describe("ix diff: workspace scope", () => {+ it("sends the workspace the directory belongs to", async () => {+ process.chdir(repo);+ await diff("3", "5");+ expect(bodies).toHaveLength(1);+ expect(bodies[0]).toMatchObject({ fromRev: 3, toRev: 5, workspace_id: "ws000001" });+ });++ it("scopes --summary the same way", async () => {+ process.chdir(repo);+ answer = { fromRev: 3, toRev: 5, summary: { added: 1 }, total: 1 };+ await diff("3", "5", "--summary");+ expect(bodies[0]).toMatchObject({ summary: true, workspace_id: "ws000001" });+ });++ it("--all asks for every workspace", async () => {+ process.chdir(repo);+ await diff("3", "5", "--all");+ expect(bodies[0].workspace_id).toBe("*");+ });++ it("outside any mapped workspace it stays global, as before, rather than failing", async () => {+ process.chdir(elsewhere);+ await diff("3", "5");+ expect(bodies).toHaveLength(1);+ expect(bodies[0].workspace_id).toBeUndefined();+ expect(process.exitCode ?? 0).toBe(0);+ });++ it("diffWorkspaceScope", () => {+ expect(diffWorkspaceScope(true, elsewhere)).toBe("*");+ expect(diffWorkspaceScope(false, repo)).toBe("ws000001");+ expect(diffWorkspaceScope(undefined, elsewhere)).toBeUndefined();+ });+});++describe("ix diff --full", () => {+ it("asks for the backend's maximum instead of sending no limit", async () => {+ process.chdir(repo);+ await diff("3", "5", "--full");+ expect(bodies[0].limit).toBe(DIFF_MAX_LIMIT);+ expect(DIFF_MAX_LIMIT).toBe(5000);+ });++ it("leaves --limit and the default as they were", () => {+ expect(diffRequestLimit({ limit: "20" })).toBe(20);+ expect(diffRequestLimit({})).toBeUndefined();+ expect(diffRequestLimit({ full: true })).toBe(5000);+ });++ it("does not tell a --full run to use --full", async () => {+ process.chdir(repo);+ answer = {+ fromRev: 3, toRev: 5, truncated: true, totalChanges: 6000,+ changes: [{ entityId: "e1", changeType: "added", atToRev: { name: "f", kind: "function" } }],+ };+ await diff("3", "5", "--full");+ const text = out.join("\n");+ expect(text).toContain("at most 5000");+ expect(text).not.toContain("Use --full");+ });++ it("the truncation note", () => {+ expect(diffTruncationNote(100, 250, false)).toBe("Showing 100 of 250 changes. Use --full to see up to 5000.");+ expect(diffTruncationNote(5000, 6000, true)).toMatch(/^Showing 5000 of 6000 changes: the backend returns at most 5000\./);+ });+});diff --git a/ix-cli/src/cli/commands/diff.ts b/ix-cli/src/cli/commands/diff.tsindex 40ce8def..614c3dcb 100644--- a/ix-cli/src/cli/commands/diff.ts+++ b/ix-cli/src/cli/commands/diff.ts@@ -16,6 +16,41 @@ import { formatDiff, relativePath, printJson } from "../format.js";import { llmLine } from "../llm.js";import { reportFailure } from "../ui.js";import { parsePickOption } from "../options.js";+import { resolveWorkspaceId } from "../bootstrap.js";++/**+ * The most changes the backend returns in one diff (`/v1/diff` clamps `limit`+ * to 5000; it does not page). `--full` asks for this many, since sending no+ * limit got the server's default of 100.+ */+export const DIFF_MAX_LIMIT = 5000;++/**+ * The `workspace_id` to send with a diff: `*` (every workspace) for `--all`,+ * else the workspace this directory belongs to, as the other graph reads use.+ * Outside any mapped workspace it is undefined, which the backend reads as+ * every workspace -- what `ix diff` always did, so no run that worked before+ * now fails.+ */+export function diffWorkspaceScope(all: boolean | undefined, cwd = process.cwd()): string | undefined {+ if (all) return "*";+ return resolveWorkspaceId(cwd);+}++/** The `limit` to send: the backend's maximum for `--full`, else `--limit` or the server default. */+export function diffRequestLimit(opts: { full?: boolean; limit?: string }): number | undefined {+ if (opts.full) return DIFF_MAX_LIMIT;+ return opts.limit ? parseInt(opts.limit, 10) : undefined;+}++/** The text-mode line over a truncated diff. */+export function diffTruncationNote(shown: number, total: number, full: boolean | undefined): string {+ if (full) {+ return `Showing ${shown} of ${total} changes: the backend returns at most ${DIFF_MAX_LIMIT}. ` ++ "Narrow it with a target or a smaller revision range, or use --summary for counts.";+ }+ return `Showing ${shown} of ${total} changes. Use --full to see up to ${DIFF_MAX_LIMIT}.`;+}/*** Subset of `DiffOptions` consumed by `detectDiffModeConflict`. Kept as a@@ -477,7 +512,8 @@ export function registerDiffCommand(program: Command): void {.option("--summary", "Show compact summary only (server-side, fast)").option("--content", "Show detailed attribute changes for each entity").option("--limit <n>", "Max changes to return (default 100)")- .option("--full", "Return all changes (no limit)")+ .option("--full", `Return all changes (up to the backend's maximum, ${DIFF_MAX_LIMIT})`)+ .option("--all", "Diff every workspace on the backend, not just this one").option("--format <fmt>", "Output format (text|json|llm)", "text").option("--kind <kind>", "Filter target entity by kind").option("--path <path>", "Restrict to symbols from files matching this path substring")@@ -490,7 +526,7 @@ export function registerDiffCommand(program: Command): void {ix diff 3 5 --summary`).action(async (fromRev: string, toRev: string, target: string | undefined, opts: {entity?: string; summary?: boolean; content?: boolean; limit?: string; full?: boolean; format: string;- kind?: string; path?: string; pick?: number;+ kind?: string; path?: string; pick?: number; all?: boolean;}) => {const conflict = detectDiffModeConflict(opts);if (conflict) {@@ -498,6 +534,7 @@ export function registerDiffCommand(program: Command): void {return;}const client = createClient();+ const workspaceId = diffWorkspaceScope(opts.all);const from = parseInt(fromRev, 10);const to = parseInt(toRev, 10);@@ -517,7 +554,7 @@ export function registerDiffCommand(program: Command): void {}if (opts.summary) {- const result: any = await client.diff(from, to, { summary: true, entityId });+ const result: any = await client.diff(from, to, { summary: true, entityId, workspaceId });if (opts.format === "json") {printJson(compactDiffResult(result));@@ -536,8 +573,8 @@ export function registerDiffCommand(program: Command): void {return;}- const limit = opts.full ? undefined : (opts.limit ? parseInt(opts.limit, 10) : undefined);- const result: any = await client.diff(from, to, { entityId, limit });+ const limit = diffRequestLimit(opts);+ const result: any = await client.diff(from, to, { entityId, limit, workspaceId });const changes: any[] = result.changes ?? [];// ── Content mode: textual diff is primary ───────────────────────@@ -681,7 +718,7 @@ export function registerDiffCommand(program: Command): void {formatDiff(result, "llm");} else {if (result.truncated) {- console.log(chalk.yellow(`Showing ${result.changes.length} of ${result.totalChanges} changes. Use --full to see all.\n`));+ console.log(chalk.yellow(`${diffTruncationNote(result.changes.length, result.totalChanges, opts.full)}\n`));}formatDiff(result, "text");}diff --git a/ix-cli/src/client/api.ts b/ix-cli/src/client/api.tsindex 491ba17c..2fd8eaf3 100644--- a/ix-cli/src/client/api.ts+++ b/ix-cli/src/client/api.ts@@ -355,7 +355,7 @@ export class IxClient {async diff(fromRev: number,toRev: number,- opts?: { entityId?: string; summary?: boolean; limit?: number }+ opts?: { entityId?: string; summary?: boolean; limit?: number; workspaceId?: string }): Promise<unknown> {return this.post("/v1/diff", {fromRev,@@ -363,6 +363,9 @@ export class IxClient {entityId: opts?.entityId,summary: opts?.summary,limit: opts?.limit,+ // The backend reads `workspace_id` like its other reads: an id scopes+ // the diff to that workspace, `*` (or none) means every workspace.+ workspace_id: opts?.workspaceId,});}diff --git a/skills/ix/references/flags.md b/skills/ix/references/flags.mdindex 207e9db0..e2f27d31 100644--- a/skills/ix/references/flags.md+++ b/skills/ix/references/flags.md@@ -277,7 +277,7 @@ Show upstream dependents of the given entity (full tree by default).### `ix diff <fromRev> <toRev> [target]`-Show diff between two revisions, optionally scoped to a file or entity.+Show diff between two revisions, optionally scoped to a file or entity. The diff covers the workspace the current directory belongs to; `--all` covers every workspace on the backend (outside any mapped workspace it does anyway).| Flag | Value | Default | Effect ||---|---|---|---|@@ -285,7 +285,8 @@ Show diff between two revisions, optionally scoped to a file or entity.| `--summary` | — | off | Show compact summary only (server-side, fast) || `--content` | — | off | Show detailed attribute changes for each entity || `--limit` | `<n>` | — | Max changes to return (default 100) |-| `--full` | — | off | Return all changes (no limit) |+| `--full` | — | off | Return all changes (up to the backend's maximum, 5000) |+| `--all` | — | off | Diff every workspace on the backend, not just this one || `--format` | `text\|json\|llm` | `text` | Output format — see [output-formats.md](output-formats.md) || `--pretty` | — | off | Indent JSON output; the default only when stdout is a terminal || `--quiet` | — | off | Drop headers, section titles and advisory hints |