| 700 | } |
| 701 | |
| 702 | pub async fn load_tools( |
| 703 | &mut self, |
| 704 | os: &mut Os, |
| 705 | stderr: &mut impl Write, |
| 706 | ) -> eyre::Result<HashMap<String, ToolSpec>> { |
| 707 | let tx = self.loading_status_sender.take(); |
| 708 | let notify = self.notify.take(); |
| 709 | self.schema = { |
| 710 | let tool_list = &self.agent.lock().await.tools; |
| 711 | let is_allow_all = tool_list.len() == 1 && tool_list.first().is_some_and(|n| n == "*"); |
| 712 | let is_allow_native = tool_list.iter().any(|t| t.as_str() == "@builtin"); |
| 713 | let mut tool_specs = |
| 714 | serde_json::from_str::<HashMap<String, ToolSpec>>(include_str!("tools/tool_index.json"))? |
| 715 | .into_iter() |
| 716 | .filter(|(name, _)| { |
| 717 | name == DUMMY_TOOL_NAME |
| 718 | || is_allow_all |
| 719 | || is_allow_native |
| 720 | || tool_list.contains(name) |
| 721 | || tool_list.contains(&format!("@builtin/{name}")) |
| 722 | }) |
| 723 | .collect::<HashMap<_, _>>(); |
| 724 | if !crate::cli::chat::tools::thinking::Thinking::is_enabled(os) { |
| 725 | tool_specs.remove("thinking"); |
| 726 | } |
| 727 | if !crate::cli::chat::tools::knowledge::Knowledge::is_enabled(os) { |
| 728 | tool_specs.remove("knowledge"); |
| 729 | } |
| 730 | if !crate::cli::chat::tools::todo::TodoList::is_enabled(os) { |
| 731 | tool_specs.remove("todo_list"); |
| 732 | } |
| 733 | if !crate::cli::chat::tools::delegate::Delegate::is_enabled(os) { |
| 734 | tool_specs.remove("delegate"); |
| 735 | } |
| 736 | |
| 737 | #[cfg(windows)] |
| 738 | { |
| 739 | use serde_json::json; |
| 740 | |
| 741 | use crate::cli::chat::tools::InputSchema; |
| 742 | |
| 743 | tool_specs.remove("execute_bash"); |
| 744 | |
| 745 | tool_specs.insert("execute_cmd".to_string(), ToolSpec { |
| 746 | name: "execute_cmd".to_string(), |
| 747 | description: "Execute the specified Windows command.".to_string(), |
| 748 | input_schema: InputSchema(json!({ |
| 749 | "type": "object", |
| 750 | "properties": { |
| 751 | "command": { |
| 752 | "type": "string", |
| 753 | "description": "Windows command to execute" |
| 754 | }, |
| 755 | "summary": { |
| 756 | "type": "string", |
| 757 | "description": "A brief explanation of what the command does" |
| 758 | } |
| 759 | }, |