pub const COMPACT_SURFACE_TOOL_COUNT: usize = 3;
pub const COMPACT_TOOL_NAMES: [&str; COMPACT_SURFACE_TOOL_COUNT] =
["symforge", "symforge_edit", "status"];
pub const CORE_TOOL_NAMES: [&str; 13] = [
"status",
"get_repo_map",
"get_file_context",
"get_file_content",
"search_text",
"search_symbols",
"get_symbol",
"find_references",
"replace_symbol_body",
"edit_within_symbol",
"batch_edit",
"index_folder",
"symforge_retrieve",
];
pub const TOOLS_ENV: &str = "SYMFORGE_TOOLS";
pub const TOOL_GROUPS: [(&str, &[&str]); 5] = [
(
"read",
&[
"search_symbols",
"get_symbol",
"find_references",
"get_file_context",
"search_text",
"search_files",
"get_file_content",
"get_symbol_context",
"get_repo_map",
"find_dependents",
"explore",
],
),
(
"edit",
&[
"batch_edit",
"edit_within_symbol",
"batch_insert",
"replace_symbol_body",
"batch_rename",
"insert_symbol",
"delete_symbol",
"edit_plan",
"symforge_edit",
],
),
(
"knowledge",
&["curate_knowledge", "review_knowledge", "search_knowledge"],
),
(
"impact",
&[
"what_changed",
"detect_impact",
"diff_symbols",
"analyze_file_impact",
],
),
(
"service",
&[
"status",
"health",
"health_compact",
"index_folder",
"checkpoint_now",
"context_inventory",
"conventions",
"validate_file_syntax",
"secret_remediate",
"inspect_match",
"ask",
"investigation_suggest",
"symforge_retrieve",
],
),
];
pub fn allow_list_tool_count() -> usize {
TOOL_GROUPS.iter().map(|(_, tools)| tools.len()).sum()
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ToolAllowList {
pub allowed: Vec<&'static str>,
pub unknown: Vec<String>,
}
impl ToolAllowList {
pub fn parse(spec: &str) -> Self {
let mut wanted: Vec<&'static str> = Vec::new();
let mut unknown = Vec::new();
for token in spec.split(',').map(str::trim).filter(|t| !t.is_empty()) {
let lower = token.to_ascii_lowercase();
if let Some((_, members)) = TOOL_GROUPS.iter().find(|(group, _)| *group == lower) {
wanted.extend(members.iter().copied());
} else if let Some(tool) = TOOL_GROUPS
.iter()
.flat_map(|(_, members)| members.iter())
.find(|tool| **tool == lower)
{
wanted.push(tool);
} else if lower == "symforge" {
unknown.push(format!("{token} (compact-only, not on this surface)"));
} else {
unknown.push(token.to_string());
}
}
let allowed = TOOL_GROUPS
.iter()
.flat_map(|(_, members)| members.iter().copied())
.filter(|tool| wanted.contains(tool))
.collect();
Self { allowed, unknown }
}
pub fn allows(&self, tool: &str) -> bool {
self.allowed.contains(&tool)
}
pub fn touched_groups(&self) -> Vec<&'static str> {
TOOL_GROUPS
.iter()
.filter(|(_, members)| members.iter().any(|tool| self.allows(tool)))
.map(|(group, _)| *group)
.collect()
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CompactSurfaceTool {
Symforge,
SymforgeEdit,
Status,
}
impl CompactSurfaceTool {
pub const ALL: [Self; COMPACT_SURFACE_TOOL_COUNT] =
[Self::Symforge, Self::SymforgeEdit, Self::Status];
pub const fn as_str(self) -> &'static str {
match self {
Self::Symforge => "symforge",
Self::SymforgeEdit => "symforge_edit",
Self::Status => "status",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SurfaceProfile {
Core,
Full,
Compact,
Meta,
}
pub fn surface_profile_label(profile: SurfaceProfile) -> &'static str {
match profile {
SurfaceProfile::Core => "core",
SurfaceProfile::Full => "full",
SurfaceProfile::Meta => "meta",
SurfaceProfile::Compact => "compact",
}
}
pub fn surface_label_from_str(value: &str) -> Option<&'static str> {
surface_profile_from_label(value).map(surface_profile_label)
}
pub fn surface_profile_from_label(value: &str) -> Option<SurfaceProfile> {
match value {
"core" => Some(SurfaceProfile::Core),
"full" => Some(SurfaceProfile::Full),
"meta" => Some(SurfaceProfile::Meta),
"compact" => Some(SurfaceProfile::Compact),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compact_tool_names_match_a019_registry() {
let from_enum: Vec<&str> = CompactSurfaceTool::ALL.iter().map(|t| t.as_str()).collect();
assert_eq!(from_enum.as_slice(), COMPACT_TOOL_NAMES);
}
#[test]
fn allow_list_groups_expand_and_mixed_lists_deduplicate() {
let list = ToolAllowList::parse(" Knowledge , search_knowledge,STATUS,, status ");
assert_eq!(
list.allowed,
vec![
"curate_knowledge",
"review_knowledge",
"search_knowledge",
"status"
]
);
assert!(list.unknown.is_empty());
assert_eq!(list.touched_groups(), vec!["knowledge", "service"]);
}
#[test]
fn allow_list_reports_unknown_names_and_the_compact_facade() {
let list = ToolAllowList::parse("get_symbol,bogus,symforge");
assert_eq!(list.allowed, vec!["get_symbol"]);
assert_eq!(
list.unknown,
vec![
"bogus".to_string(),
"symforge (compact-only, not on this surface)".to_string()
]
);
}
#[test]
fn allow_list_groups_are_disjoint_and_never_named_like_a_tool() {
let tools: Vec<&str> = TOOL_GROUPS
.iter()
.flat_map(|(_, members)| members.iter().copied())
.collect();
let unique: std::collections::BTreeSet<&str> = tools.iter().copied().collect();
assert_eq!(unique.len(), tools.len(), "a tool sits in two groups");
assert_eq!(allow_list_tool_count(), 40);
for (group, _) in TOOL_GROUPS {
assert!(!unique.contains(group), "group `{group}` shadows a tool");
}
}
}