Skip to content

Your lightweight open-source personal agent.

feat(onboard): align setup with config and workspace flags

Xubin Renb2a550176ec3
diff --cc nanobot/cli/commands.py
index def014413,a1a6341ee..0d4bb3de8
--- a/nanobot/cli/commands.py
+++ b/nanobot/cli/commands.py
@@@ -168,54 -262,46 +262,64 @@@ def main
@app.command()
-def onboard():
+def onboard(
- dir: str | None = typer.Option(None, "--dir", help="Base directory for config and workspace (default: ~/.nanobot/)"),
++ workspace: str | None = typer.Option(None, "--workspace", "-w", help="Workspace directory"),
++ config: str | None = typer.Option(None, "--config", "-c", help="Path to config file"),
+):
"""Initialize nanobot configuration and workspace."""
- from nanobot.config.loader import load_config, save_config
- from nanobot.config.loader import get_config_path, load_config, save_config
++ from nanobot.config.loader import get_config_path, load_config, save_config, set_config_path
from nanobot.config.schema import Config
- # Determine base directory
- if dir:
- base_dir = Path(dir).expanduser().resolve()
- config_path = get_config_path()
++ if config:
++ config_path = Path(config).expanduser().resolve()
++ set_config_path(config_path)
++ console.print(f"[dim]Using config: {config_path}[/dim]")
+ else:
- base_dir = Path.home() / ".nanobot"
-
- config_path = base_dir / "config.json"
- workspace_path = base_dir / "workspace"
++ config_path = get_config_path()
+
- # Ensure base directory exists
- base_dir.mkdir(parents=True, exist_ok=True)
++ def _apply_workspace_override(loaded: Config) -> Config:
++ if workspace:
++ loaded.agents.defaults.workspace = workspace
++ return loaded
+ # 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)
++ config = _apply_workspace_override(Config())
+ save_config(config, config_path)
console.print(f"[green]✓[/green] Config reset to defaults at {config_path}")
else:
- config = load_config(config_path)
- config = load_config()
- save_config(config)
++ config = _apply_workspace_override(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(), config_path)
- config = Config()
- save_config(config)
++ config = _apply_workspace_override(Config())
++ save_config(config, config_path)
console.print(f"[green]✓[/green] Created config at {config_path}")
+ console.print("[dim]Config template now uses `maxTokens` + `contextWindowTokens`; `memoryWindow` is no longer a runtime setting.[/dim]")
- # Create workspace
- if not workspace_path.exists():
- workspace_path.mkdir(parents=True, exist_ok=True)
- console.print(f"[green]✓[/green] Created workspace at {workspace_path}")
+ _onboard_plugins(config_path)
- sync_workspace_templates(workspace_path)
+ # Create workspace, preferring the configured workspace path.
+ workspace = get_workspace_path(config.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)
+
++ agent_cmd = 'nanobot agent -m "Hello!"'
++ if config:
++ agent_cmd += f" --config {config_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(f" 2. Chat: [cyan]nanobot agent -m \"Hello!\" --config {config_path} --workspace {workspace_path}[/cyan]")
- console.print(" 2. Chat: [cyan]nanobot agent -m \"Hello!\"[/cyan]")
++ console.print(f" 2. Chat: [cyan]{agent_cmd}[/cyan]")
console.print("\n[dim]Want Telegram/WhatsApp? See: https://github.com/HKUDS/nanobot#-chat-apps[/dim]")
diff --cc tests/test_commands.py
index 19c1998b7,ce36a6d8f..a820e7755
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@@ -1,3 -1,4 +1,5 @@@
++import json
+ import re
import shutil
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch
@@@ -36,9 -43,9 +44,16 @@@ def mock_paths()
mock_cp.return_value = config_file
mock_ws.return_value = workspace_dir
-- mock_sc.side_effect = lambda config: config_file.write_text("{}")
++ mock_lc.side_effect = lambda _config_path=None: Config()
++
++ def _save_config(config: Config, config_path: Path | None = None):
++ target = config_path or config_file
++ target.parent.mkdir(parents=True, exist_ok=True)
++ target.write_text(json.dumps(config.model_dump(by_alias=True)), encoding="utf-8")
++
++ mock_sc.side_effect = _save_config
- yield config_file, workspace_dir
+ yield config_file, workspace_dir, mock_ws
if base_dir.exists():
shutil.rmtree(base_dir)
@@@ -100,6 -109,6 +117,40 @@@ def test_onboard_existing_workspace_saf
assert (workspace_dir / "AGENTS.md").exists()
++def test_onboard_help_shows_workspace_and_config_options():
++ result = runner.invoke(app, ["onboard", "--help"])
++
++ assert result.exit_code == 0
++ stripped_output = _strip_ansi(result.stdout)
++ assert "--workspace" in stripped_output
++ assert "-w" in stripped_output
++ assert "--config" in stripped_output
++ assert "-c" in stripped_output
++ assert "--dir" not in stripped_output
++
++
++def test_onboard_uses_explicit_config_and_workspace_paths(tmp_path, monkeypatch):
++ config_path = tmp_path / "instance" / "config.json"
++ workspace_path = tmp_path / "workspace"
++
++ monkeypatch.setattr("nanobot.channels.registry.discover_all", lambda: {})
++
++ result = runner.invoke(
++ app,
++ ["onboard", "--config", str(config_path), "--workspace", str(workspace_path)],
++ )
++
++ assert result.exit_code == 0
++ saved = Config.model_validate(json.loads(config_path.read_text(encoding="utf-8")))
++ assert saved.workspace_path == workspace_path
++ assert (workspace_path / "AGENTS.md").exists()
++ stripped_output = _strip_ansi(result.stdout)
++ compact_output = stripped_output.replace("\n", "")
++ resolved_config = str(config_path.resolve())
++ assert resolved_config in compact_output
++ assert f"--config {resolved_config}" in compact_output
++
++
def test_config_matches_github_copilot_codex_with_hyphen_prefix():
config = Config()
config.agents.defaults.model = "github-copilot/gpt-5.3-codex"