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

inspect

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package inspect computes the record-detail panes: what the session says about one entry (its response and whether the request checks out, a call's decisions and dispatch, a compaction's fold) and about the session as a whole (its header, its verification, its configuration, its refs, its memory manifest).

It works on a snapshot of the session read from the record, never on the follower's session, and it is meant to be called off the UI's goroutine and only for what the user selects. A response's verification is cached for good (a response entry and the path behind it never change), and a snapshot is reused while the session holds no more entries than it did.

The records other products write beside the loop's are decoded here from their JSON, so the client depends on none of them: the policy verdicts of agentpolicy ("agentpolicy:verdict"), the skill grants agentkit makes of them, and agentmemory's manifest ("agentmemory:render"). A record that does not decode is left out of the pane, not an error.

Index

Constants

View Source
const SkillSourcePrefix = "agentskill:"

SkillSourcePrefix opens the source name of a rule granted by a skill (agentkit names its sources "agentskill:" and the skill's listed name).

View Source
const VerdictNS = "agentpolicy:verdict"

VerdictNS is where agentpolicy records a verdict, and the shape it writes (agentpolicy v0.0.11, record.go); the member names are the format's.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	CallID string
	Name   string
	Args   string
	// State is the path's reading of the call (agentsession's CallState).
	State string
	// Decisions are the decision entries for the call, in order: each the
	// verdict, who gave it and why.
	Decisions []Decision
	// Verdicts are the policy verdicts recorded for the call
	// (agentpolicy:verdict): the rule and the source behind a decision.
	Verdicts []Verdict
	// Asked are the questions put to the user about the call, and what
	// became of them.
	Asked []session.Elicitation
	// Dispatch is the dispatch entry, when the call was handed to its tool.
	Dispatch *Dispatch
	// Callees are the call's subsession and peer links on the path, in
	// order, with what became of each.
	Callees []Callee
	// Output is what the call returned, and OutputEntry the entry that
	// holds it; HasOutput says whether there is one.
	Output      string
	OutputEntry string
	HasOutput   bool
	// Grants are the skill grants in force when the call was made, and
	// whether and when they were revoked later.
	Grants []Grant
}

Call is a function call as the path holds it.

type Callee added in v0.0.13

type Callee struct {
	Entry   string
	Rel     string
	Session string
	// URL, Task and Context name a callee in another system.
	URL     string
	Task    string
	Context string
	// Dispatch is the dispatch the link belongs to, "" when the path
	// records none.
	Dispatch string
	// CancelSent says a cancel notice names the link: the caller asked
	// the callee to stop and did not wait.
	CancelSent bool
	// Answered says the call's output came from this callee.
	Answered bool
}

Callee is a subsession or peer link of a call, as agentsession's Callees reads it.

type Config

type Config struct {
	Model string
	// InstructionsParts is the number of parts the instructions are
	// built from, and InstructionsLen their length in runes.
	InstructionsParts int
	InstructionsLen   int
	Tools             int
	// Known is false when the context at the end of the line could not be
	// built, with Err saying why.
	Known bool
	Err   string
}

Config is the settings in force at the end of the line.

type Decision

type Decision struct {
	Entry   string
	Verdict string
	By      string
	Reason  string
	Args    string
}

Decision is a decision entry.

type Dispatch

type Dispatch struct {
	Entry          string
	Target         string
	IdempotencyKey string
	Time           time.Time
}

Dispatch is a dispatch entry.

type Entry

type Entry struct {
	ID   string
	Type string
	Time time.Time
	// Title says what the entry is: "agent message", "function call
	// upper", "compaction".
	Title string
	// KeptFromModel is set for an item the filter kept out of the
	// model's context.
	KeptFromModel bool
	// Response is the response the entry's item belongs to, when it has
	// one.
	Response *Response
	// Call is set for a function call and for its output.
	Call *Call
	// Fold is set for a compaction.
	Fold *Fold
}

Entry is what the session says about one entry of the viewed line.

func (Entry) Lines

func (e Entry) Lines() []string

Lines renders the entry's detail as plain lines: a heading, then "label: value" lines and indented lists.

type Fold

type Fold struct {
	// FirstKept is the entry the context keeps from, described.
	FirstKept     string
	FirstKeptDesc string
	// Folded is how many items sit on the path before FirstKept: the ones
	// the summary stands for in the model's request. They stay on the
	// record.
	Folded int
	// SummaryLen is the summary's length in runes, and SummaryType the
	// item type that carries it.
	SummaryLen   int
	SummaryType  string
	SummaryStart string
	// Pinned describes the items carried over whole.
	Pinned       []string
	TokensBefore int
	Usage        *openresponses.Usage
	// Call is the model call the fold made, when the compaction records one.
	Call *session.FoldCall
}

Fold is what a compaction entry folded.

type Grant

type Grant struct {
	// Skill is the skill's listed name, Source the source the rule was
	// granted under.
	Skill  string
	Source string
	Rule   string
	// Since is the verdict entry that recorded the grant.
	Since string
	// Ended is the verdict entry that revoked the source's grants, "" while
	// they hold on the whole path.
	Ended string
}

Grant is a rule a skill's read granted, and what became of it.

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

Inspector computes detail for one source, and caches what is costly. It is safe for concurrent use.

func New

func New(src Source, opts ...Option) *Inspector

New returns an inspector over src.

func (*Inspector) Entry

func (in *Inspector) Entry(ctx context.Context, sessionID, tail, entryID string, entries int) (Entry, error)

Entry computes the detail of the entry, on the line of the session that ends at tail. entries is how many entries the viewer's model held, so a snapshot read for an earlier one is not reused.

func (*Inspector) Reads

func (in *Inspector) Reads() int

Reads is how many times the source was read, for a test of the cache.

func (*Inspector) Session

func (in *Inspector) Session(ctx context.Context, sessionID, tail string, entries int) (Session, error)

Session computes the session pane for the line ending at tail.

type Manifest

type Manifest struct {
	Entries []ManifestEntry `json:"entries"`
	Omitted []ManifestEntry `json:"omitted,omitempty"`
	// Entry is the record entry the manifest in force came from.
	Entry string `json:"-"`
}

Manifest is the memory manifest in force: what the model's memory block held and what its bound left out.

type ManifestEntry

type ManifestEntry struct {
	Scope  string `json:"scope"`
	Name   string `json:"name"`
	Hash   string `json:"hash"`
	Bytes  int    `json:"bytes"`
	Reason string `json:"reason,omitempty"`
}

ManifestEntry names one memory by scope and name.

type Option

type Option func(*Inspector)

Option configures an Inspector.

func WithCost

func WithCost(fn client.Cost) Option

WithCost sets the function that prices one model call, in US dollars. A call it does not price leaves the session pane's cost unpriced.

type PathVerify

type PathVerify struct {
	Responses  int
	Verified   int
	Unhashed   int
	Mismatched int
	Failed     int
	// Problems lists what did not verify, response by response, the
	// mismatches first.
	Problems []Problem
}

PathVerify is the result of checking every response on a line.

func (PathVerify) OK

func (p PathVerify) OK() bool

OK reports whether every response on the line verified or recorded no hash for a reason it names; a mismatch or a failure is not OK.

type Problem

type Problem struct {
	Response string
	Verify   Verify
}

Problem is one response that did not verify.

type Refusal

type Refusal struct {
	Entry string
	Why   string
}

Refusal is a manifest record the fold refused, and why. A refused record leaves the manifest in force as it was, as agentmemory's fold does.

type Response

type Response struct {
	Entry       string
	ResponseID  string
	Model       string
	Status      string
	Usage       *openresponses.Usage
	LatencyMS   int64
	Attempts    int
	RequestHash string
	Verify      Verify
}

Response is a response entry and how it verifies.

type Session

type Session struct {
	ID            string
	Name          string
	CWD           string
	Harness       string
	Format        string
	Created       time.Time
	ParentSession string
	Base          string
	SpawnedBy     string
	// Entries is the session's entry count, Path the length of the viewed
	// line.
	Entries int
	Path    int

	// Verify is the tally over the responses on the viewed line.
	Verify PathVerify
	// Usage is the token usage of the model calls on the viewed line,
	// responses and folds.
	Usage openresponses.Usage
	// UsageByModel is Usage split by the model each call was made under.
	UsageByModel map[string]openresponses.Usage
	// Cost is the viewed line's cost in US dollars under the cost source,
	// and Priced says every call was priced (false with no source).
	Cost   float64
	Priced bool
	// Unpriced lists the models that have usage on the viewed line but
	// that the cost source has no price for, sorted.
	Unpriced []string
	// Config is what the record has in force at the end of the line.
	Config Config
	// Refs are the refs that point at the session, RefsErr why they could
	// not be listed (a store without refs).
	Refs    []agentsession.Ref
	RefsErr string
	// Manifest is the memory manifest in force, nil when the line holds
	// none; ManifestRefused lists the records the fold refused, which
	// leave the manifest in force as it was.
	Manifest        *Manifest
	ManifestRefused []Refusal
	// Grants are the skill grants in force at the end of the line, and
	// those a revocation ended.
	Grants []Grant
}

Session is the session-level summary pane.

func (Session) Lines

func (s Session) Lines() []string

Lines renders the session pane as plain lines.

type Source

type Source interface {
	Read(ctx context.Context, sessionID string) (*agentsession.Session, error)
	Refs(ctx context.Context, sessionID string) ([]agentsession.Ref, error)
}

Source is where a snapshot of a session and its refs come from; it is client.Record.

type Verdict

type Verdict struct {
	Entry      string `json:"-"`
	RunID      string `json:"run_id,omitempty"`
	Turn       int    `json:"turn,omitempty"`
	CallID     string `json:"call_id,omitempty"`
	Tool       string `json:"tool,omitempty"`
	Guard      string `json:"guard,omitempty"`
	Action     string `json:"action"`
	Rule       string `json:"rule,omitempty"`
	Source     string `json:"source,omitempty"`
	SourceHash string `json:"source_hash,omitempty"`
	Note       string `json:"note,omitempty"`
	Reason     string `json:"reason,omitempty"`
	By         string `json:"by,omitempty"`
	Held       bool   `json:"held,omitempty"`
	Subject    string `json:"subject,omitempty"`
	Confined   string `json:"confined,omitempty"`
}

Verdict is a policy verdict as the session holds it.

type Verify

type Verify struct {
	State VerifyState
	// Why is the cause an unhashed response names, or the error of a
	// mismatch or a failure.
	Why string
}

Verify is the result of checking one response.

type VerifyState

type VerifyState int

VerifyState says how far a response's request could be checked.

const (
	// Verified: the request rebuilt from the path hashes to the recorded
	// request hash.
	Verified VerifyState = iota
	// Unhashed: the response recorded no hash, because its writer could
	// not stand behind one. Why says what the record gives as the cause.
	Unhashed
	// Mismatch: the rebuilt request hashes to something else.
	Mismatch
	// Failed: the request could not be rebuilt at all.
	Failed
)

Verification states.

func (VerifyState) String

func (s VerifyState) String() string

String names the state.

Jump to

Keyboard shortcuts

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