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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465"""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 = 8192TIMEOUT = 300.0
def tail_excerpt(text: str) -> str: stripped = text.strip() if len(stripped) <= 4000: return stripped return "...\n" + stripped[-4000:]
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) out.seek(0) raw = out.read(OUTPUT_LIMIT * 2).decode(errors="replace") excerpt = tail_excerpt(raw) if timed_out: detail = f"verifier `{command}` timed out after {TIMEOUT:g}s" if excerpt: detail += f":\n{excerpt}" print(detail) return 1 if process.returncode == 0: return 0 detail = f"verifier `{command}` failed (exit {process.returncode})" if excerpt: detail += f":\n{excerpt}" print(detail) return 1
if __name__ == "__main__": raise SystemExit(main())