Skip to content

The agent that grows with you

feat(gateway): serve /skin on the owner and repaint the profile's TUIs

Teknium650ef9dd5ef4
diff --git a/gateway/session_tui_config.py b/gateway/session_tui_config.py
index 24200712735..2f7d97b83fa 100644
--- a/gateway/session_tui_config.py
+++ b/gateway/session_tui_config.py
@@ -104,6 +104,11 @@ def _set_display(cfg, key, value):
return {'value': raw}
if key == 'focus':
return _set_focus(display, raw)
+ if key == 'skin':
+ if not isinstance(value, str) or not value.strip():
+ raise RuntimeStoreError('invalid_params')
+ display['skin'] = value.strip()
+ return {'value': value.strip()}
raise RuntimeStoreError('invalid_params')
@@ -171,4 +176,24 @@ async def config_set(connection, ref, params):
if key == 'focus' and ref.session_id and 'tool_progress' in result:
# Main's session also took the focus mode at once: this session's /verbose state.
connection.authority.sessions[ref.session_id].tool_progress_mode = result['tool_progress']
+ if key == 'skin':
+ await _broadcast_skin(connection)
return {'key': key, **result}
+
+
+async def _broadcast_skin(connection):
+ """Main repainted every surface of the profile: ``skin.changed`` on each attached session."""
+ def resolve():
+ import sys
+ from gateway.run import _profile_runtime_scope
+ from hermes_cli.config import load_config
+ from tui_gateway.change_watcher import skin_payload
+ with _profile_runtime_scope(Path(connection.authority.profile_id)):
+ payload = skin_payload(load_config())
+ if (server := sys.modules.get('tui_gateway.server')) is not None:
+ server._note_skin_broadcast() # as main: the config watcher must not repaint it again
+ return payload
+ payload = await asyncio.to_thread(resolve)
+ for session_id, live in list(connection.authority.sessions.items()):
+ if live.subscribers:
+ live.event_stream.publish(session_id, payload, event_type='skin.changed')
diff --git a/tests/gateway/test_session_tui_config.py b/tests/gateway/test_session_tui_config.py
index 578592846b9..1c73d23af36 100644
--- a/tests/gateway/test_session_tui_config.py
+++ b/tests/gateway/test_session_tui_config.py
@@ -2,6 +2,7 @@
/indicator) are written by the shared owner into the OWNING profile's config.yaml, like main's
per-TUI sidecar ``config.set`` — never refused, never inference."""
import asyncio
+import json
import hermes_yaml as yaml
import pytest
@@ -56,3 +57,52 @@ def test_display_preferences_theme_and_indicator_persist_to_the_profile(tmp_path
assert _display(home)['tui_theme'] == 'dark'
assert not admissions(home) and not peer.requests
asyncio.run(probe())
+
+
+async def _rpc_and_events(ws, method, **params):
+ """``rpc`` that keeps the event frames delivered before the reply (``rpc`` drops them)."""
+ await ws.send(json.dumps({'jsonrpc': '2.0', 'id': method, 'method': method, 'params': params}))
+ events = []
+ async with asyncio.timeout(20):
+ while True:
+ frame = json.loads(await ws.recv())
+ if frame.get('id') == method:
+ return frame, events
+ if frame.get('method') == 'event':
+ events.append(frame['params'])
+
+
+async def _skin_event(ws, sid, seen=()):
+ """The session's own frame: the owner's repaint of THIS profile (the process-wide change
+ watcher is session-less and only watches the launch profile)."""
+ for params in seen:
+ if params['type'] == 'skin.changed' and params['session_id'] == sid:
+ return params['payload']
+ async with asyncio.timeout(20):
+ while True:
+ frame = json.loads(await ws.recv())
+ if (frame.get('method') == 'event' and frame['params']['type'] == 'skin.changed'
+ and frame['params']['session_id'] == sid):
+ return frame['params']['payload']
+
+
+def test_skin_persists_and_repaints_every_attached_tui_of_the_profile(tmp_path):
+ with owner(tmp_path) as (home, peer, desc):
+ async def probe():
+ async with websocket(home, desc) as ws, websocket(home, desc) as other:
+ sid = (await rpc(ws, 'session.create', request_id='skin', source='tui',
+ toolsets=[]))['result']['session_id']
+ peer_sid = (await rpc(other, 'session.create', request_id='skin-peer', source='tui',
+ toolsets=[]))['result']['session_id']
+ result, seen = await _rpc_and_events(ws, 'config.set', key='skin', value='mono')
+ assert result.get('result') == {'key': 'skin', 'value': 'mono'}, result
+ # Main broadcast the resolved skin to every surface of the profile.
+ for socket, session, frames in ((ws, sid, seen), (other, peer_sid, ())):
+ payload = await _skin_event(socket, session, frames)
+ assert payload['name'] == 'mono' and payload['colors'], payload
+ assert _display(home)['skin'] == 'mono'
+ assert (await rpc(ws, 'config.get', key='skin'))['result']['value'] == 'mono'
+ assert (await rpc(ws, 'config.set', key='skin', value='')).get('error', {}).get('message') == 'invalid_params'
+ assert not admissions(home) and not peer.requests
+ asyncio.run(probe())
diff --git a/tui_gateway/change_watcher.py b/tui_gateway/change_watcher.py
index 5669174eabd..faff2891946 100644
--- a/tui_gateway/change_watcher.py
+++ b/tui_gateway/change_watcher.py
@@ -12,9 +12,15 @@ _registry = HandlerRegistry()
def resolve_skin() -> dict:
+ return skin_payload(_load_cfg())
+
+
+def skin_payload(config: dict) -> dict:
+ """The ``skin.changed`` / ``gateway.ready`` skin for ``config``'s ``display.skin`` (``{}`` when the
+ skin engine fails). Pure of server state: the shared owner calls it under the profile's scope."""
try:
from hermes_cli.skin_engine import init_skin_from_config, get_active_skin
- init_skin_from_config(_load_cfg())
+ init_skin_from_config(config)
skin = get_active_skin()
# light/dark are paired palettes: the TUI prefers the block matching terminal polarity.
return {
diff --git a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
index be9a5aa27af..3b9d043e2d4 100644
--- a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
+++ b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
@@ -203,7 +203,7 @@ it('/stop is session-scoped; process-global /reload-mcp refuses on the shared ga
it('setting writes the shared gateway has no verb for say so instead of a bare invalid_params; reads still work', async () => {
const { request, slash, sys } = harness()
- for (const cmd of ['/reasoning high --global', '/skin mono', '/fast fast', '/personality pirate', '/skin']) {
+ for (const cmd of ['/reasoning high --global', '/fast fast', '/personality pirate', '/skin']) {
slash(cmd)
}
@@ -214,13 +214,23 @@ it('setting writes the shared gateway has no verb for say so instead of a bare i
const notices = sys.mock.calls.map(([text]) => String(text))
- for (const name of ['reasoning', 'skin', 'fast', 'personality']) {
+ for (const name of ['reasoning', 'fast', 'personality']) {
expect(notices).toContain(`/${name} is not available on the shared gateway yet`)
}
expect(notices.some(line => /skin: default/.test(line))).toBe(true)
})
+it('/skin writes the profile through the owner\'s config.set like main (the owner repaints via skin.changed)', async () => {
+ const { request, slash, sys } = harness()
+
+ slash('/skin mono')
+ await flush()
+
+ expect(request).toHaveBeenCalledWith('config.set', { key: 'skin', value: 'mono' })
+ expect(sys.mock.calls.map(([text]) => String(text))).toEqual(['skin → mono'])
+})
+
it('/theme and /indicator write the profile through the owner\'s config.set like main', async () => {
const { request, slash, sys } = harness()
diff --git a/ui-tui/src/app/slash/commands/session.ts b/ui-tui/src/app/slash/commands/session.ts
index d5461a83c42..b1d92ab2142 100644
--- a/ui-tui/src/app/slash/commands/session.ts
+++ b/ui-tui/src/app/slash/commands/session.ts
@@ -563,12 +563,6 @@ export const sessionCommands: SlashCommand[] = [
)
}
- // The shared owner serves this setting's read, not its write (a config.yaml / per-session
- // setting it has no frozen-policy verb for yet): say so instead of a bare invalid_params.
- if (ctx.gateway.gw?.isCanonical) {
- return ctx.transcript.sys(t('canonical.controls.notAvailable', 'skin'))
- }
-
ctx.gateway
.rpc<ConfigSetResponse>('config.set', { key: 'skin', value: arg })
.then(