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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970"""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 signalimport subprocessimport sysimport tempfile
import albedo_proc
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(sys.stdin.readline()) 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 = subprocess.Popen( command, shell=True, cwd=cwd, stdin=stdin, stdout=out, stderr=subprocess.STDOUT, start_new_session=True, ) group = albedo_proc.Group(process.pid, albedo_proc.leader_token(process.pid)) timed_out = False try: process.wait(TIMEOUT) except subprocess.TimeoutExpired: timed_out = True finally: albedo_proc.send_signal(group, signal.SIGKILL) process.wait() 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())