feat: multi-instance support with --config parameter

Add support for running multiple nanobot instances with complete isolation:

- Add --config parameter to gateway command for custom config file path
- Implement set_config_path() in config/loader.py for dynamic config path
- Derive data directory from config file location (e.g., ~/.nanobot-xxx/)
- Update get_data_path() to use unified data directory from config loader
- Ensure cron jobs use instance-specific data directory

This enables running multiple isolated nanobot instances by specifying
different config files, with each instance maintaining separate:
- Configuration files
- Workspace (memory, sessions, skills)
- Cron jobs
- Logs and media

Example usage:
  nanobot gateway --config ~/.nanobot-instance2/config.json --port 18791
This commit is contained in:
samsonchoi
2026-03-05 23:48:45 +08:00
parent c8f86fd052
commit 4e4d40ef33
3 changed files with 36 additions and 16 deletions

View File

@@ -6,15 +6,29 @@ from pathlib import Path
from nanobot.config.schema import Config
# Global variable to store current config path (for multi-instance support)
_current_config_path: Path | None = None
def set_config_path(path: Path) -> None:
"""Set the current config path (used to derive data directory)."""
global _current_config_path
_current_config_path = path
def get_config_path() -> Path:
"""Get the default configuration file path."""
"""Get the configuration file path."""
if _current_config_path:
return _current_config_path
return Path.home() / ".nanobot" / "config.json"
def get_data_dir() -> Path:
"""Get the nanobot data directory."""
from nanobot.utils.helpers import get_data_path
return get_data_path()
"""Get the nanobot data directory (derived from config path)."""
config_path = get_config_path()
# If config is ~/.nanobot-xxx/config.json, data dir is ~/.nanobot-xxx/
# If config is ~/.nanobot/config.json, data dir is ~/.nanobot/
return config_path.parent
def load_config(config_path: Path | None = None) -> Config: