Help us shape the future of Go! Take the 2026 Go Developer Survey

observer

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package observer turns a failed or blocked skill-workflow run into one concrete, reviewable artifact: a proposed project rule (see internal/ratchet) with a ready-to-run `tinyagent ratchet add` command. It also keeps a ledger of failure signatures so a failure that recurs after a proposal exists is flagged: the gate did not hold.

The observer is deterministic (no model call) and never applies a rule itself; a person runs the printed command.

Index

Constants

View Source
const MaxExcerpt = 2000

MaxExcerpt caps the stored check output excerpt, in bytes.

Variables

This section is empty.

Functions

func Dir

func Dir(root string) string

Dir is the observer directory under the project root.

func LedgerPath

func LedgerPath(root string) string

LedgerPath is the ledger file under the project root.

func LoadLedger

func LoadLedger(path string) (map[string]Entry, []string)

LoadLedger reads the ledger: the latest entry per signature. A corrupt line is skipped and reported, never fatal.

func Normalize

func Normalize(s string) string

Normalize strips the parts of a line that change between runs of the same failure: paths, hashes, numbers and durations.

func ProposalsPath

func ProposalsPath(root string) string

ProposalsPath is the proposals file under the project root.

func Signature

func Signature(res *harness.Result) string

Signature identifies a failure across runs: sha256 of the failed stage, the check argv and the normalized first failing line of the check output (the reason when there is no output).

Types

type Entry

type Entry struct {
	Signature  string `json:"signature"`
	Stage      string `json:"stage"`
	FirstSeen  string `json:"first_seen"`
	LastSeen   string `json:"last_seen"`
	Count      int    `json:"count"`
	ArtifactID string `json:"artifact_id"`
}

Entry is one ledger line. The latest line for a signature is its state.

type Observation

type Observation struct {
	// Observed is false for a passed or interrupted run: nothing written.
	Observed bool
	Proposal *Proposal // set on the first occurrence of a signature
	Entry    Entry
	// Recurrence is set when the signature was already in the ledger.
	Recurrence bool
	// RuleID is the applied ratchet rule for this signature, if any.
	RuleID string
	// Warnings are non-fatal problems, such as a corrupt ledger.
	Warnings []string
}

Observation is what Observe did for one run.

func Observe

func Observe(res *harness.Result, root string, redact func(string) string, now time.Time) (Observation, error)

Observe records a failed or blocked run under root/.tinyagent/observer: a new signature gets one proposal and a ledger entry; a known signature bumps its count and is reported as a recurrence. Passed and interrupted runs are not observed. An error means a file couldn't be written; the caller should warn, not fail the run.

type Proposal

type Proposal struct {
	ID        string   `json:"id"`
	Signature string   `json:"signature"`
	Created   string   `json:"created"`
	Workflow  string   `json:"workflow"`
	Status    string   `json:"status"`
	Stage     string   `json:"stage"`
	Reason    string   `json:"reason,omitempty"`
	Method    string   `json:"check_method,omitempty"`
	Argv      []string `json:"check_argv,omitempty"`
	Excerpt   string   `json:"check_output_excerpt,omitempty"`
	Rule      string   `json:"rule"`
	Incident  string   `json:"incident"`
	Command   string   `json:"suggested_command"`
}

Proposal is one proposed project rule distilled from a failed run.

func Propose

func Propose(res *harness.Result, root string, redact func(string) string, now time.Time) Proposal

Propose builds the proposal for a failed run. redact masks secrets in stored text; nil stores it as is.

Jump to

Keyboard shortcuts

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