Skip to content

Commit 582f835

Browse files
Apply Hermes skill policy through its native API
1 parent fc05165 commit 582f835

2 files changed

Lines changed: 88 additions & 7 deletions

File tree

‎scripts/hermes-skills-policy.py‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
"""Apply an exact disabled-skill set through Hermes' own configuration API."""
3+
4+
from __future__ import annotations
5+
6+
import argparse
7+
import json
8+
from pathlib import Path
9+
import sys
10+
11+
12+
def main() -> int:
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("--profile-home", type=Path, required=True)
15+
arguments = parser.parse_args()
16+
profile_home = arguments.profile_home.expanduser().resolve()
17+
if not profile_home.is_absolute():
18+
parser.error("--profile-home must be absolute")
19+
20+
try:
21+
payload = json.load(sys.stdin)
22+
except json.JSONDecodeError as exc:
23+
parser.error(f"stdin must contain a JSON array: {exc}")
24+
if not isinstance(payload, list) or any(
25+
not isinstance(value, str) or not value.strip()
26+
for value in payload
27+
):
28+
parser.error("stdin must contain a JSON array of non-empty skill names")
29+
expected = {value.strip() for value in payload}
30+
31+
from hermes_constants import (
32+
reset_hermes_home_override,
33+
set_hermes_home_override,
34+
)
35+
from hermes_cli.config import load_config
36+
from hermes_cli.skills_config import (
37+
get_disabled_skills,
38+
save_disabled_skills,
39+
)
40+
41+
token = set_hermes_home_override(str(profile_home))
42+
try:
43+
config = load_config()
44+
current = get_disabled_skills(config)
45+
if current != expected:
46+
save_disabled_skills(config, expected)
47+
retained = get_disabled_skills(load_config())
48+
finally:
49+
reset_hermes_home_override(token)
50+
if retained != expected:
51+
print("Hermes did not retain the disabled-skill policy", file=sys.stderr)
52+
return 1
53+
print(
54+
json.dumps(
55+
{
56+
"changed": current != expected,
57+
"disabled": len(retained),
58+
"profile_home": str(profile_home),
59+
},
60+
sort_keys=True,
61+
)
62+
)
63+
return 0
64+
65+
66+
if __name__ == "__main__":
67+
raise SystemExit(main())

‎src/diogenes_dependency_integration.py‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Reproduce Diogenes' verified Hermes integrations through native commands.
22
3-
Hermes owns its profiles, gateway, MCP registry, plugins, and skills. This
4-
module never serializes or writes ``config.yaml``. It observes configuration
5-
through ``hermes config get`` and applies changes through the public Hermes CLI
6-
or through the integration command shipped by the dependency itself.
3+
Hermes owns its profiles, gateway, MCP registry, plugins, and skills. This
4+
module never serializes or writes ``config.yaml``. It observes configuration
5+
through ``hermes config get`` and applies changes through the public Hermes CLI,
6+
Hermes' own skills configuration API, or the integration command shipped by
7+
the dependency itself.
78
"""
89

910
from __future__ import annotations
@@ -696,9 +697,22 @@ def _set_list_config_value(profile: str, key: str, values: list[str]) -> bool:
696697
if current == values:
697698
print(f"Hermes {profile} {key}: current. Nothing to do.")
698699
return False
699-
_hermes(profile, "config", "unset", key)
700-
for index, value in enumerate(values):
701-
_hermes(profile, "config", "set", f"{key}.{index}", value)
700+
if key != "skills.disabled":
701+
raise IntegrationError(f"unsupported Hermes list setting: {key}")
702+
python = DEFAULT_HERMES_HOME / "hermes-agent" / "venv" / "bin" / "python"
703+
helper = ROOT / "scripts" / "hermes-skills-policy.py"
704+
if not python.is_file() or not helper.is_file():
705+
raise IntegrationError("Hermes skills policy helper is unavailable")
706+
_run(
707+
[
708+
str(python),
709+
str(helper),
710+
"--profile-home",
711+
str(_profile_home(profile)),
712+
],
713+
input_text=json.dumps(values) + "\n",
714+
timeout=300,
715+
)
702716
retained = _config_value(profile, key)
703717
if retained != values:
704718
raise IntegrationError(f"Hermes did not retain {profile} {key}")

0 commit comments

Comments
 (0)