feat(#93): implement agent spawn via federation

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>
This commit is contained in:
Jason Woltje
2026-02-03 14:37:06 -06:00
parent a8c8af21e5
commit 12abdfe81d
405 changed files with 13545 additions and 2153 deletions

View File

@@ -1,11 +1,13 @@
# 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
1. **ConflictDetectionService**: NestJS service that:
- Fetches latest changes from remote before push
- Detects merge conflicts using simple-git
@@ -13,6 +15,7 @@ Implement conflict detection service that detects merge conflicts before pushing
- Supports both merge and rebase strategies
### Conflict Detection Strategy
1. Fetch remote branch
2. Try merge/rebase in dry-run mode (or check status after fetch)
3. Detect conflicts by:
@@ -22,6 +25,7 @@ Implement conflict detection service that detects merge conflicts before pushing
4. 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
@@ -46,6 +50,7 @@ Implement conflict detection service that detects merge conflicts before pushing
## 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
@@ -55,6 +60,7 @@ Implementation completed successfully with all acceptance criteria met:
- 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
@@ -65,6 +71,7 @@ Files created/modified:
## Testing Strategy
### Unit Tests (TDD)
1. **No conflicts scenario**:
- Fetch succeeds
- No conflicts detected
@@ -89,6 +96,7 @@ Files created/modified:
- Prevents push if conflicts exist
### Mock Strategy
- Mock simple-git for all git operations
- Mock GitOperationsService where needed
- Test both merge and rebase strategies
@@ -96,6 +104,7 @@ Files created/modified:
## Technical Notes
### Key Methods
```typescript
// Check for conflicts before push
async checkForConflicts(
@@ -118,33 +127,31 @@ async detectConflicts(
```
### Types
```typescript
interface ConflictCheckResult {
hasConflicts: boolean;
conflicts: ConflictInfo[];
strategy: 'merge' | 'rebase';
strategy: "merge" | "rebase";
canRetry: boolean;
}
interface ConflictInfo {
file: string;
type: 'content' | 'delete' | 'add';
type: "content" | "delete" | "add";
ours?: string;
theirs?: string;
}
class ConflictDetectionError extends Error {
constructor(
message: string,
operation: string,
cause?: Error
)
constructor(message: string, operation: string, cause?: Error);
}
```
## Implementation Details
### Git Commands
- `git fetch origin branch` - Fetch latest
- `git merge --no-commit --no-ff origin/branch` - Test merge
- `git merge --abort` - Abort test merge
@@ -152,6 +159,7 @@ class ConflictDetectionError extends Error {
- `git diff --name-only --diff-filter=U` - List conflicted files
### Conflict Detection Logic
1. Save current state
2. Fetch remote
3. Attempt merge/rebase (no commit)
@@ -163,22 +171,26 @@ class ConflictDetectionError extends Error {
## Notes
### Design Decisions
- Use `--no-commit` flag 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
1. Start with TDD: Write failing tests first
2. Implement minimal code to pass tests
3. Refactor for clarity