Documentation
¶
Overview ¶
Package session provides the session model for agent working sessions.
Index ¶
- type Session
- type SessionFilter
- func (f *SessionFilter) WithAgent(agent string) *SessionFilter
- func (f *SessionFilter) WithAgents(agents []string) *SessionFilter
- func (f *SessionFilter) WithCommandPattern(p string) *SessionFilter
- func (f *SessionFilter) WithEventActions(actions []string) *SessionFilter
- func (f *SessionFilter) WithEventSince(t time.Time) *SessionFilter
- func (f *SessionFilter) WithEventStatuses(statuses []string) *SessionFilter
- func (f *SessionFilter) WithEventUntil(t time.Time) *SessionFilter
- func (f *SessionFilter) WithFilePattern(p string) *SessionFilter
- func (f *SessionFilter) WithHasBlocked(v bool) *SessionFilter
- func (f *SessionFilter) WithHasErrors(v bool) *SessionFilter
- func (f *SessionFilter) WithHasSensitive(v bool) *SessionFilter
- func (f *SessionFilter) WithLimit(limit int) *SessionFilter
- func (f *SessionFilter) WithSince(t time.Time) *SessionFilter
- func (f *SessionFilter) WithUntil(t time.Time) *SessionFilter
- type SessionStats
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct {
// ID is the unique identifier for this session.
// For agents that provide their own session_id, this is a deterministic UUID derived from it.
ID uuid.UUID `json:"id"`
// AgentSessionID is the original session ID from the agent (e.g., Claude Code's session_id).
// Stored for correlation with agent's own storage. May be empty if agent doesn't provide one.
AgentSessionID string `json:"agent_session_id,omitempty"`
// AgentName is the agent identifier (e.g., "claude-code").
AgentName string `json:"agent_name"`
// AgentVersion is the agent version if detectable.
AgentVersion string `json:"agent_version,omitempty"`
// StartedAt is the session start time (UTC).
StartedAt time.Time `json:"started_at"`
// EndedAt is the session end time (UTC), zero if ongoing.
EndedAt time.Time `json:"ended_at,omitempty"`
// WorkingDirectory is the absolute path where agent was invoked.
WorkingDirectory string `json:"working_directory,omitempty"`
// ProjectName is detected from package.json, Cargo.toml, etc.
ProjectName string `json:"project_name,omitempty"`
// TotalActions is the count of events (denormalized).
TotalActions int `json:"total_actions"`
// FilesRead is the count of file_read actions.
FilesRead int `json:"files_read"`
// FilesWritten is the count of file_write actions.
FilesWritten int `json:"files_written"`
// CommandsExecuted is the count of command_exec actions.
CommandsExecuted int `json:"commands_executed"`
// Errors is the count of events with error status.
Errors int `json:"errors"`
SensitiveActions int `json:"sensitive_actions"`
BlockedActions int `json:"blocked_actions"`
// TranscriptPath is the path to the agent's transcript file.
TranscriptPath string `json:"transcript_path,omitempty"`
// InputTokens is the total input tokens across all models (denormalized).
InputTokens int64 `json:"input_tokens,omitempty"`
// OutputTokens is the total output tokens across all models (denormalized).
OutputTokens int64 `json:"output_tokens,omitempty"`
// CacheReadTokens is the total cache read tokens (denormalized).
CacheReadTokens int64 `json:"cache_read_tokens,omitempty"`
// CacheWriteTokens is the total cache write tokens (denormalized).
CacheWriteTokens int64 `json:"cache_write_tokens,omitempty"`
// EstimatedCostUSD is the estimated total cost in USD (denormalized).
EstimatedCostUSD float64 `json:"estimated_cost_usd,omitempty"`
// ModelUsage stores the per-model token breakdown (source of truth).
ModelUsage []cost.ModelUsage `json:"model_usage,omitempty"`
// CostSource indicates where cost data came from.
CostSource string `json:"cost_source,omitempty"`
// CostComputedAt is when cost was last computed.
CostComputedAt *time.Time `json:"cost_computed_at,omitempty"`
}
Session represents a single agent working session.
func NewSession ¶
NewSession creates a new Session with a generated UUID and current timestamp.
func NewSessionWithID ¶
NewSessionWithID creates a new Session with the given ID.
func (*Session) Duration ¶
Duration returns the duration of the session. If the session is still active, it returns the duration since start.
func (*Session) End ¶
func (s *Session) End()
End marks the session as ended with the current timestamp.
func (*Session) HasCostData ¶ added in v0.4.0
HasCostData returns true if cost data has been computed for this session.
type SessionFilter ¶
type SessionFilter struct {
// AgentName filters by a specific agent.
AgentName string
// Since filters sessions started after this time.
Since *time.Time
// Until filters sessions started before this time.
Until *time.Time
// ActiveOnly filters to only active sessions.
ActiveOnly bool
// Limit is the maximum number of results.
Limit int
// Offset is the number of results to skip.
Offset int
AgentNames []string
HasErrors *bool
HasSensitive *bool
HasBlocked *bool
EventSince *time.Time
EventUntil *time.Time
EventActions []string
EventStatuses []string
FilePattern string
CommandPattern string
}
SessionFilter provides filtering criteria for querying sessions.
func NewSessionFilter ¶
func NewSessionFilter() *SessionFilter
NewSessionFilter creates a new SessionFilter with default values.
func (*SessionFilter) WithAgent ¶
func (f *SessionFilter) WithAgent(agent string) *SessionFilter
WithAgent sets the AgentName filter.
func (*SessionFilter) WithAgents ¶ added in v0.5.0
func (f *SessionFilter) WithAgents(agents []string) *SessionFilter
func (*SessionFilter) WithCommandPattern ¶ added in v0.5.0
func (f *SessionFilter) WithCommandPattern(p string) *SessionFilter
func (*SessionFilter) WithEventActions ¶ added in v0.5.0
func (f *SessionFilter) WithEventActions(actions []string) *SessionFilter
func (*SessionFilter) WithEventSince ¶ added in v0.5.0
func (f *SessionFilter) WithEventSince(t time.Time) *SessionFilter
func (*SessionFilter) WithEventStatuses ¶ added in v0.5.0
func (f *SessionFilter) WithEventStatuses(statuses []string) *SessionFilter
func (*SessionFilter) WithEventUntil ¶ added in v0.5.0
func (f *SessionFilter) WithEventUntil(t time.Time) *SessionFilter
func (*SessionFilter) WithFilePattern ¶ added in v0.5.0
func (f *SessionFilter) WithFilePattern(p string) *SessionFilter
func (*SessionFilter) WithHasBlocked ¶ added in v0.5.0
func (f *SessionFilter) WithHasBlocked(v bool) *SessionFilter
func (*SessionFilter) WithHasErrors ¶ added in v0.5.0
func (f *SessionFilter) WithHasErrors(v bool) *SessionFilter
func (*SessionFilter) WithHasSensitive ¶ added in v0.5.0
func (f *SessionFilter) WithHasSensitive(v bool) *SessionFilter
func (*SessionFilter) WithLimit ¶
func (f *SessionFilter) WithLimit(limit int) *SessionFilter
WithLimit sets the Limit.
func (*SessionFilter) WithSince ¶
func (f *SessionFilter) WithSince(t time.Time) *SessionFilter
WithSince sets the Since filter.
func (*SessionFilter) WithUntil ¶ added in v0.3.3
func (f *SessionFilter) WithUntil(t time.Time) *SessionFilter
WithUntil sets the Until filter.
type SessionStats ¶
type SessionStats struct {
// TotalSessions is the total number of sessions.
TotalSessions int `json:"total_sessions"`
// ActiveSessions is the number of currently active sessions.
ActiveSessions int `json:"active_sessions"`
// TotalEvents is the total number of events across all sessions.
TotalEvents int `json:"total_events"`
// TotalFilesRead is the total files read across all sessions.
TotalFilesRead int `json:"total_files_read"`
// TotalFilesWritten is the total files written across all sessions.
TotalFilesWritten int `json:"total_files_written"`
// TotalCommandsExecuted is the total commands executed across all sessions.
TotalCommandsExecuted int `json:"total_commands_executed"`
// TotalErrors is the total errors across all sessions.
TotalErrors int `json:"total_errors"`
// OldestSession is the timestamp of the oldest session.
OldestSession time.Time `json:"oldest_session,omitempty"`
// NewestSession is the timestamp of the newest session.
NewestSession time.Time `json:"newest_session,omitempty"`
// SessionsByAgent maps agent names to session counts.
SessionsByAgent map[string]int `json:"sessions_by_agent,omitempty"`
}
SessionStats provides aggregated statistics about sessions.
func NewSessionStats ¶
func NewSessionStats() *SessionStats
NewSessionStats creates a new empty SessionStats.
func (*SessionStats) AddSession ¶
func (s *SessionStats) AddSession(session *Session)
AddSession updates the stats with data from a session.
type Summary ¶
type Summary struct {
// ActionsCount is the total number of actions.
ActionsCount int
// LinesChanged is the total lines added + removed.
LinesChanged int
// LinesAdded is the total lines added.
LinesAdded int
// LinesRemoved is the total lines removed.
LinesRemoved int
// CommandsCount is the number of commands executed.
CommandsCount int
// CommandsPassed is the number of commands that passed (exit 0).
CommandsPassed int
// CommandsFailed is the number of commands that failed (non-zero exit).
CommandsFailed int
// FilesReadCount is the number of files read.
FilesReadCount int
// FilesWrittenCount is the number of files written.
FilesWrittenCount int
}
Summary provides a human-readable summary of session activity.