Skip to content

The agent that grows with you

fix(tui-gateway): watch the skill roots of every active session's scope

Teknium5496793e5de1
diff --git a/agent/skill_commands.py b/agent/skill_commands.py
index 568b50d6f81..9cd9e449099 100644
--- a/agent/skill_commands.py
+++ b/agent/skill_commands.py
@@ -558,6 +558,37 @@ def scan_skill_commands() -> dict[str, dict[str, Any]]:
return commands
+# The most scopes the change watcher signs per pass (each is one ~1 ms stat walk).
+_MAX_WATCHED_SCOPES = 32
+
+
+def published_scopes_signature() -> tuple:
+ """Signature of every skill scope a session has resolved commands for, plus the ambient one.
+
+ One gateway serves sessions in several profiles and repos; each published ``(platform, home,
+ project)`` key names a scope whose roots (that profile's skills/external dirs, that repo's trusted
+ project skills) a viewer is looking at. The change watcher (``skills.changed``) compares this, so
+ an install in a session's repo B notifies viewers even when the gateway was launched in repo A.
+ Only command maps/catalogs refetch; a conversation's stored system prompt is never rebuilt.
+ """
+ from agent.runtime_cwd import reset_session_cwd, set_session_cwd
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+ with _publish_lock:
+ keys = list(_skill_commands_by_key)
+ scopes = sorted({(home, project) for _platform, home, project in keys if home})[:_MAX_WATCHED_SCOPES]
+ rows = [("", None, _skill_dirs_signature())]
+ for home, project in scopes:
+ home_token = set_hermes_home_override(home)
+ # No project: an empty session cwd would fall back to the process cwd; "/" resolves no repo.
+ cwd_token = set_session_cwd(project or os.path.sep)
+ try:
+ rows.append((home, project, _skill_dirs_signature()))
+ finally:
+ reset_session_cwd(cwd_token)
+ reset_hermes_home_override(home_token)
+ return tuple(rows)
+
+
def _skill_dirs_signature() -> Optional[tuple]:
"""Stat-cheap change signature of every skill root (the catalog's own: the mtime and child names of
every directory the catalog walks, depth-bounded, plus the disabled set and the platform). None when
diff --git a/tests/tui_gateway/test_change_watcher.py b/tests/tui_gateway/test_change_watcher.py
index 6af24eb211b..4488b5cd59f 100644
--- a/tests/tui_gateway/test_change_watcher.py
+++ b/tests/tui_gateway/test_change_watcher.py
@@ -502,3 +502,44 @@ def test_skill_installed_from_another_terminal_broadcasts_skills_changed(watcher
server._broadcast_watched_changes(now=10.0)
assert ("skills.changed", {}) in events
+
+
+def test_a_skill_installed_in_another_sessions_repo_broadcasts_skills_changed(watcher_home, monkeypatch, tmp_path):
+ """The gateway runs in repo A; a session's catalog resolved under repo B (its workspace, via the
+ session cwd). Installing a skill in B's ``.hermes/skills`` must still notify viewers: the watcher
+ signs every scope a session resolved commands in, not only the launch repo."""
+ import json
+ import agent.skill_commands as sc
+ import tools.skills_tool as st
+ from agent.runtime_cwd import reset_session_cwd, set_session_cwd
+ home, events = watcher_home
+ monkeypatch.setenv("HERMES_HOME", str(home))
+ (home / "skills").mkdir()
+ monkeypatch.setattr(st, "SKILLS_DIR", home / "skills")
+ monkeypatch.setattr(sc, "_skill_commands_by_key", {})
+ monkeypatch.setattr(sc, "_skill_commands_sig_by_key", {})
+ repo_a, repo_b = tmp_path / "repo-a", tmp_path / "repo-b"
+ for repo in (repo_a, repo_b):
+ (repo / ".git").mkdir(parents=True)
+ (repo / ".hermes" / "skills").mkdir(parents=True)
+ (home / "config.yaml").write_text(json.dumps({"skills": {"trusted_project_dirs": [str(repo_a), str(repo_b)]}}))
+ monkeypatch.chdir(repo_a)
+ st.clear_skills_cache()
+ token = set_session_cwd(str(repo_b))
+ try:
+ assert "/workspace-only" not in sc.get_skill_commands() # B's session catalog: publishes B's scope
+ finally:
+ reset_session_cwd(token)
+ server._broadcast_watched_changes(now=0.0)
+ assert not [e for e in events if e[0] == "skills.changed"]
+
+ skill = repo_b / ".hermes" / "skills" / "workspace-only"
+ skill.mkdir()
+ (skill / "SKILL.md").write_text("---\nname: workspace-only\ndescription: d\n---\nbody\n")
+ server._broadcast_watched_changes(now=10.0)
+ assert ("skills.changed", {}) in events
+ token = set_session_cwd(str(repo_b))
+ try:
+ assert "/workspace-only" in sc.get_skill_commands()
+ finally:
+ reset_session_cwd(token)
diff --git a/tui_gateway/change_watcher.py b/tui_gateway/change_watcher.py
index bf10566d037..26b0be489ab 100644
--- a/tui_gateway/change_watcher.py
+++ b/tui_gateway/change_watcher.py
@@ -362,11 +362,13 @@ def _bot_relay_outbox_sig():
def _skills_sig():
- """The skill roots' stat signature (``agent.skill_commands._skill_dirs_signature``): a skill
- installed or removed from another terminal (``hermes skills install``, a dropped SKILL.md) moves it,
- and attached clients refetch ``commands.catalog`` from this gateway instead of rescanning disk."""
- from agent.skill_commands import _skill_dirs_signature
- return _skill_dirs_signature()
+ """The skill roots' stat signature for every scope a session resolved commands in (each profile
+ home and session repo, not only the launch one: ``agent.skill_commands.published_scopes_signature``):
+ a skill installed or removed from another terminal (``hermes skills install``, a dropped SKILL.md,
+ nested under a category) moves it, and attached clients refetch ``commands.catalog`` from this
+ gateway instead of rescanning disk."""
+ from agent.skill_commands import published_scopes_signature
+ return published_scopes_signature()
# event → (check interval, signature fn, payload fn). Signatures are stat-cheap; the interval