policy

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package policy enforces path resolution, symlink guards, sensitive file protection, and Antigravity CLI settings.json permission rules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsApprovalRequired

func IsApprovalRequired(err error) bool

IsApprovalRequired reports whether err indicates an interactive approval gate.

Types

type Decision

type Decision string

Decision represents the outcome of evaluating a capability operation.

const (
	DecisionAllow Decision = "allow"
	DecisionAsk   Decision = "ask"
	DecisionDeny  Decision = "deny"
)

type Engine

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

func NewEngine

func NewEngine(workspaceDir string, extraRoots ...string) *Engine

NewEngine creates a policy engine rooted at workspaceDir and aligned with ~/.gemini/antigravity-cli/settings.json.

func NewEngineWithOptions

func NewEngineWithOptions(workspaceDir string, opts Options) *Engine

NewEngineWithOptions creates a policy engine with explicit host profile options.

func (*Engine) CheckCommand

func (e *Engine) CheckCommand(cmdLine string) error

CheckCommand validates a shell command against CLI permission rules and the built-in guard. Order: user deny rules > built-in guard (APPROVAL_REQUIRED) > user ask rules > user allow rules. The built-in guard is a best-effort guardrail, not a security boundary (see guards.go).

func (*Engine) CheckMCP

func (e *Engine) CheckMCP(server, tool string) error

CheckMCP validates external MCP bridge invocations against mcp(server/tool) rules.

func (*Engine) LoadSettingsJSON

func (e *Engine) LoadSettingsJSON(raw []byte)

LoadSettingsJSON loads CLI or desktop policy JSON directly (useful for testing and custom configs). Subsequent calls override AllowNonWorkspaceAccess if set and append permission rules.

func (*Engine) NativeEscalationHint

func (e *Engine) NativeEscalationHint() bool

NativeEscalationHint reports whether interactive-approval errors should mention native host tools.

func (*Engine) ResolveAndCheckRead

func (e *Engine) ResolveAndCheckRead(baseDir, targetPath string) (string, error)

ResolveAndCheckRead resolves path against baseDir and checks read permissions.

func (*Engine) ResolveAndCheckStrictCwd added in v0.4.0

func (e *Engine) ResolveAndCheckStrictCwd(baseDir, targetDir string) (string, error)

ResolveAndCheckStrictCwd resolves a working directory (`cwd`) when `--strict-root` is active, enforcing that `cwd` resides strictly inside `[workspaceDir, ...ExtraRoots]` (never `/tmp` or outside roots).

func (*Engine) ResolveAndCheckWrite

func (e *Engine) ResolveAndCheckWrite(baseDir, targetPath string) (string, error)

ResolveAndCheckWrite resolves path against baseDir and enforces workspace & .git confinement.

func (*Engine) TrustWorkspaceMCP

func (e *Engine) TrustWorkspaceMCP() bool

TrustWorkspaceMCP reports whether MCP servers declared in `<workspace>/.agents/mcp_config.json` may be spawned. Off by default: a cloned repository must not be able to make the sandbox launch arbitrary processes. Enable with `AGY_PTC_TRUST_WORKSPACE_MCP=1` or `"agyPtcTrustWorkspaceMcp": true` in an agy-ptc policy.json.

type Options

type Options struct {
	ExtraRoots            []string
	StrictWorkspace       bool     // force allowNonWorkspaceAccess = false (confine to workspaceRoots)
	TrustWorkspaceMCP     bool     // allow <workspace>/.agents/mcp_config.json
	PolicyFiles           []string // explicit JSON policy files to load in order
	ProtectedFiles        []string // additional config files (e.g. --mcp-config) protected against sandbox writes
	LoadAntigravityConfig bool     // load ~/.gemini/antigravity-cli/settings.json & ~/.gemini/config/agy-ptc/policy.json & PLUGIN_DATA/policy.json
	NativeEscalationHint  bool     // include "; run it via native run_command" in DecisionAsk messages
	SensitivePaths        []string // extra paths denied for BOTH read and write (e.g. <data-dir>/oauth-server token store)
}

Engine enforces workspace confinement, sensitive file guards, and Antigravity CLI settings.json rules. Options configures a policy Engine for either standalone MCPlex or Antigravity plugin mode.

type PolicyError

type PolicyError struct {
	Decision     Decision
	Action       string
	Target       string
	Reason       string
	NoNativeHint bool
}

PolicyError is returned when an operation is blocked or requires host interactive approval.

func (*PolicyError) Detail

func (e *PolicyError) Detail() string

Detail is the one-line message without the kind word: `<target> — <reason>[; <how to proceed>]`.

func (*PolicyError) Error

func (e *PolicyError) Error() string

func (*PolicyError) Kind

func (e *PolicyError) Kind() string

Kind implements sandbox.KindedError: guest code sees `e.name` "NeedsApproval" or "Denied".

Jump to

Keyboard shortcuts

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