Documentation
¶
Overview ¶
Package datastore provides a unified data layer for session-scoped persistence. It composes existing data packages and serves as the authoritative source for conversation histories, prompt history, session state, rewind stack, checkpoint, and cost tracking within a session.
Index ¶
- type Options
- type RewindEntry
- type RewindResult
- type SelectionParams
- type Store
- func (s *Store) AccumulateCost(modelID string, cost float64)
- func (s *Store) ActiveRecipe() *recipe.Recipe
- func (s *Store) AppendHistories(panelIDs []string, responses []models.ModelResponse, userPrompt string) map[string]int
- func (s *Store) BaseRecipe() *recipe.Recipe
- func (s *Store) BuildRecipeSnapshot() *recipestore.RecipeSnapshot
- func (s *Store) CanRewind() bool
- func (s *Store) CheckpointPath() string
- func (s *Store) ClearCheckpoint()
- func (s *Store) ClearHistories()
- func (s *Store) ClearRewindStack()
- func (s *Store) Content() session.SessionContent
- func (s *Store) ContentPath() string
- func (s *Store) CostPerModel() map[string]float64
- func (s *Store) Histories() map[string][]models.ConversationTurn
- func (s *Store) LastActiveTools() []string
- func (s *Store) LoadCheckpoint() (*checkpoint.Checkpoint, error)
- func (s *Store) Metadata() session.SessionMetadata
- func (s *Store) MetadataPath() string
- func (s *Store) PersistRunState(lastPrompt string, responses []models.ModelResponse, ...)
- func (s *Store) PromptHistory() []string
- func (s *Store) PushFileSnapshots(snaps []tools.FileSnapshot)
- func (s *Store) PushRewindEntry(entry RewindEntry)
- func (s *Store) RecipeHash() string
- func (s *Store) RecipeNameLookup() func(string) string
- func (s *Store) RecipeStore() *recipestore.Store
- func (s *Store) RecipesDir() string
- func (s *Store) RecordPrompt(prompt string) bool
- func (s *Store) RecordSelection(p SelectionParams)
- func (s *Store) Rewind() (RewindResult, error)
- func (s *Store) RewindStackLen() int
- func (s *Store) SaveInitialMeta()
- func (s *Store) SessionID() string
- func (s *Store) SessionRecipe() *recipe.Recipe
- func (s *Store) SessionRecipePath() string
- func (s *Store) SessionsDir() string
- func (s *Store) SetHistories(h map[string][]models.ConversationTurn)
- func (s *Store) SetLastActiveTools(names []string)
- func (s *Store) SetSessionRecipe(r *recipe.Recipe)
- func (s *Store) TotalCost() float64
- func (s *Store) TruncateHistories(lengths map[string]int)
- func (s *Store) UpdateLastRunNote(note string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
PromptHistPath string // path to global prompt_history.jsonl
SessionPaths session.Paths
SessionID string
Meta session.SessionMetadata
RecipeStore *recipestore.Store
Recipe *recipe.Recipe // base recipe loaded at startup
}
Options configures a new Store.
type RewindEntry ¶
type RewindEntry struct {
FileSnapshots []tools.FileSnapshot // nil if no writes were applied
HistoryLengths map[string]int // per-adapter history len BEFORE AppendHistory
FeedIndex int // index into the UI feed for annotation
Prompt string // original prompt (for rewind marker)
}
RewindEntry captures enough state to undo one run.
type RewindResult ¶
type RewindResult struct {
FileMsg string // warning from file restore, or ""
FeedIndex int // index into the UI feed for annotation
Note string // "[rewound]" or "[rewound] Applied: ..."
}
RewindResult is returned by Rewind with information the UI needs to update display.
type SelectionParams ¶
type SelectionParams struct {
Prompt string
SelectedModelID string
Responses []models.ModelResponse
AppliedFiles []string // nil for text-only votes / ratings
Rating string // "" for selection, "good" or "bad" for rating
}
SelectionParams captures the information needed to record a selection or rating.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the single source of truth for persisted and session-scoped data. It owns the in-memory state and persists on mutation.
func New ¶
New creates a Store, loading existing data from disk. Missing files are not errors — the store starts empty.
func (*Store) AccumulateCost ¶
AccumulateCost adds cost for a model run.
func (*Store) ActiveRecipe ¶
ActiveRecipe returns the session recipe if set, otherwise the base recipe.
func (*Store) AppendHistories ¶
func (s *Store) AppendHistories( panelIDs []string, responses []models.ModelResponse, userPrompt string, ) map[string]int
AppendHistories appends conversation turns for a completed run and persists to disk. Returns the pre-append lengths (for rewind support).
func (*Store) BaseRecipe ¶
BaseRecipe returns the immutable base recipe from startup.
func (*Store) BuildRecipeSnapshot ¶
func (s *Store) BuildRecipeSnapshot() *recipestore.RecipeSnapshot
BuildRecipeSnapshot creates a RecipeSnapshot from the active recipe and the last active tools.
func (*Store) CheckpointPath ¶
CheckpointPath returns the path used for checkpoint files.
func (*Store) ClearCheckpoint ¶
func (s *Store) ClearCheckpoint()
ClearCheckpoint removes the checkpoint file.
func (*Store) ClearHistories ¶
func (s *Store) ClearHistories()
ClearHistories wipes all conversation history and persists.
func (*Store) ClearRewindStack ¶
func (s *Store) ClearRewindStack()
ClearRewindStack empties the rewind stack (called on /clear, /wipe, /compact).
func (*Store) Content ¶
func (s *Store) Content() session.SessionContent
Content returns the current session content.
func (*Store) ContentPath ¶
ContentPath returns the path to session_content.json.
func (*Store) CostPerModel ¶
CostPerModel returns the per-model cumulative cost this session.
func (*Store) Histories ¶
func (s *Store) Histories() map[string][]models.ConversationTurn
Histories returns the current conversation histories map. The caller must not mutate the returned map.
func (*Store) LastActiveTools ¶
LastActiveTools returns the tool names from the last run.
func (*Store) LoadCheckpoint ¶
func (s *Store) LoadCheckpoint() (*checkpoint.Checkpoint, error)
LoadCheckpoint loads the checkpoint from disk. Returns (nil, nil) if not found.
func (*Store) Metadata ¶
func (s *Store) Metadata() session.SessionMetadata
Metadata returns the current session metadata.
func (*Store) MetadataPath ¶
MetadataPath returns the path to session_metadata.json.
func (*Store) PersistRunState ¶
func (s *Store) PersistRunState( lastPrompt string, responses []models.ModelResponse, collector *output.Collector, toolNames []string, )
PersistRunState updates session metadata with a RunSummary, appends a RunContent to content, and persists both files plus the session recipe.
func (*Store) PromptHistory ¶
PromptHistory returns the prompt history (newest-first). The caller must not mutate the returned slice.
func (*Store) PushFileSnapshots ¶
func (s *Store) PushFileSnapshots(snaps []tools.FileSnapshot)
PushFileSnapshots stores file snapshots on the top rewind entry (called after applySelection writes files).
func (*Store) PushRewindEntry ¶
func (s *Store) PushRewindEntry(entry RewindEntry)
PushRewindEntry pushes a new rewind entry onto the stack.
func (*Store) RecipeHash ¶
RecipeHash computes a content-addressed hash for the active recipe snapshot. Returns "" if no recipe store is configured.
func (*Store) RecipeNameLookup ¶
RecipeNameLookup returns a function that resolves a config hash to a recipe name.
func (*Store) RecipeStore ¶
func (s *Store) RecipeStore() *recipestore.Store
RecipeStore returns the recipe store (for /stats filter).
func (*Store) RecipesDir ¶
RecipesDir returns the recipes directory (data/recipes/).
func (*Store) RecordPrompt ¶
RecordPrompt adds a prompt to history if it differs from the most recent entry, persists to disk, and returns whether the prompt was actually added.
func (*Store) RecordSelection ¶
func (s *Store) RecordSelection(p SelectionParams)
RecordSelection updates the last RunSummary in metadata with the selection outcome.
func (*Store) Rewind ¶
func (s *Store) Rewind() (RewindResult, error)
Rewind pops the top rewind entry, restores files, truncates histories, records a rewind marker in metadata, and annotates the run note. Returns a RewindResult for the UI to update display.
func (*Store) RewindStackLen ¶
RewindStackLen returns the number of entries in the rewind stack (used by tests).
func (*Store) SaveInitialMeta ¶
func (s *Store) SaveInitialMeta()
SaveInitialMeta persists the initial session metadata to disk.
func (*Store) SessionRecipe ¶
SessionRecipe returns the working copy of the recipe (nil if unmodified).
func (*Store) SessionRecipePath ¶
SessionRecipePath returns the path to session recipe.md (used by tests).
func (*Store) SessionsDir ¶
SessionsDir returns the base sessions directory (data/sessions/).
func (*Store) SetHistories ¶
func (s *Store) SetHistories(h map[string][]models.ConversationTurn)
SetHistories replaces the histories wholesale (used by compaction) and persists.
func (*Store) SetLastActiveTools ¶
SetLastActiveTools sets the last active tool names (used after run complete).
func (*Store) SetSessionRecipe ¶
SetSessionRecipe sets the working copy of the recipe.
func (*Store) TruncateHistories ¶
TruncateHistories restores per-adapter history to the given pre-run lengths (used by rewind) and persists.
func (*Store) UpdateLastRunNote ¶
UpdateLastRunNote updates the note on the most recent RunSummary in metadata and re-saves session_metadata.json.