pub struct ContractEngine {
pub file: ContractFile,
}Expand description
Core engine for contract operations.
Fields§
§file: ContractFileIn-memory contract file.
Implementations§
Source§impl ContractEngine
impl ContractEngine
Sourcepub fn from_file(file: ContractFile) -> Self
pub fn from_file(file: ContractFile) -> Self
Create from an existing contract file.
Sourcepub fn open(path: impl Into<PathBuf>) -> ContractResult<Self>
pub fn open(path: impl Into<PathBuf>) -> ContractResult<Self>
Open from path.
Sourcepub fn save(&self) -> ContractResult<()>
pub fn save(&self) -> ContractResult<()>
Save the contract file.
Sourcepub fn add_policy(&mut self, policy: Policy) -> ContractId
pub fn add_policy(&mut self, policy: Policy) -> ContractId
Add a policy.
Sourcepub fn check_policy(
&self,
action_type: &str,
scope: PolicyScope,
) -> PolicyAction
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.
Sourcepub fn list_policies(&self, scope: Option<PolicyScope>) -> Vec<&Policy>
pub fn list_policies(&self, scope: Option<PolicyScope>) -> Vec<&Policy>
List policies, optionally filtered by scope.
Sourcepub fn get_policy(&self, id: ContractId) -> ContractResult<&Policy>
pub fn get_policy(&self, id: ContractId) -> ContractResult<&Policy>
Get a policy by ID.
Sourcepub fn add_risk_limit(&mut self, limit: RiskLimit) -> ContractId
pub fn add_risk_limit(&mut self, limit: RiskLimit) -> ContractId
Add a risk limit.
Sourcepub fn check_risk_limit(
&self,
label_pattern: &str,
amount: f64,
) -> Option<&RiskLimit>
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.
Sourcepub fn increment_risk_limit(
&mut self,
id: ContractId,
amount: f64,
) -> ContractResult<()>
pub fn increment_risk_limit( &mut self, id: ContractId, amount: f64, ) -> ContractResult<()>
Increment a risk limit by label.
Sourcepub fn list_risk_limits(&self) -> &[RiskLimit]
pub fn list_risk_limits(&self) -> &[RiskLimit]
List all risk limits.
Sourcepub fn add_approval_rule(&mut self, rule: ApprovalRule) -> ContractId
pub fn add_approval_rule(&mut self, rule: ApprovalRule) -> ContractId
Add an approval rule.
Sourcepub fn request_approval(
&mut self,
rule_id: ContractId,
action_description: impl Into<String>,
requestor: impl Into<String>,
) -> ContractResult<ContractId>
pub fn request_approval( &mut self, rule_id: ContractId, action_description: impl Into<String>, requestor: impl Into<String>, ) -> ContractResult<ContractId>
Create an approval request.
Sourcepub fn decide_approval(
&mut self,
request_id: ContractId,
decision: DecisionType,
decider: impl Into<String>,
reason: impl Into<String>,
) -> ContractResult<ContractId>
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.
Sourcepub fn list_approval_requests(
&self,
status: Option<ApprovalStatus>,
) -> Vec<&ApprovalRequest>
pub fn list_approval_requests( &self, status: Option<ApprovalStatus>, ) -> Vec<&ApprovalRequest>
List approval requests, optionally filtered by status.
Sourcepub fn add_condition(&mut self, condition: Condition) -> ContractId
pub fn add_condition(&mut self, condition: Condition) -> ContractId
Add a condition.
Sourcepub fn evaluate_condition(
&self,
id: ContractId,
) -> ContractResult<ConditionStatus>
pub fn evaluate_condition( &self, id: ContractId, ) -> ContractResult<ConditionStatus>
Evaluate a condition (simplified: just check the status).
Sourcepub fn list_conditions(&self) -> &[Condition]
pub fn list_conditions(&self) -> &[Condition]
List all conditions.
Sourcepub fn add_obligation(&mut self, obligation: Obligation) -> ContractId
pub fn add_obligation(&mut self, obligation: Obligation) -> ContractId
Add an obligation.
Sourcepub fn check_obligation(
&self,
id: ContractId,
) -> ContractResult<ObligationStatus>
pub fn check_obligation( &self, id: ContractId, ) -> ContractResult<ObligationStatus>
Check obligation status.
Sourcepub fn fulfill_obligation(&mut self, id: ContractId) -> ContractResult<()>
pub fn fulfill_obligation(&mut self, id: ContractId) -> ContractResult<()>
Fulfill an obligation.
Sourcepub fn list_obligations(
&self,
status: Option<ObligationStatus>,
) -> Vec<&Obligation>
pub fn list_obligations( &self, status: Option<ObligationStatus>, ) -> Vec<&Obligation>
List obligations, optionally filtered by status.
Sourcepub fn report_violation(&mut self, violation: Violation) -> ContractId
pub fn report_violation(&mut self, violation: Violation) -> ContractId
Report a violation.
Sourcepub fn list_violations(
&self,
severity: Option<ViolationSeverity>,
) -> Vec<&Violation>
pub fn list_violations( &self, severity: Option<ViolationSeverity>, ) -> Vec<&Violation>
List violations, optionally filtered by severity.
Sourcepub fn policy_omniscience(
&self,
agent_id: &str,
context: &str,
) -> PolicyOmniscience
pub fn policy_omniscience( &self, agent_id: &str, context: &str, ) -> PolicyOmniscience
Get complete visibility into all applicable policies for an agent.
Sourcepub fn risk_prophecy(
&self,
agent_id: &str,
forecast_window_secs: i64,
) -> RiskProphecy
pub fn risk_prophecy( &self, agent_id: &str, forecast_window_secs: i64, ) -> RiskProphecy
Predict future risk budget usage.
Sourcepub fn approval_telepathy(&self, action: &str) -> ApprovalTelepathy
pub fn approval_telepathy(&self, action: &str) -> ApprovalTelepathy
Predict approval likelihood for an action.
Sourcepub fn obligation_clairvoyance(
&self,
agent_id: &str,
window_secs: i64,
) -> ObligationClairvoyance
pub fn obligation_clairvoyance( &self, agent_id: &str, window_secs: i64, ) -> ObligationClairvoyance
Forecast upcoming obligations and identify scheduling conflicts.
Sourcepub fn violation_precognition(
&self,
planned_action: &str,
) -> ViolationPrecognition
pub fn violation_precognition( &self, planned_action: &str, ) -> ViolationPrecognition
Detect potential violations before they occur.
Sourcepub fn crystallize_contract(&self, intent: &str) -> CrystallizedContract
pub fn crystallize_contract(&self, intent: &str) -> CrystallizedContract
Generate contract policies from a high-level intent description.
Sourcepub fn extract_policy_dna(
&self,
policy_id: ContractId,
) -> ContractResult<PolicyDna>
pub fn extract_policy_dna( &self, policy_id: ContractId, ) -> ContractResult<PolicyDna>
Extract the genetic representation of a policy.
Sourcepub fn evaluate_trust_gradient(
&self,
agent_id: &str,
action: &str,
) -> TrustGradient
pub fn evaluate_trust_gradient( &self, agent_id: &str, action: &str, ) -> TrustGradient
Evaluate an action with trust-weighted policy assessment.
Sourcepub fn create_collective_contract(
&self,
parties: Vec<(&str, &str)>,
arbitration_method: ArbitrationMethod,
) -> CollectiveContract
pub fn create_collective_contract( &self, parties: Vec<(&str, &str)>, arbitration_method: ArbitrationMethod, ) -> CollectiveContract
Create a multi-party collective governance contract.
Sourcepub fn create_temporal_contract(
&self,
label: &str,
initial_level: GovernanceLevel,
) -> TemporalContract
pub fn create_temporal_contract( &self, label: &str, initial_level: GovernanceLevel, ) -> TemporalContract
Create a time-evolving contract with governance transitions.
Sourcepub fn create_contract_inheritance(
&self,
parent_id: ContractId,
child_id: ContractId,
propagate: bool,
) -> ContractResult<ContractInheritance>
pub fn create_contract_inheritance( &self, parent_id: ContractId, child_id: ContractId, propagate: bool, ) -> ContractResult<ContractInheritance>
Create a hierarchical parent-child contract relationship.
Sourcepub fn smart_escalate(&self, description: &str, urgency: f64) -> SmartEscalation
pub fn smart_escalate(&self, description: &str, urgency: f64) -> SmartEscalation
Route an approval request to the optimal approver.
Sourcepub fn violation_archaeology(
&self,
agent_id: &str,
window_secs: i64,
) -> ViolationArchaeology
pub fn violation_archaeology( &self, agent_id: &str, window_secs: i64, ) -> ViolationArchaeology
Analyze violation patterns to identify root causes.
Sourcepub fn simulate_contract(&self, scenario_count: u32) -> ContractSimulation
pub fn simulate_contract(&self, scenario_count: u32) -> ContractSimulation
Simulate contract behavior across multiple scenarios.
Sourcepub fn create_federated_governance(
&self,
name: &str,
members: Vec<(&str, &str)>,
transparency: TransparencyLevel,
) -> FederatedGovernance
pub fn create_federated_governance( &self, name: &str, members: Vec<(&str, &str)>, transparency: TransparencyLevel, ) -> FederatedGovernance
Create cross-organizational federated governance.
Sourcepub fn create_self_healing_contract(
&self,
base_contract_id: ContractId,
) -> ContractResult<SelfHealingContract>
pub fn create_self_healing_contract( &self, base_contract_id: ContractId, ) -> ContractResult<SelfHealingContract>
Create a contract that automatically adapts to violations.
Sourcepub fn stats(&self) -> ContractStats
pub fn stats(&self) -> ContractStats
Get summary statistics.