The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): boot the profile's skin on the canonical gateway
Teknium0c51167630f2
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex ec347c19c12..18f3d2081e1 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -4615,11 +4615,26 @@ export interface RuntimeDescribeResult {authority_epoch: numbercapabilities: string[]session_create: SessionCreateDescriptor+ skin?: SkinPayload | null}export interface SessionCreateDescriptor {sources: string[]parameters: string[]}+/** ``tui_gateway/change_watcher.py::resolve_skin`` — the resolved active skin (``HermesSkin``). ``{}`` when the skin engine failed to load. Colour maps are token → colour string. */+export interface SkinPayload {+ name?: string+ description?: string+ colors?: Record<string, string>+ light_colors?: Record<string, string>+ dark_colors?: Record<string, string>+ branding?: Record<string, string>+ banner_logo?: string+ banner_hero?: string+ tool_prefix?: string+ help_header?: string+ [key: string]: unknown+}export interface ClarifyRespondParams {session_id: stringexecution_generation: number@@ -5323,20 +5338,6 @@ export interface GatewayReadyPayload {heartbeat?: boolean | nullsession_authority?: boolean | null}-/** ``tui_gateway/change_watcher.py::resolve_skin`` — the resolved active skin (``HermesSkin``). ``{}`` when the skin engine failed to load. Colour maps are token → colour string. */-export interface SkinPayload {- name?: string- description?: string- colors?: Record<string, string>- light_colors?: Record<string, string>- dark_colors?: Record<string, string>- branding?: Record<string, string>- banner_logo?: string- banner_hero?: string- tool_prefix?: string- help_header?: string- [key: string]: unknown-}/** ``hermes_cli/free_tier_bootstrap.py::SetupRecord.as_payload``. */export interface SetupReadyPayload {provider_configured: booleandiff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 4913c688fea..33359e58541 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -33138,6 +33138,17 @@},"session_create": {"$ref": "#/components/schemas/SessionCreateDescriptor"+ },+ "skin": {+ "anyOf": [+ {+ "$ref": "#/components/schemas/SkinPayload"+ },+ {+ "type": "null"+ }+ ],+ "default": null}},"required": [diff --git a/gateway/session_controls.py b/gateway/session_controls.pyindex b84269d1429..0a35433cbec 100644--- a/gateway/session_controls.py+++ b/gateway/session_controls.py@@ -332,11 +332,14 @@ class AuthorityConnection:async def describe(self, ref, params):await self.ping(ref, params)from gateway.session_policy import CREATE_FIELDS, SURFACES+ from gateway.session_skin import resolved_skinreturn {'instance_id': self.authority.instance_id, 'profile_id': self.authority.profile_id,'authority_epoch': self.authority.epoch,'capabilities': ['durable-admission-v1', 'event-replay-v1', 'local-cli-create-v1', 'acp-editor-policy-v1', 'acp-session-mcp-v1'],'session_create': {'sources': sorted(SURFACES),- 'parameters': sorted(CREATE_FIELDS | {'title'})}}+ 'parameters': sorted(CREATE_FIELDS | {'title'})},+ # Main's ``gateway.ready.skin``: the canonical client's own ready carries it.+ 'skin': await asyncio.to_thread(resolved_skin)}async def info(self, ref, params):from gateway.session_local_inventory import snapshot_infodiff --git a/gateway/session_skin.py b/gateway/session_skin.pynew file mode 100644index 00000000000..abb696b5c95--- /dev/null+++ b/gateway/session_skin.py@@ -0,0 +1,33 @@+"""The owning profile's resolved skin for a canonical client's readiness.++Main's TUI booted its theme from ``gateway.ready.skin`` (``tui_gateway/entry.py`` / ``ws.py``, both+``change_watcher.resolve_skin()``). On the session authority the client publishes its own ready after+``runtime.describe``, so the describe reply carries the same payload, resolved for the profile that+owns this authority (``display.skin`` and ``<home>/skins/*.yaml`` are per profile).+"""+from __future__ import annotations++import logging++logger = logging.getLogger(__name__)+++def resolved_skin() -> dict:+ """``resolve_skin()``'s dict for the profile in scope (the dispatcher's ``owner_scope``); ``{}``+ when the skin engine fails, which the client treats as the default theme, as main did."""+ try:+ from hermes_cli.config_effective import load_user_config_effective+ from hermes_cli.skin_engine import get_active_skin, init_skin_from_config+ from hermes_constants import get_hermes_home+ init_skin_from_config(load_user_config_effective(get_hermes_home() / "config.yaml"))+ skin = get_active_skin()+ return {+ "name": skin.name, "colors": skin.colors,+ "light_colors": skin.light_colors, "dark_colors": skin.dark_colors,+ "branding": skin.branding, "banner_logo": skin.banner_logo,+ "banner_hero": skin.banner_hero, "tool_prefix": skin.tool_prefix,+ "help_header": (skin.branding or {}).get("help_header", ""),+ "customCSS": skin.custom_css}+ except Exception: # health: allow BLE001 -- main's resolve_skin: a broken skin boots the default theme+ logger.debug("runtime.describe: skin resolution failed", exc_info=True)+ return {}diff --git a/tests/gateway/test_runtime_describe_skin.py b/tests/gateway/test_runtime_describe_skin.pynew file mode 100644index 00000000000..a20ca8b5223--- /dev/null+++ b/tests/gateway/test_runtime_describe_skin.py@@ -0,0 +1,31 @@+"""``runtime.describe`` carries the owning profile's resolved skin: main's TUI booted its theme from+``gateway.ready.skin`` (``tui_gateway/entry.py`` / ``ws.py`` ``resolve_skin()``), and the canonical+client publishes its own ready from this discovery reply (FINDINGS row 3: ``-p work`` with+``display.skin: ares`` must boot Ares, not the default gold theme)."""+from pathlib import Path+from types import SimpleNamespace++import pytest++from gateway.session_controls import AuthorityConnection+from tests.gateway.test_local_source_labels import _authority+++async def test_runtime_describe_carries_the_profiles_resolved_skin(tmp_path, monkeypatch):+ authority, _store = await _authority(tmp_path, monkeypatch)+ home = Path(authority.profile_id)+ (home / 'config.yaml').write_text('display:\n skin: ares\n')+ monkeypatch.setenv('HERMES_HOME', str(home))+ conn = AuthorityConnection(authority, SimpleNamespace(write=lambda frame: None), {'user_id': 'owner'})+ try:+ described = await conn.dispatch({'id': 0, 'method': 'runtime.describe', 'params': {}})+ assert 'result' in described, described+ skin = described['result']['skin']+ assert skin['name'] == 'ares'+ assert skin['colors'] and skin['branding']+ from tui_gateway.contracts.registry import CANONICAL_METHODS+ CANONICAL_METHODS['runtime.describe'].result.model_validate(described['result'])+ finally:+ await conn.close()+ authority.db.close()diff --git a/tui_gateway/contracts/canonical.py b/tui_gateway/contracts/canonical.pyindex 5369d109859..c7439530417 100644--- a/tui_gateway/contracts/canonical.py+++ b/tui_gateway/contracts/canonical.py@@ -13,6 +13,7 @@ from typing import Literalfrom .base import JsonValue, Params, Resultfrom .common import McpServerStatus, OpenModel, ProjectRef+from .events import SkinPayloadfrom .groups_bot_relay import RoomParams, RoomTaskReceiptfrom .registry import canonical_method@@ -274,6 +275,8 @@ class RuntimeDescribeResult(Result):authority_epoch: intcapabilities: list[str]session_create: SessionCreateDescriptor+ #: The owning profile's resolved skin (``resolve_skin()``, main's ``gateway.ready.skin``).+ skin: SkinPayload | None = Nonecanonical_method("runtime.describe", params=RuntimeDescribeParams, result=RuntimeDescribeResult,diff --git a/ui-tui/src/__tests__/gatewayClient.test.ts b/ui-tui/src/__tests__/gatewayClient.test.tsindex dd0081575e6..97848f4c1c4 100644--- a/ui-tui/src/__tests__/gatewayClient.test.ts+++ b/ui-tui/src/__tests__/gatewayClient.test.ts@@ -178,6 +178,34 @@ describe('GatewayClient websocket attach mode', () => {}})+ it("boots the owner's profile skin: runtime.describe.skin rides the client-local ready (row 3)", async () => {+ vi.useFakeTimers()+ delete process.env.HERMES_TUI_GATEWAY_URL+ delete process.env.HERMES_TUI_SIDECAR_URL+ const gw = new GatewayClient(async () => ({ url: 'ws://gateway.test/api/ws', protocols: [], instance_id: 'owner', profile_id: 'fixture' }))+ const events: any[] = []+ gw.on('event', event => events.push(event))++ try {+ gw.start(); gw.drain()+ await vi.advanceTimersByTimeAsync(0)+ const socket = FakeWebSocket.instances[0]!+ socket.open()+ await vi.advanceTimersByTimeAsync(0)+ const request = socket.sent.map(text => JSON.parse(text) as { id: number; method: string })+ .find(frame => frame.method === 'runtime.describe')!++ const skin = { name: 'ares', colors: { banner_title: '#C7A96B' }, branding: { prompt_symbol: '⚔' } }+ socket.message(JSON.stringify({ jsonrpc: '2.0', id: request.id, result: {+ session_create: { sources: ['tui'], parameters: ['source', 'request_id'] }, skin } }))+ await vi.advanceTimersByTimeAsync(0)++ const ready = events.filter(event => event.type === 'gateway.ready')+ expect(ready).toHaveLength(1)+ expect(ready[0].payload.skin).toEqual(skin)+ } finally { gw.kill(); vi.useRealTimers() }+ })+it('treats a failed runtime.describe as a transport failure: redial, re-describe, then ready (B2-21)', async () => {vi.useFakeTimers()delete process.env.HERMES_TUI_GATEWAY_URLdiff --git a/ui-tui/src/gatewayClient.ts b/ui-tui/src/gatewayClient.tsindex e18fc82a0e6..0e20dc98390 100644--- a/ui-tui/src/gatewayClient.ts+++ b/ui-tui/src/gatewayClient.ts@@ -186,6 +186,7 @@ export class GatewayClient extends EventEmitter {private recoveryAttempts: number[] = []isCanonical = falseprivate creationContract?: CreationContract+ private describedSkin?: Record<string, unknown>private describeFlight?: Promise<void>private attachHold: AttachHold | null = null// The last session.create whose outcome is in doubt (see createCanonical).@@ -269,7 +270,11 @@ export class GatewayClient extends EventEmitter {private describeThenReady(ws: WebSocket | null, payload: Record<string, unknown>) {this.describeFlight = undefinedvoid this.describeRuntime().then(() => {- if (this.ws === ws) { this.publish({ type: 'gateway.ready', payload } as unknown as AnyGatewayEvent) }+ // The owner's resolved profile skin (`runtime.describe.skin`, main's `gateway.ready.skin`)+ // unless the listener's own ready already carried one.+ const ready = payload.skin === undefined && this.describedSkin ? { ...payload, skin: this.describedSkin } : payload++ if (this.ws === ws) { this.publish({ type: 'gateway.ready', payload: ready } as unknown as AnyGatewayEvent) }}).catch(error => {this.publish({ type: 'gateway.start_timeout', payload: {python: 'runtime.describe', cwd: '', stderr_tail: String(error)@@ -655,7 +660,7 @@ export class GatewayClient extends EventEmitter {this.connectSidecarMirror()// The canonical gateway has no ready frame (readiness is the discovery grant +- // runtime.describe); a client-local ready with no skin boots the default theme.+ // runtime.describe); the client-local ready carries the skin runtime.describe resolved.if (this.isCanonical) { this.describeThenReady(ws, {}) }},{ once: true }@@ -871,8 +876,11 @@ export class GatewayClient extends EventEmitter {* session.create asks again instead of reporting an outdated gateway forever. */private describeRuntime(): Promise<void> {if (!this.describeFlight) {- const flight: Promise<void> = this.requestOverWebSocket<{ session_create: CreationContract }>('runtime.describe').then(- description => { this.creationContract = description.session_create },+ const flight: Promise<void> = this.requestOverWebSocket<{ session_create: CreationContract; skin?: Record<string, unknown> | null }>('runtime.describe').then(+ description => {+ this.creationContract = description.session_create+ this.describedSkin = description.skin && typeof description.skin === 'object' ? description.skin : undefined+ },error => {if (this.describeFlight === flight) { this.describeFlight = undefined }