permissions

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 20 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 implements the daemon's permission gate: it evaluates planned tool invocations against workspace policies, the active permission mode, safety classifications, and allow/deny rules, minting a github.com/masterkeysrd/tasksmith/api.PermissionRequest whenever a human decision is required.

Core Types

An api.Permissions value is a pair of allow and deny rule lists. Rules follow the "tool(pattern)" syntax produced by FormatRule and parsed by ParseRule, and are matched against a github.com/masterkeysrd/tasksmith/internal/daemon/tools.Plan by MatchRule.

Two managers are exposed:

Rule Syntax & Matching

A rule names a tool and a glob-like pattern over the plan's target. Matching ([matchTarget]) supports exact equality, the wildcard "*" and "?", single-segment "*" and multi-segment "**" globs (via [globToRegex]), the directory-prefix "dir/**" form, and URL host matching when the target parses as a URL. DeriveGrantRules turns a planned invocation into candidate grant patterns for a github.com/masterkeysrd/tasksmith/api.PermissionRequest.GrantPatterns field.

Scopes & Persistence

api.PermissionScope values bound where rules live:

Manager.Get, Manager.Set, Manager.AddRule, and Manager.RemoveRule operate on the project and global scopes; an api.ScopeSession argument is rejected with ErrInvalidScope. Writes are validated (ValidatePermissions) and deduplicated before being flushed to disk.

Evaluation Flow

SessionManager.Evaluate resolves a github.com/masterkeysrd/tasksmith/internal/daemon/tools.Plan through a fixed precedence:

  1. The tool policy ceiling is the stricter of the workspace tool policies (SessionManager.SetPolicies, a warp.Policies) and the active agent's tool policies (SessionManager.SetAgentPolicies); the two are combined with warp.StricterToolPolicyAction into a monotonic `allow < ask < deny` ceiling. Each warp.ToolPolicies covers `readOnly`, `dangerous`, `openWorld`, `include`, `exclude`, and `ask` (the last three match short names, `namespace/name`, and fully-qualified tool patterns). A `deny` ceiling denies the plan outright; an `ask` ceiling forces approval unless a matching user allow rule grants it.
  2. Deny rules take precedence: any matching deny rule (session, project, or global) yields a denial.
  3. Restricted (untrusted) workspaces deny non-read-only plans (except safe writes inside the session's plans directory).
  4. Safe writes inside `<session-dir>/plans/` are auto-allowed.
  5. The active mode and matching allow rules decide auto-approval: github.com/masterkeysrd/tasksmith/api.ModeAuto allows everything; github.com/masterkeysrd/tasksmith/api.ModeDefault, github.com/masterkeysrd/tasksmith/api.ModePlan, and github.com/masterkeysrd/tasksmith/api.ModeAsk share the same base permission gate (safe read-only plans and matching safe allow rules); and github.com/masterkeysrd/tasksmith/api.ModeAcceptEdits additionally auto-approves non-unsafe write actions.
  6. Otherwise a UUIDv7 github.com/masterkeysrd/tasksmith/api.PermissionRequest is minted and an "ask" decision is returned.

Decisions

SessionManager.ApplyDecision records a user's github.com/masterkeysrd/tasksmith/api.PermissionDecision: github.com/masterkeysrd/tasksmith/api.DecisionAllowOnce is a no-op, github.com/masterkeysrd/tasksmith/api.DecisionAllowSession appends an allow rule at the decision's scope, and github.com/masterkeysrd/tasksmith/api.DecisionReject returns github.com/masterkeysrd/tasksmith/internal/daemon/tools.ErrPermissionDenied.

Integration

github.com/masterkeysrd/tasksmith/internal/daemon/session.Session holds a Manager and attaches a SessionManager per root session (via Manager.Attach, or derives an isolated agent-policy view for delegated subagents via SessionManager.ForSubagent), which the github.com/masterkeysrd/tasksmith/internal/daemon/harness graph consumes as its permission gate through SessionManager.Evaluate.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidConfig = errors.New("permissions: invalid configuration")
	ErrInvalidRule   = errors.New("permissions: invalid rule")
	ErrInvalidScope  = errors.New("permissions: invalid scope")
)

Sentinel errors returned by the permissions package.

Functions

func DeriveGrantRules

func DeriveGrantRules(toolName string, action api.ActionType, target string) []string

DeriveGrantRules generates candidate "tool(pattern)" permission rules suitable for PermissionRequest.GrantPatterns based on action and target.

func EvaluatePolicy

func EvaluatePolicy(plan *tools.Plan, wsPolicies, agentPolicies *warp.Policies, ws *workspace.Workspace) warp.ToolPolicyAction

EvaluatePolicy computes the effective warp.ToolPolicyAction for plan by combining the workspace policy ceiling with the active agent's policy ceiling, returning the stricter of the two (allow < ask < deny).

func FormatRule

func FormatRule(toolName, pattern string) string

FormatRule builds a normalized "tool(pattern)" rule string, defaulting an empty pattern to "*".

func IsUnsandboxedToolName

func IsUnsandboxedToolName(name string) bool

IsUnsandboxedToolName reports whether rule tool names target the unsandboxed execution namespace.

func MatchRule

func MatchRule(rule string, plan *tools.Plan) bool

MatchRule checks whether rule matches the planned tool invocation.

func ParseRule

func ParseRule(raw string) (toolName, pattern string, err error)

ParseRule parses a permission rule string in "tool(pattern)" format into its constituent tool name and pattern components.

func UnsandboxedToolName

func UnsandboxedToolName(toolName string) string

UnsandboxedToolName maps a regular tool name to the rule namespace its unsandboxed bypass plans are matched and granted under. Keeping unsandboxed execution in a separate namespace means a regular bash(git *) allow rule can never auto-approve a bypass_sandbox retry; users must grant bash_unsandboxed(git *) explicitly.

func UpdateGlobal

func UpdateGlobal(defaultMode api.PermissionMode) error

UpdateGlobal updates the user global permissions default mode.

func ValidatePermissions

func ValidatePermissions(p api.Permissions) error

ValidatePermissions checks that every rule in Allow and Deny conforms to the "tool(pattern)" syntax.

Types

type Config

type Config struct {
	Workspace  *workspace.Workspace
	GlobalPath string // optional override for tests; defaults to filepath.Join(xdg.ConfigDir(), "permissions.json")
}

Config configures the root permission Manager.

type FileAccessChecker

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

FileAccessChecker evaluates workspace file and directory read access against repository internals (.git, .bare), secret/sensitive path guards, explicit deny rules (session, project, and global), tool policy ceilings, and canonical symlink targets.

func NewFileAccessChecker

func NewFileAccessChecker(cfg FileAccessConfig) *FileAccessChecker

NewFileAccessChecker constructs a reusable FileAccessChecker from cfg, pre-resolving canonical WorkDir symlinks and effective deny rules once.

func (*FileAccessChecker) Check

func (c *FileAccessChecker) Check(path, displayPath string, isDir bool) error

Check verifies that path (displayed in error messages as displayPath when non-empty) may be read or listed as a workspace file or directory.

type FileAccessConfig

type FileAccessConfig struct {
	WorkDir   string
	Workspace *workspace.Workspace
	Manager   Manager
	Session   SessionManager
}

FileAccessConfig configures a FileAccessChecker for workspace file and directory read checks.

type Manager

type Manager interface {
	Get(scope api.PermissionScope) (api.Permissions, error)
	Set(scope api.PermissionScope, perms api.Permissions) error
	Effective() (api.Permissions, error)
	AddRule(scope api.PermissionScope, effect api.PermissionEffect, rule string) error
	RemoveRule(scope api.PermissionScope, effect api.PermissionEffect, rule string) error
	Attach(mode api.PermissionMode, initial api.Permissions, onUpdate func(api.Permissions) error) SessionManager
}

Manager coordinates global and project-level permission persistence and attaches session-scoped permission managers.

func New

func New(cfg Config) (Manager, error)

New constructs a Manager configured for the given workspace.

type RuntimePolicy

type RuntimePolicy struct {
	// AutoAllowBash auto-approves safe, sandboxed bash plans in default and
	// accept_edits modes. It never widens plan/ask modes, unsandboxed plans,
	// or anything unsafe, outside, denied, or rule-asked.
	AutoAllowBash bool
	// SandboxNative reports whether the session's enforced backend is the
	// kernel sandbox; autoAllowBash only applies when it is.
	SandboxNative bool
}

RuntimePolicy carries the live, per-session posture the permission engine consults beyond static permission files. It is refreshed whenever sandbox settings change so edits apply to running sessions without recreation.

type SessionManager

type SessionManager interface {
	Mode() api.PermissionMode
	SetMode(mode api.PermissionMode)
	Permissions() api.Permissions
	Policies() *warp.Policies
	SetPolicies(p *warp.Policies)
	AgentPolicies() *warp.Policies
	SetAgentPolicies(p *warp.Policies)
	// SetPlansDir registers the session-scoped safe plans directory
	// (<session-dir>/plans/) where agent write/edit/remove operations are
	// auto-allowed and remain writable even in restricted workspaces.
	SetPlansDir(dir string)
	// SetRuntimePolicy installs the live sandbox posture consulted while
	// evaluating bash plans (autoAllowBash). A nil policy clears it, which
	// disables autoAllowBash widening.
	SetRuntimePolicy(p *RuntimePolicy)
	// RuntimePolicy returns the live sandbox posture, or nil when unset.
	RuntimePolicy() *RuntimePolicy
	// SetWorkspace binds permission and restriction checks to ws.
	SetWorkspace(ws *workspace.Workspace)
	ForSubagent() SessionManager
	AddAllow(rule string) error
	AddDeny(rule string) error
	Clear() error
	ApplyDecision(req *api.PermissionRequest, decision api.PermissionDecision) error
	Evaluate(plan *tools.Plan) (tools.AccessDecision, *api.PermissionRequest, error)
}

SessionManager manages permission evaluation, permission modes, and session-scoped permission rules.

func NewSession

func NewSession(mode api.PermissionMode, initial api.Permissions, onUpdate func(api.Permissions) error) SessionManager

NewSession constructs a detached SessionManager without an underlying root manager.

Jump to

Keyboard shortcuts

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