Keep configs in ~/.config/build-release/ and tool state in ~/.local/state/build-release/, under XDG_* where set #801
@@ -37,7 +37,7 @@ def chunk_facts(loop: Loop) -> str:
|
||||
item = item_of(loop.window.name)
|
||||
done = loop.effects.python([str(loop.launcher.with_name("chunk-preflight")), "--worktree", *([] if item is None else [ITEM, str(item)])], loop.root)
|
||||
facts = fresh_prompt.preflight_failed(done.stderr.strip() or f"it exited {done.returncode}") if done.returncode else fresh_prompt.preflight_facts(done.stdout.strip())
|
||||
held = held_beside(loop.window.name, loop.root, loop.paths, loop.env, loop.effects)
|
||||
held = held_beside(loop.window.name, loop.root, loop.paths, loop.effects)
|
||||
return facts + (fresh_prompt.held_by_others(held) if held else "")
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from plan.touches import overlaps, predicted, Touches
|
||||
from loop_state.paths import Paths
|
||||
from transcript_archive.project_key import project_key
|
||||
from release_plan.release_standing import project_plan
|
||||
from project_config.settings import ProjectConfig
|
||||
from claude_code.transcript import read_transcript
|
||||
from claude_code.session import Session, session_named, transcript_file
|
||||
from agent_cycle import tmux
|
||||
@@ -100,11 +101,8 @@ def clear_of(ours: Touches | Failure | None, theirs: list[Touches | Failure | No
|
||||
return not theirs or (isinstance(ours, dict) and all(isinstance(touches, dict) and not overlaps(ours, touches) for touches in theirs))
|
||||
|
||||
|
||||
def next_plan(root: str, home: pathlib.Path, env: typing.Mapping[str, str], effects: Effects) -> NextChunk | NoItem | Failure:
|
||||
"""The plan on the default branch, fetched now where origin answers, with its next item, as chunk-preflight reads it."""
|
||||
config = located(root, home, env)
|
||||
if isinstance(config, Failure):
|
||||
return config
|
||||
def next_plan(root: str, config: ProjectConfig, effects: Effects) -> NextChunk | NoItem | Failure:
|
||||
"""The plan config names, on the default branch of the checkout root, fetched now where origin answers, with its next item, as chunk-preflight reads it."""
|
||||
# A chunk that just merged left the plan on origin. A fetch that fails leaves the plan as last fetched, which chunk-preflight then reads too.
|
||||
effects.git("fetch", "--quiet", "origin", cwd=root, timeout=FETCH_TIMEOUT)
|
||||
ref = default_ref(root, FETCH_TIMEOUT, run=effects.git)
|
||||
@@ -121,13 +119,13 @@ def start_chunks(loop_run: LoopRun, leaving: bool, paths: Paths, env: typing.Map
|
||||
return config
|
||||
session = loop_session(loop_run.root, paths.home)
|
||||
handed = {name: value for name, value in env.items() if name.startswith(HANDED)}
|
||||
with starting(project_lock(loop_run.root, paths.home, env)) as unlocked:
|
||||
with starting(project_lock(loop_run.root, paths)) as unlocked:
|
||||
if unlocked:
|
||||
return unlocked
|
||||
windows = tmux.listed(session, effects.tmux)
|
||||
if refused := refusal(session, windows, loop_run.root, effects.tmux):
|
||||
return refused
|
||||
chunks = chunks_to_start(windows, loop_run, leaving, config.parallel_chunks, paths, env, effects)
|
||||
chunks = chunks_to_start(windows, loop_run, leaving, config, paths, effects)
|
||||
if isinstance(chunks, AwaitedMerges):
|
||||
return chunks
|
||||
for chunk in chunks:
|
||||
@@ -147,12 +145,12 @@ def refusal(session: str, windows: list[tmux.Listed], root: str, run: tmux.Tmux)
|
||||
return None
|
||||
|
||||
|
||||
def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool, limit: int, paths: Paths, env: typing.Mapping[str, str], effects: Effects) -> list[str] | AwaitedMerges:
|
||||
def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool, config: ProjectConfig, paths: Paths, effects: Effects) -> list[str] | AwaitedMerges:
|
||||
"""The chunks to start beside windows, the session's: the stopped ones room_of restarts, then those of the plan that may_start picks. A plan that cannot be read starts NO_ITEM, as a plan without an item does. AwaitedMerges where no chunk runs or restarts and every item left awaits a person's merge."""
|
||||
room = room_of(windows, loop_run.chunk, leaving, limit)
|
||||
room = room_of(windows, loop_run.chunk, leaving, config.parallel_chunks)
|
||||
if not room.left:
|
||||
return room.restart
|
||||
plan = next_plan(loop_run.root, paths.home, env, effects)
|
||||
plan = next_plan(loop_run.root, config, effects)
|
||||
if isinstance(plan, Failure):
|
||||
# Such as in a checkout without a default branch, where chunk-preflight fails too: the worker is told why and finds the facts itself.
|
||||
say(f"starting a chunk without a plan item, since the plan cannot be read: {plan.reason}", effects)
|
||||
@@ -164,14 +162,14 @@ def chunks_to_start(windows: list[tmux.Listed], loop_run: LoopRun, leaving: bool
|
||||
return room.restart + [chunk for chunk in picked if chunk not in room.stopped]
|
||||
|
||||
|
||||
def held_beside(chunk: str, root: str, paths: Paths, env: typing.Mapping[str, str], effects: Effects) -> list[int]:
|
||||
def held_beside(chunk: str, root: str, paths: Paths, effects: Effects) -> list[int]:
|
||||
"""The plan items that the project's other chunks hold now, running or stopped, which a chunk starting as `chunk` leaves to them. It waits for a loop that is starting windows, so chunks started together see each other. Where the lock cannot be taken, it reads the windows without it."""
|
||||
wait_for_starts(root, paths.home, env)
|
||||
wait_for_starts(root, paths)
|
||||
others = [window.name for window in tmux.listed(loop_session(root, paths.home), effects.tmux) if window.name != chunk]
|
||||
return sorted(held_items(others, project_key(root, paths.home), paths.claude_code_transcripts))
|
||||
|
||||
|
||||
def wait_for_starts(root: str, home: pathlib.Path, env: typing.Mapping[str, str]) -> None:
|
||||
def wait_for_starts(root: str, paths: Paths) -> None:
|
||||
"""Returns once no loop of the project is starting windows: start_chunks holds the lock file `claims.LOCK` names while it starts them. Where the lock cannot be taken, it returns at once."""
|
||||
with starting(project_lock(root, home, env)):
|
||||
with starting(project_lock(root, paths)):
|
||||
pass
|
||||
|
||||
@@ -15,6 +15,7 @@ from release_plan.release_standing import DefaultPlan, LastCut, UNSEEN_RELEASES
|
||||
from failure import Failure
|
||||
from loop_effects.doubles import FakeEffects, ran, STAMP
|
||||
from build_release.chunk import fresh_prompt
|
||||
from project_config.main import located
|
||||
from build_release.doubles import NO_CUT, TODO
|
||||
from loop_state import paths
|
||||
from plan_store.todo_md import plan_of
|
||||
@@ -100,9 +101,11 @@ class RouteSources(unittest.TestCase):
|
||||
self.assertEqual([(item.id, item.awaits_merge) for item in held.plan.items], [(7, ""), (3, "#12 https://github.com/o/r/pull/12"), (1, "")])
|
||||
self.assertEqual(fake.made("forge")[0][:4], [root, "gh", "pr", "list"])
|
||||
self.assertIsNone(chunk_start.plan_item(held, None, fake.effects()), "items 7 and 3 wait, so no item of the next release routes the chunk")
|
||||
window = chunk_windows.next_plan(root, folder.parents[2], {}, dataclasses.replace(fake.effects(), git=git))
|
||||
config = located(root, folder.parents[2], {})
|
||||
assert not isinstance(config, Failure), config
|
||||
window = chunk_windows.next_plan(root, config, dataclasses.replace(fake.effects(), git=git))
|
||||
self.assertEqual((window.awaits_merge, fake.made("forge")[1][:4]), (True, [root, "gh", "pr", "list"]), "a window starts by the same pick")
|
||||
stopped = chunk_windows.chunks_to_start([], reload.LoopRun(1, root, "do it", ""), False, 1, paths.paths_from(folder.parents[2], {}), {}, dataclasses.replace(fake.effects(), git=git))
|
||||
stopped = chunk_windows.chunks_to_start([], reload.LoopRun(1, root, "do it", ""), False, config, paths.paths_from(folder.parents[2], {}), dataclasses.replace(fake.effects(), git=git))
|
||||
self.assertEqual(stopped, chunk_windows.AwaitedMerges(window.why), "so the loop starts no chunk, and says which pull requests it waits on")
|
||||
|
||||
def test_reads_a_plan_outside_the_checkout_as_it_stands_and_stops_without_a_config(self):
|
||||
|
||||
@@ -106,7 +106,7 @@ class ChunkWindows(unittest.TestCase):
|
||||
(folder / f"{chunk_windows.chunk_session('r', 'item-8', held.claude_code_transcripts).id}.jsonl").write_text("".join(json.dumps(line) + "\n" for line in lines))
|
||||
# Its own window, item-7, holds nothing for it; item-9's stopped chunk holds its item.
|
||||
fake = FakeEffects(windows="item-7\t0\t@1\nitem-8 ?\t0\t@2\nitem-9\t1\t@3\nitem-10\t0\t@4\n")
|
||||
self.assertEqual(chunk_windows.held_beside("item-7", "/r", held, {}, fake.effects()), [8, 9, 10, 11])
|
||||
self.assertEqual(chunk_windows.held_beside("item-7", "/r", held, fake.effects()), [8, 9, 10, 11])
|
||||
self.assertEqual(fake.tmux_calls, [["list-windows", "-t", "=loop-r", "-F", "#{window_name}\t#{pane_dead}\t#{window_id}"]])
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ class StartChunks(unittest.TestCase):
|
||||
(self.home / ".local" / "state" / "build-release").mkdir(parents=True, exist_ok=True)
|
||||
(self.home / ".local" / "state" / "build-release" / "claims").write_text("")
|
||||
fake = FakeEffects(windows="item-7\t0\t@1\nitem-9\t1\t@3\n")
|
||||
self.assertEqual(chunk_windows.held_beside("item-7", str(self.root), paths.paths_from(self.home, {}), {}, fake.effects()), [9])
|
||||
self.assertEqual(chunk_windows.held_beside("item-7", str(self.root), paths.paths_from(self.home, {}), fake.effects()), [9])
|
||||
|
||||
def test_a_chunk_holds_its_own_item_and_those_on_its_latest_chunk_items_line(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
|
||||
@@ -4,13 +4,12 @@ An entry point holds `starting` on `project_lock` while it lists the windows of
|
||||
"""
|
||||
import contextlib
|
||||
import fcntl
|
||||
from collections.abc import Mapping
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from failure import Failure
|
||||
from loop_state.paths import Paths
|
||||
from transcript_archive.project_key import project_key
|
||||
from loop_state.paths import state_folder
|
||||
from agent_cycle import tmux
|
||||
|
||||
# The file an entry point keeps locked with flock while it lists the windows of a project's chunks and starts new ones. Two loops whose chunks finish together then don't start a chunk twice, and do-epic, which holds the same lock, never starts a chunk in a checkout while build-release does.
|
||||
@@ -51,9 +50,9 @@ def claims_folder(state: pathlib.Path) -> pathlib.Path:
|
||||
return state / "claims"
|
||||
|
||||
|
||||
def project_lock(root: str, home: pathlib.Path, env: Mapping[str, str]) -> pathlib.Path:
|
||||
def project_lock(root: str, paths: Paths) -> pathlib.Path:
|
||||
"""The folder of the LOCK that everything starting a chunk in the checkout root holds."""
|
||||
return claims_folder(state_folder(env, home)) / project_key(root, home)
|
||||
return claims_folder(paths.state_folder) / project_key(root, paths.home)
|
||||
|
||||
|
||||
def loop_session(root: str, home: pathlib.Path) -> str:
|
||||
|
||||
@@ -36,6 +36,10 @@ class EpicRun:
|
||||
def session(self) -> str:
|
||||
return tmux.session_name(tmux.EPIC, self.key)
|
||||
|
||||
@property
|
||||
def folder(self) -> pathlib.Path:
|
||||
return scheduler.epic_folder(self.paths.state_folder, self.key)
|
||||
|
||||
|
||||
def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None, told: str = "") -> scheduler.Started | Failure:
|
||||
"""scheduler.start_chunks on the epic's issues, as read, in order of score, and its cap, read afresh; own is the issue of the chunk that asks, and told is the reason the planning just gave for stopping, which isn't said twice. Where no issue is open, the chunk to start is the epic's finishing, unless the epic is closed."""
|
||||
@@ -57,7 +61,7 @@ def chunks_started(epic: EpicRun, issues: list[EpicIssue], own: str | None, told
|
||||
|
||||
def planned_epic(epic: EpicRun) -> planning.Planned:
|
||||
"""The epic as planning reads and writes it."""
|
||||
return planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.env, epic.effects)
|
||||
return planning.Planned(epic.key, epic.config, epic.store, epic.record, epic.paths.home, epic.env, epic.folder, epic.effects)
|
||||
|
||||
|
||||
def scheduled_epic(epic: EpicRun, order: tuple[str, ...]) -> scheduler.Epic | Failure:
|
||||
@@ -75,7 +79,7 @@ def scheduled_epic(epic: EpicRun, order: tuple[str, ...]) -> scheduler.Epic | Fa
|
||||
seen.append(found.checkout)
|
||||
return real(found.checkout), found.config.parallel_chunks
|
||||
|
||||
return scheduler.Epic(epic.key, cap, located, epic.paths.home, epic.launcher, epic.env, epic.config.label_repos, order, epic.config.unblocking)
|
||||
return scheduler.Epic(epic.key, cap, located, epic.paths, epic.launcher, epic.env, epic.config.label_repos, order, epic.config.unblocking)
|
||||
|
||||
|
||||
def real(checkout: pathlib.Path) -> pathlib.Path:
|
||||
|
||||
+2
-2
@@ -144,7 +144,7 @@ def status_printed(epic: EpicRun) -> Stop:
|
||||
reading = dataclasses.replace(epic, effects=dataclasses.replace(epic.effects, git=dry_run.without_clones(epic.effects.git)))
|
||||
order = issues if isinstance(issues, Failure) else planning.start_order(planned_epic(reading), issues)
|
||||
# Where the issues cannot be put in order of score, they start in the backlog's order, as a run says.
|
||||
lines = issues if isinstance(issues, Failure) else status.lines(epic.key, epic.paths.state_folder, issues, epic.config.label_repos, epic.config.unblocking, epic.effects.tmux, () if isinstance(order, Failure) else tuple(order))
|
||||
lines = issues if isinstance(issues, Failure) else status.lines(epic.key, epic.folder, issues, epic.config.label_repos, epic.config.unblocking, epic.effects.tmux, () if isinstance(order, Failure) else tuple(order))
|
||||
return Stop(1, lines.reason) if isinstance(lines, Failure) else Stop(0, "\n".join(lines) or f"the epic {epic.key} has no open issue")
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ def chunk_root(key: str, issue: EpicIssue | None, epic: EpicRun) -> tuple[str, s
|
||||
if isinstance(pick, Failure):
|
||||
return Stop(1, pick.reason)
|
||||
if isinstance(pick, ClaudeWork):
|
||||
return str(scheduler.epic_folder(epic.paths.state_folder, epic.key)), None
|
||||
return str(epic.folder), None
|
||||
if not isinstance(pick, Repo):
|
||||
return Stop(1, f"{key} is no chunk: no label names its repo")
|
||||
found = locate(pick.name, [], epic.config, epic.paths.home, epic.env, epic.effects.git)
|
||||
|
||||
@@ -30,15 +30,15 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None, finis
|
||||
|
||||
A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again.
|
||||
"""
|
||||
key, folder = loop.window.name, scheduler.epic_folder(epic.paths.state_folder, epic.key)
|
||||
recorded_as = parked.parked_chunks(folder)
|
||||
key = loop.window.name
|
||||
recorded_as = parked.parked_chunks(epic.folder)
|
||||
if isinstance(recorded_as, Failure):
|
||||
return Stop(1, recorded_as.reason)
|
||||
config = config_located(loop.root, epic.paths.home, epic.env)
|
||||
if isinstance(config, Failure):
|
||||
return Stop(1, config.reason)
|
||||
# A pull request into an epic's working branch merges without a person, whatever `merge` says. The base recorded says so, not the config: the gate fails where the forge merges the pull request elsewhere.
|
||||
poll = Poll(key, repo, config.merge == "human" and based is None, folder, loop, epic)
|
||||
poll = Poll(key, repo, config.merge == "human" and based is None, epic.folder, loop, epic)
|
||||
if key in recorded_as:
|
||||
return resumed_news(poll, recorded_as[key].on, shown=None)
|
||||
entered = None if told is None else poll.first_gate(again=finished)
|
||||
|
||||
@@ -10,10 +10,9 @@ from collections.abc import Mapping
|
||||
import pathlib
|
||||
import re
|
||||
|
||||
from loop_state.paths import CLAUDE_HOME, state_folder
|
||||
from loop_state.paths import CLAUDE_HOME
|
||||
from do_epic.config import DoEpicConfig
|
||||
from loop_effects.effects import Effects, say
|
||||
from do_epic.scheduler import epic_folder, unblocks
|
||||
from do_epic.backend.protocol import EpicIssue, EpicStore, no_scores
|
||||
from do_epic.epic_record import EpicRecord
|
||||
from failure import Failure
|
||||
@@ -24,6 +23,7 @@ from claude_code.reply import Limited
|
||||
from plan_store.jira_epic import number
|
||||
from model_routing.ladder_file import read_ladder, SHIPPED
|
||||
from model_routing.ladder import Rung
|
||||
from do_epic.scheduler import unblocks
|
||||
from plan_store.scoring import weighing_texts
|
||||
|
||||
# The epic's formula, stated under its `## Scoring` as a todo.md states its own.
|
||||
@@ -43,6 +43,8 @@ class Planned:
|
||||
record: EpicRecord
|
||||
home: pathlib.Path
|
||||
env: Mapping[str, str]
|
||||
# The epic's folder, where claude plans and scores its issues.
|
||||
folder: pathlib.Path
|
||||
effects: Effects
|
||||
|
||||
|
||||
@@ -94,17 +96,16 @@ def placed(epic: Planned, issues: list[EpicIssue], unplaced: list[EpicIssue], ad
|
||||
if failed := next((each for each in (rung, language, places) if isinstance(each, Failure)), None):
|
||||
return failed
|
||||
assert isinstance(rung, Rung) and not isinstance(language, Failure) and isinstance(places, dict)
|
||||
folder = epic_folder(state_folder(epic.env, epic.home), epic.key)
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
epic.folder.mkdir(parents=True, exist_ok=True)
|
||||
checkouts = tuple(str(place.checkout) for place in places.values())
|
||||
for issue in unplaced:
|
||||
say(f"planning {issue.key}", epic.effects, stdout=True)
|
||||
parts = split.split(epic.store, issue, epic.config.label_repos, not issue.by_loop, epic.config.repo_rule, language or epic.config.language, checkouts, rung, epic.effects.claude, str(folder), epic.config.sub_task_summary)
|
||||
parts = split.split(epic.store, issue, epic.config.label_repos, not issue.by_loop, epic.config.repo_rule, language or epic.config.language, checkouts, rung, epic.effects.claude, str(epic.folder), epic.config.sub_task_summary)
|
||||
if isinstance(parts, split.Split) and parts.repos:
|
||||
added[issue.key] = split.SPLIT_LABEL
|
||||
say(f"{issue.key} is split into a sub-task for each of {', '.join(parts.repos)}", epic.effects, stdout=True)
|
||||
continue
|
||||
pick: repo_pick.Pick | repo_pick.Unclear | Failure | Limited | None = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.label_repos, epic.config.repo_rule, rung, epic.effects.claude, str(folder))
|
||||
pick: repo_pick.Pick | repo_pick.Unclear | Failure | Limited | None = parts if not isinstance(parts, split.Split) else repo_pick.picked(epic.store, issue, epic.config.label_repos, epic.config.repo_rule, rung, epic.effects.claude, str(epic.folder))
|
||||
if isinstance(pick, repo_pick.Unclear):
|
||||
pick = answered(epic, issue, pick.question)
|
||||
if isinstance(pick, Limited):
|
||||
@@ -212,13 +213,12 @@ def scored(epic: Planned, issues: list[EpicIssue]) -> tuple[list[EpicIssue], Fai
|
||||
if failed := next((each for each in (rung, language, rule, weighed) if isinstance(each, Failure)), None):
|
||||
return issues, failed
|
||||
assert isinstance(rung, Rung) and not isinstance(language, Failure) and isinstance(rule, str) and isinstance(weighed, Weighing)
|
||||
folder = epic_folder(state_folder(epic.env, epic.home), epic.key)
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
epic.folder.mkdir(parents=True, exist_ok=True)
|
||||
for issue in bare:
|
||||
say(f"scoring {issue.key}", epic.effects, stdout=True)
|
||||
repo = repo_of(epic, issue)
|
||||
goals = ranking.goals_named(weighed.goals, repo, weighed.repos.get(repo) if repo else None)
|
||||
answer = goals if isinstance(goals, Failure) else issue_scores.asked(issue, rule, goals, language or epic.config.language, rung, epic.effects.claude, str(folder))
|
||||
answer = goals if isinstance(goals, Failure) else issue_scores.asked(issue, rule, goals, language or epic.config.language, rung, epic.effects.claude, str(epic.folder))
|
||||
if isinstance(answer, Limited):
|
||||
return issues, answer
|
||||
held = answer if isinstance(answer, Failure) else scores_set(epic, issue, answer, weighed)
|
||||
|
||||
@@ -15,18 +15,18 @@ from text_files.markdown_text import listed
|
||||
from project_config.settings import PARALLEL_CHUNKS
|
||||
from do_epic.parked import parked_chunks
|
||||
from chunk_pr.approval import PARKS
|
||||
from loop_state.paths import state_folder
|
||||
from loop_state.paths import Paths
|
||||
from agent_cycle import tmux
|
||||
|
||||
# The folder in the state folder where a folder per epic key holds the epic's lock file, which `claims.LOCK` names. A chunk without a repo works there.
|
||||
STATE = "do-epic"
|
||||
# Why a human's task with a live window waits, as the epic's status says.
|
||||
HUMAN_WAIT = "it is a human's task; do-epic polls Jira until you close it"
|
||||
|
||||
|
||||
def epic_folder(state: pathlib.Path, key: str) -> pathlib.Path:
|
||||
"""The folder of the epic called key, in the state folder state."""
|
||||
return state / STATE / key
|
||||
# Why a human's task with a live window waits, as the epic's status says.
|
||||
HUMAN_WAIT = "it is a human's task; do-epic polls Jira until you close it"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -74,7 +74,7 @@ class Epic:
|
||||
cap: int
|
||||
# The checkout of the repo with this name and its `parallel-chunks`, or why the repo cannot be used.
|
||||
locate: typing.Callable[[str], tuple[pathlib.Path, int] | Failure]
|
||||
home: pathlib.Path
|
||||
paths: Paths
|
||||
# The do-epic script each window runs.
|
||||
launcher: pathlib.Path
|
||||
env: typing.Mapping[str, str]
|
||||
@@ -87,7 +87,7 @@ class Epic:
|
||||
|
||||
@property
|
||||
def folder(self) -> pathlib.Path:
|
||||
return epic_folder(state_folder(self.env, self.home), self.key)
|
||||
return epic_folder(self.paths.state_folder, self.key)
|
||||
|
||||
|
||||
def unblocks(status: str, unblocking: tuple[str, ...]) -> bool:
|
||||
@@ -233,10 +233,10 @@ def start_chunk(epic: Epic, chunk: Chunk, own: str | None, windows: list[tmux.Li
|
||||
if isinstance(located, Failure):
|
||||
return Waits(chunk.issue, located.reason)
|
||||
checkout, limit = located
|
||||
with starting(project_lock(str(checkout), epic.home, epic.env)) as unlocked:
|
||||
with starting(project_lock(str(checkout), epic.paths)) as unlocked:
|
||||
if unlocked:
|
||||
return unlocked
|
||||
if reason := refusal(chunk.repo, room_in(str(checkout), limit, (session, own), epic.home, run)):
|
||||
if reason := refusal(chunk.repo, room_in(str(checkout), limit, (session, own), epic.paths.home, run)):
|
||||
return Waits(chunk.issue, reason)
|
||||
return tmux.start_chunk(tmux.Window(session, chunk.issue, ""), str(checkout), handed, command, windows, False, run)
|
||||
|
||||
@@ -259,10 +259,10 @@ def resume(epic: Epic, repo: str, window: tmux.Window, run: tmux.Tmux) -> str |
|
||||
if isinstance(located, Failure):
|
||||
return located.reason
|
||||
checkout, limit = located
|
||||
with starting(project_lock(str(checkout), epic.home, epic.env)) as unlocked:
|
||||
with starting(project_lock(str(checkout), epic.paths)) as unlocked:
|
||||
if unlocked:
|
||||
return unlocked.reason
|
||||
if reason := refusal(repo, room_in(str(checkout), limit, (window.session, window.name), epic.home, run)):
|
||||
if reason := refusal(repo, room_in(str(checkout), limit, (window.session, window.name), epic.paths.home, run)):
|
||||
return reason
|
||||
tmux.unpark(window, str(checkout), run)
|
||||
return None
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import datetime
|
||||
import pathlib
|
||||
|
||||
from do_epic.scheduler import chunks, epic_folder, HUMAN_WAIT
|
||||
from do_epic.scheduler import chunks, HUMAN_WAIT
|
||||
from do_epic.backend.protocol import EpicIssue
|
||||
from failure import Failure
|
||||
from do_epic.parked import file_of, Parked, parked_chunks, SLOT
|
||||
@@ -20,10 +20,9 @@ def since(folder: pathlib.Path, chunk: Parked) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def lines(key: str, state: pathlib.Path, issues: list[EpicIssue], team: LabelRepos, unblocking: tuple[str, ...], run: tmux.Tmux, order: tuple[str, ...]) -> list[str] | Failure:
|
||||
def lines(key: str, folder: pathlib.Path, issues: list[EpicIssue], team: LabelRepos, unblocking: tuple[str, ...], run: tmux.Tmux, order: tuple[str, ...]) -> list[str] | Failure:
|
||||
"""A line per open issue of the epic called key, in the tracker's rank order: that its chunk runs or asks the human, or why it waits. order holds the keys of the issues that start by score, as planning.start_order puts them; a chunk it leaves out says that it starts after them. It doesn't start anything or check any limit, so the line of a chunk that has yet to start doesn't say which limit holds it back."""
|
||||
found, waits = chunks(issues, team, unblocking)
|
||||
folder = epic_folder(state, key)
|
||||
parked = parked_chunks(folder)
|
||||
if isinstance(parked, Failure):
|
||||
return parked
|
||||
|
||||
@@ -36,12 +36,16 @@ def scored(key: str, moves: str, *labels: str, blockers: tuple[str, ...] = (), b
|
||||
|
||||
|
||||
class Planning(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
self.folder = self.home / ".local/state/build-release/do-epic/ABC-12"
|
||||
|
||||
def plan(self, fake: FakeEffects) -> tuple[list[EpicIssue] | Failure | Limited, MemoryEpic, str]:
|
||||
"""What planning answers for self.issues, the store it changed and what it printed on stdout. self.asked holds what it asked the human, on stderr."""
|
||||
config = load(self.home, {})
|
||||
assert not isinstance(config, Failure), config
|
||||
store = MemoryEpic("ABC-12", list(self.issues))
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, {}, fake.effects()) # type: ignore[arg-type]
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, {}, self.folder, fake.effects()) # type: ignore[arg-type]
|
||||
out, self.asked = io.StringIO(), io.StringIO()
|
||||
with contextlib.redirect_stdout(out), contextlib.redirect_stderr(self.asked):
|
||||
read = store.read()
|
||||
@@ -152,11 +156,10 @@ class Planning(DoEpicTest):
|
||||
folders.append(cwd)
|
||||
return effects.claude(args, cwd, stdin) # type: ignore[arg-type]
|
||||
config = load(self.home, {})
|
||||
epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description("")), self.home, {}, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type]
|
||||
epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description("")), self.home, {}, self.folder, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type]
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
planning.planned(epic, list(self.issues))
|
||||
folder = self.home / ".local" / "state" / "build-release" / "do-epic" / "ABC-12"
|
||||
self.assertEqual((folders, folder.is_dir()), ([str(folder)] * 2, True))
|
||||
self.assertEqual((folders, self.folder.is_dir()), ([str(self.folder)] * 2, True))
|
||||
|
||||
def test_a_model_off_the_routing_ladder_has_no_rung(self) -> None:
|
||||
found = planning.planning_rung("claude-nope-1")
|
||||
@@ -379,7 +382,7 @@ class Planning(DoEpicTest):
|
||||
self.description = RANKED
|
||||
self.issues = [scored("ABC-20", "epic 1 by 2", "do-epic-claude", by_loop=False), issue("ABC-21", "do-epic-claude")]
|
||||
# An earlier run made the folder the scoring runs in.
|
||||
(self.home / ".local/state/build-release/do-epic/ABC-12").mkdir(parents=True, exist_ok=True)
|
||||
self.folder.mkdir(parents=True, exist_ok=True)
|
||||
fake = FakeEffects(claude=[says(ANSWER)])
|
||||
found, store, out = self.plan(fake)
|
||||
assert not isinstance(found, Failure | Limited), found
|
||||
@@ -447,10 +450,10 @@ class Planning(DoEpicTest):
|
||||
folders.append(cwd)
|
||||
return effects.claude(args, cwd, stdin) # type: ignore[arg-type]
|
||||
config = load(self.home, {})
|
||||
epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description(RANKED)), self.home, {}, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type]
|
||||
epic = planning.Planned("ABC-12", config, MemoryEpic("ABC-12", list(self.issues)), EpicRecord(Description(RANKED)), self.home, {}, self.folder, dataclasses.replace(effects, claude=claude)) # type: ignore[arg-type]
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
planning.planned(epic, list(self.issues))
|
||||
self.assertEqual(folders, [str(self.home / ".local" / "state" / "build-release" / "do-epic" / "ABC-12")] * 2)
|
||||
self.assertEqual(folders, [str(self.folder)] * 2)
|
||||
|
||||
self.rule()
|
||||
self.description = RANKED
|
||||
@@ -469,7 +472,7 @@ class Planning(DoEpicTest):
|
||||
out = io.StringIO()
|
||||
config = load(self.home, {})
|
||||
assert not isinstance(config, Failure), config
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, {}, FakeEffects(claude=[says(ANSWER)]).effects()) # type: ignore[arg-type]
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, {}, self.folder, FakeEffects(claude=[says(ANSWER)]).effects()) # type: ignore[arg-type]
|
||||
with contextlib.redirect_stdout(out):
|
||||
found, stopped = planning.scored(epic, list(self.issues))
|
||||
self.assertEqual((found, stopped, out.getvalue()), (self.issues, None, "<1790000000> scoring ABC-20\n<1790000000> ABC-20 is not scored: Jira answered 503\n"))
|
||||
@@ -520,7 +523,7 @@ class Planning(DoEpicTest):
|
||||
"""What planning answers for self.issues on a store that doesn't read as MemoryEpic does."""
|
||||
config = load(self.home, {})
|
||||
assert not isinstance(config, Failure), config
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, {}, fake.effects()) # type: ignore[arg-type]
|
||||
epic = planning.Planned("ABC-12", config, store, EpicRecord(Description(self.description)), self.home, {}, self.folder, fake.effects()) # type: ignore[arg-type]
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
return planning.planned(epic, list(self.issues))
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from do_epic.backend.protocol import EpicIssue
|
||||
from failure import Failure
|
||||
from do_epic.parked import file_of, park, Parked
|
||||
from do_epic.epic_record import parallel_chunks_in
|
||||
from loop_state.paths import paths_from
|
||||
from chunk_driver import prompts
|
||||
from model_routing.route import Route
|
||||
from model_routing.ladder import Rung
|
||||
@@ -210,7 +211,7 @@ class StartingAnEpicsChunks(unittest.TestCase):
|
||||
"""An epic whose repos are checked out under the home folder, each with its `parallel-chunks`."""
|
||||
def locate(name: str) -> tuple[pathlib.Path, int] | Failure:
|
||||
return (self.home / "code" / name, limits[name]) if name in limits else Failure(f"no project config names {name}")
|
||||
return Epic("ABC-12", cap, locate, self.home, pathlib.Path("/bin/do-epic"), {"BUILD_RELEASE_X": "1", "OTHER": "2"}, {}, self.order)
|
||||
return Epic("ABC-12", cap, locate, paths_from(self.home, {}), pathlib.Path("/bin/do-epic"), {"BUILD_RELEASE_X": "1", "OTHER": "2"}, {}, self.order)
|
||||
|
||||
def start(self, epic: Epic, issues: list[EpicIssue], run: Tmux, own: str | None = None) -> Started:
|
||||
found = start_chunks(epic, issues, False, own, run)
|
||||
|
||||
@@ -7,7 +7,6 @@ import unittest
|
||||
from failure import Failure
|
||||
from do_epic.test_scheduler import issue, Tmux
|
||||
from do_epic import parked, status
|
||||
from do_epic.scheduler import STATE
|
||||
|
||||
SINCE = 1_700_000_000
|
||||
# SINCE as the status prints it.
|
||||
@@ -17,15 +16,14 @@ EPIC = "epic-ABC-12"
|
||||
|
||||
class TheStatusLines(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.home = pathlib.Path(tempfile.mkdtemp())
|
||||
self.folder = self.home / STATE / "ABC-12"
|
||||
self.folder = pathlib.Path(tempfile.mkdtemp())
|
||||
|
||||
def park(self, key: str, on: str) -> None:
|
||||
parked.park(self.folder, parked.Parked(key, f"/code/api-{key}", "7", "s", on))
|
||||
os.utime(parked.file_of(self.folder, key), (SINCE, SINCE))
|
||||
|
||||
def lines(self, issues: list, *windows: tuple[str, str, bool, str], unblocking: tuple[str, ...] = ()) -> list[str] | Failure:
|
||||
return status.lines("ABC-12", self.home, issues, {}, unblocking, Tmux(*windows), ())
|
||||
return status.lines("ABC-12", self.folder, issues, {}, unblocking, Tmux(*windows), ())
|
||||
|
||||
def test_a_chunk_that_asks_says_where_to_answer_and_one_that_works_runs(self) -> None:
|
||||
found = self.lines([issue("ABC-20", "repo:api"), issue("ABC-21", "repo:api")], (EPIC, "ABC-20 ?", False, ""), (EPIC, "ABC-21", False, ""))
|
||||
@@ -54,7 +52,7 @@ class TheStatusLines(unittest.TestCase):
|
||||
def test_an_issue_without_scores_says_that_it_starts_after_each_that_holds_them(self) -> None:
|
||||
held = dataclasses.replace(issue("ABC-21", "repo:api"), scores={"L": 1, "E": 1, "I": 1, "S": 1})
|
||||
room = "it has not started; `do-epic ABC-12` starts it once the epic and its repo have room"
|
||||
found = status.lines("ABC-12", self.home, [issue("ABC-20", "repo:api"), held], {}, (), Tmux(), ("ABC-21",))
|
||||
found = status.lines("ABC-12", self.folder, [issue("ABC-20", "repo:api"), held], {}, (), Tmux(), ("ABC-21",))
|
||||
self.assertEqual(found, [f"ABC-20 waits: {room}, after each issue that holds every score, since it doesn't", f"ABC-21 waits: {room}"])
|
||||
# Where no issue starts by score, each starts in the tracker's rank order.
|
||||
self.assertEqual(self.lines([issue("ABC-20", "repo:api"), held]), [f"ABC-20 waits: {room}", f"ABC-21 waits: {room}"])
|
||||
|
||||
@@ -33,7 +33,7 @@ def write_config(home: pathlib.Path, checkout: pathlib.Path, goals: str = "check
|
||||
|
||||
|
||||
def configured(test: unittest.TestCase, checkout: pathlib.Path, goals: str = "checkout:README.md", home: pathlib.Path | None = None) -> pathlib.Path:
|
||||
"""Makes checkout a git checkout that a config names, under home, else under a folder of its own for the rest of the test; the config's folder, two levels under that home."""
|
||||
"""Makes checkout a git checkout that a config names, under home, else under a folder of its own for the rest of the test; the config's folder, three levels under that home."""
|
||||
subprocess.run(["git", "init", "--quiet", str(checkout)], check=True, env=isolated_env())
|
||||
if home is None:
|
||||
made = tempfile.TemporaryDirectory()
|
||||
|
||||
Reference in New Issue
Block a user