mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-30 01:41:43 +00:00
fix(config): respect quoted false for session vacuum_after_prune
This commit is contained in:
parent
4fade39c90
commit
7da299ddb0
6 changed files with 94 additions and 15 deletions
23
utils.py
23
utils.py
|
|
@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
TRUTHY_STRINGS = frozenset({"1", "true", "yes", "on"})
|
||||
FALSY_STRINGS = frozenset({"0", "false", "no", "off"})
|
||||
|
||||
|
||||
def is_truthy_value(value: Any, default: bool = False) -> bool:
|
||||
|
|
@ -28,6 +29,28 @@ def is_truthy_value(value: Any, default: bool = False) -> bool:
|
|||
return bool(value)
|
||||
|
||||
|
||||
def coerce_bool(value: Any, default: bool = False) -> bool:
|
||||
"""Coerce bool-ish config values while preserving the caller's default.
|
||||
|
||||
Unlike ``bool(value)``, this treats quoted config strings like
|
||||
``"false"`` and ``"0"`` as ``False`` instead of truthy non-empty
|
||||
strings. Unrecognized strings fall back to ``default`` so malformed
|
||||
YAML values don't silently flip behavior.
|
||||
"""
|
||||
if value is None:
|
||||
return default
|
||||
if isinstance(value, bool):
|
||||
return value
|
||||
if isinstance(value, str):
|
||||
lowered = value.strip().lower()
|
||||
if lowered in TRUTHY_STRINGS:
|
||||
return True
|
||||
if lowered in FALSY_STRINGS:
|
||||
return False
|
||||
return default
|
||||
return bool(value)
|
||||
|
||||
|
||||
def env_var_enabled(name: str, default: str = "") -> bool:
|
||||
"""Return True when an environment variable is set to a truthy value."""
|
||||
return is_truthy_value(os.getenv(name, default), default=False)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue