Skip to main content

bijux_cli/features/diagnostics/
routing_inventory.rs

1//! Read-only route and registry inventory queries for maintainer tooling.
2
3use serde::Serialize;
4
5use crate::contracts::NamespaceMetadata;
6use crate::routing::registry::RouteRegistry;
7
8/// Raw route inventory exposed to maintainer control-plane consumers.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
10pub struct RouteInventory {
11    /// Canonical built-in command paths.
12    pub routes: Vec<Vec<String>>,
13    /// Alias rewrites represented as `(alias, canonical)` segment lists.
14    pub aliases: Vec<(Vec<String>, Vec<String>)>,
15}
16
17/// Raw registry inventory exposed to maintainer control-plane consumers.
18#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
19pub struct RegistryInventory {
20    /// Namespace metadata rows from the route tree.
21    pub namespaces: Vec<NamespaceMetadata>,
22}
23
24/// Query raw built-in routes and aliases.
25#[must_use]
26pub fn route_inventory(registry: &RouteRegistry) -> RouteInventory {
27    let routes = registry
28        .built_in_paths()
29        .into_iter()
30        .map(|path| path.segments.into_iter().map(|segment| segment.0).collect())
31        .collect();
32    let aliases = registry
33        .alias_rewrites()
34        .into_iter()
35        .map(|(alias, canonical)| {
36            (
37                alias.segments.into_iter().map(|segment| segment.0).collect(),
38                canonical.segments.into_iter().map(|segment| segment.0).collect(),
39            )
40        })
41        .collect();
42    RouteInventory { routes, aliases }
43}
44
45/// Query raw namespace registry metadata.
46#[must_use]
47pub fn registry_inventory(registry: &RouteRegistry) -> RegistryInventory {
48    RegistryInventory { namespaces: registry.route_tree() }
49}