Company Brain / Curator / Skills
Rebuild Index
- name
- rebuild-index
- description
- Use during a heartbeat, when the Pages table disagrees with the files on disk, after a batch of pages was filed, or when a query against Pages returns something that does not match reality.
The rule
The file always wins. The Pages table is a derived cache. When a row and a page disagree, the index is wrong. Never edit a page so it matches a row — that is corrupting knowledge to satisfy a cache.
Steps
- glob_files across /brain/ excluding /brain/inbox/, /brain/state/, and /brain/reports/.
- Read each page's frontmatter. grep_search is faster than reading whole files when you only need the header.
- Compare against the Pages rows:
- page exists, no row — insert
- row exists, page gone — the page was moved or archived. Find it before deleting the row; a missing page is more likely a move than a deletion
- both exist, fields differ — update the row from the file
- Set indexed_at on everything you touched.
- Flag, do not fix: pages with no owner, canonical pages with no review_due, frontmatter that does not parse, and pages outside every area in /brain/TAXONOMY.md.
Bounded
On a large brain, index one area per pass and record which in the cursor. A full reindex that runs out of budget halfway leaves an index that is wrong in an unpredictable way, which is worse than one that is uniformly a week old.
Do not
- Do not edit page frontmatter to make indexing easier.
- Do not delete a Pages row for a page you merely could not find.
- Do not create pages. You index; Archivist writes.