permission

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package permission owns the coding product's tool authorization policy. It describes tool effects, resolves filesystem scope, and asks an approver when the session mode cannot allow an operation automatically.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access struct {
	Action       Action
	Path         string
	ResolvedPath string
	Location     Location
	Sensitive    SensitiveKind
}

Access is one effect of a validated tool call. Filesystem tools fill Path; Service fills ResolvedPath, Location, and Sensitive before authorization.

type Action

type Action string

Action describes the kind of access a tool call performs.

const (
	Read     Action = "read"
	Write    Action = "write"
	Execute  Action = "execute"
	Network  Action = "network"
	Internal Action = "internal"
)

type ApprovalChoice

type ApprovalChoice string

ApprovalChoice is the user's response to an approval request.

const (
	AllowOnce ApprovalChoice = "allow_once"
	Reject    ApprovalChoice = "deny"
)

type ApprovalRequest

type ApprovalRequest struct {
	Request Request
	Reason  string
}

ApprovalRequest is sent to the product surface when authorization needs the user's decision.

type ApprovalResponse

type ApprovalResponse struct {
	Choice ApprovalChoice
}

ApprovalResponse is deliberately extensible beyond a boolean so later milestones can add session grants without replacing the transport contract.

type Approver

type Approver interface {
	Decide(context.Context, ApprovalRequest) (ApprovalResponse, error)
}

Approver obtains a user decision. Implementations must honor ctx cancellation so aborting a run cannot leave a tool preflight blocked.

type Location

type Location string

Location describes where a filesystem access resolves relative to the session workspace.

const (
	LocationUnknown  Location = "unknown"
	Workspace        Location = "workspace"
	OutsideWorkspace Location = "external"
)

type Mode

type Mode string

Mode is the session-wide baseline applied before any one-off approval.

const (
	ModeAsk        Mode = "ask"
	ModeAutoEdit   Mode = "auto_edit"
	ModeFullAccess Mode = "full_access"
)

func NormalizeMode

func NormalizeMode(mode Mode) Mode

NormalizeMode keeps missing or unknown persisted values on the conservative default. API handlers still reject invalid values supplied by clients.

func (Mode) Valid

func (mode Mode) Valid() bool

Valid reports whether mode is accepted from a client or persisted record.

type PathResolver

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

PathResolver classifies filesystem targets against one canonical workspace.

func NewPathResolver

func NewPathResolver(workspace string) (PathResolver, error)

NewPathResolver canonicalizes workspace, including symlinks when possible.

func (PathResolver) Resolve

func (r PathResolver) Resolve(access Access) Access

Resolve enriches a filesystem access with its canonical target and scope. An uncertain target stays LocationUnknown so authorization requires approval.

type Request

type Request struct {
	ToolCallID string
	Tool       string
	Args       map[string]any
	Accesses   []Access
}

Request is the complete permission input for one validated tool call.

type Result added in v0.6.9

type Result struct {
	Allowed bool
	Reason  string
}

Result is the final authorization outcome after any required approval.

type SensitiveKind added in v0.6.2

type SensitiveKind string

SensitiveKind classifies a filesystem target that needs approval on its own merits, independent of where it sits. A secret inside the workspace is still a secret, so Location alone cannot decide these.

const (
	// NotSensitive is an ordinary file, judged only by Location.
	NotSensitive SensitiveKind = ""
	// SecretFile customarily holds credentials. Reading one puts its contents
	// into the model's context and the durable transcript, so it is never an
	// automatic workspace read.
	SecretFile SensitiveKind = "secret_file"
	// RepositoryInternals is Git's own state. Writing there changes what later
	// git commands do — hooks and config select programs to execute — so it is
	// not an ordinary workspace edit even when edits are enabled.
	RepositoryInternals SensitiveKind = "repository_internals"
)

func ClassifySensitive added in v0.6.2

func ClassifySensitive(path string) SensitiveKind

ClassifySensitive reports whether path needs approval on its own merits. It matches on names alone: it never opens the file, so it is cheap enough to run on every resolved access and cannot be defeated by the file's contents.

It is deliberately generous. The outcome of a match is one approval prompt, so a false positive costs a click while a false negative leaks a credential.

type Service

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

Service resolves tool effects, applies the session mode, and coordinates interactive approval without coupling the reusable agent loop to product permissions.

func NewService

func NewService(workspace string, mode Mode, approver Approver) (*Service, error)

NewService creates one authorization service for a session workspace.

func (*Service) Authorize

func (s *Service) Authorize(ctx context.Context, req Request) (Result, error)

Authorize returns the final result for a validated tool call.

func (*Service) SetMode added in v0.6.9

func (s *Service) SetMode(mode Mode)

SetMode changes the permission mode used by subsequent calls. Product code changes it only while a session is idle; the lock also keeps direct callers safe.

Jump to

Keyboard shortcuts

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