* Reconcile the index with the current filesystem once, right after open — * catches edits, adds, deletes, and `git pull`/`checkout` changes made while * no watcher was running. Runs in the background, but the returned promise * is pushed into the ToolHandler as a one-shot gate so the *firs
(afterReopen = false)
| 471 | * is populated by the watcher, not by catch-up). |
| 472 | */ |
| 473 | private catchUpSync(afterReopen = false): void { |
| 474 | const cg = this.cg; |
| 475 | if (!cg || this.opts.readOnly) return; |
| 476 | // The lease's gate is the startup reconcile and stays settled once caught |
| 477 | // up; a database reopened after a rebuild (#1902) needs a sync of its own. |
| 478 | if (this.defaultLease && !afterReopen) { |
| 479 | this.toolHandler.setCatchUpGate(this.defaultLease.ready()); |
| 480 | return; |
| 481 | } |
| 482 | const p = cg |
| 483 | .sync() |
| 484 | .then((result) => { |
| 485 | const changed = result.filesAdded + result.filesModified + result.filesRemoved; |
| 486 | if (changed > 0) { |
| 487 | process.stderr.write(`[CodeGraph MCP] Caught up ${changed} file(s) changed since last run\n`); |
| 488 | } |
| 489 | }) |
| 490 | .catch((err) => { |
| 491 | const msg = err instanceof Error ? err.message : String(err); |
| 492 | process.stderr.write(`[CodeGraph MCP] Catch-up sync failed: ${msg}\n`); |
| 493 | }); |
| 494 | this.toolHandler.setCatchUpGate(p); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | /** |
no test coverage detected