From affb702e900063e088dffd894ba9d6181fa37b5e Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 22 Feb 2026 12:58:58 -0300 Subject: [PATCH] fix(tools): auto-create work directory if missing in production MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added logic to create botserver-stack/data/system/work directory if it doesn't exist. This ensures production deployments work without manual directory setup. Changes: - Added fs::create_dir_all() in use_tool.rs - Added fs::create_dir_all() in tool_context.rs - Logs when directory is created - Fixes production deployment where /system/work may not exist This ensures the tool loading works in fresh production environments where the work folder hasn't been populated yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/basic/keywords/use_tool.rs | 8 ++++++++ src/core/bot/tool_context.rs | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/basic/keywords/use_tool.rs b/src/basic/keywords/use_tool.rs index c65c9d29f..7bc46ab85 100644 --- a/src/basic/keywords/use_tool.rs +++ b/src/basic/keywords/use_tool.rs @@ -198,6 +198,7 @@ fn associate_tool_with_session( tool_name: &str, ) -> Result { use crate::core::shared::models::schema::session_tool_associations; + use std::fs; // Check if tool's .mcp.json file exists in work directory // Use relative path from botserver binary location @@ -205,6 +206,13 @@ fn associate_tool_with_session( .unwrap_or_else(|_| PathBuf::from(".")) .join("botserver-stack/data/system"); + // Ensure work directory exists (create if not) + let work_base = gb_dir.join("work"); + if !work_base.exists() { + fs::create_dir_all(&work_base).map_err(|e| format!("Failed to create work directory {:?}: {}", work_base, e))?; + info!("Created work directory at: {:?}", work_base); + } + // Get bot name to construct the path let bot_name = get_bot_name_from_id(state, &user.bot_id)?; let work_path = Path::new(&gb_dir) diff --git a/src/core/bot/tool_context.rs b/src/core/bot/tool_context.rs index 2e668817a..a4e6b0223 100644 --- a/src/core/bot/tool_context.rs +++ b/src/core/bot/tool_context.rs @@ -1,7 +1,7 @@ use diesel::prelude::*; use log::{debug, info, warn}; use serde_json::{json, Value}; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use uuid::Uuid; use crate::core::shared::utils::DbPool; @@ -40,7 +40,16 @@ pub fn get_session_tools( let gb_dir = std::env::current_dir() .unwrap_or_else(|_| PathBuf::from(".")) .join("botserver-stack/data/system"); - let work_path = Path::new(&gb_dir).join("work").join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name)); + + // Ensure work directory exists (create if not) + let work_base = gb_dir.join("work"); + if !work_base.exists() { + std::fs::create_dir_all(&work_base) + .map_err(|e| format!("Failed to create work directory {:?}: {}", work_base, e))?; + info!("Created work directory at: {:?}", work_base); + } + + let work_path = work_base.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name)); info!("Loading {} tools for session {} from {:?}", tool_names.len(), session_id, work_path);