Skip to main content

FormationCompiler

Struct FormationCompiler 

Source
pub struct FormationCompiler;

Implementations§

Source§

impl FormationCompiler

Source

pub fn new() -> Self

Source

pub fn compile( &self, request: &FormationCompileRequest, catalogs: &FormationCompilerCatalogs, ) -> Result<CompiledFormationPlan, FormationCompileError>

Source

pub fn compile_from_catalog( &self, request: &FormationCompileRequest, formation_templates: &FormationCatalog, catalog: &DiscoveryCatalog, providers: &ProviderDescriptorCatalog, advisory_order: Option<&[String]>, ) -> Result<CompiledFormationPlan, CatalogCompileFailure>

Catalog-aware compile. Sources Suggestor candidates from a DiscoveryCatalog using structural filters (DiscoveryCatalog::find_by_role / DiscoveryCatalog::find_by_capability), then applies the same deterministic coverage-and-affinity ranking as Self::compile.

The returned CompiledFormationPlan carries a structured per-role decision trace under CompiledFormationPlan::decisions, so callers can see why each capability was satisfied or left uncovered.

advisory_order is an optional ranked list of descriptor IDs from an out-of-band advisor (e.g. an LLM-backed [CatalogLookup]). The compiler uses it strictly as a tie-breaker after deterministic scoring — it cannot promote a candidate above one with better coverage or domain affinity. LLM output is advisory, never authority.

Source

pub fn compile_draft_from_catalog( &self, request: &FormationCompileRequest, formation_templates: &FormationCatalog, catalog: &DiscoveryCatalog, providers: &ProviderDescriptorCatalog, descriptor_ids: &[SuggestorDescriptorId], ) -> Result<CompiledFormationPlan, CatalogCompileFailure>

Exact-roster validator for a draft produced by an upstream deliberation Formation (see organism-dynamics).

Confirms every id in descriptor_ids is unique, resolves in catalog (returns FormationCompileError::DraftDescriptorMissing for the first missing one), and that the supplied roster covers the template’s required roles + capabilities (returns FormationCompileError::UncoveredRequirements otherwise). Does not greedy-reselect — the returned plan’s roster is exactly descriptor_ids in the supplied order.

This is intentionally distinct from Self::compile_from_catalog: the catalog-aware path picks the best roster from a pool; the draft validator honors an upstream Formation’s choice and only checks admissibility.

The returned CompiledFormationPlan carries a single RoleDecision per chosen descriptor under its decisions field, with empty considered (no candidate ranking happened) and chosen_role derived from the descriptor’s profile.

Source§

impl FormationCompiler

Source

pub fn compile_k_candidates( &self, request: &FormationCompileRequest, formation_templates: &FormationCatalog, catalog: &DiscoveryCatalog, providers: &ProviderDescriptorCatalog, k: usize, ) -> Result<Vec<CompiledFormationPlan>, CatalogCompileFailure>

Source up to k distinct candidate rosters from the same DiscoveryCatalog by iterative swap-out diversity.

After each candidate is compiled, the function tests whether excluding each chosen descriptor would still leave the catalog capable of satisfying the template — by running a trial Self::compile_from_catalog against the catalog minus the descriptor and the current exclude set. A descriptor is added to the exclude set for the next iteration only when the trial compile succeeds, i.e. the remaining catalog can still produce some valid roster without that descriptor (possibly via a compositional alternative — multiple other descriptors covering the slot collectively). This is stricter and more correct than the previous heuristic “shares one capability with another descriptor of the same role”, which could mis-classify a broad specialist as swappable even when it was the only provider of a separate required capability.

Stops early when the filtered catalog can no longer cover the formation requirements — that’s the graceful end of the pool, not an error. Returns whatever candidates were produced.

Returns the underlying CatalogCompileFailure only when the very first iteration fails (i.e. the catalog can’t satisfy the template even unfiltered). All later failures are absorbed as “pool exhausted” and the loop stops.

Cost. Per produced candidate, this runs 1 + roster_size compiles: one to produce the candidate, and one per chosen descriptor to test swappability. compile_from_catalog is pure metadata work (no executable instantiation), so the constant is small.

k = 0 is well-defined and returns Ok(vec![]). k = 1 is equivalent to a single Self::compile_from_catalog call.

Trait Implementations§

Source§

impl Debug for FormationCompiler

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FormationCompiler

Source§

fn default() -> FormationCompiler

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Adaptor<()> for T

Source§

fn adapt(&self)

Adapt the type to be passed to a metric.
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> 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> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T