Watch options shared by the default project and explicit projects.
()
| 335 | |
| 336 | /** Watch options shared by the default project and explicit projects. */ |
| 337 | private watchOptions(): Parameters<CodeGraph['watch']>[0] { |
| 338 | // Optional override for the debounce window via env var (issue #403). |
| 339 | // Useful for workspaces with bursty writes (formatter-on-save chains, |
| 340 | // large generated outputs) where the 2s default fires too often. Clamped |
| 341 | // to [100ms, 60s]; out-of-range / non-numeric values fall back to the |
| 342 | // FileWatcher default. We log the active value so it's discoverable. |
| 343 | const debounceMs = parseDebounceEnv(process.env.CODEGRAPH_WATCH_DEBOUNCE_MS); |
| 344 | if (debounceMs !== undefined) { |
| 345 | process.stderr.write(`[CodeGraph MCP] File watcher debounce: ${debounceMs}ms (CODEGRAPH_WATCH_DEBOUNCE_MS)\n`); |
| 346 | } |
| 347 | return { |
| 348 | debounceMs, |
| 349 | onSyncComplete: (result) => { |
| 350 | if (result.filesChanged > 0) { |
| 351 | process.stderr.write( |
| 352 | `[CodeGraph MCP] Auto-synced ${result.filesChanged} file(s) in ${result.durationMs}ms\n` |
| 353 | ); |
| 354 | } |
| 355 | }, |
| 356 | onSyncError: (err) => { |
| 357 | process.stderr.write(`[CodeGraph MCP] Auto-sync error: ${err.message}\n`); |
| 358 | }, |
| 359 | onDegraded: (reason) => { |
| 360 | // Live watching gave up permanently (watch-resource exhaustion or a |
| 361 | // write lock held past the retry budget). Say so loudly and ONCE — the |
| 362 | // graph will no longer auto-update, so a long-running MCP session must |
| 363 | // not keep assuming it's fresh. The reason already names the remedy |
| 364 | // (`codegraph sync` / git sync hooks). |
| 365 | process.stderr.write(`[CodeGraph MCP] File watcher degraded — ${reason}\n`); |
| 366 | }, |
| 367 | }; |
| 368 | } |
| 369 | |
| 370 | private async doInitialize(searchFrom: string): Promise<void> { |
| 371 | this.toolHandler.setDefaultProjectHint(searchFrom); |
no test coverage detected