Skip to main content

Crate action_gate_core

Crate action_gate_core 

Source
Expand description

action-gate-core: a pure, deterministic decision gate over an ordered Check registry.

Gate::evaluate runs its checks in registration order and returns the first check’s Some(decision), or an unconditional Decision::allow if none triggers. It is a pure function of (context, checks): no host calls, no clock, unit-testable, and byte-stable via decision_to_canonical_json. Determinism depends on check ordering being stable, which the builder guarantees (insertion order).

That is the default, Mode::Open. A gate built with GateBuilder::closed or GateBuilder::require evaluates in Mode::Closed instead: it denies when no check decides, and every required check must be registered and must decide. See Mode and the closed module for the rules and reason codes.

§Config is in the checks, not a global bundle

There is no global policy-bundle type here. Each check owns its parameters (a secrets check owns its regex set, an allowlist owns its list). The consumer assembles the gate:

use action_gate_core::{Gate, checks::{AllowlistCheck, SecretsCheck}};
use action_gate_types::ActionContext;

let gate = Gate::builder()
    .check(SecretsCheck::default())
    .check(AllowlistCheck::new(["email.send", "email.draft"]))
    .build();

let decision = gate.evaluate(&ActionContext::new("email.send"));
assert!(decision.is_allow());

§Degrade is a signal, not an action

Outcome::Degrade does not perform a degraded action. The gate returns it; the consumer decides its meaning (route to a human, require confirmation). The gate never touches the world.

Modules§

closed
The stable reason codes a Mode::Closed gate produces itself (spec 004 B-6). A check’s own decision keeps the check’s reason.
secrets
The secret detector registry (spec 001).

Structs§

ActionContext
Everything a Check needs to make its decision about a proposed action.
Decision
The result a Check returns and the Gate yields.
DenyByDefault
A terminal check that denies whatever reached it (spec 001 B-14).
Evaluation
Everything Gate::evaluate_exhaustive found: the decision Gate::evaluate returns, and every deny along the way.
Gate
A pure decision gate over an ordered list of checks.
GateBuilder
Builds a Gate by registering checks in evaluation order.

Enums§

Mode
How a Gate combines its checks’ answers (spec 004).
Outcome
The three possible outcomes of a decision.

Traits§

Check
A single gate check.

Functions§

decision_to_canonical_json
Serialize a decision to canonical (key-sorted) JSON, for byte-stable hashing and comparison. Two producers serializing the same logical decision produce the same bytes regardless of serde_json’s preserve_order state.
sha256_hex
sha256:<hex> over bytes. The sha256: prefix keeps the hash self-describing, matching the ledger primitive in attest-ledger.