decisionlog

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 Imported by: 0 modules, 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 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

View Source
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.

View Source
const (
	ViaWeb      = "web"
	ViaPhone    = "phone"
	ViaTerminal = "terminal"
	ViaPolicy   = "policy"
	ViaWitness  = "witness"
	ViaInferred = "inferred"
	ViaAPI      = "api"
	ViaSystem   = "system"
)

The values of decisions.via.

View Source
const EnvVar = "LECTERN_DECISION_LOG"

EnvVar is the off switch. Anything but 0, false or off leaves recording on.

Variables

View Source
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

func Bucket(active int) string

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

func Percentile(vals []float64, p float64) *float64

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

func Record(db *store.DB, d store.Decision) error

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

func RecordApproval(db *store.DB, row *store.Approval) error

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.

func ViaFor

func ViaFor(decidedBy string) string

ViaFor maps an approval's decided_by to a decision's via. The broker does not know whether a web click or a phone tap sent a "user" decision, so both land as web; the phone case is documented in docs/decision-log.md.

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

type LatencyStats struct {
	N   int      `json:"n"`
	P50 *float64 `json:"p50"`
	P90 *float64 `json:"p90"`
}

LatencyStats is a latency distribution: how many decisions had one, and its median and 90th percentile in seconds.

type Recorder

type Recorder struct {
	DB *store.DB
	// contains filtered or unexported fields
}

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 New

func New(db *store.DB) *Recorder

New builds a Recorder over db.

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.

func (*Recorder) Wait

func (r *Recorder) Wait()

Wait blocks until every queued write has finished. Tests use it; the server never needs to.

type Summary

type Summary struct {
	Days  int           `json:"days"`
	Kinds []KindSummary `json:"kinds"`
}

Summary is the response of /api/decisions/summary.

func Summarize

func Summarize(rows []*store.Decision, days int) Summary

Summarize groups decisions by kind, in kind-name order. The rows are whatever the caller fetched for the window; Summarize does no filtering of its own.

Jump to

Keyboard shortcuts

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