"""The AI usage logs (AGENTS.md rule 7) stay in step with the work.
The course's AI Usage Report is written from these logs, so: every member has one, every handoff
note has an entry for its date in its author's log (`/handoff` writes both), and every entry says
which tool was used, what the AI did and what the member did. If a test fails, add the entry to
docs/ai-usage/<name>.md in the format of docs/ai-usage/README.md.
"""
import re
from common.settings import DOCS_DIR, REPO_ROOT
LOGS = DOCS_DIR / "ai-usage"
HANDOFFS = DOCS_DIR / "handoffs"
DATE = re.compile(r"^## (\d{4}-\d{2}-\d{2})", re.M)
def members() -> list[str]:
"""First names in AGENTS.md's team table, in lower case (the log file names)."""
team = (REPO_ROOT / "AGENTS.md").read_text().split("## Team", 1)[1].split("\n## ", 1)[0]
return [m.lower() for m in re.findall(r"^\| ([A-Z][a-z]+) \|", team, re.M) if m != "Name"]
def entries(text: str) -> list[tuple[str, str]]:
"""(date, body) for each dated entry of a log."""
parts = DATE.split(text)
return list(zip(parts[1::2], parts[2::2]))
def test_the_team_table_is_read():
assert len(members()) >= 4
def test_every_member_has_a_log():
missing = [m for m in members() if not (LOGS / f"{m}.md").exists()]
assert not missing, f"no AI usage log for {missing}: copy the format in docs/ai-usage/README.md"
def test_every_handoff_note_has_an_ai_usage_entry_for_its_date():
problems = []
for note in sorted(HANDOFFS.glob("20??-??-??-*.md")):
date, name = note.name[:10], note.name[11:].split("-")[0]
log = LOGS / f"{name}.md"
if not log.exists() or date not in {d for d, _ in entries(log.read_text())}:
problems.append(f"{note.name}: add a '## {date}' entry to docs/ai-usage/{name}.md")
assert not problems, "\n".join(problems)
def test_every_entry_says_the_tool_what_the_ai_did_and_what_the_member_did():
problems = []
for log in sorted(LOGS.glob("*.md")):
if log.name == "README.md":
continue
for date, body in entries(log.read_text()):
has = {"tool": "**Tool:**" in body,
"AI part": "**AI did:**" in body or "**How I used AI:**" in body,
"own part": "**I did:**" in body or "**What I did:**" in body}
problems += [f"{log.name} {date}: no {k}" for k, ok in has.items() if not ok]
assert not problems, "\n".join(problems)