agentpolicy

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package agentpolicy generates the AGENT-SIDE half of a run's autonomy level: the managed-settings document an agent CLI reads before it will honour — or refuse — its own launch flags. The control-plane half only constrains what POST /runs will ACCEPT; this package is the agent-side expression of a level, and is PURE — no I/O, no server state.

SECURITY invariant: each level's document is a FROZEN LITERAL, not a struct marshalled per call — byte for byte the file exercised against the pinned CLI (CLAUDE_CODE_VERSION 2.1.231), and testdata/ holds the same bytes so the golden test compares against evidence, not this file's own opinion. The one generated part is an interactive run's tool rules (WithToolRules): permissions.allow/ask/deny arrays of exact names written into a frozen document, plus allowManagedPermissionRulesOnly. A marshalled document carries an error path that would fail OPEN, so WithToolRules returns every error and its callers refuse the run; testdata/ holds the generated documents the pinned CLI was exercised with. Re-run the pinned-CLI checks on every CLI version bump — these keys are a contract with one vendor's parser, not a standard.

Index

Constants

View Source
const ClaudeCodeManagedSettingsPath = "/etc/claude-code/managed-settings.json"

ClaudeCodeManagedSettingsPath is where Claude Code reads its managed (enterprise-policy) settings on Linux. Two directories deep by necessity: the parent is the k8s mount point, so a file directly under /etc would mount over the image's own /etc.

Variables

This section is empty.

Functions

func AcceptsEdits added in v0.9.0

func AcceptsEdits(content []byte) bool

AcceptsEdits reports whether content starts the session in acceptEdits mode, where Claude Code runs a file edit without asking.

func CheckToolRules added in v0.9.0

func CheckToolRules(rules []types.ToolRule) error

CheckToolRules reports the first rule WithToolRules could not write, so a door can refuse a run before dispatch would.

func DisablesBypass added in v0.9.0

func DisablesBypass(content []byte) bool

DisablesBypass reports whether content locks bypass mode off, so an interactive run under it can never skip asking (the console's attended_no_skip).

func ForAgent

func ForAgent(agent string, level types.AutonomyLevel, hold, locked bool) (path string, content []byte, ok bool)

ForAgent returns the managed-settings file a run's agent should launch under at level, or ok=false when this run gets no agent-side layer. content is the exact file body, trailing newline included. hold is whether the run is on agent-run's hold lane. locked is the governance rubric's agent_guardrail_locks term; it selects the locked document at L2 and is ignored at every other level. ok=false is ORDINARY for any agent but claude-code, and for the two rungs that constrain nothing — not an error.

func HoldTakesOver

func HoldTakesOver(level types.AutonomyLevel, locked bool) bool

HoldTakesOver reports whether a hold run at level gets L1's document instead of what its level brings: no level, and the rungs whose own answer leaves the gate unprotected (L3 no file, L2 no allowManagedPermissionRulesOnly — which the locked L2 document carries).

func IsLocked added in v0.9.0

func IsLocked(content []byte) bool

IsLocked reports whether content is the locked L2 document, so callers name the variant from the document ForAgent actually chose rather than re-deciding the selection.

func WithToolRules added in v0.9.0

func WithToolRules(doc []byte, rules []types.ToolRule) ([]byte, error)

WithToolRules writes an interactive run's tool rules into doc (nil: the attended base, for a level that brings no document) as Claude Code's own permission rules, sorted, with allowManagedPermissionRulesOnly so no repository or user rule answers a call first. "*" is not written: Claude Code has no rule for a tool nobody names, so the document's mode answers it (it asks). With no named rule, doc is returned as it came, nil included. Any error means the rules could not be written exactly, and the run must not launch.

Types

This section is empty.

Jump to

Keyboard shortcuts

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