Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
fix(map): no slash-glue when a directory splits to file-level lines
Shrish Dwivedieb8961b88c41
diff --git a/src/graph/map.ts b/src/graph/map.tsindex a936e5a3..4af4eeb3 100644--- a/src/graph/map.ts+++ b/src/graph/map.ts@@ -38,6 +38,12 @@ export interface DirEntry {symbols: number;languages: string[];hubs: Hub[];+ /** True when the >60% split refinement bottomed out on a file that sits+ * directly in the split directory (no deeper subdirectory to split into —+ * see `dirKey`'s doc). In that case `path` IS a file's own full path, not+ * a directory, so `formatDirLine` must not append a trailing "/". False+ * for every real directory group (the overwhelming majority). */+ isFile: boolean;}/** One scope's own directory breakdown — same shape a single-scope `buildRepoMap`@@ -191,12 +197,20 @@ function computeDirEntries(const fullPath = (relKey: string): string =>stripPrefix === "" ? relKey : relKey === "" ? stripPrefix : `${stripPrefix}/${relKey}`;+ // A group's key is a FILE's own path (not a directory) exactly when the+ // split-refinement's depth-2 grouping had nowhere deeper to go and+ // `dirKey` degenerated to the file's full relative path verbatim — see+ // `dirKey`'s doc. Detecting that by membership (rather than re-deriving+ // depth here) stays correct regardless of which pass produced the key.+ const fileRelPaths = new Set(fileNodes.map((f) => relPath(f.path)));+const dirEntries: DirEntry[] = [...groups.entries()].map(([relKey, g]) => ({path: fullPath(relKey),files: g.files.length,symbols: g.symbols.length,languages: sortedLanguages(g.files.map((f) => f.path)),hubs: topHubs(g.symbols, inDegree, hubsPerDir),+ isFile: fileRelPaths.has(relKey),}));dirEntries.sort((a, b) => b.symbols - a.symbols || a.path.localeCompare(b.path));@@ -280,7 +294,11 @@ function formatDirHub(h: Hub): string {}function formatDirLine(d: DirEntry): string {- const label = `${d.path}/`.padEnd(DIR_COL_WIDTH);+ // `d.path` is only ever a real directory unless the >60% split refinement+ // bottomed out on a file with nowhere deeper to split into (`d.isFile`) —+ // only then is the trailing "/" wrong (it would glue onto the file's own+ // extension, e.g. "auth.ts/").+ const label = (d.isFile ? d.path : `${d.path}/`).padEnd(DIR_COL_WIDTH);const counts = `${d.files} files · ${d.symbols} symbols`;const hubs = d.hubs.length ? ` hubs: ${d.hubs.map(formatDirHub).join(", ")}` : "";return `${label}${counts}${hubs}`;diff --git a/test/graph-map.test.ts b/test/graph-map.test.tsindex b5847f28..be45d4c7 100644--- a/test/graph-map.test.ts+++ b/test/graph-map.test.ts@@ -146,6 +146,44 @@ test("buildRepoMap: a segment at or below 60% is not split", () => {assert.ok(map.dirs.some((d) => d.path === "src"), "60% exactly must not trigger the split");});+test("buildRepoMap: a file sitting directly in a >60% split dir collapses to a file-level entry, rendered with no trailing slash", () => {+ // src/ holds 5 of 8 files (62.5% > 60%) → split one level deeper. Four of+ // those five files nest under src/ask and src/graph (clean sub-dirs), but+ // src/auth.ts sits directly in src/ itself — depth-2 grouping has nothing+ // deeper to split it into, so `dirKey` degenerates to the file's own full+ // path ("src/auth.ts"), and that path is a FILE, not a directory.+ const nodes = [+ fileNode("src/auth.ts"),+ fileNode("src/ask/a1.ts"),+ fileNode("src/ask/a2.ts"),+ fileNode("src/graph/g1.ts"),+ fileNode("src/graph/g2.ts"),+ fileNode("tests/t1.ts"),+ fileNode("tests/t2.ts"),+ fileNode("tests/t3.ts"),+ ];+ const map = buildRepoMap(graphOf(nodes, []));+ const paths = map.dirs.map((d) => d.path);++ assert.ok(!paths.includes("src"), "the over-threshold group itself must not survive unsplit");+ assert.ok(paths.includes("src/auth.ts"), "the file that couldn't split deeper reports its own full path");+ assert.ok(paths.includes("src/ask"));+ assert.ok(paths.includes("src/graph"));++ const authEntry = map.dirs.find((d) => d.path === "src/auth.ts")!;+ assert.equal(authEntry.files, 1);++ const text = formatRepoMap(map);+ // Exact rendered line: file path padded to the 20-col width, no trailing+ // "/" glued onto it — never "src/auth.ts/1 files" or "src/auth.ts/ ".+ const expectedLine = "src/auth.ts".padEnd(20) + "1 files · 0 symbols";+ assert.ok(+ text.includes(expectedLine),+ `expected exact line "${expectedLine}" in:\n${text}`,+ );+ assert.doesNotMatch(text, /auth\.ts\//, "no slash glued onto the file path");+});+// ── hub ordering ─────────────────────────────────────────────────────────test("buildRepoMap: hubs within a dir are ranked by inDegree desc, ties broken by name asc", () => {