fix: /cd command reloads agent context including AGENTS.md#291
fix: /cd command reloads agent context including AGENTS.md#291wkramme wants to merge 9 commits intompfaffenberger:mainfrom
Conversation
Fixes issue where /cd command would change the working directory but the agent context would not be refreshed, causing: - AGENTS.md files in new directory to be ignored - Stale working directory in system prompts - Plugin callbacks not re-firing with new context Changes: - Modified /cd command to clear _puppy_rules cache and reload agent - Added agent reload with graceful error handling - Added two comprehensive tests to verify reload behavior This ensures that when users change directories, the agent picks up project-specific AGENTS.md rules and refreshes all context-dependent prompt components.
- Removed direct mutation of agent._puppy_rules from /cd command - reload_code_generation_agent() now handles invalidation internally - Updated test to verify public behavior only (reload called) - Removed brittle assertion on private _puppy_rules field This reduces coupling and makes the code more maintainable.
MagicMock is already imported at the top of the test file. Removed local re-imports in test_cd_reloads_agent_context and test_cd_handles_agent_reload_failure_gracefully.
The /cd command now uses emit_error for reload failures (not emit_warning). Also applied ruff formatting for consistency.
- Fix mock cleanup leak (stop emit_error instead of emit_warning) - Remove 'Warning:' prefix from emit_error message for consistency - Add assertion for emit_info call in test_cd_reloads_agent_context - Update test to expect new error message format (no 'Warning:' prefix)
Applied black-compatible formatting to 3 test files for consistency.
Per CodeRabbit review: - Use assert_called_once() instead of assert called - Check exact prefix with startswith() - Assert original exception text is present - Use call_args[0][0] instead of str(call_args) - Remove redundant 'agent reload failed' dead code check
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 54 minutes and 34 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe pull request modifies the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
code_puppy/command_line/core_commands.py (1)
86-88: Optional cleanup: remove redundantNoneguard afterget_current_agent().Line 87 can be simplified since
get_current_agent()is expected to always return an agent instance.Suggested simplification
current_agent = get_current_agent() - if current_agent: - # reload_code_generation_agent() invalidates cached rules - # and rebuilds prompt/context from the new cwd - current_agent.reload_code_generation_agent() - emit_info("Agent context updated for new directory") + # reload_code_generation_agent() invalidates cached rules + # and rebuilds prompt/context from the new cwd + current_agent.reload_code_generation_agent() + emit_info("Agent context updated for new directory")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code_puppy/command_line/core_commands.py` around lines 86 - 88, The `if current_agent:` guard is redundant because `get_current_agent()` always returns an agent; remove the None check and the unused `current_agent` assignment and call `reload_code_generation_agent()` directly (replace `current_agent = get_current_agent(); if current_agent:` block with a direct `reload_code_generation_agent()` invocation), ensuring any references to `current_agent` in that scope are updated or removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@code_puppy/command_line/core_commands.py`:
- Around line 86-88: The `if current_agent:` guard is redundant because
`get_current_agent()` always returns an agent; remove the None check and the
unused `current_agent` assignment and call `reload_code_generation_agent()`
directly (replace `current_agent = get_current_agent(); if current_agent:` block
with a direct `reload_code_generation_agent()` invocation), ensuring any
references to `current_agent` in that scope are updated or removed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1438de62-151d-4e81-a447-2e293b76740c
📒 Files selected for processing (5)
code_puppy/command_line/core_commands.pytests/agents/test_base_agent_full_coverage.pytests/command_line/test_core_commands_extended.pytests/command_line/test_model_settings_menu_coverage.pytests/test_command_handler.py
Summary
Ensure
/cdfully refreshes agent context so directory-specific instructions are reloaded immediately after changing directories.What changed
/cdcommand flow incore_commands.pyto reload the active agent context after a successful directory change.Why
Previously, changing directories could leave the active agent running with stale context until another action forced a rebuild. This PR makes
/cdimmediately refresh context so AGENTS.md and working-directory-dependent instructions stay accurate.Flow
sequenceDiagram participant User participant CLI as /cd handler participant FS as File System participant Agent as Current Agent User->>CLI: /cd <path> CLI->>FS: Validate directory FS-->>CLI: Exists CLI->>FS: chdir(path) CLI->>Agent: reload_code_generation_agent() Agent-->>Agent: Rebuild system prompt Agent-->>Agent: Re-read AGENTS.md in new cwd CLI-->>User: Success + context updated Note over CLI,User: If reload fails, directory change still succeedsValidation
tests/command_line/test_core_commands_extended.pytests/test_command_handler.pytests/agents/test_base_agent_full_coverage.pytests/command_line/test_model_settings_menu_coverage.pySummary by CodeRabbit
/cdcommand's error handling and user messaging when reloading agent context during directory navigation