#!/usr/bin/env python3
"""
run_tool.py — thin runner: load a JSON input file, call the vendored auditor
skill's SKILL.run(<tool>, <input>), print the result as one JSON line. This
computes NOTHING itself; a typed refusal is a valid decision (exit 0), same
convention as the native decision binaries. Infrastructure failures (bad argv,
unreadable/unparseable input file) exit non-zero.

usage: run_tool.py <tool_name> <input.json>
"""
import json
import os
import sys

_HERE = os.path.dirname(os.path.abspath(__file__))
if _HERE not in sys.path:
    sys.path.insert(0, _HERE)

from auditor import SKILL  # noqa: E402  (conformance-checks at import)


def main():
    if len(sys.argv) != 3:
        print("usage: run_tool.py <tool_name> <input.json>", file=sys.stderr)
        raise SystemExit(2)
    tool, path = sys.argv[1], sys.argv[2]
    try:
        with open(path, encoding="utf-8") as f:
            inp = json.load(f)
    except (OSError, json.JSONDecodeError) as e:
        print(f"run_tool.py: cannot read input JSON: {e}", file=sys.stderr)
        raise SystemExit(3)
    out = SKILL.run(tool, inp)
    print(json.dumps(out, sort_keys=True))


if __name__ == "__main__":
    main()
