session

package
v0.107.6-beta.6 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAnchor = errors.New("user message anchor not found")
View Source
var ErrClosed = errors.New("session store is closed")
View Source
var ErrHistoryDeleted = errors.New("history was explicitly deleted")
View Source
var ErrNotFound = errors.New("session not found")
View Source
var ErrRevision = errors.New("history revision conflict")

Functions

func FindTranscript added in v0.103.0

func FindTranscript(root, id string) (string, error)

Types

type Compaction

type Compaction struct {
	RunID     string   `json:"run_id,omitempty"`
	Seq       int      `json:"seq"`
	Cutoff    int      `json:"cutoff"`
	Summary   string   `json:"summary"`
	Model     string   `json:"model"`
	Usage     ai.Usage `json:"usage"`
	DropPrior bool     `json:"drop_prior,omitempty"`
	Fresh     bool     `json:"fresh,omitempty"`
}

type History added in v0.103.0

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

func (*History) Boundary added in v0.103.0

func (h *History) Boundary(cut int) (int, error)

func (*History) Clone added in v0.107.0

func (h *History) Clone() *History

func (*History) Compact added in v0.103.0

func (h *History) Compact(summary string, cutoff int, model string, usage ai.Usage) error

func (*History) NewContext added in v0.104.0

func (h *History) NewContext(cutoff int) error

func (*History) Observe added in v0.103.0

func (h *History) Observe(msgs []ai.Message) error

func (*History) Sequence added in v0.103.0

func (h *History) Sequence(index int) (int, bool)

type HistorySearchMatch added in v0.107.0

type HistorySearchMatch struct {
	SessionID     string    `json:"session_id"`
	Title         string    `json:"title"`
	CWD           string    `json:"cwd"`
	MessageID     string    `json:"message_id,omitempty"`
	MessageOffset *int      `json:"message_offset,omitempty"`
	Role          string    `json:"role,omitempty"`
	Snippet       string    `json:"snippet"`
	Score         float64   `json:"score"`
	UpdatedAt     time.Time `json:"updated_at"`
}

type HistorySearchResult added in v0.107.0

type HistorySearchResult struct {
	Matches   []HistorySearchMatch `json:"matches"`
	Truncated bool                 `json:"truncated"`
}

type HistorySnapshot added in v0.107.0

type HistorySnapshot struct {
	Meta           Meta
	CreatedAt      time.Time
	Messages       []ai.Message
	Offsets        []int
	ActiveMessages []ai.Message
	Revision       string
}

type Meta

type Meta struct {
	CreatedAt       time.Time `json:"-"`
	ID              string    `json:"id"`
	Title           string    `json:"title"`
	Model           string    `json:"model"`
	Provider        string    `json:"provider"`
	CWD             string    `json:"cwd"`
	Goal            string    `json:"goal"`
	ForkedFrom      string    `json:"forked_from"`
	ForkSeq         int       `json:"fork_seq"`
	Tags            []string  `json:"tags"`
	Pinned          bool      `json:"pinned"`
	Archived        bool      `json:"archived"`
	Shared          bool      `json:"shared"`
	ShareCreatedAt  time.Time `json:"share_created_at,omitempty"`
	ShareUpdatedAt  time.Time `json:"share_updated_at,omitempty"`
	ShareToken      string    `json:"share_token,omitempty"`
	ShareRedactTool bool      `json:"share_redact_tool,omitempty"`
	Effort          string    `json:"effort"`
	UsageIn         int       `json:"usage_in"`
	UsageCached     int       `json:"usage_cached"`
	UsageOut        int       `json:"usage_out"`
	UsageCacheWrite int       `json:"usage_cache_write,omitempty"`

	SubUsage   map[string]ai.Usage `json:"sub_usage"`
	ModelUsage map[string]ai.Usage `json:"model_usage,omitempty"`
	UpdatedAt  time.Time           `json:"updated_at"`

	TaskID                   string `json:"task_id"`
	ImportSourceID           string `json:"import_source_id,omitempty"`
	ImportFingerprint        string `json:"import_fingerprint,omitempty"`
	ImportMetadata           string `json:"import_metadata,omitempty"`
	ImportContentFingerprint string `json:"import_content_fingerprint,omitempty"`
}

func (Meta) UsageSummary added in v0.103.0

func (m Meta) UsageSummary(msgs []ai.Message) ai.UsageSummary

type Page added in v0.103.0

type Page struct {
	Sessions []Meta
	Next     *PageCursor
	Total    int
}

type PageCursor added in v0.103.0

type PageCursor struct {
	UpdatedAt time.Time `json:"updatedAt"`
	ID        string    `json:"id"`
}

func (PageCursor) Valid added in v0.103.0

func (c PageCursor) Valid() bool

type PageOptions added in v0.103.0

type PageOptions struct {
	CWD             *string
	After           *PageCursor
	Limit           int
	Offset          int
	IncludeEmpty    bool
	Shared          *bool
	SharedOnly      bool
	IncludeArchived bool
}

type Schedule

type Schedule struct {
	ID       int       `json:"id"`
	Schedule string    `json:"schedule"`
	Prompt   string    `json:"prompt"`
	Anchor   time.Time `json:"anchor"`
	LastFire time.Time `json:"last_fire"`
}

type Store

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

func Open

func Open(dir string) (*Store, error)

func OpenHome added in v0.103.0

func OpenHome(home string) (*Store, error)

func OpenProjectDir added in v0.107.6

func OpenProjectDir(dir string) (*Store, error)

OpenProjectDir reads both flat legacy sessions and project-grouped sessions.

func OpenProjectHome added in v0.103.0

func OpenProjectHome(home string) (*Store, error)

func (*Store) AddSchedule

func (s *Store) AddSchedule(sessionID, schedule, prompt string, anchor time.Time) (id int, err error)

func (*Store) CheckpointReferences added in v0.107.0

func (s *Store) CheckpointReferences(id string) (map[int]string, error)

func (*Store) ClearMessages

func (s *Store) ClearMessages(id string) error

func (*Store) ClearSnapshots

func (s *Store) ClearSnapshots(id string) error

func (*Store) ClearSnapshotsFrom added in v0.107.0

func (s *Store) ClearSnapshotsFrom(id string, from int) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) Compactions

func (s *Store) Compactions(id string) []Compaction

func (*Store) Create

func (s *Store) Create(cwd, model, provider string) (id string, err error)

func (*Store) Delete added in v0.103.0

func (s *Store) Delete(id string) error

func (*Store) DeleteCompaction

func (s *Store) DeleteCompaction(id string, seq int) error

func (*Store) DeleteFrom

func (s *Store) DeleteFrom(id string, from int) error

func (*Store) DeleteSchedule

func (s *Store) DeleteSchedule(sessionID string, id int) error

func (*Store) Fork

func (s *Store) Fork(srcID string, uptoSeq int, title string) (id string, err error)

func (*Store) ForkTitle

func (s *Store) ForkTitle(base string) (title string, err error)

func (*Store) ForksOf

func (s *Store) ForksOf(id string) (out []Meta, err error)

func (*Store) History added in v0.103.0

func (s *Store) History(id string, initial []ai.Message) (*History, []ai.Message, error)

func (*Store) HistorySnapshot added in v0.107.0

func (s *Store) HistorySnapshot(id string) (out HistorySnapshot, err error)

func (*Store) ImportHistory added in v0.107.0

func (s *Store) ImportHistory(id, sourceID, fingerprint, contentFingerprint, metadata, cwd, model, provider, title string, createdAt, updatedAt time.Time, pinned, shared, redact bool, shareToken string, messages []ai.Message, boundary *Compaction) (bool, error)

func (*Store) LastExchange

func (s *Store) LastExchange(id string) (user, assistant string)

func (*Store) LatestInDir

func (s *Store) LatestInDir(dir string) (meta Meta, err error)

func (*Store) ListPage added in v0.103.0

func (s *Store) ListPage(ctx context.Context, options PageOptions) (Page, error)

func (*Store) Load

func (s *Store) Load(idOrPrefix string) (meta Meta, msgs []ai.Message, err error)

func (*Store) LoadTasks

func (s *Store) LoadTasks(id string) ([]Task, error)

func (*Store) MarkFired

func (s *Store) MarkFired(sessionID string, id int, at time.Time) error

func (*Store) MessageSequence added in v0.107.0

func (s *Store) MessageSequence(id, messageID string) (int, error)

func (*Store) MutateHistory added in v0.107.0

func (s *Store) MutateHistory(id, messageID, expectedRevision, title string, replacement *ai.Message) (resultID string, err error)

MutateHistory checks the revision and anchor under the transcript lock. A nil replacement forks through the anchor's reply; otherwise it replaces the raw suffix.

func (*Store) RawMessages

func (s *Store) RawMessages(id string) []ai.Message

func (*Store) Recent

func (s *Store) Recent(n int) (out []Meta, err error)

func (*Store) RecordCompaction

func (s *Store) RecordCompaction(id string, cutoff int, summary, model string, usage ai.Usage) error

func (*Store) ReplaceFrom added in v0.107.0

func (s *Store) ReplaceFrom(id string, from int, msgs []ai.Message, model, provider string) error

ReplaceFrom atomically removes the raw message suffix starting at from and writes the replacement messages at the same raw offsets.

func (*Store) RewindSnapshots added in v0.107.0

func (s *Store) RewindSnapshots(id string, from int, expected map[int]string, apply func(commit func() error) error) error

RewindSnapshots consumes file checkpoints without changing conversation history. apply must undo its filesystem changes if commit fails.

func (*Store) Save

func (s *Store) Save(id string, from int, msgs []ai.Message, model, provider string) error

func (*Store) SaveHistory added in v0.103.0

func (s *Store) SaveHistory(id string, h *History, msgs []ai.Message, model, provider string) error

func (*Store) SaveHistoryWithUsage added in v0.103.0

func (s *Store) SaveHistoryWithUsage(id string, h *History, msgs []ai.Message, model, provider string, usage ai.UsageSummary) error

func (*Store) SaveHistoryWithUsageAtRevision added in v0.107.0

func (s *Store) SaveHistoryWithUsageAtRevision(id string, h *History, msgs []ai.Message, model, provider string, usage ai.UsageSummary, expectedRevision string) error

func (*Store) SaveSubagentTranscript

func (s *Store) SaveSubagentTranscript(parentID, taskID string, msgs []ai.Message, model, provider string) (string, error)

func (*Store) SaveTask

func (s *Store) SaveTask(id string, t Task) error

func (*Store) Schedules

func (s *Store) Schedules(id string) []Schedule

func (*Store) Search added in v0.103.0

func (s *Store) Search(query string, includeArchived bool) (out []Meta, err error)

func (*Store) SearchHistory added in v0.107.0

func (s *Store) SearchHistory(ctx context.Context, query string, limit int) (HistorySearchResult, error)

SearchHistory scans one bounded transcript at a time; it never loads all histories.

func (*Store) SessionsDir added in v0.103.0

func (s *Store) SessionsDir() string

func (*Store) SetArchived added in v0.103.0

func (s *Store) SetArchived(id string, archived bool) error

func (*Store) SetCWD added in v0.107.3

func (s *Store) SetCWD(id, cwd string) error

SetCWD updates the stored workspace and moves project-scoped sessions to the corresponding workspace bucket before writing the new metadata.

func (*Store) SetEffort

func (s *Store) SetEffort(id, effort string) error

func (*Store) SetGoal

func (s *Store) SetGoal(id, goal string) error

func (*Store) SetModel added in v0.107.0

func (s *Store) SetModel(id, model, provider string) error

func (*Store) SetPinned

func (s *Store) SetPinned(id string, pinned bool) error

func (*Store) SetShared added in v0.107.0

func (s *Store) SetShared(id, token string, enabled, redactToolContent bool) error

func (*Store) SetSnapshot

func (s *Store) SetSnapshot(id string, seq int, ref string) error

func (*Store) SetTags

func (s *Store) SetTags(id string, tags []string) error

func (*Store) SetTitle

func (s *Store) SetTitle(id, title string) error

func (*Store) SetTodos

func (s *Store) SetTodos(id, todos string) error

func (*Store) SetUsage

func (s *Store) SetUsage(id string, usage ai.UsageSummary) error

func (*Store) SharedByToken added in v0.107.0

func (s *Store) SharedByToken(token string) (Meta, []ai.Message, error)

func (*Store) SharedPage added in v0.107.0

func (s *Store) SharedPage(limit int, after *PageCursor) (Page, error)

func (*Store) SnapshotReferenced added in v0.103.0

func (s *Store) SnapshotReferenced(ref string) (bool, error)

func (*Store) Snapshots

func (s *Store) Snapshots(id string) map[int]string

func (*Store) SubagentTranscript

func (s *Store) SubagentTranscript(parentID, taskID string) ([]ai.Message, error)

func (*Store) Todos

func (s *Store) Todos(id string) string

func (*Store) TranscriptPath added in v0.103.0

func (s *Store) TranscriptPath(id string) string

func (*Store) TruncateAtSequence added in v0.107.0

func (s *Store) TruncateAtSequence(id string, seq int) error

TruncateAtSequence removes messages and snapshots at or after seq.

func (*Store) TruncateHistory added in v0.103.0

func (s *Store) TruncateHistory(id string, h *History, cut int) error

func (*Store) UndoCompaction added in v0.103.0

func (s *Store) UndoCompaction(id string, initial []ai.Message) (*History, []ai.Message, error)

func (*Store) UserHistory

func (s *Store) UserHistory(limit int) (out []string, err error)

type Task

type Task struct {
	Model       string    `json:"model,omitempty"`
	Provider    string    `json:"provider,omitempty"`
	ID          string    `json:"id"`
	Description string    `json:"description"`
	Prompt      string    `json:"prompt"`
	Status      string    `json:"status"`
	Report      string    `json:"report"`
	StartedAt   time.Time `json:"started_at"`
	EndedAt     time.Time `json:"ended_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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