"""Per-run context — exposes the active run_id (and active Analysis) to code deep in the call stack without threading them through every signature. Set by the runtime; read by Analyses, Tools, and helper functions so they can publish trace events with the right associations. """ from __future__ import annotations from contextvars import ContextVar current_run_id: ContextVar[str | None] = ContextVar("nvi.current_run_id", default=None) # Name of the Analysis currently executing (e.g. "direct_answer"). Set by the # runtime in `_execute_node` before each Analysis runs, reset after. Used by # event factories to annotate tool/llm calls so the UI can group them. current_analysis: ContextVar[str | None] = ContextVar("nvi.current_analysis", default=None)