claude_agent/plugins/
namespace.rs1pub const NAMESPACE_SEP: char = ':';
2
3pub fn namespaced(plugin: &str, resource: &str) -> String {
4 format!("{}{}{}", plugin, NAMESPACE_SEP, resource)
5}
6
7pub fn parse(name: &str) -> Option<(&str, &str)> {
8 name.split_once(NAMESPACE_SEP)
9}
10
11pub fn is_namespaced(name: &str) -> bool {
12 name.contains(NAMESPACE_SEP)
13}
14
15pub fn plugin_name(name: &str) -> Option<&str> {
16 parse(name).map(|(p, _)| p)
17}
18
19pub fn resource_name(name: &str) -> Option<&str> {
20 parse(name).map(|(_, r)| r)
21}
22
23#[cfg(test)]
24mod tests {
25 use super::*;
26
27 #[test]
28 fn test_namespaced() {
29 assert_eq!(namespaced("my-plugin", "commit"), "my-plugin:commit");
30 assert_eq!(namespaced("org", "tool"), "org:tool");
31 }
32
33 #[test]
34 fn test_parse() {
35 assert_eq!(parse("my-plugin:commit"), Some(("my-plugin", "commit")));
36 assert_eq!(parse("no-namespace"), None);
37 assert_eq!(parse("a:b:c"), Some(("a", "b:c")));
38 }
39
40 #[test]
41 fn test_is_namespaced() {
42 assert!(is_namespaced("plugin:resource"));
43 assert!(!is_namespaced("plain"));
44 }
45
46 #[test]
47 fn test_plugin_name() {
48 assert_eq!(plugin_name("my-plugin:skill"), Some("my-plugin"));
49 assert_eq!(plugin_name("plain"), None);
50 }
51
52 #[test]
53 fn test_resource_name() {
54 assert_eq!(resource_name("my-plugin:skill"), Some("skill"));
55 assert_eq!(resource_name("plain"), None);
56 }
57}