Skip to main content

PolicyEngine

Struct PolicyEngine 

Source
pub struct PolicyEngine { /* private fields */ }
Expand description

Applies constraints, mode and policy to one command, and builds the card that would unblock it.

Implementations§

Source§

impl PolicyEngine

Source

pub fn new(config: &OrchestratorConfig) -> Self

Builds an engine from a configuration, with the built-in copy and no review diff.

Source

pub fn with_copy(self, copy: ConfirmationCopy) -> Self

Replaces the copy on the cards the policy engine raises.

§The shipped default is English, and only English

Not a placeholder: it is real copy, it renders, and a deployment that never calls this ships it to every user in every locale. That is the failure worth naming here, because nothing goes wrong until a user in another language reads a sentence the rest of the product would never have written — which is how it was found.

A LocalizedText carries a default plus one string per locale, so supplying your own is additive rather than a rewrite: start from english() and use LocalizedText::with to add the languages you answer in.

Source

pub fn with_review_diff(self, diff: Arc<dyn ReviewDiffBuilder>) -> Self

Replaces the review diff builder.

use turnframe_core::interaction::ReviewDiffEntry;
use turnframe_runtime::config::OrchestratorConfig;
use turnframe_runtime::policy::PolicyEngine;
use std::sync::Arc;

let engine = PolicyEngine::new(&OrchestratorConfig::conservative())
    .with_review_diff(Arc::new(|_: &turnframe_runtime::policy::PolicyRequest<'_>| {
        vec![ReviewDiffEntry::new("name", "Name")]
    }));
assert!(format!("{engine:?}").starts_with("PolicyEngine"));
Source

pub fn mode(&self) -> &OrchestrationMode

The orchestration mode the engine gates on.

Source

pub fn review_diff(&self, request: &PolicyRequest<'_>) -> Vec<ReviewDiffEntry>

The diff a review card would show for request.

Source

pub fn decide( &self, snapshot: &PolicySnapshot, request: &PolicyRequest<'_>, constraints: &[ConstraintKind], ) -> PolicyOutcome

Decides one command against snapshot and the turn’s constraints.

See the module documentation for the order of the gates.

Source

pub fn confirmation_card( &self, key: impl Into<String>, case_ref: &CaseRef, policy: &CommandPolicy, command_refs: Vec<CommandRef>, diff: Vec<ReviewDiffEntry>, subject: Option<ConfirmationSubject>, ) -> Option<InteractionSpec>

The card whose answer satisfies policy, or None when the end user cannot supply the confirmation at all.

None comes back for ConfirmationPolicy::None (nothing to confirm) and for ConfirmationPolicy::HumanProfessionalReview (offering the user a card would let them approve themselves).

The card always carries a confirming CTA that authorizes exactly command_refs and a declining CTA, so refusing is always possible (I6). A InteractionKind::ReviewChanges card with an empty diff degrades to InteractionKind::ConfirmCommand, which ConfirmationPolicy::ReviewCard accepts just as well.

Source

pub fn selection_card( &self, key: impl Into<String>, case_ref: &CaseRef, title: LocalizedText, cancel_label: LocalizedText, candidates: &[TargetCandidate], ) -> Option<InteractionSpec>

The card that lets the user pick between ambiguous targets (§12.3).

Returns None when there are fewer than two candidates — a selection with one answer is not a selection — or more than InteractionConfig::max_selection_candidates, because truncating the list would let list order decide which cases the user may reach (I8).

Trait Implementations§

Source§

impl Clone for PolicyEngine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PolicyEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more