"""执行结果与任务阶段上下文,不引入 HTTP、数据库或适配器。""" from __future__ import annotations from contextvars import ContextVar from dataclasses import dataclass from pathlib import Path from typing import Awaitable, Callable PhaseCallback = Callable[[str, str], Awaitable[None]] # ContextVar 按 asyncio 任务隔离;共享同一对象让媒体与 HTTP 阶段使用同一准入边界。 current_phase_callback: ContextVar[PhaseCallback | None] = ContextVar( "current_phase_callback", default=None ) async def enter_phase(phase_key: str, resource_pool: str) -> None: callback = current_phase_callback.get() if callback is not None: await callback(phase_key, resource_pool) @dataclass class CpuResult: outputs: list[Path] result: dict metadata: dict