Run a preflight before each fresh worker and put its facts in the worker's prompt
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import dataclasses
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
PREFLIGHT = pathlib.Path(__file__).resolve().parents[1] / "chunk-preflight"
|
||||
|
||||
|
||||
class Streaming(typing.Protocol):
|
||||
"""A started claude whose stream-json lines arrive as it works."""
|
||||
@@ -24,6 +27,8 @@ class Effects:
|
||||
local_time: typing.Callable[[float], str]
|
||||
now: typing.Callable[[], float]
|
||||
on_terminal: typing.Callable[[], bool]
|
||||
# Runs chunk-preflight in the given directory.
|
||||
preflight: typing.Callable[[str], subprocess.CompletedProcess[str]]
|
||||
python: typing.Callable[[list[str]], subprocess.CompletedProcess[str]]
|
||||
sleep: typing.Callable[[float], None]
|
||||
stream_claude: typing.Callable[[list[str], str, dict[str, str]], Streaming]
|
||||
@@ -51,6 +56,7 @@ def system_effects() -> Effects:
|
||||
local_time=lambda seconds: time.strftime("%Y-%m-%d %H:%M %Z", time.localtime(seconds)),
|
||||
now=time.time,
|
||||
on_terminal=lambda: sys.stdin.isatty() and sys.stdout.isatty(),
|
||||
preflight=lambda cwd: subprocess.run([sys.executable, str(PREFLIGHT)], capture_output=True, cwd=cwd, stdin=subprocess.DEVNULL, text=True),
|
||||
python=lambda args: subprocess.run([sys.executable, *args], capture_output=True, text=True),
|
||||
sleep=time.sleep,
|
||||
stream_claude=StreamingClaude,
|
||||
|
||||
Reference in New Issue
Block a user