Download scripts/run_opencode.py from delqhi/frontend: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/delqhi/frontend/resolve/main/scripts/run_opencode.py
- Command line
-
hf download hf://spaces/delqhi/frontend/scripts/run_opencode.py
-
curl -L -o run_opencode.py https://huggingface.co/spaces/delqhi/frontend/resolve/main/scripts/run_opencode.py
1.7 kB
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import subprocess | |
| import sys | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description="Run opencode once via Python subprocess") | |
| parser.add_argument("--model", required=True) | |
| parser.add_argument("--agent", required=True) | |
| parser.add_argument("--cwd", required=False) | |
| parser.add_argument("--timeout-sec", type=int, default=600) | |
| parser.add_argument("--prompt", required=True) | |
| args = parser.parse_args() | |
| command = [ | |
| "opencode", | |
| "run", | |
| args.prompt, | |
| "--model", | |
| args.model, | |
| "--agent", | |
| args.agent, | |
| ] | |
| try: | |
| completed = subprocess.run( | |
| command, | |
| cwd=args.cwd or None, | |
| capture_output=True, | |
| text=True, | |
| timeout=max(1, int(args.timeout_sec)), | |
| check=False, | |
| ) | |
| payload = { | |
| "ok": completed.returncode == 0, | |
| "returncode": completed.returncode, | |
| "stdout": completed.stdout, | |
| "stderr": completed.stderr, | |
| "timeout": False, | |
| } | |
| except subprocess.TimeoutExpired as exc: | |
| payload = { | |
| "ok": False, | |
| "returncode": 124, | |
| "stdout": ( | |
| exc.stdout.decode() if isinstance(exc.stdout, bytes) else (exc.stdout or "") | |
| ), | |
| "stderr": ( | |
| exc.stderr.decode() if isinstance(exc.stderr, bytes) else (exc.stderr or "") | |
| ), | |
| "timeout": True, | |
| } | |
| sys.stdout.write(json.dumps(payload)) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |