storage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateName

func GenerateName() string

GenerateName returns a random name in adjective-gerund-noun format.

Types

type Compaction

type Compaction struct {
	Summary  string            `json:"summary"`
	Messages []json.RawMessage `json:"messages,omitempty"`
}

Compaction stores a compaction summary and optionally kept messages.

type ContextSnapshot

type ContextSnapshot struct {
	Messages []agentcore.AgentMessage
	Provider string
	Model    string
	Thinking string
}

ContextSnapshot is the projected runtime state from a session log.

type Entry

type Entry struct {
	Kind      EntryKind       `json:"kind"`
	ID        string          `json:"id"`
	ParentID  string          `json:"parent_id,omitempty"`
	Timestamp time.Time       `json:"timestamp"`
	Data      json.RawMessage `json:"data"`
}

Entry is a single JSONL line in the session file.

type EntryKind

type EntryKind string

EntryKind identifies the type of a JSONL entry.

const (
	EntryHeader         EntryKind = "header"
	EntryMessage        EntryKind = "message"
	EntryModelChange    EntryKind = "model_change"
	EntryCompaction     EntryKind = "compaction"
	EntryThinkingChange EntryKind = "thinking_change"
	EntrySessionInfo    EntryKind = "session_info"
)
type Header struct {
	Version   int       `json:"version"`
	SessionID string    `json:"session_id"`
	Name      string    `json:"name,omitempty"`
	Cwd       string    `json:"cwd"`
	Created   time.Time `json:"created"`
}

Header is the first line of a session file.

type History

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

History provides append-only input history with per-project filtering. The backing file (~/.codebot/history.jsonl) is shared across all projects; only entries matching the current project are surfaced.

func NewHistory

func NewHistory(path, project, sessionID string) *History

NewHistory loads history from path, filtering by project.

func (*History) Add

func (h *History) Add(text string)

Add appends text to history. Duplicates are moved to the front.

func (*History) Get

func (h *History) Get(index int) string

Get returns the history entry at index (0 = most recent).

func (*History) Len

func (h *History) Len() int

Len returns the number of history entries for the current project.

func (*History) SetSessionID

func (h *History) SetSessionID(id string)

SetSessionID updates the session ID for subsequent entries (e.g. after session switch).

type HistoryEntry

type HistoryEntry struct {
	Display        string         `json:"display"`
	PastedContents map[string]any `json:"pastedContents"`
	Timestamp      int64          `json:"timestamp"`
	Project        string         `json:"project"`
	SessionID      string         `json:"sessionId,omitempty"`
}

HistoryEntry is one line in the JSONL history file.

type Manager

type Manager struct {
	Dir string
}

Manager manages session files in a directory.

func NewManager

func NewManager(dir string) *Manager

NewManager creates a Manager for the given sessions directory.

func (*Manager) Create

func (m *Manager) Create(cwd string) (*Store, error)

Create creates a new session.

func (*Manager) List

func (m *Manager) List() ([]SessionInfo, error)

List returns all sessions sorted by updated time (newest first).

func (*Manager) MostRecent

func (m *Manager) MostRecent() (*SessionInfo, error)

MostRecent returns the most recently updated session.

func (*Manager) Open

func (m *Manager) Open(id string) (*Store, error)

Open opens an existing session by ID.

func (*Manager) OpenPath

func (m *Manager) OpenPath(path string) (*Store, error)

OpenPath opens a session by file path.

type ModelChange

type ModelChange struct {
	Provider string `json:"provider"`
	Model    string `json:"model"`
}

ModelChange records a model switch event.

type PlanFile

type PlanFile struct {
	Name    string // filename without .md
	ModTime int64  // unix timestamp
}

PlanFile represents a plan file entry for listing.

type PlanStore

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

PlanStore manages plan markdown files in a single directory.

func NewPlanStore

func NewPlanStore(dir string) *PlanStore

NewPlanStore creates a PlanStore and ensures the directory exists.

func (*PlanStore) Delete

func (s *PlanStore) Delete(name string) error

Delete removes a plan file.

func (*PlanStore) List

func (s *PlanStore) List() ([]PlanFile, error)

List returns all plan files sorted by modification time (newest first).

func (*PlanStore) Load

func (s *PlanStore) Load(name string) (string, error)

Load reads a plan file by name. Returns "", nil if not found.

func (*PlanStore) Save

func (s *PlanStore) Save(name, content string) error

Save writes plan content as a markdown file.

type SessionInfo

type SessionInfo struct {
	ID           string
	Name         string
	Path         string
	Cwd          string
	Created      time.Time
	Updated      time.Time
	MessageCount int
	FirstMessage string // first user message, truncated to 80 chars
}

SessionInfo is a summary of a session for listing.

type Store

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

Store manages a single session JSONL file.

func (*Store) AppendCompaction

func (s *Store) AppendCompaction(summary string, keptMessages []json.RawMessage) error

AppendCompaction records a compaction event with summary and optional kept messages.

func (*Store) AppendMessage

func (s *Store) AppendMessage(msg agentcore.Message) error

AppendMessage serializes and appends an agentcore.Message.

func (*Store) AppendModelChange

func (s *Store) AppendModelChange(provider, model string) error

AppendModelChange records a model switch.

func (*Store) AppendThinkingLevelChange

func (s *Store) AppendThinkingLevelChange(level string) error

AppendThinkingLevelChange records a thinking level switch.

func (*Store) BuildSnapshot

func (s *Store) BuildSnapshot() (ContextSnapshot, error)

BuildSnapshot reconstructs runtime state by walking the tree from the current leaf.

func (*Store) Close

func (s *Store) Close() error

Close closes the session file.

func (*Store) Header

func (s *Store) Header() Header

Header returns the session header.

func (*Store) Path

func (s *Store) Path() string

Path returns the session file path.

func (*Store) SetName

func (s *Store) SetName(name string) error

SetName updates the session display name by appending a session_info entry.

type ThinkingLevelChange

type ThinkingLevelChange struct {
	Level string `json:"level"`
}

ThinkingLevelChange records a thinking level switch event.

Jump to

Keyboard shortcuts

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