@jesdi/skills 0.0.100 → 0.0.102

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 (89) hide show
  1. package/package.json +1 -1
  2. package/skills/babysit-pr/SKILL.md +9 -2
  3. package/skills/babysit-pr/babysit.py +98 -36
  4. package/skills/babysit-pr/exam.py +156 -0
  5. package/skills/babysit-pr/fixtures/exam_host.py +47 -0
  6. package/skills/babysit-pr/fixtures/gh +107 -11
  7. package/skills/babysit-pr/test_babysit.py +8 -2
  8. package/skills/babysit-pr/test_e2e_setup.py +1 -1
  9. package/skills/babysit-pr/test_exam_merge_gate.py +189 -0
  10. package/skills/babysit-pr/test_exam_request.py +337 -0
  11. package/skills/babysit-pr/test_exam_required_check.py +145 -0
  12. package/skills/babysit-pr/test_exam_wait.py +353 -0
  13. package/skills/babysit-pr/test_merge_and_handoff.py +12 -6
  14. package/skills/babysit-pr/test_trusted_merge_risk.py +2 -2
  15. package/skills/implement-spec/ARCHITECTURE.md +1 -1
  16. package/skills/implement-spec/README.md +6 -6
  17. package/skills/implement-spec/driver_final.py +24 -21
  18. package/skills/implement-spec/driver_final_gate.py +152 -17
  19. package/skills/implement-spec/driver_gate.py +12 -0
  20. package/skills/implement-spec/driver_pr.py +16 -7
  21. package/skills/implement-spec/driver_slots.py +28 -11
  22. package/skills/implement-spec/driver_state.py +3 -2
  23. package/skills/implement-spec/prompts/pr-body.md +1 -0
  24. package/skills/implement-spec/tests/test_final_gate.py +144 -0
  25. package/skills/implement-spec/tests/test_overturn.py +2 -2
  26. package/skills/implement-spec/tests/test_walk.py +1 -0
  27. package/skills/pr-exam/SKILL.md +131 -0
  28. package/skills/pr-exam/fixtures/README.md +20 -0
  29. package/skills/pr-exam/fixtures/delta-new-concept/body.md +9 -0
  30. package/skills/pr-exam/fixtures/delta-new-concept/diff.patch +82 -0
  31. package/skills/pr-exam/fixtures/delta-new-concept/exam.json +46 -0
  32. package/skills/pr-exam/fixtures/delta-new-concept/passed.diff +66 -0
  33. package/skills/pr-exam/fixtures/delta-new-concept/records/0001-single-sync-leader.md +10 -0
  34. package/skills/pr-exam/fixtures/delta-new-concept/records/0002-stale-leader-writes.md +10 -0
  35. package/skills/pr-exam/fixtures/delta-new-concept/records/0003-fencing-token.md +10 -0
  36. package/skills/pr-exam/fixtures/delta-new-concept/records/0004-lease-expiry.md +10 -0
  37. package/skills/pr-exam/fixtures/delta-new-concept/records/0005-injected-monotonic-clock.md +10 -0
  38. package/skills/pr-exam/fixtures/delta-new-concept/records/0006-leader-lifecycle.md +10 -0
  39. package/skills/pr-exam/fixtures/delta-new-concept/records/0007-lease-rollback.md +10 -0
  40. package/skills/pr-exam/fixtures/delta-new-concept/records/0008-sync-blast-radius.md +10 -0
  41. package/skills/pr-exam/fixtures/delta-new-concept/request.json +43 -0
  42. package/skills/pr-exam/fixtures/delta-nothing-new/body.md +9 -0
  43. package/skills/pr-exam/fixtures/delta-nothing-new/diff.patch +66 -0
  44. package/skills/pr-exam/fixtures/delta-nothing-new/exam.json +10 -0
  45. package/skills/pr-exam/fixtures/delta-nothing-new/passed.diff +66 -0
  46. package/skills/pr-exam/fixtures/delta-nothing-new/records/0001-single-sync-leader.md +10 -0
  47. package/skills/pr-exam/fixtures/delta-nothing-new/records/0002-stale-leader-writes.md +10 -0
  48. package/skills/pr-exam/fixtures/delta-nothing-new/records/0003-fencing-token.md +10 -0
  49. package/skills/pr-exam/fixtures/delta-nothing-new/records/0004-lease-expiry.md +10 -0
  50. package/skills/pr-exam/fixtures/delta-nothing-new/records/0005-injected-monotonic-clock.md +10 -0
  51. package/skills/pr-exam/fixtures/delta-nothing-new/records/0006-leader-lifecycle.md +10 -0
  52. package/skills/pr-exam/fixtures/delta-nothing-new/records/0007-lease-rollback.md +10 -0
  53. package/skills/pr-exam/fixtures/delta-nothing-new/records/0008-sync-blast-radius.md +10 -0
  54. package/skills/pr-exam/fixtures/delta-nothing-new/request.json +43 -0
  55. package/skills/pr-exam/fixtures/followup/body.md +9 -0
  56. package/skills/pr-exam/fixtures/followup/diff.patch +66 -0
  57. package/skills/pr-exam/fixtures/followup/exam.json +61 -0
  58. package/skills/pr-exam/fixtures/followup/records/0001-single-sync-leader.md +10 -0
  59. package/skills/pr-exam/fixtures/followup/records/0002-stale-leader-writes.md +10 -0
  60. package/skills/pr-exam/fixtures/followup/records/0003-fencing-token.md +10 -0
  61. package/skills/pr-exam/fixtures/followup/records/0004-lease-expiry.md +10 -0
  62. package/skills/pr-exam/fixtures/followup/records/0005-injected-monotonic-clock.md +10 -0
  63. package/skills/pr-exam/fixtures/followup/records/0006-lease-rollback.md +10 -0
  64. package/skills/pr-exam/fixtures/followup/records/0007-sync-blast-radius.md +10 -0
  65. package/skills/pr-exam/fixtures/followup/request.json +41 -0
  66. package/skills/pr-exam/fixtures/grading/answers.json +5 -0
  67. package/skills/pr-exam/fixtures/grading/attempt.json +10 -0
  68. package/skills/pr-exam/fixtures/grading/grades.json +14 -0
  69. package/skills/pr-exam/fixtures/grading/questions.json +26 -0
  70. package/skills/pr-exam/fixtures/grading/request.json +10 -0
  71. package/skills/pr-exam/fixtures/twelve-concepts/body.md +9 -0
  72. package/skills/pr-exam/fixtures/twelve-concepts/diff.patch +66 -0
  73. package/skills/pr-exam/fixtures/twelve-concepts/exam.json +195 -0
  74. package/skills/pr-exam/fixtures/twelve-concepts/request.json +15 -0
  75. package/skills/pr-exam/fixtures/typo-readme/body.md +1 -0
  76. package/skills/pr-exam/fixtures/typo-readme/diff.patch +7 -0
  77. package/skills/pr-exam/fixtures/typo-readme/exam.json +30 -0
  78. package/skills/pr-exam/fixtures/typo-readme/request.json +15 -0
  79. package/skills/pr-exam/pr_exam.py +705 -0
  80. package/skills/pr-exam/test_config.py +83 -0
  81. package/skills/pr-exam/test_exam_format.py +252 -0
  82. package/skills/pr-exam/test_followup_delta.py +90 -0
  83. package/skills/pr-exam/test_learning_records.py +267 -0
  84. package/skills/pr-exam/test_record_publication.py +45 -0
  85. package/skills/pr-exam/test_scoring.py +121 -0
  86. package/skills/pr-exam/test_served_shapes.py +38 -0
  87. package/skills/pr-exam/test_setup.py +349 -0
  88. package/skills/pr-exam/test_skill_fixtures.py +88 -0
  89. package/skills-manifest.json +11 -5
@@ -153,3 +153,147 @@ def test_gate_repair_preserves_locked_tests_and_escalates_a_needed_correction(tm
153
153
  assert rig.final()["gate_repairs"] == 0 and not rig.pushes()
154
154
  assert rig.branch() == rig.final()["tidied"]
155
155
  assert rig.state()["tickets"]["01"]["phase"] == "merged"
156
+
157
+
158
+ # ---------------------------------------------------------------- the base gate: only new failures count
159
+
160
+ OLD, NEW = 'FAILED tests/test_old.py::test_y - AssertionError', 'FAILED tests/test_01.py::test_z - KeyError'
161
+
162
+
163
+ def test_a_red_gate_with_only_the_failures_of_the_base_goes_on_to_review_and_a_draft_pr(tmp_path, monkeypatch):
164
+ import driver_final_gate
165
+ import driver_slots
166
+ from test_final import final
167
+ from test_review import finding
168
+
169
+ rig = Inside(tmp_path)
170
+ tips = ['feat(01): Export rows', 'fix(01): review fix']
171
+ rig.gate_conf(full={'subjects': ['spec', *tips]}, print={subject: [OLD] for subject in ['spec', *tips]})
172
+ steps = plan(**{'final/final-spec': [final(finding('A REVIEW FINDING'))],
173
+ 'final/fixer': [fixer('review\n', 'review fix', ticket_of='01')]})
174
+ slot_1 = []
175
+ base_gate = driver_final_gate._run_base_gate
176
+ seen = lambda: (driver_slots.head('.'), driver_slots.on_branch('.'), driver_slots.git('.', 'status', '-s').stdout)
177
+
178
+ def watched(*args):
179
+ before = seen()
180
+ kept = base_gate(*args)
181
+ slot_1.append(before == seen())
182
+ return kept
183
+
184
+ monkeypatch.setattr(driver_final_gate, '_run_base_gate', watched)
185
+ rig.run(steps, '--push')
186
+ assert rig.code == 0, rig.output()
187
+ assert slot_1 == [True], 'the base gate leaves slot 1 on its branch, at its tip, with its status'
188
+ onto = rig.final()['onto']
189
+ base = [gate for gate in rig.gates('full') if gate['commit'] == onto]
190
+ assert len(base) == 1, 'the base gate runs once for both red tips'
191
+ assert base[0]['cwd'].endswith('.agent/worktrees/slot-base')
192
+ assert len(rig.final_calls('fixer')) == 1, 'only the review fix: no gate repair'
193
+ assert "not this change's to fix" in rig.final_calls('final-spec')[0]['prompt']
194
+ assert rig.final()['reviewed'] == rig.branch()
195
+ assert rig.pushes() == [f'refs/heads/feat/csv {rig.branch()}']
196
+ (pr,) = rig.prs()
197
+ assert '--draft' in pr['argv'], 'a match of failure lines is no proof: the operator readies the PR'
198
+ old = f"final/base/gate-full-{onto[:7]}.log"
199
+ assert f'only with failures that its base {onto[:7]} is red with too' in pr['body'] and old in pr['body']
200
+ assert rig.led(f'red on {rig.branch()[:7]} only with failures that its base {onto[:7]} is red with too', old,
201
+ 'the PR opens as a draft')
202
+ assert rig.led('is open as a draft: the full gate is red on')
203
+
204
+
205
+ def test_a_failure_the_base_lacks_goes_to_the_repair_with_the_base_record(tmp_path):
206
+ rig = Inside(tmp_path)
207
+ rig.gate_conf(full={'subjects': ['spec', 'feat(01): Export rows']},
208
+ print={'spec': [OLD], 'feat(01): Export rows': [OLD, NEW]})
209
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
210
+ assert rig.code == 0, rig.output()
211
+ (repair,) = rig.final_calls('fixer')
212
+ assert f"final/base/gate-full-{rig.final()['onto'][:7]}.log" in repair['prompt']
213
+ assert '--draft' not in rig.prs()[0]['argv']
214
+
215
+
216
+ def test_a_red_tip_on_a_green_base_goes_to_the_repair(tmp_path):
217
+ rig = Inside(tmp_path)
218
+ rig.gate_conf(full={'subjects': ['feat(01): Export rows']}, print={'feat(01): Export rows': [OLD]})
219
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
220
+ assert rig.code == 0, rig.output()
221
+ (repair,) = rig.final_calls('fixer')
222
+ assert 'is red too' not in repair['prompt']
223
+ assert rig.led(f"the full gate is green on the base {rig.final()['onto'][:7]}")
224
+ assert not rig.final()['gate_preexisting'] and '--draft' not in rig.prs()[0]['argv']
225
+
226
+
227
+ def test_a_base_gate_that_cannot_run_counts_each_failure_as_new(tmp_path):
228
+ rig = Inside(tmp_path)
229
+ (rig.repo / '.agent/worktrees').mkdir(parents=True, exist_ok=True)
230
+ (rig.repo / '.agent/worktrees/slot-base').write_text('not a worktree\n')
231
+ rig.gate_conf(full={'subjects': ['spec', 'feat(01): Export rows']},
232
+ print={'spec': [OLD], 'feat(01): Export rows': [OLD]})
233
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
234
+ assert rig.code == 0, rig.output()
235
+ assert len(rig.final_calls('fixer')) == 1 and not rig.final()['gate_preexisting']
236
+ assert rig.led('the full gate cannot run on the base', 'so each failure counts as new')
237
+
238
+
239
+ def test_a_red_gate_with_no_failure_line_counts_as_new_and_runs_no_base_gate(tmp_path):
240
+ rig = Inside(tmp_path)
241
+ rig.gate_conf(full={'subjects': ['spec', 'feat(01): Export rows']})
242
+ rig.run(plan(**{'final/fixer': [fixer('fixed\n', 'repair integration', ticket_of='01')]}), '--push')
243
+ assert rig.code == 0, rig.output()
244
+ assert len(rig.final_calls('fixer')) == 1
245
+ assert not [gate for gate in rig.gates('full') if gate['commit'] == rig.final()['onto']]
246
+
247
+
248
+ def test_failures_are_the_failure_lines_of_the_output_with_times_line_numbers_and_counts_masked(tmp_path):
249
+ import driver_final_gate
250
+
251
+ def record(name, output, after='clean', end='exit: 1\nafter: {after}\nend: y\n'):
252
+ path = tmp_path / name
253
+ path.write_text(f'start: x\ntier: full\ncommit: abc\nstatus: clean\ncommand: make check\n\n{output}\n'
254
+ + end.format(after=after))
255
+ return str(path)
256
+
257
+ base = record('base', 'FAILED tests/a.py::test_1 - x\n== 1 failed, 40 passed in 2.31s ==\n'
258
+ 'src/a.ts:12:5 error no-x\nmake: *** [check] Error 1')
259
+ same = record('same', 'ok\nFAILED tests/a.py::test_1 - x\n== 1 failed, 52 passed in 3.1s ==\n'
260
+ 'src/a.ts:14:5 error no-x')
261
+ assert driver_final_gate.only_old(same, base), 'a wrapper line names no failure'
262
+ assert not driver_final_gate.only_old(record('new', 'FAILED tests/a.py::test_2 - x'), base)
263
+ assert not driver_final_gate.only_old(record('twice', 'src/a.ts:1:1 error no-x\nsrc/a.ts:2:1 error no-x'), base)
264
+ assert not driver_final_gate.only_old(record('none', 'Segmentation fault'), base)
265
+ assert not driver_final_gate.only_old(record('dirty', 'FAILED tests/a.py::test_1 - x', 'not clean'), base)
266
+ one = record('one', 'FAILED tests/a.py::test_limit[1] - x')
267
+ assert not driver_final_gate.only_old(record('two', 'FAILED tests/a.py::test_limit[2] - x'), one), \
268
+ 'a number in a test identifier is part of its name'
269
+ assert not driver_final_gate.only_old(record('fewer', 'FAILED tests/a.py::test_1 - x'), base), \
270
+ 'a new failure that no line names can hide behind the same lines: only the same failures are old'
271
+ wrapped = record('wrapped', 'make: *** [check] Error 1')
272
+ assert not driver_final_gate.only_old(wrapped, wrapped), 'a wrapper line alone proves nothing'
273
+ mocha = record('mocha', ' 2 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 2 (12ms)')
274
+ assert driver_final_gate.only_old(
275
+ record('mocha-2', ' 2 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 2 (40ms)'), mocha)
276
+ assert not driver_final_gate.only_old(
277
+ record('mocha-3', ' 2 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 3 (40ms)'), mocha)
278
+ assert not driver_final_gate.only_old(record('3-failing', ' 3 failing'), record('2-failing', ' 2 failing')), \
279
+ 'a count of failures stays'
280
+ titled = record('titled', ' 1 failing\n 1) Suite does x:\n AssertionError: expected 1 to equal 2')
281
+ assert not driver_final_gate.only_old(
282
+ record('retitled', ' 1 failing\n 1) Suite does y:\n AssertionError: expected 1 to equal 2'), titled), \
283
+ 'the title of a failed test names it'
284
+ for name, end in (('killed', 'exit: 137\nafter: clean\nend: y\n'), ('signal', 'exit: -9\nafter: clean\nend: y\n'),
285
+ ('segfault', 'exit: 139\nafter: clean\nend: y\n'), ('abort', 'exit: 134\nafter: clean\nend: y\n'),
286
+ ('cut', '')):
287
+ stopped = record(name, 'FAILED tests/a.py::test_1 - x', end=end)
288
+ assert not driver_final_gate.only_old(stopped, stopped), f'a {name} run judged nothing'
289
+ assert not driver_final_gate.only_old(same, stopped), f'a {name} base run judged nothing'
290
+
291
+
292
+ def test_read_gives_the_output_exit_and_after_of_a_gate_record(tmp_path):
293
+ import driver_gate
294
+
295
+ record = tmp_path / 'r.log'
296
+ record.write_text('start: x\ncommand: make\n\nline 1\n\nline 2\nexit: 2\nafter: not clean\n M a.py\nend: y\n')
297
+ assert driver_gate.read(record) == ('line 1\n\nline 2', 2, 'not clean\n M a.py')
298
+ record.write_text('start: x\ncommand: make\n\nline 1\n')
299
+ assert driver_gate.read(record) == ('line 1\n', '', '')
@@ -210,10 +210,10 @@ def test_an_overturn_that_takes_effect_is_not_refused(asked, pair, monkeypatch):
210
210
  ])
211
211
  def test_an_agent_s_ship_overturned_is_the_operator_s_ruling_and_drafts_no_pr(pair, draft):
212
212
  questions = [q("a", "accept", by="arbiter", resume={"phase": "final"})]
213
- final = {"open": [{"title": "s", "file": "f.py", "line": 1}], "ship": None}
213
+ final = {"open": [{"title": "s", "file": "f.py", "line": 1}], "ship": None, "gate_preexisting": None}
214
214
  if pair:
215
215
  driver_decisions.overturn(questions, dict([pair]))
216
- assert driver_pr._draft(final, questions, []) == draft
216
+ assert driver_pr._draft(final, questions, [], "tip") == draft
217
217
 
218
218
 
219
219
  def test_a_body_edit_that_fails_is_made_again_by_the_next_run(tmp_path):
@@ -112,6 +112,7 @@ rec = dict(t0=time.time(), tier=os.environ.get("TIER"), cwd=os.path.realpath(os.
112
112
  status=git("status", "--short"), base=os.environ.get("IMPLEMENT_SPEC_BASE"), locked=os.environ.get("IMPLEMENT_SPEC_LOCKED"),
113
113
  pycache=os.environ.get("PYTHONPYCACHEPREFIX"), exit=code)
114
114
  print("GATE-OUTPUT-MARK", rec["commit"])
115
+ print(*conf.get("print", {{}}).get(subject, []), sep="\\n") # the failure lines of a red gate, per subject of HEAD
115
116
  (rig / "gates" / f"{{time.time_ns()}}-{{os.getpid()}}.json").write_text(json.dumps(rec))
116
117
  sys.exit(code)
117
118
  """
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: pr-exam
3
+ description: >-
4
+ Deterministic rules for a PR exam: validate a generated exam.json against its
5
+ generation request, project the served (answer-free) exam, score an attempt,
6
+ read and write learning records, and validate a repo's .pr-exam.json. Use when
7
+ generating, serving or grading a PR exam, or when the user says "pr-exam".
8
+ ---
9
+
10
+ # pr-exam
11
+
12
+ Every exam rule lives in `pr_exam.py`, next to this file. Never re-implement one: run the script.
13
+ Each command reads files and prints JSON, or exits non-zero with every error on
14
+ stderr.
15
+
16
+ | Command | Does |
17
+ |---|---|
18
+ | `python3 pr_exam.py validate --request <request.json> <exam.json>` | Checks a generated exam against its request; prints its summary. |
19
+ | `python3 pr_exam.py public <exam.json>` | Prints the exam the page may show: no key, concepts or answers. |
20
+ | `python3 pr_exam.py score --exam <exam.json> --answers <answers.json> --grades <grades.json>` | Scores an attempt and names what was missed. |
21
+ | `python3 pr_exam.py learned --records <dir> --today <YYYY-MM-DD>` | Lists concepts known, due or wrong. |
22
+ | `python3 pr_exam.py record --records <dir> --exam <exam.json> --result <result.json> --today <YYYY-MM-DD>` | Writes learning records for a scored attempt. |
23
+ | `python3 pr_exam.py config [<.pr-exam.json>]` | Reads and validates the repo's exam config. |
24
+ | `python3 pr_exam.py setup [--check] <owner/repo>` | Run by the operator: makes `exam` a required check of the default branch. `--check` only reports whether it is one. |
25
+
26
+ ## Generating an exam
27
+
28
+ You get a generation request, a JSON file with these fields:
29
+
30
+ | Field | Holds |
31
+ |---|---|
32
+ | `mode` | `first`, `followup` or `delta`: see "Modes". |
33
+ | `repo`, `pr`, `head_sha` | The PR. Copy them into the exam unchanged. |
34
+ | `diff` | Path of the PR's diff. |
35
+ | `body` | Path of the PR's body. Its merge-risk block names the risks. |
36
+ | `glossary` | Path of the repo's `GLOSSARY.md`, or null. When set, use its terms in titles and prompts. |
37
+ | `records`, `today` | The learning-record directory and the date: the arguments of `learned`. |
38
+ | `only_concepts`, `prior_prompts` | `followup` only: the concepts to ask, and the prompts already asked. |
39
+ | `prior_concepts` | `delta` only: the concepts an earlier exam of this PR covered. |
40
+ | `passed_diff` | `delta` only, when present: path of the PR's diff as it was when the exam was passed. |
41
+ | `out` | Where to write `exam.json`. |
42
+
43
+ Write this shape to `out`. A question has no field other than the ones shown:
44
+
45
+ ```json
46
+ {
47
+ "version": 1,
48
+ "mode": "first",
49
+ "repo": "owner/name", "pr": 240, "head_sha": "<from the request>",
50
+ "concepts": [
51
+ {"id": "merge-lease", "title": "Merge lease", "kind": "why"},
52
+ {"id": "retry-budget", "title": "Retry budget", "kind": "concept"}
53
+ ],
54
+ "questions": [
55
+ {"id": "q1", "concept": "merge-lease", "type": "text", "prompt": "…"},
56
+ {"id": "q2", "concept": "retry-budget", "type": "choice", "prompt": "…", "options": ["…", "…"]}
57
+ ],
58
+ "key": {
59
+ "q1": {"rubric": {"pass": "…", "partial": "…"}, "explanation": "…", "hunk": "…"},
60
+ "q2": {"answer": 1, "explanation": "…", "hunk": "…"}
61
+ }
62
+ }
63
+ ```
64
+
65
+ 1. List every concept you find in `concepts`, asked or not. A concept `id` is a slug (lowercase
66
+ letters, digits, single hyphens). Its `kind` is one of these, highest priority first:
67
+ - `why`: the reason behind a decision;
68
+ - `concept`: a new concept or domain term;
69
+ - `architecture`: a change of structure or boundary;
70
+ - `risk`: a risky area, from the merge-risk block of the body;
71
+ - `behaviour`: behaviour a user can see.
72
+
73
+ Never list or ask implementation trivia: names, line counts, formatting, syntax.
74
+ 2. One question per concept, 8 at most. With more than 8 concepts, ask the 8 of the highest-priority
75
+ kinds and leave the others listed, unasked. A trivial PR (a typo, a rename, a comment) gets 1 question.
76
+ 3. Run `python3 pr_exam.py learned --records <records> --today <today>` and reuse the id of a concept
77
+ already listed there. `skip`: list it, do not ask it. `due`: ask it as `choice` only.
78
+ `misconception`: list it and ask it, unless the cap of 8 drops it.
79
+ 4. Type mix: `choice` (multiple choice) and `text` (free text). With 2 questions or more use both;
80
+ with 3 or more, at least one `text` question is on a `why` concept.
81
+ 5. A `choice` has at least 2 options with the same word count, no two equal, and nothing in the
82
+ formatting that hints at the answer. This is retrieval practice: ask what the reader must recall,
83
+ not what the diff shows.
84
+ 6. Write the key before any answer exists, one entry per question id. Every entry has an
85
+ `explanation` and a `hunk` copied verbatim from the diff. A `choice` entry has `answer` (an index
86
+ into `options`) and no rubric. A `text` entry has a `rubric` with `pass` and `partial`, saying
87
+ what a passing and a partial answer must contain, and no answer.
88
+ 7. Run `python3 pr_exam.py validate --request <request.json> <exam.json>` and fix every error it names,
89
+ then run it again. Finish only on exit 0.
90
+
91
+ ### Modes
92
+
93
+ - `first`: the rules above.
94
+ - `followup`: one new question per concept in `only_concepts`, and no other concept: `concepts` lists
95
+ exactly those. Do not repeat a prompt in `prior_prompts`: ask the concept from another angle. The
96
+ type mix of step 4 does not apply.
97
+ - `delta`: list and ask only concepts absent from `prior_concepts`: the ones the last push added.
98
+ Compare `diff` with `passed_diff` to find them. The type mix of step 4 does not apply. When
99
+ nothing is new, write an empty exam: zero questions, and `questions`, `concepts` and `key` empty.
100
+
101
+ ## Grading answers
102
+
103
+ One fresh session grades every `text` question of one attempt. You get a grading request, a JSON
104
+ file with these fields:
105
+
106
+ | Field | Holds |
107
+ |---|---|
108
+ | `mode` | `grade`. |
109
+ | `diff` | Path of the PR's diff. |
110
+ | `questions` | Path of a JSON list, one entry per `text` question: `{"id": "q1", "prompt": "…", "rubric": {"pass": "…", "partial": "…"}}`. |
111
+ | `answers` | Path of a JSON object: the answer to each of those questions, by question id. |
112
+ | `out` | Where to write `grades.json`. |
113
+
114
+ That is all you get: the diff, the questions, their rubrics and the answers, and
115
+ nothing else from generation. No key, no explanation, no earlier attempt.
116
+
117
+ 1. Judge each answer against its rubric only: `pass` when it contains what `rubric.pass` asks for,
118
+ `partial` when it contains only what `rubric.partial` asks for, `fail` otherwise. Read the diff
119
+ to check what an answer claims. Wording, length and confidence earn nothing.
120
+ 2. Write `grades.json` to `out`, one entry per question in `questions` and no other entry:
121
+ `{"q1": {"grade": "pass", "feedback": "…"}}`. `feedback` is one line of feedback: what the answer
122
+ got right or left out.
123
+ 3. Check the shape of what you wrote: an entry for every question id, each `grade` one of `pass`,
124
+ `partial`, `fail`, each `feedback` a one-line string. Then finish.
125
+
126
+ `choice` questions are never graded by the session, and you do not score the attempt: the host runs
127
+ `pr_exam.py score`, which marks them from the key and refuses a grade for one.
128
+
129
+ ## Never
130
+
131
+ Never apply a bypass label. Never post an `exam` status. The host decides both.
@@ -0,0 +1,20 @@
1
+ # Recorded runs of the `pr-exam` skill
2
+
3
+ Each directory holds the inputs and outputs of one headless session that followed `SKILL.md`, started
4
+ with the prompt the host uses (agent-ops `dispatcher/exam_runner.py`). One live run per mode:
5
+
6
+ - `typo-readme/`: `first`, on a typo-only README diff → `exam.json`, 1 question.
7
+ - `twelve-concepts/`: `first`, on a lease store with fencing tokens, a diff with 12 concepts → `exam.json`,
8
+ 8 questions; the 4 behaviour concepts are listed but dropped by priority.
9
+ - `grading/`: one session grading the three `text` answers of an attempt at the twelve-concept exam
10
+ (`request.json`, `questions.json`, `answers.json`) → `grades.json`. `attempt.json` holds every answer
11
+ of that attempt; `score` on it fails the attempt and names three missed concepts.
12
+ - `followup/`: `followup`, on those three concepts, with the learning records `record` wrote for the
13
+ failed attempt → `exam.json`, 3 new questions.
14
+ - `delta-new-concept/`: `delta`, after a pass: the push adds a retry budget (`diff.patch` against
15
+ `passed.diff`) → `exam.json`, 2 questions on concepts no earlier exam covered.
16
+ - `delta-nothing-new/`: `delta`, after a pass: the push only rewords a docstring and renames a
17
+ variable → an empty `exam.json`.
18
+
19
+ The requests are written as the host writes them, with paths made relative. Every generation run
20
+ finished on `validate` exit 0. `test_skill_fixtures.py` checks the outputs again.
@@ -0,0 +1,9 @@
1
+ Adds a lease so that only one worker runs the nightly sync at a time. Before this, two workers sometimes ran it at once and overwrote each other's results.
2
+
3
+ Why: a worker that stalls past its TTL must not keep writing after another worker took over, so every write carries a fencing token and the store refuses a stale one.
4
+
5
+ ```merge-risk v1
6
+ risk: medium
7
+ rollback: revert; leases expire after the TTL
8
+ blast-radius: the nightly sync only
9
+ ```
@@ -0,0 +1,82 @@
1
+ diff --git a/lease.py b/lease.py
2
+ new file mode 100644
3
+ --- /dev/null
4
+ +++ b/lease.py
5
+ @@ -0,0 +1,77 @@
6
+ +import time
7
+ +
8
+ +
9
+ +class LeaseLost(Exception):
10
+ + """The caller no longer owns the lease it tried to write under."""
11
+ +
12
+ +
13
+ +class LeaseStore:
14
+ + """Single-writer lease over a key-value store.
15
+ +
16
+ + Two workers can both believe they lead after a pause (GC, network). A
17
+ + fencing token lets the store reject the older leader's late writes.
18
+ + """
19
+ +
20
+ + def __init__(self, backend, ttl=30, clock=time.monotonic):
21
+ + self.backend = backend
22
+ + self.ttl = ttl
23
+ + self.clock = clock
24
+ +
25
+ + def acquire(self, name, owner):
26
+ + now = self.clock()
27
+ + held = self.backend.get(name)
28
+ + if held and held["expires"] > now and held["owner"] != owner:
29
+ + return None
30
+ + token = (held["token"] + 1) if held else 1
31
+ + self.backend.put(name, {"owner": owner, "token": token, "expires": now + self.ttl})
32
+ + return token
33
+ +
34
+ + def renew(self, name, owner, token):
35
+ + held = self.backend.get(name)
36
+ + if not held or held["owner"] != owner or held["token"] != token:
37
+ + raise LeaseLost(name)
38
+ + held["expires"] = self.clock() + self.ttl
39
+ + self.backend.put(name, held)
40
+ +
41
+ + def write(self, name, token, key, value):
42
+ + held = self.backend.get(name)
43
+ + if not held or held["token"] != token:
44
+ + raise LeaseLost(name)
45
+ + self.backend.put(key, value)
46
+ +
47
+ + def release(self, name, owner, token):
48
+ + held = self.backend.get(name)
49
+ + if held and held["owner"] == owner and held["token"] == token:
50
+ + held["expires"] = 0
51
+ + self.backend.put(name, held)
52
+ +
53
+ +
54
+ +def acquire_with_retry(store, name, owner, attempts=5, base_delay=0.5, sleep=time.sleep):
55
+ + """Take the lease within a retry budget, backing off between tries.
56
+ +
57
+ + A worker that starts while another one leads used to give up at once, so a
58
+ + leader that died left the sync unrun until the next night. Retrying forever
59
+ + would hammer the store instead. The budget bounds both: after `attempts`
60
+ + tries with doubling delays the caller skips this run.
61
+ + """
62
+ + for attempt in range(attempts):
63
+ + token = store.acquire(name, owner)
64
+ + if token is not None:
65
+ + return token
66
+ + sleep(base_delay * 2 ** attempt)
67
+ + return None
68
+ +
69
+ +
70
+ +def run_leader(store, name, owner, work, interval=10):
71
+ + token = acquire_with_retry(store, name, owner)
72
+ + if token is None:
73
+ + return False
74
+ + try:
75
+ + while work(token):
76
+ + store.renew(name, owner, token)
77
+ + time.sleep(interval)
78
+ + except LeaseLost:
79
+ + return False
80
+ + finally:
81
+ + store.release(name, owner, token)
82
+ + return True
@@ -0,0 +1,46 @@
1
+ {
2
+ "version": 1,
3
+ "mode": "delta",
4
+ "repo": "jesdi/general-skills",
5
+ "pr": 240,
6
+ "head_sha": "cccccccccccccccccccccccccccccccccccccccc",
7
+ "concepts": [
8
+ {"id": "retry-budget", "title": "Retry budget for taking the lease", "kind": "why"},
9
+ {"id": "exponential-backoff", "title": "Exponential backoff between acquire attempts", "kind": "concept"}
10
+ ],
11
+ "questions": [
12
+ {
13
+ "id": "q1",
14
+ "concept": "retry-budget",
15
+ "type": "text",
16
+ "prompt": "A worker that finds the lease held now retries within a bounded budget instead of trying once. Why is one attempt not enough, why is retrying without limit not acceptable either, and what does the worker do when the budget runs out?"
17
+ },
18
+ {
19
+ "id": "q2",
20
+ "concept": "exponential-backoff",
21
+ "type": "choice",
22
+ "prompt": "While a worker keeps failing to take the lease, how does the wait between its attempts change?",
23
+ "options": [
24
+ "It stays the same throughout",
25
+ "It grows by fixed steps",
26
+ "It doubles after each failure",
27
+ "It shrinks after each failure"
28
+ ]
29
+ }
30
+ ],
31
+ "key": {
32
+ "q1": {
33
+ "rubric": {
34
+ "pass": "Names both failure modes the budget bounds: (1) giving up after a single attempt means that if the current leader dies, nobody takes over and the sync stays unrun until the next night; (2) retrying forever would hammer the store. Also says that once the budget is exhausted the worker skips this run (does not lead, returns without syncing).",
35
+ "partial": "Names only one of the two failure modes (the sync left unrun after a leader dies, or the store being hammered by endless retries), or names both but does not say that the worker skips the run when the budget is exhausted."
36
+ },
37
+ "explanation": "With a single attempt, a worker that starts while another leads gives up at once, so a leader that later dies leaves the sync unrun until the next night. Unlimited retries would hammer the store. The budget bounds both: after a fixed number of tries the worker gets no token and skips this run.",
38
+ "hunk": "+ A worker that starts while another one leads used to give up at once, so a\n+ leader that died left the sync unrun until the next night. Retrying forever\n+ would hammer the store instead. The budget bounds both: after `attempts`\n+ tries with doubling delays the caller skips this run."
39
+ },
40
+ "q2": {
41
+ "answer": 2,
42
+ "explanation": "The delay is the base delay times two to the power of the attempt number, so it doubles after every failed attempt: exponential backoff, which eases the load on the store the longer the lease stays held.",
43
+ "hunk": "+ sleep(base_delay * 2 ** attempt)"
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,66 @@
1
+ diff --git a/lease.py b/lease.py
2
+ new file mode 100644
3
+ --- /dev/null
4
+ +++ b/lease.py
5
+ @@ -0,0 +1,61 @@
6
+ +import time
7
+ +
8
+ +
9
+ +class LeaseLost(Exception):
10
+ + """The caller no longer owns the lease it tried to write under."""
11
+ +
12
+ +
13
+ +class LeaseStore:
14
+ + """Single-writer lease over a key-value store.
15
+ +
16
+ + Two workers can both believe they lead after a pause (GC, network). A
17
+ + fencing token lets the store reject the older leader's late writes.
18
+ + """
19
+ +
20
+ + def __init__(self, backend, ttl=30, clock=time.monotonic):
21
+ + self.backend = backend
22
+ + self.ttl = ttl
23
+ + self.clock = clock
24
+ +
25
+ + def acquire(self, name, owner):
26
+ + now = self.clock()
27
+ + held = self.backend.get(name)
28
+ + if held and held["expires"] > now and held["owner"] != owner:
29
+ + return None
30
+ + token = (held["token"] + 1) if held else 1
31
+ + self.backend.put(name, {"owner": owner, "token": token, "expires": now + self.ttl})
32
+ + return token
33
+ +
34
+ + def renew(self, name, owner, token):
35
+ + held = self.backend.get(name)
36
+ + if not held or held["owner"] != owner or held["token"] != token:
37
+ + raise LeaseLost(name)
38
+ + held["expires"] = self.clock() + self.ttl
39
+ + self.backend.put(name, held)
40
+ +
41
+ + def write(self, name, token, key, value):
42
+ + held = self.backend.get(name)
43
+ + if not held or held["token"] != token:
44
+ + raise LeaseLost(name)
45
+ + self.backend.put(key, value)
46
+ +
47
+ + def release(self, name, owner, token):
48
+ + held = self.backend.get(name)
49
+ + if held and held["owner"] == owner and held["token"] == token:
50
+ + held["expires"] = 0
51
+ + self.backend.put(name, held)
52
+ +
53
+ +
54
+ +def run_leader(store, name, owner, work, interval=10):
55
+ + token = store.acquire(name, owner)
56
+ + if token is None:
57
+ + return False
58
+ + try:
59
+ + while work(token):
60
+ + store.renew(name, owner, token)
61
+ + time.sleep(interval)
62
+ + except LeaseLost:
63
+ + return False
64
+ + finally:
65
+ + store.release(name, owner, token)
66
+ + return True
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: single-sync-leader
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # single-sync-leader
9
+
10
+ Before the lease, two workers sometimes ran the nightly sync at the same time and overwrote each other's results; the lease makes one worker the single writer.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: stale-leader-writes
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # stale-leader-writes
9
+
10
+ After a pause (GC, network) both workers can believe they lead. Every write carries the fencing token from acquire, and write raises LeaseLost when the stored token differs, so the stale leader's late writes are refused.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: fencing-token
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # fencing-token
9
+
10
+ acquire stores the previous token plus one, so the newest holder always has the highest token and any older token no longer matches.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: lease-expiry
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # lease-expiry
9
+
10
+ acquire refuses only while the lease has not expired and belongs to someone else; renew pushes expires forward, so a holder that stops renewing loses the lease after the TTL.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: injected-monotonic-clock
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # injected-monotonic-clock
9
+
10
+ The clock defaults to time.monotonic, which never jumps with wall-clock changes, and injecting it lets tests advance time without sleeping.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: leader-lifecycle
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # leader-lifecycle
9
+
10
+ run_leader renews the lease after every unit of work, stops with False when renew raises LeaseLost, and releases the lease in a finally block so it is freed whatever happens.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: lease-rollback
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # lease-rollback
9
+
10
+ The merge-risk block gives the rollback as a revert, safe because leases expire after the TTL: no lease outlives the code that renews it.
@@ -0,0 +1,10 @@
1
+ ---
2
+ concept: sync-blast-radius
3
+ state: demonstrated
4
+ date: 2026-11-18
5
+ source: jesdi/general-skills#240
6
+ status: active
7
+ ---
8
+ # sync-blast-radius
9
+
10
+ The merge-risk block limits the blast radius to the nightly sync: only it runs under run_leader.