guard

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 13 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 guard is the Guardrails tab's data: which gates refused what, and whether the lessons that became gates stopped recurring.

A gate refusal is a tool result the hook runner turned into an error: its text starts with "<Event>:<Tool> hook error: " (or is the hook's own deny JSON). The attribution table below was built from the real refusals of a week of transcripts; a refusal that matches no row is "other gate", counted and shown, never dropped.

Index

Constants

View Source
const (
	GuardBash  = "guard-bash"
	Replystamp = "replystamp"
	Agentsync  = "agentsync gate"
	Recur      = "recur"
	Mutsweep   = "mutsweep"
	Modtidy    = "modtidy"
	Modelgate  = "modelgate"
	Ctxgate    = "ctxgate"
	Ghbyhand   = "ghbyhand"
	Paritychk  = "paritycheck"
	Prbody     = "prbody"
	Quotaclaim = "quotaclaim"
	Other      = "other gate"
)

The gates a refusal is attributed to. Other holds what no rule recognises.

View Source
const (
	// Weeks is how many weeks the trend charts show.
	Weeks = 12
	// SilentWeeks is how long a landed gate must have made no refusal, nor seen a
	// recurrence, to be flagged silent.
	SilentWeeks = 4
)
View Source
const MinInterval = 10 * time.Minute

MinInterval is how seldom recur is run: its answer is a reading of memory files.

Variables

Gates lists every gate in the stack order of the chart; Other is last.

Functions

func Attribute

func Attribute(body string) string

Attribute names the gate that wrote a refusal body.

func Build

func Build(in Input) *model.Guardrails

Build assembles the tab's data.

func Exec

func Exec(ctx context.Context, memDir string) ([]byte, error)

Exec is the Runner that runs the recur binary on PATH, with fixed arguments and no shell, under a timeout.

func MemoryDir

func MemoryDir(given, claudeDir string) string

MemoryDir finds the memory directory to read: the one given, else the one under claudeDir/projects whose recur ledger was written last. "" when there is none.

func Named

func Named(text string) []string

Named lists the gates a ledger text names (a lesson's gate is written in words: "replystamp --pretool", "mutsweep -hook"), so a lesson's refusals can be found. "recur" and "agentsync" alone name too many other things to count: they need their flag, "recur --hook" or "agentsync gate".

func Refusal

func Refusal(text string, isError bool) (body string, ok bool)

Refusal reports whether a tool result's text is a gate refusal, and its body: the text after the hook prefix. Only a result the runner marked as an error, whose text STARTS like a refusal, is one: a file or a log that merely mentions a hook is not.

Types

type Count

type Count struct {
	Hour int64
	Gate string
	N    int64
}

Count is the refusals of one gate in one hour: Hour is the Unix second the hour starts at.

type Input

type Input struct {
	Now time.Time
	// Rec is what recur answered; RecErr is why it could not be read, "" when it
	// could (and then Rec is its answer, however empty). A value and not a
	// pointer: there is no nil to forget.
	Rec    Recurrence
	RecErr string
	// Refusals are the refusals the transcripts hold; Scanned is whether they were
	// scanned at all (false: not measured, which is not zero).
	Refusals []Count
	Scanned  bool
}

Input is what Build needs.

type Lesson

type Lesson struct {
	Name        string `json:"name"`
	Recurrences []struct {
		Date         *string `json:"date"`
		YearInferred bool    `json:"yearInferred"`
		Line         string  `json:"line"`
	} `json:"recurrences"`
	Ledger struct {
		Decision  string  `json:"decision"`
		Text      string  `json:"text"`
		WrittenAt *string `json:"writtenAt"`
	} `json:"ledger"`
}

Lesson is one memory with its recurrences and ledger entry.

type Recurrence

type Recurrence struct {
	Lessons []Lesson `json:"lessons"`
	Totals  struct {
		Lessons    int `json:"lessons"`
		Unreadable int `json:"unreadable"`
	} `json:"totals"`
}

Recurrence is `recur --memory <dir> --json`: the lessons that recorded a recurrence, what the ledger decided about each, and the totals. Only the fields the tab shows are decoded.

func Parse

func Parse(b []byte) (Recurrence, error)

Parse decodes recur's JSON; it refuses what has no "lessons" key, so an answer that is not recur's (an error page, a usage text) is a failure and not an empty list.

type Runner

type Runner func(ctx context.Context, memDir string) ([]byte, error)

Runner runs recur on a memory directory and returns its standard output. A non-zero exit status is not an error here when the output parses: recur exits 1 to report an unaccounted recurrence, and that is an answer.

type Source

type Source struct {
	Dir string // "" means no memory directory could be found
	Run Runner
	// contains filtered or unexported fields
}

Source reads recur at most every MinInterval and keeps the last answer. A failure is kept as the reason, never as an empty answer, so the tab says "not measured" and not "0".

func (*Source) Get

func (s *Source) Get(ctx context.Context, now time.Time) (rec Recurrence, err string)

Get is the last answer, running recur first when it has not been read for MinInterval. err is "" when rec is the answer; otherwise rec is empty and err says why, so nothing shows an old answer as current.

Jump to

Keyboard shortcuts

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