store

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 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 is PlugIt's call log (SPEC §3.6 data/plugit.db, §3.7 step 9): one row of redacted metadata per tool call, kept for the API's log.retention, read by `plugit logs` and `plugit stats`. It is SQLite (modernc.org/sqlite: pure Go, no CGO) in WAL mode, so several `plugit serve` processes (one per MCP client) can write while a viewer reads.

Callers redact before recording: nothing here knows about secrets.

Index

Constants

View Source
const (
	MaxArgsBytes    = 16 << 10
	MaxPreviewBytes = 2 << 10
	MaxErrorBytes   = 1 << 10
)

Caps on stored text, so one huge call can't bloat the log.

View Source
const SchemaVersion = 1

SchemaVersion is the call log's schema version (PRAGMA user_version).

Variables

View Source
var ErrNoLog = errors.New("no calls recorded yet")

ErrNoLog means there is no call log yet (nothing has been served).

Functions

This section is empty.

Types

type Call

type Call struct {
	ID       int64           `json:"id"`
	Time     time.Time       `json:"time"`
	API      string          `json:"api"`
	Toolset  string          `json:"toolset"`
	Tool     string          `json:"tool"`
	Op       string          `json:"op"`
	Outcome  Outcome         `json:"outcome"`
	Status   int             `json:"status,omitempty"`
	Duration time.Duration   `json:"duration_ns"`
	Bytes    int             `json:"bytes,omitempty"`
	Args     json.RawMessage `json:"args,omitempty"`
	Preview  string          `json:"preview,omitempty"`
	Error    string          `json:"error,omitempty"`
}

Call is one logged tool call. Every text field is already redacted.

type DB

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

DB is an open call log.

func Open

func Open(ctx context.Context, path string) (*DB, error)

Open opens (creating if needed) the call log at path. The directory is owner-only and the file is created 0600 before SQLite touches it; SQLite gives its -wal and -shm files the same permissions.

func OpenExisting

func OpenExisting(ctx context.Context, path string) (*DB, error)

OpenExisting opens the log for reading, or returns ErrNoLog if it doesn't exist yet. It never creates the file.

func (*DB) Close

func (db *DB) Close() error

Close closes the log.

func (*DB) Insert

func (db *DB) Insert(ctx context.Context, c Call) (int64, error)

Insert stores one call and returns its id. Oversized fields are capped.

func (*DB) List

func (db *DB) List(ctx context.Context, f Filter) ([]Call, error)

List returns calls in id order (oldest first).

func (*DB) Prune

func (db *DB) Prune(ctx context.Context, api string, before time.Time) (int64, error)

Prune deletes an API's calls older than before.

func (*DB) Stats

func (db *DB) Stats(ctx context.Context, f Filter) ([]ToolStats, error)

Stats summarizes calls per API and tool, most-called first. f.Limit and f.AfterID are ignored.

type Filter

type Filter struct {
	API     string
	AfterID int64
	Since   time.Time
	Limit   int
	Newest  bool
}

Filter selects calls.

type Outcome

type Outcome string

Outcome is how a call ended.

const (
	OK          Outcome = "ok"
	HTTPError   Outcome = "http_error"
	Denied      Outcome = "denied"
	Invalid     Outcome = "invalid"
	RateLimited Outcome = "rate_limited"
	Failed      Outcome = "error"
)

Call outcomes.

type Recorder

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

Recorder writes calls in the background so recording never blocks or fails a tool call (SPEC §3.7 step 9). When its buffer is full, calls are dropped and counted.

func NewRecorder

func NewRecorder(db *DB, buffer int, onErr func(error)) *Recorder

NewRecorder starts a recorder with room for buffer pending calls. onErr (may be nil) hears about write failures.

func (*Recorder) Close

func (r *Recorder) Close()

Close stops accepting calls and waits for queued ones to be written.

func (*Recorder) Dropped

func (r *Recorder) Dropped() int64

Dropped is how many calls were not recorded because the buffer was full.

func (*Recorder) Record

func (r *Recorder) Record(c Call)

Record queues c without blocking. After Close it does nothing.

type ToolStats

type ToolStats struct {
	API      string        `json:"api"`
	Tool     string        `json:"tool"`
	Calls    int           `json:"calls"`
	Errors   int           `json:"errors"`
	P50      time.Duration `json:"p50_ns"`
	P95      time.Duration `json:"p95_ns"`
	Bytes    int64         `json:"bytes"`
	Last     time.Time     `json:"last"`
	Outcomes map[Outcome]int
}

ToolStats summarizes one tool's calls.

Jump to

Keyboard shortcuts

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