session

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Export added in v0.7.3

func Export(record *SessionRecord, options ExportOptions) ([]byte, error)

Export serializes record according to the specified options. Supported formats are FormatMarkdown (default if empty) and FormatJSON.

func ExportJSON added in v0.7.3

func ExportJSON(record *SessionRecord, options ExportOptions) ([]byte, error)

ExportJSON serializes record into pretty-printed, deterministic JSON. System prompts and internal reasoning content are strictly excluded.

func ExportMarkdown added in v0.7.3

func ExportMarkdown(record *SessionRecord, options ExportOptions) (string, error)

ExportMarkdown serializes record into clean, human-readable Markdown. System prompts and internal reasoning content are strictly excluded.

func GenerateID

func GenerateID() string

GenerateID creates a unique session identifier.

func RedactToolArgs added in v0.7.4

func RedactToolArgs(raw json.RawMessage) json.RawMessage

RedactToolArgs masks credential-shaped values in raw tool-call arguments. SECURITY: assistant tool calls are persisted and exported, so their arguments cross the same transcript boundary as tool output. When the input was valid JSON the result stays valid JSON.

Types

type ExportFormat added in v0.7.3

type ExportFormat string

ExportFormat specifies the target serialization format for a session.

const (
	FormatMarkdown ExportFormat = "markdown"
	FormatJSON     ExportFormat = "json"
)

type ExportOptions added in v0.7.3

type ExportOptions struct {
	Format       ExportFormat
	IncludeTools bool
}

ExportOptions controls session serialization.

type JSONExportMessage added in v0.7.3

type JSONExportMessage struct {
	Role       string               `json:"role"`
	Content    string               `json:"content"`
	ToolCalls  []JSONExportToolCall `json:"tool_calls,omitempty"`
	ToolCallID string               `json:"tool_call_id,omitempty"`
	ToolName   string               `json:"tool_name,omitempty"`
}

JSONExportMessage represents a single message in the exported JSON.

type JSONExportToolCall added in v0.7.3

type JSONExportToolCall struct {
	ID   string          `json:"id"`
	Name string          `json:"name"`
	Args json.RawMessage `json:"args,omitempty"`
}

JSONExportToolCall represents a tool invocation in the exported JSON.

type JSONSessionExport added in v0.7.3

type JSONSessionExport struct {
	Version   int                 `json:"version"`
	ID        string              `json:"id"`
	Title     string              `json:"title"`
	Provider  string              `json:"provider"`
	Model     string              `json:"model"`
	CreatedAt time.Time           `json:"created_at"`
	UpdatedAt time.Time           `json:"updated_at"`
	Messages  []JSONExportMessage `json:"messages"`
}

JSONSessionExport represents the versioned, privacy-scrubbed JSON structure.

type SessionRecord

type SessionRecord struct {
	ID        string `json:"id"`
	Title     string `json:"title"`
	Provider  string `json:"provider"`
	Model     string `json:"model"`
	Workspace string `json:"workspace"`
	// Scratchpad is agent-maintained working state that survives compaction and
	// is restored with the transcript.
	Scratchpad string             `json:"scratchpad,omitempty"`
	CreatedAt  time.Time          `json:"created_at"`
	UpdatedAt  time.Time          `json:"updated_at"`
	Messages   []provider.Message `json:"messages"`
}

SessionRecord holds the full data of a persisted session.

type SessionStore

type SessionStore struct {
	// contains filtered or unexported fields
}

SessionStore handles session persistence using SQLite.

func NewStore

func NewStore(dbPath string) (*SessionStore, error)

NewStore opens or creates a SQLite session database at dbPath.

func (*SessionStore) AppendMessage

func (s *SessionStore) AppendMessage(sessionID string, msg provider.Message) error

AppendMessage persists a single message to the given session and updates timestamps.

func (*SessionStore) AppendSummaryMessage added in v0.8.0

func (s *SessionStore) AppendSummaryMessage(sessionID string, msg provider.Message) (int64, error)

AppendSummaryMessage persists a compaction summary as a flagged assistant message and returns its row id, which becomes the session's replay anchor. The flag lets a resumed transcript relabel it to a user turn.

func (*SessionStore) Close

func (s *SessionStore) Close() error

Close closes the underlying SQLite database.

func (*SessionStore) CreateSession

func (s *SessionStore) CreateSession(id, title, providerName, model string) (*SessionRecord, error)

CreateSession initializes a new session record in the database. It keeps the historical signature for callers that do not know the workspace; such a session is never auto-resumed by workspace.

func (*SessionStore) CreateSessionWithWorkspace added in v0.7.4

func (s *SessionStore) CreateSessionWithWorkspace(id, title, providerName, model, workspace string) (*SessionRecord, error)

CreateSessionWithWorkspace initializes a new session bound to workspace, which scopes auto-resume so a transcript from another repository is never replayed.

func (*SessionStore) DeleteSession

func (s *SessionStore) DeleteSession(id string) error

DeleteSession deletes a session and all its messages.

func (*SessionStore) GetLastSession

func (s *SessionStore) GetLastSession() (*SessionRecord, error)

GetLastSession returns the most recently updated session, or nil if no sessions exist.

func (*SessionStore) GetLastSessionForWorkspace added in v0.7.4

func (s *SessionStore) GetLastSessionForWorkspace(workspace string) (*SessionRecord, error)

GetLastSessionForWorkspace returns the most recently updated session created in workspace, or nil. Auto-resume is scoped this way so a transcript from another repository (file contents, possibly secrets) is never sent to the provider in the current one. An empty workspace never matches.

func (*SessionStore) GetSession

func (s *SessionStore) GetSession(id string) (*SessionRecord, error)

GetSession retrieves a session record and its full message history.

func (*SessionStore) ListSessions

func (s *SessionStore) ListSessions(limit int) ([]SessionSummary, error)

ListSessions returns a summary of recent sessions up to limit.

func (*SessionStore) SaveSession

func (s *SessionStore) SaveSession(rec *SessionRecord) error

SaveSession updates session metadata and overwrites all messages.

func (*SessionStore) SetSummaryAnchor added in v0.8.0

func (s *SessionStore) SetSummaryAnchor(sessionID, anchor string) error

SetSummaryAnchor records the row id replay reads from. An empty anchor clears it, so the full transcript is replayed.

func (*SessionStore) UpdateModel

func (s *SessionStore) UpdateModel(id, providerName, model string) error

UpdateModel updates the model and provider of an existing session.

func (*SessionStore) UpdateScratchpad added in v0.7.4

func (s *SessionStore) UpdateScratchpad(id, scratchpad string) error

UpdateScratchpad persists the agent-maintained working state for a session. An empty value clears it, because the agent explicitly replaced it.

func (*SessionStore) UpdateTitle added in v0.8.0

func (s *SessionStore) UpdateTitle(id, title string) error

UpdateTitle renames a session. The title goes through the same truncation as creation titles so picker rows and listings stay consistent.

type SessionSummary

type SessionSummary struct {
	ID           string    `json:"id"`
	Title        string    `json:"title"`
	Provider     string    `json:"provider"`
	Model        string    `json:"model"`
	MessageCount int       `json:"message_count"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

SessionSummary holds brief metadata about a session for listing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL