fetch_ml/cmd/tui/internal/model/jobs.go
Jeremie Fraeys 6028779239
feat: update CLI, TUI, and security documentation
- Add safety checks to Zig build
- Add TUI with job management and narrative views
- Add WebSocket support and export services
- Add smart configuration defaults
- Update API routes with security headers
- Update SECURITY.md with comprehensive policy
- Add Makefile security scanning targets
2026-02-19 15:35:05 -05:00

70 lines
1.9 KiB
Go

// Package model provides TUI data structures and state management
package model
import (
"fmt"
"github.com/charmbracelet/lipgloss"
)
// JobStatus represents the status of a job
type JobStatus string
// JobStatus constants represent different job states
const (
StatusPending JobStatus = "pending" // Job is pending
StatusQueued JobStatus = "queued" // Job is queued
StatusRunning JobStatus = "running" // Job is running
StatusFinished JobStatus = "finished" // Job is finished
StatusFailed JobStatus = "failed" // Job is failed
)
// Job represents a job in the TUI
type Job struct {
Name string
Status JobStatus
TaskID string
Priority int64
// Narrative fields for research context
Hypothesis string
Context string
Intent string
ExpectedOutcome string
ActualOutcome string
OutcomeStatus string // validated, invalidated, inconclusive
// GPU allocation tracking
GPUDeviceID int // -1 if not assigned
GPUUtilization int // 0-100%
GPUMemoryUsed int64 // MB
}
// Title returns the job title for display
func (j Job) Title() string { return j.Name }
// Description returns a formatted description with status icon and GPU info
func (j Job) Description() string {
icon := map[JobStatus]string{
StatusPending: "⏸",
StatusQueued: "⏳",
StatusRunning: "▶",
StatusFinished: "✓",
StatusFailed: "✗",
}[j.Status]
pri := ""
if j.Priority > 0 {
pri = fmt.Sprintf(" [P%d]", j.Priority)
}
gpu := ""
if j.GPUDeviceID >= 0 {
gpu = fmt.Sprintf(" [GPU:%d %d%%]", j.GPUDeviceID, j.GPUUtilization)
}
// Apply status color to the status text
statusStyle := lipgloss.NewStyle().Foreground(StatusColor(j.Status))
coloredStatus := statusStyle.Render(string(j.Status))
return fmt.Sprintf("%s %s%s%s", icon, coloredStatus, pri, gpu)
}
// FilterValue returns the value used for filtering
func (j Job) FilterValue() string { return j.Name }