permissions

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: 6 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

Package permissions defines golder's approval modes and the live, mutable state that tracks the active one. It is a leaf package: standard library only, no imports from judge/trust/runtime, so every layer (the risk gate, the bash tool, the slash command) can read the mode without an import cycle.

The four modes mirror codex's approval presets, adapted to golder's gate:

  • read-only: mutating tools (bash, apply_patch) are blocked outright.
  • ask: the reviewer grades each mutating call; Allow runs, the rest asks the human (or is denied when no prompt exists).
  • auto: the reviewer decides: Allow/Confirm run, Sandbox runs isolated, Deny is blocked — each non-trivial decision is announced with a one-line rationale.
  • full-access: no review and no sandbox; only the static hard-deny floor still applies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsAgainst added in v1.2.15

func AbsAgainst(base, p string) (string, error)

AbsAgainst returns p as a cleaned absolute path: an absolute p is cleaned, a relative one is resolved against base (which defaults to the working directory when empty). "~" is deliberately NOT expanded here, because the file tools do not expand it either — the gate and the tools must agree on what a path names, or the gate would ask about a location the tool never visits. User-supplied grants (NormalizeReadRoot) expand it, since there the spelling comes from a person rather than from a call argument.

func AddReadRoot added in v1.2.15

func AddReadRoot(raw string) (string, error)

AddReadRoot grants one directory for reading, for this session. It returns the normalized path so callers can echo it back. The same directory granted twice is stored once.

func BroadReadRoot added in v1.2.15

func BroadReadRoot(p string) (string, bool)

BroadReadRoot reports whether p is too wide to grant. The filesystem root, the home directory itself and the directory holding it are refused: a grant there is indistinguishable from "no boundary", and a dialog that offers it would turn one keystroke into access to everything — the exact rubber stamp the boundary exists to prevent. A parent of the workspace is NOT broad: a monorepo above the current directory is a real thing to grant.

func Inside added in v1.2.15

func Inside(root, p string) bool

Inside reports whether p is root itself or lives under it. Both paths are compared as cleaned absolute paths, so a symlinked spelling or a trailing separator does not change the answer.

func NormalizePath added in v1.2.15

func NormalizePath(raw string) (string, error)

NormalizePath validates one user- or gate-supplied path and returns its cleaned absolute form. "~/..." expands against the real home directory; relative paths are rejected (they would resolve differently for every process). The path need not exist yet.

It is the one path-normalization policy the permission layer has: the sandbox's writable roots (seatbelt.NormalizeWritableRoot) delegate here, so "~/x" and a relative path mean the same thing to both registries.

func NormalizeReadRoot added in v1.2.15

func NormalizeReadRoot(raw string) (string, error)

NormalizeReadRoot normalizes one read grant and refuses the roots that would amount to removing the boundary.

func ReadRoots added in v1.2.15

func ReadRoots() []string

ReadRoots returns the current grant list (a copy, safe to retain).

func ReadScopeCandidate added in v1.2.15

func ReadScopeCandidate(target string) string

ReadScopeCandidate returns the directory a boundary question may offer to grant for the session, given the file a call asked for: the file's own directory, or that directory's parent when the directory itself is too broad to hand over. "" means no directory should be offered (the answer is then "this one file" or nothing), which happens when both are broad — a file sitting directly in the home directory, say.

func ReadableAt added in v1.2.15

func ReadableAt(p string) bool

ReadableAt reports whether p is inside a granted read root. This is the check the file tools make once a path has failed the workspace boundary, and the one the gate makes to avoid asking twice for the same directory.

func ReadableRootsFromEnv added in v1.2.15

func ReadableRootsFromEnv(getenv func(string) string) []string

ReadableRootsFromEnv parses GOLDER_READABLE_ROOTS: colon- or comma-separated directories the read-only tools may reach without asking, for a machine or a script where editing config.toml is not the right place. Entries follow the same rules as the config list ("~/..." expands, relative paths and roots too broad to be a boundary are dropped), so an entry that would not be accepted from the config file is not accepted here either.

It mirrors GOLDER_SANDBOX_READABLE (the sandbox's read whitelist) but is not the same knob: that one reaches the OS sandbox only, so a command could read a path the file tools still refused. This one is the read-only tools' own list, and a grant here also reaches the sandbox, because the read roots feed its whitelist too.

func RemoveReadRoot added in v1.2.15

func RemoveReadRoot(raw string) bool

RemoveReadRoot revokes one grant. It reports whether the path was present.

func SetReadRoots added in v1.2.15

func SetReadRoots(paths []string) []error

SetReadRoots replaces the whole list: startup applies the config file and the environment with it, and tests reset state with SetReadRoots(nil). Invalid or too-broad entries are skipped and reported, while every valid one still applies — one typo in config.toml should not cost the rest of the list.

func SystemReadRoots added in v1.2.17

func SystemReadRoots() []string

SystemReadRoots returns the directories a run may always read: the system runtime, the package-manager trees, and the temp roots a shell needs. It is deliberately short — $HOME is NOT here, because the point of the whitelist is that credential material inside $HOME is excluded by construction rather than by an ever-growing blacklist. A user whose toolchain lives under $HOME (conda, pyenv, nvm) adds it via [sandbox] readable or GOLDER_SANDBOX_READABLE.

Types

type Mode

type Mode int

Mode is one of the four approval modes.

const (
	// ReadOnly blocks mutating tools: the model may inspect but not change.
	ReadOnly Mode = iota
	// Ask grades each mutating call and asks the human about anything that is
	// not clearly low-risk. Without an interactive prompt the call is denied.
	Ask
	// Auto lets the reviewer decide without a human: reviewed calls run, risky
	// ones run sandboxed, dangerous ones are blocked, and each decision is
	// announced with its rationale.
	Auto
	// FullAccess disables review and sandboxing (the static floor remains).
	FullAccess
)

func FromEnv

func FromEnv(getenv func(string) string) (Mode, bool)

FromEnv resolves the default mode from GOLDER_PERMISSIONS. GOLDER_JUDGE=off is honored as a legacy alias for full-access. ok is false when the variable is unset or unparseable, leaving the caller's own default in place.

func Parse

func Parse(s string) (Mode, bool)

Parse resolves a user-supplied mode name. It accepts the canonical names plus a few common shorthands ("readonly", "ro", "full"), case-insensitively. ok is false for anything unrecognized so callers can report a usage error instead of silently picking a default.

func (Mode) Description

func (m Mode) Description(lang string) string

Description returns the one-line explanation shown next to the label.

func (Mode) Label

func (m Mode) Label(lang string) string

Label returns the human-facing name of the mode in the given language ("zh" for Simplified Chinese, anything else English). UI surfaces use it so the /permissions output matches the language of the conversation.

func (Mode) String

func (m Mode) String() string

String returns the canonical, lowercase mode name used by the CLI, the slash command, and the config/env layers.

type State

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

State is the process-wide, concurrency-safe holder of the active mode. The gate, the bash tool and the slash command all read it live, so a /permissions switch applies to the very next tool call (even mid-run).

func New

func New(mode Mode) *State

New returns a State seeded with mode.

func (*State) Mode

func (s *State) Mode() Mode

Mode returns the active mode.

func (*State) Set

func (s *State) Set(mode Mode)

Set replaces the active mode.

Jump to

Keyboard shortcuts

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