"""JSON envelope helpers for consistent CLI output."""

import json
import sys


def success(data: dict) -> None:
    """Print a success JSON envelope and exit 0."""
    json.dump({"ok": True, "data": data}, sys.stdout, indent=2)
    sys.stdout.write("\n")


def error(msg: str, hint: str | None = None) -> None:
    """Print an error JSON envelope and exit 1."""
    out: dict = {"ok": False, "error": msg}
    if hint:
        out["hint"] = hint
    json.dump(out, sys.stdout, indent=2)
    sys.stdout.write("\n")
    sys.exit(1)
