* 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)
| 501 | * is populated by the watcher, not by catch-up). |
| 502 | */ |
| 503 | private catchUpSync(afterReopen = false): void { |
| 504 | const cg = this.cg; |
| 505 | if (!cg || this.opts.readOnly) return; |
| 506 | // The lease's gate is the startup reconcile and stays settled once caught |
| 507 | // up; a database reopened after a rebuild (#1902) needs a sync of its own. |
| 508 | if (this.defaultLease && !afterReopen) { |
| 509 | this.toolHandler.setCatchUpGate(this.defaultLease.ready()); |
| 510 | return; |
| 511 | } |
| 512 | const p = cg |
| 513 | .sync() |
| 514 | .then((result) => { |
| 515 | const changed = result.filesAdded + result.filesModified + result.filesRemoved; |
| 516 | if (changed > 0) { |
| 517 | process.stderr.write(`[CodeGraph MCP] Caught up ${changed} file(s) changed since last run\n`); |
| 518 | } |
| 519 | }) |
| 520 | .catch((err) => { |
| 521 | const msg = err instanceof Error ? err.message : String(err); |
| 522 | process.stderr.write(`[CodeGraph MCP] Catch-up sync failed: ${msg}\n`); |
| 523 | }); |
| 524 | this.toolHandler.setCatchUpGate(p); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /** |
no test coverage detected