* Sync the index with the current file state. * * Change detection is filesystem-based, never git: a (size, mtime) stat * pre-filter skips unchanged files, then a content-hash compare confirms real * changes. This works in non-git projects and catches committed changes from * `git pul
(
onProgress?: (progress: IndexProgress) => void,
/**
* Watcher fast path: the exact project-relative paths the OS reported as
* changed. When provided, reconciliation runs over ONLY these paths —
* per-path logic identical to the full walk (stat pre-filter, hash
* confirm, the #1240 removal/resurrection flow) — skipping the O(repo)
* scan and tracked-load. Callers must pass undefined whenever the change
* set is not exactly known (directory removals, event overflow): the full
* scan-diff remains the ground truth those cases need (#1285).
*/
scopedPaths?: string[],
/**
* Writer-side WAL pressure valve (#1539). Called after every changed file
* is stored, when no extraction transaction is open, so a checkpoint can
* safely catch up before the next file grows the WAL further.
*/
backpressure?: () => Promise<void> | null,
/** Inspect changed inputs before deletion/re-extraction cascades their edges. */
onFileChange?: (filePath: string, content?: string) => void
)
| 3875 | * `git pull`/`checkout`/`merge`/`rebase` that `git status` cannot see. |
| 3876 | */ |
| 3877 | async sync( |
| 3878 | onProgress?: (progress: IndexProgress) => void, |
| 3879 | /** |
| 3880 | * Watcher fast path: the exact project-relative paths the OS reported as |
| 3881 | * changed. When provided, reconciliation runs over ONLY these paths — |
| 3882 | * per-path logic identical to the full walk (stat pre-filter, hash |
| 3883 | * confirm, the #1240 removal/resurrection flow) — skipping the O(repo) |
| 3884 | * scan and tracked-load. Callers must pass undefined whenever the change |
| 3885 | * set is not exactly known (directory removals, event overflow): the full |
| 3886 | * scan-diff remains the ground truth those cases need (#1285). |
| 3887 | */ |
| 3888 | scopedPaths?: string[], |
| 3889 | /** |
| 3890 | * Writer-side WAL pressure valve (#1539). Called after every changed file |
| 3891 | * is stored, when no extraction transaction is open, so a checkpoint can |
| 3892 | * safely catch up before the next file grows the WAL further. |
| 3893 | */ |
| 3894 | backpressure?: () => Promise<void> | null, |
| 3895 | /** Inspect changed inputs before deletion/re-extraction cascades their edges. */ |
| 3896 | onFileChange?: (filePath: string, content?: string) => void |
| 3897 | ): Promise<SyncResult> { |
| 3898 | await initGrammars(); // Initialize WASM runtime (grammars loaded lazily below) |
| 3899 | const startTime = Date.now(); |
| 3900 | let filesChecked = 0; |
| 3901 | let filesAdded = 0; |
| 3902 | let filesModified = 0; |
| 3903 | let filesRemoved = 0; |
| 3904 | let nodesUpdated = 0; |
| 3905 | const changedFilePaths: string[] = []; |
| 3906 | const addedFilePaths: string[] = []; |
| 3907 | // Tracked with no nodes and the reason recorded (over the size limit, a |
| 3908 | // parse or grammar failure): if this sync stores nodes for one, it is new |
| 3909 | // to its importers, so it joins `addedFilePaths` once stored. |
| 3910 | const indexedFromSkip: string[] = []; |
| 3911 | const removedFilePaths: string[] = []; |
| 3912 | // `file\0name` definition pairs for the files this sync touches, sampled |
| 3913 | // BEFORE their nodes are replaced/deleted. Compared against the post-store |
| 3914 | // pairs below to derive `definitionDelta` (CG-33). |
| 3915 | const pairsBefore = new Set<string>(); |
| 3916 | // Importers' import statements, read once per sync for the files it removes. |
| 3917 | const importReader = createImportReader(this.rootDir); |
| 3918 | |
| 3919 | onProgress?.({ |
| 3920 | phase: 'scanning', |
| 3921 | current: 0, |
| 3922 | total: 0, |
| 3923 | }); |
| 3924 | |
| 3925 | const filesToIndex: string[] = []; |
| 3926 | const failedFilePaths: string[] = []; |
| 3927 | // === Filesystem reconcile (git-independent) === |
| 3928 | // The source of truth for "what changed" is the filesystem vs the indexed |
| 3929 | // state — never git. We enumerate the current source files and reconcile |
| 3930 | // each against the DB. A cheap (size, mtime) stat pre-filter skips unchanged |
| 3931 | // files without reading or hashing them, so the expensive read+hash+parse |
| 3932 | // only runs for files that actually changed. This catches edits/adds/deletes |
| 3933 | // whether or not the project uses git, and crucially also catches committed |
| 3934 | // changes from `git pull`/`checkout`/`merge`/`rebase` — which `git status` |
no test coverage detected