Skip to main content

Module policy

Module policy 

Source
Expand description

Context Policy Packs v1 — Policies-as-Code (GL #489).

A policy pack is a declarative, versioned governance preset: which tools an agent may call, the default read mode, redaction patterns for sensitive data, an audit-retention expectation and a context-budget cap. Packs are plain TOML, support single inheritance via extends, and resolve into one ResolvedPolicy a team can review like code.

v1 ships the format, validation, resolution, curated built-ins and the lean-ctx policy CLI (see cli::policy_cmd). Runtime enforcement wires in afterward (deliberately decoupled so this module stays free of hot-path churn — see the contract docs/contracts/context-policy-packs-v1.md).

Inheritance semantics are security-first and predictable:

  • scalars (default_read_mode, max_context_tokens, audit_retention_days) — the child overrides when set;
  • deny_tools and [redaction]accumulate down the chain (restrictions inherited from a parent can never be silently dropped; a child may only tighten or re-point a named redaction pattern);
  • allow_tools — the child overrides when set (an allowlist is a deliberate posture choice, not an accumulating set).

Modules§

builtin
Curated built-in policy packs (GL #489), embedded at compile time.
coverage
CGB coverage — automated partial assessment of a resolved policy pack against the Context Governance Benchmark v1.0-draft (GL #426).
floor
Org-floor merge (GL #674) — fold a central org policy underneath the local project pack so the local pack can only ever tighten, never weaken it.
org
Central, signed org policy distribution (GL #674).
runtime
Runtime view of the active context policy pack (GL #673 / #489 enforcement).

Structs§

BudgetRules
The [budgets] section — hard org spend caps (enterprise#25, Doc 08 §4.3). USD amounts against the measured cost_usd of the usage meter; breaching a cap makes the gateway refuse further requests (429) until the window rolls.
ContextRules
The [context] section of a pack. All fields optional — only what a pack states is constrained; everything else stays at engine defaults.
EgressRules
The [egress] section — output/DLP enforcement on agent writes & actions (GL #676). Gates ctx_edit writes and ctx_shell actions before they execute. Compiled into a crate::core::egress::EgressConfig at load time.
FilterRules
The [filters] section — inbound content detectors (GL #675). Each action is one of off / warn / redact / block (absent ⇒ off). Compiled into a crate::core::input_filters::FilterConfig at load time and run on tool output before it reaches the agent.
PolicyPack
One policy pack as written in TOML. Unknown keys are rejected so a typo (alow_tools) fails validation instead of silently weakening a policy.
ResolvedPolicy
A pack with its full extends chain folded in — what enforcement and policy show consume.
RoutingPolicyRules
The [routing] section — org gateway routing governance (enterprise#25, Doc 08 §4.3). Enforced in the gateway forward path when this pack arrives via a signed, trusted, enforced = true org::OrgPolicyV1.

Enums§

PolicyError
Why a pack failed to parse, validate or resolve. Rendered verbatim by the CLI, so every variant names the offending field and value.

Constants§

KNOWN_READ_MODES
Read modes a pack may pin as default_read_mode — the documented ctx_read mode vocabulary (range reads like lines:N-M are call-site specific and make no sense as a policy default).

Functions§

load
Parse + validate + resolve in one step — the common CLI path.
parse
Parse one pack from TOML text (no I/O) and validate it standalone. extends is checked against the built-ins during resolve.
parse_file
Parse a pack from a file path. Read errors surface as PolicyError::Toml with the OS message — the CLI shows them verbatim.
resolve
Fold a pack’s extends chain (against the built-ins) into one ResolvedPolicy. See the module docs for the inheritance semantics.
validate
Field-level validation of a single (unresolved) pack.