Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

14. The XDG config is the single source of truth for projects

Date: 2026-10-14

Status

Accepted. Amends 0011: XDG as default config location, which settled config resolution for the command-line tool and the TUI but left the MCP server reading a second file, and didn’t confront that the second file is a project list, not a data pointer.

Context

0011 moved the command-line tool and the TUI to an XDG-first resolution order and stated that the MCP server was “unchanged” because CORTEX_PATH there “serves a different purpose (data dir, not config)”. The second half of that sentence is true, the first isn’t. The MCP server does more than find generated content with CORTEX_PATH. Two of its tools read project configuration out of that directory:

crates/cerebro-core/src/queries/projects.rs:70   let config_path = cortex_path.join("config.toml");
crates/cerebro-core/src/queries/todos.rs:49,60   let config_path = cortex_path.join("config.toml");

The server resolves its cortex_path in crates/cerebro-mcp/src/main.rs:12 from CORTEX_PATH, falling back to ~/Projects/cortex. So the command-line tool and the TUI build from ~/.config/cerebro/config.toml while list_projects and search_todos read ~/Projects/cortex/config.toml. Two files, two update paths, two answers to “what are my projects”.

That’s not theoretical. Issue #71’s audit found the two copies disagreed by a factor of three: the cortex copy listed 21 projects, the XDG copy 60 at the time, 69 after the September sync. A consumer calling list_projects over MCP got a third of the world that cerebro build was actually building. Because the cortex copy is a tracked file in the cortex repository, the drift had a second consequence: project truth lived in two repositories, and the one the MCP server read was the one no build step wrote.

The discovery work for #71 makes this load-bearing rather than merely untidy. Discovery has to write its reconciled project list somewhere, and if the command-line tool and the MCP server disagree about where it lives, discovery would fix one view of the world while leaving the other stale. That’s the exact failure the feature exists to remove.

Decision

The XDG config, ~/.config/cerebro/config.toml as resolved by 0011, is the single source of truth for project configuration, for every binary: cerebro, cerebro-tui, and cerebro-mcp.

  1. The MCP server resolves configuration through the same resolver the command-line tool uses, in the same order: the XDG path first, CORTEX_PATH as the legacy fallback, and ./config.toml last. It doesn’t resolve through its cortex data path. Concretely, list_projects and search_todos stop reading cortex_path.join("config.toml") and take a resolved config path instead.
  2. CORTEX_PATH keeps its current, narrow job: locating the cortex data directory, where generated content/ lives. read_project, read_journal, read_today, read_intent, and get_stats read content only: output that cerebro generates, not configuration.
  3. ~/Projects/cortex/config.toml stops being a configuration source. The file may remain in the cortex repository as a copy, but nothing reads it to decide what a project is. It’s no longer authoritative. Don’t edit it to change behavior.
  4. If both an XDG config and a cortex-directory config exist and differ, the XDG config wins and the server logs the divergence at warn! once at startup, naming both paths. Silent precedence would trade one confusion for another.

The three binaries call one resolver instead of carrying three copies of the logic. The function that 0011 added to crates/cerebro/src/main.rs and crates/cerebro-tui/src/bin/cerebro-tui.rs moves into cerebro-core, and all three binaries call it, so the order can’t drift apart again.

Consequences

Pros

  • list_projects over MCP and cerebro build describe the same projects. The 21-vs-60 class of drift becomes impossible by construction rather than by discipline.
  • Project truth lives in exactly one repository. The cortex repository becomes output-only, which is what its name implies.
  • Discovery, the work of #71, has one write target and one read target, so a reconciled project list is immediately consistent across the command-line tool, the TUI, and the MCP server.
  • One resolver in cerebro-core means a future fourth binary inherits the correct behavior instead of copying it.

Cons

  • This is a behavior change for anyone whose cortex-directory config was the one kept current. Their list_projects output changes on upgrade.
  • The resolver moves across a crate boundary (cerebro → cerebro-core), touching both cerebro entry points and the MCP entry point in one change. It’s a small amount of code with a wide blast radius.
  • A stale cortex config left on disk becomes dead weight that looks live. The startup warn! mitigates this but doesn’t delete it.

Migration

Bring the cortex-copy projects into XDG, then let the cortex file fall dormant:

# XDG is canonical; make sure it is the superset.
# Compare the two before deleting anything:
diff <(grep '^name' ~/.config/cerebro/config.toml | sort) \
     <(grep '^name' ~/Projects/cortex/config.toml | sort)

# If the cortex copy has entries XDG lacks, add them to XDG (or run
# `cerebro discover --sync-config` once #71 lands, which reconciles XDG
# against what is actually on disk).

Users who only ever had an XDG config need no change. The expected direction of the merge is XDG-wards: in the audited state XDG already held the larger, more current list.

Notes

  • This decision doesn’t affect get_stats, which counts projects from the generated content/projects/ directory rather than from config. That’s a third, implicit source of “project count” and #71 handles it by making cerebro status report disk-versus-config coverage explicitly.
  • CORTEX_PATH appearing in both a data role and a legacy config role is 0011’s doing. This record leaves it as it is. The point here is only that the authoritative config never lives under the data path.
  • If you keep a cortex-directory config for convenience, generate it from the XDG config rather than hand-editing it. That’s a follow-up, not part of this decision.