history

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package history keeps the AI conversations of each host, to look back on and carry on. A conversation holds what its pane showed and, for the built-in agent, the messages it sends the model; both may hold terminal output and command results, so every file is sealed by the keychain's master key. Each host has a folder: an index of its conversations, the newest first, and a file for each.

Index

Constants

View Source
const (
	MaxPerHost = 100
	MaxSize    = 4 << 20
)

MaxPerHost is how many conversations a host keeps: saving one more drops the oldest. MaxSize is the most a conversation's file holds; a longer one keeps its latest items.

Variables

View Source
var ErrNotFound = errors.New("history: conversation not found")

ErrNotFound is a conversation that is not kept.

Functions

func NewID

func NewID() string

NewID is a new conversation's ID.

func Title

func Title(q string) string

Title is the title of a conversation first asked q: its first line, cut to about 40 characters.

Types

type Conversation

type Conversation struct {
	ID       string    `json:"id"`
	Host     string    `json:"host"`
	Title    string    `json:"title"`
	Agent    string    `json:"agent,omitempty"`
	Provider string    `json:"provider,omitempty"`
	Model    string    `json:"model,omitempty"`
	Effort   string    `json:"effort,omitempty"`
	Created  time.Time `json:"created"`
	Updated  time.Time `json:"updated"`
	Items    []Item    `json:"items"`
	// Messages are the built-in agent's, without its system prompt; nil
	// for an external agent, which keeps its own.
	Messages []llm.Message `json:"messages,omitempty"`
}

Conversation is one conversation of a host.

type File

type File struct {
	Name string `json:"name"`
	MIME string `json:"mime,omitempty"`
}

File names a file a question had attached; its content is not kept.

type Item

type Item struct {
	Kind  string          `json:"kind"`
	Text  string          `json:"text,omitempty"`
	Files []File          `json:"files,omitempty"`
	Tool  *agent.ToolCard `json:"tool,omitempty"`
}

Item is one entry of the timeline: a question (user), an answer (text), thinking (think), a tool call (tool) or an error (err).

type Sealer

type Sealer interface {
	Seal(purpose string, plain, aad []byte) ([]byte, error)
	Unseal(purpose string, sealed, aad []byte) ([]byte, error)
}

Sealer seals the store's files; *keychain.Keychain is one.

type Store

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

Store is the conversations under a folder.

func New

func New(dir string, s Sealer) *Store

New is the store under dir, sealed by s.

func (*Store) Delete

func (st *Store) Delete(host, id string) error

Delete forgets host's conversation id.

func (*Store) DeleteHost

func (st *Store) DeleteHost(host string) error

DeleteHost forgets every conversation of host.

func (*Store) List

func (st *Store) List(host string) ([]Summary, error)

List is host's conversations, the latest first.

func (*Store) Load

func (st *Store) Load(host, id string) (Conversation, error)

Load is host's conversation id.

func (*Store) Save

func (st *Store) Save(c Conversation) error

Save keeps c, first in its host's index, and drops the conversations past MaxPerHost.

type Summary

type Summary struct {
	ID       string    `json:"id"`
	Title    string    `json:"title"`
	Agent    string    `json:"agent,omitempty"`
	Provider string    `json:"provider,omitempty"`
	Model    string    `json:"model,omitempty"`
	Created  time.Time `json:"created"`
	Updated  time.Time `json:"updated"`
}

Summary is a conversation as the index lists it.

Jump to

Keyboard shortcuts

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