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
- Variables
- func Hash(kind string, body []byte) string
- type FlowRunRow
- type Link
- type MCPCall
- type ProviderPref
- type Store
- func (s *Store) AcknowledgeMCPCall(ctx context.Context, run string) error
- func (s *Store) AddMCPCall(ctx context.Context, run, turn, key string, n int, proc string) error
- func (s *Store) ClaudeProc(ctx context.Context, session string) (int, error)
- func (s *Store) ClearSwitch(ctx context.Context, session string, seq int64) error
- func (s *Store) Compacted(ctx context.Context, prev, summary string) (string, error)
- func (s *Store) Conversation(ctx context.Context, head string) ([]string, error)
- func (s *Store) EngineSession(ctx context.Context, name string) (string, error)
- func (s *Store) Extend(ctx context.Context, prev string, messages []string) (string, error)
- func (s *Store) FlowRun(ctx context.Context, id string) (FlowRunRow, error)
- func (s *Store) FlowRuns(ctx context.Context, dir, name, only string, limit int) ([]FlowRunRow, error)
- func (s *Store) FlowRunsSince(ctx context.Context, dir, name string, try bool, at time.Time) (int, error)
- func (s *Store) Get(ctx context.Context, hash string) (kind string, body []byte, err error)
- func (s *Store) GetJSON(ctx context.Context, hash, kind string, v any) error
- func (s *Store) Grant(ctx context.Context, turn, ask, key string, ok bool, reason string) error
- func (s *Store) HasFlowRun(ctx context.Context, id string) (bool, error)
- func (s *Store) LastProvider(ctx context.Context) (string, error)
- func (s *Store) MCPCalls(ctx context.Context, turn, key string) ([]MCPCall, error)
- func (s *Store) MCPRuns(ctx context.Context, turn string) ([]string, error)
- func (s *Store) MCPTurns(ctx context.Context) (map[string]bool, error)
- func (s *Store) Message(ctx context.Context, hash string) (msg.Message, error)
- func (s *Store) Messages(ctx context.Context, hashes []string) ([]msg.Message, error)
- func (s *Store) ProviderPref(ctx context.Context, provider string) (ProviderPref, error)
- func (s *Store) PruneFlowRuns(ctx context.Context, dir, name string, try bool, keep int, before time.Time) error
- func (s *Store) Put(ctx context.Context, kind string, body []byte) (string, error)
- func (s *Store) PutFlowRun(ctx context.Context, r FlowRunRow) error
- func (s *Store) PutJSON(ctx context.Context, kind string, v any) (string, error)
- func (s *Store) PutMessage(ctx context.Context, m msg.Message) (string, error)
- func (s *Store) SetClaudeProc(ctx context.Context, session string, pid int) error
- func (s *Store) SetEngineSession(ctx context.Context, name, id string) error
- func (s *Store) SetLastProvider(ctx context.Context, provider string) error
- func (s *Store) SetProviderChoice(ctx context.Context, provider, model, effort string) error
- func (s *Store) SetProviderOptions(ctx context.Context, provider string, models, efforts []string) error
- func (s *Store) SetSwitch(ctx context.Context, session string, body []byte) error
- func (s *Store) Switch(ctx context.Context, session string) (body []byte, seq int64, err error)
- func (s *Store) UseGrant(ctx context.Context, turn, key, run string) (found, ok bool, reason string, err error)
Constants ¶
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 ¶
var ErrNotFound = errors.New("store: no such content")
Functions ¶
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 ¶
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 ProviderPref ¶
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 ¶
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 ¶
AcknowledgeMCPCall records that run's result reached Claude Code.
func (*Store) AddMCPCall ¶
func (*Store) ClaudeProc ¶
ClaudeProc is the pid of the claude process last started for session, or 0.
func (*Store) ClearSwitch ¶
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 ¶
Compacted adds a Base link holding summary after the conversation that ends at prev, and returns its hash.
func (*Store) Conversation ¶
Conversation is the hashes of the messages of the conversation that ends at head, oldest first.
func (*Store) EngineSession ¶
EngineSession is the id a CLI gave the session KairoCode calls name, or "" if it has none yet.
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) Grant ¶
Grant records the user's answer to request ask, about calls of content key in turn.
func (*Store) HasFlowRun ¶
HasFlowRun says a flow's run is kept.
func (*Store) LastProvider ¶
LastProvider is the provider last chosen, in any session ("" if none). It is kept in the row of provider "", in its model.
func (*Store) MCPTurns ¶
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) ProviderPref ¶
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 ¶
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) PutMessage ¶
func (*Store) SetClaudeProc ¶
SetClaudeProc records pid as session's claude process (0: none).
func (*Store) SetEngineSession ¶
SetEngineSession records that the CLI's session name is id.
func (*Store) SetLastProvider ¶
SetLastProvider keeps provider as the one last chosen.
func (*Store) SetProviderChoice ¶
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) Switch ¶
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).