soma_codemode/types/
scope.rs1use std::collections::BTreeSet;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
6#[serde(rename_all = "snake_case")]
7pub enum ToolScope {
8 #[default]
9 All,
10 Namespaces(BTreeSet<String>),
11 Tools(BTreeSet<String>),
12}
13
14impl ToolScope {
15 #[must_use]
16 pub fn allows(&self, id: &str) -> bool {
17 match self {
18 Self::All => true,
19 Self::Namespaces(namespaces) => id
20 .split_once("::")
21 .is_some_and(|(namespace, _)| namespaces.contains(namespace)),
22 Self::Tools(tools) => tools.contains(id),
23 }
24 }
25}