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 ¶
- func AbsAgainst(base, p string) (string, error)
- func AddReadRoot(raw string) (string, error)
- func BroadReadRoot(p string) (string, bool)
- func Inside(root, p string) bool
- func NormalizePath(raw string) (string, error)
- func NormalizeReadRoot(raw string) (string, error)
- func ReadRoots() []string
- func ReadScopeCandidate(target string) string
- func ReadableAt(p string) bool
- func ReadableRootsFromEnv(getenv func(string) string) []string
- func RemoveReadRoot(raw string) bool
- func SetReadRoots(paths []string) []error
- type Mode
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsAgainst ¶ added in v1.2.15
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
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
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
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
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
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
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
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
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
RemoveReadRoot revokes one grant. It reports whether the path was present.
func SetReadRoots ¶ added in v1.2.15
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.
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 ¶
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 ¶
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 ¶
Description returns the one-line explanation shown next to the label.