From 1e9d46fb36bc2656d3d748f2c9fe6cee24b728d0 Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sun, 23 Aug 2026 20:53:56 +0800 Subject: [PATCH] fix(cli): name roles through legacy launchers --- nanobot/cli/commands.py | 8 +++++++- tests/cli/test_process_identity.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 051037183..4fcb7929e 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -56,6 +56,7 @@ from nanobot.cli.agent import agent # noqa: E402 from nanobot.cli.gateway import create_gateway_app # noqa: E402 from nanobot.cli.gateway_runtime import _run_gateway # noqa: E402 from nanobot.cli.log_control import _set_nanobot_logs # noqa: E402 +from nanobot.cli.process_identity import set_cli_process_identity # noqa: E402 from nanobot.cli.provider import provider_app # noqa: E402 from nanobot.cli.runtime_config import ( # noqa: E402 _load_inspection_config, @@ -99,12 +100,17 @@ def version_callback(value: bool): @app.callback() def main( + ctx: typer.Context, version: bool = typer.Option( None, "--version", "-v", callback=version_callback, is_eager=True ), ): """nanobot - Personal AI Assistant.""" - pass + # Editable/source installs can retain an older generated console script that + # imports this Typer app directly instead of ``nanobot.cli.entry``. Keep the + # role identity correct until that launcher is regenerated. + command = ctx.invoked_subcommand + set_cli_process_identity([command] if command else sys.argv[1:]) # ============================================================================ diff --git a/tests/cli/test_process_identity.py b/tests/cli/test_process_identity.py index 72faf2cc9..114432929 100644 --- a/tests/cli/test_process_identity.py +++ b/tests/cli/test_process_identity.py @@ -4,7 +4,9 @@ import os from pathlib import Path import pytest +from typer.testing import CliRunner +from nanobot.cli.commands import app from nanobot.cli.process_identity import named_executable, set_cli_process_identity @@ -44,6 +46,18 @@ def test_cli_process_identity_keeps_windows_launcher_name( assert titles == [] +def test_legacy_console_entrypoint_still_sets_subcommand_identity( + monkeypatch: pytest.MonkeyPatch, +) -> None: + commands: list[list[str]] = [] + monkeypatch.setattr("nanobot.cli.commands.set_cli_process_identity", commands.append) + + result = CliRunner().invoke(app, ["webui", "--help"]) + + assert result.exit_code == 0 + assert commands == [["webui"]] + + def test_named_executable_creates_stable_role_symlink( tmp_path: Path, ) -> None: