plans/2025-09-08-agent-loader-cwd-extension-v1.md
Extend the AgentLoaderService to load agents from both the existing {HOME}/forge/agents/ directory and an additional CWD/.forge/agents/ directory, combining agents from both sources while maintaining the current architecture patterns and safety guarantees.
Task 1. Add CWD agent path method to Environment
agent_cwd_path() method to the Environment struct in crates/forge_domain/src/env.rsPathBuf::from(".forge/agents") to point to the current working directoryagent_path() method but use current directory as baseTask 2. Update EnvironmentInfra trait usage documentation
Task 3. Extend AgentLoaderService init method
init() method in crates/forge_services/src/agent_loader.rs to load from three sources instead of twoinit_default())init_custom())init_cwd()) method callTask 4. Implement init_cwd method
init_cwd() private method to AgentLoaderServiceself.infra.get_environment().agent_cwd_path() to get the CWD agent directoryself.infra.exists() like existing custom agent logicDirectoryReaderInfra::read_directory_files() with "*.md" patternparse_agent_iter() functionTask 5. Combine agent sources in init method
init() method to combine all three sources: built-in, custom (global), and CWDVec::extend() pattern like existing implementationTask 6. Add comprehensive error context
Task 7. Handle agent ID conflicts
Task 8. Add unit tests for agent_cwd_path
Environment::agent_cwd_path() returns correct path structureagent_path()Task 9. Add unit tests for CWD agent loading
crates/forge_services/src/fixtures/ for CWD agent scenarios.forge/agents/ directoryTask 10. Add integration tests
Task 11. Update service documentation
AgentLoaderService to reflect multiple directory supportTask 12. Run comprehensive testing
cargo insta test --accept --unreferenced=delete for service tests{HOME}/forge/agents/ directory.forge/agents/ directory when it exists.forge/agents/ directory doesn't cause errors or prevent other agent loadingAgent ID conflicts between directories Mitigation: Implement clear precedence rules with CWD agents overriding global agents
Performance impact from additional directory scanning Mitigation: Maintain existing caching strategy and parallel loading patterns
Breaking changes to existing agent loading behavior Mitigation: Extend functionality additively without modifying existing load paths
Directory permission or access issues for CWD
Mitigation: Use same graceful error handling pattern as existing custom agent loading
Inconsistent agent quality between global and CWD sources Mitigation: Apply same parsing and validation logic to all agent sources
Configuration-driven approach: Add agent directory paths to forge.yaml configuration file, allowing users to specify custom agent directories explicitly
Environment variable approach: Support FORGE_AGENT_PATHS environment variable for colon-separated list of agent directories
Recursive directory scanning: Modify existing agent loading to recursively scan subdirectories within agent paths
Agent registry pattern: Implement a more sophisticated agent discovery system with registration and dependency management