tonydzi
## What happens `index_notes.py` collects notes with `sorted(notes_dir.rglob('*.md'))` (line 51). `rglob` descends into dot-directories, so on a real Obsidian vault — the exact audience of this repo — the index fills with files that are not notes, and **stale copies of a note compete with the live one at retrieval time**. ## Repro ```python from pathlib import Path import tempfile d = Path(tempfile.mkdtemp()) (d / "real.md").write_text("real note") (d / ".stversions").mkdir(); (d / ".stversions" / "real~20260701.md").write_text("OLD VERSION") (d / "real.sync-conflict-20260801-ABC.md").write_text("CONFLICT COPY") (d / ".obsidian").mkdir(); (d / ".obsidian" / "cache.md").write_text("plugin junk") (d / ".git").mkdir(); (d / ".git" / "COMMIT_EDITMSG.md").write_text("git junk") print(sorted(p.relative_to(d).as_posix() for p in d.rglob("*.md"))) ``` ``` ['.git/COMMIT_EDITMSG.md', '.obsidian/cache.md', '.stversions/real~20260701.md', 'real.md', 'real.sync-conflict-20260801-ABC.md'] ``` 5 files indexed, 1 of them an actual note. Anyone syncing a vault with Syncthing has both `.stversions/` and `*.sync-conflict-*` files; anyone using Obsidian has `.obsidian/`. Why it bites: an old version of a note is *semantically almost identical* to the live one, so it lands next to it in the top-K and quietly eats a retrieval slot with outdated content. The answer looks right and is stale. ## Second, smaller bug in the same line Line 53 reads with `errors='ignore'`, which also swallows the UTF-8 BOM: ```python Path("bom.md").write_bytes(b"\xef\xbb\xbf---\ntitle: x\n---\nbody") Path("bom.md").read_text(encoding="utf-8", errors="ignore")[:12] # '---\ntitle: ' ``` The leading `` means the first line is not `---`, so any frontmatter parser downstream sees the note as having no frontmatter. `encoding="utf-8-sig"` handles this correctly. ## Shape of the fix - Skip dot-directories while walking, and skip `*.sync-conflict-*` by name. - Read with `encoding="utf-8-sig"`. - Make the exclusion list overridable (env var, consistent with the repo's env-only configuration) — someone will legitimately want to index a hidden folder. ## Definition of done - The repro above indexes exactly `real.md`. - A test with a synthetic tree covering: dot-dir, sync-conflict name, BOM file, normal note. - `python index_notes.py <dir>` still prints the same summary line for a clean directory. Comment "claiming this" to take it — yours for 7 days.