34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
"""Resolve portable paths; never load a workspace .env or a global tg install."""
|
|
from pathlib import Path
|
|
import os
|
|
import shutil
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def resolve_account(account: str) -> str:
|
|
if account not in ("main", "reserve"):
|
|
raise ValueError("account must be main or reserve")
|
|
return account
|
|
|
|
|
|
def state_directory() -> Path:
|
|
configured = os.environ.get("TG_MCP_STATE_DIR")
|
|
path = Path(configured).expanduser() if configured else Path.home() / ".local" / "share" / "telegram-mcp"
|
|
if not path.is_absolute():
|
|
raise ValueError("TG_MCP_STATE_DIR must be absolute")
|
|
return path
|
|
|
|
|
|
def child_environment(account: str) -> dict[str, str]:
|
|
resolve_account(account)
|
|
# Account identity and credentials come from this bundle's CLI profile.
|
|
# Never accidentally inherit another integration's Telegram credentials.
|
|
return {k: v for k, v in os.environ.items() if not k.startswith("TG_")}
|
|
|
|
|
|
def cli_command(account: str) -> list[str]:
|
|
resolve_account(account)
|
|
return [shutil.which("node") or "node", str(ROOT / "cli" / "dist" / "bin" / "tg.js"),
|
|
"--config", str(state_directory() / "config.json"),
|
|
"--quiet", "--profile", account]
|