diff --git a/src/cli/commands/watch.ts b/src/cli/commands/watch.ts index 488149d83..a6442fbe6 100644 --- a/src/cli/commands/watch.ts +++ b/src/cli/commands/watch.ts @@ -6,6 +6,7 @@ export const command: CommandDefinition = { name: 'watch [dir]', description: 'Watch project for file changes and incrementally update the graph', options: [ + ['-d, --db ', 'Path to graph.db'], ['--poll', 'Use stat-based polling (default on Windows to avoid ReFS/Dev Drive crashes)'], ['--native', 'Force native OS file watchers instead of polling'], ['--poll-interval ', 'Polling interval in milliseconds (default: 2000)'], @@ -22,6 +23,7 @@ export const command: CommandDefinition = { engine, poll, pollInterval: opts.pollInterval ? Number(opts.pollInterval) : undefined, + dbPath: opts.db ? path.resolve(opts.db) : undefined, }); }, }; diff --git a/src/domain/graph/watcher.ts b/src/domain/graph/watcher.ts index a7b65e4ad..c00934e2c 100644 --- a/src/domain/graph/watcher.ts +++ b/src/domain/graph/watcher.ts @@ -165,8 +165,8 @@ interface WatcherContext { } /** Initialize DB, engine, cache, and statements for watch mode. */ -function setupWatcher(rootDir: string, opts: { engine?: string }): WatcherContext { - const dbPath = path.join(rootDir, '.codegraph', 'graph.db'); +function setupWatcher(rootDir: string, opts: { engine?: string; dbPath?: string }): WatcherContext { + const dbPath = opts.dbPath ?? path.join(rootDir, '.codegraph', 'graph.db'); if (!fs.existsSync(dbPath)) { throw new DbError('No graph.db found. Run `codegraph build` first.', { file: dbPath }); } @@ -297,7 +297,7 @@ function setupShutdownHandler(ctx: WatcherContext, cleanup: () => void): void { export async function watchProject( rootDir: string, - opts: { engine?: string; poll?: boolean; pollInterval?: number } = {}, + opts: { engine?: string; poll?: boolean; pollInterval?: number; dbPath?: string } = {}, ): Promise { const ctx = setupWatcher(rootDir, opts);