You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the CLI is started outside a project (such as in ~) and a project is selected through the Project Picker, project-specific MCP servers and skills were not loaded because the registries remained initialized from the original working directory.
This fix reloads both initializeAgentRegistry() and initializeSkillRegistry() after changing projects, adds debug logging, and clears the cached local-agent state so the new project's .agents/ configuration is picked up correctly.
Changes
Reload registries: In cli/src/index.tsx, invoke initializeAgentRegistry() and initializeSkillRegistry() after updating the project root in handleProjectChange.
Cache invalidation: In cli/src/utils/local-agent-registry.ts, reset cachedAgentsDir and cachedAgentsByMode when reinitializing so directory lookups and the @ menu don't serve stale cache from the launch directory.
Observability: Added a debug log confirming MCP servers and skills were reloaded for the project.
Regression tests: Added cli/src/__tests__/integration/project-change-reload.test.ts covering bug reproduction, MCP and skill reloading, project-to-project switching, and cache clearing.
Testing
Ran the new and affected test suites:
bun test cli/src/__tests__/integration/project-change-reload.test.ts
bun test cli/src/__tests__/integration/local-agents.test.ts
bun test cli/src/commands/__tests__/skill-command.test.ts
bun test sdk/src/__tests__/load-mcp-config.test.ts
Result: 58 tests passed.
Also manually verified the original issue before and after the fix, including switching between projects with different .agents/ configurations.
Good bug fix with a clear root cause: handleProjectChange in cli/src/index.tsx updated projectRoot but never re-ran initializeAgentRegistry()/initializeSkillRegistry(), so switching projects from a non-project cwd (e.g. ~) left the old project's .agents/ config (or none) cached. The two-line cache-clear in local-agent-registry.ts (cachedAgentsByMode.clear(), cachedAgentsDir = null) at the top of initializeAgentRegistry() correctly forces a fresh directory lookup instead of serving stale paths.
The new integration test project-change-reload.test.ts is thorough: it reproduces the bug first (asserting the broken behavior without the fix), then verifies the fix, project-to-project switching, and cache invalidation for custom agents. That's exactly the kind of test coverage this kind of fix needs.
A couple of things worth double-checking before porting:
initializeAgentRegistry/initializeSkillRegistry are called in index.tsx without an import diff shown — confirm they're already imported at the top of that file (likely, since they're used at startup) so this isn't a silent compile break.
Consider whether reloading synchronously in the picker's change handler introduces noticeable UI latency on large .agents/ trees — worth a quick manual check, though probably fine given it already happens at startup.
The debug log is a reasonable addition for observability.
Overall: correct diagnosis, minimal fix, in-scope files, good tests. Recommending as a port candidate.
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
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.
Summary
Fixes #957.
When the CLI is started outside a project (such as in
~) and a project is selected through the Project Picker, project-specific MCP servers and skills were not loaded because the registries remained initialized from the original working directory.This fix reloads both
initializeAgentRegistry()andinitializeSkillRegistry()after changing projects, adds debug logging, and clears the cached local-agent state so the new project's.agents/configuration is picked up correctly.Changes
Reload registries: In
cli/src/index.tsx, invokeinitializeAgentRegistry()andinitializeSkillRegistry()after updating the project root inhandleProjectChange.Cache invalidation: In
cli/src/utils/local-agent-registry.ts, resetcachedAgentsDirandcachedAgentsByModewhen reinitializing so directory lookups and the@menu don't serve stale cache from the launch directory.Observability: Added a debug log confirming MCP servers and skills were reloaded for the project.
Regression tests: Added
cli/src/__tests__/integration/project-change-reload.test.tscovering bug reproduction, MCP and skill reloading, project-to-project switching, and cache clearing.Testing
Ran the new and affected test suites:
Result: 58 tests passed.
Also manually verified the original issue before and after the fix, including switching between projects with different
.agents/configurations.