diff --git a/bin/chunk_preflight/choices.py b/bin/chunk_preflight/choices.py index f8306c7a..66428f5c 100644 --- a/bin/chunk_preflight/choices.py +++ b/bin/chunk_preflight/choices.py @@ -50,7 +50,7 @@ def planned(todo: str | Failure, cut: LastCut, default: str) -> Plan | NoItem: return NoItem(f"every item of release {version(pick.release)} in {where} waits." if pick.release 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(found, first, f"{first.tagline}\n\n{detail}".strip(), details if isinstance(details, dict) else {}) + return Plan(found, first, f"{first.tagline}\n\n{detail}".strip(), details) def worktree_on(porcelain: str, branch: str) -> pathlib.Path | None: diff --git a/bin/chunk_preflight/facts.py b/bin/chunk_preflight/facts.py index 95a27b0c..4c1f5019 100644 --- a/bin/chunk_preflight/facts.py +++ b/bin/chunk_preflight/facts.py @@ -4,12 +4,16 @@ from chunk_preflight.choices import cut_name, PULLS_LIST from release_plan.release_standing import dated_cut, LastCut, unreleased_entries from failure import Failure from chunk_preflight.gathered import Forge, Gathered, ItemFacts, NamedPath, NoItem, Plan, Ran -from records.markdown_text import quoted +from records.markdown_text import listed, quoted from release_plan.release import version +# CLAUDE.md → "Working loop" lets up to ten tiny items share a chunk, so a worker never needs more. A release with 24 joinable items would otherwise put about 155 lines of detail in every prompt. +JOINING_DETAILS = 10 + + def render(found: Gathered) -> list[str]: - """One `- ` line per fact, then the item's tagline and detail, and what each tool printed.""" + """One `- ` line per fact, then the item's tagline and detail, the detail of each item that may join its chunk, and what each tool printed.""" note = [f"- {found.note}"] if found.note else [] head = [*note, f"- {last_release(found.default, found.cut)}"] if isinstance(found.item, NoItem): @@ -42,11 +46,25 @@ def item_lines(default: str, item: ItemFacts) -> list[str]: *bundled(item.plan), *named_lines(item.named), f"\nItem {first.id}'s tagline and detail:\n\n{quoted(item.plan.text)}", - *(f"\nItem {joining.id}'s detail:\n\n{quoted(item.plan.details[joining.id])}" for joining in bundle_candidates(item.plan.items, first) if item.plan.details.get(joining.id)), + *joining_details(item.plan), *(f"\n{printed(shown, done)}" for shown, done in item.tools), ] +def joining_details(plan: Plan) -> list[str]: + """The detail of each of the first JOINING_DETAILS items that may join the chunk, in the table's order, and what the worker lacks: an item with no detail, the items left out, or details that cannot be read.""" + joining = bundle_candidates(plan.items, plan.first) + if not joining: + return [] + if isinstance(plan.details, Failure): + return [f"\nThe details of the items that may join cannot be read: {plan.details.reason}"] + shown, left = joining[:JOINING_DETAILS], joining[JOINING_DETAILS:] + lines = [f"\nItem {item.id}'s detail:\n\n{quoted(detail)}" if (detail := plan.details.get(item.id)) else f"\nItem {item.id} has no detail." for item in shown] + if left: + lines.append(f"\nThe details of items {listed([str(item.id) for item in left], 'and')} are not quoted: only the first {JOINING_DETAILS} are. Open `todo.md` for them.") + return lines + + def pulls_text(pulls: tuple[Forge, Ran | Failure] | None, branch: str) -> str: """Each open pull request from branch, by its number and URL, or why none can be listed. No title: on a public forge anyone may open one, and its title would reach the worker's prompt.""" if pulls is None: diff --git a/bin/chunk_preflight/gathered.py b/bin/chunk_preflight/gathered.py index 76fa73f9..4ef47b60 100644 --- a/bin/chunk_preflight/gathered.py +++ b/bin/chunk_preflight/gathered.py @@ -26,8 +26,8 @@ class Plan: first: Item # first's tagline and detail. text: str - # Every item's detail by its ID; empty where todo.md's details cannot be read. - details: dict[int, str] + # Every item's detail by its ID, or why todo.md's details cannot be read. + details: dict[int, str] | Failure @property def branch(self) -> str: diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index e9d03837..c077f1bf 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -345,8 +345,23 @@ class Render(unittest.TestCase): self.assertIn("Item 7's detail:\n\n> Touch `src/other.py`.\n> \n> Run the e2e leg.", said) self.assertNotIn("Not quoted", said) - def test_quotes_no_detail_for_a_joining_item_that_has_none(self): - self.assertNotIn("Item 7's detail", rendered(item_facts())) + def test_states_that_a_joining_item_has_no_detail(self): + said = rendered(item_facts()) + self.assertIn("Item 7 has no detail.", said) + self.assertNotIn("Item 7's detail", said) + + def test_states_that_the_joining_items_details_cannot_be_read(self): + said = rendered(item_facts(TODO + "\n```\nx\n```\n")) + self.assertIn("The details of the items that may join cannot be read: ## Details holds a fenced code block", said) + self.assertNotIn("has no detail", said) + + def test_quotes_the_details_of_the_first_ten_joining_items_and_names_the_rest(self): + rows = "".join(f"| {id_} | 0.2.0 | | | **Do thing {id_}.** | 1 | 1 | 1 | 1 | 1 | 1 by 1 | 10.0 |\n" for id_ in range(20, 32)) + details = "".join(f"\n### {id_}. Do thing {id_}.\n\nDetail {id_}.\n" for id_ in range(7, 8)) + "".join(f"\n### {id_}. Do thing {id_}.\n\nDetail {id_}.\n" for id_ in range(20, 32)) + said = rendered(item_facts(TODO.replace("\n## Details", rows + "\n## Details") + details)) + self.assertIn("> Detail 28.", said) + self.assertNotIn("Detail 29.", said) + self.assertIn("The details of items 29, 30 and 31 are not quoted: only the first 10 are. Open `todo.md` for them.", said) def test_states_the_items_worktree_or_why_none_was_made(self): self.assertIn("/c/proj-item-3", rendered(item_facts()))