fix(cli): reload MCP config after project selection - #1179
Open
luantaraschi wants to merge 1 commit into
Open
Conversation
Picking a different project changed the working directory, moved the project root and reset the client, but never re-scanned `.agents/` for the new directory. `cachedAgentsDir` and `cachedAgentsByMode` in the local agent registry kept serving the launch directory, so the selected project's MCP servers and local agents never reached the base agent definition. Consolidates the chdir, project root, registry reload and client reset into `activateProject()`, and clears the two cwd-derived caches before `initializeAgentRegistry()` refreshes the rest.
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.
Recreated from #966, which GitHub auto-closed when this repository's history was rewritten. Same change, rebased onto the new
mainatd4902003. Fixes #957.Picking a different project through the project picker changes the working directory, moves the project root and resets the client, but never re-scans
.agents/for the new directory.cachedAgentsDirandcachedAgentsByModeinlocal-agent-registry.tsgo on serving the launch directory, so the selected project's MCP servers and local agents never reach the base agent definition.handleProjectChangeincli/src/index.tsxhad the chdir,setProjectRootandresetCodebuffClientinline. This moves that sequence intoactivateProject()inproject-picker.tsand puts the registry reload in the middle of it, so the ordering lives in one place instead of being duplicated at the call site.reloadLocalAgentRegistry()clears onlycachedAgentsDirandcachedAgentsByMode, and that is deliberate. The module keeps five mutable caches. The other three,userAgentsCache,userAgentFilePathsandmcpServersCache, are reassigned byinitializeAgentRegistry()on both its success and failure paths,mcpServersCachefromloadMCPConfigSync(), which reads the cwd. SogetLoadedMCPServers()is covered as long as the chdir happens first. The two derived ones are the only ones nothing else resets.The test writes real
.agents/*.tsandmcp.jsonfiles into temporary launch and project directories, warms the caches in the launch project, switches throughactivateProject(), then asserts the selected project supplies the agent directory, the local agent list, the MCP server and the base agent definition, with the launch project's agent gone. A second case covers the{ reloadAgentRegistry: false }skip path, where the chdir and project root still move but the launch project's agent is still the one served. I checked that case earns its place by makingactivateProjectreload unconditionally: it is the only test that then fails.Validation on this head:
Those 10 are the same 10 a clean checkout of
mainproduces, allreact-dom/serverdeclarations in component tests this change does not touch. Counted both ways to be sure.