Skip to content

The agent that grows with you

feat(gateway): serve /personality on the owner

Teknium7f136bcc2dd0
diff --git a/gateway/session_tui_config.py b/gateway/session_tui_config.py
index 7e7d0f6d6d5..fa18457aefb 100644
--- a/gateway/session_tui_config.py
+++ b/gateway/session_tui_config.py
@@ -173,6 +173,8 @@ async def config_set(connection, ref, params):
value = params.get('value')
if key == 'fast':
return await _set_fast(connection, ref, policy, value)
+ if key == 'personality':
+ return await asyncio.to_thread(_set_personality, connection, value)
result = await asyncio.to_thread(_write_profile_config, connection,
lambda cfg: _set_display(cfg, key, value))
if key == 'focus' and ref.session_id and 'tool_progress' in result:
@@ -247,3 +249,20 @@ async def _set_fast(connection, ref, policy, value):
connection.authority.runner._set_session_service_tier_override(
connection.authority.sessions[ref.session_id].route, tier)
return {'key': 'fast', 'value': service_tier_word(tier)}
+
+
+def _set_personality(connection, value):
+ """Main's /personality: validated against the profile's personalities and persisted through
+ ``hermes_cli.personality`` (the only sanctioned write). Every next turn of the profile's sessions
+ resolves its ephemeral prompt from that config, and the changed prompt rebuilds the cached agent."""
+ from gateway.run import _profile_runtime_scope
+ from hermes_cli.config import load_config
+ from hermes_cli.personality import persist_personality, resolve_personality
+ with _profile_runtime_scope(Path(connection.authority.profile_id)), _WRITE_LOCK:
+ try:
+ name, _prompt = resolve_personality(str(value or ''), load_config())
+ except ValueError as exc:
+ raise RuntimeStoreError('unknown_personality') from exc
+ if not persist_personality(name):
+ raise RuntimeStoreError('storage_unavailable')
+ return {'key': 'personality', 'value': str(value or 'none'), 'history_reset': False}
diff --git a/tests/gateway/test_session_tui_config.py b/tests/gateway/test_session_tui_config.py
index 479cb312f0a..158abdebd29 100644
--- a/tests/gateway/test_session_tui_config.py
+++ b/tests/gateway/test_session_tui_config.py
@@ -7,7 +7,7 @@ import json
import hermes_yaml as yaml
import pytest
-from tests.gateway.test_session_busy_controls import owner, admissions
+from tests.gateway.test_session_busy_controls import owner, admissions, settled
from tests.gateway.fixtures.local_recovery_probe import rpc, websocket
@@ -137,3 +137,29 @@ def test_fast_is_session_scoped_validated_and_read_back(tmp_path):
assert (home / 'config.yaml').read_bytes() == before
assert not admissions(home) and not peer.requests
asyncio.run(probe())
+
+
+def test_personality_persists_to_the_profile_and_drives_the_next_turn(tmp_path):
+ with owner(tmp_path) as (home, peer, desc):
+ async def probe():
+ async with websocket(home, desc) as ws:
+ sid = (await rpc(ws, 'session.create', request_id='persona', source='tui',
+ toolsets=[]))['result']['session_id']
+ await rpc(ws, 'prompt.submit', session_id=sid, input_id='before', text='BEFORE')
+ await settled(home)
+ result = await rpc(ws, 'config.set', key='personality', value='pirate', session_id=sid)
+ assert result.get('result') == {'key': 'personality', 'value': 'pirate',
+ 'history_reset': False}, result
+ assert _display(home)['personality'] == 'pirate'
+ await rpc(ws, 'prompt.submit', session_id=sid, input_id='after', text='AFTER')
+ await settled(home)
+ systems = [' '.join(str(m.get('content')) for m in body['messages'] if m['role'] == 'system')
+ for body in peer.requests]
+ assert 'Captain Hermes' not in systems[0] and 'Captain Hermes' in systems[-1], systems
+ assert (await rpc(ws, 'config.set', key='personality', value='nobody', session_id=sid)
+ ).get('error', {}).get('message') == 'unknown_personality'
+ result = await rpc(ws, 'config.set', key='personality', value='none', session_id=sid)
+ assert result.get('result', {}).get('value') == 'none', result
+ assert _display(home)['personality'] == ''
+ asyncio.run(probe())
diff --git a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
index d42939df311..e6cb01a0617 100644
--- a/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
+++ b/ui-tui/src/__tests__/canonicalSlashCommands.test.ts
@@ -200,10 +200,10 @@ 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 () => {
+it('/reasoning --global still says the shared gateway has no verb for it; /skin reads still work', async () => {
const { request, slash, sys } = harness()
- for (const cmd of ['/reasoning high --global', '/personality pirate', '/skin']) {
+ for (const cmd of ['/reasoning high --global', '/skin']) {
slash(cmd)
}
@@ -214,13 +214,20 @@ 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', 'personality']) {
- expect(notices).toContain(`/${name} is not available on the shared gateway yet`)
- }
-
+ expect(notices).toContain('/reasoning is not available on the shared gateway yet')
expect(notices.some(line => /skin: default/.test(line))).toBe(true)
})
+it('/personality <name> is the owner\'s config.set like main', async () => {
+ const { request, slash, sys } = harness()
+
+ slash('/personality pirate')
+ await flush()
+
+ expect(request).toHaveBeenCalledWith('config.set', { key: 'personality', session_id: 'owner', value: 'pirate' })
+ expect(sys.mock.calls.map(([text]) => String(text))).toEqual(['personality: pirate'])
+})
+
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()
diff --git a/ui-tui/src/app/slash/commands/session.ts b/ui-tui/src/app/slash/commands/session.ts
index 9e8271215c2..ffc4c83e5b6 100644
--- a/ui-tui/src/app/slash/commands/session.ts
+++ b/ui-tui/src/app/slash/commands/session.ts
@@ -261,12 +261,6 @@ export const sessionCommands: SlashCommand[] = [
return
}
- // 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', 'personality'))
- }
-
ctx.gateway.rpc<ConfigSetResponse>('config.set', { key: 'personality', session_id: ctx.sid, value: arg }).then(
ctx.guarded<ConfigSetResponse>(r => {
if (r.history_reset) {