Skip to content

The agent that grows with you

fix(tui_gateway): legacy paste.collapse writes under the ticket's profile

Teknium5a6907154d12
diff --git a/tests/tui_gateway/test_legacy_paste_profile_home.py b/tests/tui_gateway/test_legacy_paste_profile_home.py
new file mode 100644
index 00000000000..defcc146a0a
--- /dev/null
+++ b/tests/tui_gateway/test_legacy_paste_profile_home.py
@@ -0,0 +1,20 @@
+"""A legacy ``paste.collapse`` on the shared owner writes under the ticket's profile home."""
+from pathlib import Path
+from types import SimpleNamespace
+
+import tui_gateway.server as srv
+from gateway.runtime_bootstrap import _PURPOSE_CAPABILITIES
+from tui_gateway.ws_legacy_fallback import dispatch_legacy
+
+
+def test_secondary_profile_paste_lands_in_its_own_home(tmp_path, monkeypatch):
+ launch, secondary = tmp_path / 'launch', tmp_path / 'profiles' / 'coder'
+ launch.mkdir()
+ secondary.mkdir(parents=True)
+ monkeypatch.setattr(srv, '_hermes_home', launch)
+ actor = SimpleNamespace(profile_id=str(secondary), capabilities=_PURPOSE_CAPABILITIES['interactive'])
+ reply = dispatch_legacy(srv, {'jsonrpc': '2.0', 'id': 1, 'method': 'paste.collapse',
+ 'params': {'text': 'secret\npaste'}}, None, actor)
+ path = Path(reply['result']['path'])
+ assert path.parent == secondary / 'pastes' and path.read_text() == 'secret\npaste'
+ assert not (launch / 'pastes').exists()
diff --git a/tui_gateway/methods_complete.py b/tui_gateway/methods_complete.py
index ca6b1b092fb..6c57e3caba7 100644
--- a/tui_gateway/methods_complete.py
+++ b/tui_gateway/methods_complete.py
@@ -40,7 +40,9 @@ def _(rid, params: dict) -> dict:
return _err(rid, 4004, "empty paste")
_paste_counter += 1
line_count = text.count("\n") + 1
- paste_dir = _hermes_home / "pastes"
+ # The shared owner's legacy fallback serves secondary profiles too: write under the ticket's home.
+ from tui_gateway.ws_legacy_fallback import connection_profile_home
+ paste_dir = Path(connection_profile_home() or _hermes_home) / "pastes"
paste_dir.mkdir(parents=True, exist_ok=True)
from datetime import datetime
paste_file = paste_dir / f"paste_{_paste_counter}_{datetime.now().strftime('%H%M%S')}.txt"