diff --git a/tui_gateway/server.py b/tui_gateway/server.py index 67f9f0c47..dd375b836 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -319,9 +319,13 @@ def _wire_callbacks(sid: str): def _make_agent(sid: str, key: str, session_id: str | None = None): from run_agent import AIAgent + cfg = _load_cfg() + system_prompt = cfg.get("agent", {}).get("system_prompt", "") or "" return AIAgent( model=_resolve_model(), quiet_mode=True, platform="tui", - session_id=session_id or key, session_db=_get_db(), **_agent_cbs(sid), + session_id=session_id or key, session_db=_get_db(), + ephemeral_system_prompt=system_prompt or None, + **_agent_cbs(sid), ) @@ -1119,6 +1123,11 @@ def _mirror_slash_side_effects(sid: str, session: dict, command: str): api_mode=result.api_mode, ) _emit("session.info", sid, _session_info(agent)) + elif name in ("personality", "prompt") and agent: + cfg = _load_cfg() + new_prompt = cfg.get("agent", {}).get("system_prompt", "") or "" + agent.ephemeral_system_prompt = new_prompt or None + agent._cached_system_prompt = None elif name == "compress" and agent: (getattr(agent, "compress_context", None) or getattr(agent, "context_compressor", agent).compress)() elif name == "reload-mcp" and agent and hasattr(agent, "reload_mcp_tools"): diff --git a/tui_gateway/slash_worker.py b/tui_gateway/slash_worker.py index 5d3741864..631b0c704 100644 --- a/tui_gateway/slash_worker.py +++ b/tui_gateway/slash_worker.py @@ -12,6 +12,7 @@ import sys import cli as cli_mod from cli import HermesCLI +from rich.console import Console def _run(cli: HermesCLI, command: str) -> str: @@ -22,6 +23,12 @@ def _run(cli: HermesCLI, command: str) -> str: cmd = f"/{cmd}" buf = io.StringIO() + + # Rich Console captures its file handle at construction time, so + # contextlib.redirect_stdout won't affect it. Swap the console's + # underlying file to our buffer so self.console.print() is captured. + cli.console = Console(file=buf, force_terminal=True, width=120) + old = getattr(cli_mod, "_cprint", None) if old is not None: cli_mod._cprint = lambda text: print(text) diff --git a/ui-tui/src/app.tsx b/ui-tui/src/app.tsx index 574f69f7b..5f31d8385 100644 --- a/ui-tui/src/app.tsx +++ b/ui-tui/src/app.tsx @@ -842,7 +842,7 @@ export function App({ gw }: { gw: GatewayClient }) { return true default: - rpc('slash.exec', { command: cmd.slice(1), session_id: sid }) + gw.request('slash.exec', { command: cmd.slice(1), session_id: sid }) .then((r: any) => { if (r?.output) { sys(r.output)