missions

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissionNotFound   = errors.New("mission not found")
	ErrMissionSlugExists = errors.New("mission slug already exists")
	ErrInvalidMission    = errors.New("invalid mission")
)
View Source
var (
	ErrRunNotFound = errors.New("mission run not found")
)

Functions

This section is empty.

Types

type CostAttribution

type CostAttribution struct {
	ID           uuid.UUID `db:"id" json:"id"`
	MissionID    uuid.UUID `db:"mission_id" json:"mission_id"`
	MissionRunID uuid.UUID `db:"mission_run_id" json:"mission_run_id"`
	SessionID    uuid.UUID `db:"session_id" json:"session_id"`
	ComputeCost  float64   `db:"compute_cost" json:"compute_cost"`
	StorageCost  float64   `db:"storage_cost" json:"storage_cost"`
	NetworkCost  float64   `db:"network_cost" json:"network_cost"`
	TotalCost    float64   `db:"total_cost" json:"total_cost"`
	MetricCount  int       `db:"metric_count" json:"metric_count"`
	CreatedAt    time.Time `db:"created_at" json:"created_at"`
}

CostAttribution is a snapshot of session costs linked to a mission run.

type CreateMissionRequest

type CreateMissionRequest struct {
	Slug        string   `json:"slug" binding:"required"`
	Name        string   `json:"name" binding:"required"`
	Description string   `json:"description"`
	Version     string   `json:"version"`
	Steps       []Step   `json:"steps" binding:"required"`
	Tags        []string `json:"tags"`
	Published   bool     `json:"published"`
}

func (*CreateMissionRequest) Normalize

func (r *CreateMissionRequest) Normalize()

NormalizeCreate trims slug/name after Validate for persistence.

func (CreateMissionRequest) Validate

func (r CreateMissionRequest) Validate() error

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func New

func New(db *sqlx.DB) *Manager

func (*Manager) AttributeRunCosts

func (m *Manager) AttributeRunCosts(ctx context.Context, missionID, runID uuid.UUID) (*CostAttribution, error)

AttributeRunCosts snapshots current session cost_metrics totals onto the mission run.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, orgID *uuid.UUID, actor string, req CreateMissionRequest) (*Mission, error)

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context, id uuid.UUID) error

func (*Manager) Get

func (m *Manager) Get(ctx context.Context, id uuid.UUID) (*Mission, error)

func (*Manager) GetBySlug

func (m *Manager) GetBySlug(ctx context.Context, slug string) (*Mission, error)

func (*Manager) GetMissionCostSummary

func (m *Manager) GetMissionCostSummary(ctx context.Context, missionID uuid.UUID) (*MissionCostSummary, error)

GetMissionCostSummary sums attributions for a mission.

func (*Manager) GetRun

func (m *Manager) GetRun(ctx context.Context, missionID, runID uuid.UUID) (*MissionRun, error)

GetRun loads one mission run.

func (*Manager) GetRunAttribution

func (m *Manager) GetRunAttribution(ctx context.Context, missionID, runID uuid.UUID) (*CostAttribution, error)

GetRunAttribution returns the cost snapshot for a run if present.

func (*Manager) List

func (m *Manager) List(ctx context.Context, filter MissionFilter) ([]Mission, error)

func (*Manager) ListRuns

func (m *Manager) ListRuns(ctx context.Context, missionID uuid.UUID, limit int) ([]MissionRun, error)

func (*Manager) RecordRun

func (m *Manager) RecordRun(ctx context.Context, missionID uuid.UUID, sessionID, orgID *uuid.UUID, status string, stepResults []any, runErr string) (*MissionRun, error)

RecordRun inserts a mission_runs row (increments use_count via trigger).

func (*Manager) Update

func (m *Manager) Update(ctx context.Context, id uuid.UUID, req UpdateMissionRequest) (*Mission, error)

func (*Manager) UpdateRun

func (m *Manager) UpdateRun(ctx context.Context, missionID, runID uuid.UUID, req UpdateRunRequest) (*MissionRun, error)

UpdateRun updates status/step_results and optionally finishes the run.

type Mission

type Mission struct {
	ID          uuid.UUID  `db:"id" json:"id"`
	Slug        string     `db:"slug" json:"slug"`
	Name        string     `db:"name" json:"name"`
	Description string     `db:"description" json:"description"`
	OrgID       *uuid.UUID `db:"org_id" json:"org_id,omitempty"`
	CreatedBy   string     `db:"created_by" json:"created_by"`
	Version     string     `db:"version" json:"version"`
	Published   bool       `db:"published" json:"published"`
	UseCount    int        `db:"use_count" json:"use_count"`
	Steps       []Step     `db:"steps" json:"steps"`
	Tags        []string   `db:"tags" json:"tags"`
	CreatedAt   time.Time  `db:"created_at" json:"created_at"`
	UpdatedAt   time.Time  `db:"updated_at" json:"updated_at"`
}

Mission is a reusable, versioned tool sequence.

type MissionCostSummary

type MissionCostSummary struct {
	MissionID   uuid.UUID `db:"mission_id" json:"mission_id"`
	RunCount    int       `db:"run_count" json:"run_count"`
	ComputeCost float64   `db:"compute_cost" json:"compute_cost"`
	StorageCost float64   `db:"storage_cost" json:"storage_cost"`
	NetworkCost float64   `db:"network_cost" json:"network_cost"`
	TotalCost   float64   `db:"total_cost" json:"total_cost"`
}

MissionCostSummary aggregates attributed costs for a mission.

type MissionFilter

type MissionFilter struct {
	Search    string `form:"search"`
	Published *bool  `form:"published"`
	Limit     int    `form:"limit"`
	Offset    int    `form:"offset"`
}

type MissionRun

type MissionRun struct {
	ID          uuid.UUID  `db:"id" json:"id"`
	MissionID   uuid.UUID  `db:"mission_id" json:"mission_id"`
	SessionID   *uuid.UUID `db:"session_id" json:"session_id,omitempty"`
	OrgID       *uuid.UUID `db:"org_id" json:"org_id,omitempty"`
	Status      string     `db:"status" json:"status"`
	StepResults []any      `db:"step_results" json:"step_results"`
	Error       string     `db:"error,omitempty" json:"error,omitempty"`
	CreatedAt   time.Time  `db:"created_at" json:"created_at"`
	FinishedAt  *time.Time `db:"finished_at" json:"finished_at,omitempty"`
}

MissionRun records one execution attempt of a mission.

type StartMissionRunRequest

type StartMissionRunRequest struct {
	SessionID *uuid.UUID `json:"session_id"`
}

type Step

type Step struct {
	Name        string            `json:"name"`
	Tool        string            `json:"tool"`
	Args        map[string]string `json:"args,omitempty"`
	Description string            `json:"description,omitempty"`
	// Verify is an optional post-step check evaluated by the verify package / API.
	Verify *StepVerify `json:"verify,omitempty"`
}

Step is one tool invocation in a mission (MCP tool name + args).

type StepVerify

type StepVerify struct {
	ExitCodeZero   *bool  `json:"exit_code_zero,omitempty"`
	StdoutContains string `json:"stdout_contains,omitempty"`
	FileExists     string `json:"file_exists,omitempty"`
}

StepVerify is a lightweight assertion attached to a step (evaluated when verify is enabled).

type UpdateMissionRequest

type UpdateMissionRequest struct {
	Name        *string  `json:"name"`
	Description *string  `json:"description"`
	Version     *string  `json:"version"`
	Steps       []Step   `json:"steps"`
	Tags        []string `json:"tags"`
	Published   *bool    `json:"published"`
}

type UpdateRunRequest

type UpdateRunRequest struct {
	Status      string `json:"status"`
	StepResults []any  `json:"step_results"`
	Error       string `json:"error"`
	Attribute   bool   `json:"attribute_costs"` // snapshot session costs when session_id set
}

UpdateRunRequest finishes or updates a mission run (replay completion).

Jump to

Keyboard shortcuts

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