Documentation
¶
Overview ¶
Package sessions provides JSONL-based conversation logging for session persistence and resume. It operates alongside the existing JSON session system in config/session.go — that system tracks config state (endpoint, model, NSFW mode) while this package handles append-only conversation replay.
Index ¶
- type LogEntry
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) GetRecentSession(maxAge time.Duration) (*SessionInfo, error)
- func (m *Manager) ListSessions() ([]SessionInfo, error)
- func (m *Manager) LogTurn(role, content string) error
- func (m *Manager) ProjectID() string
- func (m *Manager) ResumeSession(id string) ([]LogEntry, error)
- func (m *Manager) SessionDir() string
- func (m *Manager) SessionID() string
- func (m *Manager) StartSession() error
- type SessionInfo
- type SessionWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogEntry ¶
type LogEntry struct {
Type string `json:"type"` // "user", "assistant", "tool_call", "tool_result", "system"
Content string `json:"content"`
Role string `json:"role,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolID string `json:"tool_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
LogEntry represents a single line in the JSONL session log.
func ReadSession ¶
ReadSession reads all entries from a JSONL file. Malformed lines are silently skipped so that a partially-corrupt file can still be recovered.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates session writing, listing, and auto-resume for a project.
func NewManager ¶
NewManager creates a Manager scoped to the project that contains cwd. The projectID is derived from the git repository root (if available) or the cwd itself, hashed to a short hex string.
func (*Manager) GetRecentSession ¶
func (m *Manager) GetRecentSession(maxAge time.Duration) (*SessionInfo, error)
GetRecentSession returns the most recently modified session that is younger than maxAge, or nil if none qualifies.
func (*Manager) ListSessions ¶
func (m *Manager) ListSessions() ([]SessionInfo, error)
ListSessions returns all sessions for this project.
func (*Manager) LogTurn ¶
LogTurn writes a conversation turn. role should be one of the LogEntry.Type values: "user", "assistant", "tool_call", "tool_result", "system".
func (*Manager) ResumeSession ¶
ResumeSession loads entries from an existing JSONL session and opens a new writer that appends to it.
func (*Manager) SessionDir ¶
SessionDir returns the project-specific session directory.
func (*Manager) StartSession ¶
StartSession creates a new JSONL log file and sets up the writer.
type SessionInfo ¶
type SessionInfo struct {
ID string
Path string
Title string // derived from first user message
EntryCount int
CreatedAt time.Time
UpdatedAt time.Time // file mtime
}
SessionInfo summarises a JSONL session file without loading every entry.
func ListSessions ¶
func ListSessions(sessionDir string) ([]SessionInfo, error)
ListSessions scans sessionDir for .jsonl files and returns metadata sorted by modification time (newest first).
type SessionWriter ¶
type SessionWriter struct {
// contains filtered or unexported fields
}
SessionWriter appends LogEntry records to a JSONL file.
func NewSessionWriter ¶
func NewSessionWriter(sessionDir string, sessionID string) (*SessionWriter, error)
NewSessionWriter creates a writer that appends to <sessionDir>/<sessionID>.jsonl, creating parent directories as needed.
func (*SessionWriter) Close ¶
func (w *SessionWriter) Close() error
Close flushes and closes the underlying file.
func (*SessionWriter) Path ¶
func (w *SessionWriter) Path() string
Path returns the absolute path of the JSONL file.
func (*SessionWriter) WriteEntry ¶
func (w *SessionWriter) WriteEntry(entry LogEntry) error
WriteEntry appends a single JSON line. Ephemeral types (progress, typing, ping) are silently dropped.