stats

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 9 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 stats turns events.db rows into the refetch stats report: how many web reads failed, how many refetch picked up and how many it resolved, and which step won.

Index

Constants

View Source
const InlineTool = "refetch:inline"

InlineTool is the tool name recorded for a page the hook fetched itself (mode = "inline"); it counts as a fetch_page call.

View Source
const PickupWindow = 10 * time.Minute

PickupWindow is how long after a failed read a fetch_page call for the same URL still counts as picking it up.

Variables

This section is empty.

Functions

func IsFetchPage

func IsFetchPage(tool string) bool

IsFetchPage reports whether a tool name is refetch's fetch_page, as a plugin (mcp__plugin_refetch_refetch__fetch_page) or added with claude mcp add (mcp__refetch__fetch_page), or an inline fetch by the hook.

Types

type Fetches

type Fetches struct {
	Total    int            `json:"total"`
	OK       int            `json:"ok"`
	OKBy     map[string]int `json:"ok_by,omitempty"`
	FailedBy map[string]int `json:"failed_by,omitempty"`
	MedianMS int64          `json:"median_ms"`
}

Fetches summarizes the attempts table by fetch: what fetch_page (and refetch get) did, whether or not a hook saw the call.

type Header struct {
	Version       string
	DataPath      string
	Bytes         int64
	Chrome        string // like "Chrome 155"; "" when none was found
	RenderTimeout string // like "15s"
}

Header is context outside the report data.

type Headless

type Headless struct {
	Needed        int   `json:"needed"`
	Ran           int   `json:"ran"`
	OK            int   `json:"ok"`
	TimedOut      int   `json:"timed_out"`
	Failed        int   `json:"failed"`
	SkippedByCall int   `json:"skipped_by_call"`
	SkippedOff    int   `json:"skipped_off"`
	NoChrome      int   `json:"no_chrome"`
	SkippedRoot   int   `json:"skipped_root"`
	MedianMS      int64 `json:"median_ms"` // of the runs
}

Headless counts the headless Chrome step: needed whenever the HTTP clients got a challenge or a JavaScript-only page, then either ran or was skipped.

type HostCount

type HostCount struct {
	Host string `json:"host"`
	N    int    `json:"n"`
}

HostCount is a host and how often it needed refetch.

type HostRow

type HostRow struct {
	Host     string `json:"host"`
	Reads    int    `json:"reads"`
	Failed   int    `json:"failed"`
	PickedUp int    `json:"picked_up"`
	Resolved int    `json:"resolved"`
	Fetches  int    `json:"fetches"`
}

HostRow is one host's funnel.

type Options

type Options struct {
	Since   time.Time
	Session string // only this Claude Code session
	ByHost  bool
}

Options filter the report.

type Report

type Report struct {
	From     time.Time `json:"from"`
	To       time.Time `json:"to"`
	Sessions int       `json:"sessions"`

	Reads       int            `json:"reads"`
	OKFirst     int            `json:"ok_first_time"`
	Failed      int            `json:"failed"`
	PickedUp    int            `json:"picked_up"`
	Resolved    int            `json:"resolved"`
	ResolvedBy  map[string]int `json:"resolved_by,omitempty"` // winning client
	StillFailed int            `json:"still_failed"`
	FailedWhy   map[string]int `json:"still_failed_by,omitempty"` // last attempt's outcome
	NotPickedUp int            `json:"not_picked_up"`
	Direct      int            `json:"direct_fetch_page"`
	DirectOK    int            `json:"direct_fetch_page_ok"`
	TopHosts    []HostCount    `json:"top_hosts,omitempty"` // hosts of picked-up reads

	HeadlessWins map[string]int `json:"headless_wins_by_trigger,omitempty"` // resolved by headless Chrome, by what sent the page there

	Fetches  Fetches   `json:"fetches"`         // every fetch_page and refetch get, from the attempts table
	Headless Headless  `json:"headless"`        // the headless Chrome step over all fetches
	Wayback  Wayback   `json:"wayback"`         // the Wayback Machine step over all fetches
	Hosts    []HostRow `json:"hosts,omitempty"` // filled for --by host
}

Report is the efficiency report. Counts are of web reads unless named otherwise.

func Build

func Build(calls []store.ToolCall, attempts []store.Attempt, opt Options, now time.Time) Report

Build computes the report from rows already filtered by time.

func (Report) WriteText

func (r Report) WriteText(w io.Writer, h Header)

WriteText writes the report as the plain-text table refetch stats prints.

type Wayback added in v0.4.0

type Wayback struct {
	Ran        int `json:"ran"`
	OK         int `json:"ok"`
	NoSnapshot int `json:"no_snapshot"`
	Failed     int `json:"failed"`
}

Wayback counts the Wayback Machine step, which runs after every live step failed.

Jump to

Keyboard shortcuts

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