@giamme/forge 0.21.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 (165) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/README.md +25 -15
  3. package/SKILL.md +137 -216
  4. package/VERSION +1 -1
  5. package/bin/forge.js +104 -0
  6. package/docs/README.md +2 -3
  7. package/docs/add-ons.md +5 -3
  8. package/docs/artifacts.md +17 -2
  9. package/docs/commands.md +85 -63
  10. package/docs/decomposed-runs.md +195 -21
  11. package/docs/development.md +12 -10
  12. package/docs/forge-ui.md +33 -4
  13. package/docs/install.md +127 -6
  14. package/docs/memory.md +6 -1
  15. package/docs/models.md +36 -10
  16. package/docs/reviews.md +50 -29
  17. package/docs/safety.md +27 -2
  18. package/docs/troubleshooting.md +8 -11
  19. package/forge +29 -4
  20. package/forge.cmd +56 -0
  21. package/package.json +6 -3
  22. package/references/dataset.md +10 -9
  23. package/references/decompose-integration.md +337 -0
  24. package/references/decompose-opt-in.md +527 -0
  25. package/references/decompose-recovery.md +569 -0
  26. package/references/decompose-review.md +256 -0
  27. package/references/decompose.md +99 -1606
  28. package/references/findings.md +68 -0
  29. package/references/harnesses.md +7 -12
  30. package/references/memory.md +13 -2
  31. package/references/planning.md +48 -18
  32. package/references/ripwire.md +38 -13
  33. package/references/runtime.md +22 -33
  34. package/references/setup.md +90 -0
  35. package/references/solo.md +13 -42
  36. package/references/ui.md +12 -5
  37. package/registry.tsv +40 -22
  38. package/scripts/forge-artifact.sh +148 -13
  39. package/scripts/forge-compare.py +5 -15
  40. package/scripts/forge-config.py +14 -1
  41. package/scripts/forge-contract.py +216 -53
  42. package/scripts/forge-control.py +781 -51
  43. package/scripts/forge-dispatch.sh +202 -42
  44. package/scripts/forge-du.py +13 -3
  45. package/scripts/forge-guard.py +137 -6
  46. package/scripts/forge-handoff.py +221 -39
  47. package/scripts/forge-install-ripwire.sh +100 -24
  48. package/scripts/forge-install.sh +100 -41
  49. package/scripts/forge-issues.py +6 -4
  50. package/scripts/forge-jev-options.sh +3 -5
  51. package/scripts/forge-lib-adopt.sh +169 -5
  52. package/scripts/forge-lib-attribute.sh +10 -3
  53. package/scripts/forge-lib-decompose.sh +454 -0
  54. package/scripts/forge-lib-env.sh +179 -0
  55. package/scripts/forge-lib-group.sh +9 -6
  56. package/scripts/forge-lib-plans.sh +38 -21
  57. package/scripts/forge-lib-review.sh +28 -8
  58. package/scripts/forge-lib-task.sh +263 -69
  59. package/scripts/forge-lib-verify.sh +59 -10
  60. package/scripts/forge-memory.sh +83 -4
  61. package/scripts/forge-metrics.sh +10 -3
  62. package/scripts/forge-parallel-options.sh +23 -4
  63. package/scripts/forge-parallel.sh +602 -217
  64. package/scripts/forge-plan-check.py +71 -8
  65. package/scripts/forge-planner.py +303 -17
  66. package/scripts/forge-pr.py +9 -1
  67. package/scripts/forge-prompt.py +2 -2
  68. package/scripts/forge-review-links.py +248 -0
  69. package/scripts/forge-ripwire.py +234 -16
  70. package/scripts/forge-route.py +19 -27
  71. package/scripts/forge-runs-rm.py +92 -21
  72. package/scripts/forge-runs.py +46 -5
  73. package/scripts/forge-runtime.py +39 -14
  74. package/scripts/forge-schedule.py +141 -33
  75. package/scripts/forge-setup-stale.py +236 -0
  76. package/scripts/forge-setup.py +804 -0
  77. package/scripts/forge-shadow.py +2 -20
  78. package/scripts/forge-solo-lock.py +46 -0
  79. package/scripts/forge-solo.sh +39 -58
  80. package/scripts/forge-sweep.py +3 -2
  81. package/scripts/forge-ui.py +8 -1
  82. package/scripts/forge-update.sh +8 -3
  83. package/scripts/forge-verify.py +17 -1
  84. package/scripts/forge-version.py +13 -1
  85. package/scripts/forge-watch.py +7 -2
  86. package/scripts/forge-win.sh +156 -0
  87. package/scripts/forge_brief/__init__.py +6 -1
  88. package/scripts/forge_brief/proposals.py +6 -1
  89. package/scripts/forge_dataset/__init__.py +1 -1
  90. package/scripts/forge_dataset/capture.py +0 -34
  91. package/scripts/forge_dataset/checks.py +0 -1
  92. package/scripts/forge_dataset/cli.py +5 -1
  93. package/scripts/forge_dataset/export.py +28 -6
  94. package/scripts/forge_dataset/facts.py +1 -2
  95. package/scripts/forge_dataset/forecast.py +1 -1
  96. package/scripts/forge_dataset/harvest.py +107 -7
  97. package/scripts/forge_dataset/importer.py +3 -2
  98. package/scripts/forge_dataset/pairs.py +3 -3
  99. package/scripts/forge_dataset/reviewers.py +4 -3
  100. package/scripts/forge_dataset/routing.py +6 -3
  101. package/scripts/forge_dataset/tiers.py +1 -1
  102. package/scripts/forge_decide/__init__.py +1 -1
  103. package/scripts/forge_decide/budget.py +12 -7
  104. package/scripts/forge_decide/profiles.py +11 -14
  105. package/scripts/forge_decide/replay.py +9 -4
  106. package/scripts/forge_decompose.py +987 -0
  107. package/scripts/forge_flock.py +17 -2
  108. package/scripts/forge_groups/review.py +6 -1
  109. package/scripts/forge_jev/__init__.py +1 -1
  110. package/scripts/forge_jev/cli.py +10 -1
  111. package/scripts/forge_jev/gates.py +10 -1
  112. package/scripts/forge_jev/verify.py +10 -2
  113. package/scripts/forge_legacy.py +86 -0
  114. package/scripts/forge_memory_home.py +57 -0
  115. package/scripts/forge_models.py +151 -0
  116. package/scripts/forge_posix.py +17 -0
  117. package/scripts/forge_prefs.py +138 -0
  118. package/scripts/forge_proc.py +108 -0
  119. package/scripts/forge_registry.py +2 -2
  120. package/scripts/forge_side/__init__.py +23 -4
  121. package/scripts/forge_storage.py +28 -15
  122. package/ui/README.md +22 -10
  123. package/ui/docs/api.md +121 -99
  124. package/ui/forge_ui/control.py +53 -16
  125. package/ui/forge_ui/export.py +0 -10
  126. package/ui/forge_ui/models.py +15 -2
  127. package/ui/forge_ui/projects.py +4 -1
  128. package/ui/forge_ui/reader.py +462 -60
  129. package/ui/forge_ui/server.py +0 -10
  130. package/ui/forge_ui/static/app.js +28 -9
  131. package/ui/forge_ui/static/checksview.js +12 -3
  132. package/ui/forge_ui/static/controls.js +147 -11
  133. package/ui/forge_ui/static/convo.js +5 -2
  134. package/ui/forge_ui/static/diffview.js +4 -5
  135. package/ui/forge_ui/static/panel.js +180 -77
  136. package/ui/forge_ui/static/projectsview.js +16 -2
  137. package/ui/forge_ui/static/runmodel.js +18 -4
  138. package/ui/forge_ui/static/scene3d.js +52 -31
  139. package/ui/forge_ui/static/settings.js +1 -1
  140. package/ui/forge_ui/static/storageview.js +2 -2
  141. package/ui/forge_ui/static/style.css +23 -6
  142. package/ui/forge_ui/static/worktreesview.js +8 -4
  143. package/ui/forge_ui/transcripts.py +6 -0
  144. package/ui/forge_ui/worktrees.py +13 -1
  145. package/docs/fractal.md +0 -181
  146. package/references/fractal-dashboard.md +0 -21
  147. package/references/fractal.md +0 -307
  148. package/scripts/forge-fractal-dispatch.sh +0 -4
  149. package/scripts/forge-fractal-options.sh +0 -54
  150. package/scripts/forge-fractal.py +0 -6
  151. package/scripts/forge-install-fractal.sh +0 -4
  152. package/scripts/forge_fractal/__init__.py +0 -88
  153. package/scripts/forge_fractal/bridge.py +0 -46
  154. package/scripts/forge_fractal/cli.py +0 -224
  155. package/scripts/forge_fractal/dashboard.css +0 -138
  156. package/scripts/forge_fractal/dashboard.html +0 -41
  157. package/scripts/forge_fractal/dashboard.js +0 -687
  158. package/scripts/forge_fractal/decomposition.py +0 -262
  159. package/scripts/forge_fractal/execution.py +0 -659
  160. package/scripts/forge_fractal/inspection.py +0 -261
  161. package/scripts/forge_fractal/install.py +0 -158
  162. package/scripts/forge_fractal/invocation.py +0 -95
  163. package/scripts/forge_fractal/pipeline.py +0 -125
  164. package/scripts/forge_fractal/selection.py +0 -180
  165. package/ui/forge_ui/fractal.py +0 -582
@@ -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
@@ -741,14 +788,20 @@ PYEOF
741
788
  esac
742
789
  echo " lower the threshold: forge-parallel.sh retry $PLAN $id --decide threshold=P1 --reason \"...\" --approved"
743
790
  echo " (this task's blocking threshold, then one retry)"
791
+ echo " clarify the brief: edit tasks/$id/prompt.md (or approach.md), then retry with --decide retry=1"
792
+ echo " (--reason \"...\" --approved; unchanged code is re-reviewed against the new brief)"
744
793
  echo " a named model: forge-parallel.sh retry $PLAN $id --dwarf <spec> --reason \"...\" --approved"
745
794
  echo " (one attempt; with --decide retry=N, up to N attempts held on that model)"
746
795
  case "$from" in FAIL|UNKNOWN) # with no reviewer verdict, accept has nothing to override
747
796
  echo " accept it as it is: forge-parallel.sh accept $PLAN $id --reason \"...\" --approved"
748
797
  echo " (merges it; its findings become known issues)" ;;
749
798
  esac
750
- echo " split it: replace its row in $PLAN/tasks.tsv with smaller tasks (each with a"
751
- 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)"
752
805
  } > "$tmp" && mv "$tmp" "$tdir/decision.md" || { rm -f "${tmp:?}"; note "$id: could not write decision.md; the task stays FAIL"; return 1; }
753
806
  rm -f "${tdir:?}/decided.left"
754
807
  echo "$from" > "$tdir/decision.from"
@@ -781,14 +834,32 @@ decision_after_attempt() { # decision_after_attempt <plan> <id> <stop-before> <c
781
834
  # decision offered to a task that waits for none. Runs before anything is written.
782
835
  retry_decision_gate() { # retry_decision_gate <plan> <id> <status> <decide> <dwarf> <reason> <approved 0|1>
783
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
784
848
  if [ "$st" != NEEDS_DECISION ]; then
785
- [ -z "$decide" ] || die "retry: '$id' is $st, not waiting for a decision; --decide only decides a NEEDS_DECISION task"
849
+ if [ -n "$decide" ]; then
850
+ case "$st" in
851
+ FAIL|UNKNOWN|ERROR|TIMEOUT|INTERRUPTED|INVALIDATED|CONFLICT)
852
+ die "retry: '$id' is $st, not waiting for a decision; --decide only decides a NEEDS_DECISION task (run without --decide: forge-parallel.sh retry $PLAN $id)" ;;
853
+ *)
854
+ die "retry: '$id' is $st, not waiting for a decision; --decide only decides a NEEDS_DECISION task" ;;
855
+ esac
856
+ fi
786
857
  return 0
787
858
  fi
788
859
  if [ -z "$decide" ] && [ -z "$dwarf" ]; then
789
860
  die "retry: '$id' is waiting for your decision, and only a decision resumes it:
790
861
  $(sed -n '1,3p' "$PLAN/tasks/$id/decision.md" 2>/dev/null)
791
- 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"
792
863
  fi
793
864
  case "$decide" in
794
865
  "") ;;
@@ -796,13 +867,49 @@ read $PLAN/tasks/$id/decision.md, then retry with --decide retry=N or --decide t
796
867
  case "$n" in ''|*[!0-9]*) n=0 ;; esac
797
868
  [ "${#n}" -le 3 ] && [ "$n" -ge 1 ] && [ "$n" -le 20 ] || die "retry: --decide retry=N takes N from 1 to 20" ;;
798
869
  threshold=P[0-3]) ;;
799
- *) 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'" ;;
800
873
  esac
801
874
  reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
802
875
  [ -n "$reason" ] || die "retry: a decision needs --reason \"<why>\": it is recorded with the task"
803
876
  [ "$approved" = 1 ] || die "retry: a decision needs --approved: it resumes a task forge stopped, and is only given on the user's instruction"
804
877
  }
805
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
+
806
913
  # The decision of a NEEDS_DECISION task, recorded and then the retry prepared as `retry` does.
807
914
  # Recorded first because the escalation policy reads decisions.tsv to restart its count; when the
808
915
  # preparation refuses, the files the decision touched are put back and the task stays as it was.
@@ -812,6 +919,8 @@ retry_decided() { # retry_decided <plan> <id> <decide> <new-dwarf> <reason>
812
919
  choice="$decide"; [ -z "$newdwarf" ] || choice="${choice:+$choice }dwarf=$newdwarf"
813
920
  reason="$(printf '%s' "$reason" | tr '\n\r\t' ' ' | sed 's/^ *//; s/ *$//')"
814
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
815
924
  rm -rf "${undo:?}"; mkdir "$undo" 2>/dev/null || { note "$id: could not record the decision; nothing was retried"; return 1; }
816
925
  for f in decisions.tsv qa_threshold escalation.stop split.suggested escalation.next decided.left; do
817
926
  if [ -f "$tdir/$f" ]; then cp -p "$tdir/$f" "$undo/$f"; else : > "$undo/$f.absent"; fi
@@ -825,13 +934,16 @@ retry_decided() { # retry_decided <plan> <id> <decide> <new-dwarf> <reason>
825
934
  rm -f "${tdir:?}/escalation.stop" "${tdir:?}/split.suggested" "${tdir:?}/escalation.next"
826
935
  [ "$rc" != 0 ] || decided_left_set "$tdir" $(( $(decided_attempts "$decide") - 1 )) || rc=$?
827
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
828
939
  if [ "$rc" != 0 ]; then
829
940
  for f in decisions.tsv qa_threshold escalation.stop split.suggested escalation.next decided.left; do
830
941
  if [ -f "$undo/$f" ]; then cp -p "$undo/$f" "$tdir/$f"; else rm -f "${tdir:?}/${f:?}"; fi
831
942
  done
832
943
  else
833
944
  forge_dataset_event decision --dir "$PLAN" --task "$id" --set "choice=$choice" --set "reason=$reason" \
834
- --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"
835
947
  fi
836
948
  rm -rf "${undo:?}"
837
949
  return $rc
@@ -882,7 +994,7 @@ report_decisions() { # report_decisions <plan>
882
994
  echo "decide with (each needs --reason \"...\" --approved; decision.md has the commands filled in):"
883
995
  echo " forge-parallel.sh retry $plan <task-id> --decide retry=N | --decide threshold=Pn | --dwarf <spec>"
884
996
  [ "$acceptable" = 0 ] || echo " forge-parallel.sh accept $plan <task-id> (merge it with its findings as known issues)"
885
- 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>"
886
998
  echo "several side by side: add --no-dispatch to each retry, which records the decision and starts nothing, then:"
887
999
  echo " forge-parallel.sh run $plan"
888
1000
  echo
@@ -926,6 +1038,10 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
926
1038
  # honest than paying an implementer to rewrite unjudged work; the marker is validated
927
1039
  # against the worktree below before it is believed (a changed worktree runs the full task).
928
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"
929
1045
  elif [ "$st" = FAIL ] && [ -f "$tdir/prereview.failed" ] && [ -s "$tdir/prereview.md" ]; then
930
1046
  # No reviewer ran: forge's own pre-review tests failed (#85), and their output is the finding.
931
1047
  carry_prereview "$tdir"
@@ -960,6 +1076,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
960
1076
  qa_only=1
961
1077
  [ "$st" = UNKNOWN ] && note "$id: the reviewer gave no verdict — re-running QA on the unchanged work"
962
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"
963
1080
  fi
964
1081
  # Who decides the next implementer, in this order: an explicit --dwarf (the human's call,
965
1082
  # source `retry`), a pin (the human's call, applied once, source `pin`), then the retry
@@ -975,8 +1092,6 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
975
1092
  rm -f "$tdir/escalation.stop" "$tdir/split.suggested" "$tdir/escalation.next"
976
1093
  elif [ "$has_pin" = 1 ] && [ "$qa_only" = 1 ]; then
977
1094
  note "$id: the escalation pin waits for the next full retry (this one only re-runs QA)"
978
- elif [ "$has_pin" = 1 ] && forge_plan_is_fractal "$PLAN"; then
979
- note "$id: an escalation pin is set, but Fractal plans never apply pins — leaving it in place"
980
1095
  elif [ "$has_pin" = 1 ] && ! escalation_record_ok "$PLAN" "$id"; then
981
1096
  # Before the claim: a refused record leaves the pin unclaimed and tasks.tsv as it was.
982
1097
  note "$id: could not record the escalation in escalations.tsv; nothing was retried"
@@ -996,7 +1111,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
996
1111
  if [ -n "$next" ]; then
997
1112
  # retry_per_model replaces escalate_after (forge-route.py escalation). The note names the
998
1113
  # count that moved the task, and does not point at a flag that no longer governs the plan.
999
- per_model="$(tr -d '[:space:]' < "$PLAN/retry_per_model" 2>/dev/null || true)"
1114
+ per_model="$(tr -d '[:space:]' 2>/dev/null < "$PLAN/retry_per_model" || true)"
1000
1115
  case "$per_model" in
1001
1116
  [1-9]|[1-9][0-9]) ;;
1002
1117
  *) per_model="" ;;
@@ -1017,7 +1132,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
1017
1132
  write_escalation "$PLAN" "$id" "$cur" "$newdwarf" "$esc_source" || { rm -f "$tdir/retry_findings.next"; return 1; }
1018
1133
  fi
1019
1134
  [ "$st" != NEEDS_INPUT ] || commit_answer_findings "$tdir" || return 1
1020
- rm -f "$tdir/noretry"
1135
+ rm -f "$tdir/noretry" "$tdir/decision.md" "$tdir/decision.from"
1021
1136
  }
1022
1137
 
1023
1138
  # Puts the next implementer in place: tasks.tsv, the escalations.tsv record and the dataset
@@ -1079,8 +1194,6 @@ prepare_resume() { # prepare_resume <plan> <id>
1079
1194
  [ -f "$tdir/escalation.pin" ] && [ ! -L "$tdir/escalation.pin" ] || return 0
1080
1195
  if resume_check "$PLAN" "$id"; then
1081
1196
  note "$id: the escalation pin waits for the next full retry (this resume only re-runs QA)"
1082
- elif forge_plan_is_fractal "$PLAN"; then
1083
- note "$id: an escalation pin is set, but Fractal plans never apply pins — leaving it in place"
1084
1197
  elif ! escalation_record_ok "$PLAN" "$id"; then
1085
1198
  note "$id: could not record the escalation in escalations.tsv; nothing was retried"
1086
1199
  return 1
@@ -1095,15 +1208,14 @@ prepare_resume() { # prepare_resume <plan> <id>
1095
1208
  # member of its own tier pool (forge-route.py fallback). A move is no escalation: it is recorded in
1096
1209
  # tasks/<id>/lateral.tsv and as a `lateral` dataset event, not in escalations.tsv, so the retry
1097
1210
  # policy's streak carries across it. No attempt is spent: the stop already refunded it. Returns
1098
- # 1, changing nothing, when there is no candidate, a pin is waiting (a human's choice wins), the plan
1099
- # 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.
1100
1213
  # The fifth names the stage that stopped: dwarf (the default) or qa. A review that stopped moves to a
1101
1214
  # peer reviewer of the plan's qa-routing.json (forge-route.py qa-fallback), keeping its attempt and its
1102
1215
  # `resume` marker, so the next entry is a QA-only dispatch to the new reviewer; a pin waits for the
1103
1216
  # next full retry as it does for any QA-only resume, and the escalation streak is not touched.
1104
1217
  prepare_fallback() { # prepare_fallback <plan> <id> <excluded harness/model,...> [<cause> [<dwarf|qa>]]
1105
1218
  local PLAN="$1" id="$2" tdir="$1/tasks/$2" role="${5:-dwarf}" setter=set_dwarf cur pick cause attempt line phrase
1106
- forge_plan_is_fractal "$PLAN" && return 1
1107
1219
  if [ "$role" = qa ]; then
1108
1220
  setter=set_qa
1109
1221
  # A stopped review keeps its attempt only through a valid QA-only resume; a task not yet started
@@ -1158,6 +1270,44 @@ prepare_fallback() { # prepare_fallback <plan> <id> <excluded harness/model,...>
1158
1270
  # attempt was not reviewed and spent nothing. The attempt number is given back (as a dwarf-stage infra
1159
1271
  # stop does), the implementer is told what changed, and no escalation, decision or attempt-cap gate runs:
1160
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
+
1161
1311
  prepare_prompt_retry() { # prepare_prompt_retry <plan> <id>
1162
1312
  local PLAN="$1" id="$2" tdir="$1/tasks/$2" st attempt n
1163
1313
  st="$(task_status "$PLAN" "$id")"
@@ -1174,7 +1324,15 @@ prepare_prompt_retry() { # prepare_prompt_retry <plan> <id>
1174
1324
  printf '```diff\n'
1175
1325
  cat "$tdir/stale.diff" 2>/dev/null
1176
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
1177
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"
1178
1336
  printf 'prompt\n' > "$tdir/.retry_findings.source.tmp" && mv "$tdir/.retry_findings.source.tmp" "$tdir/retry_findings.source" || return 1
1179
1337
  rm -f "$tdir/retry_findings.commit" "$tdir/resume" "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
1180
1338
  if [ -f "$PLAN/implementer_session" ]; then
@@ -1230,6 +1388,14 @@ retry_for_scheduler() { # retry_for_scheduler <plan> <id> [--resume | --prompt |
1230
1388
  done
1231
1389
  st="$(task_status "$PLAN" "$id")"
1232
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
1233
1399
  # At its attempt cap (#69), a scheduler's or a control's retry is stopped for a decision, not dispatched.
1234
1400
  attempt_cap_gate "$PLAN" "$id" "$st" "$decide" || return 4
1235
1401
  if [ "$st" = NEEDS_DECISION ]; then
@@ -1316,14 +1482,14 @@ forge_now() { python3 -c 'import time; print("%.3f" % time.time())' 2>/dev/null
1316
1482
 
1317
1483
  # The gate goes both ways, at the effective threshold. A reviewer's FAIL whose confirmed
1318
1484
  # findings are all labelled and less severe than the threshold is accepted as
1319
- # PASS-with-known-issues; the literal status stays PASS, so the merge path, the scheduler
1320
- # 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
1321
1487
  # threshold or worse, or with no severity) becomes FAIL.
1322
1488
  # The optional 5th argument is the threshold the caller already used for this attempt's review
1323
1489
  # prompt; when given it is used as-is, so a change to the files between the prompt and the
1324
1490
  # gate cannot split one attempt across two thresholds. Absent (or empty), the files are read.
1325
1491
  qa_gate() { # qa_gate <plan> <id> <tdir> <verdict> [threshold]
1326
- 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
1327
1493
  rm -f "$tdir/qa.gate" "$tdir/known_issues.md"
1328
1494
  [ -n "$thr" ] || thr="$(qa_threshold_for "$plan" "$id")"
1329
1495
  line="$(python3 "$SKILL_DIR/scripts/forge-contract.py" gate --verdict "${verdict:-UNKNOWN}" \
@@ -1337,16 +1503,33 @@ qa_gate() { # qa_gate <plan> <id> <tdir> <verdict> [threshold]
1337
1503
  fail)
1338
1504
  echo FAIL > "$tdir/status"
1339
1505
  worst="$(printf '%s' "$line" | awk -F'\t' '{print $2}')"
1340
- 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
1341
1512
  # A scheduled task's notes go to its task.out, and a later attempt replaces qa.gate: this
1342
1513
  # log is what lets the run's summary say forge overrode a verdict (report_gate_flips).
1343
- 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}" \
1344
1515
  >> "$tdir/qa.flips" ;;
1345
1516
  esac
1346
1517
  return 0
1347
1518
  }
1348
1519
 
1349
1520
  # --- report blocks ----------------------------------------------------------------
1521
+ # The id column is as wide as the plan's longest task id, and never narrower than 14. Here and
1522
+ # not in forge-parallel.sh, which uses it too, because this file is also sourced on its own.
1523
+ id_col_width() { # id_col_width <tsv...> -> longest col-1 task id length across readable TSVs, at least 14
1524
+ local w=14 f n=0
1525
+ for f in "$@"; do
1526
+ [ -r "$f" ] || continue
1527
+ n="$(awk -F'\t' '!/^#/ && NF { if (length($1) > m) m = length($1) } END { print m + 0 }' "$f" 2>/dev/null)" || n=0
1528
+ [ "$n" -gt "$w" ] && w="$n"
1529
+ done
1530
+ echo "$w"
1531
+ }
1532
+
1350
1533
  # The wording of each line, and what the causes need, is forge_infra.py's; this block only lays them out.
1351
1534
  # A lateral move is news whether or not a task is still paused, so its lines come out either way.
1352
1535
  report_infra() { # report_infra <plan>
@@ -1381,7 +1564,8 @@ report_infra() { # report_infra <plan>
1381
1564
  }
1382
1565
 
1383
1566
  report_known_issues() { # report_known_issues <plan>
1384
- local plan="$1" id n=0
1567
+ local plan="$1" id n=0 id_w
1568
+ id_w="$(id_col_width "$plan/tasks.tsv")"
1385
1569
  for id in $(all_ids "$plan/tasks.tsv"); do
1386
1570
  [ -s "$plan/tasks/$id/known_issues.md" ] || continue
1387
1571
  # A FAIL task's tolerated findings are on disk too (the gate writes them whatever its
@@ -1389,7 +1573,7 @@ report_known_issues() { # report_known_issues <plan>
1389
1573
  case "$(task_status "$plan" "$id")" in PASS|MERGED) ;; *) continue ;; esac
1390
1574
  [ "$n" = 0 ] && echo "known issues accepted (findings below the QA threshold, or accepted by a human):"
1391
1575
  n=$((n+1))
1392
- printf ' %-14s %s finding(s) %s\n' "$id" "$(grep -c '^- ' "$plan/tasks/$id/known_issues.md" 2>/dev/null || echo 0)" "$plan/tasks/$id/known_issues.md"
1576
+ printf ' %-*s %s finding(s) %s\n' "$id_w" "$id" "$(grep -c '^- ' "$plan/tasks/$id/known_issues.md" 2>/dev/null || echo 0)" "$plan/tasks/$id/known_issues.md"
1393
1577
  done
1394
1578
  # What an adopted range kept: findings below the threshold, or a verdict --approved overrode.
1395
1579
  local dir
@@ -1397,7 +1581,7 @@ report_known_issues() { # report_known_issues <plan>
1397
1581
  [ -s "$plan/$dir/known_issues.md" ] || continue
1398
1582
  [ "$n" = 0 ] && echo "known issues accepted (findings below the QA threshold, or accepted by a person):"
1399
1583
  n=$((n+1))
1400
- printf ' %-14s %s finding(s) %s\n' adopted "$(grep -c '^- ' "$plan/$dir/known_issues.md" 2>/dev/null)" "$plan/$dir/known_issues.md"
1584
+ printf ' %-*s %s finding(s) %s\n' "$id_w" adopted "$(grep -c '^- ' "$plan/$dir/known_issues.md" 2>/dev/null)" "$plan/$dir/known_issues.md"
1401
1585
  done
1402
1586
  [ "$n" -gt 0 ] && echo
1403
1587
  return 0
@@ -1406,14 +1590,19 @@ report_known_issues() { # report_known_issues <plan>
1406
1590
  # The PASS verdicts forge turned into FAIL, since FORGE_RUN_STARTED (set by run and retry;
1407
1591
  # unset shows them all), including those whose task a later attempt fixed.
1408
1592
  report_gate_flips() { # report_gate_flips <plan>
1409
- local plan="$1" id n=0 at attempt thr worst
1593
+ local plan="$1" id n=0 at attempt thr worst greason id_w
1594
+ id_w="$(id_col_width "$plan/tasks.tsv")"
1410
1595
  for id in $(all_ids "$plan/tasks.tsv"); do
1411
1596
  [ -s "$plan/tasks/$id/qa.flips" ] || continue
1412
- while IFS="$(printf '\t')" read -r at attempt thr worst; do
1597
+ while IFS="$(printf '\t')" read -r at attempt thr worst greason; do
1413
1598
  awk -v at="${at:-0}" -v since="${FORGE_RUN_STARTED:-0}" 'BEGIN { exit !(at + 0 >= since + 0) }' || continue
1414
- [ "$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):"
1415
1600
  n=$((n+1))
1416
- printf ' %-14s attempt %s: PASS -> FAIL at the %s threshold (worst %s)\n' "$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
1417
1606
  done < "$plan/tasks/$id/qa.flips"
1418
1607
  done
1419
1608
  [ "$n" -gt 0 ] && echo
@@ -1421,12 +1610,13 @@ report_gate_flips() { # report_gate_flips <plan>
1421
1610
  }
1422
1611
 
1423
1612
  report_guard_notes() { # report_guard_notes <plan>
1424
- local plan="$1" id n=0 line
1613
+ local plan="$1" id n=0 line id_w
1614
+ id_w="$(id_col_width "$plan/tasks.tsv")"
1425
1615
  for id in $(all_ids "$plan/tasks.tsv"); do
1426
1616
  [ -s "$plan/tasks/$id/guard.txt" ] || continue
1427
1617
  [ "$n" = 0 ] && echo "implementer guard notes (observed by forge, not self-reported):"
1428
1618
  n=$((n+1))
1429
- while IFS= read -r line; do printf ' %-14s %s\n' "$id" "$line"; done < "$plan/tasks/$id/guard.txt"
1619
+ while IFS= read -r line; do printf ' %-*s %s\n' "$id_w" "$id" "$line"; done < "$plan/tasks/$id/guard.txt"
1430
1620
  done
1431
1621
  [ "$n" -gt 0 ] && echo
1432
1622
  return 0
@@ -1463,6 +1653,10 @@ PY
1463
1653
  sed 's/^/ /' "$d/verification.coverage.txt"
1464
1654
  echo
1465
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
1466
1660
  return 0
1467
1661
  }
1468
1662
 
@@ -1480,18 +1674,18 @@ report_size() { # report_size <plan>
1480
1674
  # withdrawn since the last attempt leaves the `escalation.next` that `--check` wrote for it,
1481
1675
  # so a marker found with no pin pending is decided again rather than trusted.
1482
1676
  report_escalations() { # report_escalations <plan>
1483
- local plan="$1" id n=0 head pin
1677
+ local plan="$1" id n=0 head pin id_w
1678
+ id_w="$(id_col_width "$plan/tasks.tsv")"
1484
1679
  head="retry policy (after $(cat "$plan/escalate_after" 2>/dev/null || echo 3) failed attempts on one model):"
1485
1680
  for id in $(all_ids "$plan/tasks.tsv"); do
1486
1681
  pin="$(pin_spec "$plan/tasks/$id/escalation.pin")"
1487
- [ -n "$pin" ] && forge_plan_is_fractal "$plan" && pin=""
1488
1682
  if [ -n "$pin" ] && [ "$(task_status "$plan" "$id")" != MERGED ]; then
1489
1683
  [ "$n" = 0 ] && echo "$head"
1490
1684
  n=$((n+1))
1491
1685
  if qa_only_next "$plan" "$id"; then
1492
- printf ' %-14s its next retry goes to %s (pinned; after the QA-only re-run)\n' "$id" "$pin"
1686
+ printf ' %-*s its next retry goes to %s (pinned; after the QA-only re-run)\n' "$id_w" "$id" "$pin"
1493
1687
  else
1494
- printf ' %-14s its next retry goes to %s (pinned)\n' "$id" "$pin"
1688
+ printf ' %-*s its next retry goes to %s (pinned)\n' "$id_w" "$id" "$pin"
1495
1689
  fi
1496
1690
  continue
1497
1691
  fi
@@ -1501,10 +1695,10 @@ report_escalations() { # report_escalations <plan>
1501
1695
  fi
1502
1696
  if [ -s "$plan/tasks/$id/split.suggested" ]; then
1503
1697
  [ "$n" = 0 ] && echo "$head"
1504
- n=$((n+1)); printf ' %-14s split suggested: %s\n' "$id" "$(cat "$plan/tasks/$id/split.suggested")"
1698
+ n=$((n+1)); printf ' %-*s split suggested: %s\n' "$id_w" "$id" "$(cat "$plan/tasks/$id/split.suggested")"
1505
1699
  elif [ -s "$plan/tasks/$id/escalation.next" ] && [ "$(task_status "$plan" "$id")" != MERGED ]; then
1506
1700
  [ "$n" = 0 ] && echo "$head"
1507
- n=$((n+1)); printf ' %-14s its next retry goes to %s\n' "$id" "$(cat "$plan/tasks/$id/escalation.next")"
1701
+ n=$((n+1)); printf ' %-*s its next retry goes to %s\n' "$id_w" "$id" "$(cat "$plan/tasks/$id/escalation.next")"
1508
1702
  fi
1509
1703
  done
1510
1704
  [ "$n" -gt 0 ] && echo