permission
import "github.com/barevoidco/zelk/core/permission"Package permission defines the permission modes and the effective policy a session runs under.
A Policy is plain data: the current mode, the modes a host has authorized a session to switch to, and an optional ceiling on the tools it may call. Policies only ever narrow. Narrow combines a parent’s policy with a narrower request, as a skill or a subagent definition makes one, and refuses anything that would widen authority.
Rules and protected paths configure the deterministic decision engine inside the reducer. Hosts do not build action requests or invoke rule evaluation. Shell matching is advisory; the launcher supplies process enforcement.
Constants
Section titled “Constants”const ( ModePlan = engine.ModePlan ModeDefault = engine.ModeDefault ModeAcceptEdits = engine.ModeAcceptEdits ModeAuto = engine.ModeAuto ModeDontAsk = engine.ModeDontAsk ModeBypass = engine.ModeBypass)Supported permission modes.
Variables
Section titled “Variables”var ( // ErrUnknownMode reports an unknown permission mode. ErrUnknownMode = engine.ErrUnknownMode // ErrWiden reports a policy change that would widen authority. ErrWiden = engine.ErrWiden // ErrBadRule reports a malformed permission rule. ErrBadRule = engine.ErrBadRule)CheckProtected
Section titled “CheckProtected”func CheckProtected(pattern string) errorCheckProtected reports why pattern can’t be used as a protected path pattern (WithProtectedPaths), or nil. A pattern that doesn’t compile is never matched, so a host checks one it can’t afford to lose.
ReviewedEdit
Section titled “ReviewedEdit”func ReviewedEdit(p string) boolReviewedEdit reports whether auto mode sends an edit of the workspace file p to its reviewer instead of allowing it: one that RunsLater, or one that configures the application.
RunsLater
Section titled “RunsLater”func RunsLater(p string) boolRunsLater reports whether a workspace file’s contents run or instruct whoever next builds, tests or opens the project, such as a Makefile, a CI workflow or a script. p is workspace-relative, with forward slashes.
type Mode = engine.ModeMode is a permission ceiling on unattended session actions.
Policy
Section titled “Policy”type Policy struct { // Mode is the current mode. Mode Mode // Modes are the modes the host authorizes switches to, including // Mode. Nil authorizes only Mode. Modes []Mode // Tools is the ceiling on the tools the session may call, by name. // Nil allows every tool; an empty, non-nil slice allows none. Tools []string // Rules are the deny, human-only, ask and allow rules. Rules Rules // Protected extends the built-in protected paths: globs relative to // the workspace, or base-name globs (with no slash) matched anywhere. Protected []string // NoSkillGrants says no skill's allowed-tools pre-approve calls. NoSkillGrants bool}Policy is the host’s permission configuration. Its zero value is invalid. Rule evaluation belongs to the reducer; hosts configure and narrow policy.
Policy.AllowsRead
Section titled “Policy.AllowsRead”func (p Policy) AllowsRead(path string) boolAllowsRead reports whether path, relative to the workspace, may be inlined by a host without approval. Protected paths are always withheld, even though the Read tool itself may read them; hooks still run on actual tool calls.
Example
policy := permission.Policy{Mode: permission.ModePlan, Rules: permission.Rules{Deny: []permission.Rule{permission.MustRule("Read(private/**)")}}}fmt.Println(policy.AllowsRead("main.go"))fmt.Println(policy.AllowsRead("private/key.txt"))fmt.Println(policy.AllowsRead(".zelk/config.json"))// Output:// true// false// falseOutput:
truefalsefalsePolicy.AllowsTool
Section titled “Policy.AllowsTool”func (p Policy) AllowsTool(name string) boolAllowsTool reports whether the tool is within the policy’s ceiling.
Policy.Amend
Section titled “Policy.Amend”func (p Policy) Amend(rules ...Rule) PolicyAmend returns p with additional session allow rules.
Policy.Authorized
Section titled “Policy.Authorized”func (p Policy) Authorized() []ModeAuthorized returns the modes the session may select, ordered by authority.
Policy.Narrow
Section titled “Policy.Narrow”func (p Policy) Narrow(child Policy) (Policy, error)Narrow combines p with a child policy, refusing any widening of authority.
Example
session := permission.Policy{ Mode: permission.ModeBypass, Modes: []permission.Mode{permission.ModePlan, permission.ModeBypass},}// An exploring subagent asks for plan mode and two tools.child, err := session.Narrow(permission.Policy{Mode: permission.ModePlan, Tools: []string{"Read", "Grep"}})if err != nil { panic(err)}fmt.Println(child.Mode, child.Modes, child.Tools)
// It can never get back what its parent didn't give it._, err = child.Narrow(permission.Policy{Mode: permission.ModeBypass})fmt.Println(err)// Output:// plan [plan] [Grep Read]// policy can only narrow: mode "bypass" is wider than "plan"Output:
plan [plan] [Grep Read]policy can only narrow: mode "bypass" is wider than "plan"Policy.Validate
Section titled “Policy.Validate”func (p Policy) Validate() errorValidate reports whether the policy can be enforced.
type Rule = engine.RuleRule is a parsed tool, command, path or URL permission rule.
MustRule
Section titled “MustRule”func MustRule(text string) RuleMustRule parses text and panics if it is invalid, for static host configuration.
ParseRule
Section titled “ParseRule”func ParseRule(text string) (Rule, error)ParseRule parses a tool name or a tool pattern with an argument constraint.
type Rules = engine.RulesRules are the deny, human-only, ask and allow rule sets.