evidence

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandMatches

func CommandMatches(cited, ran string) bool

CommandMatches reports whether a cited verification command is proven by a command that actually ran. Models paraphrase commands when citing them (dropping a `cd` prefix, changing quote style, omitting flags), so byte equality rejects real verifications; instead both sides are split into shell segments and each cited segment must be covered by some ran segment.

func PathsProvenInSession

func PathsProvenInSession(msgs []provider.Message, paths []string, wantWrite bool) bool

PathsProvenInSession reports whether every path is covered by a successful (non-errored) tool call somewhere in msgs — the cross-turn fallback for diff and files evidence, mirroring verifyCommandFromSession for the per-turn ledger's path receipts (which reset each turn). wantWrite restricts to writer tools (diff); false accepts a reader or writer (files).

func SessionMessagesFromContext

func SessionMessagesFromContext(ctx context.Context) ([]provider.Message, bool)

SessionMessagesFromContext retrieves the conversation history attached by WithSessionMessages.

func WithLedger

func WithLedger(ctx context.Context, ledger *Ledger) context.Context

func WithSessionMessages

func WithSessionMessages(ctx context.Context, msgs []provider.Message) context.Context

WithSessionMessages attaches the full conversation history so verifyStepEvidence can fall back to scanning the transcript when the per-turn ledger misses a command (cross-turn references, non-bash tool calls, truncated command strings).

Types

type Ledger

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

Ledger stores the receipts available to complete_step for the current turn.

func FromContext

func FromContext(ctx context.Context) (*Ledger, bool)

func NewLedger

func NewLedger() *Ledger

func (*Ledger) HasAnySuccessfulReceipt

func (l *Ledger) HasAnySuccessfulReceipt() bool

HasAnySuccessfulReceipt reports whether any tool succeeded this turn — the signal that the turn did real work, not pure conversation.

func (*Ledger) HasFailedCommand

func (l *Ledger) HasFailedCommand(command string) bool

HasFailedCommand reports whether the cited command ran this turn but exited non-zero — so callers can distinguish "ran and failed" from "never ran".

func (*Ledger) HasSuccessfulBashMentioningPaths

func (l *Ledger) HasSuccessfulBashMentioningPaths(paths []string) bool

HasSuccessfulBashMentioningPaths reports whether every path appears in some successful bash command this turn — files created or edited through shell redirection (`seq … > file`) leave no reader/writer receipt, so the command text naming the path is the receipt.

func (*Ledger) HasSuccessfulCommand

func (l *Ledger) HasSuccessfulCommand(command string) bool

func (*Ledger) HasSuccessfulCommandAfter

func (l *Ledger) HasSuccessfulCommandAfter(command string, after int) bool

func (*Ledger) HasSuccessfulCompleteStepAfter

func (l *Ledger) HasSuccessfulCompleteStepAfter(after int) bool

func (*Ledger) HasSuccessfulReadOrWrite

func (l *Ledger) HasSuccessfulReadOrWrite(paths []string) bool

func (*Ledger) HasSuccessfulTodoWrite

func (l *Ledger) HasSuccessfulTodoWrite() bool

func (*Ledger) HasSuccessfulWrite

func (l *Ledger) HasSuccessfulWrite(paths []string) bool

func (*Ledger) IncompleteLatestTodos

func (l *Ledger) IncompleteLatestTodos() ([]TodoStepMatch, bool)

func (*Ledger) LatestSuccessfulWriteIndex

func (l *Ledger) LatestSuccessfulWriteIndex(paths []string) (int, bool)

func (*Ledger) LatestSuccessfulWriterIndex

func (l *Ledger) LatestSuccessfulWriterIndex() (int, bool)

func (*Ledger) LatestTodos

func (l *Ledger) LatestTodos() ([]TodoItem, bool)

LatestTodos returns the todo list from this turn's latest successful todo_write.

func (*Ledger) MatchLatestTodoStep

func (l *Ledger) MatchLatestTodoStep(step string) (TodoStepMatch, bool)

func (*Ledger) Record

func (l *Ledger) Record(r Receipt)

Record appends a receipt. Failed receipts are retained for auditability but are never accepted by the HasSuccessful* matchers.

func (*Ledger) Reset

func (l *Ledger) Reset()

Reset clears receipts between user turns.

func (*Ledger) SuccessfulCommands

func (l *Ledger) SuccessfulCommands(limit int) []string

SuccessfulCommands returns up to limit successful bash commands from this turn, most recent first, for self-correction hints in rejection errors.

func (*Ledger) TouchedPaths

func (l *Ledger) TouchedPaths(limit int, writtenOnly bool) []string

TouchedPaths returns up to limit distinct paths from this turn's successful receipts, most recent first; writtenOnly restricts it to writer receipts.

func (*Ledger) UnverifiedCompletedTodos

func (l *Ledger) UnverifiedCompletedTodos(current []TodoItem) (missing []TodoStepMatch, hasBaseline bool)

UnverifiedCompletedTodos reports current completed todos that transitioned from the latest prior successful todo_write receipt without a matching successful complete_step receipt earlier in the same turn. If this turn has no prior todo_write baseline, hasBaseline is false and callers should preserve the existing loose validation behavior.

type ReadinessAudit

type ReadinessAudit struct {
	Result                 ReadinessAuditResult
	Recovered              bool
	MissingProjectChecks   int
	IncompleteTodos        int
	CommandMismatchMissing int
}

ReadinessAudit is a structured, non-rendered receipt for the final-answer readiness gate. It lets metrics sinks count why the host blocked a final answer without scraping Notice text or adding model-visible state.

type ReadinessAuditResult

type ReadinessAuditResult string

ReadinessAuditResult classifies one host final-answer readiness audit receipt.

const (
	ReadinessAllowed ReadinessAuditResult = "allowed"
	ReadinessBlocked ReadinessAuditResult = "blocked"
	ReadinessErrored ReadinessAuditResult = "errored"
)

type Receipt

type Receipt struct {
	ToolName string          `json:"tool_name"`
	Args     json.RawMessage `json:"args,omitempty"`
	Success  bool            `json:"success"`
	Command  string          `json:"command,omitempty"`
	Step     string          `json:"step,omitempty"`
	TodoStep *TodoStepMatch  `json:"todo_step,omitempty"`
	Paths    []string        `json:"paths,omitempty"`
	Read     bool            `json:"read,omitempty"`
	Write    bool            `json:"write,omitempty"`
	Todos    []TodoItem      `json:"todos,omitempty"`
}

Receipt is the host-runtime record of one tool call. It stays in memory for the current agent turn and is not serialized into prompts or session state.

func ReceiptFromToolCall

func ReceiptFromToolCall(toolName string, args json.RawMessage, success bool, readOnly bool) Receipt

type TodoItem

type TodoItem struct {
	Content    string `json:"content"`
	Status     string `json:"status"`
	ActiveForm string `json:"activeForm,omitempty"`
	Level      int    `json:"level,omitempty"`
}

TodoItem mirrors the todo_write item shape the host needs for step matching.

type TodoStepMatch

type TodoStepMatch struct {
	Found      bool
	Index      int
	Content    string
	Status     string
	ActiveForm string
}

TodoStepMatch is the result of matching complete_step.step against the latest successful todo_write list in this turn.

func IncompleteTodos

func IncompleteTodos(todos []TodoItem) []TodoStepMatch

IncompleteTodos returns the items of a todo list that are not completed.

func MatchStep

func MatchStep(step string, todos []TodoItem) (TodoStepMatch, bool)

MatchStep resolves a complete_step.step (number, title, or drift-tolerant variant) against a todo list, returning the matched item.

Jump to

Keyboard shortcuts

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