The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(tui): add attachments.storage config for workspace attachment staging
Brooklyn Nicholson7a21d15c3532
diff --git a/cli-config.yaml.example b/cli-config.yaml.exampleindex 60a94f6eed1..ff5425436d4 100644--- a/cli-config.yaml.example+++ b/cli-config.yaml.example@@ -42,6 +42,21 @@ database:runtime:nofile_soft_limit: 4096+# =============================================================================+# Attachments+# =============================================================================+# Where the TUI/Desktop gateway stages session file attachments (file uploads and+# pasted text). Read per profile: a session bound to profile X follows X's own+# config.yaml, so each agent's attachments stay with its workspace.+# hermes-home (default) <profile home>/attachments — the directory container+# backends bind-mount, so @file: refs resolve inside the sandbox.+# workspace <session workspace>/.hermes/attachments — staging lands inside+# the allowed reference root, so the profile's agent can always+# read its own attachments back. A remote (ssh) workspace keeps+# the profile home directory either way.+attachments:+ storage: "hermes-home"+# =============================================================================# Plugin Installation# =============================================================================diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 34351128a46..a1fa4ffb3eb 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -50,6 +50,16 @@ DEFAULT_CONFIG = {# terminal's session (tmux/kitty/wezterm pane, tty). false = resume globally most-recent."terminal_continue": True,},+ # Where the TUI/desktop gateway stages session file attachments (uploads, pasted+ # text). "hermes-home" (default) keeps <profile home>/attachments — the dir+ # container backends bind-mount, so @file: refs resolve in the sandbox (#76577).+ # "workspace" opts into <session workspace>/.hermes/attachments: staging lands+ # inside the allowed ref root, so the same profile's agent can always read its+ # own attachments back (#110662). Read per profile from that profile's config;+ # a remote (ssh) workspace keeps the profile home dir either way.+ "attachments": {+ "storage": "hermes-home",+ },"agent": {# Turn cap. null = unlimited (default; caps caused silent mid-task truncation). Positive int# caps; "none"/"unlimited"/"inf"/0/-1 also mean unlimited (resolve_turn_limit).diff --git a/tests/e2e/core/upgrade/test_config_roundtrip_properties.py b/tests/e2e/core/upgrade/test_config_roundtrip_properties.pyindex 06d6c6bc1e7..4d7008811d3 100644--- a/tests/e2e/core/upgrade/test_config_roundtrip_properties.py+++ b/tests/e2e/core/upgrade/test_config_roundtrip_properties.py@@ -236,7 +236,12 @@ def _value_for(default: Any, rng: random.Random, *, long: bool, env: dict[str, sif roll < 0.08:return Noneif roll < 0.18:- return copy.deepcopy(default) if not isinstance(default, (dict, list)) else None+ # Same-value-as-default write. Only representable scalars may be+ # deep-copied: a default-less target (e.g. c18_custom_root) passes the+ # _MISSING sentinel, which must never be planted in the config tree.+ if isinstance(default, (bool, int, float, str)) or default is None:+ return copy.deepcopy(default)+ return Noneif isinstance(default, bool):return rng.random() < 0.5if isinstance(default, int):diff --git a/tui_gateway/prompt_attachments.py b/tui_gateway/prompt_attachments.pyindex bdb749e4ef7..dfe870d1276 100644--- a/tui_gateway/prompt_attachments.py+++ b/tui_gateway/prompt_attachments.py@@ -83,11 +83,53 @@ def _session_home_dir(session: dict, name: str) -> Path:"""``<session home>/<name>``, anchored on the session's stored ``profile_home``: attachRPCs run BEFORE ``prompt.submit`` installs the profile HERMES_HOME override, whilethe sandbox mounts and the vision host-read allowlist resolve the *session profile's*- dirs at run time — writing anywhere else means the agent can never see the file."""+ dirs at run time — writing anywhere else means the agent can never see the file.++ ``attachments`` instead follows the session workspace when the profile's config opts+ in via ``attachments.storage: workspace`` (#110662): staging then lands inside the+ allowed ref root, so the ``@file:`` ref stays workspace-relative."""profile_home = session.get("profile_home")+ if name == "attachments" and _profile_attachments_storage(profile_home) == "workspace":+ if workspace := _session_attachments_workspace(session):+ return workspace / ".hermes" / "attachments"return (Path(profile_home) if profile_home else _hermes_home) / name+def _profile_attachments_storage(profile_home) -> str:+ """The session profile's ``attachments.storage`` ("" unless it opts into "workspace").++ Read from THAT profile's config.yaml — ``file.attach`` runs before ``prompt.submit``+ installs the profile scope, so the process config still belongs to the launch profile+ (same reason as ``_profile_configured_cwd``)."""+ import contextlib as _contextlib+ home = Path(profile_home) if profile_home else _hermes_home+ with _contextlib.suppress(Exception):+ from hermes_cli.config_effective import load_user_config_effective+ cfg_path = home / "config.yaml"+ if cfg_path.exists():+ attachments_cfg = load_user_config_effective(cfg_path).get("attachments")+ if isinstance(attachments_cfg, dict):+ return str(attachments_cfg.get("storage") or "").strip().lower()+ return ""+++def _session_attachments_workspace(session: dict) -> Path | None:+ """The session workspace when ``attachments.storage: workspace`` can actually write to it.++ Only a workspace on THIS host can hold gateway-staged files: an ssh-profile cwd lives+ on the remote execution host and a cwd that doesn't exist locally can't be vouched+ for, so both keep the bind-mounted ``<profile home>/attachments`` that container and+ remote backends receive (#76577)."""+ import contextlib as _contextlib+ if _cwd_is_remote(session.get("profile_home")):+ return None+ with _contextlib.suppress(Exception):+ workspace = Path(_session_cwd(session)).resolve()+ if workspace.is_dir():+ return workspace+ return None++def _session_images_dir(session: dict) -> Path:return _session_home_dir(session, "images")