rdev/internal/domain/build_events.go
jordan c59d348040 chore: prepare for composable monorepo template implementation
This commit captures the current state before implementing the composable
monorepo template system. Key changes included:

Infrastructure:
- Add CockroachDB provisioner adapter for database provisioning
- Add Redis provisioner adapter for cache provisioning
- Add build events system with PostgreSQL storage
- Add WebSocket endpoint for real-time build progress

Code agent improvements:
- Fix Claude Code adapter to use default allowed tools instead of dangerously-skip-permissions
- Add context-aware stream closing for cancellation support
- Improve parser tests for edge cases

Build system:
- Add build event constants and metrics
- Remove deprecated git_operations.go (replaced by pod_git_operations.go)
- Add rollback logic for multi-step provisioning operations

Documentation:
- Add composable-monorepo feature documentation
- Add DNS/Cloudflare service documentation
- Update deployment and troubleshooting guides

Cookbooks:
- Add fullstack-app cookbook
- Refactor landing-test with shared library

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 11:39:28 -07:00

113 lines
3.6 KiB
Go

package domain
import "time"
// BuildEventType categorizes build streaming events.
type BuildEventType string
// Build event types for SSE streaming.
const (
// BuildEventStarted is emitted when a build begins execution.
BuildEventStarted BuildEventType = "build.started"
// BuildEventOutput is emitted for each line of agent output (stdout/stderr).
BuildEventOutput BuildEventType = "build.output"
// BuildEventToolUse is emitted when the agent invokes a tool.
BuildEventToolUse BuildEventType = "build.tool_use"
// BuildEventToolResult is emitted when a tool returns a result.
BuildEventToolResult BuildEventType = "build.tool_result"
// BuildEventProgress is emitted periodically with progress estimates.
BuildEventProgress BuildEventType = "build.progress"
// BuildEventError is emitted for error output during execution.
BuildEventError BuildEventType = "build.error"
// BuildEventCompleted is emitted when a build finishes successfully.
BuildEventCompleted BuildEventType = "build.completed"
// BuildEventFailed is emitted when a build fails.
BuildEventFailed BuildEventType = "build.failed"
)
// BuildEvent represents a single event in a build's execution stream.
// Events are published to SSE subscribers in real-time and persisted for replay.
type BuildEvent struct {
// ID is the unique event identifier (format: "{taskID}:{sequence}").
ID string `json:"id"`
// TaskID links this event to a build task.
TaskID string `json:"task_id"`
// ProjectID links this event to a project.
ProjectID string `json:"project_id"`
// Type categorizes this event.
Type BuildEventType `json:"type"`
// Timestamp when the event occurred.
Timestamp time.Time `json:"timestamp"`
// Sequence is the monotonically increasing event number within a task.
Sequence int64 `json:"sequence"`
// Data contains event-type-specific payload.
Data BuildEventData `json:"data"`
}
// BuildEventData holds the payload for different event types.
type BuildEventData struct {
// Content is the main text content (output lines, error messages).
Content string `json:"content,omitempty"`
// Stream identifies the output source ("stdout", "stderr").
Stream string `json:"stream,omitempty"`
// ToolName is set for tool_use and tool_result events.
ToolName string `json:"tool_name,omitempty"`
// Progress fields (for build.progress events)
Phase string `json:"phase,omitempty"` // Current phase: "starting", "reading", "writing", "testing", "committing"
Percentage float64 `json:"percentage,omitempty"` // Estimated completion percentage (0-100)
// Completion fields (for build.completed and build.failed events)
Success bool `json:"success,omitempty"`
Error string `json:"error,omitempty"`
CommitSHA string `json:"commit_sha,omitempty"`
FilesChanged []string `json:"files_changed,omitempty"`
DurationMs int64 `json:"duration_ms,omitempty"`
}
// BuildPhase represents the current phase of a build.
type BuildPhase string
// Build phases for progress tracking.
const (
BuildPhaseStarting BuildPhase = "starting"
BuildPhaseReading BuildPhase = "reading"
BuildPhaseWriting BuildPhase = "writing"
BuildPhaseTesting BuildPhase = "testing"
BuildPhaseCommitting BuildPhase = "committing"
BuildPhaseComplete BuildPhase = "complete"
)
// PhaseWeight returns the progress weight for a phase (used for percentage estimation).
func (p BuildPhase) Weight() float64 {
switch p {
case BuildPhaseStarting:
return 0.05
case BuildPhaseReading:
return 0.15
case BuildPhaseWriting:
return 0.50
case BuildPhaseTesting:
return 0.20
case BuildPhaseCommitting:
return 0.10
default:
return 0
}
}