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: keep include-dir config outside generated output
anirudhkumar-nanonetsddb23cd79dae
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c10b64db..94b1f8d8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,9 +8,10 @@`SKIP_DIRS` (repeatable: `--include-dir build --include-dir tools`). Someecosystems keep genuine hand-written source under a directory name graftotherwise treats as build output (e.g. a `build/` that isn't generated).- The override is persisted per repo: set it once and every later no-flag- `graft build`, plus the hooks/refresh path (which never sees CLI flags at- all), include it identically. It lifts only graft's own skip list — in a+ The override is persisted per repo in Git-ignored `.graft/config.json`: set+ it once and every later no-flag `graft build`, plus the hooks/refresh path+ (which never sees CLI flags at all), include it identically. It lifts only+ graft's own skip list — in aGit repository, Git's ignore rules stay authoritative, so a directory thatis both skip-listed and gitignored needs un-ignoring (or `git add -f`) too,the same contract indexing already applies to tracked-but-ignored files.diff --git a/src/graph/workspace-cli.ts b/src/graph/workspace-cli.tsindex 95fb87fd..0c68a9b5 100644--- a/src/graph/workspace-cli.ts+++ b/src/graph/workspace-cli.ts@@ -33,9 +33,8 @@ export interface WorkspaceBuildOptions {override?: string;/** The CLI's `--include-dir` override, if any. Persisted into EACH CHILD's* own state (not the parent's) before that child builds: children are- * independent repos with their own graft state, and the parent's `graft/`- * (including any state it briefly held) is deleted by `splitWorkspace`- * right after the children build — see `clearParentGraft`'s doc comment. */+ * independent repos with their own local settings and can later be rebuilt+ * directly without seeing the parent invocation's flags. */includeDirs?: string[];}diff --git a/src/util/state.ts b/src/util/state.tsindex da770e1d..fa2aa361 100644--- a/src/util/state.ts+++ b/src/util/state.ts@@ -76,10 +76,34 @@ export interface BuildConfig {includeDirs?: string[];}-function configPath(d: string): string { return join(cacheDir(d), 'config.json'); }+/** Local, Git-ignored repository configuration. Kept outside generated+ * `graft/` output so deleting/replacing that cache, workspace federation, and+ * custom `--dir` builds cannot erase or redirect the persisted choice. */+export const BUILD_CONFIG_DIR = '.graft';-export function readBuildConfig(d: string): BuildConfig | null { return readJson<BuildConfig>(configPath(d)); }-export function writeBuildConfig(d: string, c: BuildConfig): void { writeJsonAtomic(configPath(d), c); }+export function buildConfigPath(d: string): string { return join(d, BUILD_CONFIG_DIR, 'config.json'); }++/** Keep local build configuration out of Git without coupling it to the+ * generated graph directory. Best-effort, matching graph-cache ignore setup. */+function ensureBuildConfigIgnored(d: string): void {+ const path = join(d, '.gitignore');+ let current = '';+ try { current = readFileSync(path, 'utf8'); } catch { /* no .gitignore yet */ }+ const present = current.split('\n').some((line) => {+ const value = line.trim();+ return value === BUILD_CONFIG_DIR || value === `${BUILD_CONFIG_DIR}/` || value === `/${BUILD_CONFIG_DIR}/`;+ });+ if (present) return;+ const gap = current === '' ? '' : current.endsWith('\n') ? '\n' : '\n\n';+ const block = `${gap}# graft's local repository settings — not committed.\n/${BUILD_CONFIG_DIR}/\n`;+ try { writeFileSync(path, current + block); } catch { /* best-effort */ }+}++export function readBuildConfig(d: string): BuildConfig | null { return readJson<BuildConfig>(buildConfigPath(d)); }+export function writeBuildConfig(d: string, c: BuildConfig): void {+ ensureBuildConfigIgnored(d);+ writeJsonAtomic(buildConfigPath(d), c);+}/** The persisted `--include-dir` override for repo `d`, as a Set — `undefined`* when nothing was ever persisted (or the persisted list is empty), which everydiff --git a/test/graph-include-dir.test.ts b/test/graph-include-dir.test.tsindex 3e543594..ce76e380 100644--- a/test/graph-include-dir.test.ts+++ b/test/graph-include-dir.test.ts@@ -83,6 +83,39 @@ test("A5: build/ is absent by default, present with --include-dir build, persistassert.ok(isClean(drift!), `probe must report clean, got ${JSON.stringify(drift)}`);});+test("A5: deleting the generated graft cache does not delete the persisted include-dir setting", () => {+ const d = repoWithBuildDir();+ try {+ runCli(["build", d, "--include-dir", "build"]);+ rmSync(join(d, "graft"), { recursive: true, force: true });++ runCli(["build", d]);+ const rebuilt = graphOf(d);+ assert.ok(rebuilt?.nodes.some((n) => n.id === "build/util.ts#fromBuild"));+ assert.equal(existsSync(join(d, ".graft", "config.json")), true);+ } finally {+ rmSync(d, { recursive: true, force: true });+ }+});++test("A5: custom --dir builds keep repository config outside both output directories", () => {+ const d = repoWithBuildDir();+ const out = mkdtempSync(join(tmpdir(), "graft-include-dir-output-"));+ try {+ writeFileSync(join(d, "graft"), "a regular file that must not receive config\n");+ runCli(["--dir", out, "build", d, "--include-dir", "build"]);++ const graph = readGraph(wiringPath(out));+ assert.ok(graph?.nodes.some((n) => n.id === "build/util.ts#fromBuild"));+ assert.equal(existsSync(join(d, ".graft", "config.json")), true);+ assert.equal(existsSync(join(d, "graft", ".cache", "config.json")), false);+ assert.equal(existsSync(join(out, ".cache", "config.json")), false);+ } finally {+ rmSync(d, { recursive: true, force: true });+ rmSync(out, { recursive: true, force: true });+ }+});+// --include-dir takes bare SKIP_DIRS-style directory NAMES, never paths, and// dot-dirs are (per the option's own help text) never overridable at all.// Without validation, a value like ".github" or "foo/bar" would silently@@ -97,7 +130,7 @@ test("A5: --include-dir rejects a dot-prefixed name", () => {assert.equal(r.status, 1, `expected exit 1, got ${r.status}\nstdout: ${r.stdout}\nstderr: ${r.stderr}`);assert.match(r.stderr, /--include-dir/);assert.match(r.stderr, /\.github/);- assert.equal(existsSync(join(d, "graft", ".cache", "config.json")), false, "must not persist an invalid value");+ assert.equal(existsSync(join(d, ".graft", "config.json")), false, "must not persist an invalid value");} finally {rmSync(d, { recursive: true, force: true });}@@ -110,7 +143,7 @@ test("A5: --include-dir rejects a value containing a path separator", () => {assert.equal(r.status, 1, `expected exit 1, got ${r.status}\nstdout: ${r.stdout}\nstderr: ${r.stderr}`);assert.match(r.stderr, /--include-dir/);assert.match(r.stderr, /foo\/bar/);- assert.equal(existsSync(join(d, "graft", ".cache", "config.json")), false, "must not persist an invalid value");+ assert.equal(existsSync(join(d, ".graft", "config.json")), false, "must not persist an invalid value");} finally {rmSync(d, { recursive: true, force: true });}diff --git a/test/graph-workspace-include-dir.test.ts b/test/graph-workspace-include-dir.test.tsindex f1d22c38..fe37cbe6 100644--- a/test/graph-workspace-include-dir.test.ts+++ b/test/graph-workspace-include-dir.test.ts@@ -2,24 +2,22 @@* A5 (V4) — a workspace build's `--include-dir` must reach the children.** `runWorkspaceBuild` builds each child through its own `Graft` engine- * (`workspace-cli.ts`), then `splitWorkspace` deletes the PARENT's entire- * `graft/` (including any just-persisted include-dir state — see- * `clearParentGraft`'s doc comment) and replaces it with `workspace.json`.+ * (`workspace-cli.ts`), then `splitWorkspace` replaces the PARENT's generated+ * `graft/` with `workspace.json`.* Without threading the CLI's `--include-dir` value into* `runWorkspaceBuild`/`buildChild`, a workspace build had no way to see it —- * and even if it had persisted state at the parent, that state is exactly- * what gets deleted moments later. Children are independent repos with their- * own graft state, so the fix persists the include list in EACH CHILD's own- * state instead.+ * children are independent repos with their own graft state, so the fix+ * persists the include list in EACH CHILD's own state too.*/import { test } from "node:test";import assert from "node:assert/strict";-import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";+import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, rmSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { runWorkspaceBuild } from "../src/graph/workspace-cli.js";import { buildGraph } from "../src/graph/build.js";import { readGraph, wiringPath } from "../src/graph/write.js";+import { writeBuildConfig } from "../src/util/state.js";import type { GraphV1 } from "../src/graph/types.js";function workspaceWithBuildDirs(): string {@@ -53,8 +51,7 @@ test("A5: --include-dir on a workspace build reaches every child, which persists// A later no-flag rebuild of a single child (never sees the parent's CLI// invocation at all, let alone its flags) must still include build/ —- // proof the child persisted the override in ITS OWN state, not the- // parent's (which splitWorkspace deletes right after the build).+ // proof the child persisted the override in ITS OWN state.await buildGraph(join(parent, "repoA"));const rebuilt = graphOf(join(parent, "repoA"));assert.ok(rebuilt);@@ -66,3 +63,23 @@ test("A5: --include-dir on a workspace build reaches every child, which persistsrmSync(parent, { recursive: true, force: true });}});++test("A5: a skipped-name workspace child remains discoverable on a later no-flag rebuild", async () => {+ const parent = mkdtempSync(join(tmpdir(), "ws-include-child-"));+ try {+ for (const child of ["app", "build"]) {+ mkdirSync(join(parent, child, ".git"), { recursive: true });+ writeFileSync(join(parent, child, "main.ts"), `export const ${child}Value = 1;\n`);+ }++ writeBuildConfig(parent, { includeDirs: ["build"] });+ await runWorkspaceBuild(parent, { deep: false, childConfig: {}, includeDirs: ["build"] });+ await runWorkspaceBuild(parent, { deep: false, childConfig: {} });++ const workspace = JSON.parse(readFileSync(join(parent, "graft", "workspace.json"), "utf8")) as { children: string[] };+ assert.deepEqual(workspace.children, ["app", "build"]);+ assert.equal(readFileSync(join(parent, ".graft", "config.json"), "utf8").includes("build"), true);+ } finally {+ rmSync(parent, { recursive: true, force: true });+ }+});diff --git a/test/util-state.test.ts b/test/util-state.test.tsindex 165e6aa9..6f3a2c7c 100644--- a/test/util-state.test.ts+++ b/test/util-state.test.ts@@ -10,10 +10,10 @@*/import { test } from "node:test";import assert from "node:assert/strict";-import { mkdtempSync } from "node:fs";+import { existsSync, mkdtempSync, readFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";-import { readBuildConfig, writeBuildConfig, readIncludeDirs } from "../src/util/state.js";+import { buildConfigPath, readBuildConfig, writeBuildConfig, readIncludeDirs } from "../src/util/state.js";function fresh(): string {return mkdtempSync(join(tmpdir(), "graft-buildconfig-"));@@ -29,6 +29,9 @@ test("writeBuildConfig + readBuildConfig round-trip includeDirs", () => {const d = fresh();writeBuildConfig(d, { includeDirs: ["build", "vendor"] });assert.deepEqual(readBuildConfig(d), { includeDirs: ["build", "vendor"] });+ assert.equal(buildConfigPath(d), join(d, ".graft", "config.json"));+ assert.equal(existsSync(join(d, "graft", ".cache", "config.json")), false);+ assert.match(readFileSync(join(d, ".gitignore"), "utf8"), /^\/\.graft\/$/m);});test("readIncludeDirs turns a persisted list into a Set; an empty persisted list reads as undefined (default behavior)", () => {