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
Seed the sidecars, not just the graph, on Windows
anirudhkumar-nanonets52d5e1314fca
diff --git a/src/graph/seed.ts b/src/graph/seed.tsindex 1a7d7643..f134782a 100644--- a/src/graph/seed.ts+++ b/src/graph/seed.ts@@ -36,16 +36,15 @@*/import {copyFileSync,- cpSync,existsSync,mkdirSync,readFileSync,+ readdirSync,renameSync,rmSync,statSync,} from "node:fs";import { basename, dirname, isAbsolute, join, resolve } from "node:path";-import { relPosix } from "../util/paths.js";import { ASK_INDEX_FILE } from "../ask/index-file.js";import { CACHE_DIR, contextDirFor } from "../context/node-file.js";import { EXTRACT_CACHE_PREFIX } from "./extract-cache.js";@@ -149,11 +148,35 @@ function seedable(rel: string): boolean {);}+/**+ * Copy `srcDir` into `outDir`, keeping only what {@link seedable} allows.+ *+ * Walked by hand rather than through `cpSync`'s `filter`, which did not hold on+ * Windows: the graph arrived — it is placed directly, by {@link installGraph} — while+ * every allowlisted sidecar next to it was dropped. A seeded worktree therefore had no+ * fingerprint, `probeDrift` read that as "never built", and the query right behind the+ * seed rebuilt the whole repo instead of the diff against the parent: precisely the+ * cost seeding exists to avoid, and silent, because a full rebuild still answers+ * correctly. It only surfaced as a `(? files changed)` note on the CI leg.+ *+ * Composing `rel` from the segments this walk joined itself is what fixes it — the+ * allowlist no longer depends on the form `cpSync` chooses to hand its callback, and+ * `rel` is posix by construction rather than by conversion. Also narrower than the old+ * copy in one way worth keeping: only real files and directories travel, never a+ * symlink, and nothing in the allowlist is one.+ */function copyTree(srcDir: string, outDir: string): void {- cpSync(srcDir, outDir, {- recursive: true,- filter: (src) => seedable(relPosix(srcDir, src)),- });+ const walk = (rel: string): void => {+ const from = rel ? join(srcDir, rel) : srcDir;+ mkdirSync(rel ? join(outDir, rel) : outDir, { recursive: true });+ for (const entry of readdirSync(from, { withFileTypes: true })) {+ const childRel = rel ? `${rel}/${entry.name}` : entry.name;+ if (!seedable(childRel)) continue;+ if (entry.isDirectory()) walk(childRel);+ else if (entry.isFile()) copyFileSync(join(from, entry.name), join(outDir, childRel));+ }+ };+ walk("");}/**diff --git a/test/graph-seed.test.ts b/test/graph-seed.test.tsindex a2621477..f0214eb9 100644--- a/test/graph-seed.test.ts+++ b/test/graph-seed.test.ts@@ -282,6 +282,10 @@ test("GRAFT_NO_SEED leaves the worktree exactly as it was", async () => {test("seedGraph declines a --dir override and a checkout that already has a graph", async () => {const main = gitRepo();await buildGraph(main);+ // Present so the negative assertions below mean something: both belong to the+ // checkout that produced them and must not travel.+ mkdirSync(join(outOf(main), ".cache", "session"), { recursive: true });+ writeFileSync(join(outOf(main), ".cache", "stats.json"), '{"tokens_saved":999}');const wt = addWorktree(main, "guards");// A custom output dir can't be mapped onto a sibling checkout, so don't guess.@@ -292,13 +296,20 @@ test("seedGraph declines a --dir override and a checkout that already has a grapassert.equal(seedGraph(wt).seeded, true, "first call copies");assert.deepEqual(seedGraph(wt), { seeded: false }, "second call has nothing to do");- // The freshness record has to travel with the graph, or the query right after the- // seed finds no fingerprint, cannot diff against the parent, and rebuilds the whole- // repo — which is the expensive thing seeding exists to avoid. Asserted on the- // direct `seedGraph` call because the refresh gate writes a fresh fingerprint of its- // own moments later, which would mask a copy that never happened.+ // The allowlist contract, asserted on a *direct* seed. The end-to-end test above+ // checks the same files, but only after the refresh gate has run — and that gate+ // writes a fresh fingerprint of its own, which masked a copy that never happened.+ // It did never happen on Windows: `cpSync`'s filter dropped every sidecar while the+ // graph itself (placed separately) arrived, so `probeDrift` found no fingerprint and+ // the query behind the seed rebuilt the whole repo instead of the diff.assert.ok(existsSync(fingerprintPath(outOf(main))), "the parent has a fingerprint to give");- assert.ok(existsSync(fingerprintPath(outOf(wt))), "and the seed brought it across");+ const landed = readdirSync(join(outOf(wt), ".cache")).sort();+ const why = `seeded .cache holds ${JSON.stringify(landed)}`;+ assert.ok(existsSync(fingerprintPath(outOf(wt))), `the freshness record travels — ${why}`);+ assert.ok(landed.includes("ask-index.json"), `the ask sidecar travels — ${why}`);+ assert.ok(landed.some((f) => f.startsWith("extract.")), `the extraction memo travels — ${why}`);+ assert.ok(!landed.includes("stats.json"), `borrowed savings do not — ${why}`);+ assert.ok(!landed.includes("session"), `another session's transcripts do not — ${why}`);rmSync(main, { recursive: true, force: true });rmSync(wt, { recursive: true, force: true });