The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tui_gateway): stack @method/@_profile_scoped on vault handlers like every sibling
kshitijk4poord7b836ab1c0c
diff --git a/tests/tui_gateway/test_vault_methods.py b/tests/tui_gateway/test_vault_methods.pyindex ccc745a3856..24746f0986c 100644--- a/tests/tui_gateway/test_vault_methods.py+++ b/tests/tui_gateway/test_vault_methods.py@@ -158,14 +158,8 @@ def test_launch_profile_vault_rpcs_stay_scoped_once_the_process_multiplexes(homelaunch profile's vault.* calls (Desktop sends no ``profile`` for it) must still bind the launchsecret scope — otherwise every enabled manager's token read raises UnscopedSecretError and thePasswords & Logins panel shows "Could not load vault items" until the gateway restarts."""- from agent.secret_scope import is_multiplex_active, set_multiplex_active+ from agent.secret_scope import set_multiplex_activemonkeypatch.setattr("agent.vault_backends.base.is_installed", lambda name: name == "onepassword")- monkeypatch.setenv("OP_SERVICE_ACCOUNT_TOKEN", "ops_launch_profile_token")- previous = is_multiplex_active()- set_multiplex_active(True)- try:- rows = _sources_rows(home)- finally:- set_multiplex_active(previous)- assert rows["onepassword"]["enabled"] is True+ set_multiplex_active(True) # conftest resets the latch per test+ assert _sources_rows(home)["onepassword"]["enabled"] is Truediff --git a/tui_gateway/methods_vault.py b/tui_gateway/methods_vault.pyindex c5f97dbd1ae..17c09976f71 100644--- a/tui_gateway/methods_vault.py+++ b/tui_gateway/methods_vault.py@@ -28,15 +28,11 @@ method_ctx.py) and may reference server module globals (``_ok``, ``_err``).from .method_ctx import HandlerRegistry_registry = HandlerRegistry()---def method(name: str):- """``@method(name)`` under server.py's ``@_profile_scoped`` — the one scoping path every RPC uses,- so the launch profile (no ``params.profile``) gets its secret scope bound once the process- multiplexes instead of its manager-token reads raising ``UnscopedSecretError``."""- def deco(fn):- return _registry.method(name)(_registry.profile_scoped(fn))- return deco+method = _registry.method+# server.py's ``@_profile_scoped`` (applied at install): the one scoping path every RPC uses, so the+# launch profile (no ``params.profile``) keeps its secret scope bound once the process multiplexes+# instead of its manager-token reads raising ``UnscopedSecretError``.+_profile_scoped = _registry.profile_scoped# JSON-RPC error code 5095 = vault failure (validation + store errors).# Kept as a literal inside handler bodies: handlers are rebound onto@@ -44,6 +40,7 @@ def method(name: str):@method("vault.list")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Metadata-only listing across every enabled backend (local + unlocked password managers).Each item carries ``backend``; locked managers contribute nothing (see vault.sources)."""@@ -61,6 +58,7 @@ def _(rid, params: dict) -> dict:@method("vault.sources")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Status of every login source: {name, display_name, enabled, needs_unlock, unlocked, installed}."""from agent.vault_backends import enabled_backends@@ -78,6 +76,7 @@ def _(rid, params: dict) -> dict:@method("vault.source.set")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Enable/disable an external manager: writes ``vault.<name>.enabled`` and locks it when disabling."""from agent.vault_backends.base import external_backend_classes@@ -101,6 +100,7 @@ def _(rid, params: dict) -> dict:@method("vault.unlock")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Unlock a manager with the master password typed in the Settings dialog (consumed by the CLI on stdin)."""from agent.vault_backends import enabled_backends@@ -122,6 +122,7 @@ def _(rid, params: dict) -> dict:@method("vault.lock")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Forget a manager's session token (or every one when ``name`` is omitted)."""from agent.vault_backends.unlock import lock@@ -132,6 +133,7 @@ def _(rid, params: dict) -> dict:@method("vault.add")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Add a vault item. ``secret`` values go straight into the encrypted store.@@ -164,6 +166,7 @@ def _(rid, params: dict) -> dict:@method("vault.remove")+@_profile_scopeddef _(rid, params: dict) -> dict:"""Remove a vault item by id. Result: ``{removed: bool}``."""try: