@giamme/forge 0.22.0 → 0.23.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 (153) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +19 -12
  3. package/SKILL.md +137 -216
  4. package/VERSION +1 -1
  5. package/docs/README.md +2 -3
  6. package/docs/add-ons.md +5 -3
  7. package/docs/artifacts.md +17 -2
  8. package/docs/commands.md +85 -63
  9. package/docs/decomposed-runs.md +195 -21
  10. package/docs/development.md +11 -9
  11. package/docs/forge-ui.md +33 -4
  12. package/docs/install.md +37 -5
  13. package/docs/memory.md +6 -1
  14. package/docs/models.md +36 -10
  15. package/docs/reviews.md +44 -25
  16. package/docs/safety.md +27 -2
  17. package/docs/troubleshooting.md +7 -10
  18. package/forge +25 -4
  19. package/package.json +2 -1
  20. package/references/dataset.md +10 -9
  21. package/references/decompose-integration.md +337 -0
  22. package/references/decompose-opt-in.md +527 -0
  23. package/references/decompose-recovery.md +569 -0
  24. package/references/decompose-review.md +256 -0
  25. package/references/decompose.md +99 -1606
  26. package/references/findings.md +68 -0
  27. package/references/harnesses.md +7 -12
  28. package/references/memory.md +13 -2
  29. package/references/planning.md +48 -18
  30. package/references/ripwire.md +38 -13
  31. package/references/runtime.md +22 -33
  32. package/references/setup.md +90 -0
  33. package/references/solo.md +13 -42
  34. package/references/ui.md +12 -5
  35. package/registry.tsv +40 -22
  36. package/scripts/forge-artifact.sh +143 -12
  37. package/scripts/forge-compare.py +5 -15
  38. package/scripts/forge-config.py +14 -1
  39. package/scripts/forge-contract.py +216 -53
  40. package/scripts/forge-control.py +777 -54
  41. package/scripts/forge-dispatch.sh +95 -12
  42. package/scripts/forge-du.py +13 -3
  43. package/scripts/forge-handoff.py +221 -39
  44. package/scripts/forge-install-ripwire.sh +100 -24
  45. package/scripts/forge-install.sh +18 -32
  46. package/scripts/forge-issues.py +6 -4
  47. package/scripts/forge-jev-options.sh +3 -5
  48. package/scripts/forge-lib-adopt.sh +169 -5
  49. package/scripts/forge-lib-attribute.sh +10 -3
  50. package/scripts/forge-lib-decompose.sh +454 -0
  51. package/scripts/forge-lib-env.sh +21 -0
  52. package/scripts/forge-lib-group.sh +4 -1
  53. package/scripts/forge-lib-plans.sh +30 -18
  54. package/scripts/forge-lib-review.sh +28 -8
  55. package/scripts/forge-lib-task.sh +225 -56
  56. package/scripts/forge-lib-verify.sh +59 -10
  57. package/scripts/forge-memory.sh +81 -4
  58. package/scripts/forge-metrics.sh +4 -2
  59. package/scripts/forge-parallel-options.sh +23 -4
  60. package/scripts/forge-parallel.sh +447 -175
  61. package/scripts/forge-plan-check.py +71 -8
  62. package/scripts/forge-planner.py +303 -17
  63. package/scripts/forge-pr.py +9 -1
  64. package/scripts/forge-prompt.py +2 -2
  65. package/scripts/forge-review-links.py +248 -0
  66. package/scripts/forge-ripwire.py +234 -16
  67. package/scripts/forge-route.py +19 -27
  68. package/scripts/forge-runs-rm.py +92 -21
  69. package/scripts/forge-runs.py +46 -5
  70. package/scripts/forge-runtime.py +37 -12
  71. package/scripts/forge-schedule.py +124 -33
  72. package/scripts/forge-setup-stale.py +236 -0
  73. package/scripts/forge-setup.py +804 -0
  74. package/scripts/forge-shadow.py +2 -20
  75. package/scripts/forge-solo-lock.py +46 -0
  76. package/scripts/forge-solo.sh +33 -56
  77. package/scripts/forge-sweep.py +2 -1
  78. package/scripts/forge-ui.py +8 -1
  79. package/scripts/forge-update.sh +2 -2
  80. package/scripts/forge-verify.py +16 -1
  81. package/scripts/forge-version.py +13 -1
  82. package/scripts/forge-watch.py +7 -2
  83. package/scripts/forge_dataset/__init__.py +1 -1
  84. package/scripts/forge_dataset/capture.py +0 -34
  85. package/scripts/forge_dataset/checks.py +0 -1
  86. package/scripts/forge_dataset/cli.py +5 -1
  87. package/scripts/forge_dataset/export.py +28 -6
  88. package/scripts/forge_dataset/facts.py +1 -2
  89. package/scripts/forge_dataset/forecast.py +1 -1
  90. package/scripts/forge_dataset/harvest.py +107 -7
  91. package/scripts/forge_dataset/importer.py +3 -2
  92. package/scripts/forge_dataset/pairs.py +3 -3
  93. package/scripts/forge_dataset/reviewers.py +4 -3
  94. package/scripts/forge_dataset/routing.py +6 -3
  95. package/scripts/forge_dataset/tiers.py +1 -1
  96. package/scripts/forge_decide/__init__.py +1 -1
  97. package/scripts/forge_decide/profiles.py +11 -14
  98. package/scripts/forge_decompose.py +987 -0
  99. package/scripts/forge_groups/review.py +6 -1
  100. package/scripts/forge_jev/__init__.py +1 -1
  101. package/scripts/forge_jev/cli.py +10 -1
  102. package/scripts/forge_jev/gates.py +10 -1
  103. package/scripts/forge_jev/verify.py +10 -2
  104. package/scripts/forge_legacy.py +86 -0
  105. package/scripts/forge_memory_home.py +57 -0
  106. package/scripts/forge_models.py +151 -0
  107. package/scripts/forge_prefs.py +138 -0
  108. package/scripts/forge_side/__init__.py +10 -0
  109. package/scripts/forge_storage.py +28 -15
  110. package/ui/README.md +22 -10
  111. package/ui/docs/api.md +121 -99
  112. package/ui/forge_ui/control.py +46 -14
  113. package/ui/forge_ui/export.py +0 -10
  114. package/ui/forge_ui/models.py +15 -2
  115. package/ui/forge_ui/projects.py +4 -1
  116. package/ui/forge_ui/reader.py +456 -59
  117. package/ui/forge_ui/server.py +0 -10
  118. package/ui/forge_ui/static/app.js +28 -9
  119. package/ui/forge_ui/static/checksview.js +12 -3
  120. package/ui/forge_ui/static/controls.js +147 -11
  121. package/ui/forge_ui/static/convo.js +5 -2
  122. package/ui/forge_ui/static/diffview.js +4 -5
  123. package/ui/forge_ui/static/panel.js +180 -77
  124. package/ui/forge_ui/static/projectsview.js +16 -2
  125. package/ui/forge_ui/static/runmodel.js +18 -4
  126. package/ui/forge_ui/static/scene3d.js +29 -29
  127. package/ui/forge_ui/static/settings.js +1 -1
  128. package/ui/forge_ui/static/storageview.js +2 -2
  129. package/ui/forge_ui/static/style.css +23 -6
  130. package/ui/forge_ui/static/worktreesview.js +8 -4
  131. package/ui/forge_ui/transcripts.py +6 -0
  132. package/ui/forge_ui/worktrees.py +13 -1
  133. package/docs/fractal.md +0 -181
  134. package/references/fractal-dashboard.md +0 -21
  135. package/references/fractal.md +0 -307
  136. package/scripts/forge-fractal-dispatch.sh +0 -4
  137. package/scripts/forge-fractal-options.sh +0 -54
  138. package/scripts/forge-fractal.py +0 -6
  139. package/scripts/forge-install-fractal.sh +0 -4
  140. package/scripts/forge_fractal/__init__.py +0 -88
  141. package/scripts/forge_fractal/bridge.py +0 -46
  142. package/scripts/forge_fractal/cli.py +0 -224
  143. package/scripts/forge_fractal/dashboard.css +0 -138
  144. package/scripts/forge_fractal/dashboard.html +0 -41
  145. package/scripts/forge_fractal/dashboard.js +0 -687
  146. package/scripts/forge_fractal/decomposition.py +0 -262
  147. package/scripts/forge_fractal/execution.py +0 -659
  148. package/scripts/forge_fractal/inspection.py +0 -261
  149. package/scripts/forge_fractal/install.py +0 -158
  150. package/scripts/forge_fractal/invocation.py +0 -95
  151. package/scripts/forge_fractal/pipeline.py +0 -125
  152. package/scripts/forge_fractal/selection.py +0 -180
  153. package/ui/forge_ui/fractal.py +0 -582
@@ -202,7 +202,16 @@ else:
202
202
  except (ValueError, AttributeError):
203
203
  pass
204
204
  if status and status.strip():
205
- ver.append('status: %s' % text(status))
205
+ status_text = text(status)
206
+ if status_text == 'STALE':
207
+ vcommit = read(os.path.join(vdir, 'verification.commit'))
208
+ short_sha = text(vcommit)[:7] if vcommit and vcommit.strip() else ''
209
+ if short_sha:
210
+ ver.append('status: STALE (verified %s, before later merges)' % short_sha)
211
+ else:
212
+ ver.append('status: STALE (verified an earlier commit, before later merges)')
213
+ else:
214
+ ver.append('status: %s' % status_text)
206
215
  cmd = read(os.path.join(vdir, 'verification.command'))
207
216
  if lanes is not None:
208
217
  # Lanes: each one's state; a flaky lane passed only on its rerun, a known lane failed
@@ -414,6 +423,7 @@ final_review_body() {
414
423
  forge_review_snapshot "$src" "$base" "$tip" "$review" > "$out/snapshot.log" 2>&1 ||
415
424
  { note "final review: cannot build the review snapshot (see $out/snapshot.log)"; return 3; }
416
425
  forge_review_deps "$src" "$review" "$out/review.deps"
426
+ forge_review_submodules "$src" "$review" "$out/review.deps"
417
427
  source_fp="$(forge_fingerprint "$src")" && review_fp="$(forge_fingerprint "$review" --tracked)" ||
418
428
  { note "final review: cannot fingerprint the checkouts"; return 3; }
419
429
  printf '%s\n' "$source_fp" > "$out/source.fingerprint"
@@ -489,7 +499,12 @@ final_review_body() {
489
499
  adopt_rows "$plan"
490
500
  cat "$out/notes.md"
491
501
  [ -s "$out/previous.md" ] && cat "$out/previous.md"
492
- python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind final --threshold "$thr"
502
+ local _tm="" _tm_flag=()
503
+ if [ -f "$plan/qa_test_minutes" ]; then
504
+ _tm="$(head -1 "$plan/qa_test_minutes" 2>/dev/null | tr -d ' \r')"
505
+ case "$_tm" in ''|*[!0-9]*) ;; *) _tm_flag=(--test-minutes "$_tm") ;; esac
506
+ fi
507
+ python3 "$SKILL_DIR/scripts/forge-contract.py" qa --part tail --kind final --threshold "$thr" ${_tm_flag[@]+"${_tm_flag[@]}"}
493
508
  echo
494
509
  if [ "$inline" = 1 ]; then
495
510
  echo '```diff'; cat "$out/combined.diff"; echo '```'
@@ -511,9 +526,7 @@ final_review_body() {
511
526
  # as this one does, by the same rule as per-task QA. Anything else is a fresh dispatch.
512
527
  local rs_mode=fresh rs_reason="" rs_id="" rs_cont=()
513
528
  if [ -f "$plan/reviewer_session" ]; then
514
- if [ -n "${FORGE_FRACTAL_RUN:-}" ] || forge_plan_is_fractal "$plan"; then
515
- rs_reason=fractal
516
- elif [ -z "$prev" ]; then
529
+ if [ -z "$prev" ]; then
517
530
  rs_reason=first-round
518
531
  else
519
532
  IFS=$'\t' read -r rs_mode rs_reason rs_id < <(review_session_decide \
@@ -583,7 +596,7 @@ final_review_body() {
583
596
  verdict="${verdict:-UNKNOWN}"
584
597
  local tests_note
585
598
  tests_note="$(forge_tests_note "$out/qa.last")"
586
- [ -z "$tests_note" ] || note "final review: the reviewer's tests could not run: $tests_note"
599
+ [ -z "$tests_note" ] || note "final review: the reviewer's tests did not complete: $tests_note"
587
600
  # Same gate as per-task QA, both ways: a FAIL made only of labelled findings below the
588
601
  # threshold is accepted with known issues; a PASS listing a blocking CONFIRMED finding fails.
589
602
  gate_line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "$verdict" \
@@ -593,7 +606,12 @@ final_review_body() {
593
606
  printf '%s\t%s\n' "$thr" "$gate_line" > "$out/qa.gate"
594
607
  case "$(printf '%s' "$gate_line" | awk -F'\t' '{print $1}')" in
595
608
  accept) verdict=ACCEPTED ;;
596
- fail) [ "$verdict" = PASS ] && { verdict=FAIL; gate_forced=1; } ;;
609
+ fail)
610
+ if [ "$verdict" = PASS ]; then
611
+ verdict=FAIL
612
+ gate_forced="$(printf '%s' "$gate_line" | awk -F'\t' '{print $6}')"
613
+ : "${gate_forced:=finding}"
614
+ fi ;;
597
615
  esac
598
616
  fi
599
617
  printf '%s\n' "$verdict" > "$out/verdict"
@@ -608,7 +626,9 @@ final_review_body() {
608
626
  echo " known issues: $out/known_issues.md"
609
627
  echo " report: $out/qa.last" ;;
610
628
  FAIL)
611
- if [ -n "$gate_forced" ]; then
629
+ if [ "$gate_forced" = tests ]; then
630
+ echo "final review ($spec): verdict FAIL (blocking) — the reviewer said PASS, but reported failing tests — forge made it FAIL."
631
+ elif [ -n "$gate_forced" ]; then
612
632
  echo "final review ($spec): verdict FAIL (blocking) — the reviewer said PASS, but listed a CONFIRMED finding at or above the $thr threshold — forge made it FAIL."
613
633
  else
614
634
  echo "final review ($spec): verdict FAIL (blocking) — the reviewer confirmed at least one defect in the combined result."
@@ -148,6 +148,22 @@ reviewed_state_matches() { # reviewed_state_matches <tdir> <wt>
148
148
  [ "$(forge_fingerprint "$wt")" = "$(cat "$tdir/source.fingerprint")" ]
149
149
  }
150
150
 
151
+ # True when the run stopped during the review of the task's last attempt (#146): reviewed.commit is
152
+ # that attempt's commit ("forge(<id>) attempt N: ..."), N is the attempt counter, and attempts.tsv
153
+ # has no row for N, since a row is written only when an attempt ends. Its code was never judged, so
154
+ # what it needs is the review, not a new implementer that keeps the code and is then refused as
155
+ # "identical to the previous attempt".
156
+ unjudged_attempt_commit() { # unjudged_attempt_commit <plan> <tdir>
157
+ local plan="$1" tdir="$2" commit n subject
158
+ [ -s "$tdir/reviewed.commit" ] || return 1
159
+ commit="$(cat "$tdir/reviewed.commit")"
160
+ n="$(tr -d '[:space:]' < "$tdir/attempt" 2>/dev/null)"
161
+ case "$n" in ''|*[!0-9]*|0) return 1 ;; esac
162
+ subject="$(git -C "$(cat "$plan/repo" 2>/dev/null)" log -1 --format=%s "$commit" 2>/dev/null)" || return 1
163
+ case "$subject" in "forge($(basename "$tdir")) attempt $n: "*) ;; *) return 1 ;; esac
164
+ ! awk -F'\t' -v n="$n" '$2 == n { found = 1 } END { exit !found }' "$tdir/attempts.tsv" 2>/dev/null
165
+ }
166
+
151
167
  # A QA-only resume is trusted only while the worktree is still exactly what was
152
168
  # reviewed. Anything else clears the marker and the full path runs.
153
169
  resume_valid() { # resume_valid <tdir> <wt>
@@ -173,20 +189,44 @@ resume_check() { # resume_check <plan> <id>
173
189
  # tasks/<id>/escalation.pin holds one dwarf spec (written by `forge control pin`). The
174
190
  # retry claims it with an atomic rename so a writer replacing it meanwhile never races the
175
191
  # read, and settles the claim once tasks.tsv and escalations.tsv are written.
176
- forge_plan_is_fractal() { # forge_plan_is_fractal <plan>
177
- [ -s "$1/fractal-selection.json" ] || return 1
178
- python3 -c 'import json, sys
179
- try:
180
- sys.exit(0 if json.load(open(sys.argv[1])).get("enabled") else 1)
181
- except Exception:
182
- sys.exit(1)' "$1/fractal-selection.json"
192
+ # --- Fractal, removed in forge 0.23 (#154): the removal note and old-record compatibility ----
193
+ # A plan or solo directory whose fractal-selection.json says enabled ran under Fractal. It stays
194
+ # readable from what forge recorded; nothing runs, retries or resumes it.
195
+ FORGE_FRACTAL_REMOVED_IN=0.23
196
+ forge_plan_was_fractal() { # forge_plan_was_fractal <plan or solo dir>
197
+ [ -e "$1/fractal-selection.json" ] || return 1
198
+ python3 "$SKILL_DIR/scripts/forge_legacy.py" was-fractal "$1"
199
+ }
200
+
201
+ # Refuses (exit 3) to run, retry or resume a directory that ran under Fractal.
202
+ forge_refuse_fractal_run() { # forge_refuse_fractal_run <plan or solo dir> <what the command is, e.g. run>
203
+ forge_plan_was_fractal "$1" || return 0
204
+ die "$2: $1 was made with Fractal, which forge $FORGE_FRACTAL_REMOVED_IN removed: it can still be read (forge runs, forge-ui) but not run, retried or resumed. Start a new run for the work that is left." 3
205
+ }
206
+
207
+ # A removed Fractal option exits 2 with one line. Returns 1 for any other argument.
208
+ forge_removed_flag() { # forge_removed_flag <argument>
209
+ case "$1" in
210
+ --fractal|--no-fractal|--fractal-*) ;;
211
+ *) return 1 ;;
212
+ esac
213
+ printf 'forge: %s was removed with Fractal in forge %s. Task decomposition is native now: see --decompose-level and docs/decomposed-runs.md\n' "$1" "$FORGE_FRACTAL_REMOVED_IN" >&2
214
+ exit 2
215
+ }
216
+
217
+ # The plan's dwarf tier pools: dwarf-routing.json, or the file a plan made before 0.23 has.
218
+ forge_pools_file() { # forge_pools_file <plan>
219
+ if [ ! -e "$1/dwarf-routing.json" ] && [ -e "$1/fractal-routing.json" ]; then
220
+ printf '%s\n' "$1/fractal-routing.json"
221
+ else
222
+ printf '%s\n' "$1/dwarf-routing.json"
223
+ fi
183
224
  }
184
225
 
185
226
  # --- fast service tier (--fast, #68) ---------------------------------------------------
186
227
  # A plan or solo run keeps the roles that should ask for the fast tier in <dir>/fast,
187
228
  # one role per line, in the order dwarf, qa, planner, review. Specs never change: the
188
229
  # dispatch and its preflight doctor get `--service-tier fast` only for a listed role.
189
- # Fractal dispatches through its own runner and ignores the file.
190
230
  #
191
231
  # forge_fast_parse sets FAST_PARSED (dynamic scope: the caller's local, when it has one)
192
232
  # to `none` or the roles. forge_fast_store writes that when --fast was given this time;
@@ -268,12 +308,8 @@ forge_fast_store() { # forge_fast_store <dir> — honour FAST_GIVEN / FAST_PARSE
268
308
  }
269
309
 
270
310
  # Prints `--service-tier fast` when <role> is listed in <dir>/fast, and nothing otherwise.
271
- # Fractal's runner does not take the option. That is FORGE_FRACTAL_RUN once the runner is
272
- # selected, and also a saved selection: retry preflights before the runner is selected, so
273
- # the variable is still unset. A whole-run review is not a Fractal dispatch and still asks.
274
311
  forge_fast_tier() { # forge_fast_tier <dir> <role>
275
312
  local line found=0
276
- [ -n "${FORGE_FRACTAL_RUN:-}" ] && return 0
277
313
  [ -f "$1/fast" ] || return 0
278
314
  while IFS= read -r line || [ -n "$line" ]; do
279
315
  line="${line%$'\r'}"
@@ -282,25 +318,9 @@ forge_fast_tier() { # forge_fast_tier <dir> <role>
282
318
  if [ "$line" = "$2" ]; then found=1; break; fi
283
319
  done < "$1/fast"
284
320
  [ "$found" = 1 ] || return 0
285
- if [ "$2" != review ] && forge_plan_is_fractal "$1"; then return 0; fi
286
321
  printf '%s %s\n' --service-tier fast
287
322
  }
288
323
 
289
- # One note per invocation, and only where this invocation's dispatches go through Fractal
290
- # (FORGE_FRACTAL_RUN already set) or are about to (a retry of a plan whose selection is on).
291
- # A whole-run review is not one of those dispatches, so it still asks for the tier.
292
- # No fast file, or no fractal selection to consult, returns before any python.
293
- forge_fast_fractal_note() { # forge_fast_fractal_note <dir>
294
- [ -s "$1/fast" ] || return 0
295
- [ -n "${FORGE_FAST_FRACTAL_NOTED:-}" ] && return 0
296
- if [ -z "${FORGE_FRACTAL_RUN:-}" ]; then
297
- [ -s "$1/fractal-selection.json" ] || return 0
298
- forge_plan_is_fractal "$1" || return 0
299
- fi
300
- export FORGE_FAST_FRACTAL_NOTED=1
301
- note "fast tier is not applied to Fractal dispatches"
302
- }
303
-
304
324
  # The pin's spec: the first line, trimmed, a single token (it lands in a TSV column).
305
325
  # Prints nothing when the file is not a regular file or holds no usable spec.
306
326
  pin_spec() { # pin_spec <file>
@@ -427,14 +447,25 @@ carry_findings() { # carry_findings <tdir>
427
447
  rm -f "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
428
448
  carry_implementer_session "$tdir"
429
449
  printf 'review\n' > "$tdir/retry_findings.source"
430
- local gthr='' gdec=''
450
+ local gthr='' gdec='' greason='' failed_names=''
431
451
  if [ -f "$tdir/qa.gate" ]; then
432
- IFS="$(printf '\t')" read -r gthr gdec _ < "$tdir/qa.gate" || true
452
+ IFS="$(printf '\t')" read -r gthr gdec _ _ _ _ greason < "$tdir/qa.gate" || true
433
453
  fi
434
454
  if [ "${gdec:-}" = fail ]; then
435
455
  # forge, not the reviewer, failed this attempt: say so above the copied report.
436
- { printf "forge: the reviewer's verdict was PASS, but this report lists CONFIRMED findings at or above the \`%s\` blocking threshold, so forge failed the attempt. Fix those findings.\n\n" "$gthr"
437
- cat "$tdir/qa.last"; } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md"
456
+ if [ "${greason:-}" = tests ]; then
457
+ failed_names="$(python3 "$SKILL_DIR/scripts/forge-contract.py" tests --failed --qa-last "$tdir/qa.last" 2>/dev/null || true)"
458
+ if [ -n "$failed_names" ] && [ "$failed_names" != FAILED ]; then
459
+ { printf "forge: the reviewer's verdict was PASS, but it reported failing tests (%s), so forge failed the attempt. Fix those failing tests.\n\n" "$failed_names"
460
+ cat "$tdir/qa.last"; } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md"
461
+ else
462
+ { printf "forge: the reviewer's verdict was PASS, but it reported failing tests, so forge failed the attempt. Fix those failing tests.\n\n"
463
+ cat "$tdir/qa.last"; } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md"
464
+ fi
465
+ else
466
+ { printf "forge: the reviewer's verdict was PASS, but this report lists CONFIRMED findings at or above the \`%s\` blocking threshold, so forge failed the attempt. Fix those findings.\n\n" "$gthr"
467
+ cat "$tdir/qa.last"; } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md"
468
+ fi
438
469
  else
439
470
  cp "$tdir/qa.last" "$tdir/retry_findings.md"
440
471
  fi
@@ -513,7 +544,7 @@ PY
513
544
  # resolution-file this dispatch's resolution (doctor output): harness=, model=, effort=
514
545
  # harnesses the ones that can continue this role (default: a reviewer's, claude
515
546
  # openclaude codex; an implementer passes claude openclaude)
516
- # The caller has already handled the cases that need no files (first round, Fractal). Anything
547
+ # The caller has already handled the cases that need no files (the first round). Anything
517
548
  # that cannot be checked is fresh; nothing here aborts.
518
549
  review_session_decide() {
519
550
  local sf="$1" rf="$2" cf="$3" can="${4:-claude openclaude codex}" id="" k a b h
@@ -725,6 +756,19 @@ for item in json.load(open(sys.argv[1], encoding="utf-8")):
725
756
  print(" %s \u2014 declared by no task" % item["path"])
726
757
  PYEOF
727
758
  echo
759
+ local unowned
760
+ unowned="$(python3 -c 'import json, sys
761
+ items = json.load(open(sys.argv[1], encoding="utf-8"))
762
+ print(",".join(i["path"] for i in items) if items and not any(i.get("owner") for i in items) else "")' "$tdir/outside.json" 2>/dev/null)"
763
+ if [ -n "$unowned" ]; then
764
+ # #199: no task declares any of them, so the simplest plan choice is one command, on a live run too.
765
+ echo "Add the path to this task's files and resume it, on a live run too (no task declares it):"
766
+ echo " forge control retry $PLAN $id --decide files+=$unowned --reason \"...\" --approved"
767
+ echo " (with no run live: forge-parallel.sh retry $PLAN $id --decide files+=$unowned --reason \"...\" --approved)"
768
+ echo "If the finding is not a change you want (it describes another module's behaviour, say), clarify the"
769
+ echo "brief instead and retry with --decide retry=1, as below."
770
+ echo
771
+ fi
728
772
  echo "Plan choices (this is a change of the plan, edit $PLAN/tasks.tsv):"
729
773
  echo " 1. add the path to this task's files"
730
774
  echo " 2. make this task depend on the owner (edit its deps)"
@@ -734,6 +778,9 @@ PYEOF
734
778
  echo
735
779
  fi ;;
736
780
  esac
781
+ echo "On a live run, give each choice below as forge control retry $PLAN $id with the same arguments"
782
+ echo "(forge-parallel.sh retry refuses while the run holds the plan); accept is forge control accept."
783
+ echo
737
784
  echo "Choices (each needs your reason; --approved says the decision is yours):"
738
785
  echo " N more attempts: forge-parallel.sh retry $PLAN $id --decide retry=N --reason \"...\" --approved"
739
786
  case ",${reasons// /}," in
@@ -749,8 +796,12 @@ PYEOF
749
796
  echo " accept it as it is: forge-parallel.sh accept $PLAN $id --reason \"...\" --approved"
750
797
  echo " (merges it; its findings become known issues)" ;;
751
798
  esac
752
- echo " split it: replace its row in $PLAN/tasks.tsv with smaller tasks (each with a"
753
- echo " tasks/<id>/prompt.md) and point its dependents at them, then forge-parallel.sh run $PLAN"
799
+ echo " split it into subtasks: forge-parallel.sh retry $PLAN $id --decide split --subtasks <file> --reason \"...\" --approved"
800
+ echo " (<file> holds the subtasks, each owning paths inside this task's files; or --planner <spec>"
801
+ echo " to have a planner write them. They build on the work so far, run as a plan of their own in"
802
+ echo " tasks/$id/sub and merge into this task, which is then reviewed on all of it."
803
+ echo " --decide split=fresh starts over from the task's base instead and keeps the old work on a ref)"
804
+ echo " $(python3 "$SKILL_DIR/scripts/forge_decompose.py" limits "$PLAN" 2>/dev/null)"
754
805
  } > "$tmp" && mv "$tmp" "$tdir/decision.md" || { rm -f "${tmp:?}"; note "$id: could not write decision.md; the task stays FAIL"; return 1; }
755
806
  rm -f "${tdir:?}/decided.left"
756
807
  echo "$from" > "$tdir/decision.from"
@@ -783,6 +834,17 @@ decision_after_attempt() { # decision_after_attempt <plan> <id> <stop-before> <c
783
834
  # decision offered to a task that waits for none. Runs before anything is written.
784
835
  retry_decision_gate() { # retry_decision_gate <plan> <id> <status> <decide> <dwarf> <reason> <approved 0|1>
785
836
  local PLAN="$1" id="$2" st="$3" decide="$4" dwarf="$5" reason="$6" approved="$7" n
837
+ # A split (#153) is a decision any task that has not passed can take, not only one that stopped for it.
838
+ if [ "$st" != NEEDS_DECISION ] && forge_decide_is_split "$decide"; then
839
+ case "$st" in
840
+ MERGED|PASS|RUNNING|IMPLEMENTED|NEEDS_INPUT)
841
+ die "retry: '$id' is $st: only a task that has not passed, is not running and waits for no answer can be split" ;;
842
+ esac
843
+ reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
844
+ [ -n "$reason" ] || die "retry: a decision needs --reason \"<why>\": it is recorded with the task"
845
+ [ "$approved" = 1 ] || die "retry: a decision needs --approved: a split changes the plan, and is only given on the user's instruction"
846
+ return 0
847
+ fi
786
848
  if [ "$st" != NEEDS_DECISION ]; then
787
849
  if [ -n "$decide" ]; then
788
850
  case "$st" in
@@ -797,7 +859,7 @@ retry_decision_gate() { # retry_decision_gate <plan> <id> <status> <decide> <dwa
797
859
  if [ -z "$decide" ] && [ -z "$dwarf" ]; then
798
860
  die "retry: '$id' is waiting for your decision, and only a decision resumes it:
799
861
  $(sed -n '1,3p' "$PLAN/tasks/$id/decision.md" 2>/dev/null)
800
- read $PLAN/tasks/$id/decision.md, then retry with --decide retry=N or --decide threshold=Pn, or --dwarf <spec>, each with --reason \"...\" --approved; or accept the task"
862
+ read $PLAN/tasks/$id/decision.md, then retry with --decide retry=N, --decide threshold=Pn or --decide split, or --dwarf <spec>, each with --reason \"...\" --approved; or accept the task"
801
863
  fi
802
864
  case "$decide" in
803
865
  "") ;;
@@ -805,13 +867,49 @@ read $PLAN/tasks/$id/decision.md, then retry with --decide retry=N or --decide t
805
867
  case "$n" in ''|*[!0-9]*) n=0 ;; esac
806
868
  [ "${#n}" -le 3 ] && [ "$n" -ge 1 ] && [ "$n" -le 20 ] || die "retry: --decide retry=N takes N from 1 to 20" ;;
807
869
  threshold=P[0-3]) ;;
808
- *) die "retry: --decide takes retry=N (1 to 20) or threshold=P0|P1|P2|P3, not '$decide'" ;;
870
+ split|split=keep|split=fresh) ;;
871
+ files+=?*) ;; # #199: checked by files_add_decision, before anything is recorded
872
+ *) die "retry: --decide takes retry=N (1 to 20), threshold=P0|P1|P2|P3, files+=PATH[,PATH] or split (split=fresh), not '$decide'" ;;
809
873
  esac
810
874
  reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
811
875
  [ -n "$reason" ] || die "retry: a decision needs --reason \"<why>\": it is recorded with the task"
812
876
  [ "$approved" = 1 ] || die "retry: a decision needs --approved: it resumes a task forge stopped, and is only given on the user's instruction"
813
877
  }
814
878
 
879
+ # Whether a task's brief changed since its last dispatch (#220): true, false, or nothing when no attempt
880
+ # recorded what it was given.
881
+ brief_changed_word() { # brief_changed_word <tdir>
882
+ local tdir="$1" f cur
883
+ [ -f "$tdir/prompt.dispatched" ] || return 0
884
+ for f in prompt approach; do
885
+ cur="$tdir/$f.md"; [ -f "$cur" ] || cur=/dev/null
886
+ [ -f "$tdir/$f.dispatched" ] || continue
887
+ cmp -s "$tdir/$f.dispatched" "$cur" || { echo true; return 0; }
888
+ done
889
+ echo false
890
+ }
891
+
892
+ # #199: `--decide files+=<path>[,<path>]` adds paths no task declares to the task's files in tasks.tsv
893
+ # (forge-control.py files_add: refused, with nothing written, when another task declares one). With check,
894
+ # only checks. A refusal says why on the run output, and the caller exits 6.
895
+ files_add_decision() { # files_add_decision <plan> <id> <decide> <reason> [check]
896
+ python3 - "$SKILL_DIR/scripts/forge-control.py" "$@" <<'PY'
897
+ import importlib.util, sys
898
+ spec = importlib.util.spec_from_file_location('forge_control', sys.argv[1])
899
+ module = importlib.util.module_from_spec(spec)
900
+ sys.modules['forge_control'] = module
901
+ spec.loader.exec_module(module)
902
+ plan, task, decide, reason = sys.argv[2:6]
903
+ try:
904
+ files = module.files_add(plan, task, decide, reason, check=len(sys.argv) > 6)
905
+ except (module.Invalid, module.Refused) as error:
906
+ print('forge: %s: %s' % (task, error), file=sys.stderr)
907
+ sys.exit(3)
908
+ if len(sys.argv) <= 6:
909
+ print('forge: %s: now owns %s' % (task, files), file=sys.stderr)
910
+ PY
911
+ }
912
+
815
913
  # The decision of a NEEDS_DECISION task, recorded and then the retry prepared as `retry` does.
816
914
  # Recorded first because the escalation policy reads decisions.tsv to restart its count; when the
817
915
  # preparation refuses, the files the decision touched are put back and the task stays as it was.
@@ -821,6 +919,8 @@ retry_decided() { # retry_decided <plan> <id> <decide> <new-dwarf> <reason>
821
919
  choice="$decide"; [ -z "$newdwarf" ] || choice="${choice:+$choice }dwarf=$newdwarf"
822
920
  reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
823
921
  attempt="$(cat "$tdir/attempt" 2>/dev/null || echo 0)"
922
+ local brief; brief="$(brief_changed_word "$tdir")"
923
+ case "$decide" in files+=*) files_add_decision "$PLAN" "$id" "$decide" "$reason" check || return 6 ;; esac
824
924
  rm -rf "${undo:?}"; mkdir "$undo" 2>/dev/null || { note "$id: could not record the decision; nothing was retried"; return 1; }
825
925
  for f in decisions.tsv qa_threshold escalation.stop split.suggested escalation.next decided.left; do
826
926
  if [ -f "$tdir/$f" ]; then cp -p "$tdir/$f" "$undo/$f"; else : > "$undo/$f.absent"; fi
@@ -834,13 +934,16 @@ retry_decided() { # retry_decided <plan> <id> <decide> <new-dwarf> <reason>
834
934
  rm -f "${tdir:?}/escalation.stop" "${tdir:?}/split.suggested" "${tdir:?}/escalation.next"
835
935
  [ "$rc" != 0 ] || decided_left_set "$tdir" $(( $(decided_attempts "$decide") - 1 )) || rc=$?
836
936
  [ "$rc" != 0 ] || prepare_retry "$PLAN" "$id" "$newdwarf" decided || rc=$?
937
+ # The row is written once the retry is prepared, so a refused preparation leaves tasks.tsv as it was.
938
+ case "$decide" in files+=*) [ "$rc" != 0 ] || files_add_decision "$PLAN" "$id" "$decide" "$reason" || rc=6 ;; esac
837
939
  if [ "$rc" != 0 ]; then
838
940
  for f in decisions.tsv qa_threshold escalation.stop split.suggested escalation.next decided.left; do
839
941
  if [ -f "$undo/$f" ]; then cp -p "$undo/$f" "$tdir/$f"; else rm -f "${tdir:?}/${f:?}"; fi
840
942
  done
841
943
  else
842
944
  forge_dataset_event decision --dir "$PLAN" --task "$id" --set "choice=$choice" --set "reason=$reason" \
843
- --set "attempt=$attempt"
945
+ --set "attempt=$attempt" ${brief:+--set "brief_changed=$brief"}
946
+ [ "$brief" != true ] || note "$id: its brief changed since attempt $attempt was dispatched; the next attempt gets the new text"
844
947
  fi
845
948
  rm -rf "${undo:?}"
846
949
  return $rc
@@ -891,7 +994,7 @@ report_decisions() { # report_decisions <plan>
891
994
  echo "decide with (each needs --reason \"...\" --approved; decision.md has the commands filled in):"
892
995
  echo " forge-parallel.sh retry $plan <task-id> --decide retry=N | --decide threshold=Pn | --dwarf <spec>"
893
996
  [ "$acceptable" = 0 ] || echo " forge-parallel.sh accept $plan <task-id> (merge it with its findings as known issues)"
894
- echo " or split it: replace its row in $plan/tasks.tsv with smaller tasks, then forge-parallel.sh run $plan"
997
+ echo " or split it into subtasks: forge-parallel.sh retry $plan <task-id> --decide split --subtasks <file> | --planner <spec>"
895
998
  echo "several side by side: add --no-dispatch to each retry, which records the decision and starts nothing, then:"
896
999
  echo " forge-parallel.sh run $plan"
897
1000
  echo
@@ -935,6 +1038,10 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
935
1038
  # honest than paying an implementer to rewrite unjudged work; the marker is validated
936
1039
  # against the worktree below before it is believed (a changed worktree runs the full task).
937
1040
  echo qa > "$tdir/resume"
1041
+ elif [ "$st" = INTERRUPTED ] && unjudged_attempt_commit "$PLAN" "$tdir"; then
1042
+ # The run stopped while this attempt's committed work was under review: ask the reviewer again,
1043
+ # with the same worktree check as above.
1044
+ echo qa > "$tdir/resume"
938
1045
  elif [ "$st" = FAIL ] && [ -f "$tdir/prereview.failed" ] && [ -s "$tdir/prereview.md" ]; then
939
1046
  # No reviewer ran: forge's own pre-review tests failed (#85), and their output is the finding.
940
1047
  carry_prereview "$tdir"
@@ -969,6 +1076,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
969
1076
  qa_only=1
970
1077
  [ "$st" = UNKNOWN ] && note "$id: the reviewer gave no verdict — re-running QA on the unchanged work"
971
1078
  [ "$st" = INVALIDATED ] && note "$id: the last review was voided — re-running QA on the unchanged work"
1079
+ [ "$st" = INTERRUPTED ] && note "$id: the run stopped during its review — re-running QA on the committed work"
972
1080
  fi
973
1081
  # Who decides the next implementer, in this order: an explicit --dwarf (the human's call,
974
1082
  # source `retry`), a pin (the human's call, applied once, source `pin`), then the retry
@@ -984,8 +1092,6 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
984
1092
  rm -f "$tdir/escalation.stop" "$tdir/split.suggested" "$tdir/escalation.next"
985
1093
  elif [ "$has_pin" = 1 ] && [ "$qa_only" = 1 ]; then
986
1094
  note "$id: the escalation pin waits for the next full retry (this one only re-runs QA)"
987
- elif [ "$has_pin" = 1 ] && forge_plan_is_fractal "$PLAN"; then
988
- note "$id: an escalation pin is set, but Fractal plans never apply pins — leaving it in place"
989
1095
  elif [ "$has_pin" = 1 ] && ! escalation_record_ok "$PLAN" "$id"; then
990
1096
  # Before the claim: a refused record leaves the pin unclaimed and tasks.tsv as it was.
991
1097
  note "$id: could not record the escalation in escalations.tsv; nothing was retried"
@@ -1088,8 +1194,6 @@ prepare_resume() { # prepare_resume <plan> <id>
1088
1194
  [ -f "$tdir/escalation.pin" ] && [ ! -L "$tdir/escalation.pin" ] || return 0
1089
1195
  if resume_check "$PLAN" "$id"; then
1090
1196
  note "$id: the escalation pin waits for the next full retry (this resume only re-runs QA)"
1091
- elif forge_plan_is_fractal "$PLAN"; then
1092
- note "$id: an escalation pin is set, but Fractal plans never apply pins — leaving it in place"
1093
1197
  elif ! escalation_record_ok "$PLAN" "$id"; then
1094
1198
  note "$id: could not record the escalation in escalations.tsv; nothing was retried"
1095
1199
  return 1
@@ -1104,15 +1208,14 @@ prepare_resume() { # prepare_resume <plan> <id>
1104
1208
  # member of its own tier pool (forge-route.py fallback). A move is no escalation: it is recorded in
1105
1209
  # tasks/<id>/lateral.tsv and as a `lateral` dataset event, not in escalations.tsv, so the retry
1106
1210
  # policy's streak carries across it. No attempt is spent: the stop already refunded it. Returns
1107
- # 1, changing nothing, when there is no candidate, a pin is waiting (a human's choice wins), the plan
1108
- # is Fractal or the move cannot be recorded. The fourth argument names the cause of the stop.
1211
+ # 1, changing nothing, when there is no candidate, a pin is waiting (a human's choice wins) or the
1212
+ # move cannot be recorded. The fourth argument names the cause of the stop.
1109
1213
  # The fifth names the stage that stopped: dwarf (the default) or qa. A review that stopped moves to a
1110
1214
  # peer reviewer of the plan's qa-routing.json (forge-route.py qa-fallback), keeping its attempt and its
1111
1215
  # `resume` marker, so the next entry is a QA-only dispatch to the new reviewer; a pin waits for the
1112
1216
  # next full retry as it does for any QA-only resume, and the escalation streak is not touched.
1113
1217
  prepare_fallback() { # prepare_fallback <plan> <id> <excluded harness/model,...> [<cause> [<dwarf|qa>]]
1114
1218
  local PLAN="$1" id="$2" tdir="$1/tasks/$2" role="${5:-dwarf}" setter=set_dwarf cur pick cause attempt line phrase
1115
- forge_plan_is_fractal "$PLAN" && return 1
1116
1219
  if [ "$role" = qa ]; then
1117
1220
  setter=set_qa
1118
1221
  # A stopped review keeps its attempt only through a valid QA-only resume; a task not yet started
@@ -1167,6 +1270,44 @@ prepare_fallback() { # prepare_fallback <plan> <id> <excluded harness/model,...>
1167
1270
  # attempt was not reviewed and spent nothing. The attempt number is given back (as a dwarf-stage infra
1168
1271
  # stop does), the implementer is told what changed, and no escalation, decision or attempt-cap gate runs:
1169
1272
  # nothing was spent. The status is cleared by the caller.
1273
+ # --- messages for the next attempt (#134) --------------------------------------
1274
+ # `forge control steer` queues them in tasks/<id>/steer.jsonl. As an implementer attempt starts,
1275
+ # steer_take moves them to steered.<attempt>.jsonl under the control lock; steer_section prints them
1276
+ # into that attempt's implementer and reviewer prompts (again on a re-dispatch of the same attempt).
1277
+ steer_take() { # steer_take <plan> <id> <attempt>
1278
+ # steer.inbox.jsonl: live messages an earlier attempt's killed dispatch never sent (#252).
1279
+ [ -s "$1/tasks/$2/steer.jsonl" ] || [ -s "$1/tasks/$2/steer.inbox.jsonl" ] || [ -e "$1/tasks/$2/steer.live" ] || return 0
1280
+ local moved
1281
+ moved="$(python3 "$SKILL_DIR/scripts/forge-control.py" _steer-take "$1" "$2" "$3" 2>&1)" \
1282
+ || { note "$2: the waiting messages could not be given to attempt $3 ($moved); they stay for the next one"; return 0; }
1283
+ [ "${moved:-0}" = 0 ] || note "$2: attempt $3 gets $moved message(s) from the user (forge control steer)"
1284
+ }
1285
+
1286
+ steer_section() { # steer_section <tdir> <attempt> dwarf|qa
1287
+ [ -s "$1/steered.$2.jsonl" ] || return 0
1288
+ python3 - "$1/steered.$2.jsonl" "$3" <<'PY'
1289
+ import json, sys
1290
+ texts = []
1291
+ for line in open(sys.argv[1], encoding='utf-8', errors='replace'):
1292
+ try:
1293
+ entry = json.loads(line)
1294
+ except ValueError:
1295
+ continue
1296
+ if isinstance(entry, dict) and isinstance(entry.get('text'), str) and entry['text'].strip():
1297
+ texts.append(entry['text'].strip())
1298
+ if texts:
1299
+ if sys.argv[2] == 'qa':
1300
+ print('\n## Messages the user sent the implementer for this attempt\n')
1301
+ print('The user sent these to the implementer of this attempt. Treat them as part of the requirements: '
1302
+ 'work they asked for is in scope, and judge whether the attempt followed them.\n')
1303
+ else:
1304
+ print('\n## Messages from the user for this attempt\n')
1305
+ print('The user sent these while the task waited or ran. Follow them. Where one conflicts with the '
1306
+ 'requirements above, follow the message and say so in your reply.\n')
1307
+ print('\n\n---\n\n'.join(texts))
1308
+ PY
1309
+ }
1310
+
1170
1311
  prepare_prompt_retry() { # prepare_prompt_retry <plan> <id>
1171
1312
  local PLAN="$1" id="$2" tdir="$1/tasks/$2" st attempt n
1172
1313
  st="$(task_status "$PLAN" "$id")"
@@ -1183,7 +1324,15 @@ prepare_prompt_retry() { # prepare_prompt_retry <plan> <id>
1183
1324
  printf '```diff\n'
1184
1325
  cat "$tdir/stale.diff" 2>/dev/null
1185
1326
  printf '```\n'
1327
+ # Changed during the review (#212): that review judged the old text, so its verdict did not count, but
1328
+ # what it found may still hold.
1329
+ if [ -s "$tdir/qa.stale.last" ]; then
1330
+ printf '\nThe review of your previous work finished after the change, so it judged the old text and its verdict does not count. What it said, for reference (check each point against the new requirements):\n\n'
1331
+ cat "$tdir/qa.stale.last"
1332
+ printf '\n'
1333
+ fi
1186
1334
  } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md" || return 1
1335
+ rm -f "$tdir/qa.stale.last"
1187
1336
  printf 'prompt\n' > "$tdir/.retry_findings.source.tmp" && mv "$tdir/.retry_findings.source.tmp" "$tdir/retry_findings.source" || return 1
1188
1337
  rm -f "$tdir/retry_findings.commit" "$tdir/resume" "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
1189
1338
  if [ -f "$PLAN/implementer_session" ]; then
@@ -1239,6 +1388,14 @@ retry_for_scheduler() { # retry_for_scheduler <plan> <id> [--resume | --prompt |
1239
1388
  done
1240
1389
  st="$(task_status "$PLAN" "$id")"
1241
1390
  retry_decision_gate "$PLAN" "$id" "$st" "$decide" "$newdwarf" "$reason" "$approved"
1391
+ if forge_decide_is_split "$decide"; then
1392
+ # A split queued into the live run (#153): `forge control retry --decide split` checked the subtasks and
1393
+ # stored them as the task's proposal. The split grants the one attempt that reviews the whole task.
1394
+ attempt_cap_gate "$PLAN" "$id" "$st" retry=1 || return 4
1395
+ retry_split "$PLAN" "$id" "$decide" "$reason" "" "" user || return $?
1396
+ rm -f "$PLAN/tasks/$id/status"
1397
+ return 0
1398
+ fi
1242
1399
  # At its attempt cap (#69), a scheduler's or a control's retry is stopped for a decision, not dispatched.
1243
1400
  attempt_cap_gate "$PLAN" "$id" "$st" "$decide" || return 4
1244
1401
  if [ "$st" = NEEDS_DECISION ]; then
@@ -1325,14 +1482,14 @@ forge_now() { python3 -c 'import time; print("%.3f" % time.time())' 2>/dev/null
1325
1482
 
1326
1483
  # The gate goes both ways, at the effective threshold. A reviewer's FAIL whose confirmed
1327
1484
  # findings are all labelled and less severe than the threshold is accepted as
1328
- # PASS-with-known-issues; the literal status stays PASS, so the merge path, the scheduler
1329
- # and Fractal need no new vocabulary. A PASS that lists a blocking CONFIRMED finding (at the
1485
+ # PASS-with-known-issues; the literal status stays PASS, so the merge path and the scheduler
1486
+ # need no new vocabulary. A PASS that lists a blocking CONFIRMED finding (at the
1330
1487
  # threshold or worse, or with no severity) becomes FAIL.
1331
1488
  # The optional 5th argument is the threshold the caller already used for this attempt's review
1332
1489
  # prompt; when given it is used as-is, so a change to the files between the prompt and the
1333
1490
  # gate cannot split one attempt across two thresholds. Absent (or empty), the files are read.
1334
1491
  qa_gate() { # qa_gate <plan> <id> <tdir> <verdict> [threshold]
1335
- local plan="$1" id="$2" tdir="$3" verdict="$4" thr="${5:-}" line worst
1492
+ local plan="$1" id="$2" tdir="$3" verdict="$4" thr="${5:-}" line worst greason
1336
1493
  rm -f "$tdir/qa.gate" "$tdir/known_issues.md"
1337
1494
  [ -n "$thr" ] || thr="$(qa_threshold_for "$plan" "$id")"
1338
1495
  line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "${verdict:-UNKNOWN}" \
@@ -1346,10 +1503,15 @@ qa_gate() { # qa_gate <plan> <id> <tdir> <verdict> [threshold]
1346
1503
  fail)
1347
1504
  echo FAIL > "$tdir/status"
1348
1505
  worst="$(printf '%s' "$line" | awk -F'\t' '{print $2}')"
1349
- note "$id: the reviewer said PASS but listed a CONFIRMED finding at or above the $thr threshold (worst $worst) — forge made it FAIL"
1506
+ greason="$(printf '%s' "$line" | awk -F'\t' '{print $6}')"
1507
+ if [ "$greason" = tests ]; then
1508
+ note "$id: the reviewer said PASS but reported failing tests — forge made it FAIL"
1509
+ else
1510
+ note "$id: the reviewer said PASS but listed a CONFIRMED finding at or above the $thr threshold (worst $worst) — forge made it FAIL"
1511
+ fi
1350
1512
  # A scheduled task's notes go to its task.out, and a later attempt replaces qa.gate: this
1351
1513
  # log is what lets the run's summary say forge overrode a verdict (report_gate_flips).
1352
- printf '%s\t%s\t%s\t%s\n' "$(forge_now)" "$(cat "$tdir/attempt" 2>/dev/null || echo 0)" "$thr" "$worst" \
1514
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(forge_now)" "$(cat "$tdir/attempt" 2>/dev/null || echo 0)" "$thr" "$worst" "${greason:-findings}" \
1353
1515
  >> "$tdir/qa.flips" ;;
1354
1516
  esac
1355
1517
  return 0
@@ -1428,15 +1590,19 @@ report_known_issues() { # report_known_issues <plan>
1428
1590
  # The PASS verdicts forge turned into FAIL, since FORGE_RUN_STARTED (set by run and retry;
1429
1591
  # unset shows them all), including those whose task a later attempt fixed.
1430
1592
  report_gate_flips() { # report_gate_flips <plan>
1431
- local plan="$1" id n=0 at attempt thr worst id_w
1593
+ local plan="$1" id n=0 at attempt thr worst greason id_w
1432
1594
  id_w="$(id_col_width "$plan/tasks.tsv")"
1433
1595
  for id in $(all_ids "$plan/tasks.tsv"); do
1434
1596
  [ -s "$plan/tasks/$id/qa.flips" ] || continue
1435
- while IFS="$(printf '\t')" read -r at attempt thr worst; do
1597
+ while IFS="$(printf '\t')" read -r at attempt thr worst greason; do
1436
1598
  awk -v at="${at:-0}" -v since="${FORGE_RUN_STARTED:-0}" 'BEGIN { exit !(at + 0 >= since + 0) }' || continue
1437
- [ "$n" = 0 ] && echo "forge overrode the reviewer's verdict (PASS, but it listed a CONFIRMED finding at or above the threshold):"
1599
+ [ "$n" = 0 ] && echo "forge overrode the reviewer's verdict (PASS -> FAIL):"
1438
1600
  n=$((n+1))
1439
- printf ' %-*s attempt %s: PASS -> FAIL at the %s threshold (worst %s)\n' "$id_w" "$id" "$attempt" "$thr" "$worst"
1601
+ if [ "${greason:-findings}" = tests ]; then
1602
+ printf ' %-*s attempt %s: PASS -> FAIL at the %s threshold (reported failing tests)\n' "$id_w" "$id" "$attempt" "$thr"
1603
+ else
1604
+ printf ' %-*s attempt %s: PASS -> FAIL at the %s threshold (worst %s)\n' "$id_w" "$id" "$attempt" "$thr" "$worst"
1605
+ fi
1440
1606
  done < "$plan/tasks/$id/qa.flips"
1441
1607
  done
1442
1608
  [ "$n" -gt 0 ] && echo
@@ -1487,6 +1653,10 @@ PY
1487
1653
  sed 's/^/ /' "$d/verification.coverage.txt"
1488
1654
  echo
1489
1655
  fi
1656
+ if [ "$(cat "$d/verification.status" 2>/dev/null)" = FAIL ] && [ -s "$d/verification.stale_setup" ]; then
1657
+ echo "warning: stale setup ($(cat "$d/verification.stale_setup")): generated files predate merged commits; use --setup-before-verify or prepend setup to the verify command"
1658
+ echo
1659
+ fi
1490
1660
  return 0
1491
1661
  }
1492
1662
 
@@ -1509,7 +1679,6 @@ report_escalations() { # report_escalations <plan>
1509
1679
  head="retry policy (after $(cat "$plan/escalate_after" 2>/dev/null || echo 3) failed attempts on one model):"
1510
1680
  for id in $(all_ids "$plan/tasks.tsv"); do
1511
1681
  pin="$(pin_spec "$plan/tasks/$id/escalation.pin")"
1512
- [ -n "$pin" ] && forge_plan_is_fractal "$plan" && pin=""
1513
1682
  if [ -n "$pin" ] && [ "$(task_status "$plan" "$id")" != MERGED ]; then
1514
1683
  [ "$n" = 0 ] && echo "$head"
1515
1684
  n=$((n+1))