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:
- Manager (created via New) coordinates the on-disk, cross-session persistence of project- and global-scope rules and binds per-session evaluators via Manager.Attach.
- SessionManager (created via Manager.Attach or the detached NewSession) owns the active github.com/masterkeysrd/tasksmith/api.PermissionMode, the in-memory session rules, and the SessionManager.Evaluate decision logic.
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:
- api.ScopeSession: in-memory only, owned by the SessionManager.
- api.ScopeProject: persisted under the workspace data directory (`<workspace-data-dir>/permissions.json`).
- api.ScopeGlobal: persisted under the user config directory (`<config-dir>/permissions.json`, resolved via xdg).
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:
- 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.
- Deny rules take precedence: any matching deny rule (session, project, or global) yields a denial.
- Restricted (untrusted) workspaces deny non-read-only plans (except safe writes inside the session's plans directory).
- Safe writes inside `<session-dir>/plans/` are auto-allowed.
- 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.
- 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 ¶
- Variables
- func DeriveGrantRules(toolName string, action api.ActionType, target string) []string
- func EvaluatePolicy(plan *tools.Plan, wsPolicies, agentPolicies *warp.Policies, ...) warp.ToolPolicyAction
- func FormatRule(toolName, pattern string) string
- func IsUnsandboxedToolName(name string) bool
- func MatchRule(rule string, plan *tools.Plan) bool
- func ParseRule(raw string) (toolName, pattern string, err error)
- func UnsandboxedToolName(toolName string) string
- func UpdateGlobal(defaultMode api.PermissionMode) error
- func ValidatePermissions(p api.Permissions) error
- type Config
- type FileAccessChecker
- type FileAccessConfig
- type Manager
- type RuntimePolicy
- type SessionManager
Constants ¶
This section is empty.
Variables ¶
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 ¶
FormatRule builds a normalized "tool(pattern)" rule string, defaulting an empty pattern to "*".
func IsUnsandboxedToolName ¶
IsUnsandboxedToolName reports whether rule tool names target the unsandboxed execution namespace.
func ParseRule ¶
ParseRule parses a permission rule string in "tool(pattern)" format into its constituent tool name and pattern components.
func UnsandboxedToolName ¶
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.
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.
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.