@jesdi/skills 0.0.98 → 0.0.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/package.json +1 -1
  2. package/skills/implement-spec/ARCHITECTURE.md +10 -5
  3. package/skills/implement-spec/README.md +44 -17
  4. package/skills/implement-spec/SKILL.md +4 -2
  5. package/skills/implement-spec/driver.py +166 -40
  6. package/skills/implement-spec/driver_agents.py +26 -8
  7. package/skills/implement-spec/driver_arbiter.py +89 -0
  8. package/skills/implement-spec/driver_decisions.py +212 -39
  9. package/skills/implement-spec/driver_dispute.py +1 -1
  10. package/skills/implement-spec/driver_final.py +255 -186
  11. package/skills/implement-spec/driver_final_gate.py +1 -1
  12. package/skills/implement-spec/driver_legacy.py +15 -2
  13. package/skills/implement-spec/driver_overturn.py +106 -0
  14. package/skills/implement-spec/driver_pr.py +277 -0
  15. package/skills/implement-spec/driver_report.py +24 -6
  16. package/skills/implement-spec/driver_review.py +10 -4
  17. package/skills/implement-spec/driver_run.py +38 -15
  18. package/skills/implement-spec/driver_slots.py +33 -0
  19. package/skills/implement-spec/driver_state.py +29 -15
  20. package/skills/implement-spec/driver_summary.py +11 -4
  21. package/skills/implement-spec/models.json +2 -1
  22. package/skills/implement-spec/prompts/arbiter.md +38 -0
  23. package/skills/implement-spec/prompts/conflict.md +1 -1
  24. package/skills/implement-spec/prompts/pr-body.md +1 -1
  25. package/skills/implement-spec/recovery.md +4 -4
  26. package/skills/implement-spec/tests/conftest.py +3 -0
  27. package/skills/implement-spec/tests/test_arbiter.py +208 -0
  28. package/skills/implement-spec/tests/test_arbitration.py +1 -1
  29. package/skills/implement-spec/tests/test_cli.py +1 -1
  30. package/skills/implement-spec/tests/test_decisions.py +31 -7
  31. package/skills/implement-spec/tests/test_driver.py +10 -2
  32. package/skills/implement-spec/tests/test_final.py +34 -9
  33. package/skills/implement-spec/tests/test_fixloop.py +2 -2
  34. package/skills/implement-spec/tests/test_leave_out.py +203 -0
  35. package/skills/implement-spec/tests/test_legacy.py +25 -0
  36. package/skills/implement-spec/tests/test_lenses.py +6 -4
  37. package/skills/implement-spec/tests/test_overturn.py +362 -0
  38. package/skills/implement-spec/tests/test_report.py +1 -1
  39. package/skills/implement-spec/tests/test_scoped.py +18 -15
  40. package/skills/implement-spec/tests/test_ship_draft.py +203 -0
  41. package/skills/implement-spec/tests/test_slots.py +29 -0
  42. package/skills/implement-spec/tests/test_state.py +4 -2
  43. package/skills/implement-spec/tests/test_stops.py +21 -5
  44. package/skills/implement-spec/tests/test_tidy.py +7 -5
  45. package/skills-manifest.json +3 -3
@@ -3,7 +3,11 @@
3
3
  A question in state.json `run.questions`; `answer` is None while it is open:
4
4
  {id, title, why, evidence, options: [{id, description}], recommended, ticket, kind, subject, stop, answer,
5
5
  resume: {phase[, tip][, round][, gate_allowance]}, the record fields a `retry` or a `keep-test` sets (`Resume`),
6
- ruling: the ruling sentence, once answered}
6
+ ruling: the ruling sentence, once answered; by: DRIVER or ARBITER when no operator answered it, until the operator
7
+ overturns the ruling (driver_overturn); overturned: who took the ruling the operator overturned;
8
+ issue: the URL of the follow-up issue the driver filed for a `follow-up` answer;
9
+ role: the agent whose stop a `ticket-blocked` question asks about, None for a gate or a landing stop and absent
10
+ from a question of an older driver, which a reader takes as no particular agent}
7
11
  decisions.json: {run: <run.revision>, questions: [the open ones, first six fields], revision: <SHA-256 of the rest>}."""
8
12
  from __future__ import annotations
9
13
 
@@ -12,8 +16,16 @@ import json
12
16
  from collections import Counter
13
17
  from typing import NamedTuple
14
18
 
19
+ from driver_tickets import Ticket
20
+
15
21
  PUBLIC = ("id", "title", "why", "evidence", "options", "recommended")
16
22
  DRIVER = "driver" # `by` of a question the driver answered itself
23
+ ARBITER = "arbiter" # `by` of a question the arbiter agent answered
24
+ OPERATOR = "operator" # what `ruled_by` says of a question with no `by`
25
+ SHIPS = ("accept", "follow-up") # the answers to a finding question that ship the PR with the finding open
26
+ FINDING_OPEN = "finding-open" # the kind of an important finding: the arbiter may ship it, as draft
27
+ MUST_FIX = "finding-must-fix" # the kind of a critical or must-fix finding: no agent ships it
28
+ FINDINGS = (FINDING_OPEN, MUST_FIX) # the kinds of a final-review finding that the scoped review leaves open
17
29
  FINAL = "final" # the end of run asks its questions, and has its record and its files, under this name
18
30
 
19
31
 
@@ -43,6 +55,15 @@ class Option(NamedTuple):
43
55
  ruling: str
44
56
  resumes: bool # the record goes back to the `resume` of the question
45
57
  fields: dict = {} # what else the record gets when its stop is settled; no field at all keeps it BLOCKED
58
+ final_only: bool = False # only the end of run offers it
59
+ ticket_only: bool = False # only a ticket offers it
60
+
61
+
62
+ LEAVE_OUT = Option(
63
+ "Leave the ticket out of the run, with each ticket it blocks: the merged tickets get the end of run and a draft PR "
64
+ "that names them. The driver takes it once its retries, and the arbiter's, are spent.",
65
+ "Ruling: {ticket} is left out of the run, with each ticket it blocks (leave-out): {subject}.", False,
66
+ ticket_only=True)
46
67
 
47
68
 
48
69
  class Kind(NamedTuple):
@@ -50,6 +71,20 @@ class Kind(NamedTuple):
50
71
  why: str
51
72
  recommended: str # "" for a kind that recommends no option
52
73
  options: dict[str, Option]
74
+ arbiter: tuple[str, ...] = () # the options the arbiter may rule with once the driver's retries are spent; none:
75
+ # the arbiter does not rule on it
76
+
77
+
78
+ FINDING_OPTIONS = { # both finding kinds: they differ only in who may ship the finding (`Kind.arbiter`)
79
+ "retry": Option(
80
+ "One more fix batch and scoped review.",
81
+ "Ruling: {ticket} runs again (retry): {subject}.", True),
82
+ "accept": Option(
83
+ "Push and open the PR as draft, with the finding open and listed in its rulings.",
84
+ "Ruling: {ticket} ships with the finding open (accept): {subject}.", True),
85
+ "follow-up": Option(
86
+ "As `accept`, and the driver files the finding as an issue before it opens the PR.",
87
+ "Ruling: {ticket} ships with the finding open, filed as a follow-up issue (follow-up): {subject}.", True)}
53
88
 
54
89
 
55
90
  KINDS = {
@@ -69,15 +104,17 @@ KINDS = {
69
104
  "again (a fixer after the review of its round); after a review finding, the review runs again.",
70
105
  "Ruling: {ticket} locked test is corrected to the second reading (correct-test): {subject}.", False,
71
106
  {"phase": "test-writer", "note": "correction"}),
107
+ "leave-out": LEAVE_OUT,
72
108
  "edit-spec": Option(
73
109
  "Keep the ticket BLOCKED, so the spec can be edited to say which reading it means.",
74
- "Ruling: {ticket} stays BLOCKED for an edit of the spec (edit-spec): {subject}.", False)}),
75
- # The end of run asks it too, with the ticket `final`: for an agent, or for a finding open after the scoped review.
110
+ "Ruling: {ticket} stays BLOCKED for an edit of the spec (edit-spec): {subject}.", False)},
111
+ arbiter=("keep-test", "correct-test")),
112
+ # The end of run asks it too, with the ticket `final`: for an agent, or for the integration gate.
76
113
  "ticket-blocked": Kind(
77
- "{owner}: an agent stopped or was rejected, and its rerun too, or a final-review finding or integration gate remains red: {subject}",
114
+ "{owner}: an agent stopped or was rejected, and its rerun too, or the integration gate remains red: {subject}",
78
115
  "An agent ran two times, using the same model for a timeout or moved branch and the next entry otherwise, "
79
- "and stopped or was rejected both times; or the final review left a finding open, or the integration gate "
80
- "stayed red after its repair. {owner} is BLOCKED, each ticket that it blocks waits, and nothing is pushed.",
116
+ "and stopped or was rejected both times; or the integration gate stayed red after its repair. {owner} is "
117
+ "BLOCKED, each ticket that it blocks waits, and nothing is pushed.",
81
118
  "retry",
82
119
  {"retry": Option(
83
120
  "The role runs again on its first entry from the tip the ticket left, with one rerun (the same model "
@@ -85,12 +122,38 @@ KINDS = {
85
122
  "fix batch and scoped review, and a red integration gate gets one more repair batch from its saved "
86
123
  "log, followed by the full gate and review.",
87
124
  "Ruling: {ticket} runs again (retry): {subject}.", True),
125
+ "ship-draft": Option(
126
+ "Push the branch tip that a full gate ran on, green or red, and open the PR as draft, naming this stop; "
127
+ "the end of run reviews and repairs no more. The driver takes it once its retries are spent.",
128
+ "Ruling: {ticket} ships as a draft PR (ship-draft): {subject}.", True, final_only=True),
129
+ "leave-out": LEAVE_OUT,
88
130
  "edit": Option(
89
131
  "Keep it BLOCKED, so the spec or the ticket can be edited before more work on it.",
90
132
  "Ruling: {ticket} stays BLOCKED for an edit of the spec or the ticket (edit): {subject}.", False)}),
133
+ # Only the end of run asks the two finding kinds: the subject is the finding's title and file (`subject`).
134
+ FINDING_OPEN: Kind(
135
+ "End of run: a final-review finding is open after the scoped review: {subject}",
136
+ "The scoped review after the fix batch left this important finding open. Nothing is pushed until it is ruled "
137
+ "on.",
138
+ "retry", FINDING_OPTIONS, arbiter=SHIPS),
139
+ MUST_FIX: Kind(
140
+ "End of run: a critical or must-fix finding is open after the scoped review: {subject}",
141
+ "The scoped review after the fix batch left this critical or must-fix finding open, and the driver's own fix "
142
+ "batches are spent. No agent ships it: only you may. Nothing is pushed until it is ruled on.",
143
+ "retry", FINDING_OPTIONS),
91
144
  }
92
145
 
93
146
 
147
+ def finding_kind(finding: dict) -> str:
148
+ """The kind of the question that an open final-review finding asks."""
149
+ return MUST_FIX if finding["severity"] == "critical" or finding.get("must_fix") else FINDING_OPEN
150
+
151
+
152
+ def subject(finding: dict) -> str:
153
+ """A final-review finding as its question names it: its title and file, not its line, which a fix batch moves."""
154
+ return f"{finding['title']} ({finding['file']})"
155
+
156
+
94
157
  def drop_merged(state: dict) -> list[dict]:
95
158
  """Remove the open questions of each merged ticket from `state`: the stop that asked them is over (issue #136).
96
159
  Returns them."""
@@ -103,30 +166,45 @@ def drop_merged(state: dict) -> list[dict]:
103
166
 
104
167
  def question_id(kind: str, ticket: str, asked: list[dict]) -> str:
105
168
  """The id of the next question of `kind` for `ticket`: `<NN>-<kind>-<n>` (`final-<kind>-<n>` for the end of run);
106
- n counts in `asked`, the whole run."""
107
- return f"{ticket}-{kind}-{1 + sum((q['ticket'], q['kind']) == (ticket, kind) for q in asked)}"
169
+ n counts the ids of `asked`, the whole run, so a question whose kind changed (driver_legacy) keeps its id."""
170
+ prefix = f"{ticket}-{kind}-"
171
+ return f"{prefix}{1 + sum(q['id'].startswith(prefix) for q in asked)}"
108
172
 
109
173
 
110
174
  def question(kind: str, ticket: str, subject: str, evidence: list[str], asked: list[dict], stop: int,
111
- resume: Resume) -> dict:
112
- """A new open question."""
175
+ resume: Resume, role: str | None = None) -> dict:
176
+ """A new open question; `role`: the agent whose stop it asks about. A gate or a landing stop has none, nor has a
177
+ question of a driver before it, so a reader takes no role for no particular agent."""
113
178
  made, values = KINDS[kind], {"ticket": ticket, "subject": subject, "owner": owner(ticket)}
114
179
  return {"id": question_id(kind, ticket, asked), "title": made.title.format(**values),
115
180
  "why": made.why.format(**values),
116
181
  "evidence": evidence, "recommended": made.recommended,
117
- "options": [{"id": name, "description": option.description} for name, option in made.options.items()],
118
- "ticket": ticket, "kind": kind, "subject": subject, "stop": stop, "resume": resume.fields(), "answer": None}
182
+ "options": [{"id": name, "description": option.description} for name, option in made.options.items()
183
+ if _offered(option, ticket)],
184
+ "ticket": ticket, "kind": kind, "subject": subject, "stop": stop, "resume": resume.fields(), "answer": None,
185
+ "role": role}
186
+
187
+
188
+ def _offered(option: Option, ticket: str) -> bool:
189
+ """Whether a stop of `ticket` offers `option`: an end-of-run one only at the end of run, a ticket one only for a
190
+ ticket."""
191
+ return not (option.ticket_only if ticket == FINAL else option.final_only)
119
192
 
120
193
 
121
- def stop(run: dict, kind: str, ticket: str, subjects: list[str], evidence: list[str], resume: Resume) -> None:
122
- """Count one stop in `run` and add one open question of `kind` per subject. No subject is no stop."""
123
- run["stops"] += bool(subjects)
124
- for subject in subjects:
125
- run["questions"].append(question(kind, ticket, subject, evidence, run["questions"], run["stops"], resume))
194
+ def stop(run: dict, ticket: str, asked: list[tuple[str, str, str | None]], evidence: list[str], resume: Resume
195
+ ) -> None:
196
+ """Count one stop in `run` and add one open question per (kind, subject, role) of `asked`. Nothing asked is no
197
+ stop."""
198
+ run["stops"] += bool(asked)
199
+ for kind, subject, role in asked:
200
+ run["questions"].append(question(kind, ticket, subject, evidence, run["questions"], run["stops"], resume, role))
126
201
 
127
202
 
128
- def decides(kind: str, subjects: int) -> str:
129
- return f"the operator decides on {subjects} question{'s' * (subjects > 1)} of kind {kind}"
203
+ def decides(asked: list[tuple[str, str, str | None]]) -> str:
204
+ """What the operator decides on at a stop that asks `asked`, (kind, subject, role) triples."""
205
+ counts = Counter(kind for kind, *_ in asked)
206
+ return "the operator decides on " + " and ".join(
207
+ f"{n} question{'s' * (n > 1)} of kind {kind}" for kind, n in counts.items())
130
208
 
131
209
 
132
210
  def document(run: dict) -> dict:
@@ -138,8 +216,56 @@ def document(run: dict) -> dict:
138
216
 
139
217
 
140
218
  def rulings(questions: list[dict]) -> list[str]:
141
- """The ruling sentence of each answered question, without the note of the operator."""
142
- return [q["ruling"] for q in questions if q["answer"] is not None]
219
+ """The ruling sentence of each answered question, without the note of the operator, with its follow-up issue."""
220
+ return [q["ruling"] + (f" Follow-up issue: {q['issue']}" if q.get("issue") else "")
221
+ for q in questions if q["answer"] is not None]
222
+
223
+
224
+ def waived(questions: list[dict], finding: dict) -> bool:
225
+ """An answer to a question on `finding` ships it: no fix batch is due. A finding that is critical or must-fix now
226
+ is shipped only by the operator's answer, not by the driver's or the arbiter's (`by`) to it as an important one."""
227
+ by = {ruled_by(q) for q in questions if _ships(q, subject(finding))}
228
+ return OPERATOR in by if finding_kind(finding) == MUST_FIX else bool(by)
229
+
230
+
231
+ def agent_shipped(questions: list[dict], finding: dict) -> bool:
232
+ """The driver or the arbiter (`by`), not the operator, answered a question on `finding` with an option that ships it."""
233
+ return any(ruled_by(q) != OPERATOR for q in questions if _ships(q, subject(finding)))
234
+
235
+
236
+ def _ships(q: dict, named: str) -> bool:
237
+ """`q` is a finding question on the subject `named`, answered with an option that ships it."""
238
+ return q["kind"] in FINDINGS and q["answer"] in SHIPS and q["subject"] == named
239
+
240
+
241
+ def left_out(questions: list[dict], tickets: list[Ticket]) -> set[str]:
242
+ """The tickets left out of the run: each one answered `leave-out`, and each ticket it blocks, directly or through
243
+ another. The others are the tickets the end of run ships."""
244
+ out = {q["ticket"] for q in questions if q["answer"] == "leave-out"}
245
+ for _ in tickets: # a chain of blockers is at most as long as the list
246
+ out |= {ticket.number for ticket in tickets if out.intersection(ticket.blocked_by)}
247
+ return out
248
+
249
+
250
+ def leave_out_answers(questions: list[dict], tickets: list[Ticket], retries: int) -> dict[str, str]:
251
+ """`leave-out` for each open question of a ticket that neither the driver's `retry` (`automatic`, while it ruled on
252
+ fewer than `retries` stops of the ticket) nor the arbiter rules on; none when the tickets left out would be all of
253
+ them: a run with no merged ticket ships nothing, so its stop asks the operator."""
254
+ spent, theirs = ruled(questions), {q["id"] for q in arbitrated(questions, retries)}
255
+ answers = {q["id"]: "leave-out" for q in questions if _unruled(q, spent, retries, theirs)}
256
+ after = [{**q, "answer": answers.get(q["id"], q["answer"])} for q in questions]
257
+ return answers if len(left_out(after, tickets)) < len(tickets) else {}
258
+
259
+
260
+ def _unruled(q: dict, spent: Counter, retries: int, theirs: set[str]) -> bool:
261
+ """`q` is an open question of a ticket that neither the driver's `retry` (`_due`) nor the arbiter (its id in
262
+ `theirs`) answers."""
263
+ return q["answer"] is None and q["ticket"] != FINAL and not _due(q, spent, retries) and q["id"] not in theirs
264
+
265
+
266
+ def follow_ups(questions: list[dict]) -> list[dict]:
267
+ """The finding questions answered `follow-up` with no issue filed yet."""
268
+ return [q for q in questions if q["kind"] in FINDINGS and q["answer"] == "follow-up" and not q.get("issue")]
143
269
 
144
270
 
145
271
  def ruling(q: dict) -> str:
@@ -164,35 +290,59 @@ def _settled(questions: list[dict], ticket: str, stop: int) -> dict:
164
290
  return {name: value for one in fields for name, value in one.items()} if all(fields) else {}
165
291
 
166
292
 
167
- def ruled(questions: list[dict]) -> Counter:
168
- """ticket (or FINAL) -> the stops of it that the driver ruled on."""
169
- return Counter(ticket for ticket, _ in {(q["ticket"], q["stop"]) for q in by_driver(questions)})
293
+ def ruled(questions: list[dict], by: str = DRIVER) -> Counter:
294
+ """ticket (or FINAL) -> the stops of it that `by`, the driver or the arbiter, ruled on."""
295
+ return Counter(ticket for ticket, _ in {(q["ticket"], q["stop"]) for q in questions if ruled_by(q) == by})
170
296
 
171
297
 
172
- def automatic(questions: list[dict], budget: int) -> dict:
298
+ def automatic(questions: list[dict], retries: int, must_fix_retries: int) -> dict:
173
299
  """The answers the driver gives itself: `retry` for each open question that recommends it, while the driver ruled
174
- on fewer than `budget` stops of its ticket (or of the end of run). No other option is the driver's to take: a
175
- kind that recommends one still asks the operator."""
176
- spent = ruled(questions)
177
- asked = [q for q in questions if q["answer"] is None and q["recommended"] == "retry"]
178
- return {q["id"]: q["recommended"] for q in asked if spent[q["ticket"]] < budget}
300
+ on fewer than `retries` stops of its ticket (or of the end of run). A `finding-must-fix` question counts only the
301
+ stops with one that the driver ruled, up to `retries + must_fix_retries`: that many fix batches run while a
302
+ critical or must-fix finding is open, whatever else stopped the end of run. No other option is the driver's to
303
+ take: a kind that recommends one still asks the operator."""
304
+ every = (ruled(questions), retries)
305
+ scopes = {MUST_FIX: (ruled([q for q in questions if q["kind"] == MUST_FIX]), retries + must_fix_retries)}
306
+ return {q["id"]: "retry" for q in questions if _due(q, *scopes.get(q["kind"], every))}
307
+
179
308
 
309
+ def _due(q: dict, spent: Counter, budget: int) -> bool:
310
+ """`q` is open, recommends `retry`, and the driver ruled on fewer than `budget` stops of its ticket, as `spent`
311
+ counts them."""
312
+ return q["answer"] is None and q["recommended"] == "retry" and spent[q["ticket"]] < budget
180
313
 
181
- def _answer(q: dict, answers: dict, by: str) -> str:
314
+
315
+ def _answer(q: dict, answers: dict, by: str, why: str) -> str:
182
316
  """Answer `q` from `answers` and return its ruling, with the note of the operator."""
183
317
  q["answer"], q["by"] = answers[q["id"]], by
184
- q["ruling"] = ruling(q) + " Ruled by the driver, not the operator." * (by == DRIVER)
318
+ q["ruling"] = ruling(q) + (f" Ruled by the {by}, not the operator{why}." if by else "")
185
319
  note = answers.get(f"{q['id']}.note")
186
320
  return q["ruling"] + f" Note of the operator: {note}" * bool(note)
187
321
 
188
322
 
189
- def apply(questions: list[dict], answers: dict, by: str = "") -> tuple[list[str], dict[str, dict]]:
190
- """Answer the open questions in `answers`; `by` is DRIVER for the answers of `automatic`. Returns (a ruling per
191
- answer, ticket or FINAL -> the fields that let its record go on)."""
323
+ def apply(questions: list[dict], answers: dict, by: str = "", why: dict[str, str] | None = None
324
+ ) -> tuple[list[str], dict[str, dict]]:
325
+ """Answer the open questions in `answers`; `by` is DRIVER for the answers of `automatic` and ARBITER for those of
326
+ the arbiter, whose `why` gives the end of the ruling sentence per question. Returns (a ruling per answer, ticket or
327
+ FINAL -> the fields that let its record go on)."""
192
328
  rulings, stops = [], {}
193
329
  for q in questions:
194
330
  if q["answer"] is None and q["id"] in answers:
195
- rulings.append(_answer(q, answers, by))
331
+ rulings.append(_answer(q, answers, by, (why or {}).get(q["id"], "")))
332
+ stops[q["ticket"]] = q["stop"]
333
+ return rulings, _moved(questions, stops)
334
+
335
+
336
+ def overturn(questions: list[dict], answers: dict) -> tuple[list[str], dict[str, dict]]:
337
+ """Overturn the rulings of the driver or the arbiter that `answers` names with the operator's answer: the new
338
+ ruling names the one it overturns and who took it. Returns what `apply` returns."""
339
+ rulings, stops = [], {}
340
+ for q in questions:
341
+ if q["id"] in answers:
342
+ was, q["overturned"] = q["answer"], q.pop("by")
343
+ q["answer"] = answers[q["id"]]
344
+ q["ruling"] = f"{ruling(q)} It overturns the ruling {was} of the {q['overturned']}."
345
+ rulings.append(q["ruling"])
196
346
  stops[q["ticket"]] = q["stop"]
197
347
  return rulings, _moved(questions, stops)
198
348
 
@@ -203,9 +353,32 @@ def _moved(questions: list[dict], stops: dict) -> dict[str, dict]:
203
353
  return {ticket: fields for ticket, fields in moved.items() if fields}
204
354
 
205
355
 
206
- def by_driver(questions: list[dict]) -> list[dict]:
207
- """The questions the driver answered itself."""
208
- return [q for q in questions if q.get("by") == DRIVER]
356
+ def ruled_by(q: dict) -> str:
357
+ """Who took the ruling `q` has now: DRIVER, ARBITER, or OPERATOR for an answer of the operator, an overturn
358
+ included, and for an open question."""
359
+ return q.get("by") or OPERATOR
360
+
361
+
362
+ def without_operator(questions: list[dict]) -> list[dict]:
363
+ """The questions the driver or its arbiter answered, with no operator."""
364
+ return [q for q in questions if ruled_by(q) != OPERATOR]
365
+
366
+
367
+ def overturned(questions: list[dict]) -> list[dict]:
368
+ """The questions whose ruling of the driver or the arbiter the operator overturned."""
369
+ return [q for q in questions if q.get("overturned")]
370
+
371
+
372
+ def arbitrated(questions: list[dict], budget: int) -> list[dict]:
373
+ """The open questions the arbiter rules on once the driver's retries are spent, of a `Kind.arbiter` kind (no
374
+ `finding-must-fix`): a ticket's only while the arbiter ruled on fewer than `budget` stops of it."""
375
+ spent = ruled(questions, ARBITER)
376
+ return [q for q in questions if q["answer"] is None and _arbiters(q, spent[q["ticket"]], budget)]
377
+
378
+
379
+ def _arbiters(q: dict, spent: int, budget: int) -> bool:
380
+ """Whether the arbiter rules on `q` when it ruled on `spent` stops of its ticket."""
381
+ return bool(KINDS[q["kind"]].arbiter) and (q["ticket"] == FINAL or spent < budget)
209
382
 
210
383
 
211
384
  def text(open_questions: list[dict], answers: str, page: str) -> str:
@@ -70,7 +70,7 @@ def ambiguous(run: Run, number: str, readings: list[Reading], resume: Resume) ->
70
70
  _ruling_findings(path, [(one.found, subject, f"correct the test to the second reading: {one.found.reason}")
71
71
  for one, subject in zip(readings, subjects)])
72
72
  subject = "; ".join(subjects)
73
- run.ask(number, "spec-ambiguous", [subject], str(path), resume)
73
+ run.ask(number, [("spec-ambiguous", subject)], str(path), resume)
74
74
  raise Blocked(f"the spec reads two ways on a locked test: {subject}")
75
75
 
76
76