Skip to content

The agent that grows with you

fix: canonical /yolo toggles the session bypass and the TUI forwards --yolo

Tekniumd490ba059e9d
diff --git a/gateway/session_busy_controls.py b/gateway/session_busy_controls.py
index f649433c752..69544f4e45f 100644
--- a/gateway/session_busy_controls.py
+++ b/gateway/session_busy_controls.py
@@ -29,6 +29,8 @@ async def busy_config(connection, ref, params, *, write=False):
allowed = {'session_id', 'profile', 'key'} | ({'value'} if write else set())
if params.get('key') == 'verbose' and not set(params) - allowed and ref.session_id:
return verbose_config(connection, ref, params, write)
+ if params.get('key') == 'yolo' and not set(params) - allowed and ref.session_id:
+ return yolo_config(connection, ref, params, write)
if (set(params) - allowed or not ref.session_id or params.get('key') != 'busy'
or (write and params.get('value') not in ('interrupt', 'steer', 'queue'))):
raise RuntimeStoreError('invalid_params')
@@ -68,6 +70,30 @@ def verbose_config(connection, ref, params, write):
return {'key': 'verbose', 'value': current, 'scope': 'session'}
+_YOLO_WORDS = {'1': True, 'on': True, 'true': True, '0': False, 'off': False, 'false': False}
+
+
+def yolo_config(connection, ref, params, write):
+ """Session-scoped /yolo (TUI slash + Shift+Tab, Desktop toggle): this session's approval bypass,
+ never HERMES_YOLO_MODE or approvals.mode. A ``--yolo`` launch is seeded first, so revoking it
+ here is not re-enabled by the next turn's launch seeding."""
+ value = params.get('value')
+ if write and value is not None and str(value).strip().lower() not in _YOLO_WORDS:
+ raise RuntimeStoreError('invalid_params')
+ authorize(connection, ref, params, 'session:control' if write else 'session:read')
+ from gateway.session_policy import policy_for_source
+ from tools.approval import apply_launch_yolo, disable_session_yolo, enable_session_yolo, is_session_yolo_enabled
+ live = connection.authority.sessions[ref.session_id]
+ policy = policy_for_source(connection.authority.runner, live.source)
+ if policy is not None and policy.yolo:
+ apply_launch_yolo(live.route)
+ enabled = is_session_yolo_enabled(live.route)
+ if write:
+ enabled = not enabled if value is None else _YOLO_WORDS[str(value).strip().lower()]
+ (enable_session_yolo if enabled else disable_session_yolo)(live.route)
+ return {'key': 'yolo', 'value': '1' if enabled else '0', 'scope': 'session'}
+
+
async def correct(connection, ref, params, *, verb):
if (set(params) - {'session_id', 'profile', 'text', 'execution_generation'}
or not isinstance(params.get('text'), str) or not params['text'].strip()
diff --git a/gateway/session_config.py b/gateway/session_config.py
index ae95f8ef957..9abb57e621b 100644
--- a/gateway/session_config.py
+++ b/gateway/session_config.py
@@ -53,7 +53,7 @@ async def config_get(connection, ref, params):
key = params.get('key')
if not isinstance(key, str):
raise RuntimeStoreError('invalid_params')
- if key in ('busy', 'verbose'):
+ if key in ('busy', 'verbose', 'yolo'):
from gateway.session_busy_controls import busy_config
return await busy_config(connection, ref, params)
policy = _authorize(connection, ref, params)
diff --git a/tests/gateway/test_session_busy_controls.py b/tests/gateway/test_session_busy_controls.py
index 0503c396c87..51bcd8e7b68 100644
--- a/tests/gateway/test_session_busy_controls.py
+++ b/tests/gateway/test_session_busy_controls.py
@@ -189,3 +189,28 @@ def test_corrections_are_generation_fenced_and_consumed_by_same_provider_loop(tm
print(json.dumps({'ledger': admissions(home), 'model_requests': len(peer.requests),
'same_prefix': True, 'corrections_consumed': True}))
asyncio.run(probe())
+
+
+def test_session_yolo_toggle_is_session_scoped_and_revokes_launch_yolo(tmp_path):
+ """TUI `/yolo` / Shift+Tab and the Desktop toggle send `config.set key=yolo`; the canonical owner
+ answered invalid_params, so `/yolo` could never revoke a `--yolo` launch. It is this session's
+ bypass only (never config.yaml / HERMES_YOLO_MODE) and a launch YOLO reads as on until revoked."""
+ with owner(tmp_path) as (home, peer, desc):
+ async def probe():
+ async with websocket(home, desc) as ws:
+ launch = (await rpc(ws, 'session.create', request_id='y', source='tui', toolsets=[], yolo=True))['result']['session_id']
+ plain = (await rpc(ws, 'session.create', request_id='n', source='tui', toolsets=[]))['result']['session_id']
+ config_before = (home / 'config.yaml').read_bytes()
+ assert (await rpc(ws, 'config.get', session_id=launch, key='yolo')).get('result') == {
+ 'key': 'yolo', 'value': '1', 'scope': 'session'}
+ assert (await rpc(ws, 'config.set', session_id=launch, key='yolo', value='0'))['result']['value'] == '0'
+ assert (await rpc(ws, 'config.get', session_id=launch, key='yolo'))['result']['value'] == '0'
+ assert (await rpc(ws, 'config.get', session_id=plain, key='yolo'))['result']['value'] == '0'
+ assert (await rpc(ws, 'config.set', session_id=plain, key='yolo'))['result']['value'] == '1'
+ assert (await rpc(ws, 'config.get', session_id=launch, key='yolo'))['result']['value'] == '0'
+ assert (await rpc(ws, 'config.set', session_id=plain, key='yolo', value='maybe')
+ )['error']['message'] == 'invalid_params'
+ assert (home / 'config.yaml').read_bytes() == config_before
+ assert not admissions(home) and not peer.requests
+ asyncio.run(probe())
diff --git a/ui-tui/src/__tests__/canonicalGateway.test.ts b/ui-tui/src/__tests__/canonicalGateway.test.ts
index 0bdd11c6e01..9b6031a7d64 100644
--- a/ui-tui/src/__tests__/canonicalGateway.test.ts
+++ b/ui-tui/src/__tests__/canonicalGateway.test.ts
@@ -18,3 +18,9 @@ it('rebuilds --max-turns from the launcher environment as the integer the sessio
expect(options.max_turns).toBe(5)
expect(localCreationOptions({} as NodeJS.ProcessEnv)).not.toHaveProperty('max_turns')
})
+
+it('carries `hermes --tui --yolo` (HERMES_YOLO_MODE) onto session.create as the frozen launch flag', () => {
+ expect(localCreationOptions({ HERMES_YOLO_MODE: '1' } as NodeJS.ProcessEnv).yolo).toBe(true)
+ expect(localCreationOptions({ HERMES_YOLO_MODE: '0' } as NodeJS.ProcessEnv)).not.toHaveProperty('yolo')
+ expect(localCreationOptions({} as NodeJS.ProcessEnv)).not.toHaveProperty('yolo')
+})
diff --git a/ui-tui/src/canonicalGateway.ts b/ui-tui/src/canonicalGateway.ts
index 81d72bba457..f45a8ed276f 100644
--- a/ui-tui/src/canonicalGateway.ts
+++ b/ui-tui/src/canonicalGateway.ts
@@ -90,5 +90,9 @@ export function localCreationOptions(env = process.env): Record<string, unknown>
// requires an int, so the environment's text form is undone here.
if (env.HERMES_TUI_MAX_TURNS) { options.max_turns = Number(env.HERMES_TUI_MAX_TURNS) }
+ // `hermes --tui --yolo` exports HERMES_YOLO_MODE=1 (the in-process TUI read it); over the canonical
+ // gateway it must ride session.create as the frozen launch flag or the session prompts anyway.
+ if (['1', 'true', 'yes', 'on'].includes((env.HERMES_YOLO_MODE ?? '').trim().toLowerCase())) { options.yolo = true }
+
return options
}