Skip to content

Commit 59b1b6a

Browse files
authored
fix(watch): accept -d/--db to point at a graph.db outside cwd (#987)
Every other command that operates on a graph DB (build, stats, query, fn-impact, impact, etc.) accepts \`-d, --db <path>\`, but \`watch\` did not — it rejected the flag with \`error: unknown option '--db'\` and only honored the positional \`[dir]\`. This forced users in monorepo and multi-repo setups to \`cd\` into the watched directory, defeating the purpose of having \`--db\` elsewhere. Add the option to the watch command, plumb it through watchProject and setupWatcher, and fall back to \`<rootDir>/.codegraph/graph.db\` when \`--db\` is absent. Closes #984
1 parent 937e734 commit 59b1b6a

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/cli/commands/watch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const command: CommandDefinition = {
66
name: 'watch [dir]',
77
description: 'Watch project for file changes and incrementally update the graph',
88
options: [
9+
['-d, --db <path>', 'Path to graph.db'],
910
['--poll', 'Use stat-based polling (default on Windows to avoid ReFS/Dev Drive crashes)'],
1011
['--native', 'Force native OS file watchers instead of polling'],
1112
['--poll-interval <ms>', 'Polling interval in milliseconds (default: 2000)'],
@@ -22,6 +23,7 @@ export const command: CommandDefinition = {
2223
engine,
2324
poll,
2425
pollInterval: opts.pollInterval ? Number(opts.pollInterval) : undefined,
26+
dbPath: opts.db ? path.resolve(opts.db) : undefined,
2527
});
2628
},
2729
};

src/domain/graph/watcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ interface WatcherContext {
165165
}
166166

167167
/** Initialize DB, engine, cache, and statements for watch mode. */
168-
function setupWatcher(rootDir: string, opts: { engine?: string }): WatcherContext {
169-
const dbPath = path.join(rootDir, '.codegraph', 'graph.db');
168+
function setupWatcher(rootDir: string, opts: { engine?: string; dbPath?: string }): WatcherContext {
169+
const dbPath = opts.dbPath ?? path.join(rootDir, '.codegraph', 'graph.db');
170170
if (!fs.existsSync(dbPath)) {
171171
throw new DbError('No graph.db found. Run `codegraph build` first.', { file: dbPath });
172172
}
@@ -297,7 +297,7 @@ function setupShutdownHandler(ctx: WatcherContext, cleanup: () => void): void {
297297

298298
export async function watchProject(
299299
rootDir: string,
300-
opts: { engine?: string; poll?: boolean; pollInterval?: number } = {},
300+
opts: { engine?: string; poll?: boolean; pollInterval?: number; dbPath?: string } = {},
301301
): Promise<void> {
302302
const ctx = setupWatcher(rootDir, opts);
303303

0 commit comments

Comments
 (0)