@giamme/forge 0.12.0 → 0.13.0

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 (117) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +31 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +18 -6
  7. package/docs/commands.md +189 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +34 -4
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +81 -19
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +40 -14
  17. package/references/decision-models.md +759 -0
  18. package/references/decompose.md +197 -28
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/references/ui.md +11 -0
  23. package/scripts/forge-artifact.sh +30 -4
  24. package/scripts/forge-config.py +238 -29
  25. package/scripts/forge-contract.py +127 -58
  26. package/scripts/forge-control.py +40 -9
  27. package/scripts/forge-decide.py +6 -0
  28. package/scripts/forge-dispatch.sh +47 -15
  29. package/scripts/forge-fail-first.py +2 -2
  30. package/scripts/forge-gate-addressed.sh +40 -0
  31. package/scripts/forge-gate-message.sh +64 -0
  32. package/scripts/forge-issues.py +368 -36
  33. package/scripts/forge-jev-options.sh +269 -42
  34. package/scripts/forge-lib-attribute.sh +447 -0
  35. package/scripts/forge-lib-gates.sh +32 -0
  36. package/scripts/forge-lib-plans.sh +17 -6
  37. package/scripts/forge-lib-review.sh +24 -19
  38. package/scripts/forge-lib-task.sh +219 -39
  39. package/scripts/forge-lib-verify.sh +45 -8
  40. package/scripts/forge-memory.sh +3 -3
  41. package/scripts/forge-parallel-options.sh +44 -5
  42. package/scripts/forge-parallel.sh +503 -304
  43. package/scripts/forge-plan-check.py +35 -1
  44. package/scripts/forge-pre-review.py +437 -0
  45. package/scripts/forge-prompt.py +25 -5
  46. package/scripts/forge-route.py +2 -2
  47. package/scripts/forge-runtime.py +55 -1
  48. package/scripts/forge-schedule.py +70 -9
  49. package/scripts/forge-shadow.py +2 -2
  50. package/scripts/forge-solo.sh +41 -10
  51. package/scripts/forge-submodules.py +389 -0
  52. package/scripts/forge-sweep.py +542 -0
  53. package/scripts/forge_dataset/cli.py +12 -6
  54. package/scripts/forge_dataset/export.py +55 -45
  55. package/scripts/forge_dataset/forecast.py +4 -1
  56. package/scripts/forge_dataset/harvest.py +33 -5
  57. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  58. package/scripts/forge_decide/__init__.py +141 -0
  59. package/scripts/forge_decide/budget.py +149 -0
  60. package/scripts/forge_decide/cache.py +66 -0
  61. package/scripts/forge_decide/cli.py +953 -0
  62. package/scripts/forge_decide/doctor.py +221 -0
  63. package/scripts/forge_decide/label_addressed.py +75 -0
  64. package/scripts/forge_decide/label_attribution.py +62 -0
  65. package/scripts/forge_decide/label_coverage.py +81 -0
  66. package/scripts/forge_decide/label_message.py +38 -0
  67. package/scripts/forge_decide/label_prompt.py +139 -0
  68. package/scripts/forge_decide/labels.py +328 -0
  69. package/scripts/forge_decide/metrics.py +125 -0
  70. package/scripts/forge_decide/migrate.py +226 -0
  71. package/scripts/forge_decide/providers.py +292 -0
  72. package/scripts/forge_decide/replay.py +350 -0
  73. package/scripts/forge_decide/report.py +382 -0
  74. package/scripts/forge_decide/resolve.py +397 -0
  75. package/scripts/forge_decide/sites.py +377 -0
  76. package/scripts/forge_jev/__init__.py +202 -104
  77. package/scripts/forge_jev/addressed.py +171 -0
  78. package/scripts/forge_jev/attribution.py +198 -0
  79. package/scripts/forge_jev/cli.py +460 -382
  80. package/scripts/forge_jev/client.py +155 -77
  81. package/scripts/forge_jev/coupling.py +19 -87
  82. package/scripts/forge_jev/coverage.py +303 -0
  83. package/scripts/forge_jev/findings.py +219 -0
  84. package/scripts/forge_jev/gates.py +225 -27
  85. package/scripts/forge_jev/memory.py +65 -4
  86. package/scripts/forge_jev/message.py +134 -0
  87. package/scripts/forge_jev/plan_gates.py +294 -0
  88. package/scripts/forge_jev/questions.py +173 -313
  89. package/scripts/forge_jev/verify.py +130 -104
  90. package/ui/README.md +41 -10
  91. package/ui/docs/api.md +212 -44
  92. package/ui/forge_ui/checks.py +331 -0
  93. package/ui/forge_ui/control.py +60 -11
  94. package/ui/forge_ui/export.py +8 -3
  95. package/ui/forge_ui/models.py +1 -0
  96. package/ui/forge_ui/reader.py +436 -26
  97. package/ui/forge_ui/server.py +13 -0
  98. package/ui/forge_ui/static/app.js +15 -8
  99. package/ui/forge_ui/static/checksview.js +449 -0
  100. package/ui/forge_ui/static/controls.js +20 -13
  101. package/ui/forge_ui/static/convo.js +11 -2
  102. package/ui/forge_ui/static/findingsview.js +6 -4
  103. package/ui/forge_ui/static/index.html +1 -0
  104. package/ui/forge_ui/static/panel.js +105 -17
  105. package/ui/forge_ui/static/runmodel.js +40 -2
  106. package/ui/forge_ui/static/scene3d.js +2 -15
  107. package/ui/forge_ui/static/settings.js +336 -41
  108. package/ui/forge_ui/static/style.css +72 -7
  109. package/ui/forge_ui/transcripts.py +225 -54
  110. package/references/jev.md +0 -865
  111. package/scripts/forge_jev/backtest.py +0 -322
  112. package/scripts/forge_jev/corpus.py +0 -156
  113. package/scripts/forge_jev/features.py +0 -24
  114. package/scripts/forge_jev/predict.py +0 -204
  115. package/scripts/forge_jev/review.py +0 -73
  116. package/scripts/forge_jev/routing.py +0 -271
  117. package/scripts/forge_jev/subset.py +0 -123
@@ -3,7 +3,7 @@
3
3
  Every rubric Jev is ever asked lives in this one file, not scattered at each call site.
4
4
  That is deliberate: a human auditing what gets sent to an external API, and what
5
5
  probability threshold decides anything, should be able to read one file top to bottom
6
- instead of hunting through backtest.py, client.py and cli.py for scattered prompts.
6
+ instead of hunting through client.py and cli.py for scattered prompts.
7
7
  """
8
8
  from __future__ import annotations
9
9
 
@@ -33,48 +33,6 @@ PROBE_STATE = 'yes'
33
33
  PROBE = {'probe': Noul('Is the state the word "yes"?')}
34
34
 
35
35
 
36
- def test_relevance(test_path: str, header: str = '') -> dict:
37
- """Could this test plausibly be broken by the change under review?
38
-
39
- Asked once per candidate test, with the task description and the changed source
40
- files supplied as state. Used both by backtest (scored against which tests a human
41
- actually touched in the same commit) and, eventually, by live test selection.
42
-
43
- The true/false split is deliberately asymmetric: a missed test is a missed
44
- regression (the change ships broken and nobody notices until later), while an
45
- extra test only costs a few seconds of runtime. So "true" is written to capture
46
- genuine uncertainty, not just confident matches — a test that touches the same
47
- module, calls the same function, or exercises adjacent behavior should land on the
48
- "true" side even without a slam-dunk import-graph connection. Calibration should
49
- reflect that a borderline-relevant test is still worth running.
50
- """
51
- instructions = (
52
- 'A change is being made to a codebase. Given the task description and the '
53
- f'source files it changed (in state), could the test at {test_path!r} '
54
- 'plausibly be broken by that change?'
55
- )
56
- if header:
57
- instructions += f'\n\nFirst lines of that test file:\n{header}'
58
- return Noul(
59
- instructions,
60
- true=(
61
- 'The test exercises the same module, function, class, route, or behavior '
62
- 'that the change touches, directly or through a dependency; the test name '
63
- 'or file path names the same feature area as the change; or the '
64
- 'relationship is genuinely uncertain rather than clearly absent. Missing a '
65
- 'test that should have run is a missed regression, so borderline cases '
66
- 'belong here.'
67
- ),
68
- false=(
69
- 'The test exercises an unrelated module, feature, or layer with no '
70
- 'plausible dependency on the changed files — for example a test for the '
71
- 'CLI when only a database migration changed, or a test fixture that is '
72
- 'unaffected by the change. Only mark false when the lack of relevance is '
73
- 'clear, since an unnecessary extra test only costs runtime.'
74
- ),
75
- )
76
-
77
-
78
36
  def verify_selection(candidates: list[str]) -> dict:
79
37
  """Which existing command, if any, actually verifies this repo by running its tests?
80
38
 
@@ -154,50 +112,6 @@ def verify_runtime(command: str) -> dict:
154
112
  return Score(instructions, criteria)
155
113
 
156
114
 
157
- def failure_triage(traps: list[str]) -> dict:
158
- """Why did verification fail: a real regression, a known flake, environment, or drift?
159
-
160
- Asked once per verification failure. Getting this wrong ships a regression, so
161
- 'real_regression' is written as the default reading and 'known_flake' is written to
162
- require positive evidence -- a named trap, or an error signature characteristic of
163
- flakiness (timeout, ordering, port in use, a race) -- never just "it failed and a
164
- rerun might pass."
165
- """
166
- named = '; '.join(traps) if traps else '(none recorded)'
167
- instructions = (
168
- 'Verification just failed. Given the command that was run, the tail of its '
169
- f'output, and this repo\'s known traps (in state -- recorded traps: {named}), '
170
- 'classify why it failed.'
171
- )
172
- criteria = {
173
- 'real_regression': (
174
- 'DEFAULT reading. The failure looks like the change under test actually '
175
- 'broke something: a specific assertion, a new error, or a changed output '
176
- 'tied to the kind of change being verified. Pick this whenever the failure '
177
- 'is not clearly explained by one of the other options -- an ambiguous '
178
- 'failure is a regression until proven otherwise.'
179
- ),
180
- 'known_flake': (
181
- 'Requires positive evidence, not just an unwanted failure: the failing test '
182
- 'or command is named among the recorded traps above, OR the error signature '
183
- 'is characteristic of flakiness with no link to the change under test -- a '
184
- 'timeout, a test-ordering or isolation failure, "address already in use" / '
185
- 'port in use, or an evident race condition.'
186
- ),
187
- 'environment': (
188
- 'The failure is about the environment, not the code or a flaky test: a '
189
- 'missing binary, dependency, credential, network resource, or a disk or '
190
- 'permission error unrelated to test logic.'
191
- ),
192
- 'generated_drift': (
193
- 'The failure is a diff against a generated or derived artifact (a lockfile, '
194
- 'a snapshot, generated bindings or code) that is expected to regenerate, not '
195
- 'a behavioral failure.'
196
- ),
197
- }
198
- return Choice(instructions, criteria)
199
-
200
-
201
115
  def drift_prediction(file_path: str) -> dict:
202
116
  """Is this file likely to need editing to complete the described task?
203
117
 
@@ -234,110 +148,11 @@ def drift_prediction(file_path: str) -> dict:
234
148
  ),
235
149
  )
236
150
 
237
- # --- routing (Phase 3 rubrics, recorded in shadow mode before they decide anything) ---
238
- #
239
- # Five Scores rather than one Choice asking for the tier directly. Two reasons. First,
240
- # `decompose.md` already defines difficulty as a conjunction of distinct properties
241
- # ("design judgment ... cross-cutting ... subtle edge cases or state/concurrency ... the
242
- # right approach is not obvious"), and asking about each separately is what lets code,
243
- # not the model, decide how to weigh them. Second, the composite is then computed here,
244
- # so re-tuning weights against accrued outcomes costs nothing -- no re-inference.
245
- #
246
- # The levels below are quoted from decompose.md's difficulty table wherever it says the
247
- # same thing, so that the rubric and the human-facing spec cannot drift apart.
248
-
249
-
250
- def design_judgment() -> dict:
251
- """How much design judgment does this task demand? (decompose.md's primary axis.)"""
252
- instructions = (
253
- 'Given the task and its context (in state), how much design judgment does '
254
- 'carrying it out demand? Rate what the task demands of whoever does it, NOT how '
255
- 'much code it produces: a five-hundred-line mechanical rename demands little, a '
256
- 'ten-line concurrency fix demands a lot.'
257
- )
258
- return Score(instructions, [
259
- 'none -- mechanical and local: a rename, a move, a docs edit, or a test for '
260
- 'behaviour that already exists. A mistake would be obvious.',
261
- 'some -- a self-contained implementation against a clear spec. A few choices to '
262
- 'make, all of them local and reversible.',
263
- 'substantial -- several defensible approaches exist and the choice between them '
264
- 'changes the shape of the result.',
265
- 'the approach must be invented -- the right way to do this is not obvious from '
266
- 'the goal, and getting it wrong means the work is wasted rather than merely '
267
- 'imperfect.',
268
- ])
269
-
270
-
271
- def blast_radius() -> dict:
272
- """How far can a mistake in this task reach?"""
273
- instructions = (
274
- 'If this task were done wrong, how far would the damage reach through the rest '
275
- 'of the codebase (state describes the repo and the files the task declares)?'
276
- )
277
- return Score(instructions, [
278
- 'local -- confined to the lines the task edits; nothing else observes the change.',
279
- 'one module -- other code in the same module or package is affected, but the '
280
- 'boundary holds.',
281
- 'cross-module -- behaviour other parts of the project depend on changes, so a '
282
- 'mistake surfaces somewhere the task never touched.',
283
- 'a public contract -- an API, schema, wire format, CLI surface or file format '
284
- 'that callers outside this repo, or already-stored data, depend on.',
285
- ])
286
-
287
-
288
- def state_subtlety() -> dict:
289
- """Concurrency and state -- called out by name in decompose.md's `high` row."""
290
- instructions = (
291
- 'How much subtle state or concurrency does this task involve? decompose.md '
292
- 'names this on its own because it is the property most often underrated: a very '
293
- 'small diff can still be the hardest kind of change.'
294
- )
295
- return Score(instructions, [
296
- 'none -- pure or straight-line code; no shared state, no ordering, no time.',
297
- 'sequential state -- state is read and written, but in one place, in a '
298
- 'predictable order, by one caller at a time.',
299
- 'shared or asynchronous state -- concurrency, locks, retries, caching, '
300
- 'cross-process coordination, or ordering that is not obvious from reading the '
301
- 'code, where a wrong interleaving produces a bug that does not reproduce.',
302
- ])
303
-
304
-
305
- def spec_clarity() -> dict:
306
- """Is the approach given, or must it be worked out? Note the inverted direction."""
307
- instructions = (
308
- 'How clearly does the task (and its approach.md, if state carries one) state '
309
- 'HOW the work should be done, as opposed to only what outcome is wanted?'
310
- )
311
- return Score(instructions, [
312
- 'the approach is stated -- the task says which files change and what to do in '
313
- 'them; carrying it out is following instructions.',
314
- 'the approach is implied -- the outcome is clear and there is an obvious way to '
315
- 'reach it, but nobody has written it down.',
316
- 'the approach must be invented -- the task states a goal and leaves the means '
317
- 'open, so the first real work is deciding what to build.',
318
- ])
319
-
320
-
321
- def test_coverage() -> dict:
322
- """Would a mistake here be caught? Coverage is why a wrong `low` is survivable."""
323
- instructions = (
324
- 'How well is the behaviour this task touches already covered by tests in this '
325
- 'repo (state lists the repo\'s files and the files the task declares)?'
326
- )
327
- return Score(instructions, [
328
- 'none -- nothing exercises this behaviour; a regression ships silently.',
329
- 'partial -- some tests touch the area, but not the specific behaviour being '
330
- 'changed.',
331
- 'well covered -- the behaviour has direct tests that would fail on a mistake.',
332
- ])
333
-
334
151
  # --- pre-dispatch gates (Phase 4) --------------------------------------------------
335
152
  #
336
- # These ride in the SAME request as the routing rubrics. The state a gate needs -- goal,
337
- # task, declared files, approach -- is exactly the state routing already sends, and
338
- # questions in one request evaluate in parallel, so asking them costs no extra round
339
- # trip. They warn and never block: a gate that can stop a dispatch is a gate that will
340
- # eventually stop a good one.
153
+ # Asked by `score-plan` before a plan's table is printed (gates.prompt_adequacy, site
154
+ # jev-prompt). They warn and never block: a gate that can stop a dispatch is a gate that
155
+ # will eventually stop a good one.
341
156
 
342
157
 
343
158
  def prompt_adequacy() -> dict:
@@ -371,70 +186,14 @@ def prompt_adequacy() -> dict:
371
186
  )
372
187
 
373
188
 
374
- def independently_verifiable() -> dict:
375
- """decompose.md's hard rule, checked: can this task be verified on its own?"""
376
- instructions = (
377
- 'Forge runs this task in its own worktree and verifies it alone, before any '
378
- 'other task in the plan is merged. state.plan_tasks lists the other tasks in '
379
- 'the plan with their file scopes; state.task.deps names the ones that are '
380
- 'guaranteed to land BEFORE this one. Judge against that list, not against '
381
- 'imagined work: can this task be verified on its own?'
382
- )
383
- return Noul(
384
- instructions,
385
- true=(
386
- 'Something observable proves this task once it is done -- a test that can '
387
- 'run, a command that behaves differently, a check that passes -- using only '
388
- 'this task\'s own files, what already exists in the repo, and anything '
389
- 'named in state.task.deps. A task that needs nothing from plan_tasks is '
390
- 'verifiable; so is one whose only needs are already its declared deps.'
391
- ),
392
- false=(
393
- 'Verifying this task requires a specific OTHER task in state.plan_tasks '
394
- 'that is not among its declared deps -- name it to yourself before '
395
- 'answering. This is the fragment case: one half of a rename, a caller whose '
396
- 'callee is a sibling task, an interface whose only implementation is a '
397
- 'sibling task. decompose.md forbids splitting this finely for exactly this '
398
- 'reason. Do not answer false merely because the task is small, or because '
399
- 'its value is only visible once the whole plan lands.'
400
- ),
401
- )
402
-
403
- # --- post-review annotation (Phase 4, items 5 and 6) -------------------------------
189
+ # --- post-review annotation (Phase 4, item 6) -------------------------------
404
190
  #
405
- # These read a FAIL and say whether it looks sound. They NEVER overturn it. Forge's
191
+ # This reads a FAIL and says whether the review is grounded. It NEVER overturns it. Forge's
406
192
  # second invariant is reviewer independence: a model that can talk another model out of
407
193
  # a FAIL is worth less than no reviewer at all, because it produces confident PASSes on
408
194
  # code nobody checked. So the only output here is an annotation a human reads.
409
195
 
410
196
 
411
- def failure_is_correctness() -> dict:
412
- """Does this FAIL rest on a correctness bug, or on taste?
413
-
414
- The QA prompt is explicit that "style nits are not failures", and a reviewer that
415
- fails a diff over naming or structure costs a whole retry cycle for nothing.
416
- """
417
- instructions = (
418
- 'A reviewer failed a code change. Given the review text and the diff it '
419
- 'reviewed (in state), does the review identify at least one genuine correctness '
420
- 'problem -- behaviour that is wrong, an edge case that breaks, a requirement not '
421
- 'met -- as opposed to only preferences about how the code is written?'
422
- )
423
- return Noul(
424
- instructions,
425
- true=(
426
- 'At least one finding describes something that would produce a wrong result, '
427
- 'a crash, data loss, a security hole, or a plain failure to do what the task '
428
- 'asked. It would still be a bug if the code were formatted perfectly.'
429
- ),
430
- false=(
431
- 'Every finding is about style, naming, structure, duplication, comments, '
432
- 'idiom, or a preference for a different approach that would work no better. '
433
- 'A reader could apply none of them and the code would still behave correctly.'
434
- ),
435
- )
436
-
437
-
438
197
  def findings_cite_the_diff() -> dict:
439
198
  """Citation check: is the review talking about code that is actually there?
440
199
 
@@ -461,14 +220,13 @@ def findings_cite_the_diff() -> dict:
461
220
  ),
462
221
  )
463
222
 
464
- # --- semantic wave coupling (Phase 4, item 4) --------------------------------------
223
+ # --- forward dependency (Phase 4, item 4) --------------------------------------
465
224
 
466
225
 
467
226
  def forward_dependency(earlier: str, later: str) -> dict:
468
227
  """Is an earlier-wave task written against something a LATER task has not built yet?
469
228
 
470
- Distinct from wave_coupling, which asks about two tasks running at the same time and
471
- breaking on merge. This asks about ordering: a task that runs in wave 1 is reviewed,
229
+ This asks about ordering: a task that runs in wave 1 is reviewed,
472
230
  verified and merged before wave 2 exists, so if it was written against wave 2's work
473
231
  it is wrong at the moment anyone checks it -- and its own review cannot tell, because
474
232
  the thing it is wrong about is not in the tree yet.
@@ -500,38 +258,6 @@ def forward_dependency(earlier: str, later: str) -> dict:
500
258
  )
501
259
 
502
260
 
503
- def wave_coupling(first: str, second: str) -> dict:
504
- """Would running these two tasks concurrently produce an integration conflict?
505
-
506
- `compute_waves` bounds parallelism structurally: two tasks share a wave only when
507
- their file sets are disjoint. Disjointness cannot see the conflict where task A
508
- changes an interface that task B consumes -- both diffs are clean, both pass review
509
- against their own baseline, and the merge is broken. This asks about exactly that.
510
- """
511
- instructions = (
512
- f'Two Forge tasks are about to run at the same time, in separate worktrees '
513
- f'branched from the same commit, each reviewed only against its own baseline. '
514
- f'Task A: {first!r}. Task B: {second!r}. Their declared files do not overlap. '
515
- 'Would running them concurrently still produce a broken result once both are '
516
- 'merged?'
517
- )
518
- return Noul(
519
- instructions,
520
- true=(
521
- 'One task changes something the other depends on -- a function signature, a '
522
- 'return type, a schema, a config key, an interface, a shared constant -- so '
523
- 'the second task is written against a version of the code that will no '
524
- 'longer exist. Both diffs can be individually correct and the merge still '
525
- 'broken.'
526
- ),
527
- false=(
528
- 'The two tasks touch genuinely independent behaviour. Neither one changes '
529
- 'anything the other reads, calls, or relies on, so the order they land in '
530
- 'does not matter.'
531
- ),
532
- )
533
-
534
-
535
261
  # --- memory curation (Phase 5, items 1-3) ------------------------------------------
536
262
  #
537
263
  # The stakes here are asymmetric and worth stating. memory.md is injected into EVERY
@@ -628,34 +354,168 @@ def memory_relevant(text: str, task: str) -> dict:
628
354
  'does here should be left out.',
629
355
  )
630
356
 
631
- # --- outcome rubrics: asked live by the clef-first-pass and clef-retry-pass sites, and by
632
- # the export on rebuilt states (forge_jev/outcome.py builds both). Text is frozen: it is
633
- # part of every exported case's body and of what Clef was measured answering.
634
-
635
- def first_pass() -> dict:
636
- return dict(type='noul', instructions=(
637
- 'This Forge task is dispatched to the model in state.dwarf, at the effort shown, in its '
638
- 'own worktree. An independent model (state.reviewer) then reviews the resulting diff '
639
- 'against the task. Will that FIRST attempt pass review, with no retry needed?'),
640
- criteria={
641
- 'true': 'The task is within reach of this model at this effort on the first try: the '
642
- 'requirements are clear, the change is contained, and nothing in it is likely '
643
- 'to be missed or subtly wrong.',
644
- 'false': 'The first attempt is likely to fail review: the task has edge cases, '
645
- 'cross-cutting effects, unclear requirements or subtle state that a first '
646
- 'attempt by this model at this effort typically gets wrong, so a retry would '
647
- 'be needed.'})
648
-
649
-
650
- def retry_pass() -> dict:
651
- return dict(type='noul', instructions=(
652
- 'An earlier attempt at this Forge task failed review. The task is now dispatched again, to '
653
- 'the model in state.dwarf at the effort shown, with that review\'s findings '
654
- '(state.previous_review) to fix; state.attempt is which try this is, and the model in '
655
- 'state.reviewer reviews the result. Will this attempt pass review?'),
656
- criteria={
657
- 'true': 'The findings are specific and fixable, and this model at this effort can address '
658
- 'them without breaking something else: the retry is likely to pass.',
659
- 'false': 'The findings point at a design problem, an unclear requirement or a recurring '
660
- 'mistake that another attempt by this model at this effort is likely to repeat: '
661
- 'the retry is likely to fail again and should be escalated or rethought.'})
357
+
358
+ # --- rubrics about one item (C3-C5) ------------------------------------------------
359
+ #
360
+ # A rubric about one requirement, finding or candidate issue quotes that item into its own
361
+ # instructions: the question id alone cannot tie a question to its item, so two items asked
362
+ # in one request would otherwise get the same text. A quoted item is cut first, so one long
363
+ # one cannot crowd out the state the question is about.
364
+ #
365
+ # Every Noul here is worded so that a HIGHER probability means the gate acts. A Choice's
366
+ # gate acts on `none` (coverage) or on a candidate other than `none` (culprit, duplicate).
367
+
368
+ QUOTE_CHARS = 600
369
+
370
+
371
+ def _quoted(text) -> str:
372
+ return repr(str(text)[:QUOTE_CHARS])
373
+
374
+
375
+ # Plan covers the request (#47): one Choice per requirement the request splits into.
376
+
377
+ def requirement_coverage(requirement: str, options: list) -> dict:
378
+ """Which task's acceptance criteria, if any, deliver this requirement of the request?
379
+
380
+ Asked once per requirement (coverage.py) over every task id plus 'none'. The gate acts
381
+ on 'none': a requirement no task's criteria cover goes back to the planner. A task whose
382
+ title only sounds related is not coverage, so the rubric says that outright.
383
+ """
384
+ instructions = (
385
+ 'A user asked for the work in state.request. The plan splits it into the tasks in '
386
+ 'state.tasks, each with its acceptance criteria. Which task\'s acceptance criteria, '
387
+ f'if met, would deliver this requirement: {_quoted(requirement)}? Answer none when no '
388
+ 'task\'s criteria cover it, even when a task\'s title sounds related.'
389
+ )
390
+ criteria = {task_id: f'task {task_id} covers it' for task_id in options}
391
+ criteria['none'] = 'no task\'s acceptance criteria cover it'
392
+ return Choice(instructions, criteria)
393
+
394
+
395
+ # A retry touched its blocking findings (#43).
396
+
397
+ def finding_untouched(finding: str) -> dict:
398
+ """Does the retry's diff leave this blocking finding unaddressed?
399
+
400
+ Asked once per P0/P1 finding of a retry (addressed.py). Higher means the gate acts: the
401
+ attempt is bounced before QA. An edit that might fix the finding, even one that may not
402
+ be enough, is the false side.
403
+ """
404
+ return Noul(
405
+ 'A reviewer rejected the previous attempt of a Forge task with this finding: '
406
+ f'{_quoted(finding)}. The implementer then changed the code; state.diff is everything '
407
+ 'it changed since the reviewed attempt. Does this diff leave the finding unaddressed '
408
+ '-- the code the finding names is untouched, or only unrelated code, comments or tests '
409
+ 'that do not exercise the finding\'s case changed?',
410
+ true='The cited code and behaviour are not changed in a way that could fix the finding.',
411
+ false='The diff edits the cited code or the behaviour the finding describes in a way '
412
+ 'that could fix it, even if it may not be enough.',
413
+ )
414
+
415
+
416
+ # The dwarf's final message (#44). One request per attempt; message.py picks the first that fires.
417
+
418
+ def message_unfinished() -> dict:
419
+ """Did the implementer's final message say part of the requested work is left undone?
420
+
421
+ Higher means the gate acts: the attempt is sent back as FAIL before its review. Caveats,
422
+ suggestions for later and notes about style are the false side.
423
+ """
424
+ return Noul(
425
+ 'Does the implementer\'s final message (state.message) say it did not finish the task '
426
+ '-- that part of the requested work is left undone, skipped, only partly done, or left '
427
+ 'as a TODO? Caveats, suggestions for later and notes about style do not count.'
428
+ )
429
+
430
+
431
+ def message_blocked() -> dict:
432
+ """Did the implementer say something outside the task stopped it from doing the work?
433
+
434
+ Higher means the gate acts: the attempt is sent back as FAIL before its review. A message
435
+ that reports a finished or merely difficult task is the false side.
436
+ """
437
+ return Noul(
438
+ 'Does the message say the implementer was blocked by something outside the task -- a '
439
+ 'missing dependency, an environment that fails or is unavailable, a tool or permission '
440
+ 'it lacked -- so that it could not do the work?'
441
+ )
442
+
443
+
444
+ def message_question() -> dict:
445
+ """Did the implementer ask a question only the user can answer?
446
+
447
+ Higher means the gate acts: the attempt ends NEEDS_INPUT and waits for the answer. A
448
+ choice the requirements already settle is not a question for the user.
449
+ """
450
+ return Noul(
451
+ 'Does the message ask a question only the user can answer -- a choice between behaviours '
452
+ 'the requirements leave open -- and say it could not proceed correctly without the answer?'
453
+ )
454
+
455
+
456
+ # Integration attribution (#45): which merged task broke a run's combined verification.
457
+
458
+ def culprit(options: list) -> dict:
459
+ """Which merged task most likely caused the failing combined verification of a run?
460
+
461
+ Asked once per failing integration (attribution.py) over every merged task id plus
462
+ 'none'. The gate acts on a task: its boundary is probed before the binary search. 'none'
463
+ (environmental, or unrelated to every change) leaves the search alone.
464
+ """
465
+ instructions = (
466
+ 'The combined verification of a Forge run failed after these tasks were merged one '
467
+ 'after another (state.tasks: id, title, files, diff excerpt). state.log is the end of '
468
+ 'the failing verification log. Which merged task most likely caused the failure? Answer '
469
+ 'none when the failure looks environmental or unrelated to every listed change.'
470
+ )
471
+ criteria = {task_id: f'task {task_id} most likely caused the failure' for task_id in options}
472
+ criteria['none'] = 'the failure looks environmental, or unrelated to every listed change'
473
+ return Choice(instructions, criteria)
474
+
475
+
476
+ # Findings duplicates and triage (#46): options maps each candidate issue id to its title.
477
+
478
+ def finding_duplicate(finding: str, options: dict) -> dict:
479
+ """Does this review finding restate one of the existing issues?
480
+
481
+ Asked once per finding when there are candidate issues (findings.py), over the candidate
482
+ ids plus 'none'. Higher probability on a candidate means the gate acts: the finding becomes
483
+ a comment on that issue rather than a new one. 'none' is the safe side: a finding that
484
+ only shares a file or topic with an issue is not a duplicate.
485
+ """
486
+ instructions = (
487
+ 'Is this review finding -- '
488
+ f'{_quoted(finding)} -- the same defect as one of the existing issues in state.candidates, '
489
+ 'described in other words? Same defect means the same broken behaviour in the same code, '
490
+ 'not just the same file or topic.'
491
+ )
492
+ criteria = {
493
+ candidate: (f'issue {candidate} ({_quoted(title)}) reports this same defect: the same '
494
+ 'broken behaviour in the same code')
495
+ for candidate, title in options.items()
496
+ }
497
+ criteria['none'] = ('no existing issue reports this defect; sharing a file or a topic with '
498
+ 'one is not a duplicate')
499
+ return Choice(instructions, criteria)
500
+
501
+
502
+ def finding_concrete(finding: str) -> dict:
503
+ """Is this PLAUSIBLE review finding a preference, with no concrete defect behind it?
504
+
505
+ Asked once per PLAUSIBLE finding (findings.py). Higher means the gate acts: the finding is
506
+ pre-deselected rather than filed. The question is therefore worded as the preference, not
507
+ as concreteness, so the probability keeps the same direction as every other Noul here. A
508
+ finding that names an input, state or sequence of steps that gives wrong behaviour is the
509
+ false side.
510
+ """
511
+ return Noul(
512
+ 'Does this review finding -- '
513
+ f'{_quoted(finding)} -- read as a preference about style, naming or structure rather '
514
+ 'than a defect, because it names no specific input, state or sequence of steps that '
515
+ 'produces wrong behaviour?',
516
+ true='The finding is a preference about style, naming, structure or taste. It names no '
517
+ 'specific input, state or sequence of steps that produces wrong behaviour, so '
518
+ 'fixing it would not fix a defect.',
519
+ false='The finding names a concrete defect: a specific input, state or sequence of steps '
520
+ 'that produces wrong behaviour, even when it also mentions style or naming.',
521
+ )