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: u32The 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
impl AdvisorCatalogue
Sourcepub fn load(share: &Path) -> Result<Self, String>
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));Sourcepub fn references(share: &Path, providers: &ProviderDeclarations) -> References
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());Sourcepub fn get(&self, id: &str) -> Option<&AdvisorDeclaration>
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());Sourcepub fn knows_capability(&self, word: &str) -> bool
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"));Sourcepub fn credential_of<'a>(
&self,
advisor: &AdvisorDeclaration,
refs: &'a References,
) -> Option<&'a str>
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);Sourcepub fn diagnostics(&self, refs: &References) -> Vec<String>
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
impl Clone for AdvisorCatalogue
Source§fn clone(&self) -> AdvisorCatalogue
fn clone(&self) -> AdvisorCatalogue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AdvisorCatalogue
impl Debug for AdvisorCatalogue
Source§impl Default for AdvisorCatalogue
impl Default for AdvisorCatalogue
Source§fn default() -> AdvisorCatalogue
fn default() -> AdvisorCatalogue
Source§impl<'de> Deserialize<'de> for AdvisorCatalogue
impl<'de> Deserialize<'de> for AdvisorCatalogue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for AdvisorCatalogue
impl JsonSchema for AdvisorCatalogue
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more