mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-02 07:11:49 +00:00
chore: ruff auto-fix PLR6201 resweep — tuple → set in membership tests (#27355)
Six days after #23937 (608 fixes) the codebase had accumulated 241 new PLR6201 violations. Same mechanical `x in (...)` → `x in {...}` fix, same zero-risk profile: set lookup is O(1) vs O(n) for tuple and the two are semantically equivalent for hashable scalar membership tests. All 241 instances fixed via `ruff check --select PLR6201 --fix --unsafe-fixes`, zero remaining. Every changed value is a hashable scalar (str/int/None/enum/signal); no risk of unhashable runtime errors. No behavior change. Test plan: - 119 files changed, +244/-244 (net zero) — exactly one-line edits - `ruff check` clean afterward - Compile checks pass on the largest touched files (cli.py, run_agent.py, gateway/run.py, gateway/platforms/discord.py, model_tools.py) - Subset broad test run on tests/gateway/ tests/hermes_cli/ tests/agent/ tests/tools/: 18187 passed, 59 pre-existing failures (verified against origin/main with the same shape — identical failure count, identical category — all xdist test-order flakes unrelated to this change) Follows the same template as PR #23937 ([tracker: #23972](https://github.com/NousResearch/hermes-agent/issues/23972)).
This commit is contained in:
parent
ad00777f04
commit
5fba236644
119 changed files with 244 additions and 244 deletions
|
|
@ -263,7 +263,7 @@ class ByteRoverMemoryProvider(MemoryProvider):
|
|||
|
||||
def on_memory_write(self, action: str, target: str, content: str) -> None:
|
||||
"""Mirror built-in memory writes to ByteRover."""
|
||||
if action not in ("add", "replace") or not content:
|
||||
if action not in {"add", "replace"} or not content:
|
||||
return
|
||||
|
||||
def _write():
|
||||
|
|
@ -289,7 +289,7 @@ class ByteRoverMemoryProvider(MemoryProvider):
|
|||
for msg in messages[-10:]: # last 10 messages
|
||||
role = msg.get("role", "")
|
||||
content = msg.get("content", "")
|
||||
if isinstance(content, str) and content.strip() and role in ("user", "assistant"):
|
||||
if isinstance(content, str) and content.strip() and role in {"user", "assistant"}:
|
||||
parts.append(f"{role}: {content[:500]}")
|
||||
|
||||
if not parts:
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ def _build_embedded_profile_env(config: dict[str, Any], *, llm_api_key: str | No
|
|||
current_base_url = config.get("llm_base_url") or os.environ.get("HINDSIGHT_API_LLM_BASE_URL", "")
|
||||
|
||||
# The embedded daemon expects OpenAI wire format for these providers.
|
||||
daemon_provider = "openai" if current_provider in ("openai_compatible", "openrouter") else current_provider
|
||||
daemon_provider = "openai" if current_provider in {"openai_compatible", "openrouter"} else current_provider
|
||||
|
||||
env_values = {
|
||||
"HINDSIGHT_API_LLM_PROVIDER": str(daemon_provider),
|
||||
|
|
@ -596,7 +596,7 @@ class HindsightMemoryProvider(MemoryProvider):
|
|||
try:
|
||||
cfg = _load_config()
|
||||
mode = cfg.get("mode", "cloud")
|
||||
if mode in ("local", "local_embedded"):
|
||||
if mode in {"local", "local_embedded"}:
|
||||
available, _ = _check_local_runtime()
|
||||
return available
|
||||
if mode == "local_external":
|
||||
|
|
@ -888,7 +888,7 @@ class HindsightMemoryProvider(MemoryProvider):
|
|||
from hindsight import HindsightEmbedded
|
||||
HindsightEmbedded.__del__ = lambda self: None
|
||||
llm_provider = self._config.get("llm_provider", "")
|
||||
if llm_provider in ("openai_compatible", "openrouter"):
|
||||
if llm_provider in {"openai_compatible", "openrouter"}:
|
||||
llm_provider = "openai"
|
||||
logger.debug("Creating HindsightEmbedded client (profile=%s, provider=%s)",
|
||||
self._config.get("profile", "hermes"), llm_provider)
|
||||
|
|
@ -1132,7 +1132,7 @@ class HindsightMemoryProvider(MemoryProvider):
|
|||
self._mode = "disabled"
|
||||
return
|
||||
self._api_key = self._config.get("apiKey") or self._config.get("api_key") or os.environ.get("HINDSIGHT_API_KEY", "")
|
||||
default_url = _DEFAULT_LOCAL_URL if self._mode in ("local_embedded", "local_external") else _DEFAULT_API_URL
|
||||
default_url = _DEFAULT_LOCAL_URL if self._mode in {"local_embedded", "local_external"} else _DEFAULT_API_URL
|
||||
self._api_url = self._config.get("api_url") or os.environ.get("HINDSIGHT_API_URL", default_url)
|
||||
self._llm_base_url = self._config.get("llm_base_url", "")
|
||||
|
||||
|
|
@ -1152,10 +1152,10 @@ class HindsightMemoryProvider(MemoryProvider):
|
|||
self._budget = budget if budget in _VALID_BUDGETS else "mid"
|
||||
|
||||
memory_mode = self._config.get("memory_mode", "hybrid")
|
||||
self._memory_mode = memory_mode if memory_mode in ("context", "tools", "hybrid") else "hybrid"
|
||||
self._memory_mode = memory_mode if memory_mode in {"context", "tools", "hybrid"} else "hybrid"
|
||||
|
||||
prefetch_method = self._config.get("recall_prefetch_method") or self._config.get("prefetch_method", "recall")
|
||||
self._prefetch_method = prefetch_method if prefetch_method in ("recall", "reflect") else "recall"
|
||||
self._prefetch_method = prefetch_method if prefetch_method in {"recall", "reflect"} else "recall"
|
||||
|
||||
# Bank options
|
||||
self._bank_mission = self._config.get("bank_mission", "")
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ class HonchoMemoryProvider(MemoryProvider):
|
|||
# ----- Port #4053: cron guard -----
|
||||
agent_context = kwargs.get("agent_context", "")
|
||||
platform = kwargs.get("platform", "cli")
|
||||
if agent_context in ("cron", "flush") or platform == "cron":
|
||||
if agent_context in {"cron", "flush"} or platform == "cron":
|
||||
logger.debug("Honcho skipped: cron/flush context (agent_context=%s, platform=%s)",
|
||||
agent_context, platform)
|
||||
self._cron_skipped = True
|
||||
|
|
@ -404,7 +404,7 @@ class HonchoMemoryProvider(MemoryProvider):
|
|||
# pop_context_result() in prefetch(). Dialectic prewarm runs the
|
||||
# full configured depth and writes into _prefetch_result so turn 1
|
||||
# consumes the result directly.
|
||||
if self._recall_mode in ("context", "hybrid"):
|
||||
if self._recall_mode in {"context", "hybrid"}:
|
||||
try:
|
||||
self._manager.prefetch_context(self._session_key)
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ _profile_override: str | None = None
|
|||
def _host_key() -> str:
|
||||
"""Return the active Honcho host key, derived from the current Hermes profile."""
|
||||
if _profile_override:
|
||||
if _profile_override in ("default", "custom"):
|
||||
if _profile_override in {"default", "custom"}:
|
||||
return HOST
|
||||
return f"{HOST}.{_profile_override}"
|
||||
return resolve_active_host()
|
||||
|
|
@ -295,13 +295,13 @@ def _resolve_api_key(cfg: dict) -> str:
|
|||
parsed = urlparse(base_url)
|
||||
except (TypeError, ValueError):
|
||||
parsed = None
|
||||
if parsed and parsed.scheme in ("http", "https") and parsed.netloc:
|
||||
if parsed and parsed.scheme in {"http", "https"} and parsed.netloc:
|
||||
return "local"
|
||||
# Schemeless but looks like a host (contains '.' or ':' and isn't
|
||||
# a boolean literal): let it through so legacy configs don't
|
||||
# regress into "no API key configured" when they previously worked.
|
||||
lowered = base_url.lower()
|
||||
if lowered not in ("true", "false", "none", "null") and any(
|
||||
if lowered not in {"true", "false", "none", "null"} and any(
|
||||
c in base_url for c in ".:"
|
||||
) and not base_url.isdigit():
|
||||
return "local"
|
||||
|
|
@ -334,7 +334,7 @@ def _ensure_sdk_installed() -> bool:
|
|||
|
||||
print(" honcho-ai is not installed.")
|
||||
answer = _prompt("Install it now? (honcho-ai>=2.0.1)", default="y")
|
||||
if answer.lower() not in ("y", "yes"):
|
||||
if answer.lower() not in {"y", "yes"}:
|
||||
print(" Skipping install. Run: pip install 'honcho-ai>=2.0.1'\n")
|
||||
return False
|
||||
|
||||
|
|
@ -382,7 +382,7 @@ def cmd_setup(args) -> None:
|
|||
for h in ("localhost", "127.0.0.1", "::1")
|
||||
) else "cloud"
|
||||
deploy = _prompt("Cloud or local?", default=current_deploy)
|
||||
is_local = deploy.lower() in ("local", "l")
|
||||
is_local = deploy.lower() in {"local", "l"}
|
||||
|
||||
# Clean up legacy snake_case key
|
||||
cfg.pop("base_url", None)
|
||||
|
|
@ -441,7 +441,7 @@ def cmd_setup(args) -> None:
|
|||
print(" directional -- all observations on, each AI peer builds its own view (default)")
|
||||
print(" unified -- shared pool, user observes self, AI observes others only")
|
||||
new_obs = _prompt("Observation mode", default=current_obs)
|
||||
if new_obs in ("unified", "directional"):
|
||||
if new_obs in {"unified", "directional"}:
|
||||
hermes_host["observationMode"] = new_obs
|
||||
else:
|
||||
hermes_host["observationMode"] = "directional"
|
||||
|
|
@ -457,17 +457,17 @@ def cmd_setup(args) -> None:
|
|||
try:
|
||||
hermes_host["writeFrequency"] = int(new_wf)
|
||||
except (ValueError, TypeError):
|
||||
hermes_host["writeFrequency"] = new_wf if new_wf in ("async", "turn", "session") else "async"
|
||||
hermes_host["writeFrequency"] = new_wf if new_wf in {"async", "turn", "session"} else "async"
|
||||
|
||||
# --- 6. Recall mode ---
|
||||
_raw_recall = hermes_host.get("recallMode") or cfg.get("recallMode", "hybrid")
|
||||
current_recall = "hybrid" if _raw_recall not in ("hybrid", "context", "tools") else _raw_recall
|
||||
current_recall = "hybrid" if _raw_recall not in {"hybrid", "context", "tools"} else _raw_recall
|
||||
print("\n Recall mode:")
|
||||
print(" hybrid -- auto-injected context + Honcho tools available (default)")
|
||||
print(" context -- auto-injected context only, Honcho tools hidden")
|
||||
print(" tools -- Honcho tools only, no auto-injected context")
|
||||
new_recall = _prompt("Recall mode", default=current_recall)
|
||||
if new_recall in ("hybrid", "context", "tools"):
|
||||
if new_recall in {"hybrid", "context", "tools"}:
|
||||
hermes_host["recallMode"] = new_recall
|
||||
|
||||
# --- 7. Context token budget ---
|
||||
|
|
@ -477,7 +477,7 @@ def cmd_setup(args) -> None:
|
|||
print(" uncapped -- no limit (default)")
|
||||
print(" N -- token limit per turn (e.g. 1200)")
|
||||
new_ctx_tokens = _prompt("Context tokens", default=current_display)
|
||||
if new_ctx_tokens.strip().lower() in ("none", "uncapped", "no limit"):
|
||||
if new_ctx_tokens.strip().lower() in {"none", "uncapped", "no limit"}:
|
||||
hermes_host.pop("contextTokens", None)
|
||||
elif new_ctx_tokens.strip() == "":
|
||||
pass # keep current
|
||||
|
|
@ -517,7 +517,7 @@ def cmd_setup(args) -> None:
|
|||
print(" high -- complex behavioral patterns")
|
||||
print(" max -- thorough audit-level analysis")
|
||||
new_reasoning = _prompt("Reasoning level", default=current_reasoning)
|
||||
if new_reasoning in ("minimal", "low", "medium", "high", "max"):
|
||||
if new_reasoning in {"minimal", "low", "medium", "high", "max"}:
|
||||
hermes_host["dialecticReasoningLevel"] = new_reasoning
|
||||
else:
|
||||
hermes_host["dialecticReasoningLevel"] = "low"
|
||||
|
|
@ -530,7 +530,7 @@ def cmd_setup(args) -> None:
|
|||
print(" per-repo -- one session per git repository")
|
||||
print(" global -- single session across all directories")
|
||||
new_strat = _prompt("Session strategy", default=current_strat)
|
||||
if new_strat in ("per-session", "per-repo", "per-directory", "global"):
|
||||
if new_strat in {"per-session", "per-repo", "per-directory", "global"}:
|
||||
hermes_host["sessionStrategy"] = new_strat
|
||||
|
||||
hermes_host["enabled"] = True
|
||||
|
|
@ -1130,7 +1130,7 @@ def cmd_migrate(args) -> None:
|
|||
print(" Paste the key when prompted.")
|
||||
print()
|
||||
answer = _prompt(" Run 'hermes honcho setup' now?", default="y")
|
||||
if answer.lower() in ("y", "yes"):
|
||||
if answer.lower() in {"y", "yes"}:
|
||||
cmd_setup(args)
|
||||
cfg = _read_config()
|
||||
has_key = bool(cfg.get("apiKey", ""))
|
||||
|
|
@ -1176,7 +1176,7 @@ def cmd_migrate(args) -> None:
|
|||
print(" hermes honcho migrate — this step handles it interactively")
|
||||
if has_key:
|
||||
answer = _prompt(" Upload user memory files to Honcho now?", default="y")
|
||||
if answer.lower() in ("y", "yes"):
|
||||
if answer.lower() in {"y", "yes"}:
|
||||
try:
|
||||
from plugins.memory.honcho.client import (
|
||||
HonchoClientConfig,
|
||||
|
|
@ -1226,7 +1226,7 @@ def cmd_migrate(args) -> None:
|
|||
print()
|
||||
if has_key:
|
||||
answer = _prompt(" Seed AI identity from all detected files now?", default="y")
|
||||
if answer.lower() in ("y", "yes"):
|
||||
if answer.lower() in {"y", "yes"}:
|
||||
try:
|
||||
from plugins.memory.honcho.client import (
|
||||
HonchoClientConfig,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ def resolve_active_host() -> str:
|
|||
try:
|
||||
from hermes_cli.profiles import get_active_profile_name
|
||||
profile = get_active_profile_name()
|
||||
if profile and profile not in ("default", "custom"):
|
||||
if profile and profile not in {"default", "custom"}:
|
||||
return f"{HOST}.{profile}"
|
||||
except Exception:
|
||||
pass
|
||||
|
|
@ -653,7 +653,7 @@ class HonchoClientConfig:
|
|||
return base
|
||||
|
||||
# per-directory: one Honcho session per working directory (default)
|
||||
if self.session_strategy in ("per-directory", "per-session"):
|
||||
if self.session_strategy in {"per-directory", "per-session"}:
|
||||
base = Path(cwd).name
|
||||
if self.session_peer_prefix and self.peer_name:
|
||||
return f"{self.peer_name}-{base}"
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ def _is_windows_absolute_path(value: str) -> bool:
|
|||
len(value) >= 3
|
||||
and value[0].isalpha()
|
||||
and value[1] == ":"
|
||||
and value[2] in ("/", "\\")
|
||||
and value[2] in {"/", "\\"}
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -381,7 +381,7 @@ def _is_local_path_reference(value: str) -> bool:
|
|||
|
||||
def _path_from_file_uri(uri: str) -> Path | str:
|
||||
parsed = urlparse(uri)
|
||||
if parsed.netloc not in ("", "localhost"):
|
||||
if parsed.netloc not in {"", "localhost"}:
|
||||
return f"Unsupported non-local file URI: {uri}"
|
||||
return Path(url2pathname(parsed.path)).expanduser()
|
||||
|
||||
|
|
@ -755,7 +755,7 @@ class OpenVikingMemoryProvider(MemoryProvider):
|
|||
|
||||
level = args.get("level", "overview")
|
||||
|
||||
summary_level = level in ("abstract", "overview")
|
||||
summary_level = level in {"abstract", "overview"}
|
||||
# OpenViking expects directory URIs for pseudo summary files
|
||||
# (e.g. viking://user/hermes/.overview.md).
|
||||
resolved_uri = self._normalize_summary_uri(uri) if summary_level else uri
|
||||
|
|
@ -832,7 +832,7 @@ class OpenVikingMemoryProvider(MemoryProvider):
|
|||
result = self._unwrap_result(resp)
|
||||
|
||||
# Format list/tree results for readability
|
||||
if action in ("list", "tree"):
|
||||
if action in {"list", "tree"}:
|
||||
raw_entries = result
|
||||
if isinstance(result, dict):
|
||||
raw_entries = result.get("entries") or result.get("items") or result.get("children") or []
|
||||
|
|
@ -887,7 +887,7 @@ class OpenVikingMemoryProvider(MemoryProvider):
|
|||
|
||||
payload: Dict[str, Any] = {}
|
||||
for key in ("reason", "to", "parent", "instruction", "wait", "timeout"):
|
||||
if key in args and args[key] not in (None, ""):
|
||||
if key in args and args[key] not in {None, ""}:
|
||||
payload[key] = args[key]
|
||||
|
||||
parsed_url = urlparse(url)
|
||||
|
|
|
|||
|
|
@ -88,9 +88,9 @@ def _as_bool(value: Any, default: bool) -> bool:
|
|||
return value
|
||||
if isinstance(value, str):
|
||||
lowered = value.strip().lower()
|
||||
if lowered in ("true", "1", "yes", "y", "on"):
|
||||
if lowered in {"true", "1", "yes", "y", "on"}:
|
||||
return True
|
||||
if lowered in ("false", "0", "no", "n", "off"):
|
||||
if lowered in {"false", "0", "no", "n", "off"}:
|
||||
return False
|
||||
return default
|
||||
|
||||
|
|
@ -508,7 +508,7 @@ class SupermemoryMemoryProvider(MemoryProvider):
|
|||
self._allowed_containers = [self._container_tag] + list(self._custom_containers)
|
||||
|
||||
agent_context = kwargs.get("agent_context", "")
|
||||
self._write_enabled = agent_context not in ("cron", "flush", "subagent")
|
||||
self._write_enabled = agent_context not in {"cron", "flush", "subagent"}
|
||||
self._active = bool(self._api_key)
|
||||
self._client = None
|
||||
if self._active:
|
||||
|
|
@ -598,7 +598,7 @@ class SupermemoryMemoryProvider(MemoryProvider):
|
|||
cleaned = []
|
||||
for message in messages or []:
|
||||
role = message.get("role")
|
||||
if role not in ("user", "assistant"):
|
||||
if role not in {"user", "assistant"}:
|
||||
continue
|
||||
content = _clean_text_for_capture(str(message.get("content", "")))
|
||||
if content:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue