policy

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package policy holds the gate.command-safety classifier's own deterministic command-safety consistency policy.

This is deliberately NOT Harness's PermissionReviewPolicy (github.com/looprig/harness/pkg/gate.PermissionReviewPolicy): that type is the consumer-owned, local decision ceiling Harness itself applies AFTER a classifier's assessment has been validated, and it independently re-derives eligibility from the assessment's Risk/Authorization/Categories using its own matrix. This package never touches that matrix and never grants, denies, or widens eligibility on its own.

Instead, Policy encodes this classifier's own closed-taxonomy decision structure — which risk floor a reported category implies, which category can never resolve to an eligible allow, and which authorization threshold this classifier itself expects at each risk level — as deterministic Go data rather than leaving that structure purely to prompt-following. Reconcile consumes an already strictly-decoded model assessment (as internal/wire produces it) and, before that assessment ever crosses this module's public boundary, tightens an inconsistent allow recommendation to needs_human. It never lowers a reported risk, never raises a reported authorization, and never turns an existing needs_human back into allow: it only ever moves toward the more conservative outcome.

Index

Constants

View Source
const DefaultRevision = "command-safety-policy/v1"

DefaultRevision is the initial command-safety policy revision. Per design §19.2 ("prompt, policy, schema, wire, and corpus revisions are independently explicit and included in classifier identity"), bump this whenever DefaultPolicy's taxonomy content changes meaning.

Variables

This section is empty.

Functions

func Reconcile

func Reconcile(p Policy, assessment gate.PermissionAssessment) gate.PermissionAssessment

Reconcile deterministically re-derives a fail-secure recommendation from an already strictly-decoded model assessment. An assessment that does not recommend allow is already the most conservative outcome and is returned unchanged. Otherwise, Reconcile checks, in order:

  1. A risk value outside the closed four-value gate.ReviewRisk enum (low/medium/high/critical) — including the zero value — always needs a human. Reconcile is a fail-secure function and must not depend on its caller having already enforced the closed enum (in production, internal/wire's strict decoders do, before Reconcile ever runs, but Reconcile itself must not rely on that): riskRank returns 0 for exactly this case and for no valid enum value, so this check and the critical-risk check below share one comparison.
  2. Critical risk always needs a human, regardless of category or authorization.
  3. Any category in p.AbsoluteHumanCategories always needs a human, at any authorization level.
  4. Any category in p.CategoryMinimumRisk whose floor exceeds the assessment's own reported risk is an internally inconsistent report and needs a human.
  5. The assessment's reported authorization must meet or exceed p.MinimumAuthorization for its reported risk.

Reconcile never lowers the reported risk, never raises the reported authorization, and never invents or drops a category: only Recommendation may change, and only from allow to needs_human.

Types

type Policy

type Policy struct {
	Revision string

	// CategoryMinimumRisk floors the risk every listed category implies. A
	// decoded assessment that selects a category from this table yet
	// reports a risk below that category's floor is internally
	// inconsistent — the reported risk understates what the model's own
	// category selection already claims — and Reconcile treats that
	// inconsistency as unsafe to auto-approve.
	CategoryMinimumRisk map[gate.ReviewRiskCategory]gate.ReviewRisk

	// AbsoluteHumanCategories can never resolve to an eligible allow from
	// this classifier, at any authorization level, including a strong,
	// post-warning authorization: a confirmed disclosure to an untrusted
	// destination, for example, is not made safe by user approval.
	AbsoluteHumanCategories map[gate.ReviewRiskCategory]struct{}

	// MinimumAuthorization is this classifier's own default minimum
	// authorization required at each risk level before recommending allow,
	// independent of category. It mirrors, but does not replace or
	// substitute for, Harness's own local ceiling.
	MinimumAuthorization map[gate.ReviewRisk]gate.ReviewAuthorization
}

Policy is the classifier's own deterministic command-safety consistency policy. Its zero value (no revision, nil tables) is a structurally valid "no additional tightening" policy; DefaultPolicy returns the populated, named default.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy returns the initial command-safety taxonomy policy. Tenant or product code may construct a stricter Policy value directly; this package places no floor on how conservative a caller-supplied Policy may be, only on how it is applied (Reconcile only ever tightens).

func (Policy) Clone

func (p Policy) Clone() Policy

Clone returns an independently owned copy sharing no backing map storage with the receiver.

Jump to

Keyboard shortcuts

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