Implements runner-jobs module for job lifecycle management and queue submission. Changes: - Created RunnerJobsModule with service, controller, and DTOs - Implemented job creation with BullMQ queue submission - Implemented job listing with filters (status, type, agentTaskId) - Implemented job detail retrieval with steps and events - Implemented cancel operation for pending/queued jobs - Implemented retry operation for failed jobs - Added comprehensive unit tests (24 tests, 100% coverage) - Integrated with BullMQ for async job processing - Integrated with Prisma for database operations - Followed existing CRUD patterns from tasks/events modules API Endpoints: - POST /runner-jobs - Create and queue a new job - GET /runner-jobs - List jobs (with filters) - GET /runner-jobs/:id - Get job details - POST /runner-jobs/:id/cancel - Cancel a running job - POST /runner-jobs/:id/retry - Retry a failed job Quality Gates: - Typecheck: ✅ PASSED - Lint: ✅ PASSED - Build: ✅ PASSED - Tests: ✅ PASSED (24/24 tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3.3 KiB
3.3 KiB
Issue #166: Stitcher Module Structure
Objective
Create the mosaic-stitcher module - the workflow orchestration layer that wraps OpenClaw.
Prerequisites
- #165 (BullMQ module) complete - BullMqService available
- #164 (Database schema) complete - RunnerJob, JobStep, JobEvent models available
Responsibilities
- Receive webhooks from @mosaic bot
- Apply Guard Rails (capability permissions)
- Apply Quality Rails (mandatory gates)
- Track all job steps and events
- Dispatch work to OpenClaw with constraints
Approach
- Examine existing module patterns (tasks, events, brain)
- RED: Write failing tests for StitcherService and StitcherController
- GREEN: Implement minimal code to pass tests
- REFACTOR: Clean up and improve code quality
- Verify quality gates pass
Progress
- Create scratchpad
- Examine existing module patterns
- Create directory structure
- RED: Write StitcherService tests
- RED: Write StitcherController tests
- GREEN: Implement StitcherService
- GREEN: Implement StitcherController
- Create DTOs and interfaces
- Create StitcherModule
- Register in AppModule
- REFACTOR: Improve code quality
- Run quality gates (typecheck, lint, build, test)
- Commit changes
Quality Gates Results
- Typecheck: PASS
- Lint: PASS
- Build: PASS
- Tests: PASS (12 tests passing)
Patterns Observed
- BullMqService is @Global() and provides queue management
- Controllers use @UseGuards(AuthGuard, WorkspaceGuard, PermissionGuard)
- DTOs use class-validator decorators
- Services inject PrismaService for database operations
- Modules follow: imports, controllers, providers, exports structure
- Tests use Jest with describe/it blocks
Testing
- Unit tests for StitcherService
- Unit tests for StitcherController
- Integration test for webhook endpoint
Implementation Details
Files Created
apps/api/src/stitcher/stitcher.module.ts- Module definitionapps/api/src/stitcher/stitcher.service.ts- Core orchestration serviceapps/api/src/stitcher/stitcher.controller.ts- Webhook and dispatch endpointsapps/api/src/stitcher/dto/webhook.dto.ts- Request/response DTOsapps/api/src/stitcher/dto/index.ts- DTO barrel exportapps/api/src/stitcher/interfaces/job-dispatch.interface.ts- Job dispatch interfacesapps/api/src/stitcher/interfaces/index.ts- Interface barrel exportapps/api/src/stitcher/index.ts- Module barrel exportapps/api/src/stitcher/stitcher.service.spec.ts- Service unit testsapps/api/src/stitcher/stitcher.controller.spec.ts- Controller unit tests
Key Features Implemented
- Webhook endpoint: POST /stitcher/webhook - Receives webhooks from @mosaic bot
- Job dispatch: POST /stitcher/dispatch - Manual job dispatch
- Guard Rails: applyGuardRails() - Capability permission checks
- Quality Rails: applyQualityRails() - Mandatory gate determination
- Event tracking: trackJobEvent() - Audit log for all job events
TDD Process
- RED: Created failing tests for service and controller
- GREEN: Implemented minimal code to pass tests
- REFACTOR: Fixed TypeScript strict mode issues with exactOptionalPropertyTypes
Integration
- Registered StitcherModule in AppModule
- Imports PrismaModule and BullMqModule
- Exports StitcherService for use in other modules