#!/usr/bin/env python3
"""
HyperTwist IPC wrapper for cahidenes rubiks-cube-solver oracle.
Uses the kociemba package for solving (the original repo's vision module is unused here).

Input: 54-character facelet string (UBLFRD order)
Output: Space-separated WCA move notation
"""
import sys
import kociemba

def solve(facelets: str) -> str:
    """Solve a cube from a facelet string."""
    if len(facelets) != 54:
        print(f"ERROR: Facelet string must be 54 characters, got {len(facelets)}", file=sys.stderr)
        sys.exit(1)

    try:
        solution = kociemba.solve(facelets)
        return solution
    except Exception as e:
        print(f"ERROR: {e}", file=sys.stderr)
        sys.exit(1)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("ERROR: No facelet string provided", file=sys.stderr)
        sys.exit(1)

    facelets = sys.argv[1].strip()
    result = solve(facelets)
    print(result)
