trust

package
v1.2.17 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

This file holds the interactive pieces of project trust (US-018, #134). The trust store itself lives alongside in manager.go; here are the REPL-facing parts:

  • the first-run trust dialog (EnsureTrustPrompt), shown when the cwd has no saved decision;
  • the /trust command (RegisterCommand), which saves or reports the current project's decision;
  • the BeforeToolCall hook (BeforeToolCall) that asks before side-effect tools (bash/write/edit) run in an untrusted directory.

All prompts share the REPL's single *bufio.Reader so input typed ahead is never split between the main loop and a confirmation. Headless mode is unaffected: trust is a REPL safety feature and headless is an explicit, non-interactive invocation.

Package trust persists per-directory trust decisions so golder can avoid running side-effect tools (bash/write/edit) in directories the user has not trusted (US-018, #134). Decisions are stored as a JSON map of directory path to a nullable boolean: true = trusted, false = untrusted, null/absent = undecided.

The package is intentionally free of any REPL or tool-execution concerns: it only loads, queries, and persists decisions. The interactive prompt and the permission-hook integration live in cmd/golder.

Index

Constants

This section is empty.

Variables

View Source
var LocalReadTools = map[string]bool{
	"read":       true,
	"view_image": true,
	"grep":       true,
	"find":       true,
	"ls":         true,
}

LocalReadTools are the read tools an "allow reads here" answer covers: the ones that read the folder's own files. Network reads (webfetch, websearch) are deliberately outside it - the folder key says nothing about egress, so covering them would open the session's network path on a keystroke meant for files. They stay gated and keep asking each time.

View Source
var ReadTools = map[string]bool{
	"read":       true,
	"view_image": true,
	"grep":       true,
	"find":       true,
	"ls":         true,
	"webfetch":   true,
	"websearch":  true,
}

ReadTools are the data-ingestion tools (local file reads and network reads) gated in untrusted directories only when Manager.StrictReads is set. Pure in-memory tools (todo, schedule_*, goal_*, memory_*) are never gated.

View Source
var SideEffectTools = map[string]bool{
	"bash":        true,
	"apply_patch": true,
}

SideEffectTools are the built-in tools with filesystem or process side effects that trust always gates. apply_patch is the single write-path tool (it replaced write/edit), so gating it gates every file mutation the model can make.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the trust file location: $GOLDER_HOME/trust.json, or ~/.golder/trust.json when GOLDER_HOME is unset. It returns "" when the home directory cannot be resolved and no override is set, so a caller can treat trust as disabled rather than guessing a path.

func EnsureTrustPrompt

func EnsureTrustPrompt(out io.Writer, in *bufio.Reader, mgr *Manager, cwd string)

EnsureTrustPrompt runs the first-run trust dialog when cwd has no saved decision (NearestTrustDecision reports Found=false). When a decision already exists (trusted/untrusted/null) it is a no-op: the user already answered, so golder does not re-ask on every launch. mgr==nil disables trust entirely.

func EstablishTrust

func EstablishTrust(out io.Writer, in *bufio.Reader, mgr *Manager, cwd string, approve bool)

EstablishTrust decides how the launch directory's trust is established before the REPL runs. When approve is true (mirrors pi's --approve/-a), it grants session trust up front so the first-launch prompt is skipped and side-effect tools run without per-call confirmation. Otherwise it defers to EnsureTrustPrompt, which asks only on the first launch in an undecided directory. mgr==nil disables trust entirely, so approve is a no-op.

func Gate added in v1.2.17

Gate builds the trust gate: side-effect tools and, under StrictReads, the data-ingestion tools (see GatesTool) are asked about in a directory the session has not trusted. In a trusted directory the call is allowed (nil). Otherwise the user answers with the ladder - once runs this call, "reads" grants session reads for the directory (LocalReadTools only), and "always" grants session trust so every tool stops asking - and the chosen grant is filed on the manager, so it applies to the next call of any driver sharing that manager. A nil Manager returns nil (trust disabled, no gating).

Concurrency: bash/write/edit are all ToolExecutionSequential, so the batch runs serially and this hook fires on the run-loop producer goroutine - never concurrently with itself. mu serializes prompts anyway as cheap insurance should a side-effect tool ever become parallel; it is nil-safe (callers that wire trust without a mutex simply get no serialization). The prompt writes to out from the producer goroutine; this is safe because streamRun uses an unbuffered event stream (EventBuffer=0, the default), so by the time the hook runs the main goroutine has already drained the assistant's streamed text and is idle in DrainStream. Do not raise EventBuffer above 0 while trust gating is wired without routing the prompt through the main goroutine.

func RegisterCommand

func RegisterCommand(reg *runtime.SlashRegistry, mgr *Manager, cwd string)

RegisterCommand installs the /trust action command, which saves or reports the current project's trust decision. It is an instance built-in (AddBuiltin) because its closure captures the trust manager and cwd - state out of reach of an init()-time global registration. mgr==nil is a no-op: the command is not installed, so /trust reports unknown when trust is disabled.

func ToolCallSummary

func ToolCallSummary(call agentcore.AgentToolCall) string

ToolCallSummary is the exported form of toolCallSummary, used by callers outside this package (e.g. the remote-control confirm path) that need the same one-line preview a local confirmation prompt shows.

Types

type Answer added in v1.2.17

type Answer struct {
	// Allow runs the call; false is a denial (the model is told, and can
	// propose something else).
	Allow bool
	// Always grants session trust for the directory: every tool runs without
	// asking until golder exits. Not persisted.
	Always bool
	// Reads grants local reads for the directory for the session. Not
	// persisted.
	Reads bool
}

Answer is a trust prompt's decision. The positive answers differ in what they remember, which the prompt spells out: Allow runs the call once, Always stops every tool asking in the directory for the session, and Reads stops only the local read tools (LocalReadTools) - reads of the folder's own files - while commands and network reads keep asking.

func ConfirmToolCall

func ConfirmToolCall(ctx context.Context, out io.Writer, in *bufio.Reader, call agentcore.AgentToolCall) Answer

ConfirmToolCall asks whether a trust-gated tool call may run in an untrusted directory. Denial (no/empty/EOF/interrupt) returns the zero Answer.

type Decision

type Decision int

Decision is the tri-state trust value for a directory.

const (
	// Undecided means no decision is saved for the directory (or an explicit
	// null entry). The caller should prompt the user and treat side-effect
	// tools as requiring confirmation.
	Undecided Decision = iota
	// Trusted means side-effect tools may run without confirmation.
	Trusted
	// Untrusted means side-effect tools require confirmation.
	Untrusted
)

func (Decision) String

func (d Decision) String() string

String returns a human-readable label for the decision.

type GateOpts added in v1.2.17

type GateOpts struct {
	// Manager is the trust store. A nil manager disables the gate (Gate
	// returns nil), matching the pre-existing "trust unavailable" behavior.
	Manager *Manager
	// Cwd is the directory the trust decision is about; it is also the key the
	// session grants are filed under, so every caller must pass the run's
	// workspace rather than a tool argument.
	Cwd string
	// In/Out/Mu are the shared stdin prompt channel (interactive line drivers).
	In  *bufio.Reader
	Out io.Writer
	Mu  *sync.Mutex
	// Confirm is the driver's own approval channel. When set it is preferred
	// over In/Out: it takes the same ApprovalRequest every other gate asks
	// with, so one driver dialog answers trust, read-scope and permission
	// questions alike.
	Confirm func(ctx context.Context, req judge.ApprovalRequest) judge.ApprovalAnswer
}

GateOpts configures the trust gate. Exactly one answer channel is used: Confirm when set (the TUI's dialog, or a driver's own routing), otherwise the stdin prompt when In and Out are set. A gate with neither fails closed: a run with no one to ask refuses the call with guidance instead of guessing.

type Manager

type Manager struct {

	// StrictReads extends the trust gate to data-ingestion tools (read, grep,
	// find, ls, webfetch, websearch) in untrusted directories. Fork default is
	// true (security first): a rejected directory prompts for every file and
	// network read, not just writes. Pure in-memory tools (todo, schedule_*,
	// goal_*, memory_*) are never gated. Escapes: --approve, /trust once|on,
	// or the prompt's "always" answer (all grant session trust).
	StrictReads bool
	// contains filtered or unexported fields
}

Manager loads and persists trust decisions to a JSON file (path -> *bool). The zero value is not usable; construct with NewManager. It is safe for concurrent use: every method takes the manager mutex.

func NewManager

func NewManager(path string) (*Manager, error)

NewManager loads the trust file at path. A missing file is not an error: the manager starts empty and the file is created lazily on the first SetDecision / Forget. A present-but-malformed file is a hard error so a corrupted trust store is surfaced rather than silently overwritten.

func (*Manager) ClearSessionTrust

func (m *Manager) ClearSessionTrust(dir string)

ClearSessionTrust revokes any session trust granted for dir or an ancestor, so a subsequent IsTrusted reflects only the persisted decision. The session reads grant is revoked with it: answering "no" to a directory must not leave its reads half standing. It does not touch the on-disk store. Used by "/trust off" so an active session grant (from a prior "always") does not override a freshly-persisted Untrusted entry - IsTrusted checks session before persisted, so without this clear the "off" command would be ineffective until restart.

func (*Manager) DecisionFor

func (m *Manager) DecisionFor(dir string) (Decision, bool)

DecisionFor returns the raw saved value for a single path (nil when absent or null). It is the exact-path lookup (no walk), used by /trust status to show what is stored for the current directory itself.

func (*Manager) Forget

func (m *Manager) Forget(dir string) error

Forget removes any saved decision for dir (both true/false and an explicit null entry), so the directory is treated as undecided on the next lookup.

func (*Manager) GatesTool

func (m *Manager) GatesTool(name, cwd string) bool

GatesTool reports whether the trust gate applies to a tool call in an untrusted directory cwd: always for side-effect tools, and for read tools under StrictReads unless cwd already carries a session reads grant (the gate's middle rung, which covers LocalReadTools only). A nil manager gates nothing.

func (*Manager) IsTrusted

func (m *Manager) IsTrusted(cwd string) bool

IsTrusted reports whether cwd is trusted for side-effect execution. It returns true when the nearest persisted decision is Trusted, or when cwd (or an ancestor) was granted session trust via SetSessionTrust. Everything else (Untrusted, Undecided, or no entry) returns false, meaning side-effect tools require confirmation.

func (*Manager) NearestTrustDecision

func (m *Manager) NearestTrustDecision(cwd string) Result

NearestTrustDecision walks up from cwd (inclusive) to the filesystem root and returns the nearest saved decision. When no entry is found anywhere up the tree it returns {Decision: Undecided, Found: false} so the caller knows to prompt the user.

func (*Manager) ReadsTrusted added in v1.2.17

func (m *Manager) ReadsTrusted(cwd string) bool

ReadsTrusted reports whether dir (or an ancestor) was granted session reads via SetSessionReads. It says nothing about side-effect trust - IsTrusted answers that - and network reads are not grantable per directory at all. A nil manager grants nothing.

func (*Manager) SetDecision

func (m *Manager) SetDecision(dir string, dec Decision) error

SetDecision persists a decision for dir. Trusted and Untrusted write true and false respectively; Undecided writes an explicit null entry (recorded but undecided, distinct from a forgotten/absent entry). The directory is created lazily when the trust file is first written.

func (*Manager) SetSessionReads added in v1.2.17

func (m *Manager) SetSessionReads(dir string)

SetSessionReads grants local reads for dir for the current process only: the read tools that read the folder's own files (LocalReadTools) stop asking in dir and its ancestors, while side-effect tools and network reads keep asking. It is not persisted: a future golder launch re-prompts. Used by the trust prompt's "reads here" answer.

func (*Manager) SetSessionTrust

func (m *Manager) SetSessionTrust(dir string)

SetSessionTrust grants trust for dir for the current process only. It is not persisted: a future golder launch re-prompts. Used by the "just once" REPL choice and by the confirmation prompt's "always" response.

type Result

type Result struct {
	// Decision is the nearest saved decision, or Undecided when none is found.
	Decision Decision
	// Path is the directory whose saved decision applies (the nearest ancestor
	// of cwd with an entry, inclusive of cwd itself). Empty when no entry was
	// found anywhere up the tree.
	Path string
	// Found reports whether any entry (true/false/null) existed for cwd or an
	// ancestor. When false, Decision is Undecided and the caller should prompt
	// the user for a fresh decision.
	Found bool
}

Result is the outcome of a nearest-decision lookup.

Jump to

Keyboard shortcuts

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