Skip to content

Commit 10c113a

Browse files
Handle unset Hermes settings during integration
1 parent e6fa276 commit 10c113a

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

‎src/diogenes_dependency_integration.py‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,44 @@ def _shared_profiles() -> tuple[str, ...]:
279279
return tuple(profiles)
280280

281281

282-
def _mcp_servers(profile: str) -> dict[str, Any]:
283-
result = _hermes(profile, "config", "get", "mcp_servers", "--json")
282+
def _read_config_value(profile: str, key: str) -> Any:
283+
"""Read a Hermes value while treating an unset key as normal first-run state."""
284+
argv = _hermes_argv(profile, "config", "get", key, "--json")
285+
print(f"$ {_display_argv(argv)}", flush=True)
286+
result = subprocess.run(
287+
argv,
288+
env=_host_environment(),
289+
capture_output=True,
290+
text=True,
291+
timeout=120,
292+
check=False,
293+
)
294+
detail = (result.stderr or result.stdout).strip()
295+
if result.returncode:
296+
if "Config key not set:" in detail:
297+
print(f"Hermes {profile} {key}: not configured.")
298+
return None
299+
if result.stdout:
300+
print(result.stdout.rstrip())
301+
if result.stderr:
302+
print(result.stderr.rstrip(), file=sys.stderr)
303+
raise IntegrationError(
304+
f"{Path(argv[0]).name} exited with status {result.returncode}"
305+
)
306+
if result.stdout:
307+
print(result.stdout.rstrip())
308+
if result.stderr:
309+
print(result.stderr.rstrip(), file=sys.stderr)
284310
try:
285-
value = json.loads(result.stdout)
311+
return json.loads(result.stdout)
286312
except json.JSONDecodeError as exc:
287313
raise IntegrationError(
288-
f"Hermes returned invalid MCP configuration for {profile}"
314+
f"Hermes returned invalid configuration for {key}"
289315
) from exc
316+
317+
318+
def _mcp_servers(profile: str) -> dict[str, Any]:
319+
value = _read_config_value(profile, "mcp_servers")
290320
if value is None:
291321
return {}
292322
if not isinstance(value, dict):
@@ -639,11 +669,7 @@ def _ensure_context_plugin_files() -> None:
639669

640670

641671
def _config_value(profile: str, key: str) -> Any:
642-
result = _hermes(profile, "config", "get", key, "--json")
643-
try:
644-
return json.loads(result.stdout)
645-
except json.JSONDecodeError as exc:
646-
raise IntegrationError(f"Hermes returned invalid configuration for {key}") from exc
672+
return _read_config_value(profile, key)
647673

648674

649675
def _set_config_value(profile: str, key: str, value: Any) -> bool:

0 commit comments

Comments
 (0)