Skip to content

Centralize agent configuration resolution logic#229

Merged
subsy merged 2 commits intomainfrom
claude/investigate-issue-220-MQXTJ
Jan 26, 2026
Merged

Centralize agent configuration resolution logic#229
subsy merged 2 commits intomainfrom
claude/investigate-issue-220-MQXTJ

Conversation

@subsy
Copy link
Owner

@subsy subsy commented Jan 26, 2026

Summary

This PR refactors agent configuration resolution to use a centralized getDefaultAgentConfig() function across all commands and components. This eliminates duplicate logic for determining which agent to use and ensures consistent handling of agent configuration, including command overrides and environment variable settings.

Key Changes

  • Exported getDefaultAgentConfig() function from src/config/index.ts to make it available throughout the codebase. This function implements a clear precedence order for agent selection:

    1. CLI override (options.agent)
    2. Shorthand storedConfig.agent field
    3. defaultAgent setting
    4. Agent marked with default: true in agents array
    5. First agent in agents array
    6. Built-in claude plugin
  • Updated doctor.ts command to use getDefaultAgentConfig() instead of inline agent selection logic. Now properly passes the full agent configuration (including command, envExclude, envPassthrough) to registry.getInstance().

  • Updated info.ts command to use getDefaultAgentConfig() for consistent agent resolution. Added command field to the SystemInfo.agent interface and displays custom command paths in the formatted output.

  • Updated run.tsx and RunApp.tsx to accept and pass through the agentCommand property. The display name now shows the custom command in parentheses when configured (e.g., "claude (claude-glm)").

  • Simplified environment variable resolution in both doctor.ts and info.ts by relying on the pre-resolved settings in agentConfig rather than manually merging agent-level and top-level settings.

Implementation Details

  • The getDefaultAgentConfig() function returns an AgentPluginConfig object that includes all necessary configuration: name, plugin, options, command, envExclude, and envPassthrough.
  • Agent-level environment settings now properly take precedence over top-level settings through the centralized function.
  • The refactoring maintains backward compatibility while reducing code duplication and improving maintainability.

Summary by CodeRabbit

  • New Features

    • Custom agent commands now configurable per agent within configuration
    • Agent-level commands take precedence over top-level configuration settings
    • Custom agent command paths now displayed in system information output and user interface
    • Enhanced default agent selection mechanism for agent configuration arrays
  • Tests

    • Added tests for agent configuration propagation and command precedence scenarios

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes #220 - Custom Claude Code command not being used.

Changes:
- Export getDefaultAgentConfig() from config/index.ts for reuse
- Update doctor.ts to use centralized config resolution (includes command)
- Update info.ts to use centralized config resolution and display command
- Add agentCommand prop to RunApp and RunAppWrapper components
- Display custom command in brackets in UI (e.g., "claude (claude-glm)")

The issue was that diagnostic commands (doctor, info) were manually
building agent configs without checking the [[agents]] array for
agents with default=true and their custom command settings.

Now all agent config resolution uses the centralized getDefaultAgentConfig()
which properly:
1. Checks CLI override
2. Checks shorthand agent field
3. Checks stored defaultAgent
4. Finds agent with default: true in agents array
5. Falls back to first agent or built-in claude
@vercel
Copy link

vercel bot commented Jan 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
ralph-tui Ignored Ignored Preview Jan 26, 2026 5:17pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

Walkthrough

This pull request centralises agent command configuration by exporting getDefaultAgentConfig as a public API and propagating per-agent command settings through the doctor, info, and run command flows. The changes thread the agent command value from configuration resolution through agent instantiation and into the TUI display layer.

Changes

Cohort / File(s) Summary
Agent Configuration Core
src/config/index.ts
Exports getDefaultAgentConfig function to public API with expanded JSDoc documentation detailing resolution order; enables centralised agent config resolution across commands.
Doctor Command
src/commands/doctor.ts, src/commands/doctor.test.ts
Uses centralised getDefaultAgentConfig to resolve agent configuration; passes full agentConfig object to registry.getInstance instead of manual construction; updates error messaging and environment exclusion reporting to reference agent config fields. Adds test cases verifying agent command precedence and config propagation.
Info Command
src/commands/info.ts, src/commands/info.test.ts
Integrates getDefaultAgentConfig for centralized agent resolution; adds optional command?: string field to SystemInfo.agent; switches environment exclusion reporting to use agentConfig.envPassthrough and agentConfig.envExclude; updates formatSystemInfo to display custom agent command when present. Extends tests to verify agent command collection and display.
Run Command & UI
src/commands/run.tsx, src/tui/components/RunApp.tsx
Adds optional agentCommand?: string prop to RunAppWrapperProps interface and threads it through component hierarchy from configuration to RunApp; enhances local agent display logic to show custom command in parentheses (e.g., "claude (claude-glm)") when present.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 The config now speaks with unified voice,
Agent commands thread through each choice,
From doctor to info to run's grand display,
Commands hop centre-stage, no delay!
Centralised wisdom, the path made clear— 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change—centralising agent configuration resolution logic—which is the primary refactoring across multiple files in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 57.89474% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.93%. Comparing base (efd1ff6) to head (4facc45).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/commands/doctor.ts 42.10% 11 Missing ⚠️
src/commands/run.tsx 0.00% 3 Missing ⚠️
src/commands/info.ts 86.66% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   44.93%   44.93%   -0.01%     
==========================================
  Files          84       84              
  Lines       24475    24479       +4     
==========================================
+ Hits        10998    10999       +1     
- Misses      13477    13480       +3     
Files with missing lines Coverage Δ
src/config/index.ts 54.28% <100.00%> (+1.22%) ⬆️
src/commands/info.ts 76.58% <86.66%> (-0.64%) ⬇️
src/commands/run.tsx 8.27% <0.00%> (-0.02%) ⬇️
src/commands/doctor.ts 78.80% <42.10%> (-3.17%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Adds tests for the new centralized getDefaultAgentConfig usage:

doctor.test.ts:
- Test that agents from [[agents]] array with default=true and command are used
- Test that agent-level command takes precedence over top-level command

info.test.ts:
- Test that agents from [[agents]] array with default=true are resolved
- Test that custom command is included in SystemInfo
- Test that command is displayed in formatSystemInfo output
- Test that command is undefined when not configured
@subsy
Copy link
Owner Author

subsy commented Jan 26, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@subsy subsy merged commit 07d8bc8 into main Jan 26, 2026
9 checks passed
@subsy subsy deleted the claude/investigate-issue-220-MQXTJ branch January 26, 2026 21:22
sakaman pushed a commit to sakaman/ralph-tui that referenced this pull request Feb 15, 2026
…MQXTJ

Centralize agent configuration resolution logic
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.

2 participants

Comments