store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 10 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 store keeps conversation content by the hash of its content, once (design 2.2, NFR-5). Workflows and their recorded calls carry only hashes.

Index

Constants

View Source
const (
	KindMessage = "message"
	KindHistory = "history" // a link of the conversation: {prev, messages}
	KindSystem  = "system"
	KindTools   = "tools"
	// KindContent is a file's content as a planned write leaves it.
	KindContent = "content"
	// KindPermissions is the permission rules as a turn started with them.
	KindPermissions = "permissions"
	// KindReviewed is a flow_publish call and the draft it was decided
	// on (ADR 0030): only that draft is published by it.
	KindReviewed = "reviewed"
	// KindImage is an image's bytes, a message's image part refers to by
	// hash (ADR 0026).
	KindImage = "image"
)

Kinds of content.

Variables

View Source
var ErrNotFound = errors.New("store: no such content")

Functions

func Hash

func Hash(kind string, body []byte) string

Hash is the key content of kind is stored under.

Types

type FlowRunRow

type FlowRunRow struct {
	ID, Dir, Name, Status string
	Try                   bool // a try of the flow (ADR 0017), counted apart
	Started, Ended        time.Time
	Body                  []byte
}

FlowRunRow is a flow's run as it is kept (ADR 0029): its body is the runtime's (JSON).

type Link struct {
	Prev     string   `json:"prev,omitempty"`
	Messages []string `json:"messages"`
	Base     bool     `json:"base,omitempty"`
}

Link is one turn's worth of a conversation: the messages it added, after the conversation up to Prev. A conversation is named by its last link, so a workflow passes one hash however long the conversation is.

A Base link starts a conversation afresh (ADR 0020): its messages (a summary) stand for all before it, which Conversation does not read. Its Prev still names them, so they are kept and can be looked at.

type MCPCall

type MCPCall struct {
	Run          string
	N            int
	Proc         string
	Acknowledged bool
}

MCPCall is one recorded MCP call.

type ProviderPref

type ProviderPref struct {
	Model, Effort   string
	Models, Efforts []string
}

ProviderPref is what is kept of a provider: the model and effort last chosen, and the models and efforts its agent said it has.

type Store

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

func New

func New(ctx context.Context, db *sql.DB) (*Store, error)

New makes the table if it is missing. The *sql.DB is shared with kairo's store, so the same file holds both.

func (*Store) AcknowledgeMCPCall

func (s *Store) AcknowledgeMCPCall(ctx context.Context, run string) error

AcknowledgeMCPCall records that run's result reached Claude Code.

func (*Store) AddMCPCall

func (s *Store) AddMCPCall(ctx context.Context, run, turn, key string, n int, proc string) error

func (*Store) ClaudeProc

func (s *Store) ClaudeProc(ctx context.Context, session string) (int, error)

ClaudeProc is the pid of the claude process last started for session, or 0.

func (*Store) ClearSwitch

func (s *Store) ClearSwitch(ctx context.Context, session string, seq int64) error

ClearSwitch removes session's switch once sent, unless it changed after Switch gave seq: the changed one waits for the next event.

func (*Store) Compacted

func (s *Store) Compacted(ctx context.Context, prev, summary string) (string, error)

Compacted adds a Base link holding summary after the conversation that ends at prev, and returns its hash.

func (*Store) Conversation

func (s *Store) Conversation(ctx context.Context, head string) ([]string, error)

Conversation is the hashes of the messages of the conversation that ends at head, oldest first.

func (*Store) EngineSession

func (s *Store) EngineSession(ctx context.Context, name string) (string, error)

EngineSession is the id a CLI gave the session KairoCode calls name, or "" if it has none yet.

func (*Store) Extend

func (s *Store) Extend(ctx context.Context, prev string, messages []string) (string, error)

Extend appends messages to the conversation that ends at prev.

func (*Store) FlowRun

func (s *Store) FlowRun(ctx context.Context, id string) (FlowRunRow, error)

FlowRun is a kept flow's run.

func (*Store) FlowRuns

func (s *Store) FlowRuns(ctx context.Context, dir, name, only string, limit int) ([]FlowRunRow, error)

FlowRuns are the kept runs of dir's flows ("" any dir), of flow name ("" any), the latest first, at most limit (0: all), with their bodies; only "tries" or "runs" of them, or both ("").

func (*Store) FlowRunsSince

func (s *Store) FlowRunsSince(ctx context.Context, dir, name string, try bool, at time.Time) (int, error)

FlowRunsSince counts dir's kept runs (or tries) of flow name started after at.

func (*Store) Get

func (s *Store) Get(ctx context.Context, hash string) (kind string, body []byte, err error)

func (*Store) GetJSON

func (s *Store) GetJSON(ctx context.Context, hash, kind string, v any) error

func (*Store) Grant

func (s *Store) Grant(ctx context.Context, turn, ask, key string, ok bool, reason string) error

Grant records the user's answer to request ask, about calls of content key in turn.

func (*Store) HasFlowRun

func (s *Store) HasFlowRun(ctx context.Context, id string) (bool, error)

HasFlowRun says a flow's run is kept.

func (*Store) LastProvider

func (s *Store) LastProvider(ctx context.Context) (string, error)

LastProvider is the provider last chosen, in any session ("" if none). It is kept in the row of provider "", in its model.

func (*Store) MCPCalls

func (s *Store) MCPCalls(ctx context.Context, turn, key string) ([]MCPCall, error)

MCPCalls are the recorded calls of content key in turn, by occurrence.

func (*Store) MCPRuns

func (s *Store) MCPRuns(ctx context.Context, turn string) ([]string, error)

MCPRuns are the runs of every MCP call recorded for turn.

func (*Store) MCPTurns

func (s *Store) MCPTurns(ctx context.Context) (map[string]bool, error)

MCPTurns are the turns with an MCP call recorded: one of them may hold a call cut off, to be reviewed, after it finished.

func (*Store) Message

func (s *Store) Message(ctx context.Context, hash string) (msg.Message, error)

func (*Store) Messages

func (s *Store) Messages(ctx context.Context, hashes []string) ([]msg.Message, error)

Messages loads the messages named by hashes, in order.

func (*Store) ProviderPref

func (s *Store) ProviderPref(ctx context.Context, provider string) (ProviderPref, error)

ProviderPref is provider's (zero if nothing is kept).

func (*Store) PruneFlowRuns

func (s *Store) PruneFlowRuns(ctx context.Context, dir, name string, try bool, keep int, before time.Time) error

PruneFlowRuns removes dir's runs (or tries: counted apart) of flow name past the newest keep, or started before before.

func (*Store) Put

func (s *Store) Put(ctx context.Context, kind string, body []byte) (string, error)

Put stores body once and returns its hash. Writing the same content again changes nothing, so Put is safe to repeat.

func (*Store) PutFlowRun

func (s *Store) PutFlowRun(ctx context.Context, r FlowRunRow) error

PutFlowRun keeps a flow's run; kept again, it is replaced.

func (*Store) PutJSON

func (s *Store) PutJSON(ctx context.Context, kind string, v any) (string, error)

func (*Store) PutMessage

func (s *Store) PutMessage(ctx context.Context, m msg.Message) (string, error)

func (*Store) SetClaudeProc

func (s *Store) SetClaudeProc(ctx context.Context, session string, pid int) error

SetClaudeProc records pid as session's claude process (0: none).

func (*Store) SetEngineSession

func (s *Store) SetEngineSession(ctx context.Context, name, id string) error

SetEngineSession records that the CLI's session name is id.

func (*Store) SetLastProvider

func (s *Store) SetLastProvider(ctx context.Context, provider string) error

SetLastProvider keeps provider as the one last chosen.

func (*Store) SetProviderChoice

func (s *Store) SetProviderChoice(ctx context.Context, provider, model, effort string) error

SetProviderChoice keeps the model and the effort chosen for provider ("" leaves one as it is).

func (*Store) SetProviderOptions

func (s *Store) SetProviderOptions(ctx context.Context, provider string, models, efforts []string) error

SetProviderOptions keeps the models and efforts provider's agent said it has (nil leaves one as it is).

func (*Store) SetSwitch

func (s *Store) SetSwitch(ctx context.Context, session string, body []byte) error

SetSwitch keeps body as session's switch not yet sent.

func (*Store) Switch

func (s *Store) Switch(ctx context.Context, session string) (body []byte, seq int64, err error)

Switch is session's switch not yet sent (nil body: none) and the count of its changes, to give ClearSwitch.

func (*Store) UseGrant

func (s *Store) UseGrant(ctx context.Context, turn, key, run string) (found, ok bool, reason string, err error)

UseGrant gives run an answer about calls of content key in turn: the one it was given before, or else the oldest one no run has used. An answer lets one run, never two: a call made again later, after an interruption, is asked about again (ADR 0005, 0007).

Jump to

Keyboard shortcuts

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