"""Per-run context pressure ratio for guardrail / trace correlation (thread-local)."""

from __future__ import annotations

import contextvars

_pressure_ratio: contextvars.ContextVar[float | None] = contextvars.ContextVar(
    "mugi_agent_loop_pressure_ratio", default=None
)


def set_current_pressure_ratio(ratio: float | None) -> contextvars.Token:
    return _pressure_ratio.set(ratio)


def get_current_pressure_ratio() -> float | None:
    return _pressure_ratio.get()


def reset_pressure_ratio() -> None:
    _pressure_ratio.set(None)
