Skip to content

Commit 7e5e037

Browse files
committed
Add gh-task dependency and loop mode
1 parent 57f7f7e commit 7e5e037

4 files changed

Lines changed: 58 additions & 20 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "codexapi"
7-
version = "0.5.12"
7+
version = "0.5.13"
88
description = "Minimal Python API for running the Codex CLI."
99
readme = "README.md"
1010
requires-python = ">=3.8"
@@ -17,6 +17,7 @@ classifiers = [
1717

1818
dependencies = [
1919
"PyYAML>=6.0",
20+
"gh-task",
2021
"tqdm>=4.64",
2122
]
2223

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PyYAML>=6.0
2+
tqdm>=4.64
3+
gh-task

src/codexapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
"task",
1616
"task_result",
1717
]
18-
__version__ = "0.5.12"
18+
__version__ = "0.5.13"

src/codexapi/cli.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77
import subprocess
88
import sys
9+
import time
910
import termios
1011
import tty
1112
from datetime import datetime
@@ -23,6 +24,7 @@
2324
_TAIL_BYTES = 256 * 1024
2425
_TAIL_MAX_BYTES = 4 * 1024 * 1024
2526
_TAIL_MIN_LINES = 200
27+
_PROJECT_LOOP_SLEEP = 30
2628
_ROLL_OUT_PREFIX = "rollout-"
2729
_SCIENCE_TEMPLATE = (
2830
"Good afternoon! We have a fun task today - take a good look around this repo "
@@ -1128,6 +1130,11 @@ def main(argv=None):
11281130
action="store_true",
11291131
help="Suppress progress output during verification.",
11301132
)
1133+
task_parser.add_argument(
1134+
"--loop",
1135+
action="store_true",
1136+
help="With -p, keep taking tasks and wait when none are available.",
1137+
)
11311138

11321139
ralph_parser = subparsers.add_parser(
11331140
"ralph",
@@ -1363,24 +1370,49 @@ def main(argv=None):
13631370
raise SystemExit("--name is required with --project.")
13641371
if not args.task_args:
13651372
raise SystemExit("task --project requires one or more task files.")
1366-
try:
1367-
from .gh_integration import GhTaskRunner
1368-
except ImportError as exc:
1369-
raise SystemExit("gh-task is required for --project. Install it with pip.") from exc
1370-
1371-
task_runner = GhTaskRunner(
1372-
args.project,
1373-
args.name,
1374-
args.task_args,
1375-
args.status,
1376-
args.cwd,
1377-
args.yolo,
1378-
args.flags,
1379-
)
1380-
result = task_runner(progress=not args.quiet)
1381-
if not result.success:
1382-
raise SystemExit(1)
1383-
return
1373+
from .gh_integration import GhTaskRunner
1374+
from gh_task.errors import TakeError
1375+
1376+
if args.loop:
1377+
while True:
1378+
try:
1379+
task_runner = GhTaskRunner(
1380+
args.project,
1381+
args.name,
1382+
args.task_args,
1383+
args.status,
1384+
args.cwd,
1385+
args.yolo,
1386+
args.flags,
1387+
)
1388+
except TakeError as exc:
1389+
print(str(exc), file=sys.stderr)
1390+
print(
1391+
f"Waiting {_PROJECT_LOOP_SLEEP}s for new tasks...",
1392+
file=sys.stderr,
1393+
)
1394+
time.sleep(_PROJECT_LOOP_SLEEP)
1395+
continue
1396+
result = task_runner(progress=not args.quiet)
1397+
if not result.success:
1398+
raise SystemExit(1)
1399+
else:
1400+
try:
1401+
task_runner = GhTaskRunner(
1402+
args.project,
1403+
args.name,
1404+
args.task_args,
1405+
args.status,
1406+
args.cwd,
1407+
args.yolo,
1408+
args.flags,
1409+
)
1410+
except TakeError as exc:
1411+
raise SystemExit(str(exc)) from None
1412+
result = task_runner(progress=not args.quiet)
1413+
if not result.success:
1414+
raise SystemExit(1)
1415+
return
13841416

13851417
if args.command == "task" and args.task_file:
13861418
if args.task_args:
@@ -1449,6 +1481,8 @@ def main(argv=None):
14491481
if args.command == "task":
14501482
if args.project:
14511483
raise SystemExit("task --project already handled earlier.")
1484+
if args.loop:
1485+
raise SystemExit("--loop is only supported with -p.")
14521486
if args.item is not None:
14531487
raise SystemExit("--item is only supported with -f.")
14541488
if args.max_iterations is None:

0 commit comments

Comments
 (0)