"""Minimal gateway proving the harness contract against rein-aharness. GLAS-WP-0001-T04: resolve a sand-boxer profile, request a sandbox, dispatch one rein-aharness task through the Rein contract, verify a commit landed, tear the sandbox down. This is the parity proof gating any later "retire rein-aharness as a standalone concern" conversation — it is not itself that conversation. Requires the `sandbox` extra (sand-boxer installed as a sibling editable dependency). """ from __future__ import annotations from typing import Any from sandboxer.core.manager import SandboxManager from sandboxer.models import Consumer, SandboxCreateRequest from glas_harness.contract import Rein, SandboxHandle, ToolCall from glas_harness.reins.rein_aharness import ReinAharness def run_task_through_rein( *, sandbox_profile: str, repo: str, title: str, description: str, rein: Rein | None = None, actor: str = "agt", project: str = "glas-harness", manager: SandboxManager | None = None, ) -> dict[str, Any]: """Resolve `sandbox_profile`, run one task inside it via `rein`, verify, tear down. Defaults to `ReinAharness` when no rein is supplied — the only implemented rein as of GLAS-WP-0001-T04. `rein-openweights` plugs in the same way once REIN-OW-WP-0001 lands. """ manager = manager or SandboxManager() rein = rein or ReinAharness() request = SandboxCreateRequest( profile=sandbox_profile, inputs={"repo": repo}, consumer=Consumer(actor=actor, project=project), ) status = manager.create(request) try: reachability = status.reachability.model_dump(mode="json") if status.reachability else {} sandbox = SandboxHandle( sandbox_id=status.sandbox_id, host=status.host or "", reachability=reachability ) session = rein.start_session( profile={"id": sandbox_profile}, inputs={"title": title, "description": description}, sandbox=sandbox, ) tool_result = rein.dispatch_tool(session, ToolCall(name="run_task", actor=actor)) summary = rein.end_session(session) return { "sandbox_id": status.sandbox_id, "tool_ok": tool_result.ok, "tool_output": tool_result.output, "tool_error": tool_result.error, "summary": summary, } finally: manager.destroy(status.sandbox_id)