#!/usr/bin/env python3 """gstack-detach — run a long agent job (evals, benchmarks, syncs) robustly. Agent-launched long jobs on a shared dev box keep dying to environmental killers. This tool bakes in the fixes so gstack (and every gstack user) runs them properly: * SIGTERM-proof: fork + setsid puts the job in its OWN session, so the harness's "polite quit" SIGTERM to the launching process group can't reach it (observed: `script "test:gate" was terminated by signal SIGTERM`). * No idle-sleep death (macOS): wraps the command in `caffeinate -i`. * No cross-worktree API saturation: `--lock NAME` takes a machine-wide advisory lock so concurrent Conductor worktrees SERIALIZE their eval runs instead of saturating the shared model API (which mass-times-out E2E suites). * No shared-/tmp collision: a run-scoped log path by default (~/.gstack-dev/eval-runs/