Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions agents/conductors/batch/_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,27 @@ def lane_absent_why(r: dict) -> str:


def declared_repos(p: dict) -> list[str]:
"""A parsed prompt's `Repos:` header and known target, normalised; its
survey `repos` when it declares neither."""
"""The repos a parsed prompt will touch, normalised: its `Repos:` header
when that names any known repo; otherwise its `Target:` when that is a
known repo; otherwise its survey `repos`.

`Target:` is not unioned into a declared `Repos:` block: it is often only
an epic label (a prompt with `Target: autofit` whose `Repos:` lists only
PyAutoCortex), so adding it made the claim gate report a false conflict
on a repo the prompt never touches (PyAutoBrain#675)."""
from _sizing import KNOWN_REPOS # noqa: E402
out = set()
block = re.search(r"^Repos:\n((?:- .+\n)+)", p.get("text") or "", re.M)
for ln in block.group(1).splitlines() if block else ():
r = normalise_repo(ln[1:].strip())
if r in KNOWN_REPOS:
out.add(r)
if out:
return sorted(out)
t = normalise_repo(p.get("target") or "")
if t in KNOWN_REPOS:
out.add(t)
return sorted(out) or list(p.get("repos") or [])
return [t]
return list(p.get("repos") or [])


def grade(path: Path, mind: Path, text: str | None = None) -> dict:
Expand Down
55 changes: 55 additions & 0 deletions tests/test_batch_declared_repos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""`declared_repos` and the batch claim gate (PyAutoBrain#675).

A prompt's `Target:` is often only an epic label: a prompt with
`Target: pyautoeyes` whose `Repos:` lists only PyAutoCortex never touches
PyAutoEyes, so a claim on PyAutoEyes must not hold it.
"""

from __future__ import annotations

import sys
from pathlib import Path

BRAIN = Path(__file__).resolve().parents[1]
BATCH = BRAIN / "agents" / "conductors" / "batch"
sys.path.insert(0, str(BRAIN / "agents" / "faculties" / "sizing"))
sys.path.insert(0, str(BATCH))
import _batch # noqa: E402
import _orchestrator as orch # noqa: E402
from _sizing import normalise_repo # noqa: E402

ACTIVE = ("# Active\n\n## eyes-work\n- prompt: active/feature/pyautoeyes/eyes-work.md\n"
"- session: claude-code desktop (WSL)\n- repos:\n - PyAutoEyes\n")


def _prompt(target: str, repos: list[str] | None) -> dict:
text = f"Target: {target}\n"
if repos is not None:
text += "Repos:\n" + "".join(f"- {r}\n" for r in repos)
return {"target": target, "text": text + "\nBody.\n", "repos": ["survey_only"]}


def test_repos_block_wins_over_an_epic_label_target():
p = _prompt("pyautoeyes", ["PyAutoCortex"])
assert _batch.declared_repos(p) == [normalise_repo("PyAutoCortex")]


def test_claim_on_the_target_does_not_hold_a_prompt_that_never_touches_it():
sections = orch.claim_sections(ACTIVE)
cortex_only = _batch.declared_repos(_prompt("pyautoeyes", ["PyAutoCortex"]))
assert orch._held_for(sections, "cortex-ledger", cortex_only) is None
touches_eyes = _batch.declared_repos(_prompt("pyautoeyes", ["PyAutoEyes", "PyAutoCortex"]))
assert orch._held_for(sections, "eyes-follow-up", touches_eyes) == ("PyAutoEyes", "eyes-work")


def test_no_repos_block_falls_back_to_target():
assert _batch.declared_repos(_prompt("pyautoeyes", None)) == [normalise_repo("pyautoeyes")]


def test_repos_block_of_unknown_names_falls_back_to_target():
p = _prompt("pyautoeyes", ["not_a_repo", "another_unknown"])
assert _batch.declared_repos(p) == [normalise_repo("pyautoeyes")]


def test_unknown_target_and_no_repos_falls_back_to_survey():
assert _batch.declared_repos(_prompt("epic-label", None)) == ["survey_only"]
Loading