| 1 | """Runtime path helpers derived from the active config context.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | from nanobot.config.loader import get_config_path |
| 8 | from nanobot.utils.helpers import ensure_dir |
| 9 | |
| 10 | |
| 11 | def get_data_dir() -> Path: |
| 12 | """Return the instance-level runtime data directory.""" |
| 13 | return ensure_dir(get_config_path().parent) |
| 14 | |
| 15 | |
| 16 | def get_runtime_subdir(name: str) -> Path: |
| 17 | """Return a named runtime subdirectory under the instance data dir.""" |
| 18 | return ensure_dir(get_data_dir() / name) |
| 19 | |
| 20 | |
| 21 | def get_media_dir(channel: str | None = None) -> Path: |
| 22 | """Return the media directory, optionally namespaced per channel.""" |
| 23 | base = get_runtime_subdir("media") |
| 24 | return ensure_dir(base / channel) if channel else base |
| 25 | |
| 26 | |
| 27 | def get_cron_dir() -> Path: |
| 28 | """Return the cron storage directory.""" |
| 29 | return get_runtime_subdir("cron") |
| 30 | |
| 31 | |
| 32 | def get_logs_dir() -> Path: |
| 33 | """Return the logs directory.""" |
| 34 | return get_runtime_subdir("logs") |
| 35 | |
| 36 | |
| 37 | def get_workspace_path(workspace: str | None = None) -> Path: |
| 38 | """Resolve and ensure the agent workspace path.""" |
| 39 | path = Path(workspace).expanduser() if workspace else Path.home() / ".nanobot" / "workspace" |
| 40 | return ensure_dir(path) |
| 41 | |
| 42 | |
| 43 | def is_default_workspace(workspace: str | Path | None) -> bool: |
| 44 | """Return whether a workspace resolves to nanobot's default workspace path.""" |
| 45 | current = Path(workspace).expanduser() if workspace is not None else Path.home() / ".nanobot" / "workspace" |
| 46 | default = Path.home() / ".nanobot" / "workspace" |
| 47 | return current.resolve(strict=False) == default.resolve(strict=False) |
| 48 | |
| 49 | |
| 50 | def get_cli_history_path() -> Path: |
| 51 | """Return the shared CLI history file path.""" |
| 52 | return Path.home() / ".nanobot" / "history" / "cli_history" |
| 53 | |
| 54 | |
| 55 | def get_bridge_install_dir() -> Path: |
| 56 | """Return the shared WhatsApp bridge installation directory.""" |
| 57 | return Path.home() / ".nanobot" / "bridge" |
| 58 | |
| 59 | |
| 60 | def get_legacy_sessions_dir() -> Path: |
| 61 | """Return the legacy global session directory used for migration fallback.""" |
| 62 | return Path.home() / ".nanobot" / "sessions" |
| 63 |