Skip to content

fix: unify MCP and settings pipelines in cache build#8

Merged
wpfleger96 merged 2 commits intomainfrom
fix/config-status-mcp-awareness
Apr 30, 2026
Merged

fix: unify MCP and settings pipelines in cache build#8
wpfleger96 merged 2 commits intomainfrom
fix/config-status-mcp-awareness

Conversation

@wpfleger96
Copy link
Copy Markdown
Owner

@wpfleger96 wpfleger96 commented Apr 30, 2026

ai-agent-rules install and install_mcps wrote to the same agent config files through independent pipelines with no coordination. This caused status to show false-positive diffs for amp, codex, and gemini after every install — the cache had settings but not MCPs, so the live files (which had MCPs added by install_mcps) always looked out of sync.

The fix makes the settings cache the single source of truth for what each agent config file should contain. A _merge_managed_mcps() hook now runs at the end of build_merged_settings() to reconcile managed MCPs into the cache — adding, updating, and removing stale entries — so the cache and the live file are always consistent. A Codex-specific subtlety (tracking section vs. inline markers) required reading managed-entry identity from [_ai_agent_rules_managed].names rather than per-entry _managedBy fields.

MCP keys that need to be preserved across cache rebuilds (mcp_settings_key, mcp_tracking_key) are now derived dynamically from each agent's MCPManager via _effective_preserved_fields, rather than manually added to each agent's preserved_fields. This prevents the class of bugs where a new agent's MCP key is missed (which happened with Codex's mcp_servers and _ai_agent_rules_managed during initial implementation).

Several related UX issues resolved in the same pass:

  • status diffs for non-symlink JSON files (amp, gemini) now normalize formatting before comparing, eliminating false diffs from whitespace differences
  • install_mcps returns ALREADY_INSTALLED and skips file writes when nothing changed
  • MCP install output now shows per-agent labels instead of 5x unlabeled "MCPs installed 1"
  • _merge_managed_mcps guards against non-dict MCP entries to avoid AttributeError on malformed user configs
  • Tool install output (statusline) moved to after the profile header in install output
  • skipAutoPermissionPrompt added to Claude's base settings alongside skipDangerousModePermissionPrompt
  • work.yaml profile model corrected to opus[1m] to stop cache rebuilds overwriting the 1M context variant

wpfleger96 and others added 2 commits April 30, 2026 17:23
Two independent pipelines (build_merged_settings and install_mcps) wrote
to the same agent config files without coordination, causing status to
show false-positive diffs for amp, codex, and gemini. The cache now
represents the complete expected file state by merging managed MCPs
during build_merged_settings via a _merge_managed_mcps hook.

Also fixes: MCP install output missing per-agent labels, amp settings.json
formatting mismatch, tool install output appearing before profile header,
Claude Code UI settings (skipAutoPermissionPrompt) lost on cache rebuild,
and work profile model variant (opus vs opus[1m]).
Codex's mcp_settings_key ("mcp_servers") and mcp_tracking_key
("_ai_agent_rules_managed") weren't in preserved_fields, so
get_cache_diff still produced false-positive diffs after the MCP/cache
unification — the same class of bug fixed for Amp and Gemini.

Rather than manually adding MCP keys to each agent's preserved_fields
(which is fragile and caused the Codex omission), adds an
_effective_preserved_fields property that dynamically extends the
static list with MCP keys from the agent's MCPManager. Also guards
_merge_managed_mcps against non-dict MCP entries, and restores dim
ALREADY_INSTALLED output with per-agent labels.
@wpfleger96 wpfleger96 merged commit aabb6a0 into main Apr 30, 2026
4 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

Development

Successfully merging this pull request may close these issues.

1 participant