mirror of
https://github.com/nesquena/hermes-webui.git
synced 2026-06-04 16:10:24 +00:00
dc1e369f89
The .usage.json file is owned by hermes-agent (tools/skill_usage.py). This change removes the webui-side increment logic to avoid: 1. File ownership conflict - both writing to same file 2. Schema mismatch - agent uses ISO strings, webui used floats 3. Concurrency issues - agent uses fcntl locks, webui had no locking 4. Double-counting - agent already increments counters server-side Changes: - api/skill_usage.py: keep only read_skill_usage(), remove increment functions - api/streaming.py: remove skill usage counter hook - api/routes.py: adapt response to pass through agent's format as-is, with defensive coercion for None values and metadata preservation - tests/test_skill_usage.py: remove increment tests (17→7 cases)
32 lines
1014 B
Python
32 lines
1014 B
Python
# ── Skill usage reader (read-only) ──
|
|
# Note: .usage.json is written by hermes-agent (tools/skill_usage.py).
|
|
# WebUI only reads to display usage stats in Insights page.
|
|
|
|
import json
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_USAGE_FILE = ".usage.json"
|
|
|
|
|
|
def read_skill_usage(skills_dir: Path) -> dict:
|
|
"""Read the current .usage.json.
|
|
|
|
Returns the raw nested dict ``{skill_name: {use_count: N, view_count: N, ...}}``
|
|
or an empty dict when the file does not exist or is corrupt.
|
|
"""
|
|
usage_path = skills_dir / _USAGE_FILE
|
|
if not usage_path.exists():
|
|
return {}
|
|
try:
|
|
raw = usage_path.read_text(encoding="utf-8")
|
|
data = json.loads(raw)
|
|
if isinstance(data, dict):
|
|
return data
|
|
logger.debug("Unexpected .usage.json format, resetting: %s", raw[:200])
|
|
return {}
|
|
except (json.JSONDecodeError, OSError) as exc:
|
|
logger.debug("Failed to read .usage.json: %s", exc)
|
|
return {} |