session

package
v0.0.0-...-ae22df4 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextSummary

type ContextSummary struct {
	UserPrompt    string   `json:"user_prompt,omitempty"`
	RecentActions []string `json:"recent_actions,omitempty"`
	Trigger       string   `json:"trigger,omitempty"`
}

ContextSummary stores a compact audit summary instead of full raw context.

type DisplayApproval

type DisplayApproval struct {
	ID        string                    `json:"id,omitempty"`
	TurnID    string                    `json:"turn_id,omitempty"`
	Pending   []DisplayPendingApproval  `json:"pending,omitempty"`
	Decisions []DisplayApprovalDecision `json:"decisions,omitempty"`
}

type DisplayApprovalDecision

type DisplayApprovalDecision struct {
	ToolCallID   string `json:"tool_call_id,omitempty"`
	Approved     bool   `json:"approved"`
	Reason       string `json:"reason,omitempty"`
	ModifiedArgs string `json:"modified_args,omitempty"`
}

type DisplayContentPart

type DisplayContentPart struct {
	Type       string             `json:"type"`
	Text       string             `json:"text,omitempty"`
	ToolCall   *DisplayToolCall   `json:"tool_call,omitempty"`
	ToolResult *DisplayToolResult `json:"tool_result,omitempty"`
}

type DisplayItem

type DisplayItem struct {
	ID        string               `json:"id"`
	Sequence  uint64               `json:"sequence"`
	Type      DisplayItemType      `json:"type"`
	Role      string               `json:"role,omitempty"`
	Content   []DisplayContentPart `json:"content,omitempty"`
	Turn      *DisplayTurn         `json:"turn,omitempty"`
	Approval  *DisplayApproval     `json:"approval,omitempty"`
	Error     string               `json:"error,omitempty"`
	CreatedAt time.Time            `json:"created_at"`
}

type DisplayItemType

type DisplayItemType string
const (
	DisplayItemUserMessage      DisplayItemType = "user_message"
	DisplayItemAssistantMessage DisplayItemType = "assistant_message"
	DisplayItemError            DisplayItemType = "error"
	DisplayItemTurnStarted      DisplayItemType = "turn_started"
	DisplayItemTurnPaused       DisplayItemType = "turn_paused"
	DisplayItemTurnCompleted    DisplayItemType = "turn_completed"
	DisplayItemTurnFailed       DisplayItemType = "turn_failed"
	DisplayItemTurnInterrupted  DisplayItemType = "turn_interrupted"
	DisplayItemApprovalRequest  DisplayItemType = "approval_request"
	DisplayItemApprovalDecision DisplayItemType = "approval_decision"
	DisplayItemContextCompacted DisplayItemType = "context_compacted"
)

type DisplayMediaPart

type DisplayMediaPart struct {
	Data      []byte `json:"data,omitempty"`
	URL       string `json:"url,omitempty"`
	FileID    string `json:"file_id,omitempty"`
	MediaType string `json:"media_type,omitempty"`
}

type DisplayPage

type DisplayPage struct {
	Items      []DisplayItem
	NextCursor string
	PrevCursor string
	HasMore    bool
}

func PageDisplayItems

func PageDisplayItems(items []DisplayItem, query DisplayPageQuery) DisplayPage

type DisplayPageQuery

type DisplayPageQuery struct {
	Limit     int
	After     uint64
	Before    uint64
	HasAfter  bool
	HasBefore bool
}

type DisplayPendingApproval

type DisplayPendingApproval struct {
	ToolCallID       string `json:"tool_call_id,omitempty"`
	ToolName         string `json:"tool_name,omitempty"`
	Arguments        string `json:"arguments,omitempty"`
	Description      string `json:"description,omitempty"`
	Reason           string `json:"reason,omitempty"`
	RiskLevel        string `json:"risk_level,omitempty"`
	Source           string `json:"source,omitempty"`
	RequiresSnapshot bool   `json:"requires_snapshot,omitempty"`
}

type DisplayToolCall

type DisplayToolCall struct {
	ID        string `json:"id,omitempty"`
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

type DisplayToolResult

type DisplayToolResult struct {
	ToolCallID string                         `json:"tool_call_id,omitempty"`
	ToolName   string                         `json:"tool_name,omitempty"`
	ResultType string                         `json:"result_type,omitempty"`
	Text       string                         `json:"text,omitempty"`
	JSON       any                            `json:"json,omitempty"`
	Reason     string                         `json:"reason,omitempty"`
	Content    []DisplayToolResultContentPart `json:"content,omitempty"`
	IsError    bool                           `json:"is_error,omitempty"`
}

type DisplayToolResultContentPart

type DisplayToolResultContentPart struct {
	Type  string            `json:"type"`
	Text  string            `json:"text,omitempty"`
	Image *DisplayMediaPart `json:"image,omitempty"`
}

type DisplayTurn

type DisplayTurn struct {
	ID                   string `json:"id,omitempty"`
	Reason               string `json:"reason,omitempty"`
	Status               string `json:"status,omitempty"`
	ProviderFinishReason string `json:"provider_finish_reason,omitempty"`
	LastAgentMessage     string `json:"last_agent_message,omitempty"`
	DurationMS           int64  `json:"duration_ms,omitempty"`
}

type FileStore

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

FileStore implements Store using the local filesystem. Sessions are stored as JSON files in a configurable directory.

func NewFileStore

func NewFileStore(rootDir string) (*FileStore, error)

NewFileStore creates a new file-based session store. If rootDir is empty, it defaults to ~/.zotigo

func (*FileStore) AppendDisplayItem

func (s *FileStore) AppendDisplayItem(ctx context.Context, id string, item DisplayItem) (DisplayItem, error)

func (*FileStore) Close

func (s *FileStore) Close() error

Close releases any resources.

func (*FileStore) Delete

func (s *FileStore) Delete(ctx context.Context, id string) error

Delete removes a session by ID.

func (*FileStore) Get

func (s *FileStore) Get(ctx context.Context, id string) (*Session, error)

Get retrieves a session by ID.

func (*FileStore) IsLocked

func (s *FileStore) IsLocked(ctx context.Context, id string) (bool, error)

IsLocked checks if a session is currently locked.

func (*FileStore) List

func (s *FileStore) List(ctx context.Context, filter ListFilter) ([]Metadata, error)

List returns all sessions matching the filter.

func (*FileStore) ListDisplayItems

func (s *FileStore) ListDisplayItems(ctx context.Context, id string) ([]DisplayItem, bool, error)

func (*FileStore) Lock

func (s *FileStore) Lock(ctx context.Context, id string) error

Lock acquires an exclusive lock on a session.

func (*FileStore) Put

func (s *FileStore) Put(ctx context.Context, sess *Session) error

Put stores a session.

func (*FileStore) Unlock

func (s *FileStore) Unlock(ctx context.Context, id string) error

Unlock releases the lock on a session.

type ListFilter

type ListFilter struct {
	// WorkingDirectory filters by project path.
	// Empty string means no filter.
	WorkingDirectory string

	// Limit limits the number of results.
	// 0 means no limit.
	Limit int

	// OrderBy specifies the sort order.
	OrderBy OrderBy
}

ListFilter defines filtering criteria for listing sessions.

type Manager

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

Manager handles session storage, retrieval, and locking. It uses a Store backend for persistence.

func NewManager

func NewManager() (*Manager, error)

NewManager creates a new Manager with the default FileStore.

func NewManagerWithStore

func NewManagerWithStore(store Store) *Manager

NewManagerWithStore creates a new Manager with a custom Store backend.

func (*Manager) AppendDisplayItem

func (m *Manager) AppendDisplayItem(id string, item DisplayItem) (DisplayItem, error)

func (*Manager) Close

func (m *Manager) Close() error

Close closes the underlying store.

func (*Manager) CreateNew

func (m *Manager) CreateNew(workDir string) (*Session, error)

CreateNew initializes a new session for the current directory.

func (*Manager) Delete

func (m *Manager) Delete(id string) error

Delete removes a session from the store.

func (*Manager) IsLocked

func (m *Manager) IsLocked(id string) bool

IsLocked checks if a session is currently locked.

func (*Manager) ListByDir

func (m *Manager) ListByDir(workDir string) ([]Metadata, error)

ListByDir returns all sessions for a given directory, sorted by UpdatedAt desc.

func (*Manager) ListDisplayItems

func (m *Manager) ListDisplayItems(id string) ([]DisplayItem, bool, error)

func (*Manager) Load

func (m *Manager) Load(id string) (*Session, error)

Load reads a session from the store.

func (*Manager) Lock

func (m *Manager) Lock(id string) error

Lock creates a lock on the session.

func (*Manager) Save

func (m *Manager) Save(sess *Session) error

Save writes the session to the store.

func (*Manager) Unlock

func (m *Manager) Unlock(id string) error

Unlock releases the lock on the session.

type Metadata

type Metadata struct {
	ID               string    `json:"id"`
	WorkingDirectory string    `json:"working_directory"` // The project path this session belongs to
	LastPrompt       string    `json:"last_prompt"`       // Preview of the last user interaction
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

Metadata holds the summary info for listing/indexing.

type OrderBy

type OrderBy int

OrderBy defines sort order options.

const (
	// OrderByUpdatedDesc sorts by UpdatedAt descending (newest first).
	OrderByUpdatedDesc OrderBy = iota
	// OrderByUpdatedAsc sorts by UpdatedAt ascending (oldest first).
	OrderByUpdatedAsc
	// OrderByCreatedDesc sorts by CreatedAt descending.
	OrderByCreatedDesc
	// OrderByCreatedAsc sorts by CreatedAt ascending.
	OrderByCreatedAsc
)

type SafetyDecision

type SafetyDecision string

SafetyDecision captures the outcome of a safety gate.

const (
	SafetyDecisionAllow   SafetyDecision = "allow"
	SafetyDecisionDeny    SafetyDecision = "deny"
	SafetyDecisionAskUser SafetyDecision = "ask_user"
)

type SafetyDecisionSource

type SafetyDecisionSource string

SafetyDecisionSource identifies where a safety decision came from.

const (
	SafetyDecisionSourceHardRule     SafetyDecisionSource = "hard_rule"
	SafetyDecisionSourceClassifier   SafetyDecisionSource = "classifier"
	SafetyDecisionSourceUserApproval SafetyDecisionSource = "user_approval"
)

type SafetyEvent

type SafetyEvent struct {
	Timestamp          time.Time            `json:"timestamp"`
	TurnID             string               `json:"turn_id"`
	ToolCallID         string               `json:"tool_call_id,omitempty"`
	ToolName           string               `json:"tool_name,omitempty"`
	ToolArgsSummary    string               `json:"tool_args_summary,omitempty"`
	DecisionSource     SafetyDecisionSource `json:"decision_source"`
	Decision           SafetyDecision       `json:"decision"`
	Reason             string               `json:"reason,omitempty"`
	RiskLevel          string               `json:"risk_level,omitempty"`
	SnapshotStatus     SnapshotStatus       `json:"snapshot_status,omitempty"`
	SnapshotID         string               `json:"snapshot_id,omitempty"`
	ClassifierProvider string               `json:"classifier_provider,omitempty"`
	ClassifierModel    string               `json:"classifier_model,omitempty"`
	ContextSummary     ContextSummary       `json:"context_summary,omitempty"`
	RawContext         string               `json:"raw_context,omitempty"`
}

SafetyEvent stores a compact auditable safety decision tied to a turn.

type Session

type Session struct {
	Metadata
	AgentSnapshot agent.Snapshot `json:"agent_snapshot"`
	Turns         []Turn         `json:"turns,omitempty"`
}

Session represents the full state on disk.

func (*Session) EnsureInitialized

func (s *Session) EnsureInitialized()

EnsureInitialized backfills fields added in newer versions so old sessions remain usable.

type SnapshotStatus

type SnapshotStatus string

SnapshotStatus captures snapshot behavior for a turn or event.

const (
	SnapshotStatusNotNeeded      SnapshotStatus = "not_needed"
	SnapshotStatusCreated        SnapshotStatus = "created"
	SnapshotStatusFailed         SnapshotStatus = "failed"
	SnapshotStatusMissingGitRepo SnapshotStatus = "missing_git_repo"
	// SnapshotStatusNotInstalled mirrors agent.SnapshotStatusNotInstalled for
	// persistence; kept in sync with that source of truth.
	SnapshotStatusNotInstalled SnapshotStatus = "not_installed"
)

type Store

type Store interface {
	// Get retrieves a session by ID.
	// Returns nil if not found.
	Get(ctx context.Context, id string) (*Session, error)

	// Put stores a session.
	Put(ctx context.Context, sess *Session) error

	// AppendDisplayItem appends one display-log item to the session's per-session log.
	AppendDisplayItem(ctx context.Context, id string, item DisplayItem) (DisplayItem, error)

	// ListDisplayItems returns the session's per-session display log.
	ListDisplayItems(ctx context.Context, id string) ([]DisplayItem, bool, error)

	// Delete removes a session by ID.
	Delete(ctx context.Context, id string) error

	// List returns all sessions matching the filter.
	List(ctx context.Context, filter ListFilter) ([]Metadata, error)

	// Lock acquires an exclusive lock on a session.
	// Returns error if already locked.
	Lock(ctx context.Context, id string) error

	// Unlock releases the lock on a session.
	Unlock(ctx context.Context, id string) error

	// IsLocked checks if a session is currently locked.
	IsLocked(ctx context.Context, id string) (bool, error)

	// Close releases any resources held by the store.
	Close() error
}

Store defines the interface for session storage backends. Implementations can be file-based (local), Redis, database, etc.

type Turn

type Turn struct {
	ID                string         `json:"id"`
	CreatedAt         time.Time      `json:"created_at"`
	UpdatedAt         time.Time      `json:"updated_at"`
	UserPromptSummary string         `json:"user_prompt_summary,omitempty"`
	SafetyEvents      []SafetyEvent  `json:"safety_events,omitempty"`
	SnapshotStatus    SnapshotStatus `json:"snapshot_status,omitempty"`
	SnapshotID        string         `json:"snapshot_id,omitempty"`
}

Turn stores compact turn-scoped execution metadata for auditing.

Jump to

Keyboard shortcuts

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