Watch options shared by the default project and explicit projects.
()
| 363 | |
| 364 | /** Watch options shared by the default project and explicit projects. */ |
| 365 | private watchOptions(): Parameters<CodeGraph['watch']>[0] { |
| 366 | // Optional override for the debounce window via env var (issue #403). |
| 367 | // Useful for workspaces with bursty writes (formatter-on-save chains, |
| 368 | // large generated outputs) where the 2s default fires too often. Clamped |
| 369 | // to [100ms, 60s]; out-of-range / non-numeric values fall back to the |
| 370 | // FileWatcher default. We log the active value so it's discoverable. |
| 371 | const debounceMs = parseDebounceEnv(process.env.CODEGRAPH_WATCH_DEBOUNCE_MS); |
| 372 | if (debounceMs !== undefined) { |
| 373 | process.stderr.write(`[CodeGraph MCP] File watcher debounce: ${debounceMs}ms (CODEGRAPH_WATCH_DEBOUNCE_MS)\n`); |
| 374 | } |
| 375 | return { |
| 376 | debounceMs, |
| 377 | onSyncComplete: (result) => { |
| 378 | if (result.filesChanged > 0) { |
| 379 | process.stderr.write( |
| 380 | `[CodeGraph MCP] Auto-synced ${result.filesChanged} file(s) in ${result.durationMs}ms\n` |
| 381 | ); |
| 382 | } |
| 383 | }, |
| 384 | onSyncError: (err) => { |
| 385 | process.stderr.write(`[CodeGraph MCP] Auto-sync error: ${err.message}\n`); |
| 386 | }, |
| 387 | onDegraded: (reason) => { |
| 388 | // Live watching gave up permanently (watch-resource exhaustion or a |
| 389 | // write lock held past the retry budget). Say so loudly and ONCE — the |
| 390 | // graph will no longer auto-update, so a long-running MCP session must |
| 391 | // not keep assuming it's fresh. The reason already names the remedy |
| 392 | // (`codegraph sync` / git sync hooks). |
| 393 | process.stderr.write(`[CodeGraph MCP] File watcher degraded — ${reason}\n`); |
| 394 | }, |
| 395 | }; |
| 396 | } |
| 397 | |
| 398 | private async doInitialize(searchFrom: string): Promise<void> { |
| 399 | this.toolHandler.setDefaultProjectHint(searchFrom); |
no test coverage detected