Skip to main content

weavatrix_rust/operations/catalog/
profile.rs

1use std::str::FromStr;
2
3/// Selects a bounded operation catalog independently of any transport.
4#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
5pub enum ToolProfile {
6    /// Code intelligence plus semantic, SEO, and memory extensions.
7    #[default]
8    All,
9    /// Repository and coding-agent intelligence without SEO-specific tools.
10    Code,
11    /// Content-graph, search, semantic, and SEO analysis.
12    Seo,
13    /// Exported n8n workflows without the full repository catalog.
14    N8n,
15    /// Exported Dify YAML apps without the full repository catalog.
16    Dify,
17    /// Agent Plugins, Skills, and native MCP configuration files.
18    Agent,
19    /// Mermaid flowchart diagrams and explicit diagram bindings.
20    Diagram,
21    /// ABI, compiler artifacts, and static viem/wagmi consumers.
22    Web3,
23}
24
25impl ToolProfile {
26    #[must_use]
27    pub fn allows(self, tool: &str) -> bool {
28        match self {
29            Self::All => true,
30            Self::Code => tool != "seo_link_suggestions",
31            Self::N8n => domain_core(tool, &["n8n_inventory", "n8n_trace", "n8n_context"]),
32            Self::Dify => domain_core(tool, &["dify_inventory", "dify_trace", "dify_context"]),
33            Self::Agent => domain_core(
34                tool,
35                &[
36                    "agent_inventory",
37                    "agent_trace",
38                    "agent_context",
39                    "agent_change_impact",
40                ],
41            ),
42            Self::Diagram => {
43                domain_core(
44                    tool,
45                    &["diagram_inventory", "diagram_trace", "diagram_context"],
46                ) || tool == "change_impact"
47            }
48            Self::Web3 => domain_core(
49                tool,
50                &[
51                    "web3_inventory",
52                    "web3_trace",
53                    "web3_impact",
54                    "web3_context",
55                ],
56            ),
57            Self::Seo => matches!(
58                tool,
59                "graph_stats"
60                    | "get_node"
61                    | "get_neighbors"
62                    | "query_graph"
63                    | "shortest_path"
64                    | "search_code"
65                    | "read_source"
66                    | "context_bundle"
67                    | "list_communities"
68                    | "get_community"
69                    | "module_map"
70                    | "rebuild_graph"
71                    | "open_repo"
72                    | "list_known_repos"
73                    | "semantic_link"
74                    | "vector_search"
75                    | "seo_link_suggestions"
76                    | "memory_context"
77            ),
78        }
79    }
80}
81
82fn domain_core(tool: &str, extras: &[&str]) -> bool {
83    extras.contains(&tool)
84        || matches!(
85            tool,
86            "graph_stats"
87                | "get_node"
88                | "get_neighbors"
89                | "query_graph"
90                | "search_code"
91                | "read_source"
92                | "inspect_symbol"
93                | "context_bundle"
94                | "rebuild_graph"
95                | "open_repo"
96                | "list_known_repos"
97        )
98}
99
100impl FromStr for ToolProfile {
101    type Err = String;
102
103    fn from_str(value: &str) -> Result<Self, Self::Err> {
104        match value {
105            "all" => Ok(Self::All),
106            "code" => Ok(Self::Code),
107            "seo" | "content" => Ok(Self::Seo),
108            "n8n" => Ok(Self::N8n),
109            "dify" => Ok(Self::Dify),
110            "agent" => Ok(Self::Agent),
111            "diagram" | "mermaid" => Ok(Self::Diagram),
112            "web3" => Ok(Self::Web3),
113            _ => Err(format!(
114                "unknown tool profile {value:?}; expected all, code, seo, n8n, dify, agent, diagram, or web3"
115            )),
116        }
117    }
118}