fix(cli): reload MCP config after project selection - #1179
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.
|
Good bug fix. The root cause tracking is accurate: The test in One thing to double check before porting: Small note: |
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.