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§

audit_filter
Privacy-preserving audit of content-filter decisions (GL #675).
builtin
Curated built-in policy packs (GL #489), embedded at compile time.
content
Shared, local policy decision before content is released or persisted.
coverage
CGB coverage — automated partial assessment of a resolved policy pack against the Context Governance Benchmark v1.0-draft (GL #426).
diagnostics
Project-bound diagnostic storage. Inspect complete fields before rendering previews, and resolve current rules only after the writer owns its lock.
files
Bounded reads for policy and trust inputs. Errors never include file content.
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.
hive_filters
The installed Hive filter set as policy rules: <data_dir>/hive/policy/filters/set.json, written only by the Hive connector after it verified a policy bundle (signed packs, digests, complete validation, at most HIVE_MAX_RULES rules). This side only reads it: the policy snapshot applies its patterns (filter_rules) and refuses a set that is not as signed (required_packs_installed).
hive_floor
The Hive effective policy as a floor of the gateway policy engine (Release B 3.1.4).
hive_io
The I/O members of the Hive effective policy (ent2-3): security.readable_roots and security.never_send.
org
Org-level policy distribution (ADR-023, 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.
model_allowed_by_ceilings
model_pattern_matches
Glob-lite matching shared by project admission and the gateway.
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