Fixes#104849
Converted `get_skill_commands()` from a single-slot cache (keyed by
`(platform, home)` tuple checked at call time) to a multi-slot dict
`_skill_commands_by_key = {(platform, home): {commands}}` that memoizes
each distinct identity once and serves it forever. The old single-slot
design thrashed in the Desktop `hermes serve` backend because the
platform/home identity flapped between requests (`HERMES_SESSION_PLATFORM`
set to `""` vs. resolved to `None`, profile home overrides) so every
`commands.catalog` poll (~3x/5s) re-scanned the entire skills dir.
Also normalized empty-string to `None` in `_resolve_skill_commands_platform()`
so both spellings share one cache slot (#104849 root cause), and replaced
direct `scan_skill_commands()` calls in `tui_gateway/methods_tools.py`
(two sites: `_catalog_skills`, `_dispatch_skill`) with `get_skill_commands()`
so they benefit from the cache instead of bypassing it.
- `tests/agent/test_skill_commands.py`: 30 tests green (updated monkeypatch
fixtures from `_skill_commands*` globals to `_skill_commands_by_key`).
- New regression test `test_skill_cache_thrash_104849.py`: verifies that
platform flapping (`""` ⇄ `None`) hits the same cache slot (scan once),
and that distinct `(platform, home)` identities each get their own slot
(preserves #14536 / #88023 isolation fixes).
- `test_skill_commands_reload.py`, `test_skill_invocation_description.py`,
`test_prompt_cache_boundary.py`: green.
- `ruff check` on all modified files: clean.
Tested locally: after this patch the collision warning (skill `plan` vs.
core `/plan`) that repeated ~3x/5s while the Desktop window was focused
stopped entirely (zero scans mid-session), matching the issue reporter's
verification.
The gateway auto-load header ('[IMPORTANT: The "X" skill is auto-loaded.
Follow its instructions for this session.]') is scaffolding the describer
did not recognize: session previews showed the raw header + skill body,
the titler titled from the body, and 'hermes sessions retitle-skills'
never offered to repair auto-load sessions (#48359).
describe_skill_invocation now strips the payload (the built skill body
ends with the skill-directory footer note, so the LAST footer marks where
the user's typed text begins — a header quoted inside a body example
cannot end the payload early) and renders the typed request, or '/skill'
for a bare auto-load. Listing queries extend the scaffold LIKE predicate
so long auto-load rows get the same head+tail excerpt window, and the
retitle lookup finds auto-load sessions too.
Fixes#48359
A /skill invocation expands into a message that embeds the whole skill body.
Anything that summarizes a user turn from its raw content reads the skill's
prose as if the user had written it.
describe_skill_invocation() sits next to the existing extractor and reuses its
markers, returning `/work — fix the title leak` for an invocation with an
instruction and `/work` for a bare one. It also exports the SQL LIKE pattern
and excerpt-joint sentinel that listing queries need to recognize scaffolding
before a row reaches Python.