trust

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 15 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 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 BeforeToolCall

func BeforeToolCall(mgr *Manager, cwd string, in *bufio.Reader, out io.Writer, mu *sync.Mutex) agentcore.BeforeToolCallFunc

BeforeToolCall builds the permission hook that gates side-effect tools (bash/write/edit) on the cwd's trust decision. In a trusted directory the call is allowed (nil). Otherwise the user is prompted; "always" grants session trust so subsequent side-effect calls skip the prompt. mgr==nil 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 ConfirmToolCall

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

ConfirmToolCall asks whether a side-effect tool call may run in an untrusted directory. It returns (allow, always): allow runs the call this once; always runs it AND grants session trust so subsequent side-effect calls skip the prompt. Denial (no/empty/EOF/interrupt) returns (false, false).

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 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 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 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. 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 string) bool

GatesTool reports whether the trust gate applies to a tool call in an untrusted directory: always for side-effect tools, and for read tools only under StrictReads. 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) 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) 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