Documentation
¶
Overview ¶
Package session persists JSONL conversations and related session metadata.
Index ¶
- Constants
- Variables
- func DefaultExportFilename(sess *Session) string
- func DefaultExportFilenameForFormat(sess *Session, format string) string
- func IsSessionReferenceAlias(reference string) bool
- func NormalizeExportFormat(format string) (string, error)
- func NormalizeSessionTag(tag string) string
- func RenderHTML(sess *Session) string
- func RenderMarkdown(sess *Session) string
- func ValidateExportOutputPath(path string) error
- func WorkspaceFingerprint(workspace string) string
- type BackfillReport
- type BackfillSkippedSession
- type BackfilledSession
- type ExportedSession
- type IdentityPlaceholder
- type ImportOptions
- type ImportResult
- type LookupError
- type PathIsDirectoryError
- type PinResult
- type PromptEntry
- type PruneOptions
- type PruneReport
- type PrunedSession
- type Record
- type RenameResult
- type ReplaceResult
- type RewindResult
- type Session
- type SessionIdentity
- type SessionMetadata
- type Store
- func (s *Store) Append(id string, msg anthropic.Message) error
- func (s *Store) AppendInput(id string, input string) error
- func (s *Store) AppendPromptHistoryDisabled(id string) error
- func (s *Store) AppendWithUsage(id string, msg anthropic.Message, usage *anthropic.Usage) error
- func (s *Store) ApplyCleanupPeriodDays(days int) error
- func (s *Store) BackfillPromptHistory() (BackfillReport, error)
- func (s *Store) Create(id string) (*Session, error)
- func (s *Store) CreateWithIdentity(id string, identity SessionIdentity) (*Session, error)
- func (s *Store) Delete(id string) error
- func (s *Store) Exists(id string) (bool, error)
- func (s *Store) Export(id string, format string) ([]byte, *Session, error)
- func (s *Store) Fork(id string, branchName string) (*Session, error)
- func (s *Store) Identity(id string) (SessionIdentity, error)
- func (s *Store) Import(path string, opts ImportOptions) (ImportResult, error)
- func (s *Store) LatestAnyID() (string, error)
- func (s *Store) LatestID() (string, error)
- func (s *Store) LatestIDExcluding(excludeID string) (string, error)
- func (s *Store) LatestSessionExcluding(excludeID string) (*Session, error)
- func (s *Store) List() ([]Session, error)
- func (s *Store) Open(id string) (*Session, error)
- func (s *Store) OpenExisting(id string) (*Session, error)
- func (s *Store) PinMessage(id string, index int) (PinResult, error)
- func (s *Store) PromptHistory(id string) ([]PromptEntry, error)
- func (s *Store) Prune(opts PruneOptions) (PruneReport, error)
- func (s *Store) RemoveAll() error
- func (s *Store) RemoveOlderThan(cutoff time.Time) error
- func (s *Store) Rename(oldID string, newID string) (RenameResult, error)
- func (s *Store) RepairSessionIdentities() (BackfillReport, error)
- func (s *Store) ReplaceMessages(sess *Session, messages []anthropic.Message) (ReplaceResult, error)
- func (s *Store) Rewind(id string, removeMessages int) (RewindResult, error)
- func (s *Store) SetTag(id string, tag string) (SessionIdentity, error)
- func (s *Store) UnpinMessage(id string, index int) (PinResult, error)
- func (s *Store) UpdateIdentity(id string, update SessionIdentity) (SessionIdentity, error)
- func (s *Store) Usage(id string) ([]UsageEntry, error)
- type UsageEntry
- type WorkspaceMismatchError
Constants ¶
const ( ExportMarkdown = "markdown" ExportJSON = "json" ExportJSONL = "jsonl" ExportHTML = "html" )
const DefaultCleanupPeriodDays = 30
DefaultCleanupPeriodDays matches Claude Code's default transcript retention.
const MaxRotatedSessionLogs = 3
MaxRotatedSessionLogs is the number of oversized transcript snapshots kept next to the active session JSONL.
const MaxSessionJSONLBytes int64 = 5 * 1024 * 1024
MaxSessionJSONLBytes is the active transcript size that triggers rotation.
Variables ¶
var ErrAllSessionsEmpty = errors.New("all saved sessions are empty")
ErrAllSessionsEmpty reports that saved sessions exist but none contain messages.
var ErrNoSessions = errors.New("no saved sessions")
ErrNoSessions reports that no saved session files are visible to the store.
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound reports that a requested saved session does not exist.
Functions ¶
func DefaultExportFilename ¶
func IsSessionReferenceAlias ¶
IsSessionReferenceAlias reports whether reference selects the newest session.
func NormalizeExportFormat ¶
func NormalizeSessionTag ¶
NormalizeSessionTag removes invisible Unicode controls and surrounding whitespace before a tag is persisted or rendered in a terminal.
func RenderHTML ¶
func RenderMarkdown ¶
func WorkspaceFingerprint ¶
Types ¶
type BackfillReport ¶
type BackfillReport struct {
Kind string `json:"kind"`
Action string `json:"action"`
Status string `json:"status"`
SessionsScanned int `json:"sessions_scanned"`
SessionsUpdated int `json:"sessions_updated"`
InputsAdded int `json:"inputs_added"`
IdentityUpdates int `json:"identity_updates"`
SkippedWithInputs int `json:"skipped_with_inputs"`
SkippedDisabled int `json:"skipped_disabled"`
BackfilledSessions []BackfilledSession `json:"backfilled_sessions,omitempty"`
SkippedSessionDetails []BackfillSkippedSession `json:"skipped_session_details,omitempty"`
}
type BackfillSkippedSession ¶
type BackfilledSession ¶
type ExportedSession ¶
type ExportedSession struct {
ID string `json:"id"`
Identity SessionIdentity `json:"identity"`
Messages []anthropic.Message `json:"messages"`
}
type IdentityPlaceholder ¶
type ImportOptions ¶
type ImportResult ¶
type ImportResult struct {
Source string `json:"source"`
OriginalSessionID string `json:"original_session_id,omitempty"`
SessionID string `json:"session_id"`
Path string `json:"path"`
MessageCount int `json:"message_count"`
Overwritten bool `json:"overwritten"`
Identity SessionIdentity `json:"identity"`
}
type LookupError ¶
type LookupError struct {
Err error
Reference string
SearchDir string
LegacyDir string
Workspace string
WorkspaceFingerprint string
OtherWorkspacePartitions int
OtherWorkspaceSessions int
}
LookupError adds workspace-namespace context to session lookup failures while preserving ErrNoSessions and ErrSessionNotFound through errors.Is.
func (LookupError) Error ¶
func (e LookupError) Error() string
func (LookupError) Unwrap ¶
func (e LookupError) Unwrap() error
type PathIsDirectoryError ¶
type PathIsDirectoryError struct {
Path string
}
func (PathIsDirectoryError) Error ¶
func (e PathIsDirectoryError) Error() string
type PinResult ¶
type PinResult struct {
SessionID string `json:"session_id"`
Path string `json:"path"`
Action string `json:"action"`
MessageIndex int `json:"message_index"`
MessageCount int `json:"message_count"`
PinnedMessages []int `json:"pinned_messages"`
}
PinResult describes a message pin mutation in a saved session.
type PromptEntry ¶
type PruneOptions ¶
PruneOptions controls saved-session cleanup.
type PruneReport ¶
type PruneReport struct {
Kind string `json:"kind"`
Action string `json:"action"`
Status string `json:"status"`
DryRun bool `json:"dry_run"`
Keep int `json:"keep,omitempty"`
EmptyOnly bool `json:"empty_only,omitempty"`
Scanned int `json:"scanned"`
CandidateCount int `json:"candidate_count"`
DeletedCount int `json:"deleted_count"`
Candidates []PrunedSession `json:"candidates,omitempty"`
Deleted []PrunedSession `json:"deleted,omitempty"`
}
PruneReport describes a dry-run or confirmed saved-session cleanup.
type PrunedSession ¶
type PrunedSession struct {
ID string `json:"id"`
Path string `json:"path"`
MessageCount int `json:"message_count"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
ModifiedAt time.Time `json:"modified_at,omitempty"`
Reason string `json:"reason"`
}
PrunedSession describes a session selected by cleanup.
type Record ¶
type Record struct {
Type string `json:"type"`
Time time.Time `json:"time"`
Message *anthropic.Message `json:"message,omitempty"`
Identity *SessionIdentity `json:"identity,omitempty"`
Usage *anthropic.Usage `json:"usage,omitempty"`
Input string `json:"input,omitempty"`
SessionID string `json:"session_id,omitempty"`
ParentSessionID string `json:"parent_session_id,omitempty"`
BranchName string `json:"branch_name,omitempty"`
MessageIndex int `json:"message_index,omitempty"`
Action string `json:"action,omitempty"`
}
type RenameResult ¶
type ReplaceResult ¶
type RewindResult ¶
type Session ¶
type Session struct {
ID string
Messages []anthropic.Message
Path string
Identity SessionIdentity
Metadata SessionMetadata
}
type SessionIdentity ¶
type SessionIdentity struct {
Title string `json:"title,omitempty"`
Tag string `json:"tag,omitempty"`
Workspace string `json:"workspace,omitempty"`
Worktree string `json:"worktree,omitempty"`
Purpose string `json:"purpose,omitempty"`
Placeholders []IdentityPlaceholder `json:"placeholders,omitempty"`
}
type SessionMetadata ¶
type SessionMetadata struct {
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
ModifiedAt time.Time `json:"modified_at,omitempty"`
ParentSessionID string `json:"parent_session_id,omitempty"`
BranchName string `json:"branch_name,omitempty"`
PinnedMessages []int `json:"pinned_messages,omitempty"`
}
type Store ¶
func NewWorkspaceStore ¶
func NewWorkspaceStoreWithCleanup ¶
func NewWorkspaceStoreWithCleanup(configHome string, workspace string, cleanupPeriodDays int) (*Store, error)
NewWorkspaceStoreWithCleanup opens a workspace store and applies transcript retention.
func (*Store) AppendPromptHistoryDisabled ¶
func (*Store) AppendWithUsage ¶
func (*Store) ApplyCleanupPeriodDays ¶
ApplyCleanupPeriodDays removes expired transcripts or disables persistence when days is zero.
func (*Store) BackfillPromptHistory ¶
func (s *Store) BackfillPromptHistory() (BackfillReport, error)
func (*Store) CreateWithIdentity ¶
func (s *Store) CreateWithIdentity(id string, identity SessionIdentity) (*Session, error)
func (*Store) Import ¶
func (s *Store) Import(path string, opts ImportOptions) (ImportResult, error)
func (*Store) LatestAnyID ¶
LatestAnyID returns the newest visible session, including empty transcripts.
func (*Store) LatestID ¶
LatestID returns the newest visible session that contains at least one message.
func (*Store) LatestIDExcluding ¶
LatestIDExcluding returns the newest non-empty session other than excludeID.
func (*Store) LatestSessionExcluding ¶
LatestSessionExcluding returns the newest non-empty session, falling back to sibling workspace namespaces when the current namespace has no usable match.
func (*Store) PinMessage ¶
PinMessage marks the zero-based message index as pinned for the session.
func (*Store) PromptHistory ¶
func (s *Store) PromptHistory(id string) ([]PromptEntry, error)
func (*Store) Prune ¶
func (s *Store) Prune(opts PruneOptions) (PruneReport, error)
Prune selects saved sessions for cleanup and deletes them only when Confirm is true.
func (*Store) RemoveOlderThan ¶
RemoveOlderThan deletes transcript files whose modified time is older than cutoff.
func (*Store) RepairSessionIdentities ¶
func (s *Store) RepairSessionIdentities() (BackfillReport, error)
func (*Store) ReplaceMessages ¶
func (*Store) SetTag ¶
func (s *Store) SetTag(id string, tag string) (SessionIdentity, error)
SetTag replaces or clears the searchable tag attached to a saved session.
func (*Store) UnpinMessage ¶
UnpinMessage removes a pin from the zero-based message index.
func (*Store) UpdateIdentity ¶
func (s *Store) UpdateIdentity(id string, update SessionIdentity) (SessionIdentity, error)
type UsageEntry ¶
type WorkspaceMismatchError ¶
WorkspaceMismatchError reports an explicitly bound session from another workspace.
func (WorkspaceMismatchError) Error ¶
func (e WorkspaceMismatchError) Error() string