Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263"""Runs a child agent's verifier command in its own process group and exits 0when the command passes, or 1 with bounded failure detail on stdout."""
from __future__ import annotations
import jsonimport osimport subprocessimport tempfile
from albedo_helper_lifetime import Commands, read_request
OUTPUT_LIMIT = 8192EXCERPT_LIMIT = 4000TIMEOUT = 300.0
def tail_excerpt(text: str) -> str: stripped = text.strip() if len(stripped) <= EXCERPT_LIMIT: return stripped return "...\n" + stripped[-EXCERPT_LIMIT:]
def main() -> int: request = json.loads(read_request()) commands = Commands() command = str(request["command"]) cwd = request.get("cwd") cwd = cwd if isinstance(cwd, str) and os.path.isdir(cwd) else None with tempfile.TemporaryFile() as stdin, tempfile.TemporaryFile() as out: process = commands.start( command, cwd=cwd, stdin=stdin, stdout=out, stderr=subprocess.STDOUT, ) timed_out = False try: commands.wait(process, TIMEOUT) except subprocess.TimeoutExpired: timed_out = True finally: commands.finish(process) if timed_out: detail = f"verifier `{command}` timed out after {TIMEOUT:g}s" elif process.returncode == 0: return 0 else: detail = f"verifier `{command}` failed (exit {process.returncode})" end = out.seek(0, os.SEEK_END) out.seek(max(0, end - OUTPUT_LIMIT * 2)) excerpt = tail_excerpt(out.read(OUTPUT_LIMIT * 2).decode(errors="replace")) if excerpt: detail += f":\n{excerpt}" print(detail) return 1
if __name__ == "__main__": raise SystemExit(main())