|
| 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()) |
0 commit comments