15. Project discovery reports, it does not absorb
Date: 2026-10-14
Status
Accepted. Depends on 0014: The XDG config is the single source of truth for projects, which decides where discovery writes a new project. Implements issue #71.
Context
Cerebro has no project discovery. A project exists only if you hand-add it as
a [[projects]] table in ~/.config/cerebro/config.toml, and anything absent
from that file is invisible to the collectors, the journal, TODO search, stats,
and the dashboard:
crates/cerebro-core/src/collectors/mod.rs:28 for project in &config.projects
crates/cerebro/src/main.rs:85 info!("Building all {} projects", config.projects.len())
The failure mode is silence. Nothing signals that a repository exists on
disk and nobody reads it. In the audited state the config hadn’t changed
since Jun 7 while cron built three times a day, and on Sep 20 the
journal reported 1 projects | 0 sessions | 1 commits on a day with commits in
four other repositories. Adding ten active repositories by hand the same day
moved that day’s journal to 5 projects | 3 sessions | 42 commits and project
pages from 41 to 51. The entire gap was one unmaintained section of a text
file. On disk: 95 git repositories under ~/Projects, 65 configured.
The other 30, roughly a third, go unseen by every subsystem.
A naive “scan the directory and add everything” isn’t the fix. The same audit produced five ways a discovery pass goes wrong, all observed on this machine rather than theorized:
- Worktrees double-count.
~/Projectslooks like 101 git repositories, but several are worktrees of projects already tracked (cerebro-*,rpdc-tierA,cortex-theme-refactor,Botface-repairHealthCheck,listsome-example-repair,leptos-jamstack-component-refactor). Treating each as a project counts every commit in the parent more than once. - Upstream clones inflate. Three configured projects were clones with
zero commits by the owner:
bevy(0 of 9,066),rp-hal-boards(0 of 921), andmdbook-journal(0 of 17). Together they contributed 335 of 857 dashboard TODOs, overwhelmingly upstream (FIXME (15321): solve CI failures…). Butbasic-harnessis a genuine collaboration (7 of 14 commits, the rest another author), so you can’t infer ownership from an absent remote or a single author. - Vendored code lands in the TODO count as if it were yours. The
Obsidian vault
notes-jbhreported 424 TODOs, and the top offenders were committed third-party bundles:obsidian-shellcommands/main.js(113), an Obsidian plugin’smain.js(66),github-copilot/main.js(52), plus a nestednode_modules/@github/copilot/sdk/index.js(23).bevyreports 334 or more that belong to upstream..gitignoredoesn’t help. Committers checked the bundles in. - Non-git directories are a real category, not rot. Thirteen configured
entries are plain directories holding content (
gemma-notes,health-notes,llm-eval-notes,no-github-notesat 564 MB and 5,933 markdown files, and others). They fail the git collector withcould not find repositoryevery build. - Empty repositories are noise, not damage. Seven projects have zero
commits and an unborn HEAD (
adventOfCode-2025,BevyFace,curator,hello-leptos-trunk,leptos-tutorial,order,rustlings). The collector emits awarn!per build for each, implying malfunction where there is none.
Decision
cerebro gains a discovery pass that reconciles ~/Projects against the XDG
config and reports the difference, and only writes when told to.
- Scan each immediate subdirectory of a configurable
projects_dir(default~/Projects). - Classify every entry: registered project / unregistered git repository /
worktree of a registered repository / non-git directory / stale config
entry whose
repo_pathno longer exists. - Deduplicate worktrees by
git rev-parse --git-common-dir, comparing against the canonical repository, and attribute each worktree to its parent project. A fixture verifies the attribution, never directory-name matching. - Gate on authorship, not on shape. Discovery proposes a directory as a
project when it has commits by the configured user. Remote owner is a corroborating
signal, never a requirement. The absence of a remote and a single author
must both still admit a project.
basic-harnessis the permanent regression fixture for “a genuine collaboration a naive heuristic would discard”, and the three upstream clones are the fixture for the opposite. - Deny vendored paths in the TODO collector as a prerequisite. Discovery
multiplies the number of scanned directories, and every wrong one becomes
dashboard noise immediately. The collector’s existing git-plumbing deny list
(
is_git_plumbing(),todos.rs:92, from507a292) now extends to vendored roots:.obsidian,node_modules,vendor,dist, andtarget. A regression test records the reason, in the same style as the plumbing fix. This lands before or with discovery, not after. - Non-git directories are first-class. The build accepts a registered
non-git directory for note scanning and keeps it out of the git collector,
so it no longer fails with
could not find repository.no-github-notesis the scale fixture. - Empty repositories are informational, not warnings. Discovery reports
an unborn HEAD in its summary, and the build stops
warn!ing per project. - Report by default.
--sync-configapplies.cerebro discoverprints the classified diff and writes nothing: unregistered repositories, worktrees with their parents, non-git directories, empty repositories, stale entries.cerebro discover --sync-configappends the accepted entries to the XDG config. An opt-in apply is what keeps scratch directories such astest,llm-test,rig-test, andhello-*, plus archive dumps, out of config. - An explicit deny list prunes both report and apply. Directories named in config are never proposed and never written, whether the exclusion is “archived”, “not mine”, or “scratch”. The list is config-extensible and empty by default, matching this project’s preference for explicit exclusions over inferred ones.
cerebro statusreports coverage. It surfaces directories on disk that config doesn’t list, plus stale entries pointing at missing paths, so silent ignorance gets a visible signal.
Consequences
Pros
- The corpus stops being a subset chosen by whoever last edited a text file.
The 30-unregistered-repos gap closes, and recursion has a measurable signal
via
cerebro status: a new project can no longer sit invisible in the journal. - Report-first means discovery is safe to run at any time. Nothing about a read-only run can change what the build produces.
- Worktree and authorship gating protect the numbers the dashboard already shows: no double-counted commits, no upstream engine dominating a TODO list.
- The vendored-path fix improves every existing project, not only discovered ones. It’s worth landing even if discovery slips.
Cons
- Discovery is a new subsystem with its own failure modes, and the interesting ones, worktree attribution and authorship gating, stay invisible until the numbers go wrong. Fixtures are load-bearing, not ceremony.
- The authorship gate needs a configured user identity. Where discovery can’t determine the user, it falls back to reporting only, never to auto-applying.
--sync-configwrites to the file that’s now authoritative per 0014. A bug there edits the source of truth. Append-only semantics and a printed diff before writing bound the damage.
Migration
Current behavior needs no changes. Discovery is additive and read-only until
you pass --sync-config. The intended first run is:
cerebro discover # read-only: what is on disk that config misses
cerebro discover --sync-config # accept the additions into the XDG config
cerebro status # confirm coverage is now 100%
Discovery also reports a rotted config: entries whose paths no longer exist, plus upstream clones with no owner commits. Removing those entries is a manual edit in the first version, because deletion isn’t reversible by a diff a human reads.
Notes
- Issue #71 also found that the generated markdown is a public interface with
at least two consumers, and a format change already broke one silently. The
heading
### [name](...)became a bold name plus an[Open project →](...)link, and the activity line and its em-dash separator changed with it. Pinning that contract with a fixture, including hyphenated and mixed-case names such asadvent-of-code-2025,AddyHomework, andLLM-on-a-budget, is a separate decision. It’s tracked under the same coverage release but not part of discovery policy. - The collector’s assumption that
HEADisrefs/heads/mainwas one of the audit’s early hypotheses. Its author withdrew it after direct inspection: the seven affected projects have zero commits, sorevwalkon an unborn HEAD behaves correctly. This policy treats them as informational for that reason and doesn’t “fix” branch detection. - Discovery writes to the XDG config and the MCP server reads the XDG config
per 0014, so a sync reaches a running
list_projectswithout a second write path.