Files
hermes-agent/session_rules/activity.py
yoniebans d923fc1dc4 F20: session_rules comments describe behaviour, not its history
session_rules/turns.py and activity.py carried comments copied from main that retell history rather than behaviour: issue and PR numbers, "Pre-#NNNN" tags on the historical summary prefixes, a reviewer's name and review number, and a dated incident note on SUMMARY_PREFIX. Each now says what the code does, or the reference is dropped where the sentence already says it; the historical prefixes keep their byte-pinned text and each keeps a line naming what that wording lacks. Comments and docstrings only: the parse tree with docstrings blanked is identical before and after.

Reported-by: kshitijk4poor
2026-11-17 14:09:23 +01:00

40 lines
1.4 KiB
Python

"""The session activity rules the store applies when it stamps a session's activity: the description budget and the provenance vocabulary.
Standard library only.
"""
from __future__ import annotations
from enum import Enum
from typing import Optional
ACTIVITY_DESCRIPTION_MAX = 120
class ActivityProvenance(str, Enum):
"""Where a durable/in-memory activity stamp came from."""
UNKNOWN = "unknown"
# Compression writers: heartbeat, host timeout, cooldown, turn hold.
AGENT_COMPRESSION = "agent.compression"
AGENT_COMPRESSION_TIMEOUT = "agent.compression_timeout"
AGENT_COMPRESSION_COOLDOWN = "agent.compression_cooldown"
AGENT_COMPRESSION_TURNHOLD = "agent.compression_turnhold"
def bound_activity_description(description: Optional[str]) -> str:
"""Clamp free-form activity text to the shared description budget."""
text = (description or "").strip()
return text if len(text) <= ACTIVITY_DESCRIPTION_MAX else text[: ACTIVITY_DESCRIPTION_MAX - 1] + "…"
def normalize_activity_provenance(provenance: Optional[ActivityProvenance | str]) -> ActivityProvenance:
"""Return a known provenance, or ``UNKNOWN`` when unset/unrecognized."""
if isinstance(provenance, ActivityProvenance):
return provenance
try:
return ActivityProvenance((provenance or "").strip())
except ValueError:
return ActivityProvenance.UNKNOWN