Skip to main content

AdvisorCatalogue

Struct AdvisorCatalogue 

Source
pub struct AdvisorCatalogue {
    pub version: u32,
    pub capabilities: Vec<AdvisoryCapability>,
    pub advisors: Vec<AdvisorDeclaration>,
    pub peers: Option<PeerAdvisors>,
    pub forbidden_claims: Vec<String>,
}
Expand description

The whole catalogue, as share/advisors.yaml declares it: the capability vocabulary, the advisors in preference order, how mesh peers become advisors, and the claims no document may assert. The default is the empty catalogue a share without the file has.

use majordomus_cli::reasoning::catalogue::AdvisorCatalogue;

let empty = AdvisorCatalogue::default();
assert!(empty.advisors.is_empty() && empty.get("anything").is_none());
let c: AdvisorCatalogue = majordomus_cli::metadata::yaml::parse_into(
    "version: 1\nforbidden_claims: [consensus guarantees correctness]\n",
).unwrap();
assert_eq!(c.forbidden_claims, ["consensus guarantees correctness"]);

Fields§

§version: u32

The format version.

§capabilities: Vec<AdvisoryCapability>

The advisory capability vocabulary.

§advisors: Vec<AdvisorDeclaration>

The advisors, in preference order.

§peers: Option<PeerAdvisors>

Linked mesh runtimes as advisors, when declared.

§forbidden_claims: Vec<String>

Phrases no document of the repository may assert: the claims this design refuses (“consensus guarantees correctness”), checked by reasoning.check.

Implementations§

Source§

impl AdvisorCatalogue

Source

pub fn load(share: &Path) -> Result<Self, String>

Read <share>/advisors.yaml. An absent file is an empty catalogue: a distribution that declares no advisors has none, and reasoning works without them. A file that does not parse is an error naming it.

use majordomus_cli::reasoning::catalogue::{AdvisorCatalogue, ADVISORS_FILE};

let share = tempfile::tempdir().unwrap();
assert!(AdvisorCatalogue::load(share.path()).unwrap().advisors.is_empty());
std::fs::write(share.path().join(ADVISORS_FILE), "version: one\n").unwrap();
let refused = AdvisorCatalogue::load(share.path()).unwrap_err();
assert!(refused.contains(ADVISORS_FILE));
Source

pub fn references(share: &Path, providers: &ProviderDeclarations) -> References

The references the catalogue resolves against: the provider ids the index already read, and the model catalogue of the same share (empty when it cannot be read).

use majordomus_cli::reasoning::catalogue::AdvisorCatalogue;
use majordomus_cli::share::{ProviderDeclaration, ProviderDeclarations};

let share = tempfile::tempdir().unwrap();
let providers = ProviderDeclarations {
    providers: vec![ProviderDeclaration { id: "tool".into(), ..Default::default() }],
    ..Default::default()
};
let refs = AdvisorCatalogue::references(share.path(), &providers);
assert_eq!(refs.providers, ["tool"]);
assert!(refs.models.vendors.is_empty());
Source

pub fn get(&self, id: &str) -> Option<&AdvisorDeclaration>

The declared advisor of an id; None for an id the catalogue does not declare, which includes every peer: id.

use majordomus_cli::reasoning::catalogue::AdvisorCatalogue;

let c: AdvisorCatalogue = majordomus_cli::metadata::yaml::parse_into(
    "version: 1\nadvisors:\n  - id: a\n    title: A\n    transport: cli\n    adapter: a-cli\n",
).unwrap();
assert_eq!(c.get("a").map(|a| a.title.as_str()), Some("A"));
assert!(c.get("peer:n1-r1").is_none());
Source

pub fn knows_capability(&self, word: &str) -> bool

Whether a word is in the declared capability vocabulary: what reasoning.plan checks a requested capability against before it plans.

use majordomus_cli::reasoning::catalogue::AdvisorCatalogue;

let c: AdvisorCatalogue = majordomus_cli::metadata::yaml::parse_into(
    "version: 1\ncapabilities:\n  - id: code_review\n    description: x\n",
).unwrap();
assert!(c.knows_capability("code_review"));
assert!(!c.knows_capability("telepathy"));
Source

pub fn credential_of<'a>( &self, advisor: &AdvisorDeclaration, refs: &'a References, ) -> Option<&'a str>

The credential variable whose presence says an API advisor is configured: its vendor’s, as the model catalogue declares it. Never a value, only a name. None for an advisor with no vendor, or whose vendor declares no variable.

use majordomus_cli::reasoning::catalogue::{AdvisorCatalogue, References};

let c: AdvisorCatalogue = majordomus_cli::metadata::yaml::parse_into("version: 1\ncapabilities:\n  - id: code_review\n    description: x\nadvisors:\n  - id: a\n    title: A\n    transport: api\n    adapter: a-api\n    vendor: acme\n    capabilities: [code_review]\n  - id: b\n    title: B\n    transport: cli\n    adapter: b-cli\n    executable: b\n    capabilities: [code_review]\n",
).unwrap();
let refs = References {
    models: majordomus_cli::metadata::yaml::parse_into("version: 1\nvendors:\n  - id: acme\n    title: Acme\n    credential_env: ACME_KEY\nmodels: []\n").unwrap(),
    ..Default::default()
};
assert_eq!(c.credential_of(c.get("a").unwrap(), &refs), Some("ACME_KEY"));
assert_eq!(c.credential_of(c.get("b").unwrap(), &refs), None);
Source

pub fn diagnostics(&self, refs: &References) -> Vec<String>

The catalogue’s own consistency: duplicate ids, words outside the vocabulary, a reference resolving to nothing, an advisor whose presence cannot be probed. Reported, never repaired; empty is the ordinary case.

use majordomus_cli::reasoning::catalogue::{AdvisorCatalogue, References};

let c: AdvisorCatalogue = majordomus_cli::metadata::yaml::parse_into(
    "version: 1\ncapabilities:\n  - id: code_review\n    description: x\nadvisors:\n  - id: a\n    title: A\n    transport: cli\n    adapter: a-cli\n    provider: nowhere\n    executable: a\n    capabilities: [code_review, telepathy]\n",
).unwrap();
let found = c.diagnostics(&References::default());
assert!(found.iter().any(|f| f.contains("provider 'nowhere'")));
assert!(found.iter().any(|f| f.contains("'telepathy'")));

Trait Implementations§

Source§

impl Clone for AdvisorCatalogue

Source§

fn clone(&self) -> AdvisorCatalogue

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 AdvisorCatalogue

Source§

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

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

impl Default for AdvisorCatalogue

Source§

fn default() -> AdvisorCatalogue

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

impl<'de> Deserialize<'de> for AdvisorCatalogue

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for AdvisorCatalogue

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for AdvisorCatalogue

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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
§

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

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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