From dfb4537867194ad6b9c01afb411d3f3f90d593cc Mon Sep 17 00:00:00 2001 From: skiyo Date: Mon, 9 Mar 2026 16:17:01 +0800 Subject: [PATCH 1/2] feat: add --dir option to onboard command for Multiple Instances - Add --dir parameter to specify custom base directory for config and workspace - Enables Multiple Instances initialization with isolated configurations - Config and workspace are created under the specified directory - Maintains backward compatibility with default ~/.nanobot/ - Updates help text and next steps with actual paths - Updates README.md with --dir usage examples for Multiple Instances Example usage: nanobot onboard --dir ~/.nanobot-A nanobot onboard --dir ~/.nanobot-B nanobot onboard # uses default ~/.nanobot/ --- README.md | 18 +++++++++++++++++- nanobot/cli/commands.py | 41 ++++++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f169bd7..78dec73 100644 --- a/README.md +++ b/README.md @@ -939,6 +939,21 @@ Run multiple nanobot instances simultaneously with separate configs and runtime ### Quick Start +**Initialize instances:** + +```bash +# Create separate instance directories +nanobot onboard --dir ~/.nanobot-telegram +nanobot onboard --dir ~/.nanobot-discord +nanobot onboard --dir ~/.nanobot-feishu +``` + +**Configure each instance:** + +Edit `~/.nanobot-telegram/config.json`, `~/.nanobot-discord/config.json`, etc. with different channel settings and workspaces. + +**Run instances:** + ```bash # Instance A - Telegram bot nanobot gateway --config ~/.nanobot-telegram/config.json @@ -1038,7 +1053,8 @@ nanobot gateway --config ~/.nanobot-telegram/config.json --workspace /tmp/nanobo | Command | Description | |---------|-------------| -| `nanobot onboard` | Initialize config & workspace | +| `nanobot onboard` | Initialize config & workspace at `~/.nanobot/` | +| `nanobot onboard --dir ` | Initialize config & workspace at custom directory | | `nanobot agent -m "..."` | Chat with the agent | | `nanobot agent -w ` | Chat against a specific workspace | | `nanobot agent -w -c ` | Chat against a specific workspace/config | diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 2c8d6d3..def0144 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -168,43 +168,54 @@ def main( @app.command() -def onboard(): +def onboard( + dir: str | None = typer.Option(None, "--dir", help="Base directory for config and workspace (default: ~/.nanobot/)"), +): """Initialize nanobot configuration and workspace.""" - from nanobot.config.loader import get_config_path, load_config, save_config + from nanobot.config.loader import load_config, save_config from nanobot.config.schema import Config - config_path = get_config_path() + # Determine base directory + if dir: + base_dir = Path(dir).expanduser().resolve() + else: + base_dir = Path.home() / ".nanobot" + config_path = base_dir / "config.json" + workspace_path = base_dir / "workspace" + + # Ensure base directory exists + base_dir.mkdir(parents=True, exist_ok=True) + + # Create or update config if config_path.exists(): console.print(f"[yellow]Config already exists at {config_path}[/yellow]") console.print(" [bold]y[/bold] = overwrite with defaults (existing values will be lost)") console.print(" [bold]N[/bold] = refresh config, keeping existing values and adding new fields") if typer.confirm("Overwrite?"): config = Config() - save_config(config) + save_config(config, config_path) console.print(f"[green]✓[/green] Config reset to defaults at {config_path}") else: - config = load_config() - save_config(config) + config = load_config(config_path) + save_config(config, config_path) console.print(f"[green]✓[/green] Config refreshed at {config_path} (existing values preserved)") else: - save_config(Config()) + save_config(Config(), config_path) console.print(f"[green]✓[/green] Created config at {config_path}") # Create workspace - workspace = get_workspace_path() + if not workspace_path.exists(): + workspace_path.mkdir(parents=True, exist_ok=True) + console.print(f"[green]✓[/green] Created workspace at {workspace_path}") - if not workspace.exists(): - workspace.mkdir(parents=True, exist_ok=True) - console.print(f"[green]✓[/green] Created workspace at {workspace}") - - sync_workspace_templates(workspace) + sync_workspace_templates(workspace_path) console.print(f"\n{__logo__} nanobot is ready!") console.print("\nNext steps:") - console.print(" 1. Add your API key to [cyan]~/.nanobot/config.json[/cyan]") + console.print(f" 1. Add your API key to [cyan]{config_path}[/cyan]") console.print(" Get one at: https://openrouter.ai/keys") - console.print(" 2. Chat: [cyan]nanobot agent -m \"Hello!\"[/cyan]") + console.print(f" 2. Chat: [cyan]nanobot agent -m \"Hello!\" --config {config_path} --workspace {workspace_path}[/cyan]") console.print("\n[dim]Want Telegram/WhatsApp? See: https://github.com/HKUDS/nanobot#-chat-apps[/dim]") From 499d0e15887c7745beaf7664a5e7e50712dc7eef Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Tue, 17 Mar 2026 05:58:13 +0000 Subject: [PATCH 2/2] docs(readme): update multi-instance onboard examples --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 57898c6..0410a35 100644 --- a/README.md +++ b/README.md @@ -1162,22 +1162,24 @@ MCP tools are automatically discovered and registered on startup. The LLM can us ## 🧩 Multiple Instances -Run multiple nanobot instances simultaneously with separate configs and runtime data. Use `--config` as the main entrypoint, and optionally use `--workspace` to override the workspace for a specific run. +Run multiple nanobot instances simultaneously with separate configs and runtime data. Use `--config` as the main entrypoint. Optionally pass `--workspace` during `onboard` when you want to initialize or update the saved workspace for a specific instance. ### Quick Start +If you want each instance to have its own dedicated workspace from the start, pass both `--config` and `--workspace` during onboarding. + **Initialize instances:** ```bash -# Create separate instance directories -nanobot onboard --dir ~/.nanobot-telegram -nanobot onboard --dir ~/.nanobot-discord -nanobot onboard --dir ~/.nanobot-feishu +# Create separate instance configs and workspaces +nanobot onboard --config ~/.nanobot-telegram/config.json --workspace ~/.nanobot-telegram/workspace +nanobot onboard --config ~/.nanobot-discord/config.json --workspace ~/.nanobot-discord/workspace +nanobot onboard --config ~/.nanobot-feishu/config.json --workspace ~/.nanobot-feishu/workspace ``` **Configure each instance:** -Edit `~/.nanobot-telegram/config.json`, `~/.nanobot-discord/config.json`, etc. with different channel settings and workspaces. +Edit `~/.nanobot-telegram/config.json`, `~/.nanobot-discord/config.json`, etc. with different channel settings. The workspace you passed during `onboard` is saved into each config as that instance's default workspace. **Run instances:** @@ -1281,7 +1283,7 @@ nanobot gateway --config ~/.nanobot-telegram/config.json --workspace /tmp/nanobo | Command | Description | |---------|-------------| | `nanobot onboard` | Initialize config & workspace at `~/.nanobot/` | -| `nanobot onboard --dir ` | Initialize config & workspace at custom directory | +| `nanobot onboard -c -w ` | Initialize or refresh a specific instance config and workspace | | `nanobot agent -m "..."` | Chat with the agent | | `nanobot agent -w ` | Chat against a specific workspace | | `nanobot agent -w -c ` | Chat against a specific workspace/config |