controller

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package controller provides UI-agnostic business logic for aimux. It orchestrates exports, session management, and agent coordination without depending on any TUI framework. Both the Bubble Tea TUI and a future web UI import this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BulkDeleteSessions

func BulkDeleteSessions(sessions []history.Session) (int, error)

BulkDeleteSessions removes multiple sessions, returning the count of successfully deleted sessions and the first error encountered.

func DeleteSession

func DeleteSession(s history.Session) error

DeleteSession removes a session's JSONL file and its sidecar .meta.json.

func FilterAgents added in v0.11.0

func FilterAgents(agents []agent.Agent, query string) []agent.Agent

FilterAgents returns agents matching the query string. The match is case-insensitive and checks ShortProject, ShortModel, Status, Source, ProviderName, ShortDir, and LastAction. An empty query returns all agents.

func FilterHidden

func FilterHidden(agents []agent.Agent, hidden map[string]bool) []agent.Agent

FilterHidden removes agents whose session key is in the hidden set. The key is derived from SessionID, SessionFile, or PID (in that priority).

func NextAttend added in v0.11.0

func NextAttend(agents []agent.Agent, currentIdx int) int

NextAttend returns the index of the next agent needing attention, prioritized by urgency: WaitingPermission first, then Error, then Idle, then Unknown. Active agents are always skipped.

Within the highest-priority tier, it cycles through candidates starting after currentIdx, wrapping around. Returns -1 if no agent needs attention.

func PartitionByArchive added in v0.11.0

func PartitionByArchive(agents []agent.Agent, threshold time.Duration) (active, archived []agent.Agent)

PartitionByArchive splits agents into active and archived based on idle duration. Only Idle, Error, and Unknown agents can be archived. Active and WaitingPermission agents are never archived. A zero threshold disables archiving (all agents returned in the active list).

func SetAnnotation added in v0.11.0

func SetAnnotation(sessionFile, annotation string) error

SetAnnotation updates the annotation field for a session.

func SetNote added in v0.11.0

func SetNote(sessionFile, note string) error

SetNote updates the free-text note for a session.

func SetTags added in v0.11.0

func SetTags(sessionFile string, tags []string) error

SetTags updates the tags list for a session.

func SortAgents added in v0.11.0

func SortAgents(agents []agent.Agent, field string)

SortAgents sorts agents in place using sort.SliceStable. Supported fields: "", "name", "cost", "cpu", "mem", "age", "model". The default ("") sorts by status priority (active first) then name alphabetically.

func ToggleStar added in v0.11.0

func ToggleStar(sessionFile string) (bool, error)

ToggleStar flips the starred state for a session and persists it. Returns the new starred value.

Types

type ActionInput

type ActionInput struct {
	Tool    string
	Input   string
	Success bool
	Error   string
}

ActionInput is a tool invocation within a trace turn.

type Controller

type Controller struct {
	Nav *Navigator
	// contains filtered or unexported fields
}

Controller owns the business logic and state that is shared across all UI frontends. It does NOT import bubbletea or lipgloss.

func New

func New(cfg config.Config) *Controller

New creates a new Controller with the given configuration.

func (*Controller) ExportJSONL

func (c *Controller) ExportJSONL(ctx ExportContext) (ExportResult, error)

ExportJSONL exports trace turns and session metadata to a JSONL file. Returns the file path and turn count on success.

func (*Controller) ExportOTEL

func (c *Controller) ExportOTEL(ctx ExportContext) (ExportResult, error)

ExportOTEL exports trace turns and session metadata as OTLP/HTTP spans. Returns the endpoint URL and turn count on success.

type ExportContext

type ExportContext struct {
	SessionID    string
	SessionFile  string // path to session JSONL (for loading .meta.json)
	ProviderName string
	Turns        []TraceInput
	EvalStore    *evaluation.Store
}

ExportContext holds the runtime context needed for an export operation. The UI layer populates this from its active state (which trace is open, which session file is loaded, etc.).

type ExportResult

type ExportResult struct {
	Path  string // file path (JSONL) or endpoint URL (OTEL)
	Count int    // number of turns exported
}

ExportResult holds the outcome of an export operation.

type KillAction added in v0.11.0

type KillAction struct {
	Type      KillType
	PodName   string
	Namespace string
}

KillAction holds the determined kill strategy and any provider-specific parameters (e.g., pod name and namespace for K8s agents).

func DetermineKillAction added in v0.11.0

func DetermineKillAction(ag agent.Agent) KillAction

DetermineKillAction inspects an agent and returns the appropriate kill strategy. The logic is:

  • SessionID starting with "pod-" indicates a Kubernetes pod.
  • PID == 0 with no pod prefix is a session-only entry (no live process).
  • Otherwise it is a local process to be terminated via SIGTERM.

type KillType added in v0.11.0

type KillType int

KillType describes how an agent should be terminated.

const (
	KillProcess    KillType = iota // local process: SIGTERM via provider
	KillPod                        // K8s pod: kubectl delete + scale down
	KillRemoveOnly                 // session-only entry: hide from view
)
type Navigator struct {
	CurrentView ViewType
	Breadcrumbs []string
	Zoomed      bool
	SplitMode   bool
	SplitFocus  string // "trace" or "session"
}

Navigator manages the view navigation state machine. It tracks which view is active, breadcrumbs, and zoom/split state.

func NewNavigator

func NewNavigator() *Navigator

NewNavigator creates a Navigator in the default state (agents view).

func (n *Navigator) EnterZoom()

EnterZoom enters zoomed session mode with split view.

func (n *Navigator) ExitZoom() (exitedFully bool)

ExitZoom implements hierarchical back navigation: fullscreen -> split view -> main view. Returns true if fully exited zoom (back to main), false if returned to split.

func (n *Navigator) NavigateBack()

NavigateBack returns to the agents view.

func (n *Navigator) NavigateTo(v ViewType, label string)

NavigateTo switches to a new view with a breadcrumb label.

func (n *Navigator) ToggleSplit()

ToggleSplit toggles between split and full-screen mode.

func (n *Navigator) ToggleSplitFocus()

ToggleSplitFocus switches focus between "trace" and "session" panes.

type Notification added in v0.11.0

type Notification struct {
	Title   string
	Message string
	Sound   bool
}

Notification describes a notification that should be delivered by the caller. The controller decides whether to notify; the UI layer decides how.

func ShouldNotify added in v0.11.0

func ShouldNotify(status agent.Status, projectName string, cfg config.NotificationsConfig) *Notification

ShouldNotify returns a Notification if the agent's current status warrants one, or nil if no notification should fire. The caller is responsible for delivering the notification (e.g., macOS notification center, SSE event).

type TraceInput

type TraceInput struct {
	Number     int
	Timestamp  string // RFC3339
	UserText   string
	OutputText string
	Actions    []ActionInput
	TokensIn   int64
	TokensOut  int64
	CostUSD    float64
	DurationMs int64
	Model      string
}

TraceInput is the subset of trace.Turn fields needed for export, avoiding a direct dependency on the trace package's full type (which includes rendering-specific fields).

func TurnsToInputs

func TurnsToInputs(turns []trace.Turn) []TraceInput

TurnsToInputs converts trace.Turn slices to the UI-agnostic TraceInput format. Called by the UI layer before passing data to the controller.

type ViewType

type ViewType int

ViewType identifies which view is active.

const (
	ViewAgents ViewType = iota
	ViewLogs
	ViewCosts
	ViewTeams
	ViewSessions
	ViewHelp
)

Jump to

Keyboard shortcuts

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