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(ingest): don't adopt a git repo at $HOME as a loose path's workspace
KageBinary9a39e1e2c6fe
diff --git a/ix-cli/src/cli/__tests__/map-root.test.ts b/ix-cli/src/cli/__tests__/map-root.test.tsindex 3e1b7196..bf9aec2d 100644--- a/ix-cli/src/cli/__tests__/map-root.test.ts+++ b/ix-cli/src/cli/__tests__/map-root.test.ts@@ -230,6 +230,18 @@ describe("ingest root resolution", () => {expect(resolveIngestRoot(join(loose, "x.ts"), false)).toBe(loose);});+ it("does not adopt a git repository at $HOME as the workspace of a loose path", () => {+ const realHome = realpathSync.native(home);+ mkdirSync(join(realHome, "notes", "dir"), { recursive: true });+ execFileSync("git", ["init", "-q"], { cwd: realHome });++ expect(resolveIngestRoot(join(realHome, "notes", "dir"), true)).toBe(join(realHome, "notes", "dir"));++ // A workspace the user registered at $HOME on purpose is still used.+ writeWorkspaces(realHome);+ expect(resolveIngestRoot(join(realHome, "notes", "dir"), true)).toBe(realHome);+ });+it("takes --root first, and refuses a path outside it", () => {const repo = realpathSync.native(fixture());const other = realpathSync.native(fixture());diff --git a/ix-cli/src/cli/map-root.ts b/ix-cli/src/cli/map-root.tsindex 6db993e8..99b4fea2 100644--- a/ix-cli/src/cli/map-root.ts+++ b/ix-cli/src/cli/map-root.ts@@ -1,6 +1,7 @@// Copyright 2026 Ix Infrastructure Inc.import { realpathSync, statSync } from "node:fs";+import { homedir } from "node:os";import { dirname, resolve } from "node:path";import { canonicalWorkspacePath, findWorkspaceForCwd, gitRootFor, isPathInside, resolveWorkspaceRoot } from "./config.js";@@ -65,10 +66,14 @@ export function localRootFor(dir: string): string | undefined {** 1. an explicit `--root` (the path must be inside it)* 2. the registered workspace containing the path- * 3. the path's git root+ * 3. the path's git root, unless that is the home directory* 4. the path itself for a directory, its directory for a file -- a path* in no workspace and no repository is ingested as its own workspace.*+ * Step 3 skips a git root at `$HOME` (a dotfiles repo): registering the whole+ * home directory as a workspace would route every later read under it there.+ * A workspace the user registered at `$HOME` is still honoured by step 2.+ ** The same local-first order as `resolveMapRoot`, minus its named/default* workspace step: that one answers "which repo is cwd in", and a path the* user named outside every workspace and repository belongs to none of them.@@ -89,5 +94,11 @@ export function resolveIngestRoot(target: string, isDirectory: boolean, explicitreturn root;}const probe = isDirectory ? canonicalTarget : dirname(canonicalTarget);- return canonicalWorkspacePath(localRootFor(probe) ?? probe);+ const registered = findWorkspaceForCwd(probe)?.root_path;+ if (registered) return canonicalWorkspacePath(registered);+ const gitRoot = gitRootFor(probe);+ if (gitRoot && canonicalWorkspacePath(gitRoot) !== canonicalWorkspacePath(homedir())) {+ return canonicalWorkspacePath(gitRoot);+ }+ return probe;}