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(config): key per-root state by the canonical root; keep the error cause
KageBinary08bb080b9c33
diff --git a/ix-cli/src/cli/__tests__/root-key-canonical.test.ts b/ix-cli/src/cli/__tests__/root-key-canonical.test.tsnew file mode 100644index 00000000..20f4831f--- /dev/null+++ b/ix-cli/src/cli/__tests__/root-key-canonical.test.ts@@ -0,0 +1,45 @@+// Copyright 2026 Ix Infrastructure Inc.++import { afterEach, beforeEach, describe, expect, it } from "vitest";+import * as fs from "node:fs";+import * as os from "node:os";+import * as path from "node:path";++import { ingestMtimeCachePath, ingestRebuildPath, mapBaselinePath, mapResultCachePath } from "../config.js";++/**+ * `ix ingest <path>` canonicalises its root, so it writes its baseline under+ * the real path's key. A caller that spelled the same root another way -- a+ * symlink here; macOS's /tmp or a Windows 8.3 name like RUNNER~1 in the wild+ * -- looked under its own spelling, found nothing, and re-ingested everything.+ */++let dir: string;+let link: string;++beforeEach(() => {+ dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "ix-rootkey-")));+ fs.mkdirSync(path.join(dir, "repo"));+ link = path.join(dir, "via-link");+ fs.symlinkSync(path.join(dir, "repo"), link, "dir");+});++afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));++describe("per-root state paths", () => {+ it("are the same for every spelling of one root", () => {+ for (const at of [ingestMtimeCachePath, ingestRebuildPath, mapBaselinePath, mapResultCachePath]) {+ expect(at(link), at.name).toBe(at(path.join(dir, "repo")));+ expect(at(path.join(dir, "repo", ".")), at.name).toBe(at(path.join(dir, "repo")));+ }+ });++ it("still differ between roots", () => {+ fs.mkdirSync(path.join(dir, "other"));+ expect(ingestMtimeCachePath(path.join(dir, "other"))).not.toBe(ingestMtimeCachePath(path.join(dir, "repo")));+ });++ it("key a root that does not exist yet by its resolved path", () => {+ expect(ingestMtimeCachePath(path.join(dir, "missing"))).toBe(ingestMtimeCachePath(path.join(dir, "missing", ".")));+ });+});diff --git a/ix-cli/src/cli/config.ts b/ix-cli/src/cli/config.tsindex f0c54aa9..3d944eb9 100644--- a/ix-cli/src/cli/config.ts+++ b/ix-cli/src/cli/config.ts@@ -8,13 +8,24 @@ import { parse, stringify } from "yaml";import { IxClient } from "../client/api.js";import { ixHome } from "./ix-home.js";+/**+ * The key of a project root's per-root state files. Canonical first: `ix+ * ingest <path>` resolves its root with `canonicalWorkspacePath`, and a caller+ * that spelled the same root differently -- a symlink, macOS's /tmp, a Windows+ * 8.3 name like RUNNER~1 -- found no baseline under its own spelling and+ * re-ingested everything, every time.+ */+function rootKey(projectRoot: string): string {+ return createHash("sha256").update(canonicalWorkspacePath(projectRoot)).digest("hex").slice(0, 12);+}+/*** Path to the per-project ingest mtime cache (the "skip unchanged files on re-map"* pre-filter). Keyed on a hash of the project root. Single source of truth shared by* ingest (load/save), reset, and watch (clear) — all three MUST agree on this path.*/export function ingestMtimeCachePath(projectRoot: string): string {- const key = createHash("sha256").update(projectRoot).digest("hex").slice(0, 12);+ const key = rootKey(projectRoot);return join(ixHome(), `ingest_mtimes_${key}.json`);}@@ -24,13 +35,13 @@ export function ingestMtimeCachePath(projectRoot: string): string {* same graph.*/export function ingestRebuildPath(projectRoot: string): string {- const key = createHash("sha256").update(projectRoot).digest("hex").slice(0, 12);+ const key = rootKey(projectRoot);return join(ixHome(), `ingest_rebuild_${key}.json`);}/** Path to the architecture-map completion marker for one project root. */export function mapBaselinePath(projectRoot: string): string {- const key = createHash("sha256").update(projectRoot).digest("hex").slice(0, 12);+ const key = rootKey(projectRoot);return join(ixHome(), `map_baseline_${key}.json`);}@@ -40,7 +51,7 @@ export function mapBaselinePath(projectRoot: string): string {* Cleared with the map baseline, since both describe the same hierarchy.*/export function mapResultCachePath(projectRoot: string): string {- const key = createHash("sha256").update(projectRoot).digest("hex").slice(0, 12);+ const key = rootKey(projectRoot);return join(ixHome(), `map_result_${key}.json`);}@@ -200,6 +211,7 @@ export function saveConfig(config: IxConfig): void {throw new Error(`${configPath} is not valid YAML, so Ix will not overwrite it. ` +`Fix or remove the file and run the command again. (${err instanceof Error ? err.message.split("\n")[0] : String(err)})`,+ { cause: err },);}}