Answer principles round 1: 0 🔴, 6 🟡; read the plan from the fetched default branch for routing and the preflight alike and drop the fast-forward, name no item where the release after the last tag has none, tell an empty items table from none, time out the fetch, return run_python's errors as exit codes, test the error paths and the gh rows, assert facts in place of sentences, keep the open-PR sentence in every fresh prompt, name the item branch in CLAUDE.md, and measure item 175 against five chunks with counter-signals
This commit is contained in:
@@ -9,6 +9,11 @@ from todo_table import Item, item_details, items, next_item
|
||||
|
||||
# The CLI that lists a forge's pull requests: gh for a github.com origin, tea for any other.
|
||||
Forge = typing.Literal["gh", "tea"]
|
||||
# The command each forge's CLI lists pull requests with; pulls_command adds the flags that pick their rows and fields.
|
||||
PULLS_LIST: dict[Forge, tuple[str, ...]] = {"gh": ("gh", "pr", "list"), "tea": ("tea", "pulls", "list")}
|
||||
# How the plan's earliest release stands to the version x.y.z the newest tag names. "next": it is x.y.z+1, x.y+1.0 or x+1.0.0, or no tag names a version. "cut": it is x.y.z or earlier.
|
||||
# Else the release after the tag holds no item: "finished" where commits followed the tag, "unplanned" where none did, and "unknown" where they cannot be counted.
|
||||
Standing = typing.Literal["next", "cut", "finished", "unplanned", "unknown"]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -30,7 +35,7 @@ class Release:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Plan:
|
||||
"""The checkout's todo.md items, and first, the item the next chunk takes first."""
|
||||
"""The default branch's todo.md items, and first, the item the next chunk takes first."""
|
||||
items: list[Item]
|
||||
first: Item
|
||||
# first's tagline and detail.
|
||||
@@ -42,6 +47,12 @@ class Plan:
|
||||
return f"item-{self.first.id}"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class NoItem:
|
||||
"""Why the plan names no item for the next chunk, as a sentence the worker reads."""
|
||||
why: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Worktree:
|
||||
path: pathlib.Path
|
||||
@@ -77,48 +88,57 @@ class Gathered:
|
||||
default: str
|
||||
# Why origin reads as last fetched; None after a fetch.
|
||||
note: str | None
|
||||
# Why the checkout was not fast-forwarded to default; None once it was.
|
||||
kept_as_is: str | None
|
||||
release: Release
|
||||
# The plan's first item and what was found or made for it; else why there is none.
|
||||
item: ItemFacts | str
|
||||
# What was found or made for the plan's first item; else why the plan names none.
|
||||
item: ItemFacts | NoItem
|
||||
|
||||
|
||||
def planned(todo: str | Failure) -> Plan | str:
|
||||
"""The checkout's plan and its first item, as todo_table.next_item picks it; else why there is none."""
|
||||
def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoItem:
|
||||
"""The plan in todo, the default branch's todo.md, with the item the next chunk takes first, todo_table.next_item's pick, where standing finds the plan's earliest release next; else why there is none."""
|
||||
where = f"{default}'s todo.md"
|
||||
if isinstance(todo, Failure):
|
||||
return f"the checkout's todo.md cannot be read: {todo.reason}"
|
||||
return NoItem(f"{where} cannot be read: {todo.reason}.")
|
||||
found = items(todo)
|
||||
if isinstance(found, Failure):
|
||||
return f"the checkout's todo.md cannot be read: {found.reason}"
|
||||
listed = found or []
|
||||
first = next_item(listed)
|
||||
return NoItem(f"{where} cannot be read: {found.reason}.")
|
||||
if found is None:
|
||||
return NoItem(f"{where} holds no items table.")
|
||||
earliest = min((item.release for item in found), default=None)
|
||||
stands = standing(release, earliest)
|
||||
if earliest is not None and stands == "cut":
|
||||
return NoItem(f"{where} files items under release {version(earliest)}, which is not after the last cut, {release.tag}.")
|
||||
gap = f"{where} holds no item for the release after the last cut, {release.tag}, and"
|
||||
if stands == "finished":
|
||||
return NoItem(f"{gap} commits have landed since, so that release is finished and ready to cut, and the working loop stops here.")
|
||||
if stands == "unplanned":
|
||||
return NoItem(f"{gap} no commit has landed since, so that release is to be planned first.")
|
||||
if stands == "unknown":
|
||||
return NoItem(f"{gap} the commits since it cannot be counted.")
|
||||
first = next_item(found)
|
||||
if first is None:
|
||||
return "every item of the checkout's next release waits" if listed else "the checkout holds no todo.md items table"
|
||||
return NoItem(f"every item of release {version(earliest)} in {where} waits." if earliest is not None else f"{where}'s items table holds no item.")
|
||||
details = item_details(todo)
|
||||
detail = details.get(first.id, "") if isinstance(details, dict) else f"(todo.md's details cannot be read: {details.reason})"
|
||||
return Plan(listed, first, f"{first.tagline}\n\n{detail}".strip())
|
||||
return Plan(found, first, f"{first.tagline}\n\n{detail}".strip())
|
||||
|
||||
|
||||
def held_back(default: str, head: str | Failure, status: str | Failure, behind: str | Failure) -> str | None:
|
||||
"""Why the checkout is not fast-forwarded to default, from its branch, its tracked changes and how many commits it is behind; None where nothing holds it back.
|
||||
def standing(release: Release, earliest: tuple[int, int, int] | None) -> Standing:
|
||||
"""How the plan's earliest release, None where the plan holds no item, stands to the version the release's tag names, as Standing says."""
|
||||
cut = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", release.tag) if isinstance(release.tag, str) else None
|
||||
if cut is None:
|
||||
return "next"
|
||||
major, minor, patch = (int(part) for part in cut.groups())
|
||||
if earliest in ((major, minor, patch + 1), (major, minor + 1, 0), (major + 1, 0, 0)):
|
||||
return "next"
|
||||
if earliest is not None and earliest <= (major, minor, patch):
|
||||
return "cut"
|
||||
if isinstance(release.commits, Failure):
|
||||
return "unknown"
|
||||
return "finished" if release.commits else "unplanned"
|
||||
|
||||
A dirty checkout is never fast-forwarded, as `~/.claude/CLAUDE.md` → "Working with the codebase" asks: its changes are for the human to see, never to carry along.
|
||||
"""
|
||||
branch = default.removeprefix("origin/")
|
||||
if branch == default:
|
||||
return "it has no origin remote"
|
||||
if isinstance(head, Failure):
|
||||
return "it is on no branch"
|
||||
if head.strip() != branch:
|
||||
return f"it is on {head.strip()}, not {branch}"
|
||||
if isinstance(status, Failure):
|
||||
return f"its status cannot be read: {status.reason}"
|
||||
if status.strip():
|
||||
return "it holds uncommitted changes"
|
||||
if isinstance(behind, Failure):
|
||||
return f"how far it is behind {default} cannot be read: {behind.reason}"
|
||||
return f"it is not behind {default}" if int(behind) == 0 else None
|
||||
|
||||
def version(release: tuple[int, int, int]) -> str:
|
||||
return ".".join(map(str, release))
|
||||
|
||||
|
||||
def worktree_on(porcelain: str, branch: str) -> pathlib.Path | None:
|
||||
@@ -133,11 +153,11 @@ def worktree_on(porcelain: str, branch: str) -> pathlib.Path | None:
|
||||
def worktree_add(branch: str, path: pathlib.Path, default: str, local: bool, pushed: bool) -> tuple[list[str], str]:
|
||||
"""The git arguments that add branch's worktree at path, and how it comes to be: on the local branch, else on a new one tracking origin's, else on a new one off default."""
|
||||
if local:
|
||||
return ["worktree", "add", "--quiet", str(path), branch], f"on the branch {branch}, which existed already."
|
||||
return ["worktree", "add", "--quiet", str(path), branch], f"added on the branch {branch}, which existed already."
|
||||
if pushed:
|
||||
return ["worktree", "add", "--quiet", "--track", "-b", branch, str(path), f"origin/{branch}"], f"on the new branch {branch}, made off origin/{branch}."
|
||||
return ["worktree", "add", "--quiet", "--track", "-b", branch, str(path), f"origin/{branch}"], f"added on the new branch {branch}, made off origin/{branch}."
|
||||
# --no-track: tracking the default branch would point a bare `git push` at it.
|
||||
return ["worktree", "add", "--quiet", "--no-track", "-b", branch, str(path), default], f"on the new branch {branch}, made off {default}."
|
||||
return ["worktree", "add", "--quiet", "--no-track", "-b", branch, str(path), default], f"added on the new branch {branch}, made off {default}."
|
||||
|
||||
|
||||
def forge_of(origin_url: str) -> Forge:
|
||||
@@ -147,12 +167,12 @@ def forge_of(origin_url: str) -> Forge:
|
||||
def pulls_command(forge: Forge, branch: str) -> list[str]:
|
||||
"""The command that lists open pull requests, by number, head and URL. gh lists only branch's; tea lists every one, for facts.open_pulls to pick branch's."""
|
||||
if forge == "gh":
|
||||
return ["gh", "pr", "list", "--head", branch, "--json", "number,url", "--template", "{{range .}}{{.number}}\t{{.url}}\n{{end}}"]
|
||||
return ["tea", "pulls", "list", "--fields", "index,head,url", "--output", "tsv"]
|
||||
return [*PULLS_LIST["gh"], "--head", branch, "--json", "number,url", "--template", "{{range .}}{{.number}}\t{{.url}}\n{{end}}"]
|
||||
return [*PULLS_LIST["tea"], "--fields", "index,head,url", "--output", "tsv"]
|
||||
|
||||
|
||||
def named_paths(text: str, tracked: list[str]) -> list[tuple[str, int]]:
|
||||
"""Each backticked span in text, in order and once, that names a tracked file or folder, with how many of the tracked files it holds: 1 for a file."""
|
||||
spans = dict.fromkeys(span.rstrip("/") for span in re.findall(r"`([^`\s]+)`", text))
|
||||
spans = dict.fromkeys(span.removesuffix("/") for span in re.findall(r"`([^`\s]+)`", text))
|
||||
held = ((span, sum(path == span or path.startswith(f"{span}/") for path in tracked)) for span in spans)
|
||||
return [(span, count) for span, count in held if count]
|
||||
|
||||
Reference in New Issue
Block a user