The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(state): CJK range table; shared _coerce_or for import numeric coercion
Tekniumd86ebe66c027
diff --git a/hermes_state_portability.py b/hermes_state_portability.pyindex 125feb0f70c..e4b1836d4b1 100644--- a/hermes_state_portability.py+++ b/hermes_state_portability.py@@ -350,13 +350,22 @@ class SessionPortabilityMixin:raise ValueError(f"{field} must be JSON serializable") from exc@staticmethod- def _float_or_none(value: Any) -> Optional[float]:+ def _coerce_or(value: Any, cast, default):+ """``cast(value)``; *default* for None or an unparsable value."""if value is None:- return None+ return defaulttry:- return float(value)+ return cast(value)except (TypeError, ValueError):- return None+ return default++ @classmethod+ def _float_or_none(cls, value: Any) -> Optional[float]:+ return cls._coerce_or(value, float, None)++ @classmethod+ def _int_or_default(cls, value: Any, default: int = 0) -> int:+ return cls._coerce_or(value, int, default)@staticmethoddef _import_int_or_none(value: Any, field: str) -> Optional[int]:@@ -367,15 +376,6 @@ class SessionPortabilityMixin:except (TypeError, ValueError) as exc:raise ValueError(f"{field} must be an integer") from exc- @staticmethod- def _int_or_default(value: Any, default: int = 0) -> int:- if value is None:- return default- try:- return int(value)- except (TypeError, ValueError):- return default-@staticmethoddef _reasoning_json_value(value: Any) -> Any:if not isinstance(value, str):diff --git a/hermes_state_search.py b/hermes_state_search.pyindex ae25b820e22..6a5e98d28de 100644--- a/hermes_state_search.py+++ b/hermes_state_search.py@@ -824,15 +824,15 @@ class SessionSearchMixin:sanitized = sanitized.replace(f"\x00Q{i}\x00", quoted)return sanitized.strip()+ # Unified Ideographs, Extension A, Extension B, CJK Symbols, Hiragana, Katakana, Hangul Syllables.+ _CJK_RANGES = (+ (0x4E00, 0x9FFF), (0x3400, 0x4DBF), (0x20000, 0x2A6DF), (0x3000, 0x303F), (0x3040, 0x309F),+ (0x30A0, 0x30FF), (0xAC00, 0xD7AF),+ )+@staticmethoddef _is_cjk_codepoint(cp: int) -> bool:- return (0x4E00 <= cp <= 0x9FFF or # CJK Unified Ideographs- 0x3400 <= cp <= 0x4DBF or # CJK Extension A- 0x20000 <= cp <= 0x2A6DF or # CJK Extension B- 0x3000 <= cp <= 0x303F or # CJK Symbols- 0x3040 <= cp <= 0x309F or # Hiragana- 0x30A0 <= cp <= 0x30FF or # Katakana- 0xAC00 <= cp <= 0xD7AF) # Hangul Syllables+ return any(lo <= cp <= hi for lo, hi in SessionSearchMixin._CJK_RANGES)@staticmethoddef _contains_cjk(text: str) -> bool: