Skip to main content

CapabilityRegistry

Struct CapabilityRegistry 

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

Every capability, once, validated, in id order, with the lookups projections need.

Implementations§

Source§

impl CapabilityRegistry

Source

pub fn builder() -> Builder

Start composing a registry.

use majordomus_cli::capability::{builtin, CapabilityRegistry, RegistryError};
let registry = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
assert!(registry.get("repository.info").is_some());
assert_eq!(registry.by_mcp_tool("majordomus_get").unwrap().id.as_str(), "objects.get");
// the same executables twice: every id is claimed twice, and the registry says so
let twice = CapabilityRegistry::builder().with_builtin(builtin::all()).with_builtin(builtin::all()).build();
let errors = twice.unwrap_err();
assert!(errors.iter().all(|e| matches!(e, RegistryError::DuplicateId { .. })));
Source

pub fn iter(&self) -> impl Iterator<Item = &Capability>

Every capability, by id.

Source

pub fn len(&self) -> usize

How many capabilities the registry holds.

Source

pub fn is_empty(&self) -> bool

Does the registry hold nothing?

Source

pub fn modules(&self) -> impl Iterator<Item = &ModuleInfo>

Every module, by id: the composed ones, the derived ones, and one per declarative kind.

Source

pub fn module(&self, id: &str) -> Option<&ModuleInfo>

One module by id.

Source

pub fn cases(&self, id: &str) -> Option<CaseProvider>

The benchmark case provider of an executable; None for a resource or an unknown id.

Source

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

A capability by canonical id.

Source

pub fn by_mcp_tool(&self, name: &str) -> Option<&Capability>

The capability an MCP tool name projects.

Source

pub fn by_mcp_uri(&self, uri: &str) -> Option<(&Capability, &McpResource)>

The capability an MCP resource URI projects, with the resource exposure it matched: a declarative object, or a query read as a document (majordomus://repository).

use majordomus_cli::capability::{builtin, CapabilityKind, CapabilityRegistry};
let r = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
let (c, res) = r.by_mcp_uri(builtin::REPOSITORY_URI).unwrap();
assert_eq!((c.id.as_str(), c.kind, res.name.as_str()), ("repository.info", CapabilityKind::Query, "repository"));
assert!(r.by_mcp_uri("majordomus://rule/none@1").is_none());
Source

pub fn by_http(&self, method: HttpMethod, path: &str) -> Option<&Capability>

The capability an HTTP method and path project.

Source

pub fn by_cli(&self, path: &[String]) -> Option<&Capability>

The capability a CLI path projects.

Source

pub fn by_skill(&self, alias: &str) -> Option<&Capability>

The capability a skill alias names, when one declares it.

use majordomus_cli::capability::{builtin, CapabilityRegistry};
let r = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
// `/intent <sentence>` is intents.propose, because its declaration says so
assert_eq!(r.by_skill("intent").map(|c| c.id.as_str()), Some("intents.propose"));
assert!(r.by_skill("no-such-alias").is_none());
Source

pub fn skills(&self) -> impl Iterator<Item = &Capability>

Every capability that declares a skill, by alias.

use majordomus_cli::capability::{builtin, CapabilityRegistry};
let r = CapabilityRegistry::builder().with_builtin(builtin::all()).build().unwrap();
let aliases: Vec<&str> =
    r.skills().filter_map(|c| c.skill.as_ref()).map(|s| s.alias.as_str()).collect();
// few by design: a skill is for what a person types by name, not for every tool
assert!(aliases.contains(&"intent"));
let mut ordered = aliases.clone();
ordered.sort_unstable();
assert_eq!(aliases, ordered, "by alias");
Source

pub fn fingerprint(&self) -> &str

The fingerprint of this registry and the repository state it was built from.

Source

pub fn dispatch( &self, ctx: &Context, id: &str, input: Value, ) -> Result<Value, CapabilityError>

Run the handler of an executable by id, with no counters and no cache: the raw dispatch the executor wraps. Everything else calls Context::execute. A resource, or an unknown id, is NotFound.

Source

pub fn summary(&self) -> Summary

Counts by kind, by stability and by projection, for introspection.

Trait Implementations§

Source§

impl Debug for CapabilityRegistry

Source§

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

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

impl Default for CapabilityRegistry

Source§

fn default() -> CapabilityRegistry

Returns the “default value” for a type. 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> 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, 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