package api import ( "database/sql" "github.com/thepeterstone/claudomator/internal/deployment" "github.com/thepeterstone/claudomator/internal/task" ) // taskView wraps a task with computed fields that are derived from execution // history and deployment state. It is used as the JSON response type for task // list and get endpoints so that callers receive enriched data in one request. type taskView struct { *task.Task Changestats *task.Changestats `json:"changestats,omitempty"` DeploymentStatus *deployment.Status `json:"deployment_status,omitempty"` } // enrichTask fetches the latest execution for the given task and attaches // changestats and deployment_status fields for READY tasks. // Non-READY tasks are returned without these extra fields. func (s *Server) enrichTask(tk *task.Task) *taskView { view := &taskView{Task: tk} if tk.State != task.StateReady { return view } exec, err := s.store.GetLatestExecution(tk.ID) if err != nil { if err == sql.ErrNoRows { // No execution yet — still include deployment status (empty commits). view.DeploymentStatus = deployment.Check(nil, tk.Agent.ProjectDir) } return view } view.Changestats = exec.Changestats view.DeploymentStatus = deployment.Check(exec.Commits, tk.Agent.ProjectDir) return view }