session

package
v0.9.37 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StoreChangeSessionCreated           = "session.created"
	StoreChangeSessionDeleted           = "session.deleted"
	StoreChangeSessionMetadataChanged   = "session.metadata_changed"
	StoreChangeSessionTranscriptChanged = "session.transcript_changed"
	StoreChangeSessionStatusChanged     = "session.status_changed"
	StoreChangeSessionLifecycleChanged  = "session.lifecycle_changed"
	StoreChangeSessionAttentionChanged  = "session.attention_changed"
	StoreChangeProjectMembershipChanged = "project.membership_changed"
	StoreChangeProjectCreated           = "project.created"
	StoreChangeProjectUpdated           = "project.updated"
	StoreChangeProjectDeleted           = "project.deleted"
)
View Source
const (
	TranscriptFlagCompactionTail uint8 = 1 << iota
	TranscriptFlagEmptyBody
)

Transcript index flags describe durable rows without materializing bodies.

View Source
const TranscriptMaterializationMaxRanges = 32

Variables

View Source
var (
	// ErrProjectsUnsupported indicates that the store predates or does not expose
	// durable project support.
	ErrProjectsUnsupported = errors.New("session: projects unsupported")
	// ErrProjectDuplicate indicates that a canonical project directory already
	// has a stable identity.
	ErrProjectDuplicate = errors.New("session: project already exists")
	// ErrWorkspaceConflict indicates that an immutable session workspace was
	// already bound to different values.
	ErrWorkspaceConflict = errors.New("session: workspace conflict")
)
View Source
var (
	ErrInvalidShareScope  = errors.New("session: invalid share scope")
	ErrInvalidShareAnchor = errors.New("session: invalid share anchor")
)
View Source
var (
	// ErrTranscriptConflict means a transcript mutation was based on a stale
	// revision or head row and must be retried after refreshing the transcript.
	ErrTranscriptConflict = errors.New("session: transcript changed")
	// Branch errors describe unavailable schema support and stale optimistic state.
	ErrBranchingUnsupported = errors.New("session: conversation branching unsupported")
	// ErrBranchConflict is branch-specific while matching the shared transcript
	// conflict sentinel for callers that handle all optimistic transcript races.
	ErrBranchConflict = fmt.Errorf("session: branch conflict: %w", ErrTranscriptConflict)
	// ErrBranchIdempotencyConflict means a key was reused for a different source prefix.
	ErrBranchIdempotencyConflict = errors.New("session: branch idempotency key reused with different parameters")
	// ErrNothingToUndo means there is no real post-compaction user turn to undo.
	ErrNothingToUndo = errors.New("session: nothing to undo")
	// ErrNothingToRedo means no durable undo suffix remains for this session.
	ErrNothingToRedo = errors.New("session: nothing to redo")
)
View Source
var (
	ErrResponseRunLeaseLost = errors.New("session: response run lease lost")
	ErrAttentionConflict    = errors.New("session: attention generation conflict")
)
View Source
var ErrNotFound = errors.New("session: not found")

ErrNotFound is returned when a lookup or update targets a row that does not exist (e.g., UpdateMessage against a deleted/never-persisted message ID).

View Source
var ErrSteeringConflict = errors.New("steering identity, content or ownership conflict")
View Source
var ErrTranscriptRevisionUnsupported = errors.New("session: transcript revision unsupported")

ErrTranscriptRevisionUnsupported indicates that a store does not support a mutation method that reports the exact transcript revision it commits.

Functions

func ApplyCompaction added in v0.0.234

func ApplyCompaction(ctx context.Context, store Store, sess *Session, full []Message, result *llm.CompactionResult) ([]Message, int, *Session, error)

ApplyCompaction persists a compaction result, appends the compacted rows to the caller's scrollback snapshot, returns the new active start index, refreshes session metadata when possible, and best-effort clears any persisted context estimate baseline so future turns don't seed context management with pre-compaction token counts. The full argument is the caller's scrollback snapshot and may be nil for non-UI owners that only need persistence.

func ApplyReasoningPersistencePolicy added in v0.0.258

func ApplyReasoningPersistencePolicy(msg llm.Message, cfg config.ReasoningConfig) llm.Message

ApplyReasoningPersistencePolicy removes display-only reasoning summary text when the user disabled summary persistence, while preserving provider replay identifiers/encrypted payloads. Raw reasoning is left unchanged because some providers use it as replay/debug metadata and display/export remain gated separately.

func EncodeProjectSessionCursor added in v0.0.404

func EncodeProjectSessionCursor(summary SessionSummary) string

func EncodeRecentSessionCursor added in v0.9.7

func EncodeRecentSessionCursor(summary SessionSummary) string

func ExpandShortID added in v0.0.52

func ExpandShortID(shortID string) string

ExpandShortID converts a short ID to a SQL LIKE pattern for prefix matching. Example: "240115-1430" -> "20240115-1430%"

func ExportToHTML added in v0.0.322

func ExportToHTML(sess *Session, messages []Message, opts ExportOptions) (string, error)

ExportToHTML renders a self-contained, interactive transcript document.

func ExportToMarkdown added in v0.0.56

func ExportToMarkdown(sess *Session, messages []Message, opts ExportOptions) string

ExportToMarkdown exports a session and its messages to a pretty markdown format.

func ExtractHandoverPath added in v0.0.317

func ExtractHandoverPath(prompt, dir string) string

ExtractHandoverPath recovers a handover file path embedded in a system prompt via {{handover_path}}. It matches the first path under dir with the "<date>-<slug>.md" shape. Returns "" when the prompt names no such file.

func FindMessagesByClientMessageIDs added in v0.0.363

func FindMessagesByClientMessageIDs(ctx context.Context, store Store, sessionID string, clientMessageIDs []string) (map[string]*Message, error)

FindMessagesByClientMessageIDs uses a batch capability when available and otherwise performs at most one full transcript scan.

func GetDBPath

func GetDBPath() (string, error)

GetDBPath returns the path to the sessions database.

func GetDataDir

func GetDataDir() (string, error)

GetDataDir returns the XDG data directory for term-llm. Uses $XDG_DATA_HOME if set, otherwise ~/.local/share

func GetHandoverDir added in v0.0.146

func GetHandoverDir(cwd string) (string, error)

GetHandoverDir returns the handover directory for the given working directory. The path is XDG_DATA_HOME/term-llm/handover/<basename>-<sha256[:6]>/ where the hash is computed from the absolute cwd to avoid collisions.

func GetHandoverPath added in v0.0.146

func GetHandoverPath(cwd, date string) (string, error)

GetHandoverPath returns a full handover file path with a random name like "2026-04-03-amber-creek-bloom.md". A fresh slug is generated per call so concurrent sessions in the same project get distinct plan files. The expanded system prompt is the durable per-session record of the path; use ExtractHandoverPath to recover it.

func GistFiles added in v0.0.324

func GistFiles(sess *Session, messages []Message, opts ExportOptions) (map[string]string, error)

GistFiles is retained for the explicit GitHub-only export commands.

func GistPreviewURL added in v0.0.324

func GistPreviewURL(id string) string

GistPreviewURL returns the gisthost preview URL for a valid gist ID.

func HasCompactionBoundary added in v0.0.234

func HasCompactionBoundary(sess *Session) bool

HasCompactionBoundary reports whether a session has an explicit persisted compaction boundary. Checking the count (or a positive sequence from older persisted sessions) avoids treating a zero-value Session as compacted at sequence 0.

func IsBranchableMessage added in v0.0.396

func IsBranchableMessage(message Message) bool

IsBranchableMessage reports whether message may be used as a durable branch anchor. Provider-context-only rows (system, developer, and events) and compaction artifacts are not continuation boundaries.

func IsInternalCompactionSummaryMessage added in v0.0.376

func IsInternalCompactionSummaryMessage(msg Message) bool

IsInternalCompactionSummaryMessage reports whether msg contains term-llm's internal context-compaction summary payload.

func IsRandomHandoverName added in v0.0.146

func IsRandomHandoverName(name string) bool

IsRandomHandoverName returns true if the filename matches the random 3-word pattern generated by GetHandoverPath and all three words are from the handoverWords list. This prevents LLM-generated descriptive slugs (e.g. "fix-auth-bug") from being treated as random and renamed repeatedly.

func IsSyntheticCompactionAckMessage added in v0.0.376

func IsSyntheticCompactionAckMessage(msg Message) bool

IsSyntheticCompactionAckMessage reports whether msg is the internal assistant acknowledgement inserted after a context-compaction summary. It deliberately matches the persisted TextContent representation used by compaction-tail detection so exporting this predicate does not widen persistence behavior.

func LLMActiveMessages added in v0.0.234

func LLMActiveMessages(messages []Message, activeStart int, systemPrompt string) []llm.Message

LLMActiveMessages converts the active slice of session messages into LLM messages, injecting systemPrompt only when the active context doesn't already include a system message, then applies provider-safe conversation filtering.

func MaybeRenameHandover added in v0.0.146

func MaybeRenameHandover(ctx context.Context, path string, slugGen HandoverSlugGenerator) error

MaybeRenameHandover checks if the given handover file should be renamed. It renames when the file has a random-word name and contains >= 1000 bytes. After renaming, a symlink is created from the old path to the new file so that the system prompt path remains valid (preserving LLM cache).

slugGen is called to produce the new slug; if nil or if it returns an error, the rename is silently skipped.

func MessagesAfterBranchAnchor added in v0.0.377

func MessagesAfterBranchAnchor(messages []Message, anchorMessageID int64) ([]llm.Message, error)

MessagesAfterBranchAnchor returns the visible conversation suffix omitted by CreateBranch for the given source anchor. Anchor zero selects the full transcript.

func NewID

func NewID() string

NewID generates a unique session ID using a timestamp prefix and random suffix. Format: YYYYMMDD-HHMMSS-RANDOM (e.g., "20240115-143052-a1b2c3") This format:

  • Sorts chronologically by default
  • Is human-readable for debugging
  • Has enough randomness to prevent collisions

func NewProjectID added in v0.0.404

func NewProjectID() (string, error)

func ParseIDTime

func ParseIDTime(id string) time.Time

ParseIDTime extracts the timestamp from a session ID. Returns zero time if parsing fails.

func PrettifyHandoverName added in v0.0.317

func PrettifyHandoverName(ctx context.Context, path, description string, slugGen HandoverSlugGenerator) error

PrettifyHandoverName renames a random-named handover file to a short descriptive name derived from the session's first user message, so the file has a nice name from the start. The original random path — baked into the session's system prompt — keeps working via a symlink. When the agent has not written the file yet, an empty descriptive target is atomically reserved before the symlink is created so concurrent sessions cannot share a target.

slugGen receives the description and should return roughly two words; the result is sanitized and capped at two dash-separated words. Errors from slugGen are silently skipped — the file simply keeps its random name.

func RandomHandoverSlug added in v0.0.146

func RandomHandoverSlug() string

RandomHandoverSlug returns a string like "amber-creek-bloom" using crypto/rand for word selection.

func RenderExportReasoning added in v0.0.258

func RenderExportReasoning(part llm.Part, opts ExportOptions) string

RenderExportReasoning renders non-encrypted reasoning metadata according to explicit export options. Raw reasoning is never included unless requested.

func ResetContextEstimate added in v0.0.234

func ResetContextEstimate(ctx context.Context, store Store, sess *Session) error

ResetContextEstimate clears the persisted context estimate baseline for the session after compaction.

func ResolveDBPath added in v0.0.85

func ResolveDBPath(pathOverride string) (string, error)

ResolveDBPath resolves an optional DB path override. Empty path uses the default XDG location. Supports :memory: for ephemeral in-memory storage.

func ResolvePinnedHandoverPath added in v0.0.323

func ResolvePinnedHandoverPath(prompt string, candidateDirs ...string) (path string, pinned bool)

ResolvePinnedHandoverPath recovers the handover path assigned by the system prompt. Candidate directories support sessions whose effective directory and process working directory differ. The planner's assignment is also recovered across directory changes, but only when exactly one assignment points under term-llm's global handover root.

pinned is true when an assignment was found even if it was ambiguous. Callers must not fall back to scanning another file when pinned is true.

func ShareFiles added in v0.9.23

func ShareFiles(sess *Session, messages []Message, opts ExportOptions) (map[string]string, error)

ShareFiles builds the canonical HTML and Markdown transcript bundle.

func ShortID

func ShortID(id string) string

ShortID returns a shortened version of the session ID for display. Example: "20240115-143052-a1b2c3" -> "240115-1430"

func SupportsAtomicResponseRunTranscriptFencing added in v0.9.12

func SupportsAtomicResponseRunTranscriptFencing(store Store) bool

SupportsAtomicResponseRunTranscriptFencing reports whether response-scoped transcript writes validate and checkpoint their fence in the write transaction.

func SupportsBatchTranscriptWriter added in v0.9.25

func SupportsBatchTranscriptWriter(store Store) bool

func TruncateSummary

func TruncateSummary(content string) string

TruncateSummary returns the first line of content, truncated to 100 chars.

func UpdateGeneratedTitle added in v0.0.320

func UpdateGeneratedTitle(ctx context.Context, store Store, sess *Session, shortTitle, longTitle string, generatedAt time.Time, basisMsgSeq int) error

UpdateGeneratedTitle persists generated title fields using a title-only fast path when available, and falls back to Store.Update for test/custom stores.

func UpdateGoal added in v0.0.321

func UpdateGoal(ctx context.Context, store Store, sessionID string, goal *Goal) error

UpdateGoal persists a session goal using a goal-only fast path when available, and falls back to Store.Get + Store.Update for custom stores.

func UpdateShare added in v0.0.324

func UpdateShare(ctx context.Context, store Store, sessionID string, share *ShareState) error

UpdateShare persists share metadata using a narrow update when available.

func UpdateStreamingMessage added in v0.0.289

func UpdateStreamingMessage(ctx context.Context, store Store, sessionID string, msg *Message, finalizeText bool) error

UpdateStreamingMessage updates an in-progress assistant message using the store's streaming-aware fast path when available, otherwise it falls back to Store.UpdateMessage.

func WithResponseRunFence added in v0.9.12

func WithResponseRunFence(ctx context.Context, fence ResponseRunFence) context.Context

Types

type AttentionBatchStore added in v0.9.12

type AttentionBatchStore interface {
	GetAttentionBatch(context.Context, []string) (map[string]AttentionState, error)
}

AttentionBatchStore avoids per-session queries on bounded sidebar/status projections.

func AsAttentionBatchStore added in v0.9.12

func AsAttentionBatchStore(store Store) (AttentionBatchStore, bool)

type AttentionItem added in v0.9.12

type AttentionItem struct {
	SessionID                string           `json:"session_id"`
	SessionNumber            int64            `json:"session_number,omitempty"`
	ResponseID               string           `json:"response_id"`
	Kind                     AttentionKind    `json:"kind"`
	LifecycleState           ResponseRunState `json:"lifecycle_state"`
	AttentionSeq             int64            `json:"attention_seq,omitempty"`
	StartedRev               int64            `json:"started_rev,omitempty"`
	FinalRev                 int64            `json:"final_rev,omitempty"`
	ShortTitle               string           `json:"short_title,omitempty"`
	LongTitle                string           `json:"long_title,omitempty"`
	ProjectID                string           `json:"project_id,omitempty"`
	Outcome                  ResponseRunState `json:"outcome,omitempty"`
	StartedAt                time.Time        `json:"started_at,omitempty"`
	TerminalAt               time.Time        `json:"terminal_at,omitempty"`
	LeaseExpiresAt           time.Time        `json:"lease_expires_at,omitempty"`
	InteractionRequired      bool             `json:"interaction_required,omitempty"`
	InteractionStateRev      int64            `json:"interaction_state_rev,omitempty"`
	PendingInteractionCount  int              `json:"pending_interaction_count,omitempty"`
	PendingInteractionKinds  []string         `json:"pending_interaction_kinds,omitempty"`
	InteractionRequiredSince time.Time        `json:"interaction_required_since,omitempty"`
}

type AttentionKind added in v0.9.12

type AttentionKind string
const (
	AttentionKindUnseen        AttentionKind = "unseen"
	AttentionKindRunning       AttentionKind = "running"
	AttentionKindInputRequired AttentionKind = "input_required"
)

type AttentionListOptions added in v0.9.12

type AttentionListOptions struct {
	Kind            AttentionKind
	Limit           int
	Cursor          string
	SnapshotVersion int64
}

type AttentionPage added in v0.9.12

type AttentionPage struct {
	ProtocolVersion int             `json:"protocol_version"`
	StoreInstanceID string          `json:"store_instance_id"`
	SnapshotVersion int64           `json:"snapshot_version"`
	Items           []AttentionItem `json:"items"`
	NextCursor      string          `json:"next_cursor,omitempty"`
	HasMore         bool            `json:"has_more"`
}

type AttentionState added in v0.9.12

type AttentionState struct {
	StoreInstanceID    string           `json:"store_instance_id"`
	SessionID          string           `json:"session_id"`
	LatestAttentionSeq int64            `json:"latest_attention_seq"`
	ResponseID         string           `json:"response_id,omitempty"`
	RunEpoch           int64            `json:"run_epoch,omitempty"`
	Outcome            ResponseRunState `json:"outcome,omitempty"`
	StartedRev         int64            `json:"started_rev,omitempty"`
	FinalRev           int64            `json:"final_rev,omitempty"`
	TerminalAt         time.Time        `json:"terminal_at,omitempty"`
	SeenThroughSeq     int64            `json:"seen_through_seq"`
	SeenAt             time.Time        `json:"seen_at,omitempty"`
	Unseen             bool             `json:"attention_unseen"`
	Changed            bool             `json:"-"`
}

AttentionState is the authoritative per-session terminal-attention watermark.

type AttentionStore added in v0.9.12

type AttentionStore interface {
	MarkAttentionSeen(context.Context, string, string, int64) (AttentionState, error)
	GetAttention(context.Context, string) (AttentionState, error)
	ListAttention(context.Context, AttentionListOptions) (AttentionPage, error)
	StoreInstanceID(context.Context) (string, error)
}

AttentionStore owns durable terminal markers and exact-sequence acknowledgements.

func AsAttentionStore added in v0.9.12

func AsAttentionStore(store Store) (AttentionStore, bool)

type BatchTranscriptRevisionWriter added in v0.9.25

type BatchTranscriptRevisionWriter interface {
	AppendMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []*Message) (int64, error)
}

BatchTranscriptRevisionWriter atomically appends an ordered message suffix and reports the single transcript revision committed for the whole batch.

type BranchPathNote added in v0.0.377

type BranchPathNote struct {
	Text       string
	Provenance llm.PathNoteProvenance
}

BranchPathNote is optional model-readable context inserted after the copied prefix in the same transaction that materializes a conversation branch.

type BranchResult added in v0.0.377

type BranchResult struct {
	Session            *Session `json:"session"`
	ForkAfterMessageID int64    `json:"fork_after_message_id,omitempty"`
	AnchorMessageID    int64    `json:"anchor_message_id,omitempty"`
	Reused             bool     `json:"reused,omitempty"`
}

BranchResult is the newly materialized (or idempotently reused) linear child.

type BranchTree added in v0.0.377

type BranchTree struct {
	RootSessionID   string           `json:"root_session_id"`
	ActiveSessionID string           `json:"active_session_id"`
	PathCount       int              `json:"path_count"`
	Nodes           []BranchTreeNode `json:"nodes"`
}

BranchTree is a connected component rooted at its oldest surviving ancestor. PathCount counts independently resumable linear sessions in the component; it intentionally equals len(Nodes), including non-leaf ancestor sessions.

type BranchTreeNode added in v0.0.377

type BranchTreeNode struct {
	SessionID             string    `json:"session_id"`
	SessionNumber         int64     `json:"session_number,omitempty"`
	ParentSessionID       string    `json:"parent_session_id,omitempty"`
	ForkAfterMessageID    int64     `json:"fork_after_message_id,omitempty"`
	ForkAfterSequence     int       `json:"fork_after_sequence"`
	CopiedAnchorMessageID int64     `json:"copied_anchor_message_id,omitempty"`
	Title                 string    `json:"title,omitempty"`
	AnchorRole            string    `json:"anchor_role,omitempty"`
	AnchorPreview         string    `json:"anchor_preview,omitempty"`
	CreatedAt             time.Time `json:"created_at"`
}

BranchTreeNode is one normal session in a connected conversation tree.

type ClientMessageBatchLookup added in v0.0.363

type ClientMessageBatchLookup interface {
	GetMessagesByClientMessageIDs(ctx context.Context, sessionID string, clientMessageIDs []string) (map[string]*Message, error)
}

ClientMessageBatchLookup retrieves durable first-party intents by identity.

type ClientMessageLookup added in v0.0.363

type ClientMessageLookup interface {
	GetMessageByClientMessageID(ctx context.Context, sessionID, clientMessageID string) (*Message, error)
}

ClientMessageLookup retrieves the durable owner of a first-party user intent. Implementations should return ErrNotFound when the identity is absent.

type CompactedTranscriptRevisionWriter added in v0.0.353

type CompactedTranscriptRevisionWriter interface {
	ReplaceCompactedMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []Message) (int64, error)
}

CompactedTranscriptRevisionWriter reports the exact revision committed by an atomic compaction replacement.

type CompletionPushOutboxItem added in v0.9.0

type CompletionPushOutboxItem struct {
	ID             int64
	EventID        string
	ResponseID     string
	SubscriptionID string
	Payload        []byte
	AttemptCount   int
}

type CompletionPushOutboxStore added in v0.9.0

type CompletionPushOutboxStore interface {
	EnqueueCompletionPush(ctx context.Context, item CompletionPushOutboxItem) (bool, error)
	ListDueCompletionPushes(ctx context.Context, now time.Time, limit int) ([]CompletionPushOutboxItem, error)
	MarkCompletionPushDelivered(ctx context.Context, id int64) error
	RetryCompletionPush(ctx context.Context, id int64, next time.Time, lastError string) error
	MarkCompletionPushDead(ctx context.Context, id int64, lastError string) error
	PruneCompletionPushOutbox(ctx context.Context, before time.Time) error
}

func AsCompletionPushOutboxStore added in v0.9.0

func AsCompletionPushOutboxStore(store Store) (CompletionPushOutboxStore, bool)

type Config

type Config struct {
	Enabled          bool   `mapstructure:"enabled"`            // Master switch
	MaxAgeDays       int    `mapstructure:"max_age_days"`       // Auto-delete after N days (0=never)
	MaxCount         int    `mapstructure:"max_count"`          // Keep at most N sessions (0=unlimited)
	Path             string `mapstructure:"path"`               // Optional DB path override (supports :memory:)
	StripImageBase64 bool   `mapstructure:"strip_image_base64"` // Store path/metadata only for images with ImagePath (smaller DB, less portable)
	ReadOnly         bool   `mapstructure:"-"`                  // Open DB in read-only mode (skip schema init/cleanup)
}

Config holds session storage configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default session configuration.

type ConversationBranchReplayStore added in v0.0.377

type ConversationBranchReplayStore interface {
	GetBranchByIdempotencyKey(ctx context.Context, sourceSessionID, idempotencyKey string) (BranchResult, bool, error)
}

ConversationBranchReplayStore resolves a prior idempotent branch request without regenerating optional helper context.

type ConversationBranchStore added in v0.0.377

type ConversationBranchStore interface {
	CreateBranch(ctx context.Context, sourceSessionID string, opts CreateBranchOptions) (BranchResult, error)
	GetBranchTree(ctx context.Context, sessionID string) (BranchTree, error)
}

ConversationBranchStore is an optional capability so old/read-only schemas and custom stores can fail explicitly without expanding the core Store API.

type CreateBranchOptions added in v0.0.377

type CreateBranchOptions struct {
	AnchorMessageID int64
	ExpectedState   *TranscriptMutationState
	ExpectedRev     *int64
	IdempotencyKey  string
	PathNote        *BranchPathNote
}

CreateBranchOptions identifies a durable source prefix and optional optimistic concurrency/idempotency guards. AnchorMessageID zero means an empty prefix.

type DiffCommentMessageLister added in v0.0.400

type DiffCommentMessageLister interface {
	GetDiffCommentMessages(ctx context.Context, sessionID string) ([]Message, error)
}

DiffCommentMessageLister is an optional targeted lookup capability for stores that can select only messages carrying typed inline-diff comment metadata. Web comment hydration uses it to avoid loading and decoding an entire session.

type ExportOptions added in v0.0.56

type ExportOptions struct {
	IncludeSystem             bool // Include system prompt in export
	IncludeReasoningSummaries bool // Include provider-sanctioned reasoning summaries
	IncludeRawReasoning       bool // Include raw reasoning; caller must enforce safety gate
	Partial                   bool // Export is a transcript prefix; omit misleading whole-session metrics
	ResponseOnly              bool // Export is a standalone assistant response
}

ExportOptions configures session export.

type FallbackTranscriptIndexer added in v0.0.353

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

FallbackTranscriptIndexer adapts a Store without native revisioned transcript reads to the single web transcript protocol. Revisions are monotonic for the lifetime of the adapter and advance whenever the coherent message projection or compaction metadata changes.

func NewFallbackTranscriptIndexer added in v0.0.353

func NewFallbackTranscriptIndexer(store Store) *FallbackTranscriptIndexer

func (*FallbackTranscriptIndexer) GetMessagesByTranscriptRanges added in v0.0.353

func (f *FallbackTranscriptIndexer) GetMessagesByTranscriptRanges(ctx context.Context, sessionID string, ranges []TranscriptRange) (int64, []Message, error)

func (*FallbackTranscriptIndexer) GetTranscriptIndex added in v0.0.353

func (f *FallbackTranscriptIndexer) GetTranscriptIndex(ctx context.Context, sessionID string) (int64, []TranscriptIndexItem, error)

func (*FallbackTranscriptIndexer) GetTranscriptSnapshot added in v0.0.353

func (f *FallbackTranscriptIndexer) GetTranscriptSnapshot(ctx context.Context, sessionID string) (TranscriptSnapshot, error)

func (*FallbackTranscriptIndexer) TranscriptRev added in v0.0.353

func (f *FallbackTranscriptIndexer) TranscriptRev(ctx context.Context, sessionID string) (int64, error)

type GeneratedTitleUpdater added in v0.0.320

type GeneratedTitleUpdater interface {
	UpdateGeneratedTitle(ctx context.Context, id, shortTitle, longTitle string, generatedAt time.Time, basisMsgSeq int) error
}

GeneratedTitleUpdater is an optional Store capability for updating only the generated title fields. It avoids full-session Update writes from async title generation paths, where a stale in-memory Session snapshot could clobber concurrently updated metadata such as status or pinned state.

type Goal added in v0.0.321

type Goal struct {
	Objective       string     `json:"objective"`
	Status          GoalStatus `json:"status"`
	TokenBudget     int        `json:"token_budget,omitempty"`
	TokensUsed      int        `json:"tokens_used,omitempty"`
	TimeUsedSeconds int        `json:"time_used_seconds,omitempty"`
	CreatedAt       time.Time  `json:"created_at,omitempty"`
	UpdatedAt       time.Time  `json:"updated_at,omitempty"`
	CompletedAt     time.Time  `json:"completed_at,omitempty"`
	BlockedAt       time.Time  `json:"blocked_at,omitempty"`
	PausedAt        time.Time  `json:"paused_at,omitempty"`
	LastReason      string     `json:"last_reason,omitempty"`
	LastEvidence    string     `json:"last_evidence,omitempty"`
	UpdatedNotice   bool       `json:"updated_notice,omitempty"` // true when the next goal prompt should use objective_updated.md
}

Goal is the persisted, cross-frontend state for a session objective. A nil *Goal means the session has no goal configured.

func NewGoal added in v0.0.321

func NewGoal(objective string, tokenBudget int, now time.Time) *Goal

NewGoal constructs an active goal with normalized timestamps and budget.

func (*Goal) BudgetExhausted added in v0.0.321

func (g *Goal) BudgetExhausted() bool

BudgetExhausted reports whether a finite token budget has been consumed.

func (*Goal) Clone added in v0.0.321

func (g *Goal) Clone() *Goal

Clone returns a deep-enough copy for callers that should not mutate the persisted object in place.

func (*Goal) Exists added in v0.0.321

func (g *Goal) Exists() bool

Exists reports whether the goal has meaningful persisted state.

func (*Goal) IsActive added in v0.0.321

func (g *Goal) IsActive() bool

IsActive reports whether the runner should continue pursuing this goal.

func (*Goal) Normalize added in v0.0.321

func (g *Goal) Normalize(now time.Time)

Normalize fills defaults and clamps invalid counters.

func (*Goal) RemainingTokens added in v0.0.321

func (g *Goal) RemainingTokens() int

RemainingTokens returns the remaining token budget. A zero budget is unlimited.

type GoalStatus added in v0.0.321

type GoalStatus string

GoalStatus represents the lifecycle state of a persistent session goal.

const (
	GoalStatusActive        GoalStatus = "active"
	GoalStatusPaused        GoalStatus = "paused"
	GoalStatusComplete      GoalStatus = "complete"
	GoalStatusBlocked       GoalStatus = "blocked"
	GoalStatusBudgetLimited GoalStatus = "budget_limited"
)

type GoalUpdater added in v0.0.321

type GoalUpdater interface {
	UpdateGoal(ctx context.Context, id string, goal *Goal) error
}

GoalUpdater is an optional Store capability for updating only the persisted session goal. It avoids full-session Update writes from runner callbacks where a stale Session snapshot could clobber concurrently updated metadata.

type HandoverSlugGenerator added in v0.0.146

type HandoverSlugGenerator func(ctx context.Context, content string) (string, error)

HandoverSlugGenerator produces a short filesystem-safe slug from document content.

type ListOptions

type ListOptions struct {
	IDs              []string              // Restrict to these stable session IDs (deduplicated by the store)
	Name             string                // Filter by name
	Provider         string                // Filter by provider
	Model            string                // Filter by model
	Mode             SessionMode           // Filter by mode (chat, ask, plan, exec)
	Agent            string                // Filter by agent; empty persisted agents belong to "default"
	Status           SessionStatus         // Filter by status
	Tag              string                // Filter by tag (substring match)
	Categories       []string              // Sidebar/web categories (all, chat, web, ask, plan, exec)
	Limit            int                   // Max results (0 = use default, negative = unlimited)
	Offset           int                   // Pagination offset
	BeforeNumber     int64                 // Keyset cursor: only sessions with number < this value
	SortByNumberDesc bool                  // Order by session number descending instead of activity sort
	Archived         bool                  // Include archived sessions
	SortByActivity   bool                  // Sort by last_message_at (web sidebar); defaults to last_user_message_at
	ProjectID        string                // Restrict to one stable project ID
	NoProject        bool                  // Restrict to legacy sessions with a null project ID
	ProjectCursor    *ProjectSessionCursor // Group-bound keyset cursor for project sidebar paging
	ParentID         string                // Restrict to direct child sessions of this parent
	ExcludeSubagents bool                  // Hide machine-generated child-agent sessions
}

ListOptions configures session listing.

type LoggingStore added in v0.0.41

type LoggingStore struct {
	Store
	// contains filtered or unexported fields
}

LoggingStore wraps a Store and logs errors instead of silently discarding them. This preserves the best-effort semantics (operations don't fail the caller) while providing visibility into persistence issues.

func NewLoggingStore added in v0.0.41

func NewLoggingStore(store Store, warnFunc WarnFunc) *LoggingStore

NewLoggingStore creates a new LoggingStore wrapper. The warnFunc is called when persistence operations fail.

func (*LoggingStore) ActiveRush added in v0.9.31

func (s *LoggingStore) ActiveRush(ctx context.Context, sid string) (*RushOperation, error)

func (*LoggingStore) AddMessage added in v0.0.41

func (s *LoggingStore) AddMessage(ctx context.Context, sessionID string, msg *Message) error

AddMessage wraps Store.AddMessage with error logging.

func (*LoggingStore) AddMessageUnlogged added in v0.0.392

func (s *LoggingStore) AddMessageUnlogged(ctx context.Context, sessionID string, msg *Message) error

AddMessageUnlogged performs an AddMessage operation without consuming the wrapper's one-time warning. Callers use this only when they inspect and recover a known error before retrying through AddMessage normally.

func (*LoggingStore) AddMessageWithTranscriptRev added in v0.0.353

func (s *LoggingStore) AddMessageWithTranscriptRev(ctx context.Context, sessionID string, msg *Message) (int64, error)

func (*LoggingStore) AdmitRush added in v0.9.31

func (s *LoggingStore) AdmitRush(ctx context.Context, op RushOperation, entries []PendingSteering) (*RushOperation, error)

Rush operations preserve optional-capability detection through this decorator.

func (*LoggingStore) AdvanceRush added in v0.9.31

func (s *LoggingStore) AdvanceRush(ctx context.Context, op *RushOperation, status RushStatus, reason string) (*RushOperation, error)

func (*LoggingStore) AppendMessagesWithTranscriptRev added in v0.9.25

func (s *LoggingStore) AppendMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []*Message) (int64, error)

func (*LoggingStore) ClearCompactionBoundary added in v0.0.234

func (s *LoggingStore) ClearCompactionBoundary(ctx context.Context, id string) error

ClearCompactionBoundary wraps optional Store.ClearCompactionBoundary with error logging.

func (*LoggingStore) CommitRushInitialInput added in v0.9.31

func (s *LoggingStore) CommitRushInitialInput(ctx context.Context, op *RushOperation, messages []*Message) (int64, error)

func (*LoggingStore) Create added in v0.0.41

func (s *LoggingStore) Create(ctx context.Context, sess *Session) error

Create wraps Store.Create with error logging.

func (*LoggingStore) CreateBranch added in v0.0.377

func (s *LoggingStore) CreateBranch(ctx context.Context, sourceSessionID string, opts CreateBranchOptions) (BranchResult, error)

CreateBranch preserves the optional branching capability through the logging decorator.

func (*LoggingStore) DeletePendingSteering added in v0.9.31

func (s *LoggingStore) DeletePendingSteering(ctx context.Context, sessionID, id string) error

DeletePendingSteering removes a queued intent after commit or cancellation.

func (*LoggingStore) DeletePlanSnapshot added in v0.0.339

func (s *LoggingStore) DeletePlanSnapshot(ctx context.Context, sessionID string) error

DeletePlanSnapshot delegates the optional latest-plan capability when available.

func (*LoggingStore) DeleteProviderState added in v0.0.289

func (s *LoggingStore) DeleteProviderState(ctx context.Context, sessionID, providerKey string) error

DeleteProviderState delegates optional provider resume state deletion.

func (*LoggingStore) GetBranchByIdempotencyKey added in v0.0.377

func (s *LoggingStore) GetBranchByIdempotencyKey(ctx context.Context, sourceSessionID, idempotencyKey string) (BranchResult, bool, error)

GetBranchByIdempotencyKey preserves replay lookup through the logging decorator.

func (*LoggingStore) GetBranchTree added in v0.0.377

func (s *LoggingStore) GetBranchTree(ctx context.Context, sessionID string) (BranchTree, error)

GetBranchTree preserves the optional branching capability through the logging decorator.

func (*LoggingStore) GetDiffCommentMessages added in v0.0.400

func (s *LoggingStore) GetDiffCommentMessages(ctx context.Context, sessionID string) ([]Message, error)

GetDiffCommentMessages delegates the targeted typed inline-comment lookup.

func (*LoggingStore) GetLatestVisibleMessageID added in v0.0.250

func (s *LoggingStore) GetLatestVisibleMessageID(ctx context.Context, sessionID string) (int64, error)

GetLatestVisibleMessageID returns the latest persisted user/assistant message id for a session.

func (*LoggingStore) GetMessageByClientMessageID added in v0.0.363

func (s *LoggingStore) GetMessageByClientMessageID(ctx context.Context, sessionID, clientMessageID string) (*Message, error)

GetMessageByClientMessageID wraps an optional indexed client identity lookup.

func (*LoggingStore) GetMessageByID added in v0.0.225

func (s *LoggingStore) GetMessageByID(ctx context.Context, msgID int64) (*Message, error)

GetMessageByID wraps Store.GetMessageByID with error logging.

func (*LoggingStore) GetMessagesByClientMessageIDs added in v0.0.363

func (s *LoggingStore) GetMessagesByClientMessageIDs(ctx context.Context, sessionID string, clientMessageIDs []string) (map[string]*Message, error)

GetMessagesByClientMessageIDs unwraps the logger so fallback stores are scanned once rather than once per identity.

func (*LoggingStore) GetMessagesByTranscriptRanges added in v0.0.344

func (s *LoggingStore) GetMessagesByTranscriptRanges(ctx context.Context, sessionID string, ranges []TranscriptRange) (int64, []Message, error)

GetMessagesByTranscriptRanges delegates coherent complete-segment body reads.

func (*LoggingStore) GetMessagesPageDescending added in v0.0.261

func (s *LoggingStore) GetMessagesPageDescending(ctx context.Context, sessionID string, beforeSeq, limit int) ([]Message, error)

GetMessagesPageDescending returns a reverse-ordered page of messages. It delegates when the wrapped store supports efficient paging; otherwise it falls back to in-memory paging over GetMessages.

func (*LoggingStore) GetResponseRunStartState added in v0.0.406

func (s *LoggingStore) GetResponseRunStartState(ctx context.Context, sessionID string) (ResponseRunStartState, error)

GetResponseRunStartState delegates compact response-run transcript reads.

func (*LoggingStore) GetRush added in v0.9.31

func (s *LoggingStore) GetRush(ctx context.Context, sid, id string) (*RushOperation, error)

func (*LoggingStore) GetTranscriptIndex added in v0.0.344

func (s *LoggingStore) GetTranscriptIndex(ctx context.Context, sessionID string) (int64, []TranscriptIndexItem, error)

GetTranscriptIndex delegates coherent transcript identity reads.

func (*LoggingStore) GetTranscriptSnapshot added in v0.0.344

func (s *LoggingStore) GetTranscriptSnapshot(ctx context.Context, sessionID string) (TranscriptSnapshot, error)

GetTranscriptSnapshot delegates coherent transcript envelope reads.

func (*LoggingStore) IncrementUserTurns added in v0.0.41

func (s *LoggingStore) IncrementUserTurns(ctx context.Context, id string) error

IncrementUserTurns wraps Store.IncrementUserTurns with error logging.

func (*LoggingStore) LatestRush added in v0.9.31

func (s *LoggingStore) LatestRush(ctx context.Context, sid string) (*RushOperation, error)

func (*LoggingStore) ListPendingSteering added in v0.9.31

func (s *LoggingStore) ListPendingSteering(ctx context.Context, sessionID string) ([]PendingSteering, error)

ListPendingSteering returns durable queued intents in acceptance order.

func (*LoggingStore) LoadPlanSnapshot added in v0.0.339

func (s *LoggingStore) LoadPlanSnapshot(ctx context.Context, sessionID string) (planpkg.Snapshot, int64, error)

LoadPlanSnapshot delegates the optional latest-plan capability when available.

func (*LoggingStore) LoadProviderState added in v0.0.289

func (s *LoggingStore) LoadProviderState(ctx context.Context, sessionID, providerKey string) ([]byte, error)

LoadProviderState delegates optional provider resume state loading.

func (*LoggingStore) NextUserPrompt added in v0.0.281

func (s *LoggingStore) NextUserPrompt(ctx context.Context, agent string, afterID int64) (*PromptHistoryEntry, error)

NextUserPrompt delegates the optional PromptHistoryStore capability when the wrapped store supports it.

func (*LoggingStore) NextUserPromptOutsideSession added in v0.0.281

func (s *LoggingStore) NextUserPromptOutsideSession(ctx context.Context, excludeSessionID string, afterID int64, afterCreatedAt time.Time) (*PromptHistoryEntry, error)

NextUserPromptOutsideSession delegates the optional global prompt-history capability when the wrapped store supports it.

func (*LoggingStore) PreviousUserPrompt added in v0.0.281

func (s *LoggingStore) PreviousUserPrompt(ctx context.Context, agent string, beforeID int64) (*PromptHistoryEntry, error)

PreviousUserPrompt delegates the optional PromptHistoryStore capability when the wrapped store supports it.

func (*LoggingStore) PreviousUserPromptOutsideSession added in v0.0.281

func (s *LoggingStore) PreviousUserPromptOutsideSession(ctx context.Context, excludeSessionID string, beforeID int64, beforeCreatedAt time.Time) (*PromptHistoryEntry, error)

PreviousUserPromptOutsideSession delegates the optional global prompt-history capability when the wrapped store supports it.

func (*LoggingStore) RedoLastUserTurn added in v0.0.373

func (s *LoggingStore) RedoLastUserTurn(ctx context.Context, sessionID string, expected TranscriptMutationState) (TranscriptMutationResult, error)

RedoLastUserTurn delegates storage-owned redo.

func (*LoggingStore) ReleaseRush added in v0.9.31

func (s *LoggingStore) ReleaseRush(ctx context.Context, op *RushOperation) error

func (*LoggingStore) ReplaceCompactedMessages added in v0.0.313

func (s *LoggingStore) ReplaceCompactedMessages(ctx context.Context, sessionID string, messages []Message) error

ReplaceCompactedMessages wraps optional Store.ReplaceCompactedMessages with error logging.

func (*LoggingStore) ReplaceCompactedMessagesWithTranscriptRev added in v0.0.353

func (s *LoggingStore) ReplaceCompactedMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []Message) (int64, error)

func (*LoggingStore) ReplaceMessagesWithTranscriptRev added in v0.0.353

func (s *LoggingStore) ReplaceMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []Message) (int64, error)

func (*LoggingStore) ReportAddMessageError added in v0.0.392

func (s *LoggingStore) ReportAddMessageError(err error)

ReportAddMessageError records an error returned by AddMessageUnlogged when the caller could not recover it.

func (*LoggingStore) SavePendingSteering added in v0.9.31

func (s *LoggingStore) SavePendingSteering(ctx context.Context, entry PendingSteering) error

SavePendingSteering delegates durable queued-steering persistence.

func (*LoggingStore) SavePlanSnapshot added in v0.0.339

func (s *LoggingStore) SavePlanSnapshot(ctx context.Context, sessionID string, snapshot planpkg.Snapshot) (int64, error)

SavePlanSnapshot delegates the optional latest-plan capability when available. Unsupported custom stores retain the controller's in-memory state only.

func (*LoggingStore) SaveProviderState added in v0.0.289

func (s *LoggingStore) SaveProviderState(ctx context.Context, sessionID, providerKey string, state []byte) error

SaveProviderState delegates optional provider resume state persistence.

func (*LoggingStore) SessionSummariesIncludeTranscriptRev added in v0.0.344

func (s *LoggingStore) SessionSummariesIncludeTranscriptRev() bool

SessionSummariesIncludeTranscriptRev preserves the wrapped store's list-query capability through the logging decorator.

func (*LoggingStore) SetCurrent added in v0.0.41

func (s *LoggingStore) SetCurrent(ctx context.Context, sessionID string) error

SetCurrent wraps Store.SetCurrent with error logging.

func (*LoggingStore) SupportsBatchTranscriptWriter added in v0.9.25

func (s *LoggingStore) SupportsBatchTranscriptWriter() bool

func (*LoggingStore) TranscriptMutationState added in v0.0.373

func (s *LoggingStore) TranscriptMutationState(ctx context.Context, sessionID string) (TranscriptMutationState, error)

TranscriptMutationState delegates optimistic transcript mutation state.

func (*LoggingStore) TranscriptRev added in v0.0.344

func (s *LoggingStore) TranscriptRev(ctx context.Context, sessionID string) (int64, error)

TranscriptRev delegates durable transcript revision reads.

func (*LoggingStore) TranscriptVersioned added in v0.0.344

func (s *LoggingStore) TranscriptVersioned() bool

TranscriptVersioned reports whether the wrapped store has a revisioned schema.

func (*LoggingStore) UndoLastUserTurn added in v0.0.373

func (s *LoggingStore) UndoLastUserTurn(ctx context.Context, sessionID string, expected TranscriptMutationState) (TranscriptMutationResult, error)

UndoLastUserTurn delegates storage-owned undo.

func (*LoggingStore) Update added in v0.0.41

func (s *LoggingStore) Update(ctx context.Context, sess *Session) error

Update wraps Store.Update with error logging.

func (*LoggingStore) UpdateContextEstimate added in v0.0.161

func (s *LoggingStore) UpdateContextEstimate(ctx context.Context, id string, lastTotalTokens, lastMessageCount int) error

UpdateContextEstimate wraps Store.UpdateContextEstimate with error logging.

func (*LoggingStore) UpdateGeneratedTitle added in v0.0.320

func (s *LoggingStore) UpdateGeneratedTitle(ctx context.Context, id, shortTitle, longTitle string, generatedAt time.Time, basisMsgSeq int) error

UpdateGeneratedTitle wraps the optional title-only update path with error logging.

func (*LoggingStore) UpdateGoal added in v0.0.321

func (s *LoggingStore) UpdateGoal(ctx context.Context, id string, goal *Goal) error

UpdateGoal wraps the optional goal-only update path with error logging.

func (*LoggingStore) UpdateMessage added in v0.0.174

func (s *LoggingStore) UpdateMessage(ctx context.Context, sessionID string, msg *Message) error

UpdateMessage wraps Store.UpdateMessage with error logging. ErrNotFound is returned to the caller verbatim (no logging) so upsert callers can fall back to AddMessage without noise.

func (*LoggingStore) UpdateMetrics added in v0.0.41

func (s *LoggingStore) UpdateMetrics(ctx context.Context, id string, llmTurns, toolCalls, inputTokens, outputTokens, cachedInputTokens, cacheWriteTokens int) error

UpdateMetrics wraps Store.UpdateMetrics with error logging.

func (*LoggingStore) UpdateShare added in v0.0.324

func (s *LoggingStore) UpdateShare(ctx context.Context, id string, share *ShareState) error

UpdateShare wraps the optional share-only update path with error logging.

func (*LoggingStore) UpdateStatus added in v0.0.41

func (s *LoggingStore) UpdateStatus(ctx context.Context, id string, status SessionStatus) error

UpdateStatus wraps Store.UpdateStatus with error logging.

func (*LoggingStore) UpdateStreamingMessage added in v0.0.289

func (s *LoggingStore) UpdateStreamingMessage(ctx context.Context, sessionID string, msg *Message, finalizeText bool) error

UpdateStreamingMessage wraps the optional streaming-aware update path with the same error logging semantics as UpdateMessage.

func (*LoggingStore) UpdateStreamingMessageWithTranscriptRev added in v0.0.353

func (s *LoggingStore) UpdateStreamingMessageWithTranscriptRev(ctx context.Context, sessionID string, msg *Message, finalizeText bool) (int64, error)

type Message

type Message struct {
	ID                      int64      `json:"id"`
	SessionID               string     `json:"session_id"`
	Role                    llm.Role   `json:"role"`
	Parts                   []llm.Part `json:"parts"`        // Full parts array
	TextContent             string     `json:"text_content"` // Extracted text for display/FTS
	DurationMs              int64      `json:"duration_ms,omitempty"`
	TurnIndex               int        `json:"turn_index,omitempty"`
	CreatedAt               time.Time  `json:"created_at"`
	Sequence                int        `json:"sequence"`
	CompactionTail          bool       `json:"compaction_tail,omitempty"` // Persisted display hint: retained post-compaction context already visible before the marker
	ClientMessageID         string     `json:"client_message_id,omitempty"`
	ResponseID              string     `json:"response_id,omitempty"`
	AssistantSegmentOrdinal int        `json:"assistant_segment_ordinal"` // Response-scoped; -1 when the row is not an assistant segment.
	SegmentStartSequence    int64      `json:"segment_start_sequence,omitempty"`
	SegmentEndSequence      int64      `json:"segment_end_sequence,omitempty"`
}

Message represents a message in a session. The Parts field stores the full llm.Message.Parts as JSON to preserve tool calls, uploaded images/files, and provider replay state exactly.

func FindMessageByClientMessageID added in v0.0.363

func FindMessageByClientMessageID(ctx context.Context, store Store, sessionID, clientMessageID string) (*Message, error)

FindMessageByClientMessageID uses an indexed lookup when available and falls back to scanning stores that do not implement the optional capability.

func LoadActiveMessages added in v0.0.234

func LoadActiveMessages(ctx context.Context, store Store, sess *Session) ([]Message, error)

LoadActiveMessages loads the messages that should be sent as active LLM context for a session. If the session has been compacted, older scrollback rows are intentionally skipped and callers receive only rows at/after the compaction boundary.

func LoadInitialScrollbackWithBoundary added in v0.0.309

func LoadInitialScrollbackWithBoundary(ctx context.Context, store Store, sess *Session) ([]Message, int, error)

LoadInitialScrollbackWithBoundary loads the messages needed for the first UI paint while also returning the index where active LLM context begins. For compacted sessions it loads only rows at/after the persisted boundary so long resumes avoid an eager full-transcript read; callers may load older display history lazily if needed.

func LoadScrollbackWithBoundary added in v0.0.234

func LoadScrollbackWithBoundary(ctx context.Context, store Store, sess *Session) ([]Message, int, error)

LoadScrollbackWithBoundary loads all persisted messages for display while also returning the index where active LLM context begins.

func NewMessage

func NewMessage(sessionID string, msg llm.Message, sequence int) *Message

NewMessage creates a new Message from an llm.Message with the given session ID and sequence.

func NewMessageWithReasoningPolicy added in v0.0.258

func NewMessageWithReasoningPolicy(sessionID string, msg llm.Message, sequence int, cfg config.ReasoningConfig) *Message

NewMessageWithReasoningPolicy creates a session message after applying the configured reasoning persistence policy.

func NewPathNoteMessage added in v0.0.377

func NewPathNoteMessage(sessionID, notes string, provenance llm.PathNoteProvenance, sequence int) *Message

NewPathNoteMessage creates provider-visible developer context with a persistence-only marker so UI and compaction code can recognize it safely.

func SelectShareMessages added in v0.9.22

func SelectShareMessages(messages []Message, anchorMessageID int64, scope ShareScope) ([]Message, error)

SelectShareMessages validates anchorMessageID and returns an authoritative, human-visible subset for a point-in-time share. Response shares contain only the assistant's rendered text; conversation shares include the transcript up to and including the anchored row.

func VisibleExportMessages added in v0.0.322

func VisibleExportMessages(messages []Message) []Message

VisibleExportMessages returns messages intended for human-readable exports. Retained post-compaction context is already represented earlier in scrollback.

func (*Message) ExtractTextContent

func (m *Message) ExtractTextContent() string

ExtractTextContent extracts and concatenates all text parts from the message.

func (*Message) IsGoalSteering added in v0.9.0

func (m *Message) IsGoalSteering() bool

IsGoalSteering reports whether this row is an internal active-goal prompt. Rows written before goal_steering metadata existed are recognized only when they lack a first-party client identity.

func (*Message) PartsJSON

func (m *Message) PartsJSON() (string, error)

PartsJSON returns the Parts field serialized to JSON for database storage.

func (*Message) PartsJSONForStorage added in v0.0.312

func (m *Message) PartsJSONForStorage(stripImageBase64 bool) (string, error)

func (*Message) PathNoteDisplayText added in v0.0.377

func (m *Message) PathNoteDisplayText() string

PathNoteDisplayText removes the provider-facing safety preamble from a path note.

func (*Message) PathNoteProvenance added in v0.0.377

func (m *Message) PathNoteProvenance() (*llm.PathNoteProvenance, bool)

PathNoteProvenance returns the marker attached to a generated path-note row.

func (*Message) SetPartsFromJSON

func (m *Message) SetPartsFromJSON(data string) error

SetPartsFromJSON deserializes JSON into the Parts field.

func (*Message) ToLLMMessage

func (m *Message) ToLLMMessage() llm.Message

ToLLMMessage converts a Message back to an llm.Message.

type MessageSequenceStore added in v0.0.344

type MessageSequenceStore interface {
	MaxMessageSequences(ctx context.Context, sessionIDs []string) (map[string]int, error)
}

MessageSequenceStore is an optional Store capability for fetching the latest message sequence for many sessions without issuing one query per session. Callers must preserve behavior when a store does not implement this fast path.

type MessagesDescendingPager added in v0.0.261

type MessagesDescendingPager interface {
	GetMessagesPageDescending(ctx context.Context, sessionID string, beforeSeq, limit int) ([]Message, error)
}

MessagesDescendingPager is an optional Store capability for efficient reverse pagination over session messages. Implementations return messages ordered by descending sequence and, when beforeSeq > 0, only rows with sequence < beforeSeq.

type NoopStore

type NoopStore struct{}

NoopStore is a no-op implementation of Store used when sessions are disabled. It silently discards all writes and returns empty results for reads.

func (*NoopStore) AddMessage

func (s *NoopStore) AddMessage(ctx context.Context, sessionID string, msg *Message) error

func (*NoopStore) ClearCurrent

func (s *NoopStore) ClearCurrent(ctx context.Context) error

func (*NoopStore) Close

func (s *NoopStore) Close() error

func (*NoopStore) CompactMessages added in v0.0.115

func (s *NoopStore) CompactMessages(ctx context.Context, sessionID string, messages []Message) error

func (*NoopStore) Create

func (s *NoopStore) Create(ctx context.Context, sess *Session) error

func (*NoopStore) Delete

func (s *NoopStore) Delete(ctx context.Context, id string) error

func (*NoopStore) DeletePushSubscription added in v0.0.114

func (s *NoopStore) DeletePushSubscription(ctx context.Context, endpoint string) error

func (*NoopStore) Get

func (s *NoopStore) Get(ctx context.Context, id string) (*Session, error)

func (*NoopStore) GetByNumber added in v0.0.56

func (s *NoopStore) GetByNumber(ctx context.Context, number int64) (*Session, error)

func (*NoopStore) GetByPrefix added in v0.0.52

func (s *NoopStore) GetByPrefix(ctx context.Context, prefix string) (*Session, error)

func (*NoopStore) GetCurrent

func (s *NoopStore) GetCurrent(ctx context.Context) (*Session, error)

func (*NoopStore) GetMessageByID added in v0.0.225

func (s *NoopStore) GetMessageByID(ctx context.Context, msgID int64) (*Message, error)

func (*NoopStore) GetMessages

func (s *NoopStore) GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)

func (*NoopStore) GetMessagesFrom added in v0.0.115

func (s *NoopStore) GetMessagesFrom(ctx context.Context, sessionID string, fromSeq, limit int) ([]Message, error)

func (*NoopStore) IncrementUserTurns added in v0.0.41

func (s *NoopStore) IncrementUserTurns(ctx context.Context, id string) error

func (*NoopStore) List

func (s *NoopStore) List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)

func (*NoopStore) ListPushSubscriptions added in v0.0.114

func (s *NoopStore) ListPushSubscriptions(ctx context.Context) ([]PushSubscription, error)

func (*NoopStore) MarkTitleSkipped added in v0.0.131

func (s *NoopStore) MarkTitleSkipped(ctx context.Context, id string, t time.Time) error

func (*NoopStore) NextUserPrompt added in v0.0.281

func (s *NoopStore) NextUserPrompt(ctx context.Context, agent string, afterID int64) (*PromptHistoryEntry, error)

func (*NoopStore) NextUserPromptOutsideSession added in v0.0.281

func (s *NoopStore) NextUserPromptOutsideSession(ctx context.Context, excludeSessionID string, afterID int64, afterCreatedAt time.Time) (*PromptHistoryEntry, error)

func (*NoopStore) PreviousUserPrompt added in v0.0.281

func (s *NoopStore) PreviousUserPrompt(ctx context.Context, agent string, beforeID int64) (*PromptHistoryEntry, error)

func (*NoopStore) PreviousUserPromptOutsideSession added in v0.0.281

func (s *NoopStore) PreviousUserPromptOutsideSession(ctx context.Context, excludeSessionID string, beforeID int64, beforeCreatedAt time.Time) (*PromptHistoryEntry, error)

func (*NoopStore) ReplaceMessages added in v0.0.80

func (s *NoopStore) ReplaceMessages(ctx context.Context, sessionID string, messages []Message) error

func (*NoopStore) SavePushSubscription added in v0.0.114

func (s *NoopStore) SavePushSubscription(ctx context.Context, sub *PushSubscription) error

func (*NoopStore) Search

func (s *NoopStore) Search(ctx context.Context, opts SearchOptions) ([]SearchResult, error)

func (*NoopStore) SetCurrent

func (s *NoopStore) SetCurrent(ctx context.Context, sessionID string) error

func (*NoopStore) Update

func (s *NoopStore) Update(ctx context.Context, sess *Session) error

func (*NoopStore) UpdateContextEstimate added in v0.0.161

func (s *NoopStore) UpdateContextEstimate(ctx context.Context, id string, lastTotalTokens, lastMessageCount int) error

func (*NoopStore) UpdateMessage added in v0.0.174

func (s *NoopStore) UpdateMessage(ctx context.Context, sessionID string, msg *Message) error

func (*NoopStore) UpdateMetrics added in v0.0.41

func (s *NoopStore) UpdateMetrics(ctx context.Context, id string, llmTurns, toolCalls, inputTokens, outputTokens, cachedInputTokens, cacheWriteTokens int) error

func (*NoopStore) UpdateStatus added in v0.0.41

func (s *NoopStore) UpdateStatus(ctx context.Context, id string, status SessionStatus) error

type PendingSteering added in v0.9.31

type PendingSteering struct {
	SessionID          string             `json:"session_id"`
	ID                 string             `json:"id"`
	Message            llm.Message        `json:"message"`
	DisplayText        string             `json:"display_text"`
	AttachmentSummary  string             `json:"attachment_summary"`
	CreatedAt          time.Time          `json:"created_at"`
	AcceptanceSequence int64              `json:"acceptance_sequence"`
	Origin             llm.SteeringOrigin `json:"origin"`
	OwnerKind          string             `json:"owner_kind"`
	OwnerID            string             `json:"owner_id"`
	OwnerFence         int64              `json:"owner_fence"`
}

PendingSteering is a durable, not-yet-committed steering intent. It lives outside the transcript until the engine consumes it, so restoring a session cannot accidentally send the same user message to a provider early.

type PendingSteeringStore added in v0.9.31

type PendingSteeringStore interface {
	SavePendingSteering(ctx context.Context, entry PendingSteering) error
	DeletePendingSteering(ctx context.Context, sessionID, id string) error
	ListPendingSteering(ctx context.Context, sessionID string) ([]PendingSteering, error)
}

PendingSteeringStore persists queued steering intents across tabs and runtime loss. Committed steering are still written to messages through the normal turn-completion path.

func AsPendingSteeringStore added in v0.9.31

func AsPendingSteeringStore(store Store) (PendingSteeringStore, bool)

AsPendingSteeringStore resolves the optional capability through the logging decorator without making unsupported custom stores appear durable.

type PlanSnapshotStore added in v0.0.339

type PlanSnapshotStore interface {
	LoadPlanSnapshot(ctx context.Context, sessionID string) (planpkg.Snapshot, int64, error)
	SavePlanSnapshot(ctx context.Context, sessionID string, snapshot planpkg.Snapshot) (int64, error)
	DeletePlanSnapshot(ctx context.Context, sessionID string) error
}

PlanSnapshotStore is an optional Store capability for the authoritative latest update_plan snapshot. Transcript tool-call/result parts remain the durable replay record; this narrow store supports efficient resume restoration.

type Project added in v0.0.404

type Project struct {
	ID                string     `json:"id"`
	Name              string     `json:"name"`
	CanonicalDir      string     `json:"canonical_dir"`
	IsBootstrap       bool       `json:"is_bootstrap,omitempty"`
	CreatedAt         time.Time  `json:"created_at"`
	UpdatedAt         time.Time  `json:"updated_at"`
	LastUsedAt        time.Time  `json:"last_used_at"`
	ArchivedAt        *time.Time `json:"archived_at,omitempty"`
	ConversationCount int        `json:"conversation_count"`
	Available         bool       `json:"available"`
	Git               bool       `json:"git"`
	UnavailableReason string     `json:"unavailable_reason,omitempty"`
}

Project is durable operator-managed metadata. CanonicalDir is immutable; Session.CWD and Session.WorktreeDir remain the execution snapshot.

func (Project) Archived added in v0.0.404

func (p Project) Archived() bool

type ProjectListOptions added in v0.0.404

type ProjectListOptions struct {
	IncludeArchived bool
}

type ProjectReader added in v0.0.404

type ProjectReader interface {
	GetProject(ctx context.Context, id string) (*Project, error)
}

ProjectReader is the read-only capability used to restore immutable project sessions even when project mutation mode is unavailable (for example, a read-only SQLite deployment that auto-disabled the project UI).

func AsProjectReader added in v0.0.404

func AsProjectReader(store Store) (ProjectReader, bool)

type ProjectSessionCursor added in v0.0.404

type ProjectSessionCursor struct {
	ProjectID  string    `json:"g"`
	Scope      string    `json:"s,omitempty"`
	Pinned     bool      `json:"p"`
	ActivityAt time.Time `json:"a"`
	Number     int64     `json:"n"`
}

func DecodeProjectSessionCursor added in v0.0.404

func DecodeProjectSessionCursor(value string) (ProjectSessionCursor, error)

type ProjectSessionMatch added in v0.0.404

type ProjectSessionMatch struct {
	ID          string
	CWD         string
	WorktreeDir string
}

ProjectSessionMatch is a prevalidated legacy session workspace that may be claimed by an atomic project bootstrap if its persisted paths are unchanged.

type ProjectStore added in v0.0.404

type ProjectStore interface {
	ListProjects(ctx context.Context, opts ProjectListOptions) ([]Project, error)
	GetProject(ctx context.Context, id string) (*Project, error)
	GetProjectByCanonicalDir(ctx context.Context, canonicalDir string) (*Project, error)
	HasActiveProjects(ctx context.Context) (bool, error)
	CreateProject(ctx context.Context, project *Project) error
	UpdateProject(ctx context.Context, id string, update ProjectUpdate) (*Project, error)
	BootstrapProject(ctx context.Context, project *Project, matchingSessions []ProjectSessionMatch) error
	ClaimProjectSessions(ctx context.Context, projectID string, matchingSessions []ProjectSessionMatch) (int, error)
	Sidebar(ctx context.Context, opts SidebarOptions) ([]SidebarGroup, error)
	AssignSessionProject(ctx context.Context, sessionID, projectID, expectedCWD, expectedWorktreeDir string) error
}

ProjectStore is optional so custom and read-only pre-migration stores remain usable without falsely advertising project support.

func AsProjectStore added in v0.0.404

func AsProjectStore(store Store) (ProjectStore, bool)

type ProjectUpdate added in v0.0.404

type ProjectUpdate struct {
	Name     *string
	Archived *bool
}

ProjectUpdate deliberately excludes CanonicalDir; project roots are immutable.

type PromptHistoryEntry added in v0.0.281

type PromptHistoryEntry struct {
	ID        int64
	CreatedAt time.Time
	Text      string
}

PromptHistoryEntry is a user prompt recalled from composer history.

type PromptHistoryOutsideSessionStore added in v0.0.281

type PromptHistoryOutsideSessionStore interface {
	PreviousUserPromptOutsideSession(ctx context.Context, excludeSessionID string, beforeID int64, beforeCreatedAt time.Time) (*PromptHistoryEntry, error)
	NextUserPromptOutsideSession(ctx context.Context, excludeSessionID string, afterID int64, afterCreatedAt time.Time) (*PromptHistoryEntry, error)
}

PromptHistoryOutsideSessionStore is an optional Store capability for the TUI composer history sequence after the current session's in-memory prompts have been exhausted. It traverses persisted user prompts from all agents while excluding the current session to avoid duplicate recalls.

type PromptHistoryStore added in v0.0.281

type PromptHistoryStore interface {
	PreviousUserPrompt(ctx context.Context, agent string, beforeID int64) (*PromptHistoryEntry, error)
	NextUserPrompt(ctx context.Context, agent string, afterID int64) (*PromptHistoryEntry, error)
}

PromptHistoryStore is an optional Store capability for shell-style composer history recall. Implementations traverse persisted user prompts globally so multiple TUI processes share the same prompt history.

type ProviderStateStore added in v0.0.289

type ProviderStateStore interface {
	SaveProviderState(ctx context.Context, sessionID, providerKey string, state []byte) error
	LoadProviderState(ctx context.Context, sessionID, providerKey string) ([]byte, error)
	DeleteProviderState(ctx context.Context, sessionID, providerKey string) error
}

ProviderStateStore is an optional Store capability for provider-specific resume state. It stores opaque JSON/blob payloads keyed by term-llm session and provider key, allowing stateful CLI providers to survive runtime eviction without leaking that state into the user-visible transcript.

type PushSubscription added in v0.0.114

type PushSubscription struct {
	ID              string
	Endpoint        string
	KeyP256DH       string
	KeyAuth         string
	Status          string
	VAPIDKeyID      string
	UpdatedAt       time.Time
	LastUsedAt      time.Time
	LastFailureCode string
	LastFailure     string
	LastFailureAt   time.Time
}

PushSubscription represents a Web Push subscription stored in the database.

type PushSubscriptionLifecycleStore added in v0.9.0

type PushSubscriptionLifecycleStore interface {
	UpsertPushSubscription(ctx context.Context, sub *PushSubscription) (*PushSubscription, error)
	GetPushSubscription(ctx context.Context, id string) (*PushSubscription, error)
	DeletePushSubscriptionByID(ctx context.Context, id string) error
	MarkPushSubscriptionStale(ctx context.Context, id, code, detail string) error
	MarkPushSubscriptionUsed(ctx context.Context, id string) error
}

func AsPushSubscriptionLifecycleStore added in v0.9.0

func AsPushSubscriptionLifecycleStore(store Store) (PushSubscriptionLifecycleStore, bool)

type ResponseRunAdmission added in v0.9.12

type ResponseRunAdmission struct {
	ResponseID      string
	SessionID       string
	RunEpoch        int64
	OwnerInstanceID string
	StartedRev      int64
	StartedAt       time.Time
	LeaseDuration   time.Duration
}

ResponseRunAdmission durably accounts for a run before provider work starts.

type ResponseRunCheckpoint added in v0.9.12

type ResponseRunCheckpoint struct {
	ResponseID         string
	OwnerInstanceID    string
	FencingToken       int64
	FinalRev           int64
	DurableOutputCount int
}

type ResponseRunFence added in v0.9.12

type ResponseRunFence struct {
	ResponseID         string
	OwnerInstanceID    string
	FencingToken       int64
	DurableOutputCount int
}

ResponseRunFence travels with response-scoped transcript writes. SQLite validates and checkpoints it in the same transaction as the transcript mutation so a recovered/stale owner cannot commit after losing ownership.

func ResponseRunFenceFromContext added in v0.9.12

func ResponseRunFenceFromContext(ctx context.Context) (ResponseRunFence, bool)

type ResponseRunInteractionState added in v0.9.14

type ResponseRunInteractionState struct {
	ResponseID      string
	OwnerInstanceID string
	FencingToken    int64
	Revision        int64
	Count           int
	Kinds           []string
	RequiredSince   time.Time
}

ResponseRunInteractionState is the level-triggered, payload-free projection of actionable interactions currently blocking one response run.

type ResponseRunInteractionStore added in v0.9.14

type ResponseRunInteractionStore interface {
	SetResponseRunInteractionState(context.Context, ResponseRunInteractionState) error
}

ResponseRunInteractionStore is optional so older/custom lifecycle stores keep their existing running and terminal-attention capabilities.

func AsResponseRunInteractionStore added in v0.9.14

func AsResponseRunInteractionStore(store Store) (ResponseRunInteractionStore, bool)

type ResponseRunLease added in v0.9.12

type ResponseRunLease struct {
	ResponseID     string
	FencingToken   int64
	LeaseExpiresAt time.Time
}

type ResponseRunStartState added in v0.0.406

type ResponseRunStartState struct {
	Rev               int64
	CompactionSeq     int
	CompactionCount   int
	DurableBoundaryID int64
}

ResponseRunStartState is the compact transcript envelope needed when a stateful response run starts. DurableBoundaryID is the latest non-compaction user, assistant, or tool row, or zero when no such row exists.

type ResponseRunStartStateReader added in v0.0.406

type ResponseRunStartStateReader interface {
	GetResponseRunStartState(ctx context.Context, sessionID string) (ResponseRunStartState, error)
}

ResponseRunStartStateReader is an optional Store capability for reading the response-run transcript envelope without materializing historical bodies.

type ResponseRunState added in v0.9.12

type ResponseRunState string

ResponseRunState is the durable lifecycle state of a serve-origin web run.

const (
	ResponseRunRunning   ResponseRunState = "running"
	ResponseRunCompleted ResponseRunState = "completed"
	ResponseRunFailed    ResponseRunState = "failed"
	ResponseRunCancelled ResponseRunState = "cancelled"
	ResponseRunOrphaned  ResponseRunState = "orphaned"
)

type ResponseRunTerminal added in v0.9.12

type ResponseRunTerminal struct {
	ResponseID         string
	OwnerInstanceID    string
	FencingToken       int64
	Outcome            ResponseRunState
	FinalRev           int64
	DurableOutputCount int
	EndedAt            time.Time
}

type RushEntry added in v0.9.31

type RushEntry struct {
	Steering    PendingSteering `json:"steering"`
	Disposition string          `json:"disposition"`
}

type RushOperation added in v0.9.31

type RushOperation struct {
	SessionID             string      `json:"session_id"`
	RequestID             string      `json:"rush_id"`
	SourceResponseID      string      `json:"source_response_id"`
	SourceEpoch           int64       `json:"source_run_epoch"`
	Status                RushStatus  `json:"status"`
	Revision              int64       `json:"revision"`
	ReplacementResponseID string      `json:"replacement_response_id,omitempty"`
	Fence                 int64       `json:"-"`
	Reason                string      `json:"reason,omitempty"`
	Entries               []RushEntry `json:"entries"`
	SteeringIDs           []string    `json:"steering_ids"`
	CreatedAt             time.Time   `json:"created_at"`
	UpdatedAt             time.Time   `json:"updated_at"`
}

type RushStatus added in v0.9.31

type RushStatus string
const (
	RushInterrupting RushStatus = "interrupting"
	RushWaiting      RushStatus = "waiting_for_settlement"
	RushStarting     RushStatus = "starting"
	RushStarted      RushStatus = "started"
	RushBlocked      RushStatus = "blocked"
	RushCancelled    RushStatus = "cancelled"
	RushFailed       RushStatus = "failed"
	RushNoop         RushStatus = "noop"
)

func (RushStatus) Active added in v0.9.31

func (s RushStatus) Active() bool

type RushStore added in v0.9.31

func AsRushStore added in v0.9.31

func AsRushStore(store Store) (RushStore, bool)

type SQLiteStore

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

SQLiteStore implements Store using SQLite.

func NewSQLiteStore

func NewSQLiteStore(cfg Config) (*SQLiteStore, error)

NewSQLiteStore creates a new SQLite-based session store.

func (*SQLiteStore) ActiveRush added in v0.9.31

func (s *SQLiteStore) ActiveRush(ctx context.Context, sessionID string) (*RushOperation, error)

func (*SQLiteStore) AddMessage

func (s *SQLiteStore) AddMessage(ctx context.Context, sessionID string, msg *Message) error

AddMessage adds a message to a session. If msg.Sequence < 0, the sequence number is auto-allocated atomically.

func (*SQLiteStore) AddMessageWithTranscriptRev added in v0.0.353

func (s *SQLiteStore) AddMessageWithTranscriptRev(ctx context.Context, sessionID string, msg *Message) (int64, error)

AddMessageWithTranscriptRev adds a message and returns the revision bumped by the same transaction.

func (*SQLiteStore) AdmitResponseRun added in v0.9.12

func (s *SQLiteStore) AdmitResponseRun(ctx context.Context, admission ResponseRunAdmission) (ResponseRunLease, error)

func (*SQLiteStore) AdmitRush added in v0.9.31

func (s *SQLiteStore) AdmitRush(ctx context.Context, op RushOperation, entries []PendingSteering) (*RushOperation, error)

Admission is idempotent by session/request/source, and snapshots exactly the frozen engine batch. Missing, changed or differently owned rows abort it all.

func (*SQLiteStore) AdvanceRush added in v0.9.31

func (s *SQLiteStore) AdvanceRush(ctx context.Context, op *RushOperation, status RushStatus, reason string) (*RushOperation, error)

func (*SQLiteStore) AppendMessagesWithTranscriptRev added in v0.9.25

func (s *SQLiteStore) AppendMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []*Message) (int64, error)

AppendMessagesWithTranscriptRev atomically appends messages in input order, allocates consecutive sequences, and bumps transcript_rev once.

func (*SQLiteStore) AssignSessionProject added in v0.0.404

func (s *SQLiteStore) AssignSessionProject(ctx context.Context, sessionID, projectID, expectedCWD, expectedWorktreeDir string) error

func (*SQLiteStore) BindSessionWorkspace added in v0.0.404

func (s *SQLiteStore) BindSessionWorkspace(ctx context.Context, sessionID string, binding SessionWorkspaceBinding) (*Session, error)

func (*SQLiteStore) BootstrapProject added in v0.0.404

func (s *SQLiteStore) BootstrapProject(ctx context.Context, p *Project, matchingSessions []ProjectSessionMatch) error

BootstrapProject inserts the first project and claims only the caller's prevalidated, unambiguous legacy sessions in one transaction.

func (*SQLiteStore) CheckpointResponseRun added in v0.9.12

func (s *SQLiteStore) CheckpointResponseRun(ctx context.Context, checkpoint ResponseRunCheckpoint) error

func (*SQLiteStore) ClaimProjectSessions added in v0.0.407

func (s *SQLiteStore) ClaimProjectSessions(ctx context.Context, projectID string, matchingSessions []ProjectSessionMatch) (int, error)

func (*SQLiteStore) ClearCompactionBoundary added in v0.0.234

func (s *SQLiteStore) ClearCompactionBoundary(ctx context.Context, id string) error

func (*SQLiteStore) ClearCurrent

func (s *SQLiteStore) ClearCurrent(ctx context.Context) error

ClearCurrent removes the current session marker.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the database connections.

func (*SQLiteStore) CommitRushInitialInput added in v0.9.31

func (s *SQLiteStore) CommitRushInitialInput(ctx context.Context, op *RushOperation, messages []*Message) (int64, error)

CommitRushInitialInput shares the ordinary append transaction, but adds a fenced operation CAS before any insert and commits dispositions before COMMIT.

func (*SQLiteStore) CompactMessages added in v0.0.115

func (s *SQLiteStore) CompactMessages(ctx context.Context, sessionID string, messages []Message) error

CompactMessages appends compacted messages to the session, preserving old history, and updates compaction_seq so that resume loads only post-compaction messages. Old messages remain in the database for scrollback/history.

func (*SQLiteStore) Create

func (s *SQLiteStore) Create(ctx context.Context, sess *Session) error

Create inserts a new session.

func (*SQLiteStore) CreateBranch added in v0.0.377

func (s *SQLiteStore) CreateBranch(ctx context.Context, sourceSessionID string, opts CreateBranchOptions) (BranchResult, error)

CreateBranch materializes a normal linear child session containing the source transcript prefix through opts.AnchorMessageID. The dedicated edge table is metadata only; provider state, redo state, plans, goals, and usage are not copied.

func (*SQLiteStore) CreateProject added in v0.0.404

func (s *SQLiteStore) CreateProject(ctx context.Context, p *Project) error

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, id string) error

Delete removes a session and its messages.

func (*SQLiteStore) DeletePendingSteering added in v0.9.31

func (s *SQLiteStore) DeletePendingSteering(ctx context.Context, sessionID, id string) error

func (*SQLiteStore) DeletePlanSnapshot added in v0.0.339

func (s *SQLiteStore) DeletePlanSnapshot(ctx context.Context, sessionID string) error

DeletePlanSnapshot clears the current snapshot row for a session.

func (*SQLiteStore) DeleteProviderState added in v0.0.289

func (s *SQLiteStore) DeleteProviderState(ctx context.Context, sessionID, providerKey string) error

DeleteProviderState removes provider-owned resume state for a session.

func (*SQLiteStore) DeletePushSubscription added in v0.0.114

func (s *SQLiteStore) DeletePushSubscription(ctx context.Context, endpoint string) error

DeletePushSubscription removes a Web Push subscription by endpoint.

func (*SQLiteStore) DeletePushSubscriptionByID added in v0.9.0

func (s *SQLiteStore) DeletePushSubscriptionByID(ctx context.Context, id string) error

func (*SQLiteStore) DeleteWorkspaceGrant added in v0.0.379

func (s *SQLiteStore) DeleteWorkspaceGrant(ctx context.Context, sessionID, grantID string) error

DeleteWorkspaceGrant removes a persisted workspace capability record. Runtime policy prevents the model-facing manage_workspace tool from deleting the reserved primary row; direct session rebinding may replace or remove it.

func (*SQLiteStore) EnqueueCompletionPush added in v0.9.0

func (s *SQLiteStore) EnqueueCompletionPush(ctx context.Context, item CompletionPushOutboxItem) (bool, error)

func (*SQLiteStore) FinalizeResponseRun added in v0.9.12

func (s *SQLiteStore) FinalizeResponseRun(ctx context.Context, terminal ResponseRunTerminal) (AttentionState, error)

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, id string) (*Session, error)

Get retrieves a session by ID.

func (*SQLiteStore) GetAttention added in v0.9.12

func (s *SQLiteStore) GetAttention(ctx context.Context, sessionID string) (AttentionState, error)

func (*SQLiteStore) GetAttentionBatch added in v0.9.12

func (s *SQLiteStore) GetAttentionBatch(ctx context.Context, sessionIDs []string) (map[string]AttentionState, error)

func (*SQLiteStore) GetBranchByIdempotencyKey added in v0.0.377

func (s *SQLiteStore) GetBranchByIdempotencyKey(ctx context.Context, sourceSessionID, idempotencyKey string) (BranchResult, bool, error)

GetBranchByIdempotencyKey returns an already-materialized child without repeating any helper work associated with the original branch request.

func (*SQLiteStore) GetBranchTree added in v0.0.377

func (s *SQLiteStore) GetBranchTree(ctx context.Context, sessionID string) (BranchTree, error)

GetBranchTree returns all surviving sessions connected to sessionID. Parent IDs intentionally are not foreign keys, so a deleted parent simply makes its surviving child the root of a smaller tree.

func (*SQLiteStore) GetByNumber added in v0.0.56

func (s *SQLiteStore) GetByNumber(ctx context.Context, number int64) (*Session, error)

GetByNumber retrieves a session by its sequential number.

func (*SQLiteStore) GetByPrefix added in v0.0.52

func (s *SQLiteStore) GetByPrefix(ctx context.Context, prefix string) (*Session, error)

GetByPrefix retrieves a session by number (with # prefix), exact ID, or by short ID prefix match. It tries in order: #number (e.g., #42), exact ID match, short ID prefix match.

func (*SQLiteStore) GetCurrent

func (s *SQLiteStore) GetCurrent(ctx context.Context) (*Session, error)

GetCurrent retrieves the current session.

func (*SQLiteStore) GetDiffCommentMessages added in v0.0.400

func (s *SQLiteStore) GetDiffCommentMessages(ctx context.Context, sessionID string) ([]Message, error)

GetDiffCommentMessages retrieves only messages whose serialized parts can contain typed inline-diff comment metadata. The final typed-part check remains with the caller; LIKE is used only as a conservative SQLite row prefilter.

func (*SQLiteStore) GetLatestVisibleMessageID added in v0.0.250

func (s *SQLiteStore) GetLatestVisibleMessageID(ctx context.Context, sessionID string) (int64, error)

GetLatestVisibleMessageID retrieves the latest persisted user/assistant message id for a session.

func (*SQLiteStore) GetMessageByClientMessageID added in v0.0.363

func (s *SQLiteStore) GetMessageByClientMessageID(ctx context.Context, sessionID, clientMessageID string) (*Message, error)

GetMessageByClientMessageID retrieves a first-party user message by its session-scoped stable identity.

func (*SQLiteStore) GetMessageByID added in v0.0.224

func (s *SQLiteStore) GetMessageByID(ctx context.Context, msgID int64) (*Message, error)

GetMessageByID retrieves a single message by its global message id.

func (*SQLiteStore) GetMessages

func (s *SQLiteStore) GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)

GetMessages retrieves messages for a session.

func (*SQLiteStore) GetMessagesByClientMessageIDs added in v0.0.363

func (s *SQLiteStore) GetMessagesByClientMessageIDs(ctx context.Context, sessionID string, clientMessageIDs []string) (map[string]*Message, error)

GetMessagesByClientMessageIDs resolves a batch through the indexed lookup.

func (*SQLiteStore) GetMessagesByTranscriptRanges added in v0.0.344

func (s *SQLiteStore) GetMessagesByTranscriptRanges(ctx context.Context, sessionID string, ranges []TranscriptRange) (int64, []Message, error)

GetMessagesByTranscriptRanges returns complete durable transcript segments in authoritative order and the revision describing them from one SQLite read transaction. Each segment uses four bind variables regardless of how many durable rows it expands to, so a giant tool turn never approaches SQLite's variable limit.

func (*SQLiteStore) GetMessagesFrom added in v0.0.115

func (s *SQLiteStore) GetMessagesFrom(ctx context.Context, sessionID string, fromSeq, limit int) ([]Message, error)

GetMessagesFrom retrieves messages for a session starting from a given sequence number. Used on resume and for keyset-style pagination when walking long transcripts. When limit <= 0, all rows at/after fromSeq are returned.

func (*SQLiteStore) GetMessagesPageDescending added in v0.0.261

func (s *SQLiteStore) GetMessagesPageDescending(ctx context.Context, sessionID string, beforeSeq, limit int) ([]Message, error)

GetMessagesPageDescending retrieves messages for a session in reverse sequence order. When beforeSeq > 0, only rows with sequence < beforeSeq are returned. Used for reverse tail pagination without loading entire sessions.

func (*SQLiteStore) GetProject added in v0.0.404

func (s *SQLiteStore) GetProject(ctx context.Context, id string) (*Project, error)

func (*SQLiteStore) GetProjectByCanonicalDir added in v0.0.404

func (s *SQLiteStore) GetProjectByCanonicalDir(ctx context.Context, canonicalDir string) (*Project, error)

func (*SQLiteStore) GetPushSubscription added in v0.9.0

func (s *SQLiteStore) GetPushSubscription(ctx context.Context, id string) (*PushSubscription, error)

func (*SQLiteStore) GetResponseRunStartState added in v0.0.406

func (s *SQLiteStore) GetResponseRunStartState(ctx context.Context, sessionID string) (ResponseRunStartState, error)

GetResponseRunStartState returns the response-run transcript envelope in one indexed scalar query. File-backed WAL stores use a dedicated scalar reader so startup is queued behind neither long transcript materialization nor the single writer connection. In-memory, read-only, and rollback-journal stores retain their existing serialized connection behavior.

func (*SQLiteStore) GetRush added in v0.9.31

func (s *SQLiteStore) GetRush(ctx context.Context, sessionID, requestID string) (*RushOperation, error)

func (*SQLiteStore) GetTranscriptIndex added in v0.0.344

func (s *SQLiteStore) GetTranscriptIndex(ctx context.Context, sessionID string) (int64, []TranscriptIndexItem, error)

GetTranscriptIndex returns every durable non-internal row and the revision describing it from one SQLite read transaction.

func (*SQLiteStore) GetTranscriptSnapshot added in v0.0.344

func (s *SQLiteStore) GetTranscriptSnapshot(ctx context.Context, sessionID string) (TranscriptSnapshot, error)

GetTranscriptSnapshot returns the complete transcript envelope from one SQLite read transaction.

func (*SQLiteStore) HasActiveProjects added in v0.0.407

func (s *SQLiteStore) HasActiveProjects(ctx context.Context) (bool, error)

func (*SQLiteStore) IncrementUserTurns added in v0.0.41

func (s *SQLiteStore) IncrementUserTurns(ctx context.Context, id string) error

IncrementUserTurns increments the user turn count and updates last_user_message_at.

func (*SQLiteStore) LatestRush added in v0.9.31

func (s *SQLiteStore) LatestRush(ctx context.Context, sessionID string) (*RushOperation, error)

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)

func (*SQLiteStore) ListAttention added in v0.9.12

func (s *SQLiteStore) ListAttention(ctx context.Context, opts AttentionListOptions) (AttentionPage, error)

func (*SQLiteStore) ListDueCompletionPushes added in v0.9.0

func (s *SQLiteStore) ListDueCompletionPushes(ctx context.Context, now time.Time, limit int) ([]CompletionPushOutboxItem, error)

func (*SQLiteStore) ListPendingSteering added in v0.9.31

func (s *SQLiteStore) ListPendingSteering(ctx context.Context, sessionID string) ([]PendingSteering, error)

func (*SQLiteStore) ListProjects added in v0.0.404

func (s *SQLiteStore) ListProjects(ctx context.Context, opts ProjectListOptions) ([]Project, error)

func (*SQLiteStore) ListPushSubscriptions added in v0.0.114

func (s *SQLiteStore) ListPushSubscriptions(ctx context.Context) ([]PushSubscription, error)

ListPushSubscriptions returns all stored Web Push subscriptions.

func (*SQLiteStore) ListStoreChanges added in v0.9.5

func (s *SQLiteStore) ListStoreChanges(ctx context.Context, after int64, limit int) ([]StoreChange, error)

ListStoreChanges reads the indexed tail of the durable change log. The sequence primary key makes an idle poll and a small incremental batch cheap regardless of the total number of sessions in the database.

func (*SQLiteStore) ListWorkspaceGrants added in v0.0.379

func (s *SQLiteStore) ListWorkspaceGrants(ctx context.Context, sessionID string) ([]WorkspaceGrant, error)

ListWorkspaceGrants returns workspace capability records (including the reserved primary decision row when present) for sessionID in deterministic creation order.

func (*SQLiteStore) LoadPlanSnapshot added in v0.0.339

func (s *SQLiteStore) LoadPlanSnapshot(ctx context.Context, sessionID string) (planpkg.Snapshot, int64, error)

LoadPlanSnapshot loads the authoritative latest update_plan snapshot.

func (*SQLiteStore) LoadProviderState added in v0.0.289

func (s *SQLiteStore) LoadProviderState(ctx context.Context, sessionID, providerKey string) ([]byte, error)

LoadProviderState returns opaque provider-owned resume state for a session.

func (*SQLiteStore) MarkAttentionSeen added in v0.9.12

func (s *SQLiteStore) MarkAttentionSeen(ctx context.Context, sessionID, storeInstanceID string, throughSeq int64) (AttentionState, error)

func (*SQLiteStore) MarkCompletionPushDead added in v0.9.0

func (s *SQLiteStore) MarkCompletionPushDead(ctx context.Context, id int64, lastError string) error

func (*SQLiteStore) MarkCompletionPushDelivered added in v0.9.0

func (s *SQLiteStore) MarkCompletionPushDelivered(ctx context.Context, id int64) error

func (*SQLiteStore) MarkPushSubscriptionStale added in v0.9.0

func (s *SQLiteStore) MarkPushSubscriptionStale(ctx context.Context, id, code, detail string) error

func (*SQLiteStore) MarkPushSubscriptionUsed added in v0.9.0

func (s *SQLiteStore) MarkPushSubscriptionUsed(ctx context.Context, id string) error

func (*SQLiteStore) MarkTitleSkipped added in v0.0.131

func (s *SQLiteStore) MarkTitleSkipped(ctx context.Context, id string, t time.Time) error

MarkTitleSkipped sets title_skipped_at on a session without bumping updated_at. This lets the autotitle job skip trivial sessions until real new messages arrive.

func (*SQLiteStore) MaxMessageSequences added in v0.0.344

func (s *SQLiteStore) MaxMessageSequences(ctx context.Context, sessionIDs []string) (map[string]int, error)

MaxMessageSequences returns the greatest persisted message sequence for each requested session. Sessions without messages are returned with sequence -1.

func (*SQLiteStore) NextUserPrompt added in v0.0.281

func (s *SQLiteStore) NextUserPrompt(ctx context.Context, agent string, afterID int64) (*PromptHistoryEntry, error)

NextUserPrompt returns the oldest persisted user prompt newer than afterID.

func (*SQLiteStore) NextUserPromptOutsideSession added in v0.0.281

func (s *SQLiteStore) NextUserPromptOutsideSession(ctx context.Context, excludeSessionID string, afterID int64, afterCreatedAt time.Time) (*PromptHistoryEntry, error)

NextUserPromptOutsideSession returns the oldest persisted user prompt newer than the cursor, ordered by message timestamp across all agents, excluding the current session and machine-generated subagent sessions.

func (*SQLiteStore) PersistCompactionTailHints added in v0.0.278

func (s *SQLiteStore) PersistCompactionTailHints(ctx context.Context, sessionID string, messageIDs []int64) error

func (*SQLiteStore) PreviousUserPrompt added in v0.0.281

func (s *SQLiteStore) PreviousUserPrompt(ctx context.Context, agent string, beforeID int64) (*PromptHistoryEntry, error)

PreviousUserPrompt returns the newest persisted user prompt older than beforeID. When beforeID <= 0, traversal starts at the newest prompt. History is global across sessions and optionally filtered by agent.

func (*SQLiteStore) PreviousUserPromptOutsideSession added in v0.0.281

func (s *SQLiteStore) PreviousUserPromptOutsideSession(ctx context.Context, excludeSessionID string, beforeID int64, beforeCreatedAt time.Time) (*PromptHistoryEntry, error)

PreviousUserPromptOutsideSession returns the newest persisted user prompt older than the cursor, ordered by message timestamp across all agents, excluding the current session and machine-generated subagent sessions.

func (*SQLiteStore) PruneCompletionPushOutbox added in v0.9.0

func (s *SQLiteStore) PruneCompletionPushOutbox(ctx context.Context, before time.Time) error

func (*SQLiteStore) ReadOnly added in v0.0.404

func (s *SQLiteStore) ReadOnly() bool

func (*SQLiteStore) RecoverExpiredResponseRuns added in v0.9.12

func (s *SQLiteStore) RecoverExpiredResponseRuns(ctx context.Context, limit int) ([]AttentionState, error)

func (*SQLiteStore) RedoLastUserTurn added in v0.0.373

func (s *SQLiteStore) RedoLastUserTurn(ctx context.Context, sessionID string, expected TranscriptMutationState) (TranscriptMutationResult, error)

RedoLastUserTurn restores the exact durable suffix captured by the latest undo, including stable message IDs, sequences, timestamps, and structured parts. It does not replay tool or external side effects.

func (*SQLiteStore) ReleaseRush added in v0.9.31

func (s *SQLiteStore) ReleaseRush(ctx context.Context, op *RushOperation) error

ReleaseRush returns a settled, unconsumed terminal operation to recoverable pending input. Payload stays in the ledger and only this owner's rows move.

func (*SQLiteStore) RenewResponseRunLease added in v0.9.12

func (s *SQLiteStore) RenewResponseRunLease(ctx context.Context, responseID, ownerInstanceID string, fencingToken int64) (ResponseRunLease, error)

func (*SQLiteStore) ReplaceCompactedMessages added in v0.0.313

func (s *SQLiteStore) ReplaceCompactedMessages(ctx context.Context, sessionID string, messages []Message) error

ReplaceCompactedMessages reconciles the active post-compaction history for a session while preserving pre-compaction scrollback and the compaction boundary. It must only be used with snapshots that start at the current compaction_seq.

func (*SQLiteStore) ReplaceCompactedMessagesWithTranscriptRev added in v0.0.353

func (s *SQLiteStore) ReplaceCompactedMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []Message) (int64, error)

func (*SQLiteStore) ReplaceMessages added in v0.0.80

func (s *SQLiteStore) ReplaceMessages(ctx context.Context, sessionID string, messages []Message) error

ReplaceMessages reconciles the complete persisted history for a session. It preserves any unchanged prefix and rewrites only the changed suffix, avoiding a DELETE+INSERT of long histories when serve/web persists an appended snapshot. Because the replacement snapshot becomes the complete persisted history, any previous compaction boundary is cleared.

func (*SQLiteStore) ReplaceMessagesWithTranscriptRev added in v0.0.353

func (s *SQLiteStore) ReplaceMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []Message) (int64, error)

func (*SQLiteStore) RetryCompletionPush added in v0.9.0

func (s *SQLiteStore) RetryCompletionPush(ctx context.Context, id int64, next time.Time, lastError string) error

func (*SQLiteStore) SavePendingSteering added in v0.9.31

func (s *SQLiteStore) SavePendingSteering(ctx context.Context, entry PendingSteering) error

func (*SQLiteStore) SavePlanSnapshot added in v0.0.339

func (s *SQLiteStore) SavePlanSnapshot(ctx context.Context, sessionID string, snapshot planpkg.Snapshot) (int64, error)

SavePlanSnapshot atomically replaces the current snapshot and increments the existing row's version. Saving after a clear creates a new row at version 1.

func (*SQLiteStore) SaveProviderState added in v0.0.289

func (s *SQLiteStore) SaveProviderState(ctx context.Context, sessionID, providerKey string, state []byte) error

SaveProviderState stores opaque provider-owned resume state for a session.

func (*SQLiteStore) SavePushSubscription added in v0.0.114

func (s *SQLiteStore) SavePushSubscription(ctx context.Context, sub *PushSubscription) error

SavePushSubscription upserts a Web Push subscription.

func (*SQLiteStore) SaveWorkspaceGrant added in v0.0.379

func (s *SQLiteStore) SaveWorkspaceGrant(ctx context.Context, sessionID string, grant WorkspaceGrant) error

SaveWorkspaceGrant inserts or updates a session-scoped workspace capability.

func (*SQLiteStore) Search

func (s *SQLiteStore) Search(ctx context.Context, opts SearchOptions) ([]SearchResult, error)

Search finds sessions containing the query text using FTS5.

func (*SQLiteStore) SessionSummariesIncludeTranscriptRev added in v0.0.344

func (s *SQLiteStore) SessionSummariesIncludeTranscriptRev() bool

SessionSummariesIncludeTranscriptRev reports whether List can read revisions from the sessions row without compatibility fallbacks.

func (*SQLiteStore) SetCurrent

func (s *SQLiteStore) SetCurrent(ctx context.Context, sessionID string) error

SetCurrent marks a session as the current one.

func (*SQLiteStore) SetResponseRunInteractionState added in v0.9.14

func (s *SQLiteStore) SetResponseRunInteractionState(ctx context.Context, value ResponseRunInteractionState) error

func (*SQLiteStore) Sidebar added in v0.0.404

func (s *SQLiteStore) Sidebar(ctx context.Context, opts SidebarOptions) ([]SidebarGroup, error)

Sidebar uses one bounded window query for all groups after one project query; it never performs a session query per project.

func (*SQLiteStore) StoreChangeCursor added in v0.9.5

func (s *SQLiteStore) StoreChangeCursor(ctx context.Context) (int64, error)

StoreChangeCursor returns the newest durable change sequence. Watchers take this once at startup, then request only rows appended by later commits.

func (*SQLiteStore) StoreInstanceID added in v0.9.12

func (s *SQLiteStore) StoreInstanceID(ctx context.Context) (string, error)

func (*SQLiteStore) SupportsBatchTranscriptWriter added in v0.9.25

func (s *SQLiteStore) SupportsBatchTranscriptWriter() bool

SupportsBatchTranscriptWriter reports whether this store can commit the ordered writable transaction required by collaborative terminal activity.

func (*SQLiteStore) SwitchSessionWorkspace added in v0.9.1

func (s *SQLiteStore) SwitchSessionWorkspace(ctx context.Context, sessionID string, binding SessionWorkspaceBinding) (*Session, error)

func (*SQLiteStore) TranscriptMutationState added in v0.0.373

func (s *SQLiteStore) TranscriptMutationState(ctx context.Context, sessionID string) (TranscriptMutationState, error)

TranscriptMutationState returns the durable revision and visible transcript head used for optimistic undo/redo requests.

func (*SQLiteStore) TranscriptRev added in v0.0.344

func (s *SQLiteStore) TranscriptRev(ctx context.Context, sessionID string) (int64, error)

TranscriptRev returns the current durable transcript revision. Old read-only databases without the revision column are explicitly unversioned (revision 0).

func (*SQLiteStore) TranscriptVersioned added in v0.0.344

func (s *SQLiteStore) TranscriptVersioned() bool

TranscriptVersioned reports whether this database has durable transcript revisions. It is false only for old schemas opened read-only without migration.

func (*SQLiteStore) UndoLastUserTurn added in v0.0.373

func (s *SQLiteStore) UndoLastUserTurn(ctx context.Context, sessionID string, expected TranscriptMutationState) (TranscriptMutationResult, error)

UndoLastUserTurn removes the latest real user row at or after the compaction boundary and every transcript row after it. The suffix is durably owned by SQLite so another client or a restarted process can redo it.

func (*SQLiteStore) Update

func (s *SQLiteStore) Update(ctx context.Context, sess *Session) error

Update modifies an existing session's metadata fields. Token metrics (input_tokens, cached_input_tokens, cache_write_tokens, output_tokens) and turn counters (user_turns, llm_turns, tool_calls) are intentionally excluded — they are managed exclusively by atomic update paths to prevent stale in-memory values from clobbering accumulated totals.

func (*SQLiteStore) UpdateContextEstimate added in v0.0.161

func (s *SQLiteStore) UpdateContextEstimate(ctx context.Context, id string, lastTotalTokens, lastMessageCount int) error

UpdateContextEstimate persists the last observed provider context estimate so resumed sessions can display a realistic context meter before the next turn.

func (*SQLiteStore) UpdateGeneratedTitle added in v0.0.320

func (s *SQLiteStore) UpdateGeneratedTitle(ctx context.Context, id, shortTitle, longTitle string, generatedAt time.Time, basisMsgSeq int) error

UpdateGeneratedTitle updates only generated title columns for a session.

func (*SQLiteStore) UpdateGoal added in v0.0.321

func (s *SQLiteStore) UpdateGoal(ctx context.Context, id string, goal *Goal) error

UpdateGoal updates only the persisted goal state for a session.

func (*SQLiteStore) UpdateMessage added in v0.0.174

func (s *SQLiteStore) UpdateMessage(ctx context.Context, sessionID string, msg *Message) error

UpdateMessage replaces the content of an existing message (keyed by msg.ID within sessionID). Returns ErrNotFound if no row matches. Used by the "persist as we go" upsert path: the caller first calls AddMessage to stamp an ID, then subsequent snapshots call UpdateMessage with the same ID.

func (*SQLiteStore) UpdateMetrics added in v0.0.41

func (s *SQLiteStore) UpdateMetrics(ctx context.Context, id string, llmTurns, toolCalls, inputTokens, outputTokens, cachedInputTokens, cacheWriteTokens int) error

UpdateMetrics atomically increments the metrics fields for a session. All token counters use += to avoid clobbering concurrent accumulation.

func (*SQLiteStore) UpdateProject added in v0.0.404

func (s *SQLiteStore) UpdateProject(ctx context.Context, id string, update ProjectUpdate) (*Project, error)

func (*SQLiteStore) UpdateShare added in v0.0.324

func (s *SQLiteStore) UpdateShare(ctx context.Context, id string, share *ShareState) error

UpdateShare updates only persisted share metadata for a session.

func (*SQLiteStore) UpdateStatus added in v0.0.41

func (s *SQLiteStore) UpdateStatus(ctx context.Context, id string, status SessionStatus) error

UpdateStatus updates just the session status.

func (*SQLiteStore) UpdateStreamingMessage added in v0.0.289

func (s *SQLiteStore) UpdateStreamingMessage(ctx context.Context, sessionID string, msg *Message, finalizeText bool) error

UpdateStreamingMessage updates an in-progress assistant message while letting the caller defer the FTS-backed text_content rewrite until finalization.

func (*SQLiteStore) UpdateStreamingMessageWithTranscriptRev added in v0.0.353

func (s *SQLiteStore) UpdateStreamingMessageWithTranscriptRev(ctx context.Context, sessionID string, msg *Message, finalizeText bool) (int64, error)

func (*SQLiteStore) UpsertPushSubscription added in v0.9.0

func (s *SQLiteStore) UpsertPushSubscription(ctx context.Context, sub *PushSubscription) (*PushSubscription, error)

func (*SQLiteStore) ValidateResponseRunLease added in v0.9.12

func (s *SQLiteStore) ValidateResponseRunLease(ctx context.Context, responseID, ownerInstanceID string, fencingToken int64) error

type SearchOptions added in v0.0.281

type SearchOptions struct {
	Query            string   // Text query to search for
	Categories       []string // Sidebar/web categories (all, chat, web, ask, plan, exec)
	Limit            int      // Max results (0 = use default)
	Archived         bool     // Include archived sessions
	ProjectID        string   // Restrict to one stable project ID
	ExcludeSubagents bool     // Hide machine-generated child-agent sessions
}

SearchOptions configures session full-text search.

type SearchResult

type SearchResult struct {
	SessionID           string             `json:"session_id"`
	SessionNumber       int64              `json:"session_number"` // Sequential session number
	MessageID           int64              `json:"message_id"`
	SessionName         string             `json:"session_name"`
	Summary             string             `json:"summary"`
	GeneratedShortTitle string             `json:"generated_short_title,omitempty"`
	GeneratedLongTitle  string             `json:"generated_long_title,omitempty"`
	TitleSource         SessionTitleSource `json:"title_source,omitempty"`
	Snippet             string             `json:"snippet"` // Matched text snippet
	Provider            string             `json:"provider"`
	ProviderKey         string             `json:"provider_key,omitempty"`
	Model               string             `json:"model"`
	Mode                SessionMode        `json:"mode,omitempty"`
	Origin              SessionOrigin      `json:"origin,omitempty"`
	Archived            bool               `json:"archived,omitempty"`
	Pinned              bool               `json:"pinned,omitempty"`
	Status              SessionStatus      `json:"status,omitempty"`
	ProjectID           string             `json:"project_id,omitempty"`
	ProjectName         string             `json:"project_name,omitempty"`
	MessageCount        int                `json:"message_count"`
	SessionCreatedAt    time.Time          `json:"session_created_at"`
	UpdatedAt           time.Time          `json:"updated_at"`
	LastMessageAt       time.Time          `json:"last_message_at,omitempty"`
	CreatedAt           time.Time          `json:"created_at"`
}

SearchResult represents a search match.

type ServeResponseLifecycleStore added in v0.9.12

type ServeResponseLifecycleStore interface {
	AdmitResponseRun(context.Context, ResponseRunAdmission) (ResponseRunLease, error)
	RenewResponseRunLease(context.Context, string, string, int64) (ResponseRunLease, error)
	ValidateResponseRunLease(context.Context, string, string, int64) error
	CheckpointResponseRun(context.Context, ResponseRunCheckpoint) error
	FinalizeResponseRun(context.Context, ResponseRunTerminal) (AttentionState, error)
	RecoverExpiredResponseRuns(context.Context, int) ([]AttentionState, error)
}

ServeResponseLifecycleStore is optional so custom/read-only stores remain usable.

func AsServeResponseLifecycleStore added in v0.9.12

func AsServeResponseLifecycleStore(store Store) (ServeResponseLifecycleStore, bool)

type Session

type Session struct {
	ID      string `json:"id"`
	Number  int64  `json:"number,omitempty"` // Sequential session number (1, 2, 3...)
	Name    string `json:"name,omitempty"`
	Summary string `json:"summary,omitempty"` // First user message or auto-generated

	GeneratedShortTitle string             `json:"generated_short_title,omitempty"`
	GeneratedLongTitle  string             `json:"generated_long_title,omitempty"`
	TitleSource         SessionTitleSource `json:"title_source,omitempty"`
	TitleGeneratedAt    time.Time          `json:"title_generated_at,omitempty"`
	TitleBasisMsgSeq    int                `json:"title_basis_msg_seq,omitempty"`
	TitleSkippedAt      time.Time          `json:"title_skipped_at,omitempty"` // Set when autotitle considers session untitlable; cleared when session is updated

	Provider        string              `json:"provider"`               // Provider display label
	ProviderKey     string              `json:"provider_key,omitempty"` // Canonical provider key (e.g. openai, chatgpt, custom alias)
	Model           string              `json:"model"`
	ReasoningEffort string              `json:"reasoning_effort,omitempty"` // Reasoning effort pinned at session creation (web only)
	ReasoningMode   string              `json:"reasoning_mode,omitempty"`   // Explicit Responses reasoning mode override (standard/pro).
	Mode            SessionMode         `json:"mode,omitempty"`             // Session mode (chat, ask, plan, exec)
	ApprovalMode    SessionApprovalMode `json:"approval_mode,omitempty"`    // Tool approval mode for chat sessions (prompt, auto, yolo)
	Origin          SessionOrigin       `json:"origin,omitempty"`           // Session surface/origin (tui, web, telegram)
	Agent           string              `json:"agent,omitempty"`            // Agent name used for this session
	ProjectID       string              `json:"project_id,omitempty"`       // Durable grouping/provenance identity
	ProjectName     string              `json:"project_name,omitempty"`     // Joined display metadata; not an identifier
	CWD             string              `json:"cwd,omitempty"`              // Working directory at session start
	WorktreeDir     string              `json:"worktree_dir,omitempty"`     // Bound git worktree directory, if any
	CreatedAt       time.Time           `json:"created_at"`
	UpdatedAt       time.Time           `json:"updated_at"`
	Archived        bool                `json:"archived,omitempty"`
	Pinned          bool                `json:"pinned,omitempty"`
	ParentID        string              `json:"parent_id,omitempty"`   // For session branching
	IsSubagent      bool                `json:"is_subagent,omitempty"` // True if this is a subagent session

	// Session settings (restored on resume unless overridden)
	Search bool   `json:"search,omitempty"` // Web search enabled
	Tools  string `json:"tools,omitempty"`  // Enabled tools (comma-separated)
	MCP    string `json:"mcp,omitempty"`    // Enabled MCP servers (comma-separated)

	// Session metrics
	UserTurns         int           `json:"user_turns,omitempty"`          // Number of user messages
	LLMTurns          int           `json:"llm_turns,omitempty"`           // Number of LLM API round-trips
	ToolCalls         int           `json:"tool_calls,omitempty"`          // Total tool executions
	InputTokens       int           `json:"input_tokens,omitempty"`        // Total non-cached, non-cache-write input tokens
	CachedInputTokens int           `json:"cached_input_tokens,omitempty"` // Total cached input tokens read (cache hits)
	CacheWriteTokens  int           `json:"cache_write_tokens,omitempty"`  // Total tokens written to cache (cache misses)
	OutputTokens      int           `json:"output_tokens,omitempty"`       // Total output tokens used
	LastTotalTokens   int           `json:"last_total_tokens,omitempty"`   // Last observed request context size (input+cached+output)
	LastMessageCount  int           `json:"last_message_count,omitempty"`  // Legacy checkpoint count; estimator uses structural delta
	MessageCount      int           `json:"message_count,omitempty"`       // User/assistant conversation messages visible as chat bubbles
	Status            SessionStatus `json:"status,omitempty"`              // Session status
	Tags              string        `json:"tags,omitempty"`                // Comma-separated tags
	Goal              *Goal         `json:"goal,omitempty"`                // Persistent objective state for /goal
	Share             *ShareState   `json:"share,omitempty"`               // Persisted external share metadata
	CompactionSeq     int           `json:"compaction_seq,omitempty"`      // Sequence of first post-compaction message (-1 = none)
	CompactionCount   int           `json:"compaction_count,omitempty"`    // Number of times this session has been compacted
}

Session represents a chat session stored in the database.

func (Session) PreferredLongTitle added in v0.0.120

func (s Session) PreferredLongTitle() string

PreferredLongTitle returns the best long descriptive title available for the session.

func (Session) PreferredShortTitle added in v0.0.120

func (s Session) PreferredShortTitle() string

PreferredShortTitle returns the best short title available for the session.

type SessionApprovalMode added in v0.0.317

type SessionApprovalMode string
const (
	ApprovalModePrompt SessionApprovalMode = "prompt"
	ApprovalModeAuto   SessionApprovalMode = "auto"
	ApprovalModeYolo   SessionApprovalMode = "yolo"
)

type SessionMode added in v0.0.55

type SessionMode string

SessionMode represents the type/context of a session.

const (
	ModeChat SessionMode = "chat" // Interactive chat TUI
	ModeAsk  SessionMode = "ask"  // One-shot ask command
	ModePlan SessionMode = "plan" // Collaborative planning TUI
	ModeExec SessionMode = "exec" // Command suggestion/execution
)

type SessionOrigin added in v0.0.130

type SessionOrigin string
const (
	OriginTUI      SessionOrigin = "tui"
	OriginWeb      SessionOrigin = "web"
	OriginTelegram SessionOrigin = "telegram"
)

type SessionStatus added in v0.0.41

type SessionStatus string

SessionStatus represents the current state of a session.

const (
	StatusActive      SessionStatus = "active"      // Session is open/current (may or may not be streaming)
	StatusComplete    SessionStatus = "complete"    // Session finished normally
	StatusError       SessionStatus = "error"       // Session ended with an error
	StatusInterrupted SessionStatus = "interrupted" // Session was cancelled by user
)

type SessionSummary

type SessionSummary struct {
	ID                       string             `json:"id"`
	Number                   int64              `json:"number,omitempty"` // Sequential session number
	Name                     string             `json:"name,omitempty"`
	Summary                  string             `json:"summary,omitempty"`
	GeneratedShortTitle      string             `json:"generated_short_title,omitempty"`
	GeneratedLongTitle       string             `json:"generated_long_title,omitempty"`
	TitleSource              SessionTitleSource `json:"title_source,omitempty"`
	Provider                 string             `json:"provider"`
	ProviderKey              string             `json:"provider_key,omitempty"`
	Model                    string             `json:"model"`
	Mode                     SessionMode        `json:"mode,omitempty"`
	Origin                   SessionOrigin      `json:"origin,omitempty"`
	Agent                    string             `json:"agent,omitempty"`
	Archived                 bool               `json:"archived,omitempty"`
	Pinned                   bool               `json:"pinned,omitempty"`
	MessageCount             int                `json:"message_count"`
	TranscriptRev            int64              `json:"transcript_rev"`
	UserTurns                int                `json:"user_turns,omitempty"`
	LLMTurns                 int                `json:"llm_turns,omitempty"`
	ToolCalls                int                `json:"tool_calls,omitempty"`
	InputTokens              int                `json:"input_tokens,omitempty"`
	CachedInputTokens        int                `json:"cached_input_tokens,omitempty"`
	CacheWriteTokens         int                `json:"cache_write_tokens,omitempty"`
	OutputTokens             int                `json:"output_tokens,omitempty"`
	Status                   SessionStatus      `json:"status,omitempty"`
	Tags                     string             `json:"tags,omitempty"`
	ProjectID                string             `json:"project_id,omitempty"`
	ProjectName              string             `json:"project_name,omitempty"`
	CWD                      string             `json:"cwd,omitempty"`
	WorktreeDir              string             `json:"worktree_dir,omitempty"`
	Goal                     *Goal              `json:"goal,omitempty"`
	Share                    *ShareState        `json:"share,omitempty"`
	CreatedAt                time.Time          `json:"created_at"`
	UpdatedAt                time.Time          `json:"updated_at"`
	LastMessageAt            time.Time          `json:"last_message_at,omitempty"`
	AttentionStoreInstanceID string             `json:"attention_store_instance_id,omitempty"`
	AttentionSeq             int64              `json:"attention_seq,omitempty"`
	AttentionResponseID      string             `json:"attention_response_id,omitempty"`
	AttentionFinalRev        int64              `json:"attention_final_rev,omitempty"`
	SeenThroughSeq           int64              `json:"seen_through_seq,omitempty"`
	AttentionUnseen          bool               `json:"attention_unseen,omitempty"`
	AttentionOutcome         ResponseRunState   `json:"attention_outcome,omitempty"`
	AttentionTerminalAt      int64              `json:"attention_terminal_at,omitempty"`
}

SessionSummary is a lightweight view of a session for listing.

func (SessionSummary) PreferredLongTitle added in v0.0.120

func (s SessionSummary) PreferredLongTitle() string

PreferredLongTitle returns the best long descriptive title available for the summary.

func (SessionSummary) PreferredShortTitle added in v0.0.120

func (s SessionSummary) PreferredShortTitle() string

PreferredShortTitle returns the best short title available for the summary.

type SessionSummaryTranscriptRevisionReporter added in v0.0.344

type SessionSummaryTranscriptRevisionReporter interface {
	SessionSummariesIncludeTranscriptRev() bool
}

SessionSummaryTranscriptRevisionReporter reports whether Store.List populates SessionSummary.TranscriptRev directly, allowing callers to avoid one revision query per listed session.

type SessionTitleSource added in v0.0.120

type SessionTitleSource string
const (
	TitleSourceNone      SessionTitleSource = ""
	TitleSourceUser      SessionTitleSource = "user"
	TitleSourceGenerated SessionTitleSource = "generated"
)

type SessionWorkspaceBinder added in v0.0.404

type SessionWorkspaceBinder interface {
	BindSessionWorkspace(ctx context.Context, sessionID string, binding SessionWorkspaceBinding) (*Session, error)
}

SessionWorkspaceBinder provides first-writer-wins immutable binding.

func AsSessionWorkspaceBinder added in v0.0.404

func AsSessionWorkspaceBinder(store Store) (SessionWorkspaceBinder, bool)

type SessionWorkspaceBinding added in v0.0.404

type SessionWorkspaceBinding struct {
	ProjectID   string
	CWD         string
	WorktreeDir string
}

SessionWorkspaceBinding is committed atomically after request validation.

type SessionWorkspaceSwitcher added in v0.9.1

type SessionWorkspaceSwitcher interface {
	SwitchSessionWorkspace(ctx context.Context, sessionID string, binding SessionWorkspaceBinding) (*Session, error)
}

SessionWorkspaceSwitcher performs an explicit user-requested workspace change after the caller validates the project root and managed worktree boundary.

func AsSessionWorkspaceSwitcher added in v0.9.1

func AsSessionWorkspaceSwitcher(store Store) (SessionWorkspaceSwitcher, bool)

type ShareScope added in v0.9.22

type ShareScope string

ShareScope identifies the transcript content included in a share.

const (
	ShareScopeSession      ShareScope = "session"
	ShareScopeResponse     ShareScope = "response"
	ShareScopeConversation ShareScope = "conversation"
)

type ShareState added in v0.0.324

type ShareState struct {
	Provider   string     `json:"provider,omitempty"`
	ID         string     `json:"id,omitempty"`
	URL        string     `json:"url,omitempty"`
	SourceURL  string     `json:"source_url,omitempty"`
	Visibility string     `json:"visibility,omitempty"`
	Scope      ShareScope `json:"scope,omitempty"`

	GistID     string `json:"gist_id,omitempty"`
	GistURL    string `json:"gist_url,omitempty"`
	PreviewURL string `json:"preview_url,omitempty"`
	Public     bool   `json:"public,omitempty"`

	SharedAt  time.Time `json:"shared_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

ShareState records the current external share for a session. The generic fields are authoritative; legacy Gist fields remain for one compatibility path and are normalized/dual-written without a database migration.

func (*ShareState) Clone added in v0.0.324

func (s *ShareState) Clone() *ShareState

Clone returns a normalized copy that callers may mutate safely.

func (*ShareState) Exists added in v0.0.324

func (s *ShareState) Exists() bool

Exists reports whether this state identifies a generic or legacy share.

func (*ShareState) Normalize added in v0.9.23

func (s *ShareState) Normalize()

Normalize upgrades legacy Gist state in memory and dual-writes compatibility fields for GitHub shares. It intentionally performs no database rewrite.

type ShareUpdater added in v0.0.324

type ShareUpdater interface {
	UpdateShare(ctx context.Context, id string, share *ShareState) error
}

ShareUpdater is an optional Store capability for updating only share metadata.

type SidebarGroup added in v0.0.404

type SidebarGroup struct {
	Project      *Project         `json:"project,omitempty"`
	SessionCount int              `json:"session_count"`
	LastActivity time.Time        `json:"last_activity_at,omitempty"`
	Sessions     []SessionSummary `json:"sessions"`
	NextCursor   string           `json:"next_cursor,omitempty"`
	NoProject    bool             `json:"no_project,omitempty"`
}

SidebarGroup is the bounded server-side projection used by the Web UI.

type SidebarOptions added in v0.0.404

type SidebarOptions struct {
	PerProject              int
	IncludeArchivedProjects bool
	IncludeArchivedSessions bool
}

type Store

type Store interface {
	// Session CRUD
	Create(ctx context.Context, s *Session) error
	Get(ctx context.Context, id string) (*Session, error)
	GetByNumber(ctx context.Context, number int64) (*Session, error)
	GetByPrefix(ctx context.Context, prefix string) (*Session, error)
	Update(ctx context.Context, s *Session) error
	MarkTitleSkipped(ctx context.Context, id string, t time.Time) error
	Delete(ctx context.Context, id string) error

	// Listing and search
	List(ctx context.Context, opts ListOptions) ([]SessionSummary, error)
	Search(ctx context.Context, opts SearchOptions) ([]SearchResult, error)

	// Message operations - stores full llm.Message with Parts
	AddMessage(ctx context.Context, sessionID string, msg *Message) error
	// UpdateMessage replaces the content of an existing message (by msg.ID) with
	// the supplied msg (role, parts, text, duration, sequence are updated in
	// place). Used for "persist as we go" upserts of an in-progress assistant
	// message during streaming. Returns ErrNotFound if the row does not exist.
	UpdateMessage(ctx context.Context, sessionID string, msg *Message) error
	GetMessages(ctx context.Context, sessionID string, limit, offset int) ([]Message, error)
	// GetMessagesFrom returns rows at/after fromSeq in sequence order. When limit
	// <= 0, all remaining rows are returned.
	GetMessagesFrom(ctx context.Context, sessionID string, fromSeq, limit int) ([]Message, error)
	// GetMessageByID retrieves a single message by its global message id.
	GetMessageByID(ctx context.Context, msgID int64) (*Message, error)
	ReplaceMessages(ctx context.Context, sessionID string, messages []Message) error
	CompactMessages(ctx context.Context, sessionID string, messages []Message) error

	// Metrics operations (for incremental session saving)
	UpdateMetrics(ctx context.Context, id string, llmTurns, toolCalls, inputTokens, outputTokens, cachedInputTokens, cacheWriteTokens int) error
	UpdateContextEstimate(ctx context.Context, id string, lastTotalTokens, lastMessageCount int) error
	UpdateStatus(ctx context.Context, id string, status SessionStatus) error
	IncrementUserTurns(ctx context.Context, id string) error

	// Current session tracking (for auto-resume)
	SetCurrent(ctx context.Context, sessionID string) error
	GetCurrent(ctx context.Context) (*Session, error)
	ClearCurrent(ctx context.Context) error

	// Push subscription management (for web push notifications)
	SavePushSubscription(ctx context.Context, sub *PushSubscription) error
	DeletePushSubscription(ctx context.Context, endpoint string) error
	ListPushSubscriptions(ctx context.Context) ([]PushSubscription, error)

	// Lifecycle
	Close() error
}

Store is the interface for session persistence.

func NewStore

func NewStore(cfg Config) (Store, error)

NewStore creates a new Store based on the configuration. If sessions are disabled, returns a no-op store.

type StoreChange added in v0.9.5

type StoreChange struct {
	Sequence      int64
	Kind          string
	SessionID     string
	ProjectID     string
	TranscriptRev int64
	Status        SessionStatus
}

StoreChange is one durable, monotonically ordered coarse mutation emitted by SQLite triggers. It lets other processes observe shared-store changes without rescanning the session catalog.

type StoreChangeCursorError added in v0.9.5

type StoreChangeCursorError struct {
	After  int64
	Oldest int64
	Latest int64
}

StoreChangeCursorError means the requested sequence has fallen behind the bounded durable tail and the consumer must perform authoritative recovery.

func (*StoreChangeCursorError) Error added in v0.9.5

func (e *StoreChangeCursorError) Error() string

type StoreChangeStore added in v0.9.5

type StoreChangeStore interface {
	StoreChangeCursor(ctx context.Context) (int64, error)
	ListStoreChanges(ctx context.Context, after int64, limit int) ([]StoreChange, error)
}

StoreChangeStore is an optional capability implemented by stores with a durable indexed mutation cursor. The serve event watcher uses it for cross-process/TUI observation; stores without it rely on explicit events.

func AsStoreChangeStore added in v0.9.5

func AsStoreChangeStore(store Store) (StoreChangeStore, bool)

AsStoreChangeStore resolves the optional capability through decorators without making unsupported stores appear observable.

type StreamingMessageUpdater added in v0.0.289

type StreamingMessageUpdater interface {
	UpdateStreamingMessage(ctx context.Context, sessionID string, msg *Message, finalizeText bool) error
}

StreamingMessageUpdater is an optional Store capability for the hot streaming assistant upsert path. Implementations may update role/parts/duration without rewriting the FTS-backed text_content column until finalizeText is true.

type TranscriptIndexItem added in v0.0.344

type TranscriptIndexItem struct {
	Seq                     int
	ID                      int64
	Role                    string
	Flags                   uint8
	ClientMessageID         string
	ResponseID              string
	AssistantSegmentOrdinal int
}

TranscriptIndexItem is the compact durable identity and ordering metadata for one UI-visible transcript row. IDs are stable identities; Seq is only the current ordering key.

type TranscriptIndexer added in v0.0.344

type TranscriptIndexer interface {
	GetTranscriptIndex(ctx context.Context, sessionID string) (rev int64, items []TranscriptIndexItem, err error)
	GetTranscriptSnapshot(ctx context.Context, sessionID string) (TranscriptSnapshot, error)
	GetMessagesByTranscriptRanges(ctx context.Context, sessionID string, ranges []TranscriptRange) (rev int64, messages []Message, err error)
	TranscriptRev(ctx context.Context, sessionID string) (int64, error)
}

TranscriptIndexer is an optional Store capability for coherent revisioned transcript reads. Implementations return each revision and its rows from one read transaction.

type TranscriptMutationResult added in v0.0.373

type TranscriptMutationResult struct {
	TranscriptMutationState
	UserText           string `json:"user_text,omitempty"`
	AttachmentsOmitted bool   `json:"attachments_omitted,omitempty"`
}

TranscriptMutationResult describes the transcript after undo or redo. UserText is populated for undo so clients can restore the removed prompt to their composer.

type TranscriptMutationState added in v0.0.373

type TranscriptMutationState struct {
	Rev    int64 `json:"rev"`
	HeadID int64 `json:"head_id"`
}

TranscriptMutationState is the optimistic concurrency token for undo/redo. HeadID is the final non-internal transcript row (the same row stream exposed by TranscriptIndexer); zero represents an empty transcript.

type TranscriptRange added in v0.0.344

type TranscriptRange struct {
	StartSeq int
	StartID  int64
	EndSeq   int
	EndID    int64
}

TranscriptRange identifies one complete, contiguous UI transcript segment by its inclusive durable ordering bounds. Sequence alone is not assumed unique, so IDs disambiguate both endpoints.

type TranscriptRevisionWriter added in v0.0.353

type TranscriptRevisionWriter interface {
	AddMessageWithTranscriptRev(ctx context.Context, sessionID string, msg *Message) (int64, error)
	UpdateStreamingMessageWithTranscriptRev(ctx context.Context, sessionID string, msg *Message, finalizeText bool) (int64, error)
	ReplaceMessagesWithTranscriptRev(ctx context.Context, sessionID string, messages []Message) (int64, error)
}

TranscriptRevisionWriter reports the exact revision committed by a message mutation. Serve response handoff uses this optional capability instead of a session-wide post-write revision sample.

type TranscriptSnapshot added in v0.0.344

type TranscriptSnapshot struct {
	Rev             int64
	CompactionSeq   int
	CompactionCount int
	Items           []TranscriptIndexItem
}

TranscriptSnapshot is the complete compact identity stream and its session envelope read from one database snapshot.

type TranscriptUndoRedoStore added in v0.0.373

type TranscriptUndoRedoStore interface {
	TranscriptMutationState(ctx context.Context, sessionID string) (TranscriptMutationState, error)
	UndoLastUserTurn(ctx context.Context, sessionID string, expected TranscriptMutationState) (TranscriptMutationResult, error)
	RedoLastUserTurn(ctx context.Context, sessionID string, expected TranscriptMutationState) (TranscriptMutationResult, error)
}

TranscriptUndoRedoStore owns a durable per-session redo stack. Ordinary transcript writes invalidate the entire stack in the same storage transaction.

type TranscriptVersionReporter added in v0.0.344

type TranscriptVersionReporter interface {
	TranscriptVersioned() bool
}

TranscriptVersionReporter distinguishes a current revisioned schema from an older read-only database where TranscriptIndexer exposes revision zero only.

type WarnFunc added in v0.0.41

type WarnFunc func(format string, args ...any)

WarnFunc is a function that logs warnings.

type WorkspaceAccess added in v0.0.379

type WorkspaceAccess string

WorkspaceAccess is the level of local filesystem authority granted to a session workspace. Write access always implies read access.

const (
	WorkspaceAccessRead  WorkspaceAccess = "read"
	WorkspaceAccessWrite WorkspaceAccess = "write"
)

type WorkspaceGrant added in v0.0.379

type WorkspaceGrant struct {
	ID         string
	Path       string
	Access     WorkspaceAccess
	Provenance string
	Rationale  string
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

WorkspaceGrant is a durable, session-scoped filesystem capability record. Migration 46 stores additional grants plus the reserved primary decision row; Session.CWD/WorktreeDir remains the separate primary proposal binding.

type WorkspaceGrantStore added in v0.0.379

type WorkspaceGrantStore interface {
	ListWorkspaceGrants(ctx context.Context, sessionID string) ([]WorkspaceGrant, error)
	SaveWorkspaceGrant(ctx context.Context, sessionID string, grant WorkspaceGrant) error
	DeleteWorkspaceGrant(ctx context.Context, sessionID, grantID string) error
}

WorkspaceGrantStore is an optional Store capability. Custom and mock stores that do not implement it remain usable; primary confirmations and dynamic grants then live only for the current runtime.

func AsWorkspaceGrantStore added in v0.0.379

func AsWorkspaceGrantStore(store Store) (WorkspaceGrantStore, bool)

AsWorkspaceGrantStore resolves the optional capability through term-llm's logging decorator without making an unsupported wrapped store appear durable.

Jump to

Keyboard shortcuts

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