trust

package
v1.5.66 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 22 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,
	"tuios":       true,
	"terminal":    true,
	"workspace":   true,
	"browser":     true,
}

SideEffectTools are the built-in tools with filesystem or process side effects that trust gates. Broker reads are distinguished by action in Gate; their command, launch, screenshot and input actions cannot evade project trust merely because they do not use bash or apply_patch.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the trust file location: trust.json in the golder state root ($GOLDER_HOME, else ~/.golder). It returns "" when the root cannot be resolved, 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: this hook runs concurrently with itself. bash is ToolExecutionParallel (codex parity: the shell is shareable and the exclusive lock belongs to the editing tools, which apply_patch keeps), so two commands in one batch reach the gate at the same time. mu serializes the stdin prompt - required now, rather than the insurance it was while every side-effect tool was sequential - and it is nil-safe (a driver wiring trust without a mutex gets no serialization). A driver that answers through Confirm instead (the TUI) queues each request on its own dialog queue, which is where its serialization lives, and the manager's own state is mutex-guarded.

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.

The keys are the TUI dialog's, and deliberately so: this prompt and the dialog ask the same question, and they used to answer it with different letters (`r` for reads here, `a` for all tools here — where the dialog used `a` for reads and `p` for all tools). A person who learned one front-end would press the wrong key in the other, and on this question the wrong key is a wider grant than intended. Now both spell the same ladder: y once, a reads (this session), p all tools (this session).

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
	// Mode keeps automatic broker control from introducing a human trust
	// prompt mid-call: missing project execution trust fails closed in auto.
	Mode *permissions.State
	// 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
	// OnPrompt, when set, is told the question just before a prompt is put to
	// the person — through Confirm or through the stdin prompt below — and
	// returns the function to call once it is answered. See judge.GateOpts'
	// field of the same name: it is how a driver tells the terminal around it
	// that this pane waits for a human (internal/hostcompat).
	OnPrompt func(question string) func()
}

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) Entries added in v1.2.20

func (m *Manager) Entries() (saved []TrustEntry, sessionTrust, sessionReads []string)

Entries returns every saved decision, sorted by path, plus the two session-only grants: directories trusted for this process, and directories whose local reads were allowed for this process. /trust status answers "what applies to THIS directory" by walking up; this answers "what is in the store", which is the question a user auditing their grants is actually asking.

The walk is deliberately absent: entries are the recorded keys, so a decision saved for a parent is listed once, under its own directory, instead of repeated for every child that inherits it.

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. A nil manager — trust disabled — is untrusted.

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) Path added in v1.2.20

func (m *Manager) Path() string

Path returns the trust file this manager reads and writes ("" when the store is disabled), so a report can name the file it is describing.

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. A nil manager grants nothing.

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. A nil manager — the store could not be opened, so trust is disabled — grants nothing, matching every other method here; it must not crash the caller that answered a prompt.

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.

type TrustEntry added in v1.2.20

type TrustEntry struct {
	Path     string
	Decision Decision
}

TrustEntry is one saved decision as /grants list reports it, with the provenance that decides what revoking it takes.

Jump to

Keyboard shortcuts

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