Documentation
¶
Index ¶
- func CurrentWorkspacePath() string
- func DefaultDir() (string, error)
- func EndpointStatsKey(vendor, endpoint string) string
- func ExportSessionMarkdown(ses *Session) string
- func LastTurnIndex(ses *Session) int
- func NormalizeWorkspacePath(path string) string
- type JSONLStore
- func (s *JSONLStore) AppendCheckpoint(ses *Session, compactedMessages []provider.Message, tokenCount int) error
- func (s *JSONLStore) AppendCheckpointToDisk(ses *Session, compactedMessages []provider.Message, tokenCount int) error
- func (s *JSONLStore) AppendMessage(ses *Session, msg provider.Message) error
- func (s *JSONLStore) AppendMessageToDisk(ses *Session, msg provider.Message) error
- func (s *JSONLStore) AppendMetaToDisk(ses *Session) error
- func (s *JSONLStore) AppendMetric(ses *Session, m metrics.MetricEvent) error
- func (s *JSONLStore) AppendTunnelEventToDisk(ses *Session, ev TunnelEvent) error
- func (s *JSONLStore) AppendUsageEntry(ses *Session, entry UsageEntry) error
- func (s *JSONLStore) CleanupOlderThan(before time.Time) (int, error)
- func (s *JSONLStore) Delete(id string) error
- func (s *JSONLStore) Dir() string
- func (s *JSONLStore) EnsureMeta(ses *Session) error
- func (s *JSONLStore) ExportMarkdown(id string) (string, error)
- func (s *JSONLStore) List() ([]*Session, error)
- func (s *JSONLStore) Load(id string) (*Session, error)
- func (s *JSONLStore) Save(ses *Session) error
- type Session
- func (s *Session) AddUsageForEndpoint(vendor, endpoint string, usage provider.TokenUsage)
- func (s *Session) AppendMetricForEndpoint(vendor, endpoint string, ev metrics.MetricEvent)
- func (s *Session) HasUserInteraction() bool
- func (s *Session) MetricsForEndpoint(vendor, endpoint string) []metrics.MetricEvent
- func (s *Session) RebuildEndpointStats()
- func (s *Session) UsageForEndpoint(vendor, endpoint string) provider.TokenUsage
- type Store
- type TunnelEvent
- type UsageEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentWorkspacePath ¶ added in v1.0.23
func CurrentWorkspacePath() string
func DefaultDir ¶
DefaultDir returns the default session directory.
func EndpointStatsKey ¶ added in v1.3.44
func ExportSessionMarkdown ¶
ExportSessionMarkdown renders a Session to markdown.
func LastTurnIndex ¶ added in v1.3.44
func NormalizeWorkspacePath ¶ added in v1.0.23
Types ¶
type JSONLStore ¶
type JSONLStore struct {
// contains filtered or unexported fields
}
JSONLStore implements Store using JSONL files.
func NewDefaultStore ¶
func NewDefaultStore() (*JSONLStore, error)
NewDefaultStore creates a store in the default directory.
func NewJSONLStore ¶
func NewJSONLStore(dir string) (*JSONLStore, error)
NewJSONLStore creates a store rooted at dir (creates dir if needed).
func (*JSONLStore) AppendCheckpoint ¶ added in v1.1.43
func (s *JSONLStore) AppendCheckpoint(ses *Session, compactedMessages []provider.Message, tokenCount int) error
AppendCheckpoint appends a checkpoint record to the session JSONL file. The checkpoint captures the compacted messages state after a summarize operation, so that future --resume operations can skip re-compacting old history. AppendCheckpoint persists a checkpoint (compaction snapshot) to the session's JSONL file and updates the Session object in place. The caller must ensure no concurrent access to the Session object.
func (*JSONLStore) AppendCheckpointToDisk ¶ added in v1.1.60
func (s *JSONLStore) AppendCheckpointToDisk(ses *Session, compactedMessages []provider.Message, tokenCount int) error
AppendCheckpointToDisk persists a checkpoint to the session's JSONL file and updates the index, but does NOT modify the Session object. Use this when the caller manages Session mutations under its own lock and only needs the disk write to happen outside that lock.
func (*JSONLStore) AppendMessage ¶
func (s *JSONLStore) AppendMessage(ses *Session, msg provider.Message) error
AppendMessage atomically appends a single message to the session's JSONL file. This is more efficient than Save() for incremental updates. AppendMessage persists a message to the session's JSONL file and updates the Session object in place (Messages, UpdatedAt, Title). The caller must ensure no concurrent access to the Session object.
func (*JSONLStore) AppendMessageToDisk ¶ added in v1.1.59
func (s *JSONLStore) AppendMessageToDisk(ses *Session, msg provider.Message) error
AppendMessageToDisk persists a message to the session's JSONL file and updates the index, but does NOT modify the Session object. Use this when the caller manages Session mutations under its own lock (e.g. sessionMutex in the TUI), and only needs the disk write to happen outside that lock.
func (*JSONLStore) AppendMetaToDisk ¶ added in v1.3.40
func (s *JSONLStore) AppendMetaToDisk(ses *Session) error
AppendMetaToDisk persists the latest session metadata as an additional meta record. Load applies the last meta record, so this updates fields like title, model, and token usage without rewriting the full session file.
func (*JSONLStore) AppendMetric ¶ added in v1.3.43
func (s *JSONLStore) AppendMetric(ses *Session, m metrics.MetricEvent) error
AppendMetric persists a performance metric record to the session's JSONL file.
func (*JSONLStore) AppendTunnelEventToDisk ¶ added in v1.3.20
func (s *JSONLStore) AppendTunnelEventToDisk(ses *Session, ev TunnelEvent) error
AppendTunnelEventToDisk persists a canonical tunnel event to the session's JSONL file and updates the index, but does NOT mutate the Session object.
func (*JSONLStore) AppendUsageEntry ¶ added in v1.3.43
func (s *JSONLStore) AppendUsageEntry(ses *Session, entry UsageEntry) error
AppendUsageEntry persists a per-turn usage record to the session's JSONL file. Each record captures the token consumption of a single LLM API call.
func (*JSONLStore) CleanupOlderThan ¶
func (s *JSONLStore) CleanupOlderThan(before time.Time) (int, error)
CleanupOlderThan removes sessions older than the given time. Returns count removed.
func (*JSONLStore) Delete ¶
func (s *JSONLStore) Delete(id string) error
Delete removes a session file and its index entry.
func (*JSONLStore) EnsureMeta ¶
func (s *JSONLStore) EnsureMeta(ses *Session) error
EnsureMeta writes the meta record if the session file doesn't exist yet. If the session has no user interaction, no file is created.
func (*JSONLStore) ExportMarkdown ¶
func (s *JSONLStore) ExportMarkdown(id string) (string, error)
ExportMarkdown renders a session as a markdown document.
func (*JSONLStore) List ¶
func (s *JSONLStore) List() ([]*Session, error)
List returns all sessions sorted by UpdatedAt descending (uses index for speed).
func (*JSONLStore) Load ¶
func (s *JSONLStore) Load(id string) (*Session, error)
Load reads a session from its JSONL file.
func (*JSONLStore) Save ¶
func (s *JSONLStore) Save(ses *Session) error
Save writes the full session as a JSONL file (atomic). If the session has no user interaction, the file is deleted instead.
type Session ¶
type Session struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Title string `json:"title"`
Workspace string `json:"workspace,omitempty"`
Vendor string `json:"vendor"`
Endpoint string `json:"endpoint"`
Model string `json:"model"`
TokenUsage provider.TokenUsage `json:"token_usage,omitempty"`
EndpointUsage map[string]provider.TokenUsage `json:"endpoint_usage,omitempty"`
UsageHistory []UsageEntry `json:"usage_history,omitempty"`
Metrics []metrics.MetricEvent `json:"metrics,omitempty"`
EndpointMetrics map[string][]metrics.MetricEvent `json:"endpoint_metrics,omitempty"`
Messages []provider.Message `json:"messages,omitempty"`
TunnelEvents []TunnelEvent `json:"tunnel_events,omitempty"`
TunnelEventsComplete bool `json:"tunnel_events_complete,omitempty"`
// Cost data stored as opaque JSON to avoid circular dependency with cost package.
CostJSON []byte `json:"cost,omitempty"`
// contains filtered or unexported fields
}
Session represents a single conversation session.
func NewSession ¶
NewSession creates a new Session with a generated ID.
func (*Session) AddUsageForEndpoint ¶ added in v1.3.44
func (s *Session) AddUsageForEndpoint(vendor, endpoint string, usage provider.TokenUsage)
func (*Session) AppendMetricForEndpoint ¶ added in v1.3.44
func (s *Session) AppendMetricForEndpoint(vendor, endpoint string, ev metrics.MetricEvent)
func (*Session) HasUserInteraction ¶ added in v1.1.50
HasUserInteraction returns true if the session contains at least one user message with actual text content. Sessions without user interaction (e.g., created then immediately closed) should not be persisted to avoid accumulating empty session files.
func (*Session) MetricsForEndpoint ¶ added in v1.3.44
func (s *Session) MetricsForEndpoint(vendor, endpoint string) []metrics.MetricEvent
func (*Session) RebuildEndpointStats ¶ added in v1.3.44
func (s *Session) RebuildEndpointStats()
func (*Session) UsageForEndpoint ¶ added in v1.3.44
func (s *Session) UsageForEndpoint(vendor, endpoint string) provider.TokenUsage
type Store ¶
type Store interface {
// Save persists the current state of a session (atomic write).
Save(s *Session) error
// Load retrieves a session by ID.
Load(id string) (*Session, error)
// List returns all sessions, sorted by UpdatedAt descending.
List() ([]*Session, error)
// Delete removes a session by ID.
Delete(id string) error
// ExportMarkdown renders a session as a markdown document.
ExportMarkdown(id string) (string, error)
// CleanupOlderThan removes sessions whose UpdatedAt is before the given time.
CleanupOlderThan(before time.Time) (int, error)
// AppendCheckpoint persists a checkpoint of compacted messages after summarize.
// The checkpoint allows --resume to skip re-compacting old history.
AppendCheckpoint(s *Session, compactedMessages []provider.Message, tokenCount int) error
}
Store is the interface for session persistence.
type TunnelEvent ¶ added in v1.3.20
type TunnelEvent struct {
EventID string `json:"event_id"`
StreamID string `json:"stream_id,omitempty"`
Type string `json:"type"`
Data json.RawMessage `json:"data,omitempty"`
}
TunnelEvent is the canonical persisted tunnel event for a session.
type UsageEntry ¶ added in v1.3.43
type UsageEntry struct {
Timestamp time.Time `json:"timestamp"`
TurnIndex int `json:"turn_index"`
Model string `json:"model,omitempty"`
Vendor string `json:"vendor,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Usage provider.TokenUsage `json:"usage"`
}
UsageEntry records a single LLM API call's token consumption within a session.