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

gatereason

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gatereason reads the gate-reason record of a call (docs/design/untrusted-content-and-amount- caps.md, sections 5.3 and 7) into the reasons an approver, a notifier and a viewer are shown: why the call needs a gate beyond its tool's own. A reason is evidence and the application's claim, never authority: nothing read here decides a gate, and the signed decision does not bind it. The package imports no other bide package that imports the agent, so the agent's notifier payload can carry its type.

Index

Constants

View Source
const (
	// KindTaint: the requesting turn had read untrusted content.
	KindTaint = "taint"
	// KindCap: a cap rule applies.
	KindCap = "cap"
	// KindConflict: two records name the call and disagree, so none is shown (see Find).
	KindConflict = "conflict"
)

Reason kinds.

View Source
const MaxText = 128

MaxText bounds every host-declared string of a reason, which is shown to people.

View Source
const Prefix = "gate-reason:"

Prefix is the name prefix of a gate-reason record, reserved to the engine.

Variables

This section is empty.

Functions

func Money

func Money(minor int64, currency string) string

Money is minor units in a currency, as the decimal text the figures are shown in, using the ISO 4217 exponent (internal/amount). A currency it does not know is shown in minor units.

Types

type Reason

type Reason struct {
	// Kind is KindTaint or KindCap.
	Kind string `json:"kind"`
	// Source and Ref (taint): the declared source of the content, and where it was read: "tool:<name>/<call>",
	// "input" or "retrieval". Pos is the position of the mark in the run's journal.
	Source string `json:"source,omitempty"`
	Ref    string `json:"ref,omitempty"`
	Pos    int    `json:"pos,omitempty"`
	// Rule, Action, Why, Currency, Amount and Limit (cap): the rule's name, what it decided ("gate" or
	// "refuse"), why it fired ("over", "not_assessable" or "currency"), and this call's amount and the
	// rule's limit in minor units of Currency. Amount is nil when the call's amount could not be assessed.
	Rule     string `json:"rule,omitempty"`
	Action   string `json:"action,omitempty"`
	Why      string `json:"why,omitempty"`
	Currency string `json:"currency,omitempty"`
	Amount   *int64 `json:"amount,omitempty"`
	Limit    int64  `json:"limit,omitempty"`
	// At is when the engine recorded the reason (the ask), by the run's clock: the figures are as of then.
	At string `json:"at,omitempty"`
}

Reason is one reason a call is gated, as the record holds it. Every string is a host-declared name (a source, a tool and call, a rule), cut to MaxText bytes and escaped when it is not printable text, so it can be shown as it is.

func Find

func Find(subject string, records Records) []Reason

Find is the reasons for the gate instance subject: for the escalation instance of a call ("<call>#taint"), the taint reasons of the call's record; for the call's own gate, its cap reasons. It returns none when the run has no record for the call, or none that reads.

Every record that names the call and reads must agree: a record under another name that names the call (a decoy written ahead of the engine's, or behind it) is not told from the engine's by its position, so when two disagree no reason is shown, and a single reason of Kind KindConflict stands in its place, so the approver sees that something is wrong. Records that say the same are one.

func (Reason) Line

func (r Reason) Line() string

Line is a reason as one line of text for a terminal or a log: "untrusted content from inbound-email (read by tool read_email, call c3, journal position 4)", or "cap refund_one: this call 6,000.00 USD over the limit 5,000.00 USD (refuse)".

type Records

type Records func(yield func(name string, result []byte) bool)

Records yields the name and the result bytes of the value records of a run, in journal order.

Directories

Path Synopsis
Package agentrecs adapts a run's records to gatereason.Records, for the packages that read a journal through the agent package (the approvals intake, the run viewer, the audit CLI).
Package agentrecs adapts a run's records to gatereason.Records, for the packages that read a journal through the agent package (the approvals intake, the run viewer, the audit CLI).

Jump to

Keyboard shortcuts

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