Skip to main content

ContractEngine

Struct ContractEngine 

Source
pub struct ContractEngine {
    pub file: ContractFile,
}
Expand description

Core engine for contract operations.

Fields§

§file: ContractFile

In-memory contract file.

Implementations§

Source§

impl ContractEngine

Source

pub fn new() -> Self

Create a new engine with an empty contract file.

Source

pub fn from_file(file: ContractFile) -> Self

Create from an existing contract file.

Source

pub fn open(path: impl Into<PathBuf>) -> ContractResult<Self>

Open from path.

Source

pub fn save(&self) -> ContractResult<()>

Save the contract file.

Source

pub fn add_policy(&mut self, policy: Policy) -> ContractId

Add a policy.

Source

pub fn check_policy( &self, action_type: &str, scope: PolicyScope, ) -> PolicyAction

Check if an action is allowed under current policies.

Returns the most restrictive applicable policy action.

Source

pub fn list_policies(&self, scope: Option<PolicyScope>) -> Vec<&Policy>

List policies, optionally filtered by scope.

Source

pub fn get_policy(&self, id: ContractId) -> ContractResult<&Policy>

Get a policy by ID.

Source

pub fn add_risk_limit(&mut self, limit: RiskLimit) -> ContractId

Add a risk limit.

Source

pub fn check_risk_limit( &self, label_pattern: &str, amount: f64, ) -> Option<&RiskLimit>

Check if an action would exceed any risk limits.

Returns the first limit that would be exceeded, or None if OK.

Source

pub fn increment_risk_limit( &mut self, id: ContractId, amount: f64, ) -> ContractResult<()>

Increment a risk limit by label.

Source

pub fn list_risk_limits(&self) -> &[RiskLimit]

List all risk limits.

Source

pub fn add_approval_rule(&mut self, rule: ApprovalRule) -> ContractId

Add an approval rule.

Source

pub fn request_approval( &mut self, rule_id: ContractId, action_description: impl Into<String>, requestor: impl Into<String>, ) -> ContractResult<ContractId>

Create an approval request.

Source

pub fn decide_approval( &mut self, request_id: ContractId, decision: DecisionType, decider: impl Into<String>, reason: impl Into<String>, ) -> ContractResult<ContractId>

Decide on an approval request.

Source

pub fn list_approval_requests( &self, status: Option<ApprovalStatus>, ) -> Vec<&ApprovalRequest>

List approval requests, optionally filtered by status.

Source

pub fn add_condition(&mut self, condition: Condition) -> ContractId

Add a condition.

Source

pub fn evaluate_condition( &self, id: ContractId, ) -> ContractResult<ConditionStatus>

Evaluate a condition (simplified: just check the status).

Source

pub fn list_conditions(&self) -> &[Condition]

List all conditions.

Source

pub fn add_obligation(&mut self, obligation: Obligation) -> ContractId

Add an obligation.

Source

pub fn check_obligation( &self, id: ContractId, ) -> ContractResult<ObligationStatus>

Check obligation status.

Source

pub fn fulfill_obligation(&mut self, id: ContractId) -> ContractResult<()>

Fulfill an obligation.

Source

pub fn list_obligations( &self, status: Option<ObligationStatus>, ) -> Vec<&Obligation>

List obligations, optionally filtered by status.

Source

pub fn report_violation(&mut self, violation: Violation) -> ContractId

Report a violation.

Source

pub fn list_violations( &self, severity: Option<ViolationSeverity>, ) -> Vec<&Violation>

List violations, optionally filtered by severity.

Source

pub fn policy_omniscience( &self, agent_id: &str, context: &str, ) -> PolicyOmniscience

Get complete visibility into all applicable policies for an agent.

Source

pub fn risk_prophecy( &self, agent_id: &str, forecast_window_secs: i64, ) -> RiskProphecy

Predict future risk budget usage.

Source

pub fn approval_telepathy(&self, action: &str) -> ApprovalTelepathy

Predict approval likelihood for an action.

Source

pub fn obligation_clairvoyance( &self, agent_id: &str, window_secs: i64, ) -> ObligationClairvoyance

Forecast upcoming obligations and identify scheduling conflicts.

Source

pub fn violation_precognition( &self, planned_action: &str, ) -> ViolationPrecognition

Detect potential violations before they occur.

Source

pub fn crystallize_contract(&self, intent: &str) -> CrystallizedContract

Generate contract policies from a high-level intent description.

Source

pub fn extract_policy_dna( &self, policy_id: ContractId, ) -> ContractResult<PolicyDna>

Extract the genetic representation of a policy.

Source

pub fn evaluate_trust_gradient( &self, agent_id: &str, action: &str, ) -> TrustGradient

Evaluate an action with trust-weighted policy assessment.

Source

pub fn create_collective_contract( &self, parties: Vec<(&str, &str)>, arbitration_method: ArbitrationMethod, ) -> CollectiveContract

Create a multi-party collective governance contract.

Source

pub fn create_temporal_contract( &self, label: &str, initial_level: GovernanceLevel, ) -> TemporalContract

Create a time-evolving contract with governance transitions.

Source

pub fn create_contract_inheritance( &self, parent_id: ContractId, child_id: ContractId, propagate: bool, ) -> ContractResult<ContractInheritance>

Create a hierarchical parent-child contract relationship.

Source

pub fn smart_escalate(&self, description: &str, urgency: f64) -> SmartEscalation

Route an approval request to the optimal approver.

Source

pub fn violation_archaeology( &self, agent_id: &str, window_secs: i64, ) -> ViolationArchaeology

Analyze violation patterns to identify root causes.

Source

pub fn simulate_contract(&self, scenario_count: u32) -> ContractSimulation

Simulate contract behavior across multiple scenarios.

Source

pub fn create_federated_governance( &self, name: &str, members: Vec<(&str, &str)>, transparency: TransparencyLevel, ) -> FederatedGovernance

Create cross-organizational federated governance.

Source

pub fn create_self_healing_contract( &self, base_contract_id: ContractId, ) -> ContractResult<SelfHealingContract>

Create a contract that automatically adapts to violations.

Source

pub fn stats(&self) -> ContractStats

Get summary statistics.

Trait Implementations§

Source§

impl Default for ContractEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.