store

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 Imported by: 1 module, 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 refetch's local event log: one SQLite file with the hook handler's tool calls and the MCP server's fetch attempts. Nothing in it leaves the machine.

Index

Constants

View Source
const (
	CallStarted    = "started"    // PreToolUse seen, no post event yet
	CallOK         = "ok"         // returned page text
	CallFailed     = "failed"     // tool error, or a page the block detector flags
	CallRedirected = "redirected" // denied by another hook in favor of another tool (context-mode)
	CallDenied     = "denied"     // denied for any other reason
)

Tool call outcomes.

View Source
const Retention = 180 * 24 * time.Hour

Retention is how long raw rows are kept before they are rolled into the daily table.

Variables

This section is empty.

Functions

func NormalizeURL

func NormalizeURL(raw string) (normalized, host string)

NormalizeURL lowercases the scheme and host, drops user info, default ports, the query string and the fragment, and returns the URL and its host. A string that is not an absolute URL comes back as is.

func Path

func Path(dir string) string

Path is events.db inside dir.

Types

type Attempt

type Attempt struct {
	Time     time.Time
	FetchID  string // groups the attempts of one call
	Via      string // mcp or cli
	URL      string // normalized on write
	Host     string // set on write
	Client   string
	Outcome  string
	Status   int
	Bytes    int
	Duration time.Duration
	Error    string // first 300 characters
}

Attempt is one step inside a fetch_page call (or refetch get).

type Store

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

Store is an open events.db.

func Open

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

Open opens or creates the database at path and applies the schema. It stays cheap enough for a hook; callers roll old rows up with Rollup.

func (*Store) Attempts

func (s *Store) Attempts(ctx context.Context, since time.Time) ([]Attempt, error)

Attempts returns the attempts since t, oldest first.

func (*Store) Calls

func (s *Store) Calls(ctx context.Context, since time.Time) ([]ToolCall, error)

Calls returns the tool calls since t, oldest first.

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) File

func (s *Store) File() string

File is the database path.

func (*Store) NeedsRender added in v0.3.0

func (s *Store) NeedsRender(ctx context.Context, host string, since time.Time, n int) (bool, error)

NeedsRender reports whether host's last n fetches since t were each read by the headless Chrome step ("headless") and by no HTTP client.

func (*Store) RecordAttempt

func (s *Store) RecordAttempt(ctx context.Context, a Attempt) error

RecordAttempt inserts one fetch attempt.

func (*Store) RecordCall

func (s *Store) RecordCall(ctx context.Context, c ToolCall) error

RecordCall inserts a tool call, or updates the row with the same ToolUseID (a post event completing its PreToolUse record).

func (*Store) Reset

func (s *Store) Reset(ctx context.Context) error

Reset deletes every row.

func (*Store) Rollup

func (s *Store) Rollup(ctx context.Context, cutoff time.Time) error

Rollup moves rows older than cutoff into per-day counts.

func (*Store) Size

func (s *Store) Size() int64

Size is the database file size in bytes, WAL included.

type ToolCall

type ToolCall struct {
	Time      time.Time
	SessionID string
	ToolUseID string
	Tool      string
	URL       string // normalized on write
	Host      string // set on write
	Outcome   string
	Error     string // first 300 characters
	CCVersion string // Claude Code version
}

ToolCall is one web-reading tool call seen by the hook handler.

Jump to

Keyboard shortcuts

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