Documentation
¶
Overview ¶
Package session manages ephemeral session lifecycle: IDs, per-session directory paths, metadata persistence, and feed serialization for replay.
Index ¶
- func CollectForUpload(baseDir string, since time.Time, nameLookup func(string) string) []api.SessionUpload
- func GenerateID() string
- func LatestID(baseDir string) (string, error)
- func Resolve(baseDir, prefix string) (string, error)
- func SaveContent(path string, c SessionContent) error
- func SaveMetadata(path string, m SessionMetadata) error
- func SummarizeAcrossSessions(baseDir string, filter *StatsFilter) map[string]int
- func SummarizeDetailedAcrossSessions(baseDir string, filter *StatsFilter) map[string]ModelStats
- func SummarizeRuns(runs []RunSummary, filter *StatsFilter) map[string]int
- func SummarizeRunsDetailed(runs []RunSummary, filter *StatsFilter) map[string]ModelStats
- type Meta
- type ModelRunContent
- type ModelStats
- type Paths
- type RunContent
- type RunSummary
- type SessionContent
- type SessionMetadata
- type StatsFilter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectForUpload ¶
func CollectForUpload(baseDir string, since time.Time, nameLookup func(string) string) []api.SessionUpload
CollectForUpload walks session metadata and returns redacted upload payloads. Sessions with LastActiveAt on or before since are skipped (zero since includes all). nameLookup resolves a config hash to a recipe name; it may return "".
func GenerateID ¶
func GenerateID() string
GenerateID returns a type-prefixed UUID v7 session ID (e.g. "ses_019505e2-...").
func Resolve ¶
Resolve resolves a session ID by exact match or unique prefix. Returns an error if the prefix is ambiguous or no match is found.
func SaveContent ¶
func SaveContent(path string, c SessionContent) error
SaveContent atomically writes session content to path.
func SaveMetadata ¶
func SaveMetadata(path string, m SessionMetadata) error
SaveMetadata atomically writes session metadata to path.
func SummarizeAcrossSessions ¶
func SummarizeAcrossSessions(baseDir string, filter *StatsFilter) map[string]int
SummarizeAcrossSessions aggregates win tallies across all sessions in baseDir.
func SummarizeDetailedAcrossSessions ¶
func SummarizeDetailedAcrossSessions(baseDir string, filter *StatsFilter) map[string]ModelStats
SummarizeDetailedAcrossSessions aggregates detailed stats across all sessions.
func SummarizeRuns ¶
func SummarizeRuns(runs []RunSummary, filter *StatsFilter) map[string]int
SummarizeRuns returns a model_id → win_count tally from runs. Rewound runs are excluded.
func SummarizeRunsDetailed ¶
func SummarizeRunsDetailed(runs []RunSummary, filter *StatsFilter) map[string]ModelStats
SummarizeRunsDetailed computes per-model analytics from runs. Rewound runs are excluded.
Types ¶
type Meta ¶
type Meta = SessionMetadata
Meta is an alias for SessionMetadata used by session listing.
type ModelRunContent ¶
type ModelRunContent struct {
ModelID string `json:"model_id"`
Text string `json:"text"`
ProposedWrites []output.WriteEntry `json:"proposed_writes,omitempty"`
Events []output.EventEntry `json:"events"`
StopReason string `json:"stop_reason,omitempty"`
Steps int `json:"steps,omitempty"`
ReasoningTokens int64 `json:"reasoning_tokens,omitempty"`
}
ModelRunContent holds the full response data for one model in a run.
type ModelStats ¶
type ModelStats struct {
Wins int
Losses int // times model was in a run where a different model was selected
ThumbsDown int // times model received a single-model thumbs-down rating
Participations int // times model appeared in any recorded run
WinRate float64 // Wins / Participations * 100; 0 if Participations == 0
LossRate float64 // Losses / Participations * 100
BadRate float64 // ThumbsDown / Participations * 100
AvgLatencyMS float64
AvgCostUSD float64
AvgInputTokens float64
AvgOutputTokens float64
AvgToolCalls float64
AvgProposedWrites float64
}
ModelStats holds detailed per-model analytics derived from run summaries.
type Paths ¶
type Paths struct {
Dir string
MetadataPath string
ContentPath string
CheckpointPath string
RecipePath string
}
Paths holds the per-session file paths.
type RunContent ¶
type RunContent struct {
Prompt string `json:"prompt"`
Models []ModelRunContent `json:"models"`
}
RunContent holds the full prompt and per-model response data for one run.
type RunSummary ¶
type RunSummary struct {
Timestamp time.Time `json:"timestamp"`
PromptHash string `json:"prompt_hash"`
PromptPreview string `json:"prompt_preview"`
Models []string `json:"models"`
Selected string `json:"selected,omitempty"`
Rating string `json:"rating,omitempty"`
Type string `json:"type,omitempty"` // "" | "rewind"
LatenciesMS map[string]int64 `json:"latencies_ms,omitempty"`
CostsUSD map[string]float64 `json:"costs_usd,omitempty"`
InputTokens map[string]int64 `json:"input_tokens,omitempty"`
OutputTokens map[string]int64 `json:"output_tokens,omitempty"`
ToolCalls map[string]map[string]int `json:"tool_calls,omitempty"`
ProposedWritesCount map[string]int `json:"proposed_writes_count,omitempty"`
AppliedFiles []string `json:"applied_files,omitempty"`
ConfigHash string `json:"config_hash,omitempty"`
Note string `json:"note,omitempty"`
}
RunSummary captures per-run metadata without full response text.
type SessionContent ¶
type SessionContent struct {
Runs []RunContent `json:"runs"`
Histories map[string][]models.ConversationTurn `json:"histories,omitempty"`
}
SessionContent holds the full prompts, responses, events, and conversation histories for a session (session_content.json).
func LoadContent ¶
func LoadContent(path string) (*SessionContent, error)
LoadContent reads session content from path. Returns (nil, nil) if the file does not exist.
type SessionMetadata ¶
type SessionMetadata struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
LastActiveAt time.Time `json:"last_active_at"`
Models []string `json:"models,omitempty"`
FirstPrompt string `json:"first_prompt,omitempty"`
LastPrompt string `json:"last_prompt,omitempty"`
PromptCount int `json:"prompt_count"`
ConfigHash string `json:"config_hash,omitempty"`
Runs []RunSummary `json:"runs"`
}
SessionMetadata is the lightweight per-session file (session_metadata.json). It holds stats, summaries, and run-level analytics — everything needed to list sessions, compute /stats, and decide what to share/upload.
func LoadMetadata ¶
func LoadMetadata(path string) (*SessionMetadata, error)
LoadMetadata reads session metadata from path. Returns (nil, nil) if the file does not exist.
type StatsFilter ¶
type StatsFilter struct {
ConfigHash string // if non-empty, only include runs with this config hash
SessionID string // if non-empty, only include runs from this session
}
StatsFilter controls which runs are included in Summarize functions. A nil filter matches all runs.