rdev/internal/domain/project.go
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

62 lines
2.0 KiB
Go

// Package domain contains pure domain models with no external dependencies.
// These types represent the core business concepts of the application.
package domain
// ProjectID is a strongly-typed identifier for projects.
type ProjectID string
// Project represents a claudebox project that can execute commands.
type Project struct {
ID ProjectID
Name string
Description string
PodName string
Status ProjectStatus
Workspace string
// AgentProvider specifies which code agent to use for this project.
// Empty string means use the system default (typically Claude Code).
AgentProvider AgentProvider
}
// ProjectStatus represents the current state of a project's pod.
type ProjectStatus string
const (
ProjectStatusRunning ProjectStatus = "running"
ProjectStatusPending ProjectStatus = "pending"
ProjectStatusFailed ProjectStatus = "failed"
ProjectStatusNotFound ProjectStatus = "not_found"
ProjectStatusUnknown ProjectStatus = "unknown"
ProjectStatusError ProjectStatus = "error"
)
// IsAvailable returns true if the project can accept commands.
func (s ProjectStatus) IsAvailable() bool {
return s == ProjectStatusRunning
}
// IsTerminal returns true if the status is a final state.
func (s ProjectStatus) IsTerminal() bool {
return s == ProjectStatusFailed || s == ProjectStatusNotFound
}
// K8s label and annotation constants for project discovery.
// Pods with these labels are discovered as rdev projects.
const (
// LabelProject marks a pod as an rdev project when set to "true".
LabelProject = "rdev.orchard9.ai/project"
// LabelName specifies the project name (used as project ID).
LabelName = "rdev.orchard9.ai/name"
// LabelWorkspace specifies the workspace path inside the pod.
LabelWorkspace = "rdev.orchard9.ai/workspace"
// LabelAgentProvider specifies which code agent to use ("claudecode", "opencode").
LabelAgentProvider = "rdev.orchard9.ai/agent-provider"
// AnnotDescription provides a human-readable description of the project.
AnnotDescription = "rdev.orchard9.ai/description"
)