plans/2025-06-07-tool-service-migration-v1.md
Migrate all tools from direct infrastructure dependencies to service-based architecture where each tool has a corresponding service and tools become thin wrappers that make single service calls. This will improve testability, maintainability, and follow clean architecture principles.
crates/forge_services/src/tools/fs/file_info.rscrates/forge_services/src/tools/fs/fs_find.rscrates/forge_services/src/tools/fs/fs_list.rscrates/forge_services/src/tools/fs/fs_read.rscrates/forge_services/src/tools/fs/fs_remove.rscrates/forge_services/src/tools/fs/fs_undo.rscrates/forge_services/src/tools/fs/fs_write.rscrates/forge_services/src/tools/fetch.rscrates/forge_services/src/tools/followup.rscrates/forge_services/src/tools/patch.rscrates/forge_services/src/tools/shell.rscrates/forge_services/src/tools/registry.rscrates/forge_services/src/tools/mod.rscrates/forge_services/src/crates/forge_services/src/mod.rs (new)crates/forge_services/src/fs_read_service.rs (new - template example)crates/forge_services/src/mod.rscrates/forge_app/src/services.rscrates/forge_services/src/forge_services.rscrates/forge_services/src/tools/fs/fs_read.rscrates/forge_services/src/tools/registry.rsdocs/tool-service-migration-template.md (new)crates/forge_services/src/file_info_service.rs (new - following FSRead pattern)crates/forge_services/src/fs_find_service.rs (new - following FSRead pattern)crates/forge_services/src/fs_list_service.rs (new - following FSRead pattern)crates/forge_services/src/fs_remove_service.rs (new - following FSRead pattern)crates/forge_services/src/fs_undo_service.rs (new - following FSRead pattern)crates/forge_services/src/fs_write_service.rs (new - following FSRead pattern)crates/forge_services/src/fetch_service.rs (new - following FSRead pattern)crates/forge_services/src/followup_service.rs (new - following FSRead pattern)crates/forge_services/src/patch_service.rs (new - following FSRead pattern)crates/forge_services/src/shell_service.rs (new - following FSRead pattern)Track the progress of migrating each tool to service-based architecture:
Each tool migration should follow the FSRead template pattern and include:
crates/forge_services/src/Note: FSRead serves as the template example demonstrating the generic migration pattern. All other tools should follow the exact same pattern established by the FSRead implementation.
Critical Requirements:
crates/forge_services/src/ directorycrates/forge_services/src/Risk: Modifying tool constructors and registration could break existing code that depends on current tool instantiation patterns. Mitigation: Maintain backward compatibility by keeping existing tool constructors while adding service-based alternatives. Use feature flags or gradual migration approach.
Risk: Adding service layer could introduce circular dependencies or complex dependency injection chains. Mitigation: Design services to depend only on Infrastructure traits, not on other services. Keep service interfaces focused and minimal.
Risk: Additional service layer could introduce performance overhead through extra abstraction. Mitigation: Ensure services are lightweight wrappers around infrastructure calls. Profile critical paths to verify no significant performance impact.
Risk: Mocking services for tool tests could become more complex than current infrastructure mocking. Mitigation: Create standardized service mocks and test utilities. Ensure service interfaces are designed for easy testing.
Risk: Partial migration could result in inconsistent architecture with some tools using services and others using infrastructure directly. Mitigation: Complete migration of all core tools before considering the migration complete. Document clear guidelines for future tool development.