Skip to content

fix(cmd): worktree config never writes into the primary; doctor checks the scope the agent loads - #210

Merged
JordanCoin merged 2 commits into
mainfrom
fix/152-109-config-scope
Oct 11, 2026
Merged

JordanCoin merged 2 commits into
mainfrom
fix/152-109-config-scope

Conversation

@JordanCoin

Copy link
Copy Markdown
Owner

Two bugs with one theme: codemap reporting on, or writing to, a location the user is not in.

#152 config from a linked worktree

Sharing .codemap/config.json across worktrees is deliberate (projectpath.Select resolves a linked worktree's setup root to the primary when the primary has a .codemap/), and the scanner loads config through the same config.ConfigPath(root), so scan and config agree. What was wrong:

  • codemap config init inside the worktree wrote into the primary checkout when the primary had .codemap/ but no config.json. initProjectConfig now refuses with <worktree> is a linked worktree; its config lives in the primary checkout, run \codemap config init` in . The guard sits in initProjectConfig, so the self-healing auto-init (EnsureProjectConfig`) is covered too and silently returns false.
  • codemap config show named the primary's path with no explanation. It now prints (shared from primary checkout <primary>; <worktree> is a linked worktree of it), and the missing-config hint says to run init in the primary.

No second resolver was added; both commands read projectpath.Select(root).Source == SourceLinkedWorktree.

Test: TestConfigInitRefusesToWriteIntoPrimaryFromWorktree (real git worktree add --detach; fails on main with "config init from a linked worktree succeeded").

#109 doctor reports OK from a shadowed scope

checkScopedFile reported the first scope that validated. Claude Code loads the first scope that defines a server, valid or not. Validators now wrap "defines no codemap entry" errors (missing codemap MCP server, no MCP servers registered for <root>, missing hooks object, missing <event> hook, missing mcp_servers table) in errScopeUndefined; any other error means the scope is loaded and broken. The walk takes the first defined scope as effective and keeps scanning only to name what it shadows.

Before (issue repro, broken local entry over healthy user entry):

OK   Claude MCP: ~/.claude.json (user scope)

After:

MISS Claude MCP: ~/.claude.json (local scope: unrecognized codemap MCP arguments; repair with `codemap setup --agent claude`); shadows healthy ~/.claude.json (user scope)

It is MISS, not WARN, because the registration the agent actually loads is broken and doctor must exit 1. Hooks keep merge semantics: a scope with hooks but none of codemap's falls through as undefined, exactly as before.

Test: TestRunDoctorReportsBrokenLocalMCPThatShadowsHealthyUserScope (fails on main with the OK line above).

gofmt -l . && go build ./... && go vet ./cmd && go test ./... clean.

Not changed: the Codex MCP scopes get the same walk but no shadow fixture; the issue's suggestion that config show could print the worktree root as well is covered by the shared note.

Fixes #152
Fixes #109

🤖 Generated with Claude Code

https://claude.ai/code/session_01NRaBgKRAZMX9hjbkkefA7T

…octor checks the scope the agent actually loads

#152: a linked worktree reads the primary checkout's .codemap/config.json
by design (one policy per repository), but `config init` run inside the
worktree wrote into that other checkout and `config show` named a path the
user was not in without saying why. initProjectConfig now refuses when the
setup root is a different checkout (covering `config init` and the
self-healing auto-init), and `config show` prints which primary the config
is shared from.

#109: checkScopedFile reported the first scope that validated, while Claude
Code loads the first scope that defines a server, valid or not. A broken
local entry was loaded by the agent while doctor said OK from the healthy
user entry beneath it. Validators now wrap "defines no entry" errors in
errScopeUndefined; the walk treats the first defined scope as effective,
reports MISS on it when broken, and names the healthy lower scope it
shadows.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NRaBgKRAZMX9hjbkkefA7T
Copilot AI balanced review requested due to automatic review settings October 11, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@JordanCoin
JordanCoin merged commit 3c4da42 into main Oct 11, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants