Implements FED-010: Agent Spawn via Federation feature that enables spawning and managing Claude agents on remote federated Mosaic Stack instances via COMMAND message type. Features: - Federation agent command types (spawn, status, kill) - FederationAgentService for handling agent operations - Integration with orchestrator's agent spawner/lifecycle services - API endpoints for spawning, querying status, and killing agents - Full command routing through federation COMMAND infrastructure - Comprehensive test coverage (12/12 tests passing) Architecture: - Hub → Spoke: Spawn agents on remote instances - Command flow: FederationController → FederationAgentService → CommandService → Remote Orchestrator - Response handling: Remote orchestrator returns agent status/results - Security: Connection validation, signature verification Files created: - apps/api/src/federation/types/federation-agent.types.ts - apps/api/src/federation/federation-agent.service.ts - apps/api/src/federation/federation-agent.service.spec.ts Files modified: - apps/api/src/federation/command.service.ts (agent command routing) - apps/api/src/federation/federation.controller.ts (agent endpoints) - apps/api/src/federation/federation.module.ts (service registration) - apps/orchestrator/src/api/agents/agents.controller.ts (status endpoint) - apps/orchestrator/src/api/agents/agents.module.ts (lifecycle integration) Testing: - 12/12 tests passing for FederationAgentService - All command service tests passing - TypeScript compilation successful - Linting passed Refs #93 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
5.2 KiB
5.2 KiB
ORCH-112: Conflict Detection
Objective
Implement conflict detection service that detects merge conflicts before pushing to remote. This is the final git integration feature for Phase 3.
Approach
Architecture
- ConflictDetectionService: NestJS service that:
- Fetches latest changes from remote before push
- Detects merge conflicts using simple-git
- Returns detailed conflict information
- Supports both merge and rebase strategies
Conflict Detection Strategy
- Fetch remote branch
- Try merge/rebase in dry-run mode (or check status after fetch)
- Detect conflicts by:
- Checking git status for conflicted files
- Parsing merge output for conflict markers
- Checking for unmerged paths
- Return structured conflict information with file paths and details
Integration Points
- Uses GitOperationsService for basic git operations
- Will be called by orchestrator before push operations
- Provides retry capability with different strategies
Progress
- Review requirements from ORCH-112
- Examine existing git services (GitOperationsService, WorktreeManagerService)
- Identify types structure and patterns
- Create scratchpad
- Write tests for ConflictDetectionService (TDD - RED)
- Implement ConflictDetectionService (TDD - GREEN)
- Refactor implementation (TDD - REFACTOR)
- Add types to types/conflict-detection.types.ts
- Export from types/index.ts
- Update git.module.ts to include ConflictDetectionService
- Update git/index.ts exports
- Verify tests pass with ≥85% coverage (95.77% achieved)
- Create Gitea issue
- Close Gitea issue with completion notes
Completion Summary
Implementation completed successfully with all acceptance criteria met:
- ConflictDetectionService implemented with full TDD approach
- Supports both merge and rebase strategies
- Comprehensive error handling with ConflictDetectionError
- 18 unit tests covering all scenarios
- Coverage: 95.77% (exceeds 85% requirement)
- Proper cleanup after conflict detection
- Integrated into GitModule and exported
Files created/modified:
- apps/orchestrator/src/git/conflict-detection.service.ts
- apps/orchestrator/src/git/conflict-detection.service.spec.ts
- apps/orchestrator/src/git/types/conflict-detection.types.ts
- apps/orchestrator/src/git/types/index.ts (updated)
- apps/orchestrator/src/git/git.module.ts (updated)
- apps/orchestrator/src/git/index.ts (updated)
Testing Strategy
Unit Tests (TDD)
-
No conflicts scenario:
- Fetch succeeds
- No conflicts detected
- Returns clean status
-
Merge conflicts detected:
- Fetch succeeds
- Merge shows conflicts
- Returns conflict details with file paths
-
Rebase conflicts detected:
- Fetch succeeds
- Rebase shows conflicts
- Returns conflict details
-
Fetch failure:
- Remote unavailable
- Throws appropriate error
-
Check before push:
- Integration with conflict detection
- Prevents push if conflicts exist
Mock Strategy
- Mock simple-git for all git operations
- Mock GitOperationsService where needed
- Test both merge and rebase strategies
Technical Notes
Key Methods
// Check for conflicts before push
async checkForConflicts(
localPath: string,
remote: string = 'origin',
branch: string = 'develop',
strategy: 'merge' | 'rebase' = 'merge'
): Promise<ConflictCheckResult>
// Fetch latest from remote
async fetchRemote(
localPath: string,
remote: string = 'origin'
): Promise<void>
// Detect conflicts in current state
async detectConflicts(
localPath: string
): Promise<ConflictInfo[]>
Types
interface ConflictCheckResult {
hasConflicts: boolean;
conflicts: ConflictInfo[];
strategy: "merge" | "rebase";
canRetry: boolean;
}
interface ConflictInfo {
file: string;
type: "content" | "delete" | "add";
ours?: string;
theirs?: string;
}
class ConflictDetectionError extends Error {
constructor(message: string, operation: string, cause?: Error);
}
Implementation Details
Git Commands
git fetch origin branch- Fetch latestgit merge --no-commit --no-ff origin/branch- Test mergegit merge --abort- Abort test mergegit status --porcelain- Check for conflictsgit diff --name-only --diff-filter=U- List conflicted files
Conflict Detection Logic
- Save current state
- Fetch remote
- Attempt merge/rebase (no commit)
- Check status for "UU" markers (unmerged)
- Parse conflict information
- Abort merge/rebase
- Return conflict details
Notes
Design Decisions
- Use
--no-commitflag to test merge without committing - Support both merge and rebase strategies
- Provide detailed conflict information for agent retry
- Clean up after detection (abort merge/rebase)
Error Handling
- GitOperationError for git command failures
- ConflictDetectionError for detection-specific issues
- Return structured errors for agent consumption
Dependencies
- simple-git library (already used in GitOperationsService)
- NestJS @Injectable decorator
- Logger for debugging
Next Steps
- Start with TDD: Write failing tests first
- Implement minimal code to pass tests
- Refactor for clarity
- Ensure coverage ≥85%
- Create and close Gitea issue