store

package
v0.149.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxConversationWakeAttempts = 12

Variables

View Source
var ErrRunInventoryCursor = fmt.Errorf("run inventory cursor is invalid or expired; restart discovery: %w", fs.ErrInvalid)

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Name             string
	Adapter          string
	Command          string
	ContextWindow    int
	DefaultIsolation string
	Healthy          bool
	HealthChecked    *time.Time
	ConfigJSON       *string
}

type AgentRun added in v0.149.0

type AgentRun struct {
	ID, SessionID, Principal, RequestKey, SpecHash string
	Record                                         json.RawMessage
	Revision                                       int64
}

AgentRun is the durable wing composition record. Record includes immutable launch provenance and the complete semantic outcome; tasks is its historical projection for existing conversation and CLI readers.

type AgentRunUpdate added in v0.149.0

type AgentRunUpdate struct {
	Run           *AgentRun
	Task          *Task
	Event, Detail string
}

SaveAgentRun atomically publishes full output, terminal metadata and a content-free event. Revision comparison prevents a stale observer replacing a stop intent or a terminal outcome after reconnect.

type ChatMsg

type ChatMsg struct {
	ID        int64
	SessionID string
	Role      string
	Content   string
	CreatedAt time.Time
}

type ChatSession

type ChatSession struct {
	ID        string
	Agent     string
	Title     string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Conversation added in v0.148.0

type Conversation struct {
	ID              string    `json:"conversation_id"`
	OwnerID         string    `json:"-"`
	RootID          string    `json:"root_conversation_id"`
	ParentID        string    `json:"parent_conversation_id,omitempty"`
	Title           string    `json:"title"`
	Agent           string    `json:"agent"`
	CWD             string    `json:"cwd"`
	WingID          string    `json:"wing_id"`
	SessionID       string    `json:"session_id"`
	LaunchKey       string    `json:"-"`
	SpecDigest      string    `json:"-"`
	LaunchState     string    `json:"launch_state"`
	LaunchError     string    `json:"launch_error,omitempty"`
	Checkpoint      string    `json:"checkpoint,omitempty"`
	DeliveredCursor int64     `json:"delivered_cursor"`
	Revision        int64     `json:"revision"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

Conversation is the durable personal task identity. SessionID identifies its latest execution; the execution table keeps earlier instances inspectable.

type ConversationContinuation added in v0.148.0

type ConversationContinuation struct {
	OwnerID, RequestID, ConversationID, SourceSession, SessionID string
	ProviderSessionID, InputSHA256, SpecDigest                   string
	LaunchState, LaunchError                                     string
	PriorLaunchState, PriorLaunchError                           string
}

type ConversationEvent added in v0.148.0

type ConversationEvent struct {
	Sequence       int64     `json:"sequence"`
	RootID         string    `json:"root_conversation_id"`
	ConversationID string    `json:"conversation_id"`
	SessionID      string    `json:"session_id"`
	SourceCursor   int64     `json:"session_cursor"`
	State          string    `json:"state"`
	StateSource    string    `json:"state_source"`
	Type           string    `json:"type"`
	CreatedAt      time.Time `json:"created_at"`
}

type ConversationWake added in v0.148.0

type ConversationWake struct {
	RootID            string            `json:"root_conversation_id"`
	EventSequence     int64             `json:"event_cursor"`
	Attempt           int               `json:"attempt"`
	AttemptLimit      int               `json:"attempt_limit"`
	RequestID         string            `json:"request_id,omitempty"`
	SessionID         string            `json:"session_id,omitempty"`
	ProviderSessionID string            `json:"provider_session_id,omitempty"`
	Input             string            `json:"-"`
	Status            string            `json:"status"`
	ReceiptCursor     int64             `json:"receipt_cursor,omitempty"`
	RetryAfter        int64             `json:"retry_after,omitempty"`
	Reason            string            `json:"reason,omitempty"`
	Event             ConversationEvent `json:"event"`
}

type ConversationWakePolicy added in v0.148.0

type ConversationWakePolicy struct {
	Enabled        bool  `json:"enabled"`
	ScanCursor     int64 `json:"scan_cursor"`
	DeliveryCursor int64 `json:"wake_delivery_cursor"`
}

type LogEntry

type LogEntry struct {
	ID        int64
	TaskID    string
	Timestamp time.Time
	Event     string
	Detail    *string
}

type RunInventoryItem added in v0.149.4

type RunInventoryItem struct {
	ID                 string `json:"run_id"`
	SessionID          string `json:"session_id"`
	Agent              string `json:"agent"`
	Model              string `json:"model"`
	Label              string `json:"label,omitempty"`
	CWD                string `json:"cwd"`
	Isolation          string `json:"isolation"`
	Status             string `json:"status"`
	Phase              string `json:"phase"`
	ParentID           string `json:"parent_id,omitempty"`
	RequestKey         string `json:"idempotency_key,omitempty"`
	CreatedAt          string `json:"created_at"`
	StartedAt          string `json:"started_at,omitempty"`
	FinishedAt         string `json:"finished_at,omitempty"`
	TimeoutSeconds     int    `json:"timeout_seconds"`
	FailureKind        string `json:"failure_kind,omitempty"`
	Terminal           bool   `json:"terminal"`
	Legacy             bool   `json:"legacy"`
	Cleanup            string `json:"cleanup"`
	OutputAvailability string `json:"output_availability"`
}

type RunInventoryPage added in v0.149.4

type RunInventoryPage struct {
	Runs     []RunInventoryItem
	Position RunInventoryPosition
	More     bool
}

type RunInventoryPosition added in v0.149.4

type RunInventoryPosition struct {
	Watermark    int64  `json:"watermark"`
	AnchorID     string `json:"anchor_id"`
	AfterCreated string `json:"after_created"`
	AfterID      string `json:"after_id"`
}

type RunInventoryQuery added in v0.149.4

type RunInventoryQuery struct {
	Scope         RunInventoryScope
	Limit         int
	RequestKey    string
	TerminalSince time.Time
	Position      RunInventoryPosition
	Continuing    bool
}

type RunInventoryScope added in v0.149.4

type RunInventoryScope struct {
	Principal, UserID                string
	LegacyLocalDefault, EnforcePaths bool
	AllowedPaths                     []string
}

RunInventoryScope is supplied by the authenticated wing service, never tool arguments. Legacy tasks have no user identity, matching the known-ID path.

type Store

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

func Open

func Open(dsn string) (*Store, error)

func (*Store) AdmitAgentRun added in v0.149.0

func (s *Store) AdmitAgentRun(run *AgentRun, task *Task) (*AgentRun, bool, error)

AdmitAgentRun reserves both identifiers and the optional retry key in the same transaction as the legacy task projection, before any egg can launch.

func (*Store) AppendChatMessage

func (s *Store) AppendChatMessage(sessionID, role, content string) error

func (*Store) AppendLog

func (s *Store) AppendLog(taskID, event string, detail *string) error

func (*Store) AppendThread

func (s *Store) AppendThread(e *ThreadEntry) error

func (*Store) AppendThreadAt

func (s *Store) AppendThreadAt(e *ThreadEntry, ts time.Time) error

func (*Store) BindConversationWake added in v0.148.0

func (s *Store) BindConversationWake(w *ConversationWake, session, provider, input string, now int64) error

Only queued or explicitly proven-not-sent attempts may acquire a new ID or destination. Unknown delivery keeps its immutable request and provider binding.

func (*Store) CheckpointConversation added in v0.148.0

func (s *Store) CheckpointConversation(owner, id string, expected, after int64, checkpoint string) error

CheckpointConversation is compare-and-swap. A stale controller cannot overwrite newer intent or move a delivery cursor backwards or past evidence.

func (*Store) ClearTaskCron

func (s *Store) ClearTaskCron(id string) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) ConversationEvents added in v0.148.0

func (s *Store) ConversationEvents(owner, root string, after int64, limit int) ([]ConversationEvent, error)

func (*Store) ConversationExecutions added in v0.148.0

func (s *Store) ConversationExecutions(id string) ([]string, error)

func (*Store) ConversationForSession added in v0.148.0

func (s *Store) ConversationForSession(session string) (*Conversation, error)

func (*Store) ConversationImportCursor added in v0.148.0

func (s *Store) ConversationImportCursor(session string) (int64, error)

func (*Store) ConversationWakePolicy added in v0.148.0

func (s *Store) ConversationWakePolicy(root string) (ConversationWakePolicy, error)

func (*Store) ConversationWakeRoots added in v0.148.0

func (s *Store) ConversationWakeRoots(after string, limit int) ([]*Conversation, error)

func (*Store) CountConversationLaunchesSince added in v0.148.0

func (s *Store) CountConversationLaunchesSince(owner string, since time.Time) (int, error)

CountConversationLaunchesSince counts an owner's linked launches reserved at or after since, excluding launches recorded as definitely failed. It gives host mailbox admission a spawn-rate bound that survives process restarts and is shared by every process using this state directory.

func (*Store) CreateChatSession

func (s *Store) CreateChatSession(id, agent string) error

func (*Store) CreateTask

func (s *Store) CreateTask(t *Task) error

func (*Store) DB

func (s *Store) DB() *sql.DB

func (*Store) DeleteChatSession

func (s *Store) DeleteChatSession(id string) error

func (*Store) DeleteThreadOlderThan

func (s *Store) DeleteThreadOlderThan(ts time.Time) (int64, error)

func (*Store) GetAgent

func (s *Store) GetAgent(name string) (*Agent, error)

func (*Store) GetAgentRun added in v0.149.0

func (s *Store) GetAgentRun(id string) (*AgentRun, error)

func (*Store) GetChatSession

func (s *Store) GetChatSession(id string) (*ChatSession, error)

func (*Store) GetConversation added in v0.148.0

func (s *Store) GetConversation(owner, id string) (*Conversation, error)

func (*Store) GetConversationContinuation added in v0.148.0

func (s *Store) GetConversationContinuation(owner, request string) (*ConversationContinuation, error)

func (*Store) GetTask

func (s *Store) GetTask(id string) (*Task, error)

func (*Store) ImportConversationStates added in v0.148.0

func (s *Store) ImportConversationStates(c *Conversation, events []ConversationEvent, cursor int64) error

ImportConversationStates commits event deliveries and the session read cursor together, so reconnect replay never drops an attention or completion event.

func (*Store) IncrementRetryCount

func (s *Store) IncrementRetryCount(taskID string) error

func (*Store) ListAgentRuns added in v0.149.0

func (s *Store) ListAgentRuns() ([]*AgentRun, error)

func (*Store) ListAgents

func (s *Store) ListAgents() ([]*Agent, error)

func (*Store) ListChatMessages

func (s *Store) ListChatMessages(sessionID string) ([]*ChatMsg, error)

func (*Store) ListChatSessions

func (s *Store) ListChatSessions() ([]*ChatSession, error)

func (*Store) ListConversations added in v0.148.0

func (s *Store) ListConversations(owner, root string) ([]*Conversation, error)

func (*Store) ListLogByTask

func (s *Store) ListLogByTask(taskID string) ([]*LogEntry, error)

func (*Store) ListPending

func (s *Store) ListPending(now time.Time) ([]*Task, error)

func (*Store) ListReady

func (s *Store) ListReady(now time.Time) ([]*Task, error)

ListReady returns pending tasks where all dependencies are done (or have no dependencies).

func (*Store) ListRecent

func (s *Store) ListRecent(n int) ([]*Task, error)

func (*Store) ListRecentThread

func (s *Store) ListRecentThread(n int) ([]*ThreadEntry, error)

func (*Store) ListRecurring

func (s *Store) ListRecurring() ([]*Task, error)

func (*Store) ListRunInventory added in v0.149.4

func (s *Store) ListRunInventory(ctx context.Context, q RunInventoryQuery) (RunInventoryPage, error)

ListRunInventory enumerates committed metadata in a read transaction. It does not load run output, touch eggs, reconcile state, or instantiate workers.

func (*Store) ListThreadByDate

func (s *Store) ListThreadByDate(date time.Time) ([]*ThreadEntry, error)

func (*Store) PendingConversationWake added in v0.148.0

func (s *Store) PendingConversationWake(root string) (*ConversationWake, error)

func (*Store) QueueConversationWake added in v0.148.0

func (s *Store) QueueConversationWake(root string) (*ConversationWake, error)

At most one event is outstanding per root. Scanning and reservation commit together; reopening the store cannot create a second wake for that event.

func (*Store) RecordConversationState added in v0.148.0

func (s *Store) RecordConversationState(c *Conversation, cursor int64, state, source string) error

func (*Store) RecordConversationWake added in v0.148.0

func (s *Store) RecordConversationWake(w *ConversationWake, status, reason string, receipt, now int64) error

func (*Store) ReserveConversation added in v0.148.0

func (s *Store) ReserveConversation(c Conversation) (*Conversation, bool, error)

ReserveConversation atomically claims a caller-provided launch key before spawning. Replays return the same logical and execution IDs, even if a crash left the reservation in starting; callers must reconcile, never launch again.

func (*Store) ReserveConversationContinuation added in v0.148.0

func (s *Store) ReserveConversationContinuation(c ConversationContinuation) (*ConversationContinuation, bool, error)

ReserveConversationContinuation claims the retry key and links the execution before dispatch. A crash leaves starting evidence; replay never dispatches it.

func (*Store) ResumeConversationExecution added in v0.148.0

func (s *Store) ResumeConversationExecution(source, target string) error

func (*Store) RetryNotSentConversationWake added in v0.148.0

func (s *Store) RetryNotSentConversationWake(owner, root string, now int64) error

Explicit recovery is permitted only by a retained known-no-input outcome. Attempt numbers and old request evidence never reset or become ambiguous.

func (*Store) SaveAgentRun added in v0.149.0

func (s *Store) SaveAgentRun(r *AgentRun, task *Task, event, detail string) error

func (*Store) SaveAgentRuns added in v0.149.0

func (s *Store) SaveAgentRuns(updates []AgentRunUpdate) error

SaveAgentRuns commits a parent stop intent and every unstarted follow-up cancellation together, including their task projections and events.

func (*Store) SetConversationContinuationLaunch added in v0.148.0

func (s *Store) SetConversationContinuationLaunch(c *ConversationContinuation, state, detail string) error

func (*Store) SetConversationLaunch added in v0.148.0

func (s *Store) SetConversationLaunch(id, state, detail string) error

func (*Store) SetConversationWake added in v0.148.0

func (s *Store) SetConversationWake(owner, root string, enabled bool) error

func (*Store) SetTaskError

func (s *Store) SetTaskError(id, errMsg string) error

func (*Store) SetTaskOutput

func (s *Store) SetTaskOutput(id, output string) error

func (*Store) SetTaskResolved added in v0.144.0

func (s *Store) SetTaskResolved(id, agent, isolation string) error

SetTaskResolved records the runtime choices made by the orchestrator. Tasks may be submitted without either field, so the stored values must be updated after skill/config precedence has been resolved if API clients are to see what actually ran.

func (*Store) SetTaskWhat added in v0.145.0

func (s *Store) SetTaskWhat(id, what string) error

SetTaskWhat records the final prompt used to execute a task. Some task types, such as queued agent follow-ups, cannot assemble their complete prompt until a dependency has finished.

func (*Store) SumTokensByDateRange

func (s *Store) SumTokensByDateRange(start, end time.Time) (int, error)

func (*Store) ThreadEntryExists

func (s *Store) ThreadEntryExists(taskID *string, wingID string, timestamp time.Time) (bool, error)

ThreadEntryExists checks if a thread entry with the given task_id, wing_id, and timestamp exists.

func (*Store) ThreadEntryExistsBySummary

func (s *Store) ThreadEntryExistsBySummary(wingID string, timestamp time.Time, summary string) (bool, error)

ThreadEntryExistsBySummary checks if a thread entry with the given wing_id, timestamp, and summary exists.

func (*Store) UpdateAgentHealth

func (s *Store) UpdateAgentHealth(name string, healthy bool, checkedAt time.Time) error

func (*Store) UpdateTaskStatus

func (s *Store) UpdateTaskStatus(id, status string) error

func (*Store) UpsertAgent

func (s *Store) UpsertAgent(a *Agent) error

type Task

type Task struct {
	ID             string
	Type           string
	What           string
	RunAt          time.Time
	Agent          string
	Model          string
	TimeoutSeconds int
	Isolation      string
	Memory         *string
	ParentID       *string
	Status         string
	Cron           *string
	WingID         *string
	CreatedAt      time.Time
	StartedAt      *time.Time
	FinishedAt     *time.Time
	Output         *string
	Error          *string
	RetryCount     int
	MaxRetries     int
	DependsOn      *string
	CWD            string
	PromptName     string
	PromptRevision string
	Principal      string
	RunnerPID      int
	EggConfigYAML  string
}

type ThreadEntry

type ThreadEntry struct {
	ID         int64
	TaskID     *string
	Timestamp  time.Time
	WingID     string
	Agent      *string
	Skill      *string
	UserInput  *string
	Summary    string
	TokensUsed *int
}

Jump to

Keyboard shortcuts

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