rdev/ai-lookup/services/work-queue.md
jordan 39df51defd feat: Add multi-provider code agent interface with Claude Code and OpenCode adapters
Implements weeks 1-4 of the multi-provider architecture:

Week 1 - Foundation:
- Add domain models (AgentProvider, AgentRequest, AgentEvent, AgentResult)
- Define CodeAgent port interface with Execute, Cancel, Capabilities
- Create thread-safe provider registry with first-registered default

Week 2 - Claude Code Adapter:
- Extract kubectl exec logic into CodeAgent implementation
- Parse stream-json output format (init, message, tool_use, result)
- Support session continuation via --resume flag

Week 3 - OpenCode Adapter:
- HTTP/SSE client for opencode serve API
- Session management (create, send message, abort)
- Event streaming with documented buffer rationale

Week 4 - Quality & Polish:
- Fix race condition in OpenCode Cancel method
- Add AgentRequest.Validate() with ErrPromptRequired, ErrInvalidTimeout
- Document DefaultAvailabilityTimeout constants
- Add HTTP error context for debugging

Also includes:
- Work queue system with PostgreSQL adapter
- Credential store for infrastructure secrets
- Project templates with Woodpecker CI integration
- Comprehensive test coverage

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 09:25:51 -07:00

58 lines
1.8 KiB
Markdown

# Work Queue
**Last Updated:** 2025-01
**Confidence:** High (Planned - see address-the-gaps.md)
## Summary
Work queue enables worker pool architecture. Workers poll for tasks, execute them, and report results. Supports async build orchestration for bot-driven development.
**Key Facts:**
- Tasks enqueued via `POST /work/enqueue`
- Workers dequeue via `GET /work/dequeue?worker_id=X`
- Status transitions: `pending``running``completed` | `failed`
- Callback URLs for bot notification on completion
- PostgreSQL-backed with atomic dequeue
**File Pointers:**
- Port: `internal/port/work_queue.go`
- Adapter: `internal/adapter/postgres/work_queue.go`
- Handler: `internal/handlers/work.go`
- Migration: `internal/db/migrations/011_work_queue.sql`
## Port Interface
```go
type WorkQueue interface {
Enqueue(ctx context.Context, task WorkTask) (string, error)
Dequeue(ctx context.Context, workerID string) (*WorkTask, error)
Complete(ctx context.Context, taskID string, result WorkResult) error
Fail(ctx context.Context, taskID string, err error) error
GetStatus(ctx context.Context, taskID string) (*WorkTaskStatus, error)
}
```
## Task Types
| Type | Description |
|------|-------------|
| `build` | Run Claude Code with prompt, commit result |
| `test` | Run test suite |
| `deploy` | Trigger Kubernetes deployment |
## API Endpoints
```
POST /work/enqueue - Add task to queue
GET /work/dequeue - Worker gets next task
POST /work/{id}/complete - Worker reports success
POST /work/{id}/fail - Worker reports failure
GET /work/{id}/status - Check task status
GET /work/stats - Queue statistics
```
## Related Topics
- [Worker Pool](./worker-pool.md)
- [Build Orchestration](../features/build-orchestration.md)