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

@@ -0,0 +1,79 @@
# Issue ORCH-113: Coordinator API client
## Objective
Implement HTTP client for calling coordinator quality gates from orchestrator service.
## Approach
1. Create CoordinatorClientService in NestJS with proper dependency injection
2. Use native fetch API for HTTP calls (Node.js 18+ built-in)
3. Integrate with ConfigService for COORDINATOR_URL configuration
4. Implement POST /api/quality/check endpoint call
5. Add retry logic for coordinator unavailable scenarios
6. Create comprehensive unit tests with mocked fetch
## API Contract
```typescript
POST /api/quality/check
Request: {
taskId: string,
agentId: string,
files: string[],
diffSummary: string
}
Response: {
approved: boolean,
gate: string,
message?: string,
details?: Record<string, unknown>
}
```
## Progress
- [x] Read requirements from M6-NEW-ISSUES-TEMPLATES.md
- [x] Understand coordinator and orchestrator structure
- [x] Identify coordinator is Python/FastAPI, orchestrator is NestJS
- [x] Create scratchpad
- [x] Add COORDINATOR_URL to orchestrator.config.ts
- [x] Write failing tests for CoordinatorClientService (RED phase)
- [x] Implement CoordinatorClientService (GREEN phase)
- [x] Ensure ≥85% test coverage (96.61% statements, 90% branches, 100% lines)
- [x] Update CoordinatorModule to export the service
- [x] Update AppModule to import CoordinatorModule
- [x] Verify TypeScript compilation succeeds for coordinator files
- [x] Create Gitea issue #248 and close it
## Summary
Successfully implemented ORCH-113 following strict TDD principles. The coordinator API client is fully functional with:
- POST /api/quality/check endpoint integration
- Retry logic with exponential backoff (3 attempts)
- Comprehensive error handling
- 96.61% statement coverage, 90% branch coverage, 100% line coverage
- 15 passing unit tests
- Full NestJS integration via CoordinatorModule
The service is ready for use by ORCH-114 (Quality gate callbacks) and ORCH-115 (Task dispatch).
## Testing
- Mock fetch for all HTTP calls
- Test success scenario (approved=true)
- Test rejection scenario (approved=false)
- Test coordinator unavailable (connection error)
- Test retry logic
- Test invalid responses
- Test timeout scenarios
## Notes
- Coordinator runs on port 8000 (Python/FastAPI)
- Orchestrator runs on port 3001 (NestJS)
- Using native fetch API (available in Node 18+)
- Retry strategy: 3 attempts with exponential backoff
- ConfigService is already set up in app.module.ts
- Need to extend orchestrator.config.ts with coordinatorUrl