Policy and verdict decisions
Policy turns the command safety engine's findings into a decision that a caller can enforce. It defines which policy is trusted, which findings may be hidden or changed, when a human or native authority must approve an operation, and how the final result becomes allow, warn, or block.
Policy sources and trust
Policy discovery selects an operator-controlled baseline before it considers repository settings. The resolver checks TIRITH_POLICY_ROOT/…/policy.yaml, then walks from the current directory to the repository boundary for .tirith/policy.yaml, and then checks the user policy; if no file exists, built-in defaults apply. A discovered source is marked as org, repo, user, remote, or default from the discovery path rather than from YAML content. See the command safety engine for how the loaded policy enters analysis.
Repository policy is an untrusted tightening overlay. It can add blocks, detections, approval gates, and stricter scan limits, but it cannot remove trusted protections, suppress findings, enable bypass, or redirect policy data. The effective-policy view reports the source, trust scope, and fields that the repository policy tried to weaken.
The policy loader treats a named but unreadable or invalid policy as a configuration failure. It uses a fail-closed policy that blocks the operation instead of silently replacing the broken file with permissive defaults. A missing policy is different: it uses the built-in default policy.
Remote policy is an operator-controlled replacement when its endpoint and credential are valid. The fetch requires a safe HTTPS server and a bounded response. A configured fetch mode chooses local policy, a cached policy, or a fail-closed policy when the remote service is unavailable; authentication failures always fail closed. Cached policy is bound to the endpoint and credential identity, then passes through the same parse and migration path as a fresh response.
References: crates/…/policy.rs• L57-73 crates/…/policy.rs• L1340-1551 crates/…/policy.rs• L2246-2333 crates/…/policy.rs• L3107-3177 crates/…/policy_client.rs• L28-102
Repository tightening
Repository policy is merged monotonically. A monotonic merge means the overlay can move protection toward stricter behavior but cannot move it toward weaker behavior. Additive controls such as block patterns, custom rules, denial rules, package checks, and approval rules survive the merge; suppression controls and remote or webhook destinations do not.
The same trust rule applies to repository flat lists and thresholds. A repository blocklist can add restrictions, while a repository allowlist is ignored. Repository scan settings can add coverage or raise a coverage-gap action, but they cannot hide scan paths or lower the CI failure threshold. Package policy is merged field by field, so a repository can add package checks or make thresholds stricter without replacing the trusted package policy.
The loader records repository settings that it neutralizes in neutralized_fields. This gives the operator a clear account of ignored weakening attempts without allowing those settings to affect the effective policy. Policy changes that affect decisions are also included in a redacted security projection. The projection excludes credentials and machine paths while binding decision-changing list contents and overrides, so a receipt or related record can identify the policy posture without exposing policy secrets.
References: crates/…/policy.rs• L1554-1707 crates/…/policy.rs• L1709-1778 crates/…/policy.rs• L1808-1957 crates/…/policy.rs• L1959-2087 crates/…/policy.rs• L2032-2297 crates/…/policy.rs• L3303-3465
Policy document lifecycle
Policy loading uses one shared document path so enforcement and tirith policy validate interpret versions in the same way. The path parses YAML, migrates the raw document, deserializes the policy, and then checks load-time invariants before the policy can affect a decision.
The lifecycle has these stages:
- Read the selected policy with size and file-type limits.
- Parse the YAML document.
- Detect the schema version. An omitted version means version 1.
- Apply each registered forward migration to the raw YAML.
- Reject malformed or newer-than-supported versions.
- Deserialize the migrated document into the policy model.
- Reject load-time shapes that would otherwise become silent no-ops.
This diagram shows how one policy document becomes an effective policy or a safe failure.
flowchart LR
A[Selected policy source] --> B[Bounded read]
B --> C[YAML parse]
C --> D[Version check]
D --> E[Forward migration]
E --> F[Typed policy load]
F --> G[Load-time checks]
G --> H[Effective policy]
B --> I[Fail-closed policy]
C --> I
D --> I
E --> I
F --> I
G --> I
References: crates/…/policy.rs• L1305-1338 crates/…/policy.rs• L2277-2363 crates/…/policy_migrations.rs• L1-17
Schema migration
Migrations update raw YAML before typed loading because typed deserialization can discard unknown fields. The current migration moves the old top-level internal_package_names list into the structured package_policy.internal_package_names form. The migration is forward-only and idempotent, so repeated processing does not duplicate entries.
A malformed explicit version is an error rather than an old version. A version newer than the running binary also fails with an upgrade message. This prevents a new policy field from being silently lost by an older engine.
References: crates/…/policy_migrations.rs• L8-17 crates/…/policy_migrations.rs• L19-29 crates/…/policy_migrations.rs• L36-129 crates/…/policy_migrations.rs• L133-199
Policy validation
tirith policy validate is a diagnostic gate for a whole policy file. It reports parse, migration, schema, range, reference, conflict, and pattern errors as errors or warnings. Errors make the policy invalid; warnings, such as unknown fields or an allowlist/blocklist overlap, do not.
Validation shares the runtime parse and migration path, then checks that policy references can work at run time. It checks rule IDs, approval fallbacks, paranoia bounds, network entries, custom-rule shape and context, regular expressions, scan settings, package thresholds, and other cross-field constraints. Unknown fields are reported with their nested path instead of being silently ignored. Package age, score, advisory, typosquat, and internal-name settings are checked for valid ranges and safe relationships.
tirith policy init creates a starter policy. tirith policy test applies the effective policy to a command or file and reports the resulting findings and action. tirith policy effective shows the resolved local policy and its trust scope without fetching a remote policy. These surfaces help distinguish the written policy from the policy that actually governs a decision.
References: crates/…/policy_validate.rs• L1-104 crates/…/policy_validate.rs• L106-149 crates/…/policy_validate.rs• L151-305 crates/…/policy_validate.rs• L376-401 crates/…/policy_validate.rs• L480-627 crates/…/policy_ignored.rs• L13-26 crates/…/policy.rs• L255-397 crates/…/policy.rs• L501-601 crates/…/policy.rs• L731-862
Finding suppression and adjustment
The engine first collects findings, then applies policy effects that can change the effective finding set or its severity. Suppression is narrow: a URL allowlist can remove a finding only when all URLs in its evidence are allowlisted, and a per-rule allowlist can scope that decision to one rule or custom rule. A blocklist match adds a critical policy finding, and any blocklisted URL keeps related findings even if it also matches an allowlist.
Severity overrides change the level used to derive the action. They cannot lower a protected integrity or malicious-supply-chain finding below High. Action overrides support only an upgrade to Block. Paranoia then controls which lower-severity findings remain visible: levels 1 and 2 keep Medium and above, level 3 also keeps Low, and level 4 also keeps Info.
The engine always performs detection before the paranoia display filter. This keeps policy visibility separate from detection coverage. If an override or approval caused a stronger action, the finalizer keeps the causal finding available so a blocking result does not appear without an explanation.
References: crates/…/engine.rs• L3174-3238 crates/…/engine.rs• L3279-3317 crates/…/policy.rs• L2383-2407 crates/…/policy.rs• L2763-2787 crates/…/verdict.rs• L888-935 crates/…/verdict.rs• L2053-2069 crates/…/escalation.rs• L263-360
Repeated-warning suppression
Repeated-warning suppression is a session-backed display feature, not a policy bypass. It collapses only findings that are Warn-class on their own and only when the overall result is Warn or WarnAck. High and Critical findings remain visible, and the underlying verdict, exit code, audit record, approval data, and session accounting remain unchanged.
The suppression key uses the rule and an available target such as a domain. The session stores the expiry so separate hook or CLI processes share the same window. A collapsed hit emits a finding_suppressed audit rollup, so the user can review the suppressed activity rather than losing it.
References: crates/…/suppression.rs• L1-53 crates/…/session_warnings.rs• L407-462 crates/…/check.rs• L38-131 crates/…/check.rs• L595-615
Approval and warning acknowledgement
Approval rules attach a human approval requirement to findings with matching rule IDs. The first matching finding supplies the approval reason, timeout, and fallback. When several rules match, their contracts combine toward the stricter fallback and the longer wait; a non-CLI caller cannot prompt and therefore turns a pending approval into Block.
Approval is evaluated after action overrides and agent denial rules, but before paranoia filtering and warning history. This order prevents a denied caller from carrying an approval request and prevents a filtered causal finding from removing the approval contract. Approval metadata is carried on the verdict and can be passed to a shell hook through a protected short-lived file or an owned execution receipt.
An approval timeout uses the configured block, warn, or allow fallback. Missing or malformed fallback data is treated as Block at the execution boundary. strict_warn gives ordinary warnings an acknowledgement step: an interactive CLI asks the user, while hook-driven mode returns WarnAck and provides acknowledgement metadata.
This diagram shows the policy decision path for a finding that may need a human decision.
flowchart TD
A[Raw findings] --> B[Severity and action overrides]
B --> C[Agent deny check]
C -->|Denied| D[Block]
C -->|Not denied| E[Approval rule check]
E -->|No match| F[Paranoia filter]
E -->|Match, CLI| G[Approval prompt]
E -->|Match, non-CLI| D
G -->|Approved| F
G -->|Rejected or timed out| H[Fallback action]
H --> F
F --> I[Final verdict]
References: crates/…/approval.rs• L46-153 crates/…/approval.rs• L156-255 crates/…/escalation.rs• L381-547 crates/…/check.rs• L493-531 crates/…/check.rs• L578-640 crates/…/check.rs• L815-830
Native package approval
Native package approval is a separate authority check for an exact package install plan. A trusted authority signs the plan and its short validity window; the execution side accepts it only when the signature, authority key, time bounds, and requested plan all match. A digest by itself is data, not proof of approval.
The displayed and stored request identity excludes the authority-chosen expiry. This lets a renewed grant refer to the same requested plan while the signed record still binds its own issue and expiry times. The approval is therefore tied to the package inputs and execution context rather than to a broad package name or an earlier request.
References: crates/…/package_approval.rs• L16-62 crates/…/package_approval.rs• L64-145 crates/…/package_approval.rs• L149-209 crates/…/package_approval.rs• L211-327
Verdict resolution
A verdict is the enforceable result of analysis. It contains the action, findings, policy source, analysis metadata, bypass state, and any approval or escalation information that a caller needs to act safely. The rule detection system describes how findings are produced, while risk scoring and explanations describes how rule signals receive severity and operator-facing explanations; this page covers how policy uses those findings.
Package policy controls add findings for package age, downloads, advisories, name similarity, repository mismatch, and install-script risk. These findings enter the same severity-to-action path as command findings, so a package control can warn or block without creating a second verdict model.
The base action comes from the highest remaining finding severity:
| Finding state | Base action |
|---|---|
| No findings or Info only | Allow |
| Low or Medium | Warn |
| High or Critical | Block |
The complete command path then applies policy in a monotonic order. Monotonic means a later control may preserve or strengthen a decision, but it must not weaken a decision that an earlier security control caused.
- Apply per-rule action upgrades.
- Apply caller-origin denial rules.
- Attach approval metadata, or block non-interactive callers that cannot obtain approval.
- Apply paranoia filtering without downgrading an override- or approval-caused action.
- Apply session-based escalation, such as repeated findings or several Medium findings.
- Add cross-event correlation findings and repeat the monotonic policy effects for those new findings.
- Record warning and hidden-finding outcomes for later session decisions.
Static scans use the same severity, action-override, and paranoia rules but do not use session approval or history. This keeps file, package, and artifact results aligned with command results without inventing an interactive step where none exists.
References: crates/…/verdict.rs• L188-233 crates/…/verdict.rs• L913-935 crates/…/verdict.rs• L1013-1163 crates/…/verdict.rs• L1084-1109 crates/…/verdict.rs• L2053-2069 crates/…/policy.rs• L1414-1503 crates/…/escalation.rs• L286-360 crates/…/escalation.rs• L453-547 crates/…/escalation.rs• L698-807
Session escalation
Escalation turns a warning into Block when the policy sees a repeated rule or a high density of Medium-or-higher findings. Repeat rules can use a time window and can scope counts to a domain. A multi-medium rule counts the current command's qualifying findings. Escalation actions support only Block, so history cannot weaken a current result.
Correlation adds findings from event sequences such as a secret write followed by network egress. Because those findings are discovered after the first policy pass, the engine reapplies action overrides, approval, and paranoia to the augmented set. It does not repeat caller denial or session escalation, which avoids duplicate denial findings and repeated state effects.
References: crates/…/escalation.rs• L19-59 crates/…/escalation.rs• L76-249 crates/…/escalation.rs• L549-696
Bypass and fail-closed behavior
The verdict records whether a bypass was requested, whether policy makes that bypass available, and whether it was honored. Interactive and non-interactive bypass permissions are separate policy choices. A repository policy cannot enable them, and an active incident disables both while forcing fail-closed behavior.
Fail-closed behavior is used when the system cannot establish a valid effective policy or when a protected caller cannot obtain approval. It produces a blocking finding that explains the unavailable policy, rather than returning a clean Allow with no cause.
References: crates/…/engine.rs• L3264-3274 crates/…/policy.rs• L2246-2271 crates/…/policy.rs• L2409-2444 crates/…/escalation.rs• L476-491 crates/…/package_approval.rs• L211-271
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the runtime parse, migration, and load-validation path aligned with
tirith policy validate; a new field must not load in one path and fail or disappear in the other. - Classify every new policy field as trusted, tightening-only, suppression-capable, or inert in repository scope before adding it to the policy merge. Preserve the
neutralized_fieldsrecord for settings that the effective policy ignores. - Keep severity floors and action overrides in the shared finalization paths used by command checks, static scans, package findings, correlation findings, and safe-command verification.
- If a finding can trigger approval or escalation, keep its stable
RuleIdand ensure the verdict retains the causal finding after filtering. - If a package approval record changes, keep the expiry-independent request projection, signed record, trusted authority key, and exact install-plan binding consistent across the issuing and checking sides.
- If a policy field changes the security decision, bind its value in the redacted security projection without adding secrets or machine paths.
- Preserve the distinction between display suppression and verdict suppression; repeated-warning collapse must not affect blocking, exit codes, approval files, or audit records.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Repository policy contains a weakening allowlist, severity override, or package threshold | A checkout could hide its own unsafe command or weaken package checks | Repository policy is sanitized and merged as tightening-only; ignored fields are recorded |
| Named policy is unreadable, malformed, or has an unsupported future schema | The operation must not continue under unknown policy semantics | The loader returns a fail-closed policy |
| A policy field is unknown or a custom rule has an invalid shape | The operator may think a control is active when the engine ignores it | Validation reports nested unknown fields and rejects silent no-op rule shapes |
| URL matches both allowlist and blocklist | Allowing the URL could defeat an explicit block | The blocklist adds a Critical finding and takes precedence |
| Approval is required in a gateway, daemon, or other non-CLI caller | No human can complete the approval prompt | Pending approval becomes Block outside the CLI |
| A protected integrity finding receives a Low or Medium severity override | A malicious or tampered artifact could proceed as a warning | The shared severity override clamps protected rules to High |
| A package approval record has an unknown authority, bad signature, expired time, or changed plan | An old or forged grant could authorize a different install | Verification requires a trusted key, valid time bounds, a valid signature, and an exact plan match |
| Repeated warning is suppressed in the display | The user may not see the same warning again in the current window | Only Warn-class display entries are collapsed and a finding_suppressed audit rollup is written |
| Remote policy response is invalid, oversized, or from a failed authentication | The engine could use unsafe or untrusted policy data | Response limits, validation, endpoint binding, and fail-closed authentication handling |
Key files
| File | Why to read it |
|---|---|
| crates/…/policy.rs | Defines policy sources, defaults, trust scope, repository merging, ignored-field reporting, package controls, and runtime overrides. |
| crates/…/policy_migrations.rs | Defines schema version handling and forward policy migration. |
| crates/…/policy_validate.rs | Shows the whole-policy validation contract and its error-versus-warning model. |
| crates/…/policy_ignored.rs | Shows how unknown policy fields are found and reported with nested paths. |
| crates/…/policy_client.rs | Defines remote policy fetch limits and failure categories. |
| crates/…/engine.rs | Shows blocklist findings, URL suppression, policy metadata, and paranoia filtering in the analysis result. |
| crates/…/verdict.rs | Defines findings, package policy rule IDs, severity floors, actions, and the verdict contract. |
| crates/…/escalation.rs | Defines final policy ordering, static verdict finalization, approvals, escalation, and correlation reprocessing. |
| crates/…/approval.rs | Defines policy approval matching and the handoff data used by CLI and shell callers. |
| crates/…/package_approval.rs | Defines signed native-authority approval records for exact package install plans. |
| crates/…/suppression.rs | Defines session cooldown keys and expiry behavior for repeated warning display. |
| crates/…/session_warnings.rs | Connects cooldown suppression to session state and audit rollups. |
| crates/…/policy.rs | Exposes policy initialization, validation, effective-policy inspection, and policy testing. |
| crates/…/check.rs | Shows how the finalized verdict reaches display, approval, warning acknowledgement, and exit behavior. |