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
- Variables
- func Attribute(body string) string
- func Build(in Input) *model.Guardrails
- func Exec(ctx context.Context, memDir string) ([]byte, error)
- func MemoryDir(given, claudeDir string) string
- func Named(text string) []string
- func Refusal(text string, isError bool) (body string, ok bool)
- type Count
- type Input
- type Lesson
- type Recurrence
- type Runner
- type Source
Constants ¶
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.
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 )
const MinInterval = 10 * time.Minute
MinInterval is how seldom recur is run: its answer is a reading of memory files.
Variables ¶
var Gates = []string{GuardBash, Replystamp, Agentsync, Recur, Mutsweep, Modtidy, Modelgate, Ctxgate, Ghbyhand, Paritychk, Prbody, Quotaclaim, Other}
Gates lists every gate in the stack order of the chart; Other is last.
Functions ¶
func Exec ¶
Exec is the Runner that runs the recur binary on PATH, with fixed arguments and no shell, under a timeout.
func MemoryDir ¶
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 ¶
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".
Types ¶
type Count ¶
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 ¶
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".