Repository navigation
fix(cmd): worktree config never writes into the primary; doctor checks the scope the agent loads - #210
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jsonacross worktrees is deliberate (projectpath.Selectresolves a linked worktree's setup root to the primary when the primary has a.codemap/), and the scanner loads config through the sameconfig.ConfigPath(root), so scan and config agree. What was wrong:codemap config initinside the worktree wrote into the primary checkout when the primary had.codemap/but noconfig.json.initProjectConfignow refuses with<worktree> is a linked worktree; its config lives in the primary checkout, run \codemap config init` in. The guard sits ininitProjectConfig, so the self-healing auto-init (EnsureProjectConfig`) is covered too and silently returns false.codemap config shownamed 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(realgit worktree add --detach; fails on main with "config init from a linked worktree succeeded").#109 doctor reports OK from a shadowed scope
checkScopedFilereported 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) inerrScopeUndefined; 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):
After:
It is MISS, not WARN, because the registration the agent actually loads is broken and
doctormust 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 showcould 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