refactor(reload-skills): queue note for next turn, drop cache invalidation + agent tool

Salvage-follow-up to @shannonsands's /reload-skills PR. Trims the feature to
match the design: user-initiated rescan, no prompt-cache reset, no new
schema surface, no phantom user turn, and the next-turn note carries each
added/removed skill's 60-char description (not just its name).

Changes vs the original PR:

* Drop the in-process skills prompt-cache clear in reload_skills(). Skills
  are invoked at runtime via /skill-name, skills_list, or skill_view —
  they don't need to live in the system prompt for the model to use them.
  Keeping the cache intact preserves prefix caching across the reload so
  /reload-skills pays no cache-reset cost. (MCP has to break the cache
  because tool schemas must be known at conversation start; skills do not.)

* Drop the skills_reload agent tool and SKILLS_RELOAD_SCHEMA from
  tools/skills_tool.py, plus the four skills_reload enumerations in
  toolsets.py. No new schema surface — agents can already see a freshly-
  installed skill via skill_view / skills_list the moment it's on disk.

* Replace the phantom 'role: user' turn injection with a one-shot queued
  note. CLI uses self._pending_skills_reload_note (same pattern as
  _pending_model_switch_note, prepended to the next API call and cleared).
  Gateway uses self._pending_skills_reload_notes[session_key]. The note
  is prepended to the NEXT real user message in this session, so message
  alternation stays intact and nothing out-of-band is persisted to the
  transcript.

* reload_skills() now returns added/removed as
  [{'name': str, 'description': str}, ...] (description truncated to 60
  chars — matches the curator / gateway adapter budget). The injected
  next-turn note formats each entry as 'name — description' so the model
  can actually reason about which new skills to call without running
  skills_list first.

* Only emit the note when the diff is non-empty. On empty diff, print
  'No new skills detected' and do nothing else.

* Tests rewritten to cover the queue semantics, the description payload,
  and a regression guard that the prompt-cache snapshot is preserved.
This commit is contained in:
teknium1
2026-04-29 20:39:15 -07:00
committed by Teknium
parent 7966560fb5
commit dd2d1ba5e6
8 changed files with 304 additions and 277 deletions

View File

@@ -1513,60 +1513,3 @@ registry.register(
emoji="📚",
)
# ---------------------------------------------------------------------------
# skills_reload — rescan the skills dir without restarting the gateway
# ---------------------------------------------------------------------------
def skills_reload(task_id: str | None = None) -> str:
"""Re-scan ``~/.hermes/skills/`` and clear in-process skill caches.
Use this after installing a skill via the shell during a session so the
new skill becomes visible to ``skills_list`` / ``skill_view`` and the
skill catalogue in the system prompt without a gateway restart.
Returns:
JSON string with ``added``, ``removed``, ``unchanged``, ``total``,
and ``commands`` keys. ``added``/``removed`` are bare skill names
(no leading slash).
"""
try:
from agent.skill_commands import reload_skills as _reload
result = _reload()
except Exception as e:
return json.dumps({"success": False, "error": str(e)})
return json.dumps({
"success": True,
"added": result.get("added", []),
"removed": result.get("removed", []),
"unchanged_count": len(result.get("unchanged", [])),
"total": result.get("total", 0),
"commands": result.get("commands", 0),
})
SKILLS_RELOAD_SCHEMA = {
"name": "skills_reload",
"description": (
"Re-scan the skills directory and clear in-process skill caches. "
"Use after installing or removing a skill mid-session (e.g. via the "
"shell tool or skills_hub) so the new skill becomes visible to "
"skills_list / skill_view without restarting the gateway. Returns "
"the diff of added/removed skill names plus the new total count."
),
"parameters": {
"type": "object",
"properties": {},
"required": [],
},
}
registry.register(
name="skills_reload",
toolset="skills",
schema=SKILLS_RELOAD_SCHEMA,
handler=lambda args, **kw: skills_reload(task_id=kw.get("task_id")),
check_fn=check_skills_requirements,
emoji="🔄",
)