Files
stack/docs/scratchpads/orch-110-git-ops.md
Jason Woltje 12abdfe81d 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>
2026-02-03 14:37:06 -06:00

2.6 KiB

ORCH-110: Git Operations (clone, commit, push)

Objective

Implement git operations service using simple-git library to support agent git workflows.

Acceptance Criteria

  • src/git/git-operations.service.ts implemented
  • Clone repository
  • Create branch
  • Commit changes with message
  • Push to remote
  • Git config (user.name, user.email from environment)
  • NestJS service with proper dependency injection
  • Comprehensive unit tests following TDD principles
  • Mock simple-git for unit tests (no actual git operations)
  • Test coverage >= 85%

Approach

Following TDD (Red-Green-Refactor):

  1. RED: Write failing tests first

    • Test git config setup
    • Test clone repository
    • Test create branch
    • Test commit changes
    • Test push to remote
    • Test error handling
  2. GREEN: Implement minimum code to pass tests

    • Create GitOperationsService with NestJS
    • Implement each git operation
    • Use simple-git library
    • Read config from ConfigService
  3. REFACTOR: Improve code quality

    • Extract common patterns
    • Improve error messages
    • Add type safety

Implementation Notes

Service Interface

class GitOperationsService {
  async cloneRepository(url: string, localPath: string): Promise<void>;
  async createBranch(localPath: string, branchName: string): Promise<void>;
  async commit(localPath: string, message: string): Promise<void>;
  async push(localPath: string, remote?: string, branch?: string): Promise<void>;
}

Dependencies

  • simple-git: Git operations
  • @nestjs/config: Configuration
  • ConfigService: Access git config (userName, userEmail)

Testing Strategy

  • Mock simple-git using vitest.fn()
  • No actual git operations in tests
  • Test all success paths
  • Test error handling
  • Verify git config is set
  • Verify correct parameters passed to simple-git

Progress

  • Create test file with failing tests
  • Implement GitOperationsService
  • All tests passing
  • Coverage >= 85%
  • Update git.module.ts
  • Create types file
  • Add index.ts exports

Testing Results

pnpm test src/git/git-operations.service.spec.ts --run
# Test Files  1 passed (1)
#      Tests  14 passed (14)

pnpm test src/git/git-operations.service.spec.ts --coverage --run
# Coverage: 100% statements, 85.71% branches, 100% functions, 100% lines
# Exceeds 85% requirement ✓

pnpm typecheck
# No errors ✓

Notes

  • simple-git already in package.json (v3.27.0)
  • Git config already in orchestrator.config.ts
  • Service uses dependency injection for testability
  • All git operations async
  • Error handling preserves original error messages