Documentation
¶
Overview ¶
Package runview is a read-only, local web viewer for a journal's runs: a run list (RunList) with each run's kind and state, and one run's page: a plan flow's declared topology with the run's path drawn over it, or an agent run's timeline of model turns, tool calls, attempts, approvals and halts, with the audit verdict when a signed head or evidence package is given. The page of a run in progress, read from a store, follows the run as records land (see Follower). It never writes to the store it reads, and it serves on a loopback address only (see Listen). The bide view command (cmd/bide, its own module) is its front end.
Index ¶
- func Check(w io.Writer, c Config) bool
- func CheckDiff(w io.Writer, d Diff) (weakened bool, err error)
- func Handler(o Options) http.Handler
- func Listen(addr string) (net.Listener, error)
- func Main(args []string, stdout, stderr io.Writer, stores Stores) int
- type ApprovalCheck
- type Approvals
- type Change
- type Config
- type ConfigView
- type Conformance
- type Counts
- type Decision
- type Diff
- type DiffView
- type Event
- type Exports
- type Flow
- type Follower
- type Gate
- type Graph
- type GraphEdge
- type GraphNode
- type Halt
- type JournalSource
- func (s JournalSource) Grew(ctx context.Context, runID string, after int64) (bool, error)
- func (s JournalSource) History(ctx context.Context, runID string) ([]agent.Record, error)
- func (s JournalSource) HistorySeq(ctx context.Context, runID string) ([]agent.Record, []int64, error)
- func (s JournalSource) Runs(ctx context.Context) ([]string, error)
- type KindOption
- type ListFilter
- type LiveUpdate
- type Options
- type Proof
- type Prover
- type RiskSummary
- type RunList
- type RunRow
- type Source
- type StateOption
- type Stores
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶ added in v0.14.0
Check writes c's problems as "file:node: message" lines (the node, "from->to" for an edge or arm, or nothing for the config as a whole), warnings marked as such, then, when the config has assertions, a line counting their verdicts, and reports whether any problem is an error (or, with c.Strict, any problem at all). A violated, undecided or invalid assertion is an error.
func CheckDiff ¶ added in v0.15.0
CheckDiff writes the diff as text, for CI and a pull request comment: one line per change, a line per weakened approval gate, and a summary line with the counts and the digest, each prefixed with the new config's name. It reports whether an approval policy was weakened.
func Handler ¶
Handler serves the run list at / (as JSON at /runs.json; see RunList) and a run at /run?id=<run> (its View as JSON at /run.json?id=<run>, and, for a run in progress in a store, its live updates at /run/live?id=<run>&after=<cursor>). It answers only GET and HEAD, and only requests addressed to a loopback host, so a page on another site cannot read it through a rebound DNS name.
Types ¶
type ApprovalCheck ¶
ApprovalCheck is audit.VerifyApprovals' verdict on one gate, in words.
type Approvals ¶
type Approvals struct {
Keys agent.ApproverVerifierFor
Expected *agent.ApprovalPolicy
}
Approvals configures the approval-signature check a Prover runs: Keys resolves each approver's public key (nil: no check), and Expected, when set, is the policy the auditor expects, which the check runs against instead of the policy the gate's tally records.
type Change ¶ added in v0.15.0
type Change struct {
Change string `json:"change"` // added, removed or changed
What string `json:"what"` // node, edge, entry or flow
Node string `json:"node,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
// Details say what changed, one item each ("block charge -> refund", "approval 1 of 3 -> 2 of
// 3"); for an added or removed node, what it was.
Details []string `json:"details,omitempty"`
// Gate is how the node's approval gate changed: weakened (a set of decisions the new gate
// accepts would not have passed the old one: the gate was removed, its need lowered, or an
// approver added without raising the need to match), strengthened (the reverse, and not
// weakened), or reordered (the same approvers and need in another policy order). Empty when the
// gate did not change. A removed node's gate counts as removed.
Gate string `json:"gate,omitempty"`
}
Change is one difference between two flow definitions: a node, an edge or Switch arm, the entry, or the flow's name, added, removed or changed.
type Config ¶ added in v0.14.0
type Config struct {
Name string
Data []byte
Registry *plan.Registry
// Strict makes Check fail on a warning as well as on an error (bide view -check -strict).
Strict bool
}
Config is a flow definition to show instead of a run: its file name (for messages), its JSON bytes (a YAML file converted to JSON), and, when the program embeds the viewer, the plan.Registry its blocks, predicates and merges are registered in. With no Registry the check is structural (see plan.InspectConfig).
type ConfigView ¶ added in v0.14.0
type ConfigView struct {
Name string `json:"name"`
Flow string `json:"flow"`
Typed bool `json:"typed"`
Digest string `json:"digest,omitempty"`
Errors int `json:"errors"`
Warnings int `json:"warnings"`
Problems []plan.ConfigProblem `json:"problems,omitempty"`
Graph *Graph `json:"graph,omitempty"`
Approvals []string `json:"approvals,omitempty"`
CheckLabel string `json:"check"`
// Risk counts the nodes by crash behavior and gate, for the summary card.
Risk RiskSummary `json:"risk"`
// Assertions are the verdicts on the config's assert lines, in order.
Assertions []plan.AssertionResult `json:"assertions,omitempty"`
}
ConfigView is what the config page shows.
func BuildConfig ¶ added in v0.14.0
func BuildConfig(c Config) *ConfigView
BuildConfig checks c with plan.InspectConfig and lays out its declared graph, each problem marked on the node, edge or arm it belongs to.
type Conformance ¶
type Conformance struct {
OK bool `json:"ok"`
Method string `json:"method"` // "plan.Conform", or "structural" (see structural)
Source string `json:"source"` // where the topology came from
Diffs []string `json:"diffs,omitempty"`
Digest string `json:"digest"` // "match", "mismatch", or "not compared"
}
Conformance is the verdict on whether the run followed the declared topology.
type Counts ¶ added in v0.15.0
type Counts struct {
NodesAdded int `json:"nodes_added"`
NodesRemoved int `json:"nodes_removed"`
NodesChanged int `json:"nodes_changed"`
EdgesAdded int `json:"edges_added"`
EdgesRemoved int `json:"edges_removed"`
EdgesChanged int `json:"edges_changed"`
}
Counts are a diff's changes by kind.
type Decision ¶
type Decision struct {
Approver string `json:"approver,omitempty"` // empty for a one-decision gate's Approve
Approved bool `json:"approved"`
Signed bool `json:"signed"`
}
Decision is one recorded approval decision.
type Diff ¶ added in v0.15.0
type Diff struct {
Old, New Config
}
Diff is a flow definition compared with an earlier version of it: bide check -diff. Each side is read as BuildConfig reads a config (plan.InspectConfig), so with a Registry on both sides the page also shows the digest each side's runs journal.
type DiffView ¶ added in v0.15.0
type DiffView struct {
Name string `json:"name"`
OldName string `json:"old_name"`
Flow string `json:"flow"`
// Typed reports both sides were checked against a plan.Registry, so their digests are known
// (unless a side has errors).
Typed bool `json:"typed"`
OldDigest string `json:"old_digest,omitempty"`
NewDigest string `json:"new_digest,omitempty"`
Changes []Change `json:"changes"`
// Weakened and Strengthened name each node whose approval gate changed that way, with how:
// "charge: approval 2 of 3 -> 1 of 3".
Weakened []string `json:"weakened,omitempty"`
Strengthened []string `json:"strengthened,omitempty"`
Counts Counts `json:"counts"`
// OldErrors and NewErrors count each side's config errors (bide check lists them): a side
// with errors is compared as far as it reads.
OldErrors int `json:"old_errors"`
NewErrors int `json:"new_errors"`
Graph *Graph `json:"graph,omitempty"`
}
DiffView is what the diff page shows.
func BuildDiff ¶ added in v0.15.0
BuildDiff compares d.New with d.Old and draws the new flow with the old one's removed nodes and edges as ghosts. It fails only when a side cannot be read as a flow config at all.
func (*DiffView) DigestLine ¶ added in v0.15.0
DigestLine says how the digest changed, in words, for the text summary and the page.
type Event ¶
type Event struct {
Seq int `json:"seq"` // 1-based position in the journal
Name string `json:"name"` // the record's journal name
Kind string `json:"kind"` // agent.StepKind
Class string `json:"class"` // the row's style: model, tool, attempt, approval, halt, end, value
Title string `json:"title"`
Detail string `json:"detail,omitempty"`
Badges []string `json:"badges,omitempty"`
}
Event is one journal record, as a timeline row.
type Exports ¶
Exports is a Source over exported journals (audit.JournalExport), by run ID.
type Flow ¶
type Flow struct {
Topology plan.Topology
// Digest is flow.Digest(), compared with the digest the run journaled. Empty: not compared.
Digest string
// Conform is flow.Conform. Nil: the viewer runs only its structural check (see Conformance).
// Source says where the topology came from, as the page shows it.
Conform func(ctx context.Context, j *agent.Journal, runID string) (bool, []string, error)
Source string
}
Flow is a declared flow the viewer draws a run against. The journal records a flow run's name and topology digest, not its topology, so the topology comes from the caller: a program that holds the *plan.Flow passes its Topology, Digest and Conform; the bide view command reads a Topology exported as JSON (json.Marshal(flow.Topology())) and, optionally, the digest.
type Follower ¶ added in v0.15.0
type Follower interface {
// Grew reports whether runID has a record after the store sequence after (agent.Entry.Seq).
// It is the read live mode polls, so it is cheap: one Load from after, stopped at its first entry.
Grew(ctx context.Context, runID string, after int64) (bool, error)
// HistorySeq is History with each record's store sequence, both read in one pass.
HistorySeq(ctx context.Context, runID string) ([]agent.Record, []int64, error)
}
Follower is a Source whose runs can grow while the viewer reads them: a store, not an export. JournalSource is one.
type Gate ¶
type Gate struct {
ToolUseID string `json:"tool_use_id"`
ToolName string `json:"tool_name,omitempty"`
Single bool `json:"single,omitempty"` // a one-decision gate (agent.Approve)
Need int `json:"need,omitempty"`
Approvers []string `json:"approvers,omitempty"`
ApprovedBy []string `json:"approved_by,omitempty"`
DeniedBy []string `json:"denied_by,omitempty"`
Pending []string `json:"pending,omitempty"`
Decisions []Decision `json:"decisions,omitempty"`
Tallied bool `json:"tallied"` // the gate journaled its terminal tally
// Waiting: the run paused at this gate (its approval-pending record, agent.ApprovalWait) and
// the call has no result, no terminal tally, and (for a one-decision gate) no decision yet.
Waiting bool `json:"waiting"`
// Signatures is whether the gate's approver signatures were verified (audit.VerifyApprovals,
// with -approver-keys), or why they were not checked; SignaturesOK reports a verified gate.
Signatures string `json:"signatures"`
SignaturesOK bool `json:"signatures_ok"`
Status string `json:"status"`
}
Gate is a tool call's or a plan flow node's approval gate, from the decisions and tally the journal holds. A flow node's ToolUseID is its key ("node:<name>", "node:iter:<n>:<name>").
type Graph ¶
type Graph struct {
Nodes []GraphNode `json:"nodes"`
Edges []GraphEdge `json:"edges"`
SVG string `json:"-"`
Mermaid string `json:"mermaid"`
Width int `json:"-"`
Height int `json:"-"`
// contains filtered or unexported fields
}
Graph is the declared topology with the run's path overlaid.
type GraphEdge ¶
type GraphEdge struct {
From string `json:"from"`
To string `json:"to"`
Label string `json:"label,omitempty"`
Taken bool `json:"taken"`
Back bool `json:"back,omitempty"`
Problem string `json:"problem,omitempty"` // a config problem at this edge or arm
Cex bool `json:"cex,omitempty"` // on a violated assertion's counterexample path
// Change is how a flow diff changed this edge or arm (added, removed or changed), which
// styles it; empty outside a diff.
Change string `json:"change,omitempty"`
}
GraphEdge is one declared edge or Switch arm, and whether the run took it.
type GraphNode ¶
type GraphNode struct {
Name string `json:"name"`
Kind string `json:"kind"`
Status string `json:"status"` // done, halted, attempted, waiting (at its approval gate), not-reached
// Gate is the node's declared approval gate ("2 of 3", "one decision"), empty for none, and
// GateStatus where its latest evaluation stands (see Gate.Status).
Gate string `json:"gate,omitempty"`
GateStatus string `json:"gate_status,omitempty"`
// GateLine and SigLine are what the node's box says about its gate, short enough to read in
// a screenshot: "approved 2 of 3" or "waiting, 1 of 2 approvals", and "signatures verified" (or
// not, and why in short). GateClass styles them: good, wait or bad.
GateLine string `json:"gate_line,omitempty"`
SigLine string `json:"sig_line,omitempty"`
GateClass string `json:"gate_class,omitempty"`
Iters int `json:"iters,omitempty"`
Last bool `json:"last,omitempty"`
Note string `json:"note,omitempty"` // a line under the box
Title string `json:"title,omitempty"` // the tooltip, when not "name: status"
// Risk is a config node's safety class ("side effect", "read-only", "idempotent", "safety
// unknown") and Crash its crash behavior in a few words; empty on a run's graph. Cex marks a
// node on a violated assertion's counterexample path.
Risk string `json:"risk,omitempty"`
Crash string `json:"crash,omitempty"`
Cex bool `json:"cex,omitempty"`
// contains filtered or unexported fields
}
GraphNode is one declared node and what the run did with it.
type Halt ¶
type Halt struct {
Op string `json:"op"` // "tool" or "step"
ID string `json:"id"` // the tool-use ID, or the step name ("node:<name>" for a plan node)
ToolName string `json:"tool_name,omitempty"`
Marker string `json:"marker"`
AttemptedAt time.Time `json:"attempted_at,omitzero"`
Ref string `json:"ref"` // the agent.HaltRef to resolve it with, as Go
}
Halt is an operation whose attempt marker is live with no result: a resume of the run returns *agent.OutcomeUnknown for it until agent.ResolveHalt records its outcome.
type JournalSource ¶
JournalSource reads a store through a Journal. Runs lists through the store's agent.Lister, when it has one.
func (JournalSource) HistorySeq ¶ added in v0.15.0
func (s JournalSource) HistorySeq(ctx context.Context, runID string) ([]agent.Record, []int64, error)
HistorySeq implements Follower. It reads the run through a Journal over the same store, so each record is decoded and checked as History does, and keeps the Seq of each entry the store yields.
type KindOption ¶ added in v0.15.0
KindOption is one of the kind filter's options.
type ListFilter ¶ added in v0.15.0
type ListFilter struct {
State string `json:"state,omitempty"`
Kind string `json:"kind,omitempty"`
Q string `json:"q,omitempty"`
Limit int `json:"limit"`
}
ListFilter is what the run list shows: the runs in a state group and of a kind, whose ID contains Q (ignoring case), at most Limit of them. Empty fields admit every run.
type LiveUpdate ¶ added in v0.15.0
type LiveUpdate struct {
Changed bool `json:"changed"`
// Live: the run has no end marker yet, so the page polls again; false once it has one.
Live bool `json:"live"`
// Cursor is the store sequence of the run's last record: the after of the next poll.
Cursor int64 `json:"cursor"`
State string `json:"state,omitempty"`
StateText string `json:"state_text,omitempty"`
Events []Event `json:"events,omitempty"` // the rows of the records after the cursor given, only
}
LiveUpdate is GET /run/live's answer: whether the run has records after the cursor the page gave, and, when it has, the timeline rows of those records and the run's state now.
type Options ¶
type Options struct {
Source Source
// Flows are the declared flows runs are drawn against, by flow name.
Flows map[string]*Flow
// Provers check runs against audit artifacts; the first to return a verdict for a run wins.
Provers []Prover
// Config, when set, makes the handler show this flow definition instead of runs: the page at /
// and its view as JSON at /config.json. Source is then not read.
Config *Config
// Diff, when set, makes the handler show a flow definition compared with an earlier one
// instead of runs: the page at / and its view as JSON at /diff.json (see BuildDiff).
Diff *Diff
}
Options configure Handler.
type Proof ¶
type Proof struct {
Source string `json:"source"` // "signed tree head" or "evidence package"
OK bool `json:"ok"`
Summary string `json:"summary"`
Covers int `json:"covers"` // journal records the signed head commits to
Problems []string `json:"problems,omitempty"`
Items []string `json:"items,omitempty"`
// Approvals is the signature verdict on each m-of-n gate that journaled its tally, by
// tool-use ID: audit.VerifyApprovals over the gate's evidence, with the approver keys given.
// Nil without approver keys.
Approvals map[string]ApprovalCheck `json:"approvals,omitempty"`
}
Proof is the audit verdict on the run's journal, from the audit package's own verifiers (the code bide audit verify and verify-evidence run), never a reimplementation.
type Prover ¶
Prover checks a run's records against an audit artifact. It returns nil for a run the artifact is not about.
func EvidenceProver ¶
func EvidenceProver(pkg audit.EvidencePackage, v audit.Verifier, ap Approvals, opts ...audit.EvidenceVerifyOption) Prover
EvidenceProver checks an evidence package (audit.EvidencePackage.Verify, as bide audit verify-evidence does) and that its signed head commits to the journal shown.
With approver keys (ap.Keys non-nil), it also checks each m-of-n gate's signatures with audit.VerifyApprovals over the package's actions, as bide audit verify-approvals does.
func HeadProver ¶
HeadProver checks a signed tree head: its signature under v and the timestamp rule (audit.CheckTimestamp), and that its root commits to the first sth.Size records of the journal shown, by building and verifying an inclusion proof of the last of them (audit.ProveRecord, ProofBundle.Verify), as bide audit prove and verify do.
With approver keys (ap.Keys non-nil), it also checks each m-of-n gate's signatures: it builds the gate's evidence from the journal under sth (audit.ApprovalEvidence) and verifies it with audit.VerifyApprovals, as bide audit verify-approvals does.
type RiskSummary ¶ added in v0.15.0
type RiskSummary struct {
SideEffects int `json:"side_effects"`
Gated int `json:"gated"`
Ungated int `json:"ungated"`
ReadOnly int `json:"read_only"`
Idempotent int `json:"idempotent"`
Unknown int `json:"unknown"`
// Line is the headline, as "3 side-effect steps, 2 gated, 1 ungated" ("steps known" when a
// class is unknown).
Line string `json:"line"`
// UnknownLine says why some classes are unknown, empty when none is.
UnknownLine string `json:"unknown_line,omitempty"`
}
RiskSummary counts a config's nodes by safety class: side effects (gated, when every path to one passes an approval gate, and ungated), read-only, idempotent, and unknown (the structural check cannot see a block's registered Safety).
type RunList ¶ added in v0.15.0
type RunList struct {
Filter ListFilter `json:"filter"`
Rows []RunRow `json:"runs"`
// Matched is how many runs the filter admits; Rows holds the first Filter.Limit of them.
Matched int `json:"matched"`
// Summarized is how many runs were read; Listed how many the source lists. They differ when
// more than maxSummarized runs match the ID filter.
Summarized int `json:"summarized"`
Listed int `json:"listed"`
Kinds []string `json:"kinds"` // the kinds of the runs read, for the kind filter
// Counts are the runs of each state group the ID and kind filters admit, and All their sum:
// the state filter's counts.
Counts map[string]int `json:"counts"`
All int `json:"all"`
More string `json:"more,omitempty"` // the page with listPage more rows, when there are more
Notes []string `json:"notes,omitempty"`
Err string `json:"error,omitempty"`
}
RunList is the run list page: the runs the filter admits, newest first by start time, then the runs that record none by run ID.
func (RunList) KindOptions ¶ added in v0.15.0
func (l RunList) KindOptions() []KindOption
KindOptions are the kind filter's options: the kinds of the runs read, and the chosen one.
func (RunList) States ¶ added in v0.15.0
func (l RunList) States() []StateOption
States are the state filter's options: every run, then each state group that has a run or is chosen.
type RunRow ¶ added in v0.15.0
type RunRow struct {
ID string `json:"run_id"`
Kind string `json:"kind"` // agent.RunKind, or "" when the run has no run:start
State string `json:"state"` // the View state (see Build)
StateText string `json:"state_text"`
Group string `json:"group"` // the state filter group
Flow string `json:"flow,omitempty"`
Records int `json:"records"`
// Started is when the run's first drive started, as its run:start records it
// (agent.RunStart.Started). Zero for a run journaled by a version that recorded none.
Started time.Time `json:"started,omitzero"`
}
RunRow is one run as the run list shows it.
func (RunRow) StartedText ¶ added in v0.15.0
StartedText is Started as the list shows it, or "" when the run records no start time.
type Source ¶
type Source interface {
Runs(ctx context.Context) ([]string, error)
History(ctx context.Context, runID string) ([]agent.Record, error)
}
Source is what the viewer reads: the runs it lists and each run's records. Both are reads.
type StateOption ¶ added in v0.15.0
type StateOption struct {
Value, Label string
Count int
Link string // the list with this option chosen, the other filters kept
On bool // the option is the filter's
}
StateOption is one of the state filter's options.
type Stores ¶
type Stores struct {
SQLite func(path string) (agent.Store, io.Closer, error)
Postgres func(dsn string) (agent.Store, io.Closer, error)
// YAML converts a YAML flow config to the JSON plan reads; nil means this build reads JSON
// configs only.
YAML func(data []byte) ([]byte, error)
}
Stores opens the stores bide view reads, read-only. It is how the command plugs in store backends (store/sqlite's and store/postgres's OpenReadOnly) without the core module importing one. A nil opener means this build cannot read that kind of store.
type View ¶
type View struct {
RunID string `json:"run_id"`
Kind string `json:"kind"` // agent.RunKind, or "" when the run has no run:start
Input string `json:"input,omitempty"`
Flow string `json:"flow,omitempty"` // the flow name run:start records
Digest string `json:"digest,omitempty"` // the topology digest flow:digest records
// State is the agent.RunState, except "halted" for a started run with a live attempt marker
// and no result (see Halts): a resume returns *agent.OutcomeUnknown, so it is not in progress.
State string `json:"state"`
StateText string `json:"state_text"` // State as the page shows it ("halted: outcome unknown")
Terminal string `json:"terminal,omitempty"`
Records int `json:"records"`
Events []Event `json:"events"`
Halts []Halt `json:"halts,omitempty"`
Gates []Gate `json:"gates,omitempty"`
Graph *Graph `json:"graph,omitempty"`
Conform *Conformance `json:"conformance,omitempty"`
Proof *Proof `json:"proof,omitempty"`
Notes []string `json:"notes,omitempty"` // what the page cannot show for this run, and why
LastNode string `json:"last_node,omitempty"`
FinalText string `json:"final_text,omitempty"`
// Live: the page follows the run (live mode): it was read from a store, not an export, and has
// no end marker. Cursor is the store sequence (agent.Entry.Seq) of its last record.
Live bool `json:"live,omitempty"`
Cursor int64 `json:"cursor,omitempty"`
}
View is everything the run page shows, built from the run's records alone (see Build).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package runlistdemo writes a journal of runs in every state the bide view run list tells apart: completed, halted (outcome unknown), waiting for approval, in progress, aborted and cancelled, agent runs and plan flow runs, and one run journaled as a version that recorded no start time.
|
Package runlistdemo writes a journal of runs in every state the bide view run list tells apart: completed, halted (outcome unknown), waiting for approval, in progress, aborted and cancelled, agent runs and plan flow runs, and one run journaled as a version that recorded no start time. |