(self, session: &mut ChatSession)
| 44 | |
| 45 | impl ToolsArgs { |
| 46 | pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> { |
| 47 | if let Some(subcommand) = self.subcommand { |
| 48 | return subcommand.execute(session).await; |
| 49 | } |
| 50 | |
| 51 | // No subcommand - print the current tools and their permissions. |
| 52 | // Determine how to format the output nicely. |
| 53 | let terminal_width = session.terminal_width(); |
| 54 | let longest = session |
| 55 | .conversation |
| 56 | .tool_manager |
| 57 | .tn_map |
| 58 | .values() |
| 59 | .map(|info| info.host_tool_name.len()) |
| 60 | .max() |
| 61 | .unwrap_or(0) |
| 62 | .max( |
| 63 | session |
| 64 | .conversation |
| 65 | .tools |
| 66 | .get(&ToolOrigin::Native) |
| 67 | .and_then(|tools| { |
| 68 | tools |
| 69 | .iter() |
| 70 | .map(|tool| { |
| 71 | let FigTool::ToolSpecification(t) = tool; |
| 72 | t.name.len() |
| 73 | }) |
| 74 | .max() |
| 75 | }) |
| 76 | .unwrap_or(0), |
| 77 | ); |
| 78 | |
| 79 | queue!( |
| 80 | session.stderr, |
| 81 | style::Print("\n"), |
| 82 | style::SetAttribute(Attribute::Bold), |
| 83 | style::Print({ |
| 84 | // Adding 2 because of "- " preceding every tool name |
| 85 | let width = (longest + 2).saturating_sub("Tool".len()) + 4; |
| 86 | format!("Tool{:>width$}Permission", "", width = width) |
| 87 | }), |
| 88 | StyledText::reset_attributes(), |
| 89 | style::Print("\n"), |
| 90 | style::Print("▔".repeat(terminal_width)), |
| 91 | )?; |
| 92 | |
| 93 | let mut origin_tools: Vec<_> = session.conversation.tools.iter().collect(); |
| 94 | |
| 95 | // Built in tools always appear first. |
| 96 | origin_tools.sort_by(|(origin_a, _), (origin_b, _)| match (origin_a, origin_b) { |
| 97 | (ToolOrigin::Native, _) => std::cmp::Ordering::Less, |
| 98 | (_, ToolOrigin::Native) => std::cmp::Ordering::Greater, |
| 99 | (ToolOrigin::McpServer(name_a), ToolOrigin::McpServer(name_b)) => name_a.cmp(name_b), |
| 100 | }); |
| 101 | |
| 102 | for (origin, tools) in origin_tools.iter() { |
| 103 | // Note that Tool is model facing and thus would have names recognized by model. |
nothing calls this directly
no test coverage detected