"""
Profile runtime utilities - used by launch_camoufox and proxy_check.
"""

import os
import json


def load_config_from_stdin():
    """Load JSON config from stdin (for IPC from Node)."""
    return json.loads(sys.stdin.read())


def ensure_profile_dir(path: str) -> bool:
    """Ensure profile directory exists and is writable."""
    if not path or not os.path.isabs(path):
        return False
    try:
        os.makedirs(path, exist_ok=True)
        return os.access(path, os.W_OK)
    except OSError:
        return False
