permission

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 7 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 permission decides whether a tool call may run: allow, ask, or deny, from rules shaped as opencode writes them (ADR 0002). It is pure: the rules come recorded with a turn, so the same call gets the same decision when the turn resumes, whatever the files say by then (AGENTS.md, invariant 2).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(glob, s string) bool

Match reports whether s matches glob, where * matches any run of characters (slashes and spaces included) and ? any one character.

Types

type Action

type Action string
const (
	Allow Action = "allow"
	Ask   Action = "ask"
	Deny  Action = "deny"
)

type Decision

type Decision struct {
	Action Action `json:"action"`
	Rule   string `json:"rule,omitempty"`
}

Decision is what the rules say of one call, and which rule said it.

func Decide

func Decide(rules []Rule, tool, subject string) Decision

Decide applies rules (layers in order: defaults, then the user's, then the project's) to a call of tool on subject. The last matching rule wins; with none, the call asks.

type Pattern

type Pattern struct {
	Glob   string `json:"glob"`
	Action Action `json:"action"`
}

type Rule

type Rule struct {
	Tool     string    `json:"tool"`
	Action   Action    `json:"action,omitempty"`
	Patterns []Pattern `json:"patterns,omitempty"`
}

Rule is one entry of a "permission" value: for the tools whose name matches Tool, Action, or, when Patterns is set, the action of each pattern that matches the call's subject (a bash command, a file path).

func Parse

func Parse(raw json.RawMessage) ([]Rule, error)

Parse reads a "permission" value, keeping its order: of the rules that match a call, the last one wins.

"allow"
{"*": "ask", "read": "allow"}
{"bash": {"*": "ask", "git status*": "allow", "rm *": "deny"}}

Jump to

Keyboard shortcuts

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