fix(cli): harden process identity portability

This commit is contained in:
Xubin Ren
2026-08-23 21:13:14 +08:00
parent cfc1fae8b5
commit cfc872fb52
2 changed files with 15 additions and 7 deletions
+10 -3
View File
@@ -7,11 +7,18 @@ import os
from pathlib import Path
from typing import Final
from setproctitle import setproctitle
_ROLES: Final = {"agent", "gateway", "webui"}
def _set_process_title(title: str) -> None:
# Process titles are short; do not trade Linux /proc environment visibility for
# extra title storage. setproctitle reads this switch when it is imported.
os.environ.setdefault("SPT_NOENV", "1")
from setproctitle import setproctitle
setproctitle(title)
def set_cli_process_identity(args: list[str]) -> None:
"""Name this CLI process after the nanobot role it is running."""
if os.name == "nt":
@@ -19,7 +26,7 @@ def set_cli_process_identity(args: list[str]) -> None:
# which packaging already generates as ``nanobot.exe``.
return
role = args[0] if args and args[0] in _ROLES else None
setproctitle(f"nanobot-{role}" if role else "nanobot")
_set_process_title(f"nanobot-{role}" if role else "nanobot")
def named_executable(executable: str, *, name: str, directory: Path) -> str: