store

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package store persists per-conversation state as a JSON file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checkpoint

type Checkpoint struct {
	Cwd    string    `json:"cwd"`
	Commit string    `json:"commit"`
	Prompt string    `json:"prompt"`
	At     time.Time `json:"at"`
}

Checkpoint is a git snapshot taken before a turn.

type Conversation

type Conversation struct {
	Agent       string   `json:"agent,omitempty"`
	Model       string   `json:"model,omitempty"`
	Mode        string   `json:"mode,omitempty"`
	Project     string   `json:"project,omitempty"`
	Cwd         string   `json:"cwd,omitempty"`
	SessionID   string   `json:"session_id,omitempty"`
	AlwaysAllow []string `json:"always_allow,omitempty"`
	Voice       bool     `json:"voice,omitempty"`

	TotalCost float64 `json:"total_cost_usd,omitempty"`

	Sessions    []SessionRecord `json:"sessions,omitempty"`
	Checkpoints []Checkpoint    `json:"checkpoints,omitempty"`
}

Conversation is one chat, or one forum topic in a chat.

func (*Conversation) PushCheckpoint

func (c *Conversation) PushCheckpoint(cp Checkpoint)

func (*Conversation) RecordSession

func (c *Conversation) RecordSession(r SessionRecord)

RecordSession moves id to the front of the recent sessions list.

type Project added in v0.8.0

type Project struct {
	Cwd   string    `json:"cwd"`
	Added time.Time `json:"added"`
}

Project is a project added from chat. Projects from the config file are not stored here.

type SessionRecord

type SessionRecord struct {
	ID      string    `json:"id"`
	Agent   string    `json:"agent"`
	Cwd     string    `json:"cwd"`
	Title   string    `json:"title"`
	Updated time.Time `json:"updated"`
}

SessionRecord remembers a past session so /sessions can resume it.

type Store

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

func Open

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

func (*Store) AddProject added in v0.8.0

func (st *Store) AddProject(name string, p Project) error

AddProject stores a project, failing if the name is taken.

func (*Store) AddSpend

func (st *Store) AddSpend(user string, usd float64) error

AddSpend records USD spent by a user today.

func (*Store) Get

func (st *Store) Get(key string) Conversation

Get returns a deep copy of the conversation.

func (*Store) Projects added in v0.8.0

func (st *Store) Projects() map[string]Project

Projects returns a copy of the projects added from chat.

func (*Store) RemoveProject added in v0.8.0

func (st *Store) RemoveProject(name string) error

RemoveProject deletes a stored project, failing if there is none.

func (*Store) Spend

func (st *Store) Spend(user string) (today, month float64)

Spend returns what a user spent today and over the last 30 days.

func (*Store) Update

func (st *Store) Update(key string, fn func(*Conversation)) error

Update applies fn to the conversation and saves.

Jump to

Keyboard shortcuts

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