models

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package models defines shared types used across the Samverk system.

Index

Constants

View Source
const SchemaVersion = "1.0.0"

SchemaVersion is the current issue schema version.

Variables

This section is empty.

Functions

func IsEven added in v0.1.11

func IsEven(n int) bool

IsEven returns true if n is divisible by 2.

func IsOdd added in v0.1.11

func IsOdd(n int) bool

IsOdd returns true if n is not divisible by 2.

func RenderFrontmatter

func RenderFrontmatter(fm *IssueFrontmatter, markdown string) string

RenderFrontmatter produces an issue body with YAML frontmatter followed by markdown.

Types

type AgentType

type AgentType string

AgentType identifies which agent pool should handle an issue.

const (
	AgentTypeOrchestrator AgentType = "orchestrator"
	AgentTypeDispatcher   AgentType = "dispatcher"
	AgentTypeCodeGen      AgentType = "code-gen"
	AgentTypeTest         AgentType = "test"
	AgentTypeDocs         AgentType = "docs"
	AgentTypeResearch     AgentType = "research"
	AgentTypeQC           AgentType = "qc"
	AgentTypeHuman        AgentType = "human"
	AgentTypeInfra        AgentType = "infra"
	AgentTypePC           AgentType = "pc"
)

type Complexity

type Complexity string

Complexity hints at whether work should run locally or in the cloud.

const (
	ComplexityLocal     Complexity = "local"
	ComplexityCloud     Complexity = "cloud"
	ComplexityAmbiguous Complexity = "ambiguous"
)

type CostRecord

type CostRecord struct {
	ID           string    `json:"id"`
	SessionID    string    `json:"session_id"`
	Provider     string    `json:"provider"`
	Model        string    `json:"model"`
	InputTokens  int       `json:"input_tokens"`
	OutputTokens int       `json:"output_tokens"`
	CostUSD      float64   `json:"cost_usd"` // 0 for local models
	CreatedAt    time.Time `json:"created_at"`
}

CostRecord tracks token usage for a single API call.

type CostSummary

type CostSummary struct {
	TotalInputTokens  int     `json:"total_input_tokens"`
	TotalOutputTokens int     `json:"total_output_tokens"`
	TotalCostUSD      float64 `json:"total_cost_usd"`
	RecordCount       int     `json:"record_count"`
}

CostSummary aggregates cost data over a time period.

type IssueFrontmatter

type IssueFrontmatter struct {
	SchemaVersion   string    `yaml:"schema_version"`
	Type            IssueType `yaml:"type"`
	AgentType       AgentType `yaml:"agent_type"`
	Priority        Priority  `yaml:"priority"`
	ParentIssue     int       `yaml:"parent_issue,omitempty"`
	DependsOn       []int     `yaml:"depends_on,omitempty"`
	EstimatedTokens int       `yaml:"estimated_tokens,omitempty"`
	ActualTokens    int       `yaml:"actual_tokens,omitempty"`
	ModelUsed       string    `yaml:"model_used,omitempty"`
}

IssueFrontmatter represents the YAML frontmatter parsed from an issue body.

type IssueType

type IssueType string

IssueType identifies the communication purpose of an issue.

const (
	IssueTypeTask     IssueType = "task"
	IssueTypeQuestion IssueType = "question"
	IssueTypeResult   IssueType = "result"
	IssueTypeBlock    IssueType = "block"
)

type ParseResult

type ParseResult struct {
	Frontmatter *IssueFrontmatter
	Body        string // markdown after the closing ---
}

ParseResult holds the parsed frontmatter and remaining body text.

func ParseFrontmatter

func ParseFrontmatter(body string) (*ParseResult, error)

ParseFrontmatter extracts YAML frontmatter from an issue body. The frontmatter must be delimited by --- on its own line at the start of the body. Returns error if frontmatter is present but malformed. Returns nil Frontmatter (no error) if no frontmatter block exists.

type Priority

type Priority string

Priority determines scheduling order.

const (
	PriorityCritical Priority = "critical"
	PriorityHigh     Priority = "high"
	PriorityNormal   Priority = "normal"
	PriorityLow      Priority = "low"
)

type ScalingControl added in v0.1.11

type ScalingControl struct {
	Paused        bool
	ManualWorkers int
	SetAt         time.Time
	Note          string
}

ScalingControl is a single-row record that holds manual override state written by the REST API or CLI and consumed by the autoscaler on each evaluation cycle. ManualWorkers == 0 means no manual target is set. Paused == true means the autoscaler should hold (take no autonomous action).

type ScalingEvent added in v0.1.11

type ScalingEvent struct {
	ID          string
	Timestamp   time.Time
	Action      string // "scale-up" | "scale-down" | "manual-override"
	FromWorkers int
	ToWorkers   int
	Reason      string
	Confidence  float64
}

ScalingEvent records a single autoscaler decision.

type Session

type Session struct {
	ID          string        `json:"id"`
	IssueNumber int           `json:"issue_number"`
	AgentType   string        `json:"agent_type"` // e.g., "code-gen", "qc", "research"
	Provider    string        `json:"provider"`   // e.g., "ollama", "claude", "openai"
	Model       string        `json:"model"`      // e.g., "qwen2.5-coder:7b"
	Status      SessionStatus `json:"status"`
	StartedAt   time.Time     `json:"started_at"`
	FinishedAt  *time.Time    `json:"finished_at,omitempty"`
	Error       string        `json:"error,omitempty"`
	CreatedAt   time.Time     `json:"created_at"`
	UpdatedAt   time.Time     `json:"updated_at"`
}

Session represents a unit of agent work on an issue.

type SessionStatus

type SessionStatus string

SessionStatus represents the lifecycle state of a work session.

const (
	SessionStatusPending   SessionStatus = "pending"
	SessionStatusActive    SessionStatus = "active"
	SessionStatusCompleted SessionStatus = "completed"
	SessionStatusFailed    SessionStatus = "failed"
	SessionStatusCancelled SessionStatus = "cancelled"
)

type Status

type Status string

Status tracks the lifecycle state of an issue.

const (
	StatusQueued       Status = "queued"
	StatusClaimed      Status = "claimed"
	StatusInProgress   Status = "in-progress"
	StatusBlocked      Status = "blocked"
	StatusNeedsQC      Status = "needs-qc"
	StatusNeedsHuman   Status = "needs-human"
	StatusHumanPending Status = "human-pending"
	StatusDone         Status = "done"
)

type TaskProfile added in v0.1.11

type TaskProfile struct {
	AgentType   string        `json:"agent_type"`
	Provider    string        `json:"provider"`
	AvgDuration time.Duration `json:"avg_duration"`
	P50Duration time.Duration `json:"p50_duration"`
	P90Duration time.Duration `json:"p90_duration"`
	SampleCount int           `json:"sample_count"`
	AvgTokens   int           `json:"avg_tokens"`
	UpdatedAt   time.Time     `json:"updated_at"`
}

TaskProfile holds rolling performance statistics for a specific (AgentType, Provider) combination, computed from completed sessions. Values are updated after each successful task completion.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL