state

package
v0.1.0-p8a.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoModelSelection

type AutoModelSelection struct {
	SelectedProvider string    `json:"selected_provider,omitempty"`
	SelectedModel    string    `json:"selected_model,omitempty"`
	ActiveProvider   string    `json:"active_provider,omitempty"`
	ActiveModel      string    `json:"active_model,omitempty"`
	Reason           string    `json:"reason,omitempty"`
	ExpiresAt        time.Time `json:"expires_at,omitempty"`
	UpdatedAt        time.Time `json:"updated_at,omitempty"`
}

type Manager

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

Manager manages persistent state with atomic saves.

func NewManager

func NewManager(workspace string) *Manager

NewManager creates a new state manager for the given workspace.

func NewManagerAt

func NewManagerAt(stateFile string) *Manager

NewManagerAt creates a manager for an exact runtime-owned state file. It intentionally performs no legacy workspace migration.

func NewManagerAtChecked

func NewManagerAtChecked(stateFile string) (*Manager, error)

NewManagerAtChecked creates a strict manager and reports existing state that cannot be read or decoded.

func (*Manager) ClearAutoModelSelection

func (sm *Manager) ClearAutoModelSelection(routeSessionKey string) error

ClearAutoModelSelection removes a persisted auto-fallback model selection.

func (*Manager) ClearSessionGoal

func (sm *Manager) ClearSessionGoal(routeSessionKey string) error

ClearSessionGoal removes the goal for a routed session. Missing goals are a no-op so reset/new callers can clear defensively.

func (*Manager) ClearSessionModelOverride

func (sm *Manager) ClearSessionModelOverride(routeSessionKey string) error

ClearSessionModelOverride removes a previously persisted manual model selection for a routed session.

func (*Manager) ClearSessionOverride

func (sm *Manager) ClearSessionOverride(routeSessionKey string) error

ClearSessionOverride removes a previously persisted replacement session key.

func (*Manager) ClearToolFeedbackOverride

func (sm *Manager) ClearToolFeedbackOverride(routeSessionKey string) error

ClearToolFeedbackOverride removes a persisted tool feedback override for a routed session, causing config defaults to apply again.

func (*Manager) CreateSessionGoal

func (sm *Manager) CreateSessionGoal(routeSessionKey, objective string) (SessionGoal, error)

CreateSessionGoal creates one durable goal for a routed session. It fails when a goal already exists so command/tool callers cannot silently replace an operator objective.

func (*Manager) EditSessionGoal

func (sm *Manager) EditSessionGoal(routeSessionKey, objective string) (SessionGoal, error)

EditSessionGoal updates the current objective while preserving status and creation metadata.

func (*Manager) GetAutoModelSelection

func (sm *Manager) GetAutoModelSelection(routeSessionKey string) (AutoModelSelection, bool)

GetAutoModelSelection returns the persisted auto-fallback model selection for a routed session and whether one is present.

func (*Manager) GetLastChannel

func (sm *Manager) GetLastChannel() string

GetLastChannel returns the last channel from the state.

func (*Manager) GetLastChatID

func (sm *Manager) GetLastChatID() string

GetLastChatID returns the last chat ID from the state.

func (*Manager) GetSessionGoal

func (sm *Manager) GetSessionGoal(routeSessionKey string) (SessionGoal, bool)

GetSessionGoal returns the durable goal for a routed session.

func (*Manager) GetSessionModelOverride

func (sm *Manager) GetSessionModelOverride(routeSessionKey string) (SessionModelOverride, bool)

GetSessionModelOverride returns a persisted manual model selection for a routed session.

func (*Manager) GetSessionOverride

func (sm *Manager) GetSessionOverride(routeSessionKey string) string

GetSessionOverride returns the replacement session key for a routed session.

func (*Manager) GetTimestamp

func (sm *Manager) GetTimestamp() time.Time

GetTimestamp returns the timestamp of the last state update.

func (*Manager) GetToolFeedbackOverride

func (sm *Manager) GetToolFeedbackOverride(routeSessionKey string) (bool, bool)

GetToolFeedbackOverride returns the persisted tool feedback override for a routed session and whether an override is present.

func (*Manager) ResolveSessionEpoch

func (sm *Manager) ResolveSessionEpoch(
	routeScopeKey string,
	policy session.LifecyclePolicy,
	now time.Time,
) (*session.SessionEpoch, error)

func (*Manager) SetAutoModelSelection

func (sm *Manager) SetAutoModelSelection(routeSessionKey string, selection AutoModelSelection) error

SetAutoModelSelection persists a temporary auto-fallback model selection for a routed session.

func (*Manager) SetLastChannel

func (sm *Manager) SetLastChannel(channel string) error

SetLastChannel atomically updates the last channel and saves the state. This method uses a temp file + rename pattern for atomic writes, ensuring that the state file is never corrupted even if the process crashes.

func (*Manager) SetLastChatID

func (sm *Manager) SetLastChatID(chatID string) error

SetLastChatID atomically updates the last chat ID and saves the state.

func (*Manager) SetSessionGoalStatus

func (sm *Manager) SetSessionGoalStatus(
	routeSessionKey string,
	status SessionGoalStatus,
	note string,
) (SessionGoal, error)

SetSessionGoalStatus changes goal state without changing the objective.

func (*Manager) SetSessionModelOverride

func (sm *Manager) SetSessionModelOverride(routeSessionKey, model string) error

SetSessionModelOverride persists a conversation-scoped manual model selection for a routed session.

func (*Manager) SetSessionOverride

func (sm *Manager) SetSessionOverride(routeSessionKey, sessionKey string) error

SetSessionOverride persists a replacement session key for a routed session.

func (*Manager) SetToolFeedbackOverride

func (sm *Manager) SetToolFeedbackOverride(routeSessionKey string, enabled bool) error

SetToolFeedbackOverride persists a tool feedback enable/disable override for a routed session.

func (*Manager) TouchSessionEpoch

func (sm *Manager) TouchSessionEpoch(routeScopeKey, epochID string, now time.Time) error

type SessionEpochState

type SessionEpochState struct {
	Strategy       string    `json:"strategy"`
	EpochID        string    `json:"epoch_id"`
	StartedAt      time.Time `json:"started_at"`
	LastActivityAt time.Time `json:"last_activity_at"`
}

type SessionGoal

type SessionGoal struct {
	Objective   string            `json:"objective"`
	Status      SessionGoalStatus `json:"status"`
	Note        string            `json:"note,omitempty"`
	CreatedAt   time.Time         `json:"created_at"`
	UpdatedAt   time.Time         `json:"updated_at"`
	BlockedAt   *time.Time        `json:"blocked_at,omitempty"`
	CompletedAt *time.Time        `json:"completed_at,omitempty"`
}

type SessionGoalStatus

type SessionGoalStatus string
const (
	SessionGoalActive   SessionGoalStatus = "active"
	SessionGoalPaused   SessionGoalStatus = "paused"
	SessionGoalBlocked  SessionGoalStatus = "blocked"
	SessionGoalComplete SessionGoalStatus = "complete"
)

type SessionModelOverride

type SessionModelOverride struct {
	Model     string    `json:"model,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

type State

type State struct {
	// LastChannel is the last channel used for communication
	LastChannel string `json:"last_channel,omitempty"`

	// LastChatID is the last chat ID used for communication
	LastChatID string `json:"last_chat_id,omitempty"`

	// SessionOverrides maps the default routed session key for a conversation
	// onto an explicit replacement session key created by a soft reset.
	SessionOverrides map[string]string `json:"session_overrides,omitempty"`

	// ToolFeedbackOverrides stores per-routed-session enable/disable overrides
	// for inline tool feedback such as working_summary.
	ToolFeedbackOverrides map[string]bool `json:"tool_feedback_overrides,omitempty"`

	// SessionModelOverrides stores manual model selections scoped to a routed
	// conversation. The stored value is the canonical configured model alias.
	SessionModelOverrides map[string]SessionModelOverride `json:"session_model_overrides,omitempty"`

	// AutoModelSelections stores temporary session-scoped auto-fallback routing
	// state. SelectedModel identifies the user's intended model; ActiveModel is
	// the temporary fallback model currently pinned for the conversation.
	AutoModelSelections map[string]AutoModelSelection `json:"auto_model_selections,omitempty"`

	// SessionGoals stores one durable operator objective per routed session.
	SessionGoals map[string]SessionGoal `json:"session_goals,omitempty"`

	// SessionEpochs stores lifecycle checkpoints for stateful idle and max-age
	// rotation. Keys are stable trusted route-scope keys.
	SessionEpochs map[string]SessionEpochState `json:"session_epochs,omitempty"`

	// Timestamp is the last time this state was updated
	Timestamp time.Time `json:"timestamp"`
}

State represents the persistent state for a workspace. It includes information about the last active channel/chat.

Jump to

Keyboard shortcuts

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