fix(watch): accept -d/--db to point at a graph.db outside cwd#987
fix(watch): accept -d/--db to point at a graph.db outside cwd#987carlos-alm merged 2 commits intomainfrom
Conversation
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
|
Claude finished @carlos-alm's task —— View job PR Review: Add --db flag to watch commandTodo List:
Root Cause AnalysisProblem Being Solved: The Configuration & Test Integrity Check✅ No configuration changes - No linting rules, test timeouts, or build configs modified Code Quality & Security Assessment✅ Follows established patterns - Identical to 23 other commands using
Minor observation: The implementation correctly defaults to Backlog Compliance
Critical ConcernsNone. This is a textbook example of a well-executed consistency fix. Final Recommendation
Only minor deduction: This is maintenance work rather than innovation, hence 4/5 instead of 5/5. |
Greptile SummaryThis PR adds the missing Confidence Score: 5/5Safe to merge — change is minimal, isolated, and behaviorally backward-compatible. No logic errors, no security concerns, and no regressions. All four test plan scenarios map correctly to the implementation. Only P2-level observations (journal/change-event writes always use No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI as watch.ts (CLI)
participant WP as watchProject()
participant SW as setupWatcher()
participant FS as fs / SQLite
CLI->>CLI: path.resolve(opts.db) → dbPath (or undefined)
CLI->>WP: watchProject(rootDir, { ..., dbPath })
WP->>SW: setupWatcher(rootDir, { engine, dbPath })
SW->>SW: dbPath ?? path.join(rootDir, '.codegraph/graph.db')
SW->>FS: fs.existsSync(dbPath)
alt DB missing
FS-->>SW: false
SW-->>CLI: throw DbError
else DB found
FS-->>SW: true
SW->>FS: openDb(dbPath)
SW-->>WP: WatcherContext
end
WP->>WP: startPollingWatcher / startNativeWatcher (rootDir)
Reviews (1): Last reviewed commit: "fix(watch): accept -d/--db to point at a..." | Re-trigger Greptile |
Codegraph Impact Analysis3 functions changed → 2 callers affected across 2 files
|
Summary
Every other command that operates on a graph DB (
build,stats,query,fn-impact,impact,diff-impact,export,embed,search,triage,complexity,audit,roles,cycles,map,plot,co-change,owners,batch,check,children) accepts-d, --db <path>.watchdid not — it rejected the flag witherror: unknown option '--db', forcing users in monorepo and multi-repo MCP setups tocdinto the watched directory.Add the option, plumb it through
watchProject→setupWatcher, and fall back to<rootDir>/.codegraph/graph.dbwhen it's absent.Found during
Dogfooding v3.9.4 — see #984
Test plan
codegraph watch --helpshows-d, --db <path>codegraph watch <dir> --db <path>runs against the specified DB from a different cwdcodegraph watch <dir> --db /missing.dberrors cleanly withNo graph.db found. Run \codegraph build` first.`codegraph watch <dir>(no--db) behaves exactly as before (default.codegraph/graph.dbunder the watched dir)npm run typecheckcleannpm run lintclean