//! The tool surface, primitive by primitive — the compiled form of "every //! primitive gets its full verb set". //! //! For every primitive kind, the five standard verbs, each SATISFIED by a //! named tool or REFUSED with a written reason. The grid itself is `surface` //! (design S5), because it is data the TypeScript owns; what lives here is its //! shape, its readers, and the gates. //! //! A model reading `create_todo` assumes `update_todo` exists; a hole in this //! grid is a hallucinated tool call in somebody's session. That is why the grid //! is product surface, not bookkeeping — and why the four invariants of //! `toolSurface.test.ts` are unit tests here rather than prose. use std::collections::HashSet; pub use crate::mcp::surface::{ DEV_TOOLS, GET_RECORD_KINDS, PRIMITIVE_KINDS, SHARED_TOOLS, TOOL_SURFACE, }; /// A verb satisfied by a tool, or refused for a written reason. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum VerbCell { Tool(&'static str), Not(&'static str), } impl VerbCell { pub fn tool(&self) -> Option<&'static str> { match self { VerbCell::Tool(name) => Some(name), VerbCell::Not(_) => None, } } pub fn refusal(&self) -> Option<&'static str> { match self { VerbCell::Tool(_) => None, VerbCell::Not(reason) => Some(reason), } } } /// The five verbs, plus whatever else a primitive owns. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct VerbSet { /// Bring one into existence. pub create: VerbCell, /// Browse them directly (`search_records` is the cross-kind finder). pub list: VerbCell, /// Expand one by id. pub get: VerbCell, /// Change one in place. pub update: VerbCell, /// Take one out of the working set — delete, archive, or refuse. pub remove: VerbCell, /// Tools of this primitive beyond the five verbs. pub also: &'static [&'static str], } impl VerbSet { /// The five cells in the order the grid declares them. pub fn verbs(&self) -> [(&'static str, VerbCell); 5] { [ ("create", self.create), ("list", self.list), ("get", self.get), ("update", self.update), ("remove", self.remove), ] } } pub fn verb_set(kind: &str) -> Option<&'static VerbSet> { TOOL_SURFACE .iter() .find(|(name, _)| *name == kind) .map(|(_, row)| row) } /// The tools a primitive's row names that are not shared facilities. pub fn owned_tools(kind: &str) -> Vec<&'static str> { let Some(row) = verb_set(kind) else { return Vec::new(); }; let shared: HashSet<&str> = SHARED_TOOLS.iter().copied().collect(); let mut seen: Vec<&'static str> = Vec::new(); for (_, cell) in row.verbs() { if let Some(tool) = cell.tool() { if !seen.contains(&tool) { seen.push(tool); } } } for extra in row.also { if !seen.contains(extra) { seen.push(extra); } } seen.into_iter().filter(|tool| !shared.contains(tool)).collect() } #[cfg(test)] #[path = "tool_surface_tests.rs"] mod tests;