Documentation
¶
Overview ¶
Package decisionlog records every decision a person, a policy or a witness check made about an agent's work, and how long the thing waited for it (docs/decision-log.md). Lectern already receives the hooks for all of these (agent events, approvals, Review actions); this package only writes them down, so the history exists to be studied. It adds no service and no UI: rows stay in Lectern's own database and are read through /api/decisions.
What is recorded is structure, never content: a decision's kind, its value, how it arrived, timings, and small counts. No prompt, command or message text is stored, only lengths, tool names and numbers.
Index ¶
- Constants
- Variables
- func Bucket(active int) string
- func Enabled() bool
- func Percentile(vals []float64, p float64) *float64
- func Record(db *store.DB, d store.Decision) error
- func RecordApproval(db *store.DB, row *store.Approval) error
- func ViaFor(decidedBy string) string
- type BucketStats
- type KindSummary
- type LatencyStats
- type Recorder
- type Summary
Constants ¶
const ( KindApproval = "approval" KindTurnResponse = "turn_response" KindInterrupt = "interrupt" KindPermissionPrompt = "permission_prompt" KindReviewCommit = "review_commit" KindReviewPush = "review_push" KindReviewCommentsSent = "review_comments_sent" KindReviewDiscard = "review_discard" KindTaskReview = "task_review" )
The values of decisions.kind.
const ( ViaWeb = "web" ViaPhone = "phone" ViaTerminal = "terminal" ViaPolicy = "policy" ViaWitness = "witness" ViaInferred = "inferred" ViaAPI = "api" ViaSystem = "system" )
The values of decisions.via.
const EnvVar = "LECTERN_DECISION_LOG"
EnvVar is the off switch. Anything but 0, false or off leaves recording on.
Variables ¶
var Buckets = []string{"1", "2", "3-4", "5-7", "8+"}
Buckets are the active-session counts the latency table is split by, in display order. They follow how many agents one person can supervise at once: a single session, a pair, a small group, a busy board, and more.
Functions ¶
func Bucket ¶
Bucket names the active-session bucket a count falls into. A count below one has no bucket: no live session means there was no supervision load to measure.
func Enabled ¶
func Enabled() bool
Enabled reports whether decisions are recorded. It is read on every call, so a test can flip the switch with t.Setenv.
func Percentile ¶
Percentile is the nearest-rank p-th percentile (0 < p <= 1) of vals, or nil when there are none. Nearest rank is used rather than interpolation so every reported value is a latency that actually happened.
func Record ¶
Record writes one decision. It fills in the live session and pending counts at this moment, because those are what the decision was made under. A disabled log writes nothing and returns nil.
func RecordApproval ¶
RecordApproval records a broker decision that has been applied: the row is the approval as it now stands, with its final status. It is called from the broker's OnDecided callback, so the broker never imports this package.
Types ¶
type BucketStats ¶
type BucketStats struct {
Bucket string `json:"bucket"`
N int `json:"n"`
P50 *float64 `json:"p50"`
}
BucketStats is the latency median for one active-session bucket. N counts the decisions in the bucket that had a latency.
type KindSummary ¶
type KindSummary struct {
Kind string `json:"kind"`
Count int `json:"count"`
Decisions map[string]int `json:"decisions"`
Latency LatencyStats `json:"latency_s"`
ByActiveSession []BucketStats `json:"by_active_sessions"`
}
KindSummary is one decision kind over the window.
type LatencyStats ¶
LatencyStats is a latency distribution: how many decisions had one, and its median and 90th percentile in seconds.
type Recorder ¶
Recorder turns hook events into decisions. It is an events.OnHookEvent subscriber: the state machine runs under a short lock on the hook path, and each database write runs in its own goroutine, so a hook never waits on SQLite. The state is per session and lives in memory; a restart forgets a pending wait, which costs one decision, never a wrong one.
func (*Recorder) HandleHookEvent ¶
func (r *Recorder) HandleHookEvent(sess *store.Session, event string, body []byte, state string, changed bool)
HandleHookEvent is the events.OnHookEvent subscriber. It returns at once. Events the recorder does not read are ignored.
func (*Recorder) RecordReview ¶
func (r *Recorder) RecordReview(sessionID int64, agent, kind, decision string, detail map[string]any)
RecordReview records a Review action (commit, push, comments sent, discard, or a task review). Latency is measured from the session's last Stop when one is known: that is when the agent stopped and the person started looking. A task review has no session, so its latency is null.
type Summary ¶
type Summary struct {
Days int `json:"days"`
Kinds []KindSummary `json:"kinds"`
}
Summary is the response of /api/decisions/summary.